From 521d14231c8948e8b5a22700f3afec117f52c0d6 Mon Sep 17 00:00:00 2001 From: SaberShip <6741766+SaberShip@users.noreply.github.com> Date: Fri, 21 Apr 2023 12:25:58 -0500 Subject: [PATCH] Add initial multicolor support for 3 color displays (#32) * Initial multicolor support * Default back to DISP_BW * improve accent color logic --------- Co-authored-by: SaberShip --- platformio/include/config.h | 13 +++++++--- platformio/include/renderer.h | 4 +-- platformio/src/config.cpp | 1 + platformio/src/renderer.cpp | 46 ++++++++++++++++++++--------------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/platformio/include/config.h b/platformio/include/config.h index 76f89c7b5..30a0a7826 100644 --- a/platformio/include/config.h +++ b/platformio/include/config.h @@ -27,11 +27,17 @@ // https://www.waveshare.com/product/7.5inch-e-paper-hat.htm // DISP_3C - Waveshare 800x480, 7.5inch E-Ink display, Red/Black/White // https://www.waveshare.com/product/7.5inch-e-paper-hat-b.htm -// Note: Although this 3-color panel is supported, this program only draws -// black/white to the screen. (i.e. no red icons/text) // Uncomment the macro that identifies your panel. (exactly 1 must be defined) #define DISP_BW -// #define DISP_3C +//#define DISP_3C + +// 3 Color E-Ink display +// Defines the 3rd color to be used when a 3 color display is selected. +#ifdef DISP_3C + #define ACCENT_COLOR GxEPD_RED +#else + #define ACCENT_COLOR GxEPD_BLACK +#endif // LOCALE // If your locale is not here, you can add it by copying and modifying one of @@ -192,6 +198,7 @@ extern const int BED_TIME; extern const int WAKE_TIME; extern const char UNITS; extern const int HOURLY_GRAPH_MAX; +extern const float BATTERY_WARN_VOLTAGE; extern const float LOW_BATTERY_VOLTAGE; extern const float VERY_LOW_BATTERY_VOLTAGE; extern const float CRIT_LOW_BATTERY_VOLTAGE; diff --git a/platformio/include/renderer.h b/platformio/include/renderer.h index 10d2c7a8a..77aff7850 100644 --- a/platformio/include/renderer.h +++ b/platformio/include/renderer.h @@ -45,10 +45,10 @@ typedef enum alignment uint16_t getStringWidth(String text); uint16_t getStringHeight(String text); -void drawString(int16_t x, int16_t y, String text, alignment_t alignment); +void drawString(int16_t x, int16_t y, String text, alignment_t alignment, uint16_t color=GxEPD_BLACK); void drawMultiLnString(int16_t x, int16_t y, String text, alignment_t alignment, uint16_t max_width, uint16_t max_lines, - int16_t line_spacing); + int16_t line_spacing, uint16_t color=GxEPD_BLACK); void initDisplay(); void drawCurrentConditions(owm_current_t ¤t, owm_daily_t &today, owm_resp_air_pollution_t &owm_air_pollution, diff --git a/platformio/src/config.cpp b/platformio/src/config.cpp index 9f9dd0a19..a0c121ab7 100644 --- a/platformio/src/config.cpp +++ b/platformio/src/config.cpp @@ -115,6 +115,7 @@ const int HOURLY_GRAPH_MAX = 24; // minutes). Once the battery voltage has fallen to CRIT_LOW_BATTERY_VOLTAGE, // the esp32 will hibernate and a manual press of the reset (RST) button to // begin operating again. +const float BATTERY_WARN_VOLTAGE = 3.40; // (volts) ~ 10% const float LOW_BATTERY_VOLTAGE = 3.20; // (volts) const float VERY_LOW_BATTERY_VOLTAGE = 3.10; // (volts) const float CRIT_LOW_BATTERY_VOLTAGE = 3.00; // (volts) diff --git a/platformio/src/renderer.cpp b/platformio/src/renderer.cpp index 223b395e8..edb1f9a69 100644 --- a/platformio/src/renderer.cpp +++ b/platformio/src/renderer.cpp @@ -77,10 +77,11 @@ uint16_t getStringHeight(String text) /* Draws a string with alignment */ -void drawString(int16_t x, int16_t y, String text, alignment_t alignment) +void drawString(int16_t x, int16_t y, String text, alignment_t alignment, uint16_t color) { int16_t x1, y1; uint16_t w, h; + display.setTextColor(color); display.getTextBounds(text, x, y, &x1, &y1, &w, &h); if (alignment == RIGHT) x = x - w; @@ -101,7 +102,7 @@ void drawString(int16_t x, int16_t y, String text, alignment_t alignment) */ void drawMultiLnString(int16_t x, int16_t y, String text, alignment_t alignment, uint16_t max_width, uint16_t max_lines, - int16_t line_spacing) + int16_t line_spacing, uint16_t color) { uint16_t current_line = 0; @@ -182,7 +183,7 @@ void drawMultiLnString(int16_t x, int16_t y, String text, alignment_t alignment, } // end if (splitAt != -1) } // end inner while - drawString(x, y + (current_line * line_spacing), subStr, alignment); + drawString(x, y + (current_line * line_spacing), subStr, alignment, color); // update textRemaining to no longer include what was printed // +1 for exclusive bounds, +1 to get passed space/dash @@ -640,7 +641,7 @@ void drawAlerts(std::vector &alerts, owm_alerts_t &cur_alert = alerts[alert_indices[0]]; display.drawInvertedBitmap(196, 8, getAlertBitmap48(cur_alert), 48, 48, - GxEPD_BLACK); + ACCENT_COLOR); // must be called after getAlertBitmap toTitleCase(cur_alert.event); @@ -674,7 +675,7 @@ void drawAlerts(std::vector &alerts, owm_alerts_t &cur_alert = alerts[alert_indices[i]]; display.drawInvertedBitmap(196, (i * 32), getAlertBitmap32(cur_alert), - 32, 32, GxEPD_BLACK); + 32, 32, ACCENT_COLOR); // must be called after getAlertBitmap toTitleCase(cur_alert.event); @@ -693,7 +694,7 @@ void drawLocationDate(const String &city, const String &date) { // location, date display.setFont(&FONT_16pt8b); - drawString(DISP_WIDTH - 2, 23, city, RIGHT); + drawString(DISP_WIDTH - 2, 23, city, RIGHT, ACCENT_COLOR); display.setFont(&FONT_12pt8b); drawString(DISP_WIDTH - 2, 30 + 4 + 17, date, RIGHT); return; @@ -793,7 +794,7 @@ void drawOutlookGraph(owm_hourly_t *const hourly, tm timeInfo) #if defined(UNITS_TEMP_CELSIUS) || defined(UNITS_TEMP_FAHRENHEIT) dataStr += "\xB0"; #endif - drawString(xPos0 - 8, yTick + 4, dataStr, RIGHT); + drawString(xPos0 - 8, yTick + 4, dataStr, RIGHT, ACCENT_COLOR); // PoP dataStr = String(100 - (i * 20)); @@ -855,9 +856,9 @@ void drawOutlookGraph(owm_hourly_t *const hourly, tm timeInfo) #endif // graph temperature - display.drawLine(x0_t , y0_t , x1_t , y1_t , GxEPD_BLACK); - display.drawLine(x0_t , y0_t + 1, x1_t , y1_t + 1, GxEPD_BLACK); - display.drawLine(x0_t - 1, y0_t , x1_t - 1, y1_t , GxEPD_BLACK); + display.drawLine(x0_t , y0_t , x1_t , y1_t , ACCENT_COLOR); + display.drawLine(x0_t , y0_t + 1, x1_t , y1_t + 1, ACCENT_COLOR); + display.drawLine(x0_t - 1, y0_t , x1_t - 1, y1_t , ACCENT_COLOR); } // PoP @@ -917,46 +918,53 @@ void drawStatusBar(String statusStr, String refreshTimeStr, int rssi, double batVoltage) { String dataStr; + uint16_t dataColor = GxEPD_BLACK; display.setFont(&FONT_6pt8b); int pos = DISP_WIDTH - 2; const int sp = 2; // battery int batPercent = calcBatPercent(batVoltage); + if (batVoltage < BATTERY_WARN_VOLTAGE) { + dataColor = ACCENT_COLOR; + } dataStr = String(batPercent) + "% (" + String( round(100.0 * batVoltage) / 100.0, 2 ) + "v)"; - drawString(pos, DISP_HEIGHT - 1 - 2, dataStr, RIGHT); + drawString(pos, DISP_HEIGHT - 1 - 2, dataStr, RIGHT, dataColor); pos -= getStringWidth(dataStr) + 25; display.drawInvertedBitmap(pos, DISP_HEIGHT - 1 - 17, - getBatBitmap24(batPercent), 24, 24, GxEPD_BLACK); + getBatBitmap24(batPercent), 24, 24, dataColor); pos -= sp + 9; // wifi dataStr = String(getWiFidesc(rssi)); + dataColor = rssi >= -70 ? GxEPD_BLACK : ACCENT_COLOR; if (rssi != 0) { dataStr += " (" + String(rssi) + "dBm)"; } - drawString(pos, DISP_HEIGHT - 1 - 2, dataStr, RIGHT); + drawString(pos, DISP_HEIGHT - 1 - 2, dataStr, RIGHT, dataColor); pos -= getStringWidth(dataStr) + 19; display.drawInvertedBitmap(pos, DISP_HEIGHT - 1 - 13, getWiFiBitmap16(rssi), - 16, 16, GxEPD_BLACK); + 16, 16, dataColor); pos -= sp + 8; // last refresh - drawString(pos, DISP_HEIGHT - 1 - 2, refreshTimeStr, RIGHT); + dataColor = GxEPD_BLACK; + drawString(pos, DISP_HEIGHT - 1 - 2, refreshTimeStr, RIGHT, dataColor); pos -= getStringWidth(refreshTimeStr) + 25; display.drawInvertedBitmap(pos, DISP_HEIGHT - 1 - 21, wi_refresh_32x32, - 32, 32, GxEPD_BLACK); + 32, 32, dataColor); pos -= sp; // status + dataColor = ACCENT_COLOR; if (!statusStr.isEmpty()) { - drawString(pos, DISP_HEIGHT - 1 - 2, statusStr, RIGHT); + drawString(pos, DISP_HEIGHT - 1 - 2, statusStr, RIGHT, dataColor); pos -= getStringWidth(statusStr) + 24; display.drawInvertedBitmap(pos, DISP_HEIGHT - 1 - 18, error_icon_24x24, - 24, 24, GxEPD_BLACK); + 24, 24, dataColor); } return; @@ -977,6 +985,6 @@ void drawError(const uint8_t *bitmap_196x196, errMsgLn2, CENTER); display.drawInvertedBitmap(DISP_WIDTH / 2 - 196 / 2, DISP_HEIGHT / 2 - 196 / 2 - 21, - bitmap_196x196, 196, 196, GxEPD_BLACK); + bitmap_196x196, 196, 196, ACCENT_COLOR); return; } // end drawError