1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-23 04:12:04 +00:00

Add SD mounting/unmounting code + fix menu bugs

This commit is contained in:
Such Meme, Many Skill 2019-11-21 17:34:47 +01:00
parent ff062a232b
commit 7b0faabf38
4 changed files with 46 additions and 29 deletions

View file

@ -10,7 +10,7 @@ void clearscreen(){
gfx_printf("%k%KTegraexplorer%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT); 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(); clearscreen();
gfx_printf("%k%s%k", color, message, COLOR_DEFAULT); gfx_printf("%k%s%k", color, message, COLOR_DEFAULT);
return btn_wait(); return btn_wait();
@ -22,11 +22,19 @@ int makemenu(menu_item menu[], int menuamount){
while (1){ while (1){
gfx_con_setpos(0, 31); 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++){ for (i = 0; i < menuamount; i++){
if (menu[i].property < 0) { if (menu[i].property < 0)
i--;
continue; continue;
}
if (i == currentpos - 1) if (i == currentpos - 1)
gfx_printf("%k%K%s%K\n", COLOR_DEFAULT, COLOR_WHITE, menu[i].name, COLOR_DEFAULT); gfx_printf("%k%K%s%K\n", COLOR_DEFAULT, COLOR_WHITE, menu[i].name, COLOR_DEFAULT);
else else
@ -36,16 +44,19 @@ int makemenu(menu_item menu[], int menuamount){
res = btn_wait(); res = btn_wait();
if (res & BTN_VOL_UP) if (res & BTN_VOL_UP && currentpos > 1){
currentpos--; 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++; currentpos++;
while(menu[currentpos - 1].property < 0 && currentpos < menuamount)
currentpos++;
}
else if (res & BTN_POWER) else if (res & BTN_POWER)
return menu[currentpos - 1].internal_function; return menu[currentpos - 1].internal_function;
if (currentpos > menuamount)
currentpos = menuamount;
else if (currentpos < 1)
currentpos = 1;
} }
} }

View file

@ -1,4 +1,4 @@
#pragma once #pragma once
int makemenu(menu_item menu[], int menuamount); int makemenu(menu_item menu[], int menuamount);
void message(char* message, u32 color); int message(char* message, u32 color);

View file

@ -6,6 +6,7 @@
extern bool sd_mount(); extern bool sd_mount();
extern void sd_unmount(); extern void sd_unmount();
bool sd_mounted = false;
menu_item mainmenu[MAINMENU_AMOUNT] = { menu_item mainmenu[MAINMENU_AMOUNT] = {
{"[SD:/] SD CARD", COLOR_GREEN, 1, 0}, {"[SD:/] SD CARD", COLOR_GREEN, 1, 0},
@ -23,32 +24,26 @@ menu_item shutdownmenu[4] = {
{"Back", COLOR_WHITE, 4, 0} {"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(){ void fillmainmenu(){
int i; int i;
for (i = 0; i < MAINMENU_AMOUNT; i++){ for (i = 0; i < MAINMENU_AMOUNT; i++){
switch (i + 1) { switch (i + 1) {
case 1: case 1:
if (sd_mount) if (sd_mounted)
mainmenu[i].property = 1; mainmenu[i].property = 1;
else else
mainmenu[i].property = -1; mainmenu[i].property = -1;
break; break;
case 3: case 3:
if (sd_mount) if (sd_mounted){
mainmenu[i].property = 1; mainmenu[i].property = 1;
else strcpy(mainmenu[i].name, "Unmount SD");
mainmenu[i].property = -1; }
else {
mainmenu[i].property = 0;
strcpy(mainmenu[i].name, "Mount SD");
}
break; break;
} }
} }
@ -57,12 +52,23 @@ void fillmainmenu(){
void te_main(){ void te_main(){
int res; int res;
sd_mounted = sd_mount();
while (1){ while (1){
fillmainmenu(); 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) if (res == 5)
message(CREDITS_MESSAGE, COLOR_GREEN); message(CREDITS_MESSAGE, COLOR_WHITE);
if (res == 6){ if (res == 6){
res = makemenu(shutdownmenu, 4); res = makemenu(shutdownmenu, 4);

View file

@ -2,7 +2,7 @@
#include "../utils/types.h" #include "../utils/types.h"
#define MAINMENU_AMOUNT 6 #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 { typedef struct _menu_item {
char name[50]; char name[50];