diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index ac2a1214..2c005146 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -34,18 +34,21 @@ body: id: install_format attributes: label: Install Method - description: How did you install WLED? + description: How did you install MoonModules WLED? options: + - From MoonModules Release Page + - From srg74 firmware repository + - From https://wled-install.github.io/ - Binary from WLED.me - - Self-Compiled + - Self-Compiled or other validations: required: true - type: input id: version attributes: - label: What version of WLED? + label: What version/release of MM WLED? description: You can find this in by going to Config -> Security & Updates -> Scroll to Bottom. Copy and paste the entire line after "Server message" - placeholder: "e.g. WLED 0.13.1 (build 2203150)" + placeholder: "e.g. WLEDMM_0.14.0.2.1_esp32_4MB_max (build 2212061)" validations: required: true - type: dropdown @@ -56,6 +59,9 @@ body: options: - ESP8266 - ESP32 + - ESP32-S3 + - ESP32-S2 + - ESP32-C3 - Other validations: required: true @@ -80,4 +86,4 @@ body: description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/Aircoookie/WLED/blob/master/CODE_OF_CONDUCT.md) options: - label: I agree to follow this project's Code of Conduct - required: true \ No newline at end of file + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 29a2f1b5..1278009d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -7,5 +7,5 @@ contact_links: url: https://wled.discourse.group/ about: For issues and ideas that might need longer discussion. - name: kno.wled.ge base - url: https://kno.wled.ge/basics/faq/ + url: https://mm.kno.wled.ge/basics/faq/ about: Take a look at the frequently asked questions and documentation, perhaps your question is already answered! \ No newline at end of file diff --git a/.github/workflows/wled-ci.yml b/.github/workflows/wled-ci.yml index c28446e6..1655f7ec 100644 --- a/.github/workflows/wled-ci.yml +++ b/.github/workflows/wled-ci.yml @@ -28,7 +28,7 @@ jobs: build: - name: Build Enviornments + name: Build Environments runs-on: ubuntu-latest needs: get_default_envs strategy: diff --git a/.gitignore b/.gitignore index bb02e36e..789de0a9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ node_modules wled-update.sh esp01-update.sh /wled00/LittleFS -replace_fs.py \ No newline at end of file +replace_fs.py +wled00/wled00.ino.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index baf49362..aaf02f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,73 @@ ## WLED changelog +#### Build 2302180 + +- Removed Blynk support (servers shut down on 31st Dec 2022) + +#### Build 2301240 + +- Version bump to v0.14.0-b2 "Hoshi" +- PixelArt converter (convert any image to pixel art and display it on a matrix) (PR #3042) +- various effect updates and optimisations + - added Overlay option to some effects (allows overlapping segments) + - added gradient text on Scrolling Text + - added #DDMM, #MMDD & #HHMM date and time options for Scrolling Text effect (PR #2990) + - deprecated: Dynamic Smooth, Dissolve Rnd, Solid Glitter + - optimised & enhanced loading of default values + - new effect: Distortion Waves (2D) + - 2D support for Ripple effect + - slower minimum speed for Railway effect +- DMX effect mode & segment controls (PR #2891) +- Optimisations for conditional compiles (further reduction of code size) +- better UX with effect sliders (PR #3012) +- enhanced support for ESP32 variants: C3, S2 & S3 +- usermod enhancements (PIR, Temperature, Battery (PR #2975), Analog Clock (PR #2993)) +- new usermod SHT (PR #2963) +- 2D matrix set up with gaps or irregular panels (breaking change!) (PR #2892) +- palette blending/transitions +- random palette smooth changes +- hex color notations in custom palettes +- allow more virtual buses +- plethora of bugfixes + +### WLED release 0.14.0-b1 + +#### Build 2212222 + +- Version bump to v0.14.0-b1 "Hoshi" +- 2D matrix support (including mapping 1D effects to 2D and 2D peek) +- [internal] completely rewritten Segment & WS2812FX handling code +- [internal] ability to add custom effects via usermods +- [internal] set of 2D drawing functions +- transitions on every segment (including ESP8266) +- enhanced old and new 2D effects (metadata: default values) +- custom palettes (up to 10; upload palette0.json, palette1.json, ...) +- custom effect sliders and options, quick filters +- global I2C and SPI GPIO allocation (for usermods) +- usermod settings page enhancements (dropdown & info) +- asynchronous preset loading (and added "pd" JSON API call for direct preset apply) +- new usermod Boblight (PR #2917) +- new usermod PWM Outputs (PR #2912) +- new usermod Audioreactive +- new usermod Word Clock Matrix (PR #2743) +- new usermod Ping Pong Clock (PR #2746) +- new usermod ADS1115 (PR #2752) +- new usermod Analog Clock (PR #2736) +- various usermod enhancements and updates +- allow disabling pull-up resistors on buttons +- SD card support (PR #2877) +- enhanced HTTP API to support custom effect sliders & options (X1, X2, X3, M1, M2, M3) +- multiple UDP sync message retries (PR #2830) +- network debug printer (PR #2870) +- automatic UI PC mode on large displays +- removed support for upgrading from pre-0.10 (EEPROM) +- support for setting GPIO level when LEDs are off (RMT idle level, ESP32 only) (PR #2478) +- Pakistan time-zone (PKT) +- ArtPoll support +- TM1829 LED support +- experimental support for ESP32 S2, S3 and C3 +- general improvements and bugfixes + ### WLED release 0.13.3 - Version bump to v0.13.3 "Toki" diff --git a/boards/esp32_16MB-poe.json b/boards/esp32_16MB-poe.json new file mode 100644 index 00000000..a15ef9a3 --- /dev/null +++ b/boards/esp32_16MB-poe.json @@ -0,0 +1,38 @@ +{ +"build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": "-DARDUINO_ESP32_DEV -DARDUINO_ESP32_POE", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32-poe", + "partitions": "partitions_16M.csv" +}, +"connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" +], +"debug": { + "openocd_board": "esp-wroom-32.cfg" +}, +"frameworks": [ + "arduino", + "espidf" +], +"name": "ESP32 16MB", +"upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 2000000 +}, +"url": "https://en.wikipedia.org/wiki/ESP32", +"vendor": "Multiple" +} diff --git a/boards/esp32_twilord.json b/boards/esp32_16MB.json similarity index 91% rename from boards/esp32_twilord.json rename to boards/esp32_16MB.json index 5bf0078d..288dbfe9 100644 --- a/boards/esp32_twilord.json +++ b/boards/esp32_16MB.json @@ -25,7 +25,7 @@ "arduino", "espidf" ], -"name": "TwilightLord-ESP32 16MB", +"name": "ESP32 16MB", "upload": { "flash_size": "16MB", "maximum_ram_size": 327680, @@ -34,5 +34,5 @@ "speed": 2000000 }, "url": "https://en.wikipedia.org/wiki/ESP32", -"vendor": "TwilightLord" +"vendor": "Multiple" } diff --git a/package-lock.json b/package-lock.json index 290bba68..97497117 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wled", - "version": "0.14.0.6.0", + "version": "0.14.0-b15.21", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wled", - "version": "0.14.0.6.0", + "version": "0.14.0-b15.21", "license": "ISC", "dependencies": { "clean-css": "^4.2.3", @@ -2939,24 +2939,6 @@ } }, "dependencies": { - "@sindresorhus/is": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==" - }, - "@szmarczak/http-timer": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", - "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", - "requires": { - "defer-to-connect": "^1.0.1" - } - }, - "@types/color-name": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" - }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -2983,39 +2965,6 @@ "repeat-string": "^1.5.2" } }, - "ansi-align": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz", - "integrity": "sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==", - "requires": { - "string-width": "^3.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" - }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - } - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "requires": { - "ansi-regex": "^4.1.0" - } - } - } - }, "ansi-escapes": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz", @@ -3032,9 +2981,9 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" }, "anymatch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz", - "integrity": "sha512-mM8522psRCqzV+6LhomX5wgp25YVibjh8Wj23I5RPkPppSVSjyKD2A2mBJmWGa+KN7f2D6LNh9jkBCeyLktzjg==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "requires": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -3082,9 +3031,9 @@ "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "bcrypt-pbkdf": { "version": "1.0.2", @@ -3095,68 +3044,15 @@ } }, "binary-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", - "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" }, "boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=" }, - "boxen": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/boxen/-/boxen-4.2.0.tgz", - "integrity": "sha512-eB4uT9RGzg2odpER62bBwSLvUeGC+WbRjjyyFhGsKnc8wp/m0+hQsMUvUe3H2V0D5vw0nBdO1hCJoZo5mKeuIQ==", - "requires": { - "ansi-align": "^3.0.0", - "camelcase": "^5.3.1", - "chalk": "^3.0.0", - "cli-boxes": "^2.2.0", - "string-width": "^4.1.0", - "term-size": "^2.1.0", - "type-fest": "^0.8.1", - "widest-line": "^3.1.0" - }, - "dependencies": { - "ansi-styles": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", - "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", - "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" - } - }, - "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" - }, - "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" - }, - "supports-color": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", - "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -3179,35 +3075,6 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, - "cacheable-request": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", - "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", - "requires": { - "clone-response": "^1.0.2", - "get-stream": "^5.1.0", - "http-cache-semantics": "^4.0.0", - "keyv": "^3.0.0", - "lowercase-keys": "^2.0.0", - "normalize-url": "^4.1.0", - "responselike": "^1.0.2" - }, - "dependencies": { - "get-stream": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", - "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", - "requires": { - "pump": "^3.0.0" - } - }, - "lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==" - } - } - }, "camelcase": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", @@ -3257,25 +3124,20 @@ } }, "chokidar": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.4.0.tgz", - "integrity": "sha512-aXAaho2VJtisB/1fg1+3nlLJqGOuewTzQpd/Tz0yTg2R0e4IGtshYvtjowyEumcBv2z+y4+kc75Mz7j5xJskcQ==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "requires": { - "anymatch": "~3.1.1", + "anymatch": "~3.1.2", "braces": "~3.0.2", - "fsevents": "~2.1.2", - "glob-parent": "~5.1.0", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", - "readdirp": "~3.4.0" + "readdirp": "~3.6.0" } }, - "ci-info": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", - "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==" - }, "clap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/clap/-/clap-1.2.3.tgz", @@ -3299,11 +3161,6 @@ } } }, - "cli-boxes": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.0.tgz", - "integrity": "sha512-gpaBrMAizVEANOpfZp/EEUixTXDyGt7DFzdK5hU+UbWt/J0lB0w20ncZj59Z9a93xHb9u12zF5BS6i9RKbtg4w==" - }, "cliui": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", @@ -3314,14 +3171,6 @@ "wordwrap": "0.0.2" } }, - "clone-response": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", - "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", - "requires": { - "mimic-response": "^1.0.0" - } - }, "coa": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/coa/-/coa-1.0.4.tgz", @@ -3330,19 +3179,6 @@ "q": "^1.1.2" } }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, "colors": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", @@ -3364,7 +3200,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "configstore": { "version": "1.4.0", @@ -3393,11 +3229,6 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, - "crypto-random-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", - "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==" - }, "css-select": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.0.0.tgz", @@ -3444,24 +3275,11 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, - "decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", - "requires": { - "mimic-response": "^1.0.0" - } - }, "deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" }, - "defer-to-connect": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", - "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==" - }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -3525,19 +3343,6 @@ } } }, - "dot-prop": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.2.0.tgz", - "integrity": "sha512-uEUyaDKoSQ1M4Oq8l45hSE26SnTxL6snNnqvK/VWx5wJhmff5z0FUVJDKDanor/6w3kzE3i7XZOk+7wC0EXr1A==", - "requires": { - "is-obj": "^2.0.0" - } - }, - "duplexer3": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", - "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=" - }, "duplexify": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz", @@ -3592,11 +3397,6 @@ "safer-buffer": "^2.1.0" } }, - "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" - }, "end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -3615,11 +3415,6 @@ "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-2.3.0.tgz", "integrity": "sha1-lu258v2wGZWCKyY92KratnSBgbw=" }, - "escape-goat": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", - "integrity": "sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==" - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -3674,19 +3469,11 @@ } }, "fsevents": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", - "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "optional": true }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "requires": { - "pump": "^3.0.0" - } - }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -3703,14 +3490,6 @@ "is-glob": "^4.0.1" } }, - "global-dirs": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-2.0.1.tgz", - "integrity": "sha512-5HqUqdhkEovj2Of/ms3IeS/EekcO54ytHRLV4PEY2rhRwrHXLQjeVEES0Lhka0xwNDtGYn58wyC4s5+MHsOO6A==", - "requires": { - "ini": "^1.3.5" - } - }, "got": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/got/-/got-3.3.1.tgz", @@ -3765,12 +3544,7 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" - }, - "has-yarn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", - "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==" + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==" }, "he": { "version": "1.2.0", @@ -3844,11 +3618,6 @@ } } }, - "http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" - }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -3870,12 +3639,7 @@ "ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", - "integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=" - }, - "import-lazy": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-2.1.0.tgz", - "integrity": "sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=" + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" }, "imurmurhash": { "version": "0.1.4", @@ -3936,46 +3700,24 @@ "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" }, - "is-ci": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", - "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", - "requires": { - "ci-info": "^2.0.0" - } - }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==" }, "is-finite": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.1.0.tgz", "integrity": "sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==" }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" - }, "is-glob": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", - "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "requires": { "is-extglob": "^2.1.1" } }, - "is-installed-globally": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.3.2.tgz", - "integrity": "sha512-wZ8x1js7Ia0kecP/CHM/3ABkAmujX7WPvQk6uu3Fly/Mk44pySulQpnHG46OMjHGXApINnV4QhY3SWnECO2z5g==", - "requires": { - "global-dirs": "^2.0.1", - "is-path-inside": "^3.0.1" - } - }, "is-npm": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-1.0.0.tgz", @@ -3986,16 +3728,6 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" }, - "is-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", - "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==" - }, - "is-path-inside": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.2.tgz", - "integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg==" - }, "is-redirect": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz", @@ -4011,11 +3743,6 @@ "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, - "is-yarn-global": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz", - "integrity": "sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==" - }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -4045,11 +3772,6 @@ "resolved": "https://registry.npmjs.org/jschardet/-/jschardet-1.6.0.tgz", "integrity": "sha512-xYuhvQ7I9PDJIGBWev9xm0+SMSed3ZDBAmvVjbFR1ZRLAF+vlXcQu6cRI9uAlj81rzikElRVteehwV7DuX2ZmQ==" }, - "json-buffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=" - }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -4076,14 +3798,6 @@ "verror": "1.10.0" } }, - "keyv": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", - "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", - "requires": { - "json-buffer": "3.0.0" - } - }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -4227,21 +3941,6 @@ "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==" }, - "make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "requires": { - "semver": "^6.0.0" - }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" - } - } - }, "mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", @@ -4260,15 +3959,10 @@ "mime-db": "1.44.0" } }, - "mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" - }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "requires": { "brace-expansion": "^1.1.7" } @@ -4300,152 +3994,34 @@ } }, "nodemon": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.4.tgz", - "integrity": "sha512-Ltced+hIfTmaS28Zjv1BM552oQ3dbwPqI4+zI0SLgq+wpJhSyqgYude/aZa/3i31VCQWMfXJVxvu86abcam3uQ==", + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", + "integrity": "sha512-Km2mWHKKY5GzRg6i1j5OxOHQtuvVsgskLfigG25yTtbyfRGn/GNvIbRyOf1PSCKJ2aT/58TiuUsuOU5UToVViw==", "requires": { - "chokidar": "^3.2.2", - "debug": "^3.2.6", + "chokidar": "^3.5.2", + "debug": "^3.2.7", "ignore-by-default": "^1.0.1", - "minimatch": "^3.0.4", - "pstree.remy": "^1.1.7", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", "semver": "^5.7.1", + "simple-update-notifier": "^1.0.7", "supports-color": "^5.5.0", "touch": "^3.1.0", - "undefsafe": "^2.0.2", - "update-notifier": "^4.0.0" + "undefsafe": "^2.0.5" }, "dependencies": { - "ansi-styles": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", - "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", - "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" - } - }, - "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "dependencies": { - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" - }, - "supports-color": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", - "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", - "requires": { - "has-flag": "^4.0.0" - } - } - } - }, - "configstore": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz", - "integrity": "sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA==", - "requires": { - "dot-prop": "^5.2.0", - "graceful-fs": "^4.1.2", - "make-dir": "^3.0.0", - "unique-string": "^2.0.0", - "write-file-atomic": "^3.0.0", - "xdg-basedir": "^4.0.0" - } - }, "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", "requires": { "ms": "^2.1.1" } }, - "got": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", - "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", - "requires": { - "@sindresorhus/is": "^0.14.0", - "@szmarczak/http-timer": "^1.1.2", - "cacheable-request": "^6.0.0", - "decompress-response": "^3.3.0", - "duplexer3": "^0.1.4", - "get-stream": "^4.1.0", - "lowercase-keys": "^1.0.1", - "mimic-response": "^1.0.1", - "p-cancelable": "^1.0.0", - "to-readable-stream": "^1.0.0", - "url-parse-lax": "^3.0.0" - } - }, - "is-npm": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-4.0.0.tgz", - "integrity": "sha512-96ECIfh9xtDDlPylNPXhzjsykHsMJZ18ASpaWzQyBr4YRTcVjUvzaHayDAES2oU/3KpljhHUjtSRNiDwi0F0ig==" - }, - "latest-version": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", - "integrity": "sha512-weT+r0kTkRQdCdYCNtkMwWXQTMEswKrFBkm4ckQOMVhhqhIMI1UT2hMj+1iigIhgSZm5gTmrRXBNoGUgaTY1xA==", - "requires": { - "package-json": "^6.3.0" - } - }, "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "package-json": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/package-json/-/package-json-6.5.0.tgz", - "integrity": "sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==", - "requires": { - "got": "^9.6.0", - "registry-auth-token": "^4.0.0", - "registry-url": "^5.0.0", - "semver": "^6.2.0" - }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" - } - } - }, - "registry-url": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-5.1.0.tgz", - "integrity": "sha512-8acYXXTI0AkQv6RAOjE3vOaIXZkT9wo4LOFbBKYQEEnnMNBpKqdUrI6S4NT0KPIo/WVvJ5tE/X5LF/TQUf0ekw==", - "requires": { - "rc": "^1.2.8" - } - }, - "semver-diff": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-3.1.1.tgz", - "integrity": "sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==", - "requires": { - "semver": "^6.3.0" - }, - "dependencies": { - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" - } - } + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "supports-color": { "version": "5.5.0", @@ -4454,49 +4030,13 @@ "requires": { "has-flag": "^3.0.0" } - }, - "update-notifier": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.0.tgz", - "integrity": "sha512-w3doE1qtI0/ZmgeoDoARmI5fjDoT93IfKgEGqm26dGUOh8oNpaSTsGNdYRN/SjOuo10jcJGwkEL3mroKzktkew==", - "requires": { - "boxen": "^4.2.0", - "chalk": "^3.0.0", - "configstore": "^5.0.1", - "has-yarn": "^2.1.0", - "import-lazy": "^2.1.0", - "is-ci": "^2.0.0", - "is-installed-globally": "^0.3.1", - "is-npm": "^4.0.0", - "is-yarn-global": "^0.3.0", - "latest-version": "^5.0.0", - "pupa": "^2.0.1", - "semver-diff": "^3.1.1", - "xdg-basedir": "^4.0.0" - } - }, - "write-file-atomic": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", - "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", - "requires": { - "imurmurhash": "^0.1.4", - "is-typedarray": "^1.0.0", - "signal-exit": "^3.0.2", - "typedarray-to-buffer": "^3.1.5" - } - }, - "xdg-basedir": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", - "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==" } } }, "nopt": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", - "integrity": "sha1-bd0hvSoxQXuScn3Vhfim83YI6+4=", + "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", "requires": { "abbrev": "1" } @@ -4506,11 +4046,6 @@ "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, - "normalize-url": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz", - "integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==" - }, "nth-check": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", @@ -4556,11 +4091,6 @@ "os-tmpdir": "^1.0.0" } }, - "p-cancelable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", - "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==" - }, "package-json": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/package-json/-/package-json-1.2.0.tgz", @@ -4604,9 +4134,9 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, "picomatch": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", - "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==" + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" }, "pinkie": { "version": "2.0.4", @@ -4649,28 +4179,11 @@ "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, - "pupa": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pupa/-/pupa-2.0.1.tgz", - "integrity": "sha512-hEJH0s8PXLY/cdXh66tNEQGndDrIKNqNC5xmrysZy3i5C3oEoLna7YAOad+7u125+zH1HNXUmGEkrhb3c2VriA==", - "requires": { - "escape-goat": "^2.0.0" - } - }, "q": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", @@ -4747,21 +4260,13 @@ } }, "readdirp": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.4.0.tgz", - "integrity": "sha512-0xe001vZBnJEK+uKcj8qOhyAKPzIT+gStxWr3LCB0DwcXR5NZJ3IaC+yGnHCYzB/S7ov3m3EEbZI2zeNvX+hGQ==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "requires": { "picomatch": "^2.2.1" } }, - "registry-auth-token": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-4.1.1.tgz", - "integrity": "sha512-9bKS7nTl9+/A1s7tnPeGrUpRcVY+LUh7bfFgzpndALdPfXQBfQV77rQVtqgUV3ti4vc/Ik81Ex8UJDWDQ12zQA==", - "requires": { - "rc": "^1.2.8" - } - }, "registry-url": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/registry-url/-/registry-url-3.1.0.tgz", @@ -4815,14 +4320,6 @@ "uuid": "^3.3.2" } }, - "responselike": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", - "integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", - "requires": { - "lowercase-keys": "^1.0.0" - } - }, "right-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", @@ -4859,10 +4356,20 @@ "semver": "^5.0.3" } }, - "signal-exit": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", - "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" + "simple-update-notifier": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", + "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "requires": { + "semver": "~7.0.0" + }, + "dependencies": { + "semver": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", + "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==" + } + } }, "slide": { "version": "1.1.6", @@ -4929,40 +4436,10 @@ "strip-ansi": "^3.0.0" } }, - "string-width": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", - "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" - }, - "emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" - }, - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" - }, - "strip-ansi": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", - "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", - "requires": { - "ansi-regex": "^5.0.0" - } - } - } + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" }, "strip-ansi": { "version": "3.0.1", @@ -4996,11 +4473,6 @@ "whet.extend": "~0.9.9" } }, - "term-size": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.0.tgz", - "integrity": "sha512-a6sumDlzyHVJWb8+YofY4TW112G6p2FCPEAFk+59gIYHv3XHRhm9ltVQ9kli4hNWeQBwSpe8cRN25x0ROunMOw==" - }, "terser": { "version": "4.8.1", "resolved": "https://registry.npmjs.org/terser/-/terser-4.8.1.tgz", @@ -5031,11 +4503,6 @@ "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-2.0.0.tgz", "integrity": "sha1-84sK6B03R9YoAB9B2vxlKs5nHAo=" }, - "to-readable-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==" - }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -5079,19 +4546,6 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, - "type-fest": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", - "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==" - }, - "typedarray-to-buffer": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", - "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", - "requires": { - "is-typedarray": "^1.0.0" - } - }, "uglify-js": { "version": "2.8.29", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", @@ -5109,20 +4563,9 @@ "optional": true }, "undefsafe": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz", - "integrity": "sha512-nrXZwwXrD/T/JXeygJqdCO6NZZ1L66HrxM/Z7mIq2oPanoN0F1nLx3lwJMu6AwJY69hdixaFQOuoYsMjE5/C2A==", - "requires": { - "debug": "^2.2.0" - } - }, - "unique-string": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-2.0.0.tgz", - "integrity": "sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg==", - "requires": { - "crypto-random-string": "^2.0.0" - } + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" }, "update-notifier": { "version": "0.5.0", @@ -5146,21 +4589,6 @@ "punycode": "^2.1.0" } }, - "url-parse-lax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", - "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", - "requires": { - "prepend-http": "^2.0.0" - }, - "dependencies": { - "prepend-http": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", - "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" - } - } - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -5186,14 +4614,6 @@ "resolved": "https://registry.npmjs.org/whet.extend/-/whet.extend-0.9.9.tgz", "integrity": "sha1-+HfVv2SMl+WqVC+twW1qJZucEaE=" }, - "widest-line": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", - "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", - "requires": { - "string-width": "^4.0.0" - } - }, "window-size": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", diff --git a/package.json b/package.json index 6c30d6d3..a3297fa4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wled", - "version": "0.14.0.6.0", + "version": "0.14.0-b15.21", "description": "Tools for WLED project", "main": "tools/cdata.js", "directories": { @@ -25,7 +25,7 @@ "clean-css": "^4.2.3", "html-minifier-terser": "^5.1.1", "inliner": "^1.13.1", - "nodemon": "^2.0.4", + "nodemon": "^2.0.20", "zlib": "^1.0.5" } } diff --git a/platformio.ini b/platformio.ini index 2d5035f0..df001a91 100644 --- a/platformio.ini +++ b/platformio.ini @@ -6,16 +6,14 @@ # ENVIRONMENTS # # Please uncomment one of the lines below to select your board(s) +# (use `platformio_override.ini` when building for your own board; see `platformio_override.ini.sample` for an example) # ------------------------------------------------------------------------------ -# Travis CI binaries (use `platformio_override.ini` when building for your own board; see `platformio_override.ini.sample` for an example) -; default_envs = travis_esp8266, travis_esp32 - -# Release binaries -; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3dev, esp32s3dev_8MB +# Release / CI binaries +; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3, esp32s3dev_8MB # Build everything -; default_envs = esp32dev, esp8285_4CH_MagicHome, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, travis_esp8266, travis_esp32, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips +; default_envs = esp32dev, esp8285_4CH_MagicHome, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips # Single binaries (uncomment your board) ; default_envs = elekstube_ips @@ -41,23 +39,40 @@ ; MoonModules entries ; =================== -; default_envs = esp32_4MB_min, esp32_4MB_max, esp32_16MB_max, esp8266_4MB_min, esp32_4MB_PSRAM_max, esp32S3_8MB_max, wemos_shield_esp32_4MB_max, wemos_shield_esp32_4MB_ICS4343x_max, wemos_shield_esp32_4MB_SPM1423_max, wemos_shield_esp32_4MB_LineIn_max, wemos_shield_esp32_16MB_max, esp32_pico_4MB_max -; default_envs = esp32_4MB_min -default_envs = esp32_4MB_max ; recommended default -; default_envs = esp32_16MB_max -; default_envs = esp8266_4MB_min -; default_envs = esp32_4MB_V4_min -; default_envs = esp32_4MB_V4_max -; default_envs = esp32_16MB_V4_max -; default_envs = esp32_4MB_PSRAM_max -; default_envs = esp32S3_8MB_max -; default_envs = wemos_shield_esp32_4MB_max -; default_envs = wemos_shield_esp32_4MB_ICS4343x_max -; default_envs = wemos_shield_esp32_4MB_SPM1423_max -; default_envs = wemos_shield_esp32_4MB_LineIn_max -; default_envs = wemos_shield_esp32_16MB_max -; default_envs = esp32_pico_4MB_max +default_envs = + esp32_4MB_M ; recommended default + esp32_4MB_M_debug + esp32_4MB_XL + esp32_16MB_M + esp32_16MB_M_debug + esp32_16MB_XL + esp8266_4MB_S + esp8266_4MB_M + wemos_shield_esp32_4MB_M + wemos_shield_esp32_4MB_ICS4343x_M + wemos_shield_esp32_4MB_SPM1423_M + wemos_shield_esp32_4MB_LineIn_M + wemos_shield_esp32_16MB_M + wemos_shield_esp32_16MB_ICS4343x_M + wemos_shield_esp32_16MB_SPM1423_M + wemos_shield_esp32_16MB_SPM1423_XL + wemos_shield_esp32_16MB_LineIn_M + esp32_pico_4MB_M + esp32_4MB_PSRAM_S + esp32S3_8MB_M + ;; esp32s2_tinyUF2_PSRAM_S ;; experimental - only for adafruit -S2 boards with tinyUF2 bootloader !!! + esp32s2_PSRAM_M ;; experimental + esp32c3dev_4MB_M ;; experimental + esp32_4MB_V4_S ;; experimental + esp32_16MB_V4_M ;; experimental + esp32_16MB_V4_M_debug ;; experimental + esp8266pro_16MB_S + esp8266pro_16MB_M + esp01_1MB_S + esp32_16MB_M_eth + athom_music_esp32_4MB_M +; Go to MoonModules environments for environments src_dir = ./wled00 data_dir = ./wled00/data @@ -133,6 +148,9 @@ build_flags = -D DECODE_SONY=true -D DECODE_SAMSUNG=true -D DECODE_LG=true + ;-D DECODE_RC5=true + ;-D DECODE_RC6=true + ; -Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library -DWLED_USE_MY_CONFIG ; -D USERMOD_SENSORSTOMQTT #For ADS1115 sensor uncomment following @@ -140,13 +158,6 @@ build_flags = build_unflags = -# enables all features for travis CI -build_flags_all_features = - -D WLED_ENABLE_ADALIGHT - -D WLED_ENABLE_DMX - -D WLED_ENABLE_MQTT - -D WLED_ENABLE_WEBSOCKETS - build_flags_esp8266 = ${common.build_flags} ${esp8266.build_flags} build_flags_esp32 = ${common.build_flags} ${esp32.build_flags} @@ -155,6 +166,11 @@ ldscript_2m512k = eagle.flash.2m512.ld ldscript_2m1m = eagle.flash.2m1m.ld ldscript_4m1m = eagle.flash.4m1m.ld +;; WLEDMM: additional partion layouts for 8266 "pro" with 8MB or 16MB. On 8266 the max program size is always 1MB +ldscript_auto = eagle.flash.auto.ld +ldscript_8m6m = eagle.flash.8m6m.ld +ldscript_16m14m = eagle.flash.16m14m.ld + [scripts_defaults] extra_scripts = pre:pio-scripts/set_version.py @@ -179,7 +195,7 @@ upload_speed = 115200 # Please note that we don't always use the latest version of a library. # # The following libraries have been included (and some of them changd) in the source: -# ArduinoJson@5.13.5, Blynk@0.5.4(changed), E131@1.0.0(changed), Time@1.5, Timezone@1.2.1 +# ArduinoJson@5.13.5, E131@1.0.0(changed), Time@1.5, Timezone@1.2.1 # ------------------------------------------------------------------------------ lib_compat_mode = strict lib_deps = @@ -242,8 +258,10 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 #use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x -D LOROL_LITTLEFS + ; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when builing with arduino-esp32 >=2.0.3 -default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv +default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv ;; WLED standard for 4MB flash: 1.4MB firmware, 1MB filesystem +;default_partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; Alternative for 4MB flash: 1.8MB firmware, 256KB filesystem (esptool erase_flash needed before changing) lib_deps = ${env.lib_deps} @@ -265,36 +283,46 @@ build_flagsV4 = -g -DARDUINO_ARCH_ESP32 -DESP32 -DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE -D CONFIG_ASYNC_TCP_USE_WDT=0 + ; -DARDUINO_USB_CDC_ON_BOOT=0 ;; mandatory for "classic ESP32" when builing with arduino-esp32 >=2.0.3 ;;; V4.4.x libraries (without LOROL_LITTLEFS; with newer NeoPixelBus) lib_depsV4 = ${env.lib_deps} - https://github.com/Makuna/NeoPixelBus.git#master @ 2.7.0 ;; NPB 2.6.9 tends to crash whith IDF V4.4.3 -> use latest NeoPixelBus dev version instead + ;https://github.com/Makuna/NeoPixelBus.git#master ;; NPB 2.6.9 tends to crash whith IDF V4.4.3 -> use latest NeoPixelBus dev instead + makuna/NeoPixelBus @ 2.7.1 https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 [esp32s2] build_flags = -g - -DARDUINO_ARCH_ESP32 + -DARDUINO_ARCH_ESP32 -DESP32 ;; WLEDMM -DARDUINO_ARCH_ESP32S2 -DCONFIG_IDF_TARGET_ESP32S2 + -DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE ;; WLEDMM -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + -DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 ! + ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: + ;; ARDUINO_USB_CDC_ON_BOOT, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT lib_deps = ${env.lib_deps} - makuna/NeoPixelBus @ 2.6.9 + makuna/NeoPixelBus @ 2.7.1 ;; WLEDMM - new version is more stable on -S2 https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 [esp32c3] build_flags = -g - -DARDUINO_ARCH_ESP32 + -DARDUINO_ARCH_ESP32 -DESP32 ;; WLEDMM -DARDUINO_ARCH_ESP32C3 -DCONFIG_IDF_TARGET_ESP32C3 + -DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE ;; WLEDMM -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + -DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3 + ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: + ;; ARDUINO_USB_CDC_ON_BOOT lib_deps = ${env.lib_deps} - makuna/NeoPixelBus @ 2.6.9 + makuna/NeoPixelBus @ 2.7.1 ;; WLEDMM - new version is more stable on -C3 https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 [esp32s3] @@ -304,13 +332,17 @@ build_flags = -g -DARDUINO_ARCH_ESP32 -DARDUINO_ARCH_ESP32S3 -DCONFIG_IDF_TARGET_ESP32S3 + -DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE ;; WLEDMM -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: + ;; ARDUINO_USB_MODE, ARDUINO_USB_CDC_ON_BOOT, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT lib_deps = ${env.lib_deps} ;; currently we need the latest NeoPixelBus dev version, because it contains important bugfixes for -S3 - https://github.com/Makuna/NeoPixelBus.git#master @ 2.7.0 + ;https://github.com/Makuna/NeoPixelBus.git#master ;; NPB 2.6.9 tends to crash whith IDF V4.4.3 -> use latest NeoPixelBus dev instead + makuna/NeoPixelBus @ ~2.7.1 https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 @@ -324,7 +356,7 @@ platform = ${common.platform_wled_default} platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_4m1m} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 #-DWLED_DISABLE_2D lib_deps = ${esp8266.lib_deps} monitor_filters = esp8266_exception_decoder @@ -337,14 +369,15 @@ build_unflags = ${common.build_unflags} build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP02 lib_deps = ${esp8266.lib_deps} -[env:esp01_1m_full] -board = esp01_1m -platform = ${common.platform_wled_default} -platform_packages = ${common.platform_packages} -board_build.ldscript = ${common.ldscript_1m128k} -build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP01 -D WLED_DISABLE_OTA -lib_deps = ${esp8266.lib_deps} +;WLEDMM: see below +; [env:esp01_1m_full] +; board = esp01_1m +; platform = ${common.platform_wled_default} +; platform_packages = ${common.platform_packages} +; board_build.ldscript = ${common.ldscript_1m128k} +; build_unflags = ${common.build_unflags} +; build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP01 -D WLED_DISABLE_OTA +; lib_deps = ${esp8266.lib_deps} [env:esp07] board = esp07 @@ -389,7 +422,7 @@ board = esp32dev platform = ${esp32.platform} platform_packages = ${esp32.platform_packages} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32 #-D WLED_DISABLE_BLYNK #-D WLED_DISABLE_BROWNOUT_DET +build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32 #-D WLED_DISABLE_BROWNOUT_DET lib_deps = ${esp32.lib_deps} monitor_filters = esp32_exception_decoder board_build.partitions = ${esp32.default_partitions} @@ -399,7 +432,7 @@ board = esp32dev platform = ${esp32.platform} platform_packages = ${esp32.platform_packages} build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_qio80 #-D WLED_DISABLE_BLYNK #-D WLED_DISABLE_BROWNOUT_DET +build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_qio80 #-D WLED_DISABLE_BROWNOUT_DET lib_deps = ${esp32.lib_deps} monitor_filters = esp32_exception_decoder board_build.partitions = ${esp32.default_partitions} @@ -412,7 +445,7 @@ platform = ${esp32.platform} platform_packages = ${esp32.platform_packages} upload_speed = 921600 build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_Ethernet -D RLYPIN=-1 -D WLED_USE_ETHERNET -D BTNPIN=-1 -D WLED_DISABLE_BLYNK +build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_Ethernet -D RLYPIN=-1 -D WLED_USE_ETHERNET -D BTNPIN=-1 lib_deps = ${esp32.lib_deps} board_build.partitions = ${esp32.default_partitions} @@ -426,27 +459,31 @@ board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv board_build.flash_mode = qio upload_speed = 460800 build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags} ${esp32s2.build_flags} #-D WLED_RELEASE_NAME=S2_saola lib_deps = ${esp32s2.lib_deps} -[env:esp32c3dev] +[env:esp32c3dev] ;WLEDMM, merged with latest change on upstream (renamed from env:esp32c3) board = esp32-c3-devkitm-1 -;platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip -;platform_packages = -platform = ${esp32.platformV4} -platform_packages = ${esp32.platformV4_packages} +platform = ${esp32.platformV4} ;; standard platform, well-tested on -C3, good compatibility with WLED +platform_packages = ${esp32.platformV4_packages} ;; use with standard platform +; platform = espressif32@~5.2.0 ;; alternative platform, might help in case you experience bootloops due to corrupted flash filesystem +; platform_packages = ;; for alternative platform board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=ESP32-C3 - -D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0 - -D WLED_USE_MY_CONFIG - ; -D USERMOD_AUDIOREACTIVE - -D USERMOD_CUSTOMEFFECTS + -D WLED_WATCHDOG_TIMEOUT=0 + ; -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual USB + -DARDUINO_USB_CDC_ON_BOOT=0 ;; no virtual USB + -D CONFIG_LITTLEFS_FOR_IDF_3_2 ; WLEDMM + -D WLED_USE_MY_CONFIG ; WLEDMM + ; -D USERMOD_AUDIOREACTIVE ; WLEDMM + -D USERMOD_ARTIFX ; WLEDMM upload_speed = 460800 build_unflags = ${common.build_unflags} lib_deps = ${esp32c3.lib_deps} ; https://github.com/blazoncek/arduinoFFT.git [env:esp32s3dev_8MB] -;; ESP32-S3-DevKitC-1 development board, with 8MB FLASH, no PSRAM +;; ESP32-S3-DevKitC-1 development board, with 8MB FLASH, no PSRAM (flash_mode: qio) board = esp32-s3-devkitc-1 ;platform = espressif32@5.1.1 ;platform_packages = platformio/framework-arduinoespressif32@3.20004.220825 @@ -458,12 +495,33 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -D CONFIG_LITTLEFS_F -D WLED_RELEASE_NAME=ESP32-S3 -D WLED_USE_MY_CONFIG -D USERMOD_AUDIOREACTIVE - -D USERMOD_CUSTOMEFFECTS + -D USERMOD_ARTIFX lib_deps = ${esp32s3.lib_deps} https://github.com/blazoncek/arduinoFFT.git board_build.partitions = tools/WLED_ESP32_8MB.csv board_build.f_flash = 80000000L board_build.flash_mode = qio +; board_build.flash_mode = dio ;; try this if you have problems at startup +monitor_filters = esp32_exception_decoder + +[env:esp32s3dev_8MB_PSRAM] +;; ESP32-TinyS3 development board, with 8MB FLASH and 8MB PSRAM (memory_type: qio_opi, qio_qspi, or opi_opi) +;board = um_tinys3 ; -> needs workaround from https://github.com/Aircoookie/WLED/pull/2905#issuecomment-1328049860 +;board = esp32s3box ; -> error: 'esp32_adc2gpio' was not declared in this scope +board = esp32-s3-devkitc-1 ; -> compiles, but does not support PSRAM +platform = espressif32 @ ~5.2.0 +platform_packages = +upload_speed = 921600 +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags} ${esp32s3.build_flags} + -D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0 + -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_MSC_ON_BOOT=0 ; -D ARDUINO_USB_CDC_ON_BOOT=0 + ; -D WLED_RELEASE_NAME=ESP32-S3_PSRAM + -D WLED_USE_PSRAM -DBOARD_HAS_PSRAM ; tells WLED that PSRAM shall be used +lib_deps = ${esp32s3.lib_deps} +board_build.partitions = tools/WLED_ESP32_8MB.csv +board_build.f_flash = 80000000L +board_build.flash_mode = qio monitor_filters = esp32_exception_decoder [env:esp8285_4CH_MagicHome] @@ -549,394 +607,42 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_RELEASE_NAME -D HW_PIN_SCL=35 -D HW_PIN_SDA=33 -D HW_PIN_CLOCKSPI=7 - -D HW_PIN_DATASPI=11 + -D HW_PIN_MOSISPI=11 ;WLEDMM renamed from HW_PIN_DATASPI -D HW_PIN_MISOSPI=9 ; -D STATUSLED=15 -D WLED_USE_MY_CONFIG -D USERMOD_AUDIOREACTIVE - -D USERMOD_CUSTOMEFFECTS + -D USERMOD_ARTIFX lib_deps = ${esp32s2.lib_deps} https://github.com/blazoncek/arduinoFFT.git -# ------------------------------------------------------------------------------ -# MoonModules configs -# ------------------------------------------------------------------------------ - -; shared build flags and lib deps for minimum and maximum config -[common_mm] -build_flags_min = - -Wall -Wformat -Woverflow -Wuninitialized -Winit-self -Warray-bounds ; enables more warnings - -Wno-attributes -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations ;disables some stupid warnings - -D WLED_DISABLE_BLYNK ; BLYNK is only provided for backwards compatibility (no new users accepted) - ;-D WLED_DISABLE_BROWNOUT_DET ; enable if you get "brownout detected" errors at startup - -D ABL_MILLIAMPS_DEFAULT=1500 ; 850 not enough for 1024 leds - -D WLED_USE_MY_CONFIG - -D USERMOD_AUDIOREACTIVE - -D UM_AUDIOREACTIVE_USE_NEW_FFT ; use latest (upstream) FFTLib, instead of older library midified by blazoncek. Slightly faster, more accurate, needs 2KB RAM extra - -D USERMOD_CUSTOMEFFECTS ; WLEDMM usermod - ; -D WLED_DEBUG ; lots of generic debug messages - ; -D SR_DEBUG ; some extra debug messages from audioreactive - ; -D MIC_LOGGER ; for sound input monitoring & debugging (use arduino serial plotter) - ; -D WLED_DISABLE_LOXONE - ; -D WLED_DISABLE_ALEXA - ; -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_MQTT - ; -D WLED_DISABLE_INFRARED - ; -D WLED_ENABLE_DMX - -lib_deps_min = - https://github.com/kosme/arduinoFFT#develop @ 1.9.2 ; used for USERMOD_AUDIOREACTIVE - -; monitor_filters = esp32_exception_decoder ; used to show crash details - -build_flags_max = - -D WLED_MAX_USERMODS=9 ; default only 4-6 - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4 ewowi to softhack: move to build_flags_min? - -D WLED_USE_MY_CONFIG ; include custom my_config.h ewowi to softhack: redundant as also in build_flags_min? - -D USERMOD_DALLASTEMPERATURE - -D USE_ALT_DISPlAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI - -D USERMOD_FOUR_LINE_DISPLAY - -D USERMOD_ROTARY_ENCODER_UI - -D USERMOD_AUTO_SAVE - -D USERMOD_WEATHER ; WLEDMM usermod - -D USERMOD_MPU6050_IMU ; gyro/accelero for USERMOD_GAMES (ONLY WORKS IF USERMOD_FOUR_LINE_DISPLAY NOT INCLUDED - I2C SHARING BUG) - -D USERMOD_GAMES ; WLEDMM usermod - -lib_deps_max = - OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE - olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY - ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU - -; end of common - -; base entries (without WLED_RELEASE_NAME) - -; esp32_4MB_min_base: basis for min entries and for max_base -[esp32_4MB_min_base] -board = esp32dev -platform = ${esp32.platform} -upload_speed = 460800 ; or 921600 -platform_packages = ${esp32.platform_packages} -build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp32} ${common_mm.build_flags_min} -lib_deps = ${esp32.lib_deps} ${common_mm.lib_deps_min} -board_build.partitions = ${esp32.default_partitions} -board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) -board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o) - -;esp32_4MB_max_base: basis for max entries, uses esp32_4MB_min_base, build_flags_max and lib_deps_max -[esp32_4MB_max_base] -extends = esp32_4MB_min_base -build_flags = ${esp32_4MB_min_base.build_flags} ${common_mm.build_flags_max} -lib_deps = ${esp32_4MB_min_base.lib_deps} ${common_mm.lib_deps_max} -board_build.partitions = ${esp32_4MB_min_base.board_build.partitions} -; board_build.partitions = tools/WLED_ESP32-wrover_4MB.csv - -;esp32_4MB_V4_max_base: basis for V4 entries, uses build_flags_min, build_flags_max, lib_deps_min and lib_deps_max -[esp32_4MB_V4_min_base] -board = esp32dev -upload_speed = 460800 ; or 921600 -platform = ${esp32.platformV4} -platform_packages = ${esp32.platformV4_packages} -build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${common_mm.build_flags_min} - -Wno-misleading-indentation -lib_deps = ${esp32.lib_depsV4} ${common_mm.lib_deps_min} -board_build.partitions = ${esp32.default_partitions} -board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) -board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o) -;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation - -[esp32_4MB_V4_max_base] -extends = esp32_4MB_V4_min_base -build_flags = ${esp32_4MB_V4_min_base.build_flags} ${common_mm.build_flags_max} -lib_deps = ${esp32_4MB_V4_min_base.lib_deps} ${common_mm.lib_deps_max} -board_build.partitions = ${esp32_4MB_V4_min_base.board_build.partitions} -;board_build.flash_mode = qio ; (dio = dual i/o; more compatible than qio = quad i/o) - -; end of base entries - -; bin entries (with WLED_RELEASE_NAME) - -; esp32_4MB_min: bin entry, uses esp32_4MB_min_base -[env:esp32_4MB_min] -extends = esp32_4MB_min_base -build_flags = ${esp32_4MB_min_base.build_flags} - -D WLED_RELEASE_NAME=esp32_4MB_min ; This will be included in the firmware.bin filename - ; RAM: [== ] 24.1% (used 78900 bytes from 327680 bytes) - ; Flash: [======== ] 83.7% (used 1315729 bytes from 1572864 bytes) - ; -D WLED_DISABLE_LOXONE - ; -D WLED_DISABLE_ALEXA - ; -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_MQTT - ; -D WLED_DISABLE_INFRARED - ; -D WLED_ENABLE_DMX - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER - -; esp32_4MB_max: bin entry, uses esp32_4MB_max_base -[env:esp32_4MB_max] -extends = esp32_4MB_max_base -build_flags = ${esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_4MB_max ; This will be included in the firmware.bin filename - ; RAM: [== ] 24.4% (used 79804 bytes from 327680 bytes) - ; Flash: [========= ] 88.7% (used 1394813 bytes from 1572864 bytes) - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER - -; esp32_16MB_max: bin entry, uses esp32_4MB_max_base and adds 16MB settings -[env:esp32_16MB_max] -extends = esp32_4MB_max_base -board = esp32_twilord ; "TwilightLord" ESP32 with 16MB Flash -board_build.partitions = tools/WLED_ESP32_16MB.csv ; for esp32_twilord with 16MB flash -build_flags = ${esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_16MB_max ; This will be included in the firmware.bin filename - ; RAM: [== ] 24.4% (used 79804 bytes from 327680 bytes) - ; Flash: [======= ] 66.5% (used 1394813 bytes from 2097152 bytes) - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER - ; -D WLED_DISABLE_LOXONE - ; -D WLED_DISABLE_ALEXA - ; -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_MQTT - ; -D WLED_DISABLE_INFRARED -;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation - -; esp8266_4MB_min: bin entry for 8266, with 2D (WIP) -[env:esp8266_4MB_min] -extends = env:d1_mini -upload_speed = 460800 ;115200 -build_flags = ${common.build_flags_esp8266} - -D WLED_RELEASE_NAME=esp8266_4MB_min ; This will be included in the firmware.bin filename - ; -D WLED_DEBUG - -D WLED_DISABLE_ALEXA - -D WLED_DISABLE_BLYNK - -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_2D - ; -D USERMOD_AUDIOREACTIVE - ; -D USERMOD_CUSTOMEFFECTS ; to be done - -UWLED_USE_MY_CONFIG -; monitor_filters = esp8266_exception_decoder -; RAM: [====== ] 58.7% (used 48056 bytes from 81920 bytes) -; Flash: [======== ] 75.7% (used 790428 bytes from 1044464 bytes) - -# ------------------------------------------------------------------------------ -# MoonModules configs for IDF V4.4.x -# ------------------------------------------------------------------------------ -;; Warning: the build-in LittleFS (arduino-esp32 2.0.x) seems to be "slightly different" from Lorol LittleFS. -;; When upgrading to the new framework, it might be necessary to first do a chip erase (make sure you have a backup of cfg.json and presets.json) - -; esp32_4MB_V4_min: bin entry compiled with ESP-IDF 4.4.1, uses esp32_4MB_V4_min_base -[env:esp32_4MB_V4_min] -extends = esp32_4MB_V4_min_base -build_flags = ${esp32_4MB_V4_min_base.build_flags} - -D WLED_RELEASE_NAME=esp32_4MB_V4_min ; This will be included in the firmware.bin filename - -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup - -D WLED_DISABLE_LOXONE - -D WLED_DISABLE_ALEXA - -D WLED_DISABLE_HUESYNC - -D WLED_DISABLE_MQTT - -D WLED_DISABLE_INFRARED - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER - ; RAM: [== ] 24.2% (used 79372 bytes from 327680 bytes) - ; Flash: [========= ] 88.8% (used 1396073 bytes from 1572864 bytes) -;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation - -; esp32_4MB_V4_max: bin entry compiled with ESP-IDF 4.4.1, uses esp32_4MB_V4_max_base -[env:esp32_4MB_V4_max] -extends = esp32_4MB_V4_max_base -build_flags = ${esp32_4MB_V4_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_4MB_V4_max ; This will be included in the firmware.bin filename - -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup - ; RAM: [== ] 24.8% (used 81316 bytes from 327680 bytes) - ; Flash: [==========] 97.2% (used 1528253 bytes from 1572864 bytes) - -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes - -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes - -D WLED_DISABLE_HUESYNC ;RAM 122 bytes; FLASH 6308 bytes - ; RAM: [== ] 24.7% (used 81076 bytes from 327680 bytes) - ; Flash: [==========] 95.8% (used 1506893 bytes from 1572864 bytes) - ;-D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes - ;-D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes -;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation - -; esp32_16MB_max: bin entry compiled with ESP-IDF 4.4.1, uses esp32_4MB_V4_max_base and adds 16MB settings -[env:esp32_16MB_V4_max] -extends = esp32_4MB_V4_max_base -board = esp32_twilord ; "TwilightLord" ESP32 with 16MB Flash -board_build.partitions = tools/WLED_ESP32_16MB.csv ; for esp32_twilord with 16MB flash -build_flags = ${esp32_4MB_V4_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_16MB_V4_max ; This will be included in the firmware.bin filename - -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup - ; RAM: [== ] 24.8% (used 81316 bytes from 327680 bytes) - ; Flash: [======= ] 72.9% (used 1528253 bytes from 2097152 bytes) - -;; experimental environment for boards with PSRAM (needs ESP-IDF 4.4.1). -; esp32_4MB_PSRAM_max: bin entry, uses esp32_4MB_V4_max_base and adds specific settings -[env:esp32_4MB_PSRAM_max] -extends = esp32_4MB_V4_max_base -board = lolin_d32_pro -;board = esp32cam -build_flags = ${esp32_4MB_V4_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_4MB_PSRAM_max - -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET - -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup - -D WLED_USE_PSRAM - ; RAM: [== ] 24.8% (used 81424 bytes from 327680 bytes) - ; Flash: [==========] 99.8% (used 1570457 bytes from 1572864 bytes) - ; 99.8% !!!! - -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes - -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes - -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes - -D WLED_DISABLE_HUESYNC ;RAM 122 bytes; FLASH 6308 bytes - ; RAM: [== ] 24.7% (used 80948 bytes from 327680 bytes) - ; Flash: [==========] 97.4% (used 1532485 bytes from 1572864 bytes) - ;-D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes - ; -D WLED_ENABLE_DMX - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER - -; esp32S3_8MB_max: bin entry, uses esp32_4MB_V4_max_base and adds specific settings. Override of lib_deps using lib_deps_min and lib_deps_max -[env:esp32S3_8MB_max] -extends = esp32_4MB_V4_max_base -board = esp32-s3-devkitc-1 -build_flags = ${esp32_4MB_V4_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32S3_8MB_max - -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=0 -D ARDUINO_USB_MSC_ON_BOOT=0 -D ARDUINO_USB_DFU_ON_BOOT=0 - -D WLED_WATCHDOG_TIMEOUT=0 - -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes - -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes - -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes - -D WLED_DISABLE_HUESYNC ;RAM 122 bytes; FLASH 6308 bytes - -D LEDPIN=4 - -D STATUSLED=39 - -D BTNPIN=-1 - -D RLYPIN=-1 - -D IRPIN=-1 - -D HW_PIN_SDA=40 - -D HW_PIN_SCL=41 - -D AUDIOPIN=-1 - -D SR_DMTYPE=1 - -D I2S_SDPIN=16 - -D I2S_CKPIN=17 - -D I2S_WSPIN=47 - -D ES7243_SDAPIN=8 - -D ES7243_SCLPIN=18 - ; -D WLED_DEBUG - ; -D SR_DEBUG - ; -D MIC_LOGGER -lib_deps = ${esp32s3.lib_deps} ${common_mm.lib_deps_min} ${common_mm.lib_deps_max} -board_build.partitions = tools/WLED_ESP32_8MB.csv -board_build.flash_mode = qio -; RAM: [== ] 24.7% (used 80984 bytes from 327680 bytes) -; Flash: [======= ] 69.0% (used 1447873 bytes from 2097152 bytes) - # ------------------------------------------------------------------------------ # custom board configurations # ------------------------------------------------------------------------------ -;wemos_shield_esp32_4MB_max_base: base entry, uses esp32_4MB_max_base -[wemos_shield_esp32_4MB_max_base] -extends = esp32_4MB_max_base -build_flags = ${esp32_4MB_max_base.build_flags} - -D LEDPIN=16 - -D RLYPIN=19 - -D BTNPIN=17 - -D IRPIN=18 - -D AUDIOPIN=-1 - -D TEMPERATURE_PIN=23 - -D FLD_PIN_SCL=22 -D FLD_PIN_SDA=21 - -D HW_PIN_SCL=22 -D HW_PIN_SDA=21 - ; -D ENCODER_DT_PIN=18 -D ENCODER_CLK_PIN=5 -D ENCODER_SW_PIN=19 - ; -D WLED_USE_MY_CONFIG - ; -D WLED_DISABLE_LOXONE - ; -D WLED_DISABLE_ALEXA - ; -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_MQTT - ; -D WLED_DISABLE_INFRARED - ; -D WLED_ENABLE_DMX - -;wemos_shield_esp32_4MB_max: bin entry, uses wemos_shield_esp32_4MB_max_base -[env:wemos_shield_esp32_4MB_max] -extends = wemos_shield_esp32_4MB_max_base -build_flags = ${wemos_shield_esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_max ; This will be included in the firmware.bin filename - ; -D SR_DMTYPE=1 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=14 ;; for regular I2S microphone softhack: can be removed because this is default in code -; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) -; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) - -[env:wemos_shield_esp32_4MB_ICS4343x_max] -extends = wemos_shield_esp32_4MB_max_base -build_flags = ${wemos_shield_esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_ICS4343x_max ; This will be included in the firmware.bin filename - ; -D SR_DMTYPE=1 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=14 ;; for regular I2S microphone softhack: can be removed because this is default in code - -D SR_SQUELCH=10 -D SR_GAIN=30 -D SR_FREQ_PROF=5 ; ICS-43434 specific -; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) -; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) - -[env:wemos_shield_esp32_4MB_SPM1423_max] -extends = wemos_shield_esp32_4MB_max_base -build_flags = ${wemos_shield_esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_SPM1423_max ; This will be included in the firmware.bin filename - -D SR_DMTYPE=5 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=-1 ; for I2S PDM microphone - -D SR_SQUELCH=3 -D SR_GAIN=75 -D SR_FREQ_PROF=7 ; SPM1423 specific -; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) -; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) - -[env:wemos_shield_esp32_4MB_LineIn_max] -extends = wemos_shield_esp32_4MB_max_base -build_flags = ${wemos_shield_esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_LineIn_max ; This will be included in the firmware.bin filename - -D SR_DMTYPE=4 -D MCLK_PIN=0 -D I2S_SDPIN=25 -D I2S_WSPIN=15 -D I2S_CKPIN=14 ; for audio Line-In shield - -D SR_SQUELCH=2 -D SR_GAIN=40 -D SR_FREQ_PROF=1 ; CS5343 Line-In specific - -;wemos_shield_esp32_16MB_max: bin entry, uses wemos_shield_esp32_4MB_max_base and adds 16MB settings -[env:wemos_shield_esp32_16MB_max] -extends = wemos_shield_esp32_4MB_max_base -board = esp32_twilord ; "TwilightLord" ESP32 with 16MB Flash -board_build.partitions = tools/WLED_ESP32_16MB.csv ; for esp32_twilord with 16MB flash -build_flags = ${wemos_shield_esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_max ; This will be included in the firmware.bin filename -; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) -; Flash: [======= ] 66.4% (used 1393421 bytes from 2097152 bytes) - -; ESP32 WLED pico board with builtin ICS-43432 microphpone -[env:esp32_pico_4MB_max] -extends = esp32_4MB_max_base -board = pico32 -build_flags = ${esp32_4MB_max_base.build_flags} - -D WLED_RELEASE_NAME=esp32_pico_4MB_max ; This will be included in the firmware.bin filename - -D WLED_DISABLE_BROWNOUT_DET - -D SERVERNAME='"WLED-pico32"' - ; -D WLED_WATCHDOG_TIMEOUT=60 - ; -D WLED_DEBUG - ; -D SR_DEBUG - -D LEDPIN=2 - -D RLYPIN=-1 - -D BTNPIN=-1 - -D IRPIN=-1 - -D HW_PIN_SCL=22 -D HW_PIN_SDA=21 - -D SR_DMTYPE=1 -D I2S_SDPIN=25 -D I2S_WSPIN=15 -D I2S_CKPIN=14 - -D SR_SQUELCH=5 -D SR_GAIN=30 -D SR_FREQ_PROF=5 ; ICS-43434 specific - ; -D MCLK_PIN=0 - ; -D WLED_USE_MY_CONFIG - ; -D WLED_DISABLE_LOXONE - ; -D WLED_DISABLE_ALEXA - ; -D WLED_DISABLE_HUESYNC - ; -D WLED_DISABLE_MQTT - ; -D WLED_DISABLE_INFRARED - ; -D WLED_ENABLE_DMX -; RAM: [== ] 24.4% (used 79804 bytes from 327680 bytes) -; Flash: [========= ] 88.6% (used 1394241 bytes from 1572864 bytes) +; WLEDMM see below +; [env:wemos_shield_esp32] +; board = esp32dev +; platform = espressif32@3.2 +; upload_speed = 460800 +; build_unflags = ${common.build_unflags} +; build_flags = ${common.build_flags_esp32} +; -D LEDPIN=16 +; -D RLYPIN=19 +; -D BTNPIN=17 +; -D IRPIN=18 +; -D UWLED_USE_MY_CONFIG +; -D USERMOD_DALLASTEMPERATURE +; -D USERMOD_FOUR_LINE_DISPLAY +; -D TEMPERATURE_PIN=23 +; -D USE_ALT_DISPlAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI +; -D USERMOD_AUDIOREACTIVE +; lib_deps = ${esp32.lib_deps} +; OneWire@~2.3.5 +; olikraus/U8g2 @ ^2.28.8 +; https://github.com/blazoncek/arduinoFFT.git +; board_build.partitions = ${esp32.default_partitions} [env:m5atom] board = esp32dev @@ -960,20 +666,58 @@ board_build.ldscript = ${common.ldscript_2m512k} build_flags = ${common.build_flags_esp8266} -D LEDPIN=3 -D BTNPIN=2 -D IRPIN=5 -D WLED_MAX_BUTTONS=3 lib_deps = ${esp8266.lib_deps} -[env:athom7w] -board = esp_wroom_02 +[env:Athom_RGBCW] ;7w and 5w(GU10) bulbs +board = esp8285 platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_2m512k} -build_flags = ${common.build_flags_esp8266} -D WLED_MAX_CCT_BLEND=0 -D BTNPIN=-1 -D IRPIN=-1 -D WLED_DISABLE_INFRARED +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 -D BTNPIN=-1 -D RLYPIN=-1 -D DATA_PINS=4,12,14,13,5 + -D DEFAULT_LED_TYPE=TYPE_ANALOG_5CH -D WLED_DISABLE_INFRARED -D WLED_MAX_CCT_BLEND=0 lib_deps = ${esp8266.lib_deps} -[env:athom15w] -board = esp_wroom_02 + +[env:Athom_15w_RGBCW] ;15w bulb +board = esp8285 platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} board_build.ldscript = ${common.ldscript_2m512k} -build_flags = ${common.build_flags_esp8266} -D WLED_USE_IC_CCT -D BTNPIN=-1 -D IRPIN=-1 -D WLED_DISABLE_INFRARED +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 -D BTNPIN=-1 -D RLYPIN=-1 -D DATA_PINS=4,12,14,5,13 + -D DEFAULT_LED_TYPE=TYPE_ANALOG_5CH -D WLED_DISABLE_INFRARED -D WLED_MAX_CCT_BLEND=0 -D WLED_USE_IC_CCT lib_deps = ${esp8266.lib_deps} + +[env:Athom_3Pin_Controller] ;small controller with only data +board = esp8285 +platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} +board_build.ldscript = ${common.ldscript_2m512k} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 -D BTNPIN=0 -D RLYPIN=-1 -D LEDPIN=1 -D WLED_DISABLE_INFRARED +lib_deps = ${esp8266.lib_deps} + + +[env:Athom_4Pin_Controller] ; With clock and data interface +board = esp8285 +platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} +board_build.ldscript = ${common.ldscript_2m512k} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 -D BTNPIN=0 -D RLYPIN=12 -D LEDPIN=1 -D WLED_DISABLE_INFRARED +lib_deps = ${esp8266.lib_deps} + + +[env:Athom_5Pin_Controller] ;Analog light strip controller +board = esp8285 +platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} +board_build.ldscript = ${common.ldscript_2m512k} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 -D BTNPIN=0 -D RLYPIN=-1 DATA_PINS=4,12,14,13 -D WLED_DISABLE_INFRARED +lib_deps = ${esp8266.lib_deps} + + [env:MY9291] board = esp01_1m platform = ${common.platform_wled_default} @@ -983,22 +727,6 @@ build_unflags = ${common.build_unflags} build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP01 -D WLED_DISABLE_OTA -D USERMOD_MY9291 lib_deps = ${esp8266.lib_deps} -# ------------------------------------------------------------------------------ -# travis test board configurations -# ------------------------------------------------------------------------------ - -[env:travis_esp8266] -extends = env:d1_mini -build_type = debug -build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp8266} ${common.debug_flags} ${common.build_flags_all_features} - -[env:travis_esp32] -extends = env:esp32dev -; build_type = debug -build_unflags = ${common.build_unflags} -build_flags = ${common.build_flags_esp32} ${common.debug_flags} ${common.build_flags_all_features} - # ------------------------------------------------------------------------------ # codm pixel controller board configurations # codm-controller-0.6 can also be used for the TYWE3S controller @@ -1035,7 +763,6 @@ build_flags = ${common.build_flags_esp32} -D WLED_DISABLE_BROWNOUT_DET -D WLED_D -D LEDPIN=12 -D RLYPIN=27 -D BTNPIN=34 - -D WLED_DISABLE_BLYNK -D DEFAULT_LED_COUNT=6 # Display config -D ST7789_DRIVER @@ -1054,3 +781,920 @@ lib_deps = ${esp32.lib_deps} TFT_eSPI @ ^2.3.70 board_build.partitions = ${esp32.default_partitions} + + + + + + + +# ------------------------------------------------------------------------------ +# MoonModules environments +# see https://mm.kno.wled.ge/moonmodules/platformio-entries/ +# ------------------------------------------------------------------------------ + +; shared build flags and lib deps for minimum and maximum environment +[common_mm] +build_flags_S = + -Wall -Wformat -Woverflow -Wuninitialized -Winit-self -Warray-bounds ; enables more warnings + -Wno-attributes -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations ;disables some stupid warnings + ;-D WLED_DISABLE_BROWNOUT_DET ; enable if you get "brownout detected" errors at startup + -D WLED_USE_MY_CONFIG + ; -D WLED_USE_CIE_BRIGHTNESS_TABLE ;; experimental: use different color / brightness lookup table + -D USERMOD_AUDIOREACTIVE + -D UM_AUDIOREACTIVE_USE_NEW_FFT ; use latest (upstream) FFTLib, instead of older library modified by blazoncek. Slightly faster, more accurate, needs 2KB RAM extra + -D USERMOD_ARTIFX ; WLEDMM usermod + ; -D WLED_DISABLE_LOXONE + ; -D WLED_DISABLE_ALEXA + ; -D WLED_DISABLE_HUESYNC + ; -D WLED_DISABLE_MQTT + ; -D WLED_DISABLE_INFRARED + ; -D WLED_ENABLE_DMX + +lib_deps_S = + https://github.com/kosme/arduinoFFT#develop @ 1.9.2 ; used for USERMOD_AUDIOREACTIVE + +build_flags_M = + -D WLED_MAX_USERMODS=25 ; default only 4-6, also for _XL configs takes 25 pointers in memory + ;; -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4 ewowi to softhack: move to build_flags_S? - We need a different solution + -D WLED_USE_MY_CONFIG ; include custom my_config.h ewowi to softhack: redundant as also in build_flags_S? + -D USERMOD_DALLASTEMPERATURE + -D USE_ALT_DISPLAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI + -D USERMOD_FOUR_LINE_DISPLAY + -D USERMOD_ROTARY_ENCODER_UI + -D USERMOD_AUTO_SAVE + -D USERMOD_WEATHER ; WLEDMM usermod + -D USERMOD_MPU6050_IMU ; gyro/accelero for USERMOD_GAMES (ONLY WORKS IF USERMOD_FOUR_LINE_DISPLAY NOT INCLUDED - I2C SHARING BUG) + -D USERMOD_GAMES ; WLEDMM usermod + ;WLEDMM: only setting WLED_DEBUG_HOST is enough, ip and port can be defined in sync settings as well + -D WLED_DEBUG_HOST='"192.168.x.x"' ;; to send debug messages over network to host 192.168.x.y - FQDN is also possible + -D WLED_DEBUG_PORT=1768 ;; port for network debugging. default = 7868 + +lib_deps_M = + ;https://github.com/blazoncek/OneWire.git ; includes bugfixes for inconsistent readings + OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE + olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY + ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU + +lib_deps_V4_M = + ;https://github.com/blazoncek/OneWire.git ; includes bugfixes for inconsistent readings + paulstoffregen/OneWire@ ^2.3.7 ; used for USERMOD_DALLASTEMPERATURE -> need newer release with bugfixes for -S3; still requires TEMPERATURE_PIN < 46 + olikraus/U8g2@ ^2.34.5 ; used for USERMOD_FOUR_LINE_DISPLAY -> need newer version with bugfixes for arduino-esp32 v2.0.4 (Wire inititialization) + ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU + claws/BH1750 @^1.2.0 ; used for USERMOD_BH1750 + +build_flags_XL = + -D USERMOD_BATTERY ;; enable Battery usermod + -D USERMOD_BATTERY_USE_LIPO ;; use new "decharging curve" for LiPo cells + -D USERMOD_BH1750 + -D USERMOD_ANIMATED_STAIRCASE + -D USERMOD_RTC ;; experimental + ; -D USERMOD_SENSORSTOMQTT ;; experimental ewowi causes error: fatal error: Adafruit_Sensor.h: No such file or directory + -D USERMOD_ANALOG_CLOCK + -D USERMOD_MULTI_RELAY + -D USERMOD_PIRSWITCH + -D USERMOD_PWM_FAN + ; -D USERMOD_PING_PONG_CLOCK //Removed as dots is confusing + -D USERMOD_BUZZER + -D USERMOD_SN_PHOTORESISTOR + -D USERMOD_BME280 + -D USERMOD_DHT + -D USERMOD_VL53L0X_GESTURES + -D WLED_ENABLE_PIXART + +lib_deps_XL = + claws/BH1750 @^1.2.0 ; used for USERMOD_BH1750 + ; adafruit/Adafruit BMP280 Library @ 2.1.0 ;; experimental for usermod USERMOD_SENSORSTOMQTT + ; adafruit/Adafruit CCS811 Library @ 1.0.4 ;; experimental for usermod USERMOD_SENSORSTOMQTT + ; adafruit/Adafruit Si7021 Library @ 1.4.0 ;; experimental for usermod USERMOD_SENSORSTOMQTT + BME280@~3.0.0 ; for usermod USERMOD_BME280 + https://github.com/alwynallan/DHT_nonblocking ; for usermod USERMOD_DHT + pololu/VL53L0X @ ^1.3.0 ; for usermod USERMOD_VL53L0X_GESTURES + +; end of common + +; base entries (without WLED_RELEASE_NAME) + +; common defaults for all MM environments +[esp32_4MB_S_base] +board = esp32dev +platform = ${esp32.platform} +upload_speed = 460800 ; or 921600 +platform_packages = ${esp32.platform_packages} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp32} ${common_mm.build_flags_S} +lib_deps = ${esp32.lib_deps} ${common_mm.lib_deps_S} +board_build.partitions = ${esp32.default_partitions} +board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) +board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o) + +;common default for all max environments +[esp32_4MB_M_base] +extends = esp32_4MB_S_base +build_flags = ${esp32_4MB_S_base.build_flags} ${common_mm.build_flags_M} +lib_deps = ${esp32_4MB_S_base.lib_deps} ${common_mm.lib_deps_M} +; board_build.partitions = tools/WLED_ESP32-wrover_4MB.csv + +[esp32_4MB_XL_base] +extends = esp32_4MB_M_base +build_flags = ${esp32_4MB_M_base.build_flags} ${common_mm.build_flags_XL} +lib_deps = ${esp32_4MB_M_base.lib_deps} ${common_mm.lib_deps_XL} +; board_build.partitions = tools/WLED_ESP32-wrover_4MB.csv + +;common default for all V4 min environments +[esp32_4MB_V4_S_base] +board = esp32dev +upload_speed = 460800 ; or 921600 +platform = ${esp32.platformV4} +platform_packages = ${esp32.platformV4_packages} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags} ${esp32.build_flagsV4} ${common_mm.build_flags_S} + -Wno-misleading-indentation -Wno-format-truncation +lib_deps = ${esp32.lib_depsV4} ${common_mm.lib_deps_S} +board_build.partitions = ${esp32.default_partitions} +board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) +board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o) +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +; monitor_filters = esp32_exception_decoder ; used to show crash details + +[esp32_4MB_V4_M_base] +extends = esp32_4MB_V4_S_base +build_flags = ${esp32_4MB_V4_S_base.build_flags} ${common_mm.build_flags_M} +lib_deps = ${esp32_4MB_V4_S_base.lib_deps} ${common_mm.lib_deps_V4_M} +board_build.partitions = ${esp32_4MB_V4_S_base.board_build.partitions} +;board_build.flash_mode = qio ; (dio = dual i/o; more compatible than qio = quad i/o) + +[Shield_ICS4343x] +build_flags = + -D SR_DMTYPE=1 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=14 ; for regular I2S microphone + -D SR_SQUELCH=10 -D SR_GAIN=30 -D SR_FREQ_PROF=5 ; ICS-43434 specific + +[Shield_SPM1423] +build_flags = + -D SR_DMTYPE=5 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=-1 ; for I2S PDM microphone + -D SR_SQUELCH=3 -D SR_GAIN=75 -D SR_FREQ_PROF=7 ; SPM1423 specific + +[Athom_PDMmic] +build_flags = + -D SR_DMTYPE=51 -D I2S_SDPIN=32 -D I2S_WSPIN=15 -D I2S_CKPIN=-1 ; for I2S PDM microphone Legacy mode! + -D SR_SQUELCH=10 -D SR_GAIN=40 -D SR_FREQ_PROF=7 ; SPM1423 specific + +[Shield_LineIn] +build_unflags = + -D BTNPIN=17 ;; remove - its in conflict with on-shield rotary + -D ENCODER_SW_PIN=5 ;; remove - its in conflict with on-shield rotary + -D BTNPIN=0 ;; remove - its in conflict with MCLK pin +build_flags = + -D BTNPIN=-1 + -D SR_DMTYPE=4 -D MCLK_PIN=0 -D I2S_SDPIN=26 -D I2S_WSPIN=25 -D I2S_CKPIN=27 ; for audio Line-In shield, final version + -D SR_LINE_DETECT=34 ; line-in plug insert detection sensor (future support) + -D SR_SQUELCH=8 -D SR_GAIN=40 -D SR_FREQ_PROF=1 ; CS5343 Line-In specific + -D ENCODER_DT_PIN=35 -D ENCODER_CLK_PIN=39 -D ENCODER_SW_PIN=17 ; on-shield rotary encoder + +[Debug_Flags] +build_flags = + -D WLED_DEBUG ; lots of generic debug messages + -D SR_DEBUG ; some extra debug messages from audioreactive + ; -D MIC_LOGGER ; for sound input monitoring & debugging (use arduino serial plotter) + ; NetDebug moved to build_flags_M + + +; end of base entries + + +; bin entries (with WLED_RELEASE_NAME) + +[env:esp32_4MB_S] +extends = esp32_4MB_S_base +build_flags = ${esp32_4MB_S_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_S +; RAM: [== ] 24.1% (used 78988 bytes from 327680 bytes) +; Flash: [========= ] 85.7% (used 1348593 bytes from 1572864 bytes) WLEDMM: Earlier 83.7 + +[env:esp32_4MB_M] +extends = esp32_4MB_M_base +build_flags = ${esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_M +; RAM: [== ] 24.4% (used 79956 bytes from 327680 bytes) +; Flash: [========= ] 91.1% (used 1432245 bytes from 1572864 bytes) WLEDMM: earlier 88.7 + +[env:esp32_4MB_XL] +extends = esp32_4MB_XL_base +build_flags = ${esp32_4MB_XL_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_XL +; RAM: [== ] 24.4% (used 80060 bytes from 327680 bytes) +; Flash: [==========] 95.3% (used 1499037 bytes from 1572864 bytes) + +[env:esp32_16MB_M] +extends = esp32_4MB_M_base +build_flags = ${esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_16MB_M +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem + ; RAM: [== ] 24.4% (used 79916 bytes from 327680 bytes) + ; Flash: [======= ] 67.0% (used 1405701 bytes from 2097152 bytes) +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + +[env:esp32_4MB_M_debug] +extends = esp32_4MB_M_base +build_unflags = ${common.build_unflags} + -D CORE_DEBUG_LEVEL=0 +build_flags = ${esp32_4MB_M_base.build_flags} + ${Debug_Flags.build_flags} + -D CORE_DEBUG_LEVEL=2 ;; 2=warning + -D WLED_RELEASE_NAME=esp32_4MB_M_debug +monitor_filters = esp32_exception_decoder +; RAM: [== ] 24.5% (used 80292 bytes from 327680 bytes) +; Flash: [========= ] 94.5% (used 1487113 bytes from 1572864 bytes) + +[env:esp32_16MB_M_debug] +extends = esp32_4MB_M_base +build_unflags = ${common.build_unflags} + -D CORE_DEBUG_LEVEL=0 +build_flags = ${esp32_4MB_M_base.build_flags} + ${Debug_Flags.build_flags} + -D CORE_DEBUG_LEVEL=2 ;; 2=warning + -D WLED_RELEASE_NAME=esp32_16MB_M_debug +monitor_filters = esp32_exception_decoder +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +; RAM: [== ] 24.5% (used 80292 bytes from 327680 bytes) +; Flash: [======= ] 70.9% (used 1487129 bytes from 2097152 bytes) + +[env:esp32_16MB_XL] +extends = esp32_4MB_XL_base +build_flags = ${esp32_4MB_XL_base.build_flags} + -D WLED_RELEASE_NAME=esp32_16MB_XL +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem + ; RAM: [== ] 24.4% (used 79916 bytes from 327680 bytes) + ; Flash: [======= ] 67.0% (used 1405701 bytes from 2097152 bytes) +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + +[env:esp32_16MB_M_eth] +extends = esp32_4MB_M_base +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +board = esp32_16MB-poe ;; needed for ethernet boards (selects "esp32-poe" as variant) +build_flags = ${esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_16MB_M_eth ; This will be included in the firmware.bin filename + -D WLED_USE_ETHERNET +; RAM: [== ] 24.5% (used 80348 bytes from 327680 bytes) +; Flash: [======= ] 69.4% (used 1455233 bytes from 2097152 bytes) + +[env:esp8266_4MB_S] +extends = env:d1_mini +upload_speed = 460800 ;115200 +board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz) +build_flags = ${common.build_flags_esp8266} + -D WLED_RELEASE_NAME=esp8266_4MB_S + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + ; -D WLED_DISABLE_2D + ; -UWLED_USE_MY_CONFIG + ; -D WLED_DEBUG +; monitor_filters = esp8266_exception_decoder +; RAM: [====== ] 59.3% (used 48608 bytes from 81920 bytes) +; Flash: [======== ] 77.0% (used 804176 bytes from 1044464 bytes) + +[env:esp8266_4MB_M] +extends = env:d1_mini +upload_speed = 460800 ;115200 +board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz) +build_flags = ${common.build_flags_esp8266} + -D WLED_RELEASE_NAME=esp8266_4MB_M + -D WLED_MAX_USERMODS=5 ; default only 4-6 + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_LOXONE + ; -D USERMOD_AUDIOREACTIVE + ; -D USERMOD_ARTIFX ; to be done + ; -UWLED_USE_MY_CONFIG + -D USERMOD_PIRSWITCH + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) + -D USERMOD_MULTI_RELAY + -D USE_ALT_DISPLAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI + -D USERMOD_FOUR_LINE_DISPLAY + -D USERMOD_MPU6050_IMU ; gyro/accelero for USERMOD_GAMES (ONLY WORKS IF USERMOD_FOUR_LINE_DISPLAY NOT INCLUDED - I2C SHARING BUG) + -D USERMOD_GAMES ; WLEDMM usermod + ; -D WLED_DEBUG +; monitor_filters = esp8266_exception_decoder +lib_deps = ${esp8266.lib_deps} + OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE + olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY + ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU +; RAM: [====== ] 61.5% (used 50344 bytes from 81920 bytes) +; Flash: [======== ] 81.8% (used 854444 bytes from 1044464 bytes) + +; Blaz env (for reference purposes) +[env:d1_mini_temp] +extends = env:d1_mini +board_build.filesystem = littlefs +build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_LOXONE + -D WLED_DISABLE_AUDIO ;WLEDMM not used anywhere + -D WLED_ENABLE_SIMPLE_UI + -D USERMOD_FOUR_LINE_DISPLAY + -D USE_ALT_DISPlAY + -D USERMOD_DALLASTEMPERATURE + -D TEMPERATURE_PIN=13 # (D7) + -D LEDPIN=2 # (D4) + -D RLYPIN=12 # (D6) + -D BTNPIN=0 # (D3) + -D IRPIN=14 # (D5) + -D USERMOD_MULTI_RELAY + -D MULTI_RELAY_MAX_RELAYS=2 + -D USERMOD_PIRSWITCH + -D PIR_SENSOR_PIN=16 + -D PIR_SENSOR_OFF_SEC=60 + -UWLED_USE_MY_CONFIG +lib_deps = ${esp8266.lib_deps} + paulstoffregen/OneWire@~2.3.7 ;WLEDMM Softhack, we need this as well (instead of 2.3.5)? + olikraus/U8g2 # @~2.33.15 + Wire ; WLEDMM needed? + +[env:esp8266pro_16MB_S] +extends = env:d1_mini +board = d1_mini_pro ;; "D1 mini pro": ESP8266EX, 160MHz, 80KB RAM, 16MB Flash +board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz) +;board_build.f_flash = 80000000L ;; for 80Mhz flash speed, in case your chip can handle it (default = 40Mhz) +board_build.flash_mode = qio ;; quad IO - fastest speed, in case your chip can handle it. +;;board_build.flash_mode = dout ;; use if your esp8266 becomes unstable with "qio" +board_build.ldscript = ${common.ldscript_16m14m} ;; 16MB flash, use 14MB for LittleFS + +upload_speed = 460800 ;115200 +build_flags = ${common.build_flags_esp8266} + -D WLED_RELEASE_NAME=esp8266pro_16MB_S + -D WLED_WATCHDOG_TIMEOUT=0 + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + ; -D WLED_DEBUG + ; -D WLED_DISABLE_2D + ; -D USERMOD_AUDIOREACTIVE + ; -D USERMOD_ARTIFX ; to be done + ; -UWLED_USE_MY_CONFIG +monitor_filters = esp8266_exception_decoder +; RAM: [====== ] 59.3% (used 48616 bytes from 81920 bytes) +; Flash: [======== ] 77.0% (used 804236 bytes from 1044464 bytes) + +[env:esp8266pro_16MB_M] +extends = env:d1_mini +board = d1_mini_pro ;; "D1 mini pro": ESP8266EX, 160MHz, 80KB RAM, 16MB Flash +board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz) +;board_build.f_flash = 80000000L ;; for 80Mhz flash speed, in case your chip can handle it (default = 40Mhz) +board_build.flash_mode = qio ;; quad IO - fastest speed, in case your chip can handle it. +;;board_build.flash_mode = dout ;; use if your esp8266 becomes unstable with "qio" +board_build.ldscript = ${common.ldscript_16m14m} ;; 16MB flash, use 14MB for LittleFS + +upload_speed = 460800 ;115200 +build_flags = ${common.build_flags_esp8266} + -D WLED_RELEASE_NAME=esp8266pro_16MB_M + -D WLED_MAX_USERMODS=5 ; default only 4-6 + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_LOXONE + ; -D USERMOD_AUDIOREACTIVE + ; -D USERMOD_ARTIFX ; to be done + -D USERMOD_PIRSWITCH + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) + -D USERMOD_MULTI_RELAY + -D USE_ALT_DISPLAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI + -D USERMOD_FOUR_LINE_DISPLAY + -D USERMOD_MPU6050_IMU ; gyro/accelero for USERMOD_GAMES (ONLY WORKS IF USERMOD_FOUR_LINE_DISPLAY NOT INCLUDED - I2C SHARING BUG) + -D USERMOD_GAMES ; WLEDMM usermod + ; -D WLED_DEBUG +monitor_filters = esp8266_exception_decoder +lib_deps = ${esp8266.lib_deps} + OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE + olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY + ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU +; RAM: [====== ] 62.4% (used 51092 bytes from 81920 bytes) +; Flash: [========= ] 85.5% (used 893056 bytes from 1044464 bytes) + +[env:esp01_1MB_S] +board = esp01_1m +platform = ${common.platform_wled_default} +platform_packages = ${common.platform_packages} +board_build.ldscript = ${common.ldscript_1m128k} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_OTA + -D WLED_RELEASE_NAME=esp01_1MB_S + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC +lib_deps = ${esp8266.lib_deps} +; RAM: [====== ] 59.5% (used 48748 bytes from 81920 bytes) +; Flash: [========= ] 90.7% (used 809992 bytes from 892912 bytes) + + +# ------------------------------------------------------------------------------ +# MoonModules environments for IDF V4.4.x +# ------------------------------------------------------------------------------ +;; Warning: the build-in LittleFS (arduino-esp32 2.0.x) seems to be "slightly different" from Lorol LittleFS. +;; When upgrading to the new framework, it might be necessary to first do a chip erase (make sure you have a backup of cfg.json and presets.json) + +; compiled with ESP-IDF 4.4.1 +[env:esp32_4MB_V4_S] +extends = esp32_4MB_V4_S_base +build_flags = ${esp32_4MB_V4_S_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_V4_S + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup + -D WLED_DISABLE_LOXONE + -D WLED_DISABLE_ALEXA + -D WLED_DISABLE_HUESYNC + -D WLED_DISABLE_MQTT + -D WLED_DISABLE_INFRARED + ; -D WLED_DEBUG + ; -D SR_DEBUG + ; -D MIC_LOGGER + ; RAM: [== ] 24.2% (used 79372 bytes from 327680 bytes) + ; Flash: [========= ] 88.8% (used 1396073 bytes from 1572864 bytes) +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + +; compiled with ESP-IDF 4.4.1 +[env:esp32_4MB_V4_M] +extends = esp32_4MB_V4_M_base +build_flags = ${esp32_4MB_V4_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_V4_M + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup + ; RAM: [== ] 24.8% (used 81316 bytes from 327680 bytes) + ; Flash: [==========] 97.2% (used 1528253 bytes from 1572864 bytes) + -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes + -D WLED_DISABLE_HUESYNC ;RAM 122 bytes; FLASH 6308 bytes + ; RAM: [== ] 24.7% (used 81076 bytes from 327680 bytes) + ; Flash: [==========] 95.8% (used 1506893 bytes from 1572864 bytes) + ;-D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + ;-D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + +; compiled with ESP-IDF 4.4.1 +[env:esp32_16MB_V4_M] +extends = esp32_4MB_V4_M_base +build_flags = ${esp32_4MB_V4_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_16MB_V4_M + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem + ; RAM: [== ] 24.8% (used 81316 bytes from 327680 bytes) + ; Flash: [======= ] 72.9% (used 1528253 bytes from 2097152 bytes) + +[env:esp32_16MB_V4_M_debug] +extends = esp32_4MB_V4_M_base +build_unflags = ${common.build_unflags} + -D CORE_DEBUG_LEVEL=0 +build_flags = ${esp32_4MB_V4_M_base.build_flags} + ${Debug_Flags.build_flags} + -D CORE_DEBUG_LEVEL=4 ;; 0=none, 1=error, 2=warning, 3=info, 4=debug, 5=verbose + -D WLED_RELEASE_NAME=esp32_16MB_V4_M_debug + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +monitor_filters = esp32_exception_decoder +; RAM: [=== ] 25.0% (used 82008 bytes from 327680 bytes) +; Flash: [======== ] 78.1% (used 1638193 bytes from 2097152 bytes) WLEDMM: Earlier 76.9 + +;; experimental environment for boards with PSRAM (needs ESP-IDF 4.4.1). +[env:esp32_4MB_PSRAM_S] +extends = esp32_4MB_V4_S_base +board = lolin_d32_pro +;board = esp32cam +build_flags = ${esp32_4MB_V4_S_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_PSRAM_S + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup + -D WLED_USE_PSRAM + -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + -D WLED_DISABLE_HUESYNC ; RAM 122 bytes; FLASH 6308 bytes + -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes + -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + -D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes ewowi: disabled to stay below 100% + ; -D WLED_ENABLE_DMX + ; -D WLED_DEBUG + ; -D SR_DEBUG + ; -D MIC_LOGGER +lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +;; RAM: [== ] 24.3% (used 79524 bytes from 327680 bytes) +;; Flash: [========= ] 93.2% (used 1466389 bytes from 1572864 bytes) + +;; PSRAM build env that only leaves 300Kb for filesystem (instead of 1MB), but adds 300kB for program space +[env:esp32_4MB_PSRAM_M] +extends = esp32_4MB_V4_M_base +board = lolin_d32_pro +;board = esp32cam +board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware, 256KB filesystem (esptool erase_flash needed when changing from "standard WLED" partitions) +build_flags = ${esp32_4MB_V4_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_4MB_PSRAM_M + -D WLED_WATCHDOG_TIMEOUT=0 #-D WLED_DISABLE_BROWNOUT_DET + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup + -D WLED_USE_PSRAM + -D WLED_DISABLE_LOXONE ;; FLASH 1272 bytes + -D WLED_DISABLE_HUESYNC ;; RAM 122 bytes; FLASH 6308 bytes + -D WLED_DISABLE_ALEXA ;; RAM 116 bytes; FLASH 13524 bytes + ; -D WLED_DISABLE_MQTT ;; RAM 216 bytes; FLASH 16496 bytes + ; -D WLED_DISABLE_INFRARED ;;RAM 136 bytes; FLASH 24492 bytes + ; -D WLED_ENABLE_DMX + ; -D WLED_DEBUG + ; -D SR_DEBUG + ; -D MIC_LOGGER +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +;monitor_filters = esp32_exception_decoder +;; RAM: [== ] 24.9% (used 81484 bytes from 327680 bytes) +;; Flash: [======== ] 84.6% (used 1607857 bytes from 1900544 bytes) + +[env:esp32S3_8MB_M] +extends = esp32_4MB_V4_M_base +board = esp32-s3-devkitc-1 +build_unflags = + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) + -D USE_ALT_DISPLAY ;; four line display seems to have problems with I2C - it hangs during usermod setup + -D USERMOD_FOUR_LINE_DISPLAY ;; see above + -D USERMOD_ROTARY_ENCODER_UI ;; see above + -D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX) + +build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-indentation -Wno-format-truncation + ${common_mm.build_flags_S} ${common_mm.build_flags_M} + -D WLED_RELEASE_NAME=esp32S3_8MB_M + -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=0 -D ARDUINO_USB_MSC_ON_BOOT=0 -D ARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + ;; -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MSC_ON_BOOT=0 -D ARDUINO_USB_DFU_ON_BOOT=0 ;; for Hardware-CDC USB mode + ;; -D WLED_DISABLE_ADALIGHT ;; disables serial protocols when using CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) + -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 + ; -D U8X8_HAVE_2ND_HW_I2C ;; experimental - tells U8g2 lib that a second HW I2C unit exists + -D WLED_DISABLE_LOXONE ; FLASH 1272 bytes + -D WLED_DISABLE_ALEXA ; RAM 116 bytes; FLASH 13524 bytes + ; -D WLED_DISABLE_MQTT ; RAM 216 bytes; FLASH 16496 bytes + ; -D WLED_DISABLE_HUESYNC ;RAM 122 bytes; FLASH 6308 bytes + ; -D WLED_DISABLE_INFRARED ;RAM 136 bytes; FLASH 24492 bytes + -D LEDPIN=4 + -D STATUSLED=39 + -D BTNPIN=48 + -D RLYPIN=21 + -D IRPIN=15 + -D HW_PIN_SDA=42 ;; ESP32-S3 default: SDA = 8 + -D HW_PIN_SCL=41 ;; ESP32-S3 default: SCL = 9 + -D AUDIOPIN=-1 + -D SR_DMTYPE=1 + -D I2S_SDPIN=16 + -D I2S_CKPIN=17 + -D I2S_WSPIN=47 + -D MCLK_PIN=40 + -D ES7243_SDAPIN=8 + -D ES7243_SCLPIN=18 + ; -D WLED_DEBUG + ; -D SR_DEBUG + ; -D MIC_LOGGER +lib_deps = ${esp32s3.lib_deps} ${common_mm.lib_deps_S} ${common_mm.lib_deps_V4_M} +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +board_build.partitions = tools/WLED_ESP32_8MB.csv +board_build.flash_mode = qio +; RAM: [== ] 24.7% (used 80856 bytes from 327680 bytes) +; Flash: [======= ] 66.9% (used 1403489 bytes from 2097152 bytes) + +;; MM for Adafruit QT Py ESP32-S2 -> 4MB flash, PSRAM, and tinyUF2 bootloader +;; to ewowi - i'll optimize this entry later, as a few things can be inherited for sure. To softhack: sure ;-) +[env:esp32s2_tinyUF2_PSRAM_S] +extends = esp32_4MB_V4_S_base +platform = ${esp32.platformV4} +platform_packages = ${esp32.platformV4_packages} + +board = adafruit_qtpy_esp32s2 +board_build.partitions = tools/partitions-4MB_spiffs-tinyuf2.csv ;; this is needed for tinyUF2 bootloader! Filename has to end in "tinyuf2.csv" +board_build.f_flash = 80000000L +board_build.flash_mode = qio +upload_speed = 256000 ;; 921600 +build_unflags = ${common.build_unflags} + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) + -D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX) + +build_flags = ${common.build_flags} ${esp32s2.build_flags} + ; ${Debug_Flags.build_flags} ;ewowi: enabling debug causes Error: The program size (1463330 bytes) is greater than maximum allowed (1441792 bytes) + -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 + ${common_mm.build_flags_S} + -Wno-misleading-indentation -Wno-format-truncation + -D WLED_RELEASE_NAME=esp32S2_4MB_UF2_S + -DARDUINO_USB_CDC_ON_BOOT=1 ;; mandatory, otherwise USB does not work!! + -D WLED_DISABLE_ADALIGHT ;; disables serial protocols when using CDC USB (Serial RX will receive junk commands, unless its pulled down by resistor) + -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 + -D SERVERNAME='"WLED-S2"' + -D WLED_USE_PSRAM + -D WLED_DISABLE_LOXONE ;; FLASH 1272 bytes + -D WLED_DISABLE_HUESYNC ;; RAM 122 bytes; FLASH 6308 bytes + -D WLED_DISABLE_ALEXA ;; RAM 116 bytes; FLASH 13524 bytes + ; -D WLED_DISABLE_MQTT ;; RAM 216 bytes; FLASH 16496 bytes + -D WLED_DISABLE_INFRARED ;; RAM 136 bytes; FLASH 24492 bytes + -D LEDPIN=39 ;; onboard neopixel LED. Attach your own LEDs to GPIO 7 or GPIO 6 + -D BTNPIN=0 + ;-D RLYPIN=6 + ;-D IRPIN=7 + -D HW_PIN_SCL=40 -D HW_PIN_SDA=41 + -D HW_PIN_MOSISPI=35 ;WLEDMM renamed from HW_PIN_DATASPI + -D HW_PIN_CLOCKSPI=36 + -D HW_PIN_MISOSPI=37 + -D AUDIOPIN=-1 + -D SR_DMTYPE=1 -D I2S_SDPIN=9 -D I2S_WSPIN=8 -D I2S_CKPIN=17 -D MCLK_PIN=18 + ;-D STATUSLED=-1 + -D WLED_USE_MY_CONFIG +lib_deps = ${env.lib_deps} ${esp32s2.lib_deps} ${common_mm.lib_deps_S} +lib_ignore = + IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + OneWire ; not needed as we don't include USERMOD_DALLASTEMPERATURE +monitor_filters = esp32_exception_decoder +; RAM: [=== ] 25.1% (used 82348 bytes from 327680 bytes) +; Flash: [==========] 95.8% (used 1381742 bytes from 1441792 bytes) + +;; MM environment for generic ESP32-S2, with PSRAM, 4MB flash (300kB filesystem to have more program space) +[env:esp32s2_PSRAM_M] +extends = esp32_4MB_V4_M_base +platform = espressif32@~5.2.0 ;; more stable on -S2 than 5.1.1 +platform_packages = + +board = lolin_s2_mini +board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware, 256KB filesystem (esptool erase_flash needed when changing from "standard WLED" partitions) +board_build.flash_mode = dio +upload_speed = 256000 ;; 921600 +build_unflags = ${common.build_unflags} + -DARDUINO_USB_CDC_ON_BOOT=1 + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S3 (autodetect broken?) + -D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX) +build_flags = ${common.build_flags} ${esp32s2.build_flags} + ${Debug_Flags.build_flags} + -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 + ${common_mm.build_flags_S} ${common_mm.build_flags_M} + -Wno-misleading-indentation -Wno-format-truncation + -D WLED_RELEASE_NAME=esp32S2_4MB_M + -DARDUINO_USB_CDC_ON_BOOT=0 + -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 + -D WLED_DISABLE_ADALIGHT ;; disables serial protocols, as the board onl has CDC USB + -D WLED_USE_PSRAM -DBOARD_HAS_PSRAM + -D WLED_DISABLE_INFRARED ;; save flash space + -D WLED_DISABLE_ALEXA ;; save flash space + -D WLED_DISABLE_HUESYNC ;; save flash space + -D WLED_DISABLE_LOXONE ;; save flash space + -D LEDPIN=16 + -D BTNPIN=-1 -D RLYPIN=-1 -D IRPIN=-1 + -D HW_PIN_SCL=40 -D HW_PIN_SDA=41 + -D HW_PIN_MOSISPI=35 ;WLEDMM renamed from HW_PIN_DATASPI + -D HW_PIN_CLOCKSPI=36 + -D HW_PIN_MISOSPI=37 + -D AUDIOPIN=-1 + -D SR_DMTYPE=1 -D I2S_SDPIN=9 -D I2S_WSPIN=8 -D I2S_CKPIN=17 -D MCLK_PIN=18 + -D WLED_USE_MY_CONFIG +lib_deps = ${env.lib_deps} ${esp32s2.lib_deps} ${common_mm.lib_deps_S} ${common_mm.lib_deps_V4_M} +lib_ignore = + IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation + OneWire ; not needed as we don't include USERMOD_DALLASTEMPERATURE +monitor_filters = esp32_exception_decoder +; RAM: [== ] 22.9% (used 75068 bytes from 327680 bytes) +; Flash: [======== ] 78.3% (used 1487802 bytes from 1900544 bytes) + +;; MM environment for ESP32-C3 -> 4MB flash, no PSRAM +[env:esp32c3dev_4MB_M] +extends = esp32_4MB_V4_S_base +;platform = ${esp32.platformV4} +;platform_packages = ${esp32.platformV4_packages} +platform = espressif32@~5.2.0 ;; alternative platform, might help in case you experience bootloops due to corrupted flash filesystem +platform_packages = +board = esp32-c3-devkitm-1 +;board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware, 256KB filesystem (esptool erase_flash needed when changing from "standard WLED" partitions) +;board_build.partitions = tools/WLED_ESP32_2MB_noOTA.csv ;; use this for boards with 2MB flash (like some Ai-Thinker ESP32-C3-12F models) +upload_speed = 256000 ;; 921600 + +build_unflags = ${common.build_unflags} + -D USERMOD_DALLASTEMPERATURE ;; disabled because it hangs during usermod setup on -S2 (autodetect broken?) + -D USE_ALT_DISPLAY ;; four line display seems to have problems with I2C - it hangs during usermod setup + -D USERMOD_FOUR_LINE_DISPLAY ;; see above + -D USERMOD_ROTARY_ENCODER_UI ;; see above + -D WLED_ENABLE_DMX ;; disabled because it does not work with ESP-IDF 4.4.x (buggy driver in SparkFunDMX) + +build_flags = ${common.build_flags} ${esp32c3.build_flags} + ; -D WLED_DISABLE_OTA ;; OTA is not possible for boards with 2MB flash only (like some Ai-Thinker ESP32-C3-12F models) + -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 + ${common_mm.build_flags_S} ${common_mm.build_flags_M} + -Wno-misleading-indentation -Wno-format-truncation + -D WLED_RELEASE_NAME=esp32c3dev_4MB_M + ; -DARDUINO_USB_CDC_ON_BOOT=1 ;; enable CDC USB -> needed for debugging over serial USB + ; -D WLED_DISABLE_ADALIGHT ;; to disable serial protocols when using CDC USB (Serial RX will receive junk commands, unless its pulled down by resistor) + -DARDUINO_USB_CDC_ON_BOOT=0 ;; disable CDC USB + -D SERVERNAME='"WLED-C3"' + ;-D WLEDMM_WIFI_POWERON_HACK ;; use this _only_ if your device is not able to make a WiFI connection! + ;-D WLED_DISABLE_INFRARED ;; save flash space + ;-D WLED_DISABLE_ALEXA ;; save flash space + -D LEDPIN=8 ;; onboard neopixel 5x5 Matrix. Attach your own LEDs to GPIO 20 + -D BTNPIN=9 + ; -D STATUSLED=10 ;; onboard LED + ;-D RLYPIN=3 + ;-D IRPIN=2 + ;-D HW_PIN_SDA=0 -D HW_PIN_SCL=1 ;; for I2C Qwiic connector + -D SR_DMTYPE=1 -D I2S_SDPIN=5 -D I2S_WSPIN=6 -D I2S_CKPIN=4 -D MCLK_PIN=7 + -D WLED_USE_MY_CONFIG + +lib_deps = ${env.lib_deps} ${esp32c3.lib_deps} ${common_mm.lib_deps_S} ${common_mm.lib_deps_V4_M} +;lib_ignore = IRremoteESP8266 ; use with WLED_DISABLE_INFRARED for faster compilation +;monitor_filters = esp32_exception_decoder +; RAM: [== ] 23.1% (used 75620 bytes from 327680 bytes) +; Flash: [==========] 95.8% (used 1506216 bytes from 1572864 bytes) + +# ------------------------------------------------------------------------------ +# custom board environments +# ------------------------------------------------------------------------------ + +[wemos_shield_esp32_4MB_M_base] +extends = esp32_4MB_M_base +build_flags = ${esp32_4MB_M_base.build_flags} + -D ABL_MILLIAMPS_DEFAULT=9500 ; Wemos max 10A + -D LEDPIN=16 + -D RLYPIN=19 + -D BTNPIN=17 + -D IRPIN=18 + -D AUDIOPIN=-1 + -D TEMPERATURE_PIN=23 + -D FLD_PIN_SCL=-1 -D FLD_PIN_SDA=-1 ; use global! + -D HW_PIN_SCL=22 -D HW_PIN_SDA=21 + -D HW_PIN_CLOCKSPI=-1 -D HW_PIN_MOSISPI=-1 -D HW_PIN_MISOSPI=-1 ; WLEDMM: is now also default but just to show we didn't agree on wemos pins for spi yet + -D ENCODER_DT_PIN=35 -D ENCODER_CLK_PIN=39 -D ENCODER_SW_PIN=5 ; WLEDMM spec by @SERG74: use 35 and 39 instead of 18 and 19 (conflicts) + -D PIR_SENSOR_PIN=-1 + -D PWM_PIN=-1 + ; -D WLED_USE_MY_CONFIG + +[wemos_shield_esp32_4MB_XL_base] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${common_mm.build_flags_XL} +lib_deps = ${wemos_shield_esp32_4MB_M_base.lib_deps} ${common_mm.lib_deps_XL} + +[env:wemos_shield_esp32_4MB_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_M +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_4MB_ICS4343x_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_ICS4343x.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_ICS4343x_M +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_4MB_SPM1423_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_SPM1423.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_SPM1423_M +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_4MB_LineIn_M] +extends = wemos_shield_esp32_4MB_M_base +build_unflags = ${common.build_unflags} ${Shield_LineIn.build_unflags} +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_LineIn.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_4MB_LineIn_M + +[env:wemos_shield_esp32_16MB_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_M +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +;board_build.flash_mode = qio +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [======= ] 66.4% (used 1393421 bytes from 2097152 bytes) + +[env:wemos_shield_esp32_16MB_ICS4343x_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_ICS4343x.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_ICS4343x_M +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_16MB_ICS4343x_XL] +extends = wemos_shield_esp32_4MB_XL_base +build_flags = ${wemos_shield_esp32_4MB_XL_base.build_flags} ${Shield_ICS4343x.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_ICS4343x_XL +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +; RAM: [== ] 24.4% (used 80044 bytes from 327680 bytes) +; Flash: [======= ] 67.9% (used 1424185 bytes from 2097152 bytes) + +[env:wemos_shield_esp32_16MB_SPM1423_M] +extends = wemos_shield_esp32_4MB_M_base +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_SPM1423.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_SPM1423_M +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_16MB_SPM1423_XL] +extends = wemos_shield_esp32_4MB_XL_base +build_flags = ${wemos_shield_esp32_4MB_XL_base.build_flags} ${Shield_SPM1423.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_SPM1423_XL +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem +; RAM: [== ] 24.4% (used 79820 bytes from 327680 bytes) +; Flash: [========= ] 88.6% (used 1393421 bytes from 1572864 bytes) + +[env:wemos_shield_esp32_16MB_LineIn_M] +extends = wemos_shield_esp32_4MB_M_base +build_unflags = ${common.build_unflags} ${Shield_LineIn.build_unflags} +build_flags = ${wemos_shield_esp32_4MB_M_base.build_flags} ${Shield_LineIn.build_flags} + -D WLED_RELEASE_NAME=wemos_shield_esp32_16MB_LineIn_M +board = esp32_16MB +board_build.partitions = tools/WLED_ESP32_16MB.csv ;; WLED standard for 16MB flash: 2MB firmware, 12 MB filesystem +;board_build.partitions = tools/WLED_ESP32_16MB_9MB_FS.csv ;; WLED extended for 16MB flash: 3.2MB firmware, 9 MB filesystem + +[env:athom_music_esp32_4MB_M] +extends = esp32_4MB_M_base +build_flags = ${esp32_4MB_M_base.build_flags} ${Athom_PDMmic.build_flags} + -D WLED_AP_SSID_UNIQUE + -D WLED_RELEASE_NAME=athom_music_esp32_4MB_M + -D ABL_MILLIAMPS_DEFAULT=14500 ; max 15A + -D WLED_DISABLE_MQTT -D WLED_DISABLE_LOXONE + -D WLED_DISABLE_ADALIGHT ;to get 4ld working + -D BTNPIN=0 -D RLYPIN=2 -D IRPIN=25 -D IRTYPE=9 -D LEDPIN=18 -D + -D AUDIOPIN=-1 + ; -D TEMPERATURE_PIN=23 + -D FLD_PIN_SCL=-1 -D FLD_PIN_SDA=-1 ; use global! + -D HW_PIN_SCL=3 -D HW_PIN_SDA=1 ;4ld uses rx and tx + -D HW_PIN_CLOCKSPI=-1 -D HW_PIN_MOSISPI=-1 -D HW_PIN_MISOSPI=-1 ; WLEDMM: is now also default but just to show we didn't agree on wemos pins for spi yet + ; -D ENCODER_DT_PIN=35 -D ENCODER_CLK_PIN=39 -D ENCODER_SW_PIN=5 ; WLEDMM spec by @SERG74: use 35 and 39 instead of 18 and 19 (conflicts) + ; -D PIR_SENSOR_PIN=-1 + ; -D PWM_PIN=-1 + ; -D WLED_USE_MY_CONFIG + +; ESP32 WLED pico board with builtin ICS-43432 microphpone +[env:esp32_pico_4MB_M] +extends = esp32_4MB_M_base +board = pico32 +board_build.flash_mode = dout ;; (dout = dual out; more compatible than qio = quad i/o) +upload_speed = 256000 ;; or 115200 ;; or 460800 ; or 921600 (slower speeds are better when flashing without a soldered connection) + +build_flags = ${esp32_4MB_M_base.build_flags} + -D WLED_RELEASE_NAME=esp32_pico_4MB_M + -D WLED_DISABLE_BROWNOUT_DET + -D SERVERNAME='"WLED-pico32"' + ; -D WLED_WATCHDOG_TIMEOUT=60 + -D WLED_DISABLE_ADALIGHT ;; WLEDMM this board does not have a serial-to-USB chip. Better to disable serial protocols, to avoid crashes (see upstream #3128) + ; -D WLED_DEBUG + ; -D SR_DEBUG + -D LEDPIN=2 + -D RLYPIN=-1 -D BTNPIN=-1 -D IRPIN=-1 + -D HW_PIN_SCL=22 -D HW_PIN_SDA=21 + -D SR_DMTYPE=1 -D I2S_SDPIN=25 -D I2S_WSPIN=15 -D I2S_CKPIN=14 + -D SR_SQUELCH=5 -D SR_GAIN=30 -D SR_FREQ_PROF=5 ; ICS-4343x specific + ; -D MCLK_PIN=0 + -D SR_ENABLE_DEFAULT ;; enable at first start - no need to manually set "enable", then reboot + ; -D WLED_USE_MY_CONFIG + ; -D WLED_DISABLE_LOXONE + ; -D WLED_DISABLE_ALEXA + ; -D WLED_DISABLE_HUESYNC + ; -D WLED_DISABLE_MQTT + ; -D WLED_DISABLE_INFRARED + ; -D WLED_ENABLE_DMX +; RAM: [== ] 24.4% (used 79812 bytes from 327680 bytes) +; Flash: [========= ] 90.4% (used 1422581 bytes from 1572864 bytes) + + +;; experimental +;; PICO environment with ESP-IDF v4.4.1 / arduino-esp32 v2.0.4 +[env:esp32_pico_4MB_V4_S] +extends = esp32_4MB_V4_S_base +board = pico32 +;platform = espressif32@~5.2.0 ;; alternative platform, might help in case you experience bootloops due to corrupted flash filesystem +;platform_packages = +upload_speed = 256000 ;; or 115200 ;; or 460800 ; or 921600 (slower speeds are better when flashing without a soldered connection) + +build_flags = ${esp32_4MB_V4_S_base.build_flags} + -D ARDUINO_USB_CDC_ON_BOOT=0 ; needed for arduino-esp32 >=2.0.4; avoids errors on startup + -D WLED_RELEASE_NAME=esp32_pico_4MB_V4_S + -D WLED_DISABLE_BROWNOUT_DET + -D SERVERNAME='"WLED-pico32-V4"' + -D WLED_WATCHDOG_TIMEOUT=0 + -D WLED_DISABLE_ADALIGHT ;; WLEDMM this board does not have a serial-to-USB chip. Better to disable serial protocols, to avoid crashes (see upstream #3128) + ; -D WLED_WATCHDOG_TIMEOUT=60 + ; -D WLED_DEBUG + ; -D SR_DEBUG + -D LEDPIN=2 + -D RLYPIN=-1 -D BTNPIN=-1 -D IRPIN=-1 + -D HW_PIN_SCL=22 -D HW_PIN_SDA=21 + -D SR_DMTYPE=1 -D I2S_SDPIN=25 -D I2S_WSPIN=15 -D I2S_CKPIN=14 + -D SR_SQUELCH=5 -D SR_GAIN=30 -D SR_FREQ_PROF=5 ; ICS-4343x specific + ; -D MCLK_PIN=0 + -D SR_ENABLE_DEFAULT ;; enable audioreactive at first start - no need to manually set "enable", then reboot + ; -D WLED_USE_MY_CONFIG +; RAM: [== ] 24.5% (used 80436 bytes from 327680 bytes) +; Flash: [========= ] 93.9% (used 1476341 bytes from 1572864 bytes) diff --git a/platformio_override.ini.sample b/platformio_override.ini.sample index cd81c517..d6ea5d96 100644 --- a/platformio_override.ini.sample +++ b/platformio_override.ini.sample @@ -26,7 +26,6 @@ build_flags = ${common.build_flags_esp8266} ; disable specific features ; -D WLED_DISABLE_OTA ; -D WLED_DISABLE_ALEXA -; -D WLED_DISABLE_BLYNK ; -D WLED_DISABLE_HUESYNC ; -D WLED_DISABLE_INFRARED ; -D WLED_DISABLE_WEBSOCKETS diff --git a/readme.md b/readme.md index fb5e2b26..fc5660c4 100644 --- a/readme.md +++ b/readme.md @@ -15,11 +15,11 @@ A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control NeoPixel (WS2812B, WS2811, SK6812) LEDs or also SPI based chipsets like the WS2801 and APA102! ## ⚙️ Features -- WS2812FX library integrated for over 100 special effects +- WS2812FX library with more than 100 special effects - FastLED noise effects and 50 palettes - Modern UI with color, effect and segment controls -- Segments to set different effects and colors to parts of the LEDs -- Settings page - configuration over network +- Segments to set different effects and colors to user defined parts of the LED string +- Settings page - configuration via the network - Access Point and station mode - automatic failsafe AP - Up to 10 LED outputs per instance - Support for RGBW strips @@ -28,14 +28,13 @@ A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control - Nightlight function (gradually dims down) - Full OTA software updatability (HTTP + ArduinoOTA), password protectable - Configurable analog clock (Cronixie, 7-segment and EleksTube IPS clock support via usermods) -- Configurable Auto Brightness limit for safer operation +- Configurable Auto Brightness limit for safe operation - Filesystem-based config for easier backup of presets and settings ## 💡 Supported light control interfaces - WLED app for [Android](https://play.google.com/store/apps/details?id=com.aircoookie.WLED) and [iOS](https://apps.apple.com/us/app/wled/id1475695033) - JSON and HTTP request APIs -- MQTT -- Blynk IoT +- MQTT - E1.31, Art-Net, DDP and TPM2.net - [diyHue](https://github.com/diyhue/diyHue) (Wled is supported by diyHue, including Hue Sync Entertainment under udp. Thanks to [Gregory Mallios](https://github.com/gmallios)) - [Hyperion](https://github.com/hyperion-project/hyperion.ng) @@ -49,33 +48,37 @@ A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control ## 📲 Quick start guide and documentation -See the [documentation on our official site](https://kno.wled.ge)! +See the [documentation on our official site](https://mm.kno.wled.ge)! -[On this page](https://kno.wled.ge/basics/tutorials/) you can find excellent tutorials made by the community and helpful tools to help you get your new lamp up and running! +[On this page](https://mm.kno.wled.ge/basics/tutorials/) you can find excellent tutorials and tools to help you get your new project up and running! ## 🖼️ User interface ## 💾 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://img.shields.io/badge/send%20me%20a%20small%20gift-paypal-blue.svg?style=flat-square)](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://img.shields.io/badge/send%20me%20a%20small%20gift-paypal-blue.svg?style=flat-square)](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/SoundReactive_ESP32_16MB.csv b/tools/SoundReactive_ESP32_16MB.csv deleted file mode 100644 index e547a824..00000000 --- a/tools/SoundReactive_ESP32_16MB.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offsaet, Size, Flags -nvs, data, nvs, 0x9000, 0x5000, -otadata, data, ota, 0xe000, 0x2000, -app0, app, ota_0, 0x10000, 0x200000, -app1, app, ota_1, 0x210000, 0x200000, -spiffs, data, spiffs, 0x410000, 0x7f0000, diff --git a/tools/WLED_ESP32_16MB_9MB_FS.csv b/tools/WLED_ESP32_16MB_9MB_FS.csv new file mode 100644 index 00000000..9ecac04e --- /dev/null +++ b/tools/WLED_ESP32_16MB_9MB_FS.csv @@ -0,0 +1,8 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x300000, +app1, app, ota_1, 0x310000,0x300000, +spiffs, data, spiffs, 0x610000,0x9E0000, +coredump, data, coredump,0xFF0000,0x10000, +# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage \ No newline at end of file diff --git a/tools/WLED_ESP32_2MB_noOTA.csv b/tools/WLED_ESP32_2MB_noOTA.csv new file mode 100644 index 00000000..7a1cf15f --- /dev/null +++ b/tools/WLED_ESP32_2MB_noOTA.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 20K, +otadata, data, ota, 0xe000, 8K, +app0, app, ota_0, 0x10000, 1536K, +spiffs, data, spiffs, 0x190000, 384K, diff --git a/tools/WLED_ESP32_4MB_256KB_FS.csv b/tools/WLED_ESP32_4MB_256KB_FS.csv new file mode 100644 index 00000000..f9e1be26 --- /dev/null +++ b/tools/WLED_ESP32_4MB_256KB_FS.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x1D0000, +app1, app, ota_1, 0x1E0000,0x1D0000, +spiffs, data, spiffs, 0x3B0000,0x40000, +coredump, data, coredump,0x3F0000,0x10000, \ No newline at end of file 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_spiffs-tinyuf2.csv b/tools/partitions-4MB_spiffs-tinyuf2.csv new file mode 100644 index 00000000..4979c127 --- /dev/null +++ b/tools/partitions-4MB_spiffs-tinyuf2.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.
www.rolfje.com @@ -128,4 +127,4 @@ Modifications @blazoncek ## Change log 2021-04 -* Adaptation for runtime configuration. \ No newline at end of file +* Adaptation for runtime configuration. diff --git a/usermods/BH1750_v2/readme.md b/usermods/BH1750_v2/readme.md index f70300b7..05a033cf 100644 --- a/usermods/BH1750_v2/readme.md +++ b/usermods/BH1750_v2/readme.md @@ -1,7 +1,7 @@ # BH1750 usermod -This usermod will read from an ambient light sensor like the BH1750 sensor. -The luminance is displayed both in the Info section of the web UI as well as published to the `/luminance` MQTT topic if enabled. +This usermod will read from an ambient light sensor like the BH1750. +The luminance is displayed in both the Info section of the web UI, as well as published to the `/luminance` MQTT topic if enabled. ## Dependencies - Libraries @@ -28,9 +28,9 @@ The following settings can be set at compile-time but are configurable on the us * `USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL` - the max number of milliseconds between measurements, defaults to 10000ms * `USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL` - the min number of milliseconds between measurements, defaults to 500ms * `USERMOD_BH1750_OFFSET_VALUE` - the offset value to report on, defaults to 1 -* `USERMOD_BH1750_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 10 seconds +* `USERMOD_BH1750_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 10000 ms -In addition, on the Usermod screen allows you to: +In addition, the Usermod screen allows you to: - enable/disable the usermod - Enable Home Assistant Discovery of usermod - Configure the SCL/SDA pins @@ -44,6 +44,6 @@ Jul 2022 - Added Home Assistant Discovery - Implemented PinManager to register pins - Made pins configurable in usermod menu -- Added API call to read illuminance from other modules +- Added API call to read luminance from other modules - Enhanced info-screen outputs -- Updated `readme.md` \ No newline at end of file +- Updated `readme.md` diff --git a/usermods/BH1750_v2/usermod_bh1750.h b/usermods/BH1750_v2/usermod_bh1750.h index a69e2751..77a57efb 100644 --- a/usermods/BH1750_v2/usermod_bh1750.h +++ b/usermods/BH1750_v2/usermod_bh1750.h @@ -1,10 +1,15 @@ -// force the compiler to show a warning to confirm that this file is included -#warning **** Included USERMOD_BH1750 **** +// force the compiler to show a warning to confirm that this file is included WLEDMM: commented this warning as we want serious warnings ;-) +// #warning **** Included USERMOD_BH1750 **** + +#ifndef WLED_ENABLE_MQTT +#warning "This user mod expects MQTT to be enabled." +#endif #pragma once +#include // WLEDMM: make sure that I2C drivers have the "right" Wire Object + #include "wled.h" -#include #include // the max frequency to check photoresistor, 10 seconds @@ -14,7 +19,8 @@ // the min frequency to check photoresistor, 500 ms #ifndef USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL -#define USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL 500 +//#define USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL 500 +#define USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL 2500 // WLEDMM this makes more sense #endif // how many seconds after boot to take first measurement, 10 seconds @@ -24,7 +30,7 @@ // only report if differance grater than offset value #ifndef USERMOD_BH1750_OFFSET_VALUE -#define USERMOD_BH1750_OFFSET_VALUE 1 +#define USERMOD_BH1750_OFFSET_VALUE 2 // WLEDMM this makes more sense #endif class Usermod_BH1750 : public Usermod @@ -53,14 +59,19 @@ private: static const char _HomeAssistantDiscovery[]; // set the default pins based on the architecture, these get overridden by Usermod menu settings - #ifdef ARDUINO_ARCH_ESP32 // ESP32 boards - #define HW_PIN_SCL 22 - #define HW_PIN_SDA 21 - #else // ESP8266 boards - #define HW_PIN_SCL 5 - #define HW_PIN_SDA 4 - #endif - int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup() + // #ifdef ARDUINO_ARCH_ESP32 // ESP32 boards -- WLEDMM: don't override already defined HW pins + // #ifndef HW_PIN_SDA + // #define HW_PIN_SCL 22 + // #endif + // #ifndef HW_PIN_SDA + // #define HW_PIN_SDA 21 + // #endif + // #else // ESP8266 boards + // #define HW_PIN_SCL 5 + // #define HW_PIN_SDA 4 + // #endif + //int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup() + int8_t ioPin[2] = {-1, -1}; // WLEDMM - I2C pins: wait until hw pins get allocated bool initDone = false; bool sensorFound = false; @@ -80,14 +91,17 @@ private: // set up Home Assistant discovery entries void _mqttInitialize() { +#ifdef WLED_ENABLED_MQTT mqttLuminanceTopic = String(mqttDeviceTopic) + F("/brightness"); if (HomeAssistantDiscovery) _createMqttSensor(F("Brightness"), mqttLuminanceTopic, F("Illuminance"), F(" lx")); +#endif } // Create an MQTT Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop. void _createMqttSensor(const String &name, const String &topic, const String &deviceClass, const String &unitOfMeasurement) { +#ifdef WLED_ENABLED_MQTT String t = String(F("homeassistant/sensor/")) + mqttClientID + F("/") + name + F("/config"); StaticJsonDocument<600> doc; @@ -114,20 +128,42 @@ private: DEBUG_PRINTLN(temp); mqtt->publish(t.c_str(), 0, true, temp.c_str()); +#endif } public: void setup() { - bool HW_Pins_Used = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA); // note whether architecture-based hardware SCL/SDA pins used +#if 0 + bool HW_Pins_Used = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda); // note whether architecture-based hardware SCL/SDA pins used PinOwner po = PinOwner::UM_BH1750; // defaults to being pinowner for SCL/SDA pins - PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins + if ((i2c_scl >= 0) && (i2c_sda >=0)) { // WLEDMM: make sure that global HW pins are used if defined + ioPin[0] = i2c_scl; + ioPin[1] = i2c_sda; + po = PinOwner::HW_I2C; + } + PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins // WLEDMM: after selecting final pins if (!pinManager.allocateMultiplePins(pins, 2, po)) return; - Wire.begin(ioPin[1], ioPin[0]); +#if defined(ARDUINO_ARCH_ESP32) + if (pins[1].pin < 0 || pins[0].pin < 0) { sensorFound=false; enabled=false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough + //Wire.begin(pins[1].pin, pins[0].pin); // WLEDMM this might silently fail, which is OK as it just means that I2C bus is already running. +#else + //Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed. +#endif +#endif + if (!enabled) return; + if (!pinManager.joinWire()) { // WLEDMM - this allocates global I2C pins, then starts Wire - if not started previously + sensorFound = false; + //enabled = false; + USER_PRINTLN(F("BH1750: failed to join I2C bus.")); + return; + } sensorFound = lightMeter.begin(); + if (sensorFound) { USER_PRINTLN(F("BH1750 sensor found.")); } + else{ USER_PRINTLN(F("BH1750 sensor not found.")); } initDone = true; } @@ -136,6 +172,7 @@ public: if ((!enabled) || strip.isUpdating()) return; + if (!sensorFound) return; // WLEDMM bugfix unsigned long now = millis(); // check to see if we are due for taking a measurement @@ -156,6 +193,7 @@ public: { lastLux = lux; lastSend = millis(); +#ifndef WLED_DISABLE_MQTT if (WLED_MQTT_CONNECTED) { if (!mqttInitialized) @@ -164,12 +202,13 @@ public: mqttInitialized = true; } mqtt->publish(mqttLuminanceTopic.c_str(), 0, true, String(lux).c_str()); - DEBUG_PRINTLN(F("Brightness: ") + String(lux) + F("lx")); + DEBUG_PRINTLN(String("Brightness: ") + String(lux) + String("lx")); // WLEDMM fix compilation warning } else { DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data")); } +#endif } } @@ -179,6 +218,8 @@ public: void addToJsonInfo(JsonObject &root) { + if ((!enabled) || (!sensorFound)) return; // WLEDMM bugfix + JsonObject user = root[F("u")]; if (user.isNull()) user = root.createNestedObject(F("u")); @@ -195,11 +236,20 @@ public: lux_json.add(F(" sec until read")); return; } else { - lux_json.add(lastLux); + lux_json.add(round(lastLux)); // WLEDMM lux_json.add(F(" lx")); } } + void appendConfigData() { + oappend(SET_F("addHB('BH1750');")); + // WLEDMM this usermod can ONLY use HW_I2C - so always use globals + //oappend(SET_F("addInfo('BH1750:pin[]',0,'','I2C SCL');")); + //oappend(SET_F("rOpt('BH1750:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + //oappend(SET_F("addInfo('BH1750:pin[]',1,'','I2C SDA');")); + //oappend(SET_F("rOpt('BH1750:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); + } + // (called from set.cpp) stores persistent properties to cfg.json void addToConfig(JsonObject &root) { @@ -210,9 +260,14 @@ public: top[FPSTR(_minReadInterval)] = minReadingInterval; top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery; top[FPSTR(_offset)] = offset; - JsonArray io_pin = top.createNestedArray(F("pin")); - for (byte i=0; i<2; i++) io_pin.add(ioPin[i]); - top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page + + // WLEDMM this usermod can ONLY use HW_I2C - so always use globals + //JsonArray io_pin = top.createNestedArray(F("pin")); + //WLEDMM: avoid global pin hijacking + //io_pin.add((ioPin[0]==i2c_scl)?-1:ioPin[0]); + //io_pin.add((ioPin[1]==i2c_sda)?-1:ioPin[1]); + + // top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page DEBUG_PRINTLN(F("BH1750 config saved.")); } @@ -220,7 +275,8 @@ public: // called before setup() to populate properties from values stored in cfg.json bool readFromConfig(JsonObject &root) { - int8_t newPin[2]; for (byte i=0; i<2; i++) newPin[i] = ioPin[i]; // prepare to note changed pins + int8_t newPin[2] = {-1, -1}; // WLEDMM this usermod can ONLY use HW_I2C - so always use globals + //for (byte i=0; i<2; i++) newPin[i] = ioPin[i]; // prepare to note changed pins // we look for JSON object. JsonObject top = root[FPSTR(_name)]; @@ -238,7 +294,8 @@ public: configComplete &= getJsonValue(top[FPSTR(_minReadInterval)], minReadingInterval, 500); //ms configComplete &= getJsonValue(top[FPSTR(_HomeAssistantDiscovery)], HomeAssistantDiscovery, false); configComplete &= getJsonValue(top[FPSTR(_offset)], offset, 1); - for (byte i=0; i<2; i++) configComplete &= getJsonValue(top[F("pin")][i], newPin[i], ioPin[i]); + // WLEDMM this usermod can ONLY use HW_I2C - so always use globals + //for (byte i=0; i<2; i++) configComplete &= getJsonValue(top[F("pin")][i], newPin[i], ioPin[i]); DEBUG_PRINT(FPSTR(_name)); if (!initDone) { @@ -248,15 +305,20 @@ public: } else { DEBUG_PRINTLN(F(" config (re)loaded.")); // changing parameters from settings page +#if 0 bool pinsChanged = false; for (byte i=0; i<2; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; } // check if any pins changed if (pinsChanged) { //if pins changed, deallocate old pins and allocate new ones PinOwner po = PinOwner::UM_BH1750; - if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins + if (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins + if (ioPin[0]==-1 && ioPin[1]==-1) po = PinOwner::HW_I2C; // WLEDMM global HW I2C bus pins pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po); // deallocate pins for (byte i=0; i<2; i++) ioPin[i] = newPin[i]; setup(); } +#else + if (enabled && !sensorFound) setup(); +#endif // use "return !top["newestParameter"].isNull();" when updating Usermod with new features return !top[F("pin")].isNull(); } diff --git a/usermods/BME280_v2/README.md b/usermods/BME280_v2/README.md index b8718e0e..0a4afbf1 100644 --- a/usermods/BME280_v2/README.md +++ b/usermods/BME280_v2/README.md @@ -6,14 +6,14 @@ This Usermod is designed to read a `BME280` or `BMP280` sensor and output the fo - Heat Index (`BME280` only) - Dew Point (`BME280` only) -Configuration is all completed via the Usermod menu. There are no settings to set in code! The following settings can be configured in the Usermod Menu: +Configuration is performed via the Usermod menu. There are no parameters to set in code! The following settings can be configured in the Usermod Menu: - Temperature Decimals (number of decimal places to output) - Humidity Decimals - Pressure Decimals -- Temperature Interval (how many seconds between reads of temperature and humidity) +- Temperature Interval (how many seconds between temperature and humidity measurements) - Pressure Interval - Publish Always (turn off to only publish changes, on to publish whether or not value changed) -- Use Celsius (turn off to use Farenheit) +- Use Celsius (turn off to use Fahrenheit) - Home Assistant Discovery (turn on to sent MQTT Discovery entries for Home Assistant) - SCL/SDA GPIO Pins @@ -23,7 +23,7 @@ Dependencies - `Wire` - These must be added under `lib_deps` in your `platform.ini` (or `platform_override.ini`). - Data is published over MQTT - make sure you've enabled the MQTT sync interface. -- This usermod also writes to serial (GPIO1 on ESP8266). Please make sure nothing else listening on the serial TX pin of your board will get confused by log messages! +- This usermod also writes to serial (GPIO1 on ESP8266). Please make sure nothing else is listening to the serial TX pin or your board will get confused by log messages! In addition to outputting via MQTT, you can read the values from the Info Screen on the dashboard page of the device's web interface. @@ -37,7 +37,7 @@ Methods also exist to read the read/calculated values from other WLED modules th - `getHeatIndexC()` - `getHeatIndexF()` -# Complilation +# Compiling To enable, compile with `USERMOD_BME280` defined (e.g. in `platformio_override.ini`) ```ini @@ -63,7 +63,7 @@ Pressure | `/pressure` Heat index | `/heat_index` Dew point | `/dew_point` -If you are using Home Assistant, and `Home Assistant Discovery` is turned on, Home Assistant should automatically detect a new device, provided you have the MQTT integration installed. The device is seperate from the main WLED device and will contain sensors for Pressure, Humidity, Temperature, Dew Point and Heat Index. +If you are using Home Assistant, and `Home Assistant Discovery` is turned on, Home Assistant should automatically detect a new device, provided you have the MQTT integration installed. The device is separate from the main WLED device and will contain sensors for Pressure, Humidity, Temperature, Dew Point and Heat Index. # Revision History Jul 2022 @@ -82,9 +82,9 @@ Apr 2021 Dec 2020 - Ported to V2 Usermod format -- Customisable `measure intervals` -- Customisable number of `decimal places` in published sensor values +- Customizable `measure intervals` +- Customizable number of `decimal places` in published sensor values - Pressure measured in units of hPa instead of Pa - Calculation of heat index (apparent temperature) and dew point - `16x oversampling` of sensor during measurement -- Values only published if they are different from the previous value \ No newline at end of file +- Values only published if they are different from the previous value diff --git a/usermods/BME280_v2/usermod_bme280.h b/usermods/BME280_v2/usermod_bme280.h index 6b42fc80..3b9c80ec 100644 --- a/usermods/BME280_v2/usermod_bme280.h +++ b/usermods/BME280_v2/usermod_bme280.h @@ -1,5 +1,9 @@ -// force the compiler to show a warning to confirm that this file is included -#warning **** Included USERMOD_BME280 version 2.0 **** +// force the compiler to show a warning to confirm that this file is included WLEDMM: commented this warning as we want serious warnings ;-) +// #warning **** Included USERMOD_BME280 version 2.0 **** + +#ifndef WLED_ENABLE_MQTT +#error "This user mod requires MQTT to be enabled." +#endif #pragma once @@ -16,14 +20,15 @@ private: // NOTE: Do not implement any compile-time variables, anything the user needs to configure // should be configurable from the Usermod menu using the methods below // key settings set via usermod menu - unsigned long TemperatureDecimals = 0; // Number of decimal places in published temperaure values - unsigned long HumidityDecimals = 0; // Number of decimal places in published humidity values - unsigned long PressureDecimals = 0; // Number of decimal places in published pressure values - unsigned long TemperatureInterval = 5; // Interval to measure temperature (and humidity, dew point if available) in seconds - unsigned long PressureInterval = 300; // Interval to measure pressure in seconds + uint8_t TemperatureDecimals = 0; // Number of decimal places in published temperaure values + uint8_t HumidityDecimals = 0; // Number of decimal places in published humidity values + uint8_t PressureDecimals = 0; // Number of decimal places in published pressure values + uint16_t TemperatureInterval = 5; // Interval to measure temperature (and humidity, dew point if available) in seconds + uint16_t PressureInterval = 300; // Interval to measure pressure in seconds bool PublishAlways = false; // Publish values even when they have not changed bool UseCelsius = true; // Use Celsius for Reporting bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Information + bool enabled = true; // set the default pins based on the architecture, these get overridden by Usermod menu settings #ifdef ESP8266 @@ -70,20 +75,16 @@ private: // MQTT topic strings for publishing Home Assistant discovery topics bool mqttInitialized = false; - String mqttTemperatureTopic = ""; - String mqttHumidityTopic = ""; - String mqttPressureTopic = ""; - String mqttHeatIndexTopic = ""; - String mqttDewPointTopic = ""; - // Store packet IDs of MQTT publications - uint16_t mqttTemperaturePub = 0; - uint16_t mqttPressurePub = 0; + // strings to reduce flash memory usage (used more than twice) + static const char _name[]; + static const char _enabled[]; // Read the BME280/BMP280 Sensor (which one runs depends on whether Celsius or Farenheit being set in Usermod Menu) void UpdateBME280Data(int SensorType) { float _temperature, _humidity, _pressure; + if (!enabled || (sensorType == 0)) return; // WLEDMM bugfix if (UseCelsius) { BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); @@ -95,7 +96,7 @@ private: sensorTemperature = _temperature; sensorHumidity = _humidity; sensorPressure = _pressure; - tempScale = "°C"; + tempScale = F("°C"); if (sensorType == 1) { sensorHeatIndex = EnvironmentCalculations::HeatIndex(_temperature, _humidity, envTempUnit); @@ -111,7 +112,7 @@ private: sensorTemperature = _temperature; sensorHumidity = _humidity; sensorPressure = _pressure; - tempScale = "°F"; + tempScale = F("°F"); if (sensorType == 1) { sensorHeatIndex = EnvironmentCalculations::HeatIndex(_temperature, _humidity, envTempUnit); @@ -123,18 +124,23 @@ private: // Procedure to define all MQTT discovery Topics void _mqttInitialize() { - mqttTemperatureTopic = String(mqttDeviceTopic) + F("/temperature"); - mqttPressureTopic = String(mqttDeviceTopic) + F("/pressure"); - mqttHumidityTopic = String(mqttDeviceTopic) + F("/humidity"); - mqttHeatIndexTopic = String(mqttDeviceTopic) + F("/heat_index"); - mqttDewPointTopic = String(mqttDeviceTopic) + F("/dew_point"); + char mqttTemperatureTopic[128]; + char mqttHumidityTopic[128]; + char mqttPressureTopic[128]; + char mqttHeatIndexTopic[128]; + char mqttDewPointTopic[128]; + snprintf_P(mqttTemperatureTopic, 127, PSTR("%s/temperature"), mqttDeviceTopic); + snprintf_P(mqttPressureTopic, 127, PSTR("%s/pressure"), mqttDeviceTopic); + snprintf_P(mqttHumidityTopic, 127, PSTR("%s/humidity"), mqttDeviceTopic); + snprintf_P(mqttHeatIndexTopic, 127, PSTR("%s/heat_index"), mqttDeviceTopic); + snprintf_P(mqttDewPointTopic, 127, PSTR("%s/dew_point"), mqttDeviceTopic); if (HomeAssistantDiscovery) { - _createMqttSensor(F("Temperature"), mqttTemperatureTopic, F("temperature"), tempScale); - _createMqttSensor(F("Pressure"), mqttPressureTopic, F("pressure"), F("hPa")); - _createMqttSensor(F("Humidity"), mqttHumidityTopic, F("humidity"), F("%")); - _createMqttSensor(F("HeatIndex"), mqttHeatIndexTopic, F("temperature"), tempScale); - _createMqttSensor(F("DewPoint"), mqttDewPointTopic, F("temperature"), tempScale); + _createMqttSensor(F("Temperature"), mqttTemperatureTopic, "temperature", tempScale); + _createMqttSensor(F("Pressure"), mqttPressureTopic, "pressure", F("hPa")); + _createMqttSensor(F("Humidity"), mqttHumidityTopic, "humidity", F("%")); + _createMqttSensor(F("HeatIndex"), mqttHeatIndexTopic, "temperature", tempScale); + _createMqttSensor(F("DewPoint"), mqttDewPointTopic, "temperature", tempScale); } } @@ -169,21 +175,31 @@ private: mqtt->publish(t.c_str(), 0, true, temp.c_str()); } + void publishMqtt(const char *topic, const char* state) { + //Check if MQTT Connected, otherwise it will crash the 8266 + if (WLED_MQTT_CONNECTED){ + char subuf[128]; + snprintf_P(subuf, 127, PSTR("%s/%s"), mqttDeviceTopic, topic); + mqtt->publish(subuf, 0, false, state); + } + } + public: void setup() { bool HW_Pins_Used = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda); // note whether architecture-based hardware SCL/SDA pins used - PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins + //PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins // WLEDMM not needed PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins - if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins - if (!pinManager.allocateMultiplePins(pins, 2, po)) { sensorType=0; return; } - - Wire.begin(ioPin[1], ioPin[0]); + //if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins // WLEDMM not needed + // WLEDMM join I2C HW wire + if (!pinManager.joinWire()) { sensorType=0; enabled = false; return; } + //if (!pinManager.allocateMultiplePins(pins, 2, po)) { sensorType=0; return; } + //Wire.begin(ioPin[1], ioPin[0]); if (!bme.begin()) { sensorType = 0; - DEBUG_PRINTLN(F("Could not find BME280I2C sensor!")); + DEBUG_PRINTLN(F("Could not find BME280 I2C sensor!")); } else { @@ -207,14 +223,16 @@ public: void loop() { + if (!enabled || strip.isUpdating()) return; + // BME280 sensor MQTT publishing - // Check if sensor present and MQTT Connected, otherwise it will crash the MCU - if (sensorType != 0 && WLED_MQTT_CONNECTED) + // Check if sensor present and Connected, otherwise it will crash the MCU + if (sensorType != 0) { // Timer to fetch new temperature, humidity and pressure data at intervals timer = millis(); - if (timer - lastTemperatureMeasure >= TemperatureInterval * 1000 || mqttTemperaturePub == 0) + if (timer - lastTemperatureMeasure >= TemperatureInterval * 1000) { lastTemperatureMeasure = timer; @@ -223,18 +241,11 @@ public: float temperature = roundf(sensorTemperature * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); float humidity, heatIndex, dewPoint; - if (WLED_MQTT_CONNECTED && !mqttInitialized) - { - _mqttInitialize(); - mqttInitialized = true; - } - // If temperature has changed since last measure, create string populated with device topic // from the UI and values read from sensor, then publish to broker if (temperature != lastTemperature || PublishAlways) { - String topic = String(mqttDeviceTopic) + "/temperature"; - mqttTemperaturePub = mqtt->publish(topic.c_str(), 0, false, String(temperature, TemperatureDecimals).c_str()); + publishMqtt("temperature", String(temperature, TemperatureDecimals).c_str()); } lastTemperature = temperature; // Update last sensor temperature for next loop @@ -247,20 +258,17 @@ public: if (humidity != lastHumidity || PublishAlways) { - String topic = String(mqttDeviceTopic) + F("/humidity"); - mqtt->publish(topic.c_str(), 0, false, String(humidity, HumidityDecimals).c_str()); + publishMqtt("humidity", String(humidity, HumidityDecimals).c_str()); } if (heatIndex != lastHeatIndex || PublishAlways) { - String topic = String(mqttDeviceTopic) + F("/heat_index"); - mqtt->publish(topic.c_str(), 0, false, String(heatIndex, TemperatureDecimals).c_str()); + publishMqtt("heat_index", String(heatIndex, TemperatureDecimals).c_str()); } if (dewPoint != lastDewPoint || PublishAlways) { - String topic = String(mqttDeviceTopic) + F("/dew_point"); - mqtt->publish(topic.c_str(), 0, false, String(dewPoint, TemperatureDecimals).c_str()); + publishMqtt("dew_point", String(dewPoint, TemperatureDecimals).c_str()); } lastHumidity = humidity; @@ -269,7 +277,7 @@ public: } } - if (timer - lastPressureMeasure >= PressureInterval * 1000 || mqttPressurePub == 0) + if (timer - lastPressureMeasure >= PressureInterval * 1000) { lastPressureMeasure = timer; @@ -277,15 +285,23 @@ public: if (pressure != lastPressure || PublishAlways) { - String topic = String(mqttDeviceTopic) + F("/pressure"); - mqttPressurePub = mqtt->publish(topic.c_str(), 0, true, String(pressure, PressureDecimals).c_str()); + publishMqtt("pressure", String(pressure, PressureDecimals).c_str()); } lastPressure = pressure; } } } - + + void onMqttConnect(bool sessionPresent) + { + if (WLED_MQTT_CONNECTED && !mqttInitialized) + { + _mqttInitialize(); + mqttInitialized = true; + } + } + /* * API calls te enable data exchange between WLED modules */ @@ -294,9 +310,9 @@ public: return (float)roundf(sensorTemperature * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); } else { return (float)roundf(sensorTemperature * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) * 1.8f + 32; - } - + } } + inline float getTemperatureF() { if (UseCelsius) { return ((float)roundf(sensorTemperature * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) -32) * 0.56f; @@ -304,12 +320,15 @@ public: return (float)roundf(sensorTemperature * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); } } + inline float getHumidity() { return (float)roundf(sensorHumidity * powf(10, HumidityDecimals)); } + inline float getPressure() { return (float)roundf(sensorPressure * powf(10, PressureDecimals)); } + inline float getDewPointC() { if (UseCelsius) { return (float)roundf(sensorDewPoint * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); @@ -317,6 +336,7 @@ public: return (float)roundf(sensorDewPoint * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) * 1.8f + 32; } } + inline float getDewPointF() { if (UseCelsius) { return ((float)roundf(sensorDewPoint * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) -32) * 0.56f; @@ -324,13 +344,16 @@ public: return (float)roundf(sensorDewPoint * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); } } + inline float getHeatIndexC() { if (UseCelsius) { return (float)roundf(sensorHeatIndex * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals); } else { return (float)roundf(sensorHeatIndex * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) * 1.8f + 32; } - }inline float getHeatIndexF() { + } + + inline float getHeatIndexF() { if (UseCelsius) { return ((float)roundf(sensorHeatIndex * powf(10, TemperatureDecimals)) / powf(10, TemperatureDecimals) -32) * 0.56f; } else { @@ -381,10 +404,23 @@ public: return; } + void appendConfigData() { + oappend(SET_F("addHB('BME280');")); + + oappend(SET_F("addInfo('BME280/BMP280:pin[]',0,'','I2C/SPI CLK');")); + oappend(SET_F("dRO('BME280/BMP280:pin[]',0);")); // disable read only pins + oappend(SET_F("rOpt('BME280/BMP280:pin[]',0,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + + oappend(SET_F("addInfo('BME280/BMP280:pin[]',1,'','I2C/SPI DTA');")); + oappend(SET_F("rOpt('BME280/BMP280:pin[]',1,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); + } + + // Save Usermod Config Settings void addToConfig(JsonObject& root) { - JsonObject top = root.createNestedObject(F("BME280/BMP280")); + JsonObject top = root.createNestedObject(FPSTR(_name)); + top[FPSTR(_enabled)] = enabled; top[F("TemperatureDecimals")] = TemperatureDecimals; top[F("HumidityDecimals")] = HumidityDecimals; top[F("PressureDecimals")] = PressureDecimals; @@ -394,8 +430,9 @@ public: top[F("UseCelsius")] = UseCelsius; top[F("HomeAssistantDiscovery")] = HomeAssistantDiscovery; JsonArray io_pin = top.createNestedArray(F("pin")); - for (byte i=0; i<2; i++) io_pin.add(ioPin[i]); - top[F("help4Pins")] = F("SCL,SDA"); // help for Settings page + //WLEDMM: avoid global pin hijacking + io_pin.add((ioPin[0]==i2c_scl)?-1:ioPin[0]); + io_pin.add((ioPin[1]==i2c_sda)?-1:ioPin[1]); DEBUG_PRINTLN(F("BME280 config saved.")); } @@ -405,17 +442,17 @@ public: // default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor // setting them inside readFromConfig() is slightly more robust, handling the rare but plausible use case of single value being missing after boot (e.g. if the cfg.json was manually edited and a value was removed) - int8_t newPin[2]; for (byte i=0; i<2; i++) newPin[i] = ioPin[i]; // prepare to note changed pins - JsonObject top = root[F("BME280/BMP280")]; + JsonObject top = root[FPSTR(_name)]; if (top.isNull()) { - DEBUG_PRINT(F("BME280/BMP280")); + DEBUG_PRINT(F(_name)); DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); return false; } bool configComplete = !top.isNull(); + configComplete &= getJsonValue(top[FPSTR(_enabled)], enabled); // A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing configComplete &= getJsonValue(top[F("TemperatureDecimals")], TemperatureDecimals, 1); configComplete &= getJsonValue(top[F("HumidityDecimals")], HumidityDecimals, 0); @@ -427,7 +464,7 @@ public: configComplete &= getJsonValue(top[F("HomeAssistantDiscovery")], HomeAssistantDiscovery, false); for (byte i=0; i<2; i++) configComplete &= getJsonValue(top[F("pin")][i], newPin[i], ioPin[i]); - DEBUG_PRINT(FPSTR(F("BME280/BMP280"))); + DEBUG_PRINT(FPSTR(_name)); if (!initDone) { // first run: reading from cfg.json for (byte i=0; i<2; i++) ioPin[i] = newPin[i]; @@ -454,4 +491,7 @@ public: uint16_t getId() { return USERMOD_ID_BME280; } -}; \ No newline at end of file +}; + +const char UsermodBME280::_name[] PROGMEM = "BME280/BMP280"; +const char UsermodBME280::_enabled[] PROGMEM = "enabled"; diff --git a/usermods/battery_status_basic/assets/battery_connection_schematic_01.png b/usermods/Battery/assets/battery_connection_schematic_01.png similarity index 100% rename from usermods/battery_status_basic/assets/battery_connection_schematic_01.png rename to usermods/Battery/assets/battery_connection_schematic_01.png diff --git a/usermods/battery_status_basic/assets/battery_connection_schematic_02.png b/usermods/Battery/assets/battery_connection_schematic_02.png similarity index 100% rename from usermods/battery_status_basic/assets/battery_connection_schematic_02.png rename to usermods/Battery/assets/battery_connection_schematic_02.png diff --git a/usermods/Battery/assets/battery_info_screen.png b/usermods/Battery/assets/battery_info_screen.png new file mode 100644 index 00000000..5aa60a03 Binary files /dev/null and b/usermods/Battery/assets/battery_info_screen.png differ diff --git a/usermods/Battery/assets/battery_usermod_logo.png b/usermods/Battery/assets/battery_usermod_logo.png new file mode 100644 index 00000000..b1134eb3 Binary files /dev/null and b/usermods/Battery/assets/battery_usermod_logo.png differ diff --git a/usermods/Battery/battery_defaults.h b/usermods/Battery/battery_defaults.h new file mode 100644 index 00000000..71c73b3b --- /dev/null +++ b/usermods/Battery/battery_defaults.h @@ -0,0 +1,72 @@ +// pin defaults +// for the esp32 it is best to use the ADC1: GPIO32 - GPIO39 +// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html +#ifndef USERMOD_BATTERY_MEASUREMENT_PIN + #ifdef ARDUINO_ARCH_ESP32 + #define USERMOD_BATTERY_MEASUREMENT_PIN -1 //WLEDMM instead of 35 + #else //ESP8266 boards + #define USERMOD_BATTERY_MEASUREMENT_PIN A0 + #endif +#endif + +// the frequency to check the battery, 30 sec +#ifndef USERMOD_BATTERY_MEASUREMENT_INTERVAL + #define USERMOD_BATTERY_MEASUREMENT_INTERVAL 30000 +#endif + +// default for 18650 battery +// https://batterybro.com/blogs/18650-wholesale-battery-reviews/18852515-when-to-recycle-18650-batteries-and-how-to-start-a-collection-center-in-your-vape-shop +// Discharge voltage: 2.5 volt + .1 for personal safety +#ifndef USERMOD_BATTERY_MIN_VOLTAGE + #ifdef USERMOD_BATTERY_USE_LIPO + // LiPo "1S" Batteries should not be dischared below 3V !! + #define USERMOD_BATTERY_MIN_VOLTAGE 3.2f + #else + #define USERMOD_BATTERY_MIN_VOLTAGE 2.6f + #endif +#endif + +#ifndef USERMOD_BATTERY_MAX_VOLTAGE + #define USERMOD_BATTERY_MAX_VOLTAGE 4.2f +#endif + +// a common capacity for single 18650 battery cells is between 2500 and 3600 mAh +#ifndef USERMOD_BATTERY_TOTAL_CAPACITY + #define USERMOD_BATTERY_TOTAL_CAPACITY 3100 +#endif + +// offset or calibration value to fine tune the calculated voltage +#ifndef USERMOD_BATTERY_CALIBRATION + #define USERMOD_BATTERY_CALIBRATION 0 +#endif + +// calculate remaining time / the time that is left before the battery runs out of power +// #ifndef USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED +// #define USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED false +// #endif + +// auto-off feature +#ifndef USERMOD_BATTERY_AUTO_OFF_ENABLED + #define USERMOD_BATTERY_AUTO_OFF_ENABLED true +#endif + +#ifndef USERMOD_BATTERY_AUTO_OFF_THRESHOLD + #define USERMOD_BATTERY_AUTO_OFF_THRESHOLD 10 +#endif + +// low power indication feature +#ifndef USERMOD_BATTERY_LOW_POWER_INDICATOR_ENABLED + #define USERMOD_BATTERY_LOW_POWER_INDICATOR_ENABLED true +#endif + +#ifndef USERMOD_BATTERY_LOW_POWER_INDICATOR_PRESET + #define USERMOD_BATTERY_LOW_POWER_INDICATOR_PRESET 0 +#endif + +#ifndef USERMOD_BATTERY_LOW_POWER_INDICATOR_THRESHOLD + #define USERMOD_BATTERY_LOW_POWER_INDICATOR_THRESHOLD 20 +#endif + +#ifndef USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION + #define USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION 5 +#endif \ No newline at end of file diff --git a/usermods/Battery/readme.md b/usermods/Battery/readme.md new file mode 100644 index 00000000..d55573ab --- /dev/null +++ b/usermods/Battery/readme.md @@ -0,0 +1,112 @@ +

+ +

+ +# Welcome to the battery usermod! 🔋 + +Enables battery level monitoring of your project. + +For this to work, the positive side of the (18650) battery must be connected to pin `A0` of the d1 mini/esp8266 with a 100k Ohm resistor (see [Useful Links](#useful-links)). + +If you have an ESP32 board, connect the positive side of the battery to ADC1 (GPIO32 - GPIO39) + +

+ +

+ +## ⚙️ Features + +- 💯 Displays current battery voltage +- 🚥 Displays battery level +- 🚫 Auto-off with configurable Threshold +- 🚨 Low power indicator with many configuration posibilities + +## 🎈 Installation + +define `USERMOD_BATTERY` in `wled00/my_config.h` + +### Example wiring + +

+ +

+ +### Define Your Options + +| Name | Unit | Description | +| ----------------------------------------------- | ----------- |-------------------------------------------------------------------------------------- | +| `USERMOD_BATTERY` | | define this (in `my_config.h`) to have this usermod included wled00\usermods_list.cpp | +| `USERMOD_BATTERY_USE_LIPO` | | define this (in `my_config.h`) if you use LiPo rechargeables (1S) | +| `USERMOD_BATTERY_MEASUREMENT_PIN` | | defaults to A0 on ESP8266 and GPIO35 on ESP32 | +| `USERMOD_BATTERY_MEASUREMENT_INTERVAL` | ms | battery check interval. defaults to 30 seconds | +| `USERMOD_BATTERY_MIN_VOLTAGE` | v | minimum battery voltage. default is 2.6 (18650 battery standard) | +| `USERMOD_BATTERY_MAX_VOLTAGE` | v | maximum battery voltage. default is 4.2 (18650 battery standard) | +| `USERMOD_BATTERY_TOTAL_CAPACITY` | mAh | the capacity of all cells in parralel sumed up | +| `USERMOD_BATTERY_CALIBRATION` | | offset / calibration number, fine tune the measured voltage by the microcontroller | +| Auto-Off | --- | --- | +| `USERMOD_BATTERY_AUTO_OFF_ENABLED` | true/false | enables auto-off | +| `USERMOD_BATTERY_AUTO_OFF_THRESHOLD` | % (0-100) | when this threshold is reached master power turns off | +| Low-Power-Indicator | --- | --- | +| `USERMOD_BATTERY_LOW_POWER_INDICATOR_ENABLED` | true/false | enables low power indication | +| `USERMOD_BATTERY_LOW_POWER_INDICATOR_PRESET` | preset id | when low power is detected then use this preset to indicate low power | +| `USERMOD_BATTERY_LOW_POWER_INDICATOR_THRESHOLD` | % (0-100) | when this threshold is reached low power gets indicated | +| `USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION` | seconds | for this long the configured preset is played | + +All parameters can be configured at runtime via the Usermods settings page. + +## ⚠️ Important + +- Make sure you know your battery specifications! All batteries are **NOT** the same! +- Example: + +| Your battery specification table | | Options you can define | +| :-------------------------------- |:--------------- | :---------------------------- | +| Capacity | 3500mAh 12,5 Wh | | +| Minimum capacity | 3350mAh 11,9 Wh | | +| Rated voltage | 3.6V - 3.7V | | +| **Charging end voltage** | **4,2V ± 0,05** | `USERMOD_BATTERY_MAX_VOLTAGE` | +| **Discharge voltage** | **2,5V** | `USERMOD_BATTERY_MIN_VOLTAGE` | +| Max. discharge current (constant) | 10A (10000mA) | | +| max. charging current | 1.7A (1700mA) | | +| ... | ... | ... | +| .. | .. | .. | + +Specification from: [Molicel INR18650-M35A, 3500mAh 10A Lithium-ion battery, 3.6V - 3.7V](https://www.akkuteile.de/lithium-ionen-akkus/18650/molicel/molicel-inr18650-m35a-3500mah-10a-lithium-ionen-akku-3-6v-3-7v_100833) + +## 🌐 Useful Links + +- https://lazyzero.de/elektronik/esp8266/wemos_d1_mini_a0/start +- https://arduinodiy.wordpress.com/2016/12/25/monitoring-lipo-battery-voltage-with-wemos-d1-minibattery-shield-and-thingspeak/ + +## 📝 Change Log + +2023-01-04 + +- basic support for LiPo rechargeable batteries ( `-D USERMOD_BATTERY_USE_LIPO`) +- improved support for esp32 (read calibrated voltage) +- corrected config saving (measurement pin, and battery min/max were lost) +- various bugfixes + +2022-12-25 + +- added "auto-off" feature +- added "low-power-indication" feature +- added "calibration/offset" field to configuration page +- added getter and setter, so that user usermods could interact with this one +- update readme (added new options, made it markdownlint compliant) + +2021-09-02 + +- added "Battery voltage" to info +- added circuit diagram to readme +- added MQTT support, sending battery voltage +- minor fixes + +2021-08-15 + +- changed `USERMOD_BATTERY_MIN_VOLTAGE` to 2.6 volt as default for 18650 batteries +- Updated readme, added specification table + +2021-08-10 + +- Created diff --git a/usermods/Battery/usermod_v2_Battery.h b/usermods/Battery/usermod_v2_Battery.h new file mode 100644 index 00000000..98aeda43 --- /dev/null +++ b/usermods/Battery/usermod_v2_Battery.h @@ -0,0 +1,775 @@ +#pragma once + +#include "wled.h" +#include "battery_defaults.h" + +/* + * Usermod by Maximilian Mewes + * Mail: mewes.maximilian@gmx.de + * GitHub: itCarl + * Date: 25.12.2022 + * If you have any questions, please feel free to contact me. + */ +class UsermodBattery : public Usermod +{ + private: + // battery pin can be defined in my_config.h + int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN; + // how often to read the battery voltage + unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL; + unsigned long nextReadTime = 0; + unsigned long lastReadTime = 0; + // battery min. voltage + float minBatteryVoltage = USERMOD_BATTERY_MIN_VOLTAGE; + // battery max. voltage + float maxBatteryVoltage = USERMOD_BATTERY_MAX_VOLTAGE; + // all battery cells summed up + unsigned int totalBatteryCapacity = USERMOD_BATTERY_TOTAL_CAPACITY; + // raw analog reading + float rawValue = 0.0f; + // calculated voltage + float voltage = maxBatteryVoltage; + // mapped battery level based on voltage + int8_t batteryLevel = 100; + // offset or calibration value to fine tune the calculated voltage + float calibration = USERMOD_BATTERY_CALIBRATION; + + // time left estimation feature + // bool calculateTimeLeftEnabled = USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED; + // float estimatedTimeLeft = 0.0; + + // auto shutdown/shutoff/master off feature + bool autoOffEnabled = USERMOD_BATTERY_AUTO_OFF_ENABLED; + int8_t autoOffThreshold = USERMOD_BATTERY_AUTO_OFF_THRESHOLD; + + // low power indicator feature + bool lowPowerIndicatorEnabled = USERMOD_BATTERY_LOW_POWER_INDICATOR_ENABLED; + int8_t lowPowerIndicatorPreset = USERMOD_BATTERY_LOW_POWER_INDICATOR_PRESET; + int8_t lowPowerIndicatorThreshold = USERMOD_BATTERY_LOW_POWER_INDICATOR_THRESHOLD; + int8_t lowPowerIndicatorReactivationThreshold = lowPowerIndicatorThreshold+10; + int8_t lowPowerIndicatorDuration = USERMOD_BATTERY_LOW_POWER_INDICATOR_DURATION; + bool lowPowerIndicationDone = false; + unsigned long lowPowerActivationTime = 0; // used temporary during active time + int8_t lastPreset = 0; + + bool initDone = false; + bool initializing = true; + + // strings to reduce flash memory usage (used more than twice) + static const char _name[]; + static const char _readInterval[]; + static const char _enabled[]; + static const char _threshold[]; + static const char _preset[]; + static const char _duration[]; + static const char _init[]; + + + // custom map function + // https://forum.arduino.cc/t/floating-point-using-map-function/348113/2 + double mapf(double x, double in_min, double in_max, double out_min, double out_max) + { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + + float dot2round(float x) + { + float nx = (int)(x * 100 + .5); + return (float)(nx / 100); + } + + /* + * Turn off all leds + */ + void turnOff() + { + bri = 0; + stateUpdated(CALL_MODE_DIRECT_CHANGE); + } + + /* + * Indicate low power by activating a configured preset for a given time and then switching back to the preset that was selected previously + */ + void lowPowerIndicator() + { + if (!lowPowerIndicatorEnabled) return; + if (batteryPin < 0) return; // no measurement + if (lowPowerIndicationDone && lowPowerIndicatorReactivationThreshold <= batteryLevel) lowPowerIndicationDone = false; + if (lowPowerIndicatorThreshold <= batteryLevel) return; + if (lowPowerIndicationDone) return; + if (lowPowerActivationTime <= 1) { + lowPowerActivationTime = millis(); + lastPreset = currentPreset; + applyPreset(lowPowerIndicatorPreset); + } + + if (lowPowerActivationTime+(lowPowerIndicatorDuration*1000) <= millis()) { + lowPowerIndicationDone = true; + lowPowerActivationTime = 0; + applyPreset(lastPreset); + } + } + + public: + //Functions called by WLED + + /* + * setup() is called once at boot. WiFi is not yet connected at this point. + * You can use it to initialize variables, sensors or similar. + */ + void setup() + { + #ifdef ARDUINO_ARCH_ESP32 + bool success = false; + DEBUG_PRINTLN(F("Allocating battery pin...")); + if (batteryPin >= 0 && digitalPinToAnalogChannel(batteryPin) >= 0) + if (pinManager.allocatePin(batteryPin, false, PinOwner::UM_Battery)) { + DEBUG_PRINTLN(F("Battery pin allocation succeeded.")); + success = true; + } + + if (!success) { + DEBUG_PRINTLN(F("Battery pin allocation failed.")); + batteryPin = -1; // allocation failed + } else { + pinMode(batteryPin, INPUT); + } + #else //ESP8266 boards have only one analog input pin A0 + + pinMode(batteryPin, INPUT); + #endif + + nextReadTime = millis() + readingInterval; + lastReadTime = millis(); + + initDone = true; + } + + + /* + * connected() is called every time the WiFi is (re)connected + * Use it to initialize network interfaces + */ + void connected() + { + //Serial.println("Connected to WiFi!"); + } + + + /* + * loop() is called continuously. Here you can check for events, read sensors, etc. + * + */ + void loop() + { + if(strip.isUpdating()) return; + + lowPowerIndicator(); + + // check the battery level every USERMOD_BATTERY_MEASUREMENT_INTERVAL (ms) + if (millis() < nextReadTime) return; + + nextReadTime = millis() + readingInterval; + lastReadTime = millis(); + + if (batteryPin < 0) return; // nothing to read + + initializing = false; + +#ifdef ARDUINO_ARCH_ESP32 + // use calibrated millivolts analogread on esp32 (150 mV ~ 2450 mV) + rawValue = analogReadMilliVolts(batteryPin); + // calculate the voltage + voltage = (rawValue / 1000.0f) + calibration; + // usually a voltage divider (50%) is used on ESP32, so we need to multiply by 2 + voltage *= 2.0f; +#else + // read battery raw input + rawValue = analogRead(batteryPin); + + // calculate the voltage + voltage = ((rawValue / getAdcPrecision()) * maxBatteryVoltage) + calibration; +#endif + // check if voltage is within specified voltage range, allow 10% over/under voltage + voltage = ((voltage < minBatteryVoltage * 0.85f) || (voltage > maxBatteryVoltage * 1.1f)) ? -1.0f : voltage; + + // translate battery voltage into percentage + /* + the standard "map" function doesn't work + https://www.arduino.cc/reference/en/language/functions/math/map/ notes and warnings at the bottom + */ + #ifdef USERMOD_BATTERY_USE_LIPO + batteryLevel = mapf(voltage, minBatteryVoltage, maxBatteryVoltage, 0, 100); // basic mapping + // LiPo batteries have a differnt dischargin curve, see + // https://blog.ampow.com/lipo-voltage-chart/ + if (batteryLevel < 40.0f) + batteryLevel = mapf(batteryLevel, 0, 40, 0, 12); // last 45% -> drops very quickly + else { + if (batteryLevel < 90.0f) + batteryLevel = mapf(batteryLevel, 40, 90, 12, 95); // 90% ... 40% -> almost linear drop + else // level > 90% + batteryLevel = mapf(batteryLevel, 90, 105, 95, 100); // highest 15% -> drop slowly + } + #else + batteryLevel = mapf(voltage, minBatteryVoltage, maxBatteryVoltage, 0, 100); + #endif + if (voltage > -1.0f) batteryLevel = constrain(batteryLevel, 0.0f, 110.0f); + + // if (calculateTimeLeftEnabled) { + // float currentBatteryCapacity = totalBatteryCapacity; + // estimatedTimeLeft = (currentBatteryCapacity/strip.currentMilliamps)*60; + // } + + // Auto off -- Master power off + if (autoOffEnabled && (autoOffThreshold >= batteryLevel)) + turnOff(); + +#ifndef WLED_DISABLE_MQTT + // SmartHome stuff + // still don't know much about MQTT and/or HA + if (WLED_MQTT_CONNECTED) { + char buf[64]; // buffer for snprintf() + snprintf_P(buf, 63, PSTR("%s/voltage"), mqttDeviceTopic); + mqtt->publish(buf, 0, false, String(voltage).c_str()); + } +#endif + + } + + /* + * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. + * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. + * Below it is shown how this could be used for e.g. a light sensor + */ + void addToJsonInfo(JsonObject& root) + { + JsonObject user = root["u"]; + if (user.isNull()) user = root.createNestedObject("u"); + + if (batteryPin < 0) { + JsonArray infoVoltage = user.createNestedArray(F("Battery voltage")); + infoVoltage.add(F("n/a")); + infoVoltage.add(F(" invalid GPIO")); + return; // no GPIO - nothing to report + } + + // info modal display names + JsonArray infoPercentage = user.createNestedArray(F("Battery level")); + JsonArray infoVoltage = user.createNestedArray(F("Battery voltage")); + // if (calculateTimeLeftEnabled) + // { + // JsonArray infoEstimatedTimeLeft = user.createNestedArray(F("Estimated time left")); + // if (initializing) { + // infoEstimatedTimeLeft.add(FPSTR(_init)); + // } else { + // infoEstimatedTimeLeft.add(estimatedTimeLeft); + // infoEstimatedTimeLeft.add(F(" min")); + // } + // } + JsonArray infoNextUpdate = user.createNestedArray(F("Next update")); + + infoNextUpdate.add((nextReadTime - millis()) / 1000); + infoNextUpdate.add(F(" sec")); + + if (initializing) { + infoPercentage.add(FPSTR(_init)); + infoVoltage.add(FPSTR(_init)); + return; + } + + if (batteryLevel < 0) { + infoPercentage.add(F("invalid")); + } else { + infoPercentage.add(batteryLevel); + } + infoPercentage.add(F(" %")); + + if (voltage < 0) { + infoVoltage.add(F("invalid")); + } else { + infoVoltage.add(dot2round(voltage)); + } + infoVoltage.add(F(" V")); + } + + + /* + * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). + * Values in the state object may be modified by connected clients + */ + /* + void addToJsonState(JsonObject& root) + { + + } + */ + + + /* + * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). + * Values in the state object may be modified by connected clients + */ + /* + void readFromJsonState(JsonObject& root) + { + } + */ + + + /* + * 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) + * If you want to force saving the current state, use serializeConfig() in your loop(). + * + * CAUTION: serializeConfig() will initiate a filesystem write operation. + * It might cause the LEDs to stutter and will cause flash wear if called too often. + * Use it sparingly and always in the loop, never in network callbacks! + * + * addToConfig() will make your settings editable through the Usermod Settings page automatically. + * + * Usermod Settings Overview: + * - Numeric values are treated as floats in the browser. + * - If the numeric value entered into the browser contains a decimal point, it will be parsed as a C float + * before being returned to the Usermod. The float data type has only 6-7 decimal digits of precision, and + * doubles are not supported, numbers will be rounded to the nearest float value when being parsed. + * The range accepted by the input field is +/- 1.175494351e-38 to +/- 3.402823466e+38. + * - If the numeric value entered into the browser doesn't contain a decimal point, it will be parsed as a + * C int32_t (range: -2147483648 to 2147483647) before being returned to the usermod. + * Overflows or underflows are truncated to the max/min value for an int32_t, and again truncated to the type + * used in the Usermod when reading the value from ArduinoJson. + * - Pin values can be treated differently from an integer value by using the key name "pin" + * - "pin" can contain a single or array of integer values + * - On the Usermod Settings page there is simple checking for pin conflicts and warnings for special pins + * - Red color indicates a conflict. Yellow color indicates a pin with a warning (e.g. an input-only pin) + * - Tip: use int8_t to store the pin value in the Usermod, so a -1 value (pin not set) can be used + * + * See usermod_v2_auto_save.h for an example that saves Flash space by reusing ArduinoJson key name strings + * + * If you need a dedicated settings page with custom layout for your Usermod, that takes a lot more work. + * You will have to add the setting to the HTML, xml.cpp and set.cpp manually. + * See the WLED Soundreactive fork (code and wiki) for reference. https://github.com/atuline/WLED + * + * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! + */ + void addToConfig(JsonObject& root) + { + JsonObject battery = root.createNestedObject(FPSTR(_name)); // usermodname + #ifdef ARDUINO_ARCH_ESP32 + battery[F("pin")] = batteryPin; + #endif + + // battery[F("time-left")] = calculateTimeLeftEnabled; + battery[F("min-voltage")] = minBatteryVoltage; + battery[F("max-voltage")] = maxBatteryVoltage; + battery[F("capacity")] = totalBatteryCapacity; + battery[F("calibration")] = calibration; + battery[FPSTR(_readInterval)] = readingInterval; + + JsonObject ao = battery.createNestedObject(F("auto-off")); // auto off section + ao[FPSTR(_enabled)] = autoOffEnabled; + ao[FPSTR(_threshold)] = autoOffThreshold; + + JsonObject lp = battery.createNestedObject(F("indicator")); // low power section + lp[FPSTR(_enabled)] = lowPowerIndicatorEnabled; + lp[FPSTR(_preset)] = lowPowerIndicatorPreset; // dropdown trickery (String)lowPowerIndicatorPreset; + lp[FPSTR(_threshold)] = lowPowerIndicatorThreshold; + lp[FPSTR(_duration)] = lowPowerIndicatorDuration; + + DEBUG_PRINTLN(F("Battery config saved.")); + } + + void appendConfigData() + { + oappend(SET_F("addHB('Battery');")); + + oappend(SET_F("addInfo('Battery:min-voltage', 1, 'v');")); + oappend(SET_F("addInfo('Battery:max-voltage', 1, 'v');")); + oappend(SET_F("addInfo('Battery:capacity', 1, 'mAh');")); + oappend(SET_F("addInfo('Battery:interval', 1, 'ms');")); + oappend(SET_F("addInfo('Battery:auto-off:threshold', 1, '%');")); + oappend(SET_F("addInfo('Battery:indicator:threshold', 1, '%');")); + oappend(SET_F("addInfo('Battery:indicator:duration', 1, 's');")); + + // cannot quite get this mf to work. its exeeding some buffer limit i think + // what i wanted is a list of all presets to select one from + // oappend(SET_F("bd=addDropdown('Battery:low-power-indicator', 'preset');")); + // the loop generates: oappend(SET_F("addOption(bd, 'preset name', preset id);")); + // for(int8_t i=1; i < 42; i++) { + // oappend(SET_F("addOption(bd, 'Preset#")); + // oappendi(i); + // oappend(SET_F("',")); + // oappendi(i); + // oappend(SET_F(");")); + // } + } + + + /* + * readFromConfig() can be used to read back the custom settings you added with addToConfig(). + * This is called by WLED when settings are loaded (currently this only happens immediately after boot, or after saving on the Usermod Settings page) + * + * readFromConfig() is called BEFORE setup(). This means you can use your persistent values in setup() (e.g. pin assignments, buffer sizes), + * but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup. + * If you don't know what that is, don't fret. It most likely doesn't affect your use case :) + * + * Return true in case the config values returned from Usermod Settings were complete, or false if you'd like WLED to save your defaults to disk (so any missing values are editable in Usermod Settings) + * + * getJsonValue() returns false if the value is missing, or copies the value into the variable provided and returns true if the value is present + * The configComplete variable is true only if the "exampleUsermod" object and all values are present. If any values are missing, WLED will know to call addToConfig() to save them + * + * This function is guaranteed to be called on boot, but could also be called every time settings are updated + */ + bool readFromConfig(JsonObject& root) + { + #ifdef ARDUINO_ARCH_ESP32 + int8_t newBatteryPin = batteryPin; + #endif + + JsonObject battery = root[FPSTR(_name)]; + if (battery.isNull()) + { + DEBUG_PRINT(FPSTR(_name)); + DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); + return false; + } + + #ifdef ARDUINO_ARCH_ESP32 + newBatteryPin = battery[F("pin")] | newBatteryPin; + #endif + // calculateTimeLeftEnabled = battery[F("time-left")] | calculateTimeLeftEnabled; + setMinBatteryVoltage(battery[F("min-voltage")] | minBatteryVoltage); + setMaxBatteryVoltage(battery[F("max-voltage")] | maxBatteryVoltage); + setTotalBatteryCapacity(battery[F("capacity")] | totalBatteryCapacity); + setCalibration(battery[F("calibration")] | calibration); + setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval); + + JsonObject ao = battery[F("auto-off")]; + setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled); + setAutoOffThreshold(ao[FPSTR(_threshold)] | autoOffThreshold); + + JsonObject lp = battery[F("indicator")]; + setLowPowerIndicatorEnabled(lp[FPSTR(_enabled)] | lowPowerIndicatorEnabled); + setLowPowerIndicatorPreset(lp[FPSTR(_preset)] | lowPowerIndicatorPreset); // dropdown trickery (int)lp["preset"] + setLowPowerIndicatorThreshold(lp[FPSTR(_threshold)] | lowPowerIndicatorThreshold); + lowPowerIndicatorReactivationThreshold = lowPowerIndicatorThreshold+10; + setLowPowerIndicatorDuration(lp[FPSTR(_duration)] | lowPowerIndicatorDuration); + + DEBUG_PRINT(FPSTR(_name)); + + #ifdef ARDUINO_ARCH_ESP32 + if (!initDone) + { + // first run: reading from cfg.json + batteryPin = newBatteryPin; + DEBUG_PRINTLN(F(" config loaded.")); + } + else + { + DEBUG_PRINTLN(F(" config (re)loaded.")); + + // changing parameters from settings page + if (newBatteryPin != batteryPin) + { + // deallocate pin + pinManager.deallocatePin(batteryPin, PinOwner::UM_Battery); + batteryPin = newBatteryPin; + // initialise + setup(); + } + } + #endif + + return !battery[FPSTR(_readInterval)].isNull(); + } + + /* + * Generate a preset sample for low power indication + */ + void generateExamplePreset() + { + // StaticJsonDocument<300> j; + // JsonObject preset = j.createNestedObject(); + // preset["mainseg"] = 0; + // JsonArray seg = preset.createNestedArray("seg"); + // JsonObject seg0 = seg.createNestedObject(); + // seg0["id"] = 0; + // seg0["start"] = 0; + // seg0["stop"] = 60; + // seg0["grp"] = 0; + // seg0["spc"] = 0; + // seg0["on"] = true; + // seg0["bri"] = 255; + + // JsonArray col0 = seg0.createNestedArray("col"); + // JsonArray col00 = col0.createNestedArray(); + // col00.add(255); + // col00.add(0); + // col00.add(0); + + // seg0["fx"] = 1; + // seg0["sx"] = 128; + // seg0["ix"] = 128; + + // savePreset(199, "Low power Indicator", preset); + } + + + /* + * + * Getter and Setter. Just in case some other usermod wants to interact with this in the future + * + */ + + /* + * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). + * This could be used in the future for the system to determine whether your usermod is installed. + */ + uint16_t getId() + { + return USERMOD_ID_BATTERY; + } + + + unsigned long getReadingInterval() + { + return readingInterval; + } + + /* + * minimum repetition is 3000ms (3s) + */ + void setReadingInterval(unsigned long newReadingInterval) + { + readingInterval = max((unsigned long)3000, newReadingInterval); + } + + + /* + * Get lowest configured battery voltage + */ + float getMinBatteryVoltage() + { + return minBatteryVoltage; + } + + /* + * Set lowest battery voltage + * can't be below 0 volt + */ + void setMinBatteryVoltage(float voltage) + { + minBatteryVoltage = max(0.0f, voltage); + } + + /* + * Get highest configured battery voltage + */ + float getMaxBatteryVoltage() + { + return maxBatteryVoltage; + } + + /* + * Set highest battery voltage + * can't be below minBatteryVoltage + */ + void setMaxBatteryVoltage(float voltage) + { + #ifdef USERMOD_BATTERY_USE_LIPO + maxBatteryVoltage = max(getMinBatteryVoltage()+0.7f, voltage); + #else + maxBatteryVoltage = max(getMinBatteryVoltage()+1.0f, voltage); + #endif + } + + + /* + * Get the capacity of all cells in parralel sumed up + * unit: mAh + */ + unsigned int getTotalBatteryCapacity() + { + return totalBatteryCapacity; + } + + void setTotalBatteryCapacity(unsigned int capacity) + { + totalBatteryCapacity = capacity; + } + + /* + * Get the choosen adc precision + * esp8266 = 10bit resolution = 1024.0f + * esp32 = 12bit resolution = 4095.0f + */ + float getAdcPrecision() + { + #ifdef ARDUINO_ARCH_ESP32 + // esp32 + return 4096.0f; + #else + // esp8266 + return 1024.0f; + #endif + } + + /* + * Get the calculated voltage + * formula: (adc pin value / adc precision * max voltage) + calibration + */ + float getVoltage() + { + return voltage; + } + + /* + * Get the mapped battery level (0 - 100) based on voltage + * important: voltage can drop when a load is applied, so its only an estimate + */ + int8_t getBatteryLevel() + { + return batteryLevel; + } + + /* + * Get the configured calibration value + * a offset value to fine-tune the calculated voltage. + */ + float getCalibration() + { + return calibration; + } + + /* + * Set the voltage calibration offset value + * a offset value to fine-tune the calculated voltage. + */ + void setCalibration(float offset) + { + calibration = offset; + } + + + /* + * Get auto-off feature enabled status + * is auto-off enabled, true/false + */ + bool getAutoOffEnabled() + { + return autoOffEnabled; + } + + /* + * Set auto-off feature status + */ + void setAutoOffEnabled(bool enabled) + { + autoOffEnabled = enabled; + } + + /* + * Get auto-off threshold in percent (0-100) + */ + int8_t getAutoOffThreshold() + { + return autoOffThreshold; + } + + /* + * Set auto-off threshold in percent (0-100) + */ + void setAutoOffThreshold(int8_t threshold) + { + autoOffThreshold = min((int8_t)100, max((int8_t)0, threshold)); + // when low power indicator is enabled the auto-off threshold cannot be above indicator threshold + autoOffThreshold = lowPowerIndicatorEnabled /*&& autoOffEnabled*/ ? min(lowPowerIndicatorThreshold-1, (int)autoOffThreshold) : autoOffThreshold; + } + + + /* + * Get low-power-indicator feature enabled status + * is the low-power-indicator enabled, true/false + */ + bool getLowPowerIndicatorEnabled() + { + return lowPowerIndicatorEnabled; + } + + /* + * Set low-power-indicator feature status + */ + void setLowPowerIndicatorEnabled(bool enabled) + { + lowPowerIndicatorEnabled = enabled; + } + + /* + * Get low-power-indicator preset to activate when low power is detected + */ + int8_t getLowPowerIndicatorPreset() + { + return lowPowerIndicatorPreset; + } + + /* + * Set low-power-indicator preset to activate when low power is detected + */ + void setLowPowerIndicatorPreset(int8_t presetId) + { + // String tmp = ""; For what ever reason this doesn't work :( + // lowPowerIndicatorPreset = getPresetName(presetId, tmp) ? presetId : lowPowerIndicatorPreset; + lowPowerIndicatorPreset = presetId; + } + + /* + * Get low-power-indicator threshold in percent (0-100) + */ + int8_t getLowPowerIndicatorThreshold() + { + return lowPowerIndicatorThreshold; + } + + /* + * Set low-power-indicator threshold in percent (0-100) + */ + void setLowPowerIndicatorThreshold(int8_t threshold) + { + lowPowerIndicatorThreshold = threshold; + // when auto-off is enabled the indicator threshold cannot be below auto-off threshold + lowPowerIndicatorThreshold = autoOffEnabled /*&& lowPowerIndicatorEnabled*/ ? max(autoOffThreshold+1, (int)lowPowerIndicatorThreshold) : max(5, (int)lowPowerIndicatorThreshold); + } + + /* + * Get low-power-indicator duration in seconds + */ + int8_t getLowPowerIndicatorDuration() + { + return lowPowerIndicatorDuration; + } + + /* + * Set low-power-indicator duration in seconds + */ + void setLowPowerIndicatorDuration(int8_t duration) + { + lowPowerIndicatorDuration = duration; + } + + + /* + * Get low-power-indicator status when the indication is done thsi returns true + */ + bool getLowPowerIndicatorDone() + { + return lowPowerIndicationDone; + } +}; + +// strings to reduce flash memory usage (used more than twice) +const char UsermodBattery::_name[] PROGMEM = "Battery"; +const char UsermodBattery::_readInterval[] PROGMEM = "interval"; +const char UsermodBattery::_enabled[] PROGMEM = "enabled"; +const char UsermodBattery::_threshold[] PROGMEM = "threshold"; +const char UsermodBattery::_preset[] PROGMEM = "preset"; +const char UsermodBattery::_duration[] PROGMEM = "duration"; +const char UsermodBattery::_init[] PROGMEM = "init"; diff --git a/usermods/Cronixie/usermod_cronixie.h b/usermods/Cronixie/usermod_cronixie.h index 5702d8fa..534fd3a7 100644 --- a/usermods/Cronixie/usermod_cronixie.h +++ b/usermods/Cronixie/usermod_cronixie.h @@ -271,6 +271,7 @@ class UsermodCronixie : public Usermod { { if (root["nx"].is()) { strncpy(cronixieDisplay, root["nx"], 6); + setCronixie(); } } diff --git a/usermods/DHT/readme.md b/usermods/DHT/readme.md index 55b1dd1c..6089ffbf 100644 --- a/usermods/DHT/readme.md +++ b/usermods/DHT/readme.md @@ -1,11 +1,11 @@ # DHT Temperature/Humidity sensor usermod This usermod will read from an attached DHT22 or DHT11 humidity and temperature sensor. -The sensor readings are displayed in the Info section of the web UI (and optionally send to a MQTT broker). +The sensor readings are displayed in the Info section of the web UI (and optionally sent to an MQTT broker). -If sensor is not detected after a while (10 update intervals), this usermod will be disabled. +If sensor is not detected after 10 update intervals, the usermod will be disabled. -If enabled measured temperature and humidity will be published to the following MQTT topics +If enabled, measured temperature and humidity will be published to the following MQTT topics * `{devceTopic}/dht/temperature` * `{devceTopic}/dht/humidity` @@ -15,13 +15,13 @@ Copy the example `platformio_override.ini` to the root directory. This file sho ### Define Your Options -* `USERMOD_DHT` - define this to have this user mod included wled00\usermods_list.cpp +* `USERMOD_DHT` - define this to include this user mod wled00\usermods_list.cpp * `USERMOD_DHT_DHTTYPE` - DHT model: 11, 21, 22 for DHT11, DHT21, or DHT22, defaults to 22/DHT22 * `USERMOD_DHT_PIN` - pin to which DTH is connected, defaults to Q2 pin on QuinLed Dig-Uno's board -* `USERMOD_DHT_CELSIUS` - define this to report temperatures in degrees celsious, otherwise fahrenheit will be reported -* `USERMOD_DHT_MEASUREMENT_INTERVAL` - the number of milliseconds between measurements, defaults to 60 seconds -* `USERMOD_DHT_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 90 seconds -* `USERMOD_DHT_MQTT` - publish measurements to the MQTT broker +* `USERMOD_DHT_CELSIUS` - define this to report temperatures in degrees Celsius, otherwise Fahrenheit will be reported +* `USERMOD_DHT_MEASUREMENT_INTERVAL` - the number of milliseconds between measurements, defaults to 60000 ms +* `USERMOD_DHT_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 90000 ms +* `USERMOD_DHT_MQTT` - publish measurements to an MQTT broker * `USERMOD_DHT_STATS` - For debug, report delay stats ## Project link @@ -35,11 +35,11 @@ If you are using `platformio_override.ini`, you should be able to refresh the ta ## Change Log 2022-10-15 -* Add possibility to publish sensor readings to an MQTT broker +* Add ability to publish sensor readings to an MQTT broker * fix compilation error for sample [env:d1_mini_usermod_dht_C] task 2020-02-04 * Change default QuinLed pin to Q2 -* Instead of trying to keep updates at constant cadence, space readings out by measurement interval; hope this helps to avoid occasional bursts of readings with errors +* Instead of trying to keep updates at constant cadence, space out readings by measurement interval. Hopefully, this helps eliminate occasional bursts of readings with errors * Add some more (optional) stats 2020-02-03 * Due to poor readouts on ESP32 with previous DHT library, rewrote to use https://github.com/alwynallan/DHT_nonblocking diff --git a/usermods/DHT/usermod_dht.h b/usermods/DHT/usermod_dht.h index 6253b85f..b6142f43 100644 --- a/usermods/DHT/usermod_dht.h +++ b/usermods/DHT/usermod_dht.h @@ -1,6 +1,10 @@ #pragma once #include "wled.h" +#ifndef WLED_ENABLE_MQTT +#error "This user mod requires MQTT to be enabled." +#endif + #include diff --git a/usermods/EXAMPLE_v2/usermod_v2_example.h b/usermods/EXAMPLE_v2/usermod_v2_example.h index a4fe9389..ba2ffc4e 100644 --- a/usermods/EXAMPLE_v2/usermod_v2_example.h +++ b/usermods/EXAMPLE_v2/usermod_v2_example.h @@ -20,11 +20,32 @@ * 2. Register the usermod by adding #include "usermod_filename.h" in the top and registerUsermod(new MyUsermodClass()) in the bottom of usermods_list.cpp */ +/* WLEDMM: move usermod variables to class. + +As of March 2023 this is work in progress, more variables will be moved in the future. +See Example v2, Temperature, MPU6050 and weather and fastled (rest to be done) as examples which has been converted using the steps below: + +Part 1 +- remove bool enabled = false/true (now default false) +- remove static const char _name[] and _enabled[] +- add constructor which calls superclass (temp?): XXXUsermod(const char *name, bool enabled):Usermod(name, enabled) {} +- replace _enabled with "enabled" +- remove const char PROGMEM init for _name[] and _enabled[] +Part 2 +- Remove bool initDone = false; +- addToConfig: replace createNestedObject with Usermod::addToConfig(root); JsonObject top = root[FPSTR(_name)]; +- readFromConfig: replace !top.isNull and enabled with bool configComplete = Usermod::readFromConfig(root);JsonObject top = root[FPSTR(_name)]; +Part 3 +- remove unsigned long lastTime = 0; //WLEDMM + +*/ + //class name. Use something descriptive and leave the ": public Usermod" part :) class MyExampleUsermod : public Usermod { + private: - //Private class members. You can declare variables and functions only accessible to your usermod here - unsigned long lastTime = 0; + + // Private class members. You can declare variables and functions only accessible to your usermod here // set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer) bool testBool = false; @@ -37,15 +58,53 @@ class MyExampleUsermod : public Usermod { long testLong; int8_t testPins[2]; + // any private methods should go here (non-inline methosd should be defined out of class) + void publishMqtt(const char* state, bool retain = false); // example for publishing MQTT message + + public: - //Functions called by WLED + + MyExampleUsermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM + + // non WLED related methods, may be used for data exchange between usermods (non-inline methods should be defined out of class) + + /** + * Enable/Disable the usermod + */ + // inline void enable(bool enable) { enabled = enable; } + + /** + * Get usermod enabled/disabled state + */ + // inline bool isEnabled() { return enabled; } + + // in such case add the following to another usermod: + // in private vars: + // #ifdef USERMOD_EXAMPLE + // MyExampleUsermod* UM; + // #endif + // in setup() + // #ifdef USERMOD_EXAMPLE + // UM = (MyExampleUsermod*) usermods.lookup(USERMOD_ID_EXAMPLE); + // #endif + // somewhere in loop() or other member method + // #ifdef USERMOD_EXAMPLE + // if (UM != nullptr) isExampleEnabled = UM->isEnabled(); + // if (!isExampleEnabled) UM->enable(true); + // #endif + + + // methods called by WLED (can be inlined as they are called only once but if you call them explicitly define them out of class) /* * setup() is called once at boot. WiFi is not yet connected at this point. + * readFromConfig() is called prior to setup() * You can use it to initialize variables, sensors or similar. */ void setup() { + // do your set-up here //Serial.println("Hello from my usermod!"); + initDone = true; } @@ -69,6 +128,11 @@ class MyExampleUsermod : public Usermod { * Instead, use a timer check as shown here. */ void loop() { + // if usermod is disabled or called during strip updating just exit + // NOTE: on very long strips strip.isUpdating() may always return true so update accordingly + if (!enabled || strip.isUpdating()) return; + + // do your magic here if (millis() - lastTime > 1000) { //Serial.println("I'm alive!"); lastTime = millis(); @@ -81,19 +145,25 @@ class MyExampleUsermod : public Usermod { * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. * Below it is shown how this could be used for e.g. a light sensor */ - /* void addToJsonInfo(JsonObject& root) { - int reading = 20; - //this code adds "u":{"Light":[20," lux"]} to the info object + // if "u" object does not exist yet wee need to create it JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); - JsonArray lightArr = user.createNestedArray("Light"); //name - lightArr.add(reading); //value - lightArr.add(" lux"); //unit + //this code adds "u":{"ExampleUsermod":[20," lux"]} to the info object + //int reading = 20; + //JsonArray lightArr = user.createNestedArray(FPSTR(_name))); //name + //lightArr.add(reading); //value + //lightArr.add(F(" lux")); //unit + + // if you are implementing a sensor usermod, you may publish sensor data + //JsonObject sensor = root[F("sensor")]; + //if (sensor.isNull()) sensor = root.createNestedObject(F("sensor")); + //temp = sensor.createNestedArray(F("light")); + //temp.add(reading); + //temp.add(F("lux")); } - */ /* @@ -102,7 +172,12 @@ class MyExampleUsermod : public Usermod { */ void addToJsonState(JsonObject& root) { - //root["user0"] = userVar0; + if (!initDone || !enabled) return; // prevent crash on boot applyPreset() + + JsonObject usermod = root[FPSTR(_name)]; + if (usermod.isNull()) usermod = root.createNestedObject(FPSTR(_name)); + + //usermod["user0"] = userVar0; } @@ -112,7 +187,14 @@ class MyExampleUsermod : public Usermod { */ void readFromJsonState(JsonObject& root) { - userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value + if (!initDone) return; // prevent crash on boot applyPreset() + + JsonObject usermod = root[FPSTR(_name)]; + if (!usermod.isNull()) { + // expect JSON usermod data in usermod name object: {"ExampleUsermod:{"user0":10}"} + userVar0 = usermod["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value + } + // you can as well check WLED state JSON keys //if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!")); } @@ -154,8 +236,10 @@ class MyExampleUsermod : public Usermod { */ void addToConfig(JsonObject& root) { - JsonObject top = root.createNestedObject("exampleUsermod"); - top["great"] = userVar0; //save these vars persistently whenever settings are saved + Usermod::addToConfig(root); JsonObject top = root[FPSTR(_name)]; //WLEDMM + + //save these vars persistently whenever settings are saved + top["great"] = userVar0; top["testBool"] = testBool; top["testInt"] = testInt; top["testLong"] = testLong; @@ -188,9 +272,7 @@ class MyExampleUsermod : public Usermod { // default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor // setting them inside readFromConfig() is slightly more robust, handling the rare but plausible use case of single value being missing after boot (e.g. if the cfg.json was manually edited and a value was removed) - JsonObject top = root["exampleUsermod"]; - - bool configComplete = !top.isNull(); + bool configComplete = Usermod::readFromConfig(root);JsonObject top = root[FPSTR(_name)]; //WLEDMM configComplete &= getJsonValue(top["great"], userVar0); configComplete &= getJsonValue(top["testBool"], testBool); @@ -201,6 +283,8 @@ class MyExampleUsermod : public Usermod { // A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing configComplete &= getJsonValue(top["testInt"], testInt, 42); configComplete &= getJsonValue(top["testLong"], testLong, -42424242); + + // "pin" fields have special handling in settings page (or some_pin as well) configComplete &= getJsonValue(top["pin"][0], testPins[0], -1); configComplete &= getJsonValue(top["pin"][1], testPins[1], -1); @@ -208,6 +292,21 @@ class MyExampleUsermod : public Usermod { } + /* + * appendConfigData() is called when user enters usermod settings page + * it may add additional metadata for certain entry fields (adding drop down is possible) + * be careful not to add too much as oappend() buffer is limited to 3k + */ + void appendConfigData() + { + oappend(SET_F("addInfo('")); oappend(String(FPSTR(_name)).c_str()); oappend(SET_F(":great")); oappend(SET_F("',1,'(this is a great config value)');")); + oappend(SET_F("addInfo('")); oappend(String(FPSTR(_name)).c_str()); oappend(SET_F(":testString")); oappend(SET_F("',1,'enter any string you want');")); + oappend(SET_F("dd=addDropdown('")); oappend(String(FPSTR(_name)).c_str()); oappend(SET_F("','testInt');")); + oappend(SET_F("addOption(dd,'Nothing',0);")); + oappend(SET_F("addOption(dd,'Everything',42);")); + } + + /* * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors. * Use this to blank out some LEDs or set them to a different color regardless of the set effect mode. @@ -218,7 +317,72 @@ class MyExampleUsermod : public Usermod { //strip.setPixelColor(0, RGBW32(0,0,0,0)) // set the first pixel to black } - + + /** + * handleButton() can be used to override default button behaviour. Returning true + * will prevent button working in a default way. + * Replicating button.cpp + */ + bool handleButton(uint8_t b) { + yield(); + // ignore certain button types as they may have other consequences + if (!enabled + || buttonType[b] == BTN_TYPE_NONE + || buttonType[b] == BTN_TYPE_RESERVED + || buttonType[b] == BTN_TYPE_PIR_SENSOR + || buttonType[b] == BTN_TYPE_ANALOG + || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) { + return false; + } + + bool handled = false; + // do your button handling here + return handled; + } + + +#ifndef WLED_DISABLE_MQTT + /** + * handling of MQTT message + * topic only contains stripped topic (part after /wled/MAC) + */ + bool onMqttMessage(char* topic, char* payload) { + // check if we received a command + //if (strlen(topic) == 8 && strncmp_P(topic, PSTR("/command"), 8) == 0) { + // String action = payload; + // if (action == "on") { + // enabled = true; + // return true; + // } else if (action == "off") { + // enabled = false; + // return true; + // } else if (action == "toggle") { + // enabled = !enabled; + // return true; + // } + //} + return false; + } + + /** + * onMqttConnect() is called when MQTT connection is established + */ + void onMqttConnect(bool sessionPresent) { + // do any MQTT related initialisation here + //publishMqtt("I am alive!"); + } +#endif + + + /** + * onStateChanged() is used to detect WLED state change + * @mode parameter is CALL_MODE_... parameter used for notifications + */ + void onStateChange(uint8_t mode) { + // do something if WLED state changed (color, brightness, effect, preset, etc) + } + + /* * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). * This could be used in the future for the system to determine whether your usermod is installed. @@ -230,4 +394,23 @@ class MyExampleUsermod : public Usermod { //More methods can be added in the future, this example will then be extended. //Your usermod will remain compatible as it does not need to implement all methods from the Usermod base class! -}; \ No newline at end of file +}; + + +// add more strings here to reduce flash memory usage + + +// implementation of non-inline member methods + +void MyExampleUsermod::publishMqtt(const char* state, bool retain) +{ +#ifndef WLED_DISABLE_MQTT + //Check if MQTT Connected, otherwise it will crash the 8266 + if (WLED_MQTT_CONNECTED) { + char subuf[64]; + strcpy(subuf, mqttDeviceTopic); + strcat_P(subuf, PSTR("/example")); + mqtt->publish(subuf, 0, retain, state); + } +#endif +} diff --git a/usermods/EleksTube_IPS/readme.md b/usermods/EleksTube_IPS/readme.md index 87827ac4..a05c9346 100644 --- a/usermods/EleksTube_IPS/readme.md +++ b/usermods/EleksTube_IPS/readme.md @@ -15,7 +15,7 @@ Not supported: - On-device setup with buttons (WiFi setup only) Your images must be 1-135 pixels wide and 1-240 pixels high. -For BMP, 1, 4, 8, and 24 bits per pixel formats are supported. +BMP 1, 4, 8, and 24 bits per pixel formats are supported. ## Installation @@ -26,11 +26,11 @@ Use LED pin 12, relay pin 27 and button pin 34. ## Use of RGB565 images -Binary 16-bit per pixel RGB565 format `.bin` and `.clk` images are now supported. This has the benefit of only using 2/3rds of the file size a 24 BPP `.bmp` has. -The drawback is that this format cannot be handled by common image programs and that an extra conversion step is needed. +Binary 16-bit per pixel RGB565 format `.bin` and `.clk` images are now supported. This has the benefit of using only 2/3rds of the file space a 24 BPP `.bmp` occupies. +The drawback is this format cannot be handled by common image programs and an extra conversion step is needed. You can use https://lvgl.io/tools/imageconverter to convert your .bmp to a .bin file (settings `True color` and `Binary RGB565`). Thank you to @RedNax67 for adding .bin and .clk support. -For most clockface designs, using 4 or 8 BPP BMP formats will save even more file size: +For most clockface designs, using 4 or 8 BPP BMP format will reduce file size even more: | Bits per pixel | File size in kB (for 135x240 img) | % of 24 BPP BMP | Max unique colors | --- | --- | --- | --- | @@ -42,4 +42,4 @@ For most clockface designs, using 4 or 8 BPP BMP formats will save even more fil Comparison 1 vs. 4 vs. 8 vs. 24 BPP. With this clockface on the actual clock, 4 bit looks good, and 8 bit is almost indistinguishable from 24 bit. -![comparison](https://user-images.githubusercontent.com/21045690/156899667-5b55ed9f-6e03-4066-b2aa-1260e9570369.png) \ No newline at end of file +![comparison](https://user-images.githubusercontent.com/21045690/156899667-5b55ed9f-6e03-4066-b2aa-1260e9570369.png) diff --git a/usermods/Enclosure_with_OLED_temp_ESP07/readme.md b/usermods/Enclosure_with_OLED_temp_ESP07/readme.md index 94d1c1f2..d612e06e 100644 --- a/usermods/Enclosure_with_OLED_temp_ESP07/readme.md +++ b/usermods/Enclosure_with_OLED_temp_ESP07/readme.md @@ -10,7 +10,7 @@ For BME280 sensor use usermod_bme280.cpp. Copy to wled00 and rename to usermod.c ## Features - SSD1306 128x32 and 128x64 I2C OLED display - On screen IP address, SSID and controller status (e.g. ON or OFF, recent effect) -- Auto display shutoff for saving display lifetime +- Auto display shutoff for extending display lifetime - Dallas temperature sensor - Reporting temperature to MQTT broker @@ -39,15 +39,15 @@ default_envs = esp07 ... lib_deps_external = ... - #For use SSD1306 OLED display uncomment following + #To use the SSD1306 OLED display, uncomment following U8g2@~2.27.3 - #For Dallas sensor uncomment following 2 lines + #For Dallas sensor, uncomment the following 2 lines DallasTemperature@~3.8.0 OneWire@~2.3.5 ... ``` -For BME280 sensor uncomment `U8g2@~2.27.3`,`BME280@~3.0.0 under` `[common]` section in `platformio.ini`: +For BME280 sensor, uncomment `U8g2@~2.27.3`,`BME280@~3.0.0 under` `[common]` section in `platformio.ini`: ```ini # platformio.ini ... @@ -60,7 +60,7 @@ default_envs = esp07 ... lib_deps_external = ... - #For use SSD1306 OLED display uncomment following + #To use the SSD1306 OLED display, uncomment following U8g2@~2.27.3 #For BME280 sensor uncomment following BME280@~3.0.0 diff --git a/usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp b/usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp index 0a2662aa..1ca16050 100644 --- a/usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp +++ b/usermods/Enclosure_with_OLED_temp_ESP07/usermod.cpp @@ -1,3 +1,7 @@ +#ifndef WLED_ENABLE_MQTT +#error "This user mod requires MQTT to be enabled." +#endif + #include "wled.h" #include #include // from https://github.com/olikraus/u8g2/ diff --git a/usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp b/usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp index 88d49790..d5fd4a0c 100644 --- a/usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp +++ b/usermods/Enclosure_with_OLED_temp_ESP07/usermod_bme280.cpp @@ -1,3 +1,7 @@ +#ifndef WLED_ENABLE_MQTT +#error "This user mod requires MQTT to be enabled." +#endif + #include "wled.h" #include #include // from https://github.com/olikraus/u8g2/ diff --git a/usermods/Fix_unreachable_netservices_v2/readme.md b/usermods/Fix_unreachable_netservices_v2/readme.md index f7b721dd..24d5ff5a 100644 --- a/usermods/Fix_unreachable_netservices_v2/readme.md +++ b/usermods/Fix_unreachable_netservices_v2/readme.md @@ -2,15 +2,16 @@ **Attention: This usermod compiles only for ESP8266** -This usermod-v2 modification performs a ping request to the local IP address every 60 seconds. By this procedure the net services of WLED remains accessible in some problematic WLAN environments. +This usermod-v2 modification performs a ping request to a local IP address every 60 seconds. This ensures WLED net services remain accessible in some problematic WLAN environments. The modification works with static or DHCP IP address configuration. _Story:_ -Unfortunately, with all ESP projects where a web server or other network services are running, I have the problem that after some time the web server is no longer accessible. Now I found out that the connection is at least reestablished when a ping request is executed by the device. +Unfortunately, with many ESP projects where a web server or other network services are running, after some time, the connecton to the web server is lost. +The connection can be reestablished with a ping request from the device. -With this modification, in the worst case, the network functions are not available for 60 seconds until the next ping request. +With this modification, in the worst case, the network functions are not available until the next ping request. (60 seconds) ## Webinterface diff --git a/usermods/JSON_IR_remote/readme.md b/usermods/JSON_IR_remote/readme.md index 2cba06ed..43532a6f 100644 --- a/usermods/JSON_IR_remote/readme.md +++ b/usermods/JSON_IR_remote/readme.md @@ -2,8 +2,8 @@ ## Purpose -The JSON IR remote allows users to customize IR remote behavior without writing custom code and compiling. -It also enables using any remote that is compatible with your IR receiver. Using the JSON IR remote, you can +The JSON IR remote enables users to customize IR remote behavior without writing custom code and compiling. +It also allows using any remote compatible with your IR receiver. Using the JSON IR remote, you can map buttons from any remote to any HTTP request API or JSON API command. ## Usage diff --git a/usermods/PIR_sensor_switch/readme.md b/usermods/PIR_sensor_switch/readme.md index b023cea5..574bd06d 100644 --- a/usermods/PIR_sensor_switch/readme.md +++ b/usermods/PIR_sensor_switch/readme.md @@ -7,34 +7,35 @@ _Story:_ I use the PIR Sensor to automatically turn on the WLED analog clock in my home office room when I am there. The LED strip is switched [using a relay](https://github.com/Aircoookie/WLED/wiki/Control-a-relay-with-WLED) to keep the power consumption low when it is switched off. -## Webinterface +## Web interface The info page in the web interface shows the remaining time of the off timer. Usermod can also be temporarily disbled/enabled from the info page by clicking PIR button. ## Sensor connection -My setup uses an HC-SR501 or HC-SR602 sensor, a HC-SR505 should also work. +My setup uses an HC-SR501 or HC-SR602 sensor, an HC-SR505 should also work. -The usermod uses GPIO13 (D1 mini pin D7) by default for the sensor signal but can be changed in the Usermod settings page. +The usermod uses GPIO13 (D1 mini pin D7) by default for the sensor signal, but can be changed in the Usermod settings page. [This example page](http://www.esp8266learning.com/wemos-mini-pir-sensor-example.php) describes how to connect the sensor. -Use the potentiometers on the sensor to set the time-delay to the minimum and the sensitivity to about half, or slightly above. +Use the potentiometers on the sensor to set the time delay to the minimum and the sensitivity to about half, or slightly above. You can also use usermod's off timer instead of sensor's. In such case rotate the potentiometer to its shortest time possible (or use SR602 which lacks such potentiometer). ## Usermod installation -**NOTE:** Usermod has been included in master branch of WLED so it can be compiled in directly just by defining `-D USERMOD_PIRSWITCH` and optionaly `-D PIR_SENSOR_PIN=16` to override default pin. You can also change the default off tim by adding `-D PIR_SENSOR_OFF_SEC=30`. +**NOTE:** Usermod has been included in master branch of WLED so it can be compiled in directly just by defining `-D USERMOD_PIRSWITCH` and optionaly `-D PIR_SENSOR_PIN=16` to override default pin. You can also change the default off time by adding `-D PIR_SENSOR_OFF_SEC=30`. -## API to enable/disable the PIR sensor from outside. For example from another usermod. +## API to enable/disable the PIR sensor from outside. For example from another usermod: To query or change the PIR sensor state the methods `bool PIRsensorEnabled()` and `void EnablePIRsensor(bool enable)` are available. When the PIR sensor state changes an MQTT message is broadcasted with topic `wled/deviceMAC/motion` and message `on` or `off`. -Usermod can also be configured to just send MQTT message and not change WLED state using settings page as well as responding to motion only during nighttime (assuming NTP and lattitude/longitude are set to determine sunrise/sunset times). +Usermod can also be configured to send just the MQTT message but not change WLED state using settings page as well as responding to motion only at night +(assuming NTP and lattitude/longitude are set to determine sunrise/sunset times). ### There are two options to get access to the usermod instance: -1. Include `usermod_PIR_sensor_switch.h` **before** you include the other usermod in `usermods_list.cpp' +1. Include `usermod_PIR_sensor_switch.h` **before** you include other usermods in `usermods_list.cpp' or @@ -63,7 +64,7 @@ class MyUsermod : public Usermod { ### Configuration options -Usermod can be configured in Usermods settings page. +Usermod can be configured via the Usermods settings page. * `PIRenabled` - enable/disable usermod * `pin` - dynamically change GPIO pin where PIR sensor is attached to ESP @@ -71,8 +72,8 @@ Usermod can be configured in Usermods settings page. * `on-preset` - preset triggered when PIR activates (if this is 0 it will just turn WLED on) * `off-preset` - preset triggered when PIR deactivates (if this is 0 it will just turn WLED off) * `nighttime-only` - enable triggering only between sunset and sunrise (you will need to set up _NTP_, _Lat_ & _Lon_ in Time & Macro settings) -* `mqtt-only` - only send MQTT messages, do not interact with WLED -* `off-only` - only trigger presets or turn WLED on/off in WLED is not already on (displaying effect) +* `mqtt-only` - send only MQTT messages, do not interact with WLED +* `off-only` - only trigger presets or turn WLED on/off if WLED is not already on (displaying effect) * `notifications` - enable or disable sending notifications to other WLED instances using Sync button @@ -89,4 +90,4 @@ Have fun - @gegu & @blazoncek 2022-11 * Added compile time option for off timer. * Added Home Assistant autodiscovery MQTT broadcast. -* Updated info on compiling. \ No newline at end of file +* Updated info on compiling. diff --git a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h index b03a36ce..288edb32 100644 --- a/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h +++ b/usermods/PIR_sensor_switch/usermod_PIR_sensor_switch.h @@ -4,11 +4,7 @@ #ifndef PIR_SENSOR_PIN // compatible with QuinLED-Dig-Uno - #ifdef ARDUINO_ARCH_ESP32 - #define PIR_SENSOR_PIN 23 // Q4 - #else //ESP8266 boards - #define PIR_SENSOR_PIN 13 // Q4 (D7 on D1 mini) - #endif + #define PIR_SENSOR_PIN -1 //WLEDMM not default 23 // Q4 for esp32 or otherwise 13 // Q4 (D7 on D1 mini) #endif #ifndef PIR_SENSOR_OFF_SEC @@ -114,6 +110,7 @@ private: if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; //if lights on and off only, do nothing if (PIRtriggered && switchOn) return; //if already on and triggered before, do nothing PIRtriggered = switchOn; + DEBUG_PRINT(F("PIR: strip=")); DEBUG_PRINTLN(switchOn?"on":"off"); if (switchOn) { if (m_onPreset) { if (currentPlaylist>0 && !offMode) { @@ -136,7 +133,7 @@ private: } } else { if (m_offPreset) { - if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(m_offPreset, NotifyUpdateMode); + applyPreset(m_offPreset, NotifyUpdateMode); return; } else if (prevPlaylist) { if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(prevPlaylist, NotifyUpdateMode); @@ -159,6 +156,7 @@ private: void publishMqtt(const char* state) { + #ifndef WLED_DISABLE_MQTT //Check if MQTT Connected, otherwise it will crash the 8266 if (WLED_MQTT_CONNECTED) { char subuf[64]; @@ -166,11 +164,13 @@ private: strcat_P(subuf, PSTR("/motion")); mqtt->publish(subuf, 0, false, state); } + #endif } // Create an MQTT Binary Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop. void publishHomeAssistantAutodiscovery() { + #ifndef WLED_DISABLE_MQTT if (WLED_MQTT_CONNECTED) { StaticJsonDocument<600> doc; char uid[24], json_str[1024], buf[128]; @@ -200,6 +200,7 @@ private: mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain? } + #endif } /** @@ -235,7 +236,7 @@ private: if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) { offTimerStart = 0; if (enabled == true) { - if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(false); + if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()) || PIRtriggered)) switchStrip(false); else if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND); publishMqtt("off"); } @@ -366,6 +367,20 @@ public: sensor[F("motion")] = sensorPinState || offTimerStart>0 ? true : false; } + /** + * onStateChanged() is used to detect WLED state change + */ + void onStateChange(uint8_t mode) { + if (!initDone) return; + DEBUG_PRINT(F("PIR: offTimerStart=")); DEBUG_PRINTLN(offTimerStart); + if (PIRtriggered && offTimerStart) { + // checking PIRtriggered and offTimerStart will prevent cancellation upon On trigger + DEBUG_PRINTLN(F("PIR: Canceled.")); + offTimerStart = 0; + PIRtriggered = false; + } + } + /** * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). * Values in the state object may be modified by connected clients @@ -414,6 +429,8 @@ public: void appendConfigData() { + oappend(SET_F("addHB('PIRsensorSwitch');")); + oappend(SET_F("addInfo('PIRsensorSwitch:HA-discovery',1,'HA=Home Assistant');")); // 0 is field type, 1 is actual field oappend(SET_F("addInfo('PIRsensorSwitch:notifications',1,'Periodic WS updates');")); // 0 is field type, 1 is actual field } diff --git a/usermods/PWM_fan/readme.md b/usermods/PWM_fan/readme.md index 8cd04a91..1fbfe0e6 100644 --- a/usermods/PWM_fan/readme.md +++ b/usermods/PWM_fan/readme.md @@ -2,12 +2,12 @@ v2 Usermod to to control PWM fan with RPM feedback and temperature control -This usermod requires Dallas Temperature usermod to obtain temperature information. If this is not available the fan will always run at 100% speed. -If the fan does not have _tacho_ (RPM) output you can set the _tacho-pin_ to -1 to not use that feature. +This usermod requires the Dallas Temperature usermod to obtain temperature information. If it's not available, the fan will run at 100% speed. +If the fan does not have _tachometer_ (RPM) output you can set the _tachometer-pin_ to -1 to disable that feature. -You can also set the thershold temperature at which fan runs at lowest speed. If the actual temperature measured will be 3°C greater than threshold temperature the fan will run at 100%. +You can also set the thershold temperature at which fan runs at lowest speed. If the measured temperature is 3°C greater than the threshold temperature, the fan will run at 100%. -If the _tacho_ is supported the current speed (in RPM) will be repored in WLED Info page. +If the _tachometer_ is supported, the current speed (in RPM) will be displayed on the WLED Info page. ## Installation @@ -20,7 +20,7 @@ All of the parameters are configured during run-time using Usermods settings pag This includes: * PWM output pin (can be configured at compile time `-D PWM_PIN=xx`) -* tacho input pin (can be configured at compile time `-D TACHO_PIN=xx`) +* tachometer input pin (can be configured at compile time `-D TACHO_PIN=xx`) * sampling frequency in seconds * threshold temperature in degees C @@ -32,14 +32,14 @@ No special requirements. ## Control PWM fan speed using JSON API -You can use e.g. `{"PWM-fan":{"speed":30,"lock":true}}` to set fan speed to 30 percent of maximum speed (replace 30 with arbitrary value between 0 and 100) and lock the speed. -If you include `speed` property you can set fan speed in percent (%) of maximum speed. -If you include `lock` property you can lock (_true_) or unlock (_false_) fan speed. -If the fan speed is unlocked it will revert to temperature controlled speed on next update cycle. Once fan speed is locked it will remain so until it is unlocked by next API call. +e.g. you can use `{"PWM-fan":{"speed":30,"lock":true}}` to lock fan speed to 30 percent of maximum. (replace 30 with an arbitrary value between 0 and 100) +If you include `speed` property you can set fan speed as a percentage (%) of maximum speed. +If you include `lock` property you can lock (_true_) or unlock (_false_) the fan speed. +If the fan speed is unlocked, it will revert to temperature controlled speed on the next update cycle. Once fan speed is locked it will remain so until it is unlocked by the next API call. ## Change Log 2021-10 * First public release 2022-05 -* Added JSON API call to allow changing of speed \ No newline at end of file +* Added JSON API call to allow changing of speed diff --git a/usermods/PWM_fan/usermod_PWM_fan.h b/usermods/PWM_fan/usermod_PWM_fan.h index 153a5f63..d8aa7a1a 100644 --- a/usermods/PWM_fan/usermod_PWM_fan.h +++ b/usermods/PWM_fan/usermod_PWM_fan.h @@ -1,7 +1,7 @@ #pragma once -#ifndef USERMOD_DALLASTEMPERATURE -#error The "PWM fan" usermod requires "Dallas Temeprature" usermod to function properly. +#if !defined(USERMOD_DALLASTEMPERATURE) && !defined(USERMOD_SHT) +#error The "PWM fan" usermod requires "Dallas Temeprature" or "SHT" usermod to function properly. #endif #include "wled.h" @@ -42,6 +42,8 @@ class PWMFanUsermod : public Usermod { #ifdef USERMOD_DALLASTEMPERATURE UsermodTemperature* tempUM; + #elif defined(USERMOD_SHT) + ShtUsermod* tempUM; #endif // configurable parameters @@ -145,7 +147,7 @@ class PWMFanUsermod : public Usermod { } float getActualTemperature(void) { - #ifdef USERMOD_DALLASTEMPERATURE + #if defined(USERMOD_DALLASTEMPERATURE) || defined(USERMOD_SHT) if (tempUM != nullptr) return tempUM->getTemperatureC(); #endif @@ -189,6 +191,8 @@ class PWMFanUsermod : public Usermod { #ifdef USERMOD_DALLASTEMPERATURE // This Usermod requires Temperature usermod tempUM = (UsermodTemperature*) usermods.lookup(USERMOD_ID_TEMPERATURE); + #elif defined(USERMOD_SHT) + tempUM = (ShtUsermod*) usermods.lookup(USERMOD_ID_SHT); #endif initTacho(); initPWMfan(); @@ -286,6 +290,10 @@ class PWMFanUsermod : public Usermod { } } + void appendConfigData() { + oappend(SET_F("addHB('PWM-fan');")); + } + /* * 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/RTC/readme.md b/usermods/RTC/readme.md index 3aaa6091..0add4efc 100644 --- a/usermods/RTC/readme.md +++ b/usermods/RTC/readme.md @@ -1,6 +1,6 @@ # DS1307/DS3231 Real time clock -Gets the time from I2C RTC module on boot. This allows clocks to operate e.g. if temporarily no WiFi is available. +Gets the time from I2C RTC module on boot. This allows clock operation if WiFi is not available. The stored time is updated each time NTP is synced. ## Installation diff --git a/usermods/RTC/usermod_rtc.h b/usermods/RTC/usermod_rtc.h index fd9a4054..08b92ef1 100644 --- a/usermods/RTC/usermod_rtc.h +++ b/usermods/RTC/usermod_rtc.h @@ -1,8 +1,13 @@ #pragma once +#include // WLEDMM: make sure that I2C drivers have the "right" Wire Object +#include + #include "src/dependencies/time/DS1307RTC.h" #include "wled.h" +#define RTC_DELTA 2 // only modify RTC time if delta exceeds this number of seconds + //Connect DS1307 to standard I2C pins (ESP32: GPIO 21 (SDA)/GPIO 22 (SCL)) class RTCUsermod : public Usermod { @@ -13,12 +18,27 @@ class RTCUsermod : public Usermod { void setup() { PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } }; - if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; } + if (pins[1].pin < 0 || pins[0].pin < 0) { disabled=true; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough + + // WLEDMM join hardware I2C + if (!pinManager.joinWire()) { // WLEDMM - this allocates global I2C pins, then starts Wire - if not started previously + disabled = true; + return; + } + + //if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; } +#if defined(ARDUINO_ARCH_ESP32) + //Wire.begin(pins[1].pin, pins[0].pin); // WLEDMM this might silently fail, which is OK as it just means that I2C bus is already running. +#else + //Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed. +#endif + RTC.begin(); time_t rtcTime = RTC.get(); if (rtcTime) { toki.setTime(rtcTime,TOKI_NO_MS_ACCURACY,TOKI_TS_RTC); updateLocalTime(); + USER_PRINTLN(F("Localtime updated from RTC.")); } else { if (!RTC.chipPresent()) disabled = true; //don't waste time if H/W error } @@ -28,7 +48,24 @@ class RTCUsermod : public Usermod { if (strip.isUpdating()) return; if (!disabled && toki.isTick()) { time_t t = toki.second(); - if (t != RTC.get()) RTC.set(t); //set RTC to NTP/UI-provided value + + if (abs(t - RTC.get())> RTC_DELTA) { // WLEDMM only consider time diffs > 2 seconds + if ( (toki.getTimeSource() == TOKI_TS_NTP) + ||( (toki.getTimeSource() != TOKI_TS_NONE) && (toki.getTimeSource() != TOKI_TS_RTC) + && (toki.getTimeSource() != TOKI_TS_BAD) && (toki.getTimeSource() != TOKI_TS_UDP_SEC) && (toki.getTimeSource() != TOKI_TS_UDP))) + { // WLEMM update RTC if we have a reliable time source + RTC.set(t); //set RTC to NTP/UI-provided value - WLEDMM allow up to 3 sec deviation + USER_PRINTLN(F("RTC updated using localtime.")); + } else { + // WLEDMM if no reliable time -> update from RTC + time_t rtcTime = RTC.get(); + if (rtcTime) { + toki.setTime(rtcTime,TOKI_NO_MS_ACCURACY,TOKI_TS_RTC); + updateLocalTime(); + USER_PRINTLN(F("Localtime updated from RTC.")); + } + } + } } } diff --git a/usermods/RelayBlinds/readme.md b/usermods/RelayBlinds/readme.md index 0c3d2a0b..8c533dd4 100644 --- a/usermods/RelayBlinds/readme.md +++ b/usermods/RelayBlinds/readme.md @@ -1,8 +1,8 @@ # RelayBlinds usermod -This simple usermod toggles two relay pins momentarily (default for 500ms) when `userVar0` is set. -This can be used to e.g. "push" the buttons of a window blinds motor controller. +This simple usermod toggles two relay pins momentarily (defaults to 500ms) when `userVar0` is set. +e.g. can be used to "push" the buttons of a window blinds motor controller. v1 usermod. Please replace usermod.cpp in the `wled00` directory with the one in this file. You may upload `index.htm` to `[WLED-IP]/edit` to replace the default lighting UI with a simple Up/Down button one. -Also, a simple `presets.json` file is available, this makes the relay actions controllable via two presets to facilitate control e.g. via the default UI or Alexa. \ No newline at end of file +A simple `presets.json` file is available. This makes the relay actions controllable via two presets to facilitate control e.g. the default UI or Alexa. diff --git a/usermods/SN_Photoresistor/readme.md b/usermods/SN_Photoresistor/readme.md index 4f3a36fb..feacf41a 100644 --- a/usermods/SN_Photoresistor/readme.md +++ b/usermods/SN_Photoresistor/readme.md @@ -1,7 +1,7 @@ # SN_Photoresistor usermod -This usermod will read from an attached photoresistor sensor like the KY-018 sensor. -The luminance is displayed both in the Info section of the web UI as well as published to the `/luminance` MQTT topic if enabled. +This usermod will read from an attached photoresistor sensor like the KY-018. +The luminance is displayed in both the Info section of the web UI as well as published to the `/luminance` MQTT topic, if enabled. ## Installation @@ -9,15 +9,15 @@ Copy the example `platformio_override.ini` to the root directory. This file sho ### Define Your Options -* `USERMOD_SN_PHOTORESISTOR` - define this to have this user mod included wled00\usermods_list.cpp -* `USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL` - the number of milliseconds between measurements, defaults to 60 seconds -* `USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 20 seconds -* `USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE` - the voltage supplied to the sensor, defaults to 5v -* `USERMOD_SN_PHOTORESISTOR_ADC_PRECISION` - the ADC precision is the number of distinguishable ADC inputs, defaults to 1024.0 (10 bits) -* `USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE` - the resistor size, defaults to 10000.0 (10K hms) -* `USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE` - the offset value to report on, defaults to 25 +* `USERMOD_SN_PHOTORESISTOR` - Enables this user mod. wled00\usermods_list.cpp +* `USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL` - Number of milliseconds between measurements. Defaults to 60000 ms +* `USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT` - Number of milliseconds after boot to take first measurement. Defaults to 20000 ms +* `USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE` - Voltage supplied to the sensor. Defaults to 5v +* `USERMOD_SN_PHOTORESISTOR_ADC_PRECISION` - ADC precision. Defaults to 10 bits +* `USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE` - Resistor size, defaults to 10000.0 (10K Ohms) +* `USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE` - Offset value to report on. Defaults to 25 -All parameters can be configured at runtime using Usermods settings page. +All parameters can be configured at runtime via the Usermods settings page. ## Project link diff --git a/usermods/SN_Photoresistor/usermod_sn_photoresistor.h b/usermods/SN_Photoresistor/usermod_sn_photoresistor.h index 9c3be7cc..60861e4c 100644 --- a/usermods/SN_Photoresistor/usermod_sn_photoresistor.h +++ b/usermods/SN_Photoresistor/usermod_sn_photoresistor.h @@ -109,6 +109,7 @@ public: { lastLDRValue = currentLDRValue; +#ifndef WLED_DISABLE_MQTT if (WLED_MQTT_CONNECTED) { char subuf[45]; @@ -121,6 +122,7 @@ public: DEBUG_PRINTLN("Missing MQTT connection. Not publishing data"); } } +#endif } uint16_t getLastLDRValue() diff --git a/usermods/ST7789_display/README.md b/usermods/ST7789_display/README.md index 93092186..ebaae492 100644 --- a/usermods/ST7789_display/README.md +++ b/usermods/ST7789_display/README.md @@ -1,15 +1,15 @@ -# ST7789 TFT IPS Color display 240x240pxwith ESP32 boards +# Using the ST7789 TFT IPS 240x240 pixel color display with ESP32 boards -This usermod allow to use 240x240 display to display following: +This usermod enables display of the following: -* current date and time; +* Current date and time; * Network SSID; * IP address; * WiFi signal strength; * Brightness; -* Chosen effect; -* Chosen palette; -* effect speed and intensity; +* Selected effect; +* Selected palette; +* Effect speed and intensity; * Estimated current in mA; ## Hardware @@ -41,9 +41,9 @@ lib_deps = ... ``` -Also, while in the `platformio.ini` file, you must change the environment setup to build for just the esp32dev platform as follows: +In the `platformio.ini` file, you must change the environment setup to build for just the esp32dev platform as follows: -Add lines to section: +Add the following lines to section: ```ini default_envs = esp32dev @@ -64,14 +64,14 @@ build_flags = ${common.build_flags_esp32} ;-DCONFIG_SPIRAM_SUPPORT=1 ``` -Save the `platformio.ini` file. Once this is saved, the required library files should be automatically downloaded for modifications in a later step. +Save the `platformio.ini` file. Once saved, the required library files should be automatically downloaded for modifications in a later step. ### TFT_eSPI Library Adjustments -If you are not using PlatformIO you need to modify a file in the `TFT_eSPI` library. If you followed the directions to modify and save the `platformio.ini` file above, the `Setup24_ST7789.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI/User_Setups/` folder. +If you are not using PlatformIO, you need to modify a file in the `TFT_eSPI` library. If you followed the directions to modify and save the `platformio.ini` file above, the `Setup24_ST7789.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI/User_Setups/` folder. -Edit `Setup_ST7789.h` file and uncomment nad changep GPIO pin numbers in lines containing `TFT_MOSI`, `TFT_SCLK`, `TFT_RST`, `TFT_DC`. +Edit `Setup_ST7789.h` file and uncomment and change GPIO pin numbers in lines containing `TFT_MOSI`, `TFT_SCLK`, `TFT_RST`, `TFT_DC`. -Modify the `User_Setup_Select.h` by uncommentig the line containing `#include ` and commenting out line containing `#include `. +Modify the `User_Setup_Select.h` by uncommenting the line containing `#include ` and commenting out the line containing `#include `. -If your display includes backlight enable pin, #define TFT_BL with backlight enable GPIO number. \ No newline at end of file +If your display uses the backlight enable pin, add this definition: #define TFT_BL with backlight enable GPIO number. diff --git a/usermods/Si7021_MQTT_HA/readme.md b/usermods/Si7021_MQTT_HA/readme.md index d9a96f7a..99a240f7 100644 --- a/usermods/Si7021_MQTT_HA/readme.md +++ b/usermods/Si7021_MQTT_HA/readme.md @@ -2,14 +2,14 @@ This usermod implements support for [Si7021 I²C temperature and humidity sensors](https://www.silabs.com/documents/public/data-sheets/Si7021-A20.pdf). -The sensor data will *not* be shown on the WLED UI (so far) but published via MQTT to WLED's "build in" MQTT device topic. +As of this writing, the sensor data will *not* be shown on the WLED UI, but it _is_ published via MQTT to WLED's "built-in" MQTT device topic. ``` temperature: $mqttDeviceTopic/si7021_temperature humidity: $mqttDeviceTopic/si7021_humidity ``` -Additionally the following sensors can be published: +The following sensors can also be published: ``` heat_index: $mqttDeviceTopic/si7021_heat_index @@ -17,7 +17,7 @@ dew_point: $mqttDeviceTopic/si7021_dew_point absolute_humidity: $mqttDeviceTopic/si7021_absolute_humidity ``` -Sensor data will be updated/send every 60 seconds. +Sensor data will be updated/sent every 60 seconds. This usermod also supports Home Assistant Auto Discovery. @@ -66,4 +66,4 @@ Add to `lib_deps` in platformio.ini: - Aircoookie for making WLED - Other usermod creators for example code (`sensors_to_mqtt` and `multi_relay` especially) -- You, for reading this \ No newline at end of file +- You, for reading this diff --git a/usermods/Si7021_MQTT_HA/usermod_si7021_mqtt_ha.h b/usermods/Si7021_MQTT_HA/usermod_si7021_mqtt_ha.h index 71c22da1..4a42a7d5 100644 --- a/usermods/Si7021_MQTT_HA/usermod_si7021_mqtt_ha.h +++ b/usermods/Si7021_MQTT_HA/usermod_si7021_mqtt_ha.h @@ -1,3 +1,7 @@ +#ifndef WLED_ENABLE_MQTT +#error "This user mod requires MQTT to be enabled." +#endif + #pragma once // this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod) diff --git a/usermods/TTGO-T-Display/README.md b/usermods/TTGO-T-Display/README.md index 872beeb8..439f9832 100644 --- a/usermods/TTGO-T-Display/README.md +++ b/usermods/TTGO-T-Display/README.md @@ -1,19 +1,19 @@ # TTGO T-Display ESP32 with 240x135 TFT via SPI with TFT_eSPI -This usermod allows use of the TTGO T-Display ESP32 module with integrated 240x135 display +This usermod enables use of the TTGO 240x135 T-Display ESP32 module for controlling WLED and showing the following information: * Current SSID -* IP address if obtained - * If connected to a network, current brightness % is shown - * in AP mode AP IP and password are shown +* IP address, if obtained + * If connected to a network, current brightness percentage is shown + * In AP mode, AP, IP and password are shown * Current effect * Current palette -* Estimated current in mA is shown (NOTE: for this to be a reasonable value, the correct LED type must be specified in the LED Prefs section) +* Estimated current in mA (NOTE: for this to be a reasonable value, the correct LED type must be specified in the LED Prefs section) -Button pin is mapped to the onboard button next to the side actuated reset button of the TTGO T-Display board. +Button pin is mapped to the onboard button adjacent to the reset button of the TTGO T-Display board. -I have designed a 3D printed case around this board and an ["ElectroCookie"](https://amzn.to/2WCNeeA) project board, a [level shifter](https://amzn.to/3hbKu18), a [buck regulator](https://amzn.to/3mLMy0W), and a DC [power jack](https://amzn.to/3phj9NZ). I use 12V WS2815 LED strips for my projects, and power them with 12V power supplies, so the regulator drops the voltage to the 5V level I need to power the ESP module and the level shifter. If there is any interest in this case, which elevates the board and display on some custom extended headers to make place the screen at the top of the enclosure (with accessible buttons), let me know, and I could post the STL files. It is a bit tricky to get the height correct, so I also designed a one-time use 3D printed solder fixture to set the board in the right location and at the correct height for the housing. (It is one-time use because it has to be cut off after soldering to be able to remove it). I didn't think the effort to make it in multiple pieces was worthwhile. +I have designed a 3D printed case around this board and an ["ElectroCookie"](https://amzn.to/2WCNeeA) project board, a [level shifter](https://amzn.to/3hbKu18), a [buck regulator](https://amzn.to/3mLMy0W), and a DC [power jack](https://amzn.to/3phj9NZ). I use 12V WS2815 LED strips for my projects, and power them with 12V power supplies. The regulator supplies 5V for the ESP module and the level shifter. If there is any interest in this case which elevates the board and display on custom extended standoffs to place the screen at the top of the enclosure (with accessible buttons), let me know, and I will post the STL files. It is a bit tricky to get the height correct, so I also designed a one-time use 3D printed solder fixture to set the board in the right location and at the correct height for the housing. (It is one-time use because it has to be cut off after soldering to be able to remove it). I didn't think the effort to make it in multiple pieces was worthwhile. -Usermod based on a rework of the ssd1306_i2c_oled_u8g2 usermod from the WLED repo. +Based on a rework of the ssd1306_i2c_oled_u8g2 usermod from the WLED repo. ## Hardware ![Hardware](assets/ttgo_hardware1.png) @@ -30,8 +30,8 @@ Usermod based on a rework of the ssd1306_i2c_oled_u8g2 usermod from the WLED rep Functionality checked with: * TTGO T-Display * PlatformIO -* Group of 4 individual Neopixels from Adafruit, and a several full strings of 12v WS2815 LEDs. -* The hardware design shown above should be limited to shorter strings. For larger strings, I use a different setup with a dedicated 12v power supply and power them directly off the supply (in addition to dropping the 12v supply down to 5v with a buck regulator for the ESP module and level shifter). +* Group of 4 individual Neopixels from Adafruit and several full strings of 12v WS2815 LEDs. +* The hardware design shown above should be limited to shorter strings. For larger strings, I use a different setup with a dedicated 12v power supply and power them directly from said supply (in addition to dropping the 12v to 5v with a buck regulator for the ESP module and level shifter). ## Setup Needed: * As with all usermods, copy the usermod.cpp file from the TTGO-T-Display usermod folder to the wled00 folder (replacing the default usermod.cpp file). @@ -51,24 +51,24 @@ lib_deps = ... ``` -Also, while in the `platformio.ini` file, you must change the environment setup to build for just the esp32dev platform as follows: +In the `platformio.ini` file, you must change the environment setup to build for just the esp32dev platform as follows: Comment out the line described below: ```ini -# Travis CI binaries (comment this out when building for single board) -; default_envs = travis_esp8266, esp01, esp01_1m_ota, travis_esp32 +# Release binaries +; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3 ``` -and UNCOMMENT the following line in the 'Single binaries' section: +and uncomment the following line in the 'Single binaries' section: ```ini default_envs = esp32dev ``` -Save the `platformio.ini` file. Once this is saved, the required library files should be automatically downloaded for modifications in a later step. +Save the `platformio.ini` file. Once saved, the required library files should be automatically downloaded for modifications in a later step. ### Platformio_overrides.ini (added) Copy the `platformio_overrides.ini` file which is contained in the `usermods/TTGO-T-Display/` folder into the root of your project folder. This file contains an override that remaps the button pin of WLED to use the on-board button to the right of the USB-C connector (when viewed with the port oriented downward - see hardware photo). ### TFT_eSPI Library Adjustments (board selection) -We need to modify a file in the `TFT_eSPI` library to select the correct board. If you followed the directions to modify and save the `platformio.ini` file above, the `User_Setup_Select.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI_ID1559` folder. +You need to modify a file in the `TFT_eSPI` library to select the correct board. If you followed the directions to modify and save the `platformio.ini` file above, the `User_Setup_Select.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI_ID1559` folder. Modify the `User_Setup_Select.h` file as follows: * Comment out the following line (which is the 'default' setup file): @@ -80,12 +80,12 @@ Modify the `User_Setup_Select.h` file as follows: #include // Setup file for ESP32 and TTGO T-Display ST7789V SPI bus TFT ``` -Run the build and it should complete correctly. If you see a failure like this: +Build the file. If you see a failure like this: ```ini xtensa-esp32-elf-g++: error: wled00\wled00.ino.cpp: No such file or directory xtensa-esp32-elf-g++: fatal error: no input files ``` -Just try building again - I find that sometimes this happens on the first build attempt and subsequent attempts will build correctly. +try building again. Sometimes this happens on the first build attempt and subsequent attempts build correctly. ## Arduino IDE -- UNTESTED \ No newline at end of file +- UNTESTED diff --git a/usermods/Temperature/readme.md b/usermods/Temperature/readme.md index ac2823c3..c917461a 100644 --- a/usermods/Temperature/readme.md +++ b/usermods/Temperature/readme.md @@ -1,9 +1,9 @@ # Temperature usermod -Based on the excellent `QuinLED_Dig_Uno_Temp_MQTT` by srg74 and 400killer! -This usermod will read from an attached DS18B20 temperature sensor (as available on the QuinLED Dig-Uno) -The temperature is displayed both in the Info section of the web UI as well as published to the `/temperature` MQTT topic if enabled. -This usermod may be expanded with support for different sensor types in the future. +Based on the excellent `QuinLED_Dig_Uno_Temp_MQTT` usermod by srg74 and 400killer! +Reads an attached DS18B20 temperature sensor (as available on the QuinLED Dig-Uno) +Temperature is displayed in both the Info section of the web UI as well as published to the `/temperature` MQTT topic, if enabled. +May be expanded with support for different sensor types in the future. If temperature sensor is not detected during boot, this usermod will be disabled. @@ -13,10 +13,10 @@ Copy the example `platformio_override.ini` to the root directory. This file sho ### Define Your Options -* `USERMOD_DALLASTEMPERATURE` - define this to have this user mod included wled00\usermods_list.cpp -* `USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT` - the number of milliseconds after boot to take first measurement, defaults to 20 seconds +* `USERMOD_DALLASTEMPERATURE` - enables this user mod wled00/usermods_list.cpp +* `USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT` - number of milliseconds after boot to take first measurement, defaults to 20000 ms -All parameters can be configured at runtime using Usermods settings page, including pin, selection to display temerature in degrees Celsius or Farenheit mand measurement interval. +All parameters can be configured at runtime via the Usermods settings page, including pin, temperature in degrees Celsius or Farenheit and measurement interval. ## Project link @@ -50,9 +50,9 @@ lib_deps = ## Change Log 2020-09-12 -* Changed to use async, non-blocking implementation -* Do not report low temperatures that indicate an error to mqtt +* Changed to use async non-blocking implementation +* Do not report erroneous low temperatures to MQTT * Disable plugin if temperature sensor not detected * Report the number of seconds until the first read in the info screen instead of sensor error 2021-04 -* Adaptation for runtime configuration. \ No newline at end of file +* Adaptation for runtime configuration. diff --git a/usermods/Temperature/usermod_temperature.h b/usermods/Temperature/usermod_temperature.h index a666639f..885f445e 100644 --- a/usermods/Temperature/usermod_temperature.h +++ b/usermods/Temperature/usermod_temperature.h @@ -21,7 +21,6 @@ class UsermodTemperature : public Usermod { private: - bool initDone = false; OneWire *oneWire; // GPIO pin used for sensor (with a default compile-time fallback) int8_t temperaturePin = TEMPERATURE_PIN; @@ -29,6 +28,7 @@ class UsermodTemperature : public Usermod { bool degC = true; // using parasite power on the sensor bool parasite = false; + int8_t parasitePin = -1; // how often do we read from sensor? unsigned long readingInterval = USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL; // set last reading as "40 sec before boot", so first reading is taken after 20 sec @@ -44,15 +44,12 @@ class UsermodTemperature : public Usermod { // temperature if flashed to a board without a sensor attached byte sensorFound; - bool enabled = true; - bool HApublished = false; // strings to reduce flash memory usage (used more than twice) - static const char _name[]; - static const char _enabled[]; static const char _readInterval[]; static const char _parasite[]; + static const char _parasitePin[]; //Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013 float readDallas() { @@ -94,12 +91,14 @@ class UsermodTemperature : public Usermod { DEBUG_PRINTLN(F("Requesting temperature.")); oneWire->reset(); oneWire->skip(); // skip ROM - oneWire->write(0x44,parasite); // request new temperature reading (TODO: parasite would need special handling) + oneWire->write(0x44,parasite); // request new temperature reading + if (parasite && parasitePin >=0 ) digitalWrite(parasitePin, HIGH); // has to happen within 10us (open MOSFET) lastTemperaturesRequest = millis(); waitingForConversion = true; } void readTemperature() { + if (parasite && parasitePin >=0 ) digitalWrite(parasitePin, LOW); // deactivate power (close MOSFET) temperature = readDallas(); lastMeasurement = millis(); waitingForConversion = false; @@ -134,6 +133,7 @@ class UsermodTemperature : public Usermod { return false; } +#ifndef WLED_DISABLE_MQTT void publishHomeAssistantAutodiscovery() { if (!WLED_MQTT_CONNECTED) return; @@ -155,8 +155,10 @@ class UsermodTemperature : public Usermod { mqtt->publish(buf, 0, true, json_str, payload_size); HApublished = true; } +#endif public: + UsermodTemperature(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM: this shouldn't be necessary (passthrough of constructor), maybe because Usermod is an abstract class void setup() { int retries = 10; @@ -164,7 +166,7 @@ class UsermodTemperature : public Usermod { temperature = -127.0f; // default to -127, DS18B20 only goes down to -50C if (enabled) { // config says we are enabled - DEBUG_PRINTLN(F("Allocating temperature pin...")); + USER_PRINTLN(F("Finding temperature pin...")); // pin retrieved from cfg.json (readFromConfig()) prior to running setup() if (temperaturePin >= 0 && pinManager.allocatePin(temperaturePin, true, PinOwner::UM_Temperature)) { oneWire = new OneWire(temperaturePin); @@ -173,15 +175,22 @@ class UsermodTemperature : public Usermod { delay(25); // try to find sensor } } + if (parasite && pinManager.allocatePin(parasitePin, true, PinOwner::UM_Temperature)) { + pinMode(parasitePin, OUTPUT); + digitalWrite(parasitePin, LOW); // deactivate power (close MOSFET) + } else { + parasitePin = -1; + } } else { if (temperaturePin >= 0) { - DEBUG_PRINTLN(F("Temperature pin allocation failed.")); + USER_PRINTLN(F("Temperature pin allocation failed.")); } temperaturePin = -1; // allocation failed } } lastMeasurement = millis() - readingInterval + 10000; initDone = true; + USER_PRINTLN(F("temperature usermod initialized.")); } void loop() { @@ -212,6 +221,7 @@ class UsermodTemperature : public Usermod { } errorCount = 0; +#ifndef WLED_DISABLE_MQTT if (WLED_MQTT_CONNECTED) { char subuf[64]; strcpy(subuf, mqttDeviceTopic); @@ -227,6 +237,7 @@ class UsermodTemperature : public Usermod { // publish something else to indicate status? } } +#endif } } @@ -236,6 +247,7 @@ class UsermodTemperature : public Usermod { */ //void connected() {} +#ifndef WLED_DISABLE_MQTT /** * subscribe to MQTT topic if needed */ @@ -246,6 +258,7 @@ class UsermodTemperature : public Usermod { publishHomeAssistantAutodiscovery(); } } +#endif /* * API calls te enable data exchange between WLED modules @@ -308,13 +321,15 @@ class UsermodTemperature : public Usermod { * addToConfig() (called from set.cpp) stores persistent properties to cfg.json */ void addToConfig(JsonObject &root) { + Usermod::addToConfig(root); + JsonObject top = root[FPSTR(_name)]; + // we add JSON object: {"Temperature": {"pin": 0, "degC": true}} - JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname - top[FPSTR(_enabled)] = enabled; top["pin"] = temperaturePin; // usermodparam top["degC"] = degC; // usermodparam top[FPSTR(_readInterval)] = readingInterval / 1000; top[FPSTR(_parasite)] = parasite; + top[FPSTR(_parasitePin)] = parasitePin; DEBUG_PRINTLN(F("Temperature config saved.")); } @@ -324,22 +339,24 @@ class UsermodTemperature : public Usermod { * The function should return true if configuration was successfully loaded or false if there was no configuration. */ bool readFromConfig(JsonObject &root) { + bool configComplete = Usermod::readFromConfig(root); + JsonObject top = root[FPSTR(_name)]; + // we look for JSON object: {"Temperature": {"pin": 0, "degC": true}} int8_t newTemperaturePin = temperaturePin; DEBUG_PRINT(FPSTR(_name)); - JsonObject top = root[FPSTR(_name)]; if (top.isNull()) { DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); return false; } - enabled = top[FPSTR(_enabled)] | enabled; newTemperaturePin = top["pin"] | newTemperaturePin; degC = top["degC"] | degC; readingInterval = top[FPSTR(_readInterval)] | readingInterval/1000; readingInterval = min(120,max(10,(int)readingInterval)) * 1000; // convert to ms parasite = top[FPSTR(_parasite)] | parasite; + parasitePin = top[FPSTR(_parasitePin)] | parasitePin; if (!initDone) { // first run: reading from cfg.json @@ -354,12 +371,22 @@ class UsermodTemperature : public Usermod { delete oneWire; pinManager.deallocatePin(temperaturePin, PinOwner::UM_Temperature); temperaturePin = newTemperaturePin; + pinManager.deallocatePin(parasitePin, PinOwner::UM_Temperature); // initialise setup(); } } // use "return !top["newestParameter"].isNull();" when updating Usermod with new features - return !top[FPSTR(_parasite)].isNull(); + return !top[FPSTR(_parasitePin)].isNull(); + } + + void appendConfigData() + { + oappend(SET_F("addHB('Temperature');")); // WLEDMM + oappend(SET_F("addInfo('Temperature:parasite-pwr")); //WLEDMM use literals + oappend(SET_F("',1,'(if no Vcc connected)');")); // 0 is field type, 1 is actual field + oappend(SET_F("addInfo('Temperature:parasite-pwr-pin")); //WLEDMM use literals + oappend(SET_F("',1,'(for external MOSFET)');")); // 0 is field type, 1 is actual field } uint16_t getId() @@ -369,7 +396,6 @@ class UsermodTemperature : public Usermod { }; // strings to reduce flash memory usage (used more than twice) -const char UsermodTemperature::_name[] PROGMEM = "Temperature"; -const char UsermodTemperature::_enabled[] PROGMEM = "enabled"; const char UsermodTemperature::_readInterval[] PROGMEM = "read-interval-s"; const char UsermodTemperature::_parasite[] PROGMEM = "parasite-pwr"; +const char UsermodTemperature::_parasitePin[] PROGMEM = "parasite-pwr-pin"; diff --git a/usermods/VL53L0X_gestures/readme.md b/usermods/VL53L0X_gestures/readme.md index 74c970dc..a230b1a6 100644 --- a/usermods/VL53L0X_gestures/readme.md +++ b/usermods/VL53L0X_gestures/readme.md @@ -1,10 +1,10 @@ # Description -That usermod implements support of simple hand gestures with VL53L0X sensor: on/off and brightness correction. -It can be useful for kitchen strips to avoid any touches. - - on/off - just swipe a hand below your sensor ("shortPressAction" is called and can be customized through WLED macros) - - brightness correction - keep your hand below sensor for 1 second to switch to "brightness" mode. - Configure brightness by changing distance to the sensor (see parameters below for customization). +Implements support of simple hand gestures via a VL53L0X sensor: on/off and brightness adjustment. +Useful for controlling strips when you want to avoid touching anything. + - on/off - swipe your hand below the sensor ("shortPressAction" is called. Can be customized via WLED macros) + - brightness adjustment - hold your hand below the sensor for 1 second to switch to "brightness" mode. + adjust the brightness by changing the distance between your hand and the sensor (see parameters below for customization). ## Installation @@ -26,4 +26,4 @@ default_envs = nodemcuv2 build_flags = ${env.build_flags} -D USERMOD_VL53L0X_GESTURES lib_deps = ${env.lib_deps} pololu/VL53L0X @ ^1.3.0 -``` \ No newline at end of file +``` diff --git a/usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h b/usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h index 39c2c3ef..fb616e45 100644 --- a/usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h +++ b/usermods/VL53L0X_gestures/usermod_vl53l0x_gestures.h @@ -50,14 +50,21 @@ class UsermodVL53L0XGestures : public Usermod { public: void setup() { - PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } }; - if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; } - Wire.begin(); + // WLEDMM join hardware I2C + if (!pinManager.joinWire()) { // WLEDMM - this allocates global I2C pins, then starts Wire - if not started previously + enabled = false; + return; + } + + //PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } }; + //if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; } + //Wire.begin(); sensor.setTimeout(150); if (!sensor.init()) { DEBUG_PRINTLN(F("Failed to detect and initialize VL53L0X sensor!")); + enabled = false; // WLEDMM bugfix } else { sensor.setMeasurementTimingBudget(20000); // set high speed mode } diff --git a/usermods/Wemos_D1_mini+Wemos32_mini_shield/readme.md b/usermods/Wemos_D1_mini+Wemos32_mini_shield/readme.md index eebc50da..105f2a24 100644 --- a/usermods/Wemos_D1_mini+Wemos32_mini_shield/readme.md +++ b/usermods/Wemos_D1_mini+Wemos32_mini_shield/readme.md @@ -9,10 +9,10 @@ ## Features - SSD1306 128x32 or 128x64 I2C OLED display - On screen IP address, SSID and controller status (e.g. ON or OFF, recent effect) -- Auto display shutoff for saving display lifetime +- Auto display shutoff for extending display lifetime - Dallas temperature sensor - Reporting temperature to MQTT broker -- Relay for energy saving +- Relay for saving energy ## Hardware ![Shield](https://github.com/srg74/WLED-wemos-shield/blob/master/resources/Images/Assembly_8.jpg) diff --git a/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp b/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp index c7eb8ee0..78cc32a8 100644 --- a/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp +++ b/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod.cpp @@ -101,6 +101,7 @@ void userLoop() { if (temptimer - lastMeasure > 60000) { lastMeasure = temptimer; +#ifndef WLED_DISABLE_MQTT //Check if MQTT Connected, otherwise it will crash the 8266 if (mqtt != nullptr) { @@ -116,6 +117,7 @@ void userLoop() { t += "/temperature"; mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str()); } + #endif } // Check if we time interval for redrawing passes. diff --git a/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp b/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp index 05d4e77a..c9d9a527 100644 --- a/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp +++ b/usermods/Wemos_D1_mini+Wemos32_mini_shield/usermod_bme280.cpp @@ -103,6 +103,7 @@ void userLoop() { { lastMeasure = tempTimer; +#ifndef WLED_DISABLE_MQTT // Check if MQTT Connected, otherwise it will crash the 8266 if (mqtt != nullptr) { @@ -122,6 +123,7 @@ void userLoop() { h += "/humidity"; mqtt->publish(h.c_str(), 0, true, String(board_humidity).c_str()); } + #endif } // Check if we time interval for redrawing passes. diff --git a/usermods/customeffects/arti.h b/usermods/artifx/arti.h similarity index 99% rename from usermods/customeffects/arti.h rename to usermods/artifx/arti.h index 4822ee63..290a7604 100644 --- a/usermods/customeffects/arti.h +++ b/usermods/artifx/arti.h @@ -3,6 +3,7 @@ @file arti.h @date 20220818 @author Ewoud Wijma + @Copyright (c) 2023 Ewoud Wijma @repo https://github.com/ewoudwijma/ARTI @remarks - #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 100 //set this in ArduinoJson!!!, currently not necessary... @@ -2506,9 +2507,9 @@ public: JsonObject::iterator objectIterator = definitionJson.begin(); JsonObject metaData = objectIterator->value(); const char * version = metaData["version"]; - if (strcmp(version, "v032") != 0) + if (strcmp(version, "v033") != 0) { - ERROR_ARTI("Version of definition.json file (%s) should be v032.\nPress Download wled json\n", version); + ERROR_ARTI("Version of definition.json file (%s) should be v033.\nPress Download wled json\n", version); return false; } const char * startNode = metaData["start"]; diff --git a/usermods/customeffects/arti_wled.h b/usermods/artifx/arti_wled.h similarity index 91% rename from usermods/customeffects/arti_wled.h rename to usermods/artifx/arti_wled.h index 2187f75a..d9c8e363 100644 --- a/usermods/customeffects/arti_wled.h +++ b/usermods/artifx/arti_wled.h @@ -1,8 +1,9 @@ /* @title Arduino Real Time Interpreter (ARTI) - @file arti_wled_plugin.h + @file arti_wled.h @date 20220818 @author Ewoud Wijma + @Copyright (c) 2023 Ewoud Wijma @repo https://github.com/ewoudwijma/ARTI */ @@ -55,7 +56,8 @@ enum Externals F_custom1Slider, F_custom2Slider, F_custom3Slider, - F_sampleAvg, + F_volume, + F_fftResult, F_shift, F_circle2D, @@ -146,6 +148,18 @@ float ARTI::arti_external_function(uint8_t function, float par1, float par2, flo case F_segcolor: return SEGCOLOR((uint8_t)par1); + case F_fftResult: + { + um_data_t *um_data; + if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) { + // add support for no audio + um_data = simulateSound(SEGMENT.soundSim); + } + uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; + + return fftResult[(uint8_t)par1%16]; + } + case F_shift: { uint32_t saveFirstPixel = SEGMENT.getPixelColor(0); for (uint16_t i=0; iu_data[0]; //ewowi: use instead of sampleAvg??? + float volumeSmth = *(float*) um_data->u_data[0]; return volumeSmth; } @@ -400,8 +419,8 @@ float ARTI::arti_get_external_variable(uint8_t variable, float par1, float par2, return F_custom2Slider; case F_custom3Slider: return F_custom3Slider; - case F_sampleAvg: - return F_sampleAvg; + case F_volume: + return F_volume; case F_hour: return F_hour; @@ -507,9 +526,12 @@ bool ARTI::loop() for (int i = 0; i< arti_get_external_variable(F_ledCount); i++) { - ar->set(function_symbol->function_scope->symbols[0]->scope_index, i%strip.matrixWidth); // set x - if (function_symbol->function_scope->nrOfFormals == 2) // 2D - ar->set(function_symbol->function_scope->symbols[1]->scope_index, i/strip.matrixWidth); // set y + if (function_symbol->function_scope->nrOfFormals == 2) {// 2D + ar->set(function_symbol->function_scope->symbols[0]->scope_index, i%Segment::maxWidth); // set x + ar->set(function_symbol->function_scope->symbols[1]->scope_index, i/Segment::maxWidth); // set y + } + else + ar->set(function_symbol->function_scope->symbols[0]->scope_index, i); // set x this->callStack->push(ar); diff --git a/usermods/customeffects/customeffects.css b/usermods/artifx/artifx.css similarity index 100% rename from usermods/customeffects/customeffects.css rename to usermods/artifx/artifx.css diff --git a/usermods/customeffects/customeffects.js b/usermods/artifx/artifx.js similarity index 61% rename from usermods/customeffects/customeffects.js rename to usermods/artifx/artifx.js index 85805b9b..a56c84e2 100644 --- a/usermods/customeffects/customeffects.js +++ b/usermods/artifx/artifx.js @@ -9,7 +9,7 @@ function toggleCEEditor(name, segID) { d.getElementById('ceEditor').style.transform = (isCEEditor) ? "translateY(0px)":"translateY(100%)"; } -function fetchAndExecute(url, name, callback) +function fetchAndExecute(url, name, callback, callError) { fetch (url+name, { @@ -17,8 +17,8 @@ function fetchAndExecute(url, name, callback) }) .then(res => { if (!res.ok) { - showToast("File " + name + " not found", true); - return ""; + callError("File " + name + " not found"); + return ""; } return res.text(); }) @@ -26,10 +26,7 @@ function fetchAndExecute(url, name, callback) callback(text); }) .catch(function (error) { - showToast("Error getting " + name, true); - // showToast(error, true); - // console.log(error); - presetError(false); + callError("Error getting " + name); }) .finally(() => { // if (callback) setTimeout(callback,99); @@ -53,6 +50,9 @@ function loadLogFile(name, attempt) { } else ceLogArea.value = logtext; + }, function(error){ + showToast(error); + console.log(error); }); } @@ -93,20 +93,23 @@ function populateCEEditor(name, segID) { fetchAndExecute((loc?`http://${locip}`:'.') + "/", name + ".wled", function(text) { - var cn=`Custom Effects Editor
+ var cn=`ARTI-FX Editor
${name}.wled


- +
- -
- Custom Effects Library
- Custom Effects Help
+ +
+ +

Compile and Run Log

- Run log > 3 seconds is send to Serial Ouput.`; + Run log > 3 seconds is send to Serial Ouput.
+ 🥚 + 🥚 + 🥚`; d.getElementById('kceEditor').innerHTML = cn; @@ -114,15 +117,21 @@ function populateCEEditor(name, segID) ceLogArea.value = "."; loadLogFile(name + ".wled.log", 1); + }, function(error){ + showToast(error); + console.log(error); }); } -function downloadCEFile(name) { - var url = "https://raw.githubusercontent.com/MoonModules/WLED-Effects/master/CustomEffects/wled/"; +function downloadGHFile(url, name, save=false, warn=false) { //Githubfile + if (url == "CE") url = "https://raw.githubusercontent.com/MoonModules/WLED-Effects/master/ARTIFX/wled/"; + if (url == "HBB") url = "https://raw.githubusercontent.com/MoonModules/WLED-Effects/master/Presets/HB_PresetPack210808_32x32_16seg/Base%20pack/"; + if (url == "HBE") url = "https://raw.githubusercontent.com/MoonModules/WLED-Effects/master/Presets/HB_PresetPack210808_32x32_16seg/Effects%20pack/"; + if (url == "LM") url = "https://raw.githubusercontent.com/MoonModules/WLED-Effects/master/Ledmaps/"; fetchAndExecute(url, name, function(text) { - if (name == "wledv032.json" || name == "presets.json") { - if (!confirm('Are you sure to download/overwrite ' + name + '?')) + if (save) { + if (warn && !confirm('Are you sure to download/overwrite ' + name + '?')) return; uploadFileWithText("/" + name, text); } @@ -131,13 +140,16 @@ function downloadCEFile(name) { var ceProgramArea = d.getElementById("ceProgramArea"); ceProgramArea.value = text; } + }, function(error){ + showToast(error); + console.log(url + name,error); }); return; var request = new XMLHttpRequest(); request.onload = function() { - if (name == "wledv032.json" || name == "presets.json") { + if (name == "wledv033.json" || name == "presets.json") { if (!confirm('Are you sure to download ' + name + '?')) return; uploadFileWithText("/" + name, request.response); @@ -155,7 +167,7 @@ function downloadCEFile(name) { function loadCETemplate(name) { var ceProgramArea = d.getElementById("ceProgramArea"); ceProgramArea.value = `/* - Custom Effects Template + ARTIFX Template */ program ${name} { diff --git a/usermods/customeffects/usermod_v2_customeffects.h b/usermods/artifx/usermod_v2_artifx.h similarity index 86% rename from usermods/customeffects/usermod_v2_customeffects.h rename to usermods/artifx/usermod_v2_artifx.h index c88a5a5f..eb919073 100644 --- a/usermods/customeffects/usermod_v2_customeffects.h +++ b/usermods/artifx/usermod_v2_artifx.h @@ -1,3 +1,12 @@ +/* + @title Usermod ARTIFX (AF) + @file usermod_v2_artifx.h + @date 20220818 + @author Ewoud Wijma + @Copyright (c) 2023 Ewoud Wijma + @repo https://github.com/ewoudwijma/ARTI + */ + #pragma once #include "wled.h" @@ -8,14 +17,16 @@ ARTI * arti; //effect function -uint16_t mode_customEffect(void) { +uint16_t mode_ARTIFX(void) { //tbd: move statics to SEGMENT.data static bool succesful; static bool notEnoughHeap; static char previousEffect[charLength]; - if (SEGENV.call == 0) + if (SEGENV.call == 0) { strcpy(previousEffect, ""); //force init + SEGMENT.fill(BLACK); //in case not all leds used e.g. when using expand 1d Circle. Tbd: fill black should never be used to allow for blends/transitions + } char currentEffect[charLength]; strcpy(currentEffect, (SEGMENT.name != nullptr)?SEGMENT.name:"default"); //note: switching preset with segment name to preset without does not clear the SEGMENT.name variable, but not gonna solve here ;-) @@ -40,7 +51,7 @@ uint16_t mode_customEffect(void) { strcat(programFileName, currentEffect); strcat(programFileName, ".wled"); - succesful = arti->setup("/wledv032.json", programFileName); + succesful = arti->setup("/wledv033.json", programFileName); if (!succesful) ERROR_ARTI("Setup not succesful\n"); @@ -88,9 +99,9 @@ uint16_t mode_customEffect(void) { return FRAMETIME; } -static const char _data_FX_MODE_CUSTOMEFFECT[] PROGMEM = "⚙️ Custom Effect@Speed,Intensity,Custom 1, Custom 2, Custom 3;!;!;mp12=0,1d"; +static const char _data_FX_MODE_ARTIFX[] PROGMEM = "⚙️ ARTI-FX ☾@Speed,Intensity,Custom 1, Custom 2, Custom 3;!;!;1;mp12=0"; -class CustomEffectsUserMod : public Usermod { +class ARTIFXUserMod : public Usermod { private: // strings to reduce flash memory usage (used more than twice) static const char _name[]; //usermod name @@ -104,7 +115,7 @@ class CustomEffectsUserMod : public Usermod { void setup() { if (!initDone) - strip.addEffect(FX_MODE_CUSTOMEFFECT, &mode_customEffect, _data_FX_MODE_CUSTOMEFFECT); + strip.addEffect(FX_MODE_ARTIFX, &mode_ARTIFX, _data_FX_MODE_ARTIFX); initDone = true; enabled = true; } @@ -122,12 +133,6 @@ class CustomEffectsUserMod : public Usermod { */ void addToJsonInfo(JsonObject& root) { - JsonObject user = root["u"]; - if (user.isNull()) user = root.createNestedObject("u"); - - JsonArray infoArr = user.createNestedArray(FPSTR(_name)); - infoArr.add(errorMessage); //value - // infoArr.add(""); //unit } @@ -195,9 +200,9 @@ class CustomEffectsUserMod : public Usermod { */ uint16_t getId() { - return USERMOD_ID_CUSTOMEFFECTS; + return USERMOD_ID_ARTIFX; } }; // strings to reduce flash memory usage (used more than twice) -const char CustomEffectsUserMod::_name[] PROGMEM = "CustomEffects"; +const char ARTIFXUserMod::_name[] PROGMEM = "ARTIFX"; diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 2f9a0482..1c14cb79 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -29,9 +29,9 @@ // #define SR_DEBUG // generic SR DEBUG messages #ifdef SR_DEBUG - #define DEBUGSR_PRINT(x) DEBUGOUT.print(x) - #define DEBUGSR_PRINTLN(x) DEBUGOUT.println(x) - #define DEBUGSR_PRINTF(x...) DEBUGOUT.printf(x) + #define DEBUGSR_PRINT(x) DEBUGOUT(x) + #define DEBUGSR_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUGSR_PRINTF(x...) DEBUGOUTF(x) #else #define DEBUGSR_PRINT(x) #define DEBUGSR_PRINTLN(x) @@ -54,6 +54,18 @@ #endif #endif +#if defined(MIC_LOGGER) || defined(FFT_SAMPLING_LOG) + #define PLOT_PRINT(x) DEBUGOUT(x) + #define PLOT_PRINTLN(x) DEBUGOUTLN(x) + #define PLOT_PRINTF(x...) DEBUGOUTF(x) + #define PLOT_FLUSH() DEBUGOUTFlush() +#else + #define PLOT_PRINT(x) + #define PLOT_PRINTLN(x) + #define PLOT_PRINTF(x...) + #define PLOT_FLUSH() +#endif + // use audio source class (ESP32 specific) #include "audio_source.h" constexpr i2s_port_t I2S_PORT = I2S_NUM_0; // I2S port to use (do not change !) @@ -111,6 +123,15 @@ static AudioSource *audioSource = nullptr; static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks. static bool useBandPassFilter = false; // if true, enables a bandpass filter 80Hz-16Khz to remove noise. Applies before FFT. +//WLEDMM add experimental settings +static uint8_t micLevelMethod = 0; // 0=old "floating" miclev, 1=new "freeze" mode, 2=fast freeze mode (mode 2 may not work for you) +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) +static uint8_t averageByRMS = false; // false: use mean value, true: use RMS (root mean squared). use simpler method on slower MCUs. +#else +static uint8_t averageByRMS = true; // false: use mean value, true: use RMS (root mean squared). use better method on fast MCUs. +#endif +static uint8_t freqDist = 0; // 0=old 1=rightshift mode + // audioreactive variables shared with FFT task static float micDataReal = 0.0f; // MicIn data with full 24bit resolution - lowest 8bit after decimal point static float multAgc = 1.0f; // sample * multAgc = sampleAgc. Our AGC multiplier @@ -124,19 +145,31 @@ static float volumeSmth = 0.0f; // either sampleAvg or sampleAgc depending // peak detection static bool samplePeak = false; // Boolean flag for peak - used in effects. Responding routine may reset this flag. Auto-reset after strip.getMinShowDelay() -static uint8_t maxVol = 10; // Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) +static uint8_t maxVol = 31; // (was 10) Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated) static uint8_t binNum = 8; // Used to select the bin for FFT based beat detection (deprecated) static bool udpSamplePeak = false; // Boolean flag for peak. Set at the same tiem as samplePeak, but reset by transmitAudioData static unsigned long timeOfPeak = 0; // time of last sample peak detection. static void detectSamplePeak(void); // peak detection function (needs scaled FFT reasults in vReal[]) static void autoResetPeak(void); // peak auto-reset function +// shared vars for debugging +#ifdef MIC_LOGGER +static volatile float micReal_min = 0.0f; // MicIn data min from last batch of samples +static volatile float micReal_avg = 0.0f; // MicIn data average (from last batch of samples) +static volatile float micReal_max = 0.0f; // MicIn data max from last batch of samples +#if 0 +static volatile float micReal_min2 = 0.0f; // MicIn data min after filtering +static volatile float micReal_max2 = 0.0f; // MicIn data max after filtering +#endif +#endif //////////////////// // Begin FFT Code // //////////////////// // some prototypes, to ensure consistent interfaces +static float mapf(float x, float in_min, float in_max, float out_min, float out_max); // map function for float +static float fftAddAvg(int from, int to); // average of several FFT result bins void FFTcode(void * parameter); // audio processing task: read samples, run FFT, fill GEQ channels from FFT results static void runMicFilter(uint16_t numSamples, float *sampleBuffer); // pre-filtering of raw samples (band-pass) static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels); // post-processing and post-amp of GEQ channels @@ -158,7 +191,7 @@ static const float fftResultPink[MAX_PINK+1][NUM_GEQ_CHANNELS] = { { 12.0f, 6.60f, 2.60f, 1.15f, 1.35f, 2.05f, 2.85f, 2.50f, 2.85f, 3.30f, 2.25f, 4.35f, 3.80f, 3.75f, 6.50f, 9.00f}, // 4 IMNP441 - voice, or small speaker { 2.75f, 1.60f, 1.40f, 1.46f, 1.52f, 1.57f, 1.68f, 1.80f, 1.89f, 2.00f, 2.11f, 2.21f, 2.30f, 1.75f, 2.55f, 3.60f }, // 5 ICS-43434 datasheet response * pink noise - { 2.25f, 1.20f, 1.00f, 1.20f, 1.80f, 3.20f, 5.10f, 5.50f, 4.00f, 4.80f, 6.70f, 6.40f, 5.80f, 3.90f, 6.00f, 5.10f }, // 6 ICS-43434 - big speaker, strong bass + { 2.90f, 1.25f, 0.75f, 1.08f, 2.35f, 3.55f, 3.60f, 3.40f, 2.75f, 3.45f, 4.40f, 6.35f, 6.80f, 6.80f, 8.50f,10.64f }, // 6 ICS-43434 - big speaker, strong bass { 1.65f, 1.00f, 1.05f, 1.30f, 1.48f, 1.30f, 1.80f, 3.00f, 1.50f, 1.65f, 2.56f, 3.00f, 2.60f, 2.30f, 5.00f, 3.00f }, // 7 SPM1423 { 2.25f, 1.60f, 1.30f, 1.60f, 2.20f, 3.20f, 3.06f, 2.60f, 2.85f, 3.50f, 4.10f, 4.80f, 5.70f, 6.05f,10.50f,14.85f }, // 8 userdef #1 for ewowi (enhance median/high freqs) @@ -201,17 +234,20 @@ static float FFT_MajorPeak = 1.0f; // FFT: strongest (peak) frequen static float FFT_Magnitude = 0.0f; // FFT: volume (magnitude) of peak frequency static uint8_t fftResult[NUM_GEQ_CHANNELS]= {0};// Our calculated freq. channel result table to be used by effects #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) -static uint64_t fftTime = 0; -static uint64_t sampleTime = 0; +static float fftTaskCycle = 0; // avg cycle time for FFT task +static float fftTime = 0; // avg time for single FFT +static float sampleTime = 0; // avg (blocked) time for reading I2S samples #endif // FFT Task variables (filtering and post-processing) +static float lastFftCalc[NUM_GEQ_CHANNELS] = {0.0f}; // backup of last FFT channels (before postprocessing) static float fftCalc[NUM_GEQ_CHANNELS] = {0.0f}; // Try and normalize fftBin values to a max of 4096, so that 4096/16 = 256. static float fftAvg[NUM_GEQ_CHANNELS] = {0.0f}; // Calculated frequency channel results, with smoothing (used if dynamics limiter is ON) #ifdef SR_DEBUG static float fftResultMax[NUM_GEQ_CHANNELS] = {0.0f}; // A table used for testing to determine how our post-processing is working. #endif +#if !defined(CONFIG_IDF_TARGET_ESP32C3) // audio source parameters and constant constexpr SRate_t SAMPLE_RATE = 22050; // Base sample rate in Hz - 22Khz is a standard rate. Physical sample time -> 23ms //constexpr SRate_t SAMPLE_RATE = 16000; // 16kHz - use if FFTtask takes more than 20ms. Physical sample time -> 32ms @@ -221,14 +257,25 @@ constexpr SRate_t SAMPLE_RATE = 22050; // Base sample rate in Hz - 22Khz //#define FFT_MIN_CYCLE 30 // Use with 16Khz sampling //#define FFT_MIN_CYCLE 23 // minimum time before FFT task is repeated. Use with 20Khz sampling //#define FFT_MIN_CYCLE 46 // minimum time before FFT task is repeated. Use with 10Khz sampling +#else +// slightly lower the sampling rate for -C3, to improve stability +//constexpr SRate_t SAMPLE_RATE = 20480; // 20Khz; Physical sample time -> 25ms +//#define FFT_MIN_CYCLE 23 // minimum time before FFT task is repeated. +constexpr SRate_t SAMPLE_RATE = 18000; // 18Khz; Physical sample time -> 28ms +#define FFT_MIN_CYCLE 25 // minimum time before FFT task is repeated. +// try 16Khz in case your device still lags and responds too slowly. +//constexpr SRate_t SAMPLE_RATE = 16000; // 16Khz -> Physical sample time -> 32ms +//#define FFT_MIN_CYCLE 30 // minimum time before FFT task is repeated. +#endif // FFT Constants constexpr uint16_t samplesFFT = 512; // Samples in an FFT batch - This value MUST ALWAYS be a power of 2 constexpr uint16_t samplesFFT_2 = 256; // meaningfull part of FFT results - only the "lower half" contains useful information. // the following are observed values, supported by a bit of "educated guessing" //#define FFT_DOWNSCALE 0.65f // 20kHz - downscaling factor for FFT results - "Flat-Top" window @20Khz, old freq channels -#define FFT_DOWNSCALE 0.46f // downscaling factor for FFT results - for "Flat-Top" window @22Khz, new freq channels -#define LOG_256 5.54517744 // log2(256) +//#define FFT_DOWNSCALE 0.46f // downscaling factor for FFT results - for "Flat-Top" window @22Khz, new freq channels +#define FFT_DOWNSCALE 0.40f // downscaling factor for FFT results, RMS averaging +#define LOG_256 5.54517744f // log(256) // These are the input and output vectors. Input vectors receive computed results from FFT. static float vReal[samplesFFT] = {0.0f}; // FFT sample inputs / freq output - these are our raw result bins @@ -240,13 +287,18 @@ static float windowWeighingFactors[samplesFFT] = {0.0f}; // Create FFT object #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT // lib_deps += https://github.com/kosme/arduinoFFT#develop @ 1.9.2 -#define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc), and an a few other speedups -#define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt -#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// these options actually cause slow-down on -S2 (-S2 doesn't have floating point hardware) +//#define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc), and an a few other speedups - WLEDMM not faster on ESP32 +//#define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt - WLEDMM slower on ESP32 +#endif +#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 10-50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION) #else + // around 50% slower on -S2 // lib_deps += https://github.com/blazoncek/arduinoFFT.git #endif #include + #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT static ArduinoFFT FFT = ArduinoFFT( vReal, vImag, samplesFFT, SAMPLE_RATE, windowWeighingFactors); #else @@ -261,33 +313,45 @@ static float mapf(float x, float in_min, float in_max, float out_min, float out_ } // compute average of several FFT resut bins -#if 1 // linear average -static float fftAddAvg(int from, int to) { +// linear average +static float fftAddAvgLin(int from, int to) { float result = 0.0f; for (int i = from; i <= to; i++) { result += vReal[i]; } return result / float(to - from + 1); } -#else // RMS average -static float fftAddAvg(int from, int to) { +// RMS average +static float fftAddAvgRMS(int from, int to) { double result = 0.0; for (int i = from; i <= to; i++) { result += vReal[i] * vReal[i]; } return sqrtf(result / float(to - from + 1)); } -#endif +static float fftAddAvg(int from, int to) { + if (from == to) return vReal[from]; // small optimization + if (averageByRMS) return fftAddAvgRMS(from, to); // use SMS + else return fftAddAvgLin(from, to); // use linear average +} + +#if defined(CONFIG_IDF_TARGET_ESP32C3) +constexpr bool skipSecondFFT = true; +#else +constexpr bool skipSecondFFT = false; +#endif // // FFT main task // void FFTcode(void * parameter) { - DEBUGSR_PRINT("FFT started on core: "); DEBUGSR_PRINTLN(xPortGetCoreID()); + // DEBUGSR_PRINT("FFT started on core: "); DEBUGSR_PRINTLN(xPortGetCoreID()); // causes trouble on -S2 // see https://www.freertos.org/vtaskdelayuntil.html const TickType_t xFrequency = FFT_MIN_CYCLE * portTICK_PERIOD_MS; + const TickType_t xFrequencyDouble = FFT_MIN_CYCLE * portTICK_PERIOD_MS * 2; + static bool isFirstRun = false; TickType_t xLastWakeTime = xTaskGetTickCount(); for(;;) { @@ -296,6 +360,7 @@ void FFTcode(void * parameter) // Don't run FFT computing code if we're in Receive mode or in realtime mode if (disableSoundProcessing || (audioSyncEnabled & 0x02)) { + isFirstRun = false; vTaskDelayUntil( &xLastWakeTime, xFrequency); // release CPU, and let I2S fill its buffers continue; } @@ -303,6 +368,15 @@ void FFTcode(void * parameter) #if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS) uint64_t start = esp_timer_get_time(); bool haveDoneFFT = false; // indicates if second measurement (FFT time) is valid + + static uint64_t lastCycleStart = 0; + static uint64_t lastLastTime = 0; + if ((lastCycleStart > 0) && (lastCycleStart < start)) { // filter out overflows + uint64_t taskTimeInMillis = ((start - lastCycleStart) +5ULL) / 10ULL; // "+5" to ensure proper rounding + fftTaskCycle = (((taskTimeInMillis + lastLastTime)/2) *4 + fftTaskCycle*6)/10.0; // smart smooth + lastLastTime = taskTimeInMillis; + } + lastCycleStart = start; #endif // get a fresh batch of samples from I2S @@ -311,12 +385,28 @@ void FFTcode(void * parameter) #if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS) if (start < esp_timer_get_time()) { // filter out overflows uint64_t sampleTimeInMillis = (esp_timer_get_time() - start +5ULL) / 10ULL; // "+5" to ensure proper rounding - sampleTime = (sampleTimeInMillis*3 + sampleTime*7)/10; // smooth + sampleTime = (sampleTimeInMillis*3 + sampleTime*7)/10.0; // smooth } start = esp_timer_get_time(); // start measuring FFT time #endif xLastWakeTime = xTaskGetTickCount(); // update "last unblocked time" for vTaskDelay + isFirstRun = !isFirstRun; // toggle throtte + +#ifdef MIC_LOGGER + float datMin = 0.0f; + float datMax = 0.0f; + double datAvg = 0.0f; + for (int i=0; i < samplesFFT; i++) { + if (i==0) { + datMin = datMax = vReal[i]; + } else { + if (datMin > vReal[i]) datMin = vReal[i]; + if (datMax < vReal[i]) datMax = vReal[i]; + } + datAvg += vReal[i]; + } +#endif // band pass filter - can reduce noise floor by a factor of 50 // downside: frequencies below 100Hz will be ignored @@ -334,42 +424,62 @@ void FFTcode(void * parameter) // release highest sample to volume reactive effects early - not strictly necessary here - could also be done at the end of the function // early release allows the filters (getSample() and agcAvg()) to work with fresh values - we will have matching gain and noise gate values when we want to process the FFT results. micDataReal = maxSample; - +#ifdef MIC_LOGGER + micReal_min = datMin; + micReal_max = datMax; + micReal_avg = datAvg / samplesFFT; +#if 0 + // compute mix/max again after filering - usefull for filter debugging + for (int i=0; i < samplesFFT; i++) { + if (i==0) { + datMin = datMax = vReal[i]; + } else { + if (datMin > vReal[i]) datMin = vReal[i]; + if (datMax < vReal[i]) datMax = vReal[i]; + } + } + micReal_min2 = datMin; + micReal_max2 = datMax; +#endif +#endif // run FFT (takes 3-5ms on ESP32) //if (fabsf(sampleAvg) > 0.25f) { // noise gate open if (fabsf(volumeSmth) > 0.25f) { // noise gate open + if ((skipSecondFFT == false) || (isFirstRun == true)) { + // run FFT (takes 2-3ms on ESP32, ~12ms on ESP32-S2, ~30ms on -C3) + #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT + FFT.dcRemoval(); // remove DC offset + #if !defined(FFT_PREFER_EXACT_PEAKS) + FFT.windowing( FFTWindow::Flat_top, FFTDirection::Forward); // Weigh data using "Flat Top" function - better amplitude accuracy + #else + FFT.windowing(FFTWindow::Blackman_Harris, FFTDirection::Forward); // Weigh data using "Blackman- Harris" window - sharp peaks due to excellent sideband rejection + #endif + FFT.compute( FFTDirection::Forward ); // Compute FFT + FFT.complexToMagnitude(); // Compute magnitudes + #else + FFT.DCRemoval(); // let FFT lib remove DC component, so we don't need to care about this in getSamples() - // run FFT (takes 3-5ms on ESP32, ~12ms on ESP32-S2) -#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT - FFT.dcRemoval(); // remove DC offset - #if !defined(FFT_PREFER_EXACT_PEAKS) - FFT.windowing( FFTWindow::Flat_top, FFTDirection::Forward); // Weigh data using "Flat Top" function - better amplitude accuracy - #else - FFT.windowing(FFTWindow::Blackman_Harris, FFTDirection::Forward); // Weigh data using "Blackman- Harris" window - sharp peaks due to excellent sideband rejection - #endif - FFT.compute( FFTDirection::Forward ); // Compute FFT - FFT.complexToMagnitude(); // Compute magnitudes -#else - FFT.DCRemoval(); // let FFT lib remove DC component, so we don't need to care about this in getSamples() + //FFT.Windowing( FFT_WIN_TYP_HAMMING, FFT_FORWARD ); // Weigh data - standard Hamming window + //FFT.Windowing( FFT_WIN_TYP_BLACKMAN, FFT_FORWARD ); // Blackman window - better side freq rejection + #if !defined(FFT_PREFER_EXACT_PEAKS) + FFT.Windowing( FFT_WIN_TYP_FLT_TOP, FFT_FORWARD ); // Flat Top Window - better amplitude accuracy + #else + FFT.Windowing( FFT_WIN_TYP_BLACKMAN_HARRIS, FFT_FORWARD );// Blackman-Harris - excellent sideband rejection + #endif + FFT.Compute( FFT_FORWARD ); // Compute FFT + FFT.ComplexToMagnitude(); // Compute magnitudes + #endif - //FFT.Windowing( FFT_WIN_TYP_HAMMING, FFT_FORWARD ); // Weigh data - standard Hamming window - //FFT.Windowing( FFT_WIN_TYP_BLACKMAN, FFT_FORWARD ); // Blackman window - better side freq rejection - #if !defined(FFT_PREFER_EXACT_PEAKS) - FFT.Windowing( FFT_WIN_TYP_FLT_TOP, FFT_FORWARD ); // Flat Top Window - better amplitude accuracy - #else - FFT.Windowing( FFT_WIN_TYP_BLACKMAN_HARRIS, FFT_FORWARD );// Blackman-Harris - excellent sideband rejection - #endif - FFT.Compute( FFT_FORWARD ); // Compute FFT - FFT.ComplexToMagnitude(); // Compute magnitudes -#endif - -#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT - FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant -#else - FFT.MajorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant -#endif - FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects + #ifdef UM_AUDIOREACTIVE_USE_NEW_FFT + FFT.majorPeak(FFT_MajorPeak, FFT_Magnitude); // let the effects know which freq was most dominant + #else + FFT.MajorPeak(&FFT_MajorPeak, &FFT_Magnitude); // let the effects know which freq was most dominant + #endif + FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects + } else { // skip second run --> clear fft results, keep peaks + memset(vReal, 0, sizeof(vReal)); + } #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) haveDoneFFT = true; #endif @@ -380,14 +490,16 @@ void FFTcode(void * parameter) FFT_Magnitude = 0.001; } - for (int i = 0; i < samplesFFT; i++) { - float t = fabsf(vReal[i]); // just to be sure - values in fft bins should be positive any way - vReal[i] = t / 16.0f; // Reduce magnitude. Want end result to be scaled linear and ~4096 max. - } // for() + if ((skipSecondFFT == false) || (isFirstRun == true)) { - // mapping of FFT result bins to frequency channels - //if (fabsf(sampleAvg) > 0.25f) { // noise gate open - if (fabsf(volumeSmth) > 0.25f) { // noise gate open + for (int i = 0; i < samplesFFT; i++) { + float t = fabsf(vReal[i]); // just to be sure - values in fft bins should be positive any way + vReal[i] = t / 16.0f; // Reduce magnitude. Want end result to be scaled linear and ~4096 max. + } // for() + + // mapping of FFT result bins to frequency channels + //if (fabsf(sampleAvg) > 0.25f) { // noise gate open + if (fabsf(volumeSmth) > 0.25f) { // noise gate open #if 0 /* This FFT post processing is a DIY endeavour. What we really need is someone with sound engineering expertise to do a great job here AND most importantly, that the animations look GREAT as a result. * @@ -415,54 +527,96 @@ void FFTcode(void * parameter) fftCalc[14] = fftAddAvg(147,194); // 2940 - 3900 fftCalc[15] = fftAddAvg(194,250); // 3880 - 5000 // avoid the last 5 bins, which are usually inaccurate #else - /* new mapping, optimized for 22050 Hz by softhack007 */ + //WLEDMM: different distributions + if (freqDist == 0) { + /* new mapping, optimized for 22050 Hz by softhack007 --- update: removed overlap */ // bins frequency range if (useBandPassFilter) { // skip frequencies below 100hz - fftCalc[ 0] = 0.8f * fftAddAvg(3,4); - fftCalc[ 1] = 0.9f * fftAddAvg(4,5); - fftCalc[ 2] = fftAddAvg(5,6); - fftCalc[ 3] = fftAddAvg(6,7); + fftCalc[ 0] = 0.8f * fftAddAvg(3,3); + fftCalc[ 1] = 0.9f * fftAddAvg(4,4); + fftCalc[ 2] = fftAddAvg(5,5); + fftCalc[ 3] = fftAddAvg(6,6); // don't use the last bins from 206 to 255. fftCalc[15] = fftAddAvg(165,205) * 0.75f; // 40 7106 - 8828 high -- with some damping } else { - fftCalc[ 0] = fftAddAvg(1,2); // 1 43 - 86 sub-bass - fftCalc[ 1] = fftAddAvg(2,3); // 1 86 - 129 bass - fftCalc[ 2] = fftAddAvg(3,5); // 2 129 - 216 bass - fftCalc[ 3] = fftAddAvg(5,7); // 2 216 - 301 bass + midrange + fftCalc[ 0] = fftAddAvg(1,1); // 1 43 - 86 sub-bass + fftCalc[ 1] = fftAddAvg(2,2); // 1 86 - 129 bass + fftCalc[ 2] = fftAddAvg(3,4); // 2 129 - 216 bass + fftCalc[ 3] = fftAddAvg(5,6); // 2 216 - 301 bass + midrange // don't use the last bins from 216 to 255. They are usually contaminated by aliasing (aka noise) fftCalc[15] = fftAddAvg(165,215) * 0.70f; // 50 7106 - 9259 high -- with some damping } - fftCalc[ 4] = fftAddAvg(7,10); // 3 301 - 430 midrange - fftCalc[ 5] = fftAddAvg(10,13); // 3 430 - 560 midrange - fftCalc[ 6] = fftAddAvg(13,19); // 5 560 - 818 midrange - fftCalc[ 7] = fftAddAvg(19,26); // 7 818 - 1120 midrange -- 1Khz should always be the center ! - fftCalc[ 8] = fftAddAvg(26,33); // 7 1120 - 1421 midrange - fftCalc[ 9] = fftAddAvg(33,44); // 9 1421 - 1895 midrange - fftCalc[10] = fftAddAvg(44,56); // 12 1895 - 2412 midrange + high mid - fftCalc[11] = fftAddAvg(56,70); // 14 2412 - 3015 high mid - fftCalc[12] = fftAddAvg(70,86); // 16 3015 - 3704 high mid - fftCalc[13] = fftAddAvg(86,104); // 18 3704 - 4479 high mid - fftCalc[14] = fftAddAvg(104,165) * 0.88f; // 61 4479 - 7106 high mid + high -- with slight damping -#endif - } else { // noise gate closed - just decay old values - for (int i=0; i < NUM_GEQ_CHANNELS; i++) { - fftCalc[i] *= 0.85f; // decay to zero - if (fftCalc[i] < 4.0f) fftCalc[i] = 0.0f; + fftCalc[ 4] = fftAddAvg(7,9); // 3 301 - 430 midrange + fftCalc[ 5] = fftAddAvg(10,12); // 3 430 - 560 midrange + fftCalc[ 6] = fftAddAvg(13,18); // 5 560 - 818 midrange + fftCalc[ 7] = fftAddAvg(19,25); // 7 818 - 1120 midrange -- 1Khz should always be the center ! + fftCalc[ 8] = fftAddAvg(26,32); // 7 1120 - 1421 midrange + fftCalc[ 9] = fftAddAvg(33,43); // 9 1421 - 1895 midrange + fftCalc[10] = fftAddAvg(44,55); // 12 1895 - 2412 midrange + high mid + fftCalc[11] = fftAddAvg(56,69); // 14 2412 - 3015 high mid + fftCalc[12] = fftAddAvg(70,85); // 16 3015 - 3704 high mid + fftCalc[13] = fftAddAvg(86,103); // 18 3704 - 4479 high mid + fftCalc[14] = fftAddAvg(104,164) * 0.88f; // 61 4479 - 7106 high mid + high -- with slight damping + } + else if (freqDist == 1) { //WLEDMM: Rightshft: note ewowi: frequencies in comments are not correct + if (useBandPassFilter) { + // skip frequencies below 100hz + fftCalc[ 0] = 0.8f * fftAddAvg(1,1); + fftCalc[ 1] = 0.9f * fftAddAvg(2,2); + fftCalc[ 2] = fftAddAvg(3,3); + fftCalc[ 3] = fftAddAvg(4,4); + // don't use the last bins from 206 to 255. + fftCalc[15] = fftAddAvg(165,205) * 0.75f; // 40 7106 - 8828 high -- with some damping + } else { + fftCalc[ 0] = fftAddAvg(1,1); // 1 43 - 86 sub-bass + fftCalc[ 1] = fftAddAvg(2,2); // 1 86 - 129 bass + fftCalc[ 2] = fftAddAvg(3,3); // 2 129 - 216 bass + fftCalc[ 3] = fftAddAvg(4,4); // 2 216 - 301 bass + midrange + // don't use the last bins from 216 to 255. They are usually contaminated by aliasing (aka noise) + fftCalc[15] = fftAddAvg(165,215) * 0.70f; // 50 7106 - 9259 high -- with some damping } + fftCalc[ 4] = fftAddAvg(5,6); // 3 301 - 430 midrange + fftCalc[ 5] = fftAddAvg(7,8); // 3 430 - 560 midrange + fftCalc[ 6] = fftAddAvg(9,10); // 5 560 - 818 midrange + fftCalc[ 7] = fftAddAvg(11,13); // 7 818 - 1120 midrange -- 1Khz should always be the center ! + fftCalc[ 8] = fftAddAvg(14,18); // 7 1120 - 1421 midrange + fftCalc[ 9] = fftAddAvg(19,25); // 9 1421 - 1895 midrange + fftCalc[10] = fftAddAvg(26,36); // 12 1895 - 2412 midrange + high mid + fftCalc[11] = fftAddAvg(37,45); // 14 2412 - 3015 high mid + fftCalc[12] = fftAddAvg(46,66); // 16 3015 - 3704 high mid + fftCalc[13] = fftAddAvg(67,97); // 18 3704 - 4479 high mid + fftCalc[14] = fftAddAvg(98,164) * 0.88f; // 61 4479 - 7106 high mid + high -- with slight damping + } +#endif + } else { // noise gate closed - just decay old values + isFirstRun = false; + for (int i=0; i < NUM_GEQ_CHANNELS; i++) { + fftCalc[i] *= 0.85f; // decay to zero + if (fftCalc[i] < 4.0f) fftCalc[i] = 0.0f; + } + } + + memcpy(lastFftCalc, fftCalc, sizeof(lastFftCalc)); // make a backup of last "good" channels + + } else { // if second run skipped + memcpy(fftCalc, lastFftCalc, sizeof(fftCalc)); // restore last "good" channels } // post-processing of frequency channels (pink noise adjustment, AGC, smooting, scaling) if (pinkIndex > MAX_PINK) pinkIndex = MAX_PINK; //postProcessFFTResults((fabsf(sampleAvg) > 0.25f)? true : false , NUM_GEQ_CHANNELS); - postProcessFFTResults((fabsf(volumeSmth)>0.25f)? true : false , NUM_GEQ_CHANNELS); + postProcessFFTResults((fabsf(volumeSmth)>0.25f)? true : false , NUM_GEQ_CHANNELS); // this function modifies fftCalc, fftAvg and fftResult #if defined(WLED_DEBUG) || defined(SR_DEBUG)|| defined(SR_STATS) + static uint64_t lastLastFFT = 0; if (haveDoneFFT && (start < esp_timer_get_time())) { // filter out overflows uint64_t fftTimeInMillis = ((esp_timer_get_time() - start) +5ULL) / 10ULL; // "+5" to ensure proper rounding - fftTime = (fftTimeInMillis*3 + fftTime*7)/10; // smooth + fftTime = (((fftTimeInMillis + lastLastFFT)/2) *3 + fftTime*7)/10.0; // smart smooth + lastLastFFT = fftTimeInMillis; } #endif + // run peak detection autoResetPeak(); detectSamplePeak(); @@ -470,8 +624,13 @@ void FFTcode(void * parameter) #if !defined(I2S_GRAB_ADC1_COMPLETELY) if ((audioSource == nullptr) || (audioSource->getType() != AudioSource::Type_I2SAdc)) // the "delay trick" does not help for analog ADC #endif - vTaskDelayUntil( &xLastWakeTime, xFrequency); // release CPU, and let I2S fill its buffers - + { + if ((skipSecondFFT == false) || (fabsf(volumeSmth) < 0.25f)) { + vTaskDelayUntil( &xLastWakeTime, xFrequency); // release CPU, and let I2S fill its buffers + } else if (isFirstRun == true) { + vTaskDelayUntil( &xLastWakeTime, xFrequencyDouble); // release CPU after performing FFT in "skip second run" mode + } + } } // for(;;)ever } // FFTcode() task end @@ -488,10 +647,10 @@ static void runMicFilter(uint16_t numSamples, float *sampleBuffer) // p constexpr float alpha = 0.0225f; // 80hz //constexpr float alpha = 0.01693f;// 60hz // high frequency cutoff parameter - //constexpr float beta1 = 0.75; // 11Khz - //constexpr float beta1 = 0.82; // 15Khz - //constexpr float beta1 = 0.8285; // 18Khz - constexpr float beta1 = 0.85; // 20Khz + //constexpr float beta1 = 0.75f; // 11Khz + //constexpr float beta1 = 0.82f; // 15Khz + //constexpr float beta1 = 0.8285f; // 18Khz + constexpr float beta1 = 0.85f; // 20Khz constexpr float beta2 = (1.0f - beta1) / 2.0; static float last_vals[2] = { 0.0f }; // FIR high freq cutoff filter @@ -598,13 +757,14 @@ static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels) // p // peak detection is called from FFT task when vReal[] contains valid FFT results static void detectSamplePeak(void) { bool havePeak = false; - +#if 0 // Poor man's beat detection by seeing if sample > Average + some value. // This goes through ALL of the 255 bins - but ignores stupid settings // Then we got a peak, else we don't. The peak has to time out on its own in order to support UDP sound sync. if ((sampleAvg > 1) && (maxVol > 0) && (binNum > 1) && (vReal[binNum] > maxVol) && ((millis() - timeOfPeak) > 100)) { havePeak = true; } +#endif #if 0 // alternate detection, based on FFT_MajorPeak and FFT_Magnitude. Not much better... @@ -620,7 +780,6 @@ static void detectSamplePeak(void) { timeOfPeak = millis(); udpSamplePeak = true; } - } static void autoResetPeak(void) { @@ -708,7 +867,11 @@ class AudioReactive : public Usermod { }; // set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer) + #ifdef SR_ENABLE_DEFAULT + bool enabled = true; // WLEDMM + #else bool enabled = false; + #endif bool initDone = false; // variables for UDP sound sync @@ -724,7 +887,7 @@ class AudioReactive : public Usermod { // variables used by getSample() and agcAvg() int16_t micIn = 0; // Current sample starts with negative values and large values, which is why it's 16 bit signed double sampleMax = 0.0; // Max sample over a few seconds. Needed for AGC controler. - double micLev = 0.0f; // Used to convert returned value to have '0' as minimum. A leveller + double micLev = 0.0; // Used to convert returned value to have '0' as minimum. A leveller float expAdjF = 0.0f; // Used for exponential filter. float sampleReal = 0.0f; // "sampleRaw" as float, to provide bits that are lost otherwise (before amplification by sampleGain or inputLevel). Needed for AGC. int16_t sampleRaw = 0; // Current sample. Must only be updated ONCE!!! (amplified mic value by sampleGain and inputLevel) @@ -745,7 +908,9 @@ class AudioReactive : public Usermod { static const char _name[]; static const char _enabled[]; static const char _inputLvl[]; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) static const char _analogmic[]; +#endif static const char _digitalmic[]; static const char UDP_SYNC_HEADER[]; static const char UDP_SYNC_HEADER_v1[]; @@ -760,29 +925,36 @@ class AudioReactive : public Usermod { if (disableSoundProcessing && (!udpSyncConnected || ((audioSyncEnabled & 0x02) == 0))) return; // no audio availeable #ifdef MIC_LOGGER // Debugging functions for audio input and sound processing. Comment out the values you want to see - Serial.print("micReal:"); Serial.print(micDataReal); Serial.print("\t"); - Serial.print("volumeSmth:"); Serial.print(volumeSmth); Serial.print("\t"); - //Serial.print("volumeRaw:"); Serial.print(volumeRaw); Serial.print("\t"); - Serial.print("DC_Level:"); Serial.print(micLev); Serial.print("\t"); - //Serial.print("sampleAgc:"); Serial.print(sampleAgc); Serial.print("\t"); - //Serial.print("sampleAvg:"); Serial.print(sampleAvg); Serial.print("\t"); - //Serial.print("sampleReal:"); Serial.print(sampleReal); Serial.print("\t"); - //Serial.print("micIn:"); Serial.print(micIn); Serial.print("\t"); - //Serial.print("sample:"); Serial.print(sample); Serial.print("\t"); - //Serial.print("sampleMax:"); Serial.print(sampleMax); Serial.print("\t"); - //Serial.print("samplePeak:"); Serial.print((samplePeak!=0) ? 128:0); Serial.print("\t"); - //Serial.print("multAgc:"); Serial.print(multAgc, 4); Serial.print("\t"); - Serial.println(); + PLOT_PRINT("micMin:"); PLOT_PRINT(0.5f * micReal_min); PLOT_PRINT("\t"); // scaled down to 50%, for better readability + PLOT_PRINT("micMax:"); PLOT_PRINT(0.5f * micReal_max); PLOT_PRINT("\t"); // scaled down to 50% + //PLOT_PRINT("micAvg:"); PLOT_PRINT(0.5f * micReal_avg); PLOT_PRINT("\t"); // scaled down to 50% + //PLOT_PRINT("micDC:"); PLOT_PRINT(0.5f * (micReal_min + micReal_max)/2.0f);PLOT_PRINT("\t"); // scaled down to 50% + PLOT_PRINT("micReal:"); PLOT_PRINT(micDataReal + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + PLOT_PRINT("volumeSmth:"); PLOT_PRINT(volumeSmth + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + //PLOT_PRINT("volumeRaw:"); PLOT_PRINT(volumeRaw + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + PLOT_PRINT("DC_Level:"); PLOT_PRINT(micLev + 256.0f); PLOT_PRINT("\t"); // +256 to move above other lines + // //PLOT_PRINT("filtmicMin:"); PLOT_PRINT(0.5f * micReal_min2); PLOT_PRINT("\t"); // scaled down to 50% + // //PLOT_PRINT("filtmicMax:"); PLOT_PRINT(0.5f * micReal_max2); PLOT_PRINT("\t"); // scaled down to 50% + //PLOT_PRINT("sampleAgc:"); PLOT_PRINT(sampleAgc); PLOT_PRINT("\t"); + //PLOT_PRINT("sampleAvg:"); PLOT_PRINT(sampleAvg); PLOT_PRINT("\t"); + //PLOT_PRINT("sampleReal:"); PLOT_PRINT(sampleReal); PLOT_PRINT("\t"); + //PLOT_PRINT("micIn:"); PLOT_PRINT(micIn); PLOT_PRINT("\t"); + //PLOT_PRINT("sample:"); PLOT_PRINT(sample); PLOT_PRINT("\t"); + //PLOT_PRINT("sampleMax:"); PLOT_PRINT(sampleMax); PLOT_PRINT("\t"); + //PLOT_PRINT("samplePeak:"); PLOT_PRINT((samplePeak!=0) ? 128:0); PLOT_PRINT("\t"); + //PLOT_PRINT("multAgc:"); PLOT_PRINT(multAgc, 4); PLOT_PRINT("\t"); + PLOT_PRINTLN(); + PLOT_FLUSH(); #endif #ifdef FFT_SAMPLING_LOG #if 0 for(int i=0; i 0)? (soundAgc-1): 0; // make sure the _compiler_ knows this value will not change while we are inside the function + static bool isFrozen = false; + static bool haveSilence = true; + static unsigned long lastSoundTime = 0; // for delaying un-freeze + static unsigned long startuptime = 0; // "fast freeze" mode: do not interfere during first 12 seconds (filter startup time) #ifdef WLED_DISABLE_SOUND micIn = inoise8(millis(), millis()); // Simulated analog read @@ -955,13 +1132,15 @@ class AudioReactive : public Usermod { #endif #endif - //micLev = ((micLev * 8191.0f) + micDataReal) / 8192.0f; // takes a few seconds to "catch up" with the Mic Input - //if (useBandPassFilter) - // micLev += (micDataReal-micLev) / 8192.0f; // we expect some more fluctuations with mics that need pre-filtering - //else - micLev += (micDataReal-micLev) / 12288.0f; + if (startuptime == 0) startuptime = millis(); // fast freeze mode - remember filter startup time + if ((micLevelMethod < 1) || !isFrozen) { // following the input level, UNLESS mic Level was frozen + micLev += (micDataReal-micLev) / 12288.0f; + } - if(micIn < micLev) micLev = ((micLev * 31.0f) + micDataReal) / 32.0f; // align MicLev to lowest input signal + if(micDataReal < (micLev-0.24)) { // MicLev above input signal: + micLev = ((micLev * 31.0f) + micDataReal) / 32.0f; // always align MicLev to lowest input signal + if (!haveSilence) isFrozen = true; // freeze mode: freeze micLevel so it cannot rise again + } micIn -= micLev; // Let's center it to 0 now // Using an exponential filter to smooth out the signal. We'll add controls for this in a future release. @@ -974,10 +1153,26 @@ class AudioReactive : public Usermod { expAdjF = fabsf(expAdjF); // Now (!) take the absolute value + if ((micLevelMethod == 2) && !haveSilence && (expAdjF >= (1.5f * float(soundSquelch)))) + isFrozen = true; // fast freeze mode: freeze micLevel once the volume rises 50% above squelch + //expAdjF = (micInNoDC <= soundSquelch) ? 0: expAdjF; // simple noise gate - experimental expAdjF = (expAdjF <= soundSquelch) ? 0: expAdjF; // simple noise gate if ((soundSquelch == 0) && (expAdjF < 0.25f)) expAdjF = 0; // do something meaningfull when "squelch = 0" + if (expAdjF <= 0.5f) + haveSilence = true; + else { + lastSoundTime = millis(); + haveSilence = false; + } + + // un-freeze micLev + if (micLevelMethod == 0) isFrozen = false; + if ((micLevelMethod == 1) && isFrozen && haveSilence && ((millis() - lastSoundTime) > 4000)) isFrozen = false; // normal freeze: 4 seconds silence needed + if ((micLevelMethod == 2) && isFrozen && haveSilence && ((millis() - lastSoundTime) > 6000)) isFrozen = false; // fast freeze: 6 seconds silence needed + if ((micLevelMethod == 2) && (millis() - startuptime < 12000)) isFrozen = false; // fast freeze: no freeze in first 12 seconds (filter startup phase) + tmpSample = expAdjF; micIn = abs(micIn); // And get the absolute value of each sample @@ -1053,8 +1248,16 @@ class AudioReactive : public Usermod { static unsigned long last_connection_attempt = 0; if ((audioSyncPort <= 0) || ((audioSyncEnabled & 0x03) == 0)) return; // Sound Sync not enabled + if (!(apActive || WLED_CONNECTED || interfacesInited)) { + if (udpSyncConnected) { + udpSyncConnected = false; + fftUdp.stop(); + receivedFormat = 0; + DEBUGSR_PRINTLN(F("AR connectUDPSoundSync(): connection lost, UDP closed.")); + } + return; // neither AP nor other connections availeable + } if (udpSyncConnected) return; // already connected - if (!(apActive || interfacesInited)) return; // neither AP nor other connections availeable if (millis() - last_connection_attempt < 15000) return; // only try once in 15 seconds // if we arrive here, we need a UDP connection but don't have one @@ -1233,6 +1436,7 @@ class AudioReactive : public Usermod { case 0: //ADC analog #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) case 5: //PDM Microphone + case 51: //legacy PDM Microphone #endif #endif case 1: @@ -1270,6 +1474,13 @@ class AudioReactive : public Usermod { delay(100); if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin); break; + case 51: + DEBUGSR_PRINT(F("AR: Legacy PDM Microphone - ")); DEBUGSR_PRINTLN(F(I2S_PDM_MIC_CHANNEL_TEXT)); + audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE, 1.0f); + useBandPassFilter = true; + delay(100); + if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin); + break; #endif case 6: DEBUGSR_PRINTLN(F("AR: ES8388 Source")); @@ -1283,7 +1494,7 @@ class AudioReactive : public Usermod { case 0: default: DEBUGSR_PRINTLN(F("AR: Analog Microphone (left channel only).")); - //useBandPassFilter = true; + useBandPassFilter = true; audioSource = new I2SAdcSource(SAMPLE_RATE, BLOCK_SIZE); delay(100); if (audioSource) audioSource->initialize(audioPin); @@ -1301,11 +1512,17 @@ class AudioReactive : public Usermod { #ifdef WLED_DEBUG DEBUG_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings.")); #else - ERRORSR_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings.")); + USER_PRINTLN(F("AR: Failed to initialize sound input driver. Please check input PIN settings.")); #endif disableSoundProcessing = true; + } else { + USER_PRINTLN(F("AR: sound input driver initialized successfully.")); } + // try to start UDP + last_UDPTime = 0; + receivedFormat = 0; + delay(100); if (enabled) connectUDPSoundSync(); initDone = true; } @@ -1320,6 +1537,8 @@ class AudioReactive : public Usermod { if (udpSyncConnected) { // clean-up: if open, close old UDP sync connection udpSyncConnected = false; fftUdp.stop(); + receivedFormat = 0; + DEBUGSR_PRINTLN(F("AR connected(): old UDP connection closed.")); } if (audioSyncPort > 0 && (audioSyncEnabled & 0x03)) { @@ -1328,6 +1547,13 @@ class AudioReactive : public Usermod { #else udpSyncConnected = fftUdp.beginMulticast(WiFi.localIP(), IPAddress(239, 0, 0, 1), audioSyncPort); #endif + receivedFormat = 0; + if (udpSyncConnected) last_UDPTime = millis(); + if (apActive && !(WLED_CONNECTED)) { + DEBUGSR_PRINTLN(udpSyncConnected ? F("AR connected(): UDP: connected using AP.") : F("AR connected(): UDP is disconnected (AP).")); + } else { + DEBUGSR_PRINTLN(udpSyncConnected ? F("AR connected(): UDP: connected to WIFI.") : F("AR connected(): UDP is disconnected (Wifi).")); + } } } @@ -1393,10 +1619,10 @@ class AudioReactive : public Usermod { int userloopDelay = int(t_now - lastUMRun); if (lastUMRun == 0) userloopDelay=0; // startup - don't have valid data from last run. - #ifdef WLED_DEBUG + #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) // complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second. - if ((userloopDelay > 23) && !disableSoundProcessing && (audioSyncEnabled == 0)) { - DEBUG_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay); + if ((userloopDelay > /*23*/ 65) && !disableSoundProcessing && (audioSyncEnabled == 0)) { + USER_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay); } #endif @@ -1439,6 +1665,22 @@ class AudioReactive : public Usermod { if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample else volumeSmth = syncVolumeSmth; // restore originally received sample for next run of dynamics limiter limitSampleDynamics(); // run dynamics limiter on received volumeSmth, to hide jumps and hickups + } else { + receivedFormat = 0; + } + + if ( (audioSyncEnabled & 0x02) // receive mode + && udpSyncConnected // connected + && (receivedFormat > 0) // we actually received something in the past + && ((millis() - last_UDPTime) > 25000)) { // close connection after 25sec idle + udpSyncConnected = false; + receivedFormat = 0; + fftUdp.stop(); + volumeSmth =0.0f; + volumeRaw =0; + my_magnitude = 0.1; FFT_Magnitude = 0.01; FFT_MajorPeak = 2; + multAgc = 1; + DEBUGSR_PRINTLN(F("AR loop(): UDP closed due to inactivity.")); } #if defined(MIC_LOGGER) || defined(MIC_SAMPLING_LOG) || defined(FFT_SAMPLING_LOG) @@ -1500,10 +1742,13 @@ class AudioReactive : public Usermod { autoResetPeak(); if (init && FFT_Task) { + delay(25); // WLEDMM: givesome time for I2S driver to finish sampling vTaskSuspend(FFT_Task); // update is about to begin, disable task to prevent crash if (udpSyncConnected) { // close UDP sync connection (if open) udpSyncConnected = false; fftUdp.stop(); + DEBUGSR_PRINTLN(F("AR onUpdateBegin(true): UDP connection closed.")); + receivedFormat = 0; } } else { // update has failed or create task requested @@ -1512,14 +1757,15 @@ class AudioReactive : public Usermod { connected(); // resume UDP } else // xTaskCreatePinnedToCore( - xTaskCreate( // no need to "pin" this task to core #0 +// xTaskCreate( // no need to "pin" this task to core #0 + xTaskCreateUniversal( FFTcode, // Function to implement the task "FFT", // Name of the task 5000, // Stack size in words NULL, // Task input parameter 1, // Priority of the task &FFT_Task // Task handle -// , 0 // Core where the task should run + , 0 // Core where the task should run ); } micDataReal = 0.0f; // just to be sure @@ -1619,7 +1865,10 @@ class AudioReactive : public Usermod { if (audioSource->getType() == AudioSource::Type_I2SAdc) { infoArr.add(F("ADC analog")); } else { - infoArr.add(F("I2S digital")); + if (dmType != 51) + infoArr.add(F("I2S digital")); + else + infoArr.add(F("legacy I2S PDM")); } // input level or "silence" if (maxSample5sec > 1.0) { @@ -1632,7 +1881,7 @@ class AudioReactive : public Usermod { } else { // error during audio source setup infoArr.add(F("not initialized")); - infoArr.add(F(" - check GPIO config")); + infoArr.add(F(" - check pin settings")); } } @@ -1675,12 +1924,16 @@ class AudioReactive : public Usermod { } #if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS) + infoArr = user.createNestedArray(F("I2S cycle time")); + infoArr.add(roundf(fftTaskCycle)/100.0f); + infoArr.add(" ms"); + infoArr = user.createNestedArray(F("Sampling time")); - infoArr.add(float(sampleTime)/100.0f); + infoArr.add(roundf(sampleTime)/100.0f); infoArr.add(" ms"); infoArr = user.createNestedArray(F("FFT time")); - infoArr.add(float(fftTime)/100.0f); + infoArr.add(roundf(fftTime)/100.0f); if ((fftTime/100) >= FFT_MIN_CYCLE) // FFT time over budget -> I2S buffer will overflow infoArr.add("! ms"); else if ((fftTime/80 + sampleTime/80) >= FFT_MIN_CYCLE) // FFT time >75% of budget -> risk of instability @@ -1688,8 +1941,9 @@ class AudioReactive : public Usermod { else infoArr.add(" ms"); - DEBUGSR_PRINTF("AR Sampling time: %5.2f ms\n", float(sampleTime)/100.0f); - DEBUGSR_PRINTF("AR FFT time : %5.2f ms\n", float(fftTime)/100.0f); + DEBUGSR_PRINTF("AR I2S cycle time: %5.2f ms\n", roundf(fftTaskCycle)/100.0f); + DEBUGSR_PRINTF("AR Sampling time : %5.2f ms\n", roundf(sampleTime)/100.0f); + DEBUGSR_PRINTF("AR FFT time : %5.2f ms\n", roundf(fftTime)/100.0f); #endif } } @@ -1774,7 +2028,7 @@ class AudioReactive : public Usermod { #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) JsonObject amic = top.createNestedObject(FPSTR(_analogmic)); amic["pin"] = audioPin; -#endif + #endif JsonObject dmic = top.createNestedObject(FPSTR(_digitalmic)); dmic[F("type")] = dmType; @@ -1791,6 +2045,12 @@ class AudioReactive : public Usermod { cfg[F("gain")] = sampleGain; cfg[F("AGC")] = soundAgc; + //WLEDMM: experimental settings + JsonObject poweruser = top.createNestedObject("experiments"); + poweruser[F("micLev")] = micLevelMethod; + poweruser[F("freqDist")] = freqDist; + poweruser[F("freqRMS")] = averageByRMS; + JsonObject dynLim = top.createNestedObject("dynamics"); dynLim[F("limiter")] = limiterOn; dynLim[F("rise")] = attackTime; @@ -1798,7 +2058,7 @@ class AudioReactive : public Usermod { JsonObject freqScale = top.createNestedObject("frequency"); freqScale[F("scale")] = FFTScalingMode; - freqScale[F("profile")] = pinkIndex; + freqScale[F("profile")] = pinkIndex; //WLEDMM JsonObject sync = top.createNestedObject("sync"); sync[F("port")] = audioSyncPort; @@ -1839,7 +2099,11 @@ class AudioReactive : public Usermod { if (dmType == 0) dmType = SR_DMTYPE; // MCU does not support analog #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) if (dmType == 5) dmType = SR_DMTYPE; // MCU does not support PDM + if (dmType == 51) dmType = SR_DMTYPE; // MCU does not support legacy PDM #endif + #else + if (dmType == 5) useBandPassFilter = true; // enable filter for PDM + if (dmType == 51) useBandPassFilter = true /*false*/; // switch on filter for legacy PDM #endif configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][0], i2ssdPin); @@ -1853,12 +2117,17 @@ class AudioReactive : public Usermod { configComplete &= getJsonValue(top["config"][F("gain")], sampleGain); configComplete &= getJsonValue(top["config"][F("AGC")], soundAgc); + //WLEDMM: experimental settings + configComplete &= getJsonValue(top["experiments"][F("micLev")], micLevelMethod); + configComplete &= getJsonValue(top["experiments"][F("freqDist")], freqDist); + configComplete &= getJsonValue(top["experiments"][F("freqRMS")], averageByRMS); + configComplete &= getJsonValue(top["dynamics"][F("limiter")], limiterOn); configComplete &= getJsonValue(top["dynamics"][F("rise")], attackTime); configComplete &= getJsonValue(top["dynamics"][F("fall")], decayTime); configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode); - configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex); + configComplete &= getJsonValue(top["frequency"][F("profile")], pinkIndex); //WLEDMM configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort); configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled); @@ -1869,24 +2138,88 @@ class AudioReactive : public Usermod { void appendConfigData() { + oappend(SET_F("addInfo('AudioReactive:help',0,'');")); + + //WLEDMM: add defaults + #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) // -S3/-S2/-C3 don't support analog audio + #ifdef AUDIOPIN + oappend(SET_F("xOpt('AudioReactive:analogmic:pin',1,' ⎌',")); oappendi(AUDIOPIN); oappend(");"); + #endif + oappend(SET_F("aOpt('AudioReactive:analogmic:pin',1);")); //only analog options + #endif + oappend(SET_F("dd=addDropdown('AudioReactive','digitalmic:type');")); - #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - oappend(SET_F("addOption(dd,'Generic Analog',0);")); - #endif - oappend(SET_F("addOption(dd,'Generic I2S',1);")); - oappend(SET_F("addOption(dd,'ES7243',2);")); - oappend(SET_F("addOption(dd,'SPH0654',3);")); - oappend(SET_F("addOption(dd,'Generic I2S with Mclk',4);")); - #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) - oappend(SET_F("addOption(dd,'Generic I2S PDM',5);")); - #endif + #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) + #if SR_DMTYPE==0 + oappend(SET_F("addOption(dd,'Generic Analog (⎌)',0);")); + #else + oappend(SET_F("addOption(dd,'Generic Analog',0);")); + #endif + #endif + #if SR_DMTYPE==1 + oappend(SET_F("addOption(dd,'Generic I2S (⎌)',1);")); + #else + oappend(SET_F("addOption(dd,'Generic I2S',1);")); + #endif + #if SR_DMTYPE==2 + oappend(SET_F("addOption(dd,'ES7243 (⎌)',2);")); + #else + oappend(SET_F("addOption(dd,'ES7243',2);")); + #endif + #if SR_DMTYPE==3 + oappend(SET_F("addOption(dd,'SPH0654 (⎌)',3);")); + #else + oappend(SET_F("addOption(dd,'SPH0654',3);")); + #endif + #if SR_DMTYPE==4 + oappend(SET_F("addOption(dd,'Generic I2S with Mclk (⎌)',4);")); + #else + oappend(SET_F("addOption(dd,'Generic I2S with Mclk',4);")); + #endif + #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + #if SR_DMTYPE==5 + oappend(SET_F("addOption(dd,'Generic I2S PDM (⎌)',5);")); + #else + oappend(SET_F("addOption(dd,'Generic I2S PDM',5);")); + #endif + #if SR_DMTYPE==51 + oappend(SET_F("addOption(dd,'.Legacy I2S PDM ☾ (⎌)',51);")); + #else + oappend(SET_F("addOption(dd,'.Legacy I2S PDM ☾',51);")); + #endif + #endif oappend(SET_F("addOption(dd,'ES8388',6);")); + + #ifdef SR_SQUELCH + oappend(SET_F("addInfo('AudioReactive:config:squelch',1,'⎌ ")); oappendi(SR_SQUELCH); oappend("');"); // 0 is field type, 1 is actual field + #endif + #ifdef SR_GAIN + oappend(SET_F("addInfo('AudioReactive:config:gain',1,'⎌ ")); oappendi(SR_GAIN); oappend("');"); // 0 is field type, 1 is actual field + #endif + oappend(SET_F("dd=addDropdown('AudioReactive','config:AGC');")); oappend(SET_F("addOption(dd,'Off',0);")); oappend(SET_F("addOption(dd,'Normal',1);")); oappend(SET_F("addOption(dd,'Vivid',2);")); oappend(SET_F("addOption(dd,'Lazy',3);")); + //WLEDMM: experimental settings + oappend(SET_F("dd=addDropdown('AudioReactive','experiments:micLev');")); + oappend(SET_F("addOption(dd,'Floating (⎌)',0);")); + oappend(SET_F("addOption(dd,'Freeze',1);")); + oappend(SET_F("addOption(dd,'Fast Freeze',2);")); + oappend(SET_F("addInfo('AudioReactive:experiments:micLev',1,'☾');")); + + oappend(SET_F("dd=addDropdown('AudioReactive','experiments:freqDist');")); + oappend(SET_F("addOption(dd,'Normal (⎌)',0);")); + oappend(SET_F("addOption(dd,'RightShift',1);")); + oappend(SET_F("addInfo('AudioReactive:experiments:freqDist',1,'☾');")); + + oappend(SET_F("dd=addDropdown('AudioReactive','experiments:freqRMS');")); + oappend(SET_F("addOption(dd,'Off (⎌)',0);")); + oappend(SET_F("addOption(dd,'On',1);")); + oappend(SET_F("addInfo('AudioReactive:experiments:freqRMS',1,'☾');")); + oappend(SET_F("dd=addDropdown('AudioReactive','dynamics:limiter');")); oappend(SET_F("addOption(dd,'Off',0);")); oappend(SET_F("addOption(dd,'On',1);")); @@ -1900,34 +2233,110 @@ class AudioReactive : public Usermod { oappend(SET_F("addOption(dd,'Square Root (Energy)',3);")); oappend(SET_F("addOption(dd,'Logarithmic (Loudness)',1);")); + //WLEDMM add defaults oappend(SET_F("dd=addDropdown('AudioReactive','frequency:profile');")); - oappend(SET_F("addOption(dd,'Generic Microphone',0);")); - oappend(SET_F("addOption(dd,'Generic Line-In',1);")); - oappend(SET_F("addOption(dd,'ICS-43434',5);")); - oappend(SET_F("addOption(dd,'ICS-43434 - big speakers',6);")); - oappend(SET_F("addOption(dd,'SPM1423',7);")); - oappend(SET_F("addOption(dd,'IMNP441',2);")); - oappend(SET_F("addOption(dd,'IMNP441 - big speakers',3);")); - oappend(SET_F("addOption(dd,'IMNP441 - small speakers',4);")); - oappend(SET_F("addOption(dd,'flat - no adjustments',10);")); - oappend(SET_F("addOption(dd,'userdefined #1',8);")); - oappend(SET_F("addOption(dd,'userdefined #2',9);")); + #if SR_FREQ_PROF==0 + oappend(SET_F("addOption(dd,'Generic Microphone (⎌)',0);")); + #else + oappend(SET_F("addOption(dd,'Generic Microphone',0);")); + #endif + #if SR_FREQ_PROF==1 + oappend(SET_F("addOption(dd,'Generic Line-In (⎌)',1);")); + #else + oappend(SET_F("addOption(dd,'Generic Line-In',1);")); + #endif + #if SR_FREQ_PROF==5 + oappend(SET_F("addOption(dd,'ICS-43434 (⎌)',5);")); + #else + oappend(SET_F("addOption(dd,'ICS-43434',5);")); + #endif + #if SR_FREQ_PROF==6 + oappend(SET_F("addOption(dd,'ICS-43434 - big speakers (⎌)',6);")); + #else + oappend(SET_F("addOption(dd,'ICS-43434 - big speakers',6);")); + #endif + #if SR_FREQ_PROF==7 + oappend(SET_F("addOption(dd,'SPM1423 (⎌)',7);")); + #else + oappend(SET_F("addOption(dd,'SPM1423',7);")); + #endif + #if SR_FREQ_PROF==2 + oappend(SET_F("addOption(dd,'IMNP441 (⎌)',2);")); + #else + oappend(SET_F("addOption(dd,'IMNP441',2);")); + #endif + #if SR_FREQ_PROF==3 + oappend(SET_F("addOption(dd,'IMNP441 - big speakers (⎌)',3);")); + #else + oappend(SET_F("addOption(dd,'IMNP441 - big speakers',3);")); + #endif + #if SR_FREQ_PROF==4 + oappend(SET_F("addOption(dd,'IMNP441 - small speakers (⎌)',4);")); + #else + oappend(SET_F("addOption(dd,'IMNP441 - small speakers',4);")); + #endif + #if SR_FREQ_PROF==10 + oappend(SET_F("addOption(dd,'flat - no adjustments (⎌)',10);")); + #else + oappend(SET_F("addOption(dd,'flat - no adjustments',10);")); + #endif + #if SR_FREQ_PROF==8 + oappend(SET_F("addOption(dd,'userdefined #1 (⎌)',8);")); + #else + oappend(SET_F("addOption(dd,'userdefined #1',8);")); + #endif + #if SR_FREQ_PROF==9 + oappend(SET_F("addOption(dd,'userdefined #2 (⎌)',9);")); + #else + oappend(SET_F("addOption(dd,'userdefined #2',9);")); + #endif + oappend(SET_F("addInfo('AudioReactive:frequency:profile',1,'☾');")); oappend(SET_F("dd=addDropdown('AudioReactive','sync:mode');")); oappend(SET_F("addOption(dd,'Off',0);")); oappend(SET_F("addOption(dd,'Send',1);")); oappend(SET_F("addOption(dd,'Receive',2);")); oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'requires reboot!');")); // 0 is field type, 1 is actual field - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S Serial Data', 'sd/data/dout');")); - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S L/R Clock','ws/clk/lrck');")); - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S Serial Clock','sck/bclk');")); - #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','only use -1, 0, 1 or 3');")); - #else - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','');")); + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'sd/data/dout','I2S SD');")); + #ifdef I2S_SDPIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',0,' ⎌',")); oappendi(I2S_SDPIN); oappend(");"); #endif - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'I2C SDA',' ');")); - oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'I2C SCL',' ');")); + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'ws/clk/lrck','I2S WS');")); + oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',1);")); // disable read only pins + #ifdef I2S_WSPIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',1,' ⎌',")); oappendi(I2S_WSPIN); oappend(");"); + #endif + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'sck/bclk','I2S SCK');")); + oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',2);")); // disable read only pins + #ifdef I2S_CKPIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',2,' ⎌',")); oappendi(I2S_CKPIN); oappend(");"); + #endif + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'master clock','I2S MCLK');")); + oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',3);")); // disable read only pins + #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) + oappend(SET_F("dOpt('AudioReactive:digitalmic:pin[]',3,2,2);")); //only use -1, 0, 1 or 3 + oappend(SET_F("dOpt('AudioReactive:digitalmic:pin[]',3,4,39);")); //only use -1, 0, 1 or 3 + #endif + #ifdef MCLK_PIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',3,' ⎌',")); oappendi(MCLK_PIN); oappend(");"); + #endif + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'','I2C SDA');")); + oappend(SET_F("rOpt('AudioReactive:digitalmic:pin[]',4,'use global (")); oappendi(i2c_sda); oappend(")',-1);"); + #ifdef ES7243_SDAPIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',4,' ⎌',")); oappendi(ES7243_SDAPIN); oappend(");"); + #endif + + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'','I2C SCL');")); + oappend(SET_F("rOpt('AudioReactive:digitalmic:pin[]',5,'use global (")); oappendi(i2c_scl); oappend(")',-1);"); + #ifdef ES7243_SCLPIN + oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',5,' ⎌',")); oappendi(ES7243_SCLPIN); oappend(");"); + #endif + oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',5);")); // disable read only pins } @@ -1956,7 +2365,9 @@ class AudioReactive : public Usermod { const char AudioReactive::_name[] PROGMEM = "AudioReactive"; const char AudioReactive::_enabled[] PROGMEM = "enabled"; const char AudioReactive::_inputLvl[] PROGMEM = "inputLevel"; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) const char AudioReactive::_analogmic[] PROGMEM = "analogmic"; +#endif const char AudioReactive::_digitalmic[] PROGMEM = "digitalmic"; const char AudioReactive::UDP_SYNC_HEADER[] PROGMEM = "00002"; // new sync header version, as format no longer compatible with previous structure const char AudioReactive::UDP_SYNC_HEADER_v1[] PROGMEM = "00001"; // old sync header version - need to add backwards-compatibility feature diff --git a/usermods/audioreactive/audio_source.h b/usermods/audioreactive/audio_source.h index a1cd1eda..b65bd741 100644 --- a/usermods/audioreactive/audio_source.h +++ b/usermods/audioreactive/audio_source.h @@ -24,14 +24,14 @@ // see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents // and https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/i2s.html#overview-of-all-modes -#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(ESP8266) || defined(ESP8265) +#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) || defined(ESP8266) || defined(ESP8265) // there are two things in these MCUs that could lead to problems with audio processing: // * no floating point hardware (FPU) support - FFT uses float calculations. If done in software, a strong slow-down can be expected (between 8x and 20x) // * single core, so FFT task might slow down other things like LED updates #if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1) - #error This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2. + #error This audio reactive usermod does not support ESP32-C2 or ESP32-C3. #else - #warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2. + #warning This audio reactive usermod does not support ESP32-C2 and ESP32-C3. #endif #endif @@ -219,10 +219,15 @@ class I2SSource : public AudioSource { #endif #endif #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) - // example from espressif: https://github.com/espressif/esp-idf/blob/release/v4.4/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c // This is an I2S PDM microphone, these microphones only use a clock and - // data line, to make it simpler to debug, use the WS pin as CLK and SD - // pin as DATA + // data line, to make it simpler to debug, use the WS pin as CLK and SD pin as DATA + // example from espressif: https://github.com/espressif/esp-idf/blob/release/v4.4/examples/peripherals/i2s/i2s_audio_recorder_sdcard/main/i2s_recorder_main.c + + // note to self: PDM has known bugs on S3, and does not work on C3 + // * S3: PDM sample rate only at 50% of expected rate: https://github.com/espressif/esp-idf/issues/9893 + // * S3: I2S PDM has very low amplitude: https://github.com/espressif/esp-idf/issues/8660 + // * C3: does not support PDM to PCM input. SoC would allow PDM RX, but there is no hardware to directly convert to PCM so it will not work. https://github.com/espressif/esp-idf/issues/8796 + _config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); // Change mode to pdm if clock pin not provided. PDM is not supported on ESP32-S2. PDM RX not supported on ESP32-C3 _config.channel_format =I2S_PDM_MIC_CHANNEL; // seems that PDM mono mode always uses left channel. _config.use_apll = true; // experimental - use aPLL clock source to improve sampling quality @@ -425,7 +430,7 @@ class ES7243 : public I2SSource { Wire.write((uint8_t)val); uint8_t i2cErr = Wire.endTransmission(); // i2cErr == 0 means OK if (i2cErr != 0) { - DEBUGSR_PRINTF("AR: ES7243 I2C write failed with error=%d (addr=0x%X, reg 0x%X, val 0x%X).\n", ES7243_ADDR, i2cErr, reg, val); + DEBUGSR_PRINTF("AR: ES7243 I2C write failed with error=%d (addr=0x%X, reg 0x%X, val 0x%X).\n", i2cErr, ES7243_ADDR, reg, val); } } @@ -669,7 +674,7 @@ class I2SAdcSource : public I2SSource { // Determine Analog channel. Only Channels on ADC1 are supported int8_t channel = digitalPinToAnalogChannel(_audioPin); if (channel > 9) { - ERRORSR_PRINTF("Incompatible GPIO used for analog audio input: %d\n", _audioPin); + USER_PRINTF("AR: Incompatible GPIO used for analog audio input: %d\n", _audioPin); return; } else { adc_gpio_init(ADC_UNIT_1, adc_channel_t(channel)); @@ -688,7 +693,7 @@ class I2SAdcSource : public I2SSource { // Enable I2S mode of ADC err = i2s_set_adc_mode(ADC_UNIT_1, adc1_channel_t(channel)); if (err != ESP_OK) { - DEBUGSR_PRINTF("Failed to set i2s adc mode: %d\n", err); + USER_PRINTF("AR: Failed to set i2s adc mode: %d\n", err); return; } diff --git a/usermods/audioreactive/readme.md b/usermods/audioreactive/readme.md index 59e8e37d..d9f9ea78 100644 --- a/usermods/audioreactive/readme.md +++ b/usermods/audioreactive/readme.md @@ -1,36 +1,73 @@ # Audioreactive usermod -This usermod allows controlling LEDs using audio input. Audio input can be either microphone or analog-in (AUX) using appropriate adapter. +Enabless controlling LEDs via audio input. Audio source can be a microphone or analog-in (AUX) using an appropriate adapter. Supported microphones range from analog (MAX4466, MAX9814, ...) to digital (INMP441, ICS-43434, ...). -The usermod does audio processing and provides data structure that specially written effect can use. +Does audio processing and provides data structure that specially written effects can use. -The usermod **does not** provide effects or draws anything to LED strip/matrix. +**does not** provide effects or draw anything to an LED strip/matrix. +## Additional Documentation +This usermod is an evolution of [SR-WLED](https://github.com/atuline/WLED), and a lot of documentation and information can be found in the [SR-WLED wiki](https://github.com/atuline/WLED/wiki): +* [getting started with audio](https://github.com/atuline/WLED/wiki/First-Time-Setup#sound) +* [Sound settings](https://github.com/atuline/WLED/wiki/Sound-Settings) - similar to options on the usemod settings page in WLED. +* [Digital Audio](https://github.com/atuline/WLED/wiki/Digital-Microphone-Hookup) +* [Analog Audio](https://github.com/atuline/WLED/wiki/Analog-Audio-Input-Options) +* [UDP Sound sync](https://github.com/atuline/WLED/wiki/UDP-Sound-Sync) + + +## Supported MCUs +This audioreactive usermod works best on "classic ESP32" (dual core), and on ESP32-S3 which also has dual core and hardware floating point support. + +It will compile succesfully for ESP32-S2 and ESP32-C3, however might not work well, as other WLED functions will become slow. Audio processing requires a lot of computing power, which can be problematic on smaller MCUs like -S2 and -C3. + +Analog audio is only possible on "classic" ESP32, but not on other MCUs like ESP32-S3. + +Currently ESP8266 is not supported, due to low speed and small RAM of this chip. +There are however plans to create a lightweight audioreactive for the 8266, with reduced features. ## Installation -Add `-D USERMOD_AUDIOREACTIVE` to your PlatformIO environment as well as `arduinoFFT` to your `lib_deps`. +### using customised _arduinoFFT_ library for use with this usermod +Add `-D USERMOD_AUDIOREACTIVE` to your PlatformIO environment `build_flags`, as well as `https://github.com/blazoncek/arduinoFFT.git` to your `lib_deps`. If you are not using PlatformIO (which you should) try adding `#define USERMOD_AUDIOREACTIVE` to *my_config.h* and make sure you have _arduinoFFT_ library downloaded and installed. Customised _arduinoFFT_ library for use with this usermod can be found at https://github.com/blazoncek/arduinoFFT.git +### using latest (develop) _arduinoFFT_ library +Alternatively, you can use the latest arduinoFFT development version. +ArduinoFFT `develop` library is slightly more accurate, and slighly faster than our customised library, however also needs additional 2kB RAM. + +* `build_flags` = `-D USERMOD_AUDIOREACTIVE` `-D UM_AUDIOREACTIVE_USE_NEW_FFT` +* `lib_deps`= `https://github.com/kosme/arduinoFFT#develop @ 1.9.2` + ## Configuration -All parameters are runtime configurable though some may require hard boot after change (I2S microphone or selected GPIOs). +All parameters are runtime configurable. Some may require a hard reset after changing them (I2S microphone or selected GPIOs). -If you want to define default GPIOs during compile time use the following (default values in parentheses): +If you want to define default GPIOs during compile time, use the following (default values in parentheses): -- `SR_DMTYPE=x` : defines digital microphone type: 0=analog, 1=generic I2S, 2=ES7243 I2S, 3=SPH0645 I2S, 4=generic I2S with master clock, 5=PDM I2S -- `AUDIOPIN=x` : GPIO for analog microphone/AUX-in (36) -- `I2S_SDPIN=x` : GPIO for SD pin on digital mcrophone (32) -- `I2S_WSPIN=x` : GPIO for WS pin on digital mcrophone (15) -- `I2S_CKPIN=x` : GPIO for SCK pin on digital mcrophone (14) -- `ES7243_SDAPIN` : GPIO for I2C SDA pin on ES7243 microphone (-1) -- `ES7243_SCLPIN` : GPIO for I2C SCL pin on ES7243 microphone (-1) -- `MCLK_PIN=x` : GPIO for master clock pin on digital mcrophone (-1) +- `-D SR_DMTYPE=x` : defines digital microphone type: 0=analog, 1=generic I2S (default), 2=ES7243 I2S, 3=SPH0645 I2S, 4=generic I2S with master clock, 5=PDM I2S +- `-D AUDIOPIN=x` : GPIO for analog microphone/AUX-in (36) +- `-D I2S_SDPIN=x` : GPIO for SD pin on digital microphone (32) +- `-D I2S_WSPIN=x` : GPIO for WS pin on digital microphone (15) +- `-D I2S_CKPIN=x` : GPIO for SCK pin on digital microphone (14) +- `-D MCLK_PIN=x` : GPIO for master clock pin on digital Line-In boards (-1) +- `-D ES7243_SDAPIN` : GPIO for I2C SDA pin on ES7243 microphone (-1) +- `-D ES7243_SCLPIN` : GPIO for I2C SCL pin on ES7243 microphone (-1) -**NOTE** Due to the fact that usermod uses I2S peripherial for analog audio sampling, use of analog *buttons* (i.e. potentiometers) is disabled while running this usermod with analog microphone. +**NOTE** I2S is used for analog audio sampling. Hence, the analog *buttons* (i.e. potentiometers) are disabled when running this usermod with an analog microphone. + +### Advanced Compile-Time Options +You can use the following additional flags in your `build_flags` +* `-D SR_SQUELCH=x` : Default "squelch" setting (10) +* `-D SR_GAIN=x` : Default "gain" setting (60) +* `-D I2S_USE_RIGHT_CHANNEL`: Use RIGHT instead of LEFT channel (not recommended unless you strictly need this). +* `-D I2S_USE_16BIT_SAMPLES`: Use 16bit instead of 32bit for internal sample buffers. Reduces sampling quality, but frees some RAM ressources (not recommended unless you absolutely need this). +* `-D I2S_GRAB_ADC1_COMPLETELY`: Experimental: continously sample analog ADC microphone. Only effective on ESP32. WARNING this _will_ cause conflicts(lock-up) with any analogRead() call. +* `-D MIC_LOGGER` : (debugging) Logs samples from the microphone to serial USB. Use with serial plotter (Arduino IDE) +* `-D SR_DEBUG` : (debugging) Additional error diagnostics and debug info on serial USB. ## Release notes -2022-06 Ported from [soundreactive](https://github.com/atuline/WLED) by @blazoncek (AKA Blaz Kristan) +* 2022-06 Ported from [soundreactive WLED](https://github.com/atuline/WLED) - by @blazoncek (AKA Blaz Kristan) and the [SR-WLED team](https://github.com/atuline/WLED/wiki#sound-reactive-wled-fork-team). +* 2022-11 Updated to align with "[MoonModules/WLED](https://amg.wled.me)" audioreactive usermod - by @softhack007 (AKA Frank Möhle). diff --git a/usermods/battery_status_basic/assets/battery_info_screen.png b/usermods/battery_status_basic/assets/battery_info_screen.png deleted file mode 100644 index 50eb5346..00000000 Binary files a/usermods/battery_status_basic/assets/battery_info_screen.png and /dev/null differ diff --git a/usermods/battery_status_basic/readme.md b/usermods/battery_status_basic/readme.md deleted file mode 100644 index 276b23c1..00000000 --- a/usermods/battery_status_basic/readme.md +++ /dev/null @@ -1,69 +0,0 @@ -# :battery: Battery status/level Usermod :battery: - -This Usermod allows you to monitor the battery level of your battery powered project. - -You can see the battery level and voltage in the `info modal`. - -For this to work the positive side of the (18650) battery must be connected to pin `A0` of the d1mini/esp8266 with a 100k ohm resistor (see [Useful Links](#useful-links)). - -If you have a esp32 board it is best to connect the positive side of the battery to ADC1 (GPIO32 - GPIO39) - -

- -

- -## Installation - -define `USERMOD_BATTERY_STATUS_BASIC` in `my_config.h` - -### Basic wiring diagram -

- -

- -### Define Your Options - -* `USERMOD_BATTERY_STATUS_BASIC` - define this (in `my_config.h`) to have this user mod included wled00\usermods_list.cpp -* `USERMOD_BATTERY_MEASUREMENT_PIN` - defaults to A0 on esp8266 and GPIO32 on esp32 -* `USERMOD_BATTERY_MEASUREMENT_INTERVAL` - the frequency to check the battery, defaults to 30 seconds -* `USERMOD_BATTERY_MIN_VOLTAGE` - minimum voltage of the Battery used, default is 2.6 (18650 battery standard) -* `USERMOD_BATTERY_MAX_VOLTAGE` - maximum voltage of the Battery used, default is 4.2 (18650 battery standard) - -All parameters can be configured at runtime using Usermods settings page. - -## Important :warning: -* Make sure you know your battery specification ! not every battery is the same ! -* Example: - -| Your battery specification table | | Options you can define | -| :-------------------------------- |:--------------- | :---------------------------- | -| Capacity | 3500mAh 12,5 Wh | | -| Minimum capacity | 3350mAh 11,9 Wh | | -| Rated voltage | 3.6V - 3.7V | | -| **Charging end voltage** | **4,2V ± 0,05** | `USERMOD_BATTERY_MAX_VOLTAGE` | -| **Discharge voltage** | **2,5V** | `USERMOD_BATTERY_MIN_VOLTAGE` | -| Max. discharge current (constant) | 10A (10000mA) | | -| max. charging current | 1.7A (1700mA) | | -| ... | ... | ... | -| .. | .. | .. | - -Specification from: [Molicel INR18650-M35A, 3500mAh 10A Lithium-ion battery, 3.6V - 3.7V](https://www.akkuteile.de/lithium-ionen-akkus/18650/molicel/molicel-inr18650-m35a-3500mah-10a-lithium-ionen-akku-3-6v-3-7v_100833) - -## Useful Links -* https://lazyzero.de/elektronik/esp8266/wemos_d1_mini_a0/start -* https://arduinodiy.wordpress.com/2016/12/25/monitoring-lipo-battery-voltage-with-wemos-d1-minibattery-shield-and-thingspeak/ - -## Change Log -2021-09-02 -* added "Battery voltage" to info -* added circuit diagram to readme -* added MQTT support, sending battery voltage -* minor fixes - -2021-08-15 -* changed `USERMOD_BATTERY_MIN_VOLTAGE` to 2.6 volt as default for 18650 batteries -* Updated readme, added specification table - -2021-08-10 -* Created - diff --git a/usermods/battery_status_basic/usermod_v2_battery_status_basic.h b/usermods/battery_status_basic/usermod_v2_battery_status_basic.h deleted file mode 100644 index cb3c0867..00000000 --- a/usermods/battery_status_basic/usermod_v2_battery_status_basic.h +++ /dev/null @@ -1,398 +0,0 @@ -#pragma once - -#include "wled.h" - - - - -// pin defaults -// for the esp32 it is best to use the ADC1: GPIO32 - GPIO39 -// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html -#ifndef USERMOD_BATTERY_MEASUREMENT_PIN - #ifdef ARDUINO_ARCH_ESP32 - #define USERMOD_BATTERY_MEASUREMENT_PIN 32 - #else //ESP8266 boards - #define USERMOD_BATTERY_MEASUREMENT_PIN A0 - #endif -#endif - -// esp32 has a 12bit adc resolution -// esp8266 only 10bit -#ifndef USERMOD_BATTERY_ADC_PRECISION - #ifdef ARDUINO_ARCH_ESP32 - // 12 bits - #define USERMOD_BATTERY_ADC_PRECISION 4095.0f - #else - // 10 bits - #define USERMOD_BATTERY_ADC_PRECISION 1024.0f - #endif -#endif - - -// the frequency to check the battery, 30 sec -#ifndef USERMOD_BATTERY_MEASUREMENT_INTERVAL - #define USERMOD_BATTERY_MEASUREMENT_INTERVAL 30000 -#endif - - -// default for 18650 battery -// https://batterybro.com/blogs/18650-wholesale-battery-reviews/18852515-when-to-recycle-18650-batteries-and-how-to-start-a-collection-center-in-your-vape-shop -// Discharge voltage: 2.5 volt + .1 for personal safety -#ifndef USERMOD_BATTERY_MIN_VOLTAGE - #define USERMOD_BATTERY_MIN_VOLTAGE 2.6f -#endif - -#ifndef USERMOD_BATTERY_MAX_VOLTAGE - #define USERMOD_BATTERY_MAX_VOLTAGE 4.2f -#endif - -class UsermodBatteryBasic : public Usermod -{ - private: - // battery pin can be defined in my_config.h - int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN; - // how often to read the battery voltage - unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL; - unsigned long nextReadTime = 0; - unsigned long lastReadTime = 0; - // battery min. voltage - float minBatteryVoltage = USERMOD_BATTERY_MIN_VOLTAGE; - // battery max. voltage - float maxBatteryVoltage = USERMOD_BATTERY_MAX_VOLTAGE; - // 0 - 1024 for esp8266 (10-bit resolution) - // 0 - 4095 for esp32 (Default is 12-bit resolution) - float adcPrecision = USERMOD_BATTERY_ADC_PRECISION; - // raw analog reading - float rawValue = 0.0; - // calculated voltage - float voltage = 0.0; - // mapped battery level based on voltage - long batteryLevel = 0; - bool initDone = false; - bool initializing = true; - - - // strings to reduce flash memory usage (used more than twice) - static const char _name[]; - static const char _readInterval[]; - - - // custom map function - // https://forum.arduino.cc/t/floating-point-using-map-function/348113/2 - double mapf(double x, double in_min, double in_max, double out_min, double out_max) - { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; - } - - float truncate(float val, byte dec) - { - float x = val * pow(10, dec); - float y = round(x); - float z = x - y; - if ((int)z == 5) - { - y++; - } - x = y / pow(10, dec); - return x; - } - - - - public: - //Functions called by WLED - - /* - * setup() is called once at boot. WiFi is not yet connected at this point. - * You can use it to initialize variables, sensors or similar. - */ - void setup() - { - #ifdef ARDUINO_ARCH_ESP32 - DEBUG_PRINTLN(F("Allocating battery pin...")); - if (batteryPin >= 0 && pinManager.allocatePin(batteryPin, false)) - { - DEBUG_PRINTLN(F("Battery pin allocation succeeded.")); - } else { - if (batteryPin >= 0) DEBUG_PRINTLN(F("Battery pin allocation failed.")); - batteryPin = -1; // allocation failed - } - #else //ESP8266 boards have only one analog input pin A0 - - pinMode(batteryPin, INPUT); - #endif - - nextReadTime = millis() + readingInterval; - lastReadTime = millis(); - - initDone = true; - } - - - /* - * connected() is called every time the WiFi is (re)connected - * Use it to initialize network interfaces - */ - void connected() - { - //Serial.println("Connected to WiFi!"); - } - - - /* - * loop() is called continuously. Here you can check for events, read sensors, etc. - * - */ - void loop() - { - if(strip.isUpdating()) return; - - // check the battery level every USERMOD_BATTERY_MEASUREMENT_INTERVAL (ms) - if (millis() < nextReadTime) return; - - - nextReadTime = millis() + readingInterval; - lastReadTime = millis(); - initializing = false; - - // read battery raw input - rawValue = analogRead(batteryPin); - - // calculate the voltage - voltage = (rawValue / adcPrecision) * maxBatteryVoltage ; - // check if voltage is within specified voltage range - voltage = voltagemaxBatteryVoltage?-1.0f:voltage; - - // translate battery voltage into percentage - /* - the standard "map" function doesn't work - https://www.arduino.cc/reference/en/language/functions/math/map/ notes and warnings at the bottom - */ - batteryLevel = mapf(voltage, minBatteryVoltage, maxBatteryVoltage, 0, 100); - - - // SmartHome stuff - if (WLED_MQTT_CONNECTED) { - char subuf[64]; - strcpy(subuf, mqttDeviceTopic); - strcat_P(subuf, PSTR("/voltage")); - mqtt->publish(subuf, 0, false, String(voltage).c_str()); - } - - } - - - /* - * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. - * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. - * Below it is shown how this could be used for e.g. a light sensor - */ - void addToJsonInfo(JsonObject& root) - { - - JsonObject user = root["u"]; - if (user.isNull()) user = root.createNestedObject("u"); - - // info modal display names - JsonArray batteryPercentage = user.createNestedArray("Battery level"); - JsonArray batteryVoltage = user.createNestedArray("Battery voltage"); - - if (initializing) { - batteryPercentage.add((nextReadTime - millis()) / 1000); - batteryPercentage.add(" sec"); - batteryVoltage.add((nextReadTime - millis()) / 1000); - batteryVoltage.add(" sec"); - return; - } - - if(batteryLevel < 0) { - batteryPercentage.add(F("invalid")); - } else { - batteryPercentage.add(batteryLevel); - } - batteryPercentage.add(F(" %")); - - if(voltage < 0) { - batteryVoltage.add(F("invalid")); - } else { - batteryVoltage.add(truncate(voltage, 2)); - } - batteryVoltage.add(F(" V")); - } - - - /* - * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). - * Values in the state object may be modified by connected clients - */ - /* - void addToJsonState(JsonObject& root) - { - - } - */ - - - /* - * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). - * Values in the state object may be modified by connected clients - */ - /* - void readFromJsonState(JsonObject& root) - { - } - */ - - - /* - * 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) - * If you want to force saving the current state, use serializeConfig() in your loop(). - * - * CAUTION: serializeConfig() will initiate a filesystem write operation. - * It might cause the LEDs to stutter and will cause flash wear if called too often. - * Use it sparingly and always in the loop, never in network callbacks! - * - * addToConfig() will make your settings editable through the Usermod Settings page automatically. - * - * Usermod Settings Overview: - * - Numeric values are treated as floats in the browser. - * - If the numeric value entered into the browser contains a decimal point, it will be parsed as a C float - * before being returned to the Usermod. The float data type has only 6-7 decimal digits of precision, and - * doubles are not supported, numbers will be rounded to the nearest float value when being parsed. - * The range accepted by the input field is +/- 1.175494351e-38 to +/- 3.402823466e+38. - * - If the numeric value entered into the browser doesn't contain a decimal point, it will be parsed as a - * C int32_t (range: -2147483648 to 2147483647) before being returned to the usermod. - * Overflows or underflows are truncated to the max/min value for an int32_t, and again truncated to the type - * used in the Usermod when reading the value from ArduinoJson. - * - Pin values can be treated differently from an integer value by using the key name "pin" - * - "pin" can contain a single or array of integer values - * - On the Usermod Settings page there is simple checking for pin conflicts and warnings for special pins - * - Red color indicates a conflict. Yellow color indicates a pin with a warning (e.g. an input-only pin) - * - Tip: use int8_t to store the pin value in the Usermod, so a -1 value (pin not set) can be used - * - * See usermod_v2_auto_save.h for an example that saves Flash space by reusing ArduinoJson key name strings - * - * If you need a dedicated settings page with custom layout for your Usermod, that takes a lot more work. - * You will have to add the setting to the HTML, xml.cpp and set.cpp manually. - * See the WLED Soundreactive fork (code and wiki) for reference. https://github.com/atuline/WLED - * - * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! - */ - void addToConfig(JsonObject& root) - { - // created JSON object: - /* - { - "Battery-Level": { - "pin": "A0", <--- only when using esp32 boards - "minBatteryVoltage": 2.6, - "maxBatteryVoltage": 4.2, - "read-interval-ms": 30000 - } - } - */ - JsonObject battery = root.createNestedObject(FPSTR(_name)); // usermodname - #ifdef ARDUINO_ARCH_ESP32 - battery["pin"] = batteryPin; // usermodparam - #endif - battery["minBatteryVoltage"] = minBatteryVoltage; // usermodparam - battery["maxBatteryVoltage"] = maxBatteryVoltage; // usermodparam - battery[FPSTR(_readInterval)] = readingInterval; - - DEBUG_PRINTLN(F("Battery config saved.")); - } - - - /* - * readFromConfig() can be used to read back the custom settings you added with addToConfig(). - * This is called by WLED when settings are loaded (currently this only happens immediately after boot, or after saving on the Usermod Settings page) - * - * readFromConfig() is called BEFORE setup(). This means you can use your persistent values in setup() (e.g. pin assignments, buffer sizes), - * but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup. - * If you don't know what that is, don't fret. It most likely doesn't affect your use case :) - * - * Return true in case the config values returned from Usermod Settings were complete, or false if you'd like WLED to save your defaults to disk (so any missing values are editable in Usermod Settings) - * - * getJsonValue() returns false if the value is missing, or copies the value into the variable provided and returns true if the value is present - * The configComplete variable is true only if the "exampleUsermod" object and all values are present. If any values are missing, WLED will know to call addToConfig() to save them - * - * This function is guaranteed to be called on boot, but could also be called every time settings are updated - */ - bool readFromConfig(JsonObject& root) - { - // looking for JSON object: - /* - { - "BatteryLevel": { - "pin": "A0", <--- only when using esp32 boards - "minBatteryVoltage": 2.6, - "maxBatteryVoltage": 4.2, - "read-interval-ms": 30000 - } - } - */ - #ifdef ARDUINO_ARCH_ESP32 - int8_t newBatteryPin = batteryPin; - #endif - - JsonObject battery = root[FPSTR(_name)]; - if (battery.isNull()) - { - DEBUG_PRINT(FPSTR(_name)); - DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); - return false; - } - - #ifdef ARDUINO_ARCH_ESP32 - newBatteryPin = battery["pin"] | newBatteryPin; - #endif - minBatteryVoltage = battery["minBatteryVoltage"] | minBatteryVoltage; - //minBatteryVoltage = min(12.0f, (int)readingInterval); - maxBatteryVoltage = battery["maxBatteryVoltage"] | maxBatteryVoltage; - //maxBatteryVoltage = min(14.4f, max(3.3f,(int)readingInterval)); - readingInterval = battery["read-interval-ms"] | readingInterval; - readingInterval = max(3000, (int)readingInterval); // minimum repetition is >5000ms (5s) - - DEBUG_PRINT(FPSTR(_name)); - - #ifdef ARDUINO_ARCH_ESP32 - if (!initDone) - { - // first run: reading from cfg.json - newBatteryPin = batteryPin; - DEBUG_PRINTLN(F(" config loaded.")); - } - else - { - DEBUG_PRINTLN(F(" config (re)loaded.")); - - // changing paramters from settings page - if (newBatteryPin != batteryPin) - { - // deallocate pin - pinManager.deallocatePin(batteryPin); - batteryPin = newBatteryPin; - // initialise - setup(); - } - } - #endif - - return !battery[FPSTR(_readInterval)].isNull(); - } - - - /* - * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). - * This could be used in the future for the system to determine whether your usermod is installed. - */ - uint16_t getId() - { - return USERMOD_ID_BATTERY_STATUS_BASIC; - } -}; - -// strings to reduce flash memory usage (used more than twice) -const char UsermodBatteryBasic::_name[] PROGMEM = "Battery-level"; -const char UsermodBatteryBasic::_readInterval[] PROGMEM = "read-interval-ms"; \ No newline at end of file diff --git a/usermods/blynk_relay_control/README.md b/usermods/blynk_relay_control/README.md deleted file mode 100644 index b6494b46..00000000 --- a/usermods/blynk_relay_control/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Blynk controllable relay -This usermod allows controlling a relay state from the user variables. It also allows the user variables to be set over Blynk. - -Optionally, the servo can have a reset timer to go back to it's default state after an interval. This interval is set through userVar1. - -## Instalation - -Replace the WLED06_usermod.ino file in Aircoookies WLED folder with the one here. - -## Customizations - -Update the following parameters in WLED06_usermod.ino to configure the mod's behavior: - -```cpp -//Which pin is the relay connected to -#define RELAY_PIN 5 -//Which pin state should the relay default to -#define RELAY_PIN_DEFAULT LOW -//If >0 The controller returns to RELAY_PIN_DEFAULT after this time in milliseconds -#define RELAY_PIN_TIMER_DEFAULT 3000 - -//Blynk virtual pin for controlling relay -#define BLYNK_USER_VAR0_PIN V9 -//Blynk virtual pin for controlling relay timer -#define BLYNK_USER_VAR1_PIN V10 -//Number of milliseconds between updating blynk -#define BLYNK_RELAY_UPDATE_INTERVAL 5000 -``` diff --git a/usermods/blynk_relay_control/wled06_usermod.ino b/usermods/blynk_relay_control/wled06_usermod.ino deleted file mode 100644 index d4028ea5..00000000 --- a/usermods/blynk_relay_control/wled06_usermod.ino +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file allows you to add own functionality to WLED more easily - * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled_eeprom.h) - * bytes 2400+ are currently ununsed, but might be used for future wled features - */ - -//Use userVar0 (API calls &U0=, uint16_t) to set relay state -#define relayPinState userVar0 -//Use userVar1 (API calls &U1=, uint16_t) to set relay timer duration -//Ignored if 0, otherwise number of milliseconds to allow relay to stay in -//non default state. -#define relayTimerInterval userVar1 - -//Which pin is the relay connected to -#define RELAY_PIN 5 -//Which pin state should the relay default to -#define RELAY_PIN_DEFAULT LOW -//If >0 The controller returns to RELAY_PIN_DEFAULT after this time in milliseconds -#define RELAY_PIN_TIMER_DEFAULT 3000 - -//Blynk virtual pin for controlling relay -#define BLYNK_USER_VAR0_PIN V9 -//Blynk virtual pin for controlling relay timer -#define BLYNK_USER_VAR1_PIN V10 -//Number of milliseconds between updating blynk -#define BLYNK_RELAY_UPDATE_INTERVAL 5000 - -//Is the timer for resetting the relay active -bool relayTimerStarted = false; -//millis() time after which relay will be reset -unsigned long relayTimeToDefault = 0; -//millis() time after which relay vars in Blynk will be sent -unsigned long relayBlynkUpdateTime = 0; - -//gets called once at boot. Do all initialization that doesn't depend on network here -void userSetup() -{ - relayPinState = RELAY_PIN_DEFAULT; - relayTimerInterval = RELAY_PIN_TIMER_DEFAULT; - pinMode(RELAY_PIN, OUTPUT); - digitalWrite(RELAY_PIN, relayPinState); -} - -//gets called every time WiFi is (re-)connected. Initialize own network interfaces here -void userConnected() -{ -} - -//loop. You can use "if (WLED_CONNECTED)" to check for successful connection -void userLoop() -{ - //Normalize relayPinState to an accepted value - if (relayPinState != HIGH && relayPinState != LOW) { - relayPinState = RELAY_PIN_DEFAULT; - } - //If relay changes and relayTimerInterval is set, start a timer to change back - if (relayTimerInterval != 0 && - relayPinState != RELAY_PIN_DEFAULT && - !relayTimerStarted ) { - relayTimerStarted = true; - relayTimeToDefault = millis() + relayTimerInterval; - } - //If manually changed back to default, cancel timer - if (relayTimerStarted && relayPinState == RELAY_PIN_DEFAULT ) { - relayTimerStarted = false; - } - //If timer completes, set relay back to default - if (relayTimerStarted && millis() > relayTimeToDefault) { - relayPinState = RELAY_PIN_DEFAULT; - relayTimerStarted = false; - } - digitalWrite(RELAY_PIN, relayPinState); - updateRelayBlynk(); -} - -//Update Blynk with state of userVars at BLYNK_RELAY_UPDATE_INTERVAL -void updateRelayBlynk() -{ - if (!WLED_CONNECTED) return; - if (relayBlynkUpdateTime > millis()) return; - Blynk.virtualWrite(BLYNK_USER_VAR0_PIN, userVar0); - Blynk.virtualWrite(BLYNK_USER_VAR1_PIN, userVar1); - relayBlynkUpdateTime = millis() + BLYNK_RELAY_UPDATE_INTERVAL; -} - -//Add Blynk callback for setting userVar0 -BLYNK_WRITE(BLYNK_USER_VAR0_PIN) -{ - userVar0 = param.asInt(); -} -//Add Blynk callback for setting userVar1 -BLYNK_WRITE(BLYNK_USER_VAR1_PIN) -{ - userVar1 = param.asInt(); -} diff --git a/usermods/boblight/boblight.h b/usermods/boblight/boblight.h new file mode 100644 index 00000000..b36f301c --- /dev/null +++ b/usermods/boblight/boblight.h @@ -0,0 +1,461 @@ +#pragma once + +#include "wled.h" + +/* + * Usermod that implements BobLight "ambilight" protocol + * + * See the accompanying README.md file for more info. + */ + +#ifndef BOB_PORT + #define BOB_PORT 19333 // Default boblightd port +#endif + +class BobLightUsermod : public Usermod { + typedef struct _LIGHT { + char lightname[5]; + float hscan[2]; + float vscan[2]; + } light_t; + + private: + unsigned long lastTime = 0; + bool enabled = false; + bool initDone = false; + + light_t *lights = nullptr; + uint16_t numLights = 0; // 16 + 9 + 16 + 9 + uint16_t top, bottom, left, right; // will be filled in readFromConfig() + uint16_t pct; + + WiFiClient bobClient; + WiFiServer *bob; + uint16_t bobPort = BOB_PORT; + + static const char _name[]; + static const char _enabled[]; + + /* + # boblight + # Copyright (C) Bob 2009 + # + # makeboblight.sh created by Adam Boeglin + # + # boblight is free software: you can redistribute it and/or modify it + # under the terms of the GNU General Public License as published by the + # Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # boblight is distributed in the hope that it will be useful, but + # WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + # See the GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License along + # with this program. If not, see . + */ + + // fills the lights[] array with position & depth of scan for each LED + void fillBobLights(int bottom, int left, int top, int right, float pct_scan) { + + int lightcount = 0; + int total = top+left+right+bottom; + int bcount; + + if (total > strip.getLengthTotal()) { + DEBUG_PRINTLN(F("BobLight: Too many lights.")); + return; + } + + // start left part of bottom strip (clockwise direction, 1st half) + if (bottom > 0) { + bcount = 1; + float brange = 100.0/bottom; + float bcurrent = 50.0; + if (bottom < top) { + int diff = top - bottom; + brange = 100.0/top; + bcurrent -= (diff/2)*brange; + } + while (bcount <= bottom/2) { + float btop = bcurrent - brange; + String name = "b"+String(bcount); + strncpy(lights[lightcount].lightname, name.c_str(), 4); + lights[lightcount].hscan[0] = btop; + lights[lightcount].hscan[1] = bcurrent; + lights[lightcount].vscan[0] = 100 - pct_scan; + lights[lightcount].vscan[1] = 100; + lightcount+=1; + bcurrent = btop; + bcount+=1; + } + } + + // left side + if (left > 0) { + int lcount = 1; + float lrange = 100.0/left; + float lcurrent = 100.0; + while (lcount <= left) { + float ltop = lcurrent - lrange; + String name = "l"+String(lcount); + strncpy(lights[lightcount].lightname, name.c_str(), 4); + lights[lightcount].hscan[0] = 0; + lights[lightcount].hscan[1] = pct_scan; + lights[lightcount].vscan[0] = ltop; + lights[lightcount].vscan[1] = lcurrent; + lightcount+=1; + lcurrent = ltop; + lcount+=1; + } + } + + // top side + if (top > 0) { + int tcount = 1; + float trange = 100.0/top; + float tcurrent = 0; + while (tcount <= top) { + float ttop = tcurrent + trange; + String name = "t"+String(tcount); + strncpy(lights[lightcount].lightname, name.c_str(), 4); + lights[lightcount].hscan[0] = tcurrent; + lights[lightcount].hscan[1] = ttop; + lights[lightcount].vscan[0] = 0; + lights[lightcount].vscan[1] = pct_scan; + lightcount+=1; + tcurrent = ttop; + tcount+=1; + } + } + + // right side + if (right > 0) { + int rcount = 1; + float rrange = 100.0/right; + float rcurrent = 0; + while (rcount <= right) { + float rtop = rcurrent + rrange; + String name = "r"+String(rcount); + strncpy(lights[lightcount].lightname, name.c_str(), 4); + lights[lightcount].hscan[0] = 100-pct_scan; + lights[lightcount].hscan[1] = 100; + lights[lightcount].vscan[0] = rcurrent; + lights[lightcount].vscan[1] = rtop; + lightcount+=1; + rcurrent = rtop; + rcount+=1; + } + } + + // right side of bottom strip (2nd half) + if (bottom > 0) { + float brange = 100.0/bottom; + float bcurrent = 100; + if (bottom < top) { + brange = 100.0/top; + } + while (bcount <= bottom) { + float btop = bcurrent - brange; + String name = "b"+String(bcount); + strncpy(lights[lightcount].lightname, name.c_str(), 4); + lights[lightcount].hscan[0] = btop; + lights[lightcount].hscan[1] = bcurrent; + lights[lightcount].vscan[0] = 100 - pct_scan; + lights[lightcount].vscan[1] = 100; + lightcount+=1; + bcurrent = btop; + bcount+=1; + } + } + + numLights = lightcount; + + #if WLED_DEBUG + DEBUG_PRINTLN(F("Fill light data: ")); + DEBUG_PRINTF(" lights %d\n", numLights); + for (int i=0; i strip.getLengthTotal() ) { + DEBUG_PRINTLN(F("BobLight: Too many lights.")); + DEBUG_PRINTF("%d+%d+%d+%d>%d\n", bottom, left, top, right, strip.getLengthTotal()); + totalLights = strip.getLengthTotal(); + top = bottom = (uint16_t) roundf((float)totalLights * 16.0f / 50.0f); + left = right = (uint16_t) roundf((float)totalLights * 9.0f / 50.0f); + } + lights = new light_t[totalLights]; + if (lights) fillBobLights(bottom, left, top, right, float(pct)); // will fill numLights + else enable(false); + initDone = true; + } + + void connected() { + // we can only start server when WiFi is connected + if (!bob) bob = new WiFiServer(bobPort, 1); + bob->begin(); + bob->setNoDelay(true); + } + + void loop() { + if (!enabled || strip.isUpdating()) return; + if (millis() - lastTime > 10) { + lastTime = millis(); + pollBob(); + } + } + + void enable(bool en) { enabled = en; } + +#ifndef WLED_DISABLE_MQTT + /** + * handling of MQTT message + * topic only contains stripped topic (part after /wled/MAC) + * topic should look like: /swipe with amessage of [up|down] + */ + bool onMqttMessage(char* topic, char* payload) { + //if (strlen(topic) == 6 && strncmp_P(topic, PSTR("/subtopic"), 6) == 0) { + // String action = payload; + // if (action == "on") { + // enable(true); + // return true; + // } else if (action == "off") { + // enable(false); + // return true; + // } + //} + return false; + } + + /** + * subscribe to MQTT topic for controlling usermod + */ + void onMqttConnect(bool sessionPresent) { + //char subuf[64]; + //if (mqttDeviceTopic[0] != 0) { + // strcpy(subuf, mqttDeviceTopic); + // strcat_P(subuf, PSTR("/subtopic")); + // mqtt->subscribe(subuf, 0); + //} + } +#endif + + void addToJsonInfo(JsonObject& root) + { + JsonObject user = root["u"]; + if (user.isNull()) user = root.createNestedObject("u"); + + JsonArray infoArr = user.createNestedArray(FPSTR(_name)); + String uiDomString = F(""); + infoArr.add(uiDomString); + } + + /* + * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). + * Values in the state object may be modified by connected clients + */ + void addToJsonState(JsonObject& root) + { + } + + /* + * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). + * Values in the state object may be modified by connected clients + */ + void readFromJsonState(JsonObject& root) { + if (!initDone) return; // prevent crash on boot applyPreset() + bool en = enabled; + JsonObject um = root[FPSTR(_name)]; + if (!um.isNull()) { + if (um[FPSTR(_enabled)].is()) { + en = um[FPSTR(_enabled)].as(); + } else { + String str = um[FPSTR(_enabled)]; // checkbox -> off or on + en = (bool)(str!="off"); // off is guaranteed to be present + } + if (en != enabled && lights) { + enable(en); + if (!enabled && bob && bob->hasClient()) { + if (bobClient) bobClient.stop(); + bobClient = bob->available(); + BobClear(); + exitRealtime(); + } + } + } + } + + void appendConfigData() { + oappend(SET_F("addHB('BobLight');")); + + //oappend(SET_F("dd=addDropdown('usermod','selectfield');")); + //oappend(SET_F("addOption(dd,'1st value',0);")); + //oappend(SET_F("addOption(dd,'2nd value',1);")); + oappend(SET_F("addInfo('BobLight:top',1,'LEDs');")); // 0 is field type, 1 is actual field + oappend(SET_F("addInfo('BobLight:bottom',1,'LEDs');")); // 0 is field type, 1 is actual field + oappend(SET_F("addInfo('BobLight:left',1,'LEDs');")); // 0 is field type, 1 is actual field + oappend(SET_F("addInfo('BobLight:right',1,'LEDs');")); // 0 is field type, 1 is actual field + oappend(SET_F("addInfo('BobLight:pct',1,'Depth of scan [%]');")); // 0 is field type, 1 is actual field + } + + void addToConfig(JsonObject& root) { + JsonObject umData = root.createNestedObject(FPSTR(_name)); + umData[FPSTR(_enabled)] = enabled; + umData[F("port")] = bobPort; + umData[F("top")] = top; + umData[F("bottom")] = bottom; + umData[F("left")] = left; + umData[F("right")] = right; + umData[F("pct")] = pct; + } + + bool readFromConfig(JsonObject& root) { + JsonObject umData = root[FPSTR(_name)]; + bool configComplete = !umData.isNull(); + + bool en = enabled; + configComplete &= getJsonValue(umData[FPSTR(_enabled)], en); + enable(en); + + configComplete &= getJsonValue(umData[F("port")], bobPort); + configComplete &= getJsonValue(umData[F("bottom")], bottom, 16); + configComplete &= getJsonValue(umData[F("top")], top, 16); + configComplete &= getJsonValue(umData[F("left")], left, 9); + configComplete &= getJsonValue(umData[F("right")], right, 9); + configComplete &= getJsonValue(umData[F("pct")], pct, 5); // Depth of scan [%] + pct = MIN(50,MAX(1,pct)); + + uint16_t totalLights = bottom + left + top + right; + if (initDone && numLights != totalLights) { + if (lights) delete[] lights; + setup(); + } + return configComplete; + } + + /* + * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors. + * Use this to blank out some LEDs or set them to a different color regardless of the set effect mode. + * Commonly used for custom clocks (Cronixie, 7 segment) + */ + void handleOverlayDraw() { + //strip.setPixelColor(0, RGBW32(0,0,0,0)) // set the first pixel to black + } + + uint16_t getId() { return USERMOD_ID_BOBLIGHT; } + +}; + +// strings to reduce flash memory usage (used more than twice) +const char BobLightUsermod::_name[] PROGMEM = "BobLight"; +const char BobLightUsermod::_enabled[] PROGMEM = "enabled"; + +// main boblight handling (definition here prevents inlining) +void BobLightUsermod::pollBob() { + + //check if there are any new clients + if (bob && bob->hasClient()) { + //find free/disconnected spot + if (!bobClient || !bobClient.connected()) { + if (bobClient) bobClient.stop(); + bobClient = bob->available(); + DEBUG_PRINTLN(F("Boblight: Client connected.")); + } + //no free/disconnected spot so reject + WiFiClient bobClientTmp = bob->available(); + bobClientTmp.stop(); + BobClear(); + exitRealtime(); + } + + //check clients for data + if (bobClient && bobClient.connected()) { + realtimeLock(realtimeTimeoutMs); // lock strip as we have a client connected + + //get data from the client + while (bobClient.available()) { + String input = bobClient.readStringUntil('\n'); + // DEBUG_PRINT("Client: "); DEBUG_PRINTLN(input); // may be to stressful on Serial + if (input.startsWith(F("hello"))) { + DEBUG_PRINTLN(F("hello")); + bobClient.print(F("hello\n")); + } else if (input.startsWith(F("ping"))) { + DEBUG_PRINTLN(F("ping 1")); + bobClient.print(F("ping 1\n")); + } else if (input.startsWith(F("get version"))) { + DEBUG_PRINTLN(F("version 5")); + bobClient.print(F("version 5\n")); + } else if (input.startsWith(F("get lights"))) { + char tmp[64]; + String answer = ""; + sprintf_P(tmp, PSTR("lights %d\n"), numLights); + DEBUG_PRINT(tmp); + answer.concat(tmp); + for (int i=0; i ... + input.remove(0,10); + String tmp = input.substring(0,input.indexOf(' ')); + + int light_id = -1; + for (uint16_t i=0; iavailable(); + BobClear(); + } + } + } +} diff --git a/usermods/boblight/readme.md b/usermods/boblight/readme.md new file mode 100644 index 00000000..34583009 --- /dev/null +++ b/usermods/boblight/readme.md @@ -0,0 +1,37 @@ +# BobLight usermod + +This usermod allows displaying BobLight ambilight protocol on WLED device with a limited command set (not a full implementation). +BobLight protocol uses a TCP connection which guarantees packet delivery at the possible expense of latency delays. It is not very efficient (as it uses plaintext comands) so is not suited for large number of LEDs. + +This implementation is intended for TV backlight in combination with XBMC/Kodi BobLight add-on. + +The LEDs can be configured in usermod settings page. The configuration is simple: you enter the number of LED pixels on each side of your TV (top, right, bottom, left). +The LEDs should be wired in a clockwise orientation starting in the middle of bottom side (left half of bottom leds is where the string should start). + +``` ++-------->-------+ +| | +^ v +| | ++---<--+ ---<---+ + ^ + start +``` + +## Installation + +Add `-D USERMOD_BOBLIGHT` to your PlatformIO environment. +If you are not using PlatformIO (which you should) try adding `#define USERMOD_BOBLIGHT` to *my_config.h*. + +## Configuration + +All parameters are runtime configurable though changing port may require reboot. + +If you want to define default port during compile time use the following (default values in parentheses): + +- `BOB_PORT=x` : defines default TCP port for usermod to listen on (19333) + + +## Release notes + +2022-11 Initial implementation by @blazoncek (AKA Blaz Kristan) diff --git a/usermods/mpu6050_imu/readme.md b/usermods/mpu6050_imu/readme.md index d8df0adb..f1f3d74f 100644 --- a/usermods/mpu6050_imu/readme.md +++ b/usermods/mpu6050_imu/readme.md @@ -1,13 +1,13 @@ # MPU-6050 Six-Axis (Gyro + Accelerometer) Driver -This usermod-v2 modification allows the connection of a MPU-6050 IMU sensor to -allow for effects that are controlled by the orientation or motion of the WLED Device. +v2 of this usermod enables connection of a MPU-6050 IMU sensor to +work with effects controlled by the orientation or motion of the WLED Device. -The MPU6050 has a built in "Digital Motion Processor" which does a lot of the heavy -lifting in integrating the gyro and accel measurements to get potentially more +The MPU6050 has a built in "Digital Motion Processor" which does the "heavy lifting" +integrating the gyro and accelerometer measurements to get potentially more useful gravity vector and orientation output. -It is pretty straightforward to comment out some of the variables being read off the device if they're not needed to save CPU/Mem/Bandwidth. +It is fairly straightforward to comment out variables being read from the device if they're not needed. Saves CPU/Memory/Bandwidth. _Story:_ diff --git a/usermods/mpu6050_imu/usermod_mpu6050_imu.h b/usermods/mpu6050_imu/usermod_mpu6050_imu.h index 748824ee..e923e1f9 100644 --- a/usermods/mpu6050_imu/usermod_mpu6050_imu.h +++ b/usermods/mpu6050_imu/usermod_mpu6050_imu.h @@ -1,11 +1,16 @@ #pragma once +#include // WLEDMM: make sure that I2C drivers have the "right" Wire Object +#include + #include "wled.h" + // #define MPU6050_INT_GPIO 13 // WLEDMM - better choice on ESP32 + #ifdef WLED_DEBUG - #define DEBUG_PRINT_IMU(x) Serial.print(x) - #define DEBUG_PRINT_IMULN(x) Serial.println(x) - #define DEBUG_PRINT_IMUF(x...) Serial.printf(x) + #define DEBUG_PRINT_IMU(x) DEBUG_PRINT(x) + #define DEBUG_PRINT_IMULN(x) DEBUG_PRINTLN(x) + #define DEBUG_PRINT_IMUF(x...) DEBUG_PRINTF(x) #else #define DEBUG_PRINT_IMU(x) #define DEBUG_PRINT_IMULN(x) @@ -42,14 +47,37 @@ 5. Wire up the MPU6050 as detailed above. */ -#include "I2Cdev.h" +// WLEDMM: make sure that the "standard" Wire object is used +#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE -#include "MPU6050_6Axis_MotionApps20.h" +// WLEDMM avoid stupid warnings +#undef DEBUG_PRINT +#undef DEBUG_PRINTLN +#undef DEBUG_PRINTF + +#include + +#include + +// WLEDMM - need to re-define WLED DEBUG_PRINT maros, because the were overwritten by MPU6050_6Axis_MotionApps20.h +#undef DEBUG_PRINT +#undef DEBUG_PRINTLN +#undef DEBUG_PRINTF + +#ifdef WLED_DEBUG + #define DEBUG_PRINT(x) DEBUGOUT(x) + #define DEBUG_PRINTLN(x) DEBUGOUTLN(x) + #define DEBUG_PRINTF(x...) DEBUGOUTF(x) +#else + #define DEBUG_PRINT(x) + #define DEBUG_PRINTLN(x) + #define DEBUG_PRINTF(x...) +#endif // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE - #include "Wire.h" + //#include "Wire.h" // WLEDMM not necessary #endif // ================================================================ @@ -65,18 +93,22 @@ void IRAM_ATTR dmpDataReady() { class MPU6050Driver : public Usermod { private: MPU6050 mpu; - bool enabled = true; unsigned long lastUMRun = millis(); // MPU control/status vars - bool dmpReady = false; // set true if DMP init was successful uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU uint8_t devStatus; // return status after each device operation (0 = success, !0 = error) uint16_t packetSize; // expected DMP packet size (default is 42 bytes) uint16_t fifoCount; // count of all bytes currently in FIFO uint8_t fifoBuffer[64]; // FIFO storage buffer + // strings to reduce flash memory usage (used more than twice) + static const char _INT_pin[]; + public: + MPU6050Driver(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM: this shouldn't be necessary (passthrough of constructor), maybe because Usermod is an abstract class + + bool dmpReady = false; // set true if DMP init was successful // WLEDMM expose this info in public interface // orientation/motion vars Quaternion qat; // [w, x, y, z] quaternion container VectorInt16 aa; // [x, y, z] accel sensor measurements @@ -84,19 +116,49 @@ class MPU6050Driver : public Usermod { VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements VectorFloat gravity; // [x, y, z] gravity vector - float euler[3]; // [psi, theta, phi] Euler angle container - float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector + float euler[3] = {0.0f};// [psi, theta, phi] Euler angle container + float ypr[3] = {0.0f}; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector - static const int INTERRUPT_PIN = 15; // use pin 15 on ESP8266 + #if !defined(ARDUINO_ARCH_ESP32) || !defined(MPU6050_INT_GPIO) + static const int INTERRUPT_PIN = -1; // WLEDMM: not use pin 15 (on ESP8266) as can and will cause conflict with other pins + #else + static const int INTERRUPT_PIN = MPU6050_INT_GPIO; // WLEDMM + #endif void setup() { - DEBUG_PRINT_IMULN("mpu setup"); + // WLEDMM begin + if (!enabled) { + dmpReady = false; + return; + } + USER_PRINTLN(F("mpu setup")); PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } }; - if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; } + if ((i2c_scl < 0) || (i2c_sda < 0)) { + //enabled = false; + USER_PRINTF("mpu6050: warning - ivalid I2C pins: sda=%d scl=%d\n", i2c_sda, i2c_scl); + //return; + } + + if (pins[1].pin < 0 || pins[0].pin < 0) { enabled=false; dmpReady = false; return; } //WLEDMM bugfix - ensure that "final" GPIO are valid and no "-1" sneaks trough + //if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { + + // WLEDMM join I2C HW wire + if (!pinManager.joinWire()) { + enabled = false; + dmpReady = false; + USER_PRINTF("mpu6050: failed to allocate I2C sda=%d scl=%d\n", i2c_sda, i2c_scl); + return; + } + // WLEDMM end // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE - Wire.begin(); +#if defined(ARDUINO_ARCH_ESP32) + //Wire.begin(pins[1].pin, pins[0].pin); // WLEDMM fix - need to use proper pins, in case that Wire was not started yet. Call will silently fail if Wire is initialized already. +#else + //Wire.begin(); // WLEDMM - i2c pins on 8266 are fixed. +#endif + Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); @@ -116,12 +178,31 @@ class MPU6050Driver : public Usermod { // initialize device DEBUG_PRINT_IMULN(F("Initializing I2C devices...")); + // WLEDMM begin + if ((INTERRUPT_PIN < 0) || (!pinManager.isPinINT(INTERRUPT_PIN))) { + //enabled = false; + USER_PRINTF("mpu6050: warning - interrupt GPIO %d does not support interrupts.\n", INTERRUPT_PIN); + //INTERRUPT_PIN = -1; + //return; + } + if ((INTERRUPT_PIN >= 0) && (pinManager.getPinOwner(INTERRUPT_PIN) != PinOwner::UM_IMU) // only allocate pin if we don't ownn it already + && !pinManager.allocatePin(INTERRUPT_PIN, false, PinOwner::UM_IMU)) + { + //enabled = false; + USER_PRINTF("mpu6050: warning - failed to allocate interrupt GPIO %d\n", INTERRUPT_PIN); + //INTERRUPT_PIN = -1; + //return; + } + // WLEDMM end + mpu.initialize(); - pinMode(INTERRUPT_PIN, INPUT); + if (INTERRUPT_PIN >= 0) { // WLEDMM only if pin is valid + pinMode(INTERRUPT_PIN, INPUT); + } // verify connection DEBUG_PRINT_IMULN(F("Testing device connections...")); - DEBUG_PRINT_IMULN(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); + USER_PRINTLN(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); // // wait for ready // DEBUG_PRINT_IMULN(F("\nSend any character to begin DMP programming and demo: ")); @@ -151,11 +232,13 @@ class MPU6050Driver : public Usermod { DEBUG_PRINT_IMULN(F("Enabling DMP...")); mpu.setDMPEnabled(true); - // enable Arduino interrupt detection - DEBUG_PRINT_IMU(F("Enabling interrupt detection (Arduino external interrupt ")); - DEBUG_PRINT_IMU(digitalPinToInterrupt(INTERRUPT_PIN)); - DEBUG_PRINT_IMULN(F(")...")); - attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); + if (INTERRUPT_PIN >= 0) { + // enable Arduino interrupt detection + DEBUG_PRINT_IMU(F("Enabling interrupt detection (Arduino external interrupt ")); + DEBUG_PRINT_IMU(digitalPinToInterrupt(INTERRUPT_PIN)); + DEBUG_PRINT_IMULN(F(")...")); + attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); + } mpuIntStatus = mpu.getIntStatus(); // set our DMP Ready flag so the main loop() function knows it's okay to use it @@ -165,14 +248,16 @@ class MPU6050Driver : public Usermod { // get expected DMP packet size for later comparison packetSize = mpu.dmpGetFIFOPacketSize(); } else { - // ERROR! - // 1 = initial memory load failed - // 2 = DMP configuration updates failed - // (if it's going to break, usually the code will be 1) - DEBUG_PRINT_IMU(F("DMP Initialization failed (code ")); - DEBUG_PRINT_IMU(devStatus); - DEBUG_PRINT_IMULN(F(")")); + // ERROR! + // 1 = initial memory load failed + // 2 = DMP configuration updates failed + // (if it's going to break, usually the code will be 1) + DEBUG_PRINT(F("DMP Initialization failed (code ")); + DEBUG_PRINT(devStatus); + DEBUG_PRINTLN(")"); + dmpReady = false; } + initDone = true; } void connected() { @@ -181,6 +266,7 @@ class MPU6050Driver : public Usermod { void loop() { // if programming failed, don't try to do anything + if (!initDone) return; if (!enabled || (strip.isUpdating() && (millis() - lastUMRun < 2))) return; // be nice, but not too nice lastUMRun = millis(); // update time keeping @@ -202,12 +288,15 @@ class MPU6050Driver : public Usermod { void addToJsonInfo(JsonObject& root) { + if (!initDone) return; + if (!enabled && !dmpReady) return; // WLEDMM no info when usermod disabled JsonObject user = root["u"]; if (user.isNull()) user = root.createNestedObject("u"); - StaticJsonDocument<600> doc; //measured 528 + StaticJsonDocument<800> doc; //measured 528 // WLEDMM added some margin (was 600) JsonObject imu_meas = doc.createNestedObject("IMU"); + //JsonObject imu_meas = user.createNestedObject("IMU"); #ifdef WLED_DEBUG JsonArray quat_json = imu_meas.createNestedArray("Quat"); quat_json.add(qat.w); @@ -243,12 +332,15 @@ class MPU6050Driver : public Usermod { orient_json.add(ypr[0] * 180/M_PI); orient_json.add(ypr[1] * 180/M_PI); orient_json.add(ypr[2] * 180/M_PI); - - char stringBuffer[300]; // measured 266 + char stringBuffer[400]; // measured 266 // WLEDMM added some margin (was 300) serializeJson(imu_meas, stringBuffer); JsonArray mainObject = user.createNestedArray("IMU"); - mainObject.add(stringBuffer); - + if (!dmpReady || !enabled) { // WLEDMM + if (!dmpReady) mainObject.add(F("Sensor Not Found")); + else if (!enabled) mainObject.add(F("usermod disabled")); + } else { + mainObject.add(stringBuffer); + } // Serial.printf("imu_meas %u (%u %u) stringBuffer %u\n", (unsigned int)imu_meas.memoryUsage(), (unsigned int)imu_meas.size(), (unsigned int)imu_meas.nesting(), strlen(stringBuffer)); } @@ -262,29 +354,64 @@ class MPU6050Driver : public Usermod { //{ //} - // void addToConfig(JsonObject& root) - // { - // JsonObject top = root.createNestedObject("MPU6050"); - // top[FPSTR("enabled")] = enabled; + // void addToConfig(JsonObject& root) + // { + // Usermod::addToConfig(root); + // JsonObject top = root[FPSTR(_name)]; + // // //JsonObject interruptPin = top.createNestedObject(FPSTR(_INT_pin)); + // // //interruptPin["pin"] = INTERRUPT_PIN; + // // DEBUG_PRINTLN(F("MPU6050 IMU config saved.")); + // } - // JsonObject interruptPin = top.createNestedObject(FPSTR("interruptPin")); - // interruptPin["pin"] = interruptPin; - // } + //WLEDMM: add appendConfigData + void appendConfigData() + { + oappend(SET_F("addHB('mpu6050-IMU');")); + /* + #ifdef MPU6050_INT_GPIO + oappend(SET_F("xOpt('mpu6050-IMU:interrupt_pin',0,' ⎌',")); oappendi(MPU6050_INT_GPIO); 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');"); + } + */ + } - // bool readFromConfig(JsonObject& root) - // { - // JsonObject top = root[FPSTR("MPU6050")]; - // bool configComplete = !top.isNull(); + bool readFromConfig(JsonObject& root) + { + bool configComplete = Usermod::readFromConfig(root); + JsonObject top = root[FPSTR(_name)]; - // configComplete &= getJsonValue(top[FPSTR("enabled")], enabled); - // configComplete &= getJsonValue(top[FPSTR("interruptPin")]["pin"], interruptPin); + if (top.isNull()) { + DEBUG_PRINT(FPSTR(_name)); + DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); + return false; + } - // return configComplete; - // } + //configComplete &= getJsonValue(top[FPSTR(_INT_pin)]["pin"], INTERRUPT_PIN); + + DEBUG_PRINT(FPSTR(_name)); + if (!initDone) { + // first run: reading from cfg.json + DEBUG_PRINTLN(F(" config loaded.")); + } else { + DEBUG_PRINTLN(F(" config (re)loaded.")); + if (enabled || dmpReady) setup(); // re-run setup if user has checked "enabled" + if (!enabled) dmpReady = false; // not enabled inplies "no DMP data ready" + } + + return configComplete; + // use "return !top["newestParameter"].isNull();" when updating Usermod with new features + //return !top[FPSTR(_INT_pin)].isNull(); + } uint16_t getId() { return USERMOD_ID_IMU; } -}; \ No newline at end of file +}; + +// strings to reduce flash memory usage (used more than twice) +const char MPU6050Driver::_INT_pin[] PROGMEM = "interrupt_pin"; diff --git a/usermods/multi_relay/readme.md b/usermods/multi_relay/readme.md index a0a3e9e9..2906b860 100644 --- a/usermods/multi_relay/readme.md +++ b/usermods/multi_relay/readme.md @@ -1,37 +1,37 @@ # Multi Relay -This usermod-v2 modification allows the connection of multiple relays each with individual delay and on/off mode. +This usermod-v2 modification allows the connection of multiple relays, each with individual delay and on/off mode. ## HTTP API -All responses are returned as JSON. +All responses are returned in JSON format. * Status Request: `http://[device-ip]/relays` * Switch Command: `http://[device-ip]/relays?switch=1,0,1,1` -The number of numbers behind the switch parameter must correspond to the number of relays. The number 1 switches the relay on. The number 0 switches the relay off. +The number of values behind the switch parameter must correspond to the number of relays. The value 1 switches the relay on, 0 switches it off. * Toggle Command: `http://[device-ip]/relays?toggle=1,0,1,1` -The number of numbers behind the parameter switch must correspond to the number of relays. The number 1 causes a toggling of the relay. The number 0 leaves the state of the device. +The number of values behind the parameter switch must correspond to the number of relays. The value 1 causes the relay to toggle, 0 leaves its state unchanged. -Examples +Examples: 1. total of 4 relays, relay 2 will be toggled: `http://[device-ip]/relays?toggle=0,1,0,0` 2. total of 3 relays, relay 1&3 will be switched on: `http://[device-ip]/relays?switch=1,0,1` ## JSON API -You can switch relay state using the following JSON object transmitted to: `http://[device-ip]/json` - +You can toggle the relay state by sending the following JSON object to: `http://[device-ip]/json` Switch relay 0 on: `{"MultiRelay":{"relay":0,"on":true}}` -Switch relay4 3 & 4 off: `{"MultiRelay":[{"relay":2,"on":false},{"relay":3,"on":false}]}` +Switch relay 3 and 4 off: `{"MultiRelay":[{"relay":2,"on":false},{"relay":3,"on":false}]}` + ## MQTT API * `wled`/_deviceMAC_/`relay`/`0`/`command` `on`|`off`|`toggle` * `wled`/_deviceMAC_/`relay`/`1`/`command` `on`|`off`|`toggle` -When relay is switched it will publish a message: +When a relay is switched, a message is published: * `wled`/_deviceMAC_/`relay`/`0` `on`|`off` @@ -42,7 +42,7 @@ When relay is switched it will publish a message: or 2. Use `#define USERMOD_MULTI_RELAY` in wled.h or `-D USERMOD_MULTI_RELAY` in your platformio.ini -You can override the default maximum number (4) of relays by defining MULTI_RELAY_MAX_RELAYS. +You can override the default maximum number of relays (which is 4) by defining MULTI_RELAY_MAX_RELAYS. Example **usermods_list.cpp**: @@ -78,15 +78,15 @@ void registerUsermods() ## Configuration -Usermod can be configured in Usermods settings page. +Usermod can be configured via the Usermods settings page. * `enabled` - enable/disable usermod -* `pin` - GPIO pin where relay is attached to ESP (can be configured at compile time `-D MULTI_RELAY_PINS=xx,xx,...`) +* `pin` - ESP GPIO pin the relay is connected to (can be configured at compile time `-D MULTI_RELAY_PINS=xx,xx,...`) * `delay-s` - delay in seconds after on/off command is received -* `active-high` - toggle high/low activation of relay (can be used to reverse relay states) -* `external` - if enabled WLED does not control relay, it can only be triggered by external command (MQTT, HTTP, JSON or button) +* `active-high` - assign high/low activation of relay (can be used to reverse relay states) +* `external` - if enabled, WLED does not control relay, it can only be triggered by an external command (MQTT, HTTP, JSON or button) * `button` - button (from LED Settings) that controls this relay -* `broadcast`- time in seconds between state broadcasts using MQTT +* `broadcast`- time in seconds between MQTT relay-state broadcasts * `HA-discovery`- enable Home Assistant auto discovery If there is no MultiRelay section, just save current configuration and re-open Usermods settings page. @@ -99,4 +99,4 @@ Have fun - @blazoncek 2021-11 * Added information about dynamic configuration options -* Added button support. \ No newline at end of file +* Added button support. diff --git a/usermods/multi_relay/usermod_multi_relay.h b/usermods/multi_relay/usermod_multi_relay.h index 7381a00d..749b9c75 100644 --- a/usermods/multi_relay/usermod_multi_relay.h +++ b/usermods/multi_relay/usermod_multi_relay.h @@ -66,12 +66,14 @@ class MultiRelay : public Usermod { static const char _HAautodiscovery[]; void publishMqtt(int relay) { +#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/relay/%d"), mqttDeviceTopic, relay); mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off"); } +#endif } /** @@ -182,7 +184,7 @@ class MultiRelay : public Usermod { */ MultiRelay() { const int8_t defPins[] = {MULTI_RELAY_PINS}; - for (int i=0; ipublish(buf, 0, true, json_str, payload_size); } } +#endif /** * setup() is called once at boot. WiFi is not yet connected at this point. @@ -571,6 +575,11 @@ class MultiRelay : public Usermod { DEBUG_PRINTLN(F("MultiRelay config saved.")); } + void appendConfigData() + { + oappend(SET_F("addHB('MultiRelay');")); + } + /** * restore the changeable values * readFromConfig() is called before setup() to populate properties from values stored in cfg.json diff --git a/usermods/photoresistor_sensor_mqtt_v1/README.md b/usermods/photoresistor_sensor_mqtt_v1/README.md index 33d96bc7..f83bb01a 100644 --- a/usermods/photoresistor_sensor_mqtt_v1/README.md +++ b/usermods/photoresistor_sensor_mqtt_v1/README.md @@ -1,10 +1,12 @@ # Photoresister sensor with MQTT -This simple usermod allows attaching a photoresistor sensor like the KY-018 and publish the readings in percentage over MQTT. The frequency of MQTT messages can be modified, and there is a threshold value that can be set so that significant changes in the readings can be published immediately instead of waiting for the next update. This was found to be a good compromise between spamming MQTT messages and delayed updates. +Enables attaching a photoresistor sensor like the KY-018 and publishing the readings as a percentage, via MQTT. The frequency of MQTT messages is user definable. +A threshold value can be set so significant changes in the readings are published immediately vice waiting for the next update. This was found to be a good compromise between excessive MQTT traffic and delayed updates. -I also found it useful to limit the frequency of analog pin reads because otherwise the board hangs. +I also found it useful to limit the frequency of analog pin reads, otherwise the board hangs. -This usermod has only been tested with the KY-018 sensor though should work for any other analog pin sensor. Note that this does not control the LED strip directly, it only publishes MQTT readings for use with other integrations like Home Assistant. +This usermod has only been tested with the KY-018 sensor though it should work for any other analog pin sensor. +Note: this does not control the LED strip directly, it only publishes MQTT readings for use with other integrations like Home Assistant. ## Installation diff --git a/usermods/project_cars_shiftlight/readme.md b/usermods/project_cars_shiftlight/readme.md index 4490a2ba..433da430 100644 --- a/usermods/project_cars_shiftlight/readme.md +++ b/usermods/project_cars_shiftlight/readme.md @@ -1,12 +1,11 @@ ### Shift Light for Project Cars Turn your WLED lights into a rev light and shift indicator for Project Cars. +It's easy to use. -It is pretty straight forward to use. +1. Make sure your WLED device and your PC/console are on the same network and can talk to each other -1. Make sure, your WLED device and your PC/console are on the same network and can talk to each other - -2. Go to the gameplay settings menu in PCARS and enable UDP. There are 9 numbers you can choose from. This is the refresh rate. The lower the number, the better. But you might run into problems at faster rates. +2. Go to the gameplay settings menu in PCARS and enable UDP. There are 9 numbers you can choose from. This is the refresh rate. The lower the number, the better. However, you might run into problems at faster rates. | Number | Updates/Second | | ------ | -------------- | @@ -20,4 +19,5 @@ It is pretty straight forward to use. | 8 | 05 | | 9 | 1 | -3. once you enter a race, WLED should automatically shift to PCARS mode. Done. +3. Once you enter a race, WLED should automatically shift to PCARS mode. +4. Done. diff --git a/usermods/pwm_outputs/readme.md b/usermods/pwm_outputs/readme.md new file mode 100644 index 00000000..0309ad36 --- /dev/null +++ b/usermods/pwm_outputs/readme.md @@ -0,0 +1,27 @@ +# PWM outputs + +v2 Usermod to add generic PWM outputs to WLED. Usermode could be used to control servo motors, LED brightness or any other device controlled by PWM signal. + +## Installation + +Add the compile-time option `-D USERMOD_PWM_OUTPUTS` to your `platformio.ini` (or `platformio_override.ini`). By default upt to 3 PWM outputs could be configured, to increase that limit add build argument `-D USERMOD_PWM_OUTPUT_PINS=10` (replace 10 by desired amount). + +Currently only ESP32 is supported. + +## Configuration + +By default PWM outputs are disabled, navigate to Usermods settings and configure desired PWM pins and frequencies. + +## Usage + +If PWM output is configured, it starts to publish its duty cycle value (0-1) both to state JSON and to info JSON (visible in UI info panel). To set PWM duty cycle, use JSON api (over HTTP or over Serial) + +```json +{ + "pwm": { + "0": {"duty": 0.1}, + "1": {"duty": 0.2}, + ... + } +} +``` diff --git a/usermods/pwm_outputs/usermod_pwm_outputs.h b/usermods/pwm_outputs/usermod_pwm_outputs.h new file mode 100644 index 00000000..1880308c --- /dev/null +++ b/usermods/pwm_outputs/usermod_pwm_outputs.h @@ -0,0 +1,221 @@ +#pragma once +#include "wled.h" + +#ifndef ESP32 + #error This usermod does not support the ESP8266. +#endif + +#ifndef USERMOD_PWM_OUTPUT_PINS + #define USERMOD_PWM_OUTPUT_PINS 3 +#endif + + +class PwmOutput { + public: + + void open(int8_t pin, uint32_t freq) { + + if (enabled_) { + if (pin == pin_ && freq == freq_) { + return; // PWM output is already open + } else { + close(); // Config has changed, close and reopen + } + } + + pin_ = pin; + freq_ = freq; + if (pin_ < 0) + return; + + DEBUG_PRINTF("pwm_output[%d]: setup to freq %d\n", pin_, freq_); + if (!pinManager.allocatePin(pin_, true, PinOwner::UM_PWM_OUTPUTS)) + return; + + channel_ = pinManager.allocateLedc(1); + if (channel_ == 255) { + DEBUG_PRINTF("pwm_output[%d]: failed to quire ledc\n", pin_); + pinManager.deallocatePin(pin_, PinOwner::UM_PWM_OUTPUTS); + return; + } + + ledcSetup(channel_, freq_, bit_depth_); + ledcAttachPin(pin_, channel_); + DEBUG_PRINTF("pwm_output[%d]: init successful\n", pin_); + enabled_ = true; + } + + void close() { + DEBUG_PRINTF("pwm_output[%d]: close\n", pin_); + if (!enabled_) + return; + pinManager.deallocatePin(pin_, PinOwner::UM_PWM_OUTPUTS); + if (channel_ != 255) + pinManager.deallocateLedc(channel_, 1); + channel_ = 255; + duty_ = 0.0f; + enabled_ = false; + } + + void setDuty(const float duty) { + DEBUG_PRINTF("pwm_output[%d]: set duty %f\n", pin_, duty); + if (!enabled_) + return; + duty_ = min(1.0f, max(0.0f, duty)); + const uint32_t value = static_cast((1 << bit_depth_) * duty_); + ledcWrite(channel_, value); + } + + void setDuty(const uint16_t duty) { + setDuty(static_cast(duty) / 65535.0f); + } + + bool isEnabled() const { + return enabled_; + } + + void addToJsonState(JsonObject& pwmState) const { + pwmState[F("duty")] = duty_; + } + + void readFromJsonState(JsonObject& pwmState) { + if (pwmState.isNull()) { + return; + } + float duty; + if (getJsonValue(pwmState[F("duty")], duty)) { + setDuty(duty); + } + } + + void addToJsonInfo(JsonObject& user) const { + if (!enabled_) + return; + char buffer[12]; + sprintf_P(buffer, PSTR("PWM pin %d"), pin_); + JsonArray data = user.createNestedArray(buffer); + data.add(1e2f * duty_); + data.add(F("%")); + } + + void addToConfig(JsonObject& pwmConfig) const { + pwmConfig[F("pin")] = pin_; + pwmConfig[F("freq")] = freq_; + } + + bool readFromConfig(JsonObject& pwmConfig) { + if (pwmConfig.isNull()) + return false; + + bool configComplete = true; + int8_t newPin = pin_; + uint32_t newFreq = freq_; + configComplete &= getJsonValue(pwmConfig[F("pin")], newPin); + configComplete &= getJsonValue(pwmConfig[F("freq")], newFreq); + + open(newPin, newFreq); + + return configComplete; + } + + private: + int8_t pin_ {-1}; + uint32_t freq_ {50}; + static const uint8_t bit_depth_ {12}; + uint8_t channel_ {255}; + float duty_ {0.0f}; + bool enabled_ {false}; +}; + + +class PwmOutputsUsermod : public Usermod { + public: + + static const char USERMOD_NAME[]; + static const char PWM_STATE_NAME[]; + + void setup() { + // By default all PWM outputs are disabled, no setup do be done + } + + void loop() { + } + + void addToJsonState(JsonObject& root) { + JsonObject pwmStates = root.createNestedObject(PWM_STATE_NAME); + for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) { + const PwmOutput& pwm = pwms_[i]; + if (!pwm.isEnabled()) + continue; + char buffer[4]; + sprintf_P(buffer, PSTR("%d"), i); + JsonObject pwmState = pwmStates.createNestedObject(buffer); + pwm.addToJsonState(pwmState); + } + } + + void readFromJsonState(JsonObject& root) { + JsonObject pwmStates = root[PWM_STATE_NAME]; + if (pwmStates.isNull()) + return; + + for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) { + PwmOutput& pwm = pwms_[i]; + if (!pwm.isEnabled()) + continue; + char buffer[4]; + sprintf_P(buffer, PSTR("%d"), i); + JsonObject pwmState = pwmStates[buffer]; + pwm.readFromJsonState(pwmState); + } + } + + void addToJsonInfo(JsonObject& root) { + JsonObject user = root[F("u")]; + if (user.isNull()) + user = root.createNestedObject(F("u")); + + for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) { + const PwmOutput& pwm = pwms_[i]; + pwm.addToJsonInfo(user); + } + } + + void addToConfig(JsonObject& root) { + JsonObject top = root.createNestedObject(USERMOD_NAME); + for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) { + const PwmOutput& pwm = pwms_[i]; + char buffer[8]; + sprintf_P(buffer, PSTR("PWM %d"), i); + JsonObject pwmConfig = top.createNestedObject(buffer); + pwm.addToConfig(pwmConfig); + } + } + + bool readFromConfig(JsonObject& root) { + JsonObject top = root[USERMOD_NAME]; + if (top.isNull()) + return false; + + bool configComplete = true; + for (int i = 0; i < USERMOD_PWM_OUTPUT_PINS; i++) { + PwmOutput& pwm = pwms_[i]; + char buffer[8]; + sprintf_P(buffer, PSTR("PWM %d"), i); + JsonObject pwmConfig = top[buffer]; + configComplete &= pwm.readFromConfig(pwmConfig); + } + return configComplete; + } + + uint16_t getId() { + return USERMOD_ID_PWM_OUTPUTS; + } + + private: + PwmOutput pwms_[USERMOD_PWM_OUTPUT_PINS]; + +}; + +const char PwmOutputsUsermod::USERMOD_NAME[] PROGMEM = "PwmOutputs"; +const char PwmOutputsUsermod::PWM_STATE_NAME[] PROGMEM = "pwm"; diff --git a/usermods/quinled-an-penta/readme.md b/usermods/quinled-an-penta/readme.md index 4a4c0290..2338747d 100644 --- a/usermods/quinled-an-penta/readme.md +++ b/usermods/quinled-an-penta/readme.md @@ -1,5 +1,5 @@ # QuinLED-An-Penta -The (un)official usermod to get the best out of the QuinLED-An-Penta (https://quinled.info/quinled-an-penta/), like using the OLED and the SHT30 temperature/humidity sensor. +The (un)official usermod to get the best out of the QuinLED-An-Penta (https://quinled.info/quinled-an-penta/), e.g. using the OLED and the SHT30 temperature/humidity sensor. ## Requirements * "u8gs" by olikraus, v2.28 or higher: https://github.com/olikraus/u8g2 @@ -31,15 +31,15 @@ lib_deps = ${esp32.lib_deps} ## Some words about the (optional) OLED This mod has been optimized for an SSD1306 driven 128x64 OLED. Using a smaller OLED or an OLED using a different driver will result in unexpected results. I highly recommend using these "two color monochromatic OLEDs", which have the first 16 pixels in a different color than the other 48, e.g. a yellow/blue OLED. -Also note, you need to have an **SPI** driven OLED, **not i2c**! +Note: you _must_ use an **SPI** driven OLED, **not an i2c one**! ### Limitations combined with Ethernet -The initial development of this mod had been done with a beta version of the QuinLED-An-Penta, which had a different IO layout for the OLED: The CS pin used to be IO_0, but has been changed to IO27 with the first v1 public release. Unfortunately, IO27 is used by the Ethernet boards, so WLED will not let you enable the OLED screen, if you're using it with Ethernet. This unfortunately makes the development I've done to support/show Ethernet information void, as it cannot be used. -However (and I've not tried this, as I don't own a v1 board): You can try to modify this mod and try to use IO27 for the OLED and share it with the Ethernet board. It is "just" the chip select pin, so there is a chance that both can coexist and use the same IO. You need to skip WLEDs PinManager for the CS pin, so WLED will not block using it. If you don't know how this works: Leave it. If you know what I'm talking about: Try it and please let me know on the Intermit.Tech (QuinLED) Discord server: https://discord.gg/WdbAauG +The initial development of this mod was done with a beta version of the QuinLED-An-Penta, which had a different IO layout for the OLED: The CS pin _was_ IO_0, but has been changed to IO27 with the first v1 public release. Unfortunately, IO27 is used by Ethernet boards, so WLED will not let you enable the OLED screen, if you're using it with Ethernet. Unfortunately, that makes the development I've done to support/show Ethernet information invalid, as it cannot be used. +However, (and I've not tried this, as I don't own a v1 board) you can modify this usermod and try to use IO27 for the OLED and share it with the Ethernet board. It is "just" the chip select pin, so there is a chance that both can coexist and use the same IO. You need to skip WLEDs PinManager for the CS pin, so WLED will not block using it. If you don't know how this works, don't change it. If you know what I'm talking about, try it and please let me know on the Intermit.Tech (QuinLED) Discord server: https://discord.gg/WdbAauG ### My OLED flickers after some time, what should I do? -That's a tricky one: During development I saw that the OLED sometimes starts to "bug out" / flicker and won't work anymore. This seems to be caused by the high PWM interference the board produces. It seems to loose its settings and then doesn't know how to draw anymore. Turns out the only way to fix this is to call the libraries `begin()` method again which will re-initialize the display. -If you're facing this issue, you can enable a setting I've added which will call the `begin()` roughly every 60 seconds between a page change. This will make the page change take ~500ms, but will fix the display. +That's a tricky one. During development I saw that the OLED sometimes starts to "drop out" / flicker and won't work anymore. This seems to be caused by the high PWM interference the board produces. It seems to lose its settings then doesn't know how to draw anymore. Turns out the only way to fix this is to call the libraries `begin()` method again which re-initializes the display. +If you're facing this issue, you can enable a setting which will call the `begin()` roughly every 60 seconds between page changes. This will make the page change take ~500ms, but will fix the display. ## Configuration @@ -53,11 +53,11 @@ Navigate to the "Config" and then to the "Usermods" section. If you compiled WLE * Possible values: Enabled/Disabled * Default: Disabled * OLED-Flip-Screen-180: - * What it does: Flips the screen 180° / upside-down + * What it does: Flips the screen 180° * Possible values: Enabled/Disabled * Default: Disabled * OLED-Seconds-Per-Page: - * What it does: Defines how long the OLED should stay on one page in seconds before changing to the next + * What it does: Number of seconds the OLED should stay on one page before changing pages * Possible values: Enabled/Disabled * Default: 10 * OLED-Fix-Bugged-Screen: @@ -76,4 +76,4 @@ Navigate to the "Config" and then to the "Usermods" section. If you compiled WLE * First implementation. ## Credits -ezcGman | Andy: Find me on the Intermit.Tech (QuinLED) Discord server: https://discord.gg/WdbAauG \ No newline at end of file +ezcGman | Andy: Find me on the Intermit.Tech (QuinLED) Discord server: https://discord.gg/WdbAauG diff --git a/usermods/readme.md b/usermods/readme.md index 0c56efae..8aa8d6ab 100644 --- a/usermods/readme.md +++ b/usermods/readme.md @@ -2,17 +2,17 @@ This folder serves as a repository for usermods (custom `usermod.cpp` files)! -If you have created an usermod that you believe is useful (for example to support a particular sensor, display, feature...), feel free to contribute by opening a pull request! +If you have created a usermod you believe is useful (for example to support a particular sensor, display, feature...), feel free to contribute by opening a pull request! In order for other people to be able to have fun with your usermod, please keep these points in mind: - Create a folder in this folder with a descriptive name (for example `usermod_ds18b20_temp_sensor_mqtt`) - Include your custom files -- If your usermod requires changes to other WLED files, please write a `readme.md` outlining the steps one has to take to use the usermod +- If your usermod requires changes to other WLED files, please write a `readme.md` outlining the steps one needs to take - Create a pull request! - If your feature is useful for the majority of WLED users, I will consider adding it to the base code! -While I do my best to not break too much, keep in mind that as WLED is being updated, usermods might break. +While I do my best to not break too much, keep in mind that as WLED is updated, usermods might break. I am not actively maintaining any usermod in this directory, that is your responsibility as the creator of the usermod. For new usermods, I would recommend trying out the new v2 usermod API, which allows installing multiple usermods at once and new functions! diff --git a/usermods/rgb-rotary-encoder/readme.md b/usermods/rgb-rotary-encoder/readme.md index 2bf0ecb7..ba5aad4d 100644 --- a/usermods/rgb-rotary-encoder/readme.md +++ b/usermods/rgb-rotary-encoder/readme.md @@ -5,8 +5,8 @@ This usermod-v2 adds support for the awesome RGB Rotary Encoder Board by Adam Ze https://user-images.githubusercontent.com/3090131/124680599-0180ab80-dec7-11eb-9065-a6d08ebe0287.mp4 ## Credits -The actual / original code that does the different LED modes is from Adam Zeloof. So I don't take credit for these. But I ported it to WLED, which involved replacing the LED library he used (because, guess what, WLED already has one; so no need to add another one, but use whatever WLED uses), plus the rotary encoder library, because that one was not compatible with ESP, only Arduino. -So it was quite more work than I hoped, but I got there eventually :) +The actual / original code that controls the LED modes is from Adam Zeloof. I take no credit for it. I ported it to WLED, which involved replacing the LED library he used, (because WLED already has one, so no need to add another one) plus the rotary encoder library because it was not compatible with ESP, only Arduino. +It was quite a bit more work than I hoped, but I got there eventually :) ## Requirements * "ESP Rotary" by Lennart Hennigs, v1.5.0 or higher: https://github.com/LennartHennigs/ESPRotary @@ -33,25 +33,25 @@ lib_deps = ${esp8266.lib_deps} ``` ## How to connect the board to your ESP -We gonna need (minimum) three or (maximum) four GPIOs for the board: -* "ea": Basically tells if the encoder goes into one or the other direction -* "eb": Same thing, but the other direction -* "di": LED data in. To actually control the LEDs -* *(optional)* "sw": The integrated switch in the rotary encoder. Can be omitted for the bare functionality of just controlling the brightness +We'll need (minimum) three or (maximum) four GPIOs for the board: +* "ea": reports the encoder direction +* "eb": Same thing, opposite direction +* "di": LED data in. +* *(optional)* "sw": The integrated switch in the rotary encoder. Can be omitted for the bare functionality of controlling only the brightness -We also gonna need some power, so: +We'll also need power: * "vdd": Needs to be connected to **+5V**. -* "gnd": Well, it's GND. +* "gnd": Ground. -You can freely pick the GPIOs, it doesn't matter. Those will be configured in the "Usermods" section in the WLED web panel: +You can freely pick the GPIOs, it doesn't matter. Those will be configured in the "Usermods" section of the WLED web panel: ## Configuration -Navigate to the "Config" and then to the "Usermods" section. If you compiled WLED with `-D RGB_ROTARY_ENCODER`, you will see the config for it there. The settings there are the GPIOs we mentioned before (*Note: The switch pin is not there, as this can just be configured the "normal" button on the "LED Preferences" page*), plus a few more: +Navigate to the "Config" and then to the "Usermods" section. If you compiled WLED with `-D RGB_ROTARY_ENCODER`, you will see the config for it there. The settings there are the aforementioned GPIOs, (*Note: The switch pin is not there, as this can just be configured the "normal" button on the "LED Preferences" page*) plus a few more: * LED pin: * Possible values: Any valid and available GPIO * Default: 3 - * What it does: Pin to control the LED ring + * What it does: controls the LED ring * ea pin: * Possible values: Any valid and available GPIO * Default: 15 @@ -63,7 +63,7 @@ Navigate to the "Config" and then to the "Usermods" section. If you compiled WLE * LED Mode: * Possible values: 1-3 * Default: 3 - * What it does: The usermod provides three different modes of how the LEDs can look like. Here's an example: https://github.com/isotope-engineering/RGB-Encoder-Board/blob/master/images/rgb-encoder-animations.gif + * What it does: The usermod provides three different modes of how the LEDs can appear. Here's an example: https://github.com/isotope-engineering/RGB-Encoder-Board/blob/master/images/rgb-encoder-animations.gif * Up left is "1" * Up right is not supported / doesn't make sense for brightness control * Bottom left is "2" @@ -71,15 +71,15 @@ Navigate to the "Config" and then to the "Usermods" section. If you compiled WLE * LED Brightness: * Possible values: 1-255 * Default: 64 - * What it does: Brightness of the LED ring + * What it does: sets LED ring Brightness * Steps per click: * Possible values: Any positive number * Default: 4 - * What it does: With each "click", a rotary encoder actually increments it's "steps". Most rotary encoder do four "steps" per "click". I know this sounds super weird, so just leave this the default value, unless your rotary encoder behaves weirdly, like with one click, it makes two LEDs light up, or you sometimes need two click for one LED. Then you should play around with this value or write a small sketch using the same "ESP Rotary" library and read out the steps it does. + * What it does: With each "click", a rotary encoder actually increments its "steps". Most rotary encoders produce four "steps" per "click". Leave this at the default value unless your rotary encoder behaves strangely. e.g. with one click, it makes two LEDs light up, or you need two clicks for one LED. If that's the case, adjust this value or write a small sketch using the same "ESP Rotary" library and read out the steps it produce. * Increment per click: * Possible values: Any positive number * Default: 5 - * What it does: Most rotary encoder have 20 "clicks", so basically 20 positions. This value should be set to 100 / `number of clicks` + * What it does: Most rotary encoders have 20 "clicks" or positions. This value should be set to 100/`number of clicks` ## Change log 2021-07 diff --git a/usermods/sensors_to_mqtt/readme.md b/usermods/sensors_to_mqtt/readme.md index 7f2d6407..d427d3e1 100644 --- a/usermods/sensors_to_mqtt/readme.md +++ b/usermods/sensors_to_mqtt/readme.md @@ -1,12 +1,12 @@ -# Sensors To Home Assistant (or mqtt) +# Send sensor data To Home Assistant -This usermod will publish values of the BMP280, CCS811 and Si7021 sensors to Home Assistant via MQTT. +Publishes BMP280, CCS811 and Si7021 measurements to Home Assistant via MQTT. -Its using home assistant automatic device discovery feature. +Uses Home Assistant Automatic Device Discovery. -The use of Home Assistant is not mandatory; it will publish the sensor values via MQTT just fine without it. +The use of Home Assistant is not mandatory. The mod will publish sensor values via MQTT just fine without it. -Its resusing the mqtt connection set in the WLED web user interface. +Uses the MQTT connection set in the WLED web user interface. ## Maintainer @@ -15,12 +15,12 @@ twitter.com/mpronk89 ## Features - Reads BMP280, CCS811 and Si7021 senors -- Publishes via MQTT, configured via webui of wled +- Publishes via MQTT, configured via WLED webUI - Announces device in Home Assistant for easy setup - Efficient energy usage - Updates every 60 seconds -## Example mqtt topics: +## Example MQTT topics: `$mqttDeviceTopic` is set in webui of WLED! @@ -40,7 +40,7 @@ IAQ: $mqttDeviceTopic/iaq ### Requirements 1. BMP280/CCS811/Si7021 sensor. E.g. https://aliexpress.com/item/32979998543.html -2. A microcontroller which can talk i2c, e.g. esp32 +2. A microcontroller that supports i2c. e.g. esp32 ### installation @@ -77,7 +77,7 @@ SDA_PIN = 4; adafruit/Adafruit Si7021 Library @ 1.4.0 ``` -The #ifdefs in `usermods_list.cpp` should do the rest :) +The #ifdefs in `usermods_list.cpp` should do the rest # Credits diff --git a/usermods/sensors_to_mqtt/usermod_v2_SensorsToMqtt.h b/usermods/sensors_to_mqtt/usermod_v2_SensorsToMqtt.h index dd7aedc1..972e2c86 100644 --- a/usermods/sensors_to_mqtt/usermod_v2_SensorsToMqtt.h +++ b/usermods/sensors_to_mqtt/usermod_v2_SensorsToMqtt.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/readme.md b/usermods/seven_segment_display/readme.md index ca52383d..a5294701 100644 --- a/usermods/seven_segment_display/readme.md +++ b/usermods/seven_segment_display/readme.md @@ -1,25 +1,25 @@ # Seven Segment Display -Usermod that uses the overlay feature to create a configurable seven segment display. -This has only been tested on a single configuration. Colon support is entirely untested. +Uses the overlay feature to create a configurable seven segment display. +This has only been tested on a single configuration. Colon support has _not_ been tested. ## Installation Add the compile-time option `-D USERMOD_SEVEN_SEGMENT` to your `platformio.ini` (or `platformio_override.ini`) or use `#define USERMOD_SEVEN_SEGMENT` in `my_config.h`. ## Settings -Settings can be controlled through both the usermod setting page and through MQTT with a raw payload. +Settings can be controlled via both the usermod setting page and through MQTT with a raw payload. ##### Example Topic ```/sevenSeg/perSegment/set``` Payload ```3``` #### perSegment -- ssLEDPerSegment -The number of individual LEDs per segment. There are 7 segments per digit. +The number of individual LEDs per segment. 7 segments per digit. #### perPeriod -- ssLEDPerPeriod -The number of individual LEDs per period. A ':' has 2x periods. +The number of individual LEDs per period. A ':' (colon) has two periods. #### startIdx -- ssStartLED -Index of the LED that the display starts at. Allows a seven segment display to be in the middle of a string. +Index of the LED the display starts at. Enabless a seven segment display to be in the middle of a string. #### timeEnable -- ssTimeEnabled -When true, when displayMask is configured for a time output and no message is set the time will be displayed. +When true, when displayMask is configured for a time output and no message is set, the time will be displayed. #### scrollSpd -- ssScrollSpeed Time, in milliseconds, between message shifts when the length of displayMsg exceeds the length of the displayMask. #### displayMask -- ssDisplayMask @@ -35,9 +35,9 @@ All others for alpha numeric, (will be blank when displaying time) ```HHMMSS ``` ```hh:MM:SS ``` #### displayMsg -- ssDisplayMessage -Message to be displayed across the display. If the length exceeds the length of the displayMask the message will scroll at scrollSpd. To 'remove' a message or revert back to time, if timeEnabled is true, set the message to '~'. +Message to be displayed. If the message length exceeds the length of displayMask, the message will scroll at scrollSpd. To 'remove' a message or revert back to time, if timeEnabled is true, set the message to '~'. #### displayCfg -- ssDisplayConfig -The order that your LEDs are configured. All seven segments in the display need to be wired the same way. +The order your LEDs are configured in. All segments in the display need to be wired the same way.
            -------
          /   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..e2b65910 100644
--- a/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
+++ b/usermods/usermod_v2_auto_save/usermod_v2_auto_save.h
@@ -79,6 +79,10 @@ class AutoSaveUsermod : public Usermod {
         month(localTime), day(localTime),
         hour(localTime), minute(localTime), second(localTime));
       cacheInvalidate++;  // force reload of presets
+      DEBUG_PRINT(F("UM autosave: saving preset "));
+      DEBUG_PRINT(autoSavePreset);
+      DEBUG_PRINT(F(" => "));
+      DEBUG_PRINTLN(presetNameBuffer);
       savePreset(autoSavePreset, presetNameBuffer);
     }
 
@@ -86,7 +90,7 @@ class AutoSaveUsermod : public Usermod {
       #ifdef USERMOD_FOUR_LINE_DISPLAY
       if (display != nullptr) {
         display->wakeDisplay();
-        display->overlay("Settings", "Auto Saved", 1500);
+        if (display->canDraw()) display->overlay("Settings", "Auto Saved", 1500);   // WLEDMM bugfix
       }
       #endif
     }
@@ -204,6 +208,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_fastled/readme.md b/usermods/usermod_v2_fastled/readme.md
new file mode 100644
index 00000000..93707655
--- /dev/null
+++ b/usermods/usermod_v2_fastled/readme.md
@@ -0,0 +1,10 @@
+# Usermods API v2 example usermod
+
+In this usermod file you can find the documentation on how to take advantage of the new version 2 usermods!
+
+## Installation 
+
+Copy `usermod_v2_fastled.h` to the wled00 directory.  
+Uncomment the corresponding lines in `usermods_list.cpp` and compile!  
+_(You shouldn't need to actually install this, it does nothing useful)_
+
diff --git a/usermods/usermod_v2_fastled/usermod_v2_fastled.h b/usermods/usermod_v2_fastled/usermod_v2_fastled.h
new file mode 100644
index 00000000..ae073445
--- /dev/null
+++ b/usermods/usermod_v2_fastled/usermod_v2_fastled.h
@@ -0,0 +1,358 @@
+#pragma once
+
+#include "wled.h"
+
+//WLEDMM
+
+
+// Polar basics demo for the 
+// FastLED Podcast #2
+// https://www.youtube.com/watch?v=KKjFRZFBUrQ
+//
+// VO.1 preview version
+// by Stefan Petrick 2023
+// This code is licenced under a 
+// Creative Commons Attribution 
+// License CC BY-NC 3.0
+
+class PolarBasics {
+  private:
+
+  public:
+    float runtime;                          // elapse ms since startup
+    float newdist, newangle;                // parameters for image reconstruction
+    float z;                                // 3rd dimension for the 3d noise function
+    float offset_x, offset_y;               // wanna shift the cartesians during runtime?
+    float scale_x, scale_y;                 // cartesian scaling in 2 dimensions
+    float dist, angle;                      // the actual polar coordinates
+
+    int x, y;                               // the cartesian coordiantes
+    int num_x;// = WIDTH;                      // horizontal pixel count
+    int num_y;// = HEIGHT;                     // vertical pixel count
+
+    // Background for setting the following 2 numbers: the FastLED inoise16() function returns
+    // raw values ranging from 0-65535. In order to improve contrast we filter this output and
+    // stretch the remains. In histogram (photography) terms this means setting a blackpoint and
+    // a whitepoint. low_limit MUST be smaller than high_limit.
+
+    uint16_t low_limit;//  = 30000;            // everything lower drawns in black
+                                            // higher numer = more black & more contrast present
+    uint16_t high_limit;// = 50000;            // everything higher gets maximum brightness & bleeds out
+                                            // lower number = the result will be more bright & shiny
+
+    float center_x;// = (num_x / 2) - 0.5;     // the reference point for polar coordinates
+    float center_y;// = (num_y / 2) - 0.5;     // (can also be outside of the actual xy matrix)
+    //float center_x = 20;                  // the reference point for polar coordinates
+    //float center_y = 20;                
+
+    //WLEDMM: assign 32x32 fixed for the time being
+    float theta   [32] [32];          // look-up table for all angles
+    float distance[32] [32];          // look-up table for all distances
+    float vignette[32] [32];
+    float inverse_vignette[32] [32];
+
+    // std::vector> theta;          // look-up table for all angles
+    // std::vector> distance;          // look-up table for all distances
+    // std::vector> vignette;
+    // std::vector> inverse_vignette;
+
+    float spd;                            // can be used for animation speed manipulation during runtime
+
+    float show1, show2, show3, show4, show5; // to save the rendered values of all animation layers
+    float red, green, blue;                  // for the final RGB results after the colormapping
+
+    float c, d, e, f;                                                   // factors for oscillators
+    float linear_c, linear_d, linear_e, linear_f;                       // linear offsets
+    float angle_c, angle_d, angle_e, angle_f;                           // angle offsets
+    float noise_angle_c, noise_angle_d, noise_angle_e, noise_angle_f;   // angles based on linear noise travel
+    float dir_c, dir_d, dir_e, dir_f;                                   // direction multiplicators
+
+  void init () {
+    num_x = SEGMENT.virtualWidth(); // horizontal pixel count
+    num_y = SEGMENT.virtualHeight(); // vertical pixel count
+    low_limit  = 30000;            // everything lower drawns in black
+                                            // higher numer = more black & more contrast present
+    high_limit = 50000;            // everything higher gets maximum brightness & bleeds out
+                                            // lower number = the result will be more bright & shiny
+    center_x = (num_x / 2) - 0.5;     // the reference point for polar coordinates
+    center_y = (num_y / 2) - 0.5;     // (can also be outside of the actual xy matrix)
+
+    //allocate memory for the 2D arrays
+    // theta.resize(num_x, std::vector(num_y, 0));
+    // distance.resize(num_x, std::vector(num_y, 0));
+    // vignette.resize(num_x, std::vector(num_y, 0));
+    // inverse_vignette.resize(num_x, std::vector(num_y, 0));
+  }
+
+  PolarBasics() {
+    USER_PRINTLN("constructor");
+  }
+  ~PolarBasics() {
+    USER_PRINTLN("destructor");
+  }
+
+  void speedratiosAndOscillators() {
+    // set speedratios for the offsets & oscillators
+  
+    spd = 0.05  ;
+    c   = 0.013  ;
+    d   = 0.017   ;
+    e   = 0.2  ;
+    f   = 0.007  ;
+
+    calculate_oscillators();     // get linear offsets and oscillators going
+  }
+
+  void forLoop() {
+      // pick polar coordinates from look the up table 
+
+      dist  = distance [x] [y];
+      angle = theta    [y] [x];
+
+      // Generation of one layer. Explore the parameters and what they do.
+   
+      scale_x  = 10000;                       // smaller value = zoom in, bigger structures, less detail
+      scale_y  = 10000;                       // higher = zoom out, more pixelated, more detail
+      z        = 0;                           // must be >= 0
+      newangle = angle + angle_c;
+      newdist  = dist;
+      offset_x = 0;                        // must be >=0
+      offset_y = 0;                        // must be >=0
+      
+      show1 = render_pixel();
+
+              
+      // Colormapping - Assign rendered values to colors 
+      
+      red   = show1;
+      green = 0;
+      blue  = 0;
+
+      // Check the final results.
+      // Discard faulty RGB values & write the valid results into the framebuffer.
+      
+      write_pixel_to_framebuffer();
+  }
+
+  void calculate_oscillators() {
+    
+    runtime = millis();                          // save elapsed ms since start up
+
+    runtime = runtime * spd;                     // global anaimation speed
+
+    linear_c = runtime * c;                      // some linear rising offsets 0 to max
+    linear_d = runtime * d;
+    linear_e = runtime * e;
+    linear_f = runtime * f;
+
+    angle_c = fmodf(linear_c, 2 * PI);           // some cyclic angle offsets  0 to 2*PI
+    angle_d = fmodf(linear_d, 2 * PI);
+    angle_e = fmodf(linear_e, 2 * PI);
+    angle_f = fmodf(linear_f, 2 * PI);
+
+    dir_c = sinf(angle_c);                       // some direction oscillators -1 to 1
+    dir_d = sinf(angle_d);
+    dir_e = sinf(angle_e);
+    dir_f = sinf(angle_f);
+
+    uint16_t noi;
+    noi =  inoise16(10000 + linear_c * 100000);    // some noise controlled angular offsets
+    noise_angle_c = map_float(noi, 0, 65535 , 0, 4*PI);
+    noi =  inoise16(20000 + linear_d * 100000);
+    noise_angle_d = map_float(noi, 0, 65535 , 0, 4*PI);
+    noi =  inoise16(30000 + linear_e * 100000);
+    noise_angle_e = map_float(noi, 0, 65535 , 0, 4*PI);
+    noi =  inoise16(40000 + linear_f * 100000);
+    noise_angle_f = map_float(noi, 0, 65535 , 0, 4*PI);
+  }
+
+
+  // given a static polar origin we can precalculate 
+  // all the (expensive) polar coordinates
+
+  void render_polar_lookup_table() {
+
+    for (int xx = 0; xx < num_x; xx++) {
+      for (int yy = 0; yy < num_y; yy++) {
+
+          float dx = xx - center_x;
+          float dy = yy - center_y;
+
+        distance[xx] [yy] = hypotf(dx, dy);
+        theta[xx] [yy]    = atan2f(dy, dx);
+        
+      }
+    }
+  }
+
+  // convert polar coordinates back to cartesian
+  // & render noise value there
+
+  float render_pixel() {
+
+    // convert polar coordinates back to cartesian ones
+
+    float newx = (offset_x + center_x - (cosf(newangle) * newdist)) * scale_x;
+    float newy = (offset_y + center_y - (sinf(newangle) * newdist)) * scale_y;
+
+    // render noisevalue at this new cartesian point
+
+    uint16_t raw_noise_field_value = inoise16(newx, newy, z);
+
+    // a lot is happening here, namely
+    // A) enhance histogram (improve contrast) by setting the black and white point
+    // B) scale the result to a 0-255 range
+    // it's the contrast boosting & the "colormapping" (technically brightness mapping)
+
+    if (raw_noise_field_value < low_limit)  raw_noise_field_value =  low_limit;
+    if (raw_noise_field_value > high_limit) raw_noise_field_value = high_limit;
+
+    float scaled_noise_value = map_float(raw_noise_field_value, low_limit, high_limit, 0, 255);
+
+    return scaled_noise_value;
+
+    // done, we've just rendered one color value for one single pixel
+  }
+
+  // float mapping maintaining 32 bit precision
+  // we keep values with high resolution for potential later usage
+
+  float map_float(float x, float in_min, float in_max, float out_min, float out_max) { 
+    
+    float result = (x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min;
+    if (result < out_min) result = out_min;
+    if( result > out_max) result = out_max;
+
+    return result; 
+  }
+
+  // Avoid any possible color flicker by forcing the raw RGB values to be 0-255.
+  // This enables to play freely with random equations for the colormapping
+  // without causing flicker by accidentally missing the valid target range.
+
+  void rgb_sanity_check() {
+
+        // rescue data if possible: when negative return absolute value
+        if (red < 0)     red = abs(red);
+        if (green < 0) green = abs(green);
+        if (blue < 0)   blue = abs(blue);
+        
+        // discard everything above the valid 0-255 range
+        if (red   > 255)   red = 255;
+        if (green > 255) green = 255;
+        if (blue  > 255)  blue = 255;
+    
+  }
+
+  void write_pixel_to_framebuffer() {
+    
+        // the final color values shall not exceed 255 (to avoid flickering pixels caused by >255 = black...)
+        // negative values * -1 
+
+        rgb_sanity_check();
+
+        CRGB finalcolor = CRGB(red, green, blue);
+      
+        // write the rendered pixel into the framebutter
+        SEGMENT.setPixelColorXY(x,y,finalcolor);
+  }
+
+  // precalculate a radial brightness mask
+
+  void render_vignette_table(float filter_radius) {
+
+    for (int xx = 0; xx < num_x; xx++) {
+      for (int yy = 0; yy < num_y; yy++) {
+
+        vignette[xx] [yy] = (filter_radius - distance[xx] [yy]) / filter_radius; 
+        if (vignette[xx] [yy] < 0) vignette[xx] [yy] = 0;  
+      }
+    }
+  }
+
+};
+
+//effect functions
+uint16_t mode_PolarBasics(void) { 
+
+  PolarBasics* pb;
+
+
+  if(!SEGENV.allocateData(sizeof(PolarBasics))) {SEGMENT.fill(SEGCOLOR(0)); return 350;} //mode_static(); //allocation failed
+
+  pb = reinterpret_cast(SEGENV.data);
+
+  //first time init
+  if (SEGENV.call == 0) {
+
+    USER_PRINTF("mode_PolarBasics %d\n", sizeof(PolarBasics));
+    //  if (SEGENV.call == 0) SEGMENT.setUpLeds();
+
+    pb->init();
+
+    pb->render_polar_lookup_table();          // precalculate all polar coordinates 
+                                        // to improve the framerate
+    pb->render_vignette_table(9.5);           // the number is the desired radius in pixel
+                                        // WIDTH/2 generates a circle
+  }
+
+  pb->speedratiosAndOscillators();
+
+  // ...and now let's generate a frame 
+
+  for (pb->x = 0; pb->x < pb->num_x; pb->x++) {
+    for (pb->y = 0; pb->y < pb->num_y; pb->y++) {
+
+      pb->forLoop();
+
+    }
+  }
+
+  // FastLED.show();
+
+  return FRAMETIME;
+}
+
+static const char _data_FX_mode_PolarBasics[] PROGMEM = "💡Polar Basics ☾@;;;2";
+
+//class name. Use something descriptive and leave the ": public Usermod" part :)
+class FastledUsermod : public Usermod {
+
+  private:
+
+
+  public:
+
+    FastledUsermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM
+
+    void setup() {
+      strip.addEffect(255, &mode_PolarBasics, _data_FX_mode_PolarBasics);
+
+      initDone = true;
+    }
+
+
+    void connected() {
+    }
+
+
+    void loop() {
+      if (!enabled || strip.isUpdating()) return;
+
+      // do your magic here
+      if (millis() - lastTime > 1000) {
+        //Serial.println("I'm alive!");
+        lastTime = millis();
+      }
+    }
+
+
+    uint16_t getId()
+    {
+      return USERMOD_ID_FASTLED;
+    }
+
+};
+
+
+
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..ff60a4d4 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,60 +1,62 @@
 #pragma once
 
+#include               // WLEDMM: make sure that I2C drivers have the "right" Wire Object
+#include 
+#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 second 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 behaviour without parallel update task - slower, but more robust. May delay other tasks like LEDs or audioreactive!!
+#endif
+
+//#define OLD_4LD_FONTS          // comment out if you prefer the "classic" look with blocky fonts (saves 1K flash)
+
 //
-// Insired by the usermod_v2_four_line_display
+// Inspired by the usermod_v2_four_line_display
 //
 // v2 usermod for using 128x32 or 128x64 i2c
 // OLED displays to provide a four line display
 // for WLED.
 //
 // Dependencies
-// * This usermod REQURES the ModeSortUsermod
-// * This Usermod works best, by far, when coupled 
-//   with RotaryEncoderUIUsermod.
+// * This usermod does not REQUIRE the ModeSortUsermod any more
+// * This usermod works best, by far, when coupled 
+//   with RotaryEncoderUI_ALT usermod.
 //
 // Make sure to enable NTP and set your time zone in WLED Config | Time.
 //
 // REQUIREMENT: You must add the following requirements to
 // REQUIREMENT: "lib_deps" within platformio.ini / platformio_override.ini
-// REQUIREMENT: *  U8g2  (the version already in platformio.ini is fine)
-// REQUIREMENT: *  Wire
+// REQUIREMENT: olikraus/U8g2@ ^2.34.15 (the version already in platformio.ini is fine)
 //
 
 //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
@@ -92,33 +94,58 @@ typedef enum {
   SSD1305,      // U8X8_SSD1305_128X32_ADAFRUIT_HW_I2C
   SSD1305_64,   // U8X8_SSD1305_128X64_ADAFRUIT_HW_I2C
   SSD1306_SPI,  // U8X8_SSD1306_128X32_NONAME_HW_SPI
-  SSD1306_SPI64 // U8X8_SSD1306_128X64_NONAME_HW_SPI
+  SSD1306_SPI64=7, // U8X8_SSD1306_128X64_NONAME_HW_SPI
+  SSD1309_SPI64=8, // U8X8_SSD1309_128X64_NONAME0_4W_HW_SPI
+  SSD1327_SPI128=9 // U8X8_SSD1327_WS_128X128_4W_SW_SPI
 } DisplayType;
 
 
 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
 
+#if defined(ARDUINO_ARCH_ESP32) && defined(FLD_ESP32_USE_THREADS)
+    // semaphores - needed on ESP32 only, as we use a separate task to update the display
+    SemaphoreHandle_t drawMux = xSemaphoreCreateBinary();      // for drawstring and drawglyph functions (to prevent concurrent access to HW)
+    SemaphoreHandle_t drawMuxBig = xSemaphoreCreateBinary();   // for draw2x2GlyphIcons() and showCurrentEffectOrPalette() - more complex and not thread-safe
+    const TickType_t maxWait =     300 * portTICK_PERIOD_MS;   // wait max. 300ms (drawstring semaphore)
+    const TickType_t maxWaitLong = 800 * portTICK_PERIOD_MS;   // wait max. 800ms (big drawing semaphore)
+    #define FLD_SemaphoreTake(x,t)  xSemaphoreTake((x),(t))
+    #define FLD_SemaphoreGive(x)    xSemaphoreGive(x)
+#else
+    // 8266 or no tasks - no semaphores
+    #define FLD_SemaphoreTake(x,t) pdTRUE
+    #define FLD_SemaphoreGive(x)
+    #if !defined(ARDUINO_ARCH_ESP32) && !defined(pdTRUE)
+      #define pdTRUE true
+    #endif
+#endif
+
     #ifndef FLD_SPI_DEFAULT
     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. Initially 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,8 +154,18 @@ 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;
+    bool driverHW = false;
+    bool driverSPI = false;
 
     // Next variables hold the previous known values to determine if redraw is
     // required.
@@ -178,6 +215,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 (u8x8 == nullptr) return;
+
       u8x8_t *u8x8_struct = u8x8->getU8x8();
       u8x8_cad_StartTransfer(u8x8_struct);
       u8x8_cad_SendCmd(u8x8_struct, 0x0db); //address of value
@@ -189,45 +229,93 @@ class FourLineDisplayUsermod : public Usermod {
      * Wrappers for screen drawing
      */
     void setFlipMode(uint8_t mode) {
-      if (type == NONE || !enabled) return;
+      if (!typeOK || !enabled) return;    // WLEDMM make sure the display is initialized before we try to draw on it
+      if (u8x8 == nullptr) return;
       u8x8->setFlipMode(mode);
     }
     void setContrast(uint8_t contrast) {
-      if (type == NONE || !enabled) return;
+      if (!typeOK || !enabled) return;    // WLEDMM make sure the display is initialized before we try to draw on it
+      if (u8x8 == nullptr) return;
       u8x8->setContrast(contrast);
     }
     void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
-      if (type == NONE || !enabled) return;
+      if (!typeOK || !enabled) return;    // WLEDMM make sure the display is initialized before we try to draw on it
+      if (u8x8 == nullptr) return;
+      if (FLD_SemaphoreTake(drawMux, maxWait) != pdTRUE) return;      // WLEDMM acquire draw mutex
+
+#if  defined(ARDUINO_ARCH_ESP32) && !defined(OLD_4LD_FONTS)           // WLEDMM use nicer 2x2 font on ESP32
+      if (!ignoreLH && lineHeight>1) { 
+        if(strlen(string) > 3)                    // WLEDMM little hack - less than 3 chars -> show in bold
+          u8x8->setFont(u8x8_font_7x14_1x2_r);    // normal
+        else
+          u8x8->setFont(u8x8_font_8x13B_1x2_r);   // bold
+        u8x8->drawString(col, row, string);
+      }
+      else {
+        u8x8->setFont(u8x8_font_chroma48medium8_r);
+        u8x8->drawString(col, row, string);
+      }
+#else
       u8x8->setFont(u8x8_font_chroma48medium8_r);
-      if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
-      else                            u8x8->drawString(col, row, string);
+      if (!ignoreLH && lineHeight>1) u8x8->draw1x2String(col, row, string);
+      else                           u8x8->drawString(col, row, string);
+#endif
+      FLD_SemaphoreGive(drawMux);                                     // WLEDMM release draw mutex
     }
     void draw2x2String(uint8_t col, uint8_t row, const char *string) {
-      if (type == NONE || !enabled) return;
+      if (!typeOK || !enabled) return;
+      if (u8x8 == nullptr) return;
+      if (FLD_SemaphoreTake(drawMux, maxWait) != pdTRUE) return;      // WLEDMM acquire draw mutex
+#if  defined(ARDUINO_ARCH_ESP32) && !defined(OLD_4LD_FONTS)           // WLEDMM use nicer 2x2 font on ESP32
+      if (lineHeight>1) {                            // WLEDMM use 2x3 on 128x64 displays
+        //u8x8->setFont(u8x8_font_profont29_2x3_r);   // sans serif 2x3
+        u8x8->setFont(u8x8_font_courB18_2x3_r);       // courier bold 2x3
+        u8x8->drawString(col, row + (row >3? 1:0), string);
+      } else {
+        //u8x8->setFont(u8x8_font_lucasarts_scumm_subtitle_o_2x2_r);
+        //u8x8->setFont(u8x8_font_lucasarts_scumm_subtitle_r_2x2_r);
+        u8x8->setFont(u8x8_font_px437wyse700b_2x2_r);
+        u8x8->drawString(col, row, string);
+      }
+#else
       u8x8->setFont(u8x8_font_chroma48medium8_r);
-      u8x8->draw2x2String(col, row, string);
+      if (lineHeight>1) {                            // WLEDMM use 2x3 on 128x64 displays
+        u8x8->draw2x2String(col, row + (row >3? 1:0), string);
+      } else {
+        u8x8->draw2x2String(col, row, string);
+      }
+#endif
+      FLD_SemaphoreGive(drawMux);                                     // WLEDMM release draw mutex
     }
     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;
+      if (FLD_SemaphoreTake(drawMux, maxWait) != pdTRUE) return;      // WLEDMM acquire draw mutex
       u8x8->setFont(font);
-      if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
+      if (!ignoreLH && lineHeight>1)  u8x8->draw1x2Glyph(col, row, glyph);
       else                            u8x8->drawGlyph(col, row, glyph);
+      FLD_SemaphoreGive(drawMux);                                     // WLEDMM release draw mutex
     }
     void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) {
-      if (type == NONE || !enabled) return;
+      if (!typeOK || !enabled) return;
+      if (FLD_SemaphoreTake(drawMux, maxWait) != pdTRUE) return;      // WLEDMM acquire draw mutex
       u8x8->setFont(font);
       u8x8->draw2x2Glyph(col, row, glyph);
+      FLD_SemaphoreGive(drawMux);                                     // WLEDMM release draw mutex
     }
     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
+      if (FLD_SemaphoreTake(drawMux, maxWaitLong ) != pdTRUE) return; // WLEDMM acquire draw mutex - clear() can take very long in software I2C mode
+      u8x8->clear();         // crashes randomly on ESP32
+      FLD_SemaphoreGive(drawMux);                                     // WLEDMM release draw mutex
     }
     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
+      if (u8x8 == nullptr) return;
       u8x8->setPowerSave(save);
     }
 
@@ -238,7 +326,9 @@ class FourLineDisplayUsermod : public Usermod {
     }
 
     void draw2x2GlyphIcons() {
-      if (lineHeight == 2) {
+      if (!typeOK || !enabled) return;    // WLEDMM make sure the display is initialized before we try to draw on it
+      if (FLD_SemaphoreTake(drawMuxBig, maxWaitLong) != pdTRUE) return;      // WLEDMM acquire BIG draw mutex
+      if (lineHeight > 1) {
         drawGlyph( 1,            0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon
         drawGlyph( 5,            0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon
         drawGlyph( 9,            0, 3, u8x8_4LineDisplay_WLED_icons_2x2, true); //intensity icon
@@ -251,6 +341,7 @@ class FourLineDisplayUsermod : public Usermod {
         drawGlyph(15, 2, 4, u8x8_4LineDisplay_WLED_icons_1x1); //palette icon
         drawGlyph(15, 3, 5, u8x8_4LineDisplay_WLED_icons_1x1); //effect icon
       }
+      FLD_SemaphoreGive(drawMuxBig);                                   // WLEDMM release BIG draw mutex
     }
 
     /**
@@ -259,13 +350,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,23 +372,41 @@ 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
+        if (useAMPM) drawString(12, lineHeight*2 + (lineHeight-1), (isitAM ? "AM" : "PM"), true); //draw am/pm if using 12 time
 
         drawStatusIcons(); //icons power, wifi, timer, etc
 
+        if (lineHeight > 1) {       // WLEDMM use extra space for useful information
+          #if defined(WLED_DEBUG) || defined(SR_DEBUG)  || defined(SR_STATS)
+            snprintf_P(lineBuffer, LINE_BUFFER_SIZE, PSTR(" %-3.3s %-2.2s      "), driverSPI? "SPI" : "I2C", driverHW? "hw" : "sw"); // WLEDMM driver info
+          #else
+            strncpy_P(lineBuffer, PSTR("             "), LINE_BUFFER_SIZE);
+          #endif
+          if (apActive) strncpy_P(lineBuffer, PSTR(" AP mode     "), LINE_BUFFER_SIZE);
+          else if (!WLED_CONNECTED) strncpy_P(lineBuffer, PSTR(" NO NET      "), LINE_BUFFER_SIZE);
+          if (WLED_MQTT_CONNECTED) lineBuffer[9] = 'M'; // "MQTT"
+          if (realtimeMode && !realtimeOverride) lineBuffer[10] = 'X'; // "eXternal control"
+          //if (transitionActive) lineBuffer[11] = 'T';
+          //if (stateChanged) lineBuffer[12] = 'C';
+          drawString(1, 0, lineBuffer, false);
+        }
+
         knownMinute = minuteCurrent;
         knownHour   = hourCurrent;
       }
       if (showSeconds && secondCurrent != lastSecond) {
         lastSecond = secondCurrent;
         draw2x2String(6, lineHeight*2, secondCurrent%2 ? " " : ":");
-        sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
-        drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
+        snprintf_P(lineBuffer, LINE_BUFFER_SIZE, PSTR("%02d"), secondCurrent);
+        if (useAMPM)
+          drawString(12, lineHeight*2+1 + (lineHeight-1), lineBuffer, true); // even with double sized rows print seconds in 1 line // WLEDMM move it a bit lower
+        else
+          drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
       }
       drawing = false;
     }
@@ -307,42 +416,66 @@ 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 successful setup
 
-      bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
+      bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64 || type > 7);
       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;
+        } else {
+          if ((spi_sclk < 0) && (spi_mosi < 0)) { // WLEDMM UM pins are valid, but global = -1 --> copy pins to "global"
+            spi_sclk = ioPin[0];
+            spi_mosi = ioPin[1];
+          }
         }
-        isHW = (ioPin[0]==hw_sclk && ioPin[1]==hw_mosi);
+        if ((ioPin[0] < 0 || ioPin[1] < 0) && (spi_sclk < 0 || spi_mosi < 0))  {      // invalid pins, or "use global" and global pins not defined
+          typeOK=false; strcpy(errorMessage, PSTR("SPI No Pins defined")); return; }  //WLEDMM bugfix - ensure that "final" GPIO are valid
+
+        isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi);
+        if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true;  // WLEDMM "use global" = hardware
+        if ((spi_sclk <0) || (spi_mosi < 0)) isHW = false;      // no global pins - use software emulation
         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;
         }
+        // start SPI now!
+#ifdef ARDUINO_ARCH_ESP32
+        if (isHW) SPI.begin(spi_sclk, spi_miso, spi_mosi);   // ESP32 - will silently fail if SPI alread active.
+#else
+        if (isHW) SPI.begin();                               // ESP8266 - SPI pins are fixed
+#endif
+
       } 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;
-        }
-        isHW = (ioPin[0]==hw_scl && ioPin[1]==hw_sda);
+        //if (ioPin[0] < 0 || ioPin[1] < 0) { //WLEDMM do _not_ copy global pins !!
+        //  ioPin[0] = i2c_scl;
+        //  ioPin[1] = i2c_sda;
+        //}
+        isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
+        if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true;  // WLEDMM "use global" = hardware
         // 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) && (i2c_scl < 0 || i2c_sda < 0))  {        // invalid pins, or "use global" and global pins not defined
+          typeOK=false; strcpy(errorMessage, PSTR("I2C No Pins defined")); return; }  //WLEDMM bugfix - ensure that "final" GPIO are valid
+
+        if (isHW) {
+          if (!pinManager.joinWire(i2c_sda, i2c_scl)) { typeOK=false; strcpy(errorMessage, PSTR("I2C HW 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
+        }
       }
 
+      driverHW = isHW;
+      driverSPI= isSPI;
       DEBUG_PRINTLN(F("Allocating display."));
 /*
 // At some point it may be good to not new/delete U8X8 object but use this instead
@@ -371,7 +504,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) {
@@ -413,28 +547,57 @@ class FourLineDisplayUsermod : public Usermod {
           if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]);
           else       u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset
           break;
+        case SSD1309_SPI64:
+          // u8x8 uses global SPI variable that is attached to VSPI bus on ESP32
+          if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1309_128X64_NONAME0_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]);
+          else       u8x8 = (U8X8 *) new U8X8_SSD1309_128X64_NONAME0_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset
+          break;
+        case SSD1327_SPI128:
+          // u8x8 uses global SPI variable that is attached to VSPI bus on ESP32
+          if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1327_WS_128X128_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]);
+          else       u8x8 = (U8X8 *) new U8X8_SSD1327_WS_128X128_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset
+          break;
         default:
           u8x8 = nullptr;
       }
 
       if (nullptr == u8x8) {
-          DEBUG_PRINTLN(F("Display init failed."));
-          pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po);
-          type = NONE;
+          USER_PRINTLN(F("Display init failed."));
+          if (!isHW || !isSPI) pinManager.deallocateMultiplePins((const uint8_t*)ioPin, isSPI ? 5 : 2, po);   // WLEDMM do not de-alloc global pins
+          typeOK=false;
+          strcpy(errorMessage, PSTR("Display init failed"));
           return;
       }
 
       lineHeight = u8x8->getRows() > 4 ? 2 : 1;
-      DEBUG_PRINTLN(F("Starting display."));
+      if (u8x8->getRows() > 8) lineHeight =3;
+      //if (u8x8->getRows() > 12) lineHeight =4;
+      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;
+
+      reDrawing = false;
+      drawing = true;
       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
       setPowerSave(0);
+      drawing = false;
+
+      // init semaphores to allow drawing
+      FLD_SemaphoreGive(drawMux);
+      FLD_SemaphoreGive(drawMuxBig);
+
+      onUpdateBegin(false);  // create Display task // WLEDMM bugfix: before drawing anything
+      delay(200);
+
       //drawString(0, 0, "Loading...");
       overlayLogo(3500);
-      onUpdateBegin(false);  // create Display task
       initDone = true;
     }
 
@@ -450,12 +613,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 +632,48 @@ 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 (!typeOK || !enabled || !initDone) return(false);    // WLEDMM make sure the display is initialized before we try to draw on it
+    #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.
@@ -541,7 +742,7 @@ class FourLineDisplayUsermod : public Usermod {
           // and turn it back on if it changed.
           clear();
           sleepOrClock(true);
-        } else if (displayTurnedOff && ntpEnabled) {
+        } else if (displayTurnedOff) {  // WLEDMM removed "&& ntpEnabled"
           showTime();
         }
         return;
@@ -561,6 +762,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 +787,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 +798,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 +809,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();
       }
@@ -616,10 +819,10 @@ class FourLineDisplayUsermod : public Usermod {
       uint8_t col = 15;
       uint8_t row = 0;
       drawGlyph(col, row,   (wificonnected ? 20 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // wifi icon
-      if (lineHeight==2) { col--; } else { row++; }
+      if (lineHeight>1) { col--; } else { row++; }
       drawGlyph(col, row,          (bri > 0 ? 9 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // power icon
-      if (lineHeight==2) { col--; } else { col = row = 0; }
-      drawGlyph(col, row, (nightlightActive ? 6 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // moon icon for nighlight mode
+      if (lineHeight>1) { col--; } else { col = row = 0; }
+      drawGlyph(col, row, (nightlightActive ? 6 : 0), u8x8_4LineDisplay_WLED_icons_1x1, true); // moon icon for nightlight mode
     }
     
     /**
@@ -632,7 +835,7 @@ class FourLineDisplayUsermod : public Usermod {
       markColNum = newMarkColNum;
     }
 
-    //Draw the arrow for the current setting beiong changed
+    //Draw the arrow for the current setting being changed
     void drawArrow() {
       if (markColNum != 255 && markLineNum !=255) drawGlyph(markColNum, markLineNum*lineHeight, 21, u8x8_4LineDisplay_WLED_icons_1x1);
     }
@@ -640,10 +843,14 @@ 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 (FLD_SemaphoreTake(drawMuxBig, maxWaitLong) != pdTRUE) return;      // WLEDMM acquire BIG draw mutex
+
       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'
@@ -653,9 +860,9 @@ class FourLineDisplayUsermod : public Usermod {
           for (byte i=5; i<=printedChars; i++) lineBuffer[i-5] = lineBuffer[i]; //include '\0'
           printedChars -= 5;
         }
-        if (lineHeight == 2) {                                 // use this code for 8 line display
-          char smallBuffer1[MAX_MODE_LINE_SPACE];
-          char smallBuffer2[MAX_MODE_LINE_SPACE];
+        if (lineHeight > 1) {                                 // use this code for 8 line display
+          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,19 +889,23 @@ 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 above 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 above 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;
           drawString(1, row*lineHeight, smallBuffer3, true);
         }
       }
+
+      FLD_SemaphoreGive(drawMuxBig);                                   // WLEDMM release BIG draw mutex
     }
 
     /**
@@ -704,7 +915,8 @@ class FourLineDisplayUsermod : public Usermod {
      * to wake up the screen.
      */
     bool wakeDisplay() {
-      if (type == NONE || !enabled) return false;
+      if (!typeOK || !enabled) return false;
+      if (!initDone)  return false;
       if (displayTurnedOff) {
         unsigned long now = millis();
         while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
@@ -725,14 +937,17 @@ 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
+      if (!initDone) return;             // WLEDMM bugfix
       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();
       // Print the overlay
       if (glyphType>0 && glyphType<255) {
-        if (lineHeight == 2) drawGlyph(5, 0, glyphType, u8x8_4LineDisplay_WLED_icons_6x6, true); // use 3x3 font with draw2x2Glyph() if flash runs short and comment out 6x6 font
+        if (lineHeight > 1)  drawGlyph(5, 0, glyphType, u8x8_4LineDisplay_WLED_icons_6x6, true); // use 3x3 font with draw2x2Glyph() if flash runs short and comment out 6x6 font
         else                 drawGlyph(6, 0, glyphType, u8x8_4LineDisplay_WLED_icons_3x3, true);
       }
       if (line1) {
@@ -749,13 +964,14 @@ 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;
       // Turn the display back on
       if (!wakeDisplay()) clear();
       // Print the overlay
-      if (lineHeight == 2) {
+      if (lineHeight > 1) {
         //add a bit of randomness
         switch (millis()%3) {
           case 0:
@@ -810,8 +1026,11 @@ 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
+      if (!initDone) return;             // WLEDMM bugfix
       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 +1050,8 @@ 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
+      if (!initDone) return;             // WLEDMM bugfix
       unsigned long now = millis();
       while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
       drawing = true;
@@ -872,10 +1093,11 @@ class FourLineDisplayUsermod : public Usermod {
     /**
      * Enable sleep (turn the display off) or clock mode.
      */
-    void sleepOrClock(bool enabled) {
-      if (enabled) {
+    void sleepOrClock(bool sleepEnable) {
+      if (sleepEnable) {
         displayTurnedOff = true;
-        if (clockMode && ntpEnabled) {
+        //setContrast(contrastFix? 2+ contrast/4 : 0);    // un-comment to dim display in "clock mode"
+        if (clockMode) {                                  // WLEDMM removed " && ntpEnabled"
           knownMinute = knownHour = 99;
           showTime();
         } else
@@ -883,6 +1105,7 @@ class FourLineDisplayUsermod : public Usermod {
       } else {
         displayTurnedOff = false;
         setPowerSave(0);
+        //setContrast(contrast);                        // un-comment to restore display brightness on wakeup
       }
     }
 
@@ -968,7 +1191,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,20 +1199,22 @@ 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;  
+              const TickType_t xFrequency = REFRESH_RATE_MS * portTICK_PERIOD_MS / 2;
               TickType_t xLastWakeTime = xTaskGetTickCount();
               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 +1252,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 +1263,52 @@ 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',' ');"));
+      oappend(SET_F("addOption(dd,'SSD1309 SPI 128x64',8);"));
+      oappend(SET_F("addOption(dd,'SSD1327 SPI 128x128',9);"));
+      bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64 || type > 7);
+      // 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');");
+      }
     }
 
     /*
@@ -1060,12 +1328,12 @@ class FourLineDisplayUsermod : public Usermod {
     void addToConfig(JsonObject& root) {
       // 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;
+      if ((type == SSD1306_SPI || type == SSD1306_SPI64) || (type > 7)) {
+        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 +1349,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 +1385,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
@@ -1126,7 +1394,7 @@ class FourLineDisplayUsermod : public Usermod {
       clockMode     = top[FPSTR(_clockMode)] | clockMode;
       showSeconds   = top[FPSTR(_showSeconds)] | showSeconds;
       contrastFix   = top[FPSTR(_contrastFix)] | contrastFix;
-      if (newType == SSD1306_SPI || newType == SSD1306_SPI64)
+      if (newType == SSD1306_SPI || newType == SSD1306_SPI64 || newType > 7)
         ioFrequency = min(20000, max(500, (int)(top[FPSTR(_busClkFrequency)] | ioFrequency/1000))) * 1000;  // limit frequency
       else
         ioFrequency = min(3400, max(100, (int)(top[FPSTR(_busClkFrequency)] | ioFrequency/1000))) * 1000;  // limit frequency
@@ -1141,31 +1409,44 @@ 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);
+          bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64 || type > 7);
           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 (oldPin[0]==-1 && oldPin[1]==-1) isHW = true;   // WLEDMM "use global" means hardware driver
+            if (spi_sclk==-1 && spi_mosi==-1) isHW = false;    // WLEDMM global pins not set -> software driver
             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);
-            if (isHW) po = PinOwner::HW_I2C;
+            //bool isHW = (oldPin[0]==i2c_scl && oldPin[1]==i2c_sda);
+            //if ((ioPin[0] == -1) || (ioPin[1] == -1)) isHW = true;  // WLEDMM "use global" = hardware
+            //if (isHW) po = PinOwner::HW_I2C;                        // WLEDMM don't try to de-alloc HW pins.
           }
           pinManager.deallocateMultiplePins((const uint8_t *)oldPin, 2, po);
           type = newType;
           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 +1478,11 @@ 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
+
+// WLEDMM clean up some macros, so they don't cause problems in other usermods
+#undef FLD_SemaphoreTake
+#undef FLD_SemaphoreGive
+
diff --git a/usermods/usermod_v2_games/usermod_v2_games.h b/usermods/usermod_v2_games/usermod_v2_games.h
index a26b5d5a..1b1f9047 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/
 
@@ -183,7 +183,7 @@ uint16_t mode_IMUTest(void) {
 
   uint8_t y = 0;
 
-  if (IMU != nullptr) {
+  if ((IMU != nullptr) && (IMU->dmpReady)) {
     SEGMENT.setPixelColorXY(SEGMENT.virtualWidth() * (IMU->aa.x+INT16_MAX)/(2*INT16_MAX), y+=1, BLUE);
     SEGMENT.setPixelColorXY(SEGMENT.virtualWidth() * (IMU->aa.y+INT16_MAX)/(2*INT16_MAX), y+=1, BLUE);
     SEGMENT.setPixelColorXY(SEGMENT.virtualWidth() * (IMU->aa.z+INT16_MAX)/(2*INT16_MAX), y+=1, BLUE);
@@ -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)
@@ -279,7 +280,7 @@ uint16_t mode_3DIMUCube(void) {
   float roll = 0;
 
   #ifdef USERMOD_MPU6050_IMU
-    if (IMU != nullptr) {
+    if ((IMU != nullptr) && (IMU->dmpReady)) {
       yaw = -IMU->ypr[0];
       pitch = IMU->ypr[1];
       roll = IMU->ypr[2];
@@ -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"; //WLEDMM random smooth
 
 class GamesUsermod : public Usermod {
   private:
diff --git a/usermods/usermod_v2_klipper_percentage/readme.md b/usermods/usermod_v2_klipper_percentage/readme.md
new file mode 100644
index 00000000..0619bf85
--- /dev/null
+++ b/usermods/usermod_v2_klipper_percentage/readme.md
@@ -0,0 +1,40 @@
+# Klipper Percentage Usermod
+This usermod polls the Klipper API every 10s for the progressvalue.
+The leds are then filled with a solid color according to that progress percentage. 
+the solid color is the secondary color of the segment.
+
+A corresponding curl command would be:
+```
+curl --location --request GET 'http://[]/printer/objects/query?virtual_sdcard=progress'
+```
+## Usage
+Compile the source with the buildflag  `-D USERMOD_KLIPPER_PERCENTAGE` added.
+
+You can also use the WLBD bot in the Discord by simply extending an exsisting build enviroment:
+```
+[env:esp32klipper]
+extends = env:esp32dev
+build_flags = ${common.build_flags_esp32} -D USERMOD_KLIPPER_PERCENTAGE
+```
+
+## Settings 
+
+### Enabled:
+Checkbox to enable or disable the overlay
+
+### Klipper IP: 
+IP adress of your Klipper instance you want to poll. ESP has to be restarted after change
+
+### Direction : 
+0 = normal
+
+1 = reversed
+
+2 = center
+
+-----
+Author:
+
+Sören Willrodt
+
+Discord: Sören#5281
\ No newline at end of file
diff --git a/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h
new file mode 100644
index 00000000..0e19cc80
--- /dev/null
+++ b/usermods/usermod_v2_klipper_percentage/usermod_v2_klipper_percentage.h
@@ -0,0 +1,222 @@
+#pragma once
+
+#include "wled.h"
+
+class klipper_percentage : public Usermod
+{
+private:
+  unsigned long lastTime = 0;
+  String ip = "192.168.25.207";
+  WiFiClient wifiClient;
+  char errorMessage[100] = "";
+  int printPercent = 0;
+  int direction = 0; // 0 for along the strip, 1 for reversed direction
+
+  static const char _name[];
+  static const char _enabled[];
+  bool enabled = false;
+
+  void httpGet(WiFiClient &client, char *errorMessage)
+  {
+    // https://arduinojson.org/v6/example/http-client/
+    // is this the most compact way to do http get and put it in arduinojson object???
+    // would like async response ... ???
+    client.setTimeout(10000);
+    if (!client.connect(ip.c_str(), 80))
+    {
+      strcat(errorMessage, PSTR("Connection failed"));
+    }
+    else
+    {
+      // Send HTTP request
+      client.println(F("GET /printer/objects/query?virtual_sdcard=progress HTTP/1.0"));
+      client.println("Host: " + ip);
+      client.println(F("Connection: close"));
+      if (client.println() == 0)
+      {
+        strcat(errorMessage, PSTR("Failed to send request"));
+      }
+      else
+      {
+        // Check HTTP status
+        char status[32] = {0};
+        client.readBytesUntil('\r', status, sizeof(status));
+        if (strcmp(status, "HTTP/1.1 200 OK") != 0)
+        {
+          strcat(errorMessage, PSTR("Unexpected response: "));
+          strcat(errorMessage, status);
+        }
+        else
+        {
+          // Skip HTTP headers
+          char endOfHeaders[] = "\r\n\r\n";
+          if (!client.find(endOfHeaders))
+          {
+            strcat(errorMessage, PSTR("Invalid response"));
+          }
+        }
+      }
+    }
+  }
+
+public:
+  void setup()
+  {
+  }
+
+  void connected()
+  {
+  }
+
+  void loop()
+  {
+    if (enabled)
+    {
+      if (WLED_CONNECTED)
+      {
+        if (millis() - lastTime > 10000)
+        {
+          httpGet(wifiClient, errorMessage);
+          if (strcmp(errorMessage, "") == 0)
+          {
+            PSRAMDynamicJsonDocument klipperDoc(4096); // in practive about 2673
+            DeserializationError error = deserializeJson(klipperDoc, wifiClient);
+            if (error)
+            {
+              strcat(errorMessage, PSTR("deserializeJson() failed: "));
+              strcat(errorMessage, error.c_str());
+            }
+            printPercent = (int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100);
+
+            DEBUG_PRINT("Percent: ");
+            DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as() * 100));
+            DEBUG_PRINT("LEDs: ");
+            DEBUG_PRINTLN(direction == 2 ? (strip.getLengthTotal() / 2) * printPercent / 100 : strip.getLengthTotal() * printPercent / 100);
+          }
+          else
+          {
+            DEBUG_PRINTLN(errorMessage);
+            DEBUG_PRINTLN(ip);
+          }
+          lastTime = millis();
+        }
+      }
+    }
+  }
+
+  void addToConfig(JsonObject &root)
+  {
+    JsonObject top = root.createNestedObject("Klipper Printing Percentage");
+    top["Enabled"] = enabled;
+    top["Klipper IP"] = ip;
+    top["Direction"] = direction;
+  }
+
+  bool readFromConfig(JsonObject &root)
+  {
+    // default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor
+    // setting them inside readFromConfig() is slightly more robust, handling the rare but plausible use case of single value being missing after boot (e.g. if the cfg.json was manually edited and a value was removed)
+
+    JsonObject top = root["Klipper Printing Percentage"];
+
+    bool configComplete = !top.isNull();
+    configComplete &= getJsonValue(top["Klipper IP"], ip);
+    configComplete &= getJsonValue(top["Enabled"], enabled);
+    configComplete &= getJsonValue(top["Direction"], direction);
+    return configComplete;
+  }
+
+  /*
+   * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
+   * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
+   * Below it is shown how this could be used for e.g. a light sensor
+   */
+  void addToJsonInfo(JsonObject &root)
+  {
+    JsonObject user = root["u"];
+    if (user.isNull())
+      user = root.createNestedObject("u");
+
+    JsonArray infoArr = user.createNestedArray(FPSTR(_name));
+    String uiDomString = F("");
+    infoArr.add(uiDomString);
+  }
+
+  void addToJsonState(JsonObject &root)
+  {
+    JsonObject usermod = root[FPSTR(_name)];
+    if (usermod.isNull())
+    {
+      usermod = root.createNestedObject(FPSTR(_name));
+    }
+    usermod["on"] = enabled;
+  }
+  void readFromJsonState(JsonObject &root)
+  {
+    JsonObject usermod = root[FPSTR(_name)];
+    if (!usermod.isNull())
+    {
+      if (usermod[FPSTR(_enabled)].is())
+      {
+        enabled = usermod[FPSTR(_enabled)].as();
+      }
+    }
+  }
+
+  /*
+   * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors.
+   * Use this to blank out some LEDs or set them to a different color regardless of the set effect mode.
+   * Commonly used for custom clocks (Cronixie, 7 segment)
+   */
+  void handleOverlayDraw()
+  {
+    if (enabled)
+    {
+      if (direction == 0) // normal
+      {
+        for (int i = 0; i < strip.getLengthTotal() * printPercent / 100; i++)
+        {
+          strip.setPixelColor(i, strip.getSegment(0).colors[1]);
+        }
+      }
+      else if (direction == 1) // reversed
+      {
+        for (int i = 0; i < strip.getLengthTotal() * printPercent / 100; i++)
+        {
+          strip.setPixelColor(strip.getLengthTotal() - i, strip.getSegment(0).colors[1]);
+        }
+      }
+      else if (direction == 2) // center
+      {
+        for (int i = 0; i < (strip.getLengthTotal() / 2) * printPercent / 100; i++)
+        {
+          strip.setPixelColor((strip.getLengthTotal() / 2) + i, strip.getSegment(0).colors[1]);
+          strip.setPixelColor((strip.getLengthTotal() / 2) - i, strip.getSegment(0).colors[1]);
+        }
+      }
+      else
+      {
+        direction = 0;
+      }
+    }
+  }
+
+  /*
+   * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).
+   * This could be used in the future for the system to determine whether your usermod is installed.
+   */
+  uint16_t getId()
+  {
+    return USERMOD_ID_KLIPPER;
+  }
+};
+const char klipper_percentage::_name[] PROGMEM = "Klipper_Percentage";
+const char klipper_percentage::_enabled[] PROGMEM = "enabled";
\ No newline at end of file
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..96539658 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
   }
 
   /*
@@ -341,15 +348,18 @@ public:
       findCurrentEffectAndPalette();
     }
 
-    if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
-      currentEffectAndPaletteInitialized = false;
+    if (modes_alpha_indexes != nullptr) {  // WLEDMM bugfix
+      if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
+        currentEffectAndPaletteInitialized = false;
+      }
     }
 
     if (currentTime - loopTime >= 2) // 2ms since last check of encoder = 500Hz
     {
       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 +385,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) {
@@ -461,11 +471,13 @@ public:
 
   void displayNetworkInfo() {
     #ifdef USERMOD_FOUR_LINE_DISPLAY
+    if (display != nullptr)
     display->networkOverlay(PSTR("NETWORK INFO"), 10000);
     #endif
   }
 
   void findCurrentEffectAndPalette() {
+    if (modes_alpha_indexes == nullptr) return; // WLEDMM bugfix
     currentEffectAndPaletteInitialized = true;
     for (uint8_t i = 0; i < strip.getModeCount(); i++) {
       if (modes_alpha_indexes[i] == effectCurrent) {
@@ -502,7 +514,8 @@ public:
     // 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
     //setValuesFromFirstSelectedSeg(); //to make transition work on main segment (should no longer be required)
     stateUpdated(CALL_MODE_BUTTON);
-    updateInterfaces(CALL_MODE_BUTTON);
+    if ((millis() - lastInterfaceUpdate) > INTERFACE_UPDATE_COOLDOWN)   // WLEDMM respect cooldown times, to avoid crash in AsyncWebSocketMessageBuffer
+      updateInterfaces(CALL_MODE_BUTTON);
   }
 
   void changeBrightness(bool increase) {
@@ -514,10 +527,14 @@ public:
     }
     display->updateRedrawTime();
   #endif
-    bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
+    byte lastBri = bri;
+    if (bri < 40) bri = max(min((increase ? bri+fadeAmount/2 : bri-fadeAmount/2), 255), 0);    // WLEDMM slower steps when brightness < 16%
+    else bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
+    if (lastBri != bri) stateChanged = true;                                                   // WLEDMM bugfix
     lampUdated();
   #ifdef USERMOD_FOUR_LINE_DISPLAY
-    display->updateBrightness();
+    if (display->canDraw())   // only draw if nothing else is drawing
+      display->updateBrightness();
   #endif
   }
 
@@ -532,7 +549,7 @@ public:
     display->updateRedrawTime();
   #endif
     effectCurrentIndex = max(min((increase ? effectCurrentIndex+1 : effectCurrentIndex-1), strip.getModeCount()-1), 0);
-    effectCurrent = modes_alpha_indexes[effectCurrentIndex];
+    if (modes_alpha_indexes != nullptr) effectCurrent = modes_alpha_indexes[effectCurrentIndex];
     stateChanged = true;
     if (applyToAll) {
       for (byte i=0; ishowCurrentEffectOrPalette(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 +592,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 +621,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 +641,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 +777,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 +882,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,11 +940,11 @@ 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;
         }
-        setup();
+        if (enabled) setup();   // WLEDMM no pin stealing!
       }
     }
     // use "return !top["newestParameter"].isNull();" when updating Usermod with new features
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..2ed00424 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) {
@@ -142,14 +142,13 @@ void httpGet(WiFiClient &client, const char *url, char *errorMessage) {
 class WeatherUsermod : public Usermod {
   private:
     // strings to reduce flash memory usage (used more than twice)
-    static const char _name[]; //usermod name
     String apiKey = ""; //config var
 
-    unsigned long lastTime = 0; //will be used to download new forecast every hour
     char errorMessage[100] = "";
     bool isConnected = false; //only call openweathermap if connected
 
   public:
+    WeatherUsermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM: this shouldn't be necessary (passthrough of constructor), maybe because Usermod is an abstract class
 
     void setup() {
       strip.addEffect(255, &mode_2DWeather, _data_FX_MODE_2DWEATHER);
@@ -256,7 +255,6 @@ class WeatherUsermod : public Usermod {
     /*
      * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
      * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
-     * Below it is shown how this could be used for e.g. a light sensor
      */
     void addToJsonInfo(JsonObject& root)
     {
@@ -292,7 +290,8 @@ class WeatherUsermod : public Usermod {
 
     void addToConfig(JsonObject& root)
     {
-      JsonObject top = root.createNestedObject(FPSTR(_name));
+      Usermod::addToConfig(root);
+      JsonObject top = root[FPSTR(_name)];
       top[F("apiKey")] = apiKey;
       top[F("units")]   = weather_units;
       top[F("minTemp")] = weather_minTemp;
@@ -302,10 +301,9 @@ class WeatherUsermod : public Usermod {
 
     bool readFromConfig(JsonObject& root)
     {
+      bool configComplete = Usermod::readFromConfig(root);
       JsonObject top = root[FPSTR(_name)];
 
-      bool configComplete = !top.isNull();
-
       configComplete &= getJsonValue(top[F("apiKey")], apiKey);
       configComplete &= getJsonValue(top[F("units")], weather_units);
       configComplete &= getJsonValue(top[F("minTemp")], weather_minTemp);
@@ -317,13 +315,15 @@ class WeatherUsermod : public Usermod {
 
     void appendConfigData()
     {
-      oappend(SET_F("dd=addDropdown('WeatherUserMod','units');"));
+      oappend(SET_F("addHB('Weather');")); // WLEDMM
+
+      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');"));
     }
 
     /*
@@ -347,9 +347,6 @@ class WeatherUsermod : public Usermod {
     }
 };
 
-// strings to reduce flash memory usage (used more than twice)
-const char WeatherUsermod::_name[]       PROGMEM = "WeatherUserMod";
-
 // example openweathermap data
 // {"cod":"200","message":0,"cnt":40,"list":[
 // {"dt":1663945200,"main":{"temp":18.05,"feels_like":17.79,"temp_min":17.64,"temp_max":18.05,"pressure":1014,"sea_level":1014,"grnd_level":1013,"humidity":72,"temp_kf":0.41},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":4.32,"deg":238,"gust":5.6},"visibility":10000,"pop":0.48,"rain":{"3h":0.15},"sys":{"pod":"d"},"dt_txt":"2022-09-23 15:00:00"},
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. ![image](https://user-images.githubusercontent.com/371964/197094071-f8ccaf59-1d85-4dd2-8e09-1389675291e1.png) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index adde641a..b2c64012 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;!,!;!;01"; /* @@ -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;!,!;!;01"; /* @@ -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@!;!,!;!;01"; /* @@ -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@!;,!;!;01"; /* @@ -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@!;!,!;!;01"; /* @@ -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@!;!,!;!;01"; /* @@ -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@!,!;!,!;!;01"; /* * 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,21 +961,22 @@ 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;!"; /* * Emulates a traffic light. */ uint16_t mode_traffic_light(void) { + if (SEGLEN == 1) return mode_static(); for (int i=0; i < SEGLEN; i++) SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 1)); uint32_t mdelay = 500; @@ -990,10 +998,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;,!;!"; /* @@ -1001,6 +1009,7 @@ static const char _data_FX_MODE_TRAFFIC_LIGHT[] PROGMEM = "Traffic Light@!;,!;!; */ #define FLASH_COUNT 4 uint16_t mode_chase_flash(void) { + if (SEGLEN == 1) return mode_static(); uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1); for (int i = 0; i < SEGLEN; i++) { @@ -1023,13 +1032,14 @@ 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;!"; /* * Prim flashes running, followed by random color. */ uint16_t mode_chase_flash_random(void) { + if (SEGLEN == 1) return mode_static(); uint8_t flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1); for (int i = 0; i < SEGENV.aux1; i++) { @@ -1058,7 +1068,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 +1077,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 +1114,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 +1126,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 +1156,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,13 +1166,14 @@ 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"; /* * Firing comets from one end. "Lighthouse" */ uint16_t mode_comet(void) { + if (SEGLEN == 1) return mode_static(); uint16_t counter = strip.now * ((SEGMENT.speed >>2) +1); uint16_t index = (counter * SEGLEN) >> 16; if (SEGENV.call == 0) SEGENV.aux0 = index; @@ -1177,43 +1188,46 @@ 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;!,!;!"; /* * Fireworks function. */ uint16_t mode_fireworks() { - const uint16_t width = strip.isMatrix ? SEGMENT.virtualWidth() : SEGMENT.virtualLength(); + if (SEGLEN == 1) return mode_static(); + const uint16_t width = SEGMENT.is2D() ? 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 = SEGMENT.is2D() ? SEGMENT.getPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width) : SEGMENT.getPixelColor(SEGENV.aux0); // get spark color + if (valid2) sv2 = SEGMENT.is2D() ? 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 + if (valid1) { if (SEGMENT.is2D()) SEGMENT.setPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width, sv1); else SEGMENT.setPixelColor(SEGENV.aux0, sv1); } // restore spark color after blur + if (valid2) { if (SEGMENT.is2D()) SEGMENT.setPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width, sv2); else SEGMENT.setPixelColor(SEGENV.aux1, sv2); } // restore old spark color after blur for (int i=0; i> 1)) == 0) { uint16_t index = random16(width*height); uint16_t j = index % width, k = index / width; uint32_t col = SEGMENT.color_from_palette(random8(), false, false, 0); - if (strip.isMatrix) SEGMENT.setPixelColorXY(j, k, col); + if (SEGMENT.is2D()) SEGMENT.setPixelColorXY(j, k, col); else SEGMENT.setPixelColor(index, col); SEGENV.aux1 = SEGENV.aux0; // old spark SEGENV.aux0 = index; // remember where spark occured @@ -1221,16 +1235,16 @@ 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 -uint16_t mode_rain() -{ +uint16_t mode_rain() { + if (SEGLEN == 1) return mode_static(); 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 +1255,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 +1270,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 +1299,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@!,!;!;!;01;pal=0"; //WLEDMM pal=0 /* @@ -1323,7 +1337,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 +1346,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 -uint16_t police_base(uint32_t color1, uint32_t color2) -{ +//American Police Light with all LEDs Red and Blue +uint16_t police_base(uint32_t color1, uint32_t color2) { + if (SEGLEN == 1) return mode_static(); 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 +1368,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 +1377,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 +1471,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 +1521,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 +1532,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 +1552,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 +1562,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 +1593,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 +1610,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 +1633,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 +1641,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 +1677,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 +1722,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 +1750,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 +1764,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) @@ -1791,16 +1799,16 @@ uint16_t mode_oscillate(void) } } - for (int i=0; i < SEGLEN; i++) { + for (int i = 0; i < SEGLEN; i++) { uint32_t color = BLACK; - for (int j=0; j < numOscillators; j++) { + for (int j = 0; j < numOscillators; j++) { if(i >= oscillators[j].pos - oscillators[j].size && i <= oscillators[j].pos + oscillators[j].size) { color = (color == BLACK) ? SEGCOLOR(j) : color_blend(color, SEGCOLOR(j), 128); } } SEGMENT.setPixelColor(i, color); } - + SEGENV.step = it; return FRAMETIME; } @@ -1808,8 +1816,8 @@ static const char _data_FX_MODE_OSCILLATE[] PROGMEM = "Oscillate"; //TODO -uint16_t mode_lightning(void) -{ +uint16_t mode_lightning(void) { + if (SEGLEN == 1) return mode_static(); 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 +1831,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 +1856,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; @@ -1871,7 +1878,6 @@ uint16_t mode_pride_2015(void) sPseudotime += duration * msmultiplier; sHue16 += duration * beatsin88( 400, 5,9); uint16_t brightnesstheta16 = sPseudotime; - CRGB fastled_col; for (int i = 0 ; i < SEGLEN; i++) { hue16 += hueinc16; @@ -1884,63 +1890,67 @@ 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 (SEGLEN == 1) return mode_static(); + 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 +1961,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 +1972,43 @@ 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() { + if (SEGLEN == 1) return mode_static(); + 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 +2021,20 @@ uint16_t mode_fire_2012() for (int stripNr=0; stripNr> 1)); @@ -2151,11 +2151,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 +2164,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 +2175,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 +2190,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 +2207,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 +2245,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,25 +2258,27 @@ 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 // send a meteor from begining to to the end of the strip with a trail that randomly decays. // adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain uint16_t mode_meteor() { + if (SEGLEN == 1) return mode_static(); 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,17 +2305,18 @@ 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 // send a meteor from begining to to the end of the strip with a trail that randomly decays. // adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain uint16_t mode_meteor_smooth() { + if (SEGLEN == 1) return mode_static(); 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 +2331,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 +2345,13 @@ 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() { + if (SEGLEN == 1) return mode_static(); + uint16_t dur = (256 - SEGMENT.speed) * 40; uint16_t rampdur = (dur * SEGMENT.intensity) >> 8; if (SEGENV.step > dur) { @@ -2368,16 +2368,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 +2396,85 @@ 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 (SEGLEN == 1) return mode_static(); + 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 (SEGLEN == 1) return mode_static(); + 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 +2496,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 +2529,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 +2573,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,26 +2611,27 @@ 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 uint16_t mode_halloween_eyes() { + if (SEGLEN == 1) return mode_static(); const uint16_t maxWidth = strip.isMatrix ? SEGMENT.virtualWidth() : SEGLEN; const uint16_t HALLOWEEN_EYE_SPACE = MAX(2, strip.isMatrix ? SEGMENT.virtualWidth()>>4: SEGLEN>>5); const uint16_t HALLOWEEN_EYE_WIDTH = HALLOWEEN_EYE_SPACE/2; 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 +2643,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 +2666,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 +2678,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 +2700,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 +2729,14 @@ 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 (SEGLEN == 1) return mode_static(); + 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 +2755,7 @@ uint16_t spots_base(uint16_t threshold) } } } - + return FRAMETIME; } @@ -2767,7 +2765,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 +2776,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 @@ -2792,15 +2790,16 @@ typedef struct Ball { * Bouncing Balls Effect */ uint16_t mode_bouncing_balls(void) { + if (SEGLEN == 1) return mode_static(); //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 +2816,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 +2830,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,13 +2856,14 @@ 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 /* * Sinelon stolen from FASTLED examples */ uint16_t sinelon_base(bool dual, bool rainbow=false) { + if (SEGLEN == 1) return mode_static(); SEGMENT.fade_out(SEGMENT.intensity); uint16_t pos = beatsin16(SEGMENT.speed/10,0,SEGLEN-1); if (SEGENV.call == 0) SEGENV.aux0 = pos; @@ -2878,7 +2878,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 +2900,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 @@ -2945,6 +2961,7 @@ typedef struct Spark { * modified from https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Popcorn.h */ uint16_t mode_popcorn(void) { + if (SEGLEN == 1) return mode_static(); //allocate segment data uint16_t strips = SEGMENT.nrOfVStrips(); uint16_t dataSize = sizeof(spark) * maxNumPopcorn; @@ -2953,7 +2970,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 +2990,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 +3017,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 +3078,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 +3104,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@!,!;!,!;!;01;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"; /* @@ -3118,6 +3135,7 @@ typedef struct particle { } star; uint16_t mode_starburst(void) { + if (SEGLEN == 1) return mode_static(); uint16_t maxData = FAIR_DATA_PER_SEG; //ESP8266: 256 ESP32: 640 uint8_t segs = strip.getActiveSegmentsNum(); if (segs <= (strip.getMaxSegments() /2)) maxData *= 2; //ESP8266: 512 if <= 8 segs ESP32: 1280 if <= 16 segs @@ -3129,26 +3147,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 +3179,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 +3198,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 +3209,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 +3222,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 +3235,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 +3245,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"; /* @@ -3237,6 +3255,7 @@ static const char _data_FX_MODE_STARBURST[] PROGMEM = "Fireworks Starburst@Chanc */ uint16_t mode_exploding_fireworks(void) { + if (SEGLEN == 1) return mode_static(); const uint16_t cols = strip.isMatrix ? SEGMENT.virtualWidth() : 1; const uint16_t rows = strip.isMatrix ? SEGMENT.virtualHeight() : SEGMENT.virtualLength(); @@ -3258,28 +3277,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 +3314,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 +3378,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"; /* @@ -3372,15 +3390,16 @@ static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gr */ uint16_t mode_drip(void) { + if (SEGLEN == 1) return mode_static(); //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 +3470,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 /* @@ -3469,12 +3488,13 @@ typedef struct Tetris { } tetris; uint16_t mode_tetrix(void) { + if (SEGLEN == 1) return mode_static(); uint16_t strips = SEGMENT.nrOfVStrips(); // allow running on virtual strips (columns in 2D segment) uint16_t dataSize = sizeof(tetris); 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 +3504,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 +3516,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,8 +3530,8 @@ 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; - for (int i=int(drop->pos); ipos) < int(drop->stack)) drop->pos = drop->stack; + for (int i = int(drop->pos); i < SEGLEN; i++) { uint32_t col = ipos)+drop->brick ? SEGMENT.color_from_palette(drop->col, false, false, 0) : SEGCOLOR(1); SEGMENT.setPixelColor(indexToVStrip(i, stripNr), col); } @@ -3526,10 +3546,11 @@ uint16_t mode_tetrix(void) { drop->brick = 0; // reset brick size (no more growing) if (drop->step > millis()) { // allow fading of virtual strip - for (int i=0; istack = 0; // reset brick stack size drop->step = 0; // proceed with next brick + if (SEGMENT.check1) drop->col += 8; // gradually increase palette index } } } @@ -3538,9 +3559,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 +3640,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 +3673,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@!,!;!,!;!;01;m12=1"; //Bar // "Pacifica" @@ -3661,16 +3682,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 +3706,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 +3720,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 +3760,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 +3768,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 +3780,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,28 +3790,14 @@ 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"; /* * Mode simulates a gradual sunrise */ uint16_t mode_sunrise() { + if (SEGLEN == 1) return mode_static(); //speed 0 - static sun //speed 1 - 60: sunrise time in minutes //speed 60 - 120 : sunset time in minutes - 60; @@ -3799,12 +3806,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 +3823,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 +3844,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,19 +3879,19 @@ 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. random16_set_seed(535); // The randomizer needs to be re-set each time through the loop in order for the same 'random' numbers to be the same each time through. - for (int i = 0; i SEGMENT.intensity) pixBri = 0; @@ -3893,7 +3900,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 +3939,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. @@ -3946,7 +3953,7 @@ uint16_t mode_sinewave(void) { // Adjustable sinewave. By Andrew Tul SEGENV.step += SEGMENT.speed/16; // Speed of animation. uint16_t freq = SEGMENT.intensity/4;//SEGMENT.fft2/8; // Frequency of the signal. - for (int i=0; i> 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 +3999,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 +4008,7 @@ static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,!;!,!,!;!;m12=1,1d"; // */ uint16_t mode_chunchun(void) { - //SEGMENT.fill(SEGCOLOR(1)); + if (SEGLEN == 1) return mode_static(); 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 +4025,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 @@ -4053,6 +4060,7 @@ typedef struct Spotlight { */ uint16_t mode_dancing_shadows(void) { + if (SEGLEN == 1) return mode_static(); uint8_t numSpotlights = map(SEGMENT.intensity, 0, 255, 2, SPOT_MAX_COUNT); // 49 on 32 segment ESP32, 17 on 16 segment ESP8266 bool initialize = SEGENV.aux0 != numSpotlights; SEGENV.aux0 = numSpotlights; @@ -4165,7 +4173,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,15 +4186,15 @@ 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)); } 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 +4222,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 +4275,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 +4311,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 +4327,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 +4348,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 +4394,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 +4407,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 +4419,7 @@ class AuroraWave { rgb.r = basecolor.r * factor; rgb.g = basecolor.g * factor; rgb.b = basecolor.b * factor; - + return rgb; }; @@ -4488,25 +4496,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 @@ -4516,7 +4524,7 @@ static const char _data_FX_MODE_AURORA[] PROGMEM = "Aurora@!,!;1,2,3;!;sx=24,pal // 16 bit perlinmove. Use Perlin Noise instead of sinewaves for movement. By Andrew Tuline. // Controls are speed, # of pixels, faderate. uint16_t mode_perlinmove(void) { - + if (SEGLEN == 1) return mode_static(); SEGMENT.fade_out(255-SEGMENT.custom1); for (int i = 0; i < SEGMENT.intensity/16 + 1; i++) { uint16_t locn = inoise16(millis()*128/(260-SEGMENT.speed)+i*15000, millis()*128/(260-SEGMENT.speed)); // Get a new pixel location from moving noise. @@ -4526,7 +4534,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 +4552,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 +4575,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 +4619,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 +4637,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 +4654,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 +4700,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 +4715,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 +4726,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 +4777,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 +4812,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 +4839,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 +4847,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 +4856,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 +4877,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 +4917,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 +4973,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 +5090,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 +5108,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 +5182,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 +5197,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 +5224,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 +5241,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 +5264,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 +5307,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 +5330,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 +5356,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 +5371,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 +5382,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 +5390,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 +5412,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 +5462,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 +5513,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 +5545,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 +5591,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 +5640,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 +5665,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 +5755,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,12 +5816,12 @@ 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); - if (blob->r[i] > 1.f) SEGMENT.fill_circle(blob->y[i], blob->x[i], roundf(blob->r[i]), c); - else SEGMENT.setPixelColorXY(blob->y[i], blob->x[i], c); + if (blob->r[i] > 1.f) SEGMENT.fill_circle(blob->x[i], blob->y[i], roundf(blob->r[i]), c); + else SEGMENT.setPixelColorXY(blob->x[i], blob->y[i], c); // move x if (blob->x[i] + blob->r[i] >= cols - 1) blob->x[i] += (blob->sX[i] * ((cols - 1 - blob->x[i]) / blob->r[i] + 0.005f)); else if (blob->x[i] - blob->r[i] <= 0) blob->x[i] += (blob->sX[i] * (blob->x[i] / blob->r[i] + 0.005f)); @@ -5833,7 +5856,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 +5882,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 +5893,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 +5906,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 +5956,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 @@ -6006,6 +6037,8 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli SEGMENT.custom1 = *binNum; SEGMENT.custom2 = *maxVol * 2; } + if (SEGMENT.custom1 < 2) SEGMENT.custom1 = 2; // WLEDMM prevent stupid settings + if (SEGMENT.custom2 < 48) SEGMENT.custom1 = 48; // WLEDMM prevent stupid settings *binNum = SEGMENT.custom1; // Select a bin. *maxVol = SEGMENT.custom2 / 2; // Our volume comparator. @@ -6051,7 +6084,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 +6132,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 +6161,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 +6173,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 +6210,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 +6233,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 +6261,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 +6284,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 +6302,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 +6312,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 +6331,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 +6363,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 ////////////////////// @@ -6346,13 +6389,13 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline. SEGENV.aux0 = secondHand; int pixBri = volumeRaw * SEGMENT.intensity / 64; - for (int i=0; ithisphase += beatsin8(6,-4,4); // You can change direction and speed individually. plasmoip->thatphase += beatsin8(7,-4,4); // Two phase values to make a complex pattern. By Andrew Tuline. - for (int i=0; ithisphase) & 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 +6573,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 /////////////////////// @@ -6557,6 +6600,8 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline. SEGMENT.custom1 = *binNum; SEGMENT.custom2 = *maxVol * 2; } + if (SEGMENT.custom1 < 2) SEGMENT.custom1 = 2; // WLEDMM prevent stupid settings + if (SEGMENT.custom2 < 48) SEGMENT.custom1 = 48; // WLEDMM prevent stupid settings *binNum = SEGMENT.custom1; // Select a bin. *maxVol = SEGMENT.custom2 / 2; // Our volume comparator. @@ -6574,7 +6619,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 +6650,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 +6678,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 +6704,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 +6719,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 ///////////////////////// @@ -6689,6 +6734,7 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil um_data = simulateSound(SEGMENT.soundSim); } uint8_t *fftResult = (uint8_t*)um_data->u_data[2]; + float volumeSmth = *(float*)um_data->u_data[0]; if (SEGENV.call == 0) { SEGMENT.setUpLeds(); @@ -6699,17 +6745,49 @@ 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(0,0,0); + // color = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // formula from 0.13.x (10Khz): R = 3880-5120, G=240-340, B=60-100 + if (!SEGENV.check1) { + color = CRGB(fftResult[12]/2, fftResult[3]/2, fftResult[1]/2); // formula for 0.14.x (22Khz): R = 3015-3704, G=216-301, B=86-129 + } else { + // candy factory: an attempt to get more colors + color = CRGB(fftResult[11]/2 + fftResult[12]/4 + fftResult[14]/4, // red : 2412-3704 + 4479-7106 + fftResult[4]/2 + fftResult[3]/4, // green: 216-430 + fftResult[0]/4 + fftResult[1]/4 + fftResult[2]/4); // blue: 46-216 + if ((color.getLuma() < 96) && (volumeSmth >= 1.5f)) { // enhance "almost dark" pixels with yellow, based on not-yet-used channels + unsigned yello_g = (fftResult[5] + fftResult[6] + fftResult[7]) / 3; + unsigned yello_r = (fftResult[7] + fftResult[8] + fftResult[9] + fftResult[10]) / 4; + color.green += (uint8_t) yello_g / 2; + color.red += (uint8_t) yello_r / 2; + } + } - for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left + if (volumeSmth < 1.0f) color = CRGB(0,0,0); // silence = black + + // make colors less "pastel", by turning up color saturation in HSV space + if (color.getLuma() > 32) { // don't change "dark" pixels + CHSV hsvColor = rgb2hsv_approximate(color); + hsvColor.v = min(max(hsvColor.v, (uint8_t)48), (uint8_t)204); // 48 < brightness < 204 + if (SEGENV.check1) + hsvColor.s = max(hsvColor.s, (uint8_t)204); // candy factory mode: strongly turn up color saturation (> 192) + else + hsvColor.s = max(hsvColor.s, (uint8_t)108); // normal mode: turn up color saturation to avoid pastels + color = hsvColor; + } + //if (color.getLuma() > 12) color.maximizeBrightness(); // for testing + + //SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[4], 0, 255, 255, 4))); // 0.13.x fade -> 180hz-260hz + uint8_t fadeVal = map(fftResult[3], 0, 255, 255, 4); // 0.14.x fade -> 216hz-301hz + if (SEGENV.check1) fadeVal = constrain(fadeVal, 0, 176); // "candy factory" mode - avoid complete fade-out + SEGMENT.setPixelColor(mid, color.fadeToBlackBy(fadeVal)); + + 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,,,,,Candy Factory;;;1f;m12=2,si=0"; // Arc, Beatsin //////////////////// @@ -6724,12 +6802,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. @@ -6739,13 +6817,21 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN. uint16_t pixCol = (log10f(FFT_MajorPeak) - 1.78f) * 255.0f/(MAX_FREQ_LOG10 - 1.78f); // Scale log10 of frequency values to the 255 colour index. if (FFT_MajorPeak < 61.0f) pixCol = 0; // handle underflow +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + uint16_t bright = (int) (sqrtf(my_magnitude)*16.0f); // WLEDMM sqrt scaling, to make peaks more prominent +#else uint16_t bright = (int)my_magnitude; +#endif SEGMENT.setPixelColor(locn, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(SEGMENT.intensity+pixCol, false, PALETTE_SOLID_WRAP, 0), bright)); + if (SEGMENT.speed > 228) { // WLEDMM looks nice in 2D + SEGMENT.blur(5*(SEGMENT.speed - 224)); + SEGMENT.setPixelColor(locn, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(SEGMENT.intensity+pixCol, false, PALETTE_SOLID_WRAP, 0), bright)); + } 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 +6844,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 +6881,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 +6902,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 +6921,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 +6945,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 +6990,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 +7007,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 +7042,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 +7058,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 +7070,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 +7083,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 +7102,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 +7110,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 +7129,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) @@ -7055,6 +7141,9 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin SEGMENT.custom2 = *maxVol * 2; } + if (SEGMENT.custom1 < 2) SEGMENT.custom1 = 2; // WLEDMM prevent stupid settings + if (SEGMENT.custom2 < 48) SEGMENT.custom1 = 48; // WLEDMM prevent stupid settings + *binNum = SEGMENT.custom1; // Select a bin. *maxVol = SEGMENT.custom2 / 2; // Our volume comparator. @@ -7071,12 +7160,12 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin } else { SEGMENT.setPixelColor(SEGLEN-1, color_blend(SEGCOLOR(1), SEGMENT.color_from_palette(pixCol+SEGMENT.intensity, false, PALETTE_SOLID_WRAP, 0), (int)my_magnitude)); } - for (int i=0; i(SEGENV.data); //array of previous bar heights per frequency band @@ -7099,6 +7189,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 1)) ? map(band, 0, NUM_BANDS - 1, 0, 15):band; // always use full range. comment out this line to get the previous behaviour. + // frBand = constrain(frBand, 0, 15); //WLEDMM can never be out of bounds (I think...) + uint16_t colorIndex = frBand * 17; //WLEDMM 0.255 + uint16_t bandHeight = fftResult[frBand]; // WLEDMM we use the original ffResult, to preserve accuracy + + // WLEDMM begin - smooth out bars + if ((x > 0) && (x < (cols-1)) && (SEGMENT.check2)) { + // get height of next (right side) bar + uint8_t nextband = (remaining < 1)? band +1: band; + nextband = constrain(nextband, 0, 15); // just to be sure + frBand = ((NUM_BANDS < 16) && (NUM_BANDS > 1)) ? map(nextband, 0, NUM_BANDS - 1, 0, 15):nextband; // always use full range. comment out this line to get the previous behaviour. + uint16_t nextBandHeight = fftResult[frBand]; + // smooth Band height + bandHeight = (7*bandHeight + 3*lastBandHeight + 3*nextBandHeight) / 12; // yeees, its 12 not 13 (10% amplification) + bandHeight = constrain(bandHeight, 0, 255); // remove potential over/underflows + colorIndex = map(x, 0, cols-1, 0, 255); //WLEDMM + } + lastBandHeight = bandHeight; // remember BandHeight (left side) for next iteration + uint16_t barHeight = map(bandHeight, 0, 255, 0, rows); // Now we map bandHeight to barHeight. do not subtract -1 from rows here + // WLEDMM end + + if (barHeight > 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 ((SEGMENT.intensity < 255) && (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, 0, (samplePeak > 0) ? GREEN : BLACK); + if (samplePeak > 0) SEGMENT.setPixelColorXY(0, 0, 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,Smooth bars ☾;!,,Peaks;!;2f;c1=255,c2=64,pal=11,si=0"; // Beatsin ///////////////////////// @@ -7194,7 +7321,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 +7426,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 +7565,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 +7680,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 +7718,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..f62ce24a 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -72,7 +72,11 @@ #ifndef MAX_NUM_SEGMENTS #define MAX_NUM_SEGMENTS 32 #endif - #define MAX_SEGMENT_DATA 32767 + #if defined(ARDUINO_ARCH_ESP32S2) + #define MAX_SEGMENT_DATA 24576 + #else + #define MAX_SEGMENT_DATA 32767 + #endif #endif /* How much data bytes each segment should max allocate to leave enough space for other segments, @@ -143,7 +147,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 +231,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 +245,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 +254,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 @@ -311,7 +316,7 @@ #define FX_MODE_WAVESINS 184 #define FX_MODE_ROCKTAVES 185 #define FX_MODE_2DAKEMI 186 -#define FX_MODE_CUSTOMEFFECT 187 //WLEDMM Custom Effects +#define FX_MODE_ARTIFX 187 //WLEDMM ARTIFX #define MODE_COUNT 188 @@ -321,8 +326,8 @@ typedef enum mapping1D2D { M12_pArc = 2, M12_pCorner = 3, M12_jMap = 4, //WLEDMM jMap - M12_sCircle = 5, //WLEDMM jMap - M12_sBlock = 6 //WLEDMM jMap + M12_sCircle = 5, //WLEDMM Circle + M12_sBlock = 6 //WLEDMM Block } mapping1D2D_t; // segment, 72 bytes @@ -373,10 +378,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 { @@ -463,7 +469,7 @@ typedef struct Segment { _dataLen(0), _t(nullptr) { - refreshLightCapabilities(); + //refreshLightCapabilities(); } Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) { @@ -499,6 +505,9 @@ typedef struct Segment { inline bool isSelected(void) const { return selected; } inline bool isActive(void) const { return stop > start; } inline bool is2D(void) const { return (width()>1 && height()>1); } + inline bool hasRGB(void) const { return _isRGB; } + inline bool hasWhite(void) const { return _hasW; } + inline bool isCCT(void) const { return _isCCT; } inline uint16_t width(void) const { return stop - start; } // segment width in physical pixels (length if 1D) inline uint16_t height(void) const { return stopY - startY; } // segment height (if 2D) in physical pixels inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels @@ -508,6 +517,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 +532,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 +603,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 +660,7 @@ class WS2812FX { // 96 bytes } mode_data_t; static WS2812FX* instance; - + public: WS2812FX() : @@ -663,14 +674,7 @@ 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), - matrix{0,0,0,0}, - panel{{0,0,0,0}}, + panels(1), #endif // semi-private (just obscured) used in effect functions through macros _currentPalette(CRGBPalette16(CRGB::Black)), @@ -707,6 +711,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); } @@ -720,7 +727,6 @@ class WS2812FX { // 96 bytes finalizeInit(), service(void), setMode(uint8_t segid, uint8_t m), - setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0), setColor(uint8_t slot, uint32_t c), setCCT(uint16_t k), setBrightness(uint8_t b, bool direct = false), @@ -730,15 +736,16 @@ 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); + 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 setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setColor(slot, RGBW32(r,g,b,w)); } + void fill(uint32_t c) { for (int i = 0; i < getLengthTotal(); 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 void setupEffectData(void); // add default effects to the list; defined in FX.cpp @@ -756,7 +763,8 @@ class WS2812FX { // 96 bytes hasCCTBus(void), // return true if the strip is being sent pixel updates isUpdating(void), - useLedsArray = true; //WLEDMM default true as recommended for overlapping segments + deserializeMap(uint8_t n=0), + useLedsArray = false; inline bool isServicing(void) { return _isServicing; } inline bool hasWhiteChannel(void) {return _hasWhiteChannel;} @@ -777,7 +785,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; } @@ -785,17 +793,17 @@ class WS2812FX { // 96 bytes ablMilliampsMax, currentMilliamps, getLengthPhysical(void), + getLengthTotal(void), // will include virtual/nonexistent pixels in matrix getFps(); inline uint16_t getFrameTime(void) { return _frametime; } inline uint16_t getMinShowDelay(void) { return MIN_SHOW_DELAY; } - inline uint16_t getLengthTotal(void) { return _length; } + inline uint16_t getLength(void) { return _length; } // 2D matrix may have less pixels than W*H inline uint16_t getTransition(void) { return _transitionDur; } uint32_t now, timebase, - currentColor(uint32_t colorNew, uint8_t tNr), getPixelColor(uint16_t); inline uint32_t getLastShow(void) { return _lastShow; } @@ -819,28 +827,53 @@ 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; + //WLEDMM: keep storing basic 2d setup + bool + bOrA = false; //WLEDMM basic or advanced, default basic + 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; //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_t() + : xOffset(0) + , yOffset(0) + , width(8) + , height(8) + , options(0) + {} } Panel; - Panel - matrix, - panel[WLED_MAX_PANELS]; + std::vector panel; #endif void - setUpMatrix(bool reset = true), //WLEDMM: add reset option to switch on/off reset of customMappingTable + setUpMatrix(), setPixelColorXY(int x, int y, uint32_t c); // outsmart the compiler :) by correctly overloading @@ -889,9 +922,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..84335dd8 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,90 +29,129 @@ // 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 -void WS2812FX::setUpMatrix(bool reset) { +void WS2812FX::setUpMatrix() { #ifndef WLED_DISABLE_2D // erase old ledmap, just in case. - if (reset) { //WLEDMM: add reset option to switch on/off reset of customMappingTable - if (customMappingTable != nullptr) delete[] customMappingTable; - customMappingTable = nullptr; - customMappingSize = 0; - } + if (customMappingTable != nullptr) delete[] customMappingTable; + customMappingTable = nullptr; + customMappingSize = 0; + // isMatrix is set in cfg.cpp or set.cpp if (isMatrix) { - matrixWidth = hPanels * panelW; - matrixHeight = vPanels * panelH; + // 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; + } + } // safety check - if (matrixWidth * matrixHeight > MAX_LEDS) { - matrixWidth = _length; - matrixHeight = 1; + if (Segment::maxWidth * Segment::maxHeight > 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; } - 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(); + gapSize = map.size(); + if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map + gapTable = new int8_t[gapSize]; + if (gapTable) for (size_t i = 0; i < gapSize; i++) { + gapTable[i] = constrain(map[i], -1, 1); } } } + DEBUG_PRINTLN(F("Gaps loaded.")); + releaseJSONBufferLock(); } + + uint16_t x, y, pix=0; //pixel + for (size_t pan = 0; pan < panel.size(); pan++) { + Panel &p = panel[pan]; + uint16_t h = p.vertical ? p.height : p.width; + uint16_t v = p.vertical ? p.width : p.height; + for (size_t j = 0; j < v; j++){ + for(size_t i = 0; i < h; i++) { + y = (p.vertical?p.rightStart:p.bottomStart) ? v-j-1 : j; + x = (p.vertical?p.bottomStart:p.rightStart) ? h-i-1 : i; + x = p.serpentine && j%2 ? h-x-1 : x; + size_t index = (p.yOffset + (p.vertical?x:y)) * Segment::maxWidth + p.xOffset + (p.vertical?y:x); + if (!gapTable || (gapTable && gapTable[index] > 0)) customMappingTable[index] = pix; // a useful pixel (otherwise -1 is retained) + if (!gapTable || (gapTable && gapTable[index] >= 0)) pix++; // not a missing pixel + } + } + } + + // delete gap array as we no longer need it + if (gapTable) delete[] gapTable; + #ifdef WLED_DEBUG - DEBUG_PRINT(F("Matrix ledmap:")); + DEBUG_PRINTF("Matrix ledmap: \n"); for (uint16_t i=0; i= _length) return; if (index < customMappingSize) index = customMappingTable[index]; + if (index >= _length) return; busses.setPixelColor(index, col); } // 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); #else uint16_t index = x; #endif - if (index >= _length) return 0; if (index < customMappingSize) index = customMappingTable[index]; + if (index >= _length) return 0; return busses.getPixelColor(index); } @@ -157,12 +196,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 +244,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 +310,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 +467,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 +499,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 +560,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..58dd2624 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -75,11 +75,13 @@ /////////////////////////////////////////////////////////////////////////////// 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) { //DEBUG_PRINTLN(F("-- Copy segment constructor --")); - memcpy(this, &orig, sizeof(Segment)); + memcpy((void*)this, (void*)&orig, sizeof(Segment)); name = nullptr; data = nullptr; _dataLen = 0; @@ -95,7 +97,7 @@ Segment::Segment(const Segment &orig) { // move constructor Segment::Segment(Segment &&orig) noexcept { //DEBUG_PRINTLN(F("-- Move segment constructor --")); - memcpy(this, &orig, sizeof(Segment)); + memcpy((void*)this, (void*)&orig, sizeof(Segment)); orig.name = nullptr; orig.data = nullptr; orig._dataLen = 0; @@ -114,7 +116,7 @@ Segment& Segment::operator= (const Segment &orig) { if (leds && !Segment::_globalLeds) free(leds); deallocateData(); // copy source - memcpy(this, &orig, sizeof(Segment)); + memcpy((void*)this, (void*)&orig, sizeof(Segment)); // erase pointers to allocated data name = nullptr; data = nullptr; @@ -139,7 +141,7 @@ Segment& Segment::operator= (Segment &&orig) noexcept { deallocateData(); // free old runtime data if (_t) delete _t; if (leds && !Segment::_globalLeds) free(leds); - memcpy(this, &orig, sizeof(Segment)); + memcpy((void*)this, (void*)&orig, sizeof(Segment)); orig.name = nullptr; orig.data = nullptr; orig._dataLen = 0; @@ -176,18 +178,19 @@ 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; + if (transitional && _t) { transitional = false; delete _t; _t = nullptr; } + deallocateData(); + next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0; reset = false; // setOption(SEG_OPTION_RESET, false); } } @@ -196,7 +199,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 +216,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; @@ -227,21 +231,54 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) { case FX_MODE_NOISE16_4 : pal = 26; break; // landscape 33 case FX_MODE_GLITTER : pal = 11; break; // rainbow colors case FX_MODE_SUNRISE : pal = 35; break; // heat palette - case FX_MODE_FLOW : pal = 6; break; // party + case FX_MODE_RAILWAY : pal = 3; break; // prim + sec } 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 > randomPaletteChangeTime * 1000U) { + 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 > randomPaletteChangeTime * 1000U) { + 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 (!_isRGB && !_hasW) { + if (slot == 0 && c == BLACK) return false; // on/off segment cannot have primary color black + if (slot == 1 && c != BLACK) return false; // on/off segment cannot have secondary color non black + } if (fadeTransition) startTransition(strip.getTransition()); // start transition prior to change colors[slot] = c; stateChanged = true; // send UDP/WS broadcast @@ -404,6 +481,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 +499,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 +522,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 @@ -496,13 +580,13 @@ class JMapC { char previousSegmentName[50] = ""; ~JMapC() { - Serial.println("~JMapC"); + USER_PRINTLN("~JMapC"); deletejVectorMap(); } void deletejVectorMap() { if (jVectorMap.size() > 0) { - Serial.println("delete jVectorMap"); - for (int i=0; i>16; // hack to allow running on virtual strips (2D segment columns/rows) +#endif i &= 0xFFFF; if (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 +807,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 +872,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 +888,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 +913,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); @@ -847,11 +959,13 @@ void Segment::setPixelColor(float i, uint32_t col, bool aa) uint32_t Segment::getPixelColor(int i) { +#ifndef WLED_DISABLE_2D int vStrip = i>>16; +#endif 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,29 +1048,46 @@ uint8_t Segment::differs(Segment& b) const { } void Segment::refreshLightCapabilities() { - uint8_t capabilities = 0x01; + uint8_t capabilities = 0; + uint16_t segStartIdx = 0xFFFFU; + uint16_t segStopIdx = 0; + + if (start < Segment::maxWidth * Segment::maxHeight) { + // we are withing 2D matrix (includes 1D segments) + for (int y = startY; y < stopY; y++) for (int x = start; x < stop; x++) { + uint16_t index = x + Segment::maxWidth * y; + if (index < strip.customMappingSize) index = strip.customMappingTable[index]; // convert logical address to physical + if (index < 0xFFFFU) { + if (segStartIdx > index) segStartIdx = index; + if (segStopIdx < index) segStopIdx = index; + } + if (segStartIdx == segStopIdx) segStopIdx++; // we only have 1 pixel segment + } + } else { + // we are on the strip located after the matrix + segStartIdx = start; + segStopIdx = stop; + } for (uint8_t b = 0; b < busses.getNumBusses(); b++) { Bus *bus = busses.getBus(b); if (bus == nullptr || bus->getLength()==0) break; if (!bus->isOk()) continue; - if (bus->getStart() >= stop) continue; - if (bus->getStart() + bus->getLength() <= start) continue; + if (bus->getStart() >= segStopIdx) continue; + if (bus->getStart() + bus->getLength() <= segStartIdx) 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 - } + //uint8_t type = bus->getType(); + 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 +1211,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 +1244,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 +1281,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 +1315,65 @@ uint8_t * Segment::getAudioPalette(int pal) { // WS2812FX class implementation /////////////////////////////////////////////////////////////////////////////// +//WLEDMM from util.cpp +// enumerate all ledmapX.json files on FS and extract ledmap names if existing +void WS2812FX::enumerateLedmaps() { + ledMaps = 1; + for (size_t i=1; i<10; i++) { + char fileName[33]; + sprintf_P(fileName, PSTR("/ledmap%d.json"), i); + bool isFile = WLED_FS.exists(fileName); + + #ifndef ESP8266 + if (ledmapNames[i-1]) { //clear old name + delete[] ledmapNames[i-1]; + ledmapNames[i-1] = nullptr; + } + #endif + + if (isFile) { + ledMaps |= 1 << i; + + #ifndef ESP8266 + if (requestJSONBufferLock(21)) { + if (readObjectFromFile(fileName, nullptr, &doc)) { + size_t len = 0; + if (!doc["n"].isNull()) { + // name field exists + const char *name = doc["n"].as(); + if (name != nullptr) len = strlen(name); + if (len > 0 && len < 33) { + ledmapNames[i-1] = new char[len+1]; + if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], name, 33); + } + } + if (!ledmapNames[i-1]) { + char tmp[33]; + snprintf_P(tmp, 32, PSTR("ledmap%d.json"), i); + len = strlen(tmp); + ledmapNames[i-1] = new char[len+1]; + if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], tmp, 33); + } + } + releaseJSONBufferLock(); + } + #endif + } + } + //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 +1398,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 +1414,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 +1428,12 @@ void WS2812FX::finalizeInit(void) #endif } + if (isMatrix) setUpMatrix(); + else { + Segment::maxWidth = _length; + Segment::maxHeight = 1; + } + //initialize leds array. TBD: realloc if nr of leds change if (Segment::_globalLeds) { purgeSegments(true); @@ -1241,17 +1441,20 @@ void WS2812FX::finalizeInit(void) Segment::_globalLeds = nullptr; } if (useLedsArray) { + size_t arrSize = sizeof(CRGB) * getLengthTotal(); #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM) if (psramFound()) - Segment::_globalLeds = (CRGB*) ps_malloc(sizeof(CRGB) * _length); + Segment::_globalLeds = (CRGB*) ps_malloc(arrSize); else #endif - Segment::_globalLeds = (CRGB*) malloc(sizeof(CRGB) * _length); - memset(Segment::_globalLeds, 0, sizeof(CRGB) * _length); + Segment::_globalLeds = (CRGB*) malloc(arrSize); + memset(Segment::_globalLeds, 0, arrSize); } //segments are created in makeAutoSegments(); + DEBUG_PRINTLN(F("Loading custom palettes")); loadCustomPalettes(); // (re)load all custom palettes + DEBUG_PRINTLN(F("Loading custom ledmaps")); deserializeMap(); // (re)load default ledmap } @@ -1291,7 +1494,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(); } @@ -1312,15 +1515,15 @@ void WS2812FX::service() { void IRAM_ATTR WS2812FX::setPixelColor(int i, uint32_t col) { - if (i >= _length) return; if (i < customMappingSize) i = customMappingTable[i]; + if (i >= _length) return; busses.setPixelColor(i, col); } uint32_t WS2812FX::getPixelColor(uint16_t i) { - if (i >= _length) return 0; if (i < customMappingSize) i = customMappingTable[i]; + if (i >= _length) return 0; return busses.getPixelColor(i); } @@ -1332,7 +1535,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 +1585,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 +1594,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 +1618,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 +1655,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) { @@ -1533,6 +1736,12 @@ uint8_t WS2812FX::getActiveSegmentsNum(void) { return c; } +uint16_t WS2812FX::getLengthTotal(void) { + uint16_t len = Segment::maxWidth * Segment::maxHeight; // will be _length for 1D (see finalizeInit()) but should cover whole matrix for 2D + if (isMatrix && _length > len) len = _length; // for 2D with trailing strip + return len; +} + uint16_t WS2812FX::getLengthPhysical(void) { uint16_t len = 0; for (size_t b = 0; b < busses.getNumBusses(); b++) { @@ -1550,12 +1759,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; } @@ -1580,7 +1784,6 @@ void WS2812FX::purgeSegments(bool force) { if (_segments.size() <= 1) return; for (size_t i = _segments.size()-1; i > 0; i--) if (_segments[i].stop == 0 || force) { - DEBUG_PRINT(F("Purging segment segment: ")); DEBUG_PRINTLN(i); deleted++; _segments.erase(_segments.begin() + i); } @@ -1596,97 +1799,65 @@ 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) { - if (isMatrix) { - #ifndef WLED_DISABLE_2D - // only create 1 2D segment - if (forceReset || getSegmentsNum() == 0) resetSegments(); // initialises 1 segment - else if (getActiveSegmentsNum() == 1) { - size_t i = getLastActiveSegmentId(); - _segments[i].start = 0; - _segments[i].stop = matrixWidth; - _segments[i].startY = 0; - _segments[i].stopY = matrixHeight; - _segments[i].grouping = 1; - _segments[i].spacing = 0; - _mainSegment = i; - } - #endif - } else if (autoSegments) { //make one segment per bus + if (autoSegments) { //make one segment per bus uint16_t segStarts[MAX_NUM_SEGMENTS] = {0}; uint16_t segStops [MAX_NUM_SEGMENTS] = {0}; - uint8_t s = 0; - for (uint8_t i = 0; i < busses.getNumBusses(); i++) { + size_t s = 0; + + #ifndef WLED_DISABLE_2D + // 2D segment is the 1st one using entire matrix + if (isMatrix) { + segStarts[0] = 0; + segStops[0] = Segment::maxWidth*Segment::maxHeight; + s++; + } + #endif + + for (size_t i = s; i < busses.getNumBusses(); i++) { Bus* b = busses.getBus(i); segStarts[s] = b->getStart(); segStops[s] = segStarts[s] + b->getLength(); + #ifndef WLED_DISABLE_2D + if (isMatrix && segStops[s] < Segment::maxWidth*Segment::maxHeight) continue; // ignore buses comprising matrix + if (isMatrix && segStarts[s] < Segment::maxWidth*Segment::maxHeight) segStarts[s] = Segment::maxWidth*Segment::maxHeight; + #endif + //check for overlap with previous segments for (size_t j = 0; j < s; j++) { if (segStops[j] > segStarts[s] && segStarts[j] < segStops[s]) { @@ -1698,23 +1869,40 @@ void WS2812FX::makeAutoSegments(bool forceReset) { } s++; } + _segments.clear(); - for (size_t i = 0; i < s; i++) { - Segment seg = Segment(segStarts[i], segStops[i]); - seg.selected = true; - _segments.push_back(seg); + _segments.reserve(s); // prevent reallocations + // there is always at least one segment (but we need to differentiate between 1D and 2D) + #ifndef WLED_DISABLE_2D + if (isMatrix) + _segments.push_back(Segment(0, Segment::maxWidth, 0, Segment::maxHeight)); + else + #endif + _segments.push_back(Segment(segStarts[0], segStops[0])); + for (size_t i = 1; i < s; i++) { + _segments.push_back(Segment(segStarts[i], segStops[i])); } - _mainSegment = 0; + } else { + if (forceReset || getSegmentsNum() == 0) resetSegments(); //expand the main seg to the entire length, but only if there are no other segments, or reset is forced else if (getActiveSegmentsNum() == 1) { size_t i = getLastActiveSegmentId(); + #ifndef WLED_DISABLE_2D + _segments[i].start = 0; + _segments[i].stop = Segment::maxWidth; + _segments[i].startY = 0; + _segments[i].stopY = Segment::maxHeight; + _segments[i].grouping = 1; + _segments[i].spacing = 0; + #else _segments[i].start = 0; _segments[i].stop = _length; - _mainSegment = 0; + #endif } } + _mainSegment = 0; fixInvalidSegments(); } @@ -1722,14 +1910,30 @@ void WS2812FX::makeAutoSegments(bool forceReset) { void WS2812FX::fixInvalidSegments() { //make sure no segment is longer than total (sanity check) for (size_t i = getSegmentsNum()-1; i > 0; i--) { - if (_segments[i].start >= _length) { _segments.erase(_segments.begin()+i); continue; } - if (_segments[i].stop > _length) _segments[i].stop = _length; - // this is always called as the last step after finalizeInit(), update covered bus types - _segments[i].refreshLightCapabilities(); + if (isMatrix) { + #ifndef WLED_DISABLE_2D + if (_segments[i].start >= Segment::maxWidth * Segment::maxHeight) { + // 1D segment at the end of matrix + if (_segments[i].start >= _length || _segments[i].startY > 0 || _segments[i].stopY > 1) { _segments.erase(_segments.begin()+i); continue; } + if (_segments[i].stop > _length) _segments[i].stop = _length; + continue; + } + if (_segments[i].start >= Segment::maxWidth || _segments[i].startY >= Segment::maxHeight) { _segments.erase(_segments.begin()+i); continue; } + if (_segments[i].stop > Segment::maxWidth) _segments[i].stop = Segment::maxWidth; + if (_segments[i].stopY > Segment::maxHeight) _segments[i].stopY = Segment::maxHeight; + #endif + } else { + if (_segments[i].start >= _length) { _segments.erase(_segments.begin()+i); continue; } + if (_segments[i].stop > _length) _segments[i].stop = _length; + } } + // this is always called as the last step after finalizeInit(), update covered bus types + for (segment &seg : _segments) + seg.refreshLightCapabilities(); } //true if all segments align with a bus, or if a segment covers the total length +//irrelevant in 2D set-up bool WS2812FX::checkSegmentAlignment() { bool aligned = false; for (segment &seg : _segments) { @@ -1746,8 +1950,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 +1959,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,26 +1969,24 @@ 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); DEBUG_PRINTF("Modes: %d*%d=%uB\n", sizeof(mode_ptr), _mode.size(), (_mode.capacity()*sizeof(mode_ptr))); DEBUG_PRINTF("Data: %d*%d=%uB\n", sizeof(const char *), _modeData.size(), (_modeData.capacity()*sizeof(const char *))); DEBUG_PRINTF("Map: %d*%d=%uB\n", sizeof(uint16_t), (int)customMappingSize, customMappingSize*sizeof(uint16_t)); - if (useLedsArray) DEBUG_PRINTF("Buffer: %d*%d=%uB\n", sizeof(CRGB), (int)_length, _length*sizeof(CRGB)); + size = getLengthTotal(); + if (useLedsArray) DEBUG_PRINTF("Buffer: %d*%u=%uB\n", sizeof(CRGB), size, size*sizeof(CRGB)); } #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 +2001,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)); } @@ -1821,85 +2034,103 @@ void WS2812FX::loadCustomPalettes() } //load custom mapping table from JSON file (called from finalizeInit() or deserializeState()) -void WS2812FX::deserializeMap(uint8_t n) { - // WLEDMM: also supports isMatrix +bool WS2812FX::deserializeMap(uint8_t n) { + // 2D support creates its own ledmap (on the fly) if a ledmap.json exists it will overwrite built one. 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); //WLEDMM: trick to not include 0 in ledmap.json + 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("/%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) { - //WLEDMM: if isMatrix then not erase but back to matrix default - if (isMatrix) - setUpMatrix(true); - else { - customMappingSize = 0; - delete[] customMappingTable; - customMappingTable = nullptr; - } + //WLEDM: doubt this is necessary as return false causes setupMatrix to deal with this + if (!isMatrix && !n && customMappingTable != nullptr) { + customMappingSize = 0; + delete[] customMappingTable; + customMappingTable = nullptr; + loadedLedmap = 0; //WLEDMM } - return; + return false; } - if (!requestJSONBufferLock(7)) return; - - DEBUG_PRINT(F("Reading LED map from ")); - DEBUG_PRINTLN(fileName); + if (!requestJSONBufferLock(7)) return false; if (!readObjectFromFile(fileName, nullptr, &doc)) { releaseJSONBufferLock(); - return; //if file does not exist just exit + return false; //if file does not exist just exit } + USER_PRINT(F("Reading LED map from ")); //WLEDMM use USER_PRINT + USER_PRINTLN(fileName); + // erase old custom ledmap if (customMappingTable != nullptr) { customMappingSize = 0; delete[] customMappingTable; customMappingTable = nullptr; + loadedLedmap = 0; } JsonArray map = doc[F("map")]; if (!map.isNull() && map.size()) { // not an empty map - //WLEDMM: if isMatrix then customMap size is whole matrix -#ifndef WLED_DISABLE_2D - if (isMatrix) - customMappingSize = matrixWidth * matrixHeight; - else -#endif - customMappingSize = map.size(); - customMappingTable = new uint16_t[customMappingSize]; - for (uint16_t i=0; i0 && doc[F("height")]>0) { + Segment::maxWidth = doc[F("width")];; + Segment::maxHeight = doc[F("height")];; + resetSegments(true); //WLEDMM not makeAutoSegments() as we only want to change bounds } - setUpMatrix(false); //WLEDMM: apply logical to physical mapping after the ledmap + + 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/blynk.cpp b/wled00/blynk.cpp deleted file mode 100644 index c8103d8c..00000000 --- a/wled00/blynk.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "wled.h" -#ifndef WLED_DISABLE_BLYNK -#include "src/dependencies/blynk/Blynk/BlynkHandlers.h" -#endif - -/* - * Remote light control with the free Blynk app - */ - -uint16_t blHue = 0; -byte blSat = 255; - -void initBlynk(const char *auth, const char *host, uint16_t port) -{ - #ifndef WLED_DISABLE_BLYNK - if (!WLED_CONNECTED) return; - blynkEnabled = (auth[0] != 0); - if (blynkEnabled) Blynk.config(auth, host, port); - #endif -} - -void handleBlynk() -{ - #ifndef WLED_DISABLE_BLYNK - if (WLED_CONNECTED && blynkEnabled) - Blynk.run(); - #endif -} - -void updateBlynk() -{ - #ifndef WLED_DISABLE_BLYNK - if (!WLED_CONNECTED) return; - Blynk.virtualWrite(V0, bri); - //we need a RGB -> HSB convert here - Blynk.virtualWrite(V3, bri? 1:0); - Blynk.virtualWrite(V4, effectCurrent); - Blynk.virtualWrite(V5, effectSpeed); - Blynk.virtualWrite(V6, effectIntensity); - Blynk.virtualWrite(V7, nightlightActive); - Blynk.virtualWrite(V8, notifyDirect); - #endif -} - -#ifndef WLED_DISABLE_BLYNK -BLYNK_WRITE(V0) -{ - bri = param.asInt();//bri - stateUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V1) -{ - blHue = param.asInt();//hue - colorHStoRGB(blHue*10,blSat,col); - colorUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V2) -{ - blSat = param.asInt();//sat - colorHStoRGB(blHue*10,blSat,col); - colorUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V3) -{ - bool on = (param.asInt()>0); - if (!on != !bri) {toggleOnOff(); stateUpdated(CALL_MODE_BLYNK);} -} - -BLYNK_WRITE(V4) -{ - effectCurrent = param.asInt()-1;//fx - colorUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V5) -{ - effectSpeed = param.asInt();//sx - colorUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V6) -{ - effectIntensity = param.asInt();//ix - colorUpdated(CALL_MODE_BLYNK); -} - -BLYNK_WRITE(V7) -{ - nightlightActive = (param.asInt()>0); -} - -BLYNK_WRITE(V8) -{ - notifyDirect = (param.asInt()>0); //send notifications -} -#endif diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp new file mode 100644 index 00000000..08bb5128 --- /dev/null +++ b/wled00/bus_manager.cpp @@ -0,0 +1,563 @@ +/* + * 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 +//WLEDMM: #define DEBUGOUT(x) netDebugEnabled?NetDebug.print(x):Serial.print(x) not supported in this file as netDebugEnabled not in scope +#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) && bool(_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; + 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; diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 5f604321..ffb3bd14 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,37 +121,37 @@ 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) { _cct = cct; } - static void setCCTBlend(uint8_t b) { - if (b > 100) b = 100; - _cctBlend = (b * 127) / 100; - //compile-time limiter for hardware that can't power both white channels at max - #ifdef WLED_MAX_CCT_BLEND - 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; } + static void setCCTBlend(uint8_t b) { + if (b > 100) b = 100; + _cctBlend = (b * 127) / 100; + //compile-time limiter for hardware that can't power both white channels at max + #ifdef WLED_MAX_CCT_BLEND + if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND; + #endif + } + 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..bbf38d2e 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -182,7 +182,12 @@ #endif //APA102 -#define B_HS_DOT_3 NeoPixelBrightnessBus //hardware SPI +#ifdef WLED_USE_ETHERNET +// fix for #2542 (by @BlackBird77) +#define B_HS_DOT_3 NeoPixelBrightnessBus //hardware HSPI with DMA (ESP32 only) +#else +#define B_HS_DOT_3 NeoPixelBrightnessBus //hardware HSPI +#endif #define B_SS_DOT_3 NeoPixelBrightnessBus //soft SPI //LPD8806 @@ -699,7 +704,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 +776,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 +871,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 +899,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 +933,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..32e15ecc 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" @@ -14,6 +17,10 @@ void getStringFromJson(char* dest, const char* src, size_t len) { } bool deserializeConfig(JsonObject doc, bool fromFS) { + + //WLEDMM add USER_PRINT + USER_PRINTF("deserializeConfig\n"); + bool needsSave = false; //int rev_major = doc["rev"][0]; // 1 //int rev_minor = doc["rev"][1]; // 0 @@ -64,7 +71,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 +91,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,47 +104,61 @@ 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")]); + + //WLEDMM: keep storing basic 2d setup + CJSON(strip.panels, matrix[F("mpc")]); + CJSON(strip.bOrA, matrix["ba"]); //WLEDMM basic or advanced + CJSON(strip.panelsV, matrix[F("mpv")]); + CJSON(strip.panelsH, matrix[F("mph")]); 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")]); + CJSON(strip.panelO.rightStart, matrix[F("prl")]); + CJSON(strip.panelO.vertical, matrix[F("pvl")]); + CJSON(strip.panelO.serpentine, matrix["psl"]); + 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 } + } else { + // fallback + WS2812FX::Panel p; + strip.panels = 1; + p.height = p.width = 8; + p.xOffset = p.yOffset = 0; + p.options = 0; + strip.panel.push_back(p); } - // 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 +182,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 +213,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 +223,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 +268,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 1.5) gammaCorrectBri = true; - else if (light_gc_bri > 0.5) gammaCorrectBri = false; - if (light_gc_col > 1.5) gammaCorrectCol = true; - else if (light_gc_col > 0.5) gammaCorrectCol = false; + float light_gc_col = light["gc"]["col"]; + if (light_gc_bri > 1.0f) gammaCorrectBri = true; + else gammaCorrectBri = false; + if (light_gc_col > 1.0f) gammaCorrectCol = true; + else gammaCorrectCol = false; + if (gammaCorrectVal > 1.0f && gammaCorrectVal <= 3) { + if (gammaCorrectVal != 2.8f) calcGammaTable(gammaCorrectVal); + } else { + gammaCorrectVal = 1.0f; // no gamma correction + gammaCorrectBri = false; + gammaCorrectCol = false; + } JsonObject light_tr = light["tr"]; CJSON(fadeTransition, light_tr["mode"]); int tdd = light_tr["dur"] | -1; if (tdd >= 0) transitionDelay = transitionDelayDefault = tdd * 100; CJSON(strip.paletteFade, light_tr["pal"]); + CJSON(randomPaletteChangeTime, light_tr[F("rpc")]); JsonObject light_nl = light["nl"]; CJSON(nightlightMode, light_nl["mode"]); @@ -379,6 +427,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]); CJSON(DMXAddress, if_live_dmx[F("addr")]); if (!DMXAddress || DMXAddress > 510) DMXAddress = 1; + CJSON(DMXSegmentSpacing, if_live_dmx[F("dss")]); + if (DMXSegmentSpacing > 150) DMXSegmentSpacing = 0; + CJSON(e131Priority, if_live_dmx[F("e131prio")]); + if (e131Priority > 200) e131Priority = 200; CJSON(DMXMode, if_live_dmx["mode"]); tdd = if_live[F("timeout")] | -1; @@ -394,17 +446,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(alexaNumPresets, interfaces["va"]["p"]); -#ifndef WLED_DISABLE_BLYNK - const char* apikey = interfaces["blynk"][F("token")] | "Hidden"; - tdd = strnlen(apikey, 36); - if (tdd > 20 || tdd == 0) - getStringFromJson(blynkApiKey, apikey, 36); //normally not present due to security - - JsonObject if_blynk = interfaces["blynk"]; - getStringFromJson(blynkHost, if_blynk[F("host")], 33); - CJSON(blynkPort, if_blynk["port"]); -#endif - #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces["mqtt"]; CJSON(mqttEnabled, if_mqtt["en"]); @@ -436,6 +477,18 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { CJSON(hueIP[i], if_hue_ip[i]); #endif +//WLEDMM: add netdebug variables +#ifdef WLED_DEBUG_HOST + JsonObject if_ndb = interfaces["ndb"]; + JsonArray if_ndb_ip = if_ndb["ip"]; + for (byte i = 0; i < 4; i++) + CJSON(netDebugPrintIP[i], if_ndb_ip[i]); + CJSON(netDebugPrintPort, if_ndb["port"]); + CJSON(netDebugEnabled, if_ndb["enabled"]); + // USER_PRINTF("deserializeConfig %d\n", netDebugEnabled); + pinManager.manageDebugTXPin(); +#endif + JsonObject if_ntp = interfaces[F("ntp")]; CJSON(ntpEnabled, if_ntp["en"]); getStringFromJson(ntpServerName, if_ntp[F("host")], 33); // "1.wled.pool.ntp.org" @@ -472,7 +525,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 +726,35 @@ 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; + + //WLEDMM: keep storing basic 2d setup + matrix[F("ba")] = strip.bOrA; //WLEDMM basic or advanced + matrix[F("mph")] = strip.panelsH; + matrix[F("mpv")] = strip.panelsV; 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 +794,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 @@ -781,13 +841,15 @@ void serializeConfig() { light[F("aseg")] = autoSegments; JsonObject light_gc = light.createNestedObject("gc"); - light_gc["bri"] = (gammaCorrectBri) ? 2.8 : 1.0; - light_gc["col"] = (gammaCorrectCol) ? 2.8 : 1.0; + light_gc["bri"] = (gammaCorrectBri) ? gammaCorrectVal : 1.0f; // keep compatibility + light_gc["col"] = (gammaCorrectCol) ? gammaCorrectVal : 1.0f; // keep compatibility + light_gc["val"] = gammaCorrectVal; JsonObject light_tr = light.createNestedObject("tr"); light_tr["mode"] = fadeTransition; light_tr["dur"] = transitionDelayDefault / 100; light_tr["pal"] = strip.paletteFade; + light_tr[F("rpc")] = randomPaletteChangeTime; JsonObject light_nl = light.createNestedObject("nl"); light_nl["mode"] = nightlightMode; @@ -836,7 +898,9 @@ void serializeConfig() { JsonObject if_live_dmx = if_live.createNestedObject("dmx"); if_live_dmx[F("uni")] = e131Universe; if_live_dmx[F("seqskip")] = e131SkipOutOfSequence; + if_live_dmx[F("e131prio")] = e131Priority; if_live_dmx[F("addr")] = DMXAddress; + if_live_dmx[F("dss")] = DMXSegmentSpacing; if_live_dmx["mode"] = DMXMode; if_live[F("timeout")] = realtimeTimeoutMs / 100; @@ -853,13 +917,6 @@ void serializeConfig() { if_va["p"] = alexaNumPresets; -#ifndef WLED_DISABLE_BLYNK - JsonObject if_blynk = interfaces.createNestedObject("blynk"); - if_blynk[F("token")] = strlen(blynkApiKey) ? "Hidden":""; - if_blynk[F("host")] = blynkHost; - if_blynk["port"] = blynkPort; -#endif - #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces.createNestedObject("mqtt"); if_mqtt["en"] = mqttEnabled; @@ -891,6 +948,18 @@ void serializeConfig() { } #endif +//WLEDMM: add netdebug variables +#ifdef WLED_DEBUG_HOST + JsonObject if_ndb = interfaces.createNestedObject("ndb"); + JsonArray if_ndb_ip = if_ndb.createNestedArray("ip"); + for (byte i = 0; i < 4; i++) { + if_ndb_ip.add(netDebugPrintIP[i]); + } + if_ndb["port"] = netDebugPrintPort; + if_ndb["enabled"] = netDebugEnabled; + // USER_PRINTF("serializeConfig %d\n", netDebugEnabled); +#endif + JsonObject if_ntp = interfaces.createNestedObject("ntp"); if_ntp["en"] = ntpEnabled; if_ntp[F("host")] = ntpServerName; @@ -962,6 +1031,9 @@ void serializeConfig() { JsonObject usermods_settings = doc.createNestedObject("um"); usermods.addToConfig(usermods_settings); + //WLEDMM add USER_PRINT + USER_PRINTF("serializeConfig\n"); + File f = WLED_FS.open("/cfg.json", "w"); if (f) serializeJson(doc, f); f.close(); @@ -990,13 +1062,6 @@ bool deserializeConfigSec() { JsonObject interfaces = doc["if"]; -#ifndef WLED_DISABLE_BLYNK - const char* apikey = interfaces["blynk"][F("token")] | "Hidden"; - int tdd = strnlen(apikey, 36); - if (tdd > 20 || tdd == 0) - getStringFromJson(blynkApiKey, apikey, 36); -#endif - #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces["mqtt"]; getStringFromJson(mqttPass, if_mqtt["psk"], 65); @@ -1035,10 +1100,6 @@ void serializeConfigSec() { ap["psk"] = apPass; JsonObject interfaces = doc.createNestedObject("if"); -#ifndef WLED_DISABLE_BLYNK - JsonObject if_blynk = interfaces.createNestedObject("blynk"); - if_blynk[F("token")] = blynkApiKey; -#endif #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces.createNestedObject("mqtt"); if_mqtt["psk"] = mqttPass; diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 0387a925..61457eba 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -57,41 +57,44 @@ void setRandomColor(byte* rgb) void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb { - float h = ((float)hue)/65535.0; - float s = ((float)sat)/255.0; - byte i = floor(h*6); - float f = h * 6-i; - float p = 255 * (1-s); - float q = 255 * (1-f*s); - float t = 255 * (1-(1-f)*s); + float h = ((float)hue)/65535.0f; + float s = ((float)sat)/255.0f; + int i = floorf(h*6); + float f = h * 6.0f - i; + int p = int(255.0f * (1.0f-s)); + int q = int(255.0f * (1.0f-f*s)); + int t = int(255.0f * (1.0f-(1.0f-f)*s)); + p = constrain(p, 0, 255); + q = constrain(q, 0, 255); + t = constrain(t, 0, 255); switch (i%6) { - case 0: rgb[0]=255,rgb[1]=t,rgb[2]=p;break; - case 1: rgb[0]=q,rgb[1]=255,rgb[2]=p;break; - case 2: rgb[0]=p,rgb[1]=255,rgb[2]=t;break; - case 3: rgb[0]=p,rgb[1]=q,rgb[2]=255;break; - case 4: rgb[0]=t,rgb[1]=p,rgb[2]=255;break; - case 5: rgb[0]=255,rgb[1]=p,rgb[2]=q; + case 0: rgb[0]=255,rgb[1]=t, rgb[2]=p; break; + case 1: rgb[0]=q, rgb[1]=255,rgb[2]=p; break; + case 2: rgb[0]=p, rgb[1]=255,rgb[2]=t; break; + case 3: rgb[0]=p, rgb[1]=q, rgb[2]=255;break; + case 4: rgb[0]=t, rgb[1]=p, rgb[2]=255;break; + case 5: rgb[0]=255,rgb[1]=p, rgb[2]=q; break; } } //get RGB values from color temperature in K (https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html) void colorKtoRGB(uint16_t kelvin, byte* rgb) //white spectrum to rgb, calc { - float r = 0, g = 0, b = 0; - float temp = kelvin / 100; - if (temp <= 66) { + int r = 0, g = 0, b = 0; + float temp = kelvin / 100.0f; + if (temp <= 66.0f) { r = 255; - g = round(99.4708025861 * log(temp) - 161.1195681661); - if (temp <= 19) { + g = roundf(99.4708025861f * logf(temp) - 161.1195681661f); + if (temp <= 19.0f) { b = 0; } else { - b = round(138.5177312231 * log((temp - 10)) - 305.0447927307); + b = roundf(138.5177312231f * logf((temp - 10.0f)) - 305.0447927307f); } } else { - r = round(329.698727446 * pow((temp - 60), -0.1332047592)); - g = round(288.1221695283 * pow((temp - 60), -0.0755148492)); + r = roundf(329.698727446f * powf((temp - 60.0f), -0.1332047592f)); + g = roundf(288.1221695283f * powf((temp - 60.0f), -0.0755148492f)); 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); @@ -147,9 +150,9 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www b = 1.0f; } // Apply gamma correction - r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f; - g = g <= 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * pow(g, (1.0f / 2.4f)) - 0.055f; - b = b <= 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f; + r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * powf(r, (1.0f / 2.4f)) - 0.055f; + g = g <= 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * powf(g, (1.0f / 2.4f)) - 0.055f; + b = b <= 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * powf(b, (1.0f / 2.4f)) - 0.055f; if (r > b && r > g) { // red is biggest @@ -173,9 +176,9 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www b = 1.0f; } } - rgb[0] = 255.0*r; - rgb[1] = 255.0*g; - rgb[2] = 255.0*b; + rgb[0] = byte(255.0f*r); + rgb[1] = byte(255.0f*g); + rgb[2] = byte(255.0f*b); } void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.developers.meethue.com/documentation/color-conversions-rgb-xy) @@ -194,7 +197,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); @@ -242,35 +245,13 @@ float maxf (float v, float w) return v; } -/* -uint32_t colorRGBtoRGBW(uint32_t c) -{ - byte rgb[4]; - rgb[0] = R(c); - rgb[1] = G(c); - rgb[2] = B(c); - rgb[3] = W(c); - colorRGBtoRGBW(rgb); - return RGBW32(rgb[0], rgb[1], rgb[2], rgb[3]); -} - -void colorRGBtoRGBW(byte* rgb) //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY) -{ - float low = minf(rgb[0],minf(rgb[1],rgb[2])); - float high = maxf(rgb[0],maxf(rgb[1],rgb[2])); - if (high < 0.1f) return; - float sat = 100.0f * ((high - low) / high); // maximum saturation is 100 (corrected from 255) - rgb[3] = (byte)((255.0f - sat) / 255.0f * (rgb[0] + rgb[1] + rgb[2]) / 3); -} -*/ - -byte correctionRGB[4] = {0,0,0,0}; -uint16_t lastKelvin = 0; - // adjust RGB values based on color temperature in K (range [2800-10200]) (https://en.wikipedia.org/wiki/Color_balance) +// called from bus manager when color correction is enabled! uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb) { //remember so that slow colorKtoRGB() doesn't have to run for every setPixelColor() + static byte correctionRGB[4] = {0,0,0,0}; + static uint16_t lastKelvin = 0; if (lastKelvin != kelvin) colorKtoRGB(kelvin, correctionRGB); // convert Kelvin to RGB lastKelvin = kelvin; byte rgbw[4]; @@ -320,8 +301,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 +320,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 const 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) { @@ -347,9 +354,11 @@ uint8_t gamma8_cal(uint8_t b, float gamma) // re-calculates & fills gamma table void calcGammaTable(float gamma) { +#if !defined(WLED_USE_CIE_BRIGHTNESS_TABLE) // WLEDMM not possible when using the CIE table for (uint16_t i = 0; i < 256; i++) { gammaT[i] = gamma8_cal(i, gamma); } +#endif } // used for individual channel or brightness gamma correction diff --git a/wled00/const.h b/wled00/const.h index a6ffe0a5..288b4b3f 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 Random Smooth 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 @@ -60,6 +79,17 @@ #define WLED_MAX_COLOR_ORDER_MAPPINGS 10 #endif +#if defined(WLED_MAX_LEDMAPS) && (WLED_MAX_LEDMAPS > 32 || WLED_MAX_LEDMAPS < 10) + #undef WLED_MAX_LEDMAPS +#endif +#ifndef WLED_MAX_LEDMAPS + #ifdef ESP8266 + #define WLED_MAX_LEDMAPS 10 + #else + #define WLED_MAX_LEDMAPS 16 + #endif +#endif + //Usermod IDs #define USERMOD_ID_RESERVED 0 //Unused. Might indicate no usermod present #define USERMOD_ID_UNSPECIFIED 1 //Default value for a general user mod that does not specify a custom ID @@ -79,7 +109,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 +127,16 @@ #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 +#define USERMOD_ID_KLIPPER 40 // Usermod Klipper percentage //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_ARTIFX 90 //Usermod "usermod_v2_artifx.h" +#define USERMOD_ID_WEATHER 91 //Usermod "usermod_v2_weather.h" +#define USERMOD_ID_GAMES 92 //Usermod "usermod_v2_games.h" +#define USERMOD_ID_FASTLED 93 //Usermod "usermod_v2_fastled.h" //Access point behavior #define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot @@ -119,17 +154,19 @@ #define CALL_MODE_FX_CHANGED 6 //no longer used #define CALL_MODE_HUE 7 #define CALL_MODE_PRESET_CYCLE 8 -#define CALL_MODE_BLYNK 9 +#define CALL_MODE_BLYNK 9 //no longer used #define CALL_MODE_ALEXA 10 #define CALL_MODE_WS_SEND 11 //special call mode, not for notifier, updates websocket only #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 +188,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 +212,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 +311,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 +339,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 @@ -316,11 +364,11 @@ #define MAX_LEDS_PER_BUS 2048 // may not be enough for fast LEDs (i.e. APA102) #endif -// string temp buffer (now stored in stack locally) +// string temp buffer (now stored in stack locally) // WLEDMM ...which is actually not the greatest design choice on ESP32 #ifdef ESP8266 #define SETTINGS_STACK_BUF_SIZE 2048 #else -#define SETTINGS_STACK_BUF_SIZE 3096 +#define SETTINGS_STACK_BUF_SIZE 3712 // WLEDMM added 512 bytes of margin (was 3096) #endif #ifdef WLED_USE_ETHERNET @@ -334,7 +382,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 @@ -361,8 +409,8 @@ #define JSON_BUFFER_SIZE 24576 #endif -//#define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048) -#define MIN_HEAP_SIZE (8192) +//#define MIN_HEAP_SIZE (8k for AsyncWebServer) +#define MIN_HEAP_SIZE 8192 // Maximum size of node map (list of other WLED instances) #ifdef ESP8266 @@ -394,43 +442,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..d12942b6 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 { @@ -391,12 +392,16 @@ button { } .slider { - background-color: var(--c-2); max-width: 300px; - min-width: 280px; + min-width: 260px; margin: 0 auto; /* add 5px; if you want some vertical space but looks ugly */ border-radius: 24px; position: relative; + padding-bottom: 2px; +} + +#sliders .slider, #info .slider { + background-color: var(--c-2); } .filter, .option { @@ -424,17 +429,20 @@ button { box-shadow: 4px 4px 10px 4px var(--c-1); color: var(--c-f); text-align: center; - padding: 5px 10px; + padding: 4px 8px; border-radius: 6px; /* Position the tooltip text */ width: 160px; position: absolute; z-index: 1; - bottom: 100%; + bottom: 80%; 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; @@ -643,7 +651,7 @@ img { #wbal .sliderdisplay { background: linear-gradient(90deg, #ff8f1f 0%, #fff 50%, #cbdbff); } /* wrapper divs hidden by default */ -#rgbwrap, #kwrap, #wwrap, #wbal, #qcs-w, #hexw { +#rgbwrap, #swrap, #hwrap, #kwrap, #wwrap, #wbal, #qcs-w, #hexw { display: none; } @@ -727,9 +735,13 @@ input[type=range]::-moz-range-thumb { #Colors .sliderwrap { width: 260px; - margin: 10px 0 0; + margin: 4px 0 0; } +/* #Colors { + padding-top: 18px; +} + */ /* Dynamically hide brightness slider label */ .hd { display: var(--bhd); @@ -740,13 +752,14 @@ input[type=range]::-moz-range-thumb { margin-top: var(--bmt); } -#picker, #rgbwrap, #kwrap, #wwrap, #wbal, #vwrap, #qcs-w, #hexw, #pall, #ledmap { +#picker, #qcs-w, #hexw, #pall, #ledmap { margin: 0 auto; width: 260px; + /*background-color: unset;*/ } #picker { - margin-top: 10px; + margin-top: -10px !important; } /* buttons */ @@ -864,8 +877,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 +902,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 +994,7 @@ textarea { .segname, .pname { white-space: nowrap; - cursor: pointer; + /*cursor: pointer;*/ text-align: center; overflow: clip; text-overflow: ellipsis; @@ -1185,7 +1198,7 @@ TD .checkmark, TD .radiomark { } .bp { - margin-bottom: 5px; + margin-bottom: 8px; } /* segment & preset wrapper */ @@ -1220,7 +1233,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 +1343,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 +1374,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 { @@ -1405,6 +1418,9 @@ TD .checkmark, TD .radiomark { .expanded { display: inline-block !important; } +.expanded .segin.hide, .expanded .presin.hide, .expanded .sbs.hide { + display: none !important; +} .m6 { margin: 6px 0; @@ -1501,7 +1517,7 @@ TD .checkmark, TD .radiomark { } } -@media all and (max-width: 1249px) { +@media all and (max-width: 1024px) { #buttonPcm { display: none; } diff --git a/wled00/data/index.htm b/wled00/data/index.htm index c91bc0c2..ebf0d711 100644 --- a/wled00/data/index.htm +++ b/wled00/data/index.htm @@ -6,6 +6,7 @@ + WLED - + @@ -65,7 +66,7 @@ - + @@ -88,94 +89,102 @@
-
-
- -
- -
-

-
-
- -
- -
-

-
-
- -
- -
-

-
-
- -
- -
-
-
-
-

RGB color

-
+
+
+
+
- + +
+
+ Hue +
+
+
+ +
+
+ Saturation +
+
+
+
+ Value/Brightness
-
+
- +
+ Kelvin/Temperature
-
-
- -
+
+ +
+
+ +
+
+ Red channel +
+
+
+ +
+
+ Green channel +
+
+
+ +
+
+ Blue channel
-
-
-

White channel

-
- -
+
+ +
+ +
+
+ White channel
-
-
-

White balance

-
- -
+
+ +
+ +
+
+ White balance
-
-
-
-
-
-
-
-

-
-
-
-
-
R
-
-
- - - -
-

-
- - - -
+
+
+
+
+
+
+

+
+
+
+
+
R
+
+
+ + + +
+

+
+ + + +
+

Color palette

@@ -198,6 +207,12 @@
+
+ +
+
+
+

Effect mode

@@ -287,15 +302,15 @@
@@ -303,15 +318,22 @@
+
+
+
+
+
+

Segments

Loading...
+
-

Transition:  s

+

Transition:  s

@@ -339,7 +361,7 @@
-
+

- Made with ❤︎ by Aircoookie and the WLED community + WLED made with ❤︎ by Aircoookie and the WLED community
+ WLED MM made with ❤︎ by Softhack007 & Ewowi and the WLED 2D & Audio Dev community
- + @@ -387,6 +413,6 @@

- + diff --git a/wled00/data/index.js b/wled00/data/index.js index c4566648..50459b17 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -1,10 +1,10 @@ //page js var loc = false, locip; -var noNewSegs = false; var isOn = false, nlA = false, isLv = false, isInfo = false, isNodes = false, syncSend = false, syncTglRecv = true; var hasWhite = false, hasRGB = false, hasCCT = false; var nlDur = 60, nlTar = 0; var nlMode = false; +var segLmax = 0; // size (in pixels) of largest selected segment var selectedFx = 0; var selectedPal = 0; var csel = 0; // selected color slot (0-2) @@ -17,6 +17,7 @@ var d = document; var palettesData; var fxdata = []; var pJson = {}, eJson = {}, lJson = {}; +var plJson = {}; // array of playlists var pN = "", pI = 0, pNum = 0; var pmt = 1, pmtLS = 0, pmtLast = 0; var lastinfo = {}; @@ -25,7 +26,7 @@ var ws, cpick, ranges; var cfg = { theme:{base:"dark", bg:{url:""}, alpha:{bg:0.6,tab:0.8}, color:{bg:""}}, comp :{colors:{picker: true, rgb: false, quick: true, hex: false}, - labels:true, pcmbot:false, pid:true, seglen:false, segpwr:false, segexp:false, css:true, hdays:false} + labels:true, pcmbot:false, pid:true, seglen:false, segpwr:false, segexp:true, css:true, hdays:false} //WLEDMM segexp true as default }; var hol = [ [0,11,24,4,"https://aircoookie.github.io/xmas.png"], // christmas @@ -36,6 +37,9 @@ var hol = [ [0,6,4,1,"https://initiate.alphacoders.com/download/wallpaper/516792/images/jpg/510921363292536"], // 4th of July [0,0,1,1,"https://initiate.alphacoders.com/download/wallpaper/1198800/images/jpg/2522807481585600"] // new year ]; +var ctx = null; // WLEDMM +var ledmapNr = -1; //WLEDMM +var ledmapFileNames = []; //WLEDMM function handleVisibilityChange() {if (!d.hidden && new Date () - lastUpdate > 3000) requestJson();} function sCol(na, col) {d.documentElement.style.setProperty(na, col);} @@ -60,13 +64,10 @@ function setCSL(cs) let w = cs.dataset.w ? parseInt(cs.dataset.w) : 0; let hasShadow = getComputedStyle(cs).textShadow !== "none"; if (hasRGB && !isRgbBlack(cs.dataset)) { - cs.style.backgroundColor = rgbStr(cs.dataset); if (!hasShadow) cs.style.color = rgbBri(cs.dataset) > 127 ? "#000":"#fff"; // if text has no CSS "shadow" - if (hasWhite && w > 0) { - cs.style.background = `linear-gradient(180deg, ${rgbStr(cs.dataset)} 30%, rgb(${w},${w},${w}))`; - } + cs.style.background = (hasWhite && w > 0) ? `linear-gradient(180deg, ${rgbStr(cs.dataset)} 30%, rgb(${w},${w},${w}))` : rgbStr(cs.dataset); } else { - if (!hasWhite) w = 0; + if (hasRGB && !hasWhite) w = 0; cs.style.background = `rgb(${w},${w},${w})`; if (!hasShadow) cs.style.color = w > 127 ? "#000":"#fff"; } @@ -273,9 +274,9 @@ function onLoad() function updateTablinks(tabI) { var tablinks = gEBCN("tablinks"); - for (var i of tablinks) i.classList.remove("active"); + for (var i of tablinks) i.classList.remove('active'); if (pcMode) return; - tablinks[tabI].classList.add("active"); + tablinks[tabI].classList.add('active'); } function openTab(tabI, force = false) @@ -291,13 +292,13 @@ var timeout; function showToast(text, error = false) { if (error) gId('connind').style.backgroundColor = "var(--c-r)"; - var x = gId("toast"); + var x = gId('toast'); //if (error) text += ''; x.innerHTML = text; - x.classList.add(error ? "error":"show"); + x.classList.add(error ? 'error':'show'); clearTimeout(timeout); x.style.animation = 'none'; - timeout = setTimeout(()=>{ x.classList.remove("show"); }, 2900); + timeout = setTimeout(()=>{ x.classList.remove('show'); }, 2900); if (error) console.log(text); } @@ -308,12 +309,12 @@ function showErrorToast() function clearErrorToast(n=5000) { - var x = gId("toast"); - if (x.classList.contains("error")) { + var x = gId('toast'); + if (x.classList.contains('error')) { clearTimeout(timeout); timeout = setTimeout(()=>{ - x.classList.remove("show"); - x.classList.remove("error"); + x.classList.remove('show'); + x.classList.remove('error'); }, n); } } @@ -522,7 +523,7 @@ function loadFXData(callback = null) fxdata = json||[]; // add default value for Solid fxdata.shift() - fxdata.unshift(";!;0"); + fxdata.unshift(";!;"); }) .catch((e)=>{ fxdata = []; @@ -539,13 +540,13 @@ function populateQL() { var cn = ""; if (pQL.length > 0) { - pQL.sort((a,b) => (a[0]>b[0])); + pQL.sort((a,b) => (a[1]>b[1])); //WLEDMM do not sort on preset id but on ql name cn += `

Quick load

`; for (var key of (pQL||[])) { cn += ``; } - gId('pql').classList.add("expanded"); - } else gId('pql').classList.remove("expanded"); + gId('pql').classList.add('expanded'); + } else gId('pql').classList.remove('expanded'); gId('pql').innerHTML = cn; } @@ -570,7 +571,8 @@ function populatePresets(fromls) cn += `
`; if (cfg.comp.pid) cn += `
${i}
`; - cn += `
${isPlaylist(i)?"":""}${pName(i)} + //WLEDMM: show ql if defined + cn += `
${isPlaylist(i)?"":""}${(pJson[i].ql?pJson[i].ql+' ':'') + pName(i)}
@@ -609,9 +611,11 @@ function parseInfo(i) { mw = i.leds.matrix ? i.leds.matrix.w : 0; mh = i.leds.matrix ? i.leds.matrix.h : 0; isM = mw>0 && mh>0; - if (!isM) { - gId("filter1D").classList.add("hide"); - //gId("filter2D").classList.add("hide"); + if (isM) { + gId('buttonSr').className = "active"; isLv = true; //WLEDMM: on after load + } else { + gId("filter1D").classList.add('hide'); + //gId("filter2D").classList.add('hide'); hideModes("2D"); } // if (i.noaudio) { @@ -641,8 +645,10 @@ function populateInfo(i) { var cn=""; var heap = i.freeheap/1000; - heap = heap.toFixed(1); - var theap = (i.totalheap>0)?i.totalheap/1000:-1; theap = theap.toFixed(1); //WLEDMM - total heap is not available on 8266 + var heap = Math.round(i.freeheap/100)/10; // WLEDMM bugfix + var theap = (i.totalheap>0)?i.totalheap/1000:-1; //WLEDMM - total heap is not available on 8266 + var flashsize = i.getflash/1000; //WLEDMM and Athom + flashsize = flashsize.toFixed(1); //WLEDMM and Athom var pwr = i.leds.pwr; var pwru = "Not calculated"; if (pwr > 1000) {pwr /= 1000; pwr = pwr.toFixed((pwr > 10) ? 0 : 1); pwru = pwr + " A";} @@ -662,33 +668,40 @@ function populateInfo(i) if (i.cn) vcn = i.cn; //WLEDMM: add total heap and total PSRAM, and build number, add bin name - if (i.ver.includes("0.14.1.")) vcn = "Sitting Ducks"; // easter egg - if (i.ver.includes("0.14.0.")) vcn = "Lupo"; // check for MM versioning scheme - cn += `v${i.ver}  "${vcn}"

(WLEDMM_${i.ver}_${i.rel}.bin)

build ${i.vid}

+ if (i.ver.includes("0.14.1")) vcn = "Sitting Ducks"; // easter egg + if (i.ver.includes("0.14.0")) vcn = "Lupo"; // check for MM versioning scheme + if (i.ver.includes("0.14.0-b2.2")) vcn = "Sitting Ducks"; // early easter egg + if (i.ver.includes("0.14.0-b15.21")) vcn = "Lupo"; + cn += `v${i.ver}  "${vcn}"

(WLEDMM_${i.ver} ${i.rel}.bin)

build ${i.vid}

${urows} -${urows===""?'':''} -${i.opt&0x100?inforow("Debug",""):''} +${urows===""?'':''} +${i.opt&0x100?inforow("Net Print ☾",""):''} +${i.serialOnline?inforow(i.serialOnline,"TX="+i.sTX,"; RX="+i.sRX):""} +${i.opt&0x100?'':''} ${inforow("Build",i.vid)} -${inforow("Signal strength",i.wifi.signal +"% ("+ i.wifi.rssi, " dBm)")} -${inforow("Uptime",getRuntimeStr(i.uptime))} ${inforow("Estimated current",pwru)} ${inforow("Average FPS",i.leds.fps)} +${inforow("Signal strength",i.wifi.signal +"% ("+ i.wifi.rssi, " dBm)")} +${inforow("Uptime",getRuntimeStr(i.uptime))} -${inforow("MAC address",i.mac)} ${inforow("Filesystem",i.fs.u + "/" + i.fs.t + " kB (" +Math.round(i.fs.u*100/i.fs.t) + "%)")} +${theap>0?inforow("Heap ☾",((i.totalheap-i.freeheap)/1000).toFixed(0)+"/"+theap.toFixed(0)+" kB"," ("+Math.round((i.totalheap-i.freeheap)/(10*theap))+"%)"):""} +${i.minfreeheap?inforow("Max used heap ☾",((i.totalheap-i.minfreeheap)/1000).toFixed(1)+" kB"," ("+Math.round((i.totalheap-i.minfreeheap)/(10*theap))+"%)"):""} +${inforow("Free heap",heap," kB")} +${inforow("Flash Size ☾",flashsize," kB")} +${i.tpram?inforow("PSRAM ☾",(i.tpram/1024).toFixed(1)," kB"):""} +${i.psram?((i.tpram-i.psram)>16383?inforow("Used PSRAM ☾",((i.tpram-i.psram)/1024).toFixed(1)," kB"):inforow("Used PSRAM ☾",(i.tpram-i.psram)," B")):""} +${i.psusedram?((i.tpram-i.psusedram)>16383?inforow("Max used PSRAM ☾",((i.tpram-i.psusedram)/1024).toFixed(1)," kB"):inforow("Max used PSRAM ☾",(i.tpram-i.psusedram)," B")):""} +${i.psram?inforow("Free PSRAM",(i.psram/1024).toFixed(1)," kB"):""} +${inforow("MAC address",i.mac)} ${inforow("Environment",i.arch + " " + i.core + " (" + i.lwip + ")")} -${theap>0?inforow("Total heap",theap," kB"):""} -${theap>0?inforow("used heap",((i.totalheap-i.freeheap)/1000).toFixed(1)," kB"):inforow("Free heap",heap," kB")} -${i.minfreeheap?inforow("Max used heap",((i.totalheap-i.minfreeheap)/1000).toFixed(1)," kB"):""} -${i.tpram?inforow("Total PSRAM",(i.tpram/1024).toFixed(1)," kB"):""} -${i.psram?((i.tpram-i.psram)>16383?inforow("Used PSRAM",((i.tpram-i.psram)/1024).toFixed(1)," kB"):inforow("Used PSRAM",(i.tpram-i.psram)," B")):""} -${i.psusedram?((i.tpram-i.psusedram)>16383?inforow("Max Used PSRAM",((i.tpram-i.psusedram)/1024).toFixed(1)," kB"):inforow("Max Used PSRAM",(i.tpram-i.psusedram)," B")):""} -${i.e32model?inforow(i.e32model,i.e32cores +" core(s)"," "+i.e32speed+" Mhz"):""} -${i.e32flash?inforow("Flash "+i.e32flash+" MB"+", mode "+i.e32flashmode+i.e32flashtext,i.e32flashspeed," Mhz"):""} -${i.e32core0code?inforow("Core0 rst reason",i.e32core0code, " "+i.e32core0text):""} -${i.e32core1code?inforow("Core1 rst reason",i.e32core1code, " "+i.e32core1text):""} +${i.e32model?inforow(i.e32model + " ☾",i.e32cores +" core(s)"," "+i.e32speed+" Mhz"):""} +${i.e32flash?inforow("Flash "+i.e32flash+"MB"+" mode "+i.e32flashmode+i.e32flashtext + " ☾",i.e32flashspeed," Mhz"):""} +${i.e32code?inforow("Last ESP Restart ☾",i.e32code+" "+i.e32text):""} +${i.e32core0code?inforow("Core0 rst reason ☾",i.e32core0code, " "+i.e32core0text):""} +${i.e32core1code?inforow("Core1 rst reason ☾",i.e32core1code, " "+i.e32core1text):""}





`; gId('kv').innerHTML = cn; @@ -705,6 +718,9 @@ function populateSegments(s) let li = lastinfo; segCount = 0; lowestUnused = 0; lSeg = 0; + ledmapNr = s.ledmap; //WLEDMM + ledmapFileNames = []; //WLEDMM + for (var inst of (s.seg||[])) { segCount++; @@ -713,7 +729,9 @@ function populateSegments(s) if (i > lSeg) lSeg = i; let sg = gId(`seg${i}`); - let exp = sg ? (sg.classList.contains("expanded") || (i===0 && cfg.comp.segexp)) : false; + let exp = sg ? (sg.classList.contains('expanded') || (i===0 && cfg.comp.segexp)) : false; + + ledmapFileNames.push((inst.n?inst.n:"default") + ".json"); //WLEDMM let segp = `
@@ -729,7 +747,7 @@ function populateSegments(s) let rvXck = ``; let miXck = ``; let rvYck = "", miYck =""; - if (isM) { + if (isM && staXReverse`; miYck = ``; } @@ -740,9 +758,9 @@ function populateSegments(s) - - - + + +
`; let sndSim = `
Sound sim
@@ -753,9 +771,9 @@ function populateSegments(s)
`; - //WLEDMM Custom Effects + //WLEDMM ARTIFX let fxName = eJson.find((o)=>{return o.id==selectedFx}).name; - let cusEff = `
`; + let cusEff = `
`; cn += `