From 9312ceb22b88eedc9dd43b7123cb7f88f108894b Mon Sep 17 00:00:00 2001 From: Robin Cerny Date: Tue, 20 Jan 2026 11:24:38 +0100 Subject: [PATCH] added lighting settings to UI and prefs --- analog_system_monitor_arduino/Core.cpp | 12 +++++ analog_system_monitor_arduino/Core.h | 5 ++ analog_system_monitor_arduino/Ui.cpp | 73 ++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/analog_system_monitor_arduino/Core.cpp b/analog_system_monitor_arduino/Core.cpp index 9895157..e813730 100644 --- a/analog_system_monitor_arduino/Core.cpp +++ b/analog_system_monitor_arduino/Core.cpp @@ -26,6 +26,10 @@ float calibratedPoints[NUM_CHANNELS][5] = { {0.0f, 26.0f, 50.0f, 76.0f, 99.0f} }; +uint8_t lightingHue = 0; +uint8_t lightingSaturation = 255; +uint8_t lightingBrightness = 255; + bool overrideActive[NUM_CHANNELS] = {false}; ConnectionState connectionState = STATE_DISCONNECTED; @@ -107,6 +111,14 @@ void coreInit() { } } + lightingHue = prefs.getUChar("light_hue", 0); + lightingSaturation = prefs.getUChar("light_sat", 255); + lightingBrightness = prefs.getUChar("light_bright",255); + + Serial.printf("Lighting loaded (0–255): H=%d S=%d B=%d\n", + lightingHue, lightingSaturation, lightingBrightness); + + // Start UDP with runtime port udp.begin(udpPort); Serial.print("Listening on UDP port "); diff --git a/analog_system_monitor_arduino/Core.h b/analog_system_monitor_arduino/Core.h index 77189ee..747d0e7 100644 --- a/analog_system_monitor_arduino/Core.h +++ b/analog_system_monitor_arduino/Core.h @@ -23,6 +23,11 @@ extern float logicalPoints[5]; extern float calibratedPoints[NUM_CHANNELS][5]; extern bool overrideActive[NUM_CHANNELS]; +// Lighting parameters (0–255 range for now) +extern uint8_t lightingHue; // 0–255 +extern uint8_t lightingSaturation; // 0–255 +extern uint8_t lightingBrightness; // 0–255 + // State extern ConnectionState connectionState; diff --git a/analog_system_monitor_arduino/Ui.cpp b/analog_system_monitor_arduino/Ui.cpp index ac85c48..69961e9 100644 --- a/analog_system_monitor_arduino/Ui.cpp +++ b/analog_system_monitor_arduino/Ui.cpp @@ -96,6 +96,24 @@ void calOverrideSwitchCallback(Control *sender, int type) { } } } +void lightingSaveCallback(Control *sender, int type) { + if (type != B_UP) return; // avoid double-trigger + + prefs.putUChar("light_hue", lightingHue); + prefs.putUChar("light_sat", lightingSaturation); + prefs.putUChar("light_bright", lightingBrightness); + + Serial.printf("Lighting saved (0–255): H=%d S=%d B=%d\n", + lightingHue, lightingSaturation, lightingBrightness); +} + +static int toSlider(uint8_t v) { + return (int)((v / 255.0f) * 100.0f); +} + +static uint8_t fromSlider(int v) { + return (uint8_t)((v / 100.0f) * 255.0f); +} // ------------------------------- // UI init @@ -213,13 +231,58 @@ void uiInit(uint16_t& tabSettings, uint16_t& tabLighting, uint16_t& tabCalibrati restartCallback ); - // Lighting tab placeholder + // ------------------------------- + // Lighting Controls + // ------------------------------- + + // Hue slider (0–360) ESPUI.addControl( - ControlType::Label, - "Lighting Placeholder", - "Coming soon...", + ControlType::Slider, + "Hue", + String(toSlider(lightingHue)), + ControlColor::Sunflower, + tabLighting, + [](Control *sender, int type) { + int sliderVal = sender->value.toInt(); // 0–100 + lightingHue = fromSlider(sliderVal); // convert to 0–255 + Serial.printf("Lighting Hue changed (RAM only): %d\n", lightingHue); + } + ); + + // Saturation slider (0–100) + ESPUI.addControl( + ControlType::Slider, + "Saturation", + String(toSlider(lightingSaturation)), + ControlColor::Carrot, + tabLighting, + [](Control *sender, int type) { + int sliderVal = sender->value.toInt(); // 0–100 + lightingSaturation = fromSlider(sliderVal); + Serial.printf("Lighting Saturation updated (RAM only): %d\n", lightingSaturation); + } + ); + + // Brightness slider (0–100) + ESPUI.addControl( + ControlType::Slider, + "Brightness", + String(toSlider(lightingBrightness)), ControlColor::Emerald, - tabLighting + tabLighting, + [](Control *sender, int type) { + int sliderVal = sender->value.toInt(); // 0–100 + lightingBrightness = fromSlider(sliderVal); + Serial.printf("Lighting Brightness updated (RAM only): %d\n", lightingBrightness); + } + ); + ESPUI.addControl( + ControlType::Button, + "Save Lighting Settings", + "Save", + ControlColor::Emerald, + tabLighting, + lightingSaveCallback ); // -------------------------------