Improve screensaver to be non-blocking

This commit is contained in:
jacob.eva 2024-08-30 15:31:20 +01:00
parent 9d68b58e2e
commit 17ad6d213d
No known key found for this signature in database
GPG Key ID: 0B92E083BBCCAA1E

View File

@ -129,8 +129,12 @@ uint8_t disp_ext_fb = false;
unsigned char fb[512]; unsigned char fb[512];
uint32_t last_disp_update = 0; uint32_t last_disp_update = 0;
int disp_update_interval = 1000/disp_target_fps; int disp_update_interval = 1000/disp_target_fps;
#define SCREENSAVER_TIME 500 // ms
uint32_t last_screensaver = 0; uint32_t last_screensaver = 0;
uint32_t screensaver_interval = 600000; uint32_t screensaver_interval = 600000;
bool screensaver_enabled = false;
uint32_t last_page_flip = 0; uint32_t last_page_flip = 0;
uint32_t last_interface_page_flip = 0; uint32_t last_interface_page_flip = 0;
int page_interval = 4000; int page_interval = 4000;
@ -1113,11 +1117,15 @@ void update_display(bool blank = false) {
update_stat_area(); update_stat_area();
update_disp_area(); update_disp_area();
display.display(); display.display();
if (millis()-last_screensaver >= screensaver_interval) { // Invert display to protect against OLED screen burn in
display.invertDisplay(1); if (millis()-last_screensaver >= screensaver_interval+SCREENSAVER_TIME && screensaver_enabled) {
delay(500);
display.invertDisplay(0); display.invertDisplay(0);
last_screensaver = millis(); last_screensaver = millis();
screensaver_enabled = false;
}
else if (millis()-last_screensaver >= screensaver_interval) {
display.invertDisplay(1);
screensaver_enabled = true;
} }
#elif DISP_H == 122 && (DISPLAY == EINK_BW || DISPLAY == EINK_3C) #elif DISP_H == 122 && (DISPLAY == EINK_BW || DISPLAY == EINK_3C)
display.setFullWindow(); display.setFullWindow();