Skip to content

Commit

Permalink
Added a hidden power off feature
Browse files Browse the repository at this point in the history
Use <LEFT> + <START> to power off. This is still experimental.
  • Loading branch information
d0k3 committed Nov 5, 2015
1 parent 45f6f34 commit 6826048
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 11 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,23 @@ void Reboot()
while(true);
}


void PowerOff()
{
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0);
while (true);
}


int main()
{
ClearBottomScreen();
DebugClear();
InitFS();

ProcessMenu(menu, sizeof(menu) / sizeof(MenuInfo));
u32 menu_exit = ProcessMenu(menu, sizeof(menu) / sizeof(MenuInfo));

DeinitFS();
Reboot();
(menu_exit == MENU_EXIT_REBOOT) ? Reboot() : PowerOff();
return 0;
}
11 changes: 8 additions & 3 deletions source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ u32 ProcessEntry(MenuEntry* entry)
return pad_state;
}

void ProcessMenu(MenuInfo* info, u32 nMenus)
u32 ProcessMenu(MenuInfo* info, u32 nMenus)
{
MenuInfo mainMenu;
MenuInfo* currMenu = &mainMenu;
u32 index = 0;
u32 result = MENU_EXIT_REBOOT;

// build main menu structure from submenus
memset(&mainMenu, 0x00, sizeof(MenuInfo));
Expand Down Expand Up @@ -150,11 +151,15 @@ void ProcessMenu(MenuInfo* info, u32 nMenus)
index = 0;
} else if (pad_state & BUTTON_SELECT) {
pad_state = UnmountSd();
}else {
} else {
full_draw = false;
}
if (pad_state & BUTTON_START)
if (pad_state & BUTTON_START) {
result = (pad_state & BUTTON_LEFT) ? MENU_EXIT_POWEROFF : MENU_EXIT_REBOOT;
break;
}
DrawMenu(currMenu, index, full_draw, currMenu != &mainMenu);
}

return result;
}
5 changes: 4 additions & 1 deletion source/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "common.h"

#define MENU_EXIT_REBOOT 0
#define MENU_EXIT_POWEROFF 1

typedef struct {
char* name;
u32 (*function)(void);
Expand All @@ -15,4 +18,4 @@ typedef struct {
MenuEntry entries[12];
} MenuInfo;

void ProcessMenu(MenuInfo* info, u32 nMenus);
u32 ProcessMenu(MenuInfo* info, u32 nMenus);

0 comments on commit 6826048

Please sign in to comment.