Make powerGetDetails return status, disable output on failure to read

-PC returns false always
-Switch returns if either charge or charge status fails
This commit is contained in:
Daniel Bernard 2018-10-08 20:45:14 -05:00
parent 233dfd2b2c
commit a8ce7c2a6b
5 changed files with 26 additions and 15 deletions

View File

@ -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)
{

View File

@ -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) {

View File

@ -3,6 +3,6 @@
void powerInit(void);
void powerGetDetails(uint32_t *batteryCharge, bool *isCharging);
bool powerGetDetails(uint32_t *batteryCharge, bool *isCharging);
void powerExit(void);

View File

@ -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) {

View File

@ -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;
}