Merge pull request #38 from n0xa/menu

Refactor menus
This commit is contained in:
Noah Axon 2023-12-29 00:14:47 -06:00 committed by GitHub
commit b8ece62e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 135 additions and 192 deletions

View File

@ -8,7 +8,7 @@
//#define CARDPUTER //#define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=- // -=-=- Uncommenting more than one at a time will result in errors -=-=-
String buildver="2.1.1"; String buildver="2.1.2";
#define BGCOLOR BLACK #define BGCOLOR BLACK
#define FGCOLOR GREEN #define FGCOLOR GREEN
@ -172,6 +172,44 @@ bool isSwitching = true;
int current_proc = 1; // Start in Main Menu mode if no RTC int current_proc = 1; // Start in Main Menu mode if no RTC
#endif #endif
void drawmenu(MENU thismenu[], int size) {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1);
// scrolling menu
if (cursor > 5) {
for ( int i = 0 + (cursor - 5) ; i < size ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(thismenu[i].name);
}
} else {
for (
int i = 0 ; i < size ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(thismenu[i].name);
}
}
}
void number_drawmenu(int nums) {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1);
// scrolling menu
if (cursor > 5) {
for ( int i = 0 + (cursor - 5) ; i < nums ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(i);
}
} else {
for (
int i = 0 ; i < nums ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(i);
}
}
}
void switcher_button_proc() { void switcher_button_proc() {
if (rstOverride == false) { if (rstOverride == false) {
if (check_next_press()) { if (check_next_press()) {
@ -250,29 +288,20 @@ MENU mmenu[] = {
{ "QR Codes", 18}, { "QR Codes", 18},
{ "Settings", 2}, { "Settings", 2},
}; };
int mmenu_size = sizeof(mmenu) / sizeof(MENU);
void mmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(mmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(mmenu[i].name);
}
}
void mmenu_setup() { void mmenu_setup() {
cursor = 0; cursor = 0;
rstOverride = true; rstOverride = true;
mmenu_drawmenu(); drawmenu(mmenu, mmenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void mmenu_loop() { void mmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(mmenu) / sizeof(MENU) ); cursor = cursor % mmenu_size;
mmenu_drawmenu(); drawmenu(mmenu, mmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -330,16 +359,7 @@ void screen_dim_proc() {
{ "25 seconds", 25}, { "25 seconds", 25},
{ "30 seconds", 30}, { "30 seconds", 30},
}; };
int dmenu_size = sizeof(dmenu) / sizeof(MENU);
void dmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(dmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(dmenu[i].name);
}
}
void dmenu_setup() { void dmenu_setup() {
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
@ -348,15 +368,15 @@ void screen_dim_proc() {
delay(1000); delay(1000);
cursor = (screen_dim_time / 5) - 1; cursor = (screen_dim_time / 5) - 1;
rstOverride = true; rstOverride = true;
dmenu_drawmenu(); drawmenu(dmenu, dmenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void dmenu_loop() { void dmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(dmenu) / sizeof(MENU) ); cursor = cursor % dmenu_size;
dmenu_drawmenu(); drawmenu(dmenu, dmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -370,12 +390,12 @@ void screen_dim_proc() {
DISP.println("SET BRIGHTNESS"); DISP.println("SET BRIGHTNESS");
delay(1000); delay(1000);
cursor = brightness / 10; cursor = brightness / 10;
timeset_drawmenu(11); number_drawmenu(11);
while( !check_select_press()) { while( !check_select_press()) {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % 11 ; cursor = cursor % 11 ;
timeset_drawmenu(11); number_drawmenu(11);
screenBrightness(10 * cursor); screenBrightness(10 * cursor);
delay(250); delay(250);
} }
@ -409,29 +429,20 @@ MENU smenu[] = {
{ "Clear Settings", 99}, { "Clear Settings", 99},
#endif #endif
}; };
int smenu_size = sizeof(smenu) / sizeof (MENU);
void smenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(smenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(smenu[i].name);
}
}
void smenu_setup() { void smenu_setup() {
cursor = 0; cursor = 0;
rstOverride = true; rstOverride = true;
smenu_drawmenu(); drawmenu(smenu, smenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void smenu_loop() { void smenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(smenu) / sizeof(MENU) ); cursor = cursor % smenu_size;
smenu_drawmenu(); drawmenu(smenu, smenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -459,29 +470,20 @@ int rotation = 1;
{ "Right", 1}, { "Right", 1},
{ "Left", 3}, { "Left", 3},
}; };
int rmenu_size = sizeof(rmenu) / sizeof (MENU);
void rmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(rmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(rmenu[i].name);
}
}
void rmenu_setup() { void rmenu_setup() {
cursor = 0; cursor = 0;
rstOverride = true; rstOverride = true;
rmenu_drawmenu(); drawmenu(rmenu, rmenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void rmenu_loop() { void rmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(rmenu) / sizeof(MENU) ); cursor = cursor % rmenu_size;
rmenu_drawmenu(); drawmenu(rmenu, rmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -500,6 +502,7 @@ int rotation = 1;
#if defined(AXP) #if defined(AXP)
/// BATTERY INFO /// /// BATTERY INFO ///
int oldbattery=0;
void battery_drawmenu(int battery, int b, int c) { void battery_drawmenu(int battery, int b, int c) {
DISP.setTextSize(SMALL_TEXT); DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
@ -528,12 +531,15 @@ int rotation = 1;
float c = M5.Axp.GetVapsData() * 1.4 / 1000; float c = M5.Axp.GetVapsData() * 1.4 / 1000;
float b = M5.Axp.GetVbatData() * 1.1 / 1000; float b = M5.Axp.GetVbatData() * 1.1 / 1000;
int battery = ((b - 3.0) / 1.2) * 100; int battery = ((b - 3.0) / 1.2) * 100;
if (battery != oldbattery){
battery_drawmenu(battery, b, c); battery_drawmenu(battery, b, c);
}
if (check_select_press()) { if (check_select_press()) {
rstOverride = false; rstOverride = false;
isSwitching = true; isSwitching = true;
current_proc = 1; current_proc = 1;
} }
oldbattery = battery;
} }
#endif // AXP #endif // AXP
@ -575,16 +581,7 @@ MENU tvbgmenu[] = {
{ "Americas / Asia", 0}, { "Americas / Asia", 0},
{ "EU/MidEast/Africa", 1}, { "EU/MidEast/Africa", 1},
}; };
int tvbgmenu_size = sizeof(tvbgmenu) / sizeof (MENU);
void tvbgmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(tvbgmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(tvbgmenu[i].name);
}
}
void tvbgmenu_setup() { void tvbgmenu_setup() {
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
@ -596,14 +593,14 @@ void tvbgmenu_setup() {
cursor = region % 2; cursor = region % 2;
rstOverride = true; rstOverride = true;
delay(1000); delay(1000);
tvbgmenu_drawmenu(); drawmenu(tvbgmenu, tvbgmenu_size);
} }
void tvbgmenu_loop() { void tvbgmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(tvbgmenu) / sizeof(MENU) ); cursor = cursor % tvbgmenu_size;
tvbgmenu_drawmenu(); drawmenu(tvbgmenu, tvbgmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -709,24 +706,6 @@ void sendAllCodes() {
/// CLOCK /// /// CLOCK ///
/// TIMESET /// /// TIMESET ///
void timeset_drawmenu(int nums) {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1);
// scrolling menu
if (cursor > 5) {
for ( int i = 0 + (cursor - 5) ; i < nums ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(i);
}
} else {
for (
int i = 0 ; i < nums ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(i);
}
}
}
#if defined(RTC) #if defined(RTC)
void clock_setup() { void clock_setup() {
@ -753,12 +732,12 @@ void sendAllCodes() {
void timeset_loop() { void timeset_loop() {
M5.Rtc.GetBm8563Time(); M5.Rtc.GetBm8563Time();
cursor = M5.Rtc.Hour; cursor = M5.Rtc.Hour;
timeset_drawmenu(24); number_drawmenu(24);
while(digitalRead(M5_BUTTON_HOME) == HIGH) { while(digitalRead(M5_BUTTON_HOME) == HIGH) {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % 24 ; cursor = cursor % 24 ;
timeset_drawmenu(24); number_drawmenu(24);
delay(100); delay(100);
} }
} }
@ -768,12 +747,12 @@ void sendAllCodes() {
DISP.println("SET MINUTE"); DISP.println("SET MINUTE");
delay(2000); delay(2000);
cursor = M5.Rtc.Minute; cursor = M5.Rtc.Minute;
timeset_drawmenu(60); number_drawmenu(60);
while(digitalRead(M5_BUTTON_HOME) == HIGH) { while(digitalRead(M5_BUTTON_HOME) == HIGH) {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % 60 ; cursor = cursor % 60 ;
timeset_drawmenu(60); number_drawmenu(60);
delay(100); delay(100);
} }
} }
@ -803,16 +782,7 @@ MENU btmenu[] = {
{ "SourApple Crash", 2}, { "SourApple Crash", 2},
{ "BT Maelstrom", 3}, { "BT Maelstrom", 3},
}; };
int btmenu_size = sizeof(btmenu) / sizeof (MENU);
void btmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(btmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(btmenu[i].name);
}
}
void btmenu_setup() { void btmenu_setup() {
cursor = 0; cursor = 0;
@ -821,15 +791,15 @@ void btmenu_setup() {
maelstrom = false; maelstrom = false;
androidPair = false; androidPair = false;
rstOverride = true; rstOverride = true;
btmenu_drawmenu(); drawmenu(btmenu, btmenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void btmenu_loop() { void btmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(btmenu) / sizeof(MENU) ); cursor = cursor % btmenu_size;
btmenu_drawmenu(); drawmenu(btmenu, btmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -922,25 +892,7 @@ MENU ajmenu[] = {
{ "TV Color Balance", 26}, { "TV Color Balance", 26},
{ "Setup New Phone", 28}, { "Setup New Phone", 28},
}; };
int ajmenu_size = sizeof(ajmenu) / sizeof (MENU);
void aj_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1);
// scrolling menu
if (cursor > 5) {
for ( int i = 0 + (cursor - 5) ; i < ( sizeof(ajmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(ajmenu[i].name);
}
} else {
for (
int i = 0 ; i < ( sizeof(ajmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(ajmenu[i].name);
}
}
}
void aj_setup(){ void aj_setup(){
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
@ -953,15 +905,15 @@ void aj_setup(){
swiftPair = false; swiftPair = false;
maelstrom = false; maelstrom = false;
rstOverride = true; rstOverride = true;
aj_drawmenu(); drawmenu(ajmenu, ajmenu_size);
} }
void aj_loop(){ void aj_loop(){
if (!maelstrom){ if (!maelstrom){
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(ajmenu) / sizeof(MENU) ); cursor = cursor % ajmenu_size;
aj_drawmenu(); drawmenu(ajmenu, ajmenu_size);
delay(100); delay(100);
} }
} }
@ -1197,11 +1149,11 @@ void aj_adv(){
if (sourApple || swiftPair || androidPair || maelstrom){ if (sourApple || swiftPair || androidPair || maelstrom){
isSwitching = true; isSwitching = true;
current_proc = 16; current_proc = 16;
btmenu_drawmenu(); drawmenu(btmenu, btmenu_size);
} else { } else {
isSwitching = true; isSwitching = true;
current_proc = 8; current_proc = 8;
aj_drawmenu(); drawmenu(ajmenu, ajmenu_size);
} }
sourApple = false; sourApple = false;
swiftPair = false; swiftPair = false;
@ -1367,29 +1319,20 @@ MENU wsmenu[] = {
{ "Spam Rickroll", 2}, { "Spam Rickroll", 2},
{ "Spam Random", 3}, { "Spam Random", 3},
}; };
int wsmenu_size = sizeof(wsmenu) / sizeof (MENU);
void wsmenu_drawmenu() {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(wsmenu) / sizeof(MENU) ) ; i++ ) {
DISP.print((cursor == i) ? ">" : " ");
DISP.println(wsmenu[i].name);
}
}
void wsmenu_setup() { void wsmenu_setup() {
cursor = 0; cursor = 0;
rstOverride = true; rstOverride = true;
wsmenu_drawmenu(); drawmenu(wsmenu, wsmenu_size);
delay(500); // Prevent switching after menu loads up delay(500); // Prevent switching after menu loads up
} }
void wsmenu_loop() { void wsmenu_loop() {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(wsmenu) / sizeof(MENU) ); cursor = cursor % wsmenu_size;
wsmenu_drawmenu(); drawmenu(wsmenu, wsmenu_size);
delay(250); delay(250);
} }
if (check_select_press()) { if (check_select_press()) {
@ -1547,7 +1490,7 @@ void bootScreen(){
while(true){ while(true){
M5Cardputer.update(); M5Cardputer.update();
if (M5Cardputer.Keyboard.isChange()) { if (M5Cardputer.Keyboard.isChange()) {
mmenu_drawmenu(); drawmenu(mmenu, mmenu_size);
delay(250); delay(250);
break; break;
} }