Skip to content

Commit 6334971

Browse files
authored
Merge pull request #722 from fdlamotte/techo_epd_damage
Techo epd damage
2 parents a93a0fe + 9f97edc commit 6334971

File tree

5 files changed

+69
-21
lines changed

5 files changed

+69
-21
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 28 additions & 17 deletions
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 {
@@ -419,38 +425,34 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
419425
if (_display != NULL) {
420426
if (!_display->isOn()) _display->turnOn();
421427
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
422-
_next_refresh = 0; // trigger refresh
428+
_next_refresh = 100; // trigger refresh
423429
}
424430
}
425431

426432
void UITask::userLedHandler() {
427433
#ifdef PIN_STATUS_LED
428-
static int state = 0;
429-
static int next_change = 0;
430-
static int last_increment = 0;
431-
432434
int cur_time = millis();
433-
if (cur_time > next_change) {
434-
if (state == 0) {
435-
state = 1;
435+
if (cur_time > next_led_change) {
436+
if (led_state == 0) {
437+
led_state = 1;
436438
if (_msgcount > 0) {
437-
last_increment = LED_ON_MSG_MILLIS;
439+
last_led_increment = LED_ON_MSG_MILLIS;
438440
} else {
439-
last_increment = LED_ON_MILLIS;
441+
last_led_increment = LED_ON_MILLIS;
440442
}
441-
next_change = cur_time + last_increment;
443+
next_led_change = cur_time + last_led_increment;
442444
} else {
443-
state = 0;
444-
next_change = cur_time + LED_CYCLE_MILLIS - last_increment;
445+
led_state = 0;
446+
next_led_change = cur_time + LED_CYCLE_MILLIS - last_led_increment;
445447
}
446-
digitalWrite(PIN_STATUS_LED, state);
448+
digitalWrite(PIN_STATUS_LED, led_state);
447449
}
448450
#endif
449451
}
450452

451453
void UITask::setCurrScreen(UIScreen* c) {
452454
curr = c;
453-
_next_refresh = 0;
455+
_next_refresh = 100;
454456
}
455457

456458
/*
@@ -519,11 +521,18 @@ void UITask::loop() {
519521
c = handleLongPress(KEY_ENTER);
520522
}
521523
#endif
524+
#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN)
525+
if (millis() > next_backlight_btn_check) {
526+
bool touch_state = digitalRead(PIN_BUTTON2);
527+
digitalWrite(DISP_BACKLIGHT, !touch_state);
528+
next_backlight_btn_check = millis() + 300;
529+
}
530+
#endif
522531

523532
if (c != 0 && curr) {
524533
curr->handleInput(c);
525534
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
526-
_next_refresh = 0; // trigger refresh
535+
_next_refresh = 100; // trigger refresh
527536
}
528537

529538
userLedHandler();
@@ -553,9 +562,11 @@ void UITask::loop() {
553562
}
554563
_display->endFrame();
555564
}
565+
#if AUTO_OFF_MILLIS > 0
556566
if (millis() > _auto_off) {
557567
_display->turnOff();
558568
}
569+
#endif
559570
}
560571

561572
#ifdef AUTO_SHUTDOWN_MILLIVOLTS

examples/companion_radio/ui-new/UITask.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ class UITask : public AbstractUITask {
2626
unsigned long _alert_expiry;
2727
int _msgcount;
2828
unsigned long ui_started_at, next_batt_chck;
29+
int next_backlight_btn_check = 0;
30+
#ifdef PIN_STATUS_LED
31+
int led_state = 0;
32+
int next_led_change = 0;
33+
int last_led_increment = 0;
34+
#endif
2935

3036
UIScreen* splash;
3137
UIScreen* home;

src/helpers/ui/GxEPDDisplay.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bool GxEPDDisplay::begin() {
1919
display.fillScreen(GxEPD_WHITE);
2020
display.display(true);
2121
#if DISP_BACKLIGHT
22+
digitalWrite(DISP_BACKLIGHT, LOW);
2223
pinMode(DISP_BACKLIGHT, OUTPUT);
2324
#endif
2425
_init = true;
@@ -27,14 +28,14 @@ bool GxEPDDisplay::begin() {
2728

2829
void GxEPDDisplay::turnOn() {
2930
if (!_init) begin();
30-
#if DISP_BACKLIGHT
31+
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
3132
digitalWrite(DISP_BACKLIGHT, HIGH);
3233
#endif
3334
_isOn = true;
3435
}
3536

3637
void GxEPDDisplay::turnOff() {
37-
#if DISP_BACKLIGHT
38+
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
3839
digitalWrite(DISP_BACKLIGHT, LOW);
3940
#endif
4041
_isOn = false;
@@ -43,14 +44,17 @@ void GxEPDDisplay::turnOff() {
4344
void GxEPDDisplay::clear() {
4445
display.fillScreen(GxEPD_WHITE);
4546
display.setTextColor(GxEPD_BLACK);
47+
display_crc.reset();
4648
}
4749

4850
void GxEPDDisplay::startFrame(Color bkg) {
4951
display.fillScreen(GxEPD_WHITE);
5052
display.setTextColor(_curr_color = GxEPD_BLACK);
53+
display_crc.reset();
5154
}
5255

5356
void GxEPDDisplay::setTextSize(int sz) {
57+
display_crc.update<int>(sz);
5458
switch(sz) {
5559
case 1: // Small
5660
display.setFont(&FreeSans9pt7b);
@@ -68,6 +72,7 @@ void GxEPDDisplay::setTextSize(int sz) {
6872
}
6973

7074
void GxEPDDisplay::setColor(Color c) {
75+
display_crc.update<Color> (c);
7176
// colours need to be inverted for epaper displays
7277
if (c == DARK) {
7378
display.setTextColor(_curr_color = GxEPD_WHITE);
@@ -77,22 +82,38 @@ void GxEPDDisplay::setColor(Color c) {
7782
}
7883

7984
void GxEPDDisplay::setCursor(int x, int y) {
85+
display_crc.update<int>(x);
86+
display_crc.update<int>(y);
8087
display.setCursor(x*SCALE_X, (y+10)*SCALE_Y);
8188
}
8289

8390
void GxEPDDisplay::print(const char* str) {
91+
display_crc.update<char>(str, strlen(str));
8492
display.print(str);
8593
}
8694

8795
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);
88100
display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
89101
}
90102

91103
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);
92108
display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
93109
}
94110

95111
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);
96117
// Calculate the base position in display coordinates
97118
uint16_t startX = x * SCALE_X;
98119
uint16_t startY = y * SCALE_Y;
@@ -136,5 +157,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
136157
}
137158

138159
void GxEPDDisplay::endFrame() {
139-
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+
}
140165
}

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +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
81+
-D BACKLIGHT_BTN=PIN_BUTTON2
82+
-D AUTO_OFF_MILLIS=0
8183
; -D MESH_PACKET_LOGGING=1
8284
; -D MESH_DEBUG=1
8385
build_src_filter = ${LilyGo_Techo.build_src_filter}
@@ -91,3 +93,4 @@ lib_deps =
9193
${LilyGo_Techo.lib_deps}
9294
densaugeo/base64 @ ~1.4.0
9395
zinggjm/GxEPD2 @ 1.6.2
96+
bakercp/CRC32 @ ^2.0.0

0 commit comments

Comments
 (0)