Skip to content

Commit 13d0468

Browse files
authored
Merge branch 'dev' into dev-meshpocket
2 parents c9671d7 + 5782c2e commit 13d0468

31 files changed

+354
-150
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 81 additions & 29 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
@@ -223,11 +225,11 @@ class HomeScreen : public UIScreen {
223225
}
224226

225227
bool handleInput(char c) override {
226-
if (c == KEY_LEFT) {
228+
if (c == KEY_LEFT || c == KEY_PREV) {
227229
_page = (_page + HomePage::Count - 1) % HomePage::Count;
228230
return true;
229231
}
230-
if (c == KEY_RIGHT || c == KEY_SELECT) {
232+
if (c == KEY_NEXT || c == KEY_RIGHT) {
231233
_page = (_page + 1) % HomePage::Count;
232234
if (_page == HomePage::RECENT) {
233235
_task->showAlert("Recent adverts", 800);
@@ -321,11 +323,15 @@ 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 {
328-
if (c == KEY_SELECT || c == KEY_RIGHT) {
334+
if (c == KEY_NEXT || c == KEY_RIGHT) {
329335
num_unread--;
330336
if (num_unread == 0) {
331337
_task->gotoHomeScreen();
@@ -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
/*
@@ -492,9 +494,13 @@ void UITask::loop() {
492494
#if defined(PIN_USER_BTN)
493495
int ev = user_btn.check();
494496
if (ev == BUTTON_EVENT_CLICK) {
495-
c = checkDisplayOn(KEY_SELECT);
497+
c = checkDisplayOn(KEY_NEXT);
496498
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
497499
c = handleLongPress(KEY_ENTER);
500+
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
501+
c = handleDoubleClick(KEY_PREV);
502+
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
503+
c = handleTripleClick(KEY_SELECT);
498504
}
499505
#endif
500506
#if defined(WIO_TRACKER_L1)
@@ -514,16 +520,27 @@ void UITask::loop() {
514520
#if defined(PIN_USER_BTN_ANA)
515521
ev = analog_btn.check();
516522
if (ev == BUTTON_EVENT_CLICK) {
517-
c = checkDisplayOn(KEY_SELECT);
523+
c = checkDisplayOn(KEY_NEXT);
518524
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
519525
c = handleLongPress(KEY_ENTER);
526+
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
527+
c = handleDoubleClick(KEY_PREV);
528+
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
529+
c = handleTripleClick(KEY_SELECT);
530+
}
531+
#endif
532+
#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN)
533+
if (millis() > next_backlight_btn_check) {
534+
bool touch_state = digitalRead(PIN_BUTTON2);
535+
digitalWrite(DISP_BACKLIGHT, !touch_state);
536+
next_backlight_btn_check = millis() + 300;
520537
}
521538
#endif
522539

523540
if (c != 0 && curr) {
524541
curr->handleInput(c);
525542
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
526-
_next_refresh = 0; // trigger refresh
543+
_next_refresh = 100; // trigger refresh
527544
}
528545

529546
userLedHandler();
@@ -553,9 +570,11 @@ void UITask::loop() {
553570
}
554571
_display->endFrame();
555572
}
573+
#if AUTO_OFF_MILLIS > 0
556574
if (millis() > _auto_off) {
557575
_display->turnOff();
558576
}
577+
#endif
559578
}
560579

561580
#ifdef AUTO_SHUTDOWN_MILLIVOLTS
@@ -604,20 +623,53 @@ char UITask::handleLongPress(char c) {
604623
return c;
605624
}
606625

607-
/*
608-
void UITask::handleButtonTriplePress() {
609-
MESH_DEBUG_PRINTLN("UITask: triple press triggered");
610-
// Toggle buzzer quiet mode
626+
char UITask::handleDoubleClick(char c) {
627+
MESH_DEBUG_PRINTLN("UITask: double click triggered");
628+
checkDisplayOn(c);
629+
return c;
630+
}
631+
632+
char UITask::handleTripleClick(char c) {
633+
MESH_DEBUG_PRINTLN("UITask: triple click triggered");
634+
checkDisplayOn(c);
635+
toggleBuzzer();
636+
c = 0;
637+
return c;
638+
}
639+
640+
void UITask::toggleGPS() {
641+
if (_sensors != NULL) {
642+
// toggle GPS on/off
643+
int num = _sensors->getNumSettings();
644+
for (int i = 0; i < num; i++) {
645+
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
646+
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
647+
_sensors->setSettingValue("gps", "0");
648+
soundBuzzer(UIEventType::ack);
649+
showAlert("GPS: Disabled", 800);
650+
} else {
651+
_sensors->setSettingValue("gps", "1");
652+
soundBuzzer(UIEventType::ack);
653+
showAlert("GPS: Enabled", 800);
654+
}
655+
_next_refresh = 0;
656+
break;
657+
}
658+
}
659+
}
660+
}
661+
662+
void UITask::toggleBuzzer() {
663+
// Toggle buzzer quiet mode
611664
#ifdef PIN_BUZZER
612665
if (buzzer.isQuiet()) {
613666
buzzer.quiet(false);
614667
soundBuzzer(UIEventType::ack);
615-
showAlert("Buzzer: ON", 600);
668+
showAlert("Buzzer: ON", 800);
616669
} else {
617670
buzzer.quiet(true);
618-
showAlert("Buzzer: OFF", 600);
671+
showAlert("Buzzer: OFF", 800);
619672
}
620673
_next_refresh = 0; // trigger refresh
621674
#endif
622675
}
623-
*/

examples/companion_radio/ui-new/UITask.h

Lines changed: 12 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;
@@ -37,6 +43,8 @@ class UITask : public AbstractUITask {
3743
// Button action handlers
3844
char checkDisplayOn(char c);
3945
char handleLongPress(char c);
46+
char handleDoubleClick(char c);
47+
char handleTripleClick(char c);
4048

4149
void setCurrScreen(UIScreen* c);
4250

@@ -55,6 +63,10 @@ class UITask : public AbstractUITask {
5563
bool hasDisplay() const { return _display != NULL; }
5664
bool isButtonPressed() const;
5765

66+
void toggleBuzzer();
67+
void toggleGPS();
68+
69+
5870
// from AbstractUITask
5971
void msgRead(int msgcount) override;
6072
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;

src/helpers/HeltecV3Board.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ class HeltecV3Board : public ESP32Board {
8585
}
8686

8787
void powerOff() override {
88-
// TODO: re-enable this when there is a definite wake-up source pin:
89-
// enterDeepSleep(0);
88+
enterDeepSleep(0);
9089
}
9190

9291
uint16_t getBattMilliVolts() override {

src/helpers/ui/GxEPDDisplay.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bool GxEPDDisplay::begin() {
1616
display.fillScreen(GxEPD_WHITE);
1717
display.display(true);
1818
#if DISP_BACKLIGHT
19+
digitalWrite(DISP_BACKLIGHT, LOW);
1920
pinMode(DISP_BACKLIGHT, OUTPUT);
2021
#endif
2122
_init = true;
@@ -24,14 +25,14 @@ bool GxEPDDisplay::begin() {
2425

2526
void GxEPDDisplay::turnOn() {
2627
if (!_init) begin();
27-
#if DISP_BACKLIGHT
28+
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
2829
digitalWrite(DISP_BACKLIGHT, HIGH);
2930
#endif
3031
_isOn = true;
3132
}
3233

3334
void GxEPDDisplay::turnOff() {
34-
#if DISP_BACKLIGHT
35+
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
3536
digitalWrite(DISP_BACKLIGHT, LOW);
3637
#endif
3738
_isOn = false;
@@ -40,14 +41,17 @@ void GxEPDDisplay::turnOff() {
4041
void GxEPDDisplay::clear() {
4142
display.fillScreen(GxEPD_WHITE);
4243
display.setTextColor(GxEPD_BLACK);
44+
display_crc.reset();
4345
}
4446

4547
void GxEPDDisplay::startFrame(Color bkg) {
4648
display.fillScreen(GxEPD_WHITE);
4749
display.setTextColor(_curr_color = GxEPD_BLACK);
50+
display_crc.reset();
4851
}
4952

5053
void GxEPDDisplay::setTextSize(int sz) {
54+
display_crc.update<int>(sz);
5155
switch(sz) {
5256
case 1: // Small
5357
display.setFont(&FreeSans9pt7b);
@@ -65,6 +69,7 @@ void GxEPDDisplay::setTextSize(int sz) {
6569
}
6670

6771
void GxEPDDisplay::setColor(Color c) {
72+
display_crc.update<Color> (c);
6873
// colours need to be inverted for epaper displays
6974
if (c == DARK) {
7075
display.setTextColor(_curr_color = GxEPD_WHITE);
@@ -74,22 +79,38 @@ void GxEPDDisplay::setColor(Color c) {
7479
}
7580

7681
void GxEPDDisplay::setCursor(int x, int y) {
82+
display_crc.update<int>(x);
83+
display_crc.update<int>(y);
7784
display.setCursor((x+offset_x)*scale_x, (y+offset_y)*scale_y);
7885
}
7986

8087
void GxEPDDisplay::print(const char* str) {
88+
display_crc.update<char>(str, strlen(str));
8189
display.print(str);
8290
}
8391

8492
void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
85-
display.fillRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color);
93+
display_crc.update<int>(x);
94+
display_crc.update<int>(y);
95+
display_crc.update<int>(w);
96+
display_crc.update<int>(h);
97+
display.fillRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
8698
}
8799

88100
void GxEPDDisplay::drawRect(int x, int y, int w, int h) {
89-
display.drawRect(x*scale_x, y*scale_y, w*scale_x, h*scale_y, _curr_color);
101+
display_crc.update<int>(x);
102+
display_crc.update<int>(y);
103+
display_crc.update<int>(w);
104+
display_crc.update<int>(h);
105+
display.drawRect(x*SCALE_X, y*SCALE_Y, w*SCALE_X, h*SCALE_Y, _curr_color);
90106
}
91107

92108
void GxEPDDisplay::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
109+
display_crc.update<int>(x);
110+
display_crc.update<int>(y);
111+
display_crc.update<int>(w);
112+
display_crc.update<int>(h);
113+
display_crc.update<uint8_t>(bits, w * h / 8);
93114
// Calculate the base position in display coordinates
94115
uint16_t startX = x * scale_x;
95116
uint16_t startY = y * scale_y;
@@ -133,5 +154,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
133154
}
134155

135156
void GxEPDDisplay::endFrame() {
136-
display.display(true);
157+
uint32_t crc = display_crc.finalize();
158+
if (crc != last_display_crc_value) {
159+
display.display(true);
160+
last_display_crc_value = crc;
161+
}
137162
}

src/helpers/ui/GxEPDDisplay.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <epd/GxEPD2_150_BN.h> // 1.54" b/w
1717
#include <epd/GxEPD2_213_B74.h> // 2.13" b/w
18+
#include <CRC32.h>
19+
1820
#include "DisplayDriver.h"
1921

2022
//GxEPD2_BW<GxEPD2_150_BN, 200> display(GxEPD2_150_BN(DISP_CS, DISP_DC, DISP_RST, DISP_BUSY)); // DEPG0150BN 200x200, SSD1681, TTGO T5 V2.4.1
@@ -38,6 +40,8 @@ class GxEPDDisplay : public DisplayDriver {
3840
bool _init = false;
3941
bool _isOn = false;
4042
uint16_t _curr_color;
43+
CRC32 display_crc;
44+
int last_display_crc_value = 0;
4145

4246
public:
4347
// there is a margin in y...

0 commit comments

Comments
 (0)