From 9fb7485051241fa7939a6a88954dedbf69d7616a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 20 Sep 2018 11:22:58 -0700 Subject: [PATCH] mGUI: Add BATTERY_NOT_PRESENT state --- include/mgba-util/gui.h | 3 ++- src/platform/switch/main.c | 2 ++ src/util/gui/menu.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/mgba-util/gui.h b/include/mgba-util/gui.h index 183fcfa80..a13251bc6 100644 --- a/include/mgba-util/gui.h +++ b/include/mgba-util/gui.h @@ -47,7 +47,8 @@ enum { BATTERY_HIGH = 3, BATTERY_FULL = 4, - BATTERY_CHARGING = 8 + BATTERY_CHARGING = 8, + BATTERY_NOT_PRESENT = 16 }; struct GUIBackground { diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index 156a9ac44..55be2f910 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -360,6 +360,8 @@ static int _batteryState(void) { int state = 0; if (R_SUCCEEDED(psmGetBatteryChargePercentage(&charge))) { state = (charge + 12) / 25; + } else { + return BATTERY_NOT_PRESENT; } ChargerType type; if (R_SUCCEEDED(psmGetChargerType(&type)) && type) { diff --git a/src/util/gui/menu.c b/src/util/gui/menu.c index f9cba3d36..68ba7781f 100644 --- a/src/util/gui/menu.c +++ b/src/util/gui/menu.c @@ -260,6 +260,9 @@ void GUIDrawBattery(struct GUIParams* params) { return; } int state = params->batteryState(); + if (state == BATTERY_NOT_PRESENT) { + return; + } uint32_t color = 0xFF000000; if (state == (BATTERY_CHARGING | BATTERY_FULL)) { color |= 0xFFC060;