Add a settings menu for TV-B-Gone Region

This commit is contained in:
Noah Axon 2023-09-28 19:36:37 -05:00
parent 96be87edc1
commit 150f23e389
2 changed files with 64 additions and 14 deletions

View File

@ -40,6 +40,7 @@ struct MENU {
// 10 - Credits // 10 - Credits
// 11 - Wifi beacon spam // 11 - Wifi beacon spam
// 12 - Wifi spam menu // 12 - Wifi spam menu
// 13 - TV-B-Gone Region Setting
bool isSwitching = true; bool isSwitching = true;
int current_proc = 0; // Start in Clock Mode int current_proc = 0; // Start in Clock Mode
@ -123,11 +124,12 @@ void mmenu_loop() {
/// SETTINGS MENU /// /// SETTINGS MENU ///
MENU smenu[] = { MENU smenu[] = {
{ "set clock time", 3},
{ "brightness", 4},
{ "battery info", 6}, { "battery info", 6},
{ "brightness", 4},
{ "set clock time", 3},
{ "rotation", 7}, { "rotation", 7},
{ "credits", 10}, { "tvbg region", 13},
{ "about", 10},
{ "back", 1}, { "back", 1},
}; };
@ -274,6 +276,47 @@ void rmenu_loop() {
} }
} }
/// TVBG-Region MENU ///
MENU tvbgmenu[] = {
{ "North America", 0},
{ "Europe", 1},
{ "back", region},
};
void tvbgmenu_drawmenu() {
M5.Lcd.setTextSize(2);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 8, 1);
for ( int i = 0 ; i < ( sizeof(tvbgmenu) / sizeof(MENU) ) ; i++ ) {
M5.Lcd.print((cursor == i) ? ">" : " ");
M5.Lcd.println(tvbgmenu[i].name);
}
}
void tvbgmenu_setup() {
cursor = 0;
rstOverride = true;
tvbgmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
}
void tvbgmenu_loop() {
if (digitalRead(M5_BUTTON_RST) == LOW) {
cursor++;
cursor = cursor % ( sizeof(tvbgmenu) / sizeof(MENU) );
tvbgmenu_drawmenu();
delay(250);
}
if (digitalRead(M5_BUTTON_HOME) == LOW) {
rstOverride = false;
isSwitching = true;
region = tvbgmenu[cursor].command;
EEPROM.write(3, region);
EEPROM.commit();
current_proc = 2;
}
}
/// BATTERY INFO /// /// BATTERY INFO ///
void battery_drawmenu(int battery, int b, int c) { void battery_drawmenu(int battery, int b, int c) {
M5.Lcd.setTextSize(2); M5.Lcd.setTextSize(2);
@ -323,12 +366,10 @@ void tvbgone_setup() {
digitalWrite(IRLED, HIGH); digitalWrite(IRLED, HIGH);
delay_ten_us(5000); delay_ten_us(5000);
if (digitalRead(REGIONSWITCH)) { if(region == NA) {
region = NA;
M5.Lcd.println("Region: NA"); M5.Lcd.println("Region: NA");
} }
else { else {
region = EU;
M5.Lcd.println("Region: EU"); M5.Lcd.println("Region: EU");
} }
delay(1000); // Give time after loading delay(1000); // Give time after loading
@ -836,24 +877,28 @@ void setup() {
M5.begin(); M5.begin();
EEPROM.begin(EEPROM_SIZE); EEPROM.begin(EEPROM_SIZE);
// Uncomment these to blow away EEPROM to factory settings - for testing purposes // Uncomment these to blow away EEPROM to factory settings - for testing purposes
//EEPROM.write(0, 255); //EEPROM.write(0, 255); // Rotation
//EEPROM.write(1, 255); //EEPROM.write(1, 255); // dim time
//EEPROM.write(2, 255); //EEPROM.write(2, 255); // brightness
//EEPROM.write(2, 255); // TV-B-Gone Region
//EEPROM.commit(); //EEPROM.commit();
Serial.printf("EEPROM 0: %d\n", EEPROM.read(0)); Serial.printf("EEPROM 0: %d\n", EEPROM.read(0));
Serial.printf("EEPROM 1: %d\n", EEPROM.read(1)); Serial.printf("EEPROM 1: %d\n", EEPROM.read(1));
Serial.printf("EEPROM 2: %d\n", EEPROM.read(2)); Serial.printf("EEPROM 2: %d\n", EEPROM.read(2));
Serial.printf("EEPROM 3: %d\n", EEPROM.read(3));
if(EEPROM.read(0) > 3){ if(EEPROM.read(0) > 3){
// Let's just assume rotation > 3 is a fresh/corrupt EEPROM and write defaults for everything // Let's just assume rotation > 3 is a fresh/corrupt EEPROM and write defaults for everything
Serial.println("EEPROM likely not properly configured. Writing defaults."); Serial.println("EEPROM likely not properly configured. Writing defaults.");
EEPROM.write(0, 3); // Left rotation EEPROM.write(0, 3); // Left rotation
EEPROM.write(1, 15); // 15 second auto dim time EEPROM.write(1, 15); // 15 second auto dim time
EEPROM.write(2, 100); // 100% brightness EEPROM.write(2, 100); // 100% brightness
EEPROM.write(3, 0); // TVBG NA Region
EEPROM.commit(); EEPROM.commit();
} }
rotation = EEPROM.read(0); rotation = EEPROM.read(0);
screen_dim_time = EEPROM.read(1); screen_dim_time = EEPROM.read(1);
brightness = EEPROM.read(2); brightness = EEPROM.read(2);
region = EEPROM.read(3);
M5.Axp.ScreenBreath(brightness); M5.Axp.ScreenBreath(brightness);
M5.Lcd.setRotation(rotation); M5.Lcd.setRotation(rotation);
M5.Lcd.setTextColor(GREEN, BLACK); M5.Lcd.setTextColor(GREEN, BLACK);
@ -929,6 +974,10 @@ void loop() {
break; break;
case 12: case 12:
wsmenu_setup(); wsmenu_setup();
break;
case 13:
tvbgmenu_setup();
break;
} }
} }
@ -971,5 +1020,9 @@ void loop() {
break; break;
case 12: case 12:
wsmenu_loop(); wsmenu_loop();
break;
case 13:
tvbgmenu_loop();
break;
} }
} }

7
tvbg.h
View File

@ -86,12 +86,9 @@ uint8_t region;
void sendAllCodes() void sendAllCodes()
{ {
bool endingEarly = false; //will be set to true if the user presses the button during code-sending bool endingEarly = false; //will be set to true if the user presses the button during code-sending
if (digitalRead(REGIONSWITCH)) { if (region == NA) {
region = NA;
num_codes = num_NAcodes; num_codes = num_NAcodes;
} } else {
else {
region = EU;
num_codes = num_EUcodes; num_codes = num_EUcodes;
} }
for (i = 0 ; i < num_codes; i++) for (i = 0 ; i < num_codes; i++)