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