Merge pull request #722 from fdlamotte/techo_epd_damage
Techo epd damage
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
#include "../MyMesh.h"
|
#include "../MyMesh.h"
|
||||||
#include "target.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
|
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
|
||||||
|
|
||||||
#ifdef PIN_STATUS_LED
|
#ifdef PIN_STATUS_LED
|
||||||
@@ -321,7 +323,11 @@ public:
|
|||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.printWordWrap(p->msg, display.width());
|
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
|
return 1000; // next render after 1000 ms
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleInput(char c) override {
|
bool handleInput(char c) override {
|
||||||
@@ -419,38 +425,34 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
|||||||
if (_display != NULL) {
|
if (_display != NULL) {
|
||||||
if (!_display->isOn()) _display->turnOn();
|
if (!_display->isOn()) _display->turnOn();
|
||||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||||
_next_refresh = 0; // trigger refresh
|
_next_refresh = 100; // trigger refresh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::userLedHandler() {
|
void UITask::userLedHandler() {
|
||||||
#ifdef PIN_STATUS_LED
|
#ifdef PIN_STATUS_LED
|
||||||
static int state = 0;
|
|
||||||
static int next_change = 0;
|
|
||||||
static int last_increment = 0;
|
|
||||||
|
|
||||||
int cur_time = millis();
|
int cur_time = millis();
|
||||||
if (cur_time > next_change) {
|
if (cur_time > next_led_change) {
|
||||||
if (state == 0) {
|
if (led_state == 0) {
|
||||||
state = 1;
|
led_state = 1;
|
||||||
if (_msgcount > 0) {
|
if (_msgcount > 0) {
|
||||||
last_increment = LED_ON_MSG_MILLIS;
|
last_led_increment = LED_ON_MSG_MILLIS;
|
||||||
} else {
|
} else {
|
||||||
last_increment = LED_ON_MILLIS;
|
last_led_increment = LED_ON_MILLIS;
|
||||||
}
|
}
|
||||||
next_change = cur_time + last_increment;
|
next_led_change = cur_time + last_led_increment;
|
||||||
} else {
|
} else {
|
||||||
state = 0;
|
led_state = 0;
|
||||||
next_change = cur_time + LED_CYCLE_MILLIS - last_increment;
|
next_led_change = cur_time + LED_CYCLE_MILLIS - last_led_increment;
|
||||||
}
|
}
|
||||||
digitalWrite(PIN_STATUS_LED, state);
|
digitalWrite(PIN_STATUS_LED, led_state);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::setCurrScreen(UIScreen* c) {
|
void UITask::setCurrScreen(UIScreen* c) {
|
||||||
curr = c;
|
curr = c;
|
||||||
_next_refresh = 0;
|
_next_refresh = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -519,11 +521,18 @@ void UITask::loop() {
|
|||||||
c = handleLongPress(KEY_ENTER);
|
c = handleLongPress(KEY_ENTER);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN)
|
||||||
|
if (millis() > next_backlight_btn_check) {
|
||||||
|
bool touch_state = digitalRead(PIN_BUTTON2);
|
||||||
|
digitalWrite(DISP_BACKLIGHT, !touch_state);
|
||||||
|
next_backlight_btn_check = millis() + 300;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (c != 0 && curr) {
|
if (c != 0 && curr) {
|
||||||
curr->handleInput(c);
|
curr->handleInput(c);
|
||||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||||
_next_refresh = 0; // trigger refresh
|
_next_refresh = 100; // trigger refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
userLedHandler();
|
userLedHandler();
|
||||||
@@ -553,9 +562,11 @@ void UITask::loop() {
|
|||||||
}
|
}
|
||||||
_display->endFrame();
|
_display->endFrame();
|
||||||
}
|
}
|
||||||
|
#if AUTO_OFF_MILLIS > 0
|
||||||
if (millis() > _auto_off) {
|
if (millis() > _auto_off) {
|
||||||
_display->turnOff();
|
_display->turnOff();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AUTO_SHUTDOWN_MILLIVOLTS
|
#ifdef AUTO_SHUTDOWN_MILLIVOLTS
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ class UITask : public AbstractUITask {
|
|||||||
unsigned long _alert_expiry;
|
unsigned long _alert_expiry;
|
||||||
int _msgcount;
|
int _msgcount;
|
||||||
unsigned long ui_started_at, next_batt_chck;
|
unsigned long ui_started_at, next_batt_chck;
|
||||||
|
int next_backlight_btn_check = 0;
|
||||||
|
#ifdef PIN_STATUS_LED
|
||||||
|
int led_state = 0;
|
||||||
|
int next_led_change = 0;
|
||||||
|
int last_led_increment = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
UIScreen* splash;
|
UIScreen* splash;
|
||||||
UIScreen* home;
|
UIScreen* home;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ bool GxEPDDisplay::begin() {
|
|||||||
display.fillScreen(GxEPD_WHITE);
|
display.fillScreen(GxEPD_WHITE);
|
||||||
display.display(true);
|
display.display(true);
|
||||||
#if DISP_BACKLIGHT
|
#if DISP_BACKLIGHT
|
||||||
|
digitalWrite(DISP_BACKLIGHT, LOW);
|
||||||
pinMode(DISP_BACKLIGHT, OUTPUT);
|
pinMode(DISP_BACKLIGHT, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
_init = true;
|
_init = true;
|
||||||
@@ -27,14 +28,14 @@ bool GxEPDDisplay::begin() {
|
|||||||
|
|
||||||
void GxEPDDisplay::turnOn() {
|
void GxEPDDisplay::turnOn() {
|
||||||
if (!_init) begin();
|
if (!_init) begin();
|
||||||
#if DISP_BACKLIGHT
|
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||||
digitalWrite(DISP_BACKLIGHT, HIGH);
|
digitalWrite(DISP_BACKLIGHT, HIGH);
|
||||||
#endif
|
#endif
|
||||||
_isOn = true;
|
_isOn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::turnOff() {
|
void GxEPDDisplay::turnOff() {
|
||||||
#if DISP_BACKLIGHT
|
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||||
digitalWrite(DISP_BACKLIGHT, LOW);
|
digitalWrite(DISP_BACKLIGHT, LOW);
|
||||||
#endif
|
#endif
|
||||||
_isOn = false;
|
_isOn = false;
|
||||||
@@ -43,14 +44,17 @@ void GxEPDDisplay::turnOff() {
|
|||||||
void GxEPDDisplay::clear() {
|
void GxEPDDisplay::clear() {
|
||||||
display.fillScreen(GxEPD_WHITE);
|
display.fillScreen(GxEPD_WHITE);
|
||||||
display.setTextColor(GxEPD_BLACK);
|
display.setTextColor(GxEPD_BLACK);
|
||||||
|
display_crc.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::startFrame(Color bkg) {
|
void GxEPDDisplay::startFrame(Color bkg) {
|
||||||
display.fillScreen(GxEPD_WHITE);
|
display.fillScreen(GxEPD_WHITE);
|
||||||
display.setTextColor(_curr_color = GxEPD_BLACK);
|
display.setTextColor(_curr_color = GxEPD_BLACK);
|
||||||
|
display_crc.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::setTextSize(int sz) {
|
void GxEPDDisplay::setTextSize(int sz) {
|
||||||
|
display_crc.update<int>(sz);
|
||||||
switch(sz) {
|
switch(sz) {
|
||||||
case 1: // Small
|
case 1: // Small
|
||||||
display.setFont(&FreeSans9pt7b);
|
display.setFont(&FreeSans9pt7b);
|
||||||
@@ -68,6 +72,7 @@ void GxEPDDisplay::setTextSize(int sz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::setColor(Color c) {
|
void GxEPDDisplay::setColor(Color c) {
|
||||||
|
display_crc.update<Color> (c);
|
||||||
// colours need to be inverted for epaper displays
|
// colours need to be inverted for epaper displays
|
||||||
if (c == DARK) {
|
if (c == DARK) {
|
||||||
display.setTextColor(_curr_color = GxEPD_WHITE);
|
display.setTextColor(_curr_color = GxEPD_WHITE);
|
||||||
@@ -77,22 +82,38 @@ void GxEPDDisplay::setColor(Color c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::setCursor(int x, int y) {
|
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);
|
display.setCursor(x*SCALE_X, (y+10)*SCALE_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::print(const char* str) {
|
void GxEPDDisplay::print(const char* str) {
|
||||||
|
display_crc.update<char>(str, strlen(str));
|
||||||
display.print(str);
|
display.print(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::fillRect(int x, int y, int w, int h) {
|
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);
|
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) {
|
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);
|
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) {
|
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
|
// Calculate the base position in display coordinates
|
||||||
uint16_t startX = x * SCALE_X;
|
uint16_t startX = x * SCALE_X;
|
||||||
uint16_t startY = y * SCALE_Y;
|
uint16_t startY = y * SCALE_Y;
|
||||||
@@ -136,5 +157,9 @@ uint16_t GxEPDDisplay::getTextWidth(const char* str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GxEPDDisplay::endFrame() {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN // DEPG0150BN 200x200, SSD1681, (FPC8101), TTGO T5 V2.4.1
|
#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 <epd/GxEPD2_150_BN.h> // 1.54" b/w
|
||||||
|
#include <CRC32.h>
|
||||||
|
|
||||||
#include "DisplayDriver.h"
|
#include "DisplayDriver.h"
|
||||||
|
|
||||||
@@ -29,6 +30,8 @@ class GxEPDDisplay : public DisplayDriver {
|
|||||||
bool _init = false;
|
bool _init = false;
|
||||||
bool _isOn = false;
|
bool _isOn = false;
|
||||||
uint16_t _curr_color;
|
uint16_t _curr_color;
|
||||||
|
CRC32 display_crc;
|
||||||
|
int last_display_crc_value = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// there is a margin in y...
|
// there is a margin in y...
|
||||||
|
|||||||
@@ -74,10 +74,12 @@ build_flags =
|
|||||||
-D MAX_CONTACTS=100
|
-D MAX_CONTACTS=100
|
||||||
-D MAX_GROUP_CHANNELS=8
|
-D MAX_GROUP_CHANNELS=8
|
||||||
-D BLE_PIN_CODE=123456
|
-D BLE_PIN_CODE=123456
|
||||||
-D BLE_DEBUG_LOGGING=1
|
; -D BLE_DEBUG_LOGGING=1
|
||||||
-D DISPLAY_CLASS=GxEPDDisplay
|
-D DISPLAY_CLASS=GxEPDDisplay
|
||||||
-D OFFLINE_QUEUE_SIZE=256
|
-D OFFLINE_QUEUE_SIZE=256
|
||||||
-D UI_RECENT_LIST_SIZE=9
|
-D UI_RECENT_LIST_SIZE=9
|
||||||
|
-D BACKLIGHT_BTN=PIN_BUTTON2
|
||||||
|
-D AUTO_OFF_MILLIS=0
|
||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
; -D MESH_DEBUG=1
|
; -D MESH_DEBUG=1
|
||||||
build_src_filter = ${LilyGo_Techo.build_src_filter}
|
build_src_filter = ${LilyGo_Techo.build_src_filter}
|
||||||
@@ -91,3 +93,4 @@ lib_deps =
|
|||||||
${LilyGo_Techo.lib_deps}
|
${LilyGo_Techo.lib_deps}
|
||||||
densaugeo/base64 @ ~1.4.0
|
densaugeo/base64 @ ~1.4.0
|
||||||
zinggjm/GxEPD2 @ 1.6.2
|
zinggjm/GxEPD2 @ 1.6.2
|
||||||
|
bakercp/CRC32 @ ^2.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user