diff --git a/.travis.yml b/.travis.yml index 3e2ea2435c44..4fb1c153838b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: - ENV=sonoff-knx - ENV=sonoff-sensors - ENV=sonoff-display + - ENV=sonoff-ir - ENV=sonoff-BG - ENV=sonoff-BR - ENV=sonoff-CN diff --git a/build-container/Dockerfile b/build-container/Dockerfile new file mode 100644 index 000000000000..a5852d41c4c6 --- /dev/null +++ b/build-container/Dockerfile @@ -0,0 +1,24 @@ +FROM python:2 + +LABEL author="Eduard Angold" + +# Install platformio. To be able to build tasmota <=v6.6.0 (and later) +# we have to use version 3.6.7 of platformio. +RUN pip install --upgrade pip &&\ + pip install -U platformio==3.6.7 + +# Init project +COPY init_pio_tasmota /init_pio_tasmota + +# Install project dependencies using a init project. +RUN cd /init_pio_tasmota &&\ + pio run &&\ + cd ../ &&\ + rm -fr init_pio_tasmota &&\ + cp -r /root/.platformio / &&\ + chmod -R 777 /.platformio + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] + diff --git a/build-container/README.md b/build-container/README.md new file mode 100644 index 000000000000..a02f1860ec3a --- /dev/null +++ b/build-container/README.md @@ -0,0 +1,26 @@ +# Docker container for tasmota builds +This Container will setup a proper build environment for [Sonoff-Tasmota](https://github.com/arendst/Sonoff-Tasmota) + +## Create container +`docker build -t mytasmota:latest .` + +## Use a ready container from docker hub +Use instead of the container `mytasmota:latest` the published container `eddyhub/docker-tasmota:latest` from docker hub. + +## Build all development binaries +`git clone https://github.com/arendst/Sonoff-Tasmota.git` +`docker run -ti --rm -v $(pwd)/Sonoff-Tasmota:/tasmota -u $UID:$GID mytasmota:latest` + +## Build a specific binary with custom options +Checkout Sonoff-Tasmota: `git clone https://github.com/arendst/Sonoff-Tasmota.git` +Mount the source as volume in `/tasmota`. **Prefix** any parameter available in `Sonoff-Tasmota/sonoff/my_user_config.h` with `TASMOTA_` as a environment variable for the container. **Also don't forget to escape what needs to be escaped in your shell.** **Strings** should be in **double quotes**. My config example: +`docker run -ti --rm -v $(pwd)/Sonoff-Tasmota:/tasmota -e TASMOTA_STA_SSID1='"my-wifi"' -e TASMOTA_STA_PASS1='"my-wifi-password"' -e TASMOTA_MQTT_HOST='my-mqtt-host' -e TASMOTA_MQTT_USER='"my-mqtt-user"' -e TASMOTA_MQTT_PASS='"my-mqtt-password"' -e TASMOTA_WEB_PASSWORD='"my-web-password"' -u $UID:$GID mytasmota:latest --environment sonoff-DE + +Now you should have the file Sonoff-Tasmota/.pioenvs/sonoff-DE/firmware.bin which can be flashed on your device. + +## Build a specific version of tasmota +Checkout out the needed version before using the build instructions above: +- `git clone https://github.com/arendst/Sonoff-Tasmota.git` +- `git -C Sonoff-Tasmota checkout v6.6.0` +Build it: +- `docker run -ti --rm -v $(pwd)/Sonoff-Tasmota:/tasmota -u $UID:$GID mytasmota:latest` diff --git a/build-container/entrypoint.sh b/build-container/entrypoint.sh new file mode 100644 index 000000000000..6bdf2dea618c --- /dev/null +++ b/build-container/entrypoint.sh @@ -0,0 +1,35 @@ +# configure build via environment +#!/bin/bash + +TASMOTA_VOLUME='/tasmota' +USER_CONFIG_OVERRIDE="${TASMOTA_VOLUME}/sonoff/user_config_override.h" + +if [ -d $TASMOTA_VOLUME ]; then + cd $TASMOTA_VOLUME + if [ -n "$(env | grep ^TASMOTA_)" ]; then + echo "Removing $USER_CONFIG_OVERRIDE and creating a new one." + rm "$USER_CONFIG_OVERRIDE" + #export PLATFORMIO_BUILD_FLAGS='-DUSE_CONFIG_OVERRIDE' + sed -i 's/^; *-DUSE_CONFIG_OVERRIDE/ -DUSE_CONFIG_OVERRIDE/' platformio.ini + echo '#ifndef _USER_CONFIG_OVERRIDE_H_' >> $USER_CONFIG_OVERRIDE + echo '#define _USER_CONFIG_OVERRIDE_H_' >> $USER_CONFIG_OVERRIDE + echo '#warning **** user_config_override.h: Using Settings from this File ****' >> $USER_CONFIG_OVERRIDE + echo '#undef CFG_HOLDER' >> $USER_CONFIG_OVERRIDE + echo '#define CFG_HOLDER 1' >> $USER_CONFIG_OVERRIDE + for i in $(env | grep ^TASMOTA_); do + config=${i#TASMOTA_} + key=$(echo $config | cut -d '=' -f 1) + value=$(echo $config | cut -d '=' -f 2) + echo "#undef ${key}" >> $USER_CONFIG_OVERRIDE + echo "#define ${key} ${value}" >> $USER_CONFIG_OVERRIDE + done + echo '#endif' >> $USER_CONFIG_OVERRIDE + fi + echo "Compiling..." + #pio run -t clean + pio run $@ + echo "Everything done you find your builds in .pioenvs//firmware.bin" +else + echo ">>> NO TASMOTA VOLUME MOUNTED --> EXITING" + exit 0; +fi diff --git a/build-container/init_pio_tasmota/platformio.ini b/build-container/init_pio_tasmota/platformio.ini new file mode 100755 index 000000000000..058e9064fd04 --- /dev/null +++ b/build-container/init_pio_tasmota/platformio.ini @@ -0,0 +1,30 @@ +[env:core_2_3_0] +; *** Esp8266 core for Arduino version 2.3.0 +platform = espressif8266@1.5.0 +framework = arduino +board = esp01_1m + +[env:core_2_4_2] +; *** Esp8266 core for Arduino version 2.4.2 +platform = espressif8266@1.8.0 +framework = arduino +board = esp01_1m + +[env:core_2_5_2] +; *** Esp8266 core for Arduino version 2.5.2 +platform = espressif8266@~2.2.2 +framework = arduino +board = esp01_1m + +[env:core_stage] +; *** Esp8266 core for Arduino version latest beta +platform = https://github.com/platformio/platform-espressif8266.git#feature/stage +framework = arduino +board = esp01_1m + +[env:core_pre] +; *** Arduino Esp8266 core pre 2.6.x for Tasmota (mqtt reconnects fixed) +platform = https://github.com/Jason2866/platform-espressif8266.git#Tasmota +framework = arduino +board = esp01_1m + diff --git a/build-container/init_pio_tasmota/src/main.cpp b/build-container/init_pio_tasmota/src/main.cpp new file mode 100644 index 000000000000..27f3768b72cf --- /dev/null +++ b/build-container/init_pio_tasmota/src/main.cpp @@ -0,0 +1,3 @@ +#include +void setup() {} +void loop() {} diff --git a/lib/IRremoteESP8266-2.6.4/.github/CONTRIBUTING.md b/lib/IRremoteESP8266-2.6.5/.github/CONTRIBUTING.md old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/.github/CONTRIBUTING.md rename to lib/IRremoteESP8266-2.6.5/.github/CONTRIBUTING.md diff --git a/lib/IRremoteESP8266-2.6.4/.github/Contributors.md b/lib/IRremoteESP8266-2.6.5/.github/Contributors.md old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/.github/Contributors.md rename to lib/IRremoteESP8266-2.6.5/.github/Contributors.md diff --git a/lib/IRremoteESP8266-2.6.4/.github/issue_template.md b/lib/IRremoteESP8266-2.6.5/.github/issue_template.md old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/.github/issue_template.md rename to lib/IRremoteESP8266-2.6.5/.github/issue_template.md diff --git a/lib/IRremoteESP8266-2.6.4/.gitignore b/lib/IRremoteESP8266-2.6.5/.gitignore old mode 100644 new mode 100755 similarity index 94% rename from lib/IRremoteESP8266-2.6.4/.gitignore rename to lib/IRremoteESP8266-2.6.5/.gitignore index 4441365bc3fb..c02171953c0a --- a/lib/IRremoteESP8266-2.6.4/.gitignore +++ b/lib/IRremoteESP8266-2.6.5/.gitignore @@ -48,3 +48,6 @@ tools/mode2_decode #Cygwin builds *.exe + +# Mac extended attributes +.DS_Store diff --git a/lib/IRremoteESP8266-2.6.4/.gitmodules b/lib/IRremoteESP8266-2.6.5/.gitmodules old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/.gitmodules rename to lib/IRremoteESP8266-2.6.5/.gitmodules diff --git a/lib/IRremoteESP8266-2.6.4/.style.yapf b/lib/IRremoteESP8266-2.6.5/.style.yapf old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/.style.yapf rename to lib/IRremoteESP8266-2.6.5/.style.yapf diff --git a/lib/IRremoteESP8266-2.6.4/.travis.yml b/lib/IRremoteESP8266-2.6.5/.travis.yml old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/.travis.yml rename to lib/IRremoteESP8266-2.6.5/.travis.yml index b873bff6ec27..e8bf3d8325e1 --- a/lib/IRremoteESP8266-2.6.4/.travis.yml +++ b/lib/IRremoteESP8266-2.6.5/.travis.yml @@ -56,6 +56,7 @@ jobs: - arduino --verify --board $BD $PWD/examples/TurnOnMitsubishiHeavyAc/TurnOnMitsubishiHeavyAc.ino 2> /dev/null - arduino --verify --board $BD $PWD/examples/DumbIRRepeater/DumbIRRepeater.ino 2> /dev/null - arduino --verify --board $BD $PWD/examples/SmartIRRepeater/SmartIRRepeater.ino 2> /dev/null + - arduino --verify --board $BD $PWD/examples/CommonAcControl/CommonAcControl.ino 2> /dev/null - script: # Check the version numbers match. - LIB_VERSION=$(egrep "^#define\s+_IRREMOTEESP8266_VERSION_\s+" src/IRremoteESP8266.h | cut -d\" -f2) diff --git a/lib/IRremoteESP8266-2.6.4/CPPLINT.cfg b/lib/IRremoteESP8266-2.6.5/CPPLINT.cfg old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/CPPLINT.cfg rename to lib/IRremoteESP8266-2.6.5/CPPLINT.cfg diff --git a/lib/IRremoteESP8266-2.6.4/LICENSE.txt b/lib/IRremoteESP8266-2.6.5/LICENSE.txt old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/LICENSE.txt rename to lib/IRremoteESP8266-2.6.5/LICENSE.txt diff --git a/lib/IRremoteESP8266-2.6.4/README.md b/lib/IRremoteESP8266-2.6.5/README.md old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/README.md rename to lib/IRremoteESP8266-2.6.5/README.md index 4aa0093c69f2..c4cb31515c3f --- a/lib/IRremoteESP8266-2.6.4/README.md +++ b/lib/IRremoteESP8266-2.6.5/README.md @@ -9,7 +9,7 @@ This library enables you to **send _and_ receive** infra-red signals on an [ESP8266](https://github.com/esp8266/Arduino) or an [ESP32](https://github.com/espressif/arduino-esp32) using the [Arduino framework](https://www.arduino.cc/) using common 940nm IR LEDs and common IR receiver modules. e.g. TSOP{17,22,24,36,38,44,48}* demodulators etc. -## v2.6.4 Now Available +## v2.6.5 Now Available Version 2.6.4 of the library is now [available](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). You can view the [Release Notes](ReleaseNotes.md) for all the significant changes. #### Upgrading from pre-v2.0 diff --git a/lib/IRremoteESP8266-2.6.4/ReleaseNotes.md b/lib/IRremoteESP8266-2.6.5/ReleaseNotes.md old mode 100644 new mode 100755 similarity index 94% rename from lib/IRremoteESP8266-2.6.4/ReleaseNotes.md rename to lib/IRremoteESP8266-2.6.5/ReleaseNotes.md index 1526303a20d5..5672d2483c3e --- a/lib/IRremoteESP8266-2.6.4/ReleaseNotes.md +++ b/lib/IRremoteESP8266-2.6.5/ReleaseNotes.md @@ -1,5 +1,30 @@ # Release Notes +## _v2.6.5 (20190828)_ + +**[Bug Fixes]** +- IRMQTTServer: Remove duplicate MQTT_CLIMATE from HA discovery (#869) +- Fujitsu: Ensure `on()` is called in common a/c framework. (#862) +- Update `strToModel()` (#861) +- IRMQTTServer: Add missing header file. (#858) +- IRMQTTServer: Fix a compile error when HTML_PASSWORD_ENABLE is enabled. (#856) + +**[Features]** +- IRrecv: Allow tolerance percentage to be set at run-time. (#865) +- Basic support for Daikin152 A/C protocol. (#874) +- Teco: Add light, humid, & save support. (#871) +- Detailed support for Amcor A/C protocol. (#836, #854) +- IRMQTTServer: Add ability to report Vcc at the ESP chip. (#845) +- Gree: Add timer support. (#849) +- IRac/Mitsubishi A/C: Support wide `swingh_t` mode (#844) +- IRMQTTServer: Generate protocol and bit size html selects (#838) + +**[Misc]** +- New example code to show how to use the `IRac` class to control A/Cs (#839) +- Improve/fix `swingh_t::kWide` support (#846) +- Kelvinator: Optimise code a little to save space. (#843) + + ## _v2.6.4 (20190726)_ **[Bug Fixes]** diff --git a/lib/IRremoteESP8266-2.6.4/SupportedProtocols.md b/lib/IRremoteESP8266-2.6.5/SupportedProtocols.md old mode 100644 new mode 100755 similarity index 92% rename from lib/IRremoteESP8266-2.6.4/SupportedProtocols.md rename to lib/IRremoteESP8266-2.6.5/SupportedProtocols.md index 9d297d52306b..c9d286973cab --- a/lib/IRremoteESP8266-2.6.4/SupportedProtocols.md +++ b/lib/IRremoteESP8266-2.6.5/SupportedProtocols.md @@ -1,16 +1,17 @@ + Last generated: Wed Aug 28 12:37:20 2019 ---> # IR Protocols supported by this library | Protocol | Brand | Model | A/C Model | Detailed A/C Support | | --- | --- | --- | --- | --- | | [Aiwa](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Aiwa.cpp) | **Aiwa** | RC-T501 RCU | | - | +| [Amcor](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Amcor.cpp) | **[Amcor](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Amcor.h)** | ADR-853H A/C
ADR-853H A/C
TAC-444 remote
TAC-444 remote
TAC-495 remote
TAC-495 remote | | Yes | | [Argo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Argo.cpp) | **[Argo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Argo.h)** | Ulisse 13 DCI Mobile Split A/C | | Yes | | [Carrier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Carrier.cpp) | **Carrier/Surrey** | 42QG5A55970 remote
53NGK009/012 Inverter
619EGX0090E0 A/C
619EGX0120E0 A/C
619EGX0180E0 A/C
619EGX0220E0 A/C | | - | | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Beko](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | BINR 070/071 split-type A/C
BINR 070/071 split-type A/C
RG57K7(B)/BGEF Remote
RG57K7(B)/BGEF Remote | | Yes | | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | MS12FU-10HRDN1-QRD0GW(B) A/C
MS12FU-10HRDN1-QRD0GW(B) A/C
MSABAU-07HRFN1-QRD0GW A/C (circa 2016)
MSABAU-07HRFN1-QRD0GW A/C (circa 2016)
RG52D/BGE Remote
RG52D/BGE Remote | | Yes | -| [Daikin](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Daikin.cpp) | **[Daikin](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Daikin.h)** | 17 Series A/C (DAIKIN128)
ARC423A5 remote
ARC433** remote
ARC433B69 remote
ARC477A1 remote
BRC4C153 remote
BRC52B63 remote (DAIKIN128)
FTE12HV2S A/C
FTXB09AXVJU A/C (DAIKIN128)
FTXB12AXVJU A/C (DAIKIN128)
FTXZ25NV1B A/C
FTXZ35NV1B A/C
FTXZ50NV1B A/C | | Yes | +| [Daikin](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Daikin.cpp) | **[Daikin](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Daikin.h)** | 17 Series A/C (DAIKIN128)
ARC423A5 remote
ARC433** remote
ARC433B69 remote
ARC477A1 remote
ARC480A5 remote (DAIKIN152)
BRC4C153 remote
BRC52B63 remote (DAIKIN128)
FTE12HV2S A/C
FTXB09AXVJU A/C (DAIKIN128)
FTXB12AXVJU A/C (DAIKIN128)
FTXZ25NV1B A/C
FTXZ35NV1B A/C
FTXZ50NV1B A/C | | Yes | | [Denon](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Denon.cpp) | **Unknown** | | | - | | [Dish](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Dish.cpp) | **DISH NETWORK** | echostar 301 | | - | | [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[AUX](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | KFR-35GW/BpNFW=3 A/C
YKR-T/011 remote | | Yes | @@ -40,7 +41,7 @@ | [Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp) | **[Pioneer System](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h)** | RUBO18GMFILCAD A/C (18K BTU)
RYBO12GMFILCAD A/C (12K BTU) | | Yes | | [Mitsubishi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.cpp) | **[Mitsubishi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.h)** | HC3000 Projector
TV | | Yes | | [MitsubishiHeavy](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_MitsubishiHeavy.cpp) | **[Mitsubishi Heavy Industries](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_MitsubishiHeavy.h)** | RKX502A001C remote
RLA502A700B remote
SRKxxZJ-S A/C
SRKxxZM-S A/C
SRKxxZMXA-S A/C | | Yes | -| [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Unknown](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | | | Yes | +| [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Yamaha](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | RAV561 remote
RXV585B A/V Receiver | | Yes | | [Neoclima](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Neoclima.cpp) | **[Neoclima](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Neoclima.h)** | NS-09AHTI A/C
NS-09AHTI A/C
ZH/TY-01 remote
ZH/TY-01 remote | | Yes | | [Nikai](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Nikai.cpp) | **Unknown** | | | - | | [Panasonic](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Panasonic.cpp) | **[Panasonic](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Panasonic.h)** | A75C2311 remote (CKP)
A75C3704 remote
A75C3747 remote
A75C3747 remote
A75C3747 remote
A75C3747 remote
CKP series A/C
CS-ME10CKPG A/C
CS-ME12CKPG A/C
CS-ME14CKPG A/C
CS-YW9MKD A/C
CS-Z9RKR A/C
DKE series A/C
JKE series A/C
NKE series A/C
RKR series A/C
TV | CKP
DKE
JKE
LKE
NKE
RKR | Yes | @@ -54,7 +55,7 @@ | [Sherwood](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sherwood.cpp) | **Sherwood** | RC-138 remote
RD6505(B) Receiver | | - | | [Sony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sony.cpp) | **Unknown** | | | - | | [Tcl](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.cpp) | **[Leberg](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.h)** | LBS-TOR07 A/C | | Yes | -| [Teco](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Teco.cpp) | **[Unknown](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Teco.h)** | | | Yes | +| [Teco](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Teco.cpp) | **[Alaska](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Teco.h)** | SAC9010QC A/C
SAC9010QC remote | | Yes | | [Toshiba](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Toshiba.cpp) | **[Toshiba](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Toshiba.h)** | Akita EVO II
RAS 18SKP-ES
RAS-B13N3KV2
RAS-B13N3KVP-E
WC-L03SE
WH-TA04NE | | Yes | | [Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.cpp) | **[Unknown](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.h)** | | | Yes | | [Vestel](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Vestel.cpp) | **[Vestel](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Vestel.h)** | BIOX CXP-9 A/C (9K BTU) | | Yes | @@ -73,11 +74,13 @@ ## Send & decodable protocols: - AIWA_RC_T501 +- AMCOR - ARGO - CARRIER_AC - COOLIX - DAIKIN - DAIKIN128 +- DAIKIN152 - DAIKIN160 - DAIKIN176 - DAIKIN2 diff --git a/lib/IRremoteESP8266-2.6.5/examples/CommonAcControl/CommonAcControl.ino b/lib/IRremoteESP8266-2.6.5/examples/CommonAcControl/CommonAcControl.ino new file mode 100755 index 000000000000..6f0416b51f8f --- /dev/null +++ b/lib/IRremoteESP8266-2.6.5/examples/CommonAcControl/CommonAcControl.ino @@ -0,0 +1,81 @@ +/* Copyright 2019 David Conran +* +* This example code demonstrates how to use the "Common" IRac class to control +* various air conditions. The IRac class does not support all the features +* for every protocol. Some have more detailed support that what the "Common" +* interface offers, and some only have a limited subset of the "Common" options. +* +* This example code will: +* o Try to turn on, then off every fully supported A/C protocol we know of. +* o It will try to put the A/C unit into Cooling mode at 25C, with a medium +* fan speed, and no fan swinging. +* Note: Some protocols support multiple models, only the first model is tried. +* +*/ +#include +#include +#include +#include + +const uint16_t kIrLed = 4; // The ESP GPIO pin to use that controls the IR LED. +IRac ac(kIrLed); // Create a A/C object using GPIO to sending messages with. +stdAc::state_t state; // Where we will store the desired state of the A/C. +stdAc::state_t prev; // Where we will store the previous state of the A/C. + +void setup() { + Serial.begin(115200); + delay(200); + + // Set up what we want to send. + // See state_t, opmode_t, fanspeed_t, swingv_t, & swingh_t in IRsend.h for + // all the various options. + state.protocol = decode_type_t::DAIKIN; // Set a protocol to use. + state.model = 1; // Some A/C's have different models. Let's try using just 1. + state.mode = stdAc::opmode_t::kCool; // Run in cool mode initially. + state.celsius = true; // Use Celsius for units of temp. False = Fahrenheit + state.degrees = 25; // 25 degrees. + state.fanspeed = stdAc::fanspeed_t::kMedium; // Start with the fan at medium. + state.swingv = stdAc::swingv_t::kOff; // Don't swing the fan up or down. + state.swingh = stdAc::swingh_t::kOff; // Don't swing the fan left or right. + state.light = false; // Turn off any LED/Lights/Display that we can. + state.beep = false; // Turn off any beep from the A/C if we can. + state.econo = false; // Turn off any economy modes if we can. + state.filter = false; // Turn off any Ion/Mold/Health filters if we can. + state.turbo = false; // Don't use any turbo/powerful/etc modes. + state.quiet = false; // Don't use any quiet/silent/etc modes. + state.sleep = -1; // Don't set any sleep time or modes. + state.clean = false; // Turn off any Cleaning options if we can. + state.clock = -1; // Don't set any current time if we can avoid it. + state.power = false; // Initially start with the unit off. + + prev = state; // Make sure we have a valid previous state. +} + +void loop() { + // For every protocol the library has ... + for (int i = 1; i < kLastDecodeType; i++) { + decode_type_t protocol = (decode_type_t)i; + // If the protocol is supported by the IRac class ... + if (ac.isProtocolSupported(protocol)) { + state.protocol = protocol; // Change the protocol used. + + Serial.println("Protocol " + String(protocol) + " / " + + typeToString(protocol)); + state.power = true; // We want to turn on the A/C unit. + // Have the IRac class create and send a message. + // We need a `prev` state as some A/Cs use toggle messages. + // e.g. On & Off are the same message. When given the previous state, + // it will try to do the correct thing for you. + ac.sendAc(state, &prev); // Construct and send the message. + Serial.println("Sent a message to turn ON the A/C unit."); + prev = state; // Copy new state over the previous one. + delay(5000); // Wait 5 seconds. + state.power = false; // Now we want to turn the A/C off. + ac.sendAc(state, &prev); // Construct and send the message. + Serial.println("Sent a message to turn OFF the A/C unit."); + prev = state; // Copy new state over the previous one. + delay(1000); // Wait 1 second. + } + } + Serial.println("Starting from the begining again ..."); +} diff --git a/lib/IRremoteESP8266-2.6.4/examples/ControlSamsungAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/CommonAcControl/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/ControlSamsungAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/CommonAcControl/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/ControlSamsungAC/ControlSamsungAC.ino b/lib/IRremoteESP8266-2.6.5/examples/ControlSamsungAC/ControlSamsungAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/ControlSamsungAC/ControlSamsungAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/ControlSamsungAC/ControlSamsungAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/DumbIRRepeater/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/ControlSamsungAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/DumbIRRepeater/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/ControlSamsungAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/DumbIRRepeater/DumbIRRepeater.ino b/lib/IRremoteESP8266-2.6.5/examples/DumbIRRepeater/DumbIRRepeater.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/DumbIRRepeater/DumbIRRepeater.ino rename to lib/IRremoteESP8266-2.6.5/examples/DumbIRRepeater/DumbIRRepeater.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRGCSendDemo/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/DumbIRRepeater/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRGCSendDemo/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/DumbIRRepeater/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRGCSendDemo/IRGCSendDemo.ino b/lib/IRremoteESP8266-2.6.5/examples/IRGCSendDemo/IRGCSendDemo.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRGCSendDemo/IRGCSendDemo.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRGCSendDemo/IRGCSendDemo.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRGCTCPServer/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRGCSendDemo/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRGCTCPServer/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRGCSendDemo/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRGCTCPServer/IRGCTCPServer.ino b/lib/IRremoteESP8266-2.6.5/examples/IRGCTCPServer/IRGCTCPServer.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRGCTCPServer/IRGCTCPServer.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRGCTCPServer/IRGCTCPServer.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRServer/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRGCTCPServer/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRServer/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRGCTCPServer/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.h b/lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.h old mode 100644 new mode 100755 similarity index 93% rename from lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.h rename to lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.h index de3158a4baba..73821dc05211 --- a/lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.h +++ b/lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.h @@ -5,6 +5,9 @@ #ifndef EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ #define EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ +#if defined(ESP8266) +#include +#endif // ESP8266 #include #include #include @@ -156,6 +159,16 @@ const uint16_t kMinUnknownSize = 2 * 10; // ------------------------ Advanced Usage Only -------------------------------- +// Reports the input voltage to the ESP chip. **NOT** the input voltage +// to the development board (e.g. NodeMCU, D1 Mini etc) which are typically +// powered by USB (5V) which is then lowered to 3V via a Low Drop Out (LDO) +// Voltage regulator. Hence, this feature is turned off by default as it +// make little sense for most users as it really isn't the actual input voltage. +// E.g. For purposes of monitoring a battery etc. +// Note: Turning on the feature costs ~250 bytes of prog space. +#define REPORT_VCC false // Do we report Vcc via html info page & MQTT? + +// Keywords for MQTT topics, html arguments, or config file. #define KEY_PROTOCOL "protocol" #define KEY_MODEL "model" #define KEY_POWER "power" @@ -175,6 +188,7 @@ const uint16_t kMinUnknownSize = 2 * 10; #define KEY_CELSIUS "use_celsius" #define KEY_JSON "json" #define KEY_RESEND "resend" +#define KEY_VCC "vcc" // HTML arguments we will parse for IR code information. #define KEY_TYPE "type" // KEY_PROTOCOL is also checked too. @@ -206,11 +220,14 @@ const uint8_t kPasswordLength = 20; // ----------------- End of User Configuration Section ------------------------- // Constants -#define _MY_VERSION_ "v1.3.3" +#define _MY_VERSION_ "v1.3.4" const uint8_t kRebootTime = 15; // Seconds const uint8_t kQuickDisplayTime = 2; // Seconds +// Common bit sizes for the simple protocols. +const uint8_t kCommonBitSizes[] = { + 12, 13, 15, 16, 20, 24, 28, 32, 35, 36, 42, 48, 56, 64}; // Gpio related #if defined(ESP8266) const int8_t kTxGpios[] = {-1, 0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16}; @@ -294,6 +311,9 @@ void sendJsonState(const stdAc::state_t state, const String topic, const bool retain = false, const bool ha_mode = true); #endif // MQTT_CLIMATE_JSON #endif // MQTT_ENABLE +#if REPORT_VCC +String vccToString(void); +#endif // REPORT_VCC bool isSerialGpioUsedByIr(void); void debug(const char *str); void saveWifiConfigCallback(void); @@ -319,7 +339,9 @@ String addJsReloadUrl(const String url, const uint16_t timeout_s, const bool notify); void handleExamples(void); String htmlSelectBool(const String name, const bool def); -String htmlSelectProtocol(const String name, const decode_type_t def); +String htmlSelectClimateProtocol(const String name, const decode_type_t def); +String htmlSelectAcStateProtocol(const String name, const decode_type_t def, + const bool simple); String htmlSelectModel(const String name, const int16_t def); String htmlSelectMode(const String name, const stdAc::opmode_t def); String htmlSelectFanspeed(const String name, const stdAc::fanspeed_t def); diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.ino b/lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.ino old mode 100644 new mode 100755 similarity index 95% rename from lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.ino index c4208af45381..730a8965fc86 --- a/lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/IRMQTTServer.ino +++ b/lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/IRMQTTServer.ino @@ -347,6 +347,10 @@ using irutils::msToString; +#if REPORT_VCC + ADC_MODE(ADC_VCC); +#endif // REPORT_VCC + // Globals #if defined(ESP8266) ESP8266WebServer server(kHttpPort); @@ -650,6 +654,26 @@ String htmlMenu(void) { return html; } +String htmlSelectAcStateProtocol(const String name, const decode_type_t def, + const bool simple) { + String html = ""); + return html; +} + // Root web page with example usage etc. void handleRoot(void) { #if HTML_PASSWORD_ENABLE @@ -664,65 +688,23 @@ void handleRoot(void) { html += F( "

Send a simple IR message

" "

" - "Type: " - "" + "Type: "); + html += htmlSelectAcStateProtocol(KEY_TYPE, decode_type_t::NEC, true); + html += F( " Code: 0x" " Bit size: " "" " Repeats: " @@ -731,36 +713,9 @@ void handleRoot(void) { "

" "

Send a complex (Air Conditioner) IR message

" "" - "Type: " - "" + "Type: "); + html += htmlSelectAcStateProtocol(KEY_TYPE, decode_type_t::KELVINATOR, false); + html += F( " State code: 0x" ""; for (uint8_t i = 1; i <= decode_type_t::kLastDecodeType; i++) { if (IRac::isProtocolSupported((decode_type_t)i)) { @@ -962,7 +917,7 @@ String htmlSelectGpio(const String name, const int16_t def, String htmlSelectMode(const String name, const stdAc::opmode_t def) { String html = ""; - for (int8_t i = 0; i <= 5; i++) { + for (int8_t i = 0; i <= (int8_t)stdAc::fanspeed_t::kLastFanspeedEnum; i++) { String speed = IRac::fanspeedToString((stdAc::fanspeed_t)i); html += htmlOptionItem(speed, speed, (stdAc::fanspeed_t)i == def); } @@ -982,7 +937,7 @@ String htmlSelectFanspeed(const String name, const stdAc::fanspeed_t def) { String htmlSelectSwingv(const String name, const stdAc::swingv_t def) { String html = ""; - for (int8_t i = -1; i <= 5; i++) { + for (int8_t i = -1; i <= (int8_t)stdAc::swingh_t::kLastSwinghEnum; i++) { String swing = IRac::swinghToString((stdAc::swingh_t)i); html += htmlOptionItem(swing, swing, (stdAc::swingh_t)i == def); } @@ -1034,7 +989,8 @@ void handleAirCon(void) { "" "" "" + htmlSelectClimateProtocol(KEY_PROTOCOL, climate.protocol) + + "" "" "
Protocol" + - htmlSelectProtocol(KEY_PROTOCOL, climate.protocol) + "
Model" + htmlSelectModel(KEY_MODEL, climate.model) + "
Power" + htmlSelectBool(KEY_POWER, climate.power) + @@ -1169,6 +1125,10 @@ uint32_t maxSketchSpace(void) { #endif // defined(ESP8266) } +#if REPORT_VCC +String vccToString(void) { return String(ESP.getVcc() / 1000.0); } +#endif // REPORT_VCC + // Info web page void handleInfo(void) { String html = htmlHeader(F("IR MQTT server info")); @@ -1223,6 +1183,11 @@ void handleInfo(void) { "Off" #endif // DEBUG "
" +#if REPORT_VCC + "Vcc: "; + html += vccToString(); + html += "V
" +#endif // REPORT_VCC "

" #if MQTT_ENABLE "

MQTT Information

" @@ -1300,7 +1265,8 @@ void doRestart(const char* str, const bool serial_only) { void handleReset(void) { #if HTML_PASSWORD_ENABLE if (!server.authenticate(HttpUsername, HttpPassword)) { - debug("Basic HTTP authentication failure for " + kUrlWipe); + debug(("Basic HTTP authentication failure for " + + String(kUrlWipe)).c_str()); return server.requestAuthentication(); } #endif @@ -1329,7 +1295,8 @@ void handleReset(void) { void handleReboot() { #if HTML_PASSWORD_ENABLE if (!server.authenticate(HttpUsername, HttpPassword)) { - debug("Basic HTTP authentication failure for " + kUrlReboot); + debug(("Basic HTTP authentication failure for " + + String(kUrlReboot)).c_str()); return server.requestAuthentication(); } #endif @@ -2215,6 +2182,9 @@ void doBroadcast(TimerMs *timer, const uint32_t interval, debug("Sending MQTT stat update broadcast."); sendClimate(state, state, MqttClimateStat, retain, true, false); +#if REPORT_VCC + sendString(MqttClimateStat + KEY_VCC, vccToString(), false); +#endif // REPORT_VCC #if MQTT_CLIMATE_JSON sendJsonState(state, MqttClimateStat + KEY_JSON); #endif // MQTT_CLIMATE_JSON @@ -2370,29 +2340,22 @@ void sendMQTTDiscovery(const char *topic) { "{" "\"~\":\"" + MqttClimate + "\"," "\"name\":\"" + MqttHAName + "\"," - "\"pow_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_POWER "\"," - "\"mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_MODE "\"," - "\"mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" KEY_MODE - "\"," + "\"pow_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_POWER "\"," + "\"mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_MODE "\"," + "\"mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_MODE "\"," "\"modes\":[\"off\",\"auto\",\"cool\",\"heat\",\"dry\",\"fan_only\"]," - "\"temp_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" KEY_TEMP "\"," - "\"temp_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" KEY_TEMP - "\"," + "\"temp_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_TEMP "\"," + "\"temp_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_TEMP "\"," "\"min_temp\":\"16\"," "\"max_temp\":\"30\"," "\"temp_step\":\"1\"," - "\"fan_mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" - KEY_FANSPEED "\"," - "\"fan_mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" - KEY_FANSPEED "\"," + "\"fan_mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_FANSPEED "\"," + "\"fan_mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_FANSPEED "\"," "\"fan_modes\":[\"auto\",\"min\",\"low\",\"medium\",\"high\",\"max\"]," - "\"swing_mode_cmd_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_CMND "/" - KEY_SWINGV "\"," - "\"swing_mode_stat_t\":\"~" MQTT_CLIMATE "/" MQTT_CLIMATE_STAT "/" - KEY_SWINGV "\"," + "\"swing_mode_cmd_t\":\"~/" MQTT_CLIMATE_CMND "/" KEY_SWINGV "\"," + "\"swing_mode_stat_t\":\"~/" MQTT_CLIMATE_STAT "/" KEY_SWINGV "\"," "\"swing_modes\":[" - "\"off\",\"auto\",\"highest\",\"high\",\"middle\",\"low\",\"lowest\"" - "]" + "\"off\",\"auto\",\"highest\",\"high\",\"middle\",\"low\",\"lowest\"]" "}").c_str())) { mqttLog("MQTT climate discovery successful sent."); hasDiscoveryBeenSent = true; diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRMQTTServer/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRMQTTServer/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRServer/IRServer.ino b/lib/IRremoteESP8266-2.6.5/examples/IRServer/IRServer.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRServer/IRServer.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRServer/IRServer.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDemo/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRServer/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDemo/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRServer/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDemo/IRrecvDemo.ino b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDemo/IRrecvDemo.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDemo/IRrecvDemo.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDemo/IRrecvDemo.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDump/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDemo/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDump/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDemo/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDump/IRrecvDump.ino b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDump/IRrecvDump.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDump/IRrecvDump.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDump/IRrecvDump.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDumpV2/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDump/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDumpV2/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDump/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRrecvDumpV2/IRrecvDumpV2.ino b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDumpV2/IRrecvDumpV2.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRrecvDumpV2/IRrecvDumpV2.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDumpV2/IRrecvDumpV2.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRsendDemo/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRrecvDumpV2/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRsendDemo/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRrecvDumpV2/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRsendDemo/IRsendDemo.ino b/lib/IRremoteESP8266-2.6.5/examples/IRsendDemo/IRsendDemo.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRsendDemo/IRsendDemo.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRsendDemo/IRsendDemo.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRsendProntoDemo/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRsendDemo/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRsendProntoDemo/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRsendDemo/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/IRsendProntoDemo/IRsendProntoDemo.ino b/lib/IRremoteESP8266-2.6.5/examples/IRsendProntoDemo/IRsendProntoDemo.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/IRsendProntoDemo/IRsendProntoDemo.ino rename to lib/IRremoteESP8266-2.6.5/examples/IRsendProntoDemo/IRsendProntoDemo.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/JVCPanasonicSendDemo/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/IRsendProntoDemo/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/JVCPanasonicSendDemo/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/IRsendProntoDemo/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino b/lib/IRremoteESP8266-2.6.5/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino rename to lib/IRremoteESP8266-2.6.5/examples/JVCPanasonicSendDemo/JVCPanasonicSendDemo.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/LGACSend/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/JVCPanasonicSendDemo/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/LGACSend/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/JVCPanasonicSendDemo/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/LGACSend/LGACSend.ino b/lib/IRremoteESP8266-2.6.5/examples/LGACSend/LGACSend.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/LGACSend/LGACSend.ino rename to lib/IRremoteESP8266-2.6.5/examples/LGACSend/LGACSend.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/SmartIRRepeater/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/LGACSend/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/SmartIRRepeater/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/LGACSend/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/SmartIRRepeater/SmartIRRepeater.ino b/lib/IRremoteESP8266-2.6.5/examples/SmartIRRepeater/SmartIRRepeater.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/SmartIRRepeater/SmartIRRepeater.ino rename to lib/IRremoteESP8266-2.6.5/examples/SmartIRRepeater/SmartIRRepeater.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnArgoAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/SmartIRRepeater/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnArgoAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/SmartIRRepeater/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnArgoAC/TurnOnArgoAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnArgoAC/TurnOnArgoAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnArgoAC/TurnOnArgoAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnArgoAC/TurnOnArgoAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnDaikinAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnArgoAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnDaikinAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnArgoAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnDaikinAC/TurnOnDaikinAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnFujitsuAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnDaikinAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnFujitsuAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnDaikinAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnFujitsuAC/TurnOnFujitsuAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnFujitsuAC/TurnOnFujitsuAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnFujitsuAC/TurnOnFujitsuAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnFujitsuAC/TurnOnFujitsuAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnKelvinatorAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnFujitsuAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnKelvinatorAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnFujitsuAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnKelvinatorAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnKelvinatorAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiAC/TurnOnMitsubishiAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiHeavyAc/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiHeavyAc/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiHeavyAc/TurnOnMitsubishiHeavyAc.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiHeavyAc/TurnOnMitsubishiHeavyAc.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnMitsubishiHeavyAc/TurnOnMitsubishiHeavyAc.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiHeavyAc/TurnOnMitsubishiHeavyAc.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnPanasonicAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiHeavyAc/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnPanasonicAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnMitsubishiHeavyAc/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnPanasonicAC/TurnOnPanasonicAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnPanasonicAC/TurnOnPanasonicAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnPanasonicAC/TurnOnPanasonicAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnPanasonicAC/TurnOnPanasonicAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnToshibaAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnPanasonicAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnToshibaAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnPanasonicAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnToshibaAC/TurnOnToshibaAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnToshibaAC/TurnOnToshibaAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnToshibaAC/TurnOnToshibaAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnToshibaAC/TurnOnToshibaAC.ino diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnTrotecAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnToshibaAC/platformio.ini old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnTrotecAC/platformio.ini rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnToshibaAC/platformio.ini diff --git a/lib/IRremoteESP8266-2.6.4/examples/TurnOnTrotecAC/TurnOnTrotecAC.ino b/lib/IRremoteESP8266-2.6.5/examples/TurnOnTrotecAC/TurnOnTrotecAC.ino old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/examples/TurnOnTrotecAC/TurnOnTrotecAC.ino rename to lib/IRremoteESP8266-2.6.5/examples/TurnOnTrotecAC/TurnOnTrotecAC.ino diff --git a/lib/IRremoteESP8266-2.6.5/examples/TurnOnTrotecAC/platformio.ini b/lib/IRremoteESP8266-2.6.5/examples/TurnOnTrotecAC/platformio.ini new file mode 100755 index 000000000000..1aba0afcc1f2 --- /dev/null +++ b/lib/IRremoteESP8266-2.6.5/examples/TurnOnTrotecAC/platformio.ini @@ -0,0 +1,18 @@ +[platformio] +src_dir = . + +[env] +lib_extra_dirs = ../../ +lib_ldf_mode = deep+ +lib_ignore = examples +build_flags = + +[env:nodemcuv2] +platform = espressif8266 +framework = arduino +board = nodemcuv2 + +[env:esp32dev] +platform = espressif32 +framework = arduino +board = esp32dev diff --git a/lib/IRremoteESP8266-2.6.4/keywords.txt b/lib/IRremoteESP8266-2.6.5/keywords.txt old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/keywords.txt rename to lib/IRremoteESP8266-2.6.5/keywords.txt index 6edef19371d6..db2d398a151b --- a/lib/IRremoteESP8266-2.6.4/keywords.txt +++ b/lib/IRremoteESP8266-2.6.5/keywords.txt @@ -20,9 +20,11 @@ # Datatypes & Classes (KEYWORD1) ####################################### +IRAmcorAc KEYWORD1 IRArgoAC KEYWORD1 IRCoolixAC KEYWORD1 IRDaikin128 KEYWORD1 +IRDaikin152 KEYWORD1 IRDaikin160 KEYWORD1 IRDaikin176 KEYWORD1 IRDaikin2 KEYWORD1 @@ -77,6 +79,7 @@ _delayMicroseconds KEYWORD2 _matchGeneric KEYWORD2 _setMode KEYWORD2 _setTemp KEYWORD2 +_validTolerance KEYWORD2 add KEYWORD2 addBoolToString KEYWORD2 addFanToString KEYWORD2 @@ -84,6 +87,7 @@ addIntToString KEYWORD2 addLabeledString KEYWORD2 addModeToString KEYWORD2 addTempToString KEYWORD2 +amcor KEYWORD2 argo KEYWORD2 bcdToUint8 KEYWORD2 begin KEYWORD2 @@ -125,12 +129,14 @@ daikin2 KEYWORD2 daikin216 KEYWORD2 decode KEYWORD2 decodeAiwaRCT501 KEYWORD2 +decodeAmcor KEYWORD2 decodeArgo KEYWORD2 decodeCOOLIX KEYWORD2 decodeCarrierAC KEYWORD2 decodeDISH KEYWORD2 decodeDaikin KEYWORD2 decodeDaikin128 KEYWORD2 +decodeDaikin152 KEYWORD2 decodeDaikin160 KEYWORD2 decodeDaikin176 KEYWORD2 decodeDaikin2 KEYWORD2 @@ -243,6 +249,7 @@ getFreshAir KEYWORD2 getFreshAirHigh KEYWORD2 getHealth KEYWORD2 getHold KEYWORD2 +getHumid KEYWORD2 getIFeel KEYWORD2 getIon KEYWORD2 getIonFilter KEYWORD2 @@ -269,6 +276,7 @@ getQuiet KEYWORD2 getRClevel KEYWORD2 getRaw KEYWORD2 getRoomTemp KEYWORD2 +getSave KEYWORD2 getSensor KEYWORD2 getSensorTemp KEYWORD2 getSilent KEYWORD2 @@ -293,6 +301,8 @@ getTempOffset KEYWORD2 getTempRaw KEYWORD2 getTime KEYWORD2 getTimer KEYWORD2 +getTimerEnabled KEYWORD2 +getTolerance KEYWORD2 getTurbo KEYWORD2 getUseCelsius KEYWORD2 getVane KEYWORD2 @@ -357,12 +367,14 @@ samsung KEYWORD2 send KEYWORD2 sendAc KEYWORD2 sendAiwaRCT501 KEYWORD2 +sendAmcor KEYWORD2 sendArgo KEYWORD2 sendCOOLIX KEYWORD2 sendCarrierAC KEYWORD2 sendDISH KEYWORD2 sendDaikin KEYWORD2 sendDaikin128 KEYWORD2 +sendDaikin152 KEYWORD2 sendDaikin160 KEYWORD2 sendDaikin176 KEYWORD2 sendDaikin2 KEYWORD2 @@ -455,6 +467,7 @@ setFreshAir KEYWORD2 setFreshAirHigh KEYWORD2 setHealth KEYWORD2 setHold KEYWORD2 +setHumid KEYWORD2 setIFeel KEYWORD2 setIon KEYWORD2 setIonFilter KEYWORD2 @@ -480,6 +493,7 @@ setPurify KEYWORD2 setQuiet KEYWORD2 setRaw KEYWORD2 setRoomTemp KEYWORD2 +setSave KEYWORD2 setSensor KEYWORD2 setSensorTemp KEYWORD2 setSensorTempRaw KEYWORD2 @@ -500,6 +514,8 @@ setTempRaw KEYWORD2 setTime KEYWORD2 setTimer KEYWORD2 setTimerActive KEYWORD2 +setTimerEnabled KEYWORD2 +setTolerance KEYWORD2 setTurbo KEYWORD2 setUnknownThreshold KEYWORD2 setUseCelsius KEYWORD2 @@ -550,6 +566,7 @@ xorBytes KEYWORD2 AIWA_RC_T501 LITERAL1 AIWA_RC_T501_BITS LITERAL1 ALLOW_DELAY_CALLS LITERAL1 +AMCOR LITERAL1 ARDB1 LITERAL1 ARGO LITERAL1 ARGO_COMMAND_LENGTH LITERAL1 @@ -583,6 +600,7 @@ COOLIX LITERAL1 COOLIX_BITS LITERAL1 DAIKIN LITERAL1 DAIKIN128 LITERAL1 +DAIKIN152 LITERAL1 DAIKIN160 LITERAL1 DAIKIN176 LITERAL1 DAIKIN2 LITERAL1 @@ -601,11 +619,13 @@ DAIKIN_MAX_TEMP LITERAL1 DAIKIN_MIN_TEMP LITERAL1 DECODE_AC LITERAL1 DECODE_AIWA_RC_T501 LITERAL1 +DECODE_AMCOR LITERAL1 DECODE_ARGO LITERAL1 DECODE_CARRIER_AC LITERAL1 DECODE_COOLIX LITERAL1 DECODE_DAIKIN LITERAL1 DECODE_DAIKIN128 LITERAL1 +DECODE_DAIKIN152 LITERAL1 DECODE_DAIKIN160 LITERAL1 DECODE_DAIKIN176 LITERAL1 DECODE_DAIKIN2 LITERAL1 @@ -889,11 +909,13 @@ SANYO_LC7461 LITERAL1 SANYO_LC7461_BITS LITERAL1 SANYO_SA8650B_BITS LITERAL1 SEND_AIWA_RC_T501 LITERAL1 +SEND_AMCOR LITERAL1 SEND_ARGO LITERAL1 SEND_CARRIER_AC LITERAL1 SEND_COOLIX LITERAL1 SEND_DAIKIN LITERAL1 SEND_DAIKIN128 LITERAL1 +SEND_DAIKIN152 LITERAL1 SEND_DAIKIN160 LITERAL1 SEND_DAIKIN176 LITERAL1 SEND_DAIKIN2 LITERAL1 @@ -1001,6 +1023,42 @@ kAiwaRcT501PostBits LITERAL1 kAiwaRcT501PostData LITERAL1 kAiwaRcT501PreBits LITERAL1 kAiwaRcT501PreData LITERAL1 +kAmcorAuto LITERAL1 +kAmcorBits LITERAL1 +kAmcorChecksumByte LITERAL1 +kAmcorCool LITERAL1 +kAmcorDefaultRepeat LITERAL1 +kAmcorDry LITERAL1 +kAmcorFan LITERAL1 +kAmcorFanAuto LITERAL1 +kAmcorFanMask LITERAL1 +kAmcorFanMax LITERAL1 +kAmcorFanMed LITERAL1 +kAmcorFanMin LITERAL1 +kAmcorFooterMark LITERAL1 +kAmcorGap LITERAL1 +kAmcorHdrMark LITERAL1 +kAmcorHdrSpace LITERAL1 +kAmcorHeat LITERAL1 +kAmcorMaxMask LITERAL1 +kAmcorMaxTemp LITERAL1 +kAmcorMinTemp LITERAL1 +kAmcorModeFanByte LITERAL1 +kAmcorModeMask LITERAL1 +kAmcorOneMark LITERAL1 +kAmcorOneSpace LITERAL1 +kAmcorPowerByte LITERAL1 +kAmcorPowerMask LITERAL1 +kAmcorPowerOff LITERAL1 +kAmcorPowerOn LITERAL1 +kAmcorSpecialByte LITERAL1 +kAmcorStateLength LITERAL1 +kAmcorTempByte LITERAL1 +kAmcorTempMask LITERAL1 +kAmcorTolerance LITERAL1 +kAmcorVentMask LITERAL1 +kAmcorZeroMark LITERAL1 +kAmcorZeroSpace LITERAL1 kArgoAuto LITERAL1 kArgoBitMark LITERAL1 kArgoBits LITERAL1 @@ -1151,6 +1209,17 @@ kDaikin128SectionLength LITERAL1 kDaikin128Sections LITERAL1 kDaikin128StateLength LITERAL1 kDaikin128ZeroSpace LITERAL1 +kDaikin152BitMark LITERAL1 +kDaikin152Bits LITERAL1 +kDaikin152DefaultRepeat LITERAL1 +kDaikin152Freq LITERAL1 +kDaikin152Gap LITERAL1 +kDaikin152HdrMark LITERAL1 +kDaikin152HdrSpace LITERAL1 +kDaikin152LeaderBits LITERAL1 +kDaikin152OneSpace LITERAL1 +kDaikin152StateLength LITERAL1 +kDaikin152ZeroSpace LITERAL1 kDaikin160BitMark LITERAL1 kDaikin160Bits LITERAL1 kDaikin160ByteFan LITERAL1 @@ -1555,6 +1624,13 @@ kGreeSwingMiddleUp LITERAL1 kGreeSwingPosMask LITERAL1 kGreeSwingUp LITERAL1 kGreeSwingUpAuto LITERAL1 +kGreeTempMask LITERAL1 +kGreeTimer1Mask LITERAL1 +kGreeTimerEnabledBit LITERAL1 +kGreeTimerHalfHrBit LITERAL1 +kGreeTimerHoursMask LITERAL1 +kGreeTimerMax LITERAL1 +kGreeTimerTensHrMask LITERAL1 kGreeTurboMask LITERAL1 kGreeWiFiMask LITERAL1 kGreeXfanMask LITERAL1 @@ -1749,6 +1825,10 @@ kLasertagMinSamples LITERAL1 kLasertagTick LITERAL1 kLasertagTolerance LITERAL1 kLastDecodeType LITERAL1 +kLastFanspeedEnum LITERAL1 +kLastOpmodeEnum LITERAL1 +kLastSwinghEnum LITERAL1 +kLastSwingvEnum LITERAL1 kLeft LITERAL1 kLeftMax LITERAL1 kLegoPfBitMark LITERAL1 @@ -2420,12 +2500,15 @@ kTecoGap LITERAL1 kTecoHdrMark LITERAL1 kTecoHdrSpace LITERAL1 kTecoHeat LITERAL1 +kTecoHumid LITERAL1 +kTecoLight LITERAL1 kTecoMaxTemp LITERAL1 kTecoMinTemp LITERAL1 kTecoModeMask LITERAL1 kTecoOneSpace LITERAL1 kTecoPower LITERAL1 kTecoReset LITERAL1 +kTecoSave LITERAL1 kTecoSleep LITERAL1 kTecoSwing LITERAL1 kTecoTempMask LITERAL1 @@ -2483,6 +2566,7 @@ kTrotecStateLength LITERAL1 kTrotecTimerBit LITERAL1 kTrotecZeroSpace LITERAL1 kUnknownThreshold LITERAL1 +kUseDefTol LITERAL1 kVestelAcAuto LITERAL1 kVestelAcBitMark LITERAL1 kVestelAcBits LITERAL1 @@ -2604,3 +2688,4 @@ kWhynterOneSpaceTicks LITERAL1 kWhynterTick LITERAL1 kWhynterZeroSpace LITERAL1 kWhynterZeroSpaceTicks LITERAL1 +kWide LITERAL1 diff --git a/lib/IRremoteESP8266-2.6.4/library.json b/lib/IRremoteESP8266-2.6.5/library.json old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/library.json rename to lib/IRremoteESP8266-2.6.5/library.json index b678372d72fe..c5136f18e09d --- a/lib/IRremoteESP8266-2.6.4/library.json +++ b/lib/IRremoteESP8266-2.6.5/library.json @@ -1,6 +1,6 @@ { "name": "IRremoteESP8266", - "version": "2.6.4", + "version": "2.6.5", "keywords": "infrared, ir, remote, esp8266, esp32", "description": "Send and receive infrared signals with multiple protocols (ESP8266/ESP32)", "repository": diff --git a/lib/IRremoteESP8266-2.6.4/library.properties b/lib/IRremoteESP8266-2.6.5/library.properties old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/library.properties rename to lib/IRremoteESP8266-2.6.5/library.properties index 7ab396d1f898..f83a804282a4 --- a/lib/IRremoteESP8266-2.6.4/library.properties +++ b/lib/IRremoteESP8266-2.6.5/library.properties @@ -1,5 +1,5 @@ name=IRremoteESP8266 -version=2.6.4 +version=2.6.5 author=David Conran, Sebastien Warin, Mark Szabo, Ken Shirriff maintainer=Mark Szabo, David Conran, Sebastien Warin, Roi Dayan, Massimiliano Pinto sentence=Send and receive infrared signals with multiple protocols (ESP8266/ESP32) diff --git a/lib/IRremoteESP8266-2.6.4/pylintrc b/lib/IRremoteESP8266-2.6.5/pylintrc old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/pylintrc rename to lib/IRremoteESP8266-2.6.5/pylintrc diff --git a/lib/IRremoteESP8266-2.6.4/src/CPPLINT.cfg b/lib/IRremoteESP8266-2.6.5/src/CPPLINT.cfg old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/CPPLINT.cfg rename to lib/IRremoteESP8266-2.6.5/src/CPPLINT.cfg diff --git a/lib/IRremoteESP8266-2.6.4/src/IRac.cpp b/lib/IRremoteESP8266-2.6.5/src/IRac.cpp old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/src/IRac.cpp rename to lib/IRremoteESP8266-2.6.5/src/IRac.cpp index 4483357bcca5..df668d836bf6 --- a/lib/IRremoteESP8266-2.6.4/src/IRac.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/IRac.cpp @@ -15,6 +15,7 @@ #include "IRsend.h" #include "IRremoteESP8266.h" #include "IRutils.h" +#include "ir_Amcor.h" #include "ir_Argo.h" #include "ir_Coolix.h" #include "ir_Daikin.h" @@ -46,7 +47,10 @@ IRac::IRac(const uint16_t pin, const bool inverted, const bool use_modulation) { // Is the given protocol supported by the IRac class? bool IRac::isProtocolSupported(const decode_type_t protocol) { switch (protocol) { -#if SEND_ARGO +#if SEND_AMCOR + case decode_type_t::AMCOR: +#endif +#if SEND_AMCOR case decode_type_t::ARGO: #endif #if SEND_COOLIX @@ -140,6 +144,27 @@ bool IRac::isProtocolSupported(const decode_type_t protocol) { } } +#if SEND_AMCOR +void IRac::amcor(IRAmcorAc *ac, + const bool on, const stdAc::opmode_t mode, const float degrees, + const stdAc::fanspeed_t fan) { + ac->setPower(on); + ac->setMode(ac->convertMode(mode)); + ac->setTemp(degrees); + ac->setFan(ac->convertFan(fan)); + // No Swing setting available. + // No Quiet setting available. + // No Light setting available. + // No Filter setting available. + // No Turbo setting available. + // No Economy setting available. + // No Clean setting available. + // No Beep setting available. + // No Sleep setting available. + ac->send(); +} +#endif // SEND_AMCOR + #if SEND_ARGO void IRac::argo(IRArgoAC *ac, const bool on, const stdAc::opmode_t mode, const float degrees, @@ -400,6 +425,7 @@ void IRac::fujitsu(IRFujitsuAC *ac, const fujitsu_ac_remote_model_t model, // No Beep setting available. // No Sleep setting available. // No Clock setting available. + ac->on(); // Ref: Issue #860 } else { // Off is special case/message. We don't need to send other messages. ac->off(); @@ -801,7 +827,7 @@ void IRac::tcl112(IRTcl112Ac *ac, void IRac::teco(IRTecoAc *ac, const bool on, const stdAc::opmode_t mode, const float degrees, const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, - const int16_t sleep) { + const bool light, const int16_t sleep) { ac->setPower(on); ac->setMode(ac->convertMode(mode)); ac->setTemp(degrees); @@ -810,7 +836,7 @@ void IRac::teco(IRTecoAc *ac, // No Horizontal swing setting available. // No Quiet setting available. // No Turbo setting available. - // No Light setting available. + ac->setLight(light); // No Filter setting available. // No Clean setting available. // No Beep setting available. @@ -1014,6 +1040,14 @@ bool IRac::sendAc(const decode_type_t vendor, const int16_t model, if (mode == stdAc::opmode_t::kOff) on = false; // Per vendor settings & setup. switch (vendor) { +#if SEND_AMCOR + case AMCOR: + { + IRAmcorAc ac(_pin, _inverted, _modulation); + amcor(&ac, on, mode, degC, fan); + break; + } +#endif // SEND_AMCOR #if SEND_ARGO case ARGO: { @@ -1247,7 +1281,7 @@ bool IRac::sendAc(const decode_type_t vendor, const int16_t model, { IRTecoAc ac(_pin, _inverted, _modulation); ac.begin(); - teco(&ac, on, mode, degC, fan, swingv, sleep); + teco(&ac, on, mode, degC, fan, swingv, light, sleep); break; } #endif // SEND_TECO @@ -1413,17 +1447,28 @@ stdAc::swingh_t IRac::strToSwingH(const char *str, !strcasecmp(str, "MAXRIGHT") || !strcasecmp(str, "MAX RIGHT") || !strcasecmp(str, "FARRIGHT") || !strcasecmp(str, "FAR RIGHT")) return stdAc::swingh_t::kRightMax; + else if (!strcasecmp(str, "WIDE")) + return stdAc::swingh_t::kWide; else return def; } // Assumes str is the model or an integer >= 1. int16_t IRac::strToModel(const char *str, const int16_t def) { + // Gree + if (!strcasecmp(str, "YAW1F")) { + return gree_ac_remote_model_t::YAW1F; + } else if (!strcasecmp(str, "YBOFB")) { + return gree_ac_remote_model_t::YBOFB; // Fujitsu A/C models - if (!strcasecmp(str, "ARRAH2E")) { + } else if (!strcasecmp(str, "ARRAH2E")) { return fujitsu_ac_remote_model_t::ARRAH2E; } else if (!strcasecmp(str, "ARDB1")) { return fujitsu_ac_remote_model_t::ARDB1; + } else if (!strcasecmp(str, "ARREB1E")) { + return fujitsu_ac_remote_model_t::ARREB1E; + } else if (!strcasecmp(str, "ARJW2")) { + return fujitsu_ac_remote_model_t::ARJW2; // Panasonic A/C families } else if (!strcasecmp(str, "LKE") || !strcasecmp(str, "PANASONICLKE")) { return panasonic_ac_remote_model_t::kPanasonicLke; @@ -1542,6 +1587,8 @@ String IRac::swinghToString(const stdAc::swingh_t swingh) { return F("right"); case stdAc::swingh_t::kRightMax: return F("rightmax"); + case stdAc::swingh_t::kWide: + return F("wide"); default: return F("unknown"); } @@ -1555,6 +1602,13 @@ namespace IRAcUtils { // A string with the human description of the A/C message. "" if we can't. String resultAcToString(const decode_results * const result) { switch (result->decode_type) { +#if DECODE_AMCOR + case decode_type_t::AMCOR: { + IRAmcorAc ac(0); + ac.setRaw(result->state); + return ac.toString(); + } +#endif // DECODE_AMCOR #if DECODE_ARGO case decode_type_t::ARGO: { IRArgoAC ac(0); @@ -1784,6 +1838,14 @@ namespace IRAcUtils { const stdAc::state_t *prev) { if (decode == NULL || result == NULL) return false; // Safety check. switch (decode->decode_type) { +#if DECODE_AMCOR + case decode_type_t::AMCOR: { + IRAmcorAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } +#endif // DECODE_AMCOR #if DECODE_ARGO case decode_type_t::ARGO: { IRArgoAC ac(kGpioUnused); diff --git a/lib/IRremoteESP8266-2.6.4/src/IRac.h b/lib/IRremoteESP8266-2.6.5/src/IRac.h old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/src/IRac.h rename to lib/IRremoteESP8266-2.6.5/src/IRac.h index d02ce43afc73..73ee4b2a3345 --- a/lib/IRremoteESP8266-2.6.4/src/IRac.h +++ b/lib/IRremoteESP8266-2.6.5/src/IRac.h @@ -7,6 +7,7 @@ #include #endif #include "IRremoteESP8266.h" +#include "ir_Amcor.h" #include "ir_Argo.h" #include "ir_Coolix.h" #include "ir_Daikin.h" @@ -73,6 +74,11 @@ class IRac { uint16_t _pin; bool _inverted; bool _modulation; +#if SEND_AMCOR + void amcor(IRAmcorAc *ac, + const bool on, const stdAc::opmode_t mode, const float degrees, + const stdAc::fanspeed_t fan); +#endif // SEND_AMCOR #if SEND_ARGO void argo(IRArgoAC *ac, const bool on, const stdAc::opmode_t mode, const float degrees, @@ -260,7 +266,7 @@ void electra(IRElectraAc *ac, void teco(IRTecoAc *ac, const bool on, const stdAc::opmode_t mode, const float degrees, const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, - const int16_t sleep = -1); + const bool light, const int16_t sleep = -1); #endif // SEND_TECO #if SEND_TOSHIBA_AC void toshiba(IRToshibaAC *ac, diff --git a/lib/IRremoteESP8266-2.6.4/src/IRrecv.cpp b/lib/IRremoteESP8266-2.6.5/src/IRrecv.cpp old mode 100644 new mode 100755 similarity index 96% rename from lib/IRremoteESP8266-2.6.4/src/IRrecv.cpp rename to lib/IRremoteESP8266-2.6.5/src/IRrecv.cpp index 70360f0ec747..739ced38f873 --- a/lib/IRremoteESP8266-2.6.4/src/IRrecv.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/IRrecv.cpp @@ -182,6 +182,7 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize, #if DECODE_HASH _unknown_threshold = kUnknownThreshold; #endif // DECODE_HASH + _tolerance = kTolerance; } // Class destructor @@ -297,6 +298,15 @@ void IRrecv::setUnknownThreshold(const uint16_t length) { } #endif // DECODE_HASH + +// Set the base tolerance percentage for matching incoming IR messages. +void IRrecv::setTolerance(const uint8_t percent) { + _tolerance = std::min(percent, (uint8_t)100); +} + +// Get the base tolerance percentage for matching incoming IR messages. +uint8_t IRrecv::getTolerance(void) { return _tolerance; } + // Decodes the received IR message. // If the interrupt state is saved, we will immediately resume waiting // for the next IR message to avoid missing messages. @@ -651,6 +661,14 @@ bool IRrecv::decode(decode_results *results, irparams_t *save) { DPRINTLN("Attempting Daikin128 decode"); if (decodeDaikin128(results)) return true; #endif // DECODE_DAIKIN128 +#if DECODE_AMCOR + DPRINTLN("Attempting Amcor decode"); + if (decodeAmcor(results)) return true; +#endif // DECODE_AMCOR +#if DECODE_DAIKIN152 + DPRINTLN("Attempting Daikin152 decode"); + if (decodeDaikin152(results)) return true; +#endif // DECODE_DAIKIN152 #if DECODE_HASH // decodeHash returns a hash on any input. // Thus, it needs to be last in the list. @@ -665,6 +683,11 @@ bool IRrecv::decode(decode_results *results, irparams_t *save) { return false; } +// Convert the tolerance percentage into something valid. +uint8_t IRrecv::_validTolerance(const uint8_t percentage) { + return (percentage > 100) ? _tolerance : percentage; +} + // Calculate the lower bound of the nr. of ticks. // // Args: @@ -673,10 +696,12 @@ bool IRrecv::decode(decode_results *results, irparams_t *save) { // delta: A non-scaling amount to reduce usecs by. // Returns: // Nr. of ticks. -uint32_t IRrecv::ticksLow(uint32_t usecs, uint8_t tolerance, uint16_t delta) { +uint32_t IRrecv::ticksLow(const uint32_t usecs, const uint8_t tolerance, + const uint16_t delta) { // max() used to ensure the result can't drop below 0 before the cast. return ((uint32_t)std::max( - (int32_t)(usecs * (1.0 - tolerance / 100.0) - delta), 0)); + (int32_t)(usecs * (1.0 - _validTolerance(tolerance) / 100.0) - delta), + 0)); } // Calculate the upper bound of the nr. of ticks. @@ -687,8 +712,10 @@ uint32_t IRrecv::ticksLow(uint32_t usecs, uint8_t tolerance, uint16_t delta) { // delta: A non-scaling amount to increase usecs by. // Returns: // Nr. of ticks. -uint32_t IRrecv::ticksHigh(uint32_t usecs, uint8_t tolerance, uint16_t delta) { - return ((uint32_t)(usecs * (1.0 + tolerance / 100.0)) + 1 + delta); +uint32_t IRrecv::ticksHigh(const uint32_t usecs, const uint8_t tolerance, + const uint16_t delta) { + return ((uint32_t)(usecs * (1.0 + _validTolerance(tolerance) / 100.0)) + 1 + + delta); } // Check if we match a pulse(measured) with the desired within @@ -836,7 +863,7 @@ bool IRrecv::matchSpace(uint32_t measured, uint32_t desired, uint8_t tolerance, // Compare two tick values, returning 0 if newval is shorter, // 1 if newval is equal, and 2 if newval is longer // Use a tolerance of 20% -int16_t IRrecv::compare(uint16_t oldval, uint16_t newval) { +uint16_t IRrecv::compare(const uint16_t oldval, const uint16_t newval) { if (newval < oldval * 0.8) return 0; else if (oldval < newval * 0.8) @@ -859,7 +886,7 @@ bool IRrecv::decodeHash(decode_results *results) { // however it is left this way for compatibility with previously captured // values. for (uint16_t i = 1; i < results->rawlen - 2; i++) { - int16_t value = compare(results->rawbuf[i], results->rawbuf[i + 2]); + uint16_t value = compare(results->rawbuf[i], results->rawbuf[i + 2]); // Add value into the hash hash = (hash * kFnvPrime32) ^ value; } @@ -883,7 +910,7 @@ bool IRrecv::decodeHash(decode_results *results) { // onespace: Nr. of uSeconds in an expected space signal for a '1' bit. // zeromark: Nr. of uSeconds in an expected mark signal for a '0' bit. // zerospace: Nr. of uSeconds in an expected space signal for a '0' bit. -// tolerance: Percentage error margin to allow. (Def: kTolerance) +// tolerance: Percentage error margin to allow. (Def: kUseDefTol) // excess: Nr. of useconds. (Def: kMarkExcess) // MSBfirst: Bit order to save the data in. (Def: true) // Returns: @@ -928,7 +955,7 @@ match_result_t IRrecv::matchData( // onespace: Nr. of uSeconds in an expected space signal for a '1' bit. // zeromark: Nr. of uSeconds in an expected mark signal for a '0' bit. // zerospace: Nr. of uSeconds in an expected space signal for a '0' bit. -// tolerance: Percentage error margin to allow. (Def: kTolerance) +// tolerance: Percentage error margin to allow. (Def: kUseDefTol) // excess: Nr. of useconds. (Def: kMarkExcess) // MSBfirst: Bit order to save the data in. (Def: true) // Returns: @@ -975,7 +1002,7 @@ uint16_t IRrecv::matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr, // footermark: Nr. of uSeconds for the expected footer mark signal. // footerspace: Nr. of uSeconds for the expected footer space/gap signal. // atleast: Is the match on the footerspace a matchAtLeast or matchSpace? -// tolerance: Percentage error margin to allow. (Def: kTolerance) +// tolerance: Percentage error margin to allow. (Def: kUseDefTol) // excess: Nr. of useconds. (Def: kMarkExcess) // MSBfirst: Bit order to save the data in. (Def: true) // Returns: @@ -1074,7 +1101,7 @@ uint16_t IRrecv::_matchGeneric(volatile uint16_t *data_ptr, // footermark: Nr. of uSeconds for the expected footer mark signal. // footerspace: Nr. of uSeconds for the expected footer space/gap signal. // atleast: Is the match on the footerspace a matchAtLeast or matchSpace? -// tolerance: Percentage error margin to allow. (Def: kTolerance) +// tolerance: Percentage error margin to allow. (Def: kUseDefTol) // excess: Nr. of useconds. (Def: kMarkExcess) // MSBfirst: Bit order to save the data in. (Def: true) // Returns: @@ -1121,7 +1148,7 @@ uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr, // footermark: Nr. of uSeconds for the expected footer mark signal. // footerspace: Nr. of uSeconds for the expected footer space/gap signal. // atleast: Is the match on the footerspace a matchAtLeast or matchSpace? -// tolerance: Percentage error margin to allow. (Def: kTolerance) +// tolerance: Percentage error margin to allow. (Def: kUseDefTol) // excess: Nr. of useconds. (Def: kMarkExcess) // MSBfirst: Bit order to save the data in. (Def: true) // Returns: diff --git a/lib/IRremoteESP8266-2.6.4/src/IRrecv.h b/lib/IRremoteESP8266-2.6.5/src/IRrecv.h old mode 100644 new mode 100755 similarity index 89% rename from lib/IRremoteESP8266-2.6.4/src/IRrecv.h rename to lib/IRremoteESP8266-2.6.5/src/IRrecv.h index 30fa8b120fa3..72c168269ee3 --- a/lib/IRremoteESP8266-2.6.4/src/IRrecv.h +++ b/lib/IRremoteESP8266-2.6.5/src/IRrecv.h @@ -32,8 +32,9 @@ const uint8_t kIdleState = 2; const uint8_t kMarkState = 3; const uint8_t kSpaceState = 4; const uint8_t kStopState = 5; -const uint8_t kTolerance = 25; // default percent tolerance in measurements. -const uint16_t kRawTick = 2; // Capture tick to uSec factor. +const uint8_t kTolerance = 25; // default percent tolerance in measurements. +const uint8_t kUseDefTol = 255; // Indicate to use the class default tolerance. +const uint16_t kRawTick = 2; // Capture tick to uSec factor. #define RAWTICK kRawTick // Deprecated. For legacy user code support only. // How long (ms) before we give up wait for more data? // Don't exceed kMaxTimeoutMs without a good reason. @@ -122,6 +123,8 @@ class IRrecv { const bool save_buffer = false); // Constructor #endif // ESP32 ~IRrecv(void); // Destructor + void setTolerance(const uint8_t percent = kTolerance); + uint8_t getTolerance(void); bool decode(decode_results *results, irparams_t *save = NULL); void enableIRIn(const bool pullup = false); void disableIRIn(void); @@ -130,32 +133,40 @@ class IRrecv { #if DECODE_HASH void setUnknownThreshold(const uint16_t length); #endif - static bool match(uint32_t measured, uint32_t desired, - uint8_t tolerance = kTolerance, uint16_t delta = 0); - static bool matchMark(uint32_t measured, uint32_t desired, - uint8_t tolerance = kTolerance, - int16_t excess = kMarkExcess); - static bool matchSpace(uint32_t measured, uint32_t desired, - uint8_t tolerance = kTolerance, - int16_t excess = kMarkExcess); + bool match(const uint32_t measured, const uint32_t desired, + const uint8_t tolerance = kUseDefTol, + const uint16_t delta = 0); + bool matchMark(const uint32_t measured, const uint32_t desired, + const uint8_t tolerance = kUseDefTol, + const int16_t excess = kMarkExcess); + bool matchSpace(const uint32_t measured, const uint32_t desired, + const uint8_t tolerance = kUseDefTol, + const int16_t excess = kMarkExcess); #ifndef UNIT_TEST private: #endif irparams_t *irparams_save; + uint8_t _tolerance; +#if defined(ESP32) uint8_t _timer_num; +#endif // defined(ESP32) #if DECODE_HASH uint16_t _unknown_threshold; #endif // These are called by decode + uint8_t _validTolerance(const uint8_t percentage); void copyIrParams(volatile irparams_t *src, irparams_t *dst); - int16_t compare(uint16_t oldval, uint16_t newval); - static uint32_t ticksLow(uint32_t usecs, uint8_t tolerance = kTolerance, - uint16_t delta = 0); - static uint32_t ticksHigh(uint32_t usecs, uint8_t tolerance = kTolerance, - uint16_t delta = 0); - bool matchAtLeast(uint32_t measured, uint32_t desired, - uint8_t tolerance = kTolerance, uint16_t delta = 0); + uint16_t compare(const uint16_t oldval, const uint16_t newval); + uint32_t ticksLow(const uint32_t usecs, + const uint8_t tolerance = kUseDefTol, + const uint16_t delta = 0); + uint32_t ticksHigh(const uint32_t usecs, + const uint8_t tolerance = kUseDefTol, + const uint16_t delta = 0); + bool matchAtLeast(const uint32_t measured, const uint32_t desired, + const uint8_t tolerance = kUseDefTol, + const uint16_t delta = 0); uint16_t _matchGeneric(volatile uint16_t *data_ptr, uint64_t *result_bits_ptr, uint8_t *result_ptr, @@ -171,20 +182,20 @@ class IRrecv { const uint16_t footermark, const uint32_t footerspace, const bool atleast = false, - const uint8_t tolerance = kTolerance, + const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); match_result_t matchData(volatile uint16_t *data_ptr, const uint16_t nbits, const uint16_t onemark, const uint32_t onespace, const uint16_t zeromark, const uint32_t zerospace, - const uint8_t tolerance = kTolerance, + const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); uint16_t matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr, const uint16_t remaining, const uint16_t nbytes, const uint16_t onemark, const uint32_t onespace, const uint16_t zeromark, const uint32_t zerospace, - const uint8_t tolerance = kTolerance, + const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); uint16_t matchGeneric(volatile uint16_t *data_ptr, @@ -195,7 +206,7 @@ class IRrecv { const uint16_t zeromark, const uint32_t zerospace, const uint16_t footermark, const uint32_t footerspace, const bool atleast = false, - const uint8_t tolerance = kTolerance, + const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); uint16_t matchGeneric(volatile uint16_t *data_ptr, uint8_t *result_ptr, @@ -206,7 +217,7 @@ class IRrecv { const uint16_t footermark, const uint32_t footerspace, const bool atleast = false, - const uint8_t tolerance = kTolerance, + const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); bool decodeHash(decode_results *results); @@ -249,7 +260,7 @@ class IRrecv { #endif #if (DECODE_RC5 || DECODE_R6 || DECODE_LASERTAG || DECODE_MWM) int16_t getRClevel(decode_results *results, uint16_t *offset, uint16_t *used, - uint16_t bitTime, uint8_t tolerance = kTolerance, + uint16_t bitTime, uint8_t tolerance = kUseDefTol, int16_t excess = kMarkExcess, uint16_t delta = 0, uint8_t maxwidth = 3); #endif @@ -348,6 +359,11 @@ class IRrecv { const uint16_t nbits = kDaikin128Bits, const bool strict = true); #endif // DECODE_DAIKIN128 +#if DECODE_DAIKIN152 + bool decodeDaikin152(decode_results *results, + const uint16_t nbits = kDaikin152Bits, + const bool strict = true); +#endif // DECODE_DAIKIN152 #if DECODE_DAIKIN160 bool decodeDaikin160(decode_results *results, const uint16_t nbits = kDaikin160Bits, @@ -474,6 +490,11 @@ bool decodeNeoclima(decode_results *results, const uint16_t nbits = kNeoclimaBits, const bool strict = true); #endif // DECODE_NEOCLIMA +#if DECODE_AMCOR +bool decodeAmcor(decode_results *results, + const uint16_t nbits = kAmcorBits, + const bool strict = true); +#endif // DECODE_AMCOR }; #endif // IRRECV_H_ diff --git a/lib/IRremoteESP8266-2.6.4/src/IRremoteESP8266.h b/lib/IRremoteESP8266-2.6.5/src/IRremoteESP8266.h old mode 100644 new mode 100755 similarity index 96% rename from lib/IRremoteESP8266-2.6.4/src/IRremoteESP8266.h rename to lib/IRremoteESP8266-2.6.5/src/IRremoteESP8266.h index 6c982af74739..0e1f00fa3cf8 --- a/lib/IRremoteESP8266-2.6.4/src/IRremoteESP8266.h +++ b/lib/IRremoteESP8266-2.6.5/src/IRremoteESP8266.h @@ -51,13 +51,14 @@ #endif // UNIT_TEST // Library Version -#define _IRREMOTEESP8266_VERSION_ "2.6.4" +#define _IRREMOTEESP8266_VERSION_ "2.6.5" // Supported IR protocols // Each protocol you include costs memory and, during decode, costs time // Disable (set to false) all the protocols you do not need/want! // The Air Conditioner protocols are the most expensive memory-wise. // -/* + +#ifdef USE_IR_REMOTE_FULL // full IR protocols #define DECODE_HASH true // Semi-unique code for unknown messages #define SEND_RAW true @@ -247,7 +248,14 @@ #define DECODE_DAIKIN128 true #define SEND_DAIKIN128 true -*/ + +#define DECODE_AMCOR true +#define SEND_AMCOR true + +#define DECODE_DAIKIN152 true +#define SEND_DAIKIN152 true + +#else // defined(FIRMWARE_IR) || defined(FIRMWARE_IR_CUSTOM) // full IR protocols // Tasmota supported protocols (less protocols is less code size) #define DECODE_HASH true // Semi-unique code for unknown messages @@ -440,6 +448,8 @@ #define DECODE_DAIKIN128 false #define SEND_DAIKIN128 true +#endif // defined(FIRMWARE_IR) || defined(FIRMWARE_IR_CUSTOM) // full IR protocols + #if (DECODE_ARGO || DECODE_DAIKIN || DECODE_FUJITSU_AC || DECODE_GREE || \ DECODE_KELVINATOR || DECODE_MITSUBISHI_AC || DECODE_TOSHIBA_AC || \ DECODE_TROTEC || DECODE_HAIER_AC || DECODE_HITACHI_AC || \ @@ -448,7 +458,8 @@ DECODE_PANASONIC_AC || DECODE_MWM || DECODE_DAIKIN2 || \ DECODE_VESTEL_AC || DECODE_TCL112AC || DECODE_MITSUBISHIHEAVY || \ DECODE_DAIKIN216 || DECODE_SHARP_AC || DECODE_DAIKIN160 || \ - DECODE_NEOCLIMA || DECODE_DAIKIN176 || DECODE_DAIKIN128) + DECODE_NEOCLIMA || DECODE_DAIKIN176 || DECODE_DAIKIN128 || \ + DECODE_AMCOR || DECODE_DAIKIN152) #define DECODE_AC true // We need some common infrastructure for decoding A/Cs. #else #define DECODE_AC false // We don't need that infrastructure. @@ -536,8 +547,10 @@ enum decode_type_t { NEOCLIMA, DAIKIN176, DAIKIN128, + AMCOR, + DAIKIN152, // 70 // Add new entries before this one, and update it to point to the last entry. - kLastDecodeType = DAIKIN128, + kLastDecodeType = DAIKIN152, }; // Message lengths & required repeat values @@ -546,6 +559,9 @@ const uint16_t kSingleRepeat = 1; const uint16_t kAiwaRcT501Bits = 15; const uint16_t kAiwaRcT501MinRepeats = kSingleRepeat; +const uint16_t kAmcorStateLength = 8; +const uint16_t kAmcorBits = kAmcorStateLength * 8; +const uint16_t kAmcorDefaultRepeat = kSingleRepeat; const uint16_t kArgoStateLength = 12; const uint16_t kArgoBits = kArgoStateLength * 8; const uint16_t kArgoDefaultRepeat = kNoRepeat; @@ -567,6 +583,9 @@ const uint16_t kDaikin160DefaultRepeat = kNoRepeat; const uint16_t kDaikin128StateLength = 16; const uint16_t kDaikin128Bits = kDaikin128StateLength * 8; const uint16_t kDaikin128DefaultRepeat = kNoRepeat; +const uint16_t kDaikin152StateLength = 19; +const uint16_t kDaikin152Bits = kDaikin152StateLength * 8; +const uint16_t kDaikin152DefaultRepeat = kNoRepeat; const uint16_t kDaikin176StateLength = 22; const uint16_t kDaikin176Bits = kDaikin176StateLength * 8; const uint16_t kDaikin176DefaultRepeat = kNoRepeat; diff --git a/lib/IRremoteESP8266-2.6.4/src/IRsend.cpp b/lib/IRremoteESP8266-2.6.5/src/IRsend.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/IRsend.cpp rename to lib/IRremoteESP8266-2.6.5/src/IRsend.cpp index 6e36c7809c52..b094fdff5bcc --- a/lib/IRremoteESP8266-2.6.4/src/IRsend.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/IRsend.cpp @@ -500,6 +500,7 @@ uint16_t IRsend::minRepeats(const decode_type_t protocol) { switch (protocol) { // Single repeats case AIWA_RC_T501: + case AMCOR: case COOLIX: case GICABLE: case INAX: @@ -574,6 +575,7 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) { case MAGIQUEST: case VESTEL_AC: return 56; + case AMCOR: case PIONEER: return 64; case ARGO: @@ -581,7 +583,9 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) { case DAIKIN: return kDaikinBits; case DAIKIN128: - return kDaikin128Bits; + return kDaikin128Bits; + case DAIKIN152: + return kDaikin152Bits; case DAIKIN160: return kDaikin160Bits; case DAIKIN176: @@ -841,6 +845,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data, bool IRsend::send(const decode_type_t type, const unsigned char *state, const uint16_t nbytes) { switch (type) { +#if SEND_AMCOR + case AMCOR: + sendAmcor(state, nbytes); + break; +#endif #if SEND_ARGO case ARGO: sendArgo(state, nbytes); @@ -856,6 +865,11 @@ bool IRsend::send(const decode_type_t type, const unsigned char *state, sendDaikin128(state, nbytes); break; #endif // SEND_DAIKIN128 +#if SEND_DAIKIN152 + case DAIKIN152: + sendDaikin152(state, nbytes); + break; +#endif // SEND_DAIKIN152 #if SEND_DAIKIN160 case DAIKIN160: sendDaikin160(state, nbytes); diff --git a/lib/IRremoteESP8266-2.6.4/src/IRsend.h b/lib/IRremoteESP8266-2.6.5/src/IRsend.h old mode 100644 new mode 100755 similarity index 95% rename from lib/IRremoteESP8266-2.6.4/src/IRsend.h rename to lib/IRremoteESP8266-2.6.5/src/IRsend.h index 8984e612aead..cbccee479d91 --- a/lib/IRremoteESP8266-2.6.4/src/IRsend.h +++ b/lib/IRremoteESP8266-2.6.5/src/IRsend.h @@ -49,6 +49,8 @@ namespace stdAc { kHeat = 2, kDry = 3, kFan = 4, + // Add new entries before this one, and update it to point to the last entry + kLastOpmodeEnum = kFan, }; enum class fanspeed_t { @@ -58,6 +60,8 @@ namespace stdAc { kMedium = 3, kHigh = 4, kMax = 5, + // Add new entries before this one, and update it to point to the last entry + kLastFanspeedEnum = kMax, }; enum class swingv_t { @@ -68,6 +72,8 @@ namespace stdAc { kMiddle = 3, kLow = 4, kLowest = 5, + // Add new entries before this one, and update it to point to the last entry + kLastSwingvEnum = kLowest, }; enum class swingh_t { @@ -78,6 +84,9 @@ namespace stdAc { kMiddle = 3, kRight = 4, kRightMax = 5, + kWide = 6, // a.k.a. left & right at the same time. + // Add new entries before this one, and update it to point to the last entry + kLastSwinghEnum = kWide, }; // Structure to hold a common A/C state. @@ -311,6 +320,11 @@ class IRsend { const uint16_t nbytes = kDaikin128StateLength, const uint16_t repeat = kDaikin128DefaultRepeat); #endif // SEND_DAIKIN128 +#if SEND_DAIKIN152 + void sendDaikin152(const unsigned char data[], + const uint16_t nbytes = kDaikin152StateLength, + const uint16_t repeat = kDaikin152DefaultRepeat); +#endif // SEND_DAIKIN152 #if SEND_DAIKIN160 void sendDaikin160(const unsigned char data[], const uint16_t nbytes = kDaikin160StateLength, @@ -464,6 +478,11 @@ class IRsend { const uint16_t nbytes = kNeoclimaStateLength, const uint16_t repeat = kNeoclimaMinRepeat); #endif // SEND_NEOCLIMA +#if SEND_AMCOR + void sendAmcor(const unsigned char data[], + const uint16_t nbytes = kAmcorStateLength, + const uint16_t repeat = kAmcorDefaultRepeat); +#endif // SEND_AMCOR protected: diff --git a/lib/IRremoteESP8266-2.6.4/src/IRtimer.cpp b/lib/IRremoteESP8266-2.6.5/src/IRtimer.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/IRtimer.cpp rename to lib/IRremoteESP8266-2.6.5/src/IRtimer.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/IRtimer.h b/lib/IRremoteESP8266-2.6.5/src/IRtimer.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/IRtimer.h rename to lib/IRremoteESP8266-2.6.5/src/IRtimer.h diff --git a/lib/IRremoteESP8266-2.6.4/src/IRutils.cpp b/lib/IRremoteESP8266-2.6.5/src/IRutils.cpp old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/src/IRutils.cpp rename to lib/IRremoteESP8266-2.6.5/src/IRutils.cpp index cd7c72307f28..6f589aa3ddb8 --- a/lib/IRremoteESP8266-2.6.4/src/IRutils.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/IRutils.cpp @@ -95,6 +95,8 @@ decode_type_t strToDecodeType(const char * const str) { return decode_type_t::UNUSED; else if (!strcasecmp(str, "AIWA_RC_T501")) return decode_type_t::AIWA_RC_T501; + else if (!strcasecmp(str, "AMCOR")) + return decode_type_t::AMCOR; else if (!strcasecmp(str, "ARGO")) return decode_type_t::ARGO; else if (!strcasecmp(str, "CARRIER_AC")) @@ -105,6 +107,8 @@ decode_type_t strToDecodeType(const char * const str) { return decode_type_t::DAIKIN; else if (!strcasecmp(str, "DAIKIN128")) return decode_type_t::DAIKIN128; + else if (!strcasecmp(str, "DAIKIN152")) + return decode_type_t::DAIKIN152; else if (!strcasecmp(str, "DAIKIN160")) return decode_type_t::DAIKIN160; else if (!strcasecmp(str, "DAIKIN176")) @@ -254,6 +258,9 @@ String typeToString(const decode_type_t protocol, const bool isRepeat) { case AIWA_RC_T501: result = F("AIWA_RC_T501"); break; + case AMCOR: + result = F("AMCOR"); + break; case ARGO: result = F("ARGO"); break; @@ -269,6 +276,9 @@ String typeToString(const decode_type_t protocol, const bool isRepeat) { case DAIKIN128: result = F("DAIKIN128"); break; + case DAIKIN152: + result = F("DAIKIN152"); + break; case DAIKIN160: result = F("DAIKIN160"); break; @@ -467,9 +477,11 @@ String typeToString(const decode_type_t protocol, const bool isRepeat) { // Does the given protocol use a complex state as part of the decode? bool hasACState(const decode_type_t protocol) { switch (protocol) { + case AMCOR: case ARGO: case DAIKIN: case DAIKIN128: + case DAIKIN152: case DAIKIN160: case DAIKIN176: case DAIKIN2: diff --git a/lib/IRremoteESP8266-2.6.4/src/IRutils.h b/lib/IRremoteESP8266-2.6.5/src/IRutils.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/IRutils.h rename to lib/IRremoteESP8266-2.6.5/src/IRutils.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Aiwa.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Aiwa.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Aiwa.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Aiwa.cpp diff --git a/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.cpp new file mode 100755 index 000000000000..8c0b73c8c232 --- /dev/null +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.cpp @@ -0,0 +1,326 @@ +// Copyright 2019 David Conran + +// Supports: +// Brand: Amcor, Model: ADR-853H A/C +// Brand: Amcor, Model: TAC-495 remote +// Brand: Amcor, Model: TAC-444 remote + +#include "ir_Amcor.h" +#include +#include "IRrecv.h" +#include "IRsend.h" +#include "IRutils.h" + +// Constants +// Ref: +// https://github.com/crankyoldgit/IRremoteESP8266/issues/385 +const uint16_t kAmcorHdrMark = 8200; +const uint16_t kAmcorHdrSpace = 4200; +const uint16_t kAmcorOneMark = 1500; +const uint16_t kAmcorZeroMark = 600; +const uint16_t kAmcorOneSpace = kAmcorZeroMark; +const uint16_t kAmcorZeroSpace = kAmcorOneMark; +const uint16_t kAmcorFooterMark = 1900; +const uint16_t kAmcorGap = 34300; +const uint8_t kAmcorTolerance = 40; + +using irutils::addBoolToString; +using irutils::addModeToString; +using irutils::addFanToString; +using irutils::addTempToString; + +#if SEND_AMCOR +// Send a Amcor HVAC formatted message. +// +// Args: +// data: The message to be sent. +// nbytes: The byte size of the array being sent. typically kAmcorStateLength. +// repeat: The number of times the message is to be repeated. +// +// Status: STABLE / Reported as working. +// +void IRsend::sendAmcor(const unsigned char data[], const uint16_t nbytes, + const uint16_t repeat) { + // Check if we have enough bytes to send a proper message. + if (nbytes < kAmcorStateLength) return; + sendGeneric(kAmcorHdrMark, kAmcorHdrSpace, kAmcorOneMark, kAmcorOneSpace, + kAmcorZeroMark, kAmcorZeroSpace, kAmcorFooterMark, kAmcorGap, + data, nbytes, 38, false, repeat, kDutyDefault); +} +#endif + +#if DECODE_AMCOR +// Decode the supplied Amcor HVAC message. +// Args: +// results: Ptr to the data to decode and where to store the decode result. +// nbits: Nr. of bits to expect in the data portion. +// Typically kAmcorBits. +// strict: Flag to indicate if we strictly adhere to the specification. +// Returns: +// boolean: True if it can decode it, false if it can't. +// +// Status: STABLE / Reported as working. +// +bool IRrecv::decodeAmcor(decode_results *results, uint16_t nbits, + bool strict) { + if (results->rawlen < 2 * nbits + kHeader - 1) + return false; // Can't possibly be a valid Amcor message. + if (strict && nbits != kAmcorBits) + return false; // We expect Amcor to be 64 bits of message. + + uint16_t offset = kStartOffset; + + uint16_t used; + // Header + Data Block (64 bits) + Footer + used = matchGeneric(results->rawbuf + offset, results->state, + results->rawlen - offset, 64, + kAmcorHdrMark, kAmcorHdrSpace, + kAmcorOneMark, kAmcorOneSpace, + kAmcorZeroMark, kAmcorZeroSpace, + kAmcorFooterMark, kAmcorGap, true, + kAmcorTolerance, 0, false); + if (!used) return false; + offset += used; + + if (strict) { + if (!IRAmcorAc::validChecksum(results->state)) return false; + } + + // Success + results->bits = nbits; + results->decode_type = AMCOR; + // No need to record the state as we stored it as we decoded it. + // As we use result->state, we don't record value, address, or command as it + // is a union data type. + return true; +} +#endif + +IRAmcorAc::IRAmcorAc(const uint16_t pin, const bool inverted, + const bool use_modulation) + : _irsend(pin, inverted, use_modulation) { this->stateReset(); } + +void IRAmcorAc::begin(void) { _irsend.begin(); } + +#if SEND_AMCOR +void IRAmcorAc::send(const uint16_t repeat) { + this->checksum(); // Create valid checksum before sending + _irsend.sendAmcor(remote_state, kAmcorStateLength, repeat); +} +#endif // SEND_AMCOR + +uint8_t IRAmcorAc::calcChecksum(const uint8_t state[], const uint16_t length) { + return irutils::sumNibbles(state, length - 1); +} + +bool IRAmcorAc::validChecksum(const uint8_t state[], const uint16_t length) { + return (state[length - 1] == IRAmcorAc::calcChecksum(state, length)); +} + +void IRAmcorAc::checksum(void) { + remote_state[kAmcorChecksumByte] = IRAmcorAc::calcChecksum(remote_state, + kAmcorStateLength); +} + +void IRAmcorAc::stateReset(void) { + for (uint8_t i = 1; i < kAmcorStateLength; i++) remote_state[i] = 0x0; + remote_state[0] = 0x01; + setFan(kAmcorFanAuto); + setMode(kAmcorAuto); + setTemp(25); // 25C +} + +uint8_t* IRAmcorAc::getRaw(void) { + this->checksum(); // Ensure correct bit array before returning + return remote_state; +} + +void IRAmcorAc::setRaw(const uint8_t state[]) { + for (uint8_t i = 0; i < kAmcorStateLength; i++) remote_state[i] = state[i]; +} + +void IRAmcorAc::on(void) { setPower(true); } + +void IRAmcorAc::off(void) { setPower(false); } + +void IRAmcorAc::setPower(const bool on) { + remote_state[kAmcorPowerByte] &= ~kAmcorPowerMask; + remote_state[kAmcorPowerByte] |= (on ? kAmcorPowerOn : kAmcorPowerOff); +} + +bool IRAmcorAc::getPower(void) { + return ((remote_state[kAmcorPowerByte] & kAmcorPowerMask) == kAmcorPowerOn); +} + +// Set the temp in deg C +void IRAmcorAc::setTemp(const uint8_t degrees) { + uint8_t temp = std::max(kAmcorMinTemp, degrees); + temp = std::min(kAmcorMaxTemp, temp); + + temp <<= 1; + remote_state[kAmcorTempByte] &= ~kAmcorTempMask; + remote_state[kAmcorTempByte] |= temp; +} + +uint8_t IRAmcorAc::getTemp(void) { + return (remote_state[kAmcorTempByte] & kAmcorTempMask) >> 1; +} + +// Maximum Cooling or Hearing +void IRAmcorAc::setMax(const bool on) { + if (on) { + switch (getMode()) { + case kAmcorCool: + setTemp(kAmcorMinTemp); + break; + case kAmcorHeat: + setTemp(kAmcorMaxTemp); + break; + default: // Not allowed in all other operating modes. + return; + } + remote_state[kAmcorSpecialByte] |= kAmcorMaxMask; + } else { + remote_state[kAmcorSpecialByte] &= ~kAmcorMaxMask; + } +} + +bool IRAmcorAc::getMax(void) { + return ((remote_state[kAmcorSpecialByte] & kAmcorMaxMask) == kAmcorMaxMask); +} + +// Set the speed of the fan +void IRAmcorAc::setFan(const uint8_t speed) { + switch (speed) { + case kAmcorFanAuto: + case kAmcorFanMin: + case kAmcorFanMed: + case kAmcorFanMax: + remote_state[kAmcorModeFanByte] &= ~kAmcorFanMask; + remote_state[kAmcorModeFanByte] |= speed << 4; + break; + default: + setFan(kAmcorFanAuto); + } +} + +uint8_t IRAmcorAc::getFan(void) { + return (remote_state[kAmcorModeFanByte] & kAmcorFanMask) >> 4; +} + +uint8_t IRAmcorAc::getMode(void) { + return remote_state[kAmcorModeFanByte] & kAmcorModeMask; +} + +void IRAmcorAc::setMode(const uint8_t mode) { + remote_state[kAmcorSpecialByte] &= ~kAmcorVentMask; // Clear the vent setting + switch (mode) { + case kAmcorFan: + remote_state[kAmcorSpecialByte] |= kAmcorVentMask; // Set the vent option + // FALL-THRU + case kAmcorCool: + case kAmcorHeat: + case kAmcorDry: + case kAmcorAuto: + // Mask out bits + remote_state[kAmcorModeFanByte] &= ~kAmcorModeMask; + // Set the mode at bit positions + remote_state[kAmcorModeFanByte] |= mode; + return; + default: + this->setMode(kAmcorAuto); + } +} + +// Convert a standard A/C mode into its native mode. +uint8_t IRAmcorAc::convertMode(const stdAc::opmode_t mode) { + switch (mode) { + case stdAc::opmode_t::kCool: + return kAmcorCool; + case stdAc::opmode_t::kHeat: + return kAmcorHeat; + case stdAc::opmode_t::kDry: + return kAmcorDry; + case stdAc::opmode_t::kFan: + return kAmcorFan; + default: + return kAmcorAuto; + } +} + +// Convert a standard A/C Fan speed into its native fan speed. +uint8_t IRAmcorAc::convertFan(const stdAc::fanspeed_t speed) { + switch (speed) { + case stdAc::fanspeed_t::kMin: + case stdAc::fanspeed_t::kLow: + return kAmcorFanMin; + case stdAc::fanspeed_t::kMedium: + return kAmcorFanMed; + case stdAc::fanspeed_t::kHigh: + case stdAc::fanspeed_t::kMax: + return kAmcorFanMax; + default: + return kAmcorFanAuto; + } +} + +// Convert a native mode to it's common equivalent. +stdAc::opmode_t IRAmcorAc::toCommonMode(const uint8_t mode) { + switch (mode) { + case kAmcorCool: return stdAc::opmode_t::kCool; + case kAmcorHeat: return stdAc::opmode_t::kHeat; + case kAmcorDry: return stdAc::opmode_t::kDry; + case kAmcorFan: return stdAc::opmode_t::kFan; + default: return stdAc::opmode_t::kAuto; + } +} + +// Convert a native fan speed to it's common equivalent. +stdAc::fanspeed_t IRAmcorAc::toCommonFanSpeed(const uint8_t speed) { + switch (speed) { + case kAmcorFanMax: return stdAc::fanspeed_t::kMax; + case kAmcorFanMed: return stdAc::fanspeed_t::kMedium; + case kAmcorFanMin: return stdAc::fanspeed_t::kMin; + default: return stdAc::fanspeed_t::kAuto; + } +} + +// Convert the A/C state to it's common equivalent. +stdAc::state_t IRAmcorAc::toCommon(void) { + stdAc::state_t result; + result.protocol = decode_type_t::AMCOR; + result.power = this->getPower(); + result.mode = this->toCommonMode(this->getMode()); + result.celsius = true; + result.degrees = this->getTemp(); + result.fanspeed = this->toCommonFanSpeed(this->getFan()); + // Not supported. + result.model = -1; + result.turbo = false; + result.swingv = stdAc::swingv_t::kOff; + result.swingh = stdAc::swingh_t::kOff; + result.light = false; + result.filter = false; + result.econo = false; + result.quiet = false; + result.clean = false; + result.beep = false; + result.sleep = -1; + result.clock = -1; + return result; +} + +// Convert the internal state into a human readable string. +String IRAmcorAc::toString() { + String result = ""; + result.reserve(70); // Reserve some heap for the string to reduce fragging. + result += addBoolToString(getPower(), F("Power"), false); + result += addModeToString(getMode(), kAmcorAuto, kAmcorCool, + kAmcorHeat, kAmcorDry, kAmcorFan); + result += addFanToString(getFan(), kAmcorFanMax, kAmcorFanMin, + kAmcorFanAuto, kAmcorFanAuto, + kAmcorFanMed); + result += addTempToString(getTemp()); + result += addBoolToString(getMax(), F("Max")); + return result; +} diff --git a/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.h b/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.h new file mode 100755 index 000000000000..73beb27a7547 --- /dev/null +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Amcor.h @@ -0,0 +1,118 @@ +// Amcor A/C +// +// Copyright 2019 David Conran + +#ifndef IR_AMCOR_H_ +#define IR_AMCOR_H_ + +#define __STDC_LIMIT_MACROS +#include +#ifndef UNIT_TEST +#include +#endif +#include "IRremoteESP8266.h" +#include "IRsend.h" +#ifdef UNIT_TEST +#include "IRsend_test.h" +#endif + +// Supports: +// Brand: Amcor, Model: ADR-853H A/C +// Brand: Amcor, Model: TAC-495 remote +// Brand: Amcor, Model: TAC-444 remote +// Ref: +// https://github.com/crankyoldgit/IRremoteESP8266/issues/834 +// Kudos: +// ldellus: For the breakdown and mapping of the bit values. + +// Constants + + +// state[1] +const uint8_t kAmcorModeFanByte = 1; +// Fan Control +const uint8_t kAmcorFanMin = 0b001; +const uint8_t kAmcorFanMed = 0b010; +const uint8_t kAmcorFanMax = 0b011; +const uint8_t kAmcorFanAuto = 0b100; +const uint8_t kAmcorFanMask = 0b01110000; +// Modes +const uint8_t kAmcorCool = 0b001; +const uint8_t kAmcorHeat = 0b010; +const uint8_t kAmcorFan = 0b011; // Aka "Vent" +const uint8_t kAmcorDry = 0b100; +const uint8_t kAmcorAuto = 0b101; +const uint8_t kAmcorModeMask = 0b00000111; + +// state[2] +const uint8_t kAmcorTempByte = 2; +// Temperature +const uint8_t kAmcorMinTemp = 12; // Celsius +const uint8_t kAmcorMaxTemp = 32; // Celsius +const uint8_t kAmcorTempMask = 0b01111110; + +// state[5] +// Power +const uint8_t kAmcorPowerByte = 5; +const uint8_t kAmcorPowerMask = 0b11110000; +const uint8_t kAmcorPowerOn = 0b00110000; // 0x30 +const uint8_t kAmcorPowerOff = 0b11000000; // 0xC0 + +// state[6] +const uint8_t kAmcorSpecialByte = 6; +// Max Mode (aka "Lo" in Cool and "Hi" in Heat) +const uint8_t kAmcorMaxMask = 0b00000011; // 0x03 +// "Vent" Mode +const uint8_t kAmcorVentMask = 0b11000000; // 0xC0 + +// state[7] +// Checksum byte. +const uint8_t kAmcorChecksumByte = kAmcorStateLength - 1; + +// Classes +class IRAmcorAc { + public: + explicit IRAmcorAc(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + + void stateReset(); +#if SEND_AMCOR + void send(const uint16_t repeat = kAmcorDefaultRepeat); + uint8_t calibrate(void) { return _irsend.calibrate(); } +#endif // SEND_AMCOR + void begin(); + static uint8_t calcChecksum(const uint8_t state[], + const uint16_t length = kAmcorStateLength); + static bool validChecksum(const uint8_t state[], + const uint16_t length = kAmcorStateLength); + void setPower(const bool state); + bool getPower(); + void on(); + void off(); + void setTemp(const uint8_t temp); + uint8_t getTemp(); + void setMax(const bool on); + bool getMax(void); + void setFan(const uint8_t speed); + uint8_t getFan(); + void setMode(const uint8_t mode); + uint8_t getMode(); + uint8_t* getRaw(); + void setRaw(const uint8_t state[]); + uint8_t convertMode(const stdAc::opmode_t mode); + uint8_t convertFan(const stdAc::fanspeed_t speed); + static stdAc::opmode_t toCommonMode(const uint8_t mode); + static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); + stdAc::state_t toCommon(void); + String toString(); +#ifndef UNIT_TEST + + private: + IRsend _irsend; +#else + IRsendTest _irsend; +#endif + uint8_t remote_state[kAmcorStateLength]; // The state of the IR remote. + void checksum(void); +}; +#endif // IR_AMCOR_H_ diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Argo.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Argo.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Argo.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Argo.cpp index 7a2ecec19cb5..522ede7e6fb9 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Argo.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Argo.cpp @@ -422,7 +422,7 @@ bool IRrecv::decodeArgo(decode_results *results, const uint16_t nbits, kArgoBitMark, kArgoOneSpace, kArgoBitMark, kArgoZeroSpace, 0, 0, // Footer (None, allegedly. This seems very wrong.) - true, kTolerance, 0, false)) return false; + true, _tolerance, 0, false)) return false; // Compliance // Verify we got a valid checksum. diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Argo.h b/lib/IRremoteESP8266-2.6.5/src/ir_Argo.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Argo.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Argo.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Carrier.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Carrier.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Carrier.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Carrier.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Coolix.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Coolix.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Coolix.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Coolix.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Coolix.h b/lib/IRremoteESP8266-2.6.5/src/ir_Coolix.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Coolix.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Coolix.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Daikin.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Daikin.cpp old mode 100644 new mode 100755 similarity index 94% rename from lib/IRremoteESP8266-2.6.4/src/ir_Daikin.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Daikin.cpp index bca94841c981..317526f5ebe7 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Daikin.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Daikin.cpp @@ -1275,9 +1275,9 @@ bool IRrecv::decodeDaikin2(decode_results *results, uint16_t nbits, // Leader if (!matchMark(results->rawbuf[offset++], kDaikin2LeaderMark, - kDaikin2Tolerance)) return false; + _tolerance + kDaikin2Tolerance)) return false; if (!matchSpace(results->rawbuf[offset++], kDaikin2LeaderSpace, - kDaikin2Tolerance)) return false; + _tolerance + kDaikin2Tolerance)) return false; // Sections uint16_t pos = 0; @@ -1291,7 +1291,8 @@ bool IRrecv::decodeDaikin2(decode_results *results, uint16_t nbits, kDaikin2BitMark, kDaikin2ZeroSpace, kDaikin2BitMark, kDaikin2Gap, section >= kDaikin2Sections - 1, - kDaikin2Tolerance, kDaikinMarkExcess, false); + _tolerance + kDaikin2Tolerance, kDaikinMarkExcess, + false); if (used == 0) return false; offset += used; pos += ksectionSize[section]; @@ -2913,3 +2914,156 @@ bool IRrecv::decodeDaikin128(decode_results *results, const uint16_t nbits, return true; } #endif // DECODE_DAIKIN128 + +#if SEND_DAIKIN152 +// Send a Daikin 152 bit A/C message. +// +// Args: +// data: An array of kDaikin152StateLength bytes containing the IR command. +// +// Supported devices: +// - Daikin ARC480A5 remote. +// +// Status: Beta / Probably working. +// +// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +void IRsend::sendDaikin152(const unsigned char data[], const uint16_t nbytes, + const uint16_t repeat) { + for (uint16_t r = 0; r <= repeat; r++) { + // Leader + sendGeneric(0, 0, kDaikin152BitMark, kDaikin152OneSpace, + kDaikin152BitMark, kDaikin152ZeroSpace, + kDaikin152BitMark, kDaikin152Gap, + (uint64_t)0, kDaikin152LeaderBits, + kDaikin152Freq, false, 0, kDutyDefault); + // Header + Data + Footer + sendGeneric(kDaikin152HdrMark, kDaikin152HdrSpace, kDaikin152BitMark, + kDaikin152OneSpace, kDaikin152BitMark, kDaikin152ZeroSpace, + kDaikin152BitMark, kDaikin152Gap, data, + nbytes, kDaikin152Freq, false, 0, kDutyDefault); + } +} +#endif // SEND_DAIKIN152 + +#if DECODE_DAIKIN152 +// Decode the supplied Daikin 152 bit A/C message. +// Args: +// results: Ptr to the data to decode and where to store the decode result. +// nbits: Nr. of bits to expect in the data portion. (kDaikin152Bits) +// strict: Flag to indicate if we strictly adhere to the specification. +// Returns: +// boolean: True if it can decode it, false if it can't. +// +// Supported devices: +// - Daikin ARC480A5 remote. +// +// Status: Beta / Probably working. +// +// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +bool IRrecv::decodeDaikin152(decode_results *results, const uint16_t nbits, + const bool strict) { + if (results->rawlen < 2 * (5 + nbits + kFooter) + kHeader - 1) + return false; + if (nbits / 8 < kDaikin152StateLength) return false; + + // Compliance + if (strict && nbits != kDaikin152Bits) return false; + + uint16_t offset = kStartOffset; + uint16_t used; + + // Leader + uint64_t leader = 0; + used = matchGeneric(results->rawbuf + offset, &leader, + results->rawlen - offset, kDaikin152LeaderBits, + 0, 0, // No Header + kDaikin152BitMark, kDaikin152OneSpace, + kDaikin152BitMark, kDaikin152ZeroSpace, + kDaikin152BitMark, kDaikin152Gap, // Footer gap + false, _tolerance, kMarkExcess, false); + if (used == 0 || leader != 0) return false; + offset += used; + + // Header + Data + Footer + used = matchGeneric(results->rawbuf + offset, results->state, + results->rawlen - offset, nbits, + kDaikin152HdrMark, kDaikin152HdrSpace, + kDaikin152BitMark, kDaikin152OneSpace, + kDaikin152BitMark, kDaikin152ZeroSpace, + kDaikin152BitMark, kDaikin152Gap, + true, _tolerance, kMarkExcess, false); + if (used == 0) return false; + + // Compliance + if (strict) { + if (!IRDaikin152::validChecksum(results->state)) return false; + } + + // Success + results->decode_type = decode_type_t::DAIKIN152; + results->bits = nbits; + // No need to record the state as we stored it as we decoded it. + // As we use result->state, we don't record value, address, or command as it + // is a union data type. + return true; +} +#endif // DECODE_DAIKIN152 + +// Class for handling Daikin 152 bit / 19 byte A/C messages. +// +// Code by crankyoldgit. +// +// Supported Remotes: Daikin ARC480A5 remote +// +// Ref: +// https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +IRDaikin152::IRDaikin152(const uint16_t pin, const bool inverted, + const bool use_modulation) + : _irsend(pin, inverted, use_modulation) { stateReset(); } + +void IRDaikin152::begin() { _irsend.begin(); } + +#if SEND_DAIKIN152 +void IRDaikin152::send(const uint16_t repeat) { + checksum(); + _irsend.sendDaikin152(remote_state, kDaikin152StateLength, repeat); +} +#endif // SEND_DAIKIN152 + +// Verify the checksum is valid for a given state. +// Args: +// state: The array to verify the checksum of. +// length: The size of the state. +// Returns: +// A boolean. +bool IRDaikin152::validChecksum(uint8_t state[], const uint16_t length) { + // Validate the checksum of the given state. + if (length <= 1 || state[length - 1] != sumBytes(state, length - 1)) + return false; + else + return true; +} + +// Calculate and set the checksum values for the internal state. +void IRDaikin152::checksum() { + remote_state[kDaikin152StateLength - 1] = sumBytes( + remote_state, kDaikin152StateLength - 1); +} + +void IRDaikin152::stateReset() { + for (uint8_t i = 3; i < kDaikin152StateLength; i++) remote_state[i] = 0x00; + remote_state[0] = 0x11; + remote_state[1] = 0xDA; + remote_state[2] = 0x27; + // remote_state[19] is a checksum byte, it will be set by checksum(). +} + +uint8_t *IRDaikin152::getRaw() { + checksum(); // Ensure correct settings before sending. + return remote_state; +} + +void IRDaikin152::setRaw(const uint8_t new_code[]) { + for (uint8_t i = 0; i < kDaikin152StateLength; i++) + remote_state[i] = new_code[i]; +} diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Daikin.h b/lib/IRremoteESP8266-2.6.5/src/ir_Daikin.h old mode 100644 new mode 100755 similarity index 94% rename from lib/IRremoteESP8266-2.6.4/src/ir_Daikin.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Daikin.h index ad9e1c182c4a..98a38c64030d --- a/lib/IRremoteESP8266-2.6.4/src/ir_Daikin.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Daikin.h @@ -16,7 +16,7 @@ // Brand: Daikin, Model: FTXB12AXVJU A/C (DAIKIN128) // Brand: Daikin, Model: FTXB09AXVJU A/C (DAIKIN128) // Brand: Daikin, Model: BRC52B63 remote (DAIKIN128) - +// Brand: Daikin, Model: ARC480A5 remote (DAIKIN152) #ifndef IR_DAIKIN_H_ #define IR_DAIKIN_H_ @@ -32,7 +32,7 @@ #endif /* - Daikin AC map + Daikin AC map (i.e. DAIKIN, not the other variants) byte 6= b4:Comfort byte 7= checksum of the first part (and last byte before a 29ms pause) @@ -176,7 +176,7 @@ const uint16_t kDaikin2ZeroSpace = 420; const uint16_t kDaikin2Sections = 2; const uint16_t kDaikin2Section1Length = 20; const uint16_t kDaikin2Section2Length = 19; -const uint8_t kDaikin2Tolerance = kTolerance + 5; +const uint8_t kDaikin2Tolerance = 5; // Extra percentage tolerance const uint8_t kDaikin2BitSleepTimer = 0b00100000; const uint8_t kDaikin2BitPurify = 0b00010000; @@ -328,6 +328,17 @@ const uint8_t kDaikin128BitWall = 0b00001000; const uint8_t kDaikin128BitCeiling = 0b00000001; const uint8_t kDaikin128MaskLight = kDaikin128BitWall | kDaikin128BitCeiling; +// Another variant of the protocol for the Daikin ARC480A5 remote. +// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +const uint16_t kDaikin152Freq = 38000; // Modulation Frequency in Hz. +const uint8_t kDaikin152LeaderBits = 5; +const uint16_t kDaikin152HdrMark = 3492; +const uint16_t kDaikin152HdrSpace = 1718; +const uint16_t kDaikin152BitMark = 433; +const uint16_t kDaikin152OneSpace = 1529; +const uint16_t kDaikin152ZeroSpace = kDaikin152BitMark; +const uint16_t kDaikin152Gap = 25182; + // Legacy defines. #define DAIKIN_COOL kDaikinCool #define DAIKIN_HEAT kDaikinHeat @@ -603,6 +614,7 @@ class IRDaikin160 { void stateReset(); void checksum(); }; + // Class to emulate a Daikin BRC4C153 remote. class IRDaikin176 { public: @@ -721,4 +733,31 @@ class IRDaikin128 { void clearSleepTimerFlag(void); }; +// Class to emulate a Daikin ARC480A5 remote. +class IRDaikin152 { + public: + explicit IRDaikin152(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + +#if SEND_DAIKIN152 + void send(const uint16_t repeat = kDaikin152DefaultRepeat); + uint8_t calibrate(void) { return _irsend.calibrate(); } +#endif + void begin(); + uint8_t* getRaw(); + void setRaw(const uint8_t new_code[]); + static bool validChecksum(uint8_t state[], + const uint16_t length = kDaikin152StateLength); +#ifndef UNIT_TEST + + private: + IRsend _irsend; +#else + IRsendTest _irsend; +#endif + // # of bytes per command + uint8_t remote_state[kDaikin152StateLength]; + void stateReset(); + void checksum(); +}; #endif // IR_DAIKIN_H_ diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Denon.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Denon.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Denon.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Denon.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Dish.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Dish.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Dish.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Dish.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Electra.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Electra.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Electra.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Electra.cpp index 4c61da34dd5f..6b945aa3fa3b --- a/lib/IRremoteESP8266-2.6.4/src/ir_Electra.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Electra.cpp @@ -317,7 +317,7 @@ bool IRrecv::decodeElectraAC(decode_results *results, uint16_t nbits, kElectraAcBitMark, kElectraAcOneSpace, kElectraAcBitMark, kElectraAcZeroSpace, kElectraAcBitMark, kElectraAcMessageGap, true, - kTolerance, 0, false)) return false; + _tolerance, 0, false)) return false; // Compliance if (strict) { diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Electra.h b/lib/IRremoteESP8266-2.6.5/src/ir_Electra.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Electra.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Electra.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.cpp old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.cpp index 43695b9322d6..fa6a0ce8cbd2 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.cpp @@ -267,9 +267,6 @@ bool IRFujitsuAC::setRaw(const uint8_t newState[], const uint16_t length) { return true; } -// Set the requested power state of the A/C to off. -void IRFujitsuAC::off(void) { this->setCmd(kFujitsuAcCmdTurnOff); } - void IRFujitsuAC::stepHoriz(void) { this->setCmd(kFujitsuAcCmdStepHoriz); } void IRFujitsuAC::toggleSwingHoriz(const bool update) { @@ -336,6 +333,17 @@ uint8_t IRFujitsuAC::getCmd(const bool raw) { return _cmd; } +// Set the requested power state of the A/C. +void IRFujitsuAC::setPower(const bool on) { + this->setCmd(on ? kFujitsuAcCmdTurnOn : kFujitsuAcCmdTurnOff); +} + +// Set the requested power state of the A/C to off. +void IRFujitsuAC::off(void) { this->setPower(false); } + +// Set the requested power state of the A/C to on. +void IRFujitsuAC::on(void) { this->setPower(true); } + bool IRFujitsuAC::getPower(void) { return _cmd != kFujitsuAcCmdTurnOff; } void IRFujitsuAC::setOutsideQuiet(const bool on) { @@ -649,7 +657,7 @@ bool IRrecv::decodeFujitsuAC(decode_results* results, uint16_t nbits, match_result_t data_result = matchData(&(results->rawbuf[offset]), kFujitsuAcMinBits - 8, kFujitsuAcBitMark, kFujitsuAcOneSpace, kFujitsuAcBitMark, - kFujitsuAcZeroSpace, kTolerance, kMarkExcess, false); + kFujitsuAcZeroSpace, _tolerance, kMarkExcess, false); if (data_result.success == false) return false; // Fail if (data_result.data != 0x1010006314) return false; // Signature failed. dataBitsSoFar += kFujitsuAcMinBits - 8; @@ -666,7 +674,7 @@ bool IRrecv::decodeFujitsuAC(decode_results* results, uint16_t nbits, i++, dataBitsSoFar += 8, offset += data_result.used) { data_result = matchData( &(results->rawbuf[offset]), 8, kFujitsuAcBitMark, kFujitsuAcOneSpace, - kFujitsuAcBitMark, kFujitsuAcZeroSpace, kTolerance, kMarkExcess, false); + kFujitsuAcBitMark, kFujitsuAcZeroSpace, _tolerance, kMarkExcess, false); if (data_result.success == false) break; // Fail results->state[i] = data_result.data; } diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.h b/lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.h old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.h index 469e7ee9c7fb..e953f90589b0 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Fujitsu.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Fujitsu.h @@ -104,7 +104,6 @@ class IRFujitsuAC { uint8_t calibrate(void) { return _irsend.calibrate(); } #endif // SEND_FUJITSU_AC void begin(void); - void off(void); void stepHoriz(void); void toggleSwingHoriz(const bool update = true); void stepVert(void); @@ -123,6 +122,9 @@ class IRFujitsuAC { bool setRaw(const uint8_t newState[], const uint16_t length); uint8_t getStateLength(void); static bool validChecksum(uint8_t* state, const uint16_t length); + void setPower(const bool on); + void off(void); + void on(void); bool getPower(void); void setOutsideQuiet(const bool on); diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_GICable.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_GICable.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_GICable.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_GICable.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_GlobalCache.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_GlobalCache.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_GlobalCache.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_GlobalCache.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Goodweather.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Goodweather.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Goodweather.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Goodweather.cpp index a196cb7eff57..d8ac45f1b506 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Goodweather.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Goodweather.cpp @@ -419,7 +419,7 @@ bool IRrecv::decodeGoodweather(decode_results* results, data_result = matchData(&(results->rawbuf[offset]), 8, kGoodweatherBitMark, kGoodweatherOneSpace, kGoodweatherBitMark, kGoodweatherZeroSpace, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (data_result.success == false) return false; DPRINTLN("DEBUG: Normal byte read okay."); offset += data_result.used; @@ -428,7 +428,7 @@ bool IRrecv::decodeGoodweather(decode_results* results, data_result = matchData(&(results->rawbuf[offset]), 8, kGoodweatherBitMark, kGoodweatherOneSpace, kGoodweatherBitMark, kGoodweatherZeroSpace, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (data_result.success == false) return false; DPRINTLN("DEBUG: Inverted byte read okay."); offset += data_result.used; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Goodweather.h b/lib/IRremoteESP8266-2.6.5/src/ir_Goodweather.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Goodweather.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Goodweather.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Gree.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Gree.cpp old mode 100644 new mode 100755 similarity index 90% rename from lib/IRremoteESP8266-2.6.4/src/ir_Gree.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Gree.cpp index 2bfb8e8b59e4..a4d906424ebc --- a/lib/IRremoteESP8266-2.6.4/src/ir_Gree.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Gree.cpp @@ -35,6 +35,7 @@ using irutils::addLabeledString; using irutils::addModeToString; using irutils::addFanToString; using irutils::addTempToString; +using irutils::minsToString; #if SEND_GREE // Send a Gree Heat Pump message. @@ -222,12 +223,13 @@ void IRGreeAC::setTemp(const uint8_t temp) { uint8_t new_temp = std::max((uint8_t)kGreeMinTemp, temp); new_temp = std::min((uint8_t)kGreeMaxTemp, new_temp); if (getMode() == kGreeAuto) new_temp = 25; - remote_state[1] = (remote_state[1] & 0xF0U) | (new_temp - kGreeMinTemp); + remote_state[1] = (remote_state[1] & ~kGreeTempMask) | + (new_temp - kGreeMinTemp); } // Return the set temp. in deg C uint8_t IRGreeAC::getTemp(void) { - return ((remote_state[1] & 0xFU) + kGreeMinTemp); + return ((remote_state[1] & kGreeTempMask) + kGreeMinTemp); } // Set the speed of the fan, 0-3, 0 is auto, 1-3 is the speed @@ -359,6 +361,44 @@ uint8_t IRGreeAC::getSwingVerticalPosition(void) { return remote_state[4] & kGreeSwingPosMask; } +void IRGreeAC::setTimerEnabled(const bool on) { + if (on) + remote_state[1] |= kGreeTimerEnabledBit; + else + remote_state[1] &= ~kGreeTimerEnabledBit; +} + +bool IRGreeAC::getTimerEnabled(void) { + return remote_state[1] & kGreeTimerEnabledBit; +} + +// Returns the number of minutes the timer is set for. +uint16_t IRGreeAC::getTimer(void) { + uint16_t hrs = irutils::bcdToUint8( + (remote_state[2] & kGreeTimerHoursMask) | + ((remote_state[1] & kGreeTimerTensHrMask) >> 1)); + return hrs * 60 + ((remote_state[1] & kGreeTimerHalfHrBit) ? 30 : 0); +} + +// Set the A/C's timer to turn off in X many minutes. +// Stores time internally in 30 min units. +// e.g. 5 mins means 0 (& Off), 95 mins is 90 mins (& On). Max is 24 hours. +// +// Args: +// minutes: The number of minutes the timer should be set for. +void IRGreeAC::setTimer(const uint16_t minutes) { + // Clear the previous settings. + remote_state[1] &= ~kGreeTimer1Mask; + remote_state[2] &= ~kGreeTimerHoursMask; + uint16_t mins = std::min(kGreeTimerMax, minutes); // Bounds check. + setTimerEnabled(mins >= 30); // Timer is enabled when >= 30 mins. + uint8_t hours = mins / 60; + uint8_t halfhour = (mins % 60) < 30 ? 0 : 1; + // Set the "tens" digit of hours & the half hour. + remote_state[1] |= (((hours / 10) << 1) | halfhour) << 4; + // Set the "units" digit of hours. + remote_state[2] |= (hours % 10); +} // Convert a standard A/C mode into its native mode. uint8_t IRGreeAC::convertMode(const stdAc::opmode_t mode) { @@ -504,6 +544,11 @@ String IRGreeAC::toString(void) { result += F(" (Auto)"); break; } + result += F(", Timer: "); + if (getTimerEnabled()) + result += minsToString(getTimer()); + else + result += F("Off"); return result; } @@ -538,7 +583,7 @@ bool IRrecv::decodeGree(decode_results* results, uint16_t nbits, bool strict) { kGreeBitMark, kGreeOneSpace, kGreeBitMark, kGreeZeroSpace, 0, 0, false, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (used == 0) return false; offset += used; @@ -546,7 +591,7 @@ bool IRrecv::decodeGree(decode_results* results, uint16_t nbits, bool strict) { match_result_t data_result; data_result = matchData(&(results->rawbuf[offset]), kGreeBlockFooterBits, kGreeBitMark, kGreeOneSpace, kGreeBitMark, - kGreeZeroSpace, kTolerance, kMarkExcess, false); + kGreeZeroSpace, _tolerance, kMarkExcess, false); if (data_result.success == false) return false; if (data_result.data != kGreeBlockFooter) return false; offset += data_result.used; @@ -558,7 +603,7 @@ bool IRrecv::decodeGree(decode_results* results, uint16_t nbits, bool strict) { kGreeBitMark, kGreeOneSpace, kGreeBitMark, kGreeZeroSpace, kGreeBitMark, kGreeMsgSpace, true, - kTolerance, kMarkExcess, false)) return false; + _tolerance, kMarkExcess, false)) return false; // Compliance if (strict) { diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Gree.h b/lib/IRremoteESP8266-2.6.5/src/ir_Gree.h old mode 100644 new mode 100755 similarity index 72% rename from lib/IRremoteESP8266-2.6.4/src/ir_Gree.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Gree.h index 9619c68e349a..a399d50d5481 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Gree.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Gree.h @@ -36,40 +36,48 @@ const uint8_t kGreeFan = 3; const uint8_t kGreeHeat = 4; // Byte 0 -const uint8_t kGreeModeMask = 0b00000111; -const uint8_t kGreePower1Mask = 0b00001000; -const uint8_t kGreeFanMask = 0b00110000; -const uint8_t kGreeSwingAutoMask = 0b01000000; -const uint8_t kGreeSleepMask = 0b10000000; -// Byte 2 -const uint8_t kGreeTurboMask = 0b00010000; -const uint8_t kGreeLightMask = 0b00100000; -const uint8_t kGreePower2Mask = 0b01000000; // This might not be used. See #814 -const uint8_t kGreeXfanMask = 0b10000000; -// Byte 4 -const uint8_t kGreeSwingPosMask = 0b00001111; -// byte 5 -const uint8_t kGreeIFeelMask = 0b00000100; -const uint8_t kGreeWiFiMask = 0b01000000; - - -const uint8_t kGreeMinTemp = 16; // Celsius -const uint8_t kGreeMaxTemp = 30; // Celsius +const uint8_t kGreeModeMask = 0b00000111; +const uint8_t kGreePower1Mask = 0b00001000; +const uint8_t kGreeFanMask = 0b00110000; const uint8_t kGreeFanAuto = 0; const uint8_t kGreeFanMin = 1; const uint8_t kGreeFanMed = 2; const uint8_t kGreeFanMax = 3; +const uint8_t kGreeSwingAutoMask = 0b01000000; +const uint8_t kGreeSleepMask = 0b10000000; +// Byte 1 +const uint8_t kGreeTempMask = 0b00001111; +const uint8_t kGreeMinTemp = 16; // Celsius +const uint8_t kGreeMaxTemp = 30; // Celsius +const uint8_t kGreeTimerEnabledBit = 0b10000000; +const uint8_t kGreeTimerHalfHrBit = 0b00010000; +const uint8_t kGreeTimerTensHrMask = 0b01100000; +const uint8_t kGreeTimer1Mask = kGreeTimerTensHrMask | kGreeTimerHalfHrBit; +const uint16_t kGreeTimerMax = 24 * 60; + +// Byte 2 +const uint8_t kGreeTimerHoursMask = 0b00001111; +const uint8_t kGreeTurboMask = 0b00010000; +const uint8_t kGreeLightMask = 0b00100000; +// This might not be used. See #814 +const uint8_t kGreePower2Mask = 0b01000000; +const uint8_t kGreeXfanMask = 0b10000000; +// Byte 4 +const uint8_t kGreeSwingPosMask = 0b00001111; +// byte 5 +const uint8_t kGreeIFeelMask = 0b00000100; +const uint8_t kGreeWiFiMask = 0b01000000; -const uint8_t kGreeSwingLastPos = 0b00000000; -const uint8_t kGreeSwingAuto = 0b00000001; -const uint8_t kGreeSwingUp = 0b00000010; -const uint8_t kGreeSwingMiddleUp = 0b00000011; -const uint8_t kGreeSwingMiddle = 0b00000100; +const uint8_t kGreeSwingLastPos = 0b00000000; +const uint8_t kGreeSwingAuto = 0b00000001; +const uint8_t kGreeSwingUp = 0b00000010; +const uint8_t kGreeSwingMiddleUp = 0b00000011; +const uint8_t kGreeSwingMiddle = 0b00000100; const uint8_t kGreeSwingMiddleDown = 0b00000101; -const uint8_t kGreeSwingDown = 0b00000110; -const uint8_t kGreeSwingDownAuto = 0b00000111; +const uint8_t kGreeSwingDown = 0b00000110; +const uint8_t kGreeSwingDownAuto = 0b00000111; const uint8_t kGreeSwingMiddleAuto = 0b00001001; -const uint8_t kGreeSwingUpAuto = 0b00001011; +const uint8_t kGreeSwingUpAuto = 0b00001011; // Legacy defines. #define GREE_AUTO kGreeAuto @@ -132,6 +140,8 @@ class IRGreeAC { void setSwingVertical(const bool automatic, const uint8_t position); bool getSwingVerticalAuto(void); uint8_t getSwingVerticalPosition(void); + uint16_t getTimer(void); + void setTimer(const uint16_t minutes); uint8_t convertMode(const stdAc::opmode_t mode); uint8_t convertFan(const stdAc::fanspeed_t speed); uint8_t convertSwingV(const stdAc::swingv_t swingv); @@ -156,6 +166,8 @@ class IRGreeAC { gree_ac_remote_model_t _model; void checksum(const uint16_t length = kGreeStateLength); void fixup(void); + void setTimerEnabled(const bool on); + bool getTimerEnabled(void); }; #endif // IR_GREE_H_ diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Haier.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Haier.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Haier.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Haier.cpp index 8cb24334c205..d2b947f9ee09 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Haier.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Haier.cpp @@ -933,7 +933,7 @@ bool IRrecv::decodeHaierAC(decode_results* results, uint16_t nbits, kHaierAcBitMark, kHaierAcOneSpace, kHaierAcBitMark, kHaierAcZeroSpace, kHaierAcBitMark, kHaierAcMinGap, true, - kTolerance, kMarkExcess)) return false; + _tolerance, kMarkExcess)) return false; // Compliance if (strict) { diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Haier.h b/lib/IRremoteESP8266-2.6.5/src/ir_Haier.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Haier.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Haier.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Hitachi.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Hitachi.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Hitachi.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Hitachi.cpp index dedaa56961cb..0550816a9ac0 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Hitachi.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Hitachi.cpp @@ -382,7 +382,7 @@ String IRHitachiAc::toString(void) { // https://github.com/crankyoldgit/IRremoteESP8266/issues/453 bool IRrecv::decodeHitachiAC(decode_results *results, const uint16_t nbits, const bool strict) { - const uint8_t kTolerance = 30; + const uint8_t k_tolerance = _tolerance + 5; if (results->rawlen < 2 * nbits + kHeader + kFooter - 1) return false; // Can't possibly be a valid HitachiAC message. if (strict) { @@ -412,7 +412,7 @@ bool IRrecv::decodeHitachiAC(decode_results *results, const uint16_t nbits, kHitachiAcBitMark, kHitachiAcOneSpace, kHitachiAcBitMark, kHitachiAcZeroSpace, kHitachiAcBitMark, kHitachiAcMinGap, true, - kTolerance)) return false; + k_tolerance)) return false; // Compliance if (strict) { diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Hitachi.h b/lib/IRremoteESP8266-2.6.5/src/ir_Hitachi.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Hitachi.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Hitachi.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Inax.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Inax.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Inax.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Inax.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_JVC.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_JVC.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_JVC.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_JVC.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Kelvinator.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Kelvinator.cpp old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/src/ir_Kelvinator.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Kelvinator.cpp index f280d01610e5..0af521b1564b --- a/lib/IRremoteESP8266-2.6.4/src/ir_Kelvinator.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Kelvinator.cpp @@ -475,7 +475,7 @@ bool IRrecv::decodeKelvinator(decode_results *results, uint16_t nbits, kKelvinatorBitMark, kKelvinatorOneSpace, kKelvinatorBitMark, kKelvinatorZeroSpace, 0, 0, false, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (used == 0) return false; offset += used; pos += 4; @@ -485,26 +485,20 @@ bool IRrecv::decodeKelvinator(decode_results *results, uint16_t nbits, &(results->rawbuf[offset]), kKelvinatorCmdFooterBits, kKelvinatorBitMark, kKelvinatorOneSpace, kKelvinatorBitMark, kKelvinatorZeroSpace, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (data_result.success == false) return false; if (data_result.data != kKelvinatorCmdFooter) return false; offset += data_result.used; - // Interdata gap. - if (!matchMark(results->rawbuf[offset++], kKelvinatorBitMark)) - return false; - if (!matchSpace(results->rawbuf[offset++], kKelvinatorGapSpace)) - return false; - - // Data (Options) (32 bits) + // Gap + Data (Options) (32 bits) used = matchGeneric(results->rawbuf + offset, results->state + pos, results->rawlen - offset, 32, - 0, 0, + kKelvinatorBitMark, kKelvinatorGapSpace, kKelvinatorBitMark, kKelvinatorOneSpace, kKelvinatorBitMark, kKelvinatorZeroSpace, kKelvinatorBitMark, kKelvinatorGapSpace * 2, s > 0, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (used == 0) return false; offset += used; pos += 4; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Kelvinator.h b/lib/IRremoteESP8266-2.6.5/src/ir_Kelvinator.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Kelvinator.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Kelvinator.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_LG.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_LG.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_LG.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_LG.cpp index ded6fefad2b3..124256e9f1c3 --- a/lib/IRremoteESP8266-2.6.4/src/ir_LG.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_LG.cpp @@ -237,7 +237,7 @@ bool IRrecv::decodeLG(decode_results *results, uint16_t nbits, bool strict) { match_result_t data_result = matchData(&(results->rawbuf[offset]), nbits, bitmarkticks * m_tick, kLgOneSpaceTicks * s_tick, bitmarkticks * m_tick, - kLgZeroSpaceTicks * s_tick, kTolerance, 0); + kLgZeroSpaceTicks * s_tick, _tolerance, 0); if (data_result.success == false) return false; data = data_result.data; offset += data_result.used; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_LG.h b/lib/IRremoteESP8266-2.6.5/src/ir_LG.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_LG.h rename to lib/IRremoteESP8266-2.6.5/src/ir_LG.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Lasertag.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Lasertag.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Lasertag.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Lasertag.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Lego.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Lego.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Lego.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Lego.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Lutron.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Lutron.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Lutron.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Lutron.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_MWM.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_MWM.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_MWM.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_MWM.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Magiquest.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Magiquest.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Magiquest.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Magiquest.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Magiquest.h b/lib/IRremoteESP8266-2.6.5/src/ir_Magiquest.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Magiquest.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Magiquest.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Midea.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Midea.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Midea.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Midea.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Midea.h b/lib/IRremoteESP8266-2.6.5/src/ir_Midea.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Midea.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Midea.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Mitsubishi.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Mitsubishi.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Mitsubishi.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Mitsubishi.cpp index 14a0676fd65a..c78b1d21ab3b --- a/lib/IRremoteESP8266-2.6.4/src/ir_Mitsubishi.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Mitsubishi.cpp @@ -302,7 +302,7 @@ bool IRrecv::decodeMitsubishiAC(decode_results *results, uint16_t nbits, data_result = matchData(&(results->rawbuf[offset]), 8, kMitsubishiAcBitMark, kMitsubishiAcOneSpace, kMitsubishiAcBitMark, - kMitsubishiAcZeroSpace, kTolerance, kMarkExcess, false); + kMitsubishiAcZeroSpace, _tolerance, kMarkExcess, false); if (data_result.success == false) { failure = true; DPRINT("Byte decode failed at #"); @@ -365,7 +365,7 @@ bool IRrecv::decodeMitsubishiAC(decode_results *results, uint16_t nbits, data_result = matchData(&(results->rawbuf[offset]), 8, kMitsubishiAcBitMark, kMitsubishiAcOneSpace, kMitsubishiAcBitMark, - kMitsubishiAcZeroSpace, kTolerance, kMarkExcess, false); + kMitsubishiAcZeroSpace, _tolerance, kMarkExcess, false); if (data_result.success == false || data_result.data != results->state[i]) { DPRINTLN("Repeat payload error."); @@ -672,6 +672,8 @@ uint8_t IRMitsubishiAC::convertSwingH(const stdAc::swingh_t position) { return kMitsubishiAcWideVaneAuto - 4; case stdAc::swingh_t::kRightMax: return kMitsubishiAcWideVaneAuto - 3; + case stdAc::swingh_t::kWide: + return kMitsubishiAcWideVaneAuto - 2; case stdAc::swingh_t::kAuto: return kMitsubishiAcWideVaneAuto; default: @@ -721,6 +723,7 @@ stdAc::swingh_t IRMitsubishiAC::toCommonSwingH(const uint8_t pos) { case 3: return stdAc::swingh_t::kMiddle; case 4: return stdAc::swingh_t::kRight; case 5: return stdAc::swingh_t::kRightMax; + case 6: return stdAc::swingh_t::kWide; default: return stdAc::swingh_t::kAuto; } } diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Mitsubishi.h b/lib/IRremoteESP8266-2.6.5/src/ir_Mitsubishi.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Mitsubishi.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Mitsubishi.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_MitsubishiHeavy.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_MitsubishiHeavy.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_MitsubishiHeavy.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_MitsubishiHeavy.cpp index 98a681e0501d..6b42959915b5 --- a/lib/IRremoteESP8266-2.6.4/src/ir_MitsubishiHeavy.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_MitsubishiHeavy.cpp @@ -1045,7 +1045,7 @@ bool IRrecv::decodeMitsubishiHeavy(decode_results* results, kMitsubishiHeavyBitMark, kMitsubishiHeavyOneSpace, kMitsubishiHeavyBitMark, kMitsubishiHeavyZeroSpace, kMitsubishiHeavyBitMark, kMitsubishiHeavyGap, true, - kTolerance, 0, false); + _tolerance, 0, false); if (used == 0) return false; offset += used; // Compliance diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_MitsubishiHeavy.h b/lib/IRremoteESP8266-2.6.5/src/ir_MitsubishiHeavy.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_MitsubishiHeavy.h rename to lib/IRremoteESP8266-2.6.5/src/ir_MitsubishiHeavy.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_NEC.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_NEC.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_NEC.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_NEC.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_NEC.h b/lib/IRremoteESP8266-2.6.5/src/ir_NEC.h old mode 100644 new mode 100755 similarity index 93% rename from lib/IRremoteESP8266-2.6.4/src/ir_NEC.h rename to lib/IRremoteESP8266-2.6.5/src/ir_NEC.h index fef1a65fd426..e45ff702cd5d --- a/lib/IRremoteESP8266-2.6.4/src/ir_NEC.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_NEC.h @@ -9,6 +9,10 @@ #include #include "IRremoteESP8266.h" +// Supports: +// Brand: Yamaha, Model: RAV561 remote +// Brand: Yamaha, Model: RXV585B A/V Receiver + // Constants // Ref: // http://www.sbprojects.com/knowledge/ir/nec.php diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Neoclima.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Neoclima.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Neoclima.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Neoclima.cpp index bd2a3d1b5391..353d43b146a2 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Neoclima.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Neoclima.cpp @@ -528,7 +528,7 @@ bool IRrecv::decodeNeoclima(decode_results *results, const uint16_t nbits, kNeoclimaBitMark, kNeoclimaOneSpace, kNeoclimaBitMark, kNeoclimaZeroSpace, kNeoclimaBitMark, kNeoclimaHdrSpace, false, - kTolerance, 0, false); + _tolerance, 0, false); if (!used) return false; offset += used; // Extra footer. diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Neoclima.h b/lib/IRremoteESP8266-2.6.5/src/ir_Neoclima.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Neoclima.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Neoclima.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Nikai.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Nikai.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Nikai.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Nikai.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Panasonic.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Panasonic.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Panasonic.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Panasonic.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Panasonic.h b/lib/IRremoteESP8266-2.6.5/src/ir_Panasonic.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Panasonic.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Panasonic.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Pioneer.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Pioneer.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Pioneer.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Pioneer.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Pronto.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Pronto.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Pronto.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Pronto.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_RC5_RC6.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_RC5_RC6.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_RC5_RC6.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_RC5_RC6.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_RCMM.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_RCMM.cpp old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/src/ir_RCMM.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_RCMM.cpp index cbc5e40b3b46..4e8f43891875 --- a/lib/IRremoteESP8266-2.6.4/src/ir_RCMM.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_RCMM.cpp @@ -141,11 +141,9 @@ bool IRrecv::decodeRCMM(decode_results *results, uint16_t nbits, bool strict) { data <<= 2; // Use non-default tolerance & excess for matching some of the spaces as the // defaults are too generous and causes mis-matches in some cases. - if (match(results->rawbuf[offset], kRcmmBitSpace0Ticks * s_tick, - kTolerance)) + if (match(results->rawbuf[offset], kRcmmBitSpace0Ticks * s_tick)) data += 0; - else if (match(results->rawbuf[offset], kRcmmBitSpace1Ticks * s_tick, - kTolerance)) + else if (match(results->rawbuf[offset], kRcmmBitSpace1Ticks * s_tick)) data += 1; else if (match(results->rawbuf[offset], kRcmmBitSpace2Ticks * s_tick, kRcmmTolerance)) diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Samsung.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Samsung.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Samsung.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Samsung.cpp index 09ba3e199d8d..77985b1c4935 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Samsung.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Samsung.cpp @@ -742,7 +742,7 @@ bool IRrecv::decodeSamsungAC(decode_results *results, const uint16_t nbits, kSamsungAcBitMark, kSamsungAcZeroSpace, kSamsungAcBitMark, kSamsungAcSectionGap, pos + kSamsungACSectionLength >= nbits / 8, - kTolerance, 0, false); + _tolerance, 0, false); if (used == 0) return false; offset += used; } diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Samsung.h b/lib/IRremoteESP8266-2.6.5/src/ir_Samsung.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Samsung.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Samsung.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Sanyo.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Sanyo.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Sanyo.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Sanyo.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Sharp.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Sharp.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Sharp.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Sharp.cpp index b27c319e0577..2502485543f5 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Sharp.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Sharp.cpp @@ -538,7 +538,7 @@ bool IRrecv::decodeSharpAc(decode_results *results, const uint16_t nbits, kSharpAcBitMark, kSharpAcOneSpace, kSharpAcBitMark, kSharpAcZeroSpace, kSharpAcBitMark, kSharpAcGap, true, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (used == 0) return false; offset += used; // Compliance diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Sharp.h b/lib/IRremoteESP8266-2.6.5/src/ir_Sharp.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Sharp.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Sharp.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Sherwood.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Sherwood.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Sherwood.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Sherwood.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Sony.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Sony.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Sony.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Sony.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Tcl.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Tcl.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Tcl.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Tcl.cpp index 80cefdeb1134..0186f43e57c3 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Tcl.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Tcl.cpp @@ -396,7 +396,7 @@ bool IRrecv::decodeTcl112Ac(decode_results *results, const uint16_t nbits, kTcl112AcBitMark, kTcl112AcOneSpace, kTcl112AcBitMark, kTcl112AcZeroSpace, kTcl112AcBitMark, kTcl112AcGap, true, - kTcl112AcTolerance, 0, false)) return false; + _tolerance + kTcl112AcTolerance, 0, false)) return false; // Compliance // Verify we got a valid checksum. if (strict && !IRTcl112Ac::validChecksum(results->state)) return false; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Tcl.h b/lib/IRremoteESP8266-2.6.5/src/ir_Tcl.h old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/src/ir_Tcl.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Tcl.h index dce81c4ec7db..1a1bc1d6b9e3 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Tcl.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Tcl.h @@ -23,7 +23,7 @@ const uint16_t kTcl112AcBitMark = 500; const uint16_t kTcl112AcOneSpace = 1050; const uint16_t kTcl112AcZeroSpace = 325; const uint32_t kTcl112AcGap = kDefaultMessageGap; // Just a guess. -const uint8_t kTcl112AcTolerance = kTolerance + 5; // Percent +const uint8_t kTcl112AcTolerance = 5; // Extra Percent const uint8_t kTcl112AcHeat = 1; const uint8_t kTcl112AcDry = 2; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Teco.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Teco.cpp old mode 100644 new mode 100755 similarity index 87% rename from lib/IRremoteESP8266-2.6.4/src/ir_Teco.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Teco.cpp index 9cc47a37d8cf..9967ccee102a --- a/lib/IRremoteESP8266-2.6.4/src/ir_Teco.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Teco.cpp @@ -64,19 +64,18 @@ uint64_t IRTecoAc::getRaw(void) { return remote_state; } void IRTecoAc::setRaw(const uint64_t new_code) { remote_state = new_code; } -void IRTecoAc::on(void) { remote_state |= kTecoPower; } +void IRTecoAc::on(void) { setPower(true); } -void IRTecoAc::off(void) { remote_state &= ~kTecoPower; } +void IRTecoAc::off(void) { setPower(false); } void IRTecoAc::setPower(const bool on) { if (on) - this->on(); + remote_state |= kTecoPower; else - this->off(); + remote_state &= ~kTecoPower; } -bool IRTecoAc::getPower(void) { - return (remote_state & kTecoPower) == kTecoPower; } +bool IRTecoAc::getPower(void) { return remote_state & kTecoPower; } void IRTecoAc::setTemp(const uint8_t temp) { uint8_t newtemp = temp; @@ -146,6 +145,33 @@ void IRTecoAc::setSleep(const bool on) { bool IRTecoAc::getSleep(void) { return remote_state & kTecoSleep; } +bool IRTecoAc::getLight(void) { return remote_state & kTecoLight; } + +void IRTecoAc::setLight(const bool on) { + if (on) + remote_state |= kTecoLight; + else + remote_state &= ~kTecoLight; +} + +bool IRTecoAc::getHumid(void) { return remote_state & kTecoHumid; } + +void IRTecoAc::setHumid(const bool on) { + if (on) + remote_state |= kTecoHumid; + else + remote_state &= ~kTecoHumid; +} + +bool IRTecoAc::getSave(void) { return remote_state & kTecoSave; } + +void IRTecoAc::setSave(const bool on) { + if (on) + remote_state |= kTecoSave; + else + remote_state &= ~kTecoSave; +} + // Convert a standard A/C mode into its native mode. uint8_t IRTecoAc::convertMode(const stdAc::opmode_t mode) { switch (mode) { @@ -212,10 +238,10 @@ stdAc::state_t IRTecoAc::toCommon(void) { result.swingv = this->getSwing() ? stdAc::swingv_t::kAuto : stdAc::swingv_t::kOff; result.sleep = this->getSleep() ? 0 : -1; + result.light = this->getLight(); // Not supported. result.swingh = stdAc::swingh_t::kOff; result.turbo = false; - result.light = false; result.filter = false; result.econo = false; result.quiet = false; @@ -228,7 +254,7 @@ stdAc::state_t IRTecoAc::toCommon(void) { // Convert the internal state into a human readable string. String IRTecoAc::toString(void) { String result = ""; - result.reserve(80); // Reserve some heap for the string to reduce fragging. + result.reserve(100); // Reserve some heap for the string to reduce fragging. result += addBoolToString(getPower(), F("Power"), false); result += addModeToString(getMode(), kTecoAuto, kTecoCool, kTecoHeat, kTecoDry, kTecoFan); @@ -237,6 +263,10 @@ String IRTecoAc::toString(void) { kTecoFanAuto, kTecoFanAuto, kTecoFanMed); result += addBoolToString(getSleep(), F("Sleep")); result += addBoolToString(getSwing(), F("Swing")); + result += addBoolToString(getLight(), F("Light")); + result += addBoolToString(getHumid(), F("Humid")); + result += addBoolToString(getSave(), F("Save")); + return result; } @@ -264,7 +294,7 @@ bool IRrecv::decodeTeco(decode_results* results, kTecoBitMark, kTecoOneSpace, kTecoBitMark, kTecoZeroSpace, kTecoBitMark, kTecoGap, true, - kTolerance, kMarkExcess, false)) return false; + _tolerance, kMarkExcess, false)) return false; // Success results->decode_type = TECO; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Teco.h b/lib/IRremoteESP8266-2.6.5/src/ir_Teco.h old mode 100644 new mode 100755 similarity index 84% rename from lib/IRremoteESP8266-2.6.4/src/ir_Teco.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Teco.h index d594aca32158..616fc5dfb4a9 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Teco.h +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Teco.h @@ -12,6 +12,10 @@ #include "IRsend_test.h" #endif +// Supports: +// Brand: Alaska, Model: SAC9010QC A/C +// Brand: Alaska, Model: SAC9010QC remote + // Constants. Using LSB to be able to send only 35bits. const uint8_t kTecoAuto = 0; // 0b000 const uint8_t kTecoCool = 1; // 0b001 @@ -35,6 +39,9 @@ const uint64_t kTecoTimerHalfH = 0b00000000000000000000001000000000000; const uint64_t kTecoTimerTenHr = 0b00000000000000000000110000000000000; const uint64_t kTecoTimerOn = 0b00000000000000000001000000000000000; const uint64_t kTecoTimerUniHr = 0b00000000000000011110000000000000000; +const uint64_t kTecoHumid = 0b00000000000000100000000000000000000; +const uint64_t kTecoLight = 0b00000000000001000000000000000000000; +const uint64_t kTecoSave = 0b00000000000100000000000000000000000; const uint64_t kTecoReset = 0b01001010000000000000010000000000000; /* (header mark and space) @@ -42,8 +49,12 @@ const uint64_t kTecoReset = 0b01001010000000000000010000000000000; byte 0 = Cst 0x02 byte 1 = Cst 0x50 + b6-7 = "AIR" 0, 1, 2 (Not Implemented) byte 2: - b0-3 = 0b0000 + b0 = Save + b1 = "Tree with bubbles" / Filter?? (Not Implemented) + b2 = Light/LED. + b3 = Humid b4-7 = Timer hours (unit, not thenth) hours: 0000 (0) = +0 hour @@ -110,12 +121,21 @@ class IRTecoAc { void setMode(const uint8_t mode); uint8_t getMode(void); - void setSwing(const bool state); + void setSwing(const bool on); bool getSwing(void); - void setSleep(const bool state); + void setSleep(const bool on); bool getSleep(void); + void setLight(const bool on); + bool getLight(void); + + void setHumid(const bool on); + bool getHumid(void); + + void setSave(const bool on); + bool getSave(void); + // void setTimer(uint8_t time); // To check unit // uint8_t getTimer(uint8_t); diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Toshiba.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Toshiba.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Toshiba.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Toshiba.cpp index 00a0f4d5cf9d..4fa4c1075dfa --- a/lib/IRremoteESP8266-2.6.4/src/ir_Toshiba.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Toshiba.cpp @@ -362,7 +362,7 @@ bool IRrecv::decodeToshibaAC(decode_results* results, const uint16_t nbits, kToshibaAcBitMark, kToshibaAcOneSpace, kToshibaAcBitMark, kToshibaAcZeroSpace, kToshibaAcBitMark, kToshibaAcMinGap, true, - kTolerance, kMarkExcess)) return false; + _tolerance, kMarkExcess)) return false; // Compliance if (strict) { // Check that the checksum of the message is correct. diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Toshiba.h b/lib/IRremoteESP8266-2.6.5/src/ir_Toshiba.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Toshiba.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Toshiba.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Trotec.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Trotec.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Trotec.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Trotec.cpp index b0ddda62d790..281779f62f97 --- a/lib/IRremoteESP8266-2.6.4/src/ir_Trotec.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Trotec.cpp @@ -274,7 +274,7 @@ bool IRrecv::decodeTrotec(decode_results *results, const uint16_t nbits, kTrotecBitMark, kTrotecOneSpace, kTrotecBitMark, kTrotecZeroSpace, kTrotecBitMark, kTrotecGap, true, - kTolerance, 0, false); + _tolerance, 0, false); if (used == 0) return false; offset += used; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Trotec.h b/lib/IRremoteESP8266-2.6.5/src/ir_Trotec.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Trotec.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Trotec.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Vestel.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Vestel.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Vestel.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Vestel.cpp diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Vestel.h b/lib/IRremoteESP8266-2.6.5/src/ir_Vestel.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Vestel.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Vestel.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Whirlpool.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Whirlpool.cpp old mode 100644 new mode 100755 similarity index 99% rename from lib/IRremoteESP8266-2.6.4/src/ir_Whirlpool.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Whirlpool.cpp index 91fb58f91a76..92a9b2bb37cf --- a/lib/IRremoteESP8266-2.6.4/src/ir_Whirlpool.cpp +++ b/lib/IRremoteESP8266-2.6.5/src/ir_Whirlpool.cpp @@ -607,7 +607,7 @@ bool IRrecv::decodeWhirlpoolAC(decode_results *results, const uint16_t nbits, kWhirlpoolAcBitMark, kWhirlpoolAcZeroSpace, kWhirlpoolAcBitMark, kWhirlpoolAcGap, section >= kWhirlpoolAcSections - 1, - kTolerance, kMarkExcess, false); + _tolerance, kMarkExcess, false); if (used == 0) return false; offset += used; pos += sectionSize[section]; diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Whirlpool.h b/lib/IRremoteESP8266-2.6.5/src/ir_Whirlpool.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Whirlpool.h rename to lib/IRremoteESP8266-2.6.5/src/ir_Whirlpool.h diff --git a/lib/IRremoteESP8266-2.6.4/src/ir_Whynter.cpp b/lib/IRremoteESP8266-2.6.5/src/ir_Whynter.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/src/ir_Whynter.cpp rename to lib/IRremoteESP8266-2.6.5/src/ir_Whynter.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/IRac_test.cpp b/lib/IRremoteESP8266-2.6.5/test/IRac_test.cpp old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/test/IRac_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/IRac_test.cpp index 2b3129978391..3afc89c6e509 --- a/lib/IRremoteESP8266-2.6.4/test/IRac_test.cpp +++ b/lib/IRremoteESP8266-2.6.5/test/IRac_test.cpp @@ -1,6 +1,7 @@ // Copyright 2019 David Conran #include +#include "ir_Amcor.h" #include "ir_Argo.h" #include "ir_Daikin.h" #include "ir_Electra.h" @@ -33,6 +34,27 @@ // Tests for IRac class. +TEST(TestIRac, Amcor) { + IRAmcorAc ac(0); + IRac irac(0); + IRrecv capture(0); + char expected[] = + "Power: On, Mode: 5 (AUTO), Fan: 3 (High), Temp: 19C, Max: Off"; + + ac.begin(); + irac.amcor(&ac, + true, // Power + stdAc::opmode_t::kAuto, // Mode + 19, // Celsius + stdAc::fanspeed_t::kHigh); // Fan speed + ASSERT_EQ(expected, ac.toString()); + ac._irsend.makeDecodeResult(); + EXPECT_TRUE(capture.decode(&ac._irsend.capture)); + ASSERT_EQ(AMCOR, ac._irsend.capture.decode_type); + ASSERT_EQ(kAmcorBits, ac._irsend.capture.bits); + ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); +} + TEST(TestIRac, Argo) { IRArgoAC ac(0); IRac irac(0); @@ -390,7 +412,7 @@ TEST(TestIRac, Gree) { "Model: 1 (YAW1F), Power: On, Mode: 1 (COOL), Temp: 22C, " "Fan: 2 (Medium), Turbo: Off, IFeel: Off, WiFi: Off, XFan: On, " "Light: On, Sleep: On, Swing Vertical Mode: Manual, " - "Swing Vertical Pos: 3"; + "Swing Vertical Pos: 3, Timer: Off"; ac.begin(); irac.gree(&ac, @@ -822,7 +844,7 @@ TEST(TestIRac, Teco) { IRrecv capture(0); char expected[] = "Power: On, Mode: 0 (AUTO), Temp: 21C, Fan: 2 (Medium), Sleep: On, " - "Swing: On"; + "Swing: On, Light: On, Humid: Off, Save: Off"; ac.begin(); irac.teco(&ac, @@ -831,6 +853,7 @@ TEST(TestIRac, Teco) { 21, // Celsius stdAc::fanspeed_t::kMedium, // Fan speed stdAc::swingv_t::kAuto, // Veritcal swing + true, // Light 8 * 60 + 30); // Sleep ASSERT_EQ(expected, ac.toString()); ac._irsend.makeDecodeResult(); @@ -1220,6 +1243,7 @@ TEST(TestIRac, swinghToString) { EXPECT_EQ("off", IRac::swinghToString(stdAc::swingh_t::kOff)); EXPECT_EQ("left", IRac::swinghToString(stdAc::swingh_t::kLeft)); EXPECT_EQ("auto", IRac::swinghToString(stdAc::swingh_t::kAuto)); + EXPECT_EQ("wide", IRac::swinghToString(stdAc::swingh_t::kWide)); EXPECT_EQ("unknown", IRac::swinghToString((stdAc::swingh_t)500)); } diff --git a/lib/IRremoteESP8266-2.6.4/test/IRrecv_test.cpp b/lib/IRremoteESP8266-2.6.5/test/IRrecv_test.cpp old mode 100644 new mode 100755 similarity index 96% rename from lib/IRremoteESP8266-2.6.4/test/IRrecv_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/IRrecv_test.cpp index 899841de58c0..cda7b747fb1d --- a/lib/IRremoteESP8266-2.6.4/test/IRrecv_test.cpp +++ b/lib/IRremoteESP8266-2.6.5/test/IRrecv_test.cpp @@ -1207,3 +1207,40 @@ TEST(TestMatchGeneric, UsingBytes) { true); // MSB first. ASSERT_EQ(0, entries_used); } + +TEST(TestIRrecv, Tolerance) { + IRsendTest irsend(0); + IRrecv irrecv(1); + irsend.begin(); + + uint16_t equal_encoded_raw[11] = {500, 1500, 1500, 500, 499, 1499, + 1501, 501, 1499, 490, 500}; + match_result_t result; + + ASSERT_EQ(kTolerance, irrecv.getTolerance()); + irrecv.setTolerance(); + ASSERT_EQ(kTolerance, irrecv.getTolerance()); + irrecv.setTolerance(kTolerance + 1); + ASSERT_EQ(kTolerance + 1, irrecv.getTolerance()); + irrecv.setTolerance(kTolerance - 1); + ASSERT_EQ(kTolerance - 1, irrecv.getTolerance()); + + irrecv.setTolerance(); + ASSERT_EQ(kTolerance, irrecv.getTolerance()); + + irsend.reset(); + irsend.sendRaw(equal_encoded_raw, 11, 38000); + irsend.makeDecodeResult(); + result = irrecv.matchData(irsend.capture.rawbuf + 1, 5, 1500, 500, 500, 1500); + ASSERT_TRUE(result.success); + EXPECT_EQ(0b01011, result.data); + EXPECT_EQ(10, result.used); + + irrecv.setTolerance(0); + ASSERT_EQ(0, irrecv.getTolerance()); + irsend.reset(); + irsend.sendRaw(equal_encoded_raw, 11, 38000); + irsend.makeDecodeResult(); + result = irrecv.matchData(irsend.capture.rawbuf + 1, 5, 1500, 500, 500, 1500); + ASSERT_FALSE(result.success); +} diff --git a/lib/IRremoteESP8266-2.6.4/test/IRrecv_test.h b/lib/IRremoteESP8266-2.6.5/test/IRrecv_test.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/IRrecv_test.h rename to lib/IRremoteESP8266-2.6.5/test/IRrecv_test.h diff --git a/lib/IRremoteESP8266-2.6.4/test/IRsend_test.cpp b/lib/IRremoteESP8266-2.6.5/test/IRsend_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/IRsend_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/IRsend_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/IRsend_test.h b/lib/IRremoteESP8266-2.6.5/test/IRsend_test.h old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/IRsend_test.h rename to lib/IRremoteESP8266-2.6.5/test/IRsend_test.h diff --git a/lib/IRremoteESP8266-2.6.4/test/IRutils_test.cpp b/lib/IRremoteESP8266-2.6.5/test/IRutils_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/IRutils_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/IRutils_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/Makefile b/lib/IRremoteESP8266-2.6.5/test/Makefile old mode 100644 new mode 100755 similarity index 97% rename from lib/IRremoteESP8266-2.6.4/test/Makefile rename to lib/IRremoteESP8266-2.6.5/test/Makefile index 1de3aa220b30..0e721d58c5b9 --- a/lib/IRremoteESP8266-2.6.4/test/Makefile +++ b/lib/IRremoteESP8266-2.6.5/test/Makefile @@ -39,7 +39,7 @@ TESTS = IRutils_test IRsend_test ir_NEC_test ir_GlobalCache_test \ ir_Whirlpool_test ir_Lutron_test ir_Electra_test ir_Pioneer_test \ ir_MWM_test ir_Vestel_test ir_Teco_test ir_Tcl_test ir_Lego_test IRac_test \ ir_MitsubishiHeavy_test ir_Trotec_test ir_Argo_test ir_Goodweather_test \ - ir_Inax_test ir_Neoclima_test + ir_Inax_test ir_Neoclima_test ir_Amcor_test # All Google Test headers. Usually you shouldn't change this # definition. @@ -84,10 +84,12 @@ PROTOCOLS = ir_NEC.o ir_Sony.o ir_Samsung.o ir_JVC.o ir_RCMM.o ir_RC5_RC6.o \ ir_Midea.o ir_Magiquest.o ir_Lasertag.o ir_Carrier.o ir_Haier.o \ ir_Hitachi.o ir_GICable.o ir_Whirlpool.o ir_Lutron.o ir_Electra.o \ ir_Pioneer.o ir_MWM.o ir_Vestel.o ir_Teco.o ir_Tcl.o ir_Lego.o ir_Argo.o \ - ir_Trotec.o ir_MitsubishiHeavy.o ir_Goodweather.o ir_Inax.o ir_Neoclima.o + ir_Trotec.o ir_MitsubishiHeavy.o ir_Goodweather.o ir_Inax.o ir_Neoclima.o \ + ir_Amcor.o # All the IR Protocol header files. -PROTOCOLS_H = $(USER_DIR)/ir_Argo.h \ +PROTOCOLS_H = $(USER_DIR)/ir_Amcor.h \ + $(USER_DIR)/ir_Argo.h \ $(USER_DIR)/ir_Gree.h \ $(USER_DIR)/ir_Magiquest.h \ $(USER_DIR)/ir_Coolix.h \ @@ -607,3 +609,12 @@ ir_Neoclima_test.o : ir_Neoclima_test.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS) ir_Neoclima_test : $(COMMON_OBJ) ir_Neoclima_test.o $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ + +ir_Amcor.o : $(USER_DIR)/ir_Amcor.h $(USER_DIR)/ir_Amcor.cpp $(COMMON_DEPS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/ir_Amcor.cpp + +ir_Amcor_test.o : ir_Amcor_test.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c ir_Amcor_test.cpp + +ir_Amcor_test : $(COMMON_OBJ) ir_Amcor_test.o + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Aiwa_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Aiwa_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Aiwa_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Aiwa_test.cpp diff --git a/lib/IRremoteESP8266-2.6.5/test/ir_Amcor_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Amcor_test.cpp new file mode 100755 index 000000000000..265c61500553 --- /dev/null +++ b/lib/IRremoteESP8266-2.6.5/test/ir_Amcor_test.cpp @@ -0,0 +1,351 @@ +// Copyright 2019 David Conran + +#include "IRac.h" +#include "ir_Amcor.h" +#include "IRrecv.h" +#include "IRrecv_test.h" +#include "IRsend.h" +#include "IRsend_test.h" +#include "IRutils.h" +#include "gtest/gtest.h" + +TEST(TestUtils, Housekeeping) { + ASSERT_EQ("AMCOR", typeToString(decode_type_t::AMCOR)); + ASSERT_EQ(decode_type_t::AMCOR, strToDecodeType("AMCOR")); + ASSERT_TRUE(hasACState(decode_type_t::AMCOR)); + ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::AMCOR)); +} + +// Test sending typical data only. +TEST(TestSendAmcor, SendDataOnly) { + IRsendTest irsend(0); + irsend.begin(); + + uint8_t expectedState[kAmcorStateLength] = { + 0x01, 0x41, 0x36, 0x00, 0x00, 0x30, 0x00, 0x12}; + + irsend.reset(); + irsend.sendAmcor(expectedState); + EXPECT_EQ( + "f38000d50" + "m8200s4200" + "m1500s600m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m1500s600m600s1500m600s1500m600s1500m600s1500m600s1500m1500s600m600s1500" + "m600s1500m1500s600m1500s600m600s1500m1500s600m1500s600m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m1500s600m1500s600m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m1500s600m600s1500m600s1500m1500s600m600s1500m600s1500m600s1500" + "m1900s34300" + "m8200s4200" + "m1500s600m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m1500s600m600s1500m600s1500m600s1500m600s1500m600s1500m1500s600m600s1500" + "m600s1500m1500s600m1500s600m600s1500m1500s600m1500s600m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m1500s600m1500s600m600s1500m600s1500" + "m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500m600s1500" + "m600s1500m1500s600m600s1500m600s1500m1500s600m600s1500m600s1500m600s1500" + "m1900s34300", + irsend.outputStr()); +} + +TEST(TestDecodeAmcor, SyntheticSelfDecode) { + IRsendTest irsend(0); + IRrecv irrecv(0); + IRAmcorAc ac(0); + + uint8_t expectedState[kAmcorStateLength] = { + 0x01, 0x41, 0x30, 0x00, 0x00, 0x30, 0x00, 0x0C}; + + irsend.begin(); + irsend.reset(); + irsend.sendAmcor(expectedState); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(AMCOR, irsend.capture.decode_type); + EXPECT_EQ(kAmcorBits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); + ac.setRaw(irsend.capture.state); + EXPECT_EQ( + "Power: On, Mode: 1 (COOL), Fan: 4 (Auto), Temp: 24C, Max: Off", + ac.toString()); +} + +TEST(TestDecodeAmcor, RealExample) { + IRsendTest irsend(0); + IRrecv irrecv(0); + irsend.begin(); + + // Data from Issue #834 captured by ldellus + // Turn on, cooling, 27 deg C. + uint16_t rawData[263] = { + 8210, 4276, 1544, 480, 596, 1510, 596, 1510, 596, 1692, 388, 1534, 596, + 1510, 596, 1510, 596, 1684, 1450, 480, 596, 1510, 570, 1534, 570, 1718, 386, + 1536, 594, 1500, 1632, 482, 596, 1694, 362, 1550, 1632, 472, 1658, 456, 596, + 1684, 1474, 446, 1634, 480, 572, 1534, 572, 1718, 362, 1558, 572, 1534, 570, + 1534, 570, 1720, 360, 1558, 572, 1534, 570, 1534, 570, 1718, 360, 1560, 572, + 1534, 570, 1534, 570, 1718, 362, 1560, 572, 1532, 572, 1534, 570, 1718, 362, + 1558, 572, 1532, 572, 1534, 570, 1710, 1448, 472, 1634, 480, 572, 1534, 570, + 1718, 362, 1558, 572, 1534, 570, 1534, 572, 1716, 362, 1560, 572, 1534, 572, + 1534, 570, 1718, 362, 1550, 1634, 480, 570, 1536, 570, 1710, 1448, 482, 570, + 1534, 570, 1536, 570, 1508, 1856, 34298, + // rawData[132] is here. (8218) + 8218, 4314, 1502, 522, 530, 1576, 504, 1602, 504, 1786, 392, 1528, 504, + 1600, 504, 1600, 504, 1770, 1414, 522, 528, 1578, 502, 1602, 504, 1784, 394, + 1528, 504, 1584, 1574, 548, 528, 1762, 392, 1512, 1572, 530, 1600, 524, 528, + 1744, 1390, 530, 1574, 546, 506, 1600, 504, 1784, 394, 1528, 504, 1600, 578, + 1528, 504, 1784, 394, 1526, 504, 1600, 504, 1600, 506, 1784, 394, 1528, 504, + 1602, 504, 1602, 504, 1784, 394, 1526, 506, 1600, 504, 1600, 506, 1784, 392, + 1526, 506, 1600, 504, 1602, 502, 1768, 1390, 530, 1574, 548, 504, 1600, 504, + 1786, 392, 1530, 504, 1600, 504, 1600, 504, 1786, 392, 1528, 504, 1600, 504, + 1600, 506, 1784, 394, 1512, 1574, 548, 504, 1602, 504, 1768, 1388, 548, 504, + 1602, 504, 1602, 502, 1574, 1792}; // UNKNOWN D510A6EF + + uint8_t expectedState[kAmcorStateLength] = { + 0x01, 0x41, 0x36, 0x00, 0x00, 0x30, 0x00, 0x12}; + + irsend.reset(); + irsend.sendRaw(rawData, 263, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(AMCOR, irsend.capture.decode_type); + EXPECT_EQ(kAmcorBits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); + + // Verify the repeat is the same decode. + irsend.reset(); + irsend.sendRaw(rawData + 132, 131, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(AMCOR, irsend.capture.decode_type); + EXPECT_EQ(kAmcorBits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); + + // https://github.com/crankyoldgit/IRremoteESP8266/issues/834#issuecomment-515700254 + uint16_t rawData2[263] = {8252, 4294, 1518, 508, 544, 1560, 546, 1560, 570, + 1718, 416, 1504, 546, 1560, 570, 1532, 572, 1718, 1414, 506, 544, 1560, 570, + 1534, 570, 1718, 416, 1506, 544, 1558, 1598, 508, 544, 1746, 416, 1504, 546, + 1560, 570, 1534, 1598, 690, 1414, 508, 544, 1560, 546, 1560, 544, 1746, 416, + 1504, 546, 1560, 546, 1560, 570, 1718, 416, 1504, 544, 1560, 570, 1536, 544, + 1744, 416, 1506, 570, 1534, 546, 1558, 546, 1744, 418, 1502, 572, 1534, 544, + 1560, 570, 1720, 416, 1506, 544, 1560, 546, 1560, 544, 1744, 1414, 506, + 1572, 534, 544, 1560, 570, 1720, 416, 1504, 570, 1536, 544, 1560, 572, 1718, + 416, 1504, 570, 1542, 592, 1504, 570, 1720, 416, 1502, 1572, 534, 544, 1560, + 572, 1718, 1414, 508, 544, 1560, 570, 1534, 570, 1508, 1840, 34174, 8230, + 4292, 1546, 480, 546, 1560, 572, 1534, 570, 1718, 416, 1502, 572, 1532, 572, + 1532, 572, 1718, 1440, 480, 570, 1534, 572, 1534, 572, 1716, 418, 1504, 572, + 1532, 1626, 480, 572, 1718, 418, 1502, 574, 1534, 572, 1530, 1626, 662, + 1442, 480, 572, 1534, 572, 1534, 572, 1716, 418, 1502, 574, 1542, 592, 1504, + 598, 1692, 418, 1504, 572, 1532, 574, 1530, 574, 1716, 418, 1502, 598, 1508, + 572, 1532, 598, 1692, 418, 1502, 598, 1508, 572, 1532, 574, 1716, 418, 1504, + 598, 1508, 572, 1532, 574, 1716, 1442, 478, 1626, 480, 572, 1534, 572, 1718, + 392, 1526, 574, 1532, 572, 1532, 572, 1716, 418, 1502, 598, 1508, 574, 1532, + 598, 1700, 408, 1504, 1624, 480, 572, 1532, 574, 1716, 1440, 480, 572, 1532, + 572, 1532, 572, 1506, 1814}; // UNKNOWN ADA838FB + + uint8_t expectedState2[kAmcorStateLength] = { + 0x01, 0x41, 0x18, 0x00, 0x00, 0x30, 0x00, 0x12}; + + irsend.reset(); + irsend.sendRaw(rawData2, 263, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(AMCOR, irsend.capture.decode_type); + EXPECT_EQ(kAmcorBits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState2, irsend.capture.state, irsend.capture.bits); +} + +// Tests for IRAmcorAc class. + +TEST(TestAmcorAcClass, Power) { + IRAmcorAc ac(0); + ac.begin(); + + ac.on(); + EXPECT_TRUE(ac.getPower()); + + ac.off(); + EXPECT_FALSE(ac.getPower()); + + ac.setPower(true); + EXPECT_TRUE(ac.getPower()); + + ac.setPower(false); + EXPECT_FALSE(ac.getPower()); +} + +TEST(TestAmcorAcClass, Temperature) { + IRAmcorAc ac(0); + ac.begin(); + + ac.setTemp(0); + EXPECT_EQ(kAmcorMinTemp, ac.getTemp()); + + ac.setTemp(255); + EXPECT_EQ(kAmcorMaxTemp, ac.getTemp()); + + ac.setTemp(kAmcorMinTemp); + EXPECT_EQ(kAmcorMinTemp, ac.getTemp()); + + ac.setTemp(kAmcorMaxTemp); + EXPECT_EQ(kAmcorMaxTemp, ac.getTemp()); + + ac.setTemp(kAmcorMinTemp - 1); + EXPECT_EQ(kAmcorMinTemp, ac.getTemp()); + + ac.setTemp(kAmcorMaxTemp + 1); + EXPECT_EQ(kAmcorMaxTemp, ac.getTemp()); + + ac.setTemp(17); + EXPECT_EQ(17, ac.getTemp()); + + ac.setTemp(21); + EXPECT_EQ(21, ac.getTemp()); + + ac.setTemp(25); + EXPECT_EQ(25, ac.getTemp()); + + ac.setTemp(29); + EXPECT_EQ(29, ac.getTemp()); +} + +TEST(TestAmcorAcClass, OperatingMode) { + IRAmcorAc ac(0); + ac.begin(); + + ac.setMode(kAmcorAuto); + EXPECT_EQ(kAmcorAuto, ac.getMode()); + + ac.setMode(kAmcorCool); + EXPECT_EQ(kAmcorCool, ac.getMode()); + + ac.setMode(kAmcorHeat); + EXPECT_EQ(kAmcorHeat, ac.getMode()); + + ac.setMode(kAmcorDry); + EXPECT_EQ(kAmcorDry, ac.getMode()); + + ac.setMode(kAmcorFan); + EXPECT_EQ(kAmcorFan, ac.getMode()); + + ac.setMode(kAmcorAuto + 1); + EXPECT_EQ(kAmcorAuto, ac.getMode()); + + ac.setMode(255); + EXPECT_EQ(kAmcorAuto, ac.getMode()); +} + +TEST(TestAmcorAcClass, FanSpeed) { + IRAmcorAc ac(0); + ac.begin(); + + ac.setFan(0); + EXPECT_EQ(kAmcorFanAuto, ac.getFan()); + + ac.setFan(255); + EXPECT_EQ(kAmcorFanAuto, ac.getFan()); + + ac.setFan(kAmcorFanMax); + EXPECT_EQ(kAmcorFanMax, ac.getFan()); + + ac.setFan(kAmcorFanMax + 1); + EXPECT_EQ(kAmcorFanAuto, ac.getFan()); + + ac.setFan(kAmcorFanMax - 1); + EXPECT_EQ(kAmcorFanMax - 1, ac.getFan()); + + ac.setFan(1); + EXPECT_EQ(1, ac.getFan()); + + ac.setFan(1); + EXPECT_EQ(1, ac.getFan()); + + ac.setFan(3); + EXPECT_EQ(3, ac.getFan()); +} + +TEST(TestAmcorAcClass, Checksums) { + uint8_t state[kAmcorStateLength] = { + 0x01, 0x41, 0x30, 0x00, 0x00, 0x30, 0x00, 0x0C}; + + ASSERT_EQ(0x0C, IRAmcorAc::calcChecksum(state)); + EXPECT_TRUE(IRAmcorAc::validChecksum(state)); + // Change the array so the checksum is invalid. + state[0] ^= 0xFF; + EXPECT_FALSE(IRAmcorAc::validChecksum(state)); + // Restore the previous change, and change another byte. + state[0] ^= 0xFF; + state[4] ^= 0xFF; + EXPECT_FALSE(IRAmcorAc::validChecksum(state)); + state[4] ^= 0xFF; + EXPECT_TRUE(IRAmcorAc::validChecksum(state)); + + // Additional known good states. + uint8_t knownGood1[kAmcorStateLength] = { + 0x01, 0x11, 0x3E, 0x00, 0x00, 0x30, 0x00, 0x17}; + EXPECT_TRUE(IRAmcorAc::validChecksum(knownGood1)); + ASSERT_EQ(0x17, IRAmcorAc::calcChecksum(knownGood1)); + uint8_t knownGood2[kAmcorStateLength] = { + 0x01, 0x22, 0x26, 0x00, 0x00, 0x30, 0x00, 0x10}; + EXPECT_TRUE(IRAmcorAc::validChecksum(knownGood2)); + ASSERT_EQ(0x10, IRAmcorAc::calcChecksum(knownGood2)); + uint8_t knownGood3[kAmcorStateLength] = { + 0x01, 0x41, 0x24, 0x00, 0x00, 0xC0, 0x00, 0x18}; + EXPECT_TRUE(IRAmcorAc::validChecksum(knownGood3)); + ASSERT_EQ(0x18, IRAmcorAc::calcChecksum(knownGood3)); + + // For a recalculation. + uint8_t knownBad[kAmcorStateLength] = { + // Same as knownGood3 except for the checksum. + 0x01, 0x41, 0x24, 0x00, 0x00, 0xC0, 0x00, 0x00}; + EXPECT_FALSE(IRAmcorAc::validChecksum(knownBad)); + IRAmcorAc ac(0); + ac.setRaw(knownBad); + EXPECT_STATE_EQ(knownGood3, ac.getRaw(), kAmcorBits); +} + +TEST(TestAmcorAcClass, Max) { + IRAmcorAc ac(0); + ac.begin(); + + ac.setMode(kAmcorCool); + ac.setMax(true); + EXPECT_EQ(kAmcorCool, ac.getMode()); + EXPECT_EQ(kAmcorMinTemp, ac.getTemp()); + EXPECT_TRUE(ac.getMax()); + ac.setMax(false); + EXPECT_EQ(kAmcorCool, ac.getMode()); + EXPECT_EQ(kAmcorMinTemp, ac.getTemp()); + EXPECT_FALSE(ac.getMax()); + + ac.setMode(kAmcorHeat); + ac.setMax(true); + EXPECT_EQ(kAmcorHeat, ac.getMode()); + EXPECT_EQ(kAmcorMaxTemp, ac.getTemp()); + EXPECT_TRUE(ac.getMax()); + ac.setMax(false); + EXPECT_EQ(kAmcorHeat, ac.getMode()); + EXPECT_EQ(kAmcorMaxTemp, ac.getTemp()); + EXPECT_FALSE(ac.getMax()); + + ac.setMode(kAmcorAuto); + ac.setTemp(25); + ac.setMax(true); + EXPECT_EQ(kAmcorAuto, ac.getMode()); + EXPECT_EQ(25, ac.getTemp()); + EXPECT_FALSE(ac.getMax()); + + // Test known real data. + uint8_t lo[kAmcorStateLength] = { + 0x01, 0x41, 0x18, 0x00, 0x00, 0x30, 0x03, 0x15}; + uint8_t hi[kAmcorStateLength] = { + 0x01, 0x12, 0x40, 0x00, 0x00, 0x30, 0x03, 0x0E}; + ac.setRaw(lo); + EXPECT_EQ("Power: On, Mode: 1 (COOL), Fan: 4 (Auto), Temp: 12C, Max: On", + ac.toString()); + ac.setRaw(hi); + EXPECT_EQ("Power: On, Mode: 2 (HEAT), Fan: 1 (Low), Temp: 32C, Max: On", + ac.toString()); +} diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Argo_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Argo_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Argo_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Argo_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Carrier_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Carrier_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Carrier_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Carrier_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Coolix_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Coolix_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Coolix_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Coolix_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Daikin_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Daikin_test.cpp old mode 100644 new mode 100755 similarity index 96% rename from lib/IRremoteESP8266-2.6.4/test/ir_Daikin_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Daikin_test.cpp index d762656e323a..774109c3a667 --- a/lib/IRremoteESP8266-2.6.4/test/ir_Daikin_test.cpp +++ b/lib/IRremoteESP8266-2.6.5/test/ir_Daikin_test.cpp @@ -1519,6 +1519,11 @@ TEST(TestUtils, Housekeeping) { ASSERT_TRUE(hasACState(decode_type_t::DAIKIN128)); ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::DAIKIN128)); + ASSERT_EQ("DAIKIN152", typeToString(decode_type_t::DAIKIN152)); + ASSERT_EQ(decode_type_t::DAIKIN152, strToDecodeType("DAIKIN152")); + ASSERT_TRUE(hasACState(decode_type_t::DAIKIN152)); + ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::DAIKIN152)); + ASSERT_EQ("DAIKIN160", typeToString(decode_type_t::DAIKIN160)); ASSERT_EQ(decode_type_t::DAIKIN160, strToDecodeType("DAIKIN160")); ASSERT_TRUE(hasACState(decode_type_t::DAIKIN160)); @@ -2917,3 +2922,65 @@ TEST(TestDaikin128Class, ReconstructKnownState) { EXPECT_STATE_EQ(expectedState, ac.getRaw(), kDaikin128Bits); } + +// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +// Data from: +// https://github.com/crankyoldgit/IRremoteESP8266/issues/873#issue-485088080 +TEST(TestDecodeDaikin152, RealExample) { + IRsendTest irsend(0); + IRrecv irrecv(0); + uint16_t rawData[319] = { + 450, 420, 448, 446, 422, 444, 422, 446, 422, 446, 422, 25182, 3492, 1718, + 450, 1288, 448, 422, 446, 448, 420, 446, 422, 1290, 448, 422, 446, 446, + 422, 446, 424, 420, 448, 1290, 448, 446, 422, 1288, 448, 1288, 450, 420, + 448, 1288, 448, 1288, 450, 1288, 448, 1288, 448, 1290, 448, 446, 422, 446, + 422, 1288, 450, 446, 422, 420, 446, 446, 422, 422, 446, 446, 422, 420, + 448, 422, 446, 446, 422, 446, 422, 446, 422, 420, 446, 446, 422, 446, 422, + 422, 446, 446, 422, 422, 446, 446, 422, 446, 422, 446, 422, 446, 422, 446, + 424, 444, 424, 446, 420, 446, 422, 446, 422, 424, 444, 444, 422, 424, 444, + 1288, 450, 444, 422, 1288, 450, 1288, 450, 444, 422, 422, 446, 446, 422, + 446, 422, 446, 422, 446, 422, 422, 446, 420, 448, 444, 422, 446, 422, 446, + 422, 420, 448, 446, 422, 446, 422, 446, 422, 422, 446, 1286, 450, 422, + 448, 446, 422, 446, 422, 422, 446, 420, 446, 422, 446, 446, 422, 422, 446, + 446, 422, 422, 446, 446, 424, 444, 422, 420, 448, 446, 422, 420, 446, 446, + 422, 446, 422, 420, 448, 444, 422, 422, 448, 444, 424, 420, 446, 446, 422, + 446, 422, 422, 446, 444, 422, 446, 422, 444, 422, 446, 422, 420, 448, 446, + 422, 420, 448, 446, 422, 446, 422, 446, 422, 446, 422, 446, 422, 444, 422, + 1288, 450, 420, 448, 446, 420, 446, 422, 446, 422, 446, 424, 420, 448, + 444, 422, 422, 446, 446, 424, 420, 448, 1312, 424, 420, 448, 1288, 448, + 446, 422, 446, 424, 420, 446, 1288, 450, 1288, 450, 444, 422, 446, 422, + 422, 448, 444, 422, 420, 448, 446, 422, 1288, 448, 446, 422, 446, 422, + 444, 424, 444, 422, 446, 422, 446, 422, 420, 448, 446, 422, 420, 446, + 1290, 448, 1288, 448, 420, 446, 1288, 448, 420, 446, 1288, 450, 444, 424, + 1286, 450}; // UNKNOWN 2B9504D3 + uint8_t expectedState[kDaikin152StateLength] = { + 0x11, 0xDA, 0x27, 0x00, 0x00, 0x00, 0x34, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0xC5, 0x40, 0x00, 0xAB}; + + irsend.begin(); + irsend.reset(); + irsend.sendRaw(rawData, 319, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + ASSERT_EQ(DAIKIN152, irsend.capture.decode_type); + ASSERT_EQ(kDaikin152Bits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); +} + +// https://github.com/crankyoldgit/IRremoteESP8266/issues/873 +TEST(TestDecodeDaikin152, SyntheticExample) { + IRsendTest irsend(0); + IRrecv irrecv(0); + uint8_t expectedState[kDaikin152StateLength] = { + 0x11, 0xDA, 0x27, 0x00, 0x00, 0x00, 0x34, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0xC5, 0x40, 0x00, 0xAB}; + + irsend.begin(); + irsend.reset(); + irsend.sendDaikin152(expectedState); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + ASSERT_EQ(DAIKIN152, irsend.capture.decode_type); + ASSERT_EQ(kDaikin152Bits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); +} diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Denon_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Denon_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Denon_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Denon_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Dish_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Dish_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Dish_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Dish_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Electra_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Electra_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Electra_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Electra_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Fujitsu_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Fujitsu_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Fujitsu_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Fujitsu_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_GICable_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_GICable_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_GICable_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_GICable_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_GlobalCache_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_GlobalCache_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_GlobalCache_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_GlobalCache_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Goodweather_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Goodweather_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Goodweather_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Goodweather_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Gree_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Gree_test.cpp old mode 100644 new mode 100755 similarity index 94% rename from lib/IRremoteESP8266-2.6.4/test/ir_Gree_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Gree_test.cpp index 8d6fa5141090..d85df72b8489 --- a/lib/IRremoteESP8266-2.6.4/test/ir_Gree_test.cpp +++ b/lib/IRremoteESP8266-2.6.5/test/ir_Gree_test.cpp @@ -497,7 +497,8 @@ TEST(TestGreeClass, HumanReadable) { EXPECT_EQ( "Model: 1 (YAW1F), Power: Off, Mode: 0 (AUTO), Temp: 25C, Fan: 0 (Auto), " "Turbo: Off, IFeel: Off, WiFi: Off, XFan: Off, Light: On, Sleep: Off, " - "Swing Vertical Mode: Manual, Swing Vertical Pos: 0 (Last Pos)", + "Swing Vertical Mode: Manual, Swing Vertical Pos: 0 (Last Pos), " + "Timer: Off", irgree.toString()); irgree.on(); irgree.setMode(kGreeCool); @@ -510,10 +511,11 @@ TEST(TestGreeClass, HumanReadable) { irgree.setIFeel(true); irgree.setWiFi(true); irgree.setSwingVertical(true, kGreeSwingAuto); + irgree.setTimer(12 * 60 + 30); EXPECT_EQ( "Model: 1 (YAW1F), Power: On, Mode: 1 (COOL), Temp: 16C, Fan: 3 (High), " "Turbo: On, IFeel: On, WiFi: On, XFan: On, Light: Off, Sleep: On, " - "Swing Vertical Mode: Auto, Swing Vertical Pos: 1 (Auto)", + "Swing Vertical Mode: Auto, Swing Vertical Pos: 1 (Auto), Timer: 12:30", irgree.toString()); } @@ -573,7 +575,7 @@ TEST(TestDecodeGree, NormalRealExample) { EXPECT_EQ( "Model: 1 (YAW1F), Power: On, Mode: 1 (COOL), Temp: 26C, Fan: 1 (Low), " "Turbo: Off, IFeel: Off, WiFi: Off, XFan: Off, Light: On, Sleep: Off, " - "Swing Vertical Mode: Manual, Swing Vertical Pos: 2", + "Swing Vertical Mode: Manual, Swing Vertical Pos: 2, Timer: Off", irgree.toString()); } @@ -628,7 +630,7 @@ TEST(TestGreeClass, Issue814Power) { EXPECT_EQ( "Model: 2 (YBOFB), Power: On, Mode: 1 (COOL), Temp: 23C, Fan: 1 (Low), " "Turbo: Off, IFeel: Off, WiFi: Off, XFan: Off, Light: On, Sleep: Off, " - "Swing Vertical Mode: Auto, Swing Vertical Pos: 1 (Auto)", + "Swing Vertical Mode: Auto, Swing Vertical Pos: 1 (Auto), Timer: Off", ac.toString()); ac.off(); EXPECT_STATE_EQ(off, ac.getRaw(), kGreeBits); @@ -643,3 +645,44 @@ TEST(TestGreeClass, Issue814Power) { ac.on(); EXPECT_STATE_EQ(YBOFB_on, ac.getRaw(), kGreeBits); } + +TEST(TestGreeClass, Timer) { + IRGreeAC ac(0); + ac.begin(); + + ac.setTimer(0); + EXPECT_FALSE(ac.getTimerEnabled()); + EXPECT_EQ(0, ac.getTimer()); + + ac.setTimer(29); + EXPECT_FALSE(ac.getTimerEnabled()); + EXPECT_EQ(0, ac.getTimer()); + + ac.setTimer(30); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(30, ac.getTimer()); + + ac.setTimer(60); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(60, ac.getTimer()); + + ac.setTimer(90); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(90, ac.getTimer()); + + ac.setTimer(10 * 60); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(10 * 60, ac.getTimer()); + + ac.setTimer(23 * 60 + 59); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(23 * 60 + 30, ac.getTimer()); + + ac.setTimer(24 * 60 + 1); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(24 * 60, ac.getTimer()); + + ac.setTimer(24 * 60 + 30); + EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_EQ(24 * 60, ac.getTimer()); +} diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Haier_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Haier_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Haier_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Haier_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Hitachi_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Hitachi_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Hitachi_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Hitachi_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Inax_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Inax_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Inax_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Inax_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_JVC_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_JVC_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_JVC_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_JVC_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Kelvinator_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Kelvinator_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Kelvinator_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Kelvinator_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_LG_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_LG_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_LG_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_LG_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Lasertag_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Lasertag_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Lasertag_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Lasertag_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Lego_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Lego_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Lego_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Lego_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Lutron_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Lutron_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Lutron_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Lutron_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_MWM_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_MWM_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_MWM_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_MWM_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Magiquest_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Magiquest_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Magiquest_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Magiquest_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Midea_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Midea_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Midea_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Midea_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_MitsubishiHeavy_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_MitsubishiHeavy_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_MitsubishiHeavy_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_MitsubishiHeavy_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Mitsubishi_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Mitsubishi_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Mitsubishi_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Mitsubishi_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_NEC_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_NEC_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_NEC_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_NEC_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Neoclima_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Neoclima_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Neoclima_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Neoclima_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Nikai_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Nikai_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Nikai_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Nikai_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Panasonic_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Panasonic_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Panasonic_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Panasonic_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Pioneer_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Pioneer_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Pioneer_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Pioneer_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Pronto_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Pronto_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Pronto_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Pronto_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_RC5_RC6_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_RC5_RC6_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_RC5_RC6_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_RC5_RC6_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_RCMM_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_RCMM_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_RCMM_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_RCMM_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Samsung_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Samsung_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Samsung_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Samsung_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Sanyo_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Sanyo_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Sanyo_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Sanyo_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Sharp_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Sharp_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Sharp_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Sharp_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Sherwood_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Sherwood_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Sherwood_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Sherwood_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Sony_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Sony_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Sony_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Sony_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Tcl_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Tcl_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Tcl_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Tcl_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Teco_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Teco_test.cpp old mode 100644 new mode 100755 similarity index 86% rename from lib/IRremoteESP8266-2.6.4/test/ir_Teco_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Teco_test.cpp index aeacfcc68abb..4ed7fbd9fcad --- a/lib/IRremoteESP8266-2.6.4/test/ir_Teco_test.cpp +++ b/lib/IRremoteESP8266-2.6.5/test/ir_Teco_test.cpp @@ -198,26 +198,72 @@ TEST(TestTecoACClass, Sleep) { EXPECT_TRUE(ac.getSleep()); } +TEST(TestTecoACClass, Light) { + IRTecoAc ac(0); + ac.begin(); + + ac.setLight(true); + EXPECT_TRUE(ac.getLight()); + ac.setLight(false); + EXPECT_EQ(false, ac.getLight()); + ac.setLight(true); + EXPECT_TRUE(ac.getLight()); + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/870#issue-484797174 + ac.setRaw(0x250200A09); + EXPECT_TRUE(ac.getLight()); +} + +TEST(TestTecoACClass, Humid) { + IRTecoAc ac(0); + ac.begin(); + + ac.setHumid(true); + EXPECT_TRUE(ac.getHumid()); + ac.setHumid(false); + EXPECT_EQ(false, ac.getHumid()); + ac.setHumid(true); + EXPECT_TRUE(ac.getHumid()); + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/870#issuecomment-524536810 + ac.setRaw(0x250100A09); + EXPECT_TRUE(ac.getHumid()); +} + +TEST(TestTecoACClass, Save) { + IRTecoAc ac(0); + ac.begin(); + + ac.setSave(true); + EXPECT_TRUE(ac.getSave()); + ac.setSave(false); + EXPECT_EQ(false, ac.getSave()); + ac.setSave(true); + EXPECT_TRUE(ac.getSave()); + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/870#issuecomment-524536810 + ac.setRaw(0x250800A09); + EXPECT_TRUE(ac.getSave()); +} + TEST(TestTecoACClass, MessageConstuction) { IRTecoAc ac(0); EXPECT_EQ( "Power: Off, Mode: 0 (AUTO), Temp: 16C, Fan: 0 (Auto), Sleep: Off, " - "Swing: Off", + "Swing: Off, Light: Off, Humid: Off, Save: Off", ac.toString()); ac.setPower(true); ac.setMode(kTecoCool); ac.setTemp(21); ac.setFan(kTecoFanHigh); ac.setSwing(false); + ac.setLight(false); EXPECT_EQ( "Power: On, Mode: 1 (COOL), Temp: 21C, Fan: 3 (High), Sleep: Off, " - "Swing: Off", + "Swing: Off, Light: Off, Humid: Off, Save: Off", ac.toString()); ac.setSwing(true); EXPECT_EQ( "Power: On, Mode: 1 (COOL), Temp: 21C, Fan: 3 (High), Sleep: Off, " - "Swing: On", + "Swing: On, Light: Off, Humid: Off, Save: Off", ac.toString()); ac.setSwing(false); ac.setFan(kTecoFanLow); @@ -225,17 +271,20 @@ TEST(TestTecoACClass, MessageConstuction) { ac.setMode(kTecoHeat); EXPECT_EQ( "Power: On, Mode: 4 (HEAT), Temp: 21C, Fan: 1 (Low), Sleep: On, " - "Swing: Off", + "Swing: Off, Light: Off, Humid: Off, Save: Off", ac.toString()); ac.setSleep(false); EXPECT_EQ( "Power: On, Mode: 4 (HEAT), Temp: 21C, Fan: 1 (Low), Sleep: Off, " - "Swing: Off", + "Swing: Off, Light: Off, Humid: Off, Save: Off", ac.toString()); ac.setTemp(25); + ac.setLight(true); + ac.setSave(true); + ac.setHumid(true); EXPECT_EQ( "Power: On, Mode: 4 (HEAT), Temp: 25C, Fan: 1 (Low), Sleep: Off, " - "Swing: Off", + "Swing: Off, Light: On, Humid: On, Save: On", ac.toString()); } @@ -253,7 +302,7 @@ TEST(TestTecoACClass, ReconstructKnownMessage) { EXPECT_EQ(expected, ac.getRaw()); EXPECT_EQ( "Power: On, Mode: 1 (COOL), Temp: 27C, Fan: 0 (Auto), Sleep: On, " - "Swing: On", + "Swing: On, Light: Off, Humid: Off, Save: Off", ac.toString()); } @@ -295,7 +344,7 @@ TEST(TestDecodeTeco, NormalDecodeWithStrict) { ac.setRaw(irsend.capture.value); EXPECT_EQ( "Power: Off, Mode: 0 (AUTO), Temp: 16C, Fan: 0 (Auto), Sleep: Off, " - "Swing: Off", + "Swing: Off, Light: Off, Humid: Off, Save: Off", ac.toString()); } @@ -328,7 +377,7 @@ TEST(TestDecodeTeco, RealNormalExample) { ac.setRaw(irsend.capture.value); EXPECT_EQ( "Power: On, Mode: 1 (COOL), Temp: 27C, Fan: 0 (Auto), Sleep: On, " - "Swing: On", + "Swing: On, Light: Off, Humid: Off, Save: Off", ac.toString()); uint16_t rawData2[73] = { @@ -353,7 +402,7 @@ TEST(TestDecodeTeco, RealNormalExample) { ac.setRaw(irsend.capture.value); EXPECT_EQ( "Power: On, Mode: 2 (DRY), Temp: 21C, Fan: 2 (Medium), Sleep: Off, " - "Swing: On", + "Swing: On, Light: Off, Humid: Off, Save: Off", ac.toString()); } diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Toshiba_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Toshiba_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Toshiba_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Toshiba_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Trotec_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Trotec_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Trotec_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Trotec_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Vestel_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Vestel_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Vestel_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Vestel_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Whirlpool_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Whirlpool_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Whirlpool_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Whirlpool_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/test/ir_Whynter_test.cpp b/lib/IRremoteESP8266-2.6.5/test/ir_Whynter_test.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/test/ir_Whynter_test.cpp rename to lib/IRremoteESP8266-2.6.5/test/ir_Whynter_test.cpp diff --git a/lib/IRremoteESP8266-2.6.4/tools/Makefile b/lib/IRremoteESP8266-2.6.5/tools/Makefile old mode 100644 new mode 100755 similarity index 98% rename from lib/IRremoteESP8266-2.6.4/tools/Makefile rename to lib/IRremoteESP8266-2.6.5/tools/Makefile index 7ae48d392e18..d2da05eb3cbb --- a/lib/IRremoteESP8266-2.6.4/tools/Makefile +++ b/lib/IRremoteESP8266-2.6.5/tools/Makefile @@ -51,7 +51,7 @@ PROTOCOLS = ir_NEC.o ir_Sony.o ir_Samsung.o ir_JVC.o ir_RCMM.o ir_RC5_RC6.o \ ir_GICable.o ir_Whirlpool.o ir_Lutron.o ir_Electra.o ir_Pioneer.o \ ir_MWM.o ir_Vestel.o ir_Teco.o ir_Tcl.o ir_Lego.o \ ir_MitsubishiHeavy.o ir_Goodweather.o ir_Inax.o ir_Argo.o \ - ir_Trotec.o ir_Neoclima.o + ir_Trotec.o ir_Neoclima.o ir_Amcor.o # Common object files COMMON_OBJ = IRutils.o IRtimer.o IRsend.o IRrecv.o $(PROTOCOLS) @@ -227,3 +227,6 @@ ir_Goodweather.o : $(USER_DIR)/ir_Goodweather.cpp $(USER_DIR)/ir_Goodweather.h $ ir_Neoclima.o : $(USER_DIR)/ir_Neoclima.cpp $(USER_DIR)/ir_Neoclima.h $(COMMON_DEPS) $(GTEST_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/ir_Neoclima.cpp + +ir_Amcor.o : $(USER_DIR)/ir_Amcor.cpp $(USER_DIR)/ir_Amcor.h $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/ir_Amcor.cpp diff --git a/lib/IRremoteESP8266-2.6.4/tools/RawToGlobalCache.sh b/lib/IRremoteESP8266-2.6.5/tools/RawToGlobalCache.sh similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/RawToGlobalCache.sh rename to lib/IRremoteESP8266-2.6.5/tools/RawToGlobalCache.sh diff --git a/lib/IRremoteESP8266-2.6.4/tools/auto_analyse_raw_data.py b/lib/IRremoteESP8266-2.6.5/tools/auto_analyse_raw_data.py similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/auto_analyse_raw_data.py rename to lib/IRremoteESP8266-2.6.5/tools/auto_analyse_raw_data.py diff --git a/lib/IRremoteESP8266-2.6.4/tools/auto_analyse_raw_data_test.py b/lib/IRremoteESP8266-2.6.5/tools/auto_analyse_raw_data_test.py similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/auto_analyse_raw_data_test.py rename to lib/IRremoteESP8266-2.6.5/tools/auto_analyse_raw_data_test.py diff --git a/lib/IRremoteESP8266-2.6.4/tools/gc_decode.cpp b/lib/IRremoteESP8266-2.6.5/tools/gc_decode.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/gc_decode.cpp rename to lib/IRremoteESP8266-2.6.5/tools/gc_decode.cpp diff --git a/lib/IRremoteESP8266-2.6.4/tools/mkkeywords b/lib/IRremoteESP8266-2.6.5/tools/mkkeywords similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/mkkeywords rename to lib/IRremoteESP8266-2.6.5/tools/mkkeywords diff --git a/lib/IRremoteESP8266-2.6.4/tools/mode2_decode.cpp b/lib/IRremoteESP8266-2.6.5/tools/mode2_decode.cpp old mode 100644 new mode 100755 similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/mode2_decode.cpp rename to lib/IRremoteESP8266-2.6.5/tools/mode2_decode.cpp diff --git a/lib/IRremoteESP8266-2.6.4/tools/scrape_supported_devices.py b/lib/IRremoteESP8266-2.6.5/tools/scrape_supported_devices.py similarity index 100% rename from lib/IRremoteESP8266-2.6.4/tools/scrape_supported_devices.py rename to lib/IRremoteESP8266-2.6.5/tools/scrape_supported_devices.py diff --git a/lib/NeoPixelBus-2.2.9/COPYING b/lib/NeoPixelBus-2.2.9/COPYING deleted file mode 100644 index 10926e87f113..000000000000 --- a/lib/NeoPixelBus-2.2.9/COPYING +++ /dev/null @@ -1,675 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. - diff --git a/lib/NeoPixelBus-2.2.9/library.json b/lib/NeoPixelBus-2.2.9/library.json deleted file mode 100644 index 35e8ea0c2ea2..000000000000 --- a/lib/NeoPixelBus-2.2.9/library.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "NeoPixelBus", - "keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, RGB, RGBW", - "description": "A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. Supports most Arduino platforms. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI.", - "homepage": "https://github.com/Makuna/NeoPixelBus/wiki", - "repository": - { - "type": "git", - "url": "https://github.com/Makuna/NeoPixelBus" - }, - "version": "2.2.9", - "frameworks": "arduino", - "platforms": "*" -} - diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.cpp b/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.cpp deleted file mode 100644 index 7bfc3e0d2d20..000000000000 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266 UART hardware - -Written by Michael C. Miller. - -I invest time and resources providing this open source code, -please support me by dontating (see https://github.com/Makuna/NeoPixelBus) - -------------------------------------------------------------------------- -This file is part of the Makuna/NeoPixelBus library. - -NeoPixelBus is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as -published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -NeoPixelBus is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with NeoPixel. If not, see -. --------------------------------------------------------------------------*/ - -#ifdef ARDUINO_ARCH_ESP8266 -#include "NeoEsp8266UartMethod.h" -#include -extern "C" -{ - #include - #include - #include - #include -} - -#define UART1 1 -#define UART1_INV_MASK (0x3f << 19) - -// Gets the number of bytes waiting in the TX FIFO of UART1 -static inline uint8_t getUartTxFifoLength() -{ - return (U1S >> USTXC) & 0xff; -} - -// Append a byte to the TX FIFO of UART1 -// You must ensure the TX FIFO isn't full -static inline void enqueue(uint8_t byte) -{ - U1F = byte; -} - -static const uint8_t* esp8266_uart1_async_buf; -static const uint8_t* esp8266_uart1_async_buf_end; - -NeoEsp8266Uart::NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize) -{ - _sizePixels = pixelCount * elementSize; - _pixels = (uint8_t*)malloc(_sizePixels); - memset(_pixels, 0x00, _sizePixels); -} - -NeoEsp8266Uart::~NeoEsp8266Uart() -{ - // Wait until the TX fifo is empty. This way we avoid broken frames - // when destroying & creating a NeoPixelBus to change its length. - while (getUartTxFifoLength() > 0) - { - yield(); - } - - free(_pixels); -} - -void NeoEsp8266Uart::InitializeUart(uint32_t uartBaud) -{ - // Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1) - Serial1.begin(uartBaud, SERIAL_6N1, SERIAL_TX_ONLY); - - // Invert the TX voltage associated with logic level so: - // - A logic level 0 will generate a Vcc signal - // - A logic level 1 will generate a Gnd signal - CLEAR_PERI_REG_MASK(UART_CONF0(UART1), UART1_INV_MASK); - SET_PERI_REG_MASK(UART_CONF0(UART1), (BIT(22))); -} - -void NeoEsp8266Uart::UpdateUart() -{ - // Since the UART can finish sending queued bytes in the FIFO in - // the background, instead of waiting for the FIFO to flush - // we annotate the start time of the frame so we can calculate - // when it will finish. - _startTime = micros(); - - // Then keep filling the FIFO until done - const uint8_t* ptr = _pixels; - const uint8_t* end = ptr + _sizePixels; - while (ptr != end) - { - ptr = FillUartFifo(ptr, end); - } -} - -const uint8_t* ICACHE_RAM_ATTR NeoEsp8266Uart::FillUartFifo(const uint8_t* pixels, const uint8_t* end) -{ - // Remember: UARTs send less significant bit (LSB) first so - // pushing ABCDEF byte will generate a 0FEDCBA1 signal, - // including a LOW(0) start & a HIGH(1) stop bits. - // Also, we have configured UART to invert logic levels, so: - const uint8_t _uartData[4] = { - 0b110111, // On wire: 1 000 100 0 [Neopixel reads 00] - 0b000111, // On wire: 1 000 111 0 [Neopixel reads 01] - 0b110100, // On wire: 1 110 100 0 [Neopixel reads 10] - 0b000100, // On wire: 1 110 111 0 [NeoPixel reads 11] - }; - uint8_t avail = (UART_TX_FIFO_SIZE - getUartTxFifoLength()) / 4; - if (end - pixels > avail) - { - end = pixels + avail; - } - while (pixels < end) - { - uint8_t subpix = *pixels++; - enqueue(_uartData[(subpix >> 6) & 0x3]); - enqueue(_uartData[(subpix >> 4) & 0x3]); - enqueue(_uartData[(subpix >> 2) & 0x3]); - enqueue(_uartData[ subpix & 0x3]); - } - return pixels; -} - -NeoEsp8266AsyncUart::NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize) - : NeoEsp8266Uart(pixelCount, elementSize) -{ - _asyncPixels = (uint8_t*)malloc(_sizePixels); -} - -NeoEsp8266AsyncUart::~NeoEsp8266AsyncUart() -{ - // Remember: the UART interrupt can be sending data from _asyncPixels in the background - while (esp8266_uart1_async_buf != esp8266_uart1_async_buf_end) - { - yield(); - } - free(_asyncPixels); -} - -void ICACHE_RAM_ATTR NeoEsp8266AsyncUart::InitializeUart(uint32_t uartBaud) -{ - NeoEsp8266Uart::InitializeUart(uartBaud); - - // Disable all interrupts - ETS_UART_INTR_DISABLE(); - - // Clear the RX & TX FIFOS - SET_PERI_REG_MASK(UART_CONF0(UART1), UART_RXFIFO_RST | UART_TXFIFO_RST); - CLEAR_PERI_REG_MASK(UART_CONF0(UART1), UART_RXFIFO_RST | UART_TXFIFO_RST); - - // Set the interrupt handler - ETS_UART_INTR_ATTACH(IntrHandler, NULL); - - // Set tx fifo trigger. 80 bytes gives us 200 microsecs to refill the FIFO - WRITE_PERI_REG(UART_CONF1(UART1), 80 << UART_TXFIFO_EMPTY_THRHD_S); - - // Disable RX & TX interrupts. It is enabled by uart.c in the SDK - CLEAR_PERI_REG_MASK(UART_INT_ENA(UART1), UART_RXFIFO_FULL_INT_ENA | UART_TXFIFO_EMPTY_INT_ENA); - - // Clear all pending interrupts in UART1 - WRITE_PERI_REG(UART_INT_CLR(UART1), 0xffff); - - // Reenable interrupts - ETS_UART_INTR_ENABLE(); -} - -void NeoEsp8266AsyncUart::UpdateUart() -{ - // Instruct ESP8266 hardware uart1 to send the pixels asynchronously - esp8266_uart1_async_buf = _pixels; - esp8266_uart1_async_buf_end = _pixels + _sizePixels; - SET_PERI_REG_MASK(UART_INT_ENA(1), UART_TXFIFO_EMPTY_INT_ENA); - - // Annotate when we started to send bytes, so we can calculate when we are ready to send again - _startTime = micros(); - - // Copy the pixels to the idle buffer and swap them - memcpy(_asyncPixels, _pixels, _sizePixels); - std::swap(_asyncPixels, _pixels); -} - -void ICACHE_RAM_ATTR NeoEsp8266AsyncUart::IntrHandler(void* param) -{ - // Interrupt handler is shared between UART0 & UART1 - if (READ_PERI_REG(UART_INT_ST(UART1))) //any UART1 stuff - { - // Fill the FIFO with new data - esp8266_uart1_async_buf = FillUartFifo(esp8266_uart1_async_buf, esp8266_uart1_async_buf_end); - // Disable TX interrupt when done - if (esp8266_uart1_async_buf == esp8266_uart1_async_buf_end) - { - CLEAR_PERI_REG_MASK(UART_INT_ENA(UART1), UART_TXFIFO_EMPTY_INT_ENA); - } - // Clear all interrupts flags (just in case) - WRITE_PERI_REG(UART_INT_CLR(UART1), 0xffff); - } - - if (READ_PERI_REG(UART_INT_ST(UART0))) - { - // TODO: gdbstub uses the interrupt of UART0, but there is no way to call its - // interrupt handler gdbstub_uart_hdlr since it's static. - WRITE_PERI_REG(UART_INT_CLR(UART0), 0xffff); - } -} - -#endif - diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.h b/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.h deleted file mode 100644 index a92d5663127f..000000000000 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266UartMethod.h +++ /dev/null @@ -1,178 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266 UART hardware - -Written by Michael C. Miller. - -I invest time and resources providing this open source code, -please support me by dontating (see https://github.com/Makuna/NeoPixelBus) - -------------------------------------------------------------------------- -This file is part of the Makuna/NeoPixelBus library. - -NeoPixelBus is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as -published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -NeoPixelBus is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with NeoPixel. If not, see -. --------------------------------------------------------------------------*/ - -#pragma once - -#ifdef ARDUINO_ARCH_ESP8266 -#include - -// NeoEsp8266Uart contains all the low level details that doesn't -// depend on the transmission speed, and therefore, it isn't a template -class NeoEsp8266Uart -{ -protected: - NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize); - - ~NeoEsp8266Uart(); - - void InitializeUart(uint32_t uartBaud); - - void UpdateUart(); - - static const uint8_t* ICACHE_RAM_ATTR FillUartFifo(const uint8_t* pixels, const uint8_t* end); - - size_t _sizePixels; // Size of '_pixels' buffer below - uint8_t* _pixels; // Holds LED color values - uint32_t _startTime; // Microsecond count when last update started -}; - -// NeoEsp8266AsyncUart handles all transmission asynchronously using interrupts -// -// This UART controller uses two buffers that are swapped in every call to -// NeoPixelBus.Show(). One buffer contains the data that is being sent -// asynchronosly and another buffer contains the data that will be send -// in the next call to NeoPixelBus.Show(). -// -// Therefore, the result of NeoPixelBus.Pixels() is invalidated after -// every call to NeoPixelBus.Show() and must not be cached. -class NeoEsp8266AsyncUart: public NeoEsp8266Uart -{ -protected: - NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize); - - ~NeoEsp8266AsyncUart(); - - void InitializeUart(uint32_t uartBaud); - - void UpdateUart(); - -private: - static void ICACHE_RAM_ATTR IntrHandler(void* param); - - uint8_t* _asyncPixels; // Holds a copy of LED color values taken when UpdateUart began -}; - -// NeoEsp8266UartSpeedWs2813 contains the timing constants used to get NeoPixelBus running with the Ws2813 -class NeoEsp8266UartSpeedWs2813 -{ -public: - static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed - static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte - static const uint32_t ResetTimeUs = 250; // us between data send bursts to reset for next update -}; - -// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 800Khz -class NeoEsp8266UartSpeed800Kbps -{ -public: - static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed - static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte - static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update -}; - -// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 400Khz -class NeoEsp8266UartSpeed400Kbps -{ -public: - static const uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed - static const uint32_t UartBaud = 1600000; // 400mhz, 4 serial bytes per NeoByte - static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update -}; - -// NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that -// implements the methods needed to operate as a NeoPixelBus method. -template -class NeoEsp8266UartMethodBase: public T_BASE -{ -public: - NeoEsp8266UartMethodBase(uint16_t pixelCount, size_t elementSize) - : T_BASE(pixelCount, elementSize) - { - } - NeoEsp8266UartMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) - : T_BASE(pixelCount, elementSize) - { - } - - bool IsReadyToUpdate() const - { - uint32_t delta = micros() - this->_startTime; - return delta >= getPixelTime() + T_SPEED::ResetTimeUs; - } - - void Initialize() - { - this->InitializeUart(T_SPEED::UartBaud); - - // Inverting logic levels can generate a phantom bit in the led strip bus - // We need to delay 50+ microseconds the output stream to force a data - // latch and discard this bit. Otherwise, that bit would be prepended to - // the first frame corrupting it. - this->_startTime = micros() - getPixelTime(); - } - - void Update() - { - // Data latch = 50+ microsecond pause in the output stream. Rather than - // put a delay at the end of the function, the ending time is noted and - // the function will simply hold off (if needed) on issuing the - // subsequent round of data until the latch time has elapsed. This - // allows the mainline code to start generating the next frame of data - // rather than stalling for the latch. - while (!this->IsReadyToUpdate()) - { - yield(); - } - this->UpdateUart(); - } - - uint8_t* getPixels() const - { - return this->_pixels; - }; - - size_t getPixelsSize() const - { - return this->_sizePixels; - }; - -private: - uint32_t getPixelTime() const - { - return (T_SPEED::ByteSendTimeUs * this->_sizePixels); - }; -}; - -typedef NeoEsp8266UartMethodBase NeoEsp8266UartWs2813Method; -typedef NeoEsp8266UartMethodBase NeoEsp8266Uart800KbpsMethod; -typedef NeoEsp8266UartMethodBase NeoEsp8266Uart400KbpsMethod; - -typedef NeoEsp8266UartMethodBase NeoEsp8266AsyncUartWs2813Method; -typedef NeoEsp8266UartMethodBase NeoEsp8266AsyncUart800KbpsMethod; -typedef NeoEsp8266UartMethodBase NeoEsp8266AsyncUart400KbpsMethod; - -#endif - diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelEsp.c b/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelEsp.c deleted file mode 100644 index 52415ff4270c..000000000000 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelEsp.c +++ /dev/null @@ -1,151 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266 and Esp32. - -Written by Michael C. Miller. - -I invest time and resources providing this open source code, -please support me by dontating (see https://github.com/Makuna/NeoPixelBus) - -------------------------------------------------------------------------- -This file is part of the Makuna/NeoPixelBus library. - -NeoPixelBus is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as -published by the Free Software Foundation, either version 3 of -the License, or (at your option) any later version. - -NeoPixelBus is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with NeoPixel. If not, see -. --------------------------------------------------------------------------*/ - -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - -#include -#if defined(ARDUINO_ARCH_ESP8266) -#include -#endif - -// ESP32 doesn't define ICACHE_RAM_ATTR -#ifndef ICACHE_RAM_ATTR -#define ICACHE_RAM_ATTR IRAM_ATTR -#endif - -inline uint32_t _getCycleCount() -{ - uint32_t ccount; - __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); - return ccount; -} - -#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us -#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us -#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit -#define CYCLES_400_T0H (F_CPU / 2000000) -#define CYCLES_400_T1H (F_CPU / 833333) -#define CYCLES_400 (F_CPU / 400000) - -void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin) -{ - const uint32_t pinRegister = _BV(pin); - uint8_t mask; - uint8_t subpix; - uint32_t cyclesStart; - - // trigger emediately - cyclesStart = _getCycleCount() - CYCLES_800; - do - { - subpix = *pixels++; - for (mask = 0x80; mask != 0; mask >>= 1) - { - // do the checks here while we are waiting on time to pass - uint32_t cyclesBit = ((subpix & mask)) ? CYCLES_800_T1H : CYCLES_800_T0H; - uint32_t cyclesNext = cyclesStart; - - // after we have done as much work as needed for this next bit - // now wait for the HIGH - do - { - // cache and use this count so we don't incur another - // instruction before we turn the bit high - cyclesStart = _getCycleCount(); - } while ((cyclesStart - cyclesNext) < CYCLES_800); - - // set high -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1ts = pinRegister; -#else - GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); -#endif - - // wait for the LOW - do - { - cyclesNext = _getCycleCount(); - } while ((cyclesNext - cyclesStart) < cyclesBit); - - // set low -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1tc = pinRegister; -#else - GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); -#endif - } - } while (pixels < end); -} - -void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin) -{ - const uint32_t pinRegister = _BV(pin); - uint8_t mask; - uint8_t subpix; - uint32_t cyclesStart; - - // trigger emediately - cyclesStart = _getCycleCount() - CYCLES_400; - do - { - subpix = *pixels++; - for (mask = 0x80; mask; mask >>= 1) - { - uint32_t cyclesBit = ((subpix & mask)) ? CYCLES_400_T1H : CYCLES_400_T0H; - uint32_t cyclesNext = cyclesStart; - - // after we have done as much work as needed for this next bit - // now wait for the HIGH - do - { - // cache and use this count so we don't incur another - // instruction before we turn the bit high - cyclesStart = _getCycleCount(); - } while ((cyclesStart - cyclesNext) < CYCLES_400); - -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1ts = pinRegister; -#else - GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); -#endif - - // wait for the LOW - do - { - cyclesNext = _getCycleCount(); - } while ((cyclesNext - cyclesStart) < cyclesBit); - - // set low -#if defined(ARDUINO_ARCH_ESP32) - GPIO.out_w1tc = pinRegister; -#else - GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); -#endif - } - } while (pixels < end); -} - -#endif diff --git a/lib/NeoPixelBus-2.2.9/.gitattributes b/lib/NeoPixelBus-2.5.0.09/.gitattributes similarity index 100% rename from lib/NeoPixelBus-2.2.9/.gitattributes rename to lib/NeoPixelBus-2.5.0.09/.gitattributes diff --git a/lib/NeoPixelBus-2.2.9/.gitignore b/lib/NeoPixelBus-2.5.0.09/.gitignore similarity index 100% rename from lib/NeoPixelBus-2.2.9/.gitignore rename to lib/NeoPixelBus-2.5.0.09/.gitignore diff --git a/lib/NeoPixelBus-2.5.0.09/COPYING b/lib/NeoPixelBus-2.5.0.09/COPYING new file mode 100644 index 000000000000..153d416dc8d2 --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/COPYING @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/lib/NeoPixelBus-2.2.9/ReadMe.md b/lib/NeoPixelBus-2.5.0.09/ReadMe.md similarity index 70% rename from lib/NeoPixelBus-2.2.9/ReadMe.md rename to lib/NeoPixelBus-2.5.0.09/ReadMe.md index 580e72426177..a3ff660beeb2 100644 --- a/lib/NeoPixelBus-2.2.9/ReadMe.md +++ b/lib/NeoPixelBus-2.5.0.09/ReadMe.md @@ -1,15 +1,15 @@ # NeoPixelBus -[![Donate](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6AA97KE54UJR4) +[![Donate](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6AA97KE54UJR4) Arduino NeoPixel library A library to control one wire protocol RGB and RGBW leds like SK6812, WS2811, WS2812 and WS2813 that are commonly refered to as NeoPixels and two wire protocol RGB like APA102 commonly refered to as DotStars. Supports most Arduino platforms. -This is the most funtional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used. +This is the most functional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used. -Please read this best practices link before connecting your NeoPixels, it will save you alot of time and effort. +Please read this best practices link before connecting your NeoPixels, it will save you a lot of time and effort. [Adafruit NeoPixel Best Practices](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices) For quick questions jump on Gitter and ask away. @@ -17,6 +17,9 @@ For quick questions jump on Gitter and ask away. For bugs, make sure there isn't an active issue and then create one. +## Why this library and not FastLED or some other library? +See [Why this Library in the Wiki](https://github.com/Makuna/NeoPixelBus/wiki/Library-Comparisons). + ## Documentation [See Wiki](https://github.com/Makuna/NeoPixelBus/wiki) diff --git a/lib/NeoPixelBus-2.2.9/examples/DotStarTest/DotStarTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/DotStarTest/DotStarTest.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/DotStarTest/DotStarTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/DotStarTest/DotStarTest.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/NeoPixelBrightness/NeoPixelBrightness.ino b/lib/NeoPixelBus-2.5.0.09/examples/NeoPixelBrightness/NeoPixelBrightness.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/NeoPixelBrightness/NeoPixelBrightness.ino rename to lib/NeoPixelBus-2.5.0.09/examples/NeoPixelBrightness/NeoPixelBrightness.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/NeoPixelGamma/NeoPixelGamma.ino b/lib/NeoPixelBus-2.5.0.09/examples/NeoPixelGamma/NeoPixelGamma.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/NeoPixelGamma/NeoPixelGamma.ino rename to lib/NeoPixelBus-2.5.0.09/examples/NeoPixelGamma/NeoPixelGamma.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/NeoPixelTest/NeoPixelTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/NeoPixelTest/NeoPixelTest.ino similarity index 91% rename from lib/NeoPixelBus-2.2.9/examples/NeoPixelTest/NeoPixelTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/NeoPixelTest/NeoPixelTest.ino index 6d323b884789..415c8538ceb7 100644 --- a/lib/NeoPixelBus-2.2.9/examples/NeoPixelTest/NeoPixelTest.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/NeoPixelTest/NeoPixelTest.ino @@ -25,9 +25,7 @@ NeoPixelBus strip(PixelCount, PixelPin); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. // There are other Esp8266 alternative methods that provide more pin options, but also have // other side effects. -//NeoPixelBus strip(PixelCount); -// -// NeoEsp8266Uart800KbpsMethod uses GPI02 instead +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods // You can also use one of these for Esp8266, // each having their own restrictions @@ -38,9 +36,10 @@ NeoPixelBus strip(PixelCount, PixelPin); //NeoPixelBus strip(PixelCount, PixelPin); // Uart method is good for the Esp-01 or other pin restricted modules +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods // NOTE: These will ignore the PIN and use GPI02 pin -//NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); // The bitbang method is really only good if you are not using WiFi features of the ESP // It works with all but pin 16 diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino similarity index 98% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino index 66b4d4aca4dd..4f0386abe418 100644 --- a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino @@ -29,10 +29,7 @@ NeoPixelBus strip(PixelCount, PixelPin); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. // There are other Esp8266 alternative methods that provide more pin options, but also have // other side effects. -//NeoPixelBus strip(PixelCount); -// -// NeoEsp8266Uart800KbpsMethod uses GPI02 instead - +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods // NeoPixel animation time management object NeoPixelAnimator animations(PixelCount, NEO_CENTISECONDS); diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelCylon/NeoPixelCylon.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelCylon/NeoPixelCylon.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelCylon/NeoPixelCylon.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelCylon/NeoPixelCylon.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino similarity index 92% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino index 45e66ec3898a..f6c065c2cf67 100644 --- a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino @@ -16,13 +16,11 @@ NeoPixelBus strip(PixelCount, PixelPin); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. // There are other Esp8266 alternative methods that provide more pin options, but also have // other side effects. -//NeoPixelBus strip(PixelCount); -// -// NeoEsp8266Uart800KbpsMethod uses GPI02 instead +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods NeoPixelAnimator animations(AnimationChannels); // NeoPixel animation management object -uint16_t effectState = 0; // general purpose variable used to store effect state +boolean fadeToColor = true; // general purpose variable used to store effect state // what is stored for state is specific to the need, in this case, the colors. @@ -75,7 +73,7 @@ void BlendAnimUpdate(const AnimationParam& param) void FadeInFadeOutRinseRepeat(float luminance) { - if (effectState == 0) + if (fadeToColor) { // Fade upto a random color // we use HslColor object as it allows us to easily pick a hue @@ -89,7 +87,7 @@ void FadeInFadeOutRinseRepeat(float luminance) animations.StartAnimation(0, time, BlendAnimUpdate); } - else if (effectState == 1) + else { // fade to black uint16_t time = random(600, 700); @@ -101,7 +99,7 @@ void FadeInFadeOutRinseRepeat(float luminance) } // toggle to the next effect state - effectState = (effectState + 1) % 2; + fadeToColor = !fadeToColor; } void setup() diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino similarity index 97% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino index 3dea4c0e6ee8..c8a7788ded6a 100644 --- a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino @@ -29,9 +29,7 @@ NeoPixelBus strip(PixelCount, PixelPin); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. // There are other Esp8266 alternative methods that provide more pin options, but also have // other side effects. -//NeoPixelBus strip(PixelCount); -// -// NeoEsp8266Uart800KbpsMethod uses GPI02 instead +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods // what is stored for state is specific to the need, in this case, the colors and // the pixel to animate; diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino similarity index 96% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino index 17d6b6a482f1..8e8866775867 100644 --- a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino @@ -14,9 +14,7 @@ NeoPixelBus strip(PixelCount, PixelPin); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. // There are other Esp8266 alternative methods that provide more pin options, but also have // other side effects. -//NeoPixelBus strip(PixelCount); -// -// NeoEsp8266Uart800KbpsMethod uses GPI02 instead +// for details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods NeoPixelAnimator animations(PixelCount); // NeoPixel animation management object diff --git a/lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino b/lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino rename to lib/NeoPixelBus-2.5.0.09/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/Strings.bmp b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/Strings.bmp similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/Strings.bmp rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/Strings.bmp diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/StringsW.bmp b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/StringsW.bmp similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBitmap/StringsW.bmp rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBitmap/StringsW.bmp diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/Cylon.pdn b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/Cylon.pdn similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/Cylon.pdn rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/Cylon.pdn diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/CylonGrb.h b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/CylonGrb.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/CylonGrb.h rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/CylonGrb.h diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/CylonGrbw.h b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/CylonGrbw.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/CylonGrbw.h rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/CylonGrbw.h diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino similarity index 98% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino index 37a109f46cbe..c2c8e74b24aa 100644 --- a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino @@ -36,12 +36,12 @@ const RgbColor White(255); const RgbColor Black(0); // define a custom shader object that provides brightness support -// based upon the NeoBitsBase -template class BrightnessShader : public NeoBitsBase +// based upon the NeoShaderBase +template class BrightnessShader : public NeoShaderBase { public: BrightnessShader(): - NeoBitsBase(), + NeoShaderBase(), _brightness(255) // default to full bright {} diff --git a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino similarity index 97% rename from lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino index c421b5b1bd8d..1a13c135c1b5 100644 --- a/lib/NeoPixelBus-2.2.9/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino +++ b/lib/NeoPixelBus-2.5.0.09/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino @@ -34,12 +34,12 @@ const RgbColor White(255); const RgbColor Black(0); // define a custom shader object that provides brightness support -// based upon the NeoBitsBase -class BrightnessShader : public NeoBitsBase +// based upon the NeoShaderBase +class BrightnessShader : public NeoShaderBase { public: BrightnessShader(): - NeoBitsBase(), + NeoShaderBase(), _brightness(255) // default to full bright {} diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino diff --git a/lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino b/lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino similarity index 100% rename from lib/NeoPixelBus-2.2.9/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino rename to lib/NeoPixelBus-2.5.0.09/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/circular.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/circular.png new file mode 100644 index 000000000000..e4204dbbdf02 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/circular.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/cubic.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/cubic.png new file mode 100644 index 000000000000..a2d7c1468271 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/cubic.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/different.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/different.png new file mode 100644 index 000000000000..ae85ce2fe9e1 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/different.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/exponential.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/exponential.png new file mode 100644 index 000000000000..25031713c74a Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/exponential.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/gamma.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/gamma.png new file mode 100644 index 000000000000..33a84d6140d9 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/gamma.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/pronounced.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/pronounced.png new file mode 100644 index 000000000000..0b7833073710 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/pronounced.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/quadratic.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/quadratic.png new file mode 100644 index 000000000000..33ab17c1e868 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/quadratic.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/quintic.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/quintic.png new file mode 100644 index 000000000000..30dab932aa88 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/quintic.png differ diff --git a/lib/NeoPixelBus-2.5.0.09/extras/curves/sinusoidal.png b/lib/NeoPixelBus-2.5.0.09/extras/curves/sinusoidal.png new file mode 100644 index 000000000000..0b7533822e22 Binary files /dev/null and b/lib/NeoPixelBus-2.5.0.09/extras/curves/sinusoidal.png differ diff --git a/lib/NeoPixelBus-2.2.9/keywords.txt b/lib/NeoPixelBus-2.5.0.09/keywords.txt similarity index 54% rename from lib/NeoPixelBus-2.2.9/keywords.txt rename to lib/NeoPixelBus-2.5.0.09/keywords.txt index 75771ef9712c..4734aca32f0d 100644 --- a/lib/NeoPixelBus-2.2.9/keywords.txt +++ b/lib/NeoPixelBus-2.5.0.09/keywords.txt @@ -20,25 +20,105 @@ NeoBrgFeature KEYWORD1 NeoRbgFeature KEYWORD1 DotStarBgrFeature KEYWORD1 DotStarLbgrFeature KEYWORD1 -NeoWs2813Method KEYWORD1 Neo800KbpsMethod KEYWORD1 Neo400KbpsMethod KEYWORD1 -NeoAvrWs2813Method KEYWORD1 -NeoAvr800KbpsMethod KEYWORD1 -NeoAvr400KbpsMethod KEYWORD1 -NeoEsp8266DmaWs2813Method KEYWORD1 +NeoWs2813Method KEYWORD1 +NeoWs2812xMethod KEYWORD1 +NeoWs2812Method KEYWORD1 +NeoSk6812Method KEYWORD1 +NeoLc8812Method KEYWORD1 +NeoApa106Method KEYWORD1 +NeoEsp8266DmaWs2812xMethod KEYWORD1 +NeoEsp8266DmaSk6812Method KEYWORD1 +NeoEsp8266DmaApa106Method KEYWORD1 NeoEsp8266Dma800KbpsMethod KEYWORD1 NeoEsp8266Dma400KbpsMethod KEYWORD1 -NeoEsp8266UartWs2813Method KEYWORD1 -NeoEsp8266Uart800KbpsMethod KEYWORD1 -NeoEsp8266Uart400KbpsMethod KEYWORD1 -NeoEsp8266AsyncUartWs2813Method KEYWORD1 -NeoEsp8266AsyncUart800KbpsMethod KEYWORD1 -NeoEsp8266AsyncUart400KbpsMethod KEYWORD1 +NeoEsp8266Uart0Ws2813Method KEYWORD1 +NeoEsp8266Uart0Ws2812xMethod KEYWORD1 +NeoEsp8266Uart0Ws2812Method KEYWORD1 +NeoEsp8266Uart0Sk6812Method KEYWORD1 +NeoEsp8266Uart0Lc8812Method KEYWORD1 +NeoEsp8266Uart0Apa106Method KEYWORD1 +NeoEsp8266Uart0800KbpsMethod KEYWORD1 +NeoEsp8266Uart0400KbpsMethod KEYWORD1 +NeoEsp8266AsyncUart0Ws2813Method KEYWORD1 +NeoEsp8266AsyncUart0Ws2812xMethod KEYWORD1 +NeoEsp8266AsyncUart0Ws2812Method KEYWORD1 +NeoEsp8266AsyncUart0Sk6812Method KEYWORD1 +NeoEsp8266AsyncUart0Lc8812Method KEYWORD1 +NeoEsp8266AsyncUart0Apa106Method KEYWORD1 +NeoEsp8266AsyncUart0800KbpsMethod KEYWORD1 +NeoEsp8266AsyncUart0400KbpsMethod KEYWORD1 +NeoEsp8266Uart1Ws2813Method KEYWORD1 +NeoEsp8266Uart1Ws2812xMethod KEYWORD1 +NeoEsp8266Uart1Ws2812Method KEYWORD1 +NeoEsp8266Uart1Sk6812Method KEYWORD1 +NeoEsp8266Uart1Lc8812Method KEYWORD1 +NeoEsp8266Uart1Apa106Method KEYWORD1 +NeoEsp8266Uart1800KbpsMethod KEYWORD1 +NeoEsp8266Uart1400KbpsMethod KEYWORD1 +NeoEsp8266AsyncUart1Ws2813Method KEYWORD1 +NeoEsp8266AsyncUart1Ws2812xMethod KEYWORD1 +NeoEsp8266AsyncUart1Ws2812Method KEYWORD1 +NeoEsp8266AsyncUart1Sk6812Method KEYWORD1 +NeoEsp8266AsyncUart1Lc8812Method KEYWORD1 +NeoEsp8266AsyncUart1Apa106Method KEYWORD1 +NeoEsp8266AsyncUart1800KbpsMethod KEYWORD1 +NeoEsp8266AsyncUart1400KbpsMethod KEYWORD1 NeoEsp8266BitBangWs2813Method KEYWORD1 +NeoEsp8266BitBangWs2812xMethod KEYWORD1 +NeoEsp8266BitBangWs2812Method KEYWORD1 +NeoEsp8266BitBangSk6812Method KEYWORD1 +NeoEsp8266BitBangLc8812Method KEYWORD1 +NeoEsp8266BitBangApa106Method KEYWORD1 NeoEsp8266BitBang800KbpsMethod KEYWORD1 NeoEsp8266BitBang400KbpsMethod KEYWORD1 +NeoEsp32Rmt0Ws2812xMethod KEYWORD1 +NeoEsp32Rmt0Sk6812Method KEYWORD1 +NeoEsp32Rmt0Apa106Method KEYWORD1 +NeoEsp32Rmt0800KbpsMethod KEYWORD1 +NeoEsp32Rmt0400KbpsMethod KEYWORD1 +NeoEsp32Rmt1Ws2812xMethod KEYWORD1 +NeoEsp32Rmt1Sk6812Method KEYWORD1 +NeoEsp32Rmt1Apa106Method KEYWORD1 +NeoEsp32Rmt1800KbpsMethod KEYWORD1 +NeoEsp32Rmt1400KbpsMethod KEYWORD1 +NeoEsp32Rmt2Ws2812xMethod KEYWORD1 +NeoEsp32Rmt2Sk6812Method KEYWORD1 +NeoEsp32Rmt2Apa106Method KEYWORD1 +NeoEsp32Rmt2800KbpsMethod KEYWORD1 +NeoEsp32Rmt2400KbpsMethod KEYWORD1 +NeoEsp32Rmt3Ws2812xMethod KEYWORD1 +NeoEsp32Rmt3Sk6812Method KEYWORD1 +NeoEsp32Rmt3Apa106Method KEYWORD1 +NeoEsp32Rmt3800KbpsMethod KEYWORD1 +NeoEsp32Rmt3400KbpsMethod KEYWORD1 +NeoEsp32Rmt4Ws2812xMethod KEYWORD1 +NeoEsp32Rmt4Sk6812Method KEYWORD1 +NeoEsp32Rmt4Apa106Method KEYWORD1 +NeoEsp32Rmt4800KbpsMethod KEYWORD1 +NeoEsp32Rmt4400KbpsMethod KEYWORD1 +NeoEsp32Rmt5Ws2812xMethod KEYWORD1 +NeoEsp32Rmt5Sk6812Method KEYWORD1 +NeoEsp32Rmt5Apa106Method KEYWORD1 +NeoEsp32Rmt5800KbpsMethod KEYWORD1 +NeoEsp32Rmt5400KbpsMethod KEYWORD1 +NeoEsp32Rmt6Ws2812xMethod KEYWORD1 +NeoEsp32Rmt6Sk6812Method KEYWORD1 +NeoEsp32Rmt6Apa106Method KEYWORD1 +NeoEsp32Rmt6800KbpsMethod KEYWORD1 +NeoEsp32Rmt6400KbpsMethod KEYWORD1 +NeoEsp32Rmt7Ws2812xMethod KEYWORD1 +NeoEsp32Rmt7Sk6812Method KEYWORD1 +NeoEsp32Rmt7Apa106Method KEYWORD1 +NeoEsp32Rmt7800KbpsMethod KEYWORD1 +NeoEsp32Rmt7400KbpsMethod KEYWORD1 NeoEsp32BitBangWs2813Method KEYWORD1 +NeoEsp32BitBangWs2812xMethod KEYWORD1 +NeoEsp32BitBangWs2812Method KEYWORD1 +NeoEsp32BitBangSk6812Method KEYWORD1 +NeoEsp32BitBangLc8812Method KEYWORD1 +NeoEsp32BitBangApa106Method KEYWORD1 NeoEsp32BitBang800KbpsMethod KEYWORD1 NeoEsp32BitBang400KbpsMethod KEYWORD1 DotStarMethod KEYWORD1 @@ -105,6 +185,7 @@ PixelsSize KEYWORD2 PixelCount KEYWORD2 SetPixelColor KEYWORD2 GetPixelColor KEYWORD2 +SwapPixelColor KEYWORD2 CalculateBrightness KEYWORD2 Darken KEYWORD2 Lighten KEYWORD2 @@ -117,6 +198,7 @@ StopAnimation KEYWORD2 RestartAnimation KEYWORD2 IsAnimationActive KEYWORD2 AnimationDuration KEYWORD2 +ChangeAnimationDuration KEYWORD2 UpdateAnimations KEYWORD2 IsPaused KEYWORD2 Pause KEYWORD2 @@ -126,29 +208,38 @@ setTimeScale KEYWORD2 QuadraticIn KEYWORD2 QuadraticOut KEYWORD2 QuadraticInOut KEYWORD2 +QuadraticCenter KEYWORD2 CubicIn KEYWORD2 CubicOut KEYWORD2 CubicInOut KEYWORD2 +CubicCenter KEYWORD2 QuarticIn KEYWORD2 QuarticOut KEYWORD2 QuarticInOut KEYWORD2 +QuarticCenter KEYWORD2 QuinticIn KEYWORD2 QuinticOut KEYWORD2 QuinticInOut KEYWORD2 +QuinticCenter KEYWORD2 SinusoidalIn KEYWORD2 SinusoidalOut KEYWORD2 SinusoidalInOut KEYWORD2 +SinusoidalCenter KEYWORD2 ExponentialIn KEYWORD2 ExponentialOut KEYWORD2 ExponentialInOut KEYWORD2 +ExponentialCenter KEYWORD2 CircularIn KEYWORD2 CircularOut KEYWORD2 CircularInOut KEYWORD2 +CircularCenter KEYWORD2 Gamma KEYWORD2 Map KEYWORD2 MapProbe KEYWORD2 getWidth KEYWORD2 getHeight KEYWORD2 +RingPixelShift KEYWORD2 +RingPixelRotate KEYWORD2 getCountOfRings KEYWORD2 getPixelCountAtRing KEYWORD2 getPixelCount KEYWORD2 diff --git a/lib/NeoPixelBus-2.5.0.09/library.json b/lib/NeoPixelBus-2.5.0.09/library.json new file mode 100644 index 000000000000..76cb53848202 --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/library.json @@ -0,0 +1,14 @@ +{ + "name": "NeoPixelBus", + "keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, RGB, RGBW", + "description": "A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. Supports most Arduino platforms. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.", + "homepage": "https://github.com/Makuna/NeoPixelBus/wiki", + "repository": { + "type": "git", + "url": "https://github.com/Makuna/NeoPixelBus" + }, + "version": "2.5.0", + "frameworks": "arduino", + "platforms": "*" +} + diff --git a/lib/NeoPixelBus-2.2.9/library.properties b/lib/NeoPixelBus-2.5.0.09/library.properties similarity index 77% rename from lib/NeoPixelBus-2.2.9/library.properties rename to lib/NeoPixelBus-2.5.0.09/library.properties index 029a6db395b1..5cac2ca18de4 100644 --- a/lib/NeoPixelBus-2.2.9/library.properties +++ b/lib/NeoPixelBus-2.5.0.09/library.properties @@ -1,9 +1,9 @@ name=NeoPixelBus by Makuna -version=2.2.9 +version=2.5.0 author=Michael C. Miller (makuna@live.com) maintainer=Michael C. Miller (makuna@live.com) sentence=A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. -paragraph=Supports most Arduino platforms, including Esp8266 and Esp32. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI. +paragraph=Supports most Arduino platforms, including Esp8266 and Esp32. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI. category=Display url=https://github.com/Makuna/NeoPixelBus/wiki architectures=* \ No newline at end of file diff --git a/lib/NeoPixelBus-2.2.9/src/NeoPixelAnimator.h b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelAnimator.h similarity index 95% rename from lib/NeoPixelBus-2.2.9/src/NeoPixelAnimator.h rename to lib/NeoPixelBus-2.5.0.09/src/NeoPixelAnimator.h index 21eb2ad8bfcf..c49d9ec48547 100644 --- a/lib/NeoPixelBus-2.2.9/src/NeoPixelAnimator.h +++ b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelAnimator.h @@ -109,6 +109,8 @@ class NeoPixelAnimator return _animations[indexAnimation]._duration; } + void ChangeAnimationDuration(uint16_t indexAnimation, uint16_t newDuration); + void UpdateAnimations(); bool IsPaused() @@ -159,6 +161,11 @@ class NeoPixelAnimator _remaining = 0; } + float CurrentProgress() + { + return (float)(_duration - _remaining) / (float)_duration; + } + uint16_t _duration; uint16_t _remaining; diff --git a/lib/NeoPixelBus-2.2.9/src/NeoPixelBrightnessBus.h b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelBrightnessBus.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/NeoPixelBrightnessBus.h rename to lib/NeoPixelBus-2.5.0.09/src/NeoPixelBrightnessBus.h diff --git a/lib/NeoPixelBus-2.2.9/src/NeoPixelBus.h b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelBus.h similarity index 94% rename from lib/NeoPixelBus-2.2.9/src/NeoPixelBus.h rename to lib/NeoPixelBus-2.5.0.09/src/NeoPixelBus.h index f6a6b7babc76..3c08f83f61cf 100644 --- a/lib/NeoPixelBus-2.2.9/src/NeoPixelBus.h +++ b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelBus.h @@ -57,8 +57,9 @@ License along with NeoPixel. If not, see #include "internal/NeoBufferMethods.h" #include "internal/NeoBuffer.h" #include "internal/NeoSpriteSheet.h" -#include "internal/NeoBitmapFile.h" #include "internal/NeoDib.h" +#include "internal/NeoBitmapFile.h" + #include "internal/NeoEase.h" #include "internal/NeoGamma.h" @@ -71,6 +72,8 @@ License along with NeoPixel. If not, see #elif defined(ARDUINO_ARCH_ESP32) +#include "internal/NeoEsp32I2sMethod.h" +#include "internal/NeoEsp32RmtMethod.h" #include "internal/NeoEspBitBangMethod.h" #include "internal/DotStarGenericMethod.h" @@ -136,14 +139,21 @@ template class NeoPixelBus Dirty(); } - void Show() + // used by DotStartSpiMethod if pins can be configured + void Begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) + { + _method.Initialize(sck, miso, mosi, ss); + Dirty(); + } + + void Show(bool maintainBufferConsistency = true) { if (!IsDirty()) { return; } - _method.Update(); + _method.Update(maintainBufferConsistency); ResetDirty(); } @@ -321,7 +331,14 @@ template class NeoPixelBus } } + void SwapPixelColor(uint16_t indexPixelOne, uint16_t indexPixelTwo) + { + auto colorOne = GetPixelColor(indexPixelOne); + auto colorTwo = GetPixelColor(indexPixelTwo); + SetPixelColor(indexPixelOne, colorTwo); + SetPixelColor(indexPixelTwo, colorOne); + }; protected: const uint16_t _countPixels; // Number of RGB LEDs in strip diff --git a/lib/NeoPixelBus-2.2.9/src/internal/DotStarAvrMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarAvrMethod.h similarity index 99% rename from lib/NeoPixelBus-2.2.9/src/internal/DotStarAvrMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/DotStarAvrMethod.h index 66bd00b0b488..a627d0a6832c 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/DotStarAvrMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarAvrMethod.h @@ -68,7 +68,7 @@ class DotStarAvrMethod digitalWrite(_pinData, LOW); } - void Update() + void Update(bool) { // start frame for (int startFrameByte = 0; startFrameByte < 4; startFrameByte++) diff --git a/lib/NeoPixelBus-2.2.9/src/internal/DotStarColorFeatures.h b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarColorFeatures.h similarity index 52% rename from lib/NeoPixelBus-2.2.9/src/internal/DotStarColorFeatures.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/DotStarColorFeatures.h index 3719d6fc11ed..50a33e248f14 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/DotStarColorFeatures.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarColorFeatures.h @@ -324,3 +324,332 @@ class DotStarLgrbFeature : public DotStar4Elements }; +/* RGB Feature -- Some APA102s ship in RGB order */ +class DotStarRgbFeature : public DotStar3Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xff; // upper three bits are always 111 and brightness at max + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.R = *p++; + color.G = *p++; + color.B = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + pgm_read_byte(p++); // ignore the first byte + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLrgbFeature : public DotStar4Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111 + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.R = *p++; + color.G = *p++; + color.B = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; +/* RBG Feature -- Some APA102s ship in RBG order */ +class DotStarRbgFeature : public DotStar3Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xff; // upper three bits are always 111 and brightness at max + *p++ = color.R; + *p++ = color.B; + *p = color.G; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.R = *p++; + color.B = *p++; + color.G = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + pgm_read_byte(p++); // ignore the first byte + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLrbgFeature : public DotStar4Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111 + *p++ = color.R; + *p++ = color.B; + *p = color.G; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.R = *p++; + color.B = *p++; + color.G = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; + +/* GBR Feature -- Some APA102s ship in GBR order */ +class DotStarGbrFeature : public DotStar3Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xff; // upper three bits are always 111 and brightness at max + *p++ = color.G; + *p++ = color.B; + *p = color.R; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.G = *p++; + color.B = *p++; + color.R = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + pgm_read_byte(p++); // ignore the first byte + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLgbrFeature : public DotStar4Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111 + *p++ = color.G; + *p++ = color.B; + *p = color.R; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.G = *p++; + color.B = *p++; + color.R = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; +/* BRG Feature -- Some APA102s ship in BRG order */ +class DotStarBrgFeature : public DotStar3Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xff; // upper three bits are always 111 and brightness at max + *p++ = color.B; + *p++ = color.R; + *p = color.G; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.B = *p++; + color.R = *p++; + color.G = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + pgm_read_byte(p++); // ignore the first byte + color.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLbrgFeature : public DotStar4Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xE0 | (color.W < 31 ? color.W : 31); // upper three bits are always 111 + *p++ = color.B; + *p++ = color.R; + *p = color.G; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.B = *p++; + color.R = *p++; + color.G = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.W = pgm_read_byte(p++) & 0x1F; // mask out upper three bits + color.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; diff --git a/lib/NeoPixelBus-2.2.9/src/internal/DotStarGenericMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarGenericMethod.h similarity index 99% rename from lib/NeoPixelBus-2.2.9/src/internal/DotStarGenericMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/DotStarGenericMethod.h index d59d0e0dd964..8b3fe3350472 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/DotStarGenericMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarGenericMethod.h @@ -60,7 +60,7 @@ class DotStarGenericMethod digitalWrite(_pinData, LOW); } - void Update() + void Update(bool) { // start frame for (int startFrameByte = 0; startFrameByte < 4; startFrameByte++) diff --git a/lib/NeoPixelBus-2.2.9/src/internal/DotStarSpiMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarSpiMethod.h similarity index 81% rename from lib/NeoPixelBus-2.2.9/src/internal/DotStarSpiMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/DotStarSpiMethod.h index 4aabc29c29b2..7c51816a11c1 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/DotStarSpiMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/DotStarSpiMethod.h @@ -51,29 +51,37 @@ class DotStarSpiMethod return true; // dot stars don't have a required delay } +#if defined(ARDUINO_ARCH_ESP32) + void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) + { + SPI.begin(sck, miso, mosi, ss); + } +#endif + void Initialize() { SPI.begin(); - -#if defined(ARDUINO_ARCH_ESP8266) - SPI.setFrequency(20000000L); -#elif defined(ARDUINO_ARCH_AVR) - SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (6 MHz on Pro Trinket 3V) -#else - SPI.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due -#endif - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); } - void Update() + void Update(bool) { - // due to API inconsistencies need to call different methods on SPI + SPI.beginTransaction(SPISettings(20000000L, MSBFIRST, SPI_MODE0)); #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + // ESPs have a method to write without inplace overwriting the send buffer + // since we don't care what gets received, use it for performance SPI.writeBytes(_sendBuffer, _sizeSendBuffer); + #else - SPI.transfer(_sendBuffer, _sizeSendBuffer); + // default ARDUINO transfer inplace overwrites the send buffer + // which is bad, so we have to send one byte at a time + uint8_t* out = _sendBuffer; + uint8_t* end = out + _sizeSendBuffer; + while (out < end) + { + SPI.transfer(*out++); + } #endif + SPI.endTransaction(); } uint8_t* getPixels() const diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.c b/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.c new file mode 100644 index 000000000000..092170e20a6a --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.c @@ -0,0 +1,484 @@ +// WARNING: This file contains code that is more than likely already +// exposed from the Esp32 Arduino API. It will be removed once integration is complete. +// +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if defined(ARDUINO_ARCH_ESP32) + +#include +#include +#include "stdlib.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" + +#include "esp_intr.h" +#include "rom/ets_sys.h" +#include "soc/gpio_reg.h" +#include "soc/gpio_sig_map.h" +#include "soc/io_mux_reg.h" +#include "soc/rtc_cntl_reg.h" +#include "soc/i2s_struct.h" +#include "soc/dport_reg.h" +#include "soc/sens_reg.h" +#include "driver/gpio.h" +#include "driver/i2s.h" +#include "driver/dac.h" +#include "Esp32_i2s.h" +#include "esp32-hal.h" + +#define I2S_BASE_CLK (160000000L) +#define ESP32_REG(addr) (*((volatile uint32_t*)(0x3FF00000+(addr)))) + +#define I2S_DMA_QUEUE_SIZE 16 + +#define I2S_DMA_SILENCE_LEN 256 // bytes + +typedef struct i2s_dma_item_s { + uint32_t blocksize: 12; // datalen + uint32_t datalen : 12; // len*(bits_per_sample/8)*2 => max 2047*8bit/1023*16bit samples + uint32_t unused : 5; // 0 + uint32_t sub_sof : 1; // 0 + uint32_t eof : 1; // 1 => last? + uint32_t owner : 1; // 1 + + void* data; // malloc(datalen) + struct i2s_dma_item_s* next; + + // if this pointer is not null, it will be freed + void* free_ptr; + + // if DMA buffers are preallocated + uint8_t* buf; +} i2s_dma_item_t; + +typedef struct { + i2s_dev_t* bus; + int8_t ws; + int8_t bck; + int8_t out; + int8_t in; + uint32_t rate; + intr_handle_t isr_handle; + xQueueHandle tx_queue; + + uint8_t* silence_buf; + size_t silence_len; + + i2s_dma_item_t* dma_items; + size_t dma_count; + uint32_t dma_buf_len :12; + uint32_t unused :20; +} i2s_bus_t; + +static uint8_t i2s_silence_buf[I2S_DMA_SILENCE_LEN]; + +static i2s_bus_t I2S[2] = { + {&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_LEN, NULL, I2S_DMA_QUEUE_SIZE, 0, 0}, + {&I2S1, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_LEN, NULL, I2S_DMA_QUEUE_SIZE, 0, 0} +}; + +void IRAM_ATTR i2sDmaISR(void* arg); +bool i2sInitDmaItems(uint8_t bus_num); + +bool i2sInitDmaItems(uint8_t bus_num) { + if (bus_num > 1) { + return false; + } + if (I2S[bus_num].tx_queue) {// already set + return true; + } + + if (I2S[bus_num].dma_items == NULL) { + I2S[bus_num].dma_items = (i2s_dma_item_t*)(malloc(I2S[bus_num].dma_count* sizeof(i2s_dma_item_t))); + if (I2S[bus_num].dma_items == NULL) { + log_e("MEM ERROR!"); + return false; + } + } + + int i, i2, a; + i2s_dma_item_t* item; + + for(i=0; ieof = 1; + item->owner = 1; + item->sub_sof = 0; + item->unused = 0; + item->data = I2S[bus_num].silence_buf; + item->blocksize = I2S[bus_num].silence_len; + item->datalen = I2S[bus_num].silence_len; + item->next = &I2S[bus_num].dma_items[i2]; + item->free_ptr = NULL; + if (I2S[bus_num].dma_buf_len) { + item->buf = (uint8_t*)(malloc(I2S[bus_num].dma_buf_len)); + if (item->buf == NULL) { + log_e("MEM ERROR!"); + for(a=0; abuf = NULL; + } + } + + I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count, sizeof(i2s_dma_item_t*)); + if (I2S[bus_num].tx_queue == NULL) {// memory error + log_e("MEM ERROR!"); + free(I2S[bus_num].dma_items); + I2S[bus_num].dma_items = NULL; + return false; + } + return true; +} + +void i2sSetSilenceBuf(uint8_t bus_num, uint8_t* data, size_t len) { + if (bus_num > 1 || !data || !len) { + return; + } + I2S[bus_num].silence_buf = data; + I2S[bus_num].silence_len = len; +} + +esp_err_t i2sSetClock(uint8_t bus_num, uint8_t div_num, uint8_t div_b, uint8_t div_a, uint8_t bck, uint8_t bits) { + if (bus_num > 1 || div_a > 63 || div_b > 63 || bck > 63) { + return ESP_FAIL; + } + i2s_dev_t* i2s = I2S[bus_num].bus; + i2s->clkm_conf.clka_en = 0; + i2s->clkm_conf.clkm_div_a = div_a; + i2s->clkm_conf.clkm_div_b = div_b; + i2s->clkm_conf.clkm_div_num = div_num; + i2s->sample_rate_conf.tx_bck_div_num = bck; + i2s->sample_rate_conf.rx_bck_div_num = bck; + i2s->sample_rate_conf.tx_bits_mod = bits; + i2s->sample_rate_conf.rx_bits_mod = bits; + return ESP_OK; +} + +void i2sSetTxDataMode(uint8_t bus_num, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod) { + if (bus_num > 1) { + return; + } + + I2S[bus_num].bus->conf_chan.tx_chan_mod = chan_mod; // 0:dual channel; 1:right channel; 2:left channel; 3:left channel constant; 4:right channel constant; (channels flipped if tx_msb_right == 1) + I2S[bus_num].bus->fifo_conf.tx_fifo_mod = fifo_mod; // 0:16-bit dual channel; 1:16-bit single channel; 2:32-bit dual channel; 3:32-bit single channel data +} + +void i2sSetDac(uint8_t bus_num, bool right, bool left) { + if (bus_num > 1) { + return; + } + + if (!right && !left) { + dac_output_disable(1); + dac_output_disable(2); + dac_i2s_disable(); + I2S[bus_num].bus->conf2.lcd_en = 0; + I2S[bus_num].bus->conf.tx_right_first = 0; + I2S[bus_num].bus->conf2.camera_en = 0; + I2S[bus_num].bus->conf.tx_msb_shift = 1;// I2S signaling + return; + } + + i2sSetPins(bus_num, -1, -1, -1, -1); + I2S[bus_num].bus->conf2.lcd_en = 1; + I2S[bus_num].bus->conf.tx_right_first = 0; + I2S[bus_num].bus->conf2.camera_en = 0; + I2S[bus_num].bus->conf.tx_msb_shift = 0; + dac_i2s_enable(); + + if (right) {// DAC1, right channel, GPIO25 + dac_output_enable(1); + } + if (left) { // DAC2, left channel, GPIO26 + dac_output_enable(2); + } +} + +void i2sSetPins(uint8_t bus_num, int8_t out, int8_t ws, int8_t bck, int8_t in) { + if (bus_num > 1) { + return; + } + + if ((ws >= 0 && I2S[bus_num].ws == -1) || (bck >= 0 && I2S[bus_num].bck == -1) || (out >= 0 && I2S[bus_num].out == -1)) { + i2sSetDac(bus_num, false, false); + } + + if (ws >= 0) { + if (I2S[bus_num].ws != ws) { + if (I2S[bus_num].ws >= 0) { + gpio_matrix_out(I2S[bus_num].ws, 0x100, false, false); + } + I2S[bus_num].ws = ws; + pinMode(ws, OUTPUT); + gpio_matrix_out(ws, bus_num?I2S1O_WS_OUT_IDX:I2S0O_WS_OUT_IDX, false, false); + } + } else if (I2S[bus_num].ws >= 0) { + gpio_matrix_out(I2S[bus_num].ws, 0x100, false, false); + I2S[bus_num].ws = -1; + } + + if (bck >= 0) { + if (I2S[bus_num].bck != bck) { + if (I2S[bus_num].bck >= 0) { + gpio_matrix_out(I2S[bus_num].bck, 0x100, false, false); + } + I2S[bus_num].bck = bck; + pinMode(bck, OUTPUT); + gpio_matrix_out(bck, bus_num?I2S1O_BCK_OUT_IDX:I2S0O_BCK_OUT_IDX, false, false); + } + } else if (I2S[bus_num].bck >= 0) { + gpio_matrix_out(I2S[bus_num].bck, 0x100, false, false); + I2S[bus_num].bck = -1; + } + + if (out >= 0) { + if (I2S[bus_num].out != out) { + if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, false, false); + } + I2S[bus_num].out = out; + pinMode(out, OUTPUT); + gpio_matrix_out(out, bus_num?I2S1O_DATA_OUT23_IDX:I2S0O_DATA_OUT23_IDX, false, false); + } + } else if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, false, false); + I2S[bus_num].out = -1; + } + +} + +bool i2sWriteDone(uint8_t bus_num) { + if (bus_num > 1) { + return false; + } + return (I2S[bus_num].dma_items[I2S[bus_num].dma_count - 1].data == I2S[bus_num].silence_buf); +} + +void i2sInit(uint8_t bus_num, uint32_t bits_per_sample, uint32_t sample_rate, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod, size_t dma_count, size_t dma_len) { + if (bus_num > 1) { + return; + } + + I2S[bus_num].dma_count = dma_count; + I2S[bus_num].dma_buf_len = dma_len & 0xFFF; + + if (!i2sInitDmaItems(bus_num)) { + return; + } + + if (bus_num) { + periph_module_enable(PERIPH_I2S1_MODULE); + } else { + periph_module_enable(PERIPH_I2S0_MODULE); + } + + esp_intr_disable(I2S[bus_num].isr_handle); + i2s_dev_t* i2s = I2S[bus_num].bus; + i2s->out_link.stop = 1; + i2s->conf.tx_start = 0; + i2s->int_ena.val = 0; + i2s->int_clr.val = 0xFFFFFFFF; + i2s->fifo_conf.dscr_en = 0; + + // reset fifo + i2s->conf.rx_fifo_reset = 1; + i2s->conf.rx_fifo_reset = 0; + i2s->conf.tx_fifo_reset = 1; + i2s->conf.tx_fifo_reset = 0; + + // reset i2s + i2s->conf.tx_reset = 1; + i2s->conf.tx_reset = 0; + i2s->conf.rx_reset = 1; + i2s->conf.rx_reset = 0; + + // reset dma + i2s->lc_conf.in_rst = 1; + i2s->lc_conf.in_rst = 0; + i2s->lc_conf.out_rst = 1; + i2s->lc_conf.out_rst = 0; + + // Enable and configure DMA + i2s->lc_conf.check_owner = 0; + i2s->lc_conf.out_loop_test = 0; + i2s->lc_conf.out_auto_wrback = 0; + i2s->lc_conf.out_data_burst_en = 0; + i2s->lc_conf.outdscr_burst_en = 0; + i2s->lc_conf.out_no_restart_clr = 0; + i2s->lc_conf.indscr_burst_en = 0; + i2s->lc_conf.out_eof_mode = 1; + + i2s->pdm_conf.pcm2pdm_conv_en = 0; + i2s->pdm_conf.pdm2pcm_conv_en = 0; + // SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S); + + + i2s->conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + i2s->conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + i2s->fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + i2s->fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + + i2s->conf.tx_mono = 0; + i2s->conf.rx_mono = 0; + + i2s->conf.tx_start = 0; + i2s->conf.rx_start = 0; + + i2s->conf.tx_short_sync = 0; + i2s->conf.rx_short_sync = 0; + i2s->conf.tx_msb_shift = (bits_per_sample != 8);// 0:DAC/PCM, 1:I2S + i2s->conf.rx_msb_shift = 0; + + i2s->conf.tx_slave_mod = 0; // Master + + i2s->conf.tx_msb_right = 0; + i2s->conf.tx_right_first = (bits_per_sample == 8); + i2s->conf2.lcd_en = (bits_per_sample == 8); + i2s->conf2.camera_en = 0; + + i2s->fifo_conf.tx_fifo_mod_force_en = 1; + + i2s->pdm_conf.rx_pdm_en = 0; + i2s->pdm_conf.tx_pdm_en = 0; + + i2sSetSampleRate(bus_num, sample_rate, bits_per_sample); + + // enable intr in cpu // + esp_intr_alloc(bus_num?ETS_I2S1_INTR_SOURCE:ETS_I2S0_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1, &i2sDmaISR, &I2S[bus_num], &I2S[bus_num].isr_handle); + // enable send intr + i2s->int_ena.out_eof = 1; + i2s->int_ena.out_dscr_err = 1; + + i2s->fifo_conf.dscr_en = 1;// enable dma + i2s->out_link.start = 0; + i2s->out_link.addr = (uint32_t)(&I2S[bus_num].dma_items[0]); // loads dma_struct to dma + i2s->out_link.start = 1; // starts dma + i2s->conf.tx_start = 1;// Start I2s module + + esp_intr_enable(I2S[bus_num].isr_handle); +} + +esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t rate, uint8_t bits) { + if (bus_num > 1) { + return ESP_FAIL; + } + + if (I2S[bus_num].rate == rate) { + return ESP_OK; + } + + int clkmInteger, clkmDecimals, bck = 0; + double denom = (double)1 / 63; + int channel = 2; + +// double mclk; + double clkmdiv; + + int factor; + + if (bits == 8) { + factor = 120; + } else { + factor = (256 % bits) ? 384 : 256; + } + + clkmdiv = (double)I2S_BASE_CLK / (rate* factor); + if (clkmdiv > 256) { + log_e("rate is too low"); + return ESP_FAIL; + } + I2S[bus_num].rate = rate; + + clkmInteger = clkmdiv; + clkmDecimals = ((clkmdiv - clkmInteger) / denom); + + if (bits == 8) { +// mclk = rate* factor; + bck = 60; + bits = 16; + } else { +// mclk = (double)clkmInteger + (denom* clkmDecimals); + bck = factor/(bits* channel); + } + + i2sSetClock(bus_num, clkmInteger, clkmDecimals, 63, bck, bits); + + return ESP_OK; +} + +void IRAM_ATTR i2sDmaISR(void* arg) +{ + i2s_dma_item_t* dummy = NULL; + i2s_bus_t* dev = (i2s_bus_t*)(arg); + portBASE_TYPE hpTaskAwoken = 0; + + if (dev->bus->int_st.out_eof) { + i2s_dma_item_t* item = (i2s_dma_item_t*)(dev->bus->out_eof_des_addr); + item->data = dev->silence_buf; + item->blocksize = dev->silence_len; + item->datalen = dev->silence_len; + if (xQueueIsQueueFullFromISR(dev->tx_queue) == pdTRUE) { + xQueueReceiveFromISR(dev->tx_queue, &dummy, &hpTaskAwoken); + } + xQueueSendFromISR(dev->tx_queue, (void*)&item, &hpTaskAwoken); + } + dev->bus->int_clr.val = dev->bus->int_st.val; + if (hpTaskAwoken == pdTRUE) { + portYIELD_FROM_ISR(); + } +} + +size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent) { + if (bus_num > 1 || !I2S[bus_num].tx_queue) { + return 0; + } + size_t index = 0; + size_t toSend = len; + size_t limit = I2S_DMA_MAX_DATA_LEN; + i2s_dma_item_t* item = NULL; + + while (len) { + toSend = len; + if (toSend > limit) { + toSend = limit; + } + + if (xQueueReceive(I2S[bus_num].tx_queue, &item, portMAX_DELAY) == pdFALSE) { + log_e("xQueueReceive failed\n"); + break; + } + // data is constant. no need to copy + item->data = data + index; + item->blocksize = toSend; + item->datalen = toSend; + + len -= toSend; + index += toSend; + } + return index; +} + + +#endif diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.h b/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.h new file mode 100644 index 000000000000..0027369cf0fe --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/Esp32_i2s.h @@ -0,0 +1,40 @@ +#pragma once + +#if defined(ARDUINO_ARCH_ESP32) + +#ifdef __cplusplus +extern "C" { +#endif + +#include "esp_err.h" + +#define I2S_DMA_MAX_DATA_LEN 4092// maximum bytes in one dma item + +typedef enum { + I2S_CHAN_STEREO, I2S_CHAN_RIGHT_TO_LEFT, I2S_CHAN_LEFT_TO_RIGHT, I2S_CHAN_RIGHT_ONLY, I2S_CHAN_LEFT_ONLY +} i2s_tx_chan_mod_t; + +typedef enum { + I2S_FIFO_16BIT_DUAL, I2S_FIFO_16BIT_SINGLE, I2S_FIFO_32BIT_DUAL, I2S_FIFO_32BIT_SINGLE +} i2s_tx_fifo_mod_t; + +void i2sInit(uint8_t bus_num, uint32_t bits_per_sample, uint32_t sample_rate, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod, size_t dma_count, size_t dma_len); + +void i2sSetPins(uint8_t bus_num, int8_t out, int8_t ws, int8_t bck, int8_t in); +void i2sSetDac(uint8_t bus_num, bool right, bool left); + +esp_err_t i2sSetClock(uint8_t bus_num, uint8_t div_num, uint8_t div_b, uint8_t div_a, uint8_t bck, uint8_t bits_per_sample); +esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t sample_rate, uint8_t bits_per_sample); + +void i2sSetTxDataMode(uint8_t bus_num, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod); + +void i2sSetSilenceBuf(uint8_t bus_num, uint8_t* data, size_t len); + +size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent); +bool i2sWriteDone(uint8_t bus_num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HsbColor.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HsbColor.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HsbColor.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HsbColor.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HsbColor.h b/lib/NeoPixelBus-2.5.0.09/src/internal/HsbColor.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HsbColor.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/HsbColor.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HslColor.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HslColor.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HslColor.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HslColor.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HslColor.h b/lib/NeoPixelBus-2.5.0.09/src/internal/HslColor.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HslColor.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/HslColor.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColor.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColor.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColor.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColor.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColor.h b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColor.h similarity index 99% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColor.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColor.h index a40d6223c09c..238d4acdbbe5 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColor.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColor.h @@ -212,7 +212,7 @@ struct HtmlColor for (uint8_t indexName = 0; indexName < T_HTMLCOLORNAMES::Count(); ++indexName) { const HtmlColorPair* colorPair = T_HTMLCOLORNAMES::Pair(indexName); - PGM_P searchName = (PGM_P)pgm_read_ptr(&colorPair->Name); + PGM_P searchName = reinterpret_cast(pgm_read_ptr(&(colorPair->Name))); size_t str1Size = nameSize; const char* str1 = name; const char* str2P = searchName; diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNameStrings.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNameStrings.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNameStrings.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNameStrings.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNameStrings.h b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNameStrings.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNameStrings.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNameStrings.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNames.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNames.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColorNames.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorNames.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/HtmlColorShortNames.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorShortNames.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/HtmlColorShortNames.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/HtmlColorShortNames.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/Layouts.h b/lib/NeoPixelBus-2.5.0.09/src/internal/Layouts.h similarity index 93% rename from lib/NeoPixelBus-2.2.9/src/internal/Layouts.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/Layouts.h index 0df0049d7d5b..5b1016ea996c 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/Layouts.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/Layouts.h @@ -57,7 +57,7 @@ class RowMajorTilePreference class RowMajorLayout : public RowMajorTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) { return x + y * width; } @@ -102,7 +102,7 @@ class RowMajor180Layout : public RowMajorTilePreference class RowMajor270Layout : public RowMajorTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) { return x * height + (height - 1 - y); } @@ -136,7 +136,7 @@ class ColumnMajorTilePreference class ColumnMajorLayout : public ColumnMajorTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) { return x * height + y; } @@ -151,7 +151,7 @@ class ColumnMajorLayout : public ColumnMajorTilePreference class ColumnMajor90Layout : public ColumnMajorTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) { return (width - 1 - x) + y * width; } @@ -213,7 +213,7 @@ class RowMajorAlternatingTilePreference class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) { uint16_t index = y * width; @@ -290,7 +290,7 @@ class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) { uint16_t index = x * height; @@ -332,7 +332,7 @@ class ColumnMajorAlternatingTilePreference class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) { uint16_t index = x * height; @@ -357,7 +357,7 @@ class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference { public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) { uint16_t index = y * width; diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoArmMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoArmMethod.h similarity index 82% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoArmMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoArmMethod.h index 34b42a8532ee..9cfce887405b 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoArmMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoArmMethod.h @@ -66,7 +66,7 @@ template class NeoArmMethodBase _endTime = micros(); } - void Update() + void Update(bool) { // Data latch = 50+ microsecond pause in the output stream. Rather than // put a delay at the end of the function, the ending time is noted and @@ -106,24 +106,32 @@ template class NeoArmMethodBase uint8_t _pin; // output pin number }; +// Teensy 3.0 or 3.1 (3.2) or 3.5 or 3.6 +#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) -#if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 & 3.1 - -class NeoArmMk20dxSpeedPropsWs2813 +class NeoArmMk20dxSpeedProps800KbpsBase { public: static const uint32_t CyclesT0h = (F_CPU / 4000000); static const uint32_t CyclesT1h = (F_CPU / 1250000); static const uint32_t Cycles = (F_CPU / 800000); - static const uint32_t ResetTimeUs = 250; }; -class NeoArmMk20dxSpeedProps800Kbps +class NeoArmMk20dxSpeedPropsWs2812x : public NeoArmMk20dxSpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoArmMk20dxSpeedPropsSk6812 : public NeoArmMk20dxSpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +class NeoArmMk20dxSpeedProps800Kbps : public NeoArmMk20dxSpeedProps800KbpsBase { public: - static const uint32_t CyclesT0h = (F_CPU / 4000000); - static const uint32_t CyclesT1h = (F_CPU / 1250000); - static const uint32_t Cycles = (F_CPU / 800000); static const uint32_t ResetTimeUs = 50; }; @@ -136,6 +144,15 @@ class NeoArmMk20dxSpeedProps400Kbps static const uint32_t ResetTimeUs = 50; }; +class NeoArmMk20dxSpeedPropsApa106 +{ +public: + static const uint32_t CyclesT0h = (F_CPU / 4000000); + static const uint32_t CyclesT1h = (F_CPU / 913750); + static const uint32_t Cycles = (F_CPU / 584800); + static const uint32_t ResetTimeUs = 50; +}; + template class NeoArmMk20dxSpeedBase { public: @@ -180,16 +197,17 @@ template class NeoArmMk20dxSpeedBase } }; -typedef NeoArmMethodBase> NeoArmWs2813Method; +typedef NeoArmMethodBase> NeoArmWs2812xMethod; +typedef NeoArmMethodBase> NeoArmSk6812Method; +typedef NeoArmMethodBase> NeoArmApa106Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; + #elif defined(__MKL26Z64__) // Teensy-LC #if F_CPU == 48000000 - - class NeoArmMk26z64Speed800KbpsBase { public: @@ -280,20 +298,28 @@ class NeoArmMk26z64Speed800KbpsBase } }; -class NeoArmMk26z64SpeedWs2813 : public NeoArmMk26z64Speed800KbpsBase +class NeoArmMk26z64SpeedWs2812x : public NeoArmMk26z64Speed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoArmMk26z64SpeedSk6812 : public NeoArmMk26z64Speed800KbpsBase { public: - const static uint32_t ResetTimeUs = 250; + const static uint32_t ResetTimeUs = 80; }; class NeoArmMk26z64Speed800Kbps : public NeoArmMk26z64Speed800KbpsBase { public: const static uint32_t ResetTimeUs = 50; -} +}; -typedef NeoArmMethodBase NeoArmWs2813Method; +typedef NeoArmMethodBase NeoArmWs2812xMethod; +typedef NeoArmMethodBase NeoArmSk6812Method; typedef NeoArmMethodBase NeoArm800KbpsMethod; +typedef NeoArm800KbpsMethod NeoArmApa106Method #else #error "Teensy-LC: Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz" @@ -327,10 +353,16 @@ class NeoArmSamd21g18aSpeedProps800KbpsBase } }; -class NeoArmSamd21g18aSpeedPropsWs2813 : public NeoArmSamd21g18aSpeedProps800KbpsBase +class NeoArmSamd21g18aSpeedPropsWs2812x : public NeoArmSamd21g18aSpeedProps800KbpsBase { public: - static const uint32_t ResetTimeUs = 250; + static const uint32_t ResetTimeUs = 300; +}; + +class NeoArmSamd21g18aSpeedPropsSk6812 : public NeoArmSamd21g18aSpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; }; class NeoArmSamd21g18aSpeedProps800Kbps : public NeoArmSamd21g18aSpeedProps800KbpsBase @@ -419,11 +451,13 @@ template class NeoArmSamd21g18aSpeedBase } }; -typedef NeoArmMethodBase> NeoArmWs2813Method; +typedef NeoArmMethodBase> NeoArmWs2812xMethod; +typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; +typedef NeoArm400KbpsMethod NeoArmApa106Method -#elif defined (ARDUINO_STM32_FEATHER) // FEATHER WICED (120MHz) +#elif defined(ARDUINO_STM32_FEATHER) || defined(ARDUINO_ARCH_STM32L4) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32F1)// FEATHER WICED (120MHz) class NeoArmStm32SpeedProps800KbpsBase { @@ -477,16 +511,22 @@ class NeoArmStm32SpeedProps800KbpsBase } }; -class NeoArmStm32SpeedProps800Kbps : public NeoArmStm32SpeedProps800KbpsBase +class NeoArmStm32SpeedPropsWs2812x : public NeoArmStm32SpeedProps800KbpsBase { public: - static const uint32_t ResetTimeUs = 50; + static const uint32_t ResetTimeUs = 300; +}; + +class NeoArmStm32SpeedPropsSk6812 : public NeoArmStm32SpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; }; -class NeoArmStm32SpeedPropsWs2813 : public NeoArmStm32SpeedProps800KbpsBase +class NeoArmStm32SpeedProps800Kbps : public NeoArmStm32SpeedProps800KbpsBase { public: - static const uint32_t ResetTimeUs = 250; + static const uint32_t ResetTimeUs = 50; }; /* TODO - not found in Adafruit library @@ -521,11 +561,36 @@ template class NeoArmStm32SpeedBase uint8_t* end = ptr + sizePixels; uint8_t p = *ptr++; uint8_t bitMask = 0x80; - uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit); - volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL); - volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH); +#if defined(ARDUINO_STM32_FEATHER) + uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit); + + volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL); + volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH); + +#elif defined(ARDUINO_ARCH_STM32F4) + uint32_t pinMask = BIT(pin & 0x0f); + + volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL); + volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH); + +#elif defined(ARDUINO_ARCH_STM32F1) + + uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit); + + volatile uint32_t* set = &(PIN_MAP[pin].gpio_device->regs->BRR); + volatile uint32_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRR); + +#elif defined(ARDUINO_ARCH_STM32L4) + + uint32_t pinMask = g_APinDescription[pin].bit; + GPIO_TypeDef* GPIO = static_cast(g_APinDescription[pin].GPIO); + + volatile uint32_t* set = &(GPIO->BRR); + volatile uint32_t* clr = &(GPIO->BSRR); + +#endif for (;;) { if (p & bitMask) @@ -567,8 +632,10 @@ template class NeoArmStm32SpeedBase } }; -typedef NeoArmMethodBase> NeoArmWs2813Method; +typedef NeoArmMethodBase> NeoArmWs2812xMethod; +typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; +typedef NeoArm800KbpsMethod NeoArmApa106Method; #else // Other ARM architecture -- Presumed Arduino Due @@ -576,21 +643,29 @@ typedef NeoArmMethodBase> Neo #define ARM_OTHER_SCALE VARIANT_MCK / 2UL / 1000000UL #define ARM_OTHER_INST (2UL * F_CPU / VARIANT_MCK) -class NeoArmOtherSpeedPropsWs2813 +class NeoArmOtherSpeedProps800KbpsBase { public: static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); - static const uint32_t ResetTimeUs = 250; }; -class NeoArmOtherSpeedProps800Kbps +class NeoArmOtherSpeedPropsWs2812x : public NeoArmOtherSpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoArmOtherSpeedPropsSk6812 : public NeoArmOtherSpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +class NeoArmOtherSpeedProps800Kbps : public NeoArmOtherSpeedProps800KbpsBase { public: - static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); - static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); - static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST)); static const uint32_t ResetTimeUs = 50; }; @@ -679,16 +754,23 @@ template class NeoArmOtherSpeedBase } }; -typedef NeoArmMethodBase> NeoArmWs2813Method; +typedef NeoArmMethodBase> NeoArmWs2812xMethod; +typedef NeoArmMethodBase> NeoArmSk6812Method; typedef NeoArmMethodBase> NeoArm800KbpsMethod; typedef NeoArmMethodBase> NeoArm400KbpsMethod; +typedef NeoArm400KbpsMethod NeoArmApa106Method; #endif // Arm doesn't have alternatives methods yet, so only one to make the default -typedef NeoArmWs2813Method NeoWs2813Method; -typedef NeoArm800KbpsMethod Neo800KbpsMethod; +typedef NeoArmWs2812xMethod NeoWs2813Method; +typedef NeoArmWs2812xMethod NeoWs2812xMethod; +typedef NeoArmSk6812Method NeoSk6812Method; +typedef NeoArmSk6812Method NeoLc8812Method; +typedef NeoArm800KbpsMethod NeoWs2812Method; +typedef NeoArmApa106Method NeoApa106Method; +typedef NeoArmWs2812xMethod Neo800KbpsMethod; #ifdef NeoArm400KbpsMethod // this is needed due to missing 400Kbps for some platforms typedef NeoArm400KbpsMethod Neo400KbpsMethod; #endif diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoAvrMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoAvrMethod.h similarity index 90% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoAvrMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoAvrMethod.h index 9843816f8fc8..b292cf48c57d 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoAvrMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoAvrMethod.h @@ -71,10 +71,16 @@ class NeoAvrSpeed800KbpsBase }; -class NeoAvrSpeedWs2813 : public NeoAvrSpeed800KbpsBase +class NeoAvrSpeedWs2812x : public NeoAvrSpeed800KbpsBase { public: - static const uint32_t ResetTimeUs = 250; + static const uint32_t ResetTimeUs = 300; +}; + +class NeoAvrSpeedSk6812 : public NeoAvrSpeed800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; }; class NeoAvrSpeed800Kbps: public NeoAvrSpeed800KbpsBase @@ -142,7 +148,7 @@ template class NeoAvrMethodBase _endTime = micros(); } - void Update() + void Update(bool) { // Data latch = 50+ microsecond pause in the output stream. Rather than // put a delay at the end of the function, the ending time is noted and @@ -187,13 +193,21 @@ template class NeoAvrMethodBase uint8_t _pinMask; // Output PORT bitmask }; -typedef NeoAvrMethodBase NeoAvrWs2813Method; + +typedef NeoAvrMethodBase NeoAvrWs2812xMethod; +typedef NeoAvrMethodBase NeoAvrSk6812Method; typedef NeoAvrMethodBase NeoAvr800KbpsMethod; typedef NeoAvrMethodBase NeoAvr400KbpsMethod; + // AVR doesn't have alternatives yet, so there is just the default -typedef NeoAvrWs2813Method NeoWs2813Method; -typedef NeoAvr800KbpsMethod Neo800KbpsMethod; +typedef NeoAvrWs2812xMethod NeoWs2813Method; +typedef NeoAvrWs2812xMethod NeoWs2812xMethod; +typedef NeoAvr800KbpsMethod NeoWs2812Method; +typedef NeoAvrSk6812Method NeoSk6812Method; +typedef NeoAvrSk6812Method NeoLc8812Method; +typedef NeoAvr400KbpsMethod NeoApa106Method; +typedef NeoAvrWs2812xMethod Neo800KbpsMethod; typedef NeoAvr400KbpsMethod Neo400KbpsMethod; #endif diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoBitmapFile.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBitmapFile.h similarity index 84% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoBitmapFile.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoBitmapFile.h index 697967858348..870696f48229 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoBitmapFile.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBitmapFile.h @@ -75,12 +75,11 @@ template class NeoBitmapFile _width(0), _height(0), _sizeRow(0), - _bottomToTop(true), - _bytesPerPixel(0) + _bytesPerPixel(0), + _bottomToTop(true) { } - - + ~NeoBitmapFile() { _file.close(); @@ -172,7 +171,7 @@ template class NeoBitmapFile return _height; }; - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) { if (x < 0 || x >= _width || y < 0 || y >= _height) { @@ -190,7 +189,9 @@ template class NeoBitmapFile return color; }; - void Blt(NeoBufferContext destBuffer, + + template void Render(NeoBufferContext destBuffer, + T_SHADER& shader, uint16_t indexPixel, int16_t xSrc, int16_t ySrc, @@ -205,10 +206,11 @@ template class NeoBitmapFile { for (int16_t x = 0; x < wSrc && indexPixel < destPixelCount; x++, indexPixel++) { - if (xSrc < _width) + if ((uint16_t)xSrc < _width) { if (readPixel(&color)) { + color = shader.Apply(indexPixel, color); xSrc++; } } @@ -217,8 +219,20 @@ template class NeoBitmapFile } } } - + void Blt(NeoBufferContext destBuffer, + uint16_t indexPixel, + int16_t xSrc, + int16_t ySrc, + int16_t wSrc) + { + NeoShaderNop shaderNop; + + Render>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc); + }; + + template void Render(NeoBufferContext destBuffer, + T_SHADER& shader, int16_t xDest, int16_t yDest, int16_t xSrc, @@ -239,15 +253,16 @@ template class NeoBitmapFile { for (int16_t x = 0; x < wSrc; x++) { - if (xFile < _width) + uint16_t indexDest = layoutMap(xDest + x, yDest + y); + + if ((uint16_t)xFile < _width) { if (readPixel(&color)) { + color = shader.Apply(indexDest, color); xFile++; } } - - uint16_t indexDest = layoutMap(xDest + x, yDest + y); if (indexDest < destPixelCount) { @@ -258,6 +273,28 @@ template class NeoBitmapFile } }; + void Blt(NeoBufferContext destBuffer, + int16_t xDest, + int16_t yDest, + int16_t xSrc, + int16_t ySrc, + int16_t wSrc, + int16_t hSrc, + LayoutMapCallback layoutMap) + { + NeoShaderNop shaderNop; + + Render>(destBuffer, + shaderNop, + xDest, + yDest, + xSrc, + ySrc, + wSrc, + hSrc, + layoutMap); + }; + private: T_FILE_METHOD _file; @@ -268,26 +305,26 @@ template class NeoBitmapFile uint8_t _bytesPerPixel; bool _bottomToTop; - int16_t constrainX(int16_t x) + int16_t constrainX(int16_t x) const { if (x < 0) { x = 0; } - else if (x >= _width) + else if ((uint16_t)x >= _width) { x = _width - 1; } return x; }; - int16_t constrainY(int16_t y) + int16_t constrainY(int16_t y) const { if (y < 0) { y = 0; } - else if (y >= _height) + else if ((uint16_t)y >= _height) { y = _height - 1; } diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoBuffer.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBuffer.h similarity index 84% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoBuffer.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoBuffer.h index 86176c9b0393..996a77820302 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoBuffer.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBuffer.h @@ -133,19 +133,38 @@ template class NeoBuffer Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap); } + template void Render(NeoBufferContext destBuffer, T_SHADER& shader) + { + uint16_t countPixels = destBuffer.PixelCount(); + + if (countPixels > _method.PixelCount()) + { + countPixels = _method.PixelCount(); + } + + for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++) + { + typename T_BUFFER_METHOD::ColorObject color; + + shader.Apply(indexPixel, (uint8_t*)(&color), _method.Pixels() + (indexPixel * _method.PixelSize())); + + T_BUFFER_METHOD::ColorFeature::applyPixelColor(destBuffer.Pixels, indexPixel, color); + } + } + private: T_BUFFER_METHOD _method; uint16_t pixelIndex( int16_t x, - int16_t y) + int16_t y) const { uint16_t result = PixelIndex_OutOfBounds; if (x >= 0 && - x < Width() && + (uint16_t)x < Width() && y >= 0 && - y < Height()) + (uint16_t)y < Height()) { result = x + y * Width(); } diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoBufferContext.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBufferContext.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoBufferContext.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoBufferContext.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoBufferMethods.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoBufferMethods.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoBufferMethods.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoBufferMethods.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoColorFeatures.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoColorFeatures.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoColorFeatures.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoColorFeatures.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoDib.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoDib.h similarity index 90% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoDib.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoDib.h index ef69ce6f7b16..2ec93eb7b1f5 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoDib.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoDib.h @@ -25,6 +25,32 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +template class NeoShaderNop +{ +public: + NeoShaderNop() + { + } + + bool IsDirty() const + { + return true; + }; + + void Dirty() + { + }; + + void ResetDirty() + { + }; + + T_COLOR_OBJECT Apply(uint16_t, T_COLOR_OBJECT color) + { + return color; + }; +}; + class NeoShaderBase { public: @@ -118,11 +144,13 @@ template class NeoDib Dirty(); }; - template void Render(NeoBufferContext destBuffer, T_SHADER& shader) + template void Render(NeoBufferContext destBuffer, + T_SHADER& shader) { if (IsDirty() || shader.IsDirty()) { uint16_t countPixels = destBuffer.PixelCount(); + if (countPixels > _countPixels) { countPixels = _countPixels; diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoEase.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEase.h similarity index 72% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoEase.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoEase.h index eaa50239fa19..b7b5df9641bd 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoEase.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEase.h @@ -71,6 +71,20 @@ class NeoEase } } + static float QuadraticCenter(float unitValue) + { + unitValue *= 2.0f; + if (unitValue < 1.0f) + { + return (-0.5f * (unitValue * unitValue - 2.0f)); + } + else + { + unitValue -= 1.0f; + return (0.5f * (unitValue * unitValue + 1.0f)); + } + } + static float CubicIn(float unitValue) { return (unitValue * unitValue * unitValue); @@ -96,6 +110,13 @@ class NeoEase } } + static float CubicCenter(float unitValue) + { + unitValue *= 2.0f; + unitValue -= 1.0f; + return (0.5f * (unitValue * unitValue * unitValue) + 1); + } + static float QuarticIn(float unitValue) { return (unitValue * unitValue * unitValue * unitValue); @@ -121,6 +142,20 @@ class NeoEase } } + static float QuarticCenter(float unitValue) + { + unitValue *= 2.0f; + unitValue -= 1.0f; + if (unitValue < 0.0f) + { + return (-0.5f * (unitValue * unitValue * unitValue * unitValue - 1.0f)); + } + else + { + return (0.5f * (unitValue * unitValue * unitValue * unitValue + 1.0f)); + } + } + static float QuinticIn(float unitValue) { return (unitValue * unitValue * unitValue * unitValue * unitValue); @@ -146,6 +181,13 @@ class NeoEase } } + static float QuinticCenter(float unitValue) + { + unitValue *= 2.0f; + unitValue -= 1.0f; + return (0.5f * (unitValue * unitValue * unitValue * unitValue * unitValue + 1.0f)); + } + static float SinusoidalIn(float unitValue) { return (-cos(unitValue * HALF_PI) + 1.0f); @@ -161,6 +203,19 @@ class NeoEase return -0.5 * (cos(PI * unitValue) - 1.0f); } + static float SinusoidalCenter(float unitValue) + { + if (unitValue < 0.5f) + { + return (0.5 * sin(PI * unitValue)); + } + else + { + return (-0.5 * (cos(PI * (unitValue-0.5f)) + 1.0f)); + } + + } + static float ExponentialIn(float unitValue) { return (pow(2, 10.0f * (unitValue - 1.0f))); @@ -185,6 +240,20 @@ class NeoEase } } + static float ExponentialCenter(float unitValue) + { + unitValue *= 2.0f; + if (unitValue < 1.0f) + { + return (0.5f * (-pow(2, -10.0f * unitValue) + 1.0f)); + } + else + { + unitValue -= 2.0f; + return (0.5f * (pow(2, 10.0f * unitValue) + 1.0f)); + } + } + static float CircularIn(float unitValue) { if (unitValue == 1.0f) @@ -217,6 +286,25 @@ class NeoEase } } + static float CircularCenter(float unitValue) + { + unitValue *= 2.0f; + unitValue -= 1.0f; + if (unitValue == 0.0f) + { + return 1.0f; + } + else if (unitValue < 0.0f) + { + return (0.5f * sqrt(1.0f - unitValue * unitValue)); + } + else + { + unitValue -= 2.0f; + return (-0.5f * (sqrt(1.0f - unitValue * unitValue) - 1.0f ) + 0.5f); + } + } + static float Gamma(float unitValue) { return pow(unitValue, 1.0f / 0.45f); diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32I2sMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32I2sMethod.h new file mode 100644 index 000000000000..d7856a1ef647 --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32I2sMethod.h @@ -0,0 +1,217 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#pragma once + +#ifdef ARDUINO_ARCH_ESP32 + +extern "C" +{ +#include +#include "Esp32_i2s.h" +} + +const uint16_t c_dmaBytesPerPixelBytes = 4; + +class NeoEsp32I2sSpeedWs2812x +{ +public: + const static uint32_t I2sSampleRate = 100000; + const static uint16_t ByteSendTimeUs = 10; + const static uint16_t ResetTimeUs = 300; +}; + +class NeoEsp32I2sSpeedSk6812 +{ +public: + const static uint32_t I2sSampleRate = 100000; + const static uint16_t ByteSendTimeUs = 10; + const static uint16_t ResetTimeUs = 80; +}; + +class NeoEsp32I2sSpeed800Kbps +{ +public: + const static uint32_t I2sSampleRate = 100000; + const static uint16_t ByteSendTimeUs = 10; + const static uint16_t ResetTimeUs = 50; +}; + +class NeoEsp32I2sSpeed400Kbps +{ +public: + const static uint32_t I2sSampleRate = 50000; + const static uint16_t ByteSendTimeUs = 20; + const static uint16_t ResetTimeUs = 50; +}; + +class NeoEsp32I2sSpeedApa106 +{ +public: + const static uint32_t I2sSampleRate = 76000; + const static uint16_t ByteSendTimeUs = 14; + const static uint16_t ResetTimeUs = 50; +}; + +class NeoEsp32I2sBusZero +{ +public: + const static uint8_t I2sBusNumber = 0; +}; + +class NeoEsp32I2sBusOne +{ +public: + const static uint8_t I2sBusNumber = 1; +}; + +template class NeoEsp32I2sMethodBase +{ +public: + NeoEsp32I2sMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) : + _pin(pin) + { + uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize; + uint16_t resetSize = c_dmaBytesPerPixelBytes * T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs; + + _pixelsSize = pixelCount * elementSize; + _i2sBufferSize = pixelCount * dmaPixelSize + resetSize; + + // must have a 4 byte aligned buffer for i2s + uint32_t alignment = _i2sBufferSize % 4; + if (alignment) + { + _i2sBufferSize += 4 - alignment; + } + + _pixels = static_cast(malloc(_pixelsSize)); + memset(_pixels, 0x00, _pixelsSize); + + _i2sBuffer = static_cast(malloc(_i2sBufferSize)); + memset(_i2sBuffer, 0x00, _i2sBufferSize); + } + + ~NeoEsp32I2sMethodBase() + { + while (!IsReadyToUpdate()) + { + yield(); + } + + pinMode(_pin, INPUT); + + free(_pixels); + free(_i2sBuffer); + } + + bool IsReadyToUpdate() const + { + return (i2sWriteDone(T_BUS::I2sBusNumber)); + } + + void Initialize() + { + size_t dmaCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN; + i2sInit(T_BUS::I2sBusNumber, 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaCount, 0); + i2sSetPins(T_BUS::I2sBusNumber, _pin, -1, -1, -1); + } + + void Update(bool) + { + // wait for not actively sending data + while (!IsReadyToUpdate()) + { + yield(); + } + + FillBuffers(); + + i2sWrite(T_BUS::I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false); + } + + uint8_t* getPixels() const + { + return _pixels; + }; + + size_t getPixelsSize() const + { + return _pixelsSize; + } + +private: + const uint8_t _pin; // output pin number + + size_t _pixelsSize; // Size of '_pixels' buffer + uint8_t* _pixels; // Holds LED color values + + uint32_t _i2sBufferSize; // total size of _i2sBuffer + uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc + + void FillBuffers() + { + const uint16_t bitpatterns[16] = + { + 0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110, + 0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110, + 0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110, + 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, + }; + + uint16_t* pDma = reinterpret_cast(_i2sBuffer); + uint8_t* pPixelsEnd = _pixels + _pixelsSize; + for (uint8_t* pPixel = _pixels; pPixel < pPixelsEnd; pPixel++) + { + *(pDma++) = bitpatterns[((*pPixel) & 0x0f)]; + *(pDma++) = bitpatterns[((*pPixel) >> 4) & 0x0f]; + } + } +}; + +typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Ws2812xMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Sk6812Method; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s0800KbpsMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s0400KbpsMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Apa106Method; + +typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2812xMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Sk6812Method; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s1800KbpsMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s1400KbpsMethod; +typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Apa106Method; + +// I2s Bus 1 method is the default method for Esp32 +typedef NeoEsp32I2s1Ws2812xMethod NeoWs2813Method; +typedef NeoEsp32I2s1Ws2812xMethod NeoWs2812xMethod; +typedef NeoEsp32I2s1800KbpsMethod NeoWs2812Method; +typedef NeoEsp32I2s1Sk6812Method NeoSk6812Method; +typedef NeoEsp32I2s1Sk6812Method NeoLc8812Method; +typedef NeoEsp32I2s1Apa106Method NeoApa106Method; + +typedef NeoEsp32I2s1Ws2812xMethod Neo800KbpsMethod; +typedef NeoEsp32I2s1400KbpsMethod Neo400KbpsMethod; + +#endif \ No newline at end of file diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32RmtMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32RmtMethod.h new file mode 100644 index 000000000000..86669e509fc6 --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp32RmtMethod.h @@ -0,0 +1,369 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#pragma once + +#ifdef ARDUINO_ARCH_ESP32 + +/* General Reference documentation for the APIs used in this implementation +LOW LEVEL: (what is actually used) +DOCS: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/rmt.html +EXAMPLE: https://github.com/espressif/esp-idf/blob/826ff7186ae07dc81e960a8ea09ebfc5304bfb3b/examples/peripherals/rmt_tx/main/rmt_tx_main.c +HIGHER LEVEL: +NO TRANSLATE SUPPORT so this was not used +NOTE: https://github.com/espressif/arduino-esp32/commit/50d142950d229b8fabca9b749dc4a5f2533bc426 +Esp32-hal-rmt.h +Esp32-hal-rmt.c +*/ + +extern "C" +{ +#include +#include +} + +class NeoEsp32RmtSpeedBase +{ +public: + // ClkDiv of 2 provides for good resolution and plenty of reset resolution; but + // a ClkDiv of 1 will provide enough space for the longest reset and does show + // little better pulse accuracy + const static uint8_t RmtClockDivider = 2; + + inline constexpr static uint32_t FromNs(uint32_t ns) + { + return ns / NsPerRmtTick; + } + // this is used rather than the rmt_item32_t as you can't correctly initialize + // it as a static constexpr within the template + inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow) + { + return (FromNs(nsLow) << 16) | (1 << 15) | (FromNs(nsHigh)); + } + +public: + const static uint32_t RmtCpu = 80000000L; // 80 mhz RMT clock + const static uint32_t NsPerSecond = 1000000000L; + const static uint32_t RmtTicksPerSecond = (RmtCpu / RmtClockDivider); + const static uint32_t NsPerRmtTick = (NsPerSecond / RmtTicksPerSecond); // about 25 +}; + +class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(400, 850); + const static uint32_t RmtBit1 = Item32Val(800, 450); + const static uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtSpeedSk6812 : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(400, 850); + const static uint32_t RmtBit1 = Item32Val(800, 450); + const static uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +class NeoEsp32RmtSpeed800Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(400, 850); + const static uint32_t RmtBit1 = Item32Val(800, 450); + const static uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeed400Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(800, 1700); + const static uint32_t RmtBit1 = Item32Val(1600, 900); + const static uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(400, 1250); + const static uint32_t RmtBit1 = Item32Val(1250, 400); + const static uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtChannel0 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_0; +}; + +class NeoEsp32RmtChannel1 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_1; +}; + +class NeoEsp32RmtChannel2 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_2; +}; + +class NeoEsp32RmtChannel3 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_3; +}; + +class NeoEsp32RmtChannel4 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_4; +}; + +class NeoEsp32RmtChannel5 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_5; +}; + +class NeoEsp32RmtChannel6 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_6; +}; + +class NeoEsp32RmtChannel7 +{ +public: + const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_7; +}; + +template class NeoEsp32RmtMethodBase +{ +public: + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) : + _pin(pin) + { + _pixelsSize = pixelCount * elementSize; + + _pixelsEditing = static_cast(malloc(_pixelsSize)); + memset(_pixelsEditing, 0x00, _pixelsSize); + + _pixelsSending = static_cast(malloc(_pixelsSize)); + // no need to initialize it, it gets overwritten on every send + } + + ~NeoEsp32RmtMethodBase() + { + // wait until the last send finishes before destructing everything + // arbitrary time out of 10 seconds + rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 10000 / portTICK_PERIOD_MS); + + rmt_driver_uninstall(T_CHANNEL::RmtChannelNumber); + + free(_pixelsEditing); + free(_pixelsSending); + } + + + bool IsReadyToUpdate() const + { + return (ESP_OK == rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 0)); + } + + void Initialize() + { + rmt_config_t config; + + config.rmt_mode = RMT_MODE_TX; + config.channel = T_CHANNEL::RmtChannelNumber; + config.gpio_num = static_cast(_pin); + config.mem_block_num = 1; + config.tx_config.loop_en = false; + + config.tx_config.idle_output_en = true; + config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW; + + config.tx_config.carrier_en = false; + config.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW; + + config.clk_div = T_SPEED::RmtClockDivider; + + rmt_config(&config); + rmt_driver_install(T_CHANNEL::RmtChannelNumber, 0, 0); + rmt_translator_init(T_CHANNEL::RmtChannelNumber, _translate); + } + + void Update(bool maintainBufferConsistency) + { + // wait for not actively sending data + // this will time out at 10 seconds, an arbitrarily long period of time + // and do nothing if this happens + if (ESP_OK == rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 10000 / portTICK_PERIOD_MS)) + { + // now start the RMT transmit with the editing buffer before we swap + rmt_write_sample(T_CHANNEL::RmtChannelNumber, _pixelsEditing, _pixelsSize, false); + + if (maintainBufferConsistency) + { + // copy editing to sending, + // this maintains the contract that "colors present before will + // be the same after", otherwise GetPixelColor will be inconsistent + memcpy(_pixelsSending, _pixelsEditing, _pixelsSize); + } + + // swap so the user can modify without affecting the async operation + std::swap(_pixelsSending, _pixelsEditing); + } + } + + uint8_t* getPixels() const + { + return _pixelsEditing; + }; + + size_t getPixelsSize() const + { + return _pixelsSize; + } + +private: + const uint8_t _pin; // output pin number + + size_t _pixelsSize; // Size of '_pixels' buffer + uint8_t* _pixelsEditing; // Holds LED color values exposed for get and set + uint8_t* _pixelsSending; // Holds LED color values used to async send using RMT + + + // stranslate NeoPixelBuffer into RMT buffer + // this is done on the fly so we don't require a send buffer in raw RMT format + // which would be 32x larger than the primary buffer + static void IRAM_ATTR _translate(const void* src, + rmt_item32_t* dest, + size_t src_size, + size_t wanted_num, + size_t* translated_size, + size_t* item_num) + { + if (src == NULL || dest == NULL) + { + *translated_size = 0; + *item_num = 0; + return; + } + + size_t size = 0; + size_t num = 0; + const uint8_t* psrc = static_cast(src); + rmt_item32_t* pdest = dest; + + for (;;) + { + uint8_t data = *psrc; + + for (uint8_t bit = 0; bit < 8; bit++) + { + pdest->val = (data & 0x80) ? T_SPEED::RmtBit1 : T_SPEED::RmtBit0; + pdest++; + data <<= 1; + } + num += 8; + size++; + + // if this is the last byte we need to adjust the length of the last pulse + if (size >= src_size) + { + // extend the last bits LOW value to include the full reset signal length + pdest--; + pdest->duration1 = T_SPEED::RmtDurationReset; + // and stop updating data to send + break; + } + + if (num >= wanted_num) + { + // stop updating data to send + break; + } + + psrc++; + } + + *translated_size = size; + *item_num = num; + } +}; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; + +// RMT is NOT the default method for Esp32, +// you are required to use a specific channel listed above + +#endif \ No newline at end of file diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266DmaMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266DmaMethod.h similarity index 75% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266DmaMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266DmaMethod.h index dc4dd272336c..402c9ae8507e 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoEsp8266DmaMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266DmaMethod.h @@ -48,9 +48,7 @@ extern "C" #include "ets_sys.h" #include "user_interface.h" -// Workaround STAGE compile error -#include -#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_5_0) +#if !defined(__CORE_ESP8266_VERSION_H) || defined(ARDUINO_ESP8266_RELEASE_2_5_0) void rom_i2c_writeReg_Mask(uint32_t block, uint32_t host_id, uint32_t reg_add, uint32_t Msb, uint32_t Lsb, uint32_t indata); #endif } @@ -67,19 +65,29 @@ struct slc_queue_item uint32 next_link_ptr; }; -class NeoEsp8266DmaSpeedWs2813 +class NeoEsp8266DmaSpeed800KbpsBase { public: const static uint32_t I2sClockDivisor = 3; const static uint32_t I2sBaseClockDivisor = 16; - const static uint32_t ResetTimeUs = 250; + const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed }; -class NeoEsp8266DmaSpeed800Kbps +class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 80; +}; + +class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase { public: - const static uint32_t I2sClockDivisor = 3; - const static uint32_t I2sBaseClockDivisor = 16; const static uint32_t ResetTimeUs = 50; }; @@ -88,14 +96,25 @@ class NeoEsp8266DmaSpeed400Kbps public: const static uint32_t I2sClockDivisor = 6; const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed const static uint32_t ResetTimeUs = 50; }; +class NeoEsp8266DmaSpeedApa106 +{ +public: + const static uint32_t I2sClockDivisor = 4; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element + const static uint32_t ResetTimeUs = 50; +}; + enum NeoDmaState { NeoDmaState_Idle, NeoDmaState_Pending, NeoDmaState_Sending, + NeoDmaState_Zeroing, }; const uint16_t c_maxDmaBlockSize = 4095; const uint16_t c_dmaBytesPerPixelBytes = 4; @@ -117,6 +136,8 @@ template class NeoEsp8266DmaMethodBase _i2sBuffer = (uint8_t*)malloc(_i2sBufferSize); memset(_i2sBuffer, 0x00, _i2sBufferSize); + // _i2sBuffer[0] = 0b11101000; // debug, 1 bit then 0 bit + memset(_i2sZeroes, 0x00, sizeof(_i2sZeroes)); _is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize; @@ -133,8 +154,26 @@ template class NeoEsp8266DmaMethodBase ~NeoEsp8266DmaMethodBase() { + uint8_t waits = 1; + while (!IsReadyToUpdate()) + { + waits = 2; + yield(); + } + + // wait for any pending sends to complete + // due to internal i2s caching/send delays, this can more that once the data size + uint32_t time = micros(); + while ((micros() - time) < ((getPixelTime() + T_SPEED::ResetTimeUs) * waits)) + { + yield(); + } + StopDma(); + s_this = nullptr; + pinMode(c_I2sPin, INPUT); + free(_pixels); free(_i2sBuffer); free(_i2sBufDesc); @@ -148,7 +187,8 @@ template class NeoEsp8266DmaMethodBase void Initialize() { StopDma(); - _dmaState = NeoDmaState_Sending; // start off sending empty buffer + + pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA uint8_t* is2Buffer = _i2sBuffer; uint32_t is2BufferSize = _i2sBufferSize; @@ -193,6 +233,11 @@ template class NeoEsp8266DmaMethodBase // setup the rest of i2s DMA // ETS_SLC_INTR_DISABLE(); + + // start off in sending state as that is what it will be all setup to be + // for the interrupt + _dmaState = NeoDmaState_Sending; + SLCC0 |= SLCRXLR | SLCTXLR; SLCC0 &= ~(SLCRXLR | SLCTXLR); SLCIC = 0xFFFFFFFF; @@ -208,9 +253,11 @@ template class NeoEsp8266DmaMethodBase // expect. The TXLINK part still needs a valid DMA descriptor, even if it's unused: the DMA engine will throw // an error at us otherwise. Just feed it any random descriptor. SLCTXL &= ~(SLCTXLAM << SLCTXLA); // clear TX descriptor address - SLCTXL |= (uint32)&(_i2sBufDesc[_i2sBufDescCount-1]) << SLCTXLA; // set TX descriptor address. any random desc is OK, we don't use TX but it needs to be valid + // set TX descriptor address. any random desc is OK, we don't use TX but it needs to be valid + SLCTXL |= (uint32)&(_i2sBufDesc[_i2sBufDescCount-1]) << SLCTXLA; SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address - SLCRXL |= (uint32)_i2sBufDesc << SLCRXLA; // set RX descriptor address + // set RX descriptor address. use first of the data addresses + SLCRXL |= (uint32)&(_i2sBufDesc[0]) << SLCRXLA; ETS_SLC_INTR_ATTACH(i2s_slc_isr, NULL); SLCIE = SLCIRXEOF; // Enable only for RX EOF interrupt @@ -221,8 +268,6 @@ template class NeoEsp8266DmaMethodBase SLCTXL |= SLCTXLS; SLCRXL |= SLCRXLS; - pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA - I2S_CLK_ENABLE(); I2SIC = 0x3F; I2SIE = 0; @@ -232,30 +277,32 @@ template class NeoEsp8266DmaMethodBase I2SC |= I2SRST; I2SC &= ~(I2SRST); - I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) + // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) + I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); I2SFC |= I2SDE; //Enable DMA - I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); // Set RX/TX CHAN_MOD=0 + // Set RX/TX CHAN_MOD=0 + I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); // set the rate uint32_t i2s_clock_div = T_SPEED::I2sClockDivisor & I2SCDM; uint8_t i2s_bck_div = T_SPEED::I2sBaseClockDivisor & I2SBDM; //!trans master, !bits mod, rece slave mod, rece msb shift, right first, msb right - I2SC &= ~(I2STSM | (I2SBMM << I2SBM) | (I2SBDM << I2SBD) | (I2SCDM << I2SCD)); + I2SC &= ~(I2STSM | I2SRSM | (I2SBMM << I2SBM) | (I2SBDM << I2SBD) | (I2SCDM << I2SCD)); I2SC |= I2SRF | I2SMR | I2SRSM | I2SRMS | (i2s_bck_div << I2SBD) | (i2s_clock_div << I2SCD); I2SC |= I2STXS; // Start transmission } - void ICACHE_RAM_ATTR Update() + void ICACHE_RAM_ATTR Update(bool) { // wait for not actively sending data - while (_dmaState != NeoDmaState_Idle) + while (!IsReadyToUpdate()) { yield(); } FillBuffers(); - + // toggle state so the ISR reacts _dmaState = NeoDmaState_Pending; } @@ -273,16 +320,16 @@ template class NeoEsp8266DmaMethodBase private: static NeoEsp8266DmaMethodBase* s_this; // for the ISR - size_t _pixelsSize; // Size of '_pixels' buffer + size_t _pixelsSize; // Size of '_pixels' buffer uint8_t* _pixels; // Holds LED color values uint32_t _i2sBufferSize; // total size of _i2sBuffer uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc // normally 24 bytes creates the minimum 50us latch per spec, but - // with the new logic, this latch is used to space between three states - // buffer size = (24 * (speed / 50)) / 3 - uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 3L]; + // with the new logic, this latch is used to space between mulitple states + // buffer size = (24 * (reset time / 50)) / 6 + uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 6L]; slc_queue_item* _i2sBufDesc; // dma block descriptors uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc @@ -296,15 +343,15 @@ template class NeoEsp8266DmaMethodBase // in the case of this code, the second to last state descriptor volatile static void ICACHE_RAM_ATTR i2s_slc_isr(void) { + ETS_SLC_INTR_DISABLE(); + uint32_t slc_intr_status = SLCIS; SLCIC = 0xFFFFFFFF; - if (slc_intr_status & SLCIRXEOF) + if ((slc_intr_status & SLCIRXEOF) && s_this) { - ETS_SLC_INTR_DISABLE(); - - switch (s_this->_dmaState) + switch (s_this->_dmaState) { case NeoDmaState_Idle: break; @@ -314,7 +361,7 @@ template class NeoEsp8266DmaMethodBase slc_queue_item* finished_item = (slc_queue_item*)SLCRXEDA; // data block has pending data waiting to send, prepare it - // point last state block to top + // point last state block to top (finished_item + 1)->next_link_ptr = (uint32_t)(s_this->_i2sBufDesc); s_this->_dmaState = NeoDmaState_Sending; @@ -330,14 +377,17 @@ template class NeoEsp8266DmaMethodBase // just looping and not sending the data blocks (finished_item + 1)->next_link_ptr = (uint32_t)(finished_item); - s_this->_dmaState = NeoDmaState_Idle; + s_this->_dmaState = NeoDmaState_Zeroing; } break; - } - - ETS_SLC_INTR_ENABLE(); + case NeoDmaState_Zeroing: + s_this->_dmaState = NeoDmaState_Idle; + break; + } } + + ETS_SLC_INTR_ENABLE(); } void FillBuffers() @@ -362,6 +412,16 @@ template class NeoEsp8266DmaMethodBase void StopDma() { ETS_SLC_INTR_DISABLE(); + + // Disable any I2S send or receive + I2SC &= ~(I2STXS | I2SRXS); + + // Reset I2S + I2SC &= ~(I2SRST); + I2SC |= I2SRST; + I2SC &= ~(I2SRST); + + SLCIC = 0xFFFFFFFF; SLCIE = 0; SLCTXL &= ~(SLCTXLAM << SLCTXLA); // clear TX descriptor address @@ -369,18 +429,32 @@ template class NeoEsp8266DmaMethodBase pinMode(c_I2sPin, INPUT); } + + uint32_t getPixelTime() const + { + return (T_SPEED::ByteSendTimeUs * this->_pixelsSize); + }; + }; -template +template NeoEsp8266DmaMethodBase* NeoEsp8266DmaMethodBase::s_this; -typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaWs2813Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaWs2812xMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaSk6812Method; typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma800KbpsMethod; typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaApa106Method; // Dma method is the default method for Esp8266 -typedef NeoEsp8266DmaWs2813Method NeoWs2813Method; -typedef NeoEsp8266Dma800KbpsMethod Neo800KbpsMethod; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; +typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; +typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; +typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; +typedef NeoEsp8266DmaApa106Method NeoApa106Method; + +typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; -#endif \ No newline at end of file +#endif diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.cpp new file mode 100644 index 000000000000..eb06812e6efc --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.cpp @@ -0,0 +1,171 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp8266 UART hardware + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#ifdef ARDUINO_ARCH_ESP8266 +#include "NeoEsp8266UartMethod.h" +#include +extern "C" +{ + #include +} + +const volatile uint8_t* ICACHE_RAM_ATTR NeoEsp8266UartContext::FillUartFifo(uint8_t uartNum, + const volatile uint8_t* pixels, + const volatile uint8_t* end) +{ + // Remember: UARTs send less significant bit (LSB) first so + // pushing ABCDEF byte will generate a 0FEDCBA1 signal, + // including a LOW(0) start & a HIGH(1) stop bits. + // Also, we have configured UART to invert logic levels, so: + const uint8_t _uartData[4] = { + 0b110111, // On wire: 1 000 100 0 [Neopixel reads 00] + 0b000111, // On wire: 1 000 111 0 [Neopixel reads 01] + 0b110100, // On wire: 1 110 100 0 [Neopixel reads 10] + 0b000100, // On wire: 1 110 111 0 [NeoPixel reads 11] + }; + uint8_t avail = (UART_TX_FIFO_SIZE - GetTxFifoLength(uartNum)) / 4; + if (end - pixels > avail) + { + end = pixels + avail; + } + while (pixels < end) + { + uint8_t subpix = *pixels++; + Enqueue(uartNum, _uartData[(subpix >> 6) & 0x3]); + Enqueue(uartNum, _uartData[(subpix >> 4) & 0x3]); + Enqueue(uartNum, _uartData[(subpix >> 2) & 0x3]); + Enqueue(uartNum, _uartData[subpix & 0x3]); + } + return pixels; +} + +volatile NeoEsp8266UartInterruptContext* NeoEsp8266UartInterruptContext::s_uartInteruptContext[] = { nullptr, nullptr }; + +void NeoEsp8266UartInterruptContext::StartSending(uint8_t uartNum, uint8_t* start, uint8_t* end) +{ + // send the pixels asynchronously + _asyncBuff = start; + _asyncBuffEnd = end; + + // enable the transmit interrupt + USIE(uartNum) |= (1 << UIFE); +} + +void NeoEsp8266UartInterruptContext::Attach(uint8_t uartNum) +{ + // Disable all interrupts + ETS_UART_INTR_DISABLE(); + + // Clear the RX & TX FIFOS + const uint32_t fifoResetFlags = (1 << UCTXRST) | (1 << UCRXRST); + USC0(uartNum) |= fifoResetFlags; + USC0(uartNum) &= ~(fifoResetFlags); + + // attach the ISR if needed + if (s_uartInteruptContext[0] == nullptr && + s_uartInteruptContext[1] == nullptr) + { + ETS_UART_INTR_ATTACH(Isr, s_uartInteruptContext); + } + + // attach the context + s_uartInteruptContext[uartNum] = this; + + // Set tx fifo trigger. 80 bytes gives us 200 microsecs to refill the FIFO + USC1(uartNum) = (80 << UCFET); + + // Disable RX & TX interrupts. It maybe still enabled by uart.c in the SDK + USIE(uartNum) &= ~((1 << UIFF) | (1 << UIFE)); + + // Clear all pending interrupts in UART1 + USIC(uartNum) = 0xffff; + + // Reenable interrupts + ETS_UART_INTR_ENABLE(); +} + +void NeoEsp8266UartInterruptContext::Detach(uint8_t uartNum) +{ + // Disable interrupts + ETS_UART_INTR_DISABLE(); + + if (s_uartInteruptContext[uartNum] != nullptr) + { + // turn off uart + USC1(uartNum) = 0; + USIC(uartNum) = 0xffff; + USIE(uartNum) = 0; + + s_uartInteruptContext[uartNum] = nullptr; + + if (s_uartInteruptContext[0] == nullptr && + s_uartInteruptContext[1] == nullptr) + { + // detach our ISR + ETS_UART_INTR_ATTACH(NULL, NULL); + + // return so we don't enable interrupts since there is no ISR anymore + return; + } + } + + // Reenable interrupts + ETS_UART_INTR_ENABLE(); +} + +void ICACHE_RAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param) +{ + // make sure this is for us + if (param == s_uartInteruptContext) + { + // Interrupt handler is shared between UART0 & UART1 + // so we need to test for both + for (uint8_t uartNum = 0; uartNum < 2; uartNum++) + { + if (USIS(uartNum) && s_uartInteruptContext[uartNum] != nullptr) + { + // Fill the FIFO with new data + s_uartInteruptContext[uartNum]->_asyncBuff = FillUartFifo( + uartNum, + s_uartInteruptContext[uartNum]->_asyncBuff, + s_uartInteruptContext[uartNum]->_asyncBuffEnd); + + // Disable TX interrupt when done + if (s_uartInteruptContext[uartNum]->_asyncBuff == s_uartInteruptContext[uartNum]->_asyncBuffEnd) + { + // clear the TX FIFO Empty + USIE(uartNum) &= ~(1 << UIFE); + } + + // Clear all interrupts flags (just in case) + USIC(uartNum) = 0xffff; + } + } + } +} + +#endif + diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.h new file mode 100644 index 000000000000..d45436b2439c --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.h @@ -0,0 +1,431 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp8266 UART hardware + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#pragma once + +#ifdef ARDUINO_ARCH_ESP8266 +#include + +// this template method class is used to track the data being sent on the uart +// when using the default serial ISR installed by the core +// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes +// +class NeoEsp8266UartContext +{ +public: + // Gets the number of bytes waiting in the TX FIFO + static inline uint8_t ICACHE_RAM_ATTR GetTxFifoLength(uint8_t uartNum) + { + return (USS(uartNum) >> USTXC) & 0xff; + } + // Append a byte to the TX FIFO + static inline void ICACHE_RAM_ATTR Enqueue(uint8_t uartNum, uint8_t value) + { + USF(uartNum) = value; + } + + static const volatile uint8_t* ICACHE_RAM_ATTR FillUartFifo(uint8_t uartNum, + const volatile uint8_t* pixels, + const volatile uint8_t* end); +}; + +// this template method class is used to track the data being sent on the uart +// when using our own UART ISR +// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes +// +class NeoEsp8266UartInterruptContext : NeoEsp8266UartContext +{ +public: + NeoEsp8266UartInterruptContext() : + _asyncBuff(nullptr), + _asyncBuffEnd(nullptr) + { + } + + bool IsSending() + { + return (_asyncBuff != _asyncBuffEnd); + } + + void StartSending(uint8_t uartNum, uint8_t* start, uint8_t* end); + void Attach(uint8_t uartNum); + void Detach(uint8_t uartNum); + +private: + volatile const uint8_t* _asyncBuff; + volatile const uint8_t* _asyncBuffEnd; + volatile static NeoEsp8266UartInterruptContext* s_uartInteruptContext[2]; + + static void ICACHE_RAM_ATTR Isr(void* param); +}; + +// this template feature class is used a base for all others and contains +// common methods +// +class UartFeatureBase +{ +protected: + static void ConfigUart(uint8_t uartNum) + { + // clear all invert bits + USC0(uartNum) &= ~((1 << UCDTRI) | (1 << UCRTSI) | (1 << UCTXI) | (1 << UCDSRI) | (1 << UCCTSI) | (1 << UCRXI)); + // Invert the TX voltage associated with logic level so: + // - A logic level 0 will generate a Vcc signal + // - A logic level 1 will generate a Gnd signal + USC0(uartNum) |= (1 << UCTXI); + } +}; + +// this template feature class is used to define the specifics for uart0 +// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes +// +class UartFeature0 : UartFeatureBase +{ +public: + static const uint32_t Index = 0; + static void Init(uint32_t baud) + { + // Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1) + Serial.begin(baud, SERIAL_6N1, SERIAL_TX_ONLY); + ConfigUart(Index); + } +}; + +// this template feature class is used to define the specifics for uart1 +// used with NeoEsp8266Uart and NeoEsp8266AsyncUart classes +// +class UartFeature1 : UartFeatureBase +{ +public: + static const uint32_t Index = 1; + static void Init(uint32_t baud) + { + // Configure the serial line with 1 start bit (0), 6 data bits and 1 stop bit (1) + Serial1.begin(baud, SERIAL_6N1, SERIAL_TX_ONLY); + ConfigUart(Index); + } +}; + +// this template method class is used a base for all others and contains +// common properties and methods +// +// used by NeoEsp8266Uart and NeoEsp8266AsyncUart +// +class NeoEsp8266UartBase +{ +protected: + size_t _sizePixels; // Size of '_pixels' buffer below + uint8_t* _pixels; // Holds LED color values + uint32_t _startTime; // Microsecond count when last update started + + NeoEsp8266UartBase(uint16_t pixelCount, size_t elementSize) + { + _sizePixels = pixelCount * elementSize; + _pixels = (uint8_t*)malloc(_sizePixels); + memset(_pixels, 0x00, _sizePixels); + } + + ~NeoEsp8266UartBase() + { + free(_pixels); + } + +}; + +// this template method class is used to glue uart feature and context for +// synchronous uart method +// +// used by NeoEsp8266UartMethodBase +// +template class NeoEsp8266Uart : public NeoEsp8266UartBase +{ +protected: + + NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize) : + NeoEsp8266UartBase(pixelCount, elementSize) + { + } + + ~NeoEsp8266Uart() + { + // Wait until the TX fifo is empty. This way we avoid broken frames + // when destroying & creating a NeoPixelBus to change its length. + while (T_UARTCONTEXT::GetTxFifoLength(T_UARTFEATURE::Index) > 0) + { + yield(); + } + } + + void InitializeUart(uint32_t uartBaud) + { + T_UARTFEATURE::Init(uartBaud); + } + + void UpdateUart(bool) + { + // Since the UART can finish sending queued bytes in the FIFO in + // the background, instead of waiting for the FIFO to flush + // we annotate the start time of the frame so we can calculate + // when it will finish. + _startTime = micros(); + + // Then keep filling the FIFO until done + const uint8_t* ptr = _pixels; + const uint8_t* end = ptr + _sizePixels; + while (ptr != end) + { + ptr = const_cast(T_UARTCONTEXT::FillUartFifo(T_UARTFEATURE::Index, ptr, end)); + } + } +}; + +// this template method class is used to glue uart feature and context for +// asynchronously uart method +// +// This UART controller uses two buffers that are swapped in every call to +// NeoPixelBus.Show(). One buffer contains the data that is being sent +// asynchronosly and another buffer contains the data that will be send +// in the next call to NeoPixelBus.Show(). +// +// Therefore, the result of NeoPixelBus.Pixels() is invalidated after +// every call to NeoPixelBus.Show() and must not be cached. +// +// used by NeoEsp8266UartMethodBase +// +template class NeoEsp8266AsyncUart : public NeoEsp8266UartBase +{ +protected: + NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize) : + NeoEsp8266UartBase(pixelCount, elementSize) + { + _pixelsSending = (uint8_t*)malloc(_sizePixels); + } + + ~NeoEsp8266AsyncUart() + { + // Remember: the UART interrupt can be sending data from _pixelsSending in the background + while (_context.IsSending()) + { + yield(); + } + // detach context, which will disable intr, may disable ISR + _context.Detach(T_UARTFEATURE::Index); + + free(_pixelsSending); + } + + void ICACHE_RAM_ATTR InitializeUart(uint32_t uartBaud) + { + T_UARTFEATURE::Init(uartBaud); + + // attach the context, which will enable the ISR + _context.Attach(T_UARTFEATURE::Index); + } + + void UpdateUart(bool maintainBufferConsistency) + { + // Instruct ESP8266 hardware uart to send the pixels asynchronously + _context.StartSending(T_UARTFEATURE::Index, + _pixels, + _pixels + _sizePixels); + + // Annotate when we started to send bytes, so we can calculate when we are ready to send again + _startTime = micros(); + + if (maintainBufferConsistency) + { + // copy editing to sending, + // this maintains the contract that "colors present before will + // be the same after", otherwise GetPixelColor will be inconsistent + memcpy(_pixelsSending, _pixels, _sizePixels); + } + + // swap so the user can modify without affecting the async operation + std::swap(_pixelsSending, _pixels); + } + +private: + T_UARTCONTEXT _context; + + uint8_t* _pixelsSending; // Holds a copy of LED color values taken when UpdateUart began +}; + +class NeoEsp8266UartSpeed800KbpsBase +{ +public: + static const uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed + static const uint32_t UartBaud = 3200000; // 800mhz, 4 serial bytes per NeoByte +}; + +// NeoEsp8266UartSpeedWs2813 contains the timing constants used to get NeoPixelBus running with the Ws2813 +class NeoEsp8266UartSpeedWs2812x : public NeoEsp8266UartSpeed800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 300; // us between data send bursts to reset for next update +}; + +class NeoEsp8266UartSpeedSk6812 : public NeoEsp8266UartSpeed800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; // us between data send bursts to reset for next update +}; + +// NeoEsp8266UartSpeed800Kbps contains the timing constant used to get NeoPixelBus running at 800Khz +class NeoEsp8266UartSpeed800Kbps : public NeoEsp8266UartSpeed800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update +}; + +// NeoEsp8266UartSpeed400Kbps contains the timing constant used to get NeoPixelBus running at 400Khz +class NeoEsp8266UartSpeed400Kbps +{ +public: + static const uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed + static const uint32_t UartBaud = 1600000; // 400mhz, 4 serial bytes per NeoByte + static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update +}; + +// NeoEsp8266UartSpeedApa106 contains the timing constant used to get NeoPixelBus running for Apa106 +// Pulse cycle = 1.71 = 1.368 longer than normal, 0.731 slower, NeoEsp8266UartSpeedApa1066 +class NeoEsp8266UartSpeedApa106 +{ +public: + static const uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element at 400khz speed + static const uint32_t UartBaud = 2339181; // APA106 pulse cycle of 1.71us, 4 serial bytes per NeoByte + static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update +}; + +// NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that +// implements the methods needed to operate as a NeoPixelBus method. +template +class NeoEsp8266UartMethodBase: public T_BASE +{ +public: + NeoEsp8266UartMethodBase(uint16_t pixelCount, size_t elementSize) + : T_BASE(pixelCount, elementSize) + { + } + NeoEsp8266UartMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) + : T_BASE(pixelCount, elementSize) + { + } + + bool IsReadyToUpdate() const + { + uint32_t delta = micros() - this->_startTime; + return delta >= getPixelTime() + T_SPEED::ResetTimeUs; + } + + void Initialize() + { + this->InitializeUart(T_SPEED::UartBaud); + + // Inverting logic levels can generate a phantom bit in the led strip bus + // We need to delay 50+ microseconds the output stream to force a data + // latch and discard this bit. Otherwise, that bit would be prepended to + // the first frame corrupting it. + this->_startTime = micros() - getPixelTime(); + } + + void Update(bool maintainBufferConsistency) + { + // Data latch = 50+ microsecond pause in the output stream. Rather than + // put a delay at the end of the function, the ending time is noted and + // the function will simply hold off (if needed) on issuing the + // subsequent round of data until the latch time has elapsed. This + // allows the mainline code to start generating the next frame of data + // rather than stalling for the latch. + while (!this->IsReadyToUpdate()) + { + yield(); + } + this->UpdateUart(maintainBufferConsistency); + } + + uint8_t* getPixels() const + { + return this->_pixels; + }; + + size_t getPixelsSize() const + { + return this->_sizePixels; + }; + +private: + uint32_t getPixelTime() const + { + return (T_SPEED::ByteSendTimeUs * this->_sizePixels); + }; +}; + +// uart 0 +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Ws2812xMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0Apa106Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0800KbpsMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart0400KbpsMethod; + +typedef NeoEsp8266Uart0Ws2812xMethod NeoEsp8266Uart0Ws2813Method; +typedef NeoEsp8266Uart0800KbpsMethod NeoEsp8266Uart0Ws2812Method; +typedef NeoEsp8266Uart0Sk6812Method NeoEsp8266Uart0Lc8812Method; + +// uart 1 +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Ws2812xMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1Apa106Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1800KbpsMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266Uart1400KbpsMethod; + +typedef NeoEsp8266Uart1Ws2812xMethod NeoEsp8266Uart1Ws2813Method; +typedef NeoEsp8266Uart1800KbpsMethod NeoEsp8266Uart1Ws2812Method; +typedef NeoEsp8266Uart1Sk6812Method NeoEsp8266Uart1Lc8812Method; + +// uart 0 async +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Ws2812xMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0Apa106Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0800KbpsMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart0400KbpsMethod; + +typedef NeoEsp8266AsyncUart0Ws2812xMethod NeoEsp8266AsyncUart0Ws2813Method; +typedef NeoEsp8266AsyncUart0800KbpsMethod NeoEsp8266AsyncUart0Ws2812Method; +typedef NeoEsp8266AsyncUart0Sk6812Method NeoEsp8266AsyncUart0Lc8812Method; + +// uart 1 async +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Ws2812xMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Sk6812Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1Apa106Method; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1800KbpsMethod; +typedef NeoEsp8266UartMethodBase> NeoEsp8266AsyncUart1400KbpsMethod; + +typedef NeoEsp8266AsyncUart1Ws2812xMethod NeoEsp8266AsyncUart1Ws2813Method; +typedef NeoEsp8266AsyncUart1800KbpsMethod NeoEsp8266AsyncUart1Ws2812Method; +typedef NeoEsp8266AsyncUart1Sk6812Method NeoEsp8266AsyncUart1Lc8812Method; + +#endif + diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoEspBitBangMethod.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEspBitBangMethod.h similarity index 73% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoEspBitBangMethod.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoEspBitBangMethod.h index 499f1c3dab31..361560213f7b 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoEspBitBangMethod.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEspBitBangMethod.h @@ -39,14 +39,24 @@ License along with NeoPixel. If not, see extern "C" void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin); extern "C" void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin); -class NeoEspBitBangSpeedWs2813 +class NeoEspBitBangSpeedWs2812x { public: static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin) { bitbang_send_pixels_800(pixels, end, pin); } - static const uint32_t ResetTimeUs = 250; + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangSpeedSk6812 +{ +public: + static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin) + { + bitbang_send_pixels_800(pixels, end, pin); + } + static const uint32_t ResetTimeUs = 80; }; class NeoEspBitBangSpeed800Kbps @@ -103,7 +113,7 @@ template class NeoEspBitBangMethodBase _endTime = micros(); } - void Update() + void Update(bool) { // Data latch = 50+ microsecond pause in the output stream. Rather than // put a delay at the end of the function, the ending time is noted and @@ -116,11 +126,23 @@ template class NeoEspBitBangMethodBase yield(); // allows for system yield if needed } - noInterrupts(); // Need 100% focus on instruction timing + // Need 100% focus on instruction timing +#if defined(ARDUINO_ARCH_ESP32) + delay(1); // required + portMUX_TYPE updateMux = portMUX_INITIALIZER_UNLOCKED; - T_SPEED::send_pixels(_pixels, _pixels + _sizePixels, _pin); + portENTER_CRITICAL(&updateMux); +#else + noInterrupts(); +#endif + T_SPEED::send_pixels(_pixels, _pixels + _sizePixels, _pin); + +#if defined(ARDUINO_ARCH_ESP32) + portEXIT_CRITICAL(&updateMux); +#else interrupts(); +#endif // save EOD time for latch on next call _endTime = micros(); @@ -146,21 +168,28 @@ template class NeoEspBitBangMethodBase #if defined(ARDUINO_ARCH_ESP32) -typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2813Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangSk6812Method; typedef NeoEspBitBangMethodBase NeoEsp32BitBang800KbpsMethod; typedef NeoEspBitBangMethodBase NeoEsp32BitBang400KbpsMethod; -// Bitbang method is the default method for Esp32 -typedef NeoEsp32BitBangWs2813Method NeoWs2813Method; -typedef NeoEsp32BitBang800KbpsMethod Neo800KbpsMethod; -typedef NeoEsp32BitBang400KbpsMethod Neo400KbpsMethod; +typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; +typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; +typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; +typedef NeoEsp32BitBang400KbpsMethod NeoEsp32BitBangApa106Method; #else -typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2813Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangSk6812Method; typedef NeoEspBitBangMethodBase NeoEsp8266BitBang800KbpsMethod; typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400KbpsMethod; +typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method; +typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method; +typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method; +typedef NeoEsp8266BitBang400KbpsMethod NeoEsp8266BitBangApa106Method; #endif +// ESP bitbang doesn't have defaults and should avoided except for testing #endif \ No newline at end of file diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoGamma.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoGamma.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoGamma.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoGamma.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoGamma.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoGamma.h similarity index 95% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoGamma.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoGamma.h index 9b94e241910f..4aaf68e4a8ce 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoGamma.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoGamma.h @@ -1,5 +1,6 @@ /*------------------------------------------------------------------------- -NeoPixelGamma class is used to correct RGB colors for human eye gamma levels +NeoGamma class is used to correct RGB colors for human eye gamma levels equally +across all color channels Written by Michael C. Miller. diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoHueBlend.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoHueBlend.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoHueBlend.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoHueBlend.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoMosaic.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoMosaic.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoMosaic.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoMosaic.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAnimator.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAnimator.cpp similarity index 84% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAnimator.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAnimator.cpp index db51a5d4a78a..d535316f6f69 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAnimator.cpp +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAnimator.cpp @@ -142,7 +142,7 @@ void NeoPixelAnimator::UpdateAnimations() if (pAnim->_remaining > delta) { param.state = (pAnim->_remaining == pAnim->_duration) ? AnimationState_Started : AnimationState_Progress; - param.progress = (float)(pAnim->_duration - pAnim->_remaining) / (float)pAnim->_duration; + param.progress = pAnim->CurrentProgress(); fnUpdate(param); @@ -164,3 +164,33 @@ void NeoPixelAnimator::UpdateAnimations() } } } + +void NeoPixelAnimator::ChangeAnimationDuration(uint16_t indexAnimation, uint16_t newDuration) +{ + if (indexAnimation >= _countAnimations) + { + return; + } + + AnimationContext* pAnim = &_animations[indexAnimation]; + + // calc the current animation progress + float progress = pAnim->CurrentProgress(); + + // keep progress in range just in case + if (progress < 0.0f) + { + progress = 0.0f; + } + else if (progress > 1.0f) + { + progress = 1.0f; + } + + // change the duration + pAnim->_duration = newDuration; + + // _remaining time must also be reset after a duration change; + // use the progress to recalculate it + pAnim->_remaining = uint16_t(pAnim->_duration * (1.0f - progress)); +} \ No newline at end of file diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAvr.c b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAvr.c similarity index 99% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAvr.c rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAvr.c index 3d057e27acce..761fa7eb102f 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoPixelAvr.c +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelAvr.c @@ -64,7 +64,7 @@ void send_pixels_8mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinM volatile uint8_t lo; // PORT w/output bit set low volatile uint8_t n1; - volatile n2 = 0; // First, next bits out + volatile uint8_t n2 = 0; // First, next bits out // Squeezing an 800 KHz stream out of an 8 MHz chip requires code // specific to each PORT register. At present this is only written @@ -189,7 +189,7 @@ void send_pixels_8mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinM volatile uint8_t lo; // PORT w/output bit set low volatile uint8_t n1; - volatile n2 = 0; // First, next bits out + volatile uint8_t n2 = 0; // First, next bits out // Same as above, just switched to PORTB and stripped of comments. hi = PORTB | pinMask; @@ -645,4 +645,4 @@ void send_pixels_16mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* #error "CPU SPEED NOT SUPPORTED" #endif -#endif \ No newline at end of file +#endif diff --git a/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelEsp.c b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelEsp.c new file mode 100644 index 000000000000..f28a5755ecd6 --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoPixelEsp.c @@ -0,0 +1,169 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp8266 and Esp32. + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + +#include +#if defined(ARDUINO_ARCH_ESP8266) +#include +#endif + +// ESP32 doesn't define ICACHE_RAM_ATTR +#ifndef ICACHE_RAM_ATTR +#define ICACHE_RAM_ATTR IRAM_ATTR +#endif + +static uint32_t _getCycleCount(void) __attribute__((always_inline)); + +static inline uint32_t _getCycleCount(void) +{ + uint32_t ccount; + __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); + return ccount; +} + +#define CYCLES_800_T0H (F_CPU / 2500000) // 0.4us +#define CYCLES_800_T1H (F_CPU / 1250000) // 0.8us +#define CYCLES_800 (F_CPU / 800000) // 1.25us per bit +#define CYCLES_400_T0H (F_CPU / 2000000) +#define CYCLES_400_T1H (F_CPU / 833333) +#define CYCLES_400 (F_CPU / 400000) + +void ICACHE_RAM_ATTR bitbang_send_pixels_800(uint8_t* pixels, uint8_t* end, uint8_t pin) +{ + const uint32_t pinRegister = _BV(pin); + uint8_t mask = 0x80; + uint8_t subpix = *pixels++; + uint32_t cyclesStart = 0; // trigger emediately + uint32_t cyclesNext = 0; + + for (;;) + { + // do the checks here while we are waiting on time to pass + uint32_t cyclesBit = CYCLES_800_T0H; + if (subpix & mask) + { + cyclesBit = CYCLES_800_T1H; + } + + // after we have done as much work as needed for this next bit + // now wait for the HIGH + while (((cyclesStart = _getCycleCount()) - cyclesNext) < CYCLES_800); + + // set high +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1ts = pinRegister; +#else + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); +#endif + + // wait for the LOW + while ((_getCycleCount() - cyclesStart) < cyclesBit); + + // set low +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1tc = pinRegister; +#else + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); +#endif + cyclesNext = cyclesStart; + + // next bit + mask >>= 1; + if (mask == 0) + { + // no more bits to send in this byte + // check for another byte + if (pixels >= end) + { + // no more bytes to send so stop + break; + } + // reset mask to first bit and get the next byte + mask = 0x80; + subpix = *pixels++; + } + } +} + +void ICACHE_RAM_ATTR bitbang_send_pixels_400(uint8_t* pixels, uint8_t* end, uint8_t pin) +{ + const uint32_t pinRegister = _BV(pin); + uint8_t mask = 0x80; + uint8_t subpix = *pixels++; + uint32_t cyclesStart = 0; // trigger emediately + uint32_t cyclesNext = 0; + + for (;;) + { + // do the checks here while we are waiting on time to pass + uint32_t cyclesBit = CYCLES_400_T0H; + if (subpix & mask) + { + cyclesBit = CYCLES_400_T1H; + } + + // after we have done as much work as needed for this next bit + // now wait for the HIGH + while (((cyclesStart = _getCycleCount()) - cyclesNext) < CYCLES_400); + + // set high +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1ts = pinRegister; +#else + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); +#endif + + // wait for the LOW + while ((_getCycleCount() - cyclesStart) < cyclesBit); + + // set low +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1tc = pinRegister; +#else + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); +#endif + cyclesNext = cyclesStart; + + // next bit + mask >>= 1; + if (mask == 0) + { + // no more bits to send in this byte + // check for another byte + if (pixels >= end) + { + // no more bytes to send so stop + break; + } + // reset mask to first bit and get the next byte + mask = 0x80; + subpix = *pixels++; + } + } +} + +#endif diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoRingTopology.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoRingTopology.h similarity index 80% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoRingTopology.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoRingTopology.h index 8e152f8c529e..e598fa462dd4 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoRingTopology.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoRingTopology.h @@ -56,6 +56,33 @@ template class NeoRingTopology : protected T_LAYOUT return _map(ring, pixel); } + uint16_t RingPixelShift(uint8_t ring, uint16_t pixel, int16_t shift) + { + int32_t ringPixel = pixel; + ringPixel += shift; + + if (ringPixel < 0) + { + ringPixel = 0; + } + else + { + uint16_t count = getPixelCountAtRing(ring); + if (ringPixel >= count) + { + ringPixel = count - 1; + } + } + return ringPixel; + } + + uint16_t RingPixelRotate(uint8_t ring, uint16_t pixel, int16_t rotate) + { + int32_t ringPixel = pixel; + ringPixel += rotate; + return ringPixel % getPixelCountAtRing(ring); + } + uint8_t getCountOfRings() const { return _ringCount() - 1; // minus one as the Rings includes the extra value diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoSpriteSheet.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoSpriteSheet.h similarity index 97% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoSpriteSheet.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoSpriteSheet.h index a0f277eb97d7..83fb978d3dbf 100644 --- a/lib/NeoPixelBus-2.2.9/src/internal/NeoSpriteSheet.h +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoSpriteSheet.h @@ -146,15 +146,15 @@ template class NeoVerticalSpriteSheet uint16_t pixelIndex(uint16_t indexSprite, int16_t x, - int16_t y) + int16_t y) const { uint16_t result = PixelIndex_OutOfBounds; if (indexSprite < _spriteCount && x >= 0 && - x < SpriteWidth() && + (uint16_t)x < SpriteWidth() && y >= 0 && - y < SpriteHeight()) + (uint16_t)y < SpriteHeight()) { result = x + y * SpriteWidth() + indexSprite * _spriteHeight * SpriteWidth(); } diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoTiles.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoTiles.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoTiles.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoTiles.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/NeoTopology.h b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoTopology.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/NeoTopology.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/NeoTopology.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/RgbColor.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/RgbColor.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/RgbColor.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/RgbColor.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/RgbColor.h b/lib/NeoPixelBus-2.5.0.09/src/internal/RgbColor.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/RgbColor.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/RgbColor.h diff --git a/lib/NeoPixelBus-2.2.9/src/internal/RgbwColor.cpp b/lib/NeoPixelBus-2.5.0.09/src/internal/RgbwColor.cpp similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/RgbwColor.cpp rename to lib/NeoPixelBus-2.5.0.09/src/internal/RgbwColor.cpp diff --git a/lib/NeoPixelBus-2.2.9/src/internal/RgbwColor.h b/lib/NeoPixelBus-2.5.0.09/src/internal/RgbwColor.h similarity index 100% rename from lib/NeoPixelBus-2.2.9/src/internal/RgbwColor.h rename to lib/NeoPixelBus-2.5.0.09/src/internal/RgbwColor.h diff --git a/lib/TasmotaSerial-2.3.2/README.md b/lib/TasmotaSerial-2.3.3/README.md old mode 100755 new mode 100644 similarity index 100% rename from lib/TasmotaSerial-2.3.2/README.md rename to lib/TasmotaSerial-2.3.3/README.md diff --git a/lib/TasmotaSerial-2.3.2/examples/swsertest/swsertest.ino b/lib/TasmotaSerial-2.3.3/examples/swsertest/swsertest.ino old mode 100755 new mode 100644 similarity index 100% rename from lib/TasmotaSerial-2.3.2/examples/swsertest/swsertest.ino rename to lib/TasmotaSerial-2.3.3/examples/swsertest/swsertest.ino diff --git a/lib/TasmotaSerial-2.3.2/keywords.txt b/lib/TasmotaSerial-2.3.3/keywords.txt old mode 100755 new mode 100644 similarity index 100% rename from lib/TasmotaSerial-2.3.2/keywords.txt rename to lib/TasmotaSerial-2.3.3/keywords.txt diff --git a/lib/TasmotaSerial-2.3.2/library.json b/lib/TasmotaSerial-2.3.3/library.json old mode 100755 new mode 100644 similarity index 94% rename from lib/TasmotaSerial-2.3.2/library.json rename to lib/TasmotaSerial-2.3.3/library.json index b9017bc98ce8..46a55b7dc92d --- a/lib/TasmotaSerial-2.3.2/library.json +++ b/lib/TasmotaSerial-2.3.3/library.json @@ -1,6 +1,6 @@ { "name": "TasmotaSerial", - "version": "2.3.2", + "version": "2.3.3", "keywords": [ "serial", "io", "TasmotaSerial" ], diff --git a/lib/TasmotaSerial-2.3.2/library.properties b/lib/TasmotaSerial-2.3.3/library.properties old mode 100755 new mode 100644 similarity index 94% rename from lib/TasmotaSerial-2.3.2/library.properties rename to lib/TasmotaSerial-2.3.3/library.properties index 1401ae8e3e37..c99402e689ae --- a/lib/TasmotaSerial-2.3.2/library.properties +++ b/lib/TasmotaSerial-2.3.3/library.properties @@ -1,5 +1,5 @@ name=TasmotaSerial -version=2.3.2 +version=2.3.3 author=Theo Arends maintainer=Theo Arends sentence=Implementation of software serial with hardware serial fallback for ESP8266. diff --git a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp b/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp old mode 100755 new mode 100644 similarity index 69% rename from lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp rename to lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp index a6b42bf03f09..88151a8f1bfc --- a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.cpp +++ b/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp @@ -79,10 +79,11 @@ static void (*ISRList[16])() = { TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback, int nwmode, int buffer_size) { m_valid = false; - m_hardserial = 0; - m_hardswap = 0; + m_hardserial = false; + m_hardswap = false; m_stop_bits = 1; m_nwmode = nwmode; + serial_buffer_size = buffer_size; if (!((isValidGPIOpin(receive_pin)) && (isValidGPIOpin(transmit_pin) || transmit_pin == 16))) { return; } @@ -90,11 +91,11 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal m_tx_pin = transmit_pin; m_in_pos = m_out_pos = 0; if (hardware_fallback && (((3 == m_rx_pin) && (1 == m_tx_pin)) || ((3 == m_rx_pin) && (-1 == m_tx_pin)) || ((-1 == m_rx_pin) && (1 == m_tx_pin)))) { - m_hardserial = 1; + m_hardserial = true; } else if ((2 == hardware_fallback) && (((13 == m_rx_pin) && (15 == m_tx_pin)) || ((13 == m_rx_pin) && (-1 == m_tx_pin)) || ((-1 == m_rx_pin) && (15 == m_tx_pin)))) { - m_hardserial = 1; - m_hardswap = 1; + m_hardserial = true; + m_hardswap = true; } else { if (m_rx_pin > -1) { @@ -104,8 +105,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal m_bit_time = ESP.getCpuFreqMHz() * 1000000 / TM_SERIAL_BAUDRATE; pinMode(m_rx_pin, INPUT); tms_obj_list[m_rx_pin] = this; - if (m_nwmode) attachInterrupt(m_rx_pin, ISRList[m_rx_pin], CHANGE); - else attachInterrupt(m_rx_pin, ISRList[m_rx_pin], FALLING); + attachInterrupt(m_rx_pin, ISRList[m_rx_pin], (m_nwmode) ? CHANGE : FALLING); } if (m_tx_pin > -1) { pinMode(m_tx_pin, OUTPUT); @@ -184,7 +184,7 @@ int TasmotaSerial::read() return Serial.read(); } else { if ((-1 == m_rx_pin) || (m_in_pos == m_out_pos)) return -1; - uint8_t ch = m_buffer[m_out_pos]; + uint32_t ch = m_buffer[m_out_pos]; m_out_pos = (m_out_pos +1) % serial_buffer_size; return ch; } @@ -214,19 +214,19 @@ size_t TasmotaSerial::write(uint8_t b) } else { if (-1 == m_tx_pin) return 0; if (m_high_speed) cli(); // Disable interrupts in order to get a clean transmit - unsigned long wait = m_bit_time; + uint32_t wait = m_bit_time; digitalWrite(m_tx_pin, HIGH); - unsigned long start = ESP.getCycleCount(); + uint32_t start = ESP.getCycleCount(); // Start bit; digitalWrite(m_tx_pin, LOW); TM_SERIAL_WAIT; - for (int i = 0; i < 8; i++) { + for (uint32_t i = 0; i < 8; i++) { digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW); TM_SERIAL_WAIT; b >>= 1; } // Stop bit(s) - for (int i = 0; i < m_stop_bits; i++) { + for (uint32_t i = 0; i < m_stop_bits; i++) { digitalWrite(m_tx_pin, HIGH); TM_SERIAL_WAIT; } @@ -242,89 +242,89 @@ void ICACHE_RAM_ATTR TasmotaSerial::rxRead() void TasmotaSerial::rxRead() { #endif -if (!m_nwmode) { - // Advance the starting point for the samples but compensate for the - // initial delay which occurs before the interrupt is delivered - unsigned long wait = m_bit_time + m_bit_time/3 - 500; - unsigned long start = ESP.getCycleCount(); - uint8_t rec = 0; - for (int i = 0; i < 8; i++) { - TM_SERIAL_WAIT; - rec >>= 1; - if (digitalRead(m_rx_pin)) rec |= 0x80; - } - // Stop bit(s) - TM_SERIAL_WAIT; - if (2 == m_stop_bits) { - digitalRead(m_rx_pin); + if (!m_nwmode) { + // Advance the starting point for the samples but compensate for the + // initial delay which occurs before the interrupt is delivered + uint32_t wait = m_bit_time + m_bit_time/3 - 500; + uint32_t start = ESP.getCycleCount(); + uint8_t rec = 0; + for (uint32_t i = 0; i < 8; i++) { + TM_SERIAL_WAIT; + rec >>= 1; + if (digitalRead(m_rx_pin)) rec |= 0x80; + } + // Stop bit(s) TM_SERIAL_WAIT; - } - // Store the received value in the buffer unless we have an overflow - unsigned int next = (m_in_pos+1) % serial_buffer_size; - if (next != (int)m_out_pos) { - m_buffer[m_in_pos] = rec; - m_in_pos = next; - } - // Must clear this bit in the interrupt register, - // it gets set even when interrupts are disabled - GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rx_pin); -} else { - uint8_t diff; - uint8_t level; + if (2 == m_stop_bits) { + digitalRead(m_rx_pin); + TM_SERIAL_WAIT; + } + // Store the received value in the buffer unless we have an overflow + uint32_t next = (m_in_pos+1) % serial_buffer_size; + if (next != (int)m_out_pos) { + m_buffer[m_in_pos] = rec; + m_in_pos = next; + } + // Must clear this bit in the interrupt register, + // it gets set even when interrupts are disabled + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rx_pin); + } else { + uint32_t diff; + uint32_t level; - #define LASTBIT 9 + #define LASTBIT 9 - GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rx_pin); + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rx_pin); - level=digitalRead(m_rx_pin); + level = digitalRead(m_rx_pin); - if (!level && !ss_index) { - // start condition - ss_bstart=ESP.getCycleCount()-(m_bit_time/4); - ss_byte=0; - ss_index++; - //digitalWrite(1, LOW); - } else { - // now any bit changes go here - // calc bit number - diff=(ESP.getCycleCount()-ss_bstart)/m_bit_time; - //digitalWrite(1, level); + if (!level && !ss_index) { + // start condition + ss_bstart = ESP.getCycleCount() - (m_bit_time / 4); + ss_byte = 0; + ss_index++; + //digitalWrite(1, LOW); + } else { + // now any bit changes go here + // calc bit number + diff = (ESP.getCycleCount() - ss_bstart) / m_bit_time; + //digitalWrite(1, level); - if (!level && diff>LASTBIT) { - // start bit of next byte, store and restart - // leave irq at change - for (uint8_t i=ss_index;i<=LASTBIT;i++) { - ss_byte|=(1<ss_byte>>1); - unsigned int next = (m_in_pos+1) % serial_buffer_size; - if (next != (int)m_out_pos) { - m_buffer[m_in_pos] = ss_byte>>1; - m_in_pos = next; - } + if (!level && diff > LASTBIT) { + // start bit of next byte, store and restart + // leave irq at change + for (uint32_t i = ss_index; i <= LASTBIT; i++) { + ss_byte |= (1 << i); + } + //stobyte(0,ssp->ss_byte>>1); + uint32_t next = (m_in_pos + 1) % serial_buffer_size; + if (next != (uint32_t)m_out_pos) { + m_buffer[m_in_pos] = ss_byte >> 1; + m_in_pos = next; + } - ss_bstart=ESP.getCycleCount()-(m_bit_time/4); - ss_byte=0; - ss_index=1; - return; - } - if (diff>=LASTBIT) { - // bit zero was 0, - //stobyte(0,ssp->ss_byte>>1); - unsigned int next = (m_in_pos+1) % serial_buffer_size; - if (next != (int)m_out_pos) { - m_buffer[m_in_pos] = ss_byte>>1; - m_in_pos = next; + ss_bstart = ESP.getCycleCount() - (m_bit_time / 4); + ss_byte = 0; + ss_index = 1; + return; } - ss_byte=0; - ss_index=0; - } else { - // shift in - for (uint8_t i=ss_index;i= LASTBIT) { + // bit zero was 0, + //stobyte(0,ssp->ss_byte>>1); + uint32_t next = (m_in_pos + 1) % serial_buffer_size; + if (next != (uint32_t)m_out_pos) { + m_buffer[m_in_pos] = ss_byte >> 1; + m_in_pos = next; + } + ss_byte = 0; + ss_index = 0; + } else { + // shift in + for (uint32_t i = ss_index; i < diff; i++) { + if (!level) ss_byte |= (1 << i); + } + ss_index = diff; } - ss_index=diff; } } } -} diff --git a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h b/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h old mode 100755 new mode 100644 similarity index 85% rename from lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h rename to lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h index 57adb9e26c0d..8c6340977990 --- a/lib/TasmotaSerial-2.3.2/src/TasmotaSerial.h +++ b/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h @@ -20,7 +20,7 @@ #ifndef TasmotaSerial_h #define TasmotaSerial_h /*********************************************************************************************\ - * TasmotaSerial supports up to 115200 baud with fixed buffer size of 64 bytes using optional no iram + * TasmotaSerial supports up to 115200 baud with default buffer size of 64 bytes using optional no iram * * Based on EspSoftwareSerial v3.4.3 by Peter Lerup (https://github.com/plerup/espsoftwareserial) \*********************************************************************************************/ @@ -38,7 +38,7 @@ class TasmotaSerial : public Stream { public: - TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0,int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE); + TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0, int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE); virtual ~TasmotaSerial(); bool begin(long speed, int stop_bits = 1); @@ -60,22 +60,22 @@ class TasmotaSerial : public Stream { size_t txWrite(uint8_t byte); // Member variables + int m_rx_pin; + int m_tx_pin; + uint32_t m_stop_bits; + uint32_t ss_byte; + uint32_t ss_bstart; + uint32_t ss_index; + uint32_t m_bit_time; + uint32_t m_in_pos; + uint32_t m_out_pos; + uint32_t serial_buffer_size; bool m_valid; bool m_nwmode; bool m_hardserial; bool m_hardswap; bool m_high_speed; - int m_rx_pin; - int m_tx_pin; - int m_stop_bits; - int ss_byte; - unsigned long ss_bstart; - int ss_index; - unsigned long m_bit_time; - unsigned int m_in_pos; - unsigned int m_out_pos; uint8_t *m_buffer; - int serial_buffer_size; }; #endif // TasmotaSerial_h diff --git a/platformio.ini b/platformio.ini index b92cf42eee12..d19018416164 100755 --- a/platformio.ini +++ b/platformio.ini @@ -13,12 +13,14 @@ build_dir = .pioenvs ; *** Uncomment one of the lines below to build/upload only one environment ;default_envs = sonoff +;default_envs = sonoff-ircustom ; alternative to 'sonoff' with full IR protocols activated, you will need to disable some features to keep code not too big ;default_envs = sonoff-minimal ;default_envs = sonoff-basic ;default_envs = sonoff-classic ;default_envs = sonoff-knx ;default_envs = sonoff-sensors ;default_envs = sonoff-display +;default_envs = sonoff-ir ;default_envs = sonoff-BG ;default_envs = sonoff-BR ;default_envs = sonoff-CN @@ -200,6 +202,8 @@ build_flags = ${core_active.build_flags} ; -DFIRMWARE_BASIC ; -DFIRMWARE_KNX_NO_EMULATION ; -DFIRMWARE_DISPLAYS +; -DFIRMWARE_IR +; -DFIRMWARE_IR_CUSTOM ; -DUSE_CONFIG_OVERRIDE ; *** Fix espressif8266@1.7.0 induced undesired all warnings @@ -325,6 +329,34 @@ upload_resetmethod = ${common.upload_resetmethod} upload_speed = ${common.upload_speed} extra_scripts = ${common.extra_scripts} +[env:sonoff-ir] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board} +board_build.flash_mode = ${common.board_build.flash_mode} +board_build.f_cpu = ${common.board_build.f_cpu} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags} -DUSE_IR_REMOTE_FULL -DFIRMWARE_IR +monitor_speed = ${common.monitor_speed} +upload_port = ${common.upload_port} +upload_resetmethod = ${common.upload_resetmethod} +upload_speed = ${common.upload_speed} +extra_scripts = ${common.extra_scripts} + +[env:sonoff-ircustom] +platform = ${common.platform} +framework = ${common.framework} +board = ${common.board} +board_build.flash_mode = ${common.board_build.flash_mode} +board_build.f_cpu = ${common.board_build.f_cpu} +build_unflags = ${common.build_unflags} +build_flags = ${common.build_flags} -DUSE_IR_REMOTE_FULL +monitor_speed = ${common.monitor_speed} +upload_port = ${common.upload_port} +upload_resetmethod = ${common.upload_resetmethod} +upload_speed = ${common.upload_speed} +extra_scripts = ${common.extra_scripts} + [env:sonoff-BG] platform = ${common.platform} framework = ${common.framework} diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index d2bdd4751aa6..4de80cebe712 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,18 @@ /*********************************************************************************************\ + * 6.6.0.10 20190905 + * Redesign Tuya support by Shantur Rathore (#6353) + * Add command Reset 99 to reset bootcount to zero (#684, #6351) + * * 6.6.0.9 20190828 * Change theoretical baudrate range to 300..19660500 bps in 300 increments (#6294) + * Add Full support of all protocols in IRremoteESP8266, to be used on dedicated-IR Tasmota version. Warning: +81k Flash when compiling with USE_IR_REMOTE_FULL + * Add compile time define USE_WS2812_HARDWARE to select hardware type WS2812, WS2812X, WS2813, SK6812, LC8812 or APA106 (DMA mode only) + * Add 'sonoff-ir' pre-packaged IR-dedicated firmware and 'sonoff-ircustom' to customize firmware with IR Full protocol support + * Add Zigbee support phase 2 - cc2530 initialization and basic ZCL decoding + * Add driver USE_SDM120_2 with Domoticz P1 Smart Meter functionality as future replacement for USE_SDM120 - Pls test and report + * Add command Power0 0/1/2/Off/On/Toggle to control all power outputs at once (#6340) + * Add time to more events (#6337) + * Add command Time 1/2/3 to select JSON time format ISO + Epoch, ISO or Epoch * * 6.6.0.8 20190827 * Add Tuya Energy monitoring by Shantur Rathore diff --git a/sonoff/i18n.h b/sonoff/i18n.h index cb68dcd4c5bc..287476dd70a9 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -61,8 +61,8 @@ #define D_JSON_ERASE "Erase" #define D_JSON_ERROR "Error" #define D_JSON_EVERY "Every" -#define D_JSON_EXPORT_ACTIVE "ExportActivePower" -#define D_JSON_EXPORT_REACTIVE "ExportReactivePower" +#define D_JSON_EXPORT_ACTIVE "ExportActive" +#define D_JSON_EXPORT_REACTIVE "ExportReactive" #define D_JSON_FAILED "Failed" #define D_JSON_FALLBACKTOPIC "FallbackTopic" #define D_JSON_FEATURES "Features" @@ -86,8 +86,8 @@ #define D_JSON_I2CSCAN_NO_DEVICES_FOUND "No devices found" #define D_JSON_ID "Id" #define D_JSON_ILLUMINANCE "Illuminance" -#define D_JSON_IMPORT_ACTIVE "ImportActivePower" -#define D_JSON_IMPORT_REACTIVE "ImportReactivePower" +#define D_JSON_IMPORT_ACTIVE "ImportActive" +#define D_JSON_IMPORT_REACTIVE "ImportReactive" #define D_JSON_INFRARED "Infrared" #define D_JSON_UNKNOWN "Unknown" #define D_JSON_LIGHT "Light" @@ -148,7 +148,7 @@ #define D_JSON_TODAY "Today" #define D_JSON_TOTAL "Total" #define D_JSON_TOTAL_USAGE "TotalUsage" -#define D_JSON_TOTAL_REACTIVE "TotalReactivePower" +#define D_JSON_TOTAL_REACTIVE "TotalReactive" #define D_JSON_TOTAL_START_TIME "TotalStartTime" #define D_JSON_TVOC "TVOC" #define D_JSON_TYPE "Type" @@ -382,14 +382,29 @@ #define D_JSON_IR_PROTOCOL "Protocol" #define D_JSON_IR_BITS "Bits" #define D_JSON_IR_DATA "Data" + #define D_JSON_IR_DATALSB "DataLSB" #define D_JSON_IR_RAWDATA "RawData" #define D_JSON_IR_REPEAT "Repeat" #define D_CMND_IRHVAC "IRHVAC" - #define D_JSON_IRHVAC_VENDOR "VENDOR" - #define D_JSON_IRHVAC_POWER "POWER" - #define D_JSON_IRHVAC_MODE "MODE" - #define D_JSON_IRHVAC_FANSPEED "FANSPEED" - #define D_JSON_IRHVAC_TEMP "TEMP" + #define D_JSON_IRHVAC_VENDOR "Vendor" + #define D_JSON_IRHVAC_PROTOCOL "Protocol" + #define D_JSON_IRHVAC_MODEL "Model" + #define D_JSON_IRHVAC_POWER "Power" + #define D_JSON_IRHVAC_MODE "Mode" + #define D_JSON_IRHVAC_FANSPEED "FanSpeed" + #define D_JSON_IRHVAC_TEMP "Temp" + #define D_JSON_IRHVAC_CELSIUS "Celsius" + #define D_JSON_IRHVAC_SWINGV "SwingV" + #define D_JSON_IRHVAC_SWINGH "SwingH" + #define D_JSON_IRHVAC_LIGHT "Light" + #define D_JSON_IRHVAC_BEEP "Beep" + #define D_JSON_IRHVAC_ECONO "Econo" + #define D_JSON_IRHVAC_FILTER "Filter" + #define D_JSON_IRHVAC_TURBO "Turbo" + #define D_JSON_IRHVAC_QUIET "Quiet" + #define D_JSON_IRHVAC_CLEAN "Clean" + #define D_JSON_IRHVAC_SLEEP "Sleep" + #define D_JSON_IRHVAC_CLOCK "Clock" #define D_JSON_IRRECEIVED "IrReceived" // Commands xdrv_06_snfbridge.ino @@ -429,6 +444,16 @@ #define D_CMND_LATITUDE "Latitude" #define D_CMND_LONGITUDE "Longitude" +// Commands xdrv_16_tuyadimmer.ino + +#define D_CMND_TUYA_MCU "TuyaMCU" + +// Commands xdrv_23_zigbee.ino +#define D_CMND_ZIGBEEZNPSEND "ZigbeeZNPSend" + #define D_JSON_ZIGBEEZNPRECEIVED "ZigbeeZNPReceived" + #define D_JSON_ZIGBEEZNPSENT "ZigbeeZNPSent" + #define D_JSON_ZIGBEEZCLRECEIVED "ZigbeeZCLReceived" + #define D_JSON_ZIGBEEZCLSENT "ZigbeeZCLSent" /********************************************************************************************/ #define D_ASTERISK_PWD "****" @@ -559,7 +584,7 @@ const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = { D_STAT, D_TELE }; -const char kCodeImage[] PROGMEM = "sonoff|minimal|classic|sensors|knx|basic|display"; +const char kCodeImage[] PROGMEM = "sonoff|minimal|classic|sensors|knx|basic|display|ir"; // support.ino static const char kMonthNames[] = D_MONTH3LIST; diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 8e180a6f693a..a18adc7b774e 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -307,7 +307,7 @@ // -- Optional modules ---------------------------- #define USE_BUZZER // Add support for a buzzer (+0k6 code) #define USE_SONOFF_IFAN // Add support for Sonoff iFan02 and iFan03 (+2k code) -#define USE_TUYA_DIMMER // Add support for Tuya Serial Dimmer +#define USE_TUYA_MCU // Add support for Tuya Serial MCU #define TUYA_DIMMER_ID 0 // Default dimmer Id #define USE_ARMTRONIX_DIMMERS // Add support for Armtronix Dimmers (+1k4 code) #define USE_PS_16_DZ // Add support for PS-16-DZ Dimmer and Sonoff L1 (+2k code) @@ -429,8 +429,9 @@ #define USE_PZEM_AC // Add support for PZEM014,016 Energy monitor (+1k1 code) #define USE_PZEM_DC // Add support for PZEM003,017 Energy monitor (+1k1 code) #define USE_MCP39F501 // Add support for MCP39F501 Energy monitor as used in Shelly 2 (+3k1 code) +//#define USE_SDM120_2 // Add support for Eastron SDM120-Modbus energy meter (+1k4 code) -//#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+1k7 code) +//#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+2k4 code) #define SDM120_SPEED 2400 // SDM120-Modbus RS485 serial speed (default: 2400 baud) #define USE_SDM220 // Add extra parameters for SDM220 (+0k1 code) //#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy meter (+2k code) @@ -449,7 +450,17 @@ #define MAX31865_REF_RES 430 // Reference resistor (Usually 430Ω for a PT100, 4300Ω for a PT1000) #define MAX31865_PTD_BIAS 0 // To calibrate your not-so-good PTD -// -- IR Remote features -------------------------- +// -- IR Remote features - all protocols from IRremoteESP8266 -------------------------- +// IR Full Protocols mode is activated through platform.io only. +// Either use 'default_envs = sonoff-ircustom' and disable some features here to keep code not too big +// or use 'default_envs = sonoff-ir' for a pre-packaged IR-dedicated firmware +// When using 'sonoff-ircustom' or 'sonoff-ir', parameters below +// (USE_IR_REMOTE, USE_IR_RECEIVE, USE_IR_HVAC...) are IGNORED. +// +// Code impact of IR full protocols is +81k code, 3k mem +// You can reduce this size by disabling some protocols in "lib/IRremoteESP8266.x.x.x/src/IRremoteESP8266.h" + +// -- IR Remote features - subset of IR protocols -------------------------- #define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k3 code, 0k3 mem, 48 iram) // #define USE_IR_SEND_AIWA // Support IRsend Aiwa protocol #define USE_IR_SEND_DISH // Support IRsend Dish protocol @@ -481,12 +492,19 @@ // -- Zigbee interface ---------------------------- //#define USE_ZIGBEE // Enable serial communication with Zigbee CC2530 flashed with ZNP + #define USE_ZIGBEE_PANID 0x1A63 // arbitrary PAN ID for Zigbee network, must be unique in the home + #define USE_ZIGBEE_EXTPANID 0xCCCCCCCCCCCCCCCCL // arbitrary extended PAN ID + #define USE_ZIGBEE_CHANNEL 0x00000800 // Zigbee Channel (11) + #define USE_ZIGBEE_PRECFGKEY_L 0x0F0D0B0907050301L // note: changing requires to re-pair all devices + #define USE_ZIGBEE_PRECFGKEY_H 0x0D0C0A0806040200L // note: changing requires to re-pair all devices + #define USE_ZIGBEE_PERMIT_JOIN false // don't allow joining by default // ------------------------------------------------ #define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // - #define USE_WS2812_CTYPE NEO_GRB // WS2812 Color type (NEO_RGB, NEO_GRB, NEO_BRG, NEO_RBG, NEO_RGBW, NEO_GRBW) // #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem). When USE_WS2812_DMA is enabled expect Exceptions on Pow + #define USE_WS2812_HARDWARE NEO_HW_WS2812 // Hardware type (NEO_HW_WS2812, NEO_HW_WS2812X, NEO_HW_WS2813, NEO_HW_SK6812, NEO_HW_LC8812, NEO_HW_APA106) + #define USE_WS2812_CTYPE NEO_GRB // Color type (NEO_RGB, NEO_GRB, NEO_BRG, NEO_RBG, NEO_RGBW, NEO_GRBW) #define USE_ARILUX_RF // Add support for Arilux RF remote controller (+0k8 code, 252 iram (non 2.3.0)) @@ -530,12 +548,18 @@ //#define FIRMWARE_SENSORS // Create sonoff-sensors with useful sensors enabled //#define FIRMWARE_KNX_NO_EMULATION // Create sonoff-knx with KNX but without Emulation //#define FIRMWARE_DISPLAYS // Create sonoff-display with display drivers enabled +//#define FIRMWARE_IR // Create sonoff-ir with IR full protocols activated, and many sensors disabled +//#define FIRMWARE_IR_CUSTOM // Create sonoff customizable with special marker to add all IR protocols //#define FIRMWARE_MINIMAL // Create sonoff-minimal as intermediate firmware for OTA-MAGIC /*********************************************************************************************\ * No user configurable items below \*********************************************************************************************/ +#ifdef USE_CONFIG_OVERRIDE + #include "user_config_override.h" // Configuration overrides for my_user_config.h +#endif + #if defined(USE_DISCOVERY) && defined(USE_MQTT_AWS_IOT) #error "Select either USE_DISCOVERY or USE_MQTT_AWS_IOT, mDNS takes too much code space and is not needed for AWS IoT" #endif diff --git a/sonoff/settings.h b/sonoff/settings.h index 20b3202b6ba8..1746b9d3f9b5 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -105,8 +105,7 @@ typedef union { uint32_t spare01 : 1; uint32_t spare02 : 1; uint32_t spare03 : 1; - uint32_t spare04 : 1; - uint32_t spare05 : 1; + uint32_t time_format : 2; // (v6.6.0.9) - CMND_TIME uint32_t calc_resolution : 3; uint32_t weight_resolution : 2; uint32_t frequency_resolution : 2; @@ -186,6 +185,14 @@ typedef struct { uint32_t last_return_kWhtotal; } EnergyUsage; + +typedef struct { + uint8_t fnid = 0; + uint8_t dpid = 0; +} TuyaFnidDpidMap; + +const uint8_t MAX_TUYA_FUNCTIONS = 16; + /* struct SYSCFG { unsigned long cfg_holder; // 000 Pre v6 header @@ -364,13 +371,13 @@ struct SYSCFG { unsigned long energy_frequency_calibration; // 7C8 also used by HX711 to save last weight uint16_t web_refresh; // 7CC char mems[MAX_RULE_MEMS][10]; // 7CE - char rules[MAX_RULE_SETS][MAX_RULE_SIZE]; // 800 uses 512 bytes in v5.12.0m, 3 x 512 bytes in v5.14.0b - uint8_t data8[32]; // E00 - uint16_t data16[16]; // E20 + char rules[MAX_RULE_SETS][MAX_RULE_SIZE]; // 800 uses 512 bytes in v5.12.0m, 3 x 512 bytes in v5.14.0b + TuyaFnidDpidMap tuya_fnid_map[MAX_TUYA_FUNCTIONS]; // E00 32 bytes - uint8_t free_e20[448]; // E40 + uint8_t free_e20[472]; // E20 - // FFF last location + uint32_t cfg_timestamp; // FF8 + uint32_t cfg_crc4; // FFC } Settings; struct RTCRBT { diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 4bdae99ff0c4..12227c578703 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -1096,6 +1096,41 @@ void SettingsDelta(void) Settings.sbaudrate = Settings.ex_sbaudrate * 4; } + if (Settings.version < 0x0606000A) { + uint8_t tuyaindex = 0; + if (Settings.param[P_ex_TUYA_DIMMER_ID] > 0) { // ex SetOption34 + Settings.tuya_fnid_map[tuyaindex].fnid = 21; // TUYA_MCU_FUNC_DIMMER - Move Tuya Dimmer Id to Map + Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_DIMMER_ID]; + tuyaindex++; + } else if (Settings.flag3.tuya_disable_dimmer == 1) { // ex SetOption65 + Settings.tuya_fnid_map[tuyaindex].fnid = 11; // TUYA_MCU_FUNC_REL1 - Create FnID for Switches + Settings.tuya_fnid_map[tuyaindex].dpid = 1; + tuyaindex++; + } + if (Settings.param[P_ex_TUYA_RELAYS] > 0) { + for (uint8_t i = 0 ; i < Settings.param[P_ex_TUYA_RELAYS]; i++) { // ex SetOption41 + Settings.tuya_fnid_map[tuyaindex].fnid = 12 + i; // TUYA_MCU_FUNC_REL2 - Create FnID for Switches + Settings.tuya_fnid_map[tuyaindex].dpid = i + 2; + tuyaindex++; + } + } + if (Settings.param[P_ex_TUYA_POWER_ID] > 0) { // ex SetOption46 + Settings.tuya_fnid_map[tuyaindex].fnid = 31; // TUYA_MCU_FUNC_POWER - Move Tuya Power Id to Map + Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_POWER_ID]; + tuyaindex++; + } + if (Settings.param[P_ex_TUYA_VOLTAGE_ID] > 0) { // ex SetOption44 + Settings.tuya_fnid_map[tuyaindex].fnid = 33; // TUYA_MCU_FUNC_VOLTAGE - Move Tuya Voltage Id to Map + Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_VOLTAGE_ID]; + tuyaindex++; + } + if (Settings.param[P_ex_TUYA_CURRENT_ID] > 0) { // ex SetOption45 + Settings.tuya_fnid_map[tuyaindex].fnid = 32; // TUYA_MCU_FUNC_CURRENT - Move Tuya Current Id to Map + Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_CURRENT_ID]; + tuyaindex++; + } + + } Settings.version = VERSION; SettingsSave(1); } diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 818a42408f99..228765a00d3d 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -113,6 +113,7 @@ const uint16_t SERIALLOG_TIMER = 600; // Seconds to disable SerialLog const uint8_t OTA_ATTEMPTS = 5; // Number of times to try fetching the new firmware const uint16_t INPUT_BUFFER_SIZE = 520; // Max number of characters in (serial and http) command buffer +const uint16_t FLOATSZ = 33; // Max number of characters in float result from dtostrfd const uint16_t CMDSZ = 24; // Max number of characters in command const uint16_t TOPSZ = 100; // Max number of characters in topic string const uint16_t LOGSZ = 520; // Max number of characters in log @@ -172,6 +173,13 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to #define RGB_REMAP_BRGW 48 #define RGB_REMAP_BGRW 54 +#define NEO_HW_WS2812 0 // NeoPixelBus hardware WS2812 +#define NEO_HW_WS2812X 1 // NeoPixelBus hardware WS2812x like WS2812b +#define NEO_HW_WS2813 1 // NeoPixelBus hardware WS2813 +#define NEO_HW_SK6812 2 // NeoPixelBus hardware SK6812 +#define NEO_HW_LC8812 2 // NeoPixelBus hardware LC8812 +#define NEO_HW_APA106 3 // NeoPixelBus hardware APA106 + #define MQTT_PUBSUBCLIENT 1 // Mqtt PubSubClient library #define MQTT_TASMOTAMQTT 2 // Mqtt TasmotaMqtt library based on esp-mqtt-arduino - soon obsolete #define MQTT_ESPMQTTARDUINO 3 // Mqtt esp-mqtt-arduino library by Ingo Randolf - obsolete but define is present for debugging purposes @@ -223,7 +231,11 @@ enum EmulationOptions {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; enum TopicOptions { CMND, STAT, TELE, nu1, RESULT_OR_CMND, RESULT_OR_STAT, RESULT_OR_TELE }; -enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, power_nu1, POWER_OFF_NO_STATE, POWER_ON_NO_STATE, power_nu2, POWER_SHOW_STATE }; +enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, + POWER_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE, + POWER_SHOW_STATE = 16 }; +enum SendKeyPowerOptions { POWER_HOLD = 3, CLEAR_RETAIN = 9 }; +enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH }; enum PowerOnStateOptions { POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON }; @@ -231,9 +243,9 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParamIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, // SetOption32 .. SetOption38 - P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42 - P_TUYA_DIMMER_MAX, P_TUYA_VOLTAGE_ID, P_TUYA_CURRENT_ID, P_TUYA_POWER_ID, // SetOption43 .. SetOption46 +enum SettingsParamIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_ex_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, // SetOption32 .. SetOption38 + P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_ex_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42 + P_TUYA_DIMMER_MAX, P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 P_ENERGY_TARIFF1, P_ENERGY_TARIFF2, // SetOption47 .. SetOption48 P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 @@ -254,7 +266,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_SENSOR, FUNC_COMMAND, FUNC_COMMAND_SENSOR, FUNC_COMMAND_DRIVER, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, - FUNC_ENERGY_EVERY_SECOND, + FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET, FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 922bd18d52d2..f6641e5ce18f 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -30,9 +30,6 @@ #include "sonoff_version.h" // Sonoff-Tasmota version information #include "sonoff.h" // Enumeration used in my_user_config.h #include "my_user_config.h" // Fixed user configurable options -#ifdef USE_CONFIG_OVERRIDE - #include "user_config_override.h" // Configuration overrides for my_user_config.h -#endif #ifdef USE_MQTT_TLS #include // we need to include before "sonoff_post.h" to take precedence over the BearSSL version in Arduino #endif // USE_MQTT_TLS @@ -93,6 +90,7 @@ unsigned long pulse_timer[MAX_PULSETIMERS] = { 0 }; // Power off timer unsigned long blink_timer = 0; // Power cycle timer unsigned long backlog_delay = 0; // Command backlog delay power_t power = 0; // Current copy of Settings.power +power_t last_power = 0; // Last power set state power_t blink_power; // Blink power state power_t blink_mask = 0; // Blink relay active mask power_t blink_powersave; // Blink start power save state @@ -175,7 +173,7 @@ String backlog[MAX_BACKLOG]; // Command backlog char* Format(char* output, const char* input, int size) { char *token; - uint8_t digits = 0; + uint32_t digits = 0; if (strstr(input, "%") != nullptr) { strlcpy(output, input, size); @@ -204,7 +202,9 @@ char* Format(char* output, const char* input, int size) } } } - if (!digits) { strlcpy(output, input, size); } + if (!digits) { + strlcpy(output, input, size); + } return output; } @@ -222,7 +222,7 @@ char* GetOtaUrl(char *otaurl, size_t otaurl_size) return otaurl; } -char* GetTopic_P(char *stopic, uint8_t prefix, char *topic, const char* subtopic) +char* GetTopic_P(char *stopic, uint32_t prefix, char *topic, const char* subtopic) { /* prefix 0 = Cmnd prefix 1 = Stat @@ -261,25 +261,29 @@ char* GetTopic_P(char *stopic, uint8_t prefix, char *topic, const char* subtopic } fulltopic.replace(F("#"), ""); fulltopic.replace(F("//"), "/"); - if (!fulltopic.endsWith("/")) fulltopic += "/"; + if (!fulltopic.endsWith("/")) { + fulltopic += "/"; + } snprintf_P(stopic, TOPSZ, PSTR("%s%s"), fulltopic.c_str(), romram); return stopic; } -char* GetFallbackTopic_P(char *stopic, uint8_t prefix, const char* subtopic) +char* GetFallbackTopic_P(char *stopic, uint32_t prefix, const char* subtopic) { return GetTopic_P(stopic, prefix +4, nullptr, subtopic); } -char* GetStateText(uint8_t state) +char* GetStateText(uint32_t state) { - if (state > 3) { state = 1; } + if (state > 3) { + state = 1; + } return Settings.state_text[state]; } /********************************************************************************************/ -void SetLatchingRelay(power_t lpower, uint8_t state) +void SetLatchingRelay(power_t lpower, uint32_t state) { // power xx00 - toggle REL1 (Off) and REL3 (Off) - device 1 Off, device 2 Off // power xx01 - toggle REL2 (On) and REL3 (Off) - device 1 On, device 2 Off @@ -292,17 +296,15 @@ void SetLatchingRelay(power_t lpower, uint8_t state) } for (uint32_t i = 0; i < devices_present; i++) { - uint8_t port = (i << 1) + ((latching_power >> i) &1); + uint32_t port = (i << 1) + ((latching_power >> i) &1); if (pin[GPIO_REL1 +port] < 99) { digitalWrite(pin[GPIO_REL1 +port], bitRead(rel_inverted, port) ? !state : state); } } } -void SetDevicePower(power_t rpower, int source) +void SetDevicePower(power_t rpower, uint32_t source) { - uint8_t state; - ShowSource(source); if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) { // All on and stay on @@ -313,9 +315,11 @@ void SetDevicePower(power_t rpower, int source) if (Settings.flag.interlock) { // Allow only one or no relay set for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) { power_t mask = 1; - uint8_t count = 0; + uint32_t count = 0; for (uint32_t j = 0; j < devices_present; j++) { - if ((Settings.interlock[i] & mask) && (rpower & mask)) { count++; } + if ((Settings.interlock[i] & mask) && (rpower & mask)) { + count++; + } mask <<= 1; } if (count > 1) { @@ -326,6 +330,10 @@ void SetDevicePower(power_t rpower, int source) } } + if (rpower) { // Any power set + last_power = rpower; + } + XdrvMailbox.index = rpower; XdrvCall(FUNC_SET_POWER); // Signal power state @@ -347,7 +355,7 @@ void SetDevicePower(power_t rpower, int source) } else { for (uint32_t i = 0; i < devices_present; i++) { - state = rpower &1; + power_t state = rpower &1; if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) { digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? !state : state); } @@ -356,13 +364,59 @@ void SetDevicePower(power_t rpower, int source) } } -void SetLedPowerIdx(uint8_t led, uint8_t state) +void RestorePower(bool publish_power, uint32_t source) +{ + if (power != last_power) { + SetDevicePower(last_power, source); + if (publish_power) { + MqttPublishAllPowerState(); + } + } +} + +void SetAllPower(uint32_t state, uint32_t source) +{ +// state 0 = POWER_OFF = Relay Off +// state 1 = POWER_ON = Relay On (turn off after Settings.pulse_timer * 100 mSec if enabled) +// state 2 = POWER_TOGGLE = Toggle relay +// state 8 = POWER_OFF_NO_STATE = Relay Off and no publishPowerState +// state 9 = POWER_ON_NO_STATE = Relay On and no publishPowerState +// state 10 = POWER_TOGGLE_NO_STATE = Toggle relay and no publishPowerState +// state 16 = POWER_SHOW_STATE = Show power state + + bool publish_power = true; + if ((state >= POWER_OFF_NO_STATE) && (state <= POWER_TOGGLE_NO_STATE)) { + state &= 3; // POWER_OFF, POWER_ON or POWER_TOGGLE + publish_power = false; + } + if ((state >= POWER_OFF) && (state <= POWER_TOGGLE)) { + power_t all_on = (1 << devices_present) -1; + switch (state) { + case POWER_OFF: + power = 0; + break; + case POWER_ON: + power = all_on; + break; + case POWER_TOGGLE: + power ^= all_on; // Complement current state + } + SetDevicePower(power, source); + } + if (publish_power) { + MqttPublishAllPowerState(); + } +} + +void SetLedPowerIdx(uint32_t led, uint32_t state) { - if ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present - if (pin[GPIO_LED2] < 99) { led = 1; } + if ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present + if (pin[GPIO_LED2] < 99) { + led = 1; + } } if (pin[GPIO_LED1 + led] < 99) { - uint8_t mask = 1 << led; + uint32_t mask = 1 << led; if (state) { state = 1; led_power |= mask; @@ -373,13 +427,13 @@ void SetLedPowerIdx(uint8_t led, uint8_t state) } } -void SetLedPower(uint8_t state) +void SetLedPower(uint32_t state) { - if (99 == pin[GPIO_LEDLNK]) { // Legacy - Only use LED1 and/or LED2 + if (99 == pin[GPIO_LEDLNK]) { // Legacy - Only use LED1 and/or LED2 SetLedPowerIdx(0, state); } else { power_t mask = 1; - for (uint32_t i = 0; i < leds_present; i++) { // Map leds to power + for (uint32_t i = 0; i < leds_present; i++) { // Map leds to power bool tstate = (power & mask); SetLedPowerIdx(i, tstate); mask <<= 1; @@ -387,18 +441,18 @@ void SetLedPower(uint8_t state) } } -void SetLedPowerAll(uint8_t state) +void SetLedPowerAll(uint32_t state) { for (uint32_t i = 0; i < leds_present; i++) { SetLedPowerIdx(i, state); } } -void SetLedLink(uint8_t state) +void SetLedLink(uint32_t state) { - uint8_t led_pin = pin[GPIO_LEDLNK]; - uint8_t led_inv = ledlnk_inverted; - if (99 == led_pin) { // Legacy - LED1 is status + uint32_t led_pin = pin[GPIO_LEDLNK]; + uint32_t led_inv = ledlnk_inverted; + if (99 == led_pin) { // Legacy - LED1 is status led_pin = pin[GPIO_LED1]; led_inv = bitRead(led_inverted, 0); } @@ -408,34 +462,32 @@ void SetLedLink(uint8_t state) } } -void SetPulseTimer(uint8_t index, uint16_t time) +void SetPulseTimer(uint32_t index, uint32_t time) { pulse_timer[index] = (time > 111) ? millis() + (1000 * (time - 100)) : (time > 0) ? millis() + (100 * time) : 0L; } -uint16_t GetPulseTimer(uint8_t index) +uint32_t GetPulseTimer(uint32_t index) { - uint16_t result = 0; - long time = TimePassedSince(pulse_timer[index]); if (time < 0) { time *= -1; - result = (time > 11100) ? (time / 1000) + 100 : (time > 0) ? time / 100 : 0; + return (time > 11100) ? (time / 1000) + 100 : (time > 0) ? time / 100 : 0; } - return result; + return 0; } /********************************************************************************************/ -bool SendKey(uint8_t key, uint8_t device, uint8_t state) +bool SendKey(uint32_t key, uint32_t device, uint32_t state) { -// key 0 = button_topic -// key 1 = switch_topic -// state 0 = off -// state 1 = on -// state 2 = toggle -// state 3 = hold -// state 9 = clear retain flag +// key 0 = KEY_BUTTON = button_topic +// key 1 = KEY_SWITCH = switch_topic +// state 0 = POWER_OFF = off +// state 1 = POWER_ON = on +// state 2 = POWER_TOGGLE = toggle +// state 3 = POWER_HOLD = hold +// state 9 = CLEAR_RETAIN = clear retain flag char stopic[TOPSZ]; char scommand[CMDSZ]; @@ -445,23 +497,25 @@ bool SendKey(uint8_t key, uint8_t device, uint8_t state) char *tmp = (key) ? Settings.switch_topic : Settings.button_topic; Format(key_topic, tmp, sizeof(key_topic)); if (Settings.flag.mqtt_enabled && MqttIsConnected() && (strlen(key_topic) != 0) && strcmp(key_topic, "0")) { - if (!key && (device > devices_present)) { device = 1; } // Only allow number of buttons up to number of devices + if (!key && (device > devices_present)) { + device = 1; // Only allow number of buttons up to number of devices + } GetTopic_P(stopic, CMND, key_topic, GetPowerDevice(scommand, device, sizeof(scommand), (key + Settings.flag.device_index_enable))); // cmnd/switchtopic/POWERx - if (9 == state) { + if (CLEAR_RETAIN == state) { mqtt_data[0] = '\0'; } else { - if ((Settings.flag3.button_switch_force_local || !strcmp(mqtt_topic, key_topic) || !strcmp(Settings.mqtt_grptopic, key_topic)) && (2 == state)) { - state = ~(power >> (device -1)) &1; + if ((Settings.flag3.button_switch_force_local || !strcmp(mqtt_topic, key_topic) || !strcmp(Settings.mqtt_grptopic, key_topic)) && (POWER_TOGGLE == state)) { + state = ~(power >> (device -1)) &1; // POWER_OFF or POWER_ON } snprintf_P(mqtt_data, sizeof(mqtt_data), GetStateText(state)); } #ifdef USE_DOMOTICZ if (!(DomoticzSendKey(key, device, state, strlen(mqtt_data)))) { - MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != 3 || !Settings.flag3.no_hold_retain)); + MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != POWER_HOLD || !Settings.flag3.no_hold_retain)); } #else - MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != 3 || !Settings.flag3.no_hold_retain)); + MqttPublishDirect(stopic, ((key) ? Settings.flag.mqtt_switch_retain : Settings.flag.mqtt_button_retain) && (state != POWER_HOLD || !Settings.flag3.no_hold_retain)); #endif // USE_DOMOTICZ result = !Settings.flag3.button_switch_force_local; } else { @@ -474,17 +528,18 @@ bool SendKey(uint8_t key, uint8_t device, uint8_t state) return result; } -void ExecuteCommandPower(uint8_t device, uint8_t state, int source) +void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source) { // device = Relay number 1 and up -// state 0 = Relay Off -// state 1 = Relay On (turn off after Settings.pulse_timer * 100 mSec if enabled) -// state 2 = Toggle relay -// state 3 = Blink relay -// state 4 = Stop blinking relay -// state 6 = Relay Off and no publishPowerState -// state 7 = Relay On and no publishPowerState -// state 9 = Show power state +// state 0 = POWER_OFF = Relay Off +// state 1 = POWER_ON = Relay On (turn off after Settings.pulse_timer * 100 mSec if enabled) +// state 2 = POWER_TOGGLE = Toggle relay +// state 3 = POWER_BLINK = Blink relay +// state 4 = POWER_BLINK_STOP = Stop blinking relay +// state 8 = POWER_OFF_NO_STATE = Relay Off and no publishPowerState +// state 9 = POWER_ON_NO_STATE = Relay On and no publishPowerState +// state 10 = POWER_TOGGLE_NO_STATE = Toggle relay and no publishPowerState +// state 16 = POWER_SHOW_STATE = Show power state // ShowSource(source); @@ -498,16 +553,20 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source) } #endif // USE_SONOFF_IFAN - uint8_t publish_power = 1; - if ((POWER_OFF_NO_STATE == state) || (POWER_ON_NO_STATE == state)) { - state &= 1; - publish_power = 0; + bool publish_power = true; + if ((state >= POWER_OFF_NO_STATE) && (state <= POWER_TOGGLE_NO_STATE)) { + state &= 3; // POWER_OFF, POWER_ON or POWER_TOGGLE + publish_power = false; } - if ((device < 1) || (device > devices_present)) device = 1; + if ((device < 1) || (device > devices_present)) { + device = 1; + } active_device = device; - if (device <= MAX_PULSETIMERS) { SetPulseTimer(device -1, 0); } + if (device <= MAX_PULSETIMERS) { + SetPulseTimer(device -1, 0); + } power_t mask = 1 << (device -1); // Device to control if (state <= POWER_TOGGLE) { if ((blink_mask & mask)) { @@ -549,7 +608,9 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source) #ifdef USE_KNX KnxUpdatePowerState(device, power); #endif // USE_KNX - if (publish_power && Settings.flag3.hass_tele_on_power) { MqttPublishTeleState(); } + if (publish_power && Settings.flag3.hass_tele_on_power) { + MqttPublishTeleState(); + } if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0); } @@ -566,13 +627,17 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source) return; } else if (POWER_BLINK_STOP == state) { - uint8_t flag = (blink_mask & mask); + bool flag = (blink_mask & mask); blink_mask &= (POWER_MASK ^ mask); // Clear device mask MqttPublishPowerBlinkState(device); - if (flag) ExecuteCommandPower(device, (blink_powersave >> (device -1))&1, SRC_IGNORE); // Restore state + if (flag) { + ExecuteCommandPower(device, (blink_powersave >> (device -1))&1, SRC_IGNORE); // Restore state + } return; } - if (publish_power) MqttPublishPowerState(device); + if (publish_power) { + MqttPublishPowerState(device); + } } void StopAllPowerBlink(void) @@ -589,18 +654,6 @@ void StopAllPowerBlink(void) } } -void SetAllPower(uint8_t state, int source) -{ - if ((POWER_ALL_OFF == state) || (POWER_ALL_ON == state)) { - power = 0; - if (POWER_ALL_ON == state) { - power = (1 << devices_present) -1; - } - SetDevicePower(power, source); - MqttPublishAllPowerState(); - } -} - void MqttShowPWMState(void) { ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{")); @@ -682,6 +735,11 @@ bool MqttShowSensor(void) } } XsnsCall(FUNC_JSON_APPEND); + +#ifdef USE_SCRIPT_JSON_EXPORT + XdrvCall(FUNC_JSON_APPEND); +#endif + bool json_data_available = (strlen(mqtt_data) - json_data_start); if (strstr_P(mqtt_data, PSTR(D_JSON_PRESSURE)) != nullptr) { ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str()); @@ -822,7 +880,7 @@ void Every250mSeconds(void) { // As the max amount of sleep = 250 mSec this loop should always be taken... - uint8_t blinkinterval = 1; + uint32_t blinkinterval = 1; state_250mS++; state_250mS &= 0x3; @@ -1176,7 +1234,7 @@ void SerialInput(void) if (Settings.flag.mqtt_serial && serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed char hex_char[(serial_in_byte_counter * 2) + 2]; - Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), + ResponseTime_P(PSTR(",\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), (Settings.flag.mqtt_serial_raw) ? ToHex_P((unsigned char*)serial_in_buffer, serial_in_byte_counter, hex_char, sizeof(hex_char)) : serial_in_buffer); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED)); XdrvRulesProcess(); @@ -1188,10 +1246,10 @@ void SerialInput(void) void GpioInit(void) { - uint8_t mpin; + uint32_t mpin; if (!ValidModule(Settings.module)) { - uint8_t module = MODULE; + uint32_t module = MODULE; if (!ValidModule(MODULE)) { module = SONOFF_BASIC; } Settings.module = module; Settings.last_module = module; @@ -1228,7 +1286,7 @@ void GpioInit(void) my_adc0 = Settings.my_adc0; // Set User selected Module sensors } my_module_flag = ModuleFlag(); - uint8_t template_adc0 = my_module_flag.data &15; + uint32_t template_adc0 = my_module_flag.data &15; if ((template_adc0 > ADC0_NONE) && (template_adc0 < ADC0_USER)) { my_adc0 = template_adc0; // Force Template override } @@ -1602,8 +1660,6 @@ void setup(void) XsnsCall(FUNC_INIT); } -uint32_t _counter = 0; - void loop(void) { uint32_t my_sleep = millis(); diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 01076e0354b3..271325da1db3 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -85,7 +85,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c // -- Optional modules ------------------------- #define USE_SONOFF_IFAN // Add support for Sonoff iFan02 and iFan03 (+2k code) -#define USE_TUYA_DIMMER // Add support for Tuya Serial Dimmer +#define USE_TUYA_MCU // Add support for Tuya Serial MCU #ifndef TUYA_DIMMER_ID #define TUYA_DIMMER_ID 0 // Default dimmer Id #endif @@ -217,7 +217,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c //#ifndef USE_SONOFF_IFAN #define USE_SONOFF_IFAN // Add support for Sonoff iFan02 and iFan03 (+2k code) //#endif -#undef USE_TUYA_DIMMER // Disable support for Tuya Serial Dimmer +#undef USE_TUYA_MCU // Disable support for Tuya Serial MCU #undef USE_ARMTRONIX_DIMMERS // Disable support for Armtronix Dimmers (+1k4 code) #undef USE_PS_16_DZ // Disable support for PS-16-DZ Dimmer and Sonoff L1 (+2k code) #undef ROTARY_V1 // Disable support for MI Desk Lamp @@ -242,6 +242,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_PZEM_AC // Disable PZEM014,016 Energy monitor #undef USE_PZEM_DC // Disable PZEM003,017 Energy monitor #undef USE_MCP39F501 // Disable support for MCP39F501 Energy monitor as used in Shelly 2 (+3k1 code) +#undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI #undef USE_IR_REMOTE // Disable IR remote commands using library IRremoteESP8266 and ArduinoJson @@ -317,6 +318,81 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_RF_FLASH // Remove support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB (-3k code) #endif // FIRMWARE_DISPLAYS +/*********************************************************************************************\ + * [sonoff-ir.bin] + * Provide a dedicated image with IR full protocol support, with limited additional features +\*********************************************************************************************/ + +#ifdef FIRMWARE_IR + +#undef CODE_IMAGE +#define CODE_IMAGE 7 + +#undef USE_EMULATION_HUE // disable Hue emulation - only for lights and relays +#undef USE_EMULATION_WEMO // disable Wemo emulation - only for relays +#undef USE_EMULATION + +//#undef USE_DOMOTICZ // Disable Domoticz +//#undef USE_HOME_ASSISTANT // Disable Home Assistant +//#undef USE_KNX // Disable KNX IP Protocol Support +//#undef USE_CUSTOM // Disable Custom features +//#undef USE_TIMERS // Disable support for up to 16 timers +//#undef USE_TIMERS_WEB // Disable support for timer webpage +//#undef USE_SUNRISE // Disable support for Sunrise and sunset tools +//#undef USE_RULES // Disable support for rules +#undef USE_DISCOVERY // Disable mDNS for the following services (+8k code or +23.5k code with core 2_5_x, +0.3k mem) + +// -- Optional modules ------------------------- +#undef USE_BUZZER // Disable support for a buzzer (+0k6 code) +#undef USE_SONOFF_IFAN // Disable support for Sonoff iFan02 and iFan03 (+2k code) +#undef USE_TUYA_MCU // Disable support for Tuya Serial MCU +#undef USE_ARMTRONIX_DIMMERS // Disable support for Armtronix Dimmers (+1k4 code) +#undef USE_PS_16_DZ // Disable support for PS-16-DZ Dimmer and Sonoff L1 (+2k code) +#undef USE_DS18x20 // Disable Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code) + +#undef USE_I2C // Disable all I2C sensors +#undef USE_SPI // Disable all SPI devices + +#undef USE_MHZ19 // Disable support for MH-Z19 CO2 sensor +#undef USE_SENSEAIR // Disable support for SenseAir K30, K70 and S8 CO2 sensor +#undef USE_PMS5003 // Disable support for PMS5003 and PMS7003 particle concentration sensor +#undef USE_NOVA_SDS // Disable support for SDS011 and SDS021 particle concentration sensor +#undef USE_SERIAL_BRIDGE // Disable support for software Serial Bridge +#undef USE_SDM120 // Disable support for Eastron SDM120-Modbus energy meter +#undef USE_SDM630 // Disable support for Eastron SDM630-Modbus energy meter +#undef USE_MP3_PLAYER // Disable DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop +#undef USE_AZ7798 // Disable support for AZ-Instrument 7798 CO2 datalogger +#undef USE_PN532_HSU // Disable support for PN532 using HSU (Serial) interface (+1k8 code, 140 bytes mem) +#undef USE_RDM6300 // Disable support for RDM6300 125kHz RFID Reader (+0k8) +#undef USE_IBEACON // Disable support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) + +#undef USE_ENERGY_SENSOR // Disable Use energy sensors (+14k code) +#undef USE_ENERGY_MARGIN_DETECTION // Disable support for Energy Margin detection (+1k6 code) +#undef USE_PZEM004T // Disable PZEM004T energy sensor +#undef USE_PZEM_AC // Disable PZEM014,016 Energy monitor +#undef USE_PZEM_DC // Disable PZEM003,017 Energy monitor +#undef USE_MCP39F501 // Disable support for MCP39F501 Energy monitor as used in Shelly 2 (+3k1 code) +#undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter +//#define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor +#undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI +#undef USE_WS2812 // Disable WS2812 Led string using library NeoPixelBus (+5k code, +1k mem, 232 iram) - Disable by // +#undef USE_ARILUX_RF // Disable support for Arilux RF remote controller +#undef USE_SR04 // Disable support for for HC-SR04 ultrasonic devices +#undef USE_TM1638 // Disable support for TM1638 switches copying Switch1 .. Switch8 +#undef USE_HX711 // Disable support for HX711 load cell +#undef USE_RF_FLASH // Disable support for flashing the EFM8BB1 chip on the Sonoff RF Bridge. C2CK must be connected to GPIO4, C2D to GPIO5 on the PCB +#undef USE_TX20_WIND_SENSOR // Disable support for La Crosse TX20 anemometer +#undef USE_RC_SWITCH // Disable support for RF transceiver using library RcSwitch +#undef USE_RF_SENSOR // Disable support for RF sensor receiver (434MHz or 868MHz) (+0k8 code) +#undef USE_SM16716 // Disable support for SM16716 RGB LED controller (+0k7 code) +#undef USE_HRE // Disable support for Badger HR-E Water Meter (+1k4 code) +#undef DEBUG_THEO // Disable debug code +#undef USE_DEBUG_DRIVER // Disable debug code + +//#undef USE_LIGHT // Also disable all Dimmer/Light support + +#endif // FIRMWARE_IR + /*********************************************************************************************\ * Mandatory define for DS18x20 if changed by above image selections \*********************************************************************************************/ @@ -360,7 +436,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c // -- Optional modules ------------------------- #define USE_SONOFF_IFAN // Add support for Sonoff iFan02 and iFan03 (+2k code) -//#undef USE_TUYA_DIMMER // Disable support for Tuya Serial Dimmer +//#undef USE_TUYA_MCU // Disable support for Tuya Serial MCU #undef USE_ARMTRONIX_DIMMERS // Disable support for Armtronix Dimmers (+1k4 code) #undef USE_PS_16_DZ // Disable support for PS-16-DZ Dimmer and Sonoff L1 (+2k code) #undef ROTARY_V1 // Disable support for MI Desk Lamp @@ -391,6 +467,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c //#undef USE_MCP39F501 // Disable MCP39F501 Energy monitor as used in Shelly 2 #undef USE_DHT // Disable support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI +#undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_IR_REMOTE // Disable IR driver #undef USE_WS2812 // Disable WS2812 Led string #undef USE_ARILUX_RF // Disable support for Arilux RF remote controller @@ -440,7 +517,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c // -- Optional modules ------------------------- #undef USE_SONOFF_IFAN // Disable support for Sonoff iFan02 and iFan03 (+2k code) -#undef USE_TUYA_DIMMER // Disable support for Tuya Serial Dimmer +#undef USE_TUYA_MCU // Disable support for Tuya Serial MCU #undef USE_ARMTRONIX_DIMMERS // Disable support for Armtronix Dimmers (+1k4 code) #undef USE_PS_16_DZ // Disable support for PS-16-DZ Dimmer and Sonoff L1 (+2k code) #undef ROTARY_V1 // Disable support for MI Desk Lamp @@ -469,6 +546,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_PZEM_AC // Disable PZEM014,016 Energy monitor #undef USE_PZEM_DC // Disable PZEM003,017 Energy monitor #undef USE_MCP39F501 // Disable MCP39F501 Energy monitor as used in Shelly 2 +#undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_DHT // Disable support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI #undef USE_IR_REMOTE // Disable IR driver diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index f83f488ad60f..cdfe75e232bd 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -524,15 +524,36 @@ const uint8_t kGpioNiceList[] PROGMEM = { #if defined(USE_DS18B20) || defined(USE_DS18x20) || defined(USE_DS18x20_LEGACY) GPIO_DSB, // Single wire DS18B20 or DS18S20 #endif -#if defined(USE_LIGHT) && defined(USE_WS2812) + +// Light +#ifdef USE_LIGHT +#ifdef USE_WS2812 GPIO_WS2812, // WS2812 Led string #endif -#ifdef USE_IR_REMOTE +#ifdef USE_ARILUX_RF + GPIO_ARIRFRCV, // AriLux RF Receive input + GPIO_ARIRFSEL, // Arilux RF Receive input selected +#endif + GPIO_DI, // my92x1 PWM input + GPIO_DCKI, // my92x1 CLK input +#ifdef USE_SM16716 + GPIO_SM16716_CLK, // SM16716 CLOCK + GPIO_SM16716_DAT, // SM16716 DATA + GPIO_SM16716_SEL, // SM16716 SELECT +#endif // USE_SM16716 +#ifdef USE_TUYA_MCU + GPIO_TUYA_TX, // Tuya Serial interface + GPIO_TUYA_RX, // Tuya Serial interface +#endif +#endif // USE_LIGHT + +#if defined(USE_IR_REMOTE) || defined(USE_IR_REMOTE_FULL) GPIO_IRSEND, // IR remote -#ifdef USE_IR_RECEIVE +#if defined(USE_IR_RECEIVE) || defined(USE_IR_REMOTE_FULL) GPIO_IRRECV, // IR receiver #endif #endif + #ifdef USE_RC_SWITCH GPIO_RFSEND, // RF transmitter GPIO_RFRECV, // RF receiver @@ -553,19 +574,22 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_HX711_SCK, // HX711 Load Cell clock GPIO_HX711_DAT, // HX711 Load Cell data #endif -#if defined(USE_ENERGY_SENSOR) && defined(USE_HLW8012) + +// Energy sensors +#ifdef USE_ENERGY_SENSOR +#ifdef USE_HLW8012 GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current GPIO_HLW_CF, // HLW8012 CF power GPIO_HJL_CF, // HJL-01/BL0937 CF power #endif -#if defined(USE_ENERGY_SENSOR) && defined(USE_I2C) && defined(USE_ADE7953) +#if defined(USE_I2C) && defined(USE_ADE7953) GPIO_ADE7953_IRQ, // ADE7953 IRQ #endif GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) -#if defined(USE_ENERGY_SENSOR) && defined(USE_MCP39F501) +#ifdef USE_MCP39F501 GPIO_MCP39F5_TX, // MCP39F501 Serial interface (Shelly2) GPIO_MCP39F5_RX, // MCP39F501 Serial interface (Shelly2) GPIO_MCP39F5_RST, // MCP39F501 Reset (Shelly2) @@ -582,14 +606,26 @@ const uint8_t kGpioNiceList[] PROGMEM = { #ifdef USE_PZEM_DC GPIO_PZEM017_RX, // PZEM-003,017 Serial Modbus interface #endif +#ifdef USE_SDM120_2 + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface +#endif +#endif // USE_ENERGY_SENSOR +#ifndef USE_SDM120_2 #ifdef USE_SDM120 GPIO_SDM120_TX, // SDM120 Serial interface GPIO_SDM120_RX, // SDM120 Serial interface #endif +#endif // USE_SDM120_2 #ifdef USE_SDM630 GPIO_SDM630_TX, // SDM630 Serial interface GPIO_SDM630_RX, // SDM630 Serial interface #endif +#ifdef USE_SOLAX_X1 + GPIO_SOLAXX1_TX, // Solax Inverter tx pin + GPIO_SOLAXX1_RX, // Solax Inverter rx pin +#endif + #ifdef USE_SERIAL_BRIDGE GPIO_SBR_TX, // Serial Bridge Serial interface GPIO_SBR_RX, // Serial Bridge Serial interface @@ -619,10 +655,6 @@ const uint8_t kGpioNiceList[] PROGMEM = { #ifdef USE_MP3_PLAYER GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface #endif -#if defined(USE_LIGHT) && defined(USE_TUYA_DIMMER) - GPIO_TUYA_TX, // Tuya Serial interface - GPIO_TUYA_RX, // Tuya Serial interface -#endif #ifdef USE_AZ7798 GPIO_AZ_TXD, // AZ-Instrument 7798 CO2 datalogger Serial interface GPIO_AZ_RXD, // AZ-Instrument 7798 CO2 datalogger Serial interface @@ -647,33 +679,16 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_MAX31855CLK, // MAX31855 Serial interface GPIO_MAX31855DO, // MAX31855 Serial interface #endif -#ifdef USE_LIGHT - GPIO_DI, // my92x1 PWM input - GPIO_DCKI, // my92x1 CLK input -#ifdef USE_SM16716 - GPIO_SM16716_CLK, // SM16716 CLOCK - GPIO_SM16716_DAT, // SM16716 DATA - GPIO_SM16716_SEL, // SM16716 SELECT -#endif // USE_SM16716 -#endif // USE_LIGHT #ifdef ROTARY_V1 GPIO_ROT1A, // Rotary switch1 A Pin GPIO_ROT1B, // Rotary switch1 B Pin GPIO_ROT2A, // Rotary switch2 A Pin GPIO_ROT2B, // Rotary switch2 B Pin #endif -#ifdef USE_ARILUX_RF - GPIO_ARIRFRCV, // AriLux RF Receive input - GPIO_ARIRFSEL, // Arilux RF Receive input selected -#endif #ifdef USE_HRE GPIO_HRE_CLOCK, GPIO_HRE_DATA, #endif -#ifdef USE_SOLAX_X1 - GPIO_SOLAXX1_TX, // Solax Inverter tx pin - GPIO_SOLAXX1_RX, // Solax Inverter rx pin -#endif }; const uint8_t kModuleNiceList[] PROGMEM = { @@ -734,7 +749,7 @@ const uint8_t kModuleNiceList[] PROGMEM = { OBI2, MANZOKU_EU_4, ESP_SWITCH, // Switch Devices -#ifdef USE_TUYA_DIMMER +#ifdef USE_TUYA_MCU TUYA_DIMMER, // Dimmer Devices #endif #ifdef USE_ARMTRONIX_DIMMERS @@ -1713,7 +1728,7 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_REL1, // GPIO14 Relay SRU 5VDC SDA (0 = Off, 1 = On ) 0, 0, 0 }, - { "Tuya Dimmer", // Tuya Dimmer (ESP8266 w/ separate MCU dimmer) + { "Tuya MCU", // Tuya MCU device (ESP8266 w/ separate MCU) // https://www.amazon.com/gp/product/B07CTNSZZ8/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 GPIO_USER, // Virtual Button (controlled by MCU) GPIO_USER, // GPIO01 MCU serial control diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index e614fbf360d3..962434a63473 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,6 +20,6 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -const uint32_t VERSION = 0x06060009; +const uint32_t VERSION = 0x0606000A; #endif // _SONOFF_VERSION_H_ diff --git a/sonoff/support.ino b/sonoff/support.ino index 4ada71ad2711..e6707510e6e6 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -870,7 +870,24 @@ uint32_t WebColor(uint32_t i) * Response data handling \*********************************************************************************************/ -int Response_P(const char* format, ...) // Content send snprintf_P char data +const uint16_t TIMESZ = 100; // Max number of characters in time string + +char* ResponseGetTime(uint32_t format, char* time_str) +{ + switch (format) { + case 1: + snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); + break; + case 2: + snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":%u"), UtcTime()); + break; + default: + snprintf_P(time_str, TIMESZ, PSTR("{\"" D_JSON_TIME "\":\"%s\",\"Epoch\":%u"), GetDateAndTime(DT_LOCAL).c_str(), UtcTime()); + } + return time_str; +} + +int Response_P(const char* format, ...) // Content send snprintf_P char data { // This uses char strings. Be aware of sending %% if % is needed va_list args; @@ -880,6 +897,20 @@ int Response_P(const char* format, ...) // Content send snprintf_P char data return len; } +int ResponseTime_P(const char* format, ...) // Content send snprintf_P char data +{ + // This uses char strings. Be aware of sending %% if % is needed + va_list args; + va_start(args, format); + + ResponseGetTime(Settings.flag2.time_format, mqtt_data); + + int mlen = strlen(mqtt_data); + int len = vsnprintf_P(mqtt_data + mlen, sizeof(mqtt_data) - mlen, format, args); + va_end(args); + return len + mlen; +} + int ResponseAppend_P(const char* format, ...) // Content send snprintf_P char data { // This uses char strings. Be aware of sending %% if % is needed @@ -891,15 +922,15 @@ int ResponseAppend_P(const char* format, ...) // Content send snprintf_P char d return len + mlen; } -int ResponseAppendTime(void) +int ResponseAppendTimeFormat(uint32_t format) { - return ResponseAppend_P(PSTR("{\"" D_JSON_TIME "\":\"%s\",\"Epoch\":%u"), GetDateAndTime(DT_LOCAL).c_str(), UtcTime()); + char time_str[TIMESZ]; + return ResponseAppend_P(ResponseGetTime(format, time_str)); } -int ResponseBeginTime(void) +int ResponseAppendTime(void) { - mqtt_data[0] = '\0'; - return ResponseAppendTime(); + return ResponseAppendTimeFormat(Settings.flag2.time_format); } int ResponseJsonEnd(void) diff --git a/sonoff/support_button.ino b/sonoff/support_button.ino index c32011b42db2..5c8db5d09b12 100644 --- a/sonoff/support_button.ino +++ b/sonoff/support_button.ino @@ -165,7 +165,7 @@ void ButtonHandler(void) if (!Button.hold_timer[button_index]) { button_pressed = true; } // Do not allow within 1 second } if (button_pressed) { - if (!SendKey(0, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set + if (!SendKey(KEY_BUTTON, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set ExecuteCommandPower(button_index +1, POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally } } @@ -174,7 +174,7 @@ void ButtonHandler(void) if ((PRESSED == button) && (NOT_PRESSED == Button.last_state[button_index])) { if (Settings.flag.button_single) { // SetOption13 (0) - Allow only single button press for immediate action AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_IMMEDIATE), button_index +1); - if (!SendKey(0, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set + if (!SendKey(KEY_BUTTON, button_index +1, POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set ExecuteCommandPower(button_index +1, POWER_TOGGLE, SRC_BUTTON); // Execute Toggle command internally } } else { @@ -199,14 +199,14 @@ void ButtonHandler(void) if (Settings.flag.button_restrict) { // SetOption1 (0) - Button restriction if (Settings.param[P_HOLD_IGNORE] > 0) { // SetOption40 (0) - Do not ignore button hold if (Button.hold_timer[button_index] > loops_per_second * Settings.param[P_HOLD_IGNORE] / 10) { - Button.hold_timer[button_index] = 0; // Reset button hold counter to stay below hold trigger - Button.press_counter[button_index] = 0; // Discard button press to disable functionality + Button.hold_timer[button_index] = 0; // Reset button hold counter to stay below hold trigger + Button.press_counter[button_index] = 0; // Discard button press to disable functionality DEBUG_CORE_LOG(PSTR("BTN: " D_BUTTON "%d cancel by " D_CMND_SETOPTION "40 %d"), button_index +1, Settings.param[P_HOLD_IGNORE]); } } if (Button.hold_timer[button_index] == loops_per_second * Settings.param[P_HOLD_TIME] / 10) { // SetOption32 (40) - Button hold Button.press_counter[button_index] = 0; - SendKey(0, button_index +1, 3); // Execute Hold command via MQTT if ButtonTopic is set + SendKey(KEY_BUTTON, button_index +1, POWER_HOLD); // Execute Hold command via MQTT if ButtonTopic is set } } else { if (Button.hold_timer[button_index] == loops_per_second * hold_time_extent * Settings.param[P_HOLD_TIME] / 10) { // SetOption32 (40) - Button held for factor times longer @@ -241,7 +241,7 @@ void ButtonHandler(void) #if defined(USE_LIGHT) && defined(ROTARY_V1) if (!((0 == button_index) && RotaryButtonPressed())) { #endif - if (single_press && SendKey(0, button_index + Button.press_counter[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set + if (single_press && SendKey(KEY_BUTTON, button_index + Button.press_counter[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set // Success } else { if (Button.press_counter[button_index] < 3) { // Single or Double press diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 5d6d265f6db7..a1bedea89e69 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -257,11 +257,20 @@ void CmndDelay(void) void CmndPower(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= devices_present)) { - if ((XdrvMailbox.payload < 0) || (XdrvMailbox.payload > 4)) { XdrvMailbox.payload = 9; } -// Settings.flag.device_index_enable = user_index; + if ((XdrvMailbox.payload < POWER_OFF) || (XdrvMailbox.payload > POWER_BLINK_STOP)) { + XdrvMailbox.payload = POWER_SHOW_STATE; + } +// Settings.flag.device_index_enable = XdrvMailbox.usridx; ExecuteCommandPower(XdrvMailbox.index, XdrvMailbox.payload, SRC_IGNORE); mqtt_data[0] = '\0'; } + else if (0 == XdrvMailbox.index) { + if ((XdrvMailbox.payload < POWER_OFF) || (XdrvMailbox.payload > POWER_TOGGLE)) { + XdrvMailbox.payload = POWER_SHOW_STATE; + } + SetAllPower(XdrvMailbox.payload, SRC_IGNORE); + mqtt_data[0] = '\0'; + } } void CmndStatus(void) @@ -635,7 +644,7 @@ void CmndSetoption(void) param_low = 1; param_high = 250; break; - case P_TUYA_RELAYS: + case P_ex_TUYA_RELAYS: param_high = 8; break; } @@ -647,16 +656,16 @@ void CmndSetoption(void) LightUpdateColorMapping(); break; #endif -#if defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE) +#if (defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE)) || defined(USE_IR_REMOTE_FULL) case P_IR_UNKNOW_THRESHOLD: IrReceiveUpdateThreshold(); break; #endif -#ifdef USE_TUYA_DIMMER - case P_TUYA_RELAYS: - case P_TUYA_POWER_ID: - case P_TUYA_CURRENT_ID: - case P_TUYA_VOLTAGE_ID: +#ifdef USE_TUYA_MCU +// case P_ex_TUYA_RELAYS: +// case P_ex_TUYA_POWER_ID: +// case P_ex_TUYA_CURRENT_ID: +// case P_ex_TUYA_VOLTAGE_ID: case P_TUYA_DIMMER_MAX: restart_flag = 2; // Need a restart to update GUI break; @@ -1260,6 +1269,10 @@ void CmndReset(void) restart_flag = 210 + XdrvMailbox.payload; Response_P(PSTR("{\"" D_CMND_RESET "\":\"" D_JSON_ERASE ", " D_JSON_RESET_AND_RESTARTING "\"}")); break; + case 99: + Settings.bootcount = 0; + ResponseCmndDone(); + break; default: ResponseCmndChar(D_JSON_ONE_TO_RESET); } @@ -1267,10 +1280,25 @@ void CmndReset(void) void CmndTime(void) { +// payload 0 = (re-)enable NTP +// payload 1 = Time format {"Time":"2019-09-04T14:31:29","Epoch":1567600289} +// payload 2 = Time format {"Time":"2019-09-04T14:31:29"} +// payload 3 = Time format {"Time":1567600289} +// payload 4 = reserved +// payload 1451602800 - disable NTP and set time to epoch + + uint32_t format = Settings.flag2.time_format; if (XdrvMailbox.data_len > 0) { - RtcSetTime(XdrvMailbox.payload); + if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 4)) { + Settings.flag2.time_format = XdrvMailbox.payload -1; + format = Settings.flag2.time_format; + } else { + format = 0; // {"Time":"2019-09-04T14:31:29","Epoch":1567600289} + RtcSetTime(XdrvMailbox.payload); + } } - ResponseBeginTime(); + mqtt_data[0] = '\0'; + ResponseAppendTimeFormat(format); ResponseJsonEnd(); } diff --git a/sonoff/support_features.ino b/sonoff/support_features.ino index dfccdbd33b2d..8265e4cb97e8 100644 --- a/sonoff/support_features.ino +++ b/sonoff/support_features.ino @@ -76,7 +76,7 @@ void GetFeatures(void) #ifdef USE_WS2812_DMA feature_drv1 |= 0x00010000; // xdrv_04_light.ino #endif -#ifdef USE_IR_REMOTE +#if defined(USE_IR_REMOTE) || defined(USE_IR_REMOTE_FULL) feature_drv1 |= 0x00020000; // xdrv_05_irremote.ino #endif #ifdef USE_IR_HVAC @@ -171,7 +171,7 @@ void GetFeatures(void) #ifdef USE_PCA9685 feature_drv2 |= 0x00004000; // xdrv_15_pca9685.ino #endif -#if defined(USE_LIGHT) && defined(USE_TUYA_DIMMER) +#if defined(USE_LIGHT) && defined(USE_TUYA_MCU) feature_drv2 |= 0x00008000; // xdrv_16_tuyadimmer.ino #endif #ifdef USE_RC_SWITCH diff --git a/sonoff/support_static_buffer.ino b/sonoff/support_static_buffer.ino new file mode 100644 index 000000000000..d2817753b54e --- /dev/null +++ b/sonoff/support_static_buffer.ino @@ -0,0 +1,159 @@ +/* + support_buffer.ino - Static binary buffer for Zigbee + + Copyright (C) 2019 Theo Arends and Stephan Hadinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +typedef struct SBuffer_impl { + uint16_t size; // size in bytes of the buffer + uint16_t len; // current size of the data in buffer. Invariant: len <= size + uint8_t buf[]; // the actual data +} SBuffer_impl; + +typedef class SBuffer { + +protected: + SBuffer(void) { + // unused empty constructor except from subclass + } + +public: + SBuffer(const size_t size) { + _buf = (SBuffer_impl*) new char[size+4]; // add 4 bytes for size and len + _buf->size = size; + _buf->len = 0; + //*((uint32_t*)_buf) = size; // writing both size and len=0 in a single 32 bits write + } + + inline size_t getSize(void) const { return _buf->size; } + inline size_t size(void) const { return _buf->size; } + inline size_t getLen(void) const { return _buf->len; } + inline size_t len(void) const { return _buf->len; } + inline uint8_t *getBuffer(void) const { return _buf->buf; } + inline uint8_t *buf(void) const { return _buf->buf; } + + virtual ~SBuffer(void) { + delete[] _buf; + } + + inline void setLen(const size_t len) { + uint16_t old_len = _buf->len; + _buf->len = (len <= _buf->size) ? len : _buf->size; + if (old_len < _buf->len) { + memset((void*) &_buf->buf[old_len], 0, _buf->len - old_len); + } + } + + size_t add8(const uint8_t data) { // append 8 bits value + if (_buf->len < _buf->size) { // do we have room for 1 byte + _buf->buf[_buf->len++] = data; + } + return _buf->len; + } + size_t add16(const uint16_t data) { // append 16 bits value + if (_buf->len < _buf->size - 1) { // do we have room for 2 bytes + _buf->buf[_buf->len++] = data; + _buf->buf[_buf->len++] = data >> 8; + } + return _buf->len; + } + size_t add32(const uint32_t data) { // append 32 bits value + if (_buf->len < _buf->size - 3) { // do we have room for 2 bytes + _buf->buf[_buf->len++] = data; + _buf->buf[_buf->len++] = data >> 8; + _buf->buf[_buf->len++] = data >> 16; + _buf->buf[_buf->len++] = data >> 24; + } + return _buf->len; + } + + size_t addBuffer(const SBuffer &buf2) { + if (len() + buf2.len() <= size()) { + for (uint32_t i = 0; i < buf2.len(); i++) { + _buf->buf[_buf->len++] = buf2.buf()[i]; + } + } + return _buf->len; + } + + size_t addBuffer(const char *buf2, size_t len2) { + if (len() + len2 <= size()) { + for (uint32_t i = 0; i < len2; i++) { + _buf->buf[_buf->len++] = pgm_read_byte(&buf2[i]); + } + } + return _buf->len; + } + + uint8_t get8(size_t offset) const { + if (offset < _buf->len) { + return _buf->buf[offset]; + } else { + return 0; + } + } + uint8_t read8(const size_t offset) const { + if (offset < len()) { + return _buf->buf[offset]; + } + return 0; + } + uint16_t get16(const size_t offset) const { + if (offset < len() - 1) { + return _buf->buf[offset] | (_buf->buf[offset+1] << 8); + } + return 0; + } + uint32_t get32(const size_t offset) const { + if (offset < len() - 3) { + return _buf->buf[offset] | (_buf->buf[offset+1] << 8) | + (_buf->buf[offset+2] << 16) | (_buf->buf[offset+3] << 24); + } + return 0; + } + + SBuffer subBuffer(const size_t start, size_t len) const { + if (start >= _buf->len) { + len = 0; + } else if (start + len > _buf->len) { + len = _buf->len - start; + } + + SBuffer buf2(len); + memcpy(buf2.buf(), buf()+start, len); + buf2._buf->len = len; + return buf2; + } + +protected: + SBuffer_impl * _buf; + +} SBuffer; + +typedef class PreAllocatedSBuffer : public SBuffer { + +public: + PreAllocatedSBuffer(const size_t size, void * buffer) { + _buf = (SBuffer_impl*) buffer; + _buf->size = size - 4; + _buf->len = 0; + } + + ~PreAllocatedSBuffer(void) { + // don't deallocate + _buf = nullptr; + } +} PreAllocatedSBuffer; diff --git a/sonoff/support_switch.ino b/sonoff/support_switch.ino index 40bbcc2b93ff..940fcdb1d02d 100644 --- a/sonoff/support_switch.ino +++ b/sonoff/support_switch.ino @@ -143,7 +143,7 @@ void SwitchHandler(uint8_t mode) if (Switch.hold_timer[i]) { Switch.hold_timer[i]--; if (0 == Switch.hold_timer[i]) { - SendKey(1, i +1, 3); // Execute command via MQTT + SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT } } @@ -152,10 +152,10 @@ void SwitchHandler(uint8_t mode) // enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, MAX_SWITCH_OPTION}; if (button != Switch.last_state[i]) { - switchflag = 3; + switchflag = POWER_TOGGLE +1; switch (Settings.switchmode[i]) { case TOGGLE: - switchflag = 2; // Toggle + switchflag = POWER_TOGGLE; // Toggle break; case FOLLOW: switchflag = button &1; // Follow wall switch state @@ -165,17 +165,17 @@ void SwitchHandler(uint8_t mode) break; case PUSHBUTTON: if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { - switchflag = 2; // Toggle with pushbutton to Gnd + switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd } break; case PUSHBUTTON_INV: if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { - switchflag = 2; // Toggle with releasing pushbutton from Gnd + switchflag = POWER_TOGGLE; // Toggle with releasing pushbutton from Gnd } break; case PUSHBUTTON_TOGGLE: if (button != Switch.last_state[i]) { - switchflag = 2; // Toggle with any pushbutton change + switchflag = POWER_TOGGLE; // Toggle with any pushbutton change } break; case PUSHBUTTONHOLD: @@ -184,7 +184,7 @@ void SwitchHandler(uint8_t mode) } if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { Switch.hold_timer[i] = 0; - switchflag = 2; // Toggle with pushbutton to Gnd + switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd } break; case PUSHBUTTONHOLD_INV: @@ -193,13 +193,13 @@ void SwitchHandler(uint8_t mode) } if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { Switch.hold_timer[i] = 0; - switchflag = 2; // Toggle with pushbutton to Gnd + switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd } break; } - if (switchflag < 3) { - if (!SendKey(1, i +1, switchflag)) { // Execute command via MQTT + if (switchflag <= POWER_TOGGLE) { + if (!SendKey(KEY_SWITCH, i +1, switchflag)) { // Execute command via MQTT ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < devices_present) } } diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index b7541910ed8b..01f5cde34cad 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -500,7 +500,7 @@ static bool WifiIsInManagerMode(){ return (HTTP_MANAGER == Web.state || HTTP_MANAGER_RESET_ONLY == Web.state); } -void ShowWebSource(int source) +void ShowWebSource(uint32_t source) { if ((source > 0) && (source < SRC_MAX)) { char stemp1[20]; @@ -508,7 +508,7 @@ void ShowWebSource(int source) } } -void ExecuteWebCommand(char* svalue, int source) +void ExecuteWebCommand(char* svalue, uint32_t source) { ShowWebSource(source); ExecuteCommand(svalue, SRC_IGNORE); @@ -1050,6 +1050,9 @@ bool HandleRootStatusRefresh(void) WSContentBegin(200, CT_HTML); WSContentSend_P(PSTR("{t}")); XsnsCall(FUNC_WEB_SENSOR); +#ifdef USE_SCRIPT_WEB_DISPLAY + XdrvCall(FUNC_WEB_SENSOR); +#endif WSContentSend_P(PSTR("
")); if (devices_present) { diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index 10e3eca9cee2..8de1a3d1efc5 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -894,7 +894,7 @@ void CmndButtonRetain(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { if (!XdrvMailbox.payload) { for (uint32_t i = 1; i <= MAX_KEYS; i++) { - SendKey(0, i, 9); // Clear MQTT retain in broker + SendKey(KEY_BUTTON, i, CLEAR_RETAIN); // Clear MQTT retain in broker } } Settings.flag.mqtt_button_retain = XdrvMailbox.payload; @@ -907,7 +907,7 @@ void CmndSwitchRetain(void) if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { if (!XdrvMailbox.payload) { for (uint32_t i = 1; i <= MAX_SWITCHES; i++) { - SendKey(1, i, 9); // Clear MQTT retain in broker + SendKey(KEY_SWITCH, i, CLEAR_RETAIN); // Clear MQTT retain in broker } } Settings.flag.mqtt_switch_retain = XdrvMailbox.payload; diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index bf8e9afdc04d..d5e814a47a85 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -76,6 +76,7 @@ struct ENERGY { float reactive_power = NAN; // 123.1 VAr float power_factor = NAN; // 0.12 float frequency = NAN; // 123.1 Hz + float start_energy = 0; // 12345.12345 kWh total previous float daily = 0; // 123.123 kWh @@ -114,7 +115,6 @@ struct ENERGY { uint8_t mplr_counter = 0; uint8_t max_energy_state = 0; #endif // USE_ENERGY_POWER_LIMIT - #endif // USE_ENERGY_MARGIN_DETECTION } Energy; @@ -146,6 +146,23 @@ void EnergyUpdateToday(void) } } +void EnergyUpdateTotal(float value, bool kwh) +{ + uint32_t multiplier = (kwh) ? 100000 : 100; // kWh or Wh to deca milli Wh + + if (0 == Energy.start_energy || (value < Energy.start_energy)) { + Energy.start_energy = value; // Init after restart and handle roll-over if any +// RtcSettings.energy_kWhtotal = (unsigned long)(value * multiplier); +// Energy.kWhtoday = 0; +// RtcSettings.energy_kWhtoday = 0; + } + else if (value != Energy.start_energy) { + Energy.kWhtoday += (unsigned long)((value - Energy.start_energy) * multiplier); + Energy.start_energy = value; + } + EnergyUpdateToday(); +} + /*********************************************************************************************/ void Energy200ms(void) @@ -297,10 +314,10 @@ void EnergyMarginCheck(void) } else { Energy.mplh_counter--; if (!Energy.mplh_counter) { - Response_P(PSTR("{\"" D_JSON_MAXPOWERREACHED "\":\"%d%s\"}"), energy_power_u, (Settings.flag.value_units) ? " " D_UNIT_WATT : ""); + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":\"%d%s\"}"), energy_power_u, (Settings.flag.value_units) ? " " D_UNIT_WATT : ""); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); - ExecuteCommandPower(1, POWER_OFF, SRC_MAXPOWER); + SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER); if (!Energy.mplr_counter) { Energy.mplr_counter = Settings.param[P_MAX_POWER_RETRY] +1; } @@ -320,11 +337,11 @@ void EnergyMarginCheck(void) if (Energy.mplr_counter) { Energy.mplr_counter--; if (Energy.mplr_counter) { - Response_P(PSTR("{\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1)); + ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1)); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); - ExecuteCommandPower(1, POWER_ON, SRC_MAXPOWER); + RestorePower(true, SRC_MAXPOWER); } else { - Response_P(PSTR("{\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0)); + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0)); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); } @@ -338,17 +355,17 @@ void EnergyMarginCheck(void) energy_daily_u = (uint16_t)(Energy.daily * 1000); if (!Energy.max_energy_state && (RtcTime.hour == Settings.energy_max_energy_start)) { Energy.max_energy_state = 1; - Response_P(PSTR("{\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1)); + ResponseTime_P(PSTR(",\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1)); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR)); - ExecuteCommandPower(1, POWER_ON, SRC_MAXENERGY); + RestorePower(true, SRC_MAXENERGY); } else if ((1 == Energy.max_energy_state ) && (energy_daily_u >= Settings.energy_max_energy)) { Energy.max_energy_state = 2; dtostrfd(Energy.daily, 3, mqtt_data); - Response_P(PSTR("{\"" D_JSON_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : ""); + ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : ""); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); - ExecuteCommandPower(1, POWER_OFF, SRC_MAXENERGY); + SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY); } } #endif // USE_ENERGY_POWER_LIMIT @@ -359,9 +376,10 @@ void EnergyMarginCheck(void) void EnergyMqttShow(void) { // {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}} - ResponseBeginTime(); int tele_period_save = tele_period; tele_period = 2; + mqtt_data[0] = '\0'; + ResponseAppendTime(); EnergyShow(true); tele_period = tele_period_save; ResponseJsonEnd(); @@ -384,9 +402,13 @@ void EnergyOverTempCheck() Energy.voltage = 0; Energy.current = 0; Energy.active_power = 0; + if (!isnan(Energy.apparent_power)) { Energy.apparent_power = 0; } + if (!isnan(Energy.reactive_power)) { Energy.reactive_power = 0; } if (!isnan(Energy.frequency)) { Energy.frequency = 0; } if (!isnan(Energy.power_factor)) { Energy.power_factor = 0; } Energy.start_energy = 0; + + XnrgCall(FUNC_ENERGY_RESET); } } } @@ -424,7 +446,9 @@ void CmndEnergyReset(void) Settings.energy_kWhtoday = Energy.kWhtoday; RtcSettings.energy_kWhtoday = Energy.kWhtoday; Energy.daily = (float)Energy.kWhtoday / 100000; - if (!RtcSettings.energy_kWhtotal && !Energy.kWhtoday) { Settings.energy_kWhtotal_time = LocalTime(); } + if (!RtcSettings.energy_kWhtotal && !Energy.kWhtoday) { + Settings.energy_kWhtotal_time = LocalTime(); + } break; case 2: Settings.energy_kWhyesterday = lnum *100; @@ -450,11 +474,11 @@ void CmndEnergyReset(void) RtcSettings.energy_usage.usage1_kWhtotal = Settings.energy_kWhtotal; } - char energy_total_chr[33]; + char energy_total_chr[FLOATSZ]; dtostrfd(Energy.total, Settings.flag2.energy_resolution, energy_total_chr); - char energy_daily_chr[33]; + char energy_daily_chr[FLOATSZ]; dtostrfd(Energy.daily, Settings.flag2.energy_resolution, energy_daily_chr); - char energy_yesterday_chr[33]; + char energy_yesterday_chr[FLOATSZ]; dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); Response_P(PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"), @@ -696,7 +720,7 @@ const char HTTP_ENERGY_SNS1[] PROGMEM = "{s}" D_POWER_FACTOR "{m}%s{e}"; const char HTTP_ENERGY_SNS2[] PROGMEM = - "{s}" D_ENERGY_TODAY "{m}%s " D_UNIT_KILOWATTHOUR "{e}" + "{s}" D_ENERGY_TODAY "{m}%s " D_UNIT_KILOWATTHOUR "{e}" "{s}" D_ENERGY_YESTERDAY "{m}%s " D_UNIT_KILOWATTHOUR "{e}" "{s}" D_ENERGY_TOTAL "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; // {s} = , {m} = , {e} = #endif // USE_WEBSERVER @@ -704,16 +728,15 @@ const char HTTP_ENERGY_SNS2[] PROGMEM = void EnergyShow(bool json) { char speriod[20]; -// char sfrequency[20]; bool show_energy_period = (0 == tele_period); float power_factor = Energy.power_factor; - char apparent_power_chr[33]; - char reactive_power_chr[33]; - char power_factor_chr[33]; - char frequency_chr[33]; + char apparent_power_chr[FLOATSZ]; + char reactive_power_chr[FLOATSZ]; + char power_factor_chr[FLOATSZ]; + char frequency_chr[FLOATSZ]; if (!Energy.type_dc) { if (Energy.current_available && Energy.voltage_available) { float apparent_power = Energy.apparent_power; @@ -749,21 +772,21 @@ void EnergyShow(bool json) } } - char voltage_chr[33]; + char voltage_chr[FLOATSZ]; dtostrfd(Energy.voltage, Settings.flag2.voltage_resolution, voltage_chr); - char current_chr[33]; + char current_chr[FLOATSZ]; dtostrfd(Energy.current, Settings.flag2.current_resolution, current_chr); - char active_power_chr[33]; + char active_power_chr[FLOATSZ]; dtostrfd(Energy.active_power, Settings.flag2.wattage_resolution, active_power_chr); - char energy_daily_chr[33]; + char energy_daily_chr[FLOATSZ]; dtostrfd(Energy.daily, Settings.flag2.energy_resolution, energy_daily_chr); - char energy_yesterday_chr[33]; + char energy_yesterday_chr[FLOATSZ]; dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr); - char energy_total_chr[33]; + char energy_total_chr[FLOATSZ]; dtostrfd(Energy.total, Settings.flag2.energy_resolution, energy_total_chr); float energy = 0; - char energy_period_chr[33]; + char energy_period_chr[FLOATSZ]; if (show_energy_period) { if (Energy.period) energy = (float)(Energy.kWhtoday - Energy.period) / 100; Energy.period = Energy.kWhtoday; @@ -789,6 +812,7 @@ void EnergyShow(bool json) if (Energy.current_available) { ResponseAppend_P(PSTR(",\"" D_JSON_CURRENT "\":%s"), current_chr); } + XnrgCall(FUNC_JSON_APPEND); ResponseJsonEnd(); #ifdef USE_DOMOTICZ @@ -797,7 +821,7 @@ void EnergyShow(bool json) DomoticzSensorPowerEnergy((int)Energy.active_power, energy_total_chr); // PowerUsage, EnergyToday dtostrfd((Energy.total - Energy.total1) * 1000, 1, energy_total_chr); // Tariff2 - char energy_total1_chr[33]; + char energy_total1_chr[FLOATSZ]; dtostrfd(Energy.total1 * 1000, 1, energy_total1_chr); // Tariff1 char energy_non[2] = "0"; DomoticzSensorP1SmartMeter(energy_total1_chr, energy_total_chr, energy_non, energy_non, (int)Energy.active_power, 0); @@ -843,6 +867,7 @@ void EnergyShow(bool json) } } WSContentSend_PD(HTTP_ENERGY_SNS2, energy_daily_chr, energy_yesterday_chr, energy_total_chr); + XnrgCall(FUNC_WEB_SENSOR); #endif // USE_WEBSERVER } } diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index cb60f2af3883..cc0614264149 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifdef USE_IR_REMOTE +#if defined(USE_IR_REMOTE) && !defined(USE_IR_REMOTE_FULL) /*********************************************************************************************\ * IR Remote send and receive using IRremoteESP8266 library \*********************************************************************************************/ @@ -154,7 +154,7 @@ void IrReceiveCheck(void) } else { snprintf_P(svalue, sizeof(svalue), PSTR("\"0x%s\""), hvalue); } - Response_P(PSTR("{\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":%s"), + ResponseTime_P(PSTR(",\"" D_JSON_IRRECEIVED "\":{\"" D_JSON_IR_PROTOCOL "\":\"%s\",\"" D_JSON_IR_BITS "\":%d,\"" D_JSON_IR_DATA "\":%s"), GetTextIndexed(sirtype, sizeof(sirtype), iridx, kIrRemoteProtocols), results.bits, svalue); if (Settings.flag3.receive_raw) { @@ -671,6 +671,7 @@ uint32_t IrRemoteCmndIrHvacJson(void) const char *HVAC_Mode; const char *HVAC_FanMode; const char *HVAC_Vendor; + char parm_uc[12]; int HVAC_Temp = 21; bool HVAC_Power = true; @@ -687,11 +688,11 @@ uint32_t IrRemoteCmndIrHvacJson(void) return IE_INVALID_JSON; } - HVAC_Vendor = root[D_JSON_IRHVAC_VENDOR]; - HVAC_Power = root[D_JSON_IRHVAC_POWER]; - HVAC_Mode = root[D_JSON_IRHVAC_MODE]; - HVAC_FanMode = root[D_JSON_IRHVAC_FANSPEED]; - HVAC_Temp = root[D_JSON_IRHVAC_TEMP]; + HVAC_Vendor = root[UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_VENDOR))]; + HVAC_Power = root[UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_POWER))]; + HVAC_Mode = root[UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_MODE))]; + HVAC_FanMode = root[UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_FANSPEED))]; + HVAC_Temp = root[UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_TEMP))]; // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("IRHVAC: Received Vendor %s, Power %d, Mode %s, FanSpeed %s, Temp %d"), HVAC_Vendor, HVAC_Power, HVAC_Mode, HVAC_FanMode, HVAC_Temp); @@ -1073,4 +1074,4 @@ bool Xdrv05(uint8_t function) return result; } -#endif // USE_IR_REMOTE +#endif // defined(USE_IR_REMOTE) && !defined(USE_IR_REMOTE_FULL) diff --git a/sonoff/xdrv_05_irremote_full.ino b/sonoff/xdrv_05_irremote_full.ino new file mode 100644 index 000000000000..3c82bee21872 --- /dev/null +++ b/sonoff/xdrv_05_irremote_full.ino @@ -0,0 +1,682 @@ +/* + xdrv_05_irremote_full.ino - complete intefration of IRremoteESP8266 + + Copyright (C) 2019 Heiko Krupp, Lazar Obradovic, Theo Arends, Stephan Hadinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_IR_REMOTE_FULL +/*********************************************************************************************\ + * IR Remote send and receive using IRremoteESP8266 library +\*********************************************************************************************/ + +#define XDRV_05 5 + +#include +#include +#include +#include +#include + +enum IrErrors { IE_RESPONSE_PROVIDED, IE_NO_ERROR, IE_INVALID_RAWDATA, IE_INVALID_JSON, IE_SYNTAX_IRSEND, IE_SYNTAX_IRHVAC, + IE_UNSUPPORTED_HVAC, IE_UNSUPPORTED_PROTOCOL }; + +const char kIrRemoteCommands[] PROGMEM = "|" D_CMND_IRHVAC "|" D_CMND_IRSEND ; // No prefix + +void (* const IrRemoteCommand[])(void) PROGMEM = { &CmndIrHvac, &CmndIrSend }; + +/*********************************************************************************************\ + * IR Send +\*********************************************************************************************/ + +IRsend *irsend = nullptr; +bool irsend_active = false; + +void IrSendInit(void) +{ + irsend = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND + irsend->begin(); +} + +// from https://stackoverflow.com/questions/2602823/in-c-c-whats-the-simplest-way-to-reverse-the-order-of-bits-in-a-byte +// First the left four bits are swapped with the right four bits. Then all adjacent pairs are swapped and then all adjacent single bits. This results in a reversed order. +uint8_t reverseBitsInByte(uint8_t b) { + b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; + b = (b & 0xCC) >> 2 | (b & 0x33) << 2; + b = (b & 0xAA) >> 1 | (b & 0x55) << 1; + return b; +} + +// reverse bits in each byte +uint64_t reverseBitsInBytes64(uint64_t b) { + union { + uint8_t b[8]; + uint64_t i; + } a; + a.i = b; + for (uint32_t i=0; i<8; i++) { + a.b[i] = reverseBitsInByte(a.b[i]); + } + return a.i; +} + +char* IrUint64toHex(uint64_t value, char *str, uint16_t bits) +{ + ulltoa(value, str, 16); // Get 64bit value + + int fill = 8; + if ((bits > 3) && (bits < 65)) { + fill = bits / 4; // Max 16 + if (bits % 4) { fill++; } + } + int len = strlen(str); + fill -= len; + if (fill > 0) { + memmove(str + fill, str, len +1); + memset(str, '0', fill); + } + memmove(str + 2, str, strlen(str) +1); + str[0] = '0'; + str[1] = 'x'; + return str; +} + +/*********************************************************************************************\ + * IR Receive +\*********************************************************************************************/ + +const bool IR_FULL_RCV_SAVE_BUFFER = false; // false = do not use buffer, true = use buffer for decoding +const uint32_t IR_TIME_AVOID_DUPLICATE = 500; // Milliseconds + +// Below is from IRrecvDumpV2.ino +// As this program is a special purpose capture/decoder, let us use a larger +// than normal buffer so we can handle Air Conditioner remote codes. +const uint16_t IR_FULL_BUFFER_SIZE = 1024; + +// Some A/C units have gaps in their protocols of ~40ms. e.g. Kelvinator +// A value this large may swallow repeats of some protocols +const uint8_t IR__FULL_RCV_TIMEOUT = 50; + +IRrecv *irrecv = nullptr; + +unsigned long ir_lasttime = 0; + +void IrReceiveUpdateThreshold() +{ + if (irrecv != nullptr) { + if (Settings.param[P_IR_UNKNOW_THRESHOLD] < 6) { Settings.param[P_IR_UNKNOW_THRESHOLD] = 6; } + irrecv->setUnknownThreshold(Settings.param[P_IR_UNKNOW_THRESHOLD]); + } +} + +void IrReceiveInit(void) +{ + // an IR led is at GPIO_IRRECV + irrecv = new IRrecv(pin[GPIO_IRRECV], IR_FULL_BUFFER_SIZE, IR__FULL_RCV_TIMEOUT, IR_FULL_RCV_SAVE_BUFFER); + irrecv->setUnknownThreshold(Settings.param[P_IR_UNKNOW_THRESHOLD]); + irrecv->enableIRIn(); // Start the receiver +} + +String sendACJsonState(const stdAc::state_t &state) { + DynamicJsonBuffer jsonBuffer; + JsonObject& json = jsonBuffer.createObject(); + json[D_JSON_IRHVAC_VENDOR] = typeToString(state.protocol); + json[D_JSON_IRHVAC_MODEL] = state.model; + json[D_JSON_IRHVAC_POWER] = IRac::boolToString(state.power); + json[D_JSON_IRHVAC_MODE] = IRac::opmodeToString(state.mode); + // Home Assistant wants mode to be off if power is also off & vice-versa. + if (state.mode == stdAc::opmode_t::kOff || !state.power) { + json[D_JSON_IRHVAC_MODE] = IRac::opmodeToString(stdAc::opmode_t::kOff); + json[D_JSON_IRHVAC_POWER] = IRac::boolToString(false); + } + json[D_JSON_IRHVAC_CELSIUS] = IRac::boolToString(state.celsius); + if (floorf(state.degrees) == state.degrees) { + json[D_JSON_IRHVAC_TEMP] = floorf(state.degrees); // integer + } else { + json[D_JSON_IRHVAC_TEMP] = RawJson(String(state.degrees, 1)); // non-integer, limit to only 1 sub-digit + } + json[D_JSON_IRHVAC_FANSPEED] = IRac::fanspeedToString(state.fanspeed); + json[D_JSON_IRHVAC_SWINGV] = IRac::swingvToString(state.swingv); + json[D_JSON_IRHVAC_SWINGH] = IRac::swinghToString(state.swingh); + json[D_JSON_IRHVAC_QUIET] = IRac::boolToString(state.quiet); + json[D_JSON_IRHVAC_TURBO] = IRac::boolToString(state.turbo); + json[D_JSON_IRHVAC_ECONO] = IRac::boolToString(state.econo); + json[D_JSON_IRHVAC_LIGHT] = IRac::boolToString(state.light); + json[D_JSON_IRHVAC_FILTER] = IRac::boolToString(state.filter); + json[D_JSON_IRHVAC_CLEAN] = IRac::boolToString(state.clean); + json[D_JSON_IRHVAC_BEEP] = IRac::boolToString(state.beep); + json[D_JSON_IRHVAC_SLEEP] = state.sleep; + + String payload = ""; + payload.reserve(200); + json.printTo(payload); + return payload; +} + +String sendIRJsonState(const struct decode_results &results) { + String json("{"); + json += "\"" D_JSON_IR_PROTOCOL "\":\""; + json += typeToString(results.decode_type); + json += "\",\"" D_JSON_IR_BITS "\":"; + json += results.bits; + + if (hasACState(results.decode_type)) { + json += ",\"" D_JSON_IR_DATA "\":\"0x"; + json += resultToHexidecimal(&results); + json += "\""; + } else { + json += ",\"" D_JSON_IR_DATA "\":"; + if (Settings.flag.ir_receive_decimal) { + char svalue[32]; + ulltoa(results.value, svalue, 10); + json += svalue; + } else { + char hvalue[64]; + IrUint64toHex(results.value, hvalue, results.bits); // Get 64bit value as hex 0x00123456 + json += "\""; + json += hvalue; + json += "\",\"" D_JSON_IR_DATALSB "\":\""; + IrUint64toHex(reverseBitsInBytes64(results.value), hvalue, results.bits); // Get 64bit value as hex 0x00123456, LSB + json += hvalue; + json += "\""; + } + } + json += ",\"" D_JSON_IR_REPEAT "\":"; + json += results.repeat; + + stdAc::state_t ac_result; + if (IRAcUtils::decodeToState(&results, &ac_result, nullptr)) { + // we have a decoded state + json += ",\"" D_CMND_IRHVAC "\":"; + json += sendACJsonState(ac_result); + } + + return json; +} + +void IrReceiveCheck(void) +{ + char sirtype[14]; // Max is AIWA_RC_T501 + int8_t iridx = 0; + + decode_results results; + + if (irrecv->decode(&results)) { + uint32_t now = millis(); + + +// if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) { + if (!irsend_active && (now - ir_lasttime > IR_TIME_AVOID_DUPLICATE)) { + ir_lasttime = now; + ResponseTime_P(PSTR(",\"" D_JSON_IRRECEIVED "\":%s"), sendIRJsonState(results).c_str()); + + if (Settings.flag3.receive_raw) { + ResponseAppend_P(PSTR(",\"" D_JSON_IR_RAWDATA "\":[")); + uint16_t i; + for (i = 1; i < results.rawlen; i++) { + if (i > 1) { ResponseAppend_P(PSTR(",")); } + uint32_t usecs; + for (usecs = results.rawbuf[i] * kRawTick; usecs > UINT16_MAX; usecs -= UINT16_MAX) { + ResponseAppend_P(PSTR("%d,0,"), UINT16_MAX); + } + ResponseAppend_P(PSTR("%d"), usecs); + if (strlen(mqtt_data) > sizeof(mqtt_data) - 40) { break; } // Quit if char string becomes too long + } + uint16_t extended_length = results.rawlen - 1; + for (uint32_t j = 0; j < results.rawlen - 1; j++) { + uint32_t usecs = results.rawbuf[j] * kRawTick; + // Add two extra entries for multiple larger than UINT16_MAX it is. + extended_length += (usecs / (UINT16_MAX + 1)) * 2; + } + ResponseAppend_P(PSTR("],\"" D_JSON_IR_RAWDATA "Info\":[%d,%d,%d]"), extended_length, i -1, results.overflow); + } + + ResponseAppend_P(PSTR("}}")); + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED)); + + if (iridx) { + XdrvRulesProcess(); +#ifdef USE_DOMOTICZ + unsigned long value = results.value | (iridx << 28); // [Protocol:4, Data:28] + DomoticzSensor(DZ_COUNT, value); // Send data as Domoticz Counter value +#endif // USE_DOMOTICZ + } + } + + irrecv->resume(); + } +} + + +/*********************************************************************************************\ + * IR Heating, Ventilation and Air Conditioning +\*********************************************************************************************/ + +// list all supported protocols, either for IRSend or for IRHVAC, separated by '|' +String listSupportedProtocols(bool hvac) { + String l(""); + bool first = true; + for (uint32_t i = UNUSED + 1; i <= kLastDecodeType; i++) { + bool found = false; + if (hvac) { + found = IRac::isProtocolSupported((decode_type_t)i); + } else { + found = (IRsend::defaultBits((decode_type_t)i) > 0) && (!IRac::isProtocolSupported((decode_type_t)i)); + } + if (found) { + if (first) { + first = false; + } else { + l += "|"; + } + l += typeToString((decode_type_t)i); + } + } + return l; +} + +// used to convert values 0-5 to fanspeed_t +const stdAc::fanspeed_t IrHvacFanSpeed[] PROGMEM = { stdAc::fanspeed_t::kAuto, + stdAc::fanspeed_t::kMin, stdAc::fanspeed_t::kLow,stdAc::fanspeed_t::kMedium, + stdAc::fanspeed_t::kHigh, stdAc::fanspeed_t::kMax }; + +uint32_t IrRemoteCmndIrHvacJson(void) +{ + stdAc::state_t state, prev; + char parm_uc[12]; + + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("IRHVAC: Received %s"), XdrvMailbox.data); + char dataBufUc[XdrvMailbox.data_len]; + UpperCase(dataBufUc, XdrvMailbox.data); + RemoveSpace(dataBufUc); + if (strlen(dataBufUc) < 8) { return IE_INVALID_JSON; } + + DynamicJsonBuffer jsonBuf; + JsonObject &json = jsonBuf.parseObject(dataBufUc); + if (!json.success()) { return IE_INVALID_JSON; } + + // from: https://github.com/crankyoldgit/IRremoteESP8266/blob/master/examples/CommonAcControl/CommonAcControl.ino + state.protocol = decode_type_t::UNKNOWN; + state.model = 1; // Some A/C's have different models. Let's try using just 1. + state.mode = stdAc::opmode_t::kAuto; // Run in cool mode initially. + state.power = false; // Initially start with the unit off. + state.celsius = true; // Use Celsius for units of temp. False = Fahrenheit + state.degrees = 21.0f; // 21 degrees. + state.fanspeed = stdAc::fanspeed_t::kMedium; // Start with the fan at medium. + state.swingv = stdAc::swingv_t::kOff; // Don't swing the fan up or down. + state.swingh = stdAc::swingh_t::kOff; // Don't swing the fan left or right. + state.light = false; // Turn off any LED/Lights/Display that we can. + state.beep = false; // Turn off any beep from the A/C if we can. + state.econo = false; // Turn off any economy modes if we can. + state.filter = false; // Turn off any Ion/Mold/Health filters if we can. + state.turbo = false; // Don't use any turbo/powerful/etc modes. + state.quiet = false; // Don't use any quiet/silent/etc modes. + state.sleep = -1; // Don't set any sleep time or modes. + state.clean = false; // Turn off any Cleaning options if we can. + state.clock = -1; // Don't set any current time if we can avoid it. + + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_VENDOR)); + if (json.containsKey(parm_uc)) { state.protocol = strToDecodeType(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_PROTOCOL)); + if (json.containsKey(parm_uc)) { state.protocol = strToDecodeType(json[parm_uc]); } // also support 'protocol' + if (decode_type_t::UNKNOWN == state.protocol) { return IE_UNSUPPORTED_HVAC; } + if (!IRac::isProtocolSupported(state.protocol)) { return IE_UNSUPPORTED_HVAC; } + + // for fan speed, we also support 1-5 values + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_FANSPEED)); + if (json.containsKey(parm_uc)) { + uint32_t fan_speed = json[parm_uc]; + if ((fan_speed >= 1) && (fan_speed <= 5)) { + state.fanspeed = (stdAc::fanspeed_t) pgm_read_byte(&IrHvacFanSpeed[fan_speed]); + } else { + state.fanspeed = IRac::strToFanspeed(json[parm_uc]); + } + } + + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_MODEL)); + if (json.containsKey(parm_uc)) { state.model = IRac::strToModel(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_MODE)); + if (json.containsKey(parm_uc)) { state.mode = IRac::strToOpmode(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_SWINGV)); + if (json.containsKey(parm_uc)) { state.swingv = IRac::strToSwingV(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_SWINGH)); + if (json.containsKey(parm_uc)) { state.swingh = IRac::strToSwingH(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_TEMP)); + if (json.containsKey(parm_uc)) { state.degrees = json[parm_uc]; } + // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("model %d, mode %d, fanspeed %d, swingv %d, swingh %d"), + // state.model, state.mode, state.fanspeed, state.swingv, state.swingh); + + // decode booleans + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_POWER)); + if (json.containsKey(parm_uc)) { state.power = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_CELSIUS)); + if (json.containsKey(parm_uc)) { state.celsius = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_LIGHT)); + if (json.containsKey(parm_uc)) { state.light = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_BEEP)); + if (json.containsKey(parm_uc)) { state.beep = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_ECONO)); + if (json.containsKey(parm_uc)) { state.econo = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_FILTER)); + if (json.containsKey(parm_uc)) { state.filter = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_TURBO)); + if (json.containsKey(parm_uc)) { state.turbo = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_QUIET)); + if (json.containsKey(parm_uc)) { state.quiet = IRac::strToBool(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_CLEAN)); + if (json.containsKey(parm_uc)) { state.clean = IRac::strToBool(json[parm_uc]); } + + // optional timer and clock + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_SLEEP)); + if (json[parm_uc]) { state.sleep = json[parm_uc]; } + //if (json[D_JSON_IRHVAC_CLOCK]) { state.clock = json[D_JSON_IRHVAC_CLOCK]; } // not sure it's useful to support 'clock' + + IRac ac(pin[GPIO_IRSEND]); + bool success = ac.sendAc(state, &prev); + if (!success) { return IE_SYNTAX_IRHVAC; } + + Response_P(PSTR("{\"" D_CMND_IRHVAC "\":%s}"), sendACJsonState(state).c_str()); + return IE_RESPONSE_PROVIDED; +} + +void CmndIrHvac(void) +{ + uint8_t error = IE_SYNTAX_IRHVAC; + + if (XdrvMailbox.data_len) { + error = IrRemoteCmndIrHvacJson(); + } + if (error != IE_RESPONSE_PROVIDED) { IrRemoteCmndResponse(error); } // otherwise response was already provided +} + +/*********************************************************************************************\ + * Commands +\*********************************************************************************************/ + +uint32_t IrRemoteCmndIrSendJson(void) +{ + char parm_uc[12]; // used to convert JSON keys to uppercase + // ArduinoJSON entry used to calculate jsonBuf: JSON_OBJECT_SIZE(3) + 40 = 96 + // IRsend { "protocol": "RC5", "bits": 12, "data":"0xC86" } + // IRsend { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } + char dataBufUc[XdrvMailbox.data_len]; + UpperCase(dataBufUc, XdrvMailbox.data); + RemoveSpace(dataBufUc); + if (strlen(dataBufUc) < 8) { return IE_INVALID_JSON; } + + DynamicJsonBuffer jsonBuf; + JsonObject &json = jsonBuf.parseObject(dataBufUc); + if (!json.success()) { return IE_INVALID_JSON; } + + // IRsend { "protocol": "SAMSUNG", "bits": 32, "data": 551502015 } + // IRsend { "protocol": "NEC", "bits": 32, "data":"0x02FDFE80", "repeat": 2 } + decode_type_t protocol = decode_type_t::UNKNOWN; + uint16_t bits = 0; + uint64_t data; + uint8_t repeat = 0; + + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_VENDOR)); + if (json.containsKey(parm_uc)) { protocol = strToDecodeType(json[parm_uc]); } + UpperCase_P(parm_uc, PSTR(D_JSON_IRHVAC_PROTOCOL)); + if (json.containsKey(parm_uc)) { protocol = strToDecodeType(json[parm_uc]); } // also support 'protocol' + if (decode_type_t::UNKNOWN == protocol) { return IE_UNSUPPORTED_PROTOCOL; } + + UpperCase_P(parm_uc, PSTR(D_JSON_IR_BITS)); + if (json.containsKey(parm_uc)) { bits = json[parm_uc]; } + UpperCase_P(parm_uc, PSTR(D_JSON_IR_REPEAT)); + if (json.containsKey(parm_uc)) { repeat = json[parm_uc]; } + UpperCase_P(parm_uc, PSTR(D_JSON_IR_DATALSB)); // accept LSB values + if (json.containsKey(parm_uc)) { data = reverseBitsInBytes64(strtoull(json[parm_uc], nullptr, 0)); } + UpperCase_P(parm_uc, PSTR(D_JSON_IR_DATA)); // or classical MSB (takes priority) + if (json.containsKey(parm_uc)) { data = strtoull(json[parm_uc], nullptr, 0); } + if (0 == bits) { return IE_SYNTAX_IRSEND; } + + // check if the IRSend is greater than repeat, but can be overriden with JSON + if (XdrvMailbox.index > repeat + 1) { repeat = XdrvMailbox.index - 1; } + + char dvalue[32]; + char hvalue[32]; + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("IRS: protocol %d, bits %d, data %s (%s), repeat %d"), + protocol, bits, ulltoa(data, dvalue, 10), IrUint64toHex(data, hvalue, bits), repeat); + + irsend_active = true; // deactivate receive + bool success = irsend->send(protocol, data, bits, repeat); + + if (!success) { + irsend_active = false; + ResponseCmndChar(D_JSON_PROTOCOL_NOT_SUPPORTED); + } + return IE_NO_ERROR; +} + +uint32_t IrRemoteCmndIrSendRaw(void) +{ + // IRsend ,, ... + // or + // IRsend raw,,, (one space = zero space *2) + // IRsend raw,,,, + // IRsend raw,,,, + // IRsend raw,,

,
,,,, + + char *p; + char *str = strtok_r(XdrvMailbox.data, ", ", &p); + if (p == nullptr) { + return IE_INVALID_RAWDATA; + } + + // repeat + uint16_t repeat = XdrvMailbox.index > 0 ? XdrvMailbox.index - 1 : 0; + + uint16_t freq = atoi(str); + if (!freq && (*str != '0')) { // First parameter is any string + uint16_t count = 0; + char *q = p; + for (; *q; count += (*q++ == ',')); + if (count < 2) { + return IE_INVALID_RAWDATA; + } // Parameters must be at least 3 + + uint16_t parm[count]; + for (uint32_t i = 0; i < count; i++) { + parm[i] = strtol(strtok_r(nullptr, ", ", &p), nullptr, 0); + if (!parm[i]) { + if (!i) { + parm[0] = 38000; // Frequency default to 38kHz + } else { + return IE_INVALID_RAWDATA; // Other parameters may not be 0 + } + } + } + + uint16_t i = 0; + if (count < 4) { + // IRsend raw,0,889,000000100110000001001 + uint16_t mark = parm[1] *2; // Protocol where 0 = t, 1 = 2t (RC5) + if (3 == count) { + if (parm[2] < parm[1]) { + // IRsend raw,0,889,2,000000100110000001001 + mark = parm[1] * parm[2]; // Protocol where 0 = t1, 1 = t1*t2 (Could be RC5) + } else { + // IRsend raw,0,889,1778,000000100110000001001 + mark = parm[2]; // Protocol where 0 = t1, 1 = t2 (Could be RC5) + } + } + uint16_t raw_array[strlen(p)]; // Bits + for (; *p; *p++) { + if (*p == '0') { + raw_array[i++] = parm[1]; // Space + } + else if (*p == '1') { + raw_array[i++] = mark; // Mark + } + } + irsend_active = true; + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, i, parm[0]); + if (r < repeat) { // if it's not the last message + irsend->space(40000); // since we don't know the inter-message gap, place an arbitrary 40ms gap + } + } + } + else if (6 == count) { // NEC Protocol + // IRsend raw,0,8620,4260,544,411,1496,010101101000111011001110000000001100110000000001100000000000000010001100 + uint16_t raw_array[strlen(p)*2+3]; // Header + bits + end + raw_array[i++] = parm[1]; // Header mark + raw_array[i++] = parm[2]; // Header space + uint32_t inter_message_32 = (parm[1] + parm[2]) * 3; // compute an inter-message gap (32 bits) + uint16_t inter_message = (inter_message_32 > 65000) ? 65000 : inter_message_32; // avoid 16 bits overflow + for (; *p; *p++) { + if (*p == '0') { + raw_array[i++] = parm[3]; // Bit mark + raw_array[i++] = parm[4]; // Zero space + } + else if (*p == '1') { + raw_array[i++] = parm[3]; // Bit mark + raw_array[i++] = parm[5]; // One space + } + } + raw_array[i++] = parm[3]; // Trailing mark + irsend_active = true; + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, i, parm[0]); + if (r < repeat) { // if it's not the last message + irsend->space(inter_message); // since we don't know the inter-message gap, place an arbitrary 40ms gap + } + } + } + else { + return IE_INVALID_RAWDATA; // Invalid number of parameters + } + } else { + if (!freq) { freq = 38000; } // Default to 38kHz + uint16_t count = 0; + char *q = p; + for (; *q; count += (*q++ == ',')); + if (0 == count) { + return IE_INVALID_RAWDATA; + } + + // IRsend 0,896,876,900,888,894,876,1790,874,872,1810,1736,948,872,880,872,936,872,1792,900,888,1734 + count++; + if (count < 200) { + uint16_t raw_array[count]; // It's safe to use stack for up to 200 packets (limited by mqtt_data length) + for (uint32_t i = 0; i < count; i++) { + raw_array[i] = strtol(strtok_r(nullptr, ", ", &p), nullptr, 0); // Allow decimal (20496) and hexadecimal (0x5010) input + } + +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: stack count %d"), count); + + irsend_active = true; + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, count, freq); + } + } else { + uint16_t *raw_array = reinterpret_cast(malloc(count * sizeof(uint16_t))); + if (raw_array == nullptr) { + return IE_INVALID_RAWDATA; + } + + for (uint32_t i = 0; i < count; i++) { + raw_array[i] = strtol(strtok_r(nullptr, ", ", &p), nullptr, 0); // Allow decimal (20496) and hexadecimal (0x5010) input + } + +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: heap count %d"), count); + + irsend_active = true; + for (uint32_t r = 0; r <= repeat; r++) { + irsend->sendRaw(raw_array, count, freq); + } + free(raw_array); + } + } + + return IE_NO_ERROR; +} + +void CmndIrSend(void) +{ + uint8_t error = IE_SYNTAX_IRSEND; + + if (XdrvMailbox.data_len) { + if (strstr(XdrvMailbox.data, "{") == nullptr) { + error = IrRemoteCmndIrSendRaw(); + } else { + error = IrRemoteCmndIrSendJson(); + } + } + IrRemoteCmndResponse(error); +} + +void IrRemoteCmndResponse(uint32_t error) +{ + switch (error) { + case IE_INVALID_RAWDATA: + ResponseCmndChar(D_JSON_INVALID_RAWDATA); + break; + case IE_INVALID_JSON: + ResponseCmndChar(D_JSON_INVALID_JSON); + break; + case IE_SYNTAX_IRSEND: + Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}")); + break; + case IE_SYNTAX_IRHVAC: + Response_P(PSTR("{\"" D_CMND_IRHVAC "\":\"" D_JSON_WRONG " " D_JSON_IRHVAC_VENDOR ", " D_JSON_IRHVAC_MODE " " D_JSON_OR " " D_JSON_IRHVAC_FANSPEED "\"}")); + break; + case IE_UNSUPPORTED_HVAC: + Response_P(PSTR("{\"" D_CMND_IRHVAC "\":\"" D_JSON_WRONG " " D_JSON_IRHVAC_VENDOR " (%s)\"}"), listSupportedProtocols(true).c_str()); + break; + case IE_UNSUPPORTED_PROTOCOL: + Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_WRONG " " D_JSON_IRHVAC_PROTOCOL " (%s)\"}"), listSupportedProtocols(false).c_str()); + break; + default: // IE_NO_ERROR + ResponseCmndDone(); + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xdrv05(uint8_t function) +{ + bool result = false; + + if ((pin[GPIO_IRSEND] < 99) || (pin[GPIO_IRRECV] < 99)) { + switch (function) { + case FUNC_PRE_INIT: + if (pin[GPIO_IRSEND] < 99) { + IrSendInit(); + } + if (pin[GPIO_IRRECV] < 99) { + IrReceiveInit(); + } + break; + case FUNC_EVERY_50_MSECOND: + if (pin[GPIO_IRRECV] < 99) { + IrReceiveCheck(); // check if there's anything on IR side + } + irsend_active = false; // re-enable IR reception + break; + case FUNC_COMMAND: + if (pin[GPIO_IRSEND] < 99) { + result = DecodeCommand(kIrRemoteCommands, IrRemoteCommand); + } + break; + } + } + return result; +} + +#endif // USE_IR_REMOTE_FULL diff --git a/sonoff/xdrv_06_snfbridge.ino b/sonoff/xdrv_06_snfbridge.ino index c7b57c0c114f..67ca582fbfc4 100644 --- a/sonoff/xdrv_06_snfbridge.ino +++ b/sonoff/xdrv_06_snfbridge.ino @@ -214,7 +214,7 @@ void SonoffBridgeReceivedRaw(void) if (0xB1 == serial_in_buffer[1]) { buckets = serial_in_buffer[2] << 1; } // Bucket sniffing - Response_P(PSTR("{\"" D_CMND_RFRAW "\":{\"" D_JSON_DATA "\":\"")); + ResponseTime_P(PSTR(",\"" D_CMND_RFRAW "\":{\"" D_JSON_DATA "\":\"")); for (uint32_t i = 0; i < serial_in_byte_counter; i++) { ResponseAppend_P(PSTR("%02X"), serial_in_buffer[i]); if (0xB1 == serial_in_buffer[1]) { @@ -226,6 +226,7 @@ void SonoffBridgeReceivedRaw(void) } ResponseAppend_P(PSTR("\"}}")); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_CMND_RFRAW)); + XdrvRulesProcess(); } @@ -294,7 +295,7 @@ void SonoffBridgeReceived(void) } else { snprintf_P(stemp, sizeof(stemp), PSTR("\"%06X\""), received_id); } - Response_P(PSTR("{\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":%s,\"" D_CMND_RFKEY "\":%s}}"), + ResponseTime_P(PSTR(",\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":%s,\"" D_CMND_RFKEY "\":%s}}"), sync_time, low_time, high_time, stemp, rfkey); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED)); XdrvRulesProcess(); diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index e5bd2705f615..33acefc76cc3 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -306,7 +306,7 @@ bool DomoticzSendKey(uint8_t key, uint8_t device, uint8_t state, uint8_t svalflg if (device <= MAX_DOMOTICZ_IDX) { if ((Settings.domoticz_key_idx[device -1] || Settings.domoticz_switch_idx[device -1]) && (svalflg)) { Response_P(PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"), - (key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off"); + (key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (POWER_TOGGLE == state) ? "Toggle" : "On" : "Off"); MqttPublish(domoticz_in_topic); result = true; } diff --git a/sonoff/xdrv_08_serial_bridge.ino b/sonoff/xdrv_08_serial_bridge.ino index 98bb6a8301f4..8a05438586ee 100644 --- a/sonoff/xdrv_08_serial_bridge.ino +++ b/sonoff/xdrv_08_serial_bridge.ino @@ -71,7 +71,7 @@ void SerialBridgeInput(void) if (serial_bridge_in_byte_counter && (millis() > (serial_bridge_polling_window + SERIAL_POLLING))) { serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // Serial data completed char hex_char[(serial_bridge_in_byte_counter * 2) + 2]; - Response_P(PSTR("{\"" D_JSON_SSERIALRECEIVED "\":\"%s\"}"), + ResponseTime_P(PSTR(",\"" D_JSON_SSERIALRECEIVED "\":\"%s\"}"), (serial_bridge_raw) ? ToHex_P((unsigned char*)serial_bridge_buffer, serial_bridge_in_byte_counter, hex_char, sizeof(hex_char)) : serial_bridge_buffer); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED)); XdrvRulesProcess(); diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 674cbfb9bdba..4b767e77c504 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -296,7 +296,7 @@ void TimerEverySecond(void) if (xtimer.days & days) { Settings.timer[i].arm = xtimer.repeat; #if defined(USE_RULES) || defined(USE_SCRIPT) - if (3 == xtimer.power) { // Blink becomes Rule disregarding device and allowing use of Backlog commands + if (POWER_BLINK == xtimer.power) { // Blink becomes Rule disregarding device and allowing use of Backlog commands Response_P(PSTR("{\"Clock\":{\"Timer\":%d}}"), i +1); XdrvRulesProcess(); } else diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index fd1db942644e..35e3c4cf01b2 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -1207,7 +1207,11 @@ void CmndVariable(void) } else { if (XdrvMailbox.data_len > 0) { #ifdef USE_EXPRESSION - dtostrfd(evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len), Settings.flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]); + if (XdrvMailbox.data[0] == '=') { // Spaces already been skipped in data + dtostrfd(evaluateExpression(XdrvMailbox.data + 1, XdrvMailbox.data_len - 1), Settings.flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]); + } else { + strlcpy(rules_vars[XdrvMailbox.index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(rules_vars[XdrvMailbox.index -1])); + } #else strlcpy(rules_vars[XdrvMailbox.index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(rules_vars[XdrvMailbox.index -1])); #endif // USE_EXPRESSION @@ -1230,7 +1234,11 @@ void CmndMemory(void) } else { if (XdrvMailbox.data_len > 0) { #ifdef USE_EXPRESSION - dtostrfd(evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len), Settings.flag2.calc_resolution, Settings.mems[XdrvMailbox.index -1]); + if (XdrvMailbox.data[0] == '=') { // Spaces already been skipped in data + dtostrfd(evaluateExpression(XdrvMailbox.data + 1, XdrvMailbox.data_len - 1), Settings.flag2.calc_resolution, Settings.mems[XdrvMailbox.index -1]); + } else { + strlcpy(Settings.mems[XdrvMailbox.index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(Settings.mems[XdrvMailbox.index -1])); + } #else strlcpy(Settings.mems[XdrvMailbox.index -1], ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data, sizeof(Settings.mems[XdrvMailbox.index -1])); #endif // USE_EXPRESSION diff --git a/sonoff/xdrv_10_scripter.ino b/sonoff/xdrv_10_scripter.ino index 696c7750f2f6..ccf98a592479 100644 --- a/sonoff/xdrv_10_scripter.ino +++ b/sonoff/xdrv_10_scripter.ino @@ -52,6 +52,9 @@ keywords if then else endif, or, and are better readable for beginners (others m #define SCRIPT_MAXPERM (MAX_RULE_MEMS*10)-4/sizeof(float) #define MAX_SCRIPT_SIZE MAX_RULE_SIZE*MAX_RULE_SETS +// offsets epoch readings by 1.1.2019 00:00:00 to fit into float with second resolution +#define EPOCH_OFFSET 1546300800 + enum {OPER_EQU=1,OPER_PLS,OPER_MIN,OPER_MUL,OPER_DIV,OPER_PLSEQU,OPER_MINEQU,OPER_MULEQU,OPER_DIVEQU,OPER_EQUEQU,OPER_NOTEQU,OPER_GRTEQU,OPER_LOWEQU,OPER_GRT,OPER_LOW,OPER_PERC,OPER_XOR,OPER_AND,OPER_OR,OPER_ANDEQU,OPER_OREQU,OPER_XOREQU,OPER_PERCEQU}; enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD}; @@ -78,10 +81,12 @@ enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD}; LinkedList subscriptions; #endif //SUPPORT_MQTT_EVENT +#ifdef USE_DISPLAY #ifdef USE_TOUCH_BUTTONS #include extern VButton *buttons[MAXBUTTONS]; #endif +#endif typedef union { uint8_t data; @@ -134,6 +139,7 @@ struct SCRIPT_MEM { uint8_t *vnp_offset; char *glob_snp; // string vars pointer char *scriptptr; + char *section_ptr; char *scriptptr_bu; char *script_ram; uint16_t script_size; @@ -1009,7 +1015,13 @@ char *isvar(char *lp, uint8_t *vtype,struct T_INDEX *tind,float *fp,char *sp,Jso return lp+len; } } else { - if (fp) *fp=CharToFloat((char*)str_value); + if (fp) { + if (!strncmp(vn.c_str(),"Epoch",5)) { + *fp=atoi(str_value)-(uint32_t)EPOCH_OFFSET; + } else { + *fp=CharToFloat((char*)str_value); + } + } *vtype=NUM_RES; tind->bits.constant=1; tind->bits.is_string=0; @@ -1059,6 +1071,12 @@ chknext: goto exit; } break; + case 'e': + if (!strncmp(vname,"epoch",5)) { + fvar=UtcTime()-(uint32_t)EPOCH_OFFSET; + goto exit; + } + break; #ifdef USE_SCRIPT_FATFS case 'f': if (!strncmp(vname,"fo(",3)) { @@ -1634,6 +1652,7 @@ chknext: if (sp) strlcpy(sp,Settings.mqtt_topic,glob_script_mem.max_ssize); goto strexit; } +#ifdef USE_DISPLAY #ifdef USE_TOUCH_BUTTONS if (!strncmp(vname,"tbut[",5)) { GetNumericResult(vname+5,OPER_EQU,&fvar,0); @@ -1649,6 +1668,7 @@ chknext: goto exit; } +#endif #endif break; case 'u': @@ -2733,7 +2753,10 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { if (!strncmp(lp,type,tlen)) { // found section section=1; - if (check) return 99; + glob_script_mem.section_ptr=lp; + if (check) { + return 99; + } // check for subroutine if (*type=='#') { // check for parameter @@ -3387,6 +3410,7 @@ bool ScriptMqttData(void) //This topic is subscribed by us, so serve it serviced = true; String value; + String lkey; if (event_item.Key.length() == 0) { //If did not specify Key value = sData; } else { //If specified Key, need to parse Key/Value from JSON data @@ -3399,17 +3423,24 @@ bool ScriptMqttData(void) if ((dot = key1.indexOf('.')) > 0) { key2 = key1.substring(dot+1); key1 = key1.substring(0, dot); + lkey=key2; if (!jsonData[key1][key2].success()) break; //Failed to get the key/value, ignore this message. value = (const char *)jsonData[key1][key2]; } else { if (!jsonData[key1].success()) break; value = (const char *)jsonData[key1]; + lkey=key1; } } value.trim(); - char sbuffer[128]; - snprintf_P(sbuffer, sizeof(sbuffer), PSTR(">%s=\"%s\"\n"), event_item.Event.c_str(), value.c_str()); + + if (!strncmp(lkey.c_str(),"Epoch",5)) { + uint32_t ep=atoi(value.c_str())-(uint32_t)EPOCH_OFFSET; + snprintf_P(sbuffer, sizeof(sbuffer), PSTR(">%s=%d\n"), event_item.Event.c_str(),ep); + } else { + snprintf_P(sbuffer, sizeof(sbuffer), PSTR(">%s=\"%s\"\n"), event_item.Event.c_str(), value.c_str()); + } //toLog(sbuffer); execute_script(sbuffer); } @@ -3542,6 +3573,93 @@ String ScriptUnsubscribe(const char * data, int data_len) } #endif // SUPPORT_MQTT_EVENT +#ifdef USE_SCRIPT_WEB_DISPLAY +void ScriptWebShow(void) { + uint8_t web_script=Run_Scripter(">W",-2,0); + if (web_script==99) { + char line[128]; + char tmp[128]; + char *lp=glob_script_mem.section_ptr+2; + while (lp) { + while (*lp==SCRIPT_EOL) { + lp++; + } + if (!*lp || *lp=='#' || *lp=='>') { + break; + } + + // send this line to web + memcpy(line,lp,sizeof(line)); + line[sizeof(line)-1]=0; + char *cp=line; + for (uint32_t i=0; iJ",-2,0); + if (web_script==99) { + char line[128]; + char tmp[128]; + char *lp=glob_script_mem.section_ptr+2; + while (lp) { + while (*lp==SCRIPT_EOL) { + lp++; + } + if (!*lp || *lp=='#' || *lp=='>') { + break; + } + + // send this line to mqtt + memcpy(line,lp,sizeof(line)); + line[sizeof(line)-1]=0; + char *cp=line; + for (uint32_t i=0; itype < 17) // Toggle Relays { if (!toggle_inhibit) { - ExecuteCommandPower((chan->type) -8, 2, SRC_KNX); + ExecuteCommandPower((chan->type) -8, POWER_TOGGLE, SRC_KNX); if (Settings.flag.knx_enable_enhancement) { toggle_inhibit = TOGGLE_INHIBIT_TIME; } diff --git a/sonoff/xdrv_15_pca9685.ino b/sonoff/xdrv_15_pca9685.ino index 906207851eec..fb1a923d54fa 100644 --- a/sonoff/xdrv_15_pca9685.ino +++ b/sonoff/xdrv_15_pca9685.ino @@ -166,8 +166,7 @@ bool PCA9685_Command(void) void PCA9685_OutputTelemetry(bool telemetry) { if (0 == pca9685_detected) { return; } // We do not do this if the PCA9685 has not been detected - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"PCA9685\":{\"PWM_FREQ\":%i,"),pca9685_freq); + ResponseTime_P(PSTR(",\"PCA9685\":{\"PWM_FREQ\":%i,"),pca9685_freq); for (uint32_t pin=0;pin<16;pin++) { ResponseAppend_P(PSTR("\"PWM%i\":%i,"),pin,pca9685_pin_pwm_value[pin]); } diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyamcu.ino similarity index 56% rename from sonoff/xdrv_16_tuyadimmer.ino rename to sonoff/xdrv_16_tuyamcu.ino index 608236f4b69e..c609395d76a1 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyamcu.ino @@ -1,5 +1,5 @@ /* - xdrv_16_tuyadimmer.ino - Tuya dimmer support for Sonoff-Tasmota + xdrv_16_tuyamcu.ino - Tuya MCU support for Sonoff-Tasmota Copyright (C) 2019 digiblur, Joel Stein and Theo Arends @@ -18,7 +18,7 @@ */ #ifdef USE_LIGHT -#ifdef USE_TUYA_DIMMER +#ifdef USE_TUYA_MCU #define XDRV_16 16 #define XNRG_08 8 @@ -61,10 +61,156 @@ struct TUYA { int byte_counter = 0; // Index in serial receive buffer } Tuya; + +enum TuyaSupportedFunctions { + TUYA_MCU_FUNC_NONE, + TUYA_MCU_FUNC_SWT1 = 1, // Buttons + TUYA_MCU_FUNC_SWT2, + TUYA_MCU_FUNC_SWT3, + TUYA_MCU_FUNC_SWT4, + TUYA_MCU_FUNC_REL1 = 11, // Relays + TUYA_MCU_FUNC_REL2, + TUYA_MCU_FUNC_REL3, + TUYA_MCU_FUNC_REL4, + TUYA_MCU_FUNC_REL5, + TUYA_MCU_FUNC_REL6, + TUYA_MCU_FUNC_REL7, + TUYA_MCU_FUNC_REL8, + TUYA_MCU_FUNC_DIMMER = 21, + TUYA_MCU_FUNC_POWER = 31, + TUYA_MCU_FUNC_CURRENT, + TUYA_MCU_FUNC_VOLTAGE, + TUYA_MCU_FUNC_REL1_INV = 41, // Inverted Relays + TUYA_MCU_FUNC_REL2_INV, + TUYA_MCU_FUNC_REL3_INV, + TUYA_MCU_FUNC_REL4_INV, + TUYA_MCU_FUNC_REL5_INV, + TUYA_MCU_FUNC_REL6_INV, + TUYA_MCU_FUNC_REL7_INV, + TUYA_MCU_FUNC_REL8_INV, + TUYA_MCU_FUNC_LAST = 255 +}; + +const char kTuyaCommand[] PROGMEM = "|" // No prefix + D_CMND_TUYA_MCU; + +void (* const TuyaCommand[])(void) PROGMEM = { + &CmndTuyaMcu +}; + + +/* + +TuyaMcu fnid,dpid + +*/ + +void CmndTuyaMcu(void) { + if (XdrvMailbox.data_len > 0) { + char *p; + uint8_t i = 0; + uint8_t parm[3] = { 0 }; + for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 2; str = strtok_r(nullptr, ", ", &p)) { + parm[i] = strtoul(str, nullptr, 0); + i++; + } + + if (TuyaFuncIdValid(parm[0])) { + TuyaAddMcuFunc(parm[0], parm[1]); + restart_flag = 2; + } else { + AddLog_P2(LOG_LEVEL_ERROR, PSTR("TYA: TuyaMcu Invalid function id=%d"), parm[0]); + } + + } + + Response_P(PSTR("[")); + bool added = false; + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + if (Settings.tuya_fnid_map[i].fnid != 0) { + if (added) { + ResponseAppend_P(PSTR(",")); + } + ResponseAppend_P(PSTR("{\"fnId\":%d, \"dpId\":%d}" ), Settings.tuya_fnid_map[i].fnid, Settings.tuya_fnid_map[i].dpid); + added = true; + } + } + ResponseAppend_P(PSTR("]")); +} + /*********************************************************************************************\ * Internal Functions \*********************************************************************************************/ +void TuyaAddMcuFunc(uint8_t fnId, uint8_t dpId) { + bool added = false; + + if (fnId == 0 || dpId == 0) { // Delete entry + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + if ((dpId > 0 && Settings.tuya_fnid_map[i].dpid == dpId) || (fnId > TUYA_MCU_FUNC_NONE && Settings.tuya_fnid_map[i].fnid == fnId)) { + Settings.tuya_fnid_map[i].fnid = TUYA_MCU_FUNC_NONE; + Settings.tuya_fnid_map[i].dpid = 0; + break; + } + } + } else { // Add or update + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + if (Settings.tuya_fnid_map[i].dpid == dpId || Settings.tuya_fnid_map[i].dpid == 0 || Settings.tuya_fnid_map[i].fnid == fnId || Settings.tuya_fnid_map[i].fnid == 0) { + if (!added) { // Update entry if exisiting entry or add + Settings.tuya_fnid_map[i].fnid = fnId; + Settings.tuya_fnid_map[i].dpid = dpId; + added = true; + } else if (Settings.tuya_fnid_map[i].dpid == dpId || Settings.tuya_fnid_map[i].fnid == fnId) { // Remove existing entry if added to empty place + Settings.tuya_fnid_map[i].fnid = TUYA_MCU_FUNC_NONE; + Settings.tuya_fnid_map[i].dpid = 0; + } + } + } + } + UpdateDevices(); +} + +void UpdateDevices() { + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + uint8_t fnId = Settings.tuya_fnid_map[i].fnid; + if (fnId > TUYA_MCU_FUNC_NONE && Settings.tuya_fnid_map[i].dpid > 0) { + + if (fnId >= TUYA_MCU_FUNC_REL1 && fnId <= TUYA_MCU_FUNC_REL8) { //Relay + bitClear(rel_inverted, fnId - TUYA_MCU_FUNC_REL1); + } else if (fnId >= TUYA_MCU_FUNC_REL1_INV && fnId <= TUYA_MCU_FUNC_REL8_INV) { // Inverted Relay + bitSet(rel_inverted, fnId - TUYA_MCU_FUNC_REL1_INV); + } + + } + } +} + +inline bool TuyaFuncIdValid(uint8_t fnId) { + return (fnId >= TUYA_MCU_FUNC_SWT1 && fnId <= TUYA_MCU_FUNC_SWT4) || + (fnId >= TUYA_MCU_FUNC_REL1 && fnId <= TUYA_MCU_FUNC_REL8) || + fnId == TUYA_MCU_FUNC_DIMMER || + (fnId >= TUYA_MCU_FUNC_POWER && fnId <= TUYA_MCU_FUNC_VOLTAGE) || + (fnId >= TUYA_MCU_FUNC_REL1_INV && fnId <= TUYA_MCU_FUNC_REL8_INV); +} + +uint8_t TuyaGetFuncId(uint8_t dpid) { + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + if (Settings.tuya_fnid_map[i].dpid == dpid) { + return Settings.tuya_fnid_map[i].fnid; + } + } + return TUYA_MCU_FUNC_NONE; +} + +uint8_t TuyaGetDpId(uint8_t fnId) { + for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { + if (Settings.tuya_fnid_map[i].fnid == fnId) { + return Settings.tuya_fnid_map[i].dpid; + } + } + return 0; +} + void TuyaSendCmd(uint8_t cmd, uint8_t payload[] = nullptr, uint16_t payload_len = 0) { uint8_t checksum = (0xFF + cmd + (payload_len >> 8) + (payload_len & 0xFF)); @@ -131,7 +277,7 @@ bool TuyaSetPower(void) int16_t source = XdrvMailbox.payload; if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction - TuyaSendBool(active_device, bitRead(rpower, active_device-1)); + TuyaSendBool(active_device, bitRead(rpower, active_device-1) ^ bitRead(rel_inverted, active_device-1)); status = true; } return status; @@ -146,24 +292,26 @@ bool TuyaSetChannels(void) void LightSerialDuty(uint8_t duty) { - if (duty > 0 && !Tuya.ignore_dim && TuyaSerial) { + uint8_t dpid = TuyaGetDpId(TUYA_MCU_FUNC_DIMMER); + if (duty > 0 && !Tuya.ignore_dim && TuyaSerial && dpid > 0) { if (Settings.flag3.tuya_dimmer_min_limit) { // Enable dimming limit SetOption69: Enabled by default if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - if (Settings.flag3.tuya_disable_dimmer == 0) { duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); if (Tuya.new_dim != duty) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); - TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid); + TuyaSendValue(dpid, duty); } } - } else { + } else if (dpid > 0) { Tuya.ignore_dim = false; // reset flag if (Settings.flag3.tuya_disable_dimmer == 0) { duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set } + } else { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: Cannot set dimmer. Dimmer Id unknown")); // } } @@ -189,6 +337,7 @@ void TuyaResetWifi(void) void TuyaPacketProcess(void) { char scmnd[20]; + uint8_t fnId = TUYA_MCU_FUNC_NONE; switch (Tuya.buffer[3]) { @@ -201,57 +350,72 @@ void TuyaPacketProcess(void) break; case TUYA_CMD_STATE: - if (Tuya.buffer[5] == 5) { // on/off packet - - /*if ((power || Settings.light_dimmer > 0) && (power != Tuya.buffer[10])) { - ExecuteCommandPower(1, Tuya.buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction - }*/ - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Device-%d --> MCU State: %s Current State:%s"),Tuya.buffer[6],Tuya.buffer[10]?"On":"Off",bitRead(power, Tuya.buffer[6]-1)?"On":"Off"); - if ((power || Settings.light_dimmer > 0) && (Tuya.buffer[10] != bitRead(power, Tuya.buffer[6]-1))) { - ExecuteCommandPower(Tuya.buffer[6], Tuya.buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction - } - } - else if (Tuya.buffer[5] == 8) { // Long value packet + fnId = TuyaGetFuncId(Tuya.buffer[6]); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: FnId=%d is set for dpId=%d"), fnId, Tuya.buffer[6]); + // if (TuyaFuncIdValid(fnId)) { + if (Tuya.buffer[5] == 5) { // on/off packet + + if (fnId >= TUYA_MCU_FUNC_REL1 && fnId <= TUYA_MCU_FUNC_REL8) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Relay-%d --> MCU State: %s Current State:%s"), fnId - TUYA_MCU_FUNC_REL1 + 1, Tuya.buffer[10]?"On":"Off",bitRead(power, fnId - TUYA_MCU_FUNC_REL1)?"On":"Off"); + if ((power || Settings.light_dimmer > 0) && (Tuya.buffer[10] != bitRead(power, fnId - TUYA_MCU_FUNC_REL1))) { + ExecuteCommandPower(fnId - TUYA_MCU_FUNC_REL1 + 1, Tuya.buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction + } + } else if (fnId >= TUYA_MCU_FUNC_REL1_INV && fnId <= TUYA_MCU_FUNC_REL8_INV) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Relay-%d-Inverted --> MCU State: %s Current State:%s"), fnId - TUYA_MCU_FUNC_REL1_INV + 1, Tuya.buffer[10]?"Off":"On",bitRead(power, fnId - TUYA_MCU_FUNC_REL1_INV) ^ 1?"Off":"On"); + if (Tuya.buffer[10] != bitRead(power, fnId - TUYA_MCU_FUNC_REL1_INV) ^ 1) { + ExecuteCommandPower(fnId - TUYA_MCU_FUNC_REL1_INV + 1, Tuya.buffer[10] ^ 1, SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction + } + } else if (fnId >= TUYA_MCU_FUNC_SWT1 && fnId <= TUYA_MCU_FUNC_SWT4) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Switch-%d --> MCU State: %d Current State:%d"),fnId - TUYA_MCU_FUNC_SWT1 + 1,Tuya.buffer[10], SwitchGetVirtual(fnId - TUYA_MCU_FUNC_SWT1)); - if (Settings.flag3.tuya_disable_dimmer == 0) { - if (!Settings.param[P_TUYA_DIMMER_ID]) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), Tuya.buffer[6]); - Settings.param[P_TUYA_DIMMER_ID] = Tuya.buffer[6]; - } - if (Settings.param[P_TUYA_DIMMER_ID] == Tuya.buffer[6]) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]); - Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100); - if ((power || Settings.flag3.tuya_apply_o20) && (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { - Tuya.ignore_dim = true; - - snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), Tuya.new_dim ); - ExecuteCommand(scmnd, SRC_SWITCH); + if (SwitchGetVirtual(fnId - TUYA_MCU_FUNC_SWT1) != Tuya.buffer[10]) { + SwitchSetVirtual(fnId - TUYA_MCU_FUNC_SWT1, Tuya.buffer[10]); + SwitchHandler(1); } } + } + else if (Tuya.buffer[5] == 8) { // Long value packet + if (fnId == TUYA_MCU_FUNC_DIMMER) { + // if (!Settings.param[P_ex_TUYA_DIMMER_ID]) { + // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), Tuya.buffer[6]); + // Settings.param[P_ex_TUYA_DIMMER_ID] = Tuya.buffer[6]; + // } + // if (Settings.param[P_ex_TUYA_DIMMER_ID] == Tuya.buffer[6]) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]); + Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100); + if ((power || Settings.flag3.tuya_apply_o20) && (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { + Tuya.ignore_dim = true; + + snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), Tuya.new_dim ); + ExecuteCommand(scmnd, SRC_SWITCH); + } + // } + } -#ifdef USE_ENERGY_SENSOR - if (Settings.param[P_TUYA_VOLTAGE_ID] == Tuya.buffer[6]) { - Energy.voltage = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10; - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Voltage=%d"), Settings.param[P_TUYA_VOLTAGE_ID], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); - } else if (Settings.param[P_TUYA_CURRENT_ID] == Tuya.buffer[6]) { - Energy.current = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 1000; - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Current=%d"), Settings.param[P_TUYA_CURRENT_ID], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); - } else if (Settings.param[P_TUYA_POWER_ID] == Tuya.buffer[6]) { - Energy.active_power = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10; - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Active_Power=%d"), Settings.param[P_TUYA_POWER_ID], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); - - if (Tuya.lastPowerCheckTime != 0 && Energy.active_power > 0) { - Energy.kWhtoday += (float)Energy.active_power * (Rtc.utc_time - Tuya.lastPowerCheckTime) / 36; - EnergyUpdateToday(); + #ifdef USE_ENERGY_SENSOR + else if (fnId == TUYA_MCU_FUNC_VOLTAGE) { + Energy.voltage = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10; + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Voltage=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); + } else if (fnId == TUYA_MCU_FUNC_CURRENT) { + Energy.current = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 1000; + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Current=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); + } else if (fnId == TUYA_MCU_FUNC_POWER) { + Energy.active_power = (float)(Tuya.buffer[12] << 8 | Tuya.buffer[13]) / 10; + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Rx ID=%d Active_Power=%d"), Tuya.buffer[6], (Tuya.buffer[12] << 8 | Tuya.buffer[13])); + + if (Tuya.lastPowerCheckTime != 0 && Energy.active_power > 0) { + Energy.kWhtoday += (float)Energy.active_power * (Rtc.utc_time - Tuya.lastPowerCheckTime) / 36; + EnergyUpdateToday(); + } + Tuya.lastPowerCheckTime = Rtc.utc_time; } - Tuya.lastPowerCheckTime = Rtc.utc_time; - } else if (Settings.param[P_TUYA_DIMMER_ID] != Tuya.buffer[6]){ - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Unknown ID=%d"), Tuya.buffer[6]); - } -#endif // USE_ENERGY_SENSOR + #endif // USE_ENERGY_SENSOR - } + } + // } else { + // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Unknown FnId=%s for dpId=%s"), fnId, Tuya.buffer[6]); + // } break; case TUYA_CMD_WIFI_RESET: @@ -266,9 +430,9 @@ void TuyaPacketProcess(void) break; case TUYA_CMD_MCU_CONF: - AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: RX MCU configuration")); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX MCU configuration Mode=%d"), Tuya.buffer[5]); - if (Tuya.buffer[5] == 2) { + if (Tuya.buffer[5] == 2) { // Processing by ESP module mode uint8_t led1_gpio = Tuya.buffer[6]; uint8_t key1_gpio = Tuya.buffer[7]; bool key1_set = false; @@ -307,21 +471,41 @@ bool TuyaModuleSelected(void) Settings.my_gp.io[3] = GPIO_TUYA_RX; restart_flag = 2; } - if (Settings.flag3.tuya_disable_dimmer == 0) { + + if (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER) == 0 && TUYA_DIMMER_ID > 0) { + TuyaAddMcuFunc(TUYA_MCU_FUNC_DIMMER, TUYA_DIMMER_ID); + } + + bool relaySet = false; + + devices_present--; + + for (uint8_t i = 0 ; i < MAX_TUYA_FUNCTIONS; i++) { + if ((Settings.tuya_fnid_map[i].fnid >= TUYA_MCU_FUNC_REL1 && Settings.tuya_fnid_map[i].fnid <= TUYA_MCU_FUNC_REL8 ) || + (Settings.tuya_fnid_map[i].fnid >= TUYA_MCU_FUNC_REL1_INV && Settings.tuya_fnid_map[i].fnid <= TUYA_MCU_FUNC_REL8_INV )) { + relaySet = true; + devices_present++; + } + } + + if (!relaySet) { + TuyaAddMcuFunc(TUYA_MCU_FUNC_REL1, 1); + devices_present++; + SettingsSaveAll(); + } + + if (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER) != 0) { light_type = LT_SERIAL1; } else { light_type = LT_BASIC; } + UpdateDevices(); return true; } void TuyaInit(void) { - devices_present += Settings.param[P_TUYA_RELAYS]; // SetOption41 - Add virtual relays if present - if (!Settings.param[P_TUYA_DIMMER_ID]) { - Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID; - } Tuya.buffer = (char*)(malloc(TUYA_BUFFER_SIZE)); if (Tuya.buffer != nullptr) { TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2); @@ -434,11 +618,11 @@ int Xnrg08(uint8_t function) if (TUYA_DIMMER == my_module_type) { if (FUNC_PRE_INIT == function) { if (!energy_flg) { - if (Settings.param[P_TUYA_POWER_ID] != 0) { - if (Settings.param[P_TUYA_CURRENT_ID] == 0) { + if (TuyaGetDpId(TUYA_MCU_FUNC_POWER) != 0) { + if (TuyaGetDpId(TUYA_MCU_FUNC_CURRENT) == 0) { Energy.current_available = false; } - if (Settings.param[P_TUYA_VOLTAGE_ID] == 0) { + if (TuyaGetDpId(TUYA_MCU_FUNC_VOLTAGE) == 0) { Energy.voltage_available = false; } energy_flg = XNRG_08; @@ -486,10 +670,13 @@ bool Xdrv16(uint8_t function) case FUNC_SET_CHANNELS: result = TuyaSetChannels(); break; + case FUNC_COMMAND: + result = DecodeCommand(kTuyaCommand, TuyaCommand); + break; } } return result; } -#endif // USE_TUYA_DIMMER +#endif // USE_TUYA_MCU #endif // USE_LIGHT diff --git a/sonoff/xdrv_17_rcswitch.ino b/sonoff/xdrv_17_rcswitch.ino index 902304f0bc29..9d6d336604af 100644 --- a/sonoff/xdrv_17_rcswitch.ino +++ b/sonoff/xdrv_17_rcswitch.ino @@ -67,7 +67,7 @@ void RfReceiveCheck(void) } else { snprintf_P(stemp, sizeof(stemp), PSTR("\"0x%lX\""), (uint32_t)data); } - Response_P(PSTR("{\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_RF_DATA "\":%s,\"" D_JSON_RF_BITS "\":%d,\"" D_JSON_RF_PROTOCOL "\":%d,\"" D_JSON_RF_PULSE "\":%d}}"), + ResponseTime_P(PSTR(",\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_RF_DATA "\":%s,\"" D_JSON_RF_BITS "\":%d,\"" D_JSON_RF_PROTOCOL "\":%d,\"" D_JSON_RF_PULSE "\":%d}}"), stemp, bits, protocol, delay); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED)); XdrvRulesProcess(); diff --git a/sonoff/xdrv_22_sonoff_ifan.ino b/sonoff/xdrv_22_sonoff_ifan.ino index b2d9838f8785..0dbb31d504be 100644 --- a/sonoff/xdrv_22_sonoff_ifan.ino +++ b/sonoff/xdrv_22_sonoff_ifan.ino @@ -96,7 +96,7 @@ void SonoffIFanSetFanspeed(uint8_t fanspeed, bool sequence) fans = kIFan03Speed[fanspeed]; } for (uint32_t i = 2; i < 5; i++) { - uint8_t state = (fans &1) + 6; // Add no publishPowerState + uint8_t state = (fans &1) + POWER_OFF_NO_STATE; // Add no publishPowerState ExecuteCommandPower(i, state, SRC_IGNORE); // Use relay 2, 3 and 4 fans >>= 1; } diff --git a/sonoff/xdrv_23_zigbee.ino b/sonoff/xdrv_23_zigbee.ino deleted file mode 100644 index 71eb1aaaa577..000000000000 --- a/sonoff/xdrv_23_zigbee.ino +++ /dev/null @@ -1,412 +0,0 @@ -/* - xdrv_23_zigbee.ino - zigbee serial support for Sonoff-Tasmota - - Copyright (C) 2019 Theo Arends and Stephan Hadinger - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifdef USE_ZIGBEE - -#define XDRV_23 23 - -const uint32_t ZIGBEE_BUFFER_SIZE = 256; // Max ZNP frame is SOF+LEN+CMD1+CMD2+250+FCS = 255 -const uint8_t ZIGBEE_SOF = 0xFE; - -// State machine states -enum class ZnpStates { - S_START = 0, - S_READY -}; - -// ZNP Constants taken from https://github.com/Frans-Willem/AqaraHub/blob/master/src/znp/znp.h -enum class ZnpCommandType { POLL = 0, SREQ = 2, AREQ = 4, SRSP = 6 }; - -enum class ZnpSubsystem { - RPC_Error = 0, - SYS = 1, - MAC = 2, - NWK = 3, - AF = 4, - ZDO = 5, - SAPI = 6, - UTIL = 7, - DEBUG = 8, - APP = 9 -}; - -enum class ZnpStatus : uint8_t { - Success = 0x00, - Failure = 0x01, - InvalidParameter = 0x02, - MemError = 0x03, - BufferFull = 0x11 -}; - -typedef uint64_t IEEEAddress; -typedef uint16_t ShortAddress; - -enum class AddrMode : uint8_t { - NotPresent = 0, - Group = 1, - ShortAddress = 2, - IEEEAddress = 3, - Broadcast = 0xFF -}; - -// Commands in the SYS subsystem -enum class SysCommand : uint8_t { - RESET = 0x00, - PING = 0x01, - VERSION = 0x02, - SET_EXTADDR = 0x03, - GET_EXTADDR = 0x04, - RAM_READ = 0x05, - RAM_WRITE = 0x06, - OSAL_NV_ITEM_INIT = 0x07, - OSAL_NV_READ = 0x08, - OSAL_NV_WRITE = 0x09, - OSAL_START_TIMER = 0x0A, - OSAL_STOP_TIMER = 0x0B, - RANDOM = 0x0C, - ADC_READ = 0x0D, - GPIO = 0x0E, - STACK_TUNE = 0x0F, - SET_TIME = 0x10, - GET_TIME = 0x11, - OSAL_NV_DELETE = 0x12, - OSAL_NV_LENGTH = 0x13, - TEST_RF = 0x40, - TEST_LOOPBACK = 0x41, - RESET_IND = 0x80, - OSAL_TIMER_EXPIRED = 0x81, -}; - -// Commands in the AF subsystem -enum class AfCommand : uint8_t { - REGISTER = 0x00, - DATA_REQUEST = 0x01, - DATA_REQUEST_EXT = 0x02, - DATA_REQUEST_SRC_RTG = 0x03, - INTER_PAN_CTL = 0x10, - DATA_STORE = 0x11, - DATA_RETRIEVE = 0x12, - APSF_CONFIG_SET = 0x13, - DATA_CONFIRM = 0x80, - REFLECT_ERROR = 0x83, - INCOMING_MSG = 0x81, - INCOMING_MSG_EXT = 0x82 -}; - -// Commands in the ZDO subsystem -enum class ZdoCommand : uint8_t { - NWK_ADDR_REQ = 0x00, - IEEE_ADDR_REQ = 0x01, - NODE_DESC_REQ = 0x02, - POWER_DESC_REQ = 0x03, - SIMPLE_DESC_REQ = 0x04, - ACTIVE_EP_REQ = 0x05, - MATCH_DESC_REQ = 0x06, - COMPLEX_DESC_REQ = 0x07, - USER_DESC_REQ = 0x08, - DEVICE_ANNCE = 0x0A, - USER_DESC_SET = 0x0B, - SERVER_DISC_REQ = 0x0C, - END_DEVICE_BIND_REQ = 0x20, - BIND_REQ = 0x21, - UNBIND_REQ = 0x22, - SET_LINK_KEY = 0x23, - REMOVE_LINK_KEY = 0x24, - GET_LINK_KEY = 0x25, - MGMT_NWK_DISC_REQ = 0x30, - MGMT_LQI_REQ = 0x31, - MGMT_RTQ_REQ = 0x32, - MGMT_BIND_REQ = 0x33, - MGMT_LEAVE_REQ = 0x34, - MGMT_DIRECT_JOIN_REQ = 0x35, - MGMT_PERMIT_JOIN_REQ = 0x36, - MGMT_NWK_UPDATE_REQ = 0x37, - MSG_CB_REGISTER = 0x3E, - MGS_CB_REMOVE = 0x3F, - STARTUP_FROM_APP = 0x40, - AUTO_FIND_DESTINATION = 0x41, - EXT_REMOVE_GROUP = 0x47, - EXT_REMOVE_ALL_GROUP = 0x48, - EXT_FIND_ALL_GROUPS_ENDPOINT = 0x49, - EXT_FIND_GROUP = 0x4A, - EXT_ADD_GROUP = 0x4B, - EXT_COUNT_ALL_GROUPS = 0x4C, - NWK_ADDR_RSP = 0x80, - IEEE_ADDR_RSP = 0x81, - NODE_DESC_RSP = 0x82, - POWER_DESC_RSP = 0x83, - SIMPLE_DESC_RSP = 0x84, - ACTIVE_EP_RSP = 0x85, - MATCH_DESC_RSP = 0x86, - COMPLEX_DESC_RSP = 0x87, - USER_DESC_RSP = 0x88, - USER_DESC_CONF = 0x89, - SERVER_DISC_RSP = 0x8A, - END_DEVICE_BIND_RSP = 0xA0, - BIND_RSP = 0xA1, - UNBIND_RSP = 0xA2, - MGMT_NWK_DISC_RSP = 0xB0, - MGMT_LQI_RSP = 0xB1, - MGMT_RTG_RSP = 0xB2, - MGMT_BIND_RSP = 0xB3, - MGMT_LEAVE_RSP = 0xB4, - MGMT_DIRECT_JOIN_RSP = 0xB5, - MGMT_PERMIT_JOIN_RSP = 0xB6, - STATE_CHANGE_IND = 0xC0, - END_DEVICE_ANNCE_IND = 0xC1, - MATCH_DESC_RSP_SENT = 0xC2, - STATUS_ERROR_RSP = 0xC3, - SRC_RTG_IND = 0xC4, - LEAVE_IND = 0xC9, - TC_DEV_IND = 0xCA, - PERMIT_JOIN_IND = 0xCB, - MSG_CB_INCOMING = 0xFF -}; - -// Commands in the SAPI subsystem -enum class SapiCommand : uint8_t { - START_REQUEST = 0x00, - BIND_DEVICE = 0x01, - ALLOW_BIND = 0x02, - SEND_DATA_REQUEST = 0x03, - READ_CONFIGURATION = 0x04, - WRITE_CONFIGURATION = 0x05, - GET_DEVICE_INFO = 0x06, - FIND_DEVICE_REQUEST = 0x07, - PERMIT_JOINING_REQUEST = 0x08, - SYSTEM_RESET = 0x09, - START_CONFIRM = 0x80, - BIND_CONFIRM = 0x81, - ALLOW_BIND_CONFIRM = 0x82, - SEND_DATA_CONFIRM = 0x83, - FIND_DEVICE_CONFIRM = 0x85, - RECEIVE_DATA_INDICATION = 0x87, -}; - -// Commands in the UTIL subsystem -enum class UtilCommand : uint8_t { - GET_DEVICE_INFO = 0x00, - GET_NV_INFO = 0x01, - SET_PANID = 0x02, - SET_CHANNELS = 0x03, - SET_SECLEVEL = 0x04, - SET_PRECFGKEY = 0x05, - CALLBACK_SUB_CMD = 0x06, - KEY_EVENT = 0x07, - TIME_ALIVE = 0x09, - LED_CONTROL = 0x0A, - TEST_LOOPBACK = 0x10, - DATA_REQ = 0x11, - SRC_MATCH_ENABLE = 0x20, - SRC_MATCH_ADD_ENTRY = 0x21, - SRC_MATCH_DEL_ENTRY = 0x22, - SRC_MATCH_CHECK_SRC_ADDR = 0x23, - SRC_MATCH_ACK_ALL_PENDING = 0x24, - SRC_MATCH_CHECK_ALL_PENDING = 0x25, - ADDRMGR_EXT_ADDR_LOOKUP = 0x40, - ADDRMGR_NWK_ADDR_LOOKUP = 0x41, - APSME_LINK_KEY_DATA_GET = 0x44, - APSME_LINK_KEY_NV_ID_GET = 0x45, - ASSOC_COUNT = 0x48, - ASSOC_FIND_DEVICE = 0x49, - ASSOC_GET_WITH_ADDRESS = 0x4A, - APSME_REQUEST_KEY_CMD = 0x4B, - ZCL_KEY_EST_INIT_EST = 0x80, - ZCL_KEY_EST_SIGN = 0x81, - UTIL_SYNC_REQ = 0xE0, - ZCL_KEY_ESTABLISH_IND = 0xE1 -}; - -enum class Capability : uint16_t { - SYS = 0x0001, - MAC = 0x0002, - NWK = 0x0004, - AF = 0x0008, - ZDO = 0x0010, - SAPI = 0x0020, - UTIL = 0x0040, - DEBUG = 0x0080, - APP = 0x0100, - ZOAD = 0x1000 -}; - -enum class ConfigurationOption : uint8_t { - STARTUP_OPTION = 0x03, - POLL_RATE = 0x24, - QUEUED_POLL_RATE = 0x25, - RESPONSE_POLL_RATE = 0x26, - POLL_FAILURE_RETRIES = 0x29, - INDIRECT_MSG_TIMEOUT = 0x2B, - ROUTE_EXPIRY_TIME = 0x2C, - EXTENDED_PAN_ID = 0x2D, - BCAST_RETRIES = 0x2E, - PASSIVE_ACK_TIMEOUT = 0x2F, - BCAST_DELIVERY_TIME = 0x30, - APS_FRAME_RETRIES = 0x43, - APS_ACK_WAIT_DURATION = 0x44, - BINDING_TIME = 0x46, - PRECFGKEY = 0x62, - PRECFGKEYS_ENABLE = 0x63, - SECURITY_MODE = 0x64, - USERDESC = 0x81, - PANID = 0x83, - CHANLIST = 0x84, - LOGICAL_TYPE = 0x87, - ZDO_DIRECT_CB = 0x8F -}; - -#define D_JSON_ZIGBEEZNPRECEIVED "ZigbeeZNPReceived" - -#define D_PRFX_ZIGBEE "Zigbee" -#define D_CMND_ZIGBEEZNPSEND "ZNPSend" - -const char kZigbeeCommands[] PROGMEM = D_PRFX_ZIGBEE "|" // Prefix - D_CMND_ZIGBEEZNPSEND; - -void (* const ZigbeeCommand[])(void) PROGMEM = - { &CmndZigbeeZNPSend }; - -#include - -TasmotaSerial *ZigbeeSerial = nullptr; - -unsigned long zigbee_polling_window = 0; -uint8_t *zigbee_buffer = nullptr; -uint32_t zigbee_in_byte_counter = 0; -uint32_t zigbee_frame_len = 256; -bool zigbee_active = true; -bool zigbee_raw = false; - -void ZigbeeInput(void) -{ - // Receive only valid ZNP frames: - // 00 - SOF = 0xFE - // 01 - Length of Data Field - 0..250 - // 02 - CMD1 - first byte of command - // 03 - CMD2 - second byte of command - // 04..FD - Data Field - // FE (or last) - FCS Checksum - - while (ZigbeeSerial->available()) { - yield(); - uint8_t zigbee_in_byte = ZigbeeSerial->read(); - - if ((0 == zigbee_in_byte_counter) && (ZIGBEE_SOF != zigbee_in_byte)) { - // waiting for SOF (Start Of Frame) byte, discard anything else - continue; // discard - } - - if (zigbee_in_byte_counter < zigbee_frame_len) { - zigbee_buffer[zigbee_in_byte_counter++] = zigbee_in_byte; - zigbee_polling_window = millis(); // Wait for more data - } else { - zigbee_polling_window = 0; // Publish now - break; - } - - // recalculate frame length - if (02 == zigbee_in_byte_counter) { - // We just received the Lenght byte - uint8_t len_byte = zigbee_buffer[1]; - if (len_byte > 250) len_byte = 250; // ZNP spec says len is 250 max - - zigbee_frame_len = len_byte + 5; // SOF + LEN + CMD1 + CMD2 + FCS = 5 bytes overhead - } - } - - if (zigbee_in_byte_counter && (millis() > (zigbee_polling_window + ZIGBEE_POLLING))) { - char hex_char[(zigbee_in_byte_counter * 2) + 2]; - Response_P(PSTR("{\"" D_JSON_ZIGBEEZNPRECEIVED "\":\"%s\"}"), - ToHex_P((unsigned char*)zigbee_buffer, zigbee_in_byte_counter, hex_char, sizeof(hex_char))); - MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZNPRECEIVED)); - XdrvRulesProcess(); - zigbee_in_byte_counter = 0; - zigbee_frame_len = 254; - } -} - -/********************************************************************************************/ - -void ZigbeeInit(void) -{ - zigbee_active = false; - if ((pin[GPIO_ZIGBEE_RX] < 99) && (pin[GPIO_ZIGBEE_TX] < 99)) { - ZigbeeSerial = new TasmotaSerial(pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX]); - if (ZigbeeSerial->begin(115200)) { // ZNP is 115200, RTS/CTS (ignored), 8N1 - if (ZigbeeSerial->hardwareSerial()) { - ClaimSerial(); - zigbee_buffer = (uint8_t*) serial_in_buffer; // Use idle serial buffer to save RAM - } else { - zigbee_buffer = (uint8_t*) malloc(ZIGBEE_BUFFER_SIZE); - } - zigbee_active = true; - ZigbeeSerial->flush(); - } - } -} - -/*********************************************************************************************\ - * Commands -\*********************************************************************************************/ - -void CmndZigbeeZNPSend(void) -{ - if (XdrvMailbox.data_len > 0) { - uint8_t code; - - char *codes = RemoveSpace(XdrvMailbox.data); - int32_t size = strlen(XdrvMailbox.data); - - while (size > 0) { - char stemp[3]; - strlcpy(stemp, codes, sizeof(stemp)); - code = strtol(stemp, nullptr, 16); - ZigbeeSerial->write(code); - size -= 2; - codes += 2; - } - } - ResponseCmndDone(); -} - -/*********************************************************************************************\ - * Interface -\*********************************************************************************************/ - -bool Xdrv23(uint8_t function) -{ - bool result = false; - - if (zigbee_active) { - switch (function) { - case FUNC_LOOP: - if (ZigbeeSerial) { ZigbeeInput(); } - break; - case FUNC_PRE_INIT: - ZigbeeInit(); - break; - case FUNC_COMMAND: - result = DecodeCommand(kZigbeeCommands, ZigbeeCommand); - break; - } - } - return result; -} - -#endif // USE_ZIGBEE diff --git a/sonoff/xdrv_23_zigbee_constants.ino b/sonoff/xdrv_23_zigbee_constants.ino new file mode 100644 index 000000000000..d87cc4af5a9b --- /dev/null +++ b/sonoff/xdrv_23_zigbee_constants.ino @@ -0,0 +1,407 @@ +/* + xdrv_23_zigbee_constants.ino - zigbee support for Sonoff-Tasmota + + Copyright (C) 2019 Theo Arends and Stephan Hadinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_ZIGBEE + +typedef uint64_t Z_IEEEAddress; +typedef uint16_t Z_ShortAddress; + +enum ZnpCommandType { + Z_POLL = 0x00, + Z_SREQ = 0x20, + Z_AREQ = 0x40, + Z_SRSP = 0x60 +}; + +enum ZnpSubsystem { + Z_RPC_Error = 0x00, + Z_SYS = 0x01, + Z_MAC = 0x02, + Z_NWK = 0x03, + Z_AF = 0x04, + Z_ZDO = 0x05, + Z_SAPI = 0x06, + Z_UTIL = 0x07, + Z_DEBUG = 0x08, + Z_APP = 0x09 +}; + +// Commands in the SYS subsystem +enum SysCommand { + SYS_RESET = 0x00, + SYS_PING = 0x01, + SYS_VERSION = 0x02, + SYS_SET_EXTADDR = 0x03, + SYS_GET_EXTADDR = 0x04, + SYS_RAM_READ = 0x05, + SYS_RAM_WRITE = 0x06, + SYS_OSAL_NV_ITEM_INIT = 0x07, + SYS_OSAL_NV_READ = 0x08, + SYS_OSAL_NV_WRITE = 0x09, + SYS_OSAL_START_TIMER = 0x0A, + SYS_OSAL_STOP_TIMER = 0x0B, + SYS_RANDOM = 0x0C, + SYS_ADC_READ = 0x0D, + SYS_GPIO = 0x0E, + SYS_STACK_TUNE = 0x0F, + SYS_SET_TIME = 0x10, + SYS_GET_TIME = 0x11, + SYS_OSAL_NV_DELETE = 0x12, + SYS_OSAL_NV_LENGTH = 0x13, + SYS_TEST_RF = 0x40, + SYS_TEST_LOOPBACK = 0x41, + SYS_RESET_IND = 0x80, + SYS_OSAL_TIMER_EXPIRED = 0x81, +}; +// Commands in the SAPI subsystem +enum SapiCommand { + SAPI_START_REQUEST = 0x00, + SAPI_BIND_DEVICE = 0x01, + SAPI_ALLOW_BIND = 0x02, + SAPI_SEND_DATA_REQUEST = 0x03, + SAPI_READ_CONFIGURATION = 0x04, + SAPI_WRITE_CONFIGURATION = 0x05, + SAPI_GET_DEVICE_INFO = 0x06, + SAPI_FIND_DEVICE_REQUEST = 0x07, + SAPI_PERMIT_JOINING_REQUEST = 0x08, + SAPI_SYSTEM_RESET = 0x09, + SAPI_START_CONFIRM = 0x80, + SAPI_BIND_CONFIRM = 0x81, + SAPI_ALLOW_BIND_CONFIRM = 0x82, + SAPI_SEND_DATA_CONFIRM = 0x83, + SAPI_FIND_DEVICE_CONFIRM = 0x85, + SAPI_RECEIVE_DATA_INDICATION = 0x87, +}; +enum Z_configuration { + CONF_EXTADDR = 0x01, + CONF_BOOTCOUNTER = 0x02, + CONF_STARTUP_OPTION = 0x03, + CONF_START_DELAY = 0x04, + CONF_NIB = 0x21, + CONF_DEVICE_LIST = 0x22, + CONF_ADDRMGR = 0x23, + CONF_POLL_RATE = 0x24, + CONF_QUEUED_POLL_RATE = 0x25, + CONF_RESPONSE_POLL_RATE = 0x26, + CONF_REJOIN_POLL_RATE = 0x27, + CONF_DATA_RETRIES = 0x28, + CONF_POLL_FAILURE_RETRIES = 0x29, + CONF_STACK_PROFILE = 0x2A, + CONF_INDIRECT_MSG_TIMEOUT = 0x2B, + CONF_ROUTE_EXPIRY_TIME = 0x2C, + CONF_EXTENDED_PAN_ID = 0x2D, + CONF_BCAST_RETRIES = 0x2E, + CONF_PASSIVE_ACK_TIMEOUT = 0x2F, + CONF_BCAST_DELIVERY_TIME = 0x30, + CONF_NWK_MODE = 0x31, + CONF_CONCENTRATOR_ENABLE = 0x32, + CONF_CONCENTRATOR_DISCOVERY = 0x33, + CONF_CONCENTRATOR_RADIUS = 0x34, + CONF_CONCENTRATOR_RC = 0x36, + CONF_NWK_MGR_MODE = 0x37, + CONF_SRC_RTG_EXPIRY_TIME = 0x38, + CONF_ROUTE_DISCOVERY_TIME = 0x39, + CONF_NWK_ACTIVE_KEY_INFO = 0x3A, + CONF_NWK_ALTERN_KEY_INFO = 0x3B, + CONF_ROUTER_OFF_ASSOC_CLEANUP = 0x3C, + CONF_NWK_LEAVE_REQ_ALLOWED = 0x3D, + CONF_NWK_CHILD_AGE_ENABLE = 0x3E, + CONF_DEVICE_LIST_KA_TIMEOUT = 0x3F, + CONF_BINDING_TABLE = 0x41, + CONF_GROUP_TABLE = 0x42, + CONF_APS_FRAME_RETRIES = 0x43, + CONF_APS_ACK_WAIT_DURATION = 0x44, + CONF_APS_ACK_WAIT_MULTIPLIER = 0x45, + CONF_BINDING_TIME = 0x46, + CONF_APS_USE_EXT_PANID = 0x47, + CONF_APS_USE_INSECURE_JOIN = 0x48, + CONF_COMMISSIONED_NWK_ADDR = 0x49, + CONF_APS_NONMEMBER_RADIUS = 0x4B, + CONF_APS_LINK_KEY_TABLE = 0x4C, + CONF_APS_DUPREJ_TIMEOUT_INC = 0x4D, + CONF_APS_DUPREJ_TIMEOUT_COUNT = 0x4E, + CONF_APS_DUPREJ_TABLE_SIZE = 0x4F, + CONF_DIAGNOSTIC_STATS = 0x50, + CONF_SECURITY_LEVEL = 0x61, + CONF_PRECFGKEY = 0x62, + CONF_PRECFGKEYS_ENABLE = 0x63, + CONF_SECURITY_MODE = 0x64, + CONF_SECURE_PERMIT_JOIN = 0x65, + CONF_APS_LINK_KEY_TYPE = 0x66, + CONF_APS_ALLOW_R19_SECURITY = 0x67, + CONF_IMPLICIT_CERTIFICATE = 0x69, + CONF_DEVICE_PRIVATE_KEY = 0x6A, + CONF_CA_PUBLIC_KEY = 0x6B, + CONF_KE_MAX_DEVICES = 0x6C, + CONF_USE_DEFAULT_TCLK = 0x6D, + CONF_RNG_COUNTER = 0x6F, + CONF_RANDOM_SEED = 0x70, + CONF_TRUSTCENTER_ADDR = 0x71, + CONF_USERDESC = 0x81, + CONF_NWKKEY = 0x82, + CONF_PANID = 0x83, + CONF_CHANLIST = 0x84, + CONF_LEAVE_CTRL = 0x85, + CONF_SCAN_DURATION = 0x86, + CONF_LOGICAL_TYPE = 0x87, + CONF_NWKMGR_MIN_TX = 0x88, + CONF_NWKMGR_ADDR = 0x89, + CONF_ZDO_DIRECT_CB = 0x8F, + CONF_TCLK_TABLE_START = 0x0101, + ZNP_HAS_CONFIGURED = 0xF00 +}; + +// enum Z_nvItemIds { +// SCENE_TABLE = 145, +// MIN_FREE_NWK_ADDR = 146, +// MAX_FREE_NWK_ADDR = 147, +// MIN_FREE_GRP_ID = 148, +// MAX_FREE_GRP_ID = 149, +// MIN_GRP_IDS = 150, +// MAX_GRP_IDS = 151, +// OTA_BLOCK_REQ_DELAY = 152, +// SAPI_ENDPOINT = 161, +// SAS_SHORT_ADDR = 177, +// SAS_EXT_PANID = 178, +// SAS_PANID = 179, +// SAS_CHANNEL_MASK = 180, +// SAS_PROTOCOL_VER = 181, +// SAS_STACK_PROFILE = 182, +// SAS_STARTUP_CTRL = 183, +// SAS_TC_ADDR = 193, +// SAS_TC_MASTER_KEY = 194, +// SAS_NWK_KEY = 195, +// SAS_USE_INSEC_JOIN = 196, +// SAS_PRECFG_LINK_KEY = 197, +// SAS_NWK_KEY_SEQ_NUM = 198, +// SAS_NWK_KEY_TYPE = 199, +// SAS_NWK_MGR_ADDR = 200, +// SAS_CURR_TC_MASTER_KEY = 209, +// SAS_CURR_NWK_KEY = 210, +// SAS_CURR_PRECFG_LINK_KEY = 211, +// TCLK_TABLE_START = 257, +// TCLK_TABLE_END = 511, +// APS_LINK_KEY_DATA_START = 513, +// APS_LINK_KEY_DATA_END = 767, +// DUPLICATE_BINDING_TABLE = 768, +// DUPLICATE_DEVICE_LIST = 769, +// DUPLICATE_DEVICE_LIST_KA_TIMEOUT = 770, +//}; + +// +enum Z_Status { + Z_Success = 0x00, + Z_Failure = 0x01, + Z_InvalidParameter = 0x02, + Z_MemError = 0x03, + Z_Created = 0x09, + Z_BufferFull = 0x11 +}; + +enum Z_App_Profiles { + Z_PROF_IPM = 0x0101, // Industrial Plant Monitoring + Z_PROF_HA = 0x0104, // Home Automation -- the only supported right now + Z_PROF_CBA = 0x0105, // Commercial Building Automation + Z_PROF_TA = 0x0107, // Telecom Applications + Z_PROF_PHHC = 0x0108, // Personal Home & Hospital Care + Z_PROF_AMI = 0x0109, // Advanced Metering Initiative +}; + +enum Z_Device_Ids { + Z_DEVID_CONF_TOOL = 0x0005, + // from https://www.rfwireless-world.com/Terminology/Zigbee-Profile-ID-list.html + // Generic 0x0000 ON/OFF Switch + // 0x0001 Level Control Switch + // 0x0002 ON/OFF Output + // 0x0003 Level Controllable Output + // 0x0004 Scene Selector + // 0x0005 Configuration Tool + // 0x0006 Remote control + // 0x0007 Combined Interface + // 0x0008 Range Extender + // 0x0009 Mains Power Outlet + // Lighting 0x0100 ON/OFF Light + // 0x0101 Dimmable Light + // 0x0102 Color Dimmable Light + // 0x0103 ON/OFF Light Switch + // 0x0104 Dimmer Switch + // 0x0105 Color Dimmer Switch + // 0x0106 Light Sensor + // 0x0107 Occupancy Sensor + // Closures 0x0200 Shade + // 0x0201 Shade Controller + // HVAC 0x0300 Heating/Cooling Unit + // 0x0301 Thermostat + // 0x0302 Temperature Sensor + // 0x0303 Pump + // 0x0304 Pump Controller + // 0x0305 Pressure Sensor + // 0x0306 Flow sensor + // Intruder Alarm Systems 0x0400 IAS Control and Indicating Equipment + // 0x0401 IAS Ancillary Control Equipment + // 0x0402 IAS Zone + // 0x0403 IAS Warning Device +}; + +// enum class AddrMode : uint8_t { +// NotPresent = 0, +// Group = 1, +// ShortAddress = 2, +// IEEEAddress = 3, +// Broadcast = 0xFF +// }; +// +// +// +// Commands in the AF subsystem +enum AfCommand : uint8_t { + AF_REGISTER = 0x00, + AF_DATA_REQUEST = 0x01, + AF_DATA_REQUEST_EXT = 0x02, + AF_DATA_REQUEST_SRC_RTG = 0x03, + AF_INTER_PAN_CTL = 0x10, + AF_DATA_STORE = 0x11, + AF_DATA_RETRIEVE = 0x12, + AF_APSF_CONFIG_SET = 0x13, + AF_DATA_CONFIRM = 0x80, + AF_REFLECT_ERROR = 0x83, + AF_INCOMING_MSG = 0x81, + AF_INCOMING_MSG_EXT = 0x82 +}; +// +// Commands in the ZDO subsystem +enum : uint8_t { + ZDO_NWK_ADDR_REQ = 0x00, + ZDO_IEEE_ADDR_REQ = 0x01, + ZDO_NODE_DESC_REQ = 0x02, + ZDO_POWER_DESC_REQ = 0x03, + ZDO_SIMPLE_DESC_REQ = 0x04, + ZDO_ACTIVE_EP_REQ = 0x05, + ZDO_MATCH_DESC_REQ = 0x06, + ZDO_COMPLEX_DESC_REQ = 0x07, + ZDO_USER_DESC_REQ = 0x08, + ZDO_DEVICE_ANNCE = 0x0A, + ZDO_USER_DESC_SET = 0x0B, + ZDO_SERVER_DISC_REQ = 0x0C, + ZDO_END_DEVICE_BIND_REQ = 0x20, + ZDO_BIND_REQ = 0x21, + ZDO_UNBIND_REQ = 0x22, + ZDO_SET_LINK_KEY = 0x23, + ZDO_REMOVE_LINK_KEY = 0x24, + ZDO_GET_LINK_KEY = 0x25, + ZDO_MGMT_NWK_DISC_REQ = 0x30, + ZDO_MGMT_LQI_REQ = 0x31, + ZDO_MGMT_RTQ_REQ = 0x32, + ZDO_MGMT_BIND_REQ = 0x33, + ZDO_MGMT_LEAVE_REQ = 0x34, + ZDO_MGMT_DIRECT_JOIN_REQ = 0x35, + ZDO_MGMT_PERMIT_JOIN_REQ = 0x36, + ZDO_MGMT_NWK_UPDATE_REQ = 0x37, + ZDO_MSG_CB_REGISTER = 0x3E, + ZDO_MGS_CB_REMOVE = 0x3F, + ZDO_STARTUP_FROM_APP = 0x40, + ZDO_AUTO_FIND_DESTINATION = 0x41, + ZDO_EXT_REMOVE_GROUP = 0x47, + ZDO_EXT_REMOVE_ALL_GROUP = 0x48, + ZDO_EXT_FIND_ALL_GROUPS_ENDPOINT = 0x49, + ZDO_EXT_FIND_GROUP = 0x4A, + ZDO_EXT_ADD_GROUP = 0x4B, + ZDO_EXT_COUNT_ALL_GROUPS = 0x4C, + ZDO_NWK_ADDR_RSP = 0x80, + ZDO_IEEE_ADDR_RSP = 0x81, + ZDO_NODE_DESC_RSP = 0x82, + ZDO_POWER_DESC_RSP = 0x83, + ZDO_SIMPLE_DESC_RSP = 0x84, + ZDO_ACTIVE_EP_RSP = 0x85, + ZDO_MATCH_DESC_RSP = 0x86, + ZDO_COMPLEX_DESC_RSP = 0x87, + ZDO_USER_DESC_RSP = 0x88, + ZDO_USER_DESC_CONF = 0x89, + ZDO_SERVER_DISC_RSP = 0x8A, + ZDO_END_DEVICE_BIND_RSP = 0xA0, + ZDO_BIND_RSP = 0xA1, + ZDO_UNBIND_RSP = 0xA2, + ZDO_MGMT_NWK_DISC_RSP = 0xB0, + ZDO_MGMT_LQI_RSP = 0xB1, + ZDO_MGMT_RTG_RSP = 0xB2, + ZDO_MGMT_BIND_RSP = 0xB3, + ZDO_MGMT_LEAVE_RSP = 0xB4, + ZDO_MGMT_DIRECT_JOIN_RSP = 0xB5, + ZDO_MGMT_PERMIT_JOIN_RSP = 0xB6, + ZDO_STATE_CHANGE_IND = 0xC0, + ZDO_END_DEVICE_ANNCE_IND = 0xC1, + ZDO_MATCH_DESC_RSP_SENT = 0xC2, + ZDO_STATUS_ERROR_RSP = 0xC3, + ZDO_SRC_RTG_IND = 0xC4, + ZDO_LEAVE_IND = 0xC9, + ZDO_TC_DEV_IND = 0xCA, + ZDO_PERMIT_JOIN_IND = 0xCB, + ZDO_MSG_CB_INCOMING = 0xFF +}; + +//https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/t/475920 +enum ZdoStates { + ZDO_DEV_HOLD = 0x00, // Initialized - not started automatically + ZDO_DEV_INIT = 0x01, // Initialized - not connected to anything + ZDO_DEV_NWK_DISC = 0x02, // Discovering PANIDs to join + ZDO_DEV_NWK_JOINING = 0x03, // Joining a PAN + ZDO_DEV_NWK_REJOIN = 0x04, // ReJoining a PAN, only for end devices + ZDO_DEV_END_DEVICE_UNAUTH = 0x05, // Joined but not yet authenticated by trust center + ZDO_DEV_END_DEVICE = 0x06, // Started as a device after authentication. Note: you'll see this for both Routers or End Devices. + ZDO_DEV_ROUTER = 0x07, // Started as a Zigbee Router + ZDO_DEV_COORD_STARTING = 0x08, // Starting as a Zigbee Coordinator + ZDO_DEV_ZB_COORD = 0x09, // Started as a a Zigbee Coordinator + ZDO_DEV_NWK_ORPHAN = 0x0A, // Device has lost information about its parent. +}; +// +// Commands in the UTIL subsystem +enum Z_Util { + Z_UTIL_GET_DEVICE_INFO = 0x00, + Z_UTIL_GET_NV_INFO = 0x01, + Z_UTIL_SET_PANID = 0x02, + Z_UTIL_SET_CHANNELS = 0x03, + Z_UTIL_SET_SECLEVEL = 0x04, + Z_UTIL_SET_PRECFGKEY = 0x05, + Z_UTIL_CALLBACK_SUB_CMD = 0x06, + Z_UTIL_KEY_EVENT = 0x07, + Z_UTIL_TIME_ALIVE = 0x09, + Z_UTIL_LED_CONTROL = 0x0A, + Z_UTIL_TEST_LOOPBACK = 0x10, + Z_UTIL_DATA_REQ = 0x11, + Z_UTIL_SRC_MATCH_ENABLE = 0x20, + Z_UTIL_SRC_MATCH_ADD_ENTRY = 0x21, + Z_UTIL_SRC_MATCH_DEL_ENTRY = 0x22, + Z_UTIL_SRC_MATCH_CHECK_SRC_ADDR = 0x23, + Z_UTIL_SRC_MATCH_ACK_ALL_PENDING = 0x24, + Z_UTIL_SRC_MATCH_CHECK_ALL_PENDING = 0x25, + Z_UTIL_ADDRMGR_EXT_ADDR_LOOKUP = 0x40, + Z_UTIL_ADDRMGR_NWK_ADDR_LOOKUP = 0x41, + Z_UTIL_APSME_LINK_KEY_DATA_GET = 0x44, + Z_UTIL_APSME_LINK_KEY_NV_ID_GET = 0x45, + Z_UTIL_ASSOC_COUNT = 0x48, + Z_UTIL_ASSOC_FIND_DEVICE = 0x49, + Z_UTIL_ASSOC_GET_WITH_ADDRESS = 0x4A, + Z_UTIL_APSME_REQUEST_KEY_CMD = 0x4B, + Z_UTIL_ZCL_KEY_EST_INIT_EST = 0x80, + Z_UTIL_ZCL_KEY_EST_SIGN = 0x81, + Z_UTIL_UTIL_SYNC_REQ = 0xE0, + Z_UTIL_ZCL_KEY_ESTABLISH_IND = 0xE1 +}; + +#endif // USE_ZIGBEE diff --git a/sonoff/xdrv_23_zigbee_impl.ino b/sonoff/xdrv_23_zigbee_impl.ino new file mode 100644 index 000000000000..1653ed78caa1 --- /dev/null +++ b/sonoff/xdrv_23_zigbee_impl.ino @@ -0,0 +1,959 @@ +/* + xdrv_23_zigbee.ino - zigbee support for Sonoff-Tasmota + + Copyright (C) 2019 Theo Arends and Stephan Hadinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_ZIGBEE + +#define XDRV_23 23 + +const uint32_t ZIGBEE_BUFFER_SIZE = 256; // Max ZNP frame is SOF+LEN+CMD1+CMD2+250+FCS = 255 +const uint8_t ZIGBEE_SOF = 0xFE; +const uint8_t ZIGBEE_LABEL_ABORT = 99; // goto label 99 in case of fatal error +const uint8_t ZIGBEE_LABEL_READY = 20; // goto label 99 in case of fatal error + + +#include + +TasmotaSerial *ZigbeeSerial = nullptr; + +const char kZigbeeCommands[] PROGMEM = "|" D_CMND_ZIGBEEZNPSEND; + +void (* const ZigbeeCommand[])(void) PROGMEM = { &CmndZigbeeZNPSend }; + +typedef int32_t (*ZB_Func)(uint8_t value); +typedef int32_t (*ZB_RecvMsgFunc)(int32_t res, class SBuffer &buf); + +typedef union Zigbee_Instruction { + struct { + uint8_t i; // instruction + uint8_t d8; // 8 bits data + uint16_t d16; // 16 bits data + } i; + const void *p; // pointer + // const void *m; // for type checking only, message + // const ZB_Func f; + // const ZB_RecvMsgFunc fr; +} Zigbee_Instruction; +// +// Zigbee_Instruction z1 = { .i = {1,2,3}}; +// Zigbee_Instruction z3 = { .p = nullptr }; + +typedef struct Zigbee_Instruction_Type { + uint8_t instr; + uint8_t data; +} Zigbee_Instruction_Type; + +enum Zigbee_StateMachine_Instruction_Set { + // 2 bytes instructions + ZGB_INSTR_4_BYTES = 0, + ZGB_INSTR_NOOP = 0, // do nothing + ZGB_INSTR_LABEL, // define a label + ZGB_INSTR_GOTO, // goto label + ZGB_INSTR_ON_ERROR_GOTO, // goto label if error + ZGB_INSTR_ON_TIMEOUT_GOTO, // goto label if timeout + ZGB_INSTR_WAIT, // wait for x ms (in chunks of 100ms) + ZGB_INSTR_WAIT_FOREVER, // wait forever but state machine still active + ZGB_INSTR_STOP, // stop state machine with optional error code + + // 6 bytes instructions + ZGB_INSTR_8_BYTES = 0x80, + ZGB_INSTR_CALL = 0x80, // call a function + ZGB_INSTR_LOG, // log a message, if more detailed logging required, call a function + ZGB_INSTR_SEND, // send a ZNP message + ZGB_INSTR_WAIT_UNTIL, // wait until the specified message is received, ignore all others + ZGB_INSTR_WAIT_RECV, // wait for a message according to the filter + ZGB_ON_RECV_UNEXPECTED, // function to handle unexpected messages, or nullptr + + // 10 bytes instructions + ZGB_INSTR_12_BYTES = 0xF0, + ZGB_INSTR_WAIT_RECV_CALL, // wait for a filtered message and call function upon receive +}; + +#define ZI_NOOP() { .i = { ZGB_INSTR_NOOP, 0x00, 0x0000} }, +#define ZI_LABEL(x) { .i = { ZGB_INSTR_LABEL, (x), 0x0000} }, +#define ZI_GOTO(x) { .i = { ZGB_INSTR_GOTO, (x), 0x0000} }, +#define ZI_ON_ERROR_GOTO(x) { .i = { ZGB_INSTR_ON_ERROR_GOTO, (x), 0x0000} }, +#define ZI_ON_TIMEOUT_GOTO(x) { .i = { ZGB_INSTR_ON_TIMEOUT_GOTO, (x), 0x0000} }, +#define ZI_WAIT(x) { .i = { ZGB_INSTR_WAIT, 0x00, (x)} }, +#define ZI_WAIT_FOREVER() { .i = { ZGB_INSTR_WAIT_FOREVER, 0x00, 0x0000} }, +#define ZI_STOP(x) { .i = { ZGB_INSTR_STOP, (x), 0x0000} }, + +#define ZI_CALL(f, x) { .i = { ZGB_INSTR_CALL, (x), 0x0000} }, { .p = (const void*)(f) }, +#define ZI_LOG(x, m) { .i = { ZGB_INSTR_LOG, (x), 0x0000 } }, { .p = ((const void*)(m)) }, +#define ZI_ON_RECV_UNEXPECTED(f) { .i = { ZGB_ON_RECV_UNEXPECTED, 0x00, 0x0000} }, { .p = (const void*)(f) }, +#define ZI_SEND(m) { .i = { ZGB_INSTR_SEND, sizeof(m), 0x0000} }, { .p = (const void*)(m) }, +#define ZI_WAIT_RECV(x, m) { .i = { ZGB_INSTR_WAIT_RECV, sizeof(m), (x)} }, { .p = (const void*)(m) }, +#define ZI_WAIT_UNTIL(x, m) { .i = { ZGB_INSTR_WAIT_UNTIL, sizeof(m), (x)} }, { .p = (const void*)(m) }, +#define ZI_WAIT_RECV_FUNC(x, m, f) { .i = { ZGB_INSTR_WAIT_RECV_CALL, sizeof(m), (x)} }, { .p = (const void*)(m) }, { .p = (const void*)(f) }, + +struct ZigbeeStatus { + bool active = true; // is Zigbee active for this device, i.e. GPIOs configured + bool state_machine = false; // the state machine is running + bool state_waiting = false; // the state machine is waiting for external event or timeout + bool state_no_timeout = false; // the current wait loop does not generate a timeout but only continues running + bool ready = false; // cc2530 initialization is complet, ready to operate + uint8_t on_error_goto = ZIGBEE_LABEL_ABORT; // on error goto label, 99 default to abort + uint8_t on_timeout_goto = ZIGBEE_LABEL_ABORT; // on timeout goto label, 99 default to abort + int16_t pc = 0; // program counter, -1 means abort + uint32_t next_timeout = 0; // millis for the next timeout + + uint8_t *recv_filter = nullptr; // receive filter message + bool recv_until = false; // ignore all messages until the received frame fully matches + size_t recv_filter_len = 0; + ZB_RecvMsgFunc recv_func = nullptr; // function to call when message is expected + ZB_RecvMsgFunc recv_unexpected = nullptr; // function called when unexpected message is received + + bool init_phase = true; // initialization phase, before accepting zigbee traffic +}; +struct ZigbeeStatus zigbee; + +SBuffer *zigbee_buffer = nullptr; + + + +/*********************************************************************************************\ + * ZCL +\*********************************************************************************************/ + +typedef union ZCLHeaderFrameControl_t { + struct { + uint8_t frame_type : 2; // 00 = across entire profile, 01 = cluster specific + uint8_t manuf_specific : 1; // Manufacturer Specific Sub-field + uint8_t direction : 1; // 0 = tasmota to zigbee, 1 = zigbee to tasmota + uint8_t disable_def_resp : 1; // don't send back default response + uint8_t reserved : 3; + } b; + uint8_t d8; // raw 8 bits field +} ZCLHeaderFrameControl_t; + +class ZCLFrame { +public: + + ZCLFrame(uint8_t frame_control, uint16_t manuf_code, uint8_t transact_seq, uint8_t cmd_id, + const char *buf, size_t buf_len ): + _cmd_id(cmd_id), _manuf_code(manuf_code), _transact_seq(transact_seq), + _payload(buf_len ? buf_len : 250) // allocate the data frame from source or preallocate big enough + { + _frame_control.d8 = frame_control; + _payload.addBuffer(buf, buf_len); + }; + + void publishMQTTReceived(void) { + char hex_char[_payload.len()*2+2]; + ToHex_P((unsigned char*)_payload.getBuffer(), _payload.len(), hex_char, sizeof(hex_char)); + ResponseTime_P(PSTR(",\"" D_JSON_ZIGBEEZCLRECEIVED "\":{\"fc\":\"0x%02X\",\"manuf\":\"0x%04X\",\"transact\":%d," + "\"cmdid\":\"0x%02X\",\"payload\":\"%s\"}}"), + _frame_control, _manuf_code, _transact_seq, _cmd_id, + hex_char); + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCLSENT)); + XdrvRulesProcess(); + } + + static ZCLFrame parseRawFrame(SBuffer &buf, uint8_t offset, uint8_t len) { // parse a raw frame and build the ZCL frame object + uint32_t i = offset; + ZCLHeaderFrameControl_t frame_control; + uint16_t manuf_code = 0; + uint8_t transact_seq; + uint8_t cmd_id; + + frame_control.d8 = buf.get8(i++); + if (frame_control.b.manuf_specific) { + manuf_code = buf.get16(i); + i += 2; + } + transact_seq = buf.get8(i++); + cmd_id = buf.get8(i++); + ZCLFrame zcl_frame(frame_control.d8, manuf_code, transact_seq, cmd_id, + (const char *)(buf.buf() + i), len + offset - i); + return zcl_frame; + } + +private: + ZCLHeaderFrameControl_t _frame_control = { .d8 = 0 }; + uint16_t _manuf_code = 0; // optional + uint8_t _transact_seq = 0; // transaction sequence number + uint8_t _cmd_id = 0; + SBuffer _payload; +}; + + +/*********************************************************************************************\ + * State Machine +\*********************************************************************************************/ + +#define Z_B0(a) (uint8_t)( ((a) ) & 0xFF ) +#define Z_B1(a) (uint8_t)( ((a) >> 8) & 0xFF ) +#define Z_B2(a) (uint8_t)( ((a) >> 16) & 0xFF ) +#define Z_B3(a) (uint8_t)( ((a) >> 24) & 0xFF ) +#define Z_B4(a) (uint8_t)( ((a) >> 32) & 0xFF ) +#define Z_B5(a) (uint8_t)( ((a) >> 40) & 0xFF ) +#define Z_B6(a) (uint8_t)( ((a) >> 48) & 0xFF ) +#define Z_B7(a) (uint8_t)( ((a) >> 56) & 0xFF ) +// Macro to define message to send and receive +#define ZBM(n, x...) const uint8_t n[] PROGMEM = { x }; + +// ZBS_* Zigbee Send +// ZBR_* Zigbee Recv +ZBM(ZBS_RESET, Z_AREQ | Z_SYS, SYS_RESET, 0x01 ) // 410001 SYS_RESET_REQ Software reset +ZBM(ZBR_RESET, Z_AREQ | Z_SYS, SYS_RESET_IND ) // 4180 SYS_RESET_REQ Software reset response + +ZBM(ZBS_VERSION, Z_SREQ | Z_SYS, SYS_VERSION ) // 2102 Z_SYS:version +ZBM(ZBR_VERSION, Z_SRSP | Z_SYS, SYS_VERSION ) // 6102 Z_SYS:version + +// Check if ZNP_HAS_CONFIGURED is set +ZBM(ZBS_ZNPHC, Z_SREQ | Z_SYS, SYS_OSAL_NV_READ, ZNP_HAS_CONFIGURED & 0xFF, ZNP_HAS_CONFIGURED >> 8, 0x00 /* offset */ ) // 2108000F00 - 6108000155 +ZBM(ZBR_ZNPHC, Z_SRSP | Z_SYS, SYS_OSAL_NV_READ, Z_Success, 0x01 /* len */, 0x55) // 6108000155 +// If not set, the response is 61-08-02-00 = Z_SRSP | Z_SYS, SYS_OSAL_NV_READ, Z_InvalidParameter, 0x00 /* len */ + +ZBM(ZBS_PAN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_PANID ) // 260483 +ZBM(ZBR_PAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_Success, CONF_PANID, 0x02 /* len */, + Z_B0(USE_ZIGBEE_PANID), Z_B1(USE_ZIGBEE_PANID) ) // 6604008302xxxx + +ZBM(ZBS_EXTPAN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_EXTENDED_PAN_ID ) // 26042D +ZBM(ZBR_EXTPAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_Success, CONF_EXTENDED_PAN_ID, + 0x08 /* len */, + Z_B0(USE_ZIGBEE_EXTPANID), Z_B1(USE_ZIGBEE_EXTPANID), Z_B2(USE_ZIGBEE_EXTPANID), Z_B3(USE_ZIGBEE_EXTPANID), + Z_B4(USE_ZIGBEE_EXTPANID), Z_B5(USE_ZIGBEE_EXTPANID), Z_B6(USE_ZIGBEE_EXTPANID), Z_B7(USE_ZIGBEE_EXTPANID), + ) // 6604002D08xxxxxxxxxxxxxxxx + +ZBM(ZBS_CHANN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_CHANLIST ) // 260484 +ZBM(ZBR_CHANN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_Success, CONF_CHANLIST, + 0x04 /* len */, + Z_B0(USE_ZIGBEE_CHANNEL), Z_B1(USE_ZIGBEE_CHANNEL), Z_B2(USE_ZIGBEE_CHANNEL), Z_B3(USE_ZIGBEE_CHANNEL), + ) // 6604008404xxxxxxxx + +ZBM(ZBS_PFGK, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_PRECFGKEY ) // 260462 +ZBM(ZBR_PFGK, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_Success, CONF_PRECFGKEY, + 0x10 /* len */, + Z_B0(USE_ZIGBEE_PRECFGKEY_L), Z_B1(USE_ZIGBEE_PRECFGKEY_L), Z_B2(USE_ZIGBEE_PRECFGKEY_L), Z_B3(USE_ZIGBEE_PRECFGKEY_L), + Z_B4(USE_ZIGBEE_PRECFGKEY_L), Z_B5(USE_ZIGBEE_PRECFGKEY_L), Z_B6(USE_ZIGBEE_PRECFGKEY_L), Z_B7(USE_ZIGBEE_PRECFGKEY_L), + Z_B0(USE_ZIGBEE_PRECFGKEY_H), Z_B1(USE_ZIGBEE_PRECFGKEY_H), Z_B2(USE_ZIGBEE_PRECFGKEY_H), Z_B3(USE_ZIGBEE_PRECFGKEY_H), + Z_B4(USE_ZIGBEE_PRECFGKEY_H), Z_B5(USE_ZIGBEE_PRECFGKEY_H), Z_B6(USE_ZIGBEE_PRECFGKEY_H), Z_B7(USE_ZIGBEE_PRECFGKEY_H), + /*0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, + 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D*/ ) // 660400621001030507090B0D0F00020406080A0C0D + +ZBM(ZBS_PFGKEN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_PRECFGKEYS_ENABLE ) // 260463 +ZBM(ZBR_PFGKEN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_Success, CONF_PRECFGKEYS_ENABLE, + 0x01 /* len */, 0x00 ) // 660400630100 + +// commands to "format" the device +// Write configuration - write success +ZBM(ZBR_W_OK, Z_SRSP | Z_SAPI, SAPI_WRITE_CONFIGURATION, Z_Success ) // 660500 - Write Configuration +ZBM(ZBR_WNV_OK, Z_SRSP | Z_SYS, SYS_OSAL_NV_WRITE, Z_Success ) // 610900 - NV Write + +// Factory reset +ZBM(ZBS_FACTRES, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_STARTUP_OPTION, 0x01 /* len */, 0x02 ) // 2605030102 +// Write PAN ID +ZBM(ZBS_W_PAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PANID, 0x02 /* len */, Z_B0(USE_ZIGBEE_PANID), Z_B1(USE_ZIGBEE_PANID) ) // 26058302xxxx +// Write EXT PAN ID +ZBM(ZBS_W_EXTPAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_EXTENDED_PAN_ID, 0x08 /* len */, + Z_B0(USE_ZIGBEE_EXTPANID), Z_B1(USE_ZIGBEE_EXTPANID), Z_B2(USE_ZIGBEE_EXTPANID), Z_B3(USE_ZIGBEE_EXTPANID), + Z_B4(USE_ZIGBEE_EXTPANID), Z_B5(USE_ZIGBEE_EXTPANID), Z_B6(USE_ZIGBEE_EXTPANID), Z_B7(USE_ZIGBEE_EXTPANID) + ) // 26052D086263151D004B1200 +// Write Channel ID +ZBM(ZBS_W_CHANN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_CHANLIST, 0x04 /* len */, + Z_B0(USE_ZIGBEE_CHANNEL), Z_B1(USE_ZIGBEE_CHANNEL), Z_B2(USE_ZIGBEE_CHANNEL), Z_B3(USE_ZIGBEE_CHANNEL), + /*0x00, 0x08, 0x00, 0x00*/ ) // 26058404xxxxxxxx +// Write Logical Type = 00 = coordinator +ZBM(ZBS_W_LOGTYP, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_LOGICAL_TYPE, 0x01 /* len */, 0x00 ) // 2605870100 +// Write precfgkey +ZBM(ZBS_W_PFGK, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PRECFGKEY, + 0x10 /* len */, + Z_B0(USE_ZIGBEE_PRECFGKEY_L), Z_B1(USE_ZIGBEE_PRECFGKEY_L), Z_B2(USE_ZIGBEE_PRECFGKEY_L), Z_B3(USE_ZIGBEE_PRECFGKEY_L), + Z_B4(USE_ZIGBEE_PRECFGKEY_L), Z_B5(USE_ZIGBEE_PRECFGKEY_L), Z_B6(USE_ZIGBEE_PRECFGKEY_L), Z_B7(USE_ZIGBEE_PRECFGKEY_L), + Z_B0(USE_ZIGBEE_PRECFGKEY_H), Z_B1(USE_ZIGBEE_PRECFGKEY_H), Z_B2(USE_ZIGBEE_PRECFGKEY_H), Z_B3(USE_ZIGBEE_PRECFGKEY_H), + Z_B4(USE_ZIGBEE_PRECFGKEY_H), Z_B5(USE_ZIGBEE_PRECFGKEY_H), Z_B6(USE_ZIGBEE_PRECFGKEY_H), Z_B7(USE_ZIGBEE_PRECFGKEY_H), + /*0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, + 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D*/ ) // 2605621001030507090B0D0F00020406080A0C0D +// Write precfgkey enable +ZBM(ZBS_W_PFGKEN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PRECFGKEYS_ENABLE, 0x01 /* len */, 0x00 ) // 2605630100 +// Write Security Mode +ZBM(ZBS_WNV_SECMODE, Z_SREQ | Z_SYS, SYS_OSAL_NV_WRITE, Z_B0(CONF_TCLK_TABLE_START), Z_B1(CONF_TCLK_TABLE_START), + 0x00 /* offset */, 0x20 /* len */, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, + 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) // 2109010100200FFFFFFFFFFFFFFFF5A6967426565416C6C69616E636530390000000000000000 +// Write Z_ZDO Direct CB +ZBM(ZBS_W_ZDODCB, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_ZDO_DIRECT_CB, 0x01 /* len */, 0x01 ) // 26058F0101 +// NV Init ZNP Has Configured +ZBM(ZBS_WNV_INITZNPHC, Z_SREQ | Z_SYS, SYS_OSAL_NV_ITEM_INIT, ZNP_HAS_CONFIGURED & 0xFF, ZNP_HAS_CONFIGURED >> 8, + 0x01, 0x00 /* InitLen 16 bits */, 0x01 /* len */, 0x00 ) // 2107000F01000100 - 610709 +// Init succeeded +ZBM(ZBR_WNV_INIT_OK, Z_SRSP | Z_SYS, SYS_OSAL_NV_WRITE, Z_Created ) // 610709 - NV Write +// Write ZNP Has Configured +ZBM(ZBS_WNV_ZNPHC, Z_SREQ | Z_SYS, SYS_OSAL_NV_WRITE, Z_B0(ZNP_HAS_CONFIGURED), Z_B1(ZNP_HAS_CONFIGURED), + 0x00 /* offset */, 0x01 /* len */, 0x55 ) // 2109000F000155 - 610900 +// Z_ZDO:startupFromApp +ZBM(ZBS_STARTUPFROMAPP, Z_SREQ | Z_ZDO, ZDO_STARTUP_FROM_APP, 100, 0 /* delay */) // 25406400 +ZBM(ZBR_STARTUPFROMAPP, Z_SRSP | Z_ZDO, ZDO_STARTUP_FROM_APP ) // 6540 + 01 for new network, 00 for exisitng network, 02 for error +ZBM(AREQ_STARTUPFROMAPP, Z_AREQ | Z_ZDO, ZDO_STATE_CHANGE_IND, ZDO_DEV_ZB_COORD ) // 45C009 + 08 = starting, 09 = started +// GetDeviceInfo +ZBM(ZBS_GETDEVICEINFO, Z_SREQ | Z_UTIL, Z_UTIL_GET_DEVICE_INFO ) // 2700 +ZBM(ZBR_GETDEVICEINFO, Z_SRSP | Z_UTIL, Z_UTIL_GET_DEVICE_INFO, Z_Success ) // Ex= 6700.00.6263151D004B1200.0000.07.09.00 + // IEEE Adr (8 bytes) = 6263151D004B1200 + // Short Addr (2 bytes) = 0000 + // Device Type (1 byte) = 07 (coord?) + // Device State (1 byte) = 09 (coordinator started) + // NumAssocDevices (1 byte) = 00 + +// Read Pan ID +//ZBM(ZBS_READ_NV_PANID, Z_SREQ | Z_SYS, SYS_OSAL_NV_READ, PANID & 0xFF, PANID >> 8, 0x00 /* offset */ ) // 2108830000 + +// Z_ZDO:nodeDescReq +ZBM(ZBS_ZDO_NODEDESCREQ, Z_SREQ | Z_ZDO, ZDO_NODE_DESC_REQ, 0x00, 0x00 /* dst addr */, 0x00, 0x00 /* NWKAddrOfInterest */) // 250200000000 +ZBM(ZBR_ZDO_NODEDESCREQ, Z_SRSP | Z_ZDO, ZDO_NODE_DESC_REQ, Z_Success ) // 650200 +// Async resp ex: 4582.0000.00.0000.00.40.8F.0000.50.A000.0100.A000.00 +ZBM(AREQ_ZDO_NODEDESCREQ, Z_AREQ | Z_ZDO, ZDO_NODE_DESC_RSP) // 4582 +// SrcAddr (2 bytes) 0000 +// Status (1 byte) 00 Success +// NwkAddr (2 bytes) 0000 +// LogicalType (1 byte) - 00 Coordinator +// APSFlags (1 byte) - 40 0=APSFlags 4=NodeFreqBands +// MACCapabilityFlags (1 byte) - 8F ALL +// ManufacturerCode (2 bytes) - 0000 +// MaxBufferSize (1 byte) - 50 NPDU +// MaxTransferSize (2 bytes) - A000 = 160 +// ServerMask (2 bytes) - 0100 - Primary Trust Center +// MaxOutTransferSize (2 bytes) - A000 = 160 +// DescriptorCapabilities (1 byte) - 00 + +// Z_ZDO:activeEpReq +ZBM(ZBS_ZDO_ACTIVEEPREQ, Z_SREQ | Z_ZDO, ZDO_ACTIVE_EP_REQ, 0x00, 0x00, 0x00, 0x00) // 250500000000 +ZBM(ZBR_ZDO_ACTIVEEPREQ, Z_SRSP | Z_ZDO, ZDO_ACTIVE_EP_REQ, Z_Success) // 65050000 +ZBM(ZBR_ZDO_ACTIVEEPRSP_NONE, Z_AREQ | Z_ZDO, ZDO_ACTIVE_EP_RSP, 0x00, 0x00 /* srcAddr */, Z_Success, + 0x00, 0x00 /* nwkaddr */, 0x00 /* activeepcount */) // 45050000 - no Ep running +ZBM(ZBR_ZDO_ACTIVEEPRSP_OK, Z_AREQ | Z_ZDO, ZDO_ACTIVE_EP_RSP, 0x00, 0x00 /* srcAddr */, Z_Success, + 0x00, 0x00 /* nwkaddr */, 0x02 /* activeepcount */, 0x0B, 0x01 /* the actual endpoints */) // 25050000 - no Ep running + +// Z_AF:register profile:104, ep:01 +ZBM(ZBS_AF_REGISTER01, Z_SREQ | Z_AF, AF_REGISTER, 0x01 /* endpoint */, Z_B0(Z_PROF_HA), Z_B1(Z_PROF_HA), // 24000401050000000000 + 0x05, 0x00 /* AppDeviceId */, 0x00 /* AppDevVer */, 0x00 /* LatencyReq */, + 0x00 /* AppNumInClusters */, 0x00 /* AppNumInClusters */) +ZBM(ZBR_AF_REGISTER, Z_SRSP | Z_AF, AF_REGISTER, Z_Success) // 640000 +ZBM(ZBS_AF_REGISTER0B, Z_SREQ | Z_AF, AF_REGISTER, 0x0B /* endpoint */, Z_B0(Z_PROF_HA), Z_B1(Z_PROF_HA), // 2400040B050000000000 + 0x05, 0x00 /* AppDeviceId */, 0x00 /* AppDevVer */, 0x00 /* LatencyReq */, + 0x00 /* AppNumInClusters */, 0x00 /* AppNumInClusters */) +// Z_ZDO:mgmtPermitJoinReq +ZBM(ZBS_PERMITJOINREQ_CLOSE, Z_SREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, 0x02 /* AddrMode */, // 25360200000000 + 0x00, 0x00 /* DstAddr */, 0x00 /* Duration */, 0x00 /* TCSignificance */) +ZBM(ZBS_PERMITJOINREQ_OPEN, Z_SREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, 0x0F /* AddrMode */, // 25360FFFFCFF00 + 0xFC, 0xFF /* DstAddr */, 0xFF /* Duration */, 0x00 /* TCSignificance */) +ZBM(ZBR_PERMITJOINREQ, Z_SRSP | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, Z_Success) // 653600 +ZBM(ZBR_PERMITJOIN_AREQ_CLOSE, Z_AREQ | Z_ZDO, ZDO_PERMIT_JOIN_IND, 0x00 /* Duration */) // 45CB00 +ZBM(ZBR_PERMITJOIN_AREQ_OPEN, Z_AREQ | Z_ZDO, ZDO_PERMIT_JOIN_IND, 0xFF /* Duration */) // 45CBFF +ZBM(ZBR_PERMITJOIN_AREQ_RSP, Z_AREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_RSP, 0x00, 0x00 /* srcAddr*/, Z_Success ) // 45B6000000 + +// Filters for ZCL frames +ZBM(ZBR_AF_INCOMING_MESSAGE, Z_AREQ | Z_AF, AF_INCOMING_MSG) // 4481 + +static const Zigbee_Instruction zb_prog[] PROGMEM = { + ZI_LABEL(0) + ZI_NOOP() + ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) + ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT) + ZI_ON_RECV_UNEXPECTED(&Z_Recv_Default) + ZI_WAIT(15000) // wait for 15 seconds for Tasmota to stabilize + ZI_ON_ERROR_GOTO(50) + + ZI_LOG(LOG_LEVEL_INFO, "ZIG: rebooting device") + ZI_SEND(ZBS_RESET) // reboot cc2530 just in case we rebooted ESP8266 but not cc2530 + ZI_WAIT_RECV(5000, ZBR_RESET) // timeout 5s + ZI_LOG(LOG_LEVEL_INFO, "ZIG: checking device configuration") + ZI_SEND(ZBS_ZNPHC) // check value of ZNP Has Configured + ZI_WAIT_RECV(2000, ZBR_ZNPHC) + ZI_SEND(ZBS_VERSION) // check ZNP software version + ZI_WAIT_RECV(500, ZBR_VERSION) + ZI_SEND(ZBS_PAN) // check PAN ID + ZI_WAIT_RECV(500, ZBR_PAN) + ZI_SEND(ZBS_EXTPAN) // check EXT PAN ID + ZI_WAIT_RECV(500, ZBR_EXTPAN) + ZI_SEND(ZBS_CHANN) // check CHANNEL + ZI_WAIT_RECV(500, ZBR_CHANN) + ZI_SEND(ZBS_PFGK) // check PFGK + ZI_WAIT_RECV(500, ZBR_PFGK) + ZI_SEND(ZBS_PFGKEN) // check PFGKEN + ZI_WAIT_RECV(500, ZBR_PFGKEN) + ZI_LOG(LOG_LEVEL_INFO, "ZIG: zigbee configuration ok") + // all is good, we can start + + ZI_LABEL(10) // START ZNP App + ZI_CALL(&Z_State_Ready, 1) + ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) + // Z_ZDO:startupFromApp + ZI_LOG(LOG_LEVEL_INFO, "ZIG: starting zigbee coordinator") + ZI_SEND(ZBS_STARTUPFROMAPP) // start coordinator + ZI_WAIT_RECV(2000, ZBR_STARTUPFROMAPP) // wait for sync ack of command + ZI_WAIT_UNTIL(5000, AREQ_STARTUPFROMAPP) // wait for async message that coordinator started + ZI_SEND(ZBS_GETDEVICEINFO) // GetDeviceInfo + ZI_WAIT_RECV(500, ZBR_GETDEVICEINFO) // TODO memorize info + ZI_SEND(ZBS_ZDO_NODEDESCREQ) // Z_ZDO:nodeDescReq + ZI_WAIT_RECV(500, ZBR_ZDO_NODEDESCREQ) + ZI_WAIT_UNTIL(5000, AREQ_ZDO_NODEDESCREQ) + ZI_SEND(ZBS_ZDO_ACTIVEEPREQ) // Z_ZDO:activeEpReq + ZI_WAIT_RECV(500, ZBR_ZDO_ACTIVEEPREQ) + ZI_WAIT_UNTIL(500, ZBR_ZDO_ACTIVEEPRSP_NONE) + ZI_SEND(ZBS_AF_REGISTER01) // Z_AF register for endpoint 01, profile 0x0104 Home Automation + ZI_WAIT_RECV(500, ZBR_AF_REGISTER) + ZI_SEND(ZBS_AF_REGISTER0B) // Z_AF register for endpoint 0B, profile 0x0104 Home Automation + ZI_WAIT_RECV(500, ZBR_AF_REGISTER) + // Z_ZDO:nodeDescReq ?? Is is useful to redo it? TODO + // redo Z_ZDO:activeEpReq to check that Ep are available + ZI_SEND(ZBS_ZDO_ACTIVEEPREQ) // Z_ZDO:activeEpReq + ZI_WAIT_RECV(500, ZBR_ZDO_ACTIVEEPREQ) + ZI_WAIT_UNTIL(500, ZBR_ZDO_ACTIVEEPRSP_OK) + ZI_SEND(ZBS_PERMITJOINREQ_CLOSE) // Closing the Permit Join + ZI_WAIT_RECV(500, ZBR_PERMITJOINREQ) + ZI_WAIT_UNTIL(500, ZBR_PERMITJOIN_AREQ_RSP) // not sure it's useful + //ZI_WAIT_UNTIL(500, ZBR_PERMITJOIN_AREQ_CLOSE) + ZI_SEND(ZBS_PERMITJOINREQ_OPEN) // Opening Permit Join, normally through command TODO + ZI_WAIT_RECV(500, ZBR_PERMITJOINREQ) + ZI_WAIT_UNTIL(500, ZBR_PERMITJOIN_AREQ_RSP) // not sure it's useful + //ZI_WAIT_UNTIL(500, ZBR_PERMITJOIN_AREQ_OPEN) + + ZI_LABEL(ZIGBEE_LABEL_READY) + ZI_LOG(LOG_LEVEL_INFO, "ZIG: zigbee device ready, listening...") + ZI_CALL(&Z_State_Ready, 1) + ZI_WAIT_FOREVER() + ZI_GOTO(ZIGBEE_LABEL_READY) + + ZI_LABEL(50) // reformat device + ZI_LOG(LOG_LEVEL_INFO, "ZIG: zigbee bad configuration of device, doing a factory reset") + ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) + ZI_SEND(ZBS_FACTRES) // factory reset + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_RESET) // reset device + ZI_WAIT_RECV(5000, ZBR_RESET) + ZI_SEND(ZBS_W_PAN) // write PAN ID + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_W_EXTPAN) // write EXT PAN ID + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_W_CHANN) // write CHANNEL + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_W_LOGTYP) // write Logical Type = coordinator + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_W_PFGK) // write PRECFGKEY + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_W_PFGKEN) // write PRECFGKEY Enable + ZI_WAIT_RECV(500, ZBR_W_OK) + ZI_SEND(ZBS_WNV_SECMODE) // write Security Mode + ZI_WAIT_RECV(500, ZBR_WNV_OK) + ZI_SEND(ZBS_W_ZDODCB) // write Z_ZDO Direct CB + ZI_WAIT_RECV(500, ZBR_W_OK) + // Now mark the device as ready, writing 0x55 in memory slot 0x0F00 + ZI_SEND(ZBS_WNV_INITZNPHC) // Init NV ZNP Has Configured + ZI_WAIT_RECV(500, ZBR_WNV_INIT_OK) + ZI_SEND(ZBS_WNV_ZNPHC) // Write NV ZNP Has Configured + ZI_WAIT_RECV(500, ZBR_WNV_OK) + + ZI_LOG(LOG_LEVEL_INFO, "ZIG: zigbee device reconfigured") + ZI_GOTO(10) + + ZI_LABEL(ZIGBEE_LABEL_ABORT) // Label 99: abort + ZI_LOG(LOG_LEVEL_ERROR, "ZIG: Abort") + ZI_STOP(ZIGBEE_LABEL_ABORT) +}; + + +int32_t Z_Recv_Vers(int32_t res, class SBuffer &buf) { + // check that the version is supported + // typical version for ZNP 1.2 + // 61020200-020603D91434010200000000 + // TranportRev = 02 + // Product = 00 + // MajorRel = 2 + // MinorRel = 6 + // MaintRel = 3 + // Revision = 20190425 d (0x013414D9) + if ((0x02 == buf.get8(4)) && (0x06 == buf.get8(5))) { + return 0; // version 2.6.x is ok + } else { + return -2; // abort + } +} + +int32_t Z_Recv_Default(int32_t res, class SBuffer &buf) { + // Default message handler for new messages + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ZIG: Z_Recv_Default")); + if (zigbee.init_phase) { + // if still during initialization phase, ignore any unexpected message + return -1; // ignore message + } else { + if ( (pgm_read_byte(&ZBR_AF_INCOMING_MESSAGE[0]) == buf.get8(0)) && + (pgm_read_byte(&ZBR_AF_INCOMING_MESSAGE[1]) == buf.get8(1)) ) { + // AF_INCOMING_MSG, extract ZCL part TODO + // skip first 19 bytes + ZCLFrame zcl_received = ZCLFrame::parseRawFrame(buf, 19, buf.get8(18)); + zcl_received.publishMQTTReceived(); + } + return -1; + } +} + +int32_t Z_State_Ready(uint8_t value) { + zigbee.init_phase = false; // initialization phase complete + return 0; // continue +} + +uint8_t ZigbeeGetInstructionSize(uint8_t instr) { // in Zigbee_Instruction lines (words) + if (instr >= ZGB_INSTR_12_BYTES) { + return 3; + } else if (instr >= ZGB_INSTR_8_BYTES) { + return 2; + } else { + return 1; + } +} + +void ZigbeeGotoLabel(uint8_t label) { + // look for the label scanning entire code + uint16_t goto_pc = 0xFFFF; // 0xFFFF means not found + uint8_t cur_instr = 0; + uint8_t cur_d8 = 0; + uint8_t cur_instr_len = 1; // size of current instruction in words + + for (uint32_t i = 0; i < sizeof(zb_prog)/sizeof(zb_prog[0]); i += cur_instr_len) { + const Zigbee_Instruction *cur_instr_line = &zb_prog[i]; + cur_instr = pgm_read_byte(&cur_instr_line->i.i); + cur_d8 = pgm_read_byte(&cur_instr_line->i.d8); + //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZGB GOTO: pc %d instr %d"), i, cur_instr); + + if (ZGB_INSTR_LABEL == cur_instr) { + //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZIG: found label %d at pc %d"), cur_d8, i); + if (label == cur_d8) { + // label found, goto to this pc + zigbee.pc = i; + zigbee.state_machine = true; + zigbee.state_waiting = false; + return; + } + } + // get instruction length + cur_instr_len = ZigbeeGetInstructionSize(cur_instr); + } + + // no label found, abort + AddLog_P2(LOG_LEVEL_ERROR, PSTR("ZIG: Goto label not found, label=%d pc=%d"), label, zigbee.pc); + if (ZIGBEE_LABEL_ABORT != label) { + // if not already looking for ZIGBEE_LABEL_ABORT, goto ZIGBEE_LABEL_ABORT + ZigbeeGotoLabel(ZIGBEE_LABEL_ABORT); + } else { + AddLog_P2(LOG_LEVEL_ERROR, PSTR("ZIG: Label Abort (%d) not present, aborting Zigbee"), ZIGBEE_LABEL_ABORT); + zigbee.state_machine = false; + zigbee.active = false; + } +} + +void ZigbeeStateMachine_Run(void) { + uint8_t cur_instr = 0; + uint8_t cur_d8 = 0; + uint16_t cur_d16 = 0; + const void* cur_ptr1 = nullptr; + const void* cur_ptr2 = nullptr; + uint32_t now = millis(); + + if (zigbee.state_waiting) { // state machine is waiting for external event or timeout + // checking if timeout expired + if ((zigbee.next_timeout) && (now > zigbee.next_timeout)) { // if next_timeout == 0 then wait forever + //AddLog_P2(LOG_LEVEL_INFO, PSTR("ZIG: timeout occured pc=%d"), zigbee.pc); + if (!zigbee.state_no_timeout) { + AddLog_P2(LOG_LEVEL_INFO, PSTR("ZIG: timeout, goto label %d"), zigbee.on_timeout_goto); + ZigbeeGotoLabel(zigbee.on_timeout_goto); + } else { + zigbee.state_waiting = false; // simply stop waiting + } + } + } + + while ((zigbee.state_machine) && (!zigbee.state_waiting)) { + // reinit receive filters and functions (they only work for a single instruction) + zigbee.recv_filter = nullptr; + zigbee.recv_func = nullptr; + zigbee.recv_until = false; + zigbee.state_no_timeout = false; // reset the no_timeout for next instruction + + if (zigbee.pc > (sizeof(zb_prog)/sizeof(zb_prog[0]))) { + AddLog_P2(LOG_LEVEL_ERROR, PSTR("ZIG: Invalid pc: %d, aborting"), zigbee.pc); + zigbee.pc = -1; + } + if (zigbee.pc < 0) { + zigbee.state_machine = false; + return; + } + + // load current instruction details + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZIG: Executing instruction pc=%d"), zigbee.pc); + const Zigbee_Instruction *cur_instr_line = &zb_prog[zigbee.pc]; + cur_instr = pgm_read_byte(&cur_instr_line->i.i); + cur_d8 = pgm_read_byte(&cur_instr_line->i.d8); + cur_d16 = pgm_read_word(&cur_instr_line->i.d16); + if (cur_instr >= ZGB_INSTR_8_BYTES) { + cur_instr_line++; + cur_ptr1 = cur_instr_line->p; + } + if (cur_instr >= ZGB_INSTR_12_BYTES) { + cur_instr_line++; + cur_ptr2 = cur_instr_line->p; + } + + zigbee.pc += ZigbeeGetInstructionSize(cur_instr); // move pc to next instruction, before any goto + + switch (cur_instr) { + case ZGB_INSTR_NOOP: + case ZGB_INSTR_LABEL: // do nothing + break; + case ZGB_INSTR_GOTO: + ZigbeeGotoLabel(cur_d8); + break; + case ZGB_INSTR_ON_ERROR_GOTO: + zigbee.on_error_goto = cur_d8; + break; + case ZGB_INSTR_ON_TIMEOUT_GOTO: + zigbee.on_timeout_goto = cur_d8; + break; + case ZGB_INSTR_WAIT: + zigbee.next_timeout = now + cur_d16; + zigbee.state_waiting = true; + zigbee.state_no_timeout = true; // do not generate a timeout error when waiting is done + break; + case ZGB_INSTR_WAIT_FOREVER: + zigbee.next_timeout = 0; + zigbee.state_waiting = true; + //zigbee.state_no_timeout = true; // do not generate a timeout error when waiting is done + break; + case ZGB_INSTR_STOP: + zigbee.state_machine = false; + if (cur_d8) { + AddLog_P2(LOG_LEVEL_ERROR, PSTR("ZIG: Stopping (%d)"), cur_d8); + } + break; + case ZGB_INSTR_CALL: + if (cur_ptr1) { + uint32_t res; + res = (*((ZB_Func)cur_ptr1))(cur_d8); + if (res > 0) { + ZigbeeGotoLabel(res); + continue; // avoid incrementing PC after goto + } else if (res == 0) { + // do nothing + } else if (res == -1) { + // do nothing + } else { + ZigbeeGotoLabel(zigbee.on_error_goto); + continue; + } + } + // TODO + break; + case ZGB_INSTR_LOG: + AddLog_P(cur_d8, (char*) cur_ptr1); + break; + case ZGB_INSTR_SEND: + ZigbeeZNPSend((uint8_t*) cur_ptr1, cur_d8 /* len */); + break; + case ZGB_INSTR_WAIT_UNTIL: + zigbee.recv_until = true; // and reuse ZGB_INSTR_WAIT_RECV + case ZGB_INSTR_WAIT_RECV: + zigbee.recv_filter = (uint8_t *) cur_ptr1; + zigbee.recv_filter_len = cur_d8; // len + zigbee.next_timeout = now + cur_d16; + zigbee.state_waiting = true; + break; + case ZGB_ON_RECV_UNEXPECTED: + zigbee.recv_unexpected = (ZB_RecvMsgFunc) cur_ptr1; + break; + case ZGB_INSTR_WAIT_RECV_CALL: + zigbee.recv_filter = (uint8_t *) cur_ptr1; + zigbee.recv_filter_len = cur_d8; // len + zigbee.recv_func = (ZB_RecvMsgFunc) cur_ptr2; + zigbee.next_timeout = now + cur_d16; + zigbee.state_waiting = true; + break; + } + } +} + +int32_t ZigbeeProcessInput(class SBuffer &buf) { + if (!zigbee.state_machine) { return -1; } // if state machine is stopped, send 'ignore' message + + // apply the receive filter, acts as 'startsWith()' + bool recv_filter_match = true; + bool recv_prefix_match = false; // do the first 2 bytes match the response + if ((zigbee.recv_filter) && (zigbee.recv_filter_len > 0)) { + if (zigbee.recv_filter_len >= 2) { + recv_prefix_match = false; + if ( (pgm_read_byte(&zigbee.recv_filter[0]) == buf.get8(0)) && + (pgm_read_byte(&zigbee.recv_filter[1]) == buf.get8(1)) ) { + recv_prefix_match = true; + } + } + + for (uint32_t i = 0; i < zigbee.recv_filter_len; i++) { + if (pgm_read_byte(&zigbee.recv_filter[i]) != buf.get8(i)) { + recv_filter_match = false; + break; + } + } + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ZIG: ZigbeeProcessInput: recv_prefix_match = %d, recv_filter_match = %d"), recv_prefix_match, recv_filter_match); + } + + // if there is a recv_callback, call it now + int32_t res = -1; // default to ok + // res = 0 - proceed to next state + // res > 0 - proceed to the specified state + // res = -1 - silently ignore the message + // res <= -2 - move to error state + // pre-compute the suggested value + if ((zigbee.recv_filter) && (zigbee.recv_filter_len > 0)) { + if (!recv_prefix_match) { + res = -1; // ignore + } else { // recv_prefix_match + if (recv_filter_match) { + res = 0; // ok + } else { + if (zigbee.recv_until) { + res = -1; // ignore until full match + } else { + res = -2; // error, because message is expected but wrong value + } + } + } + } else { // we don't have any filter, ignore message by default + res = -1; + } + + if (recv_prefix_match) { + if (zigbee.recv_func) { + res = (*zigbee.recv_func)(res, buf); + } + } + if (-1 == res) { + // if frame was ignored up to now + if (zigbee.recv_unexpected) { + res = (*zigbee.recv_unexpected)(res, buf); + } + } + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ZIG: ZigbeeProcessInput: res = %d"), res); + + // change state accordingly + if (0 == res) { + // if ok, continue execution + zigbee.state_waiting = false; + } else if (res > 0) { + ZigbeeGotoLabel(res); // if >0 then go to specified label + } else if (-1 == res) { + // -1 means ignore message + // just do nothing + } else { + // any other negative value means error + ZigbeeGotoLabel(zigbee.on_error_goto); + } +} + +void ZigbeeInput(void) +{ + static uint32_t zigbee_polling_window = 0; + static uint8_t fcs = ZIGBEE_SOF; + static uint32_t zigbee_frame_len = 5; // minimal zigbee frame lenght, will be updated when buf[1] is read + // Receive only valid ZNP frames: + // 00 - SOF = 0xFE + // 01 - Length of Data Field - 0..250 + // 02 - CMD1 - first byte of command + // 03 - CMD2 - second byte of command + // 04..FD - Data Field + // FE (or last) - FCS Checksum + + while (ZigbeeSerial->available()) { + yield(); + uint8_t zigbee_in_byte = ZigbeeSerial->read(); + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZigbeeInput byte=%d len=%d"), zigbee_in_byte, zigbee_buffer->len()); + + if (0 == zigbee_buffer->len()) { // make sure all variables are correctly initialized + zigbee_frame_len = 5; + fcs = ZIGBEE_SOF; + } + + if ((0 == zigbee_buffer->len()) && (ZIGBEE_SOF != zigbee_in_byte)) { + // waiting for SOF (Start Of Frame) byte, discard anything else + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZigbeeInput discarding byte %02X"), zigbee_in_byte); + continue; // discard + } + + if (zigbee_buffer->len() < zigbee_frame_len) { + zigbee_buffer->add8(zigbee_in_byte); + zigbee_polling_window = millis(); // Wait for more data + fcs ^= zigbee_in_byte; + } + + if (zigbee_buffer->len() >= zigbee_frame_len) { + zigbee_polling_window = 0; // Publish now + break; + } + + // recalculate frame length + if (02 == zigbee_buffer->len()) { + // We just received the Lenght byte + uint8_t len_byte = zigbee_buffer->get8(1); + if (len_byte > 250) len_byte = 250; // ZNP spec says len is 250 max + + zigbee_frame_len = len_byte + 5; // SOF + LEN + CMD1 + CMD2 + FCS = 5 bytes overhead + } + } + + if (zigbee_buffer->len() && (millis() > (zigbee_polling_window + ZIGBEE_POLLING))) { + char hex_char[(zigbee_buffer->len() * 2) + 2]; + ToHex_P((unsigned char*)zigbee_buffer->getBuffer(), zigbee_buffer->len(), hex_char, sizeof(hex_char)); + + // buffer received, now check integrity + if (zigbee_buffer->len() != zigbee_frame_len) { + // Len is not correct, log and reject frame + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_JSON_ZIGBEEZNPRECEIVED ": received frame of wrong size %s, len %d, expected %d"), hex_char, zigbee_buffer->len(), zigbee_frame_len); + } else if (0x00 != fcs) { + // FCS is wrong, packet is corrupt, log and reject frame + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_JSON_ZIGBEEZNPRECEIVED ": received bad FCS frame %s, %d"), hex_char, fcs); + } else { + // frame is correct + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_JSON_ZIGBEEZNPRECEIVED ": received correct frame %s"), hex_char); + + SBuffer znp_buffer = zigbee_buffer->subBuffer(2, zigbee_frame_len - 3); // remove SOF, LEN and FCS + + ToHex_P((unsigned char*)znp_buffer.getBuffer(), znp_buffer.len(), hex_char, sizeof(hex_char)); + ResponseTime_P(PSTR(",\"" D_JSON_ZIGBEEZNPRECEIVED "\":\"%s\"}"), hex_char); + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZNPRECEIVED)); + XdrvRulesProcess(); + + // now process the message + ZigbeeProcessInput(znp_buffer); + } + zigbee_buffer->setLen(0); // empty buffer + } +} + +/********************************************************************************************/ + +void ZigbeeInit(void) +{ + zigbee.active = false; + if ((pin[GPIO_ZIGBEE_RX] < 99) && (pin[GPIO_ZIGBEE_TX] < 99)) { + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("Zigbee: GPIOs Rx:%d Tx:%d"), pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX]); + ZigbeeSerial = new TasmotaSerial(pin[GPIO_ZIGBEE_RX], pin[GPIO_ZIGBEE_TX], 0, 0, 256); // set a receive buffer of 256 bytes + if (ZigbeeSerial->begin(115200)) { // ZNP is 115200, RTS/CTS (ignored), 8N1 + if (ZigbeeSerial->hardwareSerial()) { + ClaimSerial(); + zigbee_buffer = new PreAllocatedSBuffer(sizeof(serial_in_buffer), serial_in_buffer); + } else { + zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE); + } + zigbee.active = true; + zigbee.init_phase = true; // start the state machine + zigbee.state_machine = true; // start the state machine + ZigbeeSerial->flush(); + } + } +} + +/*********************************************************************************************\ + * Commands +\*********************************************************************************************/ + +void CmndZigbeeZNPSend(void) +{ + AddLog_P2(LOG_LEVEL_INFO, PSTR("CmndZigbeeZNPSend: entering, data_len = %d"), XdrvMailbox.data_len); // TODO + if (ZigbeeSerial && (XdrvMailbox.data_len > 0)) { + uint8_t code; + + char *codes = RemoveSpace(XdrvMailbox.data); + int32_t size = strlen(XdrvMailbox.data); + + SBuffer buf((size+1)/2); + + while (size > 0) { + char stemp[3]; + strlcpy(stemp, codes, sizeof(stemp)); + code = strtol(stemp, nullptr, 16); + buf.add8(code); + size -= 2; + codes += 2; + } + ZigbeeZNPSend(buf.getBuffer(), buf.len()); + } + ResponseCmndDone(); +} + +void ZigbeeZNPSend(const uint8_t *msg, size_t len) { + if ((len < 2) || (len > 252)) { + // abort, message cannot be less than 2 bytes for CMD1 and CMD2 + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_JSON_ZIGBEEZNPSENT ": bad message len %d"), len); + return; + } + uint8_t data_len = len - 2; // removing CMD1 and CMD2 + + if (ZigbeeSerial) { + uint8_t fcs = data_len; + + ZigbeeSerial->write(ZIGBEE_SOF); // 0xFE + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZNPSend SOF %02X"), ZIGBEE_SOF); + ZigbeeSerial->write(data_len); + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZNPSend LEN %02X"), data_len); + for (uint32_t i = 0; i < len; i++) { + uint8_t b = pgm_read_byte(msg + i); + ZigbeeSerial->write(b); + fcs ^= b; + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZNPSend byt %02X"), b); + } + ZigbeeSerial->write(fcs); // finally send fcs checksum byte + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("ZNPSend FCS %02X"), fcs); + } + // Now send a MQTT message to report the sent message + char hex_char[(len * 2) + 2]; + Response_P(PSTR("{\"" D_JSON_ZIGBEEZNPSENT "\":\"%s\"}"), + ToHex_P(msg, len, hex_char, sizeof(hex_char))); + MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZNPSENT)); + XdrvRulesProcess(); +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xdrv23(uint8_t function) +{ + bool result = false; + + if (zigbee.active) { + switch (function) { + case FUNC_LOOP: + if (ZigbeeSerial) { ZigbeeInput(); } + if (zigbee.state_machine) { + //ZigbeeStateMachine(); + ZigbeeStateMachine_Run(); + } + break; + case FUNC_PRE_INIT: + ZigbeeInit(); + break; + case FUNC_COMMAND: + result = DecodeCommand(kZigbeeCommands, ZigbeeCommand); + break; + } + } + return result; +} + +#endif // USE_ZIGBEE diff --git a/sonoff/xdsp_08_ILI9488.ino b/sonoff/xdsp_08_ILI9488.ino index 51cb0fd4ca82..da20efbcb1d3 100644 --- a/sonoff/xdsp_08_ILI9488.ino +++ b/sonoff/xdsp_08_ILI9488.ino @@ -124,8 +124,7 @@ void ILI9488_InitDriver() #ifdef USE_TOUCH_BUTTONS void ILI9488_MQTT(uint8_t count,const char *cp) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"RA8876\":{\"%s%d\":\"%d\"}}"), mqtt_data,cp,count+1,(buttons[count]->vpower&0x80)>>7); + ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } // check digitizer hit @@ -165,7 +164,7 @@ if (2 == ili9488_ctouch_counter) { uint8_t bflags=buttons[count]->vpower&0x7f; if (!bflags) { // real button - if (!SendKey(0, count+1, POWER_TOGGLE)) { + if (!SendKey(KEY_BUTTON, count+1, POWER_TOGGLE)) { ExecuteCommandPower(count+1, POWER_TOGGLE, SRC_BUTTON); } buttons[count]->xdrawButton(bitRead(power,count)); diff --git a/sonoff/xdsp_10_RA8876.ino b/sonoff/xdsp_10_RA8876.ino index d77ed6c00abb..2abeda94bed5 100644 --- a/sonoff/xdsp_10_RA8876.ino +++ b/sonoff/xdsp_10_RA8876.ino @@ -109,8 +109,7 @@ void RA8876_InitDriver() #ifdef USE_TOUCH_BUTTONS void RA8876_MQTT(uint8_t count,const char *cp) { - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"RA8876\":{\"%s%d\":\"%d\"}}"), mqtt_data,cp,count+1,(buttons[count]->vpower&0x80)>>7); + ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } @@ -166,7 +165,7 @@ if (2 == ra8876_ctouch_counter) { uint8_t bflags=buttons[count]->vpower&0x7f; if (!bflags) { // real button - if (!SendKey(0, count+1, POWER_TOGGLE)) { + if (!SendKey(KEY_BUTTON, count+1, POWER_TOGGLE)) { ExecuteCommandPower(count+1, POWER_TOGGLE, SRC_BUTTON); } buttons[count]->xdrawButton(bitRead(power,count)); diff --git a/sonoff/xnrg_03_pzem004t.ino b/sonoff/xnrg_03_pzem004t.ino index 4083d9b389b7..b31f29582f25 100644 --- a/sonoff/xnrg_03_pzem004t.ino +++ b/sonoff/xnrg_03_pzem004t.ino @@ -181,12 +181,7 @@ void PzemEvery200ms(void) Energy.active_power = value; break; case 4: // Total energy as 99999Wh - if (!Energy.start_energy || (value < Energy.start_energy)) Energy.start_energy = value; // Init after restart and hanlde roll-over if any - if (value != Energy.start_energy) { - Energy.kWhtoday += (unsigned long)((value - Energy.start_energy) * 100); - Energy.start_energy = value; - } - EnergyUpdateToday(); + EnergyUpdateTotal(value, false); break; } pzem_read_state++; diff --git a/sonoff/xnrg_05_pzem_ac.ino b/sonoff/xnrg_05_pzem_ac.ino index 79f97e508a1d..04f71c5249be 100644 --- a/sonoff/xnrg_05_pzem_ac.ino +++ b/sonoff/xnrg_05_pzem_ac.ino @@ -82,12 +82,7 @@ void PzemAcEverySecond(void) Energy.power_factor = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00 float energy = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh - if (!Energy.start_energy || (energy < Energy.start_energy)) { Energy.start_energy = energy; } // Init after restart and handle roll-over if any - if (energy != Energy.start_energy) { - Energy.kWhtoday += (unsigned long)((energy - Energy.start_energy) * 100); - Energy.start_energy = energy; - } - EnergyUpdateToday(); + EnergyUpdateTotal(energy, false); // } } } diff --git a/sonoff/xnrg_06_pzem_dc.ino b/sonoff/xnrg_06_pzem_dc.ino index 4c8db837d4f9..1ad65a88a3f4 100644 --- a/sonoff/xnrg_06_pzem_dc.ino +++ b/sonoff/xnrg_06_pzem_dc.ino @@ -61,12 +61,7 @@ void PzemDcEverySecond(void) Energy.active_power = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0; // 429496729.0 W float energy = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh - if (!Energy.start_energy || (energy < Energy.start_energy)) { Energy.start_energy = energy; } // Init after restart and handle roll-over if any - if (energy != Energy.start_energy) { - Energy.kWhtoday += (unsigned long)((energy - Energy.start_energy) * 100); - Energy.start_energy = energy; - } - EnergyUpdateToday(); + EnergyUpdateTotal(energy, false); } } diff --git a/sonoff/xnrg_09_sdm120.ino b/sonoff/xnrg_09_sdm120.ino new file mode 100644 index 000000000000..6bd942655b16 --- /dev/null +++ b/sonoff/xnrg_09_sdm120.ino @@ -0,0 +1,286 @@ +/* + xnrg_09_sdm120.ino - Eastron SDM120-Modbus energy meter support for Sonoff-Tasmota + + Copyright (C) 2019 Gennaro Tortone and Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_ENERGY_SENSOR +#ifdef USE_SDM120_2 +/*********************************************************************************************\ + * Eastron SDM120 or SDM220 Modbus energy meter + * + * Based on: https://github.com/reaper7/SDM_Energy_Meter +\*********************************************************************************************/ + +#define XNRG_09 9 + +// can be user defined in my_user_config.h +#ifndef SDM120_SPEED + #define SDM120_SPEED 2400 // default SDM120 Modbus address +#endif +// can be user defined in my_user_config.h +#ifndef SDM120_ADDR + #define SDM120_ADDR 1 // default SDM120 Modbus address +#endif + +#include +TasmotaModbus *Sdm120Modbus; + +const uint16_t sdm120_start_addresses[] { + 0x0000, // SDM120C_VOLTAGE [V] + 0x0006, // SDM120C_CURRENT [A] + 0x000C, // SDM120C_POWER [W] + 0x0012, // SDM120C_APPARENT_POWER [VA] + 0x0018, // SDM120C_REACTIVE_POWER [VAR] + 0x001E, // SDM120C_POWER_FACTOR + 0x0046, // SDM120C_FREQUENCY [Hz] +#ifdef USE_SDM220 + 0x0156, // SDM120C_TOTAL_ACTIVE_ENERGY [Wh] + 0X0024, // SDM220_PHASE_ANGLE [Degre] + 0X0048, // SDM220_IMPORT_ACTIVE [kWh] + 0X004A, // SDM220_EXPORT_ACTIVE [kWh] + 0X004C, // SDM220_IMPORT_REACTIVE [kVArh] + 0X004E, // SDM220_EXPORT_REACTIVE [kVArh] + 0X0158 // SDM220 TOTAL_REACTIVE [kVArh] +#else // USE_SDM220 + 0x0156 // SDM120C_TOTAL_ACTIVE_ENERGY [Wh] +#endif // USE_SDM220 +}; + +struct SDM120 { + uint8_t read_state = 0; + uint8_t send_retry = 0; +} Sdm120; + +#ifdef USE_SDM220 +struct SDM220 { + float phase_angle = 0; + float import_active = 0; + float export_active = 0; + float import_reactive = 0; + float export_reactive = 0; + float total_reactive = 0; +} Sdm220; +#endif // USE_SDM220 + +/*********************************************************************************************/ + +void SDM120Every200ms(void) +{ + bool data_ready = Sdm120Modbus->ReceiveReady(); + + if (data_ready) { + uint8_t buffer[9]; + + uint32_t error = Sdm120Modbus->ReceiveBuffer(buffer, 2); + AddLogBuffer(LOG_LEVEL_DEBUG_MORE, (uint8_t*)buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer)); + + if (error) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "SDM120 response error %d"), error); + } else { + Energy.data_valid = 0; + + float value; + ((uint8_t*)&value)[3] = buffer[3]; // Get float values + ((uint8_t*)&value)[2] = buffer[4]; + ((uint8_t*)&value)[1] = buffer[5]; + ((uint8_t*)&value)[0] = buffer[6]; + + switch(Sdm120.read_state) { + case 0: + Energy.voltage = value; // 230.2 V + break; + + case 1: + Energy.current = value; // 1.260 A + break; + + case 2: + Energy.active_power = value; // -196.3 W + break; + + case 3: + Energy.apparent_power = value; // 223.4 VA + break; + + case 4: + Energy.reactive_power = value; // 92.2 + break; + + case 5: + Energy.power_factor = value; // -0.91 + break; + + case 6: + Energy.frequency = value; // 50.0 Hz + break; + + case 7: + EnergyUpdateTotal(value, true); // 484.708 kWh + break; + +#ifdef USE_SDM220 + case 8: + Sdm220.phase_angle = value; // 0.00 Deg + break; + + case 9: + Sdm220.import_active = value; // 478.492 kWh + break; + + case 10: + Sdm220.export_active = value; // 6.216 kWh + break; + + case 11: + Sdm220.import_reactive = value; // 172.750 kVArh + break; + + case 12: + Sdm220.export_reactive = value; // 2.844 kVArh + break; + + case 13: + Sdm220.total_reactive = value; // 175.594 kVArh + break; +#endif // USE_SDM220 + } + + Sdm120.read_state++; + if (sizeof(sdm120_start_addresses)/2 == Sdm120.read_state) { + Sdm120.read_state = 0; + } + } + } // end data ready + + if (0 == Sdm120.send_retry || data_ready) { + Sdm120.send_retry = 5; + Sdm120Modbus->Send(SDM120_ADDR, 0x04, sdm120_start_addresses[Sdm120.read_state], 2); + } else { + Sdm120.send_retry--; + } +} + +void Sdm120SnsInit(void) +{ + Sdm120Modbus = new TasmotaModbus(pin[GPIO_SDM120_RX], pin[GPIO_SDM120_TX]); + uint8_t result = Sdm120Modbus->Begin(SDM120_SPEED); + if (result) { + if (2 == result) { ClaimSerial(); } + } else { + energy_flg = ENERGY_NONE; + } +} + +void Sdm120DrvInit(void) +{ + if (!energy_flg) { + if ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) { + energy_flg = XNRG_09; + } + } +} + +#ifdef USE_SDM220 + +void Sdm220Reset(void) +{ + Sdm220.phase_angle = 0; + Sdm220.import_active = 0; + Sdm220.export_active = 0; + Sdm220.import_reactive = 0; + Sdm220.export_reactive = 0; + Sdm220.total_reactive = 0; +} + +#ifdef USE_WEBSERVER +const char HTTP_ENERGY_SDM220[] PROGMEM = + "{s}" D_IMPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}" + "{s}" D_EXPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}" + "{s}" D_TOTAL_REACTIVE "{m}%s " D_UNIT_KWARH "{e}" + "{s}" D_IMPORT_REACTIVE "{m}%s " D_UNIT_KWARH "{e}" + "{s}" D_EXPORT_REACTIVE "{m}%s " D_UNIT_KWARH "{e}" + "{s}" D_PHASE_ANGLE "{m}%s " D_UNIT_ANGLE "{e}"; +#endif // USE_WEBSERVER + +void Sdm220Show(bool json) +{ + char import_active_chr[FLOATSZ]; + dtostrfd(Sdm220.import_active, Settings.flag2.energy_resolution, import_active_chr); + char export_active_chr[FLOATSZ]; + dtostrfd(Sdm220.export_active, Settings.flag2.energy_resolution, export_active_chr); + char total_reactive_chr[FLOATSZ]; + dtostrfd(Sdm220.total_reactive, Settings.flag2.energy_resolution, total_reactive_chr); + char import_reactive_chr[FLOATSZ]; + dtostrfd(Sdm220.import_reactive, Settings.flag2.energy_resolution, import_reactive_chr); + char export_reactive_chr[FLOATSZ]; + dtostrfd(Sdm220.export_reactive, Settings.flag2.energy_resolution, export_reactive_chr); + char phase_angle_chr[FLOATSZ]; + dtostrfd(Sdm220.phase_angle, 2, phase_angle_chr); + + if (json) { + ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT_ACTIVE "\":%s,\"" D_JSON_EXPORT_ACTIVE "\":%s,\"" D_JSON_TOTAL_REACTIVE "\":%s,\"" D_JSON_IMPORT_REACTIVE "\":%s,\"" D_JSON_EXPORT_REACTIVE "\":%s,\"" D_JSON_PHASE_ANGLE "\":%s"), + import_active_chr, export_active_chr, total_reactive_chr, import_reactive_chr, export_reactive_chr, phase_angle_chr); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_ENERGY_SDM220, import_active_chr, export_active_chr, total_reactive_chr, import_reactive_chr, export_reactive_chr, phase_angle_chr); +#endif // USE_WEBSERVER + } +} + +#endif // USE_SDM220 + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +int Xnrg09(uint8_t function) +{ + int result = 0; + + if (FUNC_PRE_INIT == function) { + Sdm120DrvInit(); + } + else if (XNRG_09 == energy_flg) { + switch (function) { + case FUNC_INIT: + Sdm120SnsInit(); + break; + case FUNC_EVERY_200_MSECOND: + if (uptime > 4) { SDM120Every200ms(); } + break; + +#ifdef USE_SDM220 + case FUNC_ENERGY_RESET: + Sdm220Reset(); + break; + case FUNC_JSON_APPEND: + Sdm220Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + Sdm220Show(0); + break; +#endif // USE_WEBSERVER +#endif // USE_SDM220 + + } + } + return result; +} + +#endif // USE_SDM120_2 +#endif // USE_ENERGY_SENSOR diff --git a/sonoff/xplg_ws2812.ino b/sonoff/xplg_ws2812.ino index 479f2706548b..8b15d42866c8 100644 --- a/sonoff/xplg_ws2812.ino +++ b/sonoff/xplg_ws2812.ino @@ -39,13 +39,33 @@ typedef NeoRgbFeature selectedNeoFeatureType; #endif // USE_WS2812_CTYPE - #ifdef USE_WS2812_DMA - typedef Neo800KbpsMethod selectedNeoSpeedType; + +// See NeoEspDmaMethod.h for available options +#if (USE_WS2812_HARDWARE == NEO_HW_WS2812X) + typedef NeoEsp8266DmaWs2812xMethod selectedNeoSpeedType; +#elif (USE_WS2812_HARDWARE == NEO_HW_SK6812) + typedef NeoEsp8266DmaSk6812Method selectedNeoSpeedType; +#elif (USE_WS2812_HARDWARE == NEO_HW_APA106) + typedef NeoEsp8266DmaApa106Method selectedNeoSpeedType; +#else // USE_WS2812_HARDWARE + typedef NeoEsp8266Dma800KbpsMethod selectedNeoSpeedType; +#endif // USE_WS2812_HARDWARE + #else // USE_WS2812_DMA + +// See NeoEspBitBangMethod.h for available options +#if (USE_WS2812_HARDWARE == NEO_HW_WS2812X) + typedef NeoEsp8266BitBangWs2812xMethod selectedNeoSpeedType; +#elif (USE_WS2812_HARDWARE == NEO_HW_SK6812) + typedef NeoEsp8266BitBangSk6812Method selectedNeoSpeedType; +#else // USE_WS2812_HARDWARE typedef NeoEsp8266BitBang800KbpsMethod selectedNeoSpeedType; +#endif // USE_WS2812_HARDWARE + #endif // USE_WS2812_DMA - NeoPixelBus *strip = nullptr; + +NeoPixelBus *strip = nullptr; struct WsColor { uint8_t red, green, blue; @@ -299,11 +319,8 @@ void Ws2812Bars(uint32_t schemenr) void Ws2812Init(void) { -#ifdef USE_WS2812_DMA - strip = new NeoPixelBus(WS2812_MAX_LEDS); // For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. -#else // USE_WS2812_DMA + // For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use. strip = new NeoPixelBus(WS2812_MAX_LEDS, pin[GPIO_WS2812]); -#endif // USE_WS2812_DMA strip->Begin(); Ws2812Clear(); } diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index cd49734585ba..caefb67e8fc9 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -303,8 +303,7 @@ void MCP230xx_CheckForInterrupt(void) { break; } if (int_tele) { - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"MCP230XX_INT\":{\"D%i\":%i,\"MS\":%lu}}"), + ResponseTime_P(PSTR(",\"MCP230XX_INT\":{\"D%i\":%i,\"MS\":%lu}}"), intp+(mcp230xx_port*8), ((mcp230xx_intcap >> intp) & 0x01),millis_since_last_int); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR("MCP230XX_INT")); } @@ -730,8 +729,7 @@ void MCP230xx_OutputTelemetry(void) { } if (outputcount) { char stt[7]; - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"MCP230_OUT\":{")); + ResponseTime_P(PSTR(",\"MCP230_OUT\":{")); for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) { if (Settings.mcp230xx_config[pinx].pinmode >= 5) { sprintf(stt,ConvertNumTxt(((gpiototal>>pinx)&1),Settings.mcp230xx_config[pinx].pinmode)); @@ -746,8 +744,7 @@ void MCP230xx_OutputTelemetry(void) { #endif // USE_MCP230xx_OUTPUT void MCP230xx_Interrupt_Counter_Report(void) { - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"MCP230_INTTIMER\":{")); + ResponseTime_P(PSTR(",\"MCP230_INTTIMER\":{")); for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) { if (Settings.mcp230xx_config[pinx].int_count_en) { // Counting is enabled for this pin so we add to report ResponseAppend_P(PSTR("\"INTCNT_D%i\":%i,"),pinx,mcp230xx_int_counter[pinx]); @@ -761,8 +758,7 @@ void MCP230xx_Interrupt_Counter_Report(void) { void MCP230xx_Interrupt_Retain_Report(void) { uint16_t retainresult = 0; - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"MCP_INTRETAIN\":{")); + ResponseTime_P(PSTR(",\"MCP_INTRETAIN\":{")); for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) { if (Settings.mcp230xx_config[pinx].int_retain_flag) { ResponseAppend_P(PSTR("\"D%i\":%i,"),pinx,mcp230xx_int_retainer[pinx]); diff --git a/sonoff/xsns_40_pn532.ino b/sonoff/xsns_40_pn532.ino index 17527aa7e0a5..333ae7524e9c 100644 --- a/sonoff/xsns_40_pn532.ino +++ b/sonoff/xsns_40_pn532.ino @@ -494,12 +494,10 @@ void PN532_ScanForTag(void) pn532_function = 0; #endif // USE_PN532_DATA_FUNCTION - ResponseBeginTime(); - #ifdef USE_PN532_DATA_FUNCTION - ResponseAppend_P(PSTR(",\"PN532\":{\"UID\":\"%s\", \"DATA\":\"%s\"}}"), uids, card_datas); + ResponseTime_P(PSTR(",\"PN532\":{\"UID\":\"%s\", \"DATA\":\"%s\"}}"), uids, card_datas); #else - ResponseAppend_P(PSTR(",\"PN532\":{\"UID\":\"%s\"}}"), uids); + ResponseTime_P(PSTR(",\"PN532\":{\"UID\":\"%s\"}}"), uids); #endif // USE_PN532_DATA_FUNCTION MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); @@ -541,8 +539,7 @@ bool PN532_Command(void) if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 1),"E")) { pn532_function = 1; // Block 1 of next card/tag will be reset to 0x00... AddLog_P(LOG_LEVEL_INFO, PSTR("NFC: PN532 NFC - Next scanned tag data block 1 will be erased")); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"PN532\":{\"COMMAND\":\"E\"}}")); + ResponseTime_P(PSTR(",\"PN532\":{\"COMMAND\":\"E\"}}")); return serviced; } if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 1),"S")) { @@ -558,8 +555,7 @@ bool PN532_Command(void) pn532_newdata[pn532_newdata_len] = 0x00; // Null terminate the string pn532_function = 2; AddLog_P2(LOG_LEVEL_INFO, PSTR("NFC: PN532 NFC - Next scanned tag data block 1 will be set to '%s'"), pn532_newdata); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"PN532\":{\"COMMAND\":\"S\"}}")); + ResponseTime_P(PSTR(",\"PN532\":{\"COMMAND\":\"S\"}}")); return serviced; } } diff --git a/sonoff/xsns_44_sps30.ino b/sonoff/xsns_44_sps30.ino index 1b1434044e8e..20dc8a8f0b88 100644 --- a/sonoff/xsns_44_sps30.ino +++ b/sonoff/xsns_44_sps30.ino @@ -253,8 +253,7 @@ void SPS30_Show(bool json) { void CmdClean(void) { sps30_cmd(SPS_CMD_CLEAN); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"SPS30\":{\"CFAN\":\"true\"}}")); + ResponseTime_P(PSTR(",\"SPS30\":{\"CFAN\":\"true\"}}")); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } diff --git a/sonoff/xsns_51_rdm6300.ino b/sonoff/xsns_51_rdm6300.ino index 7fc168d7dca1..2a42b2a082db 100644 --- a/sonoff/xsns_51_rdm6300.ino +++ b/sonoff/xsns_51_rdm6300.ino @@ -106,8 +106,7 @@ void RDM6300_ScanForTag() { memcpy(rdm_uid_str,&rdm_buffer[2],8); rdm_uid_str[9]=0; - Response_P(PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); - ResponseAppend_P(PSTR(",\"RDM6300\":{\"UID\":\"%s\"}}"), rdm_uid_str); + ResponseTime_P(PSTR(",\"RDM6300\":{\"UID\":\"%s\"}}"), rdm_uid_str); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); /* char command[24]; diff --git a/sonoff/xsns_52_ibeacon.ino b/sonoff/xsns_52_ibeacon.ino index dbd56abd1b61..1df541d82c1d 100644 --- a/sonoff/xsns_52_ibeacon.ino +++ b/sonoff/xsns_52_ibeacon.ino @@ -547,8 +547,7 @@ void ibeacon_mqtt(const char *mac,const char *rssi) { memcpy(s_rssi,rssi,4); s_rssi[4]=0; int16_t n_rssi=atoi(s_rssi); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"" D_CMND_IBEACON "_%s\":{\"RSSI\":%d}}"),s_mac,n_rssi); + ResponseTime_P(PSTR(",\"" D_CMND_IBEACON "_%s\":{\"RSSI\":%d}}"),s_mac,n_rssi); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } diff --git a/sonoff/xsns_53_sml.ino b/sonoff/xsns_53_sml.ino index 40ff31df9993..9dabb29cda28 100644 --- a/sonoff/xsns_53_sml.ino +++ b/sonoff/xsns_53_sml.ino @@ -26,31 +26,28 @@ #define XSNS_53 53 -// Baudrate des D0 Ausgangs, sollte bei den meisten Zählern 9600 sein +// default baudrate of D0 output #define SML_BAUDRATE 9600 -// sende dies alle N Sekunden, für Zähler die erst auf Anforderung etwas senden +// send this every N seconds (for meters that only send data on demand) //#define SML_SEND_SEQ // debug counter input to led for counter1 and 2 //#define DEBUG_CNT_LED1 2 //#define DEBUG_CNT_LED1 2 -// use analog optical counter sensor with AD Converter ADS1115 +// use analog optical counter sensor with AD Converter ADS1115 (not yet) //#define ANALOG_OPTO_SENSOR -// fototransistor mit pullup an A0, A1 des ADS1115 A3 and +3.3V -// die pegel und die verstärkung können dann automatisch kalibriert werden +// fototransistor with pullup at A0, A1 of ADS1115 A3 and +3.3V +// level and amplification are automatically set -// support für mehr als 2 Meter mit spezieller Tasmota Serial Version -// dazu muss der modifizierte Treiber => TasmotaSerial-2.3.1 ebenfalls kopiert werden - #include // use special no wait serial driver #define SPECIAL_SS -// addresse a bug in meter DWS74 +// addresses a bug in meter DWS74 //#define DWS74_BUG // max 23 chars @@ -143,6 +140,11 @@ struct METER_DESC { uint16_t flag; int32_t params; char prefix[8]; + int8_t trxpin; + uint8_t tsecs; + char *txmem; + uint8_t index; + uint8_t max_index; }; // meter list , enter new meters here @@ -170,7 +172,7 @@ struct METER_DESC { #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS"}}; + [0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}}; const uint8_t meter[]= "1,1-0:1.8.0*255(@1," D_TPWRIN ",KWh," DJ_TPWRIN ",4|" "1,1-0:2.8.0*255(@1," D_TPWROUT ",KWh," DJ_TPWROUT ",4|" @@ -188,7 +190,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS"}}; + [0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}}; const uint8_t meter[]= "1,1-0:1.8.1*255(@1," D_TPWRIN ",KWh," DJ_TPWRIN ",4|" "1,1-0:2.8.1*255(@1," D_TPWROUT ",KWh," DJ_TPWROUT ",4|" @@ -202,7 +204,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'s',0,SML_BAUDRATE,"SML"}}; + [0]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; // 2 Richtungszähler EHZ SML 8 bit 9600 baud, binär const uint8_t meter[]= //0x77,0x07,0x01,0x00,0x01,0x08,0x00,0xff @@ -221,7 +223,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'s',0,SML_BAUDRATE,"SML"}}; + [0]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; // 2 Richtungszähler EHZ SML 8 bit 9600 baud, binär // verbrauch total const uint8_t meter[]= @@ -239,7 +241,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'s',0,SML_BAUDRATE,"SML"}}; + [0]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; // 2 Richtungszähler EHZ SML 8 bit 9600 baud, binär // verbrauch total const uint8_t meter[]= @@ -255,7 +257,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'s',0,SML_BAUDRATE,"strom"}}; + [0]={3,'s',0,SML_BAUDRATE,"strom",-1,1,0}}; const uint8_t meter[]= //0x77,0x07,0x01,0x00,0x01,0x08,0x00,0xff "1,77070100010800ff@1000," D_TPWRIN ",KWh," DJ_TPWRIN ",4|" @@ -278,7 +280,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'s',0,SML_BAUDRATE,"SML"}}; + [0]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; const uint8_t meter[]= //0x77,0x07,0x01,0x00,0x01,0x08,0x01,0xff "1,77070100010800ff@1000," D_TPWRIN ",KWh," DJ_TPWRIN ",4|" @@ -294,9 +296,9 @@ const uint8_t meter[]= #define METERS_USED 3 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS"}, // harware serial RX pin - [1]={14,'s',0,SML_BAUDRATE,"SML"}, // GPIO14 software serial - [2]={4,'o',0,SML_BAUDRATE,"OBIS2"}}; // GPIO4 software serial + [0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}, // harware serial RX pin + [1]={14,'s',0,SML_BAUDRATE,"SML",-1,1,0}, // GPIO14 software serial + [2]={4,'o',0,SML_BAUDRATE,"OBIS2",-1,1,0}}; // GPIO4 software serial // 3 Zähler definiert const uint8_t meter[]= @@ -323,8 +325,8 @@ const uint8_t meter[]= #define METERS_USED 2 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS1"}, // harware serial RX pin - [1]={14,'o',0,SML_BAUDRATE,"OBIS2"}}; // GPIO14 software serial + [0]={3,'o',0,SML_BAUDRATE,"OBIS1",-1,1,0}, // harware serial RX pin + [1]={14,'o',0,SML_BAUDRATE,"OBIS2",-1,1,0}}; // GPIO14 software serial // 2 Zähler definiert const uint8_t meter[]= @@ -345,9 +347,9 @@ const uint8_t meter[]= #define METERS_USED 3 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS1"}, // harware serial RX pin - [1]={14,'o',0,SML_BAUDRATE,"OBIS2"}, - [2]={1,'o',0,SML_BAUDRATE,"OBIS3"}}; + [0]={3,'o',0,SML_BAUDRATE,"OBIS1",-1,1,0}, // harware serial RX pin + [1]={14,'o',0,SML_BAUDRATE,"OBIS2",-1,1,0}, + [2]={1,'o',0,SML_BAUDRATE,"OBIS3",-1,1,0}}; // 3 Zähler definiert const uint8_t meter[]= @@ -375,7 +377,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ -[0]={3,'o',0,SML_BAUDRATE,"OBIS"}}; +[0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}}; const uint8_t meter[]= "1,1-0:1.8.1*255(@1," D_TPWRIN ",KWh," DJ_TPWRIN ",4|" "1,=d 1 10 @1," D_TPWRCURR ",W," DJ_TPWRCURR ",0|" @@ -388,7 +390,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 1 struct METER_DESC const meter_desc[METERS_USED]={ -[0]={3,'s',0,SML_BAUDRATE,"SML"}}; +[0]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; // 2 Richtungszähler EHZ SML 8 bit 9600 baud, binär const uint8_t meter[]= //0x77,0x07,0x01,0x00,0x01,0x08,0x00,0xff @@ -410,7 +412,7 @@ const uint8_t meter[]= #undef METERS_USED #define METERS_USED 3 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={3,'o',0,SML_BAUDRATE,"OBIS"}, // harware serial RX pin + [0]={3,'o',0,SML_BAUDRATE,"OBIS",-1,1,0}, // harware serial RX pin [1]={14,'c',0,50,"Gas"}, // GPIO14 gas counter [2]={1,'c',0,10,"Wasser"}}; // water counter @@ -433,9 +435,9 @@ const uint8_t meter[]= #define METERS_USED 3 struct METER_DESC const meter_desc[METERS_USED]={ - [0]={1,'c',0,10,"H20"}, // GPIO1 Wasser Zähler - [1]={4,'c',0,50,"GAS"}, // GPIO4 gas Zähler - [2]={3,'s',0,SML_BAUDRATE,"SML"}}; // SML harware serial RX pin + [0]={1,'c',0,10,"H20",-1,1,0}, // GPIO1 Wasser Zähler + [1]={4,'c',0,50,"GAS",-1,1,0}, // GPIO4 gas Zähler + [2]={3,'s',0,SML_BAUDRATE,"SML",-1,1,0}}; // SML harware serial RX pin const uint8_t meter[]= //----------------------------Wasserzähler--sensor53 c1------------------------------------ @@ -519,7 +521,7 @@ char meter_id[MAX_METERS][METER_ID_SIZE]; #define EBUS_SYNC 0xaa #define EBUS_ESC 0xa9 uint8_t ebus_pos; - +uint8_t mbus_pos; #ifdef USE_MEDIAN_FILTER // median filter, should be odd size @@ -789,32 +791,20 @@ uint8_t dump2log=0; bool Serial_available() { uint8_t num=dump2log&7; - if (num<1 || num>meters_used) return Serial.available(); - if (num==1) { - return Serial.available(); - } else { - return meter_ss[num-1]->available(); - } + if (num<1 || num>meters_used) num=1; + return meter_ss[num-1]->available(); } uint8_t Serial_read() { uint8_t num=dump2log&7; - if (num<1 || num>meters_used) return Serial.read(); - if (num==1) { - return Serial.read(); - } else { - return meter_ss[num-1]->read(); - } + if (num<1 || num>meters_used) num=1; + return meter_ss[num-1]->read(); } uint8_t Serial_peek() { uint8_t num=dump2log&7; - if (num<1 || num>meters_used) return Serial.peek(); - if (num==1) { - return Serial.peek(); - } else { - return meter_ss[num-1]->peek(); - } + if (num<1 || num>meters_used) num=1; + return meter_ss[num-1]->peek(); } void Dump2log(void) { @@ -1157,15 +1147,13 @@ uint8_t ebus_CalculateCRC( uint8_t *Data, uint16_t DataLen ) { void sml_shift_in(uint32_t meters,uint32_t shard) { uint32_t count; - if (meter_desc_p[meters].type!='e') { + if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m') { // shift in for (count=0; countread(); + uint8_t iob=(uint8_t)meter_ss[meters]->read(); if (meter_desc_p[meters].type=='o') { smltbuf[meters][SML_BSIZ-1]=iob&0x7f; @@ -1173,6 +1161,13 @@ void sml_shift_in(uint32_t meters,uint32_t shard) { smltbuf[meters][SML_BSIZ-1]=iob; } else if (meter_desc_p[meters].type=='r') { smltbuf[meters][SML_BSIZ-1]=iob; + } else if (meter_desc_p[meters].type=='m') { + smltbuf[meters][mbus_pos] = iob; + mbus_pos++; + if (mbus_pos>=9) { + SML_Decode(meters); + mbus_pos=0; + } } else { if (iob==EBUS_SYNC) { // should be end of telegramm @@ -1203,7 +1198,7 @@ void sml_shift_in(uint32_t meters,uint32_t shard) { } } sb_counter++; - if (meter_desc_p[meters].type!='e') SML_Decode(meters); + if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m') SML_Decode(meters); } @@ -1214,14 +1209,8 @@ uint32_t meters; for (meters=0; metersavailable()) { - sml_shift_in(meters,0); - } + while (meter_ss[meters]->available()) { + sml_shift_in(meters,0); } } } @@ -1351,7 +1340,8 @@ void SML_Decode(uint8_t index) { } else { // compare value uint8_t found=1; - int32_t ebus_dval=99; + uint32_t ebus_dval=99; + float mbus_dval=99; while (*mp!='@') { if (meter_desc_p[mindex].type=='o' || meter_desc_p[mindex].type=='c') { if (*mp++!=*cp++) { @@ -1366,7 +1356,7 @@ void SML_Decode(uint8_t index) { found=0; } } else { - // ebus or raw + // ebus mbus or raw // XXHHHHSSUU if (*mp=='x' && *(mp+1)=='x') { //ignore @@ -1382,7 +1372,7 @@ void SML_Decode(uint8_t index) { ebus_dval=val; mp+=2; } - else if (*mp=='s' && *(mp+1)=='s' && *(mp+2)=='s' && *(mp+3)=='s'){ + else if (*mp=='s' && *(mp+1)=='s' && *(mp+2)=='s' && *(mp+3)=='s') { int16_t val = *cp|(*(cp+1)<<8); ebus_dval=val; mp+=4; @@ -1392,7 +1382,15 @@ void SML_Decode(uint8_t index) { int8_t val = *cp++; ebus_dval=val; mp+=2; - } else { + } + else if (*mp=='f' && *(mp+1)=='f' && *(mp+2)=='f' && *(mp+3)=='f' && *(mp+4)=='f' && *(mp+5)=='f' && *(mp+6)=='f' && *(mp+7)=='f') { + uint32_t val= (*(cp+0)<<24)|(*(cp+1)<<16)|(*(cp+2)<<8)|(*(cp+3)<<0); + float *fp=(float*)&val; + mbus_dval=*fp; + mp+=8; + cp+=4; + } + else { uint8_t val = hexnibble(*mp++) << 4; val |= hexnibble(*mp++); if (val!=*cp++) { @@ -1421,7 +1419,7 @@ void SML_Decode(uint8_t index) { } } else { double dval; - if (meter_desc_p[mindex].type!='e' && meter_desc_p[mindex].type!='r') { + if (meter_desc_p[mindex].type!='e' && meter_desc_p[mindex].type!='r' && meter_desc_p[mindex].type!='m') { // get numeric values if (meter_desc_p[mindex].type=='o' || meter_desc_p[mindex].type=='c') { dval=xCharToDouble((char*)cp); @@ -1429,7 +1427,7 @@ void SML_Decode(uint8_t index) { dval=sml_getvalue(cp,mindex); } } else { - // ebus + // ebus or mbus if (*mp=='b') { mp++; uint8_t shift=*mp&7; @@ -1437,7 +1435,23 @@ void SML_Decode(uint8_t index) { ebus_dval&=1; mp+=2; } - dval=ebus_dval; + if (*mp=='i') { + // mbus index + mp++; + uint8_t mb_index=strtol((char*)mp,(char**)&mp,10); + if (mb_index!=meter_desc_p[mindex].index) { + goto nextsect; + } + uint16_t crc = MBUS_calculateCRC(&smltbuf[mindex][0],7); + if (lowByte(crc)!=smltbuf[mindex][7]) goto nextsect; + if (highByte(crc)!=smltbuf[mindex][8]) goto nextsect; + dval=mbus_dval; + //AddLog_P2(LOG_LEVEL_INFO, PSTR(">> %s"),mp); + mp++; + } else { + dval=ebus_dval; + } + } #ifdef USE_MEDIAN_FILTER meter_vars[vindex]=median(&sml_mf[vindex],dval); @@ -1491,8 +1505,7 @@ void SML_Immediate_MQTT(const char *mp,uint8_t index,uint8_t mindex) { if (dp&0x10) { // immediate mqtt dtostrfd(meter_vars[index],dp&0xf,tpowstr); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s}}"),meter_desc_p[mindex].prefix,jname,tpowstr); + ResponseTime_P(PSTR(",\"%s\":{\"%s\":%s}}"),meter_desc_p[mindex].prefix,jname,tpowstr); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); } } @@ -1666,6 +1679,14 @@ struct SML_COUNTER { } sml_counters[MAX_COUNTERS]; +#ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception +void SML_CounterUpd(uint8_t index) ICACHE_RAM_ATTR; +void SML_CounterUpd1(void) ICACHE_RAM_ATTR; +void SML_CounterUpd2(void) ICACHE_RAM_ATTR; +void SML_CounterUpd3(void) ICACHE_RAM_ATTR; +void SML_CounterUpd4(void) ICACHE_RAM_ATTR; +#endif // ARDUINO_ESP8266_RELEASE_2_3_0 + void SML_CounterUpd(uint8_t index) { uint32_t ltime=millis()-sml_counters[index].sml_counter_ltime; sml_counters[index].sml_counter_ltime=millis(); @@ -1718,6 +1739,14 @@ void SML_Init(void) { #ifdef USE_SCRIPT + + for (uint32_t cnt=0;cntM",-2,0); if (meter_script==99) { // use script definition @@ -1732,14 +1761,14 @@ void SML_Init(void) { lp+=2; meters_used=strtol(lp,0,10); section=1; - uint32_t mlen=METER_DEF_SIZE; - for (uint32_t cnt=0;cnt') { if (*(tp-1)=='|') *(tp-1)=0; break; } @@ -1777,13 +1806,42 @@ void SML_Init(void) { lp++; script_meter_desc[index].prefix[7]=0; for (uint32_t cnt=0; cnt<8; cnt++) { - if (*lp==SCRIPT_EOL) { + if (*lp==SCRIPT_EOL || *lp==',') { script_meter_desc[index].prefix[cnt]=0; - lp--; break; } script_meter_desc[index].prefix[cnt]=*lp++; } + if (*lp==',') { + lp++; + script_meter_desc[index].trxpin=strtol(lp,&lp,10); + if (*lp!=',') goto next_line; + lp++; + script_meter_desc[index].tsecs=strtol(lp,&lp,10); + if (*lp==',') { + lp++; + char txbuff[256]; + uint32_t txlen=0,tx_entries=1; + for (uint32_t cnt=0; cntbegin(meter_desc_p[meters].params)) { meter_ss[meters]->flush(); } - } + if (meter_ss[meters]->hardwareSerial()) { ClaimSerial(); } + } } @@ -1953,25 +2012,102 @@ uint32_t ctime=millis(); } } -#ifdef SML_SEND_SEQ -#define SML_SEQ_PERIOD 5 -uint8_t sml_seq_cnt; -void SendSeq(void) { - sml_seq_cnt++; - if (sml_seq_cnt>SML_SEQ_PERIOD) { - sml_seq_cnt=0; - // send sequence every N Seconds - uint8_t sequence[]={0x2F,0x3F,0x21,0x0D,0x0A,0}; - uint8_t *ucp=sequence; - while (*ucp) { - uint8_t iob=*ucp++; - // for no parity disable next line - iob|=(CalcEvenParity(iob)<<7); - Serial.write(iob); +#ifdef USE_SCRIPT +char *SML_Get_Sequence(char *cp,uint32_t index) { + if (!index) return cp; + uint32_t cindex=0; + while (cp) { + cp=strchr(cp,','); + if (cp) { + cp++; + cindex++; + if (cindex==index) { + return cp; + } + } + } +} + +uint8_t sml_250ms_cnt; + + +void SML_Check_Send(void) { + sml_250ms_cnt++; + for (uint32_t cnt=0; cnt=0 && script_meter_desc[cnt].txmem) { + if ((sml_250ms_cnt%script_meter_desc[cnt].tsecs)==0) { + if (script_meter_desc[cnt].max_index>1) { + script_meter_desc[cnt].index++; + if (script_meter_desc[cnt].index>=script_meter_desc[cnt].max_index) { + script_meter_desc[cnt].index=0; + } + char *cp=SML_Get_Sequence(script_meter_desc[cnt].txmem,script_meter_desc[cnt].index); + SML_Send_Seq(cnt,cp); + //AddLog_P2(LOG_LEVEL_INFO, PSTR(">> %s"),cp); + } else { + SML_Send_Seq(cnt,script_meter_desc[cnt].txmem); + } + } } } } +uint8_t sml_hexnibble(char chr) { + uint8_t rVal = 0; + if (isdigit(chr)) { + rVal = chr - '0'; + } else { + if (chr >= 'A' && chr <= 'F') rVal = chr + 10 - 'A'; + if (chr >= 'a' && chr <= 'f') rVal = chr + 10 - 'a'; + } + return rVal; +} + +// send sequence every N Seconds +void SML_Send_Seq(uint32_t meter,char *seq) { + uint8_t sbuff[32]; + uint8_t *ucp=sbuff,slen; + char *cp=seq; + while (*cp) { + if (!*cp || !*(cp+1)) break; + if (*cp==',') break; + uint8_t iob=(sml_hexnibble(*cp) << 4) | sml_hexnibble(*(cp+1)); + cp+=2; + *ucp++=iob; + slen++; + if (slen>=sizeof(sbuff)) break; + } + if (script_meter_desc[meter].type=='m') { + *ucp++=0; + *ucp++=2; + // append crc + uint16_t crc = MBUS_calculateCRC(sbuff,6); + *ucp++=lowByte(crc); + *ucp++=highByte(crc); + slen+=4; + } + meter_ss[meter]->write(sbuff,slen); +} +#endif // USE_SCRIPT + +uint16_t MBUS_calculateCRC(uint8_t *frame, uint8_t num) { + uint16_t crc, flag; + crc = 0xFFFF; + for (uint32_t i = 0; i < num; i++) { + crc ^= frame[i]; + for (uint32_t j = 8; j; j--) { + if ((crc & 0x0001) != 0) { // If the LSB is set + crc >>= 1; // Shift right and XOR 0xA001 + crc ^= 0xA001; + } else { // Else LSB is not set + crc >>= 1; // Just shift right + } + } + } + return crc; +} + +/* // for odd parity init with 1 uint8_t CalcEvenParity(uint8_t data) { uint8_t parity=0; @@ -1982,7 +2118,7 @@ uint8_t parity=0; } return parity; } -#endif +*/ // dump to log shows serial data on console @@ -1999,8 +2135,7 @@ bool XSNS_53_cmd(void) { // set dump mode cp++; dump2log=atoi(cp); - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"SML\":{\"CMD\":\"dump: %d\"}}"),dump2log); + ResponseTime_P(PSTR(",\"SML\":{\"CMD\":\"dump: %d\"}}"),dump2log); } else if (*cp=='c') { // set ounter cp++; @@ -2020,12 +2155,10 @@ bool XSNS_53_cmd(void) { } } } - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"SML\":{\"CMD\":\"counter%d: %d\"}}"),index,RtcSettings.pulse_counter[index-1]); + ResponseTime_P(PSTR(",\"SML\":{\"CMD\":\"counter%d: %d\"}}"),index,RtcSettings.pulse_counter[index-1]); } else if (*cp=='r') { // restart - ResponseBeginTime(); - ResponseAppend_P(PSTR(",\"SML\":{\"CMD\":\"restart\"}}")); + ResponseTime_P(PSTR(",\"SML\":{\"CMD\":\"restart\"}}")); SML_CounterSaveState(); SML_Init(); } else { @@ -2048,6 +2181,7 @@ void SML_CounterSaveState(void) { + /*********************************************************************************************\ * Interface \*********************************************************************************************/ @@ -2065,11 +2199,11 @@ bool Xsns53(byte function) { if (dump2log) Dump2log(); else SML_Poll(); break; -#ifdef SML_SEND_SEQ - case FUNC_EVERY_SECOND: - SendSeq(); +#ifdef USE_SCRIPT + case FUNC_EVERY_250_MSECOND: + SML_Check_Send(); break; -#endif +#endif // USE_SCRIPT case FUNC_JSON_APPEND: SML_Show(1); break;