mGUI: Show battery percentage

This commit is contained in:
Vicki Pfau 2020-08-09 17:56:26 -07:00
parent d746cb16d6
commit 3b784485f8
9 changed files with 39 additions and 26 deletions

View File

@ -47,6 +47,7 @@ Misc:
- 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

View File

@ -42,13 +42,15 @@ enum GUICursorState {
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 {

View File

@ -154,14 +154,13 @@ AccessControlInfo:
- 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

View File

@ -187,6 +187,7 @@ static void _cleanup(void) {
camExit();
ndspExit();
ptmuExit();
mcuHwcExit();
}
static void _map3DSKey(struct mInputMap* map, int ctrKey, enum GBAKey key) {
@ -237,15 +238,20 @@ static void _drawEnd(void) {
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 @@ int main() {
camera.cam = SELECT_IN1;
ptmuInit();
mcuHwcInit();
camInit();
hasSound = NO_SOUND;

View File

@ -72,13 +72,12 @@ static enum GUICursorState _pollCursor(unsigned* x, unsigned* y) {
}
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;
}

View File

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

View File

@ -137,11 +137,11 @@ const struct GUIFontGlyphMetric defaultFontMetrics[128] = {
};
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 },

View File

@ -43,7 +43,7 @@ void GUIFontPrint(const struct GUIFont* font, int x, int y, enum GUIAlignment al
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;

View File

@ -264,20 +264,20 @@ void GUIDrawBattery(struct GUIParams* params) {
return;
}
uint32_t color = 0xFF000000;
if (state == (BATTERY_CHARGING | BATTERY_FULL)) {
if ((state & (BATTERY_CHARGING | BATTERY_FULL)) == (BATTERY_CHARGING | BATTERY_FULL)) {
color |= 0xFFC060;
} else if (state & BATTERY_CHARGING) {
color |= 0x60FF60;
} else if (state >= BATTERY_HALF) {
} else if ((state & BATTERY_VALUE) >= BATTERY_HALF) {
color |= 0xFFFFFF;
} else if (state == BATTERY_LOW) {
} else if ((state & BATTERY_VALUE) >= BATTERY_LOW) {
color |= 0x30FFFF;
} else {
color |= 0x3030FF;
}
enum GUIIcon batteryIcon;
switch (state & ~BATTERY_CHARGING) {
switch ((state & BATTERY_VALUE) - (state & BATTERY_VALUE) % 25) {
case BATTERY_EMPTY:
batteryIcon = GUI_ICON_BATTERY_EMPTY;
break;
@ -298,7 +298,12 @@ void GUIDrawBattery(struct GUIParams* params) {
break;
}
GUIFontDrawIcon(params->font, params->width, 0, GUI_ALIGN_RIGHT, GUI_ORIENT_0, color, batteryIcon);
GUIFontDrawIcon(params->font, params->width, GUIFontHeight(params->font) + 2, GUI_ALIGN_RIGHT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, batteryIcon);
if (state & BATTERY_PERCENTAGE_VALID) {
unsigned width;
GUIFontIconMetrics(params->font, batteryIcon, &width, NULL);
GUIFontPrintf(params->font, params->width - width, GUIFontHeight(params->font), GUI_ALIGN_RIGHT, color, "%u%%", state & BATTERY_VALUE);
}
}
void GUIDrawClock(struct GUIParams* params) {