From f922268af7fba7b035d5e8c1ca707ecce13ffd3f Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 11 Mar 2022 08:41:01 +0100 Subject: [PATCH 1/2] Remove unneeded brightness set in live Serial --- wled00/wled_serial.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 9a5c813dc..5dbcb01e7 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -174,7 +174,6 @@ void handleSerial() if (!realtimeOverride) setRealtimePixel(pixel++, red, green, blue, 0); if (--count > 0) state = AdaState::Data_Red; else { - if (!realtimeMode && bri == 0) strip.setBrightness(briLast, true); realtimeLock(realtimeTimeoutMs, REALTIME_MODE_ADALIGHT); if (!realtimeOverride) strip.show(); From 1b2134d7a804bd6a7b366f73764772235675ab63 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 11 Mar 2022 09:20:01 +0100 Subject: [PATCH 2/2] Add old blinds usermod --- usermods/RelayBlinds/index.htm | 76 ++++++++++++++++++++++++++++ usermods/RelayBlinds/presets.json | 1 + usermods/RelayBlinds/readme.md | 8 +++ usermods/RelayBlinds/usermod.cpp | 83 +++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 usermods/RelayBlinds/index.htm create mode 100644 usermods/RelayBlinds/presets.json create mode 100644 usermods/RelayBlinds/readme.md create mode 100644 usermods/RelayBlinds/usermod.cpp diff --git a/usermods/RelayBlinds/index.htm b/usermods/RelayBlinds/index.htm new file mode 100644 index 000000000..048cff016 --- /dev/null +++ b/usermods/RelayBlinds/index.htm @@ -0,0 +1,76 @@ + + + + + Blinds + + + + + + + + + + + + + + + + + +
+ + + +
+ + \ No newline at end of file diff --git a/usermods/RelayBlinds/presets.json b/usermods/RelayBlinds/presets.json new file mode 100644 index 000000000..95b587153 --- /dev/null +++ b/usermods/RelayBlinds/presets.json @@ -0,0 +1 @@ +{"0":{},"2":{"n":"▲","win":"U0=2"},"1":{"n":"▼","win":"U0=1"}} \ No newline at end of file diff --git a/usermods/RelayBlinds/readme.md b/usermods/RelayBlinds/readme.md new file mode 100644 index 000000000..0c3d2a0ba --- /dev/null +++ b/usermods/RelayBlinds/readme.md @@ -0,0 +1,8 @@ +# RelayBlinds usermod + +This simple usermod toggles two relay pins momentarily (default for 500ms) when `userVar0` is set. +This can be used to e.g. "push" the buttons of a window blinds motor controller. + +v1 usermod. Please replace usermod.cpp in the `wled00` directory with the one in this file. +You may upload `index.htm` to `[WLED-IP]/edit` to replace the default lighting UI with a simple Up/Down button one. +Also, a simple `presets.json` file is available, this makes the relay actions controllable via two presets to facilitate control e.g. via the default UI or Alexa. \ No newline at end of file diff --git a/usermods/RelayBlinds/usermod.cpp b/usermods/RelayBlinds/usermod.cpp new file mode 100644 index 000000000..ee61b0cce --- /dev/null +++ b/usermods/RelayBlinds/usermod.cpp @@ -0,0 +1,83 @@ +#include "wled.h" + +//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) + +//gets called once at boot. Do all initialization that doesn't depend on network here +void userSetup() +{ + +} + +//gets called every time WiFi is (re-)connected. Initialize own network interfaces here +void userConnected() +{ + +} + +/* + * Physical IO + */ +#define PIN_UP_RELAY 4 +#define PIN_DN_RELAY 5 +#define PIN_ON_TIME 500 +bool upActive = false, upActiveBefore = false, downActive = false, downActiveBefore = false; +unsigned long upStartTime = 0, downStartTime = 0; + +void handleRelay() +{ + //up and down relays + if (userVar0) { + upActive = true; + if (userVar0 == 1) { + upActive = false; + downActive = true; + } + userVar0 = 0; + } + + if (upActive) + { + if(!upActiveBefore) + { + pinMode(PIN_UP_RELAY, OUTPUT); + digitalWrite(PIN_UP_RELAY, LOW); + upActiveBefore = true; + upStartTime = millis(); + DEBUG_PRINTLN("UPA"); + } + if (millis()- upStartTime > PIN_ON_TIME) + { + upActive = false; + DEBUG_PRINTLN("UPN"); + } + } else if (upActiveBefore) + { + pinMode(PIN_UP_RELAY, INPUT); + upActiveBefore = false; + } + + if (downActive) + { + if(!downActiveBefore) + { + pinMode(PIN_DN_RELAY, OUTPUT); + digitalWrite(PIN_DN_RELAY, LOW); + downActiveBefore = true; + downStartTime = millis(); + } + if (millis()- downStartTime > PIN_ON_TIME) + { + downActive = false; + } + } else if (downActiveBefore) + { + pinMode(PIN_DN_RELAY, INPUT); + downActiveBefore = false; + } +} + +//loop. You can use "if (WLED_CONNECTED)" to check for successful connection +void userLoop() +{ + handleRelay(); +} \ No newline at end of file