Browse Source

* refactor of Color mapping in UITasks / DisplayDrivers

* color displays now with a new light theme
ui-color-refactor
Scott Powell 1 week ago
parent
commit
b8504e55c6
  1. 67
      examples/companion_radio/ui-new/UITask.cpp
  2. 27
      examples/companion_radio/ui-orig/UITask.cpp
  3. 2
      examples/companion_radio/ui-tiny/ScrollingStatusBar.h
  4. 31
      examples/companion_radio/ui-tiny/UITask.cpp
  5. 12
      examples/simple_repeater/UITask.cpp
  6. 8
      examples/simple_room_server/UITask.cpp
  7. 8
      examples/simple_sensor/UITask.cpp
  8. 14
      src/helpers/ui/DisplayDriver.h
  9. 30
      src/helpers/ui/E213Display.cpp
  10. 5
      src/helpers/ui/E213Display.h
  11. 30
      src/helpers/ui/E290Display.cpp
  12. 5
      src/helpers/ui/E290Display.h
  13. 29
      src/helpers/ui/GxEPDDisplay.cpp
  14. 4
      src/helpers/ui/GxEPDDisplay.h
  15. 48
      src/helpers/ui/LGFXDisplay.cpp
  16. 4
      src/helpers/ui/LGFXDisplay.h
  17. 34
      src/helpers/ui/NV3001BDisplay.cpp
  18. 4
      src/helpers/ui/NV3001BDisplay.h
  19. 4
      src/helpers/ui/NullDisplayDriver.h
  20. 19
      src/helpers/ui/SH1106Display.cpp
  21. 4
      src/helpers/ui/SH1106Display.h
  22. 19
      src/helpers/ui/SSD1306Display.cpp
  23. 4
      src/helpers/ui/SSD1306Display.h
  24. 46
      src/helpers/ui/ST7735Display.cpp
  25. 4
      src/helpers/ui/ST7735Display.h
  26. 51
      src/helpers/ui/ST7789Display.cpp
  27. 4
      src/helpers/ui/ST7789Display.h
  28. 47
      src/helpers/ui/ST7789LCDDisplay.cpp
  29. 4
      src/helpers/ui/ST7789LCDDisplay.h
  30. 12
      src/helpers/ui/U8g2Display.cpp
  31. 16
      src/helpers/ui/U8g2Display.h
  32. 2
      variants/lilygo_techo_card/platformio.ini

67
examples/companion_radio/ui-new/UITask.cpp

@ -53,23 +53,24 @@ public:
int render(DisplayDriver& display) override { int render(DisplayDriver& display) override {
// meshcore logo // meshcore logo
display.setColor(DisplayDriver::BLUE); display.setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
display.drawXbm((display.width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); display.drawXbm((display.width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// meshcore website // meshcore website
const char* website = "https://meshcore.io"; const char* website = "https://meshcore.io";
display.setColor(DisplayDriver::LIGHT); display.setColor(UIColor::primary_txt);
display.setTextSize(1); display.setTextSize(1);
uint16_t websiteWidth = display.getTextWidth(website); uint16_t websiteWidth = display.getTextWidth(website);
display.setCursor((display.width() - websiteWidth) / 2, 22); display.setCursor((display.width() - websiteWidth) / 2, 22);
display.print(website); display.print(website);
// version info // version info
display.setColor(DisplayDriver::LIGHT); display.setColor(UIColor::primary_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width()/2, 35, _version_info); display.drawTextCentered(display.width()/2, 35, _version_info);
display.setColor(UIColor::secondary_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width()/2, 48, FIRMWARE_BUILD_DATE); display.drawTextCentered(display.width()/2, 48, FIRMWARE_BUILD_DATE);
@ -128,7 +129,7 @@ class HomeScreen : public UIScreen {
int iconHeight = 10; int iconHeight = 10;
int iconX = display.width() - iconWidth - 5; // Position the icon near the top-right corner int iconX = display.width() - iconWidth - 5; // Position the icon near the top-right corner
int iconY = 0; int iconY = 0;
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::title_txt);
// battery outline // battery outline
display.drawRect(iconX, iconY, iconWidth, iconHeight); display.drawRect(iconX, iconY, iconWidth, iconHeight);
@ -143,7 +144,7 @@ class HomeScreen : public UIScreen {
// show muted icon if buzzer is muted // show muted icon if buzzer is muted
#ifdef PIN_BUZZER #ifdef PIN_BUZZER
if (_task->isBuzzerQuiet()) { if (_task->isBuzzerQuiet()) {
display.setColor(DisplayDriver::RED); display.setColor(UIColor::warning_txt);
display.drawXbm(iconX - 9, iconY + 1, muted_icon, 8, 8); display.drawXbm(iconX - 9, iconY + 1, muted_icon, 8, 8);
} }
#endif #endif
@ -188,34 +189,37 @@ public:
} }
int render(DisplayDriver& display) override { int render(DisplayDriver& display) override {
display.setColor(UIColor::title_bkg);
display.fillRect(0, 0, display.width(), 12);
char tmp[80]; char tmp[80];
// node name // node name
display.setTextSize(1); display.setTextSize(1);
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::title_txt);
char filtered_name[sizeof(_node_prefs->node_name)]; char filtered_name[sizeof(_node_prefs->node_name)];
display.translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name)); display.translateUTF8ToBlocks(filtered_name, _node_prefs->node_name, sizeof(filtered_name));
display.setCursor(0, 0); display.setCursor(0, 2);
display.print(filtered_name); display.print(filtered_name);
// battery voltage // battery voltage
renderBatteryIndicator(display, _task->getBattMilliVolts()); renderBatteryIndicator(display, _task->getBattMilliVolts());
// curr page indicator // curr page indicator
display.setColor(UIColor::title_bkg);
int y = 14; int y = 14;
int x = display.width() / 2 - 5 * (HomePage::Count-1); int x = display.width() / 2 - 5 * (HomePage::Count-1);
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) { for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
if (i == _page) { if (i == _page) {
display.fillRect(x-1, y-1, 3, 3); display.fillRect(x-1, y-1, 4, 4);
} else { } else {
display.fillRect(x, y, 1, 1); display.fillRect(x, y, 2, 2);
} }
} }
if (_page == HomePage::FIRST) { if (_page == HomePage::FIRST) {
display.setColor(DisplayDriver::YELLOW); display.setColor(UIColor::primary_txt);
display.setTextSize(2); display.setTextSize(2);
sprintf(tmp, "MSG: %d", _task->getMsgCount()); sprintf(tmp, "MSG: %d", _task->getMsgCount());
display.drawTextCentered(display.width() / 2, 20, tmp); display.drawTextCentered(display.width() / 2, 22, tmp);
#ifdef WIFI_SSID #ifdef WIFI_SSID
IPAddress ip = WiFi.localIP(); IPAddress ip = WiFi.localIP();
@ -224,19 +228,19 @@ public:
display.drawTextCentered(display.width() / 2, 54, tmp); display.drawTextCentered(display.width() / 2, 54, tmp);
#endif #endif
if (_task->hasConnection()) { if (_task->hasConnection()) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::warning_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 43, "< Connected >"); display.drawTextCentered(display.width() / 2, 43, "< Connected >");
} else if (the_mesh.getBLEPin() != 0) { // BT pin } else if (the_mesh.getBLEPin() != 0) { // BT pin
display.setColor(DisplayDriver::RED); display.setColor(UIColor::warning_txt);
display.setTextSize(2); display.setTextSize(2);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin()); sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
display.drawTextCentered(display.width() / 2, 43, tmp); display.drawTextCentered(display.width() / 2, 43, tmp);
} }
} else if (_page == HomePage::RECENT) { } else if (_page == HomePage::RECENT) {
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE); the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::primary_txt);
int y = 20; int y = 20;
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) { for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) {
auto a = &recent[i]; auto a = &recent[i];
@ -260,7 +264,7 @@ public:
display.print(tmp); display.print(tmp);
} }
} else if (_page == HomePage::RADIO) { } else if (_page == HomePage::RADIO) {
display.setColor(DisplayDriver::YELLOW); display.setColor(UIColor::primary_txt);
display.setTextSize(1); display.setTextSize(1);
// freq / sf // freq / sf
display.setCursor(0, 20); display.setCursor(0, 20);
@ -279,15 +283,17 @@ public:
sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor()); sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor());
display.print(tmp); display.print(tmp);
} else if (_page == HomePage::BLUETOOTH) { } else if (_page == HomePage::BLUETOOTH) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
display.drawXbm((display.width() - 32) / 2, 18, display.drawXbm((display.width() - 32) / 2, 18,
_task->isSerialEnabled() ? bluetooth_on : bluetooth_off, _task->isSerialEnabled() ? bluetooth_on : bluetooth_off,
32, 32); 32, 32);
display.setColor(UIColor::secondary_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL); display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL);
} else if (_page == HomePage::ADVERT) { } else if (_page == HomePage::ADVERT) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32); display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32);
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL); display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL);
#if ENV_INCLUDE_GPS == 1 #if ENV_INCLUDE_GPS == 1
} else if (_page == HomePage::GPS) { } else if (_page == HomePage::GPS) {
@ -305,24 +311,33 @@ public:
#else #else
strcpy(buf, gps_state ? "gps on" : "gps off"); strcpy(buf, gps_state ? "gps on" : "gps off");
#endif #endif
display.setColor(UIColor::primary_txt);
display.drawTextLeftAlign(0, y, buf); display.drawTextLeftAlign(0, y, buf);
if (nmea == NULL) { if (nmea == NULL) {
y = y + 12; y = y + 12;
display.setColor(UIColor::secondary_txt);
display.drawTextLeftAlign(0, y, "Can't access GPS"); display.drawTextLeftAlign(0, y, "Can't access GPS");
} else { } else {
display.setColor(UIColor::primary_txt);
strcpy(buf, nmea->isValid()?"fix":"no fix"); strcpy(buf, nmea->isValid()?"fix":"no fix");
display.drawTextRightAlign(display.width()-1, y, buf); display.drawTextRightAlign(display.width()-1, y, buf);
y = y + 12; y = y + 12;
display.setColor(UIColor::secondary_txt);
display.drawTextLeftAlign(0, y, "sat"); display.drawTextLeftAlign(0, y, "sat");
display.setColor(UIColor::primary_txt);
sprintf(buf, "%d", nmea->satellitesCount()); sprintf(buf, "%d", nmea->satellitesCount());
display.drawTextRightAlign(display.width()-1, y, buf); display.drawTextRightAlign(display.width()-1, y, buf);
y = y + 12; y = y + 12;
display.setColor(UIColor::secondary_txt);
display.drawTextLeftAlign(0, y, "pos"); display.drawTextLeftAlign(0, y, "pos");
display.setColor(UIColor::primary_txt);
sprintf(buf, "%.4f %.4f", sprintf(buf, "%.4f %.4f",
nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.); nmea->getLatitude()/1000000., nmea->getLongitude()/1000000.);
display.drawTextRightAlign(display.width()-1, y, buf); display.drawTextRightAlign(display.width()-1, y, buf);
y = y + 12; y = y + 12;
display.setColor(UIColor::secondary_txt);
display.drawTextLeftAlign(0, y, "alt"); display.drawTextLeftAlign(0, y, "alt");
display.setColor(UIColor::primary_txt);
sprintf(buf, "%.2f", nmea->getAltitude()/1000.); sprintf(buf, "%.2f", nmea->getAltitude()/1000.);
display.drawTextRightAlign(display.width()-1, y, buf); display.drawTextRightAlign(display.width()-1, y, buf);
y = y + 12; y = y + 12;
@ -390,7 +405,9 @@ public:
strcpy(name, "unk"); sprintf(buf, ""); strcpy(name, "unk"); sprintf(buf, "");
} }
display.setCursor(0, y); display.setCursor(0, y);
display.setColor(UIColor::secondary_txt);
display.print(name); display.print(name);
display.setColor(UIColor::primary_txt);
display.setCursor( display.setCursor(
display.width()-display.getTextWidth(buf)-1, y display.width()-display.getTextWidth(buf)-1, y
); );
@ -401,11 +418,13 @@ public:
else sensors_scroll_offset = 0; else sensors_scroll_offset = 0;
#endif #endif
} else if (_page == HomePage::SHUTDOWN) { } else if (_page == HomePage::SHUTDOWN) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
display.setTextSize(1); display.setTextSize(1);
if (_shutdown_init) { if (_shutdown_init) {
display.setColor(UIColor::warning_txt);
display.drawTextCentered(display.width() / 2, 34, "hibernating..."); display.drawTextCentered(display.width() / 2, 34, "hibernating...");
} else { } else {
display.setColor(UIColor::secondary_txt);
display.drawXbm((display.width() - 32) / 2, 18, power_icon, 32, 32); display.drawXbm((display.width() - 32) / 2, 18, power_icon, 32, 32);
display.drawTextCentered(display.width() / 2, 64 - 11, "hibernate:" PRESS_LABEL); display.drawTextCentered(display.width() / 2, 64 - 11, "hibernate:" PRESS_LABEL);
} }
@ -498,7 +517,7 @@ public:
char tmp[16]; char tmp[16];
display.setCursor(0, 0); display.setCursor(0, 0);
display.setTextSize(1); display.setTextSize(1);
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
sprintf(tmp, "Unread: %d", num_unread); sprintf(tmp, "Unread: %d", num_unread);
display.print(tmp); display.print(tmp);
@ -518,13 +537,13 @@ public:
display.drawRect(0, 11, display.width(), 1); // horiz line display.drawRect(0, 11, display.width(), 1); // horiz line
display.setCursor(0, 14); display.setCursor(0, 14);
display.setColor(DisplayDriver::YELLOW); display.setColor(UIColor::secondary_txt);
char filtered_origin[sizeof(p->origin)]; char filtered_origin[sizeof(p->origin)];
display.translateUTF8ToBlocks(filtered_origin, p->origin, sizeof(filtered_origin)); display.translateUTF8ToBlocks(filtered_origin, p->origin, sizeof(filtered_origin));
display.print(filtered_origin); display.print(filtered_origin);
display.setCursor(0, 25); display.setCursor(0, 25);
display.setColor(DisplayDriver::LIGHT); display.setColor(UIColor::primary_txt);
char filtered_msg[sizeof(p->msg)]; char filtered_msg[sizeof(p->msg)];
display.translateUTF8ToBlocks(filtered_msg, p->msg, sizeof(filtered_msg)); display.translateUTF8ToBlocks(filtered_msg, p->msg, sizeof(filtered_msg));
display.printWordWrap(filtered_msg, display.width()); display.printWordWrap(filtered_msg, display.width());
@ -806,9 +825,9 @@ void UITask::loop() {
_display->setTextSize(1); _display->setTextSize(1);
int y = _display->height() / 3; int y = _display->height() / 3;
int p = _display->height() / 32; int p = _display->height() / 32;
_display->setColor(DisplayDriver::DARK); _display->setColor(UIColor::popup_bkg);
_display->fillRect(p, y, _display->width() - p*2, y); _display->fillRect(p, y, _display->width() - p*2, y);
_display->setColor(DisplayDriver::LIGHT); // draw box border _display->setColor(UIColor::popup_txt); // draw box border
_display->drawRect(p, y, _display->width() - p*2, y); _display->drawRect(p, y, _display->width() - p*2, y);
_display->drawTextCentered(_display->width() / 2, y + p*3, _alert); _display->drawTextCentered(_display->width() / 2, y + p*3, _alert);
_next_refresh = _alert_expiry; // will need refresh when alert is dismissed _next_refresh = _alert_expiry; // will need refresh when alert is dismissed
@ -845,7 +864,7 @@ void UITask::loop() {
if (_display != NULL) { if (_display != NULL) {
_display->startFrame(); _display->startFrame();
_display->setTextSize(2); _display->setTextSize(2);
_display->setColor(DisplayDriver::RED); _display->setColor(UIColor::warning_txt);
_display->drawTextCentered(_display->width() / 2, 20, "Low Battery."); _display->drawTextCentered(_display->width() / 2, 20, "Low Battery.");
_display->drawTextCentered(_display->width() / 2, 40, "Shutting Down!"); _display->drawTextCentered(_display->width() / 2, 40, "Shutting Down!");
_display->endFrame(); _display->endFrame();

27
examples/companion_radio/ui-orig/UITask.cpp

@ -167,7 +167,7 @@ void UITask::renderBatteryIndicator(uint16_t batteryMilliVolts) {
int iconHeight = 12; int iconHeight = 12;
int iconX = _display->width() - iconWidth - 5; // Position the icon near the top-right corner int iconX = _display->width() - iconWidth - 5; // Position the icon near the top-right corner
int iconY = 0; int iconY = 0;
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
// battery outline // battery outline
_display->drawRect(iconX, iconY, iconWidth, iconHeight); _display->drawRect(iconX, iconY, iconWidth, iconHeight);
@ -188,7 +188,7 @@ void UITask::renderCurrScreen() {
_display->setTextSize(1.4); _display->setTextSize(1.4);
uint16_t textWidth = _display->getTextWidth(_alert); uint16_t textWidth = _display->getTextWidth(_alert);
_display->setCursor((_display->width() - textWidth) / 2, 22); _display->setCursor((_display->width() - textWidth) / 2, 22);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::warning_txt);
_display->print(_alert); _display->print(_alert);
_alert[0] = 0; _alert[0] = 0;
_need_refresh = true; _need_refresh = true;
@ -197,30 +197,29 @@ void UITask::renderCurrScreen() {
// render message preview // render message preview
_display->setCursor(0, 0); _display->setCursor(0, 0);
_display->setTextSize(1); _display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
_display->print(_node_prefs->node_name); _display->print(_node_prefs->node_name);
_display->setCursor(0, 12); _display->setCursor(0, 12);
_display->setColor(DisplayDriver::YELLOW); _display->setColor(UIColor::secondary_txt);
_display->print(_origin); _display->print(_origin);
_display->setCursor(0, 24); _display->setCursor(0, 24);
_display->setColor(DisplayDriver::LIGHT);
_display->print(_msg); _display->print(_msg);
_display->setCursor(_display->width() - 28, 9); _display->setCursor(_display->width() - 28, 9);
_display->setTextSize(2); _display->setTextSize(2);
_display->setColor(DisplayDriver::ORANGE); _display->setColor(UIColor::primary_txt);
sprintf(tmp, "%d", _msgcount); sprintf(tmp, "%d", _msgcount);
_display->print(tmp); _display->print(tmp);
_display->setColor(DisplayDriver::YELLOW); // last color will be kept on T114 _display->setColor(UIColor::secondary_txt); // last color will be kept on T114
} else if ((millis() - ui_started_at) < BOOT_SCREEN_MILLIS) { // boot screen } else if ((millis() - ui_started_at) < BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// version info // version info
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
_display->setTextSize(1); _display->setTextSize(1);
uint16_t textWidth = _display->getTextWidth(_version_info); uint16_t textWidth = _display->getTextWidth(_version_info);
_display->setCursor((_display->width() - textWidth) / 2, 22); _display->setCursor((_display->width() - textWidth) / 2, 22);
@ -229,7 +228,7 @@ void UITask::renderCurrScreen() {
// node name // node name
_display->setCursor(0, 0); _display->setCursor(0, 0);
_display->setTextSize(1); _display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
_display->print(_node_prefs->node_name); _display->print(_node_prefs->node_name);
// battery voltage // battery voltage
@ -237,7 +236,7 @@ void UITask::renderCurrScreen() {
// freq / sf // freq / sf
_display->setCursor(0, 20); _display->setCursor(0, 20);
_display->setColor(DisplayDriver::YELLOW); _display->setColor(UIColor::secondary_txt);
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
_display->print(tmp); _display->print(tmp);
@ -248,14 +247,14 @@ void UITask::renderCurrScreen() {
// BT pin // BT pin
if (!_connected && the_mesh.getBLEPin() != 0) { if (!_connected && the_mesh.getBLEPin() != 0) {
_display->setColor(DisplayDriver::RED); _display->setColor(UIColor::warning_txt);
_display->setTextSize(2); _display->setTextSize(2);
_display->setCursor(0, 43); _display->setCursor(0, 43);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin()); sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
_display->print(tmp); _display->print(tmp);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
} else { } else {
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
} }
} }
_need_refresh = false; _need_refresh = false;

2
examples/companion_radio/ui-tiny/ScrollingStatusBar.h

@ -104,7 +104,7 @@ public:
if (_status[0] == 0) return; if (_status[0] == 0) return;
display.setTextSize(1); display.setTextSize(1);
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::primary_txt);
// if (_needs_redraw) { // if (_needs_redraw) {
// _text_width = display.getTextWidth(_status); // _text_width = display.getTextWidth(_status);

31
examples/companion_radio/ui-tiny/UITask.cpp

@ -56,24 +56,24 @@ public:
int render(DisplayDriver& display) override { int render(DisplayDriver& display) override {
if (millis() < version_after) { if (millis() < version_after) {
// meshcore logo // meshcore logo
display.setColor(DisplayDriver::BLUE); display.setColor(UIColor::corp_blue);
int logoWidth = 72; int logoWidth = 72;
display.drawXbm(0, 0, meshcore_logo, 72, 36); display.drawXbm(0, 0, meshcore_logo, 72, 36);
} else { } else {
// meshcore website // meshcore website
const char* website = "meshcore.io"; const char* website = "meshcore.io";
display.setColor(DisplayDriver::LIGHT); display.setColor(UIColor::primary_txt);
display.setTextSize(1); display.setTextSize(1);
uint16_t websiteWidth = display.getTextWidth(website); uint16_t websiteWidth = display.getTextWidth(website);
display.setCursor((display.width() - websiteWidth) / 2, 9); display.setCursor((display.width() - websiteWidth) / 2, 9);
display.print(website); display.print(website);
// version info // version info
display.setColor(DisplayDriver::LIGHT);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width()/2, 18, _version_info); display.drawTextCentered(display.width()/2, 18, _version_info);
display.setColor(UIColor::secondary_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width()/2, 27, FIRMWARE_BUILD_DATE); display.drawTextCentered(display.width()/2, 27, FIRMWARE_BUILD_DATE);
} }
@ -163,7 +163,7 @@ public:
// display.print(filtered_name); // display.print(filtered_name);
display.setColor(DisplayDriver::YELLOW); display.setColor(UIColor::primary_txt);
display.setTextSize(2); display.setTextSize(2);
sprintf(tmp, "MSG: %d", _task->getMsgCount()); sprintf(tmp, "MSG: %d", _task->getMsgCount());
display.setCursor(0, 10); display.setCursor(0, 10);
@ -180,19 +180,19 @@ public:
display.drawTextCentered(display.width() / 2, 54, tmp); display.drawTextCentered(display.width() / 2, 54, tmp);
#endif #endif
if (_task->hasConnection()) { if (_task->hasConnection()) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::warning_txt);
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width() / 2, display.height()-8, "< Connected >"); display.drawTextCentered(display.width() / 2, display.height()-8, "< Connected >");
} else if (the_mesh.getBLEPin() != 0) { // BT pin } else if (the_mesh.getBLEPin() != 0) { // BT pin
display.setColor(DisplayDriver::RED); display.setColor(UIColor::warning_txt);
display.setTextSize(2); display.setTextSize(2);
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin()); sprintf(tmp, "Pin:%d", the_mesh.getBLEPin());
display.drawTextCentered(display.width() / 2, display.height()-8, tmp); display.drawTextCentered(display.width() / 2, display.height()-8, tmp);
} }
} else if (_page == HomePage::RECENT) { } else if (_page == HomePage::RECENT) {
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE); the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE);
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::primary_txt);
int y = 8; int y = 8;
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) { for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) {
auto a = &recent[i]; auto a = &recent[i];
@ -216,7 +216,7 @@ public:
display.print(tmp); display.print(tmp);
} }
} else if (_page == HomePage::RADIO) { } else if (_page == HomePage::RADIO) {
display.setColor(DisplayDriver::YELLOW); display.setColor(UIColor::primary_txt);
display.setTextSize(1); display.setTextSize(1);
// frequency and spreading factor // frequency and spreading factor
display.setCursor(0, 8); display.setCursor(0, 8);
@ -238,14 +238,14 @@ public:
display.drawTextRightAlign(display.width(), 26, tmp); display.drawTextRightAlign(display.width(), 26, tmp);
} else if (_page == HomePage::BLUETOOTH) { } else if (_page == HomePage::BLUETOOTH) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
display.drawXbm((display.width() - 32) / 2, 8, display.drawXbm((display.width() - 32) / 2, 8,
_task->isSerialEnabled() ? bluetooth_on : bluetooth_off, _task->isSerialEnabled() ? bluetooth_on : bluetooth_off,
32, 32); 32, 32);
display.setTextSize(1); display.setTextSize(1);
// display.drawTextCentered(display.width() / 2, 40 - 11, "toggle: " PRESS_LABEL); // display.drawTextCentered(display.width() / 2, 40 - 11, "toggle: " PRESS_LABEL);
} else if (_page == HomePage::ADVERT) { } else if (_page == HomePage::ADVERT) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::corp_blue);
display.drawXbm((display.width() - 32) / 2, 8, advert_icon, 32, 32); display.drawXbm((display.width() - 32) / 2, 8, advert_icon, 32, 32);
// display.drawTextCentered(display.width() / 2, 40 - 11, "advert: " PRESS_LABEL); // display.drawTextCentered(display.width() / 2, 40 - 11, "advert: " PRESS_LABEL);
#if ENV_INCLUDE_GPS == 1 #if ENV_INCLUDE_GPS == 1
@ -264,9 +264,11 @@ public:
#else #else
strcpy(buf, gps_state ? "gps on" : "gps off"); strcpy(buf, gps_state ? "gps on" : "gps off");
#endif #endif
display.setColor(UIColor::primary_txt);
display.drawTextLeftAlign(0, y, buf); display.drawTextLeftAlign(0, y, buf);
if (nmea == NULL) { if (nmea == NULL) {
// y = y + 8; // y = y + 8;
display.setColor(UIColor::warning_txt);
display.drawTextLeftAlign(0, y, "Can't access GPS"); display.drawTextLeftAlign(0, y, "Can't access GPS");
} else { } else {
if (!gps_state || !nmea->isValid()) { if (!gps_state || !nmea->isValid()) {
@ -274,6 +276,7 @@ public:
} else { } else {
sprintf(buf, "%d sat", nmea->satellitesCount()); sprintf(buf, "%d sat", nmea->satellitesCount());
} }
display.setColor(UIColor::primary_txt);
display.drawTextRightAlign(display.width()-1, y, buf); display.drawTextRightAlign(display.width()-1, y, buf);
y = y + 8; y = y + 8;
sprintf(buf, "lat %.4f", sprintf(buf, "lat %.4f",
@ -349,8 +352,10 @@ public:
r.skipData(type); r.skipData(type);
strcpy(name, "unk"); sprintf(buf, ""); strcpy(name, "unk"); sprintf(buf, "");
} }
display.setColor(UIColor::secondary_txt);
display.setCursor(0, y); display.setCursor(0, y);
display.print(name); display.print(name);
display.setColor(UIColor::primary_txt);
display.setCursor( display.setCursor(
display.width()-display.getTextWidth(buf)-1, y display.width()-display.getTextWidth(buf)-1, y
); );
@ -361,7 +366,7 @@ public:
else sensors_scroll_offset = 0; else sensors_scroll_offset = 0;
#endif #endif
} else if (_page == HomePage::SHUTDOWN) { } else if (_page == HomePage::SHUTDOWN) {
display.setColor(DisplayDriver::GREEN); display.setColor(UIColor::secondary_txt);
display.setTextSize(1); display.setTextSize(1);
if (_shutdown_init) { if (_shutdown_init) {
display.drawTextCentered(display.width() / 2, 20, "hibernating..."); display.drawTextCentered(display.width() / 2, 20, "hibernating...");
@ -692,9 +697,9 @@ void UITask::loop() {
_display->setTextSize(1); _display->setTextSize(1);
int y = _display->height() / 3; int y = _display->height() / 3;
int p = _display->height() / 32; int p = _display->height() / 32;
_display->setColor(DisplayDriver::DARK); _display->setColor(UIColor::popup_bkg);
_display->fillRect(p, y, _display->width() - p*2, y); _display->fillRect(p, y, _display->width() - p*2, y);
_display->setColor(DisplayDriver::LIGHT); // draw box border _display->setColor(UIColor::popup_txt); // draw box border
_display->drawRect(p, y, _display->width() - p*2, y); _display->drawRect(p, y, _display->width() - p*2, y);
_display->drawTextCentered(_display->width() / 2, y + p*3, _alert); _display->drawTextCentered(_display->width() / 2, y + p*3, _alert);
_next_refresh = _alert_expiry; // will need refresh when alert is dismissed _next_refresh = _alert_expiry; // will need refresh when alert is dismissed

12
examples/simple_repeater/UITask.cpp

@ -57,18 +57,17 @@ void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < _started_at + BOOT_SCREEN_MILLIS) { // boot screen if (millis() < _started_at + BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// meshcore website // meshcore website
const char* website = "https://meshcore.io"; const char* website = "https://meshcore.io";
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
_display->setTextSize(1); _display->setTextSize(1);
_display->drawTextCentered(_display->width() / 2, 22, website); _display->drawTextCentered(_display->width() / 2, 22, website);
// version info // version info
_display->setColor(DisplayDriver::LIGHT);
_display->setTextSize(1); _display->setTextSize(1);
_display->drawTextCentered(_display->width() / 2, 35, _version_info); _display->drawTextCentered(_display->width() / 2, 35, _version_info);
@ -77,13 +76,13 @@ void UITask::renderCurrScreen() {
_display->drawTextCentered(_display->width() / 2, 48, node_type); _display->drawTextCentered(_display->width() / 2, 48, node_type);
} else if (_powering_off_at > 0) { } else if (_powering_off_at > 0) {
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// meshcore website // meshcore website
const char* website = "https://meshcore.io"; const char* website = "https://meshcore.io";
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
_display->setTextSize(1); _display->setTextSize(1);
_display->drawTextCentered(_display->width()/ 2, 22, website); _display->drawTextCentered(_display->width()/ 2, 22, website);
@ -95,12 +94,11 @@ void UITask::renderCurrScreen() {
} else { } else {
_display->setCursor(0, 0); _display->setCursor(0, 0);
_display->setTextSize(1); _display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
_display->print(_node_prefs->node_name); _display->print(_node_prefs->node_name);
// freq / sf // freq / sf
_display->setCursor(0, 20); _display->setCursor(0, 20);
_display->setColor(DisplayDriver::YELLOW);
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
_display->print(tmp); _display->print(tmp);

8
examples/simple_room_server/UITask.cpp

@ -49,20 +49,19 @@ void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen if (millis() < BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// meshcore website // meshcore website
const char* website = "https://meshcore.io"; const char* website = "https://meshcore.io";
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
_display->setTextSize(1); _display->setTextSize(1);
uint16_t websiteWidth = _display->getTextWidth(website); uint16_t websiteWidth = _display->getTextWidth(website);
_display->setCursor((_display->width() - websiteWidth) / 2, 22); _display->setCursor((_display->width() - websiteWidth) / 2, 22);
_display->print(website); _display->print(website);
// version info // version info
_display->setColor(DisplayDriver::LIGHT);
_display->setTextSize(1); _display->setTextSize(1);
uint16_t versionWidth = _display->getTextWidth(_version_info); uint16_t versionWidth = _display->getTextWidth(_version_info);
_display->setCursor((_display->width() - versionWidth) / 2, 35); _display->setCursor((_display->width() - versionWidth) / 2, 35);
@ -77,12 +76,11 @@ void UITask::renderCurrScreen() {
// node name // node name
_display->setCursor(0, 0); _display->setCursor(0, 0);
_display->setTextSize(1); _display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
_display->print(_node_prefs->node_name); _display->print(_node_prefs->node_name);
// freq / sf // freq / sf
_display->setCursor(0, 20); _display->setCursor(0, 20);
_display->setColor(DisplayDriver::YELLOW);
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
_display->print(tmp); _display->print(tmp);

8
examples/simple_sensor/UITask.cpp

@ -49,20 +49,19 @@ void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen if (millis() < BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(UIColor::corp_blue);
int logoWidth = 128; int logoWidth = 128;
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
// meshcore website // meshcore website
const char* website = "https://meshcore.io"; const char* website = "https://meshcore.io";
_display->setColor(DisplayDriver::LIGHT); _display->setColor(UIColor::primary_txt);
_display->setTextSize(1); _display->setTextSize(1);
uint16_t websiteWidth = _display->getTextWidth(website); uint16_t websiteWidth = _display->getTextWidth(website);
_display->setCursor((_display->width() - websiteWidth) / 2, 22); _display->setCursor((_display->width() - websiteWidth) / 2, 22);
_display->print(website); _display->print(website);
// version info // version info
_display->setColor(DisplayDriver::LIGHT);
_display->setTextSize(1); _display->setTextSize(1);
uint16_t versionWidth = _display->getTextWidth(_version_info); uint16_t versionWidth = _display->getTextWidth(_version_info);
_display->setCursor((_display->width() - versionWidth) / 2, 35); _display->setCursor((_display->width() - versionWidth) / 2, 35);
@ -77,12 +76,11 @@ void UITask::renderCurrScreen() {
// node name // node name
_display->setCursor(0, 0); _display->setCursor(0, 0);
_display->setTextSize(1); _display->setTextSize(1);
_display->setColor(DisplayDriver::GREEN); _display->setColor(UIColor::primary_txt);
_display->print(_node_prefs->node_name); _display->print(_node_prefs->node_name);
// freq / sf // freq / sf
_display->setCursor(0, 20); _display->setCursor(0, 20);
_display->setColor(DisplayDriver::YELLOW);
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
_display->print(tmp); _display->print(tmp);

14
src/helpers/ui/DisplayDriver.h

@ -3,12 +3,20 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
using ColorVal = uint16_t;
class UIColor {
public:
// color definitions (by element _type_)
static ColorVal window_bkg, title_bkg, title_txt, primary_txt, secondary_txt, warning_txt, popup_bkg, popup_txt, corp_blue;
};
class DisplayDriver { class DisplayDriver {
int _w, _h; int _w, _h;
protected: protected:
DisplayDriver(int w, int h) { _w = w; _h = h; } DisplayDriver(int w, int h) { _w = w; _h = h; }
public: public:
enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light //enum Color { DARK=0, LIGHT, RED, GREEN, BLUE, YELLOW, ORANGE }; // on b/w screen, colors will be !=0 synonym of light
int width() const { return _w; } int width() const { return _w; }
int height() const { return _h; } int height() const { return _h; }
@ -18,9 +26,9 @@ public:
virtual void turnOn() = 0; virtual void turnOn() = 0;
virtual void turnOff() = 0; virtual void turnOff() = 0;
virtual void clear() = 0; virtual void clear() = 0;
virtual void startFrame(Color bkg = DARK) = 0; virtual void startFrame(ColorVal bkg = UIColor::window_bkg) = 0;
virtual void setTextSize(int sz) = 0; virtual void setTextSize(int sz) = 0;
virtual void setColor(Color c) = 0; virtual void setColor(ColorVal c) = 0;
virtual void setCursor(int x, int y) = 0; virtual void setCursor(int x, int y) = 0;
virtual void print(const char* str) = 0; virtual void print(const char* str) = 0;
virtual void printWordWrap(const char* str, int max_width) { print(str); } // fallback to basic print() if no override virtual void printWordWrap(const char* str, int max_width) { print(str); } // fallback to basic print() if no override

30
src/helpers/ui/E213Display.cpp

@ -2,6 +2,17 @@
#include "../../MeshCore.h" #include "../../MeshCore.h"
// Color scheme
ColorVal UIColor::window_bkg = WHITE;
ColorVal UIColor::title_bkg = BLACK;
ColorVal UIColor::title_txt = WHITE;
ColorVal UIColor::primary_txt = BLACK;
ColorVal UIColor::secondary_txt = BLACK;
ColorVal UIColor::warning_txt = BLACK;
ColorVal UIColor::popup_bkg = BLACK;
ColorVal UIColor::popup_txt = WHITE;
ColorVal UIColor::corp_blue = BLACK;
BaseDisplay* E213Display::detectEInk() BaseDisplay* E213Display::detectEInk()
{ {
// Test 1: Logic of BUSY pin // Test 1: Logic of BUSY pin
@ -108,16 +119,18 @@ void E213Display::clear() {
display->clear(); display->clear();
} }
void E213Display::startFrame(Color bkg) { void E213Display::startFrame(ColorVal bkg) {
display_crc.reset(); display_crc.reset();
// Fill screen with white first to ensure clean background // Fill screen with white first to ensure clean background
display->fillRect(0, 0, width(), height(), WHITE); display->fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) { if (bkg == 0) {
// Fill with black if light background requested (inverted for e-ink) // Fill with black if light background requested (inverted for e-ink)
display->fillRect(0, 0, width(), height(), BLACK); display->fillRect(0, 0, width(), height(), BLACK);
} }
_color = UIColor::primary_txt;
display->setTextColor(_color);
} }
void E213Display::setTextSize(int sz) { void E213Display::setTextSize(int sz) {
@ -126,9 +139,10 @@ void E213Display::setTextSize(int sz) {
display->setTextSize(sz); display->setTextSize(sz);
} }
void E213Display::setColor(Color c) { void E213Display::setColor(ColorVal c) {
display_crc.update<Color>(c); _color = c;
// implemented in individual display methods display_crc.update<ColorVal>(c);
display->setTextColor(_color);
} }
void E213Display::setCursor(int x, int y) { void E213Display::setCursor(int x, int y) {
@ -147,7 +161,7 @@ void E213Display::fillRect(int x, int y, int w, int h) {
display_crc.update<int>(y); display_crc.update<int>(y);
display_crc.update<int>(w); display_crc.update<int>(w);
display_crc.update<int>(h); display_crc.update<int>(h);
display->fillRect(x, y, w, h, BLACK); display->fillRect(x, y, w, h, _color);
} }
void E213Display::drawRect(int x, int y, int w, int h) { void E213Display::drawRect(int x, int y, int w, int h) {
@ -155,7 +169,7 @@ void E213Display::drawRect(int x, int y, int w, int h) {
display_crc.update<int>(y); display_crc.update<int>(y);
display_crc.update<int>(w); display_crc.update<int>(w);
display_crc.update<int>(h); display_crc.update<int>(h);
display->drawRect(x, y, w, h, BLACK); display->drawRect(x, y, w, h, _color);
} }
void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) { void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@ -179,7 +193,7 @@ void E213Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// If the bit is set, draw the pixel // If the bit is set, draw the pixel
if (bitSet) { if (bitSet) {
display->drawPixel(x + bx, y + by, BLACK); display->drawPixel(x + bx, y + by, _color);
} }
} }
} }

5
src/helpers/ui/E213Display.h

@ -16,6 +16,7 @@ class E213Display : public DisplayDriver {
RefCountedDigitalPin* _periph_power; RefCountedDigitalPin* _periph_power;
CRC32 display_crc; CRC32 display_crc;
uint32_t last_display_crc_value = 0; uint32_t last_display_crc_value = 0;
uint16_t _color;
public: public:
E213Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(250, 122), _periph_power(periph_power) {} E213Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(250, 122), _periph_power(periph_power) {}
@ -30,9 +31,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char *str) override; void print(const char *str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

30
src/helpers/ui/E290Display.cpp

@ -2,6 +2,17 @@
#include "../../MeshCore.h" #include "../../MeshCore.h"
// Color scheme
ColorVal UIColor::window_bkg = WHITE;
ColorVal UIColor::title_bkg = BLACK;
ColorVal UIColor::title_txt = WHITE;
ColorVal UIColor::primary_txt = BLACK;
ColorVal UIColor::secondary_txt = BLACK;
ColorVal UIColor::warning_txt = BLACK;
ColorVal UIColor::popup_bkg = BLACK;
ColorVal UIColor::popup_txt = WHITE;
ColorVal UIColor::corp_blue = BLACK;
bool E290Display::begin() { bool E290Display::begin() {
if (_init) return true; if (_init) return true;
@ -62,15 +73,17 @@ void E290Display::clear() {
display.clear(); display.clear();
} }
void E290Display::startFrame(Color bkg) { void E290Display::startFrame(ColorVal bkg) {
display_crc.reset(); display_crc.reset();
// Fill screen with white first to ensure clean background // Fill screen with white first to ensure clean background
display.fillRect(0, 0, width(), height(), WHITE); display.fillRect(0, 0, width(), height(), WHITE);
if (bkg == LIGHT) { if (bkg == 0) {
// Fill with black if light background requested (inverted for e-ink) // Fill with black if light background requested (inverted for e-ink)
display.fillRect(0, 0, width(), height(), BLACK); display.fillRect(0, 0, width(), height(), BLACK);
} }
_color = UIColor::primary_txt;
display.setTextColor(_color);
} }
void E290Display::setTextSize(int sz) { void E290Display::setTextSize(int sz) {
@ -79,9 +92,10 @@ void E290Display::setTextSize(int sz) {
display.setTextSize(sz); display.setTextSize(sz);
} }
void E290Display::setColor(Color c) { void E290Display::setColor(ColorVal c) {
display_crc.update<Color>(c); _color = c;
// implemented in individual display methods display_crc.update<ColorVal>(c);
display.setTextColor(_color);
} }
void E290Display::setCursor(int x, int y) { void E290Display::setCursor(int x, int y) {
@ -100,7 +114,7 @@ void E290Display::fillRect(int x, int y, int w, int h) {
display_crc.update<int>(y); display_crc.update<int>(y);
display_crc.update<int>(w); display_crc.update<int>(w);
display_crc.update<int>(h); display_crc.update<int>(h);
display.fillRect(x, y, w, h, BLACK); display.fillRect(x, y, w, h, _color);
} }
void E290Display::drawRect(int x, int y, int w, int h) { void E290Display::drawRect(int x, int y, int w, int h) {
@ -108,7 +122,7 @@ void E290Display::drawRect(int x, int y, int w, int h) {
display_crc.update<int>(y); display_crc.update<int>(y);
display_crc.update<int>(w); display_crc.update<int>(w);
display_crc.update<int>(h); display_crc.update<int>(h);
display.drawRect(x, y, w, h, BLACK); display.drawRect(x, y, w, h, _color);
} }
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) { void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
@ -132,7 +146,7 @@ void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) {
// If the bit is set, draw the pixel // If the bit is set, draw the pixel
if (bitSet) { if (bitSet) {
display.drawPixel(x + bx, y + by, BLACK); display.drawPixel(x + bx, y + by, _color);
} }
} }
} }

5
src/helpers/ui/E290Display.h

@ -16,6 +16,7 @@ class E290Display : public DisplayDriver {
RefCountedDigitalPin* _periph_power; RefCountedDigitalPin* _periph_power;
CRC32 display_crc; CRC32 display_crc;
uint32_t last_display_crc_value = 0; uint32_t last_display_crc_value = 0;
uint16_t _color;
public: public:
E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {} E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {}
@ -26,9 +27,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char *str) override; void print(const char *str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

29
src/helpers/ui/GxEPDDisplay.cpp

@ -14,6 +14,18 @@
SPIClass SPI1 = SPIClass(FSPI); SPIClass SPI1 = SPIClass(FSPI);
#endif #endif
// Color scheme
ColorVal UIColor::window_bkg = GxEPD_WHITE;
ColorVal UIColor::title_bkg = GxEPD_BLACK;
ColorVal UIColor::title_txt = GxEPD_WHITE;
ColorVal UIColor::primary_txt = GxEPD_BLACK;
ColorVal UIColor::secondary_txt = GxEPD_BLACK;
ColorVal UIColor::warning_txt = GxEPD_BLACK;
ColorVal UIColor::popup_bkg = GxEPD_BLACK;
ColorVal UIColor::popup_txt = GxEPD_WHITE;
ColorVal UIColor::corp_blue = GxEPD_BLACK;
bool GxEPDDisplay::begin() { bool GxEPDDisplay::begin() {
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
#ifdef ESP32 #ifdef ESP32
@ -61,9 +73,9 @@ void GxEPDDisplay::clear() {
display_crc.reset(); display_crc.reset();
} }
void GxEPDDisplay::startFrame(Color bkg) { void GxEPDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(GxEPD_WHITE); display.fillScreen(bkg);
display.setTextColor(_curr_color = GxEPD_BLACK); display.setTextColor(_curr_color = UIColor::primary_txt);
display_crc.reset(); display_crc.reset();
} }
@ -85,14 +97,9 @@ void GxEPDDisplay::setTextSize(int sz) {
} }
} }
void GxEPDDisplay::setColor(Color c) { void GxEPDDisplay::setColor(ColorVal c) {
display_crc.update<Color> (c); display_crc.update<ColorVal> (c);
// colours need to be inverted for epaper displays display.setTextColor(_curr_color = c);
if (c == DARK) {
display.setTextColor(_curr_color = GxEPD_WHITE);
} else {
display.setTextColor(_curr_color = GxEPD_BLACK);
}
} }
void GxEPDDisplay::setCursor(int x, int y) { void GxEPDDisplay::setCursor(int x, int y) {

4
src/helpers/ui/GxEPDDisplay.h

@ -51,9 +51,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

48
src/helpers/ui/LGFXDisplay.cpp

@ -1,5 +1,16 @@
#include "LGFXDisplay.h" #include "LGFXDisplay.h"
// Color scheme
ColorVal UIColor::window_bkg = 0xFFFF;
ColorVal UIColor::title_bkg = 0x001F;
ColorVal UIColor::title_txt = 0xFFFF;
ColorVal UIColor::primary_txt = 0x0000;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = 0xFD20;
ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
ColorVal UIColor::popup_txt = 0x0000;
ColorVal UIColor::corp_blue = 0x001A;
bool LGFXDisplay::begin() { bool LGFXDisplay::begin() {
turnOn(); turnOn();
display->init(); display->init();
@ -35,45 +46,20 @@ void LGFXDisplay::clear() {
buffer.clearDisplay(); buffer.clearDisplay();
} }
void LGFXDisplay::startFrame(Color bkg) { void LGFXDisplay::startFrame(ColorVal bkg) {
// display->startWrite(); // display->startWrite();
// display->getScanLine(); // display->getScanLine();
buffer.clearDisplay(); _color = bkg;
buffer.setTextColor(TFT_WHITE); buffer.fillScreen(_color);
buffer.setTextColor(_color = UIColor::primary_txt);
} }
void LGFXDisplay::setTextSize(int sz) { void LGFXDisplay::setTextSize(int sz) {
buffer.setTextSize(sz); buffer.setTextSize(sz);
} }
void LGFXDisplay::setColor(Color c) { void LGFXDisplay::setColor(ColorVal c) {
// _color = (c != 0) ? ILI9342_WHITE : ILI9342_BLACK; buffer.setTextColor(_color = c);
switch (c) {
case DARK:
_color = TFT_BLACK;
break;
case LIGHT:
_color = TFT_WHITE;
break;
case RED:
_color = TFT_RED;
break;
case GREEN:
_color = TFT_GREEN;
break;
case BLUE:
_color = TFT_BLUE;
break;
case YELLOW:
_color = TFT_YELLOW;
break;
case ORANGE:
_color = TFT_ORANGE;
break;
default:
_color = TFT_WHITE;
}
buffer.setTextColor(_color);
} }
void LGFXDisplay::setCursor(int x, int y) { void LGFXDisplay::setCursor(int x, int y) {

4
src/helpers/ui/LGFXDisplay.h

@ -25,9 +25,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

34
src/helpers/ui/NV3001BDisplay.cpp

@ -96,18 +96,16 @@
#define NV3001B_TEXT_SIZE2_SCALE_Y 3 #define NV3001B_TEXT_SIZE2_SCALE_Y 3
#endif #endif
static uint16_t mapColor(DisplayDriver::Color c) { // Color scheme
switch (c) { ColorVal UIColor::window_bkg = 0xFFFF;
case DisplayDriver::DARK: return 0x0000; ColorVal UIColor::title_bkg = 0x001F;
case DisplayDriver::LIGHT: return 0xffff; ColorVal UIColor::title_txt = 0xFFFF;
case DisplayDriver::RED: return 0xf800; ColorVal UIColor::primary_txt = 0x0000;
case DisplayDriver::GREEN: return 0x07e0; ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
case DisplayDriver::BLUE: return 0x001f; ColorVal UIColor::warning_txt = 0xFD20;
case DisplayDriver::YELLOW: return 0xffe0; ColorVal UIColor::popup_bkg = 0x07FF; // CYAN
case DisplayDriver::ORANGE: return 0xfd20; ColorVal UIColor::popup_txt = 0x0000;
default: return 0xffff; ColorVal UIColor::corp_blue = 0x001A;
}
}
static int scaleX(int x) { static int scaleX(int x) {
return (int)(x * DISPLAY_SCALE_X); return (int)(x * DISPLAY_SCALE_X);
@ -465,15 +463,15 @@ void NV3001BDisplay::turnOff() {
void NV3001BDisplay::clear() { void NV3001BDisplay::clear() {
uint16_t saved = color; uint16_t saved = color;
color = 0x0000; color = UIColor::window_bkg;
fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT); fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT);
color = saved; color = saved;
} }
void NV3001BDisplay::startFrame(Color bkg) { void NV3001BDisplay::startFrame(ColorVal bkg) {
color = mapColor(bkg); color = bkg;
fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT); fillPhysicalRect(0, 0, NV3001B_SCREEN_WIDTH, NV3001B_SCREEN_HEIGHT);
color = 0xffff; color = UIColor::primary_txt;
text_size = 1; text_size = 1;
cursor_x = 0; cursor_x = 0;
cursor_y = 0; cursor_y = 0;
@ -483,8 +481,8 @@ void NV3001BDisplay::setTextSize(int sz) {
text_size = sz < 1 ? 1 : sz; text_size = sz < 1 ? 1 : sz;
} }
void NV3001BDisplay::setColor(Color c) { void NV3001BDisplay::setColor(ColorVal c) {
color = mapColor(c); color = c;
} }
void NV3001BDisplay::setCursor(int x, int y) { void NV3001BDisplay::setCursor(int x, int y) {

4
src/helpers/ui/NV3001BDisplay.h

@ -55,9 +55,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

4
src/helpers/ui/NullDisplayDriver.h

@ -11,9 +11,9 @@ public:
void turnOn() override { } void turnOn() override { }
void turnOff() override { } void turnOff() override { }
void clear() override { } void clear() override { }
void startFrame(Color bkg = DARK) override { } void startFrame(ColorVal bkg = UIColor::window_bkg) override { }
void setTextSize(int sz) override { } void setTextSize(int sz) override { }
void setColor(Color c) override { } void setColor(ColorVal c) override { }
void setCursor(int x, int y) override { } void setCursor(int x, int y) override { }
void print(const char* str) override { } void print(const char* str) override { }
void fillRect(int x, int y, int w, int h) override { } void fillRect(int x, int y, int w, int h) override { }

19
src/helpers/ui/SH1106Display.cpp

@ -9,6 +9,17 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
return (error == 0); return (error == 0);
} }
// Color scheme
ColorVal UIColor::window_bkg = SH110X_BLACK;
ColorVal UIColor::title_bkg = SH110X_WHITE;
ColorVal UIColor::title_txt = SH110X_BLACK;
ColorVal UIColor::primary_txt = SH110X_WHITE;
ColorVal UIColor::secondary_txt = SH110X_WHITE;
ColorVal UIColor::warning_txt = SH110X_WHITE;
ColorVal UIColor::popup_bkg = SH110X_WHITE;
ColorVal UIColor::popup_txt = SH110X_BLACK;
ColorVal UIColor::corp_blue = SH110X_WHITE;
bool SH1106Display::begin() bool SH1106Display::begin()
{ {
// Wire must already be initialised by board.begin() before this is called. // Wire must already be initialised by board.begin() before this is called.
@ -35,7 +46,7 @@ void SH1106Display::clear()
display.display(); display.display();
} }
void SH1106Display::startFrame(Color bkg) void SH1106Display::startFrame(ColorVal bkg)
{ {
display.clearDisplay(); // TODO: apply 'bkg' display.clearDisplay(); // TODO: apply 'bkg'
_color = SH110X_WHITE; _color = SH110X_WHITE;
@ -49,9 +60,9 @@ void SH1106Display::setTextSize(int sz)
display.setTextSize(sz); display.setTextSize(sz);
} }
void SH1106Display::setColor(Color c) void SH1106Display::setColor(ColorVal c)
{ {
_color = (c != 0) ? SH110X_WHITE : SH110X_BLACK; _color = c;
display.setTextColor(_color); display.setTextColor(_color);
} }
@ -77,7 +88,7 @@ void SH1106Display::drawRect(int x, int y, int w, int h)
void SH1106Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) void SH1106Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h)
{ {
display.drawBitmap(x, y, bits, w, h, SH110X_WHITE); display.drawBitmap(x, y, bits, w, h, _color);
} }
uint16_t SH1106Display::getTextWidth(const char *str) uint16_t SH1106Display::getTextWidth(const char *str)

4
src/helpers/ui/SH1106Display.h

@ -30,9 +30,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char *str) override; void print(const char *str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

19
src/helpers/ui/SSD1306Display.cpp

@ -6,6 +6,17 @@ bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
return (error == 0); return (error == 0);
} }
// Color scheme
ColorVal UIColor::window_bkg = SSD1306_BLACK;
ColorVal UIColor::title_bkg = SSD1306_WHITE;
ColorVal UIColor::title_txt = SSD1306_BLACK;
ColorVal UIColor::primary_txt = SSD1306_WHITE;
ColorVal UIColor::secondary_txt = SSD1306_WHITE;
ColorVal UIColor::warning_txt = SSD1306_WHITE;
ColorVal UIColor::popup_bkg = SSD1306_WHITE;
ColorVal UIColor::popup_txt = SSD1306_BLACK;
ColorVal UIColor::corp_blue = SSD1306_WHITE;
bool SSD1306Display::begin() { bool SSD1306Display::begin() {
if (!_isOn) { if (!_isOn) {
if (_peripher_power) _peripher_power->claim(); if (_peripher_power) _peripher_power->claim();
@ -44,7 +55,7 @@ void SSD1306Display::clear() {
display.display(); display.display();
} }
void SSD1306Display::startFrame(Color bkg) { void SSD1306Display::startFrame(ColorVal bkg) {
display.clearDisplay(); // TODO: apply 'bkg' display.clearDisplay(); // TODO: apply 'bkg'
_color = SSD1306_WHITE; _color = SSD1306_WHITE;
display.setTextColor(_color); display.setTextColor(_color);
@ -56,8 +67,8 @@ void SSD1306Display::setTextSize(int sz) {
display.setTextSize(sz); display.setTextSize(sz);
} }
void SSD1306Display::setColor(Color c) { void SSD1306Display::setColor(ColorVal c) {
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK; _color = c;
display.setTextColor(_color); display.setTextColor(_color);
} }
@ -78,7 +89,7 @@ void SSD1306Display::drawRect(int x, int y, int w, int h) {
} }
void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x, y, bits, w, h, SSD1306_WHITE); display.drawBitmap(x, y, bits, w, h, _color);
} }
uint16_t SSD1306Display::getTextWidth(const char* str) { uint16_t SSD1306Display::getTextWidth(const char* str) {

4
src/helpers/ui/SSD1306Display.h

@ -35,9 +35,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

46
src/helpers/ui/ST7735Display.cpp

@ -417,6 +417,17 @@ bool ST7735Display::i2c_probe(TwoWire& wire, uint8_t addr) {
#define PIN_TFT_LEDA_CTL_ACTIVE HIGH #define PIN_TFT_LEDA_CTL_ACTIVE HIGH
#endif #endif
// Color scheme
ColorVal UIColor::window_bkg = ST77XX_WHITE;
ColorVal UIColor::title_bkg = ST77XX_BLUE;
ColorVal UIColor::title_txt = ST77XX_WHITE;
ColorVal UIColor::primary_txt = ST77XX_BLACK;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
ColorVal UIColor::popup_txt = ST77XX_BLACK;
ColorVal UIColor::corp_blue = 0x001A;
bool ST7735Display::begin() { bool ST7735Display::begin() {
if (!sprite) { if (!sprite) {
// alloc offscreen canvas // alloc offscreen canvas
@ -527,9 +538,9 @@ void ST7735Display::clear() {
sprite->fillScreen(ST77XX_BLACK); sprite->fillScreen(ST77XX_BLACK);
} }
void ST7735Display::startFrame(Color bkg) { void ST7735Display::startFrame(ColorVal bkg) {
sprite->fillScreen(ST77XX_BLACK); sprite->fillScreen(bkg);
sprite->setTextColor(curr_color = ST77XX_WHITE); sprite->setTextColor(curr_color = UIColor::primary_txt);
sprite->setFreeFont(); sprite->setFreeFont();
sprite->setTextSize(1); // This one affects size of Please wait... message sprite->setTextSize(1); // This one affects size of Please wait... message
//sprite->cp437(true); // Use full 256 char 'Code Page 437' font //sprite->cp437(true); // Use full 256 char 'Code Page 437' font
@ -539,33 +550,8 @@ void ST7735Display::setTextSize(int sz) {
sprite->setTextSize(sz); sprite->setTextSize(sz);
} }
void ST7735Display::setColor(Color c) { void ST7735Display::setColor(ColorVal c) {
switch (c) { curr_color = c;
case DisplayDriver::DARK :
curr_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
curr_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
curr_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
curr_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
curr_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
curr_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
curr_color = ST77XX_ORANGE;
break;
default:
curr_color = ST77XX_WHITE;
break;
}
sprite->setTextColor(curr_color); sprite->setTextColor(curr_color);
} }

4
src/helpers/ui/ST7735Display.h

@ -33,9 +33,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

51
src/helpers/ui/ST7789Display.cpp

@ -26,6 +26,17 @@
#define SCALE_Y DISPLAY_SCALE_Y #define SCALE_Y DISPLAY_SCALE_Y
#endif #endif
// Color scheme
ColorVal UIColor::window_bkg = ST77XX_WHITE;
ColorVal UIColor::title_bkg = ST77XX_BLUE;
ColorVal UIColor::title_txt = ST77XX_WHITE;
ColorVal UIColor::primary_txt = ST77XX_BLACK;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
ColorVal UIColor::popup_txt = ST77XX_BLACK;
ColorVal UIColor::corp_blue = 0x001A;
bool ST7789Display::begin() { bool ST7789Display::begin() {
if(!_isOn) { if(!_isOn) {
pinMode(PIN_TFT_VDD_CTL, OUTPUT); pinMode(PIN_TFT_VDD_CTL, OUTPUT);
@ -90,9 +101,9 @@ void ST7789Display::clear() {
display.clear(); display.clear();
} }
void ST7789Display::startFrame(Color bkg) { void ST7789Display::startFrame(ColorVal bkg) {
display.clear(); display.fillRect(0, 0, display.width(), display.height());
_color = ST77XX_WHITE; _color = UIColor::primary_txt;
display.setRGB(_color); display.setRGB(_color);
display.setFont(ArialMT_Plain_16); display.setFont(ArialMT_Plain_16);
} }
@ -110,38 +121,8 @@ void ST7789Display::setTextSize(int sz) {
} }
} }
void ST7789Display::setColor(Color c) { void ST7789Display::setColor(ColorVal c) {
switch (c) { display.setRGB(_color = c);
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
display.setColor(OLEDDISPLAY_COLOR::BLACK);
break;
#if 0
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
#endif
default:
_color = ST77XX_WHITE;
display.setColor(OLEDDISPLAY_COLOR::WHITE);
break;
}
display.setRGB(_color);
} }
void ST7789Display::setCursor(int x, int y) { void ST7789Display::setCursor(int x, int y) {

4
src/helpers/ui/ST7789Display.h

@ -27,9 +27,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void printWordWrap(const char* str, int max_width) override; void printWordWrap(const char* str, int max_width) override;

47
src/helpers/ui/ST7789LCDDisplay.cpp

@ -23,6 +23,17 @@ bool ST7789LCDDisplay::i2c_probe(TwoWire& wire, uint8_t addr) {
return true; return true;
} }
// Color scheme
ColorVal UIColor::window_bkg = ST77XX_WHITE;
ColorVal UIColor::title_bkg = ST77XX_BLUE;
ColorVal UIColor::title_txt = ST77XX_WHITE;
ColorVal UIColor::primary_txt = ST77XX_BLACK;
ColorVal UIColor::secondary_txt = (18 << 11) | (36 << 5) | 18; // mid-gray
ColorVal UIColor::warning_txt = ST77XX_ORANGE;
ColorVal UIColor::popup_bkg = ST77XX_CYAN;
ColorVal UIColor::popup_txt = ST77XX_BLACK;
ColorVal UIColor::corp_blue = 0x001A;
bool ST7789LCDDisplay::begin() { bool ST7789LCDDisplay::begin() {
if (!_isOn) { if (!_isOn) {
if (_peripher_power) _peripher_power->claim(); if (_peripher_power) _peripher_power->claim();
@ -78,9 +89,9 @@ void ST7789LCDDisplay::clear() {
display.fillScreen(ST77XX_BLACK); display.fillScreen(ST77XX_BLACK);
} }
void ST7789LCDDisplay::startFrame(Color bkg) { void ST7789LCDDisplay::startFrame(ColorVal bkg) {
display.fillScreen(ST77XX_BLACK); display.fillScreen(bkg);
display.setTextColor(ST77XX_WHITE); display.setTextColor(_color = UIColor::primary_txt);
display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message display.setTextSize(1 * DISPLAY_SCALE_X); // This one affects size of Please wait... message
display.cp437(true); // Use full 256 char 'Code Page 437' font display.cp437(true); // Use full 256 char 'Code Page 437' font
} }
@ -89,34 +100,8 @@ void ST7789LCDDisplay::setTextSize(int sz) {
display.setTextSize(sz * DISPLAY_SCALE_X); display.setTextSize(sz * DISPLAY_SCALE_X);
} }
void ST7789LCDDisplay::setColor(Color c) { void ST7789LCDDisplay::setColor(ColorVal c) {
switch (c) { display.setTextColor(_color = c);
case DisplayDriver::DARK :
_color = ST77XX_BLACK;
break;
case DisplayDriver::LIGHT :
_color = ST77XX_WHITE;
break;
case DisplayDriver::RED :
_color = ST77XX_RED;
break;
case DisplayDriver::GREEN :
_color = ST77XX_GREEN;
break;
case DisplayDriver::BLUE :
_color = ST77XX_BLUE;
break;
case DisplayDriver::YELLOW :
_color = ST77XX_YELLOW;
break;
case DisplayDriver::ORANGE :
_color = ST77XX_ORANGE;
break;
default:
_color = ST77XX_WHITE;
break;
}
display.setTextColor(_color);
} }
void ST7789LCDDisplay::setCursor(int x, int y) { void ST7789LCDDisplay::setCursor(int x, int y) {

4
src/helpers/ui/ST7789LCDDisplay.h

@ -47,9 +47,9 @@ public:
void turnOn() override; void turnOn() override;
void turnOff() override; void turnOff() override;
void clear() override; void clear() override;
void startFrame(Color bkg = DARK) override; void startFrame(ColorVal bkg = UIColor::window_bkg) override;
void setTextSize(int sz) override; void setTextSize(int sz) override;
void setColor(Color c) override; void setColor(ColorVal c) override;
void setCursor(int x, int y) override; void setCursor(int x, int y) override;
void print(const char* str) override; void print(const char* str) override;
void fillRect(int x, int y, int w, int h) override; void fillRect(int x, int y, int w, int h) override;

12
src/helpers/ui/U8g2Display.cpp

@ -0,0 +1,12 @@
#include "U8g2Display.h"
// Color scheme
ColorVal UIColor::window_bkg = 0;
ColorVal UIColor::title_bkg = 1;
ColorVal UIColor::title_txt = 0;
ColorVal UIColor::primary_txt = 1;
ColorVal UIColor::secondary_txt = 1;
ColorVal UIColor::warning_txt = 1;
ColorVal UIColor::popup_bkg = 1;
ColorVal UIColor::popup_txt = 0;
ColorVal UIColor::corp_blue = 1;

16
src/helpers/ui/U8g2Display.h

@ -72,10 +72,10 @@ public:
_u8g2.sendBuffer(); _u8g2.sendBuffer();
} }
void startFrame(Color bkg = DARK) override { void startFrame(ColorVal bkg = UIColor::window_bkg) override {
_u8g2.clearBuffer(); _u8g2.clearBuffer(); // TODO: apply 'bkg' color
_drawColor = 1; _drawColor = UIColor::primary_txt;
_u8g2.setDrawColor(1); _u8g2.setDrawColor(_drawColor);
applyFont(1); applyFont(1);
} }
@ -83,8 +83,8 @@ public:
applyFont(sz); applyFont(sz);
} }
void setColor(Color c) override { void setColor(ColorVal c) override {
_drawColor = (c != DARK) ? 1 : 0; _drawColor = c;
_u8g2.setDrawColor(_drawColor); _u8g2.setDrawColor(_drawColor);
} }
@ -94,22 +94,18 @@ public:
} }
void print(const char* str) override { void print(const char* str) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawStr(_cursorX, _cursorY, str); _u8g2.drawStr(_cursorX, _cursorY, str);
} }
void fillRect(int x, int y, int w, int h) override { void fillRect(int x, int y, int w, int h) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawBox(x, y, w, h); _u8g2.drawBox(x, y, w, h);
} }
void drawRect(int x, int y, int w, int h) override { void drawRect(int x, int y, int w, int h) override {
_u8g2.setDrawColor(_drawColor);
_u8g2.drawFrame(x, y, w, h); _u8g2.drawFrame(x, y, w, h);
} }
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override {
_u8g2.setDrawColor(1);
_u8g2.drawXBM(x, y, w, h, bits); _u8g2.drawXBM(x, y, w, h, bits);
} }

2
variants/lilygo_techo_card/platformio.ini

@ -23,7 +23,7 @@ build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp> +<helpers/*.cpp>
+<TechoCardBoard.cpp> +<TechoCardBoard.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp> +<helpers/sensors/EnvironmentSensorManager.cpp>
+<helpers/ui/U8g2Display.h> +<helpers/ui/U8g2Display.cpp>
+<helpers/ui/MomentaryButton.cpp> +<helpers/ui/MomentaryButton.cpp>
+<../variants/lilygo_techo_card> +<../variants/lilygo_techo_card>
lib_deps = lib_deps =

Loading…
Cancel
Save