Don't allow installing when battery is low

This commit is contained in:
Pk11 2022-01-10 23:17:39 -06:00
parent cc45070fb4
commit f893d21f05
4 changed files with 28 additions and 2 deletions

View File

@ -179,6 +179,14 @@ int main() {
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) { if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
exitflag = true; exitflag = true;
} }
int batteryStatus;
if (isDSiMode() || REG_SCFG_EXT != 0)
batteryStatus = i2cReadRegister(I2C_PM, I2CREGPM_BATTERY);
else
batteryStatus = (readPowerManagement(PM_BATTERY_REG) & 1) ? 0x3 : 0xF;
fifoSendValue32(FIFO_USER_03, batteryStatus);
swiWaitForVBlank(); swiWaitForVBlank();
} }

View File

@ -286,6 +286,13 @@ bool install(char* fpath, bool systemTitle)
{ {
bool result = false; bool result = false;
//check battery level
while (batteryLevel < 7 && !charging)
{
if (choiceBox("\x1B[47mBattery is too low!\nPlease plug in the console.\n\nContinue?") == NO)
return false;
}
//confirmation message //confirmation message
{ {
char str[] = "Are you sure you want to install\n"; char str[] = "Are you sure you want to install\n";

View File

@ -9,6 +9,8 @@
bool programEnd = false; bool programEnd = false;
bool sdnandMode = true; bool sdnandMode = true;
bool arm7Exiting = false; bool arm7Exiting = false;
bool charging = false;
u8 batteryLevel = 0;
PrintConsole topScreen; PrintConsole topScreen;
PrintConsole bottomScreen; PrintConsole bottomScreen;
@ -92,7 +94,7 @@ static int _mainMenu(int cursor)
return result; return result;
} }
void fifoHandler(u32 value32, void* userdata) void fifoHandlerPower(u32 value32, void* userdata)
{ {
if (value32 == 0x54495845) // 'EXIT' if (value32 == 0x54495845) // 'EXIT'
{ {
@ -101,6 +103,12 @@ void fifoHandler(u32 value32, void* userdata)
} }
} }
void fifoHandlerBattery(u32 value32, void* userdata)
{
batteryLevel = value32 & 0xF;
charging = (value32 & BIT(7)) != 0;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
srand(time(0)); srand(time(0));
@ -146,7 +154,8 @@ int main(int argc, char **argv)
//main menu //main menu
int cursor = 0; int cursor = 0;
fifoSetValue32Handler(FIFO_USER_01, fifoHandler, NULL); fifoSetValue32Handler(FIFO_USER_01, fifoHandlerPower, NULL);
fifoSetValue32Handler(FIFO_USER_03, fifoHandlerBattery, NULL);
while (!programEnd) while (!programEnd)
{ {

View File

@ -7,6 +7,8 @@
extern bool programEnd; extern bool programEnd;
extern bool sdnandMode; extern bool sdnandMode;
extern bool charging;
extern u8 batteryLevel;
void installMenu(); void installMenu();
void titleMenu(); void titleMenu();