Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mdev
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Nov 8, 2022
2 parents 217ab27 + 1e104bd commit 492fd29
Show file tree
Hide file tree
Showing 20 changed files with 7,753 additions and 4,661 deletions.
2,949 changes: 2,942 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wled",
"version": "0.14.0.1.1_MM",
"version": "0.14.0.2.0_MM",
"description": "Tools for WLED project",
"main": "tools/cdata.js",
"directories": {
Expand Down
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@
; MoonModules entries
; ===================

; 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
; 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
; default_envs = esp32_4MB_min
default_envs = esp32_4MB_max ; recommended
default_envs = esp32_4MB_max ; recommended default
; default_envs = esp32_16MB_max
; default_envs = esp8266_4MB_min
; default_envs = esp32_4MB_PSRAM_max
; default_envs = esp32S3_8MB_max
; default_envs = wemos_shield_esp32_4MB_max
; default_envs = wemos_shield_esp32_16MB_max
; default_envs = esp32_pico_4MB_max


src_dir = ./wled00
Expand Down
58 changes: 33 additions & 25 deletions usermods/Animated_Staircase/Animated_Staircase.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Animated_Staircase : public Usermod {
// The maximum number of configured segments.
// Dynamically updated based on user configuration.
byte maxSegmentId = 1;
byte mainSegmentId = 0;
byte minSegmentId = 0;

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

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

void updateSegments() {
mainSegmentId = strip.getMainSegmentId();
for (int i = 0; i < strip.getSegmentsNum(); i++) {
for (int i = minSegmentId; i < maxSegmentId; i++) {
Segment &seg = strip.getSegment(i);
if (!seg.isActive()) {
maxSegmentId = i - 1;
break;
}
if (!seg.isActive()) continue; // skip gaps
if (i >= onIndex && i < offIndex) {
seg.setOption(SEG_OPTION_ON, true);

// We may need to copy mode and colors from segment 0 to make sure
// changes are propagated even when the config is changed during a wipe
// seg.setMode(mainsegment.mode);
Expand All @@ -120,8 +114,10 @@ class Animated_Staircase : public Usermod {
seg.setOption(SEG_OPTION_ON, false);
}
// Always mark segments as "transitional", we are animating the staircase
seg.setOption(SEG_OPTION_TRANSITIONAL, true);
//seg.setOption(SEG_OPTION_TRANSITIONAL, true); // not needed anymore as setOption() does it
}
strip.trigger(); // force strip refresh
stateChanged = true; // inform external devices/UI of change
colorUpdated(CALL_MODE_DIRECT_CHANGE);
}

Expand Down Expand Up @@ -207,9 +203,9 @@ class Animated_Staircase : public Usermod {
if (onIndex == offIndex) {
// Position the indices for a correct on-swipe
if (swipe == SWIPE_UP) {
onIndex = mainSegmentId;
onIndex = minSegmentId;
} else {
onIndex = maxSegmentId+1;
onIndex = maxSegmentId;
}
offIndex = onIndex;
}
Expand All @@ -221,7 +217,7 @@ class Animated_Staircase : public Usermod {
}

void autoPowerOff() {
if (on && ((millis() - lastSwitchTime) > on_time_ms)) {
if ((millis() - lastSwitchTime) > on_time_ms) {
// if sensors are still on, do nothing
if (bottomSensorState || topSensorState) return;

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

byte oldOn = onIndex;
byte oldOff = offIndex;
if (on) {
// Turn on all segments
onIndex = MAX(mainSegmentId, onIndex - 1);
offIndex = MIN(maxSegmentId + 1, offIndex + 1);
onIndex = MAX(minSegmentId, onIndex - 1);
offIndex = MIN(maxSegmentId, offIndex + 1);
} else {
if (swipe == SWIPE_UP) {
onIndex = MIN(offIndex, onIndex + 1);
} else {
offIndex = MAX(onIndex, offIndex - 1);
}
}
updateSegments();
if (oldOn != onIndex || oldOff != offIndex) updateSegments(); // reduce the number of updates to necessary ones
}
}

Expand Down Expand Up @@ -287,16 +285,22 @@ class Animated_Staircase : public Usermod {
pinMode(topPIRorTriggerPin, OUTPUT);
pinMode(topEchoPin, INPUT);
}
onIndex = minSegmentId = strip.getMainSegmentId(); // it may not be the best idea to start with main segment as it may not be the first one
offIndex = maxSegmentId = strip.getLastActiveSegmentId() + 1;

// shorten the strip transition time to be equal or shorter than segment delay
transitionDelayTemp = transitionDelay = segment_delay_ms;
strip.setTransition(segment_delay_ms/100);
strip.trigger();
} else {
// Restore segment options
for (int i = 0; i < strip.getSegmentsNum(); i++) {
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
Segment &seg = strip.getSegment(i);
if (!seg.isActive()) {
maxSegmentId = i - 1;
break;
}
if (!seg.isActive()) continue; // skip vector gaps
seg.setOption(SEG_OPTION_ON, true);
}
strip.trigger(); // force strip update
stateChanged = true; // inform external dvices/UI of change
colorUpdated(CALL_MODE_DIRECT_CHANGE);
DEBUG_PRINTLN(F("Animated Staircase disabled."));
}
Expand Down Expand Up @@ -332,8 +336,10 @@ class Animated_Staircase : public Usermod {

void loop() {
if (!enabled || strip.isUpdating()) return;
minSegmentId = strip.getMainSegmentId(); // it may not be the best idea to start with main segment as it may not be the first one
maxSegmentId = strip.getLastActiveSegmentId() + 1;
checkSensors();
autoPowerOff();
if (on) autoPowerOff();
updateSwipe();
}

Expand Down Expand Up @@ -392,14 +398,16 @@ class Animated_Staircase : public Usermod {
*/
void readFromJsonState(JsonObject& root) {
if (!initDone) return; // prevent crash on boot applyPreset()
bool en = enabled;
JsonObject staircase = root[FPSTR(_name)];
if (!staircase.isNull()) {
if (staircase[FPSTR(_enabled)].is<bool>()) {
enabled = staircase[FPSTR(_enabled)].as<bool>();
en = staircase[FPSTR(_enabled)].as<bool>();
} else {
String str = staircase[FPSTR(_enabled)]; // checkbox -> off or on
enabled = (bool)(str!="off"); // off is guaranteed to be present
en = (bool)(str!="off"); // off is guaranteed to be present
}
if (en != enabled) enable(en);
readSensorsFromJson(staircase);
DEBUG_PRINTLN(F("Staircase sensor state read from API."));
}
Expand Down
46 changes: 7 additions & 39 deletions usermods/PIR_sensor_switch/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,7 @@ You can also use usermod's off timer instead of sensor's. In such case rotate th

## Usermod installation

1. Copy the file `usermod_PIR_sensor_switch.h` to the `wled00` directory.
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`.

Example **usermods_list.cpp**:

```cpp
#include "wled.h"
/*
* Register your v2 usermods here!
* (for v1 usermods using just usermod.cpp, you can ignore this file)
*/

/*
* Add/uncomment your usermod filename here (and once more below)
* || || ||
* \/ \/ \/
*/
//#include "usermod_v2_example.h"
//#include "usermod_temperature.h"
//#include "usermod_v2_empty.h"
#include "usermod_PIR_sensor_switch.h"

void registerUsermods()
{
/*
* Add your usermod class name here
* || || ||
* \/ \/ \/
*/
//usermods.add(new MyExampleUsermod());
//usermods.add(new UsermodTemperature());
//usermods.add(new UsermodRenameMe());
usermods.add(new PIRsensorSwitch());

}
```

**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.
**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`.

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

Expand Down Expand Up @@ -121,4 +84,9 @@ Have fun - @gegu & @blazoncek
2021-11
* Added information about dynamic configuration options
* Added option to temporary enable/disble usermod from WLED UI (Info dialog)
* Added option to temporary enable/disble usermod from WLED UI (Info dialog)
2022-11
* Added compile time option for off timer.
* Added Home Assistant autodiscovery MQTT broadcast.
* Updated info on compiling.
Loading

0 comments on commit 492fd29

Please sign in to comment.