Skip to content

Commit 492fd29

Browse files
committed
Merge remote-tracking branch 'origin/main' into mdev
2 parents 217ab27 + 1e104bd commit 492fd29

File tree

20 files changed

+7753
-4661
lines changed

20 files changed

+7753
-4661
lines changed

package-lock.json

Lines changed: 2942 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wled",
3-
"version": "0.14.0.1.1_MM",
3+
"version": "0.14.0.2.0_MM",
44
"description": "Tools for WLED project",
55
"main": "tools/cdata.js",
66
"directories": {

platformio.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@
4141
; MoonModules entries
4242
; ===================
4343

44-
; default_envs = esp32_4MB_min, esp32_4MB_max, esp32_16MB_max, esp8266_4MB_min, esp32_4MB_PSRAM_max, esp32S3_8MB_max, wemos_shield_esp32_4MB_max, wemos_shield_esp32_16MB_max
44+
; default_envs = esp32_4MB_min, esp32_4MB_max, esp32_16MB_max, esp8266_4MB_min, esp32_4MB_PSRAM_max, esp32S3_8MB_max, wemos_shield_esp32_4MB_max, wemos_shield_esp32_16MB_max, esp32_pico_4MB_max
4545
; default_envs = esp32_4MB_min
46-
default_envs = esp32_4MB_max ; recommended
46+
default_envs = esp32_4MB_max ; recommended default
4747
; default_envs = esp32_16MB_max
4848
; default_envs = esp8266_4MB_min
4949
; default_envs = esp32_4MB_PSRAM_max
5050
; default_envs = esp32S3_8MB_max
5151
; default_envs = wemos_shield_esp32_4MB_max
5252
; default_envs = wemos_shield_esp32_16MB_max
53+
; default_envs = esp32_pico_4MB_max
5354

5455

5556
src_dir = ./wled00

usermods/Animated_Staircase/Animated_Staircase.h

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Animated_Staircase : public Usermod {
6565
// The maximum number of configured segments.
6666
// Dynamically updated based on user configuration.
6767
byte maxSegmentId = 1;
68-
byte mainSegmentId = 0;
68+
byte minSegmentId = 0;
6969

7070
// These values are used by the API to read the
7171
// last sensor state, or trigger a sensor
@@ -91,8 +91,7 @@ class Animated_Staircase : public Usermod {
9191
static const char _topEchoCm[];
9292
static const char _bottomEchoCm[];
9393

94-
void publishMqtt(bool bottom, const char* state)
95-
{
94+
void publishMqtt(bool bottom, const char* state) {
9695
//Check if MQTT Connected, otherwise it will crash the 8266
9796
if (WLED_MQTT_CONNECTED){
9897
char subuf[64];
@@ -102,16 +101,11 @@ class Animated_Staircase : public Usermod {
102101
}
103102

104103
void updateSegments() {
105-
mainSegmentId = strip.getMainSegmentId();
106-
for (int i = 0; i < strip.getSegmentsNum(); i++) {
104+
for (int i = minSegmentId; i < maxSegmentId; i++) {
107105
Segment &seg = strip.getSegment(i);
108-
if (!seg.isActive()) {
109-
maxSegmentId = i - 1;
110-
break;
111-
}
106+
if (!seg.isActive()) continue; // skip gaps
112107
if (i >= onIndex && i < offIndex) {
113108
seg.setOption(SEG_OPTION_ON, true);
114-
115109
// We may need to copy mode and colors from segment 0 to make sure
116110
// changes are propagated even when the config is changed during a wipe
117111
// seg.setMode(mainsegment.mode);
@@ -120,8 +114,10 @@ class Animated_Staircase : public Usermod {
120114
seg.setOption(SEG_OPTION_ON, false);
121115
}
122116
// Always mark segments as "transitional", we are animating the staircase
123-
seg.setOption(SEG_OPTION_TRANSITIONAL, true);
117+
//seg.setOption(SEG_OPTION_TRANSITIONAL, true); // not needed anymore as setOption() does it
124118
}
119+
strip.trigger(); // force strip refresh
120+
stateChanged = true; // inform external devices/UI of change
125121
colorUpdated(CALL_MODE_DIRECT_CHANGE);
126122
}
127123

@@ -207,9 +203,9 @@ class Animated_Staircase : public Usermod {
207203
if (onIndex == offIndex) {
208204
// Position the indices for a correct on-swipe
209205
if (swipe == SWIPE_UP) {
210-
onIndex = mainSegmentId;
206+
onIndex = minSegmentId;
211207
} else {
212-
onIndex = maxSegmentId+1;
208+
onIndex = maxSegmentId;
213209
}
214210
offIndex = onIndex;
215211
}
@@ -221,7 +217,7 @@ class Animated_Staircase : public Usermod {
221217
}
222218

223219
void autoPowerOff() {
224-
if (on && ((millis() - lastSwitchTime) > on_time_ms)) {
220+
if ((millis() - lastSwitchTime) > on_time_ms) {
225221
// if sensors are still on, do nothing
226222
if (bottomSensorState || topSensorState) return;
227223

@@ -238,18 +234,20 @@ class Animated_Staircase : public Usermod {
238234
if ((millis() - lastTime) > segment_delay_ms) {
239235
lastTime = millis();
240236

237+
byte oldOn = onIndex;
238+
byte oldOff = offIndex;
241239
if (on) {
242240
// Turn on all segments
243-
onIndex = MAX(mainSegmentId, onIndex - 1);
244-
offIndex = MIN(maxSegmentId + 1, offIndex + 1);
241+
onIndex = MAX(minSegmentId, onIndex - 1);
242+
offIndex = MIN(maxSegmentId, offIndex + 1);
245243
} else {
246244
if (swipe == SWIPE_UP) {
247245
onIndex = MIN(offIndex, onIndex + 1);
248246
} else {
249247
offIndex = MAX(onIndex, offIndex - 1);
250248
}
251249
}
252-
updateSegments();
250+
if (oldOn != onIndex || oldOff != offIndex) updateSegments(); // reduce the number of updates to necessary ones
253251
}
254252
}
255253

@@ -287,16 +285,22 @@ class Animated_Staircase : public Usermod {
287285
pinMode(topPIRorTriggerPin, OUTPUT);
288286
pinMode(topEchoPin, INPUT);
289287
}
288+
onIndex = minSegmentId = strip.getMainSegmentId(); // it may not be the best idea to start with main segment as it may not be the first one
289+
offIndex = maxSegmentId = strip.getLastActiveSegmentId() + 1;
290+
291+
// shorten the strip transition time to be equal or shorter than segment delay
292+
transitionDelayTemp = transitionDelay = segment_delay_ms;
293+
strip.setTransition(segment_delay_ms/100);
294+
strip.trigger();
290295
} else {
291296
// Restore segment options
292-
for (int i = 0; i < strip.getSegmentsNum(); i++) {
297+
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
293298
Segment &seg = strip.getSegment(i);
294-
if (!seg.isActive()) {
295-
maxSegmentId = i - 1;
296-
break;
297-
}
299+
if (!seg.isActive()) continue; // skip vector gaps
298300
seg.setOption(SEG_OPTION_ON, true);
299301
}
302+
strip.trigger(); // force strip update
303+
stateChanged = true; // inform external dvices/UI of change
300304
colorUpdated(CALL_MODE_DIRECT_CHANGE);
301305
DEBUG_PRINTLN(F("Animated Staircase disabled."));
302306
}
@@ -332,8 +336,10 @@ class Animated_Staircase : public Usermod {
332336

333337
void loop() {
334338
if (!enabled || strip.isUpdating()) return;
339+
minSegmentId = strip.getMainSegmentId(); // it may not be the best idea to start with main segment as it may not be the first one
340+
maxSegmentId = strip.getLastActiveSegmentId() + 1;
335341
checkSensors();
336-
autoPowerOff();
342+
if (on) autoPowerOff();
337343
updateSwipe();
338344
}
339345

@@ -392,14 +398,16 @@ class Animated_Staircase : public Usermod {
392398
*/
393399
void readFromJsonState(JsonObject& root) {
394400
if (!initDone) return; // prevent crash on boot applyPreset()
401+
bool en = enabled;
395402
JsonObject staircase = root[FPSTR(_name)];
396403
if (!staircase.isNull()) {
397404
if (staircase[FPSTR(_enabled)].is<bool>()) {
398-
enabled = staircase[FPSTR(_enabled)].as<bool>();
405+
en = staircase[FPSTR(_enabled)].as<bool>();
399406
} else {
400407
String str = staircase[FPSTR(_enabled)]; // checkbox -> off or on
401-
enabled = (bool)(str!="off"); // off is guaranteed to be present
408+
en = (bool)(str!="off"); // off is guaranteed to be present
402409
}
410+
if (en != enabled) enable(en);
403411
readSensorsFromJson(staircase);
404412
DEBUG_PRINTLN(F("Staircase sensor state read from API."));
405413
}

usermods/PIR_sensor_switch/readme.md

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,7 @@ You can also use usermod's off timer instead of sensor's. In such case rotate th
2323

2424
## Usermod installation
2525

26-
1. Copy the file `usermod_PIR_sensor_switch.h` to the `wled00` directory.
27-
2. Register the usermod by adding `#include "usermod_PIR_sensor_switch.h"` in the top and `registerUsermod(new PIRsensorSwitch());` in the bottom of `usermods_list.cpp`.
28-
29-
Example **usermods_list.cpp**:
30-
31-
```cpp
32-
#include "wled.h"
33-
/*
34-
* Register your v2 usermods here!
35-
* (for v1 usermods using just usermod.cpp, you can ignore this file)
36-
*/
37-
38-
/*
39-
* Add/uncomment your usermod filename here (and once more below)
40-
* || || ||
41-
* \/ \/ \/
42-
*/
43-
//#include "usermod_v2_example.h"
44-
//#include "usermod_temperature.h"
45-
//#include "usermod_v2_empty.h"
46-
#include "usermod_PIR_sensor_switch.h"
47-
48-
void registerUsermods()
49-
{
50-
/*
51-
* Add your usermod class name here
52-
* || || ||
53-
* \/ \/ \/
54-
*/
55-
//usermods.add(new MyExampleUsermod());
56-
//usermods.add(new UsermodTemperature());
57-
//usermods.add(new UsermodRenameMe());
58-
usermods.add(new PIRsensorSwitch());
59-
60-
}
61-
```
62-
63-
**NOTE:** Usermod has been included in master branch of WLED so it can be compiled in directly just by defining `-D USERMOD_PIRSWITCH` and optionaly `-D PIR_SENSOR_PIN=16` to override default pin.
26+
**NOTE:** Usermod has been included in master branch of WLED so it can be compiled in directly just by defining `-D USERMOD_PIRSWITCH` and optionaly `-D PIR_SENSOR_PIN=16` to override default pin. You can also change the default off tim by adding `-D PIR_SENSOR_OFF_SEC=30`.
6427

6528
## API to enable/disable the PIR sensor from outside. For example from another usermod.
6629

@@ -121,4 +84,9 @@ Have fun - @gegu & @blazoncek
12184
12285
2021-11
12386
* Added information about dynamic configuration options
124-
* Added option to temporary enable/disble usermod from WLED UI (Info dialog)
87+
* Added option to temporary enable/disble usermod from WLED UI (Info dialog)
88+
89+
2022-11
90+
* Added compile time option for off timer.
91+
* Added Home Assistant autodiscovery MQTT broadcast.
92+
* Updated info on compiling.

0 commit comments

Comments
 (0)