- Revert commit a45b767a80 in favor of tinkering "enough_power_threshold_mw" in system-settings.ini

- Add InfoNX (For battery, charger, clocks, voltages, etc.)
This commit is contained in:
KazushiM
2021-09-16 16:16:30 +08:00
parent cb13e21e85
commit bf3bd67dd6
23 changed files with 10176 additions and 83 deletions

View File

@@ -11,42 +11,9 @@
#include <nxExt.h>
#include "clocks.h"
#include "errors.h"
#include "file_utils.h"
bool Clocks::isMariko = false;
typedef enum {
None = 0,
PD = 1,
TypeC_1500mA = 2,
TypeC_3000mA = 3,
DCP = 4,
CDP = 5,
SDP = 6,
Apple_500mA = 7,
Apple_1000mA = 8,
Apple_2000mA = 9
} BatteryChargeInfoFieldsChargerType;
typedef struct {
uint32_t InputCurrentLimit; //Input (Sink) current limit in mA
uint32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA
uint32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
uint32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
uint32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases
uint32_t unk_x14; //Possibly flags
uint16_t PDControllerState; //Power Delivery Controller State
uint32_t BatteryTemperature; //Battery temperature in milli C
uint32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
uint32_t VoltageAvg; //Voltage avg in mV (more in Notes)
uint32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
uint16_t PowerRole; //Sink or Source
BatteryChargeInfoFieldsChargerType ChargerType;
uint32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
uint32_t ChargerCurrentLimit; //Charger and external device current limit in mA
uint16_t Flags; //Unknown flags
} BatteryChargeInfoFields;
void Clocks::GetList(SysClkModule module, std::uint32_t **outClocks)
{
switch(module)
@@ -226,10 +193,6 @@ void Clocks::ResetToStock(unsigned int module)
}
}
Result psmGetBatteryChargeInfoFields(Service* psmService, BatteryChargeInfoFields *out) {
return serviceDispatchOut(psmService, 17, *out);
}
SysClkProfile Clocks::GetCurrentProfile()
{
std::uint32_t mode = 0;
@@ -241,19 +204,6 @@ SysClkProfile Clocks::GetCurrentProfile()
return SysClkProfile_Docked;
}
if(FileUtils::IsPd18wAsOfficialChargerEnabled())
{
static Service* psmService = psmGetServiceSession();
static BatteryChargeInfoFields* _Fields = new BatteryChargeInfoFields;
psmGetBatteryChargeInfoFields(psmService, _Fields);
if(_Fields->ChargerType == PD)
{
uint8_t ChargerWatts = (_Fields->ChargerVoltageLimit * _Fields->ChargerCurrentLimit)/1000000.0;
if(ChargerWatts >= 17)
return SysClkProfile_HandheldChargingOfficial;
}
}
PsmChargerType chargerType;
rc = psmGetChargerType(&chargerType);

View File

@@ -21,7 +21,6 @@ static bool g_log_enabled = false;
static bool g_boost_enabled = false;
static bool g_boost_start_enabled = false;
static bool g_downclock_dock_enabled = false;
static bool g_pd18w_as_official_charger_enabled = false;
static bool g_reversenx_tool_exist = false;
static bool g_reversenx_sync_enabled = false;
static std::uint64_t g_last_flag_check = 0;
@@ -184,13 +183,6 @@ void FileUtils::InitCheckFlags()
fclose(file);
}
file = fopen(FILE_PD18W_AS_OFFICIAL_CHARGER_FLAG_PATH, "r");
if (file)
{
g_pd18w_as_official_charger_enabled = true;
fclose(file);
}
file = fopen(FILE_REVERSENX_SYNC_FLAG_PATH, "r");
if (file)
{
@@ -221,11 +213,6 @@ bool FileUtils::IsDownclockDockEnabled()
return g_downclock_dock_enabled;
}
bool FileUtils::IsPd18wAsOfficialChargerEnabled()
{
return g_pd18w_as_official_charger_enabled;
}
bool FileUtils::IsReverseNXToolExist()
{
return g_reversenx_tool_exist;

View File

@@ -25,7 +25,6 @@
#define FILE_BOOST_FLAG_PATH FILE_CONFIG_DIR "/boost.flag"
#define FILE_BOOST_START_FLAG_PATH FILE_CONFIG_DIR "/boost_start.flag"
#define FILE_DOWNCLOCK_DOCK_FLAG_PATH FILE_CONFIG_DIR "/downclock_dock.flag"
#define FILE_PD18W_AS_OFFICIAL_CHARGER_FLAG_PATH FILE_CONFIG_DIR "/pd18w_official.flag"
#define FILE_SALTYNX_PATH "/atmosphere/contents/0000000000534C56/flags/boot2.flag" // Just check for SaltyNX boot flag
#define FILE_REVERSENX_SYNC_FLAG_PATH FILE_CONFIG_DIR "/ReverseNX_sync.flag"
#define FILE_REVERSENX_RT_CONF_PATH FILE_CONFIG_DIR "/ReverseNX-RT.conf"
@@ -40,7 +39,6 @@ class FileUtils
static bool IsBoostEnabled();
static bool IsBoostStartEnabled();
static bool IsDownclockDockEnabled();
static bool IsPd18wAsOfficialChargerEnabled();
static bool IsReverseNXSyncEnabled();
static bool IsReverseNXToolExist();
static void InitializeAsync();