Add persistent settings for brightness and auto-dim time to EEPROM

This commit is contained in:
Noah Axon 2023-09-27 08:29:27 -05:00
parent d4483f2bd1
commit 512785aba3
1 changed files with 52 additions and 15 deletions

View File

@ -16,8 +16,9 @@ String dayStamp;
String timeStamp; String timeStamp;
int cursor = 0; int cursor = 0;
int rotation = 1; int rotation = 1;
int brightness = 100;
bool rstOverride = false; bool rstOverride = false;
#define EEPROM_SIZE 1 #define EEPROM_SIZE 32
struct MENU { struct MENU {
char name[19]; char name[19];
@ -62,7 +63,7 @@ void screen_dim_proc() {
if (digitalRead(M5_BUTTON_RST) == LOW || digitalRead(M5_BUTTON_HOME) == LOW) { if (digitalRead(M5_BUTTON_RST) == LOW || digitalRead(M5_BUTTON_HOME) == LOW) {
if (screen_dim_dimmed) { if (screen_dim_dimmed) {
screen_dim_dimmed = false; screen_dim_dimmed = false;
M5.Axp.ScreenBreath(100); M5.Axp.ScreenBreath(brightness);
} }
int newtime = M5.Rtc.Second + screen_dim_time + 2; // hacky but needs a couple extra seconds added int newtime = M5.Rtc.Second + screen_dim_time + 2; // hacky but needs a couple extra seconds added
@ -123,7 +124,7 @@ void mmenu_loop() {
/// SETTINGS MENU /// /// SETTINGS MENU ///
MENU smenu[] = { MENU smenu[] = {
{ "set clock time", 3}, { "set clock time", 3},
{ "set dim time", 4}, { "brightness", 4},
{ "battery info", 6}, { "battery info", 6},
{ "rotation", 7}, { "rotation", 7},
{ "credits", 10}, { "credits", 10},
@ -164,12 +165,12 @@ void smenu_loop() {
/// Dimmer MENU /// /// Dimmer MENU ///
MENU dmenu[] = { MENU dmenu[] = {
{ "30 seconds", 30},
{ "25 seconds", 25},
{ "20 seconds", 20},
{ "15 seconds", 15},
{ "10 seconds", 10},
{ "5 seconds", 5}, { "5 seconds", 5},
{ "10 seconds", 10},
{ "15 seconds", 15},
{ "20 seconds", 20},
{ "25 seconds", 25},
{ "30 seconds", 30},
{ "back", screen_dim_time}, { "back", screen_dim_time},
}; };
@ -185,7 +186,11 @@ void dmenu_drawmenu() {
void dmenu_setup() { void dmenu_setup() {
M5.Lcd.setRotation(rotation); M5.Lcd.setRotation(rotation);
cursor = 0; M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 5, 1);
M5.Lcd.println("SET AUTO DIM TIME");
delay(1000);
cursor = (screen_dim_time / 5) - 1;
rstOverride = true; rstOverride = true;
dmenu_drawmenu(); dmenu_drawmenu();
delay(250); // Prevent switching after menu loads up delay(250); // Prevent switching after menu loads up
@ -199,9 +204,30 @@ void dmenu_loop() {
delay(250); delay(250);
} }
if (digitalRead(M5_BUTTON_HOME) == LOW) { if (digitalRead(M5_BUTTON_HOME) == LOW) {
screen_dim_time = dmenu[cursor].command;
EEPROM.write(1, screen_dim_time);
EEPROM.commit();
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 5, 1);
M5.Lcd.println("SET BRIGHTNESS");
delay(1000);
cursor = brightness / 10;
timeset_drawmenu(11);
while(digitalRead(M5_BUTTON_HOME) == HIGH) {
if (digitalRead(M5_BUTTON_RST) == LOW) {
cursor++;
cursor = cursor % 11 ;
timeset_drawmenu(11);
M5.Axp.ScreenBreath(10 * cursor);
delay(250);
}
}
brightness = 10 * cursor;
M5.Axp.ScreenBreath(brightness);
EEPROM.write(3, brightness);
EEPROM.commit();
rstOverride = false; rstOverride = false;
isSwitching = true; isSwitching = true;
screen_dim_time = dmenu[cursor].command;
current_proc = 2; current_proc = 2;
} }
} }
@ -788,18 +814,29 @@ void wsmenu_loop() {
/// ENTRY /// /// ENTRY ///
void setup() { void setup() {
M5.begin(); M5.begin();
M5.Axp.ScreenBreath(100); // Brightness EEPROM.begin(EEPROM_SIZE);
// Uncomment these to blow away EEPROM to factory settings - for testing purposes
//EEPROM.write(0, 255);
//EEPROM.write(1, 255);
//EEPROM.write(2, 255);
EEPROM.commit();
if(EEPROM.read(0) <= 3){
rotation = EEPROM.read(0);
} else {
rotation = 3;
EEPROM.write(0, rotation);
EEPROM.commit();
}
screen_dim_time = EEPROM.read(1) % 30;
brightness = EEPROM.read(2) % 100;
M5.Axp.ScreenBreath(brightness);
M5.Lcd.setRotation(rotation); M5.Lcd.setRotation(rotation);
M5.Lcd.setTextColor(GREEN, BLACK); M5.Lcd.setTextColor(GREEN, BLACK);
EEPROM.begin(EEPROM_SIZE);
rotation = EEPROM.read(0);
// Boot Screen // Boot Screen
digitalWrite(M5_LED, HIGH); //LEDOFF digitalWrite(M5_LED, HIGH); //LEDOFF
M5.Lcd.fillScreen(BLACK); M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(4); M5.Lcd.setTextSize(4);
M5.Lcd.setCursor(40, 15); M5.Lcd.setCursor(40, 15);
M5.Lcd.setRotation(rotation);
M5.Lcd.print("M5-NEMO\n"); M5.Lcd.print("M5-NEMO\n");
// Pin setup // Pin setup
pinMode(M5_LED, OUTPUT); pinMode(M5_LED, OUTPUT);