1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 20:06:43 +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);
}
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;
}
}

View file

@ -1,4 +1,4 @@
#pragma once
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 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);

View file

@ -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];