From 491618dd783d3f8f0b838de4c3ffc751b5e8ec0e Mon Sep 17 00:00:00 2001
From: Djuri Baars <dsbaars@users.noreply.github.com>
Date: Sat, 8 Jun 2024 11:35:23 +0200
Subject: [PATCH] Fix light control API functionality, changed light setting
 endpoints

---
 data                    |  2 +-
 src/lib/config.cpp      |  2 +-
 src/lib/led_handler.cpp | 11 ++++++-----
 src/lib/webserver.cpp   |  4 ++--
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/data b/data
index e859ada..4f15eee 160000
--- a/data
+++ b/data
@@ -1 +1 @@
-Subproject commit e859adac8631c6380a6a3f8b20b118a5531d4f8c
+Subproject commit 4f15eee72bcd3873a0edb61bc77638a0ff5e3724
diff --git a/src/lib/config.cpp b/src/lib/config.cpp
index ac5e8cb..8a2f463 100644
--- a/src/lib/config.cpp
+++ b/src/lib/config.cpp
@@ -722,7 +722,7 @@ void setupFrontlight()
   }
   if (!preferences.isKey("flEffectDelay"))
   {
-    preferences.putUInt("flEffectDelay", 5);
+    preferences.putUInt("flEffectDelay", 15);
   }
 
   if (!preferences.isKey("flFlashOnUpd"))
diff --git a/src/lib/led_handler.cpp b/src/lib/led_handler.cpp
index 1c7799a..aa2fda6 100644
--- a/src/lib/led_handler.cpp
+++ b/src/lib/led_handler.cpp
@@ -6,7 +6,7 @@ Adafruit_NeoPixel pixels(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
 uint ledTaskParams;
 
 #ifdef HAS_FRONTLIGHT
-#define FL_FADE_STEP 50
+#define FL_FADE_STEP 25
 
 bool frontlightOn = false;
 bool flInTransition = false;
@@ -15,13 +15,13 @@ void frontlightFlash(int flDelayTime)
 {
   if (frontlightOn)
   {
-    frontlightFadeOutAll(flDelayTime);
-    frontlightFadeInAll(flDelayTime);
+    frontlightFadeOutAll(flDelayTime, true);
+    frontlightFadeInAll(flDelayTime, true);
   }
   else
   {
-    frontlightFadeInAll(flDelayTime);
-    frontlightFadeOutAll(flDelayTime);
+    frontlightFadeInAll(flDelayTime, true);
+    frontlightFadeOutAll(flDelayTime, true);
   }
 }
 
@@ -264,6 +264,7 @@ void ledTask(void *parameter)
 #ifdef HAS_FRONTLIGHT
           if (preferences.getBool("flFlashOnUpd", false))
           {
+            vTaskDelay(pdMS_TO_TICKS(10));
             if (frontlightWasOn)
             {
               frontlightFadeInAll(1);
diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp
index 73ef946..7b73823 100644
--- a/src/lib/webserver.cpp
+++ b/src/lib/webserver.cpp
@@ -46,7 +46,7 @@ void setupWebserver()
   server.addHandler(handler);
 
   AsyncCallbackJsonWebHandler *lightsJsonHandler =
-      new AsyncCallbackJsonWebHandler("/api/lights", onApiLightsSetJson);
+      new AsyncCallbackJsonWebHandler("/api/lights/set", onApiLightsSetJson);
   server.addHandler(lightsJsonHandler);
 
   server.on("/api/lights/off", HTTP_GET, onApiLightsOff);
@@ -68,7 +68,7 @@ void setupWebserver()
   // onApiLightsSetColor);
 
   server.on("/api/restart", HTTP_GET, onApiRestart);
-  server.addRewrite(new OneParamRewrite("/api/lights/{color}",
+  server.addRewrite(new OneParamRewrite("/api/lights/color/{color}",
                                         "/api/lights/color?c={color}"));
   server.addRewrite(
       new OneParamRewrite("/api/show/screen/{s}", "/api/show/screen?s={s}"));