From c80a4caab008997da5d42f470efbdedd2ae53765 Mon Sep 17 00:00:00 2001 From: jeremy Date: Thu, 29 Aug 2024 18:41:52 -0400 Subject: [PATCH 1/5] Adds a rudimentary screen saver that briefly (500ms) inverts the screen every 10 minutes on OLED displays to prevent burn-in. --- Display.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Display.h b/Display.h index 86f5055..ec36120 100644 --- a/Display.h +++ b/Display.h @@ -129,6 +129,8 @@ uint8_t disp_ext_fb = false; unsigned char fb[512]; uint32_t last_disp_update = 0; int disp_update_interval = 1000/disp_target_fps; +uint32_t last_screensaver = 0; +uint32_t screensaver_interval = 600000; uint32_t last_page_flip = 0; uint32_t last_interface_page_flip = 0; int page_interval = 4000; @@ -1111,6 +1113,12 @@ void update_display(bool blank = false) { update_stat_area(); update_disp_area(); display.display(); + if (millis()-last_screensaver >= screensaver_interval) { + display.invertDisplay(1); + delay(500); + display.invertDisplay(0); + last_screensaver = millis(); + } #elif DISP_H == 122 && (DISPLAY == EINK_BW || DISPLAY == EINK_3C) display.setFullWindow(); display.fillScreen(GxEPD_WHITE); From 17ad6d213d192f203cfb7fb4c1461f4f14e98e8b Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Fri, 30 Aug 2024 15:31:20 +0100 Subject: [PATCH 2/5] Improve screensaver to be non-blocking --- Display.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Display.h b/Display.h index ec36120..a23ca48 100644 --- a/Display.h +++ b/Display.h @@ -129,8 +129,12 @@ uint8_t disp_ext_fb = false; 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; @@ -1113,11 +1117,15 @@ void update_display(bool blank = false) { update_stat_area(); update_disp_area(); display.display(); - if (millis()-last_screensaver >= screensaver_interval) { + // 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; + } + else if (millis()-last_screensaver >= screensaver_interval) { display.invertDisplay(1); - delay(500); - display.invertDisplay(0); - last_screensaver = millis(); + screensaver_enabled = true; } #elif DISP_H == 122 && (DISPLAY == EINK_BW || DISPLAY == EINK_3C) display.setFullWindow(); From 8686ee78440c0dd80728c8d07bb0ddaf1396e54f Mon Sep 17 00:00:00 2001 From: jeremy Date: Fri, 30 Aug 2024 11:54:12 -0400 Subject: [PATCH 3/5] makes SCREENSAVER_INTERVAL a #define to save some ram --- Display.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Display.h b/Display.h index a23ca48..2aec8df 100644 --- a/Display.h +++ b/Display.h @@ -131,8 +131,8 @@ uint32_t last_disp_update = 0; int disp_update_interval = 1000/disp_target_fps; #define SCREENSAVER_TIME 500 // ms +#define SCREENSAVER_INTERVAL 600000 // ms uint32_t last_screensaver = 0; -uint32_t screensaver_interval = 600000; bool screensaver_enabled = false; uint32_t last_page_flip = 0; @@ -1118,12 +1118,12 @@ void update_display(bool blank = false) { update_disp_area(); display.display(); // Invert display to protect against OLED screen burn in - if (millis()-last_screensaver >= screensaver_interval+SCREENSAVER_TIME && screensaver_enabled) { + if (millis()-last_screensaver >= SCREENSAVER_INTERVAL+SCREENSAVER_TIME && screensaver_enabled) { display.invertDisplay(0); last_screensaver = millis(); screensaver_enabled = false; } - else if (millis()-last_screensaver >= screensaver_interval) { + else if (millis()-last_screensaver >= SCREENSAVER_INTERVAL) { display.invertDisplay(1); screensaver_enabled = true; } From d9cb64ec934a33d158def02b3a75c9c1e45acac0 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Fri, 30 Aug 2024 18:18:56 +0100 Subject: [PATCH 4/5] 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; } } } From 06b468399377af0d9179d1d26358e3aa327b7a19 Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Sat, 31 Aug 2024 21:46:07 +0100 Subject: [PATCH 5/5] Fix BLE pairing state on NRF52 --- Bluetooth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bluetooth.h b/Bluetooth.h index 18b3051..6329964 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -339,7 +339,7 @@ bool bt_setup_hw() { Bluefruit.Security.setMITM(true); Bluefruit.Security.setPairPasskeyCallback(bt_passkey_callback); - Bluefruit.Periph.setConnectCallback(bt_connect_callback); + Bluefruit.Security.setSecuredCallback(bt_connect_callback); Bluefruit.Periph.setDisconnectCallback(bt_disconnect_callback); Bluefruit.Security.setPairCompleteCallback(bt_pairing_complete); const ble_gap_addr_t gap_addr = Bluefruit.getAddr();