From 48bb13b965f9605cdbaa5ba7e44a07630615e658 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Wed, 20 Sep 2023 02:17:23 +0200 Subject: [PATCH] Flash lights when settings changed --- src/lib/functions.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/lib/functions.hpp | 1 + src/lib/webserver.cpp | 2 ++ 3 files changed, 40 insertions(+) diff --git a/src/lib/functions.cpp b/src/lib/functions.cpp index dfdf56a..5d5b645 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -399,6 +399,43 @@ void setLights(int r, int g, int b) #endif } +void flashTemporaryLights(int r, int g, int b) +{ + #ifdef WITH_RGB_LED + + uint32_t oldLights[NEOPIXEL_COUNT]; + + // get current state + for (int i = 0; i < NEOPIXEL_COUNT; i++) + { + oldLights[i] = pixels.getPixelColor(i); + } + + // flash three times in given color + for (int t = 0; t < 3; t++) { + for (int i = 0; i < NEOPIXEL_COUNT; i++) + { + pixels.setPixelColor(i, pixels.Color(r, g, b)); + } + + pixels.show(); + delay(200); + + pixels.clear(); + pixels.show(); + delay(200); + } + + // revert to previous state + for (int i = 0; i < NEOPIXEL_COUNT; i++) + { + pixels.setPixelColor(i, oldLights[i]); + } + + pixels.show(); + #endif +} + void setupI2C() { bool slaveMode = preferences.getBool("I2CSlaveMode", false); diff --git a/src/lib/functions.hpp b/src/lib/functions.hpp index d5ce525..5941059 100644 --- a/src/lib/functions.hpp +++ b/src/lib/functions.hpp @@ -17,6 +17,7 @@ void setupWifi(); void synchronizeTime(); void setupPreferences(); void setLights(int r, int g, int b); +void flashTemporaryLights(int r, int g, int b); void setupI2C(); void onI2CReceive(int len); void onI2CRequest(); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 720d75c..d6ea019 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -287,6 +287,8 @@ void onApiSettingsPost(AsyncWebServerRequest *request) request->send(200); if (settingsChanged) { + flashTemporaryLights(0,255,0); + Serial.println("Settings changed"); } }