mirror of
https://github.com/AuroraWright/SafeA9LHInstaller.git
synced 2025-06-26 13:42:45 +00:00
80 lines
1.8 KiB
C
Executable File
80 lines
1.8 KiB
C
Executable File
/*
|
|
* utils.c
|
|
*/
|
|
|
|
#include "utils.h"
|
|
#include "draw.h"
|
|
#include "screen.h"
|
|
#include "cache.h"
|
|
#include "i2c.h"
|
|
|
|
u32 waitInput(void)
|
|
{
|
|
bool pressedKey = false;
|
|
u32 key;
|
|
|
|
//Wait for no keys to be pressed
|
|
while(HID_PAD);
|
|
|
|
do
|
|
{
|
|
//Wait for a key to be pressed
|
|
while(!HID_PAD);
|
|
|
|
key = HID_PAD;
|
|
|
|
//Make sure it's pressed
|
|
for(u32 i = 0x13000; i > 0; i--)
|
|
{
|
|
if(key != HID_PAD) break;
|
|
if(i == 1) pressedKey = true;
|
|
}
|
|
}
|
|
while(!pressedKey);
|
|
|
|
return key;
|
|
}
|
|
|
|
void mcuReboot(void)
|
|
{
|
|
clearScreens();
|
|
|
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
|
flushEntireDCache();
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
|
while(true);
|
|
}
|
|
|
|
void inputSequence(void)
|
|
{
|
|
posY = drawString("If you would like to continue, press:", 10, posY, COLOR_WHITE);
|
|
posY = drawString("Up, Down, Left, Right, B, A, START, SELECT", 10, posY, COLOR_WHITE);
|
|
|
|
u32 unlockSequence[] = { BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_B, BUTTON_A, BUTTON_START, BUTTON_SELECT },
|
|
sequenceSize = sizeof(unlockSequence) / sizeof(u32);
|
|
|
|
for(u32 correctPresses = 0; correctPresses < sequenceSize; correctPresses++)
|
|
{
|
|
if(waitInput() != unlockSequence[correctPresses])
|
|
shutdown(1, "Button sequence not entered correctly");
|
|
}
|
|
}
|
|
|
|
void shutdown(u32 mode, const char *message)
|
|
{
|
|
if(mode != 0)
|
|
{
|
|
posY = drawString(message, 10, posY + SPACING_Y, mode == 1 ? COLOR_RED : COLOR_GREEN);
|
|
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
|
|
waitInput();
|
|
}
|
|
|
|
clearScreens();
|
|
|
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
|
flushEntireDCache();
|
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0);
|
|
while(true);
|
|
} |