diff --git a/.travis.yml b/.travis.yml index 3e2ea2435..4fb1c1538 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 000000000..a5852d41c --- /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 000000000..a02f1860e --- /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 000000000..6bdf2dea6 --- /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 000000000..058e9064f --- /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 000000000..27f3768b7 --- /dev/null +++ b/build-container/init_pio_tasmota/src/main.cpp @@ -0,0 +1,3 @@ +#include +void setup() {} +void loop() {} diff --git a/lib/A4988_Stepper/README.adoc b/lib/A4988_Stepper/README.adoc new file mode 100755 index 000000000..0cac353f3 --- /dev/null +++ b/lib/A4988_Stepper/README.adoc @@ -0,0 +1,19 @@ +Stepper Library for Tasmota + +This Class allows you to control bipolar stepper motors. To use it you will need an A4988-StepperDriverCircuit, connected at least with 2 GPIO's (direction and step) and of cause a stepper motor. + +== License == + +This library 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 2.1 of the License, or (at your option) any later version. + +This library 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 this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/lib/A4988_Stepper/keywords.txt b/lib/A4988_Stepper/keywords.txt new file mode 100755 index 000000000..c83465c8b --- /dev/null +++ b/lib/A4988_Stepper/keywords.txt @@ -0,0 +1,24 @@ +####################################### +# Syntax Coloring Map For Test +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +A4988_Stepper KEYWORD1 A4988_Stepper + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +doMove KEYWORD2 +doRotate KEYWORD2 +setRPM KEYWORD2 +setSPR KEYWORD2 +setMIS KEYWORD2 +version KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/lib/A4988_Stepper/library.properties b/lib/A4988_Stepper/library.properties new file mode 100755 index 000000000..2e6b38bf9 --- /dev/null +++ b/lib/A4988_Stepper/library.properties @@ -0,0 +1,9 @@ +name=A4988_Stepper +version=0.0.1 +author=Tim Leuschner +maintainer=Tim Leuschner +sentence=Allows Tasmota to control stepper motors, connected to A4988-StepperDriverCircuit. +paragraph=This library allows you to control bipolar stepper motors, controlled by A4988-stepperDriverCircuit. +category=Device Control +url= +architectures=* diff --git a/lib/A4988_Stepper/src/A4988_Stepper.cpp b/lib/A4988_Stepper/src/A4988_Stepper.cpp new file mode 100644 index 000000000..cbd72390a --- /dev/null +++ b/lib/A4988_Stepper/src/A4988_Stepper.cpp @@ -0,0 +1,155 @@ +/* + This library 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 library 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 . + + Drives a bipolar motor, controlled by A4988 stepper driver circuit + */ +// +#include "Arduino.h" +#include "A4988_Stepper.h" +A4988_Stepper::A4988_Stepper( int m_spr + , int m_rpm + , short m_mis + , short m_dir_pin + , short m_stp_pin + , short m_ena_pin + , short m_ms1_pin + , short m_ms2_pin + , short m_ms3_pin ) { + last_time = 0; // time stamp in us of the last step taken + motor_SPR = m_spr; // StepsPerRevolution + motor_RPM = m_rpm; // RoundsPerMinute + motor_MIS = m_mis; // Microsteps w/o effect if MS1-MS3 not connected - then full steps anyway + motor_dir_pin = m_dir_pin; + motor_stp_pin = m_stp_pin; + motor_ena_pin = m_ena_pin; + motor_ms1_pin = m_ms1_pin; + motor_ms2_pin = m_ms2_pin; + motor_ms3_pin = m_ms3_pin; + + adjustDelay(); + adjustPins(); + adjustMicrosteps(); +} + +void A4988_Stepper::adjustPins(void) { + // setup the pins on the microcontroller: + pinMode(motor_dir_pin, OUTPUT); + pinMode(motor_stp_pin, OUTPUT); + if (motor_ena_pin <99) { + pinMode(motor_ena_pin, OUTPUT); + digitalWrite(motor_ena_pin, HIGH); + } + + if ((motor_ms1_pin<99)&&(motor_ms2_pin<99)&&(motor_ms3_pin<99)) { + pinMode(motor_ms1_pin, OUTPUT); + pinMode(motor_ms2_pin, OUTPUT); + pinMode(motor_ms3_pin, OUTPUT); + } +} + +void A4988_Stepper::adjustMicrosteps() { + if ((motor_ms1_pin<99)&&(motor_ms2_pin<99)&&(motor_ms3_pin<99)) { + unsigned short i = 0; + while (i < 5){ + if (motor_MIS & (1<0?LOW:HIGH); + enable(); + while (steps_togo > 0) { + delay(0); // don't get watchdoged in loop + unsigned long now = micros(); + // move if delay has passed: + if (now - last_time >= motor_delay) { + digitalWrite(motor_stp_pin, lastStepWasHigh?LOW:HIGH); + lastStepWasHigh = !lastStepWasHigh; + // remeber step-time + last_time = now; + if (!lastStepWasHigh) steps_togo--; // same here - only HIGH moves, if pulled LOW step is completed... + } + } + disable(); +} + +void A4988_Stepper::doRotate(long howManyDegrees) +{ long lSteps = 0; + lSteps = motor_SPR*motor_MIS*howManyDegrees/360; + doMove(lSteps); +} + +void A4988_Stepper::doTurn(float howManyTimes) +{ long lSteps = 0; + lSteps = howManyTimes*motor_SPR; + doMove(lSteps); +} + +int A4988_Stepper::version(void) +{ + return 1; +} diff --git a/lib/A4988_Stepper/src/A4988_Stepper.h b/lib/A4988_Stepper/src/A4988_Stepper.h new file mode 100644 index 000000000..a907adfb1 --- /dev/null +++ b/lib/A4988_Stepper/src/A4988_Stepper.h @@ -0,0 +1,73 @@ +/* + This library 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 library 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 . +*/ + + +#ifndef A4988_Stepper_h +#define A4988_Stepper_h + +class A4988_Stepper { + public: + // constructor: + A4988_Stepper( int motor_spr + , int motor_rpm + , short motor_mis + , short motor_dir_pin + , short motor_stp_pin + , short motor_ena_pin + , short motor_ms1_pin + , short motor_ms2_pin + , short motor_ms3_pin + ); + + void setRPM (int whatRPM ); + int getRPM (void ); + + void setMIS (short OneToSixteen); + short getMIS (void ); + + void setSPR (int howMany ); + int getSPR (void ); + + void doMove (long steps_to_move); + void doRotate(long degrs_to_turn); + void doTurn (float howManyTimes); + + void enable (void ); + void disable (void ); + + int version (void ); + const unsigned short MIS_TABLE[5] = {0b000,0b001,0b010,0b011,0b111}; + + private: + void adjustDelay(void); + void adjustPins(void); + void adjustMicrosteps(void); + unsigned long motor_delay; // delay between steps, in ms + int motor_SPR; // Steps Per Revolution + int motor_RPM; // Rounds Per Minute + short motor_MIS; // Micro Steps + + // motor pins: + short motor_dir_pin; + short motor_stp_pin; + short motor_ena_pin; + short motor_ms1_pin; + short motor_ms2_pin; + short motor_ms3_pin; + + unsigned long last_time; // timestamp of last pincycle of last step +}; + +#endif 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 4441365bc..c02171953 --- 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 b873bff6e..e8bf3d832 --- 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 4aa0093c6..c4cb31515 --- 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 1526303a2..5672d2483 --- 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 9d297d523..c9d286973 --- 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 000000000..6f0416b51 --- /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 de3158a4b..73821dc05 --- 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 c4208af45..730a8965f --- 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 000000000..1aba0afcc --- /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 6edef1937..db2d398a1 --- 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 b678372d7..c5136f18e --- 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 7ab396d1f..f83a80428 --- 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 4483357bc..df668d836 --- 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 d02ce43af..73ee4b2a3 --- 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 70360f0ec..739ced38f --- 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 30fa8b120..72c168269 --- 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 6c982af74..0e1f00fa3 --- 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 6e36c7809..b094fdff5 --- 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 8984e612a..cbccee479 --- 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 cd7c72307..6f589aa3d --- 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 000000000..8c0b73c8c --- /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 000000000..73beb27a7 --- /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 7a2ecec19..522ede7e6 --- 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 bca94841c..317526f5e --- 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 ad9e1c182..98a38c640 --- 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 4c61da34d..6b945aa3f --- 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 43695b932..fa6a0ce8c --- 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 469e7ee9c..e953f9058 --- 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 a196cb7ef..d8ac45f1b --- 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 2bfb8e8b5..a4d906424 --- 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 9619c68e3..a399d50d5 --- 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; -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; +// 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 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 8cb24334c..d2b947f9e --- 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 dedaa5696..0550816a9 --- 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 f280d0161..0af521b15 --- 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 ded6fefad..124256e9f --- 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 14a0676fd..c78b1d21a --- 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 98a681e05..6b4295991 --- 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 fef1a65fd..e45ff702c --- 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 bd2a3d1b5..353d43b14 --- 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 cbc5e40b3..4e8f43891 --- 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 09ba3e199..77985b1c4 --- 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 b27c319e0..250248554 --- 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 80cefdeb1..0186f43e5 --- 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 dce81c4ec..1a1bc1d6b --- 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 9cc47a37d..9967ccee1 --- 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 d594aca32..616fc5dfb --- 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 00a0f4d5c..4fa4c1075 --- 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 b0ddda62d..281779f62 --- 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 91fb58f91..92a9b2bb3 --- 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 2b3129978..3afc89c6e --- 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 899841de5..cda7b747f --- 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 1de3aa220..0e721d58c --- 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 000000000..265c61500 --- /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 d762656e3..774109c3a --- 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 8d6fa5141..d85df72b8 --- 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 aeacfcc68..4ed7fbd9f --- 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 7ae48d392..d2da05eb3 --- 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 10926e87f..000000000 --- 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 35e8ea0c2..000000000 --- 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 7bfc3e0d2..000000000 --- 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 a92d56631..000000000 --- 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 52415ff42..000000000 --- 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 000000000..153d416dc --- /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 580e72426..a3ff660be 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 6d323b884..415c8538c 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 66b4d4aca..4f0386abe 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 45e66ec38..f6c065c2c 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 3dea4c0e6..c8a7788de 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 17d6b6a48..8e8866775 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 37a109f46..c2c8e74b2 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 c421b5b1b..1a13c135c 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 000000000..e4204dbbd 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 000000000..a2d7c1468 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 000000000..ae85ce2fe 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 000000000..25031713c 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 000000000..33a84d614 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 000000000..0b7833073 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 000000000..33ab17c1e 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 000000000..30dab932a 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 000000000..0b7533822 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 75771ef97..4734aca32 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 000000000..76cb53848 --- /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 029a6db39..5cac2ca18 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 21eb2ad8b..c49d9ec48 100644 --- a/lib/NeoPixelBus-2.2.9/src/NeoPixelAnimator.h +++ b/lib/NeoPixelBus-2.5.0.09/src/NeoPixelAnimator.h @@ -109,6 +109,8 @@ public: return _animations[indexAnimation]._duration; } + void ChangeAnimationDuration(uint16_t indexAnimation, uint16_t newDuration); + void UpdateAnimations(); bool IsPaused() @@ -159,6 +161,11 @@ private: _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 f6a6b7bab..3c08f83f6 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 @@ public: 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 @@ public: } } + 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 66bd00b0b..a627d0a68 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 @@ public: 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 3719d6fc1..50a33e248 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 @@ public: }; +/* 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 d59d0e0dd..8b3fe3350 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 @@ public: 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 4aabc29c2..7c51816a1 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 @@ public: 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 000000000..092170e20 --- /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 000000000..0027369cf --- /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 a40d6223c..238d4acdb 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 0df0049d7..5b1016ea9 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 34b42a853..9cfce8874 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 @@ public: _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 @@ private: 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 @@ public: 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 @@ public: } }; -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 @@ public: } }; -class NeoArmMk26z64SpeedWs2813 : public NeoArmMk26z64Speed800KbpsBase +class NeoArmMk26z64SpeedWs2812x : public NeoArmMk26z64Speed800KbpsBase { public: - const static uint32_t ResetTimeUs = 250; + const static uint32_t ResetTimeUs = 300; +}; + +class NeoArmMk26z64SpeedSk6812 : public NeoArmMk26z64Speed800KbpsBase +{ +public: + 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 @@ public: } }; -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 @@ public: } }; -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,18 +511,24 @@ public: } }; +class NeoArmStm32SpeedPropsWs2812x : public NeoArmStm32SpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoArmStm32SpeedPropsSk6812 : public NeoArmStm32SpeedProps800KbpsBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + class NeoArmStm32SpeedProps800Kbps : public NeoArmStm32SpeedProps800KbpsBase { public: static const uint32_t ResetTimeUs = 50; }; -class NeoArmStm32SpeedPropsWs2813 : public NeoArmStm32SpeedProps800KbpsBase -{ -public: - static const uint32_t ResetTimeUs = 250; -}; - /* TODO - not found in Adafruit library class NeoArmStm32SpeedProps400Kbps { @@ -521,11 +561,36 @@ public: 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 @@ public: } }; -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 @@ public: } }; -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 9843816f8..b292cf48c 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 @@ public: }; -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 @@ public: _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 @@ private: 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 697967858..870696f48 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 @@ public: _width(0), _height(0), _sizeRow(0), - _bottomToTop(true), - _bytesPerPixel(0) + _bytesPerPixel(0), + _bottomToTop(true) { } - - + ~NeoBitmapFile() { _file.close(); @@ -172,7 +171,7 @@ public: 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 @@ public: 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 @@ public: { 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 @@ public: } } } - + 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 @@ public: { 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 @@ public: } }; + 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 @@ private: 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 86176c9b0..996a77820 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 @@ public: 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 ef69ce6f7..2ec93eb7b 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 @@ public: 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 eaa50239f..b7b5df964 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 @@ public: } } + 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 @@ public: } } + 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 @@ public: } } + 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 @@ public: } } + 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 @@ public: 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 @@ public: } } + 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 @@ public: } } + 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 000000000..d7856a1ef --- /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 000000000..86669e509 --- /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 dc4dd2723..402c9ae85 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 @@ public: _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 @@ public: ~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 @@ public: 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 @@ public: // 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 @@ public: // 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 @@ public: SLCTXL |= SLCTXLS; SLCRXL |= SLCRXLS; - pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA - I2S_CLK_ENABLE(); I2SIC = 0x3F; I2SIE = 0; @@ -232,30 +277,32 @@ public: 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 @@ public: 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 @@ private: // 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 @@ private: 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 @@ private: // 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; + + case NeoDmaState_Zeroing: + s_this->_dmaState = NeoDmaState_Idle; + break; } - - - ETS_SLC_INTR_ENABLE(); } + + ETS_SLC_INTR_ENABLE(); } void FillBuffers() @@ -362,6 +412,16 @@ private: 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 @@ private: 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 000000000..eb06812e6 --- /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 000000000..42c4c63bb --- /dev/null +++ b/lib/NeoPixelBus-2.5.0.09/src/internal/NeoEsp8266UartMethod.h @@ -0,0 +1,434 @@ +/*------------------------------------------------------------------------- +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); + uint8_t *temp = _pixelsSending; + _pixelsSending = _pixels; + _pixels = temp; + } + +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 499f1c3da..361560213 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 @@ public: _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 @@ public: 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; + + 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 @@ private: #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 9b94e2419..4aaf68e4a 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 db51a5d4a..d535316f6 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 3d057e27a..761fa7eb1 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 000000000..f28a5755e --- /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 8e152f8c5..e598fa462 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 @@ public: 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 a0f277eb9..83fb978d3 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 @@ private: 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/SENDMAIL/sendemail.cpp b/lib/SENDMAIL/sendemail.cpp new file mode 100755 index 000000000..ab2c90ecd --- /dev/null +++ b/lib/SENDMAIL/sendemail.cpp @@ -0,0 +1,304 @@ +#include "sendemail.h" + +// enable serial debugging +//#define DEBUG_EMAIL_PORT Serial + +SendEmail::SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const int auth_used) : + host(host), port(port), user(user), passwd(passwd), timeout(timeout), ssl(ssl), auth_used(auth_used), client(new WiFiClientSecure()) +{ + +} + + + +String SendEmail::readClient() +{ + String r = client->readStringUntil('\n'); + r.trim(); + while (client->available()) { + delay(0); + r += client->readString(); + } + return r; +} + +void SetSerialBaudrate(int baudrate); + +bool SendEmail::send(const String& from, const String& to, const String& subject, const String& msg) +{ + if (!host.length()) + { + return false; + } + client->setTimeout(timeout); + // smtp connect +#ifdef DEBUG_EMAIL_PORT + SetSerialBaudrate(115200); + DEBUG_EMAIL_PORT.print("Connecting: "); + DEBUG_EMAIL_PORT.print(host); + DEBUG_EMAIL_PORT.print(":"); + DEBUG_EMAIL_PORT.println(port); +#endif + +#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) +#else + client->setInsecure(); + bool mfln = client->probeMaxFragmentLength(host.c_str(), port, 512); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.printf("MFLN supported: %s\n", mfln ? "yes" : "no"); +#endif + if (mfln) { + client->setBufferSizes(512, 512); + } +#endif + + + if (!client->connect(host.c_str(), port)) + { +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println("Connection failed"); +#endif + return false; + } + + String buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("220"))) + { + return false; + } + + + buffer = F("EHLO "); + buffer += client->localIP().toString(); + + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("250"))) + { + return false; + } + if (user.length()>0 && passwd.length()>0 ) + { + + //buffer = F("STARTTLS"); + //client->println(buffer); + +if (auth_used==1) { + // plain +#ifdef USE_PLAIN + buffer = F("AUTH PLAIN"); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("334"))) + { + return false; + } + + char plainAuth[100]; + memset(plainAuth,sizeof(plainAuth),0); + plainAuth[0] = '\0'; + strcpy(&plainAuth[1], user.c_str()); + strcpy(&plainAuth[2+user.length()],passwd.c_str()); + const char* pA = (const char*)&plainAuth; + char buf[100]; + base64_encode(buf, pA, user.length()+passwd.length()+2); + client->println(buf); + +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buf); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("235"))) + { + return false; + } +#endif + +} else { + + buffer = F("AUTH LOGIN"); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("334"))) + { + return false; + } + base64 b; + //buffer = user; + //buffer = b.encode(buffer); + buffer = b.encode(user); + + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + //DEBUG_EMAIL_PORT.println(user); + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("334"))) + { + return false; + } + //buffer = this->passwd; + //buffer = b.encode(buffer); + buffer = b.encode(passwd); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + //DEBUG_EMAIL_PORT.println(passwd); + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("235"))) + { + return false; + } +} + + } + + // smtp send mail + buffer = F("MAIL FROM:"); + buffer += from; + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("250"))) + { + return false; + } + buffer = F("RCPT TO:"); + buffer += to; + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("250"))) + { + return false; + } + + + buffer = F("DATA"); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = readClient(); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + if (!buffer.startsWith(F("354"))) + { + return false; + } + buffer = F("From: "); + buffer += from; + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = F("To: "); + buffer += to; + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = F("Subject: "); + buffer += subject; + buffer += F("\r\n"); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = msg; + client->println(buffer); + client->println('.'); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + buffer = F("QUIT"); + client->println(buffer); +#ifdef DEBUG_EMAIL_PORT + DEBUG_EMAIL_PORT.println(buffer); +#endif + return true; +} + +#ifdef USE_PLAIN +void SendEmail::a3_to_a4(unsigned char * a4, unsigned char * a3) { + a4[0] = (a3[0] & 0xfc) >> 2; + a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4); + a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6); + a4[3] = (a3[2] & 0x3f); +} + +int SendEmail::base64_encode(char *output, const char *input, int inputLen) { + const char* _b64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int i = 0, j = 0; + int encLen = 0; + unsigned char a3[3]; + unsigned char a4[4]; + while(inputLen--) { + a3[i++] = *(input++); + if(i == 3) { + a3_to_a4(a4, a3); + for(i = 0; i < 4; i++) { + output[encLen++] = _b64_alphabet[a4[i]]; + } + i = 0; + } + } + if(i) { + for(j = i; j < 3; j++) { + a3[j] = '\0'; + } + a3_to_a4(a4, a3); + for(j = 0; j < i + 1; j++) { + output[encLen++] = _b64_alphabet[a4[j]]; + } + while((i++ < 3)) { + output[encLen++] = '='; + } + } + output[encLen] = '\0'; + return encLen; +} +#endif diff --git a/lib/SENDMAIL/sendemail.h b/lib/SENDMAIL/sendemail.h new file mode 100755 index 000000000..394612fc6 --- /dev/null +++ b/lib/SENDMAIL/sendemail.h @@ -0,0 +1,39 @@ +#ifndef __SENDEMAIL_H +#define __SENDEMAIL_H + +//#define DEBUG_EMAIL_PORT + +#include +#include +#include +#include + +class SendEmail +{ + private: + const String host; + const int port; + const String user; + const String passwd; + const int timeout; + const bool ssl; + const int auth_used; +#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) + WiFiClient* client; +#else + // use bear ssl + // #include "WiFiClientSecureLightBearSSL.h" + // BearSSL::WiFiClientSecure_light *client; + BearSSL::WiFiClientSecure* client; + //WiFiClientSecure* client; +#endif + String readClient(); + void a3_to_a4(unsigned char * a4, unsigned char * a3); + int base64_encode(char *output, const char *input, int inputLen); + public: + SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const int auth_used); + bool send(const String& from, const String& to, const String& subject, const String& msg); + ~SendEmail() {client->stop(); delete client;} +}; + +#endif diff --git a/lib/TasmotaModbus-1.1.0/README.md b/lib/TasmotaModbus-1.1.1/README.md similarity index 100% rename from lib/TasmotaModbus-1.1.0/README.md rename to lib/TasmotaModbus-1.1.1/README.md diff --git a/lib/TasmotaModbus-1.1.0/examples/modbustest/modbustest.ino b/lib/TasmotaModbus-1.1.1/examples/modbustest/modbustest.ino similarity index 100% rename from lib/TasmotaModbus-1.1.0/examples/modbustest/modbustest.ino rename to lib/TasmotaModbus-1.1.1/examples/modbustest/modbustest.ino diff --git a/lib/TasmotaModbus-1.1.0/keywords.txt b/lib/TasmotaModbus-1.1.1/keywords.txt similarity index 100% rename from lib/TasmotaModbus-1.1.0/keywords.txt rename to lib/TasmotaModbus-1.1.1/keywords.txt diff --git a/lib/TasmotaModbus-1.1.0/library.json b/lib/TasmotaModbus-1.1.1/library.json similarity index 93% rename from lib/TasmotaModbus-1.1.0/library.json rename to lib/TasmotaModbus-1.1.1/library.json index d983bec32..75066a512 100644 --- a/lib/TasmotaModbus-1.1.0/library.json +++ b/lib/TasmotaModbus-1.1.1/library.json @@ -1,6 +1,6 @@ { "name": "TasmotaModbus", - "version": "1.1.0", + "version": "1.1.1", "keywords": [ "serial", "io", "TasmotaModbus" ], diff --git a/lib/TasmotaModbus-1.1.0/library.properties b/lib/TasmotaModbus-1.1.1/library.properties similarity index 93% rename from lib/TasmotaModbus-1.1.0/library.properties rename to lib/TasmotaModbus-1.1.1/library.properties index bb42fb372..709a71106 100644 --- a/lib/TasmotaModbus-1.1.0/library.properties +++ b/lib/TasmotaModbus-1.1.1/library.properties @@ -1,5 +1,5 @@ name=TasmotaModbus -version=1.1.0 +version=1.1.1 author=Theo Arends maintainer=Theo Arends sentence=Basic modbus wrapper for TasmotaSerial for ESP8266. diff --git a/lib/TasmotaModbus-1.1.0/src/TasmotaModbus.cpp b/lib/TasmotaModbus-1.1.1/src/TasmotaModbus.cpp similarity index 94% rename from lib/TasmotaModbus-1.1.0/src/TasmotaModbus.cpp rename to lib/TasmotaModbus-1.1.1/src/TasmotaModbus.cpp index 207fc07f8..842d242b2 100644 --- a/lib/TasmotaModbus-1.1.0/src/TasmotaModbus.cpp +++ b/lib/TasmotaModbus-1.1.1/src/TasmotaModbus.cpp @@ -100,7 +100,10 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count) } if (len < 7) { return 7; } // 7 = Not enough data - if (len != buffer[2] + 5) { return 8; } // 8 = Unexpected result + if (len != buffer[2] + 5) { + buffer[2] = len - 5; // As it's wrong anyway let's store actual number received in here (5 will be added by client) + return 8; // 8 = Unexpected result + } uint16_t crc = (buffer[len -1] << 8) | buffer[len -2]; if (CalculateCRC(buffer, len -2) != crc) { return 9; } // 9 = crc error diff --git a/lib/TasmotaModbus-1.1.0/src/TasmotaModbus.h b/lib/TasmotaModbus-1.1.1/src/TasmotaModbus.h similarity index 100% rename from lib/TasmotaModbus-1.1.0/src/TasmotaModbus.h rename to lib/TasmotaModbus-1.1.1/src/TasmotaModbus.h diff --git a/lib/TasmotaSerial-2.3.3/README.md b/lib/TasmotaSerial-2.4.0/README.md similarity index 100% rename from lib/TasmotaSerial-2.3.3/README.md rename to lib/TasmotaSerial-2.4.0/README.md diff --git a/lib/TasmotaSerial-2.3.3/examples/swsertest/swsertest.ino b/lib/TasmotaSerial-2.4.0/examples/swsertest/swsertest.ino similarity index 100% rename from lib/TasmotaSerial-2.3.3/examples/swsertest/swsertest.ino rename to lib/TasmotaSerial-2.4.0/examples/swsertest/swsertest.ino diff --git a/lib/TasmotaSerial-2.3.3/keywords.txt b/lib/TasmotaSerial-2.4.0/keywords.txt similarity index 100% rename from lib/TasmotaSerial-2.3.3/keywords.txt rename to lib/TasmotaSerial-2.4.0/keywords.txt diff --git a/lib/TasmotaSerial-2.3.3/library.json b/lib/TasmotaSerial-2.4.0/library.json similarity index 94% rename from lib/TasmotaSerial-2.3.3/library.json rename to lib/TasmotaSerial-2.4.0/library.json index b9017bc98..cdce0deba 100644 --- a/lib/TasmotaSerial-2.3.3/library.json +++ b/lib/TasmotaSerial-2.4.0/library.json @@ -1,6 +1,6 @@ { "name": "TasmotaSerial", - "version": "2.3.2", + "version": "2.4.0", "keywords": [ "serial", "io", "TasmotaSerial" ], diff --git a/lib/TasmotaSerial-2.3.3/library.properties b/lib/TasmotaSerial-2.4.0/library.properties similarity index 94% rename from lib/TasmotaSerial-2.3.3/library.properties rename to lib/TasmotaSerial-2.4.0/library.properties index 1401ae8e3..f1486dfab 100644 --- a/lib/TasmotaSerial-2.3.3/library.properties +++ b/lib/TasmotaSerial-2.4.0/library.properties @@ -1,5 +1,5 @@ name=TasmotaSerial -version=2.3.2 +version=2.4.0 author=Theo Arends maintainer=Theo Arends sentence=Implementation of software serial with hardware serial fallback for ESP8266. diff --git a/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp b/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp similarity index 73% rename from lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp rename to lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp index 42b15937f..5ffcaf390 100644 --- a/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.cpp +++ b/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp @@ -27,6 +27,9 @@ extern "C" { #include +// for STAGE and pre-2.6, we can have a single wrapper using attachInterruptArg() +void ICACHE_RAM_ATTR callRxRead(void *self) { ((TasmotaSerial*)self)->rxRead(); }; + // As the Arduino attachInterrupt has no parameter, lists of objects // and callbacks corresponding to each possible GPIO pins have to be defined TasmotaSerial *tms_obj_list[16]; @@ -83,6 +86,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal 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; } @@ -102,9 +106,14 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal if (m_buffer == NULL) return; // Use getCycleCount() loop to get as exact timing as possible m_bit_time = ESP.getCpuFreqMHz() * 1000000 / TM_SERIAL_BAUDRATE; + m_bit_start_time = m_bit_time + m_bit_time/3 - 500; // pre-compute first wait pinMode(m_rx_pin, INPUT); tms_obj_list[m_rx_pin] = this; +#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_5_2) attachInterrupt(m_rx_pin, ISRList[m_rx_pin], (m_nwmode) ? CHANGE : FALLING); +#else + attachInterruptArg(m_rx_pin, callRxRead, this, (m_nwmode) ? CHANGE : FALLING); +#endif } if (m_tx_pin > -1) { pinMode(m_tx_pin, OUTPUT); @@ -147,7 +156,9 @@ bool TasmotaSerial::begin(long speed, int stop_bits) { } else { // Use getCycleCount() loop to get as exact timing as possible m_bit_time = ESP.getCpuFreqMHz() * 1000000 / speed; + m_bit_start_time = m_bit_time + m_bit_time/3 - (ESP.getCpuFreqMHz() > 120 ? 700 : 500); // pre-compute first wait m_high_speed = (speed >= 9600); + m_very_high_speed = (speed >= 100000); } return m_valid; } @@ -201,9 +212,13 @@ int TasmotaSerial::available() } #ifdef TM_SERIAL_USE_IRAM -#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait) if (!m_high_speed) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts +#define TM_SERIAL_WAIT_SND { while (ESP.getCycleCount() < (wait + start)) if (!m_high_speed) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts +#define TM_SERIAL_WAIT_RCV { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } +#define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #else -#define TM_SERIAL_WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bit_time; } +#define TM_SERIAL_WAIT_SND { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } +#define TM_SERIAL_WAIT_RCV { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } +#define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #endif size_t TasmotaSerial::write(uint8_t b) @@ -214,22 +229,23 @@ size_t TasmotaSerial::write(uint8_t b) if (-1 == m_tx_pin) return 0; if (m_high_speed) cli(); // Disable interrupts in order to get a clean transmit uint32_t wait = m_bit_time; - digitalWrite(m_tx_pin, HIGH); + //digitalWrite(m_tx_pin, HIGH); // already in HIGH mode uint32_t start = ESP.getCycleCount(); // Start bit; digitalWrite(m_tx_pin, LOW); - TM_SERIAL_WAIT; + TM_SERIAL_WAIT_SND; for (uint32_t i = 0; i < 8; i++) { digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW); - TM_SERIAL_WAIT; + TM_SERIAL_WAIT_SND; b >>= 1; } // Stop bit(s) - for (uint32_t i = 0; i < m_stop_bits; i++) { - digitalWrite(m_tx_pin, HIGH); - TM_SERIAL_WAIT; - } + digitalWrite(m_tx_pin, HIGH); + // re-enable interrupts during stop bits, it's not an issue if they are longer than expected if (m_high_speed) sei(); + for (uint32_t i = 0; i < m_stop_bits; i++) { + TM_SERIAL_WAIT_SND; + } return 1; } } @@ -242,27 +258,50 @@ void TasmotaSerial::rxRead() { #endif if (!m_nwmode) { + int32_t loop_read = m_very_high_speed ? serial_buffer_size : 1; // 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 wait = m_bit_start_time; 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; - 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; + while (loop_read-- > 0) { // try to receveive all consecutive bytes in a raw + uint32_t rec = 0; + for (uint32_t i = 0; i < 8; i++) { + TM_SERIAL_WAIT_RCV; + rec >>= 1; + if (digitalRead(m_rx_pin)) rec |= 0x80; + } + // 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; + } + + TM_SERIAL_WAIT_RCV_LOOP; // wait for stop bit + if (2 == m_stop_bits) { + wait += m_bit_time; + TM_SERIAL_WAIT_RCV_LOOP; + } + wait += m_bit_time / 4; + + if (loop_read <= 0) { break; } // exit now if not very high speed or buffer full + + bool start_of_next_byte = false; + for (uint32_t i = 0; i < 12; i++) { + TM_SERIAL_WAIT_RCV_LOOP; // wait for 1/4 bits + wait += m_bit_time / 4; + if (!digitalRead(m_rx_pin)) { + // this is the start bit of the next byte + wait += m_bit_time; // we have advanced in the first 1/4 of bit, and already added 1/4 of bit so we're roughly centered. Just skip start bit. + start_of_next_byte = true; + m_bit_follow_metric++; + break; // exit loop + } + } + + if (!start_of_next_byte) { + break; // exit now if no sign of next byte + } } // Must clear this bit in the interrupt register, // it gets set even when interrupts are disabled diff --git a/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h b/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h similarity index 91% rename from lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h rename to lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h index 8c6340977..41f3cd0d7 100644 --- a/lib/TasmotaSerial-2.3.3/src/TasmotaSerial.h +++ b/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h @@ -53,6 +53,8 @@ class TasmotaSerial : public Stream { void rxRead(); + uint32_t getLoopReadMetric(void) const { return m_bit_follow_metric; } + using Print::write; private: @@ -67,6 +69,8 @@ class TasmotaSerial : public Stream { uint32_t ss_bstart; uint32_t ss_index; uint32_t m_bit_time; + uint32_t m_bit_start_time; + uint32_t m_bit_follow_metric = 0; uint32_t m_in_pos; uint32_t m_out_pos; uint32_t serial_buffer_size; @@ -74,7 +78,8 @@ class TasmotaSerial : public Stream { bool m_nwmode; bool m_hardserial; bool m_hardswap; - bool m_high_speed; + bool m_high_speed = false; + bool m_very_high_speed = false; // above 100000 bauds uint8_t *m_buffer; }; diff --git a/platformio.ini b/platformio.ini index b92cf42ee..d19018416 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 b94815cd0..40c3dd772 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,7 +1,25 @@ /*********************************************************************************************\ + * 6.6.0.11 20190907 + * Change Settings crc calculation allowing short term backward compatibility + * Add support for up to 4 INA226 Voltage and Current sensors by Steve Rogers (#6342) + * Change Improve reliability of TasmotaSerial at 115200 bauds and reduce IRAM usage for Stage/pre-2.6 + * Add support for A4988 stepper-motor-driver-circuit by Tim Leuschner (#6370) + * + * 6.6.0.10 20190905 + * Redesign Tuya support by Shantur Rathore (#6353) + * Add command Reset 99 to reset bootcount to zero (#684, #6351) + * Change command Time 1/2/3 to select JSON time format ISO, ISO + Epoch or Epoch for legacy reason + * * 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 38f524e4c..0aba9f63d 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" @@ -96,6 +96,7 @@ #define D_JSON_LOW "Low" #define D_JSON_MAC "Mac" #define D_JSON_MASK "Mask" +#define D_JSON_MEMORY_ERROR "Memory error" #define D_JSON_MINIMAL "minimal" #define D_JSON_MODEL "Model" #define D_JSON_MQTT_COUNT "MqttCount" @@ -148,7 +149,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" @@ -326,6 +327,7 @@ #define D_CMND_WEBCOLOR "WebColor" #define D_CMND_WEBSENSOR "WebSensor" #define D_CMND_EMULATION "Emulation" +#define D_CMND_SENDMAIL "Sendmail" // Commands xdrv_03_energy.ino #define D_CMND_POWERLOW "PowerLow" @@ -444,6 +446,28 @@ #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" + + // Commands xdrv_25_A4988_Stepper.ino + #ifdef USE_A4988_Stepper + #define D_CMND_MOTOR "MOTOR" + #define D_JSON_MOTOR_MOVE "doMove" + #define D_JSON_MOTOR_ROTATE "doRotate" + #define D_JSON_MOTOR_TURN "doTurn" + #define D_JSON_MOTOR_SPR "setSPR" + #define D_JSON_MOTOR_RPM "setRPM" + #define D_JSON_MOTOR_MIS "setMIS" + #endif + /********************************************************************************************/ #define D_ASTERISK_PWD "****" @@ -574,7 +598,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/language/bg-BG.h b/sonoff/language/bg-BG.h index b3c9fdc52..a6d05efc5 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -597,6 +597,13 @@ #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" + // Units #define D_UNIT_AMPERE "A" #define D_UNIT_CENTIMETER "cm" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 2f5ce2b9c..264faf797 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index b6bb4f205..d3f280ded 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 7c9f5d0fc..8f056dcdf 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index b69a3a622..4cd665634 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index d3218349a..0300d6f4d 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index f4e66e6f3..28eb6a8a6 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index 285496b1f..504614de4 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index b9b787227..529bb8604 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 8bbdb8b35..dc3d6c0dd 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -147,9 +147,9 @@ #define D_START "Start" #define D_STD_TIME "STD" #define D_STOP "Stop" -#define D_SUBNET_MASK "Maschera sottorete" +#define D_SUBNET_MASK "Maschera Subnet" #define D_SUBSCRIBE_TO "Sottoscrivi a" -#define D_UNSUBSCRIBE_FROM "Unsubscribe from" +#define D_UNSUBSCRIBE_FROM "Cancella da" #define D_SUCCESSFUL "Riuscito" #define D_SUNRISE "Alba" #define D_SUNSET "Tramonto" @@ -161,16 +161,16 @@ #define D_TRANSMIT "Trasmesso" #define D_TRUE "Vero" #define D_TVOC "TVOC" -#define D_UPGRADE "aggiornamento" +#define D_UPGRADE "Aggiornamento" #define D_UPLOAD "Invio" #define D_UPTIME "Uptime" #define D_USER "Utente" #define D_UTC_TIME "UTC" #define D_UV_INDEX "Indice UV" -#define D_UV_INDEX_1 "Low" -#define D_UV_INDEX_2 "Mid" -#define D_UV_INDEX_3 "High" -#define D_UV_INDEX_4 "Danger" +#define D_UV_INDEX_1 "Basso" +#define D_UV_INDEX_2 "Medio" +#define D_UV_INDEX_3 "Alto" +#define D_UV_INDEX_4 "Pericolo" #define D_UV_INDEX_5 "BurnL1/2" #define D_UV_INDEX_6 "BurnL3" #define D_UV_INDEX_7 "OoR" @@ -186,7 +186,7 @@ #define D_WARNING_MINIMAL_VERSION "ATTENZIONE Questa versione non supporta il salvataggio delle impostazioni" #define D_LEVEL_10 "level 1-0" #define D_LEVEL_01 "level 0-1" -#define D_SERIAL_LOGGING_DISABLED "Log seriale disabilitato" +#define D_SERIAL_LOGGING_DISABLED "Log Seriale disabilitato" #define D_SYSLOG_LOGGING_REENABLED "Syslog ri-abilitato" #define D_SET_BAUDRATE_TO "Baudrate impostato a" @@ -198,11 +198,11 @@ #define D_OSWATCH "osWatch" #define D_BLOCKED_LOOP "Ciclo Bloccato" #define D_WPS_FAILED_WITH_STATUS "WPSconfig Fallito con stato" -#define D_ACTIVE_FOR_3_MINUTES "attivo per 3 minuti" +#define D_ACTIVE_FOR_3_MINUTES "Attivo per 3 minuti" #define D_FAILED_TO_START "partenza fallita" #define D_PATCH_ISSUE_2186 "Patch issue 2186" #define D_CONNECTING_TO_AP "Connessione ad AP" -#define D_IN_MODE "in modalità" +#define D_IN_MODE "In modalità" #define D_CONNECT_FAILED_NO_IP_ADDRESS "Connessione fallita, indirizzo IP non ricevuto" #define D_CONNECT_FAILED_AP_NOT_REACHED "Connessione fallita, AP non raggiungibile" #define D_CONNECT_FAILED_WRONG_PASSWORD "Connessione fallita, password AP non corretta" @@ -259,8 +259,8 @@ #define D_PULLUP_ENABLE "No Button/Switch pull-up" #define D_ADC "ADC" #define D_GPIO "GPIO" -#define D_SERIAL_IN "Serial In" -#define D_SERIAL_OUT "Serial Out" +#define D_SERIAL_IN "Seriale In" +#define D_SERIAL_OUT "Seriale Out" #define D_WIFI_PARAMETERS "Parametri Wifi" #define D_SCAN_FOR_WIFI_NETWORKS "Scansione delle reti wifi" @@ -283,30 +283,30 @@ #define D_FULL_TOPIC "Full Topic" #define D_LOGGING_PARAMETERS "Parametri Logging" -#define D_SERIAL_LOG_LEVEL "Seriale livello di log" -#define D_WEB_LOG_LEVEL "Web livello di log" -#define D_SYS_LOG_LEVEL "Sys livello di log" +#define D_SERIAL_LOG_LEVEL "Livello di log Seriale" +#define D_WEB_LOG_LEVEL "livello di log Web" +#define D_SYS_LOG_LEVEL "livello di log Sys" #define D_MORE_DEBUG "Debug aggiuntivo" #define D_SYSLOG_HOST "Syslog host" #define D_SYSLOG_PORT "Syslog porta" #define D_TELEMETRY_PERIOD "Periodo Telemetria" #define D_OTHER_PARAMETERS "Altri parametri" -#define D_TEMPLATE "Template" -#define D_ACTIVATE "Activate" +#define D_TEMPLATE "Modello" +#define D_ACTIVATE "Attivare" #define D_WEB_ADMIN_PASSWORD "Password Amministratore Web" #define D_MQTT_ENABLE "Abilita MQTT" -#define D_FRIENDLY_NAME "Nome confidenziale" +#define D_FRIENDLY_NAME "Nome amichevole" #define D_BELKIN_WEMO "Belkin WeMo" #define D_HUE_BRIDGE "Hue Bridge" #define D_SINGLE_DEVICE "dispositivo singolo" #define D_MULTI_DEVICE "dispositivo multiplo" -#define D_CONFIGURE_TEMPLATE "Configure Template" -#define D_TEMPLATE_PARAMETERS "Template parameters" -#define D_TEMPLATE_NAME "Name" -#define D_BASE_TYPE "Based on" -#define D_TEMPLATE_FLAGS "Options" +#define D_CONFIGURE_TEMPLATE "Configurare Modello" +#define D_TEMPLATE_PARAMETERS "Parametri Modello" +#define D_TEMPLATE_NAME "Nome" +#define D_BASE_TYPE "Baseto nel" +#define D_TEMPLATE_FLAGS "Opzioni" #define D_SAVE_CONFIGURATION "Salva configurazione" #define D_CONFIGURATION_SAVED "Configurazione salvata" @@ -464,12 +464,12 @@ #define D_PARTICALS_BEYOND "Particelle" // xsns_32_mpu6050.ino -#define D_AX_AXIS "Accel. X-Axis" -#define D_AY_AXIS "Accel. Y-Axis" -#define D_AZ_AXIS "Accel. Z-Axis" -#define D_GX_AXIS "Gyro X-Axis" -#define D_GY_AXIS "Gyro Y-Axis" -#define D_GZ_AXIS "Gyro Z-Axis" +#define D_AX_AXIS "Accel. Asse-X" +#define D_AY_AXIS "Accel. Asse-Y" +#define D_AZ_AXIS "Accel. Asse-Z" +#define D_GX_AXIS "Gyro Asse-X" +#define D_GY_AXIS "Gyro Asse-Y" +#define D_GZ_AXIS "Gyro Asse-Z" // xsns_34_hx711.ino #define D_HX_CAL_REMOVE "Rimuovere peso" @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ko-KO.h b/sonoff/language/ko-KO.h index e4488e72a..98cae588b 100644 --- a/sonoff/language/ko-KO.h +++ b/sonoff/language/ko-KO.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 6c720d687..b0009f3e0 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index ea4038b52..b2d465288 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index c62c9fe32..2025a665b 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -65,8 +65,8 @@ #define D_BY "por" // Write by me #define D_BYTES "Bytes" #define D_CELSIUS "Celsius" -#define D_CHANNEL "Channel" -#define D_CO2 "Dióxido de carbono" +#define D_CHANNEL "Canal" +#define D_CO2 "CO2" #define D_CODE "Código" // Button code #define D_COLDLIGHT "Luz fria" #define D_COMMAND "Comando" @@ -93,14 +93,14 @@ #define D_FALLBACK_TOPIC "Tópico para retornar" #define D_FALSE "Falso" #define D_FILE "Arquivo" -#define D_FLOW_RATE "Flow rate" +#define D_FLOW_RATE "Quociente de vazão" #define D_FREE_MEMORY "Memória livre" #define D_FREQUENCY "Frequência" #define D_GAS "Gás" #define D_GATEWAY "Gateway" #define D_GROUP "Grupo" -#define D_HOST "Anfitrião" -#define D_HOSTNAME "Nome do anfitrião" +#define D_HOST "Host" +#define D_HOSTNAME "Nome do Host" #define D_HUMIDITY "Umidade" #define D_ILLUMINANCE "Luminância" #define D_IMMEDIATE "Imediato" // Button immediate @@ -167,10 +167,10 @@ #define D_USER "Usuário" #define D_UTC_TIME "UTC" #define D_UV_INDEX "Índice UV" -#define D_UV_INDEX_1 "Low" -#define D_UV_INDEX_2 "Mid" -#define D_UV_INDEX_3 "High" -#define D_UV_INDEX_4 "Danger" +#define D_UV_INDEX_1 "Baixo" +#define D_UV_INDEX_2 "Médio" +#define D_UV_INDEX_3 "Alto" +#define D_UV_INDEX_4 "Perigro" #define D_UV_INDEX_5 "BurnL1/2" #define D_UV_INDEX_6 "BurnL3" #define D_UV_INDEX_7 "OoR" @@ -178,7 +178,7 @@ #define D_UV_POWER "UV Power" #define D_VERSION "Versão" #define D_VOLTAGE "Voltagem" -#define D_WEIGHT "Weight" +#define D_WEIGHT "Peso" #define D_WARMLIGHT "Luz quente" #define D_WEB_SERVER "Servidor WEB" @@ -186,7 +186,7 @@ #define D_WARNING_MINIMAL_VERSION "AVISO: esta versão não supporta configurações persistentes" #define D_LEVEL_10 "nível 1-0" #define D_LEVEL_01 "nível 0-1" -#define D_SERIAL_LOGGING_DISABLED "Registro em série desabilitado" +#define D_SERIAL_LOGGING_DISABLED "Registro Serial desabilitado" #define D_SYSLOG_LOGGING_REENABLED "Registro do Syslog reativado" #define D_SET_BAUDRATE_TO "Ajuste da velocidade para" @@ -292,7 +292,7 @@ #define D_TELEMETRY_PERIOD "Período de telemetria" #define D_OTHER_PARAMETERS "Outros parâmetros" -#define D_TEMPLATE "Template" +#define D_TEMPLATE "Modelo" #define D_ACTIVATE "Activate" #define D_WEB_ADMIN_PASSWORD "Senha de WEB Admin" #define D_MQTT_ENABLE "MQTT habilitado" @@ -302,11 +302,11 @@ #define D_SINGLE_DEVICE "Dispositivo único" #define D_MULTI_DEVICE "Múltiplos dispositivos" -#define D_CONFIGURE_TEMPLATE "Configure Template" -#define D_TEMPLATE_PARAMETERS "Template parameters" -#define D_TEMPLATE_NAME "Name" -#define D_BASE_TYPE "Based on" -#define D_TEMPLATE_FLAGS "Options" +#define D_CONFIGURE_TEMPLATE "Configurar Modelo" +#define D_TEMPLATE_PARAMETERS "Parâmetros Modelo" +#define D_TEMPLATE_NAME "Nome" +#define D_BASE_TYPE "Baseado em" +#define D_TEMPLATE_FLAGS "Opções" #define D_SAVE_CONFIGURATION "Gravar configuração" #define D_CONFIGURATION_SAVED "Configuração gravada" @@ -347,10 +347,10 @@ #define D_UPLOAD_ERR_7 "Envio cancelado" #define D_UPLOAD_ERR_8 "Arquivo inválido" #define D_UPLOAD_ERR_9 "Arquivo muito grande" -#define D_UPLOAD_ERR_10 "Failed to init RF chip" -#define D_UPLOAD_ERR_11 "Failed to erase RF chip" -#define D_UPLOAD_ERR_12 "Failed to write to RF chip" -#define D_UPLOAD_ERR_13 "Failed to decode RF firmware" +#define D_UPLOAD_ERR_10 "Falha ao iniciar chip RF" +#define D_UPLOAD_ERR_11 "Falha ao apagar o chip RF" +#define D_UPLOAD_ERR_12 "Falha ao escrever o chip RF" +#define D_UPLOAD_ERR_13 "Falha ao decodificar o firmware de RF" #define D_UPLOAD_ERROR_CODE "Código de erro do envio" #define D_ENTER_COMMAND "Inserir comando" @@ -472,27 +472,27 @@ #define D_GZ_AXIS "Gyro Z-Axis" // xsns_34_hx711.ino -#define D_HX_CAL_REMOVE "Remove weigth" -#define D_HX_CAL_REFERENCE "Load reference weigth" -#define D_HX_CAL_DONE "Calibrated" -#define D_HX_CAL_FAIL "Calibration failed" -#define D_RESET_HX711 "Reset Scale" -#define D_CONFIGURE_HX711 "Configure Scale" -#define D_HX711_PARAMETERS "Scale parameters" -#define D_ITEM_WEIGHT "Item weight" -#define D_REFERENCE_WEIGHT "Reference weigth" -#define D_CALIBRATE "Calibrate" -#define D_CALIBRATION "Calibration" +#define D_HX_CAL_REMOVE "Remover peso" +#define D_HX_CAL_REFERENCE "Peso de referência de carga" +#define D_HX_CAL_DONE "Calibrado" +#define D_HX_CAL_FAIL "Falha na calibração" +#define D_RESET_HX711 "Redefinir escala" +#define D_CONFIGURE_HX711 "Configurar escala" +#define D_HX711_PARAMETERS "Parâmetros de escala" +#define D_ITEM_WEIGHT "Peso do Item" +#define D_REFERENCE_WEIGHT "Peso de referência" +#define D_CALIBRATE "Calibrar" +#define D_CALIBRATION "Calibração" //xsns_35_tx20.ino -#define D_TX20_WIND_DIRECTION "Wind Direction" -#define D_TX20_WIND_SPEED "Wind Speed" -#define D_TX20_WIND_SPEED_AVG "Wind Speed Avg" -#define D_TX20_WIND_SPEED_MAX "Wind Speed Max" +#define D_TX20_WIND_DIRECTION "Direção do vento" +#define D_TX20_WIND_SPEED "Velocidade do vento" +#define D_TX20_WIND_SPEED_AVG "Velocidade média do vento" +#define D_TX20_WIND_SPEED_MAX "Velocidade do vento Máxima" #define D_TX20_NORTH "N" -#define D_TX20_EAST "E" +#define D_TX20_EAST "L" #define D_TX20_SOUTH "S" -#define D_TX20_WEST "W" +#define D_TX20_WEST "O" //xsns_43_hre.ino #define D_LOG_HRE "HRE: " @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" @@ -657,37 +663,37 @@ #define D_LOG_WIFI "WIF: " // Wifi //SDM220 -#define D_PHASE_ANGLE "Phase Angle" -#define D_IMPORT_ACTIVE "Import Active" -#define D_EXPORT_ACTIVE "Export Active" -#define D_IMPORT_REACTIVE "Import Reactive" -#define D_EXPORT_REACTIVE "Export Reactive" -#define D_TOTAL_REACTIVE "Total Reactive" +#define D_PHASE_ANGLE "Ângulo de Fase" +#define D_IMPORT_ACTIVE "Importar Ativo" +#define D_EXPORT_ACTIVE "Exportar Ativo" +#define D_IMPORT_REACTIVE "Importar Reativo" +#define D_EXPORT_REACTIVE "Exportar Reativo" +#define D_TOTAL_REACTIVE "Reativo total" #define D_UNIT_KWARH "kVArh" #define D_UNIT_ANGLE "Deg" //SOLAXX1 -#define D_PV1_VOLTAGE "PV1 Voltage" -#define D_PV1_CURRENT "PV1 Current" -#define D_PV1_POWER "PV1 Power" -#define D_PV2_VOLTAGE "PV2 Voltage" -#define D_PV2_CURRENT "PV2 Current" -#define D_PV2_POWER "PV2 Power" -#define D_SOLAR_POWER "Solar Power" -#define D_INVERTER_POWER "Inverter Power" +#define D_PV1_VOLTAGE "PV1 Voltagem" +#define D_PV1_CURRENT "PV1 Corrente" +#define D_PV1_POWER "PV1 Energia" +#define D_PV2_VOLTAGE "PV2 Voltagem" +#define D_PV2_CURRENT "PV2 Corrente" +#define D_PV2_POWER "PV2 Energia" +#define D_SOLAR_POWER "Energia Solar" +#define D_INVERTER_POWER "Potência do Inversor" #define D_STATUS "Status" -#define D_WAITING "Waiting" -#define D_CHECKING "Checking" -#define D_WORKING "Working" -#define D_FAILURE "Failure" -#define D_SOLAX_ERROR_0 "No Error Code" -#define D_SOLAX_ERROR_1 "Grid Lost Fault" -#define D_SOLAX_ERROR_2 "Grid Voltage Fault" -#define D_SOLAX_ERROR_3 "Grid Frequency Fault" -#define D_SOLAX_ERROR_4 "Pv Voltage Fault" -#define D_SOLAX_ERROR_5 "Isolation Fault" -#define D_SOLAX_ERROR_6 "Over Temperature Fault" -#define D_SOLAX_ERROR_7 "Fan Fault" -#define D_SOLAX_ERROR_8 "Other Device Fault" +#define D_WAITING "Esperando" +#define D_CHECKING "Verificando" +#define D_WORKING "Trabalhando" +#define D_FAILURE "Falha" +#define D_SOLAX_ERROR_0 "Nenhum código de erro" +#define D_SOLAX_ERROR_1 "Erro Grid Perdida" +#define D_SOLAX_ERROR_2 "Falha na Tensão da rede" +#define D_SOLAX_ERROR_3 "Falha na Frequência do Grid" +#define D_SOLAX_ERROR_4 "Pv Falha de Tensão" +#define D_SOLAX_ERROR_5 "Falha de Isolamento" +#define D_SOLAX_ERROR_6 "Falha de Temperatura excessiva" +#define D_SOLAX_ERROR_7 "Falha no Ventilador" +#define D_SOLAX_ERROR_8 "Outra falha do dispositivo" #endif // _LANGUAGE_PT_BR_H_ diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 8dc4b04ae..9313cf287 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index d4eff4456..743e2bf9e 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h index 2c880618c..9d99c63ee 100644 --- a/sonoff/language/sk-SK.h +++ b/sonoff/language/sk-SK.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h index 10d209e95..33ebf9f3a 100644 --- a/sonoff/language/sv-SE.h +++ b/sonoff/language/sv-SE.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index 402baa968..ab9c9e11e 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index ca4c09fdd..72c1c6144 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 690ba880b..d0b6b7a5e 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 9acef9180..6febe1a6b 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -596,6 +596,12 @@ #define D_SENSOR_IBEACON_RX "iBeacon RX" #define D_SENSOR_RDM6300_RX "RDM6300 RX" #define D_SENSOR_CC1101_CS "CC1101 CS" +#define D_SENSOR_A4988_DIR "A4988 DIR" +#define D_SENSOR_A4988_STP "A4988 STP" +#define D_SENSOR_A4988_ENA "A4988 ENA" +#define D_SENSOR_A4988_MS1 "A4988 MS1" +#define D_SENSOR_A4988_MS2 "A4988 MS2" +#define D_SENSOR_A4988_MS3 "A4988 MS3" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 8b72d0f27..e289d8f93 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -302,12 +302,13 @@ //#define USE_SCRIPT_FATFS 4 // Script: Add FAT FileSystem Support // #define USE_EXPRESSION // Add support for expression evaluation in rules (+3k2 code, +64 bytes mem) +// #define SUPPORT_IF_STATEMENT // Add support for IF statement in rules (+4k2 code, -332 bytes mem) // #define SUPPORT_MQTT_EVENT // Support trigger event with MQTT subscriptions (+3k5 code) // -- 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) @@ -341,6 +342,7 @@ // #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code) // #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code) // #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code) +// #define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code) #define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code) // #define USE_TSL2561 // Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code) // #define USE_MGS // Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code) @@ -429,8 +431,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,9 +452,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 -------------------------- -//#define USE_IR_REMOTE_FULL // Activate all protocols from IRremoteESP8266 - // actovating this option will ignore all other USE_IR_REMOTE_* options and set them all to active +// -- 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 @@ -483,12 +494,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)) @@ -511,6 +529,7 @@ #define USE_SM16716 // Add support for SM16716 RGB LED controller (+0k7 code) //#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code) +//#define USE_A4988_Stepper // Add support for A4988 stepper-motor-driver-circuit (+10k5 code) /*********************************************************************************************\ * Debug features @@ -532,12 +551,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 20b3202b6..eb58877cb 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -78,7 +78,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages uint32_t no_power_feedback : 1; // bit 13 (v6.5.0.9) - SetOption63 - Don't scan relay power state at restart uint32_t use_underscore : 1; // bit 14 (v6.5.0.12) - SetOption64 - Enable "_" instead of "-" as sensor index separator - uint32_t tuya_disable_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Tuya Serial Dimmer control + uint32_t ex_tuya_disable_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - (Enable or Disable Tuya Serial Dimmer control) - free since 6.6.0.10 uint32_t tuya_dimmer_range_255 : 1; // bit 16 (v6.6.0.1) - SetOption66 - Enable or Disable Dimmer range 255 slider control uint32_t buzzer_enable : 1; // bit 17 (v6.6.0.1) - SetOption67 - Enable buzzer when available uint32_t pwm_multi_channels : 1; // bit 18 (v6.6.0.3) - SetOption68 - Enable multi-channels PWM instead of Color PWM @@ -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; @@ -182,10 +181,18 @@ typedef struct { uint32_t usage1_kWhtoday; uint32_t return1_kWhtotal; uint32_t return2_kWhtotal; - uint32_t last_usage_kWhtotal; uint32_t last_return_kWhtotal; + uint32_t free; } 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,15 @@ 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 + uint16_t ina226_r_shunt[4]; // E20 + uint16_t ina226_i_fs[4]; // E28 - uint8_t free_e20[448]; // E40 + uint8_t free_e30[456]; // E30 - // FFF last location + uint32_t cfg_timestamp; // FF8 + uint32_t cfg_crc32; // FFC } Settings; struct RTCRBT { diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 4bdae99ff..9534c0ab6 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -273,8 +273,8 @@ const uint32_t SETTINGS_LOCATION = SPIFFS_END; // No need for SPIFFS as it uses // Version 5.2 allow for more flash space const uint8_t CFG_ROTATES = 8; // Number of flash sectors used (handles uploads) -uint16_t settings_crc = 0; uint32_t settings_location = SETTINGS_LOCATION; +uint32_t settings_crc32 = 0; uint8_t *settings_buffer = nullptr; /********************************************************************************************/ @@ -318,19 +318,42 @@ bool SettingsBufferAlloc(void) return true; } -uint16_t GetSettingsCrc(void) +uint16_t GetCfgCrc16(uint8_t *bytes, uint32_t size) { uint16_t crc = 0; - uint8_t *bytes = (uint8_t*)&Settings; - // Fix miscalculation if previous Settings was 3584 and current Settings is 4096 as of 0x06060007 - uint32_t size = (Settings.version < 0x06060007) ? 3584 : sizeof(SYSCFG); for (uint32_t i = 0; i < size; i++) { if ((i < 14) || (i > 15)) { crc += bytes[i]*(i+1); } // Skip crc } return crc; } +uint16_t GetSettingsCrc(void) +{ + // Fix miscalculation if previous Settings was 3584 and current Settings is 4096 between 0x06060007 and 0x0606000A + uint32_t size = ((Settings.version < 0x06060007) || (Settings.version > 0x0606000A)) ? 3584 : sizeof(SYSCFG); + return GetCfgCrc16((uint8_t*)&Settings, size); +} + +uint32_t GetCfgCrc32(uint8_t *bytes, uint32_t size) +{ + // https://create.stephan-brumme.com/crc32/#bitwise + uint32_t crc = 0; + + while (size--) { + crc ^= *bytes++; + for (uint32_t j = 0; j < 8; j++) { + crc = (crc >> 1) ^ (-int(crc & 1) & 0xEDB88320); + } + } + return ~crc; +} + +uint32_t GetSettingsCrc32(void) +{ + return GetCfgCrc32((uint8_t*)&Settings, sizeof(SYSCFG) -4); // Skip crc32 +} + void SettingsSaveAll(void) { if (Settings.flag.save_state) { @@ -340,9 +363,6 @@ void SettingsSaveAll(void) } XsnsCall(FUNC_SAVE_BEFORE_RESTART); XdrvCall(FUNC_SAVE_BEFORE_RESTART); -#ifdef USE_EEPROM - EepromCommit(); -#endif SettingsSave(0); } @@ -366,7 +386,7 @@ void SettingsSave(uint8_t rotate) * stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1) */ #ifndef FIRMWARE_MINIMAL - if ((GetSettingsCrc() != settings_crc) || rotate) { + if ((GetSettingsCrc32() != settings_crc32) || rotate) { if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade) stop_flash_rotate = 1; } @@ -381,32 +401,19 @@ void SettingsSave(uint8_t rotate) settings_location = SETTINGS_LOCATION; } } - Settings.save_flag++; - Settings.cfg_size = sizeof(SYSCFG); - Settings.cfg_crc = GetSettingsCrc(); -#ifdef USE_EEPROM - if (SPIFFS_END == settings_location) { - uint8_t* flash_buffer; - flash_buffer = new uint8_t[SPI_FLASH_SEC_SIZE]; - if (eeprom_data && eeprom_size) { - size_t flash_offset = SPI_FLASH_SEC_SIZE - eeprom_size; - memcpy(flash_buffer + flash_offset, eeprom_data, eeprom_size); // Write dirty EEPROM data - } else { - ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)flash_buffer, SPI_FLASH_SEC_SIZE); // Read EEPROM area - } - memcpy(flash_buffer, &Settings, sizeof(Settings)); - ESP.flashEraseSector(settings_location); - ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)flash_buffer, SPI_FLASH_SEC_SIZE); - delete[] flash_buffer; + Settings.save_flag++; + if (UtcTime() > START_VALID_TIME) { + Settings.cfg_timestamp = UtcTime(); } else { - ESP.flashEraseSector(settings_location); - ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG)); + Settings.cfg_timestamp++; } -#else + Settings.cfg_size = sizeof(SYSCFG); + Settings.cfg_crc = GetSettingsCrc(); // Keep for backward compatibility in case of fall-back just after upgrade + Settings.cfg_crc32 = GetSettingsCrc32(); + ESP.flashEraseSector(settings_location); ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG)); -#endif // USE_EEPROM if (!stop_flash_rotate && rotate) { for (uint32_t i = 1; i < CFG_ROTATES; i++) { @@ -417,7 +424,7 @@ void SettingsSave(uint8_t rotate) AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"), settings_location, Settings.save_flag, sizeof(SYSCFG)); - settings_crc = Settings.cfg_crc; + settings_crc32 = Settings.cfg_crc32; } #endif // FIRMWARE_MINIMAL RtcSettingsSave(); @@ -442,7 +449,10 @@ void SettingsLoad(void) bool valid = false; if (Settings.version > 0x06000000) { - bool almost_valid = (Settings.cfg_crc == GetSettingsCrc()); + bool almost_valid = (Settings.cfg_crc32 == GetSettingsCrc32()); + if (Settings.version < 0x0606000B) { + almost_valid = (Settings.cfg_crc == GetSettingsCrc()); + } // Sometimes CRC on pages below FB, overwritten by OTA, is fine but Settings are still invalid. So check cfg_holder too if (almost_valid && (0 == cfg_holder)) { cfg_holder = Settings.cfg_holder; } // At FB always active cfg_holder valid = (cfg_holder == Settings.cfg_holder); @@ -471,7 +481,7 @@ void SettingsLoad(void) if (!settings_location || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h SettingsDefault(); } - settings_crc = GetSettingsCrc(); + settings_crc32 = GetSettingsCrc32(); #endif // FIRMWARE_MINIMAL RtcSettingsLoad(); @@ -1096,6 +1106,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.ex_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 818a42408..e773bf7a7 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 @@ -129,6 +130,8 @@ const uint32_t SERIAL_POLLING = 100; // Serial receive polling in ms const uint32_t ZIGBEE_POLLING = 100; // Serial receive polling in ms const uint8_t MAX_STATUS = 11; // Max number of status lines +const uint32_t START_VALID_TIME = 1451602800; // Time is synced and after 2016-01-01 + const uint32_t DRIVER_BOOT_DELAY = 1; // Number of milliseconds to retard driver cycles during boot-up time to reduce overall CPU load whilst Wifi is connecting const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to go through the main loop using delay when needed @@ -172,6 +175,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 +233,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 +245,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 @@ -249,12 +263,12 @@ enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT enum LightSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT, - FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, + FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_300_MSECOND, FUNC_EVERY_SECOND, FUNC_SAVE_AT_MIDNIGHT, FUNC_SAVE_BEFORE_RESTART, 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 922bd18d5..6a60ff49e 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 @@ -122,8 +120,6 @@ int16_t save_data_counter; // Counter and flag for config save RulesBitfield rules_flag; // Rule state flags (16 bits) uint8_t state_250mS = 0; // State 250msecond per second flag uint8_t latching_relay_pulse = 0; // Latching relay pulse timer -uint8_t backlog_index = 0; // Command backlog index -uint8_t backlog_pointer = 0; // Command backlog pointer uint8_t sleep; // Current copy of Settings.sleep uint8_t blinkspeed = 1; // LED blink rate uint8_t pin[GPIO_MAX]; // Possible pin configurations @@ -168,14 +164,23 @@ char serial_in_buffer[INPUT_BUFFER_SIZE]; // Receive buffer char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer char log_data[LOGSZ]; // Logging char web_log[WEB_LOG_SIZE] = {'\0'}; // Web log buffer -String backlog[MAX_BACKLOG]; // Command backlog +#ifdef SUPPORT_IF_STATEMENT + #include + LinkedList backlog; // Command backlog implemented with LinkedList + #define BACKLOG_EMPTY (backlog.size() == 0) +#else + uint8_t backlog_index = 0; // Command backlog index + uint8_t backlog_pointer = 0; // Command backlog pointer + String backlog[MAX_BACKLOG]; // Command backlog buffer + #define BACKLOG_EMPTY (backlog_pointer == backlog_index) +#endif /********************************************************************************************/ 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 +209,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 +229,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 +268,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 +303,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 +322,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 +337,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 +362,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 +371,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 ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present - if (pin[GPIO_LED2] < 99) { led = 1; } + 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 (pin[GPIO_LED1 + led] < 99) { - uint8_t mask = 1 << led; + uint32_t mask = 1 << led; if (state) { state = 1; led_power |= mask; @@ -373,13 +434,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 +448,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 +469,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 +504,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 +535,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 +560,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 +615,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 +634,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 +661,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 +742,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()); @@ -804,12 +869,16 @@ void Every100mSeconds(void) // Backlog if (TimeReached(backlog_delay)) { - if ((backlog_pointer != backlog_index) && !backlog_mutex) { + if (!BACKLOG_EMPTY && !backlog_mutex) { backlog_mutex = true; +#ifdef SUPPORT_IF_STATEMENT + ExecuteCommand((char*)backlog.shift().c_str(), SRC_BACKLOG); +#else ExecuteCommand((char*)backlog[backlog_pointer].c_str(), SRC_BACKLOG); - backlog_mutex = false; backlog_pointer++; if (backlog_pointer >= MAX_BACKLOG) { backlog_pointer = 0; } +#endif + backlog_mutex = false; } } } @@ -822,7 +891,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; @@ -870,7 +939,7 @@ void Every250mSeconds(void) case 0: // Every x.0 second PerformEverySecond(); - if (ota_state_flag && (backlog_pointer == backlog_index)) { + if (ota_state_flag && BACKLOG_EMPTY) { ota_state_flag--; if (2 == ota_state_flag) { ota_url = Settings.ota_url; @@ -941,7 +1010,7 @@ void Every250mSeconds(void) if (MidnightNow()) { XsnsCall(FUNC_SAVE_AT_MIDNIGHT); } - if (save_data_counter && (backlog_pointer == backlog_index)) { + if (save_data_counter && BACKLOG_EMPTY) { save_data_counter--; if (save_data_counter <= 0) { if (Settings.flag.save_state) { @@ -961,7 +1030,7 @@ void Every250mSeconds(void) save_data_counter = Settings.save_data; } } - if (restart_flag && (backlog_pointer == backlog_index)) { + if (restart_flag && BACKLOG_EMPTY) { if ((214 == restart_flag) || (215 == restart_flag) || (216 == restart_flag)) { char storage_wifi[sizeof(Settings.sta_ssid) + sizeof(Settings.sta_pwd)]; @@ -1176,7 +1245,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 +1257,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 +1297,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 +1671,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 01076e035..bf4f57c3e 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 @@ -108,6 +108,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code) //#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code) #define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code) +//#define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code) #define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code) #define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code) #define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code) @@ -217,7 +218,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 +243,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 @@ -256,6 +258,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #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 USE_A4988_Stepper // Disable support for A4988_Stepper #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code #endif // FIRMWARE_CLASSIC @@ -317,6 +320,82 @@ 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 USE_A4988_Stepper // Disable support for A4988_Stepper +#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 +439,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 +470,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 @@ -403,6 +483,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #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 USE_A4988_Stepper // Disable support for A4988_Stepper #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code #endif // FIRMWARE_BASIC @@ -440,7 +521,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 +550,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 @@ -483,6 +565,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #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 USE_A4988_Stepper // Disable support for A4988_Stepper #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code #endif // FIRMWARE_MINIMAL diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 402ca22a2..aa0dfbe9a 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -194,6 +194,12 @@ enum UserSelectablePins { GPIO_RDM6300_RX, // RDM6300 RX GPIO_IBEACON_TX, // HM17 IBEACON TX GPIO_IBEACON_RX, // HM17 IBEACON RX + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 GPIO_SENSOR_END }; // Programmer selectable GPIO functionality @@ -267,6 +273,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_ZIGBEE_TXD "|" D_SENSOR_ZIGBEE_RXD "|" D_SENSOR_RDM6300_RX "|" D_SENSOR_IBEACON_TX "|" D_SENSOR_IBEACON_RX "|" + D_SENSOR_A4988_DIR "|" D_SENSOR_A4988_STP "|" D_SENSOR_A4988_ENA "|" D_SENSOR_A4988_MS1 "|" D_SENSOR_A4988_MS2 "|" D_SENSOR_A4988_MS3 "|" ; // User selectable ADC0 functionality @@ -524,15 +531,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_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 #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 +581,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 +613,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 +662,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,32 +686,24 @@ 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 +#ifdef USE_A4988_Stepper + GPIO_A4988_DIR, // A4988 direction pin + GPIO_A4988_STP, // A4988 step pin + // folowing are not mandatory + GPIO_A4988_ENA, // A4988 enabled pin + GPIO_A4988_MS1, // A4988 microstep pin1 + GPIO_A4988_MS2, // A4988 microstep pin2 + GPIO_A4988_MS3, // A4988 microstep pin3 #endif }; @@ -734,7 +765,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 +1744,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 e614fbf36..b7eae8a8f 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 = 0x0606000B; #endif // _SONOFF_VERSION_H_ diff --git a/sonoff/support.ino b/sonoff/support.ino index 4ada71ad2..b9fec8651 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -124,6 +124,18 @@ size_t strcspn(const char *str1, const char *str2) return ret; } +// https://clc-wiki.net/wiki/C_standard_library:string.h:strpbrk +// Locate the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2 +char* strpbrk(const char *s1, const char *s2) +{ + while(*s1) { + if (strchr(s2, *s1++)) { + return (char*)--s1; + } + } + return 0; +} + // https://opensource.apple.com/source/Libc/Libc-583/stdlib/FreeBSD/strtoull.c // Convert a string to an unsigned long long integer #ifndef __LONG_LONG_MAX__ @@ -870,7 +882,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\",\"Epoch\":%u"), GetDateAndTime(DT_LOCAL).c_str(), UtcTime()); + 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\""), GetDateAndTime(DT_LOCAL).c_str()); + } + 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 +909,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 +934,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 c32011b42..5c8db5d09 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 6c2dc78a8..c181a70bf 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -215,10 +215,17 @@ void CommandHandler(char* topic, uint8_t* data, uint32_t data_len) void CmndBacklog(void) { if (XdrvMailbox.data_len) { + +#ifdef SUPPORT_IF_STATEMENT + char *blcommand = strtok(XdrvMailbox.data, ";"); + while ((blcommand != nullptr) && (backlog.size() < MAX_BACKLOG)) +#else uint32_t bl_pointer = (!backlog_pointer) ? MAX_BACKLOG -1 : backlog_pointer; bl_pointer--; char *blcommand = strtok(XdrvMailbox.data, ";"); - while ((blcommand != nullptr) && (backlog_index != bl_pointer)) { + while ((blcommand != nullptr) && (backlog_index != bl_pointer)) +#endif + { while(true) { blcommand = Trim(blcommand); if (!strncasecmp_P(blcommand, PSTR(D_CMND_BACKLOG), strlen(D_CMND_BACKLOG))) { @@ -228,17 +235,27 @@ void CmndBacklog(void) } } if (*blcommand != '\0') { +#ifdef SUPPORT_IF_STATEMENT + if (backlog.size() < MAX_BACKLOG) { + backlog.add(blcommand); + } +#else backlog[backlog_index] = String(blcommand); backlog_index++; if (backlog_index >= MAX_BACKLOG) backlog_index = 0; +#endif } blcommand = strtok(nullptr, ";"); } // ResponseCmndChar(D_JSON_APPENDED); mqtt_data[0] = '\0'; } else { - bool blflag = (backlog_pointer == backlog_index); + bool blflag = BACKLOG_EMPTY; +#ifdef SUPPORT_IF_STATEMENT + backlog.clear(); +#else backlog_pointer = backlog_index; +#endif ResponseCmndChar(blflag ? D_JSON_EMPTY : D_JSON_ABORTED); } } @@ -257,11 +274,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) @@ -607,26 +633,23 @@ void CmndSetoption(void) #endif // USE_HOME_ASSISTANT } } - else if (1 == ptype) { // SetOption50 .. 81 + else if (1 == ptype) { // SetOption50 .. 81 if (XdrvMailbox.payload <= 1) { bitWrite(Settings.flag3.data, pindex, XdrvMailbox.payload); - if (5 == pindex) { // SetOption55 + if (5 == pindex) { // SetOption55 if (0 == XdrvMailbox.payload) { restart_flag = 2; // Disable mDNS needs restart } } - if (10 == pindex) { // SetOption60 enable or disable traditional sleep + if (10 == pindex) { // SetOption60 enable or disable traditional sleep WiFiSetSleepMode(); // Update WiFi sleep mode accordingly } - if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot - restart_flag = 2; - } - if (15 == pindex) { // SetOption65 for tuya_disable_dimmer requires a reboot + if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot restart_flag = 2; } } } - else { // SetOption32 .. 49 + else { // SetOption32 .. 49 uint32_t param_low = 0; uint32_t param_high = 255; switch (pindex) { @@ -635,9 +658,6 @@ void CmndSetoption(void) param_low = 1; param_high = 250; break; - case P_TUYA_RELAYS: - param_high = 8; - break; } if ((XdrvMailbox.payload >= param_low) && (XdrvMailbox.payload <= param_high)) { Settings.param[pindex] = XdrvMailbox.payload; @@ -652,11 +672,7 @@ void CmndSetoption(void) 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_TUYA_DIMMER_MAX: restart_flag = 2; // Need a restart to update GUI break; @@ -1260,6 +1276,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 +1287,25 @@ void CmndReset(void) void CmndTime(void) { +// payload 0 = (re-)enable NTP +// payload 1 = Time format {"Time":"2019-09-04T14:31:29"} +// payload 2 = Time format {"Time":"2019-09-04T14:31:29","Epoch":1567600289} +// 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 = 1; // {"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 42144d191..9f36d3349 100644 --- a/sonoff/support_features.ino +++ b/sonoff/support_features.ino @@ -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 @@ -438,10 +438,15 @@ void GetFeatures(void) #ifdef USE_IBEACON feature5 |= 0x00000004; // xsns_52_ibeacon.ino #endif -// feature5 |= 0x00000008; - -// feature5 |= 0x00000010; -// feature5 |= 0x00000020; +#ifdef USE_SML_M + feature5 |= 0x00000008; // xsns_53_sml.ino +#endif +#ifdef USE_INA226 + feature5 |= 0x00000010; // xsns_54_ina226.ino +#endif +#ifdef USE_A4988_Stepper + feature5 |= 0x00000020; // xdrv_25_A4988.ino +#endif // feature5 |= 0x00000040; // feature5 |= 0x00000080; diff --git a/sonoff/support_static_buffer.ino b/sonoff/support_static_buffer.ino new file mode 100644 index 000000000..d2817753b --- /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 40bbcc2b9..940fcdb1d 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 b7541910e..606e40616 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,10 @@ 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) { @@ -1683,8 +1687,8 @@ void HandleBackupConfiguration(void) WSSend(200, CT_STREAM, ""); - uint16_t cfg_crc = Settings.cfg_crc; - Settings.cfg_crc = GetSettingsCrc(); // Calculate crc (again) as it might be wrong when savedata = 0 (#3918) + uint32_t cfg_crc32 = Settings.cfg_crc32; + Settings.cfg_crc32 = GetSettingsCrc32(); // Calculate crc (again) as it might be wrong when savedata = 0 (#3918) memcpy(settings_buffer, &Settings, sizeof(Settings)); if (Web.config_xor_on_set) { @@ -1704,7 +1708,7 @@ void HandleBackupConfiguration(void) SettingsBufferFree(); - Settings.cfg_crc = cfg_crc; // Restore crc in case savedata = 0 to make sure settings will be noted as changed + Settings.cfg_crc32 = cfg_crc32; // Restore crc in case savedata = 0 to make sure settings will be noted as changed } /*-------------------------------------------------------------------------------------------*/ @@ -2089,12 +2093,13 @@ void HandleUploadLoop(void) unsigned long buffer_version = settings_buffer[11] << 24 | settings_buffer[10] << 16 | settings_buffer[9] << 8 | settings_buffer[8]; if (buffer_version > 0x06000000) { uint32_t buffer_size = settings_buffer[3] << 8 | settings_buffer[2]; - uint16_t buffer_crc = settings_buffer[15] << 8 | settings_buffer[14]; - uint16_t crc = 0; - for (uint32_t i = 0; i < buffer_size; i++) { - if ((i < 14) || (i > 15)) { crc += settings_buffer[i]*(i+1); } // Skip crc + if (buffer_version > 0x0606000A) { + uint32_t buffer_crc32 = settings_buffer[4095] << 24 | settings_buffer[4094] << 16 | settings_buffer[4093] << 8 | settings_buffer[4092]; + valid_settings = (GetCfgCrc32(settings_buffer, buffer_size -4) == buffer_crc32); + } else { + uint16_t buffer_crc16 = settings_buffer[15] << 8 | settings_buffer[14]; + valid_settings = (GetCfgCrc16(settings_buffer, buffer_size) == buffer_crc16); } - valid_settings = (buffer_crc == crc); } else { valid_settings = (settings_buffer[0] == CONFIG_FILE_SIGN); } @@ -2347,6 +2352,151 @@ String UrlEncode(const String& text) return encoded; } +#ifdef USE_SENDMAIL + +#include "sendemail.h" + +//SendEmail(const String& host, const int port, const String& user, const String& passwd, const int timeout, const bool ssl); +//SendEmail::send(const String& from, const String& to, const String& subject, const String& msg) +// sendmail [server:port:user:passwd:from:to:subject] data +// sendmail [*:*:*:*:*:to:subject] data uses defines from user_config +// sendmail currently only works with core 2.4.2 + +#define SEND_MAIL_MINRAM 19*1024 + +uint16_t SendMail(char *buffer) { + uint16_t count; + char *params,*oparams; + char *mserv; + uint16_t port; + char *user; + char *pstr; + char *passwd; + char *from; + char *to; + char *subject; + char *cmd; + char secure=0,auth=0; + uint16_t status=1; + SendEmail *mail=0; + + //DebugFreeMem(); + +// return if not enough memory + uint16_t mem=ESP.getFreeHeap(); + if (mem AUTH LOGIN 1 => PLAIN LOGIN + // 2 seconds timeout + #define MAIL_TIMEOUT 2000 + mail = new SendEmail(mserv, port,user,passwd, MAIL_TIMEOUT, auth); + +#ifdef EMAIL_FROM + if (*from=='*') { + from=(char*)EMAIL_FROM; + } +#endif + +exit: + if (mail) { + bool result=mail->send(from,to,subject,cmd); + delete mail; + if (result==true) status=0; + } + + + if (oparams) free(oparams); + return status; +} + +#endif + int WebSend(char *buffer) { // [sonoff] POWER1 ON --> Sends http://sonoff/cm?cmnd=POWER1 ON @@ -2459,17 +2609,23 @@ bool JsonWebColor(const char* dataBuf) return true; } -const char kWebSendStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|" D_JSON_CONNECT_FAILED "|" D_JSON_HOST_NOT_FOUND ; +const char kWebSendStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|" D_JSON_CONNECT_FAILED "|" D_JSON_HOST_NOT_FOUND "|" D_JSON_MEMORY_ERROR; const char kWebCommands[] PROGMEM = "|" // No prefix #ifdef USE_EMULATION D_CMND_EMULATION "|" +#endif +#ifdef USE_SENDMAIL + D_CMND_SENDMAIL "|" #endif D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" D_CMND_WEBSENSOR; void (* const WebCommand[])(void) PROGMEM = { #ifdef USE_EMULATION &CmndEmulation, +#endif +#ifdef USE_SENDMAIL + &CmndSendmail, #endif &CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, &CmndWebSensor }; @@ -2497,6 +2653,18 @@ void CmndEmulation(void) } #endif // USE_EMULATION +#ifdef USE_SENDMAIL +void CmndSendmail(void) +{ + if (XdrvMailbox.data_len > 0) { + uint8_t result = SendMail(XdrvMailbox.data); + char stemp1[20]; + ResponseCmndChar(GetTextIndexed(stemp1, sizeof(stemp1), result, kWebSendStatus)); + } +} +#endif // USE_SENDMAIL + + void CmndWebServer(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index 10e3eca9c..8de1a3d1e 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 bf8e9afdc..007aa871f 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -76,15 +76,17 @@ 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 float total = 0; // 12345.12345 kWh tariff 1 + 2 float total1 = 0; // 12345.12345 kWh tariff 1 - off-peak + float export_active = NAN; // 123.123 KWh - unsigned long kWhtoday_delta = 0; // 1212312345 Wh 10^-5 (deca micro Watt hours) - Overflows to Energy.kWhtoday (HLW and CSE only) + unsigned long kWhtoday_delta = 0; // 1212312345 Wh 10^-5 (deca micro Watt hours) - Overflows to Energy.kWhtoday (HLW and CSE only) + unsigned long kWhtoday_offset = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily unsigned long kWhtoday; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily - unsigned long kWhtoday1; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily unsigned long period = 0; // 12312312 Wh * 10^-2 (deca milli Watt hours) - 5764 = 0.05764 kWh = 0.058 kWh = Energy.daily uint8_t fifth_second = 0; @@ -114,7 +116,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; @@ -129,23 +130,49 @@ void EnergyUpdateToday(void) Energy.kWhtoday_delta -= (delta * 1000); Energy.kWhtoday += delta; } - uint32_t energy_diff = Energy.kWhtoday - RtcSettings.energy_kWhtoday; - RtcSettings.energy_kWhtoday = Energy.kWhtoday; - Energy.daily = (float)Energy.kWhtoday / 100000; - Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday) / 100000; + uint32_t energy_diff = Energy.kWhtoday_offset + Energy.kWhtoday - RtcSettings.energy_kWhtoday; + + uint32_t return_diff = 0; + if (!isnan(Energy.export_active)) { + return_diff = (uint32_t)(Energy.export_active * 1000) - RtcSettings.energy_usage.last_return_kWhtotal; + RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(Energy.export_active * 1000); + } + + RtcSettings.energy_kWhtoday = Energy.kWhtoday_offset + Energy.kWhtoday; + Energy.daily = (float)(RtcSettings.energy_kWhtoday) / 100000; + Energy.total = (float)(RtcSettings.energy_kWhtotal + RtcSettings.energy_kWhtoday) / 100000; if ((RtcTime.hour < Settings.param[P_ENERGY_TARIFF2]) || // Tarrif1 = Off-Peak (RtcTime.hour >= Settings.param[P_ENERGY_TARIFF1]) || (Settings.flag3.energy_weekend && ((RtcTime.day_of_week == 1) || (RtcTime.day_of_week == 7))) ) { - Energy.kWhtoday1 += energy_diff; - RtcSettings.energy_usage.usage1_kWhtoday = Energy.kWhtoday1; - Energy.total1 = (float)(RtcSettings.energy_usage.usage1_kWhtotal + Energy.kWhtoday1) / 100000; + RtcSettings.energy_usage.usage1_kWhtoday += energy_diff; + RtcSettings.energy_usage.return1_kWhtotal += return_diff; + Energy.total1 = (float)(RtcSettings.energy_usage.usage1_kWhtotal + RtcSettings.energy_usage.usage1_kWhtoday) / 100000; + } else { + RtcSettings.energy_usage.return2_kWhtotal += return_diff; } } +void EnergyUpdateTotal(float value, bool kwh) +{ +// char energy_total_chr[FLOATSZ]; +// dtostrfd(value, 4, energy_total_chr); +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total %s %sWh"), energy_total_chr, (kwh) ? "k" : ""); + + 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 + } + else if (value != Energy.start_energy) { + Energy.kWhtoday = (unsigned long)((value - Energy.start_energy) * multiplier); + } + EnergyUpdateToday(); +} + /*********************************************************************************************/ void Energy200ms(void) @@ -160,16 +187,17 @@ void Energy200ms(void) if (RtcTime.valid) { if (LocalTime() == Midnight()) { - Settings.energy_kWhyesterday = Energy.kWhtoday; + Settings.energy_kWhyesterday = RtcSettings.energy_kWhtoday; - Settings.energy_kWhtotal += Energy.kWhtoday; - RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal; + RtcSettings.energy_kWhtotal += RtcSettings.energy_kWhtoday; + Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal; Energy.kWhtoday = 0; + Energy.kWhtoday_offset = 0; RtcSettings.energy_kWhtoday = 0; + Energy.start_energy = 0; - Settings.energy_usage.usage1_kWhtotal += Energy.kWhtoday1; - RtcSettings.energy_usage.usage1_kWhtotal = Settings.energy_usage.usage1_kWhtotal; - Energy.kWhtoday1 = 0; + RtcSettings.energy_usage.usage1_kWhtotal += RtcSettings.energy_usage.usage1_kWhtoday; + Settings.energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal; RtcSettings.energy_usage.usage1_kWhtoday = 0; Energy.kWhtoday_delta = 0; @@ -195,13 +223,10 @@ void EnergySaveState(void) { Settings.energy_kWhdoy = (RtcTime.valid) ? RtcTime.day_of_year : 0; - Settings.energy_kWhtoday = Energy.kWhtoday; - RtcSettings.energy_kWhtoday = Energy.kWhtoday; + Settings.energy_kWhtoday = RtcSettings.energy_kWhtoday; Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal; - Settings.energy_usage.usage1_kWhtoday = Energy.kWhtoday1; - RtcSettings.energy_usage.usage1_kWhtoday = Energy.kWhtoday1; - Settings.energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal; + Settings.energy_usage = RtcSettings.energy_usage; } #ifdef USE_ENERGY_MARGIN_DETECTION @@ -297,10 +322,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 +345,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 +363,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 +384,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 +410,14 @@ 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; + if (!isnan(Energy.export_active)) { Energy.export_active = 0; } + + XnrgCall(FUNC_ENERGY_RESET); } } } @@ -418,28 +449,34 @@ void CmndEnergyReset(void) if (p != XdrvMailbox.data) { switch (XdrvMailbox.index) { case 1: - Energy.kWhtoday = lnum *100; + // Reset Energy Today + Energy.kWhtoday_offset = lnum *100; + Energy.kWhtoday = 0; Energy.kWhtoday_delta = 0; - Energy.period = Energy.kWhtoday; - 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(); } + Energy.period = Energy.kWhtoday_offset; + Settings.energy_kWhtoday = Energy.kWhtoday_offset; + RtcSettings.energy_kWhtoday = Energy.kWhtoday_offset; + Energy.daily = (float)Energy.kWhtoday_offset / 100000; + if (!RtcSettings.energy_kWhtotal && !Energy.kWhtoday_offset) { + Settings.energy_kWhtotal_time = LocalTime(); + } break; case 2: + // Reset Energy Yesterday Settings.energy_kWhyesterday = lnum *100; break; case 3: + // Reset Energy Total RtcSettings.energy_kWhtotal = lnum *100; Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal; - Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday) / 100000; - Settings.energy_kWhtotal_time = (!Energy.kWhtoday) ? LocalTime() : Midnight(); + Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000; + Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight(); break; } } - if (Energy.kWhtoday1 > Energy.kWhtoday) { - Energy.kWhtoday1 = Energy.kWhtoday; + if (RtcSettings.energy_usage.usage1_kWhtoday > (Energy.kWhtoday_offset + Energy.kWhtoday)) { + RtcSettings.energy_usage.usage1_kWhtoday = Energy.kWhtoday_offset + Energy.kWhtoday; } if (Settings.energy_usage.usage1_kWhtoday > Settings.energy_kWhtoday) { Settings.energy_usage.usage1_kWhtoday = Settings.energy_kWhtoday; @@ -450,11 +487,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}}"), @@ -672,7 +709,7 @@ void CmndMaxEnergyStart(void) void EnergyDrvInit(void) { energy_flg = ENERGY_NONE; - XnrgCall(FUNC_PRE_INIT); + XnrgCall(FUNC_PRE_INIT); // Find first energy driver } void EnergySnsInit(void) @@ -680,10 +717,20 @@ void EnergySnsInit(void) XnrgCall(FUNC_INIT); if (energy_flg) { - Energy.kWhtoday = (RtcSettingsValid()) ? RtcSettings.energy_kWhtoday : (RtcTime.day_of_year == Settings.energy_kWhdoy) ? Settings.energy_kWhtoday : 0; - Energy.kWhtoday1 = (RtcSettingsValid()) ? RtcSettings.energy_usage.usage1_kWhtoday : (RtcTime.day_of_year == Settings.energy_kWhdoy) ? Settings.energy_usage.usage1_kWhtoday : 0; + if (RtcSettingsValid()) { + Energy.kWhtoday_offset = RtcSettings.energy_kWhtoday; + } + else if (RtcTime.day_of_year == Settings.energy_kWhdoy) { + Energy.kWhtoday_offset = Settings.energy_kWhtoday; + RtcSettings.energy_usage.usage1_kWhtoday = Settings.energy_usage.usage1_kWhtoday; + } + else { + Energy.kWhtoday_offset = 0; + RtcSettings.energy_usage.usage1_kWhtoday = 0; + } + Energy.kWhtoday = 0; Energy.kWhtoday_delta = 0; - Energy.period = Energy.kWhtoday; + Energy.period = Energy.kWhtoday_offset; EnergyUpdateToday(); ticker_energy.attach_ms(200, Energy200ms); } @@ -696,24 +743,22 @@ 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} = + +const char HTTP_ENERGY_SNS3[] PROGMEM = + "{s}" D_EXPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; #endif // USE_WEBSERVER 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,31 +794,40 @@ 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]; - if (show_energy_period) { - if (Energy.period) energy = (float)(Energy.kWhtoday - Energy.period) / 100; - Energy.period = Energy.kWhtoday; - dtostrfd(energy, Settings.flag2.wattage_resolution, energy_period_chr); - snprintf_P(speriod, sizeof(speriod), PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr); - } + char export_active_chr[FLOATSZ]; + dtostrfd(Energy.export_active, Settings.flag2.energy_resolution, export_active_chr); if (json) { - ResponseAppend_P(PSTR(",\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL_START_TIME "\":\"%s\",\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s%s,\"" D_JSON_POWERUSAGE "\":%s"), - GetDateAndTime(DT_ENERGY).c_str(), energy_total_chr, energy_yesterday_chr, energy_daily_chr, (show_energy_period) ? speriod : "", active_power_chr); + bool show_energy_period = (0 == tele_period); + + ResponseAppend_P(PSTR(",\"" D_RSLT_ENERGY "\":{\"" D_JSON_TOTAL_START_TIME "\":\"%s\",\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s"), + GetDateAndTime(DT_ENERGY).c_str(), energy_total_chr, energy_yesterday_chr, energy_daily_chr); + if (!isnan(Energy.export_active)) { + ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_ACTIVE "\":%s"), export_active_chr); + } + if (show_energy_period) { + float energy = 0; + if (Energy.period) { + energy = (float)(RtcSettings.energy_kWhtoday - Energy.period) / 100; + } + Energy.period = RtcSettings.energy_kWhtoday; + char energy_period_chr[FLOATSZ]; + dtostrfd(energy, Settings.flag2.wattage_resolution, energy_period_chr); + ResponseAppend_P(PSTR(",\"" D_JSON_PERIOD "\":%s"), energy_period_chr); + } + ResponseAppend_P(PSTR(",\"" D_JSON_POWERUSAGE "\":%s"), active_power_chr); if (!Energy.type_dc) { if (Energy.current_available && Energy.voltage_available) { ResponseAppend_P(PSTR(",\"" D_JSON_APPARENT_POWERUSAGE "\":%s,\"" D_JSON_REACTIVE_POWERUSAGE "\":%s,\"" D_JSON_POWERFACTOR "\":%s"), @@ -789,6 +843,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,10 +852,13 @@ 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); + char return1_total_chr[FLOATSZ]; + dtostrfd(RtcSettings.energy_usage.return1_kWhtotal, 1, return1_total_chr); + char return2_total_chr[FLOATSZ]; + dtostrfd(RtcSettings.energy_usage.return2_kWhtotal, 1, return2_total_chr); + DomoticzSensorP1SmartMeter(energy_total1_chr, energy_total_chr, return1_total_chr, return2_total_chr, (int)Energy.active_power); if (Energy.voltage_available) { DomoticzSensor(DZ_VOLTAGE, voltage_chr); // Voltage @@ -843,6 +901,11 @@ void EnergyShow(bool json) } } WSContentSend_PD(HTTP_ENERGY_SNS2, energy_daily_chr, energy_yesterday_chr, energy_total_chr); + if (!isnan(Energy.export_active)) { + WSContentSend_PD(HTTP_ENERGY_SNS3, export_active_chr); + } + + XnrgCall(FUNC_WEB_SENSOR); #endif // USE_WEBSERVER } } @@ -863,14 +926,17 @@ bool Xdrv03(uint8_t function) case FUNC_LOOP: XnrgCall(FUNC_LOOP); break; + case FUNC_EVERY_250_MSECOND: + XnrgCall(FUNC_EVERY_250_MSECOND); + break; + case FUNC_SERIAL: + result = XnrgCall(FUNC_SERIAL); + break; #ifdef USE_ENERGY_MARGIN_DETECTION case FUNC_SET_POWER: Energy.power_steady_counter = 2; break; #endif // USE_ENERGY_MARGIN_DETECTION - case FUNC_SERIAL: - result = XnrgCall(FUNC_SERIAL); - break; case FUNC_COMMAND: result = DecodeCommand(kEnergyCommands, EnergyCommand); break; @@ -885,9 +951,6 @@ bool Xsns03(uint8_t function) if (energy_flg) { switch (function) { - case FUNC_INIT: - EnergySnsInit(); - break; case FUNC_EVERY_SECOND: #ifdef USE_ENERGY_MARGIN_DETECTION EnergyMarginCheck(); @@ -905,6 +968,9 @@ bool Xsns03(uint8_t function) case FUNC_SAVE_BEFORE_RESTART: EnergySaveState(); break; + case FUNC_INIT: + EnergySnsInit(); + break; } } return result; diff --git a/sonoff/xdrv_05_irremote.ino b/sonoff/xdrv_05_irremote.ino index 59b152a32..cc0614264 100644 --- a/sonoff/xdrv_05_irremote.ino +++ b/sonoff/xdrv_05_irremote.ino @@ -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) { diff --git a/sonoff/xdrv_05_irremote_full.ino b/sonoff/xdrv_05_irremote_full.ino index 48dfa1498..3c82bee21 100644 --- a/sonoff/xdrv_05_irremote_full.ino +++ b/sonoff/xdrv_05_irremote_full.ino @@ -27,7 +27,7 @@ #include #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, @@ -220,7 +220,7 @@ void IrReceiveCheck(void) // 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; - Response_P(PSTR("{\"" D_JSON_IRRECEIVED "\":%s"), sendIRJsonState(results).c_str()); + ResponseTime_P(PSTR(",\"" D_JSON_IRRECEIVED "\":%s"), sendIRJsonState(results).c_str()); if (Settings.flag3.receive_raw) { ResponseAppend_P(PSTR(",\"" D_JSON_IR_RAWDATA "\":[")); diff --git a/sonoff/xdrv_06_snfbridge.ino b/sonoff/xdrv_06_snfbridge.ino index c7b57c0c1..67ca582fb 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 e5bd2705f..a65c82851 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; } @@ -383,14 +383,19 @@ void DomoticzSensorPowerEnergy(int power, char *energy) DomoticzSensor(DZ_POWER_ENERGY, data); } -void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char *return2, int consumed, int produced) +void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char *return2, int power) { //usage1 = energy usage meter tariff 1, This is an incrementing counter //usage2 = energy usage meter tariff 2, This is an incrementing counter //return1 = energy return meter tariff 1, This is an incrementing counter //return2 = energy return meter tariff 2, This is an incrementing counter - //consumed = actual usage power (Watt) - //produced = actual return power (Watt) + //power = if >= 0 actual usage power. if < 0 actual return power (Watt) + int consumed = power; + int produced = 0; + if (power < 0) { + consumed = 0; + produced = -power; + } char data[64]; snprintf_P(data, sizeof(data), PSTR("%s;%s;%s;%s;%d;%d"), usage1, usage2, return1, return2, consumed, produced); DomoticzSensor(DZ_P1_SMART_METER, data); diff --git a/sonoff/xdrv_08_serial_bridge.ino b/sonoff/xdrv_08_serial_bridge.ino index 98bb6a830..8a0543858 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 674cbfb9b..4b767e77c 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 fd1db9426..26bdbcb86 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -78,6 +78,7 @@ #define D_CMND_CALC_RESOLUTION "CalcRes" #define D_CMND_SUBSCRIBE "Subscribe" #define D_CMND_UNSUBSCRIBE "Unsubscribe" +#define D_CMND_IF "If" #define D_JSON_INITIATED "Initiated" @@ -106,6 +107,16 @@ const char kCompareOperators[] PROGMEM = "=\0>\0<\0|\0==!=>=<="; const uint8_t kExpressionOperatorsPriorities[] PROGMEM = {1, 1, 2, 2, 3, 4}; #define MAX_EXPRESSION_OPERATOR_PRIORITY 4 + + + #define LOGIC_OPERATOR_AND 1 + #define LOGIC_OPERATOR_OR 2 + + #define IF_BLOCK_INVALID -1 + #define IF_BLOCK_ANY 0 + #define IF_BLOCK_ELSEIF 1 + #define IF_BLOCK_ELSE 2 + #define IF_BLOCK_ENDIF 3 #endif // USE_EXPRESSION const char kRulesCommands[] PROGMEM = "|" // No prefix @@ -113,6 +124,9 @@ const char kRulesCommands[] PROGMEM = "|" // No prefix D_CMND_ADD "|" D_CMND_SUB "|" D_CMND_MULT "|" D_CMND_SCALE "|" D_CMND_CALC_RESOLUTION #ifdef SUPPORT_MQTT_EVENT "|" D_CMND_SUBSCRIBE "|" D_CMND_UNSUBSCRIBE +#endif +#ifdef SUPPORT_IF_STATEMENT + "|" D_CMND_IF #endif ; @@ -121,6 +135,9 @@ void (* const RulesCommand[])(void) PROGMEM = { &CmndAddition, &CmndSubtract, &CmndMultiply, &CmndScale, &CmndCalcResolution #ifdef SUPPORT_MQTT_EVENT , &CmndSubscribe, &CmndUnsubscribe +#endif +#ifdef SUPPORT_IF_STATEMENT + , &CmndIf #endif }; @@ -183,22 +200,13 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) rule_task = rule.substring(5, pos); // "INA219" or "SYSTEM" } - String rule_name = rule.substring(pos +1); // "CURRENT>0.100" or "BOOT" or "%var1%" or "MINUTE|5" - - char compare_operator[3]; - int8_t compare = COMPARE_OPERATOR_NONE; - for (int32_t i = MAXIMUM_COMPARE_OPERATOR; i >= 0; i--) { - snprintf_P(compare_operator, sizeof(compare_operator), kCompareOperators + (i *2)); - if ((pos = rule_name.indexOf(compare_operator)) > 0) { - compare = i; - break; - } - } + String rule_expr = rule.substring(pos +1); // "CURRENT>0.100" or "BOOT" or "%var1%" or "MINUTE|5" + String rule_name, rule_param; + int8_t compareOperator = parseCompareExpression(rule_expr, rule_name, rule_param); //Parse the compare expression.Return operator and the left, right part of expression char rule_svalue[CMDSZ] = { 0 }; float rule_value = 0; - if (compare != COMPARE_OPERATOR_NONE) { - String rule_param = rule_name.substring(pos + strlen(compare_operator)); + if (compareOperator != COMPARE_OPERATOR_NONE) { for (uint32_t i = 0; i < MAX_RULE_VARS; i++) { snprintf_P(stemp, sizeof(stemp), PSTR("%%VAR%d%%"), i +1); if (rule_param.startsWith(stemp)) { @@ -244,7 +252,6 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) } else { rule_value = CharToFloat((char*)rule_svalue); // 0.1 - This saves 9k code over toFLoat()! } - rule_name = rule_name.substring(0, pos); // "CURRENT" } // Step2: Search rule_task and rule_name @@ -268,7 +275,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) value = CharToFloat((char*)str_value); int int_value = int(value); int int_rule_value = int(rule_value); - switch (compare) { + switch (compareOperator) { case COMPARE_OPERATOR_EXACT_DIVISION: match = (int_rule_value && (int_value % int_rule_value) == 0); break; @@ -313,6 +320,40 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) return match; } +/********************************************************************************************/ +/* + * Parse a comparison expression. + * Get 3 parts - left expression, compare operator and right expression. + * Input: + * expr - A comparison expression like VAR1 >= MEM1 + 10 + * leftExpr - Used to accept returned left parts of expression + * rightExpr - Used to accept returned right parts of expression + * Output: + * leftExpr - Left parts of expression + * rightExpr - Right parts of expression + * Return: + * compare operator + * COMPARE_OPERATOR_NONE - failed + */ +int8_t parseCompareExpression(String &expr, String &leftExpr, String &rightExpr) +{ + char compare_operator[3]; + int8_t compare = COMPARE_OPERATOR_NONE; + int position; + for (int8_t i = MAXIMUM_COMPARE_OPERATOR; i >= 0; i--) { + snprintf_P(compare_operator, sizeof(compare_operator), kCompareOperators + (i *2)); + if ((position = expr.indexOf(compare_operator)) > 0) { + compare = i; + leftExpr = expr.substring(0, position); + leftExpr.trim(); + rightExpr = expr.substring(position + strlen(compare_operator)); + rightExpr.trim(); + break; + } + } + return compare; +} + /*******************************************************************************************/ bool RuleSetProcess(uint8_t rule_set, String &event_saved) @@ -389,7 +430,10 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved) // Response_P(S_JSON_COMMAND_SVALUE, D_CMND_RULE, D_JSON_INITIATED); // MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_RULE)); - +#ifdef SUPPORT_IF_STATEMENT + char *pCmd = command; + RulesPreprocessCommand(pCmd); //Do pre-process for IF statement +#endif ExecuteCommand(command, SRC_RULE); serviced = true; if (stop_all_rules) { return serviced; } // If BREAK was used, Stop execution of this rule set @@ -810,6 +854,43 @@ void CmndUnsubscribe(void) #endif // SUPPORT_MQTT_EVENT #ifdef USE_EXPRESSION +/********************************************************************************************/ +/* + * Looking for matched bracket - ")" + * Search buffer from current loction, skip all nested bracket pairs, find the matched close bracket. + * Input: + * pStart - Point to a char buffer start with "(" + * Output: + * N/A + * Return: + * position of matched close bracket + */ +char * findClosureBracket(char * pStart) +{ + char * pointer = pStart + 1; + //Look for the matched closure parenthesis.")" + bool bFindClosures = false; + uint8_t matchClosures = 1; + while (*pointer) + { + if (*pointer == ')') { + matchClosures--; + if (matchClosures == 0) { + bFindClosures = true; + break; + } + } else if (*pointer == '(') { + matchClosures++; + } + pointer++; + } + if (bFindClosures) { + return pointer; + } else { + return nullptr; + } +} + /********************************************************************************************/ /* * Parse a number value @@ -933,28 +1014,10 @@ bool findNextObjectValue(char * &pointer, float &value) bSucceed = findNextVariableValue(pointer, value); break; } else if (*pointer == '(') { //It is a sub expression bracketed with () - pointer++; - char * sub_exp_start = pointer; //Find out the sub expression between a pair of parenthesis. "()" - unsigned int sub_exp_len = 0; - //Look for the matched closure parenthesis.")" - bool bFindClosures = false; - uint8_t matchClosures = 1; - while (*pointer) - { - if (*pointer == ')') { - matchClosures--; - if (matchClosures == 0) { - sub_exp_len = pointer - sub_exp_start; - bFindClosures = true; - break; - } - } else if (*pointer == '(') { - matchClosures++; - } - pointer++; - } - if (bFindClosures) { - value = evaluateExpression(sub_exp_start, sub_exp_len); + char * closureBracket = findClosureBracket(pointer); //Get the position of closure bracket ")" + if (closureBracket != nullptr) { + value = evaluateExpression(pointer+1, closureBracket - pointer - 2); + pointer = closureBracket + 1; bSucceed = true; } break; @@ -1113,6 +1176,474 @@ float evaluateExpression(const char * expression, unsigned int len) } #endif // USE_EXPRESSION +#ifdef SUPPORT_IF_STATEMENT +void CmndIf() +{ + if (XdrvMailbox.data_len > 0) { + char parameters[XdrvMailbox.data_len+1]; + memcpy(parameters, XdrvMailbox.data, XdrvMailbox.data_len); + parameters[XdrvMailbox.data_len] = '\0'; + ProcessIfStatement(parameters); + } +} + +/********************************************************************************************/ +/* + * Evaluate a comparison expression. + * Get the logic value of expression, true or false + * Input: + * expression - A comparison expression like VAR1 >= MEM1 + 10 + * len - Length of expression + * Output: + * N/A + * Return: + * logic value of comparison expression + */ +bool evaluateComparisonExpression(const char *expression, int len) +{ + bool bResult = true; + char expbuf[len + 1]; + memcpy(expbuf, expression, len); + expbuf[len] = '\0'; + String compare_expression = expbuf; + String leftExpr, rightExpr; + int8_t compareOp = parseCompareExpression(compare_expression, leftExpr, rightExpr); + + double leftValue = evaluateExpression(leftExpr.c_str(), leftExpr.length()); + double rightValue = evaluateExpression(rightExpr.c_str(), rightExpr.length()); + switch (compareOp) { + case COMPARE_OPERATOR_EXACT_DIVISION: + bResult = (rightValue != 0 && leftValue == int(leftValue) + && rightValue == int(rightValue) && (int(leftValue) % int(rightValue)) == 0); + break; + case COMPARE_OPERATOR_EQUAL: + bResult = leftExpr.equalsIgnoreCase(rightExpr); // Compare strings - this also works for hexadecimals + break; + case COMPARE_OPERATOR_BIGGER: + bResult = (leftValue > rightValue); + break; + case COMPARE_OPERATOR_SMALLER: + bResult = (leftValue < rightValue); + break; + case COMPARE_OPERATOR_NUMBER_EQUAL: + bResult = (leftValue == rightValue); + break; + case COMPARE_OPERATOR_NOT_EQUAL: + bResult = (leftValue != rightValue); + break; + case COMPARE_OPERATOR_BIGGER_EQUAL: + bResult = (leftValue >= rightValue); + break; + case COMPARE_OPERATOR_SMALLER_EQUAL: + bResult = (leftValue <= rightValue); + break; + } + return bResult; +} + +/********************************************************************************************/ +/* + * Looking for a logical operator, either "AND" or "OR" + * A logical operator is expected at this moment. If we find something else, this function will fail. + * Input: + * pointer - Point to a char buffer + * op - Used to accpet the logical operator type + * Output: + * Pointer - pointer will forward to next character after the logical operator. + * op - The logical operator type we found + * Return: + * true - succeed + * false - failed + */ +bool findNextLogicOperator(char * &pointer, int8_t &op) +{ + bool bSucceed = false; + while (*pointer && isspace(*pointer)) { + //Skip spaces + pointer++; + } + if (*pointer) { + if (strncasecmp_P(pointer, PSTR("AND "), 4) == 0) { + op = LOGIC_OPERATOR_AND; + pointer += 4; + bSucceed = true; + } else if (strncasecmp_P(pointer, PSTR("OR "), 3) == 0) { + op = LOGIC_OPERATOR_OR; + pointer += 3; + bSucceed = true; + } + } + return bSucceed; +} + +/********************************************************************************************/ +/* + * Find next logical object and get its value + * A logical object could be: + * - A comparison expression. + * - A logical expression bracketed with a pair of parenthesis. + * Input: + * pointer - A char pointer point to a start of logical object + * value - Used to accept the result value + * Output: + * pointer - Pointer forward to next character after the object + * value - boolean type, the value of the logical object. + * Return: + * true - succeed + * false - failed + */ +bool findNextLogicObjectValue(char * &pointer, bool &value) +{ + bool bSucceed = false; + while (*pointer && isspace(*pointer)) { + //Skip leading spaces + pointer++; + } + char * pExpr = pointer; + while (*pointer) { + if (isalpha(*pointer) + && (strncasecmp_P(pointer, PSTR("AND "), 4) == 0 + || strncasecmp_P(pointer, PSTR("OR "), 3) == 0)) + { //We have a logic operator, should stop + value = evaluateComparisonExpression(pExpr, pointer - pExpr); + bSucceed = true; + break; + } else if (*pointer == '(') { //It is a sub expression bracketed with () + char * closureBracket = findClosureBracket(pointer); //Get the position of closure bracket ")" + if (closureBracket != nullptr) { + value = evaluateLogicalExpression(pointer+1, closureBracket - pointer - 2); + pointer = closureBracket + 1; + bSucceed = true; + } + break; + } + pointer++; + } + if (!bSucceed && pointer > pExpr) { + //The whole buffer is an comparison expression + value = evaluateComparisonExpression(pExpr, pointer - pExpr); + bSucceed = true; + } + return bSucceed; +} + +/********************************************************************************************/ +/* + * Evaluate a logical expression + * Logic expression is constructed with multiple comparison expressions and logical + * operators between them. For example: Mem1==0 AND (time > sunrise + 60). + * Parenthesis are allowed to change the priority of logical operators. + * Input: + * expression - A logical expression + * len - Length of the expression + * Output: + * N/A + * Return: + * boolean - the value of logical expression + */ +bool evaluateLogicalExpression(const char * expression, int len) +{ + bool bResult = false; + //Make a copy first + char expbuff[len + 1]; + memcpy(expbuff, expression, len); + expbuff[len] = '\0'; + + //snprintf_P(log_data, sizeof(log_data), PSTR("EvalLogic: |%s|"), expbuff); + //AddLog(LOG_LEVEL_DEBUG); + char * pointer = expbuff; + LinkedList values; + LinkedList logicOperators; + //Find first comparison expression + bool bValue; + if (findNextLogicObjectValue(pointer, bValue)) { + values.add(bValue); + } else { + return false; + } + int8_t op; + while (*pointer) { + if (findNextLogicOperator(pointer, op) + && (*pointer) && findNextLogicObjectValue(pointer, bValue)) + { + logicOperators.add(op); + values.add(bValue); + } else { + break; + } + } + //Calculate all "AND" first + int index = 0; + while (index < logicOperators.size()) { + if (logicOperators.get(index) == LOGIC_OPERATOR_AND) { + values.set(index, values.get(index) && values.get(index+1)); + values.remove(index + 1); + logicOperators.remove(index); + } else { + index++; + } + } + //Then, calculate all "OR" + index = 0; + while (index < logicOperators.size()) { + if (logicOperators.get(index) == LOGIC_OPERATOR_OR) { + values.set(index, values.get(index) || values.get(index+1)); + values.remove(index + 1); + logicOperators.remove(index); + } else { + index++; + } + } + return values.get(0); +} + +/********************************************************************************************/ +/* + * This function search in a buffer to find out an IF block start from current position + * Note: All the tokens found during the searching will be changed to NULL terminated string. + * Please make a copy before call this function if you still need it. + * Input: + * pointer - Point to a NULL end string buffer with the commands + * lenWord - Accept the length of block end word + * block_type - The block type you are looking for. + * Output: + * pointer - pointer point to the end of if block. + * lenWord - The length of block end word ("ENDIF", "ELSEIF", "ELSE") + * Return: + * The block type we find. + * IF_BLOCK_INVALID - Failed. + */ +int8_t findIfBlock(char * &pointer, int &lenWord, int8_t block_type) +{ + int8_t foundBlock = IF_BLOCK_INVALID; + //First break into words delimited by space or ";" + const char * word; + while (*pointer) { + if (!isalpha(*pointer)) { + pointer++; + continue; + } + word = pointer; + while (*pointer && isalpha(*pointer)) { + pointer++; + } + lenWord = pointer - word; + + if (2 == lenWord && 0 == strncasecmp_P(word, PSTR("IF"), 2)) { + //if we find a new "IF" that means this is nested if block + //Try to finish this nested if block + if (findIfBlock(pointer, lenWord, IF_BLOCK_ENDIF) != IF_BLOCK_ENDIF) { + //If failed, we done. + break; + } + } else if ( (IF_BLOCK_ENDIF == block_type || IF_BLOCK_ANY == block_type) + && (5 == lenWord) && (0 == strncasecmp_P(word, PSTR("ENDIF"), 5))) + { + //Find an "ENDIF" + foundBlock = IF_BLOCK_ENDIF; + break; + } else if ( (IF_BLOCK_ELSEIF == block_type || IF_BLOCK_ANY == block_type) + && (6 == lenWord) && (0 == strncasecmp_P(word, PSTR("ELSEIF"), 6))) + { + //Find an "ELSEIF" + foundBlock = IF_BLOCK_ELSEIF; + break; + } else if ( (IF_BLOCK_ELSE == block_type || IF_BLOCK_ANY == block_type) + && (4 == lenWord) && (0 == strncasecmp_P(word, PSTR("ELSE"), 4))) + { + //Find an "ELSE" + foundBlock = IF_BLOCK_ELSE; + break; + } + } + return foundBlock; +} + +/********************************************************************************************/ +/* + * This function is used to execute a commands block in if statement when one of the condition is true. + * Input: + * commands - A char buffer include (but not limited) the commands block need to execute + * len - Length of the commands block + * Output: + N/A + * Return: + * void + */ +void ExecuteCommandBlock(const char * commands, int len) +{ + char cmdbuff[len + 1]; //apply enough space + memcpy(cmdbuff, commands, len); + cmdbuff[len] = '\0'; + + //snprintf_P(log_data, sizeof(log_data), PSTR("ExecCmd: |%s|"), cmdbuff); + //AddLog(LOG_LEVEL_DEBUG); + char oneCommand[len + 1]; //To put one command + int insertPosition = 0; //When insert into backlog, we should do it by 0, 1, 2 ... + char * pos = cmdbuff; + int lenEndBlock = 0; + while (*pos) { + if (isspace(*pos) || '\x1e' == *pos || ';' == *pos) { + pos++; + continue; + } + if (strncasecmp_P(pos, PSTR("BACKLOG "), 8) == 0) { + //Skip "BACKLOG " and set not first command flag. So all followed command will be send to backlog + pos += 8; + continue; + } + if (strncasecmp_P(pos, PSTR("IF "), 3) == 0) { + //Has a nested IF statement + //Find the matched ENDIF + char *pEndif = pos + 3; //Skip "IF " + if (IF_BLOCK_ENDIF != findIfBlock(pEndif, lenEndBlock, IF_BLOCK_ENDIF)) { + //Cannot find matched endif, stop execution. + break; + } + //We has the whole IF statement, copy to oneCommand + memcpy(oneCommand, pos, pEndif - pos); + oneCommand[pEndif - pos] = '\0'; + pos = pEndif; + } else { //Normal command + //Looking for the command end single - '\x1e' + char *pEndOfCommand = strpbrk(pos, "\x1e;"); + if (NULL == pEndOfCommand) { + pEndOfCommand = pos + strlen(pos); + } + memcpy(oneCommand, pos, pEndOfCommand - pos); + oneCommand[pEndOfCommand - pos] = '\0'; + pos = pEndOfCommand; + } + //Start to process current command we found + //Going to insert the command into backlog + String sCurrentCommand = oneCommand; + sCurrentCommand.trim(); + if (sCurrentCommand.length() > 0 + && backlog.size() < MAX_BACKLOG && !backlog_mutex) + { + //Insert into backlog + backlog_mutex = true; + backlog.add(insertPosition, sCurrentCommand); + backlog_mutex = false; + insertPosition++; + } + } + return; +} + +/********************************************************************************************/ +/* + * Execute IF statement. This is the place to run a "IF ..." command. + * Input: + * statements - The IF statement we are going to process + * Output: + N/A + * Return: + * void + */ +void ProcessIfStatement(const char* statements) +{ + String conditionExpression; + int len = strlen(statements); + char statbuff[len + 1]; + memcpy(statbuff, statements, len + 1); + char *pos = statbuff; + int lenEndBlock = 0; + while (true) { //Each loop process one IF (or ELSEIF) block + //Find and test the condition expression followed the IF or ELSEIF + //Search for the open bracket first + while (*pos && *pos != '(') { + pos++; + } + if (0 == *pos) { break; } + char * posEnd = findClosureBracket(pos); + + if (true == evaluateLogicalExpression(pos + 1, posEnd - (pos + 1))) { + //Looking for matched "ELSEIF", "ELSE" or "ENDIF", then Execute this block + char * cmdBlockStart = posEnd + 1; + char * cmdBlockEnd = cmdBlockStart; + int8_t nextBlock = findIfBlock(cmdBlockEnd, lenEndBlock, IF_BLOCK_ANY); + if (IF_BLOCK_INVALID == nextBlock) { + //Failed + break; + } + ExecuteCommandBlock(cmdBlockStart, cmdBlockEnd - cmdBlockStart - lenEndBlock); + pos = cmdBlockEnd; + break; + } else { //Does not match the IF condition, going to check elseif and else + pos = posEnd + 1; + int8_t nextBlock = findIfBlock(pos, lenEndBlock, IF_BLOCK_ANY); + if (IF_BLOCK_ELSEIF == nextBlock) { + //Continue process next ELSEIF block like IF + continue; + } else if (IF_BLOCK_ELSE == nextBlock) { + //Looking for matched "ENDIF" then execute this block + char * cmdBlockEnd = pos; + int8_t nextBlock = findIfBlock(cmdBlockEnd, lenEndBlock, IF_BLOCK_ENDIF); + if (IF_BLOCK_ENDIF != nextBlock) { + //Failed + break; + } + ExecuteCommandBlock(pos, cmdBlockEnd - pos - lenEndBlock); + break; + } else { // IF_BLOCK_ENDIF == nextBlock + //We done + break; + } + } + } +} + +/********************************************************************************************/ +/* + * This function is called in Rules event handler to process any command between DO ... ENDON (BREAK) + * - Do escape (convert ";" into "\x1e") for all IF statements. + * Input: + * commands - The commands block need to execute + * Output: + N/A + * Return: + * void + */ +void RulesPreprocessCommand(char *pCommands) +{ + char * cmd = pCommands; + int lenEndBlock = 0; + while (*cmd) { + //Skip all ";" and space between two commands + if (';' == *cmd || isspace(*cmd)) { + cmd++; + } + else if (strncasecmp_P(cmd, PSTR("IF "), 3) == 0) { //found IF block + //We are going to look for matched "ENDIF" + char * pIfStart = cmd; + char * pIfEnd = pIfStart + 3; //Skip "IF " + //int pIfStart = cmd - command; //"IF" statement block start at position (relative to command start) + if (IF_BLOCK_ENDIF == findIfBlock(pIfEnd, lenEndBlock, IF_BLOCK_ENDIF)) { + //Found the ENDIF + cmd = pIfEnd; //Will continue process from here + //Escapte from ";" to "\x1e". + //By remove all ";" in IF statement block, we can prevent backlog command cut the whole block as multiple commands + while (pIfStart < pIfEnd) { + if (';' == *pIfStart) + *pIfStart = '\x1e'; + pIfStart++; + } + } + else { //Did not find the matched ENDIF, stop processing + break; + } + } + else { //Other commands, skip it + while (*cmd && ';' != *cmd) { + cmd++; + } + } + } + return; +} +#endif //SUPPORT_IF_STATEMENT + /*********************************************************************************************\ * Commands \*********************************************************************************************/ @@ -1207,7 +1738,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 +1765,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 696c7750f..3a87aec44 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': @@ -2011,6 +2031,7 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) { char *cp; uint16_t count; uint8_t vtype; + uint8_t dprec=glob_script_mem.script_dprec; float fvar; cp=srcbuf; struct T_INDEX ind; @@ -2021,13 +2042,16 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) { if (*cp=='%') { dstbuf[count]=*cp++; } else { - //char *scp=cp; + if (isdigit(*cp)) { + dprec=*cp&0xf; + cp++; + } cp=isvar(cp,&vtype,&ind,&fvar,string,0); if (vtype!=VAR_NV) { // found variable as result if (vtype==NUM_RES || (vtype&STYPE)==0) { // numeric result - dtostrfd(fvar,glob_script_mem.script_dprec,string); + dtostrfd(fvar,dprec,string); } else { // string result } @@ -2630,7 +2654,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { switch (lastop) { case OPER_EQU: if (glob_script_mem.var_not_found) { - if (!js) toLog("var not found\n"); + if (!js) toLogEOL("var not found: ",lp); goto next_line; } *dfvar=fvar; @@ -2733,7 +2757,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 +3414,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 +3427,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 +3577,89 @@ 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; + } + if (*lp!=';') { + // 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; + } + if (*lp!=';') { + // 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_13_display.ino b/sonoff/xdrv_13_display.ino index 6a0153545..3a144b6c9 100755 --- a/sonoff/xdrv_13_display.ino +++ b/sonoff/xdrv_13_display.ino @@ -1247,6 +1247,12 @@ void DisplayInitDriver(void) { XdspCall(FUNC_DISPLAY_INIT_DRIVER); + if (renderer) { + renderer->setTextFont(Settings.display_font); + renderer->setTextSize(Settings.display_size); + } + + // AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings.display_model); if (Settings.display_model) { @@ -1376,14 +1382,18 @@ void CmndDisplaySize(void) { if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 4)) { Settings.display_size = XdrvMailbox.payload; + if (renderer) renderer->setTextSize(Settings.display_size); + else DisplaySetSize(Settings.display_size); } ResponseCmndNumber(Settings.display_size); } void CmndDisplayFont(void) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 4)) { + if ((XdrvMailbox.payload >=0) && (XdrvMailbox.payload <= 4)) { Settings.display_font = XdrvMailbox.payload; + if (renderer) renderer->setTextFont(Settings.display_font); + else DisplaySetFont(Settings.display_font); } ResponseCmndNumber(Settings.display_font); } @@ -1804,7 +1814,7 @@ void Restore_graph(uint8_t num, char *path) { if (!fp) return; char vbuff[32]; char *cp=vbuff; - char buf[2]; + uint8_t buf[2]; uint8_t findex=0; for (uint32_t count=0;count<=gp->xs+4;count++) { diff --git a/sonoff/xdrv_15_pca9685.ino b/sonoff/xdrv_15_pca9685.ino index 906207851..fb1a923d5 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 608236f4b..6d9b26367 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,10 +18,10 @@ */ #ifdef USE_LIGHT -#ifdef USE_TUYA_DIMMER +#ifdef USE_TUYA_MCU #define XDRV_16 16 -#define XNRG_08 8 +#define XNRG_16 16 // Needs to be the last XNRG_xx #ifndef TUYA_DIMMER_ID #define TUYA_DIMMER_ID 0 @@ -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,22 @@ 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); - } + 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, 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 - } + 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 +333,7 @@ void TuyaResetWifi(void) void TuyaPacketProcess(void) { char scmnd[20]; + uint8_t fnId = TUYA_MCU_FUNC_NONE; switch (Tuya.buffer[3]) { @@ -201,24 +346,34 @@ void TuyaPacketProcess(void) break; case TUYA_CMD_STATE: - if (Tuya.buffer[5] == 5) { // on/off 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 ((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 + 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 (SwitchGetVirtual(fnId - TUYA_MCU_FUNC_SWT1) != Tuya.buffer[10]) { + SwitchSetVirtual(fnId - TUYA_MCU_FUNC_SWT1, Tuya.buffer[10]); + SwitchHandler(1); + } } - if (Settings.param[P_TUYA_DIMMER_ID] == Tuya.buffer[6]) { + + } + else if (Tuya.buffer[5] == 8) { // Long value packet + bool tuya_energy_enabled = (XNRG_16 == energy_flg); + if (fnId == TUYA_MCU_FUNC_DIMMER) { 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)) { @@ -228,30 +383,30 @@ void TuyaPacketProcess(void) 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])); + #ifdef USE_ENERGY_SENSOR + else if (tuya_energy_enabled && 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 (tuya_energy_enabled && 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 (tuya_energy_enabled && 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(); + 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 +421,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 +462,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); @@ -427,22 +602,20 @@ void TuyaSetWifiLed(void) * Energy Interface \*********************************************************************************************/ -int Xnrg08(uint8_t function) +bool Xnrg16(uint8_t function) { - int result = 0; + bool result = false; 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) { - Energy.current_available = false; - } - if (Settings.param[P_TUYA_VOLTAGE_ID] == 0) { - Energy.voltage_available = false; - } - energy_flg = XNRG_08; + if (TuyaGetDpId(TUYA_MCU_FUNC_POWER) != 0) { + if (TuyaGetDpId(TUYA_MCU_FUNC_CURRENT) == 0) { + Energy.current_available = false; } + if (TuyaGetDpId(TUYA_MCU_FUNC_VOLTAGE) == 0) { + Energy.voltage_available = false; + } + energy_flg = XNRG_16; } } } @@ -486,10 +659,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 902304f0b..9d6d33660 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 b2d9838f8..0dbb31d50 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 71eb1aaaa..000000000 --- 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 000000000..d87cc4af5 --- /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 000000000..1653ed78c --- /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/xdrv_25_A4988_Stepper.ino b/sonoff/xdrv_25_A4988_Stepper.ino new file mode 100644 index 000000000..89b0a09c1 --- /dev/null +++ b/sonoff/xdrv_25_A4988_Stepper.ino @@ -0,0 +1,174 @@ + +/* + xdrv_25_a4988_stepper.ino - A4988 StepMotorDriverCircuit- support for Sonoff-Tasmota + + Copyright (C) 2019 Tim Leuscher 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_A4988_Stepper +#include +#define XDRV_25 25 + +enum A4988Errors { A4988_NO_ERROR, A4988_NO_JSON_COMMAND, A4988_INVALID_JSON, A4988_MOVE, A4988_ROTATE, A4988_TURN}; + +short A4988_dir_pin = pin[GPIO_MAX]; +short A4988_stp_pin = pin[GPIO_MAX]; +short A4988_ms1_pin = pin[GPIO_MAX]; +short A4988_ms2_pin = pin[GPIO_MAX]; +short A4988_ms3_pin = pin[GPIO_MAX]; +short A4988_ena_pin = pin[GPIO_MAX]; +int A4988_spr = 0; +float A4988_rpm = 0; +short A4988_mis = 0; + +A4988_Stepper* myA4988 = nullptr; + +void A4988Init(void) +{ + A4988_dir_pin = pin[GPIO_A4988_DIR]; + A4988_stp_pin = pin[GPIO_A4988_STP]; + A4988_ena_pin = pin[GPIO_A4988_ENA]; + A4988_ms1_pin = pin[GPIO_A4988_MS1]; + A4988_ms2_pin = pin[GPIO_A4988_MS2]; + A4988_ms3_pin = pin[GPIO_A4988_MS3]; + A4988_spr = 200; + A4988_rpm = 30; + A4988_mis = 1; + + myA4988 = new A4988_Stepper( A4988_spr + , A4988_rpm + , A4988_mis + , A4988_dir_pin + , A4988_stp_pin + , A4988_ena_pin + , A4988_ms1_pin + , A4988_ms2_pin + , A4988_ms3_pin ); +} + +const char kA4988Commands[] PROGMEM = "|" + "MOTOR"; + +void (* const A4988Command[])(void) PROGMEM = { &CmndMOTOR}; + +uint32_t MOTORCmndJson(void) +{ + // MOTOR {"doMove":200} + // MOTOR {"doRotate":360} + // MOTOR {"doTurn":1.0} + uint32_t returnValue =A4988_NO_JSON_COMMAND; + + char parm_uc[12]; + char dataBufUc[XdrvMailbox.data_len]; + UpperCase(dataBufUc, XdrvMailbox.data); + RemoveSpace(dataBufUc); + if (strlen(dataBufUc) < 8) { returnValue =A4988_INVALID_JSON; } + + DynamicJsonBuffer jsonBuf; + JsonObject &json = jsonBuf.parseObject(dataBufUc); + if (json.success()) { + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_SPR)); + if (json.containsKey(parm_uc)){ + int howManySteps =strtoul(json[parm_uc],nullptr,10); + myA4988->setSPR(howManySteps); + returnValue = A4988_NO_ERROR; + } + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_RPM)); + if (json.containsKey(parm_uc)){ + int howManyRounds =strtoul(json[parm_uc],nullptr,10); + myA4988->setRPM(howManyRounds); + returnValue = A4988_NO_ERROR; + } + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_MIS)); + if (json.containsKey(parm_uc)){ + short oneToSixteen =strtoul(json[parm_uc],nullptr,10); + myA4988->setMIS(oneToSixteen); + returnValue = A4988_NO_ERROR; + } + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_MOVE)); + if (json.containsKey(parm_uc)){ + long stepsPlease = strtoul(json[parm_uc],nullptr,10); + myA4988->doMove(stepsPlease); + returnValue = A4988_MOVE; + } + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_ROTATE)); + if (json.containsKey(parm_uc)){ + long degrsPlease = strtoul(json[parm_uc],nullptr,10); + myA4988->doRotate(degrsPlease); + returnValue = A4988_ROTATE; + } + UpperCase_P(parm_uc, PSTR(D_JSON_MOTOR_TURN)); + if (json.containsKey(parm_uc)){ + float turnsPlease = strtod(json[parm_uc],nullptr); + myA4988->doTurn(turnsPlease); + returnValue = A4988_TURN; + } + } else returnValue =A4988_INVALID_JSON; + return returnValue; +} + +void CmndMOTOR(void){ + uint32_t error; + if (XdrvMailbox.data_len) { + if (strstr(XdrvMailbox.data, "}") == nullptr) { + error = A4988_NO_JSON_COMMAND; + } else { + error = MOTORCmndJson(); + } + } + A4988CmndResponse(error); +} + +void A4988CmndResponse(uint32_t error){ + switch (error) { + case A4988_NO_JSON_COMMAND: + ResponseCmndChar(PSTR("No command!")); + break; + case A4988_MOVE: + ResponseCmndChar(PSTR("Stepping!")); + break; + case A4988_ROTATE: + ResponseCmndChar(PSTR("Rotating!")); + break; + case A4988_TURN: + ResponseCmndChar(PSTR("Turning!")); + break; + default: // A4988_NO_ERROR + ResponseCmndDone(); + } + +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ +bool Xdrv25(uint8_t function) +{ + bool result = false; + if ((pin[GPIO_A4988_DIR] < 99) && (pin[GPIO_A4988_STP] < 99)) { + switch (function) { + case FUNC_INIT: + A4988Init(); + break; + case FUNC_COMMAND: + result = DecodeCommand(kA4988Commands, A4988Command); + break; + } + } + return result; +} + +#endif diff --git a/sonoff/xdsp_02_ssd1306.ino b/sonoff/xdsp_02_ssd1306.ino index fbbbf0acb..704226a25 100755 --- a/sonoff/xdsp_02_ssd1306.ino +++ b/sonoff/xdsp_02_ssd1306.ino @@ -148,6 +148,8 @@ void Ssd1306Time(void) void Ssd1306Refresh(void) // Every second { + if (!renderer) return; + if (Settings.display_mode) { // Mode 0 is User text switch (Settings.display_mode) { case 1: // Time diff --git a/sonoff/xdsp_05_epaper_29.ino b/sonoff/xdsp_05_epaper_29.ino index 105aa504b..8d97bd123 100644 --- a/sonoff/xdsp_05_epaper_29.ino +++ b/sonoff/xdsp_05_epaper_29.ino @@ -108,12 +108,13 @@ void EpdInitDriver29() #define EPD_FONT_HEIGTH 12 void EpdPrintLog29(void) { + disp_refresh--; if (!disp_refresh) { disp_refresh = Settings.display_refresh; - if (Settings.display_rotate) { + //if (Settings.display_rotate) { if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); } - } + //} char* txt = DisplayLogBuffer('\040'); if (txt != nullptr) { @@ -143,6 +144,8 @@ void EpdPrintLog29(void) void EpdRefresh29(void) // Every second { if (Settings.display_mode) { // Mode 0 is User text + + if (!renderer) return; /* char tftdt[Settings.display_cols[0] +1]; char date4[11]; // 24-04-2017 diff --git a/sonoff/xdsp_07_sh1106.ino b/sonoff/xdsp_07_sh1106.ino index 1c45a451d..d694129ec 100644 --- a/sonoff/xdsp_07_sh1106.ino +++ b/sonoff/xdsp_07_sh1106.ino @@ -142,16 +142,17 @@ void SH1106Time(void) void SH1106Refresh(void) // Every second { + if (!renderer) return; if (Settings.display_mode) { // Mode 0 is User text switch (Settings.display_mode) { case 1: // Time - Ssd1306Time(); + SH1106Time(); break; case 2: // Local case 3: // Local case 4: // Mqtt case 5: // Mqtt - Ssd1306PrintLog(); + SH1106PrintLog(); break; } } diff --git a/sonoff/xdsp_08_ILI9488.ino b/sonoff/xdsp_08_ILI9488.ino index 51cb0fd4c..071280601 100644 --- a/sonoff/xdsp_08_ILI9488.ino +++ b/sonoff/xdsp_08_ILI9488.ino @@ -124,13 +124,19 @@ 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); } + +void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) { + buttons[count]->xdrawButton(pwr); + if (pwr) buttons[count]->vpower|=0x80; + else buttons[count]->vpower&=0x7f; +} // check digitizer hit void FT6236Check() { uint16_t temp; +uint8_t rbutt=0,vbutt=0; ili9488_ctouch_counter++; if (2 == ili9488_ctouch_counter) { // every 100 ms should be enough @@ -158,17 +164,17 @@ if (2 == ili9488_ctouch_counter) { // now must compare with defined buttons for (uint8_t count=0; countvpower&0x7f; if (buttons[count]->contains(ili9488_pLoc.x,ili9488_pLoc.y)) { // did hit buttons[count]->press(true); if (buttons[count]->justPressed()) { - uint8_t bflags=buttons[count]->vpower&0x7f; if (!bflags) { - // real button - if (!SendKey(0, count+1, POWER_TOGGLE)) { - ExecuteCommandPower(count+1, POWER_TOGGLE, SRC_BUTTON); + uint8_t pwr=bitRead(power,rbutt); + if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { + ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); + ILI9488_RDW_BUTT(count,!pwr); } - buttons[count]->xdrawButton(bitRead(power,count)); } else { // virtual button const char *cp; @@ -186,6 +192,11 @@ if (2 == ili9488_ctouch_counter) { } } } + if (!bflags) { + rbutt++; + } else { + vbutt++; + } } } } @@ -193,15 +204,27 @@ if (2 == ili9488_ctouch_counter) { // no hit for (uint8_t count=0; countvpower&0x7f; buttons[count]->press(false); if (buttons[count]->justReleased()) { uint8_t bflags=buttons[count]->vpower&0x7f; - if (bflags>1) { - // push button - buttons[count]->vpower&=0x7f; - ILI9488_MQTT(count,"PBT"); + if (bflags>0) { + if (bflags>1) { + // push button + buttons[count]->vpower&=0x7f; + ILI9488_MQTT(count,"PBT"); + } + buttons[count]->xdrawButton(buttons[count]->vpower&0x80); } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); + } + if (!bflags) { + // check if power button stage changed + uint8_t pwr=bitRead(power,rbutt); + uint8_t vpwr=(buttons[count]->vpower&0x80)>>7; + if (pwr!=vpwr) { + ILI9488_RDW_BUTT(count,pwr); + } + rbutt++; } } } diff --git a/sonoff/xdsp_10_RA8876.ino b/sonoff/xdsp_10_RA8876.ino index d77ed6c00..d138ae154 100644 --- a/sonoff/xdsp_10_RA8876.ino +++ b/sonoff/xdsp_10_RA8876.ino @@ -109,14 +109,20 @@ 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); } +void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) { + buttons[count]->xdrawButton(pwr); + if (pwr) buttons[count]->vpower|=0x80; + else buttons[count]->vpower&=0x7f; +} + // check digitizer hit void FT5316Check() { uint16_t temp; +uint8_t rbutt=0,vbutt=0; ra8876_ctouch_counter++; if (2 == ra8876_ctouch_counter) { // every 100 ms should be enough @@ -153,23 +159,26 @@ if (2 == ra8876_ctouch_counter) { break; } */ + //AddLog_P2(LOG_LEVEL_INFO, PSTR(">> %d,%d"),ra8876_pLoc.x,ra8876_pLoc.y); + //Serial.printf("loc x: %d , loc y: %d\n",pLoc.x,pLoc.y); // now must compare with defined buttons for (uint8_t count=0; countvpower&0x7f; if (buttons[count]->contains(ra8876_pLoc.x,ra8876_pLoc.y)) { // did hit buttons[count]->press(true); if (buttons[count]->justPressed()) { - uint8_t bflags=buttons[count]->vpower&0x7f; if (!bflags) { // real button - if (!SendKey(0, count+1, POWER_TOGGLE)) { - ExecuteCommandPower(count+1, POWER_TOGGLE, SRC_BUTTON); + uint8_t pwr=bitRead(power,rbutt); + if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) { + ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON); + RA8876_RDW_BUTT(count,!pwr); } - buttons[count]->xdrawButton(bitRead(power,count)); } else { // virtual button const char *cp; @@ -187,6 +196,11 @@ if (2 == ra8876_ctouch_counter) { } } } + if (!bflags) { + rbutt++; + } else { + vbutt++; + } } } } @@ -194,15 +208,26 @@ if (2 == ra8876_ctouch_counter) { // no hit for (uint8_t count=0; countvpower&0x7f; buttons[count]->press(false); if (buttons[count]->justReleased()) { - uint8_t bflags=buttons[count]->vpower&0x7f; - if (bflags>1) { - // push button - buttons[count]->vpower&=0x7f; - RA8876_MQTT(count,"PBT"); + if (bflags>0) { + if (bflags>1) { + // push button + buttons[count]->vpower&=0x7f; + RA8876_MQTT(count,"PBT"); + } + buttons[count]->xdrawButton(buttons[count]->vpower&0x80); } - buttons[count]->xdrawButton(buttons[count]->vpower&0x80); + } + if (!bflags) { + // check if power button stage changed + uint8_t pwr=bitRead(power,rbutt); + uint8_t vpwr=(buttons[count]->vpower&0x80)>>7; + if (pwr!=vpwr) { + RA8876_RDW_BUTT(count,pwr); + } + rbutt++; } } } diff --git a/sonoff/xnrg_01_hlw8012.ino b/sonoff/xnrg_01_hlw8012.ino index befa9c305..7bf039999 100644 --- a/sonoff/xnrg_01_hlw8012.ino +++ b/sonoff/xnrg_01_hlw8012.ino @@ -249,34 +249,32 @@ void HlwSnsInit(void) void HlwDrvInit(void) { - if (!energy_flg) { - Hlw.model_type = 0; // HLW8012 - if (pin[GPIO_HJL_CF] < 99) { - pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; - pin[GPIO_HJL_CF] = 99; - Hlw.model_type = 1; // HJL-01/BL0937 + Hlw.model_type = 0; // HLW8012 + if (pin[GPIO_HJL_CF] < 99) { + pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; + pin[GPIO_HJL_CF] = 99; + Hlw.model_type = 1; // HJL-01/BL0937 + } + + if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor + + Hlw.ui_flag = true; // Voltage on high + if (pin[GPIO_NRG_SEL_INV] < 99) { + pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; + pin[GPIO_NRG_SEL_INV] = 99; + Hlw.ui_flag = false; // Voltage on low } - if (pin[GPIO_HLW_CF] < 99) { // HLW8012 or HJL-01 based device Power monitor - - Hlw.ui_flag = true; // Voltage on high - if (pin[GPIO_NRG_SEL_INV] < 99) { - pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; - pin[GPIO_NRG_SEL_INV] = 99; - Hlw.ui_flag = false; // Voltage on low + if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor + if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector + Energy.current_available = false; // Assume Voltage } - - if (pin[GPIO_NRG_CF1] < 99) { // Voltage and/or Current monitor - if (99 == pin[GPIO_NRG_SEL]) { // Voltage and/or Current selector - Energy.current_available = false; // Assume Voltage - } - } else { - Energy.current_available = false; - Energy.voltage_available = false; - } - - energy_flg = XNRG_01; + } else { + Energy.current_available = false; + Energy.voltage_available = false; } + + energy_flg = XNRG_01; } } @@ -311,28 +309,26 @@ bool HlwCommand(void) * Interface \*********************************************************************************************/ -int Xnrg01(uint8_t function) +bool Xnrg01(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - HlwDrvInit(); - } - else if (XNRG_01 == energy_flg) { - switch (function) { - case FUNC_INIT: - HlwSnsInit(); - break; - case FUNC_ENERGY_EVERY_SECOND: - HlwEverySecond(); - break; - case FUNC_EVERY_200_MSECOND: - HlwEvery200ms(); - break; - case FUNC_COMMAND: - result = HlwCommand(); - break; - } + switch (function) { + case FUNC_EVERY_200_MSECOND: + HlwEvery200ms(); + break; + case FUNC_ENERGY_EVERY_SECOND: + HlwEverySecond(); + break; + case FUNC_COMMAND: + result = HlwCommand(); + break; + case FUNC_INIT: + HlwSnsInit(); + break; + case FUNC_PRE_INIT: + HlwDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_02_cse7766.ino b/sonoff/xnrg_02_cse7766.ino index f5e1a606c..a8ab38916 100644 --- a/sonoff/xnrg_02_cse7766.ino +++ b/sonoff/xnrg_02_cse7766.ino @@ -145,7 +145,7 @@ bool CseSerialInput(void) Energy.data_valid = 0; CseReceived(); Cse.received = false; - return 1; + return true; } else { AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: " D_CHECKSUM_FAILURE)); do { // Sync buffer with data (issue #1907 and #3425) @@ -167,7 +167,7 @@ bool CseSerialInput(void) serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; } serial_in_byte = 0; // Discard - return 0; + return false; } /********************************************************************************************/ @@ -208,16 +208,14 @@ void CseEverySecond(void) void CseDrvInit(void) { - if (!energy_flg) { - if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported - baudrate = 4800; - serial_config = SERIAL_8E1; - if (0 == Settings.param[P_CSE7766_INVALID_POWER]) { - Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 - } - Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER]; - energy_flg = XNRG_02; + if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported + baudrate = 4800; + serial_config = SERIAL_8E1; + if (0 == Settings.param[P_CSE7766_INVALID_POWER]) { + Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 } + Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER]; + energy_flg = XNRG_02; } } @@ -249,25 +247,23 @@ bool CseCommand(void) * Interface \*********************************************************************************************/ -int Xnrg02(uint8_t function) +bool Xnrg02(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - CseDrvInit(); - } - else if (XNRG_02 == energy_flg) { - switch (function) { - case FUNC_ENERGY_EVERY_SECOND: - CseEverySecond(); - break; - case FUNC_COMMAND: - result = CseCommand(); - break; - case FUNC_SERIAL: - result = CseSerialInput(); - break; - } + switch (function) { + case FUNC_SERIAL: + result = CseSerialInput(); + break; + case FUNC_ENERGY_EVERY_SECOND: + CseEverySecond(); + break; + case FUNC_COMMAND: + result = CseCommand(); + break; + case FUNC_PRE_INIT: + CseDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_03_pzem004t.ino b/sonoff/xnrg_03_pzem004t.ino index 4083d9b38..1fc6e5e5e 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++; @@ -216,10 +211,8 @@ void PzemSnsInit(void) void PzemDrvInit(void) { - if (!energy_flg) { - if ((pin[GPIO_PZEM004_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { // Any device with a Pzem004T - energy_flg = XNRG_03; - } + if ((pin[GPIO_PZEM004_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { // Any device with a Pzem004T + energy_flg = XNRG_03; } } @@ -227,22 +220,20 @@ void PzemDrvInit(void) * Interface \*********************************************************************************************/ -int Xnrg03(uint8_t function) +bool Xnrg03(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - PzemDrvInit(); - } - else if (XNRG_03 == energy_flg) { - switch (function) { - case FUNC_INIT: - PzemSnsInit(); - break; - case FUNC_EVERY_200_MSECOND: - if (PzemSerial) { PzemEvery200ms(); } - break; - } + switch (function) { + case FUNC_EVERY_200_MSECOND: + if (PzemSerial) { PzemEvery200ms(); } + break; + case FUNC_INIT: + PzemSnsInit(); + break; + case FUNC_PRE_INIT: + PzemDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_04_mcp39f501.ino b/sonoff/xnrg_04_mcp39f501.ino index 5cdb4a50b..01b915954 100644 --- a/sonoff/xnrg_04_mcp39f501.ino +++ b/sonoff/xnrg_04_mcp39f501.ino @@ -583,17 +583,15 @@ void McpSnsInit(void) void McpDrvInit(void) { - if (!energy_flg) { - if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) { - if (pin[GPIO_MCP39F5_RST] < 99) { - pinMode(pin[GPIO_MCP39F5_RST], OUTPUT); - digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's - } - mcp_calibrate = 0; - mcp_timeout = 2; // Initial wait - mcp_init = 2; // Initial setup steps - energy_flg = XNRG_04; + if ((pin[GPIO_MCP39F5_RX] < 99) && (pin[GPIO_MCP39F5_TX] < 99)) { + if (pin[GPIO_MCP39F5_RST] < 99) { + pinMode(pin[GPIO_MCP39F5_RST], OUTPUT); + digitalWrite(pin[GPIO_MCP39F5_RST], 0); // MCP disable - Reset Delta Sigma ADC's } + mcp_calibrate = 0; + mcp_timeout = 2; // Initial wait + mcp_init = 2; // Initial setup steps + energy_flg = XNRG_04; } } @@ -651,28 +649,26 @@ bool McpCommand(void) * Interface \*********************************************************************************************/ -int Xnrg04(uint8_t function) +bool Xnrg04(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - McpDrvInit(); - } - else if (XNRG_04 == energy_flg) { - switch (function) { - case FUNC_LOOP: - if (McpSerial) { McpSerialInput(); } - break; - case FUNC_INIT: - McpSnsInit(); - break; - case FUNC_ENERGY_EVERY_SECOND: - if (McpSerial) { McpEverySecond(); } - break; - case FUNC_COMMAND: - result = McpCommand(); - break; - } + switch (function) { + case FUNC_LOOP: + if (McpSerial) { McpSerialInput(); } + break; + case FUNC_ENERGY_EVERY_SECOND: + if (McpSerial) { McpEverySecond(); } + break; + case FUNC_COMMAND: + result = McpCommand(); + break; + case FUNC_INIT: + McpSnsInit(); + break; + case FUNC_PRE_INIT: + McpDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_05_pzem_ac.ino b/sonoff/xnrg_05_pzem_ac.ino index 79f97e508..0a0258787 100644 --- a/sonoff/xnrg_05_pzem_ac.ino +++ b/sonoff/xnrg_05_pzem_ac.ino @@ -64,7 +64,7 @@ void PzemAcEverySecond(void) uint8_t buffer[26]; uint8_t error = PzemAcModbus->ReceiveBuffer(buffer, 10); - AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer)); + AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, sizeof(buffer)); if (error) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemAc response error %d"), error); @@ -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); // } } } @@ -114,10 +109,8 @@ void PzemAcSnsInit(void) void PzemAcDrvInit(void) { - if (!energy_flg) { - if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { - energy_flg = XNRG_05; - } + if ((pin[GPIO_PZEM016_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { + energy_flg = XNRG_05; } } @@ -125,22 +118,20 @@ void PzemAcDrvInit(void) * Interface \*********************************************************************************************/ -int Xnrg05(uint8_t function) +bool Xnrg05(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - PzemAcDrvInit(); - } - else if (XNRG_05 == energy_flg) { - switch (function) { - case FUNC_INIT: - PzemAcSnsInit(); - break; - case FUNC_ENERGY_EVERY_SECOND: - if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875 - break; - } + switch (function) { + case FUNC_ENERGY_EVERY_SECOND: + if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875 + break; + case FUNC_INIT: + PzemAcSnsInit(); + break; + case FUNC_PRE_INIT: + PzemAcDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_06_pzem_dc.ino b/sonoff/xnrg_06_pzem_dc.ino index 4c8db837d..21c256e75 100644 --- a/sonoff/xnrg_06_pzem_dc.ino +++ b/sonoff/xnrg_06_pzem_dc.ino @@ -46,7 +46,7 @@ void PzemDcEverySecond(void) uint8_t buffer[22]; uint8_t error = PzemDcModbus->ReceiveBuffer(buffer, 8); - AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer)); + AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, sizeof(buffer)); if (error) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemDc response error %d"), error); @@ -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); } } @@ -93,10 +88,8 @@ void PzemDcSnsInit(void) void PzemDcDrvInit(void) { - if (!energy_flg) { - if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { - energy_flg = XNRG_06; - } + if ((pin[GPIO_PZEM017_RX] < 99) && (pin[GPIO_PZEM0XX_TX] < 99)) { + energy_flg = XNRG_06; } } @@ -104,22 +97,20 @@ void PzemDcDrvInit(void) * Interface \*********************************************************************************************/ -int Xnrg06(uint8_t function) +bool Xnrg06(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - PzemDcDrvInit(); - } - else if (XNRG_06 == energy_flg) { - switch (function) { - case FUNC_INIT: - PzemDcSnsInit(); - break; - case FUNC_ENERGY_EVERY_SECOND: - if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875 - break; - } + switch (function) { + case FUNC_ENERGY_EVERY_SECOND: + if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875 + break; + case FUNC_INIT: + PzemDcSnsInit(); + break; + case FUNC_PRE_INIT: + PzemDcDrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_07_ade7953.ino b/sonoff/xnrg_07_ade7953.ino index de865f0e5..dcb958f63 100644 --- a/sonoff/xnrg_07_ade7953.ino +++ b/sonoff/xnrg_07_ade7953.ino @@ -169,19 +169,17 @@ void Ade7953EnergyEverySecond() void Ade7953DrvInit(void) { - if (!energy_flg) { - if (i2c_flg && (pin[GPIO_ADE7953_IRQ] < 99)) { // Irq on GPIO16 is not supported... - delay(100); // Need 100mS to init ADE7953 - if (I2cDevice(ADE7953_ADDR)) { - if (HLW_PREF_PULSE == Settings.energy_power_calibration) { - Settings.energy_power_calibration = ADE7953_PREF; - Settings.energy_voltage_calibration = ADE7953_UREF; - Settings.energy_current_calibration = ADE7953_IREF; - } - AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "ADE7953", ADE7953_ADDR); - Ade7953.init_step = 2; - energy_flg = XNRG_07; - } + if (i2c_flg && (pin[GPIO_ADE7953_IRQ] < 99)) { // Irq on GPIO16 is not supported... + delay(100); // Need 100mS to init ADE7953 + if (I2cDevice(ADE7953_ADDR)) { + if (HLW_PREF_PULSE == Settings.energy_power_calibration) { + Settings.energy_power_calibration = ADE7953_PREF; + Settings.energy_voltage_calibration = ADE7953_UREF; + Settings.energy_current_calibration = ADE7953_IREF; + } + AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "ADE7953", ADE7953_ADDR); + Ade7953.init_step = 2; + energy_flg = XNRG_07; } } } @@ -234,22 +232,20 @@ bool Ade7953Command(void) * Interface \*********************************************************************************************/ -int Xnrg07(uint8_t function) +bool Xnrg07(uint8_t function) { - int result = 0; + bool result = false; - if (FUNC_PRE_INIT == function) { - Ade7953DrvInit(); - } - else if (XNRG_07 == energy_flg) { - switch (function) { - case FUNC_ENERGY_EVERY_SECOND: - Ade7953EnergyEverySecond(); - break; - case FUNC_COMMAND: - result = Ade7953Command(); - break; - } + switch (function) { + case FUNC_ENERGY_EVERY_SECOND: + Ade7953EnergyEverySecond(); + break; + case FUNC_COMMAND: + result = Ade7953Command(); + break; + case FUNC_PRE_INIT: + Ade7953DrvInit(); + break; } return result; } diff --git a/sonoff/xnrg_08_sdm120.ino b/sonoff/xnrg_08_sdm120.ino new file mode 100644 index 000000000..472886442 --- /dev/null +++ b/sonoff/xnrg_08_sdm120.ino @@ -0,0 +1,270 @@ +/* + xnrg_08_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_08 8 + +// 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 uint8_t sdm120_table = 8; +const uint8_t sdm220_table = 13; + +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] + 0x0156, // SDM120C_TOTAL_ACTIVE_ENERGY [kWh] + + 0X0048, // SDM220_IMPORT_ACTIVE [kWh] + 0X004A, // SDM220_EXPORT_ACTIVE [kWh] + 0X004C, // SDM220_IMPORT_REACTIVE [kVArh] + 0X004E, // SDM220_EXPORT_REACTIVE [kVArh] + 0X0024 // SDM220_PHASE_ANGLE [Degree] +}; + +struct SDM120 { + float total_active = 0; + float import_active = NAN; + float import_reactive = 0; + float export_reactive = 0; + float phase_angle = 0; + uint8_t read_state = 0; + uint8_t send_retry = 0; + uint8_t start_address_count = sdm220_table; +} Sdm120; + +/*********************************************************************************************/ + +void SDM120Every250ms(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, buffer, sizeof(buffer)); + + if (error) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "SDM120 response error %d"), error); + } else { + uint32_t max_table = + Energy.data_valid = 0; + + // 0 1 2 3 4 5 6 7 8 + // SA FC BC Fh Fl Sh Sl Cl Ch + // 01 04 04 43 66 33 34 1B 38 = 230.2 Volt + 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: + Sdm120.total_active = value; // 484.708 kWh = import_active + export_active + break; + + case 8: + Sdm120.import_active = value; // 478.492 kWh + break; + + case 9: + Energy.export_active = value; // 6.216 kWh + break; + + case 10: + Sdm120.import_reactive = value; // 172.750 kVArh + break; + + case 11: + Sdm120.export_reactive = value; // 2.844 kVArh + break; + + case 12: + Sdm120.phase_angle = value; // 0.00 Deg + break; + } + + Sdm120.read_state++; + if (Sdm120.read_state == Sdm120.start_address_count) { + Sdm120.read_state = 0; + + if (Sdm120.start_address_count > sdm120_table) { + if (!isnan(Sdm120.import_active)) { + Sdm120.total_active = Sdm120.import_active; + } else { + Sdm120.start_address_count = sdm120_table; // No extended registers available + } + } + EnergyUpdateTotal(Sdm120.total_active, true); // 484.708 kWh + } + } + } // 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 ((pin[GPIO_SDM120_RX] < 99) && (pin[GPIO_SDM120_TX] < 99)) { + energy_flg = XNRG_08; + } +} + +void Sdm220Reset(void) +{ + if (isnan(Sdm120.import_active)) { return; } + + Sdm120.import_active = 0; + Sdm120.import_reactive = 0; + Sdm120.export_reactive = 0; + Sdm120.phase_angle = 0; +} + +#ifdef USE_WEBSERVER +const char HTTP_ENERGY_SDM220[] PROGMEM = + "{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) +{ + if (isnan(Sdm120.import_active)) { return; } + + char import_active_chr[FLOATSZ]; + dtostrfd(Sdm120.import_active, Settings.flag2.energy_resolution, import_active_chr); + char import_reactive_chr[FLOATSZ]; + dtostrfd(Sdm120.import_reactive, Settings.flag2.energy_resolution, import_reactive_chr); + char export_reactive_chr[FLOATSZ]; + dtostrfd(Sdm120.export_reactive, Settings.flag2.energy_resolution, export_reactive_chr); + char phase_angle_chr[FLOATSZ]; + dtostrfd(Sdm120.phase_angle, 2, phase_angle_chr); + + if (json) { + ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT_ACTIVE "\":%s,\"" D_JSON_IMPORT_REACTIVE "\":%s,\"" D_JSON_EXPORT_REACTIVE "\":%s,\"" D_JSON_PHASE_ANGLE "\":%s"), + import_active_chr, import_reactive_chr, export_reactive_chr, phase_angle_chr); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_ENERGY_SDM220, import_reactive_chr, export_reactive_chr, phase_angle_chr); +#endif // USE_WEBSERVER + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xnrg08(uint8_t function) +{ + bool result = false; + + switch (function) { + case FUNC_EVERY_250_MSECOND: + if (uptime > 4) { SDM120Every250ms(); } + break; + case FUNC_JSON_APPEND: + Sdm220Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + Sdm220Show(0); + break; +#endif // USE_WEBSERVER + case FUNC_ENERGY_RESET: + Sdm220Reset(); + break; + case FUNC_INIT: + Sdm120SnsInit(); + break; + case FUNC_PRE_INIT: + Sdm120DrvInit(); + break; + } + return result; +} + +#endif // USE_SDM120_2 +#endif // USE_ENERGY_SENSOR diff --git a/sonoff/xnrg_interface.ino b/sonoff/xnrg_interface.ino index 22582f6c7..3e36b334b 100644 --- a/sonoff/xnrg_interface.ino +++ b/sonoff/xnrg_interface.ino @@ -20,9 +20,9 @@ #ifdef USE_ENERGY_SENSOR #ifdef XFUNC_PTR_IN_ROM -int (* const xnrg_func_ptr[])(uint8_t) PROGMEM = { // Energy driver Function Pointers +bool (* const xnrg_func_ptr[])(uint8_t) PROGMEM = { // Energy driver Function Pointers #else -int (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers +bool (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers #endif #ifdef XNRG_01 @@ -92,20 +92,23 @@ int (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers const uint8_t xnrg_present = sizeof(xnrg_func_ptr) / sizeof(xnrg_func_ptr[0]); // Number of drivers found -int XnrgCall(uint8_t Function) +uint8_t xnrg_active = 0; + +bool XnrgCall(uint8_t function) { - int result = 0; - - for (uint32_t x = 0; x < xnrg_present; x++) { - result = xnrg_func_ptr[x](Function); - - if (result && ((FUNC_SERIAL == Function) || - (FUNC_COMMAND == Function) - )) { - break; + if (FUNC_PRE_INIT == function) { + for (uint32_t x = 0; x < xnrg_present; x++) { + xnrg_func_ptr[x](function); + if (energy_flg) { + xnrg_active = x; + return true; // Stop further driver investigation + } } } - return result; + else if (energy_flg) { + return xnrg_func_ptr[xnrg_active](function); + } + return false; } #endif // USE_ENERGY_SENSOR diff --git a/sonoff/xplg_ws2812.ino b/sonoff/xplg_ws2812.ino index 479f27065..8b15d4286 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 cd4973458..caefb67e8 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 17527aa7e..333ae7524 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 1b1434044..20dc8a8f0 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 7fc168d7d..2a42b2a08 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 dbd56abd1..1df541d82 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 40ff31df9..9dabb29cd 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; diff --git a/sonoff/xsns_54_ina226.ino b/sonoff/xsns_54_ina226.ino new file mode 100644 index 000000000..9fc48c83b --- /dev/null +++ b/sonoff/xsns_54_ina226.ino @@ -0,0 +1,568 @@ +/* + xsns_54_ina226.ino - INA226 Current Sensor support for Sonoff-Tasmota + + Copyright (C) 2019 Stephen Rodgers 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_I2C +#ifdef USE_INA226 +/* +* Setup a single INA226 device at address 0x40: +* +* 1. Select a module type with free I2C pins. +* 2. Configure the module to use I2C on the correct pins. +* 3. Connect your ina226 module(s) to the I2C pins. +* 4. Use the i2cscan console command to probe the modules and check they are present. +* 5. Enable the first device at I2C slave address 0x40 using the following console commands: +* a. Sensor54 11 [shunt resistance in ohms] e.g. Sensor54 11 0.1 +* b. Sensor54 12 [full scale current in amperes] e.g. Sensor54 12 3.0 +* c. Sensor54 2 saves the settings and restarts Tasmota. The device should show up after the system boots again. +* +* Device number to I2C slave address mapping +* +* 1 - 0x40 +* 2 - 0x41 +* 3 - 0x44 +* 4 - 0x45 +* +* This driver will not probe I2C bus for INA226 devices unless the full scale current is set for a device number. +* It will map device numbers as follows: +* +* To set shunt resistance and full scale current, use the Sensor54 command interface as follows: +* +* Sensor54 10 Return channel 1 shunt resistance and full scale current +* Sensor54 11 [shunt_resistance] Set INA226 channel 1 shunt resistance in ohms, floating point +* Sensor54 12 [full_scale_current] Set INA226 channel 1 full scale current in amperes, floating point +* Sensor54 20 Return channel 2 shunt resistance and full scale current +* Sensor54 21 [shunt_resistance] Set INA226 channel 2 shunt resistance in ohms, floating point +* Sensor54 22 [full_scale_current] Set INA226 channel 2 full scale current in amperes, floating point +* Sensor54 30 Return channel 3 shunt resistance and full scale current +* Sensor54 31 [shunt_resistance] Set INA226 channel 3 shunt resistance in ohms, floating point +* Sensor54 32 [full_scale_current] Set INA226 channel 3 full scale current in amperes, floating point +* Sensor54 40 Return channel 4 shunt resistance and full scale current +* Sensor54 41 [shunt_resistance] Set INA226 channel 4 shunt resistance in ohms, floating point +* Sensor54 42 [full_scale_current] Set INA226 channel 4 full scale current in amperes, floating point +* +* Other commands +* +* Sensor54 1 Rescan for devices and return the number of slaves found. +* Sensor54 2 Save the configuration and restart +* +* +*/ + +// Define driver ID + +#define XSNS_54 54 + +#define INA226_MAX_ADDRESSES 4 +#define INA226_ADDRESS1 (0x40) // 1000000 (A0+A1=GND) +#define INA226_ADDRESS2 (0x41) // 1000000 (A0=Vcc, A1=GND) +#define INA226_ADDRESS3 (0x44) // 1000000 (A0=GND, A1=Vcc) +#define INA226_ADDRESS4 (0x45) // 1000000 (A0+A1=Vcc) + +#define INA226_REG_CONFIG (0x00) // Config register +#define INA226_RES_CONFIG (0x4127) // Config register at reset +#define INA226_DEF_CONFIG (0x42FF) // Our default configuration +#define INA226_CONFIG_RESET (0x8000) // Config register reset bit + +#define INA226_REG_SHUNTVOLTAGE (0x01) +#define INA226_REG_BUSVOLTAGE (0x02) +#define INA226_REG_POWER (0x03) +#define INA226_REG_CURRENT (0x04) +#define INA226_REG_CALIBRATION (0x05) + + +typedef struct Ina226SlaveInfo_tag { + uint8_t address; + uint16_t calibrationValue; + uint16_t config; + uint8_t present : 1; + float i_lsb; +} Ina226SlaveInfo_t; + +/* +* Program memory constants +*/ + +static const uint8_t PROGMEM probeAddresses[INA226_MAX_ADDRESSES] = {INA226_ADDRESS1, INA226_ADDRESS2, INA226_ADDRESS3, INA226_ADDRESS4}; + +/* +* Global Variables +*/ + + +static char Ina226Str[] = "INA226"; +static uint8_t slavesFound = 0; +static uint8_t schedule_reinit = 0; +static Ina226SlaveInfo_t slaveInfo[4] = {0}; +//static uint16_t reinit_count[4]; +static float voltages[4]; +static float currents[4]; +static float powers[4]; + + +/* +* Log single floating point Number +*/ + +static void _debug_fval(const char *str, float fval, uint8_t prec = 4 ) +{ + char fstr[32]; + dtostrfd(fval, prec, fstr); + AddLog_P2( LOG_LEVEL_NONE, PSTR("%s: %s"), str, fstr ); +} + + +/* +* Convert 16 bit repesentation of shunt resisance to 32 bit micro ohms by looking at the msb range bit. +* If the msb is 1, the LSB's define the number of milli ohms. (Maximum shunt resistor value 32.767 ohms) +* If the msb is 0, the LSB's define the number of micro ohms. (Maximum shunt resistor value 0.032767 ohms) +*/ + +static uint32_t _expand_r_shunt(uint16_t compact_r_shunt) +{ + + uint32_t r_shunt_uohms = (compact_r_shunt & 0x8000) ? + (((uint32_t)(compact_r_shunt & 0x7FFF)) * 1000ul) : + (compact_r_shunt & 0x7FFF); + return r_shunt_uohms; +} + +/* +* Set calibration value for Ina226 +*/ + +void Ina226SetCalibration(uint8_t slaveIndex) +{ + +Ina226SlaveInfo_t *si = slaveInfo + slaveIndex; + +I2cWrite16( si->address, INA226_REG_CALIBRATION, si->calibrationValue); + +} + + +/* +* Test for presence of an Ina226 +*/ + +bool Ina226TestPresence(uint8_t device) +{ + + // Read config + + uint16_t config = I2cRead16( slaveInfo[device].address, INA226_REG_CONFIG ); + //AddLog_P2( LOG_LEVEL_NONE, PSTR("Config register %04x" ), config); + + if (config != slaveInfo[device].config) + return false; + + return true; + +} + + +/* +* Initialize INA226 devices +*/ + +void Ina226Init() +{ + + + uint32_t i; + + slavesFound = 0; + + Ina226SlaveInfo_t *p = slaveInfo; + + + //AddLog_P2( LOG_LEVEL_NONE, "Ina226Init"); + AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings)); + + if (!i2c_flg) + AddLog_P2(LOG_LEVEL_DEBUG, "INA226: Initialization failed: No I2C support"); + + + // Clear slave info data + + for (i = 0; i < 4; i++){ + *p = {0}; + } + + //AddLog_P2( LOG_LEVEL_NONE, PSTR("Sizeof Ina226Cfg: %d" ), sizeof(Ina226Cfg)); + + // Detect devices + + for (i = 0; (i < INA226_MAX_ADDRESSES); i++){ + uint8_t addr = pgm_read_byte(probeAddresses + i); + + // Skip device probing if the full scale current is zero + + //AddLog_P2( LOG_LEVEL_NONE, "fs_i[%d]: %d", i, Settings.ina226_i_fs[i]); + if (!Settings.ina226_i_fs[i]) + continue; + + + //AddLog_P2( LOG_LEVEL_NONE, PSTR("INA226 trying slave address %02x" ), addr ); + + // Try Resetting the device + + if (!I2cWrite16( addr, INA226_REG_CONFIG, INA226_CONFIG_RESET)){ + + AddLog_P2( LOG_LEVEL_DEBUG, "No INA226 at address: %02X", addr); + continue; // No device + } + + // Read config + + uint16_t config = I2cRead16( addr, INA226_REG_CONFIG ); + //AddLog_P2( LOG_LEVEL_NONE, PSTR("INA226 Config register %04x" ), config); + + if (INA226_RES_CONFIG != config) + continue; + + + config = INA226_DEF_CONFIG; // Fixme + + // Set the default configuration + if (!I2cWrite16( addr, INA226_REG_CONFIG, config)) + continue; // No device + + // store data in slave info struct. + + p = &slaveInfo[i]; + // Address + p->address = addr; + // Configuration + p->config = config; + // Full scale current in tenths of an amp + //AddLog_P2( LOG_LEVEL_NONE, "Full Scale I in tenths of an amp: %u", Settings.ina226_i_fs[i]); + p->i_lsb = (((float) Settings.ina226_i_fs[i])/10.0f)/32768.0f; + //_debug_fval("i_lsb: %s", p->i_lsb, 7); + + // Get shunt resistor value in micro ohms + uint32_t r_shunt_uohms = _expand_r_shunt(Settings.ina226_r_shunt[i]); + //AddLog_P2( LOG_LEVEL_NONE, "Shunt R in micro-ohms: %u", r_shunt_uohms); + + + p->calibrationValue = ((uint16_t) (0.00512/(p->i_lsb * r_shunt_uohms/1000000.0f))); + // Device present + p->present = true; + //AddLog_P2( LOG_LEVEL_NONE, "INA226 Device %d calibration value: %04X", i, p->calibrationValue); + + Ina226SetCalibration(i); + + //AddLog_P2( LOG_LEVEL_NONE, S_LOG_I2C_FOUND_AT, Ina226Str, addr ); + slavesFound++; + + } +} + +/* +* Read the bus voltage, and return it as a float +*/ + +float Ina226ReadBus_v(uint8_t device) +{ + uint8_t addr = slaveInfo[device].address; + int16_t reg_bus_v = I2cReadS16( addr, INA226_REG_BUSVOLTAGE); + + float result = ((float) reg_bus_v) * 0.00125f; + + return result; + +} + +/* +* Read the shunt current, and return it as a float +*/ + +float Ina226ReadShunt_i(uint8_t device) +{ + uint8_t addr = slaveInfo[device].address; + int16_t reg_shunt_i = I2cReadS16( addr, INA226_REG_CURRENT); + + float result = ((float) reg_shunt_i) * slaveInfo[device].i_lsb; + + return result; +} + +/* +* Read the calculated power +*/ + +float Ina226ReadPower_w(uint8_t device) +{ + uint8_t addr = slaveInfo[device].address; + int16_t reg_shunt_i = I2cReadS16( addr, INA226_REG_POWER); + + float result = ((float) reg_shunt_i) * (slaveInfo[device].i_lsb * 25.0); + + return result; +} + + +/* +* Read voltage, shunt voltage, current, and power registerd for a given device +*/ + +void Ina226Read(uint8_t device) +{ + //AddLog_P2( LOG_LEVEL_NONE, "Ina226Read"); + voltages[device] = Ina226ReadBus_v(device); + currents[device] = Ina226ReadShunt_i(device); + powers[device] = Ina226ReadPower_w(device); + //AddLog_P2( LOG_LEVEL_NONE, "INA226 Device %d", device ); + //_debug_fval("Voltage", voltages[device]); + //_debug_fval("Current", currents[device]); + //_debug_fval("Power", powers[device]); +} + +/* +* Poll sensors, and chack for sensor presence +*/ + +void Ina226EverySecond() +{ + //AddLog_P2( LOG_LEVEL_NONE, "Ina226EverySecond"); + for (uint8_t device = 0; device < INA226_MAX_ADDRESSES; device++){ + // If there are slaves, and the device was present, and the device still is present, read its registers + if (slavesFound && slaveInfo[device].present && Ina226TestPresence(device)){ + Ina226Read(device); + } + else { + powers[device] = currents[device] = voltages[device] = 0.0f; + // If device was present, note that it dropped off here + //if(slaveInfo[device].present){ + //reinit_count[device]++; + //AddLog_P2( LOG_LEVEL_DEBUG, "INA226 Device %d dropped off, count: %d", device, reinit_count[device]); + //} + // Device no longer present + slaveInfo[device].present = false; + } + } +} + +/* +* Decode a sensor command and act on it +*/ + +bool Ina226CommandSensor() +{ + bool serviced = true; + bool show_config = false; + char param_str[64]; + char *cp, *params[4]; + uint8_t i, param_count, device, p1 = XdrvMailbox.payload; + uint32_t r_shunt_uohms; + uint16_t compact_r_shunt_uohms; + //AddLog_P2( LOG_LEVEL_NONE, "Command received: %d", XdrvMailbox.payload); + //AddLog_P2( LOG_LEVEL_NONE, "Command data received: %s", XdrvMailbox.data); + + // Make a copy of the data and add another terminator + + if (XdrvMailbox.data_len > 62){ + return false; + } + + strncpy(param_str, XdrvMailbox.data, XdrvMailbox.data_len + 1); + param_str[XdrvMailbox.data_len] = 0; + + // Build parameter substrings (this should really be a helper function in support_command.ino) + for (cp = param_str, i = 0, param_count = 0; *cp && (i < XdrvMailbox.data_len + 1) && (param_count <= 3); i++) + if (param_str[i] == ' ' || param_str[i] == ',' || param_str[i] == 0){ + param_str[i] = 0; + params[param_count] = cp; + //AddLog_P2( LOG_LEVEL_NONE, "INA226 Command parameter: %d, value: %s", param_count, params[param_count]); + param_count++; + cp = param_str + i + 1; + } + + + if (p1 < 10 || p1 >= 50){ + // Device-less commands + switch (p1){ + case 1: // Rerun init + Ina226Init(); + Response_P(PSTR("{\"Sensor54-Command-Result\":{\"SlavesFound\":%d}}"),slavesFound); + break; + + case 2: // Save and restart + restart_flag = 2; + Response_P(PSTR("{\"Sensor54-Command-Result\":{\"Restart_flag\":%d}}"),restart_flag); + break; + + default: + serviced = false; + } + } + else if (p1 < 50){ + // Commands 10-49 tied to a particular device + device = (p1 / 10) - 1; // Leading Tens digit is device number {1-4} + switch (p1 % 10){ + case 0: // Show config + show_config = true; + break; + + case 1: // Set compacted shunt resistance from user input in ohms + r_shunt_uohms = (uint32_t) ((CharToFloat(params[1])) * 1000000.0f); + + + //AddLog_P2( LOG_LEVEL_NONE, "r_shunt_uohms: %d", r_shunt_uohms); + if (r_shunt_uohms > 32767){ + uint32_t r_shunt_mohms = r_shunt_uohms/1000UL; + Settings.ina226_r_shunt[device] = (uint16_t) (r_shunt_mohms | 0x8000); + } + else + Settings.ina226_r_shunt[device] = (uint16_t) r_shunt_uohms; + + //AddLog_P2( LOG_LEVEL_NONE, "r_shunt_compacted: %04X", Settings.ina226_r_shunt[device]); + show_config = true; + break; + + case 2: // Set full scale current in tenths of amps from user input in Amps + Settings.ina226_i_fs[device] = (uint16_t) ((CharToFloat(params[1])) * 10.0f); + //AddLog_P2( LOG_LEVEL_NONE, "i_fs: %d", Settings.ina226_i_fs[device]); + show_config = true; + break; + + + default: + serviced = false; + break; + } + } + else + serviced = false; + + if (show_config) { + char shunt_r_str[16]; + char fs_i_str[16]; + + // Shunt resistance is stored in EEPROM in microohms. Convert to ohms + r_shunt_uohms = _expand_r_shunt(Settings.ina226_r_shunt[device]); + dtostrfd(((float)r_shunt_uohms)/1000000.0f, 6, shunt_r_str); + // Full scale current is stored in EEPROM in tenths of an amp. Convert to amps. + dtostrfd(((float)Settings.ina226_i_fs[device])/10.0f, 1, fs_i_str); + // Send json response + Response_P(PSTR("{\"Sensor54-device-settings-%d\":{\"SHUNT_R\":%s,\"FS_I\":%s}}"), + device + 1, shunt_r_str, fs_i_str); + } + + return serviced; +} + +/* +* Show data gathered from INA226 devices +*/ + +#ifdef USE_WEBSERVER +const char HTTP_SNS_INA226_DATA[] PROGMEM = + "{s}%s " D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}" + "{s}%s " D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}" + "{s}%s " D_POWERUSAGE "{m}%s " D_UNIT_WATT "{e}"; +#endif // USE_WEBSERVER + +void Ina226Show(bool json) +{ + int i, num_found; + for (num_found = 0, i = 0; i < INA226_MAX_ADDRESSES; i++) { + // Skip uninstalled sensors + if (!slaveInfo[i].present) + continue; + + num_found++; + + char voltage[16]; + dtostrfd(voltages[i], Settings.flag2.voltage_resolution, voltage); + char current[16]; + dtostrfd(currents[i], Settings.flag2.current_resolution, current); + char power[16]; + dtostrfd(powers[i], Settings.flag2.wattage_resolution, power); + char name[16]; + snprintf_P(name, sizeof(name), PSTR("INA226%c%d"),IndexSeparator(), i + 1); + + + if (json) { + ResponseAppend_P(PSTR(",\"%s\":{\"Id\":%02x,\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s,\"" D_JSON_POWERUSAGE "\":%s}"), + name, i, voltage, current, power); +#ifdef USE_DOMOTICZ + if (0 == tele_period) { + DomoticzSensor(DZ_VOLTAGE, voltage); + DomoticzSensor(DZ_CURRENT, current); + } +#endif // USE_DOMOTICZ +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_SNS_INA226_DATA, name, voltage, name, current, name, power); +#endif // USE_WEBSERVER) + } + + } + +} + + +/** + * The callback function Xsns_57() interfaces Tasmota with the sensor driver. + * + * It provides the Tasmota callback IDs. + * + * @param byte callback_id Tasmota function ID. + * @return bool Return value. + * @pre None. + * @post None. + * + */ +bool Xsns54(byte callback_id) { + + // Set return value to `false` + bool result = false; + + // Check if I2C interface mode is enabled + if(i2c_flg) { + + // Check which callback ID is called by Tasmota + switch (callback_id) { + case FUNC_EVERY_SECOND: + Ina226EverySecond(); + break; + case FUNC_INIT: + Ina226Init(); + break; + case FUNC_JSON_APPEND: + Ina226Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + Ina226Show(0); + break; +#endif // USE_WEBSERVER + case FUNC_COMMAND_SENSOR: + if (XSNS_54 == XdrvMailbox.index) { + result = Ina226CommandSensor(); + } + break; + } + } // if(i2c_flg) + // Return boolean result + return result; +} + +#endif // USE_INA226 +#endif // USE_I2C diff --git a/tools/decode-config.py b/tools/decode-config.py index 67e21b3a6..f04854acd 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -VER = '2.3.0032' +VER = '2.3.0033' """ decode-config.py - Backup/Restore Sonoff-Tasmota configuration data @@ -984,7 +984,22 @@ Setting_6_6_0_9.update ({ 'sbaudrate': ('