From a8ce7c2a6b02bf4c9f0c7d41c1ee2915bd9fad29 Mon Sep 17 00:00:00 2001 From: Daniel Bernard Date: Mon, 8 Oct 2018 20:45:14 -0500 Subject: [PATCH] Make powerGetDetails return status, disable output on failure to read -PC returns false always -Switch returns if either charge or charge status fails --- common/common.h | 1 - common/menu.c | 23 ++++++++++++++--------- common/power.h | 2 +- nx_main/nx_power.c | 12 +++++++++--- pc_main/pc_power.c | 3 ++- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/common/common.h b/common/common.h index 3f5c9c7..b4cb2b4 100644 --- a/common/common.h +++ b/common/common.h @@ -64,7 +64,6 @@ void menuStartupPath(void); void menuStartup(void); void themeMenuStartup(void); void menuLoop(void); -void menuExit(void); static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha) { diff --git a/common/menu.c b/common/menu.c index c6b61b2..307b18c 100644 --- a/common/menu.c +++ b/common/menu.c @@ -427,18 +427,23 @@ void drawCharge() { char chargeString[5]; uint32_t batteryCharge; bool isCharging; + bool validPower; + + validPower = powerGetDetails(&batteryCharge, &isCharging); - powerGetDetails(&batteryCharge, &isCharging); - batteryCharge = (batteryCharge > 100) ? 100 : batteryCharge; + if (validPower) + { + batteryCharge = (batteryCharge > 100) ? 100 : batteryCharge; - sprintf(chargeString, "%d%%", batteryCharge); + sprintf(chargeString, "%d%%", batteryCharge); + + int tmpX = GetTextXCoordinate(interuiregular14, 1180, chargeString, 'r'); - int tmpX = GetTextXCoordinate(interuiregular14, 1180, chargeString, 'r'); - - DrawText(interuiregular14, tmpX - 15, 0 + 47 + 10 + 21, themeCurrent.textColor, chargeString); - drawIcon(1180 - 11, 0 + 47 + 10 + 6, 10, 15, battery_icon_bin, themeCurrent.textColor); - if (isCharging) - drawIcon(tmpX - 32, 0 + 47 + 10 + 6, 9, 15, charging_icon_bin, themeCurrent.textColor); + DrawText(interuiregular14, tmpX - 15, 0 + 47 + 10 + 21, themeCurrent.textColor, chargeString); + drawIcon(1180 - 11, 0 + 47 + 10 + 6, 10, 15, battery_icon_bin, themeCurrent.textColor); + if (isCharging) + drawIcon(tmpX - 32, 0 + 47 + 10 + 6, 9, 15, charging_icon_bin, themeCurrent.textColor); + } } void drawBackBtn(menu_s* menu, bool emptyDir) { diff --git a/common/power.h b/common/power.h index 1815f0c..d9a9d34 100644 --- a/common/power.h +++ b/common/power.h @@ -3,6 +3,6 @@ void powerInit(void); -void powerGetDetails(uint32_t *batteryCharge, bool *isCharging); +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging); void powerExit(void); \ No newline at end of file diff --git a/nx_main/nx_power.c b/nx_main/nx_power.c index 21e2ae4..d5c1949 100644 --- a/nx_main/nx_power.c +++ b/nx_main/nx_power.c @@ -3,18 +3,24 @@ static bool psmInitialized; -void powerGetDetails(uint32_t *batteryCharge, bool *isCharging) { +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) { ChargerType charger = ChargerType_None; + bool hwReadsSucceeded = false; + Result rc = 0; *isCharging = false; *batteryCharge = 0; if (psmInitialized) { - psmGetBatteryChargePercentage(batteryCharge); - psmGetChargerType(&charger); + rc = psmGetBatteryChargePercentage(batteryCharge); + hwReadsSucceeded = R_SUCCEEDED(rc); + rc = psmGetChargerType(&charger); + hwReadsSucceeded &= R_SUCCEEDED(rc); *isCharging = (charger > ChargerType_None); } + + return hwReadsSucceeded; } void powerInit(void) { diff --git a/pc_main/pc_power.c b/pc_main/pc_power.c index 4e0c427..b16faa9 100644 --- a/pc_main/pc_power.c +++ b/pc_main/pc_power.c @@ -8,7 +8,8 @@ void powerExit(void) { } -void powerGetDetails(uint32_t *batteryCharge, bool *isCharging) +bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging) *isCharging = false; *batteryCharge = 100; + return false; } \ No newline at end of file