mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Show battery state on top bar
thanks @al3x10m for pointing out the possibility
This commit is contained in:
parent
a947835830
commit
5941ce41bc
@ -1,7 +1,6 @@
|
|||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "timer.h"
|
|
||||||
#include "pxi.h"
|
#include "pxi.h"
|
||||||
|
|
||||||
static const u8 br_settings[] = {0x10, 0x17, 0x1E, 0x25, 0x2C, 0x34, 0x3C, 0x44, 0x4D, 0x56, 0x60, 0x6B, 0x79, 0x8C, 0xA7, 0xD2};
|
static const u8 br_settings[] = {0x10, 0x17, 0x1E, 0x25, 0x2C, 0x34, 0x3C, 0x44, 0x4D, 0x56, 0x60, 0x6B, 0x79, 0x8C, 0xA7, 0xD2};
|
||||||
@ -18,6 +17,12 @@ void CheckBrightness() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetBatteryPercent() {
|
||||||
|
u8 battery = 0;
|
||||||
|
I2C_readRegBuf(I2C_DEV_MCU, 0x0B, &battery, 1);
|
||||||
|
return battery;
|
||||||
|
}
|
||||||
|
|
||||||
void Reboot() {
|
void Reboot() {
|
||||||
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); // poweroff LCD to prevent MCU hangs
|
||||||
flushEntireDCache();
|
flushEntireDCache();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void CheckBrightness();
|
void CheckBrightness();
|
||||||
|
u32 GetBatteryPercent();
|
||||||
void ScreenOn();
|
void ScreenOn();
|
||||||
void Reboot();
|
void Reboot();
|
||||||
void PowerOff();
|
void PowerOff();
|
||||||
|
@ -59,17 +59,27 @@ typedef struct {
|
|||||||
u32 scroll;
|
u32 scroll;
|
||||||
} PaneData;
|
} PaneData;
|
||||||
|
|
||||||
void GetTimeString(char* timestr, bool forced_update) {
|
void GetTimeString(char* timestr, bool forced_update, bool full_year) {
|
||||||
static DsTime dstime;
|
static DsTime dstime;
|
||||||
static u64 timer = (u64) -1; // this ensures we don't check the time too often
|
static u64 timer = (u64) -1; // this ensures we don't check the time too often
|
||||||
if (forced_update || (timer == (u64) -1) || (timer_sec(timer) > 30)) {
|
if (forced_update || (timer == (u64) -1) || (timer_sec(timer) > 30)) {
|
||||||
get_dstime(&dstime);
|
get_dstime(&dstime);
|
||||||
timer = timer_start();
|
timer = timer_start();
|
||||||
}
|
}
|
||||||
if (timestr) snprintf(timestr, 31, "20%02lX-%02lX-%02lX %02lX:%02lX",
|
if (timestr) snprintf(timestr, 31, "%s%02lX-%02lX-%02lX %02lX:%02lX", full_year ? "20" : "",
|
||||||
(u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D, (u32) dstime.bcd_h, (u32) dstime.bcd_m);
|
(u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D, (u32) dstime.bcd_h, (u32) dstime.bcd_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetBatteryPercentSafe() {
|
||||||
|
static u32 battery = 0;
|
||||||
|
static u64 timer = (u64) -1; // this ensures we don't check the battery too often
|
||||||
|
if ((timer == (u64) -1) || (timer_sec(timer) > 120)) {
|
||||||
|
battery = GetBatteryPercent();
|
||||||
|
timer = timer_start();
|
||||||
|
}
|
||||||
|
return battery;
|
||||||
|
}
|
||||||
|
|
||||||
void DrawTopBar(const char* curr_path) {
|
void DrawTopBar(const char* curr_path) {
|
||||||
const u32 bartxt_start = (FONT_HEIGHT_EXT == 10) ? 1 : 2;
|
const u32 bartxt_start = (FONT_HEIGHT_EXT == 10) ? 1 : 2;
|
||||||
const u32 bartxt_x = 2;
|
const u32 bartxt_x = 2;
|
||||||
@ -97,10 +107,11 @@ void DrawTopBar(const char* curr_path) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (show_time) { // clock
|
if (show_time) { // clock & battery
|
||||||
char timestr[32];
|
char timestr[32];
|
||||||
GetTimeString(timestr, false);
|
GetTimeString(timestr, false, false);
|
||||||
DrawStringF(TOP_SCREEN, bartxt_rx, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", timestr);
|
DrawStringF(TOP_SCREEN, bartxt_rx, bartxt_start, COLOR_STD_BG, COLOR_TOP_BAR, "%14.14s %3lu%%", timestr,
|
||||||
|
GetBatteryPercentSafe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1463,7 +1474,7 @@ u32 HomeMoreMenu(char* current_path, DirStruct* current_dir, DirStruct* clipboar
|
|||||||
if (ShowRtcSetterPrompt(&dstime, "Set RTC date&time:")) {
|
if (ShowRtcSetterPrompt(&dstime, "Set RTC date&time:")) {
|
||||||
char timestr[32];
|
char timestr[32];
|
||||||
set_dstime(&dstime);
|
set_dstime(&dstime);
|
||||||
GetTimeString(timestr, true);
|
GetTimeString(timestr, true, true);
|
||||||
ShowPrompt(false, "New RTC date&time is:\n%s\n \nHint: HOMEMENU time needs\nmanual adjustment after\nsetting the RTC.",
|
ShowPrompt(false, "New RTC date&time is:\n%s\n \nHint: HOMEMENU time needs\nmanual adjustment after\nsetting the RTC.",
|
||||||
timestr);
|
timestr);
|
||||||
}
|
}
|
||||||
@ -1564,7 +1575,7 @@ u32 GodMode(bool is_b9s) {
|
|||||||
ShowRtcSetterPrompt(&dstime, "Set RTC date&time:")) {
|
ShowRtcSetterPrompt(&dstime, "Set RTC date&time:")) {
|
||||||
char timestr[32];
|
char timestr[32];
|
||||||
set_dstime(&dstime);
|
set_dstime(&dstime);
|
||||||
GetTimeString(timestr, true);
|
GetTimeString(timestr, true, true);
|
||||||
ShowPrompt(false, "New RTC date&time is:\n%s\n \nHint: HOMEMENU time needs\nmanual adjustment after\nsetting the RTC.", timestr);
|
ShowPrompt(false, "New RTC date&time is:\n%s\n \nHint: HOMEMENU time needs\nmanual adjustment after\nsetting the RTC.", timestr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user