Add battery level check

This commit is contained in:
Edoardo Lolletti 2024-04-27 17:58:24 +02:00
parent 379db68839
commit 38b1efb15b
2 changed files with 15 additions and 9 deletions

View File

@ -182,6 +182,7 @@ int main()
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
// Keep the ARM7 mostly idle // Keep the ARM7 mostly idle
int oldBatteryStatus = 0;
while (!exitflag) while (!exitflag)
{ {
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R)))
@ -189,12 +190,11 @@ int main()
exitflag = true; exitflag = true;
} }
int batteryStatus; int batteryStatus = i2cReadRegister(I2C_PM, I2CREGPM_BATTERY);
if (isDSiMode() || REG_SCFG_EXT != 0) if(oldBatteryStatus != batteryStatus)
batteryStatus = i2cReadRegister(I2C_PM, I2CREGPM_BATTERY); {
else fifoSendValue32(FIFO_USER_03, oldBatteryStatus = batteryStatus);
batteryStatus = (readPowerManagement(PM_BATTERY_REG) & 1) ? 0x3 : 0xF; }
fifoSendValue32(FIFO_USER_03, batteryStatus);
swiWaitForVBlank(); swiWaitForVBlank();
} }

View File

@ -20,8 +20,8 @@ static bool disableAllPatches = false;
static bool enableSoundAndSplash = false; static bool enableSoundAndSplash = false;
static const char* splashSoundBinaryPatchPath = NULL; static const char* splashSoundBinaryPatchPath = NULL;
static const char* customBgPath = NULL; static const char* customBgPath = NULL;
bool charging = false; volatile bool charging = false;
u8 batteryLevel = 0; volatile u8 batteryLevel = 0;
PrintConsole topScreen; PrintConsole topScreen;
PrintConsole bottomScreen; PrintConsole bottomScreen;
@ -139,7 +139,7 @@ int main(int argc, char **argv)
//DSi check //DSi check
if (!isDSiMode()) if (!isDSiMode())
{ {
messageBox("\x1B[31mError:\x1B[33m This app is only for DSi."); messageBox("\x1B[31mError:\x1B[33m This app is exclusively for DSi.");
return 0; return 0;
} }
@ -156,6 +156,12 @@ int main(int argc, char **argv)
return 0; return 0;
} }
while (batteryLevel < 7 && !charging)
{
if (choiceBox("\x1B[47mBattery is too low!\nPlease plug in the console.\n\nContinue?") == NO)
return 0;
}
DeviceList* deviceList = getDeviceList(); DeviceList* deviceList = getDeviceList();
const char* installerPath = (argc > 0) ? argv[0] : (deviceList ? deviceList->appname : "sd:/ntrboot.nds"); const char* installerPath = (argc > 0) ? argv[0] : (deviceList ? deviceList->appname : "sd:/ntrboot.nds");