From 7cc1ca1525068b17abc4b35efea4e6ee396ed145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChl?= <31169771+Blueforcer@users.noreply.github.com> Date: Tue, 18 Apr 2023 00:00:50 +0200 Subject: [PATCH] v0.56 - Better bar- and linegraph drawing algorithm - Allows to draw a progressbar in notifications and Custom Apps - Allows to disable the Temp&Hum senor via dev.json --- docs/api.md | 20 +-- docs/dev.md | 3 +- src/Apps.h | 19 ++- src/DisplayManager.cpp | 266 +++++++++++++++------------------------ src/DisplayManager.h | 2 +- src/Functions.h | 25 +++- src/Globals.cpp | 10 +- src/Globals.h | 2 +- src/MQTTManager.cpp | 14 ++- src/PeripheryManager.cpp | 8 +- src/UpdateManager.cpp | 8 +- src/main.cpp | 2 + 12 files changed, 193 insertions(+), 186 deletions(-) diff --git a/docs/api.md b/docs/api.md index ed806165..64333c0d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -49,22 +49,28 @@ All keys are optional, so you can send just the properties you want to use. | Key | Type | Description | Default | | --- | ---- | ----------- | ------- | | `text` | string | The text to display on the app. | N/A | +| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 | +| `textOffset` | integer | Sets an offset for the x position of a starting text. | 0 | +| `color` | string or array of integers | The text, bar or line color | | +| `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false | | `icon` | string | The icon ID or filename (without extension) to display on the app. | N/A | +| `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 | | `repeat` | number | Sets how many times the text should be scrolled through the matrix before the app ends. | 1 | -| `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false | | `duration` | number | Sets how long the app or notification should be displayed. | 5 | -| `color` | string | A color hex string for the text color, or an array of R,G,B values | "#FFFFFF" or [255,255,0] | +| `lifetime` | integer | Removes the custom app when there is no update after the given time in seconds | 0 | | `hold` | boolean | Set it to true, to hold your **notification** on top until you press the middle button or dismiss it via HomeAssistant. This key only belongs to notification. | false | | `sound` | string | The filename of your RTTTL ringtone file (without extension). | N/A | -| `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 | | `bar` | array of integers | draws a bargraph. Without icon maximum 16 values, with icon 11 values | N/A | | `line` | array of integers | draws a linechart. Without icon maximum 16 values, with icon 11 values | N/A | | `autoscale` | boolean | enables or disables autoscaling for bar and linechart | true | -| `lifetime` | integer | Removes the custom app when there is no update after the given time in seconds | 0 | -| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 | -| `textOffset` | integer | Sets an offset for the x position of a starting text. | 0 | +| `progress` | integer | Shows a progressbar. Value can be 0-100 | -1 | +| `progressC` | string or array of integers | The color of the progressbar | -1 | +| `progressBC` | string or array of integers | The color of the progressbar background | -1 | | `pos` | number | defines the position of your custompage in the loop, starting at 0 for the first position. This will only apply with your first push. You cant change the position afterwards with [this function](api?id=addremove-and-rearange-apps) | N/A | - + +Color values can have a hex string or an array of R,G,B values: +`"#FFFFFF" or [255,255,0]` + ### Example Here's an example JSON object to display the text "Hello, AWTRIX Light!" with the icon name "1", in rainbow colors, for 10 seconds: diff --git a/docs/dev.md b/docs/dev.md index 9fcfacc2..6f14f891 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -20,4 +20,5 @@ The JSON object has the following properties: | `color_correction` | array of int | Sets the colorcorrection of the matrix | `[255,255,255]` | | `color_temperature` | array of int | Sets the colortemperature of the matrix | `[255,255,255]` | | `gamma` |float | Sets the gamma of the matrix | `2.5` | -| `update_check` | boolean | Enables searchf or new version every 1 hour. This could cause in loop stack overflow! | `false` | \ No newline at end of file +| `update_check` | boolean | Enables searchfunction for new version every 1 hour. This could cause in loop stack overflow! | `false` | +| `sensor_reading` | boolean | Enables or disables the reading of the Temp&Hum sensor | `true` | diff --git a/src/Apps.h b/src/Apps.h index 31e06468..301585fe 100644 --- a/src/Apps.h +++ b/src/Apps.h @@ -54,6 +54,9 @@ struct CustomApp std::vector colors; std::vector fragments; uint8_t textOffset; + int progress = -1; + uint16_t pColor; + uint16_t pbColor; }; String currentCustomApp; @@ -84,6 +87,9 @@ struct Notification std::vector colors; std::vector fragments; uint8_t textOffset; + int progress = -1; + uint16_t pColor; + uint16_t pbColor; }; Notification notify; @@ -451,7 +457,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState } else { - + if (ca->rainbow) { DisplayManager.HSVtext(x + textX, 6 + y, ca->text.c_str(), false, ca->textCase); @@ -530,6 +536,12 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState // matrix->drawLine(8 + x + ca->iconPosition, 0 + y, 8 + x + ca->iconPosition, 7 + y, 0); } } + + if (ca->progress > -1) + { + DisplayManager.drawProgressBar((hasIcon ? 9 : 0), 7 + y, ca->progress, ca->pColor, ca->pbColor); + } + // Reset text color DisplayManager.getInstance().resetTextColor(); } @@ -746,6 +758,11 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer } } + if (notify.progress > -1) + { + DisplayManager.drawProgressBar((hasIcon ? 9 : 0), 7, notify.progress, notify.pColor, notify.pbColor); + } + // Reset text color after displaying notification DisplayManager.getInstance().resetTextColor(); } diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 8a731c1d..e72f78a5 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -256,7 +256,8 @@ bool parseFragmentsText(const String &jsonText, std::vector &colors, s uint16_t color; if (fragmentObj.containsKey("c")) { - color = hexToRgb565(fragmentObj["c"].as()); + auto fragColor = doc["color"]; + color = getColorFromJsonVariant(fragColor, standardColor); } else { @@ -307,6 +308,28 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json) customApp.sound = ""; } + customApp.progress = doc.containsKey("progress") ? doc["progress"].as() : -1; + + if (doc.containsKey("progressC")) + { + auto progressC = doc["progressC"]; + customApp.pColor = getColorFromJsonVariant(progressC, matrix->Color(0, 255, 0)); + } + else + { + customApp.pColor = matrix->Color(0, 255, 0); + } + + if (doc.containsKey("progressBC")) + { + auto progressBC = doc["progressBC"]; + customApp.pbColor = getColorFromJsonVariant(progressBC, matrix->Color(255, 255, 255)); + } + else + { + customApp.pbColor = matrix->Color(255, 255, 255); + } + bool autoscale = true; if (doc.containsKey("autoscale")) { @@ -396,21 +419,7 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json) if (doc.containsKey("color")) { auto color = doc["color"]; - if (color.is()) - { - customApp.color = hexToRgb565(color.as()); - } - else if (color.is() && color.size() == 3) - { - uint8_t r = color[0]; - uint8_t g = color[1]; - uint8_t b = color[2]; - customApp.color = (r << 11) | (g << 5) | b; - } - else - { - customApp.color = TEXTCOLOR_565; - } + customApp.color = getColorFromJsonVariant(color, TEXTCOLOR_565); } else { @@ -479,6 +488,29 @@ void DisplayManager_::generateNotification(const char *json) { StaticJsonDocument<1024> doc; deserializeJson(doc, json); + + notify.progress = doc.containsKey("progress") ? doc["progress"].as() : -1; + + if (doc.containsKey("progressC")) + { + auto progressC = doc["progressC"]; + notify.pColor = getColorFromJsonVariant(progressC, matrix->Color(0, 255, 0)); + } + else + { + notify.pColor = matrix->Color(0, 255, 0); + } + + if (doc.containsKey("progressBC")) + { + auto progressBC = doc["progressBC"]; + notify.pbColor = getColorFromJsonVariant(progressBC, matrix->Color(255, 255, 255)); + } + else + { + notify.pbColor = matrix->Color(255, 255, 255); + } + notify.duration = doc.containsKey("duration") ? doc["duration"].as() * 1000 : TIME_PER_APP; notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as() : -1; notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as() : false; @@ -578,21 +610,7 @@ void DisplayManager_::generateNotification(const char *json) if (doc.containsKey("color")) { auto color = doc["color"]; - if (color.is()) - { - notify.color = hexToRgb565(color.as()); - } - else if (color.is() && color.size() == 3) - { - uint8_t r = color[0]; - uint8_t g = color[1]; - uint8_t b = color[2]; - notify.color = (r << 11) | (g << 5) | b; - } - else - { - notify.color = TEXTCOLOR_565; - } + notify.color = getColorFromJsonVariant(color, TEXTCOLOR_565); } else { @@ -611,7 +629,6 @@ void DisplayManager_::generateNotification(const char *json) } notify.flag = true; - showGif = false; if (doc.containsKey("icon")) { @@ -677,12 +694,14 @@ void DisplayManager_::loadNativeApps() // Update the "date" app at position 1 updateApp("date", DateApp, SHOW_DATE, 1); - // Update the "temp" app at position 2 - updateApp("temp", TempApp, SHOW_TEMP, 2); - - // Update the "hum" app at position 3 - updateApp("hum", HumApp, SHOW_HUM, 3); + if (SENSOR_READING) + { + // Update the "temp" app at position 2 + updateApp("temp", TempApp, SHOW_TEMP, 2); + // Update the "hum" app at position 3 + updateApp("hum", HumApp, SHOW_HUM, 3); + } #ifdef ULANZI // Update the "bat" app at position 4 updateApp("bat", BatApp, SHOW_BAT, 4); @@ -889,17 +908,14 @@ void DisplayManager_::switchToApp(const char *json) ui->transitionToApp(index); } -void DisplayManager_::drawProgressBar(int cur, int total) +void DisplayManager_::drawProgressBar(int16_t x, int16_t y, int progress, uint16_t pColor, uint16_t pbColor) { - matrix->clear(); - int progress = (cur * 100) / total; - char progressStr[5]; - snprintf(progressStr, 5, "%d%%", progress); - printText(0, 6, progressStr, true, false); - int leds_for_progress = (progress * MATRIX_WIDTH * MATRIX_HEIGHT) / 100; - matrix->drawFastHLine(0, 7, MATRIX_WIDTH, matrix->Color(100, 100, 100)); - matrix->drawFastHLine(0, 7, leds_for_progress / MATRIX_HEIGHT, matrix->Color(0, 255, 0)); - matrix->show(); + int available_length = 32 - x; + int leds_for_progress = (progress * available_length) / 100; + matrix->drawFastHLine(x, y, available_length, pbColor); + Serial.println(leds_for_progress); + if (leds_for_progress > 0) + matrix->drawFastHLine(x, y, leds_for_progress, pColor); } void DisplayManager_::drawMenuIndicator(int cur, int total, uint16_t color) @@ -924,35 +940,35 @@ void DisplayManager_::drawMenuIndicator(int cur, int total, uint16_t color) void DisplayManager_::drawBarChart(int16_t x, int16_t y, const int newData[], byte dataSize, bool withIcon, uint16_t color) { - int barWidth; - if (withIcon) - { - barWidth = ((32 - 9) / (dataSize)-1); - } - else - { - barWidth = (32 / (dataSize)-1); - } - + int availableWidth = withIcon ? (32 - 9) : 32; + int gap = 1; + int totalGapsWidth = (dataSize - 1) * gap; + int barWidth = (availableWidth - totalGapsWidth) / dataSize; int startX = withIcon ? 9 : 0; for (int i = 0; i < dataSize; i++) { - int x1 = x + startX + (barWidth + 1) * i; + int x1 = x + startX + i * (barWidth + gap); int barHeight = newData[i]; - int y1 = min(8 - barHeight, 7); - matrix->fillRect(x1, y1 + y, barWidth, barHeight, color); + int y1 = (barHeight > 0) ? (8 - barHeight) : 8; + + if (barHeight > 0) + { + matrix->fillRect(x1, y1 + y, barWidth, barHeight, color); + } } } void DisplayManager_::drawLineChart(int16_t x, int16_t y, const int newData[], byte dataSize, bool withIcon, uint16_t color) { + int availableWidth = withIcon ? (32 - 9) : 32; int startX = withIcon ? 9 : 0; + float xStep = static_cast(availableWidth) / static_cast(dataSize - 1); int lastX = x + startX; int lastY = y + 8 - newData[0]; for (int i = 1; i < dataSize; i++) { - int x1 = x + startX + (32 - startX) / (dataSize - 1) * i; + int x1 = x + startX + static_cast(xStep * i); int y1 = y + 8 - newData[i]; matrix->drawLine(lastX, lastY, x1, y1, color); lastX = x1; @@ -1072,10 +1088,13 @@ String DisplayManager_::getStats() doc[LDRRawKey] = LDR_RAW; doc[RamKey] = ESP.getFreeHeap(); doc[BrightnessKey] = BRIGHTNESS; - snprintf(buffer, 5, "%.0f", CURRENT_TEMP); - doc[TempKey] = buffer; - snprintf(buffer, 5, "%.0f", CURRENT_HUM); - doc[HumKey] = buffer; + if (SENSOR_READING) + { + snprintf(buffer, 5, "%.0f", CURRENT_TEMP); + doc[TempKey] = buffer; + snprintf(buffer, 5, "%.0f", CURRENT_HUM); + doc[HumKey] = buffer; + } doc[UpTimeKey] = PeripheryManager.readUptime(); doc[SignalStrengthKey] = WiFi.RSSI(); doc[UpdateKey] = UPDATE_AVAILABLE; @@ -1220,64 +1239,31 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json) if (doc.containsKey("color")) { auto color = doc["color"]; - if (color.is()) - { - uint16_t col = hexToRgb565(color.as()); - if (col > 0) + uint16_t col = getColorFromJsonVariant(color, TEXTCOLOR_565); + + if (col > 0) + { + if (indicator == 1) { - if (indicator == 1) - { - ui->setIndicator1State(true); - ui->setIndicator1Color(col); - } - else - { - ui->setIndicator2State(true); - ui->setIndicator2Color(col); - } + ui->setIndicator1State(true); + ui->setIndicator1Color(col); } else { - if (indicator == 1) - { - ui->setIndicator1State(false); - } - else - { - ui->setIndicator2State(false); - } + ui->setIndicator2State(true); + ui->setIndicator2Color(col); } } - else if (color.is() && color.size() == 3) + else { - uint8_t r = color[0]; - uint8_t g = color[1]; - uint8_t b = color[2]; - - if (r == 0 && g == 0 && b == 0) + if (indicator == 1) { - if (indicator == 1) - { - ui->setIndicator1State(false); - } - else - { - ui->setIndicator2State(false); - } + ui->setIndicator1State(false); } else { - if (indicator == 1) - { - ui->setIndicator1State(true); - ui->setIndicator1Color((r << 11) | (g << 5) | b); - } - else - { - ui->setIndicator2State(true); - ui->setIndicator2Color((r << 11) | (g << 5) | b); - } + ui->setIndicator2State(false); } } } @@ -1424,63 +1410,19 @@ void DisplayManager_::setNewSettings(const char *json) if (doc.containsKey("WDCA")) { - auto temperature = doc["WDCA"]; - if (temperature.is()) - { - WDC_ACTIVE = hexToRgb565(temperature.as()); - } - else if (temperature.is() && temperature.size() == 3) - { - uint8_t r = temperature[0]; - uint8_t g = temperature[1]; - uint8_t b = temperature[2]; - WDC_ACTIVE = (r << 11) | (g << 5) | b; - } + auto WDCA = doc["WDCA"]; + WDC_ACTIVE = getColorFromJsonVariant(WDCA, matrix->Color(255, 255, 255)); } if (doc.containsKey("WDCI")) { - auto temperature = doc["WDCI"]; - if (temperature.is()) - { - WDC_INACTIVE = hexToRgb565(temperature.as()); - } - else if (temperature.is() && temperature.size() == 3) - { - uint8_t r = temperature[0]; - uint8_t g = temperature[1]; - uint8_t b = temperature[2]; - WDC_INACTIVE = (r << 11) | (g << 5) | b; - } - } - if (doc.containsKey("WDCA")) - { - auto temperature = doc["WDCA"]; - if (temperature.is()) - { - WDC_ACTIVE = hexToRgb565(temperature.as()); - } - else if (temperature.is() && temperature.size() == 3) - { - uint8_t r = temperature[0]; - uint8_t g = temperature[1]; - uint8_t b = temperature[2]; - WDC_ACTIVE = (r << 11) | (g << 5) | b; - } + auto WDCI = doc["WDCI"]; + WDC_INACTIVE = getColorFromJsonVariant(WDCI, matrix->Color(120, 120, 120)); } + if (doc.containsKey("TCOL")) { - auto temperature = doc["TCOL"]; - if (temperature.is()) - { - TEXTCOLOR_565 = hexToRgb565(temperature.as()); - } - else if (temperature.is() && temperature.size() == 3) - { - uint8_t r = temperature[0]; - uint8_t g = temperature[1]; - uint8_t b = temperature[2]; - TEXTCOLOR_565 = (r << 11) | (g << 5) | b; - } + auto TCOL = doc["TCOL"]; + TEXTCOLOR_565 = getColorFromJsonVariant(TCOL, matrix->Color(255, 255, 255)); } applyAllSettings(); saveSettings(); diff --git a/src/DisplayManager.h b/src/DisplayManager.h index bc952c82..a754be17 100644 --- a/src/DisplayManager.h +++ b/src/DisplayManager.h @@ -55,7 +55,7 @@ class DisplayManager_ void switchToApp(const char *json); void setNewSettings(const char *json); void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile); - void drawProgressBar(int cur, int total); + void drawProgressBar(int16_t x, int16_t y, int progress, uint16_t pColor, uint16_t pbColor); void drawMenuIndicator(int cur, int total, uint16_t color); void drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h); void drawBarChart(int16_t x, int16_t y, const int data[], byte dataSize, bool withIcon, uint16_t color); diff --git a/src/Functions.h b/src/Functions.h index a0dfe6ef..15daed63 100644 --- a/src/Functions.h +++ b/src/Functions.h @@ -31,7 +31,6 @@ const uint8_t PROGMEM gamma8[] = { 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; - CRGB applyGammaCorrection(const CRGB& color) { CRGB correctedColor; correctedColor.r = pgm_read_byte(&gamma8[color.r]); @@ -50,7 +49,7 @@ uint32_t hsvToRgb(uint8_t h, uint8_t s, uint8_t v) (rgb.b >> 3); } -uint16_t hexToRgb565(String hexValue) +uint16_t hexToRgb565(String hexValue, uint16_t defaultColor) { hexValue.replace("#", ""); uint8_t r = strtol(hexValue.substring(0, 2).c_str(), NULL, 16); @@ -58,12 +57,32 @@ uint16_t hexToRgb565(String hexValue) uint8_t b = strtol(hexValue.substring(4, 6).c_str(), NULL, 16); if ((errno == ERANGE) || (r > 255) || (g > 255) || (b > 255)) { - return 0xFFFF; + return defaultColor; } uint16_t color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); return color; } + +uint16_t getColorFromJsonVariant(JsonVariant colorVariant, uint16_t defaultColor) +{ + if (colorVariant.is()) + { + return hexToRgb565(colorVariant.as(),defaultColor); + } + else if (colorVariant.is() && colorVariant.size() == 3) + { + uint8_t r = colorVariant[0]; + uint8_t g = colorVariant[1]; + uint8_t b = colorVariant[2]; + return (r << 11) | (g << 5) | b; + } + else + { + return defaultColor; + } +} + uint16_t getTextWidth(const char *text, byte textCase) { uint16_t width = 0; diff --git a/src/Globals.cpp b/src/Globals.cpp index 4f256cfb..b7c98db1 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -55,6 +55,11 @@ void loadDevSettings() BOOT_SOUND = doc["bootsound"].as(); } + if (doc.containsKey("sensor_reading")) + { + SENSOR_READING = doc["sensor_reading"].as(); + } + if (doc.containsKey("matrix")) { MATRIX_LAYOUT = doc["matrix"]; @@ -188,7 +193,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.55"; +const char *VERSION = "0.56"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; String MQTT_USER; @@ -265,4 +270,5 @@ uint16_t WDC_ACTIVE; uint16_t WDC_INACTIVE; bool BLOCK_NAVIGATION = false; bool UPDATE_CHECK = false; -float GAMMA = 0; \ No newline at end of file +float GAMMA = 0; +bool SENSOR_READING = true; \ No newline at end of file diff --git a/src/Globals.h b/src/Globals.h index b18e65ba..abbbe8c7 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -102,5 +102,5 @@ void loadSettings(); void saveSettings(); extern bool BLOCK_NAVIGATION; extern bool UPDATE_CHECK; - +extern bool SENSOR_READING; #endif // Globals_H \ No newline at end of file diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index da200353..f0cf4aea 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -427,6 +427,7 @@ void MQTTManager_::setup() sprintf(verID, HAverID, macStr); version = new HASensor(verID); version->setName(HAverName); + version->setValue(VERSION); sprintf(sigID, HAsigID, macStr); strength = new HASensor(sigID); @@ -511,11 +512,14 @@ void MQTTManager_::sendStats() battery->setValue(buffer); #endif - snprintf(buffer, 5, "%.0f", CURRENT_TEMP); - temperature->setValue(buffer); - snprintf(buffer, 5, "%.0f", CURRENT_HUM); - humidity->setValue(buffer); + if (SENSOR_READING) + { + snprintf(buffer, 5, "%.0f", CURRENT_TEMP); + temperature->setValue(buffer); + snprintf(buffer, 5, "%.0f", CURRENT_HUM); + humidity->setValue(buffer); + } snprintf(buffer, 5, "%.0f", CURRENT_LUX); illuminance->setValue(buffer); @@ -542,7 +546,7 @@ void MQTTManager_::sendStats() itoa(freeHeapBytes, rambuffer, 10); ram->setValue(rambuffer); uptime->setValue(PeripheryManager.readUptime()); - version->setValue(VERSION); + transition->setState(AUTO_TRANSITION, false); update->setState(UPDATE_AVAILABLE, false); diff --git a/src/PeripheryManager.cpp b/src/PeripheryManager.cpp index 55abe56f..f8b81b1d 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -294,12 +294,16 @@ void PeripheryManager_::tick() uint16_t ADCVALUE = analogRead(BATTERY_PIN); BATTERY_PERCENT = min((int)map(ADCVALUE, 475, 665, 0, 100), 100); BATTERY_RAW = ADCVALUE; - sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM); - CURRENT_TEMP -= 9.0; + + if (SENSOR_READING) + { + sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM); + CURRENT_TEMP -= 9.0; #else CURRENT_TEMP = bme280.readTemperature(); CURRENT_HUM = bme280.readHumidity(); #endif + } // checkAlarms(); MQTTManager.sendStats(); } diff --git a/src/UpdateManager.cpp b/src/UpdateManager.cpp index 3613fc55..029f50f8 100644 --- a/src/UpdateManager.cpp +++ b/src/UpdateManager.cpp @@ -38,7 +38,13 @@ void update_finished() void update_progress(int cur, int total) { - DisplayManager.drawProgressBar(cur, total); + DisplayManager.clear(); + int progress = (cur * 100) / total; + char progressStr[5]; + snprintf(progressStr, 5, "%d%%", progress); + DisplayManager.printText(0, 6, progressStr, true, false); + DisplayManager.drawProgressBar(0, 7, progress, 0xCE59, 0x07E0); + DisplayManager.show(); } void update_error(int err) diff --git a/src/main.cpp b/src/main.cpp index ce7120e8..00f318e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,7 +67,9 @@ void setup() ServerManager.loadSettings(); DisplayManager.setup(); DisplayManager.HSVtext(9, 6, VERSION, true, 0); + delay(500); PeripheryManager.playBootSound(); + xTaskCreatePinnedToCore(BootAnimation, "Task", 10000, NULL, 1, &taskHandle, 0); ServerManager.setup(); if (ServerManager.isConnected)