
## 💾 Compatible hardware
-See [here](https://kno.wled.ge/basics/compatible-hardware)!
+See [here](https://mm.kno.wled.ge/basics/compatible-hardware)!
## ✌️ Other
Licensed under the MIT license
-Credits [here](https://kno.wled.ge/about/contributors/)!
+Credits [here](https://mm.kno.wled.ge/about/contributors/)!
Join the Discord server to discuss everything about WLED!
Check out the WLED [Discourse forum](https://wled.discourse.group)!
-You can also send me mails to [dev.aircoookie@gmail.com](mailto:dev.aircoookie@gmail.com), but please only do so if you want to talk to me privately.
-If WLED really brightens up your every day, you can [](https://paypal.me/aircoookie)
+
+You can also send me mails to [dev.aircoookie@gmail.com](mailto:dev.aircoookie@gmail.com), but please, only do so if you want to talk to me privately.
+
+If WLED really brightens up your day, you can [](https://paypal.me/aircoookie)
*Disclaimer:*
-If you are sensitive to photosensitive epilepsy it is not recommended that you use this software.
-In case you still want to try, don't use strobe, lighting or noise modes or high effect speed settings.
+
+If you are prone to photosensitive epilepsy, we recommended you do **not** use this software.
+If you still want to try, don't use strobe, lighting or noise modes or high effect speed settings.
+
As per the MIT license, I assume no liability for any damage to you or any other person or equipment.
diff --git a/requirements.txt b/requirements.txt
index 820ecdef..e484d7bc 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,7 +14,7 @@ async-timeout==4.0.2
# via zeroconf
bottle==0.12.23
# via platformio
-certifi==2022.6.15
+certifi==2022.12.7
# via requests
charset-normalizer==2.1.1
# via requests
@@ -23,9 +23,7 @@ click==8.1.3
# platformio
# uvicorn
colorama==0.4.5
- # via
- # click
- # platformio
+ # via platformio
h11==0.13.0
# via
# uvicorn
@@ -58,8 +56,6 @@ starlette==0.20.4
# via platformio
tabulate==0.8.10
# via platformio
-typing-extensions==4.3.0
- # via starlette
urllib3==1.26.11
# via requests
uvicorn==0.18.2
diff --git a/tools/ESP32-Chip_info.hpp b/tools/ESP32-Chip_info.hpp
index f8563ab8..1e6fad8f 100644
--- a/tools/ESP32-Chip_info.hpp
+++ b/tools/ESP32-Chip_info.hpp
@@ -545,12 +545,16 @@ void showRealSpeed() {
Serial.print("FLASH SIZE (magic byte): "); Serial.print(ESP.getFlashChipSize() / (1024.0 * 1024), 2); Serial.println(" MB");
Serial.print("FLASH MODE (magic byte): "); Serial.print(ESP.getFlashChipMode()); Serial.println(" ; 0=QIO, 1=QOUT, 2=DIO, 3=DOUT or other\n");
+ Serial.flush();
Serial.print("FLASH CHIP ID: 0x"); Serial.println(my_ESP_getFlashChipId(), HEX);
- Serial.print("FLASH CHIP FREQ: "); Serial.print(my_ESP_getFlashChipSpeed() / 1000000.0, 1); Serial.println(" MHz");
+#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
+ //Serial.print("FLASH CHIP FREQ: "); Serial.print(my_ESP_getFlashChipSpeed() / 1000000.0, 1); Serial.println(" MHz"); // this seems to crash on -S2
+#endif
Serial.print("FLASH REAL SIZE: "); Serial.print(my_ESP_getFlashChipRealSize() / (1024.0 * 1024), 2); Serial.println(" MB");
Serial.print("FLASH REAL MODE: "); Serial.println(my_ESP_getFlashChipMode());
Serial.println(F("\n------------------------------------"));
+ Serial.flush();
Serial.print( "RAM HEAP SIZE: "); Serial.print(ESP.getHeapSize() / 1024.0, 2); Serial.println(" KB");
Serial.print( " FREE RAM: "); Serial.print(ESP.getFreeHeap() / 1024.0, 2); Serial.println(" KB");
Serial.print( " MAX RAM alloc: "); Serial.print(ESP.getMaxAllocHeap() / 1024.0, 2); Serial.println(" KB");
@@ -566,6 +570,7 @@ void showRealSpeed() {
Serial.println();
show_psram_info_part2();
}
+ Serial.flush();
#endif
Serial.println();
diff --git a/tools/cdata.js b/tools/cdata.js
index d01c3e35..55b04e13 100644
--- a/tools/cdata.js
+++ b/tools/cdata.js
@@ -134,7 +134,7 @@ function writeHtmlGzipped(sourceFile, resultFile, page) {
* Binary array for the Web UI.
* gzip is used for smaller size and improved speeds.
*
- * Please see https://kno.wled.ge/advanced/custom-features/#changing-web-ui
+ * Please see https://mm.kno.wled.ge/advanced/custom-features/#changing-web-ui
* to find out how to easily modify the web UI source!
*/
@@ -199,7 +199,7 @@ function writeChunks(srcDir, specs, resultFile) {
let src = `/*
* More web UI HTML source arrays.
* This file is auto generated, please don't make any changes manually.
- * Instead, see https://kno.wled.ge/advanced/custom-features/#changing-web-ui
+ * Instead, see https://mm.kno.wled.ge/advanced/custom-features/#changing-web-ui
* to find out how to easily modify the web UI source!
*/
`;
@@ -220,6 +220,7 @@ function writeChunks(srcDir, specs, resultFile) {
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
writeHtmlGzipped("wled00/data/simple.htm", "wled00/html_simple.h", 'simple');
+writeHtmlGzipped("wled00/data/pixart/pixart.htm", "wled00/html_pixart.h", 'pixart');
/*
writeChunks(
"wled00/data",
@@ -399,6 +400,13 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
method: "gzip",
filter: "html-minify",
},
+ //WLEDMM
+ {
+ file: "peek.js",
+ name: "PAGE_peekJs",
+ method: "gzip",
+ filter: "js-minify",
+ },
{
file: "404.htm",
name: "PAGE_404",
diff --git a/tools/partitions-4MB-tinyuf2_spiffs.csv b/tools/partitions-4MB-tinyuf2_spiffs.csv
new file mode 100644
index 00000000..4979c127
--- /dev/null
+++ b/tools/partitions-4MB-tinyuf2_spiffs.csv
@@ -0,0 +1,11 @@
+# ESP-IDF Partition Table
+# Name, Type, SubType, Offset, Size, Flags
+# bootloader.bin,, 0x1000, 32K
+# partition table, 0x8000, 4K
+
+nvs, data, nvs, 0x9000, 20K,
+otadata, data, ota, 0xe000, 8K,
+ota_0, 0, ota_0, 0x10000, 1408K,
+ota_1, 0, ota_1, 0x170000, 1408K,
+uf2, app, factory,0x2d0000, 256K,
+spiffs, data, spiffs, 0x310000, 960K,
diff --git a/usermods/ADS1115_v2/readme.md b/usermods/ADS1115_v2/readme.md
index 9b778809..44092bc8 100644
--- a/usermods/ADS1115_v2/readme.md
+++ b/usermods/ADS1115_v2/readme.md
@@ -2,7 +2,7 @@
This usermod will read from an ADS1115 ADC. The voltages are displayed in the Info section of the web UI.
-Configuration is all completed via the Usermod menu. There are no settings to set in code!
+Configuration is performed via the Usermod menu. There are no parameters to set in code!
## Installation
diff --git a/usermods/Analog_Clock/Analog_Clock.h b/usermods/Analog_Clock/Analog_Clock.h
index b8f44f78..596f0acb 100644
--- a/usermods/Analog_Clock/Analog_Clock.h
+++ b/usermods/Analog_Clock/Analog_Clock.h
@@ -56,7 +56,7 @@ private:
// runtime
bool initDone = false;
- uint32_t lastOverlayDraw = 0;
+ uint32_t lastOverlayDraw = 0;
void validateAndUpdate() {
mainSegment.validateAndUpdate();
@@ -110,9 +110,9 @@ private:
static inline uint32_t qadd32(uint32_t c1, uint32_t c2) {
return RGBW32(
- qadd8(R(c1), R(c2)),
- qadd8(G(c1), G(c2)),
- qadd8(B(c1), B(c2)),
+ qadd8(R(c1), R(c2)),
+ qadd8(G(c1), G(c2)),
+ qadd8(B(c1), B(c2)),
qadd8(W(c1), W(c2))
);
}
@@ -166,7 +166,7 @@ public:
double secondP = second(localTime) / 60.0;
double minuteP = minute(localTime) / 60.0;
double hourP = (hour(localTime) % 12) / 12.0 + minuteP / 12.0;
-
+
if (hourMarksEnabled) {
for (int Led = 0; Led <= 55; Led = Led + 5)
{
@@ -174,7 +174,7 @@ public:
setPixelColor(hourmarkled, hourMarkColor);
}
}
-
+
if (secondsEnabled) {
int16_t secondLed = adjustToSegment(secondP, secondsSegment);
@@ -203,45 +203,45 @@ public:
void addToConfig(JsonObject& root) override {
validateAndUpdate();
- JsonObject top = root.createNestedObject("Analog Clock");
- top["Overlay Enabled"] = enabled;
- top["First LED (Main Ring)"] = mainSegment.firstLed;
- top["Last LED (Main Ring)"] = mainSegment.lastLed;
- top["Center/12h LED (Main Ring)"] = mainSegment.centerLed;
- top["Hour Marks Enabled"] = hourMarksEnabled;
- top["Hour Mark Color (RRGGBB)"] = colorToHexString(hourMarkColor);
- top["Hour Color (RRGGBB)"] = colorToHexString(hourColor);
- top["Minute Color (RRGGBB)"] = colorToHexString(minuteColor);
- top["Show Seconds"] = secondsEnabled;
- top["First LED (Seconds Ring)"] = secondsSegment.firstLed;
- top["Last LED (Seconds Ring)"] = secondsSegment.lastLed;
- top["Center/12h LED (Seconds Ring)"] = secondsSegment.centerLed;
- top["Second Color (RRGGBB)"] = colorToHexString(secondColor);
- top["Seconds Effect (0-1)"] = secondsEffect;
- top["Blend Colors"] = blendColors;
+ JsonObject top = root.createNestedObject(F("Analog Clock"));
+ top[F("Overlay Enabled")] = enabled;
+ top[F("First LED (Main Ring)")] = mainSegment.firstLed;
+ top[F("Last LED (Main Ring)")] = mainSegment.lastLed;
+ top[F("Center/12h LED (Main Ring)")] = mainSegment.centerLed;
+ top[F("Hour Marks Enabled")] = hourMarksEnabled;
+ top[F("Hour Mark Color (RRGGBB)")] = colorToHexString(hourMarkColor);
+ top[F("Hour Color (RRGGBB)")] = colorToHexString(hourColor);
+ top[F("Minute Color (RRGGBB)")] = colorToHexString(minuteColor);
+ top[F("Show Seconds")] = secondsEnabled;
+ top[F("First LED (Seconds Ring)")] = secondsSegment.firstLed;
+ top[F("Last LED (Seconds Ring)")] = secondsSegment.lastLed;
+ top[F("Center/12h LED (Seconds Ring)")] = secondsSegment.centerLed;
+ top[F("Second Color (RRGGBB)")] = colorToHexString(secondColor);
+ top[F("Seconds Effect (0-1)")] = secondsEffect;
+ top[F("Blend Colors")] = blendColors;
}
bool readFromConfig(JsonObject& root) override {
- JsonObject top = root["Analog Clock"];
+ JsonObject top = root[F("Analog Clock")];
bool configComplete = !top.isNull();
String color;
- configComplete &= getJsonValue(top["Overlay Enabled"], enabled, false);
- configComplete &= getJsonValue(top["First LED (Main Ring)"], mainSegment.firstLed, 0);
- configComplete &= getJsonValue(top["Last LED (Main Ring)"], mainSegment.lastLed, 59);
- configComplete &= getJsonValue(top["Center/12h LED (Main Ring)"], mainSegment.centerLed, 0);
- configComplete &= getJsonValue(top["Hour marks Enabled"], hourMarksEnabled, false);
- configComplete &= getJsonValue(top["Hour mark Color (RRGGBB)"], color, "FF0000") && hexStringToColor(color, hourMarkColor, 0x0000FF);
- configComplete &= getJsonValue(top["Hour Color (RRGGBB)"], color, "0000FF") && hexStringToColor(color, hourColor, 0x0000FF);
- configComplete &= getJsonValue(top["Minute Color (RRGGBB)"], color, "00FF00") && hexStringToColor(color, minuteColor, 0x00FF00);
- configComplete &= getJsonValue(top["Show Seconds"], secondsEnabled, true);
- configComplete &= getJsonValue(top["First LED (Seconds Ring)"], secondsSegment.firstLed, 0);
- configComplete &= getJsonValue(top["Last LED (Seconds Ring)"], secondsSegment.lastLed, 59);
- configComplete &= getJsonValue(top["Center/12h LED (Seconds Ring)"], secondsSegment.centerLed, 0);
- configComplete &= getJsonValue(top["Second Color (RRGGBB)"], color, "FF0000") && hexStringToColor(color, secondColor, 0xFF0000);
- configComplete &= getJsonValue(top["Seconds Effect (0-1)"], secondsEffect, 0);
- configComplete &= getJsonValue(top["Blend Colors"], blendColors, true);
+ configComplete &= getJsonValue(top[F("Overlay Enabled")], enabled, false);
+ configComplete &= getJsonValue(top[F("First LED (Main Ring)")], mainSegment.firstLed, 0);
+ configComplete &= getJsonValue(top[F("Last LED (Main Ring)")], mainSegment.lastLed, 59);
+ configComplete &= getJsonValue(top[F("Center/12h LED (Main Ring)")], mainSegment.centerLed, 0);
+ configComplete &= getJsonValue(top[F("Hour Marks Enabled")], hourMarksEnabled, false);
+ configComplete &= getJsonValue(top[F("Hour Mark Color (RRGGBB)")], color, F("161616")) && hexStringToColor(color, hourMarkColor, 0x161616);
+ configComplete &= getJsonValue(top[F("Hour Color (RRGGBB)")], color, F("0000FF")) && hexStringToColor(color, hourColor, 0x0000FF);
+ configComplete &= getJsonValue(top[F("Minute Color (RRGGBB)")], color, F("00FF00")) && hexStringToColor(color, minuteColor, 0x00FF00);
+ configComplete &= getJsonValue(top[F("Show Seconds")], secondsEnabled, true);
+ configComplete &= getJsonValue(top[F("First LED (Seconds Ring)")], secondsSegment.firstLed, 0);
+ configComplete &= getJsonValue(top[F("Last LED (Seconds Ring)")], secondsSegment.lastLed, 59);
+ configComplete &= getJsonValue(top[F("Center/12h LED (Seconds Ring)")], secondsSegment.centerLed, 0);
+ configComplete &= getJsonValue(top[F("Second Color (RRGGBB)")], color, F("FF0000")) && hexStringToColor(color, secondColor, 0xFF0000);
+ configComplete &= getJsonValue(top[F("Seconds Effect (0-1)")], secondsEffect, 0);
+ configComplete &= getJsonValue(top[F("Blend Colors")], blendColors, true);
if (initDone) {
validateAndUpdate();
@@ -253,4 +253,4 @@ public:
uint16_t getId() override {
return USERMOD_ID_ANALOG_CLOCK;
}
-};
\ No newline at end of file
+};
diff --git a/usermods/Animated_Staircase/Animated_Staircase.h b/usermods/Animated_Staircase/Animated_Staircase.h
index 1ef2c959..20c240c7 100644
--- a/usermods/Animated_Staircase/Animated_Staircase.h
+++ b/usermods/Animated_Staircase/Animated_Staircase.h
@@ -92,12 +92,14 @@ class Animated_Staircase : public Usermod {
static const char _bottomEchoCm[];
void publishMqtt(bool bottom, const char* state) {
+#ifndef WLED_DISABLE_MQTT
//Check if MQTT Connected, otherwise it will crash the 8266
if (WLED_MQTT_CONNECTED){
char subuf[64];
sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom);
mqtt->publish(subuf, 0, false, state);
}
+#endif
}
void updateSegments() {
@@ -345,6 +347,7 @@ class Animated_Staircase : public Usermod {
uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }
+#ifndef WLED_DISABLE_MQTT
/**
* handling of MQTT message
* topic only contains stripped topic (part after /wled/MAC)
@@ -382,6 +385,7 @@ class Animated_Staircase : public Usermod {
mqtt->subscribe(subuf, 0);
}
}
+#endif
void addToJsonState(JsonObject& root) {
JsonObject staircase = root[FPSTR(_name)];
@@ -414,6 +418,8 @@ class Animated_Staircase : public Usermod {
}
void appendConfigData() {
+ oappend(SET_F("addHB('staircase');"));
+
//oappend(SET_F("dd=addDropdown('staircase','selectfield');"));
//oappend(SET_F("addOption(dd,'1st value',0);"));
//oappend(SET_F("addOption(dd,'2nd value',1);"));
diff --git a/usermods/Animated_Staircase/README.md b/usermods/Animated_Staircase/README.md
index 2641e676..61c1cb2d 100644
--- a/usermods/Animated_Staircase/README.md
+++ b/usermods/Animated_Staircase/README.md
@@ -1,14 +1,14 @@
# Usermod Animated Staircase
-This usermod makes your staircase look cool by switching it on with an animation. It uses
+This usermod makes your staircase look cool by illuminating it with an animation. It uses
PIR or ultrasonic sensors at the top and bottom of your stairs to:
-- Light up the steps in your walking direction, leading the way.
+- Light up the steps in the direction you're walking.
- Switch off the steps after you, in the direction of the last detected movement.
- Always switch on when one of the sensors detects movement, even if an effect
- is still running. It can therewith handle multiple people on the stairs gracefully.
+ is still running. It can gracefully handle multiple people on the stairs.
The Animated Staircase can be controlled by the WLED API. Change settings such as
-speed, on/off time and distance settings by sending an HTTP request, see below.
+speed, on/off time and distance by sending an HTTP request, see below.
## WLED integration
To include this usermod in your WLED setup, you have to be able to [compile WLED from source](https://github.com/Aircoookie/WLED/wiki/Compiling-WLED).
@@ -20,17 +20,16 @@ Edit `usermods_list.cpp`:
2. add `#include "../usermods/Animated_Staircase/Animated_Staircase.h"` to the top of the file
3. add `usermods.add(new Animated_Staircase());` to the end of the `void registerUsermods()` function.
-You can configure usermod using Usermods settings page.
-Please enter GPIO pins for PIR sensors or ultrasonic sensor (trigger and echo).
+You can configure usermod using the Usermods settings page.
+Please enter GPIO pins for PIR or ultrasonic sensors (trigger and echo).
If you use PIR sensor enter -1 for echo pin.
-Maximum distance for ultrasonic sensor can be configured as a time needed for echo (see below).
+Maximum distance for ultrasonic sensor can be configured as the time needed for an echo (see below).
## Hardware installation
-1. Stick the LED strip under each step of the stairs.
-2. Connect the ESP8266 pin D4 or ESP32 pin D2 to the first LED data pin at the bottom step
- of your stairs.
+1. Attach the LED strip to each step of the stairs.
+2. Connect the ESP8266 pin D4 or ESP32 pin D2 to the first LED data pin at the bottom step.
3. Connect the data-out pin at the end of each strip per step to the data-in pin on the
- other end of the next step, creating one large virtual LED strip.
+ next step, creating one large virtual LED strip.
4. Mount sensors of choice at the bottom and top of the stairs and connect them to the ESP.
5. To make sure all LEDs get enough power and have your staircase lighted evenly, power each
step from one side, using at least AWG14 or 2.5mm^2 cable. Don't connect them serial as you
@@ -62,7 +61,7 @@ or remove them and put everything on one line.
To read the current settings, open a browser to `http://xxx.xxx.xxx.xxx/json/state` (use your WLED
device IP address). The device will respond with a json object containing all WLED settings.
-The staircase settings and sensor states are inside the WLED status element:
+The staircase settings and sensor states are inside the WLED "state" element:
```json
{
@@ -70,14 +69,14 @@ The staircase settings and sensor states are inside the WLED status element:
"staircase": {
"enabled": true,
"bottom-sensor": false,
- "tops-ensor": false
+ "top-sensor": false
},
}
```
### Enable/disable the usermod
By disabling the usermod you will be able to keep the LED's on, independent from the sensor
-activity. This enables to play with the lights without the usermod switching them on or off.
+activity. This enables you to play with the lights without the usermod switching them on or off.
To disable the usermod:
@@ -92,17 +91,17 @@ To enable the usermod again, use `"enabled":true`.
Alternatively you can use _Usermod_ Settings page where you can change other parameters as well.
### Changing animation parameters and detection range of the ultrasonic HC-SR04 sensor
-Using _Usermod_ Settings page you can define different usermod parameters, includng sensor pins, delay between segment activation and so on.
+Using _Usermod_ Settings page you can define different usermod parameters, includng sensor pins, delay between segment activation etc.
When an ultrasonic sensor is enabled you can enter maximum detection distance in centimeters separately for top and bottom sensors.
-**Please note:** that using an HC-SR04 sensor, particularly when detecting echos at longer
-distances creates delays in the WLED software, and _might_ introduce timing hickups in your animations or
+**Please note:** using an HC-SR04 sensor, particularly when detecting echos at longer
+distances creates delays in the WLED software, _might_ introduce timing hiccups in your animation or
a less responsive web interface. It is therefore advised to keep the detection distance as short as possible.
### Animation triggering through the API
-Instead of stairs activation by one of the sensors, you can also trigger the animation through
-the API. To simulate triggering the bottom sensor, use:
+In addition to activation by one of the stair sensors, you can also trigger the animation manually
+via the API. To simulate triggering the bottom sensor, use:
```bash
curl -X POST -H "Content-Type: application/json" \
@@ -110,7 +109,7 @@ curl -X POST -H "Content-Type: application/json" \
xxx.xxx.xxx.xxx/json/state
```
-Likewise, to trigger the top sensor, use:
+Likewise, to trigger the top sensor:
```bash
curl -X POST -H "Content-Type: application/json" \
@@ -119,7 +118,7 @@ curl -X POST -H "Content-Type: application/json" \
```
**MQTT**
You can publish a message with either `up` or `down` on topic `/swipe` to trigger animation.
-You can also use `on` or `off` for enabling or disabling usermod.
+You can also use `on` or `off` for enabling or disabling the usermod.
Have fun with this usermod.
+
+
+
+
+
+
-
-
-
-
-------
/ A / 0 - EDCGFAB
diff --git a/usermods/seven_segment_display/usermod_v2_seven_segment_display.h b/usermods/seven_segment_display/usermod_v2_seven_segment_display.h
index 5c0022e0..e5b726e5 100644
--- a/usermods/seven_segment_display/usermod_v2_seven_segment_display.h
+++ b/usermods/seven_segment_display/usermod_v2_seven_segment_display.h
@@ -1,3 +1,7 @@
+#ifndef WLED_ENABLE_MQTT
+#error "This user mod requires MQTT to be enabled."
+#endif
+
#pragma once
#include "wled.h"
diff --git a/usermods/seven_segment_display_reloaded/readme.md b/usermods/seven_segment_display_reloaded/readme.md
index 09479754..d373a7ee 100644
--- a/usermods/seven_segment_display_reloaded/readme.md
+++ b/usermods/seven_segment_display_reloaded/readme.md
@@ -1,6 +1,6 @@
# Seven Segment Display Reloaded
-Usermod that uses the overlay feature to create a configurable seven segment display.
+Uses the overlay feature to create a configurable seven segment display.
Optimized for maximum configurability and use with seven segment clocks by parallyze (https://www.instructables.com/member/parallyze/instructables/)
Very loosely based on the existing usermod "seven segment display".
@@ -12,26 +12,26 @@ Add the compile-time option `-D USERMOD_SSDR` to your `platformio.ini` (or `plat
For the auto brightness option, the usermod SN_Photoresistor has to be installed as well. See SN_Photoresistor/readme.md for instructions.
## Settings
-All settings can be controlled the usermod setting page.
+All settings can be controlled via the usermod settings page.
Part of the settings can be controlled through MQTT with a raw payload or through a json request to /json/state.
### enabled
-Enables/disables this overlay usermod
+Enables/disables this usermod
### inverted
-Enables the inverted mode in which the background should be enabled and the digits should be black (leds off)
+Enables the inverted mode in which the background should be enabled and the digits should be black (LEDs off)
### Colon-blinking
Enables the blinking colon(s) if they are defined
### enable-auto-brightness
-Enables the auto brightness feature. Can be only used with the usermod SN_Photoresistor installed.
+Enables the auto brightness feature. Can be used only when the usermod SN_Photoresistor is installed.
### auto-brightness-min / auto-brightness-max
The lux value calculated from usermod SN_Photoresistor will be mapped to the values defined here.
-The mapping is 0 - 1000 lux will be mapped to auto-brightness-min - auto-brightness-max
+The mapping, 0 - 1000 lux, will be mapped to auto-brightness-min and auto-brightness-max
-The mA current protection of WLED will override the calculated value if it is too high.
+WLED current protection will override the calculated value if it is too high.
### Display-Mask
Defines the type of the time/date display.
@@ -61,7 +61,7 @@ See following example for usage.
## Example
-Example for Leds definition
+Example of an LED definition:
```
< A >
/\ /\
@@ -74,15 +74,15 @@ E C
< D >
```
-Leds or Range of Leds are seperated by a comma ","
+LEDs or Range of LEDs are separated by a comma ","
-Segments are seperated by a semicolon ";" and are read as A;B;C;D;E;F;G
+Segments are separated by a semicolon ";" and are read as A;B;C;D;E;F;G
-Digits are seperated by colon ":" -> A;B;C;D;E;F;G:A;B;C;D;E;F;G
+Digits are separated by colon ":" -> A;B;C;D;E;F;G:A;B;C;D;E;F;G
Ranges are defined as lower to higher (lower first)
-For example, an clock definition for the following clock (https://www.instructables.com/Lazy-7-Quick-Build-Edition/) is
+For example, a clock definition for the following clock (https://www.instructables.com/Lazy-7-Quick-Build-Edition/) is
- hour "59,46;47-48;50-51;52-53;54-55;57-58;49,56:0,13;1-2;4-5;6-7;8-9;11-12;3,10"
@@ -96,18 +96,18 @@ or
depending on the orientation.
-# The example detailed:
+# Example details:
hour "59,46;47-48;50-51;52-53;54-55;57-58;49,56:0,13;1-2;4-5;6-7;8-9;11-12;3,10"
-there are two digits seperated by ":"
+there are two digits separated by ":"
- 59,46;47-48;50-51;52-53;54-55;57-58;49,56
- 0,13;1-2;4-5;6-7;8-9;11-12;3,10
In the first digit,
-the **segment A** consists of the leds number **59 and 46**., **segment B** consists of the leds number **47, 48** and so on
+the **segment A** consists of the LEDs number **59 and 46**., **segment B** consists of the LEDs number **47, 48** and so on
-The second digit starts again with **segment A** and leds **0 and 13**, **segment B** consists of the leds number **1 and 2** and so on
+The second digit starts again with **segment A** and LEDs **0 and 13**, **segment B** consists of the LEDs number **1 and 2** and so on
### first digit of the hour
- Segment A: 59, 46
@@ -126,4 +126,4 @@ The second digit starts again with **segment A** and leds **0 and 13**, **segmen
- Segment D: 6, 7
- Segment E: 8, 9
- Segment F: 11, 12
-- Segment G: 3, 10
\ No newline at end of file
+- Segment G: 3, 10
diff --git a/usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h b/usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h
index b1a271a6..27977405 100644
--- a/usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h
+++ b/usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h
@@ -1,3 +1,7 @@
+#ifndef WLED_ENABLE_MQTT
+#error "This user mod requires MQTT to be enabled."
+#endif
+
#pragma once
#include "wled.h"
diff --git a/usermods/sht/readme.md b/usermods/sht/readme.md
new file mode 100644
index 00000000..0337805b
--- /dev/null
+++ b/usermods/sht/readme.md
@@ -0,0 +1,56 @@
+# SHT
+Usermod to support various SHT i2c sensors like the SHT30, SHT31, SHT35 and SHT85
+
+## Requirements
+* "SHT85" by Rob Tillaart, v0.2 or higher: https://github.com/RobTillaart/SHT85
+
+## Usermod installation
+Simply copy the below block (build task) to your `platformio_override.ini` and compile WLED using this new build task. Or use an existing one, add the buildflag `-D USERMOD_SHT` and the below library dependencies.
+
+ESP32:
+```
+[env:custom_esp32dev_usermod_sht]
+extends = env:esp32dev
+build_flags = ${common.build_flags_esp32}
+ -D USERMOD_SHT
+lib_deps = ${esp32.lib_deps}
+ robtillaart/SHT85@~0.3.3
+```
+
+ESP8266:
+```
+[env:custom_d1_mini_usermod_sht]
+extends = env:d1_mini
+build_flags = ${common.build_flags_esp8266}
+ -D USERMOD_SHT
+lib_deps = ${esp8266.lib_deps}
+ robtillaart/SHT85@~0.3.3
+```
+
+## MQTT Discovery for Home Assistant
+If you're using Home Assistant and want to have the temperature and humidity available as entities in HA, you can tick the "Add-To-Home-Assistant-MQTT-Discovery" option in the usermod settings. If you have an MQTT broker configured under "Sync Settings" and it is connected, the mod will publish the auto discovery message to your broker and HA will instantly find it and create an entity each for the temperature and humidity.
+
+### Publishing readings via MQTT
+Regardless of having MQTT discovery ticked or not, the mod will always report temperature and humidity to the WLED MQTT topic of that instance, if you have a broker configured and it's connected.
+
+## Configuration
+Navigate to the "Config" and then to the "Usermods" section. If you compiled WLED with `-D USERMOD_SHT`, you will see the config for it there:
+* SHT-Type:
+ * What it does: Select the SHT sensor type you want to use
+ * Possible values: SHT30, SHT31, SHT35, SHT85
+ * Default: SHT30
+* Unit:
+ * What it does: Select which unit should be used to display the temperature in the info section. Also used when sending via MQTT discovery, see below.
+ * Possible values: Celsius, Fahrenheit
+ * Default: Celsius
+* Add-To-HA-MQTT-Discovery:
+ * What it does: Makes the temperature and humidity available via MQTT discovery, so they're automatically added to Home Assistant, because that way it's typesafe.
+ * Possible values: Enabled/Disabled
+ * Default: Disabled
+
+## Change log
+2022-12
+* First implementation.
+
+## Credits
+ezcGman | Andy: Find me on the Intermit.Tech (QuinLED) Discord server: https://discord.gg/WdbAauG
diff --git a/usermods/sht/usermod_sht.h b/usermods/sht/usermod_sht.h
new file mode 100644
index 00000000..1123a10a
--- /dev/null
+++ b/usermods/sht/usermod_sht.h
@@ -0,0 +1,485 @@
+#ifndef WLED_ENABLE_MQTT
+#error "This user mod requires MQTT to be enabled."
+#endif
+
+#pragma once
+
+#include "SHT85.h"
+
+#define USERMOD_SHT_TYPE_SHT30 0
+#define USERMOD_SHT_TYPE_SHT31 1
+#define USERMOD_SHT_TYPE_SHT35 2
+#define USERMOD_SHT_TYPE_SHT85 3
+
+class ShtUsermod : public Usermod
+{
+ private:
+ bool enabled = false; // Is usermod enabled or not
+ bool firstRunDone = false; // Remembers if the first config load run had been done
+ bool pinAllocDone = true; // Remembers if we have allocated pins
+ bool initDone = false; // Remembers if the mod has been completely initialised
+ bool haMqttDiscovery = false; // Is MQTT discovery enabled or not
+ bool haMqttDiscoveryDone = false; // Remembers if we already published the HA discovery topics
+
+ // SHT vars
+ SHT *shtTempHumidSensor; // Instance of SHT lib
+ byte shtType = 0; // SHT sensor type to be used. Default: SHT30
+ byte unitOfTemp = 0; // Temperature unit to be used. Default: Celsius (0 = Celsius, 1 = Fahrenheit)
+ bool shtInitDone = false; // Remembers if SHT sensor has been initialised
+ bool shtReadDataSuccess = false; // Did we have a successful data read and is a valid temperature and humidity available?
+ const byte shtI2cAddress = 0x44; // i2c address of the sensor. 0x44 is the default for all SHT sensors. Change this, if needed
+ unsigned long shtLastTimeUpdated = 0; // Remembers when we read data the last time
+ bool shtDataRequested = false; // Reading data is done async. This remembers if we asked the sensor to read data
+ float shtCurrentTempC = 0.0f; // Last read temperature in Celsius
+ float shtCurrentHumidity = 0.0f; // Last read humidity in RH%
+
+
+ void initShtTempHumiditySensor();
+ void cleanupShtTempHumiditySensor();
+ void cleanup();
+ bool isShtReady();
+
+ void publishTemperatureAndHumidityViaMqtt();
+ void publishHomeAssistantAutodiscovery();
+ void appendDeviceToMqttDiscoveryMessage(JsonDocument& root);
+
+ public:
+ // Strings to reduce flash memory usage (used more than twice)
+ static const char _name[];
+ static const char _enabled[];
+ static const char _shtType[];
+ static const char _unitOfTemp[];
+ static const char _haMqttDiscovery[];
+
+ void setup();
+ void loop();
+ void onMqttConnect(bool sessionPresent);
+ void appendConfigData();
+ void addToConfig(JsonObject &root);
+ bool readFromConfig(JsonObject &root);
+ void addToJsonInfo(JsonObject& root);
+
+ bool isEnabled() { return enabled; }
+
+ float getTemperature();
+ float getTemperatureC() { return roundf(shtCurrentTempC * 10.0f) / 10.0f; }
+ float getTemperatureF() { return (getTemperatureC() * 1.8f) + 32.0f; }
+ float getHumidity() { return roundf(shtCurrentHumidity * 10.0f) / 10.0f; }
+ const char* getUnitString();
+
+ uint16_t getId() { return USERMOD_ID_SHT; }
+};
+
+// Strings to reduce flash memory usage (used more than twice)
+const char ShtUsermod::_name[] PROGMEM = "SHT-Sensor";
+const char ShtUsermod::_enabled[] PROGMEM = "Enabled";
+const char ShtUsermod::_shtType[] PROGMEM = "SHT-Type";
+const char ShtUsermod::_unitOfTemp[] PROGMEM = "Unit";
+const char ShtUsermod::_haMqttDiscovery[] PROGMEM = "Add-To-HA-MQTT-Discovery";
+
+/**
+ * Initialise SHT sensor.
+ *
+ * Using the correct constructor according to config and initialises it using the
+ * global i2c pins.
+ *
+ * @return void
+ */
+void ShtUsermod::initShtTempHumiditySensor()
+{
+ switch (shtType) {
+ case USERMOD_SHT_TYPE_SHT30: shtTempHumidSensor = (SHT *) new SHT30(); break;
+ case USERMOD_SHT_TYPE_SHT31: shtTempHumidSensor = (SHT *) new SHT31(); break;
+ case USERMOD_SHT_TYPE_SHT35: shtTempHumidSensor = (SHT *) new SHT35(); break;
+ case USERMOD_SHT_TYPE_SHT85: shtTempHumidSensor = (SHT *) new SHT85(); break;
+ }
+
+ shtTempHumidSensor->begin(shtI2cAddress, i2c_sda, i2c_scl);
+ if (shtTempHumidSensor->readStatus() == 0xFFFF) {
+ DEBUG_PRINTF("[%s] SHT init failed!\n", _name);
+ cleanup();
+ return;
+ }
+
+ shtInitDone = true;
+}
+
+/**
+ * Cleanup the SHT sensor.
+ *
+ * Properly calls "reset" for the sensor then releases it from memory.
+ *
+ * @return void
+ */
+void ShtUsermod::cleanupShtTempHumiditySensor()
+{
+ if (isShtReady()) shtTempHumidSensor->reset();
+ delete shtTempHumidSensor;
+ shtInitDone = false;
+}
+
+/**
+ * Cleanup the mod completely.
+ *
+ * Calls ::cleanupShtTempHumiditySensor() to cleanup the SHT sensor and
+ * deallocates pins.
+ *
+ * @return void
+ */
+void ShtUsermod::cleanup()
+{
+ cleanupShtTempHumiditySensor();
+
+ if (pinAllocDone) {
+ PinManagerPinType pins[2] = { { i2c_sda, true }, { i2c_scl, true } };
+ pinManager.deallocateMultiplePins(pins, 2, PinOwner::HW_I2C);
+ pinAllocDone = false;
+ }
+
+ enabled = false;
+}
+
+/**
+ * Checks if the SHT sensor has been initialised.
+ *
+ * @return bool
+ */
+bool ShtUsermod::isShtReady()
+{
+ return shtInitDone;
+}
+
+/**
+ * Publish temperature and humidity to WLED device topic.
+ *
+ * Will add a "/temperature" and "/humidity" topic to the WLED device topic.
+ * Temperature will be written in configured unit.
+ *
+ * @return void
+ */
+void ShtUsermod::publishTemperatureAndHumidityViaMqtt() {
+ if (!WLED_MQTT_CONNECTED) return;
+ char buf[128];
+
+ snprintf_P(buf, 127, PSTR("%s/temperature"), mqttDeviceTopic);
+ mqtt->publish(buf, 0, false, String(getTemperature()).c_str());
+ snprintf_P(buf, 127, PSTR("%s/humidity"), mqttDeviceTopic);
+ mqtt->publish(buf, 0, false, String(getHumidity()).c_str());
+}
+
+/**
+ * If enabled, publishes HA MQTT device discovery topics.
+ *
+ * Will make Home Assistant add temperature and humidity as entities automatically.
+ *
+ * Note: Whenever usermods are part of the WLED integration in HA, this can be dropped.
+ *
+ * @return void
+ */
+void ShtUsermod::publishHomeAssistantAutodiscovery() {
+ if (!WLED_MQTT_CONNECTED) return;
+
+ char json_str[1024], buf[128];
+ size_t payload_size;
+ StaticJsonDocument<1024> json;
+
+ snprintf_P(buf, 127, PSTR("%s Temperature"), serverDescription);
+ json[F("name")] = buf;
+ snprintf_P(buf, 127, PSTR("%s/temperature"), mqttDeviceTopic);
+ json[F("stat_t")] = buf;
+ json[F("dev_cla")] = F("temperature");
+ json[F("stat_cla")] = F("measurement");
+ snprintf_P(buf, 127, PSTR("%s-temperature"), escapedMac.c_str());
+ json[F("uniq_id")] = buf;
+ json[F("unit_of_meas")] = unitOfTemp ? F("°F") : F("°C");
+ appendDeviceToMqttDiscoveryMessage(json);
+ payload_size = serializeJson(json, json_str);
+ snprintf_P(buf, 127, PSTR("homeassistant/sensor/%s/%s-temperature/config"), escapedMac.c_str(), escapedMac.c_str());
+ mqtt->publish(buf, 0, true, json_str, payload_size);
+
+ json.clear();
+
+ snprintf_P(buf, 127, PSTR("%s Humidity"), serverDescription);
+ json[F("name")] = buf;
+ snprintf_P(buf, 127, PSTR("%s/humidity"), mqttDeviceTopic);
+ json[F("stat_t")] = buf;
+ json[F("dev_cla")] = F("humidity");
+ json[F("stat_cla")] = F("measurement");
+ snprintf_P(buf, 127, PSTR("%s-humidity"), escapedMac.c_str());
+ json[F("uniq_id")] = buf;
+ json[F("unit_of_meas")] = F("%");
+ appendDeviceToMqttDiscoveryMessage(json);
+ payload_size = serializeJson(json, json_str);
+ snprintf_P(buf, 127, PSTR("homeassistant/sensor/%s/%s-humidity/config"), escapedMac.c_str(), escapedMac.c_str());
+ mqtt->publish(buf, 0, true, json_str, payload_size);
+
+ haMqttDiscoveryDone = true;
+}
+
+/**
+ * Helper to add device information to MQTT discovery topic.
+ *
+ * @return void
+ */
+void ShtUsermod::appendDeviceToMqttDiscoveryMessage(JsonDocument& root) {
+ JsonObject device = root.createNestedObject(F("dev"));
+ device[F("ids")] = escapedMac.c_str();
+ device[F("name")] = serverDescription;
+ device[F("sw")] = versionString;
+ device[F("mdl")] = ESP.getChipModel();
+ device[F("mf")] = F("espressif");
+}
+
+/**
+ * Setup the mod.
+ *
+ * Allocates i2c pins as PinOwner::HW_I2C, so they can be allocated multiple times.
+ * And calls ::initShtTempHumiditySensor() to initialise the sensor.
+ *
+ * @see Usermod::setup()
+ * @see UsermodManager::setup()
+ *
+ * @return void
+ */
+void ShtUsermod::setup()
+{
+ if (enabled) {
+ PinManagerPinType pins[2] = { { i2c_sda, true }, { i2c_scl, true } };
+ // GPIOs can be set to -1 and allocateMultiplePins() will return true, so check they're gt zero
+ if (i2c_sda < 0 || i2c_scl < 0 || !pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) {
+ DEBUG_PRINTF("[%s] SHT pin allocation failed!\n", _name);
+ cleanup();
+ return;
+ }
+ pinAllocDone = true;
+
+ initShtTempHumiditySensor();
+
+ initDone = true;
+ }
+
+ firstRunDone = true;
+}
+
+/**
+ * Actually reading data (async) from the sensor every 30 seconds.
+ *
+ * If last reading is at least 30 seconds, it will trigger a reading using
+ * SHT::requestData(). We will then continiously check SHT::dataReady() if
+ * data is ready to be read. If so, it's read, stored locally and published
+ * via MQTT.
+ *
+ * @see Usermod::loop()
+ * @see UsermodManager::loop()
+ *
+ * @return void
+ */
+void ShtUsermod::loop()
+{
+ if (!enabled || !initDone || strip.isUpdating()) return;
+
+ if (isShtReady()) {
+ if (millis() - shtLastTimeUpdated > 30000 && !shtDataRequested) {
+ shtTempHumidSensor->requestData();
+ shtDataRequested = true;
+
+ shtLastTimeUpdated = millis();
+ }
+
+ if (shtDataRequested) {
+ if (shtTempHumidSensor->dataReady()) {
+ if (shtTempHumidSensor->readData(false)) {
+ shtCurrentTempC = shtTempHumidSensor->getTemperature();
+ shtCurrentHumidity = shtTempHumidSensor->getHumidity();
+
+ publishTemperatureAndHumidityViaMqtt();
+ shtReadDataSuccess = true;
+ } else {
+ shtReadDataSuccess = false;
+ }
+
+ shtDataRequested = false;
+ }
+ }
+ }
+}
+
+/**
+ * Whenever MQTT is connected, publish HA autodiscovery topics.
+ *
+ * Is only donce once.
+ *
+ * @see Usermod::onMqttConnect()
+ * @see UsermodManager::onMqttConnect()
+ *
+ * @return void
+ */
+void ShtUsermod::onMqttConnect(bool sessionPresent) {
+ if (haMqttDiscovery && !haMqttDiscoveryDone) publishHomeAssistantAutodiscovery();
+}
+
+/**
+ * Add dropdown for sensor type and unit to UM config page.
+ *
+ * @see Usermod::appendConfigData()
+ * @see UsermodManager::appendConfigData()
+ *
+ * @return void
+ */
+void ShtUsermod::appendConfigData() {
+ oappend(SET_F("dd=addDropdown('"));
+ oappend(_name);
+ oappend(SET_F("','"));
+ oappend(_shtType);
+ oappend(SET_F("');"));
+ oappend(SET_F("addOption(dd,'SHT30',0);"));
+ oappend(SET_F("addOption(dd,'SHT31',1);"));
+ oappend(SET_F("addOption(dd,'SHT35',2);"));
+ oappend(SET_F("addOption(dd,'SHT85',3);"));
+ oappend(SET_F("dd=addDropdown('"));
+ oappend(_name);
+ oappend(SET_F("','"));
+ oappend(_unitOfTemp);
+ oappend(SET_F("');"));
+ oappend(SET_F("addOption(dd,'Celsius',0);"));
+ oappend(SET_F("addOption(dd,'Fahrenheit',1);"));
+}
+
+/**
+ * Add config data to be stored in cfg.json.
+ *
+ * @see Usermod::addToConfig()
+ * @see UsermodManager::addToConfig()
+ *
+ * @return void
+ */
+void ShtUsermod::addToConfig(JsonObject &root)
+{
+ JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
+
+ top[FPSTR(_enabled)] = enabled;
+ top[FPSTR(_shtType)] = shtType;
+ top[FPSTR(_unitOfTemp)] = unitOfTemp;
+ top[FPSTR(_haMqttDiscovery)] = haMqttDiscovery;
+}
+
+/**
+ * Apply config on boot or save of UM config page.
+ *
+ * This is called whenever WLED boots and loads cfg.json, or when the UM config
+ * page is saved. Will properly re-instantiate the SHT class upon type change and
+ * publish HA discovery after enabling.
+ *
+ * @see Usermod::readFromConfig()
+ * @see UsermodManager::readFromConfig()
+ *
+ * @return bool
+ */
+bool ShtUsermod::readFromConfig(JsonObject &root)
+{
+ JsonObject top = root[FPSTR(_name)];
+ if (top.isNull()) {
+ DEBUG_PRINTF("[%s] No config found. (Using defaults.)\n", _name);
+ return false;
+ }
+
+ bool oldEnabled = enabled;
+ byte oldShtType = shtType;
+ byte oldUnitOfTemp = unitOfTemp;
+ bool oldHaMqttDiscovery = haMqttDiscovery;
+
+ getJsonValue(top[FPSTR(_enabled)], enabled);
+ getJsonValue(top[FPSTR(_shtType)], shtType);
+ getJsonValue(top[FPSTR(_unitOfTemp)], unitOfTemp);
+ getJsonValue(top[FPSTR(_haMqttDiscovery)], haMqttDiscovery);
+
+ // First run: reading from cfg.json, nothing to do here, will be all done in setup()
+ if (!firstRunDone) {
+ DEBUG_PRINTF("[%s] First run, nothing to do\n", _name);
+ }
+ // Check if mod has been en-/disabled
+ else if (enabled != oldEnabled) {
+ enabled ? setup() : cleanup();
+ DEBUG_PRINTF("[%s] Usermod has been en-/disabled\n", _name);
+ }
+ // Config has been changed, so adopt to changes
+ else if (enabled) {
+ if (oldShtType != shtType) {
+ cleanupShtTempHumiditySensor();
+ initShtTempHumiditySensor();
+ }
+
+ if (oldUnitOfTemp != unitOfTemp) {
+ publishTemperatureAndHumidityViaMqtt();
+ publishHomeAssistantAutodiscovery();
+ }
+
+ if (oldHaMqttDiscovery != haMqttDiscovery && haMqttDiscovery) {
+ publishHomeAssistantAutodiscovery();
+ }
+
+ DEBUG_PRINTF("[%s] Config (re)loaded\n", _name);
+ }
+
+ return true;
+}
+
+/**
+ * Adds the temperature and humidity actually to the info section and /json info.
+ *
+ * This is called every time the info section is opened ot /json is called.
+ *
+ * @see Usermod::addToJsonInfo()
+ * @see UsermodManager::addToJsonInfo()
+ *
+ * @return void
+ */
+void ShtUsermod::addToJsonInfo(JsonObject& root)
+{
+ if (!enabled && !isShtReady()) {
+ return;
+ }
+
+ JsonObject user = root["u"];
+ if (user.isNull()) user = root.createNestedObject("u");
+
+ JsonArray jsonTemp = user.createNestedArray(F("Temperature"));
+ JsonArray jsonHumidity = user.createNestedArray(F("Humidity"));
+
+ if (shtLastTimeUpdated == 0 || !shtReadDataSuccess) {
+ jsonTemp.add(0);
+ jsonHumidity.add(0);
+ if (shtLastTimeUpdated == 0) {
+ jsonTemp.add(F(" Not read yet"));
+ jsonHumidity.add(F(" Not read yet"));
+ } else {
+ jsonTemp.add(F(" Error"));
+ jsonHumidity.add(F(" Error"));
+ }
+ return;
+ }
+
+ jsonHumidity.add(getHumidity());
+ jsonHumidity.add(F(" RH"));
+
+ jsonTemp.add(getTemperature());
+ jsonTemp.add(unitOfTemp ? "°F" : "°C");
+}
+
+/**
+ * Getter for last read temperature for configured unit.
+ *
+ * @return float
+ */
+float ShtUsermod::getTemperature() {
+ return unitOfTemp ? getTemperatureF() : getTemperatureC();
+}
+
+/**
+ * Returns the current configured unit as human readable string.
+ *
+ * @return const char*
+ */
+const char* ShtUsermod::getUnitString() {
+ return unitOfTemp ? "°F" : "°C";
+}
\ No newline at end of file
diff --git a/usermods/smartnest/readme.md b/usermods/smartnest/readme.md
index c56f3621..5c3ef807 100644
--- a/usermods/smartnest/readme.md
+++ b/usermods/smartnest/readme.md
@@ -1,6 +1,6 @@
# Smartnest
-This usermod-v2 modification allows integration with `smartnest.cz` service which provides MQTT integration with voice assistants.
+Enables integration with `smartnest.cz` service which provides MQTT integration with voice assistants.
In order to setup Smartnest follow the [documentation](https://www.docu.smartnest.cz/).
## MQTT API
@@ -49,7 +49,7 @@ void registerUsermods()
## Configuration
-Usermod has no configuration but relies on the MQTT configuration.\
+Usermod has no configuration, but it relies on the MQTT configuration.\
Under Config > Sync Interfaces > MQTT:
* Enable MQTT check box
* Set the `Broker` field to: `smartnest.cz`
diff --git a/usermods/smartnest/usermod_smartnest.h b/usermods/smartnest/usermod_smartnest.h
index 82673578..8d2b04ff 100644
--- a/usermods/smartnest/usermod_smartnest.h
+++ b/usermods/smartnest/usermod_smartnest.h
@@ -1,3 +1,7 @@
+#ifndef WLED_ENABLE_MQTT
+#error "This user mod requires MQTT to be enabled."
+#endif
+
#pragma once
#include "wled.h"
diff --git a/usermods/stairway_wipe_basic/readme.md b/usermods/stairway_wipe_basic/readme.md
index 632b7d85..35bc0d41 100644
--- a/usermods/stairway_wipe_basic/readme.md
+++ b/usermods/stairway_wipe_basic/readme.md
@@ -2,13 +2,13 @@
Quick usermod to accomplish something similar to [this video](https://www.youtube.com/watch?v=NHkju5ncC4A).
-This usermod allows you to add a lightstrip alongside or on the steps of a staircase.
+This usermod enables you to add a lightstrip alongside or on the steps of a staircase.
When the `userVar0` variable is set, the LEDs will gradually turn on in a Wipe effect.
Both directions are supported by setting userVar0 to 1 and 2, respectively (HTTP API commands `U0=1` and `U0=2`).
-After the Wipe is complete, the light will either stay on (Solid effect) indefinitely or after `userVar1` seconds have elapsed.
-If userVar0 is updated (e.g. by triggering a second sensor) the light will slowly fade off.
-This could be extended to also run a Wipe effect in reverse order to turn the LEDs back off.
+After the Wipe is complete, the light will either stay on (Solid effect) indefinitely or extinguish after `userVar1` seconds have elapsed.
+If userVar0 is updated (e.g. by triggering a second sensor) the light will fade slowly until it's off.
+This could be extended to also run a Wipe effect in reverse order to turn the LEDs off.
This is just a basic version to accomplish this using HTTP API calls `U0` and `U1` and/or macros.
-It should be easy to adapt this code however to interface with motion sensors or other input devices.
\ No newline at end of file
+It should be easy to adapt this code to interface with motion sensors or other input devices.
diff --git a/usermods/usermod_rotary_brightness_color/README.md b/usermods/usermod_rotary_brightness_color/README.md
index 9d59a0ba..06a3a0f8 100644
--- a/usermods/usermod_rotary_brightness_color/README.md
+++ b/usermods/usermod_rotary_brightness_color/README.md
@@ -1,18 +1,18 @@
# Rotary Encoder (Brightness and Color)
-V2 usermod that allows changing brightness and color using a rotary encoder,
+V2 usermod that enables changing brightness and color using a rotary encoder
change between modes by pressing a button (many encoders have one included)
-but it will wait for AUTOSAVE_SETTLE_MS milliseconds, a "settle"
+it will wait for AUTOSAVE_SETTLE_MS milliseconds. a "settle"
period in case there are other changes (any change will
-extend the "settle" window).
+extend the "settle" period).
It will additionally load preset AUTOSAVE_PRESET_NUM at startup.
during the first `loop()`. Reasoning below.
AutoSaveUsermod is standalone, but if FourLineDisplayUsermod is installed, it will notify the user of the saved changes.
-Note: I don't love that WLED doesn't respect the brightness of the preset being auto loaded, so the AutoSaveUsermod will set the AUTOSAVE_PRESET_NUM preset in the first loop, so brightness IS honored. This means WLED will effectively ignore Default brightness and Apply N preset at boot when the AutoSaveUsermod is installed.
+Note: WLED doesn't respect the brightness of the preset being auto loaded, so the AutoSaveUsermod will set the AUTOSAVE_PRESET_NUM preset in the first loop, so brightness IS honored. This means WLED will effectively ignore Default brightness and Apply N preset at boot when the AutoSaveUsermod is installed.
## Installation
diff --git a/usermods/usermod_v2_auto_save/readme.md b/usermods/usermod_v2_auto_save/readme.md
index 8d00fcca..f54d87a7 100644
--- a/usermods/usermod_v2_auto_save/readme.md
+++ b/usermods/usermod_v2_auto_save/readme.md
@@ -9,13 +9,13 @@ to preset number AUTOSAVE_PRESET_NUM after a change to any of:
* palette
but it will wait for AUTOSAVE_AFTER_SEC seconds,
-a "settle" period in case there are other changes (any change will extend the "settle" window).
+a "settle" period in case there are other changes (any change will extend the "settle" period).
It will additionally load preset AUTOSAVE_PRESET_NUM at startup during the first `loop()`.
AutoSaveUsermod is standalone, but if FourLineDisplayUsermod is installed, it will notify the user of the saved changes.
-Note: I don't love that WLED doesn't respect the brightness of the preset being auto loaded, so the AutoSaveUsermod will set the AUTOSAVE_PRESET_NUM preset in the first loop, so brightness IS honored. This means WLED will effectively ignore Default brightness and Apply N preset at boot when the AutoSaveUsermod is installed.
+Note: WLED doesn't respect the brightness of the preset being auto loaded, so the AutoSaveUsermod will set the AUTOSAVE_PRESET_NUM preset in the first loop, so brightness IS honored. This means WLED will effectively ignore Default brightness and Apply N preset at boot when the AutoSaveUsermod is installed.
## Installation
@@ -25,7 +25,7 @@ This file should be placed in the same directory as `platformio.ini`.
### Define Your Options
-* `USERMOD_AUTO_SAVE` - define this to have this the Auto Save usermod included wled00\usermods_list.cpp
+* `USERMOD_AUTO_SAVE` - define this to have this usermod included wled00\usermods_list.cpp
* `AUTOSAVE_AFTER_SEC` - define the delay time after the settings auto-saving routine should be executed
* `AUTOSAVE_PRESET_NUM` - define the preset number used by autosave usermod
* `USERMOD_AUTO_SAVE_ON_BOOT` - define if autosave should be enabled on boot
@@ -52,4 +52,4 @@ Note: the Four Line Display usermod requires the libraries `U8g2` and `Wire`.
2021-02
* First public release
2021-04
-* Adaptation for runtime configuration.
\ No newline at end of file
+* Adaptation for runtime configuration.
diff --git a/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h b/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
index 8283aeed..e8806609 100644
--- a/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
+++ b/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
@@ -204,6 +204,10 @@ class AutoSaveUsermod : public Usermod {
}
}
+ void appendConfigData() {
+ oappend(SET_F("addHB('Autosave');"));
+ }
+
/*
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
* It will be called by WLED when settings are actually saved (for example, LED settings are saved)
diff --git a/usermods/usermod_v2_four_line_display/readme.md b/usermods/usermod_v2_four_line_display/readme.md
index 47518be9..26250cb5 100644
--- a/usermods/usermod_v2_four_line_display/readme.md
+++ b/usermods/usermod_v2_four_line_display/readme.md
@@ -2,9 +2,9 @@
First, thanks to the authors of the ssd11306_i2c_oled_u8g2 mod.
-This usermod provides a four line display using either
+Provides a four line display using either
128x32 or 128x64 OLED displays.
-It's can operate independently, but starts to provide
+It can operate independently, but starts to provide
a relatively complete on-device UI when paired with the
Rotary Encoder UI usermod. I strongly encourage you to use
them together.
@@ -19,11 +19,11 @@ This file should be placed in the same directory as `platformio.ini`.
### Define Your Options
-* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp - also tells Rotary Encoder usermod, if installed, that the display is available
+* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this mod included wled00\usermods_list.cpp - also tells Rotary Encoder usermod, if installed, the display is available
* `FLD_PIN_SCL` - The display SCL pin, defaults to 5
* `FLD_PIN_SDA` - The display SDA pin, defaults to 4
-All of the parameters can be configured using Usermods settings page, inluding GPIO pins.
+All of the parameters can be configured via the Usermods settings page, inluding GPIO pins.
### PlatformIO requirements
@@ -44,7 +44,7 @@ UI usermod folder for how to include these using `platformio_override.ini`.
* 6 = SPI SSD1306 128x32
* 7 = SPI SSD1306 128x64 (4 double-height lines)
* `contrast` - set display contrast (higher contrast may reduce display lifetime)
-* `refreshRateSec` - time in seconds for display refresh
+* `refreshRateSec` - display refresh time in seconds
* `screenTimeOutSec` - screen saver time-out in seconds
* `flip` - flip/rotate display 180°
* `sleepMode` - enable/disable screen saver
@@ -60,4 +60,4 @@ UI usermod folder for how to include these using `platformio_override.ini`.
* Adaptation for runtime configuration.
2021-11
-* Added configuration option description.
\ No newline at end of file
+* Added configuration option description.
diff --git a/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h b/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h
index ac65508b..7f052648 100644
--- a/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h
+++ b/usermods/usermod_v2_four_line_display/usermod_v2_four_line_display.h
@@ -33,8 +33,8 @@
#ifndef FLD_PIN_CLOCKSPI
#define FLD_PIN_CLOCKSPI spi_sclk
#endif
- #ifndef FLD_PIN_DATASPI
- #define FLD_PIN_DATASPI spi_mosi
+ #ifndef FLD_PIN_MOSISPI //WLEDMM renamed from HW_PIN_DATASPI
+ #define FLD_PIN_MOSISPI spi_mosi
#endif
#ifndef FLD_PIN_CS
#define FLD_PIN_CS spi_cs
@@ -109,7 +109,7 @@ class FourLineDisplayUsermod : public Usermod {
int8_t ioPin[5] = {FLD_PIN_SCL, FLD_PIN_SDA, -1, -1, -1}; // I2C pins: SCL, SDA
uint32_t ioFrequency = 400000; // in Hz (minimum is 100000, baseline is 400000 and maximum should be 3400000)
#else
- int8_t ioPin[5] = {FLD_PIN_CLOCKSPI, FLD_PIN_DATASPI, FLD_PIN_CS, FLD_PIN_DC, FLD_PIN_RESET}; // SPI pins: CLK, MOSI, CS, DC, RST
+ int8_t ioPin[5] = {FLD_PIN_CLOCKSPI, FLD_PIN_MOSISPI, FLD_PIN_CS, FLD_PIN_DC, FLD_PIN_RESET}; // SPI pins: CLK, MOSI, CS, DC, RST
uint32_t ioFrequency = 1000000; // in Hz (minimum is 500kHz, baseline is 1MHz and maximum should be 20MHz)
#endif
DisplayType type = FLD_TYPE; // display type
@@ -120,8 +120,11 @@ class FourLineDisplayUsermod : public Usermod {
uint32_t screenTimeout = SCREEN_TIMEOUT_MS; // in ms
bool sleepMode = true; // allow screen sleep?
bool clockMode = false; // display clock
+#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+ bool enabled = false; // WLEDMM workaround for I2C bugs in IDF v4.4.1
+#else
bool enabled = true;
-
+#endif
// Next variables hold the previous known values to determine if redraw is
// required.
String knownSsid = "";
@@ -177,9 +180,9 @@ class FourLineDisplayUsermod : public Usermod {
isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
//isHW = true;
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
- if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
+ if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; enabled = false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } };
- if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
+ if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; enabled = false; return; }
}
DEBUG_PRINTLN(F("Allocating display."));
@@ -224,14 +227,14 @@ class FourLineDisplayUsermod : public Usermod {
}
if (nullptr == u8x8) {
- DEBUG_PRINTLN(F("Display init failed."));
+ USER_PRINTLN(F("Display init failed."));
pinManager.deallocateMultiplePins((const uint8_t*)ioPin, (type == SSD1306_SPI || type == SSD1306_SPI64) ? 5 : 2, po);
type = NONE;
return;
}
initDone = true;
- DEBUG_PRINTLN(F("Starting display."));
+ USER_PRINTLN(F("Starting display."));
/*if (!(type == SSD1306_SPI || type == SSD1306_SPI64))*/ u8x8->setBusClock(ioFrequency); // can be used for SPI too
u8x8->begin();
setFlipMode(flip);
@@ -636,6 +639,7 @@ class FourLineDisplayUsermod : public Usermod {
JsonObject top = root.createNestedObject(FPSTR(_name));
top[FPSTR(_enabled)] = enabled;
JsonArray io_pin = top.createNestedArray("pin");
+ #warning WLEDMM: this causes global pin hijacking
for (byte i=0; i<5; i++) io_pin.add(ioPin[i]);
top["help4Pins"] = F("Clk,Data,CS,DC,RST"); // help for Settings page
top["type"] = type;
diff --git a/usermods/usermod_v2_four_line_display_ALT/readme.md b/usermods/usermod_v2_four_line_display_ALT/readme.md
index 67cde353..00f70caf 100644
--- a/usermods/usermod_v2_four_line_display_ALT/readme.md
+++ b/usermods/usermod_v2_four_line_display_ALT/readme.md
@@ -4,12 +4,12 @@ Thank you to the authors of the original version of these usermods. It would not
"usermod_v2_four_line_display"
"usermod_v2_rotary_encoder_ui"
-The core of these usermods are a copy of the originals. The main changes are done to the FourLineDisplay usermod.
+The core of these usermods are a copy of the originals. The main changes are to the FourLineDisplay usermod.
The display usermod UI has been completely changed.
The changes made to the RotaryEncoder usermod were made to support the new UI in the display usermod.
-Without the display it functions identical to the original.
+Without the display it, functions identical to the original.
The original "usermod_v2_auto_save" will not work with the display just yet.
Press the encoder to cycle through the options:
@@ -22,7 +22,7 @@ Press the encoder to cycle through the options:
*Saturation (only if display is used)
Press and hold the encoder to display Network Info
- if AP is active then it will display AP ssid and Password
+ if AP is active, it will display AP, SSID and password
Also shows if the timer is enabled
@@ -31,8 +31,8 @@ Also shows if the timer is enabled
## Installation
Please refer to the original `usermod_v2_rotary_encoder_ui` readme for the main instructions
-Then to activate this alternative usermod add `#define USE_ALT_DISPlAY` to the `usermods_list.cpp` file,
- or add `-D USE_ALT_DISPlAY` to the original `platformio_override.ini.sample` file
+Then to activate this alternative usermod add `#define USE_ALT_DISPLAY` to the `usermods_list.cpp` file,
+ or add `-D USE_ALT_DISPLAY` to the original `platformio_override.ini.sample` file
### PlatformIO requirements
@@ -42,4 +42,4 @@ Note: the Four Line Display usermod requires the libraries `U8g2` and `Wire`.
## Change Log
2021-10
-* First public release
\ No newline at end of file
+* First public release
diff --git a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h
index 79fef942..ebe066c3 100644
--- a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h
+++ b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h
@@ -1,9 +1,18 @@
#pragma once
+#include // WLEDMM: make sure that I2C drivers have the "right" Wire Object
+#include
+#undef U8X8_NO_HW_I2C // WLEDMM: we do want I2C hardware drivers - if possible
+//#define WIRE_INTERFACES_COUNT 2 // experimental - tell U8x8Lib that there is a econd Wire unit
+
#include "wled.h"
#include // from https://github.com/olikraus/u8g2/
#include "4LD_wled_fonts.c"
+#ifndef FLD_ESP32_NO_THREADS
+#define FLD_ESP32_USE_THREADS // comment out to use 0.13.x behviour without parallel update task - slower, but more robust. May delay other tasks like LEDs or audioreactive!!
+#endif
+
//
// Insired by the usermod_v2_four_line_display
//
@@ -26,35 +35,26 @@
//The SCL and SDA pins are defined here.
#ifndef FLD_PIN_SCL
- #define FLD_PIN_SCL i2c_scl
+ #define FLD_PIN_SCL -1
#endif
#ifndef FLD_PIN_SDA
- #define FLD_PIN_SDA i2c_sda
+ #define FLD_PIN_SDA -1
#endif
#ifndef FLD_PIN_CLOCKSPI
- #define FLD_PIN_CLOCKSPI spi_sclk
+ #define FLD_PIN_CLOCKSPI -1
#endif
- #ifndef FLD_PIN_DATASPI
- #define FLD_PIN_DATASPI spi_mosi
+#ifndef FLD_PIN_MOSISPI //WLEDMM renamed from HW_PIN_DATASPI
+ #define FLD_PIN_MOSISPI -1
#endif
#ifndef FLD_PIN_CS
- #define FLD_PIN_CS spi_cs
+ #define FLD_PIN_CS -1
#endif
-#ifdef ARDUINO_ARCH_ESP32
- #ifndef FLD_PIN_DC
- #define FLD_PIN_DC 19
- #endif
- #ifndef FLD_PIN_RESET
- #define FLD_PIN_RESET 26
- #endif
-#else
- #ifndef FLD_PIN_DC
- #define FLD_PIN_DC 12
- #endif
- #ifndef FLD_PIN_RESET
- #define FLD_PIN_RESET 16
- #endif
+#ifndef FLD_PIN_DC
+ #define FLD_PIN_DC -1
+#endif
+#ifndef FLD_PIN_RESET
+ #define FLD_PIN_RESET -1
#endif
#ifndef FLD_TYPE
@@ -98,14 +98,19 @@ typedef enum {
class FourLineDisplayUsermod : public Usermod {
public:
+#ifdef ARDUINO_ARCH_ESP32
FourLineDisplayUsermod() { if (!instance) instance = this; }
static FourLineDisplayUsermod* getInstance(void) { return instance; }
+#endif
private:
static FourLineDisplayUsermod *instance;
bool initDone = false;
- volatile bool drawing = false;
+ volatile bool drawing = false; // true of overlay drawing is active
+ volatile bool reDrawing = false; // true if redraw ongoing (on esp32, this happens in a separate task)
+
+ char errorMessage[100] = ""; //WLEDMM: show error in um settings if occurred
// HW interface & configuration
U8X8 *u8x8 = nullptr; // pointer to U8X8 display object
@@ -114,11 +119,12 @@ class FourLineDisplayUsermod : public Usermod {
int8_t ioPin[5] = {FLD_PIN_SCL, FLD_PIN_SDA, -1, -1, -1}; // I2C pins: SCL, SDA
uint32_t ioFrequency = 400000; // in Hz (minimum is 100000, baseline is 400000 and maximum should be 3400000)
#else
- int8_t ioPin[5] = {FLD_PIN_CLOCKSPI, FLD_PIN_DATASPI, FLD_PIN_CS, FLD_PIN_DC, FLD_PIN_RESET}; // SPI pins: CLK, MOSI, CS, DC, RST
+ int8_t ioPin[5] = {FLD_PIN_CLOCKSPI, FLD_PIN_MOSISPI, FLD_PIN_CS, FLD_PIN_DC, FLD_PIN_RESET}; // SPI pins: CLK, MOSI, CS, DC, RST
uint32_t ioFrequency = 1000000; // in Hz (minimum is 500kHz, baseline is 1MHz and maximum should be 20MHz)
#endif
DisplayType type = FLD_TYPE; // display type
+ bool typeOK = false; //WLEDMM: instead of type == NULL and type=NULL. Intially false, as display was not initialized yet
bool flip = false; // flip display 180°
uint8_t contrast = 10; // screen contrast
uint8_t lineHeight = 1; // 1 row or 2 rows
@@ -127,7 +133,15 @@ class FourLineDisplayUsermod : public Usermod {
bool sleepMode = true; // allow screen sleep?
bool clockMode = false; // display clock
bool showSeconds = true; // display clock with seconds
+#if defined(ARDUINO_ARCH_ESP32)
+#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
+ bool enabled = false; // WLEDMM workaround for I2C bugs in IDF v4.4.1
+#else
bool enabled = true;
+#endif
+#else
+ bool enabled = true;
+#endif
bool contrastFix = false;
// Next variables hold the previous known values to determine if redraw is
@@ -178,6 +192,9 @@ class FourLineDisplayUsermod : public Usermod {
// some displays need this to properly apply contrast
void setVcomh(bool highContrast) {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
+ if (!canDraw()) return; // don't interfere with ongoing draw
+
u8x8_t *u8x8_struct = u8x8->getU8x8();
u8x8_cad_StartTransfer(u8x8_struct);
u8x8_cad_SendCmd(u8x8_struct, 0x0db); //address of value
@@ -189,45 +206,46 @@ class FourLineDisplayUsermod : public Usermod {
* Wrappers for screen drawing
*/
void setFlipMode(uint8_t mode) {
- if (type == NONE || !enabled) return;
- u8x8->setFlipMode(mode);
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
+ if (canDraw()) u8x8->setFlipMode(mode);
}
void setContrast(uint8_t contrast) {
- if (type == NONE || !enabled) return;
- u8x8->setContrast(contrast);
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
+ if (canDraw()) u8x8->setContrast(contrast);
}
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
- if (type == NONE || !enabled) return;
- u8x8->setFont(u8x8_font_chroma48medium8_r);
- if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
+ u8x8->setFont(u8x8_font_chroma48medium8_r); // crashes randomly on ESP32
+ if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string); // crashes randomly on ESP32
else u8x8->drawString(col, row, string);
}
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
- if (type == NONE || !enabled) return;
+ if (!typeOK || !enabled) return;
u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->draw2x2String(col, row, string);
}
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
- if (type == NONE || !enabled) return;
+ if (!typeOK || !enabled) return;
u8x8->setFont(font);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
else u8x8->drawGlyph(col, row, glyph);
}
void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) {
- if (type == NONE || !enabled) return;
+ if (!typeOK || !enabled) return;
u8x8->setFont(font);
u8x8->draw2x2Glyph(col, row, glyph);
}
uint8_t getCols() {
- if (type==NONE || !enabled) return 0;
+ if (!typeOK || !enabled) return 0;
return u8x8->getCols();
}
void clear() {
- if (type == NONE || !enabled) return;
- u8x8->clear();
+ if (!typeOK || !enabled) return;
+ if (nullptr == u8x8) return; // prevents some crashes
+ u8x8->clear(); // crashes randomly on ESP32
}
void setPowerSave(uint8_t save) {
- if (type == NONE || !enabled) return;
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
u8x8->setPowerSave(save);
}
@@ -238,6 +256,7 @@ class FourLineDisplayUsermod : public Usermod {
}
void draw2x2GlyphIcons() {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
if (lineHeight == 2) {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon
@@ -259,13 +278,13 @@ class FourLineDisplayUsermod : public Usermod {
* the useAMPM configuration.
*/
void showTime() {
- if (type == NONE || !enabled || !displayTurnedOff) return;
+ if (!typeOK || !enabled || !displayTurnedOff) return;
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
- char lineBuffer[LINE_BUFFER_SIZE];
+ char lineBuffer[LINE_BUFFER_SIZE] = { '\0' };
static byte lastSecond;
byte secondCurrent = second(localTime);
byte minuteCurrent = minute(localTime);
@@ -281,10 +300,10 @@ class FourLineDisplayUsermod : public Usermod {
}
if (knownHour != hourCurrent) {
// only update date when hour changes
- sprintf_P(lineBuffer, PSTR("%s %2d "), monthShortStr(month(localTime)), day(localTime));
+ snprintf_P(lineBuffer, LINE_BUFFER_SIZE, PSTR("%s %2d "), monthShortStr(month(localTime)), day(localTime));
draw2x2String(2, lineHeight==1 ? 0 : lineHeight, lineBuffer); // adjust for 8 line displays, draw month and day
}
- sprintf_P(lineBuffer,PSTR("%2d:%02d"), (useAMPM ? AmPmHour : hourCurrent), minuteCurrent);
+ snprintf_P(lineBuffer,LINE_BUFFER_SIZE, PSTR("%2d:%02d"), (useAMPM ? AmPmHour : hourCurrent), minuteCurrent);
draw2x2String(2, lineHeight*2, lineBuffer); //draw hour, min. blink ":" depending on odd/even seconds
if (useAMPM) drawString(12, lineHeight*2, (isitAM ? "AM" : "PM"), true); //draw am/pm if using 12 time
@@ -296,7 +315,7 @@ class FourLineDisplayUsermod : public Usermod {
if (showSeconds && secondCurrent != lastSecond) {
lastSecond = secondCurrent;
draw2x2String(6, lineHeight*2, secondCurrent%2 ? " " : ":");
- sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
+ snprintf_P(lineBuffer, LINE_BUFFER_SIZE, PSTR("%02d"), secondCurrent);
drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
}
drawing = false;
@@ -307,40 +326,43 @@ class FourLineDisplayUsermod : public Usermod {
// gets called once at boot. Do all initialization that doesn't depend on
// network here
void setup() {
- if (type == NONE || !enabled) return;
+ if (!enabled) return; // typeOK = true will be set after successfull setup
bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
PinOwner po = PinOwner::UM_FourLineDisplay;
if (isSPI) {
- uint8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
- uint8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
if (ioPin[0] < 0 || ioPin[1] < 0) {
- ioPin[0] = hw_sclk;
- ioPin[1] = hw_mosi;
+ ioPin[0] = spi_sclk;
+ ioPin[1] = spi_mosi;
}
- isHW = (ioPin[0]==hw_sclk && ioPin[1]==hw_mosi);
+ isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi);
PinManagerPinType cspins[3] = { { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true } };
- if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { type=NONE; return; }
+ if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { typeOK=false; strcpy(errorMessage, PSTR("SPI3 alloc pins failed")); return; }
if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } };
if (!pinManager.allocateMultiplePins(pins, 2, po)) {
pinManager.deallocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay);
- type = NONE;
+ typeOK=false;
+ strcpy(errorMessage, PSTR("SPI2 alloc pins failed"));
return;
}
} else {
- uint8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
- uint8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
if (ioPin[0] < 0 || ioPin[1] < 0) {
- ioPin[0] = hw_scl;
- ioPin[1] = hw_sda;
+ ioPin[0] = i2c_scl;
+ ioPin[1] = i2c_sda;
}
- isHW = (ioPin[0]==hw_scl && ioPin[1]==hw_sda);
+ isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
// isHW = true;
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { {ioPin[0], true }, { ioPin[1], true } };
- if (ioPin[0] < 0 || ioPin[1] < 0) { type=NONE; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
- if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
+
+ if (ioPin[0] < 0 || ioPin[1] < 0) { typeOK=false; strcpy(errorMessage, PSTR("I2C No Pins defined")); return; } //WLEDMM bugfix - ensure that "final" GPIO are valid
+
+ if (isHW) {
+ if (!pinManager.joinWire(ioPin[1], ioPin[0])) { typeOK=false; strcpy(errorMessage, PSTR("I2C init failed")); return; } // WLEDMM join the HW bus
+ } else {
+ if (!pinManager.allocateMultiplePins(pins, 2, po)) { typeOK=false; strcpy(errorMessage, PSTR("I2C Alloc pins failed")); return; } // WLEDMM use software bus
+ }
}
DEBUG_PRINTLN(F("Allocating display."));
@@ -371,7 +393,8 @@ class FourLineDisplayUsermod : public Usermod {
u8x8_Setup(u8x8.getU8x8(), u8x8_d_ssd1306_128x64_noname, u8x8_cad_001, u8x8_byte_arduino_4wire_sw_spi, u8x8_gpio_and_delay_arduino);
break;
default:
- type = NONE;
+ typeOK=false;
+ strcpy(errorMessage, PSTR("No valid type"));
return;
}
if (isSPI) {
@@ -418,16 +441,24 @@ class FourLineDisplayUsermod : public Usermod {
}
if (nullptr == u8x8) {
- DEBUG_PRINTLN(F("Display init failed."));
+ USER_PRINTLN(F("Display init failed."));
pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po);
- type = NONE;
+ typeOK=false;
+ strcpy(errorMessage, PSTR("Display init failed"));
return;
}
lineHeight = u8x8->getRows() > 4 ? 2 : 1;
- DEBUG_PRINTLN(F("Starting display."));
+ if (isSPI) {
+ USER_PRINTLN(isHW ? F("Starting display (SPI HW).") : F("Starting display (SPI Soft)."));
+ } else {
+ USER_PRINTLN(isHW ? F("Starting display (I2C HW).") : F("Starting display (I2C Soft)."));
+ }
u8x8->setBusClock(ioFrequency); // can be used for SPI too
u8x8->begin();
+ typeOK = true;
+ drawing = false;
+ reDrawing = false;
setFlipMode(flip);
setVcomh(contrastFix);
setContrast(contrast); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
@@ -450,12 +481,17 @@ class FourLineDisplayUsermod : public Usermod {
* Da loop.
*/
void loop() {
- #ifndef ARDUINO_ARCH_ESP32
- if (!enabled || strip.isUpdating()) return;
+ #if !defined(ARDUINO_ARCH_ESP32) || !defined(FLD_ESP32_USE_THREADS)
+ static unsigned long lastRunTime = 0;
unsigned long now = millis();
+ if (!enabled || !typeOK || (strip.isUpdating() && (now - lastRunTime < 50))) return;
+ lastRunTime = now;
+
if (now < nextUpdate) return;
nextUpdate = now + ((displayTurnedOff && clockMode && showSeconds) ? 1000 : refreshRate);
+ reDrawing = true;
redraw(false);
+ reDrawing = false;
#endif
}
@@ -464,15 +500,47 @@ class FourLineDisplayUsermod : public Usermod {
lastRedraw = millis();
}
+ //function to to check if a redraw or overlay draw is active. Needed for UM Rotary, to avoid random/concurrent drawing
+ bool canDraw(void) {
+ #if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS) // only necessary on ESP32
+ if (drawing) return(false); // overlay draws someting
+ if (reDrawing) return(false); // redraw task draws something
+ #endif
+ return(true);
+ }
+
/**
* Redraw the screen (but only if things have changed
* or if forceRedraw).
*/
void redraw(bool forceRedraw) {
+ #if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS)
+ // use a wrapper onESP32, to ensure the functions is not running several times in parallel !
+ static bool doForceRedraw = false; // for delaying "force redraw"
+
+ if ((overlayUntil > 0) && (millis() >= overlayUntil)) {
+ forceRedraw = true; // Time to display the overlay has elapsed, force redraw needed
+ }
+
+ if (forceRedraw) doForceRedraw = true;
+ if (reDrawing) return; // redraw already active
+ if (drawing) return; // overlay draw active
+
+ reDrawing = true; // set redraw lock
+ if (doForceRedraw) forceRedraw = true;
+ redraw_core(forceRedraw);
+ if (overlayUntil == 0) doForceRedraw = false; // redraw was skipped if overlay is still visible
+ reDrawing = false; // reset activity flag, as redraw has too many early returns that don't take care of this
+ }
+
+ void redraw_core(bool forceRedraw) {
+#endif
bool needRedraw = false;
unsigned long now = millis();
+
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
+ if (nullptr == u8x8) return; // prevent crash in case u8x8 is re-initialized (du to user changing setings)
- if (type == NONE || !enabled) return;
if (overlayUntil > 0) {
if (now >= overlayUntil) {
// Time to display the overlay has elapsed.
@@ -561,6 +629,8 @@ class FourLineDisplayUsermod : public Usermod {
knownnightlight = nightlightActive;
wificonnected = interfacesInited;
+ while (drawing && millis()-now < 150) delay(8); // wait if someone else is drawing
+
// Do the actual drawing
// First row: Icons
draw2x2GlyphIcons();
@@ -584,7 +654,7 @@ class FourLineDisplayUsermod : public Usermod {
if (overlayUntil == 0) {
brightness100 = ((uint16_t)bri*100)/255;
char lineBuffer[4];
- sprintf_P(lineBuffer, PSTR("%-3d"), brightness100);
+ snprintf_P(lineBuffer, 4, PSTR("%-3d"), brightness100);
drawString(1, lineHeight, lineBuffer);
//lastRedraw = millis();
}
@@ -595,7 +665,7 @@ class FourLineDisplayUsermod : public Usermod {
if (overlayUntil == 0) {
fxspeed100 = ((uint16_t)effectSpeed*100)/255;
char lineBuffer[4];
- sprintf_P(lineBuffer, PSTR("%-3d"), fxspeed100);
+ snprintf_P(lineBuffer, 4, PSTR("%-3d"), fxspeed100);
drawString(5, lineHeight, lineBuffer);
//lastRedraw = millis();
}
@@ -606,7 +676,7 @@ class FourLineDisplayUsermod : public Usermod {
if (overlayUntil == 0) {
fxintensity100 = ((uint16_t)effectIntensity*100)/255;
char lineBuffer[4];
- sprintf_P(lineBuffer, PSTR("%-3d"), fxintensity100);
+ snprintf_P(lineBuffer, 4, PSTR("%-3d"), fxintensity100);
drawString(9, lineHeight, lineBuffer);
//lastRedraw = millis();
}
@@ -640,10 +710,12 @@ class FourLineDisplayUsermod : public Usermod {
//Display the current effect or palette (desiredEntry)
// on the appropriate line (row).
void showCurrentEffectOrPalette(int inputEffPal, const char *qstring, uint8_t row) {
- char lineBuffer[MAX_JSON_CHARS];
+ char lineBuffer[MAX_JSON_CHARS] = { '\0' };
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
if (overlayUntil == 0) {
// Find the mode name in JSON
uint8_t printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1);
+ if (printedChars < 2) strcpy(lineBuffer, "invalid"); // catch possible error
if (lineBuffer[0]=='*' && lineBuffer[1]==' ') {
// remove "* " from dynamic palettes
for (byte i=2; i<=printedChars; i++) lineBuffer[i-2] = lineBuffer[i]; //include '\0'
@@ -654,8 +726,8 @@ class FourLineDisplayUsermod : public Usermod {
printedChars -= 5;
}
if (lineHeight == 2) { // use this code for 8 line display
- char smallBuffer1[MAX_MODE_LINE_SPACE];
- char smallBuffer2[MAX_MODE_LINE_SPACE];
+ char smallBuffer1[MAX_MODE_LINE_SPACE+1] = { '\0' };
+ char smallBuffer2[MAX_MODE_LINE_SPACE+1] = { '\0' };
uint8_t smallChars1 = 0;
uint8_t smallChars2 = 0;
if (printedChars < MAX_MODE_LINE_SPACE) { // use big font if the text fits
@@ -682,13 +754,15 @@ class FourLineDisplayUsermod : public Usermod {
}
while (smallChars1 < (MAX_MODE_LINE_SPACE-1)) smallBuffer1[smallChars1++]=' ';
smallBuffer1[smallChars1] = 0;
+ smallBuffer1[MAX_MODE_LINE_SPACE -1] = '\0'; // ensure the string ends where it should (while loop avove can overshoot by 1)
drawString(1, row*lineHeight, smallBuffer1, true);
while (smallChars2 < (MAX_MODE_LINE_SPACE-1)) smallBuffer2[smallChars2++]=' ';
smallBuffer2[smallChars2] = 0;
+ smallBuffer2[MAX_MODE_LINE_SPACE -1] = '\0'; // ensure the string ends where it should (while loop avove can overshoot by 1)
drawString(1, row*lineHeight+1, smallBuffer2, true);
}
} else { // use this code for 4 ling displays
- char smallBuffer3[MAX_MODE_LINE_SPACE+1]; // uses 1x1 icon for mode/palette
+ char smallBuffer3[MAX_MODE_LINE_SPACE+1] = {'\0'}; // uses 1x1 icon for mode/palette
uint8_t smallChars3 = 0;
for (uint8_t i = 0; i < MAX_MODE_LINE_SPACE; i++) smallBuffer3[smallChars3++] = (i >= printedChars) ? ' ' : lineBuffer[i];
smallBuffer3[smallChars3] = 0;
@@ -704,7 +778,7 @@ class FourLineDisplayUsermod : public Usermod {
* to wake up the screen.
*/
bool wakeDisplay() {
- if (type == NONE || !enabled) return false;
+ if (!typeOK || !enabled) return false;
if (displayTurnedOff) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
@@ -725,8 +799,10 @@ class FourLineDisplayUsermod : public Usermod {
* Used in Rotary Encoder usermod.
*/
void overlay(const char* line1, long showHowLong, byte glyphType) {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
+ while ((reDrawing && overlayUntil == 0) && (millis()-now < 250)) delay(10); // wait if someone else is re-drawing
drawing = true;
// Turn the display back on
if (!wakeDisplay()) clear();
@@ -749,6 +825,7 @@ class FourLineDisplayUsermod : public Usermod {
* Clears the screen and prints.
*/
void overlayLogo(long showHowLong) {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
@@ -810,8 +887,10 @@ class FourLineDisplayUsermod : public Usermod {
* Used in Auto Save usermod
*/
void overlay(const char* line1, const char* line2, long showHowLong) {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
+ while ((reDrawing && overlayUntil == 0) && (millis()-now < 250)) delay(10); // wait if someone else is re-drawing
drawing = true;
// Turn the display back on
if (!wakeDisplay()) clear();
@@ -831,6 +910,7 @@ class FourLineDisplayUsermod : public Usermod {
}
void networkOverlay(const char* line1, long showHowLong) {
+ if (!typeOK || !enabled) return; // WLEDMM make sure the display is initialized before we try to draw on it
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
@@ -968,7 +1048,7 @@ class FourLineDisplayUsermod : public Usermod {
#endif
#endif
void onUpdateBegin(bool init) {
- #ifdef ARDUINO_ARCH_ESP32
+ #if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS)
if (init && Display_Task) {
vTaskSuspend(Display_Task); // update is about to begin, disable task to prevent crash
} else {
@@ -976,7 +1056,7 @@ class FourLineDisplayUsermod : public Usermod {
if (Display_Task)
vTaskResume(Display_Task);
else
- xTaskCreatePinnedToCore(
+ xTaskCreateUniversal( // this is guaranteed to work on any ESP32 (single or dual core)
[](void * par) { // Function to implement the task
// see https://www.freertos.org/vtaskdelayuntil.html
const TickType_t xFrequency = REFRESH_RATE_MS * portTICK_PERIOD_MS / 2;
@@ -984,12 +1064,14 @@ class FourLineDisplayUsermod : public Usermod {
for(;;) {
delay(1); // DO NOT DELETE THIS LINE! It is needed to give the IDLE(0) task enough time and to keep the watchdog happy.
// taskYIELD(), yield(), vTaskDelay() and esp_task_wdt_feed() didn't seem to work.
- vTaskDelayUntil(&xLastWakeTime, xFrequency); // release CPU, by doing nothing for REFRESH_RATE_MS millis
+ xLastWakeTime = xTaskGetTickCount(); // workaround for vTaskDelayUntil bug: it does not always keep the last time so we refresh it explicitly
FourLineDisplayUsermod::getInstance()->redraw(false);
+ vTaskDelayUntil(&xLastWakeTime, xFrequency); // release CPU, by doing nothing until next REFRESH_RATE_MS millis
}
},
"4LD", // Name of the task
- 3072, // Stack size in words
+// 3072, // Stack size in words
+ 4096, // bigger Stack size in words
NULL, // Task input parameter
1, // Priority of the task (not idle)
&Display_Task, // Task handle
@@ -1027,6 +1109,8 @@ class FourLineDisplayUsermod : public Usermod {
//}
void appendConfigData() {
+ oappend(SET_F("addHB('4LineDisplay');"));
+
oappend(SET_F("dd=addDropdown('4LineDisplay','type');"));
oappend(SET_F("addOption(dd,'None',0);"));
oappend(SET_F("addOption(dd,'SSD1306',1);"));
@@ -1036,11 +1120,50 @@ class FourLineDisplayUsermod : public Usermod {
oappend(SET_F("addOption(dd,'SSD1305 128x64',5);"));
oappend(SET_F("addOption(dd,'SSD1306 SPI',6);"));
oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);"));
- oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'I2C/SPI CLK','-1 use global');"));
- oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'I2C/SPI DTA','-1 use global');"));
- oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'SPI CS',' ');"));
- oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'SPI DC',' ');"));
- oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'SPI RST',' ');"));
+ bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
+ // WLEDMM add defaults
+ oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'','I2C/SPI CLK');"));
+ oappend(SET_F("dRO('4LineDisplay:pin[]',0);")); // disable read only pins
+ if (isSPI) {
+ oappend(SET_F("rOpt('4LineDisplay:pin[]',0,'use global (")); oappendi(spi_sclk); oappend(")',-1);");
+ #ifdef FLD_PIN_CLOCKSPI
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',0,' ⎌',")); oappendi(FLD_PIN_CLOCKSPI); oappend(");");
+ #endif
+ } else {
+ oappend(SET_F("rOpt('4LineDisplay:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);");
+ #ifdef FLD_PIN_SCL
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',0,' ⎌',")); oappendi(FLD_PIN_SCL); oappend(");");
+ #endif
+ }
+ oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'','I2C/SPI DTA');"));
+ if (isSPI) {
+ oappend(SET_F("rOpt('4LineDisplay:pin[]',1,'use global (")); oappendi(spi_mosi); oappend(")',-1);");
+ #ifdef FLD_PIN_MOSISPI
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',1,' ⎌',")); oappendi(FLD_PIN_MOSISPI); oappend(");");
+ #endif
+ } else {
+ oappend(SET_F("rOpt('4LineDisplay:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);");
+ #ifdef FLD_PIN_SDA
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',1,' ⎌',")); oappendi(FLD_PIN_SDA); oappend(");");
+ #endif
+ }
+ oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'','SPI CS');"));
+ #ifdef FLD_PIN_CS
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',2,' ⎌',")); oappendi(FLD_PIN_CS); oappend(");");
+ #endif
+ oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'','SPI DC');"));
+ #ifdef FLD_PIN_DC
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',3,' ⎌',")); oappendi(FLD_PIN_DC); oappend(");");
+ #endif
+ oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'','SPI RST');"));
+ #ifdef FLD_PIN_RESET
+ oappend(SET_F("xOpt('4LineDisplay:pin[]',4,' ⎌',")); oappendi(FLD_PIN_RESET); oappend(");");
+ #endif
+
+ //WLEDMM add errorMessage to um settings
+ if (strcmp(errorMessage, "") != 0) {
+ oappend(SET_F("addInfo('errorMessage', 0, 'error: ")); oappend(errorMessage); oappend("! Correct and reboot');");
+ }
}
/*
@@ -1061,11 +1184,11 @@ class FourLineDisplayUsermod : public Usermod {
// determine if we are using global HW pins (data & clock)
int8_t hw_dta, hw_clk;
if ((type == SSD1306_SPI || type == SSD1306_SPI64)) {
- hw_clk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
- hw_dta = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
+ hw_clk = spi_sclk;
+ hw_dta = spi_mosi;
} else {
- hw_clk = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
- hw_dta = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
+ hw_clk = i2c_scl;
+ hw_dta = i2c_sda;
}
JsonObject top = root.createNestedObject(FPSTR(_name));
@@ -1081,7 +1204,7 @@ class FourLineDisplayUsermod : public Usermod {
top[FPSTR(_flip)] = (bool) flip;
top[FPSTR(_contrast)] = contrast;
top[FPSTR(_contrastFix)] = (bool) contrastFix;
- #ifndef ARDUINO_ARCH_ESP32
+ #if !defined(ARDUINO_ARCH_ESP32) || !defined(FLD_ESP32_USE_THREADS)
top[FPSTR(_refreshRate)] = refreshRate;
#endif
top[FPSTR(_screenTimeOut)] = screenTimeout/1000;
@@ -1117,7 +1240,7 @@ class FourLineDisplayUsermod : public Usermod {
for (byte i=0; i<5; i++) ioPin[i] = top["pin"][i] | ioPin[i];
flip = top[FPSTR(_flip)] | flip;
contrast = top[FPSTR(_contrast)] | contrast;
- #ifndef ARDUINO_ARCH_ESP32
+ #if !defined(ARDUINO_ARCH_ESP32) || !defined(FLD_ESP32_USE_THREADS)
refreshRate = top[FPSTR(_refreshRate)] | refreshRate;
refreshRate = min(5000, max(250, (int)refreshRate));
#endif
@@ -1141,20 +1264,28 @@ class FourLineDisplayUsermod : public Usermod {
// changing parameters from settings page
bool pinsChanged = false;
for (byte i=0; i<5; i++) if (ioPin[i] != oldPin[i]) { pinsChanged = true; break; }
+ #if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS)
+ unsigned long now = millis();
+ while ((drawing || reDrawing) && millis()-now < 300) delay(10); // wait if someone else is drawing
+ #endif
+ drawing = false;
+ reDrawing = false;
+
if (pinsChanged || type!=newType) {
- if (type != NONE) delete u8x8;
+ if (typeOK) {
+ typeOK = false;
+ if (u8x8 != nullptr) delete u8x8;
+ u8x8 = nullptr;
+ USER_PRINTLN(F("Display terminated."));
+ }
PinOwner po = PinOwner::UM_FourLineDisplay;
bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
if (isSPI) {
pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po);
- uint8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
- uint8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
- bool isHW = (oldPin[0]==hw_sclk && oldPin[1]==hw_mosi);
+ bool isHW = (oldPin[0]==spi_sclk && oldPin[1]==spi_mosi);
if (isHW) po = PinOwner::HW_SPI;
} else {
- uint8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
- uint8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
- bool isHW = (oldPin[0]==hw_scl && oldPin[1]==hw_sda);
+ bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda);
if (isHW) po = PinOwner::HW_I2C;
}
pinManager.deallocateMultiplePins((const uint8_t *)oldPin, 2, po);
@@ -1162,10 +1293,12 @@ class FourLineDisplayUsermod : public Usermod {
setup();
needsRedraw |= true;
} else {
- u8x8->setBusClock(ioFrequency); // can be used for SPI too
- setVcomh(contrastFix);
- setContrast(contrast);
- setFlipMode(flip);
+ if (enabled && typeOK && (nullptr != u8x8)) { // WLEDMM ensure we have a valid, active driver
+ u8x8->setBusClock(ioFrequency); // can be used for SPI too
+ setVcomh(contrastFix);
+ setContrast(contrast);
+ setFlipMode(flip);
+ }
}
knownHour = 99;
if (needsRedraw && !wakeDisplay()) redraw(true);
@@ -1197,4 +1330,6 @@ const char FourLineDisplayUsermod::_showSeconds[] PROGMEM = "showSeconds";
const char FourLineDisplayUsermod::_busClkFrequency[] PROGMEM = "i2c-freq-kHz";
const char FourLineDisplayUsermod::_contrastFix[] PROGMEM = "contrastFix";
+#ifdef ARDUINO_ARCH_ESP32
FourLineDisplayUsermod *FourLineDisplayUsermod::instance = nullptr;
+#endif
diff --git a/usermods/usermod_v2_games/usermod_v2_games.h b/usermods/usermod_v2_games/usermod_v2_games.h
index a26b5d5a..5256f5c5 100644
--- a/usermods/usermod_v2_games/usermod_v2_games.h
+++ b/usermods/usermod_v2_games/usermod_v2_games.h
@@ -172,7 +172,7 @@ uint16_t mode_pongGame(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_PONGGAME[] PROGMEM = "🎮 Pong@!;!;!;2d";
+static const char _data_FX_MODE_PONGGAME[] PROGMEM = "🎮 Pong ☾@!;!;!;2";
//https://howtomechatronics.com/tutorials/arduino/arduino-and-mpu6050-accelerometer-and-gyroscope-tutorial/
@@ -207,7 +207,7 @@ uint16_t mode_IMUTest(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_IMUTest[] PROGMEM = "🎮 IMUTest@;;;2d";
+static const char _data_FX_MODE_IMUTest[] PROGMEM = "🎮 IMUTest ☾@;;;2d";
#endif
@@ -264,6 +264,7 @@ class Frame3D {
points.push_back(voxel);
}
void drawLineXYZ(Voxel from, Voxel to, uint32_t col) {
+ //causes crash on ESP8266: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores, maybe not enough free heap
for (float x=MIN(from.x, to.x); x<=MAX(from.x, to.x); x+=.05)
for (float y=MIN(from.y, to.y); y<=MAX(from.y, to.y); y+=.05)
for (float z=MIN(from.z, to.z); z<=MAX(from.z, to.z); z+=.05)
@@ -318,7 +319,7 @@ uint16_t mode_3DIMUCube(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_3DIMUCube[] PROGMEM = "🎮 3DIMUCube@,Perspective;!;!;,pal=1,2d"; //random cycle
+static const char _data_FX_MODE_3DIMUCube[] PROGMEM = "🎮 3DIMUCube ☾@,Perspective;!;!;2;pal=1"; //random cycle
class GamesUsermod : public Usermod {
private:
@@ -329,9 +330,9 @@ class GamesUsermod : public Usermod {
strip.addEffect(255, &mode_pongGame, _data_FX_MODE_PONGGAME);
#ifdef USERMOD_MPU6050_IMU
IMU = (MPU6050Driver *)usermods.lookup(USERMOD_ID_IMU);
- #ifdef WLED_DEBUG
+ // #ifdef WLED_DEBUG
strip.addEffect(255, &mode_IMUTest, _data_FX_MODE_IMUTest);
- #endif
+ // #endif
#endif
strip.addEffect(255, &mode_3DIMUCube, _data_FX_MODE_3DIMUCube); //works also without IMU
}
diff --git a/usermods/usermod_v2_mode_sort/readme.md b/usermods/usermod_v2_mode_sort/readme.md
index b4fe90e7..c24322f3 100644
--- a/usermods/usermod_v2_mode_sort/readme.md
+++ b/usermods/usermod_v2_mode_sort/readme.md
@@ -8,26 +8,26 @@ palettes to other usermods. Notably it provides:
```char **getModesQStrings()```
-Provides an array of char* (pointers) to the names of the
-palettes within JSON_mode_names, in the same order as
+Provides a char* array (pointers) to the names of the
+palettes contained in JSON_mode_names, in the same order as
JSON_mode_names. These strings end in double quote (")
(or \0 if there is a problem).
```byte *getModesAlphaIndexes()```
-An array of byte designating the indexes of names of the
+A byte array designating the indexes of names of the
modes in alphabetical order. "Solid" will always remain
-at the front of the list.
+at the top of the list.
```char **getPalettesQStrings()```
-Provides an array of char* (pointers) to the names of the
-palettes within JSON_palette_names, in the same order as
+Provides a char* array (pointers) to the names of the
+palettes contained in JSON_palette_names, in the same order as
JSON_palette_names. These strings end in double quote (")
(or \0 if there is a problem).
```byte *getPalettesAlphaIndexes()```
-An array of byte designating the indexes of names of the
+A byte array designating the indexes of names of the
palettes in alphabetical order. "Default" and those
-starting with "(" will always remain at the front of the list.
+starting with "(" will always remain at the top of the list.
diff --git a/usermods/usermod_v2_ping_pong_clock/readme.md b/usermods/usermod_v2_ping_pong_clock/readme.md
index 8731222f..9f01b3eb 100644
--- a/usermods/usermod_v2_ping_pong_clock/readme.md
+++ b/usermods/usermod_v2_ping_pong_clock/readme.md
@@ -1,8 +1,10 @@
# Ping Pong LED Clock
-This Usermod File contains a modification to use WLED in combination with the Ping Pong Ball LED Clock as built in [Instructables](https://www.instructables.com/Ping-Pong-Ball-LED-Clock/).
+Contains a modification to use WLED in combination with the Ping Pong Ball LED Clock as built in [Instructables](https://www.instructables.com/Ping-Pong-Ball-LED-Clock/).
## Installation
-To install this Usermod you instruct PlatformIO to compile the Projekt with the USERMOD_PING_PONG_CLOCK flag. WLED then automatically provides you with various settings in the Usermod Page to configure this Usermod.
-Note: If your clock is bigger or smaller then mine, you may have to update the led indices for the indivdual numbers and the base indices.
+To install this Usermod, you instruct PlatformIO to compile the Project with the USERMOD_PING_PONG_CLOCK flag.
+WLED then automatically provides you with various settings on the Usermod Page.
+
+Note: Depending on the size of your clock, you may have to update the led indices for the indivdual numbers and the base indices.
diff --git a/usermods/usermod_v2_rotary_encoder_ui/readme.md b/usermods/usermod_v2_rotary_encoder_ui/readme.md
index b5a8a924..5e4f3cff 100644
--- a/usermods/usermod_v2_rotary_encoder_ui/readme.md
+++ b/usermods/usermod_v2_rotary_encoder_ui/readme.md
@@ -20,10 +20,10 @@ This file should be placed in the same directory as `platformio.ini`.
* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp
also tells this usermod that the display is available
(see the Four Line Display usermod `readme.md` for more details)
-* `ENCODER_DT_PIN` - The encoders DT pin, defaults to 12
-* `ENCODER_CLK_PIN` - The encoders CLK pin, defaults to 14
-* `ENCODER_SW_PIN` - The encoders SW pin, defaults to 13
-* `USERMOD_ROTARY_ENCODER_GPIO` - The GPIO functionality:
+* `ENCODER_DT_PIN` - defaults to 12
+* `ENCODER_CLK_PIN` - defaults to 14
+* `ENCODER_SW_PIN` - defaults to 13
+* `USERMOD_ROTARY_ENCODER_GPIO` - GPIO functionality:
`INPUT_PULLUP` to use internal pull-up
`INPUT` to use pull-up on the PCB
diff --git a/usermods/usermod_v2_rotary_encoder_ui/usermod_v2_rotary_encoder_ui.h b/usermods/usermod_v2_rotary_encoder_ui/usermod_v2_rotary_encoder_ui.h
index dc96ee52..1e85c518 100644
--- a/usermods/usermod_v2_rotary_encoder_ui/usermod_v2_rotary_encoder_ui.h
+++ b/usermods/usermod_v2_rotary_encoder_ui/usermod_v2_rotary_encoder_ui.h
@@ -99,6 +99,12 @@ public:
{
DEBUG_PRINTLN(F("Usermod Rotary Encoder init."));
PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } };
+ if ((pinA < 0) || (pinB < 0)) { //WLEDMM catch error: [ 1839][E][esp32-hal-gpio.c:102] __pinMode(): Invalid pin selected
+ enabled = false;
+ DEBUG_PRINTLN(F("Invalid GPIO pins for Usermod Rotary Encoder.")); //WLEDMM add debug info
+ return;
+ }
+
if (!pinManager.allocateMultiplePins(pins, 3, PinOwner::UM_RotaryEncoderUI)) {
// BUG: configuring this usermod with conflicting pins
// will cause it to de-allocate pins it does not own
@@ -116,8 +122,7 @@ public:
#endif
pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
- pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
-
+ if (pinC >= 0) pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO); // WLEDMM catch error
currentTime = millis();
loopTime = currentTime;
@@ -136,6 +141,7 @@ public:
#endif
initDone = true;
+ USER_PRINTLN(F("Rotary encoder setup completed.")); // WLEDMM inform user
}
/*
@@ -172,7 +178,7 @@ public:
if (currentTime >= (loopTime + 2)) // 2ms since last check of encoder = 500Hz
{
- button_state = digitalRead(pinC);
+ if (pinC >= 0) button_state = digitalRead(pinC);
if (prev_button_state != button_state)
{
if (button_state == LOW)
diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md b/usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md
index a140f25b..811c50d0 100644
--- a/usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md
+++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/readme.md
@@ -4,12 +4,12 @@ Thank you to the authors of the original version of these usermods. It would not
"usermod_v2_four_line_display"
"usermod_v2_rotary_encoder_ui"
-The core of these usermods are a copy of the originals. The main changes are done to the FourLineDisplay usermod.
+The core of these usermods are a copy of the originals. The main changes are to the FourLineDisplay usermod.
The display usermod UI has been completely changed.
The changes made to the RotaryEncoder usermod were made to support the new UI in the display usermod.
-Without the display it functions identical to the original.
+Without the display, it functions identical to the original.
The original "usermod_v2_auto_save" will not work with the display just yet.
Press the encoder to cycle through the options:
@@ -22,17 +22,17 @@ Press the encoder to cycle through the options:
*Saturation (only if display is used)
Press and hold the encoder to display Network Info
- if AP is active then it will display AP ssid and Password
+ if AP is active, it will display the AP, SSID and Password
-Also shows if the timer is enabled
+Also shows if the timer is enabled.
[See the pair of usermods in action](https://www.youtube.com/watch?v=ulZnBt9z3TI)
## Installation
Please refer to the original `usermod_v2_rotary_encoder_ui` readme for the main instructions
-Then to activate this alternative usermod add `#define USE_ALT_DISPlAY` to the `usermods_list.cpp` file,
- or add `-D USE_ALT_DISPlAY` to the original `platformio_override.ini.sample` file
+Then to activate this alternative usermod add `#define USE_ALT_DISPLAY` to the `usermods_list.cpp` file,
+ or add `-D USE_ALT_DISPLAY` to the original `platformio_override.ini.sample` file
### PlatformIO requirements
@@ -42,4 +42,4 @@ Note: the Four Line Display usermod requires the libraries `U8g2` and `Wire`.
## Change Log
2021-10
-* First public release
\ No newline at end of file
+* First public release
diff --git a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h
index 13dd0dea..526ee7a0 100644
--- a/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h
+++ b/usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h
@@ -191,7 +191,7 @@ private:
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount());
- palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount());
+ palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount()); // only use internal palettes
// How many palette names start with '*' and should not be sorted?
// (Also skipping the first one, 'Default').
@@ -267,6 +267,12 @@ public:
{
DEBUG_PRINTLN(F("Usermod Rotary Encoder init."));
PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } };
+ if ((pinA < 0) || (pinB < 0)) { //WLEDMM catch error: [ 1839][E][esp32-hal-gpio.c:102] __pinMode(): Invalid pin selected
+ enabled = false;
+ DEBUG_PRINTLN(F("Invalid GPIO pins for Usermod Rotary Encoder (ALT).")); //WLEDMM add debug info
+ return;
+ }
+ if (!enabled) return; // WLEDMM don't allocated PINS if disabled
if (!pinManager.allocateMultiplePins(pins, 3, PinOwner::UM_RotaryEncoderUI)) {
// BUG: configuring this usermod with conflicting pins
// will cause it to de-allocate pins it does not own
@@ -284,7 +290,7 @@ public:
#endif
pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
- pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
+ if (pinC >= 0) pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO); // WLEDMM catch error
loopTime = millis();
@@ -305,6 +311,7 @@ public:
Enc_A = digitalRead(pinA); // Read encoder pins
Enc_B = digitalRead(pinB);
Enc_A_prev = Enc_A;
+ USER_PRINTLN(F("Rotary encoder (ALT) setup completed.")); // WLEDMM inform user
}
/*
@@ -349,7 +356,8 @@ public:
{
loopTime = currentTime; // Updates loopTime
- bool buttonPressed = !digitalRead(pinC); //0=pressed, 1=released
+ bool buttonPressed = false;
+ if (pinC >= 0) buttonPressed = !digitalRead(pinC); //0=pressed, 1=released
if (buttonPressed) {
if (!buttonPressedBefore) buttonPressedTime = currentTime;
buttonPressedBefore = true;
@@ -375,7 +383,7 @@ public:
buttonWaitTime = 0;
char newState = select_state + 1;
bool changedState = false;
- char lineBuffer[64];
+ char lineBuffer[64] = { '\0' };
do {
// finde new state
switch (newState) {
@@ -517,7 +525,8 @@ public:
bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
- display->updateBrightness();
+ if (display->canDraw()) // only draw if nothing else is drawing
+ display->updateBrightness();
#endif
}
@@ -546,7 +555,8 @@ public:
}
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
- display->showCurrentEffectOrPalette(effectCurrent, JSON_mode_names, 3);
+ if (display->canDraw()) // only draw if nothing else is drawing
+ display->showCurrentEffectOrPalette(effectCurrent, JSON_mode_names, 3);
#endif
}
@@ -574,7 +584,8 @@ public:
}
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
- display->updateSpeed();
+ if (display->canDraw()) // only draw if nothing else is drawing
+ display->updateSpeed();
#endif
}
@@ -602,14 +613,15 @@ public:
}
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
- display->updateIntensity();
+ if (display->canDraw()) // only draw if nothing else is drawing
+ display->updateIntensity();
#endif
}
void changeCustom(uint8_t par, bool increase) {
- uint8_t val = 0;
#ifdef USERMOD_FOUR_LINE_DISPLAY
+ uint8_t val = 0;
if (display && display->wakeDisplay()) {
display->redraw(true);
// Throw away wake up input
@@ -621,11 +633,13 @@ public:
if (applyToAll) {
uint8_t id = strip.getFirstSelectedSegId();
Segment& sid = strip.getSegment(id);
+ #ifdef USERMOD_FOUR_LINE_DISPLAY
switch (par) {
case 3: val = sid.custom3 = max(min((increase ? sid.custom3+fadeAmount : sid.custom3-fadeAmount), 255), 0); break;
case 2: val = sid.custom2 = max(min((increase ? sid.custom2+fadeAmount : sid.custom2-fadeAmount), 255), 0); break;
default: val = sid.custom1 = max(min((increase ? sid.custom1+fadeAmount : sid.custom1-fadeAmount), 255), 0); break;
}
+ #endif
for (byte i=0; ishowCurrentEffectOrPalette(effectPalette, JSON_palette_names, 2);
+ if (display->canDraw()) // only draw if nothing else is drawing
+ display->showCurrentEffectOrPalette(effectPalette, JSON_palette_names, 2);
#endif
}
@@ -752,8 +769,8 @@ public:
if (presetHigh && presetLow && presetHigh > presetLow) {
StaticJsonDocument<64> root;
char str[64] = { '\0' };
- sprintf_P(str, PSTR("%d~%d~%s"), presetLow, presetHigh, increase?"":"-");
- root[F("ps")] = str;
+ snprintf_P(str, 64, PSTR("%d~%d~%s"), presetLow, presetHigh, increase?"":"-");
+ root["ps"] = str;
deserializeState(root.as(), CALL_MODE_BUTTON_PRESET);
/*
String apireq = F("win&PL=~");
@@ -857,6 +874,22 @@ public:
DEBUG_PRINTLN(F("Rotary Encoder config saved."));
}
+ //WLEDMM: add appendConfigData
+ void appendConfigData()
+ {
+ oappend(SET_F("addHB('Rotary-Encoder');"));
+
+ #ifdef ENCODER_DT_PIN
+ oappend(SET_F("xOpt('Rotary-Encoder:DT-pin',1,' ⎌',")); oappendi(ENCODER_DT_PIN); oappend(");");
+ #endif
+ #ifdef ENCODER_CLK_PIN
+ oappend(SET_F("xOpt('Rotary-Encoder:CLK-pin',1,' ⎌',")); oappendi(ENCODER_CLK_PIN); oappend(");");
+ #endif
+ #ifdef ENCODER_SW_PIN
+ oappend(SET_F("xOpt('Rotary-Encoder:SW-pin',1,' ⎌',")); oappendi(ENCODER_SW_PIN); oappend(");");
+ #endif
+ }
+
/**
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
*
@@ -899,7 +932,7 @@ public:
pinA = newDTpin;
pinB = newCLKpin;
pinC = newSWpin;
- if (pinA<0 || pinB<0 || pinC<0) {
+ if (pinA<0 || pinB<0) { // WLEDMM support for rotary without pushbutton
enabled = false;
return true;
}
diff --git a/usermods/usermod_v2_weather/readme.md b/usermods/usermod_v2_weather/readme.md
index 4417e4f2..aedfa98d 100644
--- a/usermods/usermod_v2_weather/readme.md
+++ b/usermods/usermod_v2_weather/readme.md
@@ -14,7 +14,7 @@ uint16_t mode_2DWeather(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_2DWEATHER[] PROGMEM = "Weather@;!;!;pal=54,2d"; //temperature palette
+static const char _data_FX_MODE_2DWEATHER[] PROGMEM = "Weather@;!;!;2;pal=54"; //temperature palette
```
* then activated in the usermod setup function
```c++
diff --git a/usermods/usermod_v2_weather/usermod_v2_weather.h b/usermods/usermod_v2_weather/usermod_v2_weather.h
index eef09006..7965e79d 100644
--- a/usermods/usermod_v2_weather/usermod_v2_weather.h
+++ b/usermods/usermod_v2_weather/usermod_v2_weather.h
@@ -94,7 +94,7 @@ uint16_t mode_2DWeather(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_2DWEATHER[] PROGMEM = "Weather@;!;!;pal=54,2d"; //temperature palette
+static const char _data_FX_MODE_2DWEATHER[] PROGMEM = "Weather ☾@;!;!;2;pal=54"; //temperature palette
//utility function, move somewhere else???
void epochToString(time_t time, char *timeString) {
@@ -317,13 +317,15 @@ class WeatherUsermod : public Usermod {
void appendConfigData()
{
- oappend(SET_F("dd=addDropdown('WeatherUserMod','units');"));
+ oappend(SET_F("addInfo('Weather:help',0,'');"));
+
+ oappend(SET_F("dd=addDropdown('Weather','units');"));
oappend(SET_F("addOption(dd,'Kelvin',0);"));
oappend(SET_F("addOption(dd,'Celcius',1);"));
oappend(SET_F("addOption(dd,'Fahrenheit',2);"));
- oappend(SET_F("addInfo('WeatherUserMod:units',1,'Set time and location in time settings');"));
- oappend(SET_F("addInfo('WeatherUserMod:apiKey',1,'Create acount on openweathermap.org and copy the key');"));
- oappend(SET_F("addInfo('WeatherUserMod:minTemp',1,'Changing values: Reboot to (re)load forecast');"));
+ oappend(SET_F("addInfo('Weather:units',1,'Set time and location in time settings');"));
+ oappend(SET_F("addInfo('Weather:apiKey',1,'Create acount on openweathermap.org and copy the key');"));
+ oappend(SET_F("addInfo('Weather:minTemp',1,'Changing values: Reboot to (re)load forecast');"));
}
/*
@@ -348,7 +350,7 @@ class WeatherUsermod : public Usermod {
};
// strings to reduce flash memory usage (used more than twice)
-const char WeatherUsermod::_name[] PROGMEM = "WeatherUserMod";
+const char WeatherUsermod::_name[] PROGMEM = "Weather";
// example openweathermap data
// {"cod":"200","message":0,"cnt":40,"list":[
diff --git a/usermods/usermod_v2_word_clock/readme.md b/usermods/usermod_v2_word_clock/readme.md
index 7b81582f..1dde2223 100644
--- a/usermods/usermod_v2_word_clock/readme.md
+++ b/usermods/usermod_v2_word_clock/readme.md
@@ -1,8 +1,8 @@
# Word Clock Usermod V2
-This usermod can be used to drive a wordclock with a 11x10 pixel matrix with WLED. There are also 4 additional dots for the minutes.
-The visualisation is desribed in 4 mask with LED numbers (single dots for minutes, minutes, hours and "clock/Uhr"). The index of the LEDs in the masks always starts with the index 0, even if the ledOffset is not 0.
-There are 3 parameters to change the behaviour:
+This usermod drives an 11x10 pixel matrix wordclock with WLED. There are 4 additional dots for the minutes.
+The visualisation is described by 4 masks with LED numbers (single dots for minutes, minutes, hours and "clock"). The index of the LEDs in the masks always starts at 0, even if the ledOffset is not 0.
+There are 3 parameters that control behavior:
active: enable/disable usermod
diplayItIs: enable/disable display of "Es ist" on the clock
@@ -10,23 +10,23 @@ ledOffset: number of LEDs before the wordclock LEDs
### Update for alternatative wiring pattern
Based on this fantastic work I added an alternative wiring pattern.
-For original you have to use a long wire to connect DO - DI from first line to the next line.
+The original used a long wire to connect DO to DI, from one line to the next line.
-I wired my clock in meander style. So the first LED in second line is in the right.
-With this problem every second line was inverted and showed the wrong letter.
+I wired my clock in meander style. So the first LED in the second line is on the right.
+With this method, every other line was inverted and showed the wrong letter.
-I added a switch in usermod called "meander wiring?" to enable/disable alternativ wiring pattern.
+I added a switch in usermod called "meander wiring?" to enable/disable the alternate wiring pattern.
## Installation
Copy and update the example `platformio_override.ini.sample`
-from the Rotary Encoder UI usermode folder to the root directory of your particular build.
+from the Rotary Encoder UI usermod folder to the root directory of your particular build.
This file should be placed in the same directory as `platformio.ini`.
### Define Your Options
-* `USERMOD_WORDCLOCK` - define this to have this the Auto Save usermod included wled00\usermods_list.cpp
+* `USERMOD_WORDCLOCK` - define this to have this usermod included wled00\usermods_list.cpp
### PlatformIO requirements
diff --git a/usermods/usermod_v2_word_clock/usermod_v2_word_clock.h b/usermods/usermod_v2_word_clock/usermod_v2_word_clock.h
index 1068cd96..c825a7af 100644
--- a/usermods/usermod_v2_word_clock/usermod_v2_word_clock.h
+++ b/usermods/usermod_v2_word_clock/usermod_v2_word_clock.h
@@ -25,6 +25,7 @@ class WordClockUsermod : public Usermod
bool displayItIs = false;
int ledOffset = 100;
bool meander = false;
+ bool nord = false;
// defines for mask sizes
#define maskSizeLeds 114
@@ -37,7 +38,7 @@ class WordClockUsermod : public Usermod
// "minute" masks
// Normal wiring
- const int maskMinutes[12][maskSizeMinutes] =
+ const int maskMinutes[14][maskSizeMinutes] =
{
{107, 108, 109, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // :00
{ 7, 8, 9, 10, 40, 41, 42, 43, -1, -1, -1, -1}, // :05 fünf nach
@@ -50,11 +51,13 @@ class WordClockUsermod : public Usermod
{ 15, 16, 17, 18, 19, 20, 21, 33, 34, 35, -1, -1}, // :40 zwanzig vor
{ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1}, // :45 dreiviertel
{ 11, 12, 13, 14, 33, 34, 35, -1, -1, -1, -1, -1}, // :50 zehn vor
- { 7, 8, 9, 10, 33, 34, 35, -1, -1, -1, -1, -1} // :55 fünf vor
+ { 7, 8, 9, 10, 33, 34, 35, -1, -1, -1, -1, -1}, // :55 fünf vor
+ { 26, 27, 28, 29, 30, 31, 32, 40, 41, 42, 43, -1}, // :15 alternative viertel nach
+ { 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1} // :45 alternative viertel vor
};
// Meander wiring
- const int maskMinutesMea[12][maskSizeMinutesMea] =
+ const int maskMinutesMea[14][maskSizeMinutesMea] =
{
{ 99, 100, 101, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // :00
{ 7, 8, 9, 10, 33, 34, 35, 36, -1, -1, -1, -1}, // :05 fünf nach
@@ -67,9 +70,12 @@ class WordClockUsermod : public Usermod
{ 11, 12, 13, 14, 15, 16, 17, 41, 42, 43, -1, -1}, // :40 zwanzig vor
{ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1}, // :45 dreiviertel
{ 18, 19, 20, 21, 41, 42, 43, -1, -1, -1, -1, -1}, // :50 zehn vor
- { 7, 8, 9, 10, 41, 42, 43, -1, -1, -1, -1, -1} // :55 fünf vor
+ { 7, 8, 9, 10, 41, 42, 43, -1, -1, -1, -1, -1}, // :55 fünf vor
+ { 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -1}, // :15 alternative viertel nach
+ { 26, 27, 28, 29, 30, 31, 32, 41, 42, 43, -1, -1} // :45 alternative viertel vor
};
+
// hour masks
// Normal wiring
const int maskHours[13][maskSizeHours] =
@@ -242,9 +248,15 @@ class WordClockUsermod : public Usermod
setHours(hours, false);
break;
case 3:
- // viertel
- setMinutes(3);
- setHours(hours + 1, false);
+ if (nord) {
+ // viertel nach
+ setMinutes(12);
+ setHours(hours, false);
+ } else {
+ // viertel
+ setMinutes(3);
+ setHours(hours + 1, false);
+ };
break;
case 4:
// 20 nach
@@ -272,8 +284,13 @@ class WordClockUsermod : public Usermod
setHours(hours + 1, false);
break;
case 9:
- // viertel vor
- setMinutes(9);
+ // viertel vor bzw dreiviertel
+ if (nord) {
+ setMinutes(9);
+ }
+ else {
+ setMinutes(12);
+ }
setHours(hours + 1, false);
break;
case 10:
@@ -410,6 +427,7 @@ class WordClockUsermod : public Usermod
top["displayItIs"] = displayItIs;
top["ledOffset"] = ledOffset;
top["Meander wiring?"] = meander;
+ top["Norddeutsch"] = nord;
}
/*
@@ -440,6 +458,7 @@ class WordClockUsermod : public Usermod
configComplete &= getJsonValue(top["displayItIs"], displayItIs);
configComplete &= getJsonValue(top["ledOffset"], ledOffset);
configComplete &= getJsonValue(top["Meander wiring?"], meander);
+ configComplete &= getJsonValue(top["Norddeutsch"], nord);
return configComplete;
}
diff --git a/usermods/wizlights/readme.md b/usermods/wizlights/readme.md
index 802a3798..a0e0a8b8 100644
--- a/usermods/wizlights/readme.md
+++ b/usermods/wizlights/readme.md
@@ -1,6 +1,6 @@
# Controlling Wiz lights
-This usermod allows the control of [WiZ](https://www.wizconnected.com/en/consumer/) lights that are in the same network as the WLED controller.
+Enabless controlling [WiZ](https://www.wizconnected.com/en/consumer/) lights that are part of the same network as the WLED controller.
The mod takes the colors from the first few pixels and sends them to the lights.
@@ -8,22 +8,22 @@ The mod takes the colors from the first few pixels and sends them to the lights.
- Interval (ms)
- How frequently to update the WiZ lights, in milliseconds.
- - Setting too low may causse ESP to become unresponsive.
+ - Setting it too low may causse the ESP to become unresponsive.
- Send Delay (ms)
- An optional millisecond delay after updating each WiZ light.
- - Can help smooth out effects when using a larger number of WiZ lights
+ - Can help smooth out effects when using a large number of WiZ lights
- Use Enhanced White
- - Enables using the WiZ lights onboard white LEDs instead of sending maximum RGB values.
+ - Uses the WiZ lights onboard white LEDs instead of sending maximum RGB values.
- Tunable with warm and cool LEDs as supported by WiZ bulbs
- - Note: Only sent when max RGB value is set, need to have automatic brightness limiter disabled
- - ToDo: Have better logic for white value mixing to better take advantage of the lights capabilities
+ - Note: Only sent when max RGB value is set, the automatic brightness limiter must be disabled
+ - ToDo: Have better logic for white value mixing to take advantage of the light's capabilities
- Always Force Update
- - Can be enabled to always send update message to light, even when color matches what was previously sent.
+ - Can be enabled to always send update message to light even if the new value matches the old value.
- Force update every x minutes
- - Configuration option to allow adjusting the default force update timeout of 5 minutes.
- - Setting to 0 has the same impact as enabling Always Force Update
+ - adjusts the default force update timeout of 5 minutes.
+ - Setting to 0 is the same as enabling Always Force Update
-
-Then enter the IPs for the lights to be controlled, in order. There is currently a limit of 15 devices that can be controled, but that number
+Next, enter the IP addresses for the lights to be controlled, in order. The limit is 15 devices, but that number
can be easily changed by updating _MAX_WIZ_LIGHTS_.
@@ -31,5 +31,5 @@ can be easily changed by updating _MAX_WIZ_LIGHTS_.
## Related project
-If you use these lights and python, make sure to check out the [pywizlight](https://github.com/sbidy/pywizlight) project. I learned how to
+If you use these lights and python, make sure to check out the [pywizlight](https://github.com/sbidy/pywizlight) project. You can learn how to
format the messages to control the lights from that project.
diff --git a/usermods/wizlights/wizlights.h b/usermods/wizlights/wizlights.h
index c588f00e..08d20493 100644
--- a/usermods/wizlights/wizlights.h
+++ b/usermods/wizlights/wizlights.h
@@ -75,6 +75,10 @@ class WizLightsUsermod : public Usermod {
UDP.endPacket();
}
+ // Override definition so it compiles
+ void setup() {
+
+ }
// TODO: Check millis() rollover
diff --git a/usermods/word-clock-matrix/readme.md b/usermods/word-clock-matrix/readme.md
index eb68f515..cfaa93e2 100644
--- a/usermods/word-clock-matrix/readme.md
+++ b/usermods/word-clock-matrix/readme.md
@@ -2,8 +2,8 @@
By @bwente
-See https://www.hackster.io/bwente/word-clock-with-just-two-components-073834 for the hardware guide!
-Includes a customizable feature to lower the brightness at night.
+See https://www.hackster.io/bwente/word-clock-with-just-two-components-073834 for the hardware guide!
+Includes a customizable feature to reduce the brightness at night.

diff --git a/wled00/FX.cpp b/wled00/FX.cpp
index adde641a..8915e118 100644
--- a/wled00/FX.cpp
+++ b/wled00/FX.cpp
@@ -24,12 +24,16 @@
Modified heavily for WLED
*/
-#include "FX.h"
#include "wled.h"
+#include "FX.h"
#include "fcn_declare.h"
#define IBN 5100
-#define PALETTE_SOLID_WRAP (strip.paletteBlend == 1 || strip.paletteBlend == 3)
+
+// paletteBlend: 0 - wrap when moving, 1 - always wrap, 2 - never wrap, 3 - none (undefined)
+#define PALETTE_SOLID_WRAP (strip.paletteBlend == 1 || strip.paletteBlend == 3)
+#define PALETTE_MOVING_WRAP !(strip.paletteBlend == 2 || (strip.paletteBlend == 0 && SEGMENT.speed == 0))
+
#define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16))
// effect utility functions
@@ -44,9 +48,9 @@ uint16_t triwave16(uint16_t in) {
}
/*
- * Generates a tristate square wave w/ attac & decay
+ * Generates a tristate square wave w/ attac & decay
* @param x input value 0-255
- * @param pulsewidth 0-127
+ * @param pulsewidth 0-127
* @param attdec attac & decay, max. pulsewidth / 2
* @returns signed waveform value
*/
@@ -62,7 +66,7 @@ int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) {
}
else if (x < pulsewidth - attdec) { //max
return a;
- }
+ }
else if (x < pulsewidth) { //dec to 0
return (int16_t) (pulsewidth - x) * a / attdec;
}
@@ -93,13 +97,13 @@ uint16_t blink(uint32_t color1, uint32_t color2, bool strobe, bool do_palette) {
cycleTime += FRAMETIME*2;
uint32_t it = strip.now / cycleTime;
uint32_t rem = strip.now % cycleTime;
-
+
bool on = false;
if (it != SEGENV.step //new iteration, force on state for one frame, even if set time is too brief
- || rem <= onTime) {
+ || rem <= onTime) {
on = true;
}
-
+
SEGENV.step = it; //save previous iteration
uint32_t color = on ? color1 : color2;
@@ -120,7 +124,7 @@ uint16_t blink(uint32_t color1, uint32_t color2, bool strobe, bool do_palette) {
uint16_t mode_blink(void) {
return blink(SEGCOLOR(0), SEGCOLOR(1), false, true);
}
-static const char _data_FX_MODE_BLINK[] PROGMEM = "Blink@!,Duty cycle;!,!;!;1d";
+static const char _data_FX_MODE_BLINK[] PROGMEM = "Blink@!,Duty cycle;!,!;!";
/*
@@ -129,7 +133,7 @@ static const char _data_FX_MODE_BLINK[] PROGMEM = "Blink@!,Duty cycle;!,!;!;1d";
uint16_t mode_blink_rainbow(void) {
return blink(SEGMENT.color_wheel(SEGENV.call & 0xFF), SEGCOLOR(1), false, false);
}
-static const char _data_FX_MODE_BLINK_RAINBOW[] PROGMEM = "Blink Rainbow@Frequency,Blink duration;!,!;!;1d";
+static const char _data_FX_MODE_BLINK_RAINBOW[] PROGMEM = "Blink Rainbow@Frequency,Blink duration;!,!;!";
/*
@@ -138,7 +142,7 @@ static const char _data_FX_MODE_BLINK_RAINBOW[] PROGMEM = "Blink Rainbow@Frequen
uint16_t mode_strobe(void) {
return blink(SEGCOLOR(0), SEGCOLOR(1), true, true);
}
-static const char _data_FX_MODE_STROBE[] PROGMEM = "Strobe@!;!,!;!;1d";
+static const char _data_FX_MODE_STROBE[] PROGMEM = "Strobe@!;!,!;!";
/*
@@ -147,7 +151,7 @@ static const char _data_FX_MODE_STROBE[] PROGMEM = "Strobe@!;!,!;!;1d";
uint16_t mode_strobe_rainbow(void) {
return blink(SEGMENT.color_wheel(SEGENV.call & 0xFF), SEGCOLOR(1), true, false);
}
-static const char _data_FX_MODE_STROBE_RAINBOW[] PROGMEM = "Strobe Rainbow@!;,!;!;1d";
+static const char _data_FX_MODE_STROBE_RAINBOW[] PROGMEM = "Strobe Rainbow@!;,!;!";
/*
@@ -193,8 +197,8 @@ uint16_t color_wipe(bool rev, bool useRandomColors) {
{
uint16_t index = (rev && back)? SEGLEN -1 -i : i;
uint32_t col0 = useRandomColors? SEGMENT.color_wheel(SEGENV.aux0) : SEGMENT.color_from_palette(index, true, PALETTE_SOLID_WRAP, 0);
-
- if (i < ledIndex)
+
+ if (i < ledIndex)
{
SEGMENT.setPixelColor(index, back? col1 : col0);
} else
@@ -202,7 +206,7 @@ uint16_t color_wipe(bool rev, bool useRandomColors) {
SEGMENT.setPixelColor(index, back? col0 : col1);
if (i == ledIndex) SEGMENT.setPixelColor(index, color_blend(back? col0 : col1, back? col1 : col0, rem));
}
- }
+ }
return FRAMETIME;
}
@@ -213,7 +217,7 @@ uint16_t color_wipe(bool rev, bool useRandomColors) {
uint16_t mode_color_wipe(void) {
return color_wipe(false, false);
}
-static const char _data_FX_MODE_COLOR_WIPE[] PROGMEM = "Wipe@!,!;!,!;!;1d";
+static const char _data_FX_MODE_COLOR_WIPE[] PROGMEM = "Wipe@!,!;!,!;!";
/*
@@ -222,7 +226,7 @@ static const char _data_FX_MODE_COLOR_WIPE[] PROGMEM = "Wipe@!,!;!,!;!;1d";
uint16_t mode_color_sweep(void) {
return color_wipe(true, false);
}
-static const char _data_FX_MODE_COLOR_SWEEP[] PROGMEM = "Sweep@!,!;!,!;!;1d";
+static const char _data_FX_MODE_COLOR_SWEEP[] PROGMEM = "Sweep@!,!;!,!;!";
/*
@@ -232,7 +236,7 @@ static const char _data_FX_MODE_COLOR_SWEEP[] PROGMEM = "Sweep@!,!;!,!;!;1d";
uint16_t mode_color_wipe_random(void) {
return color_wipe(false, true);
}
-static const char _data_FX_MODE_COLOR_WIPE_RANDOM[] PROGMEM = "Wipe Random@!;1,2,3;!;1d";
+static const char _data_FX_MODE_COLOR_WIPE_RANDOM[] PROGMEM = "Wipe Random@!;;!";
/*
@@ -241,11 +245,11 @@ static const char _data_FX_MODE_COLOR_WIPE_RANDOM[] PROGMEM = "Wipe Random@!;1,2
uint16_t mode_color_sweep_random(void) {
return color_wipe(true, true);
}
-static const char _data_FX_MODE_COLOR_SWEEP_RANDOM[] PROGMEM = "Sweep Random";
+static const char _data_FX_MODE_COLOR_SWEEP_RANDOM[] PROGMEM = "Sweep Random@!;;!";
/*
- * Lights all LEDs in one random color up. Then switches them
+ * Lights all LEDs up in one random color. Then switches them
* to the next random color.
*/
uint16_t mode_random_color(void) {
@@ -274,17 +278,19 @@ uint16_t mode_random_color(void) {
SEGMENT.fill(color_blend(SEGMENT.color_wheel(SEGENV.aux1), SEGMENT.color_wheel(SEGENV.aux0), fade));
return FRAMETIME;
}
-static const char _data_FX_MODE_RANDOM_COLOR[] PROGMEM = "Random Colors@!,Fade time;1,2,3;!;1d";
+static const char _data_FX_MODE_RANDOM_COLOR[] PROGMEM = "Random Colors@!,Fade time;;!";
/*
* Lights every LED in a random color. Changes all LED at the same time
* to new random colors.
*/
-uint16_t dynamic(boolean smooth=false) {
+uint16_t mode_dynamic(void) {
if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed
-
+
if(SEGENV.call == 0) {
+ //SEGMENT.setUpLeds(); //lossless getPixelColor()
+ //SEGMENT.fill(BLACK);
for (int i = 0; i < SEGLEN; i++) SEGENV.data[i] = random8();
}
@@ -293,40 +299,36 @@ uint16_t dynamic(boolean smooth=false) {
if (it != SEGENV.step && SEGMENT.speed != 0) //new color
{
for (int i = 0; i < SEGLEN; i++) {
- if (random8() <= SEGMENT.intensity) SEGENV.data[i] = random8();
+ if (random8() <= SEGMENT.intensity) SEGENV.data[i] = random8(); // random color index
}
SEGENV.step = it;
}
-
- if (smooth) {
+
+ if (SEGMENT.check1) {
for (int i = 0; i < SEGLEN; i++) {
- SEGMENT.blendPixelColor(i, SEGMENT.color_wheel(SEGENV.data[i]),16); // TODO
+ SEGMENT.blendPixelColor(i, SEGMENT.color_wheel(SEGENV.data[i]), 16);
}
} else {
for (int i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, SEGMENT.color_wheel(SEGENV.data[i]));
}
- }
+ }
return FRAMETIME;
}
+static const char _data_FX_MODE_DYNAMIC[] PROGMEM = "Dynamic@!,!,,,,Smooth;;!";
/*
- * Original effect "Dynamic"
- */
-uint16_t mode_dynamic(void) {
- return dynamic(false);
-}
-static const char _data_FX_MODE_DYNAMIC[] PROGMEM = "Dynamic@!,!;1,2,3;!;1d";
-
-
-/*
- * effect "Dynamic" with smoth color-fading
+ * effect "Dynamic" with smooth color-fading
*/
uint16_t mode_dynamic_smooth(void) {
- return dynamic(true);
+ bool old = SEGMENT.check1;
+ SEGMENT.check1 = true;
+ mode_dynamic();
+ SEGMENT.check1 = old;
+ return FRAMETIME;
}
-static const char _data_FX_MODE_DYNAMIC_SMOOTH[] PROGMEM = "Dynamic Smooth";
+static const char _data_FX_MODE_DYNAMIC_SMOOTH[] PROGMEM = "Dynamic Smooth@!,!;;!";
/*
@@ -340,7 +342,7 @@ uint16_t mode_breath(void) {
if (counter > 8192) counter = 8192 - (counter - 8192);
var = sin16(counter) / 103; //close to parabolic in range 0-8192, max val. 23170
}
-
+
uint8_t lum = 30 + var;
for (int i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum));
@@ -348,7 +350,7 @@ uint16_t mode_breath(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_BREATH[] PROGMEM = "Breathe@!;!,!;!;1d";
+static const char _data_FX_MODE_BREATH[] PROGMEM = "Breathe@!;!,!;!";
/*
@@ -364,7 +366,7 @@ uint16_t mode_fade(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_FADE[] PROGMEM = "Fade@!;!,!;!;1d";
+static const char _data_FX_MODE_FADE[] PROGMEM = "Fade@!;!,!;!";
/*
@@ -378,7 +380,7 @@ uint16_t scan(bool dual)
uint16_t size = 1 + ((SEGMENT.intensity * SEGLEN) >> 9);
uint16_t ledIndex = (prog * ((SEGLEN *2) - size *2)) >> 16;
- SEGMENT.fill(SEGCOLOR(1));
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
int led_offset = ledIndex - (SEGLEN - size);
led_offset = abs(led_offset);
@@ -404,7 +406,7 @@ uint16_t scan(bool dual)
uint16_t mode_scan(void) {
return scan(false);
}
-static const char _data_FX_MODE_SCAN[] PROGMEM = "Scan@!,# of dots;!,!,!;!;1d";
+static const char _data_FX_MODE_SCAN[] PROGMEM = "Scan@!,# of dots,,,,,Overlay;!,!,!;!";
/*
@@ -413,7 +415,7 @@ static const char _data_FX_MODE_SCAN[] PROGMEM = "Scan@!,# of dots;!,!,!;!;1d";
uint16_t mode_dual_scan(void) {
return scan(true);
}
-static const char _data_FX_MODE_DUAL_SCAN[] PROGMEM = "Scan Dual@!,# of dots;!,!,!;!;1d";
+static const char _data_FX_MODE_DUAL_SCAN[] PROGMEM = "Scan Dual@!,# of dots,,,,,Overlay;!,!,!;!";
/*
@@ -431,7 +433,7 @@ uint16_t mode_rainbow(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_RAINBOW[] PROGMEM = "Colorloop@!,Saturation;1,2,3;!;1d";
+static const char _data_FX_MODE_RAINBOW[] PROGMEM = "Colorloop@!,Saturation;;!";
/*
@@ -440,7 +442,7 @@ static const char _data_FX_MODE_RAINBOW[] PROGMEM = "Colorloop@!,Saturation;1,2,
uint16_t mode_rainbow_cycle(void) {
uint16_t counter = (strip.now * ((SEGMENT.speed >> 2) +2)) & 0xFFFF;
counter = counter >> 8;
-
+
for (int i = 0; i < SEGLEN; i++) {
//intensity/29 = 0 (1/16) 1 (1/8) 2 (1/4) 3 (1/2) 4 (1) 5 (2) 6 (4) 7 (8) 8 (16)
uint8_t index = (i * (16 << (SEGMENT.intensity /29)) / SEGLEN) + counter;
@@ -449,7 +451,7 @@ uint16_t mode_rainbow_cycle(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_RAINBOW_CYCLE[] PROGMEM = "Rainbow@!,Size;1,2,3;!;1d";
+static const char _data_FX_MODE_RAINBOW_CYCLE[] PROGMEM = "Rainbow@!,Size;;!";
/*
@@ -460,7 +462,7 @@ uint16_t running(uint32_t color1, uint32_t color2, bool theatre = false) {
uint32_t cycleTime = 50 + (255 - SEGMENT.speed);
uint32_t it = strip.now / cycleTime;
bool usePalette = color1 == SEGCOLOR(0);
-
+
for (int i = 0; i < SEGLEN; i++) {
uint32_t col = color2;
if (usePalette) color1 = SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0);
@@ -488,7 +490,7 @@ uint16_t running(uint32_t color1, uint32_t color2, bool theatre = false) {
uint16_t mode_theater_chase(void) {
return running(SEGCOLOR(0), SEGCOLOR(1), true);
}
-static const char _data_FX_MODE_THEATER_CHASE[] PROGMEM = "Theater@!,Gap size;!,!;!;1d";
+static const char _data_FX_MODE_THEATER_CHASE[] PROGMEM = "Theater@!,Gap size;!,!;!";
/*
@@ -498,7 +500,7 @@ static const char _data_FX_MODE_THEATER_CHASE[] PROGMEM = "Theater@!,Gap size;!,
uint16_t mode_theater_chase_rainbow(void) {
return running(SEGMENT.color_wheel(SEGENV.step), SEGCOLOR(1), true);
}
-static const char _data_FX_MODE_THEATER_CHASE_RAINBOW[] PROGMEM = "Theater Rainbow@!,Gap size;1,2,3;!;1d";
+static const char _data_FX_MODE_THEATER_CHASE_RAINBOW[] PROGMEM = "Theater Rainbow@!,Gap size;,!;!";
/*
@@ -530,6 +532,7 @@ uint16_t running_base(bool saw, bool dual=false) {
}
SEGMENT.setPixelColor(i, ca);
}
+
return FRAMETIME;
}
@@ -541,7 +544,7 @@ uint16_t running_base(bool saw, bool dual=false) {
uint16_t mode_running_dual(void) {
return running_base(false, true);
}
-static const char _data_FX_MODE_RUNNING_DUAL[] PROGMEM = "Running Dual";
+static const char _data_FX_MODE_RUNNING_DUAL[] PROGMEM = "Running Dual@!,Wave width;L,!,R;!";
/*
@@ -550,7 +553,7 @@ static const char _data_FX_MODE_RUNNING_DUAL[] PROGMEM = "Running Dual";
uint16_t mode_running_lights(void) {
return running_base(false);
}
-static const char _data_FX_MODE_RUNNING_LIGHTS[] PROGMEM = "Running@!,Wave width;!,!;!;1d";
+static const char _data_FX_MODE_RUNNING_LIGHTS[] PROGMEM = "Running@!,Wave width;!,!;!";
/*
@@ -559,7 +562,7 @@ static const char _data_FX_MODE_RUNNING_LIGHTS[] PROGMEM = "Running@!,Wave width
uint16_t mode_saw(void) {
return running_base(true);
}
-static const char _data_FX_MODE_SAW[] PROGMEM = "Saw@!,Width;!,!;!;1d";
+static const char _data_FX_MODE_SAW[] PROGMEM = "Saw@!,Width;!,!;!";
/*
@@ -567,7 +570,6 @@ static const char _data_FX_MODE_SAW[] PROGMEM = "Saw@!,Width;!,!;!;1d";
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
*/
uint16_t mode_twinkle(void) {
- //SEGMENT.fill(SEGCOLOR(1));
SEGMENT.fade_out(224);
uint32_t cycleTime = 20 + (255 - SEGMENT.speed)*5;
@@ -583,7 +585,7 @@ uint16_t mode_twinkle(void) {
SEGENV.aux0++;
SEGENV.step = it;
}
-
+
uint16_t PRNG16 = SEGENV.aux1;
for (uint16_t i = 0; i < SEGENV.aux0; i++)
@@ -596,42 +598,47 @@ uint16_t mode_twinkle(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!;!,!;!;m12=0,1d"; //pixels
+static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!,!;!,!;!;;m12=0"; //pixels
/*
* Dissolve function
*/
uint16_t dissolve(uint32_t color) {
- bool wa = (SEGCOLOR(1) != 0 && strip.getBrightness() < 255); //workaround, can't compare getPixel to color if not full brightness
-
- for (int j = 0; j <= SEGLEN / 15; j++)
- {
+ //bool wa = (SEGCOLOR(1) != 0 && strip.getBrightness() < 255); //workaround, can't compare getPixel to color if not full brightness
+ if (SEGENV.call == 0) {
+ SEGMENT.setUpLeds(); //lossless getPixelColor()
+ SEGMENT.fill(SEGCOLOR(1));
+ }
+
+ for (int j = 0; j <= SEGLEN / 15; j++) {
if (random8() <= SEGMENT.intensity) {
- for (size_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times
+ for (size_t times = 0; times < 10; times++) //attempt to spawn a new pixel 10 times
{
uint16_t i = random16(SEGLEN);
if (SEGENV.aux0) { //dissolve to primary/palette
- if (SEGMENT.getPixelColor(i) == SEGCOLOR(1) || wa) { // TODO
- if (color == SEGCOLOR(0))
- {
+ if (SEGMENT.getPixelColor(i) == SEGCOLOR(1) /*|| wa*/) {
+ if (color == SEGCOLOR(0)) {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
- } else { SEGMENT.setPixelColor(i, color); }
+ } else {
+ SEGMENT.setPixelColor(i, color);
+ }
break; //only spawn 1 new pixel per frame per 50 LEDs
}
} else { //dissolve to secondary
- if (SEGMENT.getPixelColor(i) != SEGCOLOR(1)) { SEGMENT.setPixelColor(i, SEGCOLOR(1)); break; } // TODO
+ if (SEGMENT.getPixelColor(i) != SEGCOLOR(1)) { SEGMENT.setPixelColor(i, SEGCOLOR(1)); break; }
}
}
}
}
- if (SEGENV.call > (255 - SEGMENT.speed) + 15U)
- {
+ if (SEGENV.step > (255 - SEGMENT.speed) + 15U) {
SEGENV.aux0 = !SEGENV.aux0;
- SEGENV.call = 0;
+ SEGENV.step = 0;
+ } else {
+ SEGENV.step++;
}
-
+
return FRAMETIME;
}
@@ -640,9 +647,9 @@ uint16_t dissolve(uint32_t color) {
* Blink several LEDs on and then off
*/
uint16_t mode_dissolve(void) {
- return dissolve(SEGCOLOR(0));
+ return dissolve(SEGMENT.check1 ? SEGMENT.color_wheel(random8()) : SEGCOLOR(0));
}
-static const char _data_FX_MODE_DISSOLVE[] PROGMEM = "Dissolve@Repeat speed,Dissolve speed;!,!;!;1d";
+static const char _data_FX_MODE_DISSOLVE[] PROGMEM = "Dissolve@Repeat speed,Dissolve speed,,,,Random;!,!;!";
/*
@@ -651,7 +658,7 @@ static const char _data_FX_MODE_DISSOLVE[] PROGMEM = "Dissolve@Repeat speed,Diss
uint16_t mode_dissolve_random(void) {
return dissolve(SEGMENT.color_wheel(random8()));
}
-static const char _data_FX_MODE_DISSOLVE_RANDOM[] PROGMEM = "Dissolve Rnd@Repeat speed,Dissolve speed;,!;!;1d";
+static const char _data_FX_MODE_DISSOLVE_RANDOM[] PROGMEM = "Dissolve Rnd@Repeat speed,Dissolve speed;,!;!";
/*
@@ -659,7 +666,7 @@ static const char _data_FX_MODE_DISSOLVE_RANDOM[] PROGMEM = "Dissolve Rnd@Repeat
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
*/
uint16_t mode_sparkle(void) {
- for(int i = 0; i < SEGLEN; i++) {
+ if (!SEGMENT.check2) for(int i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
}
uint32_t cycleTime = 10 + (255 - SEGMENT.speed)*2;
@@ -669,11 +676,11 @@ uint16_t mode_sparkle(void) {
SEGENV.aux0 = random16(SEGLEN); // aux0 stores the random led index
SEGENV.step = it;
}
-
+
SEGMENT.setPixelColor(SEGENV.aux0, SEGCOLOR(0));
return FRAMETIME;
}
-static const char _data_FX_MODE_SPARKLE[] PROGMEM = "Sparkle@!;!,!;!;m12=0,1d";
+static const char _data_FX_MODE_SPARKLE[] PROGMEM = "Sparkle@!,,,,,,Overlay;!,!;!;;m12=0";
/*
@@ -681,7 +688,7 @@ static const char _data_FX_MODE_SPARKLE[] PROGMEM = "Sparkle@!;!,!;!;m12=0,1d";
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
*/
uint16_t mode_flash_sparkle(void) {
- for(uint16_t i = 0; i < SEGLEN; i++) {
+ if (!SEGMENT.check2) for(uint16_t i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
}
@@ -694,7 +701,7 @@ uint16_t mode_flash_sparkle(void) {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_FLASH_SPARKLE[] PROGMEM = "Sparkle Dark@!,!;Bg,Fx;!;m12=0,1d";
+static const char _data_FX_MODE_FLASH_SPARKLE[] PROGMEM = "Sparkle Dark@!,!,,,,,Overlay;Bg,Fx;!;;m12=0";
/*
@@ -702,7 +709,7 @@ static const char _data_FX_MODE_FLASH_SPARKLE[] PROGMEM = "Sparkle Dark@!,!;Bg,F
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
*/
uint16_t mode_hyper_sparkle(void) {
- for (int i = 0; i < SEGLEN; i++) {
+ if (!SEGMENT.check2) for (int i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
}
@@ -717,7 +724,7 @@ uint16_t mode_hyper_sparkle(void) {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_HYPER_SPARKLE[] PROGMEM = "Sparkle+@!,!;Bg,Fx;!;m12=0,1d";
+static const char _data_FX_MODE_HYPER_SPARKLE[] PROGMEM = "Sparkle+@!,!,,,,,Overlay;Bg,Fx;!;;m12=0";
/*
@@ -747,14 +754,14 @@ uint16_t mode_multi_strobe(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_MULTI_STROBE[] PROGMEM = "Strobe Mega@!,!;!,!;!;1d";
+static const char _data_FX_MODE_MULTI_STROBE[] PROGMEM = "Strobe Mega@!,!;!,!;!";
/*
* Android loading circle
*/
uint16_t mode_android(void) {
-
+
for (int i = 0; i < SEGLEN; i++) {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
}
@@ -768,7 +775,7 @@ uint16_t mode_android(void) {
}
uint16_t a = SEGENV.step;
-
+
if (SEGENV.aux0 == 0)
{
if (SEGENV.call %3 == 1) {a++;}
@@ -778,7 +785,7 @@ uint16_t mode_android(void) {
a++;
if (SEGENV.call %3 != 1) SEGENV.aux1--;
}
-
+
if (a >= SEGLEN) a = 0;
if (a + SEGENV.aux1 < SEGLEN)
@@ -799,7 +806,7 @@ uint16_t mode_android(void) {
return 3 + ((8 * (uint32_t)(255 - SEGMENT.speed)) / SEGLEN);
}
-static const char _data_FX_MODE_ANDROID[] PROGMEM = "Android@!,Width;!,!;!;m12=1,1d"; //vertical
+static const char _data_FX_MODE_ANDROID[] PROGMEM = "Android@!,Width;!,!;!;;m12=1"; //vertical
/*
@@ -825,7 +832,7 @@ uint16_t chase(uint32_t color1, uint32_t color2, uint32_t color3, bool do_palett
// Use intensity setting to vary chase up to 1/2 string length
uint8_t size = 1 + (SEGMENT.intensity * SEGLEN >> 10);
- uint16_t b = a + size; //"trail" of chase, filled with color1
+ uint16_t b = a + size; //"trail" of chase, filled with color1
if (b > SEGLEN) b -= SEGLEN;
uint16_t c = b + size;
if (c > SEGLEN) c -= SEGLEN;
@@ -880,7 +887,7 @@ uint16_t chase(uint32_t color1, uint32_t color2, uint32_t color3, bool do_palett
uint16_t mode_chase_color(void) {
return chase(SEGCOLOR(1), (SEGCOLOR(2)) ? SEGCOLOR(2) : SEGCOLOR(0), SEGCOLOR(0), true);
}
-static const char _data_FX_MODE_CHASE_COLOR[] PROGMEM = "Chase@!,Width;!,!,!;!;1d";
+static const char _data_FX_MODE_CHASE_COLOR[] PROGMEM = "Chase@!,Width;!,!,!;!";
/*
@@ -889,7 +896,7 @@ static const char _data_FX_MODE_CHASE_COLOR[] PROGMEM = "Chase@!,Width;!,!,!;!;1
uint16_t mode_chase_random(void) {
return chase(SEGCOLOR(1), (SEGCOLOR(2)) ? SEGCOLOR(2) : SEGCOLOR(0), SEGCOLOR(0), false);
}
-static const char _data_FX_MODE_CHASE_RANDOM[] PROGMEM = "Chase Random@!,Width;!,,!;!;1d";
+static const char _data_FX_MODE_CHASE_RANDOM[] PROGMEM = "Chase Random@!,Width;!,,!;!";
/*
@@ -903,7 +910,7 @@ uint16_t mode_chase_rainbow(void) {
return chase(color, SEGCOLOR(0), SEGCOLOR(1), false);
}
-static const char _data_FX_MODE_CHASE_RAINBOW[] PROGMEM = "Chase Rainbow@!,Width;!,!;;1d";
+static const char _data_FX_MODE_CHASE_RAINBOW[] PROGMEM = "Chase Rainbow@!,Width;!,!;!";
/*
@@ -917,7 +924,7 @@ uint16_t mode_chase_rainbow_white(void) {
return chase(SEGCOLOR(0), color2, color3, false);
}
-static const char _data_FX_MODE_CHASE_RAINBOW_WHITE[] PROGMEM = "Rainbow Runner@!,Size;Bg;;1d";
+static const char _data_FX_MODE_CHASE_RAINBOW_WHITE[] PROGMEM = "Rainbow Runner@!,Size;Bg;!";
/*
@@ -945,7 +952,7 @@ uint16_t mode_colorful(void) {
cols[3] = 0x0077F0F0;
}
for (size_t i = numColors; i < numColors*2 -1U; i++) cols[i] = cols[i-numColors];
-
+
uint32_t cycleTime = 50 + (8 * (uint32_t)(255 - SEGMENT.speed));
uint32_t it = strip.now / cycleTime;
if (it != SEGENV.step)
@@ -954,15 +961,15 @@ uint16_t mode_colorful(void) {
if (SEGENV.aux0 >= numColors) SEGENV.aux0 = 0;
SEGENV.step = it;
}
-
+
for (int i = 0; i < SEGLEN; i+= numColors)
{
for (int j = 0; j < numColors; j++) SEGMENT.setPixelColor(i + j, cols[SEGENV.aux0 + j]);
}
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_COLORFUL[] PROGMEM = "Colorful@!,Saturation;1,2,3;!;1d";
+static const char _data_FX_MODE_COLORFUL[] PROGMEM = "Colorful@!,Saturation;1,2,3;!";
/*
@@ -990,10 +997,10 @@ uint16_t mode_traffic_light(void) {
if (SEGENV.aux0 > 3) SEGENV.aux0 = 0;
SEGENV.step = strip.now;
}
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_TRAFFIC_LIGHT[] PROGMEM = "Traffic Light@!;,!;!;1d";
+static const char _data_FX_MODE_TRAFFIC_LIGHT[] PROGMEM = "Traffic Light@!,US style;,!;!";
/*
@@ -1023,7 +1030,7 @@ uint16_t mode_chase_flash(void) {
}
return delay;
}
-static const char _data_FX_MODE_CHASE_FLASH[] PROGMEM = "Chase Flash@!;Bg,Fx,!;!;1d";
+static const char _data_FX_MODE_CHASE_FLASH[] PROGMEM = "Chase Flash@!;Bg,Fx;!";
/*
@@ -1058,7 +1065,7 @@ uint16_t mode_chase_flash_random(void) {
}
return delay;
}
-static const char _data_FX_MODE_CHASE_FLASH_RANDOM[] PROGMEM = "Chase Flash Rnd@!;,Fx;0;1d";
+static const char _data_FX_MODE_CHASE_FLASH_RANDOM[] PROGMEM = "Chase Flash Rnd@!;!,!;!";
/*
@@ -1067,7 +1074,7 @@ static const char _data_FX_MODE_CHASE_FLASH_RANDOM[] PROGMEM = "Chase Flash Rnd@
uint16_t mode_running_color(void) {
return running(SEGCOLOR(0), SEGCOLOR(1));
}
-static const char _data_FX_MODE_RUNNING_COLOR[] PROGMEM = "Chase 2@!,Width;!,!;!;1d";
+static const char _data_FX_MODE_RUNNING_COLOR[] PROGMEM = "Chase 2@!,Width;!,!;!";
/*
@@ -1104,7 +1111,7 @@ uint16_t mode_running_random(void) {
SEGENV.aux1 = it;
return FRAMETIME;
}
-static const char _data_FX_MODE_RUNNING_RANDOM[] PROGMEM = "Stream";
+static const char _data_FX_MODE_RUNNING_RANDOM[] PROGMEM = "Stream ☾@!,Zone size;;!";
uint16_t larson_scanner(bool dual) {
@@ -1116,7 +1123,7 @@ uint16_t larson_scanner(bool dual) {
if (SEGENV.step > index && SEGENV.step - index > SEGLEN/2) {
SEGENV.aux0 = !SEGENV.aux0;
}
-
+
for (int i = SEGENV.step; i < index; i++) {
uint16_t j = (SEGENV.aux0)?i:SEGLEN-1-i;
SEGMENT.setPixelColor( j, SEGMENT.color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
@@ -1146,7 +1153,7 @@ uint16_t larson_scanner(bool dual) {
uint16_t mode_larson_scanner(void){
return larson_scanner(false);
}
-static const char _data_FX_MODE_LARSON_SCANNER[] PROGMEM = "Scanner@!,Fade rate;!,!;!;m12=0,1d";
+static const char _data_FX_MODE_LARSON_SCANNER[] PROGMEM = "Scanner@!,Fade rate;!,!;!;;m12=0";
/*
@@ -1156,7 +1163,7 @@ static const char _data_FX_MODE_LARSON_SCANNER[] PROGMEM = "Scanner@!,Fade rate;
uint16_t mode_dual_larson_scanner(void){
return larson_scanner(true);
}
-static const char _data_FX_MODE_DUAL_LARSON_SCANNER[] PROGMEM = "Scanner Dual@!,Fade rate;!,!;!;m12=0,1d";
+static const char _data_FX_MODE_DUAL_LARSON_SCANNER[] PROGMEM = "Scanner Dual@!,Fade rate;!,!,!;!;;m12=0";
/*
@@ -1177,13 +1184,13 @@ uint16_t mode_comet(void) {
} else if (index < SEGENV.aux0 && index < 10) {
for (int i = 0; i < index ; i++) {
SEGMENT.setPixelColor( i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
- }
+ }
}
SEGENV.aux0 = index++;
return FRAMETIME;
}
-static const char _data_FX_MODE_COMET[] PROGMEM = "Lighthouse@!,Fade rate;!,!,!;!;1d";
+static const char _data_FX_MODE_COMET[] PROGMEM = "Lighthouse@!,Fade rate;!,!;!";
/*
@@ -1193,17 +1200,19 @@ uint16_t mode_fireworks() {
const uint16_t width = strip.isMatrix ? SEGMENT.virtualWidth() : SEGMENT.virtualLength();
const uint16_t height = SEGMENT.virtualHeight();
- SEGMENT.fade_out(0);
-
if (SEGENV.call == 0) {
+ SEGMENT.setUpLeds(); //lossless getPixelColor()
+ SEGMENT.fill(SEGCOLOR(1));
SEGENV.aux0 = UINT16_MAX;
SEGENV.aux1 = UINT16_MAX;
}
+ SEGMENT.fade_out(128);
+
bool valid1 = (SEGENV.aux0 < width*height);
bool valid2 = (SEGENV.aux1 < width*height);
uint32_t sv1 = 0, sv2 = 0;
- if (valid1) sv1 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width) : SEGMENT.getPixelColor(SEGENV.aux0); // TODO get spark color
- if (valid2) sv2 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width) : SEGMENT.getPixelColor(SEGENV.aux1); // TODO
+ if (valid1) sv1 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width) : SEGMENT.getPixelColor(SEGENV.aux0); // get spark color
+ if (valid2) sv2 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width) : SEGMENT.getPixelColor(SEGENV.aux1);
if (!SEGENV.step) SEGMENT.blur(16);
if (valid1) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width, sv1); else SEGMENT.setPixelColor(SEGENV.aux0, sv1); } // restore spark color after blur
if (valid2) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width, sv2); else SEGMENT.setPixelColor(SEGENV.aux1, sv2); } // restore old spark color after blur
@@ -1221,7 +1230,7 @@ uint16_t mode_fireworks() {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_FIREWORKS[] PROGMEM = "Fireworks@,Frequency;!,!;!;ix=192,pal=11,1d,2d";
+static const char _data_FX_MODE_FIREWORKS[] PROGMEM = "Fireworks@,Frequency;!,!;!;12;ix=192,pal=11";
//Twinkling LEDs running. Inspired by https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Rain.h
@@ -1230,7 +1239,7 @@ uint16_t mode_rain()
const uint16_t width = SEGMENT.virtualWidth();
const uint16_t height = SEGMENT.virtualHeight();
SEGENV.step += FRAMETIME;
- if (SEGENV.step > SPEED_FORMULA_L) {
+ if (SEGENV.call && SEGENV.step > SPEED_FORMULA_L) {
SEGENV.step = 1;
if (strip.isMatrix) {
uint32_t ctemp[width];
@@ -1241,9 +1250,9 @@ uint16_t mode_rain()
SEGENV.aux1 = (SEGENV.aux1 % width) + (SEGENV.aux1 / width + 1) * width;
} else {
//shift all leds left
- uint32_t ctemp = SEGMENT.getPixelColor(0); // TODO
+ uint32_t ctemp = SEGMENT.getPixelColor(0);
for (int i = 0; i < SEGLEN - 1; i++) {
- SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // TODO
+ SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1));
}
SEGMENT.setPixelColor(SEGLEN -1, ctemp); // wrap around
SEGENV.aux0++; // increase spark index
@@ -1256,7 +1265,7 @@ uint16_t mode_rain()
}
return mode_fireworks();
}
-static const char _data_FX_MODE_RAIN[] PROGMEM = "Rain@!,Spawning rate;!,!;;ix=128,pal=0,1d,2d";
+static const char _data_FX_MODE_RAIN[] PROGMEM = "Rain@!,Spawning rate;!,!;!;12;ix=128,pal=0";
/*
@@ -1285,7 +1294,7 @@ uint16_t mode_fire_flicker(void) {
SEGENV.step = it;
return FRAMETIME;
}
-static const char _data_FX_MODE_FIRE_FLICKER[] PROGMEM = "Fire Flicker@!,!;!;!;1d";
+static const char _data_FX_MODE_FIRE_FLICKER[] PROGMEM = "Fire Flicker@!,!;!;!;;pal=0"; //WLEDMM pal=0
/*
@@ -1323,7 +1332,7 @@ uint16_t gradient_base(bool loading) {
uint16_t mode_gradient(void) {
return gradient_base(false);
}
-static const char _data_FX_MODE_GRADIENT[] PROGMEM = "Gradient@!,Spread;!,!;!;ix=16,1d";
+static const char _data_FX_MODE_GRADIENT[] PROGMEM = "Gradient@!,Spread;!,!;!;;ix=16";
/*
@@ -1332,16 +1341,16 @@ static const char _data_FX_MODE_GRADIENT[] PROGMEM = "Gradient@!,Spread;!,!;!;ix
uint16_t mode_loading(void) {
return gradient_base(true);
}
-static const char _data_FX_MODE_LOADING[] PROGMEM = "Loading@!,Fade;!,!;!;ix=16,1d";
+static const char _data_FX_MODE_LOADING[] PROGMEM = "Loading@!,Fade;!,!;!;;ix=16";
-//American Police Light with all LEDs Red and Blue
+//American Police Light with all LEDs Red and Blue
uint16_t police_base(uint32_t color1, uint32_t color2)
{
uint16_t delay = 1 + (FRAMETIME<<3) / SEGLEN; // longer segments should change faster
uint32_t it = strip.now / map(SEGMENT.speed, 0, 255, delay<<4, delay);
uint16_t offset = it % SEGLEN;
-
+
uint16_t width = ((SEGLEN*(SEGMENT.intensity+1))>>9); //max width is half the strip
if (!width) width = 1;
for (int i = 0; i < width; i++) {
@@ -1354,7 +1363,7 @@ uint16_t police_base(uint32_t color1, uint32_t color2)
}
-//Police Lights Red and Blue
+//Police Lights Red and Blue
//uint16_t mode_police()
//{
// SEGMENT.fill(SEGCOLOR(1));
@@ -1363,15 +1372,14 @@ uint16_t police_base(uint32_t color1, uint32_t color2)
//static const char _data_FX_MODE_POLICE[] PROGMEM = "Police@!,Width;,Bg;0";
-//Police Lights with custom colors
+//Police Lights with custom colors
uint16_t mode_two_dots()
{
- SEGMENT.fill(SEGCOLOR(2));
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(2));
uint32_t color2 = (SEGCOLOR(1) == SEGCOLOR(2)) ? SEGCOLOR(0) : SEGCOLOR(1);
-
return police_base(SEGCOLOR(0), color2);
}
-static const char _data_FX_MODE_TWO_DOTS[] PROGMEM = "Two Dots@!,Dot size;1,2,Bg;!;1d";
+static const char _data_FX_MODE_TWO_DOTS[] PROGMEM = "Two Dots@!,Dot size,,,,,Overlay;1,2,Bg;!";
/*
@@ -1458,7 +1466,7 @@ uint16_t mode_fairy() {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_FAIRY[] PROGMEM = "Fairy";
+static const char _data_FX_MODE_FAIRY[] PROGMEM = "Fairy@!,# of flashers;!,!;!";
/*
@@ -1508,7 +1516,7 @@ uint16_t mode_fairytwinkle() {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_FAIRYTWINKLE[] PROGMEM = "Fairy Twinkle@;;;m12=0,1d"; //pixels
+static const char _data_FX_MODE_FAIRYTWINKLE[] PROGMEM = "Fairytwinkle@!,!;!,!;!;;m12=0"; //pixels
/*
@@ -1519,7 +1527,7 @@ uint16_t tricolor_chase(uint32_t color1, uint32_t color2) {
uint32_t it = strip.now / cycleTime; // iterator
uint8_t width = (1 + (SEGMENT.intensity>>4)); // value of 1-16 for each colour
uint8_t index = it % (width*3);
-
+
for (int i = 0; i < SEGLEN; i++, index++) {
if (index > (width*3)-1) index = 0;
@@ -1539,7 +1547,7 @@ uint16_t tricolor_chase(uint32_t color1, uint32_t color2) {
uint16_t mode_tricolor_chase(void) {
return tricolor_chase(SEGCOLOR(2), SEGCOLOR(0));
}
-static const char _data_FX_MODE_TRICOLOR_CHASE[] PROGMEM = "Chase 3@!,Size;1,2,3;0;1d";
+static const char _data_FX_MODE_TRICOLOR_CHASE[] PROGMEM = "Chase 3@!,Size;1,2,3;!";
/*
@@ -1549,7 +1557,7 @@ uint16_t mode_icu(void) {
uint16_t dest = SEGENV.step & 0xFFFF;
uint8_t space = (SEGMENT.intensity >> 3) +2;
- SEGMENT.fill(SEGCOLOR(1));
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
byte pindex = map(dest, 0, SEGLEN-SEGLEN/space, 0, 255);
uint32_t col = SEGMENT.color_from_palette(pindex, false, false, 0);
@@ -1580,14 +1588,13 @@ uint16_t mode_icu(void) {
return SPEED_FORMULA_L;
}
-static const char _data_FX_MODE_ICU[] PROGMEM = "ICU";
+static const char _data_FX_MODE_ICU[] PROGMEM = "ICU@!,!,,,,,Overlay;!,!;!";
/*
* Custom mode by Aircoookie. Color Wipe, but with 3 colors
*/
-uint16_t mode_tricolor_wipe(void)
-{
+uint16_t mode_tricolor_wipe(void) {
uint32_t cycleTime = 1000 + (255 - SEGMENT.speed)*200;
uint32_t perc = strip.now % cycleTime;
uint16_t prog = (perc * 65535) / cycleTime;
@@ -1598,7 +1605,7 @@ uint16_t mode_tricolor_wipe(void)
{
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 2));
}
-
+
if(ledIndex < SEGLEN) { //wipe from 0 to 1
for (int i = 0; i < SEGLEN; i++)
{
@@ -1621,7 +1628,7 @@ uint16_t mode_tricolor_wipe(void)
return FRAMETIME;
}
-static const char _data_FX_MODE_TRICOLOR_WIPE[] PROGMEM = "Tri Wipe@!;1,2,3;0;1d";
+static const char _data_FX_MODE_TRICOLOR_WIPE[] PROGMEM = "Tri Wipe@!;1,2,3;!";
/*
@@ -1629,8 +1636,7 @@ static const char _data_FX_MODE_TRICOLOR_WIPE[] PROGMEM = "Tri Wipe@!;1,2,3;0;1d
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/TriFade.h
* Modified by Aircoookie
*/
-uint16_t mode_tricolor_fade(void)
-{
+uint16_t mode_tricolor_fade(void) {
uint16_t counter = strip.now * ((SEGMENT.speed >> 3) +1);
uint32_t prog = (counter * 768) >> 16;
@@ -1666,22 +1672,21 @@ uint16_t mode_tricolor_fade(void)
return FRAMETIME;
}
-static const char _data_FX_MODE_TRICOLOR_FADE[] PROGMEM = "Tri Fade";
+static const char _data_FX_MODE_TRICOLOR_FADE[] PROGMEM = "Tri Fade@!;1,2,3;!";
/*
* Creates random comets
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/MultiComet.h
*/
-uint16_t mode_multi_comet(void)
-{
+uint16_t mode_multi_comet(void) {
uint32_t cycleTime = 10 + (uint32_t)(255 - SEGMENT.speed);
uint32_t it = strip.now / cycleTime;
if (SEGENV.step == it) return FRAMETIME;
if (!SEGENV.allocateData(sizeof(uint16_t) * 8)) return mode_static(); //allocation failed
-
+
SEGMENT.fade_out(SEGMENT.intensity);
-
+
uint16_t* comets = reinterpret_cast(SEGENV.data);
for (int i=0; i < 8; i++) {
@@ -1712,8 +1717,7 @@ static const char _data_FX_MODE_MULTI_COMET[] PROGMEM = "Multi Comet";
* Running random pixels ("Stream 2")
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/RandomChase.h
*/
-uint16_t mode_random_chase(void)
-{
+uint16_t mode_random_chase(void) {
if (SEGENV.call == 0) {
SEGENV.step = RGBW32(random8(), random8(), random8(), 0);
SEGENV.aux0 = random16();
@@ -1741,7 +1745,7 @@ uint16_t mode_random_chase(void)
random16_set_seed(prevSeed); // restore original seed so other effects can use "random" PRNG
return FRAMETIME;
}
-static const char _data_FX_MODE_RANDOM_CHASE[] PROGMEM = "Stream 2";
+static const char _data_FX_MODE_RANDOM_CHASE[] PROGMEM = "Stream 2 ☾@!;;";
//7 bytes
@@ -1755,13 +1759,12 @@ typedef struct Oscillator {
/*
/ Oscillating bars of color, updated with standard framerate
*/
-uint16_t mode_oscillate(void)
-{
+uint16_t mode_oscillate(void) {
uint8_t numOscillators = 3;
uint16_t dataSize = sizeof(oscillator) * numOscillators;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
-
+
Oscillator* oscillators = reinterpret_cast(SEGENV.data);
if (SEGENV.call == 0)
@@ -1800,7 +1803,7 @@ uint16_t mode_oscillate(void)
}
SEGMENT.setPixelColor(i, color);
}
-
+
SEGENV.step = it;
return FRAMETIME;
}
@@ -1808,8 +1811,7 @@ static const char _data_FX_MODE_OSCILLATE[] PROGMEM = "Oscillate";
//TODO
-uint16_t mode_lightning(void)
-{
+uint16_t mode_lightning(void) {
uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash
uint16_t ledlen = 1 + random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
uint8_t bri = 255/random8(1, 3);
@@ -1823,7 +1825,7 @@ uint16_t mode_lightning(void)
SEGENV.aux0 = 200; //200ms delay after leader
}
- SEGMENT.fill(SEGCOLOR(1));
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
if (SEGENV.aux1 > 3 && !(SEGENV.aux1 & 0x01)) { //flash on even number >2
for (int i = ledstart; i < ledstart + ledlen; i++)
@@ -1848,14 +1850,13 @@ uint16_t mode_lightning(void)
}
return FRAMETIME;
}
-static const char _data_FX_MODE_LIGHTNING[] PROGMEM = "Lightning";
+static const char _data_FX_MODE_LIGHTNING[] PROGMEM = "Lightning@!,!,,,,,Overlay;!,!;!";
// Pride2015
// Animated, ever-changing rainbows.
// by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
-uint16_t mode_pride_2015(void)
-{
+uint16_t mode_pride_2015(void) {
uint16_t duration = 10 + SEGMENT.speed;
uint16_t sPseudotime = SEGENV.step;
uint16_t sHue16 = SEGENV.aux0;
@@ -1884,63 +1885,66 @@ uint16_t mode_pride_2015(void)
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
- CRGB newcolor = CHSV( hue8, sat8, bri8);
- fastled_col = CRGB(SEGMENT.getPixelColor(i)); // TODO
-
- nblend(fastled_col, newcolor, 64);
- SEGMENT.setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
+ CRGB newcolor = CHSV(hue8, sat8, bri8);
+ SEGMENT.blendPixelColor(i, newcolor, 64);
}
SEGENV.step = sPseudotime;
SEGENV.aux0 = sHue16;
+
return FRAMETIME;
}
-static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;;1d";
+static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;";
//eight colored dots, weaving in and out of sync with each other
-uint16_t mode_juggle(void){
- SEGMENT.fade_out(SEGMENT.intensity);
+uint16_t mode_juggle(void) {
+ if (SEGENV.call == 0) {
+ SEGMENT.setUpLeds(); //lossless getPixelColor()
+ SEGMENT.fill(BLACK);
+ }
+
+ SEGMENT.fadeToBlackBy(192 - (3*SEGMENT.intensity/4));
+
CRGB fastled_col;
byte dothue = 0;
for (int i = 0; i < 8; i++) {
- uint16_t index = 0 + beatsin88((128 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1);
- fastled_col = CRGB(SEGMENT.getPixelColor(index)); // TODO
+ uint16_t index = 0 + beatsin88((16 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1);
+ fastled_col = CRGB(SEGMENT.getPixelColor(index));
fastled_col |= (SEGMENT.palette==0)?CHSV(dothue, 220, 255):ColorFromPalette(SEGPALETTE, dothue, 255);
- SEGMENT.setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue);
+ SEGMENT.setPixelColor(index, fastled_col);
dothue += 32;
}
return FRAMETIME;
}
-static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;!,!;!;sx=16,ix=240,1d";
+static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;;!;;sx=64,ix=128";
-uint16_t mode_palette()
-{
+uint16_t mode_palette() {
uint16_t counter = 0;
- if (SEGMENT.speed != 0)
+ if (SEGMENT.speed != 0)
{
counter = (strip.now * ((SEGMENT.speed >> 3) +1)) & 0xFFFF;
counter = counter >> 8;
}
-
- bool noWrap = (strip.paletteBlend == 2 || (strip.paletteBlend == 0 && SEGMENT.speed == 0));
+
for (int i = 0; i < SEGLEN; i++)
{
uint8_t colorIndex = (i * 255 / SEGLEN) - counter;
- SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(colorIndex, false, noWrap, 255));
+ SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(colorIndex, false, PALETTE_MOVING_WRAP, 255));
}
+
return FRAMETIME;
}
-static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Cycle speed;1,2,3;!;1d";
+static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Cycle speed;;!;;c3=0,o2=0";
// WLED limitation: Analog Clock overlay will NOT work when Fire2012 is active
// Fire2012 by Mark Kriegsman, July 2012
// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
-////
+////
// This basic one-dimensional 'fire' simulation works roughly as follows:
// There's a underlying array of 'heat' cells, that model the temperature
-// at each point along the line. Every cycle through the simulation,
+// at each point along the line. Every cycle through the simulation,
// four steps are performed:
// 1) All cells cool down a little bit, losing heat to the air
// 2) The heat from each cell drifts 'up' and diffuses a little
@@ -1951,7 +1955,7 @@ static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Cycle speed;1,2,3;!
// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
//
// This simulation scales it self a bit depending on SEGLEN; it should look
-// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
+// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
//
// I recommend running this simulation at anywhere from 30-100 frames per second,
// meaning an interframe delay of about 10-35 milliseconds.
@@ -1962,43 +1966,42 @@ static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Cycle speed;1,2,3;!
// There are two main parameters you can play with to control the look and
// feel of your fire: COOLING (used in step 1 above) (Speed = COOLING), and SPARKING (used
// in step 3 above) (Effect Intensity = Sparking).
-uint16_t mode_fire_2012()
-{
- uint16_t strips = SEGMENT.nrOfVStrips();
+uint16_t mode_fire_2012() {
+ const uint16_t strips = SEGMENT.nrOfVStrips();
if (!SEGENV.allocateData(strips * SEGLEN)) return mode_static(); //allocation failed
byte* heat = SEGENV.data;
- uint32_t it = strip.now >> 5; //div 32
+ const uint32_t it = strip.now >> 6; //div 64
struct virtualStrip {
static void runStrip(uint16_t stripNr, byte* heat, uint32_t it) {
+ const uint8_t ignition = max(3,SEGLEN/10); // ignition area: 10% of segment length or minimum 3 pixels
+
+ // Step 1. Cool down every cell a little
+ for (int i = 0; i < SEGLEN; i++) {
+ uint8_t cool = (it != SEGENV.step) ? random8((((20 + SEGMENT.speed/3) * 16) / SEGLEN)+2) : random(8);
+ uint8_t minTemp = 0;
+ if (i 1; k--) {
heat[k] = (heat[k - 1] + (heat[k - 2]<<1) ) / 3; // heat[k-2] multiplied by 2
}
+ }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if (random8() <= SEGMENT.intensity) {
- uint8_t y = random8(ignition);
- heat[y] = qadd8(heat[y], random8(160,255));
- }
+ // Step 3. Randomly ignite new 'sparks' of heat near the bottom
+ if (random8() <= SEGMENT.intensity) {
+ uint8_t y = random8(ignition);
+ uint8_t boost = (32+SEGMENT.custom3*2) * (2*ignition-y) / (2*ignition);
+ heat[y] = qadd8(heat[y], random8(64+boost,128+boost));
}
// Step 4. Map from heat cells to LED colors
@@ -2011,19 +2014,20 @@ uint16_t mode_fire_2012()
for (int stripNr=0; stripNr> 1));
@@ -2151,11 +2144,10 @@ uint16_t mode_noise16_2()
return FRAMETIME;
}
-static const char _data_FX_MODE_NOISE16_2[] PROGMEM = "Noise 2@!,!;!,!,!;!;1d";
+static const char _data_FX_MODE_NOISE16_2[] PROGMEM = "Noise 2@!;!;!";
-uint16_t mode_noise16_3()
-{
+uint16_t mode_noise16_3() {
uint16_t scale = 800; // the "zoom factor" for the noise
//CRGB fastled_col;
SEGENV.step += (1 + SEGMENT.speed);
@@ -2165,7 +2157,7 @@ uint16_t mode_noise16_3()
uint16_t shift_y = 1234;
uint32_t real_x = (i + shift_x) * scale; // calculate the coordinates within the noise field
uint32_t real_y = (i + shift_y) * scale; // based on the precalculated positions
- uint32_t real_z = SEGENV.step*8;
+ uint32_t real_z = SEGENV.step*8;
uint8_t noise = inoise16(real_x, real_y, real_z) >> 8; // get the noise data and scale it down
uint8_t index = sin8(noise * 3); // map led color based on noise data
@@ -2176,12 +2168,11 @@ uint16_t mode_noise16_3()
return FRAMETIME;
}
-static const char _data_FX_MODE_NOISE16_3[] PROGMEM = "Noise 3@!,!;!,!,!;!;1d";
+static const char _data_FX_MODE_NOISE16_3[] PROGMEM = "Noise 3@!;!;!";
//https://github.com/aykevl/ledstrip-spark/blob/master/ledstrip.ino
-uint16_t mode_noise16_4()
-{
+uint16_t mode_noise16_4() {
//CRGB fastled_col;
uint32_t stp = (strip.now * SEGMENT.speed) >> 7;
for (int i = 0; i < SEGLEN; i++) {
@@ -2192,15 +2183,14 @@ uint16_t mode_noise16_4()
}
return FRAMETIME;
}
-static const char _data_FX_MODE_NOISE16_4[] PROGMEM = "Noise 4@!,!;!,!,!;!;1d";
+static const char _data_FX_MODE_NOISE16_4[] PROGMEM = "Noise 4@!;!;!";
//based on https://gist.github.com/kriegsman/5408ecd397744ba0393e
-uint16_t mode_colortwinkle()
-{
+uint16_t mode_colortwinkle() {
uint16_t dataSize = (SEGLEN+7) >> 3; //1 bit per LED
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
-
+
CRGB fastled_col, prev;
fract8 fadeUpAmount = strip.getBrightness()>28 ? 8 + (SEGMENT.speed>>2) : 68-strip.getBrightness();
fract8 fadeDownAmount = strip.getBrightness()>28 ? 8 + (SEGMENT.speed>>3) : 68-strip.getBrightness();
@@ -2210,7 +2200,7 @@ uint16_t mode_colortwinkle()
uint16_t index = i >> 3;
uint8_t bitNum = i & 0x07;
bool fadeUp = bitRead(SEGENV.data[index], bitNum);
-
+
if (fadeUp) {
CRGB incrementalColor = fastled_col;
incrementalColor.nscale8_video(fadeUpAmount);
@@ -2248,7 +2238,7 @@ uint16_t mode_colortwinkle()
}
return FRAMETIME_FIXED;
}
-static const char _data_FX_MODE_COLORTWINKLE[] PROGMEM = "Colortwinkles@Fade speed,Spawn speed;1,2,3;!;m12=0,1d"; //pixels
+static const char _data_FX_MODE_COLORTWINKLE[] PROGMEM = "Colortwinkles@Fade speed,Spawn speed;;!;;m12=0"; //pixels
//Calm effect, like a lake at night
@@ -2261,15 +2251,16 @@ uint16_t mode_lake() {
for (int i = 0; i < SEGLEN; i++)
{
- int index = cos8((i*15)+ wave1)/2 + cubicwave8((i*23)+ wave2)/2;
+ int index = cos8((i*15)+ wave1)/2 + cubicwave8((i*23)+ wave2)/2;
uint8_t lum = (index > wave3) ? index - wave3 : 0;
//fastled_col = ColorFromPalette(SEGPALETTE, map(index,0,255,0,240), lum, LINEARBLEND);
//SEGMENT.setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(index, false, false, 0, lum));
}
+
return FRAMETIME;
}
-static const char _data_FX_MODE_LAKE[] PROGMEM = "Lake@!;1,2,3;!;1d";
+static const char _data_FX_MODE_LAKE[] PROGMEM = "Lake@!;Fx;!";
// meteor effect
@@ -2279,7 +2270,7 @@ uint16_t mode_meteor() {
if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed
byte* trail = SEGENV.data;
-
+
byte meteorSize= 1+ SEGLEN / 10;
uint16_t counter = strip.now * ((SEGMENT.speed >> 2) +8);
uint16_t in = counter * SEGLEN >> 16;
@@ -2306,7 +2297,7 @@ uint16_t mode_meteor() {
return FRAMETIME;
}
-static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail length;!;!;1d";
+static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail length;!;!";
// smooth meteor effect
@@ -2316,7 +2307,7 @@ uint16_t mode_meteor_smooth() {
if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed
byte* trail = SEGENV.data;
-
+
byte meteorSize= 1+ SEGLEN / 10;
uint16_t in = map((SEGENV.step >> 6 & 0xFF), 0, 255, 0, SEGLEN -1);
@@ -2331,7 +2322,7 @@ uint16_t mode_meteor_smooth() {
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, false, 0, trail[i]));
}
}
-
+
// draw meteor
for (int j = 0; j < meteorSize; j++) {
uint16_t index = in + j;
@@ -2345,13 +2336,12 @@ uint16_t mode_meteor_smooth() {
SEGENV.step += SEGMENT.speed +1;
return FRAMETIME;
}
-static const char _data_FX_MODE_METEOR_SMOOTH[] PROGMEM = "Meteor Smooth@!,Trail length;!;!;1d";
+static const char _data_FX_MODE_METEOR_SMOOTH[] PROGMEM = "Meteor Smooth@!,Trail length;!;!";
//Railway Crossing / Christmas Fairy lights
-uint16_t mode_railway()
-{
- uint16_t dur = 40 + (255 - SEGMENT.speed) * 10;
+uint16_t mode_railway() {
+ uint16_t dur = (256 - SEGMENT.speed) * 40;
uint16_t rampdur = (dur * SEGMENT.intensity) >> 8;
if (SEGENV.step > dur)
{
@@ -2368,16 +2358,16 @@ uint16_t mode_railway()
if (SEGENV.aux0) pos = 255 - pos;
for (int i = 0; i < SEGLEN; i += 2)
{
- SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(255 - pos, false, false, 255));
+ SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(255 - pos, false, false, 255)); // do not use color 1 or 2, always use palette
if (i < SEGLEN -1)
{
- SEGMENT.setPixelColor(i + 1, SEGMENT.color_from_palette(pos, false, false, 255));
+ SEGMENT.setPixelColor(i + 1, SEGMENT.color_from_palette(pos, false, false, 255)); // do not use color 1 or 2, always use palette
}
}
SEGENV.step += FRAMETIME;
return FRAMETIME;
}
-static const char _data_FX_MODE_RAILWAY[] PROGMEM = "Railway";
+static const char _data_FX_MODE_RAILWAY[] PROGMEM = "Railway@!,Smoothness;1,2;!";
//Water ripple
@@ -2396,89 +2386,83 @@ typedef struct Ripple {
#else
#define MAX_RIPPLES 100
#endif
-uint16_t ripple_base(bool rainbow)
+uint16_t ripple_base()
{
uint16_t maxRipples = min(1 + (SEGLEN >> 2), MAX_RIPPLES); // 56 max for 16 segment ESP8266
uint16_t dataSize = sizeof(ripple) * maxRipples;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
-
+
Ripple* ripples = reinterpret_cast(SEGENV.data);
- // ranbow background or chosen background, all very dim.
- if (rainbow) {
- if (SEGENV.call ==0) {
- SEGENV.aux0 = random8();
- SEGENV.aux1 = random8();
- }
- if (SEGENV.aux0 == SEGENV.aux1) {
- SEGENV.aux1 = random8();
- }
- else if (SEGENV.aux1 > SEGENV.aux0) {
- SEGENV.aux0++;
- } else {
- SEGENV.aux0--;
- }
- SEGMENT.fill(color_blend(SEGMENT.color_wheel(SEGENV.aux0),BLACK,235));
- } else {
- SEGMENT.fill(SEGCOLOR(1));
- }
-
//draw wave
- for (int i = 0; i < maxRipples; i++)
- {
+ for (int i = 0; i < maxRipples; i++) {
uint16_t ripplestate = ripples[i].state;
- if (ripplestate)
- {
+ if (ripplestate) {
uint8_t rippledecay = (SEGMENT.speed >> 4) +1; //faster decay if faster propagation
uint16_t rippleorigin = ripples[i].pos;
uint32_t col = SEGMENT.color_from_palette(ripples[i].color, false, false, 255);
- uint16_t propagation = ((ripplestate/rippledecay -1) * SEGMENT.speed);
+ uint16_t propagation = ((ripplestate/rippledecay - 1) * (SEGMENT.speed + 1));
int16_t propI = propagation >> 8;
uint8_t propF = propagation & 0xFF;
- int16_t left = rippleorigin - propI -1;
uint8_t amp = (ripplestate < 17) ? triwave8((ripplestate-1)*8) : map(ripplestate,17,255,255,2);
- for (int16_t v = left; v < left +4; v++)
+ #ifndef WLED_DISABLE_2D
+ if (SEGMENT.is2D()) {
+ uint16_t cx = rippleorigin >> 8;
+ uint16_t cy = rippleorigin & 0xFF;
+ uint8_t mag = scale8(cubicwave8((propF>>2)), amp);
+ if (propI > 0) SEGMENT.draw_circle(cx, cy, propI, color_blend(SEGMENT.getPixelColorXY(cx + propI, cy), col, mag));
+ } else
+ #endif
{
- uint8_t mag = scale8(cubicwave8((propF>>2)+(v-left)*64), amp);
- if (v < SEGLEN && v >= 0)
- {
+ int16_t left = rippleorigin - propI -1;
+ for (int16_t v = left; v < left +4; v++) {
+ uint8_t mag = scale8(cubicwave8((propF>>2)+(v-left)*64), amp);
SEGMENT.setPixelColor(v, color_blend(SEGMENT.getPixelColor(v), col, mag)); // TODO
- }
- int16_t w = left + propI*2 + 3 -(v-left);
- if (w < SEGLEN && w >= 0)
- {
+ int16_t w = left + propI*2 + 3 -(v-left);
SEGMENT.setPixelColor(w, color_blend(SEGMENT.getPixelColor(w), col, mag)); // TODO
}
- }
+ }
ripplestate += rippledecay;
ripples[i].state = (ripplestate > 254) ? 0 : ripplestate;
- } else //randomly create new wave
- {
- if (random16(IBN + 10000) <= SEGMENT.intensity)
- {
+ } else {//randomly create new wave
+ if (random16(IBN + 10000) <= SEGMENT.intensity) {
ripples[i].state = 1;
- ripples[i].pos = random16(SEGLEN);
+ ripples[i].pos = SEGMENT.is2D() ? ((random8(SEGENV.virtualWidth())<<8) | (random8(SEGENV.virtualHeight()))) : random16(SEGLEN);
ripples[i].color = random8(); //color
}
}
}
+
return FRAMETIME;
}
#undef MAX_RIPPLES
uint16_t mode_ripple(void) {
- return ripple_base(false);
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
+ return ripple_base();
}
-static const char _data_FX_MODE_RIPPLE[] PROGMEM = "Ripple";
+static const char _data_FX_MODE_RIPPLE[] PROGMEM = "Ripple@!,Wave #,,,,,Overlay;,!;!;12";
uint16_t mode_ripple_rainbow(void) {
- return ripple_base(true);
+ if (SEGENV.call ==0) {
+ SEGENV.aux0 = random8();
+ SEGENV.aux1 = random8();
+ }
+ if (SEGENV.aux0 == SEGENV.aux1) {
+ SEGENV.aux1 = random8();
+ } else if (SEGENV.aux1 > SEGENV.aux0) {
+ SEGENV.aux0++;
+ } else {
+ SEGENV.aux0--;
+ }
+ SEGMENT.fill(color_blend(SEGMENT.color_wheel(SEGENV.aux0),BLACK,235));
+ return ripple_base();
}
-static const char _data_FX_MODE_RIPPLE_RAINBOW[] PROGMEM = "Ripple Rainbow";
+static const char _data_FX_MODE_RIPPLE_RAINBOW[] PROGMEM = "Ripple Rainbow@!,Wave #;;!;12";
// TwinkleFOX by Mark Kriegsman: https://gist.github.com/kriegsman/756ea6dcae8e30845b5a
@@ -2500,7 +2484,7 @@ CRGB twinklefox_one_twinkle(uint32_t ms, uint8_t salt, bool cat)
slowcycle16 += sin8(slowcycle16);
slowcycle16 = (slowcycle16 * 2053) + 1384;
uint8_t slowcycle8 = (slowcycle16 & 0xFF) + (slowcycle16 >> 8);
-
+
// Overall twinkle density.
// 0 (NONE lit) to 8 (ALL lit at once).
// Default is 5.
@@ -2533,7 +2517,7 @@ CRGB twinklefox_one_twinkle(uint32_t ms, uint8_t salt, bool cat)
// This code takes a pixel, and if its in the 'fading down'
// part of the cycle, it adjusts the color a little bit like the
// way that incandescent bulbs fade toward 'red' as they dim.
- if (fastcycle8 >= 128)
+ if (fastcycle8 >= 128)
{
uint8_t cooling = (fastcycle8 - 128) >> 4;
c.g = qsub8(c.g, cooling);
@@ -2577,7 +2561,7 @@ uint16_t twinklefox_base(bool cat)
uint8_t backgroundBrightness = bg.getAverageLight();
for (int i = 0; i < SEGLEN; i++) {
-
+
PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
uint16_t myclockoffset16= PRNG16; // use that number as clock offset
PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
@@ -2615,14 +2599,14 @@ uint16_t mode_twinklefox()
{
return twinklefox_base(false);
}
-static const char _data_FX_MODE_TWINKLEFOX[] PROGMEM = "Twinklefox";
+static const char _data_FX_MODE_TWINKLEFOX[] PROGMEM = "Twinklefox@!,Twinkle rate;;!";
uint16_t mode_twinklecat()
{
return twinklefox_base(true);
}
-static const char _data_FX_MODE_TWINKLECAT[] PROGMEM = "Twinklecat";
+static const char _data_FX_MODE_TWINKLECAT[] PROGMEM = "Twinklecat@!,Twinkle rate;;!";
//inspired by https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectBlinkingHalloweenEyes
@@ -2634,7 +2618,7 @@ uint16_t mode_halloween_eyes()
uint16_t eyeLength = (2*HALLOWEEN_EYE_WIDTH) + HALLOWEEN_EYE_SPACE;
if (eyeLength >= maxWidth) return mode_static(); //bail if segment too short
- SEGMENT.fill(SEGCOLOR(1)); //fill background
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1)); //fill background
uint8_t state = SEGENV.aux1 >> 8;
uint16_t stateTime = SEGENV.call;
@@ -2646,15 +2630,15 @@ uint16_t mode_halloween_eyes()
if (strip.isMatrix) SEGMENT.offset = random16(SEGMENT.virtualHeight()-1); // a hack: reuse offset since it is not used in matrices
state = 1;
}
-
+
if (state < 2) { //fade eyes
uint16_t startPos = SEGENV.aux0;
uint16_t start2ndEye = startPos + HALLOWEEN_EYE_WIDTH + HALLOWEEN_EYE_SPACE;
-
+
uint32_t fadestage = (strip.now - SEGENV.step)*255 / stateTime;
if (fadestage > 255) fadestage = 255;
uint32_t c = color_blend(SEGMENT.color_from_palette(SEGENV.aux1 & 0xFF, false, false, 0), SEGCOLOR(1), fadestage);
-
+
for (int i = 0; i < HALLOWEEN_EYE_WIDTH; i++) {
if (strip.isMatrix) {
SEGMENT.setPixelColorXY(startPos + i, SEGMENT.offset, c);
@@ -2669,7 +2653,7 @@ uint16_t mode_halloween_eyes()
if (strip.now - SEGENV.step > stateTime) {
state++;
if (state > 2) state = 0;
-
+
if (state < 2) {
stateTime = 100 + SEGMENT.intensity*10; //eye fade time
} else {
@@ -2681,10 +2665,10 @@ uint16_t mode_halloween_eyes()
}
SEGENV.aux1 = (SEGENV.aux1 & 0xFF) + (state << 8); //save state
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_HALLOWEEN_EYES[] PROGMEM = "Halloween Eyes@Duration,Eye fade time;!,!;!;1d,2d";
+static const char _data_FX_MODE_HALLOWEEN_EYES[] PROGMEM = "Halloween Eyes@Duration,Eye fade time,,,,,Overlay;!,!;!;12";
//Speed slider sets amount of LEDs lit, intensity sets unlit
@@ -2703,10 +2687,10 @@ uint16_t mode_static_pattern()
drawingLit = !drawingLit;
}
}
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_STATIC_PATTERN[] PROGMEM = "Solid Pattern@Fg size,Bg size;Fg,Bg;!;pal=0,1d";
+static const char _data_FX_MODE_STATIC_PATTERN[] PROGMEM = "Solid Pattern@Fg size,Bg size;Fg,!;!;;pal=0";
uint16_t mode_tri_static_pattern()
@@ -2732,13 +2716,13 @@ uint16_t mode_tri_static_pattern()
return FRAMETIME;
}
-static const char _data_FX_MODE_TRI_STATIC_PATTERN[] PROGMEM = "Solid Pattern Tri@,Size;1,2,3;!;1d,pal=0";
+static const char _data_FX_MODE_TRI_STATIC_PATTERN[] PROGMEM = "Solid Pattern Tri@,Size;1,2,3;;;pal=0";
uint16_t spots_base(uint16_t threshold)
{
- SEGMENT.fill(SEGCOLOR(1));
-
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
+
uint16_t maxZones = SEGLEN >> 2;
uint16_t zones = 1 + ((SEGMENT.intensity * maxZones) >> 8);
uint16_t zoneLen = SEGLEN / zones;
@@ -2757,7 +2741,7 @@ uint16_t spots_base(uint16_t threshold)
}
}
}
-
+
return FRAMETIME;
}
@@ -2767,7 +2751,7 @@ uint16_t mode_spots()
{
return spots_base((255 - SEGMENT.speed) << 8);
}
-static const char _data_FX_MODE_SPOTS[] PROGMEM = "Spots@Spread,Width;!,!;!;1d";
+static const char _data_FX_MODE_SPOTS[] PROGMEM = "Spots@,Width,,,,,Overlay;!,!;!";
//Intensity slider sets number of "lights", LEDs per light fade in and out
@@ -2778,7 +2762,7 @@ uint16_t mode_spots_fade()
uint16_t tr = (t >> 1) + (t >> 2);
return spots_base(tr);
}
-static const char _data_FX_MODE_SPOTS_FADE[] PROGMEM = "Spots Fade@Spread,Width;!,!;!;1d";
+static const char _data_FX_MODE_SPOTS_FADE[] PROGMEM = "Spots Fade@Spread,Width,,,,,Overlay;!,!;!";
//each needs 12 bytes
@@ -2794,13 +2778,13 @@ typedef struct Ball {
uint16_t mode_bouncing_balls(void) {
//allocate segment data
const uint16_t strips = SEGMENT.nrOfVStrips(); // adapt for 2D
- const size_t maxNumBalls = 16;
+ const size_t maxNumBalls = 16;
uint16_t dataSize = sizeof(ball) * maxNumBalls;
if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed
-
+
Ball* balls = reinterpret_cast(SEGENV.data);
- SEGMENT.fill(SEGCOLOR(2) ? BLACK : SEGCOLOR(1));
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(2) ? BLACK : SEGCOLOR(1));
// virtualStrip idea by @ewowi (Ewoud Wijma)
// requires virtual strip # to be embedded into upper 16 bits of index in setPixelColor()
@@ -2817,7 +2801,7 @@ uint16_t mode_bouncing_balls(void) {
if (SEGENV.call == 0) {
for (size_t i = 0; i < maxNumBalls; i++) balls[i].lastBounceTime = time;
}
-
+
for (size_t i = 0; i < numBalls; i++) {
float timeSinceLastBounce = (time - balls[i].lastBounceTime)/((255-SEGMENT.speed)/64 +1);
float timeSec = timeSinceLastBounce/1000.0f;
@@ -2831,13 +2815,13 @@ uint16_t mode_bouncing_balls(void) {
balls[i].lastBounceTime = time;
if (balls[i].impactVelocity < 0.015f) {
- float impactVelocityStart = sqrtf(-2 * gravity) * random8(5,11)/10.0f; // randomize impact velocity
+ float impactVelocityStart = sqrtf(-2.0f * gravity) * random8(5,11)/10.0f; // randomize impact velocity
balls[i].impactVelocity = impactVelocityStart;
}
} else if (balls[i].height > 1.0f) {
continue; // do not draw OOB ball
}
-
+
uint32_t color = SEGCOLOR(0);
if (SEGMENT.palette) {
color = SEGMENT.color_wheel(i*(256/MAX(numBalls, 8)));
@@ -2857,7 +2841,7 @@ uint16_t mode_bouncing_balls(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_BOUNCINGBALLS[] PROGMEM = "Bouncing Balls@Gravity,# of balls;!,!,!;!;m12=1,1.5d"; //bar
+static const char _data_FX_MODE_BOUNCINGBALLS[] PROGMEM = "Bouncing Balls@Gravity,# of balls,,,,,Overlay;!,!,!;!;1.5d;m12=1"; //bar WLEDMM 1.5d
/*
@@ -2878,7 +2862,7 @@ uint16_t sinelon_base(bool dual, bool rainbow=false) {
if (rainbow) color2 = color1; //rainbow
SEGMENT.setPixelColor(SEGLEN-1-pos, color2);
}
- if (SEGENV.aux0 != pos) {
+ if (SEGENV.aux0 != pos) {
if (SEGENV.aux0 < pos) {
for (int i = SEGENV.aux0; i < pos ; i++) {
SEGMENT.setPixelColor(i, color1);
@@ -2900,34 +2884,50 @@ uint16_t sinelon_base(bool dual, bool rainbow=false) {
uint16_t mode_sinelon(void) {
return sinelon_base(false);
}
-static const char _data_FX_MODE_SINELON[] PROGMEM = "Sinelon";
+static const char _data_FX_MODE_SINELON[] PROGMEM = "Sinelon@!,Trail;!,!,!;!";
uint16_t mode_sinelon_dual(void) {
return sinelon_base(true);
}
-static const char _data_FX_MODE_SINELON_DUAL[] PROGMEM = "Sinelon Dual";
+static const char _data_FX_MODE_SINELON_DUAL[] PROGMEM = "Sinelon Dual@!,Trail;!,!,!;!";
uint16_t mode_sinelon_rainbow(void) {
return sinelon_base(false, true);
}
-static const char _data_FX_MODE_SINELON_RAINBOW[] PROGMEM = "Sinelon Rainbow";
+static const char _data_FX_MODE_SINELON_RAINBOW[] PROGMEM = "Sinelon Rainbow@!,Trail;,,!;!";
-//Rainbow with glitter, inspired by https://gist.github.com/kriegsman/062e10f7f07ba8518af6
+// utility function that will add random glitter to SEGMENT
+void glitter_base(uint8_t intensity, uint32_t col = ULTRAWHITE) {
+ if (intensity > random8()) {
+ if (SEGMENT.is2D()) {
+ SEGMENT.setPixelColorXY(random16(SEGMENT.virtualWidth()),random16(SEGMENT.virtualHeight()), col);
+ } else {
+ SEGMENT.setPixelColor(random16(SEGLEN), col);
+ }
+ }
+}
+
+//Glitter with palette background, inspired by https://gist.github.com/kriegsman/062e10f7f07ba8518af6
uint16_t mode_glitter()
{
- mode_palette();
-
- if (SEGMENT.intensity > random8())
- {
- SEGMENT.setPixelColor(random16(SEGLEN), ULTRAWHITE);
- }
-
+ if (!SEGMENT.check2) mode_palette(); // use "* Color 1" palette for solid background (replacing "Solid glitter")
+ glitter_base(SEGMENT.intensity, SEGCOLOR(2) ? SEGCOLOR(2) : ULTRAWHITE);
return FRAMETIME;
}
-static const char _data_FX_MODE_GLITTER[] PROGMEM = "Glitter@,!;!,!,!;!;m12=0,1d"; //pixels
+static const char _data_FX_MODE_GLITTER[] PROGMEM = "Glitter@!,!,,,,,Overlay;1,2,Glitter color;!;;pal=0,m12=0"; //pixels
+
+
+//Solid colour background with glitter
+uint16_t mode_solid_glitter()
+{
+ SEGMENT.fill(SEGCOLOR(0));
+ glitter_base(SEGMENT.intensity, SEGCOLOR(2) ? SEGCOLOR(2) : ULTRAWHITE);
+ return FRAMETIME;
+}
+static const char _data_FX_MODE_SOLID_GLITTER[] PROGMEM = "Solid Glitter@,!;Bg,,Glitter color;;;m12=0";
//each needs 19 bytes
@@ -2953,7 +2953,7 @@ uint16_t mode_popcorn(void) {
Spark* popcorn = reinterpret_cast(SEGENV.data);
bool hasCol2 = SEGCOLOR(2);
- SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1));
+ if (!SEGMENT.check2) SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1));
struct virtualStrip {
static void runStrip(uint16_t stripNr, Spark* popcorn) {
@@ -2973,7 +2973,7 @@ uint16_t mode_popcorn(void) {
uint16_t peakHeight = 128 + random8(128); //0-255
peakHeight = (peakHeight * (SEGLEN -1)) >> 8;
- popcorn[i].vel = sqrtf(-2.0 * gravity * peakHeight);
+ popcorn[i].vel = sqrtf(-2.0f * gravity * peakHeight);
if (SEGMENT.palette)
{
@@ -3000,7 +3000,7 @@ uint16_t mode_popcorn(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_POPCORN[] PROGMEM = "Popcorn@!,!;!,!,!;!;m12=1,1.5d"; //bar
+static const char _data_FX_MODE_POPCORN[] PROGMEM = "Popcorn@!,!,,,,,Overlay;!,!,!;!;1.5d;m12=1"; //bar WLEDMM 1.5d
//values close to 100 produce 5Hz flicker, which looks very candle-y
@@ -3061,7 +3061,7 @@ uint16_t candle(bool multi)
s_target += offset;
uint8_t dif = (s_target > s) ? s_target - s : s - s_target;
-
+
fadeStep = dif >> speedFactor;
if (fadeStep == 0) fadeStep = 1;
}
@@ -3087,14 +3087,14 @@ uint16_t mode_candle()
{
return candle(false);
}
-static const char _data_FX_MODE_CANDLE[] PROGMEM = "Candle@Flicker rate,Flicker intensity;!,!;!;sx=96,ix=224,pal=0,1d";
+static const char _data_FX_MODE_CANDLE[] PROGMEM = "Candle@!,!;!,!;!;1;sx=96,ix=224,pal=0";
uint16_t mode_candle_multi()
{
return candle(true);
}
-static const char _data_FX_MODE_CANDLE_MULTI[] PROGMEM = "Candle Multi@Flicker rate,Flicker intensity;!,!;!;sx=96,ix=224,pal=0,1d";
+static const char _data_FX_MODE_CANDLE_MULTI[] PROGMEM = "Candle Multi@!,!;!,!;!;;sx=96,ix=224,pal=0";
/*
@@ -3129,26 +3129,26 @@ uint16_t mode_starburst(void) {
uint16_t dataSize = sizeof(star) * numStars;
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
-
+
uint32_t it = millis();
-
+
star* stars = reinterpret_cast(SEGENV.data);
-
+
float maxSpeed = 375.0f; // Max velocity
float particleIgnition = 250.0f; // How long to "flash"
float particleFadeTime = 1500.0f; // Fade out time
-
+
for (int j = 0; j < numStars; j++)
{
// speed to adjust chance of a burst, max is nearly always.
if (random8((144-(SEGMENT.speed >> 1))) == 0 && stars[j].birth == 0)
{
- // Pick a random color and location.
+ // Pick a random color and location.
uint16_t startPos = random16(SEGLEN-1);
float multiplier = (float)(random8())/255.0 * 1.0;
stars[j].color = CRGB(SEGMENT.color_wheel(random8()));
- stars[j].pos = startPos;
+ stars[j].pos = startPos;
stars[j].vel = maxSpeed * (float)(random8())/255.0 * multiplier;
stars[j].birth = it;
stars[j].last = it;
@@ -3161,9 +3161,9 @@ uint16_t mode_starburst(void) {
}
}
}
-
- SEGMENT.fill(SEGCOLOR(1));
-
+
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
+
for (int j=0; j> 1;
-
+
if (stars[j].fragment[i] > 0) {
//all fragments travel right, will be mirrored on other side
stars[j].fragment[i] += stars[j].vel * dt * (float)var/3.0;
@@ -3180,10 +3180,10 @@ uint16_t mode_starburst(void) {
stars[j].last = it;
stars[j].vel -= 3*stars[j].vel*dt;
}
-
+
CRGB c = stars[j].color;
- // If the star is brand new, it flashes white briefly.
+ // If the star is brand new, it flashes white briefly.
// Otherwise it just fades over time.
float fade = 0.0f;
float age = it-stars[j].birth;
@@ -3191,7 +3191,7 @@ uint16_t mode_starburst(void) {
if (age < particleIgnition) {
c = CRGB(color_blend(WHITE, RGBW32(c.r,c.g,c.b,0), 254.5f*((age / particleIgnition))));
} else {
- // Figure out how much to fade and shrink the star based on
+ // Figure out how much to fade and shrink the star based on
// its age relative to its lifetime
if (age > particleIgnition + particleFadeTime) {
fade = 1.0f; // Black hole, all faded out
@@ -3204,7 +3204,7 @@ uint16_t mode_starburst(void) {
c = CRGB(color_blend(RGBW32(c.r,c.g,c.b,0), SEGCOLOR(1), f));
}
}
-
+
float particleSize = (1.0f - fade) * 2.0f;
for (size_t index=0; index < STARBURST_MAX_FRAG*2; index++) {
@@ -3217,7 +3217,7 @@ uint16_t mode_starburst(void) {
int end = loc + particleSize;
if (start < 0) start = 0;
if (start == end) end++;
- if (end > SEGLEN) end = SEGLEN;
+ if (end > SEGLEN) end = SEGLEN;
for (int p = start; p < end; p++) {
SEGMENT.setPixelColor(p, c.r, c.g, c.b);
}
@@ -3227,7 +3227,7 @@ uint16_t mode_starburst(void) {
return FRAMETIME;
}
#undef STARBURST_MAX_FRAG
-static const char _data_FX_MODE_STARBURST[] PROGMEM = "Fireworks Starburst@Chance,Fragments;,!;!;pal=11,m12=0,1d";
+static const char _data_FX_MODE_STARBURST[] PROGMEM = "Fireworks Starburst@Chance,Fragments,,,,,Overlay;,!;!;;pal=11,m12=0";
/*
@@ -3258,28 +3258,27 @@ uint16_t mode_exploding_fireworks(void)
SEGENV.aux1 = dataSize;
}
- //SEGMENT.fill(BLACK);
SEGMENT.fade_out(252);
-
+
Spark* sparks = reinterpret_cast(SEGENV.data);
Spark* flare = sparks; //first spark is flare data
float gravity = -0.0004f - (SEGMENT.speed/800000.0f); // m/s/s
gravity *= rows;
-
+
if (SEGENV.aux0 < 2) { //FLARE
if (SEGENV.aux0 == 0) { //init flare
flare->pos = 0;
- flare->posX = strip.isMatrix ? random16(2,cols-1) : (SEGMENT.intensity > random8()); // will enable random firing side on 1D
+ flare->posX = strip.isMatrix ? random16(2,cols-3) : (SEGMENT.intensity > random8()); // will enable random firing side on 1D
uint16_t peakHeight = 75 + random8(180); //0-255
peakHeight = (peakHeight * (rows -1)) >> 8;
flare->vel = sqrtf(-2.0f * gravity * peakHeight);
- flare->velX = strip.isMatrix ? (random8(8)-4)/32.f : 0; // no X velocity on 1D
+ flare->velX = strip.isMatrix ? (random8(9)-4)/32.f : 0; // no X velocity on 1D
flare->col = 255; //brightness
- SEGENV.aux0 = 1;
+ SEGENV.aux0 = 1;
}
-
- // launch
+
+ // launch
if (flare->vel > 12 * gravity) {
// flare
if (strip.isMatrix) SEGMENT.setPixelColorXY(int(flare->posX), rows - uint16_t(flare->pos) - 1, flare->col, flare->col, flare->col);
@@ -3296,40 +3295,40 @@ uint16_t mode_exploding_fireworks(void)
} else if (SEGENV.aux0 < 4) {
/*
* Explode!
- *
+ *
* Explosion happens where the flare ended.
* Size is proportional to the height.
*/
int nSparks = flare->pos + random8(4);
- nSparks = constrain(nSparks, 1, numSparks);
-
+ nSparks = constrain(nSparks, 4, numSparks);
+
// initialize sparks
if (SEGENV.aux0 == 2) {
- for (int i = 1; i < nSparks; i++) {
+ for (int i = 1; i < nSparks; i++) {
sparks[i].pos = flare->pos;
sparks[i].posX = flare->posX;
- sparks[i].vel = (float(random16(0, 20000)) / 10000.0f) - 0.9f; // from -0.9 to 1.1
+ sparks[i].vel = (float(random16(20001)) / 10000.0f) - 0.9f; // from -0.9 to 1.1
sparks[i].vel *= rows<32 ? 0.5f : 1; // reduce velocity for smaller strips
- sparks[i].velX = strip.isMatrix ? (float(random16(0, 4000)) / 10000.0f) - 0.2f : 0; // from -0.2 to 0.2
- sparks[i].col = 345;//abs(sparks[i].vel * 750.0); // set colors before scaling velocity to keep them bright
- //sparks[i].col = constrain(sparks[i].col, 0, 345);
+ sparks[i].velX = strip.isMatrix ? (float(random16(10001)) / 10000.0f) - 0.5f : 0; // from -0.5 to 0.5
+ sparks[i].col = 345;//abs(sparks[i].vel * 750.0); // set colors before scaling velocity to keep them bright
+ //sparks[i].col = constrain(sparks[i].col, 0, 345);
sparks[i].colIndex = random8();
- sparks[i].vel *= flare->pos/rows; // proportional to height
+ sparks[i].vel *= flare->pos/rows; // proportional to height
sparks[i].velX *= strip.isMatrix ? flare->posX/cols : 0; // proportional to width
sparks[i].vel *= -gravity *50;
- }
- //sparks[1].col = 345; // this will be our known spark
- *dying_gravity = gravity/2;
+ }
+ //sparks[1].col = 345; // this will be our known spark
+ *dying_gravity = gravity/2;
SEGENV.aux0 = 3;
}
-
+
if (sparks[1].col > 4) {//&& sparks[1].pos > 0) { // as long as our known spark is lit, work with all the sparks
for (int i = 1; i < nSparks; i++) {
sparks[i].pos += sparks[i].vel;
sparks[i].posX += sparks[i].velX;
sparks[i].vel += *dying_gravity;
sparks[i].velX += strip.isMatrix ? *dying_gravity : 0;
- if (sparks[i].col > 3) sparks[i].col -= 4;
+ if (sparks[i].col > 3) sparks[i].col -= 4;
if (sparks[i].pos > 0 && sparks[i].pos < rows) {
if (strip.isMatrix && !(sparks[i].posX >= 0 && sparks[i].posX < cols)) continue;
@@ -3360,10 +3359,10 @@ uint16_t mode_exploding_fireworks(void)
}
}
- return FRAMETIME;
+ return FRAMETIME;
}
#undef MAX_SPARKS
-static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gravity,Firing side;!,!;!=11;ix=128,1d,2d";
+static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gravity,Firing side;!,!;!;12;pal=11,ix=128";
/*
@@ -3374,13 +3373,13 @@ uint16_t mode_drip(void)
{
//allocate segment data
uint16_t strips = SEGMENT.nrOfVStrips();
- const int maxNumDrops = 4;
+ const int maxNumDrops = 4;
uint16_t dataSize = sizeof(spark) * maxNumDrops;
if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed
Spark* drops = reinterpret_cast(SEGENV.data);
- SEGMENT.fill(SEGCOLOR(1));
-
+ if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
+
struct virtualStrip {
static void runStrip(uint16_t stripNr, Spark* drops) {
@@ -3451,7 +3450,7 @@ uint16_t mode_drip(void)
return FRAMETIME;
}
-static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips,Fall ratio;!,!;!;m12=1,1.5d"; //bar
+static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips,,,,,Overlay;!,!;!;1.5d;m12=1"; //bar WLEDMM 1.5d
/*
@@ -3474,7 +3473,7 @@ uint16_t mode_tetrix(void) {
if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed
Tetris* drops = reinterpret_cast(SEGENV.data);
- if (SEGENV.call == 0) SEGMENT.fill(SEGCOLOR(1)); // will fill entire segment (1D or 2D)
+ //if (SEGENV.call == 0) SEGMENT.fill(SEGCOLOR(1)); // will fill entire segment (1D or 2D), then use drop->step = 0 below
// virtualStrip idea by @ewowi (Ewoud Wijma)
// requires virtual strip # to be embedded into upper 16 bits of index in setPixelcolor()
@@ -3484,10 +3483,10 @@ uint16_t mode_tetrix(void) {
// initialize dropping on first call or segment full
if (SEGENV.call == 0) {
drop->stack = 0; // reset brick stack size
- drop->step = 0;
- //for (int i=0; istep = millis() + 2000; // start by fading out strip
+ if (SEGMENT.check1) drop->col = 0;// use only one color from palette
}
-
+
if (drop->step == 0) { // init brick
// speed calcualtion: a single brick should reach bottom of strip in X seconds
// if the speed is set to 1 this should take 5s and at 255 it should take 0.25s
@@ -3496,11 +3495,11 @@ uint16_t mode_tetrix(void) {
speed = map(speed, 1, 255, 5000, 250); // time taken for full (SEGLEN) drop
drop->speed = float(SEGLEN * FRAMETIME) / float(speed); // set speed
drop->pos = SEGLEN; // start at end of segment (no need to subtract 1)
- drop->col = random8(0,15)<<4; // limit color choices so there is enough HUE gap
+ if (!SEGMENT.check1) drop->col = random8(0,15)<<4; // limit color choices so there is enough HUE gap
drop->step = 1; // drop state (0 init, 1 forming, 2 falling)
drop->brick = (SEGMENT.intensity ? (SEGMENT.intensity>>5)+1 : random8(1,5)) * (1+(SEGLEN>>6)); // size of brick
}
-
+
if (drop->step == 1) { // forming
if (random8()>>6) { // random drop
drop->step = 2; // fall
@@ -3510,7 +3509,7 @@ uint16_t mode_tetrix(void) {
if (drop->step == 2) { // falling
if (drop->pos > drop->stack) { // fall until top of stack
drop->pos -= drop->speed; // may add gravity as: speed += gravity
- if (uint16_t(drop->pos) < drop->stack) drop->pos = drop->stack;
+ if (int(drop->pos) < int(drop->stack)) drop->pos = drop->stack;
for (int i=int(drop->pos); ipos)+drop->brick ? SEGMENT.color_from_palette(drop->col, false, false, 0) : SEGCOLOR(1);
SEGMENT.setPixelColor(indexToVStrip(i, stripNr), col);
@@ -3530,6 +3529,7 @@ uint16_t mode_tetrix(void) {
} else {
drop->stack = 0; // reset brick stack size
drop->step = 0; // proceed with next brick
+ if (SEGMENT.check1) drop->col += 8; // gradually increase palette index
}
}
}
@@ -3538,9 +3538,9 @@ uint16_t mode_tetrix(void) {
for (int stripNr=0; stripNr> 11));
if (SEGMENT.speed == 255) size = 255;
-
+
if (percent <= 100) {
for (int i = 0; i < SEGLEN; i++) {
if (i < SEGENV.aux1) {
@@ -3619,12 +3619,12 @@ uint16_t mode_percent(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_PERCENT[] PROGMEM = "Percent@,% of fill,,,,One color;!,!;!;1d";
+static const char _data_FX_MODE_PERCENT[] PROGMEM = "Percent@,% of fill,,,,One color;!,!;!";
/*
* Modulates the brightness similar to a heartbeat
- * tries to draw an ECG aproximation on a 2D matrix
+ * (unimplemented?) tries to draw an ECG aproximation on a 2D matrix
*/
uint16_t mode_heartbeat(void) {
uint8_t bpm = 40 + (SEGMENT.speed >> 3);
@@ -3652,7 +3652,7 @@ uint16_t mode_heartbeat(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_HEARTBEAT[] PROGMEM = "Heartbeat@!,!;!,!;!;m12=1,1d";
+static const char _data_FX_MODE_HEARTBEAT[] PROGMEM = "Heartbeat@!,!;!,!;!;;m12=1"; //Bar
// "Pacifica"
@@ -3661,16 +3661,16 @@ static const char _data_FX_MODE_HEARTBEAT[] PROGMEM = "Heartbeat@!,!;!,!;!;m12=1
// For Dan.
//
//
-// In this animation, there are four "layers" of waves of light.
+// In this animation, there are four "layers" of waves of light.
//
// Each layer moves independently, and each is scaled separately.
//
-// All four wave layers are added together on top of each other, and then
-// another filter is applied that adds "whitecaps" of brightness where the
+// All four wave layers are added together on top of each other, and then
+// another filter is applied that adds "whitecaps" of brightness where the
// waves line up with each other more. Finally, another pass is taken
// over the led array to 'deepen' (dim) the blues and greens.
//
-// The speed and scale and motion each layer varies slowly within independent
+// The speed and scale and motion each layer varies slowly within independent
// hand-chosen ranges, which is why the code has a lot of low-speed 'beatsin8' functions
// with a lot of oddly specific numeric ranges.
//
@@ -3685,7 +3685,7 @@ CRGB pacifica_one_layer(uint16_t i, CRGBPalette16& p, uint16_t cistart, uint16_t
uint16_t ci = cistart;
uint16_t waveangle = ioff;
uint16_t wavescale_half = (wavescale >> 1) + 20;
-
+
waveangle += ((120 + SEGMENT.intensity) * i); //original 250 * i
uint16_t s16 = sin16(waveangle) + 32768;
uint16_t cs = scale16(s16, wavescale_half) + wavescale_half;
@@ -3699,14 +3699,14 @@ uint16_t mode_pacifica()
{
uint32_t nowOld = strip.now;
- CRGBPalette16 pacifica_palette_1 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
+ CRGBPalette16 pacifica_palette_1 =
+ { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50 };
- CRGBPalette16 pacifica_palette_2 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
+ CRGBPalette16 pacifica_palette_2 =
+ { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F };
- CRGBPalette16 pacifica_palette_3 =
- { 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
+ CRGBPalette16 pacifica_palette_3 =
+ { 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };
if (SEGMENT.palette) {
@@ -3739,7 +3739,7 @@ uint16_t mode_pacifica()
uint8_t basethreshold = beatsin8( 9, 55, 65);
uint8_t wave = beat8( 7 );
-
+
for (int i = 0; i < SEGLEN; i++) {
CRGB c = CRGB(2, 6, 10);
// Render each of four layers, with different scales and speeds, that vary over time
@@ -3747,7 +3747,7 @@ uint16_t mode_pacifica()
c += pacifica_one_layer(i, pacifica_palette_2, sCIStart2, beatsin16(4, 6 * 256, 9 * 256), beatsin8(17, 40, 80), beat16(401));
c += pacifica_one_layer(i, pacifica_palette_3, sCIStart3, 6 * 256 , beatsin8(9, 10,38) , 0-beat16(503));
c += pacifica_one_layer(i, pacifica_palette_3, sCIStart4, 5 * 256 , beatsin8(8, 10,28) , beat16(601));
-
+
// Add extra 'white' to areas where the four layers of light have lined up brightly
uint8_t threshold = scale8( sin8( wave), 20) + basethreshold;
wave += 7;
@@ -3759,8 +3759,8 @@ uint16_t mode_pacifica()
}
//deepen the blues and greens
- c.blue = scale8(c.blue, 145);
- c.green = scale8(c.green, 200);
+ c.blue = scale8(c.blue, 145);
+ c.green = scale8(c.green, 200);
c |= CRGB( 2, 5, 7);
SEGMENT.setPixelColor(i, c.red, c.green, c.blue);
@@ -3769,22 +3769,7 @@ uint16_t mode_pacifica()
strip.now = nowOld;
return FRAMETIME;
}
-static const char _data_FX_MODE_PACIFICA[] PROGMEM = "Pacifica";
-
-
-//Solid colour background with glitter
-uint16_t mode_solid_glitter()
-{
- SEGMENT.fill(SEGCOLOR(0));
-
- if (SEGMENT.intensity > random8())
- {
- SEGMENT.setPixelColor(random16(SEGLEN), ULTRAWHITE);
- }
-
- return FRAMETIME;
-}
-static const char _data_FX_MODE_SOLID_GLITTER[] PROGMEM = "Solid Glitter@,!;!;0;m12=0,1d";
+static const char _data_FX_MODE_PACIFICA[] PROGMEM = "Pacifica@!,Angle;;!;;pal=51";
/*
@@ -3799,12 +3784,12 @@ uint16_t mode_sunrise() {
SEGENV.step = millis(); //save starting time, millis() because now can change from sync
SEGENV.aux0 = SEGMENT.speed;
}
-
- SEGMENT.fill(0);
+
+ SEGMENT.fill(BLACK);
uint16_t stage = 0xFFFF;
-
+
uint32_t s10SinceStart = (millis() - SEGENV.step) /100; //tenths of seconds
-
+
if (SEGMENT.speed > 120) { //quick sunrise and sunset
uint16_t counter = (strip.now >> 1) * (((SEGMENT.speed -120) >> 1) +1);
stage = triwave16(counter);
@@ -3816,7 +3801,7 @@ uint16_t mode_sunrise() {
stage = map(s10SinceStart, 0, s10Target, 0, 0xFFFF);
if (SEGMENT.speed > 60) stage = 0xFFFF - stage; //sunset
}
-
+
for (int i = 0; i <= SEGLEN/2; i++)
{
//default palette is Fire
@@ -3837,7 +3822,7 @@ uint16_t mode_sunrise() {
return FRAMETIME;
}
-static const char _data_FX_MODE_SUNRISE[] PROGMEM = "Sunrise@Time [min];;!;sx=60,1d";
+static const char _data_FX_MODE_SUNRISE[] PROGMEM = "Sunrise@Time [min],Width;;!;;sx=60";
/*
@@ -3872,13 +3857,13 @@ uint16_t phased_base(uint8_t moder) { // We're making sine wave
uint16_t mode_phased(void) {
return phased_base(0);
}
-static const char _data_FX_MODE_PHASED[] PROGMEM = "Phased";
+static const char _data_FX_MODE_PHASED[] PROGMEM = "Phased@!,!;!,!;!";
uint16_t mode_phased_noise(void) {
return phased_base(1);
}
-static const char _data_FX_MODE_PHASEDNOISE[] PROGMEM = "Phased Noise";
+static const char _data_FX_MODE_PHASEDNOISE[] PROGMEM = "Phased Noise@!,!;!,!;!";
uint16_t mode_twinkleup(void) { // A very short twinkle routine with fade-in and dual controls. By Andrew Tuline.
@@ -3893,7 +3878,7 @@ uint16_t mode_twinkleup(void) { // A very short twinkle routine
return FRAMETIME;
}
-static const char _data_FX_MODE_TWINKLEUP[] PROGMEM = "Twinkleup@!,Intensity;!,!;!;m12=0,1d";
+static const char _data_FX_MODE_TWINKLEUP[] PROGMEM = "Twinkleup@!,Intensity;!,!;!;;m12=0";
// Peaceful noise that's slow and with gradually changing palettes. Does not support WLED palettes or default colours or controls.
@@ -3932,7 +3917,7 @@ uint16_t mode_noisepal(void) { // Slow noise
return FRAMETIME;
}
-static const char _data_FX_MODE_NOISEPAL[] PROGMEM = "Noise Pal";
+static const char _data_FX_MODE_NOISEPAL[] PROGMEM = "Noise Pal@!,Scale;;!";
// Sine waves that have controllable phase change speed, frequency and cutoff. By Andrew Tuline.
@@ -3963,12 +3948,12 @@ static const char _data_FX_MODE_SINEWAVE[] PROGMEM = "Sine";
uint16_t mode_flow(void)
{
uint16_t counter = 0;
- if (SEGMENT.speed != 0)
+ if (SEGMENT.speed != 0)
{
counter = strip.now * ((SEGMENT.speed >> 2) +1);
counter = counter >> 8;
}
-
+
uint16_t maxZones = SEGLEN / 6; //only looks good if each zone has at least 6 LEDs
uint16_t zones = (SEGMENT.intensity * maxZones) >> 8;
if (zones & 0x01) zones++; //zones must be even
@@ -3992,7 +3977,7 @@ uint16_t mode_flow(void)
return FRAMETIME;
}
-static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,!;!,!,!;!;m12=1,1d"; //vertical
+static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,Zones;;!;;m12=1"; //vertical
/*
@@ -4001,7 +3986,6 @@ static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,!;!,!,!;!;m12=1,1d"; //
*/
uint16_t mode_chunchun(void)
{
- //SEGMENT.fill(SEGCOLOR(1));
SEGMENT.fade_out(254); // add a bit of trail
uint16_t counter = strip.now * (6 + (SEGMENT.speed >> 4));
uint16_t numBirds = 2 + (SEGLEN >> 3); // 2 + 1/8 of a segment
@@ -4018,7 +4002,7 @@ uint16_t mode_chunchun(void)
}
return FRAMETIME;
}
-static const char _data_FX_MODE_CHUNCHUN[] PROGMEM = "Chunchun@!,Gap size;!,!;!;1d";
+static const char _data_FX_MODE_CHUNCHUN[] PROGMEM = "Chunchun@!,Gap size;!,!;!";
//13 bytes
@@ -4165,7 +4149,7 @@ uint16_t mode_dancing_shadows(void)
return FRAMETIME;
}
-static const char _data_FX_MODE_DANCING_SHADOWS[] PROGMEM = "Dancing Shadows@!,# of shadows;!,!,!;!;1d";
+static const char _data_FX_MODE_DANCING_SHADOWS[] PROGMEM = "Dancing Shadows@!,# of shadows;!;!";
/*
@@ -4178,7 +4162,7 @@ uint16_t mode_washing_machine(void) {
speed /= quot;
SEGENV.step += (speed * 128.0f);
-
+
for (int i=0; i> 7));
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(col, false, PALETTE_SOLID_WRAP, 3));
@@ -4186,7 +4170,7 @@ uint16_t mode_washing_machine(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_WASHING_MACHINE[] PROGMEM = "Washing Machine";
+static const char _data_FX_MODE_WASHING_MACHINE[] PROGMEM = "Washing Machine@!,!;;!";
/*
@@ -4214,7 +4198,7 @@ uint16_t mode_blends(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_BLENDS[] PROGMEM = "Blends@Shift speed,Blend speed;1,2,3;!;1d";
+static const char _data_FX_MODE_BLENDS[] PROGMEM = "Blends@Shift speed,Blend speed;;!";
/*
@@ -4267,19 +4251,19 @@ uint16_t mode_tv_simulator(void) {
tvSimulator->sceeneColorBri = random8 ( 200, 240); // random start color-brightness for the sceene
SEGENV.aux1 = 1;
SEGENV.aux0 = 0;
- }
-
+ }
+
// slightly change the color-tone in this sceene
if ( SEGENV.aux0 == 0) {
// hue change in both directions
j = random8(4 * colorIntensity);
hue = (random8() < 128) ? ((j < tvSimulator->sceeneColorHue) ? tvSimulator->sceeneColorHue - j : 767 - tvSimulator->sceeneColorHue - j) : // negative
((j + tvSimulator->sceeneColorHue) < 767 ? tvSimulator->sceeneColorHue + j : tvSimulator->sceeneColorHue + j - 767) ; // positive
-
+
// saturation
j = random8(2 * colorIntensity);
sat = (tvSimulator->sceeneColorSat - j) < 0 ? 0 : tvSimulator->sceeneColorSat - j;
-
+
// brightness
j = random8(100);
bri = (tvSimulator->sceeneColorBri - j) < 0 ? 0 : tvSimulator->sceeneColorBri - j;
@@ -4303,7 +4287,7 @@ uint16_t mode_tv_simulator(void) {
ng = (uint8_t)gamma8(tvSimulator->actualColorG) * 257;
nb = (uint8_t)gamma8(tvSimulator->actualColorB) * 257;
- if (SEGENV.aux0 == 0) { // initialize next iteration
+ if (SEGENV.aux0 == 0) { // initialize next iteration
SEGENV.aux0 = 1;
// randomize total duration and fade duration for the actual color
@@ -4319,7 +4303,7 @@ uint16_t mode_tv_simulator(void) {
// fade from prev volor to next color
if (tvSimulator->elapsed < tvSimulator->fadeTime) {
- r = map(tvSimulator->elapsed, 0, tvSimulator->fadeTime, tvSimulator->pr, nr);
+ r = map(tvSimulator->elapsed, 0, tvSimulator->fadeTime, tvSimulator->pr, nr);
g = map(tvSimulator->elapsed, 0, tvSimulator->fadeTime, tvSimulator->pg, ng);
b = map(tvSimulator->elapsed, 0, tvSimulator->fadeTime, tvSimulator->pb, nb);
} else { // Avoid divide-by-zero in map()
@@ -4340,10 +4324,10 @@ uint16_t mode_tv_simulator(void) {
tvSimulator->pb = nb;
SEGENV.aux0 = 0;
}
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_TV_SIMULATOR[] PROGMEM = "TV Simulator";
+static const char _data_FX_MODE_TV_SIMULATOR[] PROGMEM = "TV Simulator@!,!;;";
/*
@@ -4386,7 +4370,7 @@ class AuroraWave {
alive = true;
}
- CRGB getColorForLED(int ledIndex) {
+ CRGB getColorForLED(int ledIndex) {
if(ledIndex < center - width || ledIndex > center + width) return 0; //Position out of range of this wave
CRGB rgb;
@@ -4399,7 +4383,7 @@ class AuroraWave {
//The age of the wave determines it brightness.
//At half its maximum age it will be the brightest.
- float ageFactor = 0.1;
+ float ageFactor = 0.1;
if((float)age / ttl < 0.5) {
ageFactor = (float)age / (ttl / 2);
} else {
@@ -4411,7 +4395,7 @@ class AuroraWave {
rgb.r = basecolor.r * factor;
rgb.g = basecolor.g * factor;
rgb.b = basecolor.b * factor;
-
+
return rgb;
};
@@ -4488,25 +4472,25 @@ uint16_t mode_aurora(void) {
if (SEGCOLOR(1)) backlight++;
if (SEGCOLOR(2)) backlight++;
//Loop through LEDs to determine color
- for (int i = 0; i < SEGLEN; i++) {
+ for (int i = 0; i < SEGLEN; i++) {
CRGB mixedRgb = CRGB(backlight, backlight, backlight);
//For each LED we must check each wave if it is "active" at this position.
//If there are multiple waves active on a LED we multiply their values.
for (int j = 0; j < SEGENV.aux1; j++) {
CRGB rgb = waves[j].getColorForLED(i);
-
- if(rgb != CRGB(0)) {
+
+ if(rgb != CRGB(0)) {
mixedRgb += rgb;
}
}
SEGMENT.setPixelColor(i, mixedRgb[0], mixedRgb[1], mixedRgb[2]);
}
-
+
return FRAMETIME;
}
-static const char _data_FX_MODE_AURORA[] PROGMEM = "Aurora@!,!;1,2,3;!;sx=24,pal=50,1d";
+static const char _data_FX_MODE_AURORA[] PROGMEM = "Aurora@!,!;1,2,3;!;;sx=24,pal=50";
// WLED-SR effects
@@ -4526,7 +4510,7 @@ uint16_t mode_perlinmove(void) {
return FRAMETIME;
} // mode_perlinmove()
-static const char _data_FX_MODE_PERLINMOVE[] PROGMEM = "Perlin Move@!,# of pixels,fade rate;!,!;!;1d";
+static const char _data_FX_MODE_PERLINMOVE[] PROGMEM = "Perlin Move@!,# of pixels,Fade rate;!,!;!";
/////////////////////////
@@ -4544,7 +4528,7 @@ uint16_t mode_wavesins(void) {
return FRAMETIME;
} // mode_waveins()
-static const char _data_FX_MODE_WAVESINS[] PROGMEM = "Wavesins@!,Brightness variation,Starting color,Range of colors,Color variation;!;!;1d";
+static const char _data_FX_MODE_WAVESINS[] PROGMEM = "Wavesins@!,Brightness variation,Starting color,Range of colors,Color variation;!;!";
//////////////////////////////
@@ -4567,7 +4551,7 @@ uint16_t mode_FlowStripe(void) {
return FRAMETIME;
} // mode_FlowStripe()
-static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Effect speed;;;1d";
+static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Effect speed;;";
#ifndef WLED_DISABLE_2D
@@ -4611,7 +4595,7 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma
return FRAMETIME;
} // mode_2DBlackHole()
-static const char _data_FX_MODE_2DBLACKHOLE[] PROGMEM = "Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;;2d";
+static const char _data_FX_MODE_2DBLACKHOLE[] PROGMEM = "Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;;2";
////////////////////////////
@@ -4629,8 +4613,8 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so
SEGENV.aux0 = 0; // start with red hue
}
- bool dot = false;
- bool grad = true;
+ bool dot = SEGMENT.check3;
+ bool grad = SEGMENT.check1;
byte numLines = SEGMENT.intensity/16 + 1;
@@ -4646,24 +4630,26 @@ uint16_t mode_2DColoredBursts() { // By: ldirko https://editor.so
byte xsteps = abs8(x1 - y1) + 1;
byte ysteps = abs8(x2 - y2) + 1;
byte steps = xsteps >= ysteps ? xsteps : ysteps;
-
+ //Draw gradient line
for (size_t i = 1; i <= steps; i++) {
- byte dx = lerp8by8(x1, y1, i * 255 / steps);
- byte dy = lerp8by8(x2, y2, i * 255 / steps);
+ uint8_t rate = i * 255 / steps;
+ byte dx = lerp8by8(x1, y1, rate);
+ byte dy = lerp8by8(x2, y2, rate);
+ //SEGMENT.setPixelColorXY(dx, dy, grad ? color.nscale8_video(255-rate) : color); // use addPixelColorXY for different look
SEGMENT.addPixelColorXY(dx, dy, color); // use setPixelColorXY for different look
- if (grad) SEGMENT.fadePixelColorXY(dx, dy, (i * 255 / steps)); //Draw gradient line
+ if (grad) SEGMENT.fadePixelColorXY(dx, dy, rate);
}
if (dot) { //add white point at the ends of line
- SEGMENT.addPixelColorXY(x1, x2, WHITE);
- SEGMENT.addPixelColorXY(y1, y2, WHITE);
+ SEGMENT.setPixelColorXY(x1, x2, WHITE);
+ SEGMENT.setPixelColorXY(y1, y2, DARKSLATEGRAY);
}
}
- SEGMENT.blur(4);
+ if (SEGMENT.custom3) SEGMENT.blur(SEGMENT.custom3/2);
return FRAMETIME;
} // mode_2DColoredBursts()
-static const char _data_FX_MODE_2DCOLOREDBURSTS[] PROGMEM = "Colored Bursts@Speed,# of lines;;!;2d";
+static const char _data_FX_MODE_2DCOLOREDBURSTS[] PROGMEM = "Colored Bursts@Speed,# of lines,,,Blur,Gradient,,Dots;;!;2;c3=16";
/////////////////////
@@ -4690,7 +4676,7 @@ uint16_t mode_2Ddna(void) { // dna originally by by ldirko at https://pa
return FRAMETIME;
} // mode_2Ddna()
-static const char _data_FX_MODE_2DDNA[] PROGMEM = "DNA@Scroll speed,Blur;1,2,3;!;2d";
+static const char _data_FX_MODE_2DDNA[] PROGMEM = "DNA@Scroll speed,Blur;;!;2";
/////////////////////////
@@ -4705,10 +4691,9 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma
if (SEGENV.call == 0) {
SEGMENT.setUpLeds();
SEGMENT.fill(BLACK);
- SEGENV.aux0 = 0; // hue
}
- uint8_t speeds = SEGMENT.speed/2;
+ uint8_t speeds = SEGMENT.speed/2 + 1;
uint8_t freq = SEGMENT.intensity/8;
uint32_t ms = millis() / 20;
@@ -4717,23 +4702,27 @@ uint16_t mode_2DDNASpiral() { // By: ldirko https://editor.soulma
for (int i = 0; i < rows; i++) {
uint16_t x = beatsin8(speeds, 0, cols - 1, 0, i * freq) + beatsin8(speeds - 7, 0, cols - 1, 0, i * freq + 128);
uint16_t x1 = beatsin8(speeds, 0, cols - 1, 0, 128 + i * freq) + beatsin8(speeds - 7, 0, cols - 1, 0, 128 + 64 + i * freq);
- SEGENV.aux0 = i * 128 / cols + ms; //ewowi20210629: not width - 1 to avoid crash if width = 1
+ uint8_t hue = (i * 128 / rows) + ms;
+ // skip every 4th row every now and then (fade it more)
if ((i + ms / 8) & 3) {
+ // draw a gradient line between x and x1
x = x / 2; x1 = x1 / 2;
- byte steps = abs8(x - x1) + 1;
+ uint8_t steps = abs8(x - x1) + 1;
for (size_t k = 1; k <= steps; k++) {
- byte dx = lerp8by8(x, x1, k * 255 / steps);
- SEGMENT.addPixelColorXY(dx, i, ColorFromPalette(SEGPALETTE, SEGENV.aux0, 255, LINEARBLEND));
- SEGMENT.fadePixelColorXY(dx, i, (k * 255 / steps));
+ uint8_t rate = k * 255 / steps;
+ uint8_t dx = lerp8by8(x, x1, rate);
+ //SEGMENT.setPixelColorXY(dx, i, ColorFromPalette(SEGPALETTE, hue, 255, LINEARBLEND).nscale8_video(rate));
+ SEGMENT.addPixelColorXY(dx, i, ColorFromPalette(SEGPALETTE, hue, 255, LINEARBLEND)); // use setPixelColorXY for different look
+ SEGMENT.fadePixelColorXY(dx, i, rate);
}
- SEGMENT.addPixelColorXY(x, i, DARKSLATEGRAY);
- SEGMENT.addPixelColorXY(x1, i, WHITE);
+ SEGMENT.setPixelColorXY(x, i, DARKSLATEGRAY);
+ SEGMENT.setPixelColorXY(x1, i, WHITE);
}
}
return FRAMETIME;
} // mode_2DDNASpiral()
-static const char _data_FX_MODE_2DDNASPIRAL[] PROGMEM = "DNA Spiral@Scroll speed,Y frequency;;!;2d";
+static const char _data_FX_MODE_2DDNASPIRAL[] PROGMEM = "DNA Spiral@Scroll speed,Y frequency;;!;2";
/////////////////////////
@@ -4764,7 +4753,7 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli
return FRAMETIME;
} // mode_2DDrift()
-static const char _data_FX_MODE_2DDRIFT[] PROGMEM = "Drift@Rotation speed,Blur amount;;!;2d";
+static const char _data_FX_MODE_2DDRIFT[] PROGMEM = "Drift@Rotation speed,Blur amount;;!;2";
//////////////////////////
@@ -4799,7 +4788,7 @@ uint16_t mode_2Dfirenoise(void) { // firenoise2d. By Andrew Tuline
return FRAMETIME;
} // mode_2Dfirenoise()
-static const char _data_FX_MODE_2DFIRENOISE[] PROGMEM = "Firenoise@X scale,Y scale;;;2d";
+static const char _data_FX_MODE_2DFIRENOISE[] PROGMEM = "Firenoise@X scale,Y scale;;!;2;pal=0"; //WLEDMM pal=0
//////////////////////////////
@@ -4826,7 +4815,7 @@ uint16_t mode_2DFrizzles(void) { // By: Stepko https://editor.so
return FRAMETIME;
} // mode_2DFrizzles()
-static const char _data_FX_MODE_2DFRIZZLES[] PROGMEM = "Frizzles@X frequency,Y frequency,Blur;;!;2d";
+static const char _data_FX_MODE_2DFRIZZLES[] PROGMEM = "Frizzles@X frequency,Y frequency,Blur;;!;2";
///////////////////////////////////////////
@@ -4834,7 +4823,7 @@ static const char _data_FX_MODE_2DFRIZZLES[] PROGMEM = "Frizzles@X frequency,Y f
///////////////////////////////////////////
typedef struct ColorCount {
CRGB color;
- int8_t count;
+ int8_t count;
} colorCount;
uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https://natureofcode.com/book/chapter-7-cellular-automata/ and https://github.com/DougHaber/nlife-color
@@ -4843,17 +4832,20 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled
+ const uint16_t crcBufferLen = 2; //(SEGMENT.width() + SEGMENT.height())*71/100; // roughly sqrt(2)/2 for better repetition detection (Ewowi)
- if (!SEGENV.allocateData(dataSize + sizeof(unsigned long))) return mode_static(); //allocation failed
+ if (!SEGENV.allocateData(dataSize + sizeof(uint16_t)*crcBufferLen)) return mode_static(); //allocation failed
CRGB *prevLeds = reinterpret_cast(SEGENV.data);
- unsigned long *resetMillis = reinterpret_cast(SEGENV.data + dataSize); // triggers reset
+ uint16_t *crcBuffer = reinterpret_cast(SEGENV.data + dataSize);
CRGB backgroundColor = SEGCOLOR(1);
- if (SEGENV.call == 0 || strip.now - *resetMillis > 5000) {
- *resetMillis = strip.now;
+ if (SEGENV.call == 0) SEGMENT.setUpLeds();
- random16_set_seed(strip.now); //seed the random generator
+ if (SEGENV.call == 0 || strip.now - SEGMENT.step > 3000) {
+ SEGENV.step = strip.now;
+ SEGENV.aux0 = 0;
+ random16_set_seed(millis()>>2); //seed the random generator
//give the leds random state and colors (based on intensity, colors from palette or all posible colors are chosen)
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
@@ -4861,35 +4853,38 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
if (state == 0)
SEGMENT.setPixelColorXY(x,y, backgroundColor);
else
- SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0));
+ SEGMENT.setPixelColorXY(x,y, !SEGMENT.check1?SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0): random16()*random16()); //WLEDMM support all colors
}
for (int y = 0; y < rows; y++) for (int x = 0; x < cols; x++) prevLeds[XY(x,y)] = CRGB::Black;
-
-
- SEGENV.aux1 = 0;
- SEGENV.aux0 = 0xFFFF;
+ memset(crcBuffer, 0, sizeof(uint16_t)*crcBufferLen);
+ } else if (strip.now - SEGENV.step < FRAMETIME_FIXED * (uint32_t)map(SEGMENT.speed,0,255,64,4)) {
+ // update only when appropriate time passes (in 42 FPS slots)
+ return FRAMETIME;
}
//copy previous leds (save previous generation)
+ //NOTE: using lossy getPixelColor() is a benefit as endlessly repeating patterns will eventually fade out causing a reset
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) prevLeds[XY(x,y)] = SEGMENT.getPixelColorXY(x,y);
//calculate new leds
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
- colorCount colorsCount[9];//count the different colors in the 9*9 matrix
- for (int i=0; i<9; i++) colorsCount[i] = {backgroundColor, 0}; //init colorsCount
- //iterate through neighbors and count them and their different colors
+ colorCount colorsCount[9]; // count the different colors in the 3*3 matrix
+ for (int i=0; i<9; i++) colorsCount[i] = {backgroundColor, 0}; // init colorsCount
+
+ // iterate through neighbors and count them and their different colors
int neighbors = 0;
- for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { //iterate through 9*9 matrix
+ for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { // iterate through 3*3 matrix
+ if (i==0 && j==0) continue; // ignore itself
// wrap around segment
int16_t xx = x+i, yy = y+j;
- if (x+i < 0) xx = cols-1; else if (x+i >= cols) xx = 0;
+ if (x+i < 0) xx = cols-1; else if (x+i >= cols) xx = 0;
if (y+j < 0) yy = rows-1; else if (y+j >= rows) yy = 0;
- uint16_t xy = XY(xx, yy); // previous cell xy to check
- // count different neighbours and colors, except the centre cell
- if (xy != XY(x,y) && prevLeds[xy] != backgroundColor) {
+ uint16_t xy = XY(xx, yy); // previous cell xy to check
+ // count different neighbours and colors
+ if (prevLeds[xy] != backgroundColor) {
neighbors++;
bool colorFound = false;
int k;
@@ -4898,39 +4893,42 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
colorsCount[k].count++;
colorFound = true;
}
-
if (!colorFound) colorsCount[k] = {prevLeds[xy], 1}; //add new color found in the array
}
} // i,j
// Rules of Life
- uint32_t col = SEGMENT.getPixelColorXY(x,y);
+ uint32_t col = prevLeds[XY(x,y)];
uint32_t bgc = RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0);
if ((col != bgc) && (neighbors < 2)) SEGMENT.setPixelColorXY(x,y, bgc); // Loneliness
else if ((col != bgc) && (neighbors > 3)) SEGMENT.setPixelColorXY(x,y, bgc); // Overpopulation
- else if ((col == bgc) && (neighbors == 3)) { // Reproduction
- //find dominantcolor and assign to cell
+ else if ((col == bgc) && (neighbors == 3)) { // Reproduction
+ // find dominant color and assign it to a cell
colorCount dominantColorCount = {backgroundColor, 0};
for (int i=0; i<9 && colorsCount[i].count != 0; i++)
if (colorsCount[i].count > dominantColorCount.count) dominantColorCount = colorsCount[i];
- if (dominantColorCount.count > 0) SEGMENT.setPixelColorXY(x,y, dominantColorCount.color); //assign the dominant color
+ // assign the dominant color w/ a bit of randomness to avoid "gliders"
+ if (dominantColorCount.count > 0 && random8(128)) SEGMENT.setPixelColorXY(x,y, dominantColorCount.color);
+ } else if ((col == bgc) && (neighbors == 2) && !random8(128)) { // Mutation
+ SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 255));
}
// else do nothing!
} //x,y
// calculate CRC16 of leds
- uint16_t crc = crc16((const unsigned char*)prevLeds, dataSize-1); //ewowi: prevLeds instead of leds work as well, tbd: compare more patterns, see SR!
-
+ uint16_t crc = crc16((const unsigned char*)prevLeds, dataSize);
// check if we had same CRC and reset if needed
+ bool repetition = false;
+ for (int i=0; i>1)); // update only when appropriate time passes (in 42 FPS slots)
+ return FRAMETIME;
} // mode_2Dgameoflife()
-static const char _data_FX_MODE_2DGAMEOFLIFE[] PROGMEM = "Game Of Life@!;!,!;!;2d";
+static const char _data_FX_MODE_2DGAMEOFLIFE[] PROGMEM = "Game Of Life@!,,,,,All colors ☾;!,!;!;2;c1=0"; //WLEDMM support all colors
/////////////////////////
@@ -4951,7 +4949,7 @@ uint16_t mode_2DHiphotic() { // By: ldirko https://edit
return FRAMETIME;
} // mode_2DHiphotic()
-static const char _data_FX_MODE_2DHIPHOTIC[] PROGMEM = "Hiphotic@X scale,Y scale,,,Speed;;!;2d";
+static const char _data_FX_MODE_2DHIPHOTIC[] PROGMEM = "Hiphotic@X scale,Y scale,,,Speed;!;!;2";
/////////////////////////
@@ -5068,7 +5066,7 @@ uint16_t mode_2DJulia(void) { // An animated Julia set
return FRAMETIME;
} // mode_2DJulia()
-static const char _data_FX_MODE_2DJULIA[] PROGMEM = "Julia@,Max iterations per pixel,X center,Y center,Area size;;!;ix=24,c1=128,c2=128,c3=16,2d";
+static const char _data_FX_MODE_2DJULIA[] PROGMEM = "Julia@,Max iterations per pixel,X center,Y center,Area size;!;!;2;ix=24,c1=128,c2=128,c3=16";
//////////////////////////////
@@ -5086,17 +5084,18 @@ uint16_t mode_2DLissajous(void) { // By: Andrew Tuline
for (int i=0; i < 256; i ++) {
//float xlocn = float(sin8(now/4+i*(SEGMENT.speed>>5))) / 255.0f;
//float ylocn = float(cos8(now/4+i*2)) / 255.0f;
+ //WLEDMM: stick to the original calculations of xlocn and ylocn
uint8_t xlocn = sin8(strip.now/2+i*(SEGMENT.speed>>6));
uint8_t ylocn = cos8(strip.now/2+i*2);
xlocn = map(xlocn,0,255,0,cols-1);
ylocn = map(ylocn,0,255,0,rows-1);
- SEGMENT.setPixelColorXY(xlocn, ylocn, SEGMENT.color_from_palette(strip.now/100+i, false, PALETTE_SOLID_WRAP, 0));
+ SEGMENT.setPixelColorXY(xlocn, ylocn, SEGMENT.color_from_palette(millis()/100+i, false, PALETTE_SOLID_WRAP, 0));
}
return FRAMETIME;
} // mode_2DLissajous()
-static const char _data_FX_MODE_2DLISSAJOUS[] PROGMEM = "Lissajous@X frequency,Fade rate;!,!,!;!;2d";
+static const char _data_FX_MODE_2DLISSAJOUS[] PROGMEM = "Lissajous ☾@X frequency,Fade rate;!;!;2";
///////////////////////
@@ -5159,7 +5158,7 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
return FRAMETIME;
} // mode_2Dmatrix()
-static const char _data_FX_MODE_2DMATRIX[] PROGMEM = "Matrix@Falling speed,Spawning rate,Trail,,,Custom color;Spawn,Trail;;pal=0,2d";
+static const char _data_FX_MODE_2DMATRIX[] PROGMEM = "Matrix@!,Spawning rate,Trail,,,Custom color;Spawn,Trail;;2";
/////////////////////////
@@ -5174,15 +5173,15 @@ uint16_t mode_2Dmetaballs(void) { // Metaballs by Stefan Petrick. Cannot have
float speed = 0.25f * (1+(SEGMENT.speed>>6));
// get some 2 random moving points
- uint8_t x2 = inoise8(strip.now * speed, 25355, 685 ) / 16;
- uint8_t y2 = inoise8(strip.now * speed, 355, 11685 ) / 16;
+ uint8_t x2 = map(inoise8(strip.now * speed, 25355, 685), 0, 255, 0, cols-1);
+ uint8_t y2 = map(inoise8(strip.now * speed, 355, 11685), 0, 255, 0, rows-1);
- uint8_t x3 = inoise8(strip.now * speed, 55355, 6685 ) / 16;
- uint8_t y3 = inoise8(strip.now * speed, 25355, 22685 ) / 16;
+ uint8_t x3 = map(inoise8(strip.now * speed, 55355, 6685), 0, 255, 0, cols-1);
+ uint8_t y3 = map(inoise8(strip.now * speed, 25355, 22685), 0, 255, 0, rows-1);
// and one Lissajou function
- uint8_t x1 = beatsin8(23 * speed, 0, 15);
- uint8_t y1 = beatsin8(28 * speed, 0, 15);
+ uint8_t x1 = beatsin8(23 * speed, 0, cols-1);
+ uint8_t y1 = beatsin8(28 * speed, 0, rows-1);
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
@@ -5201,7 +5200,7 @@ uint16_t mode_2Dmetaballs(void) { // Metaballs by Stefan Petrick. Cannot have
dist += sqrt16((dx * dx) + (dy * dy));
// inverse result
- byte color = 1000 / dist;
+ byte color = dist ? 1000 / dist : 255;
// map color between thresholds
if (color > 0 and color < 60) {
@@ -5218,7 +5217,7 @@ uint16_t mode_2Dmetaballs(void) { // Metaballs by Stefan Petrick. Cannot have
return FRAMETIME;
} // mode_2Dmetaballs()
-static const char _data_FX_MODE_2DMETABALLS[] PROGMEM = "Metaballs@Speed;!,!,!;!;2d";
+static const char _data_FX_MODE_2DMETABALLS[] PROGMEM = "Metaballs@!;;!;2";
//////////////////////
@@ -5241,7 +5240,7 @@ uint16_t mode_2Dnoise(void) { // By Andrew Tuline
return FRAMETIME;
} // mode_2Dnoise()
-static const char _data_FX_MODE_2DNOISE[] PROGMEM = "Noise2D@Speed,Scale;!,!,!;!;2d";
+static const char _data_FX_MODE_2DNOISE[] PROGMEM = "Noise2D@!,Scale;;!;2";
//////////////////////////////
@@ -5284,7 +5283,7 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito
return FRAMETIME;
} // mode_2DPlasmaball()
-static const char _data_FX_MODE_2DPLASMABALL[] PROGMEM = "Plasma Ball@Speed,,Fade,Blur;!,!,!;!;2d";
+static const char _data_FX_MODE_2DPLASMABALL[] PROGMEM = "Plasma Ball@Speed,,Fade,Blur;;!;2";
////////////////////////////////
@@ -5307,7 +5306,7 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
SEGENV.step = 0;
}
- float adjustHeight = (float)map(rows, 8, 32, 28, 12);
+ float adjustHeight = (float)map(rows, 8, 32, 28, 12); // maybe use mapf() ???
uint16_t adjScale = map(cols, 8, 64, 310, 63);
/*
if (SEGENV.aux1 != SEGMENT.custom1/12) { // Hacky palette rotation. We need that black.
@@ -5333,13 +5332,13 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
SEGMENT.setPixelColorXY(x, y, ColorFromPalette(auroraPalette,
qsub8(
inoise8((SEGENV.step%2) + x * _scale, y * 16 + SEGENV.step % 16, SEGENV.step / _speed),
- fabsf((float)rows / 2 - (float)y) * adjustHeight)));
+ fabsf((float)rows / 2.0f - (float)y) * adjustHeight)));
}
}
return FRAMETIME;
} // mode_2DPolarLights()
-static const char _data_FX_MODE_2DPOLARLIGHTS[] PROGMEM = "Polar Lights@Speed,Scale;;;2d";
+static const char _data_FX_MODE_2DPOLARLIGHTS[] PROGMEM = "Polar Lights@!,Scale;;;2";
/////////////////////////
@@ -5348,7 +5347,7 @@ static const char _data_FX_MODE_2DPOLARLIGHTS[] PROGMEM = "Polar Lights@Speed,Sc
uint16_t mode_2DPulser(void) { // By: ldirko https://editor.soulmatelights.com/gallery/878-pulse-test , modifed by: Andrew Tuline
if (!strip.isMatrix) return mode_static(); // not a 2D set-up
- const uint16_t cols = SEGMENT.virtualWidth(); // WLEDMM bugfix
+ const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
if (SEGENV.call == 0) {
@@ -5359,7 +5358,7 @@ uint16_t mode_2DPulser(void) { // By: ldirko https://edi
SEGMENT.fadeToBlackBy(8 - (SEGMENT.intensity>>5));
uint32_t a = strip.now / (18 - SEGMENT.speed / 16);
- uint16_t x = (a / 14) % cols; // WLEDMM bugfix
+ uint16_t x = (a / 14) % cols;
uint16_t y = map((sin8(a * 5) + sin8(a * 4) + sin8(a * 2)), 0, 765, rows-1, 0);
SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, map(y, 0, rows-1, 0, 255), 255, LINEARBLEND));
@@ -5367,7 +5366,7 @@ uint16_t mode_2DPulser(void) { // By: ldirko https://edi
return FRAMETIME;
} // mode_2DPulser()
-static const char _data_FX_MODE_2DPULSER[] PROGMEM = "Pulser@Speed,Blur;;!;2d";
+static const char _data_FX_MODE_2DPULSER[] PROGMEM = "Pulser@!,Blur;;!;2";
/////////////////////////
@@ -5389,15 +5388,15 @@ uint16_t mode_2DSindots(void) { // By: ldirko http
byte t1 = millis() / (257 - SEGMENT.speed); // 20;
byte t2 = sin8(t1) / 4 * 2;
for (int i = 0; i < 13; i++) {
- byte x = sin8(t1 + i * SEGMENT.intensity/8)*(cols-1)/255; // max index now 255x15/255=15!
- byte y = sin8(t2 + i * SEGMENT.intensity/8)*(rows-1)/255; // max index now 255x15/255=15!
+ byte x = sin8(t1 + i * SEGMENT.intensity/8)*(cols-1)/255; // max index now 255x15/255=15!
+ byte y = sin8(t2 + i * SEGMENT.intensity/8)*(rows-1)/255; // max index now 255x15/255=15!
SEGMENT.setPixelColorXY(x, y, ColorFromPalette(SEGPALETTE, i * 255 / 13, 255, LINEARBLEND));
}
SEGMENT.blur(SEGMENT.custom2>>3);
return FRAMETIME;
} // mode_2DSindots()
-static const char _data_FX_MODE_2DSINDOTS[] PROGMEM = "Sindots@Speed,Dot distance,Fade rate,Blur;;!;2d";
+static const char _data_FX_MODE_2DSINDOTS[] PROGMEM = "Sindots@!,Dot distance,Fade rate,Blur;;!;2";
//////////////////////////////
@@ -5439,7 +5438,7 @@ uint16_t mode_2Dsquaredswirl(void) { // By: Mark Kriegsman. https://g
return FRAMETIME;
} // mode_2Dsquaredswirl()
-static const char _data_FX_MODE_2DSQUAREDSWIRL[] PROGMEM = "Squared Swirl@,,,,Blur;;!;2d";
+static const char _data_FX_MODE_2DSQUAREDSWIRL[] PROGMEM = "Squared Swirl@,,,,Blur;;!;2";
//////////////////////////////
@@ -5490,7 +5489,7 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi
return FRAMETIME;
} // mode_2DSunradiation()
-static const char _data_FX_MODE_2DSUNRADIATION[] PROGMEM = "Sun Radiation@Variance,Brightness;;;2d";
+static const char _data_FX_MODE_2DSUNRADIATION[] PROGMEM = "Sun Radiation@Variance,Brightness;;;2";
/////////////////////////
@@ -5522,7 +5521,7 @@ uint16_t mode_2Dtartan(void) { // By: Elliott Kember https://editor.so
return FRAMETIME;
} // mode_2DTartan()
-static const char _data_FX_MODE_2DTARTAN[] PROGMEM = "Tartan@X scale,Y scale;;!;2d";
+static const char _data_FX_MODE_2DTARTAN[] PROGMEM = "Tartan@X scale,Y scale;;!;2";
/////////////////////////
@@ -5568,7 +5567,7 @@ uint16_t mode_2Dspaceships(void) { //// Space ships by stepko (c)05.02.21 [ht
return FRAMETIME;
}
-static const char _data_FX_MODE_2DSPACESHIPS[] PROGMEM = "Spaceships@!,Blur;!,!,!;!;2d";
+static const char _data_FX_MODE_2DSPACESHIPS[] PROGMEM = "Spaceships@!,Blur;;!;2";
/////////////////////////
@@ -5617,7 +5616,7 @@ uint16_t mode_2Dcrazybees(void) {
SEGENV.step = millis() + (FRAMETIME * 8 / ((SEGMENT.speed>>5)+1));
SEGMENT.fadeToBlackBy(32);
-
+
for (size_t i = 0; i < n; i++) {
SEGMENT.addPixelColorXY(bee[i].aimX + 1, bee[i].aimY, CHSV(bee[i].hue, 255, 255));
SEGMENT.addPixelColorXY(bee[i].aimX, bee[i].aimY + 1, CHSV(bee[i].hue, 255, 255));
@@ -5642,7 +5641,7 @@ uint16_t mode_2Dcrazybees(void) {
}
return FRAMETIME;
}
-static const char _data_FX_MODE_2DCRAZYBEES[] PROGMEM = "Crazy Bees@!,Blur;;;2d";
+static const char _data_FX_MODE_2DCRAZYBEES[] PROGMEM = "Crazy Bees@!,Blur;;;2";
/////////////////////////
@@ -5732,7 +5731,7 @@ uint16_t mode_2Dghostrider(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_2DGHOSTRIDER[] PROGMEM = "Ghost Rider@Fade rate,Blur;!,!,!;!;2d";
+static const char _data_FX_MODE_2DGHOSTRIDER[] PROGMEM = "Ghost Rider@Fade rate,Blur;;!;2";
////////////////////////////
@@ -5793,7 +5792,7 @@ uint16_t mode_2Dfloatingblobs(void) {
// reduce radius until it is < 1
blob->r[i] -= (fabsf(blob->sX[i]) > fabsf(blob->sY[i]) ? fabsf(blob->sX[i]) : fabsf(blob->sY[i])) * 0.05f;
if (blob->r[i] < 1.f) {
- blob->grow[i] = true;
+ blob->grow[i] = true;
}
}
uint32_t c = SEGMENT.color_from_palette(blob->color[i], false, false, 0);
@@ -5833,7 +5832,7 @@ uint16_t mode_2Dfloatingblobs(void) {
return FRAMETIME;
}
#undef MAX_BLOBS
-static const char _data_FX_MODE_2DBLOBS[] PROGMEM = "Blobs@!,# blobs,Blur;!,!;!;c1=8,2d";
+static const char _data_FX_MODE_2DBLOBS[] PROGMEM = "Blobs@!,# blobs,Blur;!;!;2;c1=8";
////////////////////////////
@@ -5859,7 +5858,7 @@ uint16_t mode_2Dscrollingtext(void) {
char text[33] = {'\0'};
if (SEGMENT.name) for (size_t i=0,j=0; i31 && SEGMENT.name[i]<128) text[j++] = SEGMENT.name[i];
- if (!strlen(text) || !strncmp_P(text,PSTR("#DATE"),5) || !strncmp_P(text,PSTR("#TIME"),5)) { // fallback if empty segment name: display date and time
+ if (!strlen(text) || !strncmp_P(text,PSTR("#DATE"),5) || !strncmp_P(text,PSTR("#DDMM"),5) || !strncmp_P(text,PSTR("#MMDD"),5) || !strncmp_P(text,PSTR("#TIME"),5) || !strncmp_P(text,PSTR("#HHMM"),5)) { // fallback if empty segment name: display date and time
char sec[5];
byte AmPmHour = hour(localTime);
boolean isitAM = true;
@@ -5870,7 +5869,10 @@ uint16_t mode_2Dscrollingtext(void) {
if (useAMPM) sprintf_P(sec, PSTR(" %2s"), (isitAM ? "AM" : "PM"));
else sprintf_P(sec, PSTR(":%02d"), second(localTime));
if (!strncmp_P(text,PSTR("#DATE"),5)) sprintf_P(text, PSTR("%d.%d.%d"), day(localTime), month(localTime), year(localTime));
+ else if (!strncmp_P(text,PSTR("#DDMM"),5)) sprintf_P(text, PSTR("%d.%d"), day(localTime), month(localTime));
+ else if (!strncmp_P(text,PSTR("#MMDD"),5)) sprintf_P(text, PSTR("%d/%d"), month(localTime), day(localTime));
else if (!strncmp_P(text,PSTR("#TIME"),5)) sprintf_P(text, PSTR("%2d:%02d%s"), AmPmHour, minute(localTime), sec);
+ else if (!strncmp_P(text,PSTR("#HHMM"),5)) sprintf_P(text, PSTR("%2d:%02d"), AmPmHour, minute(localTime));
else sprintf_P(text, PSTR("%s %d, %d %2d:%02d%s"), monthShortStr(month(localTime)), day(localTime), year(localTime), AmPmHour, minute(localTime), sec);
}
const int numberOfLetters = strlen(text);
@@ -5880,20 +5882,25 @@ uint16_t mode_2Dscrollingtext(void) {
else SEGENV.aux0 = (cols + (numberOfLetters * letterWidth))/2;
++SEGENV.aux1 &= 0xFF; // color shift
SEGENV.step = millis() + map(SEGMENT.speed, 0, 255, 10*FRAMETIME_FIXED, 2*FRAMETIME_FIXED);
-
- // we need it 3 times
- SEGMENT.fade_out(255 - (SEGMENT.custom1>>5)); // fade to background color
- SEGMENT.fade_out(255 - (SEGMENT.custom1>>5)); // fade to background color
- SEGMENT.fade_out(255 - (SEGMENT.custom1>>5)); // fade to background color
- for (int i = 0; i < numberOfLetters; i++) {
- if (int(cols) - int(SEGENV.aux0) + letterWidth*(i+1) < 0) continue; // don't draw characters off-screen
- SEGMENT.drawCharacter(text[i], int(cols) - int(SEGENV.aux0) + letterWidth*i, yoffset, letterWidth, letterHeight, SEGMENT.color_from_palette(SEGENV.aux1, false, PALETTE_SOLID_WRAP, 0));
+ if (!SEGMENT.check2) {
+ for (int y = 0; y < rows; y++) for (int x = 0; x < cols; x++ )
+ SEGMENT.blendPixelColorXY(x, y, SEGCOLOR(1), 255 - (SEGMENT.custom1>>1));
}
}
+ for (int i = 0; i < numberOfLetters; i++) {
+ if (int(cols) - int(SEGENV.aux0) + letterWidth*(i+1) < 0) continue; // don't draw characters off-screen
+ uint32_t col1 = SEGMENT.color_from_palette(SEGENV.aux1, false, PALETTE_SOLID_WRAP, 0);
+ uint32_t col2 = BLACK;
+ if (SEGMENT.check1 && SEGMENT.palette == 0) {
+ col1 = SEGCOLOR(0);
+ col2 = SEGCOLOR(2);
+ }
+ SEGMENT.drawCharacter(text[i], int(cols) - int(SEGENV.aux0) + letterWidth*i, yoffset, letterWidth, letterHeight, col1, col2);
+ }
return FRAMETIME;
}
-static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size;!,!;!;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0,2d";
+static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size,,Gradient,Overlay;!,!,Gradient;!;2;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0";
////////////////////////////
@@ -5925,7 +5932,7 @@ uint16_t mode_2Ddriftrose(void) {
return FRAMETIME;
}
-static const char _data_FX_MODE_2DDRIFTROSE[] PROGMEM = "Drift Rose@Fade,Blur;;;2d";
+static const char _data_FX_MODE_2DDRIFTROSE[] PROGMEM = "Drift Rose@Fade,Blur;;;2";
#endif // WLED_DISABLE_2D
@@ -6051,7 +6058,7 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli
return FRAMETIME;
} // mode_ripplepeak()
-static const char _data_FX_MODE_RIPPLEPEAK[] PROGMEM = "Ripple Peak@Fade rate,Max # of ripples,Select bin,Volume (min);!,!;!;c2=0,m12=0,si=0,1d,vo"; // Pixel, Beatsin
+static const char _data_FX_MODE_RIPPLEPEAK[] PROGMEM = "Ripple Peak@Fade rate,Max # of ripples,Select bin,Volume (min);!,!;!;1v;c2=0,m12=0,si=0"; // Pixel, Beatsin
#ifndef WLED_DISABLE_2D
@@ -6099,7 +6106,7 @@ uint16_t mode_2DSwirl(void) {
return FRAMETIME;
} // mode_2DSwirl()
-static const char _data_FX_MODE_2DSWIRL[] PROGMEM = "Swirl@!,Sensitivity,Blur;,Bg Swirl;!;ix=64si=0,2d,vo"; // Beatsin
+static const char _data_FX_MODE_2DSWIRL[] PROGMEM = "Swirl@!,Sensitivity,Blur;,Bg Swirl;!;2v;ix=64,si=0"; // Beatsin // TODO: color 1 unused?
/////////////////////////
@@ -6128,7 +6135,7 @@ uint16_t mode_2DWaverly(void) {
long t = millis() / 2;
for (int i = 0; i < cols; i++) {
- uint16_t thisVal = volumeSmth*SEGMENT.intensity/64 * inoise8(i * 45 , t , t)/64;
+ uint16_t thisVal = volumeSmth*SEGMENT.intensity/64 * inoise8(i * 45 , t , t)/64; // WLEDMM back to SR code
uint16_t thisMax = map(thisVal, 0, 512, 0, rows);
for (int j = 0; j < thisMax; j++) {
@@ -6140,7 +6147,7 @@ uint16_t mode_2DWaverly(void) {
return FRAMETIME;
} // mode_2DWaverly()
-static const char _data_FX_MODE_2DWAVERLY[] PROGMEM = "Waverly@Amplification,Sensitivity;;!;ix=64,si=0,2d,vo"; // Beatsin
+static const char _data_FX_MODE_2DWAVERLY[] PROGMEM = "Waverly ☾@Amplification,Sensitivity;;!;2v;ix=64,si=0"; // Beatsin
#endif // WLED_DISABLE_2D
@@ -6177,7 +6184,7 @@ uint16_t mode_gravcenter(void) { // Gravcenter. By Andrew Tuline.
float segmentSampleAvg = volumeSmth * (float)SEGMENT.intensity / 255.0f;
segmentSampleAvg *= 0.125; // divide by 8, to compensate for later "sensitivty" upscaling
- float mySampleAvg = mapf(segmentSampleAvg*2.0, 0, 32, 0, (float)SEGLEN/2.0); // map to pixels available in current segment
+ float mySampleAvg = mapf(segmentSampleAvg*2.0, 0, 32, 0, (float)SEGLEN/2.0); // map to pixels available in current segment
uint16_t tempsamp = constrain(mySampleAvg, 0, SEGLEN/2); // Keep the sample from overflowing.
uint8_t gravity = 8 - SEGMENT.speed/32;
@@ -6200,7 +6207,7 @@ uint16_t mode_gravcenter(void) { // Gravcenter. By Andrew Tuline.
return FRAMETIME;
} // mode_gravcenter()
-static const char _data_FX_MODE_GRAVCENTER[] PROGMEM = "Gravcenter@Rate of fall,Sensitivity;,!;!;ix=128,m12=2,si=0,1d,vo"; // Circle, Beatsin
+static const char _data_FX_MODE_GRAVCENTER[] PROGMEM = "Gravcenter@Rate of fall,Sensitivity;!,!;!;1v;ix=128,m12=2,si=0"; // Arc, Beatsin
///////////////////////
@@ -6228,7 +6235,7 @@ uint16_t mode_gravcentric(void) { // Gravcentric. By Andrew
float segmentSampleAvg = volumeSmth * (float)SEGMENT.intensity / 255.0;
segmentSampleAvg *= 0.125f; // divide by 8, to compensate for later "sensitivty" upscaling
- float mySampleAvg = mapf(segmentSampleAvg*2.0, 0.0f, 32.0f, 0.0f, (float)SEGLEN/2.0); // map to pixels availeable in current segment
+ float mySampleAvg = mapf(segmentSampleAvg*2.0, 0.0f, 32.0f, 0.0f, (float)SEGLEN/2.0); // map to pixels availeable in current segment
int tempsamp = constrain(mySampleAvg, 0, SEGLEN/2); // Keep the sample from overflowing.
uint8_t gravity = 8 - SEGMENT.speed/32;
@@ -6251,7 +6258,7 @@ uint16_t mode_gravcentric(void) { // Gravcentric. By Andrew
return FRAMETIME;
} // mode_gravcentric()
-static const char _data_FX_MODE_GRAVCENTRIC[] PROGMEM = "Gravcentric@Rate of fall,Sensitivity;!;!;ix=128,m12=3,si=0,1d,vo"; // Corner, Beatsin
+static const char _data_FX_MODE_GRAVCENTRIC[] PROGMEM = "Gravcentric@Rate of fall,Sensitivity;!,!;!;1v;ix=128,m12=3,si=0"; // Corner, Beatsin
///////////////////////
@@ -6269,6 +6276,9 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline.
um_data = simulateSound(SEGMENT.soundSim);
}
float volumeSmth = *(float*) um_data->u_data[0];
+ #ifdef SR_DEBUG
+ uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
+ #endif
//SEGMENT.fade_out(240);
SEGMENT.fade_out(249); // 25%
@@ -6276,7 +6286,7 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline.
float segmentSampleAvg = volumeSmth * (float)SEGMENT.intensity / 255.0;
segmentSampleAvg *= 0.25; // divide by 4, to compensate for later "sensitivty" upscaling
- float mySampleAvg = mapf(segmentSampleAvg*2.0, 0, 64, 0, (SEGLEN-1)); // map to pixels availeable in current segment
+ float mySampleAvg = mapf(segmentSampleAvg*2.0, 0, 64, 0, (SEGLEN-1)); // map to pixels availeable in current segment
int tempsamp = constrain(mySampleAvg,0,SEGLEN-1); // Keep the sample from overflowing.
uint8_t gravity = 8 - SEGMENT.speed/32;
@@ -6295,9 +6305,16 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline.
}
gravcen->gravityCounter = (gravcen->gravityCounter + 1) % gravity;
+#ifdef SR_DEBUG
+ // WLEDMM: abuse last 2 pixels for debugging peak detection
+ SEGMENT.setPixelColor(SEGLEN-2, (samplePeak > 0) ? GREEN : BLACK);
+ if (samplePeak > 0) SEGMENT.setPixelColor(SEGLEN-1, GREEN);
+ // WLEDMM end
+#endif
+
return FRAMETIME;
} // mode_gravimeter()
-static const char _data_FX_MODE_GRAVIMETER[] PROGMEM = "Gravimeter@Rate of fall,Sensitivity;!,!;!;ix=128,m12=2,si=0,1d,vo"; // Circle, Beatsin
+static const char _data_FX_MODE_GRAVIMETER[] PROGMEM = "Gravimeter@Rate of fall,Sensitivity;!,!;!;1v;ix=128,m12=2,si=0"; // Arc, Beatsin
//////////////////////
@@ -6320,7 +6337,7 @@ uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline.
return FRAMETIME;
} // mode_juggles()
-static const char _data_FX_MODE_JUGGLES[] PROGMEM = "Juggles@!,# of balls;,!;!;m12=0,si=0,1d,vo"; // Pixels, Beatsin
+static const char _data_FX_MODE_JUGGLES[] PROGMEM = "Juggles@!,# of balls;!,!;!;1v;m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6352,7 +6369,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline.
return FRAMETIME;
} // mode_matripix()
-static const char _data_FX_MODE_MATRIPIX[] PROGMEM = "Matripix@!,Brightness;!,!;!;ix=64,m12=2,si=1,1d,vo"; //,rev=1,mi=1,rY=1,mY=1 Circle, WeWillRockYou, reverseX
+static const char _data_FX_MODE_MATRIPIX[] PROGMEM = "Matripix@!,Brightness;!,!;!;1v;ix=64,m12=2,si=1"; //,rev=1,mi=1,rY=1,mY=1 Arc, WeWillRockYou, reverseX
//////////////////////
@@ -6387,7 +6404,7 @@ uint16_t mode_midnoise(void) { // Midnoise. By Andrew Tuline.
return FRAMETIME;
} // mode_midnoise()
-static const char _data_FX_MODE_MIDNOISE[] PROGMEM = "Midnoise@Fade rate,Maximum length;,!;!;ix=128,m12=1,si=0,1d,vo"; // Bar, Beatsin
+static const char _data_FX_MODE_MIDNOISE[] PROGMEM = "Midnoise@Fade rate,Max. length;!,!;!;1v;ix=128,m12=1,si=0"; // Bar, Beatsin
//////////////////////
@@ -6420,7 +6437,7 @@ uint16_t mode_noisefire(void) { // Noisefire. By Andrew Tuline.
return FRAMETIME;
} // mode_noisefire()
-static const char _data_FX_MODE_NOISEFIRE[] PROGMEM = "Noisefire@!,!;;;m12=2,si=0,1d,vo"; // Circle, Beatsin
+static const char _data_FX_MODE_NOISEFIRE[] PROGMEM = "Noisefire@!,!;;;1v;m12=2,si=0"; // Arc, Beatsin
///////////////////////
@@ -6455,7 +6472,7 @@ uint16_t mode_noisemeter(void) { // Noisemeter. By Andrew Tuline.
return FRAMETIME;
} // mode_noisemeter()
-static const char _data_FX_MODE_NOISEMETER[] PROGMEM = "Noisemeter@Fade rate,Width;!,!;!;ix=128,m12=2,si=0,1d,vo"; // Circle, Beatsin
+static const char _data_FX_MODE_NOISEMETER[] PROGMEM = "Noisemeter@Fade rate,Width;!,!;!;1v;ix=128,m12=2,si=0"; // Arc, Beatsin
//////////////////////
@@ -6489,7 +6506,7 @@ uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline.
return FRAMETIME;
} // mode_pixelwave()
-static const char _data_FX_MODE_PIXELWAVE[] PROGMEM = "Pixelwave@!,Sensitivity;!,!;!;ix=64,m12=2,si=0,1d,vo"; // Circle, Beatsin
+static const char _data_FX_MODE_PIXELWAVE[] PROGMEM = "Pixelwave@!,Sensitivity;!,!;!;1v;ix=64,m12=2,si=0"; // Arc, Beatsin
//////////////////////
@@ -6521,7 +6538,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline.
// updated, similar to "plasma" effect - softhack007
uint8_t thisbright = cubicwave8(((i*(1 + (3*SEGMENT.speed/32)))+plasmoip->thisphase) & 0xFF)/2;
thisbright += cos8(((i*(97 +(5*SEGMENT.speed/32)))+plasmoip->thatphase) & 0xFF)/2; // Let's munge the brightness a bit and animate it all with the phases.
-
+
uint8_t colorIndex=thisbright;
if (volumeSmth * SEGMENT.intensity / 64 < thisbright) {thisbright = 0;}
@@ -6530,7 +6547,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline.
return FRAMETIME;
} // mode_plasmoid()
-static const char _data_FX_MODE_PLASMOID[] PROGMEM = "Plasmoid@Phase,# of pixels;!,!;!;sx=128,ix=128,m12=0,si=0,1d,vo"; // Pixels, Beatsin
+static const char _data_FX_MODE_PLASMOID[] PROGMEM = "Plasmoid@Phase,# of pixels;!,!;!;1v;sx=128,ix=128,m12=0,si=0"; // Pixels, Beatsin
///////////////////////
@@ -6574,7 +6591,7 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline.
return FRAMETIME;
} // mode_puddlepeak()
-static const char _data_FX_MODE_PUDDLEPEAK[] PROGMEM = "Puddlepeak@Fade rate,Puddle size,Select bin,Volume (min);!,!;!;c2=0,m12=0,si=0,1d,vo"; // Pixels, Beatsin
+static const char _data_FX_MODE_PUDDLEPEAK[] PROGMEM = "Puddlepeak@Fade rate,Puddle size,Select bin,Volume (min);!,!;!;1v;c2=0,m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6605,7 +6622,7 @@ uint16_t mode_puddles(void) { // Puddles. By Andrew Tuline.
return FRAMETIME;
} // mode_puddles()
-static const char _data_FX_MODE_PUDDLES[] PROGMEM = "Puddles@Fade rate,Puddle size;!,!;!;m12=0,si=0,1d,vo"; // Pixels, Beatsin
+static const char _data_FX_MODE_PUDDLES[] PROGMEM = "Puddles@Fade rate,Puddle size;!,!;!;1v;m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6633,7 +6650,7 @@ uint16_t mode_pixels(void) { // Pixels. By Andrew Tuline.
return FRAMETIME;
} // mode_pixels()
-static const char _data_FX_MODE_PIXELS[] PROGMEM = "Pixels@Fade rate,# of pixels;,!;!;m12=0,si=0,1d,vo"; // Pixels, Beatsin
+static const char _data_FX_MODE_PIXELS[] PROGMEM = "Pixels@Fade rate,# of pixels;!,!;!;1v;m12=0,si=0"; // Pixels, Beatsin
///////////////////////////////
@@ -6659,7 +6676,7 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline.
SEGENV.aux0 = 0;
}
- int fadeoutDelay = (256 - SEGMENT.speed) / 32;
+ int fadeoutDelay = (256 - SEGMENT.speed) / 32;
if ((fadeoutDelay <= 1 ) || ((SEGENV.call % fadeoutDelay) == 0)) SEGMENT.fade_out(SEGMENT.speed);
SEGENV.step += FRAMETIME;
@@ -6674,7 +6691,7 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline.
return FRAMETIME;
} // mode_blurz()
-static const char _data_FX_MODE_BLURZ[] PROGMEM = "Blurz@Fade rate,Blur amount;!,Color mix;!;m12=0,si=0,1d,fr"; // Pixels, Beatsin
+static const char _data_FX_MODE_BLURZ[] PROGMEM = "Blurz@Fade rate,Blur;!,Color mix;!;1f;m12=0,si=0"; // Pixels, Beatsin
/////////////////////////
@@ -6699,17 +6716,16 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil
if (SEGENV.aux0 != secondHand) { // Triggered millis timing.
SEGENV.aux0 = secondHand;
- SEGMENT.setPixelColor(mid, CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2)); // 16-> 15 as 16 is out of bounds
- CRGB color = SEGMENT.getPixelColor(mid);
- SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10))); // TODO - Update
+ CRGB color = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // 16-> 15 as 16 is out of bounds
+ SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[4], 0, 255, 255, 4))); // TODO - Update
- for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left
+ for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); // move to the left
for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right
}
return FRAMETIME;
} // mode_DJLight()
-static const char _data_FX_MODE_DJLIGHT[] PROGMEM = "DJ Light@Speed;;;m12=2,si=0,1d,fr"; // Circle, Beatsin
+static const char _data_FX_MODE_DJLIGHT[] PROGMEM = "DJ Light@Speed;;;1f;m12=2,si=0"; // Arc, Beatsin
////////////////////
@@ -6724,12 +6740,12 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN.
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
- float FFT_MajorPeak = *(float*) um_data->u_data[4];
- float my_magnitude = *(float*) um_data->u_data[5] / 4.0f;
+ float FFT_MajorPeak = *(float*)um_data->u_data[4];
+ float my_magnitude = *(float*)um_data->u_data[5] / 4.0f;
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
if (SEGENV.call == 0) SEGMENT.fill(BLACK);
- int fadeoutDelay = (256 - SEGMENT.speed) / 32;
+ int fadeoutDelay = (256 - SEGMENT.speed) / 32;
if ((fadeoutDelay <= 1 ) || ((SEGENV.call % fadeoutDelay) == 0)) SEGMENT.fade_out(SEGMENT.speed);
int locn = (log10f((float)FFT_MajorPeak) - 1.78f) * (float)SEGLEN/(MAX_FREQ_LOG10 - 1.78f); // log10 frequency range is from 1.78 to 3.71. Let's scale to SEGLEN.
@@ -6745,7 +6761,7 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN.
return FRAMETIME;
} // mode_freqmap()
-static const char _data_FX_MODE_FREQMAP[] PROGMEM = "Freqmap@Fade rate,Starting color;,!;!;m12=0,si=0,1d,fr"; // Pixels, Beatsin
+static const char _data_FX_MODE_FREQMAP[] PROGMEM = "Freqmap@Fade rate,Starting color;!,!;!;1f;m12=0,si=0"; // Pixels, Beatsin
///////////////////////
@@ -6758,7 +6774,7 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch
um_data = simulateSound(SEGMENT.soundSim);
}
float FFT_MajorPeak = *(float*)um_data->u_data[4];
- float volumeSmth = *(float*) um_data->u_data[0];
+ float volumeSmth = *(float*)um_data->u_data[0];
if (SEGENV.call == 0) {
SEGMENT.setUpLeds();
@@ -6795,12 +6811,12 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch
// shift the pixels one pixel up
SEGMENT.setPixelColor(0, color);
- for (int i = SEGLEN - 1; i > 0; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left
+ for (int i = SEGLEN - 1; i > 0; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left
}
return FRAMETIME;
} // mode_freqmatrix()
-static const char _data_FX_MODE_FREQMATRIX[] PROGMEM = "Freqmatrix@Time delay,Sound effect,Low bin,High bin,Sensivity;;;m12=3,si=0,1d,fr"; // Corner, Beatsin
+static const char _data_FX_MODE_FREQMATRIX[] PROGMEM = "Freqmatrix@Time delay,Sound effect,Low bin,High bin,Sensivity;;;1f;m12=3,si=0"; // Corner, Beatsin
//////////////////////
@@ -6816,14 +6832,14 @@ uint16_t mode_freqpixels(void) { // Freqpixel. By Andrew Tuline.
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
- float FFT_MajorPeak = *(float*) um_data->u_data[4];
- float my_magnitude = *(float*) um_data->u_data[5] / 16.0f;
+ float FFT_MajorPeak = *(float*)um_data->u_data[4];
+ float my_magnitude = *(float*)um_data->u_data[5] / 16.0f;
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
uint16_t fadeRate = 2*SEGMENT.speed - SEGMENT.speed*SEGMENT.speed/255; // Get to 255 as quick as you can.
if (SEGENV.call == 0) SEGMENT.fill(BLACK);
- int fadeoutDelay = (256 - SEGMENT.speed) / 64;
+ int fadeoutDelay = (256 - SEGMENT.speed) / 64;
if ((fadeoutDelay <= 1 ) || ((SEGENV.call % fadeoutDelay) == 0)) SEGMENT.fade_out(fadeRate);
for (int i=0; i < SEGMENT.intensity/32+1; i++) {
@@ -6835,7 +6851,7 @@ uint16_t mode_freqpixels(void) { // Freqpixel. By Andrew Tuline.
return FRAMETIME;
} // mode_freqpixels()
-static const char _data_FX_MODE_FREQPIXELS[] PROGMEM = "Freqpixels@Fade rate,Starting colour and # of pixels;;;m12=0,si=0,1d,fr"; // Pixels, Beatsin
+static const char _data_FX_MODE_FREQPIXELS[] PROGMEM = "Freqpixels@Fade rate,Starting color and # of pixels;;;1f;m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6859,8 +6875,8 @@ uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschun
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
- float FFT_MajorPeak = *(float*) um_data->u_data[4];
- float volumeSmth = *(float*) um_data->u_data[0];
+ float FFT_MajorPeak = *(float*)um_data->u_data[4];
+ float volumeSmth = *(float*)um_data->u_data[0];
if (SEGENV.call == 0) {
SEGMENT.setUpLeds();
@@ -6904,7 +6920,7 @@ uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschun
return FRAMETIME;
} // mode_freqwave()
-static const char _data_FX_MODE_FREQWAVE[] PROGMEM = "Freqwave@Time delay,Sound effect,Low bin,High bin,Pre-amp;;;m12=2,si=0,1d,fr"; // Circle, Beatsin
+static const char _data_FX_MODE_FREQWAVE[] PROGMEM = "Freqwave@Time delay,Sound effect,Low bin,High bin,Pre-amp;;;1f;m12=2,si=0"; // Arc, Beatsin
///////////////////////
@@ -6921,16 +6937,16 @@ uint16_t mode_gravfreq(void) { // Gravfreq. By Andrew Tuline.
// add support for no audio
um_data = simulateSound(SEGMENT.soundSim);
}
- float FFT_MajorPeak = *(float*) um_data->u_data[4];
- float volumeSmth = *(float*) um_data->u_data[0];
+ float FFT_MajorPeak = *(float*)um_data->u_data[4];
+ float volumeSmth = *(float*)um_data->u_data[0];
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
SEGMENT.fade_out(250);
- float segmentSampleAvg = volumeSmth * (float)SEGMENT.intensity / 255.0;
+ float segmentSampleAvg = volumeSmth * (float)SEGMENT.intensity / 255.0f;
segmentSampleAvg *= 0.125; // divide by 8, to compensate for later "sensitivty" upscaling
- float mySampleAvg = mapf(segmentSampleAvg*2.0, 0,32, 0, (float)SEGLEN/2.0); // map to pixels availeable in current segment
+ float mySampleAvg = mapf(segmentSampleAvg*2.0f, 0,32, 0, (float)SEGLEN/2.0); // map to pixels availeable in current segment
int tempsamp = constrain(mySampleAvg,0,SEGLEN/2); // Keep the sample from overflowing.
uint8_t gravity = 8 - SEGMENT.speed/32;
@@ -6956,7 +6972,7 @@ uint16_t mode_gravfreq(void) { // Gravfreq. By Andrew Tuline.
return FRAMETIME;
} // mode_gravfreq()
-static const char _data_FX_MODE_GRAVFREQ[] PROGMEM = "Gravfreq@Rate of fall,Sensivity;,!;!;ix=128,m12=0,si=0,1d,fr"; // Pixels, Beatsin
+static const char _data_FX_MODE_GRAVFREQ[] PROGMEM = "Gravfreq@Rate of fall,Sensivity;!,!;!;1f;ix=128,m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6972,7 +6988,7 @@ uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuli
if (SEGENV.call == 0) SEGMENT.fill(BLACK);
//SEGMENT.fade_out(224); // Just in case something doesn't get faded.
- int fadeoutDelay = (256 - SEGMENT.speed) / 96;
+ int fadeoutDelay = (256 - SEGMENT.speed) / 96;
if ((fadeoutDelay <= 1 ) || ((SEGENV.call % fadeoutDelay) == 0)) SEGMENT.fadeToBlackBy(4+ SEGMENT.speed/4);
uint8_t numBins = map(SEGMENT.intensity,0,255,0,16); // Map slider to fftResult bins.
@@ -6984,7 +7000,7 @@ uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuli
return FRAMETIME;
} // mode_noisemove()
-static const char _data_FX_MODE_NOISEMOVE[] PROGMEM = "Noisemove@Speed of perlin movement,Fade rate;,!;!;m12=0,si=0,1d,fr"; // Pixels, Beatsin
+static const char _data_FX_MODE_NOISEMOVE[] PROGMEM = "Noisemove@Speed of perlin movement,Fade rate;!,!;!;1f;m12=0,si=0"; // Pixels, Beatsin
//////////////////////
@@ -6997,7 +7013,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac
um_data = simulateSound(SEGMENT.soundSim);
}
float FFT_MajorPeak = *(float*) um_data->u_data[4];
- float my_magnitude = *(float*) um_data->u_data[5] / 16.0f;
+ float my_magnitude = *(float*) um_data->u_data[5] / 16.0f;
if (SEGENV.call == 0) SEGMENT.fill(BLACK);
SEGMENT.fadeToBlackBy(16); // Just in case something doesn't get faded.
@@ -7016,7 +7032,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac
}
frTemp -=132; // This should give us a base musical note of C3
- frTemp = fabsf(frTemp * 2.1); // Fudge factors to compress octave range starting at 0 and going to 255;
+ frTemp = fabsf(frTemp * 2.1f); // Fudge factors to compress octave range starting at 0 and going to 255;
uint16_t i = map(beatsin8(8+octCount*4, 0, 255, 0, octCount*8), 0, 255, 0, SEGLEN-1);
i = constrain(i, 0, SEGLEN-1);
@@ -7024,7 +7040,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac
return FRAMETIME;
} // mode_rocktaves()
-static const char _data_FX_MODE_ROCKTAVES[] PROGMEM = "Rocktaves@;,!;!;m12=1,si=0,1d,fr"; // Bar, Beatsin
+static const char _data_FX_MODE_ROCKTAVES[] PROGMEM = "Rocktaves@;!,!;!;1f;m12=1,si=0"; // Bar, Beatsin
///////////////////////
@@ -7043,7 +7059,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
float FFT_MajorPeak = *(float*) um_data->u_data[4];
uint8_t *maxVol = (uint8_t*)um_data->u_data[6];
uint8_t *binNum = (uint8_t*)um_data->u_data[7];
- float my_magnitude = *(float*) um_data->u_data[5] / 8.0f;
+ float my_magnitude = *(float*) um_data->u_data[5] / 8.0f;
if (FFT_MajorPeak < 1) FFT_MajorPeak = 1; // log10(0) is "forbidden" (throws exception)
@@ -7076,7 +7092,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
return FRAMETIME;
} // mode_waterfall()
-static const char _data_FX_MODE_WATERFALL[] PROGMEM = "Waterfall@!,Adjust color,Select bin,Volume (min);!,!;!;c2=0,m12=2,si=0,1d,fr"; // Circles, Beatsin
+static const char _data_FX_MODE_WATERFALL[] PROGMEM = "Waterfall@!,Adjust color,Select bin,Volume (min);!,!;!;1f;c2=0,m12=2,si=0"; // Arc, Beatsin
#ifndef WLED_DISABLE_2D
@@ -7099,6 +7115,9 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];
+ #ifdef SR_DEBUG
+ uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
+ #endif
if (SEGENV.call == 0) for (int i=0; i rows) barHeight = rows; // WLEDMM map() can "overshoot" due to rounding errors
if (barHeight > previousBarHeight[x]) previousBarHeight[x] = barHeight; //drive the peak up
uint32_t ledColor = BLACK;
for (int y=0; y < barHeight; y++) {
- if (SEGMENT.check1) //color_vertical / color bars toggle
+ if (SEGMENT.check1) //color_vertical / color bars toggle
colorIndex = map(y, 0, rows-1, 0, 255);
ledColor = SEGMENT.color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0);
SEGMENT.setPixelColorXY(x, rows-1 - y, ledColor);
}
- if (previousBarHeight[x] > 0)
+ if ((previousBarHeight[x] > 0) && (previousBarHeight[x] < rows)) // WLEDMM avoid "overshooting" into other segments
SEGMENT.setPixelColorXY(x, rows - previousBarHeight[x], (SEGCOLOR(2) != BLACK) ? SEGCOLOR(2) : ledColor);
if (rippleTime && previousBarHeight[x]>0) previousBarHeight[x]--; //delay/ripple effect
}
+#ifdef SR_DEBUG
+ // WLEDMM: abuse top left/right pixels for peak detection debugging
+ SEGMENT.setPixelColorXY(cols-1, rows-1, (samplePeak > 0) ? GREEN : BLACK);
+ if (samplePeak > 0) SEGMENT.setPixelColorXY(0, rows-1, GREEN);
+ // WLEDMM end
+#endif
return FRAMETIME;
} // mode_2DGEQ()
-static const char _data_FX_MODE_2DGEQ[] PROGMEM = "GEQ@Fade speed,Ripple decay,# of bands,,,Color bars;!,,Peak Color;!;c1=255,c2=64,pal=11,si=0,2d,fr"; // Beatsin
+static const char _data_FX_MODE_2DGEQ[] PROGMEM = "GEQ ☾@Fade speed,Ripple decay,# of bands,,,Color bars;!,,Peaks;!;2f;c1=255,c2=64,pal=11,si=0"; // Beatsin
/////////////////////////
@@ -7194,7 +7220,7 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil
return FRAMETIME;
} // mode_2DFunkyPlank
-static const char _data_FX_MODE_2DFUNKYPLANK[] PROGMEM = "Funky Plank@Scroll speed,,# of bands;;;si=0,2d,fr"; // Beatsin
+static const char _data_FX_MODE_2DFUNKYPLANK[] PROGMEM = "Funky Plank@Scroll speed,,# of bands;;;2f;si=0"; // Beatsin
/////////////////////////
@@ -7299,7 +7325,62 @@ uint16_t mode_2DAkemi(void) {
return FRAMETIME;
} // mode_2DAkemi
-static const char _data_FX_MODE_2DAKEMI[] PROGMEM = "Akemi@Color speed,Dance;Head palette,Arms & Legs,Eyes & Mouth;Face palette;si=0,2d,fr"; //beatsin
+static const char _data_FX_MODE_2DAKEMI[] PROGMEM = "Akemi@Color speed,Dance;Head palette,Arms & Legs,Eyes & Mouth;Face palette;2f;si=0"; //beatsin
+
+
+// Distortion waves - ldirko
+// https://editor.soulmatelights.com/gallery/1089-distorsion-waves
+// apated for WLD by @blazoncek
+uint16_t mode_2Ddistortionwaves() {
+ if (!strip.isMatrix) return mode_static(); // not a 2D set-up
+
+ const uint16_t cols = SEGMENT.virtualWidth();
+ const uint16_t rows = SEGMENT.virtualHeight();
+
+ uint8_t speed = SEGMENT.speed/32;
+ uint8_t scale = SEGMENT.intensity/32;
+
+ uint8_t w = 2;
+
+ uint16_t a = millis()/32;
+ uint16_t a2 = a/2;
+ uint16_t a3 = a/3;
+
+ uint16_t cx = beatsin8(10-speed,0,cols-1)*scale;
+ uint16_t cy = beatsin8(12-speed,0,rows-1)*scale;
+ uint16_t cx1 = beatsin8(13-speed,0,cols-1)*scale;
+ uint16_t cy1 = beatsin8(15-speed,0,rows-1)*scale;
+ uint16_t cx2 = beatsin8(17-speed,0,cols-1)*scale;
+ uint16_t cy2 = beatsin8(14-speed,0,rows-1)*scale;
+
+ uint16_t xoffs = 0;
+ for (int x = 0; x < cols; x++) {
+ xoffs += scale;
+ uint16_t yoffs = 0;
+
+ for (int y = 0; y < rows; y++) {
+ yoffs += scale;
+
+ byte rdistort = cos8((cos8(((x<<3)+a )&255)+cos8(((y<<3)-a2)&255)+a3 )&255)>>1;
+ byte gdistort = cos8((cos8(((x<<3)-a2)&255)+cos8(((y<<3)+a3)&255)+a+32 )&255)>>1;
+ byte bdistort = cos8((cos8(((x<<3)+a3)&255)+cos8(((y<<3)-a) &255)+a2+64)&255)>>1;
+
+ byte valueR = rdistort+ w* (a- ( ((xoffs - cx) * (xoffs - cx) + (yoffs - cy) * (yoffs - cy))>>7 ));
+ byte valueG = gdistort+ w* (a2-( ((xoffs - cx1) * (xoffs - cx1) + (yoffs - cy1) * (yoffs - cy1))>>7 ));
+ byte valueB = bdistort+ w* (a3-( ((xoffs - cx2) * (xoffs - cx2) + (yoffs - cy2) * (yoffs - cy2))>>7 ));
+
+ valueR = gamma8(cos8(valueR));
+ valueG = gamma8(cos8(valueG));
+ valueB = gamma8(cos8(valueB));
+
+ SEGMENT.setPixelColorXY(x, y, RGBW32(valueR, valueG, valueB, 0));
+ }
+ }
+
+ return FRAMETIME;
+}
+static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = "Distortion Waves@!,Scale;;;2;";
+
#endif // WLED_DISABLE_2D
@@ -7383,7 +7464,7 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_FIRE_FLICKER, &mode_fire_flicker, _data_FX_MODE_FIRE_FLICKER);
addEffect(FX_MODE_GRADIENT, &mode_gradient, _data_FX_MODE_GRADIENT);
addEffect(FX_MODE_LOADING, &mode_loading, _data_FX_MODE_LOADING);
-
+
addEffect(FX_MODE_FAIRY, &mode_fairy, _data_FX_MODE_FAIRY);
addEffect(FX_MODE_TWO_DOTS, &mode_two_dots, _data_FX_MODE_TWO_DOTS);
addEffect(FX_MODE_FAIRYTWINKLE, &mode_fairytwinkle, _data_FX_MODE_FAIRYTWINKLE);
@@ -7498,6 +7579,7 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_2DBLOBS, &mode_2Dfloatingblobs, _data_FX_MODE_2DBLOBS);
addEffect(FX_MODE_2DSCROLLTEXT, &mode_2Dscrollingtext, _data_FX_MODE_2DSCROLLTEXT);
addEffect(FX_MODE_2DDRIFTROSE, &mode_2Ddriftrose, _data_FX_MODE_2DDRIFTROSE);
+ addEffect(FX_MODE_2DDISTORTIONWAVES, &mode_2Ddistortionwaves, _data_FX_MODE_2DDISTORTIONWAVES);
addEffect(FX_MODE_2DGEQ, &mode_2DGEQ, _data_FX_MODE_2DGEQ); // audio
@@ -7535,5 +7617,5 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_2DAKEMI, &mode_2DAkemi, _data_FX_MODE_2DAKEMI); // audio
#endif // WLED_DISABLE_2D
-
+
}
diff --git a/wled00/FX.h b/wled00/FX.h
index 9d2a6e01..86ecd39e 100644
--- a/wled00/FX.h
+++ b/wled00/FX.h
@@ -143,7 +143,7 @@
#define FX_MODE_SAW 16
#define FX_MODE_TWINKLE 17
#define FX_MODE_DISSOLVE 18
-#define FX_MODE_DISSOLVE_RANDOM 19
+#define FX_MODE_DISSOLVE_RANDOM 19 // candidate for removal (use Dissolve with with check 3)
#define FX_MODE_SPARKLE 20
#define FX_MODE_FLASH_SPARKLE 21
#define FX_MODE_HYPER_SPARKLE 22
@@ -227,7 +227,7 @@
#define FX_MODE_HEARTBEAT 100
#define FX_MODE_PACIFICA 101
#define FX_MODE_CANDLE_MULTI 102
-#define FX_MODE_SOLID_GLITTER 103
+#define FX_MODE_SOLID_GLITTER 103 // candidate for removal (use glitter)
#define FX_MODE_SUNRISE 104
#define FX_MODE_PHASED 105
#define FX_MODE_TWINKLEUP 106
@@ -241,7 +241,7 @@
// #define FX_MODE_CANDY_CANE 114 // removed in 0.14!
#define FX_MODE_BLENDS 115
#define FX_MODE_TV_SIMULATOR 116
-#define FX_MODE_DYNAMIC_SMOOTH 117
+#define FX_MODE_DYNAMIC_SMOOTH 117 // candidate for removal (check3 in dynamic)
// new 0.14 2D effects
#define FX_MODE_2DSPACESHIPS 118 //gap fill
@@ -250,6 +250,7 @@
#define FX_MODE_2DBLOBS 121 //gap fill
#define FX_MODE_2DSCROLLTEXT 122 //gap fill
#define FX_MODE_2DDRIFTROSE 123 //gap fill
+#define FX_MODE_2DDISTORTIONWAVES 124
// WLED-SR effects (SR compatible IDs !!!)
#define FX_MODE_PIXELS 128
@@ -373,10 +374,11 @@ typedef struct Segment {
uint32_t call; // call counter
uint16_t aux0; // custom var
uint16_t aux1; // custom var
- byte* data;
- CRGB* leds;
- static CRGB *_globalLeds;
- void *jMap; //WLEDMM jMap
+ byte* data; // effect data pointer
+ CRGB* leds; // local leds[] array (may be a pointer to global)
+ static CRGB *_globalLeds; // global leds[] array
+ static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)
+ void *jMap = nullptr; //WLEDMM jMap
private:
union {
@@ -508,6 +510,7 @@ typedef struct Segment {
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
+ void set(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1);
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
void setCCT(uint16_t k);
void setOpacity(uint8_t o);
@@ -522,9 +525,9 @@ typedef struct Segment {
bool allocateData(size_t len);
void deallocateData(void);
void resetIfRequired(void);
- /**
+ /**
* Flags that before the next effect is calculated,
- * the internal segment state should be reset.
+ * the internal segment state should be reset.
* Call resetIfRequired before calling the next effect function.
* Safe to call from interrupts and network requests.
*/
@@ -593,13 +596,14 @@ typedef struct Segment {
void moveX(int8_t delta);
void moveY(int8_t delta);
void move(uint8_t dir, uint8_t delta);
+ void draw_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB c);
void fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB c);
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c);
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c) { drawLine(x0, y0, x1, y1, RGBW32(c.r,c.g,c.b,0)); } // automatic inline
void drawArc(uint16_t x0, uint16_t y0, uint16_t radius, uint32_t color, uint32_t fillColor = 0);
void drawArc(uint16_t x0, uint16_t y0, uint16_t radius, CRGB color, CRGB fillColor = BLACK) { drawArc(x0, y0, radius, RGBW32(color.r,color.g,color.b,0), RGBW32(fillColor.r,fillColor.g,fillColor.b,0)); } // automatic inline
- void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color);
- void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c) { drawCharacter(chr, x, y, w, h, RGBW32(c.r,c.g,c.b,0)); } // automatic inline
+ void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2 = 0);
+ void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2) { drawCharacter(chr, x, y, w, h, RGBW32(c.r,c.g,c.b,0), RGBW32(c2.r,c2.g,c2.b,0)); } // automatic inline
void wu_pixel(uint32_t x, uint32_t y, CRGB c);
void blur1d(fract8 blur_amount); // blur all rows in 1 dimension
void blur2d(fract8 blur_amount) { blur(blur_amount); }
@@ -649,7 +653,7 @@ class WS2812FX { // 96 bytes
} mode_data_t;
static WS2812FX* instance;
-
+
public:
WS2812FX() :
@@ -663,14 +667,8 @@ class WS2812FX { // 96 bytes
timebase(0),
isMatrix(false),
#ifndef WLED_DISABLE_2D
- hPanels(1),
- vPanels(1),
- panelH(8),
- panelW(8),
- matrixWidth(DEFAULT_LED_COUNT),
- matrixHeight(1),
+ panels(1),
matrix{0,0,0,0},
- panel{{0,0,0,0}},
#endif
// semi-private (just obscured) used in effect functions through macros
_currentPalette(CRGBPalette16(CRGB::Black)),
@@ -707,6 +705,9 @@ class WS2812FX { // 96 bytes
_mode.clear();
_modeData.clear();
_segments.clear();
+#ifndef WLED_DISABLE_2D
+ panel.clear();
+#endif
customPalettes.clear();
if (useLedsArray && Segment::_globalLeds) free(Segment::_globalLeds);
}
@@ -730,13 +731,14 @@ class WS2812FX { // 96 bytes
setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 1, uint8_t spacing = 0, uint16_t offset = UINT16_MAX, uint16_t startY=0, uint16_t stopY=1),
setMainSegmentId(uint8_t n),
restartRuntime(),
- resetSegments(),
+ resetSegments(bool boundsOnly = false), //WLEDMM add boundsOnly
makeAutoSegments(bool forceReset = false),
fixInvalidSegments(),
setPixelColor(int n, uint32_t c),
show(void),
setTargetFps(uint8_t fps),
- deserializeMap(uint8_t n=0);
+ deserializeMap(uint8_t n=0),
+ enumerateLedmaps(); //WLEDMM (from fcn_declare)
void fill(uint32_t c) { for (int i = 0; i < _length; i++) setPixelColor(i, c); } // fill whole strip with color (inline)
void addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name); // add effect to the list; defined in FX.cpp
@@ -777,7 +779,7 @@ class WS2812FX { // 96 bytes
inline uint8_t getSegmentsNum(void) { return _segments.size(); } // returns currently present segments
inline uint8_t getCurrSegmentId(void) { return _segment_index; }
inline uint8_t getMainSegmentId(void) { return _mainSegment; }
- inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; }
+ inline uint8_t getPaletteCount() { return 13 + GRADIENT_PALETTE_COUNT; } // will only return built-in palette count
inline uint8_t getTargetFps() { return _targetFps; }
inline uint8_t getModeCount() { return _modeCount; }
@@ -819,24 +821,42 @@ class WS2812FX { // 96 bytes
#ifndef WLED_DISABLE_2D
#define WLED_MAX_PANELS 64
uint8_t
- hPanels,
- vPanels;
+ panels,
+ panelsH, //WLEDMM needs to be stored as well
+ panelsV; //WLEDMM needs to be stored as well
- uint16_t
- panelH,
- panelW,
- matrixWidth,
- matrixHeight;
+ bool
+ bOrA; //WLEDMM basic or advanced
+
+ struct {
+ bool bottomStart : 1;
+ bool rightStart : 1;
+ bool vertical : 1;
+ bool serpentine : 1;
+ } matrix;
+ struct {
+ bool bottomStart : 1;
+ bool rightStart : 1;
+ bool vertical : 1;
+ bool serpentine : 1;
+ } panelO; //WLEDMM panelOrientation
- typedef struct panel_bitfield_t {
- bool bottomStart : 1; // starts at bottom?
- bool rightStart : 1; // starts on right?
- bool vertical : 1; // is vertical?
- bool serpentine : 1; // is serpentine?
+ typedef struct panel_t {
+ uint8_t xOffset; // x offset relative to the top left of matrix in LEDs. WLEDMM 8 bits/256 is enough
+ uint8_t yOffset; // y offset relative to the top left of matrix in LEDs. WLEDMM 8 bits/256 is enough
+ uint8_t width; // width of the panel
+ uint8_t height; // height of the panel
+ union {
+ uint8_t options;
+ struct {
+ bool bottomStart : 1; // starts at bottom?
+ bool rightStart : 1; // starts on right?
+ bool vertical : 1; // is vertical?
+ bool serpentine : 1; // is serpentine?
+ };
+ };
} Panel;
- Panel
- matrix,
- panel[WLED_MAX_PANELS];
+ std::vector panel;
#endif
void
@@ -889,9 +909,9 @@ class WS2812FX { // 96 bytes
uint16_t* customMappingTable;
uint16_t customMappingSize;
-
+
uint32_t _lastShow;
-
+
uint8_t _segment_index;
uint8_t _mainSegment;
diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp
index 55493e3e..a35cc6a9 100644
--- a/wled00/FX_2Dfcn.cpp
+++ b/wled00/FX_2Dfcn.cpp
@@ -1,6 +1,6 @@
/*
FX_2Dfcn.cpp contains all 2D utility functions
-
+
LICENSE
The MIT License (MIT)
Copyright (c) 2022 Blaz Kristan (https://blaz.at/home)
@@ -20,7 +20,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
- Parts of the code adapted from WLED Sound Reactive
+ Parts of the code adapted from WLED Sound Reactive: Copyright (c) 2022 Andrew Tuline, Ewoud Wijma, Harm Aldick
*/
#include "wled.h"
#include "FX.h"
@@ -29,8 +29,8 @@
// setUpMatrix() - constructs ledmap array from matrix of panels with WxH pixels
// this converts physical (possibly irregular) LED arrangement into well defined
// array of logical pixels: fist entry corresponds to left-topmost logical pixel
-// followed by horizontal pixels, when matrixWidth logical pixels are added they
-// are followed by next row (down) of matrixWidth pixels (and so forth)
+// followed by horizontal pixels, when Segment::maxWidth logical pixels are added they
+// are followed by next row (down) of Segment::maxWidth pixels (and so forth)
// note: matrix may be comprised of multiple panels each with different orientation
// but ledmap takes care of that. ledmap is constructed upon initialization
// so matrix should disable regular ledmap processing
@@ -41,78 +41,98 @@ void WS2812FX::setUpMatrix(bool reset) {
if (customMappingTable != nullptr) delete[] customMappingTable;
customMappingTable = nullptr;
customMappingSize = 0;
+ loadedLedmap = 0;
}
+ // isMatrix is set in cfg.cpp or set.cpp
if (isMatrix) {
- matrixWidth = hPanels * panelW;
- matrixHeight = vPanels * panelH;
-
- // safety check
- if (matrixWidth * matrixHeight > MAX_LEDS) {
- matrixWidth = _length;
- matrixHeight = 1;
- isMatrix = false;
- return;
+ // calculate width dynamically because it will have gaps
+ Segment::maxWidth = 1;
+ Segment::maxHeight = 1;
+ for (size_t i = 0; i < panel.size(); i++) {
+ Panel &p = panel[i];
+ if (p.xOffset + p.width > Segment::maxWidth) {
+ Segment::maxWidth = p.xOffset + p.width;
+ }
+ if (p.yOffset + p.height > Segment::maxHeight) {
+ Segment::maxHeight = p.yOffset + p.height;
+ }
}
if (reset) { //WLEDMM: add reset option to switch on/off reset of customMappingTable
- customMappingSize = matrixWidth * matrixHeight;
- customMappingTable = new uint16_t[customMappingSize];
- //WLEDMM: init customMappingTable with a 1:1 mapping (for customMappingTable[customMappingTable[x]])
- for (uint16_t i=0; i MAX_LEDS || Segment::maxWidth <= 1 || Segment::maxHeight <= 1) {
+ DEBUG_PRINTF("2D Bounds error. %d x %d\n", Segment::maxWidth, Segment::maxHeight);
+ isMatrix = false;
+ Segment::maxWidth = _length;
+ Segment::maxHeight = 1;
+ panels = 0;
+ panel.clear(); // release memory allocated by panels
+ resetSegments(true); //WLEDMM bounds only
+ return;
}
+
+ customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
}
if (customMappingTable != nullptr) {
- uint16_t startL; // index in custom mapping array (logical strip)
- uint16_t startP; // position of 1st pixel of panel on (virtual) strip
- uint16_t x, y, offset;
- uint8_t h = matrix.vertical ? vPanels : hPanels;
- uint8_t v = matrix.vertical ? hPanels : vPanels;
+ uint16_t customMappingSizeLedmap = customMappingSize;
+ customMappingSize = Segment::maxWidth * Segment::maxHeight;
- for (uint8_t j=0, p=0; j 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap
+ customMappingTableCombi = new uint16_t[customMappingSize];
+ for (int i=0; i 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap
+ if (index < customMappingSizeLedmap && customMappingTable[index] < customMappingSize)
+ customMappingTableCombi[customMappingTable[index]] = pix; //WLEDMM: allow for 2 transitions if reset = false (ledmap and logical to physical)
}
+ else
+ customMappingTable[index] = pix;
}
}
}
+
+ if (customMappingSizeLedmap > 0) { //WLEDMM: @Troy#2642 : include ledmap = 0 as default ledmap
+ for (size_t i = 0; i < customMappingSize; i++) {
+ customMappingTable[i] = customMappingTableCombi[i];
+ }
+ delete[] customMappingTableCombi;
+ }
+
#ifdef WLED_DEBUG
- DEBUG_PRINT(F("Matrix ledmap:"));
+ DEBUG_PRINTF("Matrix ledmap: %d\n", loadedLedmap);
for (uint16_t i=0; i= customMappingSize) return;
#else
uint16_t index = x;
-#endif
if (index >= _length) return;
+#endif
if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col);
}
@@ -133,11 +154,12 @@ void IRAM_ATTR_YN WS2812FX::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM
// returns RGBW values of pixel
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
#ifndef WLED_DISABLE_2D
- uint16_t index = (y * matrixWidth + x);
+ uint16_t index = (y * Segment::maxWidth + x);
+ if (index >= customMappingSize) return 0; // customMappingSize is always W * H of matrix in 2D setup
#else
uint16_t index = x;
-#endif
if (index >= _length) return 0;
+#endif
if (index < customMappingSize) index = customMappingTable[index];
return busses.getPixelColor(index);
}
@@ -157,12 +179,13 @@ uint16_t IRAM_ATTR_YN Segment::XY(uint16_t x, uint16_t y) { //WLEDMM: IRAM_ATTR
void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionaly
{
- if (!strip.isMatrix) return; // not a matrix set-up
+ if (Segment::maxHeight==1) return; // not a matrix set-up
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
if (leds) leds[XY(x,y)] = col;
uint8_t _bri_t = currentBri(on ? opacity : 0);
+ if (!_bri_t && !transitional) return;
if (_bri_t < 255) {
byte r = scale8(R(col), _bri_t);
byte g = scale8(G(col), _bri_t);
@@ -204,7 +227,7 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
// anti-aliased version of setPixelColorXY()
void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
{
- if (!strip.isMatrix) return; // not a matrix set-up
+ if (Segment::maxHeight==1) return; // not a matrix set-up
if (x<0.0f || x>1.0f || y<0.0f || y>1.0f) return; // not normalized
const uint16_t cols = virtualWidth();
@@ -270,7 +293,7 @@ void Segment::addPixelColorXY(int x, int y, uint32_t color) {
void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade);
- setPixelColor(x, y, pix);
+ setPixelColorXY(x, y, pix);
}
// blurRow: perform a blur on a row of a rectangular matrix
@@ -427,6 +450,29 @@ void Segment::move(uint8_t dir, uint8_t delta) {
}
}
+void Segment::draw_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
+ // Bresenham’s Algorithm
+ int d = 3 - (2*radius);
+ int y = radius, x = 0;
+ while (y >= x) {
+ setPixelColorXY(cx+x, cy+y, col);
+ setPixelColorXY(cx-x, cy+y, col);
+ setPixelColorXY(cx+x, cy-y, col);
+ setPixelColorXY(cx-x, cy-y, col);
+ setPixelColorXY(cx+y, cy+x, col);
+ setPixelColorXY(cx-y, cy+x, col);
+ setPixelColorXY(cx+y, cy-x, col);
+ setPixelColorXY(cx-y, cy-x, col);
+ x++;
+ if (d > 0) {
+ y--;
+ d += 4 * (x - y) + 10;
+ } else {
+ d += 4 * x + 6;
+ }
+ }
+}
+
// by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs
void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
const uint16_t cols = virtualWidth();
@@ -436,7 +482,7 @@ void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
if (x * x + y * y <= radius * radius &&
int16_t(cx)+x>=0 && int16_t(cy)+y>=0 &&
int16_t(cx)+x= cols || x1 >= cols || y0 >= rows || y1 >= rows) return;
const int16_t dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2;
for (;;) {
- addPixelColorXY(x0,y0,c);
+ setPixelColorXY(x0,y0,c);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
@@ -497,13 +543,16 @@ void Segment::drawArc(uint16_t x0, uint16_t y0, uint16_t radius, uint32_t color,
// draws a raster font character on canvas
// only supports: 4x6=24, 5x8=40, 5x12=60, 6x8=48 and 7x9=63 fonts ATM
-void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color) {
+void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2) {
if (chr < 32 || chr > 126) return; // only ASCII 32-126 supported
chr -= 32; // align with font table entries
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
const int font = w*h;
+ CRGB col = CRGB(color);
+ CRGBPalette16 grad = CRGBPalette16(col, col2 ? CRGB(col2) : col);
+
//if (w<5 || w>6 || h!=8) return;
for (int i = 0; i= 0 || x0 < cols) && ((bits>>(j+(8-w))) & 0x01)) { // bit set & drawing on-screen
- addPixelColorXY(x0, y0, color);
+ setPixelColorXY(x0, y0, col);
}
}
}
diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp
index 4d13224d..c666d913 100644
--- a/wled00/FX_fcn.cpp
+++ b/wled00/FX_fcn.cpp
@@ -75,6 +75,8 @@
///////////////////////////////////////////////////////////////////////////////
uint16_t Segment::_usedSegmentData = 0U; // amount of RAM all segments use for their data[]
CRGB *Segment::_globalLeds = nullptr;
+uint16_t Segment::maxWidth = DEFAULT_LED_COUNT;
+uint16_t Segment::maxHeight = 1;
// copy constructor
Segment::Segment(const Segment &orig) {
@@ -176,18 +178,18 @@ void Segment::deallocateData() {
_dataLen = 0;
}
-/**
+/**
* If reset of this segment was requested, clears runtime
* settings of this segment.
* Must not be called while an effect mode function is running
- * because it could access the data buffer and this method
+ * because it could access the data buffer and this method
* may free that data buffer.
*/
void Segment::resetIfRequired() {
if (reset) {
if (leds && !Segment::_globalLeds) { free(leds); leds = nullptr; }
//if (_t) { delete _t; _t = nullptr; transitional = false; }
- next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
+ next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
reset = false; // setOption(SEG_OPTION_RESET, false);
}
}
@@ -196,7 +198,7 @@ void Segment::setUpLeds() {
// deallocation happens in resetIfRequired() as it is called when segment changes or in destructor
if (Segment::_globalLeds)
#ifndef WLED_DISABLE_2D
- leds = &Segment::_globalLeds[start + startY*strip.matrixWidth]; // TODO: remove this hack
+ leds = &Segment::_globalLeds[start + startY*Segment::maxWidth];
#else
leds = &Segment::_globalLeds[start];
#endif
@@ -213,6 +215,7 @@ void Segment::setUpLeds() {
CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
static unsigned long _lastPaletteChange = 0; // perhaps it should be per segment
static CRGBPalette16 randomPalette = CRGBPalette16(DEFAULT_COLOR);
+ static CRGBPalette16 prevRandomPalette = CRGBPalette16(CRGB(BLACK));
byte tcp[72];
if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0;
if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0;
@@ -232,16 +235,49 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
switch (pal) {
case 0: //default palette. Exceptions for specific effects above
targetPalette = PartyColors_p; break;
- case 1: //periodically replace palette with a random one. Doesn't work with multiple FastLED segments
- if (millis() - _lastPaletteChange > 5000 /*+ ((uint32_t)(255-intensity))*100*/) {
+ case 1: {//periodically replace palette with a random one. Transition palette change in 500ms
+ uint32_t timeSinceLastChange = millis() - _lastPaletteChange;
+ if (timeSinceLastChange > 5000 /*+ ((uint32_t)(255-intensity))*100*/) {
+ prevRandomPalette = randomPalette;
randomPalette = CRGBPalette16(
CHSV(random8(), random8(160, 255), random8(128, 255)),
CHSV(random8(), random8(160, 255), random8(128, 255)),
CHSV(random8(), random8(160, 255), random8(128, 255)),
CHSV(random8(), random8(160, 255), random8(128, 255)));
_lastPaletteChange = millis();
+ timeSinceLastChange = 0;
}
- targetPalette = randomPalette; break;
+
+ //WLEDMM: smooth transitions of palettes instead of every 5 sec with short transition
+ for (int i=0; i< 16; i++) {
+ targetPalette[i].r = prevRandomPalette[i].r*(5000-timeSinceLastChange)/5000 + randomPalette[i].r*timeSinceLastChange/5000;
+ targetPalette[i].g = prevRandomPalette[i].g*(5000-timeSinceLastChange)/5000 + randomPalette[i].g*timeSinceLastChange/5000;
+ targetPalette[i].b = prevRandomPalette[i].b*(5000-timeSinceLastChange)/5000 + randomPalette[i].b*timeSinceLastChange/5000;
+ }
+ break;}
+ case 73: {//periodically replace palette with a random one. Transition palette change in 500ms
+ uint32_t timeSinceLastChange = millis() - _lastPaletteChange;
+ if (timeSinceLastChange > 5000 /*+ ((uint32_t)(255-intensity))*100*/) {
+ prevRandomPalette = randomPalette;
+ randomPalette = CRGBPalette16(
+ CHSV(random8(), random8(160, 255), random8(128, 255)),
+ CHSV(random8(), random8(160, 255), random8(128, 255)),
+ CHSV(random8(), random8(160, 255), random8(128, 255)),
+ CHSV(random8(), random8(160, 255), random8(128, 255)));
+ _lastPaletteChange = millis();
+ timeSinceLastChange = 0;
+ }
+ if (timeSinceLastChange <= 250) {
+ targetPalette = prevRandomPalette;
+ // there needs to be 255 palette blends (48) for full blend but that is too resource intensive
+ // so 128 is a compromise (we need to perform full blend of the two palettes as each segment can have random
+ // palette selected but only 2 static palettes are used)
+ size_t noOfBlends = ((128U * timeSinceLastChange) / 250U);
+ for (size_t i=0; i1) boundsUnchanged &= (startY == i1Y && stopY == i2Y); // 2D
+ #endif
+ if (boundsUnchanged
+ && (!grp || (grouping == grp && spacing == spc))
+ && (ofs == UINT16_MAX || ofs == offset)) return;
+
+ if (stop) fill(BLACK); //turn old segment range off
+ if (i2 <= i1) { //disable segment
+ stop = 0;
+ markForReset();
+ return;
+ }
+ if (i1 < Segment::maxWidth || (i1 >= Segment::maxWidth*Segment::maxHeight && i1 < strip.getLengthTotal())) start = i1; // Segment::maxWidth equals strip.getLengthTotal() for 1D
+ stop = i2 > Segment::maxWidth*Segment::maxHeight ? MIN(i2,strip.getLengthTotal()) : (i2 > Segment::maxWidth ? Segment::maxWidth : MAX(1,i2));
+ startY = 0;
+ stopY = 1;
+ #ifndef WLED_DISABLE_2D
+ if (Segment::maxHeight>1) { // 2D
+ if (i1Y < Segment::maxHeight) startY = i1Y;
+ stopY = i2Y > Segment::maxHeight ? Segment::maxHeight : MAX(1,i2Y);
+ }
+ #endif
+ if (grp) {
+ grouping = grp;
+ spacing = spc;
+ }
+ if (ofs < UINT16_MAX) offset = ofs;
+ markForReset();
+ if (!boundsUnchanged) refreshLightCapabilities();
+}
+
+
bool Segment::setColor(uint8_t slot, uint32_t c) { //returns true if changed
if (slot >= NUM_COLORS || c == colors[slot]) return false;
if (fadeTransition) startTransition(strip.getTransition()); // start transition prior to change
@@ -404,6 +476,14 @@ void Segment::setOption(uint8_t n, bool val) {
}
void Segment::setMode(uint8_t fx, bool loadDefaults) {
+ //WLEDMM: return to old setting if not explicitly set
+ static int16_t oldMap = -1;
+ static int16_t oldSim = -1;
+ static int16_t oldPalette = -1;
+ static byte oldReverse = -1;
+ static byte oldMirror = -1;
+ static byte oldReverse_y = -1;
+ static byte oldMirror_y = -1;
// if we have a valid mode & is not reserved
if (fx < strip.getModeCount() && strncmp_P("RSVD", strip.getModeData(fx), 4)) {
if (fx != mode) {
@@ -414,23 +494,22 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) {
// load default values from effect string
if (loadDefaults) {
int16_t sOpt;
- sOpt = extractModeDefaults(fx, "sx"); if (sOpt >= 0) speed = sOpt;
- sOpt = extractModeDefaults(fx, "ix"); if (sOpt >= 0) intensity = sOpt;
- sOpt = extractModeDefaults(fx, "c1"); if (sOpt >= 0) custom1 = sOpt;
- sOpt = extractModeDefaults(fx, "c2"); if (sOpt >= 0) custom2 = sOpt;
- sOpt = extractModeDefaults(fx, "c3"); if (sOpt >= 0) custom3 = sOpt;
- sOpt = extractModeDefaults(fx, "m12"); if (sOpt >= 0) map1D2D = constrain(sOpt, 0, 7);
- sOpt = extractModeDefaults(fx, "si"); if (sOpt >= 0) soundSim = constrain(sOpt, 0, 7);
- sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) reverse = (bool)sOpt;
- sOpt = extractModeDefaults(fx, "mi"); if (sOpt >= 0) mirror = (bool)sOpt; // NOTE: setting this option is a risky business
- sOpt = extractModeDefaults(fx, "rY"); if (sOpt >= 0) reverse_y = (bool)sOpt;
- sOpt = extractModeDefaults(fx, "mY"); if (sOpt >= 0) mirror_y = (bool)sOpt; // NOTE: setting this option is a risky business
- sOpt = extractModeDefaults(fx, "pal");
- if (sOpt >= 0 && (size_t)sOpt < strip.getPaletteCount() + strip.customPalettes.size()) {
- if (sOpt != palette) {
- palette = sOpt;
- }
- }
+ sOpt = extractModeDefaults(fx, "sx"); speed = (sOpt >= 0) ? sOpt : DEFAULT_SPEED;
+ sOpt = extractModeDefaults(fx, "ix"); intensity = (sOpt >= 0) ? sOpt : DEFAULT_INTENSITY;
+ sOpt = extractModeDefaults(fx, "c1"); custom1 = (sOpt >= 0) ? sOpt : DEFAULT_C1;
+ sOpt = extractModeDefaults(fx, "c2"); custom2 = (sOpt >= 0) ? sOpt : DEFAULT_C2;
+ sOpt = extractModeDefaults(fx, "c3"); custom3 = (sOpt >= 0) ? sOpt : DEFAULT_C3;
+ sOpt = extractModeDefaults(fx, "o1"); check1 = (sOpt >= 0) ? (bool)sOpt : false;
+ sOpt = extractModeDefaults(fx, "o2"); check2 = (sOpt >= 0) ? (bool)sOpt : false;
+ sOpt = extractModeDefaults(fx, "o3"); check3 = (sOpt >= 0) ? (bool)sOpt : false;
+ //WLEDMM: return to old setting if not explicitly set
+ sOpt = extractModeDefaults(fx, "m12"); if (sOpt >= 0) {if (oldMap==-1) oldMap = map1D2D; map1D2D = constrain(sOpt, 0, 7);} else {if (oldMap!=-1) map1D2D = oldMap; oldMap = -1;}
+ sOpt = extractModeDefaults(fx, "si"); if (sOpt >= 0) {if (oldSim==-1) oldSim = soundSim; soundSim = constrain(sOpt, 0, 7);} else {if (oldSim!=-1) soundSim = oldSim; oldSim = -1;}
+ sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) {if (oldReverse==-1) oldReverse = reverse; reverse = (bool)sOpt;} else {if (oldReverse!=-1) reverse = oldReverse==1; oldReverse = -1;}
+ sOpt = extractModeDefaults(fx, "mi"); if (sOpt >= 0) {if (oldMirror==-1) oldMirror = mirror; mirror = (bool)sOpt;} else {if (oldMirror!=-1) mirror = oldMirror==1; oldMirror = -1;} // NOTE: setting this option is a risky business
+ sOpt = extractModeDefaults(fx, "rY"); if (sOpt >= 0) {if (oldReverse_y==-1) oldReverse_y = reverse_y; reverse_y = (bool)sOpt;} else {if (oldReverse_y!=-1) reverse_y = oldReverse_y==1; oldReverse_y = -1;}
+ sOpt = extractModeDefaults(fx, "mY"); if (sOpt >= 0) {if (oldMirror_y==-1) oldMirror_y = mirror_y; mirror_y = (bool)sOpt;} else {if (oldMirror_y!=-1) mirror_y = oldMirror_y==1; oldMirror_y = -1;} // NOTE: setting this option is a risky business
+ sOpt = extractModeDefaults(fx, "pal"); if (sOpt >= 0) {if (oldPalette==-1) oldPalette = palette; setPalette(sOpt);} else {if (oldPalette!=-1) setPalette(oldPalette); oldPalette = -1;}
}
stateChanged = true; // send UDP/WS broadcast
}
@@ -438,13 +517,13 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) {
}
void Segment::setPalette(uint8_t pal) {
- if (pal < strip.getPaletteCount()) {
- if (pal != palette) {
- if (strip.paletteFade) startTransition(strip.getTransition());
- palette = pal;
- }
+ if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; // built in palettes
+ if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0; // custom palettes
+ if (pal != palette) {
+ if (strip.paletteFade) startTransition(strip.getTransition());
+ palette = pal;
+ stateChanged = true; // send UDP/WS broadcast
}
- stateChanged = true; // send UDP/WS broadcast
}
// 2D matrix
@@ -502,7 +581,7 @@ class JMapC {
void deletejVectorMap() {
if (jVectorMap.size() > 0) {
Serial.println("delete jVectorMap");
- for (int i=0; i= virtualLength() || i<0) return; // if pixel would fall out of segment just exit
#ifndef WLED_DISABLE_2D
- if (is2D()) { // if this does not work use strip.isMatrix
+ if (is2D()) {
uint16_t vH = virtualHeight(); // segment height in logical pixels
uint16_t vW = virtualWidth();
switch (map1D2D) {
@@ -721,8 +800,31 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
// expand in circular fashion from center
if (i==0)
setPixelColorXY(0, 0, col);
- else
- drawArc(0, 0, i, col);
+ else {
+ //WLEDMM: drawArc(0, 0, i, col); could work as alternative
+
+ float step = HALF_PI / (2.85f*i);
+ for (float rad = 0.0f; rad <= HALF_PI+step/2; rad += step) {
+ // may want to try float version as well (with or without antialiasing)
+ int x = roundf(sin_t(rad) * i);
+ int y = roundf(cos_t(rad) * i);
+ setPixelColorXY(x, y, col);
+ }
+ // Bresenham’s Algorithm (may not fill every pixel)
+ //int d = 3 - (2*i);
+ //int y = i, x = 0;
+ //while (y >= x) {
+ // setPixelColorXY(x, y, col);
+ // setPixelColorXY(y, x, col);
+ // x++;
+ // if (d > 0) {
+ // y--;
+ // d += 4 * (x - y) + 10;
+ // } else {
+ // d += 4 * x + 6;
+ // }
+ //}
+ }
break;
case M12_pCorner:
for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col);
@@ -763,13 +865,15 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
break;
}
return;
- } else if (strip.isMatrix && (width()==1 || height()==1)) { // TODO remove this hack
- // we have a vertical or horizontal 1D segment (WARNING: virtual...() may be transposed)
- int x = 0, y = 0;
- if (virtualHeight()>1) y = i;
- if (virtualWidth() >1) x = i;
- setPixelColorXY(x, y, col);
- return;
+ } else if (Segment::maxHeight!=1 && (width()==1 || height()==1)) {
+ if (start < Segment::maxWidth*Segment::maxHeight) {
+ // we have a vertical or horizontal 1D segment (WARNING: virtual...() may be transposed)
+ int x = 0, y = 0;
+ if (virtualHeight()>1) y = i;
+ if (virtualWidth() >1) x = i;
+ setPixelColorXY(x, y, col);
+ return;
+ }
}
#endif
@@ -777,6 +881,7 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
uint16_t len = length();
uint8_t _bri_t = currentBri(on ? opacity : 0);
+ if (!_bri_t && !transitional) return;
if (_bri_t < 255) {
byte r = scale8(R(col), _bri_t);
byte g = scale8(G(col), _bri_t);
@@ -801,7 +906,7 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
uint16_t indexSet = i + ((reverse) ? -j : j);
if (indexSet >= start && indexSet < stop) {
if (mirror) { //set the corresponding mirrored pixel
- uint16_t indexMir = stop - indexSet + start - 1;
+ uint16_t indexMir = stop - indexSet + start - 1;
indexMir += offset; // offset/phase
if (indexMir >= stop) indexMir -= len; // wrap
strip.setPixelColor(indexMir, col);
@@ -851,7 +956,7 @@ uint32_t Segment::getPixelColor(int i)
i &= 0xFFFF;
#ifndef WLED_DISABLE_2D
- if (is2D()) { // if this does not work use strip.isMatrix
+ if (is2D()) {
uint16_t vH = virtualHeight(); // segment height in logical pixels
uint16_t vW = virtualWidth();
switch (map1D2D) {
@@ -934,7 +1039,7 @@ uint8_t Segment::differs(Segment& b) const {
}
void Segment::refreshLightCapabilities() {
- uint8_t capabilities = 0x01;
+ uint8_t capabilities = 0;
for (uint8_t b = 0; b < busses.getNumBusses(); b++) {
Bus *bus = busses.getBus(b);
@@ -944,19 +1049,17 @@ void Segment::refreshLightCapabilities() {
if (bus->getStart() + bus->getLength() <= start) continue;
uint8_t type = bus->getType();
- if (type == TYPE_ANALOG_1CH || (!cctFromRgb && type == TYPE_ANALOG_2CH)) capabilities &= 0xFE; // does not support RGB
- if (bus->isRgbw()) capabilities |= 0x02; // segment supports white channel
- if (!cctFromRgb) {
- switch (type) {
- case TYPE_ANALOG_5CH:
- case TYPE_ANALOG_2CH:
- capabilities |= 0x04; //segment supports white CCT
- }
+ if (bus->hasRGB() || (cctFromRgb && bus->hasCCT())) capabilities |= SEG_CAPABILITY_RGB;
+ if (!cctFromRgb && bus->hasCCT()) capabilities |= SEG_CAPABILITY_CCT;
+ if (correctWB && (bus->hasRGB() || bus->hasCCT())) capabilities |= SEG_CAPABILITY_CCT; //white balance correction (CCT slider)
+ if (bus->hasWhite()) {
+ uint8_t aWM = Bus::getGlobalAWMode() == AW_GLOBAL_DISABLED ? bus->getAutoWhiteMode() : Bus::getGlobalAWMode();
+ bool whiteSlider = (aWM == RGBW_MODE_DUAL || aWM == RGBW_MODE_MANUAL_ONLY); // white slider allowed
+ // if auto white calculation from RGB is active (Accurate/Brighter), force RGB controls even if there are no RGB busses
+ if (!whiteSlider) capabilities |= SEG_CAPABILITY_RGB;
+ // if auto white calculation from RGB is disabled/optional (None/Dual), allow white channel adjustments
+ if ( whiteSlider) capabilities |= SEG_CAPABILITY_W;
}
- if (correctWB && type != TYPE_ANALOG_1CH) capabilities |= 0x04; //white balance correction (uses CCT slider)
- uint8_t aWM = Bus::getAutoWhiteMode()<255 ? Bus::getAutoWhiteMode() : bus->getAWMode();
- bool whiteSlider = (aWM == RGBW_MODE_DUAL || aWM == RGBW_MODE_MANUAL_ONLY); // white slider allowed
- if (bus->isRgbw() && (whiteSlider || !(capabilities & 0x01))) capabilities |= 0x08; // allow white channel adjustments (AWM allows or is not RGB)
}
_capabilities = capabilities;
}
@@ -1080,7 +1183,7 @@ void Segment::blur(uint8_t blur_amount)
* The colours are a transition r -> g -> b -> back to r
* Inspired by the Adafruit examples.
*/
-uint32_t Segment::color_wheel(uint8_t pos) { // TODO
+uint32_t Segment::color_wheel(uint8_t pos) {
if (palette) return color_from_palette(pos, false, true, 0);
pos = 255 - pos;
if(pos < 85) {
@@ -1113,7 +1216,7 @@ uint8_t Segment::get_random_wheel_index(uint8_t pos) {
* Gets a single color from the currently selected palette.
* @param i Palette Index (if mapping is true, the full palette will be _virtualSegmentLength long, if false, 255). Will wrap around automatically.
* @param mapping if true, LED position in segment is considered for color
- * @param wrap FastLED palettes will usally wrap back to the start smoothly. Set false to get a hard edge
+ * @param wrap FastLED palettes will usually wrap back to the start smoothly. Set false to get a hard edge
* @param mcol If the default palette 0 is selected, return the standard color 0, 1 or 2 instead. If >2, Party palette is used instead
* @param pbri Value to scale the brightness of the returned color by. Default is 255. (no scaling)
* @returns Single color from palette
@@ -1150,27 +1253,31 @@ uint8_t * Segment::getAudioPalette(int pal) {
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[2];
- static uint8_t xyz[12]; // Needs to be 4 times however many colors are being used.
+ static uint8_t xyz[16]; // Needs to be 4 times however many colors are being used.
// 3 colors = 12, 4 colors = 16, etc.
- CRGB rgb = getCRGBForBand(0, fftResult, pal);
-
xyz[0] = 0; // anchor of first color - must be zero
- xyz[1] = rgb.r;
- xyz[2] = rgb.g;
- xyz[3] = rgb.b;
-
- rgb = getCRGBForBand(4, fftResult, pal);
- xyz[4] = 128;
+ xyz[1] = 0;
+ xyz[2] = 0;
+ xyz[3] = 0;
+
+ CRGB rgb = getCRGBForBand(1, fftResult, pal);
+ xyz[4] = 1; // anchor of first color
xyz[5] = rgb.r;
xyz[6] = rgb.g;
xyz[7] = rgb.b;
- rgb = getCRGBForBand(8, fftResult, pal);
- xyz[8] = 255; // anchor of last color - must be 255
+ rgb = getCRGBForBand(4, fftResult, pal);
+ xyz[8] = 128;
xyz[9] = rgb.r;
xyz[10] = rgb.g;
xyz[11] = rgb.b;
+
+ rgb = getCRGBForBand(8, fftResult, pal);
+ xyz[12] = 255; // anchor of last color - must be 255
+ xyz[13] = rgb.r;
+ xyz[14] = rgb.g;
+ xyz[15] = rgb.b;
return xyz;
}
@@ -1180,6 +1287,29 @@ uint8_t * Segment::getAudioPalette(int pal) {
// WS2812FX class implementation
///////////////////////////////////////////////////////////////////////////////
+//WLEDMM from
+void WS2812FX::enumerateLedmaps() {
+ ledMaps = 1;
+ for (size_t i=1; i<10; i++) {
+ char fileName[16];
+ sprintf_P(fileName, PSTR("/ledmap%d.json"), i);
+ bool isFile = WLED_FS.exists(fileName);
+ if (isFile) ledMaps |= 1 << i;
+ }
+ //WLEDMM add segment names to be used as ledmap names
+ uint8_t segment_index = 0;
+ for (segment &seg : _segments) {
+ if (seg.name != nullptr && strcmp(seg.name, "") != 0) {
+ char fileName[32];
+ sprintf_P(fileName, PSTR("/lm%s.json"), seg.name);
+ bool isFile = WLED_FS.exists(fileName);
+ if (isFile) ledMaps |= 1 << (10+segment_index);
+ }
+ segment_index++;
+ }
+}
+
+
//do not call this method from system context (network callback)
void WS2812FX::finalizeInit(void)
{
@@ -1204,13 +1334,13 @@ void WS2812FX::finalizeInit(void)
const uint8_t defNumBusses = ((sizeof defDataPins) / (sizeof defDataPins[0]));
const uint8_t defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0]));
uint16_t prevLen = 0;
- for (uint8_t i = 0; i < defNumBusses && i < WLED_MAX_BUSSES; i++) {
+ for (uint8_t i = 0; i < defNumBusses && i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) {
uint8_t defPin[] = {defDataPins[i]};
uint16_t start = prevLen;
uint16_t count = defCounts[(i < defNumCounts) ? i : defNumCounts -1];
prevLen += count;
BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, DEFAULT_LED_COLOR_ORDER, false, 0, RGBW_MODE_MANUAL_ONLY);
- busses.add(defCfg);
+ if (busses.add(defCfg) == -1) break;
}
}
@@ -1220,7 +1350,7 @@ void WS2812FX::finalizeInit(void)
if (bus == nullptr) continue;
if (bus->getStart() + bus->getLength() > MAX_LEDS) break;
//RGBW mode is enabled if at least one of the strips is RGBW
- _hasWhiteChannel |= bus->isRgbw();
+ _hasWhiteChannel |= bus->hasWhite();
//refresh is required to remain off if at least one of the strips requires the refresh.
_isOffRefreshRequired |= bus->isOffRefreshRequired();
uint16_t busEnd = bus->getStart() + bus->getLength();
@@ -1234,6 +1364,11 @@ void WS2812FX::finalizeInit(void)
#endif
}
+ if (!isMatrix) { // if 2D then max values defined in setUpMatrix() using panel set-up
+ Segment::maxWidth = _length;
+ Segment::maxHeight = 1;
+ }
+
//initialize leds array. TBD: realloc if nr of leds change
if (Segment::_globalLeds) {
purgeSegments(true);
@@ -1291,7 +1426,7 @@ void WS2812FX::service() {
//if (seg.transitional && seg._modeP) (*_mode[seg._modeP])(progress());
delay = (*_mode[seg.currentMode(seg.mode)])();
if (seg.mode != FX_MODE_HALLOWEEN_EYES) seg.call++;
- if (seg.transitional && delay > FRAMETIME) delay = FRAMETIME; // foce faster updates during transition
+ if (seg.transitional && delay > FRAMETIME) delay = FRAMETIME; // force faster updates during transition
seg.handleTransition();
}
@@ -1332,7 +1467,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
//Stay safe with high amperage and have a reasonable safety margin!
//I am NOT to be held liable for burned down garages!
-//fine tune power estimation constants for your setup
+//fine tune power estimation constants for your setup
#define MA_FOR_ESP 100 //how much mA does the ESP use (Wemos D1 about 80mA, ESP32 about 120mA)
//you can set it to 0 if the ESP is powered by USB and the LEDs by external
@@ -1382,7 +1517,7 @@ void WS2812FX::estimateCurrentAndLimitBri() {
}
}
- if (bus->isRgbw()) { //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less
+ if (bus->hasWhite()) { //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less
busPowerSum *= 3;
busPowerSum = busPowerSum >> 2; //same as /= 4
}
@@ -1391,7 +1526,7 @@ void WS2812FX::estimateCurrentAndLimitBri() {
uint32_t powerSum0 = powerSum;
powerSum *= _brightness;
-
+
if (powerSum > powerBudget) //scale brightness down to stay in current limit
{
float scale = (float)powerBudget / (float)powerSum;
@@ -1415,7 +1550,7 @@ void WS2812FX::show(void) {
if (callback) callback();
estimateCurrentAndLimitBri();
-
+
// some buses send asynchronously and this method will return before
// all of the data has been sent.
// See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods
@@ -1452,7 +1587,7 @@ void WS2812FX::setTargetFps(uint8_t fps) {
void WS2812FX::setMode(uint8_t segid, uint8_t m) {
if (segid >= _segments.size()) return;
-
+
if (m >= getModeCount()) m = getModeCount() - 1;
if (_segments[segid].mode != m) {
@@ -1550,12 +1685,7 @@ bool WS2812FX::hasRGBWBus(void) {
for (size_t b = 0; b < busses.getNumBusses(); b++) {
Bus *bus = busses.getBus(b);
if (bus == nullptr || bus->getLength()==0) break;
- switch (bus->getType()) {
- case TYPE_SK6812_RGBW:
- case TYPE_TM1814:
- case TYPE_ANALOG_4CH:
- return true;
- }
+ if (bus->hasRGB() && bus->hasWhite()) return true;
}
return false;
}
@@ -1596,69 +1726,37 @@ Segment& WS2812FX::getSegment(uint8_t id) {
void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing, uint16_t offset, uint16_t startY, uint16_t stopY) {
if (n >= _segments.size()) return;
- Segment& seg = _segments[n];
-
- //return if neither bounds nor grouping have changed
- bool boundsUnchanged = (seg.start == i1 && seg.stop == i2);
- if (isMatrix) {
- boundsUnchanged &= (seg.startY == startY && seg.stopY == stopY);
- }
- if (boundsUnchanged
- && (!grouping || (seg.grouping == grouping && seg.spacing == spacing))
- && (offset == UINT16_MAX || offset == seg.offset)) return;
-
- //if (seg.stop) setRange(seg.start, seg.stop -1, BLACK); //turn old segment range off
- if (seg.stop) seg.fill(BLACK); //turn old segment range off
- if (i2 <= i1) //disable segment
- {
- // disabled segments should get removed using purgeSegments()
- DEBUG_PRINT(F("-- Segment ")); DEBUG_PRINT(n); DEBUG_PRINTLN(F(" marked inactive."));
- seg.stop = 0;
- //if (seg.name) {
- // delete[] seg.name;
- // seg.name = nullptr;
- //}
- // if main segment is deleted, set first active as main segment
- if (n == _mainSegment) setMainSegmentId(0);
- seg.markForReset();
- return;
- }
- if (isMatrix) {
- #ifndef WLED_DISABLE_2D
- if (i1 < matrixWidth) seg.start = i1;
- seg.stop = i2 > matrixWidth ? matrixWidth : i2;
- if (startY < matrixHeight) seg.startY = startY;
- seg.stopY = stopY > matrixHeight ? matrixHeight : MAX(1,stopY);
- if (Segment::_globalLeds) seg.setUpLeds(); //WLEDMM force all effects to use globalleds
- #endif
- } else {
- if (i1 < _length) seg.start = i1;
- seg.stop = i2 > _length ? _length : i2;
- seg.startY = 0;
- seg.stopY = 1;
- }
- if (grouping) {
- seg.grouping = grouping;
- seg.spacing = spacing;
- }
- if (offset < UINT16_MAX) seg.offset = offset;
- seg.markForReset();
- if (!boundsUnchanged) seg.refreshLightCapabilities();
+ _segments[n].set(i1, i2, grouping, spacing, offset, startY, stopY);
}
void WS2812FX::restartRuntime() {
for (segment &seg : _segments) seg.markForReset();
}
-void WS2812FX::resetSegments() {
- _segments.clear(); // destructs all Segment as part of clearing
- #ifndef WLED_DISABLE_2D
- segment seg = isMatrix ? Segment(0, matrixWidth, 0, matrixHeight) : Segment(0, _length);
- #else
- segment seg = Segment(0, _length);
- #endif
- _segments.push_back(seg);
- _mainSegment = 0;
+void WS2812FX::resetSegments(bool boundsOnly) { //WLEDMM add boundsonly
+ if (!boundsOnly) {
+ _segments.clear(); // destructs all Segment as part of clearing
+ #ifndef WLED_DISABLE_2D
+ segment seg = isMatrix ? Segment(0, Segment::maxWidth, 0, Segment::maxHeight) : Segment(0, _length);
+ #else
+ segment seg = Segment(0, _length);
+ #endif
+ _segments.push_back(seg);
+ _mainSegment = 0;
+ } else { //WLEDMM boundsonly
+ for (segment &seg : _segments) {
+ #ifndef WLED_DISABLE_2D
+ seg.start = 0;
+ seg.stop = Segment::maxWidth;
+ seg.startY = 0;
+ seg.stopY = Segment::maxHeight;
+ #else
+ seg.start = 0;
+ seg.stop = _length;
+ #endif
+ }
+ }
+
}
void WS2812FX::makeAutoSegments(bool forceReset) {
@@ -1669,13 +1767,27 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
else if (getActiveSegmentsNum() == 1) {
size_t i = getLastActiveSegmentId();
_segments[i].start = 0;
- _segments[i].stop = matrixWidth;
+ _segments[i].stop = Segment::maxWidth;
_segments[i].startY = 0;
- _segments[i].stopY = matrixHeight;
+ _segments[i].stopY = Segment::maxHeight;
_segments[i].grouping = 1;
_segments[i].spacing = 0;
_mainSegment = i;
}
+ // do we have LEDs after the matrix? (ignore buses)
+ if (autoSegments && _length > Segment::maxWidth*Segment::maxHeight /*&& getActiveSegmentsNum() == 2*/) {
+ if (_segments.size() == getLastActiveSegmentId()+1)
+ _segments.push_back(Segment(Segment::maxWidth*Segment::maxHeight, _length));
+ else {
+ size_t i = getLastActiveSegmentId() + 1;
+ _segments[i].start = Segment::maxWidth*Segment::maxHeight;
+ _segments[i].stop = _length;
+ _segments[i].startY = 0;
+ _segments[i].stopY = 1;
+ _segments[i].grouping = 1;
+ _segments[i].spacing = 0;
+ }
+ }
#endif
} else if (autoSegments) { //make one segment per bus
uint16_t segStarts[MAX_NUM_SEGMENTS] = {0};
@@ -1699,6 +1811,7 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
s++;
}
_segments.clear();
+ _segments.reserve(s); // prevent reallocations
for (size_t i = 0; i < s; i++) {
Segment seg = Segment(segStarts[i], segStops[i]);
seg.selected = true;
@@ -1746,8 +1859,7 @@ bool WS2812FX::checkSegmentAlignment() {
//After this function is called, setPixelColor() will use that segment (offsets, grouping, ... will apply)
//Note: If called in an interrupt (e.g. JSON API), original segment must be restored,
//otherwise it can lead to a crash on ESP32 because _segment_index is modified while in use by the main thread
-uint8_t WS2812FX::setPixelSegment(uint8_t n)
-{
+uint8_t WS2812FX::setPixelSegment(uint8_t n) {
uint8_t prevSegId = _segment_index;
if (n < _segments.size()) {
_segment_index = n;
@@ -1756,8 +1868,7 @@ uint8_t WS2812FX::setPixelSegment(uint8_t n)
return prevSegId;
}
-void WS2812FX::setRange(uint16_t i, uint16_t i2, uint32_t col)
-{
+void WS2812FX::setRange(uint16_t i, uint16_t i2, uint32_t col) {
if (i2 >= i)
{
for (uint16_t x = i; x <= i2; x++) setPixelColor(x, col);
@@ -1767,14 +1878,12 @@ void WS2812FX::setRange(uint16_t i, uint16_t i2, uint32_t col)
}
}
-void WS2812FX::setTransitionMode(bool t)
-{
+void WS2812FX::setTransitionMode(bool t) {
for (segment &seg : _segments) if (!seg.transitional) seg.startTransition(t ? _transitionDur : 0);
}
#ifdef WLED_DEBUG
-void WS2812FX::printSize()
-{
+void WS2812FX::printSize() {
size_t size = 0;
for (const Segment &seg : _segments) size += seg.getSize();
DEBUG_PRINTF("Segments: %d -> %uB\n", _segments.size(), size);
@@ -1785,8 +1894,7 @@ void WS2812FX::printSize()
}
#endif
-void WS2812FX::loadCustomPalettes()
-{
+void WS2812FX::loadCustomPalettes() {
byte tcp[72]; //support gradient palettes with up to 18 entries
CRGBPalette16 targetPalette;
customPalettes.clear(); // start fresh
@@ -1801,15 +1909,28 @@ void WS2812FX::loadCustomPalettes()
if (readObjectFromFile(fileName, nullptr, &pDoc)) {
JsonArray pal = pDoc[F("palette")];
- if (!pal.isNull() && pal.size()>7) { // not an empty palette (at least 2 entries)
- size_t palSize = MIN(pal.size(), 72);
- palSize -= palSize % 4; // make sure size is multiple of 4
- for (size_t i=0; i()<256; i+=4) {
- tcp[ i ] = (uint8_t) pal[ i ].as(); // index
- tcp[i+1] = (uint8_t) pal[i+1].as(); // R
- tcp[i+2] = (uint8_t) pal[i+2].as(); // G
- tcp[i+3] = (uint8_t) pal[i+3].as(); // B
- DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[i]), int(tcp[i+1]), int(tcp[i+2]), int(tcp[i+3]));
+ if (!pal.isNull() && pal.size()>4) { // not an empty palette (at least 2 entries)
+ if (pal[0].is() && pal[1].is()) {
+ // we have an array of index & hex strings
+ size_t palSize = MIN(pal.size(), 36);
+ palSize -= palSize % 2; // make sure size is multiple of 2
+ for (size_t i=0, j=0; i()<256; i+=2, j+=4) {
+ uint8_t rgbw[] = {0,0,0,0};
+ tcp[ j ] = (uint8_t) pal[ i ].as(); // index
+ colorFromHexString(rgbw, pal[i+1].as()); // will catch non-string entires
+ for (size_t c=0; c<3; c++) tcp[j+1+c] = rgbw[c]; // only use RGB component
+ DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[j]), int(tcp[j+1]), int(tcp[j+2]), int(tcp[j+3]));
+ }
+ } else {
+ size_t palSize = MIN(pal.size(), 72);
+ palSize -= palSize % 4; // make sure size is multiple of 4
+ for (size_t i=0; i()<256; i+=4) {
+ tcp[ i ] = (uint8_t) pal[ i ].as(); // index
+ tcp[i+1] = (uint8_t) pal[i+1].as(); // R
+ tcp[i+2] = (uint8_t) pal[i+2].as(); // G
+ tcp[i+3] = (uint8_t) pal[i+3].as(); // B
+ DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[i]), int(tcp[i+1]), int(tcp[i+2]), int(tcp[i+3]));
+ }
}
customPalettes.push_back(targetPalette.loadDynamicGradientPalette(tcp));
}
@@ -1825,14 +1946,28 @@ void WS2812FX::deserializeMap(uint8_t n) {
// WLEDMM: also supports isMatrix
char fileName[32];
- strcpy_P(fileName, PSTR("/ledmap"));
- if (n) sprintf(fileName +7, "%d", n);
- strcat(fileName, ".json");
- bool isFile = WLED_FS.exists(fileName);
+ //WLEDMM: als support segment name ledmaps
+ bool isFile = false;;
+ if (n<10) {
+ strcpy_P(fileName, PSTR("/ledmap"));
+ if (n) sprintf(fileName +7, "%d", n);
+ strcat(fileName, ".json");
+ isFile = WLED_FS.exists(fileName);
+ } else { //WLEDM add segment name as ledmap.name
+ uint8_t segment_index = 0;
+ for (segment &seg : _segments) {
+ if (n == 10 + segment_index && !isFile && seg.name != nullptr) {
+ sprintf_P(fileName, PSTR("/lm%s.json"), seg.name);
+ isFile = WLED_FS.exists(fileName);
+ }
+ if (isFile) break;
+ segment_index++;
+ }
+ }
if (!isFile) {
- // erase custom mapping if selecting nonexistent ledmap.json (n==0)
- if (!n && customMappingTable != nullptr) {
+ // erase custom mapping if selecting nonexistent ledmap.json (n==0) //WLEDM always erase if nonexistant
+ if (customMappingTable != nullptr) {
//WLEDMM: if isMatrix then not erase but back to matrix default
if (isMatrix)
setUpMatrix(true);
@@ -1840,6 +1975,7 @@ void WS2812FX::deserializeMap(uint8_t n) {
customMappingSize = 0;
delete[] customMappingTable;
customMappingTable = nullptr;
+ loadedLedmap = 0;
}
}
return;
@@ -1847,8 +1983,8 @@ void WS2812FX::deserializeMap(uint8_t n) {
if (!requestJSONBufferLock(7)) return;
- DEBUG_PRINT(F("Reading LED map from "));
- DEBUG_PRINTLN(fileName);
+ USER_PRINT(F("Reading LED map from ")); //WLEDMM use USER_PRINT
+ USER_PRINTLN(fileName);
if (!readObjectFromFile(fileName, nullptr, &doc)) {
releaseJSONBufferLock();
@@ -1860,6 +1996,7 @@ void WS2812FX::deserializeMap(uint8_t n) {
customMappingSize = 0;
delete[] customMappingTable;
customMappingTable = nullptr;
+ loadedLedmap = 0;
}
JsonArray map = doc[F("map")];
@@ -1867,14 +2004,24 @@ void WS2812FX::deserializeMap(uint8_t n) {
//WLEDMM: if isMatrix then customMap size is whole matrix
#ifndef WLED_DISABLE_2D
if (isMatrix)
- customMappingSize = matrixWidth * matrixHeight;
+ customMappingSize = Segment::maxWidth * Segment::maxHeight; //as whole matrix will be stored in setUpMatrix
else
#endif
customMappingSize = map.size();
customMappingTable = new uint16_t[customMappingSize];
- for (uint16_t i=0; igetLastChangedProperty();
-
+
if (m == EspalexaDeviceProperty::on)
{
if (dev->getId() == 0) // Device 0 is for on/off or macros
@@ -56,7 +56,7 @@ void onAlexaChange(EspalexaDevice* dev)
bri = briLast;
stateUpdated(CALL_MODE_ALEXA);
}
- } else
+ } else
{
applyPreset(macroAlexaOn, CALL_MODE_ALEXA);
if (bri == 0) dev->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on
@@ -82,7 +82,7 @@ void onAlexaChange(EspalexaDevice* dev)
bri = 0;
stateUpdated(CALL_MODE_ALEXA);
}
- } else
+ } else
{
applyPreset(macroAlexaOff, CALL_MODE_ALEXA);
// below for loop stops Alexa from complaining if macroAlexaOff does not actually turn off
diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp
new file mode 100644
index 00000000..91692b5b
--- /dev/null
+++ b/wled00/bus_manager.cpp
@@ -0,0 +1,566 @@
+/*
+ * Class implementation for addressing various light types
+ */
+
+#include
+#include
+#include "const.h"
+#include "pin_manager.h"
+#include "bus_wrapper.h"
+#include "bus_manager.h"
+
+//colors.cpp
+uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb);
+uint16_t approximateKelvinFromRGB(uint32_t rgb);
+void colorRGBtoRGBW(byte* rgb);
+
+//udp.cpp
+uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, uint8_t bri=255, bool isRGBW=false);
+
+// enable additional debug output
+#if defined(WLED_DEBUG_HOST)
+ #include "net_debug.h"
+ #define DEBUGOUT NetDebug
+#else
+ #define DEBUGOUT Serial
+#endif
+
+#ifdef WLED_DEBUG
+ #ifndef ESP8266
+ #include
+ #endif
+ #define DEBUG_PRINT(x) DEBUGOUT.print(x)
+ #define DEBUG_PRINTLN(x) DEBUGOUT.println(x)
+ #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x)
+#else
+ #define DEBUG_PRINT(x)
+ #define DEBUG_PRINTLN(x)
+ #define DEBUG_PRINTF(x...)
+#endif
+
+//color mangling macros
+#define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b))))
+#define R(c) (byte((c) >> 16))
+#define G(c) (byte((c) >> 8))
+#define B(c) (byte(c))
+#define W(c) (byte((c) >> 24))
+
+
+void ColorOrderMap::add(uint16_t start, uint16_t len, uint8_t colorOrder) {
+ if (_count >= WLED_MAX_COLOR_ORDER_MAPPINGS) {
+ return;
+ }
+ if (len == 0) {
+ return;
+ }
+ if (colorOrder > COL_ORDER_MAX) {
+ return;
+ }
+ _mappings[_count].start = start;
+ _mappings[_count].len = len;
+ _mappings[_count].colorOrder = colorOrder;
+ _count++;
+}
+
+uint8_t IRAM_ATTR ColorOrderMap::getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const {
+ if (_count == 0) return defaultColorOrder;
+ // upper nibble containd W swap information
+ uint8_t swapW = defaultColorOrder >> 4;
+ for (uint8_t i = 0; i < _count; i++) {
+ if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) {
+ return _mappings[i].colorOrder | (swapW << 4);
+ }
+ }
+ return defaultColorOrder;
+}
+
+
+uint32_t Bus::autoWhiteCalc(uint32_t c) {
+ uint8_t aWM = _autoWhiteMode;
+ if (_gAWM < 255) aWM = _gAWM;
+ if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
+ uint8_t w = W(c);
+ //ignore auto-white calculation if w>0 and mode DUAL (DUAL behaves as BRIGHTER if w==0)
+ if (w > 0 && aWM == RGBW_MODE_DUAL) return c;
+ uint8_t r = R(c);
+ uint8_t g = G(c);
+ uint8_t b = B(c);
+ if (aWM == RGBW_MODE_MAX) return RGBW32(r, g, b, r > g ? (r > b ? r : b) : (g > b ? g : b)); // brightest RGB channel
+ w = r < g ? (r < b ? r : b) : (g < b ? g : b);
+ if (aWM == RGBW_MODE_AUTO_ACCURATE) { r -= w; g -= w; b -= w; } //subtract w in ACCURATE mode
+ return RGBW32(r, g, b, w);
+}
+
+
+BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bus(bc.type, bc.start, bc.autoWhite), _colorOrderMap(com) {
+ if (!IS_DIGITAL(bc.type) || !bc.count) return;
+ if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
+ _pins[0] = bc.pins[0];
+ if (IS_2PIN(bc.type)) {
+ if (!pinManager.allocatePin(bc.pins[1], true, PinOwner::BusDigital)) {
+ cleanup(); return;
+ }
+ _pins[1] = bc.pins[1];
+ }
+ reversed = bc.reversed;
+ _needsRefresh = bc.refreshReq || bc.type == TYPE_TM1814;
+ _skip = bc.skipAmount; //sacrificial pixels
+ _len = bc.count + _skip;
+ _iType = PolyBus::getI(bc.type, _pins, nr);
+ if (_iType == I_NONE) return;
+ uint16_t lenToCreate = _len;
+ if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(_len); // only needs a third of "RGB" LEDs for NeoPixelBus
+ _busPtr = PolyBus::create(_iType, _pins, lenToCreate, nr);
+ _valid = (_busPtr != nullptr);
+ _colorOrder = bc.colorOrder;
+ DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n", _valid?"S":"Uns", nr, _len, bc.type, _pins[0],_pins[1],_iType);
+}
+
+void BusDigital::show() {
+ PolyBus::show(_busPtr, _iType);
+}
+
+bool BusDigital::canShow() {
+ return PolyBus::canShow(_busPtr, _iType);
+}
+
+void BusDigital::setBrightness(uint8_t b) {
+ //Fix for turning off onboard LED breaking bus
+ #ifdef LED_BUILTIN
+ if (_bri == 0 && b > 0) {
+ if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType, _pins);
+ }
+ #endif
+ Bus::setBrightness(b);
+ PolyBus::setBrightness(_busPtr, _iType, b);
+}
+
+//If LEDs are skipped, it is possible to use the first as a status LED.
+//TODO only show if no new show due in the next 50ms
+void BusDigital::setStatusPixel(uint32_t c) {
+ if (_skip && canShow()) {
+ PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrderMap.getPixelColorOrder(_start, _colorOrder));
+ PolyBus::show(_busPtr, _iType);
+ }
+}
+
+void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
+ if (_type == TYPE_SK6812_RGBW || _type == TYPE_TM1814 || _type == TYPE_WS2812_1CH_X3) c = autoWhiteCalc(c);
+ if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
+ if (reversed) pix = _len - pix -1;
+ else pix += _skip;
+ uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
+ if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
+ uint16_t pOld = pix;
+ pix = IC_INDEX_WS2812_1CH_3X(pix);
+ uint32_t cOld = PolyBus::getPixelColor(_busPtr, _iType, pix, co);
+ switch (pOld % 3) { // change only the single channel (TODO: this can cause loss because of get/set)
+ case 0: c = RGBW32(R(cOld), W(c) , B(cOld), 0); break;
+ case 1: c = RGBW32(W(c) , G(cOld), B(cOld), 0); break;
+ case 2: c = RGBW32(R(cOld), G(cOld), W(c) , 0); break;
+ }
+ }
+ PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
+}
+
+uint32_t BusDigital::getPixelColor(uint16_t pix) {
+ if (reversed) pix = _len - pix -1;
+ else pix += _skip;
+ uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
+ if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
+ uint16_t pOld = pix;
+ pix = IC_INDEX_WS2812_1CH_3X(pix);
+ uint32_t c = PolyBus::getPixelColor(_busPtr, _iType, pix, co);
+ switch (pOld % 3) { // get only the single channel
+ case 0: c = RGBW32(G(c), G(c), G(c), G(c)); break;
+ case 1: c = RGBW32(R(c), R(c), R(c), R(c)); break;
+ case 2: c = RGBW32(B(c), B(c), B(c), B(c)); break;
+ }
+ return c;
+ }
+ return PolyBus::getPixelColor(_busPtr, _iType, pix, co);
+}
+
+uint8_t BusDigital::getPins(uint8_t* pinArray) {
+ uint8_t numPins = IS_2PIN(_type) ? 2 : 1;
+ for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i];
+ return numPins;
+}
+
+void BusDigital::setColorOrder(uint8_t colorOrder) {
+ // upper nibble contains W swap information
+ if ((colorOrder & 0x0F) > 5) return;
+ _colorOrder = colorOrder;
+}
+
+void BusDigital::reinit() {
+ PolyBus::begin(_busPtr, _iType, _pins);
+}
+
+void BusDigital::cleanup() {
+ DEBUG_PRINTLN(F("Digital Cleanup."));
+ PolyBus::cleanup(_busPtr, _iType);
+ _iType = I_NONE;
+ _valid = false;
+ _busPtr = nullptr;
+ pinManager.deallocatePin(_pins[1], PinOwner::BusDigital);
+ pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
+}
+
+
+BusPwm::BusPwm(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
+ _valid = false;
+ if (!IS_PWM(bc.type)) return;
+ uint8_t numPins = NUM_PWM_PINS(bc.type);
+
+ #ifdef ESP8266
+ analogWriteRange(255); //same range as one RGB channel
+ analogWriteFreq(WLED_PWM_FREQ);
+ #else
+ _ledcStart = pinManager.allocateLedc(numPins);
+ if (_ledcStart == 255) { //no more free LEDC channels
+ deallocatePins(); return;
+ }
+ #endif
+
+ for (uint8_t i = 0; i < numPins; i++) {
+ uint8_t currentPin = bc.pins[i];
+ if (!pinManager.allocatePin(currentPin, true, PinOwner::BusPwm)) {
+ deallocatePins(); return;
+ }
+ _pins[i] = currentPin; //store only after allocatePin() succeeds
+ #ifdef ESP8266
+ pinMode(_pins[i], OUTPUT);
+ #else
+ ledcSetup(_ledcStart + i, WLED_PWM_FREQ, 8);
+ ledcAttachPin(_pins[i], _ledcStart + i);
+ #endif
+ }
+ reversed = bc.reversed;
+ _valid = true;
+}
+
+void BusPwm::setPixelColor(uint16_t pix, uint32_t c) {
+ if (pix != 0 || !_valid) return; //only react to first pixel
+ if (_type != TYPE_ANALOG_3CH) c = autoWhiteCalc(c);
+ if (_cct >= 1900 && (_type == TYPE_ANALOG_3CH || _type == TYPE_ANALOG_4CH)) {
+ c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
+ }
+ uint8_t r = R(c);
+ uint8_t g = G(c);
+ uint8_t b = B(c);
+ uint8_t w = W(c);
+ uint8_t cct = 0; //0 - full warm white, 255 - full cold white
+ if (_cct > -1) {
+ if (_cct >= 1900) cct = (_cct - 1900) >> 5;
+ else if (_cct < 256) cct = _cct;
+ } else {
+ cct = (approximateKelvinFromRGB(c) - 1900) >> 5;
+ }
+
+ uint8_t ww, cw;
+ #ifdef WLED_USE_IC_CCT
+ ww = w;
+ cw = cct;
+ #else
+ //0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold)
+ if (cct < _cctBlend) ww = 255;
+ else ww = ((255-cct) * 255) / (255 - _cctBlend);
+
+ if ((255-cct) < _cctBlend) cw = 255;
+ else cw = (cct * 255) / (255 - _cctBlend);
+
+ ww = (w * ww) / 255; //brightness scaling
+ cw = (w * cw) / 255;
+ #endif
+
+ switch (_type) {
+ case TYPE_ANALOG_1CH: //one channel (white), relies on auto white calculation
+ _data[0] = w;
+ break;
+ case TYPE_ANALOG_2CH: //warm white + cold white
+ _data[1] = cw;
+ _data[0] = ww;
+ break;
+ case TYPE_ANALOG_5CH: //RGB + warm white + cold white
+ _data[4] = cw;
+ w = ww;
+ case TYPE_ANALOG_4CH: //RGBW
+ _data[3] = w;
+ case TYPE_ANALOG_3CH: //standard dumb RGB
+ _data[0] = r; _data[1] = g; _data[2] = b;
+ break;
+ }
+}
+
+//does no index check
+uint32_t BusPwm::getPixelColor(uint16_t pix) {
+ if (!_valid) return 0;
+ return RGBW32(_data[0], _data[1], _data[2], _data[3]);
+}
+
+void BusPwm::show() {
+ if (!_valid) return;
+ uint8_t numPins = NUM_PWM_PINS(_type);
+ for (uint8_t i = 0; i < numPins; i++) {
+ uint8_t scaled = (_data[i] * _bri) / 255;
+ if (reversed) scaled = 255 - scaled;
+ #ifdef ESP8266
+ analogWrite(_pins[i], scaled);
+ #else
+ ledcWrite(_ledcStart + i, scaled);
+ #endif
+ }
+}
+
+uint8_t BusPwm::getPins(uint8_t* pinArray) {
+ if (!_valid) return 0;
+ uint8_t numPins = NUM_PWM_PINS(_type);
+ for (uint8_t i = 0; i < numPins; i++) {
+ pinArray[i] = _pins[i];
+ }
+ return numPins;
+}
+
+void BusPwm::deallocatePins() {
+ uint8_t numPins = NUM_PWM_PINS(_type);
+ for (uint8_t i = 0; i < numPins; i++) {
+ pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
+ if (!pinManager.isPinOk(_pins[i])) continue;
+ #ifdef ESP8266
+ digitalWrite(_pins[i], LOW); //turn off PWM interrupt
+ #else
+ if (_ledcStart < 16) ledcDetachPin(_pins[i]);
+ #endif
+ }
+ #ifdef ARDUINO_ARCH_ESP32
+ pinManager.deallocateLedc(_ledcStart, numPins);
+ #endif
+}
+
+
+BusOnOff::BusOnOff(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
+ _valid = false;
+ if (bc.type != TYPE_ONOFF) return;
+
+ uint8_t currentPin = bc.pins[0];
+ if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
+ return;
+ }
+ _pin = currentPin; //store only after allocatePin() succeeds
+ pinMode(_pin, OUTPUT);
+ reversed = bc.reversed;
+ _valid = true;
+}
+
+void BusOnOff::setPixelColor(uint16_t pix, uint32_t c) {
+ if (pix != 0 || !_valid) return; //only react to first pixel
+ c = autoWhiteCalc(c);
+ uint8_t r = R(c);
+ uint8_t g = G(c);
+ uint8_t b = B(c);
+ uint8_t w = W(c);
+
+ _data = bool((r+g+b+w) && _bri) ? 0xFF : 0;
+}
+
+uint32_t BusOnOff::getPixelColor(uint16_t pix) {
+ if (!_valid) return 0;
+ return RGBW32(_data, _data, _data, _data);
+}
+
+void BusOnOff::show() {
+ if (!_valid) return;
+ digitalWrite(_pin, reversed ? !(bool)_data : (bool)_data);
+}
+
+uint8_t BusOnOff::getPins(uint8_t* pinArray) {
+ if (!_valid) return 0;
+ pinArray[0] = _pin;
+ return 1;
+}
+
+
+BusNetwork::BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
+ _valid = false;
+ switch (bc.type) {
+ case TYPE_NET_ARTNET_RGB:
+ _rgbw = false;
+ _UDPtype = 2;
+ break;
+ case TYPE_NET_E131_RGB:
+ _rgbw = false;
+ _UDPtype = 1;
+ break;
+ case TYPE_NET_DDP_RGB:
+ _rgbw = false;
+ _UDPtype = 0;
+ break;
+ default: // TYPE_NET_DDP_RGB / TYPE_NET_DDP_RGBW
+ _rgbw = bc.type == TYPE_NET_DDP_RGBW;
+ _UDPtype = 0;
+ break;
+ }
+ _UDPchannels = _rgbw ? 4 : 3;
+ _data = (byte *)malloc(bc.count * _UDPchannels);
+ if (_data == nullptr) return;
+ memset(_data, 0, bc.count * _UDPchannels);
+ _len = bc.count;
+ _client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
+ _broadcastLock = false;
+ _valid = true;
+}
+
+void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
+ if (!_valid || pix >= _len) return;
+ if (hasWhite()) c = autoWhiteCalc(c);
+ if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
+ uint16_t offset = pix * _UDPchannels;
+ _data[offset] = R(c);
+ _data[offset+1] = G(c);
+ _data[offset+2] = B(c);
+ if (_rgbw) _data[offset+3] = W(c);
+}
+
+uint32_t BusNetwork::getPixelColor(uint16_t pix) {
+ if (!_valid || pix >= _len) return 0;
+ uint16_t offset = pix * _UDPchannels;
+ return RGBW32(_data[offset], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
+}
+
+void BusNetwork::show() {
+ if (!_valid || !canShow()) return;
+ _broadcastLock = true;
+ realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
+ _broadcastLock = false;
+}
+
+uint8_t BusNetwork::getPins(uint8_t* pinArray) {
+ for (uint8_t i = 0; i < 4; i++) {
+ pinArray[i] = _client[i];
+ }
+ return 4;
+}
+
+void BusNetwork::cleanup() {
+ _type = I_NONE;
+ _valid = false;
+ if (_data != nullptr) free(_data);
+ _data = nullptr;
+}
+
+
+//utility to get the approx. memory usage of a given BusConfig
+uint32_t BusManager::memUsage(BusConfig &bc) {
+ uint8_t type = bc.type;
+ uint16_t len = bc.count + bc.skipAmount;
+ if (type > 15 && type < 32) {
+ #ifdef ESP8266
+ if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
+ if (type > 29) return len*20; //RGBW
+ return len*15;
+ }
+ if (type > 29) return len*4; //RGBW
+ return len*3;
+ #else //ESP32 RMT uses double buffer?
+ if (type > 29) return len*8; //RGBW
+ return len*6;
+ #endif
+ }
+ if (type > 31 && type < 48) return 5;
+ if (type == 44 || type == 45) return len*4; //RGBW
+ return len*3; //RGB
+}
+
+int BusManager::add(BusConfig &bc) {
+ if (getNumBusses() - getNumVirtualBusses() >= WLED_MAX_BUSSES) return -1;
+ if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) {
+ busses[numBusses] = new BusNetwork(bc);
+ } else if (IS_DIGITAL(bc.type)) {
+ busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
+ } else if (bc.type == TYPE_ONOFF) {
+ busses[numBusses] = new BusOnOff(bc);
+ } else {
+ busses[numBusses] = new BusPwm(bc);
+ }
+ return numBusses++;
+}
+
+//do not call this method from system context (network callback)
+void BusManager::removeAll() {
+ DEBUG_PRINTLN(F("Removing all."));
+ //prevents crashes due to deleting busses while in use.
+ while (!canAllShow()) yield();
+ for (uint8_t i = 0; i < numBusses; i++) delete busses[i];
+ numBusses = 0;
+}
+
+void BusManager::show() {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ busses[i]->show();
+ }
+}
+
+void BusManager::setStatusPixel(uint32_t c) {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ busses[i]->setStatusPixel(c);
+ }
+}
+
+void IRAM_ATTR BusManager::setPixelColor(uint16_t pix, uint32_t c, int16_t cct) {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ Bus* b = busses[i];
+ uint16_t bstart = b->getStart();
+ if (pix < bstart || pix >= bstart + b->getLength()) continue;
+ busses[i]->setPixelColor(pix - bstart, c);
+ }
+}
+
+void BusManager::setBrightness(uint8_t b) {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ busses[i]->setBrightness(b);
+ }
+}
+
+void BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) {
+ if (cct > 255) cct = 255;
+ if (cct >= 0) {
+ //if white balance correction allowed, save as kelvin value instead of 0-255
+ if (allowWBCorrection) cct = 1900 + (cct << 5);
+ } else cct = -1;
+ Bus::setCCT(cct);
+}
+
+uint32_t BusManager::getPixelColor(uint16_t pix) {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ Bus* b = busses[i];
+ uint16_t bstart = b->getStart();
+ if (pix < bstart || pix >= bstart + b->getLength()) continue;
+ return b->getPixelColor(pix - bstart);
+ }
+ return 0;
+}
+
+bool BusManager::canAllShow() {
+ for (uint8_t i = 0; i < numBusses; i++) {
+ if (!busses[i]->canShow()) return false;
+ }
+ return true;
+}
+
+Bus* BusManager::getBus(uint8_t busNr) {
+ if (busNr >= numBusses) return nullptr;
+ return busses[busNr];
+}
+
+//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
+uint16_t BusManager::getTotalLength() {
+ uint16_t len = 0;
+ for (uint8_t i=0; igetLength();
+ return len;
+}
+
+// Bus static member definition
+int16_t Bus::_cct = -1;
+uint8_t Bus::_cctBlend = 0;
+uint8_t Bus::_gAWM = 255;
\ No newline at end of file
diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h
index 5f604321..7b9bc6e4 100644
--- a/wled00/bus_manager.h
+++ b/wled00/bus_manager.h
@@ -6,44 +6,17 @@
*/
#include "const.h"
-#include "pin_manager.h"
-#include "bus_wrapper.h"
-#include
-
-//colors.cpp
-uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb);
-void colorRGBtoRGBW(byte* rgb);
-
-// enable additional debug output
-#if defined(WLED_DEBUG_HOST)
- #define DEBUGOUT NetDebug
-#else
- #define DEBUGOUT Serial
-#endif
-
-#ifdef WLED_DEBUG
- #ifndef ESP8266
- #include
- #endif
- #define DEBUG_PRINT(x) DEBUGOUT.print(x)
- #define DEBUG_PRINTLN(x) DEBUGOUT.println(x)
- #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x)
-#else
- #define DEBUG_PRINT(x)
- #define DEBUG_PRINTLN(x)
- #define DEBUG_PRINTF(x...)
-#endif
#define GET_BIT(var,bit) (((var)>>(bit))&0x01)
#define SET_BIT(var,bit) ((var)|=(uint16_t)(0x0001<<(bit)))
#define UNSET_BIT(var,bit) ((var)&=(~(uint16_t)(0x0001<<(bit))))
-//color mangling macros
-#define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b))))
-#define R(c) (byte((c) >> 16))
-#define G(c) (byte((c) >> 8))
-#define B(c) (byte(c))
-#define W(c) (byte((c) >> 24))
+#define NUM_ICS_WS2812_1CH_3X(len) (((len)+2)/3) // 1 WS2811 IC controls 3 zones (each zone has 1 LED, W)
+#define IC_INDEX_WS2812_1CH_3X(i) ((i)/3)
+
+#define NUM_ICS_WS2812_2CH_3X(len) (((len)+1)*2/3) // 2 WS2811 ICs control 3 zones (each zone has 2 LEDs, CW and WW)
+#define IC_INDEX_WS2812_2CH_3X(i) ((i)*2/3)
+#define WS2812_2CH_3X_SPANS_2_ICS(i) ((i)&0x01) // every other LED zone is on two different ICs
//temporary struct for passing bus configuration to bus
struct BusConfig {
@@ -88,53 +61,29 @@ struct ColorOrderMapEntry {
};
struct ColorOrderMap {
- void add(uint16_t start, uint16_t len, uint8_t colorOrder) {
- if (_count >= WLED_MAX_COLOR_ORDER_MAPPINGS) {
- return;
- }
- if (len == 0) {
- return;
- }
- if (colorOrder > COL_ORDER_MAX) {
- return;
- }
- _mappings[_count].start = start;
- _mappings[_count].len = len;
- _mappings[_count].colorOrder = colorOrder;
- _count++;
- }
+ void add(uint16_t start, uint16_t len, uint8_t colorOrder);
- uint8_t count() const {
- return _count;
- }
-
- void reset() {
- _count = 0;
- memset(_mappings, 0, sizeof(_mappings));
- }
-
- const ColorOrderMapEntry* get(uint8_t n) const {
- if (n > _count) {
- return nullptr;
+ uint8_t count() const {
+ return _count;
}
- return &(_mappings[n]);
- }
- inline uint8_t IRAM_ATTR getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const {
- if (_count == 0) return defaultColorOrder;
- // upper nibble containd W swap information
- uint8_t swapW = defaultColorOrder >> 4;
- for (uint8_t i = 0; i < _count; i++) {
- if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) {
- return _mappings[i].colorOrder | (swapW << 4);
+ void reset() {
+ _count = 0;
+ memset(_mappings, 0, sizeof(_mappings));
+ }
+
+ const ColorOrderMapEntry* get(uint8_t n) const {
+ if (n > _count) {
+ return nullptr;
}
+ return &(_mappings[n]);
}
- return defaultColorOrder;
- }
+
+ uint8_t getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const;
private:
- uint8_t _count;
- ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
+ uint8_t _count;
+ ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
};
//parent class of BusDigital, BusPwm, and BusNetwork
@@ -148,7 +97,7 @@ class Bus {
{
_type = type;
_start = start;
- _autoWhiteMode = Bus::isRgbw(_type) ? aw : RGBW_MODE_MANUAL_ONLY;
+ _autoWhiteMode = Bus::hasWhite(_type) ? aw : RGBW_MODE_MANUAL_ONLY;
};
virtual ~Bus() {} //throw the bus under the bus
@@ -172,20 +121,20 @@ class Bus {
inline bool isOffRefreshRequired() { return _needsRefresh; }
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; }
- virtual bool isRgbw() { return Bus::isRgbw(_type); }
- static bool isRgbw(uint8_t type) {
- if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true;
- if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true;
- if (type == TYPE_NET_DDP_RGBW) return true;
- return false;
- }
virtual bool hasRGB() {
- if (_type == TYPE_WS2812_1CH || _type == TYPE_WS2812_WWA || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
+ if ((_type >= TYPE_WS2812_1CH && _type <= TYPE_WS2812_WWA) || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
return true;
}
- virtual bool hasWhite() {
- if (_type == TYPE_SK6812_RGBW || _type == TYPE_TM1814 || _type == TYPE_WS2812_1CH || _type == TYPE_WS2812_WWA ||
- _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_4CH || _type == TYPE_ANALOG_5CH || _type == TYPE_NET_DDP_RGBW) return true;
+ virtual bool hasWhite() { return Bus::hasWhite(_type); }
+ static bool hasWhite(uint8_t type) {
+ if ((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true; // digital types with white channel
+ if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; // analog types with white channel
+ if (type == TYPE_NET_DDP_RGBW) return true; // network types with white channel
+ return false;
+ }
+ virtual bool hasCCT() {
+ if (_type == TYPE_WS2812_2CH_X3 || _type == TYPE_WS2812_WWA ||
+ _type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_5CH) return true;
return false;
}
static void setCCT(uint16_t cct) {
@@ -199,10 +148,10 @@ class Bus {
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
#endif
}
- inline void setAWMode(uint8_t m) { if (m < 4) _autoWhiteMode = m; }
- inline uint8_t getAWMode() { return _autoWhiteMode; }
- inline static void setAutoWhiteMode(uint8_t m) { if (m < 4) _gAWM = m; else _gAWM = 255; }
- inline static uint8_t getAutoWhiteMode() { return _gAWM; }
+ inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
+ inline uint8_t getAutoWhiteMode() { return _autoWhiteMode; }
+ inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
+ inline static uint8_t getGlobalAWMode() { return _gAWM; }
bool reversed = false;
@@ -214,440 +163,151 @@ class Bus {
bool _valid;
bool _needsRefresh;
uint8_t _autoWhiteMode;
- static uint8_t _gAWM; // definition in FX_fcn.cpp
- static int16_t _cct; // definition in FX_fcn.cpp
- static uint8_t _cctBlend; // definition in FX_fcn.cpp
-
- uint32_t autoWhiteCalc(uint32_t c) {
- uint8_t aWM = _autoWhiteMode;
- if (_gAWM < 255) aWM = _gAWM;
- if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
- uint8_t w = W(c);
- //ignore auto-white calculation if w>0 and mode DUAL (DUAL behaves as BRIGHTER if w==0)
- if (w > 0 && aWM == RGBW_MODE_DUAL) return c;
- uint8_t r = R(c);
- uint8_t g = G(c);
- uint8_t b = B(c);
- w = r < g ? (r < b ? r : b) : (g < b ? g : b);
- if (aWM == RGBW_MODE_AUTO_ACCURATE) { r -= w; g -= w; b -= w; } //subtract w in ACCURATE mode
- return RGBW32(r, g, b, w);
- }
+ static uint8_t _gAWM;
+ static int16_t _cct;
+ static uint8_t _cctBlend;
+
+ uint32_t autoWhiteCalc(uint32_t c);
};
class BusDigital : public Bus {
public:
- BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bus(bc.type, bc.start, bc.autoWhite), _colorOrderMap(com) {
- if (!IS_DIGITAL(bc.type) || !bc.count) return;
- if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
- _pins[0] = bc.pins[0];
- if (IS_2PIN(bc.type)) {
- if (!pinManager.allocatePin(bc.pins[1], true, PinOwner::BusDigital)) {
- cleanup(); return;
- }
- _pins[1] = bc.pins[1];
+ BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com);
+
+ inline void show();
+
+ bool canShow();
+
+ void setBrightness(uint8_t b);
+
+ void setStatusPixel(uint32_t c);
+
+ void setPixelColor(uint16_t pix, uint32_t c);
+
+ uint32_t getPixelColor(uint16_t pix);
+
+ uint8_t getColorOrder() {
+ return _colorOrder;
}
- reversed = bc.reversed;
- _needsRefresh = bc.refreshReq || bc.type == TYPE_TM1814;
- _skip = bc.skipAmount; //sacrificial pixels
- _len = bc.count + _skip;
- _iType = PolyBus::getI(bc.type, _pins, nr);
- if (_iType == I_NONE) return;
- _busPtr = PolyBus::create(_iType, _pins, _len, nr);
- _valid = (_busPtr != nullptr);
- _colorOrder = bc.colorOrder;
- DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n", _valid?"S":"Uns", nr, _len, bc.type, _pins[0],_pins[1],_iType);
- };
- inline void show() {
- PolyBus::show(_busPtr, _iType);
- }
-
- inline bool canShow() {
- return PolyBus::canShow(_busPtr, _iType);
- }
-
- void setBrightness(uint8_t b) {
- //Fix for turning off onboard LED breaking bus
- #ifdef LED_BUILTIN
- if (_bri == 0 && b > 0) {
- if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType, _pins);
+ uint16_t getLength() {
+ return _len - _skip;
}
- #endif
- Bus::setBrightness(b);
- PolyBus::setBrightness(_busPtr, _iType, b);
- }
- //If LEDs are skipped, it is possible to use the first as a status LED.
- //TODO only show if no new show due in the next 50ms
- void setStatusPixel(uint32_t c) {
- if (_skip && canShow()) {
- PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrderMap.getPixelColorOrder(_start, _colorOrder));
- PolyBus::show(_busPtr, _iType);
+ uint8_t getPins(uint8_t* pinArray);
+
+ void setColorOrder(uint8_t colorOrder);
+
+ uint8_t skippedLeds() {
+ return _skip;
}
- }
- void setPixelColor(uint16_t pix, uint32_t c) {
- if (_type == TYPE_SK6812_RGBW || _type == TYPE_TM1814) c = autoWhiteCalc(c);
- if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
- if (reversed) pix = _len - pix -1;
- else pix += _skip;
- PolyBus::setPixelColor(_busPtr, _iType, pix, c, _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder));
- }
+ void reinit();
- uint32_t getPixelColor(uint16_t pix) {
- if (reversed) pix = _len - pix -1;
- else pix += _skip;
- return PolyBus::getPixelColor(_busPtr, _iType, pix, _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder));
- }
+ void cleanup();
- inline uint8_t getColorOrder() {
- return _colorOrder;
- }
+ ~BusDigital() {
+ cleanup();
+ }
- uint16_t getLength() {
- return _len - _skip;
- }
-
- uint8_t getPins(uint8_t* pinArray) {
- uint8_t numPins = IS_2PIN(_type) ? 2 : 1;
- for (uint8_t i = 0; i < numPins; i++) pinArray[i] = _pins[i];
- return numPins;
- }
-
- void setColorOrder(uint8_t colorOrder) {
- // upper nibble contains W swap information
- if ((colorOrder & 0x0F) > 5) return;
- _colorOrder = colorOrder;
- }
-
- inline uint8_t skippedLeds() {
- return _skip;
- }
-
- inline void reinit() {
- PolyBus::begin(_busPtr, _iType, _pins);
- }
-
- void cleanup() {
- DEBUG_PRINTLN(F("Digital Cleanup."));
- PolyBus::cleanup(_busPtr, _iType);
- _iType = I_NONE;
- _valid = false;
- _busPtr = nullptr;
- pinManager.deallocatePin(_pins[1], PinOwner::BusDigital);
- pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
- }
-
- ~BusDigital() {
- cleanup();
- }
-
- private:
- uint8_t _colorOrder = COL_ORDER_GRB;
- uint8_t _pins[2] = {255, 255};
- uint8_t _iType = I_NONE;
- uint8_t _skip = 0;
- void * _busPtr = nullptr;
- const ColorOrderMap &_colorOrderMap;
+ private:
+ uint8_t _colorOrder = COL_ORDER_GRB;
+ uint8_t _pins[2] = {255, 255};
+ uint8_t _iType = 0; //I_NONE;
+ uint8_t _skip = 0;
+ void * _busPtr = nullptr;
+ const ColorOrderMap &_colorOrderMap;
};
class BusPwm : public Bus {
public:
- BusPwm(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
- _valid = false;
- if (!IS_PWM(bc.type)) return;
- uint8_t numPins = NUM_PWM_PINS(bc.type);
+ BusPwm(BusConfig &bc);
- #ifdef ESP8266
- analogWriteRange(255); //same range as one RGB channel
- analogWriteFreq(WLED_PWM_FREQ);
- #else
- _ledcStart = pinManager.allocateLedc(numPins);
- if (_ledcStart == 255) { //no more free LEDC channels
- deallocatePins(); return;
- }
- #endif
+ void setPixelColor(uint16_t pix, uint32_t c);
- for (uint8_t i = 0; i < numPins; i++) {
- uint8_t currentPin = bc.pins[i];
- if (!pinManager.allocatePin(currentPin, true, PinOwner::BusPwm)) {
- deallocatePins(); return;
- }
- _pins[i] = currentPin; //store only after allocatePin() succeeds
- #ifdef ESP8266
- pinMode(_pins[i], OUTPUT);
- #else
- ledcSetup(_ledcStart + i, WLED_PWM_FREQ, 8);
- ledcAttachPin(_pins[i], _ledcStart + i);
- #endif
- }
- reversed = bc.reversed;
- _valid = true;
- };
+ //does no index check
+ uint32_t getPixelColor(uint16_t pix);
- void setPixelColor(uint16_t pix, uint32_t c) {
- if (pix != 0 || !_valid) return; //only react to first pixel
- if (_type != TYPE_ANALOG_3CH) c = autoWhiteCalc(c);
- if (_cct >= 1900 && (_type == TYPE_ANALOG_3CH || _type == TYPE_ANALOG_4CH)) {
- c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
- }
- uint8_t r = R(c);
- uint8_t g = G(c);
- uint8_t b = B(c);
- uint8_t w = W(c);
- uint8_t cct = 0; //0 - full warm white, 255 - full cold white
- if (_cct > -1) {
- if (_cct >= 1900) cct = (_cct - 1900) >> 5;
- else if (_cct < 256) cct = _cct;
- } else {
- cct = (approximateKelvinFromRGB(c) - 1900) >> 5;
+ void show();
+
+ uint8_t getPins(uint8_t* pinArray);
+
+ void cleanup() {
+ deallocatePins();
}
- uint8_t ww, cw;
- #ifdef WLED_USE_IC_CCT
- ww = w;
- cw = cct;
- #else
- //0 - linear (CCT 127 = 50% warm, 50% cold), 127 - additive CCT blending (CCT 127 = 100% warm, 100% cold)
- if (cct < _cctBlend) ww = 255;
- else ww = ((255-cct) * 255) / (255 - _cctBlend);
-
- if ((255-cct) < _cctBlend) cw = 255;
- else cw = (cct * 255) / (255 - _cctBlend);
-
- ww = (w * ww) / 255; //brightness scaling
- cw = (w * cw) / 255;
- #endif
-
- switch (_type) {
- case TYPE_ANALOG_1CH: //one channel (white), relies on auto white calculation
- _data[0] = w;
- break;
- case TYPE_ANALOG_2CH: //warm white + cold white
- _data[1] = cw;
- _data[0] = ww;
- break;
- case TYPE_ANALOG_5CH: //RGB + warm white + cold white
- _data[4] = cw;
- w = ww;
- case TYPE_ANALOG_4CH: //RGBW
- _data[3] = w;
- case TYPE_ANALOG_3CH: //standard dumb RGB
- _data[0] = r; _data[1] = g; _data[2] = b;
- break;
+ ~BusPwm() {
+ cleanup();
}
- }
- //does no index check
- uint32_t getPixelColor(uint16_t pix) {
- if (!_valid) return 0;
- return RGBW32(_data[0], _data[1], _data[2], _data[3]);
- }
-
- void show() {
- if (!_valid) return;
- uint8_t numPins = NUM_PWM_PINS(_type);
- for (uint8_t i = 0; i < numPins; i++) {
- uint8_t scaled = (_data[i] * _bri) / 255;
- if (reversed) scaled = 255 - scaled;
- #ifdef ESP8266
- analogWrite(_pins[i], scaled);
- #else
- ledcWrite(_ledcStart + i, scaled);
- #endif
- }
- }
-
- uint8_t getPins(uint8_t* pinArray) {
- if (!_valid) return 0;
- uint8_t numPins = NUM_PWM_PINS(_type);
- for (uint8_t i = 0; i < numPins; i++) {
- pinArray[i] = _pins[i];
- }
- return numPins;
- }
-
- void cleanup() {
- deallocatePins();
- }
-
- ~BusPwm() {
- cleanup();
- }
-
- private:
- uint8_t _pins[5] = {255, 255, 255, 255, 255};
- uint8_t _data[5] = {0};
- #ifdef ARDUINO_ARCH_ESP32
- uint8_t _ledcStart = 255;
- #endif
-
- void deallocatePins() {
- uint8_t numPins = NUM_PWM_PINS(_type);
- for (uint8_t i = 0; i < numPins; i++) {
- pinManager.deallocatePin(_pins[i], PinOwner::BusPwm);
- if (!pinManager.isPinOk(_pins[i])) continue;
- #ifdef ESP8266
- digitalWrite(_pins[i], LOW); //turn off PWM interrupt
- #else
- if (_ledcStart < 16) ledcDetachPin(_pins[i]);
- #endif
- }
+ private:
+ uint8_t _pins[5] = {255, 255, 255, 255, 255};
+ uint8_t _data[5] = {0};
#ifdef ARDUINO_ARCH_ESP32
- pinManager.deallocateLedc(_ledcStart, numPins);
+ uint8_t _ledcStart = 255;
#endif
- }
+
+ void deallocatePins();
};
class BusOnOff : public Bus {
public:
- BusOnOff(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
- _valid = false;
- if (bc.type != TYPE_ONOFF) return;
+ BusOnOff(BusConfig &bc);
- uint8_t currentPin = bc.pins[0];
- if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
- return;
+ void setPixelColor(uint16_t pix, uint32_t c);
+
+ uint32_t getPixelColor(uint16_t pix);
+
+ void show();
+
+ uint8_t getPins(uint8_t* pinArray);
+
+ void cleanup() {
+ pinManager.deallocatePin(_pin, PinOwner::BusOnOff);
}
- _pin = currentPin; //store only after allocatePin() succeeds
- pinMode(_pin, OUTPUT);
- reversed = bc.reversed;
- _valid = true;
- };
- void setPixelColor(uint16_t pix, uint32_t c) {
- if (pix != 0 || !_valid) return; //only react to first pixel
- c = autoWhiteCalc(c);
- uint8_t r = R(c);
- uint8_t g = G(c);
- uint8_t b = B(c);
- uint8_t w = W(c);
+ ~BusOnOff() {
+ cleanup();
+ }
- _data = bool((r+g+b+w) && _bri) ? 0xFF : 0;
- }
-
- uint32_t getPixelColor(uint16_t pix) {
- if (!_valid) return 0;
- return RGBW32(_data, _data, _data, _data);
- }
-
- void show() {
- if (!_valid) return;
- digitalWrite(_pin, reversed ? !(bool)_data : (bool)_data);
- }
-
- uint8_t getPins(uint8_t* pinArray) {
- if (!_valid) return 0;
- pinArray[0] = _pin;
- return 1;
- }
-
- void cleanup() {
- pinManager.deallocatePin(_pin, PinOwner::BusOnOff);
- }
-
- ~BusOnOff() {
- cleanup();
- }
-
- private:
- uint8_t _pin = 255;
- uint8_t _data = 0;
+ private:
+ uint8_t _pin = 255;
+ uint8_t _data = 0;
};
class BusNetwork : public Bus {
public:
- BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
- _valid = false;
-// switch (bc.type) {
-// case TYPE_NET_ARTNET_RGB:
-// _rgbw = false;
-// _UDPtype = 2;
-// break;
-// case TYPE_NET_E131_RGB:
-// _rgbw = false;
-// _UDPtype = 1;
-// break;
-// case TYPE_NET_DDP_RGB:
-// _rgbw = false;
-// _UDPtype = 0;
-// break;
-// default: // TYPE_NET_DDP_RGB / TYPE_NET_DDP_RGBW
- _rgbw = bc.type == TYPE_NET_DDP_RGBW;
- _UDPtype = 0;
-// break;
-// }
- _UDPchannels = _rgbw ? 4 : 3;
- _data = (byte *)malloc(bc.count * _UDPchannels);
- if (_data == nullptr) return;
- memset(_data, 0, bc.count * _UDPchannels);
- _len = bc.count;
- _client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
- _broadcastLock = false;
- _valid = true;
- };
+ BusNetwork(BusConfig &bc);
- bool hasRGB() { return true; }
- bool hasWhite() { return _rgbw; }
+ bool hasRGB() { return true; }
+ bool hasWhite() { return _rgbw; }
- void setPixelColor(uint16_t pix, uint32_t c) {
- if (!_valid || pix >= _len) return;
- if (isRgbw()) c = autoWhiteCalc(c);
- if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
- uint16_t offset = pix * _UDPchannels;
- _data[offset] = R(c);
- _data[offset+1] = G(c);
- _data[offset+2] = B(c);
- if (_rgbw) _data[offset+3] = W(c);
- }
+ void setPixelColor(uint16_t pix, uint32_t c);
- uint32_t getPixelColor(uint16_t pix) {
- if (!_valid || pix >= _len) return 0;
- uint16_t offset = pix * _UDPchannels;
- return RGBW32(_data[offset], _data[offset+1], _data[offset+2], _rgbw ? (_data[offset+3] << 24) : 0);
- }
+ uint32_t getPixelColor(uint16_t pix);
- void show() {
- if (!_valid || !canShow()) return;
- _broadcastLock = true;
- realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
- _broadcastLock = false;
- }
+ void show();
- inline bool canShow() {
- // this should be a return value from UDP routine if it is still sending data out
- return !_broadcastLock;
- }
-
- uint8_t getPins(uint8_t* pinArray) {
- for (uint8_t i = 0; i < 4; i++) {
- pinArray[i] = _client[i];
+ bool canShow() {
+ // this should be a return value from UDP routine if it is still sending data out
+ return !_broadcastLock;
}
- return 4;
- }
- inline bool isRgbw() {
- return _rgbw;
- }
+ uint8_t getPins(uint8_t* pinArray);
- inline uint16_t getLength() {
- return _len;
- }
+ uint16_t getLength() {
+ return _len;
+ }
- void cleanup() {
- _type = I_NONE;
- _valid = false;
- if (_data != nullptr) free(_data);
- _data = nullptr;
- }
+ void cleanup();
- ~BusNetwork() {
- cleanup();
- }
+ ~BusNetwork() {
+ cleanup();
+ }
private:
IPAddress _client;
@@ -661,133 +321,56 @@ class BusNetwork : public Bus {
class BusManager {
public:
- BusManager() {};
+ BusManager() {};
- //utility to get the approx. memory usage of a given BusConfig
- static uint32_t memUsage(BusConfig &bc) {
- uint8_t type = bc.type;
- uint16_t len = bc.count + bc.skipAmount;
- if (type > 15 && type < 32) {
- #ifdef ESP8266
- if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
- if (type > 29) return len*20; //RGBW
- return len*15;
- }
- if (type > 29) return len*4; //RGBW
- return len*3;
- #else //ESP32 RMT uses double buffer?
- if (type > 29) return len*8; //RGBW
- return len*6;
- #endif
+ //utility to get the approx. memory usage of a given BusConfig
+ static uint32_t memUsage(BusConfig &bc);
+
+ int add(BusConfig &bc);
+
+ //do not call this method from system context (network callback)
+ void removeAll();
+
+ void show();
+
+ void setStatusPixel(uint32_t c);
+
+ void IRAM_ATTR setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1);
+
+ void setBrightness(uint8_t b);
+
+ void setSegmentCCT(int16_t cct, bool allowWBCorrection = false);
+
+ uint32_t getPixelColor(uint16_t pix);
+
+ bool canAllShow();
+
+ Bus* getBus(uint8_t busNr);
+
+ //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
+ uint16_t getTotalLength();
+
+ inline void updateColorOrderMap(const ColorOrderMap &com) {
+ memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap));
}
- if (type > 31 && type < 48) return 5;
- if (type == 44 || type == 45) return len*4; //RGBW
- return len*3; //RGB
- }
-
- int add(BusConfig &bc) {
- if (numBusses >= WLED_MAX_BUSSES) return -1;
- if (bc.type >= TYPE_NET_DDP_RGB && bc.type < 96) {
- busses[numBusses] = new BusNetwork(bc);
- } else if (IS_DIGITAL(bc.type)) {
- busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
- } else if (bc.type == TYPE_ONOFF) {
- busses[numBusses] = new BusOnOff(bc);
- } else {
- busses[numBusses] = new BusPwm(bc);
+
+ inline const ColorOrderMap& getColorOrderMap() const {
+ return colorOrderMap;
}
- return numBusses++;
- }
- //do not call this method from system context (network callback)
- void removeAll() {
- DEBUG_PRINTLN(F("Removing all."));
- //prevents crashes due to deleting busses while in use.
- while (!canAllShow()) yield();
- for (uint8_t i = 0; i < numBusses; i++) delete busses[i];
- numBusses = 0;
- }
-
- void show() {
- for (uint8_t i = 0; i < numBusses; i++) {
- busses[i]->show();
+ inline uint8_t getNumBusses() {
+ return numBusses;
}
- }
-
- void setStatusPixel(uint32_t c) {
- for (uint8_t i = 0; i < numBusses; i++) {
- busses[i]->setStatusPixel(c);
- }
- }
-
- void IRAM_ATTR setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1) {
- for (uint8_t i = 0; i < numBusses; i++) {
- Bus* b = busses[i];
- uint16_t bstart = b->getStart();
- if (pix < bstart || pix >= bstart + b->getLength()) continue;
- busses[i]->setPixelColor(pix - bstart, c);
- }
- }
-
- void setBrightness(uint8_t b) {
- for (uint8_t i = 0; i < numBusses; i++) {
- busses[i]->setBrightness(b);
- }
- }
-
- void setSegmentCCT(int16_t cct, bool allowWBCorrection = false) {
- if (cct > 255) cct = 255;
- if (cct >= 0) {
- //if white balance correction allowed, save as kelvin value instead of 0-255
- if (allowWBCorrection) cct = 1900 + (cct << 5);
- } else cct = -1;
- Bus::setCCT(cct);
- }
-
- uint32_t getPixelColor(uint16_t pix) {
- for (uint8_t i = 0; i < numBusses; i++) {
- Bus* b = busses[i];
- uint16_t bstart = b->getStart();
- if (pix < bstart || pix >= bstart + b->getLength()) continue;
- return b->getPixelColor(pix - bstart);
- }
- return 0;
- }
-
- bool canAllShow() {
- for (uint8_t i = 0; i < numBusses; i++) {
- if (!busses[i]->canShow()) return false;
- }
- return true;
- }
-
- Bus* getBus(uint8_t busNr) {
- if (busNr >= numBusses) return nullptr;
- return busses[busNr];
- }
-
- inline uint8_t getNumBusses() {
- return numBusses;
- }
-
- //semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
- uint16_t getTotalLength() {
- uint16_t len = 0;
- for (uint8_t i=0; igetLength();
- return len;
- }
-
- void updateColorOrderMap(const ColorOrderMap &com) {
- memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap));
- }
-
- const ColorOrderMap& getColorOrderMap() const {
- return colorOrderMap;
- }
private:
- uint8_t numBusses = 0;
- Bus* busses[WLED_MAX_BUSSES];
- ColorOrderMap colorOrderMap;
+ uint8_t numBusses = 0;
+ Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES];
+ ColorOrderMap colorOrderMap;
+
+ inline uint8_t getNumVirtualBusses() {
+ int j = 0;
+ for (int i=0; igetType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++;
+ return j;
+ }
};
-#endif
+#endif
\ No newline at end of file
diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h
index 1c2468d6..ac2a996a 100644
--- a/wled00/bus_wrapper.h
+++ b/wled00/bus_wrapper.h
@@ -699,7 +699,7 @@ class PolyBus {
}
};
static uint32_t getPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint8_t co) {
- RgbwColor col(0,0,0,0);
+ RgbwColor col(0,0,0,0);
switch (busType) {
case I_NONE: break;
#ifdef ESP8266
@@ -771,7 +771,7 @@ class PolyBus {
case I_HS_P98_3: col = (static_cast(busPtr))->GetPixelColor(pix); break;
case I_SS_P98_3: col = (static_cast(busPtr))->GetPixelColor(pix); break;
}
-
+
// upper nibble contains W swap information
uint8_t w = col.W;
switch (co >> 4) {
@@ -866,7 +866,7 @@ class PolyBus {
}
}
- //gives back the internal type index (I_XX_XXX_X above) for the input
+ //gives back the internal type index (I_XX_XXX_X above) for the input
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0) {
if (!IS_DIGITAL(busType)) return I_NONE;
if (IS_2PIN(busType)) { //SPI LED chips
@@ -894,6 +894,8 @@ class PolyBus {
uint8_t offset = pins[0] -1; //for driver: 0 = uart0, 1 = uart1, 2 = dma, 3 = bitbang
if (offset > 3) offset = 3;
switch (busType) {
+ case TYPE_WS2812_1CH_X3:
+ case TYPE_WS2812_2CH_X3:
case TYPE_WS2812_RGB:
case TYPE_WS2812_WWA:
return I_8266_U0_NEO_3 + offset;
@@ -926,6 +928,8 @@ class PolyBus {
if (num > 7) offset = num -7;
#endif
switch (busType) {
+ case TYPE_WS2812_1CH_X3:
+ case TYPE_WS2812_2CH_X3:
case TYPE_WS2812_RGB:
case TYPE_WS2812_WWA:
return I_32_RN_NEO_3 + offset;
diff --git a/wled00/button.cpp b/wled00/button.cpp
index b34e3c38..fce21424 100644
--- a/wled00/button.cpp
+++ b/wled00/button.cpp
@@ -24,12 +24,14 @@ void shortPressAction(uint8_t b)
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
}
+#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "short");
}
+#endif
}
void longPressAction(uint8_t b)
@@ -43,12 +45,14 @@ void longPressAction(uint8_t b)
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
}
+#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "long");
}
+#endif
}
void doublePressAction(uint8_t b)
@@ -62,12 +66,14 @@ void doublePressAction(uint8_t b)
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
}
+#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, "double");
}
+#endif
}
bool isButtonPressed(uint8_t i)
@@ -105,20 +111,21 @@ void handleSwitch(uint8_t b)
}
if (buttonLongPressed[b] == buttonPressedBefore[b]) return;
-
+
if (millis() - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
if (!buttonPressedBefore[b]) { // on -> off
if (macroButton[b]) applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
else { //turn on
if (!bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);}
- }
+ }
} else { // off -> on
if (macroLongPress[b]) applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
else { //turn off
if (bri) {toggleOnOff(); stateUpdated(CALL_MODE_BUTTON);}
- }
+ }
}
+#ifndef WLED_DISABLE_MQTT
// publish MQTT message
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
char subuf[64];
@@ -126,13 +133,14 @@ void handleSwitch(uint8_t b)
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
}
+#endif
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
}
}
#define ANALOG_BTN_READ_CYCLE 250 // min time between two analog reading cycles
-#define STRIP_WAIT_TIME 6 // max wait time in case of strip.isUpdating()
+#define STRIP_WAIT_TIME 6 // max wait time in case of strip.isUpdating()
#define POT_SMOOTHING 0.25f // smoothing factor for raw potentiometer readings
#define POT_SENSITIVITY 4 // changes below this amount are noise (POT scratching, or ADC noise)
@@ -165,7 +173,7 @@ void handleAnalog(uint8_t b)
//while(strip.isUpdating() && (millis() - wait_started < STRIP_WAIT_TIME)) {
// delay(1);
//}
- //if (strip.isUpdating()) return; // give up
+ //if (strip.isUpdating()) return; // give up
oldRead[b] = aRead;
@@ -326,7 +334,7 @@ void esp32RMTInvertIdle()
void handleIO()
{
handleButton();
-
+
//set relay when LEDs turn on
if (strip.getBrightness())
{
diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp
index 6849e273..ae9cee77 100644
--- a/wled00/cfg.cpp
+++ b/wled00/cfg.cpp
@@ -1,3 +1,6 @@
+#include // WLEDMM: make sure that I2C drivers have the "right" Wire Object
+#include
+
#include "wled.h"
#include "wled_ethernet.h"
@@ -64,7 +67,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (apHide > 1) apHide = 1;
CJSON(apBehavior, ap[F("behav")]);
-
+
/*
JsonArray ap_ip = ap["ip"];
for (byte i = 0; i < 4; i++) {
@@ -84,7 +87,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
uint8_t autoWhiteMode = RGBW_MODE_MANUAL_ONLY;
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
- Bus::setAutoWhiteMode(hw_led[F("rgbwm")] | 255);
+ Bus::setGlobalAWMode(hw_led[F("rgbwm")] | 255);
CJSON(correctWB, hw_led["cct"]);
CJSON(cctFromRgb, hw_led[F("cr")]);
CJSON(strip.cctBlending, hw_led[F("cb")]);
@@ -97,32 +100,45 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
JsonObject matrix = hw_led[F("matrix")];
if (!matrix.isNull()) {
strip.isMatrix = true;
- CJSON(strip.panelH, matrix[F("ph")]);
- CJSON(strip.panelW, matrix[F("pw")]);
- CJSON(strip.hPanels, matrix[F("mph")]);
- CJSON(strip.vPanels, matrix[F("mpv")]);
+ CJSON(strip.panels, matrix[F("mpc")]);
+ CJSON(strip.bOrA, matrix["ba"]); //WLEDMM basic or advanced
+ CJSON(strip.panelsV, matrix[F("mpv")]); //WLEDMM needs to be stored as well
+ CJSON(strip.panelsH, matrix[F("mph")]); //WLEDMM needs to be stored as well
CJSON(strip.matrix.bottomStart, matrix[F("pb")]);
CJSON(strip.matrix.rightStart, matrix[F("pr")]);
CJSON(strip.matrix.vertical, matrix[F("pv")]);
- CJSON(strip.matrix.serpentine, matrix[F("ps")]);
+ CJSON(strip.matrix.serpentine, matrix["ps"]);
+ CJSON(strip.panelO.bottomStart, matrix[F("pbl")]); //WLEDMM
+ CJSON(strip.panelO.rightStart, matrix[F("prl")]); //WLEDMM
+ CJSON(strip.panelO.vertical, matrix[F("pvl")]); //WLEDMM
+ CJSON(strip.panelO.serpentine, matrix["psl"]); //WLEDMM
+ strip.panel.clear();
JsonArray panels = matrix[F("panels")];
uint8_t s = 0;
if (!panels.isNull()) {
+ strip.panel.reserve(max(1U,min((size_t)strip.panels,(size_t)WLED_MAX_PANELS))); // pre-allocate memory for panels
for (JsonObject pnl : panels) {
- CJSON(strip.panel[s].bottomStart, pnl["b"]);
- CJSON(strip.panel[s].rightStart, pnl["r"]);
- CJSON(strip.panel[s].vertical, pnl["v"]);
- CJSON(strip.panel[s].serpentine, pnl["s"]);
- if (++s >= WLED_MAX_PANELS) break; // max panels reached
+ WS2812FX::Panel p;
+ CJSON(p.bottomStart, pnl["b"]);
+ CJSON(p.rightStart, pnl["r"]);
+ CJSON(p.vertical, pnl["v"]);
+ CJSON(p.serpentine, pnl["s"]);
+ CJSON(p.xOffset, pnl["x"]);
+ CJSON(p.yOffset, pnl["y"]);
+ CJSON(p.height, pnl["h"]);
+ CJSON(p.width, pnl["w"]);
+ strip.panel.push_back(p);
+ if (++s >= WLED_MAX_PANELS || s >= strip.panels) break; // max panels reached
}
- }
- // clear remaining panels
- for (; s= WLED_MAX_BUSSES) break;
+ if (s >= WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES) break;
uint8_t pins[5] = {255, 255, 255, 255, 255};
JsonArray pinArr = elm["pin"];
if (pinArr.size() == 0) continue;
@@ -161,7 +177,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (fromFS) {
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
mem += BusManager::memUsage(bc);
- if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
+ if (mem <= MAX_LED_MEMORY) if (busses.add(bc) == -1) break; // finalization will be done in WLED::beginStrip()
} else {
if (busConfigs[s] != nullptr) delete busConfigs[s];
busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
@@ -192,6 +208,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
// read multiple button configuration
JsonObject btn_obj = hw["btn"];
+ bool pull = btn_obj[F("pull")] | (!disablePullUp); // if true, pullup is enabled
+ disablePullUp = !pull;
JsonArray hw_btn_ins = btn_obj[F("ins")];
if (!hw_btn_ins.isNull()) {
uint8_t s = 0;
@@ -200,11 +218,28 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
int8_t pin = btn["pin"][0] | -1;
if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) {
btnPin[s] = pin;
- #ifdef ESP32
- pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP);
- #else
- pinMode(btnPin[s], INPUT_PULLUP);
- #endif
+ #ifdef ARDUINO_ARCH_ESP32
+ // ESP32 only: check that analog button pin is a valid ADC gpio
+ if (((buttonType[s] == BTN_TYPE_ANALOG) || (buttonType[s] == BTN_TYPE_ANALOG_INVERTED)) && (digitalPinToAnalogChannel(btnPin[s]) < 0))
+ {
+ // not an ADC analog pin
+ USER_PRINTF("PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin!\n", btnPin[s], s); // WLEDMM
+ btnPin[s] = -1;
+ pinManager.deallocatePin(pin,PinOwner::Button);
+ }
+ else
+ #endif
+ {
+ if (disablePullUp) {
+ pinMode(btnPin[s], INPUT);
+ } else {
+ #ifdef ESP32
+ pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP);
+ #else
+ pinMode(btnPin[s], INPUT_PULLUP);
+ #endif
+ }
+ }
} else {
btnPin[s] = -1;
}
@@ -228,7 +263,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
// relies upon only being called once with fromFS == true, which is currently true.
uint8_t s = 0;
if (pinManager.allocatePin(btnPin[0], false, PinOwner::Button)) { // initialized to #define value BTNPIN, or zero if not defined(!)
- ++s; // do not clear default button if allocated successfully
+ ++s; // do not clear default button if allocated successfully
}
for (; s 510) DMXAddress = 1;
+ CJSON(DMXSegmentSpacing, if_live_dmx[F("dss")]);
+ if (DMXSegmentSpacing > 150) DMXSegmentSpacing = 0;
CJSON(DMXMode, if_live_dmx["mode"]);
tdd = if_live[F("timeout")] | -1;
@@ -472,7 +508,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
uint8_t it = 0;
for (JsonObject timer : timers) {
if (it > 9) break;
- if (it<8 && timer[F("hour")]==255) it=8; // hour==255 -> sunrise/sunset
+ if (it<8 && timer[F("hour")]==255) it=8; // hour==255 -> sunrise/sunset
CJSON(timerHours[it], timer[F("hour")]);
CJSON(timerMinutes[it], timer["min"]);
CJSON(timerMacro[it], timer["macro"]);
@@ -673,29 +709,33 @@ void serializeConfig() {
hw_led[F("cr")] = cctFromRgb;
hw_led[F("cb")] = strip.cctBlending;
hw_led["fps"] = strip.getTargetFps();
- hw_led[F("rgbwm")] = Bus::getAutoWhiteMode(); // global override
+ hw_led[F("rgbwm")] = Bus::getGlobalAWMode(); // global auto white mode override
hw_led[F("ld")] = strip.useLedsArray;
#ifndef WLED_DISABLE_2D
// 2D Matrix Settings
if (strip.isMatrix) {
JsonObject matrix = hw_led.createNestedObject(F("matrix"));
- matrix[F("ph")] = strip.panelH;
- matrix[F("pw")] = strip.panelW;
- matrix[F("mph")] = strip.hPanels;
- matrix[F("mpv")] = strip.vPanels;
+ matrix[F("mpc")] = strip.panels;
+ matrix[F("ba")] = strip.bOrA; //WLEDMM basic or advanced
+ matrix[F("mph")] = strip.panelsH; //WLEDMM needs to be stored as well
+ matrix[F("mpv")] = strip.panelsV; //WLEDMM needs to be stored as well
matrix[F("pb")] = strip.matrix.bottomStart;
matrix[F("pr")] = strip.matrix.rightStart;
matrix[F("pv")] = strip.matrix.vertical;
- matrix[F("ps")] = strip.matrix.serpentine;
+ matrix["ps"] = strip.matrix.serpentine;
JsonArray panels = matrix.createNestedArray(F("panels"));
- for (uint8_t i=0; iskippedLeds();
ins["type"] = bus->getType() & 0x7F;
ins["ref"] = bus->isOffRefreshRequired();
- ins[F("rgbwm")] = bus->getAWMode();
+ ins[F("rgbwm")] = bus->getAutoWhiteMode();
}
JsonArray hw_com = hw.createNestedArray(F("com"));
@@ -735,6 +775,7 @@ void serializeConfig() {
// button(s)
JsonObject hw_btn = hw.createNestedObject("btn");
hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used)
+ hw_btn[F("pull")] = !disablePullUp;
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
// configuration for all buttons
@@ -837,6 +878,7 @@ void serializeConfig() {
if_live_dmx[F("uni")] = e131Universe;
if_live_dmx[F("seqskip")] = e131SkipOutOfSequence;
if_live_dmx[F("addr")] = DMXAddress;
+ if_live_dmx[F("dss")] = DMXSegmentSpacing;
if_live_dmx["mode"] = DMXMode;
if_live[F("timeout")] = realtimeTimeoutMs / 100;
diff --git a/wled00/colors.cpp b/wled00/colors.cpp
index 0387a925..3cba87d2 100644
--- a/wled00/colors.cpp
+++ b/wled00/colors.cpp
@@ -91,7 +91,7 @@ void colorKtoRGB(uint16_t kelvin, byte* rgb) //white spectrum to rgb, calc
r = round(329.698727446 * pow((temp - 60), -0.1332047592));
g = round(288.1221695283 * pow((temp - 60), -0.0755148492));
b = 255;
- }
+ }
//g += 12; //mod by Aircoookie, a bit less accurate but visibly less pinkish
rgb[0] = (uint8_t) constrain(r, 0, 255);
rgb[1] = (uint8_t) constrain(g, 0, 255);
@@ -194,7 +194,7 @@ void colorFromDecOrHexString(byte* rgb, char* in)
if (in[0] == 0) return;
char first = in[0];
uint32_t c = 0;
-
+
if (first == '#' || first == 'h' || first == 'H') //is HEX encoded
{
c = strtoul(in +1, NULL, 16);
@@ -320,8 +320,9 @@ uint16_t approximateKelvinFromRGB(uint32_t rgb) {
}
}
+#if !defined(WLED_USE_CIE_BRIGHTNESS_TABLE)
//gamma 2.8 lookup table used for color correction
-static byte gammaT[] = {
+static byte gammaT[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
@@ -338,6 +339,31 @@ static byte gammaT[] = {
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
+#else
+// experimental
+// CIE 1931 lookup table (8bit->8bit) that was proposed during discussion of issue #2767
+// https://github.com/Aircoookie/WLED/issues/2767#issuecomment-1310961308
+// unfortunately NepixelsBu has its own internal table, that kills low brightness values similar to the original WLED table.
+// see https://github.com/Makuna/NeoPixelBus/blob/master/src/internal/NeoGamma.h
+static byte gammaT[256] = {
+ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4,
+ 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
+ 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11,
+ 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17,
+ 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24,
+ 25, 25, 26, 27, 27, 28, 28, 29, 30, 30, 31, 31, 32, 33, 33, 34,
+ 35, 35, 36, 37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46,
+ 47, 48, 49, 50, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78,
+ 79, 81, 82, 83, 84, 85, 87, 88, 89, 91, 92, 93, 94, 96, 97, 99,
+ 100, 101, 103, 104, 106, 107, 109, 110, 111, 113, 115, 116, 118, 119, 121,
+ 122, 124, 126, 127, 129, 130, 132, 134, 135, 137, 139, 141, 142, 144, 146,
+ 148, 150, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 170, 172, 174,
+ 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 198, 200, 202, 204, 207,
+ 209, 211, 213, 216, 218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242,
+ 245, 247, 250, 252, 255 };
+#endif
uint8_t gamma8_cal(uint8_t b, float gamma)
{
diff --git a/wled00/const.h b/wled00/const.h
index a6ffe0a5..af6a8088 100644
--- a/wled00/const.h
+++ b/wled00/const.h
@@ -5,7 +5,7 @@
* Readability defines and their associated numerical values + compile-time constants
*/
-#define GRADIENT_PALETTE_COUNT 60 //WLEDMM netmindz ar palette +2
+#define GRADIENT_PALETTE_COUNT 61 //WLEDMM netmindz ar palette +2, ewowi second Random Cycle palette +1
//Defaults
#define DEFAULT_CLIENT_SSID "Your_Network"
@@ -25,25 +25,44 @@
#ifndef WLED_MAX_BUSSES
#ifdef ESP8266
#define WLED_MAX_BUSSES 3
+ #define WLED_MIN_VIRTUAL_BUSSES 2
#else
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
#define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around)
+ #define WLED_MIN_VIRTUAL_BUSSES 3
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
+ #define WLED_MIN_VIRTUAL_BUSSES 4
#else
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
+ #define WLED_MIN_VIRTUAL_BUSSES 3
#endif
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
+ #define WLED_MIN_VIRTUAL_BUSSES 4
#else
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 8
+ #define WLED_MIN_VIRTUAL_BUSSES 2
#else
#define WLED_MAX_BUSSES 10
+ #define WLED_MIN_VIRTUAL_BUSSES 0
#endif
#endif
#endif
+#else
+ #ifdef ESP8266
+ #if WLED_MAX_BUSES > 5
+ #error Maximum number of buses is 5.
+ #endif
+ #define WLED_MIN_VIRTUAL_BUSSES (5-WLED_MAX_BUSSES)
+ #else
+ #if WLED_MAX_BUSES > 10
+ #error Maximum number of buses is 10.
+ #endif
+ #define WLED_MIN_VIRTUAL_BUSSES (10-WLED_MAX_BUSSES)
+ #endif
#endif
#ifndef WLED_MAX_BUTTONS
@@ -79,7 +98,7 @@
#define USERMOD_ID_RTC 15 //Usermod "usermod_rtc.h"
#define USERMOD_ID_ELEKSTUBE_IPS 16 //Usermod "usermod_elekstube_ips.h"
#define USERMOD_ID_SN_PHOTORESISTOR 17 //Usermod "usermod_sn_photoresistor.h"
-#define USERMOD_ID_BATTERY_STATUS_BASIC 18 //Usermod "usermod_v2_battery_status_basic.h"
+#define USERMOD_ID_BATTERY 18 //Usermod "usermod_v2_battery.h"
#define USERMOD_ID_PWM_FAN 19 //Usermod "usermod_PWM_fan.h"
#define USERMOD_ID_BH1750 20 //Usermod "usermod_bh1750.h"
#define USERMOD_ID_SEVEN_SEGMENT_DISPLAY 21 //Usermod "usermod_v2_seven_segment_display.h"
@@ -97,11 +116,14 @@
#define USERMOD_ID_ANALOG_CLOCK 33 //Usermod "Analog_Clock.h"
#define USERMOD_ID_PING_PONG_CLOCK 34 //Usermod "usermod_v2_ping_pong_clock.h"
#define USERMOD_ID_ADS1115 35 //Usermod "usermod_ads1115.h"
+#define USERMOD_ID_BOBLIGHT 36 //Usermod "boblight.h"
#define USERMOD_ID_SD_CARD 37 //Usermod "usermod_sd_card.h"
+#define USERMOD_ID_PWM_OUTPUTS 38 //Usermod "usermod_pwm_outputs.h
+#define USERMOD_ID_SHT 39 //Usermod "usermod_sht.h
//WLEDMM
-#define USERMOD_ID_CUSTOMEFFECTS 38 //Usermod "usermod_v2_customeffects.h"
-#define USERMOD_ID_WEATHER 39 //Usermod "usermod_v2_weather.h"
-#define USERMOD_ID_GAMES 40 //Usermod "usermod_v2_games.h"
+#define USERMOD_ID_CUSTOMEFFECTS 90 //Usermod "usermod_v2_customeffects.h"
+#define USERMOD_ID_WEATHER 91 //Usermod "usermod_v2_weather.h"
+#define USERMOD_ID_GAMES 92 //Usermod "usermod_v2_games.h"
//Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
@@ -125,11 +147,13 @@
#define CALL_MODE_BUTTON_PRESET 12 //button/IR JSON preset/macro
//RGB to RGBW conversion mode
-#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
-#define RGBW_MODE_AUTO_BRIGHTER 1 //New algorithm. Adds as much white as the darkest RGBW channel
-#define RGBW_MODE_AUTO_ACCURATE 2 //New algorithm. Adds as much white as the darkest RGBW channel and subtracts this amount from each RGB channel
-#define RGBW_MODE_DUAL 3 //Manual slider + auto calculation. Automatically calculates only if manual slider is set to off (0)
-#define RGBW_MODE_LEGACY 4 //Old floating algorithm. Too slow for realtime and palette support
+#define RGBW_MODE_MANUAL_ONLY 0 // No automatic white channel calculation. Manual white channel slider
+#define RGBW_MODE_AUTO_BRIGHTER 1 // New algorithm. Adds as much white as the darkest RGBW channel
+#define RGBW_MODE_AUTO_ACCURATE 2 // New algorithm. Adds as much white as the darkest RGBW channel and subtracts this amount from each RGB channel
+#define RGBW_MODE_DUAL 3 // Manual slider + auto calculation. Automatically calculates only if manual slider is set to off (0)
+#define RGBW_MODE_MAX 4 // Sets white to the value of the brightest RGB channel (good for white-only LEDs without any RGB)
+//#define RGBW_MODE_LEGACY 4 // Old floating algorithm. Too slow for realtime and palette support (unused)
+#define AW_GLOBAL_DISABLED 255 // Global auto white mode override disabled. Per-bus setting is used
//realtime modes
#define REALTIME_MODE_INACTIVE 0
@@ -151,10 +175,14 @@
#define DMX_MODE_DISABLED 0 //not used
#define DMX_MODE_SINGLE_RGB 1 //all LEDs same RGB color (3 channels)
#define DMX_MODE_SINGLE_DRGB 2 //all LEDs same RGB color and master dimmer (4 channels)
-#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (11 channels)
+#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (15 channels)
+#define DMX_MODE_EFFECT_W 7 //trigger standalone effects of WLED (18 channels)
#define DMX_MODE_MULTIPLE_RGB 4 //every LED is addressed with its own RGB (ledCount * 3 channels)
#define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels)
#define DMX_MODE_MULTIPLE_RGBW 6 //every LED is addressed with its own RGBW (ledCount * 4 channels)
+#define DMX_MODE_EFFECT_SEGMENT 8 //trigger standalone effects of WLED (15 channels per segement)
+#define DMX_MODE_EFFECT_SEGMENT_W 9 //trigger standalone effects of WLED (18 channels per segement)
+#define DMX_MODE_PRESET 10 //apply presets (1 channel)
//Light capability byte (unused) 0bRCCCTTTT
//bits 0/1/2/3: specifies a type of LED driver. A single "driver" may have different chip models but must have the same protocol/behavior
@@ -171,7 +199,9 @@
#define TYPE_NONE 0 //light is not configured
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
//Digital types (data pin only) (16-31)
-#define TYPE_WS2812_1CH 20 //white-only chips
+#define TYPE_WS2812_1CH 18 //white-only chips (1 channel per IC) (unused)
+#define TYPE_WS2812_1CH_X3 19 //white-only chips (3 channels per IC)
+#define TYPE_WS2812_2CH_X3 20 //CCT chips (1st IC controls WW + CW of 1st zone and CW of 2nd zone, 2nd IC controls WW of 2nd zone and WW + CW of 3rd zone)
#define TYPE_WS2812_WWA 21 //amber + warm + cold white
#define TYPE_WS2812_RGB 22
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
@@ -268,6 +298,11 @@
//Playlist option byte
#define PL_OPTION_SHUFFLE 0x01
+// Segment capability byte
+#define SEG_CAPABILITY_RGB 0x01
+#define SEG_CAPABILITY_W 0x02
+#define SEG_CAPABILITY_CCT 0x04
+
// WLED Error modes
#define ERR_NONE 0 // All good :)
#define ERR_EEP_COMMIT 2 // Could not commit to EEPROM (wrong flash layout?)
@@ -291,7 +326,7 @@
#define NTP_PACKET_SIZE 48
-//maximum number of rendered LEDs - this does not have to match max. physical LEDs, e.g. if there are virtual busses
+//maximum number of rendered LEDs - this does not have to match max. physical LEDs, e.g. if there are virtual busses
#ifndef MAX_LEDS
#ifdef ESP8266
#define MAX_LEDS 1664 //can't rely on memory limit to limit this to 1600 LEDs
@@ -320,7 +355,7 @@
#ifdef ESP8266
#define SETTINGS_STACK_BUF_SIZE 2048
#else
-#define SETTINGS_STACK_BUF_SIZE 3096
+#define SETTINGS_STACK_BUF_SIZE 3096
#endif
#ifdef WLED_USE_ETHERNET
@@ -334,7 +369,7 @@
#endif
#ifndef ABL_MILLIAMPS_DEFAULT
- #define ABL_MILLIAMPS_DEFAULT 850 // auto lower brightness to stay close to milliampere limit
+ #define ABL_MILLIAMPS_DEFAULT 1500 // auto lower brightness to stay close to milliampere limit WLEDMM: min 1500 for 1024leds
#else
#if ABL_MILLIAMPS_DEFAULT == 0 // disable ABL
#elif ABL_MILLIAMPS_DEFAULT < 250 // make sure value is at least 250
@@ -394,43 +429,29 @@
#define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates
-#if defined(ESP8266) && defined(HW_PIN_SCL)
- #undef HW_PIN_SCL
-#endif
-#if defined(ESP8266) && defined(HW_PIN_SDA)
- #undef HW_PIN_SDA
-#endif
+// HW_PIN_SCL & HW_PIN_SDA are used for information in usermods settings page and usermods themselves
+// which GPIO pins are actually used in a hardwarea layout (controller board)
+//WLEDMM: unchangeable pins are not treated here by undef them, but elsewhere in the code
+// defaults for 1st I2C on ESP32 (Wire global)
#ifndef HW_PIN_SCL
- #define HW_PIN_SCL SCL
+ #define HW_PIN_SCL -1 //WLEDMM if not defined, -1 will be used (not SCL/22) (also for esp8266?)
#endif
#ifndef HW_PIN_SDA
- #define HW_PIN_SDA SDA
+ #define HW_PIN_SDA -1 //WLEDMM if not defined, -1 will be used (not SDA/21) (also for esp8266?)
#endif
-#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
- #undef HW_PIN_CLOCKSPI
-#endif
-#if defined(ESP8266) && defined(HW_PIN_DATASPI)
- #undef HW_PIN_DATASPI
-#endif
-#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
- #undef HW_PIN_MISOSPI
-#endif
-#if defined(ESP8266) && defined(HW_PIN_CSSPI)
- #undef HW_PIN_CSSPI
-#endif
-// defaults for VSPI
+// HW_PIN_SCLKSPI & HW_PIN_MOSISPI & HW_PIN_MISOSPI are used for information in usermods settings page and usermods themselves
+// which GPIO pins are actually used in a hardwarea layout (controller board)
+//WLEDMM: unchangeable pins are not treated here by undef them, but elsewhere in the code
+// defaults for VSPI on ESP32 (SPI global, SPI.cpp) as HSPI is used by WLED (bus_wrapper.h)
#ifndef HW_PIN_CLOCKSPI
- #define HW_PIN_CLOCKSPI SCK
+ #define HW_PIN_CLOCKSPI -1 //WLEDMM if not defined -1 will be used (not SCK/18)
#endif
-#ifndef HW_PIN_DATASPI
- #define HW_PIN_DATASPI MOSI
+#ifndef HW_PIN_MOSISPI //WLEDMM renamed from HW_PIN_DATASPI
+ #define HW_PIN_MOSISPI -1 //WLEDMM if not defined -1 will be used (not MOSI/23)
#endif
#ifndef HW_PIN_MISOSPI
- #define HW_PIN_MISOSPI MISO
-#endif
-#ifndef HW_PIN_CSSPI
- #define HW_PIN_CSSPI SS
+ #define HW_PIN_MISOSPI -1 //WLEDMM if not defined -1 will be used (not MISO/19)
#endif
// WLEDMM: IRAM_ATTR for 8266 causes error: section `.text1' will not fit in region `iram1_0_seg'
diff --git a/wled00/data/index.css b/wled00/data/index.css
index af24fc06..913cd360 100644
--- a/wled00/data/index.css
+++ b/wled00/data/index.css
@@ -128,12 +128,13 @@ button {
display: inline-block;
}
-.icons.on {
- color: var(--c-g);
+.on {
+ color: var(--c-g) !important;
}
-.icons.off {
- color: var(--c-6);
+.off {
+ color: var(--c-6) !important;
+ cursor: default !important;
}
.top .icons, .bot .icons {
@@ -435,6 +436,9 @@ button {
left: 50%;
margin-left: -92px;
+ /* Ensure tooltip goes away when mouse leaves control */
+ pointer-events: none;
+
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.75s;
@@ -864,8 +868,8 @@ select {
transition-duration: 0.5s;
-webkit-backface-visibility: hidden;
-webkit-transform:translate3d(0,0,0);
- -webkit-appearance: none;
- -moz-appearance: none;
+ -webkit-appearance: none;
+ -moz-appearance: none;
backface-visibility: hidden;
transform:translate3d(0,0,0);
text-overflow: ellipsis;
@@ -889,8 +893,8 @@ div.sel-p:after {
position: absolute;
right: 10px;
top: 22px;
- width: 0;
- height: 0;
+ width: 0;
+ height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid var(--c-f);
@@ -981,7 +985,7 @@ textarea {
.segname, .pname {
white-space: nowrap;
- cursor: pointer;
+ /*cursor: pointer;*/
text-align: center;
overflow: clip;
text-overflow: ellipsis;
@@ -1185,7 +1189,7 @@ TD .checkmark, TD .radiomark {
}
.bp {
- margin-bottom: 5px;
+ margin-bottom: 8px;
}
/* segment & preset wrapper */
@@ -1220,7 +1224,7 @@ TD .checkmark, TD .radiomark {
line-height: 24px;
vertical-align: middle;
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
- filter: grayscale(100%);
+ filter: grayscale(100%);
}
.lbl-l {
@@ -1330,7 +1334,7 @@ TD .checkmark, TD .radiomark {
white-space: nowrap;
text-overflow: ellipsis;
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
- filter: grayscale(100%);
+ filter: grayscale(100%);
}
/* list item palette preview */
@@ -1361,7 +1365,7 @@ TD .checkmark, TD .radiomark {
background: var(--c-2);
border: 1px solid var(--c-3);
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
- filter: grayscale(100%);
+ filter: grayscale(100%);
}
.fnd input[type="text"]:focus {
diff --git a/wled00/data/index.htm b/wled00/data/index.htm
index c91bc0c2..c975522d 100644
--- a/wled00/data/index.htm
+++ b/wled00/data/index.htm
@@ -6,6 +6,7 @@
+
WLED
-
+
+
+
+
+
+
+
+
+ WLED Pixel Art Converter
+
+
+ Convert image to WLED JSON (pixel art on WLED matrix)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 128
+
+
+
+
+
+
+
+
+ 256
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Scale image
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Version 1.0.7 - Help/About
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/wled00/data/pixart/pixart.js b/wled00/data/pixart/pixart.js
new file mode 100644
index 00000000..a1c67aa9
--- /dev/null
+++ b/wled00/data/pixart/pixart.js
@@ -0,0 +1,364 @@
+//Start up code
+//if (window.location.protocol == "file:") {
+// let locip = prompt("File Mode. Please enter WLED IP!");
+// gId('curlUrl').value = locip;
+//} else
+//
+//Start up code
+let devMode = false; //Remove
+gurl.value = location.host;
+
+const urlParams = new URLSearchParams(window.location.search);
+if (gurl.value.length < 1){
+ gurl.value = "Missing_Host";
+}
+
+function gen(){
+ //Generate image if enough info is in place
+ //Is host non empty
+ //Is image loaded
+ //is scale > 0
+ if (((szX.value > 0 && szY.value > 0) || szDiv.style.display == 'none') && gurl.value.length > 0 && prw.style.display != 'none'){
+ //regenerate
+ let base64Image = prw.src;
+ if (isValidBase64Gif(base64Image)) {
+ im.src = base64Image;
+ getPixelRGBValues(base64Image);
+ imcn.style.display = "block";
+ bcn.style.display = "";
+ } else {
+ let imageInfo = 'WARNING! File does not appear to be a valid image
';
+ imin.innerHTML = imageInfo;
+ imin.style.display = "block";
+ imcn.style.display = "none";
+ JLD.value = '';
+ if (devMode) console.log("The string '" + base64Image + "' is not a valid base64 image.");
+ }
+ }
+
+ if(gurl.value.length > 0){
+ gId("sSg").setAttribute("fill", accentColor);
+ } else{
+ gId("sSg").setAttribute("fill", accentTextColor);
+ let ts = tSg;
+ ts.style.display = "none";
+ ts.innerHTML = "";
+ sID.style.display = "flex";
+ }
+}
+
+
+// Code for copying the generated string to clipboard
+
+cjb.addEventListener('click', async () => {
+ let JSONled = JLD;
+ JSONled.select();
+ try {
+ await navigator.clipboard.writeText(JSONled.value);
+ } catch (err) {
+ try {
+ await d.execCommand("copy");
+ } catch (err) {
+ console.error('Failed to copy text: ', err);
+ }
+ }
+});
+
+// Event listeners =======================
+
+lSS.addEventListener("change", gen);
+szY.addEventListener("change", gen);
+szX.addEventListener("change", gen);
+//frm.addEventListener("change", gen);
+cFS.addEventListener("change", gen);
+aS.addEventListener("change", gen);
+brgh.addEventListener("change", gen);
+cLN.addEventListener("change", gen);
+haIDe.addEventListener("change", gen);
+haUe.addEventListener("change", gen);
+haNe.addEventListener("change", gen);
+gurl.addEventListener("change", gen);
+sID.addEventListener("change", gen);
+prw.addEventListener("load", gen);
+//gId("convertbutton").addEventListener("click", gen);
+
+tSg.addEventListener("change", () => {
+ sop = tSg.options[tSg.selectedIndex];
+ szX.value = sop.dataset.x;
+ szY.value = sop.dataset.y;
+ gen();
+});
+
+gId("sendJSONledbutton").addEventListener('click', async () => {
+ if (window.location.protocol === "https:") {
+ alert('Will only be available when served over http (or WLED is run over https)');
+ } else {
+ postPixels();
+ }
+});
+
+brgh.oninput = () => {
+ brgV.textContent = brgh.value;
+ let perc = parseInt(brgh.value)*100/255;
+ var val = `linear-gradient(90deg, #bbb ${perc}%, #333 ${perc}%)`;
+ brgh.style.backgroundImage = val;
+}
+
+cLN.oninput = () => {
+ let cln = cLN;
+ cLV.textContent = cln.value;
+ let perc = parseInt(cln.value)*100/512;
+ var val = `linear-gradient(90deg, #bbb ${perc}%, #333 ${perc}%)`;
+ cln.style.backgroundImage = val;
+}
+
+frm.addEventListener("change", () => {
+ for (var i = 0; i < hideableRows.length; i++) {
+ hideableRows[i].classList.toggle("hide", frm.value !== "ha");
+ }
+});
+
+async function postPixels() {
+ let ss = gId("sendSvgP");
+ ss.setAttribute("fill", prsCol);
+ let er = false;
+ for (let i of httpArray) {
+ try {
+ if (devMode) console.log(i);
+ if (devMode) console.log(i.length);
+ const response = await fetch('http://'+gId('curlUrl').value+'/json/state', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ //'Content-Type': 'text/html; charset=UTF-8'
+ },
+ body: i
+ });
+ const data = await response.json();
+ if (devMode) console.log(data);
+ } catch (error) {
+ console.error(error);
+ er = true;
+ }
+ }
+ if(er){
+ //Something went wrong
+ ss.setAttribute("fill", redColor);
+ setTimeout(function(){
+ ss.setAttribute("fill", accentTextColor);
+ }, 1000);
+ } else {
+ // A, OK
+ ss.setAttribute("fill", greenColor);
+ setTimeout(function(){
+ ss.setAttribute("fill", accentColor);
+ }, 1000);
+ }
+}
+
+//File uploader code
+const dropZone = gId('drop-zone');
+const filePicker = gId('file-picker');
+const preview = prw;
+
+// Listen for dragenter, dragover, and drop events
+dropZone.addEventListener('dragenter', dragEnter);
+dropZone.addEventListener('dragover', dragOver);
+dropZone.addEventListener('drop', dropped);
+dropZone.addEventListener('click', zoneClicked);
+
+// Listen for change event on file picker
+filePicker.addEventListener('change', filePicked);
+
+// Handle zone click
+function zoneClicked(e) {
+ e.preventDefault();
+ //this.classList.add('drag-over');
+ //alert('Hej');
+ filePicker.click();
+}
+
+// Handle dragenter
+function dragEnter(e) {
+ e.preventDefault();
+ this.classList.add('drag-over');
+}
+
+// Handle dragover
+function dragOver(e) {
+ e.preventDefault();
+}
+
+// Handle drop
+function dropped(e) {
+ e.preventDefault();
+ this.classList.remove('drag-over');
+
+ // Get the dropped file
+ const file = e.dataTransfer.files[0];
+ updatePreview(file)
+}
+
+// Handle file picked
+function filePicked(e) {
+ // Get the picked file
+ const file = e.target.files[0];
+ updatePreview(file)
+}
+
+// Update the preview image
+function updatePreview(file) {
+ // Use FileReader to read the file
+ const reader = new FileReader();
+ reader.onload = () => {
+ // Update the preview image
+ preview.src = reader.result;
+ //gId("submitConvertDiv").style.display = "";
+ prw.style.display = "";
+ };
+ reader.readAsDataURL(file);
+}
+
+function isValidBase64Gif(string) {
+ // Use a regular expression to check that the string is a valid base64 string
+ /*
+ const base64gifPattern = /^data:image\/gif;base64,([A-Za-z0-9+/:]{4})*([A-Za-z0-9+/:]{3}=|[A-Za-z0-9+/:]{2}==)?$/;
+ const base64pngPattern = /^data:image\/png;base64,([A-Za-z0-9+/:]{4})*([A-Za-z0-9+/:]{3}=|[A-Za-z0-9+/:]{2}==)?$/;
+ const base64jpgPattern = /^data:image\/jpg;base64,([A-Za-z0-9+/:]{4})*([A-Za-z0-9+/:]{3}=|[A-Za-z0-9+/:]{2}==)?$/;
+ const base64webpPattern = /^data:image\/webp;base64,([A-Za-z0-9+/:]{4})*([A-Za-z0-9+/:]{3}=|[A-Za-z0-9+/:]{2}==)?$/;
+ */
+ //REMOVED, Any image appear to work as long as it can be drawn to the canvas. Leaving code in for future use, possibly
+ if (1==1 || base64gifPattern.test(string) || base64pngPattern.test(string) || base64jpgPattern.test(string) || base64webpPattern.test(string)) {
+ return true;
+ } else {
+ //Not OK
+ return false;
+ }
+}
+
+var hideableRows = d.querySelectorAll(".ha-hide");
+for (var i = 0; i < hideableRows.length; i++) {
+ hideableRows[i].classList.add("hide");
+}
+frm.addEventListener("change", () => {
+ for (var i = 0; i < hideableRows.length; i++) {
+ hideableRows[i].classList.toggle("hide", frm.value !== "ha");
+ }
+});
+
+function switchScale() {
+ //let scalePath = gId("scaleDiv").children[1].children[0]
+ let scaleTogglePath = scDiv.children[0].children[0]
+ let color = scaleTogglePath.getAttribute("fill");
+ let d = '';
+ if (color === accentColor) {
+ color = accentTextColor;
+ d = scaleToggleOffd;
+ szDiv.style.display = "none";
+ // Set values to actual XY of image, if possible
+ } else {
+ color = accentColor;
+ d = scaleToggleOnd;
+ szDiv.style.display = "";
+ }
+ //scalePath.setAttribute("fill", color);
+ scaleTogglePath.setAttribute("fill", color);
+ scaleTogglePath.setAttribute("d", d);
+ gen();
+}
+
+function generateSegmentOptions(array) {
+ //This function is prepared for a name property on each segment for easier selection
+ //Currently the name is generated generically based on index
+ tSg.innerHTML = "";
+ for (var i = 0; i < array.length; i++) {
+ var option = cE("option");
+ option.value = array[i].value;
+ option.text = array[i].text;
+ option.dataset.x = array[i].x;
+ option.dataset.y = array[i].y;
+ tSg.appendChild(option);
+ if(i === 0) {
+ option.selected = true;
+ szX.value = option.dataset.x;
+ szY.value = option.dataset.y;
+ }
+ }
+}
+
+// Get segments from device
+async function getSegments() {
+ cv = gurl.value;
+ if (cv.length > 0 ){
+ try {
+ var arr = [];
+ const response = await fetch('http://'+cv+'/json/state');
+ const json = await response.json();
+ let ids = json.seg.map(sg => ({id: sg.id, n: sg.n, xs: sg.start, xe: sg.stop, ys: sg.startY, ye: sg.stopY}));
+ for (var i = 0; i < ids.length; i++) {
+ arr.push({
+ value: ids[i]["id"],
+ text: ids[i]["n"] + ' (index: ' + ids[i]["id"] + ')',
+ x: ids[i]["xe"] - ids[i]["xs"],
+ y: ids[i]["ye"] - ids[i]["ys"]
+ });
+ }
+ generateSegmentOptions(arr);
+ tSg.style.display = "flex";
+ sID.style.display = "none";
+ gId("sSg").setAttribute("fill", greenColor);
+ setTimeout(function(){
+ gId("sSg").setAttribute("fill", accentColor);
+ }, 1000);
+
+ } catch (error) {
+ console.error(error);
+ gId("sSg").setAttribute("fill", redColor);
+ setTimeout(function(){
+ gId("sSg").setAttribute("fill", accentColor);
+ }, 1000);
+ tSg.style.display = "none";
+ sID.style.display = "flex";
+ }
+ } else{
+ gId("sSg").setAttribute("fill", redColor);
+ setTimeout(function(){
+ gId("sSg").setAttribute("fill", accentTextColor);
+ }, 1000);
+ tSg.style.display = "none";
+ sID.style.display = "flex";
+ }
+}
+
+//Initial population of segment selection
+function generateSegmentArray(noOfSegments) {
+ var arr = [];
+ for (var i = 0; i < noOfSegments; i++) {
+ arr.push({
+ value: i,
+ text: "Segment index " + i
+ });
+ }
+ return arr;
+}
+
+var segmentData = generateSegmentArray(10);
+
+generateSegmentOptions(segmentData);
+
+seDiv.innerHTML =
+''
+/*gId("convertbutton").innerHTML =
+' Convert to WLED JSON ';
+*/
+cjb.innerHTML =
+' Copy to clipboard';
+gId("sendJSONledbutton").innerHTML =
+' Send to device';
+
+//After everything is loaded, check if we have a possible IP/host
+
+if(gurl.value.length > 0){
+ // Needs to be addressed directly here so the object actually exists
+ gId("sSg").setAttribute("fill", accentColor);
+}
diff --git a/wled00/data/pixart/site.webmanifest b/wled00/data/pixart/site.webmanifest
new file mode 100644
index 00000000..82452af2
--- /dev/null
+++ b/wled00/data/pixart/site.webmanifest
@@ -0,0 +1,19 @@
+{
+ "name": "WLED Pixel Art Convertor",
+ "short_name": "ledconv",
+ "icons": [
+ {
+ "src": "/favicon-32x32.png",
+ "sizes": "32x322",
+ "type": "image/png"
+ },
+ {
+ "src": "/favicon-32x32.png",
+ "sizes": "32x32",
+ "type": "image/png"
+ }
+ ],
+ "theme_color": "#ffffff",
+ "background_color": "#ffffff",
+ "display": "standalone"
+ }
\ No newline at end of file
diff --git a/wled00/data/pixart/statics.js b/wled00/data/pixart/statics.js
new file mode 100644
index 00000000..b4f3c407
--- /dev/null
+++ b/wled00/data/pixart/statics.js
@@ -0,0 +1,51 @@
+//elements
+var gurl = gId('curlUrl');
+var szX = gId("sizeX");
+var szY = gId("sizeY");
+var szDiv = gId("sizeDiv");
+var prw = gId("preview");
+var sID = gId('segID');
+var JLD = gId('JSONled');
+var tSg = gId('targetSegment');
+var brgh = gId("brightnessNumber");
+
+var seDiv = gId("getSegmentsDiv")
+var cjb = gId("copyJSONledbutton");
+var frm = gId("formatSelector");
+var cLN = gId("colorLimitNumber");
+var haIDe = gId("haID");
+var haUe = gId("haUID");
+var haNe = gId("haName");
+var aS = gId("addressingSelector");
+var cFS = gId("colorFormatSelector");
+var lSS = gId("ledSetupSelector");
+var imin = gId('image-info');
+var imcn = gId('image-container');
+var bcn = gId("button-container");
+var im = gId('image');
+//var ss = gId("sendSvgP");
+var scDiv = gId("scaleDiv");
+var w = window;
+var canvas = gId('pixelCanvas');
+var brgV = gId("brightnessValue");
+var cLV = gId("colorLimitValue")
+
+//vars
+var httpArray = [];
+var fileJSON = '';
+
+var hideableRows = d.querySelectorAll(".ha-hide");
+for (var i = 0; i < hideableRows.length; i++) {
+ hideableRows[i].classList.add("hide");
+}
+
+var accentColor = '#eee';
+var accentTextColor = '#777';
+var prsCol = '#ccc';
+var greenColor = '#056b0a';
+var redColor = '#6b050c';
+
+var scaleToggleOffd = "M17,7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7M7,15A3,3 0 0,1 4,12A3,3 0 0,1 7,9A3,3 0 0,1 10,12A3,3 0 0,1 7,15Z";
+var scaleToggleOnd = "M17,7H7A5,5 0 0,0 2,12A5,5 0 0,0 7,17H17A5,5 0 0,0 22,12A5,5 0 0,0 17,7M17,15A3,3 0 0,1 14,12A3,3 0 0,1 17,9A3,3 0 0,1 20,12A3,3 0 0,1 17,15Z";
+
+var sSg = gId("getSegmentsSVGpath");
\ No newline at end of file
diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm
index b5e08741..099d25da 100644
--- a/wled00/data/settings.htm
+++ b/wled00/data/settings.htm
@@ -85,7 +85,7 @@
border: 1px solid #333;
border-radius: var(--h);
font-size: 6vmin;
- height: var(--h);
+ /* height: var(--h); WLEDMM remove to allow more compact display*/
width: calc(100% - 40px);
margin: 2vh auto 0;
cursor: pointer;
@@ -96,13 +96,13 @@
-
+
Loading...
+
-
+
-