From d9cb64ec934a33d158def02b3a75c9c1e45acac0 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Fri, 30 Aug 2024 18:18:56 +0100 Subject: [PATCH] Make screensaver checks more efficient + add periodic refresh to RAK4631 --- Display.h | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Display.h b/Display.h index a23ca48..2166c91 100644 --- a/Display.h +++ b/Display.h @@ -106,15 +106,23 @@ void busyCallback(const void* p) { #if DISPLAY == OLED Adafruit_SSD1306 display(DISP_W, DISP_H, &Wire, DISP_RST); float disp_target_fps = 7; +#define SCREENSAVER_TIME 500 // ms +uint32_t last_screensaver = 0; +uint32_t screensaver_interval = 600000; // 10 minutes in ms +bool screensaver_enabled = false; #endif #endif #if BOARD_MODEL == BOARD_RAK4631 #if DISPLAY == EINK_BW GxEPD2_BW display(DISPLAY_MODEL(pin_disp_cs, pin_disp_dc, pin_disp_reset, pin_disp_busy)); float disp_target_fps = 0.2; +uint32_t last_epd_refresh = 0; +#define REFRESH_PERIOD 300000 // 5 minutes in ms #elif DISPLAY == EINK_3C GxEPD2_3C display(DISPLAY_MODEL(pin_disp_cs, pin_disp_dc, pin_disp_reset, pin_disp_busy)); -float disp_target_fps = 0.05; // refresh usually takes longer on 3C, hence 4x the refresh period +float disp_target_fps = 0.05; // refresh usually takes longer on 3C, hence this is 4x the BW refresh period +uint32_t last_epd_refresh = 0; +#define REFRESH_PERIOD 600000 // 10 minutes in ms #endif #else // add more eink compatible boards here @@ -130,11 +138,6 @@ unsigned char fb[512]; uint32_t last_disp_update = 0; int disp_update_interval = 1000/disp_target_fps; -#define SCREENSAVER_TIME 500 // ms -uint32_t last_screensaver = 0; -uint32_t screensaver_interval = 600000; -bool screensaver_enabled = false; - uint32_t last_page_flip = 0; uint32_t last_interface_page_flip = 0; int page_interval = 4000; @@ -1117,13 +1120,17 @@ void update_display(bool blank = false) { update_stat_area(); update_disp_area(); display.display(); + + uint32_t current = millis(); // Invert display to protect against OLED screen burn in - if (millis()-last_screensaver >= screensaver_interval+SCREENSAVER_TIME && screensaver_enabled) { - display.invertDisplay(0); - last_screensaver = millis(); - screensaver_enabled = false; + if (screensaver_enabled) { + if (current-last_screensaver >= screensaver_interval+SCREENSAVER_TIME) { + display.invertDisplay(0); + last_screensaver = current; + screensaver_enabled = false; + } } - else if (millis()-last_screensaver >= screensaver_interval) { + else if (current-last_screensaver >= screensaver_interval) { display.invertDisplay(1); screensaver_enabled = true; } @@ -1132,9 +1139,18 @@ void update_display(bool blank = false) { display.fillScreen(GxEPD_WHITE); update_stat_area(); update_disp_area(); - display.display(true); + + uint32_t current = millis(); + if (current-last_epd_refresh >= REFRESH_PERIOD) { + // Perform a full refresh after the correct time has elapsed + display.display(false); + last_epd_refresh = current; + } else { + // Only perform a partial refresh + display.display(true); + } #endif - last_disp_update = millis(); + last_disp_update = current; } } }