From 7b0faabf3885105d6587e726f93ad8ca54fee4ba Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Thu, 21 Nov 2019 17:34:47 +0100 Subject: [PATCH] Add SD mounting/unmounting code + fix menu bugs --- source/tegraexplorer/gfx.c | 33 ++++++++++++++++++++++----------- source/tegraexplorer/gfx.h | 2 +- source/tegraexplorer/te.c | 38 ++++++++++++++++++++++---------------- source/tegraexplorer/te.h | 2 +- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/source/tegraexplorer/gfx.c b/source/tegraexplorer/gfx.c index 4f5cccc..c75f4f7 100644 --- a/source/tegraexplorer/gfx.c +++ b/source/tegraexplorer/gfx.c @@ -10,7 +10,7 @@ void clearscreen(){ gfx_printf("%k%KTegraexplorer%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT); } -void message(char* message, u32 color){ +int message(char* message, u32 color){ clearscreen(); gfx_printf("%k%s%k", color, message, COLOR_DEFAULT); return btn_wait(); @@ -22,11 +22,19 @@ int makemenu(menu_item menu[], int menuamount){ while (1){ gfx_con_setpos(0, 31); + + if (currentpos == 1){ + while (currentpos < menuamount && menu[currentpos - 1].property < 0) + currentpos++; + } + if (currentpos == menuamount){ + while (currentpos > 1 && menu[currentpos - 1].property < 0) + currentpos--; + } + for (i = 0; i < menuamount; i++){ - if (menu[i].property < 0) { - i--; + if (menu[i].property < 0) continue; - } if (i == currentpos - 1) gfx_printf("%k%K%s%K\n", COLOR_DEFAULT, COLOR_WHITE, menu[i].name, COLOR_DEFAULT); else @@ -36,16 +44,19 @@ int makemenu(menu_item menu[], int menuamount){ res = btn_wait(); - if (res & BTN_VOL_UP) + if (res & BTN_VOL_UP && currentpos > 1){ currentpos--; - else if (res & BTN_VOL_DOWN) + while(menu[currentpos - 1].property < 0 && currentpos > 1) + currentpos--; + } + + else if (res & BTN_VOL_DOWN && currentpos < menuamount){ currentpos++; + while(menu[currentpos - 1].property < 0 && currentpos < menuamount) + currentpos++; + } + else if (res & BTN_POWER) return menu[currentpos - 1].internal_function; - - if (currentpos > menuamount) - currentpos = menuamount; - else if (currentpos < 1) - currentpos = 1; } } \ No newline at end of file diff --git a/source/tegraexplorer/gfx.h b/source/tegraexplorer/gfx.h index 8a361bb..bdae328 100644 --- a/source/tegraexplorer/gfx.h +++ b/source/tegraexplorer/gfx.h @@ -1,4 +1,4 @@ #pragma once int makemenu(menu_item menu[], int menuamount); -void message(char* message, u32 color); \ No newline at end of file +int message(char* message, u32 color); \ No newline at end of file diff --git a/source/tegraexplorer/te.c b/source/tegraexplorer/te.c index b7c0d3f..e210a2a 100644 --- a/source/tegraexplorer/te.c +++ b/source/tegraexplorer/te.c @@ -6,6 +6,7 @@ extern bool sd_mount(); extern void sd_unmount(); +bool sd_mounted = false; menu_item mainmenu[MAINMENU_AMOUNT] = { {"[SD:/] SD CARD", COLOR_GREEN, 1, 0}, @@ -23,32 +24,26 @@ menu_item shutdownmenu[4] = { {"Back", COLOR_WHITE, 4, 0} }; -int calcmenuitems(){ - int amount = 0, i; - - for (i = 0; i < MAINMENU_AMOUNT; i++) - if (mainmenu[i].property >= 0) - amount++; - - return amount; -} - void fillmainmenu(){ int i; for (i = 0; i < MAINMENU_AMOUNT; i++){ switch (i + 1) { case 1: - if (sd_mount) + if (sd_mounted) mainmenu[i].property = 1; else mainmenu[i].property = -1; break; case 3: - if (sd_mount) + if (sd_mounted){ mainmenu[i].property = 1; - else - mainmenu[i].property = -1; + strcpy(mainmenu[i].name, "Unmount SD"); + } + else { + mainmenu[i].property = 0; + strcpy(mainmenu[i].name, "Mount SD"); + } break; } } @@ -57,12 +52,23 @@ void fillmainmenu(){ void te_main(){ int res; + sd_mounted = sd_mount(); + while (1){ fillmainmenu(); - res = makemenu(mainmenu, calcmenuitems()); + res = makemenu(mainmenu, MAINMENU_AMOUNT); + + if (res == 3){ + if (sd_mounted){ + sd_mounted = false; + sd_unmount(); + } + else + sd_mounted = sd_mount(); + } if (res == 5) - message(CREDITS_MESSAGE, COLOR_GREEN); + message(CREDITS_MESSAGE, COLOR_WHITE); if (res == 6){ res = makemenu(shutdownmenu, 4); diff --git a/source/tegraexplorer/te.h b/source/tegraexplorer/te.h index 68e000e..8247463 100644 --- a/source/tegraexplorer/te.h +++ b/source/tegraexplorer/te.h @@ -2,7 +2,7 @@ #include "../utils/types.h" #define MAINMENU_AMOUNT 6 -#define CREDITS_MESSAGE "Tegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax" +#define CREDITS_MESSAGE "\nTegraexplorer, made by:\nSuch Meme, Many Skill\n\nProject based on:\nLockpick_RCM\nHekate\n\nCool people:\nshchmue\ndennthecafebabe\nDax" typedef struct _menu_item { char name[50];