mGUI: Show battery percentage
Vicki Pfau vi@endrift.com
Sun, 09 Aug 2020 17:56:26 -0700
9 files changed,
39 insertions(+),
26 deletions(-)
M
CHANGES
→
CHANGES
@@ -47,6 +47,7 @@ - GB: Allow pausing event loop while CPU is blocked
- GBA: Allow pausing event loop while CPU is blocked - Debugger: Keep track of global cycle count - FFmpeg: Add looping option for GIF/APNG + - mGUI: Show battery percentage - Qt: Renderer can be changed while a game is running - Qt: Add hex index to palette view - Qt: Add transformation matrix info to sprite view
M
include/mgba-util/gui.h
→
include/mgba-util/gui.h
@@ -42,13 +42,15 @@ };
enum { BATTERY_EMPTY = 0, - BATTERY_LOW = 1, - BATTERY_HALF = 2, - BATTERY_HIGH = 3, - BATTERY_FULL = 4, + BATTERY_LOW = 25, + BATTERY_HALF = 50, + BATTERY_HIGH = 75, + BATTERY_FULL = 100, + BATTERY_VALUE = 0x7F, + BATTERY_PERCENTAGE_VALID = 0x80, - BATTERY_CHARGING = 8, - BATTERY_NOT_PRESENT = 16 + BATTERY_CHARGING = 0x100, + BATTERY_NOT_PRESENT = 0x200, }; struct GUIBackground {
M
src/platform/3ds/cia.rsf.in
→
src/platform/3ds/cia.rsf.in
@@ -154,14 +154,13 @@ - boss:U
- cam:u - cecd:u - cfg:u - - dlp:FKCL - - dlp:SRVR - dsp::DSP - frd:u - fs:USER - gsp::Gpu - hid:USER - http:C + - mcu::HWC - mic:u - ndm:u - news:u
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -187,6 +187,7 @@
camExit(); ndspExit(); ptmuExit(); + mcuHwcExit(); } static void _map3DSKey(struct mInputMap* map, int ctrKey, enum GBAKey key) {@@ -237,14 +238,19 @@
static int _batteryState(void) { u8 charge; u8 adapter; - PTMU_GetBatteryLevel(&charge); PTMU_GetBatteryChargeState(&adapter); + int state = 0; + if (R_SUCCEEDED(MCUHWC_GetBatteryLevel(&charge))) { + charge |= BATTERY_PERCENTAGE_VALID; + } else { + PTMU_GetBatteryLevel(&charge); + if (charge > 0) { + --charge; + } + } if (adapter) { state |= BATTERY_CHARGING; - } - if (charge > 0) { - --charge; } return state | charge; }@@ -814,6 +820,7 @@ camera.bufferSize = 0;
camera.cam = SELECT_IN1; ptmuInit(); + mcuHwcInit(); camInit(); hasSound = NO_SOUND;
M
src/platform/psp2/main.c
→
src/platform/psp2/main.c
@@ -72,13 +72,12 @@ return GUI_CURSOR_DOWN;
} static int _batteryState(void) { - int charge = scePowerGetBatteryLifePercent(); + int charge = scePowerGetBatteryLifePercent() | BATTERY_PERCENTAGE_VALID; int adapter = scePowerIsPowerOnline(); int state = 0; if (adapter) { state |= BATTERY_CHARGING; } - charge /= 25; return state | charge; }
M
src/platform/switch/main.c
→
src/platform/switch/main.c
@@ -607,7 +607,7 @@ static int _batteryState(void) {
u32 charge; int state = 0; if (R_SUCCEEDED(psmGetBatteryChargePercentage(&charge))) { - state = (charge + 12) / 25; + state = charge | BATTERY_PERCENTAGE_VALID; } else { return BATTERY_NOT_PRESENT; }
M
src/util/gui/font-metrics.c
→
src/util/gui/font-metrics.c
@@ -137,11 +137,11 @@ { 0, 0, { 0, 0, 0, 0 }}, // 0x7F
}; const struct GUIIconMetric defaultIconMetrics[] = { - [GUI_ICON_BATTERY_FULL] = { 0, 0, 32, 16 }, - [GUI_ICON_BATTERY_HIGH] = { 32, 0, 32, 16 }, - [GUI_ICON_BATTERY_HALF] = { 64, 0, 32, 16 }, - [GUI_ICON_BATTERY_LOW] = { 96, 0, 32, 16 }, - [GUI_ICON_BATTERY_EMPTY] = { 128, 0, 32, 16 }, + [GUI_ICON_BATTERY_FULL] = { 0, 2, 32, 12 }, + [GUI_ICON_BATTERY_HIGH] = { 32, 2, 32, 12 }, + [GUI_ICON_BATTERY_HALF] = { 64, 2, 32, 12 }, + [GUI_ICON_BATTERY_LOW] = { 96, 2, 32, 12 }, + [GUI_ICON_BATTERY_EMPTY] = { 128, 2, 32, 12 }, [GUI_ICON_SCROLLBAR_BUTTON] = { 6, 16, 4, 5 }, [GUI_ICON_SCROLLBAR_TRACK] = { 23, 16, 2, 16 }, [GUI_ICON_SCROLLBAR_THUMB] = { 38, 16, 4, 16 },
M
src/util/gui/font.c
→
src/util/gui/font.c
@@ -43,7 +43,7 @@ uint32_t c = utf8Char(&text, &len);
if (c == '\1') { c = utf8Char(&text, &len); if (c < GUI_ICON_MAX) { - GUIFontDrawIcon(font, x, y, GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, c); + GUIFontDrawIcon(font, x, y, (align & GUI_ALIGN_HCENTER) | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, c); unsigned w; GUIFontIconMetrics(font, c, &w, 0); x += w;