Compare commits
1 Commits
main
...
preset-dir
Author | SHA1 | Date | |
---|---|---|---|
|
18a54b7693 |
21
.github/workflows/wled-ci.yml
vendored
@ -8,23 +8,21 @@ jobs:
|
|||||||
name: Gather Environments
|
name: Gather Environments
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Cache pip
|
- name: Cache pip
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v2
|
||||||
with:
|
|
||||||
python-version: '3.9'
|
|
||||||
- name: Install PlatformIO
|
- name: Install PlatformIO
|
||||||
run: pip install -r requirements.txt
|
run: pip install -r requirements.txt
|
||||||
- name: Get default environments
|
- name: Get default environments
|
||||||
id: envs
|
id: envs
|
||||||
run: |
|
run: |
|
||||||
echo "environments=$(pio project config --json-output | jq -cr '.[0][1][0][1]')" >> $GITHUB_OUTPUT
|
echo "::set-output name=environments::$(pio project config --json-output | jq -cr '.[0][1][0][1]')"
|
||||||
outputs:
|
outputs:
|
||||||
environments: ${{ steps.envs.outputs.environments }}
|
environments: ${{ steps.envs.outputs.environments }}
|
||||||
|
|
||||||
@ -34,27 +32,24 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: get_default_envs
|
needs: get_default_envs
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
environment: ${{ fromJSON(needs.get_default_envs.outputs.environments) }}
|
environment: ${{ fromJSON(needs.get_default_envs.outputs.environments) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Cache pip
|
- name: Cache pip
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
- name: Cache PlatformIO
|
- name: Cache PlatformIO
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ~/.platformio
|
path: ~/.platformio
|
||||||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v2
|
||||||
with:
|
|
||||||
python-version: '3.9'
|
|
||||||
- name: Install PlatformIO
|
- name: Install PlatformIO
|
||||||
run: pip install -r requirements.txt
|
run: pip install -r requirements.txt
|
||||||
- name: Build firmware
|
- name: Build firmware
|
||||||
|
34
.gitignore
vendored
@ -1,24 +1,20 @@
|
|||||||
.cache
|
|
||||||
.clang-format
|
|
||||||
.direnv
|
|
||||||
.DS_Store
|
|
||||||
.gitignore
|
|
||||||
.idea
|
|
||||||
.pio
|
.pio
|
||||||
|
.cache
|
||||||
.pioenvs
|
.pioenvs
|
||||||
.piolibdeps
|
.piolibdeps
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
esp01-update.sh
|
|
||||||
platformio_override.ini
|
|
||||||
replace_fs.py
|
|
||||||
wled-update.sh
|
|
||||||
|
|
||||||
/build_output/
|
|
||||||
/node_modules/
|
|
||||||
|
|
||||||
/wled00/extLibs
|
|
||||||
/wled00/LittleFS
|
|
||||||
/wled00/my_config.h
|
|
||||||
/wled00/Release
|
/wled00/Release
|
||||||
/wled00/wled00.ino.cpp
|
/wled00/extLibs
|
||||||
|
/platformio_override.ini
|
||||||
|
/wled00/my_config.h
|
||||||
|
/build_output
|
||||||
|
.DS_Store
|
||||||
|
.gitignore
|
||||||
|
.clang-format
|
||||||
|
node_modules
|
||||||
|
.idea
|
||||||
|
.direnv
|
||||||
|
wled-update.sh
|
||||||
|
esp01-update.sh
|
||||||
|
/wled00/LittleFS
|
||||||
|
replace_fs.py
|
205
CHANGELOG.md
@ -1,210 +1,5 @@
|
|||||||
## WLED changelog
|
## WLED changelog
|
||||||
|
|
||||||
#### Build 2310010, build 2310130
|
|
||||||
- Release of WLED version 0.14.0 "Hoshi"
|
|
||||||
- Bugfixes for #3400, #3403, #3405
|
|
||||||
- minor HTML optimizations
|
|
||||||
- audioreactive: bugfix for UDP sound sync (partly initialized packets)
|
|
||||||
|
|
||||||
#### Build 2309240
|
|
||||||
- Release of WLED beta version 0.14.0-b6 "Hoshi"
|
|
||||||
- Effect bugfixes and improvements (Meteor, Meteor Smooth, Scrolling Text)
|
|
||||||
- audioreactive: bugfixes for ES8388 and ES7243 init; minor improvements for analog inputs
|
|
||||||
|
|
||||||
#### Build 2309100
|
|
||||||
- Release of WLED beta version 0.14.0-b5 "Hoshi"
|
|
||||||
- New standard esp32 build with audioreactive
|
|
||||||
- Effect blending bugfixes, and minor optimizations
|
|
||||||
|
|
||||||
#### Build 2309050
|
|
||||||
- Effect blending (#3311) (finally effect transitions!)
|
|
||||||
*WARNING*: May not work well with ESP8266, with plenty of segments or usermods (low RAM condition)!!!
|
|
||||||
- Added receive and send sync groups to JSON API (#3317) (you can change sync groups using preset)
|
|
||||||
- Internal temperature usermod (#3246)
|
|
||||||
- MQTT server and topic length overrides (#3354) (new build flags)
|
|
||||||
- Animated Staircase usermod enhancement (#3348) (on/off toggle/relay control)
|
|
||||||
- Added local time info to Info page (#3351)
|
|
||||||
- New effect: Rolling Balls (a.k.a. linear bounce) (#1039)
|
|
||||||
- Various bug fixes and enhancements.
|
|
||||||
|
|
||||||
#### Build 2308110
|
|
||||||
- Release of WLED beta version 0.14.0-b4 "Hoshi"
|
|
||||||
- Reset effect data immediately upon mode change
|
|
||||||
|
|
||||||
#### Build 2308030
|
|
||||||
- Improved random palette handling and blending
|
|
||||||
- Soap bugfix
|
|
||||||
- Fix ESP-NOW crash with AP mode Always
|
|
||||||
|
|
||||||
#### Build 2307180
|
|
||||||
- Bus-level global buffering (#3280)
|
|
||||||
- Removed per-segment LED buffer (SEGMENT.leds)
|
|
||||||
- various fixes and improvements (ESP variants platform 5.3.0, effect optimizations, /json/cfg pin allocation)
|
|
||||||
|
|
||||||
#### Build 2307130
|
|
||||||
- larger `oappend()` stack buffer (3.5k) for ESP32
|
|
||||||
- Preset cycle bugfix (#3262)
|
|
||||||
- Rotary encoder ALT fix for large LED count (#3276)
|
|
||||||
- effect updates (2D Plasmaball), `blur()` speedup
|
|
||||||
- On/Off toggle from nodes view (may show unknown device type on older versions) (#3291)
|
|
||||||
- various fixes and improvements (ABL, crashes when changing presets with different segments)
|
|
||||||
|
|
||||||
#### Build 2306270
|
|
||||||
- ESP-NOW remote support (#3237)
|
|
||||||
- Pixel Magic tool (display pixel art) (#3249)
|
|
||||||
- Websocket (peek) fallback when connection cannot be established, WS retries (#3267)
|
|
||||||
- Add WiFi network scan RPC command to Improv Serial (#3271)
|
|
||||||
- Longer (custom option available) segment name for ESP32
|
|
||||||
- various fixes and improvements
|
|
||||||
|
|
||||||
#### Build 2306210
|
|
||||||
- 0.14.0-b3 release
|
|
||||||
- respect global I2C in all usermods (no local initialization of I2C bus)
|
|
||||||
- Multi relay usermod compile-time enabled option (-D MULTI_RELAY_ENABLED=true|false)
|
|
||||||
|
|
||||||
#### Build 2306180
|
|
||||||
- Added client-side option for applying effect defaults from metadata
|
|
||||||
- Improved ESP8266 stability by reducing WebSocket response resends
|
|
||||||
- Updated ESP8266 core to 3.1.2
|
|
||||||
|
|
||||||
#### Build 2306141
|
|
||||||
- Lissajous improvements
|
|
||||||
- Scrolling Text improvements (leading 0)
|
|
||||||
|
|
||||||
#### Build 2306140
|
|
||||||
- Add settings PIN (un)locking to JSON post API
|
|
||||||
|
|
||||||
#### Build 2306130
|
|
||||||
- Bumped version to 0.14-b3 (beta 3)
|
|
||||||
- added pin dropdowns in LED preferences (not for LED pins) and usermods
|
|
||||||
- introduced (unused ATM) NeoGammaWLEDMethod class
|
|
||||||
- Reverse proxy support
|
|
||||||
- PCF8754 support for Rotary encoder (requires wiring INT pin to ESP GPIO)
|
|
||||||
- Rely on global I2C pins for usermods (breaking change)
|
|
||||||
- various fixes and enhancements
|
|
||||||
|
|
||||||
#### Build 2306020
|
|
||||||
- Support for segment sets (PR #3171)
|
|
||||||
- Reduce sound simulation modes to 2 to facilitate segment sets
|
|
||||||
- Trigger button immediately on press if all configured presets are the same (PR #3226)
|
|
||||||
- Changes for allowing Alexa to change light color to White when auto-calculating from RGB (PR #3211)
|
|
||||||
|
|
||||||
#### Build 2305280
|
|
||||||
- DDP protocol update (#3193)
|
|
||||||
- added PCF8574 I2C port expander support for Multi relay usermod
|
|
||||||
- MQTT multipacket (fragmented) message fix
|
|
||||||
- added option to retain MQTT brightness and color messages
|
|
||||||
- new ethernet board: @srg74 Ethernet Shield
|
|
||||||
- new 2D effects: Soap (#3184) & Octopus & Waving cell (credit @St3P40 https://github.com/80Stepko08)
|
|
||||||
- various fixes and enhancements
|
|
||||||
|
|
||||||
#### Build 2305090
|
|
||||||
- new ethernet board: @Wladi ABC! WLED Eth
|
|
||||||
- Battery usermod voltage calculation (#3116)
|
|
||||||
- custom palette editor (#3164)
|
|
||||||
- improvements in Dancing Shadows and Tartan effects
|
|
||||||
- UCS389x support
|
|
||||||
- switched to NeoPixelBus 2.7.5 (replaced NeoPixelBrightnessBus with NeoPixelBusLg)
|
|
||||||
- SPI bus clock selection (for LEDs) (#3173)
|
|
||||||
- DMX mode preset fix (#3134)
|
|
||||||
- iOS fix for scroll (#3182)
|
|
||||||
- Wordclock "Norddeutsch" fix (#3161)
|
|
||||||
- various fixes and enhancements
|
|
||||||
|
|
||||||
#### Build 2304090
|
|
||||||
- updated Arduino ESP8266 core to 4.1.0 (newer compiler)
|
|
||||||
- updated NeoPixelBus to 2.7.3 (with support for UCS890x chipset)
|
|
||||||
- better support for ESP32-C3, ESP32-S2 and ESP32-S3 (Arduino ESP32 core 5.2.0)
|
|
||||||
- iPad/tablet with 1024 pixels width in landscape orientation PC mode support (#3153)
|
|
||||||
- fix for Pixel Art Converter (#3155)
|
|
||||||
|
|
||||||
#### Build 2303240
|
|
||||||
- Peek scaling of large 2D matrices
|
|
||||||
- Added 0D (1 pixel) metadata for effects & enhance 0D (analog strip) UI handling
|
|
||||||
- Added ability to disable ADAlight (-D WLED_DISABLE_ADALIGHT)
|
|
||||||
- Fixed APA102 output on Ethernet enabled controllers
|
|
||||||
- Added ArtNet virtual/network output (#3121)
|
|
||||||
- Klipper usermod (#3106)
|
|
||||||
- Remove DST from CST timezone
|
|
||||||
- various fixes and enhancements
|
|
||||||
|
|
||||||
#### Build 2302180
|
|
||||||
|
|
||||||
- Removed Blynk support (servers shut down on 31st Dec 2022)
|
|
||||||
- Added `ledgap.json` to complement ledmaps for 2D matrices
|
|
||||||
- Added support for white addressable strips (#3073)
|
|
||||||
- Ability to use SHT temperature usermod with PWM fan usermod
|
|
||||||
- Added `onStateChange()` callback to usermods (#3081)
|
|
||||||
- Refactored `bus_manager` [internal]
|
|
||||||
- Dual 1D & 2D mode (add 1D strip after the matrix)
|
|
||||||
- Removed 1D -> 2D mapping for individual pixel control
|
|
||||||
- effect tweak: Fireworks 1D
|
|
||||||
- various bugfixes
|
|
||||||
|
|
||||||
#### 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
|
### WLED release 0.13.3
|
||||||
|
|
||||||
- Version bump to v0.13.3 "Toki"
|
- Version bump to v0.13.3 "Toki"
|
||||||
|
729
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wled",
|
"name": "wled",
|
||||||
"version": "0.14.0",
|
"version": "0.14.0-b0",
|
||||||
"description": "Tools for WLED project",
|
"description": "Tools for WLED project",
|
||||||
"main": "tools/cdata.js",
|
"main": "tools/cdata.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
@ -25,7 +25,7 @@
|
|||||||
"clean-css": "^4.2.3",
|
"clean-css": "^4.2.3",
|
||||||
"html-minifier-terser": "^5.1.1",
|
"html-minifier-terser": "^5.1.1",
|
||||||
"inliner": "^1.13.1",
|
"inliner": "^1.13.1",
|
||||||
"nodemon": "^2.0.20",
|
"nodemon": "^2.0.4",
|
||||||
"zlib": "^1.0.5"
|
"zlib": "^1.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
316
platformio.ini
@ -9,15 +9,11 @@
|
|||||||
# (use `platformio_override.ini` when building for your own board; see `platformio_override.ini.sample` for an example)
|
# (use `platformio_override.ini` when building for your own board; see `platformio_override.ini.sample` for an example)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# CI binaries
|
# Release / CI binaries
|
||||||
; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth # ESP32 variant builds are temporarily excluded from CI due to toolchain issues on the GitHub Actions Linux environment
|
default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3, esp32s3dev_8MB
|
||||||
default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32dev_audioreactive, lolin_s2_mini, esp32c3dev, esp32s3dev_8MB, esp32s3dev_8MB_PSRAM_opi
|
|
||||||
|
|
||||||
# Release binaries
|
|
||||||
; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, lolin_s2_mini, esp32c3dev, esp32s3dev_8MB
|
|
||||||
|
|
||||||
# Build everything
|
# 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, 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)
|
# Single binaries (uncomment your board)
|
||||||
; default_envs = elekstube_ips
|
; default_envs = elekstube_ips
|
||||||
@ -40,8 +36,6 @@ default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32d
|
|||||||
; default_envs = esp32dev_qio80
|
; default_envs = esp32dev_qio80
|
||||||
; default_envs = esp32_eth_ota1mapp
|
; default_envs = esp32_eth_ota1mapp
|
||||||
; default_envs = esp32s2_saola
|
; default_envs = esp32s2_saola
|
||||||
; default_envs = esp32c3dev
|
|
||||||
; default_envs = lolin_s2_mini
|
|
||||||
|
|
||||||
src_dir = ./wled00
|
src_dir = ./wled00
|
||||||
data_dir = ./wled00/data
|
data_dir = ./wled00/data
|
||||||
@ -61,37 +55,24 @@ arduino_core_2_6_3 = espressif8266@2.3.3
|
|||||||
arduino_core_2_7_4 = espressif8266@2.6.2
|
arduino_core_2_7_4 = espressif8266@2.6.2
|
||||||
arduino_core_3_0_0 = espressif8266@3.0.0
|
arduino_core_3_0_0 = espressif8266@3.0.0
|
||||||
arduino_core_3_2_0 = espressif8266@3.2.0
|
arduino_core_3_2_0 = espressif8266@3.2.0
|
||||||
arduino_core_4_1_0 = espressif8266@4.1.0
|
|
||||||
arduino_core_3_1_2 = espressif8266@4.2.0
|
|
||||||
|
|
||||||
# Development platforms
|
# Development platforms
|
||||||
arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop
|
arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop
|
||||||
arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage
|
arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage
|
||||||
|
|
||||||
# Platform to use for ESP8266
|
# Platform to use for ESP8266
|
||||||
platform_wled_default = ${common.arduino_core_3_1_2}
|
platform_wled_default = ${common.arduino_core_3_2_0}
|
||||||
# We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization
|
# We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization
|
||||||
#platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7
|
platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7
|
||||||
platform_packages = platformio/framework-arduinoespressif8266
|
platformio/toolchain-xtensa @ ~2.40802.200502
|
||||||
platformio/toolchain-xtensa @ ~2.100300.220621 #2.40802.200502
|
platformio/tool-esptool @ ~1.413.0
|
||||||
platformio/tool-esptool #@ ~1.413.0
|
platformio/tool-esptoolpy @ ~1.30000.0
|
||||||
platformio/tool-esptoolpy #@ ~1.30000.0
|
|
||||||
|
|
||||||
## previous platform for 8266, in case of problems with the new one
|
|
||||||
## you'll need makuna/NeoPixelBus@ 2.6.9 for arduino_core_3_2_0, which does not support Ucs890x
|
|
||||||
;; platform_wled_default = ${common.arduino_core_3_2_0}
|
|
||||||
;; platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7
|
|
||||||
;; platformio/toolchain-xtensa @ ~2.40802.200502
|
|
||||||
;; platformio/tool-esptool @ ~1.413.0
|
|
||||||
;; platformio/tool-esptoolpy @ ~1.30000.0
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# FLAGS: DEBUG
|
# FLAGS: DEBUG
|
||||||
# esp8266 : see https://docs.platformio.org/en/latest/platforms/espressif8266.html#debug-level
|
#
|
||||||
# esp32 : see https://docs.platformio.org/en/latest/platforms/espressif32.html#debug-level
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
debug_flags = -D DEBUG=1 -D WLED_DEBUG
|
debug_flags = -D DEBUG=1 -D WLED_DEBUG -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM
|
||||||
-DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM ;; for esp8266
|
|
||||||
#if needed (for memleaks etc) also add; -DDEBUG_ESP_OOM -include "umm_malloc/umm_malloc_cfg.h"
|
#if needed (for memleaks etc) also add; -DDEBUG_ESP_OOM -include "umm_malloc/umm_malloc_cfg.h"
|
||||||
#-DDEBUG_ESP_CORE is not working right now
|
#-DDEBUG_ESP_CORE is not working right now
|
||||||
|
|
||||||
@ -118,13 +99,11 @@ debug_flags = -D DEBUG=1 -D WLED_DEBUG
|
|||||||
# This reduces the OTA size with ~45KB, so it's especially useful on low memory boards (512k/1m).
|
# This reduces the OTA size with ~45KB, so it's especially useful on low memory boards (512k/1m).
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
build_flags =
|
build_flags =
|
||||||
-Wno-attributes
|
|
||||||
-DMQTT_MAX_PACKET_SIZE=1024
|
-DMQTT_MAX_PACKET_SIZE=1024
|
||||||
-DSECURE_CLIENT=SECURE_CLIENT_BEARSSL
|
-DSECURE_CLIENT=SECURE_CLIENT_BEARSSL
|
||||||
-DBEARSSL_SSL_BASIC
|
-DBEARSSL_SSL_BASIC
|
||||||
-D CORE_DEBUG_LEVEL=0
|
-D CORE_DEBUG_LEVEL=0
|
||||||
-D NDEBUG
|
-D NDEBUG
|
||||||
-Wno-attributes ;; silence warnings about unknown attribute 'maybe_unused' in NeoPixelBus
|
|
||||||
#build_flags for the IRremoteESP8266 library (enabled decoders have to appear here)
|
#build_flags for the IRremoteESP8266 library (enabled decoders have to appear here)
|
||||||
-D _IR_ENABLE_DEFAULT_=false
|
-D _IR_ENABLE_DEFAULT_=false
|
||||||
-D DECODE_HASH=true
|
-D DECODE_HASH=true
|
||||||
@ -132,7 +111,7 @@ build_flags =
|
|||||||
-D DECODE_SONY=true
|
-D DECODE_SONY=true
|
||||||
-D DECODE_SAMSUNG=true
|
-D DECODE_SAMSUNG=true
|
||||||
-D DECODE_LG=true
|
-D DECODE_LG=true
|
||||||
;-Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library ;; warning: this breaks framework code on ESP32-C3 and ESP32-S2
|
; -Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library
|
||||||
-DWLED_USE_MY_CONFIG
|
-DWLED_USE_MY_CONFIG
|
||||||
; -D USERMOD_SENSORSTOMQTT
|
; -D USERMOD_SENSORSTOMQTT
|
||||||
#For ADS1115 sensor uncomment following
|
#For ADS1115 sensor uncomment following
|
||||||
@ -142,7 +121,6 @@ build_unflags =
|
|||||||
|
|
||||||
build_flags_esp8266 = ${common.build_flags} ${esp8266.build_flags}
|
build_flags_esp8266 = ${common.build_flags} ${esp8266.build_flags}
|
||||||
build_flags_esp32 = ${common.build_flags} ${esp32.build_flags}
|
build_flags_esp32 = ${common.build_flags} ${esp32.build_flags}
|
||||||
build_flags_esp32_V4= ${common.build_flags} ${esp32_idf_V4.build_flags}
|
|
||||||
|
|
||||||
ldscript_1m128k = eagle.flash.1m128.ld
|
ldscript_1m128k = eagle.flash.1m128.ld
|
||||||
ldscript_2m512k = eagle.flash.2m512.ld
|
ldscript_2m512k = eagle.flash.2m512.ld
|
||||||
@ -172,21 +150,22 @@ upload_speed = 115200
|
|||||||
# LIBRARIES: required dependencies
|
# LIBRARIES: required dependencies
|
||||||
# Please note that we don't always use the latest version of a library.
|
# Please note that we don't always use the latest version of a library.
|
||||||
#
|
#
|
||||||
# The following libraries have been included (and some of them changed) in the source:
|
# The following libraries have been included (and some of them changd) in the source:
|
||||||
# ArduinoJson@5.13.5, E131@1.0.0(changed), Time@1.5, Timezone@1.2.1
|
# ArduinoJson@5.13.5, Blynk@0.5.4(changed), E131@1.0.0(changed), Time@1.5, Timezone@1.2.1
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
lib_compat_mode = strict
|
lib_compat_mode = strict
|
||||||
lib_deps =
|
lib_deps =
|
||||||
fastled/FastLED @ 3.6.0
|
fastled/FastLED @ 3.5.0
|
||||||
IRremoteESP8266 @ 2.8.2
|
IRremoteESP8266 @ 2.8.2
|
||||||
makuna/NeoPixelBus @ 2.7.5
|
|
||||||
https://github.com/Aircoookie/ESPAsyncWebServer.git @ ~2.0.7
|
https://github.com/Aircoookie/ESPAsyncWebServer.git @ ~2.0.7
|
||||||
#For use of the TTGO T-Display ESP32 Module with integrated TFT display uncomment the following line
|
#For use of the TTGO T-Display ESP32 Module with integrated TFT display uncomment the following line
|
||||||
#TFT_eSPI
|
#TFT_eSPI
|
||||||
#For compatible OLED display uncomment following
|
#For use SSD1306 OLED display uncomment following
|
||||||
#U8g2 #@ ~2.33.15
|
#U8g2@~2.28.8
|
||||||
#For Dallas sensor uncomment following
|
#U8g2@~2.32.10
|
||||||
#OneWire @ ~2.3.7
|
#For Dallas sensor uncomment following 2 lines
|
||||||
|
#OneWire@~2.3.5
|
||||||
|
#milesburton/DallasTemperature@^3.9.0
|
||||||
#For BME280 sensor uncomment following
|
#For BME280 sensor uncomment following
|
||||||
#BME280@~3.0.0
|
#BME280@~3.0.0
|
||||||
; adafruit/Adafruit BMP280 Library @ 2.1.0
|
; adafruit/Adafruit BMP280 Library @ 2.1.0
|
||||||
@ -203,9 +182,8 @@ build_flags =
|
|||||||
-DESP8266
|
-DESP8266
|
||||||
-DFP_IN_IROM
|
-DFP_IN_IROM
|
||||||
;-Wno-deprecated-declarations
|
;-Wno-deprecated-declarations
|
||||||
;-Wno-register ;; leaves some warnings when compiling C files: command-line option '-Wno-register' is valid for C++/ObjC++ but not for C
|
;-Wno-register
|
||||||
;-Dregister= # remove warnings in C++17 due to use of deprecated register keyword by the FastLED library ;; warning: this can be dangerous
|
;-Wno-misleading-indentation
|
||||||
-Wno-misleading-indentation
|
|
||||||
; NONOSDK22x_190703 = 2.2.2-dev(38a443e)
|
; NONOSDK22x_190703 = 2.2.2-dev(38a443e)
|
||||||
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190703
|
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190703
|
||||||
; lwIP 2 - Higher Bandwidth no Features
|
; lwIP 2 - Higher Bandwidth no Features
|
||||||
@ -216,110 +194,76 @@ build_flags =
|
|||||||
-DVTABLES_IN_FLASH
|
-DVTABLES_IN_FLASH
|
||||||
; restrict to minimal mime-types
|
; restrict to minimal mime-types
|
||||||
-DMIMETYPE_MINIMAL
|
-DMIMETYPE_MINIMAL
|
||||||
; other special-purpose framework flags (see https://docs.platformio.org/en/latest/platforms/espressif8266.html)
|
|
||||||
; -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48 ;; in case of linker errors like "section `.text1' will not fit in region `iram1_0_seg'"
|
|
||||||
; -D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED ;; (experimental) adds some extra heap, but may cause slowdown
|
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
${env.lib_deps}
|
||||||
#https://github.com/lorol/LITTLEFS.git
|
#https://github.com/lorol/LITTLEFS.git
|
||||||
ESPAsyncTCP @ 1.2.2
|
ESPAsyncTCP @ 1.2.2
|
||||||
ESPAsyncUDP
|
ESPAsyncUDP
|
||||||
${env.lib_deps}
|
makuna/NeoPixelBus @ 2.6.9
|
||||||
|
|
||||||
[esp32]
|
[esp32]
|
||||||
#platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.3/platform-espressif32-2.0.2.3.zip
|
#platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.3/platform-espressif32-2.0.2.3.zip
|
||||||
platform = espressif32@3.5.0
|
platform = espressif32@3.5.0
|
||||||
|
|
||||||
platform_packages = framework-arduinoespressif32 @ https://github.com/Aircoookie/arduino-esp32.git#1.0.6.4
|
platform_packages = framework-arduinoespressif32 @ https://github.com/Aircoookie/arduino-esp32.git#1.0.6.4
|
||||||
|
|
||||||
build_flags = -g
|
build_flags = -g
|
||||||
-DARDUINO_ARCH_ESP32
|
-DARDUINO_ARCH_ESP32
|
||||||
#-DCONFIG_LITTLEFS_FOR_IDF_3_2
|
#-DCONFIG_LITTLEFS_FOR_IDF_3_2
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
-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
|
#use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x
|
||||||
-D LOROL_LITTLEFS
|
-D LOROL_LITTLEFS
|
||||||
; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
|
|
||||||
default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
|
||||||
lib_deps =
|
|
||||||
https://github.com/lorol/LITTLEFS.git
|
|
||||||
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
|
||||||
${env.lib_deps}
|
|
||||||
# additional build flags for audioreactive
|
|
||||||
AR_build_flags = -D USERMOD_AUDIOREACTIVE -D UM_AUDIOREACTIVE_USE_NEW_FFT
|
|
||||||
AR_lib_deps = https://github.com/kosme/arduinoFFT#develop @ ^1.9.2
|
|
||||||
|
|
||||||
[esp32_idf_V4]
|
|
||||||
;; experimental build environment for ESP32 using ESP-IDF 4.4.x / arduino-esp32 v2.0.5
|
|
||||||
;; very similar to the normal ESP32 flags, but omitting Lorol LittleFS, as littlefs is included in the new framework already.
|
|
||||||
;;
|
|
||||||
;; please note that you can NOT update existing ESP32 installs with a "V4" build. Also updating by OTA will not work properly.
|
|
||||||
;; You need to completely erase your device (esptool erase_flash) first, then install the "V4" build from VSCode+platformio.
|
|
||||||
platform = espressif32@5.3.0
|
|
||||||
platform_packages =
|
|
||||||
build_flags = -g
|
|
||||||
-Wshadow=compatible-local ;; emit warning in case a local variable "shadows" another local one
|
|
||||||
-DARDUINO_ARCH_ESP32 -DESP32
|
|
||||||
#-DCONFIG_LITTLEFS_FOR_IDF_3_2
|
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
|
|
||||||
default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
|
https://github.com/lorol/LITTLEFS.git
|
||||||
|
makuna/NeoPixelBus @ 2.6.9
|
||||||
|
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
||||||
|
|
||||||
[esp32s2]
|
[esp32s2]
|
||||||
;; generic definitions for all ESP32-S2 boards
|
|
||||||
platform = espressif32@5.3.0
|
|
||||||
platform_packages =
|
|
||||||
build_flags = -g
|
build_flags = -g
|
||||||
-DARDUINO_ARCH_ESP32
|
-DARDUINO_ARCH_ESP32
|
||||||
-DARDUINO_ARCH_ESP32S2
|
-DARDUINO_ARCH_ESP32S2
|
||||||
-DCONFIG_IDF_TARGET_ESP32S2=1
|
-DCONFIG_IDF_TARGET_ESP32S2
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
||||||
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0
|
|
||||||
-DCO
|
-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
|
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
|
makuna/NeoPixelBus @ 2.6.9
|
||||||
|
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
||||||
|
|
||||||
[esp32c3]
|
[esp32c3]
|
||||||
;; generic definitions for all ESP32-C3 boards
|
|
||||||
platform = espressif32@5.3.0
|
|
||||||
platform_packages =
|
|
||||||
build_flags = -g
|
build_flags = -g
|
||||||
-DARDUINO_ARCH_ESP32
|
-DARDUINO_ARCH_ESP32
|
||||||
-DARDUINO_ARCH_ESP32C3
|
-DARDUINO_ARCH_ESP32C3
|
||||||
-DCONFIG_IDF_TARGET_ESP32C3=1
|
-DCONFIG_IDF_TARGET_ESP32C3
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
||||||
-DCO
|
-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 =
|
lib_deps =
|
||||||
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
|
makuna/NeoPixelBus @ 2.6.9
|
||||||
|
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
||||||
|
|
||||||
[esp32s3]
|
[esp32s3]
|
||||||
;; generic definitions for all ESP32-S3 boards
|
;; generic definitions for all ESP32-S3 boards
|
||||||
platform = espressif32@5.3.0
|
|
||||||
platform_packages =
|
|
||||||
build_flags = -g
|
build_flags = -g
|
||||||
-DESP32
|
-DESP32
|
||||||
-DARDUINO_ARCH_ESP32
|
-DARDUINO_ARCH_ESP32
|
||||||
-DARDUINO_ARCH_ESP32S3
|
-DARDUINO_ARCH_ESP32S3
|
||||||
-DCONFIG_IDF_TARGET_ESP32S3=1
|
-DCONFIG_IDF_TARGET_ESP32S3
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
||||||
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_DFU_ON_BOOT=0
|
|
||||||
-DCO
|
-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
|
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
|
||||||
${env.lib_deps}
|
${env.lib_deps}
|
||||||
|
;; NeoPixelBus 2.7.1 is the first that has official support for ESP32-S3
|
||||||
|
makuna/NeoPixelBus @ ~2.7.1
|
||||||
|
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -352,7 +296,6 @@ platform_packages = ${common.platform_packages}
|
|||||||
board_build.ldscript = ${common.ldscript_1m128k}
|
board_build.ldscript = ${common.ldscript_1m128k}
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP01 -D WLED_DISABLE_OTA
|
build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP01 -D WLED_DISABLE_OTA
|
||||||
; -D WLED_USE_UNREAL_MATH ;; may cause wrong sunset/sunrise times, but saves 7064 bytes FLASH and 975 bytes RAM
|
|
||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:esp07]
|
[env:esp07]
|
||||||
@ -398,60 +341,30 @@ board = esp32dev
|
|||||||
platform = ${esp32.platform}
|
platform = ${esp32.platform}
|
||||||
platform_packages = ${esp32.platform_packages}
|
platform_packages = ${esp32.platform_packages}
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32 #-D WLED_DISABLE_BROWNOUT_DET
|
build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32 #-D WLED_DISABLE_BLYNK #-D WLED_DISABLE_BROWNOUT_DET
|
||||||
lib_deps = ${esp32.lib_deps}
|
lib_deps = ${esp32.lib_deps}
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
board_build.partitions = ${esp32.default_partitions}
|
||||||
|
|
||||||
[env:esp32dev_audioreactive]
|
|
||||||
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_audioreactive #-D WLED_DISABLE_BROWNOUT_DET
|
|
||||||
${esp32.AR_build_flags}
|
|
||||||
lib_deps = ${esp32.lib_deps}
|
|
||||||
${esp32.AR_lib_deps}
|
|
||||||
monitor_filters = esp32_exception_decoder
|
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
|
||||||
; board_build.f_flash = 80000000L
|
|
||||||
; board_build.flash_mode = dio
|
|
||||||
|
|
||||||
[env:esp32dev_qio80]
|
[env:esp32dev_qio80]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = ${esp32.platform}
|
platform = ${esp32.platform}
|
||||||
platform_packages = ${esp32.platform_packages}
|
platform_packages = ${esp32.platform_packages}
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_qio80 #-D WLED_DISABLE_BROWNOUT_DET
|
build_flags = ${common.build_flags_esp32} -D WLED_RELEASE_NAME=ESP32_qio80 #-D WLED_DISABLE_BLYNK #-D WLED_DISABLE_BROWNOUT_DET
|
||||||
lib_deps = ${esp32.lib_deps}
|
lib_deps = ${esp32.lib_deps}
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
board_build.partitions = ${esp32.default_partitions}
|
||||||
board_build.f_flash = 80000000L
|
board_build.f_flash = 80000000L
|
||||||
board_build.flash_mode = qio
|
board_build.flash_mode = qio
|
||||||
|
|
||||||
[env:esp32dev_V4_dio80]
|
|
||||||
;; experimental ESP32 env using ESP-IDF V4.4.x
|
|
||||||
;; Warning: this build environment is not stable!!
|
|
||||||
;; please erase your device before installing.
|
|
||||||
board = esp32dev
|
|
||||||
platform = ${esp32_idf_V4.platform}
|
|
||||||
platform_packages = ${esp32_idf_V4.platform_packages}
|
|
||||||
build_unflags = ${common.build_unflags}
|
|
||||||
build_flags = ${common.build_flags} ${esp32_idf_V4.build_flags} -D WLED_RELEASE_NAME=ESP32_V4_qio80 #-D WLED_DISABLE_BROWNOUT_DET
|
|
||||||
lib_deps = ${esp32_idf_V4.lib_deps}
|
|
||||||
monitor_filters = esp32_exception_decoder
|
|
||||||
board_build.partitions = ${esp32_idf_V4.default_partitions}
|
|
||||||
board_build.f_flash = 80000000L
|
|
||||||
board_build.flash_mode = dio
|
|
||||||
|
|
||||||
[env:esp32_eth]
|
[env:esp32_eth]
|
||||||
board = esp32-poe
|
board = esp32-poe
|
||||||
platform = ${esp32.platform}
|
platform = ${esp32.platform}
|
||||||
platform_packages = ${esp32.platform_packages}
|
platform_packages = ${esp32.platform_packages}
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
build_unflags = ${common.build_unflags}
|
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
|
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
|
||||||
-D WLED_DISABLE_ESPNOW ;; ESP-NOW requires wifi, may crash with ethernet only
|
|
||||||
lib_deps = ${esp32.lib_deps}
|
lib_deps = ${esp32.lib_deps}
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
board_build.partitions = ${esp32.default_partitions}
|
||||||
|
|
||||||
@ -465,22 +378,15 @@ board_build.flash_mode = qio
|
|||||||
upload_speed = 460800
|
upload_speed = 460800
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp32s2.build_flags} #-D WLED_RELEASE_NAME=S2_saola
|
build_flags = ${common.build_flags} ${esp32s2.build_flags} #-D WLED_RELEASE_NAME=S2_saola
|
||||||
;-DLOLIN_WIFI_FIX ;; try this in case Wifi does not work
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
|
||||||
lib_deps = ${esp32s2.lib_deps}
|
lib_deps = ${esp32s2.lib_deps}
|
||||||
|
|
||||||
[env:esp32c3dev]
|
[env:esp32c3]
|
||||||
extends = esp32c3
|
platform = espressif32@5.1.1
|
||||||
platform = ${esp32c3.platform}
|
|
||||||
platform_packages = ${esp32c3.platform_packages}
|
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32-c3-devkitm-1
|
board = esp32-c3-devkitm-1
|
||||||
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
||||||
build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_RELEASE_NAME=ESP32-C3
|
build_flags = ${common.build_flags} ${esp32c3.build_flags} #-D WLED_RELEASE_NAME=ESP32-C3
|
||||||
-D WLED_WATCHDOG_TIMEOUT=0
|
-D WLED_WATCHDOG_TIMEOUT=0
|
||||||
-DLOLIN_WIFI_FIX ; seems to work much better with this
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual CDC USB
|
|
||||||
;-DARDUINO_USB_CDC_ON_BOOT=0 ;; for serial-to-USB chip
|
|
||||||
upload_speed = 460800
|
upload_speed = 460800
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
lib_deps = ${esp32c3.lib_deps}
|
lib_deps = ${esp32c3.lib_deps}
|
||||||
@ -488,14 +394,14 @@ lib_deps = ${esp32c3.lib_deps}
|
|||||||
[env:esp32s3dev_8MB]
|
[env:esp32s3dev_8MB]
|
||||||
;; ESP32-S3-DevKitC-1 development board, with 8MB FLASH, no PSRAM (flash_mode: qio)
|
;; ESP32-S3-DevKitC-1 development board, with 8MB FLASH, no PSRAM (flash_mode: qio)
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
platform = ${esp32s3.platform}
|
platform = espressif32@5.1.1
|
||||||
platform_packages = ${esp32s3.platform_packages}
|
platform_packages =
|
||||||
upload_speed = 921600 ; or 460800
|
upload_speed = 921600 ; or 460800
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp32s3.build_flags} -D WLED_RELEASE_NAME=ESP32-S3_8MB
|
build_flags = ${common.build_flags} ${esp32s3.build_flags}
|
||||||
-D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0
|
-D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0
|
||||||
-D ARDUINO_USB_CDC_ON_BOOT=0 ;; -D ARDUINO_USB_MODE=1 ;; for boards with serial-to-USB chip
|
-D ARDUINO_USB_CDC_ON_BOOT=0 -D ARDUINO_USB_MSC_ON_BOOT=0 -D ARDUINO_DFU_ON_BOOT=0 -D ARDUINO_USB_MODE=1 ;; for boards with serial-to-USB chip
|
||||||
;-D ARDUINO_USB_CDC_ON_BOOT=1 ;; -D ARDUINO_USB_MODE=1 ;; for boards with USB-OTG connector only (USBCDC or "TinyUSB")
|
;-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MSC_ON_BOOT=0 -D ARDUINO_DFU_ON_BOOT=0 ; -D ARDUINO_USB_MODE=0 ;; for boards with USB-OTG connector only (USBCDC or "TinyUSB")
|
||||||
;-D WLED_DEBUG
|
;-D WLED_DEBUG
|
||||||
lib_deps = ${esp32s3.lib_deps}
|
lib_deps = ${esp32s3.lib_deps}
|
||||||
board_build.partitions = tools/WLED_ESP32_8MB.csv
|
board_build.partitions = tools/WLED_ESP32_8MB.csv
|
||||||
@ -504,18 +410,18 @@ board_build.flash_mode = qio
|
|||||||
; board_build.flash_mode = dio ;; try this if you have problems at startup
|
; board_build.flash_mode = dio ;; try this if you have problems at startup
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
|
||||||
[env:esp32s3dev_8MB_PSRAM_opi]
|
[env:esp32s3dev_8MB_PSRAM]
|
||||||
;; ESP32-S3 development board, with 8MB FLASH and >= 8MB PSRAM (memory_type: qio_opi)
|
;; ESP32-TinyS3 development board, with 8MB FLASH and 8MB PSRAM (memory_type: qio_opi, qio_qspi, or opi_opi)
|
||||||
board = esp32-s3-devkitc-1 ;; generic dev board; the next line adds PSRAM support
|
;board = um_tinys3 ; -> needs workaround from https://github.com/Aircoookie/WLED/pull/2905#issuecomment-1328049860
|
||||||
board_build.arduino.memory_type = qio_opi ;; use with PSRAM: 8MB or 16MB
|
;board = esp32s3box ; -> error: 'esp32_adc2gpio' was not declared in this scope
|
||||||
platform = ${esp32s3.platform}
|
board = esp32-s3-devkitc-1 ; -> compiles, but does not support PSRAM
|
||||||
platform_packages = ${esp32s3.platform_packages}
|
platform = espressif32 @ ~5.2.0
|
||||||
|
platform_packages =
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp32s3.build_flags}
|
build_flags = ${common.build_flags} ${esp32s3.build_flags}
|
||||||
-D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0
|
-D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0
|
||||||
;-D ARDUINO_USB_CDC_ON_BOOT=0 ;; -D ARDUINO_USB_MODE=1 ;; for boards with serial-to-USB chip
|
-D ARDUINO_USB_MODE=1 -D ARDUINO_USB_MSC_ON_BOOT=0 ; -D ARDUINO_USB_CDC_ON_BOOT=0
|
||||||
-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 ;; for boards with USB-OTG connector only (USBCDC or "TinyUSB")
|
|
||||||
; -D WLED_RELEASE_NAME=ESP32-S3_PSRAM
|
; -D WLED_RELEASE_NAME=ESP32-S3_PSRAM
|
||||||
-D WLED_USE_PSRAM -DBOARD_HAS_PSRAM ; tells WLED that PSRAM shall be used
|
-D WLED_USE_PSRAM -DBOARD_HAS_PSRAM ; tells WLED that PSRAM shall be used
|
||||||
lib_deps = ${esp32s3.lib_deps}
|
lib_deps = ${esp32s3.lib_deps}
|
||||||
@ -524,13 +430,6 @@ board_build.f_flash = 80000000L
|
|||||||
board_build.flash_mode = qio
|
board_build.flash_mode = qio
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
|
||||||
[env:esp32s3dev_8MB_PSRAM_qspi]
|
|
||||||
;; ESP32-TinyS3 development board, with 8MB FLASH and PSRAM (memory_type: qio_qspi)
|
|
||||||
extends = env:esp32s3dev_8MB_PSRAM_opi
|
|
||||||
;board = um_tinys3 ; -> needs workaround from https://github.com/Aircoookie/WLED/pull/2905#issuecomment-1328049860
|
|
||||||
board = esp32-s3-devkitc-1 ;; generic dev board; the next line adds PSRAM support
|
|
||||||
board_build.arduino.memory_type = qio_qspi ;; use with PSRAM: 2MB or 4MB
|
|
||||||
|
|
||||||
[env:esp8285_4CH_MagicHome]
|
[env:esp8285_4CH_MagicHome]
|
||||||
board = esp8285
|
board = esp8285
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
@ -594,19 +493,14 @@ build_flags = ${common.build_flags_esp8266} -D LEDPIN=12 -D IRPIN=-1 -D RLYPIN=2
|
|||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:lolin_s2_mini]
|
[env:lolin_s2_mini]
|
||||||
platform = ${esp32s2.platform}
|
platform = espressif32@5.1.1
|
||||||
platform_packages = ${esp32s2.platform_packages}
|
|
||||||
board = lolin_s2_mini
|
board = lolin_s2_mini
|
||||||
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
|
||||||
build_unflags = ${common.build_unflags} #-DARDUINO_USB_CDC_ON_BOOT=1
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_RELEASE_NAME=ESP32-S2
|
build_flags = ${common.build_flags} ${esp32s2.build_flags} #-D WLED_RELEASE_NAME=LolinS2
|
||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1 # try disabling and enabling unflag above in case of board-specific issues, will disable Serial
|
-D ARDUINO_USB_CDC_ON_BOOT
|
||||||
-DARDUINO_USB_MSC_ON_BOOT=0
|
|
||||||
-DARDUINO_USB_DFU_ON_BOOT=0
|
|
||||||
-DLOLIN_WIFI_FIX ; seems to work much better with this
|
|
||||||
-D WLED_USE_PSRAM
|
-D WLED_USE_PSRAM
|
||||||
; -D WLED_USE_UNREAL_MATH ;; may cause wrong sunset/sunrise times, but saves 6792 bytes FLASH
|
|
||||||
-D WLED_WATCHDOG_TIMEOUT=0
|
-D WLED_WATCHDOG_TIMEOUT=0
|
||||||
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
-D CONFIG_ASYNC_TCP_USE_WDT=0
|
||||||
-D LEDPIN=16
|
-D LEDPIN=16
|
||||||
@ -625,28 +519,9 @@ lib_deps = ${esp32s2.lib_deps}
|
|||||||
# custom board configurations
|
# custom board configurations
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
[env:esp32c3dev_2MB]
|
|
||||||
;; for ESP32-C3 boards with 2MB flash (instead of 4MB).
|
|
||||||
;; this board need a specific partition file. OTA not possible.
|
|
||||||
extends = esp32c3
|
|
||||||
platform = ${esp32c3.platform}
|
|
||||||
platform_packages = ${esp32c3.platform_packages}
|
|
||||||
board = esp32-c3-devkitm-1
|
|
||||||
build_flags = ${common.build_flags} ${esp32c3.build_flags} #-D WLED_RELEASE_NAME=ESP32-C3
|
|
||||||
-D WLED_WATCHDOG_TIMEOUT=0
|
|
||||||
-D WLED_DISABLE_OTA
|
|
||||||
; -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual CDC USB
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=0 ;; for serial-to-USB chip
|
|
||||||
build_unflags = ${common.build_unflags}
|
|
||||||
upload_speed = 115200
|
|
||||||
lib_deps = ${esp32c3.lib_deps}
|
|
||||||
board_build.partitions = tools/WLED_ESP32_2MB_noOTA.csv
|
|
||||||
board_build.flash_mode = dio
|
|
||||||
|
|
||||||
[env:wemos_shield_esp32]
|
[env:wemos_shield_esp32]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = ${esp32.platform}
|
platform = espressif32@3.2
|
||||||
platform_packages = ${esp32.platform_packages}
|
|
||||||
upload_speed = 460800
|
upload_speed = 460800
|
||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags_esp32}
|
build_flags = ${common.build_flags_esp32}
|
||||||
@ -671,8 +546,7 @@ board = esp32dev
|
|||||||
build_unflags = ${common.build_unflags}
|
build_unflags = ${common.build_unflags}
|
||||||
build_flags = ${common.build_flags_esp32} -D LEDPIN=27 -D BTNPIN=39
|
build_flags = ${common.build_flags_esp32} -D LEDPIN=27 -D BTNPIN=39
|
||||||
lib_deps = ${esp32.lib_deps}
|
lib_deps = ${esp32.lib_deps}
|
||||||
platform = ${esp32.platform}
|
platform = espressif32@3.2
|
||||||
platform_packages = ${esp32.platform_packages}
|
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
board_build.partitions = ${esp32.default_partitions}
|
||||||
|
|
||||||
[env:sp501e]
|
[env:sp501e]
|
||||||
@ -689,58 +563,20 @@ 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
|
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}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:Athom_RGBCW] ;7w and 5w(GU10) bulbs
|
[env:athom7w]
|
||||||
board = esp8285
|
board = esp_wroom_02
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
platform_packages = ${common.platform_packages}
|
|
||||||
board_build.ldscript = ${common.ldscript_2m512k}
|
board_build.ldscript = ${common.ldscript_2m512k}
|
||||||
build_unflags = ${common.build_unflags}
|
build_flags = ${common.build_flags_esp8266} -D WLED_MAX_CCT_BLEND=0 -D BTNPIN=-1 -D IRPIN=-1 -D WLED_DISABLE_INFRARED
|
||||||
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}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
|
[env:athom15w]
|
||||||
[env:Athom_15w_RGBCW] ;15w bulb
|
board = esp_wroom_02
|
||||||
board = esp8285
|
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
platform_packages = ${common.platform_packages}
|
|
||||||
board_build.ldscript = ${common.ldscript_2m512k}
|
board_build.ldscript = ${common.ldscript_2m512k}
|
||||||
build_unflags = ${common.build_unflags}
|
build_flags = ${common.build_flags_esp8266} -D WLED_USE_IC_CCT -D BTNPIN=-1 -D IRPIN=-1 -D WLED_DISABLE_INFRARED
|
||||||
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}
|
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]
|
[env:MY9291]
|
||||||
board = esp01_1m
|
board = esp01_1m
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
@ -752,10 +588,10 @@ lib_deps = ${esp8266.lib_deps}
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# codm pixel controller board configurations
|
# codm pixel controller board configurations
|
||||||
# codm-controller-0_6 can also be used for the TYWE3S controller
|
# codm-controller-0.6 can also be used for the TYWE3S controller
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
[env:codm-controller-0_6]
|
[env:codm-controller-0.6]
|
||||||
board = esp_wroom_02
|
board = esp_wroom_02
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
platform_packages = ${common.platform_packages}
|
platform_packages = ${common.platform_packages}
|
||||||
@ -764,7 +600,7 @@ build_unflags = ${common.build_unflags}
|
|||||||
build_flags = ${common.build_flags_esp8266}
|
build_flags = ${common.build_flags_esp8266}
|
||||||
lib_deps = ${esp8266.lib_deps}
|
lib_deps = ${esp8266.lib_deps}
|
||||||
|
|
||||||
[env:codm-controller-0_6-rev2]
|
[env:codm-controller-0.6-rev2]
|
||||||
board = esp_wroom_02
|
board = esp_wroom_02
|
||||||
platform = ${common.platform_wled_default}
|
platform = ${common.platform_wled_default}
|
||||||
platform_packages = ${common.platform_packages}
|
platform_packages = ${common.platform_packages}
|
||||||
@ -778,8 +614,7 @@ lib_deps = ${esp8266.lib_deps}
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
[env:elekstube_ips]
|
[env:elekstube_ips]
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = ${esp32.platform}
|
platform = espressif32@3.2
|
||||||
platform_packages = ${esp32.platform_packages}
|
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
build_flags = ${common.build_flags_esp32} -D WLED_DISABLE_BROWNOUT_DET -D WLED_DISABLE_INFRARED
|
build_flags = ${common.build_flags_esp32} -D WLED_DISABLE_BROWNOUT_DET -D WLED_DISABLE_INFRARED
|
||||||
-D USERMOD_RTC
|
-D USERMOD_RTC
|
||||||
@ -787,6 +622,7 @@ build_flags = ${common.build_flags_esp32} -D WLED_DISABLE_BROWNOUT_DET -D WLED_D
|
|||||||
-D LEDPIN=12
|
-D LEDPIN=12
|
||||||
-D RLYPIN=27
|
-D RLYPIN=27
|
||||||
-D BTNPIN=34
|
-D BTNPIN=34
|
||||||
|
-D WLED_DISABLE_BLYNK
|
||||||
-D DEFAULT_LED_COUNT=6
|
-D DEFAULT_LED_COUNT=6
|
||||||
# Display config
|
# Display config
|
||||||
-D ST7789_DRIVER
|
-D ST7789_DRIVER
|
||||||
|
@ -26,6 +26,7 @@ build_flags = ${common.build_flags_esp8266}
|
|||||||
; disable specific features
|
; disable specific features
|
||||||
; -D WLED_DISABLE_OTA
|
; -D WLED_DISABLE_OTA
|
||||||
; -D WLED_DISABLE_ALEXA
|
; -D WLED_DISABLE_ALEXA
|
||||||
|
; -D WLED_DISABLE_BLYNK
|
||||||
; -D WLED_DISABLE_HUESYNC
|
; -D WLED_DISABLE_HUESYNC
|
||||||
; -D WLED_DISABLE_INFRARED
|
; -D WLED_DISABLE_INFRARED
|
||||||
; -D WLED_DISABLE_WEBSOCKETS
|
; -D WLED_DISABLE_WEBSOCKETS
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<a href="https://github.com/Aircoookie/WLED/releases"><img src="https://img.shields.io/github/release/Aircoookie/WLED.svg?style=flat-square"></a>
|
<a href="https://github.com/Aircoookie/WLED/releases"><img src="https://img.shields.io/github/release/Aircoookie/WLED.svg?style=flat-square"></a>
|
||||||
<a href="https://raw.githubusercontent.com/Aircoookie/WLED/master/LICENSE"><img src="https://img.shields.io/github/license/Aircoookie/wled?color=blue&style=flat-square"></a>
|
<a href="https://raw.githubusercontent.com/Aircoookie/WLED/master/LICENSE"><img src="https://img.shields.io/github/license/Aircoookie/wled?color=blue&style=flat-square"></a>
|
||||||
<a href="https://wled.discourse.group"><img src="https://img.shields.io/discourse/topics?colorB=blue&label=forum&server=https%3A%2F%2Fwled.discourse.group%2F&style=flat-square"></a>
|
<a href="https://wled.discourse.group"><img src="https://img.shields.io/discourse/topics?colorB=blue&label=forum&server=https%3A%2F%2Fwled.discourse.group%2F&style=flat-square"></a>
|
||||||
<a href="https://discord.gg/QAh7wJHrRM"><img src="https://img.shields.io/discord/473448917040758787.svg?colorB=blue&label=discord&style=flat-square"></a>
|
<a href="https://discord.gg/KuqP7NE"><img src="https://img.shields.io/discord/473448917040758787.svg?colorB=blue&label=discord&style=flat-square"></a>
|
||||||
<a href="https://kno.wled.ge"><img src="https://img.shields.io/badge/quick_start-wiki-blue.svg?style=flat-square"></a>
|
<a href="https://kno.wled.ge"><img src="https://img.shields.io/badge/quick_start-wiki-blue.svg?style=flat-square"></a>
|
||||||
<a href="https://github.com/Aircoookie/WLED-App"><img src="https://img.shields.io/badge/app-wled-blue.svg?style=flat-square"></a>
|
<a href="https://github.com/Aircoookie/WLED-App"><img src="https://img.shields.io/badge/app-wled-blue.svg?style=flat-square"></a>
|
||||||
<a href="https://gitpod.io/#https://github.com/Aircoookie/WLED"><img src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?style=flat-square&logo=gitpod"></a>
|
<a href="https://gitpod.io/#https://github.com/Aircoookie/WLED"><img src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?style=flat-square&logo=gitpod"></a>
|
||||||
@ -35,6 +35,7 @@ A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control
|
|||||||
- 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)
|
- 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
|
- JSON and HTTP request APIs
|
||||||
- MQTT
|
- MQTT
|
||||||
|
- Blynk IoT
|
||||||
- E1.31, Art-Net, DDP and TPM2.net
|
- 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))
|
- [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)
|
- [Hyperion](https://github.com/hyperion-project/hyperion.ng)
|
||||||
@ -53,7 +54,7 @@ See the [documentation on our official site](https://kno.wled.ge)!
|
|||||||
[On this page](https://kno.wled.ge/basics/tutorials/) you can find excellent tutorials and tools to help you get your new project up and running!
|
[On this page](https://kno.wled.ge/basics/tutorials/) you can find excellent tutorials and tools to help you get your new project up and running!
|
||||||
|
|
||||||
## 🖼️ User interface
|
## 🖼️ User interface
|
||||||
<img src="images/macbook-pro-space-gray-on-the-wooden-table.jpg" width="50%"><img src="images/walking-with-iphone-x.jpg" width="50%">
|
<img src="/images/macbook-pro-space-gray-on-the-wooden-table.jpg" width="50%"><img src="/images/walking-with-iphone-x.jpg" width="50%">
|
||||||
|
|
||||||
## 💾 Compatible hardware
|
## 💾 Compatible hardware
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ Credits [here](https://kno.wled.ge/about/contributors/)!
|
|||||||
|
|
||||||
Join the Discord server to discuss everything about WLED!
|
Join the Discord server to discuss everything about WLED!
|
||||||
|
|
||||||
<a href="https://discord.gg/QAh7wJHrRM"><img src="https://discordapp.com/api/guilds/473448917040758787/widget.png?style=banner2" width="25%"></a>
|
<a href="https://discord.gg/KuqP7NE"><img src="https://discordapp.com/api/guilds/473448917040758787/widget.png?style=banner2" width="25%"></a>
|
||||||
|
|
||||||
Check out the WLED [Discourse forum](https://wled.discourse.group)!
|
Check out the WLED [Discourse forum](https://wled.discourse.group)!
|
||||||
|
|
||||||
|
@ -4,55 +4,63 @@
|
|||||||
#
|
#
|
||||||
# pip-compile
|
# pip-compile
|
||||||
#
|
#
|
||||||
aiofiles==22.1.0
|
aiofiles==0.8.0
|
||||||
# via platformio
|
# via platformio
|
||||||
ajsonrpc==1.2.0
|
ajsonrpc==1.2.0
|
||||||
# via platformio
|
# via platformio
|
||||||
anyio==3.6.2
|
anyio==3.6.1
|
||||||
# via starlette
|
# via starlette
|
||||||
bottle==0.12.25
|
async-timeout==4.0.2
|
||||||
|
# via zeroconf
|
||||||
|
bottle==0.12.23
|
||||||
# via platformio
|
# via platformio
|
||||||
certifi==2023.7.22
|
certifi==2022.12.7
|
||||||
# via requests
|
# via requests
|
||||||
charset-normalizer==3.1.0
|
charset-normalizer==2.1.1
|
||||||
# via requests
|
# via requests
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
# via
|
# via
|
||||||
# platformio
|
# platformio
|
||||||
# uvicorn
|
# uvicorn
|
||||||
colorama==0.4.6
|
colorama==0.4.5
|
||||||
# via platformio
|
# via platformio
|
||||||
h11==0.14.0
|
h11==0.13.0
|
||||||
# via
|
# via
|
||||||
# uvicorn
|
# uvicorn
|
||||||
# wsproto
|
# wsproto
|
||||||
idna==3.4
|
idna==3.3
|
||||||
# via
|
# via
|
||||||
# anyio
|
# anyio
|
||||||
# requests
|
# requests
|
||||||
marshmallow==3.19.0
|
ifaddr==0.2.0
|
||||||
|
# via zeroconf
|
||||||
|
marshmallow==3.17.0
|
||||||
# via platformio
|
# via platformio
|
||||||
packaging==23.1
|
packaging==21.3
|
||||||
# via marshmallow
|
# via marshmallow
|
||||||
platformio==6.1.6
|
platformio==6.1.4
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
pyelftools==0.29
|
pyelftools==0.29
|
||||||
# via platformio
|
# via platformio
|
||||||
|
pyparsing==3.0.9
|
||||||
|
# via packaging
|
||||||
pyserial==3.5
|
pyserial==3.5
|
||||||
# via platformio
|
# via platformio
|
||||||
requests==2.31.0
|
requests==2.28.1
|
||||||
# via platformio
|
# via platformio
|
||||||
semantic-version==2.10.0
|
semantic-version==2.10.0
|
||||||
# via platformio
|
# via platformio
|
||||||
sniffio==1.3.0
|
sniffio==1.2.0
|
||||||
# via anyio
|
# via anyio
|
||||||
starlette==0.23.1
|
starlette==0.20.4
|
||||||
# via platformio
|
# via platformio
|
||||||
tabulate==0.9.0
|
tabulate==0.8.10
|
||||||
# via platformio
|
# via platformio
|
||||||
urllib3==1.26.15
|
urllib3==1.26.11
|
||||||
# via requests
|
# via requests
|
||||||
uvicorn==0.20.0
|
uvicorn==0.18.2
|
||||||
# via platformio
|
# via platformio
|
||||||
wsproto==1.2.0
|
wsproto==1.1.0
|
||||||
|
# via platformio
|
||||||
|
zeroconf==0.39.0
|
||||||
# via platformio
|
# via platformio
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
# 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,,64K
|
|
||||||
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
|
|
|
@ -1,5 +0,0 @@
|
|||||||
# 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,
|
|
|
@ -3,5 +3,4 @@ nvs, data, nvs, 0x9000, 0x5000,
|
|||||||
otadata, data, ota, 0xe000, 0x2000,
|
otadata, data, ota, 0xe000, 0x2000,
|
||||||
app0, app, ota_0, 0x10000, 0x200000,
|
app0, app, ota_0, 0x10000, 0x200000,
|
||||||
app1, app, ota_1, 0x210000,0x200000,
|
app1, app, ota_1, 0x210000,0x200000,
|
||||||
spiffs, data, spiffs, 0x410000,0x3E0000,
|
spiffs, data, spiffs, 0x410000,0x3F0000,
|
||||||
coredump, data, coredump,,64K
|
|
|
@ -220,9 +220,6 @@ function writeChunks(srcDir, specs, resultFile) {
|
|||||||
|
|
||||||
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
|
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
|
||||||
writeHtmlGzipped("wled00/data/simple.htm", "wled00/html_simple.h", 'simple');
|
writeHtmlGzipped("wled00/data/simple.htm", "wled00/html_simple.h", 'simple');
|
||||||
writeHtmlGzipped("wled00/data/pixart/pixart.htm", "wled00/html_pixart.h", 'pixart');
|
|
||||||
writeHtmlGzipped("wled00/data/cpal/cpal.htm", "wled00/html_cpal.h", 'cpal');
|
|
||||||
writeHtmlGzipped("wled00/data/pxmagic/pxmagic.htm", "wled00/html_pxmagic.h", 'pxmagic');
|
|
||||||
/*
|
/*
|
||||||
writeChunks(
|
writeChunks(
|
||||||
"wled00/data",
|
"wled00/data",
|
||||||
@ -390,6 +387,12 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
|
|||||||
method: "gzip",
|
method: "gzip",
|
||||||
filter: "html-minify",
|
filter: "html-minify",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
file: "liveviewws.htm",
|
||||||
|
name: "PAGE_liveviewws",
|
||||||
|
method: "gzip",
|
||||||
|
filter: "html-minify",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
file: "liveviewws2D.htm",
|
file: "liveviewws2D.htm",
|
||||||
name: "PAGE_liveviewws2D",
|
name: "PAGE_liveviewws2D",
|
||||||
|
@ -203,45 +203,45 @@ public:
|
|||||||
void addToConfig(JsonObject& root) override {
|
void addToConfig(JsonObject& root) override {
|
||||||
validateAndUpdate();
|
validateAndUpdate();
|
||||||
|
|
||||||
JsonObject top = root.createNestedObject(F("Analog Clock"));
|
JsonObject top = root.createNestedObject("Analog Clock");
|
||||||
top[F("Overlay Enabled")] = enabled;
|
top["Overlay Enabled"] = enabled;
|
||||||
top[F("First LED (Main Ring)")] = mainSegment.firstLed;
|
top["First LED (Main Ring)"] = mainSegment.firstLed;
|
||||||
top[F("Last LED (Main Ring)")] = mainSegment.lastLed;
|
top["Last LED (Main Ring)"] = mainSegment.lastLed;
|
||||||
top[F("Center/12h LED (Main Ring)")] = mainSegment.centerLed;
|
top["Center/12h LED (Main Ring)"] = mainSegment.centerLed;
|
||||||
top[F("Hour Marks Enabled")] = hourMarksEnabled;
|
top["Hour Marks Enabled"] = hourMarksEnabled;
|
||||||
top[F("Hour Mark Color (RRGGBB)")] = colorToHexString(hourMarkColor);
|
top["Hour Mark Color (RRGGBB)"] = colorToHexString(hourMarkColor);
|
||||||
top[F("Hour Color (RRGGBB)")] = colorToHexString(hourColor);
|
top["Hour Color (RRGGBB)"] = colorToHexString(hourColor);
|
||||||
top[F("Minute Color (RRGGBB)")] = colorToHexString(minuteColor);
|
top["Minute Color (RRGGBB)"] = colorToHexString(minuteColor);
|
||||||
top[F("Show Seconds")] = secondsEnabled;
|
top["Show Seconds"] = secondsEnabled;
|
||||||
top[F("First LED (Seconds Ring)")] = secondsSegment.firstLed;
|
top["First LED (Seconds Ring)"] = secondsSegment.firstLed;
|
||||||
top[F("Last LED (Seconds Ring)")] = secondsSegment.lastLed;
|
top["Last LED (Seconds Ring)"] = secondsSegment.lastLed;
|
||||||
top[F("Center/12h LED (Seconds Ring)")] = secondsSegment.centerLed;
|
top["Center/12h LED (Seconds Ring)"] = secondsSegment.centerLed;
|
||||||
top[F("Second Color (RRGGBB)")] = colorToHexString(secondColor);
|
top["Second Color (RRGGBB)"] = colorToHexString(secondColor);
|
||||||
top[F("Seconds Effect (0-1)")] = secondsEffect;
|
top["Seconds Effect (0-1)"] = secondsEffect;
|
||||||
top[F("Blend Colors")] = blendColors;
|
top["Blend Colors"] = blendColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readFromConfig(JsonObject& root) override {
|
bool readFromConfig(JsonObject& root) override {
|
||||||
JsonObject top = root[F("Analog Clock")];
|
JsonObject top = root["Analog Clock"];
|
||||||
|
|
||||||
bool configComplete = !top.isNull();
|
bool configComplete = !top.isNull();
|
||||||
|
|
||||||
String color;
|
String color;
|
||||||
configComplete &= getJsonValue(top[F("Overlay Enabled")], enabled, false);
|
configComplete &= getJsonValue(top["Overlay Enabled"], enabled, false);
|
||||||
configComplete &= getJsonValue(top[F("First LED (Main Ring)")], mainSegment.firstLed, 0);
|
configComplete &= getJsonValue(top["First LED (Main Ring)"], mainSegment.firstLed, 0);
|
||||||
configComplete &= getJsonValue(top[F("Last LED (Main Ring)")], mainSegment.lastLed, 59);
|
configComplete &= getJsonValue(top["Last LED (Main Ring)"], mainSegment.lastLed, 59);
|
||||||
configComplete &= getJsonValue(top[F("Center/12h LED (Main Ring)")], mainSegment.centerLed, 0);
|
configComplete &= getJsonValue(top["Center/12h LED (Main Ring)"], mainSegment.centerLed, 0);
|
||||||
configComplete &= getJsonValue(top[F("Hour Marks Enabled")], hourMarksEnabled, false);
|
configComplete &= getJsonValue(top["Hour marks Enabled"], hourMarksEnabled, false);
|
||||||
configComplete &= getJsonValue(top[F("Hour Mark Color (RRGGBB)")], color, F("161616")) && hexStringToColor(color, hourMarkColor, 0x161616);
|
configComplete &= getJsonValue(top["Hour mark Color (RRGGBB)"], color, "FF0000") && hexStringToColor(color, hourMarkColor, 0x0000FF);
|
||||||
configComplete &= getJsonValue(top[F("Hour Color (RRGGBB)")], color, F("0000FF")) && hexStringToColor(color, hourColor, 0x0000FF);
|
configComplete &= getJsonValue(top["Hour Color (RRGGBB)"], color, "0000FF") && hexStringToColor(color, hourColor, 0x0000FF);
|
||||||
configComplete &= getJsonValue(top[F("Minute Color (RRGGBB)")], color, F("00FF00")) && hexStringToColor(color, minuteColor, 0x00FF00);
|
configComplete &= getJsonValue(top["Minute Color (RRGGBB)"], color, "00FF00") && hexStringToColor(color, minuteColor, 0x00FF00);
|
||||||
configComplete &= getJsonValue(top[F("Show Seconds")], secondsEnabled, true);
|
configComplete &= getJsonValue(top["Show Seconds"], secondsEnabled, true);
|
||||||
configComplete &= getJsonValue(top[F("First LED (Seconds Ring)")], secondsSegment.firstLed, 0);
|
configComplete &= getJsonValue(top["First LED (Seconds Ring)"], secondsSegment.firstLed, 0);
|
||||||
configComplete &= getJsonValue(top[F("Last LED (Seconds Ring)")], secondsSegment.lastLed, 59);
|
configComplete &= getJsonValue(top["Last LED (Seconds Ring)"], secondsSegment.lastLed, 59);
|
||||||
configComplete &= getJsonValue(top[F("Center/12h LED (Seconds Ring)")], secondsSegment.centerLed, 0);
|
configComplete &= getJsonValue(top["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["Second Color (RRGGBB)"], color, "FF0000") && hexStringToColor(color, secondColor, 0xFF0000);
|
||||||
configComplete &= getJsonValue(top[F("Seconds Effect (0-1)")], secondsEffect, 0);
|
configComplete &= getJsonValue(top["Seconds Effect (0-1)"], secondsEffect, 0);
|
||||||
configComplete &= getJsonValue(top[F("Blend Colors")], blendColors, true);
|
configComplete &= getJsonValue(top["Blend Colors"], blendColors, true);
|
||||||
|
|
||||||
if (initDone) {
|
if (initDone) {
|
||||||
validateAndUpdate();
|
validateAndUpdate();
|
||||||
|
@ -25,7 +25,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
bool useUSSensorBottom = false; // using PIR or UltraSound sensor?
|
bool useUSSensorBottom = false; // using PIR or UltraSound sensor?
|
||||||
unsigned int topMaxDist = 50; // default maximum measured distance in cm, top
|
unsigned int topMaxDist = 50; // default maximum measured distance in cm, top
|
||||||
unsigned int bottomMaxDist = 50; // default maximum measured distance in cm, bottom
|
unsigned int bottomMaxDist = 50; // default maximum measured distance in cm, bottom
|
||||||
bool togglePower = false; // toggle power on/off with staircase on/off
|
|
||||||
|
|
||||||
/* runtime variables */
|
/* runtime variables */
|
||||||
bool initDone = false;
|
bool initDone = false;
|
||||||
@ -91,17 +90,14 @@ class Animated_Staircase : public Usermod {
|
|||||||
static const char _bottomEcho_pin[];
|
static const char _bottomEcho_pin[];
|
||||||
static const char _topEchoCm[];
|
static const char _topEchoCm[];
|
||||||
static const char _bottomEchoCm[];
|
static const char _bottomEchoCm[];
|
||||||
static const char _togglePower[];
|
|
||||||
|
|
||||||
void publishMqtt(bool bottom, const char* state) {
|
void publishMqtt(bool bottom, const char* state) {
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (WLED_MQTT_CONNECTED){
|
if (WLED_MQTT_CONNECTED){
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom);
|
sprintf_P(subuf, PSTR("%s/motion/%d"), mqttDeviceTopic, (int)bottom);
|
||||||
mqtt->publish(subuf, 0, false, state);
|
mqtt->publish(subuf, 0, false, state);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateSegments() {
|
void updateSegments() {
|
||||||
@ -198,7 +194,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
if (on) {
|
if (on) {
|
||||||
lastSensor = topSensorRead;
|
lastSensor = topSensorRead;
|
||||||
} else {
|
} else {
|
||||||
if (togglePower && onIndex == offIndex && offMode) toggleOnOff(); // toggle power on if off
|
|
||||||
// If the bottom sensor triggered, we need to swipe up, ON
|
// If the bottom sensor triggered, we need to swipe up, ON
|
||||||
swipe = bottomSensorRead;
|
swipe = bottomSensorRead;
|
||||||
|
|
||||||
@ -252,10 +247,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
offIndex = MAX(onIndex, offIndex - 1);
|
offIndex = MAX(onIndex, offIndex - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (oldOn != onIndex || oldOff != offIndex) {
|
if (oldOn != onIndex || oldOff != offIndex) updateSegments(); // reduce the number of updates to necessary ones
|
||||||
updateSegments(); // reduce the number of updates to necessary ones
|
|
||||||
if (togglePower && onIndex == offIndex && !offMode && !on) toggleOnOff(); // toggle power off for all segments off
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +293,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
strip.setTransition(segment_delay_ms/100);
|
strip.setTransition(segment_delay_ms/100);
|
||||||
strip.trigger();
|
strip.trigger();
|
||||||
} else {
|
} else {
|
||||||
if (togglePower && !on && offMode) toggleOnOff(); // toggle power on if off
|
|
||||||
// Restore segment options
|
// Restore segment options
|
||||||
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
|
for (int i = 0; i <= strip.getLastActiveSegmentId(); i++) {
|
||||||
Segment &seg = strip.getSegment(i);
|
Segment &seg = strip.getSegment(i);
|
||||||
@ -354,7 +345,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
|
|
||||||
uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }
|
uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
/**
|
/**
|
||||||
* handling of MQTT message
|
* handling of MQTT message
|
||||||
* topic only contains stripped topic (part after /wled/MAC)
|
* topic only contains stripped topic (part after /wled/MAC)
|
||||||
@ -392,7 +382,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
mqtt->subscribe(subuf, 0);
|
mqtt->subscribe(subuf, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void addToJsonState(JsonObject& root) {
|
void addToJsonState(JsonObject& root) {
|
||||||
JsonObject staircase = root[FPSTR(_name)];
|
JsonObject staircase = root[FPSTR(_name)];
|
||||||
@ -451,7 +440,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1;
|
staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1;
|
||||||
staircase[FPSTR(_topEchoCm)] = topMaxDist;
|
staircase[FPSTR(_topEchoCm)] = topMaxDist;
|
||||||
staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist;
|
staircase[FPSTR(_bottomEchoCm)] = bottomMaxDist;
|
||||||
staircase[FPSTR(_togglePower)] = togglePower;
|
|
||||||
DEBUG_PRINTLN(F("Staircase config saved."));
|
DEBUG_PRINTLN(F("Staircase config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,8 +484,6 @@ class Animated_Staircase : public Usermod {
|
|||||||
bottomMaxDist = top[FPSTR(_bottomEchoCm)] | bottomMaxDist;
|
bottomMaxDist = top[FPSTR(_bottomEchoCm)] | bottomMaxDist;
|
||||||
bottomMaxDist = min(150,max(30,(int)bottomMaxDist)); // max distance ~1.5m (a lag of 9ms may be expected)
|
bottomMaxDist = min(150,max(30,(int)bottomMaxDist)); // max distance ~1.5m (a lag of 9ms may be expected)
|
||||||
|
|
||||||
togglePower = top[FPSTR(_togglePower)] | togglePower; // staircase toggles power on/off
|
|
||||||
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
// first run: reading from cfg.json
|
// first run: reading from cfg.json
|
||||||
@ -521,7 +507,7 @@ class Animated_Staircase : public Usermod {
|
|||||||
if (changed) setup();
|
if (changed) setup();
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return !top[FPSTR(_togglePower)].isNull();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -561,4 +547,3 @@ const char Animated_Staircase::_bottomPIRorTrigger_pin[] PROGMEM = "bottomPIR
|
|||||||
const char Animated_Staircase::_bottomEcho_pin[] PROGMEM = "bottomEcho_pin";
|
const char Animated_Staircase::_bottomEcho_pin[] PROGMEM = "bottomEcho_pin";
|
||||||
const char Animated_Staircase::_topEchoCm[] PROGMEM = "top-dist-cm";
|
const char Animated_Staircase::_topEchoCm[] PROGMEM = "top-dist-cm";
|
||||||
const char Animated_Staircase::_bottomEchoCm[] PROGMEM = "bottom-dist-cm";
|
const char Animated_Staircase::_bottomEchoCm[] PROGMEM = "bottom-dist-cm";
|
||||||
const char Animated_Staircase::_togglePower[] PROGMEM = "toggle-on-off";
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
// force the compiler to show a warning to confirm that this file is included
|
// force the compiler to show a warning to confirm that this file is included
|
||||||
#warning **** Included USERMOD_BH1750 ****
|
#warning **** Included USERMOD_BH1750 ****
|
||||||
|
|
||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
#include <Wire.h>
|
||||||
#include <BH1750.h>
|
#include <BH1750.h>
|
||||||
|
|
||||||
// the max frequency to check photoresistor, 10 seconds
|
// the max frequency to check photoresistor, 10 seconds
|
||||||
@ -55,6 +52,15 @@ private:
|
|||||||
static const char _offset[];
|
static const char _offset[];
|
||||||
static const char _HomeAssistantDiscovery[];
|
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()
|
||||||
bool initDone = false;
|
bool initDone = false;
|
||||||
bool sensorFound = false;
|
bool sensorFound = false;
|
||||||
|
|
||||||
@ -113,7 +119,14 @@ private:
|
|||||||
public:
|
public:
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
if (i2c_scl<0 || i2c_sda<0) { enabled = false; return; }
|
bool HW_Pins_Used = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_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 (!pinManager.allocateMultiplePins(pins, 2, po)) return;
|
||||||
|
|
||||||
|
Wire.begin(ioPin[1], ioPin[0]);
|
||||||
|
|
||||||
sensorFound = lightMeter.begin();
|
sensorFound = lightMeter.begin();
|
||||||
initDone = true;
|
initDone = true;
|
||||||
}
|
}
|
||||||
@ -143,7 +156,6 @@ public:
|
|||||||
{
|
{
|
||||||
lastLux = lux;
|
lastLux = lux;
|
||||||
lastSend = millis();
|
lastSend = millis();
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
if (WLED_MQTT_CONNECTED)
|
if (WLED_MQTT_CONNECTED)
|
||||||
{
|
{
|
||||||
if (!mqttInitialized)
|
if (!mqttInitialized)
|
||||||
@ -158,7 +170,6 @@ public:
|
|||||||
{
|
{
|
||||||
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +184,7 @@ public:
|
|||||||
user = root.createNestedObject(F("u"));
|
user = root.createNestedObject(F("u"));
|
||||||
|
|
||||||
JsonArray lux_json = user.createNestedArray(F("Luminance"));
|
JsonArray lux_json = user.createNestedArray(F("Luminance"));
|
||||||
if (!enabled) {
|
if (!sensorFound) {
|
||||||
lux_json.add(F("disabled"));
|
|
||||||
} else if (!sensorFound) {
|
|
||||||
// if no sensor
|
// if no sensor
|
||||||
lux_json.add(F("BH1750 "));
|
lux_json.add(F("BH1750 "));
|
||||||
lux_json.add(F("Not Found"));
|
lux_json.add(F("Not Found"));
|
||||||
@ -201,6 +210,9 @@ public:
|
|||||||
top[FPSTR(_minReadInterval)] = minReadingInterval;
|
top[FPSTR(_minReadInterval)] = minReadingInterval;
|
||||||
top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery;
|
top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery;
|
||||||
top[FPSTR(_offset)] = offset;
|
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
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("BH1750 config saved."));
|
DEBUG_PRINTLN(F("BH1750 config saved."));
|
||||||
}
|
}
|
||||||
@ -208,6 +220,8 @@ public:
|
|||||||
// called before setup() to populate properties from values stored in cfg.json
|
// called before setup() to populate properties from values stored in cfg.json
|
||||||
bool readFromConfig(JsonObject &root)
|
bool readFromConfig(JsonObject &root)
|
||||||
{
|
{
|
||||||
|
int8_t newPin[2]; for (byte i=0; i<2; i++) newPin[i] = ioPin[i]; // prepare to note changed pins
|
||||||
|
|
||||||
// we look for JSON object.
|
// we look for JSON object.
|
||||||
JsonObject top = root[FPSTR(_name)];
|
JsonObject top = root[FPSTR(_name)];
|
||||||
if (top.isNull())
|
if (top.isNull())
|
||||||
@ -224,12 +238,27 @@ public:
|
|||||||
configComplete &= getJsonValue(top[FPSTR(_minReadInterval)], minReadingInterval, 500); //ms
|
configComplete &= getJsonValue(top[FPSTR(_minReadInterval)], minReadingInterval, 500); //ms
|
||||||
configComplete &= getJsonValue(top[FPSTR(_HomeAssistantDiscovery)], HomeAssistantDiscovery, false);
|
configComplete &= getJsonValue(top[FPSTR(_HomeAssistantDiscovery)], HomeAssistantDiscovery, false);
|
||||||
configComplete &= getJsonValue(top[FPSTR(_offset)], offset, 1);
|
configComplete &= getJsonValue(top[FPSTR(_offset)], offset, 1);
|
||||||
|
for (byte i=0; i<2; i++) configComplete &= getJsonValue(top[F("pin")][i], newPin[i], ioPin[i]);
|
||||||
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
|
// first run: reading from cfg.json
|
||||||
|
for (byte i=0; i<2; i++) ioPin[i] = newPin[i];
|
||||||
DEBUG_PRINTLN(F(" config loaded."));
|
DEBUG_PRINTLN(F(" config loaded."));
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
|
// changing parameters from settings page
|
||||||
|
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
|
||||||
|
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po); // deallocate pins
|
||||||
|
for (byte i=0; i<2; i++) ioPin[i] = newPin[i];
|
||||||
|
setup();
|
||||||
|
}
|
||||||
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
|
return !top[F("pin")].isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
return configComplete;
|
return configComplete;
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
// force the compiler to show a warning to confirm that this file is included
|
// force the compiler to show a warning to confirm that this file is included
|
||||||
#warning **** Included USERMOD_BME280 version 2.0 ****
|
#warning **** Included USERMOD_BME280 version 2.0 ****
|
||||||
|
|
||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
#include <BME280I2C.h> // BME280 sensor
|
#include <BME280I2C.h> // BME280 sensor
|
||||||
#include <EnvironmentCalculations.h> // BME280 extended measurements
|
#include <EnvironmentCalculations.h> // BME280 extended measurements
|
||||||
|
|
||||||
@ -33,6 +30,7 @@ private:
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
//uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
|
//uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
|
||||||
#endif
|
#endif
|
||||||
|
int8_t ioPin[2] = {i2c_scl, i2c_sda}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup()
|
||||||
bool initDone = false;
|
bool initDone = false;
|
||||||
|
|
||||||
// BME280 sensor settings
|
// BME280 sensor settings
|
||||||
@ -184,7 +182,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
if (i2c_scl<0 || i2c_sda<0) { enabled = false; sensorType = 0; return; }
|
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
|
||||||
|
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 (!bme.begin())
|
if (!bme.begin())
|
||||||
{
|
{
|
||||||
@ -407,6 +411,9 @@ public:
|
|||||||
top[F("PublishAlways")] = PublishAlways;
|
top[F("PublishAlways")] = PublishAlways;
|
||||||
top[F("UseCelsius")] = UseCelsius;
|
top[F("UseCelsius")] = UseCelsius;
|
||||||
top[F("HomeAssistantDiscovery")] = HomeAssistantDiscovery;
|
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
|
||||||
DEBUG_PRINTLN(F("BME280 config saved."));
|
DEBUG_PRINTLN(F("BME280 config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,6 +423,8 @@ public:
|
|||||||
// default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor
|
// 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)
|
// 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[FPSTR(_name)];
|
JsonObject top = root[FPSTR(_name)];
|
||||||
if (top.isNull()) {
|
if (top.isNull()) {
|
||||||
DEBUG_PRINT(F(_name));
|
DEBUG_PRINT(F(_name));
|
||||||
@ -434,14 +443,27 @@ public:
|
|||||||
configComplete &= getJsonValue(top[F("PublishAlways")], PublishAlways, false);
|
configComplete &= getJsonValue(top[F("PublishAlways")], PublishAlways, false);
|
||||||
configComplete &= getJsonValue(top[F("UseCelsius")], UseCelsius, true);
|
configComplete &= getJsonValue(top[F("UseCelsius")], UseCelsius, true);
|
||||||
configComplete &= getJsonValue(top[F("HomeAssistantDiscovery")], HomeAssistantDiscovery, false);
|
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(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
// first run: reading from cfg.json
|
// first run: reading from cfg.json
|
||||||
|
for (byte i=0; i<2; i++) ioPin[i] = newPin[i];
|
||||||
DEBUG_PRINTLN(F(" config loaded."));
|
DEBUG_PRINTLN(F(" config loaded."));
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
// changing parameters from settings page
|
// changing parameters from settings page
|
||||||
|
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_BME280;
|
||||||
|
if (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda) po = PinOwner::HW_I2C; // allow multiple allocations of 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();
|
||||||
|
}
|
||||||
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
|
return !top[F("pin")].isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
return configComplete;
|
return configComplete;
|
||||||
|
Before Width: | Height: | Size: 122 KiB |
Before Width: | Height: | Size: 23 KiB |
@ -1,81 +0,0 @@
|
|||||||
// 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 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
|
|
||||||
|
|
||||||
//the default ratio for the voltage divider
|
|
||||||
#ifndef USERMOD_BATTERY_VOLTAGE_MULTIPLIER
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
#define USERMOD_BATTERY_VOLTAGE_MULTIPLIER 2.0f
|
|
||||||
#else //ESP8266 boards
|
|
||||||
#define USERMOD_BATTERY_VOLTAGE_MULTIPLIER 4.2f
|
|
||||||
#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
|
|
@ -1,112 +0,0 @@
|
|||||||
<p align="center">
|
|
||||||
<img width="700" src="assets/battery_usermod_logo.png">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img width="500" src="assets/battery_info_screen.png">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## ⚙️ 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
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<img width="300" src="assets/battery_connection_schematic_01.png">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
### 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
|
|
@ -1,787 +0,0 @@
|
|||||||
#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;
|
|
||||||
// between 0 and 1, to control strength of voltage smoothing filter
|
|
||||||
float alpha = 0.05f;
|
|
||||||
// multiplier for the voltage divider that is in place between ADC pin and battery, default will be 2 but might be adapted to readout voltages over ~5v ESP32 or ~6.6v ESP8266
|
|
||||||
float voltageMultiplier = USERMOD_BATTERY_VOLTAGE_MULTIPLIER;
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float readVoltage()
|
|
||||||
{
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
// use calibrated millivolts analogread on esp32 (150 mV ~ 2450 mV default attentuation) and divide by 1000 to get from milivolts to volts and multiply by voltage multiplier and apply calibration value
|
|
||||||
return (analogReadMilliVolts(batteryPin) / 1000.0f) * voltageMultiplier + calibration;
|
|
||||||
#else
|
|
||||||
// use analog read on esp8266 ( 0V ~ 1V no attenuation options) and divide by ADC precision 1023 and multiply by voltage multiplier and apply calibration value
|
|
||||||
return (analogRead(batteryPin) / 1023.0f) * voltageMultiplier + calibration;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
voltage = readVoltage();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
voltage = readVoltage();
|
|
||||||
#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;
|
|
||||||
|
|
||||||
rawValue = readVoltage();
|
|
||||||
// filter with exponential smoothing because ADC in esp32 is fluctuating too much for a good single readout
|
|
||||||
voltage = voltage + alpha * (rawValue - voltage);
|
|
||||||
|
|
||||||
// check if voltage is within specified voltage range, allow 10% over/under voltage - removed cause this just makes it hard for people to troubleshoot as the voltage in the web gui will say invalid instead of displaying a 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[F("voltage-multiplier")] = voltageMultiplier;
|
|
||||||
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;
|
|
||||||
|
|
||||||
// read voltage in case calibration or voltage multiplier changed to see immediate effect
|
|
||||||
voltage = readVoltage();
|
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Battery config saved."));
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendConfigData()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
setVoltageMultiplier(battery[F("voltage-multiplier")] | voltageMultiplier);
|
|
||||||
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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the voltage multiplier value
|
|
||||||
* A multiplier that may need adjusting for different voltage divider setups
|
|
||||||
*/
|
|
||||||
void setVoltageMultiplier(float multiplier)
|
|
||||||
{
|
|
||||||
voltageMultiplier = multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the voltage multiplier value
|
|
||||||
* A multiplier that may need adjusting for different voltage divider setups
|
|
||||||
*/
|
|
||||||
float getVoltageMultiplier()
|
|
||||||
{
|
|
||||||
return voltageMultiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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";
|
|
@ -271,7 +271,6 @@ class UsermodCronixie : public Usermod {
|
|||||||
{
|
{
|
||||||
if (root["nx"].is<const char*>()) {
|
if (root["nx"].is<const char*>()) {
|
||||||
strncpy(cronixieDisplay, root["nx"], 6);
|
strncpy(cronixieDisplay, root["nx"], 6);
|
||||||
setCronixie();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include <dht_nonblocking.h>
|
#include <dht_nonblocking.h>
|
||||||
|
|
||||||
|
@ -22,12 +22,8 @@
|
|||||||
|
|
||||||
//class name. Use something descriptive and leave the ": public Usermod" part :)
|
//class name. Use something descriptive and leave the ": public Usermod" part :)
|
||||||
class MyExampleUsermod : public Usermod {
|
class MyExampleUsermod : public Usermod {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//Private class members. You can declare variables and functions only accessible to your usermod here
|
//Private class members. You can declare variables and functions only accessible to your usermod here
|
||||||
bool enabled = false;
|
|
||||||
bool initDone = false;
|
|
||||||
unsigned long lastTime = 0;
|
unsigned long lastTime = 0;
|
||||||
|
|
||||||
// set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer)
|
// set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer)
|
||||||
@ -41,56 +37,15 @@ class MyExampleUsermod : public Usermod {
|
|||||||
long testLong;
|
long testLong;
|
||||||
int8_t testPins[2];
|
int8_t testPins[2];
|
||||||
|
|
||||||
// string that are used multiple time (this will save some flash memory)
|
|
||||||
static const char _name[];
|
|
||||||
static const char _enabled[];
|
|
||||||
|
|
||||||
|
|
||||||
// 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:
|
public:
|
||||||
|
//Functions called by WLED
|
||||||
// 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.
|
* 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.
|
* You can use it to initialize variables, sensors or similar.
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
// do your set-up here
|
|
||||||
//Serial.println("Hello from my usermod!");
|
//Serial.println("Hello from my usermod!");
|
||||||
initDone = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,11 +69,6 @@ class MyExampleUsermod : public Usermod {
|
|||||||
* Instead, use a timer check as shown here.
|
* Instead, use a timer check as shown here.
|
||||||
*/
|
*/
|
||||||
void loop() {
|
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) {
|
if (millis() - lastTime > 1000) {
|
||||||
//Serial.println("I'm alive!");
|
//Serial.println("I'm alive!");
|
||||||
lastTime = millis();
|
lastTime = millis();
|
||||||
@ -131,25 +81,19 @@ 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.
|
* 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
|
* Below it is shown how this could be used for e.g. a light sensor
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
void addToJsonInfo(JsonObject& root)
|
void addToJsonInfo(JsonObject& root)
|
||||||
{
|
{
|
||||||
// if "u" object does not exist yet wee need to create it
|
int reading = 20;
|
||||||
|
//this code adds "u":{"Light":[20," lux"]} to the info object
|
||||||
JsonObject user = root["u"];
|
JsonObject user = root["u"];
|
||||||
if (user.isNull()) user = root.createNestedObject("u");
|
if (user.isNull()) user = root.createNestedObject("u");
|
||||||
|
|
||||||
//this code adds "u":{"ExampleUsermod":[20," lux"]} to the info object
|
JsonArray lightArr = user.createNestedArray("Light"); //name
|
||||||
//int reading = 20;
|
lightArr.add(reading); //value
|
||||||
//JsonArray lightArr = user.createNestedArray(FPSTR(_name))); //name
|
lightArr.add(" lux"); //unit
|
||||||
//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"));
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -158,12 +102,7 @@ class MyExampleUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void addToJsonState(JsonObject& root)
|
void addToJsonState(JsonObject& root)
|
||||||
{
|
{
|
||||||
if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
|
//root["user0"] = userVar0;
|
||||||
|
|
||||||
JsonObject usermod = root[FPSTR(_name)];
|
|
||||||
if (usermod.isNull()) usermod = root.createNestedObject(FPSTR(_name));
|
|
||||||
|
|
||||||
//usermod["user0"] = userVar0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -173,14 +112,7 @@ class MyExampleUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void readFromJsonState(JsonObject& root)
|
void readFromJsonState(JsonObject& root)
|
||||||
{
|
{
|
||||||
if (!initDone) return; // prevent crash on boot applyPreset()
|
userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
|
||||||
|
|
||||||
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!"));
|
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,10 +154,8 @@ class MyExampleUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void addToConfig(JsonObject& root)
|
void addToConfig(JsonObject& root)
|
||||||
{
|
{
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name));
|
JsonObject top = root.createNestedObject("exampleUsermod");
|
||||||
top[FPSTR(_enabled)] = enabled;
|
top["great"] = userVar0; //save these vars persistently whenever settings are saved
|
||||||
//save these vars persistently whenever settings are saved
|
|
||||||
top["great"] = userVar0;
|
|
||||||
top["testBool"] = testBool;
|
top["testBool"] = testBool;
|
||||||
top["testInt"] = testInt;
|
top["testInt"] = testInt;
|
||||||
top["testLong"] = testLong;
|
top["testLong"] = testLong;
|
||||||
@ -258,7 +188,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
|
// 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)
|
// 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[FPSTR(_name)];
|
JsonObject top = root["exampleUsermod"];
|
||||||
|
|
||||||
bool configComplete = !top.isNull();
|
bool configComplete = !top.isNull();
|
||||||
|
|
||||||
@ -271,8 +201,6 @@ class MyExampleUsermod : public Usermod {
|
|||||||
// A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing
|
// 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["testInt"], testInt, 42);
|
||||||
configComplete &= getJsonValue(top["testLong"], testLong, -42424242);
|
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"][0], testPins[0], -1);
|
||||||
configComplete &= getJsonValue(top["pin"][1], testPins[1], -1);
|
configComplete &= getJsonValue(top["pin"][1], testPins[1], -1);
|
||||||
|
|
||||||
@ -280,21 +208,6 @@ 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,'<i>(this is a great config value)</i>');"));
|
|
||||||
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.
|
* 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.
|
* Use this to blank out some LEDs or set them to a different color regardless of the set effect mode.
|
||||||
@ -306,71 +219,6 @@ class MyExampleUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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!).
|
* 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.
|
* This could be used in the future for the system to determine whether your usermod is installed.
|
||||||
@ -383,24 +231,3 @@ class MyExampleUsermod : public Usermod {
|
|||||||
//More methods can be added in the future, this example will then be extended.
|
//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!
|
//Your usermod will remain compatible as it does not need to implement all methods from the Usermod base class!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// add more strings here to reduce flash memory usage
|
|
||||||
const char MyExampleUsermod::_name[] PROGMEM = "ExampleUsermod";
|
|
||||||
const char MyExampleUsermod::_enabled[] PROGMEM = "enabled";
|
|
||||||
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
@ -133,13 +133,13 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) read32(bmpFS); // filesize in bytes
|
read32(bmpFS); // filesize in bytes
|
||||||
(void) read32(bmpFS); // reserved
|
read32(bmpFS); // reserved
|
||||||
seekOffset = read32(bmpFS); // start of bitmap
|
seekOffset = read32(bmpFS); // start of bitmap
|
||||||
headerSize = read32(bmpFS); // header size
|
headerSize = read32(bmpFS); // header size
|
||||||
w = read32(bmpFS); // width
|
w = read32(bmpFS); // width
|
||||||
h = read32(bmpFS); // height
|
h = read32(bmpFS); // height
|
||||||
(void) read16(bmpFS); // color planes (must be 1)
|
read16(bmpFS); // color planes (must be 1)
|
||||||
bitDepth = read16(bmpFS);
|
bitDepth = read16(bmpFS);
|
||||||
|
|
||||||
if (read32(bmpFS) != 0 || (bitDepth != 24 && bitDepth != 1 && bitDepth != 4 && bitDepth != 8)) {
|
if (read32(bmpFS) != 0 || (bitDepth != 24 && bitDepth != 1 && bitDepth != 4 && bitDepth != 8)) {
|
||||||
@ -151,9 +151,9 @@ private:
|
|||||||
uint32_t palette[256];
|
uint32_t palette[256];
|
||||||
if (bitDepth <= 8) // 1,4,8 bit bitmap: read color palette
|
if (bitDepth <= 8) // 1,4,8 bit bitmap: read color palette
|
||||||
{
|
{
|
||||||
(void) read32(bmpFS); (void) read32(bmpFS); (void) read32(bmpFS); // size, w resolution, h resolution
|
read32(bmpFS); read32(bmpFS); read32(bmpFS); // size, w resolution, h resolution
|
||||||
paletteSize = read32(bmpFS);
|
paletteSize = read32(bmpFS);
|
||||||
if (paletteSize == 0) paletteSize = 1 << bitDepth; //if 0, size is 2^bitDepth
|
if (paletteSize == 0) paletteSize = bitDepth * bitDepth; //if 0, size is 2^bitDepth
|
||||||
bmpFS.seek(14 + headerSize); // start of color palette
|
bmpFS.seek(14 + headerSize); // start of color palette
|
||||||
for (uint16_t i = 0; i < paletteSize; i++) {
|
for (uint16_t i = 0; i < paletteSize; i++) {
|
||||||
palette[i] = read32(bmpFS);
|
palette[i] = read32(bmpFS);
|
||||||
@ -198,7 +198,7 @@ private:
|
|||||||
}
|
}
|
||||||
b = c; g = c >> 8; r = c >> 16;
|
b = c; g = c >> 8; r = c >> 16;
|
||||||
}
|
}
|
||||||
if (dimming != 255) { // only dim when needed
|
if (dimming != 255) { // only dimm when needed
|
||||||
r *= dimming; g *= dimming; b *= dimming;
|
r *= dimming; g *= dimming; b *= dimming;
|
||||||
r = r >> 8; g = g >> 8; b = b >> 8;
|
r = r >> 8; g = g >> 8; b = b >> 8;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
# Internal Temperature Usermod
|
|
||||||
This usermod adds the temperature readout to the Info tab and also publishes that over the topic `mcutemp` topic.
|
|
||||||
|
|
||||||
## Important
|
|
||||||
A shown temp of 53,33°C might indicate that the internal temp is not supported.
|
|
||||||
|
|
||||||
ESP8266 does not have a internal temp sensor
|
|
||||||
|
|
||||||
ESP32S2 seems to crash on reading the sensor -> disabled
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
Add a build flag `-D USERMOD_INTERNAL_TEMPERATURE` to your `platformio.ini` (or `platformio_override.ini`).
|
|
||||||
|
|
||||||
## Authors
|
|
||||||
Soeren Willrodt [@lost-hope](https://github.com/lost-hope)
|
|
||||||
|
|
||||||
Dimitry Zhemkov [@dima-zhemkov](https://github.com/dima-zhemkov)
|
|
@ -1,117 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "wled.h"
|
|
||||||
|
|
||||||
class InternalTemperatureUsermod : public Usermod
|
|
||||||
{
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned long loopInterval = 10000;
|
|
||||||
unsigned long lastTime = 0;
|
|
||||||
bool isEnabled = false;
|
|
||||||
float temperature = 0;
|
|
||||||
|
|
||||||
static const char _name[];
|
|
||||||
static const char _enabled[];
|
|
||||||
static const char _loopInterval[];
|
|
||||||
|
|
||||||
// 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:
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (!isEnabled || strip.isUpdating() || millis() - lastTime <= loopInterval)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lastTime = millis();
|
|
||||||
|
|
||||||
#ifdef ESP8266 // ESP8266
|
|
||||||
// does not seem possible
|
|
||||||
temperature = -1;
|
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // ESP32S2
|
|
||||||
temperature = -1;
|
|
||||||
#else // ESP32 ESP32S3 and ESP32C3
|
|
||||||
temperature = roundf(temperatureRead() * 10) / 10;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
if (WLED_MQTT_CONNECTED)
|
|
||||||
{
|
|
||||||
char array[10];
|
|
||||||
snprintf(array, sizeof(array), "%f", temperature);
|
|
||||||
publishMqtt(array);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject &root)
|
|
||||||
{
|
|
||||||
if (!isEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// if "u" object does not exist yet wee need to create it
|
|
||||||
JsonObject user = root["u"];
|
|
||||||
if (user.isNull())
|
|
||||||
user = root.createNestedObject("u");
|
|
||||||
|
|
||||||
JsonArray userTempArr = user.createNestedArray(FPSTR(_name));
|
|
||||||
userTempArr.add(temperature);
|
|
||||||
userTempArr.add(F(" °C"));
|
|
||||||
|
|
||||||
// if "sensor" object does not exist yet wee need to create it
|
|
||||||
JsonObject sensor = root[F("sensor")];
|
|
||||||
if (sensor.isNull())
|
|
||||||
sensor = root.createNestedObject(F("sensor"));
|
|
||||||
|
|
||||||
JsonArray sensorTempArr = sensor.createNestedArray(FPSTR(_name));
|
|
||||||
sensorTempArr.add(temperature);
|
|
||||||
sensorTempArr.add(F("°C"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addToConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name));
|
|
||||||
top[FPSTR(_enabled)] = isEnabled;
|
|
||||||
top[FPSTR(_loopInterval)] = loopInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readFromConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
JsonObject top = root[FPSTR(_name)];
|
|
||||||
bool configComplete = !top.isNull();
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_enabled)], isEnabled);
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_loopInterval)], loopInterval);
|
|
||||||
|
|
||||||
return configComplete;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getId()
|
|
||||||
{
|
|
||||||
return USERMOD_ID_INTERNAL_TEMPERATURE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char InternalTemperatureUsermod::_name[] PROGMEM = "Internal Temperature";
|
|
||||||
const char InternalTemperatureUsermod::_enabled[] PROGMEM = "Enabled";
|
|
||||||
const char InternalTemperatureUsermod::_loopInterval[] PROGMEM = "Loop Interval";
|
|
||||||
|
|
||||||
void InternalTemperatureUsermod::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("/mcutemp"));
|
|
||||||
mqtt->publish(subuf, 0, retain, state);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -20,7 +20,7 @@
|
|||||||
* This usermod handles PIR sensor states.
|
* This usermod handles PIR sensor states.
|
||||||
* The strip will be switched on and the off timer will be resetted when the sensor goes HIGH.
|
* The strip will be switched on and the off timer will be resetted when the sensor goes HIGH.
|
||||||
* When the sensor state goes LOW, the off timer is started and when it expires, the strip is switched off.
|
* When the sensor state goes LOW, the off timer is started and when it expires, the strip is switched off.
|
||||||
* Maintained by: @blazoncek
|
*
|
||||||
*
|
*
|
||||||
* Usermods allow you to add own functionality to WLED more easily
|
* Usermods allow you to add own functionality to WLED more easily
|
||||||
* See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality
|
* See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality
|
||||||
@ -38,21 +38,21 @@ public:
|
|||||||
~PIRsensorSwitch() {}
|
~PIRsensorSwitch() {}
|
||||||
|
|
||||||
//Enable/Disable the PIR sensor
|
//Enable/Disable the PIR sensor
|
||||||
inline void EnablePIRsensor(bool en) { enabled = en; }
|
void EnablePIRsensor(bool en) { enabled = en; }
|
||||||
|
|
||||||
// Get PIR sensor enabled/disabled state
|
// Get PIR sensor enabled/disabled state
|
||||||
inline bool PIRsensorEnabled() { return enabled; }
|
bool PIRsensorEnabled() { return enabled; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
byte prevPreset = 0;
|
byte prevPreset = 0;
|
||||||
byte prevPlaylist = 0;
|
byte prevPlaylist = 0;
|
||||||
|
|
||||||
volatile unsigned long offTimerStart = 0; // off timer start time
|
uint32_t offTimerStart = 0; // off timer start time
|
||||||
volatile bool PIRtriggered = false; // did PIR trigger?
|
|
||||||
byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for stateUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE
|
byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for stateUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE
|
||||||
byte sensorPinState = LOW; // current PIR sensor pin state
|
byte sensorPinState = LOW; // current PIR sensor pin state
|
||||||
bool initDone = false; // status of initialization
|
bool initDone = false; // status of initialization
|
||||||
|
bool PIRtriggered = false;
|
||||||
unsigned long lastLoop = 0;
|
unsigned long lastLoop = 0;
|
||||||
|
|
||||||
// configurable parameters
|
// configurable parameters
|
||||||
@ -66,7 +66,6 @@ private:
|
|||||||
// flag to enable triggering only if WLED is initially off (LEDs are not on, preventing running effect being overwritten by PIR)
|
// flag to enable triggering only if WLED is initially off (LEDs are not on, preventing running effect being overwritten by PIR)
|
||||||
bool m_offOnly = false;
|
bool m_offOnly = false;
|
||||||
bool m_offMode = offMode;
|
bool m_offMode = offMode;
|
||||||
bool m_override = false;
|
|
||||||
|
|
||||||
// Home Assistant
|
// Home Assistant
|
||||||
bool HomeAssistantDiscovery = false; // is HA discovery turned on
|
bool HomeAssistantDiscovery = false; // is HA discovery turned on
|
||||||
@ -82,122 +81,12 @@ private:
|
|||||||
static const char _offOnly[];
|
static const char _offOnly[];
|
||||||
static const char _haDiscovery[];
|
static const char _haDiscovery[];
|
||||||
static const char _notify[];
|
static const char _notify[];
|
||||||
static const char _override[];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if it is daytime
|
* check if it is daytime
|
||||||
* if sunrise/sunset is not defined (no NTP or lat/lon) default to nighttime
|
* if sunrise/sunset is not defined (no NTP or lat/lon) default to nighttime
|
||||||
*/
|
*/
|
||||||
static bool isDayTime();
|
bool isDayTime() {
|
||||||
|
|
||||||
/**
|
|
||||||
* switch strip on/off
|
|
||||||
*/
|
|
||||||
void switchStrip(bool switchOn);
|
|
||||||
void publishMqtt(const char* state);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read and update PIR sensor state.
|
|
||||||
* Initilize/reset switch off timer
|
|
||||||
*/
|
|
||||||
bool updatePIRsensorState();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* switch off the strip if the delay has elapsed
|
|
||||||
*/
|
|
||||||
bool handleOffTimer();
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* connected() is called every time the WiFi is (re)connected
|
|
||||||
* Use it to initialize network interfaces
|
|
||||||
*/
|
|
||||||
//void connected();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* onMqttConnect() is called when MQTT connection is established
|
|
||||||
*/
|
|
||||||
void onMqttConnect(bool sessionPresent);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
|
||||||
*/
|
|
||||||
void loop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
|
||||||
*
|
|
||||||
* Add PIR sensor state and switch off timer duration to jsoninfo
|
|
||||||
*/
|
|
||||||
void addToJsonInfo(JsonObject &root);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* onStateChanged() is used to detect WLED state change
|
|
||||||
*/
|
|
||||||
void onStateChange(uint8_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* provide the changeable values
|
|
||||||
*/
|
|
||||||
void addToConfig(JsonObject &root);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* provide UI information and allow extending UI options
|
|
||||||
*/
|
|
||||||
void appendConfigData();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* restore the changeable values
|
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
|
||||||
*
|
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
|
||||||
*/
|
|
||||||
bool readFromConfig(JsonObject &root);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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_PIRSWITCH; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
|
||||||
const char PIRsensorSwitch::_name[] PROGMEM = "PIRsensorSwitch";
|
|
||||||
const char PIRsensorSwitch::_enabled[] PROGMEM = "PIRenabled";
|
|
||||||
const char PIRsensorSwitch::_switchOffDelay[] PROGMEM = "PIRoffSec";
|
|
||||||
const char PIRsensorSwitch::_onPreset[] PROGMEM = "on-preset";
|
|
||||||
const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset";
|
|
||||||
const char PIRsensorSwitch::_nightTime[] PROGMEM = "nighttime-only";
|
|
||||||
const char PIRsensorSwitch::_mqttOnly[] PROGMEM = "mqtt-only";
|
|
||||||
const char PIRsensorSwitch::_offOnly[] PROGMEM = "off-only";
|
|
||||||
const char PIRsensorSwitch::_haDiscovery[] PROGMEM = "HA-discovery";
|
|
||||||
const char PIRsensorSwitch::_notify[] PROGMEM = "notifications";
|
|
||||||
const char PIRsensorSwitch::_override[] PROGMEM = "override";
|
|
||||||
|
|
||||||
bool PIRsensorSwitch::isDayTime() {
|
|
||||||
updateLocalTime();
|
updateLocalTime();
|
||||||
uint8_t hr = hour(localTime);
|
uint8_t hr = hour(localTime);
|
||||||
uint8_t mi = minute(localTime);
|
uint8_t mi = minute(localTime);
|
||||||
@ -217,12 +106,14 @@ bool PIRsensorSwitch::isDayTime() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::switchStrip(bool switchOn)
|
/**
|
||||||
|
* switch strip on/off
|
||||||
|
*/
|
||||||
|
void switchStrip(bool switchOn)
|
||||||
{
|
{
|
||||||
if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; //if lights on and off only, do nothing
|
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
|
if (PIRtriggered && switchOn) return; //if already on and triggered before, do nothing
|
||||||
PIRtriggered = switchOn;
|
PIRtriggered = switchOn;
|
||||||
DEBUG_PRINT(F("PIR: strip=")); DEBUG_PRINTLN(switchOn?"on":"off");
|
|
||||||
if (switchOn) {
|
if (switchOn) {
|
||||||
if (m_onPreset) {
|
if (m_onPreset) {
|
||||||
if (currentPlaylist>0 && !offMode) {
|
if (currentPlaylist>0 && !offMode) {
|
||||||
@ -245,7 +136,7 @@ void PIRsensorSwitch::switchStrip(bool switchOn)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (m_offPreset) {
|
if (m_offPreset) {
|
||||||
applyPreset(m_offPreset, NotifyUpdateMode);
|
if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(m_offPreset, NotifyUpdateMode);
|
||||||
return;
|
return;
|
||||||
} else if (prevPlaylist) {
|
} else if (prevPlaylist) {
|
||||||
if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(prevPlaylist, NotifyUpdateMode);
|
if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(prevPlaylist, NotifyUpdateMode);
|
||||||
@ -266,21 +157,20 @@ void PIRsensorSwitch::switchStrip(bool switchOn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::publishMqtt(const char* state)
|
void publishMqtt(const char* state)
|
||||||
{
|
{
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (WLED_MQTT_CONNECTED) {
|
if (WLED_MQTT_CONNECTED) {
|
||||||
char buf[64];
|
char subuf[64];
|
||||||
sprintf_P(buf, PSTR("%s/motion"), mqttDeviceTopic); //max length: 33 + 7 = 40
|
strcpy(subuf, mqttDeviceTopic);
|
||||||
mqtt->publish(buf, 0, false, state);
|
strcat_P(subuf, PSTR("/motion"));
|
||||||
|
mqtt->publish(subuf, 0, false, state);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::publishHomeAssistantAutodiscovery()
|
// 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) {
|
if (WLED_MQTT_CONNECTED) {
|
||||||
StaticJsonDocument<600> doc;
|
StaticJsonDocument<600> doc;
|
||||||
char uid[24], json_str[1024], buf[128];
|
char uid[24], json_str[1024], buf[128];
|
||||||
@ -310,10 +200,13 @@ void PIRsensorSwitch::publishHomeAssistantAutodiscovery()
|
|||||||
|
|
||||||
mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain?
|
mqtt->publish(buf, 0, true, json_str, payload_size); // do we really need to retain?
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PIRsensorSwitch::updatePIRsensorState()
|
/**
|
||||||
|
* Read and update PIR sensor state.
|
||||||
|
* Initilize/reset switch off timer
|
||||||
|
*/
|
||||||
|
bool updatePIRsensorState()
|
||||||
{
|
{
|
||||||
bool pinState = digitalRead(PIRsensorPin);
|
bool pinState = digitalRead(PIRsensorPin);
|
||||||
if (pinState != sensorPinState) {
|
if (pinState != sensorPinState) {
|
||||||
@ -334,7 +227,10 @@ bool PIRsensorSwitch::updatePIRsensorState()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PIRsensorSwitch::handleOffTimer()
|
/**
|
||||||
|
* switch off the strip if the delay has elapsed
|
||||||
|
*/
|
||||||
|
bool handleOffTimer()
|
||||||
{
|
{
|
||||||
if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) {
|
if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) {
|
||||||
offTimerStart = 0;
|
offTimerStart = 0;
|
||||||
@ -348,9 +244,14 @@ bool PIRsensorSwitch::handleOffTimer()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
//Functions called by WLED
|
//Functions called by WLED
|
||||||
|
|
||||||
void PIRsensorSwitch::setup()
|
/**
|
||||||
|
* 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()
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
||||||
@ -369,14 +270,27 @@ void PIRsensorSwitch::setup()
|
|||||||
initDone = true;
|
initDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::onMqttConnect(bool sessionPresent)
|
/**
|
||||||
|
* connected() is called every time the WiFi is (re)connected
|
||||||
|
* Use it to initialize network interfaces
|
||||||
|
*/
|
||||||
|
void connected()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onMqttConnect() is called when MQTT connection is established
|
||||||
|
*/
|
||||||
|
void onMqttConnect(bool sessionPresent) {
|
||||||
if (HomeAssistantDiscovery) {
|
if (HomeAssistantDiscovery) {
|
||||||
publishHomeAssistantAutodiscovery();
|
publishHomeAssistantAutodiscovery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::loop()
|
/**
|
||||||
|
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
||||||
|
*/
|
||||||
|
void loop()
|
||||||
{
|
{
|
||||||
// only check sensors 4x/s
|
// only check sensors 4x/s
|
||||||
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating()) return;
|
if (!enabled || millis() - lastLoop < 250 || strip.isUpdating()) return;
|
||||||
@ -387,7 +301,12 @@ void PIRsensorSwitch::loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::addToJsonInfo(JsonObject &root)
|
/**
|
||||||
|
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
||||||
|
*
|
||||||
|
* Add PIR sensor state and switch off timer duration to jsoninfo
|
||||||
|
*/
|
||||||
|
void addToJsonInfo(JsonObject &root)
|
||||||
{
|
{
|
||||||
JsonObject user = root["u"];
|
JsonObject user = root["u"];
|
||||||
if (user.isNull()) user = root.createNestedObject("u");
|
if (user.isNull()) user = root.createNestedObject("u");
|
||||||
@ -447,18 +366,22 @@ void PIRsensorSwitch::addToJsonInfo(JsonObject &root)
|
|||||||
sensor[F("motion")] = sensorPinState || offTimerStart>0 ? true : false;
|
sensor[F("motion")] = sensorPinState || offTimerStart>0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::onStateChange(uint8_t mode) {
|
/**
|
||||||
if (!initDone) return;
|
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
||||||
DEBUG_PRINT(F("PIR: offTimerStart=")); DEBUG_PRINTLN(offTimerStart);
|
* Values in the state object may be modified by connected clients
|
||||||
if (m_override && PIRtriggered && offTimerStart) { // debounce
|
*/
|
||||||
// checking PIRtriggered and offTimerStart will prevent cancellation upon On trigger
|
/*
|
||||||
DEBUG_PRINTLN(F("PIR: Canceled."));
|
void addToJsonState(JsonObject &root)
|
||||||
offTimerStart = 0;
|
{
|
||||||
PIRtriggered = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void PIRsensorSwitch::readFromJsonState(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()
|
if (!initDone) return; // prevent crash on boot applyPreset()
|
||||||
JsonObject usermod = root[FPSTR(_name)];
|
JsonObject usermod = root[FPSTR(_name)];
|
||||||
@ -469,7 +392,11 @@ void PIRsensorSwitch::readFromJsonState(JsonObject &root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::addToConfig(JsonObject &root)
|
|
||||||
|
/**
|
||||||
|
* provide the changeable values
|
||||||
|
*/
|
||||||
|
void addToConfig(JsonObject &root)
|
||||||
{
|
{
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name));
|
JsonObject top = root.createNestedObject(FPSTR(_name));
|
||||||
top[FPSTR(_enabled)] = enabled;
|
top[FPSTR(_enabled)] = enabled;
|
||||||
@ -480,20 +407,24 @@ void PIRsensorSwitch::addToConfig(JsonObject &root)
|
|||||||
top[FPSTR(_nightTime)] = m_nightTimeOnly;
|
top[FPSTR(_nightTime)] = m_nightTimeOnly;
|
||||||
top[FPSTR(_mqttOnly)] = m_mqttOnly;
|
top[FPSTR(_mqttOnly)] = m_mqttOnly;
|
||||||
top[FPSTR(_offOnly)] = m_offOnly;
|
top[FPSTR(_offOnly)] = m_offOnly;
|
||||||
top[FPSTR(_override)] = m_override;
|
|
||||||
top[FPSTR(_haDiscovery)] = HomeAssistantDiscovery;
|
top[FPSTR(_haDiscovery)] = HomeAssistantDiscovery;
|
||||||
top[FPSTR(_notify)] = (NotifyUpdateMode != CALL_MODE_NO_NOTIFY);
|
top[FPSTR(_notify)] = (NotifyUpdateMode != CALL_MODE_NO_NOTIFY);
|
||||||
DEBUG_PRINTLN(F("PIR config saved."));
|
DEBUG_PRINTLN(F("PIR config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIRsensorSwitch::appendConfigData()
|
void appendConfigData()
|
||||||
{
|
{
|
||||||
oappend(SET_F("addInfo('PIRsensorSwitch:HA-discovery',1,'HA=Home Assistant');")); // 0 is field type, 1 is actual field
|
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
|
oappend(SET_F("addInfo('PIRsensorSwitch:notifications',1,'Periodic WS updates');")); // 0 is field type, 1 is actual field
|
||||||
oappend(SET_F("addInfo('PIRsensorSwitch:override',1,'Cancel timer on change');")); // 0 is field type, 1 is actual field
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PIRsensorSwitch::readFromConfig(JsonObject &root)
|
/**
|
||||||
|
* restore the changeable values
|
||||||
|
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
||||||
|
*
|
||||||
|
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
||||||
|
*/
|
||||||
|
bool readFromConfig(JsonObject &root)
|
||||||
{
|
{
|
||||||
bool oldEnabled = enabled;
|
bool oldEnabled = enabled;
|
||||||
int8_t oldPin = PIRsensorPin;
|
int8_t oldPin = PIRsensorPin;
|
||||||
@ -519,7 +450,6 @@ bool PIRsensorSwitch::readFromConfig(JsonObject &root)
|
|||||||
m_nightTimeOnly = top[FPSTR(_nightTime)] | m_nightTimeOnly;
|
m_nightTimeOnly = top[FPSTR(_nightTime)] | m_nightTimeOnly;
|
||||||
m_mqttOnly = top[FPSTR(_mqttOnly)] | m_mqttOnly;
|
m_mqttOnly = top[FPSTR(_mqttOnly)] | m_mqttOnly;
|
||||||
m_offOnly = top[FPSTR(_offOnly)] | m_offOnly;
|
m_offOnly = top[FPSTR(_offOnly)] | m_offOnly;
|
||||||
m_override = top[FPSTR(_override)] | m_override;
|
|
||||||
HomeAssistantDiscovery = top[FPSTR(_haDiscovery)] | HomeAssistantDiscovery;
|
HomeAssistantDiscovery = top[FPSTR(_haDiscovery)] | HomeAssistantDiscovery;
|
||||||
|
|
||||||
NotifyUpdateMode = top[FPSTR(_notify)] ? CALL_MODE_DIRECT_CHANGE : CALL_MODE_NO_NOTIFY;
|
NotifyUpdateMode = top[FPSTR(_notify)] ? CALL_MODE_DIRECT_CHANGE : CALL_MODE_NO_NOTIFY;
|
||||||
@ -549,5 +479,27 @@ bool PIRsensorSwitch::readFromConfig(JsonObject &root)
|
|||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return !top[FPSTR(_override)].isNull();
|
return !top[FPSTR(_haDiscovery)].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_PIRSWITCH;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
|
const char PIRsensorSwitch::_name[] PROGMEM = "PIRsensorSwitch";
|
||||||
|
const char PIRsensorSwitch::_enabled[] PROGMEM = "PIRenabled";
|
||||||
|
const char PIRsensorSwitch::_switchOffDelay[] PROGMEM = "PIRoffSec";
|
||||||
|
const char PIRsensorSwitch::_onPreset[] PROGMEM = "on-preset";
|
||||||
|
const char PIRsensorSwitch::_offPreset[] PROGMEM = "off-preset";
|
||||||
|
const char PIRsensorSwitch::_nightTime[] PROGMEM = "nighttime-only";
|
||||||
|
const char PIRsensorSwitch::_mqttOnly[] PROGMEM = "mqtt-only";
|
||||||
|
const char PIRsensorSwitch::_offOnly[] PROGMEM = "off-only";
|
||||||
|
const char PIRsensorSwitch::_haDiscovery[] PROGMEM = "HA-discovery";
|
||||||
|
const char PIRsensorSwitch::_notify[] PROGMEM = "notifications";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if !defined(USERMOD_DALLASTEMPERATURE) && !defined(USERMOD_SHT)
|
#ifndef USERMOD_DALLASTEMPERATURE
|
||||||
#error The "PWM fan" usermod requires "Dallas Temeprature" or "SHT" usermod to function properly.
|
#error The "PWM fan" usermod requires "Dallas Temeprature" usermod to function properly.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
@ -42,8 +42,6 @@ class PWMFanUsermod : public Usermod {
|
|||||||
|
|
||||||
#ifdef USERMOD_DALLASTEMPERATURE
|
#ifdef USERMOD_DALLASTEMPERATURE
|
||||||
UsermodTemperature* tempUM;
|
UsermodTemperature* tempUM;
|
||||||
#elif defined(USERMOD_SHT)
|
|
||||||
ShtUsermod* tempUM;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// configurable parameters
|
// configurable parameters
|
||||||
@ -147,7 +145,7 @@ class PWMFanUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float getActualTemperature(void) {
|
float getActualTemperature(void) {
|
||||||
#if defined(USERMOD_DALLASTEMPERATURE) || defined(USERMOD_SHT)
|
#ifdef USERMOD_DALLASTEMPERATURE
|
||||||
if (tempUM != nullptr)
|
if (tempUM != nullptr)
|
||||||
return tempUM->getTemperatureC();
|
return tempUM->getTemperatureC();
|
||||||
#endif
|
#endif
|
||||||
@ -191,8 +189,6 @@ class PWMFanUsermod : public Usermod {
|
|||||||
#ifdef USERMOD_DALLASTEMPERATURE
|
#ifdef USERMOD_DALLASTEMPERATURE
|
||||||
// This Usermod requires Temperature usermod
|
// This Usermod requires Temperature usermod
|
||||||
tempUM = (UsermodTemperature*) usermods.lookup(USERMOD_ID_TEMPERATURE);
|
tempUM = (UsermodTemperature*) usermods.lookup(USERMOD_ID_TEMPERATURE);
|
||||||
#elif defined(USERMOD_SHT)
|
|
||||||
tempUM = (ShtUsermod*) usermods.lookup(USERMOD_ID_SHT);
|
|
||||||
#endif
|
#endif
|
||||||
initTacho();
|
initTacho();
|
||||||
initPWMfan();
|
initPWMfan();
|
||||||
|
@ -12,7 +12,8 @@ class RTCUsermod : public Usermod {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
if (i2c_scl<0 || i2c_sda<0) { disabled = true; return; }
|
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
|
||||||
|
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
|
||||||
RTC.begin();
|
RTC.begin();
|
||||||
time_t rtcTime = RTC.get();
|
time_t rtcTime = RTC.get();
|
||||||
if (rtcTime) {
|
if (rtcTime) {
|
||||||
@ -24,8 +25,8 @@ class RTCUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (disabled || strip.isUpdating()) return;
|
if (strip.isUpdating()) return;
|
||||||
if (toki.isTick()) {
|
if (!disabled && toki.isTick()) {
|
||||||
time_t t = toki.second();
|
time_t t = toki.second();
|
||||||
if (t != RTC.get()) RTC.set(t); //set RTC to NTP/UI-provided value
|
if (t != RTC.get()) RTC.set(t); //set RTC to NTP/UI-provided value
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,6 @@ public:
|
|||||||
{
|
{
|
||||||
lastLDRValue = currentLDRValue;
|
lastLDRValue = currentLDRValue;
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
if (WLED_MQTT_CONNECTED)
|
if (WLED_MQTT_CONNECTED)
|
||||||
{
|
{
|
||||||
char subuf[45];
|
char subuf[45];
|
||||||
@ -122,7 +121,6 @@ public:
|
|||||||
DEBUG_PRINTLN("Missing MQTT connection. Not publishing data");
|
DEBUG_PRINTLN("Missing MQTT connection. Not publishing data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getLastLDRValue()
|
uint16_t getLastLDRValue()
|
||||||
|
@ -17,6 +17,12 @@
|
|||||||
#ifndef TFT_HEIGHT
|
#ifndef TFT_HEIGHT
|
||||||
#error Please define TFT_HEIGHT
|
#error Please define TFT_HEIGHT
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef TFT_MOSI
|
||||||
|
#error Please define TFT_MOSI
|
||||||
|
#endif
|
||||||
|
#ifndef TFT_SCLK
|
||||||
|
#error Please define TFT_SCLK
|
||||||
|
#endif
|
||||||
#ifndef TFT_DC
|
#ifndef TFT_DC
|
||||||
#error Please define TFT_DC
|
#error Please define TFT_DC
|
||||||
#endif
|
#endif
|
||||||
@ -134,14 +140,8 @@ class St7789DisplayUsermod : public Usermod {
|
|||||||
*/
|
*/
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
PinManagerPinType spiPins[] = { { spi_mosi, true }, { spi_miso, false}, { spi_sclk, true } };
|
PinManagerPinType pins[] = { { TFT_MOSI, true }, { TFT_MISO, false}, { TFT_SCLK, true }, { TFT_CS, true}, { TFT_DC, true}, { TFT_RST, true }, { TFT_BL, true } };
|
||||||
if (!pinManager.allocateMultiplePins(spiPins, 3, PinOwner::HW_SPI)) { enabled = false; return; }
|
if (!pinManager.allocateMultiplePins(pins, 7, PinOwner::UM_FourLineDisplay)) { enabled = false; return; }
|
||||||
PinManagerPinType displayPins[] = { { TFT_CS, true}, { TFT_DC, true}, { TFT_RST, true }, { TFT_BL, true } };
|
|
||||||
if (!pinManager.allocateMultiplePins(displayPins, sizeof(displayPins)/sizeof(PinManagerPinType), PinOwner::UM_FourLineDisplay)) {
|
|
||||||
pinManager.deallocateMultiplePins(spiPins, 3, PinOwner::HW_SPI);
|
|
||||||
enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tft.init();
|
tft.init();
|
||||||
tft.setRotation(0); //Rotation here is set up for the text to be readable with the port on the left. Use 1 to flip.
|
tft.setRotation(0); //Rotation here is set up for the text to be readable with the port on the left. Use 1 to flip.
|
||||||
@ -365,6 +365,9 @@ class St7789DisplayUsermod : public Usermod {
|
|||||||
{
|
{
|
||||||
JsonObject top = root.createNestedObject("ST7789");
|
JsonObject top = root.createNestedObject("ST7789");
|
||||||
JsonArray pins = top.createNestedArray("pin");
|
JsonArray pins = top.createNestedArray("pin");
|
||||||
|
pins.add(TFT_MOSI);
|
||||||
|
pins.add(TFT_MISO);
|
||||||
|
pins.add(TFT_SCLK);
|
||||||
pins.add(TFT_CS);
|
pins.add(TFT_CS);
|
||||||
pins.add(TFT_DC);
|
pins.add(TFT_DC);
|
||||||
pins.add(TFT_RST);
|
pins.add(TFT_RST);
|
||||||
@ -373,13 +376,6 @@ class St7789DisplayUsermod : public Usermod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void appendConfigData() {
|
|
||||||
oappend(SET_F("addInfo('ST7789:pin[]',0,'','SPI CS');"));
|
|
||||||
oappend(SET_F("addInfo('ST7789:pin[]',1,'','SPI DC');"));
|
|
||||||
oappend(SET_F("addInfo('ST7789:pin[]',2,'','SPI RST');"));
|
|
||||||
oappend(SET_F("addInfo('ST7789:pin[]',2,'','SPI BL');"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* readFromConfig() can be used to read back the custom settings you added with addToConfig().
|
* 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 once immediately after boot)
|
* This is called by WLED when settings are loaded (currently this only happens once immediately after boot)
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod)
|
// this is remixed from usermod_v2_SensorsToMqtt.h (sensors_to_mqtt usermod)
|
||||||
@ -13,6 +9,14 @@
|
|||||||
|
|
||||||
Adafruit_Si7021 si7021;
|
Adafruit_Si7021 si7021;
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32 //ESP32 boards
|
||||||
|
uint8_t SCL_PIN = 22;
|
||||||
|
uint8_t SDA_PIN = 21;
|
||||||
|
#else //ESP8266 boards
|
||||||
|
uint8_t SCL_PIN = 5;
|
||||||
|
uint8_t SDA_PIN = 4;
|
||||||
|
#endif
|
||||||
|
|
||||||
class Si7021_MQTT_HA : public Usermod
|
class Si7021_MQTT_HA : public Usermod
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -176,6 +180,7 @@ class Si7021_MQTT_HA : public Usermod
|
|||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Serial.println("Si7021_MQTT_HA: Starting!");
|
Serial.println("Si7021_MQTT_HA: Starting!");
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN);
|
||||||
Serial.println("Si7021_MQTT_HA: Initializing sensors.. ");
|
Serial.println("Si7021_MQTT_HA: Initializing sensors.. ");
|
||||||
_initializeSensor();
|
_initializeSensor();
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
; Options
|
; Options
|
||||||
; -------
|
; -------
|
||||||
; USERMOD_DALLASTEMPERATURE - define this to have this user mod included wled00\usermods_list.cpp
|
; USERMOD_DALLASTEMPERATURE - define this to have this user mod included wled00\usermods_list.cpp
|
||||||
|
; USERMOD_DALLASTEMPERATURE_CELSIUS - define this to report temperatures in degrees celsius, otherwise fahrenheit will be reported
|
||||||
; USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - the number of milliseconds between measurements, defaults to 60 seconds
|
; USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - the number of milliseconds between measurements, defaults to 60 seconds
|
||||||
|
; USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT - the number of milliseconds after boot to take first measurement, defaults to 20 seconds
|
||||||
;
|
;
|
||||||
[env:d1_mini_usermod_dallas_temperature_C]
|
[env:d1_mini_usermod_dallas_temperature_C]
|
||||||
extends = env:d1_mini
|
extends = env:d1_mini
|
||||||
build_flags = ${common.build_flags_esp8266} -D USERMOD_DALLASTEMPERATURE
|
build_flags = ${common.build_flags_esp8266} -D USERMOD_DALLASTEMPERATURE -D USERMOD_DALLASTEMPERATURE_CELSIUS
|
||||||
lib_deps = ${env.lib_deps}
|
lib_deps = ${env.lib_deps}
|
||||||
paulstoffregen/OneWire@~2.3.7
|
milesburton/DallasTemperature@^3.9.0
|
||||||
# you may want to use following with ESP32
|
OneWire@~2.3.5
|
||||||
; https://github.com/blazoncek/OneWire.git # fixes Sensor error on ESP32
|
|
||||||
|
@ -7,8 +7,6 @@ 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.
|
If temperature sensor is not detected during boot, this usermod will be disabled.
|
||||||
|
|
||||||
Maintained by @blazoncek
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Copy the example `platformio_override.ini` to the root directory. This file should be placed in the same directory as `platformio.ini`.
|
Copy the example `platformio_override.ini` to the root directory. This file should be placed in the same directory as `platformio.ini`.
|
||||||
@ -16,7 +14,7 @@ Copy the example `platformio_override.ini` to the root directory. This file sho
|
|||||||
### Define Your Options
|
### Define Your Options
|
||||||
|
|
||||||
* `USERMOD_DALLASTEMPERATURE` - enables this user mod wled00/usermods_list.cpp
|
* `USERMOD_DALLASTEMPERATURE` - enables this user mod wled00/usermods_list.cpp
|
||||||
* `USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL` - number of milliseconds between measurements, defaults to 60000 ms (60s)
|
* `USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT` - umber of milliseconds after boot to take first measurement, defaults to 20000 ms
|
||||||
|
|
||||||
All parameters can be configured at runtime via the Usermods settings page, including pin, temperature in degrees Celsius or Farenheit and 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.
|
||||||
|
|
||||||
@ -29,6 +27,7 @@ All parameters can be configured at runtime via the Usermods settings page, incl
|
|||||||
|
|
||||||
If you are using `platformio_override.ini`, you should be able to refresh the task list and see your custom task, for example `env:d1_mini_usermod_dallas_temperature_C`.
|
If you are using `platformio_override.ini`, you should be able to refresh the task list and see your custom task, for example `env:d1_mini_usermod_dallas_temperature_C`.
|
||||||
|
|
||||||
|
|
||||||
If you are not using `platformio_override.ini`, you might have to uncomment `OneWire@~2.3.5 under` `[common]` section in `platformio.ini`:
|
If you are not using `platformio_override.ini`, you might have to uncomment `OneWire@~2.3.5 under` `[common]` section in `platformio.ini`:
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
@ -44,9 +43,8 @@ default_envs = d1_mini
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
...
|
...
|
||||||
#For Dallas sensor uncomment following line
|
#For Dallas sensor uncomment following line
|
||||||
OneWire@~2.3.7
|
OneWire@~2.3.5
|
||||||
# ... or you may want to use following with ESP32
|
...
|
||||||
; https://github.com/blazoncek/OneWire.git # fixes Sensor error on ESP32...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Change Log
|
## Change Log
|
||||||
@ -58,6 +56,3 @@ lib_deps =
|
|||||||
* Report the number of seconds until the first read in the info screen instead of sensor error
|
* Report the number of seconds until the first read in the info screen instead of sensor error
|
||||||
2021-04
|
2021-04
|
||||||
* Adaptation for runtime configuration.
|
* Adaptation for runtime configuration.
|
||||||
2023-05
|
|
||||||
* Rewrite to conform to newer recommendations.
|
|
||||||
* Recommended @blazoncek fork of OneWire for ESP32 to avoid Sensor error
|
|
@ -29,7 +29,6 @@ class UsermodTemperature : public Usermod {
|
|||||||
bool degC = true;
|
bool degC = true;
|
||||||
// using parasite power on the sensor
|
// using parasite power on the sensor
|
||||||
bool parasite = false;
|
bool parasite = false;
|
||||||
int8_t parasitePin = -1;
|
|
||||||
// how often do we read from sensor?
|
// how often do we read from sensor?
|
||||||
unsigned long readingInterval = USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL;
|
unsigned long readingInterval = USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL;
|
||||||
// set last reading as "40 sec before boot", so first reading is taken after 20 sec
|
// set last reading as "40 sec before boot", so first reading is taken after 20 sec
|
||||||
@ -54,50 +53,9 @@ class UsermodTemperature : public Usermod {
|
|||||||
static const char _enabled[];
|
static const char _enabled[];
|
||||||
static const char _readInterval[];
|
static const char _readInterval[];
|
||||||
static const char _parasite[];
|
static const char _parasite[];
|
||||||
static const char _parasitePin[];
|
|
||||||
|
|
||||||
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
||||||
float readDallas();
|
float readDallas() {
|
||||||
void requestTemperatures();
|
|
||||||
void readTemperature();
|
|
||||||
bool findSensor();
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
void publishHomeAssistantAutodiscovery();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/*
|
|
||||||
* API calls te enable data exchange between WLED modules
|
|
||||||
*/
|
|
||||||
inline float getTemperatureC() { return temperature; }
|
|
||||||
inline float getTemperatureF() { return temperature * 1.8f + 32.0f; }
|
|
||||||
float getTemperature();
|
|
||||||
const char *getTemperatureUnit();
|
|
||||||
uint16_t getId() { return USERMOD_ID_TEMPERATURE; }
|
|
||||||
|
|
||||||
void setup();
|
|
||||||
void loop();
|
|
||||||
//void connected();
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
void onMqttConnect(bool sessionPresent);
|
|
||||||
#endif
|
|
||||||
//void onUpdateBegin(bool init);
|
|
||||||
|
|
||||||
//bool handleButton(uint8_t b);
|
|
||||||
//void handleOverlayDraw();
|
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject& root);
|
|
||||||
//void addToJsonState(JsonObject &root);
|
|
||||||
//void readFromJsonState(JsonObject &root);
|
|
||||||
void addToConfig(JsonObject &root);
|
|
||||||
bool readFromConfig(JsonObject &root);
|
|
||||||
|
|
||||||
void appendConfigData();
|
|
||||||
};
|
|
||||||
|
|
||||||
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
|
||||||
float UsermodTemperature::readDallas() {
|
|
||||||
byte data[9];
|
byte data[9];
|
||||||
int16_t result; // raw data from sensor
|
int16_t result; // raw data from sensor
|
||||||
float retVal = -127.0f;
|
float retVal = -127.0f;
|
||||||
@ -132,18 +90,16 @@ float UsermodTemperature::readDallas() {
|
|||||||
return data[0]==0xFF ? -127.0f : retVal;
|
return data[0]==0xFF ? -127.0f : retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsermodTemperature::requestTemperatures() {
|
void requestTemperatures() {
|
||||||
DEBUG_PRINTLN(F("Requesting temperature."));
|
DEBUG_PRINTLN(F("Requesting temperature."));
|
||||||
oneWire->reset();
|
oneWire->reset();
|
||||||
oneWire->skip(); // skip ROM
|
oneWire->skip(); // skip ROM
|
||||||
oneWire->write(0x44,parasite); // request new temperature reading
|
oneWire->write(0x44,parasite); // request new temperature reading (TODO: parasite would need special handling)
|
||||||
if (parasite && parasitePin >=0 ) digitalWrite(parasitePin, HIGH); // has to happen within 10us (open MOSFET)
|
|
||||||
lastTemperaturesRequest = millis();
|
lastTemperaturesRequest = millis();
|
||||||
waitingForConversion = true;
|
waitingForConversion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsermodTemperature::readTemperature() {
|
void readTemperature() {
|
||||||
if (parasite && parasitePin >=0 ) digitalWrite(parasitePin, LOW); // deactivate power (close MOSFET)
|
|
||||||
temperature = readDallas();
|
temperature = readDallas();
|
||||||
lastMeasurement = millis();
|
lastMeasurement = millis();
|
||||||
waitingForConversion = false;
|
waitingForConversion = false;
|
||||||
@ -152,7 +108,7 @@ void UsermodTemperature::readTemperature() {
|
|||||||
DEBUG_PRINTLN(temperature);
|
DEBUG_PRINTLN(temperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UsermodTemperature::findSensor() {
|
bool findSensor() {
|
||||||
DEBUG_PRINTLN(F("Searching for sensor..."));
|
DEBUG_PRINTLN(F("Searching for sensor..."));
|
||||||
uint8_t deviceAddress[8] = {0,0,0,0,0,0,0,0};
|
uint8_t deviceAddress[8] = {0,0,0,0,0,0,0,0};
|
||||||
// find out if we have DS18xxx sensor attached
|
// find out if we have DS18xxx sensor attached
|
||||||
@ -178,8 +134,7 @@ bool UsermodTemperature::findSensor() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
void publishHomeAssistantAutodiscovery() {
|
||||||
void UsermodTemperature::publishHomeAssistantAutodiscovery() {
|
|
||||||
if (!WLED_MQTT_CONNECTED) return;
|
if (!WLED_MQTT_CONNECTED) return;
|
||||||
|
|
||||||
char json_str[1024], buf[128];
|
char json_str[1024], buf[128];
|
||||||
@ -200,9 +155,10 @@ void UsermodTemperature::publishHomeAssistantAutodiscovery() {
|
|||||||
mqtt->publish(buf, 0, true, json_str, payload_size);
|
mqtt->publish(buf, 0, true, json_str, payload_size);
|
||||||
HApublished = true;
|
HApublished = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void UsermodTemperature::setup() {
|
public:
|
||||||
|
|
||||||
|
void setup() {
|
||||||
int retries = 10;
|
int retries = 10;
|
||||||
sensorFound = 0;
|
sensorFound = 0;
|
||||||
temperature = -127.0f; // default to -127, DS18B20 only goes down to -50C
|
temperature = -127.0f; // default to -127, DS18B20 only goes down to -50C
|
||||||
@ -217,12 +173,6 @@ void UsermodTemperature::setup() {
|
|||||||
delay(25); // try to find sensor
|
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 {
|
} else {
|
||||||
if (temperaturePin >= 0) {
|
if (temperaturePin >= 0) {
|
||||||
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
|
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
|
||||||
@ -234,7 +184,7 @@ void UsermodTemperature::setup() {
|
|||||||
initDone = true;
|
initDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsermodTemperature::loop() {
|
void loop() {
|
||||||
if (!enabled || !sensorFound || strip.isUpdating()) return;
|
if (!enabled || !sensorFound || strip.isUpdating()) return;
|
||||||
|
|
||||||
static uint8_t errorCount = 0;
|
static uint8_t errorCount = 0;
|
||||||
@ -262,7 +212,6 @@ void UsermodTemperature::loop() {
|
|||||||
}
|
}
|
||||||
errorCount = 0;
|
errorCount = 0;
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
if (WLED_MQTT_CONNECTED) {
|
if (WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
strcpy(subuf, mqttDeviceTopic);
|
strcpy(subuf, mqttDeviceTopic);
|
||||||
@ -278,7 +227,6 @@ void UsermodTemperature::loop() {
|
|||||||
// publish something else to indicate status?
|
// publish something else to indicate status?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,27 +234,35 @@ void UsermodTemperature::loop() {
|
|||||||
* connected() is called every time the WiFi is (re)connected
|
* connected() is called every time the WiFi is (re)connected
|
||||||
* Use it to initialize network interfaces
|
* Use it to initialize network interfaces
|
||||||
*/
|
*/
|
||||||
//void UsermodTemperature::connected() {}
|
//void connected() {}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
/**
|
/**
|
||||||
* subscribe to MQTT topic if needed
|
* subscribe to MQTT topic if needed
|
||||||
*/
|
*/
|
||||||
void UsermodTemperature::onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
//(re)subscribe to required topics
|
//(re)subscribe to required topics
|
||||||
//char subuf[64];
|
//char subuf[64];
|
||||||
if (mqttDeviceTopic[0] != 0) {
|
if (mqttDeviceTopic[0] != 0) {
|
||||||
publishHomeAssistantAutodiscovery();
|
publishHomeAssistantAutodiscovery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
/*
|
||||||
|
* API calls te enable data exchange between WLED modules
|
||||||
|
*/
|
||||||
|
inline float getTemperatureC() {
|
||||||
|
return (float)temperature;
|
||||||
|
}
|
||||||
|
inline float getTemperatureF() {
|
||||||
|
return (float)temperature * 1.8f + 32;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
* 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.
|
* 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
|
* Below it is shown how this could be used for e.g. a light sensor
|
||||||
*/
|
*/
|
||||||
void UsermodTemperature::addToJsonInfo(JsonObject& root) {
|
void addToJsonInfo(JsonObject& root) {
|
||||||
// dont add temperature to info if we are disabled
|
// dont add temperature to info if we are disabled
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
|
|
||||||
@ -321,21 +277,21 @@ void UsermodTemperature::addToJsonInfo(JsonObject& root) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp.add(getTemperature());
|
temp.add(degC ? getTemperatureC() : getTemperatureF());
|
||||||
temp.add(getTemperatureUnit());
|
temp.add(degC ? F("°C") : F("°F"));
|
||||||
|
|
||||||
JsonObject sensor = root[F("sensor")];
|
JsonObject sensor = root[F("sensor")];
|
||||||
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
|
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
|
||||||
temp = sensor.createNestedArray(F("temperature"));
|
temp = sensor.createNestedArray(F("temp"));
|
||||||
temp.add(getTemperature());
|
temp.add(degC ? temperature : (float)temperature * 1.8f + 32);
|
||||||
temp.add(getTemperatureUnit());
|
temp.add(degC ? F("°C") : F("°F"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
* 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
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
//void UsermodTemperature::addToJsonState(JsonObject &root)
|
//void addToJsonState(JsonObject &root)
|
||||||
//{
|
//{
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@ -344,14 +300,14 @@ void UsermodTemperature::addToJsonInfo(JsonObject& root) {
|
|||||||
* Values in the state object may be modified by connected clients
|
* Values in the state object may be modified by connected clients
|
||||||
* Read "<usermodname>_<usermodparam>" from json state and and change settings (i.e. GPIO pin) used.
|
* Read "<usermodname>_<usermodparam>" from json state and and change settings (i.e. GPIO pin) used.
|
||||||
*/
|
*/
|
||||||
//void UsermodTemperature::readFromJsonState(JsonObject &root) {
|
//void readFromJsonState(JsonObject &root) {
|
||||||
// if (!initDone) return; // prevent crash on boot applyPreset()
|
// if (!initDone) return; // prevent crash on boot applyPreset()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
||||||
*/
|
*/
|
||||||
void UsermodTemperature::addToConfig(JsonObject &root) {
|
void addToConfig(JsonObject &root) {
|
||||||
// we add JSON object: {"Temperature": {"pin": 0, "degC": true}}
|
// we add JSON object: {"Temperature": {"pin": 0, "degC": true}}
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
||||||
top[FPSTR(_enabled)] = enabled;
|
top[FPSTR(_enabled)] = enabled;
|
||||||
@ -359,7 +315,6 @@ void UsermodTemperature::addToConfig(JsonObject &root) {
|
|||||||
top["degC"] = degC; // usermodparam
|
top["degC"] = degC; // usermodparam
|
||||||
top[FPSTR(_readInterval)] = readingInterval / 1000;
|
top[FPSTR(_readInterval)] = readingInterval / 1000;
|
||||||
top[FPSTR(_parasite)] = parasite;
|
top[FPSTR(_parasite)] = parasite;
|
||||||
top[FPSTR(_parasitePin)] = parasitePin;
|
|
||||||
DEBUG_PRINTLN(F("Temperature config saved."));
|
DEBUG_PRINTLN(F("Temperature config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +323,7 @@ void UsermodTemperature::addToConfig(JsonObject &root) {
|
|||||||
*
|
*
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
||||||
*/
|
*/
|
||||||
bool UsermodTemperature::readFromConfig(JsonObject &root) {
|
bool readFromConfig(JsonObject &root) {
|
||||||
// we look for JSON object: {"Temperature": {"pin": 0, "degC": true}}
|
// we look for JSON object: {"Temperature": {"pin": 0, "degC": true}}
|
||||||
int8_t newTemperaturePin = temperaturePin;
|
int8_t newTemperaturePin = temperaturePin;
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
@ -385,7 +340,6 @@ bool UsermodTemperature::readFromConfig(JsonObject &root) {
|
|||||||
readingInterval = top[FPSTR(_readInterval)] | readingInterval/1000;
|
readingInterval = top[FPSTR(_readInterval)] | readingInterval/1000;
|
||||||
readingInterval = min(120,max(10,(int)readingInterval)) * 1000; // convert to ms
|
readingInterval = min(120,max(10,(int)readingInterval)) * 1000; // convert to ms
|
||||||
parasite = top[FPSTR(_parasite)] | parasite;
|
parasite = top[FPSTR(_parasite)] | parasite;
|
||||||
parasitePin = top[FPSTR(_parasitePin)] | parasitePin;
|
|
||||||
|
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
// first run: reading from cfg.json
|
// first run: reading from cfg.json
|
||||||
@ -400,33 +354,22 @@ bool UsermodTemperature::readFromConfig(JsonObject &root) {
|
|||||||
delete oneWire;
|
delete oneWire;
|
||||||
pinManager.deallocatePin(temperaturePin, PinOwner::UM_Temperature);
|
pinManager.deallocatePin(temperaturePin, PinOwner::UM_Temperature);
|
||||||
temperaturePin = newTemperaturePin;
|
temperaturePin = newTemperaturePin;
|
||||||
pinManager.deallocatePin(parasitePin, PinOwner::UM_Temperature);
|
|
||||||
// initialise
|
// initialise
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return !top[FPSTR(_parasitePin)].isNull();
|
return !top[FPSTR(_parasite)].isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsermodTemperature::appendConfigData() {
|
uint16_t getId()
|
||||||
oappend(SET_F("addInfo('")); oappend(String(FPSTR(_name)).c_str()); oappend(SET_F(":")); oappend(String(FPSTR(_parasite)).c_str());
|
{
|
||||||
oappend(SET_F("',1,'<i>(if no Vcc connected)</i>');")); // 0 is field type, 1 is actual field
|
return USERMOD_ID_TEMPERATURE;
|
||||||
oappend(SET_F("addInfo('")); oappend(String(FPSTR(_name)).c_str()); oappend(SET_F(":")); oappend(String(FPSTR(_parasitePin)).c_str());
|
|
||||||
oappend(SET_F("',1,'<i>(for external MOSFET)</i>');")); // 0 is field type, 1 is actual field
|
|
||||||
}
|
|
||||||
|
|
||||||
float UsermodTemperature::getTemperature() {
|
|
||||||
return degC ? getTemperatureC() : getTemperatureF();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *UsermodTemperature::getTemperatureUnit() {
|
|
||||||
return degC ? "°C" : "°F";
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
const char UsermodTemperature::_name[] PROGMEM = "Temperature";
|
const char UsermodTemperature::_name[] PROGMEM = "Temperature";
|
||||||
const char UsermodTemperature::_enabled[] PROGMEM = "enabled";
|
const char UsermodTemperature::_enabled[] PROGMEM = "enabled";
|
||||||
const char UsermodTemperature::_readInterval[] PROGMEM = "read-interval-s";
|
const char UsermodTemperature::_readInterval[] PROGMEM = "read-interval-s";
|
||||||
const char UsermodTemperature::_parasite[] PROGMEM = "parasite-pwr";
|
const char UsermodTemperature::_parasite[] PROGMEM = "parasite-pwr";
|
||||||
const char UsermodTemperature::_parasitePin[] PROGMEM = "parasite-pwr-pin";
|
|
||||||
|
31
usermods/Temperature/usermods_list.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "wled.h"
|
||||||
|
/*
|
||||||
|
* Register your v2 usermods here!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add/uncomment your usermod filename here (and once more below)
|
||||||
|
* || || ||
|
||||||
|
* \/ \/ \/
|
||||||
|
*/
|
||||||
|
//#include "usermod_v2_example.h"
|
||||||
|
#ifdef USERMOD_DALLASTEMPERATURE
|
||||||
|
#include "../usermods/Temperature/usermod_temperature.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#include "usermod_v2_empty.h"
|
||||||
|
|
||||||
|
void registerUsermods()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Add your usermod class name here
|
||||||
|
* || || ||
|
||||||
|
* \/ \/ \/
|
||||||
|
*/
|
||||||
|
//usermods.add(new MyExampleUsermod());
|
||||||
|
#ifdef USERMOD_DALLASTEMPERATURE
|
||||||
|
usermods.add(new UsermodTemperature());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//usermods.add(new UsermodRenameMe());
|
||||||
|
}
|
@ -50,7 +50,9 @@ class UsermodVL53L0XGestures : public Usermod {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
if (i2c_scl<0 || i2c_sda<0) { 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);
|
sensor.setTimeout(150);
|
||||||
if (!sensor.init())
|
if (!sensor.init())
|
||||||
|
@ -101,7 +101,6 @@ void userLoop() {
|
|||||||
if (temptimer - lastMeasure > 60000)
|
if (temptimer - lastMeasure > 60000)
|
||||||
{
|
{
|
||||||
lastMeasure = temptimer;
|
lastMeasure = temptimer;
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (mqtt != nullptr)
|
if (mqtt != nullptr)
|
||||||
{
|
{
|
||||||
@ -117,7 +116,6 @@ void userLoop() {
|
|||||||
t += "/temperature";
|
t += "/temperature";
|
||||||
mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str());
|
mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we time interval for redrawing passes.
|
// Check if we time interval for redrawing passes.
|
||||||
|
@ -103,7 +103,6 @@ void userLoop() {
|
|||||||
{
|
{
|
||||||
lastMeasure = tempTimer;
|
lastMeasure = tempTimer;
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
// Check if MQTT Connected, otherwise it will crash the 8266
|
// Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (mqtt != nullptr)
|
if (mqtt != nullptr)
|
||||||
{
|
{
|
||||||
@ -123,7 +122,6 @@ void userLoop() {
|
|||||||
h += "/humidity";
|
h += "/humidity";
|
||||||
mqtt->publish(h.c_str(), 0, true, String(board_humidity).c_str());
|
mqtt->publish(h.c_str(), 0, true, String(board_humidity).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we time interval for redrawing passes.
|
// Check if we time interval for redrawing passes.
|
||||||
|
@ -20,12 +20,6 @@
|
|||||||
* ....
|
* ....
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(FFTTASK_PRIORITY)
|
|
||||||
#define FFTTASK_PRIORITY 1 // standard: looptask prio
|
|
||||||
//#define FFTTASK_PRIORITY 2 // above looptask, below asyc_tcp
|
|
||||||
//#define FFTTASK_PRIORITY 4 // above asyc_tcp
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Comment/Uncomment to toggle usb serial debugging
|
// Comment/Uncomment to toggle usb serial debugging
|
||||||
// #define MIC_LOGGER // MIC sampling & sound input debugging (serial plotter)
|
// #define MIC_LOGGER // MIC sampling & sound input debugging (serial plotter)
|
||||||
// #define FFT_SAMPLING_LOG // FFT result debugging
|
// #define FFT_SAMPLING_LOG // FFT result debugging
|
||||||
@ -110,7 +104,7 @@ static float sampleAgc = 0.0f; // Smoothed AGC sample
|
|||||||
|
|
||||||
// peak detection
|
// 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 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 = 31; // Reasonable value for constant volume for 'peak detector', as it won't always trigger (deprecated)
|
static uint8_t maxVol = 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 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 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 unsigned long timeOfPeak = 0; // time of last sample peak detection.
|
||||||
@ -180,17 +174,12 @@ static float windowWeighingFactors[samplesFFT] = {0.0f};
|
|||||||
// Create FFT object
|
// Create FFT object
|
||||||
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
||||||
// lib_deps += https://github.com/kosme/arduinoFFT#develop @ 1.9.2
|
// lib_deps += https://github.com/kosme/arduinoFFT#develop @ 1.9.2
|
||||||
// these options actually cause slow-downs on all esp32 processors, don't use them.
|
#define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc), and an a few other speedups
|
||||||
// #define FFT_SPEED_OVER_PRECISION // enables use of reciprocals (1/x etc) - not faster on ESP32
|
#define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt
|
||||||
// #define FFT_SQRT_APPROXIMATION // enables "quake3" style inverse sqrt - slower on ESP32
|
#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 50% on ESP32 (as alternative to FFT_SQRT_APPROXIMATION)
|
||||||
// Below options are forcing ArduinoFFT to use sqrtf() instead of sqrt()
|
|
||||||
#define sqrt(x) sqrtf(x) // little hack that reduces FFT time by 10-50% on ESP32
|
|
||||||
#define sqrt_internal sqrtf // see https://github.com/kosme/arduinoFFT/pull/83
|
|
||||||
#else
|
#else
|
||||||
// around 40% slower on -S2
|
|
||||||
// lib_deps += https://github.com/blazoncek/arduinoFFT.git
|
// lib_deps += https://github.com/blazoncek/arduinoFFT.git
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <arduinoFFT.h>
|
#include <arduinoFFT.h>
|
||||||
|
|
||||||
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
#ifdef UM_AUDIOREACTIVE_USE_NEW_FFT
|
||||||
@ -422,7 +411,7 @@ static void runMicFilter(uint16_t numSamples, float *sampleBuffer) // p
|
|||||||
//constexpr float beta1 = 0.8285f; // 18Khz
|
//constexpr float beta1 = 0.8285f; // 18Khz
|
||||||
constexpr float beta1 = 0.85f; // 20Khz
|
constexpr float beta1 = 0.85f; // 20Khz
|
||||||
|
|
||||||
constexpr float beta2 = (1.0f - beta1) / 2.0f;
|
constexpr float beta2 = (1.0f - beta1) / 2.0;
|
||||||
static float last_vals[2] = { 0.0f }; // FIR high freq cutoff filter
|
static float last_vals[2] = { 0.0f }; // FIR high freq cutoff filter
|
||||||
static float lowfilt = 0.0f; // IIR low frequency cutoff filter
|
static float lowfilt = 0.0f; // IIR low frequency cutoff filter
|
||||||
|
|
||||||
@ -475,17 +464,17 @@ static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels) // p
|
|||||||
switch (FFTScalingMode) {
|
switch (FFTScalingMode) {
|
||||||
case 1:
|
case 1:
|
||||||
// Logarithmic scaling
|
// Logarithmic scaling
|
||||||
currentResult *= 0.42f; // 42 is the answer ;-)
|
currentResult *= 0.42; // 42 is the answer ;-)
|
||||||
currentResult -= 8.0f; // this skips the lowest row, giving some room for peaks
|
currentResult -= 8.0; // this skips the lowest row, giving some room for peaks
|
||||||
if (currentResult > 1.0f) currentResult = logf(currentResult); // log to base "e", which is the fastest log() function
|
if (currentResult > 1.0) currentResult = logf(currentResult); // log to base "e", which is the fastest log() function
|
||||||
else currentResult = 0.0f; // special handling, because log(1) = 0; log(0) = undefined
|
else currentResult = 0.0; // special handling, because log(1) = 0; log(0) = undefined
|
||||||
currentResult *= 0.85f + (float(i)/18.0f); // extra up-scaling for high frequencies
|
currentResult *= 0.85f + (float(i)/18.0f); // extra up-scaling for high frequencies
|
||||||
currentResult = mapf(currentResult, 0, LOG_256, 0, 255); // map [log(1) ... log(255)] to [0 ... 255]
|
currentResult = mapf(currentResult, 0, LOG_256, 0, 255); // map [log(1) ... log(255)] to [0 ... 255]
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Linear scaling
|
// Linear scaling
|
||||||
currentResult *= 0.30f; // needs a bit more damping, get stay below 255
|
currentResult *= 0.30f; // needs a bit more damping, get stay below 255
|
||||||
currentResult -= 4.0f; // giving a bit more room for peaks
|
currentResult -= 4.0; // giving a bit more room for peaks
|
||||||
if (currentResult < 1.0f) currentResult = 0.0f;
|
if (currentResult < 1.0f) currentResult = 0.0f;
|
||||||
currentResult *= 0.85f + (float(i)/1.8f); // extra up-scaling for high frequencies
|
currentResult *= 0.85f + (float(i)/1.8f); // extra up-scaling for high frequencies
|
||||||
break;
|
break;
|
||||||
@ -493,8 +482,8 @@ static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels) // p
|
|||||||
// square root scaling
|
// square root scaling
|
||||||
currentResult *= 0.38f;
|
currentResult *= 0.38f;
|
||||||
currentResult -= 6.0f;
|
currentResult -= 6.0f;
|
||||||
if (currentResult > 1.0f) currentResult = sqrtf(currentResult);
|
if (currentResult > 1.0) currentResult = sqrtf(currentResult);
|
||||||
else currentResult = 0.0f; // special handling, because sqrt(0) = undefined
|
else currentResult = 0.0; // special handling, because sqrt(0) = undefined
|
||||||
currentResult *= 0.85f + (float(i)/4.5f); // extra up-scaling for high frequencies
|
currentResult *= 0.85f + (float(i)/4.5f); // extra up-scaling for high frequencies
|
||||||
currentResult = mapf(currentResult, 0.0, 16.0, 0.0, 255.0); // map [sqrt(1) ... sqrt(256)] to [0 ... 255]
|
currentResult = mapf(currentResult, 0.0, 16.0, 0.0, 255.0); // map [sqrt(1) ... sqrt(256)] to [0 ... 255]
|
||||||
break;
|
break;
|
||||||
@ -522,11 +511,11 @@ static void postProcessFFTResults(bool noiseGateOpen, int numberOfChannels) // p
|
|||||||
// peak detection is called from FFT task when vReal[] contains valid FFT results
|
// peak detection is called from FFT task when vReal[] contains valid FFT results
|
||||||
static void detectSamplePeak(void) {
|
static void detectSamplePeak(void) {
|
||||||
bool havePeak = false;
|
bool havePeak = false;
|
||||||
// softhack007: this code continuously triggers while amplitude in the selected bin is above a certain threshold. So it does not detect peaks - it detects high activity in a frequency bin.
|
|
||||||
// Poor man's beat detection by seeing if sample > Average + some value.
|
// Poor man's beat detection by seeing if sample > Average + some value.
|
||||||
// This goes through ALL of the 255 bins - but ignores stupid settings
|
// 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.
|
// 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 > 4) && (vReal[binNum] > maxVol) && ((millis() - timeOfPeak) > 100)) {
|
if ((sampleAvg > 1) && (maxVol > 0) && (binNum > 1) && (vReal[binNum] > maxVol) && ((millis() - timeOfPeak) > 100)) {
|
||||||
havePeak = true;
|
havePeak = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,6 +569,16 @@ class AudioReactive : public Usermod {
|
|||||||
#else
|
#else
|
||||||
int8_t i2sckPin = I2S_CKPIN;
|
int8_t i2sckPin = I2S_CKPIN;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ES7243_SDAPIN
|
||||||
|
int8_t sdaPin = -1;
|
||||||
|
#else
|
||||||
|
int8_t sdaPin = ES7243_SDAPIN;
|
||||||
|
#endif
|
||||||
|
#ifndef ES7243_SCLPIN
|
||||||
|
int8_t sclPin = -1;
|
||||||
|
#else
|
||||||
|
int8_t sclPin = ES7243_SCLPIN;
|
||||||
|
#endif
|
||||||
#ifndef MCLK_PIN
|
#ifndef MCLK_PIN
|
||||||
int8_t mclkPin = I2S_PIN_NO_CHANGE; /* ESP32: only -1, 0, 1, 3 allowed*/
|
int8_t mclkPin = I2S_PIN_NO_CHANGE; /* ESP32: only -1, 0, 1, 3 allowed*/
|
||||||
#else
|
#else
|
||||||
@ -769,7 +768,7 @@ class AudioReactive : public Usermod {
|
|||||||
if (time_now - last_time > 2) {
|
if (time_now - last_time > 2) {
|
||||||
last_time = time_now;
|
last_time = time_now;
|
||||||
|
|
||||||
if((fabsf(sampleReal) < 2.0f) || (sampleMax < 1.0)) {
|
if((fabsf(sampleReal) < 2.0f) || (sampleMax < 1.0f)) {
|
||||||
// MIC signal is "squelched" - deliver silence
|
// MIC signal is "squelched" - deliver silence
|
||||||
tmpAgc = 0;
|
tmpAgc = 0;
|
||||||
// we need to "spin down" the intgrated error buffer
|
// we need to "spin down" the intgrated error buffer
|
||||||
@ -884,8 +883,8 @@ class AudioReactive : public Usermod {
|
|||||||
// keep "peak" sample, but decay value if current sample is below peak
|
// keep "peak" sample, but decay value if current sample is below peak
|
||||||
if ((sampleMax < sampleReal) && (sampleReal > 0.5f)) {
|
if ((sampleMax < sampleReal) && (sampleReal > 0.5f)) {
|
||||||
sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // new peak - with some filtering
|
sampleMax = sampleMax + 0.5f * (sampleReal - sampleMax); // new peak - with some filtering
|
||||||
// another simple way to detect samplePeak - cannot detect beats, but reacts on peak volume
|
// another simple way to detect samplePeak
|
||||||
if (((binNum < 12) || ((maxVol < 1))) && (millis() - timeOfPeak > 80) && (sampleAvg > 1)) {
|
if ((binNum < 10) && (millis() - timeOfPeak > 80) && (sampleAvg > 1)) {
|
||||||
samplePeak = true;
|
samplePeak = true;
|
||||||
timeOfPeak = millis();
|
timeOfPeak = millis();
|
||||||
udpSamplePeak = true;
|
udpSamplePeak = true;
|
||||||
@ -960,8 +959,6 @@ class AudioReactive : public Usermod {
|
|||||||
//DEBUGSR_PRINTLN("Transmitting UDP Mic Packet");
|
//DEBUGSR_PRINTLN("Transmitting UDP Mic Packet");
|
||||||
|
|
||||||
audioSyncPacket transmitData;
|
audioSyncPacket transmitData;
|
||||||
memset(reinterpret_cast<void *>(&transmitData), 0, sizeof(transmitData)); // make sure that the packet - including "invisible" padding bytes added by the compiler - is fully initialized
|
|
||||||
|
|
||||||
strncpy_P(transmitData.header, PSTR(UDP_SYNC_HEADER), 6);
|
strncpy_P(transmitData.header, PSTR(UDP_SYNC_HEADER), 6);
|
||||||
// transmit samples that were not modified by limitSampleDynamics()
|
// transmit samples that were not modified by limitSampleDynamics()
|
||||||
transmitData.sampleRaw = (soundAgc) ? rawSampleAgc: sampleRaw;
|
transmitData.sampleRaw = (soundAgc) ? rawSampleAgc: sampleRaw;
|
||||||
@ -977,10 +974,9 @@ class AudioReactive : public Usermod {
|
|||||||
transmitData.FFT_Magnitude = my_magnitude;
|
transmitData.FFT_Magnitude = my_magnitude;
|
||||||
transmitData.FFT_MajorPeak = FFT_MajorPeak;
|
transmitData.FFT_MajorPeak = FFT_MajorPeak;
|
||||||
|
|
||||||
if (fftUdp.beginMulticastPacket() != 0) { // beginMulticastPacket returns 0 in case of error
|
fftUdp.beginMulticastPacket();
|
||||||
fftUdp.write(reinterpret_cast<uint8_t *>(&transmitData), sizeof(transmitData));
|
fftUdp.write(reinterpret_cast<uint8_t *>(&transmitData), sizeof(transmitData));
|
||||||
fftUdp.endPacket();
|
fftUdp.endPacket();
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
} // transmitAudioData()
|
} // transmitAudioData()
|
||||||
|
|
||||||
@ -1140,7 +1136,7 @@ class AudioReactive : public Usermod {
|
|||||||
DEBUGSR_PRINTLN(F("AR: ES7243 Microphone (right channel only)."));
|
DEBUGSR_PRINTLN(F("AR: ES7243 Microphone (right channel only)."));
|
||||||
audioSource = new ES7243(SAMPLE_RATE, BLOCK_SIZE);
|
audioSource = new ES7243(SAMPLE_RATE, BLOCK_SIZE);
|
||||||
delay(100);
|
delay(100);
|
||||||
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
if (audioSource) audioSource->initialize(sdaPin, sclPin, i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
DEBUGSR_PRINT(F("AR: SPH0645 Microphone - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT));
|
DEBUGSR_PRINT(F("AR: SPH0645 Microphone - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT));
|
||||||
@ -1163,13 +1159,6 @@ class AudioReactive : public Usermod {
|
|||||||
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin);
|
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 6:
|
|
||||||
DEBUGSR_PRINTLN(F("AR: ES8388 Source"));
|
|
||||||
audioSource = new ES8388Source(SAMPLE_RATE, BLOCK_SIZE);
|
|
||||||
delay(100);
|
|
||||||
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
// ADC over I2S is only possible on "classic" ESP32
|
// ADC over I2S is only possible on "classic" ESP32
|
||||||
case 0:
|
case 0:
|
||||||
@ -1177,7 +1166,6 @@ class AudioReactive : public Usermod {
|
|||||||
DEBUGSR_PRINTLN(F("AR: Analog Microphone (left channel only)."));
|
DEBUGSR_PRINTLN(F("AR: Analog Microphone (left channel only)."));
|
||||||
audioSource = new I2SAdcSource(SAMPLE_RATE, BLOCK_SIZE);
|
audioSource = new I2SAdcSource(SAMPLE_RATE, BLOCK_SIZE);
|
||||||
delay(100);
|
delay(100);
|
||||||
useBandPassFilter = true; // PDM bandpass filter seems to help for bad quality analog
|
|
||||||
if (audioSource) audioSource->initialize(audioPin);
|
if (audioSource) audioSource->initialize(audioPin);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -1287,10 +1275,9 @@ class AudioReactive : public Usermod {
|
|||||||
|
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
// complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second.
|
// complain when audio userloop has been delayed for long time. Currently we need userloop running between 500 and 1500 times per second.
|
||||||
// softhack007 disabled temporarily - avoid serial console spam with MANY leds and low FPS
|
if ((userloopDelay > 23) && !disableSoundProcessing && (audioSyncEnabled == 0)) {
|
||||||
//if ((userloopDelay > 65) && !disableSoundProcessing && (audioSyncEnabled == 0)) {
|
DEBUG_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay);
|
||||||
//DEBUG_PRINTF("[AR userLoop] hickup detected -> was inactive for last %d millis!\n", userloopDelay);
|
}
|
||||||
//}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// run filters, and repeat in case of loop delays (hick-up compensation)
|
// run filters, and repeat in case of loop delays (hick-up compensation)
|
||||||
@ -1327,9 +1314,6 @@ class AudioReactive : public Usermod {
|
|||||||
if (millis() - lastTime > delayMs) {
|
if (millis() - lastTime > delayMs) {
|
||||||
have_new_sample = receiveAudioData();
|
have_new_sample = receiveAudioData();
|
||||||
if (have_new_sample) last_UDPTime = millis();
|
if (have_new_sample) last_UDPTime = millis();
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
else fftUdp.flush(); // Flush udp input buffers if we haven't read it - avoids hickups in receive mode. Does not work on 8266.
|
|
||||||
#endif
|
|
||||||
lastTime = millis();
|
lastTime = millis();
|
||||||
}
|
}
|
||||||
if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample
|
if (have_new_sample) syncVolumeSmth = volumeSmth; // remember received sample
|
||||||
@ -1348,7 +1332,7 @@ class AudioReactive : public Usermod {
|
|||||||
// Info Page: keep max sample from last 5 seconds
|
// Info Page: keep max sample from last 5 seconds
|
||||||
if ((millis() - sampleMaxTimer) > CYCLE_SAMPLEMAX) {
|
if ((millis() - sampleMaxTimer) > CYCLE_SAMPLEMAX) {
|
||||||
sampleMaxTimer = millis();
|
sampleMaxTimer = millis();
|
||||||
maxSample5sec = (0.15f * maxSample5sec) + 0.85f *((soundAgc) ? sampleAgc : sampleAvg); // reset, and start with some smoothing
|
maxSample5sec = (0.15 * maxSample5sec) + 0.85 *((soundAgc) ? sampleAgc : sampleAvg); // reset, and start with some smoothing
|
||||||
if (sampleAvg < 1) maxSample5sec = 0; // noise gate
|
if (sampleAvg < 1) maxSample5sec = 0; // noise gate
|
||||||
} else {
|
} else {
|
||||||
if ((sampleAvg >= 1)) maxSample5sec = fmaxf(maxSample5sec, (soundAgc) ? rawSampleAgc : sampleRaw); // follow maximum volume
|
if ((sampleAvg >= 1)) maxSample5sec = fmaxf(maxSample5sec, (soundAgc) ? rawSampleAgc : sampleRaw); // follow maximum volume
|
||||||
@ -1392,11 +1376,10 @@ class AudioReactive : public Usermod {
|
|||||||
memset(fftAvg, 0, sizeof(fftAvg));
|
memset(fftAvg, 0, sizeof(fftAvg));
|
||||||
memset(fftResult, 0, sizeof(fftResult));
|
memset(fftResult, 0, sizeof(fftResult));
|
||||||
for(int i=(init?0:1); i<NUM_GEQ_CHANNELS; i+=2) fftResult[i] = 16; // make a tiny pattern
|
for(int i=(init?0:1); i<NUM_GEQ_CHANNELS; i+=2) fftResult[i] = 16; // make a tiny pattern
|
||||||
inputLevel = 128; // reset level slider to default
|
inputLevel = 128; // resset level slider to default
|
||||||
autoResetPeak();
|
autoResetPeak();
|
||||||
|
|
||||||
if (init && FFT_Task) {
|
if (init && FFT_Task) {
|
||||||
delay(25); // give some time for I2S driver to finish sampling before we suspend it
|
|
||||||
vTaskSuspend(FFT_Task); // update is about to begin, disable task to prevent crash
|
vTaskSuspend(FFT_Task); // update is about to begin, disable task to prevent crash
|
||||||
if (udpSyncConnected) { // close UDP sync connection (if open)
|
if (udpSyncConnected) { // close UDP sync connection (if open)
|
||||||
udpSyncConnected = false;
|
udpSyncConnected = false;
|
||||||
@ -1408,14 +1391,15 @@ class AudioReactive : public Usermod {
|
|||||||
vTaskResume(FFT_Task);
|
vTaskResume(FFT_Task);
|
||||||
connected(); // resume UDP
|
connected(); // resume UDP
|
||||||
} else
|
} else
|
||||||
xTaskCreateUniversal( // xTaskCreateUniversal also works on -S2 and -C3 with single core
|
// xTaskCreatePinnedToCore(
|
||||||
|
xTaskCreate( // no need to "pin" this task to core #0
|
||||||
FFTcode, // Function to implement the task
|
FFTcode, // Function to implement the task
|
||||||
"FFT", // Name of the task
|
"FFT", // Name of the task
|
||||||
3592, // Stack size in words // 3592 leaves 800-1024 bytes of task stack free
|
5000, // Stack size in words
|
||||||
NULL, // Task input parameter
|
NULL, // Task input parameter
|
||||||
FFTTASK_PRIORITY, // Priority of the task
|
1, // Priority of the task
|
||||||
&FFT_Task // Task handle
|
&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
|
micDataReal = 0.0f; // just to be sure
|
||||||
@ -1512,7 +1496,7 @@ class AudioReactive : public Usermod {
|
|||||||
infoArr.add(F("I2S digital"));
|
infoArr.add(F("I2S digital"));
|
||||||
}
|
}
|
||||||
// input level or "silence"
|
// input level or "silence"
|
||||||
if (maxSample5sec > 1.0f) {
|
if (maxSample5sec > 1.0) {
|
||||||
float my_usage = 100.0f * (maxSample5sec / 255.0f);
|
float my_usage = 100.0f * (maxSample5sec / 255.0f);
|
||||||
snprintf_P(myStringBuffer, 15, PSTR(" - peak %3d%%"), int(my_usage));
|
snprintf_P(myStringBuffer, 15, PSTR(" - peak %3d%%"), int(my_usage));
|
||||||
infoArr.add(myStringBuffer);
|
infoArr.add(myStringBuffer);
|
||||||
@ -1522,7 +1506,7 @@ class AudioReactive : public Usermod {
|
|||||||
} else {
|
} else {
|
||||||
// error during audio source setup
|
// error during audio source setup
|
||||||
infoArr.add(F("not initialized"));
|
infoArr.add(F("not initialized"));
|
||||||
infoArr.add(F(" - check pin settings"));
|
infoArr.add(F(" - check GPIO config"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1673,6 +1657,8 @@ class AudioReactive : public Usermod {
|
|||||||
pinArray.add(i2swsPin);
|
pinArray.add(i2swsPin);
|
||||||
pinArray.add(i2sckPin);
|
pinArray.add(i2sckPin);
|
||||||
pinArray.add(mclkPin);
|
pinArray.add(mclkPin);
|
||||||
|
pinArray.add(sdaPin);
|
||||||
|
pinArray.add(sclPin);
|
||||||
|
|
||||||
JsonObject cfg = top.createNestedObject("config");
|
JsonObject cfg = top.createNestedObject("config");
|
||||||
cfg[F("squelch")] = soundSquelch;
|
cfg[F("squelch")] = soundSquelch;
|
||||||
@ -1733,6 +1719,8 @@ class AudioReactive : public Usermod {
|
|||||||
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][1], i2swsPin);
|
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][1], i2swsPin);
|
||||||
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][2], i2sckPin);
|
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][2], i2sckPin);
|
||||||
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][3], mclkPin);
|
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][3], mclkPin);
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][4], sdaPin);
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][5], sclPin);
|
||||||
|
|
||||||
configComplete &= getJsonValue(top["config"][F("squelch")], soundSquelch);
|
configComplete &= getJsonValue(top["config"][F("squelch")], soundSquelch);
|
||||||
configComplete &= getJsonValue(top["config"][F("gain")], sampleGain);
|
configComplete &= getJsonValue(top["config"][F("gain")], sampleGain);
|
||||||
@ -1764,8 +1752,6 @@ class AudioReactive : public Usermod {
|
|||||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
oappend(SET_F("addOption(dd,'Generic I2S PDM',5);"));
|
oappend(SET_F("addOption(dd,'Generic I2S PDM',5);"));
|
||||||
#endif
|
#endif
|
||||||
oappend(SET_F("addOption(dd,'ES8388',6);"));
|
|
||||||
|
|
||||||
oappend(SET_F("dd=addDropdown('AudioReactive','config:AGC');"));
|
oappend(SET_F("dd=addDropdown('AudioReactive','config:AGC');"));
|
||||||
oappend(SET_F("addOption(dd,'Off',0);"));
|
oappend(SET_F("addOption(dd,'Off',0);"));
|
||||||
oappend(SET_F("addOption(dd,'Normal',1);"));
|
oappend(SET_F("addOption(dd,'Normal',1);"));
|
||||||
@ -1798,6 +1784,8 @@ class AudioReactive : public Usermod {
|
|||||||
#else
|
#else
|
||||||
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>master clock</i>','I2S MCLK');"));
|
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'<i>master clock</i>','I2S MCLK');"));
|
||||||
#endif
|
#endif
|
||||||
|
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'','I2C SDA');"));
|
||||||
|
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'','I2C SCL');"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1826,9 +1814,7 @@ class AudioReactive : public Usermod {
|
|||||||
const char AudioReactive::_name[] PROGMEM = "AudioReactive";
|
const char AudioReactive::_name[] PROGMEM = "AudioReactive";
|
||||||
const char AudioReactive::_enabled[] PROGMEM = "enabled";
|
const char AudioReactive::_enabled[] PROGMEM = "enabled";
|
||||||
const char AudioReactive::_inputLvl[] PROGMEM = "inputLevel";
|
const char AudioReactive::_inputLvl[] PROGMEM = "inputLevel";
|
||||||
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
|
||||||
const char AudioReactive::_analogmic[] PROGMEM = "analogmic";
|
const char AudioReactive::_analogmic[] PROGMEM = "analogmic";
|
||||||
#endif
|
|
||||||
const char AudioReactive::_digitalmic[] PROGMEM = "digitalmic";
|
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[] 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
|
const char AudioReactive::UDP_SYNC_HEADER_v1[] PROGMEM = "00001"; // old sync header version - need to add backwards-compatibility feature
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
|
#include <Wire.h>
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <driver/i2s.h>
|
#include <driver/i2s.h>
|
||||||
#include <driver/adc.h>
|
#include <driver/adc.h>
|
||||||
@ -22,14 +23,14 @@
|
|||||||
|
|
||||||
// see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents
|
// 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
|
// 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_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_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)
|
||||||
// there are two things in these MCUs that could lead to problems with audio processing:
|
// 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)
|
// * 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
|
// * single core, so FFT task might slow down other things like LED updates
|
||||||
#if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1)
|
#if !defined(SOC_I2S_NUM) || (SOC_I2S_NUM < 1)
|
||||||
#error This audio reactive usermod does not support ESP32-C2 or ESP32-C3.
|
#error This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
|
||||||
#else
|
#else
|
||||||
#warning This audio reactive usermod does not support ESP32-C2 and ESP32-C3.
|
#warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -71,7 +72,7 @@
|
|||||||
* if you want to receive two channels, one is the actual data from microphone and another channel is suppose to receive 0, it's different data in two channels, you need to choose I2S_CHANNEL_FMT_RIGHT_LEFT in this case.
|
* if you want to receive two channels, one is the actual data from microphone and another channel is suppose to receive 0, it's different data in two channels, you need to choose I2S_CHANNEL_FMT_RIGHT_LEFT in this case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)) && (ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(4, 4, 4))
|
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)) && (ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(4, 4, 3))
|
||||||
// espressif bug: only_left has no sound, left and right are swapped
|
// espressif bug: only_left has no sound, left and right are swapped
|
||||||
// https://github.com/espressif/esp-idf/issues/9635 I2S mic not working since 4.4 (IDFGH-8138)
|
// https://github.com/espressif/esp-idf/issues/9635 I2S mic not working since 4.4 (IDFGH-8138)
|
||||||
// https://github.com/espressif/esp-idf/issues/8538 I2S channel selection issue? (IDFGH-6918)
|
// https://github.com/espressif/esp-idf/issues/8538 I2S channel selection issue? (IDFGH-6918)
|
||||||
@ -122,7 +123,7 @@ class AudioSource {
|
|||||||
This function needs to take care of anything that needs to be done
|
This function needs to take care of anything that needs to be done
|
||||||
before samples can be obtained from the microphone.
|
before samples can be obtained from the microphone.
|
||||||
*/
|
*/
|
||||||
virtual void initialize(int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) = 0;
|
virtual void initialize(int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) = 0;
|
||||||
|
|
||||||
/* Deinitialize
|
/* Deinitialize
|
||||||
Release all resources and deactivate any functionality that is used
|
Release all resources and deactivate any functionality that is used
|
||||||
@ -191,8 +192,7 @@ class I2SSource : public AudioSource {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void initialize(int8_t i2swsPin = I2S_PIN_NO_CHANGE, int8_t i2ssdPin = I2S_PIN_NO_CHANGE, int8_t i2sckPin = I2S_PIN_NO_CHANGE, int8_t mclkPin = I2S_PIN_NO_CHANGE) {
|
virtual void initialize(int8_t i2swsPin = I2S_PIN_NO_CHANGE, int8_t i2ssdPin = I2S_PIN_NO_CHANGE, int8_t i2sckPin = I2S_PIN_NO_CHANGE, int8_t mclkPin = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
|
||||||
DEBUGSR_PRINTLN("I2SSource:: initialize().");
|
|
||||||
if (i2swsPin != I2S_PIN_NO_CHANGE && i2ssdPin != I2S_PIN_NO_CHANGE) {
|
if (i2swsPin != I2S_PIN_NO_CHANGE && i2ssdPin != I2S_PIN_NO_CHANGE) {
|
||||||
if (!pinManager.allocatePin(i2swsPin, true, PinOwner::UM_Audioreactive) ||
|
if (!pinManager.allocatePin(i2swsPin, true, PinOwner::UM_Audioreactive) ||
|
||||||
!pinManager.allocatePin(i2ssdPin, false, PinOwner::UM_Audioreactive)) { // #206
|
!pinManager.allocatePin(i2ssdPin, false, PinOwner::UM_Audioreactive)) { // #206
|
||||||
@ -383,12 +383,21 @@ class I2SSource : public AudioSource {
|
|||||||
*/
|
*/
|
||||||
class ES7243 : public I2SSource {
|
class ES7243 : public I2SSource {
|
||||||
private:
|
private:
|
||||||
|
// I2C initialization functions for ES7243
|
||||||
|
void _es7243I2cBegin() {
|
||||||
|
bool i2c_initialized = Wire.begin(pin_ES7243_SDA, pin_ES7243_SCL, 100000U);
|
||||||
|
if (i2c_initialized == false) {
|
||||||
|
DEBUGSR_PRINTLN(F("AR: ES7243 failed to initialize I2C bus driver."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _es7243I2cWrite(uint8_t reg, uint8_t val) {
|
void _es7243I2cWrite(uint8_t reg, uint8_t val) {
|
||||||
#ifndef ES7243_ADDR
|
#ifndef ES7243_ADDR
|
||||||
|
Wire.beginTransmission(0x13);
|
||||||
#define ES7243_ADDR 0x13 // default address
|
#define ES7243_ADDR 0x13 // default address
|
||||||
#endif
|
#else
|
||||||
Wire.beginTransmission(ES7243_ADDR);
|
Wire.beginTransmission(ES7243_ADDR);
|
||||||
|
#endif
|
||||||
Wire.write((uint8_t)reg);
|
Wire.write((uint8_t)reg);
|
||||||
Wire.write((uint8_t)val);
|
Wire.write((uint8_t)val);
|
||||||
uint8_t i2cErr = Wire.endTransmission(); // i2cErr == 0 means OK
|
uint8_t i2cErr = Wire.endTransmission(); // i2cErr == 0 means OK
|
||||||
@ -398,6 +407,7 @@ class ES7243 : public I2SSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _es7243InitAdc() {
|
void _es7243InitAdc() {
|
||||||
|
_es7243I2cBegin();
|
||||||
_es7243I2cWrite(0x00, 0x01);
|
_es7243I2cWrite(0x00, 0x01);
|
||||||
_es7243I2cWrite(0x06, 0x00);
|
_es7243I2cWrite(0x06, 0x00);
|
||||||
_es7243I2cWrite(0x05, 0x1B);
|
_es7243I2cWrite(0x05, 0x1B);
|
||||||
@ -412,139 +422,46 @@ public:
|
|||||||
_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
|
_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
void initialize(int8_t sdaPin, int8_t sclPin, int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
||||||
DEBUGSR_PRINTLN("ES7243:: initialize();");
|
// check that pins are valid
|
||||||
|
if ((sdaPin < 0) || (sclPin < 0)) {
|
||||||
|
DEBUGSR_PRINTF("\nAR: invalid ES7243 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
||||||
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reserve SDA and SCL pins of the I2C interface
|
||||||
|
PinManagerPinType es7243Pins[2] = { { sdaPin, true }, { sclPin, true } };
|
||||||
|
if (!pinManager.allocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C)) {
|
||||||
|
pinManager.deallocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C);
|
||||||
|
DEBUGSR_PRINTF("\nAR: Failed to allocate ES7243 I2C pins: SDA=%d, SCL=%d\n", sdaPin, sclPin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_ES7243_SDA = sdaPin;
|
||||||
|
pin_ES7243_SCL = sclPin;
|
||||||
|
|
||||||
// First route mclk, then configure ADC over I2C, then configure I2S
|
// First route mclk, then configure ADC over I2C, then configure I2S
|
||||||
_es7243InitAdc();
|
_es7243InitAdc();
|
||||||
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinitialize() {
|
void deinitialize() {
|
||||||
|
// Release SDA and SCL pins of the I2C interface
|
||||||
|
PinManagerPinType es7243Pins[2] = { { pin_ES7243_SDA, true }, { pin_ES7243_SCL, true } };
|
||||||
|
pinManager.deallocateMultiplePins(es7243Pins, 2, PinOwner::HW_I2C);
|
||||||
I2SSource::deinitialize();
|
I2SSource::deinitialize();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/* ES8388 Sound Modude
|
|
||||||
This is an I2S sound processing unit that requires ininitialization over
|
|
||||||
I2C before I2S data can be received.
|
|
||||||
*/
|
|
||||||
class ES8388Source : public I2SSource {
|
|
||||||
private:
|
private:
|
||||||
|
int8_t pin_ES7243_SDA;
|
||||||
void _es8388I2cWrite(uint8_t reg, uint8_t val) {
|
int8_t pin_ES7243_SCL;
|
||||||
#ifndef ES8388_ADDR
|
|
||||||
Wire.beginTransmission(0x10);
|
|
||||||
#define ES8388_ADDR 0x10 // default address
|
|
||||||
#else
|
|
||||||
Wire.beginTransmission(ES8388_ADDR);
|
|
||||||
#endif
|
|
||||||
Wire.write((uint8_t)reg);
|
|
||||||
Wire.write((uint8_t)val);
|
|
||||||
uint8_t i2cErr = Wire.endTransmission(); // i2cErr == 0 means OK
|
|
||||||
if (i2cErr != 0) {
|
|
||||||
DEBUGSR_PRINTF("AR: ES8388 I2C write failed with error=%d (addr=0x%X, reg 0x%X, val 0x%X).\n", i2cErr, ES8388_ADDR, reg, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _es8388InitAdc() {
|
|
||||||
// https://dl.radxa.com/rock2/docs/hw/ds/ES8388%20user%20Guide.pdf Section 10.1
|
|
||||||
// http://www.everest-semi.com/pdf/ES8388%20DS.pdf Better spec sheet, more clear.
|
|
||||||
// https://docs.google.com/spreadsheets/d/1CN3MvhkcPVESuxKyx1xRYqfUit5hOdsG45St9BCUm-g/edit#gid=0 generally
|
|
||||||
// Sets ADC to around what AudioReactive expects, and loops line-in to line-out/headphone for monitoring.
|
|
||||||
// Registries are decimal, settings are binary as that's how everything is listed in the docs
|
|
||||||
// ...which makes it easier to reference the docs.
|
|
||||||
//
|
|
||||||
_es8388I2cWrite( 8,0b00000000); // I2S to slave
|
|
||||||
_es8388I2cWrite( 2,0b11110011); // Power down DEM and STM
|
|
||||||
_es8388I2cWrite(43,0b10000000); // Set same LRCK
|
|
||||||
_es8388I2cWrite( 0,0b00000101); // Set chip to Play & Record Mode
|
|
||||||
_es8388I2cWrite(13,0b00000010); // Set MCLK/LRCK ratio to 256
|
|
||||||
_es8388I2cWrite( 1,0b01000000); // Power up analog and lbias
|
|
||||||
_es8388I2cWrite( 3,0b00000000); // Power up ADC, Analog Input, and Mic Bias
|
|
||||||
_es8388I2cWrite( 4,0b11111100); // Power down DAC, Turn on LOUT1 and ROUT1 and LOUT2 and ROUT2 power
|
|
||||||
_es8388I2cWrite( 2,0b01000000); // Power up DEM and STM and undocumented bit for "turn on line-out amp"
|
|
||||||
|
|
||||||
// #define use_es8388_mic
|
|
||||||
|
|
||||||
#ifdef use_es8388_mic
|
|
||||||
// The mics *and* line-in are BOTH connected to LIN2/RIN2 on the AudioKit
|
|
||||||
// so there's no way to completely eliminate the mics. It's also hella noisy.
|
|
||||||
// Line-in works OK on the AudioKit, generally speaking, as the mics really need
|
|
||||||
// amplification to be noticable in a quiet room. If you're in a very loud room,
|
|
||||||
// the mics on the AudioKit WILL pick up sound even in line-in mode.
|
|
||||||
// TL;DR: Don't use the AudioKit for anything, use the LyraT.
|
|
||||||
//
|
|
||||||
// The LyraT does a reasonable job with mic input as configured below.
|
|
||||||
|
|
||||||
// Pick one of these. If you have to use the mics, use a LyraT over an AudioKit if you can:
|
|
||||||
_es8388I2cWrite(10,0b00000000); // Use Lin1/Rin1 for ADC input (mic on LyraT)
|
|
||||||
//_es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input (mic *and* line-in on AudioKit)
|
|
||||||
|
|
||||||
_es8388I2cWrite( 9,0b10001000); // Select Analog Input PGA Gain for ADC to +24dB (L+R)
|
|
||||||
_es8388I2cWrite(16,0b00000000); // Set ADC digital volume attenuation to 0dB (left)
|
|
||||||
_es8388I2cWrite(17,0b00000000); // Set ADC digital volume attenuation to 0dB (right)
|
|
||||||
_es8388I2cWrite(38,0b00011011); // Mixer - route LIN1/RIN1 to output after mic gain
|
|
||||||
|
|
||||||
_es8388I2cWrite(39,0b01000000); // Mixer - route LIN to mixL, +6dB gain
|
|
||||||
_es8388I2cWrite(42,0b01000000); // Mixer - route RIN to mixR, +6dB gain
|
|
||||||
_es8388I2cWrite(46,0b00100001); // LOUT1VOL - 0b00100001 = +4.5dB
|
|
||||||
_es8388I2cWrite(47,0b00100001); // ROUT1VOL - 0b00100001 = +4.5dB
|
|
||||||
_es8388I2cWrite(48,0b00100001); // LOUT2VOL - 0b00100001 = +4.5dB
|
|
||||||
_es8388I2cWrite(49,0b00100001); // ROUT2VOL - 0b00100001 = +4.5dB
|
|
||||||
|
|
||||||
// Music ALC - the mics like Auto Level Control
|
|
||||||
// You can also use this for line-in, but it's not really needed.
|
|
||||||
//
|
|
||||||
_es8388I2cWrite(18,0b11111000); // ALC: stereo, max gain +35.5dB, min gain -12dB
|
|
||||||
_es8388I2cWrite(19,0b00110000); // ALC: target -1.5dB, 0ms hold time
|
|
||||||
_es8388I2cWrite(20,0b10100110); // ALC: gain ramp up = 420ms/93ms, gain ramp down = check manual for calc
|
|
||||||
_es8388I2cWrite(21,0b00000110); // ALC: use "ALC" mode, no zero-cross, window 96 samples
|
|
||||||
_es8388I2cWrite(22,0b01011001); // ALC: noise gate threshold, PGA gain constant, noise gate enabled
|
|
||||||
#else
|
|
||||||
_es8388I2cWrite(10,0b01010000); // Use Lin2/Rin2 for ADC input ("line-in")
|
|
||||||
_es8388I2cWrite( 9,0b00000000); // Select Analog Input PGA Gain for ADC to 0dB (L+R)
|
|
||||||
_es8388I2cWrite(16,0b01000000); // Set ADC digital volume attenuation to -32dB (left)
|
|
||||||
_es8388I2cWrite(17,0b01000000); // Set ADC digital volume attenuation to -32dB (right)
|
|
||||||
_es8388I2cWrite(38,0b00001001); // Mixer - route LIN2/RIN2 to output
|
|
||||||
|
|
||||||
_es8388I2cWrite(39,0b01010000); // Mixer - route LIN to mixL, 0dB gain
|
|
||||||
_es8388I2cWrite(42,0b01010000); // Mixer - route RIN to mixR, 0dB gain
|
|
||||||
_es8388I2cWrite(46,0b00011011); // LOUT1VOL - 0b00011110 = +0dB, 0b00011011 = LyraT balance fix
|
|
||||||
_es8388I2cWrite(47,0b00011110); // ROUT1VOL - 0b00011110 = +0dB
|
|
||||||
_es8388I2cWrite(48,0b00011110); // LOUT2VOL - 0b00011110 = +0dB
|
|
||||||
_es8388I2cWrite(49,0b00011110); // ROUT2VOL - 0b00011110 = +0dB
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
ES8388Source(SRate_t sampleRate, int blockSize, float sampleScale = 1.0f, bool i2sMaster=true) :
|
|
||||||
I2SSource(sampleRate, blockSize, sampleScale) {
|
|
||||||
_config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
|
|
||||||
DEBUGSR_PRINTLN("ES8388Source:: initialize();");
|
|
||||||
if ((i2sckPin < 0) || (mclkPin < 0)) {
|
|
||||||
DEBUGSR_PRINTF("\nAR: invalid I2S pin: SCK=%d, MCLK=%d\n", i2sckPin, mclkPin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// First route mclk, then configure ADC over I2C, then configure I2S
|
|
||||||
_es8388InitAdc();
|
|
||||||
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deinitialize() {
|
|
||||||
I2SSource::deinitialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
|
||||||
#if !defined(SOC_I2S_SUPPORTS_ADC) && !defined(SOC_I2S_SUPPORTS_ADC_DAC)
|
#if !defined(SOC_I2S_SUPPORTS_ADC) && !defined(SOC_I2S_SUPPORTS_ADC_DAC)
|
||||||
@ -586,8 +503,7 @@ class I2SAdcSource : public I2SSource {
|
|||||||
/* identify Audiosource type - I2S-ADC*/
|
/* identify Audiosource type - I2S-ADC*/
|
||||||
AudioSourceType getType(void) {return(Type_I2SAdc);}
|
AudioSourceType getType(void) {return(Type_I2SAdc);}
|
||||||
|
|
||||||
void initialize(int8_t audioPin, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
|
void initialize(int8_t audioPin, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
|
||||||
DEBUGSR_PRINTLN("I2SAdcSource:: initialize().");
|
|
||||||
_myADCchannel = 0x0F;
|
_myADCchannel = 0x0F;
|
||||||
if(!pinManager.allocatePin(audioPin, false, PinOwner::UM_Audioreactive)) {
|
if(!pinManager.allocatePin(audioPin, false, PinOwner::UM_Audioreactive)) {
|
||||||
DEBUGSR_PRINTF("failed to allocate GPIO for audio analog input: %d\n", audioPin);
|
DEBUGSR_PRINTF("failed to allocate GPIO for audio analog input: %d\n", audioPin);
|
||||||
@ -758,8 +674,7 @@ class SPH0654 : public I2SSource {
|
|||||||
I2SSource(sampleRate, blockSize, sampleScale)
|
I2SSource(sampleRate, blockSize, sampleScale)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void initialize(int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t = I2S_PIN_NO_CHANGE) {
|
void initialize(uint8_t i2swsPin, uint8_t i2ssdPin, uint8_t i2sckPin, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
|
||||||
DEBUGSR_PRINTLN("SPH0654:: initialize();");
|
|
||||||
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin);
|
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin);
|
||||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
// these registers are only existing in "classic" ESP32
|
// these registers are only existing in "classic" ESP32
|
||||||
@ -770,4 +685,3 @@ class SPH0654 : public I2SSource {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
BIN
usermods/battery_status_basic/assets/battery_info_screen.png
Normal file
After Width: | Height: | Size: 68 KiB |
68
usermods/battery_status_basic/readme.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# :battery: Battery status/level Usermod :battery:
|
||||||
|
Enables battery level monitoring of your 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 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)
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img width="300" src="assets/battery_info_screen.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
define `USERMOD_BATTERY_STATUS_BASIC` in `my_config.h`
|
||||||
|
|
||||||
|
### Basic wiring diagram
|
||||||
|
<p align="center">
|
||||||
|
<img width="300" src="assets/battery_connection_schematic_01.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Define Your Options
|
||||||
|
|
||||||
|
* `USERMOD_BATTERY_STATUS_BASIC` - define this (in `my_config.h`) to have this usermod included wled00\usermods_list.cpp
|
||||||
|
* `USERMOD_BATTERY_MEASUREMENT_PIN` - defaults to A0 on ESP8266 and GPIO32 on ESP32
|
||||||
|
* `USERMOD_BATTERY_MEASUREMENT_INTERVAL` - battery check interval. defaults to 30 seconds
|
||||||
|
* `USERMOD_BATTERY_MIN_VOLTAGE` - minimum battery voltage. default is 2.6 (18650 battery standard)
|
||||||
|
* `USERMOD_BATTERY_MAX_VOLTAGE` - maximum battery voltage. default is 4.2 (18650 battery standard)
|
||||||
|
|
||||||
|
All parameters can be configured at runtime via the Usermods settings page.
|
||||||
|
|
||||||
|
## Important :warning:
|
||||||
|
* 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
|
||||||
|
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
|
||||||
|
|
398
usermods/battery_status_basic/usermod_v2_battery_status_basic.h
Normal file
@ -0,0 +1,398 @@
|
|||||||
|
#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 = voltage<minBatteryVoltage||voltage>maxBatteryVoltage?-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";
|
28
usermods/blynk_relay_control/README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Blynk controllable relay
|
||||||
|
Enables controlling a relay state via user variables. Allows the user variables to be set via Blynk.
|
||||||
|
|
||||||
|
Optionally, the servo can have a reset timer to return to its default state after a user definable interval. The interval is set via 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 Blynk updates
|
||||||
|
#define BLYNK_RELAY_UPDATE_INTERVAL 5000
|
||||||
|
```
|
96
usermods/blynk_relay_control/wled06_usermod.ino
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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();
|
||||||
|
}
|
@ -219,7 +219,6 @@ class BobLightUsermod : public Usermod {
|
|||||||
|
|
||||||
void enable(bool en) { enabled = en; }
|
void enable(bool en) { enabled = en; }
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
/**
|
/**
|
||||||
* handling of MQTT message
|
* handling of MQTT message
|
||||||
* topic only contains stripped topic (part after /wled/MAC)
|
* topic only contains stripped topic (part after /wled/MAC)
|
||||||
@ -250,7 +249,6 @@ class BobLightUsermod : public Usermod {
|
|||||||
// mqtt->subscribe(subuf, 0);
|
// mqtt->subscribe(subuf, 0);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject& root)
|
void addToJsonInfo(JsonObject& root)
|
||||||
{
|
{
|
||||||
|
@ -85,9 +85,12 @@ class MPU6050Driver : public Usermod {
|
|||||||
* setup() is called once at boot. WiFi is not yet connected at this point.
|
* setup() is called once at boot. WiFi is not yet connected at this point.
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
if (i2c_scl<0 || i2c_sda<0) { enabled = false; return; }
|
PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
|
||||||
|
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; }
|
||||||
|
// join I2C bus (I2Cdev library doesn't do this automatically)
|
||||||
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
||||||
Wire.setClock(400000U); // 400kHz I2C clock. Comment this line if having compilation difficulties
|
Wire.begin();
|
||||||
|
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
|
||||||
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
|
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
|
||||||
Fastwire::setup(400, true);
|
Fastwire::setup(400, true);
|
||||||
#endif
|
#endif
|
||||||
@ -135,7 +138,7 @@ class MPU6050Driver : public Usermod {
|
|||||||
// (if it's going to break, usually the code will be 1)
|
// (if it's going to break, usually the code will be 1)
|
||||||
DEBUG_PRINT(F("DMP Initialization failed (code "));
|
DEBUG_PRINT(F("DMP Initialization failed (code "));
|
||||||
DEBUG_PRINT(devStatus);
|
DEBUG_PRINT(devStatus);
|
||||||
DEBUG_PRINTLN(")");
|
DEBUG_PRINTLN(F(")"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +209,7 @@ class MPU6050Driver : public Usermod {
|
|||||||
JsonObject user = root["u"];
|
JsonObject user = root["u"];
|
||||||
if (user.isNull()) user = root.createNestedObject("u");
|
if (user.isNull()) user = root.createNestedObject("u");
|
||||||
|
|
||||||
JsonObject imu_meas = user.createNestedObject("IMU");
|
JsonArray imu_meas = user.createNestedObject("IMU");
|
||||||
JsonArray quat_json = imu_meas.createNestedArray("Quat");
|
JsonArray quat_json = imu_meas.createNestedArray("Quat");
|
||||||
quat_json.add(qat.w);
|
quat_json.add(qat.w);
|
||||||
quat_json.add(qat.x);
|
quat_json.add(qat.x);
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
# Multi Relay
|
# 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.
|
||||||
Usermod supports PCF8574 I2C port expander to reduce GPIO use.
|
|
||||||
PCF8574 supports 8 outputs and each output corresponds to a relay in WLED (relay 0 = port 0, etc). I you are using more than 8 relays with multiple PCF8574 make sure their addresses are set conscutively (e.g. 0x20 and 0x21). You can set address of first expander in settings.
|
|
||||||
(**NOTE:** Will require Wire library and global I2C pins defined.)
|
|
||||||
|
|
||||||
## HTTP API
|
## HTTP API
|
||||||
All responses are returned in JSON format.
|
All responses are returned in JSON format.
|
||||||
@ -84,15 +81,13 @@ void registerUsermods()
|
|||||||
Usermod can be configured via the Usermods settings page.
|
Usermod can be configured via the Usermods settings page.
|
||||||
|
|
||||||
* `enabled` - enable/disable usermod
|
* `enabled` - enable/disable usermod
|
||||||
* `use-PCF8574` - use PCF8574 port expander instead of GPIO pins
|
|
||||||
* `first-PCF8574` - I2C address of first expander (WARNING: enter *decimal* value)
|
|
||||||
* `broadcast`- time in seconds between MQTT relay-state broadcasts
|
|
||||||
* `HA-discovery`- enable Home Assistant auto discovery
|
|
||||||
* `pin` - ESP GPIO pin the relay is connected to (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
|
* `delay-s` - delay in seconds after on/off command is received
|
||||||
* `active-high` - assign high/low activation of relay (can be used to reverse relay states)
|
* `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)
|
* `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
|
* `button` - button (from LED Settings) that controls this relay
|
||||||
|
* `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.
|
If there is no MultiRelay section, just save current configuration and re-open Usermods settings page.
|
||||||
|
|
||||||
@ -105,6 +100,3 @@ Have fun - @blazoncek
|
|||||||
2021-11
|
2021-11
|
||||||
* Added information about dynamic configuration options
|
* Added information about dynamic configuration options
|
||||||
* Added button support.
|
* Added button support.
|
||||||
|
|
||||||
2023-05
|
|
||||||
* Added support for PCF8574 I2C port expander (multiple)
|
|
@ -4,19 +4,10 @@
|
|||||||
|
|
||||||
#ifndef MULTI_RELAY_MAX_RELAYS
|
#ifndef MULTI_RELAY_MAX_RELAYS
|
||||||
#define MULTI_RELAY_MAX_RELAYS 4
|
#define MULTI_RELAY_MAX_RELAYS 4
|
||||||
#else
|
|
||||||
#if MULTI_RELAY_MAX_RELAYS>8
|
|
||||||
#undef MULTI_RELAY_MAX_RELAYS
|
|
||||||
#define MULTI_RELAY_MAX_RELAYS 8
|
|
||||||
#warning Maximum relays set to 8
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MULTI_RELAY_PINS
|
#ifndef MULTI_RELAY_PINS
|
||||||
#define MULTI_RELAY_PINS -1
|
#define MULTI_RELAY_PINS -1
|
||||||
#define MULTI_RELAY_ENABLED false
|
|
||||||
#else
|
|
||||||
#define MULTI_RELAY_ENABLED true
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing)
|
#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing)
|
||||||
@ -24,37 +15,21 @@
|
|||||||
#define ON true
|
#define ON true
|
||||||
#define OFF false
|
#define OFF false
|
||||||
|
|
||||||
#ifndef USERMOD_USE_PCF8574
|
|
||||||
#undef USE_PCF8574
|
|
||||||
#define USE_PCF8574 false
|
|
||||||
#else
|
|
||||||
#undef USE_PCF8574
|
|
||||||
#define USE_PCF8574 true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PCF8574_ADDRESS
|
|
||||||
#define PCF8574_ADDRESS 0x20 // some may start at 0x38
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This usermod handles multiple relay outputs.
|
* This usermod handles multiple relay outputs.
|
||||||
* These outputs complement built-in relay output in a way that the activation can be delayed.
|
* These outputs complement built-in relay output in a way that the activation can be delayed.
|
||||||
* They can also activate/deactivate in reverse logic independently.
|
* They can also activate/deactivate in reverse logic independently.
|
||||||
*
|
|
||||||
* Written and maintained by @blazoncek
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
typedef struct relay_t {
|
typedef struct relay_t {
|
||||||
int8_t pin;
|
int8_t pin;
|
||||||
struct { // reduces memory footprint
|
bool active;
|
||||||
bool active : 1; // is the relay waiting to be switched
|
bool mode;
|
||||||
bool invert : 1; // does On mean 1 or 0
|
bool state;
|
||||||
bool state : 1; // 1 relay is On, 0 relay is Off
|
bool external;
|
||||||
bool external : 1; // is the relay externally controlled
|
uint16_t delay;
|
||||||
int8_t button : 4; // which button triggers relay
|
int8_t button;
|
||||||
};
|
|
||||||
uint16_t delay; // amount of ms to wait after it is activated
|
|
||||||
} Relay;
|
} Relay;
|
||||||
|
|
||||||
|
|
||||||
@ -64,15 +39,20 @@ class MultiRelay : public Usermod {
|
|||||||
// array of relays
|
// array of relays
|
||||||
Relay _relay[MULTI_RELAY_MAX_RELAYS];
|
Relay _relay[MULTI_RELAY_MAX_RELAYS];
|
||||||
|
|
||||||
uint32_t _switchTimerStart; // switch timer start time
|
// switch timer start time
|
||||||
bool _oldMode; // old brightness
|
uint32_t _switchTimerStart = 0;
|
||||||
bool enabled; // usermod enabled
|
// old brightness
|
||||||
bool initDone; // status of initialisation
|
bool _oldMode;
|
||||||
bool usePcf8574;
|
|
||||||
uint8_t addrPcf8574;
|
// usermod enabled
|
||||||
bool HAautodiscovery;
|
bool enabled = false; // needs to be configured (no default config)
|
||||||
uint16_t periodicBroadcastSec;
|
// status of initialisation
|
||||||
unsigned long lastBroadcast;
|
bool initDone = false;
|
||||||
|
|
||||||
|
bool HAautodiscovery = false;
|
||||||
|
|
||||||
|
uint16_t periodicBroadcastSec = 60;
|
||||||
|
unsigned long lastBroadcast = 0;
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
static const char _name[];
|
static const char _name[];
|
||||||
@ -84,146 +64,25 @@ class MultiRelay : public Usermod {
|
|||||||
static const char _button[];
|
static const char _button[];
|
||||||
static const char _broadcast[];
|
static const char _broadcast[];
|
||||||
static const char _HAautodiscovery[];
|
static const char _HAautodiscovery[];
|
||||||
static const char _pcf8574[];
|
|
||||||
static const char _pcfAddress[];
|
|
||||||
|
|
||||||
void handleOffTimer();
|
void publishMqtt(int relay) {
|
||||||
void InitHtmlAPIHandle();
|
|
||||||
int getValue(String data, char separator, int index);
|
|
||||||
uint8_t getActiveRelayCount();
|
|
||||||
|
|
||||||
byte IOexpanderWrite(byte address, byte _data);
|
|
||||||
byte IOexpanderRead(int address);
|
|
||||||
|
|
||||||
void publishMqtt(int relay);
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
void publishHomeAssistantAutodiscovery();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
MultiRelay();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* desctructor
|
|
||||||
*/
|
|
||||||
//~MultiRelay() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable/Disable the usermod
|
|
||||||
*/
|
|
||||||
inline void enable(bool enable) { enabled = enable; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get usermod enabled/disabled state
|
|
||||||
*/
|
|
||||||
inline bool isEnabled() { return enabled; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
inline uint16_t getId() { return USERMOD_ID_MULTI_RELAY; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* switch relay on/off
|
|
||||||
*/
|
|
||||||
void switchRelay(uint8_t relay, bool mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* toggle relay
|
|
||||||
*/
|
|
||||||
inline void toggleRelay(uint8_t relay) {
|
|
||||||
switchRelay(relay, !_relay[relay].state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* connected() is called every time the WiFi is (re)connected
|
|
||||||
* Use it to initialize network interfaces
|
|
||||||
*/
|
|
||||||
inline void connected() { InitHtmlAPIHandle(); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
|
||||||
*/
|
|
||||||
void loop();
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
bool onMqttMessage(char* topic, char* payload);
|
|
||||||
void onMqttConnect(bool sessionPresent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
|
||||||
*/
|
|
||||||
void addToJsonInfo(JsonObject &root);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* provide the changeable values
|
|
||||||
*/
|
|
||||||
void addToConfig(JsonObject &root);
|
|
||||||
|
|
||||||
void appendConfigData();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* restore the changeable values
|
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
|
||||||
*
|
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
|
||||||
*/
|
|
||||||
bool readFromConfig(JsonObject &root);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// class implementetion
|
|
||||||
|
|
||||||
void MultiRelay::publishMqtt(int relay) {
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (WLED_MQTT_CONNECTED){
|
if (WLED_MQTT_CONNECTED){
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, PSTR("%s/relay/%d"), mqttDeviceTopic, relay);
|
sprintf_P(subuf, PSTR("%s/relay/%d"), mqttDeviceTopic, relay);
|
||||||
mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off");
|
mqtt->publish(subuf, 0, false, _relay[relay].state ? "on" : "off");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* switch off the strip if the delay has elapsed
|
* switch off the strip if the delay has elapsed
|
||||||
*/
|
*/
|
||||||
void MultiRelay::handleOffTimer() {
|
void handleOffTimer() {
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
bool activeRelays = false;
|
bool activeRelays = false;
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
if (_relay[i].active && _switchTimerStart > 0 && now - _switchTimerStart > (_relay[i].delay*1000)) {
|
if (_relay[i].active && _switchTimerStart > 0 && now - _switchTimerStart > (_relay[i].delay*1000)) {
|
||||||
if (!_relay[i].external) switchRelay(i, !offMode);
|
if (!_relay[i].external) toggleRelay(i);
|
||||||
_relay[i].active = false;
|
_relay[i].active = false;
|
||||||
} else if (periodicBroadcastSec && now - lastBroadcast > (periodicBroadcastSec*1000)) {
|
} else if (periodicBroadcastSec && now - lastBroadcast > (periodicBroadcastSec*1000)) {
|
||||||
if (_relay[i].pin>=0) publishMqtt(i);
|
if (_relay[i].pin>=0) publishMqtt(i);
|
||||||
@ -240,7 +99,7 @@ void MultiRelay::handleOffTimer() {
|
|||||||
* https://github.com/gsieben/WLED/blob/master/usermods/GeoGab-Relays/usermod_GeoGab.h
|
* https://github.com/gsieben/WLED/blob/master/usermods/GeoGab-Relays/usermod_GeoGab.h
|
||||||
*/
|
*/
|
||||||
#define GEOGABVERSION "0.1.3"
|
#define GEOGABVERSION "0.1.3"
|
||||||
void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsyncWebServer
|
void InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsyncWebServer
|
||||||
DEBUG_PRINTLN(F("Relays: Initialize HTML API"));
|
DEBUG_PRINTLN(F("Relays: Initialize HTML API"));
|
||||||
|
|
||||||
server.on("/relays", HTTP_GET, [this](AsyncWebServerRequest *request) {
|
server.on("/relays", HTTP_GET, [this](AsyncWebServerRequest *request) {
|
||||||
@ -302,7 +161,7 @@ void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsync
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiRelay::getValue(String data, char separator, int index) {
|
int getValue(String data, char separator, int index) {
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int strIndex[] = {0, -1};
|
int strIndex[] = {0, -1};
|
||||||
int maxIndex = data.length()-1;
|
int maxIndex = data.length()-1;
|
||||||
@ -317,87 +176,68 @@ int MultiRelay::getValue(String data, char separator, int index) {
|
|||||||
return found>index ? data.substring(strIndex[0], strIndex[1]).toInt() : -1;
|
return found>index ? data.substring(strIndex[0], strIndex[1]).toInt() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Write a byte to the IO expander
|
public:
|
||||||
byte MultiRelay::IOexpanderWrite(byte address, byte _data ) {
|
/**
|
||||||
Wire.beginTransmission(address);
|
* constructor
|
||||||
Wire.write(_data);
|
*/
|
||||||
return Wire.endTransmission();
|
MultiRelay() {
|
||||||
}
|
|
||||||
|
|
||||||
//Read a byte from the IO expander
|
|
||||||
byte MultiRelay::IOexpanderRead(int address) {
|
|
||||||
byte _data = 0;
|
|
||||||
Wire.requestFrom(address, 1);
|
|
||||||
if (Wire.available()) {
|
|
||||||
_data = Wire.read();
|
|
||||||
}
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// public methods
|
|
||||||
|
|
||||||
MultiRelay::MultiRelay()
|
|
||||||
: _switchTimerStart(0)
|
|
||||||
, enabled(MULTI_RELAY_ENABLED)
|
|
||||||
, initDone(false)
|
|
||||||
, usePcf8574(USE_PCF8574)
|
|
||||||
, addrPcf8574(PCF8574_ADDRESS)
|
|
||||||
, HAautodiscovery(false)
|
|
||||||
, periodicBroadcastSec(60)
|
|
||||||
, lastBroadcast(0)
|
|
||||||
{
|
|
||||||
const int8_t defPins[] = {MULTI_RELAY_PINS};
|
const int8_t defPins[] = {MULTI_RELAY_PINS};
|
||||||
for (size_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
_relay[i].pin = i<sizeof(defPins) ? defPins[i] : -1;
|
_relay[i].pin = i<sizeof(defPins) ? defPins[i] : -1;
|
||||||
_relay[i].delay = 0;
|
_relay[i].delay = 0;
|
||||||
_relay[i].invert = false;
|
_relay[i].mode = false;
|
||||||
_relay[i].active = false;
|
_relay[i].active = false;
|
||||||
_relay[i].state = false;
|
_relay[i].state = false;
|
||||||
_relay[i].external = false;
|
_relay[i].external = false;
|
||||||
_relay[i].button = -1;
|
_relay[i].button = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* desctructor
|
||||||
|
*/
|
||||||
|
~MultiRelay() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable the usermod
|
||||||
|
*/
|
||||||
|
inline void enable(bool enable) { enabled = enable; }
|
||||||
|
/**
|
||||||
|
* Get usermod enabled/disabled state
|
||||||
|
*/
|
||||||
|
inline bool isEnabled() { return enabled; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* switch relay on/off
|
* switch relay on/off
|
||||||
*/
|
*/
|
||||||
void MultiRelay::switchRelay(uint8_t relay, bool mode) {
|
void switchRelay(uint8_t relay, bool mode) {
|
||||||
if (relay>=MULTI_RELAY_MAX_RELAYS || _relay[relay].pin<0) return;
|
if (relay>=MULTI_RELAY_MAX_RELAYS || _relay[relay].pin<0) return;
|
||||||
_relay[relay].state = mode;
|
_relay[relay].state = mode;
|
||||||
if (usePcf8574 && _relay[relay].pin >= 100) {
|
|
||||||
// we need to send all ouputs at the same time
|
|
||||||
uint8_t state = 0;
|
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
|
||||||
if (_relay[i].pin < 100) continue;
|
|
||||||
uint8_t pin = _relay[i].pin - 100;
|
|
||||||
state |= (_relay[i].invert ? !_relay[i].state : _relay[i].state) << pin; // fill relay states for all pins
|
|
||||||
}
|
|
||||||
IOexpanderWrite(addrPcf8574, state);
|
|
||||||
DEBUG_PRINT(F("Writing to PCF8574: ")); DEBUG_PRINTLN(state);
|
|
||||||
} else if (_relay[relay].pin < 100) {
|
|
||||||
pinMode(_relay[relay].pin, OUTPUT);
|
pinMode(_relay[relay].pin, OUTPUT);
|
||||||
digitalWrite(_relay[relay].pin, _relay[relay].invert ? !_relay[relay].state : _relay[relay].state);
|
digitalWrite(_relay[relay].pin, mode ? !_relay[relay].mode : _relay[relay].mode);
|
||||||
} else return;
|
|
||||||
publishMqtt(relay);
|
publishMqtt(relay);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MultiRelay::getActiveRelayCount() {
|
/**
|
||||||
|
* toggle relay
|
||||||
|
*/
|
||||||
|
inline void toggleRelay(uint8_t relay) {
|
||||||
|
switchRelay(relay, !_relay[relay].state);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getActiveRelayCount() {
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) if (_relay[i].pin>=0) count++;
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) if (_relay[i].pin>=0) count++;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Functions called by WLED
|
//Functions called by WLED
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
/**
|
/**
|
||||||
* handling of MQTT message
|
* handling of MQTT message
|
||||||
* topic only contains stripped topic (part after /wled/MAC)
|
* topic only contains stripped topic (part after /wled/MAC)
|
||||||
* topic should look like: /relay/X/command; where X is relay number, 0 based
|
* topic should look like: /relay/X/command; where X is relay number, 0 based
|
||||||
*/
|
*/
|
||||||
bool MultiRelay::onMqttMessage(char* topic, char* payload) {
|
bool onMqttMessage(char* topic, char* payload) {
|
||||||
if (strlen(topic) > 8 && strncmp_P(topic, PSTR("/relay/"), 7) == 0 && strncmp_P(topic+8, PSTR("/command"), 8) == 0) {
|
if (strlen(topic) > 8 && strncmp_P(topic, PSTR("/relay/"), 7) == 0 && strncmp_P(topic+8, PSTR("/command"), 8) == 0) {
|
||||||
uint8_t relay = strtoul(topic+7, NULL, 10);
|
uint8_t relay = strtoul(topic+7, NULL, 10);
|
||||||
if (relay<MULTI_RELAY_MAX_RELAYS) {
|
if (relay<MULTI_RELAY_MAX_RELAYS) {
|
||||||
@ -420,7 +260,7 @@ bool MultiRelay::onMqttMessage(char* topic, char* payload) {
|
|||||||
/**
|
/**
|
||||||
* subscribe to MQTT topic for controlling relays
|
* subscribe to MQTT topic for controlling relays
|
||||||
*/
|
*/
|
||||||
void MultiRelay::onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
//(re)subscribe to required topics
|
//(re)subscribe to required topics
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
if (mqttDeviceTopic[0] != 0) {
|
if (mqttDeviceTopic[0] != 0) {
|
||||||
@ -435,7 +275,7 @@ void MultiRelay::onMqttConnect(bool sessionPresent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiRelay::publishHomeAssistantAutodiscovery() {
|
void publishHomeAssistantAutodiscovery() {
|
||||||
for (int i = 0; i < MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i = 0; i < MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
char uid[24], json_str[1024], buf[128];
|
char uid[24], json_str[1024], buf[128];
|
||||||
size_t payload_size;
|
size_t payload_size;
|
||||||
@ -473,45 +313,39 @@ void MultiRelay::publishHomeAssistantAutodiscovery() {
|
|||||||
mqtt->publish(buf, 0, true, json_str, payload_size);
|
mqtt->publish(buf, 0, true, json_str, payload_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setup() is called once at boot. WiFi is not yet connected at this point.
|
* setup() is called once at boot. WiFi is not yet connected at this point.
|
||||||
* You can use it to initialize variables, sensors or similar.
|
* You can use it to initialize variables, sensors or similar.
|
||||||
*/
|
*/
|
||||||
void MultiRelay::setup() {
|
void setup() {
|
||||||
// pins retrieved from cfg.json (readFromConfig()) prior to running setup()
|
// pins retrieved from cfg.json (readFromConfig()) prior to running setup()
|
||||||
// if we want PCF8574 expander I2C pins need to be valid
|
|
||||||
if (i2c_sda<0 || i2c_scl<0) usePcf8574 = false;
|
|
||||||
|
|
||||||
uint8_t state = 0;
|
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
if (usePcf8574 && _relay[i].pin >= 100) {
|
if (_relay[i].pin<0) continue;
|
||||||
uint8_t pin = _relay[i].pin - 100;
|
if (!pinManager.allocatePin(_relay[i].pin,true, PinOwner::UM_MultiRelay)) {
|
||||||
if (!_relay[i].external) _relay[i].state = !offMode;
|
_relay[i].pin = -1; // allocation failed
|
||||||
state |= (uint8_t)(_relay[i].invert ? !_relay[i].state : _relay[i].state) << pin;
|
} else {
|
||||||
} else if (_relay[i].pin<100 && _relay[i].pin>=0) {
|
|
||||||
if (pinManager.allocatePin(_relay[i].pin,true, PinOwner::UM_MultiRelay)) {
|
|
||||||
if (!_relay[i].external) _relay[i].state = !offMode;
|
if (!_relay[i].external) _relay[i].state = !offMode;
|
||||||
switchRelay(i, _relay[i].state);
|
switchRelay(i, _relay[i].state);
|
||||||
_relay[i].active = false;
|
_relay[i].active = false;
|
||||||
} else {
|
|
||||||
_relay[i].pin = -1; // allocation failed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (usePcf8574) {
|
|
||||||
IOexpanderWrite(addrPcf8574, state); // init expander (set all outputs)
|
|
||||||
DEBUG_PRINTLN(F("PCF8574(s) inited."));
|
|
||||||
}
|
|
||||||
_oldMode = offMode;
|
_oldMode = offMode;
|
||||||
initDone = true;
|
initDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connected() is called every time the WiFi is (re)connected
|
||||||
|
* Use it to initialize network interfaces
|
||||||
|
*/
|
||||||
|
void connected() {
|
||||||
|
InitHtmlAPIHandle();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
||||||
*/
|
*/
|
||||||
void MultiRelay::loop() {
|
void loop() {
|
||||||
yield();
|
yield();
|
||||||
if (!enabled || strip.isUpdating()) return;
|
if (!enabled || strip.isUpdating()) return;
|
||||||
|
|
||||||
@ -524,7 +358,7 @@ void MultiRelay::loop() {
|
|||||||
_oldMode = offMode;
|
_oldMode = offMode;
|
||||||
_switchTimerStart = millis();
|
_switchTimerStart = millis();
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
if ((_relay[i].pin>=0) && !_relay[i].external) _relay[i].active = true;
|
if (_relay[i].pin>=0 && !_relay[i].external) _relay[i].active = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +370,7 @@ void MultiRelay::loop() {
|
|||||||
* will prevent button working in a default way.
|
* will prevent button working in a default way.
|
||||||
* Replicating button.cpp
|
* Replicating button.cpp
|
||||||
*/
|
*/
|
||||||
bool MultiRelay::handleButton(uint8_t b) {
|
bool handleButton(uint8_t b) {
|
||||||
yield();
|
yield();
|
||||||
if (!enabled
|
if (!enabled
|
||||||
|| buttonType[b] == BTN_TYPE_NONE
|
|| buttonType[b] == BTN_TYPE_NONE
|
||||||
@ -628,7 +462,7 @@ bool MultiRelay::handleButton(uint8_t b) {
|
|||||||
/**
|
/**
|
||||||
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
||||||
*/
|
*/
|
||||||
void MultiRelay::addToJsonInfo(JsonObject &root) {
|
void addToJsonInfo(JsonObject &root) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
JsonObject user = root["u"];
|
JsonObject user = root["u"];
|
||||||
if (user.isNull())
|
if (user.isNull())
|
||||||
@ -665,7 +499,7 @@ void MultiRelay::addToJsonInfo(JsonObject &root) {
|
|||||||
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
* 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
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
void MultiRelay::addToJsonState(JsonObject &root) {
|
void addToJsonState(JsonObject &root) {
|
||||||
if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
|
if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
|
||||||
JsonObject multiRelay = root[FPSTR(_name)];
|
JsonObject multiRelay = root[FPSTR(_name)];
|
||||||
if (multiRelay.isNull()) {
|
if (multiRelay.isNull()) {
|
||||||
@ -689,7 +523,7 @@ void MultiRelay::addToJsonState(JsonObject &root) {
|
|||||||
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
|
* 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
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
void MultiRelay::readFromJsonState(JsonObject &root) {
|
void readFromJsonState(JsonObject &root) {
|
||||||
if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
|
if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
|
||||||
JsonObject usermod = root[FPSTR(_name)];
|
JsonObject usermod = root[FPSTR(_name)];
|
||||||
if (!usermod.isNull()) {
|
if (!usermod.isNull()) {
|
||||||
@ -719,40 +553,31 @@ void MultiRelay::readFromJsonState(JsonObject &root) {
|
|||||||
/**
|
/**
|
||||||
* provide the changeable values
|
* provide the changeable values
|
||||||
*/
|
*/
|
||||||
void MultiRelay::addToConfig(JsonObject &root) {
|
void addToConfig(JsonObject &root) {
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name));
|
JsonObject top = root.createNestedObject(FPSTR(_name));
|
||||||
|
|
||||||
top[FPSTR(_enabled)] = enabled;
|
top[FPSTR(_enabled)] = enabled;
|
||||||
top[FPSTR(_pcf8574)] = usePcf8574;
|
|
||||||
top[FPSTR(_pcfAddress)] = addrPcf8574;
|
|
||||||
top[FPSTR(_broadcast)] = periodicBroadcastSec;
|
top[FPSTR(_broadcast)] = periodicBroadcastSec;
|
||||||
top[FPSTR(_HAautodiscovery)] = HAautodiscovery;
|
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
String parName = FPSTR(_relay_str); parName += '-'; parName += i;
|
String parName = FPSTR(_relay_str); parName += '-'; parName += i;
|
||||||
JsonObject relay = top.createNestedObject(parName);
|
JsonObject relay = top.createNestedObject(parName);
|
||||||
relay["pin"] = _relay[i].pin;
|
relay["pin"] = _relay[i].pin;
|
||||||
relay[FPSTR(_activeHigh)] = _relay[i].invert;
|
relay[FPSTR(_activeHigh)] = _relay[i].mode;
|
||||||
relay[FPSTR(_delay_str)] = _relay[i].delay;
|
relay[FPSTR(_delay_str)] = _relay[i].delay;
|
||||||
relay[FPSTR(_external)] = _relay[i].external;
|
relay[FPSTR(_external)] = _relay[i].external;
|
||||||
relay[FPSTR(_button)] = _relay[i].button;
|
relay[FPSTR(_button)] = _relay[i].button;
|
||||||
}
|
}
|
||||||
|
top[FPSTR(_HAautodiscovery)] = HAautodiscovery;
|
||||||
DEBUG_PRINTLN(F("MultiRelay config saved."));
|
DEBUG_PRINTLN(F("MultiRelay config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiRelay::appendConfigData() {
|
|
||||||
oappend(SET_F("addInfo('MultiRelay:PCF8574-address',1,'<i>(not hex!)</i>');"));
|
|
||||||
oappend(SET_F("addInfo('MultiRelay:broadcast-sec',1,'(MQTT message)');"));
|
|
||||||
//oappend(SET_F("addInfo('MultiRelay:relay-0:pin',1,'(use -1 for PCF8574)');"));
|
|
||||||
oappend(SET_F("d.extra.push({'MultiRelay':{pin:[['P0',100],['P1',101],['P2',102],['P3',103],['P4',104],['P5',105],['P6',106],['P7',107]]}});"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* restore the changeable values
|
* restore the changeable values
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
||||||
*
|
*
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
||||||
*/
|
*/
|
||||||
bool MultiRelay::readFromConfig(JsonObject &root) {
|
bool readFromConfig(JsonObject &root) {
|
||||||
int8_t oldPin[MULTI_RELAY_MAX_RELAYS];
|
int8_t oldPin[MULTI_RELAY_MAX_RELAYS];
|
||||||
|
|
||||||
JsonObject top = root[FPSTR(_name)];
|
JsonObject top = root[FPSTR(_name)];
|
||||||
@ -762,13 +587,7 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool configComplete = !top.isNull();
|
|
||||||
//configComplete &= getJsonValue(top[FPSTR(_enabled)], enabled);
|
|
||||||
enabled = top[FPSTR(_enabled)] | enabled;
|
enabled = top[FPSTR(_enabled)] | enabled;
|
||||||
usePcf8574 = top[FPSTR(_pcf8574)] | usePcf8574;
|
|
||||||
addrPcf8574 = top[FPSTR(_pcfAddress)] | addrPcf8574;
|
|
||||||
// if I2C is not globally initialised just ignore
|
|
||||||
if (i2c_sda<0 || i2c_scl<0) usePcf8574 = false;
|
|
||||||
periodicBroadcastSec = top[FPSTR(_broadcast)] | periodicBroadcastSec;
|
periodicBroadcastSec = top[FPSTR(_broadcast)] | periodicBroadcastSec;
|
||||||
periodicBroadcastSec = min(900,max(0,(int)periodicBroadcastSec));
|
periodicBroadcastSec = min(900,max(0,(int)periodicBroadcastSec));
|
||||||
HAautodiscovery = top[FPSTR(_HAautodiscovery)] | HAautodiscovery;
|
HAautodiscovery = top[FPSTR(_HAautodiscovery)] | HAautodiscovery;
|
||||||
@ -777,14 +596,14 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
|||||||
String parName = FPSTR(_relay_str); parName += '-'; parName += i;
|
String parName = FPSTR(_relay_str); parName += '-'; parName += i;
|
||||||
oldPin[i] = _relay[i].pin;
|
oldPin[i] = _relay[i].pin;
|
||||||
_relay[i].pin = top[parName]["pin"] | _relay[i].pin;
|
_relay[i].pin = top[parName]["pin"] | _relay[i].pin;
|
||||||
_relay[i].invert = top[parName][FPSTR(_activeHigh)] | _relay[i].invert;
|
_relay[i].mode = top[parName][FPSTR(_activeHigh)] | _relay[i].mode;
|
||||||
_relay[i].external = top[parName][FPSTR(_external)] | _relay[i].external;
|
_relay[i].external = top[parName][FPSTR(_external)] | _relay[i].external;
|
||||||
_relay[i].delay = top[parName][FPSTR(_delay_str)] | _relay[i].delay;
|
_relay[i].delay = top[parName][FPSTR(_delay_str)] | _relay[i].delay;
|
||||||
_relay[i].button = top[parName][FPSTR(_button)] | _relay[i].button;
|
_relay[i].button = top[parName][FPSTR(_button)] | _relay[i].button;
|
||||||
// begin backwards compatibility (beta) remove when 0.13 is released
|
// begin backwards compatibility (beta) remove when 0.13 is released
|
||||||
parName += '-';
|
parName += '-';
|
||||||
_relay[i].pin = top[parName+"pin"] | _relay[i].pin;
|
_relay[i].pin = top[parName+"pin"] | _relay[i].pin;
|
||||||
_relay[i].invert = top[parName+FPSTR(_activeHigh)] | _relay[i].invert;
|
_relay[i].mode = top[parName+FPSTR(_activeHigh)] | _relay[i].mode;
|
||||||
_relay[i].external = top[parName+FPSTR(_external)] | _relay[i].external;
|
_relay[i].external = top[parName+FPSTR(_external)] | _relay[i].external;
|
||||||
_relay[i].delay = top[parName+FPSTR(_delay_str)] | _relay[i].delay;
|
_relay[i].delay = top[parName+FPSTR(_delay_str)] | _relay[i].delay;
|
||||||
// end compatibility
|
// end compatibility
|
||||||
@ -798,17 +617,38 @@ bool MultiRelay::readFromConfig(JsonObject &root) {
|
|||||||
} else {
|
} else {
|
||||||
// deallocate all pins 1st
|
// deallocate all pins 1st
|
||||||
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++)
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++)
|
||||||
if (oldPin[i]>=0 && oldPin[i]<100) {
|
if (oldPin[i]>=0) {
|
||||||
pinManager.deallocatePin(oldPin[i], PinOwner::UM_MultiRelay);
|
pinManager.deallocatePin(oldPin[i], PinOwner::UM_MultiRelay);
|
||||||
}
|
}
|
||||||
// allocate new pins
|
// allocate new pins
|
||||||
setup();
|
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||||
|
if (_relay[i].pin>=0 && pinManager.allocatePin(_relay[i].pin, true, PinOwner::UM_MultiRelay)) {
|
||||||
|
if (!_relay[i].external) {
|
||||||
|
_relay[i].state = !offMode;
|
||||||
|
switchRelay(i, _relay[i].state);
|
||||||
|
_oldMode = offMode;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_relay[i].pin = -1;
|
||||||
|
}
|
||||||
|
_relay[i].active = false;
|
||||||
|
}
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return !top[FPSTR(_pcf8574)].isNull();
|
return !top[FPSTR(_HAautodiscovery)].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_MULTI_RELAY;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
const char MultiRelay::_name[] PROGMEM = "MultiRelay";
|
const char MultiRelay::_name[] PROGMEM = "MultiRelay";
|
||||||
const char MultiRelay::_enabled[] PROGMEM = "enabled";
|
const char MultiRelay::_enabled[] PROGMEM = "enabled";
|
||||||
@ -819,5 +659,3 @@ const char MultiRelay::_external[] PROGMEM = "external";
|
|||||||
const char MultiRelay::_button[] PROGMEM = "button";
|
const char MultiRelay::_button[] PROGMEM = "button";
|
||||||
const char MultiRelay::_broadcast[] PROGMEM = "broadcast-sec";
|
const char MultiRelay::_broadcast[] PROGMEM = "broadcast-sec";
|
||||||
const char MultiRelay::_HAautodiscovery[] PROGMEM = "HA-autodiscovery";
|
const char MultiRelay::_HAautodiscovery[] PROGMEM = "HA-autodiscovery";
|
||||||
const char MultiRelay::_pcf8574[] PROGMEM = "use-PCF8574";
|
|
||||||
const char MultiRelay::_pcfAddress[] PROGMEM = "PCF8574-address";
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Wire.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
#include <Adafruit_CCS811.h>
|
#include <Adafruit_CCS811.h>
|
||||||
@ -15,6 +12,14 @@ Adafruit_BMP280 bmp;
|
|||||||
Adafruit_Si7021 si7021;
|
Adafruit_Si7021 si7021;
|
||||||
Adafruit_CCS811 ccs811;
|
Adafruit_CCS811 ccs811;
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32 //ESP32 boards
|
||||||
|
uint8_t SCL_PIN = 22;
|
||||||
|
uint8_t SDA_PIN = 21;
|
||||||
|
#else //ESP8266 boards
|
||||||
|
uint8_t SCL_PIN = 5;
|
||||||
|
uint8_t SDA_PIN = 4;
|
||||||
|
#endif
|
||||||
|
|
||||||
class UserMod_SensorsToMQTT : public Usermod
|
class UserMod_SensorsToMQTT : public Usermod
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -222,6 +227,7 @@ public:
|
|||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.println("Starting!");
|
Serial.println("Starting!");
|
||||||
|
Wire.begin(SDA_PIN, SCL_PIN);
|
||||||
Serial.println("Initializing sensors.. ");
|
Serial.println("Initializing sensors.. ");
|
||||||
_initialize();
|
_initialize();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
# 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
|
|
@ -1,480 +0,0 @@
|
|||||||
#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 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 = nullptr; // 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();
|
|
||||||
inline bool isShtReady() { return shtInitDone; } // Checks if the SHT sensor has been initialised.
|
|
||||||
|
|
||||||
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); // uses &Wire
|
|
||||||
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;
|
|
||||||
shtTempHumidSensor = nullptr;
|
|
||||||
}
|
|
||||||
shtInitDone = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cleanup the mod completely.
|
|
||||||
*
|
|
||||||
* Calls ::cleanupShtTempHumiditySensor() to cleanup the SHT sensor and
|
|
||||||
* deallocates pins.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
void ShtUsermod::cleanup()
|
|
||||||
{
|
|
||||||
cleanupShtTempHumiditySensor();
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
// GPIOs can be set to -1 , so check they're gt zero
|
|
||||||
if (i2c_sda < 0 || i2c_scl < 0) {
|
|
||||||
DEBUG_PRINTF("[%s] I2C bus not initialised!\n", _name);
|
|
||||||
cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(getUnitString());
|
|
||||||
|
|
||||||
// sensor object
|
|
||||||
JsonObject sensor = root[F("sensor")];
|
|
||||||
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
|
|
||||||
|
|
||||||
jsonTemp = sensor.createNestedArray(F("temp"));
|
|
||||||
jsonTemp.add(getTemperature());
|
|
||||||
jsonTemp.add(getUnitString());
|
|
||||||
|
|
||||||
jsonHumidity = sensor.createNestedArray(F("humidity"));
|
|
||||||
jsonHumidity.add(getHumidity());
|
|
||||||
jsonHumidity.add(F(" RH"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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";
|
|
||||||
}
|
|
@ -1,7 +1,3 @@
|
|||||||
#ifndef WLED_ENABLE_MQTT
|
|
||||||
#error "This user mod requires MQTT to be enabled."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
# 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
|
|
@ -1,222 +0,0 @@
|
|||||||
#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<float>() * 100);
|
|
||||||
|
|
||||||
DEBUG_PRINT("Percent: ");
|
|
||||||
DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as<float>() * 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("<button class=\"btn btn-xs\" onclick=\"requestJson({");
|
|
||||||
uiDomString += FPSTR(_name);
|
|
||||||
uiDomString += F(":{");
|
|
||||||
uiDomString += FPSTR(_enabled);
|
|
||||||
uiDomString += enabled ? F(":false}});\">") : F(":true}});\">");
|
|
||||||
uiDomString += F("<i class=\"icons");
|
|
||||||
uiDomString += enabled ? F(" on") : F(" off");
|
|
||||||
uiDomString += F("\"></i>");
|
|
||||||
uiDomString += F("</button>");
|
|
||||||
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<bool>())
|
|
||||||
{
|
|
||||||
enabled = usermod[FPSTR(_enabled)].as<bool>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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";
|
|
@ -45,27 +45,7 @@
|
|||||||
#define ENCODER_SW_PIN 19
|
#define ENCODER_SW_PIN 19
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENCODER_MAX_DELAY_MS // max delay between polling encoder pins
|
// The last UI state, remove color and saturation option if diplay not active(too many options)
|
||||||
#define ENCODER_MAX_DELAY_MS 8 // 8 milliseconds => max 120 change impulses in 1 second, for full turn of a 30/30 encoder (4 changes per segment, 30 segments for one turn)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef USERMOD_USE_PCF8574
|
|
||||||
#undef USE_PCF8574
|
|
||||||
#define USE_PCF8574 false
|
|
||||||
#else
|
|
||||||
#undef USE_PCF8574
|
|
||||||
#define USE_PCF8574 true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PCF8574_ADDRESS
|
|
||||||
#define PCF8574_ADDRESS 0x20 // some may start at 0x38
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PCF8574_INT_PIN
|
|
||||||
#define PCF8574_INT_PIN -1 // GPIO connected to INT pin on PCF8574
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// The last UI state, remove color and saturation option if display not active (too many options)
|
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
#define LAST_UI_STATE 11
|
#define LAST_UI_STATE 11
|
||||||
#else
|
#else
|
||||||
@ -133,83 +113,62 @@ static int re_qstringCmp(const void *ap, const void *bp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static volatile uint8_t pcfPortData = 0; // port expander port state
|
|
||||||
static volatile uint8_t addrPcf8574 = PCF8574_ADDRESS; // has to be accessible in ISR
|
|
||||||
|
|
||||||
// Interrupt routine to read I2C rotary state
|
|
||||||
// if we are to use PCF8574 port expander we will need to rely on interrupts as polling I2C every 2ms
|
|
||||||
// is a waste of resources and causes 4LD to fail.
|
|
||||||
// in such case rely on ISR to read pin values and store them into static variable
|
|
||||||
static void IRAM_ATTR i2cReadingISR() {
|
|
||||||
Wire.requestFrom(addrPcf8574, 1U);
|
|
||||||
if (Wire.available()) {
|
|
||||||
pcfPortData = Wire.read();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RotaryEncoderUIUsermod : public Usermod {
|
class RotaryEncoderUIUsermod : public Usermod {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int8_t fadeAmount = 5; // Amount to change every step (brightness)
|
||||||
const int8_t fadeAmount; // Amount to change every step (brightness)
|
|
||||||
unsigned long loopTime;
|
unsigned long loopTime;
|
||||||
|
|
||||||
unsigned long buttonPressedTime;
|
unsigned long buttonPressedTime = 0;
|
||||||
unsigned long buttonWaitTime;
|
unsigned long buttonWaitTime = 0;
|
||||||
bool buttonPressedBefore;
|
bool buttonPressedBefore = false;
|
||||||
bool buttonLongPressed;
|
bool buttonLongPressed = false;
|
||||||
|
|
||||||
int8_t pinA; // DT from encoder
|
int8_t pinA = ENCODER_DT_PIN; // DT from encoder
|
||||||
int8_t pinB; // CLK from encoder
|
int8_t pinB = ENCODER_CLK_PIN; // CLK from encoder
|
||||||
int8_t pinC; // SW from encoder
|
int8_t pinC = ENCODER_SW_PIN; // SW from encoder
|
||||||
|
|
||||||
unsigned char select_state; // 0: brightness, 1: effect, 2: effect speed, ...
|
unsigned char select_state = 0; // 0: brightness, 1: effect, 2: effect speed, ...
|
||||||
|
|
||||||
uint16_t currentHue1; // default boot color
|
uint16_t currentHue1 = 16; // default boot color
|
||||||
byte currentSat1;
|
byte currentSat1 = 255;
|
||||||
uint8_t currentCCT;
|
|
||||||
|
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
FourLineDisplayUsermod *display;
|
FourLineDisplayUsermod *display;
|
||||||
#else
|
#else
|
||||||
void* display;
|
void* display = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pointers the start of the mode names within JSON_mode_names
|
// Pointers the start of the mode names within JSON_mode_names
|
||||||
const char **modes_qstrings;
|
const char **modes_qstrings = nullptr;
|
||||||
|
|
||||||
// Array of mode indexes in alphabetical order.
|
// Array of mode indexes in alphabetical order.
|
||||||
byte *modes_alpha_indexes;
|
byte *modes_alpha_indexes = nullptr;
|
||||||
|
|
||||||
// Pointers the start of the palette names within JSON_palette_names
|
// Pointers the start of the palette names within JSON_palette_names
|
||||||
const char **palettes_qstrings;
|
const char **palettes_qstrings = nullptr;
|
||||||
|
|
||||||
// Array of palette indexes in alphabetical order.
|
// Array of palette indexes in alphabetical order.
|
||||||
byte *palettes_alpha_indexes;
|
byte *palettes_alpha_indexes = nullptr;
|
||||||
|
|
||||||
struct { // reduce memory footprint
|
unsigned char Enc_A;
|
||||||
bool Enc_A : 1;
|
unsigned char Enc_B;
|
||||||
bool Enc_B : 1;
|
unsigned char Enc_A_prev = 0;
|
||||||
bool Enc_A_prev : 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool currentEffectAndPaletteInitialized;
|
bool currentEffectAndPaletteInitialized = false;
|
||||||
uint8_t effectCurrentIndex;
|
uint8_t effectCurrentIndex = 0;
|
||||||
uint8_t effectPaletteIndex;
|
uint8_t effectPaletteIndex = 0;
|
||||||
uint8_t knownMode;
|
uint8_t knownMode = 0;
|
||||||
uint8_t knownPalette;
|
uint8_t knownPalette = 0;
|
||||||
|
|
||||||
byte presetHigh;
|
uint8_t currentCCT = 128;
|
||||||
byte presetLow;
|
|
||||||
|
|
||||||
bool applyToAll;
|
byte presetHigh = 0;
|
||||||
|
byte presetLow = 0;
|
||||||
|
|
||||||
bool initDone;
|
bool applyToAll = true;
|
||||||
bool enabled;
|
|
||||||
|
|
||||||
bool usePcf8574;
|
bool initDone = false;
|
||||||
int8_t pinIRQ;
|
bool enabled = true;
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
static const char _name[];
|
static const char _name[];
|
||||||
@ -220,192 +179,19 @@ class RotaryEncoderUIUsermod : public Usermod {
|
|||||||
static const char _presetHigh[];
|
static const char _presetHigh[];
|
||||||
static const char _presetLow[];
|
static const char _presetLow[];
|
||||||
static const char _applyToAll[];
|
static const char _applyToAll[];
|
||||||
static const char _pcf8574[];
|
|
||||||
static const char _pcfAddress[];
|
|
||||||
static const char _pcfINTpin[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* readPin() - read rotary encoder pin value
|
|
||||||
*/
|
|
||||||
byte readPin(uint8_t pin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the modes and palettes to the index arrays
|
* Sort the modes and palettes to the index arrays
|
||||||
* modes_alpha_indexes and palettes_alpha_indexes.
|
* modes_alpha_indexes and palettes_alpha_indexes.
|
||||||
*/
|
*/
|
||||||
void sortModesAndPalettes();
|
void sortModesAndPalettes() {
|
||||||
byte *re_initIndexArray(int numModes);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an array of mode or palette names from the JSON string.
|
|
||||||
* They don't end in '\0', they end in '"'.
|
|
||||||
*/
|
|
||||||
const char **re_findModeStrings(const char json[], int numModes);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort either the modes or the palettes using quicksort.
|
|
||||||
*/
|
|
||||||
void re_sortModes(const char **modeNames, byte *indexes, int count, int numSkip);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
RotaryEncoderUIUsermod()
|
|
||||||
: fadeAmount(5)
|
|
||||||
, buttonPressedTime(0)
|
|
||||||
, buttonWaitTime(0)
|
|
||||||
, buttonPressedBefore(false)
|
|
||||||
, buttonLongPressed(false)
|
|
||||||
, pinA(ENCODER_DT_PIN)
|
|
||||||
, pinB(ENCODER_CLK_PIN)
|
|
||||||
, pinC(ENCODER_SW_PIN)
|
|
||||||
, select_state(0)
|
|
||||||
, currentHue1(16)
|
|
||||||
, currentSat1(255)
|
|
||||||
, currentCCT(128)
|
|
||||||
, display(nullptr)
|
|
||||||
, modes_qstrings(nullptr)
|
|
||||||
, modes_alpha_indexes(nullptr)
|
|
||||||
, palettes_qstrings(nullptr)
|
|
||||||
, palettes_alpha_indexes(nullptr)
|
|
||||||
, currentEffectAndPaletteInitialized(false)
|
|
||||||
, effectCurrentIndex(0)
|
|
||||||
, effectPaletteIndex(0)
|
|
||||||
, knownMode(0)
|
|
||||||
, knownPalette(0)
|
|
||||||
, presetHigh(0)
|
|
||||||
, presetLow(0)
|
|
||||||
, applyToAll(true)
|
|
||||||
, initDone(false)
|
|
||||||
, enabled(true)
|
|
||||||
, usePcf8574(USE_PCF8574)
|
|
||||||
, pinIRQ(PCF8574_INT_PIN)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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_ROTARY_ENC_UI; }
|
|
||||||
/**
|
|
||||||
* Enable/Disable the usermod
|
|
||||||
*/
|
|
||||||
inline void enable(bool enable) { if (!(pinA<0 || pinB<0 || pinC<0)) enabled = enable; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get usermod enabled/disabled state
|
|
||||||
*/
|
|
||||||
inline bool isEnabled() { return enabled; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* connected() is called every time the WiFi is (re)connected
|
|
||||||
* Use it to initialize network interfaces
|
|
||||||
*/
|
|
||||||
//void connected();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
|
||||||
*/
|
|
||||||
void loop();
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
//bool onMqttMessage(char* topic, char* payload);
|
|
||||||
//void onMqttConnect(bool sessionPresent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
|
|
||||||
*/
|
|
||||||
//void addToJsonInfo(JsonObject &root);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* provide the changeable values
|
|
||||||
*/
|
|
||||||
void addToConfig(JsonObject &root);
|
|
||||||
|
|
||||||
void appendConfigData();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* restore the changeable values
|
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
|
||||||
*
|
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
|
||||||
*/
|
|
||||||
bool readFromConfig(JsonObject &root);
|
|
||||||
|
|
||||||
// custom methods
|
|
||||||
void displayNetworkInfo();
|
|
||||||
void findCurrentEffectAndPalette();
|
|
||||||
bool changeState(const char *stateName, byte markedLine, byte markedCol, byte glyph);
|
|
||||||
void lampUdated();
|
|
||||||
void changeBrightness(bool increase);
|
|
||||||
void changeEffect(bool increase);
|
|
||||||
void changeEffectSpeed(bool increase);
|
|
||||||
void changeEffectIntensity(bool increase);
|
|
||||||
void changeCustom(uint8_t par, bool increase);
|
|
||||||
void changePalette(bool increase);
|
|
||||||
void changeHue(bool increase);
|
|
||||||
void changeSat(bool increase);
|
|
||||||
void changePreset(bool increase);
|
|
||||||
void changeCCT(bool increase);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* readPin() - read rotary encoder pin value
|
|
||||||
*/
|
|
||||||
byte RotaryEncoderUIUsermod::readPin(uint8_t pin) {
|
|
||||||
if (usePcf8574) {
|
|
||||||
if (pin >= 100) pin -= 100; // PCF I/O ports
|
|
||||||
return (pcfPortData>>pin) & 1;
|
|
||||||
} else {
|
|
||||||
return digitalRead(pin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort the modes and palettes to the index arrays
|
|
||||||
* modes_alpha_indexes and palettes_alpha_indexes.
|
|
||||||
*/
|
|
||||||
void RotaryEncoderUIUsermod::sortModesAndPalettes() {
|
|
||||||
DEBUG_PRINTLN(F("Sorting modes and palettes."));
|
|
||||||
//modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount());
|
//modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount());
|
||||||
modes_qstrings = strip.getModeDataSrc();
|
modes_qstrings = strip.getModeDataSrc();
|
||||||
modes_alpha_indexes = re_initIndexArray(strip.getModeCount());
|
modes_alpha_indexes = re_initIndexArray(strip.getModeCount());
|
||||||
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
|
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
|
||||||
|
|
||||||
palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount()+strip.customPalettes.size());
|
palettes_qstrings = re_findModeStrings(JSON_palette_names, strip.getPaletteCount());
|
||||||
palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount()+strip.customPalettes.size());
|
palettes_alpha_indexes = re_initIndexArray(strip.getPaletteCount()); // only use internal palettes
|
||||||
if (strip.customPalettes.size()) {
|
|
||||||
for (int i=0; i<strip.customPalettes.size(); i++) {
|
|
||||||
palettes_alpha_indexes[strip.getPaletteCount()+i] = 255-i;
|
|
||||||
palettes_qstrings[strip.getPaletteCount()+i] = PSTR("~Custom~");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// How many palette names start with '*' and should not be sorted?
|
// How many palette names start with '*' and should not be sorted?
|
||||||
// (Also skipping the first one, 'Default').
|
// (Also skipping the first one, 'Default').
|
||||||
@ -414,7 +200,7 @@ void RotaryEncoderUIUsermod::sortModesAndPalettes() {
|
|||||||
re_sortModes(palettes_qstrings, palettes_alpha_indexes, strip.getPaletteCount(), skipPaletteCount);
|
re_sortModes(palettes_qstrings, palettes_alpha_indexes, strip.getPaletteCount(), skipPaletteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) {
|
byte *re_initIndexArray(int numModes) {
|
||||||
byte *indexes = (byte *)malloc(sizeof(byte) * numModes);
|
byte *indexes = (byte *)malloc(sizeof(byte) * numModes);
|
||||||
for (byte i = 0; i < numModes; i++) {
|
for (byte i = 0; i < numModes; i++) {
|
||||||
indexes[i] = i;
|
indexes[i] = i;
|
||||||
@ -426,7 +212,7 @@ byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) {
|
|||||||
* Return an array of mode or palette names from the JSON string.
|
* Return an array of mode or palette names from the JSON string.
|
||||||
* They don't end in '\0', they end in '"'.
|
* They don't end in '\0', they end in '"'.
|
||||||
*/
|
*/
|
||||||
const char **RotaryEncoderUIUsermod::re_findModeStrings(const char json[], int numModes) {
|
const char **re_findModeStrings(const char json[], int numModes) {
|
||||||
const char **modeStrings = (const char **)malloc(sizeof(const char *) * numModes);
|
const char **modeStrings = (const char **)malloc(sizeof(const char *) * numModes);
|
||||||
uint8_t modeIndex = 0;
|
uint8_t modeIndex = 0;
|
||||||
bool insideQuotes = false;
|
bool insideQuotes = false;
|
||||||
@ -464,7 +250,7 @@ const char **RotaryEncoderUIUsermod::re_findModeStrings(const char json[], int n
|
|||||||
/**
|
/**
|
||||||
* Sort either the modes or the palettes using quicksort.
|
* Sort either the modes or the palettes using quicksort.
|
||||||
*/
|
*/
|
||||||
void RotaryEncoderUIUsermod::re_sortModes(const char **modeNames, byte *indexes, int count, int numSkip) {
|
void re_sortModes(const char **modeNames, byte *indexes, int count, int numSkip) {
|
||||||
if (!modeNames) return;
|
if (!modeNames) return;
|
||||||
listBeingSorted = modeNames;
|
listBeingSorted = modeNames;
|
||||||
qsort(indexes + numSkip, count - numSkip, sizeof(byte), re_qstringCmp);
|
qsort(indexes + numSkip, count - numSkip, sizeof(byte), re_qstringCmp);
|
||||||
@ -472,37 +258,21 @@ void RotaryEncoderUIUsermod::re_sortModes(const char **modeNames, byte *indexes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public methods
|
public:
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* setup() is called once at boot. WiFi is not yet connected at this point.
|
* setup() is called once at boot. WiFi is not yet connected at this point.
|
||||||
* You can use it to initialize variables, sensors or similar.
|
* You can use it to initialize variables, sensors or similar.
|
||||||
*/
|
*/
|
||||||
void RotaryEncoderUIUsermod::setup()
|
void setup()
|
||||||
{
|
{
|
||||||
DEBUG_PRINTLN(F("Usermod Rotary Encoder init."));
|
DEBUG_PRINTLN(F("Usermod Rotary Encoder init."));
|
||||||
|
|
||||||
if (usePcf8574) {
|
|
||||||
if (i2c_sda < 0 || i2c_scl < 0 || pinA < 0 || pinB < 0 || pinC < 0) {
|
|
||||||
DEBUG_PRINTLN(F("I2C and/or PCF8574 pins unused, disabling."));
|
|
||||||
enabled = false;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (pinIRQ >= 0 && pinManager.allocatePin(pinIRQ, false, PinOwner::UM_RotaryEncoderUI)) {
|
|
||||||
pinMode(pinIRQ, INPUT_PULLUP);
|
|
||||||
attachInterrupt(pinIRQ, i2cReadingISR, FALLING); // RISING, FALLING, CHANGE, ONLOW, ONHIGH
|
|
||||||
DEBUG_PRINTLN(F("Interrupt attached."));
|
|
||||||
} else {
|
|
||||||
DEBUG_PRINTLN(F("Unable to allocate interrupt pin, disabling."));
|
|
||||||
pinIRQ = -1;
|
|
||||||
enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } };
|
PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } };
|
||||||
if (pinA<0 || pinB<0 || !pinManager.allocateMultiplePins(pins, 3, PinOwner::UM_RotaryEncoderUI)) {
|
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
|
||||||
|
// (at second config)
|
||||||
|
// This is the exact type of bug solved by pinManager
|
||||||
|
// tracking the owner tags....
|
||||||
pinA = pinB = pinC = -1;
|
pinA = pinB = pinC = -1;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
return;
|
return;
|
||||||
@ -513,8 +283,7 @@ void RotaryEncoderUIUsermod::setup()
|
|||||||
#endif
|
#endif
|
||||||
pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
|
pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
|
||||||
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
|
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
|
||||||
if (pinC>=0) pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
|
pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
|
||||||
}
|
|
||||||
|
|
||||||
loopTime = millis();
|
loopTime = millis();
|
||||||
|
|
||||||
@ -532,11 +301,20 @@ void RotaryEncoderUIUsermod::setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
initDone = true;
|
initDone = true;
|
||||||
Enc_A = readPin(pinA); // Read encoder pins
|
Enc_A = digitalRead(pinA); // Read encoder pins
|
||||||
Enc_B = readPin(pinB);
|
Enc_B = digitalRead(pinB);
|
||||||
Enc_A_prev = Enc_A;
|
Enc_A_prev = Enc_A;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
* loop() is called continuously. Here you can check for events, read sensors, etc.
|
||||||
*
|
*
|
||||||
@ -547,11 +325,10 @@ void RotaryEncoderUIUsermod::setup()
|
|||||||
* 2. Try to avoid using the delay() function. NEVER use delays longer than 10 milliseconds.
|
* 2. Try to avoid using the delay() function. NEVER use delays longer than 10 milliseconds.
|
||||||
* Instead, use a timer check as shown here.
|
* Instead, use a timer check as shown here.
|
||||||
*/
|
*/
|
||||||
void RotaryEncoderUIUsermod::loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (!enabled) return;
|
if (!enabled || strip.isUpdating()) return;
|
||||||
unsigned long currentTime = millis(); // get the current elapsed time
|
unsigned long currentTime = millis(); // get the current elapsed time
|
||||||
if (strip.isUpdating() && ((currentTime - loopTime) < ENCODER_MAX_DELAY_MS)) return; // be nice, but not too nice
|
|
||||||
|
|
||||||
// Initialize effectCurrentIndex and effectPaletteIndex to
|
// Initialize effectCurrentIndex and effectPaletteIndex to
|
||||||
// current state. We do it here as (at least) effectCurrent
|
// current state. We do it here as (at least) effectCurrent
|
||||||
@ -562,13 +339,14 @@ void RotaryEncoderUIUsermod::loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
|
if (modes_alpha_indexes[effectCurrentIndex] != effectCurrent || palettes_alpha_indexes[effectPaletteIndex] != effectPalette) {
|
||||||
DEBUG_PRINTLN(F("Current mode or palette changed."));
|
|
||||||
currentEffectAndPaletteInitialized = false;
|
currentEffectAndPaletteInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTime >= (loopTime + 2)) // 2ms since last check of encoder = 500Hz
|
if (currentTime >= (loopTime + 2)) // 2ms since last check of encoder = 500Hz
|
||||||
{
|
{
|
||||||
bool buttonPressed = !readPin(pinC); //0=pressed, 1=released
|
loopTime = currentTime; // Updates loopTime
|
||||||
|
|
||||||
|
bool buttonPressed = !digitalRead(pinC); //0=pressed, 1=released
|
||||||
if (buttonPressed) {
|
if (buttonPressed) {
|
||||||
if (!buttonPressedBefore) buttonPressedTime = currentTime;
|
if (!buttonPressedBefore) buttonPressedTime = currentTime;
|
||||||
buttonPressedBefore = true;
|
buttonPressedBefore = true;
|
||||||
@ -635,8 +413,8 @@ void RotaryEncoderUIUsermod::loop()
|
|||||||
if (changedState) select_state = newState;
|
if (changedState) select_state = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
Enc_A = readPin(pinA); // Read encoder pins
|
Enc_A = digitalRead(pinA); // Read encoder pins
|
||||||
Enc_B = readPin(pinB);
|
Enc_B = digitalRead(pinB);
|
||||||
if ((Enc_A) && (!Enc_A_prev))
|
if ((Enc_A) && (!Enc_A_prev))
|
||||||
{ // A has gone from high to low
|
{ // A has gone from high to low
|
||||||
if (Enc_B == LOW) //changes to LOW so that then encoder registers a change at the very end of a pulse
|
if (Enc_B == LOW) //changes to LOW so that then encoder registers a change at the very end of a pulse
|
||||||
@ -675,41 +453,33 @@ void RotaryEncoderUIUsermod::loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Enc_A_prev = Enc_A; // Store value of A for next time
|
Enc_A_prev = Enc_A; // Store value of A for next time
|
||||||
loopTime = currentTime; // Updates loopTime
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::displayNetworkInfo() {
|
void displayNetworkInfo() {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
display->networkOverlay(PSTR("NETWORK INFO"), 10000);
|
display->networkOverlay(PSTR("NETWORK INFO"), 10000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::findCurrentEffectAndPalette() {
|
void findCurrentEffectAndPalette() {
|
||||||
DEBUG_PRINTLN(F("Finding current mode and palette."));
|
|
||||||
currentEffectAndPaletteInitialized = true;
|
currentEffectAndPaletteInitialized = true;
|
||||||
|
for (uint8_t i = 0; i < strip.getModeCount(); i++) {
|
||||||
effectCurrentIndex = 0;
|
|
||||||
for (int i = 0; i < strip.getModeCount(); i++) {
|
|
||||||
if (modes_alpha_indexes[i] == effectCurrent) {
|
if (modes_alpha_indexes[i] == effectCurrent) {
|
||||||
effectCurrentIndex = i;
|
effectCurrentIndex = i;
|
||||||
DEBUG_PRINTLN(F("Found current mode."));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
effectPaletteIndex = 0;
|
for (uint8_t i = 0; i < strip.getPaletteCount(); i++) {
|
||||||
DEBUG_PRINTLN(effectPalette);
|
|
||||||
for (uint8_t i = 0; i < strip.getPaletteCount()+strip.customPalettes.size(); i++) {
|
|
||||||
if (palettes_alpha_indexes[i] == effectPalette) {
|
if (palettes_alpha_indexes[i] == effectPalette) {
|
||||||
effectPaletteIndex = i;
|
effectPaletteIndex = i;
|
||||||
DEBUG_PRINTLN(F("Found palette."));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RotaryEncoderUIUsermod::changeState(const char *stateName, byte markedLine, byte markedCol, byte glyph) {
|
boolean changeState(const char *stateName, byte markedLine, byte markedCol, byte glyph) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display != nullptr) {
|
if (display != nullptr) {
|
||||||
if (display->wakeDisplay()) {
|
if (display->wakeDisplay()) {
|
||||||
@ -724,7 +494,7 @@ bool RotaryEncoderUIUsermod::changeState(const char *stateName, byte markedLine,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::lampUdated() {
|
void lampUdated() {
|
||||||
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
|
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
|
||||||
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
|
// 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)
|
//setValuesFromFirstSelectedSeg(); //to make transition work on main segment (should no longer be required)
|
||||||
@ -732,7 +502,7 @@ void RotaryEncoderUIUsermod::lampUdated() {
|
|||||||
updateInterfaces(CALL_MODE_BUTTON);
|
updateInterfaces(CALL_MODE_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeBrightness(bool increase) {
|
void changeBrightness(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -741,9 +511,7 @@ void RotaryEncoderUIUsermod::changeBrightness(bool increase) {
|
|||||||
}
|
}
|
||||||
display->updateRedrawTime();
|
display->updateRedrawTime();
|
||||||
#endif
|
#endif
|
||||||
//bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
|
bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
|
||||||
if (bri < 40) bri = max(min((increase ? bri+fadeAmount/2 : bri-fadeAmount/2), 255), 0); // slower steps when brightness < 16%
|
|
||||||
else bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
|
|
||||||
lampUdated();
|
lampUdated();
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
display->updateBrightness();
|
display->updateBrightness();
|
||||||
@ -751,7 +519,7 @@ void RotaryEncoderUIUsermod::changeBrightness(bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeEffect(bool increase) {
|
void changeEffect(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -780,7 +548,7 @@ void RotaryEncoderUIUsermod::changeEffect(bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeEffectSpeed(bool increase) {
|
void changeEffectSpeed(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -808,7 +576,7 @@ void RotaryEncoderUIUsermod::changeEffectSpeed(bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeEffectIntensity(bool increase) {
|
void changeEffectIntensity(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -836,7 +604,7 @@ void RotaryEncoderUIUsermod::changeEffectIntensity(bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeCustom(uint8_t par, bool increase) {
|
void changeCustom(uint8_t par, bool increase) {
|
||||||
uint8_t val = 0;
|
uint8_t val = 0;
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
@ -881,7 +649,7 @@ void RotaryEncoderUIUsermod::changeCustom(uint8_t par, bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changePalette(bool increase) {
|
void changePalette(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -890,7 +658,7 @@ void RotaryEncoderUIUsermod::changePalette(bool increase) {
|
|||||||
}
|
}
|
||||||
display->updateRedrawTime();
|
display->updateRedrawTime();
|
||||||
#endif
|
#endif
|
||||||
effectPaletteIndex = max(min((unsigned)(increase ? effectPaletteIndex+1 : effectPaletteIndex-1), strip.getPaletteCount()+strip.customPalettes.size()-1), 0U);
|
effectPaletteIndex = max(min((increase ? effectPaletteIndex+1 : effectPaletteIndex-1), strip.getPaletteCount()-1), 0);
|
||||||
effectPalette = palettes_alpha_indexes[effectPaletteIndex];
|
effectPalette = palettes_alpha_indexes[effectPaletteIndex];
|
||||||
stateChanged = true;
|
stateChanged = true;
|
||||||
if (applyToAll) {
|
if (applyToAll) {
|
||||||
@ -910,7 +678,7 @@ void RotaryEncoderUIUsermod::changePalette(bool increase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeHue(bool increase){
|
void changeHue(bool increase){
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -940,7 +708,7 @@ void RotaryEncoderUIUsermod::changeHue(bool increase){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeSat(bool increase){
|
void changeSat(bool increase){
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -969,7 +737,7 @@ void RotaryEncoderUIUsermod::changeSat(bool increase){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changePreset(bool increase) {
|
void changePreset(bool increase) {
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -1001,7 +769,7 @@ void RotaryEncoderUIUsermod::changePreset(bool increase) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::changeCCT(bool increase){
|
void changeCCT(bool increase){
|
||||||
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
#ifdef USERMOD_FOUR_LINE_DISPLAY
|
||||||
if (display && display->wakeDisplay()) {
|
if (display && display->wakeDisplay()) {
|
||||||
display->redraw(true);
|
display->redraw(true);
|
||||||
@ -1035,7 +803,7 @@ void RotaryEncoderUIUsermod::changeCCT(bool increase){
|
|||||||
* Below it is shown how this could be used for e.g. a light sensor
|
* Below it is shown how this could be used for e.g. a light sensor
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
void RotaryEncoderUIUsermod::addToJsonInfo(JsonObject& root)
|
void addToJsonInfo(JsonObject& root)
|
||||||
{
|
{
|
||||||
int reading = 20;
|
int reading = 20;
|
||||||
//this code adds "u":{"Light":[20," lux"]} to the info object
|
//this code adds "u":{"Light":[20," lux"]} to the info object
|
||||||
@ -1052,7 +820,7 @@ void RotaryEncoderUIUsermod::addToJsonInfo(JsonObject& root)
|
|||||||
* Values in the state object may be modified by connected clients
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
void RotaryEncoderUIUsermod::addToJsonState(JsonObject &root)
|
void addToJsonState(JsonObject &root)
|
||||||
{
|
{
|
||||||
//root["user0"] = userVar0;
|
//root["user0"] = userVar0;
|
||||||
}
|
}
|
||||||
@ -1063,7 +831,7 @@ void RotaryEncoderUIUsermod::addToJsonState(JsonObject &root)
|
|||||||
* Values in the state object may be modified by connected clients
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
void RotaryEncoderUIUsermod::readFromJsonState(JsonObject &root)
|
void readFromJsonState(JsonObject &root)
|
||||||
{
|
{
|
||||||
//userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
|
//userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
|
||||||
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
|
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
|
||||||
@ -1073,7 +841,7 @@ void RotaryEncoderUIUsermod::readFromJsonState(JsonObject &root)
|
|||||||
/**
|
/**
|
||||||
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
||||||
*/
|
*/
|
||||||
void RotaryEncoderUIUsermod::addToConfig(JsonObject &root) {
|
void addToConfig(JsonObject &root) {
|
||||||
// we add JSON object: {"Rotary-Encoder":{"DT-pin":12,"CLK-pin":14,"SW-pin":13}}
|
// we add JSON object: {"Rotary-Encoder":{"DT-pin":12,"CLK-pin":14,"SW-pin":13}}
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
||||||
top[FPSTR(_enabled)] = enabled;
|
top[FPSTR(_enabled)] = enabled;
|
||||||
@ -1083,23 +851,15 @@ void RotaryEncoderUIUsermod::addToConfig(JsonObject &root) {
|
|||||||
top[FPSTR(_presetLow)] = presetLow;
|
top[FPSTR(_presetLow)] = presetLow;
|
||||||
top[FPSTR(_presetHigh)] = presetHigh;
|
top[FPSTR(_presetHigh)] = presetHigh;
|
||||||
top[FPSTR(_applyToAll)] = applyToAll;
|
top[FPSTR(_applyToAll)] = applyToAll;
|
||||||
top[FPSTR(_pcf8574)] = usePcf8574;
|
|
||||||
top[FPSTR(_pcfAddress)] = addrPcf8574;
|
|
||||||
top[FPSTR(_pcfINTpin)] = pinIRQ;
|
|
||||||
DEBUG_PRINTLN(F("Rotary Encoder config saved."));
|
DEBUG_PRINTLN(F("Rotary Encoder config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotaryEncoderUIUsermod::appendConfigData() {
|
|
||||||
oappend(SET_F("addInfo('Rotary-Encoder:PCF8574-address',1,'<i>(not hex!)</i>');"));
|
|
||||||
oappend(SET_F("d.extra.push({'Rotary-Encoder':{pin:[['P0',100],['P1',101],['P2',102],['P3',103],['P4',104],['P5',105],['P6',106],['P7',107]]}});"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
||||||
*
|
*
|
||||||
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
* The function should return true if configuration was successfully loaded or false if there was no configuration.
|
||||||
*/
|
*/
|
||||||
bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
bool readFromConfig(JsonObject &root) {
|
||||||
// we look for JSON object: {"Rotary-Encoder":{"DT-pin":12,"CLK-pin":14,"SW-pin":13}}
|
// we look for JSON object: {"Rotary-Encoder":{"DT-pin":12,"CLK-pin":14,"SW-pin":13}}
|
||||||
JsonObject top = root[FPSTR(_name)];
|
JsonObject top = root[FPSTR(_name)];
|
||||||
if (top.isNull()) {
|
if (top.isNull()) {
|
||||||
@ -1110,8 +870,6 @@ bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
|||||||
int8_t newDTpin = top[FPSTR(_DT_pin)] | pinA;
|
int8_t newDTpin = top[FPSTR(_DT_pin)] | pinA;
|
||||||
int8_t newCLKpin = top[FPSTR(_CLK_pin)] | pinB;
|
int8_t newCLKpin = top[FPSTR(_CLK_pin)] | pinB;
|
||||||
int8_t newSWpin = top[FPSTR(_SW_pin)] | pinC;
|
int8_t newSWpin = top[FPSTR(_SW_pin)] | pinC;
|
||||||
int8_t newIRQpin = top[FPSTR(_pcfINTpin)] | pinIRQ;
|
|
||||||
bool oldPcf8574 = usePcf8574;
|
|
||||||
|
|
||||||
presetHigh = top[FPSTR(_presetHigh)] | presetHigh;
|
presetHigh = top[FPSTR(_presetHigh)] | presetHigh;
|
||||||
presetLow = top[FPSTR(_presetLow)] | presetLow;
|
presetLow = top[FPSTR(_presetLow)] | presetLow;
|
||||||
@ -1121,9 +879,6 @@ bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
|||||||
enabled = top[FPSTR(_enabled)] | enabled;
|
enabled = top[FPSTR(_enabled)] | enabled;
|
||||||
applyToAll = top[FPSTR(_applyToAll)] | applyToAll;
|
applyToAll = top[FPSTR(_applyToAll)] | applyToAll;
|
||||||
|
|
||||||
usePcf8574 = top[FPSTR(_pcf8574)] | usePcf8574;
|
|
||||||
addrPcf8574 = top[FPSTR(_pcfAddress)] | addrPcf8574;
|
|
||||||
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
if (!initDone) {
|
||||||
// first run: reading from cfg.json
|
// first run: reading from cfg.json
|
||||||
@ -1134,20 +889,10 @@ bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
|||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
// changing parameters from settings page
|
// changing parameters from settings page
|
||||||
if (pinA!=newDTpin || pinB!=newCLKpin || pinC!=newSWpin || pinIRQ!=newIRQpin) {
|
if (pinA!=newDTpin || pinB!=newCLKpin || pinC!=newSWpin) {
|
||||||
if (oldPcf8574) {
|
|
||||||
if (pinIRQ >= 0) {
|
|
||||||
detachInterrupt(pinIRQ);
|
|
||||||
pinManager.deallocatePin(pinIRQ, PinOwner::UM_RotaryEncoderUI);
|
|
||||||
DEBUG_PRINTLN(F("Deallocated old IRQ pin."));
|
|
||||||
}
|
|
||||||
pinIRQ = newIRQpin<100 ? newIRQpin : -1; // ignore PCF8574 pins
|
|
||||||
} else {
|
|
||||||
pinManager.deallocatePin(pinA, PinOwner::UM_RotaryEncoderUI);
|
pinManager.deallocatePin(pinA, PinOwner::UM_RotaryEncoderUI);
|
||||||
pinManager.deallocatePin(pinB, PinOwner::UM_RotaryEncoderUI);
|
pinManager.deallocatePin(pinB, PinOwner::UM_RotaryEncoderUI);
|
||||||
pinManager.deallocatePin(pinC, PinOwner::UM_RotaryEncoderUI);
|
pinManager.deallocatePin(pinC, PinOwner::UM_RotaryEncoderUI);
|
||||||
DEBUG_PRINTLN(F("Deallocated old pins."));
|
|
||||||
}
|
|
||||||
pinA = newDTpin;
|
pinA = newDTpin;
|
||||||
pinB = newCLKpin;
|
pinB = newCLKpin;
|
||||||
pinC = newSWpin;
|
pinC = newSWpin;
|
||||||
@ -1159,9 +904,18 @@ bool RotaryEncoderUIUsermod::readFromConfig(JsonObject &root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
return !top[FPSTR(_pcfINTpin)].isNull();
|
return !top[FPSTR(_applyToAll)].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_ROTARY_ENC_UI;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
const char RotaryEncoderUIUsermod::_name[] PROGMEM = "Rotary-Encoder";
|
const char RotaryEncoderUIUsermod::_name[] PROGMEM = "Rotary-Encoder";
|
||||||
@ -1172,6 +926,3 @@ const char RotaryEncoderUIUsermod::_SW_pin[] PROGMEM = "SW-pin";
|
|||||||
const char RotaryEncoderUIUsermod::_presetHigh[] PROGMEM = "preset-high";
|
const char RotaryEncoderUIUsermod::_presetHigh[] PROGMEM = "preset-high";
|
||||||
const char RotaryEncoderUIUsermod::_presetLow[] PROGMEM = "preset-low";
|
const char RotaryEncoderUIUsermod::_presetLow[] PROGMEM = "preset-low";
|
||||||
const char RotaryEncoderUIUsermod::_applyToAll[] PROGMEM = "apply-2-all-seg";
|
const char RotaryEncoderUIUsermod::_applyToAll[] PROGMEM = "apply-2-all-seg";
|
||||||
const char RotaryEncoderUIUsermod::_pcf8574[] PROGMEM = "use-PCF8574";
|
|
||||||
const char RotaryEncoderUIUsermod::_pcfAddress[] PROGMEM = "PCF8574-address";
|
|
||||||
const char RotaryEncoderUIUsermod::_pcfINTpin[] PROGMEM = "PCF8574-INT-pin";
|
|
||||||
|
@ -25,7 +25,6 @@ class WordClockUsermod : public Usermod
|
|||||||
bool displayItIs = false;
|
bool displayItIs = false;
|
||||||
int ledOffset = 100;
|
int ledOffset = 100;
|
||||||
bool meander = false;
|
bool meander = false;
|
||||||
bool nord = false;
|
|
||||||
|
|
||||||
// defines for mask sizes
|
// defines for mask sizes
|
||||||
#define maskSizeLeds 114
|
#define maskSizeLeds 114
|
||||||
@ -38,44 +37,39 @@ class WordClockUsermod : public Usermod
|
|||||||
|
|
||||||
// "minute" masks
|
// "minute" masks
|
||||||
// Normal wiring
|
// Normal wiring
|
||||||
const int maskMinutes[14][maskSizeMinutes] =
|
const int maskMinutes[12][maskSizeMinutes] =
|
||||||
{
|
{
|
||||||
{107, 108, 109, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 0 - 00
|
{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}, // 1 - 05 fünf nach
|
{ 7, 8, 9, 10, 40, 41, 42, 43, -1, -1, -1, -1}, // :05 fünf nach
|
||||||
{ 11, 12, 13, 14, 40, 41, 42, 43, -1, -1, -1, -1}, // 2 - 10 zehn nach
|
{ 11, 12, 13, 14, 40, 41, 42, 43, -1, -1, -1, -1}, // :10 zehn nach
|
||||||
{ 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1}, // 3 - 15 viertel
|
{ 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1}, // :15 viertel
|
||||||
{ 15, 16, 17, 18, 19, 20, 21, 40, 41, 42, 43, -1}, // 4 - 20 zwanzig nach
|
{ 15, 16, 17, 18, 19, 20, 21, 40, 41, 42, 43, -1}, // :20 zwanzig nach
|
||||||
{ 7, 8, 9, 10, 33, 34, 35, 44, 45, 46, 47, -1}, // 5 - 25 fünf vor halb
|
{ 7, 8, 9, 10, 33, 34, 35, 44, 45, 46, 47, -1}, // :25 fünf vor halb
|
||||||
{ 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, -1, -1}, // 6 - 30 halb
|
{ 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, -1, -1}, // :30 halb
|
||||||
{ 7, 8, 9, 10, 40, 41, 42, 43, 44, 45, 46, 47}, // 7 - 35 fünf nach halb
|
{ 7, 8, 9, 10, 40, 41, 42, 43, 44, 45, 46, 47}, // :35 fünf nach halb
|
||||||
{ 15, 16, 17, 18, 19, 20, 21, 33, 34, 35, -1, -1}, // 8 - 40 zwanzig vor
|
{ 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}, // 9 - 45 dreiviertel
|
{ 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}, // 10 - 50 zehn vor
|
{ 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}, // 11 - 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}, // 12 - 15 alternative viertel nach
|
|
||||||
{ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1} // 13 - 45 alternative viertel vor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Meander wiring
|
// Meander wiring
|
||||||
const int maskMinutesMea[14][maskSizeMinutesMea] =
|
const int maskMinutesMea[12][maskSizeMinutesMea] =
|
||||||
{
|
{
|
||||||
{ 99, 100, 101, -1, -1, -1, -1, -1, -1, -1, -1, -1}, // 0 - 00
|
{ 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}, // 1 - 05 fünf nach
|
{ 7, 8, 9, 10, 33, 34, 35, 36, -1, -1, -1, -1}, // :05 fünf nach
|
||||||
{ 18, 19, 20, 21, 33, 34, 35, 36, -1, -1, -1, -1}, // 2 - 10 zehn nach
|
{ 18, 19, 20, 21, 33, 34, 35, 36, -1, -1, -1, -1}, // :10 zehn nach
|
||||||
{ 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1}, // 3 - 15 viertel
|
{ 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1}, // :15 viertel
|
||||||
{ 11, 12, 13, 14, 15, 16, 17, 33, 34, 35, 36, -1}, // 4 - 20 zwanzig nach
|
{ 11, 12, 13, 14, 15, 16, 17, 33, 34, 35, 36, -1}, // :20 zwanzig nach
|
||||||
{ 7, 8, 9, 10, 41, 42, 43, 44, 45, 46, 47, -1}, // 5 - 25 fünf vor halb
|
{ 7, 8, 9, 10, 41, 42, 43, 44, 45, 46, 47, -1}, // :25 fünf vor halb
|
||||||
{ 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, -1, -1}, // 6 - 30 halb
|
{ 44, 45, 46, 47, -1, -1, -1, -1, -1, -1, -1, -1}, // :30 halb
|
||||||
{ 7, 8, 9, 10, 33, 34, 35, 36, 44, 45, 46, 47}, // 7 - 35 fünf nach halb
|
{ 7, 8, 9, 10, 33, 34, 35, 36, 44, 45, 46, 47}, // :35 fünf nach halb
|
||||||
{ 11, 12, 13, 14, 15, 16, 17, 41, 42, 43, -1, -1}, // 8 - 40 zwanzig vor
|
{ 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}, // 9 - 45 dreiviertel
|
{ 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}, // 10 - 50 zehn vor
|
{ 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}, // 11 - 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}, // 12 - 15 alternative viertel nach
|
|
||||||
{ 26, 27, 28, 29, 30, 31, 32, 41, 42, 43, -1, -1} // 13 - 45 alternative viertel vor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// hour masks
|
// hour masks
|
||||||
// Normal wiring
|
// Normal wiring
|
||||||
const int maskHours[13][maskSizeHours] =
|
const int maskHours[13][maskSizeHours] =
|
||||||
@ -248,15 +242,9 @@ class WordClockUsermod : public Usermod
|
|||||||
setHours(hours, false);
|
setHours(hours, false);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (nord) {
|
|
||||||
// viertel nach
|
|
||||||
setMinutes(12);
|
|
||||||
setHours(hours, false);
|
|
||||||
} else {
|
|
||||||
// viertel
|
// viertel
|
||||||
setMinutes(3);
|
setMinutes(3);
|
||||||
setHours(hours + 1, false);
|
setHours(hours + 1, false);
|
||||||
};
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// 20 nach
|
// 20 nach
|
||||||
@ -285,13 +273,7 @@ class WordClockUsermod : public Usermod
|
|||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
// viertel vor
|
// viertel vor
|
||||||
if (nord) {
|
|
||||||
setMinutes(13);
|
|
||||||
}
|
|
||||||
// dreiviertel
|
|
||||||
else {
|
|
||||||
setMinutes(9);
|
setMinutes(9);
|
||||||
}
|
|
||||||
setHours(hours + 1, false);
|
setHours(hours + 1, false);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
@ -423,18 +405,11 @@ class WordClockUsermod : public Usermod
|
|||||||
*/
|
*/
|
||||||
void addToConfig(JsonObject& root)
|
void addToConfig(JsonObject& root)
|
||||||
{
|
{
|
||||||
JsonObject top = root.createNestedObject(F("WordClockUsermod"));
|
JsonObject top = root.createNestedObject("WordClockUsermod");
|
||||||
top[F("active")] = usermodActive;
|
top["active"] = usermodActive;
|
||||||
top[F("displayItIs")] = displayItIs;
|
top["displayItIs"] = displayItIs;
|
||||||
top[F("ledOffset")] = ledOffset;
|
top["ledOffset"] = ledOffset;
|
||||||
top[F("Meander wiring?")] = meander;
|
top["Meander wiring?"] = meander;
|
||||||
top[F("Norddeutsch")] = nord;
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendConfigData()
|
|
||||||
{
|
|
||||||
oappend(SET_F("addInfo('WordClockUsermod:ledOffset', 1, 'Number of LEDs before the letters');"));
|
|
||||||
oappend(SET_F("addInfo('WordClockUsermod:Norddeutsch', 1, 'Viertel vor instead of Dreiviertel');"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -457,15 +432,14 @@ class WordClockUsermod : public Usermod
|
|||||||
// default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor
|
// 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)
|
// 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[F("WordClockUsermod")];
|
JsonObject top = root["WordClockUsermod"];
|
||||||
|
|
||||||
bool configComplete = !top.isNull();
|
bool configComplete = !top.isNull();
|
||||||
|
|
||||||
configComplete &= getJsonValue(top[F("active")], usermodActive);
|
configComplete &= getJsonValue(top["active"], usermodActive);
|
||||||
configComplete &= getJsonValue(top[F("displayItIs")], displayItIs);
|
configComplete &= getJsonValue(top["displayItIs"], displayItIs);
|
||||||
configComplete &= getJsonValue(top[F("ledOffset")], ledOffset);
|
configComplete &= getJsonValue(top["ledOffset"], ledOffset);
|
||||||
configComplete &= getJsonValue(top[F("Meander wiring?")], meander);
|
configComplete &= getJsonValue(top["Meander wiring?"], meander);
|
||||||
configComplete &= getJsonValue(top[F("Norddeutsch")], nord);
|
|
||||||
|
|
||||||
return configComplete;
|
return configComplete;
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
# Example PlatformIO Project Configuration Override for WireGuard
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Copy to platformio_override.ini to activate.
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Please visit documentation: https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[platformio]
|
|
||||||
default_envs = WLED_ESP32-WireGuard
|
|
||||||
|
|
||||||
[env:WLED_ESP32-WireGuard]
|
|
||||||
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-WireGuard
|
|
||||||
-D USERMOD_WIREGUARD
|
|
||||||
lib_deps = ${esp32.lib_deps}
|
|
||||||
https://github.com/kienvu58/WireGuard-ESP32-Arduino.git
|
|
||||||
monitor_filters = esp32_exception_decoder
|
|
||||||
board_build.partitions = ${esp32.default_partitions}
|
|
||||||
upload_speed = 921600
|
|
@ -1,19 +0,0 @@
|
|||||||
# WireGuard VPN
|
|
||||||
|
|
||||||
This usermod will connect your WLED instance to a remote WireGuard subnet.
|
|
||||||
|
|
||||||
Configuration is performed via the Usermod menu. There are no parameters to set in code!
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
Copy the `platformio_override.ini` file to the root project directory, review the build options, and select the `WLED_ESP32-WireGuard` environment.
|
|
||||||
|
|
||||||
|
|
||||||
## Author
|
|
||||||
|
|
||||||
Aiden Vigue [vigue.me](https://vigue.me)
|
|
||||||
[@acvigue](https://github.com/acvigue)
|
|
||||||
aiden@vigue.me
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,127 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <WireGuard-ESP32.h>
|
|
||||||
|
|
||||||
#include "wled.h"
|
|
||||||
|
|
||||||
class WireguardUsermod : public Usermod {
|
|
||||||
public:
|
|
||||||
void setup() { configTzTime(posix_tz, ntpServerName); }
|
|
||||||
|
|
||||||
void connected() {
|
|
||||||
if (wg.is_initialized()) {
|
|
||||||
wg.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (millis() - lastTime > 5000) {
|
|
||||||
if (is_enabled && WLED_CONNECTED) {
|
|
||||||
if (!wg.is_initialized()) {
|
|
||||||
struct tm timeinfo;
|
|
||||||
if (getLocalTime(&timeinfo, 0)) {
|
|
||||||
if (strlen(preshared_key) < 1) {
|
|
||||||
wg.begin(local_ip, private_key, endpoint_address, public_key, endpoint_port, NULL);
|
|
||||||
} else {
|
|
||||||
wg.begin(local_ip, private_key, endpoint_address, public_key, endpoint_port, preshared_key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastTime = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject& root) {
|
|
||||||
JsonObject user = root["u"];
|
|
||||||
if (user.isNull()) user = root.createNestedObject("u");
|
|
||||||
|
|
||||||
JsonArray infoArr = user.createNestedArray(F("WireGuard"));
|
|
||||||
String uiDomString;
|
|
||||||
|
|
||||||
struct tm timeinfo;
|
|
||||||
if (!getLocalTime(&timeinfo, 0)) {
|
|
||||||
uiDomString = "Time out of sync!";
|
|
||||||
} else {
|
|
||||||
if (wg.is_initialized()) {
|
|
||||||
uiDomString = "netif up!";
|
|
||||||
} else {
|
|
||||||
uiDomString = "netif down :(";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_enabled) infoArr.add(uiDomString);
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendConfigData() {
|
|
||||||
oappend(SET_F("addInfo('WireGuard:host',1,'Server Hostname');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:port',1,'Server Port');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:ip',1,'Device IP');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:psk',1,'Pre Shared Key (optional)');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:pem',1,'Private Key');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:pub',1,'Public Key');")); // 0 is field type, 1 is actual field
|
|
||||||
oappend(SET_F("addInfo('WireGuard:tz',1,'POSIX timezone string');")); // 0 is field type, 1 is actual field
|
|
||||||
}
|
|
||||||
|
|
||||||
void addToConfig(JsonObject& root) {
|
|
||||||
JsonObject top = root.createNestedObject(F("WireGuard"));
|
|
||||||
top[F("host")] = endpoint_address;
|
|
||||||
top[F("port")] = endpoint_port;
|
|
||||||
top[F("ip")] = local_ip.toString();
|
|
||||||
top[F("psk")] = preshared_key;
|
|
||||||
top[F("pem")] = private_key;
|
|
||||||
top[F("pub")] = public_key;
|
|
||||||
top[F("tz")] = posix_tz;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readFromConfig(JsonObject& root) {
|
|
||||||
JsonObject top = root[F("WireGuard")];
|
|
||||||
|
|
||||||
if (top["host"].isNull() || top["port"].isNull() || top["ip"].isNull() || top["pem"].isNull() || top["pub"].isNull() || top["tz"].isNull()) {
|
|
||||||
is_enabled = false;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
const char* host = top["host"];
|
|
||||||
strncpy(endpoint_address, host, 100);
|
|
||||||
|
|
||||||
const char* ip_s = top["ip"];
|
|
||||||
uint8_t ip[4];
|
|
||||||
sscanf(ip_s, "%u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]);
|
|
||||||
local_ip = IPAddress(ip[0], ip[1], ip[2], ip[3]);
|
|
||||||
|
|
||||||
const char* pem = top["pem"];
|
|
||||||
strncpy(private_key, pem, 45);
|
|
||||||
|
|
||||||
const char* pub = top["pub"];
|
|
||||||
strncpy(public_key, pub, 45);
|
|
||||||
|
|
||||||
const char* tz = top["tz"];
|
|
||||||
strncpy(posix_tz, tz, 150);
|
|
||||||
|
|
||||||
endpoint_port = top["port"];
|
|
||||||
|
|
||||||
if (!top["psk"].isNull()) {
|
|
||||||
const char* psk = top["psk"];
|
|
||||||
strncpy(preshared_key, psk, 45);
|
|
||||||
}
|
|
||||||
|
|
||||||
is_enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getId() { return USERMOD_ID_WIREGUARD; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
WireGuard wg;
|
|
||||||
char preshared_key[45];
|
|
||||||
char private_key[45];
|
|
||||||
IPAddress local_ip;
|
|
||||||
char public_key[45];
|
|
||||||
char endpoint_address[100];
|
|
||||||
char posix_tz[150];
|
|
||||||
int endpoint_port = 0;
|
|
||||||
bool is_enabled = false;
|
|
||||||
unsigned long lastTime = 0;
|
|
||||||
};
|
|
@ -75,10 +75,6 @@ class WizLightsUsermod : public Usermod {
|
|||||||
UDP.endPacket();
|
UDP.endPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override definition so it compiles
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Check millis() rollover
|
// TODO: Check millis() rollover
|
||||||
|
25
wled00.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.28010.2046
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wled00", "wled00\wled00.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {9A679C2B-61D3-400B-B96F-06E604E9CED2}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
1455
wled00/FX.cpp
245
wled00/FX.h
@ -72,12 +72,8 @@
|
|||||||
#ifndef MAX_NUM_SEGMENTS
|
#ifndef MAX_NUM_SEGMENTS
|
||||||
#define MAX_NUM_SEGMENTS 32
|
#define MAX_NUM_SEGMENTS 32
|
||||||
#endif
|
#endif
|
||||||
#if defined(ARDUINO_ARCH_ESP32S2)
|
|
||||||
#define MAX_SEGMENT_DATA 24576
|
|
||||||
#else
|
|
||||||
#define MAX_SEGMENT_DATA 32767
|
#define MAX_SEGMENT_DATA 32767
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* How much data bytes each segment should max allocate to leave enough space for other segments,
|
/* How much data bytes each segment should max allocate to leave enough space for other segments,
|
||||||
assuming each segment uses the same amount of data. 256 for ESP8266, 640 for ESP32. */
|
assuming each segment uses the same amount of data. 256 for ESP8266, 640 for ESP32. */
|
||||||
@ -147,7 +143,7 @@
|
|||||||
#define FX_MODE_SAW 16
|
#define FX_MODE_SAW 16
|
||||||
#define FX_MODE_TWINKLE 17
|
#define FX_MODE_TWINKLE 17
|
||||||
#define FX_MODE_DISSOLVE 18
|
#define FX_MODE_DISSOLVE 18
|
||||||
#define FX_MODE_DISSOLVE_RANDOM 19 // candidate for removal (use Dissolve with with check 3)
|
#define FX_MODE_DISSOLVE_RANDOM 19
|
||||||
#define FX_MODE_SPARKLE 20
|
#define FX_MODE_SPARKLE 20
|
||||||
#define FX_MODE_FLASH_SPARKLE 21
|
#define FX_MODE_FLASH_SPARKLE 21
|
||||||
#define FX_MODE_HYPER_SPARKLE 22
|
#define FX_MODE_HYPER_SPARKLE 22
|
||||||
@ -176,7 +172,7 @@
|
|||||||
#define FX_MODE_FIRE_FLICKER 45
|
#define FX_MODE_FIRE_FLICKER 45
|
||||||
#define FX_MODE_GRADIENT 46
|
#define FX_MODE_GRADIENT 46
|
||||||
#define FX_MODE_LOADING 47
|
#define FX_MODE_LOADING 47
|
||||||
#define FX_MODE_ROLLINGBALLS 48 //was Police before 0.14
|
// #define FX_MODE_POLICE 48 // removed in 0.14!
|
||||||
#define FX_MODE_FAIRY 49 //was Police All prior to 0.13.0-b6 (use "Two Dots" with Red/Blue and full intensity)
|
#define FX_MODE_FAIRY 49 //was Police All prior to 0.13.0-b6 (use "Two Dots" with Red/Blue and full intensity)
|
||||||
#define FX_MODE_TWO_DOTS 50
|
#define FX_MODE_TWO_DOTS 50
|
||||||
#define FX_MODE_FAIRYTWINKLE 51 //was Two Areas prior to 0.13.0-b6 (use "Two Dots" with full intensity)
|
#define FX_MODE_FAIRYTWINKLE 51 //was Two Areas prior to 0.13.0-b6 (use "Two Dots" with full intensity)
|
||||||
@ -231,7 +227,7 @@
|
|||||||
#define FX_MODE_HEARTBEAT 100
|
#define FX_MODE_HEARTBEAT 100
|
||||||
#define FX_MODE_PACIFICA 101
|
#define FX_MODE_PACIFICA 101
|
||||||
#define FX_MODE_CANDLE_MULTI 102
|
#define FX_MODE_CANDLE_MULTI 102
|
||||||
#define FX_MODE_SOLID_GLITTER 103 // candidate for removal (use glitter)
|
#define FX_MODE_SOLID_GLITTER 103
|
||||||
#define FX_MODE_SUNRISE 104
|
#define FX_MODE_SUNRISE 104
|
||||||
#define FX_MODE_PHASED 105
|
#define FX_MODE_PHASED 105
|
||||||
#define FX_MODE_TWINKLEUP 106
|
#define FX_MODE_TWINKLEUP 106
|
||||||
@ -245,7 +241,7 @@
|
|||||||
// #define FX_MODE_CANDY_CANE 114 // removed in 0.14!
|
// #define FX_MODE_CANDY_CANE 114 // removed in 0.14!
|
||||||
#define FX_MODE_BLENDS 115
|
#define FX_MODE_BLENDS 115
|
||||||
#define FX_MODE_TV_SIMULATOR 116
|
#define FX_MODE_TV_SIMULATOR 116
|
||||||
#define FX_MODE_DYNAMIC_SMOOTH 117 // candidate for removal (check3 in dynamic)
|
#define FX_MODE_DYNAMIC_SMOOTH 117
|
||||||
|
|
||||||
// new 0.14 2D effects
|
// new 0.14 2D effects
|
||||||
#define FX_MODE_2DSPACESHIPS 118 //gap fill
|
#define FX_MODE_2DSPACESHIPS 118 //gap fill
|
||||||
@ -254,10 +250,6 @@
|
|||||||
#define FX_MODE_2DBLOBS 121 //gap fill
|
#define FX_MODE_2DBLOBS 121 //gap fill
|
||||||
#define FX_MODE_2DSCROLLTEXT 122 //gap fill
|
#define FX_MODE_2DSCROLLTEXT 122 //gap fill
|
||||||
#define FX_MODE_2DDRIFTROSE 123 //gap fill
|
#define FX_MODE_2DDRIFTROSE 123 //gap fill
|
||||||
#define FX_MODE_2DDISTORTIONWAVES 124 //gap fill
|
|
||||||
#define FX_MODE_2DSOAP 125 //gap fill
|
|
||||||
#define FX_MODE_2DOCTOPUS 126 //gap fill
|
|
||||||
#define FX_MODE_2DWAVINGCELL 127 //gap fill
|
|
||||||
|
|
||||||
// WLED-SR effects (SR compatible IDs !!!)
|
// WLED-SR effects (SR compatible IDs !!!)
|
||||||
#define FX_MODE_PIXELS 128
|
#define FX_MODE_PIXELS 128
|
||||||
@ -329,7 +321,7 @@ typedef enum mapping1D2D {
|
|||||||
M12_pCorner = 3
|
M12_pCorner = 3
|
||||||
} mapping1D2D_t;
|
} mapping1D2D_t;
|
||||||
|
|
||||||
// segment, 80 bytes
|
// segment, 72 bytes
|
||||||
typedef struct Segment {
|
typedef struct Segment {
|
||||||
public:
|
public:
|
||||||
uint16_t start; // start index / start X coordinate 2D (left)
|
uint16_t start; // start index / start X coordinate 2D (left)
|
||||||
@ -353,8 +345,7 @@ typedef struct Segment {
|
|||||||
bool mirror_y : 1; // 8 : mirrored Y (2D)
|
bool mirror_y : 1; // 8 : mirrored Y (2D)
|
||||||
bool transpose : 1; // 9 : transposed (2D, swapped X & Y)
|
bool transpose : 1; // 9 : transposed (2D, swapped X & Y)
|
||||||
uint8_t map1D2D : 3; // 10-12 : mapping for 1D effect on 2D (0-use as strip, 1-expand vertically, 2-circular/arc, 3-rectangular/corner, ...)
|
uint8_t map1D2D : 3; // 10-12 : mapping for 1D effect on 2D (0-use as strip, 1-expand vertically, 2-circular/arc, 3-rectangular/corner, ...)
|
||||||
uint8_t soundSim : 1; // 13 : 0-1 sound simulation types ("soft" & "hard" or "on"/"off")
|
uint8_t soundSim : 3; // 13-15 : 0-7 sound simulation types
|
||||||
uint8_t set : 2; // 14-15 : 0-3 UI segment sets/groups
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
uint8_t grouping, spacing;
|
uint8_t grouping, spacing;
|
||||||
@ -378,32 +369,9 @@ typedef struct Segment {
|
|||||||
uint32_t call; // call counter
|
uint32_t call; // call counter
|
||||||
uint16_t aux0; // custom var
|
uint16_t aux0; // custom var
|
||||||
uint16_t aux1; // custom var
|
uint16_t aux1; // custom var
|
||||||
byte *data; // effect data pointer
|
byte* data;
|
||||||
static uint16_t maxWidth, maxHeight; // these define matrix width & height (max. segment dimensions)
|
CRGB* leds;
|
||||||
|
static CRGB *_globalLeds;
|
||||||
typedef struct TemporarySegmentData {
|
|
||||||
uint16_t _optionsT;
|
|
||||||
uint32_t _colorT[NUM_COLORS];
|
|
||||||
uint8_t _speedT;
|
|
||||||
uint8_t _intensityT;
|
|
||||||
uint8_t _custom1T, _custom2T; // custom FX parameters/sliders
|
|
||||||
struct {
|
|
||||||
uint8_t _custom3T : 5; // reduced range slider (0-31)
|
|
||||||
bool _check1T : 1; // checkmark 1
|
|
||||||
bool _check2T : 1; // checkmark 2
|
|
||||||
bool _check3T : 1; // checkmark 3
|
|
||||||
};
|
|
||||||
uint16_t _aux0T;
|
|
||||||
uint16_t _aux1T;
|
|
||||||
uint32_t _stepT;
|
|
||||||
uint32_t _callT;
|
|
||||||
uint8_t *_dataT;
|
|
||||||
uint16_t _dataLenT;
|
|
||||||
TemporarySegmentData()
|
|
||||||
: _dataT(nullptr) // just in case...
|
|
||||||
, _dataLenT(0)
|
|
||||||
{}
|
|
||||||
} tmpsegd_t;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union {
|
union {
|
||||||
@ -419,34 +387,39 @@ typedef struct Segment {
|
|||||||
uint16_t _dataLen;
|
uint16_t _dataLen;
|
||||||
static uint16_t _usedSegmentData;
|
static uint16_t _usedSegmentData;
|
||||||
|
|
||||||
// perhaps this should be per segment, not static
|
// transition data, valid only if transitional==true, holds values during transition
|
||||||
static CRGBPalette16 _randomPalette; // actual random palette
|
|
||||||
static CRGBPalette16 _newRandomPalette; // target random palette
|
|
||||||
static unsigned long _lastPaletteChange; // last random palette change time in millis()
|
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
|
||||||
static bool _modeBlend; // mode/effect blending semaphore
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// transition data, valid only if transitional==true, holds values during transition (72 bytes)
|
|
||||||
struct Transition {
|
struct Transition {
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
|
||||||
tmpsegd_t _segT; // previous segment environment
|
|
||||||
uint8_t _modeT; // previous mode/effect
|
|
||||||
#else
|
|
||||||
uint32_t _colorT[NUM_COLORS];
|
uint32_t _colorT[NUM_COLORS];
|
||||||
#endif
|
|
||||||
uint8_t _briT; // temporary brightness
|
uint8_t _briT; // temporary brightness
|
||||||
uint8_t _cctT; // temporary CCT
|
uint8_t _cctT; // temporary CCT
|
||||||
CRGBPalette16 _palT; // temporary palette
|
CRGBPalette16 _palT; // temporary palette
|
||||||
uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 255 belnds possible)
|
uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 255 belnds possible)
|
||||||
unsigned long _start; // must accommodate millis()
|
uint8_t _modeP; // previous mode/effect
|
||||||
|
//uint16_t _aux0, _aux1; // previous mode/effect runtime data
|
||||||
|
//uint32_t _step, _call; // previous mode/effect runtime data
|
||||||
|
//byte *_data; // previous mode/effect runtime data
|
||||||
|
uint32_t _start;
|
||||||
uint16_t _dur;
|
uint16_t _dur;
|
||||||
Transition(uint16_t dur=750)
|
Transition(uint16_t dur=750)
|
||||||
: _palT(CRGBPalette16(CRGB::Black))
|
: _briT(255)
|
||||||
|
, _cctT(127)
|
||||||
|
, _palT(CRGBPalette16(CRGB::Black))
|
||||||
, _prevPaletteBlends(0)
|
, _prevPaletteBlends(0)
|
||||||
|
, _modeP(FX_MODE_STATIC)
|
||||||
, _start(millis())
|
, _start(millis())
|
||||||
, _dur(dur)
|
, _dur(dur)
|
||||||
{}
|
{}
|
||||||
|
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o)
|
||||||
|
: _briT(b)
|
||||||
|
, _cctT(c)
|
||||||
|
, _palT(CRGBPalette16(CRGB::Black))
|
||||||
|
, _prevPaletteBlends(0)
|
||||||
|
, _modeP(FX_MODE_STATIC)
|
||||||
|
, _start(millis())
|
||||||
|
, _dur(d)
|
||||||
|
{
|
||||||
|
for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = o[i];
|
||||||
|
}
|
||||||
} *_t;
|
} *_t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -480,14 +453,12 @@ typedef struct Segment {
|
|||||||
aux0(0),
|
aux0(0),
|
||||||
aux1(0),
|
aux1(0),
|
||||||
data(nullptr),
|
data(nullptr),
|
||||||
|
leds(nullptr),
|
||||||
_capabilities(0),
|
_capabilities(0),
|
||||||
_dataLen(0),
|
_dataLen(0),
|
||||||
_t(nullptr)
|
_t(nullptr)
|
||||||
{
|
{
|
||||||
//refreshLightCapabilities();
|
refreshLightCapabilities();
|
||||||
#ifdef WLED_DEBUG
|
|
||||||
//Serial.printf("-- Creating segment: %p\n", this);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) {
|
Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) {
|
||||||
@ -499,14 +470,16 @@ typedef struct Segment {
|
|||||||
Segment(Segment &&orig) noexcept; // move constructor
|
Segment(Segment &&orig) noexcept; // move constructor
|
||||||
|
|
||||||
~Segment() {
|
~Segment() {
|
||||||
#ifdef WLED_DEBUG
|
//#ifdef WLED_DEBUG
|
||||||
//Serial.printf("-- Destroying segment: %p\n", this);
|
//Serial.print(F("Destroying segment:"));
|
||||||
//if (name) Serial.printf(" %s (%p)", name, name);
|
//if (name) Serial.printf(" %s (%p)", name, name);
|
||||||
//if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
|
//if (data) Serial.printf(" %d (%p)", (int)_dataLen, data);
|
||||||
|
//if (leds) Serial.printf(" [%u]", length()*sizeof(CRGB));
|
||||||
//Serial.println();
|
//Serial.println();
|
||||||
#endif
|
//#endif
|
||||||
if (name) { delete[] name; name = nullptr; }
|
if (!Segment::_globalLeds && leds) free(leds);
|
||||||
stopTransition();
|
if (name) delete[] name;
|
||||||
|
if (_t) delete _t;
|
||||||
deallocateData();
|
deallocateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,30 +487,22 @@ typedef struct Segment {
|
|||||||
Segment& operator= (Segment &&orig) noexcept; // move assignment
|
Segment& operator= (Segment &&orig) noexcept; // move assignment
|
||||||
|
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
size_t getSize() const { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0); }
|
size_t getSize() const { return sizeof(Segment) + (data?_dataLen:0) + (name?strlen(name):0) + (_t?sizeof(Transition):0) + (!Segment::_globalLeds && leds?sizeof(CRGB)*length():0); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); }
|
inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); }
|
||||||
inline bool isSelected(void) const { return selected; }
|
inline bool isSelected(void) const { return selected; }
|
||||||
inline bool isActive(void) const { return stop > start; }
|
inline bool isActive(void) const { return stop > start; }
|
||||||
inline bool is2D(void) const { return (width()>1 && height()>1); }
|
inline bool is2D(void) const { return (width()>1 && height()>1); }
|
||||||
inline bool hasRGB(void) const { return _isRGB; }
|
inline uint16_t width(void) const { return stop - start; } // segment width in physical pixels (length if 1D)
|
||||||
inline bool hasWhite(void) const { return _hasW; }
|
inline uint16_t height(void) const { return stopY - startY; } // segment height (if 2D) in physical pixels
|
||||||
inline bool isCCT(void) const { return _isCCT; }
|
|
||||||
inline uint16_t width(void) const { return isActive() ? (stop - start) : 0; } // segment width in physical pixels (length if 1D)
|
|
||||||
inline uint16_t height(void) const { return stopY - startY; } // segment height (if 2D) in physical pixels (it *is* always >=1)
|
|
||||||
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels
|
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels
|
||||||
inline uint16_t groupLength(void) const { return grouping + spacing; }
|
inline uint16_t groupLength(void) const { return grouping + spacing; }
|
||||||
inline uint8_t getLightCapabilities(void) const { return _capabilities; }
|
inline uint8_t getLightCapabilities(void) const { return _capabilities; }
|
||||||
|
|
||||||
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
|
static uint16_t getUsedSegmentData(void) { return _usedSegmentData; }
|
||||||
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
|
static void addUsedSegmentData(int len) { _usedSegmentData += len; }
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
|
||||||
static void modeBlend(bool blend) { _modeBlend = blend; }
|
|
||||||
#endif
|
|
||||||
static void handleRandomPalette();
|
|
||||||
|
|
||||||
void setUp(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, uint8_t segId = 255);
|
|
||||||
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
bool setColor(uint8_t slot, uint32_t c); //returns true if changed
|
||||||
void setCCT(uint16_t k);
|
void setCCT(uint16_t k);
|
||||||
void setOpacity(uint8_t o);
|
void setOpacity(uint8_t o);
|
||||||
@ -559,15 +524,11 @@ typedef struct Segment {
|
|||||||
* Safe to call from interrupts and network requests.
|
* Safe to call from interrupts and network requests.
|
||||||
*/
|
*/
|
||||||
inline void markForReset(void) { reset = true; } // setOption(SEG_OPTION_RESET, true)
|
inline void markForReset(void) { reset = true; } // setOption(SEG_OPTION_RESET, true)
|
||||||
|
void setUpLeds(void); // set up leds[] array for loseless getPixelColor()
|
||||||
|
|
||||||
// transition functions
|
// transition functions
|
||||||
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
void startTransition(uint16_t dur); // transition has to start before actual segment values change
|
||||||
void stopTransition(void);
|
|
||||||
void handleTransition(void);
|
void handleTransition(void);
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
|
||||||
void swapSegenv(tmpsegd_t &tmpSegD);
|
|
||||||
void restoreSegenv(tmpsegd_t &tmpSegD);
|
|
||||||
#endif
|
|
||||||
uint16_t progress(void); //transition progression between 0-65535
|
uint16_t progress(void); //transition progression between 0-65535
|
||||||
uint8_t currentBri(uint8_t briNew, bool useCct = false);
|
uint8_t currentBri(uint8_t briNew, bool useCct = false);
|
||||||
uint8_t currentMode(uint8_t modeNew);
|
uint8_t currentMode(uint8_t modeNew);
|
||||||
@ -591,9 +552,9 @@ typedef struct Segment {
|
|||||||
void fadeToBlackBy(uint8_t fadeBy);
|
void fadeToBlackBy(uint8_t fadeBy);
|
||||||
void blendPixelColor(int n, uint32_t color, uint8_t blend);
|
void blendPixelColor(int n, uint32_t color, uint8_t blend);
|
||||||
void blendPixelColor(int n, CRGB c, uint8_t blend) { blendPixelColor(n, RGBW32(c.r,c.g,c.b,0), blend); }
|
void blendPixelColor(int n, CRGB c, uint8_t blend) { blendPixelColor(n, RGBW32(c.r,c.g,c.b,0), blend); }
|
||||||
void addPixelColor(int n, uint32_t color, bool fast = false);
|
void addPixelColor(int n, uint32_t color);
|
||||||
void addPixelColor(int n, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(n, RGBW32(r,g,b,w), fast); } // automatically inline
|
void addPixelColor(int n, byte r, byte g, byte b, byte w = 0) { addPixelColor(n, RGBW32(r,g,b,w)); } // automatically inline
|
||||||
void addPixelColor(int n, CRGB c, bool fast = false) { addPixelColor(n, RGBW32(c.r,c.g,c.b,0), fast); } // automatically inline
|
void addPixelColor(int n, CRGB c) { addPixelColor(n, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
|
||||||
void fadePixelColor(uint16_t n, uint8_t fade);
|
void fadePixelColor(uint16_t n, uint8_t fade);
|
||||||
uint8_t get_random_wheel_index(uint8_t pos);
|
uint8_t get_random_wheel_index(uint8_t pos);
|
||||||
uint32_t color_from_palette(uint16_t, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri = 255);
|
uint32_t color_from_palette(uint16_t, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri = 255);
|
||||||
@ -604,7 +565,7 @@ typedef struct Segment {
|
|||||||
uint16_t virtualHeight(void) const;
|
uint16_t virtualHeight(void) const;
|
||||||
uint16_t nrOfVStrips(void) const;
|
uint16_t nrOfVStrips(void) const;
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment
|
uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment (for leds[])
|
||||||
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
|
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
|
||||||
void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline
|
void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline
|
||||||
void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
|
void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
|
||||||
@ -615,23 +576,21 @@ typedef struct Segment {
|
|||||||
// 2D support functions
|
// 2D support functions
|
||||||
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
|
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
|
||||||
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); }
|
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); }
|
||||||
void addPixelColorXY(int x, int y, uint32_t color, bool fast = false);
|
void addPixelColorXY(int x, int y, uint32_t color);
|
||||||
void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColorXY(x, y, RGBW32(r,g,b,w), fast); } // automatically inline
|
void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { addPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline
|
||||||
void addPixelColorXY(int x, int y, CRGB c, bool fast = false) { addPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), fast); }
|
void addPixelColorXY(int x, int y, CRGB c) { addPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); }
|
||||||
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade);
|
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade);
|
||||||
void box_blur(uint16_t i, bool vertical, fract8 blur_amount); // 1D box blur (with weight)
|
void box_blur(uint16_t i, bool vertical, fract8 blur_amount); // 1D box blur (with weight)
|
||||||
void blurRow(uint16_t row, fract8 blur_amount);
|
void blurRow(uint16_t row, fract8 blur_amount);
|
||||||
void blurCol(uint16_t col, fract8 blur_amount);
|
void blurCol(uint16_t col, fract8 blur_amount);
|
||||||
void moveX(int8_t delta, bool wrap = false);
|
void moveX(int8_t delta);
|
||||||
void moveY(int8_t delta, bool wrap = false);
|
void moveY(int8_t delta);
|
||||||
void move(uint8_t dir, uint8_t delta, bool wrap = false);
|
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 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, 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 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 drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2 = 0, int8_t rotate = 0);
|
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, 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, CRGB c, CRGB c2, int8_t rotate = 0) { drawCharacter(chr, x, y, w, h, RGBW32(c.r,c.g,c.b,0), RGBW32(c2.r,c2.g,c2.b,0), rotate); } // automatic inline
|
|
||||||
void wu_pixel(uint32_t x, uint32_t y, CRGB c);
|
void wu_pixel(uint32_t x, uint32_t y, CRGB c);
|
||||||
void blur1d(fract8 blur_amount); // blur all rows in 1 dimension
|
void blur1d(fract8 blur_amount); // blur all rows in 1 dimension
|
||||||
void blur2d(fract8 blur_amount) { blur(blur_amount); }
|
void blur2d(fract8 blur_amount) { blur(blur_amount); }
|
||||||
@ -648,22 +607,21 @@ typedef struct Segment {
|
|||||||
uint32_t getPixelColorXY(uint16_t x, uint16_t y) { return getPixelColor(x); }
|
uint32_t getPixelColorXY(uint16_t x, uint16_t y) { return getPixelColor(x); }
|
||||||
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
|
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
|
||||||
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColor(x, RGBW32(c.r,c.g,c.b,0), blend); }
|
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColor(x, RGBW32(c.r,c.g,c.b,0), blend); }
|
||||||
void addPixelColorXY(int x, int y, uint32_t color, bool fast = false) { addPixelColor(x, color, fast); }
|
void addPixelColorXY(int x, int y, uint32_t color) { addPixelColor(x, color); }
|
||||||
void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(x, RGBW32(r,g,b,w), fast); }
|
void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { addPixelColor(x, RGBW32(r,g,b,w)); }
|
||||||
void addPixelColorXY(int x, int y, CRGB c, bool fast = false) { addPixelColor(x, RGBW32(c.r,c.g,c.b,0), fast); }
|
void addPixelColorXY(int x, int y, CRGB c) { addPixelColor(x, RGBW32(c.r,c.g,c.b,0)); }
|
||||||
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) { fadePixelColor(x, fade); }
|
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) { fadePixelColor(x, fade); }
|
||||||
void box_blur(uint16_t i, bool vertical, fract8 blur_amount) {}
|
void box_blur(uint16_t i, bool vertical, fract8 blur_amount) {}
|
||||||
void blurRow(uint16_t row, fract8 blur_amount) {}
|
void blurRow(uint16_t row, fract8 blur_amount) {}
|
||||||
void blurCol(uint16_t col, fract8 blur_amount) {}
|
void blurCol(uint16_t col, fract8 blur_amount) {}
|
||||||
void moveX(int8_t delta, bool wrap = false) {}
|
void moveX(int8_t delta) {}
|
||||||
void moveY(int8_t delta, bool wrap = false) {}
|
void moveY(int8_t delta) {}
|
||||||
void move(uint8_t dir, uint8_t delta, bool wrap = false) {}
|
void move(uint8_t dir, uint8_t delta) {}
|
||||||
void fill_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, uint32_t c) {}
|
||||||
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c) {}
|
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c) {}
|
||||||
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t = 0, int8_t = 0) {}
|
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 color) {}
|
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color) {}
|
||||||
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2, int8_t rotate = 0) {}
|
|
||||||
void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
|
void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
|
||||||
#endif
|
#endif
|
||||||
} segment;
|
} segment;
|
||||||
@ -695,7 +653,14 @@ class WS2812FX { // 96 bytes
|
|||||||
timebase(0),
|
timebase(0),
|
||||||
isMatrix(false),
|
isMatrix(false),
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
panels(1),
|
hPanels(1),
|
||||||
|
vPanels(1),
|
||||||
|
panelH(8),
|
||||||
|
panelW(8),
|
||||||
|
matrixWidth(DEFAULT_LED_COUNT),
|
||||||
|
matrixHeight(1),
|
||||||
|
matrix{0,0,0,0},
|
||||||
|
panel{{0,0,0,0}},
|
||||||
#endif
|
#endif
|
||||||
// semi-private (just obscured) used in effect functions through macros
|
// semi-private (just obscured) used in effect functions through macros
|
||||||
_currentPalette(CRGBPalette16(CRGB::Black)),
|
_currentPalette(CRGBPalette16(CRGB::Black)),
|
||||||
@ -718,15 +683,7 @@ class WS2812FX { // 96 bytes
|
|||||||
customMappingSize(0),
|
customMappingSize(0),
|
||||||
_lastShow(0),
|
_lastShow(0),
|
||||||
_segment_index(0),
|
_segment_index(0),
|
||||||
_mainSegment(0),
|
_mainSegment(0)
|
||||||
_queuedChangesSegId(255),
|
|
||||||
_qStart(0),
|
|
||||||
_qStop(0),
|
|
||||||
_qStartY(0),
|
|
||||||
_qStopY(0),
|
|
||||||
_qGrouping(0),
|
|
||||||
_qSpacing(0),
|
|
||||||
_qOffset(0)
|
|
||||||
{
|
{
|
||||||
WS2812FX::instance = this;
|
WS2812FX::instance = this;
|
||||||
_mode.reserve(_modeCount); // allocate memory to prevent initial fragmentation (does not increase size())
|
_mode.reserve(_modeCount); // allocate memory to prevent initial fragmentation (does not increase size())
|
||||||
@ -740,10 +697,8 @@ class WS2812FX { // 96 bytes
|
|||||||
_mode.clear();
|
_mode.clear();
|
||||||
_modeData.clear();
|
_modeData.clear();
|
||||||
_segments.clear();
|
_segments.clear();
|
||||||
#ifndef WLED_DISABLE_2D
|
|
||||||
panel.clear();
|
|
||||||
#endif
|
|
||||||
customPalettes.clear();
|
customPalettes.clear();
|
||||||
|
if (useLedsArray && Segment::_globalLeds) free(Segment::_globalLeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WS2812FX* getInstance(void) { return instance; }
|
static WS2812FX* getInstance(void) { return instance; }
|
||||||
@ -755,6 +710,7 @@ class WS2812FX { // 96 bytes
|
|||||||
finalizeInit(),
|
finalizeInit(),
|
||||||
service(void),
|
service(void),
|
||||||
setMode(uint8_t segid, uint8_t m),
|
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),
|
setColor(uint8_t slot, uint32_t c),
|
||||||
setCCT(uint16_t k),
|
setCCT(uint16_t k),
|
||||||
setBrightness(uint8_t b, bool direct = false),
|
setBrightness(uint8_t b, bool direct = false),
|
||||||
@ -769,10 +725,10 @@ class WS2812FX { // 96 bytes
|
|||||||
fixInvalidSegments(),
|
fixInvalidSegments(),
|
||||||
setPixelColor(int n, uint32_t c),
|
setPixelColor(int n, uint32_t c),
|
||||||
show(void),
|
show(void),
|
||||||
setTargetFps(uint8_t fps);
|
setTargetFps(uint8_t fps),
|
||||||
|
deserializeMap(uint8_t n=0);
|
||||||
|
|
||||||
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 < _length; i++) setPixelColor(i, c); } // fill whole strip with color (inline)
|
||||||
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 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
|
void setupEffectData(void); // add default effects to the list; defined in FX.cpp
|
||||||
|
|
||||||
@ -782,7 +738,7 @@ class WS2812FX { // 96 bytes
|
|||||||
inline void trigger(void) { _triggered = true; } // Forces the next frame to be computed on all active segments.
|
inline void trigger(void) { _triggered = true; } // Forces the next frame to be computed on all active segments.
|
||||||
inline void setShowCallback(show_callback cb) { _callback = cb; }
|
inline void setShowCallback(show_callback cb) { _callback = cb; }
|
||||||
inline void setTransition(uint16_t t) { _transitionDur = t; }
|
inline void setTransition(uint16_t t) { _transitionDur = t; }
|
||||||
inline void appendSegment(const Segment &seg = Segment()) { if (_segments.size() < getMaxSegments()) _segments.push_back(seg); }
|
inline void appendSegment(const Segment &seg = Segment()) { _segments.push_back(seg); }
|
||||||
|
|
||||||
bool
|
bool
|
||||||
checkSegmentAlignment(void),
|
checkSegmentAlignment(void),
|
||||||
@ -790,7 +746,7 @@ class WS2812FX { // 96 bytes
|
|||||||
hasCCTBus(void),
|
hasCCTBus(void),
|
||||||
// return true if the strip is being sent pixel updates
|
// return true if the strip is being sent pixel updates
|
||||||
isUpdating(void),
|
isUpdating(void),
|
||||||
deserializeMap(uint8_t n=0);
|
useLedsArray = false;
|
||||||
|
|
||||||
inline bool isServicing(void) { return _isServicing; }
|
inline bool isServicing(void) { return _isServicing; }
|
||||||
inline bool hasWhiteChannel(void) {return _hasWhiteChannel;}
|
inline bool hasWhiteChannel(void) {return _hasWhiteChannel;}
|
||||||
@ -804,7 +760,6 @@ class WS2812FX { // 96 bytes
|
|||||||
getActiveSegmentsNum(void),
|
getActiveSegmentsNum(void),
|
||||||
getFirstSelectedSegId(void),
|
getFirstSelectedSegId(void),
|
||||||
getLastActiveSegmentId(void),
|
getLastActiveSegmentId(void),
|
||||||
getActiveSegsLightCapabilities(bool selectedOnly = false),
|
|
||||||
setPixelSegment(uint8_t n);
|
setPixelSegment(uint8_t n);
|
||||||
|
|
||||||
inline uint8_t getBrightness(void) { return _brightness; }
|
inline uint8_t getBrightness(void) { return _brightness; }
|
||||||
@ -820,17 +775,17 @@ class WS2812FX { // 96 bytes
|
|||||||
ablMilliampsMax,
|
ablMilliampsMax,
|
||||||
currentMilliamps,
|
currentMilliamps,
|
||||||
getLengthPhysical(void),
|
getLengthPhysical(void),
|
||||||
getLengthTotal(void), // will include virtual/nonexistent pixels in matrix
|
|
||||||
getFps();
|
getFps();
|
||||||
|
|
||||||
inline uint16_t getFrameTime(void) { return _frametime; }
|
inline uint16_t getFrameTime(void) { return _frametime; }
|
||||||
inline uint16_t getMinShowDelay(void) { return MIN_SHOW_DELAY; }
|
inline uint16_t getMinShowDelay(void) { return MIN_SHOW_DELAY; }
|
||||||
inline uint16_t getLength(void) { return _length; } // 2D matrix may have less pixels than W*H
|
inline uint16_t getLengthTotal(void) { return _length; }
|
||||||
inline uint16_t getTransition(void) { return _transitionDur; }
|
inline uint16_t getTransition(void) { return _transitionDur; }
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
now,
|
now,
|
||||||
timebase,
|
timebase,
|
||||||
|
currentColor(uint32_t colorNew, uint8_t tNr),
|
||||||
getPixelColor(uint16_t);
|
getPixelColor(uint16_t);
|
||||||
|
|
||||||
inline uint32_t getLastShow(void) { return _lastShow; }
|
inline uint32_t getLastShow(void) { return _lastShow; }
|
||||||
@ -854,31 +809,24 @@ class WS2812FX { // 96 bytes
|
|||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
#define WLED_MAX_PANELS 64
|
#define WLED_MAX_PANELS 64
|
||||||
uint8_t
|
uint8_t
|
||||||
panels;
|
hPanels,
|
||||||
|
vPanels;
|
||||||
|
|
||||||
typedef struct panel_t {
|
uint16_t
|
||||||
uint16_t xOffset; // x offset relative to the top left of matrix in LEDs
|
panelH,
|
||||||
uint16_t yOffset; // y offset relative to the top left of matrix in LEDs
|
panelW,
|
||||||
uint8_t width; // width of the panel
|
matrixWidth,
|
||||||
uint8_t height; // height of the panel
|
matrixHeight;
|
||||||
union {
|
|
||||||
uint8_t options;
|
typedef struct panel_bitfield_t {
|
||||||
struct {
|
|
||||||
bool bottomStart : 1; // starts at bottom?
|
bool bottomStart : 1; // starts at bottom?
|
||||||
bool rightStart : 1; // starts on right?
|
bool rightStart : 1; // starts on right?
|
||||||
bool vertical : 1; // is vertical?
|
bool vertical : 1; // is vertical?
|
||||||
bool serpentine : 1; // is serpentine?
|
bool serpentine : 1; // is serpentine?
|
||||||
};
|
|
||||||
};
|
|
||||||
panel_t()
|
|
||||||
: xOffset(0)
|
|
||||||
, yOffset(0)
|
|
||||||
, width(8)
|
|
||||||
, height(8)
|
|
||||||
, options(0)
|
|
||||||
{}
|
|
||||||
} Panel;
|
} Panel;
|
||||||
std::vector<Panel> panel;
|
Panel
|
||||||
|
matrix,
|
||||||
|
panel[WLED_MAX_PANELS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -932,20 +880,13 @@ class WS2812FX { // 96 bytes
|
|||||||
uint16_t* customMappingTable;
|
uint16_t* customMappingTable;
|
||||||
uint16_t customMappingSize;
|
uint16_t customMappingSize;
|
||||||
|
|
||||||
unsigned long _lastShow;
|
uint32_t _lastShow;
|
||||||
|
|
||||||
uint8_t _segment_index;
|
uint8_t _segment_index;
|
||||||
uint8_t _mainSegment;
|
uint8_t _mainSegment;
|
||||||
uint8_t _queuedChangesSegId;
|
|
||||||
uint16_t _qStart, _qStop, _qStartY, _qStopY;
|
|
||||||
uint8_t _qGrouping, _qSpacing;
|
|
||||||
uint16_t _qOffset;
|
|
||||||
|
|
||||||
uint8_t
|
|
||||||
estimateCurrentAndLimitBri(void);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
setUpSegmentFromQueuedChanges(void);
|
estimateCurrentAndLimitBri(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char JSON_mode_names[];
|
extern const char JSON_mode_names[];
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
// setUpMatrix() - constructs ledmap array from matrix of panels with WxH pixels
|
// setUpMatrix() - constructs ledmap array from matrix of panels with WxH pixels
|
||||||
// this converts physical (possibly irregular) LED arrangement into well defined
|
// this converts physical (possibly irregular) LED arrangement into well defined
|
||||||
// array of logical pixels: fist entry corresponds to left-topmost logical pixel
|
// array of logical pixels: fist entry corresponds to left-topmost logical pixel
|
||||||
// followed by horizontal pixels, when Segment::maxWidth logical pixels are added they
|
// followed by horizontal pixels, when matrixWidth logical pixels are added they
|
||||||
// are followed by next row (down) of Segment::maxWidth pixels (and so forth)
|
// are followed by next row (down) of matrixWidth pixels (and so forth)
|
||||||
// note: matrix may be comprised of multiple panels each with different orientation
|
// note: matrix may be comprised of multiple panels each with different orientation
|
||||||
// but ledmap takes care of that. ledmap is constructed upon initialization
|
// but ledmap takes care of that. ledmap is constructed upon initialization
|
||||||
// so matrix should disable regular ledmap processing
|
// so matrix should disable regular ledmap processing
|
||||||
@ -41,143 +41,98 @@ void WS2812FX::setUpMatrix() {
|
|||||||
customMappingTable = nullptr;
|
customMappingTable = nullptr;
|
||||||
customMappingSize = 0;
|
customMappingSize = 0;
|
||||||
|
|
||||||
// isMatrix is set in cfg.cpp or set.cpp
|
|
||||||
if (isMatrix) {
|
if (isMatrix) {
|
||||||
// calculate width dynamically because it will have gaps
|
matrixWidth = hPanels * panelW;
|
||||||
Segment::maxWidth = 1;
|
matrixHeight = vPanels * panelH;
|
||||||
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
|
// safety check
|
||||||
if (Segment::maxWidth * Segment::maxHeight > MAX_LEDS || Segment::maxWidth <= 1 || Segment::maxHeight <= 1) {
|
if (matrixWidth * matrixHeight > MAX_LEDS) {
|
||||||
DEBUG_PRINTLN(F("2D Bounds error."));
|
matrixWidth = _length;
|
||||||
|
matrixHeight = 1;
|
||||||
isMatrix = false;
|
isMatrix = false;
|
||||||
Segment::maxWidth = _length;
|
|
||||||
Segment::maxHeight = 1;
|
|
||||||
panels = 0;
|
|
||||||
panel.clear(); // release memory allocated by panels
|
|
||||||
resetSegments();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
|
customMappingSize = matrixWidth * matrixHeight;
|
||||||
|
customMappingTable = new uint16_t[customMappingSize];
|
||||||
|
|
||||||
if (customMappingTable != nullptr) {
|
if (customMappingTable != nullptr) {
|
||||||
customMappingSize = Segment::maxWidth * Segment::maxHeight;
|
uint16_t startL; // index in custom mapping array (logical strip)
|
||||||
|
uint16_t startP; // position of 1st pixel of panel on (virtual) strip
|
||||||
|
uint16_t x, y, offset;
|
||||||
|
uint8_t h = matrix.vertical ? vPanels : hPanels;
|
||||||
|
uint8_t v = matrix.vertical ? hPanels : vPanels;
|
||||||
|
|
||||||
// fill with empty in case we don't fill the entire matrix
|
for (uint8_t j=0, p=0; j<v; j++) {
|
||||||
for (size_t i = 0; i< customMappingSize; i++) {
|
for (uint8_t i=0; i<h; i++, p++) {
|
||||||
customMappingTable[i] = (uint16_t)-1;
|
y = (matrix.vertical ? matrix.rightStart : matrix.bottomStart) ? v - j - 1 : j;
|
||||||
}
|
x = (matrix.vertical ? matrix.bottomStart : matrix.rightStart) ? h - i - 1 : i;
|
||||||
|
x = matrix.serpentine && j%2 ? h - x - 1 : x;
|
||||||
|
|
||||||
// we will try to load a "gap" array (a JSON file)
|
startL = (matrix.vertical ? y : x) * panelW + (matrix.vertical ? x : y) * matrixWidth * panelH; // logical index (top-left corner)
|
||||||
// the array has to have the same amount of values as mapping array (or larger)
|
startP = p * panelW * panelH; // physical index (top-left corner)
|
||||||
// "gap" array is used while building ledmap (mapping array)
|
|
||||||
// and discarded afterwards as it has no meaning after the process
|
|
||||||
// content of the file is just raw JSON array in the form of [val1,val2,val3,...]
|
|
||||||
// there are no other "key":"value" pairs in it
|
|
||||||
// allowed values are: -1 (missing pixel/no LED attached), 0 (inactive/unused pixel), 1 (active/used pixel)
|
|
||||||
char fileName[32]; strcpy_P(fileName, PSTR("/2d-gaps.json")); // reduce flash footprint
|
|
||||||
bool isFile = WLED_FS.exists(fileName);
|
|
||||||
size_t gapSize = 0;
|
|
||||||
int8_t *gapTable = nullptr;
|
|
||||||
|
|
||||||
if (isFile && requestJSONBufferLock(20)) {
|
uint8_t H = panel[h*j + i].vertical ? panelW : panelH;
|
||||||
DEBUG_PRINT(F("Reading LED gap from "));
|
uint8_t W = panel[h*j + i].vertical ? panelH : panelW;
|
||||||
DEBUG_PRINTLN(fileName);
|
for (uint16_t l=0, q=0; l<H; l++) {
|
||||||
// read the array into global JSON buffer
|
for (uint16_t k=0; k<W; k++, q++) {
|
||||||
if (readObjectFromFile(fileName, nullptr, &doc)) {
|
y = (panel[h*j + i].vertical ? panel[h*j + i].rightStart : panel[h*j + i].bottomStart) ? H - l - 1 : l;
|
||||||
// the array is similar to ledmap, except it has only 3 values:
|
x = (panel[h*j + i].vertical ? panel[h*j + i].bottomStart : panel[h*j + i].rightStart) ? W - k - 1 : k;
|
||||||
// -1 ... missing pixel (do not increase pixel count)
|
x = (panel[h*j + i].serpentine && l%2) ? (W - x - 1) : x;
|
||||||
// 0 ... inactive pixel (it does count, but should be mapped out (-1))
|
offset = (panel[h*j + i].vertical ? y : x) + (panel[h*j + i].vertical ? x : y) * matrixWidth;
|
||||||
// 1 ... active pixel (it will count and will be mapped)
|
customMappingTable[startL + offset] = startP + q;
|
||||||
JsonArray map = doc.as<JsonArray>();
|
|
||||||
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
|
#ifdef WLED_DEBUG
|
||||||
DEBUG_PRINT(F("Matrix ledmap:"));
|
DEBUG_PRINT(F("Matrix ledmap:"));
|
||||||
for (uint16_t i=0; i<customMappingSize; i++) {
|
for (uint16_t i=0; i<customMappingSize; i++) {
|
||||||
if (!(i%Segment::maxWidth)) DEBUG_PRINTLN();
|
if (!(i%matrixWidth)) DEBUG_PRINTLN();
|
||||||
DEBUG_PRINTF("%4d,", customMappingTable[i]);
|
DEBUG_PRINTF("%4d,", customMappingTable[i]);
|
||||||
}
|
}
|
||||||
DEBUG_PRINTLN();
|
DEBUG_PRINTLN();
|
||||||
#endif
|
#endif
|
||||||
} else { // memory allocation error
|
} else {
|
||||||
DEBUG_PRINTLN(F("Ledmap alloc error."));
|
// memory allocation error
|
||||||
|
matrixWidth = _length;
|
||||||
|
matrixHeight = 1;
|
||||||
isMatrix = false;
|
isMatrix = false;
|
||||||
panels = 0;
|
return;
|
||||||
panel.clear();
|
|
||||||
Segment::maxWidth = _length;
|
|
||||||
Segment::maxHeight = 1;
|
|
||||||
resetSegments();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// not a matrix set up
|
||||||
|
matrixWidth = _length;
|
||||||
|
matrixHeight = 1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
isMatrix = false; // no matter what config says
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// absolute matrix version of setPixelColor()
|
// absolute matrix version of setPixelColor()
|
||||||
void /*IRAM_ATTR*/ WS2812FX::setPixelColorXY(int x, int y, uint32_t col)
|
void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col)
|
||||||
{
|
{
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
if (!isMatrix) return; // not a matrix set-up
|
if (!isMatrix) return; // not a matrix set-up
|
||||||
uint16_t index = y * Segment::maxWidth + x;
|
uint16_t index = y * matrixWidth + x;
|
||||||
|
if (index >= customMappingSize) return; // customMappingSize is always W * H of matrix in 2D setup
|
||||||
#else
|
#else
|
||||||
uint16_t index = x;
|
uint16_t index = x;
|
||||||
|
if (index >= _length) return;
|
||||||
#endif
|
#endif
|
||||||
if (index < customMappingSize) index = customMappingTable[index];
|
if (index < customMappingSize) index = customMappingTable[index];
|
||||||
if (index >= _length) return;
|
|
||||||
busses.setPixelColor(index, col);
|
busses.setPixelColor(index, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns RGBW values of pixel
|
// returns RGBW values of pixel
|
||||||
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
|
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
uint16_t index = (y * Segment::maxWidth + x);
|
uint16_t index = (y * matrixWidth + x);
|
||||||
|
if (index >= customMappingSize) return 0; // customMappingSize is always W * H of matrix in 2D setup
|
||||||
#else
|
#else
|
||||||
uint16_t index = x;
|
uint16_t index = x;
|
||||||
|
if (index >= _length) return 0;
|
||||||
#endif
|
#endif
|
||||||
if (index < customMappingSize) index = customMappingTable[index];
|
if (index < customMappingSize) index = customMappingTable[index];
|
||||||
if (index >= _length) return 0;
|
|
||||||
return busses.getPixelColor(index);
|
return busses.getPixelColor(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,17 +143,19 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
|
|||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
|
|
||||||
// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
|
// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
|
||||||
uint16_t /*IRAM_ATTR*/ Segment::XY(uint16_t x, uint16_t y) {
|
uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y) {
|
||||||
uint16_t width = virtualWidth(); // segment width in logical pixels (can be 0 if segment is inactive)
|
uint16_t width = virtualWidth(); // segment width in logical pixels
|
||||||
uint16_t height = virtualHeight(); // segment height in logical pixels (is always >= 1)
|
uint16_t height = virtualHeight(); // segment height in logical pixels
|
||||||
return isActive() ? (x%width) + (y%height) * width : 0;
|
return (x%width) + (y%height) * width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void /*IRAM_ATTR*/ Segment::setPixelColorXY(int x, int y, uint32_t col)
|
void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
|
||||||
{
|
{
|
||||||
if (!isActive()) return; // not active
|
if (!strip.isMatrix) 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 (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);
|
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
||||||
if (_bri_t < 255) {
|
if (_bri_t < 255) {
|
||||||
byte r = scale8(R(col), _bri_t);
|
byte r = scale8(R(col), _bri_t);
|
||||||
@ -216,29 +173,23 @@ void /*IRAM_ATTR*/ Segment::setPixelColorXY(int x, int y, uint32_t col)
|
|||||||
y *= groupLength(); // expand to physical pixels
|
y *= groupLength(); // expand to physical pixels
|
||||||
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
|
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
|
||||||
|
|
||||||
uint32_t tmpCol = col;
|
|
||||||
for (int j = 0; j < grouping; j++) { // groupping vertically
|
for (int j = 0; j < grouping; j++) { // groupping vertically
|
||||||
for (int g = 0; g < grouping; g++) { // groupping horizontally
|
for (int g = 0; g < grouping; g++) { // groupping horizontally
|
||||||
uint16_t xX = (x+g), yY = (y+j);
|
uint16_t xX = (x+g), yY = (y+j);
|
||||||
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
|
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
strip.setPixelColorXY(start + xX, startY + yY, col);
|
||||||
// if blending modes, blend with underlying pixel
|
|
||||||
if (_modeBlend) tmpCol = color_blend(strip.getPixelColorXY(start + xX, startY + yY), col, 0xFFFFU - progress(), true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
strip.setPixelColorXY(start + xX, startY + yY, tmpCol);
|
|
||||||
|
|
||||||
if (mirror) { //set the corresponding horizontally mirrored pixel
|
if (mirror) { //set the corresponding horizontally mirrored pixel
|
||||||
if (transpose) strip.setPixelColorXY(start + xX, startY + height() - yY - 1, tmpCol);
|
if (transpose) strip.setPixelColorXY(start + xX, startY + height() - yY - 1, col);
|
||||||
else strip.setPixelColorXY(start + width() - xX - 1, startY + yY, tmpCol);
|
else strip.setPixelColorXY(start + width() - xX - 1, startY + yY, col);
|
||||||
}
|
}
|
||||||
if (mirror_y) { //set the corresponding vertically mirrored pixel
|
if (mirror_y) { //set the corresponding vertically mirrored pixel
|
||||||
if (transpose) strip.setPixelColorXY(start + width() - xX - 1, startY + yY, tmpCol);
|
if (transpose) strip.setPixelColorXY(start + width() - xX - 1, startY + yY, col);
|
||||||
else strip.setPixelColorXY(start + xX, startY + height() - yY - 1, tmpCol);
|
else strip.setPixelColorXY(start + xX, startY + height() - yY - 1, col);
|
||||||
}
|
}
|
||||||
if (mirror_y && mirror) { //set the corresponding vertically AND horizontally mirrored pixel
|
if (mirror_y && mirror) { //set the corresponding vertically AND horizontally mirrored pixel
|
||||||
strip.setPixelColorXY(width() - xX - 1, height() - yY - 1, tmpCol);
|
strip.setPixelColorXY(width() - xX - 1, height() - yY - 1, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +198,7 @@ void /*IRAM_ATTR*/ Segment::setPixelColorXY(int x, int y, uint32_t col)
|
|||||||
// anti-aliased version of setPixelColorXY()
|
// anti-aliased version of setPixelColorXY()
|
||||||
void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
|
void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
|
||||||
{
|
{
|
||||||
if (!isActive()) return; // not active
|
if (!strip.isMatrix) return; // not a matrix set-up
|
||||||
if (x<0.0f || x>1.0f || y<0.0f || y>1.0f) return; // not normalized
|
if (x<0.0f || x>1.0f || y<0.0f || y>1.0f) return; // not normalized
|
||||||
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
@ -290,8 +241,8 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
|
|||||||
|
|
||||||
// returns RGBW values of pixel
|
// returns RGBW values of pixel
|
||||||
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
|
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
|
||||||
if (!isActive()) return 0; // not active
|
int i = XY(x,y);
|
||||||
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return 0; // if pixel would fall out of virtual segment just exit
|
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
|
||||||
if (reverse ) x = virtualWidth() - x - 1;
|
if (reverse ) x = virtualWidth() - x - 1;
|
||||||
if (reverse_y) y = virtualHeight() - y - 1;
|
if (reverse_y) y = virtualHeight() - y - 1;
|
||||||
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||||
@ -307,55 +258,35 @@ void Segment::blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds the specified color with the existing pixel color perserving color balance.
|
// Adds the specified color with the existing pixel color perserving color balance.
|
||||||
void Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
|
void Segment::addPixelColorXY(int x, int y, uint32_t color) {
|
||||||
if (!isActive()) return; // not active
|
setPixelColorXY(x, y, color_add(getPixelColorXY(x,y), color));
|
||||||
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
|
|
||||||
uint32_t col = getPixelColorXY(x,y);
|
|
||||||
uint8_t r = R(col);
|
|
||||||
uint8_t g = G(col);
|
|
||||||
uint8_t b = B(col);
|
|
||||||
uint8_t w = W(col);
|
|
||||||
if (fast) {
|
|
||||||
r = qadd8(r, R(color));
|
|
||||||
g = qadd8(g, G(color));
|
|
||||||
b = qadd8(b, B(color));
|
|
||||||
w = qadd8(w, W(color));
|
|
||||||
col = RGBW32(r,g,b,w);
|
|
||||||
} else {
|
|
||||||
col = color_add(col, color);
|
|
||||||
}
|
|
||||||
setPixelColorXY(x, y, col);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
|
void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade);
|
CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade);
|
||||||
setPixelColorXY(x, y, pix);
|
setPixelColor(x, y, pix);
|
||||||
}
|
}
|
||||||
|
|
||||||
// blurRow: perform a blur on a row of a rectangular matrix
|
// blurRow: perform a blur on a row of a rectangular matrix
|
||||||
void Segment::blurRow(uint16_t row, fract8 blur_amount) {
|
void Segment::blurRow(uint16_t row, fract8 blur_amount) {
|
||||||
if (!isActive()) return; // not active
|
const uint16_t cols = virtualWidth();
|
||||||
const uint_fast16_t cols = virtualWidth();
|
const uint16_t rows = virtualHeight();
|
||||||
const uint_fast16_t rows = virtualHeight();
|
|
||||||
|
|
||||||
if (row >= rows) return;
|
if (row >= rows) return;
|
||||||
// blur one row
|
// blur one row
|
||||||
uint8_t keep = 255 - blur_amount;
|
uint8_t keep = 255 - blur_amount;
|
||||||
uint8_t seep = blur_amount >> 1;
|
uint8_t seep = blur_amount >> 1;
|
||||||
CRGB carryover = CRGB::Black;
|
CRGB carryover = CRGB::Black;
|
||||||
for (uint_fast16_t x = 0; x < cols; x++) {
|
for (uint16_t x = 0; x < cols; x++) {
|
||||||
CRGB cur = getPixelColorXY(x, row);
|
CRGB cur = getPixelColorXY(x, row);
|
||||||
CRGB before = cur; // remember color before blur
|
|
||||||
CRGB part = cur;
|
CRGB part = cur;
|
||||||
part.nscale8(seep);
|
part.nscale8(seep);
|
||||||
cur.nscale8(keep);
|
cur.nscale8(keep);
|
||||||
cur += carryover;
|
cur += carryover;
|
||||||
if (x>0) {
|
if (x) {
|
||||||
CRGB prev = CRGB(getPixelColorXY(x-1, row)) + part;
|
CRGB prev = CRGB(getPixelColorXY(x-1, row)) + part;
|
||||||
setPixelColorXY(x-1, row, prev);
|
setPixelColorXY(x-1, row, prev);
|
||||||
}
|
}
|
||||||
if (before != cur) // optimization: only set pixel if color has changed
|
|
||||||
setPixelColorXY(x, row, cur);
|
setPixelColorXY(x, row, cur);
|
||||||
carryover = part;
|
carryover = part;
|
||||||
}
|
}
|
||||||
@ -363,35 +294,31 @@ void Segment::blurRow(uint16_t row, fract8 blur_amount) {
|
|||||||
|
|
||||||
// blurCol: perform a blur on a column of a rectangular matrix
|
// blurCol: perform a blur on a column of a rectangular matrix
|
||||||
void Segment::blurCol(uint16_t col, fract8 blur_amount) {
|
void Segment::blurCol(uint16_t col, fract8 blur_amount) {
|
||||||
if (!isActive()) return; // not active
|
const uint16_t cols = virtualWidth();
|
||||||
const uint_fast16_t cols = virtualWidth();
|
const uint16_t rows = virtualHeight();
|
||||||
const uint_fast16_t rows = virtualHeight();
|
|
||||||
|
|
||||||
if (col >= cols) return;
|
if (col >= cols) return;
|
||||||
// blur one column
|
// blur one column
|
||||||
uint8_t keep = 255 - blur_amount;
|
uint8_t keep = 255 - blur_amount;
|
||||||
uint8_t seep = blur_amount >> 1;
|
uint8_t seep = blur_amount >> 1;
|
||||||
CRGB carryover = CRGB::Black;
|
CRGB carryover = CRGB::Black;
|
||||||
for (uint_fast16_t y = 0; y < rows; y++) {
|
for (uint16_t i = 0; i < rows; i++) {
|
||||||
CRGB cur = getPixelColorXY(col, y);
|
CRGB cur = getPixelColorXY(col, i);
|
||||||
CRGB part = cur;
|
CRGB part = cur;
|
||||||
CRGB before = cur; // remember color before blur
|
|
||||||
part.nscale8(seep);
|
part.nscale8(seep);
|
||||||
cur.nscale8(keep);
|
cur.nscale8(keep);
|
||||||
cur += carryover;
|
cur += carryover;
|
||||||
if (y>0) {
|
if (i) {
|
||||||
CRGB prev = CRGB(getPixelColorXY(col, y-1)) + part;
|
CRGB prev = CRGB(getPixelColorXY(col, i-1)) + part;
|
||||||
setPixelColorXY(col, y-1, prev);
|
setPixelColorXY(col, i-1, prev);
|
||||||
}
|
}
|
||||||
if (before != cur) // optimization: only set pixel if color has changed
|
setPixelColorXY(col, i, cur);
|
||||||
setPixelColorXY(col, y, cur);
|
|
||||||
carryover = part;
|
carryover = part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1D Box blur (with added weight - blur_amount: [0=no blur, 255=max blur])
|
// 1D Box blur (with added weight - blur_amount: [0=no blur, 255=max blur])
|
||||||
void Segment::box_blur(uint16_t i, bool vertical, fract8 blur_amount) {
|
void Segment::box_blur(uint16_t i, bool vertical, fract8 blur_amount) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
const uint16_t dim1 = vertical ? rows : cols;
|
const uint16_t dim1 = vertical ? rows : cols;
|
||||||
@ -404,8 +331,8 @@ void Segment::box_blur(uint16_t i, bool vertical, fract8 blur_amount) {
|
|||||||
for (uint16_t j = 0; j < dim1; j++) {
|
for (uint16_t j = 0; j < dim1; j++) {
|
||||||
uint16_t x = vertical ? i : j;
|
uint16_t x = vertical ? i : j;
|
||||||
uint16_t y = vertical ? j : i;
|
uint16_t y = vertical ? j : i;
|
||||||
int16_t xp = vertical ? x : x-1; // "signed" to prevent underflow
|
uint16_t xp = vertical ? x : x-1;
|
||||||
int16_t yp = vertical ? y-1 : y; // "signed" to prevent underflow
|
uint16_t yp = vertical ? y-1 : y;
|
||||||
uint16_t xn = vertical ? x : x+1;
|
uint16_t xn = vertical ? x : x+1;
|
||||||
uint16_t yn = vertical ? y+1 : y;
|
uint16_t yn = vertical ? y+1 : y;
|
||||||
CRGB curr = getPixelColorXY(x,y);
|
CRGB curr = getPixelColorXY(x,y);
|
||||||
@ -443,87 +370,59 @@ void Segment::blur1d(fract8 blur_amount) {
|
|||||||
for (uint16_t y = 0; y < rows; y++) blurRow(y, blur_amount);
|
for (uint16_t y = 0; y < rows; y++) blurRow(y, blur_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::moveX(int8_t delta, bool wrap) {
|
void Segment::moveX(int8_t delta) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
if (!delta || abs(delta) >= cols) return;
|
if (!delta) return;
|
||||||
uint32_t newPxCol[cols];
|
|
||||||
for (int y = 0; y < rows; y++) {
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
for (int x = 0; x < cols-delta; x++) newPxCol[x] = getPixelColorXY((x + delta), y);
|
for (uint8_t y = 0; y < rows; y++) for (uint8_t x = 0; x < cols-1; x++) {
|
||||||
for (int x = cols-delta; x < cols; x++) newPxCol[x] = getPixelColorXY(wrap ? (x + delta) - cols : x, y);
|
if (x + delta >= cols) break;
|
||||||
} else {
|
setPixelColorXY(x, y, getPixelColorXY((x + delta)%cols, y));
|
||||||
for (int x = cols-1; x >= -delta; x--) newPxCol[x] = getPixelColorXY((x + delta), y);
|
}
|
||||||
for (int x = -delta-1; x >= 0; x--) newPxCol[x] = getPixelColorXY(wrap ? (x + delta) + cols : x, y);
|
} else {
|
||||||
|
for (uint8_t y = 0; y < rows; y++) for (int16_t x = cols-1; x >= 0; x--) {
|
||||||
|
if (x + delta < 0) break;
|
||||||
|
setPixelColorXY(x, y, getPixelColorXY(x + delta, y));
|
||||||
}
|
}
|
||||||
for (int x = 0; x < cols; x++) setPixelColorXY(x, y, newPxCol[x]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::moveY(int8_t delta, bool wrap) {
|
void Segment::moveY(int8_t delta) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
if (!delta || abs(delta) >= rows) return;
|
if (!delta) return;
|
||||||
uint32_t newPxCol[rows];
|
|
||||||
for (int x = 0; x < cols; x++) {
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
for (int y = 0; y < rows-delta; y++) newPxCol[y] = getPixelColorXY(x, (y + delta));
|
for (uint8_t x = 0; x < cols; x++) for (uint8_t y = 0; y < rows-1; y++) {
|
||||||
for (int y = rows-delta; y < rows; y++) newPxCol[y] = getPixelColorXY(x, wrap ? (y + delta) - rows : y);
|
if (y + delta >= rows) break;
|
||||||
} else {
|
setPixelColorXY(x, y, getPixelColorXY(x, (y + delta)));
|
||||||
for (int y = rows-1; y >= -delta; y--) newPxCol[y] = getPixelColorXY(x, (y + delta));
|
}
|
||||||
for (int y = -delta-1; y >= 0; y--) newPxCol[y] = getPixelColorXY(x, wrap ? (y + delta) + rows : y);
|
} else {
|
||||||
|
for (uint8_t x = 0; x < cols; x++) for (int16_t y = rows-1; y >= 0; y--) {
|
||||||
|
if (y + delta < 0) break;
|
||||||
|
setPixelColorXY(x, y, getPixelColorXY(x, y + delta));
|
||||||
}
|
}
|
||||||
for (int y = 0; y < rows; y++) setPixelColorXY(x, y, newPxCol[y]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// move() - move all pixels in desired direction delta number of pixels
|
// move() - move all pixels in desired direction delta number of pixels
|
||||||
// @param dir direction: 0=left, 1=left-up, 2=up, 3=right-up, 4=right, 5=right-down, 6=down, 7=left-down
|
// @param dir direction: 0=left, 1=left-up, 2=up, 3=right-up, 4=right, 5=right-down, 6=down, 7=left-down
|
||||||
// @param delta number of pixels to move
|
// @param delta number of pixels to move
|
||||||
// @param wrap around
|
void Segment::move(uint8_t dir, uint8_t delta) {
|
||||||
void Segment::move(uint8_t dir, uint8_t delta, bool wrap) {
|
|
||||||
if (delta==0) return;
|
if (delta==0) return;
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case 0: moveX( delta, wrap); break;
|
case 0: moveX( delta); break;
|
||||||
case 1: moveX( delta, wrap); moveY( delta, wrap); break;
|
case 1: moveX( delta); moveY( delta); break;
|
||||||
case 2: moveY( delta, wrap); break;
|
case 2: moveY( delta); break;
|
||||||
case 3: moveX(-delta, wrap); moveY( delta, wrap); break;
|
case 3: moveX(-delta); moveY( delta); break;
|
||||||
case 4: moveX(-delta, wrap); break;
|
case 4: moveX(-delta); break;
|
||||||
case 5: moveX(-delta, wrap); moveY(-delta, wrap); break;
|
case 5: moveX(-delta); moveY(-delta); break;
|
||||||
case 6: moveY(-delta, wrap); break;
|
case 6: moveY(-delta); break;
|
||||||
case 7: moveX( delta, wrap); moveY(-delta, wrap); break;
|
case 7: moveX( delta); moveY(-delta); break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Segment::draw_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
|
|
||||||
if (!isActive()) return; // not active
|
|
||||||
// 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
|
// 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) {
|
void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
for (int16_t y = -radius; y <= radius; y++) {
|
for (int16_t y = -radius; y <= radius; y++) {
|
||||||
@ -531,13 +430,12 @@ void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
|
|||||||
if (x * x + y * y <= radius * radius &&
|
if (x * x + y * y <= radius * radius &&
|
||||||
int16_t(cx)+x>=0 && int16_t(cy)+y>=0 &&
|
int16_t(cx)+x>=0 && int16_t(cy)+y>=0 &&
|
||||||
int16_t(cx)+x<cols && int16_t(cy)+y<rows)
|
int16_t(cx)+x<cols && int16_t(cy)+y<rows)
|
||||||
setPixelColorXY(cx + x, cy + y, col);
|
addPixelColorXY(cx + x, cy + y, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::nscale8(uint8_t scale) {
|
void Segment::nscale8(uint8_t scale) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) {
|
for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) {
|
||||||
@ -547,7 +445,6 @@ void Segment::nscale8(uint8_t scale) {
|
|||||||
|
|
||||||
//line function
|
//line function
|
||||||
void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) {
|
void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
if (x0 >= cols || x1 >= cols || y0 >= rows || y1 >= rows) return;
|
if (x0 >= cols || x1 >= cols || y0 >= rows || y1 >= rows) return;
|
||||||
@ -555,7 +452,7 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
|
|||||||
const int16_t dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
|
const int16_t dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
|
||||||
int16_t err = (dx>dy ? dx : -dy)/2, e2;
|
int16_t err = (dx>dy ? dx : -dy)/2, e2;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
setPixelColorXY(x0,y0,c);
|
addPixelColorXY(x0,y0,c);
|
||||||
if (x0==x1 && y0==y1) break;
|
if (x0==x1 && y0==y1) break;
|
||||||
e2 = err;
|
e2 = err;
|
||||||
if (e2 >-dx) { err -= dy; x0 += sx; }
|
if (e2 >-dx) { err -= dy; x0 += sx; }
|
||||||
@ -571,19 +468,18 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
|
|||||||
|
|
||||||
// draws a raster font character on canvas
|
// draws a raster font character on canvas
|
||||||
// only supports: 4x6=24, 5x8=40, 5x12=60, 6x8=48 and 7x9=63 fonts ATM
|
// 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, uint32_t col2, int8_t rotate) {
|
void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color) {
|
||||||
if (!isActive()) return; // not active
|
|
||||||
if (chr < 32 || chr > 126) return; // only ASCII 32-126 supported
|
if (chr < 32 || chr > 126) return; // only ASCII 32-126 supported
|
||||||
chr -= 32; // align with font table entries
|
chr -= 32; // align with font table entries
|
||||||
const uint16_t cols = virtualWidth();
|
const uint16_t cols = virtualWidth();
|
||||||
const uint16_t rows = virtualHeight();
|
const uint16_t rows = virtualHeight();
|
||||||
const int font = w*h;
|
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;
|
//if (w<5 || w>6 || h!=8) return;
|
||||||
for (int i = 0; i<h; i++) { // character height
|
for (int i = 0; i<h; i++) { // character height
|
||||||
|
int16_t y0 = y + i;
|
||||||
|
if (y0 < 0) continue; // drawing off-screen
|
||||||
|
if (y0 >= rows) break; // drawing off-screen
|
||||||
uint8_t bits = 0;
|
uint8_t bits = 0;
|
||||||
switch (font) {
|
switch (font) {
|
||||||
case 24: bits = pgm_read_byte_near(&console_font_4x6[(chr * h) + i]); break; // 5x8 font
|
case 24: bits = pgm_read_byte_near(&console_font_4x6[(chr * h) + i]); break; // 5x8 font
|
||||||
@ -593,19 +489,10 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w,
|
|||||||
case 60: bits = pgm_read_byte_near(&console_font_5x12[(chr * h) + i]); break; // 5x12 font
|
case 60: bits = pgm_read_byte_near(&console_font_5x12[(chr * h) + i]); break; // 5x12 font
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
col = ColorFromPalette(grad, (i+1)*255/h, 255, NOBLEND);
|
|
||||||
for (int j = 0; j<w; j++) { // character width
|
for (int j = 0; j<w; j++) { // character width
|
||||||
int x0, y0;
|
int16_t x0 = x + (w-1) - j;
|
||||||
switch (rotate) {
|
if ((x0 >= 0 || x0 < cols) && ((bits>>(j+(8-w))) & 0x01)) { // bit set & drawing on-screen
|
||||||
case -1: x0 = x + (h-1) - i; y0 = y + (w-1) - j; break; // -90 deg
|
addPixelColorXY(x0, y0, color);
|
||||||
case -2:
|
|
||||||
case 2: x0 = x + j; y0 = y + (h-1) - i; break; // 180 deg
|
|
||||||
case 1: x0 = x + i; y0 = y + j; break; // +90 deg
|
|
||||||
default: x0 = x + (w-1) - j; y0 = y + i; break; // no rotation
|
|
||||||
}
|
|
||||||
if (x0 < 0 || x0 >= cols || y0 < 0 || y0 >= rows) continue; // drawing off-screen
|
|
||||||
if (((bits>>(j+(8-w))) & 0x01)) { // bit set
|
|
||||||
setPixelColorXY(x0, y0, col);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -613,7 +500,6 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w,
|
|||||||
|
|
||||||
#define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
|
#define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
|
||||||
void Segment::wu_pixel(uint32_t x, uint32_t y, CRGB c) { //awesome wu_pixel procedure by reddit u/sutaburosu
|
void Segment::wu_pixel(uint32_t x, uint32_t y, CRGB c) { //awesome wu_pixel procedure by reddit u/sutaburosu
|
||||||
if (!isActive()) return; // not active
|
|
||||||
// extract the fractional parts and derive their inverses
|
// extract the fractional parts and derive their inverses
|
||||||
uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
|
uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
|
||||||
// calculate the intensities for each affected pixel
|
// calculate the intensities for each affected pixel
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#include <IPAddress.h>
|
#include <IPAddress.h>
|
||||||
|
|
||||||
#define NODE_TYPE_ID_UNDEFINED 0
|
#define NODE_TYPE_ID_UNDEFINED 0
|
||||||
#define NODE_TYPE_ID_ESP8266 82 // should be 1
|
#define NODE_TYPE_ID_ESP8266 82
|
||||||
#define NODE_TYPE_ID_ESP32 32 // should be 2
|
#define NODE_TYPE_ID_ESP32 32
|
||||||
#define NODE_TYPE_ID_ESP32S2 33 // etc
|
#define NODE_TYPE_ID_ESP32S2 33
|
||||||
#define NODE_TYPE_ID_ESP32S3 34
|
#define NODE_TYPE_ID_ESP32S3 34
|
||||||
#define NODE_TYPE_ID_ESP32C3 35
|
#define NODE_TYPE_ID_ESP32C3 35
|
||||||
|
|
||||||
@ -23,13 +23,7 @@ struct NodeStruct
|
|||||||
String nodeName;
|
String nodeName;
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
uint8_t age;
|
uint8_t age;
|
||||||
union {
|
uint8_t nodeType;
|
||||||
uint8_t nodeType; // a waste of space as we only have 5 types
|
|
||||||
struct {
|
|
||||||
uint8_t type : 7; // still a waste of space (4 bits would be enough and future-proof)
|
|
||||||
bool on : 1;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
uint32_t build;
|
uint32_t build;
|
||||||
|
|
||||||
NodeStruct() : age(0), nodeType(0), build(0)
|
NodeStruct() : age(0), nodeType(0), build(0)
|
||||||
|
@ -105,15 +105,8 @@ void onAlexaChange(EspalexaDevice* dev)
|
|||||||
uint16_t k = 1000000 / ct; //mireds to kelvin
|
uint16_t k = 1000000 / ct; //mireds to kelvin
|
||||||
|
|
||||||
if (strip.hasCCTBus()) {
|
if (strip.hasCCTBus()) {
|
||||||
bool hasManualWhite = strip.getActiveSegsLightCapabilities(true) & SEG_CAPABILITY_W;
|
|
||||||
|
|
||||||
strip.setCCT(k);
|
strip.setCCT(k);
|
||||||
if (hasManualWhite) {
|
|
||||||
rgbw[0]= 0; rgbw[1]= 0; rgbw[2]= 0; rgbw[3]= 255;
|
rgbw[0]= 0; rgbw[1]= 0; rgbw[2]= 0; rgbw[3]= 255;
|
||||||
} else {
|
|
||||||
rgbw[0] = 255; rgbw[1] = 255; rgbw[2] = 255; rgbw[3] = 0;
|
|
||||||
dev->setValue(255);
|
|
||||||
}
|
|
||||||
} else if (strip.hasWhiteChannel()) {
|
} else if (strip.hasWhiteChannel()) {
|
||||||
switch (ct) { //these values empirically look good on RGBW
|
switch (ct) { //these values empirically look good on RGBW
|
||||||
case 199: rgbw[0]=255; rgbw[1]=255; rgbw[2]=255; rgbw[3]=255; break;
|
case 199: rgbw[0]=255; rgbw[1]=255; rgbw[2]=255; rgbw[3]=255; break;
|
||||||
|
99
wled00/blynk.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#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
|
@ -1,641 +0,0 @@
|
|||||||
/*
|
|
||||||
* Class implementation for addressing various light types
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <IPAddress.h>
|
|
||||||
#include "const.h"
|
|
||||||
#include "pin_manager.h"
|
|
||||||
#include "bus_wrapper.h"
|
|
||||||
#include "bus_manager.h"
|
|
||||||
|
|
||||||
//colors.cpp
|
|
||||||
uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb);
|
|
||||||
uint16_t approximateKelvinFromRGB(uint32_t rgb);
|
|
||||||
void colorRGBtoRGBW(byte* rgb);
|
|
||||||
|
|
||||||
//udp.cpp
|
|
||||||
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, byte *buffer, uint8_t bri=255, bool isRGBW=false);
|
|
||||||
|
|
||||||
// enable additional debug output
|
|
||||||
#if defined(WLED_DEBUG_HOST)
|
|
||||||
#include "net_debug.h"
|
|
||||||
#define DEBUGOUT NetDebug
|
|
||||||
#else
|
|
||||||
#define DEBUGOUT Serial
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WLED_DEBUG
|
|
||||||
#ifndef ESP8266
|
|
||||||
#include <rom/rtc.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *Bus::allocData(size_t size) {
|
|
||||||
if (_data) free(_data); // should not happen, but for safety
|
|
||||||
return _data = (uint8_t *)(size>0 ? calloc(size, sizeof(uint8_t)) : nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com)
|
|
||||||
: Bus(bc.type, bc.start, bc.autoWhite, bc.count, bc.reversed, (bc.refreshReq || bc.type == TYPE_TM1814))
|
|
||||||
, _skip(bc.skipAmount) //sacrificial pixels
|
|
||||||
, _colorOrder(bc.colorOrder)
|
|
||||||
, _colorOrderMap(com)
|
|
||||||
{
|
|
||||||
if (!IS_DIGITAL(bc.type) || !bc.count) return;
|
|
||||||
if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
|
|
||||||
_frequencykHz = 0U;
|
|
||||||
_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];
|
|
||||||
_frequencykHz = bc.frequency ? bc.frequency : 2000U; // 2MHz clock if undefined
|
|
||||||
}
|
|
||||||
_iType = PolyBus::getI(bc.type, _pins, nr);
|
|
||||||
if (_iType == I_NONE) return;
|
|
||||||
if (bc.doubleBuffer && !allocData(bc.count * (Bus::hasWhite(_type) + 3*Bus::hasRGB(_type)))) return; //warning: hardcoded channel count
|
|
||||||
_buffering = bc.doubleBuffer;
|
|
||||||
uint16_t lenToCreate = bc.count;
|
|
||||||
if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(bc.count); // only needs a third of "RGB" LEDs for NeoPixelBus
|
|
||||||
_busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz);
|
|
||||||
_valid = (_busPtr != nullptr);
|
|
||||||
DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n", _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], _pins[1], _iType);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusDigital::show() {
|
|
||||||
if (!_valid) return;
|
|
||||||
if (_buffering) { // should be _data != nullptr, but that causes ~20% FPS drop
|
|
||||||
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
|
|
||||||
for (size_t i=0; i<_len; i++) {
|
|
||||||
size_t offset = i*channels;
|
|
||||||
uint8_t co = _colorOrderMap.getPixelColorOrder(i+_start, _colorOrder);
|
|
||||||
uint32_t c;
|
|
||||||
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs (_len is always a multiple of 3)
|
|
||||||
switch (i%3) {
|
|
||||||
case 0: c = RGBW32(_data[offset] , _data[offset+1], _data[offset+2], 0); break;
|
|
||||||
case 1: c = RGBW32(_data[offset-1], _data[offset] , _data[offset+1], 0); break;
|
|
||||||
case 2: c = RGBW32(_data[offset-2], _data[offset-1], _data[offset] , 0); break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c = RGBW32(_data[offset],_data[offset+1],_data[offset+2],(Bus::hasWhite(_type)?_data[offset+3]:0));
|
|
||||||
}
|
|
||||||
uint16_t pix = i;
|
|
||||||
if (_reversed) pix = _len - pix -1;
|
|
||||||
pix += _skip;
|
|
||||||
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
|
|
||||||
}
|
|
||||||
#if !defined(STATUSLED) || STATUSLED>=0
|
|
||||||
if (_skip) PolyBus::setPixelColor(_busPtr, _iType, 0, 0, _colorOrderMap.getPixelColorOrder(_start, _colorOrder)); // paint skipped pixels black
|
|
||||||
#endif
|
|
||||||
for (int i=1; i<_skip; i++) PolyBus::setPixelColor(_busPtr, _iType, i, 0, _colorOrderMap.getPixelColorOrder(_start, _colorOrder)); // paint skipped pixels black
|
|
||||||
}
|
|
||||||
PolyBus::show(_busPtr, _iType, !_buffering); // faster if buffer consistency is not important
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BusDigital::canShow() {
|
|
||||||
if (!_valid) return true;
|
|
||||||
return PolyBus::canShow(_busPtr, _iType);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusDigital::setBrightness(uint8_t b) {
|
|
||||||
if (_bri == b) return;
|
|
||||||
//Fix for turning off onboard LED breaking bus
|
|
||||||
#ifdef LED_BUILTIN
|
|
||||||
if (_bri == 0) { // && b > 0, covered by guard if above
|
|
||||||
if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) reinit();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
uint8_t prevBri = _bri;
|
|
||||||
Bus::setBrightness(b);
|
|
||||||
PolyBus::setBrightness(_busPtr, _iType, b);
|
|
||||||
|
|
||||||
if (_buffering) return;
|
|
||||||
|
|
||||||
// must update/repaint every LED in the NeoPixelBus buffer to the new brightness
|
|
||||||
// the only case where repainting is unnecessary is when all pixels are set after the brightness change but before the next show
|
|
||||||
// (which we can't rely on)
|
|
||||||
uint16_t hwLen = _len;
|
|
||||||
if (_type == TYPE_WS2812_1CH_X3) hwLen = NUM_ICS_WS2812_1CH_3X(_len); // only needs a third of "RGB" LEDs for NeoPixelBus
|
|
||||||
for (uint_fast16_t i = 0; i < hwLen; i++) {
|
|
||||||
// use 0 as color order, actual order does not matter here as we just update the channel values as-is
|
|
||||||
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, i, 0),prevBri);
|
|
||||||
PolyBus::setPixelColor(_busPtr, _iType, i, c, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//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 (_valid && _skip) {
|
|
||||||
PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrderMap.getPixelColorOrder(_start, _colorOrder));
|
|
||||||
if (canShow()) PolyBus::show(_busPtr, _iType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
|
|
||||||
if (!_valid) return;
|
|
||||||
if (Bus::hasWhite(_type)) c = autoWhiteCalc(c);
|
|
||||||
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
|
|
||||||
if (_buffering) { // should be _data != nullptr, but that causes ~20% FPS drop
|
|
||||||
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
|
|
||||||
size_t offset = pix*channels;
|
|
||||||
if (Bus::hasRGB(_type)) {
|
|
||||||
_data[offset++] = R(c);
|
|
||||||
_data[offset++] = G(c);
|
|
||||||
_data[offset++] = B(c);
|
|
||||||
}
|
|
||||||
if (Bus::hasWhite(_type)) _data[offset] = W(c);
|
|
||||||
} else {
|
|
||||||
if (_reversed) pix = _len - pix -1;
|
|
||||||
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 = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, pix, co),_bri);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns original color if global buffering is enabled, else returns lossly restored color from bus
|
|
||||||
uint32_t BusDigital::getPixelColor(uint16_t pix) {
|
|
||||||
if (!_valid) return 0;
|
|
||||||
if (_buffering) { // should be _data != nullptr, but that causes ~20% FPS drop
|
|
||||||
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
|
|
||||||
size_t offset = pix*channels;
|
|
||||||
uint32_t c;
|
|
||||||
if (!Bus::hasRGB(_type)) {
|
|
||||||
c = RGBW32(_data[offset], _data[offset], _data[offset], _data[offset]);
|
|
||||||
} else {
|
|
||||||
c = RGBW32(_data[offset], _data[offset+1], _data[offset+2], Bus::hasWhite(_type) ? _data[offset+3] : 0);
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
} else {
|
|
||||||
if (_reversed) pix = _len - pix -1;
|
|
||||||
pix += _skip;
|
|
||||||
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
|
|
||||||
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, (_type==TYPE_WS2812_1CH_X3) ? IC_INDEX_WS2812_1CH_3X(pix) : pix, co),_bri);
|
|
||||||
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
|
|
||||||
uint8_t r = R(c);
|
|
||||||
uint8_t g = _reversed ? B(c) : G(c); // should G and B be switched if _reversed?
|
|
||||||
uint8_t b = _reversed ? G(c) : B(c);
|
|
||||||
switch (pix % 3) { // get only the single channel
|
|
||||||
case 0: c = RGBW32(g, g, g, g); break;
|
|
||||||
case 1: c = RGBW32(r, r, r, r); break;
|
|
||||||
case 2: c = RGBW32(b, b, b, b); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
|
||||||
if (!_valid) return;
|
|
||||||
PolyBus::begin(_busPtr, _iType, _pins);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusDigital::cleanup() {
|
|
||||||
DEBUG_PRINTLN(F("Digital Cleanup."));
|
|
||||||
PolyBus::cleanup(_busPtr, _iType);
|
|
||||||
_iType = I_NONE;
|
|
||||||
_valid = false;
|
|
||||||
_busPtr = nullptr;
|
|
||||||
if (_data != nullptr) freeData();
|
|
||||||
pinManager.deallocatePin(_pins[1], PinOwner::BusDigital);
|
|
||||||
pinManager.deallocatePin(_pins[0], PinOwner::BusDigital);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BusPwm::BusPwm(BusConfig &bc)
|
|
||||||
: Bus(bc.type, bc.start, bc.autoWhite, 1, bc.reversed)
|
|
||||||
{
|
|
||||||
if (!IS_PWM(bc.type)) return;
|
|
||||||
uint8_t numPins = NUM_PWM_PINS(bc.type);
|
|
||||||
_frequency = bc.frequency ? bc.frequency : WLED_PWM_FREQ;
|
|
||||||
|
|
||||||
#ifdef ESP8266
|
|
||||||
analogWriteRange(255); //same range as one RGB channel
|
|
||||||
analogWriteFreq(_frequency);
|
|
||||||
#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, _frequency, 8);
|
|
||||||
ledcAttachPin(_pins[i], _ledcStart + i);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
_data = _pwmdata; // avoid malloc() and use stack
|
|
||||||
_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, 1, bc.reversed)
|
|
||||||
, _onoffdata(0)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
_data = &_onoffdata; // avoid malloc() and use stack
|
|
||||||
_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[0] = bool(r|g|b|w) && bool(_bri) ? 0xFF : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t BusOnOff::getPixelColor(uint16_t pix) {
|
|
||||||
if (!_valid) return 0;
|
|
||||||
return RGBW32(_data[0], _data[0], _data[0], _data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusOnOff::show() {
|
|
||||||
if (!_valid) return;
|
|
||||||
digitalWrite(_pin, _reversed ? !(bool)_data[0] : (bool)_data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, bc.count)
|
|
||||||
, _broadcastLock(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;
|
|
||||||
_client = IPAddress(bc.pins[0],bc.pins[1],bc.pins[2],bc.pins[3]);
|
|
||||||
_valid = (allocData(_len * _UDPchannels) != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BusNetwork::setPixelColor(uint16_t pix, uint32_t c) {
|
|
||||||
if (!_valid || pix >= _len) return;
|
|
||||||
if (_rgbw) 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] : 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;
|
|
||||||
freeData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//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) { // digital types
|
|
||||||
if (type == TYPE_UCS8903 || type == TYPE_UCS8904) len *= 2; // 16-bit LEDs
|
|
||||||
#ifdef ESP8266
|
|
||||||
if (bc.pins[0] == 3) { //8266 DMA uses 5x the mem
|
|
||||||
if (type > 28) return len*20; //RGBW
|
|
||||||
return len*15;
|
|
||||||
}
|
|
||||||
if (type > 28) return len*4; //RGBW
|
|
||||||
return len*3;
|
|
||||||
#else //ESP32 RMT uses double buffer?
|
|
||||||
if (type > 28) return len*8; //RGBW
|
|
||||||
return len*6;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (type > 31 && type < 48) return 5;
|
|
||||||
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) {
|
|
||||||
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; i<numBusses; i++) len += busses[i]->getLength();
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bus static member definition
|
|
||||||
int16_t Bus::_cct = -1;
|
|
||||||
uint8_t Bus::_cctBlend = 0;
|
|
||||||
uint8_t Bus::_gAWM = 255;
|
|
@ -6,21 +6,44 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
#include "pin_manager.h"
|
||||||
|
#include "bus_wrapper.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
//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 <rom/rtc.h>
|
||||||
|
#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 GET_BIT(var,bit) (((var)>>(bit))&0x01)
|
||||||
#define SET_BIT(var,bit) ((var)|=(uint16_t)(0x0001<<(bit)))
|
#define SET_BIT(var,bit) ((var)|=(uint16_t)(0x0001<<(bit)))
|
||||||
#define UNSET_BIT(var,bit) ((var)&=(~(uint16_t)(0x0001<<(bit))))
|
#define UNSET_BIT(var,bit) ((var)&=(~(uint16_t)(0x0001<<(bit))))
|
||||||
|
|
||||||
#define NUM_ICS_WS2812_1CH_3X(len) (((len)+2)/3) // 1 WS2811 IC controls 3 zones (each zone has 1 LED, W)
|
//color mangling macros
|
||||||
#define IC_INDEX_WS2812_1CH_3X(i) ((i)/3)
|
#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 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 G(c) (byte((c) >> 8))
|
||||||
#define IC_INDEX_WS2812_2CH_3X(i) ((i)*2/3)
|
#define B(c) (byte(c))
|
||||||
#define WS2812_2CH_3X_SPANS_2_ICS(i) ((i)&0x01) // every other LED zone is on two different ICs
|
#define W(c) (byte((c) >> 24))
|
||||||
|
|
||||||
// flag for using double buffering in BusDigital
|
|
||||||
extern bool useGlobalLedBuffer;
|
|
||||||
|
|
||||||
|
|
||||||
//temporary struct for passing bus configuration to bus
|
//temporary struct for passing bus configuration to bus
|
||||||
struct BusConfig {
|
struct BusConfig {
|
||||||
@ -33,26 +56,15 @@ struct BusConfig {
|
|||||||
bool refreshReq;
|
bool refreshReq;
|
||||||
uint8_t autoWhite;
|
uint8_t autoWhite;
|
||||||
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
|
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
|
||||||
uint16_t frequency;
|
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY) {
|
||||||
bool doubleBuffer;
|
|
||||||
|
|
||||||
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY, uint16_t clock_kHz=0U, bool dblBfr=false)
|
|
||||||
: count(len)
|
|
||||||
, start(pstart)
|
|
||||||
, colorOrder(pcolorOrder)
|
|
||||||
, reversed(rev)
|
|
||||||
, skipAmount(skip)
|
|
||||||
, autoWhite(aw)
|
|
||||||
, frequency(clock_kHz)
|
|
||||||
, doubleBuffer(dblBfr)
|
|
||||||
{
|
|
||||||
refreshReq = (bool) GET_BIT(busType,7);
|
refreshReq = (bool) GET_BIT(busType,7);
|
||||||
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)
|
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)
|
||||||
size_t nPins = 1;
|
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; autoWhite = aw;
|
||||||
|
uint8_t nPins = 1;
|
||||||
if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address
|
if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address
|
||||||
else if (type > 47) nPins = 2;
|
else if (type > 47) nPins = 2;
|
||||||
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
|
else if (type > 40 && type < 46) nPins = NUM_PWM_PINS(type);
|
||||||
for (size_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
for (uint8_t i = 0; i < nPins; i++) pins[i] = ppins[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//validates start and length and extends total if needed
|
//validates start and length and extends total if needed
|
||||||
@ -68,7 +80,6 @@ struct BusConfig {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Defines an LED Strip and its color ordering.
|
// Defines an LED Strip and its color ordering.
|
||||||
struct ColorOrderMapEntry {
|
struct ColorOrderMapEntry {
|
||||||
uint16_t start;
|
uint16_t start;
|
||||||
@ -77,9 +88,25 @@ struct ColorOrderMapEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ColorOrderMap {
|
struct ColorOrderMap {
|
||||||
void add(uint16_t start, uint16_t len, uint8_t colorOrder);
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t count() const { return _count; }
|
uint8_t count() const {
|
||||||
|
return _count;
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
_count = 0;
|
_count = 0;
|
||||||
@ -93,28 +120,35 @@ struct ColorOrderMap {
|
|||||||
return &(_mappings[n]);
|
return &(_mappings[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultColorOrder;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t _count;
|
uint8_t _count;
|
||||||
ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
|
ColorOrderMapEntry _mappings[WLED_MAX_COLOR_ORDER_MAPPINGS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//parent class of BusDigital, BusPwm, and BusNetwork
|
//parent class of BusDigital, BusPwm, and BusNetwork
|
||||||
class Bus {
|
class Bus {
|
||||||
public:
|
public:
|
||||||
Bus(uint8_t type, uint16_t start, uint8_t aw, uint16_t len = 1, bool reversed = false, bool refresh = false)
|
Bus(uint8_t type, uint16_t start, uint8_t aw)
|
||||||
: _type(type)
|
: _bri(255)
|
||||||
, _bri(255)
|
, _len(1)
|
||||||
, _start(start)
|
|
||||||
, _len(len)
|
|
||||||
, _reversed(reversed)
|
|
||||||
, _valid(false)
|
, _valid(false)
|
||||||
, _needsRefresh(refresh)
|
, _needsRefresh(false)
|
||||||
, _data(nullptr) // keep data access consistent across all types of buses
|
|
||||||
{
|
{
|
||||||
_autoWhiteMode = Bus::hasWhite(_type) ? aw : RGBW_MODE_MANUAL_ONLY;
|
_type = type;
|
||||||
|
_start = start;
|
||||||
|
_autoWhiteMode = Bus::isRgbw(_type) ? aw : RGBW_MODE_MANUAL_ONLY;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Bus() {} //throw the bus under the bus
|
virtual ~Bus() {} //throw the bus under the bus
|
||||||
@ -131,32 +165,27 @@ class Bus {
|
|||||||
virtual void setColorOrder() {}
|
virtual void setColorOrder() {}
|
||||||
virtual uint8_t getColorOrder() { return COL_ORDER_RGB; }
|
virtual uint8_t getColorOrder() { return COL_ORDER_RGB; }
|
||||||
virtual uint8_t skippedLeds() { return 0; }
|
virtual uint8_t skippedLeds() { return 0; }
|
||||||
virtual uint16_t getFrequency() { return 0U; }
|
|
||||||
inline void setReversed(bool reversed) { _reversed = reversed; }
|
|
||||||
inline uint16_t getStart() { return _start; }
|
inline uint16_t getStart() { return _start; }
|
||||||
inline void setStart(uint16_t start) { _start = start; }
|
inline void setStart(uint16_t start) { _start = start; }
|
||||||
inline uint8_t getType() { return _type; }
|
inline uint8_t getType() { return _type; }
|
||||||
inline bool isOk() { return _valid; }
|
inline bool isOk() { return _valid; }
|
||||||
inline bool isReversed() { return _reversed; }
|
|
||||||
inline bool isOffRefreshRequired() { return _needsRefresh; }
|
inline bool isOffRefreshRequired() { return _needsRefresh; }
|
||||||
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; }
|
bool containsPixel(uint16_t pix) { return pix >= _start && pix < _start+_len; }
|
||||||
|
|
||||||
virtual bool hasRGB(void) { return Bus::hasRGB(_type); }
|
virtual bool isRgbw() { return Bus::isRgbw(_type); }
|
||||||
static bool hasRGB(uint8_t type) {
|
static bool isRgbw(uint8_t type) {
|
||||||
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_SK6812_RGBW || type == TYPE_TM1814) return true;
|
||||||
return true;
|
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true;
|
||||||
}
|
if (type == TYPE_NET_DDP_RGBW) return true;
|
||||||
virtual bool hasWhite(void) { 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;
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool hasCCT(void) { return Bus::hasCCT(_type); }
|
virtual bool hasRGB() {
|
||||||
static bool hasCCT(uint8_t type) {
|
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_2CH_X3 || type == TYPE_WS2812_WWA ||
|
return true;
|
||||||
type == TYPE_ANALOG_2CH || type == TYPE_ANALOG_5CH) 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;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static void setCCT(uint16_t cct) {
|
static void setCCT(uint16_t cct) {
|
||||||
@ -170,127 +199,455 @@ class Bus {
|
|||||||
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
|
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
|
inline void setAWMode(uint8_t m) { if (m < 4) _autoWhiteMode = m; }
|
||||||
inline uint8_t getAutoWhiteMode() { return _autoWhiteMode; }
|
inline uint8_t getAWMode() { return _autoWhiteMode; }
|
||||||
inline static void setGlobalAWMode(uint8_t m) { if (m < 5) _gAWM = m; else _gAWM = AW_GLOBAL_DISABLED; }
|
inline static void setAutoWhiteMode(uint8_t m) { if (m < 4) _gAWM = m; else _gAWM = 255; }
|
||||||
inline static uint8_t getGlobalAWMode() { return _gAWM; }
|
inline static uint8_t getAutoWhiteMode() { return _gAWM; }
|
||||||
|
|
||||||
|
bool reversed = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t _type;
|
uint8_t _type;
|
||||||
uint8_t _bri;
|
uint8_t _bri;
|
||||||
uint16_t _start;
|
uint16_t _start;
|
||||||
uint16_t _len;
|
uint16_t _len;
|
||||||
bool _reversed;
|
|
||||||
bool _valid;
|
bool _valid;
|
||||||
bool _needsRefresh;
|
bool _needsRefresh;
|
||||||
uint8_t _autoWhiteMode;
|
uint8_t _autoWhiteMode;
|
||||||
uint8_t *_data;
|
static uint8_t _gAWM; // definition in FX_fcn.cpp
|
||||||
static uint8_t _gAWM;
|
static int16_t _cct; // definition in FX_fcn.cpp
|
||||||
static int16_t _cct;
|
static uint8_t _cctBlend; // definition in FX_fcn.cpp
|
||||||
static uint8_t _cctBlend;
|
|
||||||
|
|
||||||
uint32_t autoWhiteCalc(uint32_t c);
|
uint32_t autoWhiteCalc(uint32_t c) {
|
||||||
uint8_t *allocData(size_t size = 1);
|
uint8_t aWM = _autoWhiteMode;
|
||||||
void freeData() { if (_data != nullptr) free(_data); _data = nullptr; }
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusDigital : public Bus {
|
class BusDigital : public Bus {
|
||||||
public:
|
public:
|
||||||
BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com);
|
BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bus(bc.type, bc.start, bc.autoWhite), _colorOrderMap(com) {
|
||||||
~BusDigital() { cleanup(); }
|
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;
|
||||||
|
_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);
|
||||||
|
};
|
||||||
|
|
||||||
void show();
|
inline void show() {
|
||||||
bool canShow();
|
PolyBus::show(_busPtr, _iType);
|
||||||
void setBrightness(uint8_t b);
|
}
|
||||||
void setStatusPixel(uint32_t c);
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c);
|
inline bool canShow() {
|
||||||
void setColorOrder(uint8_t colorOrder);
|
return PolyBus::canShow(_busPtr, _iType);
|
||||||
uint32_t getPixelColor(uint16_t pix);
|
}
|
||||||
uint8_t getColorOrder() { return _colorOrder; }
|
|
||||||
uint8_t getPins(uint8_t* pinArray);
|
void setBrightness(uint8_t b) {
|
||||||
uint8_t skippedLeds() { return _skip; }
|
//Fix for turning off onboard LED breaking bus
|
||||||
uint16_t getFrequency() { return _frequencykHz; }
|
#ifdef LED_BUILTIN
|
||||||
void reinit();
|
if (_bri == 0 && b > 0) {
|
||||||
void cleanup();
|
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 setStatusPixel(uint32_t c) {
|
||||||
|
if (_skip && canShow()) {
|
||||||
|
PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrderMap.getPixelColorOrder(_start, _colorOrder));
|
||||||
|
PolyBus::show(_busPtr, _iType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t getColorOrder() {
|
||||||
|
return _colorOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
uint8_t _skip;
|
uint8_t _colorOrder = COL_ORDER_GRB;
|
||||||
uint8_t _colorOrder;
|
uint8_t _pins[2] = {255, 255};
|
||||||
uint8_t _pins[2];
|
uint8_t _iType = I_NONE;
|
||||||
uint8_t _iType;
|
uint8_t _skip = 0;
|
||||||
uint16_t _frequencykHz;
|
void * _busPtr = nullptr;
|
||||||
void * _busPtr;
|
|
||||||
const ColorOrderMap &_colorOrderMap;
|
const ColorOrderMap &_colorOrderMap;
|
||||||
bool _buffering; // temporary until we figure out why comparison "_data != nullptr" causes severe FPS drop
|
|
||||||
|
|
||||||
inline uint32_t restoreColorLossy(uint32_t c, uint8_t restoreBri) {
|
|
||||||
if (restoreBri < 255) {
|
|
||||||
uint8_t* chan = (uint8_t*) &c;
|
|
||||||
for (uint_fast8_t i=0; i<4; i++) {
|
|
||||||
uint_fast16_t val = chan[i];
|
|
||||||
chan[i] = ((val << 8) + restoreBri) / (restoreBri + 1); //adding _bri slighly improves recovery / stops degradation on re-scale
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusPwm : public Bus {
|
class BusPwm : public Bus {
|
||||||
public:
|
public:
|
||||||
BusPwm(BusConfig &bc);
|
BusPwm(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
|
||||||
~BusPwm() { cleanup(); }
|
_valid = false;
|
||||||
|
if (!IS_PWM(bc.type)) return;
|
||||||
|
uint8_t numPins = NUM_PWM_PINS(bc.type);
|
||||||
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c);
|
#ifdef ESP8266
|
||||||
uint32_t getPixelColor(uint16_t pix); //does no index check
|
analogWriteRange(255); //same range as one RGB channel
|
||||||
uint8_t getPins(uint8_t* pinArray);
|
analogWriteFreq(WLED_PWM_FREQ);
|
||||||
uint16_t getFrequency() { return _frequency; }
|
#else
|
||||||
void show();
|
_ledcStart = pinManager.allocateLedc(numPins);
|
||||||
void cleanup() { deallocatePins(); }
|
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 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 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:
|
private:
|
||||||
uint8_t _pins[5];
|
uint8_t _pins[5] = {255, 255, 255, 255, 255};
|
||||||
uint8_t _pwmdata[5];
|
uint8_t _data[5] = {0};
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
uint8_t _ledcStart;
|
uint8_t _ledcStart = 255;
|
||||||
#endif
|
#endif
|
||||||
uint16_t _frequency;
|
|
||||||
|
|
||||||
void deallocatePins();
|
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
|
||||||
|
}
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
pinManager.deallocateLedc(_ledcStart, numPins);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusOnOff : public Bus {
|
class BusOnOff : public Bus {
|
||||||
public:
|
public:
|
||||||
BusOnOff(BusConfig &bc);
|
BusOnOff(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
|
||||||
~BusOnOff() { cleanup(); }
|
_valid = false;
|
||||||
|
if (bc.type != TYPE_ONOFF) return;
|
||||||
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c);
|
uint8_t currentPin = bc.pins[0];
|
||||||
uint32_t getPixelColor(uint16_t pix);
|
if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
|
||||||
uint8_t getPins(uint8_t* pinArray);
|
return;
|
||||||
void show();
|
}
|
||||||
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);
|
||||||
|
|
||||||
|
_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:
|
private:
|
||||||
uint8_t _pin;
|
uint8_t _pin = 255;
|
||||||
uint8_t _onoffdata;
|
uint8_t _data = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusNetwork : public Bus {
|
class BusNetwork : public Bus {
|
||||||
public:
|
public:
|
||||||
BusNetwork(BusConfig &bc);
|
BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
|
||||||
~BusNetwork() { cleanup(); }
|
_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;
|
||||||
|
};
|
||||||
|
|
||||||
bool hasRGB() { return true; }
|
bool hasRGB() { return true; }
|
||||||
bool hasWhite() { return _rgbw; }
|
bool hasWhite() { return _rgbw; }
|
||||||
bool canShow() { return !_broadcastLock; } // this should be a return value from UDP routine if it is still sending data out
|
|
||||||
void setPixelColor(uint16_t pix, uint32_t c);
|
void setPixelColor(uint16_t pix, uint32_t c) {
|
||||||
uint32_t getPixelColor(uint16_t pix);
|
if (!_valid || pix >= _len) return;
|
||||||
uint8_t getPins(uint8_t* pinArray);
|
if (isRgbw()) c = autoWhiteCalc(c);
|
||||||
void show();
|
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
|
||||||
void cleanup();
|
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 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 show() {
|
||||||
|
if (!_valid || !canShow()) return;
|
||||||
|
_broadcastLock = true;
|
||||||
|
realtimeBroadcast(_UDPtype, _client, _len, _data, _bri, _rgbw);
|
||||||
|
_broadcastLock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isRgbw() {
|
||||||
|
return _rgbw;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint16_t getLength() {
|
||||||
|
return _len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanup() {
|
||||||
|
_type = I_NONE;
|
||||||
|
_valid = false;
|
||||||
|
if (_data != nullptr) free(_data);
|
||||||
|
_data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
~BusNetwork() {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IPAddress _client;
|
IPAddress _client;
|
||||||
@ -298,47 +655,139 @@ class BusNetwork : public Bus {
|
|||||||
uint8_t _UDPchannels;
|
uint8_t _UDPchannels;
|
||||||
bool _rgbw;
|
bool _rgbw;
|
||||||
bool _broadcastLock;
|
bool _broadcastLock;
|
||||||
|
byte *_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusManager {
|
class BusManager {
|
||||||
public:
|
public:
|
||||||
BusManager() : numBusses(0) {};
|
BusManager() {};
|
||||||
|
|
||||||
//utility to get the approx. memory usage of a given BusConfig
|
//utility to get the approx. memory usage of a given BusConfig
|
||||||
static uint32_t memUsage(BusConfig &bc);
|
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
|
||||||
|
}
|
||||||
|
if (type > 31 && type < 48) return 5;
|
||||||
|
if (type == 44 || type == 45) return len*4; //RGBW
|
||||||
|
return len*3; //RGB
|
||||||
|
}
|
||||||
|
|
||||||
int add(BusConfig &bc);
|
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);
|
||||||
|
}
|
||||||
|
return numBusses++;
|
||||||
|
}
|
||||||
|
|
||||||
//do not call this method from system context (network callback)
|
//do not call this method from system context (network callback)
|
||||||
void removeAll();
|
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();
|
void show() {
|
||||||
bool canAllShow();
|
for (uint8_t i = 0; i < numBusses; i++) {
|
||||||
void setStatusPixel(uint32_t c);
|
busses[i]->show();
|
||||||
void setPixelColor(uint16_t pix, uint32_t c);
|
}
|
||||||
void setBrightness(uint8_t b);
|
}
|
||||||
void setSegmentCCT(int16_t cct, bool allowWBCorrection = false);
|
|
||||||
uint32_t getPixelColor(uint16_t pix);
|
|
||||||
|
|
||||||
Bus* getBus(uint8_t busNr);
|
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())
|
//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
|
||||||
uint16_t getTotalLength();
|
uint16_t getTotalLength() {
|
||||||
inline uint8_t getNumBusses() const { return numBusses; }
|
uint16_t len = 0;
|
||||||
|
for (uint8_t i=0; i<numBusses; i++) len += busses[i]->getLength();
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
inline void updateColorOrderMap(const ColorOrderMap &com) { memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap)); }
|
void updateColorOrderMap(const ColorOrderMap &com) {
|
||||||
inline const ColorOrderMap& getColorOrderMap() const { return colorOrderMap; }
|
memcpy(&colorOrderMap, &com, sizeof(ColorOrderMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ColorOrderMap& getColorOrderMap() const {
|
||||||
|
return colorOrderMap;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t numBusses;
|
uint8_t numBusses = 0;
|
||||||
Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES];
|
Bus* busses[WLED_MAX_BUSSES];
|
||||||
ColorOrderMap colorOrderMap;
|
ColorOrderMap colorOrderMap;
|
||||||
|
|
||||||
inline uint8_t getNumVirtualBusses() {
|
|
||||||
int j = 0;
|
|
||||||
for (int i=0; i<numBusses; i++) if (busses[i]->getType() >= TYPE_NET_DDP_RGB && busses[i]->getType() < 96) j++;
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef BusWrapper_h
|
#ifndef BusWrapper_h
|
||||||
#define BusWrapper_h
|
#define BusWrapper_h
|
||||||
|
|
||||||
#include "NeoPixelBusLg.h"
|
#include "NeoPixelBrightnessBus.h"
|
||||||
|
|
||||||
// temporary - these defines should actually be set in platformio.ini
|
// temporary - these defines should actually be set in platformio.ini
|
||||||
// C3: I2S0 and I2S1 methods not supported (has one I2S bus)
|
// C3: I2S0 and I2S1 methods not supported (has one I2S bus)
|
||||||
@ -53,16 +53,6 @@
|
|||||||
#define I_8266_U1_TM2_3 18
|
#define I_8266_U1_TM2_3 18
|
||||||
#define I_8266_DM_TM2_3 19
|
#define I_8266_DM_TM2_3 19
|
||||||
#define I_8266_BB_TM2_3 20
|
#define I_8266_BB_TM2_3 20
|
||||||
//UCS8903 (RGB)
|
|
||||||
#define I_8266_U0_UCS_3 49
|
|
||||||
#define I_8266_U1_UCS_3 50
|
|
||||||
#define I_8266_DM_UCS_3 51
|
|
||||||
#define I_8266_BB_UCS_3 52
|
|
||||||
//UCS8904 (RGBW)
|
|
||||||
#define I_8266_U0_UCS_4 53
|
|
||||||
#define I_8266_U1_UCS_4 54
|
|
||||||
#define I_8266_DM_UCS_4 55
|
|
||||||
#define I_8266_BB_UCS_4 56
|
|
||||||
|
|
||||||
/*** ESP32 Neopixel methods ***/
|
/*** ESP32 Neopixel methods ***/
|
||||||
//RGB
|
//RGB
|
||||||
@ -90,16 +80,6 @@
|
|||||||
#define I_32_I0_TM2_3 37
|
#define I_32_I0_TM2_3 37
|
||||||
#define I_32_I1_TM2_3 38
|
#define I_32_I1_TM2_3 38
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
||||||
//UCS8903 (RGB)
|
|
||||||
#define I_32_RN_UCS_3 57
|
|
||||||
#define I_32_I0_UCS_3 58
|
|
||||||
#define I_32_I1_UCS_3 59
|
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
|
||||||
//UCS8904 (RGBW)
|
|
||||||
#define I_32_RN_UCS_4 60
|
|
||||||
#define I_32_I0_UCS_4 61
|
|
||||||
#define I_32_I1_UCS_4 62
|
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
|
||||||
|
|
||||||
//APA102
|
//APA102
|
||||||
#define I_HS_DOT_3 39 //hardware SPI
|
#define I_HS_DOT_3 39 //hardware SPI
|
||||||
@ -122,165 +102,122 @@
|
|||||||
#define I_SS_LPO_3 48
|
#define I_SS_LPO_3 48
|
||||||
|
|
||||||
|
|
||||||
// In the following NeoGammaNullMethod can be replaced with NeoGammaWLEDMethod to perform Gamma correction implicitly
|
|
||||||
// unfortunately that may apply Gamma correction to pre-calculated palettes which is undesired
|
|
||||||
|
|
||||||
/*** ESP8266 Neopixel methods ***/
|
/*** ESP8266 Neopixel methods ***/
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
//RGB
|
//RGB
|
||||||
#define B_8266_U0_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Uart0Ws2813Method, NeoGammaNullMethod> //3 chan, esp8266, gpio1
|
#define B_8266_U0_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart0Ws2813Method> //3 chan, esp8266, gpio1
|
||||||
#define B_8266_U1_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Uart1Ws2813Method, NeoGammaNullMethod> //3 chan, esp8266, gpio2
|
#define B_8266_U1_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart1Ws2813Method> //3 chan, esp8266, gpio2
|
||||||
#define B_8266_DM_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, gpio3
|
#define B_8266_DM_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> //3 chan, esp8266, gpio3
|
||||||
#define B_8266_BB_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, bb (any pin but 16)
|
#define B_8266_BB_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> //3 chan, esp8266, bb (any pin but 16)
|
||||||
//RGBW
|
//RGBW
|
||||||
#define B_8266_U0_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp8266Uart0Ws2813Method, NeoGammaNullMethod> //4 chan, esp8266, gpio1
|
#define B_8266_U0_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266Uart0Ws2813Method> //4 chan, esp8266, gpio1
|
||||||
#define B_8266_U1_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp8266Uart1Ws2813Method, NeoGammaNullMethod> //4 chan, esp8266, gpio2
|
#define B_8266_U1_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266Uart1Ws2813Method> //4 chan, esp8266, gpio2
|
||||||
#define B_8266_DM_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp8266Dma800KbpsMethod, NeoGammaNullMethod> //4 chan, esp8266, gpio3
|
#define B_8266_DM_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266Dma800KbpsMethod> //4 chan, esp8266, gpio3
|
||||||
#define B_8266_BB_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp8266BitBang800KbpsMethod, NeoGammaNullMethod> //4 chan, esp8266, bb (any pin)
|
#define B_8266_BB_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp8266BitBang800KbpsMethod> //4 chan, esp8266, bb (any pin)
|
||||||
//400Kbps
|
//400Kbps
|
||||||
#define B_8266_U0_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Uart0400KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, gpio1
|
#define B_8266_U0_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart0400KbpsMethod> //3 chan, esp8266, gpio1
|
||||||
#define B_8266_U1_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Uart1400KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, gpio2
|
#define B_8266_U1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Uart1400KbpsMethod> //3 chan, esp8266, gpio2
|
||||||
#define B_8266_DM_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266Dma400KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, gpio3
|
#define B_8266_DM_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266Dma400KbpsMethod> //3 chan, esp8266, gpio3
|
||||||
#define B_8266_BB_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp8266BitBang400KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, bb (any pin)
|
#define B_8266_BB_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp8266BitBang400KbpsMethod> //3 chan, esp8266, bb (any pin)
|
||||||
//TM1814 (RGBW)
|
//TM1814 (RGBW)
|
||||||
#define B_8266_U0_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp8266Uart0Tm1814Method, NeoGammaNullMethod>
|
#define B_8266_U0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart0Tm1814Method>
|
||||||
#define B_8266_U1_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp8266Uart1Tm1814Method, NeoGammaNullMethod>
|
#define B_8266_U1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart1Tm1814Method>
|
||||||
#define B_8266_DM_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp8266DmaTm1814Method, NeoGammaNullMethod>
|
#define B_8266_DM_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266DmaTm1814Method>
|
||||||
#define B_8266_BB_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp8266BitBangTm1814Method, NeoGammaNullMethod>
|
#define B_8266_BB_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266BitBangTm1814Method>
|
||||||
//TM1829 (RGB)
|
//TM1829 (RGB)
|
||||||
#define B_8266_U0_TM2_4 NeoPixelBusLg<NeoBrgFeature, NeoEsp8266Uart0Tm1829Method, NeoGammaNullMethod>
|
#define B_8266_U0_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart0Tm1829Method>
|
||||||
#define B_8266_U1_TM2_4 NeoPixelBusLg<NeoBrgFeature, NeoEsp8266Uart1Tm1829Method, NeoGammaNullMethod>
|
#define B_8266_U1_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart1Tm1829Method>
|
||||||
#define B_8266_DM_TM2_4 NeoPixelBusLg<NeoBrgFeature, NeoEsp8266DmaTm1829Method, NeoGammaNullMethod>
|
#define B_8266_DM_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266DmaTm1829Method>
|
||||||
#define B_8266_BB_TM2_4 NeoPixelBusLg<NeoBrgFeature, NeoEsp8266BitBangTm1829Method, NeoGammaNullMethod>
|
#define B_8266_BB_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266BitBangTm1829Method>
|
||||||
//UCS8903
|
|
||||||
#define B_8266_U0_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp8266Uart0Ws2813Method, NeoGammaNullMethod> //3 chan, esp8266, gpio1
|
|
||||||
#define B_8266_U1_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp8266Uart1Ws2813Method, NeoGammaNullMethod> //3 chan, esp8266, gpio2
|
|
||||||
#define B_8266_DM_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp8266Dma800KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, gpio3
|
|
||||||
#define B_8266_BB_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp8266BitBang800KbpsMethod, NeoGammaNullMethod> //3 chan, esp8266, bb (any pin but 16)
|
|
||||||
//UCS8904 RGBW
|
|
||||||
#define B_8266_U0_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp8266Uart0Ws2813Method, NeoGammaNullMethod> //4 chan, esp8266, gpio1
|
|
||||||
#define B_8266_U1_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp8266Uart1Ws2813Method, NeoGammaNullMethod> //4 chan, esp8266, gpio2
|
|
||||||
#define B_8266_DM_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp8266Dma800KbpsMethod, NeoGammaNullMethod> //4 chan, esp8266, gpio3
|
|
||||||
#define B_8266_BB_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp8266BitBang800KbpsMethod, NeoGammaNullMethod> //4 chan, esp8266, bb (any pin)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** ESP32 Neopixel methods ***/
|
/*** ESP32 Neopixel methods ***/
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
//RGB
|
//RGB
|
||||||
#define B_32_RN_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32RmtNWs2812xMethod, NeoGammaNullMethod>
|
#define B_32_RN_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtNWs2812xMethod>
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
#define B_32_I0_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32I2s0800KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I0_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0800KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
#define B_32_I1_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I1_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
//#define B_32_BB_NEO_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32BitBang800KbpsMethod, NeoGammaNullMethod> // NeoEsp8266BitBang800KbpsMethod
|
//#define B_32_BB_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32BitBang800KbpsMethod> // NeoEsp8266BitBang800KbpsMethod
|
||||||
//RGBW
|
//RGBW
|
||||||
#define B_32_RN_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp32RmtNWs2812xMethod, NeoGammaNullMethod>
|
#define B_32_RN_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32RmtNWs2812xMethod>
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
#define B_32_I0_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp32I2s0800KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I0_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s0800KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
#define B_32_I1_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I1_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
//#define B_32_BB_NEO_4 NeoPixelBusLg<NeoGrbwFeature, NeoEsp32BitBang800KbpsMethod, NeoGammaNullMethod> // NeoEsp8266BitBang800KbpsMethod
|
//#define B_32_BB_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32BitBang800KbpsMethod> // NeoEsp8266BitBang800KbpsMethod
|
||||||
//400Kbps
|
//400Kbps
|
||||||
#define B_32_RN_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32RmtN400KbpsMethod, NeoGammaNullMethod>
|
#define B_32_RN_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtN400KbpsMethod>
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
#define B_32_I0_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32I2s0400KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I0_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0400KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
#define B_32_I1_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32I2s1400KbpsMethod, NeoGammaNullMethod>
|
#define B_32_I1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1400KbpsMethod>
|
||||||
#endif
|
#endif
|
||||||
//#define B_32_BB_400_3 NeoPixelBusLg<NeoGrbFeature, NeoEsp32BitBang400KbpsMethod, NeoGammaNullMethod> // NeoEsp8266BitBang400KbpsMethod
|
//#define B_32_BB_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32BitBang400KbpsMethod> // NeoEsp8266BitBang400KbpsMethod
|
||||||
//TM1814 (RGBW)
|
//TM1814 (RGBW)
|
||||||
#define B_32_RN_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp32RmtNTm1814Method, NeoGammaNullMethod>
|
#define B_32_RN_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32RmtNTm1814Method>
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
#define B_32_I0_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp32I2s0Tm1814Method, NeoGammaNullMethod>
|
#define B_32_I0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s0Tm1814Method>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
#define B_32_I1_TM1_4 NeoPixelBusLg<NeoWrgbTm1814Feature, NeoEsp32I2s1Tm1814Method, NeoGammaNullMethod>
|
#define B_32_I1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s1Tm1814Method>
|
||||||
#endif
|
#endif
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
||||||
//TM1829 (RGB)
|
//TM1829 (RGB)
|
||||||
#define B_32_RN_TM2_3 NeoPixelBusLg<NeoBrgFeature, NeoEsp32RmtNTm1829Method, NeoGammaNullMethod>
|
#define B_32_RN_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32RmtNTm1829Method>
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
#define B_32_I0_TM2_3 NeoPixelBusLg<NeoBrgFeature, NeoEsp32I2s0Tm1829Method, NeoGammaNullMethod>
|
#define B_32_I0_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32I2s0Tm1829Method>
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
#define B_32_I1_TM2_3 NeoPixelBusLg<NeoBrgFeature, NeoEsp32I2s1Tm1829Method, NeoGammaNullMethod>
|
#define B_32_I1_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32I2s1Tm1829Method>
|
||||||
#endif
|
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
|
||||||
//UCS8903
|
|
||||||
#define B_32_RN_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp32RmtNWs2812xMethod, NeoGammaNullMethod>
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
#define B_32_I0_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp32I2s0800KbpsMethod, NeoGammaNullMethod>
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
#define B_32_I1_UCS_3 NeoPixelBusLg<NeoRgbUcs8903Feature, NeoEsp32I2s1800KbpsMethod, NeoGammaNullMethod>
|
|
||||||
#endif
|
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
|
||||||
//UCS8904
|
|
||||||
#define B_32_RN_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp32RmtNWs2812xMethod, NeoGammaNullMethod>
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
#define B_32_I0_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp32I2s0800KbpsMethod, NeoGammaNullMethod>
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
#define B_32_I1_UCS_4 NeoPixelBusLg<NeoRgbwUcs8904Feature, NeoEsp32I2s1800KbpsMethod, NeoGammaNullMethod>
|
|
||||||
#endif
|
#endif
|
||||||
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//APA102
|
//APA102
|
||||||
#ifdef WLED_USE_ETHERNET
|
#define B_HS_DOT_3 NeoPixelBrightnessBus<DotStarBgrFeature, DotStarSpi5MhzMethod> //hardware SPI
|
||||||
// fix for #2542 (by @BlackBird77)
|
#define B_SS_DOT_3 NeoPixelBrightnessBus<DotStarBgrFeature, DotStarMethod> //soft SPI
|
||||||
#define B_HS_DOT_3 NeoPixelBusLg<DotStarBgrFeature, DotStarEsp32HspiHzMethod, NeoGammaNullMethod> //hardware HSPI (was DotStarEsp32DmaHspi5MhzMethod in NPB @ 2.6.9)
|
|
||||||
#else
|
|
||||||
#define B_HS_DOT_3 NeoPixelBusLg<DotStarBgrFeature, DotStarSpiHzMethod, NeoGammaNullMethod> //hardware VSPI
|
|
||||||
#endif
|
|
||||||
#define B_SS_DOT_3 NeoPixelBusLg<DotStarBgrFeature, DotStarMethod, NeoGammaNullMethod> //soft SPI
|
|
||||||
|
|
||||||
//LPD8806
|
//LPD8806
|
||||||
#define B_HS_LPD_3 NeoPixelBusLg<Lpd8806GrbFeature, Lpd8806SpiHzMethod, NeoGammaNullMethod>
|
#define B_HS_LPD_3 NeoPixelBrightnessBus<Lpd8806GrbFeature, Lpd8806SpiMethod>
|
||||||
#define B_SS_LPD_3 NeoPixelBusLg<Lpd8806GrbFeature, Lpd8806Method, NeoGammaNullMethod>
|
#define B_SS_LPD_3 NeoPixelBrightnessBus<Lpd8806GrbFeature, Lpd8806Method>
|
||||||
|
|
||||||
//LPD6803
|
//LPD6803
|
||||||
#define B_HS_LPO_3 NeoPixelBusLg<Lpd6803GrbFeature, Lpd6803SpiHzMethod, NeoGammaNullMethod>
|
#define B_HS_LPO_3 NeoPixelBrightnessBus<Lpd6803GrbFeature, Lpd6803SpiMethod>
|
||||||
#define B_SS_LPO_3 NeoPixelBusLg<Lpd6803GrbFeature, Lpd6803Method, NeoGammaNullMethod>
|
#define B_SS_LPO_3 NeoPixelBrightnessBus<Lpd6803GrbFeature, Lpd6803Method>
|
||||||
|
|
||||||
//WS2801
|
//WS2801
|
||||||
#ifdef WLED_USE_ETHERNET
|
#if defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==40000
|
||||||
#define B_HS_WS1_3 NeoPixelBusLg<NeoRbgFeature, Ws2801MethodBase<TwoWireHspiImple<SpiSpeedHz>>, NeoGammaNullMethod>
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi40MhzMethod> // fastest bus speed (not existing method?)
|
||||||
|
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==20000
|
||||||
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi20MhzMethod> // 20MHz
|
||||||
|
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==10000
|
||||||
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801SpiMethod> // 10MHz
|
||||||
|
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==2000
|
||||||
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> //slower, more compatible
|
||||||
|
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==1000
|
||||||
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi1MhzMethod> //slower, more compatible
|
||||||
|
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==500
|
||||||
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi500KhzMethod> //slower, more compatible
|
||||||
#else
|
#else
|
||||||
#define B_HS_WS1_3 NeoPixelBusLg<NeoRbgFeature, Ws2801SpiHzMethod, NeoGammaNullMethod>
|
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> // 2MHz; slower, more compatible
|
||||||
#endif
|
#endif
|
||||||
#define B_SS_WS1_3 NeoPixelBusLg<NeoRbgFeature, Ws2801Method, NeoGammaNullMethod>
|
#define B_SS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Method>
|
||||||
|
|
||||||
//P9813
|
//P9813
|
||||||
#define B_HS_P98_3 NeoPixelBusLg<P9813BgrFeature, P9813SpiHzMethod, NeoGammaNullMethod>
|
#define B_HS_P98_3 NeoPixelBrightnessBus<P9813BgrFeature, P9813SpiMethod>
|
||||||
#define B_SS_P98_3 NeoPixelBusLg<P9813BgrFeature, P9813Method, NeoGammaNullMethod>
|
#define B_SS_P98_3 NeoPixelBrightnessBus<P9813BgrFeature, P9813Method>
|
||||||
|
|
||||||
// 48bit & 64bit to 24bit & 32bit RGB(W) conversion
|
|
||||||
#define toRGBW32(c) (RGBW32((c>>40)&0xFF, (c>>24)&0xFF, (c>>8)&0xFF, (c>>56)&0xFF))
|
|
||||||
#define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b))))
|
|
||||||
|
|
||||||
//handles pointer type conversion for all possible bus types
|
//handles pointer type conversion for all possible bus types
|
||||||
class PolyBus {
|
class PolyBus {
|
||||||
public:
|
public:
|
||||||
// initialize SPI bus speed for DotStar methods
|
|
||||||
template <class T>
|
|
||||||
static void beginDotStar(void* busPtr, int8_t sck, int8_t miso, int8_t mosi, int8_t ss, uint16_t clock_kHz = 0U) {
|
|
||||||
T dotStar_strip = static_cast<T>(busPtr);
|
|
||||||
#ifdef ESP8266
|
|
||||||
dotStar_strip->Begin();
|
|
||||||
#else
|
|
||||||
if (sck == -1 && mosi == -1) dotStar_strip->Begin();
|
|
||||||
else dotStar_strip->Begin(sck, miso, mosi, ss);
|
|
||||||
#endif
|
|
||||||
if (clock_kHz) dotStar_strip->SetMethodSettings(NeoSpiSettings((uint32_t)clock_kHz*1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Begin & initialize the PixelSettings for TM1814 strips.
|
// Begin & initialize the PixelSettings for TM1814 strips.
|
||||||
template <class T>
|
template <class T>
|
||||||
static void beginTM1814(void* busPtr) {
|
static void beginTM1814(void* busPtr) {
|
||||||
@ -289,8 +226,7 @@ class PolyBus {
|
|||||||
// Max current for each LED (22.5 mA).
|
// Max current for each LED (22.5 mA).
|
||||||
tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/225, /*G*/225, /*B*/225, /*W*/225));
|
tm1814_strip->SetPixelSettings(NeoTm1814Settings(/*R*/225, /*G*/225, /*B*/225, /*W*/225));
|
||||||
}
|
}
|
||||||
|
static void begin(void* busPtr, uint8_t busType, uint8_t* pins) {
|
||||||
static void begin(void* busPtr, uint8_t busType, uint8_t* pins, uint16_t clock_kHz = 0U) {
|
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: break;
|
case I_NONE: break;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -314,19 +250,11 @@ class PolyBus {
|
|||||||
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Begin(); break;
|
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Begin(); break;
|
||||||
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Begin(); break;
|
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Begin(); break;
|
||||||
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Begin(); break;
|
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Begin(); break;
|
||||||
case I_HS_DOT_3: beginDotStar<B_HS_DOT_3*>(busPtr, -1, -1, -1, -1, clock_kHz); break;
|
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
|
||||||
case I_HS_LPD_3: beginDotStar<B_HS_LPD_3*>(busPtr, -1, -1, -1, -1, clock_kHz); break;
|
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
|
||||||
case I_HS_LPO_3: beginDotStar<B_HS_LPO_3*>(busPtr, -1, -1, -1, -1, clock_kHz); break;
|
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Begin(); break;
|
||||||
case I_HS_WS1_3: beginDotStar<B_HS_WS1_3*>(busPtr, -1, -1, -1, -1, clock_kHz); break;
|
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(); break;
|
||||||
case I_HS_P98_3: beginDotStar<B_HS_P98_3*>(busPtr, -1, -1, -1, -1, clock_kHz); break;
|
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(); break;
|
||||||
case I_8266_U0_UCS_3: (static_cast<B_8266_U0_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_U1_UCS_3: (static_cast<B_8266_U1_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_DM_UCS_3: (static_cast<B_8266_DM_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_BB_UCS_3: (static_cast<B_8266_BB_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_U0_UCS_4: (static_cast<B_8266_U0_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_U1_UCS_4: (static_cast<B_8266_U1_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_DM_UCS_4: (static_cast<B_8266_DM_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
case I_8266_BB_UCS_4: (static_cast<B_8266_BB_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Begin(); break;
|
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Begin(); break;
|
||||||
@ -363,28 +291,12 @@ class PolyBus {
|
|||||||
case I_32_I1_TM1_4: beginTM1814<B_32_I1_TM1_4*>(busPtr); break;
|
case I_32_I1_TM1_4: beginTM1814<B_32_I1_TM1_4*>(busPtr); break;
|
||||||
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Begin(); break;
|
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Begin(); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: (static_cast<B_32_RN_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: (static_cast<B_32_I0_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_3: (static_cast<B_32_I1_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_3: (static_cast<B_32_BB_UCS_3*>(busPtr))->Begin(); break;
|
|
||||||
case I_32_RN_UCS_4: (static_cast<B_32_RN_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_4: (static_cast<B_32_I0_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_4: (static_cast<B_32_I1_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: (static_cast<B_32_BB_UCS_4*>(busPtr))->Begin(); break;
|
|
||||||
// ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin()
|
// ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin()
|
||||||
case I_HS_DOT_3: beginDotStar<B_HS_DOT_3*>(busPtr, pins[1], -1, pins[0], -1, clock_kHz); break;
|
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
|
||||||
case I_HS_LPD_3: beginDotStar<B_HS_LPD_3*>(busPtr, pins[1], -1, pins[0], -1, clock_kHz); break;
|
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
|
||||||
case I_HS_LPO_3: beginDotStar<B_HS_LPO_3*>(busPtr, pins[1], -1, pins[0], -1, clock_kHz); break;
|
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
|
||||||
case I_HS_WS1_3: beginDotStar<B_HS_WS1_3*>(busPtr, pins[1], -1, pins[0], -1, clock_kHz); break;
|
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
|
||||||
case I_HS_P98_3: beginDotStar<B_HS_P98_3*>(busPtr, pins[1], -1, pins[0], -1, clock_kHz); break;
|
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
|
||||||
#endif
|
#endif
|
||||||
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Begin(); break;
|
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Begin(); break;
|
||||||
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Begin(); break;
|
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Begin(); break;
|
||||||
@ -392,9 +304,8 @@ class PolyBus {
|
|||||||
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Begin(); break;
|
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Begin(); break;
|
||||||
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Begin(); break;
|
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Begin(); break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
static void* create(uint8_t busType, uint8_t* pins, uint16_t len, uint8_t channel) {
|
||||||
static void* create(uint8_t busType, uint8_t* pins, uint16_t len, uint8_t channel, uint16_t clock_kHz = 0U) {
|
|
||||||
void* busPtr = nullptr;
|
void* busPtr = nullptr;
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: break;
|
case I_NONE: break;
|
||||||
@ -419,14 +330,6 @@ class PolyBus {
|
|||||||
case I_8266_U1_TM2_3: busPtr = new B_8266_U1_TM2_4(len, pins[0]); break;
|
case I_8266_U1_TM2_3: busPtr = new B_8266_U1_TM2_4(len, pins[0]); break;
|
||||||
case I_8266_DM_TM2_3: busPtr = new B_8266_DM_TM2_4(len, pins[0]); break;
|
case I_8266_DM_TM2_3: busPtr = new B_8266_DM_TM2_4(len, pins[0]); break;
|
||||||
case I_8266_BB_TM2_3: busPtr = new B_8266_BB_TM2_4(len, pins[0]); break;
|
case I_8266_BB_TM2_3: busPtr = new B_8266_BB_TM2_4(len, pins[0]); break;
|
||||||
case I_8266_U0_UCS_3: busPtr = new B_8266_U0_UCS_3(len, pins[0]); break;
|
|
||||||
case I_8266_U1_UCS_3: busPtr = new B_8266_U1_UCS_3(len, pins[0]); break;
|
|
||||||
case I_8266_DM_UCS_3: busPtr = new B_8266_DM_UCS_3(len, pins[0]); break;
|
|
||||||
case I_8266_BB_UCS_3: busPtr = new B_8266_BB_UCS_3(len, pins[0]); break;
|
|
||||||
case I_8266_U0_UCS_4: busPtr = new B_8266_U0_UCS_4(len, pins[0]); break;
|
|
||||||
case I_8266_U1_UCS_4: busPtr = new B_8266_U1_UCS_4(len, pins[0]); break;
|
|
||||||
case I_8266_DM_UCS_4: busPtr = new B_8266_DM_UCS_4(len, pins[0]); break;
|
|
||||||
case I_8266_BB_UCS_4: busPtr = new B_8266_BB_UCS_4(len, pins[0]); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: busPtr = new B_32_RN_NEO_3(len, pins[0], (NeoBusChannel)channel); break;
|
case I_32_RN_NEO_3: busPtr = new B_32_RN_NEO_3(len, pins[0], (NeoBusChannel)channel); break;
|
||||||
@ -463,22 +366,6 @@ class PolyBus {
|
|||||||
case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); break;
|
case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); break;
|
||||||
case I_32_I1_TM2_3: busPtr = new B_32_I1_TM2_3(len, pins[0]); break;
|
case I_32_I1_TM2_3: busPtr = new B_32_I1_TM2_3(len, pins[0]); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: busPtr = new B_32_RN_UCS_3(len, pins[0], (NeoBusChannel)channel); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: busPtr = new B_32_I0_UCS_3(len, pins[0]); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_3: busPtr = new B_32_I1_UCS_3(len, pins[0]); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_3: busPtr = new B_32_BB_UCS_3(len, pins[0], (NeoBusChannel)channel); break;
|
|
||||||
case I_32_RN_UCS_4: busPtr = new B_32_RN_UCS_4(len, pins[0], (NeoBusChannel)channel); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_4: busPtr = new B_32_I0_UCS_4(len, pins[0]); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_4: busPtr = new B_32_I1_UCS_4(len, pins[0]); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: busPtr = new B_32_BB_UCS_4(len, pins[0], (NeoBusChannel)channel); break;
|
|
||||||
#endif
|
#endif
|
||||||
// for 2-wire: pins[1] is clk, pins[0] is dat. begin expects (len, clk, dat)
|
// for 2-wire: pins[1] is clk, pins[0] is dat. begin expects (len, clk, dat)
|
||||||
case I_HS_DOT_3: busPtr = new B_HS_DOT_3(len, pins[1], pins[0]); break;
|
case I_HS_DOT_3: busPtr = new B_HS_DOT_3(len, pins[1], pins[0]); break;
|
||||||
@ -492,108 +379,82 @@ class PolyBus {
|
|||||||
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[1], pins[0]); break;
|
case I_HS_P98_3: busPtr = new B_HS_P98_3(len, pins[1], pins[0]); break;
|
||||||
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[1], pins[0]); break;
|
case I_SS_P98_3: busPtr = new B_SS_P98_3(len, pins[1], pins[0]); break;
|
||||||
}
|
}
|
||||||
begin(busPtr, busType, pins, clock_kHz);
|
begin(busPtr, busType, pins);
|
||||||
return busPtr;
|
return busPtr;
|
||||||
}
|
};
|
||||||
|
static void show(void* busPtr, uint8_t busType) {
|
||||||
static void show(void* busPtr, uint8_t busType, bool consistent = true) {
|
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: break;
|
case I_NONE: break;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->Show(consistent); break;
|
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->Show(consistent); break;
|
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->Show(consistent); break;
|
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->Show(consistent); break;
|
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->Show(); break;
|
||||||
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Show(consistent); break;
|
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Show(consistent); break;
|
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Show(consistent); break;
|
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Show(); break;
|
||||||
case I_8266_U0_UCS_3: (static_cast<B_8266_U0_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_U1_UCS_3: (static_cast<B_8266_U1_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_DM_UCS_3: (static_cast<B_8266_DM_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_BB_UCS_3: (static_cast<B_8266_BB_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_U0_UCS_4: (static_cast<B_8266_U0_UCS_4*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_U1_UCS_4: (static_cast<B_8266_U1_UCS_4*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_DM_UCS_4: (static_cast<B_8266_DM_UCS_4*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_8266_BB_UCS_4: (static_cast<B_8266_BB_UCS_4*>(busPtr))->Show(consistent); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->Show(consistent); break;
|
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->Show(); break;
|
||||||
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Show(consistent); break;
|
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->Show(consistent); break;
|
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->Show(); break;
|
||||||
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Show(consistent); break;
|
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Show(consistent); break;
|
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Show(consistent); break;
|
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->Show(consistent); break;
|
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->Show(); break;
|
||||||
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->Show(consistent); break;
|
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->Show(consistent); break;
|
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Show(consistent); break;
|
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Show(); break;
|
||||||
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Show(consistent); break;
|
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: (static_cast<B_32_RN_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: (static_cast<B_32_I0_UCS_3*>(busPtr))->Show(consistent); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Show(); break;
|
||||||
case I_32_I1_UCS_3: (static_cast<B_32_I1_UCS_3*>(busPtr))->Show(consistent); break;
|
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Show(); break;
|
||||||
// case I_32_BB_UCS_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->Show(consistent); break;
|
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Show(); break;
|
||||||
case I_32_RN_UCS_4: (static_cast<B_32_RN_UCS_4*>(busPtr))->Show(consistent); break;
|
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->Show(); break;
|
||||||
case I_32_I0_UCS_4: (static_cast<B_32_I0_UCS_4*>(busPtr))->Show(consistent); break;
|
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Show(); break;
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Show(); break;
|
||||||
case I_32_I1_UCS_4: (static_cast<B_32_I1_UCS_4*>(busPtr))->Show(consistent); break;
|
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Show(); break;
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: (static_cast<B_32_BB_UCS_4*>(busPtr))->Show(consistent); break;
|
|
||||||
#endif
|
|
||||||
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->Show(consistent); break;
|
|
||||||
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->Show(consistent); break;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
static bool canShow(void* busPtr, uint8_t busType) {
|
static bool canShow(void* busPtr, uint8_t busType) {
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: return true;
|
case I_NONE: return true;
|
||||||
@ -618,13 +479,6 @@ class PolyBus {
|
|||||||
case I_8266_U1_TM2_3: return (static_cast<B_8266_U1_TM2_4*>(busPtr))->CanShow(); break;
|
case I_8266_U1_TM2_3: return (static_cast<B_8266_U1_TM2_4*>(busPtr))->CanShow(); break;
|
||||||
case I_8266_DM_TM2_3: return (static_cast<B_8266_DM_TM2_4*>(busPtr))->CanShow(); break;
|
case I_8266_DM_TM2_3: return (static_cast<B_8266_DM_TM2_4*>(busPtr))->CanShow(); break;
|
||||||
case I_8266_BB_TM2_3: return (static_cast<B_8266_BB_TM2_4*>(busPtr))->CanShow(); break;
|
case I_8266_BB_TM2_3: return (static_cast<B_8266_BB_TM2_4*>(busPtr))->CanShow(); break;
|
||||||
case I_8266_U0_UCS_3: return (static_cast<B_8266_U0_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_U1_UCS_3: return (static_cast<B_8266_U1_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_DM_UCS_3: return (static_cast<B_8266_DM_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_BB_UCS_3: return (static_cast<B_8266_BB_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_U0_UCS_4: return (static_cast<B_8266_U0_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_U1_UCS_4: return (static_cast<B_8266_U1_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
case I_8266_DM_UCS_4: return (static_cast<B_8266_DM_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: return (static_cast<B_32_RN_NEO_3*>(busPtr))->CanShow(); break;
|
case I_32_RN_NEO_3: return (static_cast<B_32_RN_NEO_3*>(busPtr))->CanShow(); break;
|
||||||
@ -661,22 +515,6 @@ class PolyBus {
|
|||||||
case I_32_I1_TM1_4: return (static_cast<B_32_I1_TM1_4*>(busPtr))->CanShow(); break;
|
case I_32_I1_TM1_4: return (static_cast<B_32_I1_TM1_4*>(busPtr))->CanShow(); break;
|
||||||
case I_32_I1_TM2_3: return (static_cast<B_32_I1_TM2_3*>(busPtr))->CanShow(); break;
|
case I_32_I1_TM2_3: return (static_cast<B_32_I1_TM2_3*>(busPtr))->CanShow(); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: return (static_cast<B_32_RN_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: return (static_cast<B_32_I0_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_3: return (static_cast<B_32_I1_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_3: return (static_cast<B_32_BB_UCS_3*>(busPtr))->CanShow(); break;
|
|
||||||
case I_32_RN_UCS_4: return (static_cast<B_32_RN_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_4: return (static_cast<B_32_I0_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_4: return (static_cast<B_32_I1_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: return (static_cast<B_32_BB_UCS_4*>(busPtr))->CanShow(); break;
|
|
||||||
#endif
|
#endif
|
||||||
case I_HS_DOT_3: return (static_cast<B_HS_DOT_3*>(busPtr))->CanShow(); break;
|
case I_HS_DOT_3: return (static_cast<B_HS_DOT_3*>(busPtr))->CanShow(); break;
|
||||||
case I_SS_DOT_3: return (static_cast<B_SS_DOT_3*>(busPtr))->CanShow(); break;
|
case I_SS_DOT_3: return (static_cast<B_SS_DOT_3*>(busPtr))->CanShow(); break;
|
||||||
@ -690,8 +528,7 @@ class PolyBus {
|
|||||||
case I_SS_P98_3: return (static_cast<B_SS_P98_3*>(busPtr))->CanShow(); break;
|
case I_SS_P98_3: return (static_cast<B_SS_P98_3*>(busPtr))->CanShow(); break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
static void setPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint32_t c, uint8_t co) {
|
static void setPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint32_t c, uint8_t co) {
|
||||||
uint8_t r = c >> 16;
|
uint8_t r = c >> 16;
|
||||||
uint8_t g = c >> 8;
|
uint8_t g = c >> 8;
|
||||||
@ -719,44 +556,36 @@ class PolyBus {
|
|||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: break;
|
case I_NONE: break;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_8266_U0_UCS_3: (static_cast<B_8266_U0_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
case I_8266_U1_UCS_3: (static_cast<B_8266_U1_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
case I_8266_DM_UCS_3: (static_cast<B_8266_DM_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
case I_8266_BB_UCS_3: (static_cast<B_8266_BB_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
case I_8266_U0_UCS_4: (static_cast<B_8266_U0_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
|
||||||
case I_8266_U1_UCS_4: (static_cast<B_8266_U1_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
|
||||||
case I_8266_DM_UCS_4: (static_cast<B_8266_DM_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
|
||||||
case I_8266_BB_UCS_4: (static_cast<B_8266_BB_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
@ -765,152 +594,110 @@ class PolyBus {
|
|||||||
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(colB)); break;
|
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
|
||||||
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: (static_cast<B_32_RN_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: (static_cast<B_32_I0_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_I1_UCS_3: (static_cast<B_32_I1_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
// case I_32_BB_UCS_3: (static_cast<B_32_BB_UCS_3*>(busPtr))->SetPixelColor(pix, Rgb48Color(RgbColor(col))); break;
|
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_RN_UCS_4: (static_cast<B_32_RN_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_I0_UCS_4: (static_cast<B_32_I0_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
case I_32_I1_UCS_4: (static_cast<B_32_I1_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: (static_cast<B_32_BB_UCS_4*>(busPtr))->SetPixelColor(pix, Rgbw64Color(col)); break;
|
|
||||||
#endif
|
|
||||||
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetPixelColor(pix, RgbColor(col)); break;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
static void setBrightness(void* busPtr, uint8_t busType, uint8_t b) {
|
static void setBrightness(void* busPtr, uint8_t busType, uint8_t b) {
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case I_NONE: break;
|
case I_NONE: break;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U0_NEO_3: (static_cast<B_8266_U0_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U1_NEO_3: (static_cast<B_8266_U1_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_DM_NEO_3: (static_cast<B_8266_DM_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_BB_NEO_3: (static_cast<B_8266_BB_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U0_NEO_4: (static_cast<B_8266_U0_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U1_NEO_4: (static_cast<B_8266_U1_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_DM_NEO_4: (static_cast<B_8266_DM_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_BB_NEO_4: (static_cast<B_8266_BB_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U0_400_3: (static_cast<B_8266_U0_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U1_400_3: (static_cast<B_8266_U1_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_DM_400_3: (static_cast<B_8266_DM_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_8266_BB_400_3: (static_cast<B_8266_BB_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U0_TM1_4: (static_cast<B_8266_U0_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetLuminance(b); break;
|
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_8266_U0_UCS_3: (static_cast<B_8266_U0_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_U1_UCS_3: (static_cast<B_8266_U1_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_DM_UCS_3: (static_cast<B_8266_DM_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_BB_UCS_3: (static_cast<B_8266_BB_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_U0_UCS_4: (static_cast<B_8266_U0_UCS_4*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_U1_UCS_4: (static_cast<B_8266_U1_UCS_4*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_DM_UCS_4: (static_cast<B_8266_DM_UCS_4*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_8266_BB_UCS_4: (static_cast<B_8266_BB_UCS_4*>(busPtr))->SetLuminance(b); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetLuminance(b); break;
|
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetLuminance(b); break;
|
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetLuminance(b); break;
|
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
#ifndef WLED_NO_I2S0_PIXELBUS
|
||||||
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
#ifndef WLED_NO_I2S1_PIXELBUS
|
||||||
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetLuminance(b); break;
|
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetLuminance(b); break;
|
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: (static_cast<B_32_RN_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: (static_cast<B_32_I0_UCS_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_I1_UCS_3: (static_cast<B_32_I1_UCS_3*>(busPtr))->SetLuminance(b); break;
|
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetBrightness(b); break;
|
||||||
// case I_32_BB_UCS_3: (static_cast<B_32_BB_UCS_3*>(busPtr))->SetLuminance(b); break;
|
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_RN_UCS_4: (static_cast<B_32_RN_UCS_4*>(busPtr))->SetLuminance(b); break;
|
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_I0_UCS_4: (static_cast<B_32_I0_UCS_4*>(busPtr))->SetLuminance(b); break;
|
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetBrightness(b); break;
|
||||||
case I_32_I1_UCS_4: (static_cast<B_32_I1_UCS_4*>(busPtr))->SetLuminance(b); break;
|
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetBrightness(b); break;
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: (static_cast<B_32_BB_UCS_4*>(busPtr))->SetLuminance(b); break;
|
|
||||||
#endif
|
|
||||||
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_SS_DOT_3: (static_cast<B_SS_DOT_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_SS_LPD_3: (static_cast<B_SS_LPD_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_SS_LPO_3: (static_cast<B_SS_LPO_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_HS_WS1_3: (static_cast<B_HS_WS1_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_SS_WS1_3: (static_cast<B_SS_WS1_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_HS_P98_3: (static_cast<B_HS_P98_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
case I_SS_P98_3: (static_cast<B_SS_P98_3*>(busPtr))->SetLuminance(b); break;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
static uint32_t getPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint8_t co) {
|
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) {
|
switch (busType) {
|
||||||
@ -936,14 +723,6 @@ class PolyBus {
|
|||||||
case I_8266_U1_TM2_3: col = (static_cast<B_8266_U1_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
case I_8266_U1_TM2_3: col = (static_cast<B_8266_U1_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
||||||
case I_8266_DM_TM2_3: col = (static_cast<B_8266_DM_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
case I_8266_DM_TM2_3: col = (static_cast<B_8266_DM_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
||||||
case I_8266_BB_TM2_3: col = (static_cast<B_8266_BB_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
case I_8266_BB_TM2_3: col = (static_cast<B_8266_BB_TM2_4*>(busPtr))->GetPixelColor(pix); break;
|
||||||
case I_8266_U0_UCS_3: { Rgb48Color c = (static_cast<B_8266_U0_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
case I_8266_U1_UCS_3: { Rgb48Color c = (static_cast<B_8266_U1_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
case I_8266_DM_UCS_3: { Rgb48Color c = (static_cast<B_8266_DM_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
case I_8266_BB_UCS_3: { Rgb48Color c = (static_cast<B_8266_BB_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
case I_8266_U0_UCS_4: { Rgbw64Color c = (static_cast<B_8266_U0_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
case I_8266_U1_UCS_4: { Rgbw64Color c = (static_cast<B_8266_U1_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
case I_8266_DM_UCS_4: { Rgbw64Color c = (static_cast<B_8266_DM_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
case I_8266_BB_UCS_4: { Rgbw64Color c = (static_cast<B_8266_BB_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: col = (static_cast<B_32_RN_NEO_3*>(busPtr))->GetPixelColor(pix); break;
|
case I_32_RN_NEO_3: col = (static_cast<B_32_RN_NEO_3*>(busPtr))->GetPixelColor(pix); break;
|
||||||
@ -980,22 +759,6 @@ class PolyBus {
|
|||||||
case I_32_I1_TM1_4: col = (static_cast<B_32_I1_TM1_4*>(busPtr))->GetPixelColor(pix); break;
|
case I_32_I1_TM1_4: col = (static_cast<B_32_I1_TM1_4*>(busPtr))->GetPixelColor(pix); break;
|
||||||
case I_32_I1_TM2_3: col = (static_cast<B_32_I1_TM2_3*>(busPtr))->GetPixelColor(pix); break;
|
case I_32_I1_TM2_3: col = (static_cast<B_32_I1_TM2_3*>(busPtr))->GetPixelColor(pix); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: { Rgb48Color c = (static_cast<B_32_RN_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: { Rgb48Color c = (static_cast<B_32_I0_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_3: { Rgb48Color c = (static_cast<B_32_I1_UCS_3*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,0); } break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_3: col = (static_cast<B_32_BB_UCS_3*>(busPtr))->GetPixelColor(pix); break;
|
|
||||||
case I_32_RN_UCS_4: { Rgbw64Color c = (static_cast<B_32_RN_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_4: { Rgbw64Color c = (static_cast<B_32_I0_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_4: { Rgbw64Color c = (static_cast<B_32_I1_UCS_4*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.W>>8); } break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: col = (static_cast<B_32_BB_UCS_4*>(busPtr))->GetPixelColor(pix); break;
|
|
||||||
#endif
|
#endif
|
||||||
case I_HS_DOT_3: col = (static_cast<B_HS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
|
case I_HS_DOT_3: col = (static_cast<B_HS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
|
||||||
case I_SS_DOT_3: col = (static_cast<B_SS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
|
case I_SS_DOT_3: col = (static_cast<B_SS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
|
||||||
@ -1053,14 +816,6 @@ class PolyBus {
|
|||||||
case I_8266_U1_TM2_3: delete (static_cast<B_8266_U1_TM2_4*>(busPtr)); break;
|
case I_8266_U1_TM2_3: delete (static_cast<B_8266_U1_TM2_4*>(busPtr)); break;
|
||||||
case I_8266_DM_TM2_3: delete (static_cast<B_8266_DM_TM2_4*>(busPtr)); break;
|
case I_8266_DM_TM2_3: delete (static_cast<B_8266_DM_TM2_4*>(busPtr)); break;
|
||||||
case I_8266_BB_TM2_3: delete (static_cast<B_8266_BB_TM2_4*>(busPtr)); break;
|
case I_8266_BB_TM2_3: delete (static_cast<B_8266_BB_TM2_4*>(busPtr)); break;
|
||||||
case I_8266_U0_UCS_3: delete (static_cast<B_8266_U0_UCS_3*>(busPtr)); break;
|
|
||||||
case I_8266_U1_UCS_3: delete (static_cast<B_8266_U1_UCS_3*>(busPtr)); break;
|
|
||||||
case I_8266_DM_UCS_3: delete (static_cast<B_8266_DM_UCS_3*>(busPtr)); break;
|
|
||||||
case I_8266_BB_UCS_3: delete (static_cast<B_8266_BB_UCS_3*>(busPtr)); break;
|
|
||||||
case I_8266_U0_UCS_4: delete (static_cast<B_8266_U0_UCS_4*>(busPtr)); break;
|
|
||||||
case I_8266_U1_UCS_4: delete (static_cast<B_8266_U1_UCS_4*>(busPtr)); break;
|
|
||||||
case I_8266_DM_UCS_4: delete (static_cast<B_8266_DM_UCS_4*>(busPtr)); break;
|
|
||||||
case I_8266_BB_UCS_4: delete (static_cast<B_8266_BB_UCS_4*>(busPtr)); break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
case I_32_RN_NEO_3: delete (static_cast<B_32_RN_NEO_3*>(busPtr)); break;
|
case I_32_RN_NEO_3: delete (static_cast<B_32_RN_NEO_3*>(busPtr)); break;
|
||||||
@ -1097,22 +852,6 @@ class PolyBus {
|
|||||||
case I_32_I1_TM1_4: delete (static_cast<B_32_I1_TM1_4*>(busPtr)); break;
|
case I_32_I1_TM1_4: delete (static_cast<B_32_I1_TM1_4*>(busPtr)); break;
|
||||||
case I_32_I1_TM2_3: delete (static_cast<B_32_I1_TM2_3*>(busPtr)); break;
|
case I_32_I1_TM2_3: delete (static_cast<B_32_I1_TM2_3*>(busPtr)); break;
|
||||||
#endif
|
#endif
|
||||||
case I_32_RN_UCS_3: delete (static_cast<B_32_RN_UCS_3*>(busPtr)); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_3: delete (static_cast<B_32_I0_UCS_3*>(busPtr)); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_3: delete (static_cast<B_32_I1_UCS_3*>(busPtr)); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_3: delete (static_cast<B_32_BB_UCS_3*>(busPtr)); break;
|
|
||||||
case I_32_RN_UCS_4: delete (static_cast<B_32_RN_UCS_4*>(busPtr)); break;
|
|
||||||
#ifndef WLED_NO_I2S0_PIXELBUS
|
|
||||||
case I_32_I0_UCS_4: delete (static_cast<B_32_I0_UCS_4*>(busPtr)); break;
|
|
||||||
#endif
|
|
||||||
#ifndef WLED_NO_I2S1_PIXELBUS
|
|
||||||
case I_32_I1_UCS_4: delete (static_cast<B_32_I1_UCS_4*>(busPtr)); break;
|
|
||||||
#endif
|
|
||||||
// case I_32_BB_UCS_4: delete (static_cast<B_32_BB_UCS_4*>(busPtr)); break;
|
|
||||||
#endif
|
#endif
|
||||||
case I_HS_DOT_3: delete (static_cast<B_HS_DOT_3*>(busPtr)); break;
|
case I_HS_DOT_3: delete (static_cast<B_HS_DOT_3*>(busPtr)); break;
|
||||||
case I_SS_DOT_3: delete (static_cast<B_SS_DOT_3*>(busPtr)); break;
|
case I_SS_DOT_3: delete (static_cast<B_SS_DOT_3*>(busPtr)); break;
|
||||||
@ -1155,8 +894,6 @@ class PolyBus {
|
|||||||
uint8_t offset = pins[0] -1; //for driver: 0 = uart0, 1 = uart1, 2 = dma, 3 = bitbang
|
uint8_t offset = pins[0] -1; //for driver: 0 = uart0, 1 = uart1, 2 = dma, 3 = bitbang
|
||||||
if (offset > 3) offset = 3;
|
if (offset > 3) offset = 3;
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case TYPE_WS2812_1CH_X3:
|
|
||||||
case TYPE_WS2812_2CH_X3:
|
|
||||||
case TYPE_WS2812_RGB:
|
case TYPE_WS2812_RGB:
|
||||||
case TYPE_WS2812_WWA:
|
case TYPE_WS2812_WWA:
|
||||||
return I_8266_U0_NEO_3 + offset;
|
return I_8266_U0_NEO_3 + offset;
|
||||||
@ -1168,10 +905,6 @@ class PolyBus {
|
|||||||
return I_8266_U0_TM1_4 + offset;
|
return I_8266_U0_TM1_4 + offset;
|
||||||
case TYPE_TM1829:
|
case TYPE_TM1829:
|
||||||
return I_8266_U0_TM2_3 + offset;
|
return I_8266_U0_TM2_3 + offset;
|
||||||
case TYPE_UCS8903:
|
|
||||||
return I_8266_U0_UCS_3 + offset;
|
|
||||||
case TYPE_UCS8904:
|
|
||||||
return I_8266_U0_UCS_4 + offset;
|
|
||||||
}
|
}
|
||||||
#else //ESP32
|
#else //ESP32
|
||||||
uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1
|
uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1
|
||||||
@ -1193,8 +926,6 @@ class PolyBus {
|
|||||||
if (num > 7) offset = num -7;
|
if (num > 7) offset = num -7;
|
||||||
#endif
|
#endif
|
||||||
switch (busType) {
|
switch (busType) {
|
||||||
case TYPE_WS2812_1CH_X3:
|
|
||||||
case TYPE_WS2812_2CH_X3:
|
|
||||||
case TYPE_WS2812_RGB:
|
case TYPE_WS2812_RGB:
|
||||||
case TYPE_WS2812_WWA:
|
case TYPE_WS2812_WWA:
|
||||||
return I_32_RN_NEO_3 + offset;
|
return I_32_RN_NEO_3 + offset;
|
||||||
@ -1206,10 +937,6 @@ class PolyBus {
|
|||||||
return I_32_RN_TM1_4 + offset;
|
return I_32_RN_TM1_4 + offset;
|
||||||
case TYPE_TM1829:
|
case TYPE_TM1829:
|
||||||
return I_32_RN_TM2_3 + offset;
|
return I_32_RN_TM2_3 + offset;
|
||||||
case TYPE_UCS8903:
|
|
||||||
return I_32_RN_UCS_3 + offset;
|
|
||||||
case TYPE_UCS8904:
|
|
||||||
return I_32_RN_UCS_4 + offset;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,15 @@ void shortPressAction(uint8_t b)
|
|||||||
case 1: ++effectCurrent %= strip.getModeCount(); stateChanged = true; colorUpdated(CALL_MODE_BUTTON); break;
|
case 1: ++effectCurrent %= strip.getModeCount(); stateChanged = true; colorUpdated(CALL_MODE_BUTTON); break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unloadPlaylist(); // applying a preset unloads the playlist
|
|
||||||
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
|
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
// publish MQTT message
|
// publish MQTT message
|
||||||
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
||||||
mqtt->publish(subuf, 0, false, "short");
|
mqtt->publish(subuf, 0, false, "short");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void longPressAction(uint8_t b)
|
void longPressAction(uint8_t b)
|
||||||
@ -43,18 +40,15 @@ void longPressAction(uint8_t b)
|
|||||||
case 1: bri += 8; stateUpdated(CALL_MODE_BUTTON); buttonPressedTime[b] = millis(); break; // repeatable action
|
case 1: bri += 8; stateUpdated(CALL_MODE_BUTTON); buttonPressedTime[b] = millis(); break; // repeatable action
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unloadPlaylist(); // applying a preset unloads the playlist
|
|
||||||
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
|
applyPreset(macroLongPress[b], CALL_MODE_BUTTON_PRESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
// publish MQTT message
|
// publish MQTT message
|
||||||
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
||||||
mqtt->publish(subuf, 0, false, "long");
|
mqtt->publish(subuf, 0, false, "long");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doublePressAction(uint8_t b)
|
void doublePressAction(uint8_t b)
|
||||||
@ -65,18 +59,15 @@ void doublePressAction(uint8_t b)
|
|||||||
case 1: ++effectPalette %= strip.getPaletteCount(); colorUpdated(CALL_MODE_BUTTON); break;
|
case 1: ++effectPalette %= strip.getPaletteCount(); colorUpdated(CALL_MODE_BUTTON); break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unloadPlaylist(); // applying a preset unloads the playlist
|
|
||||||
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
|
applyPreset(macroDoublePress[b], CALL_MODE_BUTTON_PRESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
// publish MQTT message
|
// publish MQTT message
|
||||||
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
||||||
mqtt->publish(subuf, 0, false, "double");
|
mqtt->publish(subuf, 0, false, "double");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isButtonPressed(uint8_t i)
|
bool isButtonPressed(uint8_t i)
|
||||||
@ -128,7 +119,6 @@ void handleSwitch(uint8_t b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
// publish MQTT message
|
// publish MQTT message
|
||||||
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
if (buttonPublishMqtt && WLED_MQTT_CONNECTED) {
|
||||||
char subuf[64];
|
char subuf[64];
|
||||||
@ -136,7 +126,6 @@ void handleSwitch(uint8_t b)
|
|||||||
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
else sprintf_P(subuf, _mqtt_topic_button, mqttDeviceTopic, (int)b);
|
||||||
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
|
mqtt->publish(subuf, 0, false, !buttonPressedBefore[b] ? "off" : "on");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
|
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
|
||||||
}
|
}
|
||||||
@ -156,7 +145,6 @@ void handleAnalog(uint8_t b)
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
rawReading = analogRead(A0) << 2; // convert 10bit read to 12bit
|
rawReading = analogRead(A0) << 2; // convert 10bit read to 12bit
|
||||||
#else
|
#else
|
||||||
if ((btnPin[b] < 0) || (digitalPinToAnalogChannel(btnPin[b]) < 0)) return; // pin must support analog ADC - newer esp32 frameworks throw lots of warnings otherwise
|
|
||||||
rawReading = analogRead(btnPin[b]); // collect at full 12bit resolution
|
rawReading = analogRead(btnPin[b]); // collect at full 12bit resolution
|
||||||
#endif
|
#endif
|
||||||
yield(); // keep WiFi task running - analog read may take several millis on ESP8266
|
yield(); // keep WiFi task running - analog read may take several millis on ESP8266
|
||||||
@ -229,10 +217,12 @@ void handleButton()
|
|||||||
{
|
{
|
||||||
static unsigned long lastRead = 0UL;
|
static unsigned long lastRead = 0UL;
|
||||||
static unsigned long lastRun = 0UL;
|
static unsigned long lastRun = 0UL;
|
||||||
|
bool analog = false;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
if (strip.isUpdating() && (now - lastRun < 400)) return; // don't interfere with strip update (unless strip is updating continuously, e.g. very long strips)
|
//if (strip.isUpdating()) return; // don't interfere with strip updates. Our button will still be there in 1ms (next cycle)
|
||||||
lastRun = now;
|
if (strip.isUpdating() && (millis() - lastRun < 400)) return; // be niced, but avoid button starvation
|
||||||
|
lastRun = millis();
|
||||||
|
|
||||||
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
|
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -243,32 +233,19 @@ void handleButton()
|
|||||||
|
|
||||||
if (usermods.handleButton(b)) continue; // did usermod handle buttons
|
if (usermods.handleButton(b)) continue; // did usermod handle buttons
|
||||||
|
|
||||||
if (buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) { // button is not a button but a potentiometer
|
if ((buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && now - lastRead > ANALOG_BTN_READ_CYCLE) { // button is not a button but a potentiometer
|
||||||
if (now - lastRead > ANALOG_BTN_READ_CYCLE) {
|
analog = true;
|
||||||
handleAnalog(b);
|
handleAnalog(b); continue;
|
||||||
lastRead = now;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0)
|
//button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0)
|
||||||
if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_PIR_SENSOR) {
|
if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_PIR_SENSOR) {
|
||||||
handleSwitch(b);
|
handleSwitch(b); continue;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//momentary button logic
|
//momentary button logic
|
||||||
if (isButtonPressed(b)) { //pressed
|
if (isButtonPressed(b)) { //pressed
|
||||||
|
|
||||||
// if all macros are the same, fire action immediately on rising edge
|
|
||||||
if (macroButton[b] && macroButton[b] == macroLongPress[b] && macroButton[b] == macroDoublePress[b]) {
|
|
||||||
if (!buttonPressedBefore[b])
|
|
||||||
shortPressAction(b);
|
|
||||||
buttonPressedBefore[b] = true;
|
|
||||||
buttonPressedTime[b] = now; // continually update (for debouncing to work in release handler)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!buttonPressedBefore[b]) buttonPressedTime[b] = now;
|
if (!buttonPressedBefore[b]) buttonPressedTime[b] = now;
|
||||||
buttonPressedBefore[b] = true;
|
buttonPressedBefore[b] = true;
|
||||||
|
|
||||||
@ -282,14 +259,8 @@ void handleButton()
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (!isButtonPressed(b) && buttonPressedBefore[b]) { //released
|
} else if (!isButtonPressed(b) && buttonPressedBefore[b]) { //released
|
||||||
|
|
||||||
long dur = now - buttonPressedTime[b];
|
long dur = now - buttonPressedTime[b];
|
||||||
|
|
||||||
// released after rising-edge short press action
|
|
||||||
if (macroButton[b] && macroButton[b] == macroLongPress[b] && macroButton[b] == macroDoublePress[b]) {
|
|
||||||
if (dur > WLED_DEBOUNCE_THRESHOLD) buttonPressedBefore[b] = false; // debounce, blocks button for 50 ms once it has been released
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore[b] = false; continue;} //too short "press", debounce
|
if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore[b] = false; continue;} //too short "press", debounce
|
||||||
bool doublePress = buttonWaitTime[b]; //did we have a short press before?
|
bool doublePress = buttonWaitTime[b]; //did we have a short press before?
|
||||||
buttonWaitTime[b] = 0;
|
buttonWaitTime[b] = 0;
|
||||||
@ -326,6 +297,7 @@ void handleButton()
|
|||||||
shortPressAction(b);
|
shortPressAction(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (analog) lastRead = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If enabled, RMT idle level is set to HIGH when off
|
// If enabled, RMT idle level is set to HIGH when off
|
||||||
|
191
wled00/cfg.cpp
@ -84,48 +84,48 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
uint8_t autoWhiteMode = RGBW_MODE_MANUAL_ONLY;
|
uint8_t autoWhiteMode = RGBW_MODE_MANUAL_ONLY;
|
||||||
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
|
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
|
||||||
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
|
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
|
||||||
Bus::setGlobalAWMode(hw_led[F("rgbwm")] | 255);
|
Bus::setAutoWhiteMode(hw_led[F("rgbwm")] | 255);
|
||||||
CJSON(correctWB, hw_led["cct"]);
|
CJSON(correctWB, hw_led["cct"]);
|
||||||
CJSON(cctFromRgb, hw_led[F("cr")]);
|
CJSON(cctFromRgb, hw_led[F("cr")]);
|
||||||
CJSON(strip.cctBlending, hw_led[F("cb")]);
|
CJSON(strip.cctBlending, hw_led[F("cb")]);
|
||||||
Bus::setCCTBlend(strip.cctBlending);
|
Bus::setCCTBlend(strip.cctBlending);
|
||||||
strip.setTargetFps(hw_led["fps"]); //NOP if 0, default 42 FPS
|
strip.setTargetFps(hw_led["fps"]); //NOP if 0, default 42 FPS
|
||||||
CJSON(useGlobalLedBuffer, hw_led[F("ld")]);
|
CJSON(strip.useLedsArray, hw_led[F("ld")]);
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
// 2D Matrix Settings
|
// 2D Matrix Settings
|
||||||
JsonObject matrix = hw_led[F("matrix")];
|
JsonObject matrix = hw_led[F("matrix")];
|
||||||
if (!matrix.isNull()) {
|
if (!matrix.isNull()) {
|
||||||
strip.isMatrix = true;
|
strip.isMatrix = true;
|
||||||
CJSON(strip.panels, matrix[F("mpc")]);
|
CJSON(strip.panelH, matrix[F("ph")]);
|
||||||
strip.panel.clear();
|
CJSON(strip.panelW, matrix[F("pw")]);
|
||||||
|
CJSON(strip.hPanels, matrix[F("mph")]);
|
||||||
|
CJSON(strip.vPanels, matrix[F("mpv")]);
|
||||||
|
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["ps"]);
|
||||||
|
|
||||||
JsonArray panels = matrix[F("panels")];
|
JsonArray panels = matrix[F("panels")];
|
||||||
uint8_t s = 0;
|
uint8_t s = 0;
|
||||||
if (!panels.isNull()) {
|
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) {
|
for (JsonObject pnl : panels) {
|
||||||
WS2812FX::Panel p;
|
CJSON(strip.panel[s].bottomStart, pnl["b"]);
|
||||||
CJSON(p.bottomStart, pnl["b"]);
|
CJSON(strip.panel[s].rightStart, pnl["r"]);
|
||||||
CJSON(p.rightStart, pnl["r"]);
|
CJSON(strip.panel[s].vertical, pnl["v"]);
|
||||||
CJSON(p.vertical, pnl["v"]);
|
CJSON(strip.panel[s].serpentine, pnl["s"]);
|
||||||
CJSON(p.serpentine, pnl["s"]);
|
if (++s >= WLED_MAX_PANELS) break; // max panels reached
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
// cannot call strip.setUpMatrix() here due to already locked JSON buffer
|
// clear remaining panels
|
||||||
|
for (; s<WLED_MAX_PANELS; s++) {
|
||||||
|
strip.panel[s].bottomStart = 0;
|
||||||
|
strip.panel[s].rightStart = 0;
|
||||||
|
strip.panel[s].vertical = 0;
|
||||||
|
strip.panel[s].serpentine = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.setUpMatrix();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -134,11 +134,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
if (fromFS || !ins.isNull()) {
|
if (fromFS || !ins.isNull()) {
|
||||||
uint8_t s = 0; // bus iterator
|
uint8_t s = 0; // bus iterator
|
||||||
if (fromFS) busses.removeAll(); // can't safely manipulate busses directly in network callback
|
if (fromFS) busses.removeAll(); // can't safely manipulate busses directly in network callback
|
||||||
uint32_t mem = 0, globalBufMem = 0;
|
uint32_t mem = 0;
|
||||||
uint16_t maxlen = 0;
|
|
||||||
bool busesChanged = false;
|
bool busesChanged = false;
|
||||||
for (JsonObject elm : ins) {
|
for (JsonObject elm : ins) {
|
||||||
if (s >= WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES) break;
|
if (s >= WLED_MAX_BUSSES) break;
|
||||||
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
||||||
JsonArray pinArr = elm["pin"];
|
JsonArray pinArr = elm["pin"];
|
||||||
if (pinArr.size() == 0) continue;
|
if (pinArr.size() == 0) continue;
|
||||||
@ -157,20 +156,15 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
|
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
|
||||||
bool reversed = elm["rev"];
|
bool reversed = elm["rev"];
|
||||||
bool refresh = elm["ref"] | false;
|
bool refresh = elm["ref"] | false;
|
||||||
uint16_t freqkHz = elm[F("freq")] | 0; // will be in kHz for DotStar and Hz for PWM (not yet implemented fully)
|
|
||||||
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
|
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
|
||||||
uint8_t AWmode = elm[F("rgbwm")] | autoWhiteMode;
|
uint8_t AWmode = elm[F("rgbwm")] | autoWhiteMode;
|
||||||
if (fromFS) {
|
if (fromFS) {
|
||||||
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, useGlobalLedBuffer);
|
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
|
||||||
mem += BusManager::memUsage(bc);
|
mem += BusManager::memUsage(bc);
|
||||||
if (useGlobalLedBuffer && start + length > maxlen) {
|
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
|
||||||
maxlen = start + length;
|
|
||||||
globalBufMem = maxlen * 4;
|
|
||||||
}
|
|
||||||
if (mem + globalBufMem <= MAX_LED_MEMORY) if (busses.add(bc) == -1) break; // finalization will be done in WLED::beginStrip()
|
|
||||||
} else {
|
} else {
|
||||||
if (busConfigs[s] != nullptr) delete busConfigs[s];
|
if (busConfigs[s] != nullptr) delete busConfigs[s];
|
||||||
busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, useGlobalLedBuffer);
|
busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
|
||||||
busesChanged = true;
|
busesChanged = true;
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
@ -178,7 +172,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
doInitBusses = busesChanged;
|
doInitBusses = busesChanged;
|
||||||
// finalization done in beginStrip()
|
// finalization done in beginStrip()
|
||||||
}
|
}
|
||||||
if (hw_led["rev"]) busses.getBus(0)->setReversed(true); //set 0.11 global reversed setting for first bus
|
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
|
||||||
|
|
||||||
// read color order map configuration
|
// read color order map configuration
|
||||||
JsonArray hw_com = hw[F("com")];
|
JsonArray hw_com = hw[F("com")];
|
||||||
@ -198,13 +192,11 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
|
|
||||||
// read multiple button configuration
|
// read multiple button configuration
|
||||||
JsonObject btn_obj = hw["btn"];
|
JsonObject btn_obj = hw["btn"];
|
||||||
bool pull = btn_obj[F("pull")] | (!disablePullUp); // if true, pullup is enabled
|
int pull = -1; // trick for inverted setting
|
||||||
disablePullUp = !pull;
|
CJSON(pull, btn_obj[F("pull")]);
|
||||||
|
if (pull>=0) disablePullUp = pull;
|
||||||
JsonArray hw_btn_ins = btn_obj[F("ins")];
|
JsonArray hw_btn_ins = btn_obj[F("ins")];
|
||||||
if (!hw_btn_ins.isNull()) {
|
if (!hw_btn_ins.isNull()) {
|
||||||
for (uint8_t b = 0; b < WLED_MAX_BUTTONS; b++) { // deallocate existing button pins
|
|
||||||
pinManager.deallocatePin(btnPin[b], PinOwner::Button); // does nothing if trying to deallocate a pin with PinOwner != Button
|
|
||||||
}
|
|
||||||
uint8_t s = 0;
|
uint8_t s = 0;
|
||||||
for (JsonObject btn : hw_btn_ins) {
|
for (JsonObject btn : hw_btn_ins) {
|
||||||
CJSON(buttonType[s], btn["type"]);
|
CJSON(buttonType[s], btn["type"]);
|
||||||
@ -272,7 +264,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
|
|
||||||
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
|
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
|
||||||
if (hw_ir_pin > -2) {
|
if (hw_ir_pin > -2) {
|
||||||
pinManager.deallocatePin(irPin, PinOwner::IR);
|
|
||||||
if (pinManager.allocatePin(hw_ir_pin, false, PinOwner::IR)) {
|
if (pinManager.allocatePin(hw_ir_pin, false, PinOwner::IR)) {
|
||||||
irPin = hw_ir_pin;
|
irPin = hw_ir_pin;
|
||||||
} else {
|
} else {
|
||||||
@ -285,7 +276,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
JsonObject relay = hw[F("relay")];
|
JsonObject relay = hw[F("relay")];
|
||||||
int hw_relay_pin = relay["pin"] | -2;
|
int hw_relay_pin = relay["pin"] | -2;
|
||||||
if (hw_relay_pin > -2) {
|
if (hw_relay_pin > -2) {
|
||||||
pinManager.deallocatePin(rlyPin, PinOwner::Relay);
|
|
||||||
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
|
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
|
||||||
rlyPin = hw_relay_pin;
|
rlyPin = hw_relay_pin;
|
||||||
pinMode(rlyPin, OUTPUT);
|
pinMode(rlyPin, OUTPUT);
|
||||||
@ -307,11 +297,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
PinManagerPinType i2c[2] = { { i2c_sda, true }, { i2c_scl, true } };
|
PinManagerPinType i2c[2] = { { i2c_sda, true }, { i2c_scl, true } };
|
||||||
if (i2c_scl >= 0 && i2c_sda >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
|
if (i2c_scl >= 0 && i2c_sda >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (!Wire.setPins(i2c_sda, i2c_scl)) { i2c_scl = i2c_sda = -1; } // this will fail if Wire is initilised (Wire.begin() called prior)
|
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called prior)
|
||||||
else Wire.begin();
|
|
||||||
#else
|
|
||||||
Wire.begin(i2c_sda, i2c_scl);
|
|
||||||
#endif
|
#endif
|
||||||
|
Wire.begin();
|
||||||
} else {
|
} else {
|
||||||
i2c_sda = -1;
|
i2c_sda = -1;
|
||||||
i2c_scl = -1;
|
i2c_scl = -1;
|
||||||
@ -340,27 +328,18 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
CJSON(strip.paletteBlend, light[F("pal-mode")]);
|
CJSON(strip.paletteBlend, light[F("pal-mode")]);
|
||||||
CJSON(autoSegments, light[F("aseg")]);
|
CJSON(autoSegments, light[F("aseg")]);
|
||||||
|
|
||||||
CJSON(gammaCorrectVal, light["gc"]["val"]); // default 2.8
|
|
||||||
float light_gc_bri = light["gc"]["bri"];
|
float light_gc_bri = light["gc"]["bri"];
|
||||||
float light_gc_col = light["gc"]["col"];
|
float light_gc_col = light["gc"]["col"]; // 2.8
|
||||||
if (light_gc_bri > 1.0f) gammaCorrectBri = true;
|
if (light_gc_bri > 1.5) gammaCorrectBri = true;
|
||||||
else gammaCorrectBri = false;
|
else if (light_gc_bri > 0.5) gammaCorrectBri = false;
|
||||||
if (light_gc_col > 1.0f) gammaCorrectCol = true;
|
if (light_gc_col > 1.5) gammaCorrectCol = true;
|
||||||
else gammaCorrectCol = false;
|
else if (light_gc_col > 0.5) gammaCorrectCol = false;
|
||||||
if (gammaCorrectVal > 1.0f && gammaCorrectVal <= 3) {
|
|
||||||
if (gammaCorrectVal != 2.8f) NeoGammaWLEDMethod::calcGammaTable(gammaCorrectVal);
|
|
||||||
} else {
|
|
||||||
gammaCorrectVal = 1.0f; // no gamma correction
|
|
||||||
gammaCorrectBri = false;
|
|
||||||
gammaCorrectCol = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject light_tr = light["tr"];
|
JsonObject light_tr = light["tr"];
|
||||||
CJSON(fadeTransition, light_tr["mode"]);
|
CJSON(fadeTransition, light_tr["mode"]);
|
||||||
int tdd = light_tr["dur"] | -1;
|
int tdd = light_tr["dur"] | -1;
|
||||||
if (tdd >= 0) transitionDelay = transitionDelayDefault = tdd * 100;
|
if (tdd >= 0) transitionDelay = transitionDelayDefault = tdd * 100;
|
||||||
CJSON(strip.paletteFade, light_tr["pal"]);
|
CJSON(strip.paletteFade, light_tr["pal"]);
|
||||||
CJSON(randomPaletteChangeTime, light_tr[F("rpc")]);
|
|
||||||
|
|
||||||
JsonObject light_nl = light["nl"];
|
JsonObject light_nl = light["nl"];
|
||||||
CJSON(nightlightMode, light_nl["mode"]);
|
CJSON(nightlightMode, light_nl["mode"]);
|
||||||
@ -420,10 +399,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]);
|
CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]);
|
||||||
CJSON(DMXAddress, if_live_dmx[F("addr")]);
|
CJSON(DMXAddress, if_live_dmx[F("addr")]);
|
||||||
if (!DMXAddress || DMXAddress > 510) DMXAddress = 1;
|
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"]);
|
CJSON(DMXMode, if_live_dmx["mode"]);
|
||||||
|
|
||||||
tdd = if_live[F("timeout")] | -1;
|
tdd = if_live[F("timeout")] | -1;
|
||||||
@ -439,27 +414,30 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
|
|
||||||
CJSON(alexaNumPresets, interfaces["va"]["p"]);
|
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
|
#ifdef WLED_ENABLE_MQTT
|
||||||
JsonObject if_mqtt = interfaces["mqtt"];
|
JsonObject if_mqtt = interfaces["mqtt"];
|
||||||
CJSON(mqttEnabled, if_mqtt["en"]);
|
CJSON(mqttEnabled, if_mqtt["en"]);
|
||||||
getStringFromJson(mqttServer, if_mqtt[F("broker")], MQTT_MAX_SERVER_LEN+1);
|
getStringFromJson(mqttServer, if_mqtt[F("broker")], 33);
|
||||||
CJSON(mqttPort, if_mqtt["port"]); // 1883
|
CJSON(mqttPort, if_mqtt["port"]); // 1883
|
||||||
getStringFromJson(mqttUser, if_mqtt[F("user")], 41);
|
getStringFromJson(mqttUser, if_mqtt[F("user")], 41);
|
||||||
getStringFromJson(mqttPass, if_mqtt["psk"], 65); //normally not present due to security
|
getStringFromJson(mqttPass, if_mqtt["psk"], 65); //normally not present due to security
|
||||||
getStringFromJson(mqttClientID, if_mqtt[F("cid")], 41);
|
getStringFromJson(mqttClientID, if_mqtt[F("cid")], 41);
|
||||||
|
|
||||||
getStringFromJson(mqttDeviceTopic, if_mqtt[F("topics")][F("device")], MQTT_MAX_TOPIC_LEN+1); // "wled/test"
|
getStringFromJson(mqttDeviceTopic, if_mqtt[F("topics")][F("device")], 33); // "wled/test"
|
||||||
getStringFromJson(mqttGroupTopic, if_mqtt[F("topics")][F("group")], MQTT_MAX_TOPIC_LEN+1); // ""
|
getStringFromJson(mqttGroupTopic, if_mqtt[F("topics")][F("group")], 33); // ""
|
||||||
CJSON(retainMqttMsg, if_mqtt[F("rtn")]);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_ESPNOW
|
|
||||||
JsonObject remote = doc["remote"];
|
|
||||||
CJSON(enable_espnow_remote, remote[F("remote_enabled")]);
|
|
||||||
getStringFromJson(linked_remote, remote[F("linked_remote")], 13);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_HUESYNC
|
#ifndef WLED_DISABLE_HUESYNC
|
||||||
JsonObject if_hue = interfaces["hue"];
|
JsonObject if_hue = interfaces["hue"];
|
||||||
CJSON(huePollingEnabled, if_hue["en"]);
|
CJSON(huePollingEnabled, if_hue["en"]);
|
||||||
@ -715,25 +693,29 @@ void serializeConfig() {
|
|||||||
hw_led[F("cr")] = cctFromRgb;
|
hw_led[F("cr")] = cctFromRgb;
|
||||||
hw_led[F("cb")] = strip.cctBlending;
|
hw_led[F("cb")] = strip.cctBlending;
|
||||||
hw_led["fps"] = strip.getTargetFps();
|
hw_led["fps"] = strip.getTargetFps();
|
||||||
hw_led[F("rgbwm")] = Bus::getGlobalAWMode(); // global auto white mode override
|
hw_led[F("rgbwm")] = Bus::getAutoWhiteMode(); // global override
|
||||||
hw_led[F("ld")] = useGlobalLedBuffer;
|
hw_led[F("ld")] = strip.useLedsArray;
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
// 2D Matrix Settings
|
// 2D Matrix Settings
|
||||||
if (strip.isMatrix) {
|
if (strip.isMatrix) {
|
||||||
JsonObject matrix = hw_led.createNestedObject(F("matrix"));
|
JsonObject matrix = hw_led.createNestedObject(F("matrix"));
|
||||||
matrix[F("mpc")] = strip.panels;
|
matrix[F("ph")] = strip.panelH;
|
||||||
|
matrix[F("pw")] = strip.panelW;
|
||||||
|
matrix[F("mph")] = strip.hPanels;
|
||||||
|
matrix[F("mpv")] = strip.vPanels;
|
||||||
|
matrix[F("pb")] = strip.matrix.bottomStart;
|
||||||
|
matrix[F("pr")] = strip.matrix.rightStart;
|
||||||
|
matrix[F("pv")] = strip.matrix.vertical;
|
||||||
|
matrix["ps"] = strip.matrix.serpentine;
|
||||||
|
|
||||||
JsonArray panels = matrix.createNestedArray(F("panels"));
|
JsonArray panels = matrix.createNestedArray(F("panels"));
|
||||||
for (uint8_t i=0; i<strip.panel.size(); i++) {
|
for (uint8_t i=0; i<strip.hPanels*strip.vPanels; i++) {
|
||||||
JsonObject pnl = panels.createNestedObject();
|
JsonObject pnl = panels.createNestedObject();
|
||||||
pnl["b"] = strip.panel[i].bottomStart;
|
pnl["b"] = strip.panel[i].bottomStart;
|
||||||
pnl["r"] = strip.panel[i].rightStart;
|
pnl["r"] = strip.panel[i].rightStart;
|
||||||
pnl["v"] = strip.panel[i].vertical;
|
pnl["v"] = strip.panel[i].vertical;
|
||||||
pnl["s"] = strip.panel[i].serpentine;
|
pnl["s"] = strip.panel[i].serpentine;
|
||||||
pnl["x"] = strip.panel[i].xOffset;
|
|
||||||
pnl["y"] = strip.panel[i].yOffset;
|
|
||||||
pnl["h"] = strip.panel[i].height;
|
|
||||||
pnl["w"] = strip.panel[i].width;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -751,12 +733,11 @@ void serializeConfig() {
|
|||||||
uint8_t nPins = bus->getPins(pins);
|
uint8_t nPins = bus->getPins(pins);
|
||||||
for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
|
for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
|
||||||
ins[F("order")] = bus->getColorOrder();
|
ins[F("order")] = bus->getColorOrder();
|
||||||
ins["rev"] = bus->isReversed();
|
ins["rev"] = bus->reversed;
|
||||||
ins[F("skip")] = bus->skippedLeds();
|
ins[F("skip")] = bus->skippedLeds();
|
||||||
ins["type"] = bus->getType() & 0x7F;
|
ins["type"] = bus->getType() & 0x7F;
|
||||||
ins["ref"] = bus->isOffRefreshRequired();
|
ins["ref"] = bus->isOffRefreshRequired();
|
||||||
ins[F("rgbwm")] = bus->getAutoWhiteMode();
|
ins[F("rgbwm")] = bus->getAWMode();
|
||||||
ins[F("freq")] = bus->getFrequency();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray hw_com = hw.createNestedArray(F("com"));
|
JsonArray hw_com = hw.createNestedArray(F("com"));
|
||||||
@ -821,15 +802,13 @@ void serializeConfig() {
|
|||||||
light[F("aseg")] = autoSegments;
|
light[F("aseg")] = autoSegments;
|
||||||
|
|
||||||
JsonObject light_gc = light.createNestedObject("gc");
|
JsonObject light_gc = light.createNestedObject("gc");
|
||||||
light_gc["bri"] = (gammaCorrectBri) ? gammaCorrectVal : 1.0f; // keep compatibility
|
light_gc["bri"] = (gammaCorrectBri) ? 2.8 : 1.0;
|
||||||
light_gc["col"] = (gammaCorrectCol) ? gammaCorrectVal : 1.0f; // keep compatibility
|
light_gc["col"] = (gammaCorrectCol) ? 2.8 : 1.0;
|
||||||
light_gc["val"] = gammaCorrectVal;
|
|
||||||
|
|
||||||
JsonObject light_tr = light.createNestedObject("tr");
|
JsonObject light_tr = light.createNestedObject("tr");
|
||||||
light_tr["mode"] = fadeTransition;
|
light_tr["mode"] = fadeTransition;
|
||||||
light_tr["dur"] = transitionDelayDefault / 100;
|
light_tr["dur"] = transitionDelayDefault / 100;
|
||||||
light_tr["pal"] = strip.paletteFade;
|
light_tr["pal"] = strip.paletteFade;
|
||||||
light_tr[F("rpc")] = randomPaletteChangeTime;
|
|
||||||
|
|
||||||
JsonObject light_nl = light.createNestedObject("nl");
|
JsonObject light_nl = light.createNestedObject("nl");
|
||||||
light_nl["mode"] = nightlightMode;
|
light_nl["mode"] = nightlightMode;
|
||||||
@ -878,9 +857,7 @@ void serializeConfig() {
|
|||||||
JsonObject if_live_dmx = if_live.createNestedObject("dmx");
|
JsonObject if_live_dmx = if_live.createNestedObject("dmx");
|
||||||
if_live_dmx[F("uni")] = e131Universe;
|
if_live_dmx[F("uni")] = e131Universe;
|
||||||
if_live_dmx[F("seqskip")] = e131SkipOutOfSequence;
|
if_live_dmx[F("seqskip")] = e131SkipOutOfSequence;
|
||||||
if_live_dmx[F("e131prio")] = e131Priority;
|
|
||||||
if_live_dmx[F("addr")] = DMXAddress;
|
if_live_dmx[F("addr")] = DMXAddress;
|
||||||
if_live_dmx[F("dss")] = DMXSegmentSpacing;
|
|
||||||
if_live_dmx["mode"] = DMXMode;
|
if_live_dmx["mode"] = DMXMode;
|
||||||
|
|
||||||
if_live[F("timeout")] = realtimeTimeoutMs / 100;
|
if_live[F("timeout")] = realtimeTimeoutMs / 100;
|
||||||
@ -897,6 +874,13 @@ void serializeConfig() {
|
|||||||
|
|
||||||
if_va["p"] = alexaNumPresets;
|
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
|
#ifdef WLED_ENABLE_MQTT
|
||||||
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
||||||
if_mqtt["en"] = mqttEnabled;
|
if_mqtt["en"] = mqttEnabled;
|
||||||
@ -905,20 +889,12 @@ void serializeConfig() {
|
|||||||
if_mqtt[F("user")] = mqttUser;
|
if_mqtt[F("user")] = mqttUser;
|
||||||
if_mqtt[F("pskl")] = strlen(mqttPass);
|
if_mqtt[F("pskl")] = strlen(mqttPass);
|
||||||
if_mqtt[F("cid")] = mqttClientID;
|
if_mqtt[F("cid")] = mqttClientID;
|
||||||
if_mqtt[F("rtn")] = retainMqttMsg;
|
|
||||||
|
|
||||||
JsonObject if_mqtt_topics = if_mqtt.createNestedObject(F("topics"));
|
JsonObject if_mqtt_topics = if_mqtt.createNestedObject(F("topics"));
|
||||||
if_mqtt_topics[F("device")] = mqttDeviceTopic;
|
if_mqtt_topics[F("device")] = mqttDeviceTopic;
|
||||||
if_mqtt_topics[F("group")] = mqttGroupTopic;
|
if_mqtt_topics[F("group")] = mqttGroupTopic;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_ESPNOW
|
|
||||||
JsonObject remote = doc.createNestedObject(F("remote"));
|
|
||||||
remote[F("remote_enabled")] = enable_espnow_remote;
|
|
||||||
remote[F("linked_remote")] = linked_remote;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_HUESYNC
|
#ifndef WLED_DISABLE_HUESYNC
|
||||||
JsonObject if_hue = interfaces.createNestedObject("hue");
|
JsonObject if_hue = interfaces.createNestedObject("hue");
|
||||||
if_hue["en"] = huePollingEnabled;
|
if_hue["en"] = huePollingEnabled;
|
||||||
@ -1035,6 +1011,13 @@ bool deserializeConfigSec() {
|
|||||||
|
|
||||||
JsonObject interfaces = doc["if"];
|
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
|
#ifdef WLED_ENABLE_MQTT
|
||||||
JsonObject if_mqtt = interfaces["mqtt"];
|
JsonObject if_mqtt = interfaces["mqtt"];
|
||||||
getStringFromJson(mqttPass, if_mqtt["psk"], 65);
|
getStringFromJson(mqttPass, if_mqtt["psk"], 65);
|
||||||
@ -1073,6 +1056,10 @@ void serializeConfigSec() {
|
|||||||
ap["psk"] = apPass;
|
ap["psk"] = apPass;
|
||||||
|
|
||||||
JsonObject interfaces = doc.createNestedObject("if");
|
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
|
#ifdef WLED_ENABLE_MQTT
|
||||||
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
||||||
if_mqtt["psk"] = mqttPass;
|
if_mqtt["psk"] = mqttPass;
|
||||||
|
@ -57,42 +57,39 @@ void setRandomColor(byte* rgb)
|
|||||||
|
|
||||||
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
|
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
|
||||||
{
|
{
|
||||||
float h = ((float)hue)/65535.0f;
|
float h = ((float)hue)/65535.0;
|
||||||
float s = ((float)sat)/255.0f;
|
float s = ((float)sat)/255.0;
|
||||||
int i = floorf(h*6);
|
byte i = floor(h*6);
|
||||||
float f = h * 6.0f - i;
|
float f = h * 6-i;
|
||||||
int p = int(255.0f * (1.0f-s));
|
float p = 255 * (1-s);
|
||||||
int q = int(255.0f * (1.0f-f*s));
|
float q = 255 * (1-f*s);
|
||||||
int t = int(255.0f * (1.0f-(1.0f-f)*s));
|
float t = 255 * (1-(1-f)*s);
|
||||||
p = constrain(p, 0, 255);
|
|
||||||
q = constrain(q, 0, 255);
|
|
||||||
t = constrain(t, 0, 255);
|
|
||||||
switch (i%6) {
|
switch (i%6) {
|
||||||
case 0: rgb[0]=255,rgb[1]=t,rgb[2]=p;break;
|
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 1: rgb[0]=q,rgb[1]=255,rgb[2]=p;break;
|
||||||
case 2: rgb[0]=p,rgb[1]=255,rgb[2]=t;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 3: rgb[0]=p,rgb[1]=q,rgb[2]=255;break;
|
||||||
case 4: rgb[0]=t,rgb[1]=p,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;
|
case 5: rgb[0]=255,rgb[1]=p,rgb[2]=q;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get RGB values from color temperature in K (https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html)
|
//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
|
void colorKtoRGB(uint16_t kelvin, byte* rgb) //white spectrum to rgb, calc
|
||||||
{
|
{
|
||||||
int r = 0, g = 0, b = 0;
|
float r = 0, g = 0, b = 0;
|
||||||
float temp = kelvin / 100.0f;
|
float temp = kelvin / 100;
|
||||||
if (temp <= 66.0f) {
|
if (temp <= 66) {
|
||||||
r = 255;
|
r = 255;
|
||||||
g = roundf(99.4708025861f * logf(temp) - 161.1195681661f);
|
g = round(99.4708025861 * log(temp) - 161.1195681661);
|
||||||
if (temp <= 19.0f) {
|
if (temp <= 19) {
|
||||||
b = 0;
|
b = 0;
|
||||||
} else {
|
} else {
|
||||||
b = roundf(138.5177312231f * logf((temp - 10.0f)) - 305.0447927307f);
|
b = round(138.5177312231 * log((temp - 10)) - 305.0447927307);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
r = roundf(329.698727446f * powf((temp - 60.0f), -0.1332047592f));
|
r = round(329.698727446 * pow((temp - 60), -0.1332047592));
|
||||||
g = roundf(288.1221695283f * powf((temp - 60.0f), -0.0755148492f));
|
g = round(288.1221695283 * pow((temp - 60), -0.0755148492));
|
||||||
b = 255;
|
b = 255;
|
||||||
}
|
}
|
||||||
//g += 12; //mod by Aircoookie, a bit less accurate but visibly less pinkish
|
//g += 12; //mod by Aircoookie, a bit less accurate but visibly less pinkish
|
||||||
@ -150,9 +147,9 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www
|
|||||||
b = 1.0f;
|
b = 1.0f;
|
||||||
}
|
}
|
||||||
// Apply gamma correction
|
// Apply gamma correction
|
||||||
r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * powf(r, (1.0f / 2.4f)) - 0.055f;
|
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) * powf(g, (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) * powf(b, (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;
|
||||||
|
|
||||||
if (r > b && r > g) {
|
if (r > b && r > g) {
|
||||||
// red is biggest
|
// red is biggest
|
||||||
@ -176,9 +173,9 @@ void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www
|
|||||||
b = 1.0f;
|
b = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rgb[0] = byte(255.0f*r);
|
rgb[0] = 255.0*r;
|
||||||
rgb[1] = byte(255.0f*g);
|
rgb[1] = 255.0*g;
|
||||||
rgb[2] = byte(255.0f*b);
|
rgb[2] = 255.0*b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.developers.meethue.com/documentation/color-conversions-rgb-xy)
|
void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.developers.meethue.com/documentation/color-conversions-rgb-xy)
|
||||||
@ -245,13 +242,35 @@ float maxf (float v, float w)
|
|||||||
return v;
|
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)
|
// 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)
|
uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb)
|
||||||
{
|
{
|
||||||
//remember so that slow colorKtoRGB() doesn't have to run for every setPixelColor()
|
//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
|
if (lastKelvin != kelvin) colorKtoRGB(kelvin, correctionRGB); // convert Kelvin to RGB
|
||||||
lastKelvin = kelvin;
|
lastKelvin = kelvin;
|
||||||
byte rgbw[4];
|
byte rgbw[4];
|
||||||
@ -302,7 +321,7 @@ uint16_t approximateKelvinFromRGB(uint32_t rgb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//gamma 2.8 lookup table used for color correction
|
//gamma 2.8 lookup table used for color correction
|
||||||
uint8_t NeoGammaWLEDMethod::gammaT[256] = {
|
static byte gammaT[] = {
|
||||||
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, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
|
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,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
|
||||||
@ -320,22 +339,27 @@ uint8_t NeoGammaWLEDMethod::gammaT[256] = {
|
|||||||
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
|
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 };
|
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
|
||||||
|
|
||||||
// re-calculates & fills gamma table
|
uint8_t gamma8_cal(uint8_t b, float gamma)
|
||||||
void NeoGammaWLEDMethod::calcGammaTable(float gamma)
|
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < 256; i++) {
|
return (int)(powf((float)b / 255.0f, gamma) * 255.0f + 0.5f);
|
||||||
gammaT[i] = (int)(powf((float)i / 255.0f, gamma) * 255.0f + 0.5f);
|
}
|
||||||
|
|
||||||
|
// re-calculates & fills gamma table
|
||||||
|
void calcGammaTable(float gamma)
|
||||||
|
{
|
||||||
|
for (uint16_t i = 0; i < 256; i++) {
|
||||||
|
gammaT[i] = gamma8_cal(i, gamma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t NeoGammaWLEDMethod::Correct(uint8_t value)
|
// used for individual channel or brightness gamma correction
|
||||||
|
uint8_t gamma8(uint8_t b)
|
||||||
{
|
{
|
||||||
if (!gammaCorrectCol) return value;
|
return gammaT[b];
|
||||||
return gammaT[value];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for color gamma correction
|
// used for color gamma correction
|
||||||
uint32_t NeoGammaWLEDMethod::Correct32(uint32_t color)
|
uint32_t gamma32(uint32_t color)
|
||||||
{
|
{
|
||||||
if (!gammaCorrectCol) return color;
|
if (!gammaCorrectCol) return color;
|
||||||
uint8_t w = W(color);
|
uint8_t w = W(color);
|
||||||
|
142
wled00/const.h
@ -12,7 +12,6 @@
|
|||||||
#define DEFAULT_AP_SSID "WLED-AP"
|
#define DEFAULT_AP_SSID "WLED-AP"
|
||||||
#define DEFAULT_AP_PASS "wled1234"
|
#define DEFAULT_AP_PASS "wled1234"
|
||||||
#define DEFAULT_OTA_PASS "wledota"
|
#define DEFAULT_OTA_PASS "wledota"
|
||||||
#define DEFAULT_MDNS_NAME "x"
|
|
||||||
|
|
||||||
//increase if you need more
|
//increase if you need more
|
||||||
#ifndef WLED_MAX_USERMODS
|
#ifndef WLED_MAX_USERMODS
|
||||||
@ -26,44 +25,25 @@
|
|||||||
#ifndef WLED_MAX_BUSSES
|
#ifndef WLED_MAX_BUSSES
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define WLED_MAX_BUSSES 3
|
#define WLED_MAX_BUSSES 3
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 2
|
|
||||||
#else
|
#else
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
|
#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_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
|
#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
|
#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_MAX_BUSSES 6 // will allow 4 digital & 2 analog
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 4
|
|
||||||
#else
|
#else
|
||||||
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
|
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 3
|
|
||||||
#endif
|
#endif
|
||||||
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
|
#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_MAX_BUSSES 6 // will allow 4 digital & 2 analog
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 4
|
|
||||||
#else
|
#else
|
||||||
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
|
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
|
||||||
#define WLED_MAX_BUSSES 8
|
#define WLED_MAX_BUSSES 8
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 2
|
|
||||||
#else
|
#else
|
||||||
#define WLED_MAX_BUSSES 10
|
#define WLED_MAX_BUSSES 10
|
||||||
#define WLED_MIN_VIRTUAL_BUSSES 0
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
#ifndef WLED_MAX_BUTTONS
|
#ifndef WLED_MAX_BUTTONS
|
||||||
@ -80,32 +60,6 @@
|
|||||||
#define WLED_MAX_COLOR_ORDER_MAPPINGS 10
|
#define WLED_MAX_COLOR_ORDER_MAPPINGS 10
|
||||||
#endif
|
#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
|
|
||||||
|
|
||||||
#ifndef WLED_MAX_SEGNAME_LEN
|
|
||||||
#ifdef ESP8266
|
|
||||||
#define WLED_MAX_SEGNAME_LEN 32
|
|
||||||
#else
|
|
||||||
#define WLED_MAX_SEGNAME_LEN 64
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if WLED_MAX_SEGNAME_LEN<32
|
|
||||||
#undef WLED_MAX_SEGNAME_LEN
|
|
||||||
#define WLED_MAX_SEGNAME_LEN 32
|
|
||||||
#else
|
|
||||||
#warning WLED UI does not support modified maximum segment name length!
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Usermod IDs
|
//Usermod IDs
|
||||||
#define USERMOD_ID_RESERVED 0 //Unused. Might indicate no usermod present
|
#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
|
#define USERMOD_ID_UNSPECIFIED 1 //Default value for a general user mod that does not specify a custom ID
|
||||||
@ -125,7 +79,7 @@
|
|||||||
#define USERMOD_ID_RTC 15 //Usermod "usermod_rtc.h"
|
#define USERMOD_ID_RTC 15 //Usermod "usermod_rtc.h"
|
||||||
#define USERMOD_ID_ELEKSTUBE_IPS 16 //Usermod "usermod_elekstube_ips.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_SN_PHOTORESISTOR 17 //Usermod "usermod_sn_photoresistor.h"
|
||||||
#define USERMOD_ID_BATTERY 18 //Usermod "usermod_v2_battery.h"
|
#define USERMOD_ID_BATTERY_STATUS_BASIC 18 //Usermod "usermod_v2_battery_status_basic.h"
|
||||||
#define USERMOD_ID_PWM_FAN 19 //Usermod "usermod_PWM_fan.h"
|
#define USERMOD_ID_PWM_FAN 19 //Usermod "usermod_PWM_fan.h"
|
||||||
#define USERMOD_ID_BH1750 20 //Usermod "usermod_bh1750.h"
|
#define USERMOD_ID_BH1750 20 //Usermod "usermod_bh1750.h"
|
||||||
#define USERMOD_ID_SEVEN_SEGMENT_DISPLAY 21 //Usermod "usermod_v2_seven_segment_display.h"
|
#define USERMOD_ID_SEVEN_SEGMENT_DISPLAY 21 //Usermod "usermod_v2_seven_segment_display.h"
|
||||||
@ -146,10 +100,6 @@
|
|||||||
#define USERMOD_ID_BOBLIGHT 36 //Usermod "boblight.h"
|
#define USERMOD_ID_BOBLIGHT 36 //Usermod "boblight.h"
|
||||||
#define USERMOD_ID_SD_CARD 37 //Usermod "usermod_sd_card.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_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
|
|
||||||
#define USERMOD_ID_WIREGUARD 41 //Usermod "wireguard.h"
|
|
||||||
#define USERMOD_ID_INTERNAL_TEMPERATURE 42 //Usermod "usermod_internal_temperature.h"
|
|
||||||
|
|
||||||
//Access point behavior
|
//Access point behavior
|
||||||
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
|
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
|
||||||
@ -167,7 +117,7 @@
|
|||||||
#define CALL_MODE_FX_CHANGED 6 //no longer used
|
#define CALL_MODE_FX_CHANGED 6 //no longer used
|
||||||
#define CALL_MODE_HUE 7
|
#define CALL_MODE_HUE 7
|
||||||
#define CALL_MODE_PRESET_CYCLE 8
|
#define CALL_MODE_PRESET_CYCLE 8
|
||||||
#define CALL_MODE_BLYNK 9 //no longer used
|
#define CALL_MODE_BLYNK 9
|
||||||
#define CALL_MODE_ALEXA 10
|
#define CALL_MODE_ALEXA 10
|
||||||
#define CALL_MODE_WS_SEND 11 //special call mode, not for notifier, updates websocket only
|
#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
|
#define CALL_MODE_BUTTON_PRESET 12 //button/IR JSON preset/macro
|
||||||
@ -177,9 +127,7 @@
|
|||||||
#define RGBW_MODE_AUTO_BRIGHTER 1 //New algorithm. Adds as much white as the darkest RGBW channel
|
#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_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_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
|
||||||
//#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
|
//realtime modes
|
||||||
#define REALTIME_MODE_INACTIVE 0
|
#define REALTIME_MODE_INACTIVE 0
|
||||||
@ -201,14 +149,10 @@
|
|||||||
#define DMX_MODE_DISABLED 0 //not used
|
#define DMX_MODE_DISABLED 0 //not used
|
||||||
#define DMX_MODE_SINGLE_RGB 1 //all LEDs same RGB color (3 channels)
|
#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_SINGLE_DRGB 2 //all LEDs same RGB color and master dimmer (4 channels)
|
||||||
#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (15 channels)
|
#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (11 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_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_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_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
|
//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
|
//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
|
||||||
@ -225,16 +169,12 @@
|
|||||||
#define TYPE_NONE 0 //light is not configured
|
#define TYPE_NONE 0 //light is not configured
|
||||||
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
|
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
|
||||||
//Digital types (data pin only) (16-31)
|
//Digital types (data pin only) (16-31)
|
||||||
#define TYPE_WS2812_1CH 18 //white-only chips (1 channel per IC) (unused)
|
#define TYPE_WS2812_1CH 20 //white-only chips
|
||||||
#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_WWA 21 //amber + warm + cold white
|
||||||
#define TYPE_WS2812_RGB 22
|
#define TYPE_WS2812_RGB 22
|
||||||
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
|
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
|
||||||
#define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units
|
#define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units
|
||||||
#define TYPE_TM1829 25
|
#define TYPE_TM1829 25
|
||||||
#define TYPE_UCS8903 26
|
|
||||||
#define TYPE_UCS8904 29
|
|
||||||
#define TYPE_SK6812_RGBW 30
|
#define TYPE_SK6812_RGBW 30
|
||||||
#define TYPE_TM1814 31
|
#define TYPE_TM1814 31
|
||||||
//"Analog" types (PWM) (32-47)
|
//"Analog" types (PWM) (32-47)
|
||||||
@ -283,7 +223,7 @@
|
|||||||
#define BTN_TYPE_ANALOG_INVERTED 8
|
#define BTN_TYPE_ANALOG_INVERTED 8
|
||||||
|
|
||||||
//Ethernet board types
|
//Ethernet board types
|
||||||
#define WLED_NUM_ETH_TYPES 11
|
#define WLED_NUM_ETH_TYPES 9
|
||||||
|
|
||||||
#define WLED_ETH_NONE 0
|
#define WLED_ETH_NONE 0
|
||||||
#define WLED_ETH_WT32_ETH01 1
|
#define WLED_ETH_WT32_ETH01 1
|
||||||
@ -292,10 +232,6 @@
|
|||||||
#define WLED_ETH_QUINLED 4
|
#define WLED_ETH_QUINLED 4
|
||||||
#define WLED_ETH_TWILIGHTLORD 5
|
#define WLED_ETH_TWILIGHTLORD 5
|
||||||
#define WLED_ETH_ESP32DEUX 6
|
#define WLED_ETH_ESP32DEUX 6
|
||||||
#define WLED_ETH_ESP32ETHKITVE 7
|
|
||||||
#define WLED_ETH_QUINLED_OCTA 8
|
|
||||||
#define WLED_ETH_ABCWLEDV43ETH 9
|
|
||||||
#define WLED_ETH_SERG74 10
|
|
||||||
|
|
||||||
//Hue error codes
|
//Hue error codes
|
||||||
#define HUE_ERROR_INACTIVE 0
|
#define HUE_ERROR_INACTIVE 0
|
||||||
@ -330,15 +266,9 @@
|
|||||||
//Playlist option byte
|
//Playlist option byte
|
||||||
#define PL_OPTION_SHUFFLE 0x01
|
#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
|
// WLED Error modes
|
||||||
#define ERR_NONE 0 // All good :)
|
#define ERR_NONE 0 // All good :)
|
||||||
#define ERR_DENIED 1 // Permission denied
|
#define ERR_EEP_COMMIT 2 // Could not commit to EEPROM (wrong flash layout?)
|
||||||
#define ERR_EEP_COMMIT 2 // Could not commit to EEPROM (wrong flash layout?) OBSOLETE
|
|
||||||
#define ERR_NOBUF 3 // JSON buffer was not released in time, request cannot be handled at this time
|
#define ERR_NOBUF 3 // JSON buffer was not released in time, request cannot be handled at this time
|
||||||
#define ERR_JSON 9 // JSON parsing failed (input too large?)
|
#define ERR_JSON 9 // JSON parsing failed (input too large?)
|
||||||
#define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?)
|
#define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?)
|
||||||
@ -356,23 +286,6 @@
|
|||||||
#define NL_MODE_COLORFADE 2 //Fade to target brightness and secondary color gradually
|
#define NL_MODE_COLORFADE 2 //Fade to target brightness and secondary color gradually
|
||||||
#define NL_MODE_SUN 3 //Sunrise/sunset. Target brightness is set immediately, then Sunrise effect is started. Max 60 min.
|
#define NL_MODE_SUN 3 //Sunrise/sunset. Target brightness is set immediately, then Sunrise effect is started. Max 60 min.
|
||||||
|
|
||||||
// Settings sub page IDs
|
|
||||||
#define SUBPAGE_MENU 0
|
|
||||||
#define SUBPAGE_WIFI 1
|
|
||||||
#define SUBPAGE_LEDS 2
|
|
||||||
#define SUBPAGE_UI 3
|
|
||||||
#define SUBPAGE_SYNC 4
|
|
||||||
#define SUBPAGE_TIME 5
|
|
||||||
#define SUBPAGE_SEC 6
|
|
||||||
#define SUBPAGE_DMX 7
|
|
||||||
#define SUBPAGE_UM 8
|
|
||||||
#define SUBPAGE_UPDATE 9
|
|
||||||
#define SUBPAGE_2D 10
|
|
||||||
#define SUBPAGE_LOCK 251
|
|
||||||
#define SUBPAGE_PINREQ 252
|
|
||||||
#define SUBPAGE_CSS 253
|
|
||||||
#define SUBPAGE_JS 254
|
|
||||||
#define SUBPAGE_WELCOME 255
|
|
||||||
|
|
||||||
#define NTP_PACKET_SIZE 48
|
#define NTP_PACKET_SIZE 48
|
||||||
|
|
||||||
@ -405,7 +318,7 @@
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#define SETTINGS_STACK_BUF_SIZE 2048
|
#define SETTINGS_STACK_BUF_SIZE 2048
|
||||||
#else
|
#else
|
||||||
#define SETTINGS_STACK_BUF_SIZE 3608 // warning: quite a large value for stack
|
#define SETTINGS_STACK_BUF_SIZE 3096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_USE_ETHERNET
|
#ifdef WLED_USE_ETHERNET
|
||||||
@ -446,8 +359,8 @@
|
|||||||
#define JSON_BUFFER_SIZE 24576
|
#define JSON_BUFFER_SIZE 24576
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define MIN_HEAP_SIZE (8k for AsyncWebServer)
|
//#define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048)
|
||||||
#define MIN_HEAP_SIZE 8192
|
#define MIN_HEAP_SIZE (8192)
|
||||||
|
|
||||||
// Maximum size of node map (list of other WLED instances)
|
// Maximum size of node map (list of other WLED instances)
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@ -477,27 +390,14 @@
|
|||||||
#define DEFAULT_LED_COUNT 30
|
#define DEFAULT_LED_COUNT 30
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INTERFACE_UPDATE_COOLDOWN 1000 // time in ms to wait between websockets, alexa, and MQTT updates
|
#define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates
|
||||||
|
|
||||||
#define PIN_RETRY_COOLDOWN 3000 // time in ms after an incorrect attempt PIN and OTA pass will be rejected even if correct
|
|
||||||
#define PIN_TIMEOUT 900000 // time in ms after which the PIN will be required again, 15 minutes
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
#if defined(I2CSCLPIN) && !defined(HW_PIN_SCL)
|
|
||||||
#define HW_PIN_SCL I2CSCLPIN
|
|
||||||
#endif
|
|
||||||
#if defined(I2CSDAPIN) && !defined(HW_PIN_SDA)
|
|
||||||
#define HW_PIN_SDA I2CSDAPIN
|
|
||||||
#endif
|
|
||||||
// you cannot change HW I2C pins on 8266
|
|
||||||
#if defined(ESP8266) && defined(HW_PIN_SCL)
|
#if defined(ESP8266) && defined(HW_PIN_SCL)
|
||||||
#undef HW_PIN_SCL
|
#undef HW_PIN_SCL
|
||||||
#endif
|
#endif
|
||||||
#if defined(ESP8266) && defined(HW_PIN_SDA)
|
#if defined(ESP8266) && defined(HW_PIN_SDA)
|
||||||
#undef HW_PIN_SDA
|
#undef HW_PIN_SDA
|
||||||
#endif
|
#endif
|
||||||
// defaults for 1st I2C on ESP32 (Wire global)
|
|
||||||
#ifndef HW_PIN_SCL
|
#ifndef HW_PIN_SCL
|
||||||
#define HW_PIN_SCL SCL
|
#define HW_PIN_SCL SCL
|
||||||
#endif
|
#endif
|
||||||
@ -505,18 +405,6 @@
|
|||||||
#define HW_PIN_SDA SDA
|
#define HW_PIN_SDA SDA
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 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)
|
|
||||||
#if defined(SPISCLKPIN) && !defined(HW_PIN_CLOCKSPI)
|
|
||||||
#define HW_PIN_CLOCKSPI SPISCLKPIN
|
|
||||||
#endif
|
|
||||||
#if defined(SPIMOSIPIN) && !defined(HW_PIN_MOSISPI)
|
|
||||||
#define HW_PIN_MOSISPI SPIMOSIPIN
|
|
||||||
#endif
|
|
||||||
#if defined(SPIMISOPIN) && !defined(HW_PIN_MISOSPI)
|
|
||||||
#define HW_PIN_MISOSPI SPIMISOPIN
|
|
||||||
#endif
|
|
||||||
// you cannot change HW SPI pins on 8266
|
|
||||||
#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
|
#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
|
||||||
#undef HW_PIN_CLOCKSPI
|
#undef HW_PIN_CLOCKSPI
|
||||||
#endif
|
#endif
|
||||||
@ -526,7 +414,10 @@
|
|||||||
#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
|
#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
|
||||||
#undef HW_PIN_MISOSPI
|
#undef HW_PIN_MISOSPI
|
||||||
#endif
|
#endif
|
||||||
// defaults for VSPI on ESP32 (SPI global, SPI.cpp) as HSPI is used by WLED (bus_wrapper.h)
|
#if defined(ESP8266) && defined(HW_PIN_CSSPI)
|
||||||
|
#undef HW_PIN_CSSPI
|
||||||
|
#endif
|
||||||
|
// defaults for VSPI
|
||||||
#ifndef HW_PIN_CLOCKSPI
|
#ifndef HW_PIN_CLOCKSPI
|
||||||
#define HW_PIN_CLOCKSPI SCK
|
#define HW_PIN_CLOCKSPI SCK
|
||||||
#endif
|
#endif
|
||||||
@ -536,5 +427,8 @@
|
|||||||
#ifndef HW_PIN_MISOSPI
|
#ifndef HW_PIN_MISOSPI
|
||||||
#define HW_PIN_MISOSPI MISO
|
#define HW_PIN_MISOSPI MISO
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef HW_PIN_CSSPI
|
||||||
|
#define HW_PIN_CSSPI SS
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,6 +42,6 @@
|
|||||||
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAbUExURQAAAAB81gCU/zKq/////9bW1oCAgGhoaAAAAGPLX8AAAAAJdFJOU///////////AFNPeBIAAAAJcEhZcwAADsAAAA7AAWrWiQkAAACdSURBVDhPxc9bDoUgEANQebP/FUuHMjBGY/B+3EYR7RH0qC/ZBc6HwCljgHO+xZIVSI2sYgHaG7EBWh8jWoxTrCBFdDJ+BD4lbIHxAcz8APAVLTsrZE4eQD5qzt3cAFTYokC4YCN9Gybgu4yAQtBFLQXHuHABA7JMeOEC/E0W5uy9gv4vo5QHK2i7yq2C8UABM4HmL+CSTXCTF1DrCX6+Gp9zB5dsAAAAAElFTkSuQmCC">
|
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAbUExURQAAAAB81gCU/zKq/////9bW1oCAgGhoaAAAAGPLX8AAAAAJdFJOU///////////AFNPeBIAAAAJcEhZcwAADsAAAA7AAWrWiQkAAACdSURBVDhPxc9bDoUgEANQebP/FUuHMjBGY/B+3EYR7RH0qC/ZBc6HwCljgHO+xZIVSI2sYgHaG7EBWh8jWoxTrCBFdDJ+BD4lbIHxAcz8APAVLTsrZE4eQD5qzt3cAFTYokC4YCN9Gybgu4yAQtBFLQXHuHABA7JMeOEC/E0W5uy9gv4vo5QHK2i7yq2C8UABM4HmL+CSTXCTF1DrCX6+Gp9zB5dsAAAAAElFTkSuQmCC">
|
||||||
<h1>404 Not Found</h1>
|
<h1>404 Not Found</h1>
|
||||||
<b>Akemi does not know where you are headed...</b><br><br>
|
<b>Akemi does not know where you are headed...</b><br><br>
|
||||||
<button onclick="window.location.href='../?sliders'">Back to controls</button>
|
<button onclick="window.location.href='/sliders'">Back to controls</button>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,689 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
|
||||||
<meta http-equiv="Pragma" content="no-cache">
|
|
||||||
<meta http-equiv="Expires" content="0">
|
|
||||||
<title>WLED Custom Palette Editor</title>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var d = document;
|
|
||||||
function gId(e) {return d.getElementById(e);}
|
|
||||||
function cE(e) {return d.createElement(e);}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
background-color: #111;
|
|
||||||
font-size: 16px;
|
|
||||||
color: #ddd;
|
|
||||||
margin: 0 10px;
|
|
||||||
line-height: 0.5;
|
|
||||||
}
|
|
||||||
#parent-container {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
height: 20px;
|
|
||||||
}
|
|
||||||
#bottomContainer {
|
|
||||||
position: absolute;
|
|
||||||
margin-top: 50px;
|
|
||||||
}
|
|
||||||
#gradient-box {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
.color-marker, .color-picker-marker {
|
|
||||||
position: absolute;
|
|
||||||
border-radius: 3px;
|
|
||||||
background-color: rgb(192, 192, 192);
|
|
||||||
border: 2px solid rgba(68, 68, 68, 0.5);
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
.color-marker {
|
|
||||||
height: 30px;
|
|
||||||
width: 7px;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
|
||||||
.color-picker-marker {
|
|
||||||
height: 7px;
|
|
||||||
width: 7px;
|
|
||||||
top: 150%;
|
|
||||||
}
|
|
||||||
.delete-marker {
|
|
||||||
position: absolute;
|
|
||||||
height: 5px;
|
|
||||||
width: 5px;
|
|
||||||
border-radius: 3px;
|
|
||||||
background-color: rgb(255, 255, 255);
|
|
||||||
border: 3px solid rgb(155, 40, 40);
|
|
||||||
top: 220%;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
.color-picker {
|
|
||||||
position: absolute;
|
|
||||||
height: 1px;
|
|
||||||
width: 1px;
|
|
||||||
border: 1px;
|
|
||||||
top: 150%;
|
|
||||||
z-index: 1;
|
|
||||||
border-color: #111;
|
|
||||||
background-color: #111;
|
|
||||||
}
|
|
||||||
.buttonclass {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
vertical-align: bottom;
|
|
||||||
background-color: #111;
|
|
||||||
}
|
|
||||||
#bottomContainer span {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
#info {
|
|
||||||
display: "";
|
|
||||||
text-align: center;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
position: relative;
|
|
||||||
margin-top: 10px;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.wrap {
|
|
||||||
width: 800px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
.palette {
|
|
||||||
height: 20px;
|
|
||||||
}
|
|
||||||
.paletteGradients {
|
|
||||||
flex: 1;
|
|
||||||
height: 20px;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
.palettesMain {
|
|
||||||
margin-top: 50px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.palTop {
|
|
||||||
height: fit-content;
|
|
||||||
text-align: center;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
position: relative;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.palGradientParent {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: fit-content;
|
|
||||||
margin-top: 10px;
|
|
||||||
text-align: center;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 12px;
|
|
||||||
position: relative;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.buttonsDiv {
|
|
||||||
display: inline-flex;
|
|
||||||
margin-left: 5px;
|
|
||||||
width: 50px;
|
|
||||||
}
|
|
||||||
.sendSpan, .editSpan{
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="wrap" class="wrap">
|
|
||||||
<div style="display: flex; justify-content: center;">
|
|
||||||
<h1 style="display: flex; align-items: center;">
|
|
||||||
<svg style="width:36px;height:36px;margin-right:6px;" viewBox="0 0 32 32">
|
|
||||||
<rect style="fill:#003FFF" x="6" y="22" width="8" height="4"/>
|
|
||||||
<rect style="fill:#003FFF" x="14" y="14" width="4" height="8"/>
|
|
||||||
<rect style="fill:#003FFF" x="18" y="10" width="4" height="8"/>
|
|
||||||
<rect style="fill:#003FFF" x="22" y="6" width="8" height="4"/>
|
|
||||||
</svg>
|
|
||||||
<span id="head">WLED Custom Palette Editor</span>
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="parent-container">
|
|
||||||
<div id="gradient-box"></div>
|
|
||||||
</div>
|
|
||||||
<div style="display: flex; justify-content: center;">
|
|
||||||
<div id="palettes" class="palettesMain">
|
|
||||||
<div id="palTop" class="palTop">
|
|
||||||
Currently in use custom palettes
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="display: flex; justify-content: center;">
|
|
||||||
<div id="info">
|
|
||||||
Click on the gradient editor to add new color slider, then the colored box below the slider to change its color.
|
|
||||||
Click the red box below indicator (and confirm) to delete.
|
|
||||||
Once finished, click the arrow icon to upload into the desired slot.
|
|
||||||
To edit existing palette, click the pencil icon.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div style="display: flex; justify-content: center;">
|
|
||||||
<div id="staticPalettes" class="palettesMain">
|
|
||||||
<div id="statpalTop" class="palTop">
|
|
||||||
Available static palettes
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
//global variables
|
|
||||||
var gradientBox = gId('gradient-box');
|
|
||||||
var cpalc = -1;
|
|
||||||
var pxCol = {};
|
|
||||||
var tCol = {};
|
|
||||||
var rect = gradientBox.getBoundingClientRect();
|
|
||||||
var gradientLength = rect.width;
|
|
||||||
var mOffs = Math.round((gradientLength / 256) / 2) - 5;
|
|
||||||
var paletteArray = []; //Holds the palettes after load.
|
|
||||||
var svgSave = '<svg style="width:25px;height:25px" viewBox="0 0 24 24"><path fill=#fff d="M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12M7,12L12,17V14H16V10H12V7L7,12Z"/></svg>'
|
|
||||||
var svgEdit = '<svg style="width:25px;height:25px" viewBox="0 0 24 24"><path fill=#fff d="M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M15.1,7.07C15.24,7.07 15.38,7.12 15.5,7.23L16.77,8.5C17,8.72 17,9.07 16.77,9.28L15.77,10.28L13.72,8.23L14.72,7.23C14.82,7.12 14.96,7.07 15.1,7.07M13.13,8.81L15.19,10.87L9.13,16.93H7.07V14.87L13.13,8.81Z"/></svg>'
|
|
||||||
|
|
||||||
function recOf() {
|
|
||||||
rect = gradientBox.getBoundingClientRect();
|
|
||||||
gradientLength = rect.width;
|
|
||||||
mOffs = Math.round((gradientLength / 256) / 2) - 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Initiation
|
|
||||||
getInfo();
|
|
||||||
window.addEventListener('load', chkW);
|
|
||||||
window.addEventListener('resize', chkW);
|
|
||||||
|
|
||||||
gradientBox.addEventListener("click", clikOnGradient);
|
|
||||||
|
|
||||||
//Sets start and stop, mandatory
|
|
||||||
addC(0);
|
|
||||||
addC(255);
|
|
||||||
|
|
||||||
updateGradient(); //Sets the gradient at startup
|
|
||||||
|
|
||||||
function clikOnGradient(e) {
|
|
||||||
removeTrashcan(e);
|
|
||||||
addC(Math.round((e.offsetX/gradientLength)*256));
|
|
||||||
}
|
|
||||||
|
|
||||||
///////// Add a new colorMarker
|
|
||||||
function addC(truePos, thisColor = '') {
|
|
||||||
let position = -1;
|
|
||||||
let iExist = false;
|
|
||||||
const colorMarkers = gradientBox.querySelectorAll('.color-marker');
|
|
||||||
|
|
||||||
colorMarkers.forEach((colorMarker, i) => {
|
|
||||||
if (colorMarker.getAttribute("data-truepos") == truePos) {
|
|
||||||
iExist = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (colorMarkers.length > 17) iExist = true;
|
|
||||||
if (iExist) return; // Exit the function early if iExist is true
|
|
||||||
|
|
||||||
if (truePos > 0 && truePos < 255) {
|
|
||||||
//calculate first available > 0
|
|
||||||
for (var i = 1; i <= 16 && position < 1; i++) {
|
|
||||||
if (!gId("colorMarker"+i)) {
|
|
||||||
position = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
position = truePos;
|
|
||||||
}
|
|
||||||
if (thisColor == ''){
|
|
||||||
thisColor = `#${(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0')}`;// set random color as default
|
|
||||||
}
|
|
||||||
|
|
||||||
const colorMarker = cE('span'); // create a marker for the color position
|
|
||||||
colorMarker.className = 'color-marker';
|
|
||||||
colorMarker.id = 'colorMarker' + position.toString();
|
|
||||||
colorMarker.setAttribute("data-truepos", truePos); //Used to always have a true position no matter what screen or percentage we use
|
|
||||||
colorMarker.setAttribute("data-truecol", thisColor); //Used to hold the color of the position in the gradient connected to a true position
|
|
||||||
colorMarker.setAttribute("data-offset", mOffs);
|
|
||||||
colorMarker.addEventListener('click', stopFurtherProp); //Added to prevent the gradient click to fire when covered by a marker
|
|
||||||
colorMarker.style.left = `${Math.round((gradientLength / 256) * truePos)+mOffs}px`;
|
|
||||||
|
|
||||||
const colorPicker = cE('input');
|
|
||||||
colorPicker.type = 'color';
|
|
||||||
colorPicker.value = thisColor;
|
|
||||||
colorPicker.className = 'color-picker';
|
|
||||||
colorPicker.id = 'colorPicker' + position.toString();
|
|
||||||
colorPicker.addEventListener('input', updateGradient);
|
|
||||||
colorPicker.addEventListener('click',cpClk)
|
|
||||||
|
|
||||||
const colorPickerMarker = cE('span'); // create a marker for the color position
|
|
||||||
colorPickerMarker.className = 'color-picker-marker';
|
|
||||||
colorPickerMarker.id = 'colorPickerMarker' + position.toString();
|
|
||||||
colorPickerMarker.addEventListener('click', colClk);
|
|
||||||
colorPickerMarker.style.left = colorMarker.style.left;
|
|
||||||
colorPicker.style.left = colorMarker.style.left;
|
|
||||||
|
|
||||||
const deleteMarker = cE('span'); // create a delete marker for the color position
|
|
||||||
if (position > 0 && position < 255) {
|
|
||||||
deleteMarker.className = 'delete-marker';
|
|
||||||
deleteMarker.id = 'deleteMarker' + position.toString();
|
|
||||||
deleteMarker.addEventListener('click', (e) => {
|
|
||||||
deleteColor(e);
|
|
||||||
});
|
|
||||||
deleteMarker.style.left = colorMarker.style.left
|
|
||||||
}
|
|
||||||
|
|
||||||
colorMarker.style.backgroundColor = colorPicker.value; // set marker color to match color picker
|
|
||||||
colorPickerMarker.style.backgroundColor = colorPicker.value;
|
|
||||||
|
|
||||||
gradientBox.appendChild(colorPicker);
|
|
||||||
gradientBox.appendChild(colorMarker);
|
|
||||||
gradientBox.appendChild(colorPickerMarker);
|
|
||||||
if (position != 0 && position != 255) gradientBox.appendChild(deleteMarker); // append the marker if not start or end
|
|
||||||
//make markers slidable IF they are not the first or last slider
|
|
||||||
if (position > 0 && position < 255) makeMeDrag(gId(colorMarker.id));
|
|
||||||
|
|
||||||
setTooltipMarker(gId(colorMarker.id));
|
|
||||||
|
|
||||||
updateGradient();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////// Update Gradient
|
|
||||||
function updateGradient() {
|
|
||||||
const colorMarkers = gradientBox.querySelectorAll('.color-marker');
|
|
||||||
pxCol = {};
|
|
||||||
tCol = {}
|
|
||||||
colorMarkers.forEach((colorMarker, index) => {
|
|
||||||
const thisColorPicker = gId(colorMarkers[index].id.replace('colorMarker', 'colorPicker'));
|
|
||||||
const colorToSet = thisColorPicker.value;
|
|
||||||
gId(colorMarkers[index].id.replace('colorMarker', 'colorPickerMarker')).style.backgroundColor = colorToSet;
|
|
||||||
colorMarkers[index].style.backgroundColor = colorToSet;
|
|
||||||
colorMarkers[index].setAttribute("data-truecol", colorToSet);
|
|
||||||
const tPos = colorMarkers[index].getAttribute("data-truepos");
|
|
||||||
const gradientPos = Math.round((gradientLength / 256)*tPos);
|
|
||||||
pxCol[gradientPos] = colorToSet;
|
|
||||||
tCol[tPos] = colorToSet;
|
|
||||||
});
|
|
||||||
gradientString = 'linear-gradient(to right';
|
|
||||||
Object.entries(pxCol).forEach(([p, c]) => {
|
|
||||||
gradientString += `, ${c} ${p}px`;
|
|
||||||
});
|
|
||||||
gradientString += ')';
|
|
||||||
gradientBox.style.background = gradientString;
|
|
||||||
//gId("jsonstring").innerHTML = calcJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopFurtherProp(e) {
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function colClk(e){
|
|
||||||
removeTrashcan(e)
|
|
||||||
e.stopPropagation();
|
|
||||||
let cp = gId(e.srcElement.id.replace("Marker",""));
|
|
||||||
cp.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cpClk(e) {
|
|
||||||
removeTrashcan(event)
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
//This neat little function makes any element draggable on the X-axis.
|
|
||||||
//Just call: makeMeDrag(myElement); And you are good to go.
|
|
||||||
function makeMeDrag(elmnt) {
|
|
||||||
var posNew = 0, mousePos = 0, mouseOffset = 0
|
|
||||||
|
|
||||||
//Set these to whatever you want to limit your movement to
|
|
||||||
var rect = gradientBox.getBoundingClientRect();
|
|
||||||
var maxX = rect.right; // maximum X coordinate
|
|
||||||
var minX = rect.left; // minimum X coordinate i.e. also offset from left of screen
|
|
||||||
var gradientLength = maxX - minX + 1;
|
|
||||||
|
|
||||||
elmnt.onmousedown = dragMouseDown;
|
|
||||||
|
|
||||||
function dragMouseDown(e) {
|
|
||||||
removeTrashcan(event)
|
|
||||||
e = e || window.event;
|
|
||||||
e.preventDefault();
|
|
||||||
// get the mouse cursor position at startup:
|
|
||||||
mousePos = e.clientX;
|
|
||||||
d.onmouseup = closeDragElement;
|
|
||||||
// call a function whenever the cursor moves:
|
|
||||||
d.onmousemove = elementDrag;
|
|
||||||
}
|
|
||||||
|
|
||||||
function elementDrag(e) {
|
|
||||||
e = e || window.event;
|
|
||||||
e.preventDefault();
|
|
||||||
// calculate the new cursor position:
|
|
||||||
posNew = mousePos - e.clientX;
|
|
||||||
mousePos = e.clientX;
|
|
||||||
mousePosInGradient = mousePos - (minX + 1)
|
|
||||||
|
|
||||||
truePos = Math.round((mousePosInGradient/gradientLength)*256);
|
|
||||||
oldTruePos = elmnt.getAttribute("data-truepos");
|
|
||||||
// set the element's new position if new position within min/max limits:
|
|
||||||
if (truePos > 0 && truePos < 255 && oldTruePos != truePos) {
|
|
||||||
if (truePos < 64) {
|
|
||||||
thisOffset = 0;
|
|
||||||
} else if (truePos > 192) {
|
|
||||||
thisOffset = 7;
|
|
||||||
} else {
|
|
||||||
thisOffset=3;
|
|
||||||
}
|
|
||||||
elmnt.style.left = (Math.round((gradientLength/256)*truePos)+mOffs) + "px";
|
|
||||||
gId(elmnt.id.replace('colorMarker', 'colorPickerMarker')).style.left = elmnt.style.left;
|
|
||||||
gId(elmnt.id.replace('colorMarker', 'deleteMarker')).style.left = elmnt.style.left;
|
|
||||||
gId(elmnt.id.replace('colorMarker', 'colorPicker')).style.left = elmnt.style.left;
|
|
||||||
elmnt.setAttribute("data-truepos", truePos);
|
|
||||||
setTooltipMarker(elmnt);
|
|
||||||
updateGradient();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeDragElement() {
|
|
||||||
/* stop moving when mouse button is released:*/
|
|
||||||
d.onmouseup = null;
|
|
||||||
d.onmousemove = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTooltipMarker(elmnt) {
|
|
||||||
elmnt.setAttribute('title', `${elmnt.getAttribute("data-truepos")} : ${elmnt.getAttribute("data-truecol")}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteColor(e) {
|
|
||||||
var trash = cE("div");
|
|
||||||
thisDeleteMarker = e.srcElement;
|
|
||||||
thisColorMarker = gId(thisDeleteMarker.id.replace("delete", "color"));
|
|
||||||
thisColorPickerMarker = gId(thisDeleteMarker.id.replace("delete", "colorPicker"));
|
|
||||||
thisColorPicker = gId(thisDeleteMarker.id.replace("deleteMarker", "colorPicker"));
|
|
||||||
renderOffsetX = 15 - 5;
|
|
||||||
renderX = e.srcElement.getBoundingClientRect().x - renderOffsetX;
|
|
||||||
renderY = e.srcElement.getBoundingClientRect().y + 13;
|
|
||||||
|
|
||||||
trash.id = "trash";
|
|
||||||
trash.innerHTML = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="30px" height="30px"><path style="fill:#880000; stroke: #888888; stroke-width: -2px;stroke-dasharray: 0.1, 8;" d="M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z"/></svg>';
|
|
||||||
trash.style.position = "absolute";
|
|
||||||
trash.style.left = (renderX) + "px";
|
|
||||||
trash.style.top = (renderY) + "px";
|
|
||||||
d.body.appendChild(trash);
|
|
||||||
|
|
||||||
trash.addEventListener("click", (e)=>{
|
|
||||||
trash.parentNode.removeChild(trash);
|
|
||||||
thisDeleteMarker.parentNode.removeChild(thisDeleteMarker);
|
|
||||||
thisColorPickerMarker.parentNode.removeChild(thisColorPickerMarker);
|
|
||||||
thisColorMarker.parentNode.removeChild(thisColorMarker);
|
|
||||||
thisColorPicker.parentNode.removeChild(thisColorPicker);
|
|
||||||
updateGradient();
|
|
||||||
});
|
|
||||||
e.stopPropagation();
|
|
||||||
// Add event listener to close the trashcan on outside click
|
|
||||||
d.addEventListener("click", removeTrashcan);
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeTrashcan(event) {
|
|
||||||
trash = gId("trash");
|
|
||||||
if (event.target != trash && trash) {
|
|
||||||
trash.parentNode.removeChild(trash);
|
|
||||||
d.removeEventListener("click", removeTrashcan);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function chkW() {
|
|
||||||
//Possibly add more code that recalculates the gradient... Massive job ;)
|
|
||||||
const wrap = gId('wrap');
|
|
||||||
const head = gId('head');
|
|
||||||
if (wrap.offsetWidth < 600) {
|
|
||||||
head.style.display = 'none';
|
|
||||||
} else {
|
|
||||||
head.style.display = 'inline';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calcJSON() {
|
|
||||||
let rStr = '{"palette":['
|
|
||||||
Object.entries(tCol).forEach(([p, c]) => {
|
|
||||||
if (p > 0) rStr += ',';
|
|
||||||
rStr += `${p},"${c.slice(1)}"`; // store in hex notation
|
|
||||||
//rStr += `${p},${parseInt(c.slice(1, 3), 16)},${parseInt(c.slice(3, 5), 16)},${parseInt(c.slice(5, 7), 16)}`;
|
|
||||||
});
|
|
||||||
rStr += ']}';
|
|
||||||
return rStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initiateUpload(idx) {
|
|
||||||
const data = calcJSON();
|
|
||||||
const fileName = `/palette${idx}.json`;
|
|
||||||
uploadJSON(data, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
function uploadJSON(jsonString, fileName) {
|
|
||||||
//Some indication on "I'm working"
|
|
||||||
var req = new XMLHttpRequest();
|
|
||||||
var blob = new Blob([jsonString], {type: "application/json"});
|
|
||||||
req.addEventListener('load', ()=>{
|
|
||||||
console.log(this.responseText, ' - ', this.status)
|
|
||||||
localStorage.removeItem('wledPalx');
|
|
||||||
//setTimeout(()=>{
|
|
||||||
// ss.setAttribute('fill', '#fff');
|
|
||||||
//}, 1000);
|
|
||||||
//setTimeout(()=>{window.location.href='/';},2000);
|
|
||||||
window.location.href = '/'; //Guessing we want to return ASAP when we get confirmation save is done
|
|
||||||
});
|
|
||||||
req.addEventListener('error', (e)=>{
|
|
||||||
console.log('Error: ', e); console.log(' Status: ', this.status);
|
|
||||||
//Show some error notification for some time
|
|
||||||
setTimeout(()=>{
|
|
||||||
//Remove it when time has pased
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
req.open("POST", "/upload");
|
|
||||||
var formData = new FormData();
|
|
||||||
formData.append("data", blob, fileName);
|
|
||||||
req.send(formData);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getInfo() {
|
|
||||||
hst = location.host;
|
|
||||||
if (hst.length > 0 ) {
|
|
||||||
try {
|
|
||||||
var arr = [];
|
|
||||||
const response = await fetch('http://'+hst+'/json/info');
|
|
||||||
const json = await response.json();
|
|
||||||
cpalc = json.cpalcount;
|
|
||||||
fetchPalettes(cpalc-1);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error('cannot identify host');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchPalettes(lastPal) {
|
|
||||||
paletteArray.length = 0;
|
|
||||||
for (let i = 0; i <= lastPal; i++) {
|
|
||||||
const url = `http://${hst}/palette${i}.json`;
|
|
||||||
try {
|
|
||||||
const response = await fetch(url);
|
|
||||||
const json = await response.json();
|
|
||||||
paletteArray.push(json);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error fetching JSON from ${url}: `, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//If there is room for more custom palettes, add an empty, gray slot
|
|
||||||
if (paletteArray.length < 10) {
|
|
||||||
//Room for one more :)
|
|
||||||
paletteArray.push({"palette":[0,70,70,70,255,70,70,70]});
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get static palettes from localStorage and do some magic to reformat them into the same format as the pallete JSONs
|
|
||||||
//This code excludes any objects with "non valid integer colors", i.e. r, c1, c2, c3 and such
|
|
||||||
//This code also fixes potentially broken palettes which doesn't end on 255
|
|
||||||
//The code finally also removes any representations of the custom palettes, since we read them from file
|
|
||||||
|
|
||||||
const wledPalx = JSON.parse(localStorage.getItem('wledPalx'));
|
|
||||||
if (!wledPalx) {
|
|
||||||
alert("The cache of palettes are missig from your browser. You should probably return to the main page and let it load properly for the palettes cache to regenerate before returning here.","Missing cached palettes!")
|
|
||||||
} else {
|
|
||||||
for (const key in wledPalx.p) {
|
|
||||||
if (key > 245) {
|
|
||||||
delete wledPalx.p[key];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const arr = wledPalx.p[key];
|
|
||||||
let valid = true;
|
|
||||||
for (const subArr of arr) {
|
|
||||||
if (!Array.isArray(subArr) || subArr.length !== 4) {
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (const val of subArr) {
|
|
||||||
if (typeof val !== 'number' || val < 0 || val > 255 || !Number.isInteger(val)) {
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!valid) {
|
|
||||||
delete wledPalx.p[key];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const lastArr = arr[arr.length - 1];
|
|
||||||
if (lastArr[0] !== 255) {
|
|
||||||
const copyArr = [...lastArr];
|
|
||||||
copyArr[0] = 255;
|
|
||||||
arr.push(copyArr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pArray = Object.entries(wledPalx.p).map(([key, value]) => ({
|
|
||||||
[key]: value.flat()
|
|
||||||
}));
|
|
||||||
|
|
||||||
paletteArray.push( ...pArray);
|
|
||||||
}
|
|
||||||
generatePaletteDivs();
|
|
||||||
}
|
|
||||||
|
|
||||||
function generatePaletteDivs() {
|
|
||||||
const palettesDiv = d.getElementById("palettes");
|
|
||||||
const staticPalettesDiv = d.getElementById("staticPalettes");
|
|
||||||
const paletteDivs = Array.from(palettesDiv.children).filter((child) => {
|
|
||||||
return child.id.match(/^palette\d$/); // match only elements with id starting with "palette" followed by a single digit
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const div of paletteDivs) {
|
|
||||||
palettesDiv.removeChild(div); // remove each div that matches the above selector
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < paletteArray.length; i++) {
|
|
||||||
const palette = paletteArray[i];
|
|
||||||
const paletteDiv = d.createElement("div");
|
|
||||||
paletteDiv.id = `palette${i}`;
|
|
||||||
paletteDiv.classList.add("palette");
|
|
||||||
const thisKey = Object.keys(palette)[0];
|
|
||||||
paletteDiv.dataset.colarray = JSON.stringify(palette[thisKey]);
|
|
||||||
|
|
||||||
const gradientDiv = d.createElement("div");
|
|
||||||
gradientDiv.id = `paletteGradient${i}`
|
|
||||||
const buttonsDiv = d.createElement("div");
|
|
||||||
buttonsDiv.id = `buttonsDiv${i}`;
|
|
||||||
buttonsDiv.classList.add("buttonsDiv")
|
|
||||||
|
|
||||||
const sendSpan = d.createElement("span");
|
|
||||||
sendSpan.id = `sendSpan${i}`;
|
|
||||||
sendSpan.onclick = function() {initiateUpload(i)};
|
|
||||||
sendSpan.setAttribute('title', `Send current editor to slot ${i}`); // perhaps Save instead of Send?
|
|
||||||
sendSpan.innerHTML = svgSave;
|
|
||||||
sendSpan.classList.add("sendSpan")
|
|
||||||
const editSpan = d.createElement("span");
|
|
||||||
editSpan.id = `editSpan${i}`;
|
|
||||||
editSpan.onclick = function() {loadForEdit(i)};
|
|
||||||
editSpan.setAttribute('title', `Copy slot ${i} palette to editor`);
|
|
||||||
editSpan.innerHTML = svgEdit;
|
|
||||||
editSpan.classList.add("editSpan")
|
|
||||||
|
|
||||||
gradientDiv.classList.add("paletteGradients");
|
|
||||||
let gradientColors = "";
|
|
||||||
|
|
||||||
for (let j = 0; j < palette[thisKey].length; j += 2) {
|
|
||||||
const position = palette[thisKey][j];
|
|
||||||
if (typeof(palette[thisKey][j+1]) === "string") {
|
|
||||||
gradientColors += `#${palette[thisKey][j+1]} ${position/255*100}%, `;
|
|
||||||
} else {
|
|
||||||
const red = palette[thisKey][j + 1];
|
|
||||||
const green = palette[thisKey][j + 2];
|
|
||||||
const blue = palette[thisKey][j + 3];
|
|
||||||
gradientColors += `rgba(${red}, ${green}, ${blue}, 1) ${position/255*100}%, `;
|
|
||||||
j += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gradientColors = gradientColors.slice(0, -2); // remove the last comma and space
|
|
||||||
gradientDiv.style.backgroundImage = `linear-gradient(to right, ${gradientColors})`;
|
|
||||||
paletteDiv.className = "palGradientParent";
|
|
||||||
if (thisKey == "palette") {
|
|
||||||
buttonsDiv.appendChild(sendSpan); //Only offer to send to custom palettes
|
|
||||||
} else{
|
|
||||||
editSpan.style.marginLeft = "25px";
|
|
||||||
}
|
|
||||||
if (i!=cpalc) {
|
|
||||||
buttonsDiv.appendChild(editSpan); //Dont offer to edit the empty spot
|
|
||||||
}
|
|
||||||
paletteDiv.appendChild(gradientDiv);
|
|
||||||
paletteDiv.appendChild(buttonsDiv);
|
|
||||||
if (thisKey == "palette") {
|
|
||||||
palettesDiv.appendChild(paletteDiv);
|
|
||||||
} else {
|
|
||||||
staticPalettesDiv.appendChild(paletteDiv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadForEdit(i) {
|
|
||||||
d.querySelectorAll('input[id^="colorPicker"]').forEach((input) => {
|
|
||||||
input.parentNode.removeChild(input);
|
|
||||||
});
|
|
||||||
d.querySelectorAll('span[id^="colorMarker"], span[id^="colorPickerMarker"], span[id^="deleteMarker"]').forEach((span) => {
|
|
||||||
span.parentNode.removeChild(span);
|
|
||||||
});
|
|
||||||
|
|
||||||
let colArray = JSON.parse(gId(`palette${i}`).getAttribute("data-colarray"));
|
|
||||||
|
|
||||||
for (let j = 0; j < colArray.length; j += 2) {
|
|
||||||
const position = colArray[j];
|
|
||||||
let hex;
|
|
||||||
if (typeof(colArray[j+1]) === "string") {
|
|
||||||
hex = `#${colArray[j+1]}`;
|
|
||||||
} else {
|
|
||||||
const red = colArray[j + 1];
|
|
||||||
const green = colArray[j + 2];
|
|
||||||
const blue = colArray[j + 3];
|
|
||||||
hex = rgbToHex(red, green, blue);
|
|
||||||
j += 2;
|
|
||||||
}
|
|
||||||
addC(position, hex);
|
|
||||||
window.scroll(0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function rgbToHex(r, g, b) {
|
|
||||||
const hex = ((r << 16) | (g << 8) | b).toString(16);
|
|
||||||
return "#" + "0".repeat(6 - hex.length) + hex;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</html>
|
|
@ -128,13 +128,12 @@ button {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.on {
|
.icons.on {
|
||||||
color: var(--c-g) !important;
|
color: var(--c-g);
|
||||||
}
|
}
|
||||||
|
|
||||||
.off {
|
.icons.off {
|
||||||
color: var(--c-6) !important;
|
color: var(--c-6);
|
||||||
/* cursor: default !important; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.top .icons, .bot .icons {
|
.top .icons, .bot .icons {
|
||||||
@ -151,7 +150,7 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.segt TD {
|
.segt TD {
|
||||||
padding: 2px 0 !important;
|
padding: 2px !important;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
/*text-transform: uppercase;*/
|
/*text-transform: uppercase;*/
|
||||||
}
|
}
|
||||||
@ -174,62 +173,34 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.slider-icon {
|
.slider-icon {
|
||||||
position: absolute;
|
transform: translate(3px,3px);
|
||||||
left: 8px;
|
}
|
||||||
bottom: 5px;
|
|
||||||
|
.e-icon {
|
||||||
|
transform: translateY(3px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sel-icon {
|
.sel-icon {
|
||||||
transform: translateX(3px);
|
transform: translateX(3px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.e-icon, .g-icon, .sel-icon, .slider-icon {
|
.e-icon, .sel-icon, .slider-icon {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: var(--c-d);
|
color: var(--c-d);
|
||||||
}
|
}
|
||||||
|
|
||||||
.g-icon {
|
|
||||||
font-style: normal;
|
|
||||||
position: absolute;
|
|
||||||
top: 8px;
|
|
||||||
right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pop-up container */
|
|
||||||
.pop {
|
|
||||||
position: absolute;
|
|
||||||
display: inline-block;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pop-up content (segment sets) */
|
|
||||||
.pop-c {
|
|
||||||
position: absolute;
|
|
||||||
background-color: var(--c-2);
|
|
||||||
border: 1px solid var(--c-8);
|
|
||||||
border-radius: 20px;
|
|
||||||
z-index: 1;
|
|
||||||
top: 3px;
|
|
||||||
right: 35px;
|
|
||||||
padding: 3px 8px 1px;
|
|
||||||
font-size: 24px;
|
|
||||||
line-height: 24px;
|
|
||||||
}
|
|
||||||
.pop-c span {
|
|
||||||
padding: 2px 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search-icon {
|
.search-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
left: 12px;
|
left: 12px;
|
||||||
|
/*pointer-events: none;*/
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clear-icon {
|
.clear-icon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
display: none;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
right: 9px;
|
right: 9px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@ -257,12 +228,14 @@ button {
|
|||||||
|
|
||||||
#liveview {
|
#liveview {
|
||||||
height: 4px;
|
height: 4px;
|
||||||
|
display: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#liveview2D {
|
#liveview2D {
|
||||||
height: 90%;
|
height: 90%;
|
||||||
|
display: none;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -340,14 +313,14 @@ button {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overscroll-behavior: none;
|
overscroll-behavior: none;
|
||||||
padding: 0 4px;
|
}
|
||||||
|
|
||||||
|
#Effects {
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
}
|
}
|
||||||
|
|
||||||
#segutil, #segutil2, #segcont, #putil, #pcont, #pql, #fx, #palw,
|
#segutil, #segutil2, #segcont, #putil, #pcont, #pql {
|
||||||
.fnd {
|
width: 280px;
|
||||||
max-width: 280px;
|
|
||||||
font-size: 19px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#putil, #segutil, #segutil2 {
|
#putil, #segutil, #segutil2 {
|
||||||
@ -359,8 +332,7 @@ button {
|
|||||||
padding-top: 12px;
|
padding-top: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#fx, #pql, #segcont, #pcont, #sliders, #picker, #qcs-w, #hexw, #pall, #ledmap,
|
#pql, #segcont, #pcont {
|
||||||
.slider, .filter, .option, .segname, .pname, .fnd {
|
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,10 +379,10 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#sliders {
|
#sliders {
|
||||||
position: -webkit-sticky;
|
width: 300px;
|
||||||
|
margin: 0 auto;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
max-width: 300px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#sliders .labels {
|
#sliders .labels {
|
||||||
@ -419,49 +391,29 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.slider {
|
.slider {
|
||||||
/*max-width: 300px;*/
|
background-color: var(--c-2);
|
||||||
/* margin: 5px auto; add 5px; if you want some vertical space but looks ugly */
|
max-width: 300px;
|
||||||
|
min-width: 280px;
|
||||||
|
margin: 0 auto; /* add 5px; if you want some vertical space but looks ugly */
|
||||||
border-radius: 24px;
|
border-radius: 24px;
|
||||||
position: relative;
|
position: relative;
|
||||||
padding-bottom: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Slider wrapper div */
|
|
||||||
.sliderwrap {
|
|
||||||
height: 30px;
|
|
||||||
width: 230px;
|
|
||||||
max-width: 230px;
|
|
||||||
position: relative;
|
|
||||||
z-index: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#sliders .slider {
|
|
||||||
padding-right: 64px; /* offset for bubble */
|
|
||||||
}
|
|
||||||
|
|
||||||
#sliders .slider, #info .slider {
|
|
||||||
background-color: var(--c-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#sliders .sliderwrap, .sbs .sliderwrap {
|
|
||||||
left: 32px; /* offset for icon */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter, .option {
|
.filter, .option {
|
||||||
background-color: var(--c-4);
|
background-color: var(--c-4);
|
||||||
border-radius: 26px;
|
border-radius: 26px;
|
||||||
height: 26px;
|
height: 26px;
|
||||||
max-width: 300px;
|
margin: 0 auto; /* add 4-8px if you want space at the bottom */
|
||||||
/* margin: 0 auto 4px; add 4-8px if you want space at the bottom */
|
|
||||||
padding: 4px 2px;
|
padding: 4px 2px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transition: opacity 0.5s linear, height 0.5s, transform 0.5s;
|
transition: opacity 0.5s linear, height 0.5s, transform 0.5s;
|
||||||
|
transform: scaleY(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter {
|
.option {
|
||||||
z-index: 1;
|
z-index: unset;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tooltip text */
|
/* Tooltip text */
|
||||||
@ -472,20 +424,17 @@ button {
|
|||||||
box-shadow: 4px 4px 10px 4px var(--c-1);
|
box-shadow: 4px 4px 10px 4px var(--c-1);
|
||||||
color: var(--c-f);
|
color: var(--c-f);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 4px 8px;
|
padding: 5px 10px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
|
||||||
/* Position the tooltip text */
|
/* Position the tooltip text */
|
||||||
width: 160px;
|
width: 160px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
bottom: 80%;
|
bottom: 100%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
margin-left: -92px;
|
margin-left: -92px;
|
||||||
|
|
||||||
/* Ensure tooltip goes away when mouse leaves control */
|
|
||||||
pointer-events: none;
|
|
||||||
|
|
||||||
/* Fade in tooltip */
|
/* Fade in tooltip */
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity 0.75s;
|
transition: opacity 0.75s;
|
||||||
@ -510,6 +459,13 @@ button {
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pql, .edit-icon {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
.fade {
|
.fade {
|
||||||
visibility: hidden; /* hide it */
|
visibility: hidden; /* hide it */
|
||||||
opacity: 0; /* make it transparent */
|
opacity: 0; /* make it transparent */
|
||||||
@ -566,7 +522,6 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.close {
|
.close {
|
||||||
position: -webkit-sticky;
|
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
float: right;
|
float: right;
|
||||||
@ -588,6 +543,7 @@ button {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: calc(var(--th) + 5px);
|
top: calc(var(--th) + 5px);
|
||||||
left: 1px;
|
left: 1px;
|
||||||
|
display: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,9 +588,14 @@ button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#info #imgw {
|
#info #imgw {
|
||||||
|
/*display: inline-block;*/
|
||||||
margin: 8px auto;
|
margin: 8px auto;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
#kv, #kn {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
*/
|
||||||
#lv {
|
#lv {
|
||||||
max-width: 600px;
|
max-width: 600px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -682,27 +643,23 @@ img {
|
|||||||
#wbal .sliderdisplay { background: linear-gradient(90deg, #ff8f1f 0%, #fff 50%, #cbdbff); }
|
#wbal .sliderdisplay { background: linear-gradient(90deg, #ff8f1f 0%, #fff 50%, #cbdbff); }
|
||||||
|
|
||||||
/* wrapper divs hidden by default */
|
/* wrapper divs hidden by default */
|
||||||
#liveview, #liveview2D, #roverstar, #pql
|
#rgbwrap, #kwrap, #wwrap, #wbal, #qcs-w, #hexw {
|
||||||
#rgbwrap, #swrap, #hwrap, #kwrap, #wwrap, #wbal, #qcs-w, #hexw,
|
|
||||||
.clear-icon, .edit-icon, .ptxt {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sliderbubble {
|
.sliderbubble {
|
||||||
width: 24px;
|
width: 24px;
|
||||||
position: absolute;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
border-radius: 16px;
|
border-radius: 10px;
|
||||||
background: var(--c-3);
|
background: var(--c-3);
|
||||||
color: var(--c-f);
|
color: var(--c-f);
|
||||||
padding: 4px;
|
padding: 2px 4px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
right: 6px;
|
right: 3px;
|
||||||
transition: visibility .25s ease,opacity .25s ease;
|
transition: visibility 0.25s ease, opacity 0.25s ease;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
/* left: 8px; */
|
|
||||||
top: 4px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.sliderbubbleshow {
|
output.sliderbubbleshow {
|
||||||
@ -760,8 +717,17 @@ input[type=range]::-moz-range-thumb {
|
|||||||
border: 2px solid var(--c-1);
|
border: 2px solid var(--c-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Slider wrapper div */
|
||||||
|
.sliderwrap {
|
||||||
|
height: 30px;
|
||||||
|
width: 230px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#Colors .sliderwrap {
|
#Colors .sliderwrap {
|
||||||
margin: 4px 0 0;
|
width: 260px;
|
||||||
|
margin: 10px 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dynamically hide brightness slider label */
|
/* Dynamically hide brightness slider label */
|
||||||
@ -770,14 +736,17 @@ input[type=range]::-moz-range-thumb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#briwrap {
|
#briwrap {
|
||||||
min-width: 267px;
|
|
||||||
float: right;
|
float: right;
|
||||||
margin-top: var(--bmt);
|
margin-top: var(--bmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#picker, #rgbwrap, #kwrap, #wwrap, #wbal, #vwrap, #qcs-w, #hexw, #pall, #ledmap {
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 260px;
|
||||||
|
}
|
||||||
|
|
||||||
#picker {
|
#picker {
|
||||||
margin-top: 8px !important;
|
margin-top: 10px;
|
||||||
max-width: 260px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* buttons */
|
/* buttons */
|
||||||
@ -794,8 +763,8 @@ input[type=range]::-moz-range-thumb {
|
|||||||
-webkit-transform:translate3d(0,0,0);
|
-webkit-transform:translate3d(0,0,0);
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
transform:translate3d(0,0,0);
|
transform:translate3d(0,0,0);
|
||||||
overflow: hidden;
|
overflow: clip;
|
||||||
text-overflow: ellipsis;
|
text-overflow: clip;
|
||||||
border: 1px solid var(--c-3);
|
border: 1px solid var(--c-3);
|
||||||
background-color: var(--c-3);
|
background-color: var(--c-3);
|
||||||
}
|
}
|
||||||
@ -826,7 +795,6 @@ input[type=range]::-moz-range-thumb {
|
|||||||
.btn-xs, .btn-pl-del, .btn-pl-add {
|
.btn-xs, .btn-pl-del, .btn-pl-add {
|
||||||
width: 42px !important;
|
width: 42px !important;
|
||||||
height: 42px !important;
|
height: 42px !important;
|
||||||
text-overflow: clip;
|
|
||||||
}
|
}
|
||||||
.btn-xs {
|
.btn-xs {
|
||||||
margin: 2px 0 0 0;
|
margin: 2px 0 0 0;
|
||||||
@ -1004,25 +972,25 @@ textarea {
|
|||||||
|
|
||||||
.ptxt {
|
.ptxt {
|
||||||
margin: -1px 4px 8px !important;
|
margin: -1px 4px 8px !important;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stxt {
|
.stxt {
|
||||||
width: 50px !important;
|
width: 50px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.segname, .pname, .bname {
|
.segname, .pname {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
cursor: pointer;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
overflow: hidden;
|
overflow: clip;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
padding: 8px 24px;
|
padding: 8px 24px;
|
||||||
max-width: 170px;
|
max-width: 170px;
|
||||||
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
.bname {
|
|
||||||
padding: 0 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.segname .flr, .pname .flr {
|
.segname .flr, .pname .flr {
|
||||||
transform: rotate(0deg);
|
transform: rotate(0deg);
|
||||||
@ -1031,10 +999,8 @@ textarea {
|
|||||||
|
|
||||||
/* segment power wrapper */
|
/* segment power wrapper */
|
||||||
.sbs {
|
.sbs {
|
||||||
/*padding: 1px 0 1px 20px;*/
|
padding: 4px 0 4px 8px;
|
||||||
display: var(--sgp);
|
display: var(--sgp);
|
||||||
width: 100%;
|
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.pname {
|
.pname {
|
||||||
@ -1076,9 +1042,11 @@ textarea {
|
|||||||
|
|
||||||
#csl .xxs {
|
#csl .xxs {
|
||||||
border: 2px solid var(--c-d) !important;
|
border: 2px solid var(--c-d) !important;
|
||||||
|
/*box-shadow: 0 0 0 2px var(--c-d);*/
|
||||||
}
|
}
|
||||||
#csl .xxs-w {
|
#csl .xxs-w {
|
||||||
border-width: 5px !important;
|
border-width: 5px !important;
|
||||||
|
/*box-shadow: 0 0 0 5px var(--c-d);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
.qcs, #namelabel { /* text shadow for name to be legible on grey backround */
|
.qcs, #namelabel { /* text shadow for name to be legible on grey backround */
|
||||||
@ -1092,6 +1060,7 @@ textarea {
|
|||||||
|
|
||||||
.pwr {
|
.pwr {
|
||||||
color: var(--c-6);
|
color: var(--c-6);
|
||||||
|
transform: translate(1px, 1px);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1106,13 +1075,18 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.frz {
|
.frz {
|
||||||
left: 10px;
|
left: 32px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 8px;
|
top: -3px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
padding: 8px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.expanded .frz {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* radiobuttons and checkmarks */
|
/* radiobuttons and checkmarks */
|
||||||
.check, .radio {
|
.check, .radio {
|
||||||
display: block;
|
display: block;
|
||||||
@ -1211,7 +1185,7 @@ TD .checkmark, TD .radiomark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bp {
|
.bp {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* segment & preset wrapper */
|
/* segment & preset wrapper */
|
||||||
@ -1221,7 +1195,10 @@ TD .checkmark, TD .radiomark {
|
|||||||
border: 0px solid var(--c-f);
|
border: 0px solid var(--c-f);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
transition: background-color 0.5s;
|
transition: background-color 0.5s;
|
||||||
|
/*filter: brightness(1);*/
|
||||||
|
font-size: 19px;
|
||||||
border-radius: 21px;
|
border-radius: 21px;
|
||||||
|
/*min-width: 264px;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
.seg {
|
.seg {
|
||||||
@ -1254,6 +1231,7 @@ TD .checkmark, TD .radiomark {
|
|||||||
|
|
||||||
.lbl-s {
|
.lbl-s {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
/* margin: 10px 4px 0 0; */
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
width: 48%;
|
width: 48%;
|
||||||
@ -1263,8 +1241,10 @@ TD .checkmark, TD .radiomark {
|
|||||||
/* list wrapper */
|
/* list wrapper */
|
||||||
.list {
|
.list {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 280px;
|
||||||
transition: background-color 0.5s;
|
transition: background-color 0.5s;
|
||||||
margin: auto auto 10px;
|
margin: auto auto 20px;
|
||||||
|
font-size: 19px;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1274,7 +1254,6 @@ TD .checkmark, TD .radiomark {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: var(--c-2);
|
background-color: var(--c-2);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: -webkit-sticky;
|
|
||||||
position: sticky;
|
position: sticky;
|
||||||
border-radius: 21px;
|
border-radius: 21px;
|
||||||
margin: 13px auto 0;
|
margin: 13px auto 0;
|
||||||
@ -1303,11 +1282,14 @@ TD .checkmark, TD .radiomark {
|
|||||||
background-color: var(--c-3);
|
background-color: var(--c-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*.selected .radiomark {
|
||||||
|
border: 1px solid var(--c-3);
|
||||||
|
}*/
|
||||||
|
|
||||||
/* selected list item */
|
/* selected list item */
|
||||||
.lstI.selected {
|
.lstI.selected {
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
border: 1px solid var(--c-4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.lstI.sticky,
|
.lstI.sticky,
|
||||||
@ -1363,6 +1345,8 @@ TD .checkmark, TD .radiomark {
|
|||||||
|
|
||||||
/* find/search element */
|
/* find/search element */
|
||||||
.fnd {
|
.fnd {
|
||||||
|
width: 280px;
|
||||||
|
margin: 0 auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1394,6 +1378,7 @@ TD .checkmark, TD .radiomark {
|
|||||||
.presin {
|
.presin {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 264px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-s,
|
.btn-s,
|
||||||
@ -1420,9 +1405,6 @@ TD .checkmark, TD .radiomark {
|
|||||||
.expanded {
|
.expanded {
|
||||||
display: inline-block !important;
|
display: inline-block !important;
|
||||||
}
|
}
|
||||||
.hide, .expanded .segin.hide, .expanded .presin.hide, .expanded .sbs.hide, .expanded .frz, .expanded .g-icon {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.m6 {
|
.m6 {
|
||||||
margin: 6px 0;
|
margin: 6px 0;
|
||||||
@ -1471,16 +1453,6 @@ TD .checkmark, TD .radiomark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media all and (max-width: 1023px) {
|
|
||||||
.top button {
|
|
||||||
width: 8%;
|
|
||||||
padding: 10px 0 8px 0;
|
|
||||||
}
|
|
||||||
#buttonPcm {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media all and (max-width: 335px) {
|
@media all and (max-width: 335px) {
|
||||||
.sliderbubble {
|
.sliderbubble {
|
||||||
display: none;
|
display: none;
|
||||||
@ -1499,83 +1471,38 @@ TD .checkmark, TD .radiomark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media all and (max-width: 420px) {
|
@media all and (max-width: 540px) {
|
||||||
#buttonNodes {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media all and (max-width: 639px) {
|
|
||||||
.top button {
|
.top button {
|
||||||
width: 16.6%;
|
width: 16.6%;
|
||||||
padding: 8px 0 4px 0;
|
padding: 8px 0 4px 0;
|
||||||
}
|
}
|
||||||
#briwrap {
|
|
||||||
margin: 0 auto !important;
|
|
||||||
float: none;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.hd {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media all and (min-width: 420px) and (max-width: 639px) {
|
@media all and (min-width: 541px) and (max-width: 719px) {
|
||||||
.top button {
|
.top button {
|
||||||
width: 14.28%;
|
width: 14.2%;
|
||||||
padding: 8px 0 4px 0;
|
padding: 8px 0 4px 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media all and (min-width: 640px) and (max-width: 767px) {
|
@media all and (max-width: 719px) {
|
||||||
|
.hd {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
#briwrap {
|
||||||
|
margin-top: 0px !important;
|
||||||
|
float: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and (max-width: 798px) {
|
||||||
#buttonNodes {
|
#buttonNodes {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* small screen & tablet "PC mode" support */
|
@media all and (max-width: 1249px) {
|
||||||
@media all and (min-width: 1024px) and (max-width: 1249px) {
|
#buttonPcm {
|
||||||
#segutil, #segutil2, #segcont, #putil, #pcont, #pql, #fx, #palw, #psFind, #sliders {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 280px;
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
#picker {
|
|
||||||
width: 230px;
|
|
||||||
}
|
|
||||||
#putil .btn-s {
|
|
||||||
width: 114px;
|
|
||||||
}
|
|
||||||
#sliders .sliderbubble {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
#sliders .sliderwrap, .sbs .sliderwrap {
|
|
||||||
width: calc(100% - 42px);
|
|
||||||
}
|
|
||||||
#sliders .slider {
|
|
||||||
padding-right: 0;
|
|
||||||
}
|
|
||||||
#sliders .sliderwrap {
|
|
||||||
left: 12px;
|
|
||||||
}
|
|
||||||
.segname {
|
|
||||||
max-width: calc(100% - 110px);
|
|
||||||
}
|
|
||||||
.segt TD {
|
|
||||||
padding: 0 !important;
|
|
||||||
}
|
|
||||||
input[type="number"], input[type=text], select, textarea {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
input[type="number"] {
|
|
||||||
width: 32px;
|
|
||||||
}
|
|
||||||
.lstIcontent {
|
|
||||||
padding-left: 8px;
|
|
||||||
}
|
|
||||||
.revchkl {
|
|
||||||
max-width: 183px;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow-x: clip;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -67,13 +67,13 @@
|
|||||||
<button id="buttonSr" onclick="toggleLiveview()"><i class="icons"></i><p class="tab-label">Peek</p></button>
|
<button id="buttonSr" onclick="toggleLiveview()"><i class="icons"></i><p class="tab-label">Peek</p></button>
|
||||||
<button id="buttonI" onclick="toggleInfo()"><i class="icons"></i><p class="tab-label">Info</p></button>
|
<button id="buttonI" onclick="toggleInfo()"><i class="icons"></i><p class="tab-label">Info</p></button>
|
||||||
<button id="buttonNodes" onclick="toggleNodes()"><i class="icons"></i><p class="tab-label">Nodes</p></button>
|
<button id="buttonNodes" onclick="toggleNodes()"><i class="icons"></i><p class="tab-label">Nodes</p></button>
|
||||||
<button onclick="window.location.href=getURL('/settings');"><i class="icons"></i><p class="tab-label">Config</p></button>
|
<button onclick="window.location.href='/settings';"><i class="icons"></i><p class="tab-label">Config</p></button>
|
||||||
<button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons"></i><p class="tab-label">PC Mode</p></button>
|
<button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons"></i><p class="tab-label">PC Mode</p></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="briwrap">
|
<div id="briwrap">
|
||||||
<p class="hd">Brightness</p>
|
<p class="hd">Brightness</p>
|
||||||
<div class="slider" style="padding-right:32px;">
|
<div class="il">
|
||||||
<i class="icons slider-icon" onclick="tglTheme()" style="transform: translate(-32px,5px);"></i>
|
<i class="icons slider-icon" onclick="tglTheme()"></i>
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderBri" onchange="setBri()" oninput="updateTrail(this)" max="255" min="1" type="range" value="128" />
|
<input id="sliderBri" onchange="setBri()" oninput="updateTrail(this)" max="255" min="1" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
@ -88,73 +88,68 @@
|
|||||||
<div class ="container">
|
<div class ="container">
|
||||||
<div id="Colors" class="tabcontent">
|
<div id="Colors" class="tabcontent">
|
||||||
<div id="picker" class="noslide"></div>
|
<div id="picker" class="noslide"></div>
|
||||||
<div id="hwrap" class="slider" style="margin-top: 20px;">
|
<div id="hwrap">
|
||||||
|
<!--p class="labels hd">Hue</p-->
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderH" class="noslide" oninput="fromH()" onchange="setColor(0)" max="359" min="0" type="range" value="0" step="any">
|
<input id="sliderH" class="noslide" oninput="fromH()" onchange="setColor(0)" max="359" min="0" type="range" value="0" step="any">
|
||||||
<div class="sliderdisplay" style="background: linear-gradient(90deg, #f00 2%, #ff0 19%, #0f0 35%, #0ff 52%, #00f 68%, #f0f 85%, #f00)"></div>
|
<div class="sliderdisplay" style="background: linear-gradient(90deg, #f00 2%, #ff0 19%, #0f0 35%, #0ff 52%, #00f 68%, #f0f 85%, #f00)"></div>
|
||||||
|
</div><br>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Hue</span>
|
<div id="swrap">
|
||||||
</div>
|
<!--p class="labels hd">Saturation</p-->
|
||||||
<div id="swrap" class="slider">
|
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderS" class="noslide" oninput="fromS()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any">
|
<input id="sliderS" class="noslide" oninput="fromS()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any">
|
||||||
<div class="sliderdisplay" style="background: linear-gradient(90deg, #aaa 0%, #f00)"></div>
|
<div class="sliderdisplay" style="background: linear-gradient(90deg, #aaa 0%, #f00)"></div>
|
||||||
|
</div><br>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Saturation</span>
|
<div id="vwrap">
|
||||||
</div>
|
<!--p class="labels hd">Value</p-->
|
||||||
<div id="vwrap" class="slider">
|
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderV" class="noslide" oninput="fromV()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any" />
|
<input id="sliderV" class="noslide" oninput="fromV()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
|
</div><br>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Value/Brightness</span>
|
<div id="kwrap">
|
||||||
</div>
|
<!--p class="labels hd">Temperature</p-->
|
||||||
<div id="kwrap" class="slider">
|
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderK" class="noslide" oninput="fromK()" onchange="setColor(0)" max="10091" min="1900" type="range" value="6550" />
|
<input id="sliderK" class="noslide" oninput="fromK()" onchange="setColor(0)" max="10091" min="1900" type="range" value="6550" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Kelvin/Temperature</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="rgbwrap">
|
<div id="rgbwrap">
|
||||||
<!--p class="labels hd">RGB color</p-->
|
<p class="labels hd">RGB color</p>
|
||||||
<div id="rwrap" class="slider">
|
<div id="rwrap" class="il">
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderR" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
<input id="sliderR" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Red channel</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="gwrap" class="slider">
|
<div id="gwrap" class="il">
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderG" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
<input id="sliderG" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Green channel</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="bwrap" class="slider">
|
<div id="bwrap" class="il">
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderB" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
<input id="sliderB" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">Blue channel</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="wwrap" class="slider">
|
<div id="wwrap">
|
||||||
<!--p class="labels hd">White channel</p-->
|
<p class="labels hd">White channel</p>
|
||||||
<div id="whibri" class="sliderwrap il">
|
<div id="whibri" class="sliderwrap il">
|
||||||
<input id="sliderW" class="noslide" oninput="fromW()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
<input id="sliderW" class="noslide" oninput="fromW()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">White channel</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="wbal" class="slider">
|
<div id="wbal">
|
||||||
<!--p class="labels hd">White balance</p-->
|
<p class="labels hd">White balance</p>
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderA" class="noslide" onchange="setBalance(this.value)" max="255" min="0" type="range" value="128" />
|
<input id="sliderA" class="noslide" onchange="setBalance(this.value)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
</div>
|
</div>
|
||||||
<span class="tooltiptext">White balance</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="qcs-w">
|
<div id="qcs-w">
|
||||||
<div class="qcs" onclick="pC('#ff0000');" title="Red" style="background-color:#ff0000;"></div>
|
<div class="qcs" onclick="pC('#ff0000');" title="Red" style="background-color:#ff0000;"></div>
|
||||||
@ -198,10 +193,6 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding-bottom: 10px;">
|
|
||||||
<button class="btn btn-xs" type="button" onclick="window.location.href=getURL('/cpal.htm')"><i class="icons btn-icon"></i></button>
|
|
||||||
<button class="btn btn-xs" type="button" onclick="palettesData=null;localStorage.removeItem('wledPalx');requestJson({rmcpal:true});setTimeout(loadPalettes,250,loadPalettesData);"><i class="icons btn-icon"></i></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -231,10 +222,6 @@
|
|||||||
<input type="checkbox" data-flt="🎨" onchange="filterFx(this)">
|
<input type="checkbox" data-flt="🎨" onchange="filterFx(this)">
|
||||||
<span class="checkmark"></span>
|
<span class="checkmark"></span>
|
||||||
</label>
|
</label>
|
||||||
<label id="filter0D" class="check fchkl hide">•
|
|
||||||
<input type="checkbox" data-flt="•" onchange="filterFx(this)">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
<label id="filter1D" class="check fchkl">⋮
|
<label id="filter1D" class="check fchkl">⋮
|
||||||
<input type="checkbox" data-flt="⋮" onchange="filterFx(this)">
|
<input type="checkbox" data-flt="⋮" onchange="filterFx(this)">
|
||||||
<span class="checkmark"></span>
|
<span class="checkmark"></span>
|
||||||
@ -253,7 +240,7 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="slider0" class="slider">
|
<div id="slider0" class="slider">
|
||||||
<i class="icons slider-icon" onclick="tglFreeze()"></i>
|
<i class="icons slider-icon" style="cursor: pointer;" onclick="tglFreeze()"></i>
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderSpeed" class="noslide" onchange="setSpeed()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
|
<input id="sliderSpeed" class="noslide" onchange="setSpeed()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
@ -262,7 +249,7 @@
|
|||||||
<span id="sliderLabel0" class="tooltiptext">Effect speed</span>
|
<span id="sliderLabel0" class="tooltiptext">Effect speed</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="slider1" class="slider">
|
<div id="slider1" class="slider">
|
||||||
<i class="icons slider-icon" onclick="tglLabels()"></i>
|
<i class="icons slider-icon" style="cursor: pointer;" onclick="tglLabels()"></i>
|
||||||
<div class="sliderwrap il">
|
<div class="sliderwrap il">
|
||||||
<input id="sliderIntensity" class="noslide" onchange="setIntensity()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
|
<input id="sliderIntensity" class="noslide" onchange="setIntensity()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
|
||||||
<div class="sliderdisplay"></div>
|
<div class="sliderdisplay"></div>
|
||||||
@ -323,7 +310,7 @@
|
|||||||
<div id="segutil2">
|
<div id="segutil2">
|
||||||
<button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button>
|
<button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button>
|
||||||
</div>
|
</div>
|
||||||
<p>Transition: <input id="tt" type="number" min="0" max="65.5" step="0.1" value="0.7"> s</p>
|
<p>Transition: <input id="tt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7"> s</p>
|
||||||
<p id="ledmap" class="hide"></p>
|
<p id="ledmap" class="hide"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -363,7 +350,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<button class="btn infobtn" onclick="requestJson()">Refresh</button>
|
<button class="btn infobtn" onclick="requestJson()">Refresh</button>
|
||||||
<button class="btn infobtn" onclick="toggleNodes()">Instance List</button>
|
<button class="btn infobtn" onclick="toggleNodes()">Instance List</button>
|
||||||
<button class="btn infobtn" onclick="window.open(getURL('/update'),'_self');">Update WLED</button>
|
<button class="btn infobtn" onclick="window.open('/update','_self');">Update WLED</button>
|
||||||
<button class="btn infobtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>
|
<button class="btn infobtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
@ -379,8 +366,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="mlv2D" class="modal">
|
<div id="mliveview2D" class="modal">
|
||||||
<div id="klv2D" style="width:100%; height:100%">Loading...</div>
|
<div id="kliveview2D" style="width:100%; height:100%">Loading...</div><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="rover" class="modal">
|
<div id="rover" class="modal">
|
||||||
|
@ -17,17 +17,21 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="canv" />
|
||||||
<script>
|
<script>
|
||||||
var ws;
|
update();
|
||||||
|
|
||||||
var tmout = null;
|
var tmout = null;
|
||||||
function update() // via HTTP (/json/live)
|
function update()
|
||||||
{
|
{
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
clearTimeout(tmout);
|
clearTimeout(tmout);
|
||||||
tmout = setTimeout(update, 250);
|
tmout = setTimeout(update, 250);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch('./json/live')
|
fetch('/json/live')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
clearTimeout(tmout);
|
clearTimeout(tmout);
|
||||||
@ -53,57 +57,8 @@
|
|||||||
clearTimeout(tmout);
|
clearTimeout(tmout);
|
||||||
tmout = setTimeout(update, 2500);
|
tmout = setTimeout(update, 2500);
|
||||||
})
|
})
|
||||||
}
|
|
||||||
function S() { // Startup function (onload)
|
|
||||||
let wsOn = (window.location.href.indexOf("?ws") > 0);
|
|
||||||
if (!wsOn) {update(); return;}
|
|
||||||
|
|
||||||
// Initialize WebSocket connection
|
|
||||||
try {
|
|
||||||
ws = top.window.ws;
|
|
||||||
} catch (e) {}
|
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
||||||
//console.info("Peek uses top WS");
|
|
||||||
ws.send("{'lv':true}");
|
|
||||||
} else {
|
|
||||||
//console.info("Peek WS opening");
|
|
||||||
let l = window.location;
|
|
||||||
let pathn = l.pathname;
|
|
||||||
let paths = pathn.slice(1,pathn.endsWith('/')?-1:undefined).split("/");
|
|
||||||
let url = l.origin.replace("http","ws");
|
|
||||||
if (paths.length > 1) {
|
|
||||||
url += "/" + paths[0];
|
|
||||||
}
|
|
||||||
ws = new WebSocket(url+"/ws");
|
|
||||||
ws.onopen = function () {
|
|
||||||
//console.info("Peek WS open");
|
|
||||||
ws.send("{'lv':true}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws.binaryType = "arraybuffer";
|
|
||||||
ws.addEventListener('message', (e) => {
|
|
||||||
try {
|
|
||||||
if (toString.call(e.data) === '[object ArrayBuffer]') {
|
|
||||||
let leds = new Uint8Array(event.data);
|
|
||||||
if (leds[0] != 76) return; //'L'
|
|
||||||
let str = "linear-gradient(90deg,";
|
|
||||||
let len = leds.length;
|
|
||||||
let start = leds[1]==2 ? 4 : 2; // 1 = 1D, 2 = 1D/2D (leds[2]=w, leds[3]=h)
|
|
||||||
for (i = start; i < len; i+=3) {
|
|
||||||
str += `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`;
|
|
||||||
if (i < len -3) str += ","
|
|
||||||
}
|
|
||||||
str += ")";
|
|
||||||
document.getElementById("canv").style.background = str;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Peek WS error:",err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
|
||||||
<body onload="S()">
|
|
||||||
<div id="canv"></div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
61
wled00/data/liveviewws.htm
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="theme-color" content="#222222">
|
||||||
|
<title>WLED Live Preview</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
#canv {
|
||||||
|
background: black;
|
||||||
|
filter: brightness(175%);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="canv"></div>
|
||||||
|
<script>
|
||||||
|
var ws;
|
||||||
|
try {
|
||||||
|
ws = top.window.ws;
|
||||||
|
} catch (e) {}
|
||||||
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
|
//console.info("Peek uses top WS");
|
||||||
|
ws.send("{'lv':true}");
|
||||||
|
} else {
|
||||||
|
console.info("Peek WS opening");
|
||||||
|
ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws");
|
||||||
|
ws.onopen = function () {
|
||||||
|
//console.info("Peek WS open");
|
||||||
|
ws.send("{'lv':true}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws.binaryType = "arraybuffer";
|
||||||
|
ws.addEventListener('message', (e) => {
|
||||||
|
try {
|
||||||
|
if (toString.call(e.data) === '[object ArrayBuffer]') {
|
||||||
|
let leds = new Uint8Array(event.data);
|
||||||
|
if (leds[0] != 76) return; //'L'
|
||||||
|
let str = "linear-gradient(90deg,";
|
||||||
|
let len = leds.length;
|
||||||
|
let start = leds[1]==2 ? 4 : 2; // 1 = 1D, 2 = 1D/2D (leds[2]=w, leds[3]=h)
|
||||||
|
for (i = start; i < len; i+=3) {
|
||||||
|
str += `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`;
|
||||||
|
if (i < len -3) str += ","
|
||||||
|
}
|
||||||
|
str += ")";
|
||||||
|
document.getElementById("canv").style.background = str;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Peek WS error:",err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -33,14 +33,7 @@
|
|||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
ws.send("{'lv':true}");
|
ws.send("{'lv':true}");
|
||||||
} else {
|
} else {
|
||||||
let l = window.location;
|
ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws");
|
||||||
let pathn = l.pathname;
|
|
||||||
let paths = pathn.slice(1,pathn.endsWith('/')?-1:undefined).split("/");
|
|
||||||
let url = l.origin.replace("http","ws");
|
|
||||||
if (paths.length > 1) {
|
|
||||||
url += "/" + paths[0];
|
|
||||||
}
|
|
||||||
ws = new WebSocket(url+"/ws");
|
|
||||||
ws.onopen = ()=>{
|
ws.onopen = ()=>{
|
||||||
ws.send("{'lv':true}");
|
ws.send("{'lv':true}");
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<title>WLED Message</title>
|
<title>WLED Message</title>
|
||||||
<script>
|
<script>
|
||||||
function B() { window.history.back() };
|
function B() { window.history.back() };
|
||||||
function RS() { window.location = "../settings"; }
|
function RS() { window.location = "/settings"; }
|
||||||
function RP() { top.location.href = "../"; }
|
function RP() { top.location.href = "/"; }
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
@import url("style.css");
|
@import url("style.css");
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
function drawBoxes(inputPixelArray, widthPixels, heightPixels) {
|
|
||||||
|
|
||||||
var w = window;
|
|
||||||
|
|
||||||
// Get the canvas context
|
|
||||||
var ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
||||||
|
|
||||||
// Set the width and height of the canvas
|
|
||||||
if (w.innerHeight < w.innerWidth) {
|
|
||||||
canvas.width = Math.floor(w.innerHeight * 0.98);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
canvas.width = Math.floor(w.innerWidth * 0.98);
|
|
||||||
}
|
|
||||||
//canvas.height = w.innerWidth;
|
|
||||||
|
|
||||||
let pixelSize = Math.floor(canvas.width/widthPixels);
|
|
||||||
|
|
||||||
let xOffset = (w.innerWidth - (widthPixels * pixelSize))/2
|
|
||||||
|
|
||||||
//Set the canvas height to fit the right number of pixelrows
|
|
||||||
canvas.height = (pixelSize * heightPixels) + 10
|
|
||||||
|
|
||||||
//Iterate through the matrix
|
|
||||||
for (let y = 0; y < heightPixels; y++) {
|
|
||||||
for (let x = 0; x < widthPixels; x++) {
|
|
||||||
|
|
||||||
// Calculate the index of the current pixel
|
|
||||||
let i = (y*widthPixels) + x;
|
|
||||||
|
|
||||||
//Gets the RGB of the current pixel
|
|
||||||
let pixel = inputPixelArray[i];
|
|
||||||
|
|
||||||
let pixelColor = 'rgb(' + pixel[0] + ', ' + pixel[1] + ', ' + pixel[2] + ')';
|
|
||||||
|
|
||||||
let textColor = 'rgb(128,128,128)';
|
|
||||||
|
|
||||||
// Set the fill style to the pixel color
|
|
||||||
ctx.fillStyle = pixelColor;
|
|
||||||
|
|
||||||
//Draw the rectangle
|
|
||||||
ctx.fillRect(x * pixelSize, y * pixelSize, pixelSize, pixelSize);
|
|
||||||
|
|
||||||
// Draw a border on the box
|
|
||||||
ctx.strokeStyle = '#888888';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.strokeRect(x * pixelSize, y * pixelSize, pixelSize, pixelSize);
|
|
||||||
|
|
||||||
//Write text to box
|
|
||||||
ctx.font = "10px Arial";
|
|
||||||
ctx.fillStyle = textColor;
|
|
||||||
ctx.textAlign = "center";
|
|
||||||
ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillText((pixel[4] + 1), (x * pixelSize) + (pixelSize /2), (y * pixelSize) + (pixelSize /2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
canvas.width = w.innerWidth;
|
|
||||||
ctx.putImageData(imageData, xOffset, 0);
|
|
||||||
}
|
|
||||||
|
|
Before Width: | Height: | Size: 649 B |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 15 KiB |
@ -1,320 +0,0 @@
|
|||||||
function getPixelRGBValues(base64Image) {
|
|
||||||
httpArray = [];
|
|
||||||
fileJSON = `{"on":true,"bri":${brgh.value},"seg":{"id":${tSg.value},"i":[`;
|
|
||||||
|
|
||||||
//Which object holds the secret to the segment ID
|
|
||||||
|
|
||||||
let segID = 0;
|
|
||||||
if(tSg.style.display == "flex"){
|
|
||||||
segID = tSg.value
|
|
||||||
} else {
|
|
||||||
segID = sID.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//const copyJSONledbutton = gId('copyJSONledbutton');
|
|
||||||
const maxNoOfColorsInCommandSting = parseInt(cLN.value);
|
|
||||||
|
|
||||||
let hybridAddressing = false;
|
|
||||||
let selectedIndex = -1;
|
|
||||||
|
|
||||||
selectedIndex = frm.selectedIndex;
|
|
||||||
const formatSelection = frm.options[selectedIndex].value;
|
|
||||||
|
|
||||||
|
|
||||||
selectedIndex = lSS.selectedIndex;
|
|
||||||
const ledSetupSelection = lSS.options[selectedIndex].value;
|
|
||||||
|
|
||||||
selectedIndex = cFS.selectedIndex;
|
|
||||||
let hexValueCheck = true;
|
|
||||||
if (cFS.options[selectedIndex].value == 'dec'){
|
|
||||||
hexValueCheck = false
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedIndex = aS.selectedIndex;
|
|
||||||
let segmentValueCheck = true; //If Range or Hybrid
|
|
||||||
if (aS.options[selectedIndex].value == 'single'){
|
|
||||||
segmentValueCheck = false
|
|
||||||
} else if (aS.options[selectedIndex].value == 'hybrid'){
|
|
||||||
hybridAddressing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let curlString = ''
|
|
||||||
let haString = ''
|
|
||||||
|
|
||||||
let colorSeparatorStart = '"';
|
|
||||||
let colorSeparatorEnd = '"';
|
|
||||||
if (!hexValueCheck){
|
|
||||||
colorSeparatorStart = '[';
|
|
||||||
colorSeparatorEnd = ']';
|
|
||||||
}
|
|
||||||
// Warnings
|
|
||||||
let hasTransparency = false; //If alpha < 255 is detected on any pixel, this is set to true in code below
|
|
||||||
let imageInfo = '';
|
|
||||||
|
|
||||||
// Create an off-screen canvas
|
|
||||||
var canvas = cE('canvas');
|
|
||||||
var context = canvas.getContext('2d', { willReadFrequently: true });
|
|
||||||
|
|
||||||
// Create an image element and set its src to the base64 image
|
|
||||||
var image = new Image();
|
|
||||||
image.src = base64Image;
|
|
||||||
|
|
||||||
// Wait for the image to load before drawing it onto the canvas
|
|
||||||
image.onload = function() {
|
|
||||||
|
|
||||||
let scalePath = scDiv.children[0].children[0];
|
|
||||||
let color = scalePath.getAttribute("fill");
|
|
||||||
let sizeX = szX.value;
|
|
||||||
let sizeY = szY.value;
|
|
||||||
|
|
||||||
if (color != accentColor || sizeX < 1 || sizeY < 1){
|
|
||||||
//image will not be rezised Set desitred size to original size
|
|
||||||
sizeX = image.width;
|
|
||||||
sizeY = image.height;
|
|
||||||
//failsafe for not generating huge images automatically
|
|
||||||
if (image.width > 512 || image.height > 512)
|
|
||||||
{
|
|
||||||
sizeX = 16;
|
|
||||||
sizeY = 16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the canvas size to the same as the desired image size
|
|
||||||
canvas.width = sizeX;
|
|
||||||
canvas.height = sizeY;
|
|
||||||
|
|
||||||
imageInfo = '<p>Width: ' + sizeX + ', Height: ' + sizeY + ' (make sure this matches your led matrix setup)</p>'
|
|
||||||
|
|
||||||
// Draw the image onto the canvas
|
|
||||||
context.drawImage(image, 0, 0, sizeX, sizeY);
|
|
||||||
|
|
||||||
// Get the pixel data from the canvas
|
|
||||||
var pixelData = context.getImageData(0, 0, sizeX, sizeY).data;
|
|
||||||
|
|
||||||
// Create an array to hold the RGB values of each pixel
|
|
||||||
var pixelRGBValues = [];
|
|
||||||
|
|
||||||
// If the first row of the led matrix is right -> left
|
|
||||||
let right2leftAdjust = 1;
|
|
||||||
|
|
||||||
if (ledSetupSelection == 'l2r'){
|
|
||||||
right2leftAdjust = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through the pixel data and get the RGB values of each pixel
|
|
||||||
for (var i = 0; i < pixelData.length; i += 4) {
|
|
||||||
var r = pixelData[i];
|
|
||||||
var g = pixelData[i + 1];
|
|
||||||
var b = pixelData[i + 2];
|
|
||||||
var a = pixelData[i + 3];
|
|
||||||
|
|
||||||
let pixel = i/4
|
|
||||||
let row = Math.floor(pixel/sizeX);
|
|
||||||
let led = pixel;
|
|
||||||
if (ledSetupSelection == 'matrix'){
|
|
||||||
//Do nothing, the matrix is set upp like the index in the image
|
|
||||||
//Every row starts from the left, i.e. no zigzagging
|
|
||||||
}
|
|
||||||
else if ((row + right2leftAdjust) % 2 === 0) {
|
|
||||||
//Setup is traditional zigzag
|
|
||||||
//right2leftAdjust basically flips the row order if = 1
|
|
||||||
//Row is left to right
|
|
||||||
//Leave led index as pixel index
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//Setup is traditional zigzag
|
|
||||||
//Row is right to left
|
|
||||||
//Invert index of row for led
|
|
||||||
let indexOnRow = led - (row * sizeX);
|
|
||||||
let maxIndexOnRow = sizeX - 1;
|
|
||||||
let reversedIndexOnRow = maxIndexOnRow - indexOnRow;
|
|
||||||
led = (row * sizeX) + reversedIndexOnRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the RGB values to the pixel RGB values array
|
|
||||||
pixelRGBValues.push([r, g, b, a, led, pixel, row]);
|
|
||||||
}
|
|
||||||
|
|
||||||
pixelRGBValues.sort((a, b) => a[5] - b[5]);
|
|
||||||
|
|
||||||
//Copy the values to a new array for resorting
|
|
||||||
let ledRGBValues = [... pixelRGBValues];
|
|
||||||
|
|
||||||
//Sort the array based on led index
|
|
||||||
ledRGBValues.sort((a, b) => a[4] - b[4]);
|
|
||||||
|
|
||||||
//Generate JSON in WLED format
|
|
||||||
let JSONledString = '';
|
|
||||||
|
|
||||||
//Set starting values for the segment check to something that is no color
|
|
||||||
let segmentStart = -1;
|
|
||||||
let maxi = ledRGBValues.length;
|
|
||||||
let curentColorIndex = 0
|
|
||||||
let commandArray = [];
|
|
||||||
|
|
||||||
//For evry pixel in the LED array
|
|
||||||
for (let i = 0; i < maxi; i++) {
|
|
||||||
let pixel = ledRGBValues[i];
|
|
||||||
let r = pixel[0];
|
|
||||||
let g = pixel[1];
|
|
||||||
let b = pixel[2];
|
|
||||||
let a = pixel[3];
|
|
||||||
let segmentString = '';
|
|
||||||
let segmentEnd = -1;
|
|
||||||
|
|
||||||
if(segmentValueCheck){
|
|
||||||
if (segmentStart < 0){
|
|
||||||
//This is the first led of a new segment
|
|
||||||
segmentStart = i;
|
|
||||||
} //Else we allready have a start index
|
|
||||||
|
|
||||||
if (i < maxi - 1){
|
|
||||||
|
|
||||||
let iNext = i + 1;
|
|
||||||
let nextPixel = ledRGBValues[iNext];
|
|
||||||
|
|
||||||
if (nextPixel[0] != r || nextPixel[1] != g || nextPixel[2] != b ){
|
|
||||||
//Next pixel has new color
|
|
||||||
//The current segment ends with this pixel
|
|
||||||
segmentEnd = i + 1 //WLED wants the NEXT LED as the stop led...
|
|
||||||
if (segmentStart == i && hybridAddressing){
|
|
||||||
//If only one led/pixel, no segment info needed
|
|
||||||
if (JSONledString == ''){
|
|
||||||
//If addressing is single, we need to start every command with a starting possition
|
|
||||||
segmentString = '' + i + ',';
|
|
||||||
//Fixed to b2
|
|
||||||
} else{
|
|
||||||
segmentString = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
segmentString = segmentStart + ',' + segmentEnd + ',';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//This is the last pixel, so the segment must end
|
|
||||||
segmentEnd = i + 1;
|
|
||||||
|
|
||||||
if (segmentStart + 1 == segmentEnd && hybridAddressing){
|
|
||||||
//If only one led/pixel, no segment info needed
|
|
||||||
if (JSONledString == ''){
|
|
||||||
//If addressing is single, we need to start every command with a starting possition
|
|
||||||
segmentString = '' + i + ',';
|
|
||||||
//Fixed to b2
|
|
||||||
} else{
|
|
||||||
segmentString = ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
segmentString = segmentStart + ',' + segmentEnd + ',';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
//Write every pixel
|
|
||||||
if (JSONledString == ''){
|
|
||||||
//If addressing is single, we need to start every command with a starting possition
|
|
||||||
JSONledString = i
|
|
||||||
//Fixed to b2
|
|
||||||
}
|
|
||||||
|
|
||||||
segmentStart = i
|
|
||||||
segmentEnd = i
|
|
||||||
//Segment string should be empty for when addressing single. So no need to set it again.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a < 255){
|
|
||||||
hasTransparency = true; //If ANY pixel has alpha < 255 then this is set to true to warn the user
|
|
||||||
}
|
|
||||||
|
|
||||||
if (segmentEnd > -1){
|
|
||||||
//This is the last pixel in the segment, write to the JSONledString
|
|
||||||
//Return color value in selected format
|
|
||||||
let colorValueString = r + ',' + g + ',' + b ;
|
|
||||||
|
|
||||||
if (hexValueCheck){
|
|
||||||
const [red, green, blue] = [r, g, b];
|
|
||||||
colorValueString = `${[red, green, blue].map(x => x.toString(16).padStart(2, '0')).join('')}`;
|
|
||||||
} else{
|
|
||||||
//do nothing, allready set
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if start and end is the same, in which case remove
|
|
||||||
|
|
||||||
JSONledString += segmentString + colorSeparatorStart + colorValueString + colorSeparatorEnd;
|
|
||||||
fileJSON = JSONledString + segmentString + colorSeparatorStart + colorValueString + colorSeparatorEnd;
|
|
||||||
|
|
||||||
curentColorIndex = curentColorIndex + 1; // We've just added a new color to the string so up the count with one
|
|
||||||
|
|
||||||
if (curentColorIndex % maxNoOfColorsInCommandSting === 0 || i == maxi - 1) {
|
|
||||||
|
|
||||||
//If we have accumulated the max number of colors to send in a single command or if this is the last pixel, we should write the current colorstring to the array
|
|
||||||
commandArray.push(JSONledString);
|
|
||||||
JSONledString = ''; //Start on an new command string
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
//Add a comma to continue the command string
|
|
||||||
JSONledString = JSONledString + ','
|
|
||||||
}
|
|
||||||
//Reset segment values
|
|
||||||
segmentStart = - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONledString = ''
|
|
||||||
|
|
||||||
//For every commandString in the array
|
|
||||||
for (let i = 0; i < commandArray.length; i++) {
|
|
||||||
let thisJSONledString = `{"on":true,"bri":${brgh.value},"seg":{"id":${segID},"i":[${commandArray[i]}]}}`;
|
|
||||||
httpArray.push(thisJSONledString);
|
|
||||||
|
|
||||||
let thiscurlString = `curl -X POST "http://${gurl.value}/json/state" -d \'${thisJSONledString}\' -H "Content-Type: application/json"`;
|
|
||||||
|
|
||||||
//Aggregated Strings That should be returned to the user
|
|
||||||
if (i > 0){
|
|
||||||
JSONledString = JSONledString + '\n<NEXT COMMAND (multiple commands not supported in API/preset setup)>\n';
|
|
||||||
curlString = curlString + ' && ';
|
|
||||||
}
|
|
||||||
JSONledString += thisJSONledString;
|
|
||||||
curlString += thiscurlString;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
haString = `#Uncomment if you don\'t allready have these defined in your switch section of your configuration.yaml
|
|
||||||
#- platform: command_line
|
|
||||||
#switches:
|
|
||||||
${haIDe.value}
|
|
||||||
friendly_name: ${haNe.value}
|
|
||||||
unique_id: ${haUe.value}
|
|
||||||
command_on: >
|
|
||||||
${curlString}
|
|
||||||
command_off: >
|
|
||||||
curl -X POST "http://${gurl.value}/json/state" -d \'{"on":false}\' -H "Content-Type: application/json"`;
|
|
||||||
|
|
||||||
if (formatSelection == 'wled'){
|
|
||||||
JLD.value = JSONledString;
|
|
||||||
} else if (formatSelection == 'curl'){
|
|
||||||
JLD.value = curlString;
|
|
||||||
} else if (formatSelection == 'ha'){
|
|
||||||
JLD.value = haString;
|
|
||||||
} else {
|
|
||||||
JLD.value = 'ERROR!/n' + formatSelection + ' is an unknown format.'
|
|
||||||
}
|
|
||||||
|
|
||||||
fileJSON += ']}}';
|
|
||||||
|
|
||||||
let infoDiv = imin;
|
|
||||||
let canvasDiv = imin;
|
|
||||||
if (hasTransparency){
|
|
||||||
imageInfo = imageInfo + '<p><b>WARNING!</b> Transparency info detected in image. Transparency (alpha) has been ignored. To ensure you get the result you desire, use only solid colors in your image.</p>'
|
|
||||||
}
|
|
||||||
|
|
||||||
infoDiv.innerHTML = imageInfo;
|
|
||||||
canvasDiv.style.display = "block"
|
|
||||||
|
|
||||||
|
|
||||||
//Drawing the image
|
|
||||||
drawBoxes(pixelRGBValues, sizeX, sizeY);
|
|
||||||
}
|
|
||||||
}
|
|