diff --git a/docs/api.md b/docs/api.md index a0a29044..ca12a8ec 100644 --- a/docs/api.md +++ b/docs/api.md @@ -12,6 +12,15 @@ With HTTP, make GET request to `http://[IP]/api/stats` | `[PREFIX]/power` | `http://[IP]/api/power` | true/false or 1/0 | POST | +## Play a sound + +Plays a RTTTL sound from the MELODIES folder. + +| Topic | URL | Payload/Body | HTTP method | +| --- | --- | --- | --- | +| `[PREFIX]/sound` | `http://[IP]/api/sound` | name of the RTTTL file without extension | POST | + + ## Colored indicators A colored indicator is like a small notification sign wich will be shown on the upper right or lower right corner. @@ -66,9 +75,8 @@ All keys are optional, so you can send just the properties you want to use. | `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 | +| `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. This function is experimental | N/A | - Color values can have a hex string or an array of R,G,B values: `"#FFFFFF" or [255,255,0]` @@ -140,78 +148,6 @@ Built-in app names are: For custom apps, use the name you set in the topic or http request header. In MQTT for example, if `[PREFIX]/custom/test` is your topic, then `test` is the name. -## Add/remove and rearange apps - - -| Topic | URL | Payload/Body | HTTP method | -| --- | --- | --- | --- | -| `[PREFIX]/apps`|`http://[IP]/api/apps`| json | POST | - -!> This function provides users with the ability to manage the apps on their device by adding, removing, and rearranging them. However, as it is an experimental feature, caution should be exercised, particularly when attempting to rearrange multiple apps at once, as this can lead to unintended consequences due to the resulting shifts in position of other apps. - -By using this function, users can add or remove native apps, as well as custom apps, from the device. -However, it is important to note that custom apps are only temporarily loaded into memory and cannot be added again using this function. -To add a custom app again, you must send it to awtrix via mqtt again. - -Additionally, you can rearrange the position of all apps on the device by specifying a new position in the JSON array. -This provides flexibility in organizing apps according to personal preference. - -The JSON payload is an array of objects, where each object represents an app to be displayed on awtrix. Each app object contains the following fields: - -### JSON Properties - -| Property | Description |Default | -|----------|-------------|-------------| -| name | The name of the app. If it's a native app, it can be one of "time", "date", "temp", "hum", or "bat". For custom apps, use the name you set in the topic. For example, if `[PREFIX]/custom/test` is your topic, then `test` is the name. | | -| show | A boolean indicating whether the app should be shown on the screen or not. If not present, the app is considered active by default. | true | -| pos | An integer indicating the position of the app in the list. If not present, the app will be added to the end of the list. | Last Item | - - -> You can also just send the information for one app. - -```json -[ - { - "name":"time", - "show":true, - "pos":3 - }, - { - "name":"date", - "pos":0 - }, - { - "name":"temp", - "pos":2 - }, - { - "name":"hum", - "show":true, - "pos":0 - }, - { - "name":"bat", - "show":false - }, - { - "name":"github", - "show":true, - "pos":4 - } -] -``` - - - -In this example, -- The "time" app is active and should be displayed in position 3. -- The "date" app should be displayed in position 0. -- The "temp" app should be displayed in position 2. -- The "hum" app should be displayed at first position. -- The "bat" app is inactive and will be removed, -- and the "github" app is active and should be displayed in position 4. - - ## Change Settings Change various settings related to the app display. @@ -231,7 +167,7 @@ Each property is optional; you do not need to send all. | `TCOL` | string / array of ints| Sets the textcolor | an array of RGB values `[255,0,0]` or any valid 6-digit hexadecimal color value, e.g. "#FF0000" for red. | N/A | | `WD` | bool | Enable or disable the weekday display | true/false | true | | `WDCA` | string / array of ints| Sets the active weekday color | an array of RGB values `[255,0,0]` or any valid 6-digit hexadecimal color value, e.g. "#FF0000" for red. | N/A | -| `WDCI` | string / array of ints| Sets the inactive weekday color | an array of RGB values `[255,0,0]` or any valid 6-digit hexadecimal color value, e.g. "#FFFF" for red. | N/A | +| `WDCI` | string / array of ints| Sets the inactive weekday color | an array of RGB values `[255,0,0]` or any valid 6-digit hexadecimal color value, e.g. "#FFFF" for white. | N/A | | `FPS` | number | Determines the frame rate at which the matrix is updated. | Any positive integer value. | 23 | | `BRI` | number | Determines the brightness of the matrix. | An integer between 0 and 255. | N/A | | `ABRI` | boolean | Determines if automatic brightness control is active. | `true` or `false`. | N/A | @@ -244,7 +180,11 @@ Each property is optional; you do not need to send all. | `SOM` | bool | Sets the start of the week to monday | true/false | true | | `BLOCKN` | bool | Blocks temporarily the physical navigation keys, but still sends the input to MQTT | true/false | false | | `UPPERCASE` | bool | Shows text in uppercase | true/false | true | - +| `TIME_COL` | string / array of ints| Sets the textcolor of the time app. Set 0 for global textcolor | an array of RGB values hexadecimal color value | N/A | +| `DATE_COL` | string / array of ints| Sets the textcolor of the date app . Set 0 for global textcolor | an array of RGB values hexadecimal color value | N/A | +| `TEMP_COL` | string / array of ints| Sets the textcolor of the temp app. Set 0 for global textcolor | an array of RGB values hexadecimal color value | N/A | +| `HUM_COL` | string / array of ints| Sets the textcolor of the humidity app. Set 0 for global textcolor | an array of RGB values hexadecimal color value | N/A | +| `BAT_COL` | string / array of ints| Sets the textcolor of the battery app. Set 0 for global textcolor | an array of RGB values hexadecimal color value | N/A | **Timeformats:** ```bash diff --git a/docs/dev.md b/docs/dev.md index 6f14f891..dfc163df 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -22,3 +22,4 @@ The JSON object has the following properties: | `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` | | `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 diff --git a/src/Apps.h b/src/Apps.h index 55dfb784..455633ae 100644 --- a/src/Apps.h +++ b/src/Apps.h @@ -131,7 +131,16 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, if (notify.flag) return; CURRENT_APP = "Time"; - DisplayManager.getInstance().resetTextColor(); + + if (TIME_COLOR > 0) + { + matrix->setTextColor(TIME_COLOR); + } + else + { + DisplayManager.getInstance().resetTextColor(); + } + time_t now = time(nullptr); struct tm *timeInfo; timeInfo = localtime(&now); @@ -179,7 +188,14 @@ void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, if (notify.flag) return; CURRENT_APP = "Date"; - DisplayManager.getInstance().resetTextColor(); + if (DATE_COLOR > 0) + { + matrix->setTextColor(DATE_COLOR); + } + else + { + DisplayManager.getInstance().resetTextColor(); + } time_t now = time(nullptr); struct tm *timeInfo; timeInfo = localtime(&now); @@ -207,7 +223,14 @@ void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, if (notify.flag) return; CURRENT_APP = "Temperature"; - DisplayManager.getInstance().resetTextColor(); + if (TEMP_COLOR > 0) + { + matrix->setTextColor(TEMP_COLOR); + } + else + { + DisplayManager.getInstance().resetTextColor(); + } matrix->drawRGBBitmap(x, y, icon_234, 8, 8); if (TEMP_DECIMAL_PLACES > 0) @@ -233,11 +256,18 @@ void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i if (notify.flag) return; CURRENT_APP = "Humidity"; - DisplayManager.getInstance().resetTextColor(); + if (HUM_COLOR > 0) + { + matrix->setTextColor(HUM_COLOR); + } + else + { + DisplayManager.getInstance().resetTextColor(); + } matrix->drawRGBBitmap(x, y + 1, icon_2075, 8, 8); matrix->setCursor(14 + x, 6 + y); - int humidity = CURRENT_HUM; // Humidity without decimal places - matrix->print(humidity); // Output humidity + int humidity = CURRENT_HUM; + matrix->print(humidity); matrix->print("%"); } @@ -247,7 +277,14 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i if (notify.flag) return; CURRENT_APP = "Battery"; - DisplayManager.getInstance().resetTextColor(); + if (BAT_COLOR > 0) + { + matrix->setTextColor(BAT_COLOR); + } + else + { + DisplayManager.getInstance().resetTextColor(); + } matrix->drawRGBBitmap(x, y, icon_1486, 8, 8); matrix->setCursor(14 + x, 6 + y); matrix->print(BATTERY_PERCENT); // Ausgabe des Ladezustands @@ -899,4 +936,5 @@ void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i } OverlayCallback overlays[] = {MenuApp, NotifyApp, AlarmApp, TimerApp}; +void (*customAppCallbacks[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool, GifPlayer *) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20}; #endif \ No newline at end of file diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 6fa3905b..a2a51997 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -203,11 +203,29 @@ void pushCustomApp(String name, int position) { if (customApps.count(name) == 0) { - void (*customAppArray[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool, GifPlayer *) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20}; + int availableCallbackIndex = -1; - int customAppIndex = customApps.size(); + for (int i = 0; i < 20; ++i) + { + bool callbackUsed = false; + + for (const auto &appPair : Apps) + { + if (appPair.second == customAppCallbacks[i]) + { + callbackUsed = true; + break; + } + } + + if (!callbackUsed) + { + availableCallbackIndex = i; + break; + } + } - if (customAppIndex >= 20) + if (availableCallbackIndex == -1) { DEBUG_PRINTLN("Error adding custom app -> Maximum number of custom apps reached"); return; @@ -215,15 +233,15 @@ void pushCustomApp(String name, int position) if (position < 0) // Insert at the end of the vector { - Apps.push_back(std::make_pair(name, customAppArray[customAppIndex])); + Apps.push_back(std::make_pair(name, customAppCallbacks[availableCallbackIndex])); } else if (position < Apps.size()) // Insert at a specific position { - Apps.insert(Apps.begin() + position, std::make_pair(name, customAppArray[customAppIndex])); + Apps.insert(Apps.begin() + position, std::make_pair(name, customAppCallbacks[availableCallbackIndex])); } else // Invalid position, Insert at the end of the vector { - Apps.push_back(std::make_pair(name, customAppArray[customAppIndex])); + Apps.push_back(std::make_pair(name, customAppCallbacks[availableCallbackIndex])); } ui->setApps(Apps); // Add Apps @@ -231,41 +249,16 @@ void pushCustomApp(String name, int position) } } - void removeCustomAppFromApps(const String &name, bool setApps) { - if (name.length() == 0) - { - DEBUG_PRINTLN("Error removing app -> Empty name"); - return; - } - auto it = std::find_if(Apps.begin(), Apps.end(), [&name](const std::pair &appPair) { return appPair.first == name; }); - if (it == Apps.end()) - { - DEBUG_PRINTLN("Error removing " + name + " -> App not found"); - return; - } - - if (!it->second) - { - DEBUG_PRINTLN("Error removing " + name + " -> Invalid AppCallback"); - return; - } Apps.erase(it); - - auto customIt = customApps.find(name); - if (customIt != customApps.end()) - { - customApps.erase(customIt); - } - + customApps.erase(customApps.find(name)); if (setApps) - { ui->setApps(Apps); - } + DisplayManager.getInstance().setAutoTransition(true); } bool parseFragmentsText(const String &jsonText, std::vector &colors, std::vector &fragments, uint16_t standardColor) @@ -273,11 +266,11 @@ bool parseFragmentsText(const String &jsonText, std::vector &colors, s colors.clear(); fragments.clear(); - DynamicJsonDocument doc(3096); + StaticJsonDocument<2048> doc; DeserializationError error = deserializeJson(doc, jsonText); + if (error) { - doc.clear(); return false; } @@ -312,7 +305,7 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json) return; } - DynamicJsonDocument doc(3096); + StaticJsonDocument<2048> doc; DeserializationError error = deserializeJson(doc, json); if (error) { @@ -525,13 +518,8 @@ void DisplayManager_::generateCustomPage(const String &name, const char *json) void DisplayManager_::generateNotification(const char *json) { - DynamicJsonDocument doc(3096); - DeserializationError error = deserializeJson(doc, json); - if (error) - { - doc.clear(); - return; - } + StaticJsonDocument<2048> doc; + deserializeJson(doc, json); notify.progress = doc.containsKey("progress") ? doc["progress"].as() : -1; @@ -738,27 +726,19 @@ void DisplayManager_::loadNativeApps() } }; - // Update the "time" app at position 0 updateApp("time", TimeApp, SHOW_TIME, 0); - - // Update the "date" app at position 1 updateApp("date", DateApp, SHOW_DATE, 1); 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); #endif ui->setApps(Apps); - setAutoTransition(true); } @@ -769,6 +749,7 @@ void DisplayManager_::setup() FastLED.addLeds(leds, MATRIX_WIDTH * MATRIX_HEIGHT); setMatrixLayout(MATRIX_LAYOUT); + matrix->setRotation(ROTATE_SCREEN ? 90 : 0); if (COLOR_CORRECTION) { FastLED.setCorrection(COLOR_CORRECTION); @@ -787,41 +768,32 @@ void DisplayManager_::setup() ui->init(); } -void checkLifetime() +void checkLifetime(uint8_t pos) { if (customApps.empty()) { return; } - std::vector appsToRemove; - - for (auto it = customApps.begin(); it != customApps.end(); ++it) + if (pos >= Apps.size()) { - auto appIt = customApps.find(it->first); - if (appIt == customApps.end()) - { - continue; - } + pos = 0; + } + String appName = Apps[pos].first; + auto appIt = customApps.find(appName); + + if (appIt != customApps.end()) + { CustomApp &app = appIt->second; if (app.lifetime > 0 && (millis() - app.lastUpdate) / 1000 >= app.lifetime) { - String appName = it->first; - appsToRemove.push_back(appName); - } - } + DEBUG_PRINTLN("Removing " + appName + " -> Lifetime over"); + removeCustomAppFromApps(appName, false); - for (const String &appName : appsToRemove) - { - DEBUG_PRINTLN("Removing " + appName + " -> Lifetime over"); - removeCustomAppFromApps(appName, false); - } - - if (!appsToRemove.empty()) - { - DEBUG_PRINTLN("Set new Apploop"); - ui->setApps(Apps); + DEBUG_PRINTLN("Set new Apploop"); + ui->setApps(Apps); + } } } @@ -837,15 +809,13 @@ void DisplayManager_::tick() if (ui->getUiState()->appState == IN_TRANSITION && !appIsSwitching) { appIsSwitching = true; - checkLifetime(); } else if (ui->getUiState()->appState == FIXED && appIsSwitching) { appIsSwitching = false; MQTTManager.setCurrentApp(CURRENT_APP); setAppTime(TIME_PER_APP); - - + checkLifetime(ui->getnextAppNumber()); } } } @@ -968,11 +938,10 @@ void DisplayManager_::switchToApp(const char *json) if (error) return; String name = doc["name"].as(); + bool fast = doc["fast"] | false; int index = findAppIndexByName(name); - if (index > -1){ - DEBUG_PRINTLN("Switching to App " + name); - ui->transitionToApp(index); - } + if (index > -1) + ui->transitionToApp(index); } void DisplayManager_::drawProgressBar(int16_t x, int16_t y, int progress, uint16_t pColor, uint16_t pbColor) @@ -980,6 +949,7 @@ void DisplayManager_::drawProgressBar(int16_t x, int16_t y, int progress, uint16 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); } @@ -1073,7 +1043,7 @@ void DisplayManager_::updateAppVector(const char *json) { DEBUG_PRINTLN(F("New apps vector received")); DEBUG_PRINTLN(json); - StaticJsonDocument<512> doc; // Erhöhen Sie die Größe des Dokuments bei Bedarf + StaticJsonDocument<2048> doc; DeserializationError error = deserializeJson(doc, json); if (error) { @@ -1487,6 +1457,36 @@ 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"]; + TIME_COLOR = getColorFromJsonVariant(TIME_COL, TEXTCOLOR_565); + } + + if (doc.containsKey("DATE_COL")) + { + auto DATE_COL = doc["DATE_COL"]; + DATE_COLOR = getColorFromJsonVariant(DATE_COL, TEXTCOLOR_565); + } + + if (doc.containsKey("TEMP_COL")) + { + auto TEMP_COL = doc["TEMP_COL"]; + TEMP_COLOR = getColorFromJsonVariant(TEMP_COL, TEXTCOLOR_565); + } + + if (doc.containsKey("HUM_COL")) + { + auto HUM_COL = doc["HUM_COL"]; + HUM_COLOR = getColorFromJsonVariant(HUM_COL, TEXTCOLOR_565); + } + + if (doc.containsKey("BAT_COL")) + { + auto BAT_COL = doc["BAT_COL"]; + BAT_COLOR = getColorFromJsonVariant(BAT_COL, TEXTCOLOR_565); + } applyAllSettings(); saveSettings(); } @@ -1534,7 +1534,7 @@ String DisplayManager_::getAppsWithIcon() void DisplayManager_::reorderApps(const String &jsonString) { - StaticJsonDocument<1024> jsonDocument; + StaticJsonDocument<2048> jsonDocument; DeserializationError error = deserializeJson(jsonDocument, jsonString); if (error) { @@ -1557,4 +1557,4 @@ void DisplayManager_::reorderApps(const String &jsonString) Apps = reorderedApps; ui->setApps(Apps); ui->forceResetState(); -} +} \ No newline at end of file diff --git a/src/Globals.cpp b/src/Globals.cpp index e8dcf490..bc8ae0bb 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -3,6 +3,7 @@ #include #include #include + Preferences Settings; char *getID() @@ -80,6 +81,11 @@ void loadDevSettings() TEMP_DECIMAL_PLACES = doc["temp_dec_places"].as(); } + if (doc.containsKey("rotate_screen")) + { + ROTATE_SCREEN = doc["rotate_screen"].as(); + } + if (doc.containsKey("gamma")) { GAMMA = doc["gamma"].as(); @@ -108,6 +114,7 @@ void loadDevSettings() COLOR_TEMPERATURE.setRGB(r, g, b); } } + file.close(); } else @@ -125,6 +132,13 @@ void loadSettings() BRIGHTNESS = Settings.getUInt("BRI", 120); AUTO_BRIGHTNESS = Settings.getBool("ABRI", false); TEXTCOLOR_565 = Settings.getUInt("TCOL", 0xFFFF); + + TIME_COLOR = Settings.getUInt("TIME_COL", 0); + DATE_COLOR = Settings.getUInt("DATE_COL", 0); + TEMP_COLOR = Settings.getUInt("TEMP_COL", 0); + HUM_COLOR = Settings.getUInt("HUM_COL", 0); + BAT_COLOR = Settings.getUInt("BAT_COL", 0); + WDC_ACTIVE = Settings.getUInt("WDCA", 0xFFFF); WDC_INACTIVE = Settings.getUInt("WDCI", 0x6B6D); AUTO_TRANSITION = Settings.getBool("ATRANS", true); @@ -164,6 +178,13 @@ void saveSettings() Settings.putBool("ABRI", AUTO_BRIGHTNESS); Settings.putBool("ATRANS", AUTO_TRANSITION); Settings.putUInt("TCOL", TEXTCOLOR_565); + + Settings.putUInt("TIME_COL", TIME_COLOR); + Settings.putUInt("DATE_COL", DATE_COLOR); + Settings.putUInt("TEMP_COL", TEMP_COLOR); + Settings.putUInt("HUM_COL", HUM_COLOR); + Settings.putUInt("BAT_COL", BAT_COLOR); + Settings.putUInt("WDCA", WDC_ACTIVE); Settings.putUInt("WDCI", WDC_INACTIVE); Settings.putUInt("TSPEED", TIME_PER_TRANSITION); @@ -193,7 +214,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.57"; +const char *VERSION = "0.58"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; String MQTT_USER; @@ -271,4 +292,11 @@ uint16_t WDC_INACTIVE; bool BLOCK_NAVIGATION = false; bool UPDATE_CHECK = false; float GAMMA = 0; -bool SENSOR_READING = true; \ No newline at end of file +bool SENSOR_READING = true; +bool ROTATE_SCREEN = false; + +uint16_t TIME_COLOR = 0; +uint16_t DATE_COLOR = 0; +uint16_t BAT_COLOR = 0; +uint16_t TEMP_COLOR = 0; +uint16_t HUM_COLOR = 0; \ No newline at end of file diff --git a/src/Globals.h b/src/Globals.h index 73dc7c27..04391d00 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -110,4 +110,12 @@ void saveSettings(); extern bool BLOCK_NAVIGATION; 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; +extern uint16_t TEMP_COLOR; +extern uint16_t HUM_COLOR; + #endif // Globals_H \ No newline at end of file diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 5d2276f0..45d36afe 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -233,7 +233,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) } if (strTopic.equals(MQTT_PREFIX + "/sound")) { - PeripheryManager.playFromFile(String(payloadCopy)); + PeripheryManager.playFromFile("/MELODIES/" + String(payloadCopy) + ".txt"); delete[] payloadCopy; return; } @@ -244,11 +244,10 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) if (topic_str.startsWith(prefix)) { topic_str = topic_str.substring(prefix.length()); + DisplayManager.generateCustomPage(topic_str, payloadCopy); } - DisplayManager.generateCustomPage(topic_str, payloadCopy); delete[] payloadCopy; - DEBUG_PRINTLN("Customapp request proceed"); return; } DEBUG_PRINTLN(F("Unknown MQTT command!")); @@ -284,8 +283,8 @@ void onMqttConnected() String fullTopic = prefix + topic; mqtt.subscribe(fullTopic.c_str()); } - if (HA_DISCOVERY) - version->setValue(VERSION); + + } void connect() @@ -553,7 +552,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 862ac65c..cc38b453 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -49,7 +49,7 @@ EasyButton button_left(BUTTON_UP_PIN); EasyButton button_right(BUTTON_DOWN_PIN); EasyButton button_select(BUTTON_SELECT_PIN); #ifdef ULANZI -MelodyPlayer player(BUZZER_PIN, 1,LOW); +MelodyPlayer player(BUZZER_PIN, 1, LOW); #else class Mp3Notify { @@ -263,8 +263,19 @@ void PeripheryManager_::setup() button_left.begin(); button_right.begin(); button_select.begin(); - button_left.onPressed(left_button_pressed); - button_right.onPressed(right_button_pressed); + + if (ROTATE_SCREEN) + { + Serial.println("Button rotation"); + button_left.onPressed(right_button_pressed); + button_right.onPressed(left_button_pressed); + } + else + { + button_left.onPressed(left_button_pressed); + button_right.onPressed(right_button_pressed); + } + button_select.onPressed(select_button_pressed); button_select.onPressedFor(1000, select_button_pressed_long); button_select.onSequence(2, 300, select_button_double); diff --git a/src/ServerManager.cpp b/src/ServerManager.cpp index 70ab39b7..8f77ba74 100644 --- a/src/ServerManager.cpp +++ b/src/ServerManager.cpp @@ -10,6 +10,7 @@ #include #include "DisplayManager.h" #include "UpdateManager.h" +#include "PeripheryManager.h" WebServer server(80); FSWebServer mws(LittleFS, server); @@ -73,6 +74,8 @@ void ServerManager_::setup() mws.addCSS(custom_css); mws.addJavascript(custom_script); mws.addHandler("/save", HTTP_POST, saveHandler); + mws.addHandler("/api/sound", HTTP_POST, []() + { PeripheryManager.playFromFile("/MELODIES/" + mws.webserver->arg("plain") + ".txt"); mws.webserver->send(200,"OK"); }); mws.addHandler("/api/notify", HTTP_POST, []() { DisplayManager.generateNotification(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); }); mws.addHandler("/api/nextapp", HTTP_POST, []()