power: Display battery internal and external temperature

This commit is contained in:
joel16 2023-06-02 23:21:35 -04:00
parent dd77c6e53a
commit b925966919
4 changed files with 77 additions and 29 deletions

View File

@ -26,6 +26,7 @@ namespace SwitchIdent {
bool IsGameCardInserted(FsDeviceOperator *fsDeviceOperator);
// Power
Result TsInitialize(void);
u32 GetBatteryPercentage(void);
const char *GetChargerType(void);
bool IsCharging(void);
@ -35,6 +36,7 @@ namespace SwitchIdent {
bool IsEnoughPowerSupplied(void);
double GetBatteryAgePercentage(void);
SetBatteryLot GetBatteryLot(void);
s32 GetBatteryTemperature(TsLocation location);
// Storage
s64 GetTotalStorage(NcmStorageId storage_id);

View File

@ -8,13 +8,16 @@ namespace Services {
void Exit(void) {
// hiddbgExit();
// hidsysExit();
tsExit();
wlaninfExit();
if (hosversionAtLeast(8, 0, 0))
if (hosversionAtLeast(8, 0, 0)) {
clkrstExit();
else
}
else {
pcvExit();
}
psmExit();
nsExit();
apmExit();
@ -36,38 +39,49 @@ namespace Services {
socketInitializeDefault();
nxlinkStdio();
if (R_FAILED(ret = romfsInit()))
if (R_FAILED(ret = romfsInit())) {
std::printf("romfsInit() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = setInitialize()))
if (R_FAILED(ret = setInitialize())) {
std::printf("setInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = setsysInitialize()))
if (R_FAILED(ret = setsysInitialize())) {
std::printf("setsysInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = setcalInitialize()))
if (R_FAILED(ret = setcalInitialize())) {
std::printf("setcalInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = splInitialize()))
if (R_FAILED(ret = splInitialize())) {
std::printf("splInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = nifmInitialize(NifmServiceType_User)))
if (R_FAILED(ret = nifmInitialize(NifmServiceType_User))) {
std::printf("nifmInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = socketInitializeDefault()))
if (R_FAILED(ret = socketInitializeDefault())) {
std::printf("socketInitializeDefault() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = appletInitialize()))
if (R_FAILED(ret = appletInitialize())) {
std::printf("appletInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = apmInitialize()))
if (R_FAILED(ret = apmInitialize())) {
std::printf("apmInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = nsInitialize()))
if (R_FAILED(ret = nsInitialize())) {
std::printf("nsInitialize() failed: 0x%x.\n\n", ret);
}
if (R_FAILED(ret = psmInitialize()))
if (R_FAILED(ret = psmInitialize())) {
std::printf("psmInitialize() failed: 0x%x.\n\n", ret);
}
if (hosversionAtLeast(8, 0, 0)) {
if (R_FAILED(ret = clkrstInitialize()))
@ -78,8 +92,13 @@ namespace Services {
}
if (hosversionBefore(15, 0, 0)) {
if (R_FAILED(ret = wlaninfInitialize()))
if (R_FAILED(ret = wlaninfInitialize())) {
std::printf("wlaninfInitialize() failed: 0x%x.\n\n", ret);
}
}
if (R_FAILED(ret = tsInitialize())) {
std::printf("tsInitialize() failed: 0x%x.\n\n", ret);
}
// if (R_FAILED(ret = hidsysInitialize()))

View File

@ -78,12 +78,16 @@ namespace Menus {
}
void PowerInfo(void) {
s32 int_temp = SwitchIdent::GetBatteryTemperature(TsLocation_Internal);
s32 ext_temp = SwitchIdent::GetBatteryTemperature(TsLocation_External);
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Battery percentage:", "%lu %% (%s)", SwitchIdent::GetBatteryPercentage(), SwitchIdent::IsCharging()? "charging" : "not charging");
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "Battery voltage state:", SwitchIdent::GetVoltageState());
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "Battery charger type:", SwitchIdent::GetChargerType());
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "Battery charging enabled:", SwitchIdent::IsChargingEnabled()? "Yes" : "No");
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "Battery ample power supplied:", SwitchIdent::IsEnoughPowerSupplied()? "Yes" : "No");
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Battery lot number:", SwitchIdent::GetBatteryLot().lot);
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 350, "Battery internal temperature:", "%d °C (%d °F)", int_temp, ((int_temp * 9/5) + 32));
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 400, "Battery external temperature:", "%d °C (%d °F)", ext_temp, ((ext_temp * 9/5) + 32));
}
void StorageInfo(void) {

View File

@ -2,13 +2,13 @@
#include "common.hpp"
namespace SwitchIdent {
static Result _psmCmdNoInOutBool(Service* srv, bool *out, u32 cmd_id) {
u8 outval = 0;
Result ret = serviceDispatchOut(srv, cmd_id, outval);
if (R_SUCCEEDED(ret)) {
if (out)
if (out) {
*out = outval & 1;
}
}
return ret;
@ -22,8 +22,9 @@ namespace SwitchIdent {
Result ret = 0;
u32 percentage = 0;
if (R_FAILED(ret = psmGetBatteryChargePercentage(&percentage)))
if (R_FAILED(ret = psmGetBatteryChargePercentage(&percentage))) {
return -1;
}
return percentage;
}
@ -32,15 +33,19 @@ namespace SwitchIdent {
Result ret = 0;
PsmChargerType charger_type;
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
if (R_FAILED(ret = psmGetChargerType(&charger_type))) {
return nullptr;
}
if (charger_type == PsmChargerType_EnoughPower)
if (charger_type == PsmChargerType_EnoughPower) {
return "Official charger or dock";
else if (charger_type == PsmChargerType_LowPower)
}
else if (charger_type == PsmChargerType_LowPower) {
return "USB-C charger";
else
}
else {
return "No charger connected";
}
return nullptr;
}
@ -49,8 +54,9 @@ namespace SwitchIdent {
Result ret = 0;
PsmChargerType charger_type;
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
if (R_FAILED(ret = psmGetChargerType(&charger_type))) {
return false;
}
return charger_type != PsmChargerType_Unconnected;
}
@ -59,8 +65,9 @@ namespace SwitchIdent {
Result ret = 0;
bool is_charing_enabled = 0;
if (R_FAILED(ret = psmIsBatteryChargingEnabled(&is_charing_enabled)))
if (R_FAILED(ret = psmIsBatteryChargingEnabled(&is_charing_enabled))) {
return -1;
}
return is_charing_enabled;
}
@ -77,8 +84,9 @@ namespace SwitchIdent {
};
if (R_SUCCEEDED(ret = psmGetBatteryVoltageState(&voltage_state))) {
if (voltage_state < 4)
if (voltage_state < 4) {
return states[voltage_state];
}
}
std::printf("psmGetBatteryVoltageState() failed: 0x%x.\n\n", ret);
@ -89,8 +97,9 @@ namespace SwitchIdent {
Result ret = 0;
double raw_percentage = 0;
if (R_FAILED(ret = psmGetRawBatteryChargePercentage(&raw_percentage)))
if (R_FAILED(ret = psmGetRawBatteryChargePercentage(&raw_percentage))) {
return -1;
}
return raw_percentage;
}
@ -99,8 +108,9 @@ namespace SwitchIdent {
Result ret = 0;
bool is_power_supplied = 0;
if (R_FAILED(ret = psmIsEnoughPowerSupplied(&is_power_supplied)))
if (R_FAILED(ret = psmIsEnoughPowerSupplied(&is_power_supplied))) {
return -1;
}
return is_power_supplied;
}
@ -109,8 +119,9 @@ namespace SwitchIdent {
Result ret = 0;
double age_percentage = 0;
if (R_FAILED(ret = psmGetBatteryAgePercentage(&age_percentage)))
if (R_FAILED(ret = psmGetBatteryAgePercentage(&age_percentage))) {
return -1;
}
return age_percentage;
}
@ -119,9 +130,21 @@ namespace SwitchIdent {
Result ret = 0;
SetBatteryLot battery_lot;
if (R_FAILED(ret = setcalGetBatteryLot(&battery_lot)))
if (R_FAILED(ret = setcalGetBatteryLot(&battery_lot))) {
std::printf("setcalGetBatteryLot() failed: 0x%x.\n\n", ret);
}
return battery_lot;
}
s32 GetBatteryTemperature(TsLocation location) {
Result ret = 0;
s32 temp = 0;
if (R_FAILED(ret = tsGetTemperature(location, &temp))) {
std::printf("tsGetTemperature() failed: 0x%x.\n\n", ret);
}
return temp;
}
}