From cc749a48acab6c66ce7c097e2a65edb7a9d9dc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChl?= <31169771+Blueforcer@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:47:26 +0200 Subject: [PATCH] v0.68 - You can set hum and temp offset via dev.json. closes #154 - Change awtrix font to use less pixel for degree symbol. - Adds UTF8 encoding to text fragments and text drawing - Restrore matrix state after notification dismiss when using wakeup. closes #152 - Wakeup updates current appname to Notification. Closes #151 - Adds more keys to settings API (read) . closes #160 - Sets DefaultDataPrefix for HA discrovery ti the MQTT topic. closes #161 - Adds second dot to DD.MM. date format. closes #164 --- docs/dev.md | 6 ++++-- lib/MatrixUI/Fonts/AwtrixFont.h | 2 +- src/DisplayManager.cpp | 36 ++++++++++++++++++++++++++------- src/Functions.h | 2 +- src/Globals.cpp | 19 +++++++++++++++-- src/Globals.h | 3 +++ src/MQTTManager.cpp | 7 ++++++- src/PeripheryManager.cpp | 7 +++++-- 8 files changed, 66 insertions(+), 16 deletions(-) diff --git a/docs/dev.md b/docs/dev.md index dfc163df..68142dc3 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -16,10 +16,12 @@ The JSON object has the following properties: | `bootsound` | string | Uses a custom melodie while booting | | | `uppercase` | boolean | Print every character in uppercase | `true` | | `matrix` | int | Changes the matrix layout (0,1 or 2) | `0` | -| `temp_dec_places` | int | Number of decimal places for temperature measurements | `0` | | `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 searchfunction for new version every 1 hour. This could cause in loop stack overflow! | `false` | +| `rotate_screen` | boolean | Rotates the screen upside down | `false` | +| `temp_dec_places` | int | Number of decimal places for temperature measurements | `0` | | `sensor_reading` | boolean | Enables or disables the reading of the Temp&Hum sensor | `true` | -| `rotate_screen` | boolean | Rotates the screen upside down | `false` | \ No newline at end of file +| `temp_offset` | float | Sets the offset for the internal temperature messurement | `-9` | +| `hum_offset` | float | Sets the offset for the internal humidity messurement | `0` | \ No newline at end of file diff --git a/lib/MatrixUI/Fonts/AwtrixFont.h b/lib/MatrixUI/Fonts/AwtrixFont.h index 883de5ed..e98725b8 100644 --- a/lib/MatrixUI/Fonts/AwtrixFont.h +++ b/lib/MatrixUI/Fonts/AwtrixFont.h @@ -371,7 +371,7 @@ const GFXglyph AwtrixFontGlyphs[] PROGMEM = { {467, 8, 1, 3, 0, -3}, /*[107] 0xAD softhyphen */ {468, 8, 3, 4, 0, -5}, /*[108] 0xAE registered */ {471, 8, 1, 4, 0, -5}, /*[109] 0xAF macron */ - {472, 8, 3, 4, 0, -5}, /*[110] 0xB0 degree */ + {472, 8, 3, 3, 0, -5}, /*[110] 0xB0 degree */ {475, 8, 5, 4, 0, -5}, /*[111] 0xB1 plusminus */ {480, 8, 3, 4, 0, -5}, /*[112] 0xB2 twosuperior */ {483, 8, 3, 4, 0, -5}, /*[113] 0xB3 threesuperior */ diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 05668644..464e04c6 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -315,7 +315,7 @@ bool parseFragmentsText(const String &jsonText, std::vector &colors, s for (JsonObject fragmentObj : fragmentArray) { - String textFragment = utf8ascii(fragmentObj["t"].as()); + String textFragment = fragmentObj["t"].as(); uint16_t color; if (fragmentObj.containsKey("c")) { @@ -805,7 +805,7 @@ bool DisplayManager_::generateNotification(const char *json) PeripheryManager.playFromFile(doc["sound"].as()); } } - + MQTTManager.setCurrentApp("Notification"); doc.clear(); return true; } @@ -1111,13 +1111,25 @@ void DisplayManager_::selectButtonLong() void DisplayManager_::dismissNotify() { + + bool wakeup; + if (!notifications.empty()) { if (notifyFlag && notifications[0].hold) { + wakeup = notifications[0].wakeup; notifications.erase(notifications.begin()); } } + + if (notifications.empty()) + { + if (wakeup && MATRIX_OFF) + { + DisplayManager.setBrightness(0); + } + } } void timerCallback() @@ -1300,11 +1312,11 @@ void DisplayManager_::updateAppVector(const char *json) { return app.first == appName; }); std::pair nativeApp = getNativeAppByName(appName); + if (!show) { if (appIt != Apps.end()) { - Apps.erase(appIt); } } @@ -1636,7 +1648,7 @@ void DisplayManager_::sendAppLoop() String DisplayManager_::getSettings() { - StaticJsonDocument<256> doc; + StaticJsonDocument<512> doc; doc["FPS"] = MATRIX_FPS; doc["ABRI"] = AUTO_BRIGHTNESS; doc["BRI"] = BRIGHTNESS; @@ -1648,12 +1660,22 @@ String DisplayManager_::getSettings() doc["DFORMAT"] = DATE_FORMAT; doc["SOM"] = START_ON_MONDAY; doc["CEL"] = IS_CELSIUS; + doc["BLOCKN"] = BLOCK_NAVIGATION; doc["MAT"] = MATRIX_LAYOUT; doc["SOUND"] = SOUND_ACTIVE; doc["GAMMA"] = GAMMA; - doc["UPPERCASE"] = GAMMA; + doc["UPPERCASE"] = UPPERCASE_LETTERS; doc["CCORRECTION"] = COLOR_CORRECTION.raw; doc["CTEMP"] = COLOR_TEMPERATURE.raw; + doc["WD"] = SHOW_WEEKDAY; + doc["WDCA"] = WDC_ACTIVE; + doc["WDCI"] = WDC_INACTIVE; + doc["TIME_COL"] = TIME_COLOR; + doc["DATE_COL"] = DATE_COLOR; + doc["HUM_COL"] = HUM_COLOR; + doc["TEMP_COL"] = TEMP_COLOR; + doc["BAT_COL"] = BAT_COLOR; + String jsonString; return serializeJson(doc, jsonString), jsonString; } @@ -1679,6 +1701,7 @@ void DisplayManager_::setNewSettings(const char *json) TIME_PER_TRANSITION = doc.containsKey("TSPEED") ? doc["TSPEED"] : TIME_PER_TRANSITION; MATRIX_FPS = doc.containsKey("FPS") ? doc["FPS"] : MATRIX_FPS; BRIGHTNESS = doc.containsKey("BRI") ? doc["BRI"] : BRIGHTNESS; + IS_CELSIUS = doc.containsKey("CEL") ? doc["CEL"] : IS_CELSIUS; START_ON_MONDAY = doc.containsKey("SOM") ? doc["SOM"].as() : START_ON_MONDAY; TIME_FORMAT = doc.containsKey("TFORMAT") ? doc["TFORMAT"].as() : TIME_FORMAT; GAMMA = doc.containsKey("GAMMA") ? doc["GAMMA"].as() : GAMMA; @@ -1753,7 +1776,6 @@ void DisplayManager_::setNewSettings(const char *json) auto TCOL = doc["TCOL"]; TEXTCOLOR_565 = getColorFromJsonVariant(TCOL, matrix->Color(255, 255, 255)); } - if (doc.containsKey("TIME_COL")) { auto TIME_COL = doc["TIME_COL"]; @@ -1945,7 +1967,7 @@ void DisplayManager_::processDrawInstructions(int16_t xOffset, int16_t yOffset, uint16_t color = getColorFromJsonVariant(color7, TEXTCOLOR_565); matrix->setCursor(x + xOffset, y + yOffset + 5); matrix->setTextColor(color); - matrix->print(text); + matrix->print(utf8ascii(text)); } else if (command == "db") { diff --git a/src/Functions.h b/src/Functions.h index 884192ae..7608a15e 100644 --- a/src/Functions.h +++ b/src/Functions.h @@ -6,7 +6,7 @@ #include std::map CharMap = { - {32, 2}, {33, 2}, {34, 4}, {35, 4}, {36, 4}, {37, 4}, {38, 4}, {39, 2}, {40, 3}, {41, 3}, {42, 4}, {43, 4}, {44, 3}, {45, 4}, {46, 2}, {47, 4}, {48, 4}, {49, 4}, {50, 4}, {51, 4}, {52, 4}, {53, 4}, {54, 4}, {55, 4}, {56, 4}, {57, 4}, {58, 2}, {59, 3}, {60, 4}, {61, 4}, {62, 4}, {63, 4}, {64, 4}, {65, 4}, {66, 4}, {67, 4}, {68, 4}, {69, 4}, {70, 4}, {71, 4}, {72, 4}, {73, 2}, {74, 4}, {75, 4}, {76, 4}, {77, 6}, {78, 5}, {79, 4}, {80, 4}, {81, 5}, {82, 4}, {83, 4}, {84, 4}, {85, 4}, {86, 4}, {87, 6}, {88, 4}, {89, 4}, {90, 4}, {91, 4}, {92, 4}, {93, 4}, {94, 4}, {95, 4}, {96, 3}, {97, 4}, {98, 4}, {99, 4}, {100, 4}, {101, 4}, {102, 4}, {103, 4}, {104, 4}, {105, 2}, {106, 4}, {107, 4}, {108, 4}, {109, 4}, {110, 4}, {111, 4}, {112, 4}, {113, 4}, {114, 4}, {115, 4}, {116, 4}, {117, 4}, {118, 4}, {119, 4}, {120, 4}, {121, 4}, {122, 4}, {123, 4}, {124, 2}, {125, 4}, {126, 4}, {161, 2}, {162, 4}, {163, 4}, {164, 4}, {165, 4}, {166, 2}, {167, 4}, {168, 4}, {169, 4}, {170, 4}, {171, 3}, {172, 4}, {173, 3}, {174, 4}, {175, 4}, {176, 4}, {177, 4}, {178, 4}, {179, 4}, {180, 3}, {181, 4}, {182, 4}, {183, 4}, {184, 4}, {185, 2}, {186, 4}, {187, 3}, {188, 4}, {189, 4}, {190, 4}, {191, 4}, {192, 4}, {193, 4}, {194, 4}, {195, 4}, {196, 4}, {197, 4}, {198, 4}, {199, 4}, {200, 4}, {201, 4}, {202, 4}, {203, 4}, {204, 4}, {205, 4}, {206, 4}, {207, 4}, {208, 4}, {209, 4}, {210, 4}, {211, 4}, {212, 4}, {213, 4}, {214, 4}, {215, 4}, {216, 4}, {217, 4}, {218, 4}, {219, 4}, {220, 4}, {221, 4}, {222, 4}, {223, 4}, {224, 4}, {225, 4}, {226, 4}, {227, 4}, {228, 4}, {229, 4}, {230, 4}, {231, 4}, {232, 4}, {233, 4}, {234, 4}, {235, 4}, {236, 3}, {237, 3}, {238, 4}, {239, 4}, {240, 4}, {241, 4}, {242, 4}, {243, 4}, {244, 4}, {245, 4}, {246, 4}, {247, 4}, {248, 4}, {249, 4}, {250, 4}, {251, 4}, {252, 4}, {253, 4}, {254, 4}, {255, 4}, {285, 2}, {338, 4}, {339, 4}, {352, 4}, {353, 4}, {376, 4}, {381, 4}, {382, 4}, {3748, 2}, {5024, 2}, {8226, 2}, {8230, 4}, {8364, 4}, {65533, 4}}; + {32, 2}, {33, 2}, {34, 4}, {35, 4}, {36, 4}, {37, 4}, {38, 4}, {39, 2}, {40, 3}, {41, 3}, {42, 4}, {43, 4}, {44, 3}, {45, 4}, {46, 2}, {47, 4}, {48, 4}, {49, 4}, {50, 4}, {51, 4}, {52, 4}, {53, 4}, {54, 4}, {55, 4}, {56, 4}, {57, 4}, {58, 2}, {59, 3}, {60, 4}, {61, 4}, {62, 4}, {63, 4}, {64, 4}, {65, 4}, {66, 4}, {67, 4}, {68, 4}, {69, 4}, {70, 4}, {71, 4}, {72, 4}, {73, 2}, {74, 4}, {75, 4}, {76, 4}, {77, 6}, {78, 5}, {79, 4}, {80, 4}, {81, 5}, {82, 4}, {83, 4}, {84, 4}, {85, 4}, {86, 4}, {87, 6}, {88, 4}, {89, 4}, {90, 4}, {91, 4}, {92, 4}, {93, 4}, {94, 4}, {95, 4}, {96, 3}, {97, 4}, {98, 4}, {99, 4}, {100, 4}, {101, 4}, {102, 4}, {103, 4}, {104, 4}, {105, 2}, {106, 4}, {107, 4}, {108, 4}, {109, 4}, {110, 4}, {111, 4}, {112, 4}, {113, 4}, {114, 4}, {115, 4}, {116, 4}, {117, 4}, {118, 4}, {119, 4}, {120, 4}, {121, 4}, {122, 4}, {123, 4}, {124, 2}, {125, 4}, {126, 4}, {161, 2}, {162, 4}, {163, 4}, {164, 4}, {165, 4}, {166, 2}, {167, 4}, {168, 4}, {169, 4}, {170, 4}, {171, 3}, {172, 4}, {173, 3}, {174, 4}, {175, 4}, {176, 3}, {177, 4}, {178, 4}, {179, 4}, {180, 3}, {181, 4}, {182, 4}, {183, 4}, {184, 4}, {185, 2}, {186, 4}, {187, 3}, {188, 4}, {189, 4}, {190, 4}, {191, 4}, {192, 4}, {193, 4}, {194, 4}, {195, 4}, {196, 4}, {197, 4}, {198, 4}, {199, 4}, {200, 4}, {201, 4}, {202, 4}, {203, 4}, {204, 4}, {205, 4}, {206, 4}, {207, 4}, {208, 4}, {209, 4}, {210, 4}, {211, 4}, {212, 4}, {213, 4}, {214, 4}, {215, 4}, {216, 4}, {217, 4}, {218, 4}, {219, 4}, {220, 4}, {221, 4}, {222, 4}, {223, 4}, {224, 4}, {225, 4}, {226, 4}, {227, 4}, {228, 4}, {229, 4}, {230, 4}, {231, 4}, {232, 4}, {233, 4}, {234, 4}, {235, 4}, {236, 3}, {237, 3}, {238, 4}, {239, 4}, {240, 4}, {241, 4}, {242, 4}, {243, 4}, {244, 4}, {245, 4}, {246, 4}, {247, 4}, {248, 4}, {249, 4}, {250, 4}, {251, 4}, {252, 4}, {253, 4}, {254, 4}, {255, 4}, {285, 2}, {338, 4}, {339, 4}, {352, 4}, {353, 4}, {376, 4}, {381, 4}, {382, 4}, {3748, 2}, {5024, 2}, {8226, 2}, {8230, 4}, {8364, 4}, {65533, 4}}; //--------------------------------------------------------------- // This is the gamma lookup for mapping 255 brightness levels diff --git a/src/Globals.cpp b/src/Globals.cpp index 16857e11..ab6f6b2e 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -41,7 +41,7 @@ void loadDevSettings() if (LittleFS.exists("/dev.json")) { File file = LittleFS.open("/dev.json", "r"); - DynamicJsonDocument doc(256); + DynamicJsonDocument doc(1024); DeserializationError error = deserializeJson(doc, file); if (error) { @@ -66,6 +66,16 @@ void loadDevSettings() MATRIX_LAYOUT = doc["matrix"]; } + if (doc.containsKey("temp_offset")) + { + TEMP_OFFSET = doc["temp_offset"]; + } + + if (doc.containsKey("hum_offset")) + { + HUM_OFFSET = doc["hum_offset"]; + } + if (doc.containsKey("uppercase")) { UPPERCASE_LETTERS = doc["uppercase"].as(); @@ -216,7 +226,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.67"; +const char *VERSION = "0.68"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; @@ -256,10 +266,15 @@ float CURRENT_HUM; float CURRENT_LUX; int BRIGHTNESS = 120; int BRIGHTNESS_PERCENT; + #ifdef ULANZI +float TEMP_OFFSET = -9; uint8_t BATTERY_PERCENT; uint16_t BATTERY_RAW; +#else +float TEMP_OFFSET; #endif +float HUM_OFFSET; uint16_t LDR_RAW; String TIME_FORMAT = "%H:%M:%S"; String DATE_FORMAT = "%d.%m.%y"; diff --git a/src/Globals.h b/src/Globals.h index 840b216e..289c69d7 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -72,6 +72,8 @@ extern String CURRENT_APP; extern uint8_t BATTERY_PERCENT; extern uint16_t BATTERY_RAW; #endif +extern float TEMP_OFFSET; +extern float HUM_OFFSET; extern int BRIGHTNESS; extern int BRIGHTNESS_PERCENT; extern String TEXTCOLOR; @@ -112,6 +114,7 @@ extern bool UPDATE_CHECK; extern bool SENSOR_READING; extern bool ROTATE_SCREEN; + extern uint16_t TIME_COLOR; extern uint16_t DATE_COLOR; extern uint16_t BAT_COLOR; diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index cccec51c..4bdaac76 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -328,12 +328,17 @@ void onMqttConnected() mqtt.subscribe(fullTopic.c_str()); delay(30); } + delay(200); if (HA_DISCOVERY) + { myOwnID->setValue(MQTT_PREFIX.c_str()); + version->setValue(VERSION); + } } void connect() { + mqtt.setDataPrefix(MQTT_PREFIX.c_str()); mqtt.onMessage(onMqttMessage); mqtt.onConnected(onMqttConnected); @@ -609,7 +614,7 @@ void MQTTManager_::sendStats() uptime->setValue(PeripheryManager.readUptime()); transition->setState(AUTO_TRANSITION, false); - version->setValue(VERSION); + // update->setState(UPDATE_AVAILABLE, false); } else diff --git a/src/PeripheryManager.cpp b/src/PeripheryManager.cpp index ebc4b1e6..1685b19d 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -153,7 +153,8 @@ void select_button_pressed_long() else if (!BLOCK_NAVIGATION) { DisplayManager.selectButtonLong(); - MenuManager.selectButtonLong(); + if (!ALARM_ACTIVE) + MenuManager.selectButtonLong(); DEBUG_PRINTLN(F("Select button pressed long")); } } @@ -343,12 +344,14 @@ void PeripheryManager_::tick() { #ifdef ULANZI sht31.readBoth(&CURRENT_TEMP, &CURRENT_HUM); - CURRENT_TEMP -= 9.0; #else CURRENT_TEMP = bme280.readTemperature(); CURRENT_HUM = bme280.readHumidity(); #endif + CURRENT_TEMP += TEMP_OFFSET; + CURRENT_HUM += HUM_OFFSET; } + checkAlarms(); MQTTManager.sendStats(); }