From e03ed26484f59884b23669a9c9536a768f10d213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChl?= <31169771+Blueforcer@users.noreply.github.com> Date: Sun, 20 Aug 2023 23:58:11 +0200 Subject: [PATCH] V0.79 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 📈 New Features - Allows to fade the indicators on and off in an given interval, blinking still works. closes #266 - Adds new Notify and CustomApp key "center" wich allows to turn centering of short, non-scrollable text on or off. ### 🐞 Bug Fixes and Optimizations - Announced in v0.71 Timer and Alarm finally removed from code. - Fixes a bug where special characters doesnt show right in notifications. close #267 - Settings API now return correct CTEMP and CCORRECTION colors as HEX. --- docs/api.md | 4 +- src/Apps.h | 93 +++++++++++-------------------- src/DisplayManager.cpp | 115 ++++++++++++++++++--------------------- src/DisplayManager.h | 19 ++++--- src/Globals.cpp | 9 +-- src/Globals.h | 6 +- src/MQTTManager.cpp | 8 --- src/MatrixDisplayUi.cpp | 113 +++++++++++++++++++++++++------------- src/MatrixDisplayUi.h | 10 +++- src/PeripheryManager.cpp | 67 +---------------------- src/PeripheryManager.h | 1 - src/ServerManager.cpp | 2 - 12 files changed, 186 insertions(+), 261 deletions(-) diff --git a/docs/api.md b/docs/api.md index ab971864..043f8a0a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -72,7 +72,8 @@ A colored indicator is like a small notification sign wich will be shown on the Instead of a RGB array you can also sent HEX color strings like `{"color":"#32a852"}` Send the color black `{"color":[0,0,0]}` or `{"color":"0"}` or a empty payload/body to hide the indicators. -Optionally you can make the indicator blinking by adding the key `"blink"` with a value of the blinking interval in milliseconds. +Optionally you can make the indicator blinking by adding the key `"blink"` with a value of the blinking interval in milliseconds **or** +you can make the indicator fading on and off by adding the key `"fade"` with a value of the fade interval in milliseconds. ## Custom Apps and Notifications With AWTRIX Light, you can create custom apps or notifications to display your own text and icons. @@ -101,6 +102,7 @@ The JSON object has the following properties, | `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 | X | X | | `topText` | boolean | Draw the text on top | false | X | X | | `textOffset` | integer | Sets an offset for the x position of a starting text. | 0 | X | X | +| `center` | boolean | Centers a short, non-scrollable text. | true | X | X | | `color` | string or array of integers | The text, bar or line color | N/A | X | X | | `background` | string or array of integers | Sets a background color | N/A | X | X | | `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false | X | X | diff --git a/src/Apps.h b/src/Apps.h index c0e9cc6e..f5660f4e 100644 --- a/src/Apps.h +++ b/src/Apps.h @@ -37,6 +37,7 @@ struct CustomApp File icon; bool isGif; bool rainbow; + bool center; int effect = -1; long duration = 0; byte textCase = 0; @@ -55,6 +56,7 @@ struct CustomApp std::vector colors; std::vector fragments; int textOffset; + int iconOffset; int progress = -1; uint16_t pColor; uint16_t background = 0; @@ -69,6 +71,7 @@ std::map customApps; struct Notification { + bool center; String drawInstructions; float scrollposition = 34; int16_t scrollDelay = 0; @@ -78,6 +81,7 @@ struct Notification File icon; bool rainbow; bool isGif; + int iconOffset; unsigned long startime = 0; long duration = 0; int16_t repeat = -1; @@ -383,57 +387,6 @@ void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer * DisplayManager.printText(0, 6, utf8ascii(MenuManager.menutext()).c_str(), true, 2); } -void AlarmApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer) -{ - if (ALARM_ACTIVE) - { - matrix->fillScreen(matrix->Color(255, 0, 0)); - CURRENT_APP = "Alarm"; - uint16_t textWidth = getTextWidth("ALARM", 0); - int16_t textX = ((32 - textWidth) / 2); - matrix->setTextColor(0); - matrix->setCursor(textX, 6); - matrix->print("ALARM"); - if (ALARM_SOUND != "") - { - if (!PeripheryManager.isPlaying()) - { -#ifdef ULANZI - PeripheryManager.playFromFile(ALARM_SOUND); -#else - PeripheryManager.playFromFile(DFMINI_MP3_ALARM); -#endif - } - } - } -} - -void TimerApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer) -{ - if (TIMER_ACTIVE) - { - matrix->fillScreen(matrix->Color(0, 255, 0)); - CURRENT_APP = "Timer"; - String menuText = "TIMER"; - uint16_t textWidth = getTextWidth(menuText.c_str(), 0); - int16_t textX = ((32 - textWidth) / 2); - matrix->setTextColor(0); - matrix->setCursor(textX, 6); - matrix->print(menuText); - if (TIMER_SOUND != "") - { - if (!PeripheryManager.isPlaying()) - { -#ifdef ULANZI - PeripheryManager.playFromFile(TIMER_SOUND); -#else - PeripheryManager.playFromFile(DFMINI_MP3_TIMER); -#endif - } - } - } -} - void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, GifPlayer *gifPlayer) { // Abort if notifyFlag is set @@ -512,11 +465,11 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState } if (ca->isGif) { - gifPlayer->playGif(x + ca->iconPosition, y, &ca->icon); + gifPlayer->playGif(x + ca->iconPosition + ca->iconOffset, y, &ca->icon); } else { - DisplayManager.drawJPG(x + ca->iconPosition, y, ca->icon); + DisplayManager.drawJPG(x + ca->iconPosition + ca->iconOffset, y, ca->icon); } if (!noScrolling) { @@ -612,7 +565,16 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState } } - int16_t textX = hasIcon ? ((24 - textWidth) / 2) + 9 : ((32 - textWidth) / 2); + int16_t textX; + if (ca->center) + { + textX = hasIcon ? ((24 - textWidth) / 2) + 9 : ((32 - textWidth) / 2); + } + else + { + textX = hasIcon ? 9 : 0; + } + if (noScrolling) { ca->repeat = -1; // Disable repeat if text is too short for scrolling @@ -631,13 +593,13 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState { if (ca->rainbow) { - DisplayManager.HSVtext(x + textX+ca->textOffset, 6 + y, ca->text.c_str(), false, ca->textCase); + DisplayManager.HSVtext(x + textX + ca->textOffset, 6 + y, ca->text.c_str(), false, ca->textCase); } else { // Display text matrix->setTextColor(ca->color); - DisplayManager.printText(x + textX+ca->textOffset, y + 6, ca->text.c_str(), false, ca->textCase); + DisplayManager.printText(x + textX + ca->textOffset, y + 6, ca->text.c_str(), false, ca->textCase); } } } @@ -785,18 +747,18 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer { // Display GIF if present - gifPlayer->playGif(notifications[0].iconPosition, 0, ¬ifications[0].icon); + gifPlayer->playGif(notifications[0].iconPosition + notifications[0].iconOffset, 0, ¬ifications[0].icon); } else { // Display JPG image if present - DisplayManager.drawJPG(notifications[0].iconPosition, 0, notifications[0].icon); + DisplayManager.drawJPG(notifications[0].iconPosition + notifications[0].iconOffset, 0, notifications[0].icon); } // Display icon divider line if text is scrolling if (!noScrolling) { - matrix->drawLine(8 + notifications[0].iconPosition, 0, 8 + notifications[0].iconPosition, 7, 0); + matrix->drawLine(8 + notifications[0].iconPosition + notifications[0].iconOffset, 0, 8 + notifications[0].iconPosition, 7, 0); } }; @@ -872,8 +834,15 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer } } - // Calculate text X position based on icon presence - int16_t textX = hasIcon ? ((24 - textWidth) / 2) + 9 : ((32 - textWidth) / 2); + int16_t textX; + if (notifications[0].center) + { + textX = hasIcon ? ((24 - textWidth) / 2) + 9 : ((32 - textWidth) / 2); + } + else + { + textX = hasIcon ? 9 : 0; + } // Set text color matrix->setTextColor(notifications[0].color); @@ -1107,6 +1076,6 @@ void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i ShowCustomApp(name, matrix, state, x, y, gifPlayer); } -OverlayCallback overlays[] = {MenuApp, NotifyApp, AlarmApp, TimerApp}; +OverlayCallback overlays[] = {MenuApp, NotifyApp}; void (*customAppCallbacks[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, 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 8d7b5f01..d78b7561 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -16,8 +16,6 @@ #include "GifPlayer.h" #include -Ticker AlarmTicker; -Ticker TimerTicker; unsigned long lastArtnetStatusTime = 0; const int numberOfChannels = 256 * 3; @@ -73,7 +71,7 @@ void DisplayManager_::setBrightness(int bri) wakeup = notifications[0].wakeup; } - if (MATRIX_OFF && !ALARM_ACTIVE && !wakeup) + if (MATRIX_OFF && !wakeup) { matrix->setBrightness(0); } @@ -84,6 +82,7 @@ void DisplayManager_::setBrightness(int bri) } } + void DisplayManager_::setTextColor(uint16_t color) { matrix->setTextColor(color); @@ -517,9 +516,11 @@ bool DisplayManager_::generateCustomPage(const String &name, const char *json, b customApp.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0; customApp.textCase = doc.containsKey("textCase") ? doc["textCase"] : 0; customApp.lifetime = doc.containsKey("lifetime") ? doc["lifetime"] : 0; + customApp.iconOffset = doc.containsKey("iconOffset") ? doc["iconOffset"] : 0; customApp.textOffset = doc.containsKey("textOffset") ? doc["textOffset"] : 0; customApp.scrollSpeed = doc.containsKey("scrollSpeed") ? doc["scrollSpeed"].as() : -1; customApp.topText = doc.containsKey("topText") ? doc["topText"].as() : false; + customApp.center = doc.containsKey("center") ? doc["center"].as() : true; customApp.noScrolling = doc.containsKey("noScroll") ? doc["noScroll"] : false; customApp.name = name; @@ -663,6 +664,7 @@ bool DisplayManager_::generateNotification(uint8_t source, const char *json) } newNotification.loopSound = doc.containsKey("loopSound") ? doc["loopSound"].as() : false; + newNotification.center = doc.containsKey("center") ? doc["center"].as() : true; newNotification.sound = doc.containsKey("sound") ? doc["sound"].as() : ""; newNotification.rtttl = doc.containsKey("rtttl") ? doc["rtttl"].as() : ""; newNotification.duration = doc.containsKey("duration") ? doc["duration"].as() * 1000 : TIME_PER_APP; @@ -671,6 +673,7 @@ bool DisplayManager_::generateNotification(uint8_t source, const char *json) newNotification.scrollSpeed = doc.containsKey("scrollSpeed") ? doc["scrollSpeed"].as() : -1; newNotification.wakeup = doc.containsKey("wakeup") ? doc["wakeup"].as() : false; newNotification.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0; + newNotification.iconOffset = doc.containsKey("iconOffset") ? doc["iconOffset"] : 0; newNotification.textCase = doc.containsKey("textCase") ? doc["textCase"] : 0; newNotification.textOffset = doc.containsKey("textOffset") ? doc["textOffset"] : 0; newNotification.topText = doc.containsKey("topText") ? doc["topText"].as() : false; @@ -754,7 +757,7 @@ bool DisplayManager_::generateNotification(uint8_t source, const char *json) } else if (doc["text"].is()) { - newNotification.text = doc["text"].as(); + newNotification.text = utf8ascii(doc["text"].as()); } else { @@ -945,7 +948,7 @@ void DisplayManager_::setup() ui->setTargetFPS(MATRIX_FPS); ui->setTimePerApp(TIME_PER_APP); ui->setTimePerTransition(TIME_PER_TRANSITION); - ui->setOverlays(overlays, 4); + ui->setOverlays(overlays, 2); ui->setBackgroundEffect(BACKGROUND_EFFECT); setAutoTransition(AUTO_TRANSITION); ui->init(); @@ -1142,39 +1145,16 @@ void DisplayManager_::previousApp() } } -void snozzeTimerCallback() -{ - ALARM_ACTIVE = true; - AlarmTicker.detach(); -} - void DisplayManager_::selectButton() { if (!MenuManager.inMenu) { DisplayManager.getInstance().dismissNotify(); - - if (ALARM_ACTIVE && SNOOZE_TIME > 0) - { - PeripheryManager.stopSound(); - ALARM_ACTIVE = false; - AlarmTicker.once(SNOOZE_TIME * 60, snozzeTimerCallback); - } - if (TIMER_ACTIVE) - { - PeripheryManager.stopSound(); - TIMER_ACTIVE = false; - } } } void DisplayManager_::selectButtonLong() { - if (ALARM_ACTIVE) - { - PeripheryManager.stopSound(); - ALARM_ACTIVE = false; - } } void DisplayManager_::dismissNotify() @@ -1194,37 +1174,6 @@ void DisplayManager_::dismissNotify() DisplayManager.setBrightness(0); } } - if (ALARM_ACTIVE) - { - PeripheryManager.stopSound(); - ALARM_ACTIVE = false; - } -} - -void timerCallback() -{ - TIMER_ACTIVE = true; - TimerTicker.detach(); -} - -void DisplayManager_::gererateTimer(String Payload) -{ - DynamicJsonDocument doc(1024); - DeserializationError error = deserializeJson(doc, Payload); - if (error) - return; - int hours = doc["hours"] | 0; - int minutes = doc["minutes"] | 0; - int seconds = doc["seconds"] | 0; - TIMER_SOUND = doc.containsKey("sound") ? doc["sound"].as() : ""; - time_t now = time(nullptr); - struct tm futureTimeinfo = *localtime(&now); - futureTimeinfo.tm_hour += hours; - futureTimeinfo.tm_min += minutes; - futureTimeinfo.tm_sec += seconds; - time_t futureTime = mktime(&futureTimeinfo); - int interval = difftime(futureTime, now) * 1000; - TimerTicker.once_ms(interval, timerCallback); } bool DisplayManager_::switchToApp(const char *json) @@ -1260,7 +1209,6 @@ 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); } @@ -1697,6 +1645,42 @@ bool DisplayManager_::indicatorParser(uint8_t indicator, const char *json) break; } } + + + if (doc.containsKey("fade")) + { + switch (indicator) + { + case 1: + ui->setIndicator1Fade(doc["fade"].as()); + break; + case 2: + ui->setIndicator2Fade(doc["fade"].as()); + break; + case 3: + ui->setIndicator3Fade(doc["fade"].as()); + break; + default: + break; + } + } + else + { + switch (indicator) + { + case 1: + ui->setIndicator1Fade(0); + break; + case 2: + ui->setIndicator2Fade(0); + break; + case 3: + ui->setIndicator3Fade(0); + break; + default: + break; + } + } MQTTManager.setIndicatorState(indicator, ui->indicator1State, ui->indicator1Color); return true; } @@ -1734,6 +1718,13 @@ void DisplayManager_::sendAppLoop() MQTTManager.publish("stats/loop", getAppsAsJson().c_str()); } +String CRGBtoHex(CRGB color) +{ + char buf[8]; + snprintf(buf, sizeof(buf), "#%02X%02X%02X", color.r, color.g, color.b); + return String(buf); +} + String DisplayManager_::getSettings() { StaticJsonDocument<1024> doc; @@ -1757,8 +1748,8 @@ String DisplayManager_::getSettings() doc["SOUND"] = SOUND_ACTIVE; doc["GAMMA"] = GAMMA; doc["UPPERCASE"] = UPPERCASE_LETTERS; - doc["CCORRECTION"] = COLOR_CORRECTION.raw; - doc["CTEMP"] = COLOR_TEMPERATURE.raw; + doc["CCORRECTION"] = CRGBtoHex(COLOR_CORRECTION); + doc["CTEMP"] = CRGBtoHex(COLOR_TEMPERATURE); doc["WD"] = SHOW_WEEKDAY; doc["TEFF"] = TRANS_EFFECT; doc["WDCA"] = WDC_ACTIVE; diff --git a/src/DisplayManager.h b/src/DisplayManager.h index 19501c6b..fd2c639b 100644 --- a/src/DisplayManager.h +++ b/src/DisplayManager.h @@ -28,11 +28,12 @@ class DisplayManager_ const unsigned long interval = 1000; public: -struct RGB { - int r; - int g; - int b; - }; + struct RGB + { + int r; + int g; + int b; + }; static DisplayManager_ &getInstance(); bool appIsSwitching; bool showGif; @@ -50,13 +51,13 @@ struct RGB { void previousApp(); void leftButton(); void resetTextColor(); - void gererateTimer(String); + void setArrayBrightness(uint8_t brightness); void clearMatrix(); void selectButton(); void selectButtonLong(); void setBrightness(int); void setTextColor(uint16_t color); - bool generateNotification(uint8_t source,const char *json); + bool generateNotification(uint8_t source, const char *json); bool generateCustomPage(const String &name, const char *json, bool preventSave); void printText(int16_t x, int16_t y, const char *text, bool centered, byte textCase); bool setAutoTransition(bool active); @@ -94,10 +95,10 @@ struct RGB { void startArtnet(); bool parseCustomPage(const String &name, const char *json); bool moodlight(const char *json); - int* getLedColors(); + int *getLedColors(); void sendBMP(Stream &stream); CRGB getPixelColor(int16_t x, int16_t y); - CRGB* getLeds(); + CRGB *getLeds(); String getEffectNames(); String getTransistionNames(); }; diff --git a/src/Globals.cpp b/src/Globals.cpp index 3cd6ad3b..f1866316 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -273,7 +273,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.78"; +const char *VERSION = "0.79"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; @@ -329,10 +329,7 @@ String DATE_FORMAT = "%d.%m.%y"; int BACKGROUND_EFFECT = -1; bool START_ON_MONDAY; -String ALARM_SOUND; -uint8_t SNOOZE_TIME; -String TIMER_SOUND; // Matrix States bool AUTO_TRANSITION = false; @@ -340,8 +337,8 @@ bool AUTO_BRIGHTNESS = true; bool UPPERCASE_LETTERS = true; bool AP_MODE; bool MATRIX_OFF; -bool TIMER_ACTIVE; -bool ALARM_ACTIVE; + + uint16_t TEXTCOLOR_565; bool SOUND_ACTIVE; String BOOT_SOUND = ""; diff --git a/src/Globals.h b/src/Globals.h index 3203757c..8ace45d1 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -81,13 +81,9 @@ extern String TEXTCOLOR; extern String TIME_FORMAT; extern bool AUTO_BRIGHTNESS; extern bool AP_MODE; -extern bool ALARM_ACTIVE; -extern bool TIMER_ACTIVE; extern bool MATRIX_OFF; -extern String ALARM_SOUND; -extern String TIMER_SOUND; extern uint16_t TEXTCOLOR_565; -extern uint8_t SNOOZE_TIME; + extern bool AUTO_TRANSITION; extern String TIME_FORMAT; extern String DATE_FORMAT; diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 5e9ea88b..150c870d 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -180,13 +180,6 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) return; } - if (strTopic.equals(MQTT_PREFIX + "/timer")) - { - DisplayManager.gererateTimer(payloadCopy); - delete[] payloadCopy; - return; - } - if (strTopic.equals(MQTT_PREFIX + "/notify/dismiss")) { DisplayManager.dismissNotify(); @@ -333,7 +326,6 @@ void onMqttConnected() "/brightness", "/notify/dismiss", "/notify", - "/timer", "/custom/#", "/switch", "/settings", diff --git a/src/MatrixDisplayUi.cpp b/src/MatrixDisplayUi.cpp index 816da927..97c66356 100644 --- a/src/MatrixDisplayUi.cpp +++ b/src/MatrixDisplayUi.cpp @@ -111,7 +111,6 @@ void MatrixDisplayUi::setAppAnimation(AnimationDirection dir) void MatrixDisplayUi::setApps(const std::vector> &appPairs) { - delete[] AppFunctions; AppCount = appPairs.size(); AppFunctions = new AppCallback[AppCount]; @@ -182,7 +181,6 @@ void MatrixDisplayUi::transitionToApp(uint8_t app) this->lastTransitionDirection = this->state.appTransitionDirection; this->state.manuelControll = true; this->state.appState = IN_TRANSITION; - this->state.appTransitionDirection = app < this->state.currentApp ? -1 : 1; } @@ -262,46 +260,70 @@ void MatrixDisplayUi::tick() void MatrixDisplayUi::drawIndicators() { + uint16_t drawColor; - if (indicator1State && indicator1Blink && (millis() % (2 * indicator1Blink)) < indicator1Blink) - { - matrix->drawPixel(31, 0, indicator1Color); - matrix->drawPixel(30, 0, indicator1Color); - matrix->drawPixel(31, 1, indicator1Color); - } - - if (indicator2State && indicator2Blink && (millis() % (2 * indicator2Blink)) < indicator2Blink) - { - matrix->drawPixel(31, 3, indicator2Color); - matrix->drawPixel(31, 4, indicator2Color); - } - - if (indicator3State && indicator3Blink && (millis() % (2 * indicator3Blink)) < indicator3Blink) - { - matrix->drawPixel(31, 7, indicator3Color); - matrix->drawPixel(31, 6, indicator3Color); - matrix->drawPixel(30, 7, indicator3Color); - } - - if (indicator1State && !indicator1Blink) - { - matrix->drawPixel(31, 0, indicator1Color); - matrix->drawPixel(30, 0, indicator1Color); - matrix->drawPixel(31, 1, indicator1Color); + // Indicator 1 + if (indicator1State) { + if (indicator1Blink) { + if (millis() % (2 * indicator1Blink) < indicator1Blink) { + drawColor = indicator1Color; + } else { + drawColor = 0; // Schwarz + } + } else if (indicator1Fade) { + drawColor = fadeColor(indicator1Color, indicator1Fade); + } else { + drawColor = indicator1Color; + } + matrix->drawPixel(31, 0, drawColor); + matrix->drawPixel(30, 0, drawColor); + matrix->drawPixel(31, 1, drawColor); + } + + // Indicator 2 + if (indicator2State) { + if (indicator2Blink) { + if (millis() % (2 * indicator2Blink) < indicator2Blink) { + drawColor = indicator2Color; + } else { + drawColor = 0; // Schwarz + } + } else if (indicator2Fade) { + drawColor = fadeColor(indicator2Color, indicator2Fade); + } else { + drawColor = indicator2Color; + } + matrix->drawPixel(31, 3, drawColor); + matrix->drawPixel(31, 4, drawColor); + } + + // Indicator 3 + if (indicator3State) { + if (indicator3Blink) { + if (millis() % (2 * indicator3Blink) < indicator3Blink) { + drawColor = indicator3Color; + } else { + drawColor = 0; // Schwarz + } + } else if (indicator3Fade) { + drawColor = fadeColor(indicator3Color, indicator3Fade); + } else { + drawColor = indicator3Color; + } + matrix->drawPixel(31, 7, drawColor); + matrix->drawPixel(31, 6, drawColor); + matrix->drawPixel(30, 7, drawColor); } +} - if (indicator2State && !indicator2Blink) - { - matrix->drawPixel(31, 3, indicator2Color); - matrix->drawPixel(31, 4, indicator2Color); - } - if (indicator3State && !indicator3Blink) - { - matrix->drawPixel(31, 7, indicator3Color); - matrix->drawPixel(31, 6, indicator3Color); - matrix->drawPixel(30, 7, indicator3Color); - } +uint16_t MatrixDisplayUi::fadeColor(uint16_t color, uint32_t interval) +{ + float phase = (sin(2 * PI * millis() / float(interval)) + 1) * 0.5; + uint8_t r = ((color >> 11) & 0x1F) * phase; + uint8_t g = ((color >> 5) & 0x3F) * phase; + uint8_t b = (color & 0x1F) * phase; + return (r << 11) | (g << 5) | b; } uint8_t currentTransition; @@ -445,6 +467,11 @@ void MatrixDisplayUi::setIndicator1Blink(int blink) this->indicator1Blink = blink; } +void MatrixDisplayUi::setIndicator1Fade(int fade) +{ + this->indicator1Fade = fade; +} + void MatrixDisplayUi::setIndicator2Color(uint16_t color) { this->indicator2Color = color; @@ -460,6 +487,11 @@ void MatrixDisplayUi::setIndicator2Blink(int blink) this->indicator2Blink = blink; } +void MatrixDisplayUi::setIndicator2Fade(int fade) +{ + this->indicator2Fade = fade; +} + void MatrixDisplayUi::setIndicator3Color(uint16_t color) { this->indicator3Color = color; @@ -475,6 +507,11 @@ void MatrixDisplayUi::setIndicator3Blink(int blink) this->indicator3Blink = blink; } +void MatrixDisplayUi::setIndicator3Fade(int fade) +{ + this->indicator3Fade = fade; +} + // ------------------ TRANSITIONS ------------------- float distance(int x1, int y1, int x2, int y2) { diff --git a/src/MatrixDisplayUi.h b/src/MatrixDisplayUi.h index d6ce55b3..a0e4c6a5 100644 --- a/src/MatrixDisplayUi.h +++ b/src/MatrixDisplayUi.h @@ -70,7 +70,6 @@ struct MatrixDisplayUiState u_int64_t lastUpdate = 0; long ticksSinceLastStateSwitch = 0; - AppState appState = FIXED; uint8_t currentApp = 0; @@ -133,6 +132,7 @@ class MatrixDisplayUi void blinkTransition(); void reloadTransition(); void crossfadeTransition(); + uint16_t fadeColor(uint16_t color, uint32_t interval); public: MatrixDisplayUi(FastLED_NeoMatrix *matrix); @@ -179,15 +179,17 @@ class MatrixDisplayUi void setIndicator1Color(uint16_t color); void setIndicator1State(bool state); void setIndicator1Blink(int Blink); + void setIndicator1Fade(int fade); void setIndicator2Color(uint16_t color); void setIndicator2State(bool state); void setIndicator2Blink(int Blink); + void setIndicator2Fade(int fade); void setIndicator3Color(uint16_t color); void setIndicator3State(bool state); void setIndicator3Blink(int Blink); - + void setIndicator3Fade(int fade); void drawIndicators(); // Customize indicator position and style @@ -241,5 +243,9 @@ class MatrixDisplayUi int indicator1Blink = 0; int indicator2Blink = 0; int indicator3Blink = 0; + + int indicator1Fade = 0; + int indicator2Fade = 0; + int indicator3Fade = 0; }; #endif diff --git a/src/PeripheryManager.cpp b/src/PeripheryManager.cpp index 37baf623..73e77bd2 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -176,8 +176,8 @@ void select_button_pressed_long() #ifndef ULANZI PeripheryManager.playFromFile(DFMINI_MP3_CLICK); #endif - if (!ALARM_ACTIVE) - MenuManager.selectButtonLong(); + + MenuManager.selectButtonLong(); DisplayManager.selectButtonLong(); @@ -457,70 +457,7 @@ void PeripheryManager_::tick() } } -const int MIN_ALARM_INTERVAL = 60; // 1 Minute -time_t lastAlarmTime = 0; -// deprecated -void PeripheryManager_::checkAlarms() -{ - if (LittleFS.exists("/alarms.json")) - { - File file = LittleFS.open("/alarms.json", "r"); - DynamicJsonDocument doc(file.size() * 1.33); - DeserializationError error = deserializeJson(doc, file); - if (error) - { - if (DEBUG_MODE) - DEBUG_PRINTLN(F("Failed to read Alarm file")); - return; - } - JsonArray alarms = doc["alarms"]; - file.close(); - - time_t now1 = time(nullptr); - struct tm *timeInfo; - timeInfo = localtime(&now1); - int currentHour = timeInfo->tm_hour; - int currentMinute = timeInfo->tm_min; - int currentDay = timeInfo->tm_wday - 1; - - for (JsonObject alarm : alarms) - { - int alarmHour = alarm["hour"]; - int alarmMinute = alarm["minute"]; - String alarmDays = alarm["days"]; - - if (currentHour == alarmHour && currentMinute == alarmMinute && alarmDays.indexOf(String(currentDay)) != -1) - { - if (difftime(now1, lastAlarmTime) < MIN_ALARM_INTERVAL) - { - return; - } - - ALARM_ACTIVE = true; - lastAlarmTime = now1; - - if (alarm.containsKey("sound")) - { - ALARM_SOUND = alarm["sound"].as(); - } - else - { - ALARM_SOUND = ""; - } - - if (alarm.containsKey("snooze")) - { - SNOOZE_TIME = alarm["snooze"].as(); - } - else - { - SNOOZE_TIME = 0; - } - } - } - } -} long PeripheryManager_::readUptime() { diff --git a/src/PeripheryManager.h b/src/PeripheryManager.h index a28bedda..8816e242 100644 --- a/src/PeripheryManager.h +++ b/src/PeripheryManager.h @@ -16,7 +16,6 @@ class PeripheryManager_ { private: PeripheryManager_() = default; - void checkAlarms(); #ifdef ULANZI const int BatReadings = 10; uint16_t TotalBatReadings[10]; diff --git a/src/ServerManager.cpp b/src/ServerManager.cpp index cf31bf23..8fe019ce 100644 --- a/src/ServerManager.cpp +++ b/src/ServerManager.cpp @@ -84,8 +84,6 @@ void addHandler() { mws.webserver->send(200, "text/html", screen_html); }); mws.addHandler("/api/previousapp", HTTP_POST, []() { DisplayManager.previousApp(); mws.webserver->send(200,F("text/plain"),F("OK")); }); - mws.addHandler("/api/timer", HTTP_POST, []() - { DisplayManager.gererateTimer(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,F("text/plain"),F("OK")); }); mws.addHandler("/api/notify/dismiss", HTTP_POST, []() { DisplayManager.dismissNotify(); mws.webserver->send(200,F("text/plain"),F("OK")); }); mws.addHandler("/api/apps", HTTP_POST, []()