From 44e9a9f895949062a7be8f75343b46057ca22d2e Mon Sep 17 00:00:00 2001 From: BastiMu Date: Fri, 18 Apr 2025 19:34:37 +0200 Subject: [PATCH 1/6] Add drop down menu for LED pin --- include/Uhr.h | 3 +++ include/clockWork.hpp | 29 +++++++++++++++++++++++------ include/webPageAdapter.h | 9 +++++++++ src/Wortuhr.cpp | 6 ++++-- webpage/index.html | 27 +++++++++++++++++++++++++++ webpage/language/de.js | 19 +++++++++++++++++++ webpage/language/en.js | 19 +++++++++++++++++++ webpage/script.js | 21 ++++++++++++++++----- 8 files changed, 120 insertions(+), 13 deletions(-) diff --git a/include/Uhr.h b/include/Uhr.h index 4421535c..c85aa43e 100644 --- a/include/Uhr.h +++ b/include/Uhr.h @@ -150,6 +150,8 @@ struct GLOBAL { bool bootShowWifi; bool bootShowIP; + uint8_t LEDpin; + Birthday birthday[MAX_BIRTHDAY_COUNT]; }; GLOBAL G = {}; @@ -253,6 +255,7 @@ enum CommandWords { COMMAND_SET_AUTO_BRIGHT = 102, COMMAND_SET_LAYOUT_VARIANT = 103, COMMAND_SET_MQTT_HA_DISCOVERY = 104, + COMMAND_SET_LEDPIN = 105, COMMAND_SPEED = 152, diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 2321a278..48efdedd 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -167,11 +167,12 @@ void ClockWork::initLedStrip(uint8_t num) { } if (strip_RGBW == NULL) { #ifdef ESP8266 - strip_RGBW = new NeoPixelBus(500); + strip_RGBW = + new NeoPixelBus(500, G.LEDpin); #elif defined(ESP32) - pinMode(LED_PIN, OUTPUT); + pinMode(G.LEDpin, OUTPUT); strip_RGBW = - new NeoPixelBus(500, LED_PIN); + new NeoPixelBus(500, G.LEDpin); #endif strip_RGBW->Begin(); } @@ -183,11 +184,12 @@ void ClockWork::initLedStrip(uint8_t num) { } if (strip_RGB == NULL) { #ifdef ESP8266 - strip_RGB = new NeoPixelBus(500); + strip_RGB = + new NeoPixelBus(500, G.LEDpin); #elif defined(ESP32) - pinMode(LED_PIN, OUTPUT); + pinMode(G.LEDpin, OUTPUT); strip_RGB = new NeoPixelBus( - 500, LED_PIN); + 500, G.LEDpin); #endif strip_RGB->Begin(); } @@ -1399,6 +1401,21 @@ void ClockWork::loop(struct tm &tm) { break; } + case COMMAND_SET_LEDPIN: { + led.clear(); + + // G.param1 sets new buildtype + Serial.printf("Clock LED pin: %u\n", G.param1); + + G.LEDpin = G.param1; + eeprom::write(); + initLedStrip(G.Colortype); + + clearClockByProgInit(); + parametersChanged = true; + break; + } + case COMMAND_SET_COLORTYPE: { // G.param1 sets new Colortype Serial.printf("LED Colortype: %u\n", G.param1); diff --git a/include/webPageAdapter.h b/include/webPageAdapter.h index a1fdcfac..c7eb894f 100644 --- a/include/webPageAdapter.h +++ b/include/webPageAdapter.h @@ -445,6 +445,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ + case COMMAND_SET_LEDPIN: { + G.progInit = true; + + G.param1 = split(payload, 3); + break; + } + + //------------------------------------------------------------------------------ + case COMMAND_SET_BIRTHDAYS: { for (uint8_t i = 0; i < MAX_BIRTHDAY_COUNT; i++) { diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 71fdfda6..41473817 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -34,8 +34,8 @@ iUhrType *usedUhrType = nullptr; #include "NeoMultiFeature.hpp" #ifdef ESP8266 -NeoPixelBus *strip_RGB = NULL; -NeoPixelBus *strip_RGBW = NULL; +NeoPixelBus *strip_RGB = NULL; +NeoPixelBus *strip_RGBW = NULL; #elif defined(ESP32) NeoPixelBus *strip_RGBW = NULL; NeoPixelBus *strip_RGB = NULL; @@ -269,6 +269,8 @@ void setup() { G.transitionColorize = 0; G.transitionDemo = false; + G.LEDpin = LED_PIN; + for (uint8_t i = 0; i < MAX_BIRTHDAY_COUNT; i++) { G.birthday[i].day = 1; G.birthday[i].month = 1; diff --git a/webpage/index.html b/webpage/index.html index 848ebc84..24cb2ef0 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -541,6 +541,33 @@

+
+

+
+
+
+ + +
+
+ +
+
+
+
+

diff --git a/webpage/language/de.js b/webpage/language/de.js index 44757cbf..432812aa 100644 --- a/webpage/language/de.js +++ b/webpage/language/de.js @@ -218,6 +218,25 @@ let TRANSLATION_DE_DE = { "label": "Verbindungsstatus", "connect": "Verbinden" }, + "led-pin": { + "h2": "LED Pin", + "help": "Hier kann der verwendete Pin für den LED-Streifen eingestellt werden.\n " + + "Hinweis: Es muss die GPIO-Nummer verwendet werden, nicht die aufgedruckte Zahl auf dem Board!\n " + + "Möglicherweise muss die Wortuhr neu gestartet werden.", + "label": "LED pin", + "GPIO2": "GPIO2", + "GPIO3": "GPIO3", + "GPIO4": "GPIO4", + "GPIO5": "GPIO5", + "GPIO6": "GPIO6", + "GPIO7": "GPIO7", + "GPIO8": "GPIO8", + "GPIO9": "GPIO9", + "GPIO10": "GPIO10", + "GPIO20": "GPIO20", + "GPIO21": "GPIO21", + "save": "Einstellung speichern" + }, "led-type": { "h2": "LED-Typ", "help": "Hier können Sie den Typ des verwendeten LED-Streifens (WS2812 oder SK6812) einstellen.\n" + diff --git a/webpage/language/en.js b/webpage/language/en.js index 2ca35f6f..213084f4 100644 --- a/webpage/language/en.js +++ b/webpage/language/en.js @@ -218,6 +218,25 @@ let TRANSLATION_EN_US = { "label": "Connection Status", "connect": "Connect" }, + "led-pin": { + "h2": "LED Pin", + "help": "Here you can set the pin used for the LED strip.\n " + + "Note: You need to set the GPIO pin, not the pin printed on your board!\n " + + "It may be neccessary to restart your Wordclock.", + "label": "LED pin", + "GPIO2": "GPIO2", + "GPIO3": "GPIO3", + "GPIO4": "GPIO4", + "GPIO5": "GPIO5", + "GPIO6": "GPIO6", + "GPIO7": "GPIO7", + "GPIO8": "GPIO8", + "GPIO9": "GPIO9", + "GPIO10": "GPIO10", + "GPIO20": "GPIO20", + "GPIO21": "GPIO21", + "save": "Save Setting" + }, "led-type": { "h2": "LED Type", "help": "Here you can set the type of LED strip used (WS2812 or SK6812).\n " + diff --git a/webpage/script.js b/webpage/script.js index 8b7acd09..4b9cd5a3 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -95,6 +95,7 @@ var transitionDuration = 1; var transitionSpeed = 30; var transitionColorize = 1; var transitionDemo = false; +var ledpin = 3; // operation modes var COMMAND_MODE_WORD_CLOCK = 1; @@ -150,6 +151,7 @@ var COMMAND_SET_BOOT = 101; var COMMAND_SET_AUTO_BRIGHT = 102; var COMMAND_SET_LAYOUT_VARIANT = 103; var COMMAND_SET_MQTT_HA_DISCOVERY = 104; +var COMMAND_SET_LEDPIN = 105; var COMMAND_SPEED = 152; @@ -239,6 +241,7 @@ function initConfigValues() { transitionSpeed = 30; transitionColorize = 1; transitionDemo = false; + ledpin = 3; } /* eslint-disable no-console */ @@ -335,12 +338,12 @@ function initWebsocket() { if (data.command === "mqtt") { $("#mqtt-port").set("value", data.MQTT_Port); - $("#mqtt-server").set({ "value": data.MQTT_Server, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); + $("#mqtt-server").set("value", data.MQTT_Server); document.getElementById("mqtt-state").checked = data.MQTT_State; - $("#mqtt-user").set({ "value": data.MQTT_User, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); - $("#mqtt-pass").set({ "value": data.MQTT_Pass, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); - $("#mqtt-clientid").set({ "value": data.MQTT_ClientId, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); - $("#mqtt-topic").set({ "value": data.MQTT_Topic, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); + $("#mqtt-user").set("value", data.MQTT_User); + $("#mqtt-pass").set("value", data.MQTT_Pass); + $("#mqtt-clientid").set("value", data.MQTT_ClientId); + $("#mqtt-topic").set("value", data.MQTT_Topic); } if (data.command === "birthdays") { @@ -392,6 +395,7 @@ function initWebsocket() { $("#front-layout").set("value", data.UhrtypeDef); $("#buildtype").set("value", data.buildtype); $("#whitetype").set("value", data.wType); + $("#ledpin").set("value", data.ledpin); $("#colortype").set("value", data.colortype); document.getElementById("boot-show-led-blink").checked = data.bootLedBlink; @@ -430,6 +434,7 @@ function initWebsocket() { hsb[1][2] = data.hsb12; effectBri = data.effectBri; effectSpeed = data.effectSpeed; + ledpin = data.ledpin; colortype = data.colortype; hasHappyBirthday = data.hasHappyBirthday; @@ -907,6 +912,12 @@ $.ready(function() { sendCmd(COMMAND_REQUEST_CONFIG_VALUES); debugMessage("FrontLayout" + debugMessageReconfigured); }); + $("#ledpin-button").on("click", function() { + ledpin = $("#ledpin").get("value"); + + sendCmd(COMMAND_SET_LEDPIN, nstr(ledpin)); + debugMessage("ledpin" + debugMessageReconfigured); + }); $("#colortype-button").on("click", function() { colortype = $("#colortype").get("value"); From 73ceb3611c8a530c070fa6b8c8aefb5a5f36cb75 Mon Sep 17 00:00:00 2001 From: BastiMu Date: Fri, 18 Apr 2025 19:41:36 +0200 Subject: [PATCH 2/6] clang formatting --- include/clockWork.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 48efdedd..8112eee1 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -168,7 +168,8 @@ void ClockWork::initLedStrip(uint8_t num) { if (strip_RGBW == NULL) { #ifdef ESP8266 strip_RGBW = - new NeoPixelBus(500, G.LEDpin); + new NeoPixelBus( + 500, G.LEDpin); #elif defined(ESP32) pinMode(G.LEDpin, OUTPUT); strip_RGBW = @@ -185,7 +186,8 @@ void ClockWork::initLedStrip(uint8_t num) { if (strip_RGB == NULL) { #ifdef ESP8266 strip_RGB = - new NeoPixelBus(500, G.LEDpin); + new NeoPixelBus( + 500, G.LEDpin); #elif defined(ESP32) pinMode(G.LEDpin, OUTPUT); strip_RGB = new NeoPixelBus( From 8d8d6ed27bf7c2ed19c1c0f48a39599d6111912b Mon Sep 17 00:00:00 2001 From: BastiMu Date: Fri, 18 Apr 2025 19:45:06 +0200 Subject: [PATCH 3/6] clang formatting --- include/clockWork.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 8112eee1..3628c388 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -186,8 +186,8 @@ void ClockWork::initLedStrip(uint8_t num) { if (strip_RGB == NULL) { #ifdef ESP8266 strip_RGB = - new NeoPixelBus( - 500, G.LEDpin); + new NeoPixelBus(500, G.LEDpin); #elif defined(ESP32) pinMode(G.LEDpin, OUTPUT); strip_RGB = new NeoPixelBus( @@ -1405,10 +1405,10 @@ void ClockWork::loop(struct tm &tm) { case COMMAND_SET_LEDPIN: { led.clear(); - + // G.param1 sets new buildtype Serial.printf("Clock LED pin: %u\n", G.param1); - + G.LEDpin = G.param1; eeprom::write(); initLedStrip(G.Colortype); @@ -1417,7 +1417,7 @@ void ClockWork::loop(struct tm &tm) { parametersChanged = true; break; } - + case COMMAND_SET_COLORTYPE: { // G.param1 sets new Colortype Serial.printf("LED Colortype: %u\n", G.param1); From 4512389527ba0b6115ca9cda4f4dd49056327b81 Mon Sep 17 00:00:00 2001 From: BastiMu Date: Wed, 23 Apr 2025 14:08:33 +0200 Subject: [PATCH 4/6] Add Buttons --- include/Uhr.h | 5 ++- include/clockWork.h | 3 ++ include/clockWork.hpp | 90 ++++++++++++++++++++++++++++++++++++++-- include/config.h | 3 ++ include/webPageAdapter.h | 7 +++- src/Wortuhr.cpp | 6 +++ webpage/index.html | 83 +++++++++++++++++++++++++++++------- webpage/language/de.js | 11 +++-- webpage/language/en.js | 11 +++-- webpage/script.js | 39 +++++++++++++++-- 10 files changed, 226 insertions(+), 32 deletions(-) diff --git a/include/Uhr.h b/include/Uhr.h index c85aa43e..68e9d127 100644 --- a/include/Uhr.h +++ b/include/Uhr.h @@ -151,6 +151,9 @@ struct GLOBAL { bool bootShowIP; uint8_t LEDpin; + uint8_t powerButton; + uint8_t modeButton; + uint8_t speedButton; Birthday birthday[MAX_BIRTHDAY_COUNT]; }; @@ -255,7 +258,7 @@ enum CommandWords { COMMAND_SET_AUTO_BRIGHT = 102, COMMAND_SET_LAYOUT_VARIANT = 103, COMMAND_SET_MQTT_HA_DISCOVERY = 104, - COMMAND_SET_LEDPIN = 105, + COMMAND_SET_GPIO = 105, COMMAND_SPEED = 152, diff --git a/include/clockWork.h b/include/clockWork.h index 2f278add..772ef951 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -16,6 +16,8 @@ class ClockWork { uint16_t adcValue0Lux = 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, // für eine dynamische offset korrektur bei 0 LUX + unsigned long buttonPressStart = 0; // Variable to store the time when the button was pressed + bool buttonPressed = false; // State of the button private: //------------------------------------------------------------------------------ @@ -23,6 +25,7 @@ class ClockWork { //------------------------------------------------------------------------------ void initBH1750Logic(); void loopAutoBrightLogic(); + void loopGPIOinput(); uint32_t num32BitWithOnesAccordingToColumns(); bool isRomanLanguage(); diff --git a/include/clockWork.hpp b/include/clockWork.hpp index 3628c388..31cb21e8 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -88,6 +88,86 @@ void ClockWork::initBH1750Logic() { //------------------------------------------------------------------------------ +void ClockWork::loopGPIOinput() { + // Read the power button state + int powerButtonState = digitalRead(G.powerButton); + + // Button is pressed + if (powerButtonState == HIGH && !buttonPressed) { + buttonPressed = true; // Button is now pressed + // Set off if brightness is set, set on if brightness is 0 + if (G.color[0].B > 0) { + for (uint8_t i = 0; i < 3; i++) { + G.color[i].B = 0; + } + } else { + for (uint8_t i = 0; i < 3; i++) { + G.color[i].B = 1; + } + } + } + + // Read the mode button state + int modeButtonState = digitalRead(G.modeButton); + + // Check if the button is pressed + if (modeButtonState == LOW && !buttonPressed) { + buttonPressed = true; // Button is now pressed + buttonPressStart = millis(); // Record the start time of the press + } + + // Check if the button is released + if (modeButtonState == HIGH && buttonPressed) { + buttonPressed = false; // Button is released + unsigned long pressDuration = millis() - buttonPressStart; + + if (pressDuration < 2000) { // Short press duration threshold (2000 ms) + // set next mode in range 1 - 8 + G.prog = (G.prog % 8) + 1; + } else { + // set transition in range 0 - 12 + G.transitionType = (G.transitionType + 1) % 13; + } + } + + // Read the speed button state + int speedButtonState = digitalRead(G.speedButton); + + // Check if the button is pressed + if (speedButtonState == LOW && !buttonPressed) { + buttonPressed = true; // Button is now pressed + buttonPressStart = millis(); // Record the start time of the press + } + + // Check if the button is released + if (speedButtonState == HIGH && buttonPressed) { + buttonPressed = false; // Button is released + unsigned long pressDuration = millis() - buttonPressStart; + + if (pressDuration < 2000) { // Short press duration threshold (2000 ms) + // Set brightness in range 10% - 100% with step 10% + if (G.color[0].B == 1) { + G.color[0].B = 0.1; + } else if (G.color[0].B >= 0.9) { + G.color[0].B = 1; + } else { + G.color[0].B += 0.1; + } + } else { + // Set hue in range 0 - 360 with step 30 + if (G.color[0].H == 360) { + G.color[0].B = 0; + } else if (G.color[0].B >= 330) { + G.color[0].B = 360; + } else { + G.color[0].B += 30; + } + } + } +} + + //------------------------------------------------------------------------------ + iUhrType *ClockWork::getPointer(uint8_t type) { switch (type) { case Ger10x11: @@ -1403,13 +1483,15 @@ void ClockWork::loop(struct tm &tm) { break; } - case COMMAND_SET_LEDPIN: { + case COMMAND_SET_GPIO: { led.clear(); - // G.param1 sets new buildtype - Serial.printf("Clock LED pin: %u\n", G.param1); + // Print new types + Serial.printf("Clock LED pin: GPIO%u\n", G.LEDpin); + Serial.printf("Clock power button: GPIO%u\n", G.powerButton); + Serial.printf("Clock mode button: GPIO%u\n", G.modeButton); + Serial.printf("Clock speed button: GPIO%u\n", G.speedButton); - G.LEDpin = G.param1; eeprom::write(); initLedStrip(G.Colortype); diff --git a/include/config.h b/include/config.h index 7ac89b64..6970883b 100644 --- a/include/config.h +++ b/include/config.h @@ -7,6 +7,9 @@ // PIN Configuration //-------------------------------------------------------------------------- #define LED_PIN 3 // Use direct pin number +#define POWER_BUTTON 2 // Use direct pin number +#define MODE_BUTTON 13 // Use direct pin number +#define SPEED_BUTTON 14 // Use direct pin number #define SDA_PIN_ESP32 21 // Use direct pin number #define SCL_PIN_ESP32 22 // Use direct pin number diff --git a/include/webPageAdapter.h b/include/webPageAdapter.h index c7eb894f..d9f8e590 100644 --- a/include/webPageAdapter.h +++ b/include/webPageAdapter.h @@ -445,10 +445,13 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, //------------------------------------------------------------------------------ - case COMMAND_SET_LEDPIN: { + case COMMAND_SET_GPIO: { G.progInit = true; - G.param1 = split(payload, 3); + G.LEDpin = split(payload, 3); + G.powerButton = split(payload, 6); + G.modeButton = split(payload, 9); + G.speedButton = split(payload, 12); break; } diff --git a/src/Wortuhr.cpp b/src/Wortuhr.cpp index 41473817..d300e822 100644 --- a/src/Wortuhr.cpp +++ b/src/Wortuhr.cpp @@ -157,6 +157,9 @@ void setup() { //------------------------------------- #if GENERAL_VERBOSE Serial.begin(115200); + pinMode(G.powerButton, INPUT_PULLUP); + pinMode(G.modeButton, INPUT_PULLUP); + pinMode(G.speedButton, INPUT_PULLUP); Serial.println(""); Serial.println("--------------------------------------"); Serial.println("Begin Setup"); @@ -270,6 +273,9 @@ void setup() { G.transitionDemo = false; G.LEDpin = LED_PIN; + G.powerButton = POWER_BUTTON; + G.modeButton = MODE_BUTTON; + G.speedButton = SPEED_BUTTON; for (uint8_t i = 0; i < MAX_BIRTHDAY_COUNT; i++) { G.birthday[i].day = 1; diff --git a/webpage/index.html b/webpage/index.html index 24cb2ef0..726e65ef 100644 --- a/webpage/index.html +++ b/webpage/index.html @@ -542,27 +542,80 @@

-

+

- - + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
- +
diff --git a/webpage/language/de.js b/webpage/language/de.js index 432812aa..4ac0f034 100644 --- a/webpage/language/de.js +++ b/webpage/language/de.js @@ -218,12 +218,15 @@ let TRANSLATION_DE_DE = { "label": "Verbindungsstatus", "connect": "Verbinden" }, - "led-pin": { - "h2": "LED Pin", + "hardware-config": { + "h2": "Hardware Einstellung", "help": "Hier kann der verwendete Pin für den LED-Streifen eingestellt werden.\n " + "Hinweis: Es muss die GPIO-Nummer verwendet werden, nicht die aufgedruckte Zahl auf dem Board!\n " + "Möglicherweise muss die Wortuhr neu gestartet werden.", - "label": "LED pin", + "led-pin": "LED pin", + "power-button": "Power Button", + "mode-button": "Mode Button", + "speed-button": "Speed Button", "GPIO2": "GPIO2", "GPIO3": "GPIO3", "GPIO4": "GPIO4", @@ -233,6 +236,8 @@ let TRANSLATION_DE_DE = { "GPIO8": "GPIO8", "GPIO9": "GPIO9", "GPIO10": "GPIO10", + "GPIO13": "GPIO13", + "GPIO14": "GPIO14", "GPIO20": "GPIO20", "GPIO21": "GPIO21", "save": "Einstellung speichern" diff --git a/webpage/language/en.js b/webpage/language/en.js index 213084f4..6ea29494 100644 --- a/webpage/language/en.js +++ b/webpage/language/en.js @@ -218,12 +218,15 @@ let TRANSLATION_EN_US = { "label": "Connection Status", "connect": "Connect" }, - "led-pin": { - "h2": "LED Pin", + "hardware-config": { + "h2": "Hardware configuration", "help": "Here you can set the pin used for the LED strip.\n " + "Note: You need to set the GPIO pin, not the pin printed on your board!\n " + "It may be neccessary to restart your Wordclock.", - "label": "LED pin", + "led-pin": "LED pin", + "power-button": "Power Button", + "mode-button": "Mode Button", + "speed-button": "Speed Button", "GPIO2": "GPIO2", "GPIO3": "GPIO3", "GPIO4": "GPIO4", @@ -233,6 +236,8 @@ let TRANSLATION_EN_US = { "GPIO8": "GPIO8", "GPIO9": "GPIO9", "GPIO10": "GPIO10", + "GPIO13": "GPIO13", + "GPIO14": "GPIO14", "GPIO20": "GPIO20", "GPIO21": "GPIO21", "save": "Save Setting" diff --git a/webpage/script.js b/webpage/script.js index 4b9cd5a3..f617a0e1 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -96,6 +96,9 @@ var transitionSpeed = 30; var transitionColorize = 1; var transitionDemo = false; var ledpin = 3; +var powerbutton = 2; +var modebutton = 13; +var speedbutton = 14; // operation modes var COMMAND_MODE_WORD_CLOCK = 1; @@ -151,7 +154,7 @@ var COMMAND_SET_BOOT = 101; var COMMAND_SET_AUTO_BRIGHT = 102; var COMMAND_SET_LAYOUT_VARIANT = 103; var COMMAND_SET_MQTT_HA_DISCOVERY = 104; -var COMMAND_SET_LEDPIN = 105; +var COMMAND_SET_GPIO = 105; var COMMAND_SPEED = 152; @@ -242,6 +245,9 @@ function initConfigValues() { transitionColorize = 1; transitionDemo = false; ledpin = 3; + powerbutton = 2; + modebutton = 13; + speedbutton = 14; } /* eslint-disable no-console */ @@ -396,8 +402,27 @@ function initWebsocket() { $("#buildtype").set("value", data.buildtype); $("#whitetype").set("value", data.wType); $("#ledpin").set("value", data.ledpin); + $("#powerbutton").set("value", data.powerbutton); + $("#modebutton").set("value", data.modebutton); + $("#speedbutton").set("value", data.speedbutton); $("#colortype").set("value", data.colortype); + removeSpecificOption("ledpin", data.powerbutton, true); + removeSpecificOption("ledpin", data.modebutton, true); + removeSpecificOption("ledpin", data.speedbutton, true); + + removeSpecificOption("powerbutton", data.ledpin, true); + removeSpecificOption("powerbutton", data.modebutton, true); + removeSpecificOption("powerbutton", data.speedbutton, true); + + removeSpecificOption("modebutton", data.ledpin, true); + removeSpecificOption("modebutton", data.powerbutton, true); + removeSpecificOption("modebutton", data.speedbutton, true); + + removeSpecificOption("speedbutton", data.ledpin, true); + removeSpecificOption("speedbutton", data.powerbutton, true); + removeSpecificOption("speedbutton", data.modebutton, true); + document.getElementById("boot-show-led-blink").checked = data.bootLedBlink; document.getElementById("boot-show-led-sweep").checked = data.bootLedSweep; document.getElementById("boot-show-wifi").checked = data.bootShowWifi; @@ -435,6 +460,9 @@ function initWebsocket() { effectBri = data.effectBri; effectSpeed = data.effectSpeed; ledpin = data.ledpin; + powerbutton = data.powerbutton; + modebutton = data.modebutton; + speedbutton = data.speedbutton; colortype = data.colortype; hasHappyBirthday = data.hasHappyBirthday; @@ -912,11 +940,14 @@ $.ready(function() { sendCmd(COMMAND_REQUEST_CONFIG_VALUES); debugMessage("FrontLayout" + debugMessageReconfigured); }); - $("#ledpin-button").on("click", function() { + $("#hardware-config-save-button").on("click", function() { ledpin = $("#ledpin").get("value"); + powerbutton = $("#powerbutton").get("value"); + modebutton = $("#modebutton").get("value"); + speedbutton = $("#speedbutton").get("value"); - sendCmd(COMMAND_SET_LEDPIN, nstr(ledpin)); - debugMessage("ledpin" + debugMessageReconfigured); + sendCmd(COMMAND_SET_GPIO, nstr(ledpin) + nstr(powerbutton) + nstr(modebutton) + nstr(speedbutton)); + debugMessage("hardware-config" + debugMessageReconfigured); }); $("#colortype-button").on("click", function() { colortype = $("#colortype").get("value"); From 456a059ed5c7ffb5ff9f76a5ea4c1ff5a8091a07 Mon Sep 17 00:00:00 2001 From: BastiMu Date: Wed, 23 Apr 2025 14:15:37 +0200 Subject: [PATCH 5/6] Revert mqtt change --- webpage/script.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webpage/script.js b/webpage/script.js index f617a0e1..ca2fd89b 100644 --- a/webpage/script.js +++ b/webpage/script.js @@ -344,12 +344,12 @@ function initWebsocket() { if (data.command === "mqtt") { $("#mqtt-port").set("value", data.MQTT_Port); - $("#mqtt-server").set("value", data.MQTT_Server); + $("#mqtt-server").set({ "value": data.MQTT_Server, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); document.getElementById("mqtt-state").checked = data.MQTT_State; - $("#mqtt-user").set("value", data.MQTT_User); - $("#mqtt-pass").set("value", data.MQTT_Pass); - $("#mqtt-clientid").set("value", data.MQTT_ClientId); - $("#mqtt-topic").set("value", data.MQTT_Topic); + $("#mqtt-user").set({ "value": data.MQTT_User, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); + $("#mqtt-pass").set({ "value": data.MQTT_Pass, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); + $("#mqtt-clientid").set({ "value": data.MQTT_ClientId, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); + $("#mqtt-topic").set({ "value": data.MQTT_Topic, "@maxlength": DATA_MQTT_RESPONSE_TEXT_LENGTH }); } if (data.command === "birthdays") { From d68dfae8e6edbdff0d044fa5de61af3f71fe0222 Mon Sep 17 00:00:00 2001 From: BastiMu Date: Sat, 31 May 2025 16:12:36 +0200 Subject: [PATCH 6/6] clag formatting --- include/clockWork.h | 7 +++++-- include/clockWork.hpp | 18 +++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/clockWork.h b/include/clockWork.h index 772ef951..cd445762 100644 --- a/include/clockWork.h +++ b/include/clockWork.h @@ -16,8 +16,11 @@ class ClockWork { uint16_t adcValue0Lux = 10; // Hier wird der niedrigste LDR-ADC Wert getrackt, // für eine dynamische offset korrektur bei 0 LUX - unsigned long buttonPressStart = 0; // Variable to store the time when the button was pressed - bool buttonPressed = false; // State of the button + + // Variable to store the time when the button was pressed + unsigned long buttonPressStart = 0; + // State of the button + bool buttonPressed = false; private: //------------------------------------------------------------------------------ diff --git a/include/clockWork.hpp b/include/clockWork.hpp index cc100815..585a3207 100644 --- a/include/clockWork.hpp +++ b/include/clockWork.hpp @@ -109,18 +109,18 @@ void ClockWork::loopGPIOinput() { // Read the mode button state int modeButtonState = digitalRead(G.modeButton); - + // Check if the button is pressed if (modeButtonState == LOW && !buttonPressed) { - buttonPressed = true; // Button is now pressed + buttonPressed = true; // Button is now pressed buttonPressStart = millis(); // Record the start time of the press } - + // Check if the button is released if (modeButtonState == HIGH && buttonPressed) { buttonPressed = false; // Button is released unsigned long pressDuration = millis() - buttonPressStart; - + if (pressDuration < 2000) { // Short press duration threshold (2000 ms) // set next mode in range 1 - 8 G.prog = (G.prog % 8) + 1; @@ -132,18 +132,18 @@ void ClockWork::loopGPIOinput() { // Read the speed button state int speedButtonState = digitalRead(G.speedButton); - + // Check if the button is pressed if (speedButtonState == LOW && !buttonPressed) { - buttonPressed = true; // Button is now pressed + buttonPressed = true; // Button is now pressed buttonPressStart = millis(); // Record the start time of the press } - + // Check if the button is released if (speedButtonState == HIGH && buttonPressed) { buttonPressed = false; // Button is released unsigned long pressDuration = millis() - buttonPressStart; - + if (pressDuration < 2000) { // Short press duration threshold (2000 ms) // Set brightness in range 10% - 100% with step 10% if (G.color[0].B == 1) { @@ -166,7 +166,7 @@ void ClockWork::loopGPIOinput() { } } - //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ iUhrType *ClockWork::getPointer(uint8_t type) { switch (type) {