Added display sleep and reset

This commit is contained in:
Tomislav Kopić 2024-06-15 21:43:41 +02:00
parent 0fd7fcbc2d
commit e022c33a5c

View File

@ -14,7 +14,7 @@
/***** Tama Setting and Features *****/
#define TAMA_DISPLAY_FRAMERATE 10
//#define ENABLE_TAMA_SOUND
#define ENABLE_TAMA_SOUND
#define ENABLE_REAL_TIME
#define ENABLE_SAVE_STATUS
#define AUTO_SAVE_MINUTES 10 // Auto save for every 10 minutes
@ -60,7 +60,7 @@ U8G2_SSD1306_128X64_NONAME_2_HW_I2C display(U8G2_MIRROR);
#define PIN_BTN_M 13 // D7
#define PIN_BTN_R 15 // D8
//define PIN_BTN_SAVE 3
#define PIN_BUZZER 14 // D5
#define PIN_BUZZER 0 // D5
/**** TamaLib Specific Variables ****/
static uint16_t current_freq = 0;
@ -377,6 +377,9 @@ void setup() {
#endif
}
uint32_t middle_long_press_started = 0;
uint32_t right_long_press_started = 0;
bool is_display_off = false;
void loop() {
tamalib_mainloop_step_by_step();
@ -386,4 +389,28 @@ void loop() {
saveStateToEEPROM(&cpuState);
}
#endif
if (digitalRead(PIN_BTN_M) == HIGH && digitalRead(PIN_BTN_L) == HIGH) {
if (millis() - middle_long_press_started > 2000) {
eraseStateFromEEPROM();
#if defined(ESP8266) || defined(ESP32)
ESP.restart();
#endif
}
}
else {
middle_long_press_started = millis();
}
if (digitalRead(PIN_BTN_R) == HIGH) {
if (millis() - right_long_press_started > 2000) {
display.sleepOn();
is_display_off = true;
}
else if (is_display_off) {
display.sleepOff();
is_display_off = false;
}
}
else {
right_long_press_started = millis();
}
}