Improve power managment, fix display override
This commit is contained in:
parent
67325370d3
commit
9594bd84ee
19
src/main.cpp
19
src/main.cpp
@ -17,7 +17,7 @@ WiFiClient client;
|
|||||||
|
|
||||||
// Define NTP Client to get time
|
// Define NTP Client to get time
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600);
|
NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600, 43200000);
|
||||||
|
|
||||||
// Define these in config.h
|
// Define these in config.h
|
||||||
const String Location = LOCATION;
|
const String Location = LOCATION;
|
||||||
@ -60,10 +60,11 @@ void initSystems() {
|
|||||||
|
|
||||||
// Timers for dynamic updates
|
// Timers for dynamic updates
|
||||||
unsigned long lastWeatherUpdate = 0;
|
unsigned long lastWeatherUpdate = 0;
|
||||||
unsigned long lastDisplayUpdate = 0;
|
unsigned long lastDisplayOverride = 0;
|
||||||
const unsigned long weatherUpdateInterval = 1800000; // 30 minutes in milliseconds
|
const unsigned long weatherUpdateInterval = 1800000; // 30 minutes in milliseconds
|
||||||
const unsigned long displayOffInterval = 300000; // 5 minutes in milliseconds for power-saving mode
|
const unsigned long displayOverrideTimeout = 60000; // 1 minute in milliseconds
|
||||||
bool is_display_off = false;
|
bool is_display_off = false;
|
||||||
|
bool display_override = false;
|
||||||
|
|
||||||
void commonButtonHandler() {
|
void commonButtonHandler() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
@ -114,6 +115,7 @@ void commonButtonHandler() {
|
|||||||
if (is_display_off) {
|
if (is_display_off) {
|
||||||
display.ssd1306_command(SSD1306_DISPLAYON); // Turn on display
|
display.ssd1306_command(SSD1306_DISPLAYON); // Turn on display
|
||||||
is_display_off = false;
|
is_display_off = false;
|
||||||
|
display_override = true;
|
||||||
beep(1300);
|
beep(1300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,6 +147,7 @@ void commonButtonHandler() {
|
|||||||
beep(1300);
|
beep(1300);
|
||||||
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display
|
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display
|
||||||
is_display_off = true;
|
is_display_off = true;
|
||||||
|
display_override = false;
|
||||||
beep(1000);
|
beep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,13 +161,9 @@ void commonButtonHandler() {
|
|||||||
|
|
||||||
void powerSaveCheck() {
|
void powerSaveCheck() {
|
||||||
int currentHour = timeClient.getHours();
|
int currentHour = timeClient.getHours();
|
||||||
if ((currentHour >= 23 || currentHour < 6) && !is_display_off) {
|
if ((currentHour >= 22 || currentHour < 8) && !is_display_off && !display_override) {
|
||||||
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display for power-saving
|
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display for power-saving
|
||||||
is_display_off = true;
|
is_display_off = true;
|
||||||
lastDisplayUpdate = millis(); // Track when display was turned off
|
|
||||||
} else if (is_display_off && (millis() - lastDisplayUpdate > displayOffInterval)) {
|
|
||||||
display.ssd1306_command(SSD1306_DISPLAYON); // Turn display back on
|
|
||||||
is_display_off = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +322,10 @@ void setup(void) {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
timeClient.update();
|
timeClient.update();
|
||||||
|
if (display_override && (millis() - lastDisplayOverride > displayOverrideTimeout)){
|
||||||
|
display_override = false;
|
||||||
|
lastDisplayOverride = millis();
|
||||||
|
}
|
||||||
if (!is_display_off && (millis() - lastWeatherUpdate > weatherUpdateInterval)) {
|
if (!is_display_off && (millis() - lastWeatherUpdate > weatherUpdateInterval)) {
|
||||||
fetchWeatherData();
|
fetchWeatherData();
|
||||||
lastWeatherUpdate = millis();
|
lastWeatherUpdate = millis();
|
||||||
|
Loading…
Reference in New Issue
Block a user