Skip to content

Commit 9f97edc

Browse files
committed
gxepd: use a crc to track damage !
1 parent cb3049e commit 9f97edc

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "../MyMesh.h"
44
#include "target.h"
55

6-
#define AUTO_OFF_MILLIS 15000 // 15 seconds
6+
#ifndef AUTO_OFF_MILLIS
7+
#define AUTO_OFF_MILLIS 15000 // 15 seconds
8+
#endif
79
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
810

911
#ifdef PIN_STATUS_LED
@@ -321,7 +323,11 @@ class MsgPreviewScreen : public UIScreen {
321323
display.setColor(DisplayDriver::LIGHT);
322324
display.printWordWrap(p->msg, display.width());
323325

326+
#if AUTO_OFF_MILLIS==0 // probably e-ink
327+
return 10000; // 10 s
328+
#else
324329
return 1000; // next render after 1000 ms
330+
#endif
325331
}
326332

327333
bool handleInput(char c) override {
@@ -556,9 +562,11 @@ void UITask::loop() {
556562
}
557563
_display->endFrame();
558564
}
565+
#if AUTO_OFF_MILLIS > 0
559566
if (millis() > _auto_off) {
560567
_display->turnOff();
561568
}
569+
#endif
562570
}
563571

564572
#ifdef AUTO_SHUTDOWN_MILLIVOLTS

src/helpers/ui/GxEPDDisplay.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ void GxEPDDisplay::turnOff() {
4444
void GxEPDDisplay::clear() {
4545
display.fillScreen(GxEPD_WHITE);
4646
display.setTextColor(GxEPD_BLACK);
47+
display_crc.reset();
4748
}
4849

4950
void GxEPDDisplay::startFrame(Color bkg) {
5051
display.fillScreen(GxEPD_WHITE);
5152
display.setTextColor(_curr_color = GxEPD_BLACK);
53+
display_crc.reset();
5254
}
5355

5456
void GxEPDDisplay::setTextSize(int sz) {
57+
display_crc.update<int>(sz);
5558
switch(sz) {
5659
case 1: // Small
5760
display.setFont(&FreeSans9pt7b);
@@ -69,6 +72,7 @@ void GxEPDDisplay::setTextSize(int sz) {
6972
}
7073

7174
void GxEPDDisplay::setColor(Color c) {
75+
display_crc.update<Color> (c);
7276
// colours need to be inverted for epaper displays
7377
if (c == DARK) {
7478
display.setTextColor(_curr_color = GxEPD_WHITE);
@@ -78,22 +82,38 @@ void GxEPDDisplay::setColor(Color c) {
7882
}
7983

8084
void GxEPDDisplay::setCursor(int x, int y) {
85+
display_crc.update<int>(x);
86+
display_crc.update<int>(y);
8187
display.setCursor(x*SCALE_X, (y+10)*SCALE_Y);
8288
}
8389

8490
void GxEPDDisplay::print(const char* str) {
91+
display_crc.update<char>(str, strlen(str));
8592
display.print(str);
8693
}
8794

8895
void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
96+
display_crc.update<int>(x);
97+
display_crc.update<int>(y);
98+
display_crc.update<int>(w);
99+
display_crc.update<int>(h);
89100
display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
90101
}
91102

92103
void GxEPDDisplay::drawRect(int x, int y, int w, int h) {
104+
display_crc.update<int>(x);
105+
display_crc.update<int>(y);
106+
display_crc.update<int>(w);
107+
display_crc.update<int>(h);
93108
display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
94109
}
95110

96111
void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
112+
display_crc.update<int>(x);
113+
display_crc.update<int>(y);
114+
display_crc.update<int>(w);
115+
display_crc.update<int>(h);
116+
display_crc.update<uint8_t>(bits, w * h / 8);
97117
// Calculate the base position in display coordinates
98118
uint16_t startX = x * SCALE_X;
99119
uint16_t startY = y * SCALE_Y;
@@ -137,5 +157,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
137157
}
138158

139159
void GxEPDDisplay::endFrame() {
140-
display.display(true);
160+
uint32_t crc = display_crc.finalize();
161+
if (crc != last_display_crc_value) {
162+
display.display(true);
163+
last_display_crc_value = crc;
164+
}
141165
}

src/helpers/ui/GxEPDDisplay.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1
1818

1919
#include <epd/GxEPD2_150_BN.h> // 1.54" b/w
20+
#include <CRC32.h>
2021

2122
#include "DisplayDriver.h"
2223

@@ -29,6 +30,8 @@ class GxEPDDisplay : public DisplayDriver {
2930
bool _init = false;
3031
bool _isOn = false;
3132
uint16_t _curr_color;
33+
CRC32 display_crc;
34+
int last_display_crc_value = 0;
3235

3336
public:
3437
// there is a margin in y...

variants/techo/platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ build_flags =
7474
-D MAX_CONTACTS=100
7575
-D MAX_GROUP_CHANNELS=8
7676
-D BLE_PIN_CODE=123456
77-
-D BLE_DEBUG_LOGGING=1
77+
; -D BLE_DEBUG_LOGGING=1
7878
-D DISPLAY_CLASS=GxEPDDisplay
7979
-D OFFLINE_QUEUE_SIZE=256
8080
-D UI_RECENT_LIST_SIZE=9
8181
-D BACKLIGHT_BTN=PIN_BUTTON2
82+
-D AUTO_OFF_MILLIS=0
8283
; -D MESH_PACKET_LOGGING=1
8384
; -D MESH_DEBUG=1
8485
build_src_filter = ${LilyGo_Techo.build_src_filter}

0 commit comments

Comments
 (0)