Просмотр исходного кода

gxepd: use a crc to track damage !

Florent 11 месяцев назад
Родитель
Сommit
9f97edcb21

+ 9 - 1
examples/companion_radio/ui-new/UITask.cpp

@@ -3,7 +3,9 @@
 #include "../MyMesh.h"
 #include "target.h"
 
-#define AUTO_OFF_MILLIS     15000   // 15 seconds
+#ifndef AUTO_OFF_MILLIS
+  #define AUTO_OFF_MILLIS     15000   // 15 seconds
+#endif
 #define BOOT_SCREEN_MILLIS   3000   // 3 seconds
 
 #ifdef PIN_STATUS_LED
@@ -321,7 +323,11 @@ public:
     display.setColor(DisplayDriver::LIGHT);
     display.printWordWrap(p->msg, display.width());
 
+#if AUTO_OFF_MILLIS==0 // probably e-ink
+    return 10000; // 10 s
+#else
     return 1000;  // next render after 1000 ms
+#endif
   }
 
   bool handleInput(char c) override {
@@ -556,9 +562,11 @@ void UITask::loop() {
       }
       _display->endFrame();
     }
+#if AUTO_OFF_MILLIS > 0
     if (millis() > _auto_off) {
       _display->turnOff();
     }
+#endif
   }
 
 #ifdef AUTO_SHUTDOWN_MILLIVOLTS

+ 25 - 1
src/helpers/ui/GxEPDDisplay.cpp

@@ -44,14 +44,17 @@ void GxEPDDisplay::turnOff() {
 void GxEPDDisplay::clear() {
   display.fillScreen(GxEPD_WHITE);
   display.setTextColor(GxEPD_BLACK);
+  display_crc.reset();
 }
 
 void GxEPDDisplay::startFrame(Color bkg) {
   display.fillScreen(GxEPD_WHITE);
   display.setTextColor(_curr_color = GxEPD_BLACK);
+  display_crc.reset();
 }
 
 void GxEPDDisplay::setTextSize(int sz) {
+  display_crc.update<int>(sz);
   switch(sz) {
     case 1:  // Small
       display.setFont(&FreeSans9pt7b);
@@ -69,6 +72,7 @@ void GxEPDDisplay::setTextSize(int sz) {
 }
 
 void GxEPDDisplay::setColor(Color c) {
+  display_crc.update<Color> (c);
   // colours need to be inverted for epaper displays
   if (c == DARK) {
     display.setTextColor(_curr_color = GxEPD_WHITE);
@@ -78,22 +82,38 @@ void GxEPDDisplay::setColor(Color c) {
 }
 
 void GxEPDDisplay::setCursor(int x, int y) {
+  display_crc.update<int>(x);
+  display_crc.update<int>(y);
   display.setCursor(x*SCALE_X, (y+10)*SCALE_Y);
 }
 
 void GxEPDDisplay::print(const char* str) {
+  display_crc.update<char>(str, strlen(str));
   display.print(str);
 }
 
 void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
+  display_crc.update<int>(x);
+  display_crc.update<int>(y);
+  display_crc.update<int>(w);
+  display_crc.update<int>(h);
   display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
 }
 
 void GxEPDDisplay::drawRect(int x, int y, int w, int h) {
+  display_crc.update<int>(x);
+  display_crc.update<int>(y);
+  display_crc.update<int>(w);
+  display_crc.update<int>(h);
   display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
 }
 
 void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
+  display_crc.update<int>(x);
+  display_crc.update<int>(y);
+  display_crc.update<int>(w);
+  display_crc.update<int>(h);
+  display_crc.update<uint8_t>(bits, w * h / 8);
   // Calculate the base position in display coordinates
   uint16_t startX = x * SCALE_X;
   uint16_t startY = y * SCALE_Y;
@@ -137,5 +157,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
 }
 
 void GxEPDDisplay::endFrame() {
-  display.display(true);
+  uint32_t crc = display_crc.finalize();
+  if (crc != last_display_crc_value) {
+    display.display(true);
+    last_display_crc_value = crc;
+  }
 }

+ 3 - 0
src/helpers/ui/GxEPDDisplay.h

@@ -17,6 +17,7 @@
 #define GxEPD2_DRIVER_CLASS GxEPD2_150_BN  // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1
 
 #include <epd/GxEPD2_150_BN.h>  // 1.54" b/w
+#include <CRC32.h>
 
 #include "DisplayDriver.h"
 
@@ -29,6 +30,8 @@ class GxEPDDisplay : public DisplayDriver {
   bool _init = false;
   bool _isOn = false;
   uint16_t _curr_color;
+  CRC32 display_crc;
+  int last_display_crc_value = 0;
 
 public:
   // there is a margin in y...

+ 2 - 1
variants/techo/platformio.ini

@@ -74,11 +74,12 @@ build_flags =
   -D MAX_CONTACTS=100
   -D MAX_GROUP_CHANNELS=8
   -D BLE_PIN_CODE=123456
-  -D BLE_DEBUG_LOGGING=1
+;  -D BLE_DEBUG_LOGGING=1
   -D DISPLAY_CLASS=GxEPDDisplay
   -D OFFLINE_QUEUE_SIZE=256
   -D UI_RECENT_LIST_SIZE=9
   -D BACKLIGHT_BTN=PIN_BUTTON2
+  -D AUTO_OFF_MILLIS=0
 ;  -D MESH_PACKET_LOGGING=1
 ;  -D MESH_DEBUG=1
 build_src_filter = ${LilyGo_Techo.build_src_filter}