diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 580eb5e132..f5849a2f13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: - python-version: '3.x' + python-version: '3.11' - uses: actions/cache@v3 with: path: ~/.cache/pip @@ -86,6 +86,7 @@ jobs: sudo apt-get update sudo apt install binutils build-essential libffi-dev libgit2-dev pip3 install --upgrade pip + pip install wheel pip install -r requirements.txt platformio update - name: Build and archive diff --git a/dist/Release_notes.txt b/dist/Release_notes.txt index 66f5f6e315..8289ad983d 100644 --- a/dist/Release_notes.txt +++ b/dist/Release_notes.txt @@ -1,3 +1,115 @@ +------------------------------------------------- +Changes in release mega-20231130 (since mega-20231013) +------------------------------------------------- + +Release date: Thu Nov 30 08:11:17 PM CET 2023 + +Fabio Ancona (3): + Update Custom-sample.h with missing Plugins and update description + Update Custom-sample.h after review + Details supported hardware + +TD-er (18): + [WiFi] Fix force B/G mode on ESP8266 + [WiFi] Limit WiFi speed to HT20 for 802.11n mode on ESP32 + [Build] Fix compile error when using default Custom.h (#4870) + [CDN URL] Add default CDN url with latest tag when no pygit2 installed + [WiFi] Fix connect to Hidden SSID on Mikrotik AP (#4885) + [WiFi] Only connect using BSSID when BSSID is available + [ESP32 WiFi] Fix reconnect issue after WIFI_REASON_AUTH_EXPIRE + [FactoryReset] Store settings to keep in ESP32 NVS storage + [Custom CDN] Move Custom CDN URL to config.dat + [Custom CDN] Move position of where Custom CDN URL is stored in settings + [Factory Reset] Use NVS stored defaults on reset + [Custom CDN] Fix storing empty CDN url. + [Factory Reset] Store WiFi/Eth config in NVS + [Factory Reset] Store log/console settings in NVS + [Custom CDN] Add checkbox to store Custom CDN to NVS + [Custom.h] Update Custom-sample.h with new CUSTOM_BUILD_CDN_URL + [Factory Reset] Add new flag to NVS for slow connect to hidden SSID + [ESP8266 build] Set all ESP8266 'normal' builds to use CDN for CSS/JS + +Ton Huisman (68): + [Lib] HeatpumpIR update to 1.0.23 + [Lib] HeatpumpIR Add compatibility with ESP32 Arduino 3.0/IDF 5.1.x + [P023] Bugfix: Template parsing was overwriting the template + [P159] Add LD2410 Radar presence detection + [P023] Minor performance improvement + [P159] Remove copy/paste evidence :-D + [P159] Many improvements, add/update settings for sensitivity + [P159] Fix compilation on LIMIT_BUILD_SIZE builds + [P159] Small improvements + [P159] Small improvements + [P159] Add command for sensor factoryreset + [Lib] LD2410: Fix bug (-1 for uint), add undocumented OutputPinState value + [P159] Add OutputPinState option after AmbientLight option (breaking change!) + [P159] Minor change to determine how that may influence the build + [NEOPIXEL] Add NeoPixelBus_wrapper and implement in NeoPixel plugins + [Lib] Adjust Adafruit_NeoMatrix to use NeoPixelBus_wrapper + [ESP-IDF5.1] Update NeoPixelBus with Tasmota's patches for ESP-IDF5.1 + [NeoPixel] Add changelogs for applying NeoPixelBus_wrapper library + [Build] Fix pygit2 version + [Build] Fix pygit2 version + [Build] Restore pygit2 version + [Build] Try older/current version of pip + [Build] Explicit version of libgit2 + [Build] Undo changes + [ESP-IDF5.1] Fix build issue on older IDF based builds + [Neopixel] Fixes and improvements + [Build] Freeze pip dependencies + [Build] Undo changes + [Build] Try fix failing pygit2 install + [Build] Try older Python version + [Neopixel] Fix fall-through return value + [Build] Fix some cherry-pick diffs + [Build] Freeze Python to 3.11 to fix pygit2 build issue + [P159] Add Gate0 energy values that where missing Add GetConfig support for fetching all available values Add ld2410,logall command for dumping all values in the log (INFO level) Code improvements + [NeopixelWrapper] Code optimization + [P021] Set Hysteresis value via config command + [P021] Update documentation + [Build] Freeze Python version to avoid build issue with pygit2 + [Build] Freeze Python version on 3.11 so pygit2 will run as intended + [P021] Change commands SetHysteresis and GetHysteresis for consistency + [Lib] LD2410: Read all data that can be read in 5 msec, add errorcount and data_valid checks + [P159] Rework processing, now near-instant response Add GetConfig support for sensitivity per gate values + [Lib] LD2410: Reformat source (nearly all is changed!) Replace yield() by delay(0) + [P159] Fix wrong use of F(""), should be EMPTY_STRING + [Lib] IRremoteESP8266 update to v2.8.6, with ESPEasy patches applied - Disable some (more) IR protocols to make 1M build fit - Add IDF 5.x compatibility + [Lib] Adafruit_NeoMatrix: Fix includes + [Lib] Remove Adafruit_NeoPixel from repo + [P131] Fix variable initialization, call begin() to start the NeoPixels + [P041] Uncrustify source, minor improvements + [P042] Fix initializations to avoid crash at start, minor improvements + [P070] Minor improvements + [Lib] Update library.properties for local copy of Adafruit_NeoMatrix + [Docs] Updates and corrections Nov. 2023 + [Docs] Updates and corrections Nov. 2023 + [P159] Add documentation + [P159] Update EasyColorMirror + [P159] Update comments to explicitly name LD2410 + [CDN] Set override url for CDN hosted files + [CDN] Update documentation + [CDN] Code improvements, Add to Provisioning + [CDN] Update documentation + [Provisioning] Split provisioning commands, add fallback for MAX builds, code cleanup + [Provisioning] Update documentation + [CDN] Replace system variables in url, update documentation + [I2C] Add Device flag for 100 kHz-only devices + [I2C] Devices that only support 100 kHz speed + [Bugfix] [P159] Saving settings checkbox failed on ESP8266 + [Docs] Fix some typos Nov. 2023 + +jfmennedy (8): + P093 Mitsubishi HeatPump Add Support for SetRemoteTemperature Resolves P093 - Mitsubishi Heat Pump Add Remote Temperature #4711 + Modify Changelog Order + Help needed here + - Fix float initialisaton, - Fix float comparator, - Still trying t get SetRemoteTemperature working... + -Fix static const uint8_t RemoteTemperature + - Implement remarks from review + Documentation + Documentation Review + + ------------------------------------------------- Changes in release mega-20231013 (since mega-20230930) ------------------------------------------------- diff --git a/docs/source/Config/Config.rst b/docs/source/Config/Config.rst index 6eba783081..eca0117a31 100644 --- a/docs/source/Config/Config.rst +++ b/docs/source/Config/Config.rst @@ -298,3 +298,15 @@ N.B. the maximum possible duration depends on the used core library version and Sleep on connection failure --------------------------- +CDN (Content delivery network) +------------------------------ + +The **Custom CDN URL** can be set to a server url (https preferred, they are downloaded by the browser, **not** by the ESPEasy unit) that hosts *all* files as listed on :ref:`ExternalHostedStaticFiles` (System variables can be used to customize the URL). + +To reduce the build size where possible, some builds fetch the javascript (.js) and .css UI files from an external server, as this is used in the browser only. The default location for this data is the Content Delivery Network (CDN) of ``jsdelivr.net``, where these file are uploaded for specific releases. + +For users that want to host these files in their local network, or if the files on jsdeliver.net have expired, an alternative location for these .js and .css file can be configured. + +Setting this location will **override** the default CDN url, except for your Custom build that may already *have* the CDN url set, then this setting won't be available! + +**Warning**: If an invalid location is set, the UI will be distorted, though should still be usable. diff --git a/docs/source/Controller/C014.rst b/docs/source/Controller/C014.rst index 3fbb1ea15a..fbd62db2a6 100644 --- a/docs/source/Controller/C014.rst +++ b/docs/source/Controller/C014.rst @@ -64,15 +64,15 @@ A home automation server/controller capable talking Homie like openHAB since 2.4 Setup ------------- -- add the Homie **Homie MQTT (Version 4.0.0 dev)** or **Homie MQTT (Version 3.0.1 dev)** controller to your controller lists depending on your build. -- insert your broker address -- and user credentials if necessary -- the publish scheme is fixed to meet the homie requirements to ``homie/%sysname%/%tskname%/%valname%`` -- the subscription scheme can be modified. Current defaults to ``homie/%sysname%/+/+/set`` to reduce incoming traffic to a minimum. Homie only expects messages via the ``homie/%sysname%/%tskname%/%valname%/set`` topic. -- last will topic (LWT) should set to ``homie/%sysname%/$state`` +- Add the Homie **Homie MQTT (Version 4.0.0 dev)** or **Homie MQTT (Version 3.0.1 dev)** controller to your controller lists depending on your build. +- Insert your broker address +- And user credentials if necessary +- The publish scheme is fixed to meet the homie requirements to ``homie/%sysname%/%tskname%/%valname%`` +- The subscription scheme can be modified. Current defaults to ``homie/%sysname%/+/+/set`` to reduce incoming traffic to a minimum. Homie only expects messages via the ``homie/%sysname%/%tskname%/%valname%/set`` topic. +- Last will topic (LWT) should set to ``homie/%sysname%/$state`` - LWT Connect Message to ``ready`` - LWT Disconnect Message to ``lost`` -- save and reboot, best with connected serial monitor or syslog server with debug set to 4 (debug) or greater (alternatively use a MQTT client and subscribe to ``homie/%sysname%/#`` - replace %sysname% by the unit-name shown on the top of the webpage). +- Save and reboot, best with connected serial monitor or syslog server with debug set to 4 (debug) or greater (alternatively use a MQTT client and subscribe to ``homie/%sysname%/#`` - replace %sysname% by the unit-name shown on the top of the webpage). .. image:: C0014_Setup_0.png @@ -93,22 +93,22 @@ The auto-discover information is sent through a big number of messages (usual mo - More devices can be added or (re-)enabled later. - Disable already configured devices (devices without the enabled box ticked will be ignored) - Check with a MQTT client if all messages are sent. The last message sent is ``$nodes`` attribute listing minimum the ``SYSTEM`` node if no other devices are enabled. -- check your WIFI connection. Perhaps bring your device nearer to your access point. (only necessary during the setup process because the messages should be stored by the broker) -- check via syslog or serial console if the messages are sent successful (you normaly can't see the log output in the web log) -- use the `mqqt-forget `_ tool to delete unused retained messages from your broker via wildcards +- Check your WIFI connection. Perhaps bring your device nearer to your access point. (only necessary during the setup process because the messages should be stored by the broker) +- Check via syslog or serial console if the messages are sent successful (you normaly can't see the log output in the web log) +- Use the `mqqt-forget `_ tool to delete unused retained messages from your broker via wildcards Features -------- The controller currently supports these features -- send auto-discover nodes for all sending and enabled plug-ins to ``homie/%unitName%/%deviceName%/%valueName%`` -- receive commands through the ``homie/%unitName%/SYSTEM/cmd/set`` topic. -- switch GPIOs through ``homie/%unitName%/SYSTEM/gpio#/set`` topic. The GPIO port must be set to **default low** or **default high** in the hardware tab to be included during auto-discover. -- send updates of GPIO ports to ``homie/%unitName%/SYSTEM/gpio#`` regardless from where the change is triggered (to be fully tested). -- in conjunction with :ref:`P086_page` actuators can be used according to the Homie convetion using rules. -- receive values for dummy devices via ``homie/%unitName%/%dummyDeviceName%/%valueName%/set``. From there the values can be processed further by using rules. -- handle ``$state`` attribute (for complete list see attribute table below) +- Send auto-discover nodes for all sending and enabled plug-ins to ``homie/%unitName%/%deviceName%/%valueName%`` +- Receive commands through the ``homie/%unitName%/SYSTEM/cmd/set`` topic. +- Switch GPIOs through ``homie/%unitName%/SYSTEM/gpio#/set`` topic. The GPIO port must be set to **default low** or **default high** in the hardware tab to be included during auto-discover. +- Send updates of GPIO ports to ``homie/%unitName%/SYSTEM/gpio#`` regardless from where the change is triggered (to be fully tested). +- In conjunction with :ref:`P086_page` actuators can be used according to the Homie convetion using rules. +- Receive values for dummy devices via ``homie/%unitName%/%dummyDeviceName%/%valueName%/set``. From there the values can be processed further by using rules. +- Handle ``$state`` attribute (for complete list see attribute table below) - ``init`` during boot process - ``ready`` during normal operation and as a heartbeat every 30sec (to be tested) @@ -117,23 +117,23 @@ The controller currently supports these features - ``lost`` configured as LWT - ``disconnected`` sent to the old topic if the unit name changes to inform that the old topic is not valid any more. Auto-discover messages are sent automagically to the new topics afterwards. -- acknowledge received message by the ``homie/%unitName%/%deviceName%/%valueName%/set`` topic to the corresponding value ``homie/%unitName%/%deviceName%/%valueName%`` even if the value was changed by a different source like HTTP or rule to keep the state in your home automation system allays up to date. (Needs further testing) +- Acknowledge received message by the ``homie/%unitName%/%deviceName%/%valueName%/set`` topic to the corresponding value ``homie/%unitName%/%deviceName%/%valueName%`` even if the value was changed by a different source like HTTP or rule to keep the state in your home automation system allays up to date. (Needs further testing) Future / planned features ------------------------- -- a special Homie Plugin is in devolopment to pass ``\set`` messages to rules for further handling. Here ``$datatype`` and ``$format`` attributes for ``$setable`` values can be specified there. This will enable ESPEasy to handle direct inputs to plug-ins like dimmers (%,0:100), colors (RGB & HSV, 255,255,255), enum devices like remote controls (Play, Pause, Vol+, Vol-, ...). :yellow:`Testing` see :ref:`P086_page` +- A special Homie Plugin is in devolopment to pass ``/set`` messages to rules for further handling. Here ``$datatype`` and ``$format`` attributes for ``$settable`` values can be specified there. This will enable ESPEasy to handle direct inputs to plug-ins like dimmers (%,0:100), colors (RGB & HSV, 255,255,255), enum devices like remote controls (Play, Pause, Vol+, Vol-, ...). See :ref:`P086_page` in :yellow:`Collection A` builds - Further in field testing with different MQTT brokers and home automation systems. - Handling units via the ``$unit`` attribute. As ESPEasy is currenty "unitless" this needs a global concept within ESPEasy -- Handling ``$datatype`` attribute. Currenly all values (except cmd and gpio) are defined as ``float``. :yellow:`Testing` see :ref:`P086_page` +- Handling ``$datatype`` attribute. Currenly all values (except cmd and gpio) are defined as ``float``. See :ref:`P086_page` in :yellow:`Collection A` builds - Prepare some "working examples". Under the hood -------------- -Auto-dicover information is sent by several $attributes +Auto-discover information is sent by several ``$attributes`` -currently the following attributes will be sent during boot +Currently the following attributes will be sent during boot Unit (Device) attributes ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/Controller/C014_node_attributes.repl b/docs/source/Controller/C014_node_attributes.repl index fc5a7af708..b8b93d9538 100644 --- a/docs/source/Controller/C014_node_attributes.repl +++ b/docs/source/Controller/C014_node_attributes.repl @@ -4,4 +4,4 @@ "``$name``","Friendly name of the Node","SYSTEM", "YES",":green:`required`", "YES",":green:`required`" "``$type``","Type of the node","System commands", "YES",":green:`required`", "YES",":green:`required`" - "``$properties``","Exposed properties. Separated by , for multiple ones.","value1,value2", "YES",":green:`required`", "YES",":green:`required`" + "``$properties``","Exposed properties. Separated by ``,`` for multiple properties.","value1,value2", "YES",":green:`required`", "YES",":green:`required`" diff --git a/docs/source/Plugin/P021.rst b/docs/source/Plugin/P021.rst index 48d9f5fdea..d89adb11ef 100644 --- a/docs/source/Plugin/P021.rst +++ b/docs/source/Plugin/P021.rst @@ -91,6 +91,9 @@ Change log .. versionchanged:: 2.0 ... + |added| + 2023-10-28: Set Hysteresis via ``config`` command and get via ``[#GetHysteresis]`` variable. + |added| 2022-08-22: Auto-save interval option. diff --git a/docs/source/Plugin/P021_DeviceConfiguration.png b/docs/source/Plugin/P021_DeviceConfiguration.png index 5810e30062..7bff50072b 100644 Binary files a/docs/source/Plugin/P021_DeviceConfiguration.png and b/docs/source/Plugin/P021_DeviceConfiguration.png differ diff --git a/docs/source/Plugin/P021_commands.repl b/docs/source/Plugin/P021_commands.repl index f8246039a3..40f9f74a58 100644 --- a/docs/source/Plugin/P021_commands.repl +++ b/docs/source/Plugin/P021_commands.repl @@ -13,7 +13,22 @@ Using this command, either from rules, via http or mqtt, the **Set Level** of the plugin can be changed. If the value differs from the currently set value, the settings are saved. " " + ``config,task,,SetHysteresis,`` + + Value: {Any valid numeric (float) value} + + Calculation: {A valid calculation, as can be used in Rules} + + "," + Using this command, either from rules, via http or mqtt, the **Hysteresis** of the plugin can be changed. If the new value differs from the currently set hysteresis, the settings are saved. + " + " ``[#GetLevel]`` "," Not a real command, but this plugin supports the ``GetLevel`` Config function, to retrieve the **Set Value** from the settings, by using the pseudo value ``GetLevel``. " + " + ``[#GetHysteresis]`` + "," + Not a real command, but this plugin supports the ``SetHysteresis`` Config function, to retrieve the **Hysteresis** from the settings, by using the pseudo value ``GetHysteresis``. + " diff --git a/docs/source/Plugin/P093.rst b/docs/source/Plugin/P093.rst index 19dba41dd3..105aad1225 100644 --- a/docs/source/Plugin/P093.rst +++ b/docs/source/Plugin/P093.rst @@ -74,7 +74,7 @@ See: :ref:`SerialHelper_page` Once we hit submit, the plugin will start sending messages through controller, i.e. MQTT with payload: -``{"roomTemperature":25.5,"wideVane":"|","power":"OFF","mode":"COOL","fan":"AUTO","vane":"AUTO","iSee":true,"operating":true,"compressorFrequency":5,"temperature":24.0}`` +``{"roomTemperature":19.5,"wideVane":"|","power":"OFF","mode":"HEAT","fan":"AUTO","vane":"AUTO","iSee":false,"operating":false,"compressorFrequency":2,"temperature":22.0,"remoteTemperature":19.5}`` Message is send every time a change is detected (i.e. one changes settings using IR remote control) and every X seconds, as set in the settings (60 seconds in above screenshot). @@ -127,6 +127,12 @@ Special thanks Change log ---------- +.. versionchanged:: 2023/09/25 + ... + + |added| + Set Remote Temperature. (value > 0: Use external temperature sensor, value = 0: Use internal temperature sensor) + .. versionchanged:: 2021/08/03 ... diff --git a/docs/source/Plugin/P093_commands.repl b/docs/source/Plugin/P093_commands.repl index 4f7a036f09..ce6a14dd60 100644 --- a/docs/source/Plugin/P093_commands.repl +++ b/docs/source/Plugin/P093_commands.repl @@ -32,3 +32,8 @@ "," Value = ``<<``, ``<``, ``|``, ``>``, ``>>``, ``<>`` or ``SWING`` " + " + ``MitsubishiHP,remotetemperature,`` + "," + Value > ``0.0``: Use external temperature sensor, Value = ``0.0``: Use internal temperature sensor. + " diff --git a/docs/source/Plugin/P093_config_values.repl b/docs/source/Plugin/P093_config_values.repl index 23940e3117..cb142f1e69 100644 --- a/docs/source/Plugin/P093_config_values.repl +++ b/docs/source/Plugin/P093_config_values.repl @@ -6,6 +6,7 @@ | ``[#roomTemperature]`` "," | Value as received from the connected device, includes 1 decimal. + | When Remote Temperature is used, received value is rounded to the nearest 0.5 C. " " | ``[#wideVane]`` @@ -52,3 +53,8 @@ "," | Value as received from the connected device, when ``Include AC status`` is enabled. " + " + | ``[#remoteTemperature]`` + "," + | Value as received from the connected device, includes 1 decimal. + " diff --git a/docs/source/Plugin/P159.rst b/docs/source/Plugin/P159.rst new file mode 100644 index 0000000000..70183da070 --- /dev/null +++ b/docs/source/Plugin/P159.rst @@ -0,0 +1,182 @@ +.. include:: ../Plugin/_plugin_substitutions_p15x.repl +.. _P159_page: + +|P159_typename| +================================================== + +|P159_shortinfo| + +Plugin details +-------------- + +Type: |P159_type| + +Name: |P159_name| + +Status: |P159_status| + +GitHub: |P159_github|_ + +Maintainer: |P159_maintainer| + +Used libraries: |P159_usedlibraries| + +Description +----------- + +Detecting (human) presence can be achieved in several ways, like via IR detection sensors, or a light-beam that's interrupted by someone passing. But these sensors have quite some limitations, like limited sensitivity, no information about the distance, or weather a person is there but not moving. + +The limitations of these existing sensors are not applicable when using radar-based presence detection, and since some time, rather affordable radar human-presence detectors are available. These are available with 5 GHz, 10 GHz, 24 GHz and 60 GHz radar frequency transmitter/receiver chips. Because of the accuracy and range, achievable with 24 GHz sensors, these are quite popular, so support has been added to ESPEasy. + +Some examples of these sensors: + +.. image:: P159_ld2410b.png + :width: 250px + :alt: LD2410b with bluetooth support, 35 x 7 mm in size + +LD2410b with bluetooth support, 35 x 7 mm in size + +.. image:: P159_ld2410c.png + :width: 250px + :alt: LD2410c, 22 x 15 mm in size + +LD2410c, 22 x 15 mm in size + +(Images are sourced from AliExpress vendors) + +Configuration +------------- + +.. image:: P159_DeviceConfiguration.png + +* **Name**: Required by ESPEasy, must be unique among the list of available devices/tasks. + +* **Enabled**: The device can be disabled or enabled. When not enabled the device should not use any resources. + +Sensor +^^^^^^ + +See: :ref:`SerialHelper_page` + +For this sensor, only the **Serial port**, and for ESP32 or Software Serial, the GPIO selection options are available. + +.. warning:: The ``SWSerial`` option should better not be used, because of the high speed (256000 baud) that is used for the serial connection! + +Device Settings +^^^^^^^^^^^^^^^ + +* **Engineering mode**: With this option set ``Yes``, when changed the settings will be saved and the page reloaded, several extra Values are made available for selection. When not using the extra values available, **Engineering mode** should best be set to ``No`` to lower the system-load. + +.. image:: P159_EngineeringMode.png + +* *Available options*: **Yes** or **No** (the default). + +* **Generate Events only when changed**: Checking this option prevents sending an event if none of the values has changed on the next **Interval**. + +Output Configuration +^^^^^^^^^^^^^^^^^^^^ + +* **Number Output Values**: Select the number of values that should be available. Default set to ``Quad`` (4). + +.. image:: P159_NumberOutputValues.png + +* Select from **Single** (1) to **Quad** (4). + +After submitting the page, the number of Values will be changed to the selected number. + +* **Value 1** .. **Value 4**: For each Value the desired data can be configured, depending on the setting for **Engineering mode**, the available options are adjusted. + +* Engineering mode = **No**: + +.. image:: P159_ValueOptionsStandard.png + +* Engineering mode = **Yes**: + +.. image:: P159_ValueOptionsEngineering1.png + +.. image:: P159_ValueOptionsEngineering2.png + +Available options: + +* *Presence*: 0 = No presence, 1 = Presence detected +* *Stationairy presence*: 0 = No stationary presence, 1 = Stationary presence detected (Stationairy = non-moving person) +* *Moving presence*: 0 = No moving presence, 1 = Moving presence detected +* *Object distance*: Distance of the detected presence, in cm. +* *Stationary Object distance*: Distance of the detected stationary presence, in cm. +* *Moving Object distance*: Distance of the detected moving presence, in cm. +* *Stationary Object energy*: Energy level of the detected stationary presence, undefined unit, range 0..100. +* *Moving Object energy*: Energy level of the detected moving presence, undefined unit, range 0..100. + +Engineering mode enabled: + +* *Ambient light sensor*: If the unit includes an ambient light sensor, and many do, then this will hold the light level, undefined unit, range 0..255. This is an undocumented setting from the device, only usable on boards that have this sensor installed. +* *Output pin state*: This reflects the **Out** pin, available on most boards. This is an undocumented setting from the device. +* *Stationary Object energy gate 0..8*: 9 selections of the Stationary Object energy level for each 'gate' (the concept of gates is explained below) +* *Moving Object energy gate 0..8*: 9 selections of the Moving Object energy level for each 'gate' + +.. * *Stationary sensitivity gate 0..8*: 9 selections of the configured Stationary sensitivity level for each 'gate' +.. * *Moving sensitivity gate 0..8*: 9 selections of the configured Moving sensitivity level for each 'gate' + +Sensitivity settings +^^^^^^^^^^^^^^^^^^^^ + +Once the task is enabled, and a sensor is connected, extra configuration settings are available, that are disabled by default, and show the current configuration, as read from the sensor. To change any of these settings, the **Modify sensor settings** checkbox must be enabled, and the input fields will be enabled. The settings available are for configuring the idle time, number of active gates and sensitivity per gate. + +A **gate** is an area in view of the sensor. Each gate is aproximately 75 cm distance (sequentially) from the sensor, and the highest active gate-number, default set to the max. value, is 8 (number starts at 0, so there are 9 gates). These active gates can be configured separately for detecting Moving and Stationary objects/persons. The lowest gate-number that can be selected is 2. + +.. image:: P159_SensitivitySettings.png + +By default, the **Modify sensor settings** checkbox is unchecked. + +After checking the checkbox to enabled state, the settings will be available immediately: + +.. image:: P159_SensitivitySettingsEnabled.png + +* **Firmware version**: The version of the firmware installed on the sensor. The version shown in the screenshots is only shown as informational, and not a required value. For the Bluetooth enabled LD2410b sensor, updates for the firmware, when available, can be installed by using the LD2410 Mobile phone app. This firmware update feature is not available from ESPEasy. +* **Modify sensor settings**: Enable the checkbox to change the sensitivity settings, and store these in the sensor when the page is Submitted. +* **Idle seconds**: The number of seconds the *Presence* stays active after presence is removed, can be set here. Default value 5 sec. max. value is 65535 sec. +* **Max. Moving gates**: The number of active gates for detecting Moving presence. Range 2 .. 8. +* **Max. Stationary gates**: The number of active gates for detecting Stationary presence. Range 2 .. 8. +* **Sensitivity, Gate 0 .. 8**: For each type of detection, the sensitivity treshold can be set, range 0 .. 100, where 0 is the most sensitive, and 100 means it won't trigger, as that's the max. value that will be reported. + +For each gate the distance range in meters is also shown. When the highest enabled Gate is less that the default 8, then only up to that gate-number is shown and configurable. + +If the **Modify sensor settings** checkbox is checked when submitting the page, the settings are sent to the sensor, and the sensor will be restarted to activate them. The configured values are persistently stored in the LD2410 sensor. + +Might the configuration not be set correctly, and changing them again doesn't seem to work, then resetting the sensor, by issuing the ``ld2410,factoryreset`` command while the task is enabled and the sensor connected, the factory defaults will be restored. (See the list of supported commands, below.) + +Data Acquisition +^^^^^^^^^^^^^^^^ + +This group of settings, **Single event with all values** and **Send to Controller** settings are standard available configuration items. Send to Controller is only visible when one or more Controllers are configured. + +* **Interval** By default, Interval will be set to 0 sec. as this is optional for this device. The data will be collected and optionally sent to any configured controllers using this interval. For sending the values to the enabled controller(s), the command ``TaskRun,`` can be used. + +Values +^^^^^^ + +The plugin provides user configurable values, where the names will be changed according to the selected sensor value. A formula can be set to recalculate. The number of decimals can be set as desired, and defaults to 0. + +In selected builds, per Value is a **Stats** checkbox available, that when checked, gathers the data and presents recent data in a graph, as described here: :ref:`Task Value Statistics: ` + +Commands available +^^^^^^^^^^^^^^^^^^ + +.. include:: P159_commands.repl + +Get Config Values +^^^^^^^^^^^^^^^^^ + +Get Config Values retrieves values or settings from the sensor or plugin, and can be used in Rules, Display plugins, Formula's etc. The square brackets **are** part of the variable. Replace ```` by the **Name** of the task. + +.. include:: P159_config_values.repl + +Change log +---------- + +.. versionchanged:: 2.0 + ... + + |added| + 2023-11-13 Initial release version. + diff --git a/docs/source/Plugin/P159_DeviceConfiguration.png b/docs/source/Plugin/P159_DeviceConfiguration.png new file mode 100644 index 0000000000..de3570d09f Binary files /dev/null and b/docs/source/Plugin/P159_DeviceConfiguration.png differ diff --git a/docs/source/Plugin/P159_EngineeringMode.png b/docs/source/Plugin/P159_EngineeringMode.png new file mode 100644 index 0000000000..9839a23e03 Binary files /dev/null and b/docs/source/Plugin/P159_EngineeringMode.png differ diff --git a/docs/source/Plugin/P159_NumberOutputValues.png b/docs/source/Plugin/P159_NumberOutputValues.png new file mode 100644 index 0000000000..dc1afd0b30 Binary files /dev/null and b/docs/source/Plugin/P159_NumberOutputValues.png differ diff --git a/docs/source/Plugin/P159_SensitivitySettings.png b/docs/source/Plugin/P159_SensitivitySettings.png new file mode 100644 index 0000000000..02bb76ebfd Binary files /dev/null and b/docs/source/Plugin/P159_SensitivitySettings.png differ diff --git a/docs/source/Plugin/P159_SensitivitySettingsEnabled.png b/docs/source/Plugin/P159_SensitivitySettingsEnabled.png new file mode 100644 index 0000000000..4efc83061d Binary files /dev/null and b/docs/source/Plugin/P159_SensitivitySettingsEnabled.png differ diff --git a/docs/source/Plugin/P159_ValueOptionsEngineering1.png b/docs/source/Plugin/P159_ValueOptionsEngineering1.png new file mode 100644 index 0000000000..d45f280ad8 Binary files /dev/null and b/docs/source/Plugin/P159_ValueOptionsEngineering1.png differ diff --git a/docs/source/Plugin/P159_ValueOptionsEngineering2.png b/docs/source/Plugin/P159_ValueOptionsEngineering2.png new file mode 100644 index 0000000000..4212f115b7 Binary files /dev/null and b/docs/source/Plugin/P159_ValueOptionsEngineering2.png differ diff --git a/docs/source/Plugin/P159_ValueOptionsStandard.png b/docs/source/Plugin/P159_ValueOptionsStandard.png new file mode 100644 index 0000000000..543ce77f20 Binary files /dev/null and b/docs/source/Plugin/P159_ValueOptionsStandard.png differ diff --git a/docs/source/Plugin/P159_commands.repl b/docs/source/Plugin/P159_commands.repl new file mode 100644 index 0000000000..2d97e4ce34 --- /dev/null +++ b/docs/source/Plugin/P159_commands.repl @@ -0,0 +1,14 @@ +.. csv-table:: + :header: "Command Syntax", "Extra information" + :widths: 20, 30 + + " + ``ld2410,factoryreset`` + "," + Sending this command to the task and a sensor is connected, then the sensor will be reset to the factory default settings, and restarted. There are no questions asked or extra arguments to provide. Use with caution of you have carefully configured, f.e. the sensitivity settings. + " + " + ``ld2410,logall`` + "," + This command will send all available sensor values (see below) to the log at INFO level. This can be viewed via an USB serial connection, when the Serial console is enabled, or via another log view, like the Tools/Log page. The minimum log level has to be set to INFO for the values to be shown. + " diff --git a/docs/source/Plugin/P159_config_values.repl b/docs/source/Plugin/P159_config_values.repl new file mode 100644 index 0000000000..82ae3edf72 --- /dev/null +++ b/docs/source/Plugin/P159_config_values.repl @@ -0,0 +1,74 @@ +.. csv-table:: + :header: "Config value", "Information" + :widths: 20, 30 + + " + ``[#Presence]`` + "," + Returns the currently reported Presence state, 0 (no presence) or 1 (presence detected) + " + " + ``[#StatPres]`` + "," + Returns the currently reported Stationary Presence state, 0 (no presence) or 1 (presence detected) + " + " + ``[#MovPres]`` + "," + Returns the currently reported Moving Presence state, 0 (no presence) or 1 (presence detected) + " + " + ``[#Distance]`` + "," + Returns the distance of the detected object from the sensor, in cm. + " + " + ``[#StatDist]`` + "," + Returns the distance of the detected Stationary object from the sensor, in cm. + " + " + ``[#MovDist]`` + "," + Returns the distance of the detected Moving object from the sensor, in cm. + " + " + ``[#StatEnergy]`` + "," + Returns the energy level of the detected Stationary object from the sensor, unknown unit, range 0..100. + " + " + ``[#MovEnergy]`` + "," + Returns the energy level of the detected Moving object from the sensor, unknown unit, range 0..100. + " + " + ``[#AmbLight]`` + "," + Returns the level of the ambient light, when available, unknown unit, range 0..255. + " + " + ``[#OutputPin]`` + "," + Returns the currently reported Output pin state, 0 (no presence) or 1 (presence detected) + " + " + ``[#StatEnergyGate0..8]`` + "," + Returns the energy level of the Stationary object per gate 0..8, unknown unit, value range 0..100. + " + " + ``[#MovEnergyGate0..8]`` + "," + Returns the energy level of the Moving object per gate 0..8, unknown unit, value range 0..100. + " + " + ``[#StatSensGate0..8]`` + "," + Returns the configured sensitivity level of the Stationary object per gate 0..8, unknown unit, value range 0..100. + " + " + ``[#MovSensGate0..8]`` + "," + Returns the configured sensitivity level of the Moving object per gate 0..8, unknown unit, value range 0..100. + " diff --git a/docs/source/Plugin/P159_ld2410b.png b/docs/source/Plugin/P159_ld2410b.png new file mode 100644 index 0000000000..c6372da93b Binary files /dev/null and b/docs/source/Plugin/P159_ld2410b.png differ diff --git a/docs/source/Plugin/P159_ld2410c.png b/docs/source/Plugin/P159_ld2410c.png new file mode 100644 index 0000000000..81d51a5236 Binary files /dev/null and b/docs/source/Plugin/P159_ld2410c.png differ diff --git a/docs/source/Plugin/_Plugin.rst b/docs/source/Plugin/_Plugin.rst index 8a2d89e1d5..ed87fae27e 100644 --- a/docs/source/Plugin/_Plugin.rst +++ b/docs/source/Plugin/_Plugin.rst @@ -385,6 +385,7 @@ There are different released versions of ESP Easy: ":ref:`P152_page`","|P152_status|","P152" ":ref:`P153_page`","|P153_status|","P153" ":ref:`P154_page`","|P154_status|","P154" + ":ref:`P159_page`","|P159_status|","P159" Internal GPIO handling @@ -541,6 +542,11 @@ Power management Plugins: |Plugin_PowerMgt| +Presence +--------- + +Plugins: |Plugin_Presence| + Regulator --------- diff --git a/docs/source/Plugin/_plugin_categories.repl b/docs/source/Plugin/_plugin_categories.repl index bf07197a00..e9b11a450e 100644 --- a/docs/source/Plugin/_plugin_categories.repl +++ b/docs/source/Plugin/_plugin_categories.repl @@ -25,6 +25,7 @@ .. |Plugin_Output| replace:: :ref:`P029_page`, :ref:`P038_page`, :ref:`P041_page`, :ref:`P042_page`, :ref:`P043_page`, :ref:`P070_page`, :ref:`P124_page`, :ref:`P126_page`, :ref:`P128_page`, :ref:`P152_page` .. |Plugin_Position| replace:: :ref:`P082_page`, :ref:`P121_page` .. |Plugin_PowerMgt| replace:: :ref:`P137_page`, :ref:`P138_page` +.. |Plugin_Presence| replace:: :ref:`P159_page` .. |Plugin_Regulator| replace:: :ref:`P021_page` .. |Plugin_RFID| replace:: :ref:`P008_page`, :ref:`P017_page`, :ref:`P040_page`, :ref:`P111_page` .. |Plugin_Switch_input| replace:: :ref:`P001_page`, :ref:`P009_page`, :ref:`P019_page`, :ref:`P059_page`, :ref:`P080_page`, :ref:`P091_page`, :ref:`P097_page`, :ref:`P143_page` diff --git a/docs/source/Plugin/_plugin_substitutions_p15x.repl b/docs/source/Plugin/_plugin_substitutions_p15x.repl index 03e3816ae2..d964183ac6 100644 --- a/docs/source/Plugin/_plugin_substitutions_p15x.repl +++ b/docs/source/Plugin/_plugin_substitutions_p15x.repl @@ -62,3 +62,16 @@ .. |P154_maintainer| replace:: `TD-er` .. |P154_compileinfo| replace:: `.` .. |P154_usedlibraries| replace:: `Adafruit BMP3XX Library` + +.. |P159_name| replace:: :cyan:`LD2410` +.. |P159_type| replace:: :cyan:`Presence` +.. |P159_typename| replace:: :cyan:`Presence - LD2410` +.. |P159_porttype| replace:: `.` +.. |P159_status| replace:: :yellow:`COLLECTION G` +.. |P159_github| replace:: P159_LD2410.ino +.. _P159_github: https://github.com/letscontrolit/ESPEasy/blob/mega/src/_P159_LD2410.ino +.. |P159_usedby| replace:: `.` +.. |P159_shortinfo| replace:: `LD2410 24 GHz Radar human presence detection sensor` +.. |P159_maintainer| replace:: `tonhuisman` +.. |P159_compileinfo| replace:: `.` +.. |P159_usedlibraries| replace:: `ncmreynolds/ld2410, with 'skoona' and ESPEasy specific enhancements` diff --git a/docs/source/Reference/ExternalHostedStaticFiles.rst b/docs/source/Reference/ExternalHostedStaticFiles.rst index 4c85451b5f..01b38cb9d2 100644 --- a/docs/source/Reference/ExternalHostedStaticFiles.rst +++ b/docs/source/Reference/ExternalHostedStaticFiles.rst @@ -1,3 +1,5 @@ +.. _ExternalHostedStaticFiles: + External Hosted Static Files **************************** diff --git a/docs/source/Rules/Rules.rst b/docs/source/Rules/Rules.rst index 6e5471b6a5..4c32e231f1 100644 --- a/docs/source/Rules/Rules.rst +++ b/docs/source/Rules/Rules.rst @@ -267,7 +267,7 @@ The trigger can be an device value being changed: Operator (inequality function) ------------------------------ -Or a inequality function: +Or an inequality function: .. code-block:: none @@ -924,7 +924,7 @@ For example: .. code-block:: none - on DS-1#Temperature do + on DS_1#Temperature do logentry,{substring:0:1:%eventvalue1%} logentry,{substring:1:2:%eventvalue1%} logentry,{substring:2:3:%eventvalue1%} @@ -935,7 +935,7 @@ The output in the log will then be: .. code-block:: none - 1512372 : Info : EVENT: DS-1#Temperature=23.06 + 1512372 : Info : EVENT: DS_1#Temperature=23.06 1512404 : Info : ACT : logentry,2 1512405 : Info : Command: logentry 1512406 : Info : 2 @@ -951,13 +951,13 @@ For example (bit useless example, just for illustrative purposes): .. code-block:: none - on DS-1#Temperature do + on DS_1#Temperature do logentry,{substring:0:2:{strtol:16:{substring:0:2:%eventvalue1%}{substring:3:5:%eventvalue1%}}} endon .. code-block:: none - 221313 : Info : EVENT: DS-1#Temperature=22.13 + 221313 : Info : EVENT: DS_1#Temperature=22.13 221346 : Info : parse_string_commands cmd: substring:0:2:22.13 -> 22 221347 : Info : parse_string_commands cmd: substring:3:5:22.13 -> 13 221348 : Info : parse_string_commands cmd: strtol:16:2213 -> 8723 @@ -1030,14 +1030,14 @@ Example of extracting sub strings from a value and interpreting as if they were .. code-block:: none - on DS-1#Temperature do + on DS_1#Temperature do logentry,{strtol:16:%eventvalue1%} logentry,{strtol:16:{substring:3:5:%eventvalue1%}} endon .. code-block:: none - 1987550 : Info : EVENT: DS-1#Temperature=24.12 + 1987550 : Info : EVENT: DS_1#Temperature=24.12 1987586 : Info : ACT : logentry,36 1987587 : Info : Command: logentry 1987588 : Info : 36 @@ -1163,7 +1163,7 @@ For example: .. code-block:: none - on DS-1#Temperature do + on DS_1#Temperature do logentry,{ord:A} // ASCII value of 'A' logentry,{ord:{substring:2:3:%eventvalue1%}} // ASCII value of 3rd character of %eventvalue1% endon @@ -1171,7 +1171,7 @@ For example: .. code-block:: none - 2982455 : Info : EVENT: DS-1#Temperature=23.12 + 2982455 : Info : EVENT: DS_1#Temperature=23.12 2982487 : Info : ACT : logentry,65 2982488 : Info : Command: logentry 2982489 : Info : 65 @@ -2025,7 +2025,7 @@ For dew point on the 'inside': if %eventvalue1%>49 Publish,%sysname%/DewPoint_INSIDE/°C,[Dew_point#°C2] else - Publish,%sysname%/DewPoint_INSIDE/°C,[Dew_point#°C2]* //This asterix shows that the calculation is not correct due to the humidity being below 50%! + Publish,%sysname%/DewPoint_INSIDE/°C,[Dew_point#°C2]* //This asterisk shows that the calculation is not correct due to the humidity being below 50%! endif endon @@ -2040,12 +2040,11 @@ published a IP number for 30+ seconds the unit is experiencing problems. On System#Boot do //When the ESP boots, do Publish,%sysname%/IP,%ip% - timerSet,1,30 //Set Timer 1 for the next event in 30 seconds + loopTimerSet,1,30 //Set Timer 1 for the next event in 30 seconds, repeating endon On Rules#Timer=1 do //When Timer1 expires, do Publish,%sysname%/IP,%ip% - timerSet,1,30 //Resets the Timer 1 for another 30 seconds endon Custom reports to Domoticz with own IDX @@ -2062,11 +2061,11 @@ just as an example we want to publish these as custom messages with a unique IDX .. code-block:: none on INA219#Amps do - Publish domoticz/in,{"idx":123456,"nvalue":0,"svalue":"%eventvalue1%"} //Own made up IDX 123456 + Publish domoticz/in,'{"idx":123456,"nvalue":0,"svalue":"%eventvalue1%"}' //Own made up IDX 123456 endon on INA219#Watts do - Publish domoticz/in,{"idx":654321,"nvalue":0,"svalue":"%eventvalue1%"} //Own made up IDX 654321 + Publish domoticz/in,'{"idx":654321,"nvalue":0,"svalue":"%eventvalue1%"}' //Own made up IDX 654321 endon @@ -2350,7 +2349,7 @@ Moving average of many values To calculate the moving average of a value over many (several dozens up to 200) measurements, this script has been developed: -.. code:: none +.. code-block:: none on MovingAverage do // %v201% = max elements @@ -2385,7 +2384,7 @@ To calculate the moving average of a value over many (several dozens up to 200) This rule can be used to calculate the moving average for, f.e., a temperature sensor like this: -.. code:: none +.. code-block:: none on bme#temperature do event,MovingAverage=%eventvalue1% // Calculate the moving avg. diff --git a/docs/source/Tools/Tools.rst b/docs/source/Tools/Tools.rst index f934c154f9..8f4a415fac 100644 --- a/docs/source/Tools/Tools.rst +++ b/docs/source/Tools/Tools.rst @@ -155,7 +155,7 @@ All these values are described in great detail in the Advanced section, where th * **Use Last Connected AP from RTC**: ``false`` means the ESPEasy node needs to scan at reboot and cannot reuse the last used connection before the reboot. * **Extra Wait WiFi Connect**: ``true`` means there is an extra wait upto 1000 msec after initiating a connection to an access point. This can be useful when connecting to some FritzBox access points or routers. (Added: 2023/04/05) * **Enable SDK WiFi Auto Reconnect**: ``true`` means the Espressif SDK will automatically attempt a reconnect when a connection is briefly lost. Access points (like TP-Link Omada) with "Band Steering" enabled may trigger a quick disconnect to force nodes to connect on the 5 GHz band. (Added: 2023/04/05) - +* **Hidden SSID Slow Connect**: ``true`` Connect per found hidden SSID to an access point. Needed for some APs like Mikrotik. This may slow down connecting to the AP significantly. (Added: 2023/11/20) @@ -759,6 +759,18 @@ This will act much faster on these disconnect events. However it also seems to s Whenever ESPEasy calls for a disconnect, or the disconnect takes longer than such a very brief disconnect initiated by the Band Steering algorithm of the access point, ESPEasy will turn off the WiFi and turn it on again as if "Restart WiFi Lost Conn" was enabled. +Hidden SSID Slow Connect +^^^^^^^^^^^^^^^^^^^^^^^^ + +Added: 2023-11-20 + +Some access points with hidden SSID do not react to a broadcast connect attempt with a given SSID. +For example Mikrotik routers and access points only allow connecting to a hidden SSID when specifically addressed. +This may cause a significant slow down connecting to a hidden AP when there are lots of hidden access points with a relative strong signal. + +This is enabled by default. + + Show JSON ========= @@ -1043,20 +1055,73 @@ See the ``Custom-sample.h`` file for some examples. Allow Fetch by Command ---------------------- -This checkbox allows provisioning via commands. -These commands are not restricted, so they can also be given via HTTP or MQTT. +This list of checkboxes per file allows provisioning via commands. +These ``Provision*`` commands are not restricted, so they can also be given via HTTP or MQTT. However, they can only be executed when: -* Allow Fetch by Command is enabled -* the file to download is checked +* the file at Allow Fetch by Command is checked +* the file at Files to Download is *also* checked * URL (+ optional credentials) is stored The commands are: +Changed: 2023-11-18: Single-word commands split into 2 words: ``Provision,[,]`` + +* ``Provision,Config`` Fetch ``config.dat`` +* ``Provision,Security`` Fetch ``security.dat`` +* ``Provision,Notification`` Fetch ``notification.dat`` +* ``Provision,Provision`` Fetch ``provisioning.dat`` +* ``Provision,Rules,1`` Fetch ``rules1.txt`` +* ``Provision,CustomCdnUrl`` Fetch ``customcdnurl.dat`` (When the Custom CDN Url feature is included in the build.) + +* ``Provision,Firmware,`` Fetch and install ``FirmwareBinary.bin`` on the unit + +Once the Firmware download & install is finished the outcome is completed by a generated event (gets the download filename as an argument): + +* ``ProvisionFirmware#Success=`` When download and install where succesfull +* ``ProvisionFirmware#Failed=`` When something went wrong during download or install + +These events can be handled in rules, an provisioning support script could look like this: + +.. code-block:: none + + On updateSettings Do + provision,provision + provision,config + Endon + + On updateCredentials Do + provision,security + Endon + + On updateRules Do + provision,rules,1 + provision,rules,2 + provision,rules,3 + Endon + + On updateRulesSettings Do + AsyncEvent,updateSettings + AsyncEvent,updateRules + Reboot + Endon + + // e.g. + // event,PerformFirmwareUpdate=firmware_max_ESP32_16M8M_LittleFS.bin + On PerformFirmwareUpdate=* Do + pwm,2,100,0,8 + provision,firmware,%eventvalue1% + Endon + + On provisionfirmware#success=* Do + gpio,2,0 + Reboot + Endon + + On provisionfirmware#failure Do + gpio,2,0 + Reboot + Endon + -* ``ProvisionConfig`` Fetch ``config.dat`` -* ``ProvisionSecurity`` Fetch ``security.dat`` -* ``ProvisionNotification`` Fetch ``notification.dat`` -* ``ProvisionProvision`` Fetch ``provisioning.dat`` -* ``ProvisionRules,1`` Fetch ``rules1.txt`` diff --git a/docs/source/Tools/images/SettingsArchive_download1.png b/docs/source/Tools/images/SettingsArchive_download1.png index 0e53d4ac63..e47932e286 100644 Binary files a/docs/source/Tools/images/SettingsArchive_download1.png and b/docs/source/Tools/images/SettingsArchive_download1.png differ diff --git a/docs/source/Tools/images/SettingsArchive_provisioning.png b/docs/source/Tools/images/SettingsArchive_provisioning.png index 662be22a9e..28c5c3ac2f 100644 Binary files a/docs/source/Tools/images/SettingsArchive_provisioning.png and b/docs/source/Tools/images/SettingsArchive_provisioning.png differ diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp index d29cd8ac46..2b0746ee82 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.cpp @@ -48,8 +48,7 @@ */ #include "gamma.h" -#include -#include +#include "Adafruit_NeoMatrix.h" #ifdef __AVR__ #include #elif defined(ESP8266) @@ -73,7 +72,7 @@ // Constructor for single matrix: Adafruit_NeoMatrix::Adafruit_NeoMatrix(int w, int h, uint8_t pin, uint8_t matrixType, neoPixelType ledType) - : Adafruit_GFX(w, h), Adafruit_NeoPixel(w * h, pin, ledType), + : Adafruit_GFX(w, h), NeoPixelBus_wrapper(w * h, pin, ledType), type(matrixType), matrixWidth(w), matrixHeight(h), tilesX(0), tilesY(0), remapFn(NULL) {} @@ -82,7 +81,7 @@ Adafruit_NeoMatrix::Adafruit_NeoMatrix(uint8_t mW, uint8_t mH, uint8_t tX, uint8_t tY, uint8_t pin, uint8_t matrixType, neoPixelType ledType) : Adafruit_GFX(mW * tX, mH * tY), - Adafruit_NeoPixel(mW * mH * tX * tY, pin, ledType), type(matrixType), + NeoPixelBus_wrapper(mW * mH * tX * tY, pin, ledType), type(matrixType), matrixWidth(mW), matrixHeight(mH), tilesX(tX), tilesY(tY), remapFn(NULL) { } diff --git a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h index fe23b55a62..1ad7126a94 100644 --- a/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h +++ b/lib/Adafruit_NeoMatrix/Adafruit_NeoMatrix.h @@ -40,7 +40,9 @@ #include #endif #include -#include +#include + +// 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library // Matrix layout information is passed in the 'matrixType' parameter for // each constructor (the parameter immediately following is the LED type @@ -79,7 +81,7 @@ /** * @brief Class for using NeoPixel matrices with the GFX graphics library. */ -class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel { +class Adafruit_NeoMatrix : public Adafruit_GFX, public NeoPixelBus_wrapper { public: /** diff --git a/lib/Adafruit_NeoMatrix/library.properties b/lib/Adafruit_NeoMatrix/library.properties index 45200b6d2b..1e28aaed39 100644 --- a/lib/Adafruit_NeoMatrix/library.properties +++ b/lib/Adafruit_NeoMatrix/library.properties @@ -1,10 +1,10 @@ -name=Adafruit NeoMatrix +name=Adafruit NeoMatrix via NeoPixelBus version=1.3.0 author=Adafruit maintainer=Adafruit -sentence=Adafruit_GFX-compatible library for NeoPixel grids -paragraph=Adafruit_GFX-compatible library for NeoPixel grids +sentence=Adafruit_GFX-compatible library for NeoPixel grids, adjusted to use NeoPixelBus via NeoPixelBus_wrapper (ESPEasy specific) +paragraph=Adafruit_GFX-compatible library for NeoPixel grids, adjusted to use NeoPixelBus via NeoPixelBus_wrapper (ESPEasy specific) category=Display url=https://github.com/adafruit/Adafruit_NeoMatrix architectures=* -depends=Adafruit NeoPixel, Adafruit GFX Library +depends=NeoPixelBus by Makuna, NeoPixelBus_wrapper, Adafruit GFX Library diff --git a/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md b/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index f0e26146fa..0000000000 --- a/lib/Adafruit_NeoPixel/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,46 +0,0 @@ -Thank you for opening an issue on an Adafruit Arduino library repository. To -improve the speed of resolution please review the following guidelines and -common troubleshooting steps below before creating the issue: - -- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use - the forums at http://forums.adafruit.com to ask questions and troubleshoot why - something isn't working as expected. In many cases the problem is a common issue - that you will more quickly receive help from the forum community. GitHub issues - are meant for known defects in the code. If you don't know if there is a defect - in the code then start with troubleshooting on the forum first. - -- **If following a tutorial or guide be sure you didn't miss a step.** Carefully - check all of the steps and commands to run have been followed. Consult the - forum if you're unsure or have questions about steps in a guide/tutorial. - -- **For Arduino projects check these very common issues to ensure they don't apply**: - - - For uploading sketches or communicating with the board make sure you're using - a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes - very hard to tell the difference between a data and charge cable! Try using the - cable with other devices or swapping to another cable to confirm it is not - the problem. - - - **Be sure you are supplying adequate power to the board.** Check the specs of - your board and plug in an external power supply. In many cases just - plugging a board into your computer is not enough to power it and other - peripherals. - - - **Double check all soldering joints and connections.** Flakey connections - cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. - - - **Ensure you are using an official Arduino or Adafruit board.** We can't - guarantee a clone board will have the same functionality and work as expected - with this code and don't support them. - -If you're sure this issue is a defect in the code and checked the steps above -please fill in the following fields to provide enough troubleshooting information. -You may delete the guideline and text above to just leave the following details: - -- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** - -- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO - VERSION HERE** - -- List the steps to reproduce the problem below (if possible attach a sketch or - copy the sketch code in too): **LIST REPRO STEPS BELOW** diff --git a/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md b/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7b641eb862..0000000000 --- a/lib/Adafruit_NeoPixel/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,26 +0,0 @@ -Thank you for creating a pull request to contribute to Adafruit's GitHub code! -Before you open the request please review the following guidelines and tips to -help it be more easily integrated: - -- **Describe the scope of your change--i.e. what the change does and what parts - of the code were modified.** This will help us understand any risks of integrating - the code. - -- **Describe any known limitations with your change.** For example if the change - doesn't apply to a supported platform of the library please mention it. - -- **Please run any tests or examples that can exercise your modified code.** We - strive to not break users of the code and running tests/examples helps with this - process. - -Thank you again for contributing! We will try to test and integrate the change -as soon as we can, but be aware we have many GitHub repositories to manage and -can't immediately respond to every request. There is no need to bump or check in -on a pull request (it will clutter the discussion of the request). - -Also don't be worried if the request is closed or not integrated--sometimes the -priorities of Adafruit's GitHub code (education, ease of use) might not match the -priorities of the pull request. Don't fret, the open source community thrives on -forks and GitHub makes it easy to keep your changes in a forked repo. - -After reviewing the guidelines above you can delete this text from the pull request. diff --git a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml b/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml deleted file mode 100644 index 2ff3d65477..0000000000 --- a/lib/Adafruit_NeoPixel/.github/workflows/githubci.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Arduino Library CI - -on: [pull_request, push, repository_dispatch] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - uses: actions/checkout@v2 - - uses: actions/checkout@v2 - with: - repository: adafruit/ci-arduino - path: ci - - - name: pre-install - run: bash ci/actions_install.sh - - - name: test platforms - run: python3 ci/build_platform.py main_platforms - - - name: doxygen - env: - GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} - PRETTYNAME : "Adafruit NeoPixel Library" - run: bash ci/doxy_gen_and_deploy.sh diff --git a/lib/Adafruit_NeoPixel/.gitignore b/lib/Adafruit_NeoPixel/.gitignore deleted file mode 100644 index c2a26c0383..0000000000 --- a/lib/Adafruit_NeoPixel/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Our handy .gitignore for automation ease -Doxyfile* -doxygen_sqlite3.db -html diff --git a/lib/Adafruit_NeoPixel/.travis.yml b/lib/Adafruit_NeoPixel/.travis.yml deleted file mode 100644 index f4b943074f..0000000000 --- a/lib/Adafruit_NeoPixel/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: c -sudo: false -before_install: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) -script: - - build_main_platforms - - build_platform trinket -notifications: - email: - on_success: change - on_failure: change diff --git a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp b/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp deleted file mode 100644 index d1a260a777..0000000000 --- a/lib/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp +++ /dev/null @@ -1,3441 +0,0 @@ -/*! - * @file Adafruit_NeoPixel.cpp - * - * @mainpage Arduino Library for driving Adafruit NeoPixel addressable LEDs, - * FLORA RGB Smart Pixels and compatible devicess -- WS2811, WS2812, WS2812B, - * SK6812, etc. - * - * @section intro_sec Introduction - * - * This is the documentation for Adafruit's NeoPixel library for the - * Arduino platform, allowing a broad range of microcontroller boards - * (most AVR boards, many ARM devices, ESP8266 and ESP32, among others) - * to control Adafruit NeoPixels, FLORA RGB Smart Pixels and compatible - * devices -- WS2811, WS2812, WS2812B, SK6812, etc. - * - * Adafruit invests time and resources providing this open source code, - * please support Adafruit and open-source hardware by purchasing products - * from Adafruit! - * - * @section author Author - * - * Written by Phil "Paint Your Dragon" Burgess for Adafruit Industries, - * with contributions by PJRC, Michael Miller and other members of the - * open source community. - * - * @section license License - * - * This file is part of the Adafruit_NeoPixel library. - * - * Adafruit_NeoPixel 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. - * - * Adafruit_NeoPixel 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 - * . - * - */ - -#include "Adafruit_NeoPixel.h" - -#if defined(TARGET_LPC1768) -#include -#endif - -#if defined(NRF52) || defined(NRF52_SERIES) -#include "nrf.h" - -// Interrupt is only disabled if there is no PWM device available -// Note: Adafruit Bluefruit nrf52 does not use this option -//#define NRF52_DISABLE_INT -#endif - -#if defined(ARDUINO_ARCH_NRF52840) -#if defined __has_include -#if __has_include() -#include -#endif -#endif -#endif - -/*! - @brief NeoPixel constructor when length, pin and pixel type are known - at compile-time. - @param n Number of NeoPixels in strand. - @param p Arduino pin number which will drive the NeoPixel data in. - @param t Pixel type -- add together NEO_* constants defined in - Adafruit_NeoPixel.h, for example NEO_GRB+NEO_KHZ800 for - NeoPixels expecting an 800 KHz (vs 400 KHz) data stream - with color bytes expressed in green, red, blue order per - pixel. - @return Adafruit_NeoPixel object. Call the begin() function before use. -*/ -Adafruit_NeoPixel::Adafruit_NeoPixel(uint16_t n, int16_t p, neoPixelType t) - : begun(false), brightness(0), pixels(NULL), endTime(0) { - updateType(t); - updateLength(n); - setPin(p); -#if defined(ARDUINO_ARCH_RP2040) - // Find a free SM on one of the PIO's - sm = pio_claim_unused_sm(pio, false); // don't panic - // Try pio1 if SM not found - if (sm < 0) { - pio = pio1; - sm = pio_claim_unused_sm(pio, true); // panic if no SM is free - } - init = true; -#endif -} - -/*! - @brief "Empty" NeoPixel constructor when length, pin and/or pixel type - are not known at compile-time, and must be initialized later with - updateType(), updateLength() and setPin(). - @return Adafruit_NeoPixel object. Call the begin() function before use. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax (length, pin, - type). -*/ -Adafruit_NeoPixel::Adafruit_NeoPixel() - : -#if defined(NEO_KHZ400) - is800KHz(true), -#endif - begun(false), numLEDs(0), numBytes(0), pin(-1), brightness(0), - pixels(NULL), rOffset(1), gOffset(0), bOffset(2), wOffset(1), endTime(0) { -} - -/*! - @brief Deallocate Adafruit_NeoPixel object, set data pin back to INPUT. -*/ -Adafruit_NeoPixel::~Adafruit_NeoPixel() { - free(pixels); - if (pin >= 0) - pinMode(pin, INPUT); -} - -/*! - @brief Configure NeoPixel pin for output. -*/ -void Adafruit_NeoPixel::begin(void) { - if (pin >= 0) { - pinMode(pin, OUTPUT); - digitalWrite(pin, LOW); - } - begun = true; -} - -/*! - @brief Change the length of a previously-declared Adafruit_NeoPixel - strip object. Old data is deallocated and new data is cleared. - Pin number and pixel format are unchanged. - @param n New length of strip, in pixels. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax (length, pin, - type). -*/ -void Adafruit_NeoPixel::updateLength(uint16_t n) { - free(pixels); // Free existing data (if any) - - // Allocate new data -- note: ALL PIXELS ARE CLEARED - numBytes = n * ((wOffset == rOffset) ? 3 : 4); - if ((pixels = (uint8_t *)malloc(numBytes))) { - memset(pixels, 0, numBytes); - numLEDs = n; - } else { - numLEDs = numBytes = 0; - } -} - -/*! - @brief Change the pixel format of a previously-declared - Adafruit_NeoPixel strip object. If format changes from one of - the RGB variants to an RGBW variant (or RGBW to RGB), the old - data will be deallocated and new data is cleared. Otherwise, - the old data will remain in RAM and is not reordered to the - new format, so it's advisable to follow up with clear(). - @param t Pixel type -- add together NEO_* constants defined in - Adafruit_NeoPixel.h, for example NEO_GRB+NEO_KHZ800 for - NeoPixels expecting an 800 KHz (vs 400 KHz) data stream - with color bytes expressed in green, red, blue order per - pixel. - @note This function is deprecated, here only for old projects that - may still be calling it. New projects should instead use the - 'new' keyword with the first constructor syntax - (length, pin, type). -*/ -void Adafruit_NeoPixel::updateType(neoPixelType t) { - bool oldThreeBytesPerPixel = (wOffset == rOffset); // false if RGBW - - wOffset = (t >> 6) & 0b11; // See notes in header file - rOffset = (t >> 4) & 0b11; // regarding R/G/B/W offsets - gOffset = (t >> 2) & 0b11; - bOffset = t & 0b11; -#if defined(NEO_KHZ400) - is800KHz = (t < 256); // 400 KHz flag is 1<<8 -#endif - - // If bytes-per-pixel has changed (and pixel data was previously - // allocated), re-allocate to new size. Will clear any data. - if (pixels) { - bool newThreeBytesPerPixel = (wOffset == rOffset); - if (newThreeBytesPerPixel != oldThreeBytesPerPixel) - updateLength(numLEDs); - } -} - -// RP2040 specific driver -#if defined(ARDUINO_ARCH_RP2040) -void Adafruit_NeoPixel::rp2040Init(uint8_t pin, bool is800KHz) -{ - uint offset = pio_add_program(pio, &ws2812_program); - - if (is800KHz) - { - // 800kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 800000, 8); - } - else - { - // 400kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 400000, 8); - } -} -// Not a user API -void Adafruit_NeoPixel::rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) -{ - if (this->init) - { - // On first pass through initialise the PIO - rp2040Init(pin, is800KHz); - this->init = false; - } - - while(numBytes--) - // Bits for transmission must be shifted to top 8 bits - pio_sm_put_blocking(pio, sm, ((uint32_t)*pixels++)<< 24); -} - -#endif - -#if defined(ESP8266) -// ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution -extern "C" IRAM_ATTR void espShow(uint8_t pin, uint8_t *pixels, - uint32_t numBytes, boolean is800KHz); -#elif defined(ESP32) -extern "C" void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, - boolean is800KHz); -#endif // ESP8266 - -#if defined(K210) -#define KENDRYTE_K210 1 -#endif - -#if defined(KENDRYTE_K210) -extern "C" void k210Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, - boolean is800KHz); -#endif // KENDRYTE_K210 -/*! - @brief Transmit pixel data in RAM to NeoPixels. - @note On most architectures, interrupts are temporarily disabled in - order to achieve the correct NeoPixel signal timing. This means - that the Arduino millis() and micros() functions, which require - interrupts, will lose small intervals of time whenever this - function is called (about 30 microseconds per RGB pixel, 40 for - RGBW pixels). There's no easy fix for this, but a few - specialized alternative or companion libraries exist that use - very device-specific peripherals to work around it. -*/ -void Adafruit_NeoPixel::show(void) { - - if (!pixels) - return; - - // Data latch = 300+ 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 (!canShow()) - ; - // endTime is a private member (rather than global var) so that multiple - // instances on different pins can be quickly issued in succession (each - // instance doesn't delay the next). - - // In order to make this code runtime-configurable to work with any pin, - // SBI/CBI instructions are eschewed in favor of full PORT writes via the - // OUT or ST instructions. It relies on two facts: that peripheral - // functions (such as PWM) take precedence on output pins, so our PORT- - // wide writes won't interfere, and that interrupts are globally disabled - // while data is being issued to the LEDs, so no other code will be - // accessing the PORT. The code takes an initial 'snapshot' of the PORT - // state, computes 'pin high' and 'pin low' values, and writes these back - // to the PORT register as needed. - - // NRF52 may use PWM + DMA (if available), may not need to disable interrupt - // ESP32 may not disable interrupts because espShow() uses RMT which tries to acquire locks -#if !(defined(NRF52) || defined(NRF52_SERIES) || defined(ESP32)) - noInterrupts(); // Need 100% focus on instruction timing -#endif - -#if defined(__AVR__) - // AVR MCUs -- ATmega & ATtiny (no XMEGA) --------------------------------- - - volatile uint16_t i = numBytes; // Loop counter - volatile uint8_t *ptr = pixels, // Pointer to next byte - b = *ptr++, // Current byte value - hi, // PORT w/output bit set high - lo; // PORT w/output bit set low - - // Hand-tuned assembly code issues data to the LED drivers at a specific - // rate. There's separate code for different CPU speeds (8, 12, 16 MHz) - // for both the WS2811 (400 KHz) and WS2812 (800 KHz) drivers. The - // datastream timing for the LED drivers allows a little wiggle room each - // way (listed in the datasheets), so the conditions for compiling each - // case are set up for a range of frequencies rather than just the exact - // 8, 12 or 16 MHz values, permitting use with some close-but-not-spot-on - // devices (e.g. 16.5 MHz DigiSpark). The ranges were arrived at based - // on the datasheet figures and have not been extensively tested outside - // the canonical 8/12/16 MHz speeds; there's no guarantee these will work - // close to the extremes (or possibly they could be pushed further). - // Keep in mind only one CPU speed case actually gets compiled; the - // resulting program isn't as massive as it might look from source here. - -// 8 MHz(ish) AVR --------------------------------------------------------- -#if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - volatile uint8_t n1, n2 = 0; // First, next bits out - - // Squeezing an 800 KHz stream out of an 8 MHz chip requires code - // specific to each PORT register. - - // 10 instruction clocks per bit: HHxxxxxLLL - // OUT instructions: ^ ^ ^ (T=0,2,7) - - // PORTD OUTPUT ---------------------------------------------------- - -#if defined(PORTD) -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - if (port == &PORTD) { -#endif // defined(PORTB/C/F) - - hi = PORTD | pinMask; - lo = PORTD & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - // Dirty trick: RJMPs proceeding to the next instruction are used - // to delay two clock cycles in one instruction word (rather than - // using two NOPs). This was necessary in order to squeeze the - // loop down to exactly 64 words -- the maximum possible for a - // relative branch. - - asm volatile( - "headD:" - "\n\t" // Clk Pseudocode - // Bit 7: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 6" - "\n\t" // 1-2 if(b & 0x40) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 6: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 5" - "\n\t" // 1-2 if(b & 0x20) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 5: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 4" - "\n\t" // 1-2 if(b & 0x10) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 4: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 3" - "\n\t" // 1-2 if(b & 0x08) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 3: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 2" - "\n\t" // 1-2 if(b & 0x04) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 2: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 1" - "\n\t" // 1-2 if(b & 0x02) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "rjmp .+0" - "\n\t" // 2 nop nop - // Bit 1: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n2] , %[lo]" - "\n\t" // 1 n2 = lo - "out %[port] , %[n1]" - "\n\t" // 1 PORT = n1 - "rjmp .+0" - "\n\t" // 2 nop nop - "sbrc %[byte] , 0" - "\n\t" // 1-2 if(b & 0x01) - "mov %[n2] , %[hi]" - "\n\t" // 0-1 n2 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "sbiw %[count], 1" - "\n\t" // 2 i-- (don't act on Z flag yet) - // Bit 0: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi - "mov %[n1] , %[lo]" - "\n\t" // 1 n1 = lo - "out %[port] , %[n2]" - "\n\t" // 1 PORT = n2 - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 0x80) - "mov %[n1] , %[hi]" - "\n\t" // 0-1 n1 = hi - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo - "brne headD" - "\n" // 2 while(i) (Z flag set above) - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTD)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - } else // other PORT(s) -#endif // defined(PORTB/C/F) -#endif // defined(PORTD) - - // PORTB OUTPUT ---------------------------------------------------- - -#if defined(PORTB) -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - if (port == &PORTB) { -#endif // defined(PORTD/C/F) - - // Same as above, just switched to PORTB and stripped of comments. - hi = PORTB | pinMask; - lo = PORTB & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headB:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headB" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTB)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - } -#endif -#if defined(PORTC) || defined(PORTF) - else -#endif // defined(PORTC/F) -#endif // defined(PORTB) - - // PORTC OUTPUT ---------------------------------------------------- - -#if defined(PORTC) -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - if (port == &PORTC) { -#endif // defined(PORTD/B/F) - - // Same as above, just switched to PORTC and stripped of comments. - hi = PORTC | pinMask; - lo = PORTC & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headC:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headC" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTC)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - } -#endif // defined(PORTD/B/F) -#if defined(PORTF) - else -#endif -#endif // defined(PORTC) - - // PORTF OUTPUT ---------------------------------------------------- - -#if defined(PORTF) -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - if (port == &PORTF) { -#endif // defined(PORTD/B/C) - - hi = PORTF | pinMask; - lo = PORTF & ~pinMask; - n1 = lo; - if (b & 0x80) - n1 = hi; - - asm volatile( - "headF:" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 6" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 5" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 4" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 3" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 2" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 1" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "rjmp .+0" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n2] , %[lo]" - "\n\t" - "out %[port] , %[n1]" - "\n\t" - "rjmp .+0" - "\n\t" - "sbrc %[byte] , 0" - "\n\t" - "mov %[n2] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "mov %[n1] , %[lo]" - "\n\t" - "out %[port] , %[n2]" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[n1] , %[hi]" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "brne headF" - "\n" - : [byte] "+r"(b), [n1] "+r"(n1), [n2] "+r"(n2), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTF)), [ptr] "e"(ptr), [hi] "r"(hi), - [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - } -#endif // defined(PORTD/B/C) -#endif // defined(PORTF) - -#if defined(NEO_KHZ400) - } else { // end 800 KHz, do 400 KHz - - // Timing is more relaxed; unrolling the inner loop for each bit is - // not necessary. Still using the peculiar RJMPs as 2X NOPs, not out - // of need but just to trim the code size down a little. - // This 400-KHz-datastream-on-8-MHz-CPU code is not quite identical - // to the 800-on-16 code later -- the hi/lo timing between WS2811 and - // WS2812 is not simply a 2:1 scale! - - // 20 inst. clocks per bit: HHHHxxxxxxLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,4,10) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head20:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 6) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 7) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 8) - "breq nextbyte20" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 10) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp head20" - "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" - "\n\t" // (T = 10) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 12) - "nop" - "\n\t" // 1 nop (T = 13) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 14) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 16) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 18) - "brne head20" - "\n" // 2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [hi] "r"(hi), [lo] "r"(lo), [ptr] "e"(ptr)); - } -#endif // NEO_KHZ400 - -// 12 MHz(ish) AVR -------------------------------------------------------- -#elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - // In the 12 MHz case, an optimized 800 KHz datastream (no dead time - // between bytes) requires a PORT-specific loop similar to the 8 MHz - // code (but a little more relaxed in this case). - - // 15 instruction clocks per bit: HHHHxxxxxxLLLLL - // OUT instructions: ^ ^ ^ (T=0,4,10) - - volatile uint8_t next; - - // PORTD OUTPUT ---------------------------------------------------- - -#if defined(PORTD) -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - if (port == &PORTD) { -#endif // defined(PORTB/C/F) - - hi = PORTD | pinMask; - lo = PORTD & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Don't "optimize" the OUT calls into the bitTime subroutine; - // we're exploiting the RCALL and RET as 3- and 4-cycle NOPs! - asm volatile("headD:" - "\n\t" // (T = 0) - "out %[port], %[hi]" - "\n\t" // (T = 1) - "rcall bitTimeD" - "\n\t" // Bit 7 (T = 15) - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 6 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 5 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 4 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 3 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 2 - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeD" - "\n\t" // Bit 1 - // Bit 0: - "out %[port] , %[hi]" - "\n\t" // 1 PORT = hi (T = 1) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 3) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 5) - "out %[port] , %[next]" - "\n\t" // 1 PORT = next (T = 6) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 7) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 0x80) (T = 8) - "mov %[next] , %[hi]" - "\n\t" // 0-1 next = hi (T = 9) - "nop" - "\n\t" // 1 (T = 10) - "out %[port] , %[lo]" - "\n\t" // 1 PORT = lo (T = 11) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 13) - "brne headD" - "\n\t" // 2 if(i != 0) -> (next byte) - "rjmp doneD" - "\n\t" - "bitTimeD:" - "\n\t" // nop nop nop (T = 4) - "out %[port], %[next]" - "\n\t" // 1 PORT = next (T = 5) - "mov %[next], %[lo]" - "\n\t" // 1 next = lo (T = 6) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 7) - "sbrc %[byte], 7" - "\n\t" // 1-2 if(b & 0x80) (T = 8) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 9) - "nop" - "\n\t" // 1 (T = 10) - "out %[port], %[lo]" - "\n\t" // 1 PORT = lo (T = 11) - "ret" - "\n\t" // 4 nop nop nop nop (T = 15) - "doneD:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTD)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTB) || defined(PORTC) || defined(PORTF) - } else // other PORT(s) -#endif // defined(PORTB/C/F) -#endif // defined(PORTD) - - // PORTB OUTPUT ---------------------------------------------------- - -#if defined(PORTB) -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - if (port == &PORTB) { -#endif // defined(PORTD/C/F) - - hi = PORTB | pinMask; - lo = PORTB & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTB & stripped of comments - asm volatile("headB:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeB" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headB" - "\n\t" - "rjmp doneB" - "\n\t" - "bitTimeB:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneB:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTB)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTC) || defined(PORTF) - } -#endif -#if defined(PORTC) || defined(PORTF) - else -#endif // defined(PORTC/F) -#endif // defined(PORTB) - - // PORTC OUTPUT ---------------------------------------------------- - -#if defined(PORTC) -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - if (port == &PORTC) { -#endif // defined(PORTD/B/F) - - hi = PORTC | pinMask; - lo = PORTC & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTC & stripped of comments - asm volatile("headC:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headC" - "\n\t" - "rjmp doneC" - "\n\t" - "bitTimeC:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneC:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTC)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTF) - } -#endif // defined(PORTD/B/F) -#if defined(PORTF) - else -#endif -#endif // defined(PORTC) - - // PORTF OUTPUT ---------------------------------------------------- - -#if defined(PORTF) -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - if (port == &PORTF) { -#endif // defined(PORTD/B/C) - - hi = PORTF | pinMask; - lo = PORTF & ~pinMask; - next = lo; - if (b & 0x80) - next = hi; - - // Same as above, just set for PORTF & stripped of comments - asm volatile("headF:" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port], %[hi]" - "\n\t" - "rcall bitTimeC" - "\n\t" - "out %[port] , %[hi]" - "\n\t" - "rjmp .+0" - "\n\t" - "ld %[byte] , %a[ptr]+" - "\n\t" - "out %[port] , %[next]" - "\n\t" - "mov %[next] , %[lo]" - "\n\t" - "sbrc %[byte] , 7" - "\n\t" - "mov %[next] , %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port] , %[lo]" - "\n\t" - "sbiw %[count], 1" - "\n\t" - "brne headF" - "\n\t" - "rjmp doneC" - "\n\t" - "bitTimeC:" - "\n\t" - "out %[port], %[next]" - "\n\t" - "mov %[next], %[lo]" - "\n\t" - "rol %[byte]" - "\n\t" - "sbrc %[byte], 7" - "\n\t" - "mov %[next], %[hi]" - "\n\t" - "nop" - "\n\t" - "out %[port], %[lo]" - "\n\t" - "ret" - "\n\t" - "doneC:" - "\n" - : [byte] "+r"(b), [next] "+r"(next), [count] "+w"(i) - : [port] "I"(_SFR_IO_ADDR(PORTF)), [ptr] "e"(ptr), - [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(PORTD) || defined(PORTB) || defined(PORTC) - } -#endif // defined(PORTD/B/C) -#endif // defined(PORTF) - -#if defined(NEO_KHZ400) - } else { // 400 KHz - - // 30 instruction clocks per bit: HHHHHHxxxxxxxxxLLLLLLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,6,15) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head30:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 6) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 8) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "nop" - "\n\t" // 1 nop (T = 15) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 17) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 19) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 20) - "breq nextbyte30" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 22) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 24) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 26) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 28) - "rjmp head30" - "\n\t" // 2 -> head30 (next bit out) - "nextbyte30:" - "\n\t" // (T = 22) - "nop" - "\n\t" // 1 nop (T = 23) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 24) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 26) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 28) - "brne head30" - "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [hi] "r"(hi), [lo] "r"(lo), [ptr] "e"(ptr)); - } -#endif // NEO_KHZ400 - -// 16 MHz(ish) AVR -------------------------------------------------------- -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - - // WS2811 and WS2812 have different hi/lo duty cycles; this is - // similar but NOT an exact copy of the prior 400-on-8 code. - - // 20 inst. clocks per bit: HHHHHxxxxxxxxLLLLLLL - // ST instructions: ^ ^ ^ (T=0,5,13) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head20:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte], 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 5) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 7) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 8) - "breq nextbyte20" - "\n\t" // 1-2 if(bit == 0) (from dec above) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "nop" - "\n\t" // 1 nop (T = 13) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 15) - "nop" - "\n\t" // 1 nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp head20" - "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" - "\n\t" // (T = 10) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 11) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 13) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 15) - "nop" - "\n\t" // 1 nop (T = 16) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 18) - "brne head20" - "\n" // 2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [ptr] "e"(ptr), [hi] "r"(hi), [lo] "r"(lo)); - -#if defined(NEO_KHZ400) - } else { // 400 KHz - - // The 400 KHz clock on 16 MHz MCU is the most 'relaxed' version. - - // 40 inst. clocks per bit: HHHHHHHHxxxxxxxxxxxxLLLLLLLLLLLLLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,8,20) - - volatile uint8_t next, bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile("head40:" - "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" - "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" - "\n\t" // 1-2 if(b & 128) - "mov %[next] , %[hi]" - "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 6) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 8) - "st %a[port], %[next]" - "\n\t" // 2 PORT = next (T = 10) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 12) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 14) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 16) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 18) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 20) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 22) - "nop" - "\n\t" // 1 nop (T = 23) - "mov %[next] , %[lo]" - "\n\t" // 1 next = lo (T = 24) - "dec %[bit]" - "\n\t" // 1 bit-- (T = 25) - "breq nextbyte40" - "\n\t" // 1-2 if(bit == 0) - "rol %[byte]" - "\n\t" // 1 b <<= 1 (T = 27) - "nop" - "\n\t" // 1 nop (T = 28) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 30) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 32) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 34) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 36) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 38) - "rjmp head40" - "\n\t" // 2 -> head40 (next bit out) - "nextbyte40:" - "\n\t" // (T = 27) - "ldi %[bit] , 8" - "\n\t" // 1 bit = 8 (T = 28) - "ld %[byte] , %a[ptr]+" - "\n\t" // 2 b = *ptr++ (T = 30) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 32) - "st %a[port], %[lo]" - "\n\t" // 2 PORT = lo (T = 34) - "rjmp .+0" - "\n\t" // 2 nop nop (T = 36) - "sbiw %[count], 1" - "\n\t" // 2 i-- (T = 38) - "brne head40" - "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e"(port), [byte] "+r"(b), [bit] "+r"(bit), - [next] "+r"(next), [count] "+w"(i) - : [ptr] "e"(ptr), [hi] "r"(hi), [lo] "r"(lo)); - } -#endif // NEO_KHZ400 - -#else -#error "CPU SPEED NOT SUPPORTED" -#endif // end F_CPU ifdefs on __AVR__ - - // END AVR ---------------------------------------------------------------- - -#elif defined(__arm__) - - // ARM MCUs -- Teensy 3.0, 3.1, LC, Arduino Due, RP2040 ------------------- - -#if defined(ARDUINO_ARCH_RP2040) - // Use PIO - rp2040Show(pin, pixels, numBytes, is800KHz); - -#elif defined(TEENSYDUINO) && \ - defined(KINETISK) // Teensy 3.0, 3.1, 3.2, 3.5, 3.6 -#define CYCLES_800_T0H (F_CPU / 4000000) -#define CYCLES_800_T1H (F_CPU / 1250000) -#define CYCLES_800 (F_CPU / 800000) -#define CYCLES_400_T0H (F_CPU / 2000000) -#define CYCLES_400_T1H (F_CPU / 833333) -#define CYCLES_400 (F_CPU / 400000) - - uint8_t *p = pixels, *end = p + numBytes, pix, mask; - volatile uint8_t *set = portSetRegister(pin), *clr = portClearRegister(pin); - uint32_t cyc; - - ARM_DEMCR |= ARM_DEMCR_TRCENA; - ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - cyc = ARM_DWT_CYCCNT + CYCLES_800; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; - cyc = ARM_DWT_CYCCNT; - *set = 1; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H) - ; - } - *clr = 1; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - cyc = ARM_DWT_CYCCNT + CYCLES_400; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - cyc = ARM_DWT_CYCCNT; - *set = 1; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H) - ; - } - *clr = 1; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - } -#endif // NEO_KHZ400 - -#elif defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__)) -#define CYCLES_800_T0H (F_CPU_ACTUAL / 4000000) -#define CYCLES_800_T1H (F_CPU_ACTUAL / 1250000) -#define CYCLES_800 (F_CPU_ACTUAL / 800000) -#define CYCLES_400_T0H (F_CPU_ACTUAL / 2000000) -#define CYCLES_400_T1H (F_CPU_ACTUAL / 833333) -#define CYCLES_400 (F_CPU_ACTUAL / 400000) - - uint8_t *p = pixels, *end = p + numBytes, pix, mask; - volatile uint32_t *set = portSetRegister(pin), *clr = portClearRegister(pin); - uint32_t cyc, msk = digitalPinToBitMask(pin); - - ARM_DEMCR |= ARM_DEMCR_TRCENA; - ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - cyc = ARM_DWT_CYCCNT + CYCLES_800; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; - cyc = ARM_DWT_CYCCNT; - *set = msk; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H) - ; - } - *clr = msk; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_800) - ; -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - cyc = ARM_DWT_CYCCNT + CYCLES_400; - while (p < end) { - pix = *p++; - for (mask = 0x80; mask; mask >>= 1) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - cyc = ARM_DWT_CYCCNT; - *set = msk; - if (pix & mask) { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H) - ; - } else { - while (ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H) - ; - } - *clr = msk; - } - } - while (ARM_DWT_CYCCNT - cyc < CYCLES_400) - ; - } -#endif // NEO_KHZ400 - -#elif defined(TEENSYDUINO) && defined(__MKL26Z64__) // Teensy-LC - -#if F_CPU == 48000000 - uint8_t *p = pixels, pix, count, dly, bitmask = digitalPinToBitMask(pin); - volatile uint8_t *reg = portSetRegister(pin); - uint32_t num = numBytes; - asm volatile("L%=_begin:" - "\n\t" - "ldrb %[pix], [%[p], #0]" - "\n\t" - "lsl %[pix], #24" - "\n\t" - "movs %[count], #7" - "\n\t" - "L%=_loop:" - "\n\t" - "lsl %[pix], #1" - "\n\t" - "bcs L%=_loop_one" - "\n\t" - "L%=_loop_zero:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_loop_delay_T0H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T0H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_loop_delay_T0L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T0L" - "\n\t" - "b L%=_next" - "\n\t" - "L%=_loop_one:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_loop_delay_T1H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T1H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_loop_delay_T1L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_loop_delay_T1L" - "\n\t" - "nop" - "\n\t" - "L%=_next:" - "\n\t" - "sub %[count], #1" - "\n\t" - "bne L%=_loop" - "\n\t" - "lsl %[pix], #1" - "\n\t" - "bcs L%=_last_one" - "\n\t" - "L%=_last_zero:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #4" - "\n\t" - "L%=_last_delay_T0H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T0H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #10" - "\n\t" - "L%=_last_delay_T0L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T0L" - "\n\t" - "b L%=_repeat" - "\n\t" - "L%=_last_one:" - "\n\t" - "strb %[bitmask], [%[reg], #0]" - "\n\t" - "movs %[dly], #13" - "\n\t" - "L%=_last_delay_T1H:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T1H" - "\n\t" - "strb %[bitmask], [%[reg], #4]" - "\n\t" - "movs %[dly], #1" - "\n\t" - "L%=_last_delay_T1L:" - "\n\t" - "sub %[dly], #1" - "\n\t" - "bne L%=_last_delay_T1L" - "\n\t" - "nop" - "\n\t" - "L%=_repeat:" - "\n\t" - "add %[p], #1" - "\n\t" - "sub %[num], #1" - "\n\t" - "bne L%=_begin" - "\n\t" - "L%=_done:" - "\n\t" - : [p] "+r"(p), [pix] "=&r"(pix), [count] "=&r"(count), - [dly] "=&r"(dly), [num] "+r"(num) - : [bitmask] "r"(bitmask), [reg] "r"(reg)); -#else -#error "Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz" -#endif // F_CPU == 48000000 - - // Begin of support for nRF52 based boards ------------------------- - -#elif defined(NRF52) || defined(NRF52_SERIES) -// [[[Begin of the Neopixel NRF52 EasyDMA implementation -// by the Hackerspace San Salvador]]] -// This technique uses the PWM peripheral on the NRF52. The PWM uses the -// EasyDMA feature included on the chip. This technique loads the duty -// cycle configuration for each cycle when the PWM is enabled. For this -// to work we need to store a 16 bit configuration for each bit of the -// RGB(W) values in the pixel buffer. -// Comparator values for the PWM were hand picked and are guaranteed to -// be 100% organic to preserve freshness and high accuracy. Current -// parameters are: -// * PWM Clock: 16Mhz -// * Minimum step time: 62.5ns -// * Time for zero in high (T0H): 0.31ms -// * Time for one in high (T1H): 0.75ms -// * Cycle time: 1.25us -// * Frequency: 800Khz -// For 400Khz we just double the calculated times. -// ---------- BEGIN Constants for the EasyDMA implementation ----------- -// The PWM starts the duty cycle in LOW. To start with HIGH we -// need to set the 15th bit on each register. - -// WS2812 (rev A) timing is 0.35 and 0.7us -//#define MAGIC_T0H 5UL | (0x8000) // 0.3125us -//#define MAGIC_T1H 12UL | (0x8000) // 0.75us - -// WS2812B (rev B) timing is 0.4 and 0.8 us -#define MAGIC_T0H 6UL | (0x8000) // 0.375us -#define MAGIC_T1H 13UL | (0x8000) // 0.8125us - -// WS2811 (400 khz) timing is 0.5 and 1.2 -#define MAGIC_T0H_400KHz 8UL | (0x8000) // 0.5us -#define MAGIC_T1H_400KHz 19UL | (0x8000) // 1.1875us - -// For 400Khz, we double value of CTOPVAL -#define CTOPVAL 20UL // 1.25us -#define CTOPVAL_400KHz 40UL // 2.5us - -// ---------- END Constants for the EasyDMA implementation ------------- -// -// If there is no device available an alternative cycle-counter -// implementation is tried. -// The nRF52 runs with a fixed clock of 64Mhz. The alternative -// implementation is the same as the one used for the Teensy 3.0/1/2 but -// with the Nordic SDK HAL & registers syntax. -// The number of cycles was hand picked and is guaranteed to be 100% -// organic to preserve freshness and high accuracy. -// ---------- BEGIN Constants for cycle counter implementation --------- -#define CYCLES_800_T0H 18 // ~0.36 uS -#define CYCLES_800_T1H 41 // ~0.76 uS -#define CYCLES_800 71 // ~1.25 uS - -#define CYCLES_400_T0H 26 // ~0.50 uS -#define CYCLES_400_T1H 70 // ~1.26 uS -#define CYCLES_400 156 // ~2.50 uS - // ---------- END of Constants for cycle counter implementation -------- - - // To support both the SoftDevice + Neopixels we use the EasyDMA - // feature from the NRF25. However this technique implies to - // generate a pattern and store it on the memory. The actual - // memory used in bytes corresponds to the following formula: - // totalMem = numBytes*8*2+(2*2) - // The two additional bytes at the end are needed to reset the - // sequence. - // - // If there is not enough memory, we will fall back to cycle counter - // using DWT - uint32_t pattern_size = - numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t); - uint16_t *pixels_pattern = NULL; - - NRF_PWM_Type *pwm = NULL; - - // Try to find a free PWM device, which is not enabled - // and has no connected pins - NRF_PWM_Type *PWM[] = { - NRF_PWM0, - NRF_PWM1, - NRF_PWM2 -#if defined(NRF_PWM3) - , - NRF_PWM3 -#endif - }; - - for (unsigned int device = 0; device < (sizeof(PWM) / sizeof(PWM[0])); - device++) { - if ((PWM[device]->ENABLE == 0) && - (PWM[device]->PSEL.OUT[0] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[1] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[2] & PWM_PSEL_OUT_CONNECT_Msk) && - (PWM[device]->PSEL.OUT[3] & PWM_PSEL_OUT_CONNECT_Msk)) { - pwm = PWM[device]; - break; - } - } - - // only malloc if there is PWM device available - if (pwm != NULL) { -#if defined(ARDUINO_NRF52_ADAFRUIT) // use thread-safe malloc - pixels_pattern = (uint16_t *)rtos_malloc(pattern_size); -#else - pixels_pattern = (uint16_t *)malloc(pattern_size); -#endif - } - - // Use the identified device to choose the implementation - // If a PWM device is available use DMA - if ((pixels_pattern != NULL) && (pwm != NULL)) { - uint16_t pos = 0; // bit position - - for (uint16_t n = 0; n < numBytes; n++) { - uint8_t pix = pixels[n]; - - for (uint8_t mask = 0x80; mask > 0; mask >>= 1) { -#if defined(NEO_KHZ400) - if (!is800KHz) { - pixels_pattern[pos] = - (pix & mask) ? MAGIC_T1H_400KHz : MAGIC_T0H_400KHz; - } else -#endif - { - pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H; - } - - pos++; - } - } - - // Zero padding to indicate the end of que sequence - pixels_pattern[pos++] = 0 | (0x8000); // Seq end - pixels_pattern[pos++] = 0 | (0x8000); // Seq end - - // Set the wave mode to count UP - pwm->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos); - - // Set the PWM to use the 16MHz clock - pwm->PRESCALER = - (PWM_PRESCALER_PRESCALER_DIV_1 << PWM_PRESCALER_PRESCALER_Pos); - - // Setting of the maximum count - // but keeping it on 16Mhz allows for more granularity just - // in case someone wants to do more fine-tuning of the timing. -#if defined(NEO_KHZ400) - if (!is800KHz) { - pwm->COUNTERTOP = (CTOPVAL_400KHz << PWM_COUNTERTOP_COUNTERTOP_Pos); - } else -#endif - { - pwm->COUNTERTOP = (CTOPVAL << PWM_COUNTERTOP_COUNTERTOP_Pos); - } - - // Disable loops, we want the sequence to repeat only once - pwm->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos); - - // On the "Common" setting the PWM uses the same pattern for the - // for supported sequences. The pattern is stored on half-word - // of 16bits - pwm->DECODER = (PWM_DECODER_LOAD_Common << PWM_DECODER_LOAD_Pos) | - (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos); - - // Pointer to the memory storing the patter - pwm->SEQ[0].PTR = (uint32_t)(pixels_pattern) << PWM_SEQ_PTR_PTR_Pos; - - // Calculation of the number of steps loaded from memory. - pwm->SEQ[0].CNT = (pattern_size / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos; - - // The following settings are ignored with the current config. - pwm->SEQ[0].REFRESH = 0; - pwm->SEQ[0].ENDDELAY = 0; - - // The Neopixel implementation is a blocking algorithm. DMA - // allows for non-blocking operation. To "simulate" a blocking - // operation we enable the interruption for the end of sequence - // and block the execution thread until the event flag is set by - // the peripheral. - // pwm->INTEN |= (PWM_INTEN_SEQEND0_Enabled<PSEL.OUT[0] = g_APinDescription[pin].name; -#else - pwm->PSEL.OUT[0] = g_ADigitalPinMap[pin]; -#endif - - // Enable the PWM - pwm->ENABLE = 1; - - // After all of this and many hours of reading the documentation - // we are ready to start the sequence... - pwm->EVENTS_SEQEND[0] = 0; - pwm->TASKS_SEQSTART[0] = 1; - - // But we have to wait for the flag to be set. - while (!pwm->EVENTS_SEQEND[0]) { -#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_NRF52840) - yield(); -#endif - } - - // Before leave we clear the flag for the event. - pwm->EVENTS_SEQEND[0] = 0; - - // We need to disable the device and disconnect - // all the outputs before leave or the device will not - // be selected on the next call. - // TODO: Check if disabling the device causes performance issues. - pwm->ENABLE = 0; - - pwm->PSEL.OUT[0] = 0xFFFFFFFFUL; - -#if defined(ARDUINO_NRF52_ADAFRUIT) // use thread-safe free - rtos_free(pixels_pattern); -#else - free(pixels_pattern); -#endif - } // End of DMA implementation - // --------------------------------------------------------------------- - else { -#ifndef ARDUINO_ARCH_NRF52840 -// Fall back to DWT -#if defined(ARDUINO_NRF52_ADAFRUIT) - // Bluefruit Feather 52 uses freeRTOS - // Critical Section is used since it does not block SoftDevice execution - taskENTER_CRITICAL(); -#elif defined(NRF52_DISABLE_INT) - // If you are using the Bluetooth SoftDevice we advise you to not disable - // the interrupts. Disabling the interrupts even for short periods of time - // causes the SoftDevice to stop working. - // Disable the interrupts only in cases where you need high performance for - // the LEDs and if you are not using the EasyDMA feature. - __disable_irq(); -#endif - - NRF_GPIO_Type *nrf_port = (NRF_GPIO_Type *)digitalPinToPort(pin); - uint32_t pinMask = digitalPinToBitMask(pin); - - uint32_t CYCLES_X00 = CYCLES_800; - uint32_t CYCLES_X00_T1H = CYCLES_800_T1H; - uint32_t CYCLES_X00_T0H = CYCLES_800_T0H; - -#if defined(NEO_KHZ400) - if (!is800KHz) { - CYCLES_X00 = CYCLES_400; - CYCLES_X00_T1H = CYCLES_400_T1H; - CYCLES_X00_T0H = CYCLES_400_T0H; - } -#endif - - // Enable DWT in debug core - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; - - // Tries to re-send the frame if is interrupted by the SoftDevice. - while (1) { - uint8_t *p = pixels; - - uint32_t cycStart = DWT->CYCCNT; - uint32_t cyc = 0; - - for (uint16_t n = 0; n < numBytes; n++) { - uint8_t pix = *p++; - - for (uint8_t mask = 0x80; mask; mask >>= 1) { - while (DWT->CYCCNT - cyc < CYCLES_X00) - ; - cyc = DWT->CYCCNT; - - nrf_port->OUTSET |= pinMask; - - if (pix & mask) { - while (DWT->CYCCNT - cyc < CYCLES_X00_T1H) - ; - } else { - while (DWT->CYCCNT - cyc < CYCLES_X00_T0H) - ; - } - - nrf_port->OUTCLR |= pinMask; - } - } - while (DWT->CYCCNT - cyc < CYCLES_X00) - ; - - // If total time longer than 25%, resend the whole data. - // Since we are likely to be interrupted by SoftDevice - if ((DWT->CYCCNT - cycStart) < (8 * numBytes * ((CYCLES_X00 * 5) / 4))) { - break; - } - - // re-send need 300us delay - delayMicroseconds(300); - } - -// Enable interrupts again -#if defined(ARDUINO_NRF52_ADAFRUIT) - taskEXIT_CRITICAL(); -#elif defined(NRF52_DISABLE_INT) - __enable_irq(); -#endif -#endif - } - // END of NRF52 implementation - -#elif defined(__SAMD21E17A__) || defined(__SAMD21G18A__) || \ - defined(__SAMD21E18A__) || defined(__SAMD21J18A__) || \ - defined (__SAMD11C14A__) - // Arduino Zero, Gemma/Trinket M0, SODAQ Autonomo - // and others - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask, portNum; - uint32_t pinMask; - - portNum = g_APinDescription[pin].ulPort; - pinMask = 1ul << g_APinDescription[pin].ulPin; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint32_t *set = &(PORT->Group[portNum].OUTSET.reg), - *clr = &(PORT->Group[portNum].OUTCLR.reg); - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;"); - if (p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - } - if (bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop; nop; nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - for (;;) { - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"); - if (p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - *clr = pinMask; - } else { - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop;"); - } - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - if (bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } - } -#endif - -//---- -#elif defined(XMC1100_XMC2GO) || defined(XMC1100_H_BRIDGE2GO) || defined(XMC1100_Boot_Kit) || defined(XMC1300_Boot_Kit) - - // XMC1100/1200/1300 with ARM Cortex M0 are running with 32MHz, XMC1400 runs with 48MHz so may not work - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask, portNum; - uint32_t pinMask; - - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - XMC_GPIO_PORT_t* XMC_port = mapping_port_pin[ pin ].port; - uint8_t XMC_pin = mapping_port_pin[ pin ].pin; - - uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin; - uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin; - -#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled - if(is800KHz) { -#endif - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop;"); - } - if(bitMask >>= 1) { - asm("nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } -#ifdef NEO_KHZ400 // untested code - } else { // 400 KHz bitstream - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop;"); - } - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - if(bitMask >>= 1) { - asm("nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } - } - -#endif -//---- - -//---- -#elif defined(XMC4700_Relax_Kit) || defined(XMC4800_Relax_Kit) - -// XMC4700 and XMC4800 with ARM Cortex M4 are running with 144MHz -// Tried this with a timer/counter, couldn't quite get adequate -// resolution. So yay, you get a load of goofball NOPs... - -uint8_t *ptr, *end, p, bitMask, portNum; -uint32_t pinMask; - -ptr = pixels; -end = ptr + numBytes; -p = *ptr++; -bitMask = 0x80; - -XMC_GPIO_PORT_t* XMC_port = mapping_port_pin[ pin ].port; -uint8_t XMC_pin = mapping_port_pin[ pin ].pin; - -uint32_t omrhigh = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_HIGH << XMC_pin; -uint32_t omrlow = (uint32_t)XMC_GPIO_OUTPUT_LEVEL_LOW << XMC_pin; - -#ifdef NEO_KHZ400 // 800 KHz check needed only if 400 KHz support enabled -if(is800KHz) { -#endif - - for(;;) { - XMC_port->OMR = omrhigh; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - if(p & bitMask) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - XMC_port->OMR = omrlow; - } else { - XMC_port->OMR = omrlow; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - } - if(bitMask >>= 1) { - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;"); - } else { - if(ptr >= end) break; - p = *ptr++; - bitMask = 0x80; - } - } - - -#ifdef NEO_KHZ400 - } else { // 400 KHz bitstream - // ToDo! - } -#endif -//---- - -#elif defined(__SAMD51__) // M4 - - uint8_t *ptr, *end, p, bitMask, portNum, bit; - uint32_t pinMask; - - portNum = g_APinDescription[pin].ulPort; - pinMask = 1ul << g_APinDescription[pin].ulPin; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint32_t *set = &(PORT->Group[portNum].OUTSET.reg), - *clr = &(PORT->Group[portNum].OUTCLR.reg); - - // SAMD51 overclock-compatible timing is only a mild abomination. - // It uses SysTick for a consistent clock reference regardless of - // optimization / cache settings. That's the good news. The bad news, - // since SysTick->VAL is a volatile type it's slow to access...and then, - // with the SysTick interval that Arduino sets up (1 ms), this would - // require a subtract and MOD operation for gauging elapsed time, and - // all taken in combination that lacks adequate temporal resolution - // for NeoPixel timing. So a kind of horrible thing is done here... - // since interrupts are turned off anyway and it's generally accepted - // by now that we're gonna lose track of time in the NeoPixel lib, - // the SysTick timer is reconfigured for a period matching the NeoPixel - // bit timing (either 800 or 400 KHz) and we watch SysTick->VAL very - // closely (just a threshold, no subtract or MOD or anything) and that - // seems to work just well enough. When finished, the SysTick - // peripheral is set back to its original state. - - uint32_t t0, t1, top, ticks, saveLoad = SysTick->LOAD, saveVal = SysTick->VAL; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - top = (uint32_t)(F_CPU * 0.00000125); // Bit hi + lo = 1.25 uS - t0 = top - (uint32_t)(F_CPU * 0.00000040); // 0 = 0.4 uS hi - t1 = top - (uint32_t)(F_CPU * 0.00000080); // 1 = 0.8 uS hi -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - top = (uint32_t)(F_CPU * 0.00000250); // Bit hi + lo = 2.5 uS - t0 = top - (uint32_t)(F_CPU * 0.00000050); // 0 = 0.5 uS hi - t1 = top - (uint32_t)(F_CPU * 0.00000120); // 1 = 1.2 uS hi - } -#endif - - SysTick->LOAD = top; // Config SysTick for NeoPixel bit freq - SysTick->VAL = top; // Set to start value (counts down) - (void)SysTick->VAL; // Dummy read helps sync up 1st bit - - for (;;) { - *set = pinMask; // Set output high - ticks = (p & bitMask) ? t1 : t0; // SysTick threshold, - while (SysTick->VAL > ticks) - ; // wait for it - *clr = pinMask; // Set output low - if (!(bitMask >>= 1)) { // Next bit for this byte...done? - if (ptr >= end) - break; // If last byte sent, exit loop - p = *ptr++; // Fetch next byte - bitMask = 0x80; // Reset bitmask - } - while (SysTick->VAL <= ticks) - ; // Wait for rollover to 'top' - } - - SysTick->LOAD = saveLoad; // Restore SysTick rollover to 1 ms - SysTick->VAL = saveVal; // Restore SysTick value - -#elif defined(ARDUINO_STM32_FEATHER) // FEATHER WICED (120MHz) - - // Tried this with a timer/counter, couldn't quite get adequate - // resolution. So yay, you get a load of goofball NOPs... - - uint8_t *ptr, *end, p, bitMask; - uint32_t pinMask; - - pinMask = BIT(PIN_MAP[pin].gpio_bit); - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - - volatile uint16_t *set = &(PIN_MAP[pin].gpio_device->regs->BSRRL); - volatile uint16_t *clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH); - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - if (p & bitMask) { // ONE - // High 800ns - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop;"); - // Low 450ns - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop;"); - } else { // ZERO - // High 400ns - *set = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop;"); - // Low 850ns - *clr = pinMask; - asm("nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop; nop; nop; nop; nop;" - "nop; nop; nop; nop;"); - } - if (bitMask >>= 1) { - // Move on to the next pixel - asm("nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - // ToDo! - } -#endif - -#elif defined(TARGET_LPC1768) - uint8_t *ptr, *end, p, bitMask; - ptr = pixels; - end = ptr + numBytes; - p = *ptr++; - bitMask = 0x80; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - for (;;) { - if (p & bitMask) { - // data ONE high - // min: 550 typ: 700 max: 5,500 - gpio_set(pin); - time::delay_ns(550); - // min: 450 typ: 600 max: 5,000 - gpio_clear(pin); - time::delay_ns(450); - } else { - // data ZERO high - // min: 200 typ: 350 max: 500 - gpio_set(pin); - time::delay_ns(200); - // data low - // min: 450 typ: 600 max: 5,000 - gpio_clear(pin); - time::delay_ns(450); - } - if (bitMask >>= 1) { - // Move on to the next pixel - asm("nop;"); - } else { - if (ptr >= end) - break; - p = *ptr++; - bitMask = 0x80; - } - } -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - // ToDo! - } -#endif -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - uint8_t *p = pixels, *end = p + numBytes, pix = *p++, mask = 0x80; - uint32_t cyc; - uint32_t saveLoad = SysTick->LOAD, saveVal = SysTick->VAL; -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - uint32_t top = (F_CPU / 800000); // 1.25µs - uint32_t t0 = top - (F_CPU / 2500000); // 0.4µs - uint32_t t1 = top - (F_CPU / 1250000); // 0.8µs - SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq - SysTick->VAL = 0; // Set to start value - for (;;) { - LL_GPIO_SetOutputPin(gpioPort, gpioPin); - cyc = (pix & mask) ? t1 : t0; - while (SysTick->VAL > cyc) - ; - LL_GPIO_ResetOutputPin(gpioPort, gpioPin); - if (!(mask >>= 1)) { - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - while (SysTick->VAL <= cyc) - ; - } -#if defined(NEO_KHZ400) - } else { // 400 kHz bitstream - uint32_t top = (F_CPU / 400000); // 2.5µs - uint32_t t0 = top - (F_CPU / 2000000); // 0.5µs - uint32_t t1 = top - (F_CPU / 833333); // 1.2µs - SysTick->LOAD = top - 1; // Config SysTick for NeoPixel bit freq - SysTick->VAL = 0; // Set to start value - for (;;) { - LL_GPIO_SetOutputPin(gpioPort, gpioPin); - cyc = (pix & mask) ? t1 : t0; - while (SysTick->VAL > cyc) - ; - LL_GPIO_ResetOutputPin(gpioPort, gpioPin); - if (!(mask >>= 1)) { - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - while (SysTick->VAL <= cyc) - ; - } - } -#endif // NEO_KHZ400 - SysTick->LOAD = saveLoad; // Restore SysTick rollover to 1 ms - SysTick->VAL = saveVal; // Restore SysTick value -#elif defined(NRF51) - uint8_t *p = pixels, pix, count, mask; - int32_t num = numBytes; - unsigned int bitmask = (1 << g_ADigitalPinMap[pin]); - // https://github.com/sandeepmistry/arduino-nRF5/blob/dc53980c8bac27898fca90d8ecb268e11111edc1/variants/BBCmicrobit/variant.cpp - - volatile unsigned int *reg = (unsigned int *)(0x50000000UL + 0x508); - - // https://github.com/sandeepmistry/arduino-nRF5/blob/dc53980c8bac27898fca90d8ecb268e11111edc1/cores/nRF5/SDK/components/device/nrf51.h - // http://www.iot-programmer.com/index.php/books/27-micro-bit-iot-in-c/chapters-micro-bit-iot-in-c/47-micro-bit-iot-in-c-fast-memory-mapped-gpio?showall=1 - // https://github.com/Microsoft/pxt-neopixel/blob/master/sendbuffer.asm - - asm volatile( - // "cpsid i" ; disable irq - - // b .start - "b L%=_start" - "\n\t" - // .nextbit: ; C0 - "L%=_nextbit:" - "\n\t" //; C0 - // str r1, [r3, #0] ; pin := hi C2 - "strb %[bitmask], [%[reg], #0]" - "\n\t" //; pin := hi C2 - // tst r6, r0 ; C3 - "tst %[mask], %[pix]" - "\n\t" // ; C3 - // bne .islate ; C4 - "bne L%=_islate" - "\n\t" //; C4 - // str r1, [r2, #0] ; pin := lo C6 - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo C6 - // .islate: - "L%=_islate:" - "\n\t" - // lsrs r6, r6, #1 ; r6 >>= 1 C7 - "lsr %[mask], %[mask], #1" - "\n\t" //; r6 >>= 1 C7 - // bne .justbit ; C8 - "bne L%=_justbit" - "\n\t" //; C8 - - // ; not just a bit - need new byte - // adds r4, #1 ; r4++ C9 - "add %[p], #1" - "\n\t" //; r4++ C9 - // subs r5, #1 ; r5-- C10 - "sub %[num], #1" - "\n\t" //; r5-- C10 - // bcc .stop ; if (r5<0) goto .stop C11 - "bcc L%=_stop" - "\n\t" //; if (r5<0) goto .stop C11 - // .start: - "L%=_start:" - // movs r6, #0x80 ; reset mask C12 - "movs %[mask], #0x80" - "\n\t" //; reset mask C12 - // nop ; C13 - "nop" - "\n\t" //; C13 - - // .common: ; C13 - "L%=_common:" - "\n\t" //; C13 - // str r1, [r2, #0] ; pin := lo C15 - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo C15 - // ; always re-load byte - it just fits with the cycles better this way - // ldrb r0, [r4, #0] ; r0 := *r4 C17 - "ldrb %[pix], [%[p], #0]" - "\n\t" //; r0 := *r4 C17 - // b .nextbit ; C20 - "b L%=_nextbit" - "\n\t" //; C20 - - // .justbit: ; C10 - "L%=_justbit:" - "\n\t" //; C10 - // ; no nops, branch taken is already 3 cycles - // b .common ; C13 - "b L%=_common" - "\n\t" //; C13 - - // .stop: - "L%=_stop:" - "\n\t" - // str r1, [r2, #0] ; pin := lo - "strb %[bitmask], [%[reg], #4]" - "\n\t" //; pin := lo - // cpsie i ; enable irq - - : [p] "+r"(p), [pix] "=&r"(pix), [count] "=&r"(count), [mask] "=&r"(mask), - [num] "+r"(num) - : [bitmask] "r"(bitmask), [reg] "r"(reg)); - -#elif defined(__SAM3X8E__) // Arduino Due - -#define SCALE VARIANT_MCK / 2UL / 1000000UL -#define INST (2UL * F_CPU / VARIANT_MCK) -#define TIME_800_0 ((int)(0.40 * SCALE + 0.5) - (5 * INST)) -#define TIME_800_1 ((int)(0.80 * SCALE + 0.5) - (5 * INST)) -#define PERIOD_800 ((int)(1.25 * SCALE + 0.5) - (5 * INST)) -#define TIME_400_0 ((int)(0.50 * SCALE + 0.5) - (5 * INST)) -#define TIME_400_1 ((int)(1.20 * SCALE + 0.5) - (5 * INST)) -#define PERIOD_400 ((int)(2.50 * SCALE + 0.5) - (5 * INST)) - - int pinMask, time0, time1, period, t; - Pio *port; - volatile WoReg *portSet, *portClear, *timeValue, *timeReset; - uint8_t *p, *end, pix, mask; - - pmc_set_writeprotect(false); - pmc_enable_periph_clk((uint32_t)TC3_IRQn); - TC_Configure(TC1, 0, - TC_CMR_WAVE | TC_CMR_WAVSEL_UP | TC_CMR_TCCLKS_TIMER_CLOCK1); - TC_Start(TC1, 0); - - pinMask = g_APinDescription[pin].ulPin; // Don't 'optimize' these into - port = g_APinDescription[pin].pPort; // declarations above. Want to - portSet = &(port->PIO_SODR); // burn a few cycles after - portClear = &(port->PIO_CODR); // starting timer to minimize - timeValue = &(TC1->TC_CHANNEL[0].TC_CV); // the initial 'while'. - timeReset = &(TC1->TC_CHANNEL[0].TC_CCR); - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - -#if defined(NEO_KHZ400) // 800 KHz check needed only if 400 KHz support enabled - if (is800KHz) { -#endif - time0 = TIME_800_0; - time1 = TIME_800_1; - period = PERIOD_800; -#if defined(NEO_KHZ400) - } else { // 400 KHz bitstream - time0 = TIME_400_0; - time1 = TIME_400_1; - period = PERIOD_400; - } -#endif - - for (t = time0;; t = time0) { - if (pix & mask) - t = time1; - while (*timeValue < (unsigned)period) - ; - *portSet = pinMask; - *timeReset = TC_CCR_CLKEN | TC_CCR_SWTRG; - while (*timeValue < (unsigned)t) - ; - *portClear = pinMask; - if (!(mask >>= 1)) { // This 'inside-out' loop logic utilizes - if (p >= end) - break; // idle time to minimize inter-byte delays. - pix = *p++; - mask = 0x80; - } - } - while (*timeValue < (unsigned)period) - ; // Wait for last bit - TC_Stop(TC1, 0); - -#endif // end Due - - // END ARM ---------------------------------------------------------------- - -#elif defined(ESP8266) || defined(ESP32) - - // ESP8266 ---------------------------------------------------------------- - - // ESP8266 show() is external to enforce ICACHE_RAM_ATTR execution - espShow(pin, pixels, numBytes, is800KHz); - -#elif defined(KENDRYTE_K210) - - k210Show(pin, pixels, numBytes, is800KHz); - -#elif defined(__ARDUINO_ARC__) - - // Arduino 101 ----------------------------------------------------------- - -#define NOPx7 \ - { \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - __builtin_arc_nop(); \ - } - - PinDescription *pindesc = &g_APinDescription[pin]; - register uint32_t loop = - 8 * numBytes; // one loop to handle all bytes and all bits - register uint8_t *p = pixels; - register uint32_t currByte = (uint32_t)(*p); - register uint32_t currBit = 0x80 & currByte; - register uint32_t bitCounter = 0; - register uint32_t first = 1; - - // The loop is unusual. Very first iteration puts all the way LOW to the wire - // - constant LOW does not affect NEOPIXEL, so there is no visible effect - // displayed. During that very first iteration CPU caches instructions in the - // loop. Because of the caching process, "CPU slows down". NEOPIXEL pulse is - // very time sensitive that's why we let the CPU cache first and we start - // regular pulse from 2nd iteration - if (pindesc->ulGPIOType == SS_GPIO) { - register uint32_t reg = pindesc->ulGPIOBase + SS_GPIO_SWPORTA_DR; - uint32_t reg_val = __builtin_arc_lr((volatile uint32_t)reg); - register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId); - register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId); - - loop += 1; // include first, special iteration - while (loop--) { - if (!first) { - currByte <<= 1; - bitCounter++; - } - - // 1 is >550ns high and >450ns low; 0 is 200..500ns high and >450ns low - __builtin_arc_sr(first ? reg_bit_low : reg_bit_high, - (volatile uint32_t)reg); - if (currBit) { // ~400ns HIGH (740ns overall) - NOPx7 NOPx7 - } - // ~340ns HIGH - NOPx7 __builtin_arc_nop(); - - // 820ns LOW; per spec, max allowed low here is 5000ns */ - __builtin_arc_sr(reg_bit_low, (volatile uint32_t)reg); - NOPx7 NOPx7 - - if (bitCounter >= 8) { - bitCounter = 0; - currByte = (uint32_t)(*++p); - } - - currBit = 0x80 & currByte; - first = 0; - } - } else if (pindesc->ulGPIOType == SOC_GPIO) { - register uint32_t reg = pindesc->ulGPIOBase + SOC_GPIO_SWPORTA_DR; - uint32_t reg_val = MMIO_REG_VAL(reg); - register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId); - register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId); - - loop += 1; // include first, special iteration - while (loop--) { - if (!first) { - currByte <<= 1; - bitCounter++; - } - MMIO_REG_VAL(reg) = first ? reg_bit_low : reg_bit_high; - if (currBit) { // ~430ns HIGH (740ns overall) - NOPx7 NOPx7 __builtin_arc_nop(); - } - // ~310ns HIGH - NOPx7 - - // 850ns LOW; per spec, max allowed low here is 5000ns */ - MMIO_REG_VAL(reg) = reg_bit_low; - NOPx7 NOPx7 - - if (bitCounter >= 8) { - bitCounter = 0; - currByte = (uint32_t)(*++p); - } - - currBit = 0x80 & currByte; - first = 0; - } - } - -#else -#error Architecture not supported -#endif - - // END ARCHITECTURE SELECT ------------------------------------------------ - -#if !(defined(NRF52) || defined(NRF52_SERIES) || defined(ESP32)) - interrupts(); -#endif - - endTime = micros(); // Save EOD time for latch on next call -} - -/*! - @brief Set/change the NeoPixel output pin number. Previous pin, - if any, is set to INPUT and the new pin is set to OUTPUT. - @param p Arduino pin number (-1 = no pin). -*/ -void Adafruit_NeoPixel::setPin(int16_t p) { - if (begun && (pin >= 0)) - pinMode(pin, INPUT); // Disable existing out pin - pin = p; - if (begun) { - pinMode(p, OUTPUT); - digitalWrite(p, LOW); - } -#if defined(__AVR__) - port = portOutputRegister(digitalPinToPort(p)); - pinMask = digitalPinToBitMask(p); -#endif -#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - gpioPort = digitalPinToPort(p); - gpioPin = STM_LL_GPIO_PIN(digitalPinToPinName(p)); -#endif -} - -/*! - @brief Set a pixel's color using separate red, green and blue - components. If using RGBW pixels, white will be set to 0. - @param n Pixel index, starting from 0. - @param r Red brightness, 0 = minimum (off), 255 = maximum. - @param g Green brightness, 0 = minimum (off), 255 = maximum. - @param b Blue brightness, 0 = minimum (off), 255 = maximum. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint8_t r, uint8_t g, - uint8_t b) { - - if (n < numLEDs) { - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - } - uint8_t *p; - if (wOffset == rOffset) { // Is an RGB-type strip - p = &pixels[n * 3]; // 3 bytes per pixel - } else { // Is a WRGB-type strip - p = &pixels[n * 4]; // 4 bytes per pixel - p[wOffset] = 0; // But only R,G,B passed -- set W to 0 - } - p[rOffset] = r; // R,G,B always stored - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Set a pixel's color using separate red, green, blue and white - components (for RGBW NeoPixels only). - @param n Pixel index, starting from 0. - @param r Red brightness, 0 = minimum (off), 255 = maximum. - @param g Green brightness, 0 = minimum (off), 255 = maximum. - @param b Blue brightness, 0 = minimum (off), 255 = maximum. - @param w White brightness, 0 = minimum (off), 255 = maximum, ignored - if using RGB pixels. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint8_t r, uint8_t g, - uint8_t b, uint8_t w) { - - if (n < numLEDs) { - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - w = (w * brightness) >> 8; - } - uint8_t *p; - if (wOffset == rOffset) { // Is an RGB-type strip - p = &pixels[n * 3]; // 3 bytes per pixel (ignore W) - } else { // Is a WRGB-type strip - p = &pixels[n * 4]; // 4 bytes per pixel - p[wOffset] = w; // Store W - } - p[rOffset] = r; // Store R,G,B - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Set a pixel's color using a 32-bit 'packed' RGB or RGBW value. - @param n Pixel index, starting from 0. - @param c 32-bit color value. Most significant byte is white (for RGBW - pixels) or ignored (for RGB pixels), next is red, then green, - and least significant byte is blue. -*/ -void Adafruit_NeoPixel::setPixelColor(uint16_t n, uint32_t c) { - if (n < numLEDs) { - uint8_t *p, r = (uint8_t)(c >> 16), g = (uint8_t)(c >> 8), b = (uint8_t)c; - if (brightness) { // See notes in setBrightness() - r = (r * brightness) >> 8; - g = (g * brightness) >> 8; - b = (b * brightness) >> 8; - } - if (wOffset == rOffset) { - p = &pixels[n * 3]; - } else { - p = &pixels[n * 4]; - uint8_t w = (uint8_t)(c >> 24); - p[wOffset] = brightness ? ((w * brightness) >> 8) : w; - } - p[rOffset] = r; - p[gOffset] = g; - p[bOffset] = b; - } -} - -/*! - @brief Fill all or part of the NeoPixel strip with a color. - @param c 32-bit color value. Most significant byte is white (for - RGBW pixels) or ignored (for RGB pixels), next is red, - then green, and least significant byte is blue. If all - arguments are unspecified, this will be 0 (off). - @param first Index of first pixel to fill, starting from 0. Must be - in-bounds, no clipping is performed. 0 if unspecified. - @param count Number of pixels to fill, as a positive value. Passing - 0 or leaving unspecified will fill to end of strip. -*/ -void Adafruit_NeoPixel::fill(uint32_t c, uint16_t first, uint16_t count) { - uint16_t i, end; - - if (first >= numLEDs) { - return; // If first LED is past end of strip, nothing to do - } - - // Calculate the index ONE AFTER the last pixel to fill - if (count == 0) { - // Fill to end of strip - end = numLEDs; - } else { - // Ensure that the loop won't go past the last pixel - end = first + count; - if (end > numLEDs) - end = numLEDs; - } - - for (i = first; i < end; i++) { - this->setPixelColor(i, c); - } -} - -/*! - @brief Convert hue, saturation and value into a packed 32-bit RGB color - that can be passed to setPixelColor() or other RGB-compatible - functions. - @param hue An unsigned 16-bit value, 0 to 65535, representing one full - loop of the color wheel, which allows 16-bit hues to "roll - over" while still doing the expected thing (and allowing - more precision than the wheel() function that was common to - prior NeoPixel examples). - @param sat Saturation, 8-bit value, 0 (min or pure grayscale) to 255 - (max or pure hue). Default of 255 if unspecified. - @param val Value (brightness), 8-bit value, 0 (min / black / off) to - 255 (max or full brightness). Default of 255 if unspecified. - @return Packed 32-bit RGB with the most significant byte set to 0 -- the - white element of WRGB pixels is NOT utilized. Result is linearly - but not perceptually correct, so you may want to pass the result - through the gamma32() function (or your own gamma-correction - operation) else colors may appear washed out. This is not done - automatically by this function because coders may desire a more - refined gamma-correction function than the simplified - one-size-fits-all operation of gamma32(). Diffusing the LEDs also - really seems to help when using low-saturation colors. -*/ -uint32_t Adafruit_NeoPixel::ColorHSV(uint16_t hue, uint8_t sat, uint8_t val) { - - uint8_t r, g, b; - - // Remap 0-65535 to 0-1529. Pure red is CENTERED on the 64K rollover; - // 0 is not the start of pure red, but the midpoint...a few values above - // zero and a few below 65536 all yield pure red (similarly, 32768 is the - // midpoint, not start, of pure cyan). The 8-bit RGB hexcone (256 values - // each for red, green, blue) really only allows for 1530 distinct hues - // (not 1536, more on that below), but the full unsigned 16-bit type was - // chosen for hue so that one's code can easily handle a contiguous color - // wheel by allowing hue to roll over in either direction. - hue = (hue * 1530L + 32768) / 65536; - // Because red is centered on the rollover point (the +32768 above, - // essentially a fixed-point +0.5), the above actually yields 0 to 1530, - // where 0 and 1530 would yield the same thing. Rather than apply a - // costly modulo operator, 1530 is handled as a special case below. - - // So you'd think that the color "hexcone" (the thing that ramps from - // pure red, to pure yellow, to pure green and so forth back to red, - // yielding six slices), and with each color component having 256 - // possible values (0-255), might have 1536 possible items (6*256), - // but in reality there's 1530. This is because the last element in - // each 256-element slice is equal to the first element of the next - // slice, and keeping those in there this would create small - // discontinuities in the color wheel. So the last element of each - // slice is dropped...we regard only elements 0-254, with item 255 - // being picked up as element 0 of the next slice. Like this: - // Red to not-quite-pure-yellow is: 255, 0, 0 to 255, 254, 0 - // Pure yellow to not-quite-pure-green is: 255, 255, 0 to 1, 255, 0 - // Pure green to not-quite-pure-cyan is: 0, 255, 0 to 0, 255, 254 - // and so forth. Hence, 1530 distinct hues (0 to 1529), and hence why - // the constants below are not the multiples of 256 you might expect. - - // Convert hue to R,G,B (nested ifs faster than divide+mod+switch): - if (hue < 510) { // Red to Green-1 - b = 0; - if (hue < 255) { // Red to Yellow-1 - r = 255; - g = hue; // g = 0 to 254 - } else { // Yellow to Green-1 - r = 510 - hue; // r = 255 to 1 - g = 255; - } - } else if (hue < 1020) { // Green to Blue-1 - r = 0; - if (hue < 765) { // Green to Cyan-1 - g = 255; - b = hue - 510; // b = 0 to 254 - } else { // Cyan to Blue-1 - g = 1020 - hue; // g = 255 to 1 - b = 255; - } - } else if (hue < 1530) { // Blue to Red-1 - g = 0; - if (hue < 1275) { // Blue to Magenta-1 - r = hue - 1020; // r = 0 to 254 - b = 255; - } else { // Magenta to Red-1 - r = 255; - b = 1530 - hue; // b = 255 to 1 - } - } else { // Last 0.5 Red (quicker than % operator) - r = 255; - g = b = 0; - } - - // Apply saturation and value to R,G,B, pack into 32-bit result: - uint32_t v1 = 1 + val; // 1 to 256; allows >>8 instead of /255 - uint16_t s1 = 1 + sat; // 1 to 256; same reason - uint8_t s2 = 255 - sat; // 255 to 0 - return ((((((r * s1) >> 8) + s2) * v1) & 0xff00) << 8) | - (((((g * s1) >> 8) + s2) * v1) & 0xff00) | - (((((b * s1) >> 8) + s2) * v1) >> 8); -} - -/*! - @brief Query the color of a previously-set pixel. - @param n Index of pixel to read (0 = first). - @return 'Packed' 32-bit RGB or WRGB value. Most significant byte is white - (for RGBW pixels) or 0 (for RGB pixels), next is red, then green, - and least significant byte is blue. - @note If the strip brightness has been changed from the default value - of 255, the color read from a pixel may not exactly match what - was previously written with one of the setPixelColor() functions. - This gets more pronounced at lower brightness levels. -*/ -uint32_t Adafruit_NeoPixel::getPixelColor(uint16_t n) const { - if (n >= numLEDs) - return 0; // Out of bounds, return no color. - - uint8_t *p; - - if (wOffset == rOffset) { // Is RGB-type device - p = &pixels[n * 3]; - if (brightness) { - // Stored color was decimated by setBrightness(). Returned value - // attempts to scale back to an approximation of the original 24-bit - // value used when setting the pixel color, but there will always be - // some error -- those bits are simply gone. Issue is most - // pronounced at low brightness levels. - return (((uint32_t)(p[rOffset] << 8) / brightness) << 16) | - (((uint32_t)(p[gOffset] << 8) / brightness) << 8) | - ((uint32_t)(p[bOffset] << 8) / brightness); - } else { - // No brightness adjustment has been made -- return 'raw' color - return ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) | - (uint32_t)p[bOffset]; - } - } else { // Is RGBW-type device - p = &pixels[n * 4]; - if (brightness) { // Return scaled color - return (((uint32_t)(p[wOffset] << 8) / brightness) << 24) | - (((uint32_t)(p[rOffset] << 8) / brightness) << 16) | - (((uint32_t)(p[gOffset] << 8) / brightness) << 8) | - ((uint32_t)(p[bOffset] << 8) / brightness); - } else { // Return raw color - return ((uint32_t)p[wOffset] << 24) | ((uint32_t)p[rOffset] << 16) | - ((uint32_t)p[gOffset] << 8) | (uint32_t)p[bOffset]; - } - } -} - -/*! - @brief Adjust output brightness. Does not immediately affect what's - currently displayed on the LEDs. The next call to show() will - refresh the LEDs at this level. - @param b Brightness setting, 0=minimum (off), 255=brightest. - @note This was intended for one-time use in one's setup() function, - not as an animation effect in itself. Because of the way this - library "pre-multiplies" LED colors in RAM, changing the - brightness is often a "lossy" operation -- what you write to - pixels isn't necessary the same as what you'll read back. - Repeated brightness changes using this function exacerbate the - problem. Smart programs therefore treat the strip as a - write-only resource, maintaining their own state to render each - frame of an animation, not relying on read-modify-write. -*/ -void Adafruit_NeoPixel::setBrightness(uint8_t b) { - // Stored brightness value is different than what's passed. - // This simplifies the actual scaling math later, allowing a fast - // 8x8-bit multiply and taking the MSB. 'brightness' is a uint8_t, - // adding 1 here may (intentionally) roll over...so 0 = max brightness - // (color values are interpreted literally; no scaling), 1 = min - // brightness (off), 255 = just below max brightness. - uint8_t newBrightness = b + 1; - if (newBrightness != brightness) { // Compare against prior value - // Brightness has changed -- re-scale existing data in RAM, - // This process is potentially "lossy," especially when increasing - // brightness. The tight timing in the WS2811/WS2812 code means there - // aren't enough free cycles to perform this scaling on the fly as data - // is issued. So we make a pass through the existing color data in RAM - // and scale it (subsequent graphics commands also work at this - // brightness level). If there's a significant step up in brightness, - // the limited number of steps (quantization) in the old data will be - // quite visible in the re-scaled version. For a non-destructive - // change, you'll need to re-render the full strip data. C'est la vie. - uint8_t c, *ptr = pixels, - oldBrightness = brightness - 1; // De-wrap old brightness value - uint16_t scale; - if (oldBrightness == 0) - scale = 0; // Avoid /0 - else if (b == 255) - scale = 65535 / oldBrightness; - else - scale = (((uint16_t)newBrightness << 8) - 1) / oldBrightness; - for (uint16_t i = 0; i < numBytes; i++) { - c = *ptr; - *ptr++ = (c * scale) >> 8; - } - brightness = newBrightness; - } -} - -/*! - @brief Retrieve the last-set brightness value for the strip. - @return Brightness value: 0 = minimum (off), 255 = maximum. -*/ -uint8_t Adafruit_NeoPixel::getBrightness(void) const { return brightness - 1; } - -/*! - @brief Fill the whole NeoPixel strip with 0 / black / off. -*/ -void Adafruit_NeoPixel::clear(void) { memset(pixels, 0, numBytes); } - -// A 32-bit variant of gamma8() that applies the same function -// to all components of a packed RGB or WRGB value. -uint32_t Adafruit_NeoPixel::gamma32(uint32_t x) { - uint8_t *y = (uint8_t *)&x; - // All four bytes of a 32-bit value are filtered even if RGB (not WRGB), - // to avoid a bunch of shifting and masking that would be necessary for - // properly handling different endianisms (and each byte is a fairly - // trivial operation, so it might not even be wasting cycles vs a check - // and branch for the RGB case). In theory this might cause trouble *if* - // someone's storing information in the unused most significant byte - // of an RGB value, but this seems exceedingly rare and if it's - // encountered in reality they can mask values going in or coming out. - for (uint8_t i = 0; i < 4; i++) - y[i] = gamma8(y[i]); - return x; // Packed 32-bit return -} - -/*! - @brief Fill NeoPixel strip with one or more cycles of hues. - Everyone loves the rainbow swirl so much, now it's canon! - @param first_hue Hue of first pixel, 0-65535, representing one full - cycle of the color wheel. Each subsequent pixel will - be offset to complete one or more cycles over the - length of the strip. - @param reps Number of cycles of the color wheel over the length - of the strip. Default is 1. Negative values can be - used to reverse the hue order. - @param saturation Saturation (optional), 0-255 = gray to pure hue, - default = 255. - @param brightness Brightness/value (optional), 0-255 = off to max, - default = 255. This is distinct and in combination - with any configured global strip brightness. - @param gammify If true (default), apply gamma correction to colors - for better appearance. -*/ -void Adafruit_NeoPixel::rainbow(uint16_t first_hue, int8_t reps, - uint8_t saturation, uint8_t brightness, bool gammify) { - for (uint16_t i=0; i. - * - */ - -#ifndef ADAFRUIT_NEOPIXEL_H -#define ADAFRUIT_NEOPIXEL_H - -#ifdef ARDUINO -#if (ARDUINO >= 100) -#include -#else -#include -#include -#endif - -#ifdef USE_TINYUSB // For Serial when selecting TinyUSB -#include -#endif - -#endif - -#ifdef TARGET_LPC1768 -#include -#endif - -#if defined(ARDUINO_ARCH_RP2040) -#include -#include "hardware/pio.h" -#include "hardware/clocks.h" -#include "rp2040_pio.h" -#endif - -// The order of primary colors in the NeoPixel data stream can vary among -// device types, manufacturers and even different revisions of the same -// item. The third parameter to the Adafruit_NeoPixel constructor encodes -// the per-pixel byte offsets of the red, green and blue primaries (plus -// white, if present) in the data stream -- the following #defines provide -// an easier-to-use named version for each permutation. e.g. NEO_GRB -// indicates a NeoPixel-compatible device expecting three bytes per pixel, -// with the first byte transmitted containing the green value, second -// containing red and third containing blue. The in-memory representation -// of a chain of NeoPixels is the same as the data-stream order; no -// re-ordering of bytes is required when issuing data to the chain. -// Most of these values won't exist in real-world devices, but it's done -// this way so we're ready for it (also, if using the WS2811 driver IC, -// one might have their pixels set up in any weird permutation). - -// Bits 5,4 of this value are the offset (0-3) from the first byte of a -// pixel to the location of the red color byte. Bits 3,2 are the green -// offset and 1,0 are the blue offset. If it is an RGBW-type device -// (supporting a white primary in addition to R,G,B), bits 7,6 are the -// offset to the white byte...otherwise, bits 7,6 are set to the same value -// as 5,4 (red) to indicate an RGB (not RGBW) device. -// i.e. binary representation: -// 0bWWRRGGBB for RGBW devices -// 0bRRRRGGBB for RGB - -// RGB NeoPixel permutations; white and red offsets are always same -// Offset: W R G B -#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B -#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G -#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B -#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R -#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G -#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R - -// RGBW NeoPixel permutations; all 4 offsets are distinct -// Offset: W R G B -#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) ///< Transmit as W,R,G,B -#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) ///< Transmit as W,R,B,G -#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) ///< Transmit as W,G,R,B -#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) ///< Transmit as W,G,B,R -#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) ///< Transmit as W,B,R,G -#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) ///< Transmit as W,B,G,R - -#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) ///< Transmit as R,W,G,B -#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) ///< Transmit as R,W,B,G -#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) ///< Transmit as R,G,W,B -#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) ///< Transmit as R,G,B,W -#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) ///< Transmit as R,B,W,G -#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) ///< Transmit as R,B,G,W - -#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) ///< Transmit as G,W,R,B -#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) ///< Transmit as G,W,B,R -#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) ///< Transmit as G,R,W,B -#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W -#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,W,R -#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) ///< Transmit as G,B,R,W - -#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) ///< Transmit as B,W,R,G -#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) ///< Transmit as B,W,G,R -#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) ///< Transmit as B,R,W,G -#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) ///< Transmit as B,R,G,W -#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,W,R -#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) ///< Transmit as B,G,R,W - -// Add NEO_KHZ400 to the color order value to indicate a 400 KHz device. -// All but the earliest v1 NeoPixels expect an 800 KHz data stream, this is -// the default if unspecified. Because flash space is very limited on ATtiny -// devices (e.g. Trinket, Gemma), v1 NeoPixels aren't handled by default on -// those chips, though it can be enabled by removing the ifndef/endif below, -// but code will be bigger. Conversely, can disable the NEO_KHZ400 line on -// other MCUs to remove v1 support and save a little space. - -#define NEO_KHZ800 0x0000 ///< 800 KHz data transmission -#ifndef __AVR_ATtiny85__ -#define NEO_KHZ400 0x0100 ///< 400 KHz data transmission -#endif - -// If 400 KHz support is enabled, the third parameter to the constructor -// requires a 16-bit value (in order to select 400 vs 800 KHz speed). -// If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value -// is sufficient to encode pixel color order, saving some space. - -#ifdef NEO_KHZ400 -typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor -#else -typedef uint8_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor -#endif - -// These two tables are declared outside the Adafruit_NeoPixel class -// because some boards may require oldschool compilers that don't -// handle the C++11 constexpr keyword. - -/* A PROGMEM (flash mem) table containing 8-bit unsigned sine wave (0-255). - Copy & paste this snippet into a Python REPL to regenerate: -import math -for x in range(256): - print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _NeoPixelSineTable[256] = { - 128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, - 173, 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211, - 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240, - 241, 243, 244, 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, - 254, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, - 250, 250, 249, 248, 246, 245, 244, 243, 241, 240, 238, 237, 235, 234, 232, - 230, 228, 226, 224, 222, 220, 218, 215, 213, 211, 208, 206, 203, 201, 198, - 196, 193, 190, 188, 185, 182, 179, 176, 173, 170, 167, 165, 162, 158, 155, - 152, 149, 146, 143, 140, 137, 134, 131, 128, 124, 121, 118, 115, 112, 109, - 106, 103, 100, 97, 93, 90, 88, 85, 82, 79, 76, 73, 70, 67, 65, - 62, 59, 57, 54, 52, 49, 47, 44, 42, 40, 37, 35, 33, 31, 29, - 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6, - 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11, - 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, - 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76, - 79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121, - 124}; - -/* Similar to above, but for an 8-bit gamma-correction table. - Copy & paste this snippet into a Python REPL to regenerate: -import math -gamma=2.6 -for x in range(256): - print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _NeoPixelGammaTable[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, - 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, - 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, - 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, - 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, - 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, - 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, - 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, 97, 99, 100, 102, - 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 119, 120, 122, 124, 125, - 127, 129, 130, 132, 134, 136, 137, 139, 141, 143, 145, 146, 148, 150, 152, - 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, - 184, 186, 188, 191, 193, 195, 197, 199, 202, 204, 206, 209, 211, 213, 215, - 218, 220, 223, 225, 227, 230, 232, 235, 237, 240, 242, 245, 247, 250, 252, - 255}; - -/*! - @brief Class that stores state and functions for interacting with - Adafruit NeoPixels and compatible devices. -*/ -class Adafruit_NeoPixel { - -public: - // Constructor: number of LEDs, pin number, LED type - Adafruit_NeoPixel(uint16_t n, int16_t pin = 6, - neoPixelType type = NEO_GRB + NEO_KHZ800); - Adafruit_NeoPixel(void); - ~Adafruit_NeoPixel(); - - void begin(void); - void show(void); - void setPin(int16_t p); - void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); - void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w); - void setPixelColor(uint16_t n, uint32_t c); - void fill(uint32_t c = 0, uint16_t first = 0, uint16_t count = 0); - void setBrightness(uint8_t); - void clear(void); - void updateLength(uint16_t n); - void updateType(neoPixelType t); - /*! - @brief Check whether a call to show() will start sending data - immediately or will 'block' for a required interval. NeoPixels - require a short quiet time (about 300 microseconds) after the - last bit is received before the data 'latches' and new data can - start being received. Usually one's sketch is implicitly using - this time to generate a new frame of animation...but if it - finishes very quickly, this function could be used to see if - there's some idle time available for some low-priority - concurrent task. - @return 1 or true if show() will start sending immediately, 0 or false - if show() would block (meaning some idle time is available). - */ - bool canShow(void) { - // It's normal and possible for endTime to exceed micros() if the - // 32-bit clock counter has rolled over (about every 70 minutes). - // Since both are uint32_t, a negative delta correctly maps back to - // positive space, and it would seem like the subtraction below would - // suffice. But a problem arises if code invokes show() very - // infrequently...the micros() counter may roll over MULTIPLE times in - // that interval, the delta calculation is no longer correct and the - // next update may stall for a very long time. The check below resets - // the latch counter if a rollover has occurred. This can cause an - // extra delay of up to 300 microseconds in the rare case where a - // show() call happens precisely around the rollover, but that's - // neither likely nor especially harmful, vs. other code that might - // stall for 30+ minutes, or having to document and frequently remind - // and/or provide tech support explaining an unintuitive need for - // show() calls at least once an hour. - uint32_t now = micros(); - if (endTime > now) { - endTime = now; - } - return (now - endTime) >= 300L; - } - /*! - @brief Get a pointer directly to the NeoPixel data buffer in RAM. - Pixel data is stored in a device-native format (a la the NEO_* - constants) and is not translated here. Applications that access - this buffer will need to be aware of the specific data format - and handle colors appropriately. - @return Pointer to NeoPixel buffer (uint8_t* array). - @note This is for high-performance applications where calling - setPixelColor() on every single pixel would be too slow (e.g. - POV or light-painting projects). There is no bounds checking - on the array, creating tremendous potential for mayhem if one - writes past the ends of the buffer. Great power, great - responsibility and all that. - */ - uint8_t *getPixels(void) const { return pixels; }; - uint8_t getBrightness(void) const; - /*! - @brief Retrieve the pin number used for NeoPixel data output. - @return Arduino pin number (-1 if not set). - */ - int16_t getPin(void) const { return pin; }; - /*! - @brief Return the number of pixels in an Adafruit_NeoPixel strip object. - @return Pixel count (0 if not set). - */ - uint16_t numPixels(void) const { return numLEDs; } - uint32_t getPixelColor(uint16_t n) const; - /*! - @brief An 8-bit integer sine wave function, not directly compatible - with standard trigonometric units like radians or degrees. - @param x Input angle, 0-255; 256 would loop back to zero, completing - the circle (equivalent to 360 degrees or 2 pi radians). - One can therefore use an unsigned 8-bit variable and simply - add or subtract, allowing it to overflow/underflow and it - still does the expected contiguous thing. - @return Sine result, 0 to 255, or -128 to +127 if type-converted to - a signed int8_t, but you'll most likely want unsigned as this - output is often used for pixel brightness in animation effects. - */ - static uint8_t sine8(uint8_t x) { - return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out - } - /*! - @brief An 8-bit gamma-correction function for basic pixel brightness - adjustment. Makes color transitions appear more perceptially - correct. - @param x Input brightness, 0 (minimum or off/black) to 255 (maximum). - @return Gamma-adjusted brightness, can then be passed to one of the - setPixelColor() functions. This uses a fixed gamma correction - exponent of 2.6, which seems reasonably okay for average - NeoPixels in average tasks. If you need finer control you'll - need to provide your own gamma-correction function instead. - */ - static uint8_t gamma8(uint8_t x) { - return pgm_read_byte(&_NeoPixelGammaTable[x]); // 0-255 in, 0-255 out - } - /*! - @brief Convert separate red, green and blue values into a single - "packed" 32-bit RGB color. - @param r Red brightness, 0 to 255. - @param g Green brightness, 0 to 255. - @param b Blue brightness, 0 to 255. - @return 32-bit packed RGB value, which can then be assigned to a - variable for later use or passed to the setPixelColor() - function. Packed RGB format is predictable, regardless of - LED strand color order. - */ - static uint32_t Color(uint8_t r, uint8_t g, uint8_t b) { - return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; - } - /*! - @brief Convert separate red, green, blue and white values into a - single "packed" 32-bit WRGB color. - @param r Red brightness, 0 to 255. - @param g Green brightness, 0 to 255. - @param b Blue brightness, 0 to 255. - @param w White brightness, 0 to 255. - @return 32-bit packed WRGB value, which can then be assigned to a - variable for later use or passed to the setPixelColor() - function. Packed WRGB format is predictable, regardless of - LED strand color order. - */ - static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { - return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; - } - static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255); - /*! - @brief A gamma-correction function for 32-bit packed RGB or WRGB - colors. Makes color transitions appear more perceptially - correct. - @param x 32-bit packed RGB or WRGB color. - @return Gamma-adjusted packed color, can then be passed in one of the - setPixelColor() functions. Like gamma8(), this uses a fixed - gamma correction exponent of 2.6, which seems reasonably okay - for average NeoPixels in average tasks. If you need finer - control you'll need to provide your own gamma-correction - function instead. - */ - static uint32_t gamma32(uint32_t x); - - void rainbow(uint16_t first_hue = 0, int8_t reps = 1, - uint8_t saturation = 255, uint8_t brightness = 255, - bool gammify = true); - -private: -#if defined(ARDUINO_ARCH_RP2040) - void rp2040Init(uint8_t pin, bool is800KHz); - void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz); -#endif - -protected: -#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled... - bool is800KHz; ///< true if 800 KHz pixels -#endif - bool begun; ///< true if begin() previously called - uint16_t numLEDs; ///< Number of RGB LEDs in strip - uint16_t numBytes; ///< Size of 'pixels' buffer below - int16_t pin; ///< Output pin number (-1 if not yet set) - uint8_t brightness; ///< Strip brightness 0-255 (stored as +1) - uint8_t *pixels; ///< Holds LED color values (3 or 4 bytes each) - uint8_t rOffset; ///< Red index within each 3- or 4-byte pixel - uint8_t gOffset; ///< Index of green byte - uint8_t bOffset; ///< Index of blue byte - uint8_t wOffset; ///< Index of white (==rOffset if no white) - uint32_t endTime; ///< Latch timing reference -#ifdef __AVR__ - volatile uint8_t *port; ///< Output PORT register - uint8_t pinMask; ///< Output PORT bitmask -#endif -#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) - GPIO_TypeDef *gpioPort; ///< Output GPIO PORT - uint32_t gpioPin; ///< Output GPIO PIN -#endif -#if defined(ARDUINO_ARCH_RP2040) - PIO pio = pio0; - int sm = 0; - bool init = true; -#endif -}; - -#endif // ADAFRUIT_NEOPIXEL_H diff --git a/lib/Adafruit_NeoPixel/CONTRIBUTING.md b/lib/Adafruit_NeoPixel/CONTRIBUTING.md deleted file mode 100644 index aa753894e5..0000000000 --- a/lib/Adafruit_NeoPixel/CONTRIBUTING.md +++ /dev/null @@ -1,13 +0,0 @@ -# Contribution Guidelines - -This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/adafruit/Adafruit_NeoPixel/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. - -The following are some guidelines to observe when creating issues or PRs: - -- Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas - -- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets - -- Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: - -- Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library diff --git a/lib/Adafruit_NeoPixel/COPYING b/lib/Adafruit_NeoPixel/COPYING deleted file mode 100644 index 65c5ca88a6..0000000000 --- a/lib/Adafruit_NeoPixel/COPYING +++ /dev/null @@ -1,165 +0,0 @@ - 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. diff --git a/lib/Adafruit_NeoPixel/README.md b/lib/Adafruit_NeoPixel/README.md deleted file mode 100644 index eff1337119..0000000000 --- a/lib/Adafruit_NeoPixel/README.md +++ /dev/null @@ -1,157 +0,0 @@ -# Adafruit NeoPixel Library [![Build Status](https://github.com/adafruit/Adafruit_NeoPixel/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_NeoPixel/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_NeoPixel/html/index.html) - -Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield]. - -After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch. - -Compatibility notes: Port A is not supported on any AVR processors at this time - -[flora]: http://adafruit.com/products/1060 -[strip]: http://adafruit.com/products/1138 -[pixel]: http://adafruit.com/products/1312 -[stick]: http://adafruit.com/products/1426 -[shield]: http://adafruit.com/products/1430 - ---- - -## Installation - -### First Method - -![image](https://user-images.githubusercontent.com/36513474/68967967-3e37f480-0803-11ea-91d9-601848c306ee.png) - -1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries -1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. -1. Then search for Neopixel strip using the search bar. -1. Click on the text area and then select the specific version and install it. - -### Second Method - -1. Navigate to the [Releases page](https://github.com/adafruit/Adafruit_NeoPixel/releases). -1. Download the latest release. -1. Extract the zip file -1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library - -## Features - -- ### Simple to use - - Controlling NeoPixels “from scratch” is quite a challenge, so we provide a library letting you focus on the fun and interesting bits. - -- ### Give back - - The library is free; you don’t have to pay for anything. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! - -- ### Supported Chipsets - - We have included code for the following chips - sometimes these break for exciting reasons that we can't control in which case please open an issue! - - - AVR ATmega and ATtiny (any 8-bit) - 8 MHz, 12 MHz and 16 MHz - - Teensy 3.x and LC - - Arduino Due - - Arduino 101 - - ATSAMD21 (Arduino Zero/M0 and other SAMD21 boards) @ 48 MHz - - ATSAMD51 @ 120 MHz - - Adafruit STM32 Feather @ 120 MHz - - ESP8266 any speed - - ESP32 any speed - - Nordic nRF52 (Adafruit Feather nRF52), nRF51 (micro:bit) - - Infineon XMC1100 BootKit @ 32 MHz - - Infineon XMC1100 2Go @ 32 MHz - - Infineon XMC1300 BootKit @ 32 MHz - - Infineon XMC4700 RelaxKit, XMC4800 RelaxKit, XMC4800 IoT Amazon FreeRTOS Kit @ 144 MHz - - Check forks for other architectures not listed here! - -- ### GNU Lesser General Public License - - Adafruit_NeoPixel 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. - -## Functions - -- begin() -- updateLength() -- updateType() -- show() -- delay_ns() -- setPin() -- setPixelColor() -- fill() -- ColorHSV() -- getPixelColor() -- setBrightness() -- getBrightness() -- clear() -- gamma32() - -## Examples - -There are many examples implemented in this library. One of the examples is below. You can find other examples [here](https://github.com/adafruit/Adafruit_NeoPixel/tree/master/examples) - -### Simple - -```Cpp -#include -#ifdef __AVR__ - #include -#endif -#define PIN 6 -#define NUMPIXELS 16 - -Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); -#define DELAYVAL 500 - -void setup() { -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - - pixels.begin(); -} - -void loop() { - pixels.clear(); - - for(int i=0; i -#include "driver/rmt.h" - -#if defined(ESP_IDF_VERSION) -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) -#define HAS_ESP_IDF_4 -#endif -#endif - -// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered -// to work with the Arduino version of the ESP-IDF (3.2) - -#define WS2812_T0H_NS (400) -#define WS2812_T0L_NS (850) -#define WS2812_T1H_NS (800) -#define WS2812_T1L_NS (450) - -#define WS2811_T0H_NS (500) -#define WS2811_T0L_NS (2000) -#define WS2811_T1H_NS (1200) -#define WS2811_T1L_NS (1300) - -static uint32_t t0h_ticks = 0; -static uint32_t t1h_ticks = 0; -static uint32_t t0l_ticks = 0; -static uint32_t t1l_ticks = 0; - -// Limit the number of RMT channels available for the Neopixels. Defaults to all -// channels (8 on ESP32, 4 on ESP32-S2 and S3). Redefining this value will free -// any channels with a higher number for other uses, such as IR send-and-recieve -// libraries. Redefine as 1 to restrict Neopixels to only a single channel. -#define ADAFRUIT_RMT_CHANNEL_MAX RMT_CHANNEL_MAX - -#define RMT_LL_HW_BASE (&RMT) - -bool rmt_reserved_channels[ADAFRUIT_RMT_CHANNEL_MAX]; - -static void IRAM_ATTR ws2812_rmt_adapter(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; - } - const rmt_item32_t bit0 = {{{ t0h_ticks, 1, t0l_ticks, 0 }}}; //Logical 0 - const rmt_item32_t bit1 = {{{ t1h_ticks, 1, t1l_ticks, 0 }}}; //Logical 1 - size_t size = 0; - size_t num = 0; - uint8_t *psrc = (uint8_t *)src; - rmt_item32_t *pdest = dest; - while (size < src_size && num < wanted_num) { - for (int i = 0; i < 8; i++) { - // MSB first - if (*psrc & (1 << (7 - i))) { - pdest->val = bit1.val; - } else { - pdest->val = bit0.val; - } - num++; - pdest++; - } - size++; - psrc++; - } - *translated_size = size; - *item_num = num; -} - -void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { - // Reserve channel - rmt_channel_t channel = ADAFRUIT_RMT_CHANNEL_MAX; - for (size_t i = 0; i < ADAFRUIT_RMT_CHANNEL_MAX; i++) { - if (!rmt_reserved_channels[i]) { - rmt_reserved_channels[i] = true; - channel = i; - break; - } - } - if (channel == ADAFRUIT_RMT_CHANNEL_MAX) { - // Ran out of channels! - return; - } - -#if defined(HAS_ESP_IDF_4) - rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel); - config.clk_div = 2; -#else - // Match default TX config from ESP-IDF version 3.4 - rmt_config_t config = { - .rmt_mode = RMT_MODE_TX, - .channel = channel, - .gpio_num = pin, - .clk_div = 2, - .mem_block_num = 1, - .tx_config = { - .carrier_freq_hz = 38000, - .carrier_level = RMT_CARRIER_LEVEL_HIGH, - .idle_level = RMT_IDLE_LEVEL_LOW, - .carrier_duty_percent = 33, - .carrier_en = false, - .loop_en = false, - .idle_output_en = true, - } - }; -#endif - rmt_config(&config); - rmt_driver_install(config.channel, 0, 0); - - // Convert NS timings to ticks - uint32_t counter_clk_hz = 0; - -#if defined(HAS_ESP_IDF_4) - rmt_get_counter_clock(channel, &counter_clk_hz); -#else - // this emulates the rmt_get_counter_clock() function from ESP-IDF 3.4 - if (RMT_LL_HW_BASE->conf_ch[config.channel].conf1.ref_always_on == RMT_BASECLK_REF) { - uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt; - uint32_t div = div_cnt == 0 ? 256 : div_cnt; - counter_clk_hz = REF_CLK_FREQ / (div); - } else { - uint32_t div_cnt = RMT_LL_HW_BASE->conf_ch[config.channel].conf0.div_cnt; - uint32_t div = div_cnt == 0 ? 256 : div_cnt; - counter_clk_hz = APB_CLK_FREQ / (div); - } -#endif - - // NS to tick converter - float ratio = (float)counter_clk_hz / 1e9; - - if (is800KHz) { - t0h_ticks = (uint32_t)(ratio * WS2812_T0H_NS); - t0l_ticks = (uint32_t)(ratio * WS2812_T0L_NS); - t1h_ticks = (uint32_t)(ratio * WS2812_T1H_NS); - t1l_ticks = (uint32_t)(ratio * WS2812_T1L_NS); - } else { - t0h_ticks = (uint32_t)(ratio * WS2811_T0H_NS); - t0l_ticks = (uint32_t)(ratio * WS2811_T0L_NS); - t1h_ticks = (uint32_t)(ratio * WS2811_T1H_NS); - t1l_ticks = (uint32_t)(ratio * WS2811_T1L_NS); - } - - // Initialize automatic timing translator - rmt_translator_init(config.channel, ws2812_rmt_adapter); - - // Write and wait to finish - rmt_write_sample(config.channel, pixels, (size_t)numBytes, true); - rmt_wait_tx_done(config.channel, pdMS_TO_TICKS(100)); - - // Free channel again - rmt_driver_uninstall(config.channel); - rmt_reserved_channels[channel] = false; - - gpio_set_direction(pin, GPIO_MODE_OUTPUT); -} - -#endif diff --git a/lib/Adafruit_NeoPixel/esp8266.c b/lib/Adafruit_NeoPixel/esp8266.c deleted file mode 100644 index 51c3f3c8a3..0000000000 --- a/lib/Adafruit_NeoPixel/esp8266.c +++ /dev/null @@ -1,86 +0,0 @@ -// This is a mash-up of the Due show() code + insights from Michael Miller's -// ESP8266 work for the NeoPixelBus library: github.com/Makuna/NeoPixelBus -// Needs to be a separate .c file to enforce ICACHE_RAM_ATTR execution. - -#if defined(ESP8266) - -#include -#ifdef ESP8266 -#include -#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; -} - -#ifdef ESP8266 -IRAM_ATTR void espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, __attribute__((unused)) boolean is800KHz) { -#else -void espShow( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) { -#endif - -#define CYCLES_800_T0H (F_CPU / 2500001) // 0.4us -#define CYCLES_800_T1H (F_CPU / 1250001) // 0.8us -#define CYCLES_800 (F_CPU / 800001) // 1.25us per bit -#define CYCLES_400_T0H (F_CPU / 2000000) // 0.5uS -#define CYCLES_400_T1H (F_CPU / 833333) // 1.2us -#define CYCLES_400 (F_CPU / 400000) // 2.5us per bit - - uint8_t *p, *end, pix, mask; - uint32_t t, time0, time1, period, c, startTime; - -#ifdef ESP8266 - uint32_t pinMask; - pinMask = _BV(pin); -#endif - - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - startTime = 0; - -#ifdef NEO_KHZ400 - if(is800KHz) { -#endif - time0 = CYCLES_800_T0H; - time1 = CYCLES_800_T1H; - period = CYCLES_800; -#ifdef NEO_KHZ400 - } else { // 400 KHz bitstream - time0 = CYCLES_400_T0H; - time1 = CYCLES_400_T1H; - period = CYCLES_400; - } -#endif - - for(t = time0;; t = time0) { - if(pix & mask) t = time1; // Bit high duration - while(((c = _getCycleCount()) - startTime) < period); // Wait for bit start -#ifdef ESP8266 - GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinMask); // Set high -#else - gpio_set_level(pin, HIGH); -#endif - startTime = c; // Save start time - while(((c = _getCycleCount()) - startTime) < t); // Wait high duration -#ifdef ESP8266 - GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask); // Set low -#else - gpio_set_level(pin, LOW); -#endif - if(!(mask >>= 1)) { // Next bit/byte - if(p >= end) break; - pix = *p++; - mask = 0x80; - } - } - while((_getCycleCount() - startTime) < period); // Wait for last bit -} - -#endif // ESP8266 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.trinket.test.skip b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/.trinket.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino b/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino deleted file mode 100644 index 95335cdfce..0000000000 --- a/lib/Adafruit_NeoPixel/examples/RGBWstrandtest/RGBWstrandtest.ino +++ /dev/null @@ -1,177 +0,0 @@ -// NeoPixel test program showing use of the WHITE channel for RGBW -// pixels only (won't look correct on regular RGB NeoPixel strips). - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#define LED_PIN 6 - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// NeoPixel brightness, 0 (min) to 255 (max) -#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255) - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(BRIGHTNESS); -} - -void loop() { - // Fill along the length of the strip in various colors... - colorWipe(strip.Color(255, 0, 0) , 50); // Red - colorWipe(strip.Color( 0, 255, 0) , 50); // Green - colorWipe(strip.Color( 0, 0, 255) , 50); // Blue - colorWipe(strip.Color( 0, 0, 0, 255), 50); // True white (not RGB white) - - whiteOverRainbow(75, 5); - - pulseWhite(5); - - rainbowFade2White(3, 3, 1); -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i= strip.numPixels()) whiteLength = strip.numPixels() - 1; - - int head = whiteLength - 1; - int tail = 0; - int loops = 3; - int loopNum = 0; - uint32_t lastTime = millis(); - uint32_t firstPixelHue = 0; - - for(;;) { // Repeat forever (or until a 'break' or 'return') - for(int i=0; i= tail) && (i <= head)) || // If between head & tail... - ((tail > head) && ((i >= tail) || (i <= head)))) { - strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white - } else { // else set rainbow - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - } - - strip.show(); // Update strip with new contents - // There's no delay here, it just runs full-tilt until the timer and - // counter combination below runs out. - - firstPixelHue += 40; // Advance just a little along the color wheel - - if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail? - if(++head >= strip.numPixels()) { // Advance head, wrap around - head = 0; - if(++loopNum >= loops) return; - } - if(++tail >= strip.numPixels()) { // Advance tail, wrap around - tail = 0; - } - lastTime = millis(); // Save time of last movement - } - } -} - -void pulseWhite(uint8_t wait) { - for(int j=0; j<256; j++) { // Ramp up from 0 to 255 - // Fill entire strip with white at gamma-corrected brightness level 'j': - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - delay(wait); - } - - for(int j=255; j>=0; j--) { // Ramp down from 255 to 0 - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - delay(wait); - } -} - -void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) { - int fadeVal=0, fadeMax=100; - - // Hue of first pixel runs 'rainbowLoops' complete loops through the color - // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to rainbowLoops*65536, using steps of 256 so we - // advance around the wheel at a decent clip. - for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536; - firstPixelHue += 256) { - - for(int i=0; i= ((rainbowLoops-1) * 65536)) { // Last loop, - if(fadeVal > 0) fadeVal--; // fade out - } else { - fadeVal = fadeMax; // Interim loop, make sure fade is at max - } - } - - for(int k=0; k=0; j--) { // Ramp down 255 to 0 - strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); - strip.show(); - } - } - - delay(500); // Pause 1/2 second -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino deleted file mode 100644 index 80e02d21b3..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLE/StrandtestArduinoBLE.ino +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** - * This example is based on StrandtestBLE example and adapts it to use - * the new ArduinoBLE library. - * - * https://github.com/arduino-libraries/ArduinoBLE - * - * Supported boards: - * Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - * - * You can use a generic BLE central app, like LightBlue (iOS and Android) or - * nRF Connect (Android), to interact with the services and characteristics - * created in this sketch. - * - * This example code is in the public domain. - * - */ -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -uint8_t rgb_values[3]; - -#include - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service - -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - -void setup() -{ - Serial.begin(115200); - Serial.println("Hello World!"); - - // custom services and characteristics can be added as well - // begin initialization - if (!BLE.begin()) - { - Serial.println("starting BLE failed!"); - - while (1) - ; - } - - Serial.print("Peripheral address: "); - Serial.println(BLE.address()); - - // set advertised local name and service UUID: - BLE.setLocalName("LED"); - BLE.setAdvertisedService(ledService); - - // add the characteristic to the service - ledService.addCharacteristic(switchCharacteristic); - - // add service - BLE.addService(ledService); - - // set the initial value for the characeristic: - switchCharacteristic.writeValue(0); - - // start advertising - BLE.advertise(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - pinMode(PIN, OUTPUT); - digitalWrite(PIN, LOW); - -} - -void loop() -{ - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) - { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - - // while the central is still connected to peripheral: - while (central.connected()) - { - // if the remote device wrote to the characteristic, - // use the value to control the LED: - if (switchCharacteristic.written()) - { - switch (switchCharacteristic.value()) - { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color(0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color(0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color(0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } - } - } - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) -{ - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - strip.setPixelColor(i, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - delay(wait); // Pause for a moment - } -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) -{ - for (int a = 0; a < 10; a++) - { // Repeat 10 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in steps of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } - } -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(int wait) -{ - // Hue of first pixel runs 5 complete loops through the color wheel. - // Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time - // means we'll make 5*65536/256 = 1280 passes through this outer loop: - for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) - { - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - // Offset pixel hue by an amount to make one full revolution of the - // color wheel (range of 65536) along the length of the strip - // (strip.numPixels() steps): - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or - // optionally add saturation and value (brightness) (each 0 to 255). - // Here we're using just the single-argument hue variant. The result - // is passed through strip.gamma32() to provide 'truer' colors - // before assigning to each pixel: - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } -} - -// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. -void theaterChaseRainbow(int wait) -{ - int firstPixelHue = 0; // First pixel starts at red (hue 0) - for (int a = 0; a < 30; a++) - { // Repeat 30 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in increments of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - // hue of pixel 'c' is offset by an amount to make one full - // revolution of the color wheel (range 65536) along the length - // of the strip (strip.numPixels() steps): - int hue = firstPixelHue + c * 65536L / strip.numPixels(); - uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino b/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino deleted file mode 100644 index b986943ae4..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestArduinoBLECallback/StrandtestArduinoBLECallback.ino +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** - * This example is based on StrandtestArduinoBLE example to make use of - * callbacks features of the ArduinoBLE library. - * - * https://github.com/arduino-libraries/ArduinoBLE - * - * Supported boards: - * Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - * - * You can use a generic BLE central app, like LightBlue (iOS and Android) or - * nRF Connect (Android), to interact with the services and characteristics - * created in this sketch. - * - * This example code is in the public domain. - * - */ -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -uint8_t rgb_values[3]; - -#include - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service - -// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - -void setup() -{ - Serial.begin(115200); - Serial.println("Hello World!"); - - // custom services and characteristics can be added as well - // begin initialization - if (!BLE.begin()) - { - Serial.println("starting BLE failed!"); - - while (1) - ; - } - - Serial.print("Peripheral address: "); - Serial.println(BLE.address()); - - // set advertised local name and service UUID: - BLE.setLocalName("LEDCallback"); - BLE.setAdvertisedService(ledService); - - // add the characteristic to the service - ledService.addCharacteristic(switchCharacteristic); - - // add service - BLE.addService(ledService); - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - // assign event handlers for characteristic - switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); - // set the initial value for the characeristic: - switchCharacteristic.writeValue(0); - - // start advertising - BLE.advertise(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - pinMode(PIN, OUTPUT); - digitalWrite(PIN, LOW); -} - -void loop() -{ - // poll for BLE events - BLE.poll(); -} - -void blePeripheralConnectHandler(BLEDevice central) -{ - // central connected event handler - Serial.print("Connected event, central: "); - Serial.println(central.address()); -} - -void blePeripheralDisconnectHandler(BLEDevice central) -{ - // central disconnected event handler - Serial.print("Disconnected event, central: "); - Serial.println(central.address()); -} - -void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) -{ - // central wrote new value to characteristic, update LED - Serial.print("Characteristic event, written: "); - - switch (switchCharacteristic.value()) - { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color(0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color(0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color(0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) -{ - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - strip.setPixelColor(i, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - delay(wait); // Pause for a moment - } -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) -{ - for (int a = 0; a < 10; a++) - { // Repeat 10 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in steps of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } - } -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(int wait) -{ - // Hue of first pixel runs 5 complete loops through the color wheel. - // Color wheel has a range of 65536 but it's OK if we roll over, so - // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time - // means we'll make 5*65536/256 = 1280 passes through this outer loop: - for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) - { - for (int i = 0; i < strip.numPixels(); i++) - { // For each pixel in strip... - // Offset pixel hue by an amount to make one full revolution of the - // color wheel (range of 65536) along the length of the strip - // (strip.numPixels() steps): - int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); - // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or - // optionally add saturation and value (brightness) (each 0 to 255). - // Here we're using just the single-argument hue variant. The result - // is passed through strip.gamma32() to provide 'truer' colors - // before assigning to each pixel: - strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - } -} - -// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames. -void theaterChaseRainbow(int wait) -{ - int firstPixelHue = 0; // First pixel starts at red (hue 0) - for (int a = 0; a < 30; a++) - { // Repeat 30 times... - for (int b = 0; b < 3; b++) - { // 'b' counts from 0 to 2... - strip.clear(); // Set all pixels in RAM to 0 (off) - // 'c' counts up from 'b' to end of strip in increments of 3... - for (int c = b; c < strip.numPixels(); c += 3) - { - // hue of pixel 'c' is offset by an amount to make one full - // revolution of the color wheel (range 65536) along the length - // of the strip (strip.numPixels() steps): - int hue = firstPixelHue + c * 65536L / strip.numPixels(); - uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.arduinoble.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.arduinoble.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.none.test.only deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.test.skip b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp deleted file mode 100644 index d1693dec86..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "BLESerial.h" - -// #define BLE_SERIAL_DEBUG - -BLESerial* BLESerial::_instance = NULL; - -BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) : - BLEPeripheral(req, rdy, rst) -{ - this->_txCount = 0; - this->_rxHead = this->_rxTail = 0; - this->_flushed = 0; - BLESerial::_instance = this; - - addAttribute(this->_uartService); - addAttribute(this->_uartNameDescriptor); - setAdvertisedServiceUuid(this->_uartService.uuid()); - addAttribute(this->_rxCharacteristic); - addAttribute(this->_rxNameDescriptor); - this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received); - addAttribute(this->_txCharacteristic); - addAttribute(this->_txNameDescriptor); -} - -void BLESerial::begin(...) { - BLEPeripheral::begin(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::begin()")); - #endif -} - -void BLESerial::poll() { - if (millis() < this->_flushed + 100) { - BLEPeripheral::poll(); - } else { - flush(); - } -} - -void BLESerial::end() { - this->_rxCharacteristic.setEventHandler(BLEWritten, NULL); - this->_rxHead = this->_rxTail = 0; - flush(); - BLEPeripheral::disconnect(); -} - -int BLESerial::available(void) { - BLEPeripheral::poll(); - int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::available() = ")); - Serial.println(retval); - #endif - return retval; -} - -int BLESerial::peek(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::peek() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -int BLESerial::read(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer); - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::read() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -void BLESerial::flush(void) { - if (this->_txCount == 0) return; - this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount); - this->_flushed = millis(); - this->_txCount = 0; - BLEPeripheral::poll(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::flush()")); - #endif -} - -size_t BLESerial::write(uint8_t byte) { - BLEPeripheral::poll(); - if (this->_txCharacteristic.subscribed() == false) return 0; - this->_txBuffer[this->_txCount++] = byte; - if (this->_txCount == sizeof(this->_txBuffer)) flush(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::write(")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.print(byte, HEX); - Serial.println(F(") = 1")); - #endif - return 1; -} - -BLESerial::operator bool() { - bool retval = BLEPeripheral::connected(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::operator bool() = ")); - Serial.println(retval); - #endif - return retval; -} - -void BLESerial::_received(const uint8_t* data, size_t size) { - for (int i = 0; i < size; i++) { - this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer); - this->_rxBuffer[this->_rxHead] = data[i]; - } - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::received(")); - for (int i = 0; i < size; i++) Serial.print((char) data[i]); - Serial.println(F(")")); - #endif -} - -void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) { - BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength()); -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h deleted file mode 100644 index 01904c7885..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/BLESerial.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _BLE_SERIAL_H_ -#define _BLE_SERIAL_H_ - -#include -#include - -class BLESerial : public BLEPeripheral, public Stream -{ - public: - BLESerial(unsigned char req, unsigned char rdy, unsigned char rst); - - void begin(...); - void poll(); - void end(); - - virtual int available(void); - virtual int peek(void); - virtual int read(void); - virtual void flush(void); - virtual size_t write(uint8_t byte); - using Print::write; - virtual operator bool(); - - private: - unsigned long _flushed; - static BLESerial* _instance; - - size_t _rxHead; - size_t _rxTail; - size_t _rxCount() const; - uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - size_t _txCount; - uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - - BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); - BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART"); - BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)"); - BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)"); - - void _received(const uint8_t* data, size_t size); - static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic); -}; - -#endif diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino b/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino deleted file mode 100644 index 593b35b6d5..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE/StrandtestBLE.ino +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** - * This example was developed by the Hackerspace San Salvador to demonstrate - * the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice. - * To compile this example you'll need to add support for the NRF52 based - * following the instructions at: - * https://github.com/sandeepmistry/arduino-nRF5 - * Or adding the following URL to the board manager URLs on Arduino preferences: - * https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json - * Then you can install the BLEPeripheral library avaiable at: - * https://github.com/sandeepmistry/arduino-BLEPeripheral - * To test it, compile this example and use the UART module from the nRF - * Toolbox App for Android. Edit the interface and send the characters - * 'a' to 'i' to switch the animation. - * There is a delay because this example blocks the thread of execution but - * the change will be shown after the current animation ends. (This might - * take a couple of seconds) - * For more info write us at: info _at- teubi.co - */ -#include -#include -#include "BLESerial.h" -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -// define pins (varies per shield/board) -#define BLE_REQ 10 -#define BLE_RDY 2 -#define BLE_RST 9 - -// create ble serial instance, see pinouts above -BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST); - -uint8_t current_state = 0; -uint8_t rgb_values[3]; - -void setup() { - Serial.begin(115200); - Serial.println("Hello World!"); - // custom services and characteristics can be added as well - BLESerial.setLocalName("UART_HS"); - BLESerial.begin(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - //pinMode(PIN, OUTPUT); - //digitalWrite(PIN, LOW); - - current_state = 'a'; -} - -void loop() { - while(BLESerial.available()) { - uint8_t character = BLESerial.read(); - switch(character) { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - current_state = character; - break; - }; - } - switch(current_state) { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color( 0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color( 0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color( 0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only deleted file mode 100644 index 8b13789179..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/.none.test.only +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp deleted file mode 100644 index d1693dec86..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "BLESerial.h" - -// #define BLE_SERIAL_DEBUG - -BLESerial* BLESerial::_instance = NULL; - -BLESerial::BLESerial(unsigned char req, unsigned char rdy, unsigned char rst) : - BLEPeripheral(req, rdy, rst) -{ - this->_txCount = 0; - this->_rxHead = this->_rxTail = 0; - this->_flushed = 0; - BLESerial::_instance = this; - - addAttribute(this->_uartService); - addAttribute(this->_uartNameDescriptor); - setAdvertisedServiceUuid(this->_uartService.uuid()); - addAttribute(this->_rxCharacteristic); - addAttribute(this->_rxNameDescriptor); - this->_rxCharacteristic.setEventHandler(BLEWritten, BLESerial::_received); - addAttribute(this->_txCharacteristic); - addAttribute(this->_txNameDescriptor); -} - -void BLESerial::begin(...) { - BLEPeripheral::begin(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::begin()")); - #endif -} - -void BLESerial::poll() { - if (millis() < this->_flushed + 100) { - BLEPeripheral::poll(); - } else { - flush(); - } -} - -void BLESerial::end() { - this->_rxCharacteristic.setEventHandler(BLEWritten, NULL); - this->_rxHead = this->_rxTail = 0; - flush(); - BLEPeripheral::disconnect(); -} - -int BLESerial::available(void) { - BLEPeripheral::poll(); - int retval = (this->_rxHead - this->_rxTail + sizeof(this->_rxBuffer)) % sizeof(this->_rxBuffer); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::available() = ")); - Serial.println(retval); - #endif - return retval; -} - -int BLESerial::peek(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::peek() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -int BLESerial::read(void) { - BLEPeripheral::poll(); - if (this->_rxTail == this->_rxHead) return -1; - this->_rxTail = (this->_rxTail + 1) % sizeof(this->_rxBuffer); - uint8_t byte = this->_rxBuffer[this->_rxTail]; - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::read() = ")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.println(byte, HEX); - #endif - return byte; -} - -void BLESerial::flush(void) { - if (this->_txCount == 0) return; - this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount); - this->_flushed = millis(); - this->_txCount = 0; - BLEPeripheral::poll(); - #ifdef BLE_SERIAL_DEBUG - Serial.println(F("BLESerial::flush()")); - #endif -} - -size_t BLESerial::write(uint8_t byte) { - BLEPeripheral::poll(); - if (this->_txCharacteristic.subscribed() == false) return 0; - this->_txBuffer[this->_txCount++] = byte; - if (this->_txCount == sizeof(this->_txBuffer)) flush(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::write(")); - Serial.print((char) byte); - Serial.print(F(" 0x")); - Serial.print(byte, HEX); - Serial.println(F(") = 1")); - #endif - return 1; -} - -BLESerial::operator bool() { - bool retval = BLEPeripheral::connected(); - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::operator bool() = ")); - Serial.println(retval); - #endif - return retval; -} - -void BLESerial::_received(const uint8_t* data, size_t size) { - for (int i = 0; i < size; i++) { - this->_rxHead = (this->_rxHead + 1) % sizeof(this->_rxBuffer); - this->_rxBuffer[this->_rxHead] = data[i]; - } - #ifdef BLE_SERIAL_DEBUG - Serial.print(F("BLESerial::received(")); - for (int i = 0; i < size; i++) Serial.print((char) data[i]); - Serial.println(F(")")); - #endif -} - -void BLESerial::_received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic) { - BLESerial::_instance->_received(rxCharacteristic.value(), rxCharacteristic.valueLength()); -} diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h deleted file mode 100644 index 01904c7885..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/BLESerial.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _BLE_SERIAL_H_ -#define _BLE_SERIAL_H_ - -#include -#include - -class BLESerial : public BLEPeripheral, public Stream -{ - public: - BLESerial(unsigned char req, unsigned char rdy, unsigned char rst); - - void begin(...); - void poll(); - void end(); - - virtual int available(void); - virtual int peek(void); - virtual int read(void); - virtual void flush(void); - virtual size_t write(uint8_t byte); - using Print::write; - virtual operator bool(); - - private: - unsigned long _flushed; - static BLESerial* _instance; - - size_t _rxHead; - size_t _rxTail; - size_t _rxCount() const; - uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - size_t _txCount; - uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH]; - - BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"); - BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART"); - BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)"); - BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); - BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)"); - - void _received(const uint8_t* data, size_t size); - static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic); -}; - -#endif diff --git a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino b/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino deleted file mode 100644 index 20c924d014..0000000000 --- a/lib/Adafruit_NeoPixel/examples/StrandtestBLE_nodelay/StrandtestBLE_nodelay.ino +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** - * This example was developed by the Hackerspace San Salvador to demonstrate - * the simultaneous use of the NeoPixel library and the Bluetooth SoftDevice. - * To compile this example you'll need to add support for the NRF52 based - * following the instructions at: - * https://github.com/sandeepmistry/arduino-nRF5 - * Or adding the following URL to the board manager URLs on Arduino preferences: - * https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json - * Then you can install the BLEPeripheral library avaiable at: - * https://github.com/sandeepmistry/arduino-BLEPeripheral - * To test it, compile this example and use the UART module from the nRF - * Toolbox App for Android. Edit the interface and send the characters - * 'a' to 'i' to switch the animation. - * There is a no delay because this example does not block the threads execution - * so the change will be shown immediately and will not need to wait for the current - * animation to end. - * For more info write us at: info _at- teubi.co - */ -#include -#include -#include "BLESerial.h" -#include - -#define PIN 15 // Pin where NeoPixels are connected - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(64, PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -// define pins (varies per shield/board) -#define BLE_REQ 10 -#define BLE_RDY 2 -#define BLE_RST 9 - -// create ble serial instance, see pinouts above -BLESerial BLESerial(BLE_REQ, BLE_RDY, BLE_RST); - -uint8_t current_state = 0; -uint8_t rgb_values[3]; - -void setup() { - Serial.begin(115200); - Serial.println("Hello World!"); - // custom services and characteristics can be added as well - BLESerial.setLocalName("UART_HS"); - BLESerial.begin(); - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - - //pinMode(PIN, OUTPUT); - //digitalWrite(PIN, LOW); - - current_state = 'a'; -} - -void loop() { - while(BLESerial.available()) { - uint8_t character = BLESerial.read(); - switch(character) { - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - current_state = character; - break; - }; - } - switch(current_state) { - case 'a': - colorWipe(strip.Color(255, 0, 0), 20); // Red - break; - case 'b': - colorWipe(strip.Color( 0, 255, 0), 20); // Green - break; - case 'c': - colorWipe(strip.Color( 0, 0, 255), 20); // Blue - break; - case 'd': - theaterChase(strip.Color(255, 0, 0), 20); // Red - break; - case 'e': - theaterChase(strip.Color( 0, 255, 0), 20); // Green - break; - case 'f': - theaterChase(strip.Color(255, 0, 255), 20); // Cyan - break; - case 'g': - rainbow(10); - break; - case 'h': - theaterChaseRainbow(20); - break; - } -} - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - pixelCurrent++; // Advance current pixel - if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED - pixelCurrent = 0; -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i = 0; i < pixelNumber; i++) { - strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM) - } - strip.show(); // Update strip to match - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM) - } - pixelQueue++; // Advance current pixel - if(pixelQueue >= 3) - pixelQueue = 0; // Loop the pattern from the first LED -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; - for(uint16_t i=0; i < pixelNumber; i++) { - strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time - } - strip.show(); // Update strip to match - pixelCycle++; // Advance current cycle - if(pixelCycle >= 256) - pixelCycle = 0; // Loop the cycle back to the begining -} - -//Theatre-style crawling lights with rainbow effect -void theaterChaseRainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time - } - strip.show(); - for(int i=0; i < pixelNumber; i+3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time - } - pixelQueue++; // Advance current queue - pixelCycle++; // Advance current cycle - if(pixelQueue >= 3) - pixelQueue = 0; // Loop - if(pixelCycle >= 256) - pixelCycle = 0; // Loop -} - -// Input a value 0 to 255 to get a color value. -// The colours are a transition r - g - b - back to r. -uint32_t Wheel(byte WheelPos) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } - if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); - } - WheelPos -= 170; - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); -} diff --git a/lib/Adafruit_NeoPixel/examples/buttoncycler/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/buttoncycler/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino b/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino deleted file mode 100644 index f6d87edcb3..0000000000 --- a/lib/Adafruit_NeoPixel/examples/buttoncycler/buttoncycler.ino +++ /dev/null @@ -1,164 +0,0 @@ -// Simple demonstration on using an input device to trigger changes on your -// NeoPixels. Wire a momentary push button to connect from ground to a -// digital IO pin. When the button is pressed it will change to a new pixel -// animation. Initial state has all pixels off -- press the button once to -// start the first animation. As written, the button does not interrupt an -// animation in-progress, it works only when idle. - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Digital IO pin connected to the button. This will be driven with a -// pull-up resistor so the switch pulls the pin to ground momentarily. -// On a high -> low transition the button press logic will execute. -#define BUTTON_PIN 2 - -#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels. - -#define PIXEL_COUNT 16 // Number of NeoPixels - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -boolean oldState = HIGH; -int mode = 0; // Currently-active animation mode, 0-9 - -void setup() { - pinMode(BUTTON_PIN, INPUT_PULLUP); - strip.begin(); // Initialize NeoPixel strip object (REQUIRED) - strip.show(); // Initialize all pixels to 'off' -} - -void loop() { - // Get current button state. - boolean newState = digitalRead(BUTTON_PIN); - - // Check if state changed from high to low (button press). - if((newState == LOW) && (oldState == HIGH)) { - // Short delay to debounce button. - delay(20); - // Check if button is still low after debounce. - newState = digitalRead(BUTTON_PIN); - if(newState == LOW) { // Yes, still low - if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8 - switch(mode) { // Start the new animation... - case 0: - colorWipe(strip.Color( 0, 0, 0), 50); // Black/off - break; - case 1: - colorWipe(strip.Color(255, 0, 0), 50); // Red - break; - case 2: - colorWipe(strip.Color( 0, 255, 0), 50); // Green - break; - case 3: - colorWipe(strip.Color( 0, 0, 255), 50); // Blue - break; - case 4: - theaterChase(strip.Color(127, 127, 127), 50); // White - break; - case 5: - theaterChase(strip.Color(127, 0, 0), 50); // Red - break; - case 6: - theaterChase(strip.Color( 0, 0, 127), 50); // Blue - break; - case 7: - rainbow(10); - break; - case 8: - theaterChaseRainbow(50); - break; - } - } - } - - // Set the last-read button state to the old state. - oldState = newState; -} - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/simple/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/simple/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/simple/simple.ino b/lib/Adafruit_NeoPixel/examples/simple/simple.ino deleted file mode 100644 index 09f458ecbe..0000000000 --- a/lib/Adafruit_NeoPixel/examples/simple/simple.ino +++ /dev/null @@ -1,50 +0,0 @@ -// NeoPixel Ring simple sketch (c) 2013 Shae Erisson -// Released under the GPLv3 license to match the rest of the -// Adafruit NeoPixel library - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -#define PIN 6 // On Trinket or Gemma, suggest changing this to 1 - -// How many NeoPixels are attached to the Arduino? -#define NUMPIXELS 16 // Popular NeoPixel ring size - -// When setting up the NeoPixel library, we tell it how many pixels, -// and which pin to use to send signals. Note that for older NeoPixel -// strips you might need to change the third parameter -- see the -// strandtest example for more information on possible values. -Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); - -#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) -} - -void loop() { - pixels.clear(); // Set all pixel colors to 'off' - - // The first NeoPixel in a strand is #0, second is 1, all the way up - // to the count of pixels minus one. - for(int i=0; i -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -int pin = 6; // On Trinket or Gemma, suggest changing this to 1 - -// How many NeoPixels are attached to the Arduino? -int numPixels = 16; // Popular NeoPixel ring size - -// NeoPixel color format & data rate. See the strandtest example for -// information on possible values. -int pixelFormat = NEO_GRB + NEO_KHZ800; - -// Rather than declaring the whole NeoPixel object here, we just create -// a pointer for one, which we'll then allocate later... -Adafruit_NeoPixel *pixels; - -#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - // Right about here is where we could read 'pin', 'numPixels' and/or - // 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple - // example and doesn't do that -- those variables are just set to fixed - // values at the top of this code -- but this is where it would happen. - - // Then create a new NeoPixel object dynamically with these values: - pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat); - - // Going forward from here, code works almost identically to any other - // NeoPixel example, but instead of the dot operator on function calls - // (e.g. pixels.begin()), we instead use pointer indirection (->) like so: - pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - // You'll see more of this in the loop() function below. -} - -void loop() { - pixels->clear(); // Set all pixel colors to 'off' - - // The first NeoPixel in a strand is #0, second is 1, all the way up - // to the count of pixels minus one. - for(int i=0; iColor() takes RGB values, from 0,0,0 up to 255,255,255 - // Here we're using a moderately bright green color: - pixels->setPixelColor(i, pixels->Color(0, 150, 0)); - - pixels->show(); // Send the updated pixel colors to the hardware. - - delay(DELAYVAL); // Pause before next pass through loop - } -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino b/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino deleted file mode 100644 index f4554cc82a..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest/strandtest.ino +++ /dev/null @@ -1,143 +0,0 @@ -// A basic everyday NeoPixel strip test program. - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#define LED_PIN 6 - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - - -// setup() function -- runs once at startup -------------------------------- - -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) -} - - -// loop() function -- runs repeatedly as long as board is on --------------- - -void loop() { - // Fill along the length of the strip in various colors... - colorWipe(strip.Color(255, 0, 0), 50); // Red - colorWipe(strip.Color( 0, 255, 0), 50); // Green - colorWipe(strip.Color( 0, 0, 255), 50); // Blue - - // Do a theater marquee effect in various colors... - theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness - theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness - theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness - - rainbow(10); // Flowing rainbow cycle along the whole strip - theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant -} - - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - for(int i=0; i RGB - strip.setPixelColor(c, color); // Set pixel 'c' to value 'color' - } - strip.show(); // Update strip with new contents - delay(wait); // Pause for a moment - firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames - } - } -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip deleted file mode 100644 index 8b13789179..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/.esp8266.test.skip +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino b/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino deleted file mode 100644 index 9c392e2be7..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_nodelay/strandtest_nodelay.ino +++ /dev/null @@ -1,186 +0,0 @@ -// A non-blocking everyday NeoPixel strip test program. - -// NEOPIXEL BEST PRACTICES for most reliable operation: -// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. -// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. -// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. -// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS -// connect GROUND (-) first, then +, then data. -// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, -// a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. -// (Skipping these may work OK on your workbench but can fail in the field) - -#include -#ifdef __AVR__ - #include // Required for 16 MHz Adafruit Trinket -#endif - -// Which pin on the Arduino is connected to the NeoPixels? -// On a Trinket or Gemma we suggest changing this to 1: -#ifdef ESP32 -// Cannot use 6 as output for ESP. Pins 6-11 are connected to SPI flash. Use 16 instead. -#define LED_PIN 16 -#else -#define LED_PIN 6 -#endif - -// How many NeoPixels are attached to the Arduino? -#define LED_COUNT 60 - -// Declare our NeoPixel strip object: -Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); -// Argument 1 = Number of pixels in NeoPixel strip -// Argument 2 = Arduino pin number (most are valid) -// Argument 3 = Pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -unsigned long pixelPrevious = 0; // Previous Pixel Millis -unsigned long patternPrevious = 0; // Previous Pattern Millis -int patternCurrent = 0; // Current Pattern Number -int patternInterval = 5000; // Pattern Interval (ms) -int pixelInterval = 50; // Pixel Interval (ms) -int pixelQueue = 0; // Pattern Pixel Queue -int pixelCycle = 0; // Pattern Pixel Cycle -uint16_t pixelCurrent = 0; // Pattern Current Pixel Number -uint16_t pixelNumber = LED_COUNT; // Total Number of Pixels - -// setup() function -- runs once at startup -------------------------------- -void setup() { - // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. - // Any other board, you can remove this part (but no harm leaving it): -#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) - clock_prescale_set(clock_div_1); -#endif - // END of Trinket-specific code. - - strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) - strip.show(); // Turn OFF all pixels ASAP - strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) -} - -// loop() function -- runs repeatedly as long as board is on --------------- -void loop() { - unsigned long currentMillis = millis(); // Update current time - if((currentMillis - patternPrevious) >= patternInterval) { // Check for expired time - patternPrevious = currentMillis; - patternCurrent++; // Advance to next pattern - if(patternCurrent >= 7) - patternCurrent = 0; - } - - if(currentMillis - pixelPrevious >= pixelInterval) { // Check for expired time - pixelPrevious = currentMillis; // Run current frame - switch (patternCurrent) { - case 7: - theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant - break; - case 6: - rainbow(10); // Flowing rainbow cycle along the whole strip - break; - case 5: - theaterChase(strip.Color(0, 0, 127), 50); // Blue - break; - case 4: - theaterChase(strip.Color(127, 0, 0), 50); // Red - break; - case 3: - theaterChase(strip.Color(127, 127, 127), 50); // White - break; - case 2: - colorWipe(strip.Color(0, 0, 255), 50); // Blue - break; - case 1: - colorWipe(strip.Color(0, 255, 0), 50); // Green - break; - default: - colorWipe(strip.Color(255, 0, 0), 50); // Red - break; - } - } -} - -// Some functions of our own for creating animated effects ----------------- - -// Fill strip pixels one after another with a color. Strip is NOT cleared -// first; anything there will be covered pixel by pixel. Pass in color -// (as a single 'packed' 32-bit value, which you can get by calling -// strip.Color(red, green, blue) as shown in the loop() function above), -// and a delay time (in milliseconds) between pixels. -void colorWipe(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - strip.setPixelColor(pixelCurrent, color); // Set pixel's color (in RAM) - strip.show(); // Update strip to match - pixelCurrent++; // Advance current pixel - if(pixelCurrent >= pixelNumber) // Loop the pattern from the first LED - pixelCurrent = 0; -} - -// Theater-marquee-style chasing lights. Pass in a color (32-bit value, -// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms) -// between frames. -void theaterChase(uint32_t color, int wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i = 0; i < pixelNumber; i++) { - strip.setPixelColor(i + pixelQueue, color); // Set pixel's color (in RAM) - } - strip.show(); // Update strip to match - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Set pixel's color (in RAM) - } - pixelQueue++; // Advance current pixel - if(pixelQueue >= 3) - pixelQueue = 0; // Loop the pattern from the first LED -} - -// Rainbow cycle along whole strip. Pass delay time (in ms) between frames. -void rainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; - for(uint16_t i=0; i < pixelNumber; i++) { - strip.setPixelColor(i, Wheel((i + pixelCycle) & 255)); // Update delay time - } - strip.show(); // Update strip to match - pixelCycle++; // Advance current cycle - if(pixelCycle >= 256) - pixelCycle = 0; // Loop the cycle back to the begining -} - -//Theatre-style crawling lights with rainbow effect -void theaterChaseRainbow(uint8_t wait) { - if(pixelInterval != wait) - pixelInterval = wait; // Update delay time - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, Wheel((i + pixelCycle) % 255)); // Update delay time - } - strip.show(); - for(int i=0; i < pixelNumber; i+=3) { - strip.setPixelColor(i + pixelQueue, strip.Color(0, 0, 0)); // Update delay time - } - pixelQueue++; // Advance current queue - pixelCycle++; // Advance current cycle - if(pixelQueue >= 3) - pixelQueue = 0; // Loop - if(pixelCycle >= 256) - pixelCycle = 0; // Loop -} - -// Input a value 0 to 255 to get a color value. -// The colours are a transition r - g - b - back to r. -uint32_t Wheel(byte WheelPos) { - WheelPos = 255 - WheelPos; - if(WheelPos < 85) { - return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); - } - if(WheelPos < 170) { - WheelPos -= 85; - return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); - } - WheelPos -= 170; - return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); -} diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/.esp8266.test.skip b/lib/Adafruit_NeoPixel/examples/strandtest_wheel/.esp8266.test.skip deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino b/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino deleted file mode 100644 index c0ca41edcb..0000000000 --- a/lib/Adafruit_NeoPixel/examples/strandtest_wheel/strandtest_wheel.ino +++ /dev/null @@ -1,134 +0,0 @@ -#include -#ifdef __AVR__ - #include -#endif - -#define PIN 6 - -// Parameter 1 = number of pixels in strip -// Parameter 2 = Arduino pin number (most are valid) -// Parameter 3 = pixel type flags, add together as needed: -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) -Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); - -// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across -// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input -// and minimize distance between Arduino and first pixel. Avoid connecting -// on a live circuit...if you must, connect GND first. - -void setup() { - // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket - #if defined (__AVR_ATtiny85__) - if (F_CPU == 16000000) clock_prescale_set(clock_div_1); - #endif - // End of trinket special code - - strip.begin(); - strip.setBrightness(50); - strip.show(); // Initialize all pixels to 'off' -} - -void loop() { - // Some example procedures showing how to display to the pixels: - colorWipe(strip.Color(255, 0, 0), 50); // Red - colorWipe(strip.Color(0, 255, 0), 50); // Green - colorWipe(strip.Color(0, 0, 255), 50); // Blue -//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW - // Send a theater pixel chase in... - theaterChase(strip.Color(127, 127, 127), 50); // White - theaterChase(strip.Color(127, 0, 0), 50); // Red - theaterChase(strip.Color(0, 0, 127), 50); // Blue - - rainbow(20); - rainbowCycle(20); - theaterChaseRainbow(50); -} - -// Fill the dots one after the other with a color -void colorWipe(uint32_t c, uint8_t wait) { - for(uint16_t i=0; i -#include "sysctl.h" - -void k210Show( - uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) -{ - -#define CYCLES_800_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2500000) // 0.4us -#define CYCLES_800_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1250000) // 0.8us -#define CYCLES_800 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 800000) // 1.25us per bit -#define CYCLES_400_T0H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 2000000) // 0.5uS -#define CYCLES_400_T1H (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 833333) // 1.2us -#define CYCLES_400 (sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 400000) // 2.5us per bit - - uint8_t *p, *end, pix, mask; - uint32_t t, time0, time1, period, c, startTime; - - p = pixels; - end = p + numBytes; - pix = *p++; - mask = 0x80; - startTime = 0; - -#ifdef NEO_KHZ400 - if (is800KHz) - { -#endif - time0 = CYCLES_800_T0H; - time1 = CYCLES_800_T1H; - period = CYCLES_800; -#ifdef NEO_KHZ400 - } - else - { // 400 KHz bitstream - time0 = CYCLES_400_T0H; - time1 = CYCLES_400_T1H; - period = CYCLES_400; - } -#endif - - for (t = time0;; t = time0) - { - if (pix & mask) - t = time1; // Bit high duration - while (((c = read_cycle()) - startTime) < period) - ; // Wait for bit start - digitalWrite(pin, HIGH); - startTime = c; // Save start time - while (((c = read_cycle()) - startTime) < t) - ; // Wait high duration - digitalWrite(pin, LOW); - - if (!(mask >>= 1)) - { // Next bit/byte - if (p >= end) - break; - pix = *p++; - mask = 0x80; - } - } - while ((read_cycle() - startTime) < period) - ; // Wait for last bit -} - -#endif // KENDRYTE_K210 diff --git a/lib/Adafruit_NeoPixel/keywords.txt b/lib/Adafruit_NeoPixel/keywords.txt deleted file mode 100644 index 4003ede9dc..0000000000 --- a/lib/Adafruit_NeoPixel/keywords.txt +++ /dev/null @@ -1,72 +0,0 @@ -####################################### -# Syntax Coloring Map For Adafruit_NeoPixel -####################################### -# Class -####################################### - -Adafruit_NeoPixel KEYWORD1 - -####################################### -# Methods and Functions -####################################### - -begin KEYWORD2 -show KEYWORD2 -setPin KEYWORD2 -setPixelColor KEYWORD2 -fill KEYWORD2 -setBrightness KEYWORD2 -clear KEYWORD2 -updateLength KEYWORD2 -updateType KEYWORD2 -canShow KEYWORD2 -getPixels KEYWORD2 -getBrightness KEYWORD2 -getPin KEYWORD2 -numPixels KEYWORD2 -getPixelColor KEYWORD2 -sine8 KEYWORD2 -gamma8 KEYWORD2 -Color KEYWORD2 -ColorHSV KEYWORD2 -gamma32 KEYWORD2 - -####################################### -# Constants -####################################### - -NEO_COLMASK LITERAL1 -NEO_SPDMASK LITERAL1 -NEO_KHZ800 LITERAL1 -NEO_KHZ400 LITERAL1 -NEO_RGB LITERAL1 -NEO_RBG LITERAL1 -NEO_GRB LITERAL1 -NEO_GBR LITERAL1 -NEO_BRG LITERAL1 -NEO_BGR LITERAL1 -NEO_WRGB LITERAL1 -NEO_WRBG LITERAL1 -NEO_WGRB LITERAL1 -NEO_WGBR LITERAL1 -NEO_WBRG LITERAL1 -NEO_WBGR LITERAL1 -NEO_RWGB LITERAL1 -NEO_RWBG LITERAL1 -NEO_RGWB LITERAL1 -NEO_RGBW LITERAL1 -NEO_RBWG LITERAL1 -NEO_RBGW LITERAL1 -NEO_GWRB LITERAL1 -NEO_GWBR LITERAL1 -NEO_GRWB LITERAL1 -NEO_GRBW LITERAL1 -NEO_GBWR LITERAL1 -NEO_GBRW LITERAL1 -NEO_BWRG LITERAL1 -NEO_BWGR LITERAL1 -NEO_BRWG LITERAL1 -NEO_BRGW LITERAL1 -NEO_BGWR LITERAL1 -NEO_BGRW LITERAL1 - diff --git a/lib/Adafruit_NeoPixel/library.properties b/lib/Adafruit_NeoPixel/library.properties deleted file mode 100644 index 7bbd4889ca..0000000000 --- a/lib/Adafruit_NeoPixel/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=Adafruit NeoPixel -version=1.10.6 -author=Adafruit -maintainer=Adafruit -sentence=Arduino library for controlling single-wire-based LED pixels and strip. -paragraph=Arduino library for controlling single-wire-based LED pixels and strip. -category=Display -url=https://github.com/adafruit/Adafruit_NeoPixel -architectures=* -includes=Adafruit_NeoPixel.h diff --git a/lib/Adafruit_NeoPixel/rp2040.c b/lib/Adafruit_NeoPixel/rp2040.c deleted file mode 100644 index 388a43bf2b..0000000000 --- a/lib/Adafruit_NeoPixel/rp2040.c +++ /dev/null @@ -1,53 +0,0 @@ -// This sketch is based on the SDK example here: -// https://github.com/raspberrypi/pico-examples/tree/master/pio/ws2812 - -/** - Copyright (c) 2020 Raspberry Pi (Trading) Ltd. - - SPDX-License-Identifier: BSD-3-Clause -*/ - -#if defined(ARDUINO_ARCH_RP2040) - -#include -#include "hardware/pio.h" -#include "hardware/clocks.h" - -#include "rp2040_pio.h" - -void rp2040Init(uint8_t pin, bool is800KHz) -{ - // todo get free sm - PIO pio = pio0; - int sm = 0; - uint offset = pio_add_program(pio, &ws2812_program); - - if (is800KHz) - { - // 800kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 800000, 8); - } - else - { - // 400kHz, 8 bit transfers - ws2812_program_init(pio, sm, offset, pin, 400000, 8); - } -} - -void rp2040Show(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz) -{ - static bool init = true; - - if (init) - { - // On first pass through initialise the PIO - rp2040Init(pin, is800KHz); - init = false; - } - - while(numBytes--) - // Bits for transmission must be shifted to top 8 bits - pio_sm_put_blocking(pio0, 0, ((uint32_t)*pixels++)<< 24); -} - -#endif // KENDRYTE_K210 diff --git a/lib/Adafruit_NeoPixel/rp2040_pio.h b/lib/Adafruit_NeoPixel/rp2040_pio.h deleted file mode 100644 index f7ccd46de0..0000000000 --- a/lib/Adafruit_NeoPixel/rp2040_pio.h +++ /dev/null @@ -1,63 +0,0 @@ -// -------------------------------------------------- // -// This file is autogenerated by pioasm; do not edit! // -// -------------------------------------------------- // - -// Unless you know what you are doing... -// Lines 47 and 52 have been edited to set transmit bit count - -#if !PICO_NO_HARDWARE -#include "hardware/pio.h" -#endif - -// ------ // -// ws2812 // -// ------ // - -#define ws2812_wrap_target 0 -#define ws2812_wrap 3 - -#define ws2812_T1 2 -#define ws2812_T2 5 -#define ws2812_T3 3 - -static const uint16_t ws2812_program_instructions[] = { - // .wrap_target - 0x6221, // 0: out x, 1 side 0 [2] - 0x1123, // 1: jmp !x, 3 side 1 [1] - 0x1400, // 2: jmp 0 side 1 [4] - 0xa442, // 3: nop side 0 [4] - // .wrap -}; - -#if !PICO_NO_HARDWARE -static const struct pio_program ws2812_program = { - .instructions = ws2812_program_instructions, - .length = 4, - .origin = -1, -}; - -static inline pio_sm_config ws2812_program_get_default_config(uint offset) { - pio_sm_config c = pio_get_default_sm_config(); - sm_config_set_wrap(&c, offset + ws2812_wrap_target, offset + ws2812_wrap); - sm_config_set_sideset(&c, 1, false, false); - return c; -} - -#include "hardware/clocks.h" -static inline void ws2812_program_init(PIO pio, uint sm, uint offset, uint pin, - float freq, uint bits) { - pio_gpio_init(pio, pin); - pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); - pio_sm_config c = ws2812_program_get_default_config(offset); - sm_config_set_sideset_pins(&c, pin); - sm_config_set_out_shift(&c, false, true, - bits); // <----<<< Length changed to "bits" - sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); - int cycles_per_bit = ws2812_T1 + ws2812_T2 + ws2812_T3; - float div = clock_get_hz(clk_sys) / (freq * cycles_per_bit); - sm_config_set_clkdiv(&c, div); - pio_sm_init(pio, sm, offset, &c); - pio_sm_set_enabled(pio, sm, true); -} - -#endif diff --git a/lib/HeatpumpIR/ElectroluxHeatpumpIR.cpp b/lib/HeatpumpIR/ElectroluxHeatpumpIR.cpp new file mode 100644 index 0000000000..5609d1fa0d --- /dev/null +++ b/lib/HeatpumpIR/ElectroluxHeatpumpIR.cpp @@ -0,0 +1,178 @@ +#include "ElectroluxHeatpumpIR.h" + +// This is a protected method, i.e. generic Electrolux instances cannot be created +ElectroluxHeatpumpIR::ElectroluxHeatpumpIR() : HeatpumpIR() +{ +} + +// Support for YAL1F remote +ElectroluxYALHeatpumpIR::ElectroluxYALHeatpumpIR() : ElectroluxHeatpumpIR() +{ + static const char model[] PROGMEM = "electroluxyal"; + static const char info[] PROGMEM = "{\"mdl\":\"electroluxyal\",\"dn\":\"Electrolux YAL\",\"mT\":16,\"xT\":30,\"fs\":3}"; + + _model = model; + _info = info; + electroluxModel = ELECTROLUX_YAL; +} + +void ElectroluxHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd) +{ + (void)swingVCmd; + (void)swingHCmd; + + // Sensible defaults for the heat pump mode + + uint8_t powerMode = ELECTROLUX_AIRCON1_POWER_ON; + uint8_t operatingMode = ELECTROLUX_AIRCON1_MODE_HEAT; + uint8_t fanSpeed = ELECTROLUX_AIRCON1_FAN_AUTO; + uint8_t temperature = 21; + uint8_t swingV = ELECTROLUX_VDIR_AUTO; + uint8_t swingH = ELECTROLUX_HDIR_AUTO; + + + if (powerModeCmd == POWER_OFF) + { + powerMode = ELECTROLUX_AIRCON1_POWER_OFF; + } + else + { + switch (operatingModeCmd) + { + case MODE_AUTO: + operatingMode = ELECTROLUX_AIRCON1_MODE_AUTO; + temperatureCmd = 25; + break; + case MODE_HEAT: + operatingMode = ELECTROLUX_AIRCON1_MODE_HEAT; + break; + case MODE_COOL: + operatingMode = ELECTROLUX_AIRCON1_MODE_COOL; + break; + case MODE_DRY: + operatingMode = ELECTROLUX_AIRCON1_MODE_DRY; + fanSpeedCmd = FAN_1; + break; + case MODE_FAN: + operatingMode = ELECTROLUX_AIRCON1_MODE_FAN; + break; + } + } + + switch (fanSpeedCmd) + { + case FAN_AUTO: + fanSpeed = ELECTROLUX_AIRCON1_FAN_AUTO; + break; + case FAN_1: + fanSpeed = ELECTROLUX_AIRCON1_FAN1; + break; + case FAN_2: + fanSpeed = ELECTROLUX_AIRCON1_FAN2; + break; + case FAN_3: + fanSpeed = ELECTROLUX_AIRCON1_FAN3; + break; + } + + switch (swingVCmd) + { + case VDIR_AUTO: + swingV = ELECTROLUX_VDIR_AUTO; + break; + case VDIR_SWING: + swingV = ELECTROLUX_VDIR_SWING; + break; + } + + switch (swingHCmd) + { + case HDIR_AUTO: + swingH = ELECTROLUX_HDIR_AUTO; + break; + case HDIR_SWING: + swingH = ELECTROLUX_HDIR_SWING; + break; + } + + + + + if (temperatureCmd > 15 && temperatureCmd < 31) + { + temperature = temperatureCmd - 16; + } + + sendElectrolux(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH); +} + +// Send the Electrolux code +void ElectroluxHeatpumpIR::sendElectrolux(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH) +{ + + uint8_t ElectroluxTemplate[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00 }; + // 0 1 2 3 4 5 6 7 + uint8_t i; + + // Set the Fan speed, operating mode and power state + ElectroluxTemplate[0] = fanSpeed | operatingMode | powerMode; + // Set the temperature + ElectroluxTemplate[1] = temperature; + + ElectroluxTemplate[2] = 0x20; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN + ElectroluxTemplate[3] = 0x50; // bits 4..7 always 0101 + ElectroluxTemplate[6] = 0x00; + + if (swingV == ELECTROLUX_VDIR_SWING) + { + ElectroluxTemplate[0] |= (1 << 6); // Enable swing by setting bit 6 + ElectroluxTemplate[4] |= 0x01; // Set vertical swing direction + } + if(swingH == ELECTROLUX_HDIR_SWING) + { + ElectroluxTemplate[0] |= (1 << 6); // Enable swing by setting bit 6 + ElectroluxTemplate[4] |= 0x10; // Set horizontal swing direction + } + + ElectroluxTemplate[7] = ((( + (ElectroluxTemplate[0] & 0x0F) + + (ElectroluxTemplate[1] & 0x0F) + + (ElectroluxTemplate[2] & 0x0F) + + (ElectroluxTemplate[3] & 0x0F) + + ((ElectroluxTemplate[4] & 0xF0) >> 4) + + ((ElectroluxTemplate[5] & 0xF0) >> 4) + + ((ElectroluxTemplate[6] & 0xF0) >> 4) + + 0x0A) & 0x0F) << 4) | (ElectroluxTemplate[7] & 0x0F); + + // 38 kHz PWM frequency + IR.setFrequency(38); + + // Send Header mark + IR.mark(ELECTROLUX_AIRCON1_HDR_MARK); + IR.space(ELECTROLUX_AIRCON1_HDR_SPACE); + + // Payload part #1 + for (i=0; i<4; i++) { + IR.sendIRbyte(ElectroluxTemplate[i], ELECTROLUX_AIRCON1_BIT_MARK, ELECTROLUX_AIRCON1_ZERO_SPACE, ELECTROLUX_AIRCON1_ONE_SPACE); + } + // Only three first bits of byte 4 are sent, this is always '010' + IR.mark(ELECTROLUX_AIRCON1_BIT_MARK); + IR.space(ELECTROLUX_AIRCON1_ZERO_SPACE); + IR.mark(ELECTROLUX_AIRCON1_BIT_MARK); + IR.space(ELECTROLUX_AIRCON1_ONE_SPACE); + IR.mark(ELECTROLUX_AIRCON1_BIT_MARK); + IR.space(ELECTROLUX_AIRCON1_ZERO_SPACE); + + // Message space + IR.mark(ELECTROLUX_AIRCON1_BIT_MARK); + IR.space(ELECTROLUX_AIRCON1_MSG_SPACE); + + // Payload part #2 + for (i=4; i<8; i++) { + IR.sendIRbyte(ElectroluxTemplate[i], ELECTROLUX_AIRCON1_BIT_MARK, ELECTROLUX_AIRCON1_ZERO_SPACE, ELECTROLUX_AIRCON1_ONE_SPACE); + } + + // End mark + IR.mark(ELECTROLUX_AIRCON1_BIT_MARK); + IR.space(0); +} diff --git a/lib/HeatpumpIR/ElectroluxHeatpumpIR.h b/lib/HeatpumpIR/ElectroluxHeatpumpIR.h new file mode 100644 index 0000000000..82c24109f4 --- /dev/null +++ b/lib/HeatpumpIR/ElectroluxHeatpumpIR.h @@ -0,0 +1,73 @@ +/* + Electrolux heatpump control (remote control YAL1F) Based on Gree YAC +*/ +#ifndef ElectroluxHeatpumpIR_h +#define ElectroluxHeatpumpIR_h + +#include + +// Electrolux timing constants +#define ELECTROLUX_AIRCON1_HDR_MARK 9000 +#define ELECTROLUX_AIRCON1_HDR_SPACE 4000 +#define ELECTROLUX_AIRCON1_BIT_MARK 620 +#define ELECTROLUX_AIRCON1_ONE_SPACE 1600 +#define ELECTROLUX_AIRCON1_ZERO_SPACE 540 +#define ELECTROLUX_AIRCON1_MSG_SPACE 19000 + + +// Power state +#define ELECTROLUX_AIRCON1_POWER_OFF 0x00 +#define ELECTROLUX_AIRCON1_POWER_ON 0x08 + +// Operating modes +// Electrolux codes +#define ELECTROLUX_AIRCON1_MODE_AUTO 0x00 +#define ELECTROLUX_AIRCON1_MODE_COOL 0x01 +#define ELECTROLUX_AIRCON1_MODE_DRY 0x02 +#define ELECTROLUX_AIRCON1_MODE_FAN 0x03 +#define ELECTROLUX_AIRCON1_MODE_HEAT 0x04 + +// Fan speeds. Note that some heatpumps have less than 5 fan speeds +#define ELECTROLUX_AIRCON1_FAN_AUTO 0x00 // Fan speed +#define ELECTROLUX_AIRCON1_FAN1 0x10 // * 1 +#define ELECTROLUX_AIRCON1_FAN2 0x20 // * 2 +#define ELECTROLUX_AIRCON1_FAN3 0x30 // * 3 + +// Vertical air directions. Note that these cannot be set on all heat pumps +#define ELECTROLUX_VDIR_AUTO 0x00 +#define ELECTROLUX_VDIR_SWING 0x01 + +// Horizontal air directions. Note that these cannot be set on all heat pumps +#define ELECTROLUX_HDIR_AUTO 0x00 +#define ELECTROLUX_HDIR_SWING 0x01 + +#define ELECTROLUX_YAL 0 + + +class ElectroluxHeatpumpIR : public HeatpumpIR +{ + protected: + ElectroluxHeatpumpIR(); + uint8_t electroluxModel; + + public: + void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd); + + private: + void sendElectrolux(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, uint8_t swingH); +}; + + +class ElectroluxYALHeatpumpIR : public ElectroluxHeatpumpIR +{ + public: + ElectroluxYALHeatpumpIR(); + + public: + void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd) + { + ElectroluxHeatpumpIR::send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, swingHCmd); + } +}; + +#endif diff --git a/lib/HeatpumpIR/GreeHeatpumpIR.cpp b/lib/HeatpumpIR/GreeHeatpumpIR.cpp index 0319aed649..15628d269c 100644 --- a/lib/HeatpumpIR/GreeHeatpumpIR.cpp +++ b/lib/HeatpumpIR/GreeHeatpumpIR.cpp @@ -37,7 +37,7 @@ GreeYAAHeatpumpIR::GreeYAAHeatpumpIR() : GreeHeatpumpIR() } // Support for YAC1FBF remote -GreeYACHeatpumpIR::GreeYACHeatpumpIR() : GreeHeatpumpIR() +GreeYACHeatpumpIR::GreeYACHeatpumpIR() : GreeiFeelHeatpumpIR() { static const char model[] PROGMEM = "greeyac"; static const char info[] PROGMEM = "{\"mdl\":\"greeyac\",\"dn\":\"Gree YAC\",\"mT\":16,\"xT\":30,\"fs\":3}"; @@ -47,6 +47,17 @@ GreeYACHeatpumpIR::GreeYACHeatpumpIR() : GreeHeatpumpIR() greeModel = GREE_YAC; } +// Support for YT1F remote +GreeYTHeatpumpIR::GreeYTHeatpumpIR() : GreeiFeelHeatpumpIR() +{ + static const char model[] PROGMEM = "greeyt"; + static const char info[] PROGMEM = "{\"mdl\":\"greeyt\",\"dn\":\"Gree YT\",\"mT\":16,\"xT\":30,\"fs\":3}"; + + _model = model; + _info = info; + greeModel = GREE_YT; +} + void GreeHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd) { send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, swingHCmd, false); @@ -54,7 +65,7 @@ void GreeHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingM void GreeHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd, bool turboMode) { - send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, swingHCmd, false, turboMode); + send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, swingHCmd, turboMode, false); } void GreeHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd, bool turboMode, bool iFeelMode) @@ -143,7 +154,7 @@ void GreeHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingM } } - if (greeModel == GREE_YAA || greeModel == GREE_YAC) + if (greeModel == GREE_YAA || greeModel == GREE_YAC || greeModel == GREE_YT) { switch (swingVCmd) { @@ -211,11 +222,15 @@ void GreeHeatpumpIR::sendGree(IRSender& IR, uint8_t powerMode, uint8_t operating { (void)swingH; - uint8_t GreeTemplate[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00 }; + uint8_t GreeTemplate[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 0 1 2 3 4 5 6 7 uint8_t i; + if (greeModel != GREE_YT) { + GreeTemplate[5] = 0x20; + } + // Set the Fan speed, operating mode and power state GreeTemplate[0] = fanSpeed | operatingMode | powerMode; // Set the temperature @@ -230,26 +245,42 @@ void GreeHeatpumpIR::sendGree(IRSender& IR, uint8_t powerMode, uint8_t operating } if (greeModel == GREE_YAC) { - GreeTemplate[4] |= (swingH << 4); + GreeTemplate[4] |= (swingH << 4); // GREE_YT will ignore packets where this is set + } + if (greeModel == GREE_YAC || greeModel == GREE_YT) + { if (iFeelMode) { - GreeTemplate[5] |= (1 << 3); + GreeTemplate[5] |= GREE_IFEEL_BIT; + } + } + if (greeModel == GREE_YT) { + GreeTemplate[2] = GREE_LIGHT_BIT | GREE_HEALTH_BIT; // HEALTH is always on for GREE_YT + GreeTemplate[3] = 0x50; // bits 4..7 always 0101 + + if (turboMode) + { + GreeTemplate[2] |= GREE_TURBO_BIT; + } + if (swingV == GREE_VDIR_SWING) + { + GreeTemplate[0] |= GREE_VSWING; // Enable swing by setting bit 6 + GreeTemplate[4] = swingV; } } if (greeModel == GREE_YAA || greeModel == GREE_YAC) { -// GreeTemplate[2] = 0xE0; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN - GreeTemplate[2] = 0x20; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN + GreeTemplate[2] = GREE_LIGHT_BIT; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN GreeTemplate[3] = 0x50; // bits 4..7 always 0101 GreeTemplate[6] = 0x20; // YAA1FB, FAA1FB1, YB1F2 bits 4..7 always 0010 if (turboMode) { - GreeTemplate[2] |= (1 << 4); // Set bit 4 (TURBO) + GreeTemplate[2] |= GREE_TURBO_BIT; } if (swingV == GREE_VDIR_SWING) { - GreeTemplate[0] |= (1 << 6); // Enable swing by setting bit 6 + GreeTemplate[0] |= GREE_VSWING; // Enable swing by setting bit 6 } else if (swingV != GREE_VDIR_AUTO) { @@ -312,7 +343,7 @@ void GreeHeatpumpIR::sendGree(IRSender& IR, uint8_t powerMode, uint8_t operating } // Sends current sensed temperatures, YAC remotes/supporting units only -void GreeYACHeatpumpIR::send(IRSender& IR, uint8_t currentTemperature) +void GreeiFeelHeatpumpIR::send(IRSender& IR, uint8_t currentTemperature) { uint8_t GreeTemplate[] = { 0x00, 0x00 }; diff --git a/lib/HeatpumpIR/GreeHeatpumpIR.h b/lib/HeatpumpIR/GreeHeatpumpIR.h index ceec6a3371..f50b8cd82c 100644 --- a/lib/HeatpumpIR/GreeHeatpumpIR.h +++ b/lib/HeatpumpIR/GreeHeatpumpIR.h @@ -38,7 +38,7 @@ #define GREE_AIRCON1_FAN3 0x30 // * high #define GREE_AIRCON1_TURBO 0x80 // * turbo mode on YAN -// Only available on YAN +// Only available on YAN and YT // Vertical air directions. Note that these cannot be set on all heat pumps #define GREE_VDIR_AUTO 0x00 #define GREE_VDIR_MANUAL 0x00 @@ -60,11 +60,25 @@ #define GREE_HDIR_MRIGHT 0x05 #define GREE_HDIR_RIGHT 0x06 +#define GREE_IFEEL_BIT 0x08 + +// Only available on YAA, YAC, and YT +// byte 0 +#define GREE_VSWING (1 << 6) +// byte 2 +#define GREE_TURBO_BIT (1 << 4) +#define GREE_LIGHT_BIT (1 << 5) +#define GREE_HEALTH_BIT (1 << 6) +#define GREE_XFAN_BIT (1 << 7) // aka BLOW on some remotes + + + // Gree model codes #define GREE_GENERIC 0 #define GREE_YAN 1 #define GREE_YAA 2 #define GREE_YAC 3 +#define GREE_YT 4 class GreeHeatpumpIR : public HeatpumpIR @@ -112,11 +126,8 @@ class GreeYAAHeatpumpIR : public GreeHeatpumpIR } }; -class GreeYACHeatpumpIR : public GreeHeatpumpIR +class GreeiFeelHeatpumpIR : public GreeHeatpumpIR { - public: - GreeYACHeatpumpIR(); - public: void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd, bool turboMode, bool iFeelMode) { @@ -125,4 +136,16 @@ class GreeYACHeatpumpIR : public GreeHeatpumpIR void send(IRSender& IR, uint8_t currentTemperature); }; +class GreeYACHeatpumpIR : public GreeiFeelHeatpumpIR +{ + public: + GreeYACHeatpumpIR(); +}; + +class GreeYTHeatpumpIR : public GreeiFeelHeatpumpIR +{ + public: + GreeYTHeatpumpIR(); +}; + #endif diff --git a/lib/HeatpumpIR/HeatpumpIRFactory.cpp b/lib/HeatpumpIR/HeatpumpIRFactory.cpp index 3fe0eb6764..eaed55e4d4 100644 --- a/lib/HeatpumpIR/HeatpumpIRFactory.cpp +++ b/lib/HeatpumpIR/HeatpumpIRFactory.cpp @@ -17,6 +17,8 @@ HeatpumpIR* HeatpumpIRFactory::create(const char *modelName) { return new DaikinHeatpumpARC480A14IR(); } else if (strcmp_P(modelName, PSTR("daikin")) == 0) { return new DaikinHeatpumpIR(); + } else if (strcmp_P(modelName, PSTR("electroluxyal")) == 0) { + return new ElectroluxYALHeatpumpIR(); } else if (strcmp_P(modelName, PSTR("fuego")) == 0) { return new FuegoHeatpumpIR(); } else if (strcmp_P(modelName, PSTR("fujitsu_awyz")) == 0) { @@ -77,7 +79,11 @@ HeatpumpIR* HeatpumpIRFactory::create(const char *modelName) { return new ToshibaDaiseikaiHeatpumpIR(); } else if (strcmp_P(modelName, PSTR("toshiba")) == 0) { return new ToshibaHeatpumpIR(); + } else if (strcmp_P(modelName, PSTR("ZHJG01")) == 0) { + return new ZHJG01HeatpumpIR(); + } else if (strcmp_P(modelName, PSTR("ZHLT01")) == 0) { + return new ZHLT01HeatpumpIR(); } return NULL; -} \ No newline at end of file +} diff --git a/lib/HeatpumpIR/HeatpumpIRFactory.h b/lib/HeatpumpIR/HeatpumpIRFactory.h index dd0331344a..b96e1872e1 100644 --- a/lib/HeatpumpIR/HeatpumpIRFactory.h +++ b/lib/HeatpumpIR/HeatpumpIRFactory.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,8 @@ #include #include #include - +#include +#include class HeatpumpIRFactory { @@ -37,4 +39,4 @@ class HeatpumpIRFactory static HeatpumpIR* create(const char *modelName); }; -#endif \ No newline at end of file +#endif diff --git a/lib/HeatpumpIR/IRSenderESP32.cpp b/lib/HeatpumpIR/IRSenderESP32.cpp index d8e79d1c3c..135b15e1c6 100644 --- a/lib/HeatpumpIR/IRSenderESP32.cpp +++ b/lib/HeatpumpIR/IRSenderESP32.cpp @@ -6,6 +6,9 @@ #if defined ESP32 #include +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) +#include +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 IRSenderESP32::IRSenderESP32(uint8_t pin, uint8_t pwmChannel) : IRSender(pin) { _pwmChannel = pwmChannel; @@ -20,10 +23,18 @@ void IRSenderESP32::setFrequency(int frequency) // Send an IR 'mark' symbol, i.e. transmitter ON void IRSenderESP32::mark(int markLength) { +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + ledcAttach(_pin, _frequency, 8); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 ledcSetup(_pwmChannel, _frequency, 8); ledcAttachPin(_pin, _pwmChannel); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 long beginning = micros(); +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + ledcWrite(_pin, 127); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 ledcWrite(_pwmChannel, 127); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 while((int)(micros() - beginning) < markLength); gpio_reset_pin(static_cast(_pin)); digitalWrite(_pin, LOW); diff --git a/lib/HeatpumpIR/README.md b/lib/HeatpumpIR/README.md index 85726c07f6..83cb0316be 100644 --- a/lib/HeatpumpIR/README.md +++ b/lib/HeatpumpIR/README.md @@ -4,7 +4,7 @@ Original location: https://github.com/ToniA/arduino-heatpumpir For concrete examples, see the MySensors (Arduino + nRF24 radio) and ESPEasy (ESP8266 modules) integrations: * https://github.com/mysensors/MySensorsArduinoExamples/tree/master/examples/HeatpumpIRController -* https://github.com/ToniA/ESPEasy/blob/master/ESPEasy/_P115_HeatpumpIR.ino +* https://github.com/ToniA/ESPEasy/blob/HeatpumpIR/src/_P088_HeatpumpIR.ino An Arduino library to control pump/split unit air conditioner. Currently supporting at least these models: @@ -14,7 +14,7 @@ An Arduino library to control pump/split unit air conditioner. Currently support * Hisense AUD (remote control Y-H1-01, Y-H1-02(E), Y-J1, Y-E4-07) probably AUC model * Hyundai (remote control P/N Y512F2) * This is probably a generic Gree model - * Model H-AR21-07H (remote control P/N YKR-P/002E) confirmed as AUX + * Models H-AR21-07H / H-AR16-09H (remote control P/N YKR-P/002E) confirmed as AUX * Fujitsu Nocria AWYZ14 (remote control P/N AR-PZ2) * Also Fujitsu remote controls RY3-AR and AR-RCE1E * IVT AY-XP12FR-N (remote control CRMC-A673JBEZ) @@ -33,14 +33,22 @@ An Arduino library to control pump/split unit air conditioner. Currently support * Panasonic E9/E12-JKE and E9/E12-NKE * Samsung * AQV12PSBN / AQV09ASA + * AQV12MSAN, Remote Control ARH-1362 * Samsung FJM (RJ040F2HXEA / 2XMH026FNEA), Remote Control P/N ARH-465 * Sharp AY-ZP40KR (remote control P/N CRMC-A788JBEZ), possibly also IVT +* Sharp AY-X09LCJ (Remote control P/N YT1F) * Toshiba Daiseikai (Toshiba remote control P/N WH-TA01EE). * Fully compatible with CarrierNQV functions instead of Daiseikai functions. * Tested with: RAS-10G2KVP-E RAS-10G2AVP-E and RAS-13G2KVP-E RAS-13G2AVP-E * Tosot T18H-SN/I (remote control P/N YAA1FB) as GreeYAA variant * Also marketed as Tadiran brand - +* Vaillant VAI8 (remote control P/N YAN1F1), a Gree YAA variant + * Tested and fully working with VAI8-025WNI + * Does not support iFeel, all other (essential) features are implemented, note the custom send() for commanding turbo and panel light +* ZH/LT-01 remote control + * Brands: Eurom, Chigo, Tristar, Tecnomaster, Elgin, Geant, Tekno, Topair, + Proma, Sumikura, JBS, Turbo Air, Nakatomy, Celestial Air, Ager, + Blueway, Airlux, etc. ## Instructions @@ -66,7 +74,7 @@ Note that depending on your board, certain GPIO's might not be available. For ex ### ESPEasy on ESP8266 board -This library (together with the HeatpumpIR plugin) is integrated into the ESP Easy firmware. The a look here: https://github.com/letscontrolit/ESPEasy +This library (together with the HeatpumpIR plugin) is integrated into the ESP Easy firmware. Take a look here: https://github.com/letscontrolit/ESPEasy * Download the pre-built firmware under the 'Releases' tab * HeatpumpIR is included in the 'minimalIRext' images * Documentation: https://espeasy.readthedocs.io/en/latest/Plugin/P088.html#p088-page diff --git a/lib/HeatpumpIR/SamsungHeatpumpIR.cpp b/lib/HeatpumpIR/SamsungHeatpumpIR.cpp index 4ee85595da..2f9d311827 100644 --- a/lib/HeatpumpIR/SamsungHeatpumpIR.cpp +++ b/lib/HeatpumpIR/SamsungHeatpumpIR.cpp @@ -20,6 +20,16 @@ SamsungAQVHeatpumpIR::SamsungAQVHeatpumpIR() : SamsungHeatpumpIR() _info = info; } +SamsungAQV12MSANHeatpumpIR::SamsungAQV12MSANHeatpumpIR() : SamsungAQVHeatpumpIR() +{ + static const char model[] PROGMEM = "samsung_aqv12msan"; + static const char info[] PROGMEM = "{\"mdl\":\"samsung_aqv12msan\",\"dn\":\"Samsung AQV12MSAN\",\"mT\":16,\"xT\":27,\"fs\":4}"; + + _model = model; + _info = info; + _samsungAQVModel = MODEL_AQV12_MSAN; +} + SamsungFJMHeatpumpIR::SamsungFJMHeatpumpIR() : SamsungHeatpumpIR() { static const char model[] PROGMEM = "samsung_fjm"; @@ -44,41 +54,29 @@ void SamsungAQVHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t oper uint8_t temperature = 23; uint8_t swingV = SAMSUNG_AIRCON1_VS_AUTO; - if (powerModeCmd == POWER_OFF) - { - powerMode = SAMSUNG_AIRCON1_MODE_OFF; - - if (operatingModeCmd == MODE_COOL) // Cooling-only models need to have COOL as the operating mode in power off - { - operatingMode = SAMSUNG_AIRCON1_MODE_COOL; - } - } - else - { - switch (operatingModeCmd) - { - case MODE_AUTO: - operatingMode = SAMSUNG_AIRCON1_MODE_AUTO; - fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in AUTO mode - break; - case MODE_HEAT: - operatingMode = SAMSUNG_AIRCON1_MODE_HEAT; - break; - case MODE_COOL: - operatingMode = SAMSUNG_AIRCON1_MODE_COOL; - break; - case MODE_DRY: - operatingMode = SAMSUNG_AIRCON1_MODE_DRY; - fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in DRY mode - break; - case MODE_FAN: - operatingMode = SAMSUNG_AIRCON1_MODE_FAN; - if ( fanSpeedCmd == FAN_AUTO ) { - fanSpeedCmd = FAN_1; // Fan speed cannot be 'AUTO' in FAN mode - } - break; - } - } + switch (operatingModeCmd) + { + case MODE_AUTO: + operatingMode = SAMSUNG_AIRCON1_MODE_AUTO; + fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in AUTO mode + break; + case MODE_HEAT: + operatingMode = SAMSUNG_AIRCON1_MODE_HEAT; + break; + case MODE_COOL: + operatingMode = SAMSUNG_AIRCON1_MODE_COOL; + break; + case MODE_DRY: + operatingMode = SAMSUNG_AIRCON1_MODE_DRY; + fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in DRY mode + break; + case MODE_FAN: + operatingMode = SAMSUNG_AIRCON1_MODE_FAN; + if ( fanSpeedCmd == FAN_AUTO ) { + fanSpeedCmd = FAN_1; // Fan speed cannot be 'AUTO' in FAN mode + } + break; + } switch (fanSpeedCmd) { @@ -108,6 +106,19 @@ void SamsungAQVHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t oper break; } + // power offmode is something special, so set it latest to treat + if (powerModeCmd == POWER_OFF) + { + powerMode = SAMSUNG_AIRCON1_MODE_OFF; + if (_samsungAQVModel == MODEL_AQV12_MSAN) + { + if (operatingModeCmd == MODE_AUTO) + { + fanSpeed = 0x0D; // reverse enginering remote + } + } + } + sendSamsung(IR, powerMode, operatingMode, fanSpeed, temperature, swingV); } @@ -115,8 +126,8 @@ void SamsungAQVHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t oper void SamsungAQVHeatpumpIR::sendSamsung(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV) { - uint8_t SamsungTemplate[] = { 0x02, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, // Header part - 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, // Always the same data on POWER messages + uint8_t SamsungTemplate[] = { 0x02, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, // Header part (0-6) + 0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, // Always the same data on POWER messages (7-13) 0x01, 0x00, 0xFE, 0x71, 0x00, 0x00, 0x00 }; // The actual data is in this part, on uint8_ts 14-20 uint8_t SamsungChecksum = 0; @@ -142,7 +153,7 @@ void SamsungAQVHeatpumpIR::sendSamsung(IRSender& IR, uint8_t powerMode, uint8_t // Calculate the byte 15 checksum // Count the number of ONE bits on message uint8_ts 15-20 - for (uint8_t j=15; j<21; j++) { + for (uint8_t j=16; j<20; j++) { uint8_t Samsungbyte = SamsungTemplate[j]; for (uint8_t i=0; i<8; i++) { if ( (Samsungbyte & 0x01) == 0x01 ) { @@ -153,11 +164,19 @@ void SamsungAQVHeatpumpIR::sendSamsung(IRSender& IR, uint8_t powerMode, uint8_t } // Transform the number of ONE bits to the actual checksum - SamsungChecksum = 32 - SamsungChecksum; + SamsungChecksum = 28 - SamsungChecksum; SamsungChecksum <<= 4; - SamsungChecksum += 0x02; + SamsungChecksum |= (powerMode == SAMSUNG_AIRCON1_MODE_OFF && _samsungAQVModel == MODEL_AQV12_MSAN) ? 0x22 : 0x02; SamsungTemplate[15] = SamsungChecksum; + + // incredible hack if power off and temp = 20 and mode heat, dry or cool + if (powerMode == SAMSUNG_AIRCON1_MODE_OFF && _samsungAQVModel == MODEL_AQV12_MSAN + && (SamsungTemplate[18] == SAMSUNG_AIRCON1_MODE_HEAT || SamsungTemplate[18] == SAMSUNG_AIRCON1_MODE_DRY || SamsungTemplate[18] == SAMSUNG_AIRCON1_MODE_COOL)) + { + SamsungTemplate[15] = 0x02; + SamsungTemplate[16] = 0xFF; //normally this is swingV + } // 38 kHz PWM frequency IR.setFrequency(38); @@ -273,7 +292,7 @@ void SamsungFJMHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t oper break; } - if ( temperatureCmd > 15 && temperatureCmd < 28) + if ( temperatureCmd > 15 && temperatureCmd < 31) { temperature = temperatureCmd; } diff --git a/lib/HeatpumpIR/SamsungHeatpumpIR.h b/lib/HeatpumpIR/SamsungHeatpumpIR.h index 01a31286bf..fd43c9cd39 100644 --- a/lib/HeatpumpIR/SamsungHeatpumpIR.h +++ b/lib/HeatpumpIR/SamsungHeatpumpIR.h @@ -1,5 +1,6 @@ /* Samsung AQV12PSBN / AQV09ASA heatpump control (remote control P/N zzz) + Samsung AQV12MSAN (remote control ARH-1362) Samsung FJM (RJ040F2HXEA / MH026FNEA) heatpump control (remote control P/N ARH-465) */ #ifndef SamsungHeatpumpIR_h @@ -47,11 +48,13 @@ #define SAMSUNG_AIRCON2_VS_AUTO 0xF0 #define SAMSUNG_AIRCON2_TURBO 0x06 // 30 minutes of full power +#define MODEL_AQV12_MSAN 1 class SamsungHeatpumpIR : public HeatpumpIR { protected: SamsungHeatpumpIR(); + uint8_t _samsungAQVModel; public: virtual void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd); @@ -82,4 +85,10 @@ class SamsungFJMHeatpumpIR : public SamsungHeatpumpIR void sendSamsung(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, bool turboMode); }; +class SamsungAQV12MSANHeatpumpIR : public SamsungAQVHeatpumpIR +{ + public: + SamsungAQV12MSANHeatpumpIR(); +}; + #endif diff --git a/lib/HeatpumpIR/VaillantHeatpumpIR.cpp b/lib/HeatpumpIR/VaillantHeatpumpIR.cpp new file mode 100644 index 0000000000..7f82c9a3ab --- /dev/null +++ b/lib/HeatpumpIR/VaillantHeatpumpIR.cpp @@ -0,0 +1,186 @@ +#include "VaillantHeatpumpIR.h" + + +VaillantHeatpumpIR::VaillantHeatpumpIR() +{ + static const char model[] PROGMEM = "vaillantvai8"; + static const char info[] PROGMEM = "{\"mdl\":\"vaillantvai8\",\"dn\":\"Vaillant VAI8\",\"mT\":16,\"xT\":30,\"fs\":3}"; + + _model = model; + _info = info; +} + +void VaillantHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd) +{ + send(IR, powerModeCmd, operatingModeCmd, fanSpeedCmd, temperatureCmd, swingVCmd, false, true); +} + +void VaillantHeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, bool turboModeCmd, bool lightCmd) +{ + + // Sensible defaults for the heat pump mode + + uint8_t powerMode = VAILLANT_AIRCON1_POWER_ON; + uint8_t operatingMode = VAILLANT_AIRCON1_MODE_COOL; + uint8_t fanSpeed = VAILLANT_AIRCON1_FAN1; + uint8_t temperature = 25; + uint8_t swingV = VAILLANT_VDIR_UP; + + if (powerModeCmd == POWER_OFF) + { + powerMode = VAILLANT_AIRCON1_POWER_OFF; + } + else + { + switch (operatingModeCmd) + { + case MODE_AUTO: + operatingMode = VAILLANT_AIRCON1_MODE_AUTO; + temperatureCmd = 25; + break; + case MODE_HEAT: + operatingMode = VAILLANT_AIRCON1_MODE_HEAT; + break; + case MODE_COOL: + operatingMode = VAILLANT_AIRCON1_MODE_COOL; + break; + case MODE_DRY: + operatingMode = VAILLANT_AIRCON1_MODE_DRY; + fanSpeedCmd = FAN_1; + break; + case MODE_FAN: + operatingMode = VAILLANT_AIRCON1_MODE_FAN; + break; + } + } + + switch (fanSpeedCmd) + { + case FAN_AUTO: + fanSpeed = VAILLANT_AIRCON1_FAN_AUTO; + break; + case FAN_1: + fanSpeed = VAILLANT_AIRCON1_FAN1; + break; + case FAN_2: + fanSpeed = VAILLANT_AIRCON1_FAN2; + break; + case FAN_3: + fanSpeed = VAILLANT_AIRCON1_FAN3; + break; + } + + switch (swingVCmd) + { + case VDIR_AUTO: + swingV = VAILLANT_VDIR_AUTO; + break; + case VDIR_SWING: + swingV = VAILLANT_VDIR_SWING; + break; + case VDIR_UP: + swingV = VAILLANT_VDIR_UP; + break; + case VDIR_MUP: + swingV = VAILLANT_VDIR_MUP; + break; + case VDIR_MIDDLE: + swingV = VAILLANT_VDIR_MIDDLE; + break; + case VDIR_MDOWN: + swingV = VAILLANT_VDIR_MDOWN; + break; + case VDIR_DOWN: + swingV = VAILLANT_VDIR_DOWN; + break; + } + + if (temperatureCmd > 15 && temperatureCmd < 31) + { + temperature = temperatureCmd - 16; + } + + sendVaillant(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, turboModeCmd, lightCmd); +} + +// Send the Vaillant code +void VaillantHeatpumpIR::sendVaillant(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, bool turboMode, bool light) +{ + + uint8_t vaillantTemplate[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + // 0 1 2 3 4 5 6 7 + + uint8_t i; + + // Set the Fan speed, operating mode and power state + vaillantTemplate[0] = fanSpeed | operatingMode | powerMode; + // Set the temperature + vaillantTemplate[1] = temperature; + + + if (powerMode == VAILLANT_AIRCON1_POWER_ON) + { + vaillantTemplate[2] = 0x40; // bits 0..3 always 0000, bits 4..7 TURBO,LIGHT,HEALTH,X-FAN + } + + vaillantTemplate[3] = 0x50; + vaillantTemplate[4] = swingV; + vaillantTemplate[5] = 0x02; + vaillantTemplate[6] = 0x00; + + if (turboMode) + { + vaillantTemplate[2] |= (1 << 4); // Set bit 4 (TURBO) + } + if (light) + { + vaillantTemplate[2] |= (1 << 5); // Set bit 5 (light) + } + if (swingV == VAILLANT_VDIR_SWING) + { + vaillantTemplate[0] |= (1 << 6); // Enable swing by setting bit 6 + } + + // Calculate the checksum + vaillantTemplate[7] = ((( + (vaillantTemplate[0] & 0x0F) + + (vaillantTemplate[1] & 0x0F) + + (vaillantTemplate[2] & 0x0F) + + (vaillantTemplate[3] & 0x0F) + + ((vaillantTemplate[5] & 0xF0) >> 4) + + ((vaillantTemplate[6] & 0xF0) >> 4) + + ((vaillantTemplate[7] & 0xF0) >> 4) + + 0x0A) & 0x0F) << 4) | (vaillantTemplate[7] & 0x0F); + + // 38 kHz PWM frequency + IR.setFrequency(38); + + // Send Header mark + IR.mark(VAILLANT_AIRCON1_HDR_MARK); + IR.space(VAILLANT_AIRCON1_HDR_SPACE); + + // Payload part #1 + for (i=0; i<4; i++) { + IR.sendIRbyte(vaillantTemplate[i], VAILLANT_AIRCON1_BIT_MARK, VAILLANT_AIRCON1_ZERO_SPACE, VAILLANT_AIRCON1_ONE_SPACE); + } + // Only three first bits of byte 4 are sent, this is always '010' + IR.mark(VAILLANT_AIRCON1_BIT_MARK); + IR.space(VAILLANT_AIRCON1_ZERO_SPACE); + IR.mark(VAILLANT_AIRCON1_BIT_MARK); + IR.space(VAILLANT_AIRCON1_ONE_SPACE); + IR.mark(VAILLANT_AIRCON1_BIT_MARK); + IR.space(VAILLANT_AIRCON1_ZERO_SPACE); + + // Message space + IR.mark(VAILLANT_AIRCON1_BIT_MARK); + IR.space(VAILLANT_AIRCON1_MSG_SPACE); + + // Payload part #2 + for (i=4; i<8; i++) { + IR.sendIRbyte(vaillantTemplate[i], VAILLANT_AIRCON1_BIT_MARK, VAILLANT_AIRCON1_ZERO_SPACE, VAILLANT_AIRCON1_ONE_SPACE); + } + + // End mark + IR.mark(VAILLANT_AIRCON1_BIT_MARK); + IR.space(0); +} diff --git a/lib/HeatpumpIR/VaillantHeatpumpIR.h b/lib/HeatpumpIR/VaillantHeatpumpIR.h new file mode 100644 index 0000000000..c09e0c3e4d --- /dev/null +++ b/lib/HeatpumpIR/VaillantHeatpumpIR.h @@ -0,0 +1,56 @@ +/* + Vaillant VAI8 heatpump control (remote control P/N YAN1F1) +*/ +#ifndef VaillantHeatpumpIR_h +#define VaillantHeatpumpIR_h + +#include + +// Vaillant timing constants +#define VAILLANT_AIRCON1_HDR_MARK 9000 +#define VAILLANT_AIRCON1_HDR_SPACE 4000 +#define VAILLANT_AIRCON1_BIT_MARK 620 +#define VAILLANT_AIRCON1_ONE_SPACE 1600 +#define VAILLANT_AIRCON1_ZERO_SPACE 540 +#define VAILLANT_AIRCON1_MSG_SPACE 19000 + +// Power state +#define VAILLANT_AIRCON1_POWER_OFF 0x00 +#define VAILLANT_AIRCON1_POWER_ON 0x08 + +// Operating modes +#define VAILLANT_AIRCON1_MODE_AUTO 0x00 +#define VAILLANT_AIRCON1_MODE_COOL 0x01 +#define VAILLANT_AIRCON1_MODE_DRY 0x02 +#define VAILLANT_AIRCON1_MODE_FAN 0x03 +#define VAILLANT_AIRCON1_MODE_HEAT 0x04 + +// Fan speeds. Note that some heatpumps have less than 5 fan speeds +#define VAILLANT_AIRCON1_FAN_AUTO 0x00 // Fan speed +#define VAILLANT_AIRCON1_FAN1 0x10 // * low +#define VAILLANT_AIRCON1_FAN2 0x20 // * med +#define VAILLANT_AIRCON1_FAN3 0x30 // * high + +// Vertical air directions. Note that these cannot be set on all heat pumps +#define VAILLANT_VDIR_AUTO 0x00 +#define VAILLANT_VDIR_MANUAL 0x00 +#define VAILLANT_VDIR_SWING 0x01 +#define VAILLANT_VDIR_UP 0x02 +#define VAILLANT_VDIR_MUP 0x03 +#define VAILLANT_VDIR_MIDDLE 0x04 +#define VAILLANT_VDIR_MDOWN 0x05 +#define VAILLANT_VDIR_DOWN 0x06 + + +class VaillantHeatpumpIR : public HeatpumpIR +{ + public: + VaillantHeatpumpIR(); + void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, bool turboModeCmd, bool lightCmd); + void send(IRSender& IR, uint8_t powerModeCmd, uint8_t operatingModeCmd, uint8_t fanSpeedCmd, uint8_t temperatureCmd, uint8_t swingVCmd, uint8_t swingHCmd); + + private: + void sendVaillant(IRSender& IR, uint8_t powerMode, uint8_t operatingMode, uint8_t fanSpeed, uint8_t temperature, uint8_t swingV, bool turboMode, bool light); +}; + +#endif diff --git a/lib/HeatpumpIR/ZHJG01HeatpumpIR.cpp b/lib/HeatpumpIR/ZHJG01HeatpumpIR.cpp new file mode 100644 index 0000000000..1a37066d5a --- /dev/null +++ b/lib/HeatpumpIR/ZHJG01HeatpumpIR.cpp @@ -0,0 +1,160 @@ +#include + +ZHJG01HeatpumpIR::ZHJG01HeatpumpIR() : HeatpumpIR() +{ + static const char model[] PROGMEM = "ZHJG01"; + static const char info[] PROGMEM = "{\"mdl\":\"ZHJG01\",\"dn\":\"ZHJG01\",\"mT\":18,\"xT\":32,\"fs\":3,\"maint\":[10]}}"; + + _model = model; + _info = info; +} + +void ZHJG01HeatpumpIR::send(IRSender& IR, + uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd) +{ + + uint8_t operatingMode = ZHJG01_MODE_AUTO; + uint8_t fanSpeed = ZHJG01_FAN_AUTO; + uint8_t temperature = 25; + uint8_t swingV = ZHJG01_VDIR_FIXED; + + uint8_t powerMode = powerModeCmd == 0 ? ZHJG01_POWER_OFF : ZHJG01_POWER_ON; + + switch (operatingModeCmd) + { + case MODE_COOL: + operatingMode = ZHJG01_MODE_COOL; + break; + case MODE_FAN: + operatingMode = ZHJG01_MODE_FAN; + break; + case MODE_DRY: + operatingMode = ZHJG01_MODE_DRY; + temperatureCmd = 25; + break; + case MODE_HEAT: + operatingMode = ZHJG01_MODE_HEAT; + break; + default: + operatingMode = ZHJG01_MODE_AUTO; + temperatureCmd = 25; + } + + switch (fanSpeedCmd) + { + case FAN_AUTO: + fanSpeed = ZHJG01_FAN_AUTO; + break; + case FAN_1: + fanSpeed = ZHJG01_FAN1; + break; + case FAN_2: + fanSpeed = ZHJG01_FAN2; + break; + case FAN_3: + fanSpeed = ZHJG01_FAN3; + break; + case FAN_4: + case FAN_5: + fanSpeed = ZHJG01_FAN_TURBO; + break; + case FAN_SILENT: + fanSpeed = ZHJG01_FAN_ECO; + break; + } + + switch (swingVCmd) + { + case VDIR_AUTO: + swingV = ZHJG01_VDIR_WIND; + break; + case VDIR_SWING: + swingV = ZHJG01_VDIR_SWING; + break; + default: + swingV = ZHJG01_VDIR_FIXED; + } + + // temperature must be between 17 and 32 degrees + if (temperatureCmd < 16) + { + temperature = 16; + } + else if (temperatureCmd > 32) + { + temperature = 32; + } else + { + temperature = temperatureCmd; + } + + sendZHJG01(IR, powerMode, operatingMode, fanSpeed, temperature, swingV); +} + +void ZHJG01HeatpumpIR::sendZHJG01(IRSender& IR, + uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV) +{ + uint8_t ZHJG01Template[] = { 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF }; + // Bytenumbers: 0 1 2 3 4 5 + +/******************************************************************************** + * Byte[0]: Turbo, Eco, Fan, Vertical Swing + * TURBO ON: B0x1xxxxx + * ECO ON: B0x0xxxxx + * TURBO/ECO OFF: B1xxxxxxx + * FAN1: Bx00xxxxx + * FAN2: Bx01xxxxx + * FAN3: Bx10xxxxx + * FAN AUTO: Bx11xxxxx + * VERTICAL FIXED: Bxxx01xxx + * VERTICAL SWING: Bxxx10xxx + * VERTICAL WIND: Bxxx11xxx + *******************************************************************************/ + ZHJG01Template[1] = fanSpeed | swingV; + ZHJG01Template[0] = ~ ZHJG01Template[1]; + +/******************************************************************************** + * Byte[2]: Temp, Power, Mode + * TEMP: Bttttxxxx + * POWER ON: Bxxxx0xxx + * POWER OFF: Bxxxx1xxx + * MODE HEAT: Bxxxxx011 + * MODE VENT: Bxxxxx100 + * MODE DRY: Bxxxxx101 + * MODE COOL: Bxxxxx110 + * MODE AUTO: Bxxxxx111 + *******************************************************************************/ + + uint8_t tempBits = ((temperature - 17) << 4) & 0b11110000; + ZHJG01Template[3] = tempBits | powerMode | operatingMode; + ZHJG01Template[2] = ~ ZHJG01Template[3]; + + + ZHJG01Template[5] = 0b11010101; // Undecoded (timer?) + ZHJG01Template[4] = ~ ZHJG01Template[5]; + + // 38 kHz PWM frequency + IR.setFrequency(38); + + // Header + IR.mark(ZHJG01_HDR_MARK); + IR.space(ZHJG01_HDR_SPACE); + + // Data + for (unsigned int i=0; i + +/******************************************************************************** + * TIMINGS + * Space: Not used + * Header Mark: 6550 us + * Header Space: 7755 us + * Bit Mark: 560 us + * Zero Space: 1530 us + * One Space: 3750 us + *******************************************************************************/ +#define ZHJG01_HDR_MARK 6550 +#define ZHJG01_HDR_SPACE 7755 +#define ZHJG01_BIT_MARK 560 +#define ZHJG01_ZERO_SPACE 1530 +#define ZHJG01_ONE_SPACE 3750 + +/******************************************************************************** + * + * ZHJG01 codes + * + *******************************************************************************/ + +// Power +#define ZHJG01_POWER_OFF 0x00 +#define ZHJG01_POWER_ON 0x08 + +// Operating Modes +#define ZHJG01_MODE_AUTO 0x00 +#define ZHJG01_MODE_COOL 0x01 +#define ZHJG01_MODE_DRY 0x02 +#define ZHJG01_MODE_FAN 0x03 +#define ZHJG01_MODE_HEAT 0x04 + +//Fan control +#define ZHJG01_FAN_AUTO 0x00 +#define ZHJG01_FAN1 0x60 +#define ZHJG01_FAN2 0x40 +#define ZHJG01_FAN3 0x20 +#define ZHJG01_FAN_TURBO 0x80 +#define ZHJG01_FAN_ECO 0xA0 +// FAN_4 and FAN_5 are not supported, but are implemented as button "TURBO" +// This only works for HEAT and COOL. Otherwise FAN_3 is used. +// FAN_SILENT is not supported, but is implmented as button "ECO". + +// Vertical Swing +#define ZHJG01_VDIR_WIND 0x00 // "Natural Wind", implemented on VDIR_AUTO +#define ZHJG01_VDIR_SWING 0x08 // Swing +#define ZHJG01_VDIR_FIXED 0x10 // All others are not supported + // and implemented as Fixed + +class ZHJG01HeatpumpIR : public HeatpumpIR +{ + public: + ZHJG01HeatpumpIR(); + void send(IRSender& IR, uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd); + + protected: + void sendZHJG01(IRSender& IR, uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV); +}; + +#endif diff --git a/lib/HeatpumpIR/ZHLT01HeatpumpIR.cpp b/lib/HeatpumpIR/ZHLT01HeatpumpIR.cpp new file mode 100644 index 0000000000..3030183e8a --- /dev/null +++ b/lib/HeatpumpIR/ZHLT01HeatpumpIR.cpp @@ -0,0 +1,198 @@ +#include + +ZHLT01HeatpumpIR::ZHLT01HeatpumpIR() : HeatpumpIR() +{ + static const char model[] PROGMEM = "ZHLT01"; + static const char info[] PROGMEM = "{\"mdl\":\"ZHLT01\",\"dn\":\"ZHLT01\",\"mT\":18,\"xT\":32,\"fs\":3,\"maint\":[10]}}"; + + _model = model; + _info = info; +} + +void ZHLT01HeatpumpIR::send(IRSender& IR, uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd) +{ + +// Sensible defaults for the heat pump mode + + uint8_t powerMode = AC1_POWER_ON; + uint8_t operatingMode = AC1_MODE_AUTO; + uint8_t fanSpeed = AC1_FAN_AUTO; + uint8_t temperature = 25; + uint8_t swingV = AC1_VDIR_FIXED; + uint8_t swingH = AC1_HDIR_FIXED; + + if (powerModeCmd == 0) + { + powerMode = AC1_POWER_OFF; + } + + switch (operatingModeCmd) + { + case MODE_COOL: + operatingMode = AC1_MODE_COOL; + break; + case MODE_FAN: + operatingMode = AC1_MODE_FAN; + break; + case MODE_DRY: + operatingMode = AC1_MODE_DRY; + temperatureCmd = 25; + break; + case MODE_HEAT: + operatingMode = AC1_MODE_HEAT; + break; + case MODE_MAINT: + operatingMode = AC1_MODE_DRY; // MODE_MAINT not supported + temperatureCmd = 30; // Simlulated as DRY at 30°C + break; + default: + operatingMode = AC1_MODE_AUTO; + temperatureCmd = 25; // "Auto" = 25°C + } + + switch (fanSpeedCmd) + { + case FAN_AUTO: + fanSpeed = AC1_FAN_AUTO; + break; + case FAN_SILENT: + fanSpeed = AC1_FAN_SILENT; + break; + case FAN_1: + fanSpeed = AC1_FAN1; + break; + case FAN_2: + fanSpeed = AC1_FAN2; + break; + case FAN_3: + fanSpeed = AC1_FAN3; + break; + case FAN_4: + if ( operatingMode == AC1_MODE_COOL || operatingMode == AC1_MODE_HEAT ) + { fanSpeed = AC1_FAN_TURBO; } + else + { fanSpeed = AC1_FAN3; } + break; + case FAN_5: + if ( operatingMode == AC1_MODE_COOL || operatingMode == AC1_MODE_HEAT ) + { fanSpeed = AC1_FAN_TURBO; } + else + { fanSpeed = AC1_FAN3; } + break; + } + + switch (swingVCmd) + { + case VDIR_AUTO: + swingV = AC1_VDIR_WIND; + break; + case VDIR_SWING: + swingV = AC1_VDIR_SWING; + break; + default: + swingV = AC1_VDIR_FIXED; + } + + switch (swingHCmd) + { + case HDIR_SWING: + swingH = AC1_HDIR_SWING; + break; + default: + swingH = AC1_HDIR_FIXED; + } + +// temperature must be between 16 and 32 degrees + + temperature = temperatureCmd; + + if ( temperatureCmd < 16) + { + temperature = 16; + } + + if (temperatureCmd > 32) + { + temperature = 32; + } + + + sendZHLT01(IR, powerMode, operatingMode, fanSpeed, temperature, swingV, swingH); +} + +void ZHLT01HeatpumpIR::sendZHLT01(IRSender& IR, uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV, + uint8_t swingH) +{ + uint8_t ZHLT01Template[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x2A, 0xD5 }; + // Bytenumbers: 0 1 2 3 4 5 6 7 8 9 10 11 + +/******************************************************************************** + * Byte[03]: Button TURBO used for fanspeed 4 and 5 + * TURBO ON: Bxxxx1xxx (bit3) + * TURBO ON: Bxxxx0xxx + *******************************************************************************/ + if (fanSpeed == AC1_FAN_TURBO) + { + ZHLT01Template[3] = AC1_FAN_TURBO; + ZHLT01Template[2] = ~ ZHLT01Template[3]; + fanSpeed = AC1_FAN_AUTO; + } + + /******************************************************************************** + * Byte[07]: POWER, FAN, SLEEP, HORIZONTAL, VERTICAL + * POWER ON: B0xxxxx1x + * POWER OFF: B0xxxxx0x + * VERTICAL SWING: B0xxx01xx + * VERTICAL WIND: B0xxx00xx + * VERTICAL FIXED: B0xxx10xx + * HORIZONTAL SWING: B0xx0xxxx + * HORIZONTAL OFF: B0xx1xxxx + * FAN AUTO: B000xxxx0 + * FAN SILENT: B000xxxx1 + * FAN3: B001xxxx0 + * FAN2: B010xxxx0 + * FAN1: B011xxxx0 + *******************************************************************************/ + ZHLT01Template[7] = fanSpeed | powerMode | swingV | swingH; + ZHLT01Template[6] = ~ ZHLT01Template[7]; + +/******************************************************************************** + * Byte[09]: Mode, Temperature + * MODE AUTO: B000xxxxx + * MODE COOL: B001xxxxx + * MODE VENT: B011xxxxx + * MODE DRY: B010xxxxx + * MODE HEAT: B100xxxxx + * Temperature is determined by bit0-4: + * 0x00 = 16C + * 0x10 = 32C + *******************************************************************************/ + + ZHLT01Template[9] = operatingMode | (temperature - 16); + ZHLT01Template[8] = ~ ZHLT01Template[9]; + +// 38 kHz PWM frequency + IR.setFrequency(38); + +// Header + IR.mark(AC1_HDR_MARK); + IR.space(AC1_HDR_SPACE); + +// Data + for (unsigned int i=0; i + +/******************************************************************************** + * TIMINGS + * Space: Not used + * Header Mark: 6200 us + * Header Space: 7500 us + * Bit Mark: 475 us + * Zero Space: 525 us + * One Space: 1650 us + *******************************************************************************/ +#define AC1_HDR_MARK 6200 +#define AC1_HDR_SPACE 7500 +#define AC1_BIT_MARK 475 +#define AC1_ZERO_SPACE 525 +#define AC1_ONE_SPACE 1650 + +/******************************************************************************** + * + * ZHLT01 codes + * + *******************************************************************************/ + +// Power +#define AC1_POWER_OFF 0x00 +#define AC1_POWER_ON 0x02 + +// Operating Modes +#define AC1_MODE_AUTO 0x00 +#define AC1_MODE_COOL 0x20 +#define AC1_MODE_DRY 0x40 +#define AC1_MODE_FAN 0x60 +#define AC1_MODE_HEAT 0x80 +// MODE_MAINT is not supported, but implemented as DRY at 30°C. + +//Fan control +#define AC1_FAN_AUTO 0x00 +#define AC1_FAN_SILENT 0x01 +#define AC1_FAN1 0x60 +#define AC1_FAN2 0x40 +#define AC1_FAN3 0x20 +#define AC1_FAN_TURBO 0x08 +// FAN_4 and FAN_5 are not supported, but are implemented as button "TURBO" +// This only works for HEAT and COOL. Otherwise FAN_3 is used. + +// Vertical Swing +#define AC1_VDIR_WIND 0x00 // "Natural Wind", implemented on VDIR_AUTO +#define AC1_VDIR_SWING 0x04 // Swing +#define AC1_VDIR_FIXED 0x08 // All others are not supported + // and implemented as Fixed + +// Horizontal Swing +#define AC1_HDIR_SWING 0x00 // HDIR_SWING +#define AC1_HDIR_FIXED 0x10 // All others are not supported + // and implemented as Fixed + +class ZHLT01HeatpumpIR : public HeatpumpIR +{ + public: + ZHLT01HeatpumpIR(); + void send(IRSender& IR, uint8_t powerModeCmd, + uint8_t operatingModeCmd, + uint8_t fanSpeedCmd, + uint8_t temperatureCmd, + uint8_t swingVCmd, + uint8_t swingHCmd); + + protected: + void sendZHLT01(IRSender& IR, uint8_t powerMode, + uint8_t operatingMode, + uint8_t fanSpeed, + uint8_t temperature, + uint8_t swingV, + uint8_t swingH); +}; + +#endif diff --git a/lib/HeatpumpIR/examples/AUXTest_MQTT/AUXTest_MQTT.ino b/lib/HeatpumpIR/examples/AUXTest_MQTT/AUXTest_MQTT.ino new file mode 100644 index 0000000000..4ad88ce5f7 --- /dev/null +++ b/lib/HeatpumpIR/examples/AUXTest_MQTT/AUXTest_MQTT.ino @@ -0,0 +1,127 @@ +#include +#include +#include + +// This example based on DaikinTest_MQTT example. Thanks for @nick1802 for sample + +IRSenderESP8266 irSender(4); // Set GPIO pin number here. I use D2 pin on my Wemos D1 mini. See image in this example path +AUXHeatpumpIR *heatpumpIR; // This class also works with Hyundai H-AR16-09H model (rc YKR-P/002E) + +// TODO: Make next params manually configurable on first launch + +const char* ssid = "SSID";// your wifi name +const char* password = "SSIDPASS"; // your wifi password + +IPAddress ip(192, 168, 1, 100); //ESP static ip +IPAddress gateway(192, 168, 1, 1); //Set Gateway +IPAddress subnet(255, 255, 255, 0); //Subnet mask +const char* mqtt_server = "192.168.1.101"; // MQTT Server address +const int mqtt_port = 1883; // MQTT Server port (default: 1883) + +String client_id = "ESP-" + String(ESP.getChipId(), HEX); +String power_topic = "homeassistant/ac/" + client_id + "/switch"; +String mode_topic = "homeassistant/ac/" + client_id + "/mode/set"; +String fan_topic = "homeassistant/ac/" + client_id + "/fan_speed/set"; +String temperature_topic = "homeassistant/ac/" + client_id + "/temperature/set"; +String swing_topic = "homeassistant/ac/" + client_id + "/swing/set"; + +int power; +int acmode; +int fan; +int temp; +int swing; + +WiFiClient espClient; +PubSubClient client(espClient); + +void setup() { + Serial.begin(74880); + + setup_wifi(); + + heatpumpIR = new AUXHeatpumpIR(); // Initiate IR receiver object + + client.setServer(mqtt_server, mqtt_port); + client.setCallback(callback); // Set callback to MQTT client which calls everytime in main loop function + + Serial.println("Topics:"); + Serial.println(power_topic); + Serial.println(mode_topic); + Serial.println(fan_topic); + Serial.println(temperature_topic); + Serial.println(swing_topic); + + // Set default AC settings + power = POWER_OFF; + acmode = MODE_AUTO; + fan = FAN_AUTO; + temp = 25; + swing = VDIR_SWING; +} + +void setup_wifi() { + delay(10); + WiFi.mode(WIFI_STA); //set wifi to connect to your wifi and not start a AP + WiFi.config(ip, gateway, subnet); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { // waits for WIFI to connect + delay(500); + } + Serial.println(WiFi.localIP()); + Serial.print("RSSI : "); + Serial.println(WiFi.RSSI()); // wifi signal strength + Serial.println(); +} + +void reconnect() { + while (!client.connected()) { + client.loop(); + if (client.connect(client_id.c_str())) { + client.subscribe(power_topic.c_str()); + client.subscribe(mode_topic.c_str()); + client.subscribe(fan_topic.c_str()); + client.subscribe(temperature_topic.c_str()); + client.subscribe(swing_topic.c_str()); + } else { + delay(500); + } + } +} + +void callback(char* topic, byte* payload, unsigned int length) { + String Payload = ""; + for (int i = 0; i < length; i++) Payload += (char)payload[i]; + + if (String(topic) == power_topic) { + if (Payload == "ON") power = POWER_ON; + else if (Payload == "OFF") power = POWER_OFF; + } + if (String(topic) == mode_topic) { + if (Payload == "heat") acmode = MODE_HEAT; + else if (Payload == "cool") acmode = MODE_COOL; + else if (Payload == "dry") acmode = MODE_DRY; + else if (Payload == "fan_only") acmode = MODE_FAN; + else if (Payload == "auto") acmode = MODE_AUTO; + } + if (String(topic) == fan_topic) { + if (Payload == "auto") fan = FAN_AUTO; + else if (Payload == "low") fan = FAN_1; + else if (Payload == "medium") fan = FAN_2; + else if (Payload == "high") fan = FAN_3; + } + if (String(topic) == temperature_topic) { + temp = Payload.toInt(); + } + if (String(topic) == swing_topic) { + if (Payload == "on") swing = VDIR_AUTO; + else if (Payload == "off") swing = VDIR_SWING; + } + + heatpumpIR->send(irSender, power, acmode, fan, temp, swing, 0); // Last zero because my AC doesn't have horizontal swing function +} + +void loop() { + if (!client.connected()) reconnect(); + client.loop(); + delay(50); +} diff --git a/lib/HeatpumpIR/examples/AUXTest_MQTT/ESP8266-WeMos-D1-Mini-pinout-gpio-pin.png b/lib/HeatpumpIR/examples/AUXTest_MQTT/ESP8266-WeMos-D1-Mini-pinout-gpio-pin.png new file mode 100644 index 0000000000..4d6fd8be8d Binary files /dev/null and b/lib/HeatpumpIR/examples/AUXTest_MQTT/ESP8266-WeMos-D1-Mini-pinout-gpio-pin.png differ diff --git a/lib/HeatpumpIR/examples/AUXTest_MQTT/home_assistant_climate.yaml b/lib/HeatpumpIR/examples/AUXTest_MQTT/home_assistant_climate.yaml new file mode 100644 index 0000000000..0e61bec3bd --- /dev/null +++ b/lib/HeatpumpIR/examples/AUXTest_MQTT/home_assistant_climate.yaml @@ -0,0 +1,10 @@ +climate: + - platform: mqtt + min_temp: 16 + max_temp: 30 + precision: 1.0 + power_command_topic: "homeassistant/ac/{GET IT FROM SERIAL OUTPUT}/switch" + mode_command_topic: "homeassistant/ac/{GET IT FROM SERIAL OUTPUT}/mode/set" + temperature_command_topic: "homeassistant/ac/{GET IT FROM SERIAL OUTPUT}/temperature/set" + fan_mode_command_topic: "homeassistant/ac/{GET IT FROM SERIAL OUTPUT}/fan_speed/set" + swing_mode_command_topic: "homeassistant/ac/{GET IT FROM SERIAL OUTPUT}/swing/set" diff --git a/lib/HeatpumpIR/examples/GreeTest/GreeYACTest/GreeYACTest.ino b/lib/HeatpumpIR/examples/GreeTest/GreeYACTest/GreeYACTest.ino new file mode 100644 index 0000000000..20606a37fb --- /dev/null +++ b/lib/HeatpumpIR/examples/GreeTest/GreeYACTest/GreeYACTest.ino @@ -0,0 +1,62 @@ +#include +#include + +IRSenderPWM irSender(9); // IR led on Duemilanove digital pin 3, using Arduino PWM +//IRSenderBlaster irSender(3); // IR led on Duemilanove digital pin 3, using IR Blaster (generates the 38 kHz carrier) + +GreeYACHeatpumpIR *heatpumpIR; + +int redLED = 6; +int orangeLED = 5; +int greenLED = 4; +int blueLED = 3; + +void setup() +{ + Serial.begin(9600); + pinMode(redLED, OUTPUT); + pinMode(orangeLED, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(blueLED, OUTPUT); + delay(500); + heatpumpIR = new GreeYACHeatpumpIR(); + Serial.println(F("Starting")); +} + +void loop() +{ + const char* buf; + + Serial.print(F("Sending IR to ")); + // Print the model + buf = heatpumpIR->model(); + // 'model' is a PROGMEM pointer, so need to write a byte at a time + while (char modelChar = pgm_read_byte(buf++)) + { + Serial.print(modelChar); + } + Serial.print(F(", info: ")); + // Print the info + buf = heatpumpIR->info(); + // 'info' is a PROGMEM pointer, so need to write a byte at a time + while (char infoChar = pgm_read_byte(buf++)) + { + Serial.print(infoChar); + } + Serial.println(); + + digitalWrite(orangeLED,HIGH); + delay(4000); + heatpumpIR->send(irSender, POWER_ON, MODE_HEAT, FAN_AUTO, 24, VDIR_AUTO, HDIR_AUTO, false, true); + + delay(4000); + heatpumpIR->send(irSender, 24); + + digitalWrite(orangeLED,LOW); + + digitalWrite(redLED, HIGH); + + // don't loop() + for(;;) + ; +} diff --git a/lib/HeatpumpIR/examples/simple/simple.ino b/lib/HeatpumpIR/examples/simple/simple.ino index ea62324827..7210527360 100644 --- a/lib/HeatpumpIR/examples/simple/simple.ino +++ b/lib/HeatpumpIR/examples/simple/simple.ino @@ -21,6 +21,7 @@ #include #include #include +#include #ifndef ESP8266 @@ -44,7 +45,7 @@ HeatpumpIR *heatpumpIR[] = {new PanasonicCKPHeatpumpIR(), new PanasonicDKEHeatpu new GreeGenericHeatpumpIR(), new GreeYANHeatpumpIR(), new GreeYAAHeatpumpIR(), new FuegoHeatpumpIR(), new ToshibaHeatpumpIR(), new ToshibaDaiseikaiHeatpumpIR(), new IVTHeatpumpIR(), new HitachiHeatpumpIR(), - new BalluHeatpumpIR(), new AUXHeatpumpIR(), + new BalluHeatpumpIR(), new AUXHeatpumpIR(), new ZHLT01HeatpumpIR(), NULL}; void setup() diff --git a/lib/HeatpumpIR/keywords.txt b/lib/HeatpumpIR/keywords.txt index 7a8a225954..94e5831c44 100644 --- a/lib/HeatpumpIR/keywords.txt +++ b/lib/HeatpumpIR/keywords.txt @@ -38,6 +38,7 @@ IVTHeatpumpIR KEYWORD1 HitachiHeatpumpIR KEYWORD1 BalluHeatpumpIR KEYWORD1 AUXHeatpumpIR KEYWORD1 +ZHLT01HeatpumpIR KEYWORD1 IRSender KEYWORD1 IRSenderPWM KEYWORD1 diff --git a/lib/HeatpumpIR/library.json b/lib/HeatpumpIR/library.json index c057912e42..db8041a672 100644 --- a/lib/HeatpumpIR/library.json +++ b/lib/HeatpumpIR/library.json @@ -12,9 +12,14 @@ "url": "https://github.com/ToniA/arduino-heatpumpir.git" }, "frameworks": "arduino", - "platforms": [ - "atmelavr", - "espressif8266", - "espressif32" + "platforms": ["atmelavr", "espressif32", "espressif8266"], + "version": "1.0.23", + "dependencies": [ + { + "owner": "crankyoldgit", + "name": "IRremoteESP8266", + "version": "~2.8.4", + "platforms": ["espressif8266"] + } ] } diff --git a/lib/HeatpumpIR/library.properties b/lib/HeatpumpIR/library.properties index 8352284295..30315771af 100644 --- a/lib/HeatpumpIR/library.properties +++ b/lib/HeatpumpIR/library.properties @@ -1,5 +1,5 @@ name=HeatpumpIR -version=1.0.16 +version=1.0.23 author=Toni Arte maintainer=Toni Arte sentence=Heatpump / Air Conditioner infrared control diff --git a/lib/IRremoteESP8266/README.md b/lib/IRremoteESP8266/README.md index e9d16eddda..5eac39e4b8 100644 --- a/lib/IRremoteESP8266/README.md +++ b/lib/IRremoteESP8266/README.md @@ -10,8 +10,8 @@ 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.8.2 Now Available -Version 2.8.2 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. +## v2.8.6 Now Available +Version 2.8.6 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 Usage of the library has been slightly changed in v2.0. You will need to change your usage to work with v2.0 and beyond. You can read more about the changes required on our [Upgrade to v2.0](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Upgrading-to-v2.0) page. diff --git a/lib/IRremoteESP8266/README_de.md b/lib/IRremoteESP8266/README_de.md index 50dbab2cba..9e584bb84b 100644 --- a/lib/IRremoteESP8266/README_de.md +++ b/lib/IRremoteESP8266/README_de.md @@ -11,8 +11,8 @@ Diese Programmbibliothek ermöglicht das **Senden _und_ Empfangen** von Infrarotsignalen mit [ESP8266](https://github.com/esp8266/Arduino)- und [ESP32](https://github.com/espressif/arduino-esp32)-Mikrocontrollern mithilfe des [Arduino-Frameworks](https://www.arduino.cc/) und handelsüblichen 940nm Infrarot-LEDs undIR-Empfängermodulen, wie zum Beispiel TSOP{17,22,24,36,38,44,48}*-Demodulatoren. -## v2.8.2 jetzt verfügbar -Version 2.8.2 der Bibliothek ist nun [verfügbar](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). Die [Versionshinweise](ReleaseNotes.md) enthalten alle wichtigen Neuerungen. +## v2.8.6 jetzt verfügbar +Version 2.8.6 der Bibliothek ist nun [verfügbar](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). Die [Versionshinweise](ReleaseNotes.md) enthalten alle wichtigen Neuerungen. #### Hinweis für Nutzer von Versionen vor v2.0 Die Benutzung der Bibliothek hat sich mit Version 2.0 leicht geändert. Einige Anpassungen im aufrufenden Code werden nötig sein, um mit Version ab 2.0 korrekt zu funktionieren. Mehr zu den Anpassungen finden sich auf unserer [Upgrade to v2.0](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Upgrading-to-v2.0)-Seite. diff --git a/lib/IRremoteESP8266/README_fr.md b/lib/IRremoteESP8266/README_fr.md index 71f4d4abc6..f7bd69eaf8 100644 --- a/lib/IRremoteESP8266/README_fr.md +++ b/lib/IRremoteESP8266/README_fr.md @@ -10,8 +10,8 @@ Cette librairie vous permetra de **recevoir et d'envoyer des signaux** infrarouge sur le protocole [ESP8266](https://github.com/esp8266/Arduino) ou sur le protocole [ESP32](https://github.com/espressif/arduino-esp32) en utilisant le [Arduino framework](https://www.arduino.cc/) qui utilise la norme 940nm IR LEDs et le module basique de reception d'onde IR. Exemple : TSOP{17,22,24,36,38,44,48}* modules etc. -## v2.8.2 disponible -Version 2.8.2 de la libraire est maintenant [disponible](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). Vous pouvez voir le [Release Notes](ReleaseNotes.md) pour tous les changements importants. +## v2.8.6 disponible +Version 2.8.6 de la libraire est maintenant [disponible](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). Vous pouvez voir le [Release Notes](ReleaseNotes.md) pour tous les changements importants. #### mise à jour depuis pre-v2.0 L'utilisation de la librairie à un peu changer depuis la version in v2.0. Si vous voulez l'utiliser vous devrez changer votre utilisation aussi. Vous pouvez vous renseigner sur les précondition d'utilisation ici : [Upgrade to v2.0](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Upgrading-to-v2.0) page. diff --git a/lib/IRremoteESP8266/README_nl.md b/lib/IRremoteESP8266/README_nl.md new file mode 100644 index 0000000000..8c4cb8e08c --- /dev/null +++ b/lib/IRremoteESP8266/README_nl.md @@ -0,0 +1,89 @@ +![IRremoteESP8266 Library](./assets/images/banner.svg) + +[![Build-Status](https://github.com/crankyoldgit/IRremoteESP8266/actions/workflows/Build.yml/badge.svg)](../../actions/workflows/Build.yml/badge.svg) +[![Code-Lint](https://github.com/crankyoldgit/IRremoteESP8266/actions/workflows/Lint.yml/badge.svg)](../../actions/workflows/Lint.yml) +[![Tests](https://github.com/crankyoldgit/IRremoteESP8266/actions/workflows/UnitTests.yml/badge.svg)](../../ctions/workflows/UnitTests.yml) +[![Dokumentation](https://github.com/crankyoldgit/IRremoteESP8266/actions/workflows/Documentation.yml/badge.svg)](../../actions/workflows/Documentation.yml) +[![arduino-library-badge](https://www.ardu-badge.com/badge/IRremoteESP8266.svg?)](https://www.ardu-badge.com/IRremoteESP8266) +[![Arduino-Bibliothek-Abzeichen](https://www.ardu-badge.com/badge/IRremoteESP8266.svg?)](https://www.ardu-badge.com/IRremoteESP8266) +[![Git-Lizenz](https://gitlicense.com/badge/crankyoldgit/IRremoteESP8266)](https://gitlicense.com/license/crankyoldgit/IRremoteESP8266) + +Deze library maakt het mogelijk om Infraroodsignalen **te versturen en ontvangen** via het [Arduino framework](https://www.arduino.cc/) met veelgebruikte 940nm IR LEDs en IR ontvang modules. b.v. TSOP{17,22,24,36,38,44,48}* demodulatoren enz. + +## v2.8.6 nu beschikbaar +Versie 2.8.6 van de bibliotheek is nu [beschikbaar](https://github.com/crankyoldgit/IRremoteESP8266/releases/latest). Bekijk de [Release Notes](ReleaseNotes.md) voor alle belangrijke veranderingen. + +#### Upgraden vanaf pre-v2.0 +Het gebruik van de bibliotheek is enigszins gewijzigd in v2.0. Je zult het gebruik moeten aanpassen om te kunnen werken met v2.0 en hoger. Je kunt meer lezen over de vereiste aanpassingen op onze [Upgraden naar v2.0](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Upgrading-to-v2.0) pagina. + +#### Upgraden vanaf pre-v2.5 +De bibliotheek defineert constanten nu niet meer als `#define`, maar gebruikt +[const](https://google.github.io/styleguide/cppguide.html#Constant_Names) met +de juiste naamgeving volgens de +[C++ style guide](https://google.github.io/styleguide/cppguide.html). +Dit kan ertoe leiden dat oude programma's niet compileren. +De meest extern gebruikte `#define`s zijn _gealiased_ voor beperkte +compatibiliteit voor projecten die de oude stijl gebruiken. In de toekomst zal alleen de +nieuwe `kConstantName` stijl worden ondersteund voor nieuwe protocoltoevoegingen. + +In het onwaarschijnlijke geval dat het je code breekt, dan heb je misschien verwezen naar +iets wat je waarschijnlijk niet had moeten doen. Gelukkig is het redelijk simpel om de nieuwe naam +te bepalen vanaf de oude, b.v. `CONSTANT_NAME` naar `kConstantName`. +Gebruik gezond verstand of onderzoek de code van de bibliotheek als dit van toepassing is op jouw code. + +## Ondersteunde Protocollen +De details van de ondersteunde protocollen en apparaten staan +[hier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md) vermeld. + +## Probleemoplossing +Voordat je een probleem meldt of om hulp vraagt, graag eerst onze [Probleemoplossingsgids](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Troubleshooting-Guide) volgen. + +## Veelgestelde Vragen +Enkele antwoorden op veel veelgestelde vragen en problemen staan op onze [F.A.Q. wiki pagina](https://github.com/crankyoldgit/IRremoteESP8266/wiki/Frequently-Asked-Questions). + +## Bibliotheek API Documentatie +De bibliotheek gebruikt [Doxygen](https://www.doxygen.nl/index.html) om [automatisch documentatie](https://crankyoldgit.github.io/IRremoteESP8266/doxygen/html/) toe te voegen aan de [API](https://en.wikipedia.org/wiki/Application_programming_interface) van de [bibliotheek](https://crankyoldgit.github.io/IRremoteESP8266/doxygen/html/). +Je kunt de documentatie [hier](https://crankyoldgit.github.io/IRremoteESP8266/doxygen/html/) vinden. + +## Installatie +##### Officiële versies via de Arduino IDE v1.8+ (Windows & Linux) +1. Klik op de _"Schets"_ -> _"Bibliotheek gebruiken"_ -> _"Bibliotheken beheren..."_ menuknoppen. +1. Vul `IRremoteESP8266` in bij _"Filter je zoekresultaten..."_ rechtsboven de pop-up. +1. Klik op het IRremoteESP8266 resultaat van de zoekopdracht. +1. Selecteer de versie die je wilt installeren en klik op _"Installeren"_. + +##### Handmatige installatie voor Windows +1. Klik op de _"Clone or Download"_ knop, en kies dan _"[Download ZIP](https://github.com/crankyoldgit/IRremoteESP8266/archive->master.zip)"_. +1. Pak de inhoud van de gedownloade zip uit. +1. Hernoem de uitgepakte map naar _"IRremoteESP8266"_. +1. Verplaats de map naar de bibliotheken map. (voor Windows: `C:\Gebruikers\GEBRUIKERSNAAM\Documenten\Arduino\libraries\`) +1. Herstart de Arduino IDE. +1. Bekijk de voorbeelden. + +##### Git gebruiken om de bibliotheken te installeren ( Linux ) +``` +cd ~/Arduino/libraries +git clone https://github.com/crankyoldgit/IRremoteESP8266.git +``` +###### Om de bibliotheken te updaten naar de laatste versie +``` +cd ~/Arduino/libraries/IRremoteESP8266 && git pull +``` + +## Bijdragen +Als je wilt [bijdragen](.github/CONTRIBUTING.md#how-can-i-contribute) aan dit project, hulp is altijd welkom bij: +- Het [melden](.github/CONTRIBUTING.md#reporting-bugs) van problemen en foutmeldingen +- Ideeën voor verbeteringen +- Verbeteringen van de documentatie +- [Het aanmaken van issues](.github/CONTRIBUTING.md#reporting-bugs) en [pull requests](.github/CONTRIBUTING.md#pull-requests) +- Het delen van deze bibliotheek + +## Bijdragers +Bekijk alle bijdragers [hier](.github/Contributors.md) + +## Bibliotheek Geschiedenis +Deze bibliotheek was oorspronkelijk gebaseerd op het werk van Ken Shirriff (https://github.com/shirriff/Arduino-IRremote/) + +[Mark Szabo](https://github.com/crankyoldgit/IRremoteESP8266) heeft de IRsend class bijgewerkt om te werken op een ESP8266 en [Sebastien Warin](https://github.com/sebastienwarin/IRremoteESP8266) de ontvang & decodeer class (IRrecv). + +Voor v2.0 is de bibliotheek bijna volledig herschreven met de mogelijkheden van de ESP8266 in het achterhoofd. diff --git a/lib/IRremoteESP8266/ReleaseNotes.md b/lib/IRremoteESP8266/ReleaseNotes.md index 5fd04c726e..27b5b3fac2 100644 --- a/lib/IRremoteESP8266/ReleaseNotes.md +++ b/lib/IRremoteESP8266/ReleaseNotes.md @@ -1,5 +1,108 @@ # Release Notes +## _v2.8.6 (20230727)_ + +**[Bug Fixes]** +- Ensure `IRCoolixAC::toCommon()` returns `kNoTempValue` when no sensor temp is detected. (#2015 #2012) +- Fix compilation dependency of LG on Samsung send protocol (#2011 #2010) +- Fix missing parameter in call to `IRac::gree()` (#2008 #2007) + +**[Features]** +- IRac: Ensure the `sleep` parameter is used for the `FUJITSU_AC` protocol. (#1992 #1991) + +**[Misc]** +- Allow the BlynkIRRemote.ino code to compile again. (#2016) +- do not list WHIRLPOOL_AC unconditionally as supported protocol (#2003) +- IRUtils:typeToString() — simplify (#2002) +- Fix brand Green -> Gree (#1994) +- Fix undefined `std::round` compilation error (#1989) + + +## _v2.8.5 (20230508)_ + +**[Bug Fixes]** +- Fix a bug where we never detached the timer interrupt on ESP32s. (#1984 #1983) +- Missing argument in use of midea function (#1959 #1958) +- IRMQTTServer: Improve HA MQTT climate handling. (#1911) +- SEND_SANYO_AC88: Fix poor cut-n-paste error (#1905 #1897) + +**[Features]** +- Add support for a 40bit variant of the standard Panasonic protocol (#1977 @1976) +- Initial support for York AC protocol (#1889) +- IRMQTTServer: SHT-3x Temperature Sensor Support (#1951) +- IRMQTTServer: HA multi output discovery (#1947) +- IRMQTTServer: extended with new A/C common fields (#1940) +- IRMQTTServer: Sync the on state to power from mode for HA (#1946) +- Experimental basic support for Carrier 84-bit protocol. (#1945 #1943) +- Add support the WowWee 11-Bit RoboRaptor-X protocol. (#1939 #1938) +- Added 'sensorTemperature' and 'iFeel' to IRac (common) (#1928) +- Added extra 'mid' option for Fan & SwingV to IRac (#1929) +- Added "commandType" to IRAc (#1921) +- Added support for Argo WREM-3 A/C remote protocol [part1] (#1920) +- Added Dutch (nl-NL) translation (#1907) +- ARGO: Improve code & add support for decoding 32bit sensor msgs. (#1906 #1859) +- Added support for Gorenje cooker hood IR protocol (#1888 #1887) + +**[Misc]** +- Add Electrolux YKR-H/531E as a supported device (#1981 #1980) +- Update `XMP` status to Stable (#1944) +- upgrade to a later version of `googletest` (#1936) +- MITSUBISHI128: Added model to supported protocol (#1924) +- Added Dutch (nl-NL) README (#1908) +- Added GMock to UT Makefile (#1902) +- Update HA example config for HA 2022.6+ (#1901 #1900) +- Add a `d1_mini_noMDNS` build option to `IRMQTTServer`. (#1985) + + +## _v2.8.4 (20220918)_ + +**[Bug Fixes]** + - [Bugfix] Handle gcc unsupported __VA_OPT___ macro (#1880 #1881) + + +## _v2.8.3 (20220915)_ + +**[Bug Fixes]** +- Fix `#if` for DECODE_COOLIX48 (#1796) +- Add missing `prev`s to `decodeToState()` (#1783) + +**[Features]** +- Add `pause()` function to ESP32 when receiving. (#1871) +- ARGO: Argo add `sendSensorTemp()` (#1858 #1859) +- HAIER_AC160: Experimental detail support. (#1852 #1804) +- BOSCH144: Add IRac class support (#1841) +- Mitsubishi_AC: update left vane in `IRac` class (#1837) +- Basic support for Daikin 312bit/39byte A/C protocol. (#1836 #1829) +- Experimental basic support for Sanyo AC 152 bit protocol. (#1828 #1826) +- GREE: Add model support for `YX1FSF`/Soleus Air Windown A/C (#1823 #1821) +- Experimental basic support for Bosch 144bit protocol. (#1822 #1787) +- Experimental basic support for TCL AC 96 bit protocol. (#1820 #1810) +- Add basic support for clima-butler (52bit) RCS-SD43UWI (#1815 #1812) +- TOTO: An experimental _(s)wipe_ at support for Toto Toilets. (#1811 #1806) +- CARRIER_AC128: Experimental Basic support for Carrier AC 128bit protocol. (#1798 #1797) +- HAIER_AC160: Add basic support for Haier 160bit protocol. (#1805 #1804) +- DAIKIN: Add basic support for 200-bit Daikin protocol. (#1803 #1802) +- FUJITSU: Improve handling of 10C Heat mode. (#1788 #1780) +- FUJITSU: Improve handling of short (command only) messages. (#1784 #1780) + +**[Misc]** +- Improve the `_IRREMOTEESP8266_VERSION_VAL` macro (#1875 #1870) +- SONY: Update supported devices. (#1872) +- SAMSUNG: Update supported devices (#1873) +- NEC: Update supported devices (#1874) +- Give IRmacros.h smaller scope to avoid impacting projects using IRremoteESP8266 (#1857 #1853 #1851) +- Inhibit protocol names for not-included protocols (#1853 #1851) +- Test out codeql static analysis (#1842) +- Remove pylint disable=no-self-use (#1817) +- Fujitsu General: update supported devices (#1813) +- DAIKIN: Update supported devices (#1808 #1807) +- Fujitsu: Update supported remote info. (#1801 #1794) +- DAIKIN128: Update supported devices (#1754) +- Voltas: Add link to manual for 122LZF A/C. (#1800 #1799 #1238) +- Daikin128: Additional unit test. (#1795 #1754) +- MIDEA: Update supported devices (#1791 #1790) + + ## _v2.8.2 (20220314)_ **[Bug Fixes]** diff --git a/lib/IRremoteESP8266/SupportedProtocols.md b/lib/IRremoteESP8266/SupportedProtocols.md index 509e7cd506..3c6d38a034 100644 --- a/lib/IRremoteESP8266/SupportedProtocols.md +++ b/lib/IRremoteESP8266/SupportedProtocols.md @@ -1,6 +1,6 @@ + Last generated: Thu 27 Jul 2023 05:37:11 +0000 ---> # IR Protocols supported by this library | Protocol | Brand | Model | A/C Model | Detailed A/C Support | @@ -9,10 +9,13 @@ | [Airwell](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Airwell.cpp) | **[Airwell](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Airwell.h)** | DLS 21 DCI R410 AW A/C
RC04 remote
RC08W remote | | Yes | | [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
TAC-444 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 | +| [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 [WREM2 remote]
Ulisse Eco Mobile Split A/C (Wifi) [WREM3 remote] | SAC_WREM2
SAC_WREM3 | Yes | | [Arris](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Arris.cpp) | **Arris** | 120A V1.0 A18 remote
VIP1113M Set-top box | | - | +| [Bosch](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Bosch.cpp) | **[Bosch](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Bosch.h)** | CL3000i-Set 26 E A/C
RG10A(G2S)BGEF remote | | Yes | | [Bose](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Bose.cpp) | **Bose** | Bose TV Speaker | | - | +| [Carrier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Carrier.cpp) | **[Carrier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Carrier.h)** | 3021203 RR03-S-Remote (CARRIER_AC84)
342WM100CT A/C (CARRIER_AC84)
40GKX0E2006 remote (CARRIER_AC128) | | Yes | | [Carrier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Carrier.cpp) | **[Carrier/Surrey](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Carrier.h)** | 42QG5A55970 remote
53NGK009/012 Inverter
619EGX0090E0 A/C
619EGX0120E0 A/C
619EGX0180E0 A/C
619EGX0220E0 A/C | | Yes | +| [ClimaButler](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_ClimaButler.cpp) | **Clima-Butler** | AR-715 remote
RCS-SD43UWI A/C | | - | | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Airwell](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | RC08B remote | | Yes | | [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
RG57K7(B)/BGEF Remote | | Yes | | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Bosch](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | B1ZAI2441W/B1ZAO2441W A/C
RG36B4/BGE remote | | Yes | @@ -22,7 +25,7 @@ | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Tokio](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | AATOEMF17-12CHR1SW split-type RG51\|50/BGE Remote | | Yes | | [Coolix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.cpp) | **[Toshiba](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Coolix.h)** | RAS-4M27YAV-E A/C
RAS-M10YKV-E A/C
RAS-M13YKV-E A/C
WH-E1YE remote | | Yes | | [Corona](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Corona.cpp) | **[Corona](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Corona.h)** | AR-01 remote
CSH-N2211 A/C
CSH-N2511 A/C
CSH-N2811 A/C
CSH-N4011 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 FTXB09AXVJU A/C (DAIKIN128)
17 Series FTXB12AXVJU A/C (DAIKIN128)
17 Series FTXB24AXVJU A/C (NOT SUPPORTED)
ARC423A5 remote (DAIKIN160)
ARC433** remote (DAIKIN)
ARC433B69 remote (DAIKIN216)
ARC466A33 remote (DAIKIN)
ARC477A1 remote (DAIKIN2)
ARC480A5 remote (DAIKIN152)
ARC484A4 remote (DAIKIN216)
BRC4C151 remote (DAIKIN176)
BRC4C153 remote (DAIKIN176)
BRC52B63 remote (DAIKIN128)
DGS01 remote (DAIKIN64)
FFN-C/FCN-F Series A/C (DAIKIN64)
FFQ35B8V1B A/C (DAIKIN176)
FTE12HV2S A/C
FTQ60TV16U2 A/C (DAIKIN216)
FTWX35AXV1 A/C (DAIKIN64)
FTXM-M A/C (DAIKIN)
FTXZ25NV1B A/C (DAIKIN2)
FTXZ35NV1B A/C (DAIKIN2)
FTXZ50NV1B A/C (DAIKIN2)
M Series A/C (DAIKIN) | | 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 FTXB09AXVJU A/C (DAIKIN128)
17 Series FTXB12AXVJU A/C (DAIKIN128)
17 Series FTXB24AXVJU A/C (DAIKIN128)
ARC423A5 remote (DAIKIN160)
ARC433** remote (DAIKIN)
ARC433B69 remote (DAIKIN216)
ARC466A12 remote (DAIKIN)
ARC466A33 remote (DAIKIN)
ARC466A67 remote (DAIKIN312)
ARC477A1 remote (DAIKIN2)
ARC480A5 remote (DAIKIN152)
ARC484A4 remote (DAIKIN216)
BRC4C151 remote (DAIKIN176)
BRC4C153 remote (DAIKIN176)
BRC4M150W16 remote (DAIKIN200)
BRC52B63 remote (DAIKIN128)
DGS01 remote (DAIKIN64)
FFN-C/FCN-F Series A/C (DAIKIN64)
FFQ35B8V1B A/C (DAIKIN176)
FTE12HV2S A/C
FTQ60TV16U2 A/C (DAIKIN216)
FTWX35AXV1 A/C (DAIKIN64)
FTXM-M A/C (DAIKIN)
FTXM20R5V1B A/C (DAIKIN312)
FTXZ25NV1B A/C (DAIKIN2)
FTXZ35NV1B A/C (DAIKIN2)
FTXZ50NV1B A/C (DAIKIN2)
M Series A/C (DAIKIN) | | Yes | | [Delonghi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Delonghi.cpp) | **[Delonghi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Delonghi.h)** | PAC A95 | | Yes | | [Denon](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Denon.cpp) | **Denon** | AVR-3801 A/V Receiver (probably) | | - | | [Dish](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Dish.cpp) | **DISH NETWORK** | echostar 301 | | - | @@ -32,34 +35,37 @@ | [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 | | [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[Centek](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | SCT-65Q09 A/C
YKR-P/002E remote | | Yes | | [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | Classic INV 17 / AXW12DCS A/C
YKR-M/003E remote | | Yes | +| [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[Electrolux](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | YKR-H/531E A/C | | Yes | | [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[Frigidaire](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | FGPC102AB1 A/C | | Yes | | [Electra](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.cpp) | **[Subtropic](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Electra.h)** | SUB-07HN1_18Y A/C
YKR-H/102E remote | | Yes | | [EliteScreens](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_EliteScreens.cpp) | **Elite Screens** | CineTension2 / CineTension3 series
Home2 / Home3 series
Spectrum series
VMAX Plus4 series
VMAX2 / VMAX2 Plus series
ZSP-IR-B / ZSP-IR-W remote | | - | | [EliteScreens](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_EliteScreens.cpp) | **Lumene Screens** | Embassy | | - | | [Epson](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Epson.cpp) | **Epson** | EN-TW9100W Projector
EX3220 Projector
EX5220 Projector
EX5230 Projector
EX6220 Projector
EX7220 Projector
VS230 Projector
VS330 Projector | | - | -| [Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.cpp) | **[Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.h)** | AGTV14LAC A/C (ARRAH2E)
AR-DB1 remote (ARDB1)
AR-DL10 remote (ARDB1)
AR-RAC1E remote (ARRAH2E)
AR-RAE1E remote (ARRAH2E)
AR-RAH1U remote (ARREB1E)
AR-RAH2E remote (ARRAH2E)
AR-REB1E remote (ARREB1E)
AR-REB4E remote (ARREB1E)
AR-REW1E remote (ARREW4E)
AR-REW4E remote (ARREW4E)
AR-RY4 remote (ARRY4)
AST9RSGCW A/C (ARDB1)
ASTB09LBC A/C (ARRY4)
ASTG09K A/C (ARREW4E)
ASTG18K A/C (ARREW4E)
ASU12RLF A/C (ARREB1E)
ASU30C1 A/C (ARDB1)
ASYG09KETA-B A/C (ARREW4E)
ASYG30LFCA A/C (ARRAH2E)
ASYG7LMCA A/C (ARREB1E) | ARDB1
ARJW2
ARRAH2E
ARREB1E
ARREW4E
ARRY4 | Yes | -| [Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.cpp) | **[Fujitsu General](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.h)** | AOHG09LLC A/C (ARRAH2E)
AR-JW2 remote (ARJW2)
AR-RCE1E remote (ARRAH2E)
ASHG09LLCA A/C (ARRAH2E) | ARDB1
ARJW2
ARRAH2E
ARREB1E
ARREW4E
ARRY4 | Yes | +| [Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.cpp) | **[Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.h)** | AGTV14LAC A/C (ARRAH2E)
AR-DB1 remote (ARDB1)
AR-DL10 remote (ARDB1)
AR-RAC1E remote (ARRAH2E)
AR-RAE1E remote (ARRAH2E)
AR-RAH1U remote (ARREB1E)
AR-RAH2E remote (ARRAH2E)
AR-RAH2U remote (ARRAH2E)
AR-REB1E remote (ARREB1E)
AR-REB4E remote (ARREB1E)
AR-REG1U remote (ARRAH2E)
AR-REW1E remote (ARREW4E)
AR-REW4E remote (ARREW4E)
AR-RY4 remote (ARRY4)
AST9RSGCW A/C (ARDB1)
ASTB09LBC A/C (ARRY4)
ASTG09K A/C (ARREW4E)
ASTG18K A/C (ARREW4E)
ASU12RLF A/C (ARREB1E)
ASU30C1 A/C (ARDB1)
ASYG09KETA-B A/C (ARREW4E)
ASYG30LFCA A/C (ARRAH2E)
ASYG7LMCA A/C (ARREB1E) | ARDB1
ARJW2
ARRAH2E
ARREB1E
ARREW4E
ARRY4 | Yes | +| [Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.cpp) | **[Fujitsu General](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.h)** | AOHG09LLC A/C (ARRAH2E)
AR-JW17 remote (ARDB1)
AR-JW2 remote (ARJW2)
AR-RCE1E remote (ARRAH2E)
ASHG09LLCA A/C (ARRAH2E) | ARDB1
ARJW2
ARRAH2E
ARREB1E
ARREW4E
ARRY4 | Yes | +| [Fujitsu](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.cpp) | **[OGeneral](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Fujitsu.h)** | AR-RCL1E remote (ARRAH2E) | ARDB1
ARJW2
ARRAH2E
ARREB1E
ARREW4E
ARRY4 | Yes | | [GICable](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_GICable.cpp) | **G.I. Cable** | XRC-200 remote | | - | | [GlobalCache](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_GlobalCache.cpp) | **Global Cache** | Control Tower IR DB | | - | | [Goodweather](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Goodweather.cpp) | **[Goodweather](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Goodweather.h)** | ZH/JT-03 remote | | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Amana](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | PBC093G00CC A/C
YX1FF remote | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Cooper & Hunter](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | CH-S09FTXG A/C
YB1F2 remote | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[EKOKAI](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | A/C | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | VIR09HP115V1AH A/C
VIR12HP230V1AH A/C
YAA1FBF remote
YAN1F1 remote
YB1F2F remote | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Green](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | YBOFB remote
YBOFB2 remote | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[RusClimate](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | EACS/I-09HAR_X/N3 A/C
YAW1F remote | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Ultimate](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | Heat Pump | YAW1F
YBOFB | Yes | -| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Vailland](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | VAI5-035WNI A/C
YACIFB remote | YAW1F
YBOFB | Yes | +| [Gorenje](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gorenje.cpp) | **Gorenje** | DKF 2600 MWT Cooker Hood | | - | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Amana](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | PBC093G00CC A/C
YX1FF remote | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Cooper & Hunter](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | CH-S09FTXG A/C
YB1F2 remote | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[EKOKAI](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | A/C | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | VIR09HP115V1AH A/C
VIR12HP230V1AH A/C
YAA1FBF remote
YAN1F1 remote
YB1F2F remote
YX1F2F remote (YX1FSF) | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Green](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | YBOFB remote
YBOFB2 remote | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[RusClimate](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | EACS/I-09HAR_X/N3 A/C
YAW1F remote | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Soleus Air](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | window A/C (YX1FSF) | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Ultimate](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | Heat Pump | YAW1F
YBOFB
YX1FSF | Yes | +| [Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.cpp) | **[Vailland](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Gree.h)** | VAI5-035WNI A/C
YACIFB remote | YAW1F
YBOFB
YX1FSF | Yes | | [Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.cpp) | **[Daichi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.h)** | D-H A/C (HAIER_AC176) | | Yes | -| [Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.cpp) | **[Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.h)** | HSU-09HMC203 A/C (HAIER_AC_YRW02)
HSU07-HEA03 remote (HAIER_AC)
V9014557 M47 8D remote (HAIER_AC176)
YR-W02 remote (HAIER_AC_YRW02) | | Yes | +| [Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.cpp) | **[Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.h)** | HSU-09HMC203 A/C (HAIER_AC_YRW02)
HSU07-HEA03 remote (HAIER_AC)
KFR-26GW/83@UI-Ge A/C (HAIER_AC160)
V9014557 M47 8D remote (HAIER_AC176)
YR-W02 remote (HAIER_AC_YRW02) | | Yes | | [Haier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.cpp) | **[Mabe](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Haier.h)** | MMI18HDBWCA6MI8 A/C (HAIER_AC176)
V12843 HJ200223 remote (HAIER_AC176) | | Yes | | [Hitachi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Hitachi.cpp) | **[Hitachi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Hitachi.h)** | KAZE-312KSDP A/C (HITACHI_AC1)
LT0541-HTA remote (HITACHI_AC1)
PC-LH3B (HITACHI_AC3)
R-LT0541-HTA/Y.K.1.1-1 V2.3 remote (HITACHI_AC1)
RAK-25NH5 A/C (HITACHI_AC264)
RAR-2P2 remote (HITACHI_AC264)
RAR-3U3 remote (HITACHI_AC296)
RAR-8P2 remote (HITACHI_AC424)
RAS-22NK A/C (HITACHI_AC344)
RAS-35THA6 remote
RAS-70YHA3 A/C (HITACHI_AC296)
RAS-AJ25H A/C (HITACHI_AC424)
RF11T1 remote (HITACHI_AC344)
Series VI A/C (Circa 2007) (HITACHI_AC1) | | Yes | | [Inax](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Inax.cpp) | **Lixil** | Inax DT-BA283 Toilet | | - | | [JVC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_JVC.cpp) | **JVC** | PTU94023B remote | | - | | [Kelon](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelon.cpp) | **[Hisense](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelon.h)** | AST-09UW4RVETG00A A/C (KELON168) | | Yes | | [Kelon](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelon.cpp) | **[Kelon](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelon.h)** | AST-09UW4RVETG00A A/C (KELON168)
DG11R2-01 remote (KELON168)
ON/OFF 9000-12000 (KELON) | | Yes | -| [Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.cpp) | **[Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.h)** | YAP0F8 remote | | Yes | -| [Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.cpp) | **[Green](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.h)** | YAPOF3 remote | | Yes | +| [Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.cpp) | **[Gree](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.h)** | YAP0F8 remote
YAPOF3 remote | | Yes | | [Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.cpp) | **[Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.h)** | KSV26CRC A/C
KSV26HRC A/C
KSV35CRC A/C
KSV35HRC A/C
KSV53HRC A/C
KSV62HRC A/C
KSV70CRC A/C
KSV70HRC A/C
KSV80HRC A/C
YALIF Remote | | Yes | | [Kelvinator](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.cpp) | **[Sharp](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Kelvinator.h)** | A5VEY A/C
YB1FA remote | | Yes | | [LG](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_LG.cpp) | **[General Electric](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_LG.h)** | 6711AR2853M Remote (LG - GE6711AR2853M)
AG1BH09AW101 A/C (LG - GE6711AR2853M) | | Yes | @@ -78,18 +84,20 @@ | [Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp) | **[Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h)** | FS40-7AR Stand Fan (MIDEA24) | | Yes | | [Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp) | **[MrCool](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h)** | RG57A6/BGEFU1 remote (MIDEA) | | Yes | | [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)** | RG66B6(B)/BGEFU1 remote (MIDEA)
RUBO18GMFILCAD A/C (18K BTU) (MIDEA)
RYBO12GMFILCAD A/C (12K BTU) (MIDEA)
UB018GMFILCFHD A/C (12K BTU) (MIDEA)
WS012GMFI22HLD A/C (12K BTU) (MIDEA)
WS018GMFI22HLD A/C (12K BTU) (MIDEA) | | Yes | -| [Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp) | **[Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h)** | RG57H(B)/BGE remote (MIDEA)
TROTEC PAC 3900 X (MIDEA) | | Yes | +| [Midea](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.cpp) | **[Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Midea.h)** | RG57H(B)/BGE remote (MIDEA)
RG57H3(B)/BGCEF-M remote (MIDEA)
TROTEC PAC 2100 X (MIDEA)
TROTEC PAC 3900 X (MIDEA) | | Yes | | [MilesTag2](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_MilesTag2.cpp) | **Milestag2** | Various | | - | | [Mirage](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.cpp) | **[Maxell](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.h)** | KKG9A-C1 remote
MX-CH18CF A/C | KKG29AC1
KKG9AC1 | Yes | | [Mirage](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.cpp) | **[Mirage](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.h)** | VLU series A/C | KKG29AC1
KKG9AC1 | Yes | | [Mirage](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.cpp) | **[Tronitechnik](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mirage.h)** | KKG29A-C1 remote
Reykir 9000 A/C | KKG29AC1
KKG9AC1 | 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 (MITSUBISHI2)
KM14A 0179213 remote
MS-GK24VA A/C
TV (MITSUBISHI) | | Yes | -| [Mitsubishi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.cpp) | **[Mitsubishi Electric](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.h)** | 001CP T7WE10714 remote (MITSUBISHI136)
KPOA remote (MITSUBISHI112)
MLZ-RX5017AS A/C (MITSUBISHI_AC)
MSH-A24WV A/C (MITSUBISHI112)
MSZ-FHnnVE A/C (MITSUBISHI_AC)
MSZ-GV2519 A/C (MITSUBISHI_AC)
MSZ-SF25VE3 A/C (MITSUBISHI_AC)
MSZ-ZW4017S A/C (MITSUBISHI_AC)
MUH-A24WV A/C (MITSUBISHI112)
PEAD-RP71JAA Ducted A/C (MITSUBISHI136)
RH151 remote (MITSUBISHI_AC)
RH151/M21ED6426 remote (MITSUBISHI_AC)
SG153/M21EDF426 remote (MITSUBISHI_AC)
SG15D remote (MITSUBISHI_AC) | | Yes | +| [Mitsubishi](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.cpp) | **[Mitsubishi Electric](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Mitsubishi.h)** | 001CP T7WE10714 remote (MITSUBISHI136)
KPOA remote (MITSUBISHI112)
MLZ-RX5017AS A/C (MITSUBISHI_AC)
MSH-A24WV A/C (MITSUBISHI112)
MSZ-FHnnVE A/C (MITSUBISHI_AC)
MSZ-GV2519 A/C (MITSUBISHI_AC)
MSZ-SF25VE3 A/C (MITSUBISHI_AC)
MSZ-ZW4017S A/C (MITSUBISHI_AC)
MUH-A24WV A/C (MITSUBISHI112)
PAR-FA32MA remote (MITSUBISHI136)
PEAD-RP71JAA Ducted A/C (MITSUBISHI136)
RH151 remote (MITSUBISHI_AC)
RH151/M21ED6426 remote (MITSUBISHI_AC)
SG153/M21EDF426 remote (MITSUBISHI_AC)
SG15D remote (MITSUBISHI_AC) | | 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 (88 bit)
RLA502A700B remote (152 bit)
SRKxxZJ-S A/C (88 bit)
SRKxxZM-S A/C (152 bit)
SRKxxZMXA-S A/C (152 bit) | | Yes | | [Multibrackets](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Multibrackets.cpp) | **Multibrackets** | Motorized Swing mount large - 4500 | | - | | [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Aloka](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | SleepyLights LED Lamp | | - | +| [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[BBK](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | SP550S 5.1 sound system | | - | | [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Duux](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | Blizzard Smart 10K / DXMA04 A/C
YJ-A081 TR Remote | | - | | [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Silan Microelectronics](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | SC6121-001 IC | | - | +| [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Tanix](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | TX3 mini Android TV Box | | - | | [NEC](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.cpp) | **[Toshiba](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_NEC.h)** | 42TL838 LCD TV | | - | | [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 | | - | | [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
ZH/TY-01 remote | | Yes | @@ -101,11 +109,11 @@ | [RC5_RC6](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_RC5_RC6.cpp) | **Philips** | RC-5X (RC5X)
Standard RC-5 (RC5)
Standard RC-6 (RC6) | | - | | [RCMM](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_RCMM.cpp) | **Microsoft** | XBOX 360 | | - | | [Rhoss](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Rhoss.cpp) | **[Rhoss](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Rhoss.h)** | Idrowall MPCV 20-30-35-40 | | Yes | -| [Samsung](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Samsung.cpp) | **[Samsung](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Samsung.h)** | AH59-02692E Soundbar remote (SAMSUNG36)
AK59-00167A Bluray remote (SAMSUNG36)
AR09FSSDAWKNFA A/C (SAMSUNG_AC)
AR09HSFSBWKN A/C (SAMSUNG_AC)
AR12HSSDBWKNEU A/C (SAMSUNG_AC)
AR12KSFPEWQNET A/C (SAMSUNG_AC)
AR12NXCXAWKXEU A/C (SAMSUNG_AC)
AR12TXEAAWKNEU A/C (SAMSUNG_AC)
BN59-01178B TV remote (SAMSUNG)
DB63-03556X003 remote
DB93-14195A remote (SAMSUNG_AC)
DB93-16761C remote
DB96-24901C remote (SAMSUNG_AC)
HW-J551 Soundbar (SAMSUNG36)
IEC-R03 remote
UA55H6300 TV (SAMSUNG) | | Yes | -| [Sanyo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sanyo.cpp) | **[Sanyo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sanyo.h)** | LC7461 transmitter IC (SANYO_LC7461)
RCS-2HS4E remote (SANYO_AC)
RCS-2S4E remote (SANYO_AC)
SA 8650B - disabled
SAP-K121AHA A/C (SANYO_AC)
SAP-K242AH A/C (SANYO_AC) | | Yes | +| [Samsung](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Samsung.cpp) | **[Samsung](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Samsung.h)** | AH59-02692E Soundbar remote (SAMSUNG36)
AK59-00167A Bluray remote (SAMSUNG36)
AR09FSSDAWKNFA A/C (SAMSUNG_AC)
AR09HSFSBWKN A/C (SAMSUNG_AC)
AR12HSSDBWKNEU A/C (SAMSUNG_AC)
AR12KSFPEWQNET A/C (SAMSUNG_AC)
AR12NXCXAWKXEU A/C (SAMSUNG_AC)
AR12TXEAAWKNEU A/C (SAMSUNG_AC)
BN59-01178B TV remote (SAMSUNG)
DB63-03556X003 remote
DB93-14195A remote (SAMSUNG_AC)
DB93-16761C remote
DB96-24901C remote (SAMSUNG_AC)
HW-J551 Soundbar (SAMSUNG36)
IEC-R03 remote
UA55H6300 TV (SAMSUNG)
UE40K5510AUXRU TV (SAMSUNG) | | Yes | +| [Sanyo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sanyo.cpp) | **[Sanyo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sanyo.h)** | LC7461 transmitter IC (SANYO_LC7461)
RCS-2HS4E remote (SANYO_AC)
RCS-2S4E remote (SANYO_AC)
RCS-4MHVPIS4EE remote (SANYO_AC152)
SA 8650B - disabled
SAP-K121AHA A/C (SANYO_AC)
SAP-K242AH A/C (SANYO_AC)
SAP-KMRV124EHE A/C (SANYO_AC152) | | Yes | | [Sharp](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sharp.cpp) | **[Sharp](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sharp.h)** | AH-A12REVP-1 A/C (A903)
AH-AxSAY A/C (A907)
AH-PR13-GL A/C (A903)
AH-XP10NRY A/C (A903)
AY-ZP40KR A/C (A907)
CRMC-820 JBEZ remote (A903)
CRMC-A705 JBEZ remote (A705)
CRMC-A863 JBEZ remote (A903)
CRMC-A903JBEZ remote (A903)
CRMC-A907 JBEZ remote (A907)
CRMC-A950 JBEZ (A907)
LC-52D62U TV | A705
A903
A907 | Yes | | [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) | **Sony** | HT-CT380 Soundbar (Uses 38kHz & 3 repeats) | | - | +| [Sony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Sony.cpp) | **Sony** | HT-CT380 Soundbar (Uses 38kHz & 3 repeats)
HT-SF150 Soundbar (Uses 38kHz & 3 repeats) | | - | | [Symphony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp) | **Blyss** | Owen-SW-5 3 Fan
WP-YK8 090218 remote | | - | | [Symphony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp) | **SamHop** | SM3015 Fan Remote Control
SM5021 Encoder chip
SM5032 Decoder chip | | - | | [Symphony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp) | **Satellite Electronic** | ID6 Remote
JY199I Fan driver
JY199I-L Fan driver | | - | @@ -114,13 +122,14 @@ | [Symphony](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp) | **Westinghouse** | 78095 Remote
Ceiling fan | | - | | [Tcl](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.cpp) | **[Daewoo](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.h)** | DSB-F0934ELH-V A/C
GYKQ-52E remote | GZ055BE1
TAC09CHSD | Yes | | [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 (TAC09CHSD) | GZ055BE1
TAC09CHSD | Yes | -| [Tcl](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.cpp) | **[TCL](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.h)** | TAC-09CHSD/XA31I A/C (TAC09CHSD) | GZ055BE1
TAC09CHSD | Yes | +| [Tcl](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.cpp) | **[TCL](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.h)** | GYKQ-58(XM) remote (TCL96AC)
TAC-09CHSD/XA31I A/C (TAC09CHSD) | GZ055BE1
TAC09CHSD | Yes | | [Tcl](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.cpp) | **[Teknopoint](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Tcl.h)** | Allegro SSA-09H A/C (GZ055BE1)
GZ-055B-E1 remote (GZ055BE1) | GZ055BE1
TAC09CHSD | Yes | | [Technibel](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Technibel.cpp) | **[Technibel](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Technibel.h)** | IRO PLUS | | 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 | | [Teknopoint](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Teknopoint.cpp) | **Teknopoint** | Allegro SSA-09H A/C
GZ-055B-E1 remote
GZ01-BEJ0-000 remote | | - | | [Toshiba](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Toshiba.cpp) | **[Carrier](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Toshiba.h)** | 42NQV025M2 / 38NYV025M2 A/C
42NQV035M2 / 38NYV035M2 A/C
42NQV050M2 / 38NYV050M2 A/C
42NQV060M2 / 38NYV060M2 A/C | | 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-2558V A/C
RAS-25SKVP2-ND A/C
RAS-B13N3KV2
RAS-B13N3KVP-E
WC-L03SE
WH-TA01JE remote
WH-TA04NE
WH-UB03NJ remote | | Yes | +| [Toto](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Toto.cpp) | **Toto** | Washlet Toilet NJ | | - | | [Transcold](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Transcold.cpp) | **[Transcold](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Transcold.h)** | M1-F-NO-6 A/C | | Yes | | [Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.cpp) | **[Duux](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.h)** | Blizzard Smart 10K / DXMA04 A/C (TROTEC) | | Yes | | [Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.cpp) | **[Trotec](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Trotec.h)** | PAC 3200 A/C (TROTEC)
PAC 3550 Pro A/C (TROTEC_3550) | | Yes | @@ -129,7 +138,9 @@ | [Voltas](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Voltas.cpp) | **[Voltas](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Voltas.h)** | 122LZF 4011252 Window A/C | 122LZF | Yes | | [Whirlpool](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Whirlpool.cpp) | **[Whirlpool](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Whirlpool.h)** | DG11J1-04 remote
DG11J1-3A remote
DG11J1-91 remote
SPIS409L A/C
SPIS412L A/C
SPIW409L A/C
SPIW412L A/C
SPIW418L A/C | DG11J13A
DG11J191 | Yes | | [Whynter](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Whynter.cpp) | **Whynter** | ARC-110WD A/C | | - | +| [Wowwee](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Wowwee.cpp) | **WowWee** | RoboRapter-X | | - | | [Xmp](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Xmp.cpp) | **Xfinity** | XR11 remote
XR2 remote | | - | +| [York](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_York.cpp) | **[York](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_York.h)** | GRYLH2A remote
MHH07P17 A/C | | Yes | | [Zepeal](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Zepeal.cpp) | **Zepeal** | DRT-A3311(BG) 5 button remote
DRT-A3311(BG) floor fan | | - | @@ -150,10 +161,14 @@ - AMCOR - ARGO - ARRIS +- BOSCH144 - BOSE - CARRIER_AC +- CARRIER_AC128 - CARRIER_AC40 - CARRIER_AC64 +- CARRIER_AC84 +- CLIMABUTLER - COOLIX - COOLIX48 - CORONA_AC @@ -163,7 +178,9 @@ - DAIKIN160 - DAIKIN176 - DAIKIN2 +- DAIKIN200 - DAIKIN216 +- DAIKIN312 - DAIKIN64 - DELONGHI_AC - DENON @@ -176,8 +193,10 @@ - FUJITSU_AC - GICABLE - GOODWEATHER +- GORENJE - GREE - HAIER_AC +- HAIER_AC160 - HAIER_AC176 - HAIER_AC_YRW02 - HITACHI_AC @@ -231,6 +250,7 @@ - SAMSUNG_AC - SANYO - SANYO_AC +- SANYO_AC152 - SANYO_AC88 - SANYO_LC7461 - SHARP @@ -238,10 +258,12 @@ - SONY - SYMPHONY - TCL112AC +- TCL96AC - TECHNIBEL_AC - TECO - TEKNOPOINT - TOSHIBA_AC +- TOTO - TRANSCOLD - TROTEC - TROTEC_3550 @@ -250,5 +272,7 @@ - VOLTAS - WHIRLPOOL_AC - WHYNTER +- WOWWEE - XMP +- YORK - ZEPEAL diff --git a/lib/IRremoteESP8266/examples/BlynkIrRemote/BlynkIrRemote.ino b/lib/IRremoteESP8266/examples/BlynkIrRemote/BlynkIrRemote.ino index 7eaed8f83b..686cba1fbd 100644 --- a/lib/IRremoteESP8266/examples/BlynkIrRemote/BlynkIrRemote.ino +++ b/lib/IRremoteESP8266/examples/BlynkIrRemote/BlynkIrRemote.ino @@ -104,6 +104,8 @@ /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial +#define BLYNK_TEMPLATE_ID "TMPL••••••••" // Made up values. Please Change. +#define BLYNK_TEMPLATE_NAME "My First Device" // Please Change. #if defined(ESP8266) #include diff --git a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h index 611c1ff73a..d347b69cb9 100644 --- a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h +++ b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.h @@ -132,6 +132,8 @@ const uint32_t kMqttReconnectTime = 5000; // Delay(ms) between reconnect tries. #define MQTT_CLIMATE "ac" // Sub-topic for the climate topics. #define MQTT_CLIMATE_CMND "cmnd" // Sub-topic for the climate command topics. #define MQTT_CLIMATE_STAT "stat" // Sub-topic for the climate stat topics. +// Sub-topic for the temperature/humidity sensor stat topics. +#define MQTT_SENSOR_STAT "sensor" // Enable sending/receiving climate via JSON. `true` cost ~5k of program space. #define MQTT_CLIMATE_JSON false @@ -221,6 +223,25 @@ const uint16_t kMinUnknownSize = 2 * 10; // actual a/c unit. #define REPLAY_DECODED_AC_MESSAGE false +// ------------------------ SHT-3x Support ------------------------------------- +// To enable SHT-3x sensor support (such as the Lolin SHT30 Shield), connected +// to GPIOs 4 and 5 (D2 and D1), do the following: +// - uncomment the line in platformio.ini to enable the SHT-3x library +// - uncomment the following #define line +// #define SHT3X_SUPPORT true + +// Default address for SHT-3x sensor. +#define SHT3X_I2C_ADDRESS 0x44 +// Requires MQTT_DISCOVERY_ENABLE to be true as well. +// If set, will send HA MQTT Discovery messages for the SHT-3x sensor. +#define SHT3X_MQTT_DISCOVERY_ENABLE true +// I2C SDA pin for SHT-3x sensor (D2). +#define SHT3X_I2C_SDA 4 +// I2C SCL pin for SHT-3x sensor (D1). +#define SHT3X_I2C_SCL 5 +// Check frequency for SHT-3x sensor (in seconds). +#define SHT3X_CHECK_FREQ 60 + // ------------------------ Advanced Usage Only -------------------------------- // Reports the input voltage to the ESP chip. **NOT** the input voltage @@ -238,6 +259,7 @@ const uint16_t kMinUnknownSize = 2 * 10; #define KEY_POWER "power" #define KEY_MODE "mode" #define KEY_TEMP "temp" +#define KEY_HUMIDITY "humidity" #define KEY_FANSPEED "fanspeed" #define KEY_SWINGV "swingv" #define KEY_SWINGH "swingh" @@ -253,6 +275,9 @@ const uint16_t kMinUnknownSize = 2 * 10; #define KEY_JSON "json" #define KEY_RESEND "resend" #define KEY_VCC "vcc" +#define KEY_COMMAND "command" +#define KEY_SENSORTEMP "sensortemp" +#define KEY_IFEEL "ifeel" // HTML arguments we will parse for IR code information. #define KEY_TYPE "type" // KEY_PROTOCOL is also checked too. @@ -260,11 +285,17 @@ const uint16_t kMinUnknownSize = 2 * 10; #define KEY_BITS "bits" #define KEY_REPEAT "repeats" #define KEY_CHANNEL "channel" // Which IR TX channel to send on. +#define KEY_SENSORTEMP_DISABLED "sensortemp_disabled" // For HTML form only, + // not sent via MQTT + // nor JSON // GPIO html/config keys #define KEY_TX_GPIO "tx" #define KEY_RX_GPIO "rx" +// Miscellaneous constants +#define TOGGLE_JS_FN_NAME "ToggleInputBasedOnCheckbox" + // Text for Last Will & Testament status messages. const char* const kLwtOnline = "Online"; const char* const kLwtOffline = "Offline"; @@ -290,7 +321,7 @@ const uint16_t kJsonAcStateMaxSize = 1024; // Bytes // ----------------- End of User Configuration Section ------------------------- // Constants -#define _MY_VERSION_ "v1.7.0" +#define _MY_VERSION_ "v1.8.2" const uint8_t kRebootTime = 15; // Seconds const uint8_t kQuickDisplayTime = 2; // Seconds @@ -358,7 +389,8 @@ static const char kClimateTopics[] PROGMEM = "(" KEY_PROTOCOL "|" KEY_MODEL "|" KEY_POWER "|" KEY_MODE "|" KEY_TEMP "|" KEY_FANSPEED "|" KEY_SWINGV "|" KEY_SWINGH "|" KEY_QUIET "|" KEY_TURBO "|" KEY_LIGHT "|" KEY_BEEP "|" KEY_ECONO "|" KEY_SLEEP "|" - KEY_FILTER "|" KEY_CLEAN "|" KEY_CELSIUS "|" KEY_RESEND + KEY_FILTER "|" KEY_CLEAN "|" KEY_CELSIUS "|" KEY_RESEND "|" KEY_COMMAND "|" + "|" KEY_SENSORTEMP "|" KEY_IFEEL #if MQTT_CLIMATE_JSON "|" KEY_JSON #endif // MQTT_CLIMATE_JSON @@ -367,6 +399,7 @@ static const char* const kMqttTopics[] = { KEY_PROTOCOL, KEY_MODEL, KEY_POWER, KEY_MODE, KEY_TEMP, KEY_FANSPEED, KEY_SWINGV, KEY_SWINGH, KEY_QUIET, KEY_TURBO, KEY_LIGHT, KEY_BEEP, KEY_ECONO, KEY_SLEEP, KEY_FILTER, KEY_CLEAN, KEY_CELSIUS, KEY_RESEND, + KEY_COMMAND, KEY_SENSORTEMP, KEY_IFEEL KEY_JSON}; // KEY_JSON needs to be the last one. @@ -410,7 +443,8 @@ int8_t getDefaultTxGpio(void); String genStatTopic(const uint16_t channel = 0); String listOfTxGpios(void); bool hasUnsafeHTMLChars(String input); -String htmlHeader(const String title, const String h1_text = ""); +String htmlHeader(const String title, const String h1_text = "", + const String headScriptsJS = ""); String htmlEnd(void); String htmlButton(const String url, const String button, const String text = ""); @@ -418,9 +452,13 @@ String htmlMenu(void); void handleRoot(void); String addJsReloadUrl(const String url, const uint16_t timeout_s, const bool notify); +String getJsToggleCheckbox(const String functionName = TOGGLE_JS_FN_NAME); void handleExamples(void); String htmlOptionItem(const String value, const String text, bool selected); String htmlSelectBool(const String name, const bool def); +String htmlDisableCheckbox(const String name, const String targetControlId, + const bool checked, + const String toggleJsFnName = TOGGLE_JS_FN_NAME); String htmlSelectClimateProtocol(const String name, const decode_type_t def); String htmlSelectAcStateProtocol(const String name, const decode_type_t def, const bool simple); @@ -449,6 +487,9 @@ bool parseStringAndSendPronto(IRsend *irsend, const String str, #if SEND_RAW bool parseStringAndSendRaw(IRsend *irsend, const String str); #endif // SEND_RAW +#if SHT3X_SUPPORT +void sendMQTTDiscoverySensor(const char *topic, String type); +#endif // SH3X_SUPPORT void handleIr(void); void handleNotFound(void); void setup_wifi(void); diff --git a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.ino b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.ino index 4f3324fc2f..e6ca7f493c 100644 --- a/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.ino +++ b/lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.ino @@ -231,6 +231,49 @@ * * In HA's configuration.yaml, add: * + * #### New format (Post Home Assistant 2022.6 release) + * + * mqtt: + * climate: + * - name: Living Room Aircon + * modes: + * - "off" + * - "auto" + * - "cool" + * - "heat" + * - "dry" + * - "fan_only" + * fan_modes: + * - "Auto" + * - "Min" + * - "Low" + * - "Medium" + * - "High" + * - "Max" + * swing_modes: + * - "Off" + * - "Auto" + * - "Highest" + * - "High" + * - "Middle" + * - "Low" + * - "Lowest" + * power_command_topic: "ir_server/ac/cmnd/power" + * mode_command_topic: "ir_server/ac/cmnd/mode" + * mode_state_topic: "ir_server/ac/stat/mode" + * temperature_command_topic: "ir_server/ac/cmnd/temp" + * temperature_state_topic: "ir_server/ac/stat/temp" + * fan_mode_command_topic: "ir_server/ac/cmnd/fanspeed" + * fan_mode_state_topic: "ir_server/ac/stat/fanspeed" + * swing_mode_command_topic: "ir_server/ac/cmnd/swingv" + * swing_mode_state_topic: "ir_server/ac/stat/swingv" + * min_temp: 16 + * max_temp: 32 + * temp_step: 1 + * retain: false + * + * #### Old format (Pre Home Assistant 2022.6 release) + * * climate: * - platform: mqtt * name: Living Room Aircon @@ -256,8 +299,7 @@ * - "Middle" * - "Low" * - "Lowest" - * # `power_command_topic` is probably not needed for most HA configurations - * # power_command_topic: "ir_server/ac/cmnd/power" + * power_command_topic: "ir_server/ac/cmnd/power" * mode_command_topic: "ir_server/ac/cmnd/mode" * mode_state_topic: "ir_server/ac/stat/mode" * temperature_command_topic: "ir_server/ac/cmnd/temp" @@ -377,6 +419,10 @@ using irutils::msToString; ADC_MODE(ADC_VCC); #endif // REPORT_VCC +#ifdef SHT3X_SUPPORT +#include +#endif + // Globals uint8_t _sanity = 0; #if defined(ESP8266) @@ -397,7 +443,7 @@ char Hostname[kHostnameLength + 1] = "ir_server"; // Default hostname. uint16_t *codeArray; uint32_t lastReconnectAttempt = 0; // MQTT last attempt reconnection number bool boot = true; -volatile bool lockIr = false; // Primitive locking for gating the IR LED. +atomic_bool lockIr = false; // Primitive locking for gating the IR LED. uint32_t sendReqCounter = 0; bool lastSendSucceeded = false; // Store the success status of the last send. uint32_t lastSendTime = 0; @@ -453,9 +499,15 @@ String MqttClimateCmnd; // Sub-topic for the climate command topics. #if MQTT_DISCOVERY_ENABLE String MqttDiscovery; String MqttUniqueId; +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE +String MqttDiscoverySensor; +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE #endif // MQTT_DISCOVERY_ENABLE String MqttHAName; String MqttClientId; +#if SHT3X_SUPPORT +String MqttSensorStat; +#endif // SHT3X_SUPPORT // Primative lock file for gating MQTT state broadcasts. bool lockMqttBroadcast = true; @@ -495,6 +547,11 @@ bool isSerialGpioUsedByIr(void) { return false; // Not in use as far as we can tell. } +#if SHT3X_SUPPORT +SHT3X TemperatureSensor(SHT3X_I2C_ADDRESS); +TimerMs statSensorReadTime = TimerMs(); +#endif // SHT3X_SUPPORT + // Debug messages get sent to the serial port. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -905,7 +962,7 @@ void handleExamples(void) { #endif // EXAMPLES_ENABLE String htmlSelectBool(const String name, const bool def) { - String html = F(""); for (uint16_t i = 0; i < 2; i++) html += htmlOptionItem(IRac::boolToString(i), IRac::boolToString(i), i == def); @@ -913,8 +970,20 @@ String htmlSelectBool(const String name, const bool def) { return html; } +String htmlDisableCheckbox(const String name, const String targetControlId, + const bool checked, const String toggleJsFnName) { + String html = String(F("Disabled"); + return html; +} + String htmlSelectClimateProtocol(const String name, const decode_type_t def) { - String html = F(""); for (uint8_t i = 1; i <= decode_type_t::kLastDecodeType; i++) { if (IRac::isProtocolSupported((decode_type_t)i)) { html += htmlOptionItem(String(i), typeToString((decode_type_t)i), @@ -926,7 +995,7 @@ String htmlSelectClimateProtocol(const String name, const decode_type_t def) { } String htmlSelectModel(const String name, const int16_t def) { - String html = F(""); for (int16_t i = -1; i <= 6; i++) { String num = String(i); String text; @@ -942,9 +1011,21 @@ String htmlSelectModel(const String name, const int16_t def) { return html; } +String htmlSelectCommandType(const String name, const stdAc::ac_command_t def) { + String html = String(F(""); + return html; +} + String htmlSelectUint(const String name, const uint16_t max, const uint16_t def) { - String html = F(""); for (uint16_t i = 0; i < max; i++) { String num = String(i); html += htmlOptionItem(num, num, i == def); @@ -955,7 +1036,7 @@ String htmlSelectUint(const String name, const uint16_t max, String htmlSelectGpio(const String name, const int16_t def, const int8_t list[], const int16_t length) { - String html = F(": "); for (int16_t i = 0; i < length; i++) { String num = String(list[i]); html += htmlOptionItem(num, list[i] == kGpioUnused ? F("Unused") : num, @@ -967,7 +1048,7 @@ String htmlSelectGpio(const String name, const int16_t def, } String htmlSelectMode(const String name, const stdAc::opmode_t def) { - String html = F(""); for (int8_t i = -1; i <= (int8_t)stdAc::opmode_t::kLastOpmodeEnum; i++) { String mode = IRac::opmodeToString((stdAc::opmode_t)i); html += htmlOptionItem(mode, mode, (stdAc::opmode_t)i == def); @@ -977,7 +1058,7 @@ String htmlSelectMode(const String name, const stdAc::opmode_t def) { } String htmlSelectFanspeed(const String name, const stdAc::fanspeed_t def) { - String html = F(""); 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); @@ -987,7 +1068,7 @@ String htmlSelectFanspeed(const String name, const stdAc::fanspeed_t def) { } String htmlSelectSwingv(const String name, const stdAc::swingv_t def) { - String html = F(""); for (int8_t i = -1; i <= (int8_t)stdAc::swingv_t::kLastSwingvEnum; i++) { String swing = IRac::swingvToString((stdAc::swingv_t)i); html += htmlOptionItem(swing, swing, (stdAc::swingv_t)i == def); @@ -997,7 +1078,7 @@ String htmlSelectSwingv(const String name, const stdAc::swingv_t def) { } String htmlSelectSwingh(const String name, const stdAc::swingh_t def) { - String html = F(""); 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); @@ -1006,14 +1087,20 @@ String htmlSelectSwingh(const String name, const stdAc::swingh_t def) { return html; } -String htmlHeader(const String title, const String h1_text) { +String htmlHeader(const String title, const String h1_text, + const String headScriptsJS) { String html = F(""); html += title; html += F("" "" - "

"); + "initial-scale=1.0,minimum-scale=1.0,maximum-scale=5.0\">"); + if (headScriptsJS.length()) { + html += F("\n"); + } + html += F("

"); if (h1_text.length()) html += h1_text; else @@ -1036,15 +1123,26 @@ String htmlButton(const String url, const String button, const String text) { return html; } +String getJsToggleCheckbox(const String functionName) { + const String javascript = + String(F(" function ")) + functionName + F("(checkbox, targetInputId) {\n" + " var targetControl = document.getElementById(targetInputId);\n" + " targetControl.disabled = checkbox.checked;\n" + " if (!targetControl.disabled) { targetControl.focus(); }\n" + " }\n"); + return javascript; +} + // Admin web page void handleAirCon(void) { - String html = htmlHeader(F("Air Conditioner Control")); + String html = htmlHeader(F("Air Conditioner Control"), "", + getJsToggleCheckbox()); html += htmlMenu(); if (kNrOfIrTxGpios > 1) { - html += F("
" "" - "" @@ -1053,11 +1151,12 @@ void handleAirCon(void) { "
"); } if (climate[chan] != NULL) { - html += F("

Current Settings

" + bool noSensorTemp = (climate[chan]->next.sensorTemperature == kNoTempValue); + html += String(F("

Current Settings

" "" - "") + + "") + F("
Climate #") + + "
Climate #")) + htmlSelectUint(KEY_CHANNEL, kNrOfIrTxGpios, chan) + F("" "
" "" + "" "" @@ -1084,6 +1186,16 @@ void handleAirCon(void) { (!climate[chan]->next.celsius ? " selected='selected'" : "") + F(">F" "" + "" "" @@ -1096,6 +1208,9 @@ void handleAirCon(void) { "" + "" "" @@ -1190,7 +1305,13 @@ void handleAdmin(void) { #if MQTT_DISCOVERY_ENABLE html += htmlButton( kUrlSendDiscovery, F("Send MQTT Discovery"), - F("Send a Climate MQTT discovery message to Home Assistant.

")); +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE + F("Send a Climate and Sensor MQTT" +#else + F("Send a Climate MQTT" +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE + " discovery message to Home Assistant.

")); + #endif // MQTT_DISCOVERY_ENABLE #if MQTT_CLEAR_ENABLE html += htmlButton( @@ -1244,8 +1365,8 @@ void handleInfo(void) { String html = htmlHeader(F("IR MQTT server info")); html += htmlMenu(); html += - F("

General

" - "

Hostname: ") + String(Hostname) + F("
" + String(F("

General

" + "

Hostname: ")) + String(Hostname) + F("
" "IP address: ") + WiFi.localIP().toString() + F("
" "MAC address: ") + WiFi.macAddress() + F("
" "Booted: ") + timeSince(1) + F("
") + @@ -1392,6 +1513,10 @@ bool clearMqttSavedStates(const String topic_base) { #if MQTT_DISCOVERY_ENABLE // Clear the HA climate discovery message. success &= mqtt_client.publish(MqttDiscovery.c_str(), "", true); +#if SHT3X_SUPPORT && MQTT_DISCOVERY_ENABLE + // Clear the HA sensor discovery message. + success &= mqtt_client.publish(MqttDiscoverySensor.c_str(), "", true); +#endif // SHT3X_SUPPORT && MQTT_DISCOVERY_ENABLE #endif // MQTT_DISCOVERY_ENABLE for (size_t channel = 0; channel <= kNrOfIrTxGpios; @@ -2106,13 +2231,20 @@ void init_vars(void) { MqttClimateCmnd = MqttClimate + '/' + MQTT_CLIMATE_CMND + '/'; // Sub-topic for the climate stat topics. #if MQTT_DISCOVERY_ENABLE - MqttDiscovery = "homeassistant/climate/" + String(Hostname) + "/config"; + MqttDiscovery = "homeassistant/climate/" + String(Hostname); +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE + MqttDiscoverySensor = "homeassistant/sensor/" + String(Hostname); +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE MqttUniqueId = WiFi.macAddress(); MqttUniqueId.replace(":", ""); #endif // MQTT_DISCOVERY_ENABLE MqttHAName = String(Hostname) + "_aircon"; // Create a unique MQTT client id. MqttClientId = String(Hostname) + String(kChipId, HEX); +#if SHT3X_SUPPORT + // Sub-topic for the climate stat topics. + MqttSensorStat = String(MqttPrefix) + '/' + MQTT_SENSOR_STAT + '/'; +#endif // SHT3X_SUPPORT #endif // MQTT_ENABLE } @@ -2418,6 +2550,9 @@ void handleSendMqttDiscovery(void) { htmlMenu() + F("

The Home Assistant MQTT Discovery message is being sent to topic: ") + MqttDiscovery + +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE + F(" and ") + MqttDiscoverySensor + +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE F(". It will show up in Home Assistant in a few seconds." "

" "

Warning!

" @@ -2425,7 +2560,15 @@ void handleSendMqttDiscovery(void) { " is sent.

") + addJsReloadUrl(kUrlRoot, kRebootTime, true) + htmlEnd()); - sendMQTTDiscovery(MqttDiscovery.c_str()); + for (uint16_t i = 0; i < kNrOfIrTxGpios; i++) { + String channel_id = ""; + if (i > 0) channel_id = "_" + String(i); + sendMQTTDiscovery(MqttDiscovery.c_str(), channel_id); + } +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE + sendMQTTDiscoverySensor(MqttDiscoverySensor.c_str(), KEY_TEMP); + sendMQTTDiscoverySensor(MqttDiscoverySensor.c_str(), KEY_HUMIDITY); +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE } #endif // MQTT_DISCOVERY_ENABLE @@ -2598,12 +2741,13 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) { } #if MQTT_DISCOVERY_ENABLE -void sendMQTTDiscovery(const char *topic) { +void sendMQTTDiscovery(const char *topic, String channel_id) { + String pub_topic = String(topic) + channel_id + F("/config"); if (mqtt_client.publish( - topic, String( + pub_topic.c_str(), String( F("{" - "\"~\":\"") + MqttClimate + F("\"," - "\"name\":\"") + MqttHAName + F("\"," + "\"~\":\"") + MqttClimate + channel_id + F("\"," + "\"name\":\"") + MqttHAName + channel_id + F("\"," #if (!MQTT_CLIMATE_HA_MODE) // Typically we don't need or use the power command topic if we are using // our Home Assistant Climate compatiblity mode. It causes odd behaviour @@ -2629,9 +2773,12 @@ void sendMQTTDiscovery(const char *topic) { "\"swing_modes\":[\"" D_STR_OFF "\",\"" D_STR_AUTO "\",\"" D_STR_HIGHEST "\",\"" D_STR_HIGH "\",\"" D_STR_MIDDLE "\",\"" D_STR_LOW "\",\"" D_STR_LOWEST "\"]," - "\"uniq_id\":\"") + MqttUniqueId + F("\"," +#if SHT3X_SUPPORT + "\"curr_temp_t\":\"") + MqttSensorStat + F(KEY_TEMP "\"," +#endif // SHT3X_SUPPORT + "\"uniq_id\":\"") + MqttUniqueId + channel_id + F("\"," "\"device\":{" - "\"identifiers\":[\"") + MqttUniqueId + F("\"]," + "\"identifiers\":[\"") + MqttUniqueId + channel_id + F("\"]," "\"connections\":[[\"mac\",\"") + WiFi.macAddress() + F("\"]]," "\"manufacturer\":\"IRremoteESP8266\"," "\"model\":\"IRMQTTServer\"," @@ -2647,6 +2794,47 @@ void sendMQTTDiscovery(const char *topic) { mqttLog(PSTR("MQTT climate discovery FAILED to send.")); } } + +#if SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE +// Send the MQTT Discovery data for the SHT3X sensor. +// type must be a String of either KEY_TEMP or KEY_HUMIDITY. +void sendMQTTDiscoverySensor(const char *topic, String type) { + String pub_topic = String(topic) + F("_") + type + F("/config"); + String uom = "%"; + String ha_class = type; + // XXX Update units of measure for temperature. + if (type == KEY_TEMP) { + uom = "°C"; + ha_class = "temperature"; + } + if (mqtt_client.publish( + pub_topic.c_str(), String( + F("{" + "\"name\":\"") + MqttHAName + "_" + type + F("\"," + + "\"stat_t\":\"") + MqttSensorStat + type + F("\"," + "\"dev_cla\":\"") + ha_class + F("\"," + "\"unit_of_meas\":\"") + uom + F("\"," + + "\"uniq_id\":\"") + MqttUniqueId + type + F("\"," + "\"device\":{" + "\"identifiers\":[\"") + MqttUniqueId + type + F("\"]," + "\"connections\":[[\"mac\",\"") + WiFi.macAddress() + F("\"]]," + "\"manufacturer\":\"IRremoteESP8266\"," + "\"model\":\"IRMQTTServer\"," + "\"name\":\"") + Hostname + F("\"," + "\"sw_version\":\"" _MY_VERSION_ "\"" + "}" + "}")).c_str(), true)) { + mqttLog(PSTR("MQTT sensor discovery successful sent.")); + hasDiscoveryBeenSent = true; + lastDiscovery.reset(); + mqttSentCounter++; + } else { + mqttLog(PSTR("MQTT sensor discovery FAILED to send.")); + } +} +#endif // SHT3X_SUPPORT && SHT3X_MQTT_DISCOVERY_ENABLE #endif // MQTT_DISCOVERY_ENABLE #endif // MQTT_ENABLE @@ -2678,8 +2866,8 @@ void loop(void) { boot = false; } else { mqttLog(String( - F("IRMQTTServer just (re)connected to MQTT. " - "Lost connection about ") + String(F("IRMQTTServer just (re)connected to MQTT. " + "Lost connection about ")) + timeSince(lastConnectedTime)).c_str()); } lastConnectedTime = now; @@ -2715,6 +2903,29 @@ void loop(void) { } // Periodically send all of the climate state via MQTT. doBroadcast(&lastBroadcast, kBroadcastPeriodMs, climate, false, false); +#if SHT3X_SUPPORT + // Check if it's time to read the SHT3x sensor. + if (statSensorReadTime.elapsed() > SHT3X_CHECK_FREQ * 1000) { + byte result = TemperatureSensor.get(); + if (result == 0) { + // Success + float temp = TemperatureSensor.cTemp; + // XXX Convert units + float humidity = TemperatureSensor.humidity; + // Publish the temp and humidity to MQTT. + String mqttTempTopic = MqttSensorStat + KEY_TEMP; + String mqttHumidityTopic = MqttSensorStat + KEY_HUMIDITY; + mqtt_client.publish(mqttTempTopic.c_str(), String(temp).c_str()); + mqtt_client.publish(mqttHumidityTopic.c_str(), + String(humidity).c_str()); + } else { + // Error + mqttLog((String(F("SHT3x sensor read error: ")) + + String(result)).c_str()); + } + statSensorReadTime.reset(); + } +#endif // SHT3X_SUPPORT } #endif // MQTT_ENABLE #if IR_RX @@ -2934,6 +3145,7 @@ void sendJsonState(const stdAc::state_t state, const String topic, DynamicJsonDocument json(kJsonAcStateMaxSize); json[KEY_PROTOCOL] = typeToString(state.protocol); json[KEY_MODEL] = state.model; + json[KEY_COMMAND] = IRac::commandToString(state.command); json[KEY_POWER] = IRac::boolToString(state.power); json[KEY_MODE] = IRac::opmodeToString(state.mode, ha_mode); // Home Assistant wants mode to be off if power is also off & vice-versa. @@ -2943,10 +3155,12 @@ void sendJsonState(const stdAc::state_t state, const String topic, } json[KEY_CELSIUS] = IRac::boolToString(state.celsius); json[KEY_TEMP] = state.degrees; + json[KEY_SENSORTEMP] = state.sensorTemperature; json[KEY_FANSPEED] = IRac::fanspeedToString(state.fanspeed); json[KEY_SWINGV] = IRac::swingvToString(state.swingv); json[KEY_SWINGH] = IRac::swinghToString(state.swingh); json[KEY_QUIET] = IRac::boolToString(state.quiet); + json[KEY_IFEEL] = IRac::boolToString(state.iFeel); json[KEY_TURBO] = IRac::boolToString(state.turbo); json[KEY_ECONO] = IRac::boolToString(state.econo); json[KEY_LIGHT] = IRac::boolToString(state.light); @@ -2984,6 +3198,10 @@ stdAc::state_t jsonToState(const stdAc::state_t current, const char *str) { result.model = IRac::strToModel(json[KEY_MODEL].as()); else if (validJsonInt(json, KEY_MODEL)) result.model = json[KEY_MODEL]; + if (validJsonStr(json, KEY_COMMAND)) + result.command = IRac::strToCommand(json[KEY_COMMAND].as()); + else if (validJsonInt(json, KEY_COMMAND)) + result.command = json[KEY_COMMAND]; if (validJsonStr(json, KEY_MODE)) result.mode = IRac::strToOpmode(json[KEY_MODE]); if (validJsonStr(json, KEY_FANSPEED)) @@ -2994,10 +3212,14 @@ stdAc::state_t jsonToState(const stdAc::state_t current, const char *str) { result.swingh = IRac::strToSwingH(json[KEY_SWINGH]); if (json.containsKey(KEY_TEMP)) result.degrees = json[KEY_TEMP]; + if (json.containsKey(KEY_SENSORTEMP)) + result.sensorTemperature = json[KEY_SENSORTEMP]; if (validJsonInt(json, KEY_SLEEP)) result.sleep = json[KEY_SLEEP]; if (validJsonStr(json, KEY_POWER)) result.power = IRac::strToBool(json[KEY_POWER]); + if (validJsonStr(json, KEY_IFEEL)) + result.iFeel = IRac::strToBool(json[KEY_IFEEL]); if (validJsonStr(json, KEY_QUIET)) result.quiet = IRac::strToBool(json[KEY_QUIET]); if (validJsonStr(json, KEY_TURBO)) @@ -3029,6 +3251,8 @@ void updateClimate(stdAc::state_t *state, const String str, state->protocol = strToDecodeType(payload.c_str()); } else if (str.equals(prefix + F(KEY_MODEL))) { state->model = IRac::strToModel(payload.c_str()); + } else if (str.equals(prefix + F(KEY_COMMAND))) { + state->command = IRac::strToCommandType(payload.c_str()); } else if (str.equals(prefix + F(KEY_POWER))) { state->power = IRac::strToBool(payload.c_str()); #if MQTT_CLIMATE_HA_MODE @@ -3039,16 +3263,32 @@ void updateClimate(stdAc::state_t *state, const String str, state->mode = IRac::strToOpmode(payload.c_str()); #if MQTT_CLIMATE_HA_MODE // When in Home Assistant mode, a Mode of Off, means turn the Power off too. - if (state->mode == stdAc::opmode_t::kOff) state->power = false; + if (state->mode == stdAc::opmode_t::kOff) { + state->power = false; + } else { + state->power = true; + } #endif // MQTT_CLIMATE_HA_MODE } else if (str.equals(prefix + F(KEY_TEMP))) { state->degrees = payload.toFloat(); + } else if (str.equals(prefix + F(KEY_SENSORTEMP))) { + state->sensorTemperature = payload.toFloat(); + } else if (str.equals(prefix + F(KEY_SENSORTEMP_DISABLED))) { + // The "disabled" html form field appears after the actual sensorTemp field + // and the spec guarantees the form POST field order preserves body order + // => this will always execute after KEY_SENSORTEMP has been parsed already + if (IRac::strToBool(payload.c_str())) { + // UI control was disabled, ignore the value + state->sensorTemperature = kNoTempValue; + } } else if (str.equals(prefix + F(KEY_FANSPEED))) { state->fanspeed = IRac::strToFanspeed(payload.c_str()); } else if (str.equals(prefix + F(KEY_SWINGV))) { state->swingv = IRac::strToSwingV(payload.c_str()); } else if (str.equals(prefix + F(KEY_SWINGH))) { state->swingh = IRac::strToSwingH(payload.c_str()); + } else if (str.equals(prefix + F(KEY_IFEEL))) { + state->iFeel = IRac::strToBool(payload.c_str()); } else if (str.equals(prefix + F(KEY_QUIET))) { state->quiet = IRac::strToBool(payload.c_str()); } else if (str.equals(prefix + F(KEY_TURBO))) { @@ -3086,14 +3326,16 @@ bool sendClimate(const String topic_prefix, const bool retain, diff = true; success &= sendInt(topic_prefix + KEY_MODEL, next.model, retain); } + if (prev.command != next.command || forceMQTT) { + String command_str = IRac::commandTypeToString(next.command); + diff = true; + success &= sendString(topic_prefix + KEY_COMMAND, command_str, retain); + } #ifdef MQTT_CLIMATE_HA_MODE String mode_str = IRac::opmodeToString(next.mode, MQTT_CLIMATE_HA_MODE); #else // MQTT_CLIMATE_HA_MODE String mode_str = IRac::opmodeToString(next.mode); #endif // MQTT_CLIMATE_HA_MODE - // I don't know why, but the modes need to be lower case to work with - // Home Assistant & Google Home. - mode_str.toLowerCase(); #if MQTT_CLIMATE_HA_MODE // Home Assistant want's these two bound together. if (prev.power != next.power || prev.mode != next.mode || forceMQTT) { @@ -3107,6 +3349,10 @@ bool sendClimate(const String topic_prefix, const bool retain, } if (prev.mode != next.mode || forceMQTT) { #endif // MQTT_CLIMATE_HA_MODE + // I don't know why, but the modes need to be lower case to work with + // Home Assistant & Google Home. + mode_str.toLowerCase(); + success &= sendString(topic_prefix + KEY_MODE, mode_str, retain); diff = true; } @@ -3118,6 +3364,11 @@ bool sendClimate(const String topic_prefix, const bool retain, diff = true; success &= sendBool(topic_prefix + KEY_CELSIUS, next.celsius, retain); } + if (prev.sensorTemperature != next.sensorTemperature || forceMQTT) { + diff = true; + success &= sendFloat(topic_prefix + KEY_SENSORTEMP, + next.sensorTemperature, retain); + } if (prev.fanspeed != next.fanspeed || forceMQTT) { diff = true; success &= sendString(topic_prefix + KEY_FANSPEED, @@ -3133,6 +3384,10 @@ bool sendClimate(const String topic_prefix, const bool retain, success &= sendString(topic_prefix + KEY_SWINGH, IRac::swinghToString(next.swingh), retain); } + if (prev.iFeel != next.iFeel || forceMQTT) { + diff = true; + success &= sendBool(topic_prefix + KEY_IFEEL, next.iFeel, retain); + } if (prev.quiet != next.quiet || forceMQTT) { diff = true; success &= sendBool(topic_prefix + KEY_QUIET, next.quiet, retain); diff --git a/lib/IRremoteESP8266/examples/IRMQTTServer/platformio.ini b/lib/IRremoteESP8266/examples/IRMQTTServer/platformio.ini index d0ac2b8c8e..a20250c67c 100644 --- a/lib/IRremoteESP8266/examples/IRMQTTServer/platformio.ini +++ b/lib/IRremoteESP8266/examples/IRMQTTServer/platformio.ini @@ -15,6 +15,8 @@ lib_deps_builtin = lib_deps_external = PubSubClient@>=2.8.0 ArduinoJson@>=6.0 +# Uncomment the following to enable SHT-3x support. +# https://github.com/wemos/WEMOS_SHT3x_Arduino_Library.git [common_esp8266] lib_deps_external = @@ -36,6 +38,14 @@ lib_deps = ${common_esp8266.lib_deps_external} board = d1_mini lib_deps = ${common_esp8266.lib_deps_external} +[env:d1_mini_noMDNS] +board = d1_mini +build_flags = + ${env.build_flags} + -DMQTT_SERVER_AUTODETECT_ENABLE=false + -DMDNS_ENABLE=false +lib_deps = ${common_esp8266.lib_deps_external} + [env:d1_mini_no_mqtt] board = d1_mini build_flags = diff --git a/lib/IRremoteESP8266/examples/IRrecvDumpV2/platformio.ini b/lib/IRremoteESP8266/examples/IRrecvDumpV2/platformio.ini index b56304f66b..eca7c917e9 100644 --- a/lib/IRremoteESP8266/examples/IRrecvDumpV2/platformio.ini +++ b/lib/IRremoteESP8266/examples/IRrecvDumpV2/platformio.ini @@ -64,4 +64,9 @@ build_flags = -D_IR_LOCALE_=zh-CN ; Chinese (Simplified) ; Build the library with all protocols disabled to flush out #if/#ifdef issues & ; any compiler warnings, by turning them into errors. [env:shakedown_no_protocols] -build_flags = -D_IR_ENABLE_DEFAULT_=false -Werror -Wno-error=switch +build_flags = + ${env.build_flags} + -Werror + -Wno-error=switch + -Wno-error=switch-unreachable + -D_IR_ENABLE_DEFAULT_=false diff --git a/lib/IRremoteESP8266/examples/SmartIRRepeater/platformio.ini b/lib/IRremoteESP8266/examples/SmartIRRepeater/platformio.ini index 0db3d6dc86..88a7e8a17d 100644 --- a/lib/IRremoteESP8266/examples/SmartIRRepeater/platformio.ini +++ b/lib/IRremoteESP8266/examples/SmartIRRepeater/platformio.ini @@ -34,4 +34,5 @@ build_flags = ${env.build_flags} -Werror -Wno-error=switch + -Wno-error=switch-unreachable -D_IR_ENABLE_DEFAULT_=false diff --git a/lib/IRremoteESP8266/keywords.txt b/lib/IRremoteESP8266/keywords.txt index bab1f5d5ef..ef944fdb55 100644 --- a/lib/IRremoteESP8266/keywords.txt +++ b/lib/IRremoteESP8266/keywords.txt @@ -20,11 +20,15 @@ # Datatypes & Classes (KEYWORD1) ####################################### +Config KEYWORD1 CoronaSection KEYWORD1 IRAirtonAc KEYWORD1 IRAirwellAc KEYWORD1 IRAmcorAc KEYWORD1 IRArgoAC KEYWORD1 +IRArgoACBase KEYWORD1 +IRArgoAC_WREM3 KEYWORD1 +IRBosch144AC KEYWORD1 IRCarrierAc64 KEYWORD1 IRCoolixAC KEYWORD1 IRCoronaAc KEYWORD1 @@ -43,6 +47,7 @@ IRFujitsuAC KEYWORD1 IRGoodweatherAc KEYWORD1 IRGreeAC KEYWORD1 IRHaierAC KEYWORD1 +IRHaierAC160 KEYWORD1 IRHaierAC176 KEYWORD1 IRHaierACYRW02 KEYWORD1 IRHitachiAc KEYWORD1 @@ -81,11 +86,21 @@ IRTrumaAc KEYWORD1 IRVestelAc KEYWORD1 IRVoltas KEYWORD1 IRWhirlpoolAc KEYWORD1 +IRYorkAc KEYWORD1 IRac KEYWORD1 IRrecv KEYWORD1 IRsend KEYWORD1 IRtimer KEYWORD1 +Timer KEYWORD1 TimerMs KEYWORD1 +ac_command_t KEYWORD1 +argoFan_t KEYWORD1 +argoFlap_t KEYWORD1 +argoIrMessageType_t KEYWORD1 +argoMode_t KEYWORD1 +argoTimerType_t KEYWORD1 +argoWeekday KEYWORD1 +argo_ac_remote_model_t KEYWORD1 decode_results KEYWORD1 decode_type_t KEYWORD1 fanspeed_t KEYWORD1 @@ -114,6 +129,7 @@ whirlpool_ac_remote_model_t KEYWORD1 _backupState KEYWORD2 _cancelOffTimer KEYWORD2 _cancelOnTimer KEYWORD2 +_checksum KEYWORD2 _delayMicroseconds KEYWORD2 _getEconoToggle KEYWORD2 _getOffTimer KEYWORD2 @@ -135,6 +151,7 @@ _setSleepTimer KEYWORD2 _setTemp KEYWORD2 _setTime KEYWORD2 _setTimer KEYWORD2 +_stateReset KEYWORD2 _toString KEYWORD2 _validTolerance KEYWORD2 add KEYWORD2 @@ -150,15 +167,21 @@ addSwingHToString KEYWORD2 addSwingVToString KEYWORD2 addTempFloatToString KEYWORD2 addTempToString KEYWORD2 +addTimerModeToString KEYWORD2 addToggleToString KEYWORD2 adjustRepeat KEYWORD2 airton KEYWORD2 airwell KEYWORD2 amcor KEYWORD2 argo KEYWORD2 +argoWrem3_ACCommand KEYWORD2 +argoWrem3_ConfigSet KEYWORD2 +argoWrem3_SetTimer KEYWORD2 +argoWrem3_iFeelReport KEYWORD2 bcdToUint8 KEYWORD2 begin KEYWORD2 boolToString KEYWORD2 +bosch144 KEYWORD2 buildFromState KEYWORD2 calcBlockChecksum KEYWORD2 calcChecksum KEYWORD2 @@ -175,6 +198,7 @@ cancelOnTimer KEYWORD2 cancelTimers KEYWORD2 carrier64 KEYWORD2 celsiusToFahrenheit KEYWORD2 +channelToString KEYWORD2 checkInvertedBytePairs KEYWORD2 checkSum KEYWORD2 checkZjsSig KEYWORD2 @@ -186,6 +210,7 @@ clearPowerSpecial KEYWORD2 clearSensorTemp KEYWORD2 clearSleepTimerFlag KEYWORD2 cmpStates KEYWORD2 +commandTypeToString KEYWORD2 compare KEYWORD2 convertFan KEYWORD2 convertMode KEYWORD2 @@ -206,18 +231,25 @@ daikin176 KEYWORD2 daikin2 KEYWORD2 daikin216 KEYWORD2 daikin64 KEYWORD2 +dayToString KEYWORD2 +daysBitmaskToString KEYWORD2 decode KEYWORD2 decodeAirton KEYWORD2 decodeAirwell KEYWORD2 decodeAiwaRCT501 KEYWORD2 decodeAmcor KEYWORD2 decodeArgo KEYWORD2 +decodeArgoWREM3 KEYWORD2 decodeArris KEYWORD2 +decodeBosch144 KEYWORD2 decodeBose KEYWORD2 decodeCOOLIX KEYWORD2 decodeCarrierAC KEYWORD2 +decodeCarrierAC128 KEYWORD2 decodeCarrierAC40 KEYWORD2 decodeCarrierAC64 KEYWORD2 +decodeCarrierAC84 KEYWORD2 +decodeClimaButler KEYWORD2 decodeCoolix48 KEYWORD2 decodeCoronaAc KEYWORD2 decodeDISH KEYWORD2 @@ -227,7 +259,9 @@ decodeDaikin152 KEYWORD2 decodeDaikin160 KEYWORD2 decodeDaikin176 KEYWORD2 decodeDaikin2 KEYWORD2 +decodeDaikin200 KEYWORD2 decodeDaikin216 KEYWORD2 +decodeDaikin312 KEYWORD2 decodeDaikin64 KEYWORD2 decodeDelonghiAc KEYWORD2 decodeDenon KEYWORD2 @@ -239,8 +273,10 @@ decodeEpson KEYWORD2 decodeFujitsuAC KEYWORD2 decodeGICable KEYWORD2 decodeGoodweather KEYWORD2 +decodeGorenje KEYWORD2 decodeGree KEYWORD2 decodeHaierAC KEYWORD2 +decodeHaierAC160 KEYWORD2 decodeHaierAC176 KEYWORD2 decodeHaierACYRW02 KEYWORD2 decodeHash KEYWORD2 @@ -287,17 +323,20 @@ decodeSamsung36 KEYWORD2 decodeSamsungAC KEYWORD2 decodeSanyo KEYWORD2 decodeSanyoAc KEYWORD2 +decodeSanyoAc152 KEYWORD2 decodeSanyoAc88 KEYWORD2 decodeSanyoLC7461 KEYWORD2 decodeSharp KEYWORD2 decodeSharpAc KEYWORD2 decodeSony KEYWORD2 decodeSymphony KEYWORD2 +decodeTcl96Ac KEYWORD2 decodeTechnibelAc KEYWORD2 decodeTeco KEYWORD2 decodeTeknopoint KEYWORD2 decodeToState KEYWORD2 decodeToshibaAC KEYWORD2 +decodeToto KEYWORD2 decodeTranscold KEYWORD2 decodeTrotec KEYWORD2 decodeTrotec3550 KEYWORD2 @@ -306,7 +345,9 @@ decodeVestelAc KEYWORD2 decodeVoltas KEYWORD2 decodeWhirlpoolAC KEYWORD2 decodeWhynter KEYWORD2 +decodeWowwee KEYWORD2 decodeXmp KEYWORD2 +decodeYork KEYWORD2 decodeZepeal KEYWORD2 defaultBits KEYWORD2 delonghiac KEYWORD2 @@ -351,6 +392,7 @@ get3D KEYWORD2 get8CHeat KEYWORD2 get8CHeatToggle KEYWORD2 getAbsenseDetect KEYWORD2 +getAuxHeating KEYWORD2 getBeep KEYWORD2 getBit KEYWORD2 getBoost KEYWORD2 @@ -358,6 +400,8 @@ getBreeze KEYWORD2 getBufSize KEYWORD2 getButton KEYWORD2 getCelsius KEYWORD2 +getChannel KEYWORD2 +getChecksum KEYWORD2 getClean KEYWORD2 getCleanToggle KEYWORD2 getClock KEYWORD2 @@ -368,10 +412,13 @@ getCorrectedRawLength KEYWORD2 getCurrTime KEYWORD2 getCurrentDay KEYWORD2 getCurrentTime KEYWORD2 +getCurrentTimeMinutes KEYWORD2 +getDelayTimerMinutes KEYWORD2 getDirectIndirect KEYWORD2 getDisplay KEYWORD2 getDisplayTempSource KEYWORD2 getDryGrade KEYWORD2 +getEco KEYWORD2 getEcocool KEYWORD2 getEcono KEYWORD2 getEconoToggle KEYWORD2 @@ -425,8 +472,10 @@ getPurify KEYWORD2 getQuiet KEYWORD2 getRClevel KEYWORD2 getRaw KEYWORD2 -getRoomTemp KEYWORD2 +getRawByteLength KEYWORD2 getSave KEYWORD2 +getScheduleTimerStartMinutes KEYWORD2 +getScheduleTimerStopMinutes KEYWORD2 getSectionByte KEYWORD2 getSectionChecksum KEYWORD2 getSensor KEYWORD2 @@ -442,6 +491,7 @@ getSpeed KEYWORD2 getStartClock KEYWORD2 getState KEYWORD2 getStateLength KEYWORD2 +getStateLengthForIrMsgType KEYWORD2 getStatePrev KEYWORD2 getStopClock KEYWORD2 getSupercool KEYWORD2 @@ -463,6 +513,7 @@ getTempUnit KEYWORD2 getTempUnits KEYWORD2 getTime KEYWORD2 getTimer KEYWORD2 +getTimerActiveDaysBitmap KEYWORD2 getTimerEnabled KEYWORD2 getTimerMode KEYWORD2 getTimerTime KEYWORD2 @@ -490,6 +541,7 @@ getiFeel KEYWORD2 goodweather KEYWORD2 gree KEYWORD2 haier KEYWORD2 +haier160 KEYWORD2 haier176 KEYWORD2 haierYrwo2 KEYWORD2 handleSpecialState KEYWORD2 @@ -497,6 +549,7 @@ handleToggles KEYWORD2 hasACState KEYWORD2 hasInvertedStates KEYWORD2 hasStateChanged KEYWORD2 +hasValidPreamble KEYWORD2 hitachi KEYWORD2 hitachi1 KEYWORD2 hitachi264 KEYWORD2 @@ -507,10 +560,12 @@ htmlEscape KEYWORD2 initState KEYWORD2 int64ToString KEYWORD2 invertBits KEYWORD2 +irCommandTypeToString KEYWORD2 is8CHeatToggle KEYWORD2 isCleanToggle KEYWORD2 isEconoToggle KEYWORD2 isLightToggle KEYWORD2 +isLongCode KEYWORD2 isOffCommand KEYWORD2 isOffTimerActive KEYWORD2 isOffTimerEnabled KEYWORD2 @@ -531,6 +586,7 @@ isTimeCommand KEYWORD2 isTimerActive KEYWORD2 isTurboToggle KEYWORD2 isValidLgAc KEYWORD2 +isValidWrem3Message KEYWORD2 isVaneSwingV KEYWORD2 kelon KEYWORD2 kelvinator KEYWORD2 @@ -569,6 +625,7 @@ on KEYWORD2 opmodeToString KEYWORD2 panasonic KEYWORD2 panasonic32 KEYWORD2 +pause KEYWORD2 recoverSavedState KEYWORD2 reset KEYWORD2 resultAcToString KEYWORD2 @@ -590,12 +647,17 @@ sendAirwell KEYWORD2 sendAiwaRCT501 KEYWORD2 sendAmcor KEYWORD2 sendArgo KEYWORD2 +sendArgoWREM3 KEYWORD2 sendArris KEYWORD2 +sendBosch144 KEYWORD2 sendBose KEYWORD2 sendCOOLIX KEYWORD2 sendCarrierAC KEYWORD2 +sendCarrierAC128 KEYWORD2 sendCarrierAC40 KEYWORD2 sendCarrierAC64 KEYWORD2 +sendCarrierAC84 KEYWORD2 +sendClimaButler KEYWORD2 sendCoolix48 KEYWORD2 sendCoronaAc KEYWORD2 sendDISH KEYWORD2 @@ -605,7 +667,9 @@ sendDaikin152 KEYWORD2 sendDaikin160 KEYWORD2 sendDaikin176 KEYWORD2 sendDaikin2 KEYWORD2 +sendDaikin200 KEYWORD2 sendDaikin216 KEYWORD2 +sendDaikin312 KEYWORD2 sendDaikin64 KEYWORD2 sendData KEYWORD2 sendDelonghiAc KEYWORD2 @@ -621,8 +685,10 @@ sendGC KEYWORD2 sendGICable KEYWORD2 sendGeneric KEYWORD2 sendGoodweather KEYWORD2 +sendGorenje KEYWORD2 sendGree KEYWORD2 sendHaierAC KEYWORD2 +sendHaierAC160 KEYWORD2 sendHaierAC176 KEYWORD2 sendHaierACYRW02 KEYWORD2 sendHitachiAC KEYWORD2 @@ -680,8 +746,10 @@ sendSAMSUNG KEYWORD2 sendSamsung36 KEYWORD2 sendSamsungAC KEYWORD2 sendSanyoAc KEYWORD2 +sendSanyoAc152 KEYWORD2 sendSanyoAc88 KEYWORD2 sendSanyoLC7461 KEYWORD2 +sendSensorTemp KEYWORD2 sendSharp KEYWORD2 sendSharpAc KEYWORD2 sendSharpRaw KEYWORD2 @@ -690,10 +758,12 @@ sendSony KEYWORD2 sendSony38 KEYWORD2 sendSymphony KEYWORD2 sendTcl112Ac KEYWORD2 +sendTcl96Ac KEYWORD2 sendTechnibelAc KEYWORD2 sendTeco KEYWORD2 sendTeknopoint KEYWORD2 sendToshibaAC KEYWORD2 +sendToto KEYWORD2 sendTranscold KEYWORD2 sendTrotec KEYWORD2 sendTrotec3550 KEYWORD2 @@ -702,7 +772,9 @@ sendVestelAc KEYWORD2 sendVoltas KEYWORD2 sendWhirlpoolAC KEYWORD2 sendWhynter KEYWORD2 +sendWowwee KEYWORD2 sendXmp KEYWORD2 +sendYork KEYWORD2 sendZepeal KEYWORD2 serialPrintUint64 KEYWORD2 set10CHeat KEYWORD2 @@ -711,6 +783,7 @@ set8CHeat KEYWORD2 set8CHeatToggle KEYWORD2 setAbsenseDetect KEYWORD2 setAuto KEYWORD2 +setAuxHeating KEYWORD2 setBeep KEYWORD2 setBit KEYWORD2 setBits KEYWORD2 @@ -718,19 +791,26 @@ setBoost KEYWORD2 setBreeze KEYWORD2 setButton KEYWORD2 setCelsius KEYWORD2 +setChannel KEYWORD2 +setCheckSumS3 KEYWORD2 setClean KEYWORD2 setCleanToggle KEYWORD2 setClock KEYWORD2 setCmd KEYWORD2 setComfort KEYWORD2 setCommand KEYWORD2 +setConfigEntry KEYWORD2 setCurrTime KEYWORD2 setCurrentDay KEYWORD2 +setCurrentDayOfWeek KEYWORD2 setCurrentTime KEYWORD2 +setCurrentTimeMinutes KEYWORD2 +setDelayTimerMinutes KEYWORD2 setDirectIndirect KEYWORD2 setDisplay KEYWORD2 setDisplayTempSource KEYWORD2 setDryGrade KEYWORD2 +setEco KEYWORD2 setEcocool KEYWORD2 setEcono KEYWORD2 setEconoToggle KEYWORD2 @@ -753,6 +833,7 @@ setIFeel KEYWORD2 setISave10C KEYWORD2 setISee KEYWORD2 setId KEYWORD2 +setInvertBytes KEYWORD2 setInvertedStates KEYWORD2 setIon KEYWORD2 setIonFilter KEYWORD2 @@ -761,6 +842,7 @@ setLight KEYWORD2 setLightToggle KEYWORD2 setLock KEYWORD2 setMax KEYWORD2 +setMessageType KEYWORD2 setMode KEYWORD2 setModel KEYWORD2 setMold KEYWORD2 @@ -784,8 +866,10 @@ setPowerful KEYWORD2 setPurify KEYWORD2 setQuiet KEYWORD2 setRaw KEYWORD2 -setRoomTemp KEYWORD2 setSave KEYWORD2 +setScheduleTimerActiveDays KEYWORD2 +setScheduleTimerStartMinutes KEYWORD2 +setScheduleTimerStopMinutes KEYWORD2 setSensor KEYWORD2 setSensorTemp KEYWORD2 setSensorTempRaw KEYWORD2 @@ -888,6 +972,7 @@ xorBytes KEYWORD2 A705 LITERAL1 A903 LITERAL1 A907 LITERAL1 +AC_CONTROL LITERAL1 AIRTON LITERAL1 AIRWELL LITERAL1 AIWA_RC_T501 LITERAL1 @@ -927,11 +1012,18 @@ ARREB1E LITERAL1 ARREW4E LITERAL1 ARRIS LITERAL1 ARRY4 LITERAL1 +AUTO LITERAL1 +BOSCH144 LITERAL1 BOSE LITERAL1 CARRIER_AC LITERAL1 +CARRIER_AC128 LITERAL1 CARRIER_AC40 LITERAL1 CARRIER_AC64 LITERAL1 +CARRIER_AC84 LITERAL1 CARRIER_AC_BITS LITERAL1 +CLIMABUTLER LITERAL1 +CONFIG_PARAM_SET LITERAL1 +COOL LITERAL1 COOLIX LITERAL1 COOLIX48 LITERAL1 COOLIX_BITS LITERAL1 @@ -942,7 +1034,9 @@ DAIKIN152 LITERAL1 DAIKIN160 LITERAL1 DAIKIN176 LITERAL1 DAIKIN2 LITERAL1 +DAIKIN200 LITERAL1 DAIKIN216 LITERAL1 +DAIKIN312 LITERAL1 DAIKIN64 LITERAL1 DAIKIN_AUTO LITERAL1 DAIKIN_COMMAND_LENGTH LITERAL1 @@ -963,10 +1057,14 @@ DECODE_AIWA_RC_T501 LITERAL1 DECODE_AMCOR LITERAL1 DECODE_ARGO LITERAL1 DECODE_ARRIS LITERAL1 +DECODE_BOSCH144 LITERAL1 DECODE_BOSE LITERAL1 DECODE_CARRIER_AC LITERAL1 +DECODE_CARRIER_AC128 LITERAL1 DECODE_CARRIER_AC40 LITERAL1 DECODE_CARRIER_AC64 LITERAL1 +DECODE_CARRIER_AC84 LITERAL1 +DECODE_CLIMABUTLER LITERAL1 DECODE_COOLIX LITERAL1 DECODE_COOLIX48 LITERAL1 DECODE_CORONA_AC LITERAL1 @@ -976,7 +1074,9 @@ DECODE_DAIKIN152 LITERAL1 DECODE_DAIKIN160 LITERAL1 DECODE_DAIKIN176 LITERAL1 DECODE_DAIKIN2 LITERAL1 +DECODE_DAIKIN200 LITERAL1 DECODE_DAIKIN216 LITERAL1 +DECODE_DAIKIN312 LITERAL1 DECODE_DAIKIN64 LITERAL1 DECODE_DELONGHI_AC LITERAL1 DECODE_DENON LITERAL1 @@ -990,8 +1090,10 @@ DECODE_FUJITSU_AC LITERAL1 DECODE_GICABLE LITERAL1 DECODE_GLOBALCACHE LITERAL1 DECODE_GOODWEATHER LITERAL1 +DECODE_GORENJE LITERAL1 DECODE_GREE LITERAL1 DECODE_HAIER_AC LITERAL1 +DECODE_HAIER_AC160 LITERAL1 DECODE_HAIER_AC176 LITERAL1 DECODE_HAIER_AC_YRW02 LITERAL1 DECODE_HASH LITERAL1 @@ -1043,6 +1145,7 @@ DECODE_SAMSUNG36 LITERAL1 DECODE_SAMSUNG_AC LITERAL1 DECODE_SANYO LITERAL1 DECODE_SANYO_AC LITERAL1 +DECODE_SANYO_AC152 LITERAL1 DECODE_SANYO_AC88 LITERAL1 DECODE_SHARP LITERAL1 DECODE_SHARP_AC LITERAL1 @@ -1050,10 +1153,12 @@ DECODE_SHERWOOD LITERAL1 DECODE_SONY LITERAL1 DECODE_SYMPHONY LITERAL1 DECODE_TCL112AC LITERAL1 +DECODE_TCL96AC LITERAL1 DECODE_TECHNIBEL_AC LITERAL1 DECODE_TECO LITERAL1 DECODE_TEKNOPOINT LITERAL1 DECODE_TOSHIBA_AC LITERAL1 +DECODE_TOTO LITERAL1 DECODE_TRANSCOLD LITERAL1 DECODE_TROTEC LITERAL1 DECODE_TROTEC_3550 LITERAL1 @@ -1062,8 +1167,11 @@ DECODE_VESTEL_AC LITERAL1 DECODE_VOLTAS LITERAL1 DECODE_WHIRLPOOL_AC LITERAL1 DECODE_WHYNTER LITERAL1 +DECODE_WOWWEE LITERAL1 DECODE_XMP LITERAL1 +DECODE_YORK LITERAL1 DECODE_ZEPEAL LITERAL1 +DELAY_TIMER LITERAL1 DELONGHI_AC LITERAL1 DENON LITERAL1 DENON_48_BITS LITERAL1 @@ -1074,11 +1182,29 @@ DG11J191 LITERAL1 DISH LITERAL1 DISH_BITS LITERAL1 DOSHISHA LITERAL1 +DRY LITERAL1 ECOCLIM LITERAL1 ELECTRA_AC LITERAL1 ELITESCREENS LITERAL1 ENABLE_NOISE_FILTER_OPTION LITERAL1 EPSON LITERAL1 +FAN LITERAL1 +FAN_AUTO LITERAL1 +FAN_HIGH LITERAL1 +FAN_HIGHEST LITERAL1 +FAN_LOW LITERAL1 +FAN_LOWER LITERAL1 +FAN_LOWEST LITERAL1 +FAN_MEDIUM LITERAL1 +FLAP_1 LITERAL1 +FLAP_2 LITERAL1 +FLAP_3 LITERAL1 +FLAP_4 LITERAL1 +FLAP_5 LITERAL1 +FLAP_6 LITERAL1 +FLAP_AUTO LITERAL1 +FLAP_FULL LITERAL1 +FRIDAY LITERAL1 FUJITSU_AC LITERAL1 FUJITSU_AC_BITS LITERAL1 FUJITSU_AC_CMD_STAY_ON LITERAL1 @@ -1111,6 +1237,7 @@ GICABLE LITERAL1 GICABLE_BITS LITERAL1 GLOBALCACHE LITERAL1 GOODWEATHER LITERAL1 +GORENJE LITERAL1 GREE LITERAL1 GREE_AUTO LITERAL1 GREE_COOL LITERAL1 @@ -1133,6 +1260,7 @@ GREE_SWING_UP LITERAL1 GREE_SWING_UP_AUTO LITERAL1 GZ055BE1 LITERAL1 HAIER_AC LITERAL1 +HAIER_AC160 LITERAL1 HAIER_AC176 LITERAL1 HAIER_AC_AUTO LITERAL1 HAIER_AC_CMD_FAN LITERAL1 @@ -1189,6 +1317,7 @@ HAIER_AC_YRW02_SWING_MIDDLE LITERAL1 HAIER_AC_YRW02_SWING_OFF LITERAL1 HAIER_AC_YRW02_SWING_TOP LITERAL1 HAIER_AC_YRW02_TURBO_OFF LITERAL1 +HEAT LITERAL1 HIGH LITERAL1 HITACHI_AC LITERAL1 HITACHI_AC1 LITERAL1 @@ -1206,7 +1335,7 @@ HITACHI_AC344 LITERAL1 HITACHI_AC424 LITERAL1 HITACHI_AC_BITS LITERAL1 HITACHI_AC_STATE_LENGTH LITERAL1 -ICACHE_RAM_ATTR LITERAL1 +IFEEL_TEMP_REPORT LITERAL1 INAX LITERAL1 JVC LITERAL1 JVC_BITS LITERAL1 @@ -1281,6 +1410,7 @@ MITSUBISHI_AC_VANE_AUTO_MOVE LITERAL1 MITSUBISHI_BITS LITERAL1 MITSUBISHI_HEAVY_152 LITERAL1 MITSUBISHI_HEAVY_88 LITERAL1 +MONDAY LITERAL1 MULTIBRACKETS LITERAL1 MWM LITERAL1 NEC LITERAL1 @@ -1289,6 +1419,8 @@ NEC_LIKE LITERAL1 NEOCLIMA LITERAL1 NIKAI LITERAL1 NIKAI_BITS LITERAL1 +NOTHING LITERAL1 +NO_TIMER LITERAL1 ONCE LITERAL1 PANASONIC LITERAL1 PANASONIC_AC LITERAL1 @@ -1311,26 +1443,37 @@ RCMM_BITS LITERAL1 RHOSS LITERAL1 R_LT0541_HTA_A LITERAL1 R_LT0541_HTA_B LITERAL1 +SAC_WREM2 LITERAL1 +SAC_WREM3 LITERAL1 SAMSUNG LITERAL1 SAMSUNG36 LITERAL1 SAMSUNG_AC LITERAL1 SAMSUNG_BITS LITERAL1 SANYO LITERAL1 SANYO_AC LITERAL1 +SANYO_AC152 LITERAL1 SANYO_AC88 LITERAL1 SANYO_LC7461 LITERAL1 SANYO_LC7461_BITS LITERAL1 SANYO_SA8650B_BITS LITERAL1 +SATURDAY LITERAL1 +SCHEDULE_TIMER_1 LITERAL1 +SCHEDULE_TIMER_2 LITERAL1 +SCHEDULE_TIMER_3 LITERAL1 SEND_AIRTON LITERAL1 SEND_AIRWELL LITERAL1 SEND_AIWA_RC_T501 LITERAL1 SEND_AMCOR LITERAL1 SEND_ARGO LITERAL1 SEND_ARRIS LITERAL1 +SEND_BOSCH144 LITERAL1 SEND_BOSE LITERAL1 SEND_CARRIER_AC LITERAL1 +SEND_CARRIER_AC128 LITERAL1 SEND_CARRIER_AC40 LITERAL1 SEND_CARRIER_AC64 LITERAL1 +SEND_CARRIER_AC84 LITERAL1 +SEND_CLIMABUTLER LITERAL1 SEND_COOLIX LITERAL1 SEND_COOLIX48 LITERAL1 SEND_CORONA_AC LITERAL1 @@ -1340,7 +1483,9 @@ SEND_DAIKIN152 LITERAL1 SEND_DAIKIN160 LITERAL1 SEND_DAIKIN176 LITERAL1 SEND_DAIKIN2 LITERAL1 +SEND_DAIKIN200 LITERAL1 SEND_DAIKIN216 LITERAL1 +SEND_DAIKIN312 LITERAL1 SEND_DAIKIN64 LITERAL1 SEND_DELONGHI_AC LITERAL1 SEND_DENON LITERAL1 @@ -1354,8 +1499,10 @@ SEND_FUJITSU_AC LITERAL1 SEND_GICABLE LITERAL1 SEND_GLOBALCACHE LITERAL1 SEND_GOODWEATHER LITERAL1 +SEND_GORENJE LITERAL1 SEND_GREE LITERAL1 SEND_HAIER_AC LITERAL1 +SEND_HAIER_AC160 LITERAL1 SEND_HAIER_AC176 LITERAL1 SEND_HAIER_AC_YRW02 LITERAL1 SEND_HITACHI_AC LITERAL1 @@ -1407,6 +1554,7 @@ SEND_SAMSUNG36 LITERAL1 SEND_SAMSUNG_AC LITERAL1 SEND_SANYO LITERAL1 SEND_SANYO_AC LITERAL1 +SEND_SANYO_AC152 LITERAL1 SEND_SANYO_AC88 LITERAL1 SEND_SHARP LITERAL1 SEND_SHARP_AC LITERAL1 @@ -1414,10 +1562,12 @@ SEND_SHERWOOD LITERAL1 SEND_SONY LITERAL1 SEND_SYMPHONY LITERAL1 SEND_TCL112AC LITERAL1 +SEND_TCL96AC LITERAL1 SEND_TECHNIBEL_AC LITERAL1 SEND_TECO LITERAL1 SEND_TEKNOPOINT LITERAL1 SEND_TOSHIBA_AC LITERAL1 +SEND_TOTO LITERAL1 SEND_TRANSCOLD LITERAL1 SEND_TROTEC LITERAL1 SEND_TROTEC_3550 LITERAL1 @@ -1426,7 +1576,9 @@ SEND_VESTEL_AC LITERAL1 SEND_VOLTAS LITERAL1 SEND_WHIRLPOOL_AC LITERAL1 SEND_WHYNTER LITERAL1 +SEND_WOWWEE LITERAL1 SEND_XMP LITERAL1 +SEND_YORK LITERAL1 SEND_ZEPEAL LITERAL1 SHARP LITERAL1 SHARP_AC LITERAL1 @@ -1438,13 +1590,17 @@ SONY_12_BITS LITERAL1 SONY_15_BITS LITERAL1 SONY_20_BITS LITERAL1 SONY_38K LITERAL1 +SUNDAY LITERAL1 SYMPHONY LITERAL1 TAC09CHSD LITERAL1 TCL112AC LITERAL1 +TCL96AC LITERAL1 TECHNIBEL_AC LITERAL1 TECO LITERAL1 TEKNOPOINT LITERAL1 +THURSDAY LITERAL1 TIMEOUT_MS LITERAL1 +TIMER_COMMAND LITERAL1 TOSHIBA_AC LITERAL1 TOSHIBA_AC_AUTO LITERAL1 TOSHIBA_AC_COOL LITERAL1 @@ -1456,6 +1612,7 @@ TOSHIBA_AC_MAX_TEMP LITERAL1 TOSHIBA_AC_MIN_TEMP LITERAL1 TOSHIBA_AC_POWER LITERAL1 TOSHIBA_AC_STATE_LENGTH LITERAL1 +TOTO LITERAL1 TRANSCOLD LITERAL1 TROTEC LITERAL1 TROTEC_3550 LITERAL1 @@ -1471,6 +1628,7 @@ TROTEC_MAX_TEMP LITERAL1 TROTEC_MAX_TIMER LITERAL1 TROTEC_MIN_TEMP LITERAL1 TRUMA LITERAL1 +TUESDAY LITERAL1 UNKNOWN LITERAL1 UNUSED LITERAL1 USE_IRAM_ATTR LITERAL1 @@ -1478,12 +1636,16 @@ V9014557_A LITERAL1 V9014557_B LITERAL1 VESTEL_AC LITERAL1 VOLTAS LITERAL1 +WEDNESDAY LITERAL1 WHIRLPOOL_AC LITERAL1 WHYNTER LITERAL1 WHYNTER_BITS LITERAL1 +WOWWEE LITERAL1 XMP LITERAL1 YAW1F LITERAL1 YBOFB LITERAL1 +YORK LITERAL1 +YX1FSF LITERAL1 ZEPEAL LITERAL1 k0Str LITERAL1 k10CHeatStr LITERAL1 @@ -1591,6 +1753,10 @@ kAmcorVentOn LITERAL1 kAmcorZeroMark LITERAL1 kAmcorZeroSpace LITERAL1 kArdb1Str LITERAL1 +kArgo3AcControlStateLength LITERAL1 +kArgo3ConfigStateLength LITERAL1 +kArgo3TimerStateLength LITERAL1 +kArgo3iFeelReportStateLength LITERAL1 kArgoAuto LITERAL1 kArgoBitMark LITERAL1 kArgoBits LITERAL1 @@ -1609,6 +1775,7 @@ kArgoFlap5 LITERAL1 kArgoFlap6 LITERAL1 kArgoFlapAuto LITERAL1 kArgoFlapFull LITERAL1 +kArgoFrequency LITERAL1 kArgoGap LITERAL1 kArgoHdrMark LITERAL1 kArgoHdrSpace LITERAL1 @@ -1616,13 +1783,26 @@ kArgoHeat LITERAL1 kArgoHeatAuto LITERAL1 kArgoHeatBit LITERAL1 kArgoHeatBlink LITERAL1 +kArgoMaxChannel LITERAL1 kArgoMaxRoomTemp LITERAL1 kArgoMaxTemp LITERAL1 kArgoMinTemp LITERAL1 kArgoOff LITERAL1 kArgoOneSpace LITERAL1 +kArgoPost LITERAL1 +kArgoPreamble1 LITERAL1 +kArgoPreamble2 LITERAL1 +kArgoSensorCheck LITERAL1 +kArgoSensorFixed LITERAL1 +kArgoShortBits LITERAL1 +kArgoShortStateLength LITERAL1 kArgoStateLength LITERAL1 kArgoTempDelta LITERAL1 +kArgoWrem2Str LITERAL1 +kArgoWrem3Postfix_ACControl LITERAL1 +kArgoWrem3Postfix_Timer LITERAL1 +kArgoWrem3Preamble LITERAL1 +kArgoWrem3Str LITERAL1 kArgoZeroSpace LITERAL1 kArjw2Str LITERAL1 kArrah2eStr LITERAL1 @@ -1644,6 +1824,35 @@ kAutoStr LITERAL1 kAutomaticStr LITERAL1 kBeepStr LITERAL1 kBitsStr LITERAL1 +kBosch144Auto LITERAL1 +kBosch144Bits LITERAL1 +kBosch144BytesPerSection LITERAL1 +kBosch144Cool LITERAL1 +kBosch144DefaultState LITERAL1 +kBosch144Dry LITERAL1 +kBosch144Fan LITERAL1 +kBosch144Fan100 LITERAL1 +kBosch144Fan20 LITERAL1 +kBosch144Fan40 LITERAL1 +kBosch144Fan60 LITERAL1 +kBosch144Fan80 LITERAL1 +kBosch144FanAuto LITERAL1 +kBosch144FanAuto0 LITERAL1 +kBosch144Heat LITERAL1 +kBosch144NrOfSections LITERAL1 +kBosch144Off LITERAL1 +kBosch144StateLength LITERAL1 +kBosch144TempMap LITERAL1 +kBosch144TempMax LITERAL1 +kBosch144TempMin LITERAL1 +kBosch144TempRange LITERAL1 +kBoschBitMark LITERAL1 +kBoschFooterSpace LITERAL1 +kBoschFreq LITERAL1 +kBoschHdrMark LITERAL1 +kBoschHdrSpace LITERAL1 +kBoschOneSpace LITERAL1 +kBoschZeroSpace LITERAL1 kBoseBitMark LITERAL1 kBoseBits LITERAL1 kBoseFreq LITERAL1 @@ -1656,6 +1865,19 @@ kBottomStr LITERAL1 kBreezeStr LITERAL1 kButtonStr LITERAL1 kCancelStr LITERAL1 +kCarrierAc128BitMark LITERAL1 +kCarrierAc128Bits LITERAL1 +kCarrierAc128Hdr2Mark LITERAL1 +kCarrierAc128Hdr2Space LITERAL1 +kCarrierAc128HdrMark LITERAL1 +kCarrierAc128HdrSpace LITERAL1 +kCarrierAc128InterSpace LITERAL1 +kCarrierAc128MinRepeat LITERAL1 +kCarrierAc128OneSpace LITERAL1 +kCarrierAc128SectionBits LITERAL1 +kCarrierAc128SectionGap LITERAL1 +kCarrierAc128StateLength LITERAL1 +kCarrierAc128ZeroSpace LITERAL1 kCarrierAc40BitMark LITERAL1 kCarrierAc40Bits LITERAL1 kCarrierAc40Gap LITERAL1 @@ -1685,6 +1907,16 @@ kCarrierAc64OneSpace LITERAL1 kCarrierAc64TimerMax LITERAL1 kCarrierAc64TimerMin LITERAL1 kCarrierAc64ZeroSpace LITERAL1 +kCarrierAc84Bits LITERAL1 +kCarrierAc84ExtraBits LITERAL1 +kCarrierAc84ExtraTolerance LITERAL1 +kCarrierAc84Gap LITERAL1 +kCarrierAc84HdrMark LITERAL1 +kCarrierAc84HdrSpace LITERAL1 +kCarrierAc84MinRepeat LITERAL1 +kCarrierAc84One LITERAL1 +kCarrierAc84StateLength LITERAL1 +kCarrierAc84Zero LITERAL1 kCarrierAcBitMark LITERAL1 kCarrierAcBits LITERAL1 kCarrierAcFreq LITERAL1 @@ -1698,16 +1930,29 @@ kCeilingStr LITERAL1 kCelsiusFahrenheitStr LITERAL1 kCelsiusStr LITERAL1 kCentreStr LITERAL1 +kChStr LITERAL1 kChangeStr LITERAL1 kCirculateStr LITERAL1 kCkpStr LITERAL1 kCleanStr LITERAL1 +kClimaButlerBitMark LITERAL1 +kClimaButlerBits LITERAL1 +kClimaButlerFreq LITERAL1 +kClimaButlerGap LITERAL1 +kClimaButlerHdrMark LITERAL1 +kClimaButlerHdrSpace LITERAL1 +kClimaButlerOneSpace LITERAL1 +kClimaButlerZeroSpace LITERAL1 kClockStr LITERAL1 kCodeStr LITERAL1 kColonSpaceStr LITERAL1 kComfortStr LITERAL1 kCommaSpaceStr LITERAL1 kCommandStr LITERAL1 +kConfigCommand LITERAL1 +kConfigCommandStr LITERAL1 +kControlCommand LITERAL1 +kControlCommandStr LITERAL1 kCool LITERAL1 kCoolStr LITERAL1 kCoolingStr LITERAL1 @@ -1880,6 +2125,19 @@ kDaikin176StateLength LITERAL1 kDaikin176SwingHAuto LITERAL1 kDaikin176SwingHOff LITERAL1 kDaikin176ZeroSpace LITERAL1 +kDaikin200BitMark LITERAL1 +kDaikin200Bits LITERAL1 +kDaikin200DefaultRepeat LITERAL1 +kDaikin200Freq LITERAL1 +kDaikin200Gap LITERAL1 +kDaikin200HdrMark LITERAL1 +kDaikin200HdrSpace LITERAL1 +kDaikin200OneSpace LITERAL1 +kDaikin200Section1Length LITERAL1 +kDaikin200Section2Length LITERAL1 +kDaikin200Sections LITERAL1 +kDaikin200StateLength LITERAL1 +kDaikin200ZeroSpace LITERAL1 kDaikin216BitMark LITERAL1 kDaikin216Bits LITERAL1 kDaikin216DefaultRepeat LITERAL1 @@ -1940,6 +2198,19 @@ kDaikin2SwingVSwing LITERAL1 kDaikin2SwingVUpperMiddle LITERAL1 kDaikin2Tolerance LITERAL1 kDaikin2ZeroSpace LITERAL1 +kDaikin312BitMark LITERAL1 +kDaikin312Bits LITERAL1 +kDaikin312DefaultRepeat LITERAL1 +kDaikin312HdrGap LITERAL1 +kDaikin312HdrMark LITERAL1 +kDaikin312HdrSpace LITERAL1 +kDaikin312OneSpace LITERAL1 +kDaikin312Section1Length LITERAL1 +kDaikin312Section2Length LITERAL1 +kDaikin312SectionGap LITERAL1 +kDaikin312Sections LITERAL1 +kDaikin312StateLength LITERAL1 +kDaikin312ZeroSpace LITERAL1 kDaikin64BitMark LITERAL1 kDaikin64Bits LITERAL1 kDaikin64ChecksumOffset LITERAL1 @@ -2202,6 +2473,8 @@ kFujitsuAcMaxTemp LITERAL1 kFujitsuAcMaxTempF LITERAL1 kFujitsuAcMinBits LITERAL1 kFujitsuAcMinGap LITERAL1 +kFujitsuAcMinHeat LITERAL1 +kFujitsuAcMinHeatF LITERAL1 kFujitsuAcMinRepeat LITERAL1 kFujitsuAcMinTemp LITERAL1 kFujitsuAcMinTempF LITERAL1 @@ -2277,6 +2550,15 @@ kGoodweatherSwingSlow LITERAL1 kGoodweatherTempMax LITERAL1 kGoodweatherTempMin LITERAL1 kGoodweatherZeroSpace LITERAL1 +kGorenjeBitMark LITERAL1 +kGorenjeBits LITERAL1 +kGorenjeFreq LITERAL1 +kGorenjeHdrMark LITERAL1 +kGorenjeHdrSpace LITERAL1 +kGorenjeMinGap LITERAL1 +kGorenjeOneSpace LITERAL1 +kGorenjeTolerance LITERAL1 +kGorenjeZeroSpace LITERAL1 kGpioUnused LITERAL1 kGreeAuto LITERAL1 kGreeBitMark LITERAL1 @@ -2290,6 +2572,7 @@ kGreeDisplayTempOff LITERAL1 kGreeDisplayTempOutside LITERAL1 kGreeDisplayTempSet LITERAL1 kGreeDry LITERAL1 +kGreeEcono LITERAL1 kGreeFan LITERAL1 kGreeFanAuto LITERAL1 kGreeFanMax LITERAL1 @@ -2325,12 +2608,27 @@ kGreeSwingUpAuto LITERAL1 kGreeTimerMax LITERAL1 kGreeZeroSpace LITERAL1 kGz055be1Str LITERAL1 +kHaierAC160Bits LITERAL1 +kHaierAC160StateLength LITERAL1 kHaierAC176Bits LITERAL1 kHaierAC176StateLength LITERAL1 kHaierACBits LITERAL1 kHaierACStateLength LITERAL1 kHaierACYRW02Bits LITERAL1 kHaierACYRW02StateLength LITERAL1 +kHaierAc160ButtonAuxHeating LITERAL1 +kHaierAc160ButtonClean LITERAL1 +kHaierAc160ButtonLight LITERAL1 +kHaierAc160DefaultRepeat LITERAL1 +kHaierAc160Prefix LITERAL1 +kHaierAc160SwingVAuto LITERAL1 +kHaierAc160SwingVHigh LITERAL1 +kHaierAc160SwingVHighest LITERAL1 +kHaierAc160SwingVLow LITERAL1 +kHaierAc160SwingVLowest LITERAL1 +kHaierAc160SwingVMiddle LITERAL1 +kHaierAc160SwingVOff LITERAL1 +kHaierAc160SwingVTop LITERAL1 kHaierAc176DefaultRepeat LITERAL1 kHaierAc176Prefix LITERAL1 kHaierAcAuto LITERAL1 @@ -2583,6 +2881,7 @@ kHoldStr LITERAL1 kHourStr LITERAL1 kHoursStr LITERAL1 kHumidStr LITERAL1 +kIFeelReportStr LITERAL1 kIFeelStr LITERAL1 kISeeStr LITERAL1 kIdStr LITERAL1 @@ -2684,6 +2983,7 @@ kKelvinatorSwingVUpperMiddle LITERAL1 kKelvinatorTick LITERAL1 kKelvinatorZeroSpace LITERAL1 kKelvinatorZeroSpaceTicks LITERAL1 +kKeyStr LITERAL1 kKkg29ac1Str LITERAL1 kKkg9ac1Str LITERAL1 kLasertagBits LITERAL1 @@ -2694,6 +2994,7 @@ kLasertagMinRepeat LITERAL1 kLasertagMinSamples LITERAL1 kLasertagTick LITERAL1 kLasertagTolerance LITERAL1 +kLastAcCommandEnum LITERAL1 kLastDecodeType LITERAL1 kLastFanspeedEnum LITERAL1 kLastOpmodeEnum LITERAL1 @@ -2831,8 +3132,10 @@ kMaxRightStr LITERAL1 kMaxStr LITERAL1 kMaxTimeoutMs LITERAL1 kMaximumStr LITERAL1 +kMedHighStr LITERAL1 kMedStr LITERAL1 kMedium LITERAL1 +kMediumHigh LITERAL1 kMediumStr LITERAL1 kMetzAddressBits LITERAL1 kMetzBitMark LITERAL1 @@ -3240,6 +3543,7 @@ kNikaiZeroSpaceTicks LITERAL1 kNkeStr LITERAL1 kNoRepeat LITERAL1 kNoStr LITERAL1 +kNoTempValue LITERAL1 kNowStr LITERAL1 kOff LITERAL1 kOffStr LITERAL1 @@ -3248,6 +3552,8 @@ kOnStr LITERAL1 kOnTimerStr LITERAL1 kOutsideQuietStr LITERAL1 kOutsideStr LITERAL1 +kPanasonic40Bits LITERAL1 +kPanasonic40Manufacturer LITERAL1 kPanasonicAc32Auto LITERAL1 kPanasonicAc32BitMark LITERAL1 kPanasonicAc32Bits LITERAL1 @@ -3538,6 +3844,16 @@ kSamsungRptSpaceTicks LITERAL1 kSamsungTick LITERAL1 kSamsungZeroSpace LITERAL1 kSamsungZeroSpaceTicks LITERAL1 +kSanyoAc152BitMark LITERAL1 +kSanyoAc152Bits LITERAL1 +kSanyoAc152ExtraTolerance LITERAL1 +kSanyoAc152Freq LITERAL1 +kSanyoAc152HdrMark LITERAL1 +kSanyoAc152HdrSpace LITERAL1 +kSanyoAc152MinRepeat LITERAL1 +kSanyoAc152OneSpace LITERAL1 +kSanyoAc152StateLength LITERAL1 +kSanyoAc152ZeroSpace LITERAL1 kSanyoAc88Auto LITERAL1 kSanyoAc88BitMark LITERAL1 kSanyoAc88Bits LITERAL1 @@ -3611,11 +3927,14 @@ kSanyoSa8650bOneMark LITERAL1 kSanyoSa8650bRptLength LITERAL1 kSanyoSa8650bZeroMark LITERAL1 kSaveStr LITERAL1 +kScheduleStr LITERAL1 kSecondStr LITERAL1 kSecondsStr LITERAL1 kSensorStr LITERAL1 +kSensorTempReport LITERAL1 kSensorTempStr LITERAL1 kSetStr LITERAL1 +kSetTimerCommandStr LITERAL1 kSharpAcAuto LITERAL1 kSharpAcBitMark LITERAL1 kSharpAcBits LITERAL1 @@ -3770,6 +4089,15 @@ kTcl112AcTimerMax LITERAL1 kTcl112AcTimerResolution LITERAL1 kTcl112AcTolerance LITERAL1 kTcl112AcZeroSpace LITERAL1 +kTcl96AcBitMark LITERAL1 +kTcl96AcBitSpaces LITERAL1 +kTcl96AcBits LITERAL1 +kTcl96AcDefaultRepeat LITERAL1 +kTcl96AcGap LITERAL1 +kTcl96AcHdrMark LITERAL1 +kTcl96AcHdrSpace LITERAL1 +kTcl96AcSpaceCount LITERAL1 +kTcl96AcStateLength LITERAL1 kTechnibelAcBitMark LITERAL1 kTechnibelAcBits LITERAL1 kTechnibelAcCool LITERAL1 @@ -3831,6 +4159,8 @@ kTempUpStr LITERAL1 kThreeLetterDayOfWeekStr LITERAL1 kTimeSep LITERAL1 kTimeoutMs LITERAL1 +kTimerActiveDaysStr LITERAL1 +kTimerCommand LITERAL1 kTimerModeStr LITERAL1 kTimerStr LITERAL1 kToggleStr LITERAL1 @@ -3871,6 +4201,19 @@ kToshibaAcSwingToggle LITERAL1 kToshibaAcTurboOn LITERAL1 kToshibaAcUsualGap LITERAL1 kToshibaAcZeroSpace LITERAL1 +kTotoBitMark LITERAL1 +kTotoBits LITERAL1 +kTotoDefaultRepeat LITERAL1 +kTotoGap LITERAL1 +kTotoHdrMark LITERAL1 +kTotoHdrSpace LITERAL1 +kTotoLongBits LITERAL1 +kTotoOneSpace LITERAL1 +kTotoPrefix LITERAL1 +kTotoPrefixBits LITERAL1 +kTotoShortBits LITERAL1 +kTotoSpecialGap LITERAL1 +kTotoZeroSpace LITERAL1 kTranscoldAuto LITERAL1 kTranscoldBitMark LITERAL1 kTranscoldBits LITERAL1 @@ -3963,10 +4306,13 @@ kTypeStr LITERAL1 kUnknownStr LITERAL1 kUnknownThreshold LITERAL1 kUpStr LITERAL1 +kUpperMiddle LITERAL1 +kUpperMiddleStr LITERAL1 kUpperStr LITERAL1 kUseDefTol LITERAL1 kV9014557AStr LITERAL1 kV9014557BStr LITERAL1 +kValueStr LITERAL1 kVaneStr LITERAL1 kVestelAcAuto LITERAL1 kVestelAcBitMark LITERAL1 @@ -4075,6 +4421,14 @@ kWhynterZeroSpaceTicks LITERAL1 kWide LITERAL1 kWideStr LITERAL1 kWifiStr LITERAL1 +kWowweeBitMark LITERAL1 +kWowweeBits LITERAL1 +kWowweeDefaultRepeat LITERAL1 +kWowweeFreq LITERAL1 +kWowweeHdrMark LITERAL1 +kWowweeHdrSpace LITERAL1 +kWowweeOneSpace LITERAL1 +kWowweeZeroSpace LITERAL1 kXFanStr LITERAL1 kXmpBaseSpace LITERAL1 kXmpBits LITERAL1 @@ -4090,6 +4444,27 @@ kXmpWordSize LITERAL1 kYaw1fStr LITERAL1 kYbofbStr LITERAL1 kYesStr LITERAL1 +kYorkAuto LITERAL1 +kYorkBitMark LITERAL1 +kYorkBits LITERAL1 +kYorkCool LITERAL1 +kYorkDry LITERAL1 +kYorkFan LITERAL1 +kYorkFanAuto LITERAL1 +kYorkFanHigh LITERAL1 +kYorkFanLow LITERAL1 +kYorkFanMedium LITERAL1 +kYorkFreq LITERAL1 +kYorkHdrMark LITERAL1 +kYorkHdrSpace LITERAL1 +kYorkHeat LITERAL1 +kYorkKnownGoodState LITERAL1 +kYorkMaxTemp LITERAL1 +kYorkMinTemp LITERAL1 +kYorkOneSpace LITERAL1 +kYorkStateLength LITERAL1 +kYorkZeroSpace LITERAL1 +kYx1fsfStr LITERAL1 kZepealBits LITERAL1 kZepealCommandOffOn LITERAL1 kZepealCommandOffTimer LITERAL1 diff --git a/lib/IRremoteESP8266/library.json b/lib/IRremoteESP8266/library.json index 948ae48fa9..60c4811529 100644 --- a/lib/IRremoteESP8266/library.json +++ b/lib/IRremoteESP8266/library.json @@ -1,6 +1,6 @@ { "name": "IRremoteESP8266", - "version": "2.8.2", + "version": "2.8.6", "keywords": "infrared, ir, remote, esp8266, esp32", "description": "Send and receive infrared signals with multiple protocols (ESP8266/ESP32)", "repository": diff --git a/lib/IRremoteESP8266/library.properties b/lib/IRremoteESP8266/library.properties index d776853f2c..faed00b754 100644 --- a/lib/IRremoteESP8266/library.properties +++ b/lib/IRremoteESP8266/library.properties @@ -1,5 +1,5 @@ name=IRremoteESP8266 -version=2.8.2 +version=2.8.6 author=David Conran, Sebastien Warin, Mark Szabo, Ken Shirriff maintainer=David Conran, Mark Szabo, Sebastien Warin, Roi Dayan, Massimiliano Pinto, Christian Nilsson sentence=Send and receive infrared signals with multiple protocols (ESP8266/ESP32) diff --git a/lib/IRremoteESP8266/platformio.ini b/lib/IRremoteESP8266/platformio.ini index 76c2f3b40e..eacdd4f1d2 100644 --- a/lib/IRremoteESP8266/platformio.ini +++ b/lib/IRremoteESP8266/platformio.ini @@ -18,5 +18,10 @@ board = nodemcuv2 board = d1_mini [env:esp32dev] -platform = espressif32 +platform = espressif32 @ ^6.4.0 board = esp32dev + +# Experimental IDF 5.x support +[env:esp32devIDF5x] +platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.12/platform-espressif32.zip +board = esp32dev diff --git a/lib/IRremoteESP8266/src/IRac.cpp b/lib/IRremoteESP8266/src/IRac.cpp index e14f05b62e..67c218c1ed 100644 --- a/lib/IRremoteESP8266/src/IRac.cpp +++ b/lib/IRremoteESP8266/src/IRac.cpp @@ -12,6 +12,12 @@ #ifndef ARDUINO #include #endif +#include +#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_MATH_TR1) + using std::roundf; +#else + using ::roundf; +#endif #include "IRsend.h" #include "IRremoteESP8266.h" #include "IRtext.h" @@ -20,6 +26,7 @@ #include "ir_Airwell.h" #include "ir_Amcor.h" #include "ir_Argo.h" +#include "ir_Bosch.h" #include "ir_Carrier.h" #include "ir_Coolix.h" #include "ir_Corona.h" @@ -63,6 +70,36 @@ #endif // ESP8266 #endif // STRCASECMP +#ifndef UNIT_TEST +#define OUTPUT_DECODE_RESULTS_FOR_UT(ac) +#else +/* NOTE: THIS IS NOT A DOXYGEN COMMENT (would require ENABLE_PREPROCESSING-YES) +/// If compiling for UT *and* a test receiver @c IRrecv is provided via the +/// @c _utReceived param, this injects an "output" gadget @c _lastDecodeResults +/// into the @c IRAc::sendAc method, so that the UT code may parse the "sent" +/// value and drive further assertions +/// +/// @note The @c decode_results "returned" is a shallow copy (empty rawbuf), +/// mostly b/c the class does not have a custom/deep copy c-tor +/// and defining it would be an overkill for this purpose +/// @note For future maintainers: If @c IRAc class is ever refactored to use +/// polymorphism (static or dynamic)... this macro should be removed +/// and replaced with proper GMock injection. +*/ +#define OUTPUT_DECODE_RESULTS_FOR_UT(ac) \ + { \ + if (_utReceiver) { \ + _lastDecodeResults = nullptr; \ + (ac)._irsend.makeDecodeResult(); \ + if (_utReceiver->decode(&(ac)._irsend.capture)) { \ + _lastDecodeResults = std::unique_ptr( \ + new decode_results((ac)._irsend.capture)); \ + _lastDecodeResults->rawbuf = nullptr; \ + } \ + } \ + } +#endif // UNIT_TEST + /// Class constructor /// @param[in] pin Gpio pin to use when transmitting IR messages. /// @param[in] inverted true, gpio output defaults to high. false, to low. @@ -161,6 +198,9 @@ bool IRac::isProtocolSupported(const decode_type_t protocol) { #if SEND_ARGO case decode_type_t::ARGO: #endif +#if SEND_BOSCH144 + case decode_type_t::BOSCH144: +#endif #if SEND_CARRIER_AC64 case decode_type_t::CARRIER_AC64: #endif // SEND_CARRIER_AC64 @@ -215,6 +255,9 @@ bool IRac::isProtocolSupported(const decode_type_t protocol) { #if SEND_HAIER_AC case decode_type_t::HAIER_AC: #endif +#if SEND_HAIER_AC160 + case decode_type_t::HAIER_AC160: +#endif // SEND_HAIER_AC160 #if SEND_HAIER_AC176 case decode_type_t::HAIER_AC176: #endif // SEND_HAIER_AC176 @@ -325,7 +368,12 @@ bool IRac::isProtocolSupported(const decode_type_t protocol) { #if SEND_VOLTAS case decode_type_t::VOLTAS: #endif +#if SEND_YORK + case decode_type_t::YORK: +#endif +#if SEND_WHIRLPOOL_AC case decode_type_t::WHIRLPOOL_AC: +#endif return true; default: return false; @@ -432,19 +480,27 @@ void IRac::amcor(IRAmcorAc *ac, /// @param[in] on The power setting. /// @param[in] mode The operation mode setting. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] turbo Run the device in turbo/powerful mode. /// @param[in] sleep Nr. of minutes for sleep mode. /// @note -1 is Off, >= 0 is on. void IRac::argo(IRArgoAC *ac, const bool on, const stdAc::opmode_t mode, const float degrees, - const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const float sensorTemp, const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, const bool iFeel, const bool turbo, const int16_t sleep) { ac->begin(); ac->setPower(on); ac->setMode(ac->convertMode(mode)); - ac->setTemp(degrees); + ac->setTemp(static_cast(roundf(degrees))); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } + ac->setiFeel(iFeel); ac->setFan(ac->convertFan(fan)); ac->setFlap(ac->convertSwingV(swingv)); // No Quiet setting available. @@ -457,8 +513,164 @@ void IRac::argo(IRArgoAC *ac, ac->setNight(sleep >= 0); // Convert to a boolean. ac->send(); } + +/// Send an Argo A/C WREM-3 AC **control** message with the supplied settings. +/// @param[in, out] ac A Ptr to an IRArgoAC_WREM3 object to use. +/// @param[in] on The power setting. +/// @param[in] mode The operation mode setting. +/// @param[in] degrees The set temperature setting in degrees Celsius. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. +/// @warning The @c sensorTemp param is assumed to be in 0..255 range (uint8_t) +/// The overflow is *not* checked, though. +/// @note The value is rounded to nearest integer, rounding halfway cases +/// away from zero. E.g. 1.5 [C] becomes 2 [C]. +/// @param[in] fan The speed setting for the fan. +/// @param[in] swingv The vertical swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. +/// @param[in] night Enable night mode (raises temp by +1*C after 1h). +/// @param[in] econo Enable eco mode (limits power consumed). +/// @param[in] turbo Run the device in turbo/powerful mode. +/// @param[in] filter Enable filter mode +/// @param[in] light Enable device display/LEDs +void IRac::argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, const bool on, + const stdAc::opmode_t mode, const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, const bool iFeel, + const bool night, const bool econo, const bool turbo, const bool filter, + const bool light) { + ac->begin(); + ac->setMessageType(argoIrMessageType_t::AC_CONTROL); + ac->setPower(on); + ac->setMode(ac->convertMode(mode)); + ac->setTemp(degrees); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } + ac->setiFeel(iFeel); + ac->setFan(ac->convertFan(fan)); + ac->setFlap(ac->convertSwingV(swingv)); + ac->setNight(night); + ac->setEco(econo); + ac->setMax(turbo); + ac->setFilter(filter); + ac->setLight(light); + // No Clean setting available. + // No Beep setting available - always beeps in this mode :) + ac->send(); +} + +/// Send an Argo A/C WREM-3 iFeel (room temp) silent (no beep) report. +/// @param[in, out] ac A Ptr to an IRArgoAC_WREM3 object to use. +/// @param[in] sensorTemp The room (iFeel) temperature setting +/// in degrees Celsius. +/// @warning The @c sensorTemp param is assumed to be in 0..255 range (uint8_t) +/// The overflow is *not* checked, though. +/// @note The value is rounded to nearest integer, rounding halfway cases +/// away from zero. E.g. 1.5 [C] becomes 2 [C]. +void IRac::argoWrem3_iFeelReport(IRArgoAC_WREM3 *ac, const float sensorTemp) { + ac->begin(); + ac->setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + ac->send(); +} + +/// Send an Argo A/C WREM-3 Config command. +/// @param[in, out] ac A Ptr to an IRArgoAC_WREM3 object to use. +/// @param[in] param The parameter ID. +/// @param[in] value The parameter value. +/// @param[in] safe If true, will only allow setting the below parameters +/// in order to avoid accidentally setting a restricted +/// vendor-specific param and breaking the A/C device +/// @note Known parameters (P, where xx is the @c param) +/// P05 - Temperature Scale (0-Celsius, 1-Fahrenheit) +/// P06 - Transmission channel (0..3) +/// P12 - ECO mode power input limit (30..99, default: 75) +void IRac::argoWrem3_ConfigSet(IRArgoAC_WREM3 *ac, const uint8_t param, + const uint8_t value, bool safe /*= true*/) { + if (safe) { + switch (param) { + case 5: // temp. scale (note this is likely excess as not transmitted) + if (value > 1) { return; /* invalid */ } + break; + case 6: // channel (note this is likely excess as not transmitted) + if (value > 3) { return; /* invalid */ } + break; + case 12: // eco power limit + if (value < 30 || value > 99) { return; /* invalid */ } + break; + default: + return; /* invalid */ + } + } + ac->begin(); + ac->setMessageType(argoIrMessageType_t::CONFIG_PARAM_SET); + ac->setConfigEntry(param, value); + ac->send(); +} + +/// Send an Argo A/C WREM-3 Delay timer command. +/// @param[in, out] ac A Ptr to an IRArgoAC_WREM3 object to use. +/// @param[in] on Whether the unit is currently on. The timer, upon elapse +/// will toggle this state +/// @param[in] currentTime currentTime in minutes, starting from 00:00 +/// @note For timer mode, this value is not really used much so can be zero. +/// @param[in] delayMinutes Number of minutes after which the @c on state should +/// be toggled +/// @note Schedule timers are not exposed via this interface +void IRac::argoWrem3_SetTimer(IRArgoAC_WREM3 *ac, bool on, + const uint16_t currentTime, const uint16_t delayMinutes) { + ac->begin(); + ac->setMessageType(argoIrMessageType_t::TIMER_COMMAND); + ac->setPower(on); + ac->setTimerType(argoTimerType_t::DELAY_TIMER); + ac->setCurrentTimeMinutes(currentTime); + // Note: Day of week is not set (no need) + ac->setDelayTimerMinutes(delayMinutes); + ac->send(); +} #endif // SEND_ARGO +#if SEND_BOSCH144 +/// Send a Bosch144 A/C message with the supplied settings. +/// @note May result in multiple messages being sent. +/// @param[in, out] ac A Ptr to an IRBosch144AC object to use. +/// @param[in] on The power setting. +/// @param[in] mode The operation mode setting. +/// @param[in] degrees The temperature setting in degrees. +/// @param[in] fan The speed setting for the fan. +/// @param[in] quiet Run the device in quiet/silent mode. +/// @note -1 is Off, >= 0 is on. +void IRac::bosch144(IRBosch144AC *ac, + const bool on, const stdAc::opmode_t mode, + const float degrees, const stdAc::fanspeed_t fan, + const bool quiet) { + ac->begin(); + ac->setPower(on); + if (!on) { + // after turn off AC no more commands should + // be accepted + ac->send(); + return; + } + ac->setTemp(degrees); + ac->setFan(ac->convertFan(fan)); + ac->setMode(ac->convertMode(mode)); + ac->setQuiet(quiet); + ac->send(); // Send the state, which will also power on the unit. + // The following are all options/settings that create their own special + // messages. Often they only make sense to be sent after the unit is turned + // on. For instance, assuming a person wants to have the a/c on and in turbo + // mode. If we send the turbo message, it is ignored if the unit is off. + // Hence we send the special mode/setting messages after a normal message + // which will turn on the device. + // No Filter setting available. + // No Beep setting available. + // No Clock setting available. + // No Econo setting available. + // No Sleep setting available. +} +#endif // SEND_BOSCH144 + #if SEND_CARRIER_AC64 /// Send a Carrier 64-bit A/C message with the supplied settings. /// @param[in, out] ac A Ptr to an IRCarrierAc64 object to use. @@ -498,9 +710,12 @@ void IRac::carrier64(IRCarrierAc64 *ac, /// @param[in] on The power setting. /// @param[in] mode The operation mode setting. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. /// @param[in] swingh The horizontal swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] turbo Run the device in turbo/powerful mode. /// @param[in] light Turn on the LED/Display mode. /// @param[in] clean Turn on the self-cleaning mode. e.g. Mould, dry filters etc @@ -508,10 +723,11 @@ void IRac::carrier64(IRCarrierAc64 *ac, /// @note -1 is Off, >= 0 is on. void IRac::coolix(IRCoolixAC *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, const stdAc::swingh_t swingh, - const bool turbo, const bool light, const bool clean, - const int16_t sleep) { + const bool iFeel, const bool turbo, const bool light, + const bool clean, const int16_t sleep) { ac->begin(); ac->setPower(on); if (!on) { @@ -528,6 +744,12 @@ void IRac::coolix(IRCoolixAC *ac, // No Clock setting available. // No Econo setting available. // No Quiet setting available. + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } else { + ac->clearSensorTemp(); + } + ac->setZoneFollow(iFeel); ac->send(); // Send the state, which will also power on the unit. // The following are all options/settings that create their own special // messages. Often they only make sense to be sent after the unit is turned @@ -892,13 +1114,16 @@ void IRac::delonghiac(IRDelonghiAc *ac, /// @param[in] on The power setting. /// @param[in] mode The operation mode setting. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. /// @param[in] fan The speed setting for the fan. /// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on. /// @param[in] clock The time in Nr. of mins since midnight. < 0 is ignore. void IRac::ecoclim(IREcoclimAc *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, - const int16_t sleep, const int16_t clock) { + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const int16_t sleep, + const int16_t clock) { ac->begin(); ac->setPower(on); uint8_t new_mode; @@ -908,8 +1133,13 @@ void IRac::ecoclim(IREcoclimAc *ac, new_mode = ac->convertMode(mode); // Not Sleep, so use the supplied mode. ac->setMode(new_mode); ac->setTemp(degrees); - ac->setSensorTemp(degrees); //< Set to the desired temp until we cab disable. ac->setFan(ac->convertFan(fan)); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } else { + ac->setSensorTemp(degrees); //< Set to the desired temp + // until we can disable. + } // No SwingV setting available // No SwingH setting available // No Quiet setting available. @@ -931,22 +1161,28 @@ void IRac::ecoclim(IREcoclimAc *ac, /// @param[in] on The power setting. /// @param[in] mode The operation mode setting. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. /// @param[in] swingh The horizontal swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] turbo Run the device in turbo/powerful mode. /// @param[in] lighttoggle Should we toggle the LED/Display? /// @param[in] clean Turn on the self-cleaning mode. e.g. Mould, dry filters etc void IRac::electra(IRElectraAc *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, - const stdAc::swingv_t swingv, - const stdAc::swingh_t swingh, const bool turbo, - const bool lighttoggle, const bool clean) { + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const stdAc::swingh_t swingh, const bool iFeel, + const bool turbo, const bool lighttoggle, const bool clean) { ac->begin(); ac->setPower(on); ac->setMode(ac->convertMode(mode)); ac->setTemp(degrees); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } ac->setFan(ac->convertFan(fan)); ac->setSwingV(swingv != stdAc::swingv_t::kOff); ac->setSwingH(swingh != stdAc::swingh_t::kOff); @@ -959,6 +1195,7 @@ void IRac::electra(IRElectraAc *ac, // No Beep setting available. // No Sleep setting available. // No Clock setting available. + ac->setIFeel(iFeel); ac->send(); } #endif // SEND_ELECTRA_AC @@ -1084,6 +1321,7 @@ void IRac::goodweather(IRGoodweatherAc *ac, /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. /// @param[in] swingh The horizontal swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] turbo Run the device in turbo/powerful mode. /// @param[in] econo Toggle the device's economical mode. /// @param[in] light Turn on the LED/Display mode. @@ -1093,8 +1331,8 @@ void IRac::gree(IRGreeAC *ac, const gree_ac_remote_model_t model, const bool on, const stdAc::opmode_t mode, const bool celsius, const float degrees, const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, const stdAc::swingh_t swingh, - const bool turbo, const bool econo, const bool light, - const bool clean, const int16_t sleep) { + const bool iFeel, const bool turbo, const bool econo, + const bool light, const bool clean, const int16_t sleep) { ac->begin(); ac->setModel(model); ac->setPower(on); @@ -1104,6 +1342,7 @@ void IRac::gree(IRGreeAC *ac, const gree_ac_remote_model_t model, ac->setSwingVertical(swingv == stdAc::swingv_t::kAuto, // Set auto flag. ac->convertSwingV(swingv)); ac->setSwingHorizontal(ac->convertSwingH(swingh)); + ac->setIFeel(iFeel); ac->setLight(light); ac->setTurbo(turbo); ac->setEcono(econo); @@ -1155,6 +1394,52 @@ void IRac::haier(IRHaierAC *ac, } #endif // SEND_HAIER_AC +#if SEND_HAIER_AC160 +/// Send a Haier 160 bit A/C message with the supplied settings. +/// @param[in, out] ac A Ptr to an IRHaierAC160 object to use. +/// @param[in] on The power setting. +/// @param[in] mode The operation mode setting. +/// @param[in] celsius Temperature units. True is Celsius, False is Fahrenheit. +/// @param[in] degrees The temperature setting in degrees. +/// @param[in] fan The speed setting for the fan. +/// @param[in] swingv The vertical swing setting. +/// @param[in] turbo Run the device in turbo/powerful mode. +/// @param[in] quiet Run the device in quiet mode. +/// @param[in] filter Turn on the (ion/pollen/etc) filter mode. +/// @param[in] clean Turn on the clean mode. +/// @param[in] light Turn on the LED/Display mode. +/// @param[in] prevlight Previous LED/Display mode. +/// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on. +void IRac::haier160(IRHaierAC160 *ac, + const bool on, const stdAc::opmode_t mode, + const bool celsius, const float degrees, + const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, + const bool turbo, const bool quiet, const bool filter, + const bool clean, const bool light, const bool prevlight, + const int16_t sleep) { + ac->begin(); + // No Model setting available. + ac->setMode(ac->convertMode(mode)); + ac->setUseFahrenheit(!celsius); + ac->setTemp(degrees); + ac->setFan(ac->convertFan(fan)); + ac->setSwingV(ac->convertSwingV(swingv)); + // No Horizontal Swing setting available. + ac->setQuiet(quiet); + ac->setTurbo(turbo); + ac->setHealth(filter); + ac->setClean(clean); + // No Clean setting available. + // No Beep setting available. + ac->setSleep(sleep >= 0); // Sleep on this A/C is either on or off. + ac->setPower(on); + // Light needs to be sent last as the "button" value seems to control it. + ac->setLightToggle(light ^ prevlight); + ac->send(); +} +#endif // SEND_HAIER_AC160 + #if SEND_HAIER_AC176 /// Send a Haier 176 bit A/C message with the supplied settings. /// @param[in, out] ac A Ptr to an IRHaierAC176 object to use. @@ -1567,8 +1852,11 @@ void IRac::lg(IRLgAc *ac, const lg_ac_remote_model_t model, /// @param[in] mode The operation mode setting. /// @param[in] celsius Temperature units. True is Celsius, False is Fahrenheit. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading +/// in degrees. /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] quiet Run the device in quiet/silent mode. /// @param[in] quiet_prev The device's previous quiet/silent mode. /// @param[in] turbo Toggle the device's turbo/powerful mode. @@ -1579,9 +1867,9 @@ void IRac::lg(IRLgAc *ac, const lg_ac_remote_model_t model, /// @note On Danby A/C units, swingv controls the Ion Filter instead. void IRac::midea(IRMideaAC *ac, const bool on, const stdAc::opmode_t mode, const bool celsius, - const float degrees, const stdAc::fanspeed_t fan, - const stdAc::swingv_t swingv, - const bool quiet, const bool quiet_prev, + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const bool iFeel, const bool quiet, const bool quiet_prev, const bool turbo, const bool econo, const bool light, const bool clean, const int16_t sleep) { ac->begin(); @@ -1589,6 +1877,10 @@ void IRac::midea(IRMideaAC *ac, ac->setMode(ac->convertMode(mode)); ac->setUseCelsius(celsius); ac->setTemp(degrees, celsius); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(sensorTemp, celsius); + } + ac->setEnableSensorTemp(iFeel); ac->setFan(ac->convertFan(fan)); ac->setSwingVToggle(swingv != stdAc::swingv_t::kOff); // No Horizontal swing setting available. @@ -1986,19 +2278,29 @@ void IRac::samsung(IRSamsungAc *ac, /// @param[in] on The power setting. /// @param[in] mode The operation mode setting. /// @param[in] degrees The temperature setting in degrees. +/// @param[in] sensorTemp The room (iFeel) temperature sensor reading in degrees +/// Celsius. /// @param[in] fan The speed setting for the fan. /// @param[in] swingv The vertical swing setting. +/// @param[in] iFeel Whether to enable iFeel (remote temp) mode on the A/C unit. /// @param[in] beep Enable/Disable beeps when receiving IR messages. /// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on. void IRac::sanyo(IRSanyoAc *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, - const stdAc::swingv_t swingv, const bool beep, - const int16_t sleep) { + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const bool iFeel, const bool beep, const int16_t sleep) { ac->begin(); ac->setPower(on); ac->setMode(ac->convertMode(mode)); ac->setTemp(degrees); + if (sensorTemp != kNoTempValue) { + ac->setSensorTemp(static_cast(roundf(sensorTemp))); + } else { + ac->setSensorTemp(degrees); // Set the sensor temp to the desired + // (normal) temp. + } + ac->setSensor(!iFeel); ac->setFan(ac->convertFan(fan)); ac->setSwingV(ac->convertSwingV(swingv)); // No Horizontal swing setting available. @@ -2011,10 +2313,6 @@ void IRac::sanyo(IRSanyoAc *ac, ac->setBeep(beep); ac->setSleep(sleep >= 0); // Sleep is either on/off, so convert to boolean. // No Clock setting available. - - // Extra - ac->setSensor(true); // Set the A/C to use the temp sensor in the Unit/Wall. - ac->setSensorTemp(degrees); // Set the sensor temp to the desired temp. ac->send(); } #endif // SEND_SANYO_AC @@ -2707,6 +3005,11 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { // Convert the temp from Fahrenheit to Celsius if we are not in Celsius mode. float degC __attribute__((unused)) = desired.celsius ? desired.degrees : fahrenheitToCelsius(desired.degrees); + // Convert the sensorTemp from Fahrenheit to Celsius if we are not in Celsius + // mode. + float sensorTempC __attribute__((unused)) = + desired.sensorTemperature ? desired.sensorTemperature + : fahrenheitToCelsius(desired.sensorTemperature); // special `state_t` that is required to be sent based on that. stdAc::state_t send = this->handleToggles(this->cleanState(desired), prev); // Some protocols expect a previous state for power. @@ -2719,6 +3022,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { const stdAc::swingv_t prev_swingv = (prev != NULL) ? prev->swingv : stdAc::swingv_t::kOff; #endif // (SEND_LG || SEND_SHARP_AC) +#if (SEND_HAIER_AC160) + const bool prev_light = (prev != NULL) ? prev->light : !send.light; +#endif // (SEND_HAIER_AC160) #if SEND_MIDEA const bool prev_quiet = (prev != NULL) ? prev->quiet : !send.quiet; #endif // SEND_MIDEA @@ -2753,12 +3059,47 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { #if SEND_ARGO case ARGO: { - IRArgoAC ac(_pin, _inverted, _modulation); - argo(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv, - send.turbo, send.sleep); + if (send.model == argo_ac_remote_model_t::SAC_WREM3) { + IRArgoAC_WREM3 ac(_pin, _inverted, _modulation); + switch (send.command) { + case stdAc::ac_command_t::kSensorTempReport: + argoWrem3_iFeelReport(&ac, sensorTempC); + break; + case stdAc::ac_command_t::kConfigCommand: + /// @warning: this is ABUSING current **common** parameters: + /// @c clock and @c sleep as config key and value + /// Hence, value pre-validation is performed (safe-mode) + /// to avoid accidental device misconfiguration + argoWrem3_ConfigSet(&ac, send.clock, send.sleep, true); + break; + case stdAc::ac_command_t::kTimerCommand: + argoWrem3_SetTimer(&ac, send.power, send.clock, send.sleep); + break; + case stdAc::ac_command_t::kControlCommand: + default: + argoWrem3_ACCommand(&ac, send.power, send.mode, degC, sensorTempC, + send.fanspeed, send.swingv, send.iFeel, send.quiet, send.econo, + send.turbo, send.filter, send.light); + break; + } + OUTPUT_DECODE_RESULTS_FOR_UT(ac); + } else { + IRArgoAC ac(_pin, _inverted, _modulation); + argo(&ac, send.power, send.mode, degC, sensorTempC, send.fanspeed, + send.swingv, send.iFeel, send.turbo, send.sleep); + OUTPUT_DECODE_RESULTS_FOR_UT(ac); + } break; } #endif // SEND_ARGO +#if SEND_BOSCH144 + case BOSCH144: + { + IRBosch144AC ac(_pin, _inverted, _modulation); + bosch144(&ac, send.power, send.mode, degC, send.fanspeed, send.quiet); + break; + } +#endif // SEND_BOSCH144 #if SEND_CARRIER_AC64 case CARRIER_AC64: { @@ -2772,8 +3113,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { case COOLIX: { IRCoolixAC ac(_pin, _inverted, _modulation); - coolix(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv, - send.swingh, send.turbo, send.light, send.clean, send.sleep); + coolix(&ac, send.power, send.mode, degC, sensorTempC, send.fanspeed, + send.swingv, send.swingh, send.iFeel, send.turbo, send.light, + send.clean, send.sleep); break; } #endif // SEND_COOLIX @@ -2871,7 +3213,8 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { case ECOCLIM: { IREcoclimAc ac(_pin, _inverted, _modulation); - ecoclim(&ac, send.power, send.mode, degC, send.fanspeed, send.clock); + ecoclim(&ac, send.power, send.mode, degC, sensorTempC, send.fanspeed, + send.iFeel, send.clock); break; } #endif // SEND_ECOCLIM @@ -2879,8 +3222,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { case ELECTRA_AC: { IRElectraAc ac(_pin, _inverted, _modulation); - electra(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv, - send.swingh, send.turbo, send.light, send.clean); + electra(&ac, send.power, send.mode, degC, sensorTempC, send.fanspeed, + send.swingv, send.swingh, send.iFeel, send.turbo, send.light, + send.clean); break; } #endif // SEND_ELECTRA_AC @@ -2892,7 +3236,7 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { fujitsu(&ac, (fujitsu_ac_remote_model_t)send.model, send.power, send.mode, send.celsius, send.degrees, send.fanspeed, send.swingv, send.swingh, send.quiet, - send.turbo, send.econo, send.filter, send.clean); + send.turbo, send.econo, send.filter, send.clean, send.sleep); break; } #endif // SEND_FUJITSU_AC @@ -2912,7 +3256,8 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { _modulation); gree(&ac, (gree_ac_remote_model_t)send.model, send.power, send.mode, send.celsius, send.degrees, send.fanspeed, send.swingv, send.swingh, - send.turbo, send.econo, send.light, send.clean, send.sleep); + send.iFeel, send.turbo, send.econo, send.light, send.clean, + send.sleep); break; } #endif // SEND_GREE @@ -2925,6 +3270,16 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { break; } #endif // SEND_HAIER_AC +#if SEND_HAIER_AC160 + case HAIER_AC160: + { + IRHaierAC160 ac(_pin, _inverted, _modulation); + haier160(&ac, send.power, send.mode, send.celsius, send.degrees, + send.fanspeed, send.swingv, send.turbo, send.filter, send.clean, + send.light, prev_light, send.sleep); + break; + } +#endif // SEND_HAIER_AC160 #if SEND_HAIER_AC176 case HAIER_AC176: { @@ -3038,8 +3393,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { { IRMideaAC ac(_pin, _inverted, _modulation); midea(&ac, send.power, send.mode, send.celsius, send.degrees, - send.fanspeed, send.swingv, send.quiet, prev_quiet, send.turbo, - send.econo, send.light, send.sleep); + send.sensorTemperature, send.fanspeed, send.swingv, send.iFeel, + send.quiet, prev_quiet, send.turbo, send.econo, send.light, + send.clean, send.sleep); break; } #endif // SEND_MIDEA @@ -3148,8 +3504,8 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) { case SANYO_AC: { IRSanyoAc ac(_pin, _inverted, _modulation); - sanyo(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv, - send.beep, send.sleep); + sanyo(&ac, send.power, send.mode, degC, sensorTempC, send.fanspeed, + send.swingv, send.iFeel, send.beep, send.sleep); break; } #endif // SEND_SANYO_AC @@ -3306,7 +3662,9 @@ bool IRac::cmpStates(const stdAc::state_t a, const stdAc::state_t b) { a.fanspeed != b.fanspeed || a.swingv != b.swingv || a.swingh != b.swingh || a.quiet != b.quiet || a.turbo != b.turbo || a.econo != b.econo || a.light != b.light || a.filter != b.filter || - a.clean != b.clean || a.beep != b.beep || a.sleep != b.sleep; + a.clean != b.clean || a.beep != b.beep || a.sleep != b.sleep || + a.command != b.command || a.sensorTemperature != b.sensorTemperature || + a.iFeel != b.iFeel; } /// Check if the internal state has changed from what was previously sent. @@ -3314,6 +3672,26 @@ bool IRac::cmpStates(const stdAc::state_t a, const stdAc::state_t b) { /// @return True if it has changed, False if not. bool IRac::hasStateChanged(void) { return cmpStates(next, _prev); } +/// Convert the supplied str into the appropriate enum. +/// @param[in] str A Ptr to a C-style string to be converted. +/// @param[in] def The enum to return if no conversion was possible. +/// @return The equivalent enum. +stdAc::ac_command_t IRac::strToCommandType(const char *str, + const stdAc::ac_command_t def) { + if (!STRCASECMP(str, kControlCommandStr)) + return stdAc::ac_command_t::kControlCommand; + else if (!STRCASECMP(str, kIFeelReportStr) || + !STRCASECMP(str, kIFeelStr)) + return stdAc::ac_command_t::kSensorTempReport; + else if (!STRCASECMP(str, kSetTimerCommandStr) || + !STRCASECMP(str, kTimerStr)) + return stdAc::ac_command_t::kTimerCommand; + else if (!STRCASECMP(str, kConfigCommandStr)) + return stdAc::ac_command_t::kConfigCommand; + else + return def; +} + /// Convert the supplied str into the appropriate enum. /// @param[in] str A Ptr to a C-style string to be converted. /// @param[in] def The enum to return if no conversion was possible. @@ -3377,6 +3755,8 @@ stdAc::fanspeed_t IRac::strToFanspeed(const char *str, !STRCASECMP(str, kMaximumStr) || !STRCASECMP(str, kHighestStr)) return stdAc::fanspeed_t::kMax; + else if (!STRCASECMP(str, kMedHighStr)) + return stdAc::fanspeed_t::kMediumHigh; else return def; } @@ -3409,6 +3789,8 @@ stdAc::swingv_t IRac::strToSwingV(const char *str, !STRCASECMP(str, kMediumStr) || !STRCASECMP(str, kCentreStr)) return stdAc::swingv_t::kMiddle; + else if (!STRCASECMP(str, kUpperMiddleStr)) + return stdAc::swingv_t::kUpperMiddle; else if (!STRCASECMP(str, kHighStr) || !STRCASECMP(str, kHiStr)) return stdAc::swingv_t::kHigh; @@ -3551,6 +3933,11 @@ int16_t IRac::strToModel(const char *str, const int16_t def) { return whirlpool_ac_remote_model_t::DG11J13A; } else if (!STRCASECMP(str, kDg11j191Str)) { return whirlpool_ac_remote_model_t::DG11J191; + // Argo A/C models + } else if (!STRCASECMP(str, kArgoWrem2Str)) { + return argo_ac_remote_model_t::SAC_WREM2; + } else if (!STRCASECMP(str, kArgoWrem3Str)) { + return argo_ac_remote_model_t::SAC_WREM3; } else { int16_t number = atoi(str); if (number > 0) @@ -3586,6 +3973,19 @@ String IRac::boolToString(const bool value) { return value ? kOnStr : kOffStr; } +/// Convert the supplied operation mode into the appropriate String. +/// @param[in] cmdType The enum to be converted. +/// @return The equivalent String for the locale. +String IRac::commandTypeToString(const stdAc::ac_command_t cmdType) { + switch (cmdType) { + case stdAc::ac_command_t::kControlCommand: return kControlCommandStr; + case stdAc::ac_command_t::kSensorTempReport: return kIFeelReportStr; + case stdAc::ac_command_t::kTimerCommand: return kSetTimerCommandStr; + case stdAc::ac_command_t::kConfigCommand: return kConfigCommandStr; + default: return kUnknownStr; + } +} + /// Convert the supplied operation mode into the appropriate String. /// @param[in] mode The enum to be converted. /// @param[in] ha A flag to indicate we want GoogleHome/HomeAssistant output. @@ -3607,13 +4007,14 @@ String IRac::opmodeToString(const stdAc::opmode_t mode, const bool ha) { /// @return The equivalent String for the locale. String IRac::fanspeedToString(const stdAc::fanspeed_t speed) { switch (speed) { - case stdAc::fanspeed_t::kAuto: return kAutoStr; - case stdAc::fanspeed_t::kMax: return kMaxStr; - case stdAc::fanspeed_t::kHigh: return kHighStr; - case stdAc::fanspeed_t::kMedium: return kMediumStr; - case stdAc::fanspeed_t::kLow: return kLowStr; - case stdAc::fanspeed_t::kMin: return kMinStr; - default: return kUnknownStr; + case stdAc::fanspeed_t::kAuto: return kAutoStr; + case stdAc::fanspeed_t::kMax: return kMaxStr; + case stdAc::fanspeed_t::kHigh: return kHighStr; + case stdAc::fanspeed_t::kMedium: return kMediumStr; + case stdAc::fanspeed_t::kMediumHigh: return kMedHighStr; + case stdAc::fanspeed_t::kLow: return kLowStr; + case stdAc::fanspeed_t::kMin: return kMinStr; + default: return kUnknownStr; } } @@ -3622,14 +4023,15 @@ String IRac::fanspeedToString(const stdAc::fanspeed_t speed) { /// @return The equivalent String for the locale. String IRac::swingvToString(const stdAc::swingv_t swingv) { switch (swingv) { - case stdAc::swingv_t::kOff: return kOffStr; - case stdAc::swingv_t::kAuto: return kAutoStr; - case stdAc::swingv_t::kHighest: return kHighestStr; - case stdAc::swingv_t::kHigh: return kHighStr; - case stdAc::swingv_t::kMiddle: return kMiddleStr; - case stdAc::swingv_t::kLow: return kLowStr; - case stdAc::swingv_t::kLowest: return kLowestStr; - default: return kUnknownStr; + case stdAc::swingv_t::kOff: return kOffStr; + case stdAc::swingv_t::kAuto: return kAutoStr; + case stdAc::swingv_t::kHighest: return kHighestStr; + case stdAc::swingv_t::kHigh: return kHighStr; + case stdAc::swingv_t::kMiddle: return kMiddleStr; + case stdAc::swingv_t::kUpperMiddle: return kUpperMiddleStr; + case stdAc::swingv_t::kLow: return kLowStr; + case stdAc::swingv_t::kLowest: return kLowestStr; + default: return kUnknownStr; } } @@ -3681,11 +4083,24 @@ namespace IRAcUtils { #endif // DECODE_AMCOR #if DECODE_ARGO case decode_type_t::ARGO: { + if (IRArgoAC_WREM3::isValidWrem3Message(result->state, result->bits, + true)) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } IRArgoAC ac(kGpioUnused); - ac.setRaw(result->state); + ac.setRaw(result->state, result->bits / 8); return ac.toString(); } #endif // DECODE_ARGO +#if DECODE_BOSCH144 + case decode_type_t::BOSCH144: { + IRBosch144AC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } +#endif // DECODE_BOSCH144 #if DECODE_CARRIER_AC64 case decode_type_t::CARRIER_AC64: { IRCarrierAc64 ac(kGpioUnused); @@ -3816,6 +4231,13 @@ namespace IRAcUtils { return ac.toString(); } #endif // DECODE_HAIER_AC +#if DECODE_HAIER_AC160 + case decode_type_t::HAIER_AC160: { + IRHaierAC160 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } +#endif // DECODE_HAIER_AC160 #if DECODE_HAIER_AC176 case decode_type_t::HAIER_AC176: { IRHaierAC176 ac(kGpioUnused); @@ -4082,6 +4504,13 @@ namespace IRAcUtils { return ac.toString(); } #endif // DECODE_WHIRLPOOL_AC +#if DECODE_YORK + case decode_type_t::YORK: { + IRYorkAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } +#endif // DECODE_YORK default: return ""; } @@ -4129,12 +4558,35 @@ namespace IRAcUtils { #endif // DECODE_AMCOR #if DECODE_ARGO case decode_type_t::ARGO: { - IRArgoAC ac(kGpioUnused); + const uint16_t length = decode->bits / 8; + if (IRArgoAC_WREM3::isValidWrem3Message(decode->state, + decode->bits, true)) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setRaw(decode->state, length); + *result = ac.toCommon(); + } else { + IRArgoAC ac(kGpioUnused); + switch (length) { + case kArgoStateLength: + case kArgoShortStateLength: + ac.setRaw(decode->state, length); + *result = ac.toCommon(); + break; + default: + return false; + } + } + break; + } +#endif // DECODE_ARGO +#if DECODE_BOSCH144 + case decode_type_t::BOSCH144: { + IRBosch144AC ac(kGpioUnused); ac.setRaw(decode->state); *result = ac.toCommon(); break; } -#endif // DECODE_ARGO +#endif // DECODE_BOSCH144 #if DECODE_CARRIER_AC64 case decode_type_t::CARRIER_AC64: { IRCarrierAc64 ac(kGpioUnused); @@ -4283,6 +4735,14 @@ namespace IRAcUtils { break; } #endif // DECODE_HAIER_AC +#if DECODE_HAIER_AC160 + case decode_type_t::HAIER_AC160: { + IRHaierAC160 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } +#endif // DECODE_HAIER_AC160 #if DECODE_HAIER_AC176 case decode_type_t::HAIER_AC176: { IRHaierAC176 ac(kGpioUnused); @@ -4587,6 +5047,14 @@ namespace IRAcUtils { break; } #endif // DECODE_WHIRLPOOL_AC +#if DECODE_YORK + case decode_type_t::YORK: { + IRYorkAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } +#endif // DECODE_YORK default: return false; } diff --git a/lib/IRremoteESP8266/src/IRac.h b/lib/IRremoteESP8266/src/IRac.h index 8e3ef7582e..7f4a3cf018 100644 --- a/lib/IRremoteESP8266/src/IRac.h +++ b/lib/IRremoteESP8266/src/IRac.h @@ -5,12 +5,15 @@ #ifndef UNIT_TEST #include +#else +#include #endif #include "IRremoteESP8266.h" #include "ir_Airton.h" #include "ir_Airwell.h" #include "ir_Amcor.h" #include "ir_Argo.h" +#include "ir_Bosch.h" #include "ir_Carrier.h" #include "ir_Coolix.h" #include "ir_Corona.h" @@ -46,6 +49,7 @@ #include "ir_Vestel.h" #include "ir_Voltas.h" #include "ir_Whirlpool.h" +#include "ir_York.h" // Constants const int8_t kGpioUnused = -1; ///< A placeholder for not using an actual GPIO. @@ -83,6 +87,8 @@ class IRac { static bool cmpStates(const stdAc::state_t a, const stdAc::state_t b); static bool strToBool(const char *str, const bool def = false); static int16_t strToModel(const char *str, const int16_t def = -1); + static stdAc::ac_command_t strToCommandType(const char *str, + const stdAc::ac_command_t def = stdAc::ac_command_t::kControlCommand); static stdAc::opmode_t strToOpmode( const char *str, const stdAc::opmode_t def = stdAc::opmode_t::kAuto); static stdAc::fanspeed_t strToFanspeed( @@ -93,6 +99,7 @@ class IRac { static stdAc::swingh_t strToSwingH( const char *str, const stdAc::swingh_t def = stdAc::swingh_t::kOff); static String boolToString(const bool value); + static String commandTypeToString(const stdAc::ac_command_t cmdType); static String opmodeToString(const stdAc::opmode_t mode, const bool ha = false); static String fanspeedToString(const stdAc::fanspeed_t speed); @@ -102,10 +109,17 @@ class IRac { stdAc::state_t getStatePrev(void); bool hasStateChanged(void); stdAc::state_t next; ///< The state we want the device to be in after we send -#ifndef UNIT_TEST +#ifdef UNIT_TEST + /// @cond IGNORE + /// UT-specific + /// See @c OUTPUT_DECODE_RESULTS_FOR_UT macro description in IRac.cpp + std::shared_ptr _utReceiver = nullptr; + std::unique_ptr _lastDecodeResults = nullptr; + /// @endcond +#else private: -#endif +#endif // UNIT_TEST uint16_t _pin; ///< The GPIO to use to transmit messages from. bool _inverted; ///< IR LED is lit when GPIO is LOW (true) or HIGH (false)? bool _modulation; ///< Is frequency modulation to be used? @@ -131,9 +145,26 @@ class IRac { #if SEND_ARGO void argo(IRArgoAC *ac, const bool on, const stdAc::opmode_t mode, const float degrees, - const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, - const bool turbo, const int16_t sleep = -1); + const float sensorTemp, const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, const bool iFeel, const bool turbo, + const int16_t sleep = -1); + void argoWrem3_ACCommand(IRArgoAC_WREM3 *ac, + const bool on, const stdAc::opmode_t mode, const float degrees, + const float sensorTemp, const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, const bool iFeel, const bool night, + const bool econo, const bool turbo, const bool filter, const bool light); + void argoWrem3_iFeelReport(IRArgoAC_WREM3 *ac, const float sensorTemp); + void argoWrem3_ConfigSet(IRArgoAC_WREM3 *ac, const uint8_t param, + const uint8_t value, bool safe = true); + void argoWrem3_SetTimer(IRArgoAC_WREM3 *ac, bool on, + const uint16_t currentTime, const uint16_t delayMinutes); #endif // SEND_ARGO +#if SEND_BOSCH144 + void bosch144(IRBosch144AC *ac, + const bool on, const stdAc::opmode_t mode, const float degrees, + const stdAc::fanspeed_t fan, + const bool quiet); +#endif // SEND_BOSCH144 #if SEND_CARRIER_AC64 void carrier64(IRCarrierAc64 *ac, const bool on, const stdAc::opmode_t mode, @@ -143,10 +174,10 @@ void carrier64(IRCarrierAc64 *ac, #if SEND_COOLIX void coolix(IRCoolixAC *ac, const bool on, const stdAc::opmode_t mode, const float degrees, - const stdAc::fanspeed_t fan, + const float sensorTemp, const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, const stdAc::swingh_t swingh, - const bool turbo, const bool light, const bool clean, - const int16_t sleep = -1); + const bool iFeel, const bool turbo, const bool light, + const bool clean, const int16_t sleep = -1); #endif // SEND_COOLIX #if SEND_CORONA_AC void corona(IRCoronaAc *ac, @@ -224,15 +255,16 @@ void daikin216(IRDaikin216 *ac, #if SEND_ECOCLIM void ecoclim(IREcoclimAc *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, - const int16_t sleep = -1, const int16_t clock = -1); + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const int16_t sleep = -1, + const int16_t clock = -1); #endif // SEND_ECOCLIM #if SEND_ELECTRA_AC void electra(IRElectraAc *ac, const bool on, const stdAc::opmode_t mode, - const float degrees, const stdAc::fanspeed_t fan, - const stdAc::swingv_t swingv, - const stdAc::swingh_t swingh, const bool turbo, + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const stdAc::swingh_t swingh, const bool iFeel, const bool turbo, const bool lighttoggle, const bool clean); #endif // SEND_ELECTRA_AC #if SEND_FUJITSU_AC @@ -258,8 +290,8 @@ void electra(IRElectraAc *ac, const bool on, const stdAc::opmode_t mode, const bool celsius, const float degrees, const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, const stdAc::swingh_t swingh, - const bool turbo, const bool econo, const bool light, - const bool clean, const int16_t sleep = -1); + const bool iFeel, const bool turbo, const bool econo, + const bool light, const bool clean, const int16_t sleep = -1); #endif // SEND_GREE #if SEND_HAIER_AC void haier(IRHaierAC *ac, @@ -268,6 +300,15 @@ void electra(IRElectraAc *ac, const bool filter, const int16_t sleep = -1, const int16_t clock = -1); #endif // SEND_HAIER_AC +#if SEND_HAIER_AC160 + void haier160(IRHaierAC160 *ac, + const bool on, const stdAc::opmode_t mode, const bool celsius, + const float degrees, const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, + const bool turbo, const bool quiet, const bool filter, + const bool clean, const bool light, const bool prevlight, + const int16_t sleep = -1); +#endif // SEND_HAIER_AC160 #if SEND_HAIER_AC176 void haier176(IRHaierAC176 *ac, const haier_ac176_remote_model_t model, const bool on, @@ -347,11 +388,11 @@ void electra(IRElectraAc *ac, #if SEND_MIDEA void midea(IRMideaAC *ac, const bool on, const stdAc::opmode_t mode, const bool celsius, - const float degrees, const stdAc::fanspeed_t fan, - const stdAc::swingv_t swingv, - const bool quiet, const bool quiet_prev, const bool turbo, - const bool econo, const bool light, const bool clean, - const int16_t sleep = -1); + const float degrees, const float sensorTemp, + const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, + const bool iFeel, const bool quiet, const bool quiet_prev, + const bool turbo, const bool econo, const bool light, + const bool clean, const int16_t sleep = -1); #endif // SEND_MIDEA #if SEND_MIRAGE void mirage(IRMirageAc *ac, const stdAc::state_t state); @@ -435,8 +476,9 @@ void electra(IRElectraAc *ac, #if SEND_SANYO_AC void sanyo(IRSanyoAc *ac, const bool on, const stdAc::opmode_t mode, const float degrees, - const stdAc::fanspeed_t fan, const stdAc::swingv_t swingv, - const bool beep, const int16_t sleep = -1); + const float sensorTemp, const stdAc::fanspeed_t fan, + const stdAc::swingv_t swingv, const bool iFeel, const bool beep, + const int16_t sleep = -1); #endif // SEND_SANYO_AC #if SEND_SANYO_AC88 void sanyo88(IRSanyoAc88 *ac, diff --git a/lib/IRremoteESP8266/src/IRrecv.cpp b/lib/IRremoteESP8266/src/IRrecv.cpp index 6ff9fd70be..c7202534da 100644 --- a/lib/IRremoteESP8266/src/IRrecv.cpp +++ b/lib/IRremoteESP8266/src/IRrecv.cpp @@ -21,6 +21,12 @@ extern "C" { #include "IRremoteESP8266.h" #include "IRutils.h" +#if defined(ESP32) +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) +#include +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 +#endif + #ifdef UNIT_TEST #undef ICACHE_RAM_ATTR #define ICACHE_RAM_ATTR @@ -144,7 +150,7 @@ namespace _IRrecv { // Namespace extension #if defined(ESP32) portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; #endif // ESP32 -volatile irparams_t params; +atomic_irparams_t params; irparams_t *params_save; // A copy of the interrupt state while decoding. } // namespace _IRrecv @@ -215,7 +221,7 @@ static void USE_IRAM_ATTR gpio_intr() { else params.rawbuf[rawlen] = (now - start) / kRawTick; } - params.rawlen++; + params.rawlen = params.rawlen + 1; // C++20 fix start = now; @@ -242,8 +248,13 @@ static void USE_IRAM_ATTR gpio_intr() { // @see https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L176-L178 timer->dev->config.alarm_en = 1; #else // _ESP32_IRRECV_TIMER_HACK +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + timerWrite(timer, 0); + timerStart(timer); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 timerWrite(timer, 0); timerAlarmEnable(timer); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 #endif // _ESP32_IRRECV_TIMER_HACK #endif // ESP32 } @@ -333,9 +344,6 @@ IRrecv::IRrecv(const uint16_t recvpin, const uint16_t bufsize, /// timers or interrupts used. IRrecv::~IRrecv(void) { disableIRIn(); -#if defined(ESP32) - if (timer != NULL) timerEnd(timer); // Cleanup the ESP32 timeout timer. -#endif // ESP32 delete[] params.rawbuf; if (params_save != NULL) { delete[] params_save->rawbuf; @@ -359,7 +367,11 @@ void IRrecv::enableIRIn(const bool pullup) { #if defined(ESP32) // Initialise the ESP32 timer. // 80MHz / 80 = 1 uSec granularity. - timer = timerBegin(_timer_num, 80, true); +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + timer = timerBegin(1000000); // 1 MHz +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 + timer = timerBegin(_timer_num, 80, true); // 1 MHz : 80 MHz with divider 80 +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 #ifdef DEBUG if (timer == NULL) { DPRINT("FATAL: Unable enable system timer: "); @@ -367,12 +379,17 @@ void IRrecv::enableIRIn(const bool pullup) { } #endif // DEBUG assert(timer != NULL); // Check we actually got the timer. +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + timerAttachInterrupt(timer, &read_timeout); + timerAlarm(timer, MS_TO_USEC(params.timeout), ONCE, 0); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 // Set the timer so it only fires once, and set it's trigger in uSeconds. timerAlarmWrite(timer, MS_TO_USEC(params.timeout), ONCE); // Note: Interrupt needs to be attached before it can be enabled or disabled. // Note: EDGE (true) is not supported, use LEVEL (false). Ref: #1713 // See: https://github.com/espressif/arduino-esp32/blob/caef4006af491130136b219c1205bdcf8f08bf2b/cores/esp32/esp32-hal-timer.c#L224-L227 timerAttachInterrupt(timer, &read_timeout, false); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 #endif // ESP32 // Initialise state machine variables @@ -398,13 +415,32 @@ void IRrecv::disableIRIn(void) { os_timer_disarm(&timer); #endif // ESP8266 #if defined(ESP32) + if (timer == NULL) { return; } // Call only once (defensive) +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + timerDetachInterrupt(timer); + timerEnd(timer); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 timerAlarmDisable(timer); + timerDetachInterrupt(timer); timerEnd(timer); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 + timer = NULL; // Cleanup the ESP32 timeout timer. #endif // ESP32 detachInterrupt(params.recvpin); #endif // UNIT_TEST } +/// Pause collection of received IR data. +/// @see IRrecv class constructor +void IRrecv::pause(void) { + params.rcvstate = kStopState; + params.rawlen = 0; + params.overflow = false; +#if defined(ESP32) + gpio_intr_disable((gpio_num_t)params.recvpin); +#endif // ESP32 +} + /// Resume collection of received IR data. /// @note This is required if `decode()` is successful and `save_buffer` was /// not set when the class was instanciated. @@ -414,7 +450,12 @@ void IRrecv::resume(void) { params.rawlen = 0; params.overflow = false; #if defined(ESP32) +#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3) ) + timerStop(timer); +#else // ESP_ARDUINO_VERSION_MAJOR >= 3 timerAlarmDisable(timer); +#endif // ESP_ARDUINO_VERSION_MAJOR >= 3 + gpio_intr_enable((gpio_num_t)params.recvpin); #endif // ESP32 } @@ -424,7 +465,7 @@ void IRrecv::resume(void) { /// i.e. In kStopState. /// @param[in] src Pointer to an irparams_t structure to copy from. /// @param[out] dst Pointer to an irparams_t structure to copy to. -void IRrecv::copyIrParams(volatile irparams_t *src, irparams_t *dst) { +void IRrecv::copyIrParams(atomic_irparams_t *src, irparams_t *dst) { // Typecast src and dst addresses to (char *) char *csrc = (char *)src; // NOLINT(readability/casting) char *cdst = (char *)dst; // NOLINT(readability/casting) @@ -489,8 +530,8 @@ void IRrecv::crudeNoiseFilter(decode_results *results, const uint16_t floor) { for (uint16_t i = offset + 2; i <= results->rawlen && i < kBufSize; i++) results->rawbuf[i - 2] = results->rawbuf[i]; if (offset > 1) { // There is a previous pair we can add to. - // Merge this pair into into the previous space. - results->rawbuf[offset - 1] += addition; + // Merge this pair into into the previous space. // C++20 fix applied + results->rawbuf[offset - 1] = results->rawbuf[offset - 1] + addition; } results->rawlen -= 2; // Adjust the length. } else { @@ -689,9 +730,12 @@ bool IRrecv::decode(decode_results *results, irparams_t *save, return true; #endif #if DECODE_PANASONIC - DPRINTLN("Attempting Panasonic decode"); + DPRINTLN("Attempting Panasonic (48-bit) decode"); if (decodePanasonic(results, offset)) return true; -#endif + DPRINTLN("Attempting Panasonic (40-bit) decode"); + if (decodePanasonic(results, offset, kPanasonic40Bits, true, + kPanasonic40Manufacturer)) return true; +#endif // DECODE_PANASONIC #if DECODE_LG DPRINTLN("Attempting LG (28-bit) decode"); if (decodeLG(results, offset, kLgBits, true)) return true; @@ -931,8 +975,21 @@ bool IRrecv::decode(decode_results *results, irparams_t *save, return true; #endif #if DECODE_ARGO - DPRINTLN("Attempting Argo decode"); - if (decodeArgo(results, offset)) return true; + DPRINTLN("Attempting Argo WREM3 decode (AC Control)"); + if (decodeArgoWREM3(results, offset, kArgo3AcControlStateLength * 8, true)) + return true; + DPRINTLN("Attempting Argo WREM3 decode (iFeel report)"); + if (decodeArgoWREM3(results, offset, kArgo3iFeelReportStateLength * 8, true)) + return true; + DPRINTLN("Attempting Argo WREM3 decode (Config)"); + if (decodeArgoWREM3(results, offset, kArgo3ConfigStateLength * 8, true)) + return true; + DPRINTLN("Attempting Argo WREM3 decode (Timer)"); + if (decodeArgoWREM3(results, offset, kArgo3TimerStateLength * 8, true)) + return true; + DPRINTLN("Attempting Argo WREM2 decode"); + if (decodeArgo(results, offset, kArgoBits) || + decodeArgo(results, offset, kArgoShortBits, false)) return true; #endif // DECODE_ARGO #if DECODE_SHARP_AC DPRINTLN("Attempting SHARP_AC decode"); @@ -1140,6 +1197,22 @@ bool IRrecv::decode(decode_results *results, irparams_t *save, DPRINTLN("Attempting Daikin 312-bit decode"); if (decodeDaikin312(results, offset)) return true; #endif // DECODE_DAIKIN312 +#if DECODE_GORENJE + DPRINTLN("Attempting GORENJE decode"); + if (decodeGorenje(results, offset)) return true; +#endif // DECODE_GORENJE +#if DECODE_WOWWEE + DPRINTLN("Attempting WOWWEE decode"); + if (decodeWowwee(results, offset)) return true; +#endif // DECODE_WOWWEE +#if DECODE_CARRIER_AC84 + DPRINTLN("Attempting Carrier A/C 84-bit decode"); + if (decodeCarrierAC84(results, offset)) return true; +#endif // DECODE_CARRIER_AC84 +#if DECODE_YORK + DPRINTLN("Attempting York decode"); + if (decodeYork(results, offset, kYorkBits)) return true; +#endif // DECODE_YORK // Typically new protocols are added above this line. } #if DECODE_HASH @@ -1404,7 +1477,7 @@ bool IRrecv::decodeHash(decode_results *results) { /// @return A match_result_t structure containing the success (or not), the /// data value, and how many buffer entries were used. match_result_t IRrecv::matchData( - volatile uint16_t *data_ptr, const uint16_t nbits, const uint16_t onemark, + atomic_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, const int16_t excess, const bool MSBfirst, const bool expectlastspace) { @@ -1464,7 +1537,7 @@ match_result_t IRrecv::matchData( /// true is Most Significant Bit First Order, false is Least Significant First /// @param[in] expectlastspace Do we expect a space at the end of the message? /// @return If successful, how many buffer entries were used. Otherwise 0. -uint16_t IRrecv::matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr, +uint16_t IRrecv::matchBytes(atomic_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, @@ -1516,7 +1589,7 @@ uint16_t IRrecv::matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr, /// @param[in] MSBfirst Bit order to save the data in. (Def: true) /// true is Most Significant Bit First Order, false is Least Significant First /// @return If successful, how many buffer entries were used. Otherwise 0. -uint16_t IRrecv::_matchGeneric(volatile uint16_t *data_ptr, +uint16_t IRrecv::_matchGeneric(atomic_uint16_t *data_ptr, uint64_t *result_bits_ptr, uint8_t *result_bytes_ptr, const bool use_bits, @@ -1618,7 +1691,7 @@ uint16_t IRrecv::_matchGeneric(volatile uint16_t *data_ptr, /// @param[in] MSBfirst Bit order to save the data in. (Def: true) /// true is Most Significant Bit First Order, false is Least Significant First /// @return If successful, how many buffer entries were used. Otherwise 0. -uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr, +uint16_t IRrecv::matchGeneric(atomic_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -1665,7 +1738,7 @@ uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr, /// @param[in] MSBfirst Bit order to save the data in. (Def: true) /// true is Most Significant Bit First Order, false is Least Significant First /// @return If successful, how many buffer entries were used. Otherwise 0. -uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr, +uint16_t IRrecv::matchGeneric(atomic_uint16_t *data_ptr, uint8_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -1712,7 +1785,7 @@ uint16_t IRrecv::matchGeneric(volatile uint16_t *data_ptr, /// @return If successful, how many buffer entries were used. Otherwise 0. /// @note Parameters one + zero add up to the total time for a bit. /// e.g. mark(one) + space(zero) is a `1`, mark(zero) + space(one) is a `0`. -uint16_t IRrecv::matchGenericConstBitTime(volatile uint16_t *data_ptr, +uint16_t IRrecv::matchGenericConstBitTime(atomic_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -1799,7 +1872,7 @@ uint16_t IRrecv::matchGenericConstBitTime(volatile uint16_t *data_ptr, /// @return If successful, how many buffer entries were used. Otherwise 0. /// @see https://en.wikipedia.org/wiki/Manchester_code /// @see http://ww1.microchip.com/downloads/en/AppNotes/Atmel-9164-Manchester-Coding-Basics_Application-Note.pdf -uint16_t IRrecv::matchManchester(volatile const uint16_t *data_ptr, +uint16_t IRrecv::matchManchester(atomic_const_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -1906,7 +1979,7 @@ uint16_t IRrecv::matchManchester(volatile const uint16_t *data_ptr, /// @see https://en.wikipedia.org/wiki/Manchester_code /// @see http://ww1.microchip.com/downloads/en/AppNotes/Atmel-9164-Manchester-Coding-Basics_Application-Note.pdf /// @todo Clean up and optimise this. It is just "get it working code" atm. -uint16_t IRrecv::matchManchesterData(volatile const uint16_t *data_ptr, +uint16_t IRrecv::matchManchesterData(atomic_const_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -2027,7 +2100,7 @@ uint16_t IRrecv::matchManchesterData(volatile const uint16_t *data_ptr, #if UNIT_TEST /// Unit test helper to get access to the params structure. -volatile irparams_t *IRrecv::_getParamsPtr(void) { +atomic_irparams_t *IRrecv::_getParamsPtr(void) { return ¶ms; } #endif // UNIT_TEST diff --git a/lib/IRremoteESP8266/src/IRrecv.h b/lib/IRremoteESP8266/src/IRrecv.h index 025de52720..c777758cca 100644 --- a/lib/IRremoteESP8266/src/IRrecv.h +++ b/lib/IRremoteESP8266/src/IRrecv.h @@ -86,6 +86,8 @@ typedef struct { uint8_t timeout; // Nr. of milliSeconds before we give up. } irparams_t; +typedef volatile irparams_t atomic_irparams_t; + /// Results from a data match typedef struct { bool success; // Was the match successful? @@ -111,7 +113,7 @@ class decode_results { uint8_t state[kStateSizeMax]; // Multi-byte results. }; uint16_t bits; // Number of bits in decoded value - volatile uint16_t *rawbuf; // Raw intervals in .5 us ticks + atomic_uint16_t *rawbuf; // Raw intervals in .5 us ticks uint16_t rawlen; // Number of records in rawbuf. bool overflow; bool repeat; // Is the result a repeat code? @@ -137,6 +139,7 @@ class IRrecv { uint8_t max_skip = 0, uint16_t noise_floor = 0); void enableIRIn(const bool pullup = false); void disableIRIn(void); + void pause(void); void resume(void); uint16_t getBufSize(void); #if DECODE_HASH @@ -170,11 +173,11 @@ class IRrecv { uint16_t _unknown_threshold; #endif #ifdef UNIT_TEST - volatile irparams_t *_getParamsPtr(void); + atomic_irparams_t *_getParamsPtr(void); #endif // UNIT_TEST // These are called by decode uint8_t _validTolerance(const uint8_t percentage); - void copyIrParams(volatile irparams_t *src, irparams_t *dst); + void copyIrParams(atomic_irparams_t *src, irparams_t *dst); uint16_t compare(const uint16_t oldval, const uint16_t newval); uint32_t ticksLow(const uint32_t usecs, const uint8_t tolerance = kUseDefTol, @@ -185,7 +188,7 @@ class IRrecv { 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, + uint16_t _matchGeneric(atomic_uint16_t *data_ptr, uint64_t *result_bits_ptr, uint8_t *result_ptr, const bool use_bits, @@ -203,14 +206,14 @@ class IRrecv { 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, + match_result_t matchData(atomic_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 = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true, const bool expectlastspace = true); - uint16_t matchBytes(volatile uint16_t *data_ptr, uint8_t *result_ptr, + uint16_t matchBytes(atomic_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, @@ -218,7 +221,7 @@ class IRrecv { const int16_t excess = kMarkExcess, const bool MSBfirst = true, const bool expectlastspace = true); - uint16_t matchGeneric(volatile uint16_t *data_ptr, + uint16_t matchGeneric(atomic_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, const uint16_t hdrmark, const uint32_t hdrspace, @@ -229,7 +232,8 @@ class IRrecv { 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, + uint16_t matchGeneric(atomic_uint16_t *data_ptr, + uint8_t *result_ptr, const uint16_t remaining, const uint16_t nbits, const uint16_t hdrmark, const uint32_t hdrspace, const uint16_t onemark, const uint32_t onespace, @@ -240,7 +244,7 @@ class IRrecv { const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); - uint16_t matchGenericConstBitTime(volatile uint16_t *data_ptr, + uint16_t matchGenericConstBitTime(atomic_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -254,7 +258,7 @@ class IRrecv { const uint8_t tolerance = kUseDefTol, const int16_t excess = kMarkExcess, const bool MSBfirst = true); - uint16_t matchManchesterData(volatile const uint16_t *data_ptr, + uint16_t matchManchesterData(atomic_const_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -264,7 +268,7 @@ class IRrecv { const int16_t excess = kMarkExcess, const bool MSBfirst = true, const bool GEThomas = true); - uint16_t matchManchester(volatile const uint16_t *data_ptr, + uint16_t matchManchester(atomic_const_uint16_t *data_ptr, uint64_t *result_ptr, const uint16_t remaining, const uint16_t nbits, @@ -293,6 +297,9 @@ class IRrecv { #if DECODE_ARGO bool decodeArgo(decode_results *results, uint16_t offset = kStartOffset, const uint16_t nbits = kArgoBits, const bool strict = true); + bool decodeArgoWREM3(decode_results *results, uint16_t offset = kStartOffset, + const uint16_t nbits = kArgo3AcControlStateLength * 8, + const bool strict = true); #endif // DECODE_ARGO #if DECODE_ARRIS bool decodeArris(decode_results *results, uint16_t offset = kStartOffset, @@ -579,6 +586,12 @@ class IRrecv { const uint16_t nbits = kCarrierAc40Bits, const bool strict = true); #endif // DECODE_CARRIER_AC40 +#if DECODE_CARRIER_AC84 + bool decodeCarrierAC84(decode_results *results, + uint16_t offset = kStartOffset, + const uint16_t nbits = kCarrierAc84Bits, + const bool strict = true); +#endif // DECODE_CARRIER_AC84 #if DECODE_CARRIER_AC64 bool decodeCarrierAC64(decode_results *results, uint16_t offset = kStartOffset, @@ -597,6 +610,11 @@ class IRrecv { const uint16_t nbits = kGoodweatherBits, const bool strict = true); #endif // DECODE_GOODWEATHER +#if DECODE_GORENJE + bool decodeGorenje(decode_results *results, uint16_t offset = kStartOffset, + const uint16_t nbits = kGorenjeBits, + const bool strict = true); +#endif // DECODE_GORENJE #if DECODE_GREE bool decodeGree(decode_results *results, uint16_t offset = kStartOffset, const uint16_t nbits = kGreeBits, @@ -856,6 +874,18 @@ class IRrecv { const uint16_t nbits = kBosch144Bits, const bool strict = true); #endif // DECODE_BOSCH144 +#if DECODE_WOWWEE + bool decodeWowwee(decode_results *results, + uint16_t offset = kStartOffset, + const uint16_t nbits = kWowweeBits, + const bool strict = true); +#endif // DECODE_WOWWEE +#if DECODE_YORK + bool decodeYork(decode_results *results, + uint16_t kStartOffset, + const uint16_t kYorkBits, + const bool strict = true); +#endif // DECODE_YORK }; #endif // IRRECV_H_ diff --git a/lib/IRremoteESP8266/src/IRremoteESP8266.h b/lib/IRremoteESP8266/src/IRremoteESP8266.h index 2005c96cd8..b1140f2591 100644 --- a/lib/IRremoteESP8266/src/IRremoteESP8266.h +++ b/lib/IRremoteESP8266/src/IRremoteESP8266.h @@ -51,6 +51,16 @@ #include #include #endif // UNIT_TEST +#if __cplusplus >= 202002L +#include +typedef std::atomic< bool > atomic_bool; +typedef std::atomic atomic_uint32_t; +#else +typedef volatile bool atomic_bool; +typedef volatile uint32_t atomic_uint32_t; +#endif +typedef volatile uint16_t atomic_uint16_t; +typedef volatile const uint16_t atomic_const_uint16_t; // Library Version Information // Major version number (X.x.x) @@ -58,7 +68,7 @@ // Minor version number (x.X.x) #define _IRREMOTEESP8266_VERSION_MINOR 8 // Patch version number (x.x.X) -#define _IRREMOTEESP8266_VERSION_PATCH 2 +#define _IRREMOTEESP8266_VERSION_PATCH 6 // Macro to convert version info into an integer #define _IRREMOTEESP8266_VERSION_VAL(major, minor, patch) \ (((major) << 16) | ((minor) << 8) | (patch)) @@ -924,6 +934,34 @@ #define SEND_DAIKIN312 _IR_ENABLE_DEFAULT_ #endif // SEND_DAIKIN312 +#ifndef DECODE_GORENJE +#define DECODE_GORENJE _IR_ENABLE_DEFAULT_ +#endif // DECODE_GORENJE +#ifndef SEND_GORENJE +#define SEND_GORENJE _IR_ENABLE_DEFAULT_ +#endif // SEND_GORENJE + +#ifndef DECODE_WOWWEE +#define DECODE_WOWWEE _IR_ENABLE_DEFAULT_ +#endif // DECODE_WOWWEE +#ifndef SEND_WOWWEE +#define SEND_WOWWEE _IR_ENABLE_DEFAULT_ +#endif // SEND_WOWWEE + +#ifndef DECODE_CARRIER_AC84 +#define DECODE_CARRIER_AC84 _IR_ENABLE_DEFAULT_ +#endif // DECODE_CARRIER_AC84 +#ifndef SEND_CARRIER_AC84 +#define SEND_CARRIER_AC84 _IR_ENABLE_DEFAULT_ +#endif // SEND_CARRIER_AC84 + +#ifndef DECODE_YORK +#define DECODE_YORK _IR_ENABLE_DEFAULT_ +#endif // DECODE_YORK +#ifndef SEND_YORK +#define SEND_YORK _IR_ENABLE_DEFAULT_ +#endif // SEND_YORK + #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 || \ @@ -942,6 +980,7 @@ DECODE_KELON168 || DECODE_HITACHI_AC296 || DECODE_CARRIER_AC128 || \ DECODE_DAIKIN200 || DECODE_HAIER_AC160 || DECODE_TCL96AC || \ DECODE_BOSCH144 || DECODE_SANYO_AC152 || DECODE_DAIKIN312 || \ + DECODE_CARRIER_AC84 || DECODE_YORK || \ false) // Add any DECODE to the above if it uses result->state (see kStateSizeMax) // you might also want to add the protocol to hasACState function @@ -1104,8 +1143,12 @@ enum decode_type_t { BOSCH144, // 120 SANYO_AC152, DAIKIN312, + GORENJE, + WOWWEE, + CARRIER_AC84, // 125 + YORK, // Add new entries before this one, and update it to point to the last entry. - kLastDecodeType = DAIKIN312, + kLastDecodeType = YORK, }; // Message lengths & required repeat values @@ -1123,7 +1166,13 @@ const uint16_t kAmcorStateLength = 8; const uint16_t kAmcorBits = kAmcorStateLength * 8; const uint16_t kAmcorDefaultRepeat = kSingleRepeat; const uint16_t kArgoStateLength = 12; +const uint16_t kArgoShortStateLength = 4; const uint16_t kArgoBits = kArgoStateLength * 8; +const uint16_t kArgoShortBits = kArgoShortStateLength * 8; +const uint16_t kArgo3AcControlStateLength = 6; // Bytes +const uint16_t kArgo3iFeelReportStateLength = 2; // Bytes +const uint16_t kArgo3TimerStateLength = 9; // Bytes +const uint16_t kArgo3ConfigStateLength = 4; // Bytes const uint16_t kArgoDefaultRepeat = kNoRepeat; const uint16_t kArrisBits = 32; const uint16_t kBosch144StateLength = 18; @@ -1137,6 +1186,9 @@ const uint16_t kCarrierAc40Bits = 40; const uint16_t kCarrierAc40MinRepeat = 2; const uint16_t kCarrierAc64Bits = 64; const uint16_t kCarrierAc64MinRepeat = kNoRepeat; +const uint16_t kCarrierAc84StateLength = 11; +const uint16_t kCarrierAc84Bits = kCarrierAc84StateLength * 8 - 4; +const uint16_t kCarrierAc84MinRepeat = kNoRepeat; const uint16_t kCarrierAc128StateLength = 16; const uint16_t kCarrierAc128Bits = kCarrierAc128StateLength * 8; const uint16_t kCarrierAc128MinRepeat = kNoRepeat; @@ -1203,6 +1255,7 @@ const uint16_t kGicableBits = 16; const uint16_t kGicableMinRepeat = kSingleRepeat; const uint16_t kGoodweatherBits = 48; const uint16_t kGoodweatherMinRepeat = kNoRepeat; +const uint16_t kGorenjeBits = 8; const uint16_t kGreeStateLength = 8; const uint16_t kGreeBits = kGreeStateLength * 8; const uint16_t kGreeDefaultRepeat = kNoRepeat; @@ -1292,6 +1345,8 @@ const uint16_t kNeoclimaBits = kNeoclimaStateLength * 8; const uint16_t kNeoclimaMinRepeat = kNoRepeat; const uint16_t kPanasonicBits = 48; const uint32_t kPanasonicManufacturer = 0x4004; +const uint32_t kPanasonic40Manufacturer = 0x34; +const uint16_t kPanasonic40Bits = 40; const uint16_t kPanasonicAcStateLength = 27; const uint16_t kPanasonicAcStateShortLength = 16; const uint16_t kPanasonicAcBits = kPanasonicAcStateLength * 8; @@ -1372,6 +1427,8 @@ const uint16_t kWhirlpoolAcStateLength = 21; const uint16_t kWhirlpoolAcBits = kWhirlpoolAcStateLength * 8; const uint16_t kWhirlpoolAcDefaultRepeat = kNoRepeat; const uint16_t kWhynterBits = 32; +const uint16_t kWowweeBits = 11; +const uint16_t kWowweeDefaultRepeat = kNoRepeat; const uint8_t kVestelAcBits = 56; const uint16_t kXmpBits = 64; const uint16_t kZepealBits = 16; @@ -1386,6 +1443,8 @@ const uint16_t kRhossStateLength = 12; const uint16_t kRhossBits = kRhossStateLength * 8; const uint16_t kRhossDefaultRepeat = 0; const uint16_t kClimaButlerBits = 52; +const uint16_t kYorkBits = 136; +const uint16_t kYorkStateLength = 17; // Legacy defines. (Deprecated) diff --git a/lib/IRremoteESP8266/src/IRsend.cpp b/lib/IRremoteESP8266/src/IRsend.cpp index 1fb1339c56..10e440b325 100644 --- a/lib/IRremoteESP8266/src/IRsend.cpp +++ b/lib/IRremoteESP8266/src/IRsend.cpp @@ -603,7 +603,10 @@ uint16_t IRsend::minRepeats(const decode_type_t protocol) { uint16_t IRsend::defaultBits(const decode_type_t protocol) { switch (protocol) { case MULTIBRACKETS: + case GORENJE: return 8; + case WOWWEE: + return 11; case RC5: case SYMPHONY: return 12; @@ -690,6 +693,8 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) { return kBosch144Bits; case CORONA_AC: return kCoronaAcBits; + case CARRIER_AC84: + return kCarrierAc84Bits; case CARRIER_AC128: return kCarrierAc128Bits; case DAIKIN: @@ -791,6 +796,8 @@ uint16_t IRsend::defaultBits(const decode_type_t protocol) { return kWhirlpoolAcBits; case XMP: return kXmpBits; + case YORK: + return kYorkBits; // No default amount of bits. case FUJITSU_AC: case MWM: @@ -916,6 +923,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data, sendGoodweather(data, nbits, min_repeat); break; #endif +#if SEND_GORENJE + case GORENJE: + sendGorenje(data, nbits, min_repeat); + break; +#endif #if SEND_GREE case GREE: sendGree(data, nbits, min_repeat); @@ -1114,6 +1126,11 @@ bool IRsend::send(const decode_type_t type, const uint64_t data, sendWhynter(data, nbits, min_repeat); break; #endif +#if SEND_WOWWEE + case WOWWEE: + sendWowwee(data, nbits, min_repeat); + break; +#endif // SEND_WOWWEE #if SEND_XMP case XMP: sendXmp(data, nbits, min_repeat); @@ -1159,6 +1176,11 @@ bool IRsend::send(const decode_type_t type, const uint8_t *state, sendBosch144(state, nbytes); break; #endif // SEND_BOSCH144 +#if SEND_CARRIER_AC84 + case CARRIER_AC84: + sendCarrierAC84(state, nbytes); + break; +#endif // SEND_CARRIER_AC84 #if SEND_CARRIER_AC128 case CARRIER_AC128: sendCarrierAC128(state, nbytes); @@ -1407,6 +1429,11 @@ bool IRsend::send(const decode_type_t type, const uint8_t *state, sendWhirlpoolAC(state, nbytes); break; #endif // SEND_WHIRLPOOL_AC +#if SEND_YORK + case YORK: + sendYork(state, nbytes); + break; +#endif // SEND_YORK default: return false; } diff --git a/lib/IRremoteESP8266/src/IRsend.h b/lib/IRremoteESP8266/src/IRsend.h index 02f2c939ea..38491372aa 100644 --- a/lib/IRremoteESP8266/src/IRsend.h +++ b/lib/IRremoteESP8266/src/IRsend.h @@ -39,6 +39,9 @@ const uint8_t kDutyMax = 100; // Percentage const uint16_t kMaxAccurateUsecDelay = 16383; // Usecs to wait between messages we don't know the proper gap time. const uint32_t kDefaultMessageGap = 100000; +/// Placeholder for missing sensor temp value +/// @note Not using "-1" as it may be a valid external temp +const float kNoTempValue = -100.0; /// Enumerators and Structures for the Common A/C API. namespace stdAc { @@ -56,14 +59,15 @@ enum class opmode_t { /// Common A/C settings for Fan Speeds. enum class fanspeed_t { - kAuto = 0, - kMin = 1, - kLow = 2, - kMedium = 3, - kHigh = 4, - kMax = 5, + kAuto = 0, + kMin = 1, + kLow = 2, + kMedium = 3, + kHigh = 4, + kMax = 5, + kMediumHigh = 6, // Add new entries before this one, and update it to point to the last entry - kLastFanspeedEnum = kMax, + kLastFanspeedEnum = kMediumHigh, }; /// Common A/C settings for Vertical Swing. @@ -75,8 +79,21 @@ enum class swingv_t { kMiddle = 3, kLow = 4, kLowest = 5, + kUpperMiddle = 6, // Add new entries before this one, and update it to point to the last entry - kLastSwingvEnum = kLowest, + kLastSwingvEnum = kUpperMiddle, +}; + +/// @brief Tyoe of A/C command (if the remote uses different codes for each) +/// @note Most remotes support only a single command or aggregate multiple +/// into one (e.g. control+timer). Use @c kControlCommand in such case +enum class ac_command_t { + kControlCommand = 0, + kSensorTempReport = 1, + kTimerCommand = 2, + kConfigCommand = 3, + // Add new entries before this one, and update it to point to the last entry + kLastAcCommandEnum = kConfigCommand, }; /// Common A/C settings for Horizontal Swing. @@ -113,6 +130,9 @@ struct state_t { bool beep = false; int16_t sleep = -1; // `-1` means off. int16_t clock = -1; // `-1` means not set. + stdAc::ac_command_t command = stdAc::ac_command_t::kControlCommand; + bool iFeel = false; + float sensorTemperature = kNoTempValue; // `kNoTempValue` means not set. }; }; // namespace stdAc @@ -202,6 +222,11 @@ enum lg_ac_remote_model_t { LG6711A20083V, // (5) Same as GE6711AR2853M, but only SwingV toggle. }; +/// Argo A/C model numbers +enum argo_ac_remote_model_t { + SAC_WREM2 = 1, // (1) ARGO WREM2 remote (default) + SAC_WREM3 // (2) ARGO WREM3 remote (touch buttons), bit-len vary by cmd +}; // Classes @@ -285,11 +310,12 @@ class IRsend { void sendSherwood(uint64_t data, uint16_t nbits = kSherwoodBits, uint16_t repeat = kSherwoodMinRepeat); #endif -#if SEND_SAMSUNG + // `sendSAMSUNG()` is required by `sendLG()` +#if (SEND_SAMSUNG || SEND_LG) void sendSAMSUNG(const uint64_t data, const uint16_t nbits = kSamsungBits, const uint16_t repeat = kNoRepeat); uint32_t encodeSAMSUNG(const uint8_t customer, const uint8_t command); -#endif +#endif // (SEND_SAMSUNG || SEND_LG) #if SEND_SAMSUNG36 void sendSamsung36(const uint64_t data, const uint16_t nbits = kSamsung36Bits, const uint16_t repeat = kNoRepeat); @@ -519,14 +545,22 @@ class IRsend { const uint16_t nbits = kGoodweatherBits, const uint16_t repeat = kGoodweatherMinRepeat); #endif // SEND_GOODWEATHER +#if SEND_GORENJE + void sendGorenje(const uint64_t data, const uint16_t nbits = kGorenjeBits, + const uint16_t repeat = kNoRepeat); +#endif // SEND_GORENJE #if SEND_PRONTO void sendPronto(uint16_t data[], uint16_t len, uint16_t repeat = kNoRepeat); #endif #if SEND_ARGO void sendArgo(const unsigned char data[], + const uint16_t nbytes = kArgoStateLength, + const uint16_t repeat = kArgoDefaultRepeat, + bool sendFooter = false); + void sendArgoWREM3(const unsigned char data[], const uint16_t nbytes = kArgoStateLength, const uint16_t repeat = kArgoDefaultRepeat); -#endif +#endif // SEND_ARGO #if SEND_TROTEC void sendTrotec(const unsigned char data[], const uint16_t nbytes = kTrotecStateLength, @@ -575,6 +609,11 @@ class IRsend { void sendCarrierAC64(uint64_t data, uint16_t nbits = kCarrierAc64Bits, uint16_t repeat = kCarrierAc64MinRepeat); #endif +#if SEND_CARRIER_AC84 + void sendCarrierAC84(const uint8_t data[], + const uint16_t nbytes = kCarrierAc84StateLength, + const uint16_t repeat = kNoRepeat); +#endif // SEND_CARRIER_AC84 #if SEND_CARRIER_AC128 void sendCarrierAC128(const uint8_t data[], uint16_t nbytes = kCarrierAc128StateLength, @@ -837,6 +876,15 @@ class IRsend { const uint16_t nbytes = kBosch144StateLength, const uint16_t repeat = kNoRepeat); #endif // SEND_BOSCH144 +#if SEND_WOWWEE + void sendWowwee(const uint64_t data, const uint16_t nbits = kWowweeBits, + const uint16_t repeat = kWowweeDefaultRepeat); +#endif // SEND_WOWWEE +#if SEND_YORK + void sendYork(const unsigned char data[], + const uint16_t nbytes = kYorkStateLength, + const uint16_t repeat = kNoRepeat); +#endif // SEND_YORK protected: #ifdef UNIT_TEST diff --git a/lib/IRremoteESP8266/src/IRtext.cpp b/lib/IRremoteESP8266/src/IRtext.cpp index ab588d77b9..84727daf96 100644 --- a/lib/IRremoteESP8266/src/IRtext.cpp +++ b/lib/IRremoteESP8266/src/IRtext.cpp @@ -66,10 +66,13 @@ IRTEXT_CONST_STRING(kOffTimerStr, D_STR_OFFTIMER); ///< "Off Timer" IRTEXT_CONST_STRING(kTimerModeStr, D_STR_TIMERMODE); ///< "Timer Mode" IRTEXT_CONST_STRING(kClockStr, D_STR_CLOCK); ///< "Clock" IRTEXT_CONST_STRING(kCommandStr, D_STR_COMMAND); ///< "Command" +IRTEXT_CONST_STRING(kConfigCommandStr, D_STR_CONFIG); ///< "Config" +IRTEXT_CONST_STRING(kControlCommandStr, D_STR_CONTROL); ///< "Control" IRTEXT_CONST_STRING(kXFanStr, D_STR_XFAN); ///< "XFan" IRTEXT_CONST_STRING(kHealthStr, D_STR_HEALTH); ///< "Health" IRTEXT_CONST_STRING(kModelStr, D_STR_MODEL); ///< "Model" IRTEXT_CONST_STRING(kTempStr, D_STR_TEMP); ///< "Temp" +IRTEXT_CONST_STRING(kIFeelReportStr, D_STR_IFEELREPORT); ///< "IFeel Report" IRTEXT_CONST_STRING(kIFeelStr, D_STR_IFEEL); ///< "IFeel" IRTEXT_CONST_STRING(kHumidStr, D_STR_HUMID); ///< "Humid" IRTEXT_CONST_STRING(kSaveStr, D_STR_SAVE); ///< "Save" @@ -121,6 +124,7 @@ IRTEXT_CONST_STRING(kOutsideStr, D_STR_OUTSIDE); ///< "Outside" IRTEXT_CONST_STRING(kLoudStr, D_STR_LOUD); ///< "Loud" IRTEXT_CONST_STRING(kLowerStr, D_STR_LOWER); ///< "Lower" IRTEXT_CONST_STRING(kUpperStr, D_STR_UPPER); ///< "Upper" +IRTEXT_CONST_STRING(kUpperMiddleStr, D_STR_UPPER_MIDDLE); ///< "Upper-Middle" IRTEXT_CONST_STRING(kBreezeStr, D_STR_BREEZE); ///< "Breeze" IRTEXT_CONST_STRING(kCirculateStr, D_STR_CIRCULATE); ///< "Circulate" IRTEXT_CONST_STRING(kCeilingStr, D_STR_CEILING); ///< "Ceiling" @@ -158,6 +162,7 @@ IRTEXT_CONST_STRING(kMaxStr, D_STR_MAX); ///< "Max" IRTEXT_CONST_STRING(kMaximumStr, D_STR_MAXIMUM); ///< "Maximum" IRTEXT_CONST_STRING(kMinStr, D_STR_MIN); ///< "Min" IRTEXT_CONST_STRING(kMinimumStr, D_STR_MINIMUM); ///< "Minimum" +IRTEXT_CONST_STRING(kMedHighStr, D_STR_MED_HIGH); ///< "Med-high" IRTEXT_CONST_STRING(kMedStr, D_STR_MED); ///< "Med" IRTEXT_CONST_STRING(kMediumStr, D_STR_MEDIUM); ///< "Medium" @@ -203,6 +208,13 @@ IRTEXT_CONST_STRING(kSwingVModeStr, D_STR_SWINGVMODE); ///< "Swing(V) Mode" IRTEXT_CONST_STRING(kSwingVToggleStr, D_STR_SWINGVTOGGLE); ///< ///< "Swing(V) Toggle" IRTEXT_CONST_STRING(kTurboToggleStr, D_STR_TURBOTOGGLE); ///< "Turbo Toggle" +IRTEXT_CONST_STRING(kSetTimerCommandStr, D_STR_SET_TIMER); ///< "Set Timer" +IRTEXT_CONST_STRING(kScheduleStr, D_STR_SCHEDULE); ///< "Schedule" +IRTEXT_CONST_STRING(kChStr, D_STR_CH); ///< "CH#" +IRTEXT_CONST_STRING(kTimerActiveDaysStr, D_STR_TIMER_ACTIVE_DAYS); +///< "TimerActiveDays" +IRTEXT_CONST_STRING(kKeyStr, D_STR_KEY); ///< "Key" +IRTEXT_CONST_STRING(kValueStr, D_STR_VALUE); ///< "Value" // Separators & Punctuation const char kTimeSep = D_CHR_TIME_SEP; ///< ':' @@ -279,6 +291,8 @@ IRTEXT_CONST_STRING(k122lzfStr, D_STR_122LZF); ///< "122LZF" IRTEXT_CONST_STRING(kDg11j13aStr, D_STR_DG11J13A); ///< "DG11J13A" IRTEXT_CONST_STRING(kDg11j104Str, D_STR_DG11J104); ///< "DG11J104" IRTEXT_CONST_STRING(kDg11j191Str, D_STR_DG11J191); ///< "DG11J191" +IRTEXT_CONST_STRING(kArgoWrem2Str, D_STR_ARGO_WREM2); ///< "WREM3" +IRTEXT_CONST_STRING(kArgoWrem3Str, D_STR_ARGO_WREM3); ///< "WREM3" #define D_STR_UNSUPPORTED "?" // Unsupported protocols will be showing as // a question mark, check for length > 1 @@ -897,6 +911,26 @@ IRTEXT_CONST_BLOB_DECL(kAllProtocolNamesStr) { #else D_STR_UNSUPPORTED "\x0" #endif // if DECODE_DAIKIN312 || SEND_DAIKIN312 + #if DECODE_GORENJE || SEND_GORENJE + D_STR_GORENJE "\x0" + #else + D_STR_UNSUPPORTED "\x0" + #endif // if DECODE_GORENJE || SEND_GORENJE + #if DECODE_WOWWEE || SEND_WOWWEE + D_STR_WOWWEE "\x0" + #else + D_STR_UNSUPPORTED "\x0" + #endif // if DECODE_WOWWEE || SEND_WOWWEE + #if DECODE_CARRIER_AC84 || SEND_CARRIER_AC84 + D_STR_CARRIER_AC84 "\x0" + #else + D_STR_UNSUPPORTED "\x0" + #endif // if DECODE_CARRIER_AC84 || SEND_CARRIER_AC84 + #if DECODE_YORK || SEND_YORK + D_STR_YORK "\x0" + #else + D_STR_UNSUPPORTED "\x0" + #endif // if DECODE_YORK || SEND_YORK ///< New protocol strings should be added just above this line. "\x0" ///< This string requires double null termination. }; diff --git a/lib/IRremoteESP8266/src/IRtext.h b/lib/IRremoteESP8266/src/IRtext.h index c212337618..15d2690b7a 100644 --- a/lib/IRremoteESP8266/src/IRtext.h +++ b/lib/IRremoteESP8266/src/IRtext.h @@ -39,13 +39,15 @@ extern IRTEXT_CONST_PTR(kAkb73757604Str); extern IRTEXT_CONST_PTR(kAkb74955603Str); extern IRTEXT_CONST_PTR(kAkb75215403Str); extern IRTEXT_CONST_PTR(kArdb1Str); +extern IRTEXT_CONST_PTR(kArgoWrem2Str); +extern IRTEXT_CONST_PTR(kArgoWrem3Str); extern IRTEXT_CONST_PTR(kArjw2Str); extern IRTEXT_CONST_PTR(kArrah2eStr); extern IRTEXT_CONST_PTR(kArreb1eStr); extern IRTEXT_CONST_PTR(kArrew4eStr); extern IRTEXT_CONST_PTR(kArry4Str); -extern IRTEXT_CONST_PTR(kAutomaticStr); extern IRTEXT_CONST_PTR(kAutoStr); +extern IRTEXT_CONST_PTR(kAutomaticStr); extern IRTEXT_CONST_PTR(kBeepStr); extern IRTEXT_CONST_PTR(kBitsStr); extern IRTEXT_CONST_PTR(kBottomStr); @@ -57,6 +59,7 @@ extern IRTEXT_CONST_PTR(kCelsiusFahrenheitStr); extern IRTEXT_CONST_PTR(kCelsiusStr); extern IRTEXT_CONST_PTR(kCentreStr); extern IRTEXT_CONST_PTR(kChangeStr); +extern IRTEXT_CONST_PTR(kChStr); extern IRTEXT_CONST_PTR(kCirculateStr); extern IRTEXT_CONST_PTR(kCkpStr); extern IRTEXT_CONST_PTR(kCleanStr); @@ -64,13 +67,15 @@ extern IRTEXT_CONST_PTR(kClockStr); extern IRTEXT_CONST_PTR(kCodeStr); extern IRTEXT_CONST_PTR(kColonSpaceStr); extern IRTEXT_CONST_PTR(kComfortStr); -extern IRTEXT_CONST_PTR(kCommandStr); extern IRTEXT_CONST_PTR(kCommaSpaceStr); -extern IRTEXT_CONST_PTR(kCoolingStr); +extern IRTEXT_CONST_PTR(kCommandStr); +extern IRTEXT_CONST_PTR(kConfigCommandStr); +extern IRTEXT_CONST_PTR(kControlCommandStr); extern IRTEXT_CONST_PTR(kCoolStr); +extern IRTEXT_CONST_PTR(kCoolingStr); extern IRTEXT_CONST_PTR(kDashStr); -extern IRTEXT_CONST_PTR(kDaysStr); extern IRTEXT_CONST_PTR(kDayStr); +extern IRTEXT_CONST_PTR(kDaysStr); extern IRTEXT_CONST_PTR(kDehumidifyStr); extern IRTEXT_CONST_PTR(kDg11j104Str); extern IRTEXT_CONST_PTR(kDg11j13aStr); @@ -80,18 +85,18 @@ extern IRTEXT_CONST_PTR(kDirectStr); extern IRTEXT_CONST_PTR(kDisplayTempStr); extern IRTEXT_CONST_PTR(kDkeStr); extern IRTEXT_CONST_PTR(kDownStr); -extern IRTEXT_CONST_PTR(kDryingStr); extern IRTEXT_CONST_PTR(kDryStr); +extern IRTEXT_CONST_PTR(kDryingStr); extern IRTEXT_CONST_PTR(kEconoStr); extern IRTEXT_CONST_PTR(kEconoToggleStr); extern IRTEXT_CONST_PTR(kEyeAutoStr); extern IRTEXT_CONST_PTR(kEyeStr); extern IRTEXT_CONST_PTR(kFalseStr); extern IRTEXT_CONST_PTR(kFanOnlyNoSpaceStr); -extern IRTEXT_CONST_PTR(kFan_OnlyStr); extern IRTEXT_CONST_PTR(kFanOnlyStr); extern IRTEXT_CONST_PTR(kFanOnlyWithSpaceStr); extern IRTEXT_CONST_PTR(kFanStr); +extern IRTEXT_CONST_PTR(kFan_OnlyStr); extern IRTEXT_CONST_PTR(kFastStr); extern IRTEXT_CONST_PTR(kFilterStr); extern IRTEXT_CONST_PTR(kFixedStr); @@ -100,22 +105,24 @@ extern IRTEXT_CONST_PTR(kFreshStr); extern IRTEXT_CONST_PTR(kGe6711ar2853mStr); extern IRTEXT_CONST_PTR(kGz055be1Str); extern IRTEXT_CONST_PTR(kHealthStr); -extern IRTEXT_CONST_PTR(kHeatingStr); extern IRTEXT_CONST_PTR(kHeatStr); -extern IRTEXT_CONST_PTR(kHighestStr); -extern IRTEXT_CONST_PTR(kHighStr); +extern IRTEXT_CONST_PTR(kHeatingStr); extern IRTEXT_CONST_PTR(kHiStr); +extern IRTEXT_CONST_PTR(kHighStr); +extern IRTEXT_CONST_PTR(kHighestStr); extern IRTEXT_CONST_PTR(kHoldStr); -extern IRTEXT_CONST_PTR(kHoursStr); extern IRTEXT_CONST_PTR(kHourStr); +extern IRTEXT_CONST_PTR(kHoursStr); extern IRTEXT_CONST_PTR(kHumidStr); -extern IRTEXT_CONST_PTR(kIdStr); +extern IRTEXT_CONST_PTR(kIFeelReportStr); extern IRTEXT_CONST_PTR(kIFeelStr); +extern IRTEXT_CONST_PTR(kISeeStr); +extern IRTEXT_CONST_PTR(kIdStr); extern IRTEXT_CONST_PTR(kIndirectStr); extern IRTEXT_CONST_PTR(kInsideStr); extern IRTEXT_CONST_PTR(kIonStr); -extern IRTEXT_CONST_PTR(kISeeStr); extern IRTEXT_CONST_PTR(kJkeStr); +extern IRTEXT_CONST_PTR(kKeyStr); extern IRTEXT_CONST_PTR(kKkg29ac1Str); extern IRTEXT_CONST_PTR(kKkg9ac1Str); extern IRTEXT_CONST_PTR(kLastStr); @@ -126,29 +133,30 @@ extern IRTEXT_CONST_PTR(kLg6711a20083vStr); extern IRTEXT_CONST_PTR(kLightStr); extern IRTEXT_CONST_PTR(kLightToggleStr); extern IRTEXT_CONST_PTR(kLkeStr); -extern IRTEXT_CONST_PTR(kLockStr); extern IRTEXT_CONST_PTR(kLoStr); +extern IRTEXT_CONST_PTR(kLockStr); extern IRTEXT_CONST_PTR(kLoudStr); +extern IRTEXT_CONST_PTR(kLowStr); extern IRTEXT_CONST_PTR(kLowerStr); extern IRTEXT_CONST_PTR(kLowestStr); -extern IRTEXT_CONST_PTR(kLowStr); extern IRTEXT_CONST_PTR(kManualStr); -extern IRTEXT_CONST_PTR(kMaximumStr); extern IRTEXT_CONST_PTR(kMaxLeftNoSpaceStr); extern IRTEXT_CONST_PTR(kMaxLeftStr); extern IRTEXT_CONST_PTR(kMaxRightNoSpaceStr); extern IRTEXT_CONST_PTR(kMaxRightStr); extern IRTEXT_CONST_PTR(kMaxStr); -extern IRTEXT_CONST_PTR(kMediumStr); +extern IRTEXT_CONST_PTR(kMaximumStr); +extern IRTEXT_CONST_PTR(kMedHighStr); extern IRTEXT_CONST_PTR(kMedStr); -extern IRTEXT_CONST_PTR(kMiddleStr); +extern IRTEXT_CONST_PTR(kMediumStr); extern IRTEXT_CONST_PTR(kMidStr); -extern IRTEXT_CONST_PTR(kMinimumStr); +extern IRTEXT_CONST_PTR(kMiddleStr); extern IRTEXT_CONST_PTR(kMinStr); -extern IRTEXT_CONST_PTR(kMinutesStr); +extern IRTEXT_CONST_PTR(kMinimumStr); extern IRTEXT_CONST_PTR(kMinuteStr); -extern IRTEXT_CONST_PTR(kModelStr); +extern IRTEXT_CONST_PTR(kMinutesStr); extern IRTEXT_CONST_PTR(kModeStr); +extern IRTEXT_CONST_PTR(kModelStr); extern IRTEXT_CONST_PTR(kMouldStr); extern IRTEXT_CONST_PTR(kMoveStr); extern IRTEXT_CONST_PTR(kNAStr); @@ -171,9 +179,9 @@ extern IRTEXT_CONST_PTR(kPanasonicPkrStr); extern IRTEXT_CONST_PTR(kPanasonicRkrStr); extern IRTEXT_CONST_PTR(kPkrStr); extern IRTEXT_CONST_PTR(kPowerButtonStr); -extern IRTEXT_CONST_PTR(kPowerfulStr); extern IRTEXT_CONST_PTR(kPowerStr); extern IRTEXT_CONST_PTR(kPowerToggleStr); +extern IRTEXT_CONST_PTR(kPowerfulStr); extern IRTEXT_CONST_PTR(kPreviousPowerStr); extern IRTEXT_CONST_PTR(kProtocolStr); extern IRTEXT_CONST_PTR(kPurifyStr); @@ -188,8 +196,10 @@ extern IRTEXT_CONST_PTR(kRlt0541htaaStr); extern IRTEXT_CONST_PTR(kRlt0541htabStr); extern IRTEXT_CONST_PTR(kRoomStr); extern IRTEXT_CONST_PTR(kSaveStr); -extern IRTEXT_CONST_PTR(kSecondsStr); +extern IRTEXT_CONST_PTR(kScheduleStr); extern IRTEXT_CONST_PTR(kSecondStr); +extern IRTEXT_CONST_PTR(kSecondsStr); +extern IRTEXT_CONST_PTR(kSensorReportStr); extern IRTEXT_CONST_PTR(kSensorStr); extern IRTEXT_CONST_PTR(kSensorTempStr); extern IRTEXT_CONST_PTR(kSetStr); @@ -213,7 +223,9 @@ extern IRTEXT_CONST_PTR(kTempDownStr); extern IRTEXT_CONST_PTR(kTempStr); extern IRTEXT_CONST_PTR(kTempUpStr); extern IRTEXT_CONST_PTR(kThreeLetterDayOfWeekStr); +extern IRTEXT_CONST_PTR(kTimerActiveDaysStr); extern IRTEXT_CONST_PTR(kTimerModeStr); +extern IRTEXT_CONST_PTR(kSetTimerCommandStr); extern IRTEXT_CONST_PTR(kTimerStr); extern IRTEXT_CONST_PTR(kToggleStr); extern IRTEXT_CONST_PTR(kTopStr); @@ -222,8 +234,10 @@ extern IRTEXT_CONST_PTR(kTurboStr); extern IRTEXT_CONST_PTR(kTurboToggleStr); extern IRTEXT_CONST_PTR(kTypeStr); extern IRTEXT_CONST_PTR(kUnknownStr); -extern IRTEXT_CONST_PTR(kUpperStr); extern IRTEXT_CONST_PTR(kUpStr); +extern IRTEXT_CONST_PTR(kUpperStr); +extern IRTEXT_CONST_PTR(kUpperMiddleStr); +extern IRTEXT_CONST_PTR(kValueStr); extern IRTEXT_CONST_PTR(kV9014557AStr); extern IRTEXT_CONST_PTR(kV9014557BStr); extern IRTEXT_CONST_PTR(kVaneStr); diff --git a/lib/IRremoteESP8266/src/IRutils.cpp b/lib/IRremoteESP8266/src/IRutils.cpp index 7c59228c01..8f19b2922a 100644 --- a/lib/IRremoteESP8266/src/IRutils.cpp +++ b/lib/IRremoteESP8266/src/IRutils.cpp @@ -6,6 +6,7 @@ #endif #define __STDC_LIMIT_MACROS +#include #include #include #include @@ -173,6 +174,7 @@ bool hasACState(const decode_type_t protocol) { case AMCOR: case ARGO: case BOSCH144: + case CARRIER_AC84: case CARRIER_AC128: case CORONA_AC: case DAIKIN: @@ -224,6 +226,7 @@ bool hasACState(const decode_type_t protocol) { case TROTEC_3550: case VOLTAS: case WHIRLPOOL_AC: + case YORK: return true; default: return false; @@ -304,7 +307,7 @@ String resultToSourceCode(const decode_results * const results) { if (results->decode_type != UNKNOWN) { if (hasState) { #if DECODE_AC - uint16_t nbytes = results->bits / 8; + uint16_t nbytes = ceil(static_cast(results->bits) / 8.0); output += F("uint8_t state["); output += uint64ToString(nbytes); output += F("] = {"); @@ -695,6 +698,13 @@ namespace irutils { default: return kUnknownStr; } break; + case decode_type_t::ARGO: + switch (model) { + case argo_ac_remote_model_t::SAC_WREM2: return kArgoWrem2Str; + case argo_ac_remote_model_t::SAC_WREM3: return kArgoWrem3Str; + default: return kUnknownStr; + } + break; default: return kUnknownStr; } } @@ -722,10 +732,12 @@ namespace irutils { /// @param[in] celsius Is the temp Celsius or Fahrenheit. /// true is C, false is F /// @param[in] precomma Should the output string start with ", " or not? + /// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? /// @return The resulting String. String addTempToString(const uint16_t degrees, const bool celsius, - const bool precomma) { - String result = addIntToString(degrees, kTempStr, precomma); + const bool precomma, const bool isSensorTemp) { + String result = addIntToString(degrees, (isSensorTemp)? + kSensorTempStr : kTempStr, precomma); result += celsius ? 'C' : 'F'; return result; } @@ -736,12 +748,14 @@ namespace irutils { /// @param[in] celsius Is the temp Celsius or Fahrenheit. /// true is C, false is F /// @param[in] precomma Should the output string start with ", " or not? + /// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? /// @return The resulting String. String addTempFloatToString(const float degrees, const bool celsius, - const bool precomma) { + const bool precomma, const bool isSensorTemp) { String result = ""; - result.reserve(14); // Assuming ", Temp: XXX.5F" is the largest. - result += addIntToString(degrees, kTempStr, precomma); + result.reserve(21); // Assuming ", Sensor Temp: XXX.5F" is the largest. + result += addIntToString(degrees, (isSensorTemp)? + kSensorTempStr : kTempStr, precomma); // Is it a half degree? if (((uint16_t)(2 * degrees)) & 1) result += F(".5"); result += celsius ? 'C' : 'F'; @@ -788,33 +802,46 @@ namespace irutils { result.reserve(19); // ", Day: N (UNKNOWN)" result += addIntToString(day_of_week, kDayStr, precomma); result += kSpaceLBraceStr; + result += dayToString(day_of_week, offset); + return result + ')'; + } + + /// Create a String of the 3-letter day of the week from a numerical day of + /// the week. e.g. "Mon" + /// @param[in] day_of_week A numerical version of the sequential day of the + /// week. e.g. Sunday = 1, Monday = 2, ..., Saturday = 7 + /// @param[in] offset Days to offset by. + /// e.g. For different day starting the week. + /// @return The resulting String. + String dayToString(const uint8_t day_of_week, const int8_t offset) { if ((uint8_t)(day_of_week + offset) < 7) #if UNIT_TEST - result += String(kThreeLetterDayOfWeekStr).substr( + return String(kThreeLetterDayOfWeekStr).substr( (day_of_week + offset) * 3, 3); #else // UNIT_TEST - result += String(kThreeLetterDayOfWeekStr).substring( + return String(kThreeLetterDayOfWeekStr).substring( (day_of_week + offset) * 3, (day_of_week + offset) * 3 + 3); #endif // UNIT_TEST else - result += kUnknownStr; - return result + ')'; + return kUnknownStr; } /// Create a String of human output for the given fan speed. /// e.g. "Fan: 0 (Auto)" /// @param[in] speed The numeric speed of the fan to display. - /// @param[in] high The numeric value for High speed. + /// @param[in] high The numeric value for High speed. (second highest) /// @param[in] low The numeric value for Low speed. /// @param[in] automatic The numeric value for Auto speed. /// @param[in] quiet The numeric value for Quiet speed. /// @param[in] medium The numeric value for Medium speed. /// @param[in] maximum The numeric value for Highest speed. (if > high) + /// @param[in] medium_high The numeric value for third-highest speed. + /// (if > medium) /// @return The resulting String. String addFanToString(const uint8_t speed, const uint8_t high, const uint8_t low, const uint8_t automatic, const uint8_t quiet, const uint8_t medium, - const uint8_t maximum) { + const uint8_t maximum, const uint8_t medium_high) { String result = ""; result.reserve(21); // ", Fan: NNN (UNKNOWN)" result += addIntToString(speed, kFanStr); @@ -825,6 +852,7 @@ namespace irutils { else if (speed == quiet) result += kQuietStr; else if (speed == medium) result += kMediumStr; else if (speed == maximum) result += kMaximumStr; + else if (speed == medium_high) result += kMedHighStr; else result += kUnknownStr; return result + ')'; @@ -950,6 +978,106 @@ namespace irutils { return result + ')'; } + /// @brief Create a String of human output for the given timer setting. + /// e.g. "Timer Mode: 2 (Schedule 1)" + /// @param[in] timerMode The numeric value of the timer mode to display. + /// @param[in] noTimer The numeric value for no timer (off) + /// @param[in] delayTimer The numeric value for delay (sleep) timer + /// @param[in] schedule1 The numeric value for schedule timer #1 + /// @param[in] schedule2 The numeric value for schedule timer #2 + /// @param[in] schedule3 The numeric value for schedule timer #3 + /// @param[in] precomma Should the output string start with ", " or not? + /// @return String representation + String addTimerModeToString(const uint8_t timerMode, const uint8_t noTimer, + const uint8_t delayTimer, const uint8_t schedule1, + const uint8_t schedule2, const uint8_t schedule3, + const bool precomma) { + String result = ""; + result.reserve(28); // ", Timer Mode: 2 (Schedule 1)" + result += addIntToString(timerMode, kTimerModeStr, precomma); + result += kSpaceLBraceStr; + if (timerMode == noTimer) { + result += kOffStr; + } else if (timerMode == delayTimer) { + result += kSleepTimerStr; + } else if (timerMode == schedule1) { + result += kScheduleStr; + result += '1'; + } else if (timerMode == schedule2) { + result += kScheduleStr; + result += '2'; + } else if (timerMode == schedule3) { + result += kScheduleStr; + result += '3'; + } else { + result += kUnknownStr; + } + return result + ')'; + } + + /// @brief Create a String of human output for the given channel + /// e.g. "[CH#0]" + /// @param channel The numeric value of the channel to display. + /// @return String representation + String channelToString(const uint8_t channel) { + String result = ""; + result.reserve(6); // "[CH#4]" + result += "["; + result += kChStr; + result += uint64ToString(channel); + result += "]"; + return result; + } + + /// @brief Create a String of human output for the given command type + /// e.g. "IFeel Report" + /// @param irCommandType The numeric value of the command type to display. + /// @param acControlCmd The numeric value of the "control" (default) command + /// @param iFeelReportCmd The numeric value of the sensor temperature command + /// @param timerCmd The numeric value of the timer config IR command + /// @param configCmd The numeric value of the config param set IR command + /// @return String representation + String irCommandTypeToString(uint8_t irCommandType, uint8_t acControlCmd, + uint8_t iFeelReportCmd, uint8_t timerCmd, + uint8_t configCmd) { + String result = ""; + result.reserve(12); // "IFeel Report" + if (irCommandType == acControlCmd) { + result += kCommandStr; + } else if (irCommandType == iFeelReportCmd) { + result += kIFeelReportStr; + } else if (irCommandType == timerCmd) { + result += kTimerStr; + } else if (irCommandType == configCmd) { + result += kConfigCommandStr; + } else { + result += kUnknownStr; + } + return result; + } + + /// @brief Create a String of the 3-letter day of the week bitmap + // e.g. 0b0000101 is "Sun | Tue" + /// @param[in] daysBitmap The bitmap representing days of week to represent + /// e.g bit[0]=Sunday, bit[1]=Monday, ... + /// @param[in] offset Days to offset by. + /// e.g. For different day starting the week. + /// @return String representation. + String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset) { + String result = ""; + result.reserve(27); // Sun|Mon|Tue|Wed|Thu|Fri|Sat + + for (uint8_t i = 0; i < 7; ++i) { + if (((daysBitmap >> i) & 0b1) == 0b1) { + if (result.length() > 0) { + result += "|"; + } + result += irutils::dayToString(i, offset); + } + } + return result; + } + /// Escape any special HTML (unsafe) characters in a string. e.g. anti-XSS. /// @param[in] unescaped A String containing text to make HTML safe. /// @return A string that is HTML safe. @@ -1273,7 +1401,7 @@ namespace irutils { /// issue has been found. uint8_t lowLevelSanityCheck(void) { const uint64_t kExpectedBitFieldResult = 0x8000012340000039ULL; - volatile uint32_t EndianTest = 0x12345678; + atomic_uint32_t EndianTest = 0x12345678; const uint8_t kBitFieldError = 0b01; const uint8_t kEndiannessError = 0b10; uint8_t result = 0; diff --git a/lib/IRremoteESP8266/src/IRutils.h b/lib/IRremoteESP8266/src/IRutils.h index a5dcde0432..8c94df2286 100644 --- a/lib/IRremoteESP8266/src/IRutils.h +++ b/lib/IRremoteESP8266/src/IRutils.h @@ -60,16 +60,19 @@ namespace irutils { String addLabeledString(const String value, const String label, const bool precomma = true); String addTempToString(const uint16_t degrees, const bool celsius = true, - const bool precomma = true); + const bool precomma = true, + const bool isSensorTemp = false); String addTempFloatToString(const float degrees, const bool celsius = true, - const bool precomma = true); + const bool precomma = true, + const bool isSensorTemp = false); String addModeToString(const uint8_t mode, const uint8_t automatic, const uint8_t cool, const uint8_t heat, const uint8_t dry, const uint8_t fan); String addFanToString(const uint8_t speed, const uint8_t high, const uint8_t low, const uint8_t automatic, const uint8_t quiet, const uint8_t medium, - const uint8_t maximum = 0xFF); + const uint8_t maximum = 0xFF, + const uint8_t medium_high = 0xFF); String addSwingHToString(const uint8_t position, const uint8_t automatic, const uint8_t maxleft, const uint8_t left, const uint8_t middle, @@ -87,6 +90,19 @@ namespace irutils { const uint8_t breeze, const uint8_t circulate); String addDayToString(const uint8_t day_of_week, const int8_t offset = 0, const bool precomma = true); + String addTimerModeToString(const uint8_t timerType, const uint8_t noTimer, + const uint8_t delayTimer, + const uint8_t schedule1 = 0xFF, + const uint8_t schedule2 = 0xFF, + const uint8_t schedule3 = 0xFF, + const bool precomma = true); + String irCommandTypeToString(uint8_t commandType, uint8_t acControlCmd, + uint8_t iFeelReportCmd = 0xFF, + uint8_t timerCmd = 0xFF, + uint8_t configCmd = 0xFF); + String dayToString(const uint8_t day_of_week, const int8_t offset = 0); + String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset = 0); + String channelToString(const uint8_t channel); String htmlEscape(const String unescaped); String msToString(uint32_t const msecs); String minsToString(const uint16_t mins); diff --git a/lib/IRremoteESP8266/src/ir_Argo.cpp b/lib/IRremoteESP8266/src/ir_Argo.cpp index 04cde67ed1..2f5ce4ea65 100644 --- a/lib/IRremoteESP8266/src/ir_Argo.cpp +++ b/lib/IRremoteESP8266/src/ir_Argo.cpp @@ -1,11 +1,16 @@ // Copyright 2017 Schmolders // Copyright 2019 crankyoldgit +// Copyright 2022 Mateusz Bronk (mbronk) /// @file /// @brief Argo A/C protocol. -/// Controls an Argo Ulisse 13 DCI A/C + +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1859 +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1912 + #include "ir_Argo.h" #include +#include #include #ifndef UNIT_TEST #include @@ -22,189 +27,890 @@ const uint16_t kArgoBitMark = 400; const uint16_t kArgoOneSpace = 2200; const uint16_t kArgoZeroSpace = 900; const uint32_t kArgoGap = kDefaultMessageGap; // Made up value. Complete guess. +const uint8_t kArgoSensorCheck = 52; // Part of the sensor message check calc. +const uint8_t kArgoSensorFixed = 0b011; +const uint8_t kArgoWrem3Preamble = 0b1011; +const uint8_t kArgoWrem3Postfix_Timer = 0b1; +const uint8_t kArgoWrem3Postfix_ACControl = 0b110000; using irutils::addBoolToString; using irutils::addIntToString; using irutils::addLabeledString; using irutils::addModeToString; using irutils::addTempToString; +using irutils::addFanToString; +using irutils::addSwingVToString; +using irutils::minsToString; +using irutils::addDayToString; +using irutils::addModelToString; +using irutils::daysBitmaskToString; +using irutils::addTimerModeToString; #if SEND_ARGO /// Send a Argo A/C formatted message. -/// Status: BETA / Probably works. +/// Status: [WREM-2] BETA / Probably works. +/// [WREM-3] Confirmed working w/ Argo 13 ECO (WREM-3) +/// @note The "no footer" part needs re-checking for validity but retained for +/// backwards compatibility. +/// Consider using @c sendFooter=true code for WREM-2 as well /// @param[in] data The message to be sent. /// @param[in] nbytes The number of bytes of message to be sent. /// @param[in] repeat The number of times the command is to be repeated. +/// @param[in] sendFooter Whether to send footer and add a final gap. +/// *REQUIRED* for WREM-3, UNKNOWN for WREM-2 (used to be +/// disabled in previous impl., hence retained) +/// @note Consider removing this param (default to true) if WREM-2 works w/ it void IRsend::sendArgo(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 < kArgoStateLength) return; - // TODO(kaschmo): validate + const uint16_t repeat, bool sendFooter /*= false*/) { + if (nbytes < std::min({kArgo3AcControlStateLength, + kArgo3ConfigStateLength, + kArgo3iFeelReportStateLength, + kArgo3TimerStateLength, + kArgoStateLength, + kArgoShortStateLength})) { + return; // Not enough bytes to send a proper message. + } + + const uint16_t _footermark = (sendFooter)? kArgoBitMark : 0; + const uint32_t _gap = (sendFooter)? kArgoGap : 0; + sendGeneric(kArgoHdrMark, kArgoHdrSpace, kArgoBitMark, kArgoOneSpace, - kArgoBitMark, kArgoZeroSpace, 0, 0, // No Footer. - data, nbytes, 38, false, repeat, kDutyDefault); + kArgoBitMark, kArgoZeroSpace, + _footermark, _gap, + data, nbytes, kArgoFrequency, false, repeat, kDutyDefault); +} + + +/// Send a Argo A/C formatted message. +/// Status: Confirmed working w/ Argo 13 ECO (WREM-3) +/// @param[in] data The message to be sent. +/// @param[in] nbytes The number of bytes of message to be sent. +/// @param[in] repeat The number of times the command is to be repeated. +void IRsend::sendArgoWREM3(const unsigned char data[], const uint16_t nbytes, + const uint16_t repeat) { + sendArgo(data, nbytes, repeat, true); } #endif // SEND_ARGO + /// Class constructor /// @param[in] pin GPIO to be used when sending. /// @param[in] inverted Is the output signal to be inverted? /// @param[in] use_modulation Is frequency modulation to be used? -IRArgoAC::IRArgoAC(const uint16_t pin, const bool inverted, +template +IRArgoACBase::IRArgoACBase(const uint16_t pin, const bool inverted, const bool use_modulation) : _irsend(pin, inverted, use_modulation) { stateReset(); } + +/// Class constructor +/// @param[in] pin GPIO to be used when sending. +/// @param[in] inverted Is the output signal to be inverted? +/// @param[in] use_modulation Is frequency modulation to be used? +IRArgoAC::IRArgoAC(const uint16_t pin, const bool inverted, + const bool use_modulation) + : IRArgoACBase(pin, inverted, use_modulation) { } + + +/// Class constructor +/// @param[in] pin GPIO to be used when sending. +/// @param[in] inverted Is the output signal to be inverted? +/// @param[in] use_modulation Is frequency modulation to be used? +IRArgoAC_WREM3::IRArgoAC_WREM3(const uint16_t pin, const bool inverted, + const bool use_modulation) + : IRArgoACBase(pin, inverted, use_modulation) {} + /// Set up hardware to be able to send a message. -void IRArgoAC::begin(void) { _irsend.begin(); } +template +void IRArgoACBase::begin(void) { _irsend.begin(); } -#if SEND_ARGO -/// Send the current internal state as an IR message. -/// @param[in] repeat Nr. of times the message will be repeated. -void IRArgoAC::send(const uint16_t repeat) { - _irsend.sendArgo(getRaw(), kArgoStateLength, repeat); + +/// @cond +/// @brief Get byte length of raw WREM-2 message based on IR cmd type +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param type The type of IR command +/// @note Not all types are supported. AC_CONTROL and TIMER are the same cmd +/// @return Byte length of state command +/// @relates IRArgoACBase\ +template<> +uint16_t IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t type) { + switch (type) { + case argoIrMessageType_t::AC_CONTROL: + case argoIrMessageType_t::TIMER_COMMAND: + return kArgoStateLength; + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + return kArgoShortStateLength; + case argoIrMessageType_t::CONFIG_PARAM_SET: + default: + return 0; // Not supported by WREM-2 + } } -#endif // SEND_ARGO +/// @endcond -/// Verify the checksum is valid for a given state. -/// @param[in] state The array to verify the checksum of. +/// @brief Get byte length of raw WREM-3 message based on IR cmd type +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param type The type of IR command +/// @return Byte length of state command +/// @relates IRArgoACBase\ +template<> +uint16_t IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t type) { + switch (type) { + case argoIrMessageType_t::AC_CONTROL: + return kArgo3AcControlStateLength; + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + return kArgo3iFeelReportStateLength; + case argoIrMessageType_t::TIMER_COMMAND: + return kArgo3TimerStateLength; + case argoIrMessageType_t::CONFIG_PARAM_SET: + return kArgo3ConfigStateLength; + default: + return 0; + } +} + +/// @cond +/// @brief Get message type from raw WREM-2 data +/// 1st param ignored: WREM-2 does not carry type in payload, allegedly +/// @param length Message length: used for *heuristic* detection of message type +/// @return IR message type +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +argoIrMessageType_t IRArgoACBase::getMessageType( + const uint8_t[], const uint16_t length) { + if (length == kArgoShortStateLength) { + return argoIrMessageType_t::IFEEL_TEMP_REPORT; + } + return argoIrMessageType_t::AC_CONTROL; +} +/// @endcond + + +/// @brief Get message type from raw WREM-3 data +/// @param state The raw IR data +/// @param length Length of @c state (in byte) +/// @return IR message type +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +argoIrMessageType_t IRArgoACBase::getMessageType( + const uint8_t state[], const uint16_t length) { + if (length < 1) { + return static_cast(-1); + } + return static_cast(state[0] >> 6); +} + +/// @brief Get message type from raw WREM-3 data +/// @param raw Raw data +/// @return IR message type +argoIrMessageType_t IRArgoAC_WREM3::getMessageType( + const ArgoProtocolWREM3& raw) { + return static_cast(raw.IrCommandType); +} + + +/// @brief Get actual raw state byte length for the current state +/// _param 1st param ignored: WREM-2 does not caryy type in payload, allegedly +/// @param messageType Type of message the state is carrying +/// @return Actual length of state (in bytes) +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +uint16_t IRArgoACBase::getRawByteLength(const ArgoProtocol&, + argoIrMessageType_t messageType) { + if (messageType == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + return kArgoShortStateLength; + } + return kArgoStateLength; +} + + +/// @brief Get actual raw state byte length for the current state +/// @param raw The raw state +/// _param 2nd param ignored (1st byte of @c raw is sufficient to get len) +/// @return Actual length of state (in bytes) +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +uint16_t IRArgoACBase::getRawByteLength( + const ArgoProtocolWREM3& raw, argoIrMessageType_t) { + return IRArgoAC_WREM3::getStateLengthForIrMsgType( + IRArgoAC_WREM3::getMessageType(raw)); +} + + +/// @brief Get actual raw state byte length for the current state +/// @return Actual length of state (in bytes) +template +uint16_t IRArgoACBase::getRawByteLength() const { + return getRawByteLength(_, _messageType); +} + +/// @cond +/// Calculate the checksum for a given state (WREM-2). +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @warning This does NOT calculate 'short' (iFeel) message checksums +/// @param[in] state The array to calculate the checksum for. /// @param[in] length The size of the state. -/// @return A boolean indicating if it's checksum is valid. -uint8_t IRArgoAC::calcChecksum(const uint8_t state[], const uint16_t length) { +/// @return The 8-bit calculated result. +/// @relates IRArgoACBase\ +template<> +uint8_t IRArgoACBase::calcChecksum(const uint8_t state[], + const uint16_t length) { // Corresponds to byte 11 being constant 0b01 // Only add up bytes to 9. byte 10 is 0b01 constant anyway. // Assume that argo array is MSB first (left) return sumBytes(state, length - 2, 2); } +/// @endcond + + +/// Calculate the checksum for a given state (WREM-3). +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] state The array to calculate the checksum for. +/// @param[in] length The size of the state. +/// @return The 8-bit calculated result. +/// @relates IRArgoACBase\ +template<> +uint8_t IRArgoACBase::calcChecksum(const uint8_t state[], + const uint16_t length) { + if (length < 1) { + return -1; // Nothing to compute on + } + + uint16_t payloadSizeBits = (length - 1) * 8; // Last byte carries checksum + + argoIrMessageType_t msgType = getMessageType(state, length); + if (msgType == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + payloadSizeBits += 5; // For WREM3::iFeel the checksum is 3-bit + } else if (msgType == argoIrMessageType_t::TIMER_COMMAND) { + payloadSizeBits += 3; // For WREM3::Timer the checksum is 5-bit + } // Otherwise: full 8-bit checksum + + uint8_t checksum = sumBytes(state, payloadSizeBits / 8, 0); + + // Add stray bits from last byte to the checksum (if any) + const uint8_t maskPayload = 0xFF >> (8 - (payloadSizeBits % 8)); + checksum += (state[length-1] & maskPayload); + + const uint8_t maskChecksum = 0xFF >> (payloadSizeBits % 8); + return checksum & maskChecksum; +} + + +/// Update the checksum for a given state (WREM2). +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @warning This impl does not support short message format (iFeel) +/// @param[in,out] state Pointer to a binary representation of the A/C state. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::_checksum(ArgoProtocol *state) { + uint8_t sum = calcChecksum(state->raw, kArgoStateLength); + // Append sum to end of array + // Set const part of checksum bit 10 + state->Post = kArgoPost; + state->Sum = sum; +} + + +/// @brief Update the checksum for a given state (WREM3). +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in,out] state Pointer to a binary representation of the A/C state. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::_checksum(ArgoProtocolWREM3 *state) { + argoIrMessageType_t msgType = IRArgoAC_WREM3::getMessageType(*state); + + uint8_t sum = calcChecksum(state->raw, getRawByteLength(*state)); + switch (msgType) { + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + state->CheckHi = sum; + break; + case argoIrMessageType_t::TIMER_COMMAND: + state->timer.Checksum = sum; + break; + case argoIrMessageType_t::CONFIG_PARAM_SET: + state->config.Checksum = sum; + break; + case argoIrMessageType_t::AC_CONTROL: + default: + state->Sum = sum; + break; + } +} + + +/// Update the checksum for the internal state. +template +void IRArgoACBase::checksum(void) { _checksum(&_); } + + +/// Reset the given state to a known good state. +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in,out] state Pointer to a binary representation of the A/C state. +/// _param 2nd param unused (always resets to AC_CONTROL state) +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::_stateReset(ArgoProtocol *state, + argoIrMessageType_t) { + for (uint8_t i = 2; i < kArgoStateLength; i++) state->raw[i] = 0x0; + state->Pre1 = kArgoPreamble1; // LSB first (as sent) 0b00110101; + state->Pre2 = kArgoPreamble2; // LSB first: 0b10101111; + state->Post = kArgoPost; +} + + +/// Reset the given state to a known good state +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in,out] state Pointer to a binary representation of the A/C state. +/// @param messageType Type of message to reset the state for +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::_stateReset(ArgoProtocolWREM3 *state, + argoIrMessageType_t messageType) { + for (uint8_t i = 1; i < sizeof(state->raw) / sizeof(state->raw[0]); i++) { + state->raw[i] = 0x0; + } + state->Pre1 = kArgoWrem3Preamble; // LSB first (as sent) 0b00110101; + state->IrChannel = 0; + state->IrCommandType = static_cast(messageType); + + if (messageType == argoIrMessageType_t::TIMER_COMMAND) { + state->timer.Post1 = kArgoWrem3Postfix_Timer; // 0b1 + } else if (messageType == argoIrMessageType_t::AC_CONTROL) { + state->Post1 = kArgoWrem3Postfix_ACControl; // 0b110000 + } +} + + +/// @brief Reset the internals of the object to a known good state. +/// @param messageType Type of message to reset the state for +template +void IRArgoACBase::stateReset(argoIrMessageType_t messageType) { + _stateReset(&_, messageType); + if (messageType == argoIrMessageType_t::AC_CONTROL) { + off(); + setTemp(20); + setSensorTemp(25); + setMode(argoMode_t::AUTO); + setFan(argoFan_t::FAN_AUTO); + } + _messageType = messageType; + _length = getStateLengthForIrMsgType(_messageType); +} + + +/// @brief Retrieve the checksum value from transmitted state +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] state Raw state +/// @param length Length of @c state in bytes +/// @return Checksum value (8-bit) +/// @relates IRArgoACBase\ +template<> +uint8_t IRArgoACBase::getChecksum(const uint8_t state[], + const uint16_t length) { + if (length < 1) { + return -1; + } + return (state[length - 2] >> 2) + (state[length - 1] << 6); +} + +/// @cond +/// @brief Retrieve the checksum value from transmitted state +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] state Raw state +/// @param length Length of @c state in bytes +/// @return Checksum value (up to 8-bit) +template<> +uint8_t IRArgoACBase::getChecksum(const uint8_t state[], + const uint16_t length) { + if (length < 1) { + return -1; + } + argoIrMessageType_t msgType = getMessageType(state, length); + if (msgType == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + return (state[length - 1] & 0b11100000) >> 5; + } + if (msgType == argoIrMessageType_t::TIMER_COMMAND) { + return state[length - 1] >> 3; + } + return (state[length - 1]); +} +/// @endcond + /// Verify the checksum is valid for a given state. /// @param[in] state The array to verify the checksum of. /// @param[in] length The size of the state. /// @return A boolean indicating if it's checksum is valid. -bool IRArgoAC::validChecksum(const uint8_t state[], const uint16_t length) { - return ((state[length - 2] >> 2) + (state[length - 1] << 6)) == - IRArgoAC::calcChecksum(state, length); +template +bool IRArgoACBase::validChecksum(const uint8_t state[], + const uint16_t length) { + return (getChecksum(state, length) == calcChecksum(state, length)); } -/// Update the checksum for the internal state. -void IRArgoAC::checksum(void) { - uint8_t sum = IRArgoAC::calcChecksum(_.raw, kArgoStateLength); - // Append sum to end of array - // Set const part of checksum bit 10 - _.raw[10] = 0b00000010; - _.Sum = sum; + +#if SEND_ARGO +/// Send the current internal state as an IR message. +/// @param[in] repeat Nr. of times the message will be repeated. +template +void IRArgoACBase::send(const uint16_t repeat) { + _irsend.sendArgo(getRaw(), getRawByteLength(), repeat); } -/// Reset the internals of the object to a known good state. -void IRArgoAC::stateReset(void) { - for (uint8_t i = 0; i < kArgoStateLength; i++) _.raw[i] = 0x0; +/// @cond +/// Send the current internal state as an IR message. +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] repeat Nr. of times the message will be repeated. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::send(const uint16_t repeat) { + _irsend.sendArgoWREM3(getRaw(), getRawByteLength(), repeat); +} +/// @endcond + + +/// Send current room temperature for the iFeel feature as a silent IR +/// message (no acknowledgement from the device) (WREM2) +/// @param[in] degrees The temperature in degrees celsius. +/// @param[in] repeat Nr. of times the message will be repeated. +void IRArgoAC::sendSensorTemp(const uint8_t degrees, const uint16_t repeat) { + const uint8_t temp = std::max(std::min(degrees, kArgoMaxRoomTemp), + kArgoTempDelta) - kArgoTempDelta; + const uint8_t check = kArgoSensorCheck + temp; - // Argo Message. Store MSB left. - // Default message: - _.raw[0] = 0b10101100; // LSB first (as sent) 0b00110101; //const preamble - _.raw[1] = 0b11110101; // LSB first: 0b10101111; //const preamble - // Keep payload 2-9 at zero - _.raw[10] = 0b00000010; // Const 01 - _.Sum = 0; + ArgoProtocol data; + _stateReset(&data, argoIrMessageType_t::IFEEL_TEMP_REPORT); + data.SensorT = temp; + data.CheckHi = check >> 5; + data.CheckLo = check; + data.Fixed = kArgoSensorFixed; + _checksum(&data); + uint16_t msgLen = getRawByteLength(data, + argoIrMessageType_t::IFEEL_TEMP_REPORT); - off(); - setTemp(20); - setRoomTemp(25); - setMode(kArgoAuto); - setFan(kArgoFanAuto); + _irsend.sendArgo(data.raw, msgLen, repeat); } +/// Send current room temperature for the iFeel feature as a silent IR +/// message (no acknowledgement from the device) (WREM3) +/// @param[in] degrees The temperature in degrees celsius. +/// @param[in] repeat Nr. of times the message will be repeated. +void IRArgoAC_WREM3::sendSensorTemp(const uint8_t degrees, + const uint16_t repeat) { + const uint8_t temp = std::max(std::min(degrees, kArgoMaxRoomTemp), + kArgoTempDelta) - kArgoTempDelta; + ArgoProtocolWREM3 data = {}; + _stateReset(&data, argoIrMessageType_t::IFEEL_TEMP_REPORT); + data.SensorT = temp; + _checksum(&data); + uint16_t msgLen = getRawByteLength(data, + argoIrMessageType_t::IFEEL_TEMP_REPORT); + _irsend.sendArgoWREM3(data.raw, msgLen, repeat); +} +#endif + + /// Get the raw state of the object, suitable to be sent with the appropriate /// IRsend object method. /// @return A PTR to the internal state. -uint8_t* IRArgoAC::getRaw(void) { +template +uint8_t* IRArgoACBase::getRaw(void) { checksum(); // Ensure correct bit array before returning return _.raw; } + /// Set the raw state of the object. /// @param[in] state The raw state from the native IR message. -void IRArgoAC::setRaw(const uint8_t state[]) { - std::memcpy(_.raw, state, kArgoStateLength); +/// @param[in] length The length of raw state in bytes. +template +void IRArgoACBase::setRaw(const uint8_t state[], const uint16_t length) { + std::memcpy(_.raw, state, length); + _messageType = getMessageType(state, length); + _length = length; } /// Set the internal state to have the power on. -void IRArgoAC::on(void) { setPower(true); } +template +void IRArgoACBase::on(void) { setPower(true); } /// Set the internal state to have the power off. -void IRArgoAC::off(void) { setPower(false); } +template +void IRArgoACBase::off(void) { setPower(false); } +/// @cond /// Set the internal state to have the desired power. /// @param[in] on The desired power state. -void IRArgoAC::setPower(const bool on) { +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setPower(const bool on) { _.Power = on; } +/// @endcond + +/// @brief Set the internal state to have the desired power. +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] on The desired power state. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setPower(const bool on) { + if (_messageType == argoIrMessageType_t::TIMER_COMMAND) { + _.timer.IsOn = on; + } else { + _.Power = on; + } +} /// Get the power setting from the internal state. +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function /// @return A boolean indicating the power setting. -bool IRArgoAC::getPower(void) const { return _.Power; } +/// @relates IRArgoACBase\ +template<> +bool IRArgoACBase::getPower(void) const { return _.Power; } + +/// Get the power setting from the internal state. +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @return A boolean indicating the power setting. +/// @relates IRArgoACBase\ +template<> +bool IRArgoACBase::getPower(void) const { + if (_messageType == argoIrMessageType_t::TIMER_COMMAND) { + return _.timer.IsOn; + } + return _.Power; +} /// Control the current Max setting. (i.e. Turbo) /// @param[in] on The desired setting. -void IRArgoAC::setMax(const bool on) { +template +void IRArgoACBase::setMax(const bool on) { _.Max = on; } /// Is the Max (i.e. Turbo) setting on? /// @return The current value. -bool IRArgoAC::getMax(void) const { return _.Max; } +template +bool IRArgoACBase::getMax(void) const { return _.Max; } /// Set the temperature. /// @param[in] degrees The temperature in degrees celsius. /// @note Sending 0 equals +4 -void IRArgoAC::setTemp(const uint8_t degrees) { +template +void IRArgoACBase::setTemp(const uint8_t degrees) { uint8_t temp = std::max(kArgoMinTemp, degrees); // delta 4 degrees. "If I want 12 degrees, I need to send 8" temp = std::min(kArgoMaxTemp, temp) - kArgoTempDelta; // mask out bits - // argo[13] & 0x00000100; // mask out ON/OFF Bit _.Temp = temp; } /// Get the current temperature setting. /// @return The current setting for temp. in degrees celsius. -uint8_t IRArgoAC::getTemp(void) const { +template +uint8_t IRArgoACBase::getTemp(void) const { return _.Temp + kArgoTempDelta; } + +/// @brief Get the current fan mode setting as a strongly typed value (WREM2). +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @return The current fan mode. +/// @relates IRArgoACBase\ +template<> +argoFan_t IRArgoACBase::getFanEx(void) const { + switch (_.Fan) { + case kArgoFan3: + return argoFan_t::FAN_HIGHEST; + case kArgoFan2: + return argoFan_t::FAN_MEDIUM; + case kArgoFan1: + return argoFan_t::FAN_LOWEST; + case kArgoFanAuto: + return argoFan_t::FAN_AUTO; + default: + return static_cast(_.Fan); + } +} + +/// @brief Get the current fan mode setting as a strongly typed value (WREM3). +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @return The current fan mode. +/// @relates IRArgoACBase\ +template<> +argoFan_t IRArgoACBase::getFanEx(void) const { + return static_cast(_.Fan); +} + +/// @cond +/// Set the desired fan mode (WREM2). +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] fan The desired fan speed. +/// @note Only a subset of fan speeds are supported (1|2|3|Auto) +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setFan(argoFan_t fan) { + switch (fan) { + case argoFan_t::FAN_AUTO: + _.Fan = kArgoFanAuto; + break; + case argoFan_t::FAN_HIGHEST: + case argoFan_t::FAN_HIGH: + _.Fan = kArgoFan3; + break; + case argoFan_t::FAN_MEDIUM: + case argoFan_t::FAN_LOW: + _.Fan = kArgoFan2; + break; + case argoFan_t::FAN_LOWER: + case argoFan_t::FAN_LOWEST: + _.Fan = kArgoFan1; + break; + default: + uint8_t raw_value = static_cast(fan); // 2-bit value, per def. + if ((raw_value & 0b11) == raw_value) { + // Outside of known value range, but matches field length + // Let's assume the caller knows what they're doing and pass it through + _.Fan = raw_value; + } else { + _.Fan = kArgoFanAuto; + } + break; + } +} +/// @endcond + +/// Set the desired fan mode (WREM3). +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] fan The desired fan speed. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setFan(argoFan_t fan) { + switch (fan) { + case argoFan_t::FAN_AUTO: + case argoFan_t::FAN_HIGHEST: + case argoFan_t::FAN_HIGH: + case argoFan_t::FAN_MEDIUM: + case argoFan_t::FAN_LOW: + case argoFan_t::FAN_LOWER: + case argoFan_t::FAN_LOWEST: + _.Fan = static_cast(fan); + break; + default: + _.Fan = static_cast(argoFan_t::FAN_AUTO); + break; + } +} + /// Set the speed of the fan. +/// @deprecated /// @param[in] fan The desired setting. void IRArgoAC::setFan(const uint8_t fan) { _.Fan = std::min(fan, kArgoFan3); } /// Get the current fan speed setting. +/// @deprecated /// @return The current fan speed. uint8_t IRArgoAC::getFan(void) const { return _.Fan; } -/// Set the flap position. i.e. Swing. +/// @brief Get Flap (VSwing) value as a strongly-typed value +/// @note This @c getFlapEx() method has been introduced to be able to retain +/// old implementation of @c getFlap() for @c IRArgoAc which used uint8_t +/// @return Flap setting +template +argoFlap_t IRArgoACBase::getFlapEx(void) const { + return static_cast(_.Flap); +} + +/// Set the desired flap mode +/// @param[in] flap The desired flap mode. +template +void IRArgoACBase::setFlap(argoFlap_t flap) { + uint8_t raw_value = static_cast(flap); + if ((raw_value & 0b111) == raw_value) { + // Outside of known value range, but matches field length + // Let's assume the caller knows what they're doing and pass it through + _.Flap = raw_value; + } else { + _.Flap = static_cast(argoFlap_t::FLAP_AUTO); + } +} + +/// Set the flap position. i.e. Swing. (WREM2) /// @warning Not yet working! +/// @deprecated /// @param[in] flap The desired setting. void IRArgoAC::setFlap(const uint8_t flap) { - flap_mode = flap; + setFlap(static_cast(flap)); // TODO(kaschmo): set correct bits for flap mode } -/// Get the flap position. i.e. Swing. +/// Get the flap position. i.e. Swing. (WREM2) /// @warning Not yet working! +/// @deprecated /// @return The current flap setting. -uint8_t IRArgoAC::getFlap(void) const { return flap_mode; } +uint8_t IRArgoAC::getFlap(void) const { + return _.Flap; +} + +/// Get the current operation mode setting. +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @return The current operation mode. +/// @note This @c getModeEx() method has been introduced to be able to retain +/// old implementation of @c getMode() for @c IRArgoAc which used uint8_t +/// @relates IRArgoACBase\ +template<> +argoMode_t IRArgoACBase::getModeEx(void) const { + switch (_.Mode) { + case kArgoCool: + return argoMode_t::COOL; + case kArgoDry: + return argoMode_t::DRY; + case kArgoAuto: + return argoMode_t::AUTO; + case kArgoHeat: + return argoMode_t::HEAT; + case kArgoOff: // Modelling "FAN" as "OFF", for the lack of better constant + return argoMode_t::FAN; + case kArgoHeatAuto: + default: + return static_cast(_.Mode); + } +} /// Get the current operation mode setting. +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function. /// @return The current operation mode. -uint8_t IRArgoAC::getMode(void) const { - return _.Mode; +/// @note This @c getModeEx() method has been introduced to be able to retain +/// old implementation of @c getMode() for @c IRArgoAc which used uint8_t +/// @relates IRArgoACBase\ +template<> +argoMode_t IRArgoACBase::getModeEx(void) const { + return static_cast(_.Mode); } +/// @cond /// Set the desired operation mode. /// @param[in] mode The desired operation mode. -void IRArgoAC::setMode(const uint8_t mode) { +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setMode(argoMode_t mode) { + switch (mode) { + case argoMode_t::COOL: + _.Mode = static_cast(kArgoCool); + break; + case argoMode_t::DRY: + _.Mode = static_cast(kArgoDry); + break; + case argoMode_t::HEAT: + _.Mode = static_cast(kArgoHeat); + break; + case argoMode_t::FAN: + _.Mode = static_cast(kArgoOff); + break; + case argoMode_t::AUTO: + _.Mode = static_cast(kArgoAuto); + break; + default: + uint8_t raw_value = static_cast(mode); + if ((raw_value & 0b111) == raw_value) { + // Outside of known value range, but matches field length + // Let's assume the caller knows what they're doing and pass it through + _.Mode = raw_value; + } else { + _.Mode = static_cast(kArgoAuto); + } + break; + } +} +/// @endcond + +/// @brief Set the desired operation mode. +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] mode The desired operation mode. +/// @relates IRArgoACBase\ +template<> +void IRArgoACBase::setMode(argoMode_t mode) { + switch (mode) { + case argoMode_t::COOL: + case argoMode_t::DRY: + case argoMode_t::HEAT: + case argoMode_t::FAN: + case argoMode_t::AUTO: + _.Mode = static_cast(mode); + break; + default: + _.Mode = static_cast(argoMode_t::AUTO); + break; + } +} + +/// @brief Set the desired operation mode. +/// @deprecated +/// @param mode The desired operation mode. +void IRArgoAC::setMode(uint8_t mode) { switch (mode) { case kArgoCool: case kArgoDry: @@ -213,118 +919,309 @@ void IRArgoAC::setMode(const uint8_t mode) { case kArgoHeat: case kArgoHeatAuto: _.Mode = mode; - return; + break; default: _.Mode = kArgoAuto; + break; } } +/// @brief Get the current operation mode +/// @deprecated +/// @return The current operation mode +uint8_t IRArgoAC::getMode() const { return _.Mode;} + +argoFan_t IRArgoAC_WREM3::getFan(void) const { return getFanEx(); } +argoFlap_t IRArgoAC_WREM3::getFlap(void) const { return getFlapEx(); } +argoMode_t IRArgoAC_WREM3::getMode(void) const { return getModeEx(); } + /// Turn on/off the Night mode. i.e. Sleep. /// @param[in] on The desired setting. -void IRArgoAC::setNight(const bool on) { - _.Night = on; -} +template +void IRArgoACBase::setNight(const bool on) { _.Night = on; } /// Get the status of Night mode. i.e. Sleep. /// @return true if on, false if off. -bool IRArgoAC::getNight(void) const { return _.Night; } +template +bool IRArgoACBase::getNight(void) const { return _.Night; } -/// Turn on/off the iFeel mode. +/// @brief Turn on/off the Economy mode (lowered power mode) +/// @param[in] on The desired setting. +void IRArgoAC_WREM3::setEco(const bool on) { _.Eco = on; } + +/// @brief Get the status of Economy function +/// @return true if on, false if off. +bool IRArgoAC_WREM3::getEco(void) const { return _.Eco; } + +/// @brief Turn on/off the Filter mode (not supported by Argo Ulisse) /// @param[in] on The desired setting. -void IRArgoAC::setiFeel(const bool on) { - _.iFeel = on; +void IRArgoAC_WREM3::setFilter(const bool on) { _.Filter = on; } + +/// @brief Get status of the filter function +/// @return true if on, false if off. +bool IRArgoAC_WREM3::getFilter(void) const { return _.Filter; } + +/// @brief Turn on/off the device Lights (LED) +/// @param[in] on The desired setting. +void IRArgoAC_WREM3::setLight(const bool on) { _.Light = on; } + +/// @brief Get status of device lights +/// @return true if on, false if off. +bool IRArgoAC_WREM3::getLight(void) const { return _.Light; } + +/// @brief Set the IR channel on which to communicate +/// @param[in] channel The desired IR channel. +void IRArgoAC_WREM3::setChannel(const uint8_t channel) { + _.IrChannel = std::min(channel, kArgoMaxChannel); } +/// @brief Get the currently set transmission channel +/// @return Channel number +uint8_t IRArgoAC_WREM3::getChannel(void) const { return _.IrChannel;} + +/// @brief Set the config data to send +/// Valid only for @c argoIrMessageType_t::CONFIG_PARAM_SET message +/// @param paramId The param ID +/// @param value The value of the parameter +void IRArgoAC_WREM3::setConfigEntry(const uint8_t paramId, + const uint8_t value) { + _.config.Key = paramId; + _.config.Value = value; +} + +/// @brief Get the config entry previously set +/// @return Key->value pair (paramID: value) +std::pair IRArgoAC_WREM3::getConfigEntry(void) const { + return std::make_pair(_.config.Key, _.config.Value); +} + +/// Turn on/off the iFeel mode. +/// @param[in] on The desired setting. +template +void IRArgoACBase::setiFeel(const bool on) { _.iFeel = on; } + /// Get the status of iFeel mode. /// @return true if on, false if off. -bool IRArgoAC::getiFeel(void) const { return _.iFeel; } +template +bool IRArgoACBase::getiFeel(void) const { return _.iFeel; } -/// Set the time for the A/C -/// @warning Not yet working! -void IRArgoAC::setTime(void) { - // TODO(kaschmo): use function call from checksum to set time first +/// @brief Set the message type of the next command (setting this resets state) +/// @param msgType The message type to set +template +void IRArgoACBase::setMessageType(const argoIrMessageType_t msgType) { + stateReset(msgType); +} + +/// @brief Get the message type +/// @return Message type currently set +template +argoIrMessageType_t IRArgoACBase::getMessageType(void) const { + return _messageType; } /// Set the value for the current room temperature. +/// @note Depending on message type - this will set `sensor` or `roomTemp` value /// @param[in] degrees The temperature in degrees celsius. -void IRArgoAC::setRoomTemp(const uint8_t degrees) { +template +void IRArgoACBase::setSensorTemp(const uint8_t degrees) { uint8_t temp = std::min(degrees, kArgoMaxRoomTemp); temp = std::max(temp, kArgoTempDelta) - kArgoTempDelta; - _.RoomTemp = temp; + if (getMessageType() == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + _.SensorT = temp; + } else { + _.RoomTemp = temp; + } } /// Get the currently stored value for the room temperature setting. +/// @note Depending on message type - this will get `sensor` or `roomTemp` value /// @return The current setting for the room temp. in degrees celsius. -uint8_t IRArgoAC::getRoomTemp(void) const { +template +uint8_t IRArgoACBase::getSensorTemp(void) const { + if (getMessageType() == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + return _.SensorT + kArgoTempDelta; + } return _.RoomTemp + kArgoTempDelta; } +/// @brief Convert a stdAc::ac_command_t enum into its native message type. +/// @param command The enum to be converted. +/// @return The native equivalent of the enum. +template +argoIrMessageType_t IRArgoACBase::convertCommand( + const stdAc::ac_command_t command) { + switch (command) { + case stdAc::ac_command_t::kSensorTempReport: + return argoIrMessageType_t::IFEEL_TEMP_REPORT; + case stdAc::ac_command_t::kTimerCommand: + return argoIrMessageType_t::TIMER_COMMAND; + case stdAc::ac_command_t::kConfigCommand: + return argoIrMessageType_t::CONFIG_PARAM_SET; + case stdAc::ac_command_t::kControlCommand: + default: + return argoIrMessageType_t::AC_CONTROL; + } +} + /// Convert a stdAc::opmode_t enum into its native mode. /// @param[in] mode The enum to be converted. /// @return The native equivalent of the enum. -uint8_t IRArgoAC::convertMode(const stdAc::opmode_t mode) { +template +argoMode_t IRArgoACBase::convertMode(const stdAc::opmode_t mode) { switch (mode) { case stdAc::opmode_t::kCool: - return kArgoCool; + return argoMode_t::COOL; case stdAc::opmode_t::kHeat: - return kArgoHeat; + return argoMode_t::HEAT; case stdAc::opmode_t::kDry: - return kArgoDry; - case stdAc::opmode_t::kOff: - return kArgoOff; - // No fan mode. - default: - return kArgoAuto; + return argoMode_t::DRY; + case stdAc::opmode_t::kFan: + return argoMode_t::FAN; + case stdAc::opmode_t::kAuto: + default: // No off mode. + return argoMode_t::AUTO; } } /// Convert a stdAc::fanspeed_t enum into it's native speed. /// @param[in] speed The enum to be converted. /// @return The native equivalent of the enum. -uint8_t IRArgoAC::convertFan(const stdAc::fanspeed_t speed) { +template +argoFan_t IRArgoACBase::convertFan(const stdAc::fanspeed_t speed) { switch (speed) { case stdAc::fanspeed_t::kMin: + return argoFan_t::FAN_LOWEST; case stdAc::fanspeed_t::kLow: - return kArgoFan1; + return argoFan_t::FAN_LOWER; case stdAc::fanspeed_t::kMedium: - return kArgoFan2; + return argoFan_t::FAN_LOW; + case stdAc::fanspeed_t::kMediumHigh: + return argoFan_t::FAN_MEDIUM; case stdAc::fanspeed_t::kHigh: + return argoFan_t::FAN_HIGH; case stdAc::fanspeed_t::kMax: - return kArgoFan3; + return argoFan_t::FAN_HIGHEST; default: - return kArgoFanAuto; + return argoFan_t::FAN_AUTO; } } /// Convert a stdAc::swingv_t enum into it's native setting. /// @param[in] position The enum to be converted. /// @return The native equivalent of the enum. -uint8_t IRArgoAC::convertSwingV(const stdAc::swingv_t position) { +template +argoFlap_t IRArgoACBase::convertSwingV(const stdAc::swingv_t position) { switch (position) { case stdAc::swingv_t::kHighest: - return kArgoFlapFull; + return argoFlap_t::FLAP_1; case stdAc::swingv_t::kHigh: - return kArgoFlap5; + return argoFlap_t::FLAP_2; + case stdAc::swingv_t::kUpperMiddle: + return argoFlap_t::FLAP_3; case stdAc::swingv_t::kMiddle: - return kArgoFlap4; + return argoFlap_t::FLAP_4; case stdAc::swingv_t::kLow: - return kArgoFlap3; + return argoFlap_t::FLAP_5; case stdAc::swingv_t::kLowest: - return kArgoFlap1; + return argoFlap_t::FLAP_6; + case stdAc::swingv_t::kOff: // This is abusing the semantics quite a bit + return argoFlap_t::FLAP_FULL; + case stdAc::swingv_t::kAuto: default: - return kArgoFlapAuto; + return argoFlap_t::FLAP_AUTO; + } +} + +/// @cond +/// Convert a native flap mode into its stdAc equivalent (WREM2). +/// @note This is a full specialization for @c ArgoProtocol type and while +/// it semantically belongs to @c IrArgoAC class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] position The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +/// @relates IRArgoACBase\ +template<> +stdAc::swingv_t IRArgoACBase::toCommonSwingV( + const uint8_t position) { + switch (position) { + case kArgoFlapFull: + return stdAc::swingv_t::kHighest; + case kArgoFlap5: + return stdAc::swingv_t::kHigh; + case kArgoFlap4: + return stdAc::swingv_t::kMiddle; + case kArgoFlap3: + return stdAc::swingv_t::kLow; + case kArgoFlap1: + return stdAc::swingv_t::kLowest; + default: + return stdAc::swingv_t::kAuto; + } +} +/// @endcond + +/// Convert a native flap mode into its stdAc equivalent (WREM3). +/// @note This is a full specialization for @c ArgoProtocolWREM3 type and while +/// it semantically belongs to @c IrArgoAC_WREM3 class impl., it has *not* +/// been pushed there, to avoid having to use a virtual function +/// @param[in] position The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +/// @relates IRArgoACBase\ +template<> +stdAc::swingv_t IRArgoACBase::toCommonSwingV( + const uint8_t position) { + switch (static_cast(position)) { + case argoFlap_t::FLAP_FULL: + return stdAc::swingv_t::kOff; + case argoFlap_t::FLAP_6: + return stdAc::swingv_t::kHighest; + case argoFlap_t::FLAP_5: + return stdAc::swingv_t::kHigh; + case argoFlap_t::FLAP_4: + return stdAc::swingv_t::kUpperMiddle; + case argoFlap_t::FLAP_3: + return stdAc::swingv_t::kMiddle; + case argoFlap_t::FLAP_2: + return stdAc::swingv_t::kLow; + case argoFlap_t::FLAP_1: + return stdAc::swingv_t::kLowest; + case argoFlap_t::FLAP_AUTO: + default: + return stdAc::swingv_t::kAuto; + } +} + +/// Convert a native message type into its stdAc equivalent. +/// @param[in] command The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +template +stdAc::ac_command_t IRArgoACBase::toCommonCommand( + const argoIrMessageType_t command) { + switch (command) { + case argoIrMessageType_t::AC_CONTROL: + return stdAc::ac_command_t::kControlCommand; + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + return stdAc::ac_command_t::kSensorTempReport; + case argoIrMessageType_t::TIMER_COMMAND: + return stdAc::ac_command_t::kTimerCommand; + case argoIrMessageType_t::CONFIG_PARAM_SET: + return stdAc::ac_command_t::kConfigCommand; + default: + return stdAc::ac_command_t::kControlCommand; } } /// Convert a native mode into its stdAc equivalent. /// @param[in] mode The native setting to be converted. /// @return The stdAc equivalent of the native setting. -stdAc::opmode_t IRArgoAC::toCommonMode(const uint8_t mode) { +template +stdAc::opmode_t IRArgoACBase::toCommonMode(const argoMode_t mode) { switch (mode) { - case kArgoCool: return stdAc::opmode_t::kCool; - case kArgoHeat: return stdAc::opmode_t::kHeat; - case kArgoDry: return stdAc::opmode_t::kDry; - // No fan mode. + case argoMode_t::COOL: return stdAc::opmode_t::kCool; + case argoMode_t::DRY : return stdAc::opmode_t::kDry; + case argoMode_t::FAN : return stdAc::opmode_t::kFan; + case argoMode_t::HEAT : return stdAc::opmode_t::kHeat; + case argoMode_t::AUTO : return stdAc::opmode_t::kAuto; default: return stdAc::opmode_t::kAuto; } } @@ -332,11 +1229,16 @@ stdAc::opmode_t IRArgoAC::toCommonMode(const uint8_t mode) { /// Convert a native fan speed into its stdAc equivalent. /// @param[in] speed The native setting to be converted. /// @return The stdAc equivalent of the native setting. -stdAc::fanspeed_t IRArgoAC::toCommonFanSpeed(const uint8_t speed) { +template +stdAc::fanspeed_t IRArgoACBase::toCommonFanSpeed(const argoFan_t speed) { switch (speed) { - case kArgoFan3: return stdAc::fanspeed_t::kMax; - case kArgoFan2: return stdAc::fanspeed_t::kMedium; - case kArgoFan1: return stdAc::fanspeed_t::kMin; + case argoFan_t::FAN_AUTO: return stdAc::fanspeed_t::kAuto; + case argoFan_t::FAN_HIGHEST: return stdAc::fanspeed_t::kMax; + case argoFan_t::FAN_HIGH: return stdAc::fanspeed_t::kHigh; + case argoFan_t::FAN_MEDIUM: return stdAc::fanspeed_t::kMediumHigh; + case argoFan_t::FAN_LOW: return stdAc::fanspeed_t::kMedium; + case argoFan_t::FAN_LOWER: return stdAc::fanspeed_t::kLow; + case argoFan_t::FAN_LOWEST: return stdAc::fanspeed_t::kMin; default: return stdAc::fanspeed_t::kAuto; } } @@ -346,15 +1248,18 @@ stdAc::fanspeed_t IRArgoAC::toCommonFanSpeed(const uint8_t speed) { stdAc::state_t IRArgoAC::toCommon(void) const { stdAc::state_t result{}; result.protocol = decode_type_t::ARGO; + result.model = argo_ac_remote_model_t::SAC_WREM2; + result.command = toCommonCommand(_messageType); result.power = _.Power; - result.mode = toCommonMode(_.Mode); + result.mode = toCommonMode(getModeEx()); result.celsius = true; result.degrees = getTemp(); - result.fanspeed = toCommonFanSpeed(_.Fan); + result.sensorTemperature = getSensorTemp(); + result.iFeel = getiFeel(); + result.fanspeed = toCommonFanSpeed(getFanEx()); result.turbo = _.Max; result.sleep = _.Night ? 0 : -1; // Not supported. - result.model = -1; // Not supported. result.swingv = stdAc::swingv_t::kOff; result.swingh = stdAc::swingh_t::kOff; result.light = false; @@ -367,71 +1272,413 @@ stdAc::state_t IRArgoAC::toCommon(void) const { return result; } -/// Convert the current internal state into a human readable string. +/// Convert the current internal state into its stdAc::state_t equivalent. +/// @return The stdAc equivalent of the native settings. +stdAc::state_t IRArgoAC_WREM3::toCommon(void) const { + stdAc::state_t result{}; + result.protocol = decode_type_t::ARGO; + result.model = argo_ac_remote_model_t::SAC_WREM3; + result.command = toCommonCommand(_messageType); + result.power = getPower(); + result.mode = toCommonMode(getModeEx()); + result.celsius = true; + result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); + result.iFeel = getiFeel(); + result.fanspeed = toCommonFanSpeed(getFanEx()); + result.turbo = _.Max; + result.swingv = toCommonSwingV(_.Flap); + result.light = getLight(); + result.filter = getFilter(); + result.econo = getEco(); + result.quiet = getNight(); + result.beep = (_messageType != argoIrMessageType_t::IFEEL_TEMP_REPORT); + + result.clock = -1; + result.sleep = _.Night ? 0 : -1; + if (_messageType == argoIrMessageType_t::TIMER_COMMAND) { + result.clock = getCurrentTimeMinutes(); + result.sleep = getDelayTimerMinutes(); + } + + // Not supported. + result.swingh = stdAc::swingh_t::kOff; + result.clean = false; + + + return result; +} + + +namespace { + /// @brief Short-hand for casting enum to its underlying storage type + /// @tparam E The type of enum + /// @param e Enum value + /// @return Type of underlying value + template + constexpr typename std::underlying_type::type to_underlying(E e) noexcept { + return static_cast::type>(e); + } +} + +/// Convert the current internal state into a human readable string (WREM2). /// @return A human readable string. String IRArgoAC::toString(void) const { String result = ""; - result.reserve(100); // Reserve some heap for the string to reduce fragging. - result += addBoolToString(_.Power, kPowerStr, false); - result += addIntToString(_.Mode, kModeStr); - result += kSpaceLBraceStr; - switch (_.Mode) { - case kArgoAuto: - result += kAutoStr; - break; - case kArgoCool: - result += kCoolStr; - break; - case kArgoHeat: - result += kHeatStr; - break; - case kArgoDry: - result += kDryStr; - break; - case kArgoHeatAuto: - result += kHeatStr; - result += ' '; - result += kAutoStr; - break; - case kArgoOff: - result += kOffStr; - break; - default: - result += kUnknownStr; + result.reserve(118); // Reserve some heap for the string to reduce fragging. + // E.g.: Model: 1 (WREM2), Power: On, Mode: 0 (Cool), Fan: 0 (Auto), + // Temp: 20C, Room Temp: 21C, Max: On, IFeel: On, Night: On + result += addModelToString(decode_type_t::ARGO, + argo_ac_remote_model_t::SAC_WREM2, false); + if (_messageType == argoIrMessageType_t::IFEEL_TEMP_REPORT) { + result += addIntToString(getSensorTemp(), kSensorTempStr); + result += 'C'; + } else { + result += addBoolToString(_.Power, kPowerStr); + result += addIntToString(_.Mode, kModeStr); + result += kSpaceLBraceStr; + switch (_.Mode) { + case kArgoAuto: + result += kAutoStr; + break; + case kArgoCool: + result += kCoolStr; + break; + case kArgoHeat: + result += kHeatStr; + break; + case kArgoDry: + result += kDryStr; + break; + case kArgoHeatAuto: + result += kHeatStr; + result += ' '; + result += kAutoStr; + break; + case kArgoOff: + result += kOffStr; + break; + default: + result += kUnknownStr; + } + result += ')'; + result += addIntToString(_.Fan, kFanStr); + result += kSpaceLBraceStr; + switch (_.Fan) { + case kArgoFanAuto: + result += kAutoStr; + break; + case kArgoFan3: + result += kMaxStr; + break; + case kArgoFan1: + result += kMinStr; + break; + case kArgoFan2: + result += kMedStr; + break; + default: + result += kUnknownStr; + } + result += ')'; + result += addTempToString(getTemp()); + result += addTempToString(getSensorTemp(), true, true, true); + result += addBoolToString(_.Max, kMaxStr); + result += addBoolToString(_.iFeel, kIFeelStr); + result += addBoolToString(_.Night, kNightStr); } - result += ')'; - result += addIntToString(_.Fan, kFanStr); - result += kSpaceLBraceStr; - switch (_.Fan) { - case kArgoFanAuto: - result += kAutoStr; - break; - case kArgoFan3: - result += kMaxStr; - break; - case kArgoFan1: - result += kMinStr; + return result; +} + +/// @brief Set current clock (as minutes, counted from 0:00) +/// E.g. 13:38 becomes 818 (13*60+38) +/// @param currentTimeMinutes Current time (in minutes) +void IRArgoAC_WREM3::setCurrentTimeMinutes(uint16_t currentTimeMinutes) { + uint16_t time = std::min(currentTimeMinutes, static_cast(23*60+59)); + _.timer.CurrentTimeHi = (time >> 4); + _.timer.CurrentTimeLo = (time & 0b1111); +} + +/// @brief Retrieve current time +/// @return Current time as minutes from 0:00 +uint16_t IRArgoAC_WREM3::getCurrentTimeMinutes(void) const { + return (_.timer.CurrentTimeHi << 4) + _.timer.CurrentTimeLo; +} + +/// @brief Set current day of week +/// @param dayOfWeek Current day of week +void IRArgoAC_WREM3::setCurrentDayOfWeek(argoWeekday dayOfWeek) { + uint8_t day = std::min(to_underlying(dayOfWeek), + to_underlying(argoWeekday::SATURDAY)); + _.timer.CurrentWeekdayHi = (day >> 1); + _.timer.CurrentWeekdayLo = (day & 0b1); +} + +/// @brief Get current day of week +/// @return Current day of week +argoWeekday IRArgoAC_WREM3::getCurrentDayOfWeek(void) const { + return static_cast((_.timer.CurrentWeekdayHi << 1) + + _.timer.CurrentWeekdayLo); +} + +/// @brief Set timer type +/// @param timerType Timer type to use OFF | DELAY | SCHEDULE<1|2|3> +/// @note 2 timer types supported: delay | schedule timer +/// - @c DELAY_TIMER requires setting @c setDelayTimerMinutes +/// and @c setCurrentTimeMinutes and (optionally) @c setCurrentDayOfWeek +/// - @c SCHEDULE_TIMER requires setting: +/// @c setScheduleTimerStartMinutes +/// @c setScheduleTimerStopMinutes +/// @c setScheduleTimerActiveDays +/// as well as current time *and* day +/// @c setCurrentTimeMinutes and @c setCurrentDayOfWeek +void IRArgoAC_WREM3::setTimerType(const argoTimerType_t timerType) { + if (timerType > argoTimerType_t::SCHEDULE_TIMER_3) { + _.timer.TimerType = to_underlying(argoTimerType_t::NO_TIMER); + } else { + _.timer.TimerType = to_underlying(timerType); + } +} + +/// @brief Get currently set timer type +/// @return Timer type +argoTimerType_t IRArgoAC_WREM3::getTimerType(void) const { + return static_cast(_.timer.TimerType); +} + +/// @brief Set delay timer delay in minutes (10-minute increments only) +/// Max is 1190 (19h50m) +/// @note The delay timer also accepts current device state: set by @c setPower +/// @param delayMinutes Delay minutes +void IRArgoAC_WREM3::setDelayTimerMinutes(const uint16_t delayMinutes) { + const uint16_t DELAY_TIMER_MAX = 19*60+50; + uint16_t time = std::min(delayMinutes, DELAY_TIMER_MAX); + + // only full 10 minute increments are allowed + time = static_cast((time / 10.0) + 0.5) * 10; + + _.timer.DelayTimeHi = (time >> 6); + _.timer.DelayTimeLo = (time & 0b111111); +} + +/// @brief Get current delay timer value +/// @return Delay timer value (in minutes) +uint16_t IRArgoAC_WREM3::getDelayTimerMinutes(void) const { + return (_.timer.DelayTimeHi << 6) + _.timer.DelayTimeLo; +} + +/// @brief Set schedule timer on time (time when the device should turn on) +/// (10-minute increments only) +/// @param startTimeMinutes Time when the device should turn itself on +/// expressed as # of minutes counted from 0:00 +/// The value is in 10-minute increments (rounded) +/// E.g. 13:38 becomes 820 (13:40 in minutes) +void IRArgoAC_WREM3::setScheduleTimerStartMinutes( + const uint16_t startTimeMinutes) { + const uint16_t SCHEDULE_TIMER_MAX = 23*60+50; + uint16_t time = std::min(startTimeMinutes, SCHEDULE_TIMER_MAX); + + // only full 10 minute increments are allowed + time = static_cast((time / 10.0) + 0.5) * 10; + + _.timer.TimerStartHi = (time >> 3); + _.timer.TimerStartLo = (time & 0b111); +} + +/// @brief Get schedule timer ON time +/// @return Schedule on time (as # of minutes from 0:00) +uint16_t IRArgoAC_WREM3::getScheduleTimerStartMinutes(void) const { + return (_.timer.TimerStartHi << 3) + _.timer.TimerStartLo; +} + +/// @brief Set schedule timer off time (time when the device should turn off) +/// (10-minute increments only) +/// @param stopTimeMinutes Time when the device should turn itself off +/// expressed as # of minutes counted from 0:00 +/// The value is in 10-minute increments (rounded) +/// E.g. 13:38 becomes 820 (13:40 in minutes) +void IRArgoAC_WREM3::setScheduleTimerStopMinutes( + const uint16_t stopTimeMinutes) { + const uint16_t SCHEDULE_TIMER_MAX = 23*60+50; + uint16_t time = std::min(stopTimeMinutes, SCHEDULE_TIMER_MAX); + + // only full 10 minute increments are allowed + time = static_cast((time / 10.0) + 0.5) * 10; + + _.timer.TimerEndHi = (time >> 8); + _.timer.TimerEndLo = (time & 0b11111111); +} + +/// @brief Get schedule timer OFF time +/// @return Schedule off time (as # of minutes from 0:00) +uint16_t IRArgoAC_WREM3::getScheduleTimerStopMinutes(void) const { + return (_.timer.TimerEndHi << 8) + _.timer.TimerEndLo; +} + +/// @brief Get the days when shedule timer shall be active (as bitmap) +/// @return Days when schedule timer is active, as raw bitmap type +/// where bit[0] is Sunday, bit[1] -> Monday, ... +uint8_t IRArgoAC_WREM3::getTimerActiveDaysBitmap(void) const { + return (_.timer.TimerActiveDaysHi << 5) + _.timer.TimerActiveDaysLo; +} + +/// @brief Set the days when the schedule timer shall be active +/// @param days A set of days when the timer shall run +void IRArgoAC_WREM3::setScheduleTimerActiveDays( + const std::set& days) { + uint8_t daysBitmap = 0; + for (const argoWeekday& day : days) { + daysBitmap |= (0b1 << to_underlying(day)); + } + _.timer.TimerActiveDaysHi = (daysBitmap >> 5); + _.timer.TimerActiveDaysLo = (daysBitmap & 0b11111); +} + +/// @brief Get the days when shedule timer shall be active (as set) +/// @return Days when the schedule timer runs +std::set IRArgoAC_WREM3::getScheduleTimerActiveDays(void) const { + std::set result = {}; + uint8_t daysBitmap = getTimerActiveDaysBitmap(); + for (uint8_t i = to_underlying(argoWeekday::SUNDAY); + i <= to_underlying(argoWeekday::SATURDAY); + ++i) { + if (((daysBitmap >> i) & 0b1) == 0b1) { + result.insert(static_cast(i)); + } + } + return result; +} + +/// @brief Get device model +/// @return Device model +argo_ac_remote_model_t IRArgoAC_WREM3::getModel() const { + return argo_ac_remote_model_t::SAC_WREM3; +} + +namespace { + String commandTypeToString(argoIrMessageType_t type, uint8_t channel) { + String result = irutils::irCommandTypeToString(to_underlying(type), + to_underlying(argoIrMessageType_t::AC_CONTROL), + to_underlying(argoIrMessageType_t::IFEEL_TEMP_REPORT), + to_underlying(argoIrMessageType_t::TIMER_COMMAND), + to_underlying(argoIrMessageType_t::CONFIG_PARAM_SET)); + result += irutils::channelToString(channel); + result += kColonSpaceStr; + return result; + } +} // namespace + +/// Convert the current internal state into a human readable string (WREM3). +/// @return A human readable string. +String IRArgoAC_WREM3::toString(void) const { + String result = ""; + result.reserve(190); // Reserve some heap for the string to reduce fragging. + // E.g.: Command[CH#0]: Model: 2 (WREM3), Power: On, Mode: 1 (Cool), + // Temp: 22C, Room: 26C, Fan: 0 (Auto), Swing(V): 7 (Breeze), + // IFeel: Off, Night: Off, Econo: Off, Max: Off, Filter: Off, Light: On + // Temp: 20C, Room Temp: 21C, Max: On, IFeel: On, Night: On + + argoIrMessageType_t commandType = this->getMessageType(); + argo_ac_remote_model_t model = getModel(); + + result += commandTypeToString(commandType, getChannel()); + result += addModelToString(decode_type_t::ARGO, model, false); + + switch (commandType) { + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + result += addTempToString(getSensorTemp(), true, true, true); break; - case kArgoFan2: - result += kMedStr; + + case argoIrMessageType_t::AC_CONTROL: + result += addBoolToString(getPower(), kPowerStr); + result += addModeToString(to_underlying(getModeEx()), + to_underlying(argoMode_t::AUTO), + to_underlying(argoMode_t::COOL), + to_underlying(argoMode_t::HEAT), + to_underlying(argoMode_t::DRY), + to_underlying(argoMode_t::FAN)); + result += addTempToString(getTemp()); + result += addTempToString(getSensorTemp(), true, true, true); + result += addFanToString(to_underlying(getFanEx()), + to_underlying(argoFan_t::FAN_HIGH), + to_underlying(argoFan_t::FAN_LOWER), + to_underlying(argoFan_t::FAN_AUTO), + to_underlying(argoFan_t::FAN_LOWEST), + to_underlying(argoFan_t::FAN_LOW), + to_underlying(argoFan_t::FAN_HIGHEST), + to_underlying(argoFan_t::FAN_MEDIUM)); + result += addSwingVToString(to_underlying(getFlapEx()), + to_underlying(argoFlap_t::FLAP_AUTO), + to_underlying(argoFlap_t::FLAP_1), + to_underlying(argoFlap_t::FLAP_2), + to_underlying(argoFlap_t::FLAP_3), + to_underlying(argoFlap_t::FLAP_4), -1, + to_underlying(argoFlap_t::FLAP_5), + to_underlying(argoFlap_t::FLAP_6), -1, -1, + to_underlying(argoFlap_t::FLAP_FULL), -1); + result += addBoolToString(getiFeel(), kIFeelStr); + result += addBoolToString(getNight(), kNightStr); + result += addBoolToString(getEco(), kEconoStr); + result += addBoolToString(getMax(), kMaxStr); // Turbo + result += addBoolToString(getFilter(), kFilterStr); + result += addBoolToString(getLight(), kLightStr); break; - default: - result += kUnknownStr; - } - result += ')'; - result += addTempToString(getTemp()); - result += kCommaSpaceStr; - result += kRoomStr; - result += ' '; - result += addTempToString(getRoomTemp(), true, false); - result += addBoolToString(_.Max, kMaxStr); - result += addBoolToString(_.iFeel, kIFeelStr); - result += addBoolToString(_.Night, kNightStr); + + case argoIrMessageType_t::TIMER_COMMAND: + result += addBoolToString(_.timer.IsOn, kPowerStr); + result += addTimerModeToString(to_underlying(getTimerType()), + to_underlying(argoTimerType_t::NO_TIMER), + to_underlying(argoTimerType_t::DELAY_TIMER), + to_underlying(argoTimerType_t::SCHEDULE_TIMER_1), + to_underlying(argoTimerType_t::SCHEDULE_TIMER_2), + to_underlying(argoTimerType_t::SCHEDULE_TIMER_3)); + result += addLabeledString(minsToString(getCurrentTimeMinutes()), + kClockStr); + result += addDayToString(to_underlying(getCurrentDayOfWeek())); + switch (getTimerType()) { + case argoTimerType_t::NO_TIMER: + result += addLabeledString(kOffStr, kTimerStr); + break; + case argoTimerType_t::DELAY_TIMER: + result += addLabeledString(minsToString(getDelayTimerMinutes()), + kTimerStr); + break; + default: + result += addLabeledString(minsToString(getScheduleTimerStartMinutes()), + kOnTimerStr); + result += addLabeledString(minsToString(getScheduleTimerStopMinutes()), + kOffTimerStr); + + result += addLabeledString(daysBitmaskToString( + getTimerActiveDaysBitmap()), kTimerActiveDaysStr); + break; + } + break; + + case argoIrMessageType_t::CONFIG_PARAM_SET: + result += addIntToString(_.config.Key, kKeyStr); + result += addIntToString(_.config.Value, kValueStr); + break; + } + return result; } +/// @brief Check if raw ARGO state starts with valid WREM3 preamble +/// @param state The state bytes +/// @param length Length of state in bytes +/// @return True if state starts wiht valid WREM3 preamble, False otherwise +bool IRArgoAC_WREM3::hasValidPreamble(const uint8_t state[], + const uint16_t length) { + if (length < 1) { + return false; + } + uint8_t preamble = state[0] & 0x0F; + return preamble == kArgoWrem3Preamble; +} + #if DECODE_ARGO -/// Decode the supplied Argo message. +/// Decode the supplied Argo message (WREM2). /// Status: BETA / Probably works. /// @param[in,out] results Ptr to the data to decode & where to store the decode /// result. @@ -458,7 +1705,9 @@ bool IRrecv::decodeArgo(decode_results *results, uint16_t offset, // Compliance // Verify we got a valid checksum. - if (strict && !IRArgoAC::validChecksum(results->state)) return false; + if (strict && !IRArgoAC::validChecksum(results->state, kArgoStateLength)) { + return false; + } // Success results->decode_type = decode_type_t::ARGO; results->bits = nbits; @@ -467,4 +1716,107 @@ bool IRrecv::decodeArgo(decode_results *results, uint16_t offset, // is a union data type. return true; } + +/// Decode the supplied Argo message (WREM3). +/// Status: Confirmed working w/ Argo 13 ECO (WREM-3) +/// @param[in,out] results Ptr to the data to decode & where to store the decode +/// result. +/// @param[in] offset The starting index to use when attempting to decode the +/// raw data. Typically/Defaults to kStartOffset. +/// @param[in] nbits The number of data bits to expect. +/// @param[in] strict Flag indicating if we should perform strict matching. +/// @return A boolean. True if it can decode it, false if it can't. +/// @note This decoder is separate from @c decodeArgo to maintain backwards +/// compatibility. Contrary to WREM2, this expects a footer and gap! +bool IRrecv::decodeArgoWREM3(decode_results *results, uint16_t offset, + const uint16_t nbits, + const bool strict) { + if (strict + && nbits != kArgo3AcControlStateLength * 8 + && nbits != kArgo3ConfigStateLength * 8 + && nbits != kArgo3iFeelReportStateLength * 8 + && nbits != kArgo3TimerStateLength * 8) { + return false; + } + + uint16_t bytesRead = matchGeneric(results->rawbuf + offset, results->state, + results->rawlen - offset, nbits, + kArgoHdrMark, kArgoHdrSpace, + kArgoBitMark, kArgoOneSpace, + kArgoBitMark, kArgoZeroSpace, + kArgoBitMark, kArgoGap, // difference vs decodeArgo + true, _tolerance, 0, + false); + if (!bytesRead) { + return false; + } + + // If 'strict', assert it is a valid WREM-3 'model' protocolar message + // vs. just 'any ARGO' + if (strict && + !IRArgoAC_WREM3::isValidWrem3Message(results->state, nbits, true)) { + return false; + } + + // Success: Matched ARGO protocol and WREM3-model + // Note that unfortunately decode_type does not allow to persist model... + // so we will be re-detecting it later :) + results->decode_type = decode_type_t::ARGO; + 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; +} + +/// @brief Detects if an ARGO protocol message is a WREM-3 sub-type (model) +/// @param state The raw IR decore state +/// @param nbits The length of @c state **IN BITS** +/// @param verifyChecksum Whether to perform checksum verification +/// @return True if the message is a WREM-3 one +bool IRArgoAC_WREM3::isValidWrem3Message(const uint8_t state[], + const uint16_t nbits, + bool verifyChecksum) { + if ((nbits % 8) != 0) { + return false; // WREM-3 protocol always has a full byte length commands + } + uint16_t stateLengthBytes = std::min(static_cast(nbits / 8), + kStateSizeMax); + if (!IRArgoAC_WREM3::hasValidPreamble(state, stateLengthBytes)) { + return false; + } + + argoIrMessageType_t messageType = IRArgoACBase + ::getMessageType(state, stateLengthBytes); + + switch (messageType) { + case argoIrMessageType_t::AC_CONTROL : + if (stateLengthBytes != kArgo3AcControlStateLength) { return false; } + break; + case argoIrMessageType_t::CONFIG_PARAM_SET: + if (stateLengthBytes != kArgo3ConfigStateLength) { return false; } + break; + case argoIrMessageType_t::TIMER_COMMAND: + if (stateLengthBytes != kArgo3TimerStateLength) { return false; } + break; + case argoIrMessageType_t::IFEEL_TEMP_REPORT: + if (stateLengthBytes != kArgo3iFeelReportStateLength) { return false; } + break; + default: + return false; + } + + // Compliance: Verify we got a valid checksum. + if (verifyChecksum && + !IRArgoAC_WREM3::validChecksum(state, stateLengthBytes)) { + return false; + } + return true; +} + #endif // DECODE_ARGO + + +// force template instantiation +template class IRArgoACBase; +template class IRArgoACBase; diff --git a/lib/IRremoteESP8266/src/ir_Argo.h b/lib/IRremoteESP8266/src/ir_Argo.h index 6ceb58e421..ba804f93c1 100644 --- a/lib/IRremoteESP8266/src/ir_Argo.h +++ b/lib/IRremoteESP8266/src/ir_Argo.h @@ -1,13 +1,18 @@ // Copyright 2017 Schmolders +// Copyright 2022 crankyoldgit +// Copyright 2022 Mateusz Bronk (mbronk) /// @file /// @brief Support for Argo Ulisse 13 DCI Mobile Split ACs. // Supports: -// Brand: Argo, Model: Ulisse 13 DCI Mobile Split A/C +// Brand: Argo, Model: Ulisse 13 DCI Mobile Split A/C [WREM2 remote] +// Brand: Argo, Model: Ulisse Eco Mobile Split A/C (Wifi) [WREM3 remote] #ifndef IR_ARGO_H_ #define IR_ARGO_H_ +#include +#include #ifndef UNIT_TEST #include #endif @@ -20,14 +25,14 @@ // ARGO Ulisse DCI -/// Native representation of a Argo A/C message. +/// Native representation of a Argo A/C message for WREM-2 remote. union ArgoProtocol { uint8_t raw[kArgoStateLength]; ///< The state in native IR code form struct { // Byte 0 - uint64_t :8; // Typically 0b00110101 + uint64_t Pre1 :8; // Typically 0b00110101 // Byte 1 - uint64_t :8; // Typically 0b10101111 + uint64_t Pre2 :8; // Typically 0b10101111 // Byte 2~4 uint64_t :3; uint64_t Mode :3; @@ -57,17 +62,143 @@ union ArgoProtocol { uint32_t :1; // const 0 uint32_t iFeel :1; // Byte 10~11 - uint32_t :2; // const 01 + uint32_t Post :2; uint32_t Sum :8; // straddle byte 10 and 11 uint32_t :6; }; + struct { + // Byte 0-1 + uint8_t :8; + uint8_t :8; + // Byte 2-3 + uint8_t CheckHi :3; + uint8_t SensorT :5; + uint8_t Fixed :3; // Typically 0b011 + uint8_t CheckLo :5; + }; }; -// Constants. Store MSB left. +/// Native representation of A/C IR message for WREM-3 remote +/// @note The remote sends 4 different IR command types, varying in length +/// and methods of checksum calculation +/// - [0b00] Regular A/C command (change operation mode) - 6-byte +/// - [0b01] iFeel Temperature report - 2-byte +/// - [0b10] Timer command - 9-byte +/// - [0b11] Config command - 4-byte +/// @note The 1st 2 structures are unnamed for compat. with @c ArgoProtocol +/// 1st byte definition is a header common across all commands though +union ArgoProtocolWREM3 { + uint8_t raw[kArgoStateLength]; ///< The state in native IR code form + struct { + // Byte 0 (same definition across the union) + uint8_t Pre1 :4; /// Preamble: 0b1011 @ref kArgoWrem3Preamble + uint8_t IrChannel :2; /// 0..3 range + uint8_t IrCommandType :2; /// @ref argoIrMessageType_t + // Byte 1 + uint8_t RoomTemp :5; // in Celsius, range: 4..35 (offset by -4[*C]) + uint8_t Mode :3; /// @ref argoMode_t + // Byte 2 + uint8_t Temp :5; // in Celsius, range: 10..32 (offset by -4[*C]) + uint8_t Fan :3; /// @ref argoFan_t + // Byte3 + uint8_t Flap :3; /// SwingV @ref argoFlap_t + uint8_t Power :1; + uint8_t iFeel :1; + uint8_t Night :1; + uint8_t Eco :1; + uint8_t Max :1; ///< a.k.a. Turbo + // Byte4 + uint8_t Filter :1; + uint8_t Light :1; + uint8_t Post1 :6; /// Unknown, always 0b110000 (TempScale?) + // Byte5 + uint8_t Sum :8; /// Checksum + }; + struct { + // Byte 0 (same definition across the union) + uint8_t :8; // {Pre1 | IrChannel | IrCommandType} + // Byte 1 + uint8_t SensorT :5; // in Celsius, range: 4..35 (offset by -4[*C]) + uint8_t CheckHi :3; // Checksum (short) + }; + struct Timer { + // Byte 0 (same definition across the union) + uint8_t : 8; // {Pre1 | IrChannel | IrCommandType} + // Byte 1 + uint8_t IsOn : 1; + uint8_t TimerType : 3; + uint8_t CurrentTimeLo : 4; + // Byte 2 + uint8_t CurrentTimeHi : 7; + uint8_t CurrentWeekdayLo : 1; + // Byte 3 + uint8_t CurrentWeekdayHi : 2; + uint8_t DelayTimeLo : 6; + // Byte 4 + uint8_t DelayTimeHi : 5; + uint8_t TimerStartLo : 3; + // Byte 5 + uint8_t TimerStartHi : 8; + // Byte 6 + uint8_t TimerEndLo : 8; + // Byte 7 + uint8_t TimerEndHi : 3; + uint8_t TimerActiveDaysLo : 5; // Bitmap (LSBit is Sunday) + // Byte 8 + uint8_t TimerActiveDaysHi : 2; // Bitmap (LSBit is Sunday) + uint8_t Post1 : 1; // Unknown, always 1 + uint8_t Checksum : 5; + } timer; + struct Config { + uint8_t :8; // Byte 0 {Pre1 | IrChannel | IrCommandType} + uint8_t Key :8; // Byte 1 + uint8_t Value :8; // Byte 2 + uint8_t Checksum :8; // Byte 3 + } config; +}; -const uint8_t kArgoHeatBit = 0b00100000; +// Constants (WREM-2). Store MSB left. +const uint8_t kArgoHeatBit = 0b00100000; +const uint8_t kArgoPreamble1 = 0b10101100; +const uint8_t kArgoPreamble2 = 0b11110101; +const uint8_t kArgoPost = 0b00000010; + +// Constants (generic) +const uint16_t kArgoFrequency = 38000; // Hz +// Temp +const uint8_t kArgoTempDelta = 4; +const uint8_t kArgoMaxRoomTemp = 35; // Celsius +const uint8_t kArgoMinTemp = 10; // Celsius delta +4 +const uint8_t kArgoMaxTemp = 32; // Celsius +const uint8_t kArgoMaxChannel = 3; + + +/// @brief IR message type (determines the payload part of IR command) +/// @note Raw values match WREM-3 protocol, but the enum is used in generic +/// context +/// @note WREM-3 remote supports all commands separately, whereas +/// WREM-2 (allegedly) only has the @c AC_CONTROL and @c IFEEL_TEMP_REPORT +/// (timers are part of @c AC_CONTROL command), and there's no config. +enum class argoIrMessageType_t : uint8_t { + AC_CONTROL = 0b00, + IFEEL_TEMP_REPORT = 0b01, + TIMER_COMMAND = 0b10, // WREM-3 only (WREM-2 has it under AC_CONTROL) + CONFIG_PARAM_SET = 0b11 // WREM-3 only +}; + +/// @brief A/C operation mode +/// @note Raw values match WREM-3 protocol, but the enum is used in generic +/// context +enum class argoMode_t : uint8_t { + COOL = 0b001, + DRY = 0b010, + HEAT = 0b011, + FAN = 0b100, + AUTO = 0b101 +}; -// Mode 0b00111000 +// Raw mode definitions for WREM-2 remote +// (not wraped into a ns nor enum for backwards-compat.) const uint8_t kArgoCool = 0b000; const uint8_t kArgoDry = 0b001; const uint8_t kArgoAuto = 0b010; @@ -77,19 +208,42 @@ const uint8_t kArgoHeatAuto = 0b101; // ?no idea what mode that is const uint8_t kArgoHeatBlink = 0b110; -// Fan 0b00011000 +/// @brief Fan speed +/// @note Raw values match WREM-3 protocol, but the enum is used in generic +/// context +enum class argoFan_t : uint8_t { + FAN_AUTO = 0b000, + FAN_LOWEST = 0b001, + FAN_LOWER = 0b010, + FAN_LOW = 0b011, + FAN_MEDIUM = 0b100, + FAN_HIGH = 0b101, + FAN_HIGHEST = 0b110 +}; + +// Raw fan speed definitions for WREM-2 remote +// (not wraped into a ns nor enum for backwards-compat.) const uint8_t kArgoFanAuto = 0; // 0b00 const uint8_t kArgoFan1 = 1; // 0b01 const uint8_t kArgoFan2 = 2; // 0b10 const uint8_t kArgoFan3 = 3; // 0b11 -// Temp -const uint8_t kArgoTempDelta = 4; -const uint8_t kArgoMaxRoomTemp = 35; // Celsius -const uint8_t kArgoMinTemp = 10; // Celsius delta +4 -const uint8_t kArgoMaxTemp = 32; // Celsius +/// @brief Flap position (swing-V) +/// @note Raw values match WREM-3 protocol, but the enum is used in generic +/// context +enum class argoFlap_t : uint8_t { + FLAP_AUTO = 0, + FLAP_1 = 1, // Highest + FLAP_2 = 2, + FLAP_3 = 3, + FLAP_4 = 4, + FLAP_5 = 5, + FLAP_6 = 6, // Lowest + FLAP_FULL = 7 +}; -// Flap/SwingV +// Raw Flap/SwingV definitions for WREM-2 remote +// (not wraped into a ns nor enum for backwards-compat.) const uint8_t kArgoFlapAuto = 0; const uint8_t kArgoFlap1 = 1; const uint8_t kArgoFlap2 = 2; @@ -123,12 +277,52 @@ const uint8_t kArgoFlapFull = 7; #define ARGO_FLAP_FULL kArgoFlapFull -/// Class for handling detailed Argo A/C messages. -class IRArgoAC { +/// @brief Timer type to set (for @c argoIrMessageType_t::TIMER_COMMAND) +/// @note Raw values match WREM-3 protocol +enum class argoTimerType_t : uint8_t { + NO_TIMER = 0b000, + DELAY_TIMER = 0b001, + SCHEDULE_TIMER_1 = 0b010, + SCHEDULE_TIMER_2 = 0b011, + SCHEDULE_TIMER_3 = 0b100 +}; + +/// @brief Day type to set (for @c argoIrMessageType_t::TIMER_COMMAND) +/// @note Raw values match WREM-3 protocol +enum class argoWeekday : uint8_t { + SUNDAY = 0b000, + MONDAY = 0b001, + TUESDAY = 0b010, + WEDNESDAY = 0b011, + THURSDAY = 0b100, + FRIDAY = 0b101, + SATURDAY = 0b110 +}; + + + +/// @brief Base class for handling *common* support for Argo remote protocols +/// (functionality is shared across WREM-2 and WREM-3 IR protocols) +/// @note This class uses static polymorphism and full template specializations +/// when required, to avoid a performance penalty of doing v-table lookup. +/// 2 instantiations are forced in impl. file: for @c ArgoProtocol and +/// @c ArgoProtocolWREM3 +/// @note This class is abstract (though does not declare a pure-virtual fn. +/// for abovementioned reasons), and instead declares protected c-tor +/// @tparam ARGO_PROTOCOL_T The Raw device protocol/message used +template +class IRArgoACBase { +#ifndef UNIT_TEST // A less cloggy way of expressing FRIEND_TEST(...) + + protected: +#else + public: - explicit IRArgoAC(const uint16_t pin, const bool inverted = false, +#endif + explicit IRArgoACBase(const uint16_t pin, const bool inverted = false, const bool use_modulation = true); + public: #if SEND_ARGO void send(const uint16_t repeat = kArgoDefaultRepeat); /// Run the calibration to calculate uSec timing offsets for this platform. @@ -137,6 +331,7 @@ class IRArgoAC { /// Only ever needs to be run once per object instantiation, if at all. int8_t calibrate(void) { return _irsend.calibrate(); } #endif // SEND_ARGO + void begin(void); void on(void); void off(void); @@ -147,14 +342,20 @@ class IRArgoAC { void setTemp(const uint8_t degrees); uint8_t getTemp(void) const; - void setFan(const uint8_t fan); - uint8_t getFan(void) const; + void setSensorTemp(const uint8_t degrees); + uint8_t getSensorTemp(void) const; - void setFlap(const uint8_t flap); - uint8_t getFlap(void) const; + void setFan(const argoFan_t fan); + void setFanEx(const argoFan_t fan) { setFan(fan); } + argoFan_t getFanEx(void) const; ///< `-Ex` for backw. compat w/ @c IRArgoAC - void setMode(const uint8_t mode); - uint8_t getMode(void) const; + void setFlap(const argoFlap_t flap); + void setFlapEx(const argoFlap_t flap) { setFlap(flap); } + argoFlap_t getFlapEx(void) const; ///< `-Ex` for backw. compat w/ @c IRArgoAC + + void setMode(const argoMode_t mode); + void setModeEx(const argoMode_t mode) { setMode(mode); } + argoMode_t getModeEx(void) const; ///< `-Ex` for backw. compat w/ @c IRArgoAC void setMax(const bool on); bool getMax(void) const; @@ -165,41 +366,156 @@ class IRArgoAC { void setiFeel(const bool on); bool getiFeel(void) const; - void setTime(void); - void setRoomTemp(const uint8_t degrees); - uint8_t getRoomTemp(void) const; + void setMessageType(const argoIrMessageType_t msgType); + argoIrMessageType_t getMessageType(void) const; + static argoIrMessageType_t getMessageType(const uint8_t state[], + const uint16_t length); uint8_t* getRaw(void); - void setRaw(const uint8_t state[]); - static uint8_t calcChecksum(const uint8_t state[], - const uint16_t length = kArgoStateLength); - static bool validChecksum(const uint8_t state[], - const uint16_t length = kArgoStateLength); - static uint8_t convertMode(const stdAc::opmode_t mode); - static uint8_t convertFan(const stdAc::fanspeed_t speed); - static uint8_t convertSwingV(const stdAc::swingv_t position); - static stdAc::opmode_t toCommonMode(const uint8_t mode); - static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); - stdAc::state_t toCommon(void) const; - String toString(void) const; + uint16_t getRawByteLength() const; + static uint16_t getStateLengthForIrMsgType(argoIrMessageType_t type); + void setRaw(const uint8_t state[], const uint16_t length); + + static bool validChecksum(const uint8_t state[], const uint16_t length); + + static argoMode_t convertMode(const stdAc::opmode_t mode); + static argoFan_t convertFan(const stdAc::fanspeed_t speed); + static argoFlap_t convertSwingV(const stdAc::swingv_t position); + static argoIrMessageType_t convertCommand(const stdAc::ac_command_t command); + + protected: + void _stateReset(ARGO_PROTOCOL_T *state, argoIrMessageType_t messageType + = argoIrMessageType_t::AC_CONTROL); + void stateReset(argoIrMessageType_t messageType + = argoIrMessageType_t::AC_CONTROL); + void _checksum(ARGO_PROTOCOL_T *state); + void checksum(void); + static uint16_t getRawByteLength(const ARGO_PROTOCOL_T& raw, + argoIrMessageType_t messageTypeHint = argoIrMessageType_t::AC_CONTROL); + static uint8_t calcChecksum(const uint8_t state[], const uint16_t length); + static uint8_t getChecksum(const uint8_t state[], const uint16_t length); + + static stdAc::opmode_t toCommonMode(const argoMode_t mode); + static stdAc::fanspeed_t toCommonFanSpeed(const argoFan_t speed); + static stdAc::swingv_t toCommonSwingV(const uint8_t position); + static stdAc::ac_command_t toCommonCommand(const argoIrMessageType_t command); + + // Attributes + ARGO_PROTOCOL_T _; ///< The raw protocol data + uint16_t _length = kArgoStateLength; + argoIrMessageType_t _messageType = argoIrMessageType_t::AC_CONTROL; + #ifndef UNIT_TEST - private: + protected: IRsend _irsend; ///< instance of the IR send class #else + + public: /// @cond IGNORE IRsendTest _irsend; ///< instance of the testing IR send class /// @endcond #endif - // # of bytes per command - ArgoProtocol _; - void stateReset(void); - void checksum(void); +}; - // Attributes - uint8_t flap_mode; - uint8_t heat_mode; - uint8_t cool_mode; +/// @brief Supports Argo A/C SAC-WREM2 IR remote protocol +class IRArgoAC : public IRArgoACBase { + public: + explicit IRArgoAC(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + + #if SEND_ARGO + void sendSensorTemp(const uint8_t degrees, + const uint16_t repeat = kArgoDefaultRepeat); + #endif // SEND_ARGO + + String toString(void) const; + stdAc::state_t toCommon(void) const; + + using IRArgoACBase::setMode; + void setMode(const uint8_t mode); /// @deprecated, for backwards-compat. + uint8_t getMode(void) const; /// @deprecated, for backwards-compat. + + using IRArgoACBase::setFan; + void setFan(const uint8_t fan); /// @deprecated, for backwards-compat. + uint8_t getFan(void) const; /// @deprecated, for backwards-compat. + + using IRArgoACBase::setFlap; + void setFlap(const uint8_t flap); /// @deprecated, for backwards-compat. + uint8_t getFlap(void) const; /// @deprecated, for backwards-compat. +}; + +/// @brief Supports Argo A/C SAC-WREM3 IR remote protocol +class IRArgoAC_WREM3 : public IRArgoACBase { + public: + explicit IRArgoAC_WREM3(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + + #if SEND_ARGO + void sendSensorTemp(const uint8_t degrees, + const uint16_t repeat = kArgoDefaultRepeat); + #endif // SEND_ARGO + + argo_ac_remote_model_t getModel(void) const; + + + argoFan_t getFan(void) const; + argoFlap_t getFlap(void) const; + argoMode_t getMode(void) const; + + void setEco(const bool on); + bool getEco(void) const; + + void setFilter(const bool on); + bool getFilter(void) const; + + void setLight(const bool on); + bool getLight(void) const; + + void setChannel(const uint8_t channel); + uint8_t getChannel(void) const; + + void setConfigEntry(const uint8_t paramId, const uint8_t value); + std::pair getConfigEntry(void) const; + + void setCurrentTimeMinutes(uint16_t currentTimeMinutes); + uint16_t getCurrentTimeMinutes(void) const; + + void setCurrentDayOfWeek(argoWeekday dayOfWeek); + argoWeekday getCurrentDayOfWeek(void) const; + + void setTimerType(const argoTimerType_t timerType); + argoTimerType_t getTimerType(void) const; + + void setDelayTimerMinutes(const uint16_t delayMinutes); + uint16_t getDelayTimerMinutes(void) const; + + void setScheduleTimerStartMinutes(const uint16_t startTimeMinutes); + uint16_t getScheduleTimerStartMinutes(void) const; + // uint16_t getTimerXStartMinutes(void) const + + void setScheduleTimerStopMinutes(const uint16_t stopTimeMinutes); + uint16_t getScheduleTimerStopMinutes(void) const; + // uint16_t getTimerXStopMinutes(void) const; + + + void setScheduleTimerActiveDays(const std::set& days); + std::set getScheduleTimerActiveDays(void) const; + uint8_t getTimerActiveDaysBitmap(void) const; + + using IRArgoACBase::getMessageType; + static argoIrMessageType_t getMessageType(const ArgoProtocolWREM3& raw); + + String toString(void) const; + stdAc::state_t toCommon(void) const; + + static bool hasValidPreamble(const uint8_t state[], const uint16_t length); + + public: +#if DECODE_ARGO + static bool isValidWrem3Message(const uint8_t state[], const uint16_t nbits, + bool verifyChecksum = true); +#endif }; #endif // IR_ARGO_H_ diff --git a/lib/IRremoteESP8266/src/ir_Bosch.cpp b/lib/IRremoteESP8266/src/ir_Bosch.cpp index f6e26eb527..56e9d2b994 100644 --- a/lib/IRremoteESP8266/src/ir_Bosch.cpp +++ b/lib/IRremoteESP8266/src/ir_Bosch.cpp @@ -1,54 +1,32 @@ // Copyright 2022 David Conran +// Copyright 2022 Nico Thien /// @file /// @brief Support for the Bosch A/C / heatpump protocol /// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1787 -// Supports: -// Brand: Bosch, Model: CL3000i-Set 26 E A/C -// Brand: Bosch, Model: RG10A(G2S)BGEF remote - -#include -#ifndef ARDUINO -#include -#endif -#include "IRrecv.h" -#include "IRsend.h" -#include "IRtext.h" -#include "IRutils.h" - -// Constants -const uint16_t kBoschHdrMark = 4366; -const uint16_t kBoschBitMark = 502; -const uint16_t kBoschHdrSpace = 4415; -const uint16_t kBoschOneSpace = 1645; -const uint16_t kBoschZeroSpace = 571; -const uint16_t kBoschFooterSpace = 5235; -const uint16_t kBoschFreq = 38000; // Hz. (Guessing the most common frequency.) -const uint16_t kBosch144NrOfSections = 3; +#include "ir_Bosch.h" #if SEND_BOSCH144 -/// Send a Bosch 144-bit / 18-byte message -/// Status: STABLE / Confirmed Working. +/// Send a Bosch 144-bit / 18-byte message (96-bit message are also possible) +/// Status: BETA / Probably Working. /// @param[in] data The message to be sent. /// @param[in] nbytes The number of bytes of message to be sent. /// @param[in] repeat The number of times the command is to be repeated. void IRsend::sendBosch144(const unsigned char data[], const uint16_t nbytes, const uint16_t repeat) { - // nbytes is required to be a multiple of kBosch144NrOfSections. - if (nbytes % kBosch144NrOfSections != 0) return; - + // nbytes is required to be a multiple of kBosch144BytesPerSection. + if (nbytes % kBosch144BytesPerSection != 0)return; // Set IR carrier frequency enableIROut(kBoschFreq); for (uint16_t r = 0; r <= repeat; r++) { - const uint16_t kSectionByteSize = nbytes / kBosch144NrOfSections; - for (uint16_t offset = 0; offset < nbytes; offset += kSectionByteSize) + for (uint16_t offset=0; offset < nbytes; offset += kBosch144BytesPerSection) // Section Header + Data + Footer sendGeneric(kBoschHdrMark, kBoschHdrSpace, kBoschBitMark, kBoschOneSpace, kBoschBitMark, kBoschZeroSpace, kBoschBitMark, kBoschFooterSpace, - data + offset, kSectionByteSize, + data + offset, kBosch144BytesPerSection, kBoschFreq, true, 0, kDutyDefault); space(kDefaultMessageGap); // Complete guess } @@ -56,6 +34,247 @@ void IRsend::sendBosch144(const unsigned char data[], const uint16_t nbytes, #endif // SEND_BOSCH144 +/// Class constructor. +/// @param[in] pin GPIO to be used when sending. +/// @param[in] inverted Is the output signal to be inverted? +/// @param[in] use_modulation Is frequency modulation to be used? +IRBosch144AC::IRBosch144AC(const uint16_t pin, const bool inverted, + const bool use_modulation) + : _irsend(pin, inverted, use_modulation) { stateReset(); } + +/// Reset the internal state to a fixed known good state. +void IRBosch144AC::stateReset(void) { + setRaw(kBosch144DefaultState, kBosch144StateLength); + setPower(true); +} + +/// Set up hardware to be able to send a message. +void IRBosch144AC::begin(void) { _irsend.begin(); } + +#if SEND_BOSCH144 +/// Send the current internal state as an IR message. +/// @param[in] repeat Nr. of times the message will be repeated. +void IRBosch144AC::send(const uint16_t repeat) { + if (!powerFlag) { // "Off" is a 96bit message + _irsend.sendBosch144(kBosch144Off, sizeof(kBosch144Off), repeat); + } else { + _irsend.sendBosch144(getRaw(), kBosch144StateLength, repeat); + } // other 96bit messages are not yet supported +} +#endif // SEND_BOSCH144 + +/// Get a copy of the internal state as a valid code for this protocol. +/// @return A valid code for this protocol based on the current internal state. +unsigned char* IRBosch144AC::getRaw(void) { + setInvertBytes(); + setCheckSumS3(); + return _.raw; +} + +/// Set the internal state from a valid code for this protocol. +/// @param[in] new_code A valid code for this protocol. +/// @param[in] length Size of the array being passed in in bytes. +void IRBosch144AC::setRaw(const uint8_t new_code[], const uint16_t length) { + const uint16_t len = min(length, kBosch144StateLength); + const uint16_t lenOff = sizeof(kBosch144Off); +// Is it an off message? + if (memcmp(kBosch144Off, new_code, min(lenOff, len)) == 0) + setPower(false); // It is. + else + setPower(true); + memcpy(_.raw, new_code, len); +} + +void IRBosch144AC::setPower(const bool on) { + powerFlag = on; +} + +bool IRBosch144AC::getPower(void) const { + return powerFlag; +} + +void IRBosch144AC::setTempRaw(const uint8_t code) { + _.TempS1 = _.TempS2 = code >> 1; // save 4 bits in S1 and S2 + _.TempS3 = code & 1; // save 1 bit in Section3 +} + +/// Set the temperature. +/// @param[in] degrees The temperature in degrees celsius. +void IRBosch144AC::setTemp(const uint8_t degrees) { + uint8_t temp = max(kBosch144TempMin, degrees); + temp = min(kBosch144TempMax, temp); + setTempRaw(kBosch144TempMap[temp - kBosch144TempMin]); +} + +uint8_t IRBosch144AC::getTemp(void) const { + uint8_t temp = (_.TempS1 << 1) + _.TempS3; + uint8_t retemp = 25; + for (uint8_t i = 0; i < kBosch144TempRange; i++) { + if (temp == kBosch144TempMap[i]) { + retemp = kBosch144TempMin + i; + } + } + return retemp; +} + +/// Set the speed of the fan. +/// @param[in] speed The desired setting. +void IRBosch144AC::setFan(const uint16_t speed) { + _.FanS1 = _.FanS2 = speed >> 6; // save 3 bits in S1 and S2 + _.FanS3 = speed & 0b111111; // save 6 bits in Section3 +} + +uint16_t IRBosch144AC::getFan(void) const { + return (_.FanS1 << 6) + _.FanS3; +} + +/// Set the desired operation mode. +/// @param[in] mode The desired operation mode. +void IRBosch144AC::setMode(const uint8_t mode) { + _.ModeS1 = _.ModeS2 = mode >> 1; // save 2 bits in S1 and S2 + _.ModeS3 = mode & 0b1; // save 1 bit in Section3 + if (mode == kBosch144Auto || mode == kBosch144Dry) { + _.FanS1 = _.FanS2 = 0b000; // save 3 bits in S1 and S2 + _.FanS3 = kBosch144FanAuto0; // save 6 bits in Section3 + } +} + +uint8_t IRBosch144AC::getMode(void) const { + return (_.ModeS1 << 1) + _.ModeS3; +} + +/// Set the Quiet mode of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRBosch144AC::setQuiet(const bool on) { + _.Quiet = on; // save 1 bit in Section3 + setFan(kBosch144FanAuto); // set Fan -> Auto +} + +/// Get the Quiet mode of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRBosch144AC::getQuiet(void) const { return _.Quiet; } + +/// Convert a stdAc::opmode_t enum into its native mode. +/// @param[in] mode The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRBosch144AC::convertMode(const stdAc::opmode_t mode) { + switch (mode) { + case stdAc::opmode_t::kCool: + return kBosch144Cool; + case stdAc::opmode_t::kHeat: + return kBosch144Heat; + case stdAc::opmode_t::kDry: + return kBosch144Dry; + case stdAc::opmode_t::kFan: + return kBosch144Fan; + default: + return kBosch144Auto; + } +} + +/// Convert a stdAc::fanspeed_t enum into it's native speed. +/// @param[in] speed The enum to be converted. +/// @return The native equivalent of the enum. +uint16_t IRBosch144AC::convertFan(const stdAc::fanspeed_t speed) { + switch (speed) { + case stdAc::fanspeed_t::kMin: + return kBosch144Fan20; + case stdAc::fanspeed_t::kLow: + return kBosch144Fan40; + case stdAc::fanspeed_t::kMedium: + return kBosch144Fan60; + case stdAc::fanspeed_t::kHigh: + return kBosch144Fan80; + case stdAc::fanspeed_t::kMax: + return kBosch144Fan100; + default: + return kBosch144FanAuto; + } +} + +/// Convert a native mode into its stdAc equivalent. +/// @param[in] mode The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::opmode_t IRBosch144AC::toCommonMode(const uint8_t mode) { + switch (mode) { + case kBosch144Cool: return stdAc::opmode_t::kCool; + case kBosch144Heat: return stdAc::opmode_t::kHeat; + case kBosch144Dry: return stdAc::opmode_t::kDry; + case kBosch144Fan: return stdAc::opmode_t::kFan; + default: return stdAc::opmode_t::kAuto; + } +} + +/// Convert a native fan speed into its stdAc equivalent. +/// @param[in] speed The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::fanspeed_t IRBosch144AC::toCommonFanSpeed(const uint16_t speed) { + switch (speed) { + case kBosch144Fan100: return stdAc::fanspeed_t::kMax; + case kBosch144Fan80: return stdAc::fanspeed_t::kHigh; + case kBosch144Fan60: return stdAc::fanspeed_t::kMedium; + case kBosch144Fan40: return stdAc::fanspeed_t::kLow; + case kBosch144Fan20: return stdAc::fanspeed_t::kMin; + default: return stdAc::fanspeed_t::kAuto; + } +} + +/// Convert the current internal state into its stdAc::state_t equivalent. +/// @return The stdAc equivalent of the native settings. +stdAc::state_t IRBosch144AC::toCommon(void) const { + stdAc::state_t result{}; + result.protocol = decode_type_t::BOSCH144; + result.power = getPower(); + result.mode = toCommonMode(getMode()); + result.celsius = true; + result.degrees = getTemp(); + result.fanspeed = toCommonFanSpeed(getFan()); + result.quiet = getQuiet(); + // 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.clean = false; + result.beep = false; + result.clock = -1; + result.sleep = -1; + return result; +} + +/// Convert the current internal state into a human readable string. +/// @return A human readable string. +String IRBosch144AC::toString(void) const { + uint8_t mode = getMode(); + uint8_t fan = static_cast(toCommonFanSpeed(getFan())); + String result = ""; + result.reserve(70); // Reserve some heap for the string to reduce fragging. + result += addBoolToString(getPower(), kPowerStr, false); + result += addModeToString(mode, kBosch144Auto, kBosch144Cool, + kBosch144Heat, kBosch144Dry, kBosch144Fan); + result += addFanToString(fan, static_cast(stdAc::fanspeed_t::kMax), + static_cast(stdAc::fanspeed_t::kMin), + static_cast(stdAc::fanspeed_t::kAuto), + static_cast(stdAc::fanspeed_t::kAuto), + static_cast(stdAc::fanspeed_t::kMedium)); + result += addTempToString(getTemp()); + result += addBoolToString(_.Quiet, kQuietStr); + return result; +} + +void IRBosch144AC::setInvertBytes() { + for (uint8_t i = 0; i <= 10; i += 2) { + _.raw[i + 1] = ~_.raw[i]; + } +} + +void IRBosch144AC::setCheckSumS3() { + _.ChecksumS3 = sumBytes(&(_.raw[12]), 5); +} + #if DECODE_BOSCH144 /// Decode the supplied Bosch 144-bit / 18-byte A/C message. /// Status: STABLE / Confirmed Working. diff --git a/lib/IRremoteESP8266/src/ir_Bosch.h b/lib/IRremoteESP8266/src/ir_Bosch.h new file mode 100644 index 0000000000..9ebee98548 --- /dev/null +++ b/lib/IRremoteESP8266/src/ir_Bosch.h @@ -0,0 +1,193 @@ +// Copyright 2022 Nico Thien +/// @file +/// @brief Support for Bosch A/C protocol +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1787 + +// Supports: +// Brand: Bosch, Model: CL3000i-Set 26 E A/C +// Brand: Bosch, Model: RG10A(G2S)BGEF remote + + +#ifndef IR_BOSCH_H_ +#define IR_BOSCH_H_ + +#define __STDC_LIMIT_MACROS +#include +#include +#include +#include "IRremoteESP8266.h" +#include "IRsend.h" +#include "IRrecv.h" +#include "IRtext.h" +#include "IRutils.h" +#ifndef UNIT_TEST +#include +#endif +#ifdef UNIT_TEST +#include "IRsend_test.h" +#endif + +// Constants +const uint16_t kBoschHdrMark = 4366; +const uint16_t kBoschBitMark = 502; +const uint16_t kBoschHdrSpace = 4415; +const uint16_t kBoschOneSpace = 1645; +const uint16_t kBoschZeroSpace = 571; +const uint16_t kBoschFooterSpace = 5235; +const uint16_t kBoschFreq = 38000; // Hz. (Guessing the most common frequency.) +const uint16_t kBosch144NrOfSections = 3; +const uint16_t kBosch144BytesPerSection = 6; + +using irutils::addBoolToString; +using irutils::addModeToString; +using irutils::addFanToString; +using irutils::addTempToString; +using std::min; +using std::max; +using std::memcpy; +using std::memcmp; + +// Modes Bit[0] to Section 3 Bit[1-2] to Section 1 +// ModeS3 ModeS1 +const uint8_t kBosch144Cool = 0b000; +const uint8_t kBosch144Dry = 0b011; +const uint8_t kBosch144Auto = 0b101; +const uint8_t kBosch144Heat = 0b110; +const uint8_t kBosch144Fan = 0b010; + +// Fan Control Bit[0-5] to Section 3 Bit[6-8] to Section 1 +// FanS3 FanS1 +const uint16_t kBosch144Fan20 = 0b111001010; +const uint16_t kBosch144Fan40 = 0b100010100; +const uint16_t kBosch144Fan60 = 0b010011110; +const uint16_t kBosch144Fan80 = 0b001101000; +const uint16_t kBosch144Fan100 = 0b001110010; +const uint16_t kBosch144FanAuto = 0b101110011; +const uint16_t kBosch144FanAuto0 = 0b000110011; + +// Temperature +const uint8_t kBosch144TempMin = 16; // Celsius +const uint8_t kBosch144TempMax = 30; // Celsius +const uint8_t kBosch144TempRange = kBosch144TempMax - kBosch144TempMin + 1; +const uint8_t kBosch144TempMap[kBosch144TempRange] = { + 0b00001, // 16C // Bit[0] to Section 3 Bit[1-4] to Section 1 + 0b00000, // 17C // TempS3 TempS1 + 0b00010, // 18c + 0b00110, // 19C + 0b00100, // 20C + 0b01100, // 21C + 0b01110, // 22C + 0b01010, // 23C + 0b01000, // 24C + 0b11000, // 25C + 0b11010, // 26C + 0b10010, // 27C + 0b10000, // 28C + 0b10100, // 29C + 0b10110 // 30C +}; + +// "OFF" is a 96bit-message the same as Coolix protocol +const uint8_t kBosch144Off[] = {0xB2, 0x4D, 0x7B, 0x84, 0xE0, 0x1F, + 0xB2, 0x4D, 0x7B, 0x84, 0xE0, 0x1F}; + +// On, 25C, Mode: Auto +const uint8_t kBosch144DefaultState[kBosch144StateLength] = { + 0xB2, 0x4D, 0x1F, 0xE0, 0xC8, 0x37, + 0xB2, 0x4D, 0x1F, 0xE0, 0xC8, 0x37, + 0xD5, 0x65, 0x00, 0x00, 0x00, 0x3A}; + +union Bosch144Protocol { + uint8_t raw[kBosch144StateLength]; ///< The state in IR code form. + struct { + uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############ + uint8_t InnvertS1_1:8; // Invert byte 0b01001101 / 0x4D # + uint8_t :5; // not used (without timer use) # + uint8_t FanS1 :3; // Fan speed bits in Section 1 # + uint8_t InnvertS1_2:8; // Invert byte # Section 1 = + uint8_t :2; // not used (without timer use) # Sektion 2 + uint8_t ModeS1 :2; // Operation mode bits S1 # + uint8_t TempS1 :4; // Desired temperature (Celsius) S2 # + uint8_t InnvertS1_3:8; // Invert byte (without timer use) ############ + + uint8_t :8; // Fixed value 0b10110010 / 0xB2. ############ + uint8_t InnvertS2_1:8; // Invert byte 0b01001101 / 0x4D # + uint8_t :5; // not used (without timer use) # + uint8_t FanS2 :3; // Fan speed bits in Section 2 # + uint8_t InnvertS2_2:8; // Invert byte # Section 2 = + uint8_t :2; // not used (without timer use) # Sektion 1 + uint8_t ModeS2 :2; // Operation mode bits S2 # + uint8_t TempS2 :4; // Desired temperature (Celsius) S2 # + uint8_t InnvertS2_3:8; // Invert byte (without timer use) ########### + + uint8_t :8; // Fixed value 0b11010101 / 0xD5 ########### + uint8_t ModeS3 :1; // ModeBit in Section 3 # + uint8_t FanS3 :6; // Fan speed bits in Section 3 # + uint8_t :1; // Unknown # + uint8_t :7; // Unknown # + uint8_t Quiet :1; // Silent-Mode # Section 3 + uint8_t :4; // Unknown # + uint8_t TempS3 :1; // Desired temp. Bit in Section3 # + uint8_t :3; // Unknown # + uint8_t :8; // Unknown # + uint8_t ChecksumS3 :8; // Checksum from byte 13-17 ########### + }; +}; + +// Classes + +/// Class for handling detailed Bosch144 A/C messages. +class IRBosch144AC { + public: + explicit IRBosch144AC(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + void stateReset(void); +#if SEND_BOSCH144 + void send(const uint16_t repeat = 0); + /// Run the calibration to calculate uSec timing offsets for this platform. + /// @return The uSec timing offset needed per modulation of the IR Led. + /// @note This will produce a 65ms IR signal pulse at 38kHz. + /// Only ever needs to be run once per object instantiation, if at all. + int8_t calibrate(void) { return _irsend.calibrate(); } +#endif // SEND_BOSCH144 + void begin(); + void setPower(const bool state); + bool getPower(void) const; + void setTemp(const uint8_t temp); + uint8_t getTemp(void) const; + void setFan(const uint16_t speed); + uint16_t getFan(void) const; + void setMode(const uint8_t mode); + uint8_t getMode(void) const; + void setQuiet(const bool on); + bool getQuiet(void) const; + uint8_t* getRaw(void); + void setRaw(const uint8_t new_code[], + const uint16_t length = kBosch144StateLength); + static uint8_t convertMode(const stdAc::opmode_t mode); + static uint16_t convertFan(const stdAc::fanspeed_t speed); + static stdAc::opmode_t toCommonMode(const uint8_t mode); + static stdAc::fanspeed_t toCommonFanSpeed(const uint16_t speed); + stdAc::state_t toCommon(void) const; + String toString(void) const; +#ifndef UNIT_TEST + + private: + IRsend _irsend; ///< Instance of the IR send class +#else + /// @cond IGNORE + IRsendTest _irsend; ///< Instance of the testing IR send class + /// @endcond +#endif + Bosch144Protocol _; ///< The state of the IR remote in IR code form. + + // Internal State settings + bool powerFlag; + + void setInvertBytes(); + void setCheckSumS3(); + void setTempRaw(const uint8_t code); + uint8_t getTempRaw(void) const; +}; + +#endif // IR_BOSCH_H_ diff --git a/lib/IRremoteESP8266/src/ir_Carrier.cpp b/lib/IRremoteESP8266/src/ir_Carrier.cpp index 42b45f9abb..ef51cc4393 100644 --- a/lib/IRremoteESP8266/src/ir_Carrier.cpp +++ b/lib/IRremoteESP8266/src/ir_Carrier.cpp @@ -46,6 +46,15 @@ const uint16_t kCarrierAc64OneSpace = 1736; const uint16_t kCarrierAc64ZeroSpace = 615; const uint32_t kCarrierAc64Gap = kDefaultMessageGap; // A guess. +//< @see: https://github.com/crankyoldgit/IRremoteESP8266/issues/1943#issue-1519570772 +const uint16_t kCarrierAc84HdrMark = 5850; +const uint16_t kCarrierAc84Zero = 1175; +const uint16_t kCarrierAc84One = 430; +const uint16_t kCarrierAc84HdrSpace = kCarrierAc84Zero; +const uint32_t kCarrierAc84Gap = kDefaultMessageGap; // A guess. +const uint8_t kCarrierAc84ExtraBits = 4; +const uint8_t kCarrierAc84ExtraTolerance = 5; + const uint16_t kCarrierAc128HdrMark = 4600; const uint16_t kCarrierAc128HdrSpace = 2600; const uint16_t kCarrierAc128Hdr2Mark = 9300; @@ -645,3 +654,94 @@ bool IRrecv::decodeCarrierAC128(decode_results *results, uint16_t offset, return true; } #endif // DECODE_CARRIER_AC128 + +#if SEND_CARRIER_AC84 +/// Send a Carroer A/C 84 Bit formatted message. +/// Status: BETA / Untested but probably works. +/// @param[in] data The message to be sent. +/// @param[in] nbytes The byte size of the message being sent. +/// @param[in] repeat The number of times the command is to be repeated. +void IRsend::sendCarrierAC84(const uint8_t data[], const uint16_t nbytes, + const uint16_t repeat) { + // Protocol uses a constant bit time encoding. + for (uint16_t r = 0; r <= repeat; r++) { + if (nbytes) { + // The least significant `kCarrierAc84ExtraBits` bits of the first byte + sendGeneric(kCarrierAc84HdrMark, kCarrierAc84HdrSpace, // Header + kCarrierAc84Zero, kCarrierAc84One, // Data + kCarrierAc84One, kCarrierAc84Zero, + 0, 0, // No footer + GETBITS64(data[0], 0, kCarrierAc84ExtraBits), + kCarrierAc84ExtraBits, + 38000, false, 0, 33); + // The rest of the data. + sendGeneric(0, 0, // No Header + kCarrierAc84Zero, kCarrierAc84One, // Data + kCarrierAc84One, kCarrierAc84Zero, + kCarrierAc84Zero, kDefaultMessageGap, // Footer + data + 1, nbytes - 1, 38000, false, 0, 33); + } + } +} +#endif // SEND_CARRIER_AC84 + +#if DECODE_CARRIER_AC84 +/// Decode the supplied Carroer A/C 84 Bit formatted message. +/// Status: STABLE / Confirmed Working. +/// @param[in,out] results Ptr to the data to decode & where to store the decode +/// result. +/// @param[in] offset The starting index to use when attempting to decode the +/// raw data. Typically/Defaults to kStartOffset. +/// @param[in] nbits The number of data bits to expect. +/// @param[in] strict Flag indicating if we should perform strict matching. +/// @return A boolean. True if it can decode it, false if it can't. +bool IRrecv::decodeCarrierAC84(decode_results *results, uint16_t offset, + const uint16_t nbits, const bool strict) { + // Check if we have enough data to even possibly match. + if (results->rawlen < 2 * nbits + kHeader + kFooter - 1 + offset) + return false; // Can't possibly be a valid Carrier message. + // Compliance check. + if (strict && nbits != kCarrierAc84Bits) return false; + + // This decoder expects to decode an unusual number of bits. Check before we + // start. + if (nbits % 8 != kCarrierAc84ExtraBits) return false; + + uint64_t data = 0; + uint16_t used = 0; + + // Header + Data (kCarrierAc84ExtraBits only) + used = matchGenericConstBitTime(results->rawbuf + offset, &data, + results->rawlen - offset, + kCarrierAc84ExtraBits, + // Header (None) + kCarrierAc84HdrMark, kCarrierAc84HdrSpace, + // Data + kCarrierAc84Zero, kCarrierAc84One, + // No Footer + 0, 0, + false, + _tolerance + kCarrierAc84ExtraTolerance, + kMarkExcess, false); + if (!used) return false; + // Stuff the captured data so far into the first byte of the state. + *results->state = data; + offset += used; + // Capture the rest of the data as normal as we should be on a byte boundary. + // Data + Footer + if (!matchGeneric(results->rawbuf + offset, results->state + 1, + results->rawlen - offset, nbits - kCarrierAc84ExtraBits, + 0, 0, // No Header expected. + kCarrierAc84Zero, kCarrierAc84One, // Data + kCarrierAc84One, kCarrierAc84Zero, + kCarrierAc84Zero, kDefaultMessageGap, true, + _tolerance + kCarrierAc84ExtraTolerance, + kMarkExcess, false)) return false; + + // Success + results->decode_type = decode_type_t::CARRIER_AC84; + results->bits = nbits; + results->repeat = false; + return true; +} +#endif // DECODE_CARRIER_AC84 diff --git a/lib/IRremoteESP8266/src/ir_Carrier.h b/lib/IRremoteESP8266/src/ir_Carrier.h index c642c51e5c..7554a45ba7 100644 --- a/lib/IRremoteESP8266/src/ir_Carrier.h +++ b/lib/IRremoteESP8266/src/ir_Carrier.h @@ -4,6 +4,7 @@ /// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1127 /// @see https://docs.google.com/spreadsheets/d/1EZy78L0cn1KDIX1aKq2biptejFqCjD5HO3tLiRvXf48/edit#gid=0 /// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1797 +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1943 // Supports: // Brand: Carrier/Surrey, Model: 42QG5A55970 remote @@ -13,6 +14,8 @@ // Brand: Carrier/Surrey, Model: 619EGX0220E0 A/C // Brand: Carrier/Surrey, Model: 53NGK009/012 Inverter // Brand: Carrier, Model: 40GKX0E2006 remote (CARRIER_AC128) +// Brand: Carrier, Model: 3021203 RR03-S-Remote (CARRIER_AC84) +// Brand: Carrier, Model: 342WM100CT A/C (CARRIER_AC84) #ifndef IR_CARRIER_H_ #define IR_CARRIER_H_ diff --git a/lib/IRremoteESP8266/src/ir_Coolix.cpp b/lib/IRremoteESP8266/src/ir_Coolix.cpp index 755e891904..6769ebb79d 100644 --- a/lib/IRremoteESP8266/src/ir_Coolix.cpp +++ b/lib/IRremoteESP8266/src/ir_Coolix.cpp @@ -548,6 +548,11 @@ stdAc::state_t IRCoolixAC::toCommon(const stdAc::state_t *prev) const { // Back to "normal" stateful messages. result.mode = toCommonMode(getMode()); result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); + if (result.sensorTemperature == kCoolixSensorTempIgnoreCode) { + result.sensorTemperature = kNoTempValue; + } + result.iFeel = getZoneFollow(); result.fanspeed = toCommonFanSpeed(getFan()); return result; } diff --git a/lib/IRremoteESP8266/src/ir_Coolix.h b/lib/IRremoteESP8266/src/ir_Coolix.h index 2155b54b05..d711367b20 100644 --- a/lib/IRremoteESP8266/src/ir_Coolix.h +++ b/lib/IRremoteESP8266/src/ir_Coolix.h @@ -165,6 +165,7 @@ class IRCoolixAC { static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const; String toString(void) const; + void setZoneFollow(const bool on); #ifndef UNIT_TEST private: @@ -189,7 +190,6 @@ class IRCoolixAC { void setTempRaw(const uint8_t code); uint8_t getTempRaw(void) const; void setSensorTempRaw(const uint8_t code); - void setZoneFollow(const bool on); bool isSpecialState(void) const; bool handleSpecialState(const uint32_t data); void updateAndSaveState(const uint32_t raw_state); diff --git a/lib/IRremoteESP8266/src/ir_Ecoclim.cpp b/lib/IRremoteESP8266/src/ir_Ecoclim.cpp index 983913d38d..e24559b5f6 100644 --- a/lib/IRremoteESP8266/src/ir_Ecoclim.cpp +++ b/lib/IRremoteESP8266/src/ir_Ecoclim.cpp @@ -365,6 +365,7 @@ stdAc::state_t IREcoclimAc::toCommon(void) const { result.mode = toCommonMode(getMode()); result.celsius = true; result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); result.fanspeed = toCommonFanSpeed(_.Fan); result.sleep = (getMode() == kEcoclimSleep) ? 0 : -1; result.clock = getClock(); diff --git a/lib/IRremoteESP8266/src/ir_Electra.cpp b/lib/IRremoteESP8266/src/ir_Electra.cpp index f0882bc6d1..f8edf97299 100644 --- a/lib/IRremoteESP8266/src/ir_Electra.cpp +++ b/lib/IRremoteESP8266/src/ir_Electra.cpp @@ -365,6 +365,7 @@ stdAc::state_t IRElectraAc::toCommon(void) const { result.mode = toCommonMode(_.Mode); result.celsius = true; result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); result.fanspeed = toCommonFanSpeed(_.Fan); result.swingv = getSwingV() ? stdAc::swingv_t::kAuto : stdAc::swingv_t::kOff; @@ -373,6 +374,7 @@ stdAc::state_t IRElectraAc::toCommon(void) const { result.light = getLightToggle(); result.turbo = _.Turbo; result.clean = _.Clean; + result.iFeel = getIFeel(); // Not supported. result.model = -1; // No models used. result.quiet = false; diff --git a/lib/IRremoteESP8266/src/ir_Electra.h b/lib/IRremoteESP8266/src/ir_Electra.h index 142b525628..602406d8d4 100644 --- a/lib/IRremoteESP8266/src/ir_Electra.h +++ b/lib/IRremoteESP8266/src/ir_Electra.h @@ -14,6 +14,7 @@ // Brand: Centek, Model: SCT-65Q09 A/C // Brand: Centek, Model: YKR-P/002E remote // Brand: AEG, Model: Chillflex Pro AXP26U338CW A/C +// Brand: Electrolux, Model: YKR-H/531E A/C #ifndef IR_ELECTRA_H_ #define IR_ELECTRA_H_ diff --git a/lib/IRremoteESP8266/src/ir_Gorenje.cpp b/lib/IRremoteESP8266/src/ir_Gorenje.cpp new file mode 100644 index 0000000000..f93e4e2317 --- /dev/null +++ b/lib/IRremoteESP8266/src/ir_Gorenje.cpp @@ -0,0 +1,71 @@ +// Copyright 2022 Mateusz Bronk (mbronk) +/// @file +/// @brief Support for the Gorenje cooker hood IR protocols. +/// @see https://techfresh.pl/wp-content/uploads/2017/08/Gorenje-DKF-2600-MWT.pdf +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1887 + +// Supports: +// Brand: Gorenje, Model: DKF 2600 MWT Cooker Hood + +#include "IRrecv.h" +#include "IRsend.h" +#include "IRutils.h" + +const uint32_t kGorenjeMinGap = 100000U; // 0.1s +const uint16_t kGorenjeHdrMark = 0; +const uint32_t kGorenjeHdrSpace = 0; +const uint16_t kGorenjeBitMark = 1300; +const uint32_t kGorenjeOneSpace = 5700; +const uint32_t kGorenjeZeroSpace = 1700; +const uint16_t kGorenjeFreq = 38000; // Hz +const uint16_t kGorenjeTolerance = 7; // % + +#if SEND_GORENJE +/// Send a Gorenje Cooker Hood formatted message. +/// Status: STABLE / Known working. +/// @param[in] data containing the IR command to be sent. +/// @param[in] nbits Nr. of bits of the message to send. usually kGorenjeBits +/// @param[in] repeat Nr. of times the message is to be repeated. +void IRsend::sendGorenje(const uint64_t data, const uint16_t nbits, + const uint16_t repeat) { + sendGeneric(kGorenjeHdrMark, kGorenjeHdrSpace, + kGorenjeBitMark, kGorenjeOneSpace, + kGorenjeBitMark, kGorenjeZeroSpace, + kGorenjeBitMark, kGorenjeMinGap, + data, nbits, kGorenjeFreq, true, repeat, kDutyDefault); +} +#endif // SEND_GORENJE + +#if DECODE_GORENJE +/// Decode the supplied Gorenje Cooker Hood message. +/// Status: STABLE / Known working. +/// @param[in,out] results Ptr to the data to decode & where to store the +/// decoded result +/// @param[in] offset The starting index to use when attempting to decode the +/// raw data. Typically/Defaults to kStartOffset. +/// @param[in] nbits The number of data bits to expect. +/// @param[in] strict Flag indicating if we should perform strict matching. +/// @return A boolean. True if it can decode it, false if it can't. +bool IRrecv::decodeGorenje(decode_results *results, uint16_t offset, + const uint16_t nbits, const bool strict) { + if (strict && nbits != kGorenjeBits) + return false; // We expect Gorenje to be a certain sized message. + + uint64_t data = 0; + if (!matchGeneric(results->rawbuf + offset, &data, + results->rawlen - offset, nbits, + kGorenjeHdrMark, kGorenjeHdrSpace, + kGorenjeBitMark, kGorenjeOneSpace, + kGorenjeBitMark, kGorenjeZeroSpace, + kGorenjeBitMark, kGorenjeMinGap, + true, kGorenjeTolerance)) return false; + + // Matched! + results->bits = nbits; + results->value = data; + results->decode_type = decode_type_t::GORENJE; + results->command = 0; + results->address = 0; + return true; +} +#endif // DECODE_GORENJE diff --git a/lib/IRremoteESP8266/src/ir_Gree.cpp b/lib/IRremoteESP8266/src/ir_Gree.cpp index ead7178e3b..2c44cfe523 100644 --- a/lib/IRremoteESP8266/src/ir_Gree.cpp +++ b/lib/IRremoteESP8266/src/ir_Gree.cpp @@ -591,6 +591,8 @@ stdAc::state_t IRGreeAC::toCommon(void) { result.mode = toCommonMode(_.Mode); result.celsius = !_.UseFahrenheit; result.degrees = getTemp(); + // no support for Sensor temp. + result.iFeel = getIFeel(); result.fanspeed = toCommonFanSpeed(_.Fan); if (_.SwingAuto) result.swingv = stdAc::swingv_t::kAuto; diff --git a/lib/IRremoteESP8266/src/ir_Haier.cpp b/lib/IRremoteESP8266/src/ir_Haier.cpp index 93336212ec..a608282829 100644 --- a/lib/IRremoteESP8266/src/ir_Haier.cpp +++ b/lib/IRremoteESP8266/src/ir_Haier.cpp @@ -1481,3 +1481,689 @@ bool IRrecv::decodeHaierAC160(decode_results* results, uint16_t offset, return true; } #endif // DECODE_HAIER_AC160 + + +/// Class constructor +/// @param[in] pin GPIO to be used when sending. +/// @param[in] inverted Is the output signal to be inverted? +/// @param[in] use_modulation Is frequency modulation to be used? +IRHaierAC160::IRHaierAC160(const uint16_t pin, const bool inverted, + const bool use_modulation) + : _irsend(pin, inverted, use_modulation) { stateReset(); } + +/// Set up hardware to be able to send a message. +void IRHaierAC160::begin(void) { _irsend.begin(); } + +#if SEND_HAIER_AC160 +/// Send the current internal state as an IR message. +/// @param[in] repeat Nr. of times the message will be repeated. +void IRHaierAC160::send(const uint16_t repeat) { + _irsend.sendHaierAC160(getRaw(), kHaierAC160StateLength, repeat); +} +#endif // SEND_HAIER_AC160 + +/// Calculate and set the checksum values for the internal state. +void IRHaierAC160::checksum(void) { + _.Sum = sumBytes(_.raw, kHaierACYRW02StateLength - 1); + _.Sum2 = sumBytes(_.raw + kHaierACYRW02StateLength, + kHaierAC160StateLength - kHaierACYRW02StateLength - 1); +} + +/// Reset the internal state to a fixed known good state. +void IRHaierAC160::stateReset(void) { + std::memset(_.raw, 0, sizeof _.raw); + _.Model = kHaierAcYrw02ModelA; + _.Prefix = kHaierAc160Prefix; + _.Temp = kHaierAcYrw02DefTempC - kHaierAcYrw02MinTempC; + setClean(false); + setFan(kHaierAcYrw02FanAuto); + _.Power = true; + _.Button = kHaierAcYrw02ButtonPower; +} + +/// Get a PTR to the internal state/code for this protocol. +/// @return PTR to a code for this protocol based on the current internal state. +uint8_t* IRHaierAC160::getRaw(void) { + checksum(); + return _.raw; +} + +/// Set the internal state from a valid code for this protocol. +/// @param[in] new_code A valid code for this protocol. +void IRHaierAC160::setRaw(const uint8_t new_code[]) { + memcpy(_.raw, new_code, kHaierAC160StateLength); +} + +/// Set the Button/Command setting of the A/C. +/// @param[in] button The value of the button/command that was pressed. +void IRHaierAC160::setButton(uint8_t button) { + switch (button) { + case kHaierAcYrw02ButtonTempUp: + case kHaierAcYrw02ButtonTempDown: + case kHaierAcYrw02ButtonSwingV: + case kHaierAcYrw02ButtonSwingH: + case kHaierAcYrw02ButtonFan: + case kHaierAcYrw02ButtonPower: + case kHaierAcYrw02ButtonMode: + case kHaierAcYrw02ButtonHealth: + case kHaierAcYrw02ButtonTurbo: + case kHaierAcYrw02ButtonSleep: + case kHaierAcYrw02ButtonLock: + case kHaierAc160ButtonClean: + case kHaierAcYrw02ButtonCFAB: + _.Button = button; + } +} + +/// Get the Button/Command setting of the A/C. +/// @return The value of the button/command that was pressed. +uint8_t IRHaierAC160::getButton(void) const { return _.Button; } + +/// Set the operating mode of the A/C. +/// @param[in] mode The desired operating mode. +void IRHaierAC160::setMode(uint8_t mode) { + switch (mode) { + case kHaierAcYrw02Auto: + case kHaierAcYrw02Dry: + case kHaierAcYrw02Fan: + // Turbo & Quiet is only available in Cool/Heat mode. + _.Turbo = false; + _.Quiet = false; + // FALL-THRU + case kHaierAcYrw02Cool: + case kHaierAcYrw02Heat: + _.Button = kHaierAcYrw02ButtonMode; + _.Mode = mode; + break; + default: + setMode(kHaierAcYrw02Auto); // Unexpected, default to auto mode. + } + _.AuxHeating = (_.Mode == kHaierAcYrw02Heat); // Set only if heat mode. +} + +/// Get the operating mode setting of the A/C. +/// @return The current operating mode setting. +uint8_t IRHaierAC160::getMode(void) const { return _.Mode; } + +/// Set the default temperature units to use. +/// @param[in] on Use Fahrenheit as the units. +/// true is Fahrenheit, false is Celsius. +void IRHaierAC160::setUseFahrenheit(const bool on) { _.UseFahrenheit = on; } + +/// Get the default temperature units in use. +/// @return true is Fahrenheit, false is Celsius. +bool IRHaierAC160::getUseFahrenheit(void) const { return _.UseFahrenheit; } + +/// Set the temperature. +/// @param[in] degree The temperature in degrees. +/// @param[in] fahrenheit Use units of Fahrenheit and set that as units used. +void IRHaierAC160::setTemp(const uint8_t degree, const bool fahrenheit) { + uint8_t old_temp = getTemp(); + if (old_temp == degree) return; + + if (_.UseFahrenheit == fahrenheit) { + if (old_temp > degree) + _.Button = kHaierAcYrw02ButtonTempDown; + else + _.Button = kHaierAcYrw02ButtonTempUp; + } else { + _.Button = kHaierAcYrw02ButtonCFAB; + } + _.UseFahrenheit = fahrenheit; + + uint8_t temp = degree; + if (fahrenheit) { + if (temp < kHaierAcYrw02MinTempF) + temp = kHaierAcYrw02MinTempF; + else if (temp > kHaierAcYrw02MaxTempF) + temp = kHaierAcYrw02MaxTempF; + if (degree >= 77) { temp++; } + if (degree >= 79) { temp++; } + // See at IRHaierAC160::getTemp() comments for clarification + _.ExtraDegreeF = temp % 2; + _.Temp = (temp - kHaierAcYrw02MinTempF -_.ExtraDegreeF) >> 1; + } else { + if (temp < kHaierAcYrw02MinTempC) + temp = kHaierAcYrw02MinTempC; + else if (temp > kHaierAcYrw02MaxTempC) + temp = kHaierAcYrw02MaxTempC; + _.Temp = temp - kHaierAcYrw02MinTempC; + } +} + +/// Get the current temperature setting. +/// The unit of temperature is specified by UseFahrenheit value. +/// @return The current setting for temperature. +uint8_t IRHaierAC160::getTemp(void) const { + if (!_.UseFahrenheit) { return _.Temp + kHaierAcYrw02MinTempC; } + uint8_t degree = _.Temp*2 + kHaierAcYrw02MinTempF + _.ExtraDegreeF; + // The way of coding the temperature in degree Fahrenheit is + // kHaierAcYrw02MinTempF + Temp*2 + ExtraDegreeF, for example + // Temp = 0b0011, ExtraDegreeF = 0b1, temperature is 60 + 3*2 + 1 = 67F + // But around 78F there is unconsistency, see table below + // + // | Fahrenheit | Temp | ExtraDegreeF | + // | 60F | 0b0000 | 0b0 | + // | 61F | 0b0000 | 0b1 | + // | 62F | 0b0001 | 0b0 | + // | 63F | 0b0001 | 0b1 | + // | 64F | 0b0010 | 0b0 | + // | 65F | 0b0010 | 0b1 | + // | 66F | 0b0011 | 0b0 | + // | 67F | 0b0011 | 0b1 | + // | 68F | 0b0100 | 0b0 | + // | 69F | 0b0100 | 0b1 | + // | 70F | 0b0101 | 0b0 | + // | 71F | 0b0101 | 0b1 | + // | 72F | 0b0110 | 0b0 | + // | 73F | 0b0110 | 0b1 | + // | 74F | 0b0111 | 0b0 | + // | 75F | 0b0111 | 0b1 | + // | 76F | 0b1000 | 0b0 | + // | Not Used | 0b1000 | 0b1 | + // | 77F | 0b1001 | 0b0 | + // | Not Used | 0b1001 | 0b1 | + // | 78F | 0b1010 | 0b0 | + // | 79F | 0b1010 | 0b1 | + // | 80F | 0b1011 | 0b0 | + // | 81F | 0b1011 | 0b1 | + // | 82F | 0b1100 | 0b0 | + // | 83F | 0b1100 | 0b1 | + // | 84F | 0b1101 | 0b0 | + // | 86F | 0b1110 | 0b0 | + // | 85F | 0b1101 | 0b1 | + if (degree >= 77) { degree--; } + if (degree >= 79) { degree--; } + return degree; +} + +/// Set the Clean setting of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setClean(const bool on) { + _.Button = kHaierAc160ButtonClean; + _.Clean = on; + _.Clean2 = on; +} + +/// Get the Clean setting of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getClean(void) const { return _.Clean && _.Clean2; } + +/// Get the value of the current power setting. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getPower(void) const { return _.Power; } + +/// Change the power setting. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setPower(const bool on) { + _.Button = kHaierAcYrw02ButtonPower; + _.Power = on; +} + +/// Change the power setting to On. +void IRHaierAC160::on(void) { setPower(true); } + +/// Change the power setting to Off. +void IRHaierAC160::off(void) { setPower(false); } + +/// Get the Sleep setting of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getSleep(void) const { return _.Sleep; } + +/// Set the Sleep setting of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setSleep(const bool on) { + _.Button = kHaierAcYrw02ButtonSleep; + _.Sleep = on; +} + +/// Get the Turbo setting of the A/C. +/// @return The current turbo setting. +bool IRHaierAC160::getTurbo(void) const { return _.Turbo; } + +/// Set the Turbo setting of the A/C. +/// @param[in] on The desired turbo setting. +/// @note Turbo & Quiet can't be on at the same time, and only in Heat/Cool mode +void IRHaierAC160::setTurbo(const bool on) { + switch (getMode()) { + case kHaierAcYrw02Cool: + case kHaierAcYrw02Heat: + _.Turbo = on; + _.Button = kHaierAcYrw02ButtonTurbo; + if (on) _.Quiet = false; + } +} + +/// Get the Quiet setting of the A/C. +/// @return The current Quiet setting. +bool IRHaierAC160::getQuiet(void) const { return _.Quiet; } + +/// Set the Quiet setting of the A/C. +/// @param[in] on The desired Quiet setting. +/// @note Turbo & Quiet can't be on at the same time, and only in Heat/Cool mode +void IRHaierAC160::setQuiet(const bool on) { + switch (getMode()) { + case kHaierAcYrw02Cool: + case kHaierAcYrw02Heat: + _.Quiet = on; + _.Button = kHaierAcYrw02ButtonTurbo; + if (on) _.Turbo = false; + } +} + +/// Get the value of the Aux Heating setting. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getAuxHeating(void) const { return _.AuxHeating; } + +/// Change the Aux Heating setting. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setAuxHeating(const bool on) { + _.Button = kHaierAc160ButtonAuxHeating; + _.AuxHeating = on; +} + +/// Get the value of the current Light toggle setting. +/// @return true, the setting is on. false, the setting is off. +/// @note This setting seems to be controlled just by the button setting. +bool IRHaierAC160::getLightToggle(void) const { + return _.Button == kHaierAc160ButtonLight; +} + +/// Set the Light Toggle setting of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +/// @note This setting seems to be controlled just by the button setting. +void IRHaierAC160::setLightToggle(const bool on) { + _.Button = on ? kHaierAc160ButtonLight : kHaierAcYrw02ButtonPower; +} + +/// Get the current fan speed setting. +/// @return The current fan speed. +uint8_t IRHaierAC160::getFan(void) const { return _.Fan; } + +/// Set the speed of the fan. +/// @param[in] speed The desired setting. +void IRHaierAC160::setFan(uint8_t speed) { + switch (speed) { + case kHaierAcYrw02FanLow: + case kHaierAcYrw02FanMed: + case kHaierAcYrw02FanHigh: + case kHaierAcYrw02FanAuto: + _.Fan = speed; + _.Fan2 = (speed == kHaierAcYrw02FanAuto) ? 0 : speed; + _.Button = kHaierAcYrw02ButtonFan; + } +} + +/// Set the Health (filter) setting of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setHealth(const bool on) { + _.Button = kHaierAcYrw02ButtonHealth; + _.Health = on; +} + +/// Get the Health (filter) setting of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getHealth(void) const { return _.Health; } + +/// Get the Vertical Swing position setting of the A/C. +/// @return The native position/mode. +uint8_t IRHaierAC160::getSwingV(void) const { return _.SwingV; } + +/// Set the Vertical Swing mode of the A/C. +/// @param[in] pos The position/mode to set the vanes to. +void IRHaierAC160::setSwingV(const uint8_t pos) { + switch (pos) { + case kHaierAc160SwingVOff: + case kHaierAc160SwingVAuto: + case kHaierAc160SwingVTop: + case kHaierAc160SwingVHighest: + case kHaierAc160SwingVHigh: + case kHaierAc160SwingVMiddle: + case kHaierAc160SwingVLow: + case kHaierAc160SwingVLowest: + _.Button = kHaierAcYrw02ButtonSwingV; + _.SwingV = pos; + break; + default: return; // If in doubt, Do nothing. + } +} + +/// Set the Timer operating mode. +/// @param[in] mode The timer mode to use. +void IRHaierAC160::setTimerMode(const uint8_t mode) { + _.TimerMode = (mode > kHaierAcYrw02OffThenOnTimer) ? kHaierAcYrw02NoTimers + : mode; + switch (_.TimerMode) { + case kHaierAcYrw02NoTimers: + setOnTimer(0); // Disable the On timer. + setOffTimer(0); // Disable the Off timer. + break; + case kHaierAcYrw02OffTimer: + setOnTimer(0); // Disable the On timer. + break; + case kHaierAcYrw02OnTimer: + setOffTimer(0); // Disable the Off timer. + break; + } +} + +/// Get the Timer operating mode. +/// @return The mode of the timer is currently configured to. +uint8_t IRHaierAC160::getTimerMode(void) const { return _.TimerMode; } + +/// Set the number of minutes of the On Timer setting. +/// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. +void IRHaierAC160::setOnTimer(const uint16_t mins) { + const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + _.OnTimerHrs = nr_mins / 60; + _.OnTimerMins = nr_mins % 60; + + const bool enabled = (nr_mins > 0); + uint8_t mode = getTimerMode(); + switch (mode) { + case kHaierAcYrw02OffTimer: + mode = enabled ? kHaierAcYrw02OffThenOnTimer : mode; + break; + case kHaierAcYrw02OnThenOffTimer: + case kHaierAcYrw02OffThenOnTimer: + mode = enabled ? kHaierAcYrw02OffThenOnTimer : kHaierAcYrw02OffTimer; + break; + default: + // Enable/Disable the On timer for the simple case. + mode = enabled << 1; + } + _.TimerMode = mode; +} + +/// Get the number of minutes of the On Timer setting. +/// @return Nr of minutes. +uint16_t IRHaierAC160::getOnTimer(void) const { + return _.OnTimerHrs * 60 + _.OnTimerMins; +} + +/// Set the number of minutes of the Off Timer setting. +/// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. +void IRHaierAC160::setOffTimer(const uint16_t mins) { + const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + _.OffTimerHrs = nr_mins / 60; + _.OffTimerMins = nr_mins % 60; + + const bool enabled = (nr_mins > 0); + uint8_t mode = getTimerMode(); + switch (mode) { + case kHaierAcYrw02OnTimer: + mode = enabled ? kHaierAcYrw02OnThenOffTimer : mode; + break; + case kHaierAcYrw02OnThenOffTimer: + case kHaierAcYrw02OffThenOnTimer: + mode = enabled ? kHaierAcYrw02OnThenOffTimer : kHaierAcYrw02OnTimer; + break; + default: + // Enable/Disable the Off timer for the simple case. + mode = enabled; + } + _.TimerMode = mode; +} + +/// Get the number of minutes of the Off Timer setting. +/// @return Nr of minutes. +uint16_t IRHaierAC160::getOffTimer(void) const { + return _.OffTimerHrs * 60 + _.OffTimerMins; +} + +/// Get the Lock setting of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRHaierAC160::getLock(void) const { return _.Lock; } + +/// Set the Lock setting of the A/C. +/// @param[in] on true, the setting is on. false, the setting is off. +void IRHaierAC160::setLock(const bool on) { + _.Button = kHaierAcYrw02ButtonLock; + _.Lock = on; +} + +/// Convert a stdAc::opmode_t enum into its native mode. +/// @param[in] mode The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRHaierAC160::convertMode(const stdAc::opmode_t mode) { + switch (mode) { + case stdAc::opmode_t::kCool: return kHaierAcYrw02Cool; + case stdAc::opmode_t::kHeat: return kHaierAcYrw02Heat; + case stdAc::opmode_t::kDry: return kHaierAcYrw02Dry; + case stdAc::opmode_t::kFan: return kHaierAcYrw02Fan; + default: return kHaierAcYrw02Auto; + } +} + +/// Convert a stdAc::fanspeed_t enum into it's native speed. +/// @param[in] speed The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRHaierAC160::convertFan(const stdAc::fanspeed_t speed) { + switch (speed) { + case stdAc::fanspeed_t::kMin: + case stdAc::fanspeed_t::kLow: return kHaierAcYrw02FanLow; + case stdAc::fanspeed_t::kMedium: return kHaierAcYrw02FanMed; + case stdAc::fanspeed_t::kHigh: + case stdAc::fanspeed_t::kMax: return kHaierAcYrw02FanHigh; + default: return kHaierAcYrw02FanAuto; + } +} + +/// Convert a stdAc::swingv_t enum into it's native setting. +/// @param[in] position The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRHaierAC160::convertSwingV(const stdAc::swingv_t position) { + switch (position) { + case stdAc::swingv_t::kHighest: return kHaierAc160SwingVTop; + case stdAc::swingv_t::kHigh: return kHaierAc160SwingVHigh; + case stdAc::swingv_t::kMiddle: return kHaierAc160SwingVMiddle; + case stdAc::swingv_t::kLow: return kHaierAc160SwingVLow; + case stdAc::swingv_t::kLowest: return kHaierAc160SwingVLowest; + case stdAc::swingv_t::kOff: return kHaierAc160SwingVOff; + default: return kHaierAc160SwingVAuto; + } +} + +/// Convert a native mode into its stdAc equivalent. +/// @param[in] mode The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::opmode_t IRHaierAC160::toCommonMode(const uint8_t mode) { + switch (mode) { + case kHaierAcYrw02Cool: return stdAc::opmode_t::kCool; + case kHaierAcYrw02Heat: return stdAc::opmode_t::kHeat; + case kHaierAcYrw02Dry: return stdAc::opmode_t::kDry; + case kHaierAcYrw02Fan: return stdAc::opmode_t::kFan; + default: return stdAc::opmode_t::kAuto; + } +} + +/// Convert a native fan speed into its stdAc equivalent. +/// @param[in] speed The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::fanspeed_t IRHaierAC160::toCommonFanSpeed(const uint8_t speed) { + switch (speed) { + case kHaierAcYrw02FanHigh: return stdAc::fanspeed_t::kMax; + case kHaierAcYrw02FanMed: return stdAc::fanspeed_t::kMedium; + case kHaierAcYrw02FanLow: return stdAc::fanspeed_t::kMin; + default: return stdAc::fanspeed_t::kAuto; + } +} + +/// Convert a stdAc::swingv_t enum into it's native setting. +/// @param[in] pos The enum to be converted. +/// @return The native equivalent of the enum. +stdAc::swingv_t IRHaierAC160::toCommonSwingV(const uint8_t pos) { + switch (pos) { + case kHaierAc160SwingVTop: + case kHaierAc160SwingVHighest: return stdAc::swingv_t::kHighest; + case kHaierAc160SwingVHigh: return stdAc::swingv_t::kHigh; + case kHaierAc160SwingVMiddle: return stdAc::swingv_t::kMiddle; + case kHaierAc160SwingVLow: return stdAc::swingv_t::kLow; + case kHaierAc160SwingVLowest: return stdAc::swingv_t::kLowest; + case kHaierAc160SwingVOff: return stdAc::swingv_t::kOff; + default: return stdAc::swingv_t::kAuto; + } +} + +/// Convert the current internal state into its stdAc::state_t equivalent. +/// @param[in] prev Ptr to the previous state if required. +/// @return The stdAc equivalent of the native settings. +stdAc::state_t IRHaierAC160::toCommon(const stdAc::state_t *prev) const { + stdAc::state_t result{}; + // Start with the previous state if given it. + if (prev != NULL) { + result = *prev; + } else { + // Set defaults for non-zero values that are not implicitly set for when + // there is no previous state. + // e.g. Any setting that toggles should probably go here. + result.light = false; + } + result.protocol = decode_type_t::HAIER_AC160; + result.power = _.Power; + result.mode = toCommonMode(_.Mode); + result.celsius = !_.UseFahrenheit; + result.degrees = getTemp(); + result.fanspeed = toCommonFanSpeed(_.Fan); + result.swingv = toCommonSwingV(_.SwingV); + result.swingh = stdAc::swingh_t::kOff; + result.sleep = _.Sleep ? 0 : -1; + result.turbo = _.Turbo; + result.quiet = _.Quiet; + result.clean = _.Clean && _.Clean2; + result.light ^= getLightToggle(); + result.filter = _.Health; + // Not supported. + result.model = -1; + result.econo = false; + result.beep = true; + result.clock = -1; + return result; +} + +/// Convert the current internal state into a human readable string. +/// @return A human readable string. +String IRHaierAC160::toString(void) const { + String result = ""; + result.reserve(280); // Reserve some heap for the string to reduce fragging. + result += addBoolToString(_.Power, kPowerStr, false); + uint8_t cmd = _.Button; + result += addIntToString(cmd, kButtonStr); + result += kSpaceLBraceStr; + switch (cmd) { + case kHaierAcYrw02ButtonPower: + result += kPowerStr; + break; + case kHaierAcYrw02ButtonMode: + result += kModeStr; + break; + case kHaierAcYrw02ButtonFan: + result += kFanStr; + break; + case kHaierAcYrw02ButtonTempUp: + result += kTempUpStr; + break; + case kHaierAcYrw02ButtonTempDown: + result += kTempDownStr; + break; + case kHaierAcYrw02ButtonSleep: + result += kSleepStr; + break; + case kHaierAcYrw02ButtonHealth: + result += kHealthStr; + break; + case kHaierAcYrw02ButtonSwingV: + result += kSwingVStr; + break; + case kHaierAcYrw02ButtonSwingH: + result += kSwingHStr; + break; + case kHaierAcYrw02ButtonTurbo: + result += kTurboStr; + break; + case kHaierAcYrw02ButtonTimer: + result += kTimerStr; + break; + case kHaierAcYrw02ButtonLock: + result += kLockStr; + break; + case kHaierAc160ButtonClean: + result += kCleanStr; + break; + case kHaierAc160ButtonLight: + result += kLightStr; + break; + case kHaierAc160ButtonAuxHeating: + result += kHeatingStr; + break; + case kHaierAcYrw02ButtonCFAB: + result += kCelsiusFahrenheitStr; + break; + default: + result += kUnknownStr; + } + result += ')'; + result += addModeToString(_.Mode, kHaierAcYrw02Auto, kHaierAcYrw02Cool, + kHaierAcYrw02Heat, kHaierAcYrw02Dry, + kHaierAcYrw02Fan); + result += addTempToString(getTemp(), !_.UseFahrenheit); + result += addFanToString(_.Fan, kHaierAcYrw02FanHigh, kHaierAcYrw02FanLow, + kHaierAcYrw02FanAuto, kHaierAcYrw02FanAuto, + kHaierAcYrw02FanMed); + result += addBoolToString(_.Turbo, kTurboStr); + result += addBoolToString(_.Quiet, kQuietStr); + result += addBoolToString(_.Health, kHealthStr); + result += addIntToString(_.SwingV, kSwingVStr); + result += kSpaceLBraceStr; + switch (_.SwingV) { + case kHaierAc160SwingVOff: result += kOffStr; break; + case kHaierAc160SwingVAuto: result += kAutoStr; break; + case kHaierAc160SwingVTop: result += kTopStr; break; + case kHaierAc160SwingVHighest: result += kHighestStr; break; + case kHaierAc160SwingVHigh: result += kHighStr; break; + case kHaierAc160SwingVMiddle: result += kMiddleStr; break; + case kHaierAc160SwingVLow: result += kLowStr; break; + case kHaierAc160SwingVLowest: result += kLowestStr; break; + default: result += kUnknownStr; + } + result += ')'; + result += addBoolToString(_.Sleep, kSleepStr); + result += addBoolToString(getClean(), kCleanStr); + const uint8_t tmode = getTimerMode(); + result += addIntToString(tmode, kTimerModeStr); + result += kSpaceLBraceStr; + switch (tmode) { + case kHaierAcYrw02NoTimers: + result += kNAStr; + break; + case kHaierAcYrw02OnTimer: + result += kOnStr; + break; + case kHaierAcYrw02OffTimer: + result += kOffStr; + break; + case kHaierAcYrw02OnThenOffTimer: + result += kOnStr; + result += '-'; + result += kOffStr; + break; + case kHaierAcYrw02OffThenOnTimer: + result += kOffStr; + result += '-'; + result += kOnStr; + break; + default: + result += kUnknownStr; + } + result += ')'; + result += addLabeledString((tmode != kHaierAcYrw02NoTimers && + tmode != kHaierAcYrw02OffTimer) ? + minsToString(getOnTimer()) : kOffStr, kOnTimerStr); + result += addLabeledString((tmode != kHaierAcYrw02NoTimers && + tmode != kHaierAcYrw02OnTimer) ? + minsToString(getOffTimer()) : kOffStr, kOffTimerStr); + result += addBoolToString(_.Lock, kLockStr); + result += addBoolToString(_.AuxHeating, kHeatingStr); + return result; +} +// End of IRHaierAC160 class. diff --git a/lib/IRremoteESP8266/src/ir_Haier.h b/lib/IRremoteESP8266/src/ir_Haier.h index 9afc862a5b..31cf4bcffc 100644 --- a/lib/IRremoteESP8266/src/ir_Haier.h +++ b/lib/IRremoteESP8266/src/ir_Haier.h @@ -146,6 +146,7 @@ const uint8_t kHaierAcYrw02DefTempC = 25; const uint8_t kHaierAcYrw02ModelA = 0xA6; const uint8_t kHaierAcYrw02ModelB = 0x59; const uint8_t kHaierAc176Prefix = 0xB7; +const uint8_t kHaierAc160Prefix = 0xB5; const uint8_t kHaierAcYrw02SwingVOff = 0x0; const uint8_t kHaierAcYrw02SwingVTop = 0x1; @@ -154,6 +155,15 @@ const uint8_t kHaierAcYrw02SwingVBottom = 0x3; // Only available in heat mode. const uint8_t kHaierAcYrw02SwingVDown = 0xA; const uint8_t kHaierAcYrw02SwingVAuto = 0xC; // Airflow +const uint8_t kHaierAc160SwingVOff = 0b0000; +const uint8_t kHaierAc160SwingVTop = 0b0001; +const uint8_t kHaierAc160SwingVHighest = 0b0010; +const uint8_t kHaierAc160SwingVHigh = 0b0100; +const uint8_t kHaierAc160SwingVMiddle = 0b0110; +const uint8_t kHaierAc160SwingVLow = 0b1000; +const uint8_t kHaierAc160SwingVLowest = 0b0011; +const uint8_t kHaierAc160SwingVAuto = 0b1100; // Airflow + const uint8_t kHaierAcYrw02SwingHMiddle = 0x0; const uint8_t kHaierAcYrw02SwingHLeftMax = 0x3; const uint8_t kHaierAcYrw02SwingHLeft = 0x4; @@ -184,6 +194,9 @@ const uint8_t kHaierAcYrw02ButtonTurbo = 0b01000; const uint8_t kHaierAcYrw02ButtonSleep = 0b01011; const uint8_t kHaierAcYrw02ButtonTimer = 0b10000; const uint8_t kHaierAcYrw02ButtonLock = 0b10100; +const uint8_t kHaierAc160ButtonLight = 0b10101; +const uint8_t kHaierAc160ButtonAuxHeating = 0b10110; +const uint8_t kHaierAc160ButtonClean = 0b11001; const uint8_t kHaierAcYrw02ButtonCFAB = 0b11010; const uint8_t kHaierAcYrw02NoTimers = 0b000; @@ -262,6 +275,75 @@ union HaierAc176Protocol{ }; }; +/// Native representation of a Haier 160 bit A/C message. +union HaierAc160Protocol{ + uint8_t raw[kHaierAC160StateLength]; ///< The state in native form + struct { + // Byte 0 + uint8_t Model :8; + // Byte 1 + uint8_t SwingV :4; + uint8_t Temp :4; // 16C~30C + // Byte 2 + uint8_t :5; + uint8_t SwingH :3; + // Byte 3 + uint8_t :1; + uint8_t Health :1; + uint8_t :3; + uint8_t TimerMode :3; + // Byte 4 + uint8_t :6; + uint8_t Power :1; + uint8_t AuxHeating :1; + // Byte 5 + uint8_t OffTimerHrs :5; + uint8_t Fan :3; + // Byte 6 + uint8_t OffTimerMins:6; + uint8_t Turbo :1; + uint8_t Quiet :1; + // Byte 7 + uint8_t OnTimerHrs :5; + uint8_t Mode :3; + // Byte 8 + uint8_t OnTimerMins :6; + uint8_t :1; + uint8_t Sleep :1; + // Byte 9 + uint8_t :8; + // Byte 10 + uint8_t ExtraDegreeF :1; + uint8_t :3; + uint8_t Clean :1; + uint8_t UseFahrenheit:1; + uint8_t :2; + // Byte 11 + uint8_t :8; + // Byte 12 + uint8_t Button :5; + uint8_t Lock :1; + uint8_t :2; + // Byte 13 + uint8_t Sum :8; + // Byte 14 + uint8_t Prefix :8; + // Byte 15 + uint8_t :6; + uint8_t Clean2 :1; + uint8_t :1; + // Byte 16 + uint8_t :5; + uint8_t Fan2 :3; + // Byte 17 + uint8_t :8; + // Byte 18 + uint8_t :8; + // Byte 19 + uint8_t Sum2 :8; + }; +}; + // Legacy Haier YRW02 remote defines. #define HAIER_AC_YRW02_SWING_OFF kHaierAcYrw02SwingOff #define HAIER_AC_YRW02_SWING_TOP kHaierAcYrw02SwingTop @@ -476,4 +558,96 @@ class IRHaierACYRW02 : public IRHaierAC176 { const uint8_t state[], const uint16_t length = kHaierACYRW02StateLength); }; + +/// Class for handling detailed Haier 160 bit A/C messages. +class IRHaierAC160 { + public: + explicit IRHaierAC160(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); +#if SEND_HAIER_AC160 + virtual void send(const uint16_t repeat = kHaierAc160DefaultRepeat); + /// Run the calibration to calculate uSec timing offsets for this platform. + /// @return The uSec timing offset needed per modulation of the IR Led. + /// @note This will produce a 65ms IR signal pulse at 38kHz. + /// Only ever needs to be run once per object instantiation, if at all. + int8_t calibrate(void) { return _irsend.calibrate(); } +#endif // SEND_HAIER_AC160 + void begin(void); + void stateReset(void); + + void setButton(const uint8_t button); + uint8_t getButton(void) const; + + void setUseFahrenheit(const bool on); + bool getUseFahrenheit(void) const; + void setTemp(const uint8_t temp, const bool fahrenheit = false); + uint8_t getTemp(void) const; + + void setFan(const uint8_t speed); + uint8_t getFan(void) const; + + uint8_t getMode(void) const; + void setMode(const uint8_t mode); + + bool getPower(void) const; + void setPower(const bool on); + void on(void); + void off(void); + + bool getSleep(void) const; + void setSleep(const bool on); + bool getClean(void) const; + void setClean(const bool on); + bool getLightToggle(void) const; + void setLightToggle(const bool on); + + bool getTurbo(void) const; + void setTurbo(const bool on); + bool getQuiet(void) const; + void setQuiet(const bool on); + bool getAuxHeating(void) const; + void setAuxHeating(const bool on); + + uint8_t getSwingV(void) const; + void setSwingV(const uint8_t pos); + + void setTimerMode(const uint8_t setting); + uint8_t getTimerMode(void) const; + void setOnTimer(const uint16_t mins); + uint16_t getOnTimer(void) const; + void setOffTimer(const uint16_t mins); + uint16_t getOffTimer(void) const; + + bool getLock(void) const; + void setLock(const bool on); + + bool getHealth(void) const; + void setHealth(const bool on); + + uint8_t* getRaw(void); + virtual void setRaw(const uint8_t new_code[]); + static bool validChecksum(const uint8_t state[], + const uint16_t length = kHaierAC160StateLength); + static uint8_t convertMode(const stdAc::opmode_t mode); + static uint8_t convertFan(const stdAc::fanspeed_t speed); + static uint8_t convertSwingV(const stdAc::swingv_t position); + static stdAc::opmode_t toCommonMode(const uint8_t mode); + static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); + static stdAc::swingv_t toCommonSwingV(const uint8_t pos); + static bool toCommonTurbo(const uint8_t speed); + static bool toCommonQuiet(const uint8_t speed); + stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const; + String toString(void) const; +#ifndef UNIT_TEST + + private: + IRsend _irsend; ///< Instance of the IR send class +#else // UNIT_TEST + /// @cond IGNORE + IRsendTest _irsend; ///< Instance of the testing IR send class + /// @endcond +#endif // UNIT_TEST + HaierAc160Protocol _; + void checksum(void); +}; #endif // IR_HAIER_H_ diff --git a/lib/IRremoteESP8266/src/ir_Kelvinator.h b/lib/IRremoteESP8266/src/ir_Kelvinator.h index 32cb3e1fa0..342c60592d 100644 --- a/lib/IRremoteESP8266/src/ir_Kelvinator.h +++ b/lib/IRremoteESP8266/src/ir_Kelvinator.h @@ -13,7 +13,7 @@ // Brand: Kelvinator, Model: KSV70CRC A/C // Brand: Kelvinator, Model: KSV70HRC A/C // Brand: Kelvinator, Model: KSV80HRC A/C -// Brand: Green, Model: YAPOF3 remote +// Brand: Gree, Model: YAPOF3 remote // Brand: Gree, Model: YAP0F8 remote // Brand: Sharp, Model: YB1FA remote // Brand: Sharp, Model: A5VEY A/C diff --git a/lib/IRremoteESP8266/src/ir_Midea.cpp b/lib/IRremoteESP8266/src/ir_Midea.cpp index 4fbc07973e..80acfcda38 100644 --- a/lib/IRremoteESP8266/src/ir_Midea.cpp +++ b/lib/IRremoteESP8266/src/ir_Midea.cpp @@ -679,6 +679,7 @@ stdAc::state_t IRMideaAC::toCommon(const stdAc::state_t *prev) { result.mode = toCommonMode(_.Mode); result.celsius = !_.useFahrenheit; result.degrees = getTemp(result.celsius); + result.sensorTemperature = getSensorTemp(result.celsius); result.fanspeed = toCommonFanSpeed(_.Fan); result.sleep = _.Sleep ? 0 : -1; result.econo = getEconoToggle(); diff --git a/lib/IRremoteESP8266/src/ir_Mirage.cpp b/lib/IRremoteESP8266/src/ir_Mirage.cpp index e3e7c60d3a..b7d6ce42d2 100644 --- a/lib/IRremoteESP8266/src/ir_Mirage.cpp +++ b/lib/IRremoteESP8266/src/ir_Mirage.cpp @@ -740,6 +740,7 @@ stdAc::state_t IRMirageAc::toCommon(void) const { result.mode = toCommonMode(_.Mode); result.celsius = true; result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); result.fanspeed = toCommonFanSpeed(getFan(), _model); result.swingv = toCommonSwingV(getSwingV()); result.swingh = getSwingH() ? stdAc::swingh_t::kAuto : stdAc::swingh_t::kOff; @@ -750,6 +751,7 @@ stdAc::state_t IRMirageAc::toCommon(void) const { result.sleep = getSleep() ? 0 : -1; result.quiet = getQuiet(); result.clock = getClock() / 60; + result.iFeel = getIFeel(); // Not supported. result.econo = false; result.beep = false; @@ -775,10 +777,14 @@ void IRMirageAc::fromCommon(const stdAc::state_t state) { setFilter(state.filter); // setClock() expects seconds, not minutes. setClock((state.clock > 0) ? state.clock * 60 : 0); + setIFeel(state.iFeel); + if (state.sensorTemperature != kNoTempValue) { + setSensorTemp(state.celsius ? state.sensorTemperature + : fahrenheitToCelsius(state.sensorTemperature)); + } // Non-common settings. setOnTimer(0); setOffTimer(0); - setIFeel(false); } /// Convert the internal state into a human readable string. diff --git a/lib/IRremoteESP8266/src/ir_Mitsubishi.h b/lib/IRremoteESP8266/src/ir_Mitsubishi.h index 85e61eefdd..4f9954f8b3 100644 --- a/lib/IRremoteESP8266/src/ir_Mitsubishi.h +++ b/lib/IRremoteESP8266/src/ir_Mitsubishi.h @@ -36,6 +36,7 @@ // Brand: Mitsubishi Electric, Model: MSZ-ZW4017S A/C (MITSUBISHI_AC) // Brand: Mitsubishi Electric, Model: MSZ-FHnnVE A/C (MITSUBISHI_AC) // Brand: Mitsubishi Electric, Model: RH151 remote (MITSUBISHI_AC) +// Brand: Mitsubishi Electric, Model: PAR-FA32MA remote (MITSUBISHI136) #ifndef IR_MITSUBISHI_H_ #define IR_MITSUBISHI_H_ diff --git a/lib/IRremoteESP8266/src/ir_NEC.h b/lib/IRremoteESP8266/src/ir_NEC.h index 95da064b78..c9b0a6ec15 100644 --- a/lib/IRremoteESP8266/src/ir_NEC.h +++ b/lib/IRremoteESP8266/src/ir_NEC.h @@ -14,6 +14,8 @@ // Brand: Duux, Model: Blizzard Smart 10K / DXMA04 A/C // Brand: Duux, Model: YJ-A081 TR Remote // Brand: Silan Microelectronics, Model: SC6121-001 IC +// Brand: BBK, Model: SP550S 5.1 sound system +// Brand: Tanix, Model: TX3 mini Android TV Box #ifndef IR_NEC_H_ #define IR_NEC_H_ diff --git a/lib/IRremoteESP8266/src/ir_Panasonic.cpp b/lib/IRremoteESP8266/src/ir_Panasonic.cpp index a0a0b6b23d..82acaac71c 100644 --- a/lib/IRremoteESP8266/src/ir_Panasonic.cpp +++ b/lib/IRremoteESP8266/src/ir_Panasonic.cpp @@ -128,8 +128,15 @@ uint64_t IRsend::encodePanasonic(const uint16_t manufacturer, bool IRrecv::decodePanasonic(decode_results *results, uint16_t offset, const uint16_t nbits, const bool strict, const uint32_t manufacturer) { - if (strict && nbits != kPanasonicBits) - return false; // Request is out of spec. + if (strict) { // Compliance checks + switch (nbits) { + case kPanasonic40Bits: + case kPanasonicBits: + break; + default: + return false; // Request is out of spec. + } + } uint64_t data = 0; @@ -147,8 +154,10 @@ bool IRrecv::decodePanasonic(decode_results *results, uint16_t offset, if (address != manufacturer) // Verify the Manufacturer code. return false; // Verify the checksum. - uint8_t checksumOrig = data; - uint8_t checksumCalc = (data >> 24) ^ (data >> 16) ^ (data >> 8); + const uint8_t checksumOrig = data; + uint8_t checksumCalc = (data >> 16) ^ (data >> 8); + if (nbits != kPanasonic40Bits) + checksumCalc ^= (data >> 24); if (checksumOrig != checksumCalc) return false; } diff --git a/lib/IRremoteESP8266/src/ir_Panasonic.h b/lib/IRremoteESP8266/src/ir_Panasonic.h index 5668e4a57a..50b0783ac1 100644 --- a/lib/IRremoteESP8266/src/ir_Panasonic.h +++ b/lib/IRremoteESP8266/src/ir_Panasonic.h @@ -20,9 +20,11 @@ // Brand: Panasonic, Model: CS-Z9RKR A/C (PANASONIC_AC RKR/6) // Brand: Panasonic, Model: CS-Z24RKR A/C (PANASONIC_AC RKR/6) // Brand: Panasonic, Model: CS-YW9MKD A/C (PANASONIC_AC JKE/4) +// Brand: Panasonic, Model: CS-E12QKEW A/C (PANASONIC_AC DKE/3) // Brand: Panasonic, Model: A75C2311 remote (PANASONIC_AC CKP/5) // Brand: Panasonic, Model: A75C2616-1 remote (PANASONIC_AC DKE/3) // Brand: Panasonic, Model: A75C3704 remote (PANASONIC_AC DKE/3) +// Brand: Panasonic, Model: PN1122V remote (PANASONIC_AC DKE/3) // Brand: Panasonic, Model: A75C3747 remote (PANASONIC_AC JKE/4) // Brand: Panasonic, Model: CS-E9CKP series A/C (PANASONIC_AC32) // Brand: Panasonic, Model: A75C2295 remote (PANASONIC_AC32) diff --git a/lib/IRremoteESP8266/src/ir_RCMM.cpp b/lib/IRremoteESP8266/src/ir_RCMM.cpp index 97a3c79b5b..00cc58f028 100644 --- a/lib/IRremoteESP8266/src/ir_RCMM.cpp +++ b/lib/IRremoteESP8266/src/ir_RCMM.cpp @@ -35,7 +35,6 @@ const uint16_t kRcmmMinGapTicks = 120; const uint32_t kRcmmMinGap = 3360; // Use a tolerance of +/-10% when matching some data spaces. const uint8_t kRcmmTolerance = 10; -const uint16_t kRcmmExcess = 50; #if SEND_RCMM /// Send a Philips RC-MM packet. diff --git a/lib/IRremoteESP8266/src/ir_Samsung.cpp b/lib/IRremoteESP8266/src/ir_Samsung.cpp index b3fe2a8601..958f2665bd 100644 --- a/lib/IRremoteESP8266/src/ir_Samsung.cpp +++ b/lib/IRremoteESP8266/src/ir_Samsung.cpp @@ -82,7 +82,8 @@ using irutils::addTempToString; using irutils::addToggleToString; using irutils::minsToString; -#if SEND_SAMSUNG +// This sending protocol is used by some other protocols. e.g. LG. +#if (SEND_SAMSUNG || SEND_LG) /// Send a 32-bit Samsung formatted message. /// Status: STABLE / Should be working. /// @param[in] data The message to be sent. @@ -112,7 +113,7 @@ uint32_t IRsend::encodeSAMSUNG(const uint8_t customer, const uint8_t command) { return ((revcommand ^ 0xFF) | (revcommand << 8) | (revcustomer << 16) | (revcustomer << 24)); } -#endif +#endif // (SEND_SAMSUNG || SEND_LG) #if DECODE_SAMSUNG /// Decode the supplied Samsung 32-bit message. diff --git a/lib/IRremoteESP8266/src/ir_Samsung.h b/lib/IRremoteESP8266/src/ir_Samsung.h index acabb36481..6c59c7af4e 100644 --- a/lib/IRremoteESP8266/src/ir_Samsung.h +++ b/lib/IRremoteESP8266/src/ir_Samsung.h @@ -12,6 +12,7 @@ // Supports: // Brand: Samsung, Model: UA55H6300 TV (SAMSUNG) // Brand: Samsung, Model: BN59-01178B TV remote (SAMSUNG) +// Brand: Samsung, Model: UE40K5510AUXRU TV (SAMSUNG) // Brand: Samsung, Model: DB63-03556X003 remote // Brand: Samsung, Model: DB93-16761C remote // Brand: Samsung, Model: IEC-R03 remote diff --git a/lib/IRremoteESP8266/src/ir_Sanyo.cpp b/lib/IRremoteESP8266/src/ir_Sanyo.cpp index 4a38e8e091..4b99d04922 100644 --- a/lib/IRremoteESP8266/src/ir_Sanyo.cpp +++ b/lib/IRremoteESP8266/src/ir_Sanyo.cpp @@ -622,10 +622,12 @@ stdAc::state_t IRSanyoAc::toCommon(void) const { result.mode = toCommonMode(_.Mode); result.celsius = true; result.degrees = getTemp(); + result.sensorTemperature = getSensorTemp(); result.fanspeed = toCommonFanSpeed(_.Fan); result.sleep = _.Sleep ? 0 : -1; result.swingv = toCommonSwingV(_.SwingV); result.beep = _.Beep; + result.iFeel = !getSensor(); // Not supported. result.swingh = stdAc::swingh_t::kOff; result.turbo = false; @@ -762,13 +764,13 @@ void IRSanyoAc88::stateReset(void) { /// Set up hardware to be able to send a message. void IRSanyoAc88::begin(void) { _irsend.begin(); } -#if SEND_SANYO_AC +#if SEND_SANYO_AC88 /// Send the current internal state as IR messages. /// @param[in] repeat Nr. of times the message will be repeated. void IRSanyoAc88::send(const uint16_t repeat) { _irsend.sendSanyoAc88(getRaw(), kSanyoAc88StateLength, repeat); } -#endif // SEND_SANYO_AC +#endif // SEND_SANYO_AC88 /// Get a PTR to the internal state/code for this protocol with all integrity /// checks passing. diff --git a/lib/IRremoteESP8266/src/ir_Sony.cpp b/lib/IRremoteESP8266/src/ir_Sony.cpp index 5746ee9b19..fb7b9af6f5 100644 --- a/lib/IRremoteESP8266/src/ir_Sony.cpp +++ b/lib/IRremoteESP8266/src/ir_Sony.cpp @@ -11,6 +11,7 @@ // Supports: // Brand: Sony, Model: HT-CT380 Soundbar (Uses 38kHz & 3 repeats) +// Brand: Sony, Model: HT-SF150 Soundbar (Uses 38kHz & 3 repeats) #include #include "IRrecv.h" diff --git a/lib/IRremoteESP8266/src/ir_Wowwee.cpp b/lib/IRremoteESP8266/src/ir_Wowwee.cpp new file mode 100644 index 0000000000..d999f0c4be --- /dev/null +++ b/lib/IRremoteESP8266/src/ir_Wowwee.cpp @@ -0,0 +1,91 @@ +// Copyright 2022 David Conran + +/// @file +/// @brief Support for WowWee RoboRapter protocol +/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues1938 + +// Supports: +// Brand: WowWee, Model: RoboRapter-X + +// WowWee RoboRapter-X messages +// Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1938#issuecomment-1367968228 +// +// Button Code +// ====== ===== +// Left 0x180 +// Forward 0x186 +// Backward 0x187 +// Right 0x188 +// Stop 0x18E +// Head Counterclockwise 0x191 +// Tail Left 0x192 +// Tail Right 0x193 +// Head Clockwise 0x194 +// Guard Mode 0x1B0 +// Roam 0x1B1 +// Cautious Mood 0x1B2 +// Playful Mood 0x1B3 +// Hunting Mood 0x1B4 +// Demo 0x1D0 +// Bite 0x1D1 + +#include +#include "IRrecv.h" +#include "IRsend.h" +#include "IRutils.h" + +// Constants +const uint16_t kWowweeHdrMark = 6684; +const uint16_t kWowweeHdrSpace = 723; +const uint16_t kWowweeBitMark = 912; +const uint16_t kWowweeOneSpace = 3259; +const uint16_t kWowweeZeroSpace = kWowweeHdrSpace; +const uint16_t kWowweeFreq = 38000; // Hz. (Just a guess) + + +#if SEND_WOWWEE +/// Send a WowWee formatted message. +/// Status: STABLE / Confirmed working with real device. +/// @param[in] data The message to be sent. +/// @param[in] nbits The number of bits of message to be sent. +/// @param[in] repeat The number of times the command is to be repeated. +void IRsend::sendWowwee(uint64_t data, uint16_t nbits, uint16_t repeat) { + sendGeneric(kWowweeHdrMark, kWowweeHdrSpace, + kWowweeBitMark, kWowweeOneSpace, + kWowweeBitMark, kWowweeZeroSpace, + kWowweeBitMark, kDefaultMessageGap, data, + nbits, kWowweeFreq, true, repeat, 33); +} +#endif // SEND_WOWWEE + +#if DECODE_WOWWEE +/// Decode the supplied WowWee message. +/// Status: STABLE / Confirmed working with real device. +/// @param[in,out] results Ptr to the data to decode & where to store the result +/// @param[in] offset The starting index to use when attempting to decode the +/// raw data. Typically/Defaults to kStartOffset. +/// @param[in] nbits The number of data bits to expect. +/// @param[in] strict Flag indicating if we should perform strict matching. +bool IRrecv::decodeWowwee(decode_results *results, uint16_t offset, + const uint16_t nbits, const bool strict) { + if (strict && nbits != kWowweeBits) + return false; // We expect Wowwee to be a certain sized message. + + uint64_t data = 0; + + // Match Header + Data + Footer + if (!matchGeneric(results->rawbuf + offset, &data, + results->rawlen - offset, nbits, + kWowweeHdrMark, kWowweeHdrSpace, + kWowweeBitMark, kWowweeOneSpace, + kWowweeBitMark, kWowweeZeroSpace, + kWowweeBitMark, kDefaultMessageGap, true)) return false; + // Success + results->bits = nbits; + results->value = data; + results->decode_type = WOWWEE; + results->command = 0; + results->address = 0; + return true; +} +#endif // DECODE_WOWWEE diff --git a/lib/IRremoteESP8266/src/ir_Xmp.cpp b/lib/IRremoteESP8266/src/ir_Xmp.cpp index 29d7f6c1bb..5d9da4c522 100644 --- a/lib/IRremoteESP8266/src/ir_Xmp.cpp +++ b/lib/IRremoteESP8266/src/ir_Xmp.cpp @@ -115,7 +115,7 @@ using IRXmpUtils::adjustRepeat; #if SEND_XMP /// Send a XMP packet. -/// Status: Beta / Untested against a real device. +/// Status: STABLE / Confirmed working against a real device. /// @param[in] data The message to be sent. /// @param[in] nbits The number of bits of message to be sent. /// @param[in] repeat The number of times the command is to be repeated. @@ -150,7 +150,7 @@ void IRsend::sendXmp(const uint64_t data, const uint16_t nbits, #if DECODE_XMP /// Decode the supplied XMP packet/message. -/// Status: BETA / Probably works. +/// Status: STABLE / Confirmed working against a real device. /// @param[in,out] results Ptr to the data to decode & where to store the result /// @param[in] offset The starting index to use when attempting to decode the /// raw data. Typically/Defaults to kStartOffset. diff --git a/lib/IRremoteESP8266/src/ir_York.cpp b/lib/IRremoteESP8266/src/ir_York.cpp new file mode 100644 index 0000000000..f017293287 --- /dev/null +++ b/lib/IRremoteESP8266/src/ir_York.cpp @@ -0,0 +1,357 @@ +// Copyright 2022 Daniele Gobbetti + +/// @file +/// @brief Support for the York AC protocol (remote GRYLH2A) + +// Note: Most of the code is autogenerated by the provided tools or assembled +// from other support classes + +#include "ir_York.h" +#include +#include +#ifndef ARDUINO +#include +#endif +#include "IRrecv.h" +#include "IRremoteESP8266.h" +#include "IRsend.h" +#ifdef UNIT_TEST +#include "IRsend_test.h" +#endif +#include "IRtext.h" +#include "IRutils.h" + + +using irutils::addBoolToString; +using irutils::addModeToString; +using irutils::addFanToString; +using irutils::addTempToString; +using irutils::addLabeledString; +using irutils::minsToString; + + +// Constants +const uint16_t kYorkHdrMark = 4887; +const uint16_t kYorkBitMark = 612; +const uint16_t kYorkHdrSpace = 2267; +const uint16_t kYorkOneSpace = 1778; +const uint16_t kYorkZeroSpace = 579; +const uint16_t kYorkFreq = 38000; // Hz. (Guessing the most common frequency.) + +#if SEND_YORK +/// Send a 17 Byte / 136 bit York A/C message. +/// Status: ALPHA / Untested. +/// @param[in] data An array of bytes containing the IR command. +/// @param[in] nbytes Nr. of bytes of data in the array. (>=kStateLength) +/// @param[in] repeat Nr. of times the message is to be repeated. +void IRsend::sendYork(const uint8_t data[], const uint16_t nbytes, + const uint16_t repeat) { + if (nbytes < kYorkStateLength) + return; + sendGeneric(kYorkHdrMark, kYorkHdrSpace, + kYorkBitMark, kYorkOneSpace, + kYorkBitMark, kYorkZeroSpace, + kYorkBitMark, kDefaultMessageGap, + data, nbytes, kYorkFreq, + false, repeat, kDutyDefault); // false == LSB +} +#endif // SEND_YORK + +#if DECODE_YORK +/// Decode the supplied message. +/// Status: ALPHA / Tested, some values still are not mapped to the internal +/// state of AC +/// @param[in,out] results Ptr to the data to decode & where to store the decode +/// @param[in] offset The starting index to use when attempting to decode the +/// raw data. Typically/Defaults to kStartOffset. +/// @param[in] nbits The number of data bits to expect. +/// @param[in] strict Flag indicating if we should perform strict matching. +/// @return A boolean. True if it can decode it, false if it can't. +bool IRrecv::decodeYork(decode_results *results, uint16_t offset, + const uint16_t nbits, const bool strict) { + if (strict && nbits != kYorkBits) + return false; + + uint16_t used = 0; + + used = matchGeneric(results->rawbuf + offset, results->state, + results->rawlen - offset, nbits, + kYorkHdrMark, kYorkHdrSpace, + kYorkBitMark, kYorkOneSpace, + kYorkBitMark, kYorkZeroSpace, + kYorkBitMark, kDefaultMessageGap, + false, _tolerance, kMarkExcess, + false); // LSB + if (used == 0) return false; // We failed to find any data. + + // Succes + results->decode_type = decode_type_t::YORK; + results->bits = nbits; + + return true; +} +#endif // DECODE_YORK + +// +// +/// Class constructor +/// @param[in] pin GPIO to be used when sending. +/// @param[in] inverted Is the output signal to be inverted? +/// @param[in] use_modulation Is frequency modulation to be used? +IRYorkAc::IRYorkAc(const uint16_t pin, const bool inverted, + const bool use_modulation) + : _irsend(pin, inverted, use_modulation) { + stateReset(); + } + +// Reset the internal state to a fixed known good state. +void IRYorkAc::stateReset() { + // This resets to a known-good state. + setRaw(kYorkKnownGoodState); +} + +/// Set up hardware to be able to send a message. +void IRYorkAc::begin(void) { _irsend.begin(); } + +/// Get the raw state of the object, suitable to be sent with the appropriate +/// IRsend object method. +/// @return A copy of the internal state. +uint8_t *IRYorkAc::getRaw(void) { + calcChecksum(); + return _.raw; +} + +/// Set the internal state from a valid code for this protocol. +/// @param[in] new_code A valid code for this protocol. +/// @param[in] length Length of the code in bytes. +void IRYorkAc::setRaw(const uint8_t new_code[], const uint16_t length) { + std::memcpy(_.raw, new_code, length); +} + +#if SEND_YORK +/// Send the current internal state as an IR message. +/// @param[in] repeat Nr. of times the message will be repeated. +void IRYorkAc::send(const uint16_t repeat) { + _irsend.sendYork(getRaw(), kYorkStateLength, repeat); +} +#endif // SEND_YORK + +/// Get the current operation mode setting. +/// @return The current operation mode. +uint8_t IRYorkAc::getMode(void) const { + return _.Mode; +} + +/// Set the desired operation mode. +/// @param[in] mode The desired operation mode. +void IRYorkAc::setMode(const uint8_t mode) { + switch (mode) { + case kYorkFan: + case kYorkCool: + case kYorkHeat: + case kYorkDry: + _.Mode = mode; + break; + default: + _.Mode = kYorkAuto; + } + setFan(getFan()); // Ensure the fan is at the correct speed for the new mode. +} + +/// Convert a stdAc::opmode_t enum into its native mode. +/// @param[in] mode The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRYorkAc::convertMode(const stdAc::opmode_t mode) { + switch (mode) { + case stdAc::opmode_t::kCool: return kYorkCool; + case stdAc::opmode_t::kHeat: return kYorkHeat; + case stdAc::opmode_t::kDry: return kYorkDry; + case stdAc::opmode_t::kFan: return kYorkFan; + default: return kYorkAuto; + } +} + +/// Convert a native mode into its stdAc equivalent. +/// @param[in] mode The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::opmode_t IRYorkAc::toCommonMode(const uint8_t mode) { + switch (mode) { + case kYorkCool: return stdAc::opmode_t::kCool; + case kYorkHeat: return stdAc::opmode_t::kHeat; + case kYorkDry: return stdAc::opmode_t::kDry; + case kYorkFan: return stdAc::opmode_t::kFan; + default: return stdAc::opmode_t::kAuto; + } +} + +/// Set the speed of the fan. +/// @param[in] speed The desired setting. +/// @note The fan speed is locked to Low when in Dry mode, to auto when in auto +/// mode. "Fan" mode has no support for "auto" speed. +void IRYorkAc::setFan(const uint8_t speed) { + switch (getMode()) { + case kYorkDry: + _.Fan = kYorkFanLow; + break; + case kYorkFan: + _.Fan = std::min(speed, kYorkFanHigh); + break; + case kYorkAuto: + _.Fan = kYorkFanAuto; + break; + default: + _.Fan = std::min(speed, kYorkFanAuto); + } +} + +/// Get the current fan speed setting. +/// @return The current fan speed. +uint8_t IRYorkAc::getFan(void) const { + return _.Fan; +} + +/// Convert a stdAc::fanspeed_t enum into it's native speed. +/// @param[in] speed The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRYorkAc::convertFan(const stdAc::fanspeed_t speed) { + switch (speed) { + case stdAc::fanspeed_t::kMin: + case stdAc::fanspeed_t::kLow: + return kYorkFanLow; + case stdAc::fanspeed_t::kMedium: + return kYorkFanMedium; + case stdAc::fanspeed_t::kHigh: + case stdAc::fanspeed_t::kMax: + return kYorkFanHigh; + default: + return kYorkFanAuto; + } +} + +/// Convert a native fan speed into its stdAc equivalent. +/// @param[in] speed The native setting to be converted. +/// @return The stdAc equivalent of the native setting. +stdAc::fanspeed_t IRYorkAc::toCommonFanSpeed(const uint8_t speed) { + switch (speed) { + case kYorkFanHigh: return stdAc::fanspeed_t::kMax; + case kYorkFanMedium: return stdAc::fanspeed_t::kMedium; + case kYorkFanLow: return stdAc::fanspeed_t::kMin; + default: return stdAc::fanspeed_t::kAuto; + } +} + +/// Set the temperature. +/// @param[in] degrees The temperature in degrees celsius. +void IRYorkAc::setTemp(const uint8_t degrees) { + _.Temp = std::min(kYorkMaxTemp, std::max(kYorkMinTemp, degrees)); +} + +/// Get the current temperature setting. +/// @return Get current setting for temp. in degrees celsius. +uint8_t IRYorkAc::getTemp(void) const { + return _.Temp; +} + +/// Set the On Timer value of the A/C. +/// @param[in] nr_of_mins The number of minutes the timer should be. +/// @note The timer time only has a resolution of 10 mins. +/// @note Setting the On Timer active will cancel the Sleep timer/setting. +void IRYorkAc::setOnTimer(const uint16_t nr_of_mins) { + _.OnTimer = nr_of_mins / 10; +} + +/// Set the Off Timer value of the A/C. +/// @param[in] nr_of_mins The number of minutes the timer should be. +/// @note The timer time only has a resolution of 10 mins. +/// @note Setting the Off Timer active will cancel the Sleep timer/setting. +void IRYorkAc::setOffTimer(const uint16_t nr_of_mins) { + _.OffTimer = nr_of_mins / 10; +} + + +/// Get the On Timer setting of the A/C. +/// @return The Nr. of minutes the On Timer is set for. +uint16_t IRYorkAc::getOnTimer(void) const { + return _.OnTimer * 10; +} + +/// Get the Off Timer setting of the A/C. +/// @return The Nr. of minutes the Off Timer is set for. +/// @note Sleep & Off Timer share the same timer. +uint16_t IRYorkAc::getOffTimer(void) const { + return _.OffTimer * 10; +} + +/// CRC16-16 (a.k.a. CRC-16-IBM) +void IRYorkAc::calcChecksum() { + uint8_t length = 14; + uint16_t reg_crc = 0x0000; + uint8_t* data = _.raw; + while (length--) { + reg_crc ^= *data++; + for (uint16_t index = 0; index < 8; index++) { + if (reg_crc & 0x01) { + reg_crc = (reg_crc>>1) ^ 0xA001; + } else { + reg_crc = reg_crc >>1; + } + } + } + _.Chk1 = (reg_crc & 0xff); + _.Chk2 = ((reg_crc >> 8) & 0x00ff); +} + +/// Convert the current internal state into its stdAc::state_t equivalent. +/// @param[in] prev Ptr to the previous state if required. +/// @return The stdAc equivalent of the native settings. +stdAc::state_t IRYorkAc::toCommon(const stdAc::state_t *prev) const { + stdAc::state_t result{}; + // Start with the previous state if given it. + if (prev != NULL) { + result = *prev; + } else { + // Set defaults for non-zero values that are not implicitly set for when + // there is no previous state. + // e.g. Any setting that toggles should probably go here. + result.power = false; + } + result.protocol = decode_type_t::YORK; + result.mode = toCommonMode(_.Mode); + result.celsius = true; + result.degrees = getTemp(); + result.fanspeed = toCommonFanSpeed(_.Fan); + result.swingv = _.SwingV ? stdAc::swingv_t::kAuto : stdAc::swingv_t::kOff; + result.sleep = getOffTimer(); + // Not supported. + result.model = -1; + result.turbo = false; + 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.clock = -1; + return result; +} + +/// Convert the current internal state into a human readable string. +/// @return A human readable string. +String IRYorkAc::toString(void) const { + String result = ""; + result.reserve(70); // Reserve some heap for the string to reduce fragging. + result += addBoolToString(_.Power, kPowerStr, false); + + result += addModeToString(_.Mode, kYorkAuto, kYorkCool, + kYorkHeat, kYorkDry, kYorkFan); + result += addFanToString(_.Fan, kYorkFanHigh, kYorkFanLow, + kYorkFanAuto, kYorkFanAuto, + kYorkFanMedium); + result += addTempToString(getTemp(), true); + result += addBoolToString(_.SwingV, kSwingVStr); + result += addLabeledString(minsToString(getOnTimer()), kOnTimerStr); + result += addLabeledString(minsToString(getOffTimer()), kOffTimerStr); + + return result; +} diff --git a/lib/IRremoteESP8266/src/ir_York.h b/lib/IRremoteESP8266/src/ir_York.h new file mode 100644 index 0000000000..3de56bb898 --- /dev/null +++ b/lib/IRremoteESP8266/src/ir_York.h @@ -0,0 +1,137 @@ +// Copyright 2022 Daniele Gobbetti + +/// @file +/// @brief Support for the York AC protocol (remote GRYLH2A) + +// Supports: +// Brand: York, Model: MHH07P17 A/C +// Brand: York, Model: GRYLH2A remote + +#ifndef IR_YORK_H_ +#define IR_YORK_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 + + +/// Native representation of a York A/C message. +union YorkProtocol{ + uint8_t raw[kYorkStateLength]; ///< The state of the IR remote. + struct { + // byte 0-5 + uint8_t preamble[6]; // unknown, fixed 0x08, 0x10, 0x07, 0x02, 0x40, 0x08 + // byte 6 + uint8_t Key1 :4; // key pressed on the remote: 1 power, 2 temp up, 3 + // temp down... + uint8_t Key2 :4; // only set when setting ontime/offtime: + // Key1 value is 0x6 (enter key) and Key2 is 0x3 for + // "start" and 0x2 for "stop" + // byte 7 + uint8_t Fan :4; // Fan speed: 1 low, 2 mid, 3 max, 8 auto + uint8_t Power :1; // main unit power: 1 on, 0 off + uint8_t :3; + // byte 8 + uint8_t Mode :4; // 1 heat, 2 cool, 3 dry, 4 fan, 8 auto + uint8_t :4; + // byte 9 + uint8_t :2; + uint8_t Temp :6; // Degrees Celsius + // byte 10 + uint8_t OffTimer :8; // Power off time: 10s of minutes from now + // byte 11 + uint8_t OnTimer :8; // Power on time: 10s of minutes from now + // byte 12 + uint8_t :8; // unknown, normally 0x00, could be 0x08 when ontime + // set, 0x88 if both on and offtime set, 0x60 if + // sleep mode set + // byte 13 + uint8_t SwingV :1; // 0 off, 1 on + uint8_t :7; + // byte 14 + uint8_t :8; // checksum preamble, fixed 0xEC + // byte 15-16 + uint8_t Chk1 :8; // checksum, algorithm CRC-16/ARC, first byte + uint8_t Chk2 :8; // checksum, algorithm CRC-16/ARC, second byte + }; +}; + +// Constants +const uint8_t kYorkKnownGoodState[kYorkStateLength] = { + 0x08, 0x10, 0x07, 0x02, 0x40, 0x08, + 0x03, 0x18, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, + 0xEC, + 0xF5, 0xF2}; // Mode "Heat", Fan Speed "auto", Temp: 24, Power: on + +// Temperature +const uint8_t kYorkMinTemp = 18; // Celsius +const uint8_t kYorkMaxTemp = 32; // Celsius +// Fan +const uint8_t kYorkFanLow = 1; +const uint8_t kYorkFanMedium = 2; +const uint8_t kYorkFanHigh = 3; +const uint8_t kYorkFanAuto = 8; +// Modes +const uint8_t kYorkHeat = 1; +const uint8_t kYorkCool = 2; +const uint8_t kYorkDry = 3; +const uint8_t kYorkFan = 4; +const uint8_t kYorkAuto = 8; + +// Classes +/// Class for handling detailed York A/C messages. +class IRYorkAc { + public: + explicit IRYorkAc(const uint16_t pin, const bool inverted = false, + const bool use_modulation = true); + void stateReset(); +#if SEND_YORK + void send(const uint16_t repeat = kNoRepeat); + /// Run the calibration to calculate uSec timing offsets for this platform. + /// @return The uSec timing offset needed per modulation of the IR Led. + /// @note This will produce a 65ms IR signal pulse at 38kHz. + /// Only ever needs to be run once per object instantiation, if at all. + int8_t calibrate(void) { return _irsend.calibrate(); } +#endif // SEND_YORK + void begin(); + void setPowerToggle(const bool on); + bool getPowerToggle() const; + void setTemp(const uint8_t temp); + uint8_t getTemp() const; + void setFan(const uint8_t speed); + uint8_t getFan() const; + void setMode(const uint8_t mode); + uint8_t getMode() const; + uint16_t getOnTimer(void) const; + uint16_t getOffTimer(void) const; + void setOnTimer(const uint16_t mins); + void setOffTimer(const uint16_t mins); + uint8_t* getRaw(); + void setRaw(const uint8_t new_code[], + const uint16_t length = kYorkStateLength); + static uint8_t convertMode(const stdAc::opmode_t mode); + static uint8_t convertFan(const stdAc::fanspeed_t speed); + void calcChecksum(); + static stdAc::opmode_t toCommonMode(const uint8_t mode); + static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed); + stdAc::state_t toCommon(const stdAc::state_t *prev = NULL) const; + String toString() const; +#ifndef UNIT_TEST + + private: + IRsend _irsend; ///< Instance of the IR send class +#else + /// @cond IGNORE + IRsendTest _irsend; ///< Instance of the testing IR send class + /// @endcond +#endif + YorkProtocol _; +}; +#endif // IR_YORK_H_ diff --git a/lib/IRremoteESP8266/src/locale/defaults.h b/lib/IRremoteESP8266/src/locale/defaults.h index 40b85c27c3..438cc5da3b 100644 --- a/lib/IRremoteESP8266/src/locale/defaults.h +++ b/lib/IRremoteESP8266/src/locale/defaults.h @@ -310,6 +310,9 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_LOCK #define D_STR_LOCK "Lock" #endif // D_STR_LOCK +#ifndef D_STR_REPORT +#define D_STR_REPORT "Report" +#endif // D_STR_REPORT #ifndef D_STR_AUTO #define D_STR_AUTO "Auto" @@ -378,6 +381,9 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_MEDIUM #define D_STR_MEDIUM "Medium" #endif // D_STR_MEDIUM +#ifndef D_STR_MED_HIGH +#define D_STR_MED_HIGH D_STR_MED "-" D_STR_HIGH +#endif // D_STR_MED_HIGH #ifndef D_STR_HIGHEST #define D_STR_HIGHEST "Highest" @@ -445,6 +451,33 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_BOTTOM #define D_STR_BOTTOM "Bottom" #endif // D_STR_BOTTOM +#ifndef D_STR_UPPER_MIDDLE +#define D_STR_UPPER_MIDDLE D_STR_UPPER "-" D_STR_MIDDLE +#endif // D_STR_UPPER_MIDDLE +#ifndef D_STR_CONFIG +#define D_STR_CONFIG "Config" +#endif // D_STR_CONFIG +#ifndef D_STR_CONTROL +#define D_STR_CONTROL "Control" +#endif // D_STR_CONTROL +#ifndef D_STR_SET_TIMER +#define D_STR_SET_TIMER D_STR_SET " " D_STR_TIMER +#endif // D_STR_AC_TIMER +#ifndef D_STR_SCHEDULE +#define D_STR_SCHEDULE "Schedule" +#endif // D_STR_SCHEDULE +#ifndef D_STR_CH +#define D_STR_CH "CH#" +#endif // D_STR_CH +#ifndef D_STR_TIMER_ACTIVE_DAYS +#define D_STR_TIMER_ACTIVE_DAYS "TimerActiveDays" +#endif // D_STR_TIMER_ACTIVE_DAYS +#ifndef D_STR_KEY +#define D_STR_KEY "Key" +#endif // D_STR_KEY +#ifndef D_STR_VALUE +#define D_STR_VALUE "Value" +#endif // D_STR_VALUE // Compound words/phrases/descriptions from pre-defined words. // Note: Obviously these need to be defined *after* their component words. @@ -472,6 +505,9 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_DISPLAYTEMP #define D_STR_DISPLAYTEMP D_STR_DISPLAY " " D_STR_TEMP #endif // D_STR_DISPLAYTEMP +#ifndef D_STR_IFEELREPORT +#define D_STR_IFEELREPORT D_STR_IFEEL " " D_STR_REPORT +#endif // D_STR_IFEELREPORT #ifndef D_STR_SENSORTEMP #define D_STR_SENSORTEMP D_STR_SENSOR " " D_STR_TEMP #endif // D_STR_SENSORTEMP @@ -689,6 +725,12 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_DG11J191 #define D_STR_DG11J191 "DG11J191" #endif // D_STR_DG11J191 +#ifndef D_STR_ARGO_WREM2 +#define D_STR_ARGO_WREM2 "WREM2" +#endif // D_STR_ARGO_WREM2 +#ifndef D_STR_ARGO_WREM3 +#define D_STR_ARGO_WREM3 "WREM3" +#endif // D_STR_ARGO_WREM3 // Protocols Names #ifndef D_STR_AIRTON @@ -727,6 +769,9 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_CARRIER_AC64 #define D_STR_CARRIER_AC64 D_STR_CARRIER_AC "64" #endif // D_STR_CARRIER_AC64 +#ifndef D_STR_CARRIER_AC84 +#define D_STR_CARRIER_AC84 D_STR_CARRIER_AC "84" +#endif // D_STR_CARRIER_AC84 #ifndef D_STR_CARRIER_AC128 #define D_STR_CARRIER_AC128 D_STR_CARRIER_AC "128" #endif // D_STR_CARRIER_AC128 @@ -808,6 +853,9 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_GOODWEATHER #define D_STR_GOODWEATHER "GOODWEATHER" #endif // D_STR_GOODWEATHER +#ifndef D_STR_GORENJE +#define D_STR_GORENJE "GORENJE" +#endif // D_STR_GORENJE #ifndef D_STR_GREE #define D_STR_GREE "GREE" #endif // D_STR_GREE @@ -1060,9 +1108,15 @@ D_STR_INDIRECT " " D_STR_MODE #ifndef D_STR_WHYNTER #define D_STR_WHYNTER "WHYNTER" #endif // D_STR_WHYNTER +#ifndef D_STR_WOWWEE +#define D_STR_WOWWEE "WOWWEE" +#endif // D_STR_WOWWEE #ifndef D_STR_XMP #define D_STR_XMP "XMP" #endif // D_STR_XMP +#ifndef D_STR_YORK +#define D_STR_YORK "YORK" +#endif // D_STR_YORK #ifndef D_STR_ZEPEAL #define D_STR_ZEPEAL "ZEPEAL" #endif // D_STR_ZEPEAL diff --git a/lib/IRremoteESP8266/src/locale/nl-NL.h b/lib/IRremoteESP8266/src/locale/nl-NL.h new file mode 100644 index 0000000000..3cac00b5e7 --- /dev/null +++ b/lib/IRremoteESP8266/src/locale/nl-NL.h @@ -0,0 +1,136 @@ +// Copyright 2022 - Stijn (@stijnb1234) +// Locale/language file for Dutch / The Netherlands. +// This file will override the default values located in `defaults.h`. +#ifndef LOCALE_NL_NL_H_ +#define LOCALE_NL_NL_H_ + +#define D_STR_UNKNOWN "ONBEKEND" +#define D_STR_POWER "Stroom" +#define D_STR_PREVIOUS "Vorige" +#define D_STR_ON "Aan" +#define D_STR_OFF "Uit" +#define D_STR_MODE "Modus" +#define D_STR_TOGGLE "Omschakelen" +#define D_STR_SLEEP "Slaap" +#define D_STR_LIGHT "Licht" +#define D_STR_POWERFUL "Sterk" +#define D_STR_QUIET "Rustig" +#define D_STR_ECONO "Eco" +#define D_STR_SWING "Zwaai" +#define D_STR_BEEP "Piep" +#define D_STR_MOULD "Schimmel" +#define D_STR_CLEAN "Reinigen" +#define D_STR_PURIFY "Zuiver" +#define D_STR_TIMER "Timer" +#define D_STR_ONTIMER D_STR_TIMER " " D_STR_ON +#define D_STR_OFFTIMER D_STR_TIMER " " D_STR_OFF +#define D_STR_CLOCK "Klok" +#define D_STR_COMMAND "Commando" +#define D_STR_XFAN "XVentilator" +#define D_STR_HEALTH "Gezondheid" +#define D_STR_IFEEL "IkVoel" +#define D_STR_ISEE "IkZie" +#define D_STR_HUMID "Vochtigheid" +#define D_STR_SAVE "Opslaan" +#define D_STR_EYE "Ogen" +#define D_STR_FOLLOW "Volgen" +#define D_STR_FRESH "Fris" +#define D_STR_HOLD "Houd" +#define D_STR_BUTTON "Knop" +#define D_STR_NIGHT "Nacht" +#define D_STR_SILENT "Stil" +#define D_STR_UP "Omhoog" +#define D_STR_TEMPUP D_STR_TEMP " " D_STR_UP +#define D_STR_DOWN "Omlaag" +#define D_STR_TEMPDOWN D_STR_TEMP " " D_STR_DOWN +#define D_STR_CHANGE "Wisselen" +#define D_STR_MOVE "Verplaatsen" +#define D_STR_SET "Instellen" +#define D_STR_CANCEL "Annuleren" +#define D_STR_COMFORT "Comfortabel" +#define D_STR_WEEKLY "Weekelijks" +#define D_STR_WEEKLYTIMER D_STR_TIMER " " D_STR_WEEKLY +#define D_STR_FAST "Snel" +#define D_STR_SLOW "Langzaam" +#define D_STR_AIRFLOW "Luchtstroom" +#define D_STR_STEP "Stap" +#define D_STR_NA "N/A" +#define D_STR_OUTSIDE "Buiten" +#define D_STR_LOUD "Luid" +#define D_STR_UPPER "Boven" +#define D_STR_LOWER "Beneden" +#define D_STR_BREEZE "Wind" +#define D_STR_CIRCULATE "Circulatie" +#define D_STR_CEILING "Plafond" +#define D_STR_WALL "Muur" +#define D_STR_ROOM "Kamer" +#define D_STR_6THSENSE "6e Zintuig" +#define D_STR_FIXED "Vast" + +#define D_STR_AUTOMATIC "Automatisch" +#define D_STR_MANUAL "Handmatig" +#define D_STR_COOL "Koelen" +#define D_STR_HEAT "Verwarmen" +#define D_STR_FAN "Venilator" +#define D_STR_FANONLY "alleen_fan" +#define D_STR_DRY "Drogen" + +#define D_STR_MED "Mid" +#define D_STR_MEDIUM "Medium" + +#define D_STR_HIGHEST "Hoogste" +#define D_STR_HIGH "Hoog" +#define D_STR_HI "H" +#define D_STR_MID "M" +#define D_STR_MIDDLE "Medium" +#define D_STR_LOW "Laag" +#define D_STR_LO "L" +#define D_STR_LOWEST "Laagste" +#define D_STR_RIGHT "Rechts" +#define D_STR_MAXRIGHT D_STR_MAX " " D_STR_RIGHT +#define D_STR_RIGHTMAX_NOSPACE D_STR_RIGHT D_STR_MAX +#define D_STR_LEFT "Links" +#define D_STR_MAXLEFT D_STR_MAX " " D_STR_LEFT +#define D_STR_LEFTMAX_NOSPACE D_STR_LEFT D_STR_MAX +#define D_STR_WIDE "Breed" +#define D_STR_CENTRE "Midden" +#define D_STR_TOP "Boven" +#define D_STR_BOTTOM "Onder" + +#define D_STR_DAY "Dag" +#define D_STR_DAYS D_STR_DAY "en" +#define D_STR_HOUR "Uur" +#define D_STR_HOURS D_STR_HOUR +#define D_STR_MINUTE "Minuut" +#define D_STR_MINUTES "Minuten" +#define D_STR_SECOND "Seconde" +#define D_STR_SECONDS D_STR_SECOND "n" +#define D_STR_NOW "Nu" +#define D_STR_THREELETTERDAYS "ZonMaaDinWoeDonVriZat" + +#define D_STR_YES "Ja" +#define D_STR_NO "Nee" +#define D_STR_TRUE "Waar" +#define D_STR_FALSE "Niet Waar" + +#define D_STR_REPEAT "Herhalen" +#define D_STR_PREVIOUS "Vorige" +#define D_STR_DISPLAY "Display" +#define D_STR_INSIDE "Binnen" +#define D_STR_POWERBUTTON "Hoofdschakelaar" +#define D_STR_PREVIOUSPOWER "Vorige inschakelstatus" +#define D_STR_DISPLAYTEMP "Temperatuurweergave" + +// IRrecvDumpV2+ +#define D_STR_TIMESTAMP "Tijdsaanduiding" +#define D_STR_LIBRARY "Bibliotheek" +#define D_STR_TOLERANCE "Tolerantie" +#define D_STR_MESGDESC "Beschrijving" +#define D_STR_IRRECVDUMP_STARTUP \ + "IRrecvDump draait en wacht op IR-signaal op pin %d" +#define D_WARN_BUFFERFULL \ + "WAARSCHUWING: IR-code is te groot voor buffer (>= %d). " \ + "Het resultaat kan niet worden vertrouwd totdat het is verholpen. " \ + "Wijzig & vergroot `kCaptureBufferSize`." + +#endif // LOCALE_NL_NL_H_ diff --git a/lib/IRremoteESP8266/test/IRac_test.cpp b/lib/IRremoteESP8266/test/IRac_test.cpp index 30d9f7e4fc..8d6274c65d 100644 --- a/lib/IRremoteESP8266/test/IRac_test.cpp +++ b/lib/IRremoteESP8266/test/IRac_test.cpp @@ -73,6 +73,7 @@ TEST(TestIRac, Airton) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Airwell) { @@ -96,6 +97,7 @@ TEST(TestIRac, Airwell) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Amcor) { @@ -119,6 +121,7 @@ TEST(TestIRac, Amcor) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Argo) { @@ -130,16 +133,19 @@ TEST(TestIRac, Argo) { true, // Power stdAc::opmode_t::kHeat, // Mode 21, // Celsius + 22, // Sensor Temp. stdAc::fanspeed_t::kHigh, // Fan speed stdAc::swingv_t::kOff, // Vertical swing + false, // iFeel false, // Turbo -1); // Sleep EXPECT_TRUE(ac.getPower()); EXPECT_EQ(kArgoHeat, ac.getMode()); EXPECT_EQ(21, ac.getTemp()); - EXPECT_EQ(kArgoFlapAuto, ac.getFlap()); + EXPECT_EQ(kArgoFlapFull, ac.getFlap()); EXPECT_FALSE(ac.getMax()); // Turbo EXPECT_FALSE(ac.getNight()); // Sleep + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, ac.getMessageType()); } TEST(TestIRac, Carrier64) { @@ -174,6 +180,7 @@ TEST(TestIRac, Carrier64) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Coolix) { @@ -189,9 +196,11 @@ TEST(TestIRac, Coolix) { true, // Power stdAc::opmode_t::kHeat, // Mode 21, // Celsius + kNoTempValue, // Sensor Temp stdAc::fanspeed_t::kHigh, // Fan speed stdAc::swingv_t::kOff, // Vertical swing stdAc::swingh_t::kOff, // Horizontal swing + false, // iFeel false, // Turbo false, // Light false, // Clean @@ -235,6 +244,7 @@ TEST(TestIRac, Coolix) { // End of message #2 (i.e. Repeat '1') // Note: the two messages (#1 & #2) are identical. ac._irsend.outputStr()); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Corona) { @@ -277,6 +287,7 @@ TEST(TestIRac, Corona) { ASSERT_EQ(expectedCapture, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin) { @@ -310,6 +321,7 @@ TEST(TestIRac, Daikin) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin128) { @@ -343,6 +355,7 @@ TEST(TestIRac, Daikin128) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin152) { @@ -371,6 +384,7 @@ TEST(TestIRac, Daikin152) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin160) { @@ -396,6 +410,7 @@ TEST(TestIRac, Daikin160) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin176) { @@ -421,6 +436,7 @@ TEST(TestIRac, Daikin176) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin2) { @@ -460,6 +476,7 @@ TEST(TestIRac, Daikin2) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin216) { @@ -488,6 +505,7 @@ TEST(TestIRac, Daikin216) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Daikin64) { @@ -548,7 +566,7 @@ TEST(TestIRac, Ecoclim) { IRac irac(kGpioUnused); IRrecv capture(kGpioUnused); char expected[] = - "Power: On, Mode: 1 (Cool), Temp: 26C, SensorTemp: 26C, Fan: 2 (High), " + "Power: On, Mode: 1 (Cool), Temp: 26C, SensorTemp: 27C, Fan: 2 (High), " "Clock: 12:34, On Timer: Off, Off Timer: Off, Type: 0"; ac.begin(); @@ -556,6 +574,7 @@ TEST(TestIRac, Ecoclim) { true, // Power stdAc::opmode_t::kCool, // Mode 26, // Celsius + 27, // Sensor Temp. stdAc::fanspeed_t::kHigh, // Fan speed -1, // Sleep 12 * 60 + 34); // Clock @@ -567,7 +586,7 @@ TEST(TestIRac, Ecoclim) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); char expected_sleep[] = - "Power: On, Mode: 7 (Sleep), Temp: 21C, SensorTemp: 21C, Fan: 0 (Low), " + "Power: On, Mode: 7 (Sleep), Temp: 21C, SensorTemp: 22C, Fan: 0 (Low), " "Clock: 17:17, On Timer: Off, Off Timer: Off, Type: 0"; ac._irsend.reset(); @@ -575,6 +594,7 @@ TEST(TestIRac, Ecoclim) { true, // Power stdAc::opmode_t::kCool, // Mode 21, // Celsius + 22, // Sensor Temp. stdAc::fanspeed_t::kLow, // Fan speed 8 * 60, // Sleep 17 * 60 + 17); // Clock @@ -600,9 +620,11 @@ TEST(TestIRac, Electra) { true, // Power stdAc::opmode_t::kFan, // Mode 26, // Celsius + 27, // Sensor Temp. stdAc::fanspeed_t::kHigh, // Fan speed stdAc::swingv_t::kAuto, // Vertical swing stdAc::swingh_t::kLeft, // Horizontal swing + false, // iFeel true, // Turbo true, // Light (toggle) true); // Clean @@ -647,7 +669,8 @@ TEST(TestIRac, Fujitsu) { false, // Turbo (Powerful) false, // Econo true, // Filter - true); // Clean + true, // Clean + -1); // Sleep ASSERT_EQ(ardb1_expected, ac.toString()); ac._irsend.makeDecodeResult(); EXPECT_TRUE(capture.decode(&ac._irsend.capture)); @@ -656,6 +679,7 @@ TEST(TestIRac, Fujitsu) { ASSERT_EQ(ardb1_expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); // Try to set the device to 10C Heat mode. @@ -681,6 +705,7 @@ TEST(TestIRac, Fujitsu) { ASSERT_EQ(kFujitsuAcBits, ac._irsend.capture.bits); ASSERT_EQ(arrah2e_expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); irac.fujitsu(&ac, fujitsu_ac_remote_model_t::ARRY4, // Model @@ -695,7 +720,8 @@ TEST(TestIRac, Fujitsu) { false, // Turbo (Powerful) false, // Econo true, // Filter - true); // Clean + true, // Clean + -1); // Sleep ASSERT_EQ(arry4_expected, ac.toString()); ac._irsend.makeDecodeResult(); EXPECT_TRUE(capture.decode(&ac._irsend.capture)); @@ -703,6 +729,7 @@ TEST(TestIRac, Fujitsu) { ASSERT_EQ(kFujitsuAcBits, ac._irsend.capture.bits); ASSERT_EQ(arry4_expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); irac.fujitsu(&ac, @@ -717,8 +744,9 @@ TEST(TestIRac, Fujitsu) { false, // Quiet false, // Turbo (Powerful) false, // Econo - false, // Filter - false); // Clean + false, // Filter + false, // Clean + -1); // Sleep ASSERT_EQ(arrew4e_expected, ac.toString()); ac._irsend.makeDecodeResult(); EXPECT_TRUE(capture.decode(&ac._irsend.capture)); @@ -753,6 +781,7 @@ TEST(TestIRac, Goodweather) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Gree) { @@ -761,7 +790,7 @@ TEST(TestIRac, Gree) { IRrecv capture(kGpioUnused); char expected[] = "Model: 1 (YAW1F), Power: On, Mode: 1 (Cool), Temp: 71F, " - "Fan: 2 (Medium), Turbo: Off, Econo: Off, IFeel: Off, WiFi: Off, " + "Fan: 2 (Medium), Turbo: Off, Econo: Off, IFeel: On, WiFi: Off, " "XFan: On, Light: On, Sleep: On, Swing(V) Mode: Manual, " "Swing(V): 3 (UNKNOWN), Swing(H): 5 (Right), Timer: Off, " "Display Temp: 0 (Off)"; @@ -776,6 +805,7 @@ TEST(TestIRac, Gree) { stdAc::fanspeed_t::kMedium, // Fan speed stdAc::swingv_t::kHigh, // Vertical swing stdAc::swingh_t::kRight, // Horizontal swing + true, // iFeel false, // Turbo false, // Econo true, // Light @@ -789,6 +819,7 @@ TEST(TestIRac, Gree) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Haier) { @@ -818,6 +849,43 @@ TEST(TestIRac, Haier) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); +} + +TEST(TestIRac, Haier160) { + IRHaierAC160 ac(kGpioUnused); + IRac irac(kGpioUnused); + IRrecv capture(kGpioUnused); + const char expected[] = + "Power: On, Button: 5 (Power), Mode: 1 (Cool), Temp: 23C, " + "Fan: 2 (Medium), Turbo: On, Quiet: Off, Health: On, " + "Swing(V): 4 (High), Sleep: On, " + "Clean: On, Timer Mode: 0 (N/A), On Timer: Off, Off Timer: Off, " + "Lock: Off, Heating: Off"; + ac.begin(); + irac.haier160(&ac, + true, // Power + stdAc::opmode_t::kCool, // Mode + true, // Celsius + 23, // Degrees + stdAc::fanspeed_t::kMedium, // Fan speed + stdAc::swingv_t::kHigh, // Vertical swing + true, // Turbo + false, // Quiet + true, // Filter/Health + true, // Clean + true, // Light + true, // Light (prev) + 8 * 60 + 0); // Sleep time + ASSERT_EQ(expected, ac.toString()); + ac._irsend.makeDecodeResult(); + EXPECT_TRUE(capture.decode(&ac._irsend.capture)); + ASSERT_EQ(HAIER_AC160, ac._irsend.capture.decode_type); + ASSERT_EQ(kHaierAC160Bits, ac._irsend.capture.bits); + ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); + stdAc::state_t r, p; + ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Haier176) { @@ -851,6 +919,7 @@ TEST(TestIRac, Haier176) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, HaierYrwo2) { @@ -884,6 +953,7 @@ TEST(TestIRac, HaierYrwo2) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Hitachi) { @@ -911,6 +981,7 @@ TEST(TestIRac, Hitachi) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Hitachi1) { @@ -943,6 +1014,7 @@ TEST(TestIRac, Hitachi1) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Hitachi264) { @@ -968,6 +1040,7 @@ TEST(TestIRac, Hitachi264) { ASSERT_EQ(expected_swingon, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); EXPECT_EQ(decode_type_t::HITACHI_AC264, r.protocol); EXPECT_TRUE(r.power); EXPECT_EQ(stdAc::opmode_t::kHeat, r.mode); @@ -996,6 +1069,7 @@ TEST(TestIRac, Hitachi296) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); EXPECT_EQ(decode_type_t::HITACHI_AC296, r.protocol); EXPECT_TRUE(r.power); EXPECT_EQ(stdAc::opmode_t::kHeat, r.mode); @@ -1027,6 +1101,7 @@ TEST(TestIRac, Hitachi344) { ASSERT_EQ(expected_swingon, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); EXPECT_EQ(decode_type_t::HITACHI_AC344, r.protocol); EXPECT_TRUE(r.power); EXPECT_EQ(stdAc::opmode_t::kHeat, r.mode); @@ -1047,6 +1122,7 @@ TEST(TestIRac, Hitachi344) { ASSERT_EQ(expected_swingoff, ac.toString()); ac._irsend.makeDecodeResult(); EXPECT_TRUE(capture.decode(&ac._irsend.capture)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ASSERT_EQ(HITACHI_AC344, ac._irsend.capture.decode_type); ASSERT_EQ(kHitachiAc344Bits, ac._irsend.capture.bits); ASSERT_EQ(expected_swingoff, @@ -1080,6 +1156,7 @@ TEST(TestIRac, Hitachi424) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); irac.hitachi424(&ac, @@ -1096,6 +1173,7 @@ TEST(TestIRac, Hitachi424) { ASSERT_EQ(kHitachiAc424Bits, ac._irsend.capture.bits); ASSERT_EQ(expected_swingv, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Kelvinator) { @@ -1129,6 +1207,7 @@ TEST(TestIRac, Kelvinator) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, LG) { @@ -1161,6 +1240,7 @@ TEST(TestIRac, LG) { ASSERT_EQ(61, ac._irsend.capture.rawlen); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, LG2) { @@ -1193,6 +1273,7 @@ TEST(TestIRac, LG2) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); // Message #2 - SwingV Low EXPECT_TRUE(capture.decodeLG(&ac._irsend.capture, 61)); ASSERT_EQ(LG2, ac._irsend.capture.decode_type); @@ -1408,6 +1489,7 @@ TEST(TestIRac, LG2_AKB73757604) { ASSERT_EQ(LG2, ac._irsend.capture.decode_type); ASSERT_EQ(kLgBits, ac._irsend.capture.bits); ASSERT_EQ(kLgAcSwingHAuto, ac._irsend.capture.value); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Midea) { @@ -1426,8 +1508,10 @@ TEST(TestIRac, Midea) { stdAc::opmode_t::kDry, // Mode true, // Celsius 27, // Degrees + 28, // Sensor Temp. stdAc::fanspeed_t::kMedium, // Fan speed stdAc::swingv_t::kOff, // Swing(V) + false, // iFeel false, // Silent/Quiet false, // Previous Silent/Quiet setting false, // Turbo @@ -1444,6 +1528,7 @@ TEST(TestIRac, Midea) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Mirage) { @@ -1483,6 +1568,7 @@ TEST(TestIRac, Mirage) { ASSERT_EQ(kMirageBits, ac._irsend.capture.bits); ASSERT_EQ(expected_KKG9AC1, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); const char expected_KKG29AC1[] = "Model: 2 (KKG29AC1), Power: On, Mode: 3 (Dry), Temp: 27C, " @@ -1500,6 +1586,7 @@ TEST(TestIRac, Mirage) { ASSERT_EQ(expected_KKG29AC1, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Mitsubishi) { @@ -1532,6 +1619,7 @@ TEST(TestIRac, Mitsubishi) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Mitsubishi136) { @@ -1558,6 +1646,7 @@ TEST(TestIRac, Mitsubishi136) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, MitsubishiHeavy88) { @@ -1588,6 +1677,7 @@ TEST(TestIRac, MitsubishiHeavy88) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, MitsubishiHeavy152) { @@ -1621,6 +1711,7 @@ TEST(TestIRac, MitsubishiHeavy152) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Neoclima) { @@ -1655,6 +1746,7 @@ TEST(TestIRac, Neoclima) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Panasonic) { @@ -1687,6 +1779,7 @@ TEST(TestIRac, Panasonic) { ASSERT_EQ(expected_nke, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); char expected_dke[] = "Model: 3 (DKE), Power: On, Mode: 3 (Cool), Temp: 18C, Fan: 4 (Maximum), " @@ -1713,6 +1806,7 @@ TEST(TestIRac, Panasonic) { ASSERT_EQ(kPanasonicAcBits, ac._irsend.capture.bits); ASSERT_EQ(expected_dke, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Panasonic32) { @@ -1739,6 +1833,7 @@ TEST(TestIRac, Panasonic32) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Samsung) { @@ -1778,6 +1873,7 @@ TEST(TestIRac, Samsung) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); irac.samsung(&ac, @@ -1806,6 +1902,7 @@ TEST(TestIRac, Samsung) { ASSERT_EQ(kSamsungAcExtendedBits, ac._irsend.capture.bits); ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); const char sleep[] = @@ -1839,6 +1936,7 @@ TEST(TestIRac, Samsung) { ASSERT_EQ(kSamsungAcExtendedBits, ac._irsend.capture.bits); ASSERT_EQ(sleep, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Sanyo) { @@ -1855,8 +1953,10 @@ TEST(TestIRac, Sanyo) { true, // Power stdAc::opmode_t::kCool, // Mode 28, // Celsius + kNoTempValue, // SensorTemp stdAc::fanspeed_t::kMedium, // Fan speed stdAc::swingv_t::kHighest, // Vertical Swing + false, // iFeel true, // Beep 17); // Sleep ASSERT_EQ(expected, ac.toString()); @@ -1867,6 +1967,7 @@ TEST(TestIRac, Sanyo) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Sanyo88) { @@ -1896,6 +1997,7 @@ TEST(TestIRac, Sanyo88) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Sharp) { @@ -1928,6 +2030,7 @@ TEST(TestIRac, Sharp) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Tcl112) { @@ -1962,6 +2065,7 @@ TEST(TestIRac, Tcl112) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); // Test the quiet mode, which should generate two messages. ac._irsend.reset(); irac.tcl112(&ac, @@ -2017,6 +2121,7 @@ TEST(TestIRac, Technibel) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Teco) { @@ -2044,6 +2149,7 @@ TEST(TestIRac, Teco) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Toshiba) { @@ -2073,6 +2179,7 @@ TEST(TestIRac, Toshiba) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); EXPECT_EQ( "f38000d50" "m4400s4300" @@ -2148,6 +2255,7 @@ TEST(TestIRac, Transcold) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Trotec) { @@ -2177,6 +2285,7 @@ TEST(TestIRac, Trotec) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Trotec3550) { @@ -2207,6 +2316,7 @@ TEST(TestIRac, Trotec3550) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Truma) { @@ -2236,6 +2346,7 @@ TEST(TestIRac, Truma) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, Vestel) { @@ -2265,6 +2376,7 @@ TEST(TestIRac, Vestel) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); char expected_clocks[] = @@ -2290,6 +2402,7 @@ TEST(TestIRac, Vestel) { ASSERT_EQ(kVestelAcBits, ac._irsend.capture.bits); ASSERT_EQ(expected_clocks, IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); // Now check it sends both messages during normal operation when the // clock is set. @@ -2369,6 +2482,7 @@ TEST(TestIRac, Voltas) { ASSERT_EQ(expected_unknown, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); ac._irsend.reset(); // Test the UNKNOWN model type @@ -2435,6 +2549,7 @@ TEST(TestIRac, Whirlpool) { ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } TEST(TestIRac, cmpStates) { @@ -2472,6 +2587,21 @@ TEST(TestIRac, cmpStates) { // Now make them different. b.power = false; ASSERT_TRUE(IRac::cmpStates(a, b)); + + b = a; + ASSERT_FALSE(IRac::cmpStates(a, b)); + b.command = stdAc::ac_command_t::kTimerCommand; + ASSERT_TRUE(IRac::cmpStates(a, b)); + + b = a; + ASSERT_FALSE(IRac::cmpStates(a, b)); + b.iFeel = true; + ASSERT_TRUE(IRac::cmpStates(a, b)); + + b = a; + ASSERT_FALSE(IRac::cmpStates(a, b)); + b.sensorTemperature = 12.5; + ASSERT_TRUE(IRac::cmpStates(a, b)); } TEST(TestIRac, handleToggles) { @@ -2575,6 +2705,7 @@ TEST(TestIRac, strToFanspeed) { EXPECT_EQ(stdAc::fanspeed_t::kMin, IRac::strToFanspeed("MIN")); EXPECT_EQ(stdAc::fanspeed_t::kLow, IRac::strToFanspeed("LOW")); EXPECT_EQ(stdAc::fanspeed_t::kMedium, IRac::strToFanspeed("MEDIUM")); + EXPECT_EQ(stdAc::fanspeed_t::kMediumHigh, IRac::strToFanspeed("MED-HIGH")); EXPECT_EQ(stdAc::fanspeed_t::kHigh, IRac::strToFanspeed("HIGH")); EXPECT_EQ(stdAc::fanspeed_t::kMax, IRac::strToFanspeed("MAX")); EXPECT_EQ(stdAc::fanspeed_t::kAuto, IRac::strToFanspeed("FOOBAR")); @@ -2587,6 +2718,7 @@ TEST(TestIRac, strToSwingV) { EXPECT_EQ(stdAc::swingv_t::kLowest, IRac::strToSwingV("LOWEST")); EXPECT_EQ(stdAc::swingv_t::kLow, IRac::strToSwingV("LOW")); EXPECT_EQ(stdAc::swingv_t::kMiddle, IRac::strToSwingV("MIDDLE")); + EXPECT_EQ(stdAc::swingv_t::kUpperMiddle, IRac::strToSwingV("UPPER-MIDDLE")); EXPECT_EQ(stdAc::swingv_t::kHigh, IRac::strToSwingV("HIGH")); EXPECT_EQ(stdAc::swingv_t::kHighest, IRac::strToSwingV("HIGHEST")); EXPECT_EQ(stdAc::swingv_t::kOff, IRac::strToSwingV("OFF")); @@ -2617,6 +2749,10 @@ TEST(TestIRac, strToModel) { IRac::strToModel("ARRAH2E")); EXPECT_EQ(whirlpool_ac_remote_model_t::DG11J13A, IRac::strToModel("DG11J13A")); + EXPECT_EQ(argo_ac_remote_model_t::SAC_WREM2, + IRac::strToModel("WREM2")); + EXPECT_EQ(argo_ac_remote_model_t::SAC_WREM3, + IRac::strToModel("WREM3")); EXPECT_EQ(1, IRac::strToModel("1")); EXPECT_EQ(10, IRac::strToModel("10")); EXPECT_EQ(-1, IRac::strToModel("0")); @@ -2624,6 +2760,26 @@ TEST(TestIRac, strToModel) { EXPECT_EQ(0, IRac::strToModel("FOOBAR", 0)); } +TEST(TestIRac, strToCommandType) { + EXPECT_EQ(stdAc::ac_command_t::kControlCommand, + IRac::strToCommandType("Control")); + EXPECT_EQ(stdAc::ac_command_t::kSensorTempReport, + IRac::strToCommandType("IFeel Report")); + EXPECT_EQ(stdAc::ac_command_t::kSensorTempReport, + IRac::strToCommandType("IFeel")); + EXPECT_EQ(stdAc::ac_command_t::kTimerCommand, + IRac::strToCommandType("Set Timer")); + EXPECT_EQ(stdAc::ac_command_t::kTimerCommand, + IRac::strToCommandType("Timer")); + EXPECT_EQ(stdAc::ac_command_t::kConfigCommand, + IRac::strToCommandType("Config")); + EXPECT_EQ(stdAc::ac_command_t::kControlCommand, + IRac::strToCommandType("FOOBAR")); + EXPECT_EQ(stdAc::ac_command_t::kTimerCommand, + IRac::strToCommandType("FOOBAR", + stdAc::ac_command_t::kTimerCommand)); +} + TEST(TestIRac, boolToString) { EXPECT_EQ("On", IRac::boolToString(true)); EXPECT_EQ("Off", IRac::boolToString(false)); @@ -2643,6 +2799,7 @@ TEST(TestIRac, opmodeToString) { TEST(TestIRac, fanspeedToString) { EXPECT_EQ("Low", IRac::fanspeedToString(stdAc::fanspeed_t::kLow)); EXPECT_EQ("Auto", IRac::fanspeedToString(stdAc::fanspeed_t::kAuto)); + EXPECT_EQ("Med-High", IRac::fanspeedToString(stdAc::fanspeed_t::kMediumHigh)); EXPECT_EQ("UNKNOWN", IRac::fanspeedToString((stdAc::fanspeed_t)500)); } @@ -2650,6 +2807,8 @@ TEST(TestIRac, swingvToString) { EXPECT_EQ("Off", IRac::swingvToString(stdAc::swingv_t::kOff)); EXPECT_EQ("Low", IRac::swingvToString(stdAc::swingv_t::kLow)); EXPECT_EQ("Auto", IRac::swingvToString(stdAc::swingv_t::kAuto)); + EXPECT_EQ("Upper-Middle", IRac::swingvToString( + stdAc::swingv_t::kUpperMiddle)); EXPECT_EQ("UNKNOWN", IRac::swingvToString((stdAc::swingv_t)500)); } @@ -2661,6 +2820,17 @@ TEST(TestIRac, swinghToString) { EXPECT_EQ("UNKNOWN", IRac::swinghToString((stdAc::swingh_t)500)); } +TEST(TestIRac, commandTypeToString) { + EXPECT_EQ("Control", + IRac::commandTypeToString(stdAc::ac_command_t::kControlCommand)); + EXPECT_EQ("IFeel Report", + IRac::commandTypeToString(stdAc::ac_command_t::kSensorTempReport)); + EXPECT_EQ("Set Timer", + IRac::commandTypeToString(stdAc::ac_command_t::kTimerCommand)); + EXPECT_EQ("Config", + IRac::commandTypeToString(stdAc::ac_command_t::kConfigCommand)); +} + // Check that we keep the previous state info if the message is a special // state-less command. TEST(TestIRac, CoolixDecodeToState) { @@ -2679,6 +2849,7 @@ TEST(TestIRac, CoolixDecodeToState) { ASSERT_TRUE(irrecv.decode(&irsend.capture)); stdAc::state_t result; ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, result.command); ASSERT_EQ(decode_type_t::COOLIX, result.protocol); ASSERT_FALSE(result.power); ASSERT_EQ(stdAc::opmode_t::kHeat, result.mode); @@ -2727,9 +2898,11 @@ TEST(TestIRac, Issue821) { result.power, // Power result.mode, // Mode result.degrees, // Celsius + kNoTempValue, // Sensor Temp result.fanspeed, // Fan speed result.swingv, // Vertical swing result.swingh, // Horizontal swing + result.iFeel, // iFeel result.turbo, // Turbo result.light, // Light result.clean, // Clean @@ -2842,6 +3015,7 @@ TEST(TestIRac, Issue1001) { IRAcUtils::resultAcToString(&ac._irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); // Now check if the mode is set to "Off" instead of just change to power off. // i.e. How Home Assistant expects things to work. @@ -2872,6 +3046,7 @@ TEST(TestIRac, Issue1001) { "Command: 1 (Power)", IRAcUtils::resultAcToString(&ac._irsend.capture)); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, r.command); } // Check power switching in Daikin2 common a/c handling when from an IR message. @@ -2921,6 +3096,7 @@ TEST(TestIRac, Issue1035) { ASSERT_FALSE(prev.power); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &result, &prev)); ASSERT_TRUE(result.power); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, result.command); prev = result; @@ -2932,6 +3108,7 @@ TEST(TestIRac, Issue1035) { ASSERT_EQ(DAIKIN2, ac._irsend.capture.decode_type); ASSERT_TRUE(prev.power); ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &result, &prev)); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, result.command); ASSERT_FALSE(result.power); } @@ -3103,4 +3280,26 @@ TEST(TestIRac, initState) { EXPECT_EQ(-1, builtin_init.model); EXPECT_EQ(stdAc::swingv_t::kOff, builtin_init.swingv); EXPECT_EQ(decode_type_t::UNKNOWN, no_init.protocol); + EXPECT_EQ(stdAc::ac_command_t::kControlCommand, no_init.command); + EXPECT_FALSE(no_init.iFeel); + EXPECT_EQ(kNoTempValue, no_init.sensorTemperature); +} + +TEST(TestIRac, cleanState) { + IRac irac(kGpioUnused); + stdAc::state_t s = {}; + s.mode = stdAc::opmode_t::kFan; + s.power = true; + s.sensorTemperature = 20.5; + s.degrees = 22.3; + + auto clean = irac.cleanState(s); + EXPECT_TRUE(clean.power); + EXPECT_EQ(s.mode, clean.mode); + EXPECT_EQ(s.sensorTemperature, clean.sensorTemperature); + EXPECT_EQ(s.degrees, clean.degrees); + + s.mode = stdAc::opmode_t::kOff; + clean = irac.cleanState(s); + EXPECT_FALSE(clean.power); } diff --git a/lib/IRremoteESP8266/test/IRrecv_test.cpp b/lib/IRremoteESP8266/test/IRrecv_test.cpp index 2d32847d38..25a8e4e0a4 100644 --- a/lib/IRremoteESP8266/test/IRrecv_test.cpp +++ b/lib/IRremoteESP8266/test/IRrecv_test.cpp @@ -48,7 +48,7 @@ TEST(TestIRrecv, DecodeHeapOverflow) { IRrecv irrecv(1); irrecv.enableIRIn(); ASSERT_EQ(kRawBuf, irrecv.getBufSize()); - volatile irparams_t *params_ptr = irrecv._getParamsPtr(); + atomic_irparams_t *params_ptr = irrecv._getParamsPtr(); // replace the buffer with a slightly bigger one to see if we go past the end // accidentally. params_ptr->rawbuf = new uint16_t[kRawBuf + 10]; diff --git a/lib/IRremoteESP8266/test/IRrecv_test.h b/lib/IRremoteESP8266/test/IRrecv_test.h index bb366c1ee0..42c3f0a17d 100644 --- a/lib/IRremoteESP8266/test/IRrecv_test.h +++ b/lib/IRremoteESP8266/test/IRrecv_test.h @@ -3,15 +3,16 @@ #ifndef TEST_IRRECV_TEST_H_ #define TEST_IRRECV_TEST_H_ +#include #include #include #include #include "IRutils.h" -#define EXPECT_STATE_EQ(a, b, c) \ - for (uint8_t i = 0; i < c / 8; ++i) { \ - EXPECT_EQ(a[i], b[i]) << "Expected state " \ - "differs at i = " \ - << uint64ToString(i); \ +#define EXPECT_STATE_EQ(a, b, c) \ + for (uint8_t i = 0; i < ceil((c) / 8.0); ++i) { \ + EXPECT_EQ((a)[i], (b)[i]) << "Expected state " \ + "differs at i = " \ + << uint64ToString(i); \ } #endif // TEST_IRRECV_TEST_H_ diff --git a/lib/IRremoteESP8266/test/Makefile b/lib/IRremoteESP8266/test/Makefile index 7a193e813a..8c0a33da44 100644 --- a/lib/IRremoteESP8266/test/Makefile +++ b/lib/IRremoteESP8266/test/Makefile @@ -16,6 +16,7 @@ # Points to the root of Google Test, relative to where this file is. # Remember to tweak this if you move this file. GTEST_DIR = ../lib/googletest/googletest +GMOCK_DIR = ../lib/googletest/googlemock # Where to find user code. USER_DIR = ../src @@ -24,11 +25,14 @@ INCLUDES = -I$(USER_DIR) -I. # Flags passed to the preprocessor. # Set Google Test's header directory as a system directory, such that # the compiler doesn't generate warnings in Google Test headers. -CPPFLAGS += -isystem $(GTEST_DIR)/include -DUNIT_TEST -D_IR_LOCALE_=en-AU +CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include -DUNIT_TEST -D_IR_LOCALE_=en-AU # Flags passed to the C++ compiler. CXXFLAGS += -g -Wall -Wextra -Werror -pthread -std=gnu++11 +# Google Test libraries +GTEST_LIBS = gtest.a gtest_main.a gmock.a gmock_main.a + # All tests produced by this Makefile. generated from all *_test.cpp files TESTS = $(patsubst %.cpp,%,$(wildcard *_test.cpp)) @@ -37,12 +41,19 @@ TESTS = $(patsubst %.cpp,%,$(wildcard *_test.cpp)) GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ $(GTEST_DIR)/include/gtest/internal/*.h +# All Google Mock headers. Note that all Google Test headers are +# included here too, as they are #included by Google Mock headers. +# Usually you shouldn't change this definition. +GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \ + $(GMOCK_DIR)/include/gmock/internal/*.h \ + $(GTEST_HEADERS) + # House-keeping build targets. -all : $(TESTS) +all : $(GTEST_LIBS) $(TESTS) clean : - rm -f $(TESTS) gtest.a gtest_main.a *.o + rm -f $(GTEST_LIBS) $(TESTS) *.o # Build and run all the tests. run : all @@ -65,13 +76,14 @@ run-% : %_test install-googletest : rm -rf ../lib/googletest - git clone -b v1.8.x https://github.com/google/googletest.git ../lib/googletest + git clone -b v1.12.x https://github.com/google/googletest.git ../lib/googletest -# Builds gtest.a and gtest_main.a. +# Builds gtest.a, gtest_main.a, gmock.a, gmock_main.a. # Usually you shouldn't tweak such internal variables, indicated by a # trailing _. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) +GMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS) # All the IR protocol object files. PROTOCOL_OBJS = $(patsubst %.cpp,%.o,$(wildcard $(USER_DIR)/ir_*.cpp)) @@ -82,7 +94,7 @@ PROTOCOLS_H = $(wildcard $(USER_DIR)/ir_*.h) # Common object files COMMON_OBJ = IRutils.o IRtimer.o IRsend.o IRrecv.o IRac.o ir_GlobalCache.o \ - IRtext.o $(PROTOCOLS) gtest_main.a + IRtext.o $(PROTOCOLS) gtest_main.a gmock_main.a # Common dependencies COMMON_DEPS = $(USER_DIR)/IRrecv.h $(USER_DIR)/IRsend.h $(USER_DIR)/IRtimer.h \ $(USER_DIR)/IRutils.h $(USER_DIR)/IRremoteESP8266.h \ @@ -90,26 +102,41 @@ COMMON_DEPS = $(USER_DIR)/IRrecv.h $(USER_DIR)/IRsend.h $(USER_DIR)/IRtimer.h \ $(PROTOCOLS_H) # Common test dependencies -COMMON_TEST_DEPS = $(COMMON_DEPS) IRrecv_test.h IRsend_test.h +COMMON_TEST_DEPS = $(COMMON_DEPS) IRrecv_test.h IRsend_test.h ut_utils.h -# For simplicity and to avoid depending on Google Test's -# implementation details, the dependencies specified below are -# conservative and not optimized. This is fine as Google Test -# compiles fast and for ordinary users its source rarely changes. +# For simplicity and to avoid depending on implementation details of +# Google Mock and Google Test, the dependencies specified below are +# conservative and not optimized. This is fine as Google Mock and +# Google Test compile fast and for ordinary users their source rarely +# changes. gtest-all.o : $(GTEST_SRCS_) - $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) -c \ $(GTEST_DIR)/src/gtest-all.cc gtest_main.o : $(GTEST_SRCS_) - $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) -c \ $(GTEST_DIR)/src/gtest_main.cc +gmock-all.o : $(GMOCK_SRCS_) + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ + -c $(GMOCK_DIR)/src/gmock-all.cc + +gmock_main.o : $(GMOCK_SRCS_) + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ + -c $(GMOCK_DIR)/src/gmock_main.cc + gtest.a : gtest-all.o $(AR) $(ARFLAGS) $@ $^ gtest_main.a : gtest-all.o gtest_main.o $(AR) $(ARFLAGS) $@ $^ +gmock.a : gmock-all.o + $(AR) $(ARFLAGS) $@ $^ + +gmock_main.a : gmock_main.o + $(AR) $(ARFLAGS) $@ $^ + # Keep all intermediate files. .SECONDARY: @@ -123,10 +150,10 @@ IRtext.o : $(USER_DIR)/IRtext.cpp $(USER_DIR)/IRtext.h $(USER_DIR)/IRremoteESP82 IRutils.o : $(USER_DIR)/IRutils.cpp $(USER_DIR)/IRutils.h $(USER_DIR)/IRremoteESP8266.h $(USER_DIR)/i18n.h $(USER_DIR)/IRtext.cpp $(USER_DIR)/IRtext.h $(USER_DIR)/locale/*.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/IRutils.cpp -IRutils_test.o : IRutils_test.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS) +IRutils_test.o : IRutils_test.cpp $(COMMON_TEST_DEPS) $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c IRutils_test.cpp -IRutils_test : IRutils_test.o ir_NEC.o ir_Nikai.o ir_Toshiba.o IRtext.o $(COMMON_OBJ) gtest_main.a +IRutils_test : IRutils_test.o ir_NEC.o ir_Nikai.o ir_Toshiba.o IRtext.o $(COMMON_OBJ) $(GTEST_LIBS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ IRtimer.o : $(USER_DIR)/IRtimer.cpp $(USER_DIR)/IRtimer.h @@ -135,19 +162,19 @@ IRtimer.o : $(USER_DIR)/IRtimer.cpp $(USER_DIR)/IRtimer.h IRsend.o : $(USER_DIR)/IRsend.cpp $(USER_DIR)/IRsend.h $(USER_DIR)/IRremoteESP8266.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/IRsend.cpp -IRsend_test.o : IRsend_test.cpp $(USER_DIR)/IRsend.h $(USER_DIR)/IRrecv.h IRsend_test.h $(GTEST_HEADERS) +IRsend_test.o : IRsend_test.cpp $(USER_DIR)/IRsend.h $(USER_DIR)/IRrecv.h IRsend_test.h $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c IRsend_test.cpp -IRrecv.o : $(USER_DIR)/IRrecv.cpp $(USER_DIR)/IRrecv.h $(USER_DIR)/IRremoteESP8266.h $(GTEST_HEADERS) +IRrecv.o : $(USER_DIR)/IRrecv.cpp $(USER_DIR)/IRrecv.h $(USER_DIR)/IRremoteESP8266.h $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/IRrecv.cpp -IRrecv_test.o : IRrecv_test.cpp $(USER_DIR)/IRsend.h $(USER_DIR)/IRrecv.h IRsend_test.h $(GTEST_HEADERS) +IRrecv_test.o : IRrecv_test.cpp $(USER_DIR)/IRsend.h $(USER_DIR)/IRrecv.h IRsend_test.h $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c IRrecv_test.cpp -IRac.o : $(USER_DIR)/IRac.cpp $(USER_DIR)/IRac.h $(COMMON_DEPS) $(GTEST_HEADERS) +IRac.o : $(USER_DIR)/IRac.cpp $(USER_DIR)/IRac.h $(COMMON_DEPS) $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/IRac.cpp -IRac_test.o : IRac_test.cpp $(USER_DIR)/IRac.h $(COMMON_DEPS) $(GTEST_HEADERS) +IRac_test.o : IRac_test.cpp $(USER_DIR)/IRac.h $(COMMON_DEPS) $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c IRac_test.cpp # new specific targets goes above this line @@ -158,11 +185,11 @@ ir_%.o : $(USER_DIR)/ir_%.h $(USER_DIR)/ir_%.cpp $(COMMON_DEPS) ir_%.o : $(USER_DIR)/ir_%.cpp $(COMMON_DEPS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(USER_DIR)/ir_$*.cpp -ir_%_test.o : ir_%_test.cpp $(USER_DIR)/ir_$%.h $(COMMON_TEST_DEPS) $(GTEST_HEADERS) +ir_%_test.o : ir_%_test.cpp $(USER_DIR)/ir_$%.h $(COMMON_TEST_DEPS) $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c ir_$*_test.cpp -ir_%_test.o : ir_%_test.cpp $(COMMON_TEST_DEPS) $(GTEST_HEADERS) +ir_%_test.o : ir_%_test.cpp $(COMMON_TEST_DEPS) $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c ir_$*_test.cpp -%_test : $(COMMON_OBJ) %_test.o +%_test : $(COMMON_OBJ) %_test.o $(GTEST_LIBS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ diff --git a/lib/IRremoteESP8266/test/ir_Argo_test.cpp b/lib/IRremoteESP8266/test/ir_Argo_test.cpp index 3ab890adca..817272a17e 100644 --- a/lib/IRremoteESP8266/test/ir_Argo_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Argo_test.cpp @@ -1,15 +1,22 @@ // Copyright 2019 David Conran +// Copyright 2022 Mateusz Bronk (mbronk) +#include +#include +#include #include "ir_Argo.h" #include "IRac.h" #include "IRrecv.h" #include "IRrecv_test.h" #include "IRsend.h" #include "IRsend_test.h" -#include "gtest/gtest.h" +#include "./ut_utils.h" +/******************************************************************************/ +/* Tests for toCommon() */ +/******************************************************************************/ TEST(TestArgoACClass, toCommon) { - IRArgoAC ac(0); + IRArgoAC ac(kGpioUnused); ac.setPower(true); ac.setMode(kArgoCool); ac.setTemp(20); @@ -18,6 +25,7 @@ TEST(TestArgoACClass, toCommon) { ac.setNight(true); // Now test it. ASSERT_EQ(decode_type_t::ARGO, ac.toCommon().protocol); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, ac.toCommon().command); ASSERT_TRUE(ac.toCommon().power); ASSERT_TRUE(ac.toCommon().celsius); ASSERT_EQ(20, ac.toCommon().degrees); @@ -25,8 +33,8 @@ TEST(TestArgoACClass, toCommon) { ASSERT_EQ(stdAc::fanspeed_t::kMax, ac.toCommon().fanspeed); ASSERT_EQ(0, ac.toCommon().sleep); ASSERT_TRUE(ac.toCommon().turbo); + ASSERT_EQ(argo_ac_remote_model_t::SAC_WREM2, ac.toCommon().model); // Unsupported. - ASSERT_EQ(-1, ac.toCommon().model); ASSERT_EQ(stdAc::swingv_t::kOff, ac.toCommon().swingv); ASSERT_EQ(stdAc::swingh_t::kOff, ac.toCommon().swingh); ASSERT_FALSE(ac.toCommon().econo); @@ -36,30 +44,229 @@ TEST(TestArgoACClass, toCommon) { ASSERT_FALSE(ac.toCommon().beep); ASSERT_FALSE(ac.toCommon().quiet); ASSERT_EQ(-1, ac.toCommon().clock); + ASSERT_FALSE(ac.toCommon().iFeel); + ASSERT_EQ(25, ac.toCommon().sensorTemperature); } +TEST(TestArgoAC_WREM3Class, toCommon) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setPower(true); + ac.setMode(argoMode_t::COOL); + ac.setTemp(21); + ac.setFan(argoFan_t::FAN_HIGHEST); + ac.setMax(true); + ac.setNight(true); + ac.setFlap(argoFlap_t::FLAP_4); + ac.setEco(true); + ac.setFilter(true); + ac.setLight(true); + ac.setiFeel(true); + // Now test it. + ASSERT_EQ(decode_type_t::ARGO, ac.toCommon().protocol); + ASSERT_EQ(argo_ac_remote_model_t::SAC_WREM3, ac.toCommon().model); + ASSERT_EQ(stdAc::ac_command_t::kControlCommand, ac.toCommon().command); + ASSERT_TRUE(ac.toCommon().celsius); + ASSERT_TRUE(ac.toCommon().beep); // Always on (except for iFeel) + ASSERT_FALSE(ac.toCommon().clean); + ASSERT_EQ(-1, ac.toCommon().clock); + ASSERT_EQ(0, ac.toCommon().sleep); + ASSERT_EQ(stdAc::swingh_t::kOff, ac.toCommon().swingh); + ASSERT_TRUE(ac.toCommon().power); + ASSERT_EQ(stdAc::opmode_t::kCool, ac.toCommon().mode); + ASSERT_EQ(21, ac.toCommon().degrees); + ASSERT_EQ(stdAc::fanspeed_t::kMax, ac.toCommon().fanspeed); + ASSERT_TRUE(ac.toCommon().turbo); + ASSERT_TRUE(ac.toCommon().quiet); // Night + ASSERT_EQ(stdAc::swingv_t::kUpperMiddle, ac.toCommon().swingv); + ASSERT_TRUE(ac.toCommon().econo); + ASSERT_TRUE(ac.toCommon().light); + ASSERT_TRUE(ac.toCommon().filter); + ASSERT_TRUE(ac.toCommon().iFeel); + ASSERT_EQ(25, ac.toCommon().sensorTemperature); +} + +/******************************************************************************/ +/* Tests of message construction */ +/******************************************************************************/ + TEST(TestArgoACClass, MessageConstructon) { - IRArgoAC ac(0); + IRArgoAC ac(kGpioUnused); ac.setPower(true); ac.setTemp(20); ac.setMode(kArgoCool); ac.setFan(kArgoFanAuto); - ac.setRoomTemp(21); + ac.setSensorTemp(21); ac.setiFeel(true); ac.setMax(true); ac.setNight(true); // Don't implicitly trust this. It's just a guess. - uint8_t expected[kArgoStateLength] = { - 0xAC, 0xF5, 0x00, 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xD6, 0x01}; - EXPECT_STATE_EQ(expected, ac.getRaw(), kArgoBits); + auto expected = std::vector({ + 0xAC, 0xF5, 0x00, 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0xAC, 0xD6, 0x01}); + auto actual = ac.getRaw(); + EXPECT_THAT(std::vector(actual, actual + kArgoBits / 8), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Model: 1 (WREM2), Power: On, Mode: 0 (Cool), Fan: 0 (Auto), Temp: 20C, " + "Sensor Temp: 21C, Max: On, IFeel: On, Night: On", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_ACControl) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setChannel(0); + ac.setPower(true); + ac.setMode(argoMode_t::COOL); + ac.setTemp(22); + ac.setSensorTemp(26); + ac.setFan(argoFan_t::FAN_AUTO); + ac.setFlap(argoFlap_t::FLAP_FULL); + ac.setiFeel(false); + ac.setNight(false); + ac.setEco(false); + ac.setMax(false); + ac.setFilter(false); + ac.setLight(true); + auto expected = std::vector({ + 0x0B, 0x36, 0x12, 0x0F, 0xC2, 0x24}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3AcControlStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Command[CH#0]: Model: 2 (WREM3), Power: On, Mode: 1 (Cool), Temp: 22C, " + "Sensor Temp: 26C, Fan: 0 (Auto), Swing(V): 7 (Breeze), IFeel: Off, " + "Night: Off, Econo: Off, Max: Off, Filter: Off, Light: On", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_ACControl_2) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setChannel(2); + ac.setPower(true); + ac.setMode(argoMode_t::AUTO); + ac.setTemp(23); + ac.setSensorTemp(28); + ac.setFan(argoFan_t::FAN_MEDIUM); + ac.setMax(true); + ac.setNight(true); + ac.setFlap(argoFlap_t::FLAP_4); + ac.setEco(true); + ac.setFilter(true); + ac.setLight(true); + ac.setiFeel(true); + auto expected = std::vector({ + 0x2B, 0xB8, 0x93, 0xFC, 0xC3, 0x35}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3AcControlStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); EXPECT_EQ( - "Power: On, Mode: 0 (Cool), Fan: 0 (Auto), Temp: 20C, Room Temp: 21C, " - "Max: On, IFeel: On, Night: On", + "Command[CH#2]: Model: 2 (WREM3), Power: On, Mode: 5 (Auto), Temp: 23C, " + "Sensor Temp: 28C, Fan: 4 (Med-High), Swing(V): 4 (Middle), IFeel: On, " + "Night: On, Econo: On, Max: On, Filter: On, Light: On", ac.toString()); } -// Tests for sendArgo(). +TEST(TestArgoAC_WREM3Class, MessageConstructon_iFeelReport) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + ac.setSensorTemp(31); + + auto expected = std::vector({0x4B, 0xDB}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3iFeelReportStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 31C", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_Config) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setMessageType(argoIrMessageType_t::CONFIG_PARAM_SET); + ac.setConfigEntry(6, 30); + + auto expected = std::vector({0xCB, 0x06, 0x1E, 0xEF}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3ConfigStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Config[CH#0]: Model: 2 (WREM3), Key: 6, Value: 30", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_NoTimer) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setMessageType(argoIrMessageType_t::TIMER_COMMAND); + ac.off(); + ac.setCurrentTimeMinutes(1*60+59); + ac.setCurrentDayOfWeek(argoWeekday::MONDAY); + ac.setTimerType(argoTimerType_t::NO_TIMER); + + auto expected = std::vector({0x8B, 0x70, 0x87, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x34}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3TimerStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Timer[CH#0]: Model: 2 (WREM3), Power: Off, Timer Mode: 0 (Off), " + "Clock: 01:59, Day: 1 (Mon), Timer: Off", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_DelayTimer) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setMessageType(argoIrMessageType_t::TIMER_COMMAND); + ac.off(); + ac.setCurrentTimeMinutes(12*60+00); + ac.setCurrentDayOfWeek(argoWeekday::SATURDAY); + ac.setTimerType(argoTimerType_t::DELAY_TIMER); + ac.setDelayTimerMinutes(9*60+40); + + auto expected = std::vector({0x8B, 0x02, 0x2D, 0x13, 0x09, 0x00, + 0x00, 0x00, 0xD4}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3TimerStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Timer[CH#0]: Model: 2 (WREM3), Power: Off, Timer Mode: 1 (Sleep Timer)," + " Clock: 12:00, Day: 6 (Sat), Timer: 09:40", + ac.toString()); +} + +TEST(TestArgoAC_WREM3Class, MessageConstructon_ScheduleTimer) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setMessageType(argoIrMessageType_t::TIMER_COMMAND); + ac.on(); + ac.setCurrentTimeMinutes(18*60+16); + ac.setCurrentDayOfWeek(argoWeekday::SATURDAY); + ac.setTimerType(argoTimerType_t::SCHEDULE_TIMER_3); + ac.setScheduleTimerStartMinutes(8*60+40); + ac.setScheduleTimerStopMinutes(19*60+50); + ac.setScheduleTimerActiveDays({argoWeekday::MONDAY, argoWeekday::SATURDAY, + argoWeekday::SUNDAY}); + + auto expected = std::vector({0x8B, 0x89, 0x44, 0x03, 0x00, 0x41, + 0xA6, 0x1C, 0x26}); + auto actual = ac.getRaw(); + ASSERT_EQ(ac.getRawByteLength(), kArgo3TimerStateLength); + EXPECT_THAT(std::vector(actual, actual + ac.getRawByteLength()), + ::testing::ElementsAreArray(expected)); + EXPECT_EQ( + "Timer[CH#0]: Model: 2 (WREM3), Power: On, Timer Mode: 4 (Schedule3)," + " Clock: 18:16, Day: 6 (Sat), On Timer: 08:40, Off Timer: 19:50, " + "TimerActiveDays: Sun|Mon|Sat", + ac.toString()); +} + +/******************************************************************************/ +/* Tests for sendArgo(). */ +/******************************************************************************/ // Test sending typical data only. TEST(TestSendArgo, SendDataOnly) { @@ -88,12 +295,39 @@ TEST(TestSendArgo, SendDataOnly) { irsend.outputStr()); } -// Tests for decodeArgo(). -// Decode normal Argo messages. +TEST(TestSendArgoWrem3, SendDataOnly) { + IRsendTest irsend(0); + irsend.begin(); + uint8_t data[kArgoStateLength] = { + 0x0B, 0x31, 0x35, 0xFE, 0xC0, 0x2F}; + irsend.sendArgoWREM3(data); + EXPECT_EQ( + "f38000d50" + "m6400s3300" + "m400s2200m400s2200m400s900m400s2200m400s900m400s900m400s900m400s900" + "m400s2200m400s900m400s900m400s900m400s2200m400s2200m400s900m400s900" + "m400s2200m400s900m400s2200m400s900m400s2200m400s2200m400s900m400s900" + "m400s900m400s2200m400s2200m400s2200m400s2200m400s2200m400s2200m400s2200" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s2200m400s2200" + "m400s2200m400s2200m400s2200m400s2200m400s900m400s2200m400s900m400s900" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900" + "m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900m400s900" + "m400s900m400s900m400s900m400s100000", + irsend.outputStr()); +} + +/******************************************************************************/ +/* Tests for decodeArgo(). */ +/******************************************************************************/ + +// Decode normal Argo messages. TEST(TestDecodeArgo, SyntheticDecode) { - IRsendTest irsend(0); - IRrecv irrecv(0); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); // Synthesised Normal Argo message. @@ -107,16 +341,235 @@ TEST(TestDecodeArgo, SyntheticDecode) { EXPECT_EQ(kArgoBits, irsend.capture.bits); EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); EXPECT_EQ( - "Power: On, Mode: 0 (Cool), Fan: 0 (Auto), Temp: 20C, Room Temp: 21C, " - "Max: On, IFeel: On, Night: On", + "Model: 1 (WREM2), Power: On, Mode: 0 (Cool), Fan: 0 (Auto), Temp: 20C, " + "Sensor Temp: 21C, Max: On, IFeel: On, Night: On", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); } +// Synthetic send and decode ***via common*** interface +TEST(TestIrAc, ArgoWrem2_SyntheticSendAndDecode_ACCommand) { + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = 1; + state.power = true; + state.mode = stdAc::opmode_t::kCool; + + irac.sendAc(state, nullptr); + ASSERT_NE(nullptr, irac._lastDecodeResults); + EXPECT_EQ(ARGO, irac._lastDecodeResults->decode_type); + EXPECT_EQ("Model: 1 (WREM2), Power: On, Mode: 0 (Cool), Fan: 0 (Auto), " + "Temp: 25C, Sensor Temp: 25C, Max: Off, IFeel: Off, Night: Off", + IRAcUtils::resultAcToString(irac._lastDecodeResults.get())); + + stdAc::state_t r = {}; + ASSERT_TRUE(IRAcUtils::decodeToState(irac._lastDecodeResults.get(), &r, + nullptr)); + EXPECT_EQ(ARGO, r.protocol); + EXPECT_EQ(1, r.model); + EXPECT_TRUE(r.power); + EXPECT_EQ(state.mode, r.mode); +} + +TEST(TestIrAc, ArgoWrem3_SyntheticSendAndDecode_ACCommand) { + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = argo_ac_remote_model_t::SAC_WREM3; + state.power = true; + state.mode = stdAc::opmode_t::kCool; + + irac.sendAc(state, nullptr); + ASSERT_NE(nullptr, irac._lastDecodeResults); + EXPECT_EQ(ARGO, irac._lastDecodeResults->decode_type); + EXPECT_EQ("Command[CH#0]: Model: 2 (WREM3), Power: On, Mode: 1 (Cool)," + " Temp: 25C, Sensor Temp: 25C, Fan: 0 (Auto), Swing(V): 7 (Breeze)," + " IFeel: Off, Night: Off, Econo: Off, Max: Off, Filter: Off, " + "Light: Off", + IRAcUtils::resultAcToString(irac._lastDecodeResults.get())); + + stdAc::state_t r = {}; + ASSERT_TRUE(IRAcUtils::decodeToState(irac._lastDecodeResults.get(), &r, + nullptr)); + EXPECT_EQ(ARGO, r.protocol); + EXPECT_EQ(state.model, r.model); + EXPECT_EQ(state.power, r.power); +} + +TEST(TestIrAc, ArgoWrem3_SyntheticSendAndDecode_iFeelReport) { + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = argo_ac_remote_model_t::SAC_WREM3; + state.command = stdAc::ac_command_t::kSensorTempReport; + state.sensorTemperature = 18.9; // expected to be rounded up + + irac.sendAc(state, nullptr); + + ASSERT_NE(nullptr, irac._lastDecodeResults); + EXPECT_EQ(ARGO, irac._lastDecodeResults->decode_type); + EXPECT_EQ("IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 19C", + IRAcUtils::resultAcToString(irac._lastDecodeResults.get())); + + stdAc::state_t r = {}; + ASSERT_TRUE(IRAcUtils::decodeToState(irac._lastDecodeResults.get(), &r, + nullptr)); + EXPECT_EQ(ARGO, r.protocol); + EXPECT_EQ(state.model, r.model); + EXPECT_EQ(state.command, r.command); + EXPECT_EQ(19, r.sensorTemperature); +} + +TEST(TestIrAc, ArgoWrem3_SyntheticSendAndDecode_Timer) { + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = argo_ac_remote_model_t::SAC_WREM3; + state.command = stdAc::ac_command_t::kTimerCommand; + state.power = true; + state.mode = stdAc::opmode_t::kAuto; // Needs to be set for `state.power` + // not to be ignored! + state.clock = 13*60+21; + state.sleep = 2*60+10; + + irac.sendAc(state, nullptr); + + ASSERT_NE(nullptr, irac._lastDecodeResults); + EXPECT_EQ(ARGO, irac._lastDecodeResults->decode_type); + EXPECT_EQ("Timer[CH#0]: Model: 2 (WREM3), Power: On, Timer Mode: 1 " + "(Sleep Timer), Clock: 13:21, Day: 0 (Sun), Timer: 02:10", + IRAcUtils::resultAcToString(irac._lastDecodeResults.get())); + + stdAc::state_t r = {}; + ASSERT_TRUE(IRAcUtils::decodeToState(irac._lastDecodeResults.get(), &r, + nullptr)); + EXPECT_EQ(ARGO, r.protocol); + EXPECT_EQ(state.model, r.model); + EXPECT_EQ(state.command, r.command); + EXPECT_EQ(state.power, r.power); + EXPECT_EQ(state.clock, r.clock); + EXPECT_EQ(state.sleep, r.sleep); +} + +/// +/// @brief Test fixture for Config messages sent via @c IRAc generic i-face +/// @note The commands are abusing generic intafrace and instead are +/// using: @c clock -> for settingID +/// @c sleep -> for setting Value +/// +class TestArgoConfigViaIRAc : + public ::testing::TestWithParam> { +}; + +class TestArgoConfigViaIRAc_Positive : public TestArgoConfigViaIRAc {}; +TEST_P(TestArgoConfigViaIRAc_Positive, + ArgoWrem3_SyntheticSendAndDecode_Config_Positive) { + int16_t settingId = std::get<0>(GetParam()); + int16_t settingValue = std::get<1>(GetParam()); + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = argo_ac_remote_model_t::SAC_WREM3; + state.command = stdAc::ac_command_t::kConfigCommand; + state.clock = settingId; + state.sleep = settingValue; + + irac.sendAc(state, nullptr); + + ASSERT_NE(nullptr, irac._lastDecodeResults); + EXPECT_EQ(ARGO, irac._lastDecodeResults->decode_type); + std::ostringstream ossExpectedStr; + ossExpectedStr << "Config[CH#0]: Model: 2 (WREM3), Key: " << settingId + << ", Value: " << settingValue; + EXPECT_EQ(ossExpectedStr.str(), + IRAcUtils::resultAcToString(irac._lastDecodeResults.get())); + + stdAc::state_t r = {}; + ASSERT_TRUE(IRAcUtils::decodeToState(irac._lastDecodeResults.get(), &r, + nullptr)); + EXPECT_EQ(ARGO, r.protocol); + EXPECT_EQ(state.model, r.model); + EXPECT_EQ(state.command, r.command); +} + +INSTANTIATE_TEST_CASE_P( + TestIrAc, + TestArgoConfigViaIRAc_Positive, + ::testing::Values( + std::make_tuple(5, 0), + std::make_tuple(5, 1), + std::make_tuple(6, 0), + std::make_tuple(6, 1), + std::make_tuple(6, 2), + std::make_tuple(6, 3), + std::make_tuple(12, 30), + std::make_tuple(12, 75), + std::make_tuple(12, 99) +)); + +class TestArgoConfigViaIRAc_Negative : public TestArgoConfigViaIRAc {}; +TEST_P(TestArgoConfigViaIRAc_Negative, + ArgoWrem3_SyntheticSendAndDecode_Config_Negative) { + int16_t settingId = std::get<0>(GetParam()); + int16_t settingValue = std::get<1>(GetParam()); + IRac irac(kGpioUnused); + auto capture = std::make_shared(kGpioUnused); + irac._utReceiver = capture; + + stdAc::state_t state = {}; + state.protocol = ARGO; + state.model = argo_ac_remote_model_t::SAC_WREM3; + state.command = stdAc::ac_command_t::kConfigCommand; + state.clock = settingId; + state.sleep = settingValue; + + irac.sendAc(state, nullptr); + + // The "safe" mode should have prevented the message from sending out + ASSERT_EQ(nullptr, irac._lastDecodeResults); // nothing got sent +} + +INSTANTIATE_TEST_CASE_P( + TestIrAc, + TestArgoConfigViaIRAc_Negative, + ::testing::Values( + std::make_tuple(5, 2), + std::make_tuple(6, 4), + std::make_tuple(12, 29), + std::make_tuple(12, 100), + std::make_tuple(0, 0), + std::make_tuple(80, 86) +)); + -TEST(TestArgoACClass, SetAndGetTemp) { - IRArgoAC ac(0); +/******************************************************************************/ +/* Tests for IRArgoACBase (comon functionality across WREM2 and WREM3) */ +/******************************************************************************/ + +using IRArgoACBase_typelist = ::testing::Types; +template struct TestArgoACBaseClass : public testing::Test {}; +TYPED_TEST_CASE(TestArgoACBaseClass, IRArgoACBase_typelist); + + +TYPED_TEST(TestArgoACBaseClass, SetAndGetTemp) { + IRArgoACBase ac(kGpioUnused); ac.setTemp(25); EXPECT_EQ(25, ac.getTemp()); @@ -130,59 +583,107 @@ TEST(TestArgoACClass, SetAndGetTemp) { EXPECT_EQ(kArgoMaxTemp, ac.getTemp()); } -TEST(TestArgoACClass, SetAndGetRoomTemp) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, SetAndGetSensorTemp) { + IRArgoACBase ac(kGpioUnused); - ac.setRoomTemp(25); - EXPECT_EQ(25, ac.getRoomTemp()); - ac.setRoomTemp(kArgoTempDelta); - EXPECT_EQ(kArgoTempDelta, ac.getRoomTemp()); - ac.setRoomTemp(kArgoMaxRoomTemp); - EXPECT_EQ(kArgoMaxRoomTemp, ac.getRoomTemp()); - ac.setRoomTemp(kArgoTempDelta - 1); - EXPECT_EQ(kArgoTempDelta, ac.getRoomTemp()); - ac.setRoomTemp(kArgoMaxRoomTemp + 1); - EXPECT_EQ(kArgoMaxRoomTemp, ac.getRoomTemp()); + // Room Temp from AC command + ac.setSensorTemp(25); + EXPECT_EQ(25, ac.getSensorTemp()); + ac.setSensorTemp(kArgoTempDelta); + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); + ac.setSensorTemp(kArgoMaxRoomTemp); + EXPECT_EQ(kArgoMaxRoomTemp, ac.getSensorTemp()); + ac.setSensorTemp(kArgoTempDelta - 1); + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); + ac.setSensorTemp(kArgoMaxRoomTemp + 1); + EXPECT_EQ(kArgoMaxRoomTemp, ac.getSensorTemp()); + + // Room temp from iFeel coommand + ac.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); // reset + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); + ac.setSensorTemp(19); + EXPECT_EQ(19, ac.getSensorTemp()); + ac.setSensorTemp(kArgoTempDelta); + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); + ac.setSensorTemp(kArgoMaxRoomTemp); + EXPECT_EQ(kArgoMaxRoomTemp, ac.getSensorTemp()); + ac.setSensorTemp(kArgoTempDelta - 1); + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); + ac.setSensorTemp(kArgoMaxRoomTemp + 1); + EXPECT_EQ(kArgoMaxRoomTemp, ac.getSensorTemp()); } -TEST(TestArgoACClass, SetAndGetMode) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, SetAndGetModeEx) { + IRArgoACBase ac(kGpioUnused); - ac.setMode(kArgoHeat); - EXPECT_EQ(kArgoHeat, ac.getMode()); - ac.setMode(kArgoCool); - EXPECT_EQ(kArgoCool, ac.getMode()); - ac.setMode(kArgoDry); - EXPECT_EQ(kArgoDry, ac.getMode()); - ac.setMode(kArgoAuto); - EXPECT_EQ(kArgoAuto, ac.getMode()); - ac.setMode(kArgoHeatAuto); - EXPECT_EQ(kArgoHeatAuto, ac.getMode()); - ac.setMode(kArgoOff); - EXPECT_EQ(kArgoOff, ac.getMode()); - ac.setMode(255); - EXPECT_EQ(kArgoAuto, ac.getMode()); + ac.setMode(argoMode_t::HEAT); + EXPECT_EQ(argoMode_t::HEAT, ac.getModeEx()); + ac.setMode(argoMode_t::AUTO); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); + ac.setMode(argoMode_t::COOL); + EXPECT_EQ(argoMode_t::COOL, ac.getModeEx()); + ac.setMode(argoMode_t::DRY); + EXPECT_EQ(argoMode_t::DRY, ac.getModeEx()); + ac.setMode(argoMode_t::FAN); + EXPECT_EQ(argoMode_t::FAN, ac.getModeEx()); + ac.setMode(static_cast(255)); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); } -TEST(TestArgoACClass, SetAndGetFan) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, SetAndGetFanEx) { + IRArgoACBase ac(kGpioUnused); - ac.setFan(kArgoFan3); - EXPECT_EQ(kArgoFan3, ac.getFan()); - ac.setFan(kArgoFan1); - EXPECT_EQ(kArgoFan1, ac.getFan()); - ac.setFan(kArgoFanAuto); - EXPECT_EQ(kArgoFanAuto, ac.getFan()); - ac.setFan(kArgoFan3); - EXPECT_EQ(kArgoFan3, ac.getFan()); - ASSERT_NE(7, kArgoFan3); - // Now try some unexpected value. - ac.setFan(7); - EXPECT_EQ(kArgoFan3, ac.getFan()); + ac.setFan(argoFan_t::FAN_AUTO); + EXPECT_EQ(argoFan_t::FAN_AUTO, ac.getFanEx()); + ac.setFan(argoFan_t::FAN_HIGHEST); + EXPECT_EQ(argoFan_t::FAN_HIGHEST, ac.getFanEx()); + if (std::is_same()) { + // Only supported on WREM3 + ac.setFan(argoFan_t::FAN_HIGH); + EXPECT_EQ(argoFan_t::FAN_HIGH, ac.getFanEx()); + } + ac.setFan(argoFan_t::FAN_MEDIUM); + EXPECT_EQ(argoFan_t::FAN_MEDIUM, ac.getFanEx()); + if (std::is_same()) { + // Only supported on WREM3 + ac.setFan(argoFan_t::FAN_LOW); + EXPECT_EQ(argoFan_t::FAN_LOW, ac.getFanEx()); + ac.setFan(argoFan_t::FAN_LOWER); + EXPECT_EQ(argoFan_t::FAN_LOWER, ac.getFanEx()); + } + ac.setFan(argoFan_t::FAN_LOWEST); + EXPECT_EQ(argoFan_t::FAN_LOWEST, ac.getFanEx()); + ac.setFan(static_cast(255)); + EXPECT_EQ(argoFan_t::FAN_AUTO, ac.getFanEx()); +} + +TYPED_TEST(TestArgoACBaseClass, SetAndGetFlapEx) { + IRArgoACBase ac(kGpioUnused); + + ac.setFlap(argoFlap_t::FLAP_FULL); + EXPECT_EQ(argoFlap_t::FLAP_FULL, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_AUTO); + EXPECT_EQ(argoFlap_t::FLAP_AUTO, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_6); + EXPECT_EQ(argoFlap_t::FLAP_6, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_5); + EXPECT_EQ(argoFlap_t::FLAP_5, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_4); + EXPECT_EQ(argoFlap_t::FLAP_4, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_3); + EXPECT_EQ(argoFlap_t::FLAP_3, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_2); + EXPECT_EQ(argoFlap_t::FLAP_2, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_1); + EXPECT_EQ(argoFlap_t::FLAP_1, ac.getFlapEx()); + ac.setFlap(argoFlap_t::FLAP_FULL); + ac.setFlap(static_cast(255)); + EXPECT_EQ(argoFlap_t::FLAP_AUTO, ac.getFlapEx()); } -TEST(TestArgoACClass, Night) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, Night) { + IRArgoACBase ac(kGpioUnused); + ac.setNight(false); ASSERT_FALSE(ac.getNight()); ac.setNight(true); @@ -191,8 +692,9 @@ TEST(TestArgoACClass, Night) { ASSERT_FALSE(ac.getNight()); } -TEST(TestArgoACClass, iFeel) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, iFeel) { + IRArgoACBase ac(kGpioUnused); + ac.setiFeel(false); ASSERT_FALSE(ac.getiFeel()); ac.setiFeel(true); @@ -201,8 +703,9 @@ TEST(TestArgoACClass, iFeel) { ASSERT_FALSE(ac.getiFeel()); } -TEST(TestArgoACClass, Power) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, Power) { + IRArgoACBase ac(kGpioUnused); + ac.setPower(false); ASSERT_FALSE(ac.getPower()); ac.setPower(true); @@ -211,8 +714,18 @@ TEST(TestArgoACClass, Power) { ASSERT_FALSE(ac.getPower()); } -TEST(TestArgoACClass, Max) { - IRArgoAC ac(0); +TYPED_TEST(TestArgoACBaseClass, OnOff) { + IRArgoACBase ac(kGpioUnused); + + ASSERT_FALSE(ac.getPower()); + ac.on(); + ASSERT_TRUE(ac.getPower()); + ac.off(); + ASSERT_FALSE(ac.getPower()); +} + +TYPED_TEST(TestArgoACBaseClass, Max) { + IRArgoACBase ac(kGpioUnused); ac.setMax(false); ASSERT_FALSE(ac.getMax()); ac.setMax(true); @@ -221,8 +734,875 @@ TEST(TestArgoACClass, Max) { ASSERT_FALSE(ac.getMax()); } +TYPED_TEST(TestArgoACBaseClass, SetAndGetMessageType) { + IRArgoACBase ac(kGpioUnused); + + ac.setMessageType(argoIrMessageType_t::AC_CONTROL); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, ac.getMessageType()); + ac.setMessageType(argoIrMessageType_t::CONFIG_PARAM_SET); + EXPECT_EQ(argoIrMessageType_t::CONFIG_PARAM_SET, ac.getMessageType()); + ac.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, ac.getMessageType()); + ac.setMessageType(argoIrMessageType_t::TIMER_COMMAND); + EXPECT_EQ(argoIrMessageType_t::TIMER_COMMAND, ac.getMessageType()); +} + +TYPED_TEST(TestArgoACBaseClass, SetMessageTypeResetsState) { + IRArgoACBase ac(kGpioUnused); + + ac.on(); + ac.setTemp(30); + ac.setSensorTemp(33); + ac.setMode(argoMode_t::COOL); + ac.setFan(argoFan_t::FAN_HIGHEST); + + ac.setMessageType(argoIrMessageType_t::AC_CONTROL); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, ac.getMessageType()); + EXPECT_FALSE(ac.getPower()); + EXPECT_EQ(20, ac.getTemp()); + EXPECT_EQ(25, ac.getSensorTemp()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); + EXPECT_EQ(argoFan_t::FAN_AUTO, ac.getFanEx()); + + ac.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, ac.getMessageType()); + EXPECT_EQ(kArgoTempDelta, ac.getSensorTemp()); +} + +TYPED_TEST(TestArgoACBaseClass, staticGetMessageType) { + IRArgoACBase ac(kGpioUnused); + + ac.setMessageType(argoIrMessageType_t::AC_CONTROL); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, + IRArgoACBase::getMessageType(ac.getRaw(), + ac.getRawByteLength())); + + ac.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, + IRArgoACBase::getMessageType(ac.getRaw(), + ac.getRawByteLength())); + + if (std::is_same()) { + // Only supported for WREM3 + ac.setMessageType(argoIrMessageType_t::CONFIG_PARAM_SET); + EXPECT_EQ(argoIrMessageType_t::CONFIG_PARAM_SET, + IRArgoACBase::getMessageType(ac.getRaw(), + ac.getRawByteLength())); + + ac.setMessageType(argoIrMessageType_t::TIMER_COMMAND); + EXPECT_EQ(argoIrMessageType_t::TIMER_COMMAND, + IRArgoACBase::getMessageType(ac.getRaw(), + ac.getRawByteLength())); + } +} + +TYPED_TEST(TestArgoACBaseClass, staticgetStateLengthForIrMsgType) { + if (std::is_same()) { + EXPECT_EQ(kArgoStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::AC_CONTROL)); + EXPECT_EQ(kArgoStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::TIMER_COMMAND)); + EXPECT_EQ(0, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::CONFIG_PARAM_SET)); + EXPECT_EQ(kArgoShortStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::IFEEL_TEMP_REPORT)); + } else { + EXPECT_EQ(kArgo3AcControlStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::AC_CONTROL)); + EXPECT_EQ(kArgo3TimerStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::TIMER_COMMAND)); + EXPECT_EQ(kArgo3ConfigStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::CONFIG_PARAM_SET)); + EXPECT_EQ(kArgo3iFeelReportStateLength, + IRArgoACBase::getStateLengthForIrMsgType( + argoIrMessageType_t::IFEEL_TEMP_REPORT)); + } +} + +TYPED_TEST(TestArgoACBaseClass, setRaw) { + TypeParam rawStateAC = {}; + rawStateAC.RoomTemp = 30; + + TypeParam rawStateIFeel = {}; + rawStateIFeel.SensorT = 25; + + IRArgoACBase ac(kGpioUnused); + + if (std::is_same()) { + ac.setRaw(reinterpret_cast(&rawStateAC), std::min( + static_cast(kArgoStateLength), sizeof(TypeParam))); + EXPECT_EQ(30 + kArgoTempDelta, ac.getSensorTemp()); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, ac.getMessageType()); + + ac.setRaw(reinterpret_cast(&rawStateIFeel), std::min( + static_cast(kArgoShortStateLength), sizeof(TypeParam))); + EXPECT_EQ(25 + kArgoTempDelta, ac.getSensorTemp()); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, ac.getMessageType()); + } else { + ac.setRaw(reinterpret_cast(&rawStateAC), std::min( + static_cast(kArgo3AcControlStateLength), sizeof(TypeParam))); + EXPECT_EQ(30 + kArgoTempDelta, ac.getSensorTemp()); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, ac.getMessageType()); + + auto raw = reinterpret_cast(&rawStateIFeel); + raw[0] = 0x4B; // sets Byte0::IrCommandType to IFeel (0b01) + ac.setRaw(raw, std::min(static_cast(kArgo3iFeelReportStateLength), + sizeof(TypeParam))); + EXPECT_EQ(25 + kArgoTempDelta, ac.getSensorTemp()); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, ac.getMessageType()); + } +} + +/******************************************************************************/ +/* Backward-compatibility tests of legacy IRArgoAc raw methods vs. base class */ +/******************************************************************************/ + +/// @brief Tests interactions of raw setFan() method +/// with a base-class getFanEx() +TEST(TestArgoACClass, SetAndGetFanEx) { + IRArgoAC ac(kGpioUnused); + + ac.setFan(kArgoFan3); + EXPECT_EQ(kArgoFan3, ac.getFan()); + EXPECT_EQ(argoFan_t::FAN_HIGHEST, ac.getFanEx()); + ac.setFan(kArgoFan1); + EXPECT_EQ(kArgoFan1, ac.getFan()); + EXPECT_EQ(argoFan_t::FAN_LOWEST, ac.getFanEx()); + ac.setFan(kArgoFanAuto); + EXPECT_EQ(kArgoFanAuto, ac.getFan()); + EXPECT_EQ(argoFan_t::FAN_AUTO, ac.getFanEx()); + ac.setFan(kArgoFan2); + EXPECT_EQ(kArgoFan2, ac.getFan()); + EXPECT_EQ(argoFan_t::FAN_MEDIUM, ac.getFanEx()); + + ASSERT_NE(7, kArgoFan3); + // Now try some unexpected value. + ac.setFan(7); + EXPECT_EQ(kArgoFan3, ac.getFan()); +} + +/// @brief Tests interactions of base-class setFan() method +/// with a raw getFan() +TEST(TestArgoACClass, SetFanExAndGetFan) { + IRArgoAC ac(kGpioUnused); + + ac.setFan(argoFan_t::FAN_AUTO); + EXPECT_EQ(kArgoFanAuto, ac.getFan()); + + ac.setFan(argoFan_t::FAN_HIGHEST); + EXPECT_EQ(kArgoFan3, ac.getFan()); + ac.setFan(argoFan_t::FAN_HIGH); + EXPECT_EQ(kArgoFan3, ac.getFan()); + + ac.setFan(argoFan_t::FAN_MEDIUM); + EXPECT_EQ(kArgoFan2, ac.getFan()); + ac.setFan(argoFan_t::FAN_LOW); + EXPECT_EQ(kArgoFan2, ac.getFan()); + + ac.setFan(argoFan_t::FAN_LOWER); + EXPECT_EQ(kArgoFan1, ac.getFan()); + ac.setFan(argoFan_t::FAN_LOWEST); + EXPECT_EQ(kArgoFan1, ac.getFan()); + + ac.setFan(static_cast(255)); + EXPECT_EQ(kArgoFanAuto, ac.getFan()); +} + +TEST(TestArgoACClass, SetFlapGetFlap) { + IRArgoAC ac(kGpioUnused); + + ac.setFlap(kArgoFlapFull); + EXPECT_EQ(kArgoFlapFull, ac.getFlap()); + ac.setFlap(kArgoFlapAuto); + EXPECT_EQ(kArgoFlapAuto, ac.getFlap()); + ac.setFlap(kArgoFlap1); + EXPECT_EQ(kArgoFlap1, ac.getFlap()); + ac.setFlap(kArgoFlap2); + EXPECT_EQ(kArgoFlap2, ac.getFlap()); + ac.setFlap(kArgoFlap3); + EXPECT_EQ(kArgoFlap3, ac.getFlap()); + ac.setFlap(kArgoFlap4); + EXPECT_EQ(kArgoFlap4, ac.getFlap()); + ac.setFlap(kArgoFlap5); + EXPECT_EQ(kArgoFlap5, ac.getFlap()); + ac.setFlap(kArgoFlap6); + EXPECT_EQ(kArgoFlap6, ac.getFlap()); +} + +/// @brief Tests interactions of raw setMode() method +/// with a base-class getModeEx() +TEST(TestArgoACClass, SetModeAndGetModeEx) { + IRArgoAC ac(kGpioUnused); + + ac.setMode(kArgoHeat); + EXPECT_EQ(kArgoHeat, ac.getMode()); + EXPECT_EQ(argoMode_t::HEAT, ac.getModeEx()); + ac.setMode(kArgoCool); + EXPECT_EQ(kArgoCool, ac.getMode()); + EXPECT_EQ(argoMode_t::COOL, ac.getModeEx()); + ac.setMode(kArgoDry); + EXPECT_EQ(kArgoDry, ac.getMode()); + EXPECT_EQ(argoMode_t::DRY, ac.getModeEx()); + ac.setMode(kArgoAuto); + EXPECT_EQ(kArgoAuto, ac.getMode()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); + ac.setMode(kArgoHeatAuto); + EXPECT_EQ(kArgoHeatAuto, ac.getMode()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); + ac.setMode(kArgoOff); + EXPECT_EQ(kArgoOff, ac.getMode()); + EXPECT_EQ(argoMode_t::FAN, ac.getModeEx()); + ac.setMode(255); + EXPECT_EQ(kArgoAuto, ac.getMode()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); +} + +/// @brief Tests interactions of base-class setMode() method +/// with a raw getMode() +TEST(TestArgoACClass, SetModeExAndGetMode) { + IRArgoAC ac(kGpioUnused); + + ac.setMode(argoMode_t::HEAT); + EXPECT_EQ(kArgoHeat, ac.getMode()); + EXPECT_EQ(argoMode_t::HEAT, ac.getModeEx()); + ac.setMode(argoMode_t::AUTO); + EXPECT_EQ(kArgoAuto, ac.getMode()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); + ac.setMode(argoMode_t::COOL); + EXPECT_EQ(kArgoCool, ac.getMode()); + EXPECT_EQ(argoMode_t::COOL, ac.getModeEx()); + ac.setMode(argoMode_t::DRY); + EXPECT_EQ(kArgoDry, ac.getMode()); + EXPECT_EQ(argoMode_t::DRY, ac.getModeEx()); + ac.setMode(argoMode_t::FAN); + EXPECT_EQ(kArgoOff, ac.getMode()); // Fan is N/A (?) -> defaults to off + EXPECT_EQ(argoMode_t::FAN, ac.getModeEx()); + ac.setMode(static_cast(kArgoHeatBlink)); + EXPECT_EQ(kArgoHeatBlink, ac.getMode()); + EXPECT_EQ(static_cast(kArgoHeatBlink), ac.getModeEx()); + ac.setMode(static_cast(255)); + EXPECT_EQ(kArgoAuto, ac.getMode()); + EXPECT_EQ(argoMode_t::AUTO, ac.getModeEx()); +} + +TEST(TestArgoACClass, SendSensorTemp) { + IRrecv irrecv(kGpioUnused); + + // Method 1 (via sendSensorTemp()) + IRArgoAC ac(kGpioUnused); + ac.sendSensorTemp(10); + ac._irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&ac._irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, ac._irsend.capture.decode_type); + EXPECT_EQ("Model: 1 (WREM2), Sensor Temp: 10C", + IRAcUtils::resultAcToString(&ac._irsend.capture)); + + // Method 2 (via send()) + IRArgoAC ac2(kGpioUnused); + ac2.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + ac2.setSensorTemp(19); + ac2.send(); + ac2._irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&ac2._irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, ac2._irsend.capture.decode_type); + EXPECT_EQ("Model: 1 (WREM2), Sensor Temp: 19C", + IRAcUtils::resultAcToString(&ac2._irsend.capture)); +} + +/******************************************************************************/ +/* IRArgoAC_WREM3-specific tests */ +/******************************************************************************/ + +TEST(TestArgoAC_WREM3Class, Eco) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setEco(false); + ASSERT_FALSE(ac.getEco()); + ac.setEco(true); + ASSERT_TRUE(ac.getEco()); + ac.setEco(false); + ASSERT_FALSE(ac.getEco()); +} + +TEST(TestArgoAC_WREM3Class, Filter) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setFilter(false); + ASSERT_FALSE(ac.getFilter()); + ac.setFilter(true); + ASSERT_TRUE(ac.getFilter()); + ac.setFilter(false); + ASSERT_FALSE(ac.getFilter()); +} + +TEST(TestArgoAC_WREM3Class, Light) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setLight(false); + ASSERT_FALSE(ac.getLight()); + ac.setLight(true); + ASSERT_TRUE(ac.getLight()); + ac.setLight(false); + ASSERT_FALSE(ac.getLight()); +} + +TEST(TestArgoAC_WREM3Class, Channel) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setChannel(0); + ASSERT_EQ(0, ac.getChannel()); + ac.setChannel(1); + ASSERT_EQ(1, ac.getChannel()); + ac.setChannel(2); + ASSERT_EQ(2, ac.getChannel()); + ac.setChannel(3); + ASSERT_EQ(3, ac.getChannel()); + ac.setChannel(4); + ASSERT_EQ(3, ac.getChannel()); +} + +TEST(TestArgoAC_WREM3Class, ConfigEntry) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setConfigEntry(0, 0); + ASSERT_EQ(std::make_pair(static_cast(0), static_cast(0)), + ac.getConfigEntry()); + ac.setConfigEntry(80, 86); + ASSERT_EQ(std::make_pair(static_cast(80), static_cast(86)), + ac.getConfigEntry()); + ac.setConfigEntry(255, 255); + ASSERT_EQ(std::make_pair(static_cast(255), + static_cast(255)), + ac.getConfigEntry()); +} + +TEST(TestArgoAC_WREM3Class, CurrentTimeMinutes) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setCurrentTimeMinutes(0); + ASSERT_EQ(0, ac.getCurrentTimeMinutes()); + ac.setCurrentTimeMinutes(16*60+50); + ASSERT_EQ(16*60+50, ac.getCurrentTimeMinutes()); + ac.setCurrentTimeMinutes(23*60+59); + ASSERT_EQ(23*60+59, ac.getCurrentTimeMinutes()); + ac.setCurrentTimeMinutes(23*60+59+1); + ASSERT_EQ(23*60+59, ac.getCurrentTimeMinutes()); +} + +TEST(TestArgoAC_WREM3Class, CurrentDayOfWeek) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setCurrentDayOfWeek(argoWeekday::SUNDAY); + ASSERT_EQ(argoWeekday::SUNDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::MONDAY); + ASSERT_EQ(argoWeekday::MONDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::TUESDAY); + ASSERT_EQ(argoWeekday::TUESDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::WEDNESDAY); + ASSERT_EQ(argoWeekday::WEDNESDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::THURSDAY); + ASSERT_EQ(argoWeekday::THURSDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::FRIDAY); + ASSERT_EQ(argoWeekday::FRIDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(argoWeekday::SATURDAY); + ASSERT_EQ(argoWeekday::SATURDAY, ac.getCurrentDayOfWeek()); + ac.setCurrentDayOfWeek(static_cast(200)); + ASSERT_EQ(argoWeekday::SATURDAY, ac.getCurrentDayOfWeek()); +} + +TEST(TestArgoAC_WREM3Class, TimerType) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setTimerType(argoTimerType_t::NO_TIMER); + ASSERT_EQ(argoTimerType_t::NO_TIMER, ac.getTimerType()); + ac.setTimerType(argoTimerType_t::DELAY_TIMER); + ASSERT_EQ(argoTimerType_t::DELAY_TIMER, ac.getTimerType()); + ac.setTimerType(argoTimerType_t::SCHEDULE_TIMER_1); + ASSERT_EQ(argoTimerType_t::SCHEDULE_TIMER_1, ac.getTimerType()); + ac.setTimerType(argoTimerType_t::SCHEDULE_TIMER_2); + ASSERT_EQ(argoTimerType_t::SCHEDULE_TIMER_2, ac.getTimerType()); + ac.setTimerType(argoTimerType_t::SCHEDULE_TIMER_3); + ASSERT_EQ(argoTimerType_t::SCHEDULE_TIMER_3, ac.getTimerType()); + ac.setTimerType(static_cast(201)); + ASSERT_EQ(argoTimerType_t::NO_TIMER, ac.getTimerType()); +} + +TEST(TestArgoAC_WREM3Class, DelayTimerMinutes) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setDelayTimerMinutes(0); + ASSERT_EQ(0, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(16*60+50); + ASSERT_EQ(16*60+50, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(16*60+54); + ASSERT_EQ(16*60+50, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(16*60+55); + ASSERT_EQ(16*60+60, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(19*60+44); + ASSERT_EQ(19*60+40, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(19*60+50); + ASSERT_EQ(19*60+50, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(19*60+60); + ASSERT_EQ(19*60+50, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(23*60+59); // Above max (19h50m) + ASSERT_EQ(19*60+50, ac.getDelayTimerMinutes()); + ac.setDelayTimerMinutes(23*60+59+1); + ASSERT_EQ(19*60+50, ac.getDelayTimerMinutes()); +} + +TEST(TestArgoAC_WREM3Class, ScheduleTimerStartMinutes) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setScheduleTimerStartMinutes(0); + ASSERT_EQ(0, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(16*60+50); + ASSERT_EQ(16*60+50, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(16*60+54); + ASSERT_EQ(16*60+50, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(16*60+55); + ASSERT_EQ(16*60+60, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(23*60+50); + ASSERT_EQ(23*60+50, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(23*60+59); // Above max (23h50m) + ASSERT_EQ(23*60+50, ac.getScheduleTimerStartMinutes()); + ac.setScheduleTimerStartMinutes(23*60+59+1); + ASSERT_EQ(23*60+50, ac.getScheduleTimerStartMinutes()); +} + +TEST(TestArgoAC_WREM3Class, ScheduleTimerStopMinutes) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setScheduleTimerStopMinutes(0); + ASSERT_EQ(0, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(16*60+50); + ASSERT_EQ(16*60+50, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(16*60+54); + ASSERT_EQ(16*60+50, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(16*60+55); + ASSERT_EQ(16*60+60, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(23*60+50); + ASSERT_EQ(23*60+50, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(23*60+59); // Above max (23h50m) + ASSERT_EQ(23*60+50, ac.getScheduleTimerStopMinutes()); + ac.setScheduleTimerStopMinutes(23*60+59+1); + ASSERT_EQ(23*60+50, ac.getScheduleTimerStopMinutes()); +} + +TEST(TestArgoAC_WREM3Class, ScheduleTimerActiveDays) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setScheduleTimerActiveDays(std::set({})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::IsEmpty()); + EXPECT_EQ(0b0000000, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::SUNDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::SUNDAY)); + EXPECT_EQ(0b0000001, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::MONDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::MONDAY)); + EXPECT_EQ(0b0000010, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::TUESDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::TUESDAY)); + EXPECT_EQ(0b0000100, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({ + argoWeekday::WEDNESDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::WEDNESDAY)); + EXPECT_EQ(0b0001000, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::THURSDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::THURSDAY)); + EXPECT_EQ(0b0010000, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::FRIDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::FRIDAY)); + EXPECT_EQ(0b0100000, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({argoWeekday::SATURDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), + ::testing::ElementsAre(argoWeekday::SATURDAY)); + EXPECT_EQ(0b1000000, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({ + argoWeekday::MONDAY, argoWeekday::TUESDAY, argoWeekday::WEDNESDAY, + argoWeekday::THURSDAY, argoWeekday::FRIDAY, argoWeekday::SATURDAY, + argoWeekday::SUNDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), ::testing::ElementsAre( + argoWeekday::SUNDAY, argoWeekday::MONDAY, argoWeekday::TUESDAY, + argoWeekday::WEDNESDAY, argoWeekday::THURSDAY, argoWeekday::FRIDAY, + argoWeekday::SATURDAY)); + EXPECT_EQ(0b1111111, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({ + argoWeekday::MONDAY, argoWeekday::TUESDAY, argoWeekday::WEDNESDAY, + argoWeekday::THURSDAY, argoWeekday::FRIDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), ::testing::ElementsAre( + argoWeekday::MONDAY, argoWeekday::TUESDAY, argoWeekday::WEDNESDAY, + argoWeekday::THURSDAY, argoWeekday::FRIDAY)); + EXPECT_EQ(0b0111110, ac.getTimerActiveDaysBitmap()); + + ac.setScheduleTimerActiveDays(std::set({ argoWeekday::TUESDAY, + argoWeekday::THURSDAY, argoWeekday::SATURDAY, argoWeekday::SUNDAY})); + EXPECT_THAT(ac.getScheduleTimerActiveDays(), ::testing::ElementsAre( + argoWeekday::SUNDAY, argoWeekday::TUESDAY, argoWeekday::THURSDAY, + argoWeekday::SATURDAY)); + EXPECT_EQ(0b1010101, ac.getTimerActiveDaysBitmap()); +} + +TEST(TestArgoAC_WREM3Class, staticGetMessageTypeFromRaw) { + ArgoProtocolWREM3 raw = {}; + + raw.IrCommandType = static_cast( + argoIrMessageType_t::AC_CONTROL); + EXPECT_EQ(argoIrMessageType_t::AC_CONTROL, + IRArgoAC_WREM3::getMessageType(raw)); + + raw.IrCommandType = static_cast( + argoIrMessageType_t::CONFIG_PARAM_SET); + EXPECT_EQ(argoIrMessageType_t::CONFIG_PARAM_SET, + IRArgoAC_WREM3::getMessageType(raw)); + + raw.IrCommandType = static_cast( + argoIrMessageType_t::IFEEL_TEMP_REPORT); + EXPECT_EQ(argoIrMessageType_t::IFEEL_TEMP_REPORT, + IRArgoAC_WREM3::getMessageType(raw)); + + raw.IrCommandType = static_cast( + argoIrMessageType_t::TIMER_COMMAND); + EXPECT_EQ(argoIrMessageType_t::TIMER_COMMAND, + IRArgoAC_WREM3::getMessageType(raw)); +} + +TEST(TestArgoAC_WREM3Class, HasValidPreamble) { + uint8_t preamble[] = { 0x4B, 0x57 }; + ASSERT_TRUE(IRArgoAC_WREM3::hasValidPreamble(preamble, + sizeof(preamble) / sizeof(preamble[0]))); + ASSERT_FALSE(IRArgoAC_WREM3::hasValidPreamble(preamble, 0)); + ASSERT_TRUE(IRArgoAC_WREM3::hasValidPreamble(preamble, 1)); + + preamble[0] = 0b00001011; + ASSERT_TRUE(IRArgoAC_WREM3::hasValidPreamble(preamble, + sizeof(preamble) / sizeof(preamble[0]))); + preamble[0] = 0b11111011; + ASSERT_TRUE(IRArgoAC_WREM3::hasValidPreamble(preamble, + sizeof(preamble) / sizeof(preamble[0]))); + preamble[0] = 0b00001010; + ASSERT_FALSE(IRArgoAC_WREM3::hasValidPreamble(preamble, + sizeof(preamble) / sizeof(preamble[0]))); + preamble[0] = 0b00000011; + ASSERT_FALSE(IRArgoAC_WREM3::hasValidPreamble(preamble, + sizeof(preamble) / sizeof(preamble[0]))); +} + +TEST(TestArgoAC_WREM3Class, IsValidWrem3Message) { + uint8_t wrem3AC[] = { 0x0B, 0x36, 0x12, 0x0F, 0xC2, 0x24 }; + uint8_t wrem3IFeel[] = { 0x4B, 0x78 }; + uint8_t wrem3Config[] = { 0xCB, 0x0C, 0x4A, 0x21 }; + uint8_t wrem3Tmr[] = { 0x8B, 0x05, 0x4D, 0x98, 0xD2, 0x44, 0x2E, 0x34, 0xA7 }; + uint8_t wrem2IFeel[] = { 0xAC, 0xF5, 0xC2, 0x63 }; + + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3AC, + sizeof(wrem3AC) / sizeof(wrem3AC[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3IFeel, + sizeof(wrem3IFeel) / sizeof(wrem3IFeel[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Config, + sizeof(wrem3Config) / sizeof(wrem3Config[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Tmr, + sizeof(wrem3Tmr) / sizeof(wrem3Tmr[0]) * 8, true)); + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem2IFeel, + sizeof(wrem2IFeel) / sizeof(wrem2IFeel[0]) * 8, true)); + + // 1 bit too short + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3AC, + sizeof(wrem3AC) / sizeof(wrem3AC[0]) * 8 - 1, true)); + + // wrong checksum + wrem3AC[5] ^= wrem3AC[5]; + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3AC, + sizeof(wrem3AC) / sizeof(wrem3AC[0]) * 8, true)); // strict + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3AC, + sizeof(wrem3AC) / sizeof(wrem3AC[0]) * 8, false)); // lax + wrem3AC[5] ^= wrem3AC[5]; // restore + + wrem3IFeel[1] ^= wrem3IFeel[1]; + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3IFeel, + sizeof(wrem3IFeel) / sizeof(wrem3IFeel[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3IFeel, + sizeof(wrem3IFeel) / sizeof(wrem3IFeel[0]) * 8, false)); + wrem3IFeel[1] ^= wrem3IFeel[1]; // restore + + wrem3Config[3] ^= wrem3Config[3]; + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Config, + sizeof(wrem3Config) / sizeof(wrem3Config[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Config, + sizeof(wrem3Config) / sizeof(wrem3Config[0]) * 8, false)); + wrem3Config[3] ^= wrem3Config[3]; // restore + + wrem3Tmr[8] ^= wrem3Tmr[8]; + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Tmr, + sizeof(wrem3Tmr) / sizeof(wrem3Tmr[0]) * 8, true)); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(wrem3Tmr, + sizeof(wrem3Tmr) / sizeof(wrem3Tmr[0]) * 8, false)); + wrem3Tmr[8] ^= wrem3Tmr[8]; // restore + + // wrong preamble + wrem3IFeel[0] += 1; + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3IFeel, + sizeof(wrem3IFeel) / sizeof(wrem3IFeel[0]) * 8, true)); + ASSERT_FALSE(IRArgoAC_WREM3::isValidWrem3Message(wrem3IFeel, + sizeof(wrem3IFeel) / sizeof(wrem3IFeel[0]) * 8, false)); + wrem3IFeel[0] -= 1; // restore +} + +TEST(TestArgoAC_WREM3Class, SendSensorTemp) { + IRrecv irrecv(kGpioUnused); + + // Method 1 (via sendSensorTemp()) + IRArgoAC_WREM3 ac(kGpioUnused); + ac.sendSensorTemp(10); + ac._irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&ac._irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, ac._irsend.capture.decode_type); + EXPECT_EQ("IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 10C", + IRAcUtils::resultAcToString(&ac._irsend.capture)); + + // Method 2 (via send()) + IRArgoAC_WREM3 ac2(kGpioUnused); + ac2.setMessageType(argoIrMessageType_t::IFEEL_TEMP_REPORT); + ac2.setSensorTemp(19); + ac2.send(); + ac2._irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&ac2._irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, ac2._irsend.capture.decode_type); + EXPECT_EQ("IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 19C", + IRAcUtils::resultAcToString(&ac2._irsend.capture)); +} + +TEST(TestArgoAC_WREM3Class, NonExModeFlapFan) { + IRArgoAC_WREM3 ac(kGpioUnused); + + ac.setFan(argoFan_t::FAN_HIGH); + EXPECT_EQ(argoFan_t::FAN_HIGH, ac.getFan()); + EXPECT_EQ(argoFan_t::FAN_HIGH, ac.getFanEx()); + + ac.setMode(argoMode_t::FAN); + EXPECT_EQ(argoMode_t::FAN, ac.getMode()); + EXPECT_EQ(argoMode_t::FAN, ac.getModeEx()); + + ac.setFlap(argoFlap_t::FLAP_4); + EXPECT_EQ(argoFlap_t::FLAP_4, ac.getFlap()); + EXPECT_EQ(argoFlap_t::FLAP_4, ac.getFlapEx()); +} + + +/******************************************************************************/ +/* Housekeeping */ +/******************************************************************************/ + TEST(TestUtils, Housekeeping) { ASSERT_EQ("ARGO", typeToString(decode_type_t::ARGO)); ASSERT_EQ(decode_type_t::ARGO, strToDecodeType("ARGO")); ASSERT_TRUE(hasACState(decode_type_t::ARGO)); + ASSERT_EQ(irutils::modelToStr(decode_type_t::ARGO, + argo_ac_remote_model_t::SAC_WREM2), "WREM2"); + ASSERT_EQ(irutils::modelToStr(decode_type_t::ARGO, + argo_ac_remote_model_t::SAC_WREM3), "WREM3"); +} + + +/******************************************************************************/ +/* Decode tests based on real (recorded) IR messages */ +/******************************************************************************/ +TEST(TestDecodeArgo, RealShortDecode) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + // Real short Argo message. (i.e. 32 bits) + const uint16_t sensor_28C[67] = { + 6418, 3168, 444, 834, 444, 834, 442, 2112, 444, 2112, 444, 834, 442, 2114, + 442, 834, 442, 2112, 444, 2112, 444, 832, 442, 2114, 442, 834, 442, 2112, + 442, 2114, 442, 2112, 444, 2112, 442, 834, 442, 2112, 444, 834, 442, 834, + 442, 834, 442, 834, 442, 2114, 442, 2114, 442, 2112, 442, 2112, 442, 834, + 444, 834, 442, 834, 442, 2112, 442, 2112, 442, 836, + 442}; // UNKNOWN 6149090 + irsend.reset(); + uint8_t expectedState[kArgoShortStateLength] = { + 0xAC, 0xF5, 0xC2, 0x63}; + irsend.sendRaw(sensor_28C, 67, 38); + irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, irsend.capture.decode_type); + EXPECT_EQ(kArgoShortBits, irsend.capture.bits); + EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); + EXPECT_EQ( + "Model: 1 (WREM2), Sensor Temp: 28C", + IRAcUtils::resultAcToString(&irsend.capture)); + stdAc::state_t r, p; + // These short messages do result in a valid state (w/ room temperature only) + EXPECT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); + EXPECT_EQ(stdAc::ac_command_t::kSensorTempReport, r.command); + EXPECT_EQ(28, r.sensorTemperature); } + +/// +/// @brief Test Fixture for recorded tests +/// +struct ArgoE2ETestParam { + const std::vector rawDataInput; + const uint8_t expectedEncodedSizeBytes; + const std::vector expectedEncodedValue; + const std::string expectedString; + + ArgoE2ETestParam(std::vector _raw, uint8_t _encSize, + std::vector _encValue, std::string _str) + : rawDataInput(_raw), expectedEncodedSizeBytes(_encSize), + expectedEncodedValue(_encValue), expectedString(_str) {} + + friend std::ostream& operator<<(std::ostream& os, const ArgoE2ETestParam& v) { + return os << "rawDataInput: " << ::testing::PrintToString(v.rawDataInput) + << "\n\texpectedEncodedSize: " + << static_cast(v.expectedEncodedSizeBytes) + << "[B]" << "\n\texpectedEncodedValue: 0x" + << bytesToHexString(v.expectedEncodedValue) << "\n\texpectedString: " + << v.expectedString; + } +}; + +/// +/// @brief Test fixture for real-world recorded messages for WREM3 +/// +class TestArgoE2E : public ::testing::TestWithParam {}; + +// Test code +TEST_P(TestArgoE2E, RealExampleCommands) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendRaw(&GetParam().rawDataInput[0], + GetParam().rawDataInput.size(), kArgoFrequency); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::ARGO, irsend.capture.decode_type); + ASSERT_TRUE(IRArgoAC_WREM3::isValidWrem3Message(irsend.capture.state, + irsend.capture.bits, true)); + + EXPECT_EQ(GetParam().expectedEncodedSizeBytes * 8, irsend.capture.bits); + + std::vector stateActual(irsend.capture.state, irsend.capture.state + + GetParam().expectedEncodedSizeBytes); + EXPECT_THAT(stateActual, ::testing::ElementsAreArray( + GetParam().expectedEncodedValue)); + + EXPECT_FALSE(irsend.capture.repeat); + + EXPECT_EQ(GetParam().expectedString, + IRAcUtils::resultAcToString(&irsend.capture)); +} + +// Test cases +INSTANTIATE_TEST_CASE_P( + TestDecodeArgo, + TestArgoE2E, + ::testing::Values( + ArgoE2ETestParam( + std::vector { + 6468, 3150, 456, 2154, 428, 2152, 462, 874, 422, 2158, 424, 882, + 424, 880, 428, 876, 430, 874, 454, 850, 424, 2154, 460, 2150, + 430, 874, 422, 2156, 458, 2152, 430, 874, 420, 884, 454, 850, + 424, 2152, 462, 874, 422, 882, 424, 2154, 428, 876, 430, 874, + 476, 828, 478, 2098, 462, 2148, 424, 2156, 458, 2150, 430, 874, + 432, 872, 422, 882, 424, 880, 482, 822, 430, 2148, 454, 852, + 488, 816, 480, 826, 482, 852, 454, 2126, 424, 2154, 458, 876, + 454, 852, 454, 2124, 426, 880, 426, 878, 428, 2150, 486, 848, + 426, 878, 428 + }, + kArgo3AcControlStateLength, + std::vector { 0x0B, 0x36, 0x12, 0x0F, 0xC2, 0x24 }, + "Command[CH#0]: Model: 2 (WREM3), Power: On, Mode: 1 (Cool), Temp: 22C, " + "Sensor Temp: 26C, Fan: 0 (Auto), Swing(V): 7 (Breeze), IFeel: Off, " + "Night: Off, Econo: Off, Max: Off, Filter: Off, Light: On"), + + + ArgoE2ETestParam( + std::vector { + 6460, 3150, 454, 2154, 426, 2152, 462, 842, 452, 2156, 424, 878, + 428, 874, 432, 2144, 456, 878, 428, 2148, 432, 870, 424, 2152, + 460, 842, 452, 2154, 426, 878, 428, 876, 430, 872, 422 + }, + kArgo3iFeelReportStateLength, + std::vector { 0x4B, 0x15 }, + "IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 25C"), + + + ArgoE2ETestParam( + std::vector { + 6434, 3222, 424, 2186, 424, 2156, 422, 882, 422, 2158, 430, 874, + 430, 876, 430, 2212, 400, 874, 430, 2150, 450, 2160, 428, 2152, + 428, 908, 396, 2184, 426, 878, 426, 2152, 426, 880, 448 + }, + kArgo3iFeelReportStateLength, + std::vector {0x4B, 0x57}, + "IFeel Report[CH#0]: Model: 2 (WREM3), Sensor Temp: 27C"), + + + ArgoE2ETestParam( + std::vector { + 6468, 3154, 482, 2128, 452, 2128, 484, 820, 486, 2124, 456, 848, + 458, 848, 424, 880, 448, 2130, 482, 2126, 452, 852, 422, 2158, + 488, 816, 490, 814, 490, 814, 492, 812, 482, 822, 484, 2124, + 422, 882, 456, 2124, 488, 2122, 456, 848, 458, 846, 460, 2120, + 482, 822, 484, 822, 484, 820, 486, 818, 488, 2122, 458, 2122, + 490, 814, 492, 814, 492, 2118, 450, 854, 452, 2126, 486, 820, + 486, 818, 488, 2122, 458, 846, 458, 2120, 492, 2118, 430, 874, + 430, 876, 454, 2126, 484, 820, 486, 818, 478, 828, 488, 2120, + 426, 878, 460, 844, 430, 2148, 486, 2094, 454, 2154, 480, 826, + 480, 2128, 430, 876, 430, 872, 422, 882, 424, 882, 424, 2156, + 478, 826, 480, 2100, 458, 2152, 482, 822, 484, 822, 452, 2156, + 424, 2156, 478, 2104, 452, 852, 454, 852, 452, 2158, 478, 828, + 478, 2132, 426 + }, + kArgo3TimerStateLength, + std::vector { + 0x8B, 0x05, 0x4D, 0x98, 0xD2, 0x44, 0x2E, 0x34, 0xA7 + }, + "Timer[CH#0]: Model: 2 (WREM3), Power: On, Timer Mode: 2 (Schedule1), " + "Clock: 20:32, Day: 0 (Sun), On Timer: 09:10, Off Timer: 17:50, " + "TimerActiveDays: Mon|Tue|Fri|Sat"), + + + ArgoE2ETestParam( + std::vector { + 6464, 3156, 492, 2118, 472, 2108, 484, 820, 486, 2124, 454, 850, + 456, 848, 426, 2154, 492, 2120, 482, 822, 450, 854, 452, 2128, + 484, 2126, 454, 850, 454, 850, 456, 848, 424, 880, 480, 822, + 428, 2152, 482, 822, 484, 2126, 454, 850, 454, 850, 456, 2122, + 490, 814, 492, 2118, 452, 852, 454, 850, 454, 848, 458, 846, + 460, 2118, 482, 822, 484, 820, 486 + }, + kArgo3ConfigStateLength, + std::vector { 0xCB, 0x0C, 0x4A, 0x21 }, + "Config[CH#0]: Model: 2 (WREM3), Key: 12, Value: 74")), + [](const testing::TestParamInfo& info) { + return bytesToHexString(info.param.expectedEncodedValue); + } +); diff --git a/lib/IRremoteESP8266/test/ir_Bosch_test.cpp b/lib/IRremoteESP8266/test/ir_Bosch_test.cpp index e9b6dc9ced..dd9402b69b 100644 --- a/lib/IRremoteESP8266/test/ir_Bosch_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Bosch_test.cpp @@ -13,7 +13,7 @@ TEST(TestUtils, Housekeeping) { ASSERT_EQ("BOSCH144", typeToString(decode_type_t::BOSCH144)); ASSERT_EQ(decode_type_t::BOSCH144, strToDecodeType("BOSCH144")); ASSERT_TRUE(hasACState(decode_type_t::BOSCH144)); - ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::BOSCH144)); + ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::BOSCH144)); ASSERT_EQ(kBosch144Bits, IRsend::defaultBits(decode_type_t::BOSCH144)); ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::BOSCH144)); } @@ -69,10 +69,10 @@ TEST(TestDecodeBosch144, RealExample) { EXPECT_EQ(kBosch144Bits, irsend.capture.bits); EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); EXPECT_EQ( - "", + "Power: On, Mode: 0 (Cool), Fan: 5 (High), Temp: 16C, Quiet: Off", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t result, prev; - ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); + ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); } TEST(TestDecodeBosch144, SyntheticSelfDecode) { @@ -93,8 +93,8 @@ TEST(TestDecodeBosch144, SyntheticSelfDecode) { EXPECT_EQ(kBosch144Bits, irsend.capture.bits); EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); EXPECT_EQ( - "", + "Power: On, Mode: 0 (Cool), Fan: 5 (High), Temp: 16C, Quiet: Off", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t result, prev; - ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); + ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); } diff --git a/lib/IRremoteESP8266/test/ir_Carrier_test.cpp b/lib/IRremoteESP8266/test/ir_Carrier_test.cpp index fa0f07b0cb..7920b83cae 100644 --- a/lib/IRremoteESP8266/test/ir_Carrier_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Carrier_test.cpp @@ -264,6 +264,16 @@ TEST(TestUtils, Housekeeping) { ASSERT_EQ(kCarrierAc64MinRepeat, IRsend::minRepeats(decode_type_t::CARRIER_AC64)); + // CARRIER_AC84 + ASSERT_EQ("CARRIER_AC84", typeToString(decode_type_t::CARRIER_AC84)); + ASSERT_EQ(decode_type_t::CARRIER_AC84, strToDecodeType("CARRIER_AC84")); + ASSERT_TRUE(hasACState(decode_type_t::CARRIER_AC84)); + ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::CARRIER_AC84)); + ASSERT_EQ(kCarrierAc84Bits, + IRsend::defaultBits(decode_type_t::CARRIER_AC84)); + ASSERT_EQ(kNoRepeat, + IRsend::minRepeats(decode_type_t::CARRIER_AC84)); + // CARRIER_AC128 ASSERT_EQ("CARRIER_AC128", typeToString(decode_type_t::CARRIER_AC128)); ASSERT_EQ(decode_type_t::CARRIER_AC128, strToDecodeType("CARRIER_AC128")); @@ -693,3 +703,113 @@ TEST(TestDecodeCarrierAC128, SyntheticExample) { stdAc::state_t r, p; ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); } + +// Decode a "real" Carrier 84bit example message. +TEST(TestDecodeCarrierAC84, RealExample) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + const uint8_t expected_state[kCarrierAc84StateLength] = { + 0x03, 0x00, 0x93, 0x31, 0x00, 0x12, 0x00, 0x12, 0x54, 0x21, 0xE8}; + irsend.begin(); + + irsend.reset(); + // Data from: + // https://github.com/crankyoldgit/IRremoteESP8266/issues/1943#issue-1519570772 + const uint16_t rawData[171] = { + 5844, 1152, + 1154, 462, 1152, 462, 418, 1194, 418, 1194, 420, 1194, 416, 1198, + 418, 1196, 416, 1196, 418, 1194, 420, 1192, 420, 1194, 420, 1194, + 1152, 460, 1152, 460, 420, 1192, 418, 1194, 1154, 458, 418, 1194, + 420, 1192, 1154, 460, 1152, 458, 420, 1194, 418, 1194, 418, 1194, + 1152, 460, 1154, 458, 418, 1196, 416, 1194, 418, 1194, 418, 1196, + 420, 1194, 418, 1192, 420, 1194, 420, 1192, 418, 1196, 416, 1194, + 416, 1196, 1152, 462, 416, 1194, 422, 1192, 1154, 458, 420, 1192, + 418, 1194, 418, 1194, 418, 1196, 420, 1194, 418, 1192, 420, 1194, + 418, 1192, 420, 1194, 418, 1194, 420, 1194, 418, 1194, 1154, 458, + 418, 1194, 418, 1192, 1154, 458, 418, 1196, 416, 1194, 420, 1194, + 416, 1192, 418, 1194, 1152, 462, 416, 1196, 1152, 458, 418, 1196, + 1152, 458, 418, 1194, 1154, 460, 418, 1194, 418, 1196, 418, 1196, + 418, 1194, 1154, 460, 420, 1192, 418, 1194, 420, 1194, 418, 1194, + 418, 1196, 1152, 460, 418, 1194, 1154, 458, 1154, 460, 1152, 458, + 1152}; // UNKNOWN E366A1BC + + + irsend.sendRaw(rawData, 171, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(CARRIER_AC84, irsend.capture.decode_type); + EXPECT_EQ(kCarrierAc84Bits, irsend.capture.bits); + EXPECT_STATE_EQ(expected_state, irsend.capture.state, irsend.capture.bits); + EXPECT_EQ( + "", + IRAcUtils::resultAcToString(&irsend.capture)); + EXPECT_EQ( + "Protocol : CARRIER_AC84\n" + "Code : 0x03009331001200125421E8 (84 Bits)\n", + resultToHumanReadableBasic(&irsend.capture)); +} + +// Decode a synthetic Carrier AC 84-bit message. +TEST(TestDecodeCarrierAC84, SyntheticExample) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + irsend.reset(); + + const uint8_t expected_state[kCarrierAc84StateLength] = { + 0x0C, 0x00, 0xC9, 0x8C, 0x00, 0x48, 0x00, 0x48, 0x2A, 0x84, 0x17}; + irsend.sendCarrierAC84(expected_state); + irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&irsend.capture)); + ASSERT_EQ(CARRIER_AC84, irsend.capture.decode_type); + ASSERT_EQ(kCarrierAc84Bits, irsend.capture.bits); + EXPECT_STATE_EQ(expected_state, irsend.capture.state, irsend.capture.bits); + EXPECT_EQ( + "", + IRAcUtils::resultAcToString(&irsend.capture)); + stdAc::state_t r, p; + ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); +} + +// Decode a "real" troublesome Carrier 84bit example message. +TEST(TestDecodeCarrierAC84, RealExample2) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + const uint8_t expected_state[kCarrierAc84StateLength] = { + 0x03, 0x00, 0x03, 0x32, 0x00, 0x12, 0x00, 0x12, 0x33, 0x11, 0xDC}; + irsend.begin(); + + irsend.reset(); + // Data from: + // https://github.com/crankyoldgit/IRremoteESP8266/issues/1943#issuecomment-1374434085 + const uint16_t rawData[171] = { + 5828, 1158, 1148, 464, 1148, 494, 384, 1200, 414, 1202, 412, 1202, 410, + 1204, 408, 1204, 408, 1206, 408, 1228, 386, 1202, 408, 1232, 386, 1202, + 1148, 464, 1146, 468, 412, 1200, 384, 1230, 412, 1200, 412, 1200, 410, + 1204, 412, 1200, 412, 1202, 1146, 468, 410, 1202, 410, 1204, 1146, 466, + 1146, 464, 410, 1230, 386, 1198, 414, 1200, 412, 1202, 410, 1202, 410, + 1200, 410, 1204, 408, 1204, 410, 1202, 412, 1226, 386, 1202, 1144, 468, + 408, 1204, 410, 1200, 1146, 468, 412, 1198, 410, 1206, 408, 1202, 410, + 1228, 384, 1228, 386, 1202, 410, 1202, 412, 1202, 408, 1202, 410, 1202, + 408, 1202, 410, 1204, 1146, 464, 412, 1202, 412, 1200, 1146, 468, 408, + 1202, 412, 1200, 382, 1232, 1146, 488, 1122, 466, 410, 1228, 386, 1200, + 1146, 492, 1118, 466, 412, 1202, 410, 1204, 1146, 464, 414, 1198, 410, + 1204, 410, 1202, 1150, 464, 410, 1202, 412, 1202, 410, 1226, 386, 1200, + 410, 1228, 1148, 440, 1148, 466, 1144, 468, 408, 1202, 1144, 470, 1144, + 492, 1120}; // UNKNOWN 4CC7BE54 + + irsend.sendRaw(rawData, 171, 38000); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(CARRIER_AC84, irsend.capture.decode_type); + EXPECT_EQ(kCarrierAc84Bits, irsend.capture.bits); + EXPECT_STATE_EQ(expected_state, irsend.capture.state, irsend.capture.bits); + EXPECT_EQ( + "", + IRAcUtils::resultAcToString(&irsend.capture)); + EXPECT_EQ( + "Protocol : CARRIER_AC84\n" + "Code : 0x03000332001200123311DC (84 Bits)\n", + resultToHumanReadableBasic(&irsend.capture)); +} diff --git a/lib/IRremoteESP8266/test/ir_Coolix_test.cpp b/lib/IRremoteESP8266/test/ir_Coolix_test.cpp index ba3610bc7f..101fab6546 100644 --- a/lib/IRremoteESP8266/test/ir_Coolix_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Coolix_test.cpp @@ -492,6 +492,9 @@ TEST(TestCoolixACClass, SetGetClearSensorTempAndZoneFollow) { EXPECT_EQ( "Power: On, Mode: 3 (Heat), Fan: 6 (Zone Follow), Temp: 24C, " "Zone Follow: On, Sensor Temp: 19C", ac.toString()); + // For #Issue2012 + EXPECT_EQ(19, ac.getSensorTemp()); + EXPECT_EQ(19, ac.toCommon().sensorTemperature); } TEST(TestCoolixACClass, SpecialModesAndReset) { @@ -1068,3 +1071,36 @@ TEST(TestDecodeCoolix48, SyntheticSelfDecode) { "m552s5244", irsend.outputStr()); } + +// Test for issue https://github.com/crankyoldgit/IRremoteESP8266/issues/2012#issuecomment-1650098971 +TEST(TestCoolixACClass, Issue2012) { + IRrecv irrecv(kGpioUnused); + IRCoolixAC ac(kGpioUnused); + + ac.stateReset(); + ac.setRaw(0xB21FD8); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 26C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + + ac.setRaw(0xB21F98); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 27C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + + ac.setRaw(0xB21F88); + EXPECT_EQ( + "Power: On, Mode: 2 (Auto), Fan: 0 (Auto0), Temp: 28C, " + "Zone Follow: Off, Sensor Temp: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); + ac.setRaw(0xB27BE0); + EXPECT_EQ( + "Power: Off", + ac.toString()); + EXPECT_EQ(kNoTempValue, ac.toCommon().sensorTemperature); +} diff --git a/lib/IRremoteESP8266/test/ir_Gorenje_test.cpp b/lib/IRremoteESP8266/test/ir_Gorenje_test.cpp new file mode 100644 index 0000000000..245b29b985 --- /dev/null +++ b/lib/IRremoteESP8266/test/ir_Gorenje_test.cpp @@ -0,0 +1,203 @@ +// Copyright 2022 Mateusz Bronk (mbronk) + +#include "IRac.h" +#include "IRsend.h" +#include "IRsend_test.h" +#include "gtest/gtest.h" + +class TestDecodeGorenjeSyntheticSendTestFixture + : public ::testing::TestWithParam {}; +class TestDecodeGorenjeReceiveTestFixture + : public ::testing::TestWithParam, + uint64_t>> {}; + +TEST(TestGorenje, Settings) { + ASSERT_EQ("GORENJE", typeToString(decode_type_t::GORENJE)); + ASSERT_EQ(decode_type_t::GORENJE, strToDecodeType("GORENJE")); + ASSERT_FALSE(hasACState(decode_type_t::GORENJE)); + ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::GORENJE)); + ASSERT_EQ(kGorenjeBits, + IRsendTest::defaultBits(decode_type_t::GORENJE)); +} + +// Test sending typical data (cooker hood light toggle) +TEST(TestSendGorenje, SendLightToggle) { + IRsendTest irsend(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendGorenje(0x10); // Light toggle + EXPECT_EQ( + "f38000d50" + "m1300s1700m1300s1700m1300s1700m1300s5700m1300s1700m1300s1700m1300s1700" + "m1300s1700" + "m1300s100000", + irsend.outputStr()); +} + +// Test sending with different repeats. +TEST(TestSendGorenje, SendWithRepeats) { + IRsendTest irsend(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendGorenje(0x8, kGorenjeBits, 0); // 0 repeats. + EXPECT_EQ( + "f38000d50" + "m1300s1700m1300s1700m1300s1700m1300s1700m1300s5700m1300s1700m1300s1700" + "m1300s1700" + "m1300s100000", + irsend.outputStr()); + irsend.sendGorenje(0x8, kGorenjeBits, 2); // 2 repeats. + EXPECT_EQ( + "f38000d50" + "m1300s1700m1300s1700m1300s1700m1300s1700m1300s5700m1300s1700m1300s1700" + "m1300s1700" + "m1300s100000" + "m1300s1700m1300s1700m1300s1700m1300s1700m1300s5700m1300s1700m1300s1700" + "m1300s1700" + "m1300s100000" + "m1300s1700m1300s1700m1300s1700m1300s1700m1300s5700m1300s1700m1300s1700" + "m1300s1700" + "m1300s100000", + irsend.outputStr()); +} + + +// Decode a Synthetic example +TEST_P(TestDecodeGorenjeSyntheticSendTestFixture, SyntheticExample) { + uint64_t commandToTest = GetParam(); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendGorenje(commandToTest); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(GORENJE, irsend.capture.decode_type); + EXPECT_EQ(kGorenjeBits, irsend.capture.bits); + EXPECT_EQ(commandToTest, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.address); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_FALSE(irsend.capture.repeat); +} + +INSTANTIATE_TEST_CASE_P( + TestDecodeGorenje, + TestDecodeGorenjeSyntheticSendTestFixture, + ::testing::Values(0x2, 0x8, 0x4, 0x10, 0x20, 0x1)); + + +// Decode a real example (codes captured from original remote) +TEST_P(TestDecodeGorenjeReceiveTestFixture, RealExample) { + const std::vector rawDataInput = std::get<0>(GetParam()); + const uint64_t expectedValue = std::get<1>(GetParam()); + + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendRaw(&rawDataInput[0], rawDataInput.size(), 38000); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::GORENJE, irsend.capture.decode_type); + EXPECT_EQ(kGorenjeBits, irsend.capture.bits); + EXPECT_EQ(expectedValue, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.address); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_FALSE(irsend.capture.repeat); +} + +INSTANTIATE_TEST_CASE_P( + TestDecodeGorenje, + TestDecodeGorenjeReceiveTestFixture, + ::testing::Values( + // POWER + std::make_tuple(std::vector { + 1292, 1716, 1300, 1708, 1296, 1712, + 1294, 1714, 1302, 1708, 1298, 1710, + 1294, 5752, 1294, 1714, 1302 + }, + 0x2), + std::make_tuple(std::vector { + 1302, 1706, 1298, 1710, 1294, 1714, + 1292, 1716, 1300, 1708, 1296, 1712, + 1294, 5754, 1292, 1716, 1300 + }, + 0x2), + + // FAN- + std::make_tuple(std::vector { + 1328, 1680, 1324, 1684, 1320, 1688, + 1328, 1680, 1324, 5724, 1322, 1684, + 1330, 1678, 1326, 1682, 1324 + }, + 0x8), + std::make_tuple(std::vector { + 1296, 1712, 1292, 1718, 1298, 1710, + 1294, 1714, 1292, 5756, 1300, 1708, + 1296, 1712, 1294, 1714, 1300 + }, + 0x8), + + // FAN+ + std::make_tuple(std::vector { + 1324, 1684, 1320, 1688, 1328, 1680, + 1324, 1684, 1322, 1688, 1328, 5718, + 1326, 1682, 1322, 1686, 1352 + }, + 0x4), + std::make_tuple(std::vector { + 1296, 1714, 1292, 1716, 1298, 1710, + 1296, 1714, 1292, 1716, 1300, 5748, + 1296, 1712, 1292, 1716, 1300 + }, + 0x4), + + // Light toggle + std::make_tuple(std::vector { + 1326, 1682, 1322, 1686, 1328, 1680, + 1324, 5722, 1322, 1686, 1330, 1680, + 1326, 1682, 1322, 1686, 1328 + }, + 0x10), + std::make_tuple(std::vector { + 1328, 1680, 1324, 1684, 1330, 1678, + 1326, 5722, 1324, 1684, 1330, 1678, + 1326, 1682, 1322, 1686, 1330 + }, + 0x10), + + // Light- + std::make_tuple(std::vector { + 1328, 1680, 1324, 1686, 1330, 5716, + 1328, 1680, 1324, 1684, 1330, 1678, + 1326, 1682, 1354, 1654, 1328 + }, + 0x20), + std::make_tuple(std::vector { + 1322, 1686, 1318, 1690, 1326, 5722, + 1322, 1686, 1330, 1678, 1326, 1682, + 1322, 1686, 1328, 1680, 1324 + }, + 0x20), + + // Light+ + std::make_tuple(std::vector { + 1328, 1680, 1326, 1682, 1322, 1688, + 1328, 1680, 1324, 1686, 1330, 1678, + 1326, 1682, 1322, 5724, 1330 + }, + 0x1), + std::make_tuple(std::vector { + 1298, 1710, 1294, 1714, 1302, 1708, + 1298, 1710, 1294, 1716, 1300, 1708, + 1296, 1712, 1292, 5756, 1300 + }, + 0x1) + ) +); diff --git a/lib/IRremoteESP8266/test/ir_Haier_test.cpp b/lib/IRremoteESP8266/test/ir_Haier_test.cpp index 57c813c0d0..5f2b9a92df 100644 --- a/lib/IRremoteESP8266/test/ir_Haier_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Haier_test.cpp @@ -1361,7 +1361,7 @@ TEST(TestUtils, Housekeeping) { ASSERT_EQ("HAIER_AC160", typeToString(decode_type_t::HAIER_AC160)); ASSERT_EQ(decode_type_t::HAIER_AC160, strToDecodeType("HAIER_AC160")); ASSERT_TRUE(hasACState(decode_type_t::HAIER_AC160)); - ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::HAIER_AC160)); + ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::HAIER_AC160)); ASSERT_EQ(kHaierAC160Bits, IRsend::defaultBits(decode_type_t::HAIER_AC160)); ASSERT_EQ(kNoRepeat, IRsend::minRepeats(decode_type_t::HAIER_AC160)); } @@ -1588,10 +1588,14 @@ TEST(TestDecodeHaierAC160, RealExample) { EXPECT_FALSE(irsend.capture.repeat); EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); EXPECT_EQ( - "", + "Power: On, Button: 5 (Power), Mode: 1 (Cool), Temp: 26C, Fan: 3 (Low), " + "Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), Sleep: Off, " + "Clean: Off, " + "Timer Mode: 0 (N/A), On Timer: Off, Off Timer: Off, Lock: Off, " + "Heating: Off", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t result, prev; - ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); + ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); } // Decoding a message we entirely constructed based solely on a given state. @@ -1613,8 +1617,417 @@ TEST(TestDecodeHaierAC160, SyntheticExample) { EXPECT_FALSE(irsend.capture.repeat); EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits); EXPECT_EQ( - "", + "Power: On, Button: 5 (Power), Mode: 1 (Cool), Temp: 26C, Fan: 3 (Low), " + "Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), Sleep: Off, " + "Clean: Off, " + "Timer Mode: 0 (N/A), On Timer: Off, Off Timer: Off, Lock: Off, " + "Heating: Off", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t result, prev; - ASSERT_FALSE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); + ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &result, &prev)); +} + +// Tests for the IRHaierAC160 class. + +TEST(TestHaierAC160Class, Button) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setButton(kHaierAcYrw02ButtonPower); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + ac.setButton(kHaierAcYrw02ButtonMode); + EXPECT_EQ(kHaierAcYrw02ButtonMode, ac.getButton()); + ac.setButton(kHaierAcYrw02ButtonSleep); + EXPECT_EQ(kHaierAcYrw02ButtonSleep, ac.getButton()); + ac.setButton(kHaierAcYrw02ButtonFan); + + // Test unexpected values. + ac.setButton(0xFF); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); + ac.setButton(0x10); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); +} + +TEST(TestHaierAC160Class, OperatingMode) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setButton(kHaierAcYrw02ButtonPower); + ac.setMode(kHaierAcYrw02Auto); + EXPECT_EQ(kHaierAcYrw02Auto, ac.getMode()); + EXPECT_EQ(kHaierAcYrw02ButtonMode, ac.getButton()); + + ac.setMode(kHaierAcYrw02Cool); + EXPECT_EQ(kHaierAcYrw02Cool, ac.getMode()); + EXPECT_FALSE(ac.getAuxHeating()); + + ac.setMode(kHaierAcYrw02Heat); + EXPECT_EQ(kHaierAcYrw02Heat, ac.getMode()); + EXPECT_TRUE(ac.getAuxHeating()); + + ac.setMode(kHaierAcYrw02Fan); + EXPECT_EQ(kHaierAcYrw02Fan, ac.getMode()); + EXPECT_FALSE(ac.getAuxHeating()); + + ac.setMode(kHaierAcYrw02Dry); + EXPECT_EQ(kHaierAcYrw02Dry, ac.getMode()); + + ac.setMode(kHaierAcYrw02Auto - 1); + EXPECT_EQ(kHaierAcYrw02Auto, ac.getMode()); + + ac.setMode(kHaierAcYrw02Cool); + EXPECT_EQ(kHaierAcYrw02Cool, ac.getMode()); + + ac.setMode(kHaierAcYrw02Fan + 1); + EXPECT_EQ(kHaierAcYrw02Auto, ac.getMode()); + + ac.setMode(255); + EXPECT_EQ(kHaierAcYrw02Auto, ac.getMode()); +} + +TEST(TestHaierAC160Class, Temperature) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setTemp(kHaierAcYrw02MinTempC); + EXPECT_EQ(kHaierAcYrw02MinTempC, ac.getTemp()); + + ac.setButton(kHaierAcYrw02ButtonPower); + ac.setTemp(kHaierAcYrw02MinTempC + 1); + EXPECT_EQ(kHaierAcYrw02MinTempC + 1, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MaxTempC); + EXPECT_EQ(kHaierAcYrw02MaxTempC, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MinTempC - 1); + EXPECT_EQ(kHaierAcYrw02MinTempC, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempDown, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MaxTempC + 1); + EXPECT_EQ(kHaierAcYrw02MaxTempC, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(23); + EXPECT_EQ(23, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempDown, ac.getButton()); + ac.setButton(kHaierAcYrw02ButtonPower); + ac.setTemp(23); + EXPECT_EQ(23, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MinTempF, true); + EXPECT_EQ(kHaierAcYrw02MinTempF, ac.getTemp()); + + ac.setButton(kHaierAcYrw02ButtonPower); + ac.setTemp(kHaierAcYrw02MinTempF + 1, true); + EXPECT_EQ(kHaierAcYrw02MinTempF + 1, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MaxTempF, true); + EXPECT_EQ(kHaierAcYrw02MaxTempF, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MinTempF - 1, true); + EXPECT_EQ(kHaierAcYrw02MinTempF, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempDown, ac.getButton()); + + ac.setTemp(kHaierAcYrw02MaxTempF + 1, true); + EXPECT_EQ(kHaierAcYrw02MaxTempF, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); + + ac.setTemp(66, true); + EXPECT_EQ(66, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempDown, ac.getButton()); + ac.setButton(kHaierAcYrw02ButtonPower); + ac.setTemp(66, true); + EXPECT_EQ(66, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + + // Test specific cases for converting to Fahrenheit + ac.setTemp(76, true); + EXPECT_EQ(76, ac.getTemp()); + ac.setTemp(77, true); + EXPECT_EQ(77, ac.getTemp()); + ac.setTemp(78, true); + EXPECT_EQ(78, ac.getTemp()); + + ac.setTemp(24); + EXPECT_EQ(kHaierAcYrw02ButtonCFAB, ac.getButton()); + + ac.setTemp(0); + EXPECT_EQ(kHaierAcYrw02MinTempC, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempDown, ac.getButton()); + + ac.setTemp(255); + EXPECT_EQ(kHaierAcMaxTemp, ac.getTemp()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); +} + +TEST(TestHaierAC160Class, CleanMode) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setClean(true); + EXPECT_TRUE(ac.getClean()); + EXPECT_EQ(kHaierAc160ButtonClean, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setClean(false); + EXPECT_FALSE(ac.getClean()); + EXPECT_EQ(kHaierAc160ButtonClean, ac.getButton()); + + ac.setClean(true); + EXPECT_TRUE(ac.getClean()); + EXPECT_EQ(kHaierAc160ButtonClean, ac.getButton()); + + ac.stateReset(); + EXPECT_FALSE(ac.getClean()); + // clean button pressed. + // https://docs.google.com/spreadsheets/d/1RNJ7esbArS5fy1lmiM-i1PekXSNojCMad4WuuyunsC8/edit#gid=2048081808&range=FR22 + const uint8_t clean_on[kHaierAC160StateLength] = { + 0xA6, 0xAC, 0x00, 0x00, 0x40, 0x60, 0x00, 0x20, 0x00, 0x00, + 0x10, 0x00, 0x19, 0x3B, 0xB5, 0x40, 0x60, 0x00, 0x00, 0x55}; + ac.setRaw(clean_on); + EXPECT_TRUE(ac.getClean()); + EXPECT_EQ( + "Power: On, Button: 25 (Clean), Mode: 1 (Cool), Temp: 26C, " + "Fan: 3 (Low), Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), " + "Sleep: Off, Clean: On, Timer Mode: 0 (N/A), " + "On Timer: Off, Off Timer: Off, Lock: Off, Heating: Off", + ac.toString()); + // No clean set. + // https://docs.google.com/spreadsheets/d/1RNJ7esbArS5fy1lmiM-i1PekXSNojCMad4WuuyunsC8/edit#gid=2048081808&range=FR4 + const uint8_t clean_off[kHaierAC160StateLength] = { + 0xA6, 0xAC, 0x00, 0x00, 0x40, 0x60, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x05, 0x17, 0xB5, 0x00, 0x60, 0x00, 0x00, 0x15}; + ac.setRaw(clean_off); + EXPECT_FALSE(ac.getClean()); + EXPECT_EQ( + "Power: On, Button: 5 (Power), Mode: 1 (Cool), Temp: 26C, " + "Fan: 3 (Low), Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), " + "Sleep: Off, Clean: Off, Timer Mode: 0 (N/A), " + "On Timer: Off, Off Timer: Off, Lock: Off, Heating: Off", + ac.toString()); +} + +TEST(TestHaierAC160Class, Power) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setPower(true); + EXPECT_TRUE(ac.getPower()); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setPower(false); + EXPECT_FALSE(ac.getPower()); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + + ac.setPower(true); + EXPECT_TRUE(ac.getPower()); + EXPECT_EQ(kHaierAcYrw02ButtonPower, ac.getButton()); + + ac.off(); + EXPECT_FALSE(ac.getPower()); + ac.on(); + EXPECT_TRUE(ac.getPower()); +} + +TEST(TestHaierAC160Class, SleepMode) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setSleep(true); + EXPECT_TRUE(ac.getSleep()); + EXPECT_EQ(kHaierAcYrw02ButtonSleep, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setSleep(false); + EXPECT_FALSE(ac.getSleep()); + EXPECT_EQ(kHaierAcYrw02ButtonSleep, ac.getButton()); + + ac.setSleep(true); + EXPECT_TRUE(ac.getSleep()); + EXPECT_EQ(kHaierAcYrw02ButtonSleep, ac.getButton()); +} + +TEST(TestHaierAC160Class, Health) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setHealth(true); + EXPECT_TRUE(ac.getHealth()); + EXPECT_EQ(kHaierAcYrw02ButtonHealth, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setHealth(false); + EXPECT_FALSE(ac.getHealth()); + EXPECT_EQ(kHaierAcYrw02ButtonHealth, ac.getButton()); + + ac.setHealth(true); + EXPECT_TRUE(ac.getHealth()); + EXPECT_EQ(kHaierAcYrw02ButtonHealth, ac.getButton()); +} + +TEST(TestHaierAC160Class, TurboAndQuiet) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setMode(kHaierAcYrw02Cool); // Turbo & Quiet is allowed in this mode. + ac.setTurbo(false); + ac.setQuiet(false); + EXPECT_FALSE(ac.getTurbo()); + EXPECT_FALSE(ac.getQuiet()); + EXPECT_EQ(kHaierAcYrw02ButtonTurbo, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + + ac.setTurbo(true); + EXPECT_TRUE(ac.getTurbo()); + EXPECT_FALSE(ac.getQuiet()); + EXPECT_EQ(kHaierAcYrw02ButtonTurbo, ac.getButton()); + + ac.setQuiet(true); + EXPECT_FALSE(ac.getTurbo()); + EXPECT_TRUE(ac.getQuiet()); + EXPECT_EQ(kHaierAcYrw02ButtonTurbo, ac.getButton()); + + ac.setTurbo(false); + ac.setQuiet(false); + EXPECT_FALSE(ac.getTurbo()); + EXPECT_FALSE(ac.getQuiet()); + EXPECT_EQ(kHaierAcYrw02ButtonTurbo, ac.getButton()); + + ac.setMode(kHaierAcYrw02Auto); // Turbo & Quiet is not allowed in this mode. + EXPECT_FALSE(ac.getTurbo()); + EXPECT_FALSE(ac.getQuiet()); + ac.setTurbo(true); + EXPECT_FALSE(ac.getTurbo()); + EXPECT_NE(kHaierAcYrw02ButtonTurbo, ac.getButton()); + ac.setQuiet(true); + EXPECT_FALSE(ac.getQuiet()); + EXPECT_NE(kHaierAcYrw02ButtonTurbo, ac.getButton()); +} + +TEST(TestHaierAC160Class, Fan) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setFan(kHaierAcYrw02FanAuto); + EXPECT_EQ(kHaierAcYrw02FanAuto, ac.getFan()); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + + ac.setFan(kHaierAcYrw02FanLow); + EXPECT_EQ(kHaierAcYrw02FanLow, ac.getFan()); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); + + ac.setFan(kHaierAcYrw02FanHigh); + EXPECT_EQ(kHaierAcYrw02FanHigh, ac.getFan()); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); + + ac.setFan(kHaierAcYrw02FanMed); + EXPECT_EQ(kHaierAcYrw02FanMed, ac.getFan()); + EXPECT_EQ(kHaierAcYrw02ButtonFan, ac.getButton()); + + // Test unexpected values. + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setFan(0x00); + EXPECT_EQ(kHaierAcYrw02FanMed, ac.getFan()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); +} + +TEST(TestHaierAC160Class, SwingV) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setSwingV(kHaierAc160SwingVOff); + EXPECT_EQ(kHaierAc160SwingVOff, ac.getSwingV()); + EXPECT_EQ(kHaierAcYrw02ButtonSwingV, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + + ac.setSwingV(kHaierAc160SwingVAuto); + EXPECT_EQ(kHaierAc160SwingVAuto, ac.getSwingV()); + EXPECT_EQ(kHaierAcYrw02ButtonSwingV, ac.getButton()); + + ac.setSwingV(kHaierAc160SwingVTop); + EXPECT_EQ(kHaierAc160SwingVTop, ac.getSwingV()); + EXPECT_EQ(kHaierAcYrw02ButtonSwingV, ac.getButton()); + + ac.setSwingV(kHaierAc160SwingVLow); + EXPECT_EQ(kHaierAc160SwingVLow, ac.getSwingV()); + EXPECT_EQ(kHaierAcYrw02ButtonSwingV, ac.getButton()); + + // Test unexpected values. + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setSwingV(0xFF); + EXPECT_EQ(kHaierAc160SwingVLow, ac.getSwingV()); + EXPECT_EQ(kHaierAcYrw02ButtonTempUp, ac.getButton()); +} + +TEST(TestHaierAC160Class, Light) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setLightToggle(true); + EXPECT_TRUE(ac.getLightToggle()); + EXPECT_EQ(kHaierAc160ButtonLight, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setLightToggle(false); + EXPECT_FALSE(ac.getLightToggle()); + EXPECT_NE(kHaierAc160ButtonLight, ac.getButton()); + + ac.setLightToggle(true); + EXPECT_TRUE(ac.getLightToggle()); + EXPECT_EQ(kHaierAc160ButtonLight, ac.getButton()); + + const uint8_t light_press[kHaierAC160StateLength] = { + 0xA6, 0xAC, 0x00, 0x00, 0x40, 0x60, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x15, 0x27, 0xB5, 0x00, 0x60, 0x00, 0x00, 0x15}; + ac.setRaw(light_press); + EXPECT_TRUE(ac.getLightToggle()); + EXPECT_EQ(kHaierAc160ButtonLight, ac.getButton()); + EXPECT_EQ( + "Power: On, Button: 21 (Light), Mode: 1 (Cool), Temp: 26C, " + "Fan: 3 (Low), Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), " + "Sleep: Off, Clean: Off, Timer Mode: 0 (N/A), " + "On Timer: Off, Off Timer: Off, Lock: Off, Heating: Off", + ac.toString()); +} + +TEST(TestHaierAC160Class, AuxHeating) { + IRHaierAC160 ac(kGpioUnused); + ac.begin(); + + ac.setAuxHeating(true); + EXPECT_TRUE(ac.getAuxHeating()); + EXPECT_EQ(kHaierAc160ButtonAuxHeating, ac.getButton()); + + ac.setButton(kHaierAcYrw02ButtonTempUp); + ac.setAuxHeating(false); + EXPECT_FALSE(ac.getAuxHeating()); + EXPECT_EQ(kHaierAc160ButtonAuxHeating, ac.getButton()); + + ac.setAuxHeating(true); + EXPECT_TRUE(ac.getAuxHeating()); + EXPECT_EQ(kHaierAc160ButtonAuxHeating, ac.getButton()); + + // https://docs.google.com/spreadsheets/d/1RNJ7esbArS5fy1lmiM-i1PekXSNojCMad4WuuyunsC8/edit#gid=2048081808&range=A124:W143 + const uint8_t aux_button_off[kHaierAC160StateLength] = { + 0xA6, 0xAC, 0x00, 0x00, 0x40, 0x60, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x16, 0x88, 0xB5, 0x00, 0x60, 0x00, 0x00, 0x15}; + ac.setRaw(aux_button_off); + EXPECT_FALSE(ac.getAuxHeating()); + EXPECT_EQ(kHaierAc160ButtonAuxHeating, ac.getButton()); + EXPECT_EQ( + "Power: On, Button: 22 (Heating), Mode: 4 (Heat), Temp: 26C, " + "Fan: 3 (Low), Turbo: Off, Quiet: Off, Health: Off, Swing(V): 12 (Auto), " + "Sleep: Off, Clean: Off, Timer Mode: 0 (N/A), " + "On Timer: Off, Off Timer: Off, Lock: Off, Heating: Off", + ac.toString()); } diff --git a/lib/IRremoteESP8266/test/ir_Panasonic_test.cpp b/lib/IRremoteESP8266/test/ir_Panasonic_test.cpp index 3e52cef8b2..3e3ae4d2be 100644 --- a/lib/IRremoteESP8266/test/ir_Panasonic_test.cpp +++ b/lib/IRremoteESP8266/test/ir_Panasonic_test.cpp @@ -13,7 +13,7 @@ // Tests for encodePanasonic(). TEST(TestEncodePanasonic, General) { - IRsendTest irsend(4); + IRsendTest irsend(kGpioUnused); EXPECT_EQ(0x0, irsend.encodePanasonic(0, 0, 0, 0)); EXPECT_EQ(0x101010101, irsend.encodePanasonic(1, 1, 1, 1)); EXPECT_EQ(0xFFFF, irsend.encodePanasonic(0, 0, 0, 0xFF)); @@ -28,7 +28,7 @@ TEST(TestEncodePanasonic, General) { // Test sending typical data only. TEST(TestSendPanasonic64, SendDataOnly) { - IRsendTest irsend(4); + IRsendTest irsend(kGpioUnused); irsend.begin(); irsend.reset(); @@ -76,7 +76,7 @@ TEST(TestSendPanasonic64, SendDataOnly) { // Test sending with different repeats. TEST(TestSendPanasonic64, SendWithRepeats) { - IRsendTest irsend(4); + IRsendTest irsend(kGpioUnused); irsend.begin(); irsend.reset(); @@ -147,7 +147,7 @@ TEST(TestSendPanasonic64, SendWithRepeats) { // Test sending an atypical data size. TEST(TestSendPanasonic64, SendUnusualSize) { - IRsendTest irsend(4); + IRsendTest irsend(kGpioUnused); irsend.begin(); irsend.reset(); @@ -213,8 +213,8 @@ TEST(TestSendPanasonic, CompareToSendPanasonic64) { // Decode normal Panasonic messages. TEST(TestDecodePanasonic, NormalDecodeWithStrict) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); // Normal Panasonic 48-bit message. @@ -259,8 +259,8 @@ TEST(TestDecodePanasonic, NormalDecodeWithStrict) { // Decode normal repeated Panasonic messages. TEST(TestDecodePanasonic, NormalDecodeWithRepeatAndStrict) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); // Normal Panasonic 48-bit message with 2 repeats. @@ -293,8 +293,8 @@ TEST(TestDecodePanasonic, NormalDecodeWithRepeatAndStrict) { // Decode Panasonic messages with unsupported values. TEST(TestDecodePanasonic, DecodeWithNonStrictValues) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -331,8 +331,8 @@ TEST(TestDecodePanasonic, DecodeWithNonStrictValues) { // Decode Panasonic messages with unsupported size/lengths. TEST(TestDecodePanasonic, DecodeWithNonStrictSize) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -375,8 +375,8 @@ TEST(TestDecodePanasonic, DecodeWithNonStrictSize) { // Decode (non-standard) 64-bit messages. TEST(TestDecodePanasonic, Decode64BitMessages) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -395,8 +395,8 @@ TEST(TestDecodePanasonic, Decode64BitMessages) { // Decode a 'real' example via GlobalCache TEST(TestDecodePanasonic, DecodeGlobalCacheExample) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -432,8 +432,8 @@ TEST(TestDecodePanasonic, DecodeGlobalCacheExample) { // Fail to decode a non-Panasonic example via GlobalCache TEST(TestDecodePanasonic, FailToDecodeNonPanasonicExample) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -452,8 +452,8 @@ TEST(TestDecodePanasonic, FailToDecodeNonPanasonicExample) { // Failing to decode Panasonic in Issue #245 TEST(TestDecodePanasonic, DecodeIssue245) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); irsend.reset(); @@ -813,8 +813,8 @@ TEST(TestIRPanasonicAcClass, HumanReadable) { // Decode normal Panasonic AC messages. TEST(TestDecodePanasonicAC, RealExample) { - IRsendTest irsend(4); - IRrecv irrecv(4); + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); irsend.begin(); // Data from Issue #525 @@ -1586,3 +1586,73 @@ TEST(TestIRPanasonicAc32Class, HumanReadable) { "Swing(H): Off, Swing(V): 5 (Lowest)", ac.toString()); } + +// Decode a 'real' example of a captured 40 bit panasonic message +TEST(TestDecodePanasonic, RealPanasonic40BitMesg) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + irsend.reset(); + // Panasonic 40 bit code https://github.com/crankyoldgit/IRremoteESP8266/issues/1976#issue-1660147581 + const uint16_t rawData1[83] = { + 3486, 1742, + 432, 456, 406, 456, 406, 1336, 406, 1312, 430, 456, 406, 1334, 408, 456, + 406, 456, 408, 456, 406, 1334, 408, 456, 408, 454, 408, 1334, 408, 456, + 406, 1336, 406, 456, 408, 1334, 408, 456, 406, 456, 408, 1336, 406, 456, + 408, 454, 406, 456, 406, 454, 408, 1332, 410, 1332, 408, 1334, 408, 1336, + 406, 1334, 410, 1332, 410, 454, 406, 456, 406, 456, 406, 1332, 410, 1334, + 408, 454, 406, 1336, 406, 1336, 406, 454, 410, 454, 408}; // UKN 1D41D404 + + irsend.sendRaw(rawData1, 83, 38); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(PANASONIC, irsend.capture.decode_type); + EXPECT_EQ(kPanasonic40Bits, irsend.capture.bits); + EXPECT_EQ(0x344A90FC6C, irsend.capture.value); + EXPECT_EQ(0x34, irsend.capture.address); + EXPECT_EQ(0x4A90FC6C, irsend.capture.command); + EXPECT_FALSE(irsend.capture.repeat); + + // night ch3 from https://github.com/crankyoldgit/IRremoteESP8266/issues/1976#issuecomment-1501736104 + const uint16_t rawData2[83] = { + 3490, 1734, + 440, 426, 460, 400, 438, 1304, 438, 1302, 440, 426, 436, 1302, 464, 400, + 462, 400, 462, 402, 462, 1278, 438, 426, 438, 426, 460, 1282, 434, 428, + 434, 1308, 460, 402, 460, 1280, 440, 422, 438, 426, 436, 1306, 438, 424, + 462, 402, 436, 426, 462, 400, 438, 426, 436, 1304, 434, 1308, 438, 1304, + 464, 1278, 436, 1306, 466, 398, 464, 398, 466, 1276, 466, 1274, 464, 1280, + 462, 402, 436, 1304, 466, 1276, 440, 422, 440, 424, 460}; // UKN DAE32FFC + irsend.reset(); + + irsend.sendRaw(rawData2, 83, 38); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(PANASONIC, irsend.capture.decode_type); + EXPECT_EQ(kPanasonic40Bits, irsend.capture.bits); + EXPECT_EQ(0x344A907CEC, irsend.capture.value); + EXPECT_EQ(0x34, irsend.capture.address); + EXPECT_EQ(0x4A907CEC, irsend.capture.command); + EXPECT_FALSE(irsend.capture.repeat); +} + +// recreate the above real message, synthetically. +TEST(TestDecodePanasonic, SynthticPanasonic40BitMesg) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + irsend.reset(); + + irsend.sendPanasonic64(0x344A90FC6C, kPanasonic40Bits); + irsend.makeDecodeResult(); + + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(PANASONIC, irsend.capture.decode_type); + EXPECT_EQ(kPanasonic40Bits, irsend.capture.bits); + EXPECT_EQ(0x344A90FC6C, irsend.capture.value); + EXPECT_EQ(0x34, irsend.capture.address); + EXPECT_EQ(0x4A90FC6C, irsend.capture.command); + EXPECT_FALSE(irsend.capture.repeat); +} diff --git a/lib/IRremoteESP8266/test/ir_Wowwee_test.cpp b/lib/IRremoteESP8266/test/ir_Wowwee_test.cpp new file mode 100644 index 0000000000..e74f61149e --- /dev/null +++ b/lib/IRremoteESP8266/test/ir_Wowwee_test.cpp @@ -0,0 +1,103 @@ +// Copyright 2022 David Conran + +#include "IRac.h" +#include "IRrecv.h" +#include "IRrecv_test.h" +#include "IRsend.h" +#include "IRsend_test.h" +#include "gtest/gtest.h" + +TEST(TestUtils, Housekeeping) { + ASSERT_EQ("WOWWEE", typeToString(decode_type_t::WOWWEE)); + ASSERT_EQ(decode_type_t::WOWWEE, strToDecodeType("WOWWEE")); + ASSERT_FALSE(hasACState(decode_type_t::WOWWEE)); + ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::WOWWEE)); + ASSERT_EQ(kWowweeBits, IRsend::defaultBits(decode_type_t::WOWWEE)); + ASSERT_EQ(kWowweeDefaultRepeat, IRsend::minRepeats(decode_type_t::WOWWEE)); +} + +// Tests for sendWowwee(). +// Test sending typical data only. +TEST(TestSendWowwee, SendDataOnly) { + IRsendTest irsend(kGpioUnused); + irsend.begin(); + + irsend.reset(); + irsend.sendWowwee(0x186); // Nikai TV Power Off. + EXPECT_EQ( + "f38000d33" + "m6684s723" + "m912s723m912s723m912s3259m912s3259m912s723m912s723m912s723m912s723" + "m912s3259m912s3259m912s723m912s100000", + irsend.outputStr()); + + irsend.reset(); +} + +// Tests for decodeWowwee(). + +// Decode normal Wowwee messages. +TEST(TestDecodeWowwee, RealDecode) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1938#issue-1513240242 + const uint16_t rawForward[25] = { + 6684, 740, 918, 724, 942, 724, 918, 3250, 870, 3268, 872, 770, 940, 690, + 942, 688, 942, 738, 942, 3250, 868, 3268, 872, 732, 918 + }; // UNKNOWN 7469BF81 + irsend.reset(); + irsend.sendRaw(rawForward, 25, 38); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::WOWWEE, irsend.capture.decode_type); + EXPECT_EQ(kWowweeBits, irsend.capture.bits); + EXPECT_EQ(0x186, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_EQ(0x0, irsend.capture.address); + + // Ref: https://github.com/crankyoldgit/IRremoteESP8266/issues/1938#issue-1513240242 + const uint16_t rawLeft[25] = { + 6630, 764, 868, 762, 892, 788, 866, 3324, 792, 3348, 818, 760, 866, 788, + 894, 772, 892, 750, 870, 786, 920, 750, 864, 776, 868 + }; // UNKNOWN 28A1120F + irsend.reset(); + irsend.sendRaw(rawLeft, 25, 38); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::WOWWEE, irsend.capture.decode_type); + EXPECT_EQ(kWowweeBits, irsend.capture.bits); + EXPECT_EQ(0x180, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_EQ(0x0, irsend.capture.address); +} + +// Decode normal repeated Wowwee messages. +TEST(TestDecodeWowwee, SyntheticDecode) { + IRsendTest irsend(kGpioUnused); + IRrecv irrecv(kGpioUnused); + irsend.begin(); + + // Normal Wowwee 11-bit message. + irsend.reset(); + irsend.sendWowwee(0x186); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::WOWWEE, irsend.capture.decode_type); + EXPECT_EQ(kWowweeBits, irsend.capture.bits); + EXPECT_EQ(0x186, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_EQ(0x0, irsend.capture.address); + + // Normal Wowwee 11-bit message. + irsend.reset(); + irsend.sendWowwee(0x180); + irsend.makeDecodeResult(); + ASSERT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(decode_type_t::WOWWEE, irsend.capture.decode_type); + EXPECT_EQ(kWowweeBits, irsend.capture.bits); + EXPECT_EQ(0x180, irsend.capture.value); + EXPECT_EQ(0x0, irsend.capture.command); + EXPECT_EQ(0x0, irsend.capture.address); +} diff --git a/lib/IRremoteESP8266/test/ir_York_test.cpp b/lib/IRremoteESP8266/test/ir_York_test.cpp new file mode 100644 index 0000000000..d8ec1c9d1f --- /dev/null +++ b/lib/IRremoteESP8266/test/ir_York_test.cpp @@ -0,0 +1,96 @@ +// Copyright 2023 Daniele Gobbetti + +#include "ir_York.h" +#include "IRac.h" +#include "IRrecv.h" +#include "IRrecv_test.h" +#include "IRsend.h" +#include "IRsend_test.h" +#include "gtest/gtest.h" + + +// General housekeeping +TEST(TestYork, Housekeeping) { + ASSERT_EQ("YORK", typeToString(decode_type_t::YORK)); + ASSERT_EQ(typeToString(decode_type_t::YORK), "YORK"); + ASSERT_TRUE(hasACState(YORK)); + ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::YORK)); + ASSERT_EQ(kYorkBits, IRsend::defaultBits(decode_type_t::YORK)); +} + +// Tests for sendYork(). +// Test sending typical data only. +TEST(TestSendYork, SendDataOnly) { + IRsendTest irsend(0); + irsend.begin(); + uint8_t data[kYorkStateLength] = { + 0x08, 0x10, 0x07, 0x02, 0x40, 0x08, + 0x03, 0x18, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, + 0xEC, 0xF5, 0xF2}; + irsend.reset(); + irsend.sendYork(data); + EXPECT_EQ( + "f38000d50" + "m4887s2267m612s579m612s579m612s579m612s1778m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s1778m612s579m612s579" + "m612s579m612s1778m612s1778m612s1778m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s1778m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s579m612s1778m612s579m612s579" + "m612s579m612s579m612s1778m612s579m612s579m612s579m612s579m612s1778" + "m612s1778m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s1778m612s1778m612s579m612s579m612s579m612s1778m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s1778m612s1778m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579m612s579" + "m612s579m612s579m612s579m612s579m612s1778m612s1778m612s579m612s1778" + "m612s1778m612s1778m612s1778m612s579m612s1778m612s579m612s1778m612s1778" + "m612s1778m612s1778m612s579m612s1778m612s579m612s579m612s1778m612s1778" + "m612s1778m612s1778m612s100000", + irsend.outputStr()); + + irsend.reset(); +} + +// Decode normal York messages. +TEST(TestDecodeYork, SyntheticDecode) { + IRsendTest irsend(0); + IRrecv irrecv(0); + irsend.begin(); + + // Synthesised Normal York message. + irsend.reset(); + uint8_t kYorkKnownGoodState[kYorkStateLength] = { + 0x08, 0x10, 0x07, 0x02, 0x40, 0x08, + 0x03, 0x18, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, + 0xEC, 0xF5, 0xF2}; + irsend.sendYork(kYorkKnownGoodState); + irsend.makeDecodeResult(); + EXPECT_TRUE(irrecv.decode(&irsend.capture)); + EXPECT_EQ(YORK, irsend.capture.decode_type); + EXPECT_EQ(kYorkBits, irsend.capture.bits); + EXPECT_STATE_EQ(kYorkKnownGoodState, irsend.capture.state, + irsend.capture.bits); + EXPECT_EQ( + "Power: On, Mode: 1 (Heat), Fan: 8 (Auto), Temp: 24C, Swing(V): Off" + ", On Timer: 00:00, Off Timer: 00:00", + IRAcUtils::resultAcToString(&irsend.capture)); + stdAc::state_t r, p; + ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); +} + +// test checksum calculation +TEST(TestYorkClass, SetAndGetTemp) { + IRYorkAc ac(kGpioUnused); + EXPECT_NE(23, ac.getTemp()); // default state is 24 deegrees Celsius + ac.setTemp(23); + EXPECT_EQ(23, ac.getTemp()); + + uint8_t expectedState[kYorkStateLength] = { + 0x08, 0x10, 0x07, 0x02, 0x40, 0x08, + 0x03, 0x18, 0x01, 0x5C, 0x00, 0x00, 0x00, 0x00, + 0xEC, 0xA5, 0xF7}; + + EXPECT_STATE_EQ(expectedState, ac.getRaw(), kYorkBits); +} diff --git a/lib/IRremoteESP8266/test/ut_utils.h b/lib/IRremoteESP8266/test/ut_utils.h new file mode 100644 index 0000000000..a8d8c7d541 --- /dev/null +++ b/lib/IRremoteESP8266/test/ut_utils.h @@ -0,0 +1,35 @@ +// Copyright 2022 Mateusz Bronk + +#ifndef TEST_UT_UTILS_H_ +#define TEST_UT_UTILS_H_ + +#include +#include +#include +#include +#include + + +std::string bytesToHexString(const std::vector& value) { + std::ostringstream oss; + oss << std::hex << std::setfill('0'); + + std::for_each(std::begin(value), std::end(value), [&oss] (uint8_t i) { + oss << std::setw(2) << std::uppercase << static_cast(i); + }); + return oss.str(); +} + +std::vector hexStringToBytes(const std::string& hex) { + std::vector bytes; + bytes.reserve(hex.length() / 2); + + for (size_t i = 0; i < hex.length(); i += 2) { + std::string nextByte = hex.substr(i, 2); + uint8_t byte = static_cast(strtol(nextByte.c_str(), nullptr, 16)); + bytes.emplace_back(byte); + } + return bytes; +} + +#endif // TEST_UT_UTILS_H_ diff --git a/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md b/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md index 0c394e63b8..1e4e000b9f 100644 --- a/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md +++ b/lib/NeoPixelBus/.github/ISSUE_TEMPLATE/all-others.md @@ -8,8 +8,7 @@ assignees: '' --- ### STOP -If you are seeking support, then please use the Discussions feature or gitter channel by following one of these links. -[NeoPixelBus Discussions](https://github.com/Makuna/NeoPixelBus/discussions) -[NeoPixelBus Gitter Channel](https://gitter.im/Makuna/NeoPixelBus) +If you are seeking support, then please use the gitter channel by following this link. +[NeoPixelBus Gitter Channel](https://gitter.im/Makuna/NeoPixelBus) -If you submit issues that are not traceable bugs or feature requests, it will just get closed. +If you submit issues that are not traceable bugs or feature requests, it will get closed and you will be directed to the gitter channel. diff --git a/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino b/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino index 41ffdbac9f..9805ac451f 100644 --- a/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino +++ b/lib/NeoPixelBus/examples/ESP32/DotStarTest_Esp32DmaSpi/DotStarTest_Esp32DmaSpi.ino @@ -6,28 +6,10 @@ // There is serial output of the current state so you can confirm and follow along // -// -// ESP32 SPI Buses and up to how many bits they support: -// ESP32: Spi1 (4 bit) | Spi2 (4 bit) | Spi3 (4 bit) -// ESP32-S2: | Spi2 (8 bit) | Spi3 -// ESP32-S3: | Spi2 (8 bit) | Spi3 (4 bit) -// ESP32-C3: | Spi2 (4 bit) | -// -// If a DotStarEsp32DmaSpi method is used without specifying the bus number -// then Spi2 will be used by default -// -// In this demo if an alternate SPI bus is chosen then Spi3 will be used - #include #define USE_DEFAULT_SPI_PORT 1 - -// C3 only has a single Spi bus -#if CONFIG_IDF_TARGET_ESP32C3 -#define USE_ALTERNATE_SPI_PORT 0 -#else #define USE_ALTERNATE_SPI_PORT 1 -#endif #if (USE_DEFAULT_SPI_PORT == 1) const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure @@ -44,7 +26,7 @@ //NeoPixelBus strip(PixelCount, DotClockPin, DotDataPin); // for hardware SPI (best performance) with default SPI peripheral - NeoPixelBus strip(PixelCount); + NeoPixelBus strip(PixelCount); // DotStarEsp32DmaVspiMethod defaults to 10MHz clock speed. For other speeds, replace "DotStarSpiMethod" with another method specifying speed, e.g. "DotStarSpi2MhzMethod" (see wiki for more details) // See DotStarTest_Esp32Advanced example for how to set clock speed at runtime @@ -62,14 +44,14 @@ const int8_t DotChipSelectPin2 = -1; // -1 means the chip select signal won't be output, freeing up one pin compared to useSpiAlternatePins2=false // for hardware SPI (best performance) with alternate SPI peripheral - NeoPixelBus strip2(PixelCount2); + NeoPixelBus strip2(PixelCount2); // DotStarEsp32DmaHspiMethod defaults to 10MHz clock speed. For other speeds, replace "DotStarSpiMethod" with another method specifying speed, e.g. "DotStarHspi2MhzMethod" (see wiki for more details) #endif #define colorSaturation 128 -// Note that both DotStarEsp32DmaSpiMethod and DotStarEsp32DmaSpi1Method can be used with DotStarLbgrFeature and DotStarWbgrFeature but to keep things simple those are excluded from this example, see DotStarTest for more details +// Note that both DotStarEsp32DmaVspiMethod and DotStarEsp32DmaHspiMethod can be used with DotStarLbgrFeature and DotStarWbgrFeature but to keep things simple those are excluded from this example, see DotStarTest for more details RgbColor red(colorSaturation, 0, 0); RgbColor green(0, colorSaturation, 0); diff --git a/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino b/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino deleted file mode 100644 index 72d558232a..0000000000 --- a/lib/NeoPixelBus/examples/ESP32/NeoPixel_ESP32_I2sParallel/NeoPixel_ESP32_I2sParallel.ino +++ /dev/null @@ -1,54 +0,0 @@ -// -// NeoPixel_ESP32_I2sParallel - -// This sketch demonstrates the use of the I2S Parallel method allowing upto 8 hardware updated channels -// This example only works on the ESP32 -// -// The key part of the method name is Esp32I2s1X8, -// E2p32 (platform specific method), -// I2s Channel 1 (most commonly available), -// X8 (8 parallel channel mode) -// -// In this example, it demonstrates different ColorFeatures, Method specification, and count per strip -// -#include - -// Demonstrating the use of the first four channels, but the method used allows for eight -NeoPixelBus strip1(120, 15); // note: older WS2811 and longer strip -NeoPixelBus strip2(100, 2); // note: modern WS2812 with letter like WS2812b -NeoPixelBus strip3(100, 4); // note: inverted -NeoPixelBus strip4(50, 16); // note: RGBW and Sk6812 and smaller strip - -void setup() { - Serial.begin(115200); - while (!Serial); // wait for serial attach - - Serial.println(); - Serial.println("Initializing..."); - Serial.flush(); - - // must call begin on all the strips - strip1.Begin(); - strip2.Begin(); - strip3.Begin(); - strip4.Begin(); - - Serial.println(); - Serial.println("Running..."); -} - -void loop() { - delay(1000); - - // draw on the strips - strip1.SetPixelColor(0, RgbColor(255, 0, 0)); // red - strip2.SetPixelColor(0, RgbColor(0, 127, 0)); // green - strip3.SetPixelColor(0, RgbColor(0, 0, 53)); // blue - strip4.SetPixelColor(0, RgbwColor(0, 0, 128, 255)); // white channel with a little blue - - // show them, - // only on the last show, no matter the order, will the data be sent - strip1.Show(); - strip2.Show(); - strip3.Show(); - strip4.Show(); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino b/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino new file mode 100644 index 0000000000..01af6cb3a4 --- /dev/null +++ b/lib/NeoPixelBus/examples/NeoPixelBrightness/NeoPixelBrightness.ino @@ -0,0 +1,83 @@ +// NeoPixelBrightness +// This example will cycle brightness from high to low of +// three pixels colored Red, Green, Blue. +// This demonstrates the use of the NeoPixelBrightnessBus +// with integrated brightness support +// +// There is serial output of the current state so you can +// confirm and follow along +// + +#include // instead of NeoPixelBus.h + +const uint16_t PixelCount = 3; // this example assumes 3 pixels, making it smaller will cause a failure +const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266 + +#define colorSaturation 255 // saturation of color constants +RgbColor red(colorSaturation, 0, 0); +RgbColor green(0, colorSaturation, 0); +RgbColor blue(0, 0, colorSaturation); + +// Make sure to provide the correct color order feature +// for your NeoPixels +NeoPixelBrightnessBus strip(PixelCount, PixelPin); + +// you loose the original color the lower the dim value used +// here due to quantization +const uint8_t c_MinBrightness = 8; +const uint8_t c_MaxBrightness = 255; + +int8_t direction; // current direction of dimming + +void setup() +{ + Serial.begin(115200); + while (!Serial); // wait for serial attach + + Serial.println(); + Serial.println("Initializing..."); + Serial.flush(); + + // this resets all the neopixels to an off state + strip.Begin(); + strip.Show(); + + direction = -1; // default to dim first + + Serial.println(); + Serial.println("Running..."); + + // set our three original colors + strip.SetPixelColor(0, red); + strip.SetPixelColor(1, green); + strip.SetPixelColor(2, blue); + + strip.Show(); +} + + +void loop() +{ + uint8_t brightness = strip.GetBrightness(); + Serial.println(brightness); + + delay(100); + + // swap diection of dim when limits are reached + // + if (direction < 0 && brightness <= c_MinBrightness) + { + direction = 1; + } + else if (direction > 0 && brightness >= c_MaxBrightness) + { + direction = -1; + } + // apply dimming + brightness += direction; + strip.SetBrightness(brightness); + + // show the results + strip.Show(); +} + diff --git a/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino b/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino deleted file mode 100644 index 55240cfbf2..0000000000 --- a/lib/NeoPixelBus/examples/NeoPixelBusLg/NeoPixelBusLg.ino +++ /dev/null @@ -1,108 +0,0 @@ -// NeoPixelBusLg -// -// This example demonstrates the use of the NeoPixelBusLg -// with integrated luminance and gamma support -// -// There is serial output of the current state so you can -// confirm and follow along -// - -#include // instead of NeoPixelBus.h - -const uint16_t PixelCount = 96; // set to the number of pixels in your strip -const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266 - -RgbColor red(255, 0, 0); -RgbColor green(0, 255, 0); -RgbColor blue(0, 0, 255); -RgbColor black(0, 0, 0); -RgbColor white(255, 255, 255); - -// Make sure to provide the correct color order feature -// for your NeoPixels -NeoPixelBusLg strip(PixelCount, PixelPin); - -// If speed is an issue and memory is not, then you can use the gamma table variant -// which is much faster but uses 256 bytes of RAM -// NeoPixelBusLg strip(PixelCount, PixelPin); - -// If you want to turn gamma correction off, then you can use the null gamma method -// NeoPixelBusLg strip(PixelCount, PixelPin); - -// If you use a LED driver between the NeoPixel chip and the LEDs that require the PWM range inverted -// NeoPixelBusLg> strip(PixelCount, PixelPin); - -void setup() -{ - Serial.begin(115200); - while (!Serial); // wait for serial attach - - Serial.println(); - Serial.println("Initializing..."); - Serial.flush(); - - // this resets all the neopixels to an off state - strip.Begin(); - strip.SetLuminance(128); // (0-255) - initially at half brightness - strip.Show(); - - Serial.println(); - Serial.println("Running..."); -} - -void loop() -{ - static const uint8_t c_MinBrightness = 0; - static const uint8_t c_MaxBrightness = 255; - - static int8_t direction = -1; // start with dimming - - uint8_t luminance = strip.GetLuminance(); - - Serial.print(direction); - Serial.print(" "); - Serial.println(luminance); - - delay(200); - - // swap direction of luminance when limits are reached - // - if (direction < 0 && luminance <= c_MinBrightness) - { - direction = 1; - } - else if (direction > 0 && luminance >= c_MaxBrightness) - { - direction = -1; - } - else - { - luminance += direction; - } - - strip.SetLuminance(luminance); - - // draw something - // - uint16_t half = strip.PixelCount() / 2; - DrawGradient(green, black, 0, half - 1); - DrawGradient(black, red, half, strip.PixelCount() - 1); - - // show the results - strip.Show(); -} - -void DrawGradient(RgbColor startColor, - RgbColor finishColor, - uint16_t startIndex, - uint16_t finishIndex) -{ - uint16_t delta = finishIndex - startIndex; - - for (uint16_t index = startIndex; index < finishIndex; index++) - { - float progress = static_cast(index - startIndex) / delta; - RgbColor color = RgbColor::LinearBlend(startColor, finishColor, progress); - strip.SetPixelColor(index, color); - } -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino b/lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino similarity index 93% rename from lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino rename to lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino index 4c859c92d5..3ed91524ef 100644 --- a/lib/NeoPixelBus/examples/gamma/NeoPixelGamma/NeoPixelGamma.ino +++ b/lib/NeoPixelBus/examples/NeoPixelGamma/NeoPixelGamma.ino @@ -1,5 +1,5 @@ // NeoPixelGamma -// This example will display a timed series of color gradients with gamma correction +// This example will display a timed series of color gradiants with gamma correction // and then without. // If the last pixel is on, then the colors being shown are color corrected. // It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and @@ -15,9 +15,9 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); // uncomment only one of these to compare memory use or speed // diff --git a/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino b/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino index dd63558f30..415c8538ce 100644 --- a/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino +++ b/lib/NeoPixelBus/examples/NeoPixelTest/NeoPixelTest.ino @@ -8,7 +8,7 @@ // NOTE: You will need to make sure to pick the one for your platform // // -// There is serial output of the current state so you can confirm and follow along. +// There is serial output of the current state so you can confirm and follow along // #include @@ -19,35 +19,35 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore #define colorSaturation 128 // three element pixels, in different order and speeds -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); //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. -// For details see wiki linked here https://github.com/Makuna/NeoPixelBus/wiki/ESP8266-NeoMethods. +// 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. +// each having their own restrictions // -// These two are the same as above as the DMA method is the default. -// NOTE: These will ignore the PIN and use GPI03 pin. -//NeoPixelBus strip(PixelCount, PixelPin); +// These two are the same as above as the DMA method is the default +// NOTE: These will ignore the PIN and use GPI03 pin +//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); +// 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); -// The bitbang method is really only good if you are not using WiFi features of the ESP. -// It works with all but pin 16. -//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 +//NeoPixelBus strip(PixelCount, PixelPin); //NeoPixelBus strip(PixelCount, PixelPin); // four element pixels, RGBW -//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); RgbColor red(colorSaturation, 0, 0); RgbColor green(0, colorSaturation, 0); diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino b/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino index 04c24b2be7..fc3a372f90 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelAnimation/NeoPixelAnimation.ino @@ -25,7 +25,7 @@ const uint16_t PixelCount = 4; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino b/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino index 15b36d0b8e..4eec443d47 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelCylon/NeoPixelCylon.ino @@ -14,9 +14,9 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 const RgbColor CylonEyeColor(HtmlColor(0x7f0000)); -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(2); // only ever need 2 animations diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino index ac18de5f0b..f6c065c2cf 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino @@ -12,7 +12,7 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 const uint8_t AnimationChannels = 1; // we only need one as all the pixels are animated at once -NeoPixelBus strip(PixelCount, PixelPin); +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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino index 30a0e20272..c8a7788ded 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunLoop/NeoPixelFunLoop.ino @@ -25,7 +25,7 @@ const uint16_t NextPixelMoveDuration = 1000 / PixelCount; // how fast we move th NeoGamma colorGamma; // for any fade animations, best to correct gamma -NeoPixelBus strip(PixelCount, PixelPin); +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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino b/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino index 89e8347a78..8e88667758 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino @@ -10,7 +10,7 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 -NeoPixelBus strip(PixelCount, PixelPin); +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. diff --git a/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino b/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino index b796091c02..bdc9af70c9 100644 --- a/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino +++ b/lib/NeoPixelBus/examples/animations/NeoPixelRotateLoop/NeoPixelRotateLoop.ino @@ -18,9 +18,9 @@ const float MaxLightness = 0.4f; // max lightness at the head of the tail (0.5f NeoGamma colorGamma; // for any fade animations, best to correct gamma -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino index 34111e83d8..56071b2b15 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino @@ -23,9 +23,9 @@ const uint16_t PixelCount = 144; // the sample images are meant for 144 pixels const uint16_t PixelPin = 2; const uint16_t AnimCount = 1; // we only need one -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object // our NeoBitmapFile will use the same color feature as NeoPixelBus and diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino index 1ba86644d6..34b97f2a65 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferCylon/NeoPixelBufferCylon.ino @@ -22,9 +22,9 @@ const uint16_t PixelCount = 16; // the sample images are meant for 16 pixels const uint16_t PixelPin = 2; const uint16_t AnimCount = 1; // we only need one -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object // sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino index a435167f2d..c2c8e74b24 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelBufferShader/NeoPixelBufferShader.ino @@ -9,7 +9,7 @@ const uint16_t PixelCount = 64; // set this to the size of your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 // three element GRB pixels, change to your needs -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // the buffer object, // defined to use memory with the same feature as the strip @@ -47,7 +47,7 @@ public: // required for a shader object, it will be called for // every pixel - void Apply(uint16_t index, uint8_t* pDest, const uint8_t* pSrc) + void Apply(uint16_t index, uint8_t* pDest, uint8_t* pSrc) { // we don't care what the index is so we ignore it // diff --git a/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino b/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino index 4988aecd73..1a13c135c1 100644 --- a/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino +++ b/lib/NeoPixelBus/examples/bitmaps/NeoPixelDibTest/NeoPixelDibTest.ino @@ -9,7 +9,7 @@ const uint16_t PixelCount = 64; // set this to the size of your strip const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 // three element GRB pixels, change to your needs -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // the DIB object, using RgbColor and initialized with the same number of pixels as our strip NeoDib image(PixelCount); diff --git a/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino b/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino deleted file mode 100644 index 977d6780eb..0000000000 --- a/lib/NeoPixelBus/examples/gamma/NeoPixelGammaDynamic/NeoPixelGammaDynamic.ino +++ /dev/null @@ -1,103 +0,0 @@ -// NeoPixelGammaDynamic -// This example will display a timed series of color gradients with gamma correction -// and then without. -// If the last pixel is on, then the colors being shown are color corrected. -// It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and -// then repeat. -// -// This will demonstrate the use of the NeoGamma class with the -// NeoGammaDynamicTableMethod being used for a custom gamma table -// -// - -#include -#include - -const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip -const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 - -// for esp8266 the pin is ignored unless it is the bitbang method -NeoPixelBus strip(PixelCount, PixelPin); - -NeoGamma colorGamma; - -void DrawPixels(bool corrected, HslColor startColor, HslColor stopColor) -{ - for (uint16_t index = 0; index < strip.PixelCount() - 1; index++) - { - float progress = index / static_cast(strip.PixelCount() - 2); - RgbColor color = HslColor::LinearBlend(startColor, stopColor, progress); - if (corrected) - { - color = colorGamma.Correct(color); - } - strip.SetPixelColor(index, color); - } - - // use the last pixel to indicate if we are showing corrected colors or not - if (corrected) - { - strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(64)); - } - else - { - strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(0)); - } - - strip.Show(); -} - - -float GammaCalc(float unitValue) -{ - // we will use CieLab gamma equation for our custom table - return NeoEase::GammaCieLab(unitValue); -} - -void setup() -{ - // initialize the internal gamma table using our GammaCalc function - // if you plan on using 16bit element colors, add a second optional arg as `true` - NeoGammaDynamicTableMethod::Initialize(GammaCalc); // , true); - - strip.Begin(); - strip.Show(); -} - -void loop() -{ - HslColor startColor; - HslColor stopColor; - - // red color - startColor = HslColor(0.0f, 1.0f, 0.0f); - stopColor = HslColor(0.0f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // green color - startColor = HslColor(0.33f, 1.0f, 0.0f); - stopColor = HslColor(0.33f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // blue color - startColor = HslColor(0.66f, 1.0f, 0.0f); - stopColor = HslColor(0.66f, 1.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); - - // white color - startColor = HslColor(0.0f, 0.0f, 0.0f); - stopColor = HslColor(0.0f, 0.0f, 0.5f); - DrawPixels(true, startColor, stopColor); - delay(5000); - DrawPixels(false, startColor, stopColor); - delay(5000); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino index 4854b00af4..6b70b6f427 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicDump/NeoPixelMosaicDump.ino @@ -41,13 +41,10 @@ NeoMosaic mosaic( void DumpMosaic() { - int16_t totalWidth = static_cast(mosaic.getWidth()); - int16_t totalHeight = static_cast(mosaic.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -55,19 +52,19 @@ void DumpMosaic() Serial.println(); Serial.print("\t---"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < mosaic.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < mosaic.getWidth(); x++) { NeoTopologyHint hint = mosaic.TopologyHint(x, y); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino index 700a1bfed3..2f6500c9f0 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelMosaicTest/NeoPixelMosaicTest.ino @@ -35,9 +35,9 @@ NeoMosaic mosaic( TileWidth, TileHeight); -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino index 6e4753a11a..57aa6e4b82 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelRingDynamicTopologyTest/NeoPixelRingDynamicTopologyTest.ino @@ -63,7 +63,7 @@ NeoRingTopology topo; // declare our strip // -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // define some handy colors // diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino index 47922a7f3b..26d526fd7e 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelRingTopologyTest/NeoPixelRingTopologyTest.ino @@ -47,7 +47,7 @@ NeoRingTopology topo; // declare our strip // -NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); // define some handy colors // diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino index c95a0d2f44..2849c56197 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesDump/NeoPixelTilesDump.ino @@ -45,13 +45,10 @@ NeoTiles tiles( void DumpTopo() { - int16_t totalWidth = static_cast(tiles.getWidth()); - int16_t totalHeight = static_cast(tiles.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -59,19 +56,19 @@ void DumpTopo() Serial.println(); Serial.print("\t---"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < tiles.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < tiles.getWidth(); x++) { NeoTopologyHint hint = tiles.TopologyHint(x, y); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino index f86e603b49..1dfc645169 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTilesTest/NeoPixelTilesTest.ino @@ -39,11 +39,11 @@ NeoTiles tiles( TileWidth, TileHeight); -NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino index d0e5548f88..aa78a25399 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyDump/NeoPixelTopologyDump.ino @@ -31,13 +31,10 @@ NeoTopology topo(PanelWidth, PanelHeight); void DumpTopo() { - int16_t totalWidth = static_cast(topo.getWidth()); - int16_t totalHeight = static_cast(topo.getHeight()); - Serial.println(); Serial.print("\t\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print(x); Serial.print("\t"); @@ -45,19 +42,19 @@ void DumpTopo() Serial.println(); Serial.print("\t--"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print("--------"); } Serial.println(); - for (int16_t y = 0; y < totalHeight; y++) + for (int y = 0; y < topo.getHeight(); y++) { Serial.print(" "); Serial.print(y); Serial.print("\t|\t"); - for (int16_t x = 0; x < totalWidth; x++) + for (int x = 0; x < topo.getWidth(); x++) { Serial.print(topo.Map(x, y)); Serial.print("\t"); diff --git a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino index 6ff0628683..2071abb348 100644 --- a/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino +++ b/lib/NeoPixelBus/examples/topologies/NeoPixelTopologyTest/NeoPixelTopologyTest.ino @@ -28,11 +28,11 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore NeoTopology topo(PanelWidth, PanelHeight); -NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); -//NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); +//NeoPixelBus strip(PixelCount, PixelPin); // for esp8266 omit the pin -//NeoPixelBus strip(PixelCount); +//NeoPixelBus strip(PixelCount); RgbColor red(128, 0, 0); RgbColor green(0, 128, 0); diff --git a/lib/NeoPixelBus/keywords.txt b/lib/NeoPixelBus/keywords.txt index 7fce1f1256..03f59e82cd 100644 --- a/lib/NeoPixelBus/keywords.txt +++ b/lib/NeoPixelBus/keywords.txt @@ -7,24 +7,17 @@ ####################################### NeoPixelBus KEYWORD1 -NeoPixelBusLg KEYWORD1 NeoPixelSegmentBus KEYWORD1 RgbwColor KEYWORD1 RgbColor KEYWORD1 Rgb16Color KEYWORD1 Rgb48Color KEYWORD1 -Rgbw64Color KEYWORD1 -RgbwwColor KEYWORD1 HslColor KEYWORD1 HsbColor KEYWORD1 HtmlColor KEYWORD1 NeoNoSettings KEYWORD1 NeoTm1814Settings KEYWORD1 NeoTm1914Settings KEYWORD1 -NeoSm16803pbSettings KEYWORD1 -NeoSm16823eSettings KEYWORD1 -NeoSm16804ebSettings KEYWORD1 -NeoSm16824eSettings KEYWORD1 NeoSpiSettings KEYWORD1 NeoGrbFeature KEYWORD1 NeoGrbwFeature KEYWORD1 @@ -32,21 +25,9 @@ NeoRgbwFeature KEYWORD1 NeoRgbFeature KEYWORD1 NeoBrgFeature KEYWORD1 NeoRbgFeature KEYWORD1 -NeoBgrFeature KEYWORD1 -NeoRgbw64Feature KEYWORD1 -NeoRgb48Feature KEYWORD1 -NeoGrb48Feature KEYWORD1 -NeoGrbcwxFeature KEYWORD1 -NeoRgbUcs8903Feature KEYWORD1 -NeoRgbwUcs8904Feature KEYWORD1 -NeoGrb48Ws2816Feature KEYWORD1 NeoWrgbTm1814Feature KEYWORD1 NeoRgbTm1914Feature KEYWORD1 NeoGrbTm1914Feature KEYWORD1 -NeoRgbSm16803pbFeature KEYWORD1 -NeoRgbSm16823eFeature KEYWORD1 -NeoRgbwSm16804ebFeature KEYWORD1 -NeoRgbwSm16824eFeature KEYWORD1 DotStarBgrFeature KEYWORD1 DotStarLbgrFeature KEYWORD1 Lpd6803GrbFeature KEYWORD1 @@ -63,7 +44,6 @@ NeoWs2813Method KEYWORD1 NeoWs2812xMethod KEYWORD1 NeoWs2812Method KEYWORD1 NeoWs2811Method KEYWORD1 -NeoWs2816Method KEYWORD1 NeoSk6812Method KEYWORD1 NeoTm1814Method KEYWORD1 NeoTm1914Method KEYWORD1 @@ -71,14 +51,12 @@ NeoTm1829Method KEYWORD1 NeoTx1812Method KEYWORD1 NeoLc8812Method KEYWORD1 NeoApa106Method KEYWORD1 -NeoIntertekMethod KEYWORD1 Neo800KbpsInvertedMethod KEYWORD1 Neo400KbpsInvertedMethod KEYWORD1 NeoWs2813InvertedMethod KEYWORD1 NeoWs2812xInvertedMethod KEYWORD1 NeoWs2812InvertedMethod KEYWORD1 NeoWs2811InvertedMethod KEYWORD1 -NeoWs2816InvertedMethod KEYWORD1 NeoSk6812InvertedMethod KEYWORD1 NeoTm1814InvertedMethod KEYWORD1 NeoTm1914InvertedMethod KEYWORD1 @@ -86,9 +64,7 @@ NeoTm1829InvertedMethod KEYWORD1 NeoTx1812InvertedMethod KEYWORD1 NeoLc8812InvertedMethod KEYWORD1 NeoApa106InvertedMethod KEYWORD1 -NeoInvertedIntertekMethod KEYWORD1 NeoEsp8266DmaWs2812xMethod KEYWORD1 -NeoEsp8266DmaWs2816Method KEYWORD1 NeoEsp8266DmaSk6812Method KEYWORD1 NeoEsp8266DmaTm1814Method KEYWORD1 NeoEsp8266DmaTm1914Method KEYWORD1 @@ -97,7 +73,6 @@ NeoEsp8266DmaApa106Method KEYWORD1 NeoEsp8266Dma800KbpsMethod KEYWORD1 NeoEsp8266Dma400KbpsMethod KEYWORD1 NeoEsp8266DmaInvertedWs2812xMethod KEYWORD1 -NeoEsp8266DmaInvertedWs2816Method KEYWORD1 NeoEsp8266DmaInvertedSk6812Method KEYWORD1 NeoEsp8266DmaInvertedTm1814Method KEYWORD1 NeoEsp8266DmaInvertedTm1914Method KEYWORD1 @@ -105,15 +80,10 @@ NeoEsp8266DmaInvertedTm1829Method KEYWORD1 NeoEsp8266DmaInvertedApa106Method KEYWORD1 NeoEsp8266DmaInverted800KbpsMethod KEYWORD1 NeoEsp8266DmaInverted400KbpsMethod KEYWORD1 -NeoEsp8266Dmx512Method KEYWORD1 -NeoEsp8266Ws2821Method KEYWORD1 -NeoEsp8266Dmx512InvertedMethod KEYWORD1 -NeoEsp8266Ws2821InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2813Method KEYWORD1 NeoEsp8266Uart0Ws2812xMethod KEYWORD1 NeoEsp8266Uart0Ws2812Method KEYWORD1 NeoEsp8266Uart0Ws2811Method KEYWORD1 -NeoEsp8266Uart0Ws2816Method KEYWORD1 NeoEsp8266Uart0Sk6812Method KEYWORD1 NeoEsp8266Uart0Tm1814Method KEYWORD1 NeoEsp8266Uart0Tm1914Method KEYWORD1 @@ -126,7 +96,6 @@ NeoEsp8266AsyncUart0Ws2813Method KEYWORD1 NeoEsp8266AsyncUart0Ws2812xMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812Method KEYWORD1 NeoEsp8266AsyncUart0Ws2811Method KEYWORD1 -NeoEsp8266AsyncUart0Ws2816Method KEYWORD1 NeoEsp8266AsyncUart0Sk6812Method KEYWORD1 NeoEsp8266AsyncUart0Tm1814Method KEYWORD1 NeoEsp8266AsyncUart0Tm1914Method KEYWORD1 @@ -139,7 +108,6 @@ NeoEsp8266Uart1Ws2813Method KEYWORD1 NeoEsp8266Uart1Ws2812xMethod KEYWORD1 NeoEsp8266Uart1Ws2812Method KEYWORD1 NeoEsp8266Uart1Ws2811Method KEYWORD1 -NeoEsp8266Uart1Ws2816Method KEYWORD1 NeoEsp8266Uart1Sk6812Method KEYWORD1 NeoEsp8266Uart1Tm1814 KEYWORD1 NeoEsp8266Uart1Tm1914 KEYWORD1 @@ -152,7 +120,6 @@ NeoEsp8266AsyncUart1Ws2813Method KEYWORD1 NeoEsp8266AsyncUart1Ws2812xMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812Method KEYWORD1 NeoEsp8266AsyncUart1Ws2811Method KEYWORD1 -NeoEsp8266AsyncUart1Ws2816Method KEYWORD1 NeoEsp8266AsyncUart1Sk6812Method KEYWORD1 NeoEsp8266AsyncUart1Tm1814 KEYWORD1 NeoEsp8266AsyncUart1Tm1914 KEYWORD1 @@ -165,7 +132,6 @@ NeoEsp8266Uart0Ws2813InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2812xInvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2812InvertedMethod KEYWORD1 NeoEsp8266Uart0Ws2811InvertedMethod KEYWORD1 -NeoEsp8266Uart0Ws2816InvertedMethod KEYWORD1 NeoEsp8266Uart0Sk6812InvertedMethod KEYWORD1 NeoEsp8266Uart0Tm1814InvertedMethod KEYWORD1 NeoEsp8266Uart0Tm1914InvertedMethod KEYWORD1 @@ -178,7 +144,6 @@ NeoEsp8266AsyncUart0Ws2813InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812xInvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Ws2811InvertedMethod KEYWORD1 -NeoEsp8266AsyncUart0Ws2816InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Sk6812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Tm1814InvertedMethod KEYWORD1 NeoEsp8266AsyncUart0Tm1914InvertedMethod KEYWORD1 @@ -191,7 +156,6 @@ NeoEsp8266Uart1Ws2813InvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2812xInvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2812InvertedMethod KEYWORD1 NeoEsp8266Uart1Ws2811InvertedMethod KEYWORD1 -NeoEsp8266Uart1Ws2816InvertedMethod KEYWORD1 NeoEsp8266Uart1Sk6812InvertedMethod KEYWORD1 NeoEsp8266Uart1Tm1814InvertedMethod KEYWORD1 NeoEsp8266Uart1Tm1914InvertedMethod KEYWORD1 @@ -204,7 +168,6 @@ NeoEsp8266AsyncUart1Ws2813InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812xInvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Ws2811InvertedMethod KEYWORD1 -NeoEsp8266AsyncUart1Ws2816InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Sk6812InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Tm1814InvertedMethod KEYWORD1 NeoEsp8266AsyncUart1Tm1914InvertedMethod KEYWORD1 @@ -217,7 +180,6 @@ NeoEsp8266BitBangWs2813Method KEYWORD1 NeoEsp8266BitBangWs2812xMethod KEYWORD1 NeoEsp8266BitBangWs2812Method KEYWORD1 NeoEsp8266BitBangWs2811Method KEYWORD1 -NeoEsp8266BitBangWs2816Method KEYWORD1 NeoEsp8266BitBangSk6812Method KEYWORD1 NeoEsp8266BitBangTm1814Method KEYWORD1 NeoEsp8266BitBangTm1914Method KEYWORD1 @@ -230,7 +192,6 @@ NeoEsp8266BitBangWs2813InvertedMethod KEYWORD1 NeoEsp8266BitBangWs2812xInvertedMethod KEYWORD1 NeoEsp8266BitBangWs2812InvertedMethod KEYWORD1 NeoEsp8266BitBangWs2811InvertedMethod KEYWORD1 -NeoEsp8266BitBangWs2816InvertedMethod KEYWORD1 NeoEsp8266BitBangSk6812InvertedMethod KEYWORD1 NeoEsp8266BitBangTm1814InvertedMethod KEYWORD1 NeoEsp8266BitBangTm1914InvertedMethod KEYWORD1 @@ -240,7 +201,6 @@ NeoEsp8266BitBangApa106InvertedMethod KEYWORD1 NeoEsp8266BitBang800KbpsInvertedMethod KEYWORD1 NeoEsp8266BitBang400KbpsInvertedMethod KEYWORD1 NeoEsp32I2sNWs2812xMethod KEYWORD1 -NeoEsp32I2sNWs2816Method KEYWORD1 NeoEsp32I2sNSk6812Method KEYWORD1 NeoEsp32I2sNTm1814Method KEYWORD1 NeoEsp32I2sNTm1914Method KEYWORD1 @@ -248,7 +208,6 @@ NeoEsp32I2sN800KbpsMethod KEYWORD1 NeoEsp32I2sN400KbpsMethod KEYWORD1 NeoEsp32I2sNApa106Method KEYWORD1 NeoEsp32I2s0Ws2812xMethod KEYWORD1 -NeoEsp32I2s0Ws2816Method KEYWORD1 NeoEsp32I2s0Sk6812Method KEYWORD1 NeoEsp32I2s0Tm1814Method KEYWORD1 NeoEsp32I2s0Tm1914Method KEYWORD1 @@ -257,7 +216,6 @@ NeoEsp32I2s0800KbpsMethod KEYWORD1 NeoEsp32I2s0400KbpsMethod KEYWORD1 NeoEsp32I2s0Apa106Method KEYWORD1 NeoEsp32I2s1Ws2812xMethod KEYWORD1 -NeoEsp32I2s1Ws2816Method KEYWORD1 NeoEsp32I2s1Sk6812Method KEYWORD1 NeoEsp32I2s1Tm1814Method KEYWORD1 NeoEsp32I2s1Tm1914Method KEYWORD1 @@ -266,7 +224,6 @@ NeoEsp32I2s1800KbpsMethod KEYWORD1 NeoEsp32I2s1400KbpsMethod KEYWORD1 NeoEsp32I2s1Apa106Method KEYWORD1 NeoEsp32I2sNWs2812xInvertedMethod KEYWORD1 -NeoEsp32I2sNWs2816InvertedMethod KEYWORD1 NeoEsp32I2sNSk6812InvertedMethod KEYWORD1 NeoEsp32I2sNTm1814InvertedMethod KEYWORD1 NeoEsp32I2sNTm1914InvertedMethod KEYWORD1 @@ -274,7 +231,6 @@ NeoEsp32I2sN800KbpsInvertedMethod KEYWORD1 NeoEsp32I2sN400KbpsInvertedMethod KEYWORD1 NeoEsp32I2sNApa106InvertedMethod KEYWORD1 NeoEsp32I2s0Ws2812xInvertedMethod KEYWORD1 -NeoEsp32I2s0Ws2816InvertedMethod KEYWORD1 NeoEsp32I2s0Sk6812InvertedMethod KEYWORD1 NeoEsp32I2s0Tm1814InvertedMethod KEYWORD1 NeoEsp32I2s0Tm1914InvertedMethod KEYWORD1 @@ -283,7 +239,6 @@ NeoEsp32I2s0800KbpsInvertedMethod KEYWORD1 NeoEsp32I2s0400KbpsInvertedMethod KEYWORD1 NeoEsp32I2s0Apa106InvertedMethod KEYWORD1 NeoEsp32I2s1Ws2812xInvertedMethod KEYWORD1 -NeoEsp32I2s1Ws2816InvertedMethod KEYWORD1 NeoEsp32I2s1Sk6812InvertedMethod KEYWORD1 NeoEsp32I2s1Tm1814InvertedMethod KEYWORD1 NeoEsp32I2s1Tm1914InvertedMethod KEYWORD1 @@ -291,65 +246,8 @@ NeoEsp32I2s1Tm1829InvertedMethod KEYWORD1 NeoEsp32I2s1800KbpsInvertedMethod KEYWORD1 NeoEsp32I2s1400KbpsInvertedMethod KEYWORD1 NeoEsp32I2s1Apa106InvertedMethod KEYWORD1 -NeoEsp32I2s0X8Ws2812xMethod KEYWORD1 -NeoEsp32I2s0X8800KbpsMethod KEYWORD1 -NeoEsp32I2s0X8400KbpsMethod KEYWORD1 -NeoEsp32I2s0X8Ws2813Method KEYWORD1 -NeoEsp32I2s0X8Ws2812dMethod KEYWORD1 -NeoEsp32I2s0X8Ws2811Method KEYWORD1 -NeoEsp32I2s0X8Ws2816Method KEYWORD1 -NeoEsp32I2s0X8Ws2812Method KEYWORD1 -NeoEsp32I2s0X8Sk6812Method KEYWORD1 -NeoEsp32I2s0X8Tm1814Method KEYWORD1 -NeoEsp32I2s0X8Tm1829Method KEYWORD1 -NeoEsp32I2s0X8Tm1914Method KEYWORD1 -NeoEsp32I2s0X8Lc8812Method KEYWORD1 -NeoEsp32I2s0X8Apa106Method KEYWORD1 -NeoEsp32I2s0X16Ws2812xMethod KEYWORD1 -NeoEsp32I2s0X16800KbpsMethod KEYWORD1 -NeoEsp32I2s0X16400KbpsMethod KEYWORD1 -NeoEsp32I2s0X16Ws2813Method KEYWORD1 -NeoEsp32I2s0X16Ws2812dMethod KEYWORD1 -NeoEsp32I2s0X16Ws2811Method KEYWORD1 -NeoEsp32I2s0X16Ws2816Method KEYWORD1 -NeoEsp32I2s0X16Ws2812Method KEYWORD1 -NeoEsp32I2s0X16Sk6812Method KEYWORD1 -NeoEsp32I2s0X16Tm1814Method KEYWORD1 -NeoEsp32I2s0X16Tm1829Method KEYWORD1 -NeoEsp32I2s0X16Tm1914Method KEYWORD1 -NeoEsp32I2s0X16Lc8812Method KEYWORD1 -NeoEsp32I2s0X16Apa106Method KEYWORD1 -NeoEsp32I2s1X8Ws2812xMethod KEYWORD1 -NeoEsp32I2s1X8800KbpsMethod KEYWORD1 -NeoEsp32I2s1X8400KbpsMethod KEYWORD1 -NeoEsp32I2s1X8Ws2813Method KEYWORD1 -NeoEsp32I2s1X8Ws2812dMethod KEYWORD1 -NeoEsp32I2s1X8Ws2811Method KEYWORD1 -NeoEsp32I2s1X8Ws2816Method KEYWORD1 -NeoEsp32I2s1X8Ws2812Method KEYWORD1 -NeoEsp32I2s1X8Sk6812Method KEYWORD1 -NeoEsp32I2s1X8Tm1814Method KEYWORD1 -NeoEsp32I2s1X8Tm1829Method KEYWORD1 -NeoEsp32I2s1X8Tm1914Method KEYWORD1 -NeoEsp32I2s1X8Lc8812Method KEYWORD1 -NeoEsp32I2s1X8Apa106Method KEYWORD1 -NeoEsp32I2s1X16Ws2812xMethod KEYWORD1 -NeoEsp32I2s1X16800KbpsMethod KEYWORD1 -NeoEsp32I2s1X16400KbpsMethod KEYWORD1 -NeoEsp32I2s1X16Ws2813Method KEYWORD1 -NeoEsp32I2s1X16Ws2812dMethod KEYWORD1 -NeoEsp32I2s1X16Ws2811Method KEYWORD1 -NeoEsp32I2s1X16Ws2816Method KEYWORD1 -NeoEsp32I2s1X16Ws2812Method KEYWORD1 -NeoEsp32I2s1X16Sk6812Method KEYWORD1 -NeoEsp32I2s1X16Tm1814Method KEYWORD1 -NeoEsp32I2s1X16Tm1829Method KEYWORD1 -NeoEsp32I2s1X16Tm1914Method KEYWORD1 -NeoEsp32I2s1X16Lc8812Method KEYWORD1 -NeoEsp32I2s1X16Apa106Method KEYWORD1 NeoEsp32RmtNWs2811Method KEYWORD1 NeoEsp32RmtNWs2812xMethod KEYWORD1 -NeoEsp32RmtNWs2816Method KEYWORD1 NeoEsp32RmtNSk6812Method KEYWORD1 NeoEsp32RmtNTm1814Method KEYWORD1 NeoEsp32RmtNTm1914Method KEYWORD1 @@ -359,7 +257,6 @@ NeoEsp32RmtN800KbpsMethod KEYWORD1 NeoEsp32RmtN400KbpsMethod KEYWORD1 NeoEsp32Rmt0Ws2811Method KEYWORD1 NeoEsp32Rmt0Ws2812xMethod KEYWORD1 -NeoEsp32Rmt0Ws2816Method KEYWORD1 NeoEsp32Rmt0Sk6812Method KEYWORD1 NeoEsp32Rmt0Tm1814Method KEYWORD1 NeoEsp32Rmt0Tm1914Method KEYWORD1 @@ -369,7 +266,6 @@ NeoEsp32Rmt0800KbpsMethod KEYWORD1 NeoEsp32Rmt0400KbpsMethod KEYWORD1 NeoEsp32Rmt1Ws2811Method KEYWORD1 NeoEsp32Rmt1Ws2812xMethod KEYWORD1 -NeoEsp32Rmt1Ws2816Method KEYWORD1 NeoEsp32Rmt1Sk6812Method KEYWORD1 NeoEsp32Rmt1Tm1814Method KEYWORD1 NeoEsp32Rmt1Tm1914Method KEYWORD1 @@ -379,7 +275,6 @@ NeoEsp32Rmt1800KbpsMethod KEYWORD1 NeoEsp32Rmt1400KbpsMethod KEYWORD1 NeoEsp32Rmt2Ws2811Method KEYWORD1 NeoEsp32Rmt2Ws2812xMethod KEYWORD1 -NeoEsp32Rmt2Ws2816Method KEYWORD1 NeoEsp32Rmt2Sk6812Method KEYWORD1 NeoEsp32Rmt2Tm1814Method KEYWORD1 NeoEsp32Rmt2Tm1829Method KEYWORD1 @@ -389,7 +284,6 @@ NeoEsp32Rmt2800KbpsMethod KEYWORD1 NeoEsp32Rmt2400KbpsMethod KEYWORD1 NeoEsp32Rmt3Ws2811Method KEYWORD1 NeoEsp32Rmt3Ws2812xMethod KEYWORD1 -NeoEsp32Rmt3Ws2816Method KEYWORD1 NeoEsp32Rmt3Sk6812Method KEYWORD1 NeoEsp32Rmt3Tm1814Method KEYWORD1 NeoEsp32Rmt3Tm1914Method KEYWORD1 @@ -399,7 +293,6 @@ NeoEsp32Rmt3800KbpsMethod KEYWORD1 NeoEsp32Rmt3400KbpsMethod KEYWORD1 NeoEsp32Rmt4Ws2811Method KEYWORD1 NeoEsp32Rmt4Ws2812xMethod KEYWORD1 -NeoEsp32Rmt4Ws2816Method KEYWORD1 NeoEsp32Rmt4Sk6812Method KEYWORD1 NeoEsp32Rmt4Tm1814Method KEYWORD1 NeoEsp32Rmt4Tm1914Method KEYWORD1 @@ -409,7 +302,6 @@ NeoEsp32Rmt4800KbpsMethod KEYWORD1 NeoEsp32Rmt4400KbpsMethod KEYWORD1 NeoEsp32Rmt5Ws2811Method KEYWORD1 NeoEsp32Rmt5Ws2812xMethod KEYWORD1 -NeoEsp32Rmt5Ws2816Method KEYWORD1 NeoEsp32Rmt5Sk6812Method KEYWORD1 NeoEsp32Rmt5Tm1814Method KEYWORD1 NeoEsp32Rmt5Tm1914Method KEYWORD1 @@ -419,7 +311,6 @@ NeoEsp32Rmt5800KbpsMethod KEYWORD1 NeoEsp32Rmt5400KbpsMethod KEYWORD1 NeoEsp32Rmt6Ws2811Method KEYWORD1 NeoEsp32Rmt6Ws2812xMethod KEYWORD1 -NeoEsp32Rmt6Ws2816Method KEYWORD1 NeoEsp32Rmt6Sk6812Method KEYWORD1 NeoEsp32Rmt6Tm1814Method KEYWORD1 NeoEsp32Rmt6Tm1914Method KEYWORD1 @@ -429,7 +320,6 @@ NeoEsp32Rmt6800KbpsMethod KEYWORD1 NeoEsp32Rmt6400KbpsMethod KEYWORD1 NeoEsp32Rmt7Ws2811Method KEYWORD1 NeoEsp32Rmt7Ws2812xMethod KEYWORD1 -NeoEsp32Rmt7Ws2816Method KEYWORD1 NeoEsp32Rmt7Sk6812Method KEYWORD1 NeoEsp32Rmt7Tm1814Method KEYWORD1 NeoEsp32Rmt7Tm1914Method KEYWORD1 @@ -439,7 +329,6 @@ NeoEsp32Rmt7800KbpsMethod KEYWORD1 NeoEsp32Rmt7400KbpsMethod KEYWORD1 NeoEsp32RmtNWs2811InvertedMethod KEYWORD1 NeoEsp32RmtNWs2812xInvertedMethod KEYWORD1 -NeoEsp32RmtNWs2816InvertedMethod KEYWORD1 NeoEsp32RmtNSk6812InvertedMethod KEYWORD1 NeoEsp32RmtNTm1814InvertedMethod KEYWORD1 NeoEsp32RmtNTm1914InvertedMethod KEYWORD1 @@ -449,7 +338,6 @@ NeoEsp32RmtN800KbpsInvertedMethod KEYWORD1 NeoEsp32RmtN400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt0Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt0Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt0Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt0Tm1914InvertedMethod KEYWORD1 @@ -459,7 +347,6 @@ NeoEsp32Rmt0800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt0400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt1Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt1Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt1Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt1Tm1914InvertedMethod KEYWORD1 @@ -469,7 +356,6 @@ NeoEsp32Rmt1800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt2Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt2Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt2Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt2Tm1914InvertedMethod KEYWORD1 @@ -479,7 +365,6 @@ NeoEsp32Rmt2800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt3Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt3Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt3Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt3Tm1914InvertedMethod KEYWORD1 @@ -489,7 +374,6 @@ NeoEsp32Rmt3800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt4Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt4Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt4Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt4Tm1914InvertedMethod KEYWORD1 @@ -499,7 +383,6 @@ NeoEsp32Rmt4800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt5Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt5Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt5Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt5Tm1914InvertedMethod KEYWORD1 @@ -509,7 +392,6 @@ NeoEsp32Rmt5800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt6Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt6Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt6Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt6Tm1914InvertedMethod KEYWORD1 @@ -519,7 +401,6 @@ NeoEsp32Rmt6800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2812xInvertedMethod KEYWORD1 -NeoEsp32Rmt7Ws2816InvertedMethod KEYWORD1 NeoEsp32Rmt7Sk6812InvertedMethod KEYWORD1 NeoEsp32Rmt7Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt7Tm1914InvertedMethod KEYWORD1 @@ -531,7 +412,6 @@ NeoEsp32BitBangWs2813Method KEYWORD1 NeoEsp32BitBangWs2812xMethod KEYWORD1 NeoEsp32BitBangWs2812Method KEYWORD1 NeoEsp32BitBangWs2811Method KEYWORD1 -NeoEsp32BitBangWs2816Method KEYWORD1 NeoEsp32BitBangSk6812Method KEYWORD1 NeoEsp32BitBangTm1814Method KEYWORD1 NeoEsp32BitBangTm1914Method KEYWORD1 @@ -544,7 +424,6 @@ NeoEsp32BitBangWs2813InvertedMethod KEYWORD1 NeoEsp32BitBangWs2812xInvertedMethod KEYWORD1 NeoEsp32BitBangWs2812InvertedMethod KEYWORD1 NeoEsp32BitBangWs2811InvertedMethod KEYWORD1 -NeoEsp32BitBangWs2816InvertedMethod KEYWORD1 NeoEsp32BitBangSk6812InvertedMethod KEYWORD1 NeoEsp32BitBangTm1814InvertedMethod KEYWORD1 NeoEsp32BitBangTm1914InvertedMethod KEYWORD1 @@ -554,7 +433,6 @@ NeoEsp32BitBangApa106InvertedMethod KEYWORD1 NeoEsp32BitBang800KbpsInvertedMethod KEYWORD1 NeoEsp32BitBang400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmNWs2812xMethod KEYWORD1 -NeoNrf52xPwmNWs2816Method KEYWORD1 NeoNrf52xPwmNSk6812Method KEYWORD1 NeoNrf52xPwmNTm1814Method KEYWORD1 NeoNrf52xPwmNTm1914Method KEYWORD1 @@ -564,7 +442,6 @@ NeoNrf52xPwmN800KbpsMethod KEYWORD1 NeoNrf52xPwmN400KbpsMethod KEYWORD1 NeoNrf52xPwmNApa106Method KEYWORD1 NeoNrf52xPwm0Ws2812xMethod KEYWORD1 -NeoNrf52xPwm0Ws2816Method KEYWORD1 NeoNrf52xPwm0Sk6812Method KEYWORD1 NeoNrf52xPwm0Tm1814Method KEYWORD1 NeoNrf52xPwm0Tm1914Method KEYWORD1 @@ -574,7 +451,6 @@ NeoNrf52xPwm0800KbpsMethod KEYWORD1 NeoNrf52xPwm0400KbpsMethod KEYWORD1 NeoNrf52xPwm0Apa106Method KEYWORD1 NeoNrf52xPwm1Ws2812xMethod KEYWORD1 -NeoNrf52xPwm1Ws2816Method KEYWORD1 NeoNrf52xPwm1Sk6812Method KEYWORD1 NeoNrf52xPwm1Tm1814Method KEYWORD1 NeoNrf52xPwm1Tm1914Method KEYWORD1 @@ -584,7 +460,6 @@ NeoNrf52xPwm1800KbpsMethod KEYWORD1 NeoNrf52xPwm1400KbpsMethod KEYWORD1 NeoNrf52xPwm1Apa106Method KEYWORD1 NeoNrf52xPwm2Ws2812xMethod KEYWORD1 -NeoNrf52xPwm2Ws2816Method KEYWORD1 NeoNrf52xPwm2Sk6812Method KEYWORD1 NeoNrf52xPwm2Tm1814Method KEYWORD1 NeoNrf52xPwm2Tm1914Method KEYWORD1 @@ -594,7 +469,6 @@ NeoNrf52xPwm2800KbpsMethod KEYWORD1 NeoNrf52xPwm2400KbpsMethod KEYWORD1 NeoNrf52xPwm2Apa106Method KEYWORD1 NeoNrf52xPwm3Ws2812xMethod KEYWORD1 -NeoNrf52xPwm3Ws2816Method KEYWORD1 NeoNrf52xPwm3Sk6812Method KEYWORD1 NeoNrf52xPwm3Tm1814Method KEYWORD1 NeoNrf52xPwm3Tm1914Method KEYWORD1 @@ -604,7 +478,6 @@ NeoNrf52xPwm3800KbpsMethod KEYWORD1 NeoNrf52xPwm3400KbpsMethod KEYWORD1 NeoNrf52xPwm3Apa106Method KEYWORD1 NeoNrf52xPwmNWs2812xInvertedMethod KEYWORD1 -NeoNrf52xPwmNWs2816InvertedMethod KEYWORD1 NeoNrf52xPwmNSk6812InvertedMethod KEYWORD1 NeoNrf52xPwmNTm1814InvertedMethod KEYWORD1 NeoNrf52xPwmNTm1914InvertedMethod KEYWORD1 @@ -614,7 +487,6 @@ NeoNrf52xPwmN800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmN400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwmNApa106InvertedMethod KEYWORD1 NeoNrf52xPwm0Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm0Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm0Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm0Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm0Tm1914InvertedMethod KEYWORD1 @@ -624,7 +496,6 @@ NeoNrf52xPwm0800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm0400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm0Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm1Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm1Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm1Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm1Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm1Tm1914InvertedMethod KEYWORD1 @@ -634,7 +505,6 @@ NeoNrf52xPwm1800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm1400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm1Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm2Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm2Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm2Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm2Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm2Tm1914InvertedMethod KEYWORD1 @@ -644,7 +514,6 @@ NeoNrf52xPwm2800KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm2400KbpsInvertedMethod KEYWORD1 NeoNrf52xPwm2Apa106InvertedMethod KEYWORD1 NeoNrf52xPwm3Ws2812xInvertedMethod KEYWORD1 -NeoNrf52xPwm3Ws2816InvertedMethod KEYWORD1 NeoNrf52xPwm3Sk6812InvertedMethod KEYWORD1 NeoNrf52xPwm3Tm1814InvertedMethod KEYWORD1 NeoNrf52xPwm3Tm1914InvertedMethod KEYWORD1 @@ -661,14 +530,14 @@ DotStarSpi2MhzMethod KEYWORD1 DotStarSpi1MhzMethod KEYWORD1 DotStarSpi500KhzMethod KEYWORD1 DotStarSpiHzMethod KEYWORD1 -Ws2801Method KEYWORD1 -Ws2801SpiMethod KEYWORD1 -Ws2801Spi20MhzMethod KEYWORD1 -Ws2801Spi10MhzMethod KEYWORD1 -Ws2801Spi2MhzMethod KEYWORD1 -Ws2801Spi1MhzMethod KEYWORD1 -Ws2801Spi500KhzMethod KEYWORD1 -Ws2801SpiHzMethod KEYWORD1 +NeoWs2801Method KEYWORD1 +NeoWs2801SpiMethod KEYWORD1 +NeoWs2801Spi20MhzMethod KEYWORD1 +NeoWs2801Spi10MhzMethod KEYWORD1 +NeoWs2801Spi2MhzMethod KEYWORD1 +NeoWs2801Spi1MhzMethod KEYWORD1 +NeoWs2801Spi500KhzMethod KEYWORD1 +NeoWs2801SpiHzMethod KEYWORD1 Lpd6803SpiMethod KEYWORD1 Lpd6803Method KEYWORD1 Lpd6803Spi20MhzMethod KEYWORD1 @@ -693,15 +562,6 @@ P9813Spi2MhzMethod KEYWORD1 P9813Spi1MhzMethod KEYWORD1 P9813Spi500KhzMethod KEYWORD1 P9813SpiHzMethod KEYWORD1 -Tlc5947Method KEYWORD1 -Tlc5947Method16Bit KEYWORD1 -Tlc5947Spi30MhzMethod KEYWORD1 -Tlc5947Spi30MhzMethod16Bit KEYWORD1 -Tlc5947Spi15MhzMethod KEYWORD1 -Tlc5947Spi15MhzMethod16Bit KEYWORD1 -Tlc5947SpiMethod KEYWORD1 -Tlc5947SpiMethod16Bit KEYWORD1 -Sm16716Method KEYWORD1 NeoPixelAnimator KEYWORD1 AnimUpdateCallback KEYWORD1 AnimationParam KEYWORD1 @@ -727,7 +587,6 @@ NeoTopology KEYWORD1 NeoRingTopology KEYWORD1 NeoTiles KEYWORD1 NeoMosaic KEYWORD1 -NeoGammaCieLabEquationMethod KEYWORD1 NeoGammaEquationMethod KEYWORD1 NeoGammaTableMethod KEYWORD1 NeoGamma KEYWORD1 @@ -767,9 +626,6 @@ PixelCount KEYWORD2 SetPixelColor KEYWORD2 GetPixelColor KEYWORD2 SwapPixelColor KEYWORD2 -SetLuminance KEYWORD2 -GetLuminance KEYWORD2 -ApplyPostAdjustments KEYWORD2 SetString KEYWORD2 CalculateBrightness KEYWORD2 Dim KEYWORD2 @@ -823,7 +679,6 @@ CircularOut KEYWORD2 CircularInOut KEYWORD2 CircularCenter KEYWORD2 Gamma KEYWORD2 -GammaCieLab KEYWORD2 Map KEYWORD2 MapProbe KEYWORD2 getWidth KEYWORD2 diff --git a/lib/NeoPixelBus/library.json b/lib/NeoPixelBus/library.json index 638e27dfb7..306e6e0942 100644 --- a/lib/NeoPixelBus/library.json +++ b/lib/NeoPixelBus/library.json @@ -1,13 +1,13 @@ { "name": "NeoPixelBus", - "keywords": "NeoPixel, WS2811, WS2812, WS2813, WS2821, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, LPD6803, P9813, TM1829, TM1814, TM1914, TX1812, WS2801, SM16803, SM16823, SM16804, SM16824, SM16716, DMX512, RGB, RGBW", - "description": "A library that makes controlling NeoPixels (WS2812x and many others) and DotStars (SK6812 and many others) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes separate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For all platforms; there are two methods of sending DotStar data, hardware SPI and software SPI.", + "keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, LPD6803, P9813, TM1829, TM1814, TM1914, TX1812, WS2801 RGB, RGBW", + "description": "A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813, SK6812, TM1829, TM1814, TM1914, TX1812) and DotStars (APA102, LPD8806, LPD6803, SK9822, WS2801, P9813) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes seperate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. 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.7.6", + "version": "2.6.7", "frameworks": "arduino", "platforms": "*", "dependencies": [ diff --git a/lib/NeoPixelBus/library.properties b/lib/NeoPixelBus/library.properties index 7bfa7171b9..35c9faea15 100644 --- a/lib/NeoPixelBus/library.properties +++ b/lib/NeoPixelBus/library.properties @@ -1,9 +1,9 @@ name=NeoPixelBus by Makuna -version=2.7.6 +version=2.6.7 author=Michael C. Miller (makuna@live.com) maintainer=Michael C. Miller (makuna@live.com) -sentence=A library that makes controlling NeoPixels (WS2812x and many others) and DotStars (SK6812 and many others) easy. -paragraph=Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes separate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For all platforms; there are two methods of sending DotStar data, hardware SPI and software SPI. +sentence=A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813, SK6812, TM1829, TM1814, TM1914, TX1812) and DotStars (APA102, LPD8806, LPD6803, SK9822, WS2801, P9813) easy. +paragraph=Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels and 7 Segment LED direct driven. Includes seperate RgbColor, RgbwColor, Rgb16Color, Rgb48Color, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. 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=* +architectures=* \ No newline at end of file diff --git a/lib/NeoPixelBus/src/NeoPixelAnimator.h b/lib/NeoPixelBus/src/NeoPixelAnimator.h index b16816477c..d990599a47 100644 --- a/lib/NeoPixelBus/src/NeoPixelAnimator.h +++ b/lib/NeoPixelBus/src/NeoPixelAnimator.h @@ -27,7 +27,7 @@ License along with NeoPixel. If not, see #pragma once #include -#include "internal/animations/NeoEase.h" +#include "internal/NeoEase.h" enum AnimationState { diff --git a/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h b/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h index 15527b9670..e110fdfc24 100644 --- a/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h +++ b/lib/NeoPixelBus/src/NeoPixelBrightnessBus.h @@ -28,18 +28,13 @@ License along with NeoPixel. If not, see #include "NeoPixelBus.h" -// FIXME 2023-08-09 tonhuisman: Disabled deprecation warning as the newer classes won't properly work with ESP8266 for ESPEasy P128 -template class /*[[deprecated("Use NeoPixelBusLg instead.")]]*/ NeoPixelBrightnessBus : +template class NeoPixelBrightnessBus : public NeoPixelBus { private: void ScaleColor(uint16_t scale, typename T_COLOR_FEATURE::ColorObject* color) { - // This is the similiar as calling Dim on the color object - // there is an assumption that all color elements are byte aligned - // so if any future color object gets introduced that is not it will - // cause a problem uint8_t* ptr = (uint8_t*)color; uint8_t* ptrEnd = ptr + sizeof(typename T_COLOR_FEATURE::ColorObject); @@ -52,17 +47,12 @@ template class /*[[deprecated("Use void ConvertColor(typename T_COLOR_FEATURE::ColorObject* color) { - // This is the same as calling Dim on the color object uint16_t scale = _brightness + 1; ScaleColor(scale, color); } void RecoverColor(typename T_COLOR_FEATURE::ColorObject* color) const { - // this is the same as calling Brighton on the color object - // there is an assumption that all color elements are byte aligned - // so if any future color object gets introduced that is not it will - // cause a problem uint8_t* ptr = (uint8_t*)color; uint8_t* ptrEnd = ptr + sizeof(typename T_COLOR_FEATURE::ColorObject); uint16_t scale = _brightness + 1; @@ -93,12 +83,6 @@ template class /*[[deprecated("Use { } - NeoPixelBrightnessBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - NeoPixelBus(countPixels, pinClock, pinData, pinLatch, pinOutputEnable), - _brightness(255) - { - } - NeoPixelBrightnessBus(uint16_t countPixels) : NeoPixelBus(countPixels), _brightness(255) diff --git a/lib/NeoPixelBus/src/NeoPixelBus.h b/lib/NeoPixelBus/src/NeoPixelBus.h index bf6344fd6a..d810e2a94b 100644 --- a/lib/NeoPixelBus/src/NeoPixelBus.h +++ b/lib/NeoPixelBus/src/NeoPixelBus.h @@ -27,20 +27,108 @@ License along with NeoPixel. If not, see #include -// standard neo definitions -// -const uint8_t NEO_DIRTY = 0x80; // a change was made to pixel data that requires a show -const uint16_t PixelIndex_OutOfBounds = 0xffff; +// some platforms do not come with STL or properly defined one, specifically functional +// if you see... +// undefined reference to `std::__throw_bad_function_call()' +// ...then you can either add the platform symbol to the list so NEOPIXEBUS_NO_STL gets defined or +// go to boards.txt and enable c++ by adding (teensy31.build.flags.libs=-lstdc++) and set to "smallest code" option in Arduino +// +#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(STM32L432xx) || defined(STM32L476xx) || defined(ARDUINO_ARCH_SAM) +#define NEOPIXEBUS_NO_STL 1 +#endif + +// some platforms do not define this standard progmem type for some reason +// +#ifndef PGM_VOID_P +#define PGM_VOID_P const void * +#endif + +// '_state' flags for internal state +#define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show + +#include "internal/NeoHueBlend.h" -#include "internal/NeoUtil.h" -#include "internal/animations/NeoEase.h" #include "internal/NeoSettings.h" -#include "internal/NeoColors.h" + +#include "internal/RgbColor.h" +#include "internal/Rgb16Color.h" +#include "internal/Rgb48Color.h" + +#include "internal/HslColor.h" +#include "internal/HsbColor.h" +#include "internal/HtmlColor.h" + +#include "internal/RgbwColor.h" +#include "internal/SegmentDigit.h" + #include "internal/NeoColorFeatures.h" -#include "internal/NeoTopologies.h" -#include "internal/NeoBuffers.h" +#include "internal/NeoTm1814ColorFeatures.h" +#include "internal/NeoTm1914ColorFeatures.h" +#include "internal/DotStarColorFeatures.h" +#include "internal/Lpd8806ColorFeatures.h" +#include "internal/Lpd6803ColorFeatures.h" +#include "internal/P9813ColorFeatures.h" +#include "internal/NeoSegmentFeatures.h" + +#include "internal/Layouts.h" +#include "internal/NeoTopology.h" +#include "internal/NeoRingTopology.h" +#include "internal/NeoTiles.h" +#include "internal/NeoMosaic.h" + +#include "internal/NeoBufferContext.h" +#include "internal/NeoBufferMethods.h" +#include "internal/NeoBuffer.h" +#include "internal/NeoSpriteSheet.h" +#include "internal/NeoDib.h" +#include "internal/NeoBitmapFile.h" + +#include "internal/NeoEase.h" +#include "internal/NeoGamma.h" + #include "internal/NeoBusChannel.h" -#include "internal/NeoMethods.h" + +#include "internal/DotStarGenericMethod.h" +#include "internal/Lpd8806GenericMethod.h" +#include "internal/Lpd6803GenericMethod.h" +#include "internal/Ws2801GenericMethod.h" +#include "internal/P9813GenericMethod.h" + +#if defined(ARDUINO_ARCH_ESP8266) + +#include "internal/NeoEsp8266DmaMethod.h" +#include "internal/NeoEsp8266UartMethod.h" +#include "internal/NeoEspBitBangMethod.h" + +#elif defined(ARDUINO_ARCH_ESP32) +#if ESP_IDF_VERSION_MAJOR < 5 +#include "internal/NeoEsp32I2sMethod.h" +#include "internal/NeoEsp32RmtMethod.h" +#else +#if !defined(CONFIG_IDF_TARGET_ESP32C2) +#include "internal/NeoEsp32RmtMethod_idf5.h" // every other SOC +#else //CONFIG_IDF_TARGET_ESP32C2 +#include "internal/NeoEsp32SpiMethod_idf5.h" // ESP32C2 +#endif //CONFIG_IDF_TARGET_ESP32C2 +#endif // ESP_IDF_VERSION_MAJOR +#include "internal/NeoEspBitBangMethod.h" +#include "internal/DotStarEsp32DmaSpiMethod.h" + +#elif defined(ARDUINO_ARCH_NRF52840) // must be before __arm__ + +#include "internal/NeoNrf52xMethod.h" + +#elif defined(__arm__) // must be before ARDUINO_ARCH_AVR due to Teensy incorrectly having it set + +#include "internal/NeoArmMethod.h" + +#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) + +#include "internal/NeoAvrMethod.h" + +#else +#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus" +#endif template class NeoPixelBus @@ -70,13 +158,6 @@ template class NeoPixelBus { } - NeoPixelBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - _countPixels(countPixels), - _state(0), - _method(pinClock, pinData, pinLatch, pinOutputEnable, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize) - { - } - NeoPixelBus(uint16_t countPixels) : _countPixels(countPixels), _state(0), @@ -114,16 +195,9 @@ template class NeoPixelBus ClearTo(0); } - // used by DotStarEsp32DmaSpiMethod if pins can be configured - reordered and extended version supporting oct SPI - void Begin(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t dat4, int8_t dat5, int8_t dat6, int8_t dat7, int8_t ss) - { - _method.Initialize(sck, dat0, dat1, dat2, dat3, dat4, dat5, dat6, dat7, ss); - ClearTo(0); - } - void Show(bool maintainBufferConsistency = true) { - if (!IsDirty() && !_method.AlwaysUpdate()) + if (!IsDirty()) { return; } @@ -317,7 +391,7 @@ template class NeoPixelBus void SetPixelSettings(const typename T_COLOR_FEATURE::SettingsObject& settings) { - T_COLOR_FEATURE::applySettings(_method.getData(), _method.getDataSize(), settings); + T_COLOR_FEATURE::applySettings(_method.getData(), settings); Dirty(); }; @@ -349,13 +423,13 @@ template class NeoPixelBus uint8_t* _pixels() { // get pixels data within the data stream - return T_COLOR_FEATURE::pixels(_method.getData(), _method.getDataSize()); + return T_COLOR_FEATURE::pixels(_method.getData()); } const uint8_t* _pixels() const { // get pixels data within the data stream - return T_COLOR_FEATURE::pixels(_method.getData(), _method.getDataSize()); + return T_COLOR_FEATURE::pixels(_method.getData()); } void _rotateLeft(uint16_t rotationCount, uint16_t first, uint16_t last) diff --git a/lib/NeoPixelBus/src/NeoPixelBusLg.h b/lib/NeoPixelBus/src/NeoPixelBusLg.h deleted file mode 100644 index 9afaeee601..0000000000 --- a/lib/NeoPixelBus/src/NeoPixelBusLg.h +++ /dev/null @@ -1,197 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixelBus library wrapper template class that provides luminance and gamma control - -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 - -#include "NeoPixelBus.h" - -// -// -// T_GAMMA - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// NeoGammaInvert - -template class NeoPixelBusLg : - public NeoPixelBus -{ -public: - class LuminanceShader - { - public: - LuminanceShader(uint8_t luminance = 255) : - _luminance(luminance) - { - } - - // our shader is always dirty, but these are needed for standard - // shader support - bool IsDirty() const - { - return true; - }; - - void Dirty() - { - }; - - void ResetDirty() - { - }; - - typename T_COLOR_FEATURE::ColorObject Apply(uint16_t, const typename T_COLOR_FEATURE::ColorObject& original) - { - // dim and then return gamma adjusted - typename T_COLOR_FEATURE::ColorObject color = original.Dim(_luminance); - return NeoGamma::Correct(color); - } - - protected: - uint8_t _luminance; - - bool setLuminance(uint8_t luminance) - { - bool different = (_luminance != luminance); - - if (different) - { - _luminance = luminance; - } - - return different; - } - - uint8_t getLuminance() const - { - return _luminance; - } - - friend class NeoPixelBusLg; - }; - - // Exposed Shader instance for use with NeoDib.Render like - // - // image.Render(strip, strip.Shader); - // where MyBusType is defined like - // typedef NeoPixelBusLg MyBusType; - // - LuminanceShader Shader; - -public: - NeoPixelBusLg(uint16_t countPixels, uint8_t pin) : - NeoPixelBus(countPixels, pin), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pin, NeoBusChannel channel) : - NeoPixelBus(countPixels, pin, channel), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pinClock, uint8_t pinData) : - NeoPixelBus(countPixels, pinClock, pinData), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels, uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable = NOT_A_PIN) : - NeoPixelBus(countPixels, pinClock, pinData, pinLatch, pinOutputEnable), - Shader() - { - } - - NeoPixelBusLg(uint16_t countPixels) : - NeoPixelBus(countPixels), - Shader() - { - } - - ~NeoPixelBusLg() - { - } - - void SetLuminance(uint8_t luminance) - { - // does NOT affect current pixel data as there is no safe way - // to reconstruct the original color values after being - // modified with both luminance and gamma without storing them - if (Shader.setLuminance(luminance)) - { - this->Dirty(); - } - } - - uint8_t GetLuminance() const - { - return Shader.getLuminance(); - } - - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) - { - color = Shader.Apply(indexPixel, color); - NeoPixelBus::SetPixelColor(indexPixel, color); - } - - /* - GetPixelColor is not overloaded as the original will be used - to just return the fully adjusted color value directly with - no reverse conversion since it is fraught with inaccuracy - */ - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) - { - color = Shader.Apply(0, color); - NeoPixelBus::ClearTo(color); - }; - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color, uint16_t first, uint16_t last) - { - color = Shader.Apply(0, color); - NeoPixelBus::ClearTo(color, first, last); - } - - // if the Pixels buffer is manipulated directly, then this can be called - // to apply the luminance and gamma correction to those changes - void ApplyPostAdjustments() - { - if (this->IsDirty()) - { - for (uint16_t indexPixel = 0; indexPixel < NeoPixelBus::PixelCount(); indexPixel++) - { - typename T_COLOR_FEATURE::ColorObject color = NeoPixelBus::GetPixelColor(indexPixel); - color = Shader.Apply(indexPixel, color); - NeoPixelBus::SetPixelColor(indexPixel, color); - } - this->Dirty(); - } - } -}; - - diff --git a/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h b/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h new file mode 100644 index 0000000000..e0b8575732 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/DotStarColorFeatures.h @@ -0,0 +1,698 @@ +/*------------------------------------------------------------------------- +DotStarColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStars + +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 + +class DotStar3Elements +{ +public: + static const size_t PixelSize = 4; // still requires 4 to be sent + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class DotStar4Elements +{ +public: + static const size_t PixelSize = 4; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbwColor ColorObject; +}; + + +class DotStar3ElementsNoSettings : public DotStar3Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class DotStar4ElementsNoSettings : public DotStar4Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class DotStarBgrFeature : public DotStar3ElementsNoSettings +{ +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.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.B = *p++; + color.G = *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); + + p++; // ignore the first byte + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLbgrFeature : public DotStar4ElementsNoSettings +{ +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.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.B = *p++; + color.G = *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.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarGrbFeature : public DotStar3ElementsNoSettings +{ +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.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.G = *p++; + color.R = *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); + + p++; // ignore the first byte + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class DotStarLgrbFeature : public DotStar4ElementsNoSettings +{ +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.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = (*p++) & 0x1F; // mask out upper three bits + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +/* RGB Feature -- Some APA102s ship in RGB order */ +class DotStarRgbFeature : public DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + (void)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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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 DotStar3ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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); + + 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 DotStar4ElementsNoSettings +{ +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(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const 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/src/internal/DotStarEsp32DmaSpiMethod.h b/lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h new file mode 100644 index 0000000000..953a216e74 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h @@ -0,0 +1,356 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for DotStars using Esp32, DMA and SPI (APA102). + +Written by Michael C. Miller. +DotStarEsp32DmaSpiMethod written by Louis Beaudoin (Pixelvation) + +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 + +#include "driver/spi_master.h" + +#if (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)) && !defined(HSPI_HOST) +// HSPI_HOST depreciated in C3 +#define HSPI_HOST SPI2_HOST +#endif + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32VspiBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 1; +}; +#endif + +class Esp32HspiBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 1; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32Vspi2BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 2; +}; +#endif + +class Esp32Hspi2BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 2; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +class Esp32Vspi4BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = VSPI_HOST; + const static int DmaChannel = 1; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 4; +}; +#endif + +class Esp32Hspi4BitBus +{ +public: + const static spi_host_device_t SpiHostDevice = HSPI_HOST; + const static int DmaChannel = 2; // arbitrary assignment, but based on the fact there are only two DMA channels and two available SPI ports, we need to split them somehow + const static int ParallelBits = 4; +}; + +template class DotStarEsp32DmaSpiMethod +{ +public: + typedef typename T_SPISPEED::SettingsObject SettingsObject; + + DotStarEsp32DmaSpiMethod(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizePixelData(pixelCount * elementSize + settingsSize), + _sizeEndFrame((pixelCount + 15) / 16) // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes) + { + _spiBufferSize = _sizeStartFrame + _sizePixelData + _sizeEndFrame; + + // must have a 4 byte aligned buffer for i2s + uint32_t alignment = _spiBufferSize % 4; + if (alignment) + { + _spiBufferSize += 4 - alignment; + } + + _data = static_cast(malloc(_spiBufferSize)); + _dmadata = static_cast(heap_caps_malloc(_spiBufferSize, MALLOC_CAP_DMA)); + + // data cleared later in NeoPixelBus::Begin() + } + + // Support constructor specifying pins by ignoring pins + DotStarEsp32DmaSpiMethod(uint8_t, uint8_t, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + DotStarEsp32DmaSpiMethod(pixelCount, elementSize, settingsSize) + { + } + + ~DotStarEsp32DmaSpiMethod() + { + if (_spiHandle) + { + deinitSpiDevice(); + esp_err_t ret = spi_bus_free(T_SPIBUS::SpiHostDevice); + ESP_ERROR_CHECK(ret); + } + free(_data); + free(_dmadata); + _spiHandle = NULL; + } + + bool IsReadyToUpdate() const + { + spi_transaction_t t; + spi_transaction_t * tptr = &t; + esp_err_t ret = spi_device_get_trans_result(_spiHandle, &tptr, 0); + + // We know the previous transaction completed if we got ESP_OK, and we know there's no transactions queued if tptr is unmodified + return (ret == ESP_OK || tptr == &t); + } + + void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t ss) + { + memset(_data, 0x00, _sizeStartFrame); + memset(_data + _sizeStartFrame + _sizePixelData, 0x00, _spiBufferSize - (_sizeStartFrame + _sizePixelData)); + + _ssPin = ss; + + esp_err_t ret; + spi_bus_config_t buscfg; + memset(&buscfg, 0x00, sizeof(buscfg)); + + buscfg.miso_io_num = dat1; + buscfg.mosi_io_num = dat0; + buscfg.sclk_io_num = sck; + buscfg.quadwp_io_num = dat2; + buscfg.quadhd_io_num = dat3; + buscfg.max_transfer_sz = _spiBufferSize; + + //Initialize the SPI bus + ret = spi_bus_initialize(T_SPIBUS::SpiHostDevice, &buscfg, T_SPIBUS::DmaChannel); + ESP_ERROR_CHECK(ret); + + initSpiDevice(); + } + + void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) + { + Initialize(sck, mosi, miso, -1, -1, ss); + } + + // If pins aren't specified, initialize bus with just the default SCK and MOSI pins for the SPI peripheral (no SS, no >1-bit pins) + void Initialize() + { +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) + if (T_SPIBUS::SpiHostDevice == VSPI_HOST) + { + Initialize(SCK, -1, MOSI, -1, -1, -1); + } + else + { + Initialize(14, -1, 13, -1, -1, -1); + } +#else + Initialize(SCK, -1, MOSI, -1, -1, -1); +#endif + } + + void Update(bool) + { + while(!IsReadyToUpdate()); + + memcpy(_dmadata, _data, _spiBufferSize); + + memset(&_spiTransaction, 0, sizeof(spi_transaction_t)); + _spiTransaction.length = (_spiBufferSize) * 8; // in bits not bytes! + if (T_SPIBUS::ParallelBits == 1) + { + _spiTransaction.flags = 0; + } + if (T_SPIBUS::ParallelBits == 2) + { + _spiTransaction.flags = SPI_TRANS_MODE_DIO; + } + if (T_SPIBUS::ParallelBits == 4) + { + _spiTransaction.flags = SPI_TRANS_MODE_QIO; + } + _spiTransaction.tx_buffer = _dmadata; + + esp_err_t ret = spi_device_queue_trans(_spiHandle, &_spiTransaction, 0); //Transmit! + assert(ret == ESP_OK); //Should have had no issues. + } + + uint8_t* getData() const + { + return _data + _sizeStartFrame; + }; + + size_t getDataSize() const + { + return _sizePixelData; + }; + + void applySettings(const SettingsObject& settings) + { + _speed.applySettings(settings); + if (_spiHandle) + { + deinitSpiDevice(); + initSpiDevice(); + } + } + +private: + void initSpiDevice() + { + spi_device_interface_config_t devcfg = {}; + + devcfg.clock_speed_hz = _speed.Clock; + devcfg.mode = 0; //SPI mode 0 + devcfg.spics_io_num = _ssPin; //CS pin + devcfg.queue_size = 1; + if (T_SPIBUS::ParallelBits == 1) + { + devcfg.flags = 0; + } + if (T_SPIBUS::ParallelBits >= 2) + { + devcfg.flags = SPI_DEVICE_HALFDUPLEX; + } + + //Allocate the LEDs on the SPI bus + esp_err_t ret = spi_bus_add_device(T_SPIBUS::SpiHostDevice, &devcfg, &_spiHandle); + ESP_ERROR_CHECK(ret); + } + + void deinitSpiDevice() + { + while(!IsReadyToUpdate()); + esp_err_t ret = spi_bus_remove_device(_spiHandle); + ESP_ERROR_CHECK(ret); + } + + const size_t _sizeStartFrame = 4; + const size_t _sizePixelData; // Size of '_data' buffer below, minus (_sizeStartFrame + _sizeEndFrame) + const size_t _sizeEndFrame; + + size_t _spiBufferSize; + uint8_t* _data; // Holds start/end frames and LED color values + uint8_t* _dmadata; // Holds start/end frames and LED color values + spi_device_handle_t _spiHandle = NULL; + spi_transaction_t _spiTransaction; + T_SPISPEED _speed; + int8_t _ssPin; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspiHzMethod; + +typedef DotStarEsp32DmaVspi10MhzMethod DotStarEsp32DmaVspiMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspiHzMethod; + +typedef DotStarEsp32DmaHspi10MhzMethod DotStarEsp32DmaHspiMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi2Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi2BitHzMethod; + +typedef DotStarEsp32DmaVspi2Bit10MhzMethod DotStarEsp32DmaVspi2BitMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi2Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi2BitHzMethod; + +typedef DotStarEsp32DmaHspi2Bit10MhzMethod DotStarEsp32DmaHspi2BitMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +// Clock Speed and Default Definitions for DotStarEsp32DmaVspi4Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaVspi4BitHzMethod; + +typedef DotStarEsp32DmaVspi4Bit10MhzMethod DotStarEsp32DmaVspi4BitMethod; +#endif + +// Clock Speed and Default Definitions for DotStarEsp32DmaHspi4Bit +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit40MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit20MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit10MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit5MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit2MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit1MhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4Bit500KhzMethod; +typedef DotStarEsp32DmaSpiMethod DotStarEsp32DmaHspi4BitHzMethod; + +typedef DotStarEsp32DmaHspi4Bit10MhzMethod DotStarEsp32DmaHspi4BitMethod; diff --git a/lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h b/lib/NeoPixelBus/src/internal/DotStarGenericMethod.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h rename to lib/NeoPixelBus/src/internal/DotStarGenericMethod.h index 591ec6d0fb..81a4527ec6 100644 --- a/lib/NeoPixelBus/src/internal/methods/DotStarGenericMethod.h +++ b/lib/NeoPixelBus/src/internal/DotStarGenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -106,12 +104,6 @@ template class DotStarMethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -122,7 +114,7 @@ template class DotStarMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } @@ -153,26 +145,26 @@ typedef DotStarSpi10MhzMethod DotStarSpiMethod; #if defined(ARDUINO_ARCH_ESP32) // Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32 -typedef DotStarMethodBase> DotStarEsp32Vspi40MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi20MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi10MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi5MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi2MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi1MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Vspi500KhzMethod; -typedef DotStarMethodBase> DotStarEsp32VspiHzMethod; +typedef DotStarMethodBase> DotStarVspi40MhzMethod; +typedef DotStarMethodBase> DotStarVspi20MhzMethod; +typedef DotStarMethodBase> DotStarVspi10MhzMethod; +typedef DotStarMethodBase> DotStarVspi5MhzMethod; +typedef DotStarMethodBase> DotStarVspi2MhzMethod; +typedef DotStarMethodBase> DotStarVspi1MhzMethod; +typedef DotStarMethodBase> DotStarVspi500KhzMethod; +typedef DotStarMethodBase> DotStarVspiHzMethod; -typedef DotStarSpi10MhzMethod DotStarEsp32VspiMethod; +typedef DotStarSpi10MhzMethod DotStarVspiMethod; #include "TwoWireHspiImple.h" -typedef DotStarMethodBase> DotStarEsp32Hspi40MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi20MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi10MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi5MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi2MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi1MhzMethod; -typedef DotStarMethodBase> DotStarEsp32Hspi500KhzMethod; -typedef DotStarMethodBase> DotStarEsp32HspiHzMethod; - -typedef DotStarEsp32Hspi10MhzMethod DotStarEsp32HspiMethod; +typedef DotStarMethodBase> DotStarHspi40MhzMethod; +typedef DotStarMethodBase> DotStarHspi20MhzMethod; +typedef DotStarMethodBase> DotStarHspi10MhzMethod; +typedef DotStarMethodBase> DotStarHspi5MhzMethod; +typedef DotStarMethodBase> DotStarHspi2MhzMethod; +typedef DotStarMethodBase> DotStarHspi1MhzMethod; +typedef DotStarMethodBase> DotStarHspi500KhzMethod; +typedef DotStarMethodBase> DotStarHspiHzMethod; + +typedef DotStarHspi10MhzMethod DotStarHspiMethod; #endif diff --git a/lib/NeoPixelBus/src/internal/Esp32_i2s.c b/lib/NeoPixelBus/src/internal/Esp32_i2s.c new file mode 100644 index 0000000000..5823b1875f --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Esp32_i2s.c @@ -0,0 +1,501 @@ +// 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 "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 + +// ESP32C3/S3 I2S is not supported yet due to significant changes to interface +#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1 +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C2) + +#include +#include +#include "stdlib.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" + + +#if ESP_IDF_VERSION_MAJOR>=4 +#include "esp_intr_alloc.h" +#else +#include "esp_intr.h" +#endif + +#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" +#if defined(CONFIG_IDF_TARGET_ESP32) +/* included here for ESP-IDF v4.x compatibility */ +#include "soc/dport_reg.h" +#endif +#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" + +#if ESP_IDF_VERSION_MAJOR<=4 +#define I2S_BASE_CLK (160000000L) +#endif + +#define ESP32_REG(addr) (*((volatile uint32_t*)(0x3FF00000+(addr)))) + +#define I2S_DMA_BLOCK_COUNT_DEFAULT 16 +// 24 bytes gives us enough time if we use single stage idle +// with the two stage idle we can use the minimum of 4 bytes +#define I2S_DMA_SILENCE_SIZE 4*1 +#define I2S_DMA_SILENCE_BLOCK_COUNT 3 // two front, one back +#define I2S_DMA_QUEUE_COUNT 2 + +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; + volatile uint32_t is_sending_data; +} i2s_bus_t; + +// is_sending_data values +#define I2s_Is_Idle 0 +#define I2s_Is_Pending 1 +#define I2s_Is_Sending 2 + +static uint8_t i2s_silence_buf[I2S_DMA_SILENCE_SIZE] = { 0 }; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) +static i2s_bus_t I2S[I2S_NUM_MAX] = { + {&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle}, + {&I2S1, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle} +}; +#else +static i2s_bus_t I2S[I2S_NUM_MAX] = { + {&I2S0, -1, -1, -1, -1, 0, NULL, NULL, i2s_silence_buf, I2S_DMA_SILENCE_SIZE, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, 0, 0, I2s_Is_Idle} +}; +#endif + +void IRAM_ATTR i2sDmaISR(void* arg); + +bool i2sInitDmaItems(uint8_t bus_num) { + if (bus_num >= I2S_NUM_MAX) { + return false; + } + if (I2S[bus_num].tx_queue) {// already set + return true; + } + + size_t dmaCount = I2S[bus_num].dma_count; + + if (I2S[bus_num].dma_items == NULL) { + I2S[bus_num].dma_items = (i2s_dma_item_t*)heap_caps_malloc(dmaCount * sizeof(i2s_dma_item_t), MALLOC_CAP_DMA); + if (I2S[bus_num].dma_items == NULL) { + log_e("MEM ERROR!"); + return false; + } + } + + int i, i2; + i2s_dma_item_t* item = NULL; + i2s_dma_item_t* itemPrev = NULL; + + for(i=0; i< dmaCount; i++) { + itemPrev = item; + + i2 = (i+1) % dmaCount; + item = &I2S[bus_num].dma_items[i]; + item->eof = 0; + 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; + item->buf = NULL; + } + itemPrev->eof = 1; + item->eof = 1; + + I2S[bus_num].tx_queue = xQueueCreate(I2S_DMA_QUEUE_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; +} + +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 >= I2S_NUM_MAX || div_a > 63 || div_b > 63 || bck > 63) { + return ESP_FAIL; + } + i2s_dev_t* i2s = I2S[bus_num].bus; + + typeof(i2s->clkm_conf) clkm_conf; + + clkm_conf.val = 0; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + clkm_conf.clka_en = 0; +#else + clkm_conf.clk_sel = 2; +#endif + + clkm_conf.clkm_div_a = div_a; + clkm_conf.clkm_div_b = div_b; + clkm_conf.clkm_div_num = div_num; + i2s->clkm_conf.val = clkm_conf.val; + + typeof(i2s->sample_rate_conf) sample_rate_conf; + sample_rate_conf.val = 0; + sample_rate_conf.tx_bck_div_num = bck; + sample_rate_conf.rx_bck_div_num = bck; + sample_rate_conf.tx_bits_mod = bits; + sample_rate_conf.rx_bits_mod = bits; + i2s->sample_rate_conf.val = sample_rate_conf.val; + return ESP_OK; +} + +void i2sSetPins(uint8_t bus_num, int8_t out, bool invert) { + if (bus_num >= I2S_NUM_MAX) { + return; + } + + if (out >= 0) { + if (I2S[bus_num].out != out) { + if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, invert, false); + } + I2S[bus_num].out = out; + pinMode(out, OUTPUT); + + int i2sSignal; +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num == 1) { + i2sSignal = I2S1O_DATA_OUT23_IDX; + } + else +#endif + { + i2sSignal = I2S0O_DATA_OUT23_IDX; + } + + gpio_matrix_out(out, i2sSignal, invert, false); + } + } else if (I2S[bus_num].out >= 0) { + gpio_matrix_out(I2S[bus_num].out, 0x100, invert, false); + I2S[bus_num].out = -1; + } + +} + +bool i2sWriteDone(uint8_t bus_num) { + if (bus_num >= I2S_NUM_MAX) { + return false; + } + + return (I2S[bus_num].is_sending_data == I2s_Is_Idle); +} + +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 >= I2S_NUM_MAX) { + return; + } + + I2S[bus_num].dma_count = dma_count + I2S_DMA_SILENCE_BLOCK_COUNT; // an extra two for looping silence + I2S[bus_num].dma_buf_len = dma_len & 0xFFF; + + if (!i2sInitDmaItems(bus_num)) { + return; + } + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num) { + periph_module_enable(PERIPH_I2S1_MODULE); + } else +#endif + { + 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 + typeof(i2s->lc_conf) lc_conf; + lc_conf.val = 0; + lc_conf.out_eof_mode = 1; + i2s->lc_conf.val = lc_conf.val; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + i2s->pdm_conf.pcm2pdm_conv_en = 0; + i2s->pdm_conf.pdm2pcm_conv_en = 0; +#endif + // SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S); + + typeof(i2s->conf_chan) conf_chan; + conf_chan.val = 0; + conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left + i2s->conf_chan.val = conf_chan.val; + + typeof(i2s->fifo_conf) fifo_conf; + fifo_conf.val = 0; + fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel + i2s->fifo_conf.val = fifo_conf.val; + + typeof(i2s->conf) conf; + conf.val = 0; + conf.tx_msb_shift = (bits_per_sample != 8);// 0:DAC/PCM, 1:I2S + conf.tx_right_first = (bits_per_sample == 8); + i2s->conf.val = conf.val; + + typeof(i2s->conf2) conf2; + conf2.val = 0; + conf2.lcd_en = (bits_per_sample == 8); + i2s->conf2.val = conf2.val; + + i2s->fifo_conf.tx_fifo_mod_force_en = 1; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) + i2s->pdm_conf.rx_pdm_en = 0; + i2s->pdm_conf.tx_pdm_en = 0; +#endif + + i2sSetSampleRate(bus_num, sample_rate, bits_per_sample); + + // enable intr in cpu // + int i2sIntSource; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) +// (I2S_NUM_MAX == 2) + if (bus_num == 1) { + i2sIntSource = ETS_I2S1_INTR_SOURCE; + } + else +#endif + { + i2sIntSource = ETS_I2S0_INTR_SOURCE; + } + + + esp_intr_alloc(i2sIntSource, 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 >= I2S_NUM_MAX) { + 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_bus_t* dev = (i2s_bus_t*)(arg); + + if (dev->bus->int_st.out_eof) + { + // i2s_dma_item_t* item = (i2s_dma_item_t*)(dev->bus->out_eof_des_addr); + if (dev->is_sending_data == I2s_Is_Pending) + { + dev->is_sending_data = I2s_Is_Idle; + } + else if (dev->is_sending_data == I2s_Is_Sending) + { + // loop the silent items + i2s_dma_item_t* itemSilence = &dev->dma_items[1]; + itemSilence->next = &dev->dma_items[0]; + + dev->is_sending_data = I2s_Is_Pending; + } + } + + dev->bus->int_clr.val = dev->bus->int_st.val; +} + +size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free_when_sent) { + if (bus_num >= I2S_NUM_MAX || !I2S[bus_num].tx_queue) { + return 0; + } + size_t blockSize = len; + + i2s_dma_item_t* item = &I2S[bus_num].dma_items[0]; + size_t dataLeft = len; + uint8_t* pos = data; + + // skip front two silent items + item += 2; + + while (dataLeft) { + + blockSize = dataLeft; + if (blockSize > I2S_DMA_MAX_DATA_LEN) { + blockSize = I2S_DMA_MAX_DATA_LEN; + } + dataLeft -= blockSize; + + // data is constant. no need to copy + item->data = pos; + item->blocksize = blockSize; + item->datalen = blockSize; + + item++; + + pos += blockSize; + } + + + // reset silence item to not loop + item = &I2S[bus_num].dma_items[1]; + item->next = &I2S[bus_num].dma_items[2]; + I2S[bus_num].is_sending_data = I2s_Is_Sending; + + + xQueueReset(I2S[bus_num].tx_queue); + xQueueSend(I2S[bus_num].tx_queue, (void*)&I2S[bus_num].dma_items[0], 10); + + return len; +} + +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) +#endif //ESP_IDF_VERSION_MAJOR < 5 +#endif // defined(ARDUINO_ARCH_ESP32) + diff --git a/lib/NeoPixelBus/src/internal/Esp32_i2s.h b/lib/NeoPixelBus/src/internal/Esp32_i2s.h new file mode 100644 index 0000000000..bfc024a8ce --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Esp32_i2s.h @@ -0,0 +1,45 @@ +#pragma once + +#include "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 + +#ifndef CONFIG_SOC_RMT_TX_CANDIDATES_PER_GROUP // turn this off with something new from idf5.1 +// ESP32C3 I2S is not supported yet due to significant changes to interface +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) + +#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, bool invert); + +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); + +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 +#endif // ESP_IDF_VERSION_MAJOR < 5 diff --git a/lib/NeoPixelBus/src/internal/colors/HsbColor.cpp b/lib/NeoPixelBus/src/internal/HsbColor.cpp similarity index 96% rename from lib/NeoPixelBus/src/internal/colors/HsbColor.cpp rename to lib/NeoPixelBus/src/internal/HsbColor.cpp index b45f5113f7..146ddb84e0 100644 --- a/lib/NeoPixelBus/src/internal/colors/HsbColor.cpp +++ b/lib/NeoPixelBus/src/internal/HsbColor.cpp @@ -24,9 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HsbColor.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HsbColor.h b/lib/NeoPixelBus/src/internal/HsbColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HsbColor.h rename to lib/NeoPixelBus/src/internal/HsbColor.h index bf9466bd6c..939d5a1003 100644 --- a/lib/NeoPixelBus/src/internal/colors/HsbColor.h +++ b/lib/NeoPixelBus/src/internal/HsbColor.h @@ -26,6 +26,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + // ------------------------------------------------------------------------ // HsbColor represents a color object that is represented by Hue, Saturation, Brightness // component values. It contains helpful color routines to manipulate the diff --git a/lib/NeoPixelBus/src/internal/colors/HslColor.cpp b/lib/NeoPixelBus/src/internal/HslColor.cpp similarity index 96% rename from lib/NeoPixelBus/src/internal/colors/HslColor.cpp rename to lib/NeoPixelBus/src/internal/HslColor.cpp index bd6c3f43c2..92ae687516 100644 --- a/lib/NeoPixelBus/src/internal/colors/HslColor.cpp +++ b/lib/NeoPixelBus/src/internal/HslColor.cpp @@ -25,9 +25,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HslColor.h b/lib/NeoPixelBus/src/internal/HslColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HslColor.h rename to lib/NeoPixelBus/src/internal/HslColor.h index 44f9061ef5..3555a5c068 100644 --- a/lib/NeoPixelBus/src/internal/colors/HslColor.h +++ b/lib/NeoPixelBus/src/internal/HslColor.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + // ------------------------------------------------------------------------ // HslColor represents a color object that is represented by Hue, Saturation, Lightness // component values. It contains helpful color routines to manipulate the diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp b/lib/NeoPixelBus/src/internal/HtmlColor.cpp similarity index 94% rename from lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp rename to lib/NeoPixelBus/src/internal/HtmlColor.cpp index 9e9af5f90e..018d58f561 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColor.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColor.cpp @@ -23,11 +23,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" static inline char hexdigit(uint8_t v) diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColor.h b/lib/NeoPixelBus/src/internal/HtmlColor.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColor.h rename to lib/NeoPixelBus/src/internal/HtmlColor.h index 3e63421e1f..25329eb6ef 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColor.h +++ b/lib/NeoPixelBus/src/internal/HtmlColor.h @@ -25,6 +25,9 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "RgbColor.h" + #define MAX_HTML_COLOR_NAME_LEN 21 #ifndef pgm_read_ptr @@ -32,6 +35,10 @@ License along with NeoPixel. If not, see #define pgm_read_ptr(addr) (*reinterpret_cast(addr)) #endif +#ifndef countof +#define countof(array) (sizeof(array)/sizeof(array[0])) +#endif + // ------------------------------------------------------------------------ // HtmlColorPair represents an association between a name and a HTML color code // ------------------------------------------------------------------------ diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp index 6c71b33c2b..87dda4b3d8 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "HtmlColorNameStrings.h" /* HTML4 color names */ diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h similarity index 99% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h rename to lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h index dcd30c62d9..86ffcf4f23 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNameStrings.h +++ b/lib/NeoPixelBus/src/internal/HtmlColorNameStrings.h @@ -26,6 +26,8 @@ License along with NeoPixel. If not, see #pragma once +#include + /* HTML4 color names */ extern const char c_HtmlNameAqua[] PROGMEM; extern const char c_HtmlNameBlack[] PROGMEM; diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp b/lib/NeoPixelBus/src/internal/HtmlColorNames.cpp similarity index 98% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorNames.cpp index ce6fd63011..b1098eaae4 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorNames.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorNames.cpp @@ -24,12 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp b/lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp similarity index 94% rename from lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp rename to lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp index 14aaf268f3..3c4e27c3eb 100644 --- a/lib/NeoPixelBus/src/internal/colors/HtmlColorShortNames.cpp +++ b/lib/NeoPixelBus/src/internal/HtmlColorShortNames.cpp @@ -24,12 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "HtmlColor.h" #include "HtmlColorNameStrings.h" diff --git a/lib/NeoPixelBus/src/internal/Layouts.h b/lib/NeoPixelBus/src/internal/Layouts.h new file mode 100644 index 0000000000..5b1016ea99 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Layouts.h @@ -0,0 +1,426 @@ +#pragma once +/*------------------------------------------------------------------------- +Layout provides a collection of class objects that are used with NeoTopology +object. +They define the specific layout of pixels and do the math to change the 2d +cordinate space to 1d cordinate space + +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 +. +-------------------------------------------------------------------------*/ + +const uint16_t PixelIndex_OutOfBounds = 0xffff; + +//----------------------------------------------------------------------------- +// RowMajor +//----------------------------------------------------------------------------- + +class RowMajorLayout; +class RowMajor90Layout; +class RowMajor180Layout; +class RowMajor270Layout; + +class RowMajorTilePreference +{ +public: + typedef RowMajorLayout EvenRowEvenColumnLayout; + typedef RowMajor270Layout EvenRowOddColumnLayout; + typedef RowMajor90Layout OddRowEvenColumnLayout; + typedef RowMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 04 05 06 07 +// 08 09 10 11 +// 12 13 14 15 +// +class RowMajorLayout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return x + y * width; + } +}; + +// layout example of 4x4 +// 12 08 04 00 +// 13 09 05 01 +// 14 10 06 02 +// 15 11 07 03 +// +class RowMajor90Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + y; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 11 10 09 08 +// 07 06 05 04 +// 03 02 01 00 +// +class RowMajor180Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) + (height - 1 - y) * width; + } +}; + +// layout example of 4x4 +// 03 07 11 15 +// 02 06 10 14 +// 01 05 09 13 +// 00 04 08 12 +// +class RowMajor270Layout : public RowMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + (height - 1 - y); + } +}; + + +//----------------------------------------------------------------------------- +// ColumnMajor +//----------------------------------------------------------------------------- + +class ColumnMajorLayout; +class ColumnMajor90Layout; +class ColumnMajor180Layout; +class ColumnMajor270Layout; + +class ColumnMajorTilePreference +{ +public: + typedef ColumnMajorLayout EvenRowEvenColumnLayout; + typedef ColumnMajor270Layout EvenRowOddColumnLayout; + typedef ColumnMajor90Layout OddRowEvenColumnLayout; + typedef ColumnMajor180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 04 08 12 +// 01 05 09 13 +// 02 06 10 14 +// 03 07 11 15 +// +class ColumnMajorLayout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + return x * height + y; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 07 06 05 04 +// 11 10 09 08 +// 15 14 13 12 +// +class ColumnMajor90Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + return (width - 1 - x) + y * width; + } +}; + +// layout example of 4x4 +// 15 11 07 03 +// 14 10 06 02 +// 13 09 05 01 +// 12 08 04 00 +// +class ColumnMajor180Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return (width - 1 - x) * height + (height - 1 - y); + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 08 09 10 11 +// 04 05 06 07 +// 00 01 02 03 +// +class ColumnMajor270Layout : public ColumnMajorTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + return x + (height - 1 - y) * width; + } +}; + + +//----------------------------------------------------------------------------- +// RowMajorAlternating +//----------------------------------------------------------------------------- + +class RowMajorAlternating270Layout; +class RowMajorAlternating90Layout; + +class RowMajorAlternatingTilePreference +{ +public: + typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; + typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; + typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; + typedef RowMajorAlternating90Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 01 02 03 +// 07 06 05 04 +// 08 09 10 11 +// 15 14 13 12 +// +class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; + +// layout example of 4x4 +// 15 08 07 00 +// 14 09 06 01 +// 13 10 05 02 +// 12 11 04 03 +// +class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 12 13 14 15 +// 11 10 09 08 +// 04 05 06 07 +// 03 02 01 00 +// +class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 03 04 11 12 +// 02 05 10 13 +// 01 06 09 14 +// 00 07 08 15 +// +class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; + + +//----------------------------------------------------------------------------- +// ColumnMajorAlternating +//----------------------------------------------------------------------------- + +class ColumnMajorAlternatingLayout; +class ColumnMajorAlternating180Layout; + +class ColumnMajorAlternatingTilePreference +{ +public: + typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; + typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; + typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; +}; + +// layout example of 4x4 +// 00 07 08 15 +// 01 06 09 14 +// 02 05 10 13 +// 03 04 11 12 +// +class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t index = x * height; + + if (x & 0x0001) + { + index += ((height - 1) - y); + } + else + { + index += y; + } + return index; + } +}; + +// layout example of 4x4 +// 03 02 01 00 +// 04 05 06 07 +// 11 10 09 08 +// 12 13 14 15 +// +class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) + { + uint16_t index = y * width; + + if (y & 0x0001) + { + index += x; + } + else + { + index += ((width - 1) - x); + } + return index; + } +}; + +// layout example of 4x4 +// 12 11 04 03 +// 13 10 05 02 +// 14 09 06 01 +// 15 08 07 00 +// +class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t mx = ((width - 1) - x); + uint16_t index = mx * height; + + if (mx & 0x0001) + { + index += y; + } + else + { + index += ((height - 1) - y); + } + return index; + } +}; + +// layout example of 4x4 +// 15 14 13 12 +// 08 09 10 11 +// 07 06 05 04 +// 00 01 02 03 +// +class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference +{ +public: + static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) + { + uint16_t my = ((height - 1) - y); + uint16_t index = my * width; + + if (my & 0x0001) + { + index += ((width - 1) - x); + } + else + { + index += x; + } + return index; + } +}; diff --git a/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h b/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h new file mode 100644 index 0000000000..709935073f --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Lpd6803ColorFeatures.h @@ -0,0 +1,301 @@ +/*------------------------------------------------------------------------- +Lpd6803ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStar like chips + +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 + +class Lpd68033ElementsNoSettings +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Lpd68033Elements : public Lpd68033ElementsNoSettings +{ +public: + static const size_t PixelSize = 2; // 1 bit + 555 encoded elements + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; + +protected: + static void encodePixel(uint8_t c1, uint8_t c2, uint8_t c3, uint16_t* color555) + { + *color555 = (0x8000 | + ((c1 & 0xf8) << 7) | + ((c2 & 0xf8) << 2) | + ((c3 & 0xf8) >> 3)); + } + + static void decodePixel(uint16_t color555, uint8_t* c1, uint8_t* c2, uint8_t* c3) + { + *c1 = (color555 >> 7) & 0xf8; + *c2 = (color555 >> 2) & 0xf8; + *c3 = (color555 << 3) & 0xf8; + } +}; + +class Lpd6803BrgFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.B, color.R, color.G, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.B, &color.R, &color.G); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.B, &color.R, &color.G); + + return color; + } +}; + +class Lpd6803GrbFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.G, color.R, color.B, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.G, &color.R, &color.B); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.G, &color.R, &color.B); + + return color; + } +}; + +class Lpd6803GbrFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.G, color.B, color.R, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.G, &color.B, &color.R); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.G, &color.B, &color.R); + + return color; + } +}; + + +class Lpd6803RgbFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.R, color.G, color.B, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + return color; + } +}; + diff --git a/lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h b/lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h rename to lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h index 9807db8f1b..ecb7e49732 100644 --- a/lib/NeoPixelBus/src/internal/methods/Lpd6803GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Lpd6803GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -102,12 +100,6 @@ template class Lpd6803MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -118,7 +110,7 @@ template class Lpd6803MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h b/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h new file mode 100644 index 0000000000..6ffb4d0d9b --- /dev/null +++ b/lib/NeoPixelBus/src/internal/Lpd8806ColorFeatures.h @@ -0,0 +1,189 @@ +/*------------------------------------------------------------------------- +Lpd8806ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with DotStar like chips + +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 + +class Lpd88063ElementsNoSettings +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Lpd88063Elements : public Lpd88063ElementsNoSettings +{ +public: + static const size_t PixelSize = 3; + + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class Lpd8806BrgFeature : public Lpd88063Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = (color.B >> 1) | 0x80; + *p++ = (color.R >> 1) | 0x80; + *p = (color.G >> 1) | 0x80; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.B = (*p++) << 1; + color.R = (*p++) << 1; + color.G = (*p) << 1; + + 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.B = (pgm_read_byte(p++)) << 1; + color.R = (pgm_read_byte(p++)) << 1; + color.G = (pgm_read_byte(p)) << 1; + + return color; + } + +}; + +class Lpd8806GrbFeature : public Lpd88063Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = (color.G >> 1) | 0x80; + *p++ = (color.R >> 1) | 0x80; + *p = (color.B >> 1) | 0x80; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = (*p++) << 1; + color.R = (*p++) << 1; + color.B = (*p) << 1; + + 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.G = (pgm_read_byte(p++)) << 1; + color.R = (pgm_read_byte(p++)) << 1; + color.B = (pgm_read_byte(p)) << 1; + + return color; + } + +}; + diff --git a/lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h b/lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h rename to lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h index e33555707d..c2372f21a1 100644 --- a/lib/NeoPixelBus/src/internal/methods/Lpd8806GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Lpd8806GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -102,12 +100,6 @@ template class Lpd8806MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -118,7 +110,7 @@ template class Lpd8806MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h b/lib/NeoPixelBus/src/internal/NeoArmMethod.h similarity index 99% rename from lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h rename to lib/NeoPixelBus/src/internal/NeoArmMethod.h index 2f23000566..ef1f7cf698 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoArmMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoArmMethod.h @@ -30,8 +30,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(__arm__) && !defined(ARDUINO_ARCH_NRF52840) template class NeoArmMethodBase @@ -93,12 +91,6 @@ template class NeoArmMethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -109,7 +101,7 @@ template class NeoArmMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -857,7 +849,6 @@ typedef NeoArmTm1814InvertedMethod NeoArmTm1914InvertedMethod; typedef NeoArmWs2812xMethod NeoWs2813Method; typedef NeoArmWs2812xMethod NeoWs2812xMethod; typedef NeoArmWs2812xMethod NeoWs2811Method; -typedef NeoArmWs2812xMethod NeoWs2816Method; typedef NeoArmSk6812Method NeoSk6812Method; typedef NeoArmSk6812Method NeoLc8812Method; typedef NeoArm800KbpsMethod NeoWs2812Method; diff --git a/lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h b/lib/NeoPixelBus/src/internal/NeoAvrMethod.h similarity index 63% rename from lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h rename to lib/NeoPixelBus/src/internal/NeoAvrMethod.h index 8e250347ce..685ab56ef6 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoAvrMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoAvrMethod.h @@ -27,8 +27,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) extern "C" @@ -41,8 +39,6 @@ extern "C" void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); - void send_data_16mhz_600(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); - void send_data_32mhz(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask, const uint8_t cycleTiming); } class NeoAvrSpeed800KbpsBase @@ -66,10 +62,8 @@ class NeoAvrSpeed800KbpsBase #endif // PORTD send_data_12mhz_800_PortB(data, sizeData, pinMask); -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU send_data_16mhz_800(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 3); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -77,38 +71,6 @@ class NeoAvrSpeed800KbpsBase }; -class NeoAvrSpeed600KbpsBase -{ -public: - static void send_data(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) - { -#if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) // 8Mhz CPU -#ifdef PORTD // PORTD isn't present on ATtiny85, etc. - if (port == &PORTD) - send_data_8mhz_800_PortD(data, sizeData, pinMask); - else if (port == &PORTB) -#endif // PORTD - send_data_8mhz_800_PortB(data, sizeData, pinMask); - -#elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU -#ifdef PORTD // PORTD - if (port == &PORTD) - send_data_12mhz_800_PortD(data, sizeData, pinMask); - else if (port == &PORTB) -#endif // PORTD - send_data_12mhz_800_PortB(data, sizeData, pinMask); - -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU - send_data_16mhz_600(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 3); -#else -#error "CPU SPEED NOT SUPPORTED" -#endif - } - -}; - class NeoAvrSpeedWs2812x : public NeoAvrSpeed800KbpsBase { public: @@ -121,19 +83,6 @@ class NeoAvrSpeedSk6812 : public NeoAvrSpeed800KbpsBase static const uint32_t ResetTimeUs = 80; }; -class NeoAvrSpeedApa106 : public NeoAvrSpeed600KbpsBase -{ -public: - static const uint32_t ResetTimeUs = 100; -}; - -class NeoAvrSpeed600KbpsIps : public NeoAvrSpeed600KbpsBase -{ -public: - static const uint32_t ResetTimeUs = 300; - static const uint16_t InterpixelTimeUs = 8; // 12.4, with loop overhead of about 5us for loop -}; - class NeoAvrSpeedTm1814 : public NeoAvrSpeed800KbpsBase { public: @@ -163,10 +112,8 @@ class NeoAvrSpeed400Kbps #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU send_data_12mhz_400(data, sizeData, port, pinMask); -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU send_data_16mhz_400(data, sizeData, port, pinMask); -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - send_data_32mhz(data, sizeData, port, pinMask, 7); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -240,12 +187,6 @@ template class NeoAvrMethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -256,11 +197,11 @@ template class NeoAvrMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } -protected: +private: const size_t _sizeData; // size of _data below const uint8_t _pin; // output pin number @@ -271,64 +212,9 @@ template class NeoAvrMethodBase uint8_t _pinMask; // Output PORT bitmask }; -template class NeoAvrIpsMethodBase : public NeoAvrMethodBase -{ -public: - NeoAvrIpsMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoAvrMethodBase(pin, pixelCount, elementSize, settingsSize), - _elementSize(elementSize) - { - } - - ~NeoAvrIpsMethodBase() - { - } - - 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 - // 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 (!NeoAvrMethodBase::IsReadyToUpdate()) - { -#if !defined(ARDUINO_TEEONARDU_LEO) && !defined(ARDUINO_TEEONARDU_FLORA) - yield(); // allows for system yield if needed -#endif - } - - noInterrupts(); // Need 100% focus on instruction timing - - uint8_t* dataPixel = NeoAvrMethodBase::_data; - const uint8_t* dataEnd = dataPixel + NeoAvrMethodBase::_sizeData; - - while (dataPixel < dataEnd) - { - T_SPEED::send_data(dataPixel, - _elementSize, - NeoAvrMethodBase::_port, - NeoAvrMethodBase::_pinMask); - dataPixel += _elementSize; - delayMicroseconds(T_SPEED::InterpixelTimeUs); - } - - interrupts(); - - // save EOD time for latch on next call - NeoAvrMethodBase::_endTime = micros(); - } - -private: - const size_t _elementSize; // size of a single pixel -}; typedef NeoAvrMethodBase NeoAvrWs2812xMethod; typedef NeoAvrMethodBase NeoAvrSk6812Method; -typedef NeoAvrMethodBase NeoAvrApa106Method; -typedef NeoAvrIpsMethodBase NeoAvr600KbpsIpsMethod; - typedef NeoAvrMethodBase NeoAvrTm1814InvertedMethod; typedef NeoAvrMethodBase NeoAvrTm1829InvertedMethod; typedef NeoAvrMethodBase NeoAvr800KbpsMethod; @@ -340,10 +226,9 @@ typedef NeoAvrWs2812xMethod NeoWs2813Method; typedef NeoAvrWs2812xMethod NeoWs2812xMethod; typedef NeoAvr800KbpsMethod NeoWs2812Method; typedef NeoAvrWs2812xMethod NeoWs2811Method; -typedef NeoAvrWs2812xMethod NeoWs2816Method; typedef NeoAvrSk6812Method NeoSk6812Method; typedef NeoAvrSk6812Method NeoLc8812Method; -typedef NeoAvrApa106Method NeoApa106Method; +typedef NeoAvr400KbpsMethod NeoApa106Method; typedef NeoAvrWs2812xMethod Neo800KbpsMethod; typedef NeoAvr400KbpsMethod Neo400KbpsMethod; diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h b/lib/NeoPixelBus/src/internal/NeoBitmapFile.h similarity index 98% rename from lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h rename to lib/NeoPixelBus/src/internal/NeoBitmapFile.h index d66316a811..467d55d1c5 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBitmapFile.h +++ b/lib/NeoPixelBus/src/internal/NeoBitmapFile.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBitmapFile +NeoPixel library Written by Michael C. Miller. @@ -67,9 +67,6 @@ enum BmpCompression BI_CmykRle4 }; -// T_COLOR_FEATURE - one of the Features -// T_FILE_METHOD - any standard File object following Arduino File methods/members -// template class NeoBitmapFile { public: diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h b/lib/NeoPixelBus/src/internal/NeoBuffer.h similarity index 87% rename from lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h rename to lib/NeoPixelBus/src/internal/NeoBuffer.h index fa18994fb6..d904e87146 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBuffer.h +++ b/lib/NeoPixelBus/src/internal/NeoBuffer.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBuffer +NeoPixel library Written by Michael C. Miller. @@ -25,24 +25,16 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_BUFFER_METHOD - one of -// NeoBufferMethod -// NeoBufferProgmemMethod -// template class NeoBuffer { public: NeoBuffer(uint16_t width, uint16_t height, - PGM_VOID_P pixels = nullptr) : + PGM_VOID_P pixels) : _method(width, height, pixels) { } - ~NeoBuffer() - { - } - operator NeoBufferContext() { return _method; @@ -68,14 +60,14 @@ template class NeoBuffer int16_t y, typename T_BUFFER_METHOD::ColorObject color) { - _method.SetPixelColor(PixelIndex(x, y), color); + _method.SetPixelColor(pixelIndex(x, y), color); }; typename T_BUFFER_METHOD::ColorObject GetPixelColor( int16_t x, int16_t y) const { - return _method.GetPixelColor(PixelIndex(x, y)); + return _method.GetPixelColor(pixelIndex(x, y)); }; void ClearTo(typename T_BUFFER_METHOD::ColorObject color) @@ -124,7 +116,7 @@ template class NeoBuffer if (indexDest < destPixelCount) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), PixelIndex(xSrc + x, ySrc + y)); + const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(xSrc + x, ySrc + y)); uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest); _method.CopyPixels(pDest, pSrc, 1); @@ -152,14 +144,18 @@ template class NeoBuffer for (uint16_t indexPixel = 0; indexPixel < countPixels; indexPixel++) { - const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), indexPixel); - uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); + typename T_BUFFER_METHOD::ColorObject color; + + shader.Apply(indexPixel, (uint8_t*)(&color), _method.Pixels() + (indexPixel * _method.PixelSize())); - shader.Apply(indexPixel, pDest, pSrc); + T_BUFFER_METHOD::ColorFeature::applyPixelColor(destBuffer.Pixels, indexPixel, color); } } - uint16_t PixelIndex( +private: + T_BUFFER_METHOD _method; + + uint16_t pixelIndex( int16_t x, int16_t y) const { @@ -174,7 +170,4 @@ template class NeoBuffer } return result; } - -private: - T_BUFFER_METHOD _method; }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h b/lib/NeoPixelBus/src/internal/NeoBufferContext.h similarity index 98% rename from lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h rename to lib/NeoPixelBus/src/internal/NeoBufferContext.h index d1cb0b8154..8b57344961 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferContext.h +++ b/lib/NeoPixelBus/src/internal/NeoBufferContext.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBufferContext +NeoPixel library Written by Michael C. Miller. diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h b/lib/NeoPixelBus/src/internal/NeoBufferMethods.h similarity index 60% rename from lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h rename to lib/NeoPixelBus/src/internal/NeoBufferMethods.h index af97805263..79d354f57d 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferMethods.h +++ b/lib/NeoPixelBus/src/internal/NeoBufferMethods.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoBufferMethod +NeoPixel library Written by Michael C. Miller. @@ -26,10 +26,24 @@ License along with NeoPixel. If not, see #pragma once + +#if defined(NEOPIXEBUS_NO_STL) + +typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); + +#else + +#undef max +#undef min +#include +typedef std::function LayoutMapCallback; + +#endif + template class NeoBufferMethod { public: - NeoBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = nullptr) : + NeoBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = NULL) : _width(width), _height(height) { @@ -44,7 +58,6 @@ template class NeoBufferMethod ~NeoBufferMethod() { free(_pixels); - _pixels = nullptr; } operator NeoBufferContext() @@ -149,5 +162,102 @@ template class NeoBufferMethod uint8_t* _pixels; }; +template class NeoBufferProgmemMethod +{ +public: + NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : + _width(width), + _height(height), + _pixels(pixels) + { + } + + operator NeoBufferContext() + { + return NeoBufferContext(Pixels(), PixelsSize()); + } + + uint8_t* Pixels() const + { + return (uint8_t*)_pixels; + }; + + size_t PixelsSize() const + { + return PixelSize() * PixelCount(); + }; + + size_t PixelSize() const + { + return T_COLOR_FEATURE::PixelSize; + }; + + uint16_t PixelCount() const + { + return _width * _height; + }; + + uint16_t Width() const + { + return _width; + }; + + uint16_t Height() const + { + return _height; + }; + + void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + { + if (indexPixel >= PixelCount()) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + uint16_t indexPixel = x + y * _width; + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); + } + + typedef typename T_COLOR_FEATURE::ColorObject ColorObject; + typedef T_COLOR_FEATURE ColorFeature; + +private: + const uint16_t _width; + const uint16_t _height; + PGM_VOID_P _pixels; +}; diff --git a/lib/NeoPixelBus/src/internal/NeoBuffers.h b/lib/NeoPixelBus/src/internal/NeoBuffers.h deleted file mode 100644 index a3eacc4952..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoBuffers.h +++ /dev/null @@ -1,40 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBuffers includes all the classes that describe pixel buffers - -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 - -#include "buffers/LayoutMapCallback.h" -#include "buffers/NeoShaderNop.h" -#include "buffers/NeoShaderBase.h" -#include "buffers/NeoBufferContext.h" - -#include "buffers/NeoBuffer.h" -#include "buffers/NeoBufferMethods.h" -#include "buffers/NeoBufferProgmemMethod.h" - -#include "buffers/NeoDib.h" -#include "buffers/NeoBitmapFile.h" -#include "buffers/NeoVerticalSpriteSheet.h" - diff --git a/lib/NeoPixelBus/src/internal/NeoBusChannel.h b/lib/NeoPixelBus/src/internal/NeoBusChannel.h index ea3ef515b6..5fdb131bf3 100644 --- a/lib/NeoPixelBus/src/internal/NeoBusChannel.h +++ b/lib/NeoPixelBus/src/internal/NeoBusChannel.h @@ -5,7 +5,6 @@ // ESP32 - 8 TX channels // ESP32S2 - 4 TX channels // ESP32C3 - 2 TX channels -// ESP32S3 - 4 TX channels // NRF52840 - 3 or 4 channels (some variants only have 3) enum NeoBusChannel @@ -13,7 +12,7 @@ enum NeoBusChannel NeoBusChannel_0, NeoBusChannel_1, -#if !defined(CONFIG_IDF_TARGET_ESP32C3) +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) NeoBusChannel_2, @@ -29,14 +28,14 @@ enum NeoBusChannel NeoBusChannel_3, -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) NeoBusChannel_4, NeoBusChannel_5, NeoBusChannel_6, NeoBusChannel_7, -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) #endif // ARDUINO_ARCH_ESP32 diff --git a/lib/NeoPixelBus/src/internal/NeoColorFeatures.h b/lib/NeoPixelBus/src/internal/NeoColorFeatures.h index b33a170bb0..d1494a278e 100644 --- a/lib/NeoPixelBus/src/internal/NeoColorFeatures.h +++ b/lib/NeoPixelBus/src/internal/NeoColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoColorFeatures includes all the feature classes that describe color order and +NeoColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class Written by Michael C. Miller. @@ -26,52 +26,402 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// Core Element base classes -// -#include "features/NeoElementsNoSettings.h" -#include "features/NeoByteElements.h" - -// Core Feature base classes -#include "features/Neo2Byte555Feature.h" -#include "features/Neo3ByteFeature.h" -#include "features/Neo3Byte777Feature.h" -#include "features/Neo4ByteFeature.h" -#include "features/DotStarX4ByteFeature.h" -#include "features/DotStarL4ByteFeature.h" -#include "features/Neo6xByteFeature.h" -#include "features/Neo6xxByteFeature.h" -#include "features/Neo3WordFeature.h" -#include "features/Neo4WordFeature.h" - -// NeoPixel Features -// -#include "features/NeoRgbFeatures.h" -#include "features/NeoRgbwFeatures.h" -#include "features/NeoRgb48Features.h" -#include "features/NeoRgbw64Features.h" - -#include "features/NeoRgbwxxFeatures.h" -#include "features/NeoRgbcwxFeatures.h" -#include "features/NeoSm168xxFeatures.h" -#include "features/NeoTm1814Features.h" -#include "features/NeoTm1914Features.h" - -typedef NeoRgb48Feature NeoRgbUcs8903Feature; -typedef NeoRgbw64Feature NeoRgbwUcs8904Feature; -typedef NeoGrb48Feature NeoGrbWs2816Feature; - -// DotStart Features -// -#include "features/DotStarRgbFeatures.h" -#include "features/DotStarLrgbFeatures.h" -#include "features/Lpd6803RgbFeatures.h" -#include "features/Lpd8806RgbFeatures.h" - -#include "features/P9813BgrFeature.h" - -// 7 Segment Features -// -#include "features/NeoAbcdefgpsSegmentFeature.h" -#include "features/NeoBacedfpgsSegmentFeature.h" - -typedef NeoAbcdefgpsSegmentFeature SevenSegmentFeature; // Abcdefg order is default +class Neo3Elements +{ +public: + static const size_t PixelSize = 3; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + for (uint8_t iElement = 0; iElement < PixelSize; iElement++) + { + *pPixelDest++ = pPixelSrc[iElement]; + } + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class Neo4Elements +{ +public: + static const size_t PixelSize = 4; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; + + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = *pSrc; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = *pSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = pgm_read_dword(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; + uint32_t* pDestBack = pDest + count; + const uint32_t* pSrcBack = pSrc + count; + while (pDestBack > pDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbwColor ColorObject; +}; + + +class Neo3ElementsNoSettings : public Neo3Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class Neo4ElementsNoSettings : public Neo4Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class NeoGrbFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class NeoGrbwFeature : public Neo4ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p++ = color.B; + *p = color.W; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *p++; + color.B = *p++; + color.W = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRgbwFeature : public Neo4ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p++ = color.B; + *p = color.W; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.R = *p++; + color.G = *p++; + color.B = *p++; + color.W = *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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRgbFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + +class NeoBrgFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.B; + *p++ = color.R; + *p = color.G; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; + +class NeoRbgFeature : public Neo3ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.B; + *p = color.G; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + +}; diff --git a/lib/NeoPixelBus/src/internal/NeoColors.h b/lib/NeoPixelBus/src/internal/NeoColors.h deleted file mode 100644 index dd26204a3a..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoColors.h +++ /dev/null @@ -1,55 +0,0 @@ -/*------------------------------------------------------------------------- -NeoColors includes all the color classes that describe color and -modify colors for NeoPixelBus - -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 - -#include "colors/NeoHueBlend.h" - -#include "colors/RgbColorIndexes.h" -#include "colors/RgbColorBase.h" - -#include "colors/RgbColor.h" -#include "colors/Rgb16Color.h" -#include "colors/Rgb48Color.h" - -#include "colors/HslColor.h" -#include "colors/HsbColor.h" -#include "colors/HtmlColor.h" - -#include "colors/RgbwColor.h" -#include "colors/Rgbw64Color.h" - -#include "colors/RgbwwColor.h" - -#include "colors/SegmentDigit.h" - -#include "colors/NeoGamma.h" -#include "colors/NeoGammaEquationMethod.h" -#include "colors/NeoGammaCieLabEquationMethod.h" -#include "colors/NeoGammaTableMethod.h" -#include "colors/NeoGammaDynamicTableMethod.h" -#include "colors/NeoGammaNullMethod.h" -#include "colors/NeoGammaInvertMethod.h" diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoDib.h b/lib/NeoPixelBus/src/internal/NeoDib.h similarity index 85% rename from lib/NeoPixelBus/src/internal/buffers/NeoDib.h rename to lib/NeoPixelBus/src/internal/NeoDib.h index f3d162fccd..9ede9b110e 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoDib.h +++ b/lib/NeoPixelBus/src/internal/NeoDib.h @@ -1,6 +1,5 @@ /*------------------------------------------------------------------------- -NeoDib - Device Independant Bitmap, interal data stored in RGB/RGBW format -rather than the ColorFeature format +NeoPixel library Written by Michael C. Miller. @@ -26,14 +25,59 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_COLOR_OBJECT - one of the color objects -// RgbColor -// RgbwColor -// Rgb16Color -// Rgb48Color -// Rgbw64Color -// SevenSegDigit -// +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: + NeoShaderBase() : + _state(0) + { + } + + bool IsDirty() const + { + return (_state & NEO_DIRTY); + }; + + void Dirty() + { + _state |= NEO_DIRTY; + }; + + void ResetDirty() + { + _state &= ~NEO_DIRTY; + }; + +protected: + uint8_t _state; // internal state +}; + template class NeoDib { public: diff --git a/lib/NeoPixelBus/src/internal/animations/NeoEase.h b/lib/NeoPixelBus/src/internal/NeoEase.h similarity index 96% rename from lib/NeoPixelBus/src/internal/animations/NeoEase.h rename to lib/NeoPixelBus/src/internal/NeoEase.h index 52c0012bbd..77a3460751 100644 --- a/lib/NeoPixelBus/src/internal/animations/NeoEase.h +++ b/lib/NeoPixelBus/src/internal/NeoEase.h @@ -310,16 +310,4 @@ class NeoEase { return pow(unitValue, 1.0f / 0.45f); } - - static float GammaCieLab(float unitValue) - { - if (unitValue <= 0.08f) - { - return unitValue / 9.033f; - } - else - { - return pow((unitValue + 0.16f) / 1.16f, 3.0f); - } - } }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h similarity index 93% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h index 5e3d2432b0..2afe6d5aa8 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32I2sMethod.h @@ -26,14 +26,16 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - -// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - +#if ESP_IDF_VERSION_MAJOR <= 4 +// ESP32C3 I2S is not supported yet due to significant changes to interface +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) extern "C" { +#include +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#endif #include "Esp32_i2s.h" } @@ -171,13 +173,11 @@ template class NeoEsp32I2sM yield(); } - i2sDeinit(_bus.I2sBusNumber); - gpio_matrix_out(_pin, 0x100, false, false); pinMode(_pin, INPUT); free(_data); - heap_caps_free(_i2sBuffer); + free(_i2sBuffer); } bool IsReadyToUpdate() const @@ -190,15 +190,13 @@ template class NeoEsp32I2sM size_t dmaBlockCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN; i2sInit(_bus.I2sBusNumber, - false, - 2, // bytes per sample + 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaBlockCount, - _i2sBuffer, - _i2sBufferSize); - i2sSetPins(_bus.I2sBusNumber, _pin, -1, -1, T_INVERT::Inverted); + 0); + i2sSetPins(_bus.I2sBusNumber, _pin, T_INVERT::Inverted); } void Update(bool) @@ -211,13 +209,7 @@ template class NeoEsp32I2sM FillBuffers(); - i2sWrite(_bus.I2sBusNumber); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; + i2sWrite(_bus.I2sBusNumber, _i2sBuffer, _i2sBufferSize, false, false); } uint8_t* getData() const @@ -230,7 +222,7 @@ template class NeoEsp32I2sM return _sizeData; } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -241,7 +233,7 @@ template class NeoEsp32I2sM uint8_t* _data; // Holds LED color values - size_t _i2sBufferSize; // total size of _i2sBuffer + uint32_t _i2sBufferSize; // total size of _i2sBuffer uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc void construct(uint16_t pixelCount, size_t elementSize, size_t settingsSize) @@ -313,7 +305,7 @@ typedef NeoEsp32I2sMethodBase NeoEsp32I2s0400KbpsInvertedMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Apa106InvertedMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) // (I2S_NUM_MAX == 2) typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2812xMethod; @@ -355,15 +347,14 @@ typedef NeoEsp32I2sMethodBase -#include "../NeoSettings.h" -#include "../NeoBusChannel.h" -#include "NeoEsp32RmtMethod.h" -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 5 && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) +#include "NeoSettings.h" +#include "NeoBusChannel.h" +#include "NeoEsp32RmtMethod.h" // translate NeoPixelBuffer into RMT buffer @@ -219,17 +219,6 @@ void NeoEsp32RmtSpeedTx1812::Translate(const void* src, RmtBit0, RmtBit1, RmtDurationReset); } -void NeoEsp32RmtSpeedGs1903::Translate(const void* src, - rmt_item32_t* dest, - size_t src_size, - size_t wanted_num, - size_t* translated_size, - size_t* item_num) -{ - _translate(src, dest, src_size, wanted_num, translated_size, item_num, - RmtBit0, RmtBit1, RmtDurationReset); -} - void NeoEsp32RmtInvertedSpeedWs2811::Translate(const void* src, rmt_item32_t* dest, size_t src_size, @@ -339,16 +328,4 @@ void NeoEsp32RmtInvertedSpeedTx1812::Translate(const void* src, _translate(src, dest, src_size, wanted_num, translated_size, item_num, RmtBit0, RmtBit1, RmtDurationReset); } - -void NeoEsp32RmtInvertedSpeedGs1903::Translate(const void* src, - rmt_item32_t* dest, - size_t src_size, - size_t wanted_num, - size_t* translated_size, - size_t* item_num) -{ - _translate(src, dest, src_size, wanted_num, translated_size, item_num, - RmtBit0, RmtBit1, RmtDurationReset); -} - #endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h index 1753b664c5..3cc86d19a4 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32RmtMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod.h @@ -29,9 +29,7 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 5 && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32C2) /* General Reference documentation for the APIs used in this implementation LOW LEVEL: (what is actually used) @@ -45,8 +43,13 @@ Esp32-hal-rmt.h Esp32-hal-rmt.c */ +#include + extern "C" { +#if ESP_IDF_VERSION_MAJOR >= 5 +#include +#endif #include } @@ -266,21 +269,6 @@ class NeoEsp32RmtSpeedTx1812 : public NeoEsp32RmtSpeedBase size_t* item_num); }; -class NeoEsp32RmtSpeedGs1903 : public NeoEsp32RmtSpeedBase -{ -public: - const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); - const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 300); - const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(40000); // 40us - - 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); -}; - class NeoEsp32RmtInvertedSpeedWs2811 : public NeoEsp32RmtInvertedSpeedBase { public: @@ -434,21 +422,6 @@ class NeoEsp32RmtInvertedSpeedTx1812 : public NeoEsp32RmtInvertedSpeedBase size_t* item_num); }; -class NeoEsp32RmtInvertedSpeedGs1903 : public NeoEsp32RmtInvertedSpeedBase -{ -public: - const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); - const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 300); - const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(40000); // 40us - - 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); -}; - class NeoEsp32RmtChannel0 { public: @@ -481,7 +454,7 @@ class NeoEsp32RmtChannel3 const static rmt_channel_t RmtChannelNumber = RMT_CHANNEL_3; }; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) class NeoEsp32RmtChannel4 { @@ -617,12 +590,6 @@ template class NeoEsp32RmtMethodBase } } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _dataEditing; @@ -633,7 +600,7 @@ template class NeoEsp32RmtMethodBase return _sizeData; } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -660,40 +627,34 @@ template class NeoEsp32RmtMethodBase // normal typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNGs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; @@ -701,124 +662,106 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2816Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812Method; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Gs1903Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) #endif // !defined(CONFIG_IDF_TARGET_ESP32C3) // inverted typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32RmtNGs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsInvertedMethod; @@ -826,102 +769,89 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsInvertedMethod; -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xInvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2816InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812InvertedMethod; -typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Gs1903InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsInvertedMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) #endif // !defined(CONFIG_IDF_TARGET_ESP32C3) -#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) // Normally I2s method is the default, defining NEOPIXEL_ESP32_RMT_DEFAULT // will switch to use RMT as the default method -// The ESP32S2, ESP32S3, and ESP32C3 will always defualt to RMT +// The ESP32S2 & ESP32C3 will always defualt to RMT -#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) -// RMT channel 1 method is the default method for ESP32S2, ESP32S3, and ESP32C3 +// RMT channel 1 method is the default method for Esp32S2 & Esp32C3 typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2813Method; typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32Rmt1800KbpsMethod NeoWs2812Method; typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2811Method; -typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2816Method; typedef NeoEsp32Rmt1Sk6812Method NeoSk6812Method; typedef NeoEsp32Rmt1Tm1814Method NeoTm1814Method; typedef NeoEsp32Rmt1Tm1829Method NeoTm1829Method; @@ -929,7 +859,6 @@ typedef NeoEsp32Rmt1Tm1914Method NeoTm1914Method; typedef NeoEsp32Rmt1Sk6812Method NeoLc8812Method; typedef NeoEsp32Rmt1Apa106Method NeoApa106Method; typedef NeoEsp32Rmt1Tx1812Method NeoTx1812Method; -typedef NeoEsp32Rmt1Gs1903Method NeoGs1903Method; typedef NeoEsp32Rmt1Ws2812xMethod Neo800KbpsMethod; typedef NeoEsp32Rmt1400KbpsMethod Neo400KbpsMethod; @@ -938,7 +867,6 @@ typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoEsp32Rmt1800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoEsp32Rmt1Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoEsp32Rmt1Tm1829InvertedMethod NeoTm1829InvertedMethod; @@ -946,19 +874,17 @@ typedef NeoEsp32Rmt1Tm1914InvertedMethod NeoTm1914InvertedMethod; typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoLc8812InvertedMethod; typedef NeoEsp32Rmt1Apa106InvertedMethod NeoApa106InvertedMethod; typedef NeoEsp32Rmt1Tx1812InvertedMethod NeoTx1812InvertedMethod; -typedef NeoEsp32Rmt1Gs1903InvertedMethod NeoGs1903InvertedMethod; typedef NeoEsp32Rmt1Ws2812xInvertedMethod Neo800KbpsInvertedMethod; typedef NeoEsp32Rmt1400KbpsInvertedMethod Neo400KbpsInvertedMethod; -#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) +#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) // RMT channel 6 method is the default method for Esp32 typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2813Method; typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32Rmt6800KbpsMethod NeoWs2812Method; typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2811Method; -typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2816Method; typedef NeoEsp32Rmt6Sk6812Method NeoSk6812Method; typedef NeoEsp32Rmt6Tm1814Method NeoTm1814Method; typedef NeoEsp32Rmt6Tm1829Method NeoTm1829Method; @@ -966,7 +892,6 @@ typedef NeoEsp32Rmt6Tm1914Method NeoTm1914Method; typedef NeoEsp32Rmt6Sk6812Method NeoLc8812Method; typedef NeoEsp32Rmt6Apa106Method NeoApa106Method; typedef NeoEsp32Rmt6Tx1812Method NeoTx1812Method; -typedef NeoEsp32Rmt6Gs1903Method NeoGs1903Method; typedef NeoEsp32Rmt6Ws2812xMethod Neo800KbpsMethod; typedef NeoEsp32Rmt6400KbpsMethod Neo400KbpsMethod; @@ -975,7 +900,6 @@ typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoEsp32Rmt6800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoEsp32Rmt6Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoEsp32Rmt6Tm1829InvertedMethod NeoTm1829InvertedMethod; @@ -983,7 +907,6 @@ typedef NeoEsp32Rmt6Tm1914InvertedMethod NeoTm1914InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoLc8812InvertedMethod; typedef NeoEsp32Rmt6Apa106InvertedMethod NeoApa106InvertedMethod; typedef NeoEsp32Rmt6Tx1812InvertedMethod NeoTx1812InvertedMethod; -typedef NeoEsp32Rmt6Gs1903InvertedMethod NeoGs1903InvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod Neo800KbpsInvertedMethod; typedef NeoEsp32Rmt6400KbpsInvertedMethod Neo400KbpsInvertedMethod; diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp new file mode 100644 index 0000000000..9ca1cddd3b --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp @@ -0,0 +1,107 @@ +#if ESP_IDF_VERSION_MAJOR >= 5 && defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) +#include "../internal/NeoEsp32RmtMethod_idf5.h" + + +size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_encoder_handle_t bytes_encoder = led_encoder->bytes_encoder; + rmt_encoder_handle_t copy_encoder = led_encoder->copy_encoder; + rmt_encode_state_t session_state = RMT_ENCODING_RESET; + rmt_encode_state_t state = RMT_ENCODING_RESET; + size_t encoded_symbols = 0; + switch (led_encoder->state) { + case 0: // send RGB data + encoded_symbols += bytes_encoder->encode(bytes_encoder, channel, primary_data, data_size, &session_state); + if (session_state & RMT_ENCODING_COMPLETE) { + led_encoder->state = 1; // switch to next state when current encoding session finished + } + if (session_state & RMT_ENCODING_MEM_FULL) { + // static_cast(static_cast(a) | static_cast(b)); + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_MEM_FULL)); + goto out; // yield if there's no free space for encoding artifacts + } + // fall-through + case 1: // send reset code + encoded_symbols += copy_encoder->encode(copy_encoder, channel, &led_encoder->reset_code, + sizeof(led_encoder->reset_code), &session_state); + if (session_state & RMT_ENCODING_COMPLETE) { + led_encoder->state = RMT_ENCODING_RESET; // back to the initial encoding session + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_COMPLETE)); + } + if (session_state & RMT_ENCODING_MEM_FULL) { + state = static_cast(static_cast(state) | static_cast(RMT_ENCODING_MEM_FULL)); + goto out; // yield if there's no free space for encoding artifacts + } + } +out: + *ret_state = state; + return encoded_symbols; +} + +esp_err_t rmt_del_led_strip_encoder(rmt_encoder_t *encoder) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_del_encoder(led_encoder->bytes_encoder); + rmt_del_encoder(led_encoder->copy_encoder); + delete led_encoder; + return ESP_OK; +} + +esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder) +{ + rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base); + rmt_encoder_reset(led_encoder->bytes_encoder); + rmt_encoder_reset(led_encoder->copy_encoder); + led_encoder->state = RMT_ENCODING_RESET; + return ESP_OK; +} + +esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder, uint32_t bit0, uint32_t bit1) +{ + const char* TAG = "TEST_RMT"; //TODO: Remove later + esp_err_t ret = ESP_OK; + rmt_led_strip_encoder_t *led_encoder = NULL; + uint32_t reset_ticks = config->resolution / 1000000 * 50 / 2; // reset code duration defaults to 50us + rmt_bytes_encoder_config_t bytes_encoder_config; + rmt_copy_encoder_config_t copy_encoder_config = {}; + rmt_symbol_word_t reset_code_config; + + + ESP_GOTO_ON_FALSE(config && ret_encoder, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + led_encoder = new rmt_led_strip_encoder_t(); + ESP_GOTO_ON_FALSE(led_encoder, ESP_ERR_NO_MEM, err, TAG, "no mem for led strip encoder"); + led_encoder->base.encode = rmt_encode_led_strip; + led_encoder->base.del = rmt_del_led_strip_encoder; + led_encoder->base.reset = rmt_led_strip_encoder_reset; + + bytes_encoder_config.bit0.val = bit0; + bytes_encoder_config.bit1.val = bit1; + + bytes_encoder_config.flags.msb_first = 1; // WS2812 transfer bit order: G7...G0R7...R0B7...B0 - TODO: more checks + + ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &led_encoder->bytes_encoder), err, TAG, "create bytes encoder failed"); + ESP_GOTO_ON_ERROR(rmt_new_copy_encoder(©_encoder_config, &led_encoder->copy_encoder), err, TAG, "create copy encoder failed"); + + reset_code_config.level0 = 0; + reset_code_config.duration0 = reset_ticks; + reset_code_config.level1 = 0; + reset_code_config.duration1 = reset_ticks; + led_encoder->reset_code = reset_code_config; + *ret_encoder = &led_encoder->base; + return ret; +err: + // AddLog(2,"RMT:could not init led decoder"); + if (led_encoder) { + if (led_encoder->bytes_encoder) { + rmt_del_encoder(led_encoder->bytes_encoder); + } + if (led_encoder->copy_encoder) { + rmt_del_encoder(led_encoder->copy_encoder); + } + delete led_encoder; + } + return ret; +} + +#endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h new file mode 100644 index 0000000000..d0fc0d8fae --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h @@ -0,0 +1,801 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +A BIG thanks to Andreas Merkle for the investigation and implementation of +a workaround to the GCC bug that drops method attributes from template methods + +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 + +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR >= 5 && !defined(CONFIG_IDF_TARGET_ESP32C2) + +/* 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 +*/ + +#include + +//extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); + +extern "C" +{ +#include +#include "driver/rmt_tx.h" +#include "driver/rmt_encoder.h" +#include "esp_check.h" +} + +#include "NeoBusChannel.h" +#include "NeoSettings.h" + +#define RMT_LED_STRIP_RESOLUTION_HZ 40000000 // 40MHz resolution - setting of the "old" driver + +typedef struct { + uint32_t resolution; /*!< Encoder resolution, in Hz */ +} led_strip_encoder_config_t; + +typedef struct { + rmt_encoder_t base; + rmt_encoder_t *bytes_encoder; + rmt_encoder_t *copy_encoder; + int state; + rmt_symbol_word_t reset_code; +} rmt_led_strip_encoder_t; + +size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state); + +esp_err_t rmt_del_led_strip_encoder(rmt_encoder_t *encoder); + +esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder); + +esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder, uint32_t bit0, uint32_t bit1); + +#define NEOPIXELBUS_RMT_INT_FLAGS (ESP_INTR_FLAG_LOWMED) + +class NeoEsp32RmtSpeed +{ +public: +// next section is probably not needed anymore for IDF 5.1 + // 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; + } + +protected: + 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 +// end of deprecated section + +}; + +class NeoEsp32RmtSpeedBase : public NeoEsp32RmtSpeed +{ +public: + // this is used rather than the rmt_symbol_word_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)); + } +}; + +class NeoEsp32RmtInvertedSpeedBase : public NeoEsp32RmtSpeed +{ +public: + // this is used rather than the rmt_symbol_word_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 << 31) | (FromNs(nsHigh)); + } +}; + +class NeoEsp32RmtSpeedWs2811 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950); // TODO: DRAM_ATTR debatable everywhere + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtSpeedSk6812 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1814 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1829 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 400); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtSpeedTm1914 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +class NeoEsp32RmtSpeed800Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeed400Kbps : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(350, 1350); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1350, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtSpeedTx1812 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 600); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(600, 300); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +class NeoEsp32RmtInvertedSpeedWs2811 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtInvertedSpeedWs2812x : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us +}; + +class NeoEsp32RmtInvertedSpeedSk6812 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1814 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1829 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 900); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 400); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1914 : public NeoEsp32RmtSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(360, 890); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(720, 530); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + +class NeoEsp32RmtInvertedSpeed800Kbps : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeed400Kbps : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeedApa106 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(350, 1350); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1350, 350); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us +}; + +class NeoEsp32RmtInvertedSpeedTx1812 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 600); + const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(600, 300); + const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us +}; + +class NeoEsp32RmtChannel0 +{ +public: + NeoEsp32RmtChannel0() {}; + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel1 +{ +public: + NeoEsp32RmtChannel1() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +#if !defined(CONFIG_IDF_TARGET_ESP32C6) // C6 only 2 RMT channels ?? +class NeoEsp32RmtChannel2 +{ +public: + NeoEsp32RmtChannel2() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel3 +{ +public: + NeoEsp32RmtChannel3() {}; + +protected: + rmt_channel_handle_t RmtChannelNumber = NULL; +}; +#endif // !defined(CONFIG_IDF_TARGET_ESP32C6) +#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +class NeoEsp32RmtChannel4 +{ +public: + NeoEsp32RmtChannel4() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel5 +{ +public: + NeoEsp32RmtChannel5() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel6 +{ +public: + NeoEsp32RmtChannel6() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +class NeoEsp32RmtChannel7 +{ +public: + NeoEsp32RmtChannel7() {}; + + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +#endif + +// dynamic channel support +class NeoEsp32RmtChannelN +{ +public: + NeoEsp32RmtChannelN(NeoBusChannel channel) : + RmtChannelNumber(nullptr) + { + //RmtChannelNumber = NULL; + }; + NeoEsp32RmtChannelN() = delete; // no default constructor + rmt_channel_handle_t RmtChannelNumber = NULL; +}; + +template class NeoEsp32RmtMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + _pin(pin) + { + construct(); + } + + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel) : + _sizeData(pixelCount* elementSize + settingsSize), + _pin(pin), + _channel(channel) + { + construct(); + } + + ~NeoEsp32RmtMethodBase() + { + // wait until the last send finishes before destructing everything + // arbitrary time out of 10 seconds + + ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 10000 / portTICK_PERIOD_MS)); + ESP_ERROR_CHECK( rmt_del_channel(_channel.RmtChannelNumber)); + + gpio_matrix_out(_pin, 0x100, false, false); + pinMode(_pin, INPUT); + + free(_dataEditing); + free(_dataSending); + } + + + bool IsReadyToUpdate() const + { + return (ESP_OK == rmt_tx_wait_all_done(_channel.RmtChannelNumber, 0)); + } + + void Initialize() + { + esp_err_t ret = ESP_OK; + rmt_tx_channel_config_t config = {}; + config.clk_src = RMT_CLK_SRC_DEFAULT; + config.gpio_num = static_cast(_pin); + config.mem_block_symbols = 64; // memory block size, 64 * 4 = 256 Bytes + config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ; // 1 MHz tick resolution, i.e., 1 tick = 1 µs + config.trans_queue_depth = 4; // set the number of transactions that can pend in the background + config.flags.invert_out = false; // do not invert output signal + config.flags.with_dma = false; // do not need DMA backend + + ret += rmt_new_tx_channel(&config,&_channel.RmtChannelNumber); + led_strip_encoder_config_t encoder_config = {}; + encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ; + + _tx_config.loop_count = 0; //no loop + + ret += rmt_new_led_strip_encoder(&encoder_config, &_led_encoder, T_SPEED::RmtBit0, T_SPEED::RmtBit1); + + // ESP_LOGI(TAG, "Enable RMT TX channel"); + ret += rmt_enable(_channel.RmtChannelNumber); + // AddLog(2,"RMT:initialized with error code: %u on pin: %u",ret, _pin); + } + + void Update(bool maintainBufferConsistency) + { + // AddLog(2,".."); + // 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 == ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 10000 / portTICK_PERIOD_MS))) + { + // AddLog(2,"__ %u", _sizeData); + // now start the RMT transmit with the editing buffer before we swap + esp_err_t ret = rmt_transmit(_channel.RmtChannelNumber, _led_encoder, _dataEditing, _sizeData, &_tx_config); // 3 for _sizeData + // AddLog(2,"rmt_transmit: %u", ret); + 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(_dataSending, _dataEditing, _sizeData); + } + + // swap so the user can modify without affecting the async operation + std::swap(_dataSending, _dataEditing); + } + } + + uint8_t* getData() const + { + return _dataEditing; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data*' buffers + const uint8_t _pin; // output pin number + + rmt_transmit_config_t _tx_config = {}; + rmt_encoder_handle_t _led_encoder = nullptr; + + T_CHANNEL _channel; // holds instance for multi channel support + + + // Holds data stream which include LED color values and other settings as needed + uint8_t* _dataEditing; // exposed for get and set + uint8_t* _dataSending; // used for async send using RMT + + + void construct() + { + // AddLog(2,"RMT:construct"); + _dataEditing = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _dataSending = static_cast(malloc(_sizeData)); + // no need to initialize it, it gets overwritten on every send + } +}; + +// normal +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; + +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C3) + +// inverted +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNWs2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNSk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNApa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtNTx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32RmtN400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsInvertedMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsInvertedMethod; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsInvertedMethod; + +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1829InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1914InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tx1812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsInvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsInvertedMethod; + +#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) + + +#if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +// Normally I2s method is the default, defining NEOPIXEL_ESP32_RMT_DEFAULT +// will switch to use RMT as the default method +// The ESP32S2 & ESP32C3 will always defualt to RMT + +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +// RMT channel 1 method is the default method for Esp32S2 & Esp32C3 +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2813Method; +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2812xMethod; +typedef NeoEsp32Rmt1800KbpsMethod NeoWs2812Method; +typedef NeoEsp32Rmt1Ws2812xMethod NeoWs2811Method; +typedef NeoEsp32Rmt1Sk6812Method NeoSk6812Method; +typedef NeoEsp32Rmt1Tm1814Method NeoTm1814Method; +typedef NeoEsp32Rmt1Tm1829Method NeoTm1829Method; +typedef NeoEsp32Rmt1Tm1914Method NeoTm1914Method; +typedef NeoEsp32Rmt1Sk6812Method NeoLc8812Method; +typedef NeoEsp32Rmt1Apa106Method NeoApa106Method; +typedef NeoEsp32Rmt1Tx1812Method NeoTx1812Method; + +typedef NeoEsp32Rmt1Ws2812xMethod Neo800KbpsMethod; +typedef NeoEsp32Rmt1400KbpsMethod Neo400KbpsMethod; + +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2813InvertedMethod; +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2812xInvertedMethod; +typedef NeoEsp32Rmt1Ws2812xInvertedMethod NeoWs2811InvertedMethod; +typedef NeoEsp32Rmt1800KbpsInvertedMethod NeoWs2812InvertedMethod; +typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoSk6812InvertedMethod; +typedef NeoEsp32Rmt1Tm1814InvertedMethod NeoTm1814InvertedMethod; +typedef NeoEsp32Rmt1Tm1829InvertedMethod NeoTm1829InvertedMethod; +typedef NeoEsp32Rmt1Tm1914InvertedMethod NeoTm1914InvertedMethod; +typedef NeoEsp32Rmt1Sk6812InvertedMethod NeoLc8812InvertedMethod; +typedef NeoEsp32Rmt1Apa106InvertedMethod NeoApa106InvertedMethod; +typedef NeoEsp32Rmt1Tx1812InvertedMethod NeoTx1812InvertedMethod; + +typedef NeoEsp32Rmt1Ws2812xInvertedMethod Neo800KbpsInvertedMethod; +typedef NeoEsp32Rmt1400KbpsInvertedMethod Neo400KbpsInvertedMethod; + +#else // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) + +// RMT channel 6 method is the default method for Esp32 +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2813Method; +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2812xMethod; +typedef NeoEsp32Rmt6800KbpsMethod NeoWs2812Method; +typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2811Method; +typedef NeoEsp32Rmt6Sk6812Method NeoSk6812Method; +typedef NeoEsp32Rmt6Tm1814Method NeoTm1814Method; +typedef NeoEsp32Rmt6Tm1829Method NeoTm1829Method; +typedef NeoEsp32Rmt6Tm1914Method NeoTm1914Method; +typedef NeoEsp32Rmt6Sk6812Method NeoLc8812Method; +typedef NeoEsp32Rmt6Apa106Method NeoApa106Method; +typedef NeoEsp32Rmt6Tx1812Method NeoTx1812Method; + +typedef NeoEsp32Rmt6Ws2812xMethod Neo800KbpsMethod; +typedef NeoEsp32Rmt6400KbpsMethod Neo400KbpsMethod; + +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2813InvertedMethod; +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2812xInvertedMethod; +typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2811InvertedMethod; +typedef NeoEsp32Rmt6800KbpsInvertedMethod NeoWs2812InvertedMethod; +typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoSk6812InvertedMethod; +typedef NeoEsp32Rmt6Tm1814InvertedMethod NeoTm1814InvertedMethod; +typedef NeoEsp32Rmt6Tm1829InvertedMethod NeoTm1829InvertedMethod; +typedef NeoEsp32Rmt6Tm1914InvertedMethod NeoTm1914InvertedMethod; +typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoLc8812InvertedMethod; +typedef NeoEsp32Rmt6Apa106InvertedMethod NeoApa106InvertedMethod; +typedef NeoEsp32Rmt6Tx1812InvertedMethod NeoTx1812InvertedMethod; + +typedef NeoEsp32Rmt6Ws2812xInvertedMethod Neo800KbpsInvertedMethod; +typedef NeoEsp32Rmt6400KbpsInvertedMethod Neo400KbpsInvertedMethod; + +#endif // defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +#endif // defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) + +#endif diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h new file mode 100644 index 0000000000..a6c3adc23c --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp32SpiMethod_idf5.h @@ -0,0 +1,504 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp32. + +Adaption of Espressif's component library code by Christian Baars + +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 not yet 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 + +#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR >= 5 + +#if (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)) && !defined(HSPI_HOST) +// HSPI_HOST depreciated in C3 +#define HSPI_HOST SPI2_HOST +#endif + +#include + +// extern void AddLog(uint32_t loglevel, PGM_P formatP, ...); // TODO: Remove all Addlogs + +extern "C" +{ +#include +#include "esp_rom_gpio.h" +#include "driver/spi_master.h" +#include "esp_check.h" +} + +#define LED_STRIP_SPI_DEFAULT_RESOLUTION (25 * 100 * 1000) // 2.5MHz resolution +#define LED_STRIP_SPI_DEFAULT_TRANS_QUEUE_SIZE 4 + +#define SPI_BYTES_PER_COLOR_BYTE 3 +#define SPI_BITS_PER_COLOR_BYTE (SPI_BYTES_PER_COLOR_BYTE * 8) + +static const char *TAG = "led_strip_spi"; // TODO: Remove all TAG log stuff + +typedef enum { + LED_MODEL_WS2812, /*!< LED strip model: WS2812 */ + LED_MODEL_SK6812, /*!< LED strip model: SK6812 */ + LED_MODEL_INVALID /*!< Invalid LED strip model */ +} led_model_t; + +typedef enum { + LED_PIXEL_FORMAT_GRB, /*!< Pixel format: GRB */ + LED_PIXEL_FORMAT_GRBW, /*!< Pixel format: GRBW */ + LED_PIXEL_FORMAT_INVALID /*!< Invalid pixel format */ +} led_pixel_format_t; + +typedef struct { + spi_host_device_t spi_host; + spi_device_handle_t spi_device; + uint32_t strip_len; + uint8_t bytes_per_pixel; + uint8_t pixel_buf[]; +} led_strip_spi_obj; + +/** + * @brief LED Strip Configuration + */ +typedef struct { + int strip_gpio_num; /*!< GPIO number that used by LED strip */ + uint32_t max_leds; /*!< Maximum LEDs in a single strip */ + led_pixel_format_t led_pixel_format; /*!< LED pixel format */ + led_model_t led_model; /*!< LED model */ + + struct { + uint32_t invert_out: 1; /*!< Invert output signal */ + } flags; +} led_strip_config_t; + +typedef struct { + spi_clock_source_t clk_src; /*!< SPI clock source */ + spi_host_device_t spi_bus; /*!< SPI bus ID. Which buses are available depends on the specific chip */ + struct { + uint32_t with_dma: 1; /*!< Use DMA to transmit data */ + } flags; +} led_strip_spi_config_t; + + +class NeoEsp32SpiSpeed +{ +public: + + +protected: + +// end of deprecated section + +}; + +class NeoEsp32SpiSpeedBase : public NeoEsp32SpiSpeed +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedBase : public NeoEsp32SpiSpeed +{ +public: + +}; + +class NeoEsp32SpiSpeedWs2811 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedWs2812x : public NeoEsp32SpiSpeedBase +{ +public: + static const uint8_t bytes_per_pixel = 3; + +}; + +class NeoEsp32SpiSpeedSk6812 : public NeoEsp32SpiSpeedBase +{ +public: + static const uint8_t bytes_per_pixel = 4; + +}; + +class NeoEsp32SpiSpeed400Kbps : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedApa106 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiSpeedTx1812 : public NeoEsp32SpiSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedWs2811 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedWs2812x : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedSk6812 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeed800Kbps : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeed400Kbps : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedApa106 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiInvertedSpeedTx1812 : public NeoEsp32SpiInvertedSpeedBase +{ +public: + +}; + +class NeoEsp32SpiChannel +{ +public: + +}; + + +template class NeoEsp32SpiMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp32SpiMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + // _pixelCount(pixelCount), + _pin(pin) + { + _pixelCount = pixelCount; + construct(); + } + + NeoEsp32SpiMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel) : + _sizeData(pixelCount* elementSize + settingsSize), + // _pixelCount(pixelCount), + _pin(pin) + // _channel(channel) // TODO: Refactor this somehow + { + _pixelCount = pixelCount; + construct(); + } + + ~NeoEsp32SpiMethodBase() + { + // wait until the last send finishes before destructing everything + // arbitrary time out of 10 seconds + + gpio_matrix_out(_pin, 0x100, false, false); + pinMode(_pin, INPUT); + + spi_bus_remove_device(_spi_strip->spi_device); + spi_bus_free(_spi_strip->spi_host); + free(_spi_strip); + + free(_dataEditing); + free(_dataSending); + } + + + bool IsReadyToUpdate() const + { + return true; // TODO + } + + void Initialize() + { + esp_err_t ret = ESP_OK; + uint8_t bytes_per_pixel = T_SPEED::bytes_per_pixel; + uint32_t mem_caps = MALLOC_CAP_DEFAULT; + spi_clock_source_t clk_src = SPI_CLK_SRC_DEFAULT; + spi_bus_config_t spi_bus_cfg; + spi_device_interface_config_t spi_dev_cfg; + bool with_dma = true; /// TODO: pass value or compute based on pixelcount + int clock_resolution_khz = 0; + + // ESP_GOTO_ON_FALSE(led_config && spi_config && ret_strip, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); + // ESP_GOTO_ON_FALSE(led_config->led_pixel_format < LED_PIXEL_FORMAT_INVALID, ESP_ERR_INVALID_ARG, err, TAG, "invalid led_pixel_format"); + + // if ( LED_PIXEL_FORMAT_GRB == LED_PIXEL_FORMAT_GRBW) { // TODO + // bytes_per_pixel = 4; + // } else if (LED_PIXEL_FORMAT_GRB == LED_PIXEL_FORMAT_GRB) { + // bytes_per_pixel = 3; + // } else { + // assert(false); + // } + + if (with_dma) { // TODO + // DMA buffer must be placed in internal SRAM + mem_caps |= MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA; + } + _spi_strip = (led_strip_spi_obj *)heap_caps_calloc(1, sizeof(led_strip_spi_obj) + _pixelCount * bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE, mem_caps); + + ESP_GOTO_ON_FALSE(_spi_strip, ESP_ERR_NO_MEM, err, TAG, "no mem for spi strip"); + + _spi_strip->spi_host = SPI2_HOST; + + // for backward compatibility, if the user does not set the clk_src, use the default value + // if (clk_src) { + // clk_src = spi_config->clk_src; + // } + + spi_bus_cfg = { + .mosi_io_num = _pin, + //Only use MOSI to generate the signal, set -1 when other pins are not used. + .miso_io_num = -1, + .sclk_io_num = -1, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = _pixelCount * bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE, + }; + ESP_GOTO_ON_ERROR(spi_bus_initialize(_spi_strip->spi_host, &spi_bus_cfg, with_dma ? SPI_DMA_CH_AUTO : SPI_DMA_DISABLED), err, TAG, "create SPI bus failed"); + + // if (led_config->flags.invert_out == true) { + // esp_rom_gpio_connect_out_signal(_pin, spi_periph_signal[_spi_strip->spi_host].spid_out, true, false); + // } + + spi_dev_cfg = { + .command_bits = 0, + .address_bits = 0, + .dummy_bits = 0, + .mode = 0, + //set -1 when CS is not used + .clock_source = clk_src, + .clock_speed_hz = LED_STRIP_SPI_DEFAULT_RESOLUTION, + .spics_io_num = -1, + .queue_size = LED_STRIP_SPI_DEFAULT_TRANS_QUEUE_SIZE, + }; + + ESP_GOTO_ON_ERROR(spi_bus_add_device(_spi_strip->spi_host, &spi_dev_cfg, &_spi_strip->spi_device), err, TAG, "Failed to add spi device"); + + spi_device_get_actual_freq(_spi_strip->spi_device, &clock_resolution_khz); + // TODO: ideally we should decide the SPI_BYTES_PER_COLOR_BYTE by the real clock resolution + // But now, let's fixed the resolution, the downside is, we don't support a clock source whose frequency is not multiple of LED_STRIP_SPI_DEFAULT_RESOLUTION + ESP_GOTO_ON_FALSE(clock_resolution_khz == LED_STRIP_SPI_DEFAULT_RESOLUTION / 1000, ESP_ERR_NOT_SUPPORTED, err, + TAG, "unsupported clock resolution:%dKHz", clock_resolution_khz); + + _spi_strip->bytes_per_pixel = bytes_per_pixel; + _spi_strip->strip_len = _pixelCount; + + // AddLog(2,"SPI:initialized with error code: %u on pin: %u",ret, _pin); + return; + err: + if (_spi_strip) { + if (_spi_strip->spi_device) { + spi_bus_remove_device(_spi_strip->spi_device); + } + if (_spi_strip->spi_host) { + spi_bus_free(_spi_strip->spi_host); + } + free(_spi_strip); + } + // AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin); + return; + } + + void Update(bool maintainBufferConsistency) + { + // AddLog(2,".."); + // 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 READY + { + // AddLog(2,"__ %u", _sizeData); + // now start the SPI transmit with the editing buffer before we swap + led_strip_transmit_RGB_buffer(_dataEditing, _sizeData, T_SPEED::bytes_per_pixel); + + 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(_dataSending, _dataEditing, _sizeData); + } + + // swap so the user can modify without affecting the async operation + std::swap(_dataSending, _dataEditing); + } + } + + uint8_t* getData() const + { + return _dataEditing; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data*' buffers + int16_t _pixelCount; + const uint8_t _pin; // output pin number + T_CHANNEL _channel; // not really used here + + led_strip_spi_obj *_spi_strip; + + + // Holds data stream which include LED color values and other settings as needed + uint8_t* _dataEditing; // exposed for get and set + uint8_t* _dataSending; // used for async send using RMT - TODO: Check if this useful for SPI + + + void construct() + { + _dataEditing = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _dataSending = static_cast(malloc(_sizeData)); + // no need to initialize it, it gets overwritten on every send + } + + // please make sure to zero-initialize the buf before calling this function + + void __led_strip_spi_bit(uint8_t data, uint8_t *buf) + { + // Each color of 1 bit is represented by 3 bits of SPI, low_level:100 ,high_level:110 + // So a color byte occupies 3 bytes of SPI. + *(buf + 2) |= data & BIT(0) ? BIT(2) | BIT(1) : BIT(2); + *(buf + 2) |= data & BIT(1) ? BIT(5) | BIT(4) : BIT(5); + *(buf + 2) |= data & BIT(2) ? BIT(7) : 0x00; + *(buf + 1) |= BIT(0); + *(buf + 1) |= data & BIT(3) ? BIT(3) | BIT(2) : BIT(3); + *(buf + 1) |= data & BIT(4) ? BIT(6) | BIT(5) : BIT(6); + *(buf + 0) |= data & BIT(5) ? BIT(1) | BIT(0) : BIT(1); + *(buf + 0) |= data & BIT(6) ? BIT(4) | BIT(3) : BIT(4); + *(buf + 0) |= data & BIT(7) ? BIT(7) | BIT(6) : BIT(7); + } + + esp_err_t led_strip_spi_set_pixel(uint32_t index, uint32_t red, uint32_t green, uint32_t blue) + { + if(index >= _spi_strip->strip_len) return ESP_FAIL; + // LED_PIXEL_FORMAT_GRB takes 72bits(9bytes) + uint32_t start = index * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE; + memset(_spi_strip->pixel_buf + start, 0, _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + __led_strip_spi_bit(green, &_spi_strip->pixel_buf[start]); + __led_strip_spi_bit(red, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE]); + __led_strip_spi_bit(blue, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 2]); + if (_spi_strip->bytes_per_pixel > 3) { + __led_strip_spi_bit(0, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 3]); + } + return ESP_OK; + } + + esp_err_t led_strip_spi_set_pixel_rgbw(uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white) + { + // LED_PIXEL_FORMAT_GRBW takes 96bits(12bytes) + uint32_t start = index * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE; + // SK6812 component order is GRBW + memset(_spi_strip->pixel_buf + start, 0, _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + __led_strip_spi_bit(green, &_spi_strip->pixel_buf[start]); + __led_strip_spi_bit(red, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE]); + __led_strip_spi_bit(blue, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 2]); + __led_strip_spi_bit(white, &_spi_strip->pixel_buf[start + SPI_BYTES_PER_COLOR_BYTE * 3]); + + return ESP_OK; + } + + esp_err_t led_strip_spi_clear() + { + //Write zero to turn off all leds + memset(_spi_strip->pixel_buf, 0, _spi_strip->strip_len * _spi_strip->bytes_per_pixel * SPI_BYTES_PER_COLOR_BYTE); + uint8_t *buf = _spi_strip->pixel_buf; + for (int index = 0; index < _spi_strip->strip_len * _spi_strip->bytes_per_pixel; index++) { + __led_strip_spi_bit(0, buf); + buf += SPI_BYTES_PER_COLOR_BYTE; + } + return led_strip_spi_refresh(); + } + + esp_err_t led_strip_spi_refresh() + { + spi_transaction_t tx_conf; + memset(&tx_conf, 0, sizeof(tx_conf)); + + tx_conf.length = _spi_strip->strip_len * _spi_strip->bytes_per_pixel * SPI_BITS_PER_COLOR_BYTE; + tx_conf.tx_buffer = _spi_strip->pixel_buf; + tx_conf.rx_buffer = NULL; + spi_device_transmit(_spi_strip->spi_device, &tx_conf); // TODO -check + return ESP_OK; + } + + void led_strip_transmit_RGB_buffer(uint8_t * buffer, size_t size, uint8_t bytes_per_pixel) + { + for (int i = 0; i < size; i+=bytes_per_pixel) { + led_strip_spi_set_pixel(i/bytes_per_pixel, buffer[i+1], buffer[i], buffer[i+2]); //GRB -> RGB + } + /* Refresh the strip to send data */ + led_strip_spi_refresh(); + } +}; + +// normal +typedef NeoEsp32SpiMethodBase NeoEsp32SpiN800KbpsMethod; +typedef NeoEsp32SpiMethodBase NeoEsp32SpiNSk6812Method; + + +// SPI channel method is the default method for Esp32C2 +#ifdef CONFIG_IDF_TARGET_ESP32C2 +typedef NeoEsp32SpiSpeedWs2812x NeoWs2813Method; +typedef NeoEsp32SpiSpeedWs2812x NeoWs2812xMethod; +typedef NeoEsp32SpiSpeedSk6812 NeoSk6812Method; + +#endif //CONFIG_IDF_TARGET_ESP32C2 + +#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp similarity index 88% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp rename to lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp index e47e0bfa34..4bfc7d3409 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.cpp @@ -25,11 +25,12 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "../NeoUtil.h" -#include "NeoEsp8266I2sMethodCore.h" +#include "NeoSettings.h" +#include "NeoBusChannel.h" +#include "NeoEsp8266DmaMethod.h" #ifdef ARDUINO_ARCH_ESP8266 -NeoEsp8266I2sMethodCore* NeoEsp8266I2sMethodCore::s_this; +NeoEsp8266DmaMethodCore* NeoEsp8266DmaMethodCore::s_this; #endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h new file mode 100644 index 0000000000..7a8a32330c --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266DmaMethod.h @@ -0,0 +1,612 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for Esp8266. + + +Written by Michael C. Miller. +Thanks to g3gg0.de for porting the initial DMA support which lead to this. +Thanks to github/cnlohr for the original work on DMA support, which opend +all our minds to a better way (located at https://github.com/cnlohr/esp8266ws2812i2s). + +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 "Arduino.h" + +extern "C" +{ +#include "osapi.h" +#include "ets_sys.h" + +#include "i2s_reg.h" + +#ifdef ARDUINO_ESP8266_MAJOR //this define was added in ESP8266 Arduino Core version v3.0.1 + #include "core_esp8266_i2s.h" //for Arduino core >= 3.0.1 +#else + #include "i2s.h" //for Arduino core <= 3.0.0 +#endif + +#include "eagle_soc.h" +#include "esp8266_peri.h" +#include "slc_register.h" + +#include "osapi.h" +#include "ets_sys.h" +#include "user_interface.h" + +#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 +} + +struct slc_queue_item +{ + uint32 blocksize : 12; + uint32 datalen : 12; + uint32 unused : 5; + uint32 sub_sof : 1; + uint32 eof : 1; + uint32 owner : 1; + uint8* buf_ptr; + struct slc_queue_item* next_link_ptr; +}; + +class NeoEsp8266DmaSpeedBase +{ +public: + static const uint8_t Level = 0x00; + static uint16_t Convert(uint8_t value) + { + const uint16_t bitpatterns[16] = + { + 0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110, + 0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110, + 0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110, + 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, + }; + + return bitpatterns[value]; + } +}; + +class NeoEsp8266DmaInvertedSpeedBase +{ +public: + static const uint8_t Level = 0xFF; + static uint16_t Convert(uint8_t value) + { + const uint16_t bitpatterns[16] = + { + 0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001, + 0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001, + 0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001, + 0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001, + }; + + return bitpatterns[value]; + } +}; + +class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase +{ +public: + const static uint32_t I2sClockDivisor = 3; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed +}; + +class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 80; +}; + +class NeoEsp8266DmaInvertedSpeedTm1814 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaInvertedSpeedTm1829 : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 50; +}; + +class NeoEsp8266DmaSpeed400Kbps : public NeoEsp8266DmaSpeedBase +{ +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 NeoEsp8266DmaSpeedBase +{ +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; +}; + + + +class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase +{ +public: + const static uint32_t I2sClockDivisor = 3; + const static uint32_t I2sBaseClockDivisor = 16; + const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed +}; + +class NeoEsp8266DmaInvertedSpeedWs2812x : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 300; +}; + +class NeoEsp8266DmaInvertedSpeedSk6812 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 80; +}; + +class NeoEsp8266DmaSpeedTm1814 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaSpeedTm1829 : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 200; +}; + +class NeoEsp8266DmaInvertedSpeed800Kbps : public NeoEsp8266DmaInvertedSpeed800KbpsBase +{ +public: + const static uint32_t ResetTimeUs = 50; +}; + +class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase +{ +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 NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase +{ +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; +const uint8_t c_I2sPin = 3; // due to I2S hardware, the pin used is restricted to this + +class NeoEsp8266DmaMethodCore +{ +protected: + static NeoEsp8266DmaMethodCore* s_this; // for the ISR + + volatile NeoDmaState _dmaState; + + slc_queue_item* _i2sBufDesc; // dma block descriptors + uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc + + + // This routine is called as soon as the DMA routine has something to tell us. All we + // handle here is the RX_EOF_INT status, which indicate the DMA has sent a buffer whose + // descriptor has the 'EOF' field set to 1. + // in the case of this code, the second to last state descriptor + static void IRAM_ATTR i2s_slc_isr(void) + { + ETS_SLC_INTR_DISABLE(); + + uint32_t slc_intr_status = SLCIS; + + SLCIC = 0xFFFFFFFF; + + if ((slc_intr_status & SLCIRXEOF) && s_this) + { + switch (s_this->_dmaState) + { + case NeoDmaState_Idle: + break; + + case NeoDmaState_Pending: + { + 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 + (finished_item + 1)->next_link_ptr = s_this->_i2sBufDesc; + + s_this->_dmaState = NeoDmaState_Sending; + } + break; + + case NeoDmaState_Sending: + { + slc_queue_item* finished_item = (slc_queue_item*)SLCRXEDA; + + // the data block had actual data sent + // point last state block to first state block thus + // just looping and not sending the data blocks + (finished_item + 1)->next_link_ptr = finished_item; + + s_this->_dmaState = NeoDmaState_Zeroing; + } + break; + + case NeoDmaState_Zeroing: + s_this->_dmaState = NeoDmaState_Idle; + break; + } + } + + ETS_SLC_INTR_ENABLE(); + } +}; + +template class NeoEsp8266DmaMethodBase : NeoEsp8266DmaMethodCore +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEsp8266DmaMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize) + { + uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize; + uint16_t dmaSettingsSize = c_dmaBytesPerPixelBytes * settingsSize; + + _i2sBufferSize = pixelCount * dmaPixelSize + dmaSettingsSize; + + _data = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + + _i2sBuffer = static_cast(malloc(_i2sBufferSize)); + // no need to initialize it, it gets overwritten on every send + + // _i2sBuffer[0] = 0b11101000; // debug, 1 bit then 0 bit + + memset(_i2sZeroes, T_SPEED::Level, sizeof(_i2sZeroes)); + + _is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize; + + _i2sBufDescCount = (_i2sBufferSize / _is2BufMaxBlockSize) + 1 + 2; // need two more for state/latch blocks + _i2sBufDesc = (slc_queue_item*)malloc(_i2sBufDescCount * sizeof(slc_queue_item)); + + s_this = this; // store this for the ISR + } + + NeoEsp8266DmaMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + NeoEsp8266DmaMethodBase(pixelCount, elementSize, settingsSize) + { + } + + ~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(_data); + free(_i2sBuffer); + free(_i2sBufDesc); + } + + bool IsReadyToUpdate() const + { + return (_dmaState == NeoDmaState_Idle); + } + + void Initialize() + { + StopDma(); + + pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA + + uint8_t* is2Buffer = _i2sBuffer; + uint32_t is2BufferSize = _i2sBufferSize; + uint16_t indexDesc; + + // prepare main data block decriptors that point into our one static dma buffer + for (indexDesc = 0; indexDesc < (_i2sBufDescCount - 2); indexDesc++) + { + uint32_t blockSize = (is2BufferSize > _is2BufMaxBlockSize) ? _is2BufMaxBlockSize : is2BufferSize; + + _i2sBufDesc[indexDesc].owner = 1; + _i2sBufDesc[indexDesc].eof = 0; // no need to trigger interrupt generally + _i2sBufDesc[indexDesc].sub_sof = 0; + _i2sBufDesc[indexDesc].datalen = blockSize; + _i2sBufDesc[indexDesc].blocksize = blockSize; + _i2sBufDesc[indexDesc].buf_ptr = is2Buffer; + _i2sBufDesc[indexDesc].unused = 0; + _i2sBufDesc[indexDesc].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc + 1])); + + is2Buffer += blockSize; + is2BufferSize -= blockSize; + } + + // prepare the two state/latch descriptors + for (; indexDesc < _i2sBufDescCount; indexDesc++) + { + _i2sBufDesc[indexDesc].owner = 1; + _i2sBufDesc[indexDesc].eof = 0; // no need to trigger interrupt generally + _i2sBufDesc[indexDesc].sub_sof = 0; + _i2sBufDesc[indexDesc].datalen = sizeof(_i2sZeroes); + _i2sBufDesc[indexDesc].blocksize = sizeof(_i2sZeroes); + _i2sBufDesc[indexDesc].buf_ptr = _i2sZeroes; + _i2sBufDesc[indexDesc].unused = 0; + _i2sBufDesc[indexDesc].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc + 1])); + } + + // the first state block will trigger the interrupt + _i2sBufDesc[indexDesc - 2].eof = 1; + // the last state block will loop to the first state block by defualt + _i2sBufDesc[indexDesc - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[indexDesc - 2])); + + // 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; + + // Configure DMA + SLCC0 &= ~(SLCMM << SLCM); // clear DMA MODE + SLCC0 |= (1 << SLCM); // set DMA MODE to 1 + SLCRXDC |= SLCBINR | SLCBTNR; // enable INFOR_NO_REPLACE and TOKEN_NO_REPLACE + SLCRXDC &= ~(SLCBRXFE | SLCBRXEM | SLCBRXFM); // disable RX_FILL, RX_EOF_MODE and RX_FILL_MODE + + // Feed DMA the 1st buffer desc addr + // To send data to the I2S subsystem, counter-intuitively we use the RXLINK part, not the TXLINK as you might + // 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 + // 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 + // 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 + + ETS_SLC_INTR_ENABLE(); + + //Start transmission + SLCTXL |= SLCTXLS; + SLCRXL |= SLCRXLS; + + I2S_CLK_ENABLE(); + I2SIC = 0x3F; + I2SIE = 0; + + //Reset I2S + I2SC &= ~(I2SRST); + I2SC |= I2SRST; + I2SC &= ~(I2SRST); + + // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) + I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); + I2SFC |= I2SDE; //Enable DMA + // 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 | 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 IRAM_ATTR Update(bool) + { + // wait for not actively sending data + while (!IsReadyToUpdate()) + { + yield(); + } + FillBuffers(); + + // toggle state so the ISR reacts + _dmaState = NeoDmaState_Pending; + } + + uint8_t* getData() const + { + return _data; + }; + + size_t getDataSize() const + { + return _sizeData; + } + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data' buffer + uint8_t* _data; // Holds LED color values + + size_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 mulitple states + // buffer size = (24 * (reset time / 50)) / 6 + uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 6L]; + + uint16_t _is2BufMaxBlockSize; // max size based on size of a pixel of a single block + + + void FillBuffers() + { + uint16_t* pDma = (uint16_t*)_i2sBuffer; + uint8_t* pEnd = _data + _sizeData; + for (uint8_t* pData = _data; pData < pEnd; pData++) + { + *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); + *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); + } + } + + 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 + SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address + + pinMode(c_I2sPin, INPUT); + } + + uint32_t getPixelTime() const + { + return (T_SPEED::ByteSendTimeUs * this->_sizeData); + }; + +}; + + + +// normal +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaWs2812xMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaSk6812Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaTm1814Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaTm1829Method; +typedef NeoEsp8266DmaTm1814Method NeoEsp8266DmaTm1914Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma800KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266Dma400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaApa106Method; + + +// inverted +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedWs2812xMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedSk6812Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedTm1814Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedTm1829Method; +typedef NeoEsp8266DmaInvertedTm1814Method NeoEsp8266DmaInvertedTm1914Method; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInverted800KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInverted400KbpsMethod; +typedef NeoEsp8266DmaMethodBase NeoEsp8266DmaInvertedApa106Method; + +// Dma method is the default method for Esp8266 +typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; +typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; +typedef NeoEsp8266DmaWs2812xMethod NeoWs2811Method; +typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; +typedef NeoEsp8266DmaTm1814Method NeoTm1814Method; +typedef NeoEsp8266DmaTm1829Method NeoTm1829Method; +typedef NeoEsp8266DmaTm1914Method NeoTm1914Method; +typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; +typedef NeoEsp8266DmaApa106Method NeoApa106Method; + +typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; +typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; + +// inverted +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2813InvertedMethod; +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2812xInvertedMethod; +typedef NeoEsp8266DmaInverted800KbpsMethod NeoWs2812InvertedMethod; +typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2811InvertedMethod; +typedef NeoEsp8266DmaInvertedSk6812Method NeoSk6812InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1814Method NeoTm1814InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1829Method NeoTm1829InvertedMethod; +typedef NeoEsp8266DmaInvertedTm1914Method NeoTm1914InvertedMethod; +typedef NeoEsp8266DmaInvertedSk6812Method NeoLc8812InvertedMethod; +typedef NeoEsp8266DmaInvertedApa106Method NeoApa106InvertedMethod; + +typedef NeoEsp8266DmaInvertedWs2812xMethod Neo800KbpsInvertedMethod; +typedef NeoEsp8266DmaInverted400KbpsMethod Neo400KbpsInvertedMethod; +#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp rename to lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp index cde0c4a4b7..66324b9d58 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.cpp +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.cpp @@ -24,12 +24,10 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include "../NeoUtil.h" - #ifdef ARDUINO_ARCH_ESP8266 #include -#include "../NeoSettings.h" +#include "NeoSettings.h" #include "NeoEsp8266UartMethod.h" #include extern "C" @@ -141,9 +139,7 @@ void NeoEsp8266UartInterruptContext::Detach(uint8_t uartNum) ETS_UART_INTR_ENABLE(); } -// The xtos_1int handler calls with param1 as the arg, param2 as a pointer -// to an exception frame in memory. -void IRAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param, MAYBE_UNUSED void* exceptionFrame) +void IRAM_ATTR NeoEsp8266UartInterruptContext::Isr(void* param) { // make sure this is for us if (param == s_uartInteruptContext) diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h rename to lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h index 073b5edaff..9ef2f4b453 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266UartMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp8266UartMethod.h @@ -26,9 +26,8 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #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 @@ -80,7 +79,7 @@ class NeoEsp8266UartInterruptContext : NeoEsp8266UartContext volatile const uint8_t* _asyncBuffEnd; volatile static NeoEsp8266UartInterruptContext* s_uartInteruptContext[2]; - static void IRAM_ATTR Isr(void* param, void* exceptionFrame); + static void IRAM_ATTR Isr(void* param); }; // this template feature class is used a base for all others and contains @@ -165,8 +164,6 @@ class NeoEsp8266UartBase // synchronous uart method // // used by NeoEsp8266UartMethodBase -// T_UARTFEATURE - (UartFeature0 | UartFeature1) -// T_UARTCONTEXT - (NeoEsp8266UartContext | NeoEsp8266UartInterruptContext) // template class NeoEsp8266Uart : public NeoEsp8266UartBase { @@ -221,8 +218,6 @@ template class NeoEsp8266Uart : // every call to NeoPixelBus.Show() and must not be cached. // // used by NeoEsp8266UartMethodBase -// T_UARTFEATURE - (UartFeature0 | UartFeature1) -// T_UARTCONTEXT - (NeoEsp8266UartContext | NeoEsp8266UartInterruptContext) // template class NeoEsp8266AsyncUart : public NeoEsp8266UartBase { @@ -354,11 +349,6 @@ class NeoEsp8266UartInverted // NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that // implements the methods needed to operate as a NeoPixelBus method. -// -// T_SPEED - (NeoEsp8266UartSpeed*) -// T_BASE - (NeoEsp8266Uart | NeoEsp8266AsyncUart) -// T_INVERT - (NeoEsp8266UartNotInverted | NeoEsp8266UartInverted) -// template class NeoEsp8266UartMethodBase: public T_BASE { @@ -406,12 +396,6 @@ class NeoEsp8266UartMethodBase: public T_BASE this->UpdateUart(maintainBufferConsistency); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return this->_data; @@ -422,7 +406,7 @@ class NeoEsp8266UartMethodBase: public T_BASE return this->_sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -445,7 +429,6 @@ typedef NeoEsp8266UartMethodBase +// ESP32C3 I2S is not supported yet +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +#if !defined(ARDUINO_ARCH_ESP8266) +#include "soc/gpio_periph.h" +#endif + static inline uint32_t getCycleCount(void) { uint32_t ccount; - -#if defined(CONFIG_IDF_TARGET_ESP32C3) - __asm__ __volatile__("csrr %0,0x7e2":"=r" (ccount)); - //ccount = esp_cpu_get_ccount(); -#else __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); -#endif return ccount; } -void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, - const uint8_t* end, - uint8_t pin, - uint32_t t0h, - uint32_t t1h, - uint32_t period, - size_t sizePixel, - uint32_t tSpacing, - bool invert) +void IRAM_ATTR NeoEspBitBangBase_send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) { - uint32_t setValue = _BV(pin); - uint32_t clearValue = _BV(pin); + const uint32_t pinRegister = _BV(pin); uint8_t mask = 0x80; uint8_t subpix = *pixels++; - uint8_t element = 0; 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 = t0h; + if (subpix & mask) + { + cyclesBit = t1h; + } + + // after we have done as much work as needed for this next bit + // now wait for the HIGH + while (((cyclesStart = getCycleCount()) - cyclesNext) < period); + + // set pin state #if defined(ARDUINO_ARCH_ESP32) -#if defined(CONFIG_IDF_TARGET_ESP32C3) - volatile uint32_t* setRegister = &GPIO.out_w1ts.val; - volatile uint32_t* clearRegister = &GPIO.out_w1tc.val; - setValue = _BV(pin); - clearValue = _BV(pin); + GPIO.out_w1ts = pinRegister; #else - volatile uint32_t* setRegister = &GPIO.out_w1ts; - volatile uint32_t* clearRegister = &GPIO.out_w1tc; -#endif // defined(CONFIG_IDF_TARGET_ESP32C3) + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); +#endif + + // wait for the LOW + while ((getCycleCount() - cyclesStart) < cyclesBit); + + // reset pin start +#if defined(ARDUINO_ARCH_ESP32) + GPIO.out_w1tc = pinRegister; #else - uint32_t setRegister = PERIPHS_GPIO_BASEADDR + GPIO_OUT_W1TS_ADDRESS; - uint32_t clearRegister = PERIPHS_GPIO_BASEADDR + GPIO_OUT_W1TC_ADDRESS; - if (pin == 16) - { - setRegister = RTC_GPIO_OUT; - clearRegister = RTC_GPIO_OUT; - // reading AND writing RTC_GPIO_OUT is too slow inside the loop so - // we only do writing in the loop - clearValue = (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe); - setValue = clearValue | 1; - } -#endif // defined(ARDUINO_ARCH_ESP32) + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); +#endif - if (invert) - { - std::swap(setRegister, clearRegister); - std::swap(setValue, clearValue); + 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 IRAM_ATTR NeoEspBitBangBase_send_pixels_inv(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) +{ + 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 (;;) { @@ -104,9 +122,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // set pin state #if defined(ARDUINO_ARCH_ESP32) - *setRegister = setValue; + GPIO.out_w1tc = pinRegister; #else - WRITE_PERI_REG(setRegister, setValue); + GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister); #endif // wait for the LOW @@ -114,9 +132,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // reset pin start #if defined(ARDUINO_ARCH_ESP32) - *clearRegister = clearValue; + GPIO.out_w1ts = pinRegister; #else - WRITE_PERI_REG(clearRegister, clearValue); + GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister); #endif cyclesNext = cyclesStart; @@ -135,22 +153,9 @@ void IRAM_ATTR neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, // reset mask to first bit and get the next byte mask = 0x80; subpix = *pixels++; - - // if pixel spacing is needed - if (tSpacing) - { - element++; - if (element == sizePixel) - { - element = 0; - - // wait for pixel spacing - while ((getCycleCount() - cyclesNext) < tSpacing); - } - } } } } - +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) #endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h b/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h new file mode 100644 index 0000000000..44f8654889 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoEspBitBangMethod.h @@ -0,0 +1,381 @@ +/*------------------------------------------------------------------------- +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 +. +-------------------------------------------------------------------------*/ + +#pragma once + +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + +// ESP32C3 I2S is not supported yet +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) + +#if defined(ARDUINO_ARCH_ESP8266) +#include +#endif + +#define CYCLES_LOOPTEST (4) // adjustment due to loop exit test instruction cycles + +class NeoEspSpeedWs2811 +{ +public: + const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us + const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeedTm1814 +{ +public: + const static uint32_t T0H = (F_CPU / 2916666 - CYCLES_LOOPTEST); // 0.35us + const static uint32_t T1H = (F_CPU / 1666666 - CYCLES_LOOPTEST); // 0.75us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeedTm1829 +{ +public: + const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us + const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeed800Mhz +{ +public: + const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us + const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us + const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit +}; + +class NeoEspSpeed400Mhz +{ +public: + const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST); + const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST); + const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST); +}; + +class NeoEspSpeedApa106 +{ +public: + const static uint32_t T0H = (F_CPU / 2857143 - CYCLES_LOOPTEST); // 0.35us + const static uint32_t T1H = (F_CPU / 740741 - CYCLES_LOOPTEST); // 1.35 + const static uint32_t Period = (F_CPU / 606061 - CYCLES_LOOPTEST); // 1.65us +}; + +extern void NeoEspBitBangBase_send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period); +extern void NeoEspBitBangBase_send_pixels_inv(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period); + +class NeoEspPinset +{ +public: + const static uint8_t IdleLevel = LOW; + + inline static void send_pixels_impl(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) + { + NeoEspBitBangBase_send_pixels(pixels, end, pin, t0h, t1h, period); + } +}; + +class NeoEspPinsetInverted +{ +public: + const static uint8_t IdleLevel = HIGH; + + inline static void send_pixels_impl(uint8_t* pixels, uint8_t* end, uint8_t pin, uint32_t t0h, uint32_t t1h, uint32_t period) + { + NeoEspBitBangBase_send_pixels_inv(pixels, end, pin, t0h, t1h, period); + } +}; + +template class NeoEspBitBangBase +{ +public: + static void send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin) + { + T_PINSET::send_pixels_impl(pixels, end, pin, T_SPEED::T0H, T_SPEED::T1H, T_SPEED::Period); + } +}; + +class NeoEspBitBangSpeedWs2811 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangSpeedWs2812x : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangSpeedSk6812 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +// normal is inverted signal +class NeoEspBitBangSpeedTm1814 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +// normal is inverted signal +class NeoEspBitBangSpeedTm1829 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +class NeoEspBitBangSpeed800Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangSpeed400Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangSpeedApa106 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeedWs2811 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangInvertedSpeedWs2812x : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 300; +}; + +class NeoEspBitBangInvertedSpeedSk6812 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 80; +}; + +// normal is inverted signal, so inverted is normal +class NeoEspBitBangInvertedSpeedTm1814 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +// normal is inverted signal, so inverted is normal +class NeoEspBitBangInvertedSpeedTm1829 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 200; +}; + +class NeoEspBitBangInvertedSpeed800Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeed400Kbps : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +class NeoEspBitBangInvertedSpeedApa106 : public NeoEspBitBangBase +{ +public: + static const uint32_t ResetTimeUs = 50; +}; + +template class NeoEspBitBangMethodBase +{ +public: + typedef NeoNoSettings SettingsObject; + + NeoEspBitBangMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + _pin(pin) + { + pinMode(pin, OUTPUT); + + _data = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + } + + ~NeoEspBitBangMethodBase() + { + pinMode(_pin, INPUT); + + free(_data); + } + + bool IsReadyToUpdate() const + { + uint32_t delta = micros() - _endTime; + + return (delta >= T_SPEED::ResetTimeUs); + } + + void Initialize() + { + digitalWrite(_pin, T_PINSET::IdleLevel); + + _endTime = micros(); + } + + 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 + // 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 (!IsReadyToUpdate()) + { + yield(); // allows for system yield if needed + } + + // 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(_data, _data + _sizeData, _pin); + +#if defined(ARDUINO_ARCH_ESP32) + portEXIT_CRITICAL(&updateMux); +#else + interrupts(); +#endif + + // save EOD time for latch on next call + _endTime = micros(); + } + + uint8_t* getData() const + { + return _data; + }; + + size_t getDataSize() const + { + return _sizeData; + }; + + void applySettings(const SettingsObject& settings) + { + } + +private: + const size_t _sizeData; // Size of '_data' buffer below + const uint8_t _pin; // output pin number + + uint32_t _endTime; // Latch timing reference + uint8_t* _data; // Holds LED color values +}; + + +#if defined(ARDUINO_ARCH_ESP32) + +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2811Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangSk6812Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1814Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1829Method; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang800KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang400KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangApa106Method; + +typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; +typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; +typedef NeoEsp32BitBangTm1814Method NeoEsp32BitBangTm1914Method; +typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; + +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2811InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangWs2812xInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangSk6812InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1814InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangTm1829InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang800KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBang400KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp32BitBangApa106InvertedMethod; + +typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2813InvertedMethod; +typedef NeoEsp32BitBang800KbpsInvertedMethod NeoEsp32BitBangWs2812InvertedMethod; +typedef NeoEsp32BitBangTm1814InvertedMethod NeoEsp32BitBangTm1914InvertedMethod; +typedef NeoEsp32BitBangSk6812InvertedMethod NeoEsp32BitBangLc8812InvertedMethod; + +#else + +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2811Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2812xMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangSk6812Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1814Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1829Method; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang800KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400KbpsMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangApa106Method; + +typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method; +typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method; +typedef NeoEsp8266BitBangTm1814Method NeoEsp8266BitBangTm1914Method; +typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method; + +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2811InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangWs2812xInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangSk6812InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1814InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangTm1829InvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang800KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBang400KbpsInvertedMethod; +typedef NeoEspBitBangMethodBase NeoEsp8266BitBangApa106InvertedMethod; + +typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2813InvertedMethod; +typedef NeoEsp8266BitBang800KbpsInvertedMethod NeoEsp8266BitBangWs2812InvertedMethod; +typedef NeoEsp8266BitBangTm1814InvertedMethod NeoEsp8266BitBangTm1914InvertedMethod; +typedef NeoEsp8266BitBangSk6812InvertedMethod NeoEsp8266BitBangLc8812InvertedMethod; + +#endif + +// ESP bitbang doesn't have defaults and should avoided except for testing + +#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C6) +#endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp b/lib/NeoPixelBus/src/internal/NeoGamma.cpp similarity index 62% rename from lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp rename to lib/NeoPixelBus/src/internal/NeoGamma.cpp index f1d8782527..fdff9e784f 100644 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.cpp +++ b/lib/NeoPixelBus/src/internal/NeoGamma.cpp @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoGamma classes are used to correct RGB colors for human eye gamma levels +NeoPixelGamma class is used to correct RGB colors for human eye gamma levels Written by Michael C. Miller. @@ -25,24 +25,23 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include -#include "../NeoUtil.h" -#include "NeoGammaTableMethod.h" +#include "NeoPixelBus.h" const uint8_t NeoGammaTableMethod::_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, // 32 - 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, // 48 - 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, // 64 - 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, // 80 - 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, // 96 - 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, // 112 - 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, // 128 - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, // 144 - 71, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, // 160 - 90, 91, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, // 176 - 111, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, // 192 - 135, 137, 138, 140, 142, 143, 145, 146, 148, 150, 151, 153, 155, 156, 158, 160, // 208 - 162, 163, 165, 167, 168, 170, 172, 174, 176, 177, 179, 181, 183, 185, 187, 189, // 224 - 190, 192, 194, 196, 198, 200, 202, 203, 206, 207, 210, 212, 214, 216, 218, 220, // 240 - 222, 224, 226, 228, 230, 232, 234, 237, 239, 241, 243, 245, 247, 250, 251, 255 // 256 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, + 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, + 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, + 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, + 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, + 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, + 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 86, 87, 88, 89, + 91, 92, 93, 94, 96, 97, 98, 100, 101, 102, 104, 105, 106, 108, 109, 110, + 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, 126, 128, 130, 131, 133, 134, + 136, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 155, 157, 159, 160, + 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 187, 189, + 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, + 223, 225, 227, 229, 231, 233, 235, 238, 240, 242, 244, 246, 248, 251, 253, 255 }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h b/lib/NeoPixelBus/src/internal/NeoGamma.h similarity index 60% rename from lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h rename to lib/NeoPixelBus/src/internal/NeoGamma.h index 19ce6879ca..4aaf68e4a8 100644 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaEquationMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoGamma.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoGammaEquationMethod class is used to correct RGB colors for human eye gamma levels equally +NeoGamma class is used to correct RGB colors for human eye gamma levels equally across all color channels Written by Michael C. Miller. @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once - // NeoGammaEquationMethod uses no memory but is slower than NeoGammaTableMethod class NeoGammaEquationMethod { @@ -35,10 +34,41 @@ class NeoGammaEquationMethod { return static_cast(255.0f * NeoEase::Gamma(value / 255.0f) + 0.5f); } - static uint16_t Correct(uint16_t value) +}; + +// NeoGammaTableMethod uses 256 bytes of memory, but is significantly faster +class NeoGammaTableMethod +{ +public: + static uint8_t Correct(uint8_t value) + { + return _table[value]; + } + +private: + static const uint8_t _table[256]; +}; + + +// use one of the method classes above as a converter for this template class +template class NeoGamma +{ +public: + RgbColor Correct(const RgbColor& original) + { + return RgbColor(T_METHOD::Correct(original.R), + T_METHOD::Correct(original.G), + T_METHOD::Correct(original.B)); + } + + RgbwColor Correct(const RgbwColor& original) { - return static_cast(65535.0f * NeoEase::Gamma(value / 65535.0f) + 0.5f); + return RgbwColor(T_METHOD::Correct(original.R), + T_METHOD::Correct(original.G), + T_METHOD::Correct(original.B), + T_METHOD::Correct(original.W) ); } }; + diff --git a/lib/NeoPixelBus/src/internal/colors/NeoHueBlend.h b/lib/NeoPixelBus/src/internal/NeoHueBlend.h similarity index 100% rename from lib/NeoPixelBus/src/internal/colors/NeoHueBlend.h rename to lib/NeoPixelBus/src/internal/NeoHueBlend.h diff --git a/lib/NeoPixelBus/src/internal/NeoMethods.h b/lib/NeoPixelBus/src/internal/NeoMethods.h deleted file mode 100644 index 27ac2bcfcd..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoMethods.h +++ /dev/null @@ -1,71 +0,0 @@ -/*------------------------------------------------------------------------- -NeoMethods includes all the classes that describe pulse/data sending methods using -bitbang, SPI, or other platform specific hardware peripherl support. - -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 - -// Generic Two Wire (clk and data) methods -// -#include "methods/DotStarGenericMethod.h" -#include "methods/Lpd8806GenericMethod.h" -#include "methods/Lpd6803GenericMethod.h" -#include "methods/Ws2801GenericMethod.h" -#include "methods/P9813GenericMethod.h" -#include "methods/Tlc5947GenericMethod.h" -#include "methods/Sm16716GenericMethod.h" -#include "methods/Mbi6033GenericMethod.h" - -// Platform specific and One Wire (data) methods -// -#if defined(ARDUINO_ARCH_ESP8266) - -#include "methods/NeoEsp8266DmaMethod.h" -#include "methods/NeoEsp8266I2sDmx512Method.h" -#include "methods/NeoEsp8266UartMethod.h" -#include "methods/NeoEspBitBangMethod.h" - -#elif defined(ARDUINO_ARCH_ESP32) - -#include "methods/NeoEsp32I2sMethod.h" -#include "methods/NeoEsp32RmtMethod.h" -#include "methods/NeoEspBitBangMethod.h" -#include "methods/DotStarEsp32DmaSpiMethod.h" -#include "methods/NeoEsp32I2sXMethod.h" - -#elif defined(ARDUINO_ARCH_NRF52840) // must be before __arm__ - -#include "methods/NeoNrf52xMethod.h" - -#elif defined(__arm__) // must be before ARDUINO_ARCH_AVR due to Teensy incorrectly having it set - -#include "methods/NeoArmMethod.h" - -#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) - -#include "methods/NeoAvrMethod.h" - -#else -#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus" -#endif diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h b/lib/NeoPixelBus/src/internal/NeoMosaic.h similarity index 91% rename from lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h rename to lib/NeoPixelBus/src/internal/NeoMosaic.h index c42ba0d404..551bd53773 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoMosaic.h +++ b/lib/NeoPixelBus/src/internal/NeoMosaic.h @@ -1,5 +1,7 @@ +#pragma once + /*------------------------------------------------------------------------- -NeoMosaic provides a mapping feature of a 2d cordinate to linear 1d cordinate +Mosiac provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus where the the matricies use a set of prefered topology and the tiles of those matricies use the RowMajorAlternating layout @@ -26,7 +28,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once //----------------------------------------------------------------------------- @@ -35,12 +36,6 @@ License along with NeoPixel. If not, see // the tiles by using different rotations of the layout at specific locations // // T_LAYOUT = the layout used for matrix panel (rotation is ignored) -// One of the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout -// // // NOTE: The tiles in the mosaic are always laid out using RowMajorAlternating // @@ -63,7 +58,7 @@ template class NeoMosaic uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x >= static_cast(totalWidth)) + if (x >= totalWidth) { x = totalWidth - 1; } @@ -72,7 +67,7 @@ template class NeoMosaic x = 0; } - if (y >= static_cast(totalHeight)) + if (y >= totalHeight) { y = totalHeight - 1; } @@ -112,8 +107,7 @@ template class NeoMosaic uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x < 0 || x >= static_cast(totalWidth) || - y < 0 || y >= static_cast(totalHeight)) + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) { return NeoTopologyHint_OutOfBounds; } diff --git a/lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h b/lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h similarity index 95% rename from lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h rename to lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h index 5d085d1e32..da97fe7752 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoNrf52xMethod.h +++ b/lib/NeoPixelBus/src/internal/NeoNrf52xMethod.h @@ -29,8 +29,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #if defined(ARDUINO_ARCH_NRF52840) const uint16_t c_dmaBytesPerDataByte = 8 * sizeof(nrf_pwm_values_common_t); // bits * bytes to represent pulse @@ -402,12 +400,6 @@ template class NeoNrf52xMethodBase dmaStart(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -418,7 +410,7 @@ template class NeoNrf52xMethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } @@ -526,7 +518,6 @@ template class NeoNrf52xMethodBase // normal typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNSk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1829Method; @@ -538,7 +529,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1829Method; @@ -550,7 +540,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1829Method; @@ -562,7 +551,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1829Method; @@ -575,7 +563,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw #if defined(NRF_PWM3) typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2811Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2812xMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2816Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Sk6812Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1814Method; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1829Method; @@ -589,7 +576,6 @@ typedef NeoNrf52xMethodBase NeoNrf52xPw // inverted typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwmNWs2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNSk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwmNTm1829InvertedMethod; @@ -601,7 +587,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm0Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm0Tm1829InvertedMethod; @@ -613,7 +598,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm1Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm1Tm1829InvertedMethod; @@ -625,7 +609,6 @@ typedef NeoNrf52xMethodBase Neo typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm2Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm2Tm1829InvertedMethod; @@ -638,7 +621,6 @@ typedef NeoNrf52xMethodBase Neo #if defined(NRF_PWM3) typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2811InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2812xInvertedMethod; -typedef NeoNrf52xMethodBase NeoNrf52xPwm3Ws2816InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Sk6812InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1814InvertedMethod; typedef NeoNrf52xMethodBase NeoNrf52xPwm3Tm1829InvertedMethod; @@ -654,7 +636,6 @@ typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2813Method; typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2812xMethod; typedef NeoNrf52xPwm2800KbpsMethod NeoWs2812Method; typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2811Method; -typedef NeoNrf52xPwm2Ws2812xMethod NeoWs2816Method; typedef NeoNrf52xPwm2Sk6812Method NeoSk6812Method; typedef NeoNrf52xPwm2Tm1814Method NeoTm1814Method; typedef NeoNrf52xPwm2Tm1829Method NeoTm1829Method; @@ -670,7 +651,6 @@ typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2813InvertedMethod; typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoNrf52xPwm2800KbpsInvertedMethod NeoWs2812InvertedMethod; -typedef NeoNrf52xPwm2Ws2812xInvertedMethod NeoWs2816InvertedMethod; typedef NeoNrf52xPwm2Sk6812InvertedMethod NeoSk6812InvertedMethod; typedef NeoNrf52xPwm2Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoNrf52xPwm2Tm1829InvertedMethod NeoTm1829InvertedMethod; diff --git a/lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp b/lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp similarity index 99% rename from lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp rename to lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp index b97565fa7f..55e74ae218 100644 --- a/lib/NeoPixelBus/src/internal/animations/NeoPixelAnimator.cpp +++ b/lib/NeoPixelBus/src/internal/NeoPixelAnimator.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "NeoPixelBus.h" #include "NeoPixelAnimator.h" diff --git a/lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c b/lib/NeoPixelBus/src/internal/NeoPixelAvr.c similarity index 81% rename from lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c rename to lib/NeoPixelBus/src/internal/NeoPixelAvr.c index e6572c6747..84e989388b 100644 --- a/lib/NeoPixelBus/src/internal/methods/NeoPixelAvr.c +++ b/lib/NeoPixelBus/src/internal/NeoPixelAvr.c @@ -466,10 +466,7 @@ void send_data_12mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask) [lo] "r" (lo)); } -void send_data_12mhz_400(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) +void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { volatile uint16_t i = (uint16_t)sizeData; // Loop counter volatile uint8_t* ptr = data; // Pointer to next byte @@ -480,8 +477,7 @@ void send_data_12mhz_400(uint8_t* data, // 30 instruction clocks per bit: HHHHHHxxxxxxxxxLLLLLLLLLLLLLLL // ST instructions: ^ ^ ^ (T=0,6,15) - volatile uint8_t next; - volatile uint8_t bit; + volatile uint8_t next, bit; hi = *port | pinMask; lo = *port & ~pinMask; @@ -524,7 +520,7 @@ void send_data_12mhz_400(uint8_t* data, [ptr] "e" (ptr)); } -#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000UL) // 16Mhz CPU +#elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { @@ -581,10 +577,7 @@ void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, [lo] "r" (lo)); } -void send_data_16mhz_400(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) +void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { volatile size_t i = sizeData; // Loop counter volatile uint8_t* ptr = data; // Pointer to next byte @@ -597,8 +590,7 @@ void send_data_16mhz_400(uint8_t* data, // 40 inst. clocks per bit: HHHHHHHHxxxxxxxxxxxxLLLLLLLLLLLLLLLLLLLL // ST instructions: ^ ^ ^ (T=0,8,20) - volatile uint8_t next; - volatile uint8_t bit; + volatile uint8_t next, bit; hi = *port | pinMask; lo = *port & ~pinMask; @@ -649,137 +641,6 @@ void send_data_16mhz_400(uint8_t* data, [lo] "r" (lo)); } -// 0 400us (320-480) -// 1 1100us (960-1200) -// w 1600us -void send_data_16mhz_600(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask) -{ - volatile size_t i = sizeData; // Loop counter - volatile uint8_t* ptr = data; // Pointer to next byte - volatile uint8_t b = *ptr++; // Current byte value - volatile uint8_t hi; // PORT w/output bit set high - volatile uint8_t lo; // PORT w/output bit set low - - // The 633 KHz clock on 16 MHz MCU. - // - // 25 inst. clocks per bit: HHHHHHHHxxxxxxxxxxLLLLLLLL - // ST instructions: ^ ^ ^ (T=0,8,18) - - - volatile uint8_t next; - volatile uint8_t bit; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - - asm volatile( - "head40:" "\n\t" // Clk Pseudocode (T = 0) - "st %a[port], %[hi]" "\n\t" // 2 PORT = hi (T = 2) - "sbrc %[byte] , 7" "\n\t" // 1-2 if(b & 0b10000000) - "mov %[next] , %[hi]" "\n\t" // 0-1 next = hi (T = 4) - "rjmp .+0" "\n\t" // 2 nop nop (T = 6) - "st %a[port], %[next]" "\n\t" // 2 PORT = next (T = 8) - "mov %[next] , %[lo]" "\n\t" // 1 next = lo (T = 9) - "rjmp .+0" "\n\t" // 2 nop nop (T = 11) - "rjmp .+0" "\n\t" // 2 nop nop (T = 13) - "rjmp .+0" "\n\t" // 2 nop nop (T = 15) - "dec %[bit]" "\n\t" // 1 bit-- (T = 16) - "breq nextbyte40" "\n\t" // 1-2 if(bit == 0) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 18) duplicate here improves high length for non byte boundary - "rol %[byte]" "\n\t" // 1 b <<= 1 (T = 21) - "nop" "\n\t" // 1 nop (T = 22) - "rjmp .+0" "\n\t" // 2 nop nop (T = 24) - "rjmp head40" "\n\t" // 2 -> head40 (next bit out) - "nextbyte40:" "\n\t" // (T = 18) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 20) duplicate here improves high length while reducing interbyte - "ldi %[bit] , 8" "\n\t" // 1 bit = 8 (T = 21) - "ld %[byte] , %a[ptr]+" "\n\t" // 2 b = *ptr++ (T = 23) - "sbiw %[count], 1" "\n\t" // 2 i-- (T = 25) - "brne head40" "\n" // 1-2 if(i != 0) -> (next byte) - : [port] "+e" (port), - [byte] "+r" (b), - [bit] "+r" (bit), - [next] "+r" (next), - [count] "+w" (i) - : [ptr] "e" (ptr), - [hi] "r" (hi), - [lo] "r" (lo)); -} - -#elif (F_CPU >= 31000000UL) && (F_CPU <= 35000000UL) // 32Mhz CPU - -void send_data_32mhz(uint8_t* data, - size_t sizeData, - volatile uint8_t* port, - uint8_t pinMask, - const uint8_t cycleTiming) -{ - volatile uint16_t i = (uint16_t)sizeData; // Loop counter - volatile uint8_t* ptr = data; // Pointer to next byte - volatile uint8_t b = *ptr++; // Current byte value - volatile uint8_t hi; // PORT w/output bit set high - volatile uint8_t lo; // PORT w/output bit set low - - volatile uint8_t next; - volatile uint8_t bit; - volatile uint8_t cycle; - volatile uint8_t cycleCount; - - hi = *port | pinMask; - lo = *port & ~pinMask; - next = lo; - bit = 8; - cycleCount = cycleTiming; - - asm volatile( - "head20:" "\n\t" // Clk Pseudocode - "st %a[port], %[hi]" "\n\t" // 2 PORT = hi - "sbrc %[byte], 7" "\n\t" // 1-2 if(b & 128) - "mov %[next], %[hi]" "\n\t" // 0-1 next = hi - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop1:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop1" "\n\t" // 2 if(cycle != 0) -> (cycleLoop1) - "st %a[port], %[next]" "\n\t" // 2 PORT = next - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop2:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop2" "\n\t" // 2 if(cycle != 0) -> (cycleLoop2) - "rjmp .+0" "\n\t" // 2 nop nop (timing tuning) - "st %a[port], %[lo]" "\n\t" // 2 PORT = lo - "mov %[next] , %[lo]" "\n\t" // 1 next = lo - "mov %[cycle], %[cycleCount]" "\n\t" // 0-1 cycle = shortCycle - "cycleLoop3:" "\n\t" - "dec %[cycle]" "\n\t" // 1 cycle-- - "brne cycleLoop3" "\n\t" // 2 if(cycle != 0) -> (cycleLoop3) - "dec %[bit]" "\n\t" // 1 bit-- - "breq nextbyte20" "\n\t" // 1-2 if(bit == 0) (from dec above) - "rol %[byte]" "\n\t" // 1 b <<= 1 (T = 15) - "rjmp head20" "\n\t" // 2 -> head20 (next bit out) - "nextbyte20:" "\n\t" // (T = 15) - "ldi %[bit] , 8" "\n\t" // 1 bit = 8 (T = 16) - "ld %[byte] , %a[ptr]+" "\n\t" // 2 b = *ptr++ (T = 18) - "sbiw %[count], 1" "\n\t" // 2 i-- (T = 38) - "brne head20" "\n" // 2 if(i != 0) -> (next byte) - // outputs - : [port] "+e" (port), - [byte] "+r" (b), - [bit] "+r" (bit), - [next] "+r" (next), - [cycle] "+r" (cycle), - [count] "+w" (i) - // inputs - : [ptr] "e" (ptr), - [hi] "r" (hi), - [lo] "r" (lo), - [cycleCount] "r" (cycleCount)); -} - #else #error "CPU SPEED NOT SUPPORTED" #endif diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h b/lib/NeoPixelBus/src/internal/NeoRingTopology.h similarity index 84% rename from lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h rename to lib/NeoPixelBus/src/internal/NeoRingTopology.h index 970de02c18..7255a97e38 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoRingTopology.h +++ b/lib/NeoPixelBus/src/internal/NeoRingTopology.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoRingTopology provides a mapping feature of a 2d polar cordinate to a linear 1d cordinate. @@ -26,26 +28,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once - -// NeoRingTopology - -// -// T_LAYOUT - a user provided class that contains the following members with -// the Rings[] initialized with the starting index of each ring and -// one extra entry for the total count (example below). -// Other methods and members can exist to intialize a dynamic layout as needed. -// -// class RingsLayout -// { -// protected: -// const uint16_t Rings[] = { 0, 1, 7, 19, 35, 59, PixelCount }; -// -// uint8_t _ringCount() const -// { -// return sizeof(Rings) / sizeof(Rings[0]); -// } -// }; -// template class NeoRingTopology : public T_LAYOUT { diff --git a/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h b/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h new file mode 100644 index 0000000000..0198a838db --- /dev/null +++ b/lib/NeoPixelBus/src/internal/NeoSegmentFeatures.h @@ -0,0 +1,216 @@ +/*------------------------------------------------------------------------- +NeoSegmentFeatures provides feature classes to describe seven segment display +elements for NeoPixelBus template class + +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 + +class Neo9Elements +{ +public: + static const size_t PixelSize = 9; // three 3 element + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + for (uint8_t iElement = 0; iElement < PixelSize; iElement++) + { + *pPixelDest++ = pPixelSrc[iElement]; + } + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef SevenSegDigit ColorObject; +}; + +class Neo9ElementsNoSettings : public Neo9Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +// Abcdefgps byte order +class NeoAbcdefgSegmentFeature : public Neo9ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + *p++ = color.Segment[iSegment]; + } + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + color.Segment[iSegment] = *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); + uint8_t commonSize = (PixelSize < color.SegmentCount) ? PixelSize : color.SegmentCount; + + for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) + { + color.Segment[iSegment] = pgm_read_byte(p++); + } + + return color; + } + +}; + + +// BACEDF.G+ byte order +class NeoBacedfpgsSegmentFeature : public Neo9ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + // Segment Digit is Abcdefgps order + *p++ = color.Segment[LedSegment_B]; + *p++ = color.Segment[LedSegment_A]; + *p++ = color.Segment[LedSegment_C]; + + *p++ = color.Segment[LedSegment_E]; + *p++ = color.Segment[LedSegment_D]; + *p++ = color.Segment[LedSegment_F]; + + *p++ = color.Segment[LedSegment_Decimal]; + *p++ = color.Segment[LedSegment_G]; + *p++ = color.Segment[LedSegment_Custom]; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.Segment[LedSegment_B] = *p++; + color.Segment[LedSegment_A] = *p++; + color.Segment[LedSegment_C] = *p++; + + color.Segment[LedSegment_E] = *p++; + color.Segment[LedSegment_D] = *p++; + color.Segment[LedSegment_F] = *p++; + + color.Segment[LedSegment_Decimal] = *p++; + color.Segment[LedSegment_G] = *p++; + color.Segment[LedSegment_Custom] = *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.Segment[LedSegment_B] = pgm_read_byte(p++); + color.Segment[LedSegment_A] = pgm_read_byte(p++); + color.Segment[LedSegment_C] = pgm_read_byte(p++); + + color.Segment[LedSegment_E] = pgm_read_byte(p++); + color.Segment[LedSegment_D] = pgm_read_byte(p++); + color.Segment[LedSegment_F] = pgm_read_byte(p++); + + color.Segment[LedSegment_Decimal] = pgm_read_byte(p++); + color.Segment[LedSegment_G] = pgm_read_byte(p++); + color.Segment[LedSegment_Custom] = pgm_read_byte(p++); + + return color; + } + +}; + +typedef NeoBacedfpgsSegmentFeature SevenSegmentFeature; // Abcdefg order is default \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoSettings.h b/lib/NeoPixelBus/src/internal/NeoSettings.h index 3835d6a045..1af9f82b1f 100644 --- a/lib/NeoPixelBus/src/internal/NeoSettings.h +++ b/lib/NeoPixelBus/src/internal/NeoSettings.h @@ -39,26 +39,9 @@ class NeoRgbCurrentSettings { } - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - default: - return BlueTenthMilliAmpere; - } - } - - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma }; class NeoRgbwCurrentSettings @@ -68,71 +51,12 @@ class NeoRgbwCurrentSettings RedTenthMilliAmpere(red), GreenTenthMilliAmpere(green), BlueTenthMilliAmpere(blue), - WhiteTenthMilliAmpere(white) - { - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - case 2: - return BlueTenthMilliAmpere; - default: - return WhiteTenthMilliAmpere; - } - } - - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma - const uint16_t WhiteTenthMilliAmpere; // in 1/10th ma -}; - -class NeoRgbwwCurrentSettings -{ -public: - NeoRgbwwCurrentSettings(uint16_t red, uint16_t green, uint16_t blue, uint16_t warmWhite, uint16_t coolWhite) : - RedTenthMilliAmpere(red), - GreenTenthMilliAmpere(green), - BlueTenthMilliAmpere(blue), - WarmWhiteTenthMilliAmpere(warmWhite), - CoolWhiteTenthMilliAmpere(coolWhite) - { - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const + WhiteCurrent(white) { - switch (idx) - { - case 0: - return RedTenthMilliAmpere; - case 1: - return GreenTenthMilliAmpere; - case 2: - return BlueTenthMilliAmpere; - case 3: - return WarmWhiteTenthMilliAmpere; - default: - return CoolWhiteTenthMilliAmpere; - } } - const uint16_t RedTenthMilliAmpere; // in 1/10th ma - const uint16_t GreenTenthMilliAmpere; // in 1/10th ma - const uint16_t BlueTenthMilliAmpere; // in 1/10th ma - const uint16_t WarmWhiteTenthMilliAmpere; // in 1/10th ma - const uint16_t CoolWhiteTenthMilliAmpere; // in 1/10th ma + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma + uint16_t WhiteCurrent; // in 1/10th ma }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h b/lib/NeoPixelBus/src/internal/NeoSpriteSheet.h similarity index 97% rename from lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h rename to lib/NeoPixelBus/src/internal/NeoSpriteSheet.h index bc1885f13c..73fdde3d66 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoVerticalSpriteSheet.h +++ b/lib/NeoPixelBus/src/internal/NeoSpriteSheet.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoVerticalSpriteSheet +NeoPixel library Written by Michael C. Miller. @@ -25,10 +25,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -// T_BUFFER_METHOD - one of -// NeoBufferMethod -// NeoBufferProgmemMethod -// + template class NeoVerticalSpriteSheet { public: diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoTiles.h b/lib/NeoPixelBus/src/internal/NeoTiles.h similarity index 91% rename from lib/NeoPixelBus/src/internal/topologies/NeoTiles.h rename to lib/NeoPixelBus/src/internal/NeoTiles.h index d614e4a633..2c0ca8338d 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoTiles.h +++ b/lib/NeoPixelBus/src/internal/NeoTiles.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoTiles provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map tiles of matricies of NeoPixels to a index on the NeoPixelBus @@ -26,18 +28,13 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once //----------------------------------------------------------------------------- // class NeoTiles // Simple template Tile layout class // T_MATRIX_LAYOUT = the layout used on the pixel matrix panel (a tile) // T_TILE_LAYOUT = the layout used for the tiles. -// one of the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout +// //----------------------------------------------------------------------------- template class NeoTiles { @@ -55,7 +52,7 @@ template class NeoTiles uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x >= static_cast(totalWidth)) + if (x >= totalWidth) { x = totalWidth - 1; } @@ -64,7 +61,7 @@ template class NeoTiles x = 0; } - if (y >= static_cast(totalHeight)) + if (y >= totalHeight) { y = totalHeight - 1; } @@ -104,8 +101,7 @@ template class NeoTiles uint16_t totalWidth = getWidth(); uint16_t totalHeight = getHeight(); - if (x < 0 || x >= static_cast(totalWidth) || - y < 0 || y >= static_cast(totalHeight)) + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) { return NeoTopologyHint_OutOfBounds; } diff --git a/lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h b/lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h similarity index 54% rename from lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h rename to lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h index 41ea38f828..00d0dfa371 100644 --- a/lib/NeoPixelBus/src/internal/features/NeoTm1814Features.h +++ b/lib/NeoPixelBus/src/internal/NeoTm1814ColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoTm1814Features provides feature classes to describe color order and +NeoTm1814ColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class specific to the TM1814 chip Written by Michael C. Miller. @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "../NeoUtil.h" - class NeoTm1814Settings : public NeoRgbwCurrentSettings { public: @@ -53,26 +51,21 @@ class NeoTm1814Settings : public NeoRgbwCurrentSettings } }; -template -class NeoElementsTm1814Settings +class Neo4ElementsTm1814Settings : public Neo4Elements { -private: - const static uint16_t EncodeDivisor = 5; - public: typedef NeoTm1814Settings SettingsObject; static const size_t SettingsSize = 8; - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) + static void applySettings(uint8_t* pData, const SettingsObject& settings) { - // settings are at the front of the data stream uint8_t* pSet = pData; // C1 - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_1]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_2]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_3]) - SettingsObject::MinCurrent) / EncodeDivisor; - *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_4]) - SettingsObject::MinCurrent) / EncodeDivisor; + *pSet++ = (SettingsObject::LimitCurrent(settings.WhiteCurrent) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.RedTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.GreenTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.BlueTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; uint8_t* pC1 = pData; @@ -83,23 +76,56 @@ class NeoElementsTm1814Settings } } - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static uint8_t* pixels(uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static const uint8_t* pixels(const uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } }; -class NeoWrgbTm1814Feature : - public Neo4ByteFeature, - public NeoElementsTm1814Settings -{ +class NeoWrgbTm1814Feature : public Neo4ElementsTm1814Settings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.W; + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = *p++; + 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++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; diff --git a/lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h b/lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h similarity index 53% rename from lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h rename to lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h index 3a72a0ec40..52bc03d181 100644 --- a/lib/NeoPixelBus/src/internal/features/NeoTm1914Features.h +++ b/lib/NeoPixelBus/src/internal/NeoTm1914ColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoTm1914Features provides feature classes to describe color order and +NeoTm1914ColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class specific to the TM1914 chip Written by Michael C. Miller. @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -#include "../NeoUtil.h" - enum NeoTm1914_Mode { NeoTm1914_Mode_DinFdinAutoSwitch, // Switches between DIN and FDIN on any signal pause > 300ms @@ -46,15 +44,14 @@ class NeoTm1914Settings NeoTm1914_Mode Mode; }; -class Neo3ByteElementsTm1914Settings +class Neo3ElementsTm1914Settings : public Neo3Elements { public: typedef NeoTm1914Settings SettingsObject; static const size_t SettingsSize = 6; - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) + static void applySettings(uint8_t* pData, const SettingsObject& settings) { - // settings are at the front of the data stream uint8_t* pSet = pData; uint8_t mode = 0xff; @@ -87,29 +84,91 @@ class Neo3ByteElementsTm1914Settings } } - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static uint8_t* pixels(uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) + static const uint8_t* pixels(const uint8_t* pData) { - // settings are at the front of the data stream return pData + SettingsSize; } }; -class NeoRgbTm1914Feature : - public Neo3ByteFeature, - public Neo3ByteElementsTm1914Settings +class NeoRgbTm1914Feature : public Neo3ElementsTm1914Settings { +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; -class NeoGrbTm1914Feature : - public Neo3ByteFeature, - public Neo3ByteElementsTm1914Settings +class NeoGrbTm1914Feature : public Neo3ElementsTm1914Settings { +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.G; + *p++ = color.R; + *p = color.B; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.G = *p++; + color.R = *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.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/NeoTopologies.h b/lib/NeoPixelBus/src/internal/NeoTopologies.h deleted file mode 100644 index ce41f3e47a..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoTopologies.h +++ /dev/null @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- -NeoTopologies includes all the classes that describe pixel cordinate mapping -from 2d spaces to 1d strips that NeoPixelBus uses. - -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 - -#include "topologies/ColumnMajorAlternatingLayout.h" -#include "topologies/ColumnMajorLayout.h" -#include "topologies/RowMajorAlternatingLayout.h" -#include "topologies/RowMajorLayout.h" - -#include "topologies/NeoTopology.h" -#include "topologies/NeoRingTopology.h" -#include "topologies/NeoTiles.h" -#include "topologies/NeoMosaic.h" - - diff --git a/lib/NeoPixelBus/src/internal/topologies/NeoTopology.h b/lib/NeoPixelBus/src/internal/NeoTopology.h similarity index 88% rename from lib/NeoPixelBus/src/internal/topologies/NeoTopology.h rename to lib/NeoPixelBus/src/internal/NeoTopology.h index 0909764cb1..224c1dbdf6 100644 --- a/lib/NeoPixelBus/src/internal/topologies/NeoTopology.h +++ b/lib/NeoPixelBus/src/internal/NeoTopology.h @@ -1,3 +1,5 @@ +#pragma once + /*------------------------------------------------------------------------- NeoTopology provides a mapping feature of a 2d cordinate to linear 1d cordinate It is used to map a matrix of NeoPixels to a index on the NeoPixelBus @@ -24,7 +26,6 @@ You should have received a copy of the GNU Lesser General Public License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#pragma once enum NeoTopologyHint { @@ -34,14 +35,6 @@ enum NeoTopologyHint NeoTopologyHint_OutOfBounds }; -// NeoTopology - -// -// T_LAYOUT - the following classes and their rotated variants -// RowMajorLayout -// ColumnMajorLayout -// RowMajorAlternatingLayout -// ColumnMajorAlternatingLayout -// template class NeoTopology { public: @@ -54,7 +47,7 @@ template class NeoTopology uint16_t Map(int16_t x, int16_t y) const { - if (x >= static_cast(_width)) + if (x >= _width) { x = _width - 1; } @@ -62,7 +55,7 @@ template class NeoTopology { x = 0; } - if (y >= static_cast(_height)) + if (y >= _height) { y = _height - 1; } diff --git a/lib/NeoPixelBus/src/internal/NeoUtil.h b/lib/NeoPixelBus/src/internal/NeoUtil.h deleted file mode 100644 index 3c08a80430..0000000000 --- a/lib/NeoPixelBus/src/internal/NeoUtil.h +++ /dev/null @@ -1,94 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions - -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 - -// some platforms do not come with STL or properly defined one, specifically functional -// if you see... -// undefined reference to `std::__throw_bad_function_call()' -// ...then you can either add the platform symbol to the list so NEOPIXEBUS_NO_STL gets defined or -// go to boards.txt and enable c++ by adding (teensy31.build.flags.libs=-lstdc++) and set to "smallest code" option in Arduino -// -#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(STM32L432xx) || defined(STM32L476xx) || defined(ARDUINO_ARCH_SAM) -#define NEOPIXEBUS_NO_STL 1 -#endif - -#ifndef MAYBE_UNUSED - #ifdef ESP32 - #define MAYBE_UNUSED [[maybe_unused]] - #endif - #ifdef ESP8266 - #define MAYBE_UNUSED - #endif -#endif - -// some platforms do not define this standard progmem type for some reason -// -#ifndef PGM_VOID_P -#define PGM_VOID_P const void * -#endif - -#ifndef countof -#define countof(array) (sizeof(array)/sizeof(array[0])) -#endif - -class NeoUtil -{ -private: - static constexpr uint8_t Reverse8BitsLookup[16] = { - 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, - 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf }; - -public: - inline static uint8_t Reverse8Bits(uint8_t n) - { - return (Reverse8BitsLookup[n & 0b1111] << 4) | Reverse8BitsLookup[n >> 4]; - } - - inline static size_t RoundUp(size_t numToRound, size_t multiple) - { - return ((numToRound + multiple - 1) / multiple) * multiple; - } - - // alternatives that proved to be slower but left for more periodic testing - /* - // marginally slower than the table - static uint8_t Reverse8Bits(uint8_t b) - { - b = (b & 0b11110000) >> 4 | (b & 0b00001111) << 4; - b = (b & 0b11001100) >> 2 | (b & 0b00110011) << 2; - b = (b & 0b10101010) >> 1 | (b & 0b01010101) << 1; - return b; - } - */ - - /* WAY TO SLOW - static uint8_t Reverse8Bits(uint8_t b) - { - return (b * 0x0202020202ULL & 0x010884422010ULL) % 1023; - } - */ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h b/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h new file mode 100644 index 0000000000..cad80d0726 --- /dev/null +++ b/lib/NeoPixelBus/src/internal/P9813ColorFeatures.h @@ -0,0 +1,162 @@ +/*------------------------------------------------------------------------- +P9813ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class when used with P9813s + +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 + +class P98133Elements +{ +public: + static const size_t PixelSize = 4; // still requires 4 to be sent + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = pPixelSrc[0]; + *pPixelDest++ = pPixelSrc[1]; + *pPixelDest++ = pPixelSrc[2]; + *pPixelDest++ = pPixelSrc[3]; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + while (pPixelDest < pEnd) + { + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + *pPixelDest++ = *pPixelSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint8_t* pDestBack = pPixelDest + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + while (pDestBack > pPixelDest) + { + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbColor ColorObject; +}; + +class P98133ElementsNoSettings : public P98133Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t*, const SettingsObject&) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } + + static const uint8_t* pixels(const uint8_t* pData) + { + return pData; + } +}; + +class P9813BgrFeature : public P98133ElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6); + *p++ = color.B; + *p++ = color.G; + *p = color.R; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + p++; // ignore the first byte + color.B = *p++; + color.G = *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); + + p++; // ignore the first byte + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p); + + return color; + } + +}; + + + + + + diff --git a/lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h b/lib/NeoPixelBus/src/internal/P9813GenericMethod.h similarity index 94% rename from lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h rename to lib/NeoPixelBus/src/internal/P9813GenericMethod.h index 4023c59b7c..2fd1d4b5a4 100644 --- a/lib/NeoPixelBus/src/internal/methods/P9813GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/P9813GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -98,12 +96,6 @@ template class P9813MethodBase _wire.endTransaction(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -114,7 +106,7 @@ template class P9813MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb16Color.h b/lib/NeoPixelBus/src/internal/Rgb16Color.h similarity index 87% rename from lib/NeoPixelBus/src/internal/colors/Rgb16Color.h rename to lib/NeoPixelBus/src/internal/Rgb16Color.h index aa08164b28..d2fdd8cd56 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb16Color.h +++ b/lib/NeoPixelBus/src/internal/Rgb16Color.h @@ -25,6 +25,11 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" + + // ------------------------------------------------------------------------ // Rgb16Color represents a color object that is represented by Red, Green, Blue // component values stored in a single 16 bit value using 565 model. @@ -66,16 +71,6 @@ struct Rgb16Color : RgbColorBase { }; - // ------------------------------------------------------------------------ - // Construct a Rgb16Color using RgbCOlor - // ------------------------------------------------------------------------ - Rgb16Color(const RgbColor& color) - { - setR(color.R); - setG(color.G); - setB(color.B); - }; - // ------------------------------------------------------------------------ // Construct a Rgb16Color using HtmlColor // ------------------------------------------------------------------------ @@ -153,23 +148,6 @@ struct Rgb16Color : RgbColorBase return (Color565 & 0x001f) << 3; }; - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return getR(); - case 1: - return getG(); - default: - return getB(); - } - } // ------------------------------------------------------------------------ // Comparison operators @@ -265,16 +243,7 @@ struct Rgb16Color : RgbColorBase return Rgb16Color(result.R, result.G, result.B); }; - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgb16Color LinearBlend(const Rgb16Color& left, const Rgb16Color& right, uint8_t progress) - { - RgbColor result = RgbColor::LinearBlend(left, right, progress); - - return Rgb16Color(result.R, result.G, result.B); - }; - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -308,8 +277,5 @@ struct Rgb16Color : RgbColorBase }; uint16_t Color565; - - const static uint8_t Max = 255; - const static size_t Count = 3; // three elements in [] }; diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp b/lib/NeoPixelBus/src/internal/Rgb48Color.cpp similarity index 80% rename from lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp rename to lib/NeoPixelBus/src/internal/Rgb48Color.cpp index d33b355dd5..ea03f92229 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.cpp +++ b/lib/NeoPixelBus/src/internal/Rgb48Color.cpp @@ -24,24 +24,22 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" #include "Rgb48Color.h" +#include "RgbColor.h" #include "HslColor.h" #include "HsbColor.h" #include "HtmlColor.h" -#include "RgbwColor.h" -#include "Rgbw64Color.h" - -Rgb48Color::Rgb48Color(const Rgbw64Color& color) : - R(color.R), - G(color.G), - B(color.B) +Rgb48Color::Rgb48Color(const HtmlColor& color) { -} + uint32_t temp = color.Color; + + B = (temp & 0xff); + temp = temp >> 8; + G = (temp & 0xff); + temp = temp >> 8; + R = (temp & 0xff); +}; Rgb48Color::Rgb48Color(const HslColor& color) { @@ -148,15 +146,9 @@ void Rgb48Color::Lighten(uint16_t delta) Rgb48Color Rgb48Color::LinearBlend(const Rgb48Color& left, const Rgb48Color& right, float progress) { - return Rgb48Color( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress)); -} -Rgb48Color Rgb48Color::LinearBlend(const Rgb48Color& left, const Rgb48Color& right, uint8_t progress) -{ - return Rgb48Color(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8)); + return Rgb48Color( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress)); } Rgb48Color Rgb48Color::BilinearBlend(const Rgb48Color& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.h b/lib/NeoPixelBus/src/internal/Rgb48Color.h similarity index 64% rename from lib/NeoPixelBus/src/internal/colors/Rgb48Color.h rename to lib/NeoPixelBus/src/internal/Rgb48Color.h index b7881c88e3..eb351421be 100644 --- a/lib/NeoPixelBus/src/internal/colors/Rgb48Color.h +++ b/lib/NeoPixelBus/src/internal/Rgb48Color.h @@ -25,7 +25,11 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -struct Rgbw64Color; // forward declared +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" +#include "RgbColor.h" + // ------------------------------------------------------------------------ // Rgb48Color represents a color object that is represented by Red, Green, Blue @@ -57,34 +61,17 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ // Construct a Rgb48Color using RgbColor // ------------------------------------------------------------------------ - Rgb48Color(const RgbColor& color) + Rgb48Color(const RgbColor& color) { - // x16 = map(x8, 0, 255, 0, 65535); // refactors to just * 257 - R = (uint16_t)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255 - G = (uint16_t)color.G * 257; - B = (uint16_t)color.B * 257; - }; - - // ------------------------------------------------------------------------ - // explicitly Construct a Rgb48Color using RgbwColor - // ------------------------------------------------------------------------ - explicit Rgb48Color(const RgbwColor& color) - { - *this = RgbColor(color); + R = (color.R == 0) ? 0 : (color.R << 8 | 0xff); + G = (color.G == 0) ? 0 : (color.G << 8 | 0xff); + B = (color.B == 0) ? 0 : (color.B << 8 | 0xff); } - // ------------------------------------------------------------------------ - // explicitly Construct a Rgb48Color using Rgbw64Color - // ------------------------------------------------------------------------ - explicit Rgb48Color(const Rgbw64Color& color); - // ------------------------------------------------------------------------ // Construct a Rgb48Color using HtmlColor // ------------------------------------------------------------------------ - Rgb48Color(const HtmlColor& color) - { - *this = RgbColor(color); - }; + Rgb48Color(const HtmlColor& color); // ------------------------------------------------------------------------ // Construct a Rgb48Color using HslColor @@ -117,68 +104,6 @@ struct Rgb48Color : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int32_t CompareTo(const Rgb48Color& other, uint16_t epsilon = 256) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int32_t Compare(const Rgb48Color& left, const Rgb48Color& right, uint16_t epsilon = 256) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness @@ -193,18 +118,6 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Dim(uint16_t ratio) const; - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgb48Color Dim(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Dim(expanded); - } - // ------------------------------------------------------------------------ // Brighten will return a new color that is blended to white with the given ratio // ratio - (0-65535) where 65535 will return the original color and 0 will return white @@ -213,18 +126,6 @@ struct Rgb48Color : RgbColorBase // ------------------------------------------------------------------------ Rgb48Color Brighten(uint16_t ratio) const; - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgb48Color Brighten(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Brighten(expanded); - } - // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change @@ -247,11 +148,7 @@ struct Rgb48Color : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static Rgb48Color LinearBlend(const Rgb48Color& left, const Rgb48Color& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgb48Color LinearBlend(const Rgb48Color& left, const Rgb48Color& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -288,17 +185,16 @@ struct Rgb48Color : RgbColorBase uint16_t B; const static uint16_t Max = 65535; - const static size_t Count = 3; // three elements in [] private: inline static uint16_t _elementDim(uint16_t value, uint16_t ratio) { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 16; + return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; } inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio) { - uint32_t element = ((static_cast(value) + 1) << 16) / (static_cast(ratio) + 1); + uint32_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); if (element > Max) { diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColor.cpp b/lib/NeoPixelBus/src/internal/RgbColor.cpp similarity index 84% rename from lib/NeoPixelBus/src/internal/colors/RgbColor.cpp rename to lib/NeoPixelBus/src/internal/RgbColor.cpp index 81d0ba56f1..406d78e12e 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColor.cpp +++ b/lib/NeoPixelBus/src/internal/RgbColor.cpp @@ -24,16 +24,12 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb16Color.h" #include "Rgb48Color.h" #include "HslColor.h" #include "HsbColor.h" #include "HtmlColor.h" - #include "RgbwColor.h" RgbColor::RgbColor(const RgbwColor& color) : @@ -166,16 +162,9 @@ void RgbColor::Lighten(uint8_t delta) RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, float progress) { - return RgbColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress)); -} - -RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, uint8_t progress) -{ - return RgbColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8)); + return RgbColor( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress)); } RgbColor RgbColor::BilinearBlend(const RgbColor& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColor.h b/lib/NeoPixelBus/src/internal/RgbColor.h similarity index 76% rename from lib/NeoPixelBus/src/internal/colors/RgbColor.h rename to lib/NeoPixelBus/src/internal/RgbColor.h index 2b34d80431..aa999f5ba9 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColor.h +++ b/lib/NeoPixelBus/src/internal/RgbColor.h @@ -25,6 +25,10 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include +#include "NeoSettings.h" +#include "RgbColorBase.h" + struct RgbwColor; // ------------------------------------------------------------------------ @@ -101,68 +105,6 @@ struct RgbColor : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbColor& left, const RgbColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - default: - return B; - } - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness @@ -207,11 +149,7 @@ struct RgbColor : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbColor LinearBlend(const RgbColor& left, const RgbColor& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -248,7 +186,6 @@ struct RgbColor : RgbColorBase uint8_t B; const static uint8_t Max = 255; - const static size_t Count = 3; // three elements in [] private: inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp b/lib/NeoPixelBus/src/internal/RgbColorBase.cpp similarity index 98% rename from lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp rename to lib/NeoPixelBus/src/internal/RgbColorBase.cpp index 92c43f9d3f..ad0eb82772 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.cpp +++ b/lib/NeoPixelBus/src/internal/RgbColorBase.cpp @@ -24,8 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" #include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h b/lib/NeoPixelBus/src/internal/RgbColorBase.h similarity index 75% rename from lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h rename to lib/NeoPixelBus/src/internal/RgbColorBase.h index 399c6f9ba0..689fe884e5 100644 --- a/lib/NeoPixelBus/src/internal/buffers/NeoShaderBase.h +++ b/lib/NeoPixelBus/src/internal/RgbColorBase.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoShaderBase +RgbColorBase provides a RGB color object common support Written by Michael C. Miller. @@ -25,29 +25,18 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once -class NeoShaderBase +struct HslColor; +struct HsbColor; +struct HtmlColor; +struct Rgb16Color; + +struct RgbColorBase { -public: - NeoShaderBase() : - _state(0) - { - } - - bool IsDirty() const - { - return (_state & NEO_DIRTY); - }; - - void Dirty() - { - _state |= NEO_DIRTY; - }; - - void ResetDirty() - { - _state &= ~NEO_DIRTY; - }; protected: - uint8_t _state; // internal state + static float _CalcColor(float p, float q, float t); + + static void _HslToRgb(const HslColor& color, float* r, float* g, float* b); + + static void _HsbToRgb(const HsbColor& color, float* r, float* g, float* b); }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp b/lib/NeoPixelBus/src/internal/RgbwColor.cpp similarity index 81% rename from lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp rename to lib/NeoPixelBus/src/internal/RgbwColor.cpp index 5391583dd2..10b3727843 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbwColor.cpp +++ b/lib/NeoPixelBus/src/internal/RgbwColor.cpp @@ -24,9 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" #include "RgbColor.h" #include "Rgb48Color.h" #include "HslColor.h" @@ -168,17 +165,10 @@ void RgbwColor::Lighten(uint8_t delta) RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress) { - return RgbwColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.W + ((static_cast(right.W) - left.W) * progress) ); -} -RgbwColor RgbwColor::LinearBlend(const RgbwColor& left, const RgbwColor& right, uint8_t progress) -{ - return RgbwColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.W + (((static_cast(right.W) - left.W) * static_cast(progress) + 1) >> 8)); + return RgbwColor( left.R + ((right.R - left.R) * progress), + left.G + ((right.G - left.G) * progress), + left.B + ((right.B - left.B) * progress), + left.W + ((right.W - left.W) * progress) ); } RgbwColor RgbwColor::BilinearBlend(const RgbwColor& c00, diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwColor.h b/lib/NeoPixelBus/src/internal/RgbwColor.h similarity index 74% rename from lib/NeoPixelBus/src/internal/colors/RgbwColor.h rename to lib/NeoPixelBus/src/internal/RgbwColor.h index 6154769fd6..73732b5e40 100644 --- a/lib/NeoPixelBus/src/internal/colors/RgbwColor.h +++ b/lib/NeoPixelBus/src/internal/RgbwColor.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + struct RgbColor; struct HslColor; struct HsbColor; @@ -34,7 +36,7 @@ struct HsbColor; // component values and an extra White component. It contains helpful color // routines to manipulate the color. // ------------------------------------------------------------------------ -struct RgbwColor : RgbColorBase +struct RgbwColor { typedef NeoRgbwCurrentSettings SettingsObject; @@ -103,72 +105,6 @@ struct RgbwColor : RgbColorBase return !(*this == other); }; - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbwColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbwColor& left, const RgbwColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - // ------------------------------------------------------------------------ // Returns if the color is grey, all values are equal other than white // ------------------------------------------------------------------------ @@ -230,11 +166,7 @@ struct RgbwColor : RgbColorBase // and a value between will blend the color weighted linearly between them // ------------------------------------------------------------------------ static RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwColor LinearBlend(const RgbwColor& left, const RgbwColor& right, uint8_t progress); - + // ------------------------------------------------------------------------ // BilinearBlend between four colors by the amount defined by 2d variable // c00 - upper left quadrant color @@ -255,10 +187,10 @@ struct RgbwColor : RgbColorBase { auto total = 0; - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += W * settings.WhiteTenthMilliAmpere / Max; + total += R * settings.RedTenthMilliAmpere / 255; + total += G * settings.GreenTenthMilliAmpere / 255; + total += B * settings.BlueTenthMilliAmpere / 255; + total += W * settings.WhiteCurrent / 255; return total; } @@ -273,9 +205,6 @@ struct RgbwColor : RgbColorBase uint8_t B; uint8_t W; - const static uint8_t Max = 255; - const static size_t Count = 4; // four elements in [] - private: inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) { @@ -286,9 +215,9 @@ struct RgbwColor : RgbColorBase { uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - if (element > Max) + if (element > 255) { - element = Max; + element = 255; } else { diff --git a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp b/lib/NeoPixelBus/src/internal/SegmentDigit.cpp similarity index 75% rename from lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp rename to lib/NeoPixelBus/src/internal/SegmentDigit.cpp index 2984cf8576..b310f59039 100644 --- a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.cpp +++ b/lib/NeoPixelBus/src/internal/SegmentDigit.cpp @@ -24,7 +24,6 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#include #include "SegmentDigit.h" // @@ -60,7 +59,7 @@ const uint8_t SevenSegDigit::DecodeSpecial[] = { void SevenSegDigit::init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { Segment[iSegment] = (bitmask & 0x01) ? brightness : defaultBrightness; bitmask >>= 1; @@ -112,39 +111,17 @@ uint8_t SevenSegDigit::CalculateBrightness() const { uint16_t sum = 0; - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { sum += Segment[iSegment]; } - return static_cast(sum / Count); -} - -SevenSegDigit SevenSegDigit::Dim(uint8_t ratio) const -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = _elementDim(Segment[iSegment], ratio); - } - return result; -} - -SevenSegDigit SevenSegDigit::Brighten(uint8_t ratio) const -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = _elementBrighten(Segment[iSegment], ratio); - } - return result; + return static_cast(sum / SegmentCount); } void SevenSegDigit::Darken(uint8_t delta) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { uint8_t element = Segment[iSegment]; if (element > delta) @@ -161,7 +138,7 @@ void SevenSegDigit::Darken(uint8_t delta) void SevenSegDigit::Lighten(uint8_t delta) { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { uint8_t element = Segment[iSegment]; if (element < 255 - delta) @@ -180,22 +157,9 @@ SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenS { SevenSegDigit result; - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) - { - result.Segment[iSegment] = left.Segment[iSegment] + ((static_cast(right.Segment[iSegment]) - left.Segment[iSegment]) * progress); - } - return result; -} - -SevenSegDigit SevenSegDigit::LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, uint8_t progress) -{ - SevenSegDigit result; - - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { - result.Segment[iSegment] = left.Segment[iSegment] + - (((static_cast(right.Segment[iSegment]) - left.Segment[iSegment]) * static_cast(progress) + 1) >> 8); + result.Segment[iSegment] = left.Segment[iSegment] + ((right.Segment[iSegment] - left.Segment[iSegment]) * progress); } return result; } - diff --git a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.h b/lib/NeoPixelBus/src/internal/SegmentDigit.h similarity index 76% rename from lib/NeoPixelBus/src/internal/colors/SegmentDigit.h rename to lib/NeoPixelBus/src/internal/SegmentDigit.h index abf8649ce7..a7fe452e81 100644 --- a/lib/NeoPixelBus/src/internal/colors/SegmentDigit.h +++ b/lib/NeoPixelBus/src/internal/SegmentDigit.h @@ -25,6 +25,8 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +#include + enum LedSegment { LedSegment_A, @@ -105,7 +107,7 @@ struct SevenSegDigit // ------------------------------------------------------------------------ bool operator==(const SevenSegDigit& other) const { - for (uint8_t iSegment = 0; iSegment < Count; iSegment++) + for (uint8_t iSegment = 0; iSegment < SegmentCount; iSegment++) { if (Segment[iSegment] != other.Segment[iSegment]) { @@ -120,48 +122,12 @@ struct SevenSegDigit return !(*this == other); }; - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order of the Segments - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - return Segment[idx]; - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - return Segment[idx]; - } - // ------------------------------------------------------------------------ // CalculateBrightness will calculate the overall brightness // NOTE: This is a simple linear brightness // ------------------------------------------------------------------------ uint8_t CalculateBrightness() const; - // ------------------------------------------------------------------------ - // Dim will return a new SevenSegDigit that is blended to off with the given ratio - // ratio - (0-255) where 255 will return the original brightness and 0 will return off - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - SevenSegDigit Dim(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new SevenSegDigit that is blended to full bright with the given ratio - // ratio - (0-255) where 255 will return the original brightness and 0 will return full brightness - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - SevenSegDigit Brighten(uint8_t ratio) const; - // ------------------------------------------------------------------------ // Darken will adjust the color by the given delta toward black // NOTE: This is a simple linear change @@ -185,23 +151,19 @@ struct SevenSegDigit // weighted linearly between them // ------------------------------------------------------------------------ static SevenSegDigit LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static SevenSegDigit LinearBlend(const SevenSegDigit& left, const SevenSegDigit& right, uint8_t progress); uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) { auto total = 0; - for (uint8_t segment = LedSegment_A; segment < Count - 2; segment++) + for (uint8_t segment = LedSegment_A; segment < SegmentCount - 2; segment++) { total += Segment[segment] * settings.SegmentTenthMilliAmpere / Max; } - total += Segment[Count - 2] * settings.DecimalTenthMilliAmpere / Max; - total += Segment[Count - 1] * settings.SpecialTenthMilliAmpere / Max; + total += Segment[SegmentCount - 2] * settings.DecimalTenthMilliAmpere / Max; + total += Segment[SegmentCount - 1] * settings.SpecialTenthMilliAmpere / Max; return total; } @@ -287,8 +249,8 @@ struct SevenSegDigit // segment members (0-255) where each represents the segment location // and the value defines the brightnes (0) is off and (255) is full brightness // ------------------------------------------------------------------------ - static const uint8_t Count = 9; - uint8_t Segment[Count]; + static const uint8_t SegmentCount = 9; + uint8_t Segment[SegmentCount]; const static uint8_t Max = 255; @@ -301,25 +263,5 @@ struct SevenSegDigit protected: void init(uint8_t bitmask, uint8_t brightness, uint8_t defaultBrightness); - - inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; - } - - inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio) - { - uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } }; diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h b/lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h similarity index 87% rename from lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h rename to lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h index d45eff05c0..eede5f9cce 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireBitBangImple.h @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" class TwoWireBitBangImple { @@ -63,18 +62,6 @@ class TwoWireBitBangImple digitalWrite(_pinData, LOW); } - void transmitBit(uint8_t bit) - { - // set data bit on pin - digitalWrite(_pinData, bit); - - // set clock high as data is ready - digitalWrite(_pinClock, HIGH); - - // set clock low as data pin is changed - digitalWrite(_pinClock, LOW); - } - void transmitByte(uint8_t data) { for (int bit = 7; bit >= 0; bit--) @@ -101,7 +88,7 @@ class TwoWireBitBangImple } } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h b/lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h similarity index 84% rename from lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h rename to lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h index 79e47ae50a..5b475ac5fd 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireBitBangImpleAvr.h +++ b/lib/NeoPixelBus/src/internal/TwoWireBitBangImpleAvr.h @@ -26,7 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" class TwoWireBitBangImple { @@ -68,28 +67,6 @@ class TwoWireBitBangImple digitalWrite(_pinData, LOW); } - void transmitBit(uint8_t bit) - { - // set data bit on pin - // digitalWrite(_pinData, bit); // HIGH : LOW - if (bit) - { - *_portData |= _pinMaskData; - } - else - { - *_portData &= ~_pinMaskData; - } - - // set clock high as data is ready - // digitalWrite(_pinClock, HIGH); - *_portClock |= _pinMaskClock; - - // set clock low as data pin is changed - // digitalWrite(_pinClock, LOW); - *_portClock &= ~_pinMaskClock; - } - void transmitByte(uint8_t data) { for (int bit = 7; bit >= 0; bit--) @@ -126,7 +103,7 @@ class TwoWireBitBangImple } } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h b/lib/NeoPixelBus/src/internal/TwoWireHspiImple.h similarity index 96% rename from lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h rename to lib/NeoPixelBus/src/internal/TwoWireHspiImple.h index bdacd38e81..5a96bd5a97 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireHspiImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireHspiImple.h @@ -27,8 +27,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #include template class TwoWireHspiImple @@ -83,7 +81,7 @@ template class TwoWireHspiImple _hspi->writeBytes(const_cast(data), dataSize); } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _speed.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h b/lib/NeoPixelBus/src/internal/TwoWireSpiImple.h similarity index 78% rename from lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h rename to lib/NeoPixelBus/src/internal/TwoWireSpiImple.h index 2a1244b728..906d86b8f9 100644 --- a/lib/NeoPixelBus/src/internal/methods/TwoWireSpiImple.h +++ b/lib/NeoPixelBus/src/internal/TwoWireSpiImple.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - #include class SpiSpeed40Mhz @@ -36,51 +34,29 @@ class SpiSpeed40Mhz typedef NeoNoSettings SettingsObject; SpiSpeed40Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 40000000L; }; -class SpiSpeed30Mhz -{ -public: - typedef NeoNoSettings SettingsObject; - SpiSpeed30Mhz() {}; - - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} - - static const uint32_t Clock = 30000000L; -}; - class SpiSpeed20Mhz { public: typedef NeoNoSettings SettingsObject; SpiSpeed20Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 20000000L; }; -class SpiSpeed15Mhz -{ -public: - typedef NeoNoSettings SettingsObject; - SpiSpeed15Mhz() {}; - - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} - - static const uint32_t Clock = 15000000L; -}; - class SpiSpeed10Mhz { public: typedef NeoNoSettings SettingsObject; SpiSpeed10Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 10000000L; }; @@ -91,7 +67,7 @@ class SpiSpeed5Mhz typedef NeoNoSettings SettingsObject; SpiSpeed5Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 5000000L; }; @@ -102,7 +78,7 @@ class SpiSpeed2Mhz typedef NeoNoSettings SettingsObject; SpiSpeed2Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 2000000L; }; @@ -113,7 +89,7 @@ class SpiSpeed1Mhz typedef NeoNoSettings SettingsObject; SpiSpeed1Mhz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 1000000L; }; @@ -124,7 +100,7 @@ class SpiSpeed500Khz typedef NeoNoSettings SettingsObject; SpiSpeed500Khz() {}; - static void applySettings(MAYBE_UNUSED const SettingsObject& settings) {} + static void applySettings(const SettingsObject& settings) {} static const uint32_t Clock = 500000L; }; @@ -148,7 +124,7 @@ class SpiSpeedHz Clock(10000000) {}; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { Clock = settings.Clock; } @@ -217,7 +193,7 @@ template class TwoWireSpiImple #endif } - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _speed.applySettings(settings); } diff --git a/lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h b/lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h similarity index 79% rename from lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h rename to lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h index 3065cc0600..24521c6f6d 100644 --- a/lib/NeoPixelBus/src/internal/methods/Ws2801GenericMethod.h +++ b/lib/NeoPixelBus/src/internal/Ws2801GenericMethod.h @@ -26,8 +26,6 @@ License along with NeoPixel. If not, see #pragma once -#include "../NeoUtil.h" - // must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set #if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) #include "TwoWireBitBangImpleAvr.h" @@ -104,12 +102,6 @@ template class Ws2801MethodBase _endTime = micros(); } - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - uint8_t* getData() const { return _data; @@ -120,7 +112,7 @@ template class Ws2801MethodBase return _sizeData; }; - void applySettings(MAYBE_UNUSED const SettingsObject& settings) + void applySettings(const SettingsObject& settings) { _wire.applySettings(settings); } @@ -133,20 +125,20 @@ template class Ws2801MethodBase uint8_t* _data; // Holds LED color values }; -typedef Ws2801MethodBase Ws2801Method; +typedef Ws2801MethodBase NeoWs2801Method; #if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) #include "TwoWireSpiImple.h" -typedef Ws2801MethodBase> Ws2801Spi20MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi10MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi5MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi2MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi1MhzMethod; -typedef Ws2801MethodBase> Ws2801Spi500KhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi20MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi10MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi5MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi2MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi1MhzMethod; +typedef Ws2801MethodBase> NeoWs2801Spi500KhzMethod; -typedef Ws2801MethodBase> Ws2801SpiHzMethod; +typedef Ws2801MethodBase> NeoWs2801SpiHzMethod; -typedef Ws2801Spi10MhzMethod Ws2801SpiMethod; +typedef NeoWs2801Spi10MhzMethod NeoWs2801SpiMethod; #endif diff --git a/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h b/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h deleted file mode 100644 index d822f1883e..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/LayoutMapCallback.h +++ /dev/null @@ -1,41 +0,0 @@ -/*------------------------------------------------------------------------- -LayoutMapCallback - -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 - - -#if defined(NEOPIXEBUS_NO_STL) - -typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); - -#else - -#undef max -#undef min -#include -typedef std::function LayoutMapCallback; - -#endif \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h b/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h deleted file mode 100644 index b03b72d3db..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/NeoBufferProgmemMethod.h +++ /dev/null @@ -1,126 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBufferProgmemMethod - -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 - -template class NeoBufferProgmemMethod -{ -public: - NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : - _width(width), - _height(height), - _pixels(pixels) - { - } - - operator NeoBufferContext() - { - return NeoBufferContext(Pixels(), PixelsSize()); - } - - const uint8_t* Pixels() const - { - return reinterpret_cast(_pixels); - }; - - size_t PixelsSize() const - { - return PixelSize() * PixelCount(); - }; - - size_t PixelSize() const - { - return T_COLOR_FEATURE::PixelSize; - }; - - uint16_t PixelCount() const - { - return _width * _height; - }; - - uint16_t Width() const - { - return _width; - }; - - uint16_t Height() const - { - return _height; - }; - - void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const - { - if (indexPixel >= PixelCount()) - { - // Pixel # is out of bounds, this will get converted to a - // color object type initialized to 0 (black) - return 0; - } - - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); - }; - - typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const - { - if (x < 0 || x >= _width || y < 0 || y >= _height) - { - // Pixel # is out of bounds, this will get converted to a - // color object type initialized to 0 (black) - return 0; - } - - uint16_t indexPixel = x + y * _width; - return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); - }; - - void ClearTo(typename T_COLOR_FEATURE::ColorObject color) - { - // PROGMEM is read only, this will do nothing - }; - - void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); - } - - typedef typename T_COLOR_FEATURE::ColorObject ColorObject; - typedef T_COLOR_FEATURE ColorFeature; - -private: - const uint16_t _width; - const uint16_t _height; - PGM_VOID_P _pixels; -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h b/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h deleted file mode 100644 index c7ca2e02b2..0000000000 --- a/lib/NeoPixelBus/src/internal/buffers/NeoShaderNop.h +++ /dev/null @@ -1,53 +0,0 @@ -/*------------------------------------------------------------------------- -NeoShaderNop - -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 - -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; - }; -}; - diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGamma.h b/lib/NeoPixelBus/src/internal/colors/NeoGamma.h deleted file mode 100644 index d2f1b93fc5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGamma.h +++ /dev/null @@ -1,81 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGamma class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -// use one of the gamma method classes as a converter for this template class -// T_METHOD - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// NeoGammaInvert -// -template class NeoGamma -{ -public: - static RgbColor Correct(const RgbColor& original) - { - return RgbColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B)); - } - - static RgbwColor Correct(const RgbwColor& original) - { - return RgbwColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.W) ); - } - - static Rgb48Color Correct(const Rgb48Color& original) - { - return Rgb48Color(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B)); - } - - static Rgbw64Color Correct(const Rgbw64Color& original) - { - return Rgbw64Color(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.W)); - } - - static RgbwwColor Correct(const RgbwwColor& original) - { - return RgbwwColor(T_METHOD::Correct(original.R), - T_METHOD::Correct(original.G), - T_METHOD::Correct(original.B), - T_METHOD::Correct(original.WW), - T_METHOD::Correct(original.CW)); - } -}; - - - diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h deleted file mode 100644 index 6603677e5b..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaCieLabEquationMethod.h +++ /dev/null @@ -1,41 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaCieLabEquationMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -// Alternative equation to provide at least one official model for specific LEDs -class NeoGammaCieLabEquationMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return static_cast(255.0f * NeoEase::GammaCieLab(value / 255.0f) + 0.5f); - } - static uint16_t Correct(uint16_t value) - { - return static_cast(65535.0f * NeoEase::GammaCieLab(value / 65535.0f) + 0.5f); - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp b/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp deleted file mode 100644 index 383b39fbe2..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGamma classes are used to correct RGB colors for human eye gamma levels - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoUtil.h" -#include "NeoGammaDynamicTableMethod.h" - - -uint8_t NeoGammaDynamicTableMethod::_table[256] = { 0 }; -NeoGammaDynamicTableMethod::NeoGamma16LowHint* NeoGammaDynamicTableMethod::_hints = nullptr; -uint8_t NeoGammaDynamicTableMethod::_hintsCount = 0; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h deleted file mode 100644 index 2ccc9fedff..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaDynamicTableMethod.h +++ /dev/null @@ -1,226 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaDynamicTableMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -#if defined(NEOPIXEBUS_NO_STL) - -typedef float(*GammaCalcFunction)(float unitValue); - -#else - -#undef max -#undef min -#include -typedef std::function GammaCalcFunction; - -#endif - -class NeoGammaDynamicTableMethod -{ -protected: - struct NeoGamma16LowHint - { - uint8_t pos; - uint8_t count; - }; - -public: - static uint8_t Correct(uint8_t value) - { - return _table[value]; - } - - static uint16_t Correct(uint16_t value) - { - // since a single monolithic table would be an unreasonable memory usage - // this will use a hybrid of two tables, the base 255 table for the hibyte - // and a smaller table with hints on how to use the table for certain values - // and the left over values some simple calculations to approximate the final - // 16 bit value as compared to the equation - uint8_t hi = (value >> 8); - uint16_t lo = (value & 0x00ff); - uint8_t hiResult = _table[hi]; - uint16_t lowResult = 0; - - if (hi < _hintsCount) - { - // use _hints table to calculate a reasonable lowbyte - lowResult = (lo + _hints[hi].pos * 256) / _hints[hi].count; - } - else if (hi == 255) - { - // last entry is always linear - lowResult = lo; - } - else - { - // check the _table for duplicate or jumps to adjust the range of lowbyte - if (hiResult == _table[hi - 1]) - { - // this result is an upper duplicate - lowResult = (lo >> 1) | 0x80; // lo / 2 + 128 - } - else - { - uint8_t delta = _table[hi + 1] - hiResult; - - if (delta == 0) - { - // this result is a lower duplicate - lowResult = (lo >> 1); // lo / 2 - } - else if (delta == 1) - { - // this result is incremental and thus linear - lowResult = lo; - } - else - { - // this result jumps by more than one, so need to spread across - lowResult = delta * lo; - } - } - - } - - return (static_cast(hiResult) << 8) + lowResult; - } - - static void Initialize(GammaCalcFunction calc, bool optimize16Bit = false) - { - if (_hints) - { - delete [] _hints; - _hints = nullptr; - } - - // first, iterate and fill 8 bit table - for (uint16_t entry = 0; entry < 256; entry++) - { - _table[entry] = static_cast(255.0f * calc(entry / 255.0f) + 0.5f); - } - - // no optimization, so no 16 bit hints table - if (optimize16Bit) - { - NeoGamma16LowHint hints[256]; - - // now walk table creating an optimized hint table for 16bit - // approximation - // There is an assumption that lower values have series of duplicates and - // upper values at worst have two values the same - // - uint16_t entryStart = 0; - uint16_t entryEnd = 0; - uint16_t entryLastTriplet = 0; - - while (entryStart < 255) - { - uint8_t value = _table[entryStart]; - - while (value == _table[entryEnd] && entryEnd < 255) - { - entryEnd++; - } - - if (entryEnd == entryStart) - { - // no more duplicates, no need to continue - break; - } - - uint8_t pos = 0; - uint8_t count = entryEnd - entryStart; - - if (count >= 3) - { - // remember the last triplet + series - // as we don't need hints after this - // there can be paired duplicates after and before this - entryLastTriplet = entryEnd; - } - - // fill hints with known duplicate value - while (entryStart != entryEnd) - { - hints[entryStart].count = count; - hints[entryStart].pos = pos; - entryStart++; - pos++; - } - } - // create static hint table and copy temp table to it - _hintsCount = entryLastTriplet; // only need to last triplet - _hints = new NeoGamma16LowHint[_hintsCount]; - memcpy(_hints, hints, sizeof(NeoGamma16LowHint) * _hintsCount); - } - } - - // SerialDumpTables is used if you want to generate your own static gamma table class - // rather than use this dynamically generated table. Just capture the serial output - // and use as your initializers for your tables - static void SerialDumpTables() - { - Serial.println(); - Serial.println("8 bit:"); - for (uint16_t entry = 0; entry < 256; entry++) - { - if (entry % 16 == 0) - { - Serial.println(); - } - Serial.print(_table[entry]); - Serial.print(", "); - } - - Serial.println(); - Serial.println(); - Serial.print("16 bit: hintsCount = "); - Serial.println(_hintsCount); - if (_hints) - { - for (uint8_t hint = 0; hint < _hintsCount; hint++) - { - if (hint % 16 == 0) - { - Serial.println(); - } - Serial.print("{"); - Serial.print(_hints[hint].pos); - Serial.print(","); - Serial.print(_hints[hint].count); - Serial.print("}, "); - } - } - Serial.println(); - } - -private: - static uint8_t _table[256]; - static NeoGamma16LowHint* _hints; - static uint8_t _hintsCount; -}; diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h deleted file mode 100644 index f28bdef2b5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaInvertMethod.h +++ /dev/null @@ -1,48 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaInvertMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -// use one of the gamma method classes as a base converter for this template class -// T_METHOD - -// NeoGammaEquationMethod -// NeoGammaCieLabEquationMethod -// NeoGammaTableMethod -// NeoGammaNullMethod -// -template class NeoGammaInvertMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return ~T_METHOD::Correct(value); - } - - static uint16_t Correct(uint16_t value) - { - return ~T_METHOD::Correct(value); - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h deleted file mode 100644 index d1d4436bf3..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaNullMethod.h +++ /dev/null @@ -1,42 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaNullMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -// no gamma correction at all -class NeoGammaNullMethod -{ -public: - static uint8_t Correct(uint8_t value) - { - return value; - } - - static uint16_t Correct(uint16_t value) - { - return value; - } -}; diff --git a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h b/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h deleted file mode 100644 index 4874a44045..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/NeoGammaTableMethod.h +++ /dev/null @@ -1,113 +0,0 @@ -/*------------------------------------------------------------------------- -NeoGammaTableMethod class is used to correct RGB colors for human eye gamma levels equally -across all color channels - -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 - -// NeoGammaTableMethod uses 256 bytes of memory, but is significantly faster -class NeoGammaTableMethod -{ -protected: - struct NeoGamma16LowHint - { - uint8_t pos; - uint8_t count; - }; - -public: - static uint8_t Correct(uint8_t value) - { - return _table[value]; - } - - static uint16_t Correct(uint16_t value) - { - // since a single monolithic table would be an unreasonable memory usage - // this will use a hybrid of two tables, the base 255 table for the hibyte - // and a smaller table with hints on how to use the table for certain values - // and the left over values some simple calculations to approximate the final - // 16 bit value as compared to the equation - static const NeoGamma16LowHint _hints[] = { - {0,16}, {1,16}, {2,16}, {3,16}, {4,16}, {5,16}, {6,16}, {7,16}, {8,16}, {9,16}, {10,16}, {11,16}, {12,16}, {13,16}, {14,16}, {15,16}, - {0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}, {6,10}, {7,10}, {8,10}, {9,10}, {0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}, - {0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}, {0,4}, {1,4}, {2,4}, {3,4}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3}, - {2,3}, {0,4}, {1,4}, {2,4}, {3,4}, {0,3}, {1,3}, {2,3}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}, - {0,2}, {1,2}, {0,2}, {1,2}, {0,3}, {1,3}, {2,3}, {0,2}, {1,2} - }; - - uint8_t hi = (value >> 8); - uint16_t lo = (value & 0x00ff); - uint8_t hiResult = _table[hi]; - uint16_t lowResult = 0; - - if (hi < countof(_hints)) - { - // use _hints table to calculate a reasonable lowbyte - lowResult = (lo + _hints[hi].pos * 256) / _hints[hi].count; - } - else if (hi == 255) - { - // last entry is always linear - lowResult = lo; - } - else - { - // check the _table for duplicate or jumps to adjust the range of lowbyte - if (hiResult == _table[hi - 1]) - { - // this result is an upper duplicate - lowResult = (lo >> 1) | 0x80; // lo / 2 + 128 - } - else - { - uint8_t delta = _table[hi + 1] - hiResult; - - if (delta == 0) - { - // this result is a lower duplicate - lowResult = (lo >> 1); // lo / 2 - } - else if (delta == 1) - { - // this result is incremental and thus linear - lowResult = lo; - } - else - { - // this result jumps by more than one, so need to spread across - lowResult = delta * lo; - } - } - - } - - return (static_cast(hiResult) << 8) + lowResult; - } - - -private: - static const uint8_t _table[256]; - -}; diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h b/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h deleted file mode 100644 index aef9d9a899..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorBase.h +++ /dev/null @@ -1,69 +0,0 @@ -/*------------------------------------------------------------------------- -RgbColorBase provides a RGB color object common support - -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 - -struct HslColor; -struct HsbColor; -struct HtmlColor; -struct Rgb16Color; - -struct RgbColorBase -{ - -protected: - static float _CalcColor(float p, float q, float t); - - static void _HslToRgb(const HslColor& color, float* r, float* g, float* b); - - static void _HsbToRgb(const HsbColor& color, float* r, float* g, float* b); - - template static T_RESULT _Compare( - const T_COLOR& left, - const T_COLOR& right, - T_RESULT epsilon) - { - T_RESULT result = 0; - T_RESULT resultAbs = 0; - - for (size_t elem = 0; elem < T_COLOR::Count; elem++) - { - T_RESULT delta = static_cast(left[elem]) - right[elem]; - T_RESULT deltaAbs = abs(delta); - - if (deltaAbs > resultAbs) - { - resultAbs = deltaAbs; - result = delta; - } - } - - if (resultAbs > epsilon) - { - return result; - } - return 0; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h b/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h deleted file mode 100644 index ea2bac0bfc..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbColorIndexes.h +++ /dev/null @@ -1,35 +0,0 @@ -/*------------------------------------------------------------------------- -RgbColorIndexes provides constants for color element vector access on - RGB(w) Color Objects - -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 - -const uint8_t ColorIndexR = 0; -const uint8_t ColorIndexG = 1; -const uint8_t ColorIndexB = 2; -const uint8_t ColorIndexW = 3; -const uint8_t ColorIndexWW = 3; // warmer white -const uint8_t ColorIndexCW = 4; // cooler white \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp b/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp deleted file mode 100644 index e90f7af734..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/*------------------------------------------------------------------------- -Rgbw64Color provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" -#include "RgbwColor.h" -#include "Rgb48Color.h" -#include "HslColor.h" -#include "HsbColor.h" -#include "Rgbw64Color.h" -#include "HtmlColor.h" - -Rgbw64Color::Rgbw64Color(const HslColor& color) -{ - Rgb48Color rgbColor(color); - *this = rgbColor; -} - -Rgbw64Color::Rgbw64Color(const HsbColor& color) -{ - Rgb48Color rgbColor(color); - *this = rgbColor; -} - -uint16_t Rgbw64Color::CalculateBrightness() const -{ - uint16_t colorB = static_cast((static_cast(R) + static_cast(G) + static_cast(B)) / 3); - if (W > colorB) - { - return W; - } - else - { - return colorB; - } -} - -Rgbw64Color Rgbw64Color::Dim(uint16_t ratio) const -{ - // specifically avoids float math - return Rgbw64Color(_elementDim(R, ratio), _elementDim(G, ratio), _elementDim(B, ratio), _elementDim(W, ratio)); -} - -Rgbw64Color Rgbw64Color::Brighten(uint16_t ratio) const -{ - // specifically avoids float math - return Rgbw64Color(_elementBrighten(R, ratio), _elementBrighten(G, ratio), _elementBrighten(B, ratio), _elementBrighten(W, ratio)); -} - -void Rgbw64Color::Darken(uint16_t delta) -{ - if (R > delta) - { - R -= delta; - } - else - { - R = 0; - } - - if (G > delta) - { - G -= delta; - } - else - { - G = 0; - } - - if (B > delta) - { - B -= delta; - } - else - { - B = 0; - } - - if (W > delta) - { - W -= delta; - } - else - { - W = 0; - } -} - -void Rgbw64Color::Lighten(uint16_t delta) -{ - if (IsColorLess()) - { - if (W < Max - delta) - { - W += delta; - } - else - { - W = Max; - } - } - else - { - if (R < Max - delta) - { - R += delta; - } - else - { - R = Max; - } - - if (G < Max - delta) - { - G += delta; - } - else - { - G = Max; - } - - if (B < Max - delta) - { - B += delta; - } - else - { - B = Max; - } - } -} - -Rgbw64Color Rgbw64Color::LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, float progress) -{ - return Rgbw64Color( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.W + ((static_cast(right.W) - left.W) * progress) ); -} -Rgbw64Color Rgbw64Color::LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, uint8_t progress) -{ - return Rgbw64Color(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.W + (((static_cast(right.W) - left.W) * static_cast(progress) + 1) >> 8)); -} - -Rgbw64Color Rgbw64Color::BilinearBlend(const Rgbw64Color& c00, - const Rgbw64Color& c01, - const Rgbw64Color& c10, - const Rgbw64Color& c11, - float x, - float y) -{ - float v00 = (1.0f - x) * (1.0f - y); - float v10 = x * (1.0f - y); - float v01 = (1.0f - x) * y; - float v11 = x * y; - - return Rgbw64Color( - c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11, - c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11, - c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11, - c00.W * v00 + c10.W * v10 + c01.W * v01 + c11.W * v11 ); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h b/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h deleted file mode 100644 index 9729740d86..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/Rgbw64Color.h +++ /dev/null @@ -1,348 +0,0 @@ -/*------------------------------------------------------------------------- -Rgbw64Color provides a color object that can be directly consumed by NeoPixelBus - -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 - -struct RgbColor; -struct HslColor; -struct HsbColor; - -// ------------------------------------------------------------------------ -// Rgbw64Color represents a color object that is represented by Red, Green, Blue -// component values and an extra White component. It contains helpful color -// routines to manipulate the color. -// ------------------------------------------------------------------------ -struct Rgbw64Color : RgbColorBase -{ - typedef NeoRgbwCurrentSettings SettingsObject; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using R, G, B, W values (0-65535) - // ------------------------------------------------------------------------ - Rgbw64Color(uint16_t r, uint16_t g, uint16_t b, uint16_t w = 0) : - R(r), G(g), B(b), W(w) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbColor using a single brightness value (0-65535) - // This works well for creating gray tone colors - // (0) = black, (65535) = white, (32768) = gray - // ------------------------------------------------------------------------ - Rgbw64Color(uint16_t brightness) : - R(0), G(0), B(0), W(brightness) - { - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using RgbColor - // ------------------------------------------------------------------------ - Rgbw64Color(const RgbColor& color) - { - *this = Rgb48Color(color); - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using Rgb48Color - // ------------------------------------------------------------------------ - Rgbw64Color(const Rgb48Color& color) : - R(color.R), - G(color.G), - B(color.B), - W(0) - { - }; - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using RgbwColor - // ------------------------------------------------------------------------ - Rgbw64Color(const RgbwColor& color) - { - // x16 = map(x8, 0, 255, 0, 65535); // refactors to just * 257 - R = (uint16_t)color.R * 257; // 257 = MAXUINT16/MAXUINT8 = 65535/255 - G = (uint16_t)color.G * 257; - B = (uint16_t)color.B * 257; - W = (uint16_t)color.W * 257; - }; - - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HtmlColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HtmlColor& color) - { - *this = RgbwColor(color); - } - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HslColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HslColor& color); - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color using HsbColor - // ------------------------------------------------------------------------ - Rgbw64Color(const HsbColor& color); - - // ------------------------------------------------------------------------ - // Construct a Rgbw64Color that will have its values set in latter operations - // CAUTION: The R,G,B, W members are not initialized and may not be consistent - // ------------------------------------------------------------------------ - Rgbw64Color() - { - }; - - // ------------------------------------------------------------------------ - // Comparison operators - // ------------------------------------------------------------------------ - bool operator==(const Rgbw64Color& other) const - { - return (R == other.R && G == other.G && B == other.B && W == other.W); - }; - - bool operator!=(const Rgbw64Color& other) const - { - return !(*this == other); - }; - - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int32_t CompareTo(const Rgbw64Color& other, uint16_t epsilon = 256) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int32_t Compare(const Rgbw64Color& left, const Rgbw64Color& right, uint16_t epsilon = 256) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint16_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - default: - return W; - } - } - - // ------------------------------------------------------------------------ - // Returns if the color is grey, all values are equal other than white - // ------------------------------------------------------------------------ - bool IsMonotone() const - { - return (R == B && R == G); - }; - - // ------------------------------------------------------------------------ - // Returns if the color components are all zero, the white component maybe - // anything - // ------------------------------------------------------------------------ - bool IsColorLess() const - { - return (R == 0 && B == 0 && G == 0); - }; - - // ------------------------------------------------------------------------ - // CalculateBrightness will calculate the overall brightness - // NOTE: This is a simple linear brightness - // ------------------------------------------------------------------------ - uint16_t CalculateBrightness() const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-65535) where 65535 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Dim(uint16_t ratio) const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Dim(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Dim(expanded); - } - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-65535) where 65535 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Brighten(uint16_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - Rgbw64Color Brighten(uint8_t ratio) const - { - uint16_t expanded = ratio << 8; - return Brighten(expanded); - } - - // ------------------------------------------------------------------------ - // Darken will adjust the color by the given delta toward black - // NOTE: This is a simple linear change - // delta - (0-65535) the amount to dim the color - // ------------------------------------------------------------------------ - void Darken(uint16_t delta); - - // ------------------------------------------------------------------------ - // Lighten will adjust the color by the given delta toward white - // NOTE: This is a simple linear change - // delta - (0-65535) the amount to lighten the color - // ------------------------------------------------------------------------ - void Lighten(uint16_t delta); - - // ------------------------------------------------------------------------ - // LinearBlend between two colors by the amount defined by progress variable - // left - the color to start the blend at - // right - the color to end the blend at - // progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgbw64Color LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static Rgbw64Color LinearBlend(const Rgbw64Color& left, const Rgbw64Color& right, uint8_t progress); - - // ------------------------------------------------------------------------ - // BilinearBlend between four colors by the amount defined by 2d variable - // c00 - upper left quadrant color - // c01 - upper right quadrant color - // c10 - lower left quadrant color - // c11 - lower right quadrant color - // x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space - // y - unit value (0.0 - 1.0) that defines the blend progress in vertical space - // ------------------------------------------------------------------------ - static Rgbw64Color BilinearBlend(const Rgbw64Color& c00, - const Rgbw64Color& c01, - const Rgbw64Color& c10, - const Rgbw64Color& c11, - float x, - float y); - - uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) - { - auto total = 0; - - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += W * settings.WhiteTenthMilliAmpere / Max; - - return total; - } - - // ------------------------------------------------------------------------ - // Red, Green, Blue, White color members (0-65535) where - // (0,0,0,0) is black and (65535,65535,65535, 0) and (0,0,0,65535) is white - // Note (65535,65535,65535,65535) is extreme bright white - // ------------------------------------------------------------------------ - uint16_t R; - uint16_t G; - uint16_t B; - uint16_t W; - - const static uint16_t Max = 65535; - const static size_t Count = 4; // four elements in [] - -private: - inline static uint16_t _elementDim(uint16_t value, uint16_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 16; - } - - inline static uint16_t _elementBrighten(uint16_t value, uint16_t ratio) - { - uint32_t element = ((static_cast(value) + 1) << 16) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } -}; - diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp b/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp deleted file mode 100644 index 9751bc2602..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/*------------------------------------------------------------------------- -RgbwwColor provides a color object that can be directly consumed by NeoPixelBus - -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 -. --------------------------------------------------------------------------*/ - -#include -#include "../NeoSettings.h" -#include "RgbColorBase.h" -#include "RgbColor.h" -#include "RgbwColor.h" -#include "Rgb48Color.h" -#include "HslColor.h" -#include "HsbColor.h" -#include "HtmlColor.h" - -#include "RgbwwColor.h" - -RgbwwColor::RgbwwColor(const HtmlColor& color) -{ - uint32_t temp = color.Color; - B = (temp & 0xff); - temp = temp >> 8; - G = (temp & 0xff); - temp = temp >> 8; - R = (temp & 0xff); - temp = temp >> 8; - WW = (temp & 0xff); - CW = WW; -}; - -RgbwwColor::RgbwwColor(const HslColor& color) -{ - RgbColor rgbColor(color); - *this = rgbColor; -} - -RgbwwColor::RgbwwColor(const HsbColor& color) -{ - RgbColor rgbColor(color); - *this = rgbColor; -} - -uint8_t RgbwwColor::CalculateBrightness() const -{ - uint8_t colorB = static_cast((static_cast(R) + static_cast(G) + static_cast(B)) / 3); - uint8_t whiteB = static_cast((static_cast(WW) + static_cast(CW)) / 2); - - return (whiteB > colorB) ? whiteB : colorB; -} - -RgbwwColor RgbwwColor::Dim(uint8_t ratio) const -{ - // specifically avoids float math - return RgbwwColor(_elementDim(R, ratio), - _elementDim(G, ratio), - _elementDim(B, ratio), - _elementDim(WW, ratio), - _elementDim(CW, ratio)); -} - -RgbwwColor RgbwwColor::Brighten(uint8_t ratio) const -{ - // specifically avoids float math - return RgbwwColor(_elementBrighten(R, ratio), - _elementBrighten(G, ratio), - _elementBrighten(B, ratio), - _elementBrighten(WW, ratio), - _elementBrighten(CW, ratio)); -} - -void RgbwwColor::Darken(uint8_t delta) -{ - if (R > delta) - { - R -= delta; - } - else - { - R = 0; - } - - if (G > delta) - { - G -= delta; - } - else - { - G = 0; - } - - if (B > delta) - { - B -= delta; - } - else - { - B = 0; - } - - if (WW > delta) - { - WW -= delta; - } - else - { - WW = 0; - } - - if (CW > delta) - { - CW -= delta; - } - else - { - CW = 0; - } -} - -void RgbwwColor::Lighten(uint8_t delta) -{ - if (IsColorLess()) - { - if (WW < 255 - delta) - { - WW += delta; - } - else - { - WW = 255; - } - - if (CW < 255 - delta) - { - CW += delta; - } - else - { - CW = 255; - } - } - else - { - if (R < 255 - delta) - { - R += delta; - } - else - { - R = 255; - } - - if (G < 255 - delta) - { - G += delta; - } - else - { - G = 255; - } - - if (B < 255 - delta) - { - B += delta; - } - else - { - B = 255; - } - } -} - -RgbwwColor RgbwwColor::LinearBlend(const RgbwwColor& left, const RgbwwColor& right, float progress) -{ - return RgbwwColor( left.R + ((static_cast(right.R) - left.R) * progress), - left.G + ((static_cast(right.G) - left.G) * progress), - left.B + ((static_cast(right.B) - left.B) * progress), - left.WW + ((static_cast(right.WW) - left.WW) * progress), - left.CW + ((static_cast(right.CW) - left.CW) * progress)); -} - -RgbwwColor RgbwwColor::LinearBlend(const RgbwwColor& left, const RgbwwColor& right, uint8_t progress) -{ - return RgbwwColor(left.R + (((static_cast(right.R) - left.R) * static_cast(progress) + 1) >> 8), - left.G + (((static_cast(right.G) - left.G) * static_cast(progress) + 1) >> 8), - left.B + (((static_cast(right.B) - left.B) * static_cast(progress) + 1) >> 8), - left.WW + (((static_cast(right.WW) - left.WW) * static_cast(progress) + 1) >> 8), - left.CW + (((static_cast(right.CW) - left.CW) * static_cast(progress) + 1) >> 8)); -} - -RgbwwColor RgbwwColor::BilinearBlend(const RgbwwColor& c00, - const RgbwwColor& c01, - const RgbwwColor& c10, - const RgbwwColor& c11, - float x, - float y) -{ - float v00 = (1.0f - x) * (1.0f - y); - float v10 = x * (1.0f - y); - float v01 = (1.0f - x) * y; - float v11 = x * y; - - return RgbwwColor( - c00.R * v00 + c10.R * v10 + c01.R * v01 + c11.R * v11, - c00.G * v00 + c10.G * v10 + c01.G * v01 + c11.G * v11, - c00.B * v00 + c10.B * v10 + c01.B * v01 + c11.B * v11, - c00.WW * v00 + c10.WW * v10 + c01.WW * v01 + c11.WW * v11, - c00.CW * v00 + c10.CW * v10 + c01.CW * v01 + c11.CW * v11); -} \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h b/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h deleted file mode 100644 index 8833e783d5..0000000000 --- a/lib/NeoPixelBus/src/internal/colors/RgbwwColor.h +++ /dev/null @@ -1,325 +0,0 @@ -/*------------------------------------------------------------------------- -RgbwwColor provides a color object that can be directly consumed by NeoPixelBus - -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 - -struct RgbColor; -struct HslColor; -struct HsbColor; - -// ------------------------------------------------------------------------ -// RgbwwColor represents a color object that is represented by Red, Green, Blue -// component values and two extra White components. -// While the white components are labeled as WW (warm) and CW (cool), they can be -// considered as the "warmer" and "cooler" whites of your LEDs; so that if yours -// have Nuetral and Cool, you could consider the WW as your nuetral. -// It contains helpful color routines to manipulate the color. -// ------------------------------------------------------------------------ -struct RgbwwColor : RgbColorBase -{ - typedef NeoRgbwwCurrentSettings SettingsObject; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using R, G, B, WW, CW values (0-255) - // ------------------------------------------------------------------------ - RgbwwColor(uint8_t r, uint8_t g, uint8_t b, uint8_t warmW = 0, uint8_t coolW = 0) : - R(r), G(g), B(b), WW(warmW), CW(coolW) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using a single brightness value (0-255) - // This works well for creating gray tone colors - // (0) = black, (255) = white, (128) = gray - // ------------------------------------------------------------------------ - RgbwwColor(uint8_t brightness) : - R(0), G(0), B(0), WW(brightness), CW(brightness) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using RgbColor - // ------------------------------------------------------------------------ - RgbwwColor(const RgbColor& color) : - R(color.R), - G(color.G), - B(color.B), - WW(0), - CW(0) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using RgbwColor - // ------------------------------------------------------------------------ - RgbwwColor(const RgbwColor& color) : - R(color.R), - G(color.G), - B(color.B), - WW(color.W), - CW(color.W) - { - }; - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HtmlColor - // ------------------------------------------------------------------------ - RgbwwColor(const HtmlColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HslColor - // ------------------------------------------------------------------------ - RgbwwColor(const HslColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor using HsbColor - // ------------------------------------------------------------------------ - RgbwwColor(const HsbColor& color); - - // ------------------------------------------------------------------------ - // Construct a RgbwwColor that will have its values set in latter operations - // CAUTION: The R,G,B, WW, CW members are not initialized and may not be consistent - // ------------------------------------------------------------------------ - RgbwwColor() - { - }; - - // ------------------------------------------------------------------------ - // Comparison operators - // ------------------------------------------------------------------------ - bool operator==(const RgbwwColor& other) const - { - return (R == other.R && G == other.G && B == other.B && WW == other.WW && CW == other.CW); - }; - - bool operator!=(const RgbwwColor& other) const - { - return !(*this == other); - }; - - // ------------------------------------------------------------------------ - // CompareTo method - // compares against another color with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - this is less than other - // positive - this is greater than other - // ------------------------------------------------------------------------ - int16_t CompareTo(const RgbwwColor& other, uint8_t epsilon = 1) - { - return _Compare(*this, other, epsilon); - } - - // ------------------------------------------------------------------------ - // Compare method - // compares two colors with the given epsilon (delta allowed) - // returns the greatest difference of a set of elements, - // 0 = equal within epsilon delta - // negative - left is less than right - // positive - left is greater than right - // ------------------------------------------------------------------------ - static int16_t Compare(const RgbwwColor& left, const RgbwwColor& right, uint8_t epsilon = 1) - { - return _Compare(left, right, epsilon); - } - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than R,G,B,WW,CW - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - case 3: - return WW; - default: - return CW; - } - } - - // ------------------------------------------------------------------------ - // operator [] - read write - // access elements in order by index rather than R,G,B,WW,CW - // see static Count for the number of elements - // ------------------------------------------------------------------------ - uint8_t& operator[](size_t idx) - { - switch (idx) - { - case 0: - return R; - case 1: - return G; - case 2: - return B; - case 3: - return WW; - default: - return CW; - } - } - - // ------------------------------------------------------------------------ - // Returns if the color is grey, all values are equal other than whites - // ------------------------------------------------------------------------ - bool IsMonotone() const - { - return (R == B && R == G); - }; - - // ------------------------------------------------------------------------ - // Returns if the color components are all zero, the white components maybe - // anything - // ------------------------------------------------------------------------ - bool IsColorLess() const - { - return (R == 0 && B == 0 && G == 0); - }; - - // ------------------------------------------------------------------------ - // CalculateBrightness will calculate the overall brightness - // NOTE: This is a simple linear brightness - // ------------------------------------------------------------------------ - uint8_t CalculateBrightness() const; - - // ------------------------------------------------------------------------ - // Dim will return a new color that is blended to black with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return black - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - RgbwwColor Dim(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Brighten will return a new color that is blended to white with the given ratio - // ratio - (0-255) where 255 will return the original color and 0 will return white - // - // NOTE: This is a simple linear blend - // ------------------------------------------------------------------------ - RgbwwColor Brighten(uint8_t ratio) const; - - // ------------------------------------------------------------------------ - // Darken will adjust the color by the given delta toward black - // NOTE: This is a simple linear change - // delta - (0-255) the amount to dim the color - // ------------------------------------------------------------------------ - void Darken(uint8_t delta); - - // ------------------------------------------------------------------------ - // Lighten will adjust the color by the given delta toward white - // NOTE: This is a simple linear change - // delta - (0-255) the amount to lighten the color - // ------------------------------------------------------------------------ - void Lighten(uint8_t delta); - - // ------------------------------------------------------------------------ - // LinearBlend between two colors by the amount defined by progress variable - // left - the color to start the blend at - // right - the color to end the blend at - // progress - (0.0 - 1.0) value where 0 will return left and 1.0 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwwColor LinearBlend(const RgbwwColor& left, const RgbwwColor& right, float progress); - // progress - (0 - 255) value where 0 will return left and 255 will return right - // and a value between will blend the color weighted linearly between them - // ------------------------------------------------------------------------ - static RgbwwColor LinearBlend(const RgbwwColor& left, const RgbwwColor& right, uint8_t progress); - - // ------------------------------------------------------------------------ - // BilinearBlend between four colors by the amount defined by 2d variable - // c00 - upper left quadrant color - // c01 - upper right quadrant color - // c10 - lower left quadrant color - // c11 - lower right quadrant color - // x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space - // y - unit value (0.0 - 1.0) that defines the blend progress in vertical space - // ------------------------------------------------------------------------ - static RgbwwColor BilinearBlend(const RgbwwColor& c00, - const RgbwwColor& c01, - const RgbwwColor& c10, - const RgbwwColor& c11, - float x, - float y); - - uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) - { - auto total = 0; - - total += R * settings.RedTenthMilliAmpere / Max; - total += G * settings.GreenTenthMilliAmpere / Max; - total += B * settings.BlueTenthMilliAmpere / Max; - total += WW * settings.WarmWhiteTenthMilliAmpere / Max; - total += CW * settings.CoolWhiteTenthMilliAmpere / Max; - - return total; - } - - // ------------------------------------------------------------------------ - // Red, Green, Blue, Warm White, Cool White color members (0-255) where - // (0,0,0,0,0) is black and - // (255,255,255, 0, 0) is a white - // (0,0,0,255,0) is warm white and - // (0,0,0,0,255) is cool white and - // Note (255,255,255,255,255) is extreme bright white - // ------------------------------------------------------------------------ - uint8_t R; - uint8_t G; - uint8_t B; - uint8_t WW; - uint8_t CW; - - const static uint8_t Max = 255; - const static size_t Count = 5; // four elements in [] - -private: - inline static uint8_t _elementDim(uint8_t value, uint8_t ratio) - { - return (static_cast(value) * (static_cast(ratio) + 1)) >> 8; - } - - inline static uint8_t _elementBrighten(uint8_t value, uint8_t ratio) - { - uint16_t element = ((static_cast(value) + 1) << 8) / (static_cast(ratio) + 1); - - if (element > Max) - { - element = Max; - } - else - { - element -= 1; - } - return element; - } -}; - diff --git a/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h deleted file mode 100644 index 0e6a0b17f6..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarL4ByteFeature.h +++ /dev/null @@ -1,70 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarL4Feature provides feature base class to describe color order for - 3 color but 4 byte features when used with DotStars, exposing Luminance as W - -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 - -template -class DotStarL4Feature : - public NeoByteElements<4, RgbwColor, uint32_t> -{ -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[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color.W = (*p++) & 0x1F; // mask out upper three bits - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *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[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h b/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h deleted file mode 100644 index 17c6d4f708..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarLrgbFeatures.h +++ /dev/null @@ -1,65 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarLrgbFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStars - -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 - -class DotStarLrgbFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLrbgFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarLgrbFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLgbrFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarLbrgFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarLbgrFeature : - public DotStarL4Feature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h b/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h deleted file mode 100644 index 158e579d7f..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarRgbFeatures.h +++ /dev/null @@ -1,65 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarRbgFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStars - -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 - -class DotStarRgbFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarRbgFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarGbrFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarGrbFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - - -class DotStarBrgFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; - -class DotStarBgrFeature : - public DotStarX4Feature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h deleted file mode 100644 index 2d2aeb71fb..0000000000 --- a/lib/NeoPixelBus/src/internal/features/DotStarX4ByteFeature.h +++ /dev/null @@ -1,70 +0,0 @@ -/*------------------------------------------------------------------------- -DotStarX4Feature provides feature base class to describe color order for - 3 color but 4 byte features when used with DotStars - -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 - -template -class DotStarX4Feature : - public NeoByteElements<4, RgbColor, uint32_t> -{ -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[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first byte - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *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[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h b/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h deleted file mode 100644 index 15e8fa52c0..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Lpd6803RgbFeatures.h +++ /dev/null @@ -1,52 +0,0 @@ -/*------------------------------------------------------------------------- -Lpd6803RgbFeature provides feature class to describe color order and -color depth for NeoPixelBus template class when used with DotStar like chips - -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 - -class Lpd6803RgbFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - - -class Lpd6803GrbFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd6803GbrFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd6803BrgFeature : - public Neo2Byte555Feature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h b/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h deleted file mode 100644 index e800a1f996..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Lpd8806RgbFeatures.h +++ /dev/null @@ -1,39 +0,0 @@ -/*------------------------------------------------------------------------- -Lpd8806RgbFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with DotStar like chips - -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 - -class Lpd8806GrbFeature : - public Neo3Byte777Feature, - public NeoElementsNoSettings -{ -}; - -class Lpd8806BrgFeature : - public Neo3Byte777Feature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h b/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h deleted file mode 100644 index a9fca0d3fb..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo2Byte555Feature.h +++ /dev/null @@ -1,89 +0,0 @@ -/*------------------------------------------------------------------------- -Neo2Byte555Feature provides feature base classes to describe color elements -with 555 encoding for NeoPixelBus Color Feature template classes - -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 - -template -class Neo2Byte555Feature : - public NeoByteElements<2, RgbColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint16_t color555; - - encodePixel(&color555, color); - *p++ = color555 >> 8; - *p = color555 & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - uint16_t color555; - - color555 = ((*p++) << 8); - color555 |= (*p); - - decodePixel(&color, color555); - - 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); - - uint16_t color555; - - color555 = (pgm_read_byte(p++) << 8); - color555 |= pgm_read_byte(p); - - decodePixel(&color, color555); - - return color; - } - -protected: - static void encodePixel(uint16_t* color555, const ColorObject& color) - { - *color555 = (0x8000 | - ((color[V_IC_1] & 0xf8) << 7) | - ((color[V_IC_2] & 0xf8) << 2) | - ((color[V_IC_3] & 0xf8) >> 3)); - } - - static void decodePixel(ColorObject* color, uint16_t color555) - { - (*color)[V_IC_2] = (color555 >> 2) & 0xf8; - (*color)[V_IC_3] = (color555 << 3) & 0xf8; - (*color)[V_IC_1] = (color555 >> 7) & 0xf8; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h b/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h deleted file mode 100644 index 1ce703161d..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3Byte777Feature.h +++ /dev/null @@ -1,67 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3Byte777Feature provides feature base class to describe color order for - 3 byte features that only support 7 bits per element - -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 - -template -class Neo3Byte777Feature : - public NeoByteElements<3, RgbColor, uint8_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = (color[V_IC_1] >> 1) | 0x80; - *p++ = (color[V_IC_2] >> 1) | 0x80; - *p = (color[V_IC_3] >> 1) | 0x80; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = (*p++) << 1; - color[V_IC_2] = (*p++) << 1; - color[V_IC_3] = (*p) << 1; - - return color; - } - - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = (pgm_read_byte(p++)) << 1; - color[V_IC_2] = (pgm_read_byte(p++)) << 1; - color[V_IC_3] = (pgm_read_byte(p)) << 1; - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h deleted file mode 100644 index d6a228fdd8..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3ByteFeature.h +++ /dev/null @@ -1,67 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3ByteFeature provides feature base class to describe color order for - 3 byte features - -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 - -template -class Neo3ByteFeature : - public NeoByteElements<3, RgbColor, uint8_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p = color[V_IC_3]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p; - - return color; - } - - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p); - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h b/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h deleted file mode 100644 index 4d74092688..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo3WordFeature.h +++ /dev/null @@ -1,77 +0,0 @@ -/*------------------------------------------------------------------------- -Neo3WordFeature provides feature base class to describe color order for - 3 Word features - -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 - -template -class Neo3WordFeature : - public NeoWordElements<6, Rgb48Color, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p = color[V_IC_3] & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p); - - return color; - } - - }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h deleted file mode 100644 index eea734c763..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo4ByteFeature.h +++ /dev/null @@ -1,69 +0,0 @@ -/*------------------------------------------------------------------------- -Neo4ByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 5 bytes - -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 - -template -class Neo4ByteFeature : - public NeoByteElements<4, RgbwColor, uint32_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p = color[V_IC_4]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p); - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h b/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h deleted file mode 100644 index fe3d3ad80a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo4WordFeature.h +++ /dev/null @@ -1,82 +0,0 @@ -/*------------------------------------------------------------------------- -Neo4WordFeature provides feature base class to describe color order for - 4 Word features - -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 - -template -class Neo4WordFeature : - public NeoWordElements<8, Rgbw64Color, uint32_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p++ = color[V_IC_3] & 0xff; - *p++ = color[V_IC_4] >> 8; - *p = color[V_IC_4] & 0xff; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p++; - color[V_IC_4] = (static_cast(*p++) << 8); - color[V_IC_4] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p++); - color[V_IC_4] = pgm_read_word(p); - - return color; - } - - }; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h deleted file mode 100644 index 9b732c604a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo6xByteFeature.h +++ /dev/null @@ -1,76 +0,0 @@ -/*------------------------------------------------------------------------- -Neo6xByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 5 bytes - -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 - -template -class Neo6xByteFeature : - public NeoByteElements<6, RgbwwColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p++ = color[V_IC_4]; - *p++ = color[V_IC_5]; - - *p = 0x00; // X - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p++; - color[V_IC_5] = *p; - // ignore the x - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p++); - color[V_IC_5] = pgm_read_byte(p); - // ignore the x - - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h b/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h deleted file mode 100644 index 6b5bdec25a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/Neo6xxByteFeature.h +++ /dev/null @@ -1,73 +0,0 @@ -/*------------------------------------------------------------------------- -Neo6xxByteFeature provides feature base class to describe color order for - 6 byte features that only use the first 4 bytes - -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 - -template -class Neo6xxByteFeature : - public NeoByteElements<6, RgbwColor, uint16_t> -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = color[V_IC_1]; - *p++ = color[V_IC_2]; - *p++ = color[V_IC_3]; - *p++ = color[V_IC_4]; - // zero the xx, this maybe unnecessary though, but its thorough - *p++ = 0x00; - *p = 0x00; // X - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color[V_IC_1] = *p++; - color[V_IC_2] = *p++; - color[V_IC_3] = *p++; - color[V_IC_4] = *p; - // ignore the xx - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); - - color[V_IC_1] = pgm_read_byte(p++); - color[V_IC_2] = pgm_read_byte(p++); - color[V_IC_3] = pgm_read_byte(p++); - color[V_IC_4] = pgm_read_byte(p); - // ignore the xx - return color; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h b/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h deleted file mode 100644 index 940abd847c..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoAbcdefgpsSegmentFeature.h +++ /dev/null @@ -1,72 +0,0 @@ -/*------------------------------------------------------------------------- -NeoAbcdefgpsSegmentFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with seven segment display - -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 - -// Abcdefgps byte order -class NeoAbcdefgpsSegmentFeature : - public NeoByteElements<9, SevenSegDigit, uint8_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - *p++ = color.Segment[iSegment]; - } - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - color.Segment[iSegment] = *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); - uint8_t commonSize = (PixelSize < color.Count) ? PixelSize : color.Count; - - for (uint8_t iSegment = 0; iSegment < commonSize; iSegment++) - { - color.Segment[iSegment] = pgm_read_byte(p++); - } - - return color; - } - -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h b/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h deleted file mode 100644 index 9a36f85bd8..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoBacedfpgsSegmentFeature.h +++ /dev/null @@ -1,93 +0,0 @@ -/*------------------------------------------------------------------------- -NeoBacedfpgsSegmentFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with seven segment display - -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 - -// BACEDF.G+ byte order -class NeoBacedfpgsSegmentFeature : - public NeoByteElements<9, SevenSegDigit, uint8_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - // Segment Digit is Abcdefgps order - *p++ = color.Segment[LedSegment_B]; - *p++ = color.Segment[LedSegment_A]; - *p++ = color.Segment[LedSegment_C]; - - *p++ = color.Segment[LedSegment_E]; - *p++ = color.Segment[LedSegment_D]; - *p++ = color.Segment[LedSegment_F]; - - *p++ = color.Segment[LedSegment_Decimal]; - *p++ = color.Segment[LedSegment_G]; - *p++ = color.Segment[LedSegment_Custom]; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - color.Segment[LedSegment_B] = *p++; - color.Segment[LedSegment_A] = *p++; - color.Segment[LedSegment_C] = *p++; - - color.Segment[LedSegment_E] = *p++; - color.Segment[LedSegment_D] = *p++; - color.Segment[LedSegment_F] = *p++; - - color.Segment[LedSegment_Decimal] = *p++; - color.Segment[LedSegment_G] = *p++; - color.Segment[LedSegment_Custom] = *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.Segment[LedSegment_B] = pgm_read_byte(p++); - color.Segment[LedSegment_A] = pgm_read_byte(p++); - color.Segment[LedSegment_C] = pgm_read_byte(p++); - - color.Segment[LedSegment_E] = pgm_read_byte(p++); - color.Segment[LedSegment_D] = pgm_read_byte(p++); - color.Segment[LedSegment_F] = pgm_read_byte(p++); - - color.Segment[LedSegment_Decimal] = pgm_read_byte(p++); - color.Segment[LedSegment_G] = pgm_read_byte(p++); - color.Segment[LedSegment_Custom] = pgm_read_byte(p++); - - return color; - } - -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoByteElements.h b/lib/NeoPixelBus/src/internal/features/NeoByteElements.h deleted file mode 100644 index 3075bdc5d5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoByteElements.h +++ /dev/null @@ -1,139 +0,0 @@ -/*------------------------------------------------------------------------- -NeoByteElements provides feature base classes to describe color elements -for NeoPixelBus Color Feature template classes - -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 - -// NeoElementsBase contains common methods used by features to map and -// copy pixel memory data in native stream format -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoElementsBase -{ -public: - static const size_t PixelSize = V_PIXEL_SIZE; - typedef T_COLOR_OBJECT ColorObject; - - static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) - { - return pPixels + indexPixel * PixelSize; - } - static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) - { - return pPixels + indexPixel * PixelSize; - } - - static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY)); - const T_COPY* pEndSrc = reinterpret_cast(pPixelSrc) + PixelSize / sizeof(T_COPY); - - while (pDest < pEnd) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - while (pSrc < pEndSrc) - { - *pDest++ = *pSrc++; - } - } - } - - static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pEnd = pDest + (count * PixelSize / sizeof(T_COPY)); - - while (pDest < pEnd) - { - *pDest++ = *pSrc++; - } - } - - static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) - { - const T_COPY* pSrc = reinterpret_cast(pPixelSrc); - const T_COPY* pSrcBack = pSrc + (count * PixelSize / sizeof(T_COPY)); - T_COPY* pDest = reinterpret_cast(pPixelDest); - T_COPY* pDestBack = pDest + (count * PixelSize / sizeof(T_COPY)); - - while (pDestBack > pDest) - { - *--pDestBack = *--pSrcBack; - } - } -}; - -// NeoByteElements is used for 8bit color element types and less -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint8_t/uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoByteElements : public NeoElementsBase -{ -public: - - static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) - { - uint8_t* pEnd = pPixelDest + (count * NeoElementsBase::PixelSize); - const uint8_t* pSrc = reinterpret_cast(pPixelSrc); - - while (pPixelDest < pEnd) - { - *pPixelDest++ = pgm_read_byte(pSrc++); - } - } -}; - -// NeoWordElements is used for 16bit color element types -// -// V_PIXEL_SIZE - the size in bytes of a pixel in the data stream -// T_COLOR_OBJECT - the primary color object used to represent a pixel -// T_COPY - (uint16_t/uint32_t) the base type to use when copying/moving -template -class NeoWordElements : public NeoElementsBase -{ -public: - - static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) - { - uint16_t* pDest = reinterpret_cast(pPixelDest); - uint16_t* pEnd = pDest + (count * NeoElementsBase::PixelSize / sizeof(uint16_t)); - const uint16_t* pSrc = reinterpret_cast(pPixelSrc); - - while (pDest < pEnd) - { - *pDest++ = pgm_read_word(pSrc++); - } - } -}; - - diff --git a/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h b/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h deleted file mode 100644 index 39827721de..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoElementsNoSettings.h +++ /dev/null @@ -1,49 +0,0 @@ -/*------------------------------------------------------------------------- -NeoElementsNoSettings provides feature base classes to describe a - no settings feature - -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 -#include "../NeoUtil.h" - -class NeoElementsNoSettings -{ -public: - typedef NeoNoSettings SettingsObject; - static const size_t SettingsSize = 0; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h b/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h deleted file mode 100644 index c9a2165619..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgb48Features.h +++ /dev/null @@ -1,63 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgb48Feature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - -class NeoRgb48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbg48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrb48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbr48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgr48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrg48Feature : - public Neo3WordFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h deleted file mode 100644 index ec4cb06529..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbFeatures.h +++ /dev/null @@ -1,64 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - -class NeoRgbFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgFeature : - public Neo3ByteFeature, - public NeoElementsNoSettings -{ -}; - diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h deleted file mode 100644 index 42f475cbf5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbcwxFeatures.h +++ /dev/null @@ -1,33 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbcwxFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - -class NeoGrbcwxFeature : - public Neo6xByteFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h b/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h deleted file mode 100644 index b04e76f5b5..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbw64Features.h +++ /dev/null @@ -1,66 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbw64Feature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - - -class NeoRgbw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgw64Feature : - public Neo4WordFeature, - public NeoElementsNoSettings -{ -}; - - diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h deleted file mode 100644 index 9d92a59252..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbwFeatures.h +++ /dev/null @@ -1,63 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbwFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - -class NeoRgbwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoRbgwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGbrwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoGrbwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBgrwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; - -class NeoBrgwFeature : - public Neo4ByteFeature, - public NeoElementsNoSettings -{ -}; \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h deleted file mode 100644 index c27af05996..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoRgbwxxFeatures.h +++ /dev/null @@ -1,33 +0,0 @@ -/*------------------------------------------------------------------------- -NeoRgbwxxFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class - -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 - -class NeoRgbwxxFeature : - public Neo6xxByteFeature, - public NeoElementsNoSettings -{ -}; diff --git a/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h b/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h deleted file mode 100644 index 1ce33b5032..0000000000 --- a/lib/NeoPixelBus/src/internal/features/NeoSm168xxFeatures.h +++ /dev/null @@ -1,305 +0,0 @@ -/*------------------------------------------------------------------------- -NeoSm168xxFeatures provides feature classes to describe color order and -color depth for NeoPixelBus template class specific to the SM168xx chips/leds - -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 -/* -3 channel RGB -SM16803P 1.8~60mA << need spec sheet to get accurate implementation -SM16813PB 1.8~19mA -SM16823E 60~350mA -4 channel RGBW -SM16804PB 1.5~60mA << need spec sheet to get accurate implementation -SM16804EB 1.8~19mA -SM16824E 60~350mA -*/ - -#include "../NeoUtil.h" - -class NeoSm168x3SettingsBase : public NeoRgbCurrentSettings -{ -public: - NeoSm168x3SettingsBase(uint8_t redGain, - uint8_t greenGain, - uint8_t blueGain, - uint16_t redCurrent, - uint16_t greenCurrent, - uint16_t blueCurrent) : - NeoRgbCurrentSettings(redCurrent, greenCurrent, blueCurrent), - RedGain(redGain & 0x0f), - GreenGain(greenGain & 0x0f), - BlueGain(blueGain & 0x0f) {} - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedGain; - case 1: - return GreenGain; - default: - return BlueGain; - } - } - - const uint8_t RedGain : 4; - const uint8_t GreenGain : 4; - const uint8_t BlueGain : 4; -}; - -template -class NeoSm16803pbSettings : public NeoSm168x3SettingsBase -{ -public: - NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain) : - NeoSm168x3SettingsBase(redGain, - greenGain, - blueGain, - CurrentLookup[redGain], - CurrentLookup[greenGain], - CurrentLookup[blueGain]) - { - } - - void Encode(uint8_t* encoded) const - { - // 0RGB 4 bits each - *encoded++ = operator[](V_IC_1); - *encoded = operator[](V_IC_2) << 4 | operator[](V_IC_3); - } - -protected: - static constexpr uint8_t CurrentLookup[16] = { - 18, 30, 41, 53, 64, 76, 87, 99, - 110, 133, 145, 156, 168, 179, 190}; -}; - -template -class NeoSm16823eSettings : public NeoSm168x3SettingsBase -{ -public: - NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms) : - NeoSm168x3SettingsBase(redGain, - greenGain, - blueGain, - calcCurrent(resisterOhms, redGain), - calcCurrent(resisterOhms, greenGain), - calcCurrent(resisterOhms, blueGain)), - extROhms(resisterOhms) - { - } - - void Encode(uint8_t* encoded) const - { - // RGB0 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4; - } - -protected: - const uint16_t extROhms; - - static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain) - { - uint16_t mA = (967 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead - return mA * 10; // return tenths of mA - } -}; - -// RGBW versions - -class NeoSm168x4SettingsBase : public NeoRgbwCurrentSettings -{ -public: - NeoSm168x4SettingsBase(uint8_t redGain, - uint8_t greenGain, - uint8_t blueGain, - uint8_t whiteGain, - uint16_t redCurrent, - uint16_t greenCurrent, - uint16_t blueCurrent, - uint16_t whiteCurrent) : - NeoRgbwCurrentSettings(redCurrent, greenCurrent, blueCurrent, whiteCurrent), - RedGain(redGain & 0x0f), - GreenGain(greenGain & 0x0f), - BlueGain(blueGain & 0x0f), - WhiteGain(whiteGain & 0x0f) {} - - // ------------------------------------------------------------------------ - // operator [] - readonly - // access elements in order by index rather than member name - // ------------------------------------------------------------------------ - uint8_t operator[](size_t idx) const - { - switch (idx) - { - case 0: - return RedGain; - case 1: - return GreenGain; - case 2: - return BlueGain; - default: - return WhiteGain; - } - } - - const uint8_t RedGain : 4; - const uint8_t GreenGain : 4; - const uint8_t BlueGain : 4; - const uint8_t WhiteGain : 4; -}; - -template -class NeoSm16804ebSettings : public NeoSm168x4SettingsBase -{ -public: - NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain) : - NeoSm168x4SettingsBase(redGain, - greenGain, - blueGain, - whiteGain, - CurrentLookup[redGain], - CurrentLookup[greenGain], - CurrentLookup[blueGain], - CurrentLookup[whiteGain]) - { - } - - void Encode(uint8_t* encoded) const - { - // RGBW 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4); - } - -protected: - static constexpr uint8_t CurrentLookup[16] = { - 18, 30, 41, 53, 64, 76, 87, 99, - 110, 133, 145, 156, 168, 179, 190 }; -}; - -template -class NeoSm16824eSettings : public NeoSm168x4SettingsBase -{ -public: - NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms) : - NeoSm168x4SettingsBase(redGain, - greenGain, - blueGain, - whiteGain, - calcCurrent(resisterOhms, redGain), - calcCurrent(resisterOhms, greenGain), - calcCurrent(resisterOhms, blueGain), - calcCurrent(resisterOhms, whiteGain)), - extROhms(resisterOhms) - { - } - - void Encode(uint8_t* encoded) const - { - // RGBW 4 bits each - *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2); - *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4); - } - -protected: - const uint16_t extROhms; - - static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain) - { - uint16_t mA = (1100 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead - return mA * 10; // return tenths of mA - } - -}; - -// CAUTION: Make sure ColorIndex order for Neo4ByteFeature matches T_SETTINGS -template -class NeoRgbwSm168x4Elements : - public Neo4ByteFeature -{ -public: - typedef T_SETTINGS SettingsObject; - static const size_t SettingsSize = 2; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - // settings are at the end of the data stream - uint8_t* pDest = pData + sizeData - SettingsSize; - - settings.Encode(pDest); - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; - -// CAUTION: Make sure ColorIndex order for Neo3ByteFeature matches T_SETTINGS -template class NeoRgbSm168x3Elements : - public Neo3ByteFeature -{ -public: - typedef T_SETTINGS SettingsObject; - static const size_t SettingsSize = 2; - - static void applySettings(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData, MAYBE_UNUSED const SettingsObject& settings) - { - // settings are at the end of the data stream - uint8_t* pDest = pData + sizeData - SettingsSize; - - settings.Encode(pDest); - } - - static uint8_t* pixels(MAYBE_UNUSED uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } - - static const uint8_t* pixels(MAYBE_UNUSED const uint8_t* pData, MAYBE_UNUSED size_t sizeData) - { - return pData; - } -}; - -// FIXME 2023-08-08 tonhuisman: Space added between >> to avoid compiler warning -typedef NeoRgbSm168x3Elements > NeoRgbSm16803pbFeature; -typedef NeoRgbSm168x3Elements > NeoRgbSm16823eFeature; -typedef NeoRgbwSm168x4Elements > NeoRgbwSm16804ebFeature; -typedef NeoRgbwSm168x4Elements > NeoRgbwSm16824eFeature; - - diff --git a/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h b/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h deleted file mode 100644 index c81fda676a..0000000000 --- a/lib/NeoPixelBus/src/internal/features/P9813BgrFeature.h +++ /dev/null @@ -1,77 +0,0 @@ -/*------------------------------------------------------------------------- -P9813BgrFeature provides feature classes to describe color order and -color depth for NeoPixelBus template class when used with P9813s - -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 - - -class P9813BgrFeature : - public NeoByteElements<4, RgbColor, uint32_t>, - public NeoElementsNoSettings -{ -public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) - { - uint8_t* p = getPixelAddress(pPixels, indexPixel); - - *p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6); - *p++ = color.B; - *p++ = color.G; - *p = color.R; - } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first byte - color.B = *p++; - color.G = *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.B = pgm_read_byte(p++); - color.G = pgm_read_byte(p++); - color.R = pgm_read_byte(p); - - return color; - } - -}; - - - - - - diff --git a/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h b/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h deleted file mode 100644 index 9da2cdf60b..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/DotStarEsp32DmaSpiMethod.h +++ /dev/null @@ -1,334 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for DotStars using Esp32, DMA and SPI (APA102). - -Written by Michael C. Miller. -DotStarEsp32DmaSpiMethod written by Louis Beaudoin (Pixelvation) - -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 - -#include "../NeoUtil.h" - -#include "driver/spi_master.h" - -// API and type use require newer IDF versions -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 1) - -template class DotStarEsp32DmaSpiMethodBase -{ -public: - typedef typename T_SPISPEED::SettingsObject SettingsObject; - - DotStarEsp32DmaSpiMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeStartFrame(4 * T_SPIBUS::ParallelBits), - _sizePixelData(pixelCount * elementSize + settingsSize), - _sizeEndFrame((pixelCount + 15) / 16 * T_SPIBUS::ParallelBits) // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes) - { - _spiBufferSize = _sizeStartFrame + _sizePixelData + _sizeEndFrame; - - // must have a 4 byte aligned buffer for i2s - uint32_t alignment = _spiBufferSize % 4; - if (alignment) - { - _spiBufferSize += 4 - alignment; - } - - _data = static_cast(malloc(_spiBufferSize)); - _dmadata = static_cast(heap_caps_malloc(_spiBufferSize, MALLOC_CAP_DMA)); - - // data cleared later in NeoPixelBus::Begin() - } - - // Support constructor specifying pins by ignoring pins - DotStarEsp32DmaSpiMethodBase(uint8_t, uint8_t, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - DotStarEsp32DmaSpiMethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~DotStarEsp32DmaSpiMethodBase() - { - if (_spiHandle) - { - deinitSpiDevice(); - esp_err_t ret = spi_bus_free(T_SPIBUS::SpiHostDevice); - ESP_ERROR_CHECK(ret); - } - free(_data); - heap_caps_free(_dmadata); - _spiHandle = NULL; - } - - bool IsReadyToUpdate() const - { - spi_transaction_t t; - spi_transaction_t* tptr = &t; - - esp_err_t ret = spi_device_get_trans_result(_spiHandle, &tptr, 0); - - // we are ready if prev result is back (ESP_OK) or if we got a timeout and - // transaction length of 0 (we didn't start a transaction) - return (ret == ESP_OK || (ret == ESP_ERR_TIMEOUT && 0 == _spiTransaction.length)); - } - - void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t dat4, int8_t dat5, int8_t dat6, int8_t dat7, int8_t ss) - { - memset(_data, 0x00, _sizeStartFrame); - memset(_data + _sizeStartFrame + _sizePixelData, 0x00, _spiBufferSize - (_sizeStartFrame + _sizePixelData)); - - _ssPin = ss; - - esp_err_t ret; - spi_bus_config_t buscfg = { 0 }; - - buscfg.sclk_io_num = sck; - buscfg.data0_io_num = dat0; - buscfg.data1_io_num = dat1; - buscfg.data2_io_num = dat2; - buscfg.data3_io_num = dat3; - buscfg.data4_io_num = dat4; - buscfg.data5_io_num = dat5; - buscfg.data6_io_num = dat6; - buscfg.data7_io_num = dat7; - buscfg.max_transfer_sz = _spiBufferSize; - if (T_SPIBUS::ParallelBits == 8) - { - buscfg.flags = SPICOMMON_BUSFLAG_OCTAL; - } - - //Initialize the SPI bus - ret = spi_bus_initialize(T_SPIBUS::SpiHostDevice, &buscfg, SPI_DMA_CH_AUTO); - ESP_ERROR_CHECK(ret); - - _spiTransaction = { 0 }; - initSpiDevice(); - } - - void Initialize(int8_t sck, int8_t dat0, int8_t dat1, int8_t dat2, int8_t dat3, int8_t ss) - { - Initialize(sck, dat0, dat1, dat2, dat3, -1, -1, -1, -1, ss); - } - - void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) - { - Initialize(sck, mosi, miso, -1, -1, ss); - } - - // If pins aren't specified, initialize bus with just the default SCK and MOSI pins for the SPI peripheral (no SS, no >1-bit pins) - void Initialize() - { -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - if (T_SPIBUS::SpiHostDevice == VSPI_HOST) - { - Initialize(SCK, -1, MOSI, -1, -1, -1); - } - else - { - Initialize(14, -1, 13, -1, -1, -1); - } -#else - Initialize(SCK, -1, MOSI, -1, -1, -1); -#endif - } - - void Update(bool) - { - while(!IsReadyToUpdate()) - { - portYIELD(); - } - - memcpy(_dmadata, _data, _spiBufferSize); - - _spiTransaction = { 0 }; - _spiTransaction.length = (_spiBufferSize) * 8; // in bits not bytes! - - if (T_SPIBUS::ParallelBits == 1) - { - _spiTransaction.flags = 0; - } - if (T_SPIBUS::ParallelBits == 2) - { - _spiTransaction.flags = SPI_TRANS_MODE_DIO; - } - if (T_SPIBUS::ParallelBits == 4) - { - _spiTransaction.flags = SPI_TRANS_MODE_QIO; - } - if (T_SPIBUS::ParallelBits == 8) - { - _spiTransaction.flags = SPI_TRANS_MODE_OCT; - } - _spiTransaction.tx_buffer = _dmadata; - - esp_err_t ret = spi_device_queue_trans(_spiHandle, &_spiTransaction, 0); //Transmit! - ESP_ERROR_CHECK(ret); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data + _sizeStartFrame; - }; - - size_t getDataSize() const - { - return _sizePixelData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _speed.applySettings(settings); - if (_spiHandle) - { - deinitSpiDevice(); - initSpiDevice(); - } - } - -private: - void initSpiDevice() - { - spi_device_interface_config_t devcfg = {0}; - - devcfg.clock_speed_hz = _speed.Clock; - devcfg.mode = 0; //SPI mode 0 - devcfg.spics_io_num = _ssPin; //CS pin - devcfg.queue_size = 1; - if (T_SPIBUS::ParallelBits == 1) - { - devcfg.flags = 0; - } - if (T_SPIBUS::ParallelBits >= 2) - { - devcfg.flags = SPI_DEVICE_HALFDUPLEX; - } - - //Allocate the LEDs on the SPI bus - esp_err_t ret = spi_bus_add_device(T_SPIBUS::SpiHostDevice, &devcfg, &_spiHandle); - ESP_ERROR_CHECK(ret); - } - - void deinitSpiDevice() - { - while(!IsReadyToUpdate()); - esp_err_t ret = spi_bus_remove_device(_spiHandle); - ESP_ERROR_CHECK(ret); - } - - const size_t _sizeStartFrame; - const size_t _sizePixelData; // Size of '_data' buffer below, minus (_sizeStartFrame + _sizeEndFrame) - const size_t _sizeEndFrame; - - size_t _spiBufferSize; - uint8_t* _data; // Holds start/end frames and LED color values - uint8_t* _dmadata; // Holds start/end frames and LED color values - spi_device_handle_t _spiHandle = NULL; - spi_transaction_t _spiTransaction; - T_SPISPEED _speed; - int8_t _ssPin; -}; - - -// Unfortunately we have a bit of a mess with SPI bus names across different version of the ESP32 -// e.g ESP32 has SPI, HSPI, and VSPI (1, 2, and 3), ESP32-S2 has SPI, FSPI, and HSPI (1, 2, and 3) -// and the S3 and C3 dropped the silly names entirely and just uses SPI1, SPI2, and SPI3. -// -// SPI1 can be only be used by ESP32 and supports up to 4 bit -// SPI2 supports up to 4 bit output across all of those devices (!) and supports 8 bit on S2 and S3 -// SPI3 supports up to 4 bit output on ESP32 and S3, and 1 bit only on the S2 - -enum spi_bus_width_t { - WIDTH1 = 1, - WIDTH2 = 2, - WIDTH4 = 4, - WIDTH8 = 8, -}; - -template -struct Esp32SpiBus -{ - const static spi_host_device_t SpiHostDevice = bus; - const static int ParallelBits = bits; -}; - -// Define all valid ESP32 SPI Buses with a default speed - -// SPI1 -- ESP32 Only -#if defined(CONFIG_IDF_TARGET_ESP32) -typedef Esp32SpiBus Esp32Spi1Bus; -typedef Esp32SpiBus Esp32Spi12BitBus; -typedef Esp32SpiBus Esp32Spi14BitBus; - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi1Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi12BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi14BitMethod; -#endif - -// SPI2 -typedef Esp32SpiBus Esp32Spi2Bus; -typedef Esp32SpiBus Esp32Spi22BitBus; -typedef Esp32SpiBus Esp32Spi24BitBus; -#if SOC_SPI_SUPPORT_OCT -typedef Esp32SpiBus Esp32Spi28BitBus; -#endif - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi2Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi22BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi24BitMethod; -#if SOC_SPI_SUPPORT_OCT -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi28BitMethod; -#endif - - -// SPI3 -#if (defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S3)) -typedef Esp32SpiBus Esp32Spi3Bus; -typedef Esp32SpiBus Esp32Spi32BitBus; -typedef Esp32SpiBus Esp32Spi34BitBus; - -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi3Method; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi32BitMethod; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi34BitMethod; -#endif - -#if defined(CONFIG_IDF_TARGET_ESP32S2) -typedef Esp32SpiBus Esp32Spi3Bus; -typedef DotStarEsp32DmaSpiMethodBase DotStarEsp32DmaSpi3Method; -#endif - -// Default SpiDma methods if we don't care about bus. It's nice that every single ESP32 out there -// supports up to 4 bits on SPI2 - -typedef DotStarEsp32DmaSpi2Method DotStarEsp32DmaSpiMethod; -typedef DotStarEsp32DmaSpi22BitMethod DotStarEsp32DmaSpi2BitMethod; -typedef DotStarEsp32DmaSpi24BitMethod DotStarEsp32DmaSpi4BitMethod; -#if SOC_SPI_SUPPORT_OCT -typedef DotStarEsp32DmaSpi28BitMethod DotStarEsp32DmaSpi8BitMethod; -#endif - -#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 1) \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c b/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c deleted file mode 100644 index 5893d19d48..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.c +++ /dev/null @@ -1,671 +0,0 @@ -// 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 "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 - -// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - - - -#include -#include -#include "stdlib.h" - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "freertos/queue.h" - - -#if ESP_IDF_VERSION_MAJOR>=4 -#include "esp_intr_alloc.h" -#else -#include "esp_intr.h" -#endif - -#include "rom/lldesc.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" -#if defined(CONFIG_IDF_TARGET_ESP32) -/* included here for ESP-IDF v4.x compatibility */ -#include "soc/dport_reg.h" -#endif -#include "soc/sens_reg.h" -#include "driver/gpio.h" -#include "driver/i2s.h" - -#if !defined(CONFIG_IDF_TARGET_ESP32S3) -#include "driver/dac.h" -#endif - -#include "Esp32_i2s.h" -#include "esp32-hal.h" - -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, bool parallel_mode, size_t bytes_per_sample); - -#define MATRIX_DETACH_OUT_SIG 0x100 - -#if ESP_IDF_VERSION_MAJOR<=4 -#define I2S_BASE_CLK (160000000L) -#endif - -#define I2S_DMA_BLOCK_COUNT_DEFAULT 0 -// 20 bytes gives us enough time if we use single stage idle -// But it can't be longer due to non-parrallel mode and 50us reset time -// there just isn't enough silence at the end to fill more than 20 bytes -#define I2S_DMA_SILENCE_SIZE 20 // 4 byte increments -#define I2S_DMA_SILENCE_BLOCK_COUNT_FRONT 2 // two front -#define I2S_DMA_SILENCE_BLOCK_COUNT_BACK 1 // one back, required for non parallel - -typedef struct -{ - i2s_dev_t* bus; - int8_t ws; - int8_t bck; - int8_t out; - int8_t in; - - intr_handle_t isr_handle; - lldesc_t* dma_items; - size_t dma_count; - - volatile uint32_t is_sending_data; -} i2s_bus_t; - -// is_sending_data values -#define I2s_Is_Idle 0 -#define I2s_Is_Pending 1 -#define I2s_Is_Sending 2 - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) -static i2s_bus_t I2S[I2S_NUM_MAX] = -{ - {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle}, - {&I2S1, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} -}; -#else -static i2s_bus_t I2S[I2S_NUM_MAX] = -{ - {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} -}; -#endif - -void IRAM_ATTR i2sDmaISR(void* arg); - -inline void dmaItemInit(lldesc_t* item, uint8_t* posData, size_t sizeData, lldesc_t* itemNext) -{ - item->eof = 0; - item->owner = 1; - item->sosf = 0; - item->offset = 0; - item->buf = posData; - item->size = sizeData; - item->length = sizeData; - item->qe.stqe_next = itemNext; -} - -bool i2sInitDmaItems(uint8_t bus_num, uint8_t* data, size_t dataSize) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - size_t dmaCount = I2S[bus_num].dma_count; - - if (I2S[bus_num].dma_items == NULL) - { - I2S[bus_num].dma_items = (lldesc_t*)heap_caps_malloc(dmaCount * sizeof(lldesc_t), MALLOC_CAP_DMA); - if (I2S[bus_num].dma_items == NULL) - { - log_e("MEM ERROR!"); - return false; - } - } - - lldesc_t* itemFirst = &I2S[bus_num].dma_items[0]; - lldesc_t* item = itemFirst; -// lldesc_t* itemsEnd = itemFirst + I2S[bus_num].dma_count; - lldesc_t* itemNext = item + 1; - size_t dataLeft = dataSize; - uint8_t* pos = data; - // at the end of the data is the encoded silence reset - uint8_t* posSilence = data + dataSize - I2S_DMA_SILENCE_SIZE; - - // front two are silent items used for looping to micmic single fire - // default to looping - dmaItemInit(item, posSilence, I2S_DMA_SILENCE_SIZE, itemNext); - dmaItemInit(itemNext, posSilence, I2S_DMA_SILENCE_SIZE, item); - item = itemNext; - itemNext++; - - // init blocks with avialable data - // - while (dataLeft) - { - item = itemNext; - itemNext++; - - size_t blockSize = dataLeft; - if (blockSize > I2S_DMA_MAX_DATA_LEN) - { - blockSize = I2S_DMA_MAX_DATA_LEN; - } - dataLeft -= blockSize; - - dmaItemInit(item, pos, blockSize, itemNext); - - pos += blockSize; - } - - // last data item is EOF to manage send state using EOF ISR - item->eof = 1; - - // last block, the back silent item, loops to front - item = itemNext; - dmaItemInit(item, posSilence, I2S_DMA_SILENCE_SIZE, itemFirst); - - return true; -} - -bool i2sDeinitDmaItems(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - heap_caps_free(I2S[bus_num].dma_items); - I2S[bus_num].dma_items = NULL; - - return true; -} - -// normal 4, 10, 63, 12, 16 - -esp_err_t i2sSetClock(uint8_t bus_num, - uint8_t div_num, // 4 13 - uint8_t div_b, // 10 20 - uint8_t div_a, // 63 63 - uint8_t bck, // 12 60 or 7 - uint8_t bits) // 16 8 -{ - if (bus_num >= I2S_NUM_MAX || div_a > 63 || div_b > 63 || bck > 63) - { - return ESP_FAIL; - } - - //log_i("i2sSetClock bus %u, clkm_div_num %u, clk_div_a %u, clk_div_b %u, bck_div_num %u, bits_mod %u", - // bus_num, - // div_num, - // div_a, - // div_b, - // bck, - // bits); - - i2s_dev_t* i2s = I2S[bus_num].bus; - - typeof(i2s->clkm_conf) clkm_conf; - - clkm_conf.val = 0; - -#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3) - clkm_conf.clk_sel = 2; // APPL = 1 APB = 2 - clkm_conf.clk_en = 1; // examples of i2s show this being set if sel is set to 2 -#else - clkm_conf.clka_en = 0; -#endif - - clkm_conf.clkm_div_a = div_a; - clkm_conf.clkm_div_b = div_b; - clkm_conf.clkm_div_num = div_num; - i2s->clkm_conf.val = clkm_conf.val; - - typeof(i2s->sample_rate_conf) sample_rate_conf; - sample_rate_conf.val = 0; - sample_rate_conf.tx_bck_div_num = bck; - sample_rate_conf.rx_bck_div_num = bck; - sample_rate_conf.tx_bits_mod = bits; - sample_rate_conf.rx_bits_mod = bits; - i2s->sample_rate_conf.val = sample_rate_conf.val; - - return ESP_OK; -} - -void i2sSetPins(uint8_t bus_num, - int8_t out, - int8_t parallel, - int8_t busSampleSize, - bool invert) -{ - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - if (out >= 0) - { - uint32_t i2sSignal; - - pinMode(out, OUTPUT); - -#if defined(CONFIG_IDF_TARGET_ESP32S2) - - // S2 only has one bus - // - // in parallel mode - // 8bit mode : I2S0O_DATA_OUT16_IDX ~I2S0O_DATA_OUT23_IDX - // 16bit mode : I2S0O_DATA_OUT8_IDX ~I2S0O_DATA_OUT23_IDX - // 24bit mode : I2S0O_DATA_OUT0_IDX ~I2S0O_DATA_OUT23_IDX - if (parallel == -1) - { - i2sSignal = I2S0O_DATA_OUT23_IDX; - } - else if (busSampleSize == 1) - { - i2sSignal = I2S0O_DATA_OUT16_IDX + parallel; - } - else if (busSampleSize == 2) - { - i2sSignal = I2S0O_DATA_OUT8_IDX + parallel; - } - else - { - i2sSignal = I2S0O_DATA_OUT0_IDX + parallel; - } - -#else - if (bus_num == 0) - { - // in parallel mode - // 0-7 bits : I2S0O_DATA_OUT16_IDX ~I2S0O_DATA_OUT23_IDX - // 8-15 bits : I2S0O_DATA_OUT8_IDX ~I2S0O_DATA_OUT23_IDX - // 16-23 bits : I2S0O_DATA_OUT0_IDX ~I2S0O_DATA_OUT23_IDX - if (parallel == -1) - { - i2sSignal = I2S0O_DATA_OUT23_IDX; - } - else if (parallel < 8) - { - i2sSignal = I2S0O_DATA_OUT16_IDX + parallel; - } - else if (parallel < 16) - { - i2sSignal = I2S0O_DATA_OUT8_IDX + parallel - 8; - } - else - { - i2sSignal = I2S0O_DATA_OUT0_IDX + parallel - 16; - } - } - else - { - if (parallel == -1) - { - i2sSignal = I2S1O_DATA_OUT23_IDX; - } - else - { - i2sSignal = I2S1O_DATA_OUT0_IDX + parallel; - } - } -#endif - //log_i("i2sSetPins bus %u, i2sSignal %u, pin %u, mux %u", - // bus_num, - // i2sSignal, - // out, - // parallel); - gpio_matrix_out(out, i2sSignal, invert, false); - } -} - -void i2sSetClkWsPins(uint8_t bus_num, - int8_t outClk, - bool invertClk, - int8_t outWs, - bool invertWs) -{ - - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - uint32_t i2sSignalClk = I2S0O_BCK_OUT_IDX; - uint32_t i2sSignalWs = I2S0O_WS_OUT_IDX; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - if (bus_num == 1) - { - i2sSignalClk = I2S1O_BCK_OUT_IDX; - i2sSignalWs = I2S1O_WS_OUT_IDX; - } -#endif - - if (outClk >= 0) - { - pinMode(outClk, OUTPUT); - gpio_matrix_out(outClk, i2sSignalClk, invertClk, false); - } - - if (outWs >= 0) - { - pinMode(outWs, OUTPUT); - gpio_matrix_out(outWs, i2sSignalWs, invertWs, false); - } -} - -bool i2sWriteDone(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - return (I2S[bus_num].is_sending_data == I2s_Is_Idle); -} - -void i2sInit(uint8_t bus_num, - bool parallel_mode, - size_t bytes_per_sample, - uint32_t sample_rate, - i2s_tx_chan_mod_t chan_mod, - i2s_tx_fifo_mod_t fifo_mod, - size_t dma_count, - uint8_t* data, - size_t dataSize) -{ - if (bus_num >= I2S_NUM_MAX) - { - return; - } - - I2S[bus_num].dma_count = dma_count + - I2S_DMA_SILENCE_BLOCK_COUNT_FRONT + - I2S_DMA_SILENCE_BLOCK_COUNT_BACK; - - if (!i2sInitDmaItems(bus_num, data, dataSize)) - { - return; - } - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) - if (bus_num) - { - periph_module_enable(PERIPH_I2S1_MODULE); - } - else -#endif - { - 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 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; - - // 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; - - - // set parallel (LCD) mode - { - typeof(i2s->conf2) conf2; - conf2.val = 0; - conf2.lcd_en = parallel_mode; - conf2.lcd_tx_wrx2_en = 0; // parallel_mode; // ((parallel_mode) && (bytes_per_sample == 2)); - i2s->conf2.val = conf2.val; - } - - // Enable and configure DMA - { - typeof(i2s->lc_conf) lc_conf; - lc_conf.val = 0; - lc_conf.out_eof_mode = 1; - i2s->lc_conf.val = lc_conf.val; - } - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - i2s->pdm_conf.pcm2pdm_conv_en = 0; - i2s->pdm_conf.pdm2pcm_conv_en = 0; -#endif - // SET_PERI_REG_BITS(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S); - - { - typeof(i2s->fifo_conf) fifo_conf; - - fifo_conf.val = 0; - fifo_conf.rx_fifo_mod_force_en = 1; - fifo_conf.tx_fifo_mod_force_en = 1; - fifo_conf.tx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel - fifo_conf.rx_fifo_mod = fifo_mod; // 0-right&left channel;1-one channel - fifo_conf.rx_data_num = 32; //Thresholds. - fifo_conf.tx_data_num = 32; - - i2s->fifo_conf.val = fifo_conf.val; - } - - // $REVIEW old code didn't set this - { - typeof(i2s->conf1) conf1; - conf1.val = 0; - conf1.tx_stop_en = 0; - conf1.tx_pcm_bypass = 1; - i2s->conf1.val = conf1.val; - } - - { - typeof(i2s->conf_chan) conf_chan; - conf_chan.val = 0; - conf_chan.tx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left - conf_chan.rx_chan_mod = chan_mod; // 0-two channel;1-right;2-left;3-righ;4-left - i2s->conf_chan.val = conf_chan.val; - } - - { - typeof(i2s->conf) conf; - conf.val = 0; - conf.tx_msb_shift = !parallel_mode; // 0:DAC/PCM, 1:I2S - conf.tx_right_first = 0; // parallel_mode?; - i2s->conf.val = conf.val; - } - - i2s->timing.val = 0; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - i2s->pdm_conf.rx_pdm_en = 0; - i2s->pdm_conf.tx_pdm_en = 0; -#endif - - - i2sSetSampleRate(bus_num, sample_rate, parallel_mode, bytes_per_sample); - - /* */ - //Reset FIFO/DMA -> needed? Doesn't dma_reset/fifo_reset do this? - i2s->lc_conf.in_rst=1; i2s->lc_conf.out_rst=1; i2s->lc_conf.ahbm_rst=1; i2s->lc_conf.ahbm_fifo_rst=1; - i2s->lc_conf.in_rst=0; i2s->lc_conf.out_rst=0; i2s->lc_conf.ahbm_rst=0; i2s->lc_conf.ahbm_fifo_rst=0; - i2s->conf.tx_reset=1; i2s->conf.tx_fifo_reset=1; i2s->conf.rx_fifo_reset=1; - i2s->conf.tx_reset=0; i2s->conf.tx_fifo_reset=0; i2s->conf.rx_fifo_reset=0; - /* */ - - // enable intr in cpu // - int i2sIntSource; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) - if (bus_num == 1) { - i2sIntSource = ETS_I2S1_INTR_SOURCE; - } - else -#endif - { - i2sIntSource = ETS_I2S0_INTR_SOURCE; - } - - esp_intr_alloc(i2sIntSource, 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; - -/* ??? */ - // Enable and configure DMA - { - typeof(i2s->lc_conf) lc_conf; - lc_conf.val = 0; - lc_conf.out_data_burst_en = 1; - lc_conf.indscr_burst_en = 1; - i2s->lc_conf.val = lc_conf.val; - } -/* */ - 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); -} - -void i2sDeinit(uint8_t bus_num) -{ - i2sDeinitDmaItems(bus_num); -} - -esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t rate, bool parallel_mode, size_t bytes_per_sample) -{ - if (bus_num >= I2S_NUM_MAX) - { - return ESP_FAIL; - } - - uint8_t bck = 12; - - // parallel mode needs a higher sample rate - // - if (parallel_mode) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - rate *= bytes_per_sample; - bck *= bytes_per_sample; - - //rate /= bytes_per_sample; - //bck /= bytes_per_sample; -#else - rate *= bytes_per_sample; -#endif - } - - // 160,000,000L / (100,000 * 384) - double clkmdiv = (double)I2S_BASE_CLK / ((rate * 384) + 1); - if (clkmdiv > 256.0) - { - log_e("rate is too low"); - return ESP_FAIL; - } - else if (clkmdiv < 2.0) - { - log_e("rate is too fast, clkmdiv = %f (%u, %u, %u)", - clkmdiv, - rate, - parallel_mode, - bytes_per_sample); - return ESP_FAIL; - } - - // calc integer and franctional for more precise timing - // - uint8_t clkmInteger = clkmdiv; - uint8_t clkmFraction = (clkmdiv - clkmInteger) * 63.0; - - i2sSetClock(bus_num, clkmInteger, clkmFraction, 63, bck, bytes_per_sample * 8); - - return ESP_OK; -} - -void IRAM_ATTR i2sDmaISR(void* arg) -{ - i2s_bus_t* i2s = (i2s_bus_t*)(arg); - - if (i2s->bus->int_st.out_eof) - { - // lldesc_t* item = (lldesc_t*)(i2s->bus->out_eof_des_addr); - if (i2s->is_sending_data != I2s_Is_Idle) - { - // the second item (last of the two front silent items) is - // silent looping item - lldesc_t* itemLoop = &i2s->dma_items[0]; - lldesc_t* itemLoopBreaker = itemLoop + 1; - // set to loop on silent items - itemLoopBreaker->qe.stqe_next = itemLoop; - - i2s->is_sending_data = I2s_Is_Idle; - } - } - - i2s->bus->int_clr.val = i2s->bus->int_st.val; -} - -bool i2sWrite(uint8_t bus_num) -{ - if (bus_num >= I2S_NUM_MAX) - { - return false; - } - - // the second item (last of the two front silent items) is - // silent looping item - lldesc_t* itemLoopBreaker = &I2S[bus_num].dma_items[1]; - lldesc_t* itemLoopNext = itemLoopBreaker + 1; - - // set to NOT loop on silent items - itemLoopBreaker->qe.stqe_next = itemLoopNext; - - I2S[bus_num].is_sending_data = I2s_Is_Sending; - - return true; -} - -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -#endif // defined(ARDUINO_ARCH_ESP32) - diff --git a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h b/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h deleted file mode 100644 index 9f961d3489..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Esp32_i2s.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -// ESP32C3/S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - -#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, - bool parallel_mode, - size_t bytes_per_sample, - uint32_t sample_rate, - i2s_tx_chan_mod_t chan_mod, - i2s_tx_fifo_mod_t fifo_mod, - size_t dma_count, - uint8_t* data, - size_t dataSize); -void i2sDeinit(uint8_t bus_num); -void i2sSetPins(uint8_t bus_num, - int8_t out, - int8_t parallel, - int8_t busSampleSize, - bool invert); -void i2sSetClkWsPins(uint8_t bus_num, - int8_t outClk, - bool invertClk, - int8_t outWs, - bool invertWs); -bool i2sWrite(uint8_t bus_num); -bool i2sWriteDone(uint8_t bus_num); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h deleted file mode 100644 index 21688e13ff..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Mbi6033GenericMethod.h +++ /dev/null @@ -1,208 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Mbi6033s using general Pins. - -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 - -#include "../NeoUtil.h" -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - - -template class Mbi6033MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - Mbi6033MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _countChips(NeoUtil::RoundUp(pixelCount * elementSize, c_countBytesPerChip) / c_countBytesPerChip), - _sizeData(_countChips * c_countBytesPerChip + settingsSize), - _pinClock(pinClock), - _wire(pinClock, pinData) - { - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Mbi6033MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Mbi6033MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Mbi6033MethodBase() - { - free(_data); - } - - bool IsReadyToUpdate() const - { - return true; // clock driven chips 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) - { - _pinClock = sck; - _wire.begin(sck, miso, mosi, ss); - } -#endif - - void Initialize() - { - _wire.begin(); - } - - void Update(bool) - { - // non current header format: - // 8 bits: command (0xf3) = non current header mode - // 14 bits: sync (0x0000) - // 14 bits: length (count chips - 1) - // 8 bits: configuration (0x02) - // bits (6-4) refresh rate divider bits (0 for fastest) - // bit (1) on or off - // 4 bits: header code name X1 (0x0) - const uint16_t chipLength = _countChips - 1; - const uint8_t headerFrame[6] = { 0xf3, - 0x00, - static_cast(chipLength >> 12), - static_cast((chipLength >> 4) & 0xff), - static_cast((chipLength << 4) & 0xff), - 0x20 }; - - // prefix protocol, >21us clock low, clock high, >21us clock low - // expecting at least 21us since last call to show - // but using hardware SPI won't allow messing with clock - // directly like this... - //delayMicroseconds(c_usResetTime); - //digitalWrite(_pinClock, HIGH); - //digitalWrite(_pinClock, LOW); - //delayMicroseconds(c_usResetTime); - - _wire.beginTransaction(); - - // reset by toggle of clock - delayMicroseconds(c_usResetTime); - _wire.transmitBit(0); // Our Two Wire BitBang supports this - delayMicroseconds(c_usResetTime); - - // header frame - _wire.transmitBytes(headerFrame, sizeof(headerFrame)); - - // data: - // 24 bytes per chip of data (12 16 bit values) - _wire.transmitBytes(_data, _sizeData); - - _wire.endTransaction(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - // while spec states 4 RGB * 16 bit values, - // its really 12 channels * 16 bit values, as they could - // be wired how ever the circuit is built, like 3 RGBW - static const uint16_t c_countBytesPerChip = 24; // twelve 16 bit values - static const uint16_t c_usResetTime = 21; - - const uint16_t _countChips; // not pixels, driver chips - const size_t _sizeData; // Size of '_data' buffer below - - uint8_t _pinClock; - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values -}; - -typedef Mbi6033MethodBase Mbi6033Method; - -/* Due to reset model by these chips needing to control clock, we can't use hardware SPI -* as neither the normal SPI exposes a single bit send nor does it allow direct clock pulses -* using digitalWrite. If a generalized solution could be found, then this could be enabled -* -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) -#include "TwoWireSpiImple.h" -typedef Mbi6033MethodBase> Mbi6033Spi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Spi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033SpiHzMethod; - -typedef Mbi6033Spi10MhzMethod Mbi6033SpiMethod; -#endif - -#if defined(ARDUINO_ARCH_ESP32) -// Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32 -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Vspi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32VspiHzMethod; - -typedef Mbi6033Spi10MhzMethod Mbi6033Esp32VspiMethod; - -#include "TwoWireHspiImple.h" -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi40MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi20MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi10MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi5MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi2MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi1MhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32Hspi500KhzMethod; -typedef Mbi6033MethodBase> Mbi6033Esp32HspiHzMethod; - -typedef Mbi6033Esp32Hspi10MhzMethod Mbi6033Esp32HspiMethod; -#endif -*/ \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h deleted file mode 100644 index 335be8fd71..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp32I2sXMethod.h +++ /dev/null @@ -1,763 +0,0 @@ -#pragma once - -/*------------------------------------------------------------------------- -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 -. --------------------------------------------------------------------------*/ - -#include "../NeoUtil.h" - -// ESP32C3/S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - -extern "C" -{ -#include "Esp32_i2s.h" -} - -#pragma once - -// ESP32 Endian Map -// uint16_t -// 1234 -// 3412 -// uint32_t -// 12345678 -// 78563412 -// uint64_t -// 0123456789abcdef -// efcdab8967452301 - -// -// true size of mux channel, 8 bit -// -class NeoEspI2sMuxBusSize8Bit -{ -public: - NeoEspI2sMuxBusSize8Bit() {}; - - const static size_t MuxBusDataSize = 1; - - static void EncodeIntoDma(uint8_t* dmaBuffer, const uint8_t* data, size_t sizeData, uint8_t muxId) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - // 1234 - order - // 3412 = actual due to endianness - // 00000001 - const uint32_t EncodedZeroBit = 0x00000100; - // 00010101 - const uint32_t EncodedOneBit = 0x01000101; -#else - // 8 channel bits layout for DMA 32bit value - // note, right to left - // mux bus bit/id 76543210 76543210 76543210 76543210 - // encode bit # 3 2 1 0 - // value zero 0 0 0 1 - // value one 0 1 1 1 - // - // due to indianness between peripheral and cpu, bytes within the words are swapped in the const - // 1234 - order - // 3412 = actual due to endianness - // 00000001 - const uint32_t EncodedZeroBit = 0x00010000; - // 00010101 - const uint32_t EncodedOneBit = 0x01010001; -#endif - - uint32_t* pDma = reinterpret_cast(dmaBuffer); - const uint8_t* pEnd = data + sizeData; - - for (const uint8_t* pPixel = data; pPixel < pEnd; pPixel++) - { - uint8_t value = *pPixel; - - for (uint8_t bit = 0; bit < 8; bit++) - { - uint32_t dma = *(pDma); - - dma |= (((value & 0x80) ? EncodedOneBit : EncodedZeroBit) << (muxId)); - *(pDma++) = dma; - value <<= 1; - } - } - } -}; - -// -// true size of mux channel, 16 bit -// -class NeoEspI2sMuxBusSize16Bit -{ -public: - NeoEspI2sMuxBusSize16Bit() {}; - - const static size_t MuxBusDataSize = 2; - - static void EncodeIntoDma(uint8_t* dmaBuffer, const uint8_t* data, size_t sizeData, uint8_t muxId) - { -#if defined(CONFIG_IDF_TARGET_ESP32S2) - // 1234 5678 - order - // 3412 7856 = actual due to endianness - // not swap 0000000000000001 - const uint64_t EncodedZeroBit64 = 0x0000000000010000; - // no swap 0000000100010001 - const uint64_t EncodedOneBit64 = 0x0001000000010001; - // can be shifted by 8! - Fillx16(dmaBuffer, - data, - sizeData, - muxId, - EncodedZeroBit64, - EncodedOneBit64); -#else - - // 16 channel bits layout for DMA 64bit value - // note, right to left, destination is 32bit chunks - // due to indianness between peripheral and cpu, - // bytes within the words are swapped and words within dwords - // in the literal constants - // { } { } - // 0123 4567 89ab cdef - order of bytes in literal constant - // efcd ab89 6745 2301 - order of memory on ESP32 due to Endianness - // 6745 2301 efcd ab89 - 32bit dest means only map using 32bits so swap upper and lower - // - // Due to final bit locations, can't shift encoded one bit - // either left more than 7 or right more than 7 so we have to - // split the updates and use different encodings - if (muxId < 8) - { - // endian + dest swap 0000000000000001 - const uint64_t EncodedZeroBit64 = 0x0000000001000000; - // endian + dest swap 0000000100010001 - const uint64_t EncodedOneBit64 = 0x0100000001000100; - // cant be shifted by 8! - Fillx16(dmaBuffer, - data, - sizeData, - muxId, - EncodedZeroBit64, - EncodedOneBit64); - } - else - { - // endian + dest swap 0000000000000001 - // then pre shift by 8 0000000000000100 - const uint64_t EncodedZeroBit64 = 0x0000000000010000; - // endian + dest swap 0000000100010001 - // then pre shift by 8 0000010001000100 - const uint64_t EncodedOneBit64 = 0x0001000000010001; - Fillx16(dmaBuffer, - data, - sizeData, - muxId - 8, // preshifted - EncodedZeroBit64, - EncodedOneBit64); - } -#endif - } - -protected: - static void Fillx16(uint8_t* dmaBuffer, - const uint8_t* data, - size_t sizeData, - uint8_t muxShift, - const uint64_t EncodedZeroBit64, - const uint64_t EncodedOneBit64) - { - uint64_t* pDma64 = reinterpret_cast(dmaBuffer); - const uint8_t* pEnd = data + sizeData; - - for (const uint8_t* pPixel = data; pPixel < pEnd; pPixel++) - { - uint8_t value = *pPixel; - - for (uint8_t bit = 0; bit < 8; bit++) - { - uint64_t dma64 = *(pDma64); - - dma64 |= (((value & 0x80) ? EncodedOneBit64 : EncodedZeroBit64) << (muxShift)); - *(pDma64++) = dma64; - value <<= 1; - } - } - } -}; - -// -// tracks mux channels used and if updated -// -// T_FLAG - type used to store bit flags, UINT8_t for 8 channels, UINT16_t for 16 -// T_MUXSIZE - true size of mux channel = NeoEspI2sMuxBusSize8Bit or NeoEspI2sMuxBusSize16Bit -// -template class NeoEspI2sMuxMap : public T_MUXSIZE -{ -public: - const static uint8_t InvalidMuxId = -1; - const static size_t BusMaxCount = sizeof(T_FLAG) * 8; - - size_t MaxBusDataSize; // max size of stream data from any single mux bus - T_FLAG UpdateMap; // bitmap flags of mux buses to track update state - T_FLAG UpdateMapMask; // mask to used bits in s_UpdateMap - T_FLAG BusCount; // count of mux buses - - // as a static instance, all members get initialized to zero - // and the constructor is called at inconsistent time to other globals - // so its not useful to have or rely on, - // but without it presence they get zeroed far too late - NeoEspI2sMuxMap() - // //: - // //MaxBusDataSize(0), - // //UpdateMap(0), - // //UpdateMapMask(0), - // //BusCount(0) - { - } - - uint8_t RegisterNewMuxBus(const size_t dataSize) - { - // find first available bus id - uint8_t muxId = 0; - while (muxId < BusMaxCount) - { - T_FLAG muxIdField = (1 << muxId); - if ((UpdateMapMask & muxIdField) == 0) - { - // complete registration - BusCount++; - UpdateMapMask |= muxIdField; - if (dataSize > MaxBusDataSize) - { - MaxBusDataSize = dataSize; - } - break; - } - muxId++; - } - if (muxId == BusMaxCount) - { - log_e("exceded channel limit of %u on bus", BusMaxCount); - } - return muxId; - } - - - bool DeregisterMuxBus(uint8_t muxId) - { - T_FLAG muxIdField = (1 << muxId); - if (UpdateMapMask & muxIdField) - { - // complete deregistration - BusCount--; - UpdateMapMask &= ~muxIdField; - if (UpdateMapMask == 0) - { - return true; - } - } - return false; - } - - bool IsAllMuxBusesUpdated() - { - return (UpdateMap == UpdateMapMask); - } - - bool IsNoMuxBusesUpdate() - { - return (UpdateMap == 0); - } - - void MarkMuxBusUpdated(uint8_t muxId) - { - UpdateMap |= (1 << muxId); - } - - void ResetMuxBusesUpdated() - { - UpdateMap = 0; - } - - void Reset() - { - MaxBusDataSize = 0; - UpdateMap = 0; - UpdateMapMask = 0; - BusCount = 0; - } -}; - -// -// Implementation of a Double Buffered version of a I2sContext -// Manages the underlying I2S details including the buffer(s) -// This creates a front buffer that can be filled while actively sending -// the back buffer, thus improving async operation of the i2s DMA. -// Note that the back buffer must be DMA memory, a limited resource, so -// the front buffer uses normal memory and copies rather than swap pointers -// -// T_MUXMAP - NeoEspI2sMuxMap - tracking class for mux state -// -template class NeoEspI2sDblBuffContext -{ -public: - const static size_t DmaBitsPerPixelBit = 4; - - size_t I2sBufferSize; // total size of I2sBuffer - uint8_t* I2sBuffer; // holds the DMA buffer that is referenced by I2sBufDesc - uint8_t* I2sEditBuffer; // hold a editable buffer that is copied to I2sBuffer - T_MUXMAP MuxMap; - - // as a static instance, all members get initialized to zero - // and the constructor is called at inconsistent time to other globals - // so its not useful to have or rely on, - // but without it presence they get zeroed far too late - NeoEspI2sDblBuffContext() - // //: - // //I2sBufferSize(0), - // //I2sBuffer(nullptr), - // //I2sEditBuffer(nullptr), - // //MuxMap() - { - } - - void Construct(const uint8_t busNumber, uint32_t i2sSampleRate) - { - // construct only once on first time called - if (I2sBuffer == nullptr) - { - // MuxMap.MaxBusDataSize = max size in bytes of a single channel - // DmaBitsPerPixelBit = how many dma bits/byte are needed for each source (pixel) bit/byte - // T_MUXMAP::MuxBusDataSize = the true size of data for selected mux mode (not exposed size as i2s0 only supports 16bit mode) - I2sBufferSize = MuxMap.MaxBusDataSize * 8 * DmaBitsPerPixelBit * T_MUXMAP::MuxBusDataSize; - - // must have a 4 byte aligned buffer for i2s - uint32_t alignment = I2sBufferSize % 4; - if (alignment) - { - I2sBufferSize += 4 - alignment; - } - - size_t dmaBlockCount = (I2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN; - - I2sBuffer = static_cast(heap_caps_malloc(I2sBufferSize, MALLOC_CAP_DMA)); - if (I2sBuffer == nullptr) - { - log_e("send buffer memory allocation failure (size %u)", - I2sBufferSize); - } - memset(I2sBuffer, 0x00, I2sBufferSize); - - I2sEditBuffer = static_cast(malloc(I2sBufferSize)); - if (I2sEditBuffer == nullptr) - { - log_e("edit buffer memory allocation failure (size %u)", - I2sBufferSize); - } - memset(I2sEditBuffer, 0x00, I2sBufferSize); - - i2sInit(busNumber, - true, - T_MUXMAP::MuxBusDataSize, - i2sSampleRate, -#if defined(CONFIG_IDF_TARGET_ESP32S2) -// using these modes on ESP32S2 actually allows it to function -// in both x8 and x16 - I2S_CHAN_STEREO, - I2S_FIFO_16BIT_DUAL, -#else -// but they won't work on ESP32 in parallel mode, but these will - I2S_CHAN_RIGHT_TO_LEFT, - I2S_FIFO_16BIT_SINGLE, -#endif - dmaBlockCount, - I2sBuffer, - I2sBufferSize); - } - } - - void Destruct(const uint8_t busNumber) - { - if (I2sBuffer == nullptr) - { - return; - } - - i2sSetPins(busNumber, -1, -1, -1, false); - i2sDeinit(busNumber); - - free(I2sEditBuffer); - heap_caps_free(I2sBuffer); - - I2sBufferSize = 0; - I2sBuffer = nullptr; - I2sEditBuffer = nullptr; - - MuxMap.Reset(); - } -}; - -// -// Implementation of the low level interface into i2s mux bus -// -// T_BUSCONTEXT - the context to use, currently only NeoEspI2sDblBuffContext but there is -// a plan to provide one that doesn't implement the front buffer but would be less -// async as it would have to wait until the last frame was completely sent before -// updating and new data -// T_BUS - the bus id, NeoEsp32I2sBusZero, NeoEsp32I2sBusOne -// -template class NeoEsp32I2sMuxBus -{ -public: - NeoEsp32I2sMuxBus() : - _muxId(s_context.MuxMap.InvalidMuxId) - { - } - - void RegisterNewMuxBus(size_t dataSize) - { - _muxId = s_context.MuxMap.RegisterNewMuxBus(dataSize); - } - - void Initialize(uint8_t pin, uint32_t i2sSampleRate, bool invert) - { - s_context.Construct(T_BUS::I2sBusNumber, i2sSampleRate); - i2sSetPins(T_BUS::I2sBusNumber, pin, _muxId, s_context.MuxMap.MuxBusDataSize, invert); - } - - void DeregisterMuxBus(uint8_t pin) - { - if (s_context.MuxMap.DeregisterMuxBus(_muxId)) - { - s_context.Destruct(T_BUS::I2sBusNumber); - } - - // disconnect muxed pin - gpio_matrix_out(pin, 0x100, false, false); - pinMode(pin, INPUT); - - _muxId = s_context.MuxMap.InvalidMuxId; - } - - void StartWrite() - { - if (s_context.MuxMap.IsAllMuxBusesUpdated()) - { - s_context.MuxMap.ResetMuxBusesUpdated(); - - // wait for not actively sending data - while (!IsWriteDone()) - { - yield(); - } - // copy edit buffer to sending buffer - memcpy(s_context.I2sBuffer, s_context.I2sEditBuffer, s_context.I2sBufferSize); - i2sWrite(T_BUS::I2sBusNumber); - } - } - - bool IsWriteDone() const - { - return i2sWriteDone(T_BUS::I2sBusNumber); - } - - void FillBuffers(const uint8_t* data, size_t sizeData) - { - if (s_context.MuxMap.IsNoMuxBusesUpdate()) - { - // clear all the data in preperation for each mux channel to add - memset(s_context.I2sEditBuffer, 0x00, s_context.I2sBufferSize); - } - - s_context.MuxMap.EncodeIntoDma(s_context.I2sEditBuffer, - data, - sizeData, - _muxId ); - - s_context.MuxMap.MarkMuxBusUpdated(_muxId); - } - - void MarkUpdated() - { - s_context.MuxMap.MarkMuxBusUpdated(_muxId); - } - -private: - static T_BUSCONTEXT s_context; - uint8_t _muxId; -}; - -template T_BUSCONTEXT NeoEsp32I2sMuxBus::s_context = T_BUSCONTEXT(); - -// -// wrapping layer of the i2s mux bus as a NeoMethod -// -// T_SPEED - NeoEsp32I2sSpeed* (ex NeoEsp32I2sSpeedWs2812x) used to define output signal form -// T_BUS - NeoEsp32I2sMuxBus, the bus to use -// T_INVERT - NeoEsp32I2sNotInverted or NeoEsp32I2sInverted, will invert output signal -// -template class NeoEsp32I2sXMethodBase -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp32I2sXMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount * elementSize + settingsSize), - _pin(pin), - _bus() - { - _bus.RegisterNewMuxBus(_sizeData + T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs); - } - - ~NeoEsp32I2sXMethodBase() - { - while (!_bus.IsWriteDone()) - { - yield(); - } - - _bus.DeregisterMuxBus(_pin); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return _bus.IsWriteDone(); - } - - void Initialize() - { - _bus.Initialize(_pin, T_SPEED::I2sSampleRate, T_INVERT::Inverted); - - _data = static_cast(malloc(_sizeData)); - if (_data == nullptr) - { - log_e("front buffer memory allocation failure"); - } - // data cleared later in Begin() - } - - void Update(bool) - { - _bus.FillBuffers(_data, _sizeData); - _bus.StartWrite(); // only triggers actual write after all mux busses have updated - } - - bool AlwaysUpdate() - { - // this method requires update to be called even if no changes to method buffer - // as edit buffer is always cleared and then copied to send buffer and all - // mux bus needs to included - return true; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - const size_t _sizeData; // Size of '_data' buffer - const uint8_t _pin; // output pin number - - T_BUS _bus; // holds instance for mux bus support - uint8_t* _data; // Holds LED color values -}; - -#if defined(CONFIG_IDF_TARGET_ESP32S2) - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux16Bus; - -#else - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusZero> NeoEsp32I2s0Mux16Bus; - - -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusOne> NeoEsp32I2s1Mux8Bus; -typedef NeoEsp32I2sMuxBus>, NeoEsp32I2sBusOne> NeoEsp32I2s1Mux16Bus; - -#endif - -// NORMAL -// - -// I2s0x8 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Apa106Method; - -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2813Method; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2812dMethod; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2811Method; -typedef NeoEsp32I2s0X8Ws2812xMethod NeoEsp32I2s0X8Ws2816Method; -typedef NeoEsp32I2s0X8800KbpsMethod NeoEsp32I2s0X8Ws2812Method; -typedef NeoEsp32I2s0X8Sk6812Method NeoEsp32I2s0X8Lc8812Method; - -// I2s0x16 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Apa106Method; - -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2813Method; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2812dMethod; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2811Method; -typedef NeoEsp32I2s0X16Ws2812xMethod NeoEsp32I2s0X16Ws2816Method; -typedef NeoEsp32I2s0X16800KbpsMethod NeoEsp32I2s0X16Ws2812Method; -typedef NeoEsp32I2s0X16Sk6812Method NeoEsp32I2s0X16Lc8812Method; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - -// I2s1x8 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Apa106Method; - -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2813Method; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2812dMethod; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2811Method; -typedef NeoEsp32I2s1X8Ws2812xMethod NeoEsp32I2s1X8Ws2816Method; -typedef NeoEsp32I2s1X8800KbpsMethod NeoEsp32I2s1X8Ws2812Method; -typedef NeoEsp32I2s1X8Sk6812Method NeoEsp32I2s1X8Lc8812Method; - -// I2s1x16 -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Ws2812xMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Sk6812Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1814Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1829Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1914Method; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16800KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16400KbpsMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Apa106Method; - -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2813Method; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2812dMethod; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2811Method; -typedef NeoEsp32I2s1X16Ws2812xMethod NeoEsp32I2s1X16Ws2816Method; -typedef NeoEsp32I2s1X16800KbpsMethod NeoEsp32I2s1X16Ws2812Method; -typedef NeoEsp32I2s1X16Sk6812Method NeoEsp32I2s1X16Lc8812Method; - - -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) - -// INVERTED -// -// I2s0x8 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X8Apa106InvertedMethod; - -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2813InvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2812xInvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2811InvertedMethod; -typedef NeoEsp32I2s0X8Ws2812xInvertedMethod NeoEsp32I2s0X8Ws2816InvertedMethod; -typedef NeoEsp32I2s0X8800KbpsInvertedMethod NeoEsp32I2s0X8Ws2812InvertedMethod; -typedef NeoEsp32I2s0X8Sk6812InvertedMethod NeoEsp32I2s0X8Lc8812InvertedMethod; - - -// I2s0x16 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s0X16Apa106InvertedMethod; - -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2813InvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2812xInvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2811InvertedMethod; -typedef NeoEsp32I2s0X16Ws2812xInvertedMethod NeoEsp32I2s0X16Ws2816InvertedMethod; -typedef NeoEsp32I2s0X16800KbpsInvertedMethod NeoEsp32I2s0X16Ws2812InvertedMethod; -typedef NeoEsp32I2s0X16Sk6812InvertedMethod NeoEsp32I2s0X16Lc8812InvertedMethod; - -#if !defined(CONFIG_IDF_TARGET_ESP32S2) - -// I2s1x8 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X8Apa106InvertedMethod; - -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2813InvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2812xInvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2811InvertedMethod; -typedef NeoEsp32I2s1X8Ws2812xInvertedMethod NeoEsp32I2s1X8Ws2816InvertedMethod; -typedef NeoEsp32I2s1X8800KbpsInvertedMethod NeoEsp32I2s1X8Ws2812InvertedMethod; -typedef NeoEsp32I2s1X8Sk6812InvertedMethod NeoEsp32I2s1X8Lc8812InvertedMethod; - -// I2s1x16 INVERTED -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Ws2812xInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Sk6812InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1814InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1829InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Tm1914InvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16800KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16400KbpsInvertedMethod; -typedef NeoEsp32I2sXMethodBase NeoEsp32I2s1X16Apa106InvertedMethod; - -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2813InvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2812xInvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2811InvertedMethod; -typedef NeoEsp32I2s1X16Ws2812xInvertedMethod NeoEsp32I2s1X16Ws2816InvertedMethod; -typedef NeoEsp32I2s1X16800KbpsInvertedMethod NeoEsp32I2s1X16Ws2812InvertedMethod; -typedef NeoEsp32I2s1X16Sk6812InvertedMethod NeoEsp32I2s1X16Lc8812InvertedMethod; - -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) - -#endif // defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h deleted file mode 100644 index 85d39dc37a..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266DmaMethod.h +++ /dev/null @@ -1,437 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - - -Written by Michael C. Miller. -Thanks to g3gg0.de for porting the initial DMA support which lead to this. -Thanks to github/cnlohr for the original work on DMA support, which opend -all our minds to a better way (located at https://github.com/cnlohr/esp8266ws2812i2s). - -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 - -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP8266 -#include "NeoEsp8266I2sMethodCore.h" - -class NeoEsp8266DmaSpeedBase -{ -public: - static const uint8_t IdleLevel = 0; - static uint16_t Convert(uint8_t value) - { - const uint16_t bitpatterns[16] = - { - 0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110, - 0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110, - 0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110, - 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, - }; - - return bitpatterns[value]; - } -}; - -class NeoEsp8266DmaInvertedSpeedBase -{ -public: - static const uint8_t IdleLevel = 1; - static uint16_t Convert(uint8_t value) - { - const uint16_t bitpatterns[16] = - { - 0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001, - 0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001, - 0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001, - 0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001, - }; - - return bitpatterns[value]; - } -}; - -class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed -}; - -class NeoEsp8266DmaSpeedWs2812x : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 300; -}; - -class NeoEsp8266DmaSpeedSk6812 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 80; -}; - -class NeoEsp8266DmaInvertedSpeedTm1814 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaInvertedSpeedTm1829 : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaSpeed800Kbps : public NeoEsp8266DmaSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaSpeed400Kbps : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 10; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - 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 NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 17; // 0-63 - const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaSpeedIntertek : public NeoEsp8266DmaSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 12470; - const static uint32_t InterPixelTimeUs = 20; -}; - -class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed -}; - -class NeoEsp8266DmaInvertedSpeedWs2812x : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 300; -}; - -class NeoEsp8266DmaInvertedSpeedSk6812 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 80; -}; - -class NeoEsp8266DmaSpeedTm1814 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaSpeedTm1829 : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 200; -}; - -class NeoEsp8266DmaInvertedSpeed800Kbps : public NeoEsp8266DmaInvertedSpeed800KbpsBase -{ -public: - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 10; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - 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 NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 17; // 0-63 - const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element - const static uint32_t ResetTimeUs = 50; -}; - -class NeoEsp8266DmaInvertedSpeedIntertek : public NeoEsp8266DmaInvertedSpeedBase -{ -public: - const static uint32_t I2sClockDivisor = 5; // 0-63 - const static uint32_t I2sBaseClockDivisor = 10; // 0-63 - const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed - const static uint32_t ResetTimeUs = 12470; - const static uint32_t InterPixelTimeUs = 20; -}; - -template class NeoEsp8266DmaEncode : public T_SPEED -{ -public: - static size_t SpacingPixelSize(size_t sizePixel) - { - return sizePixel; - } - - static void FillBuffers(uint8_t* i2sBuffer, - const uint8_t* data, - size_t sizeData, - MAYBE_UNUSED size_t sizePixel) - { - uint16_t* pDma = (uint16_t*)i2sBuffer; - const uint8_t* pEnd = data + sizeData; - for (const uint8_t* pData = data; pData < pEnd; pData++) - { - *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); - *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); - } - } -}; - -template class NeoEsp8266DmaPixelSpacingEncode : public T_SPEED -{ -public: - static size_t SpacingPixelSize(size_t sizePixel) - { - return sizePixel + T_SPEED::InterPixelTimeUs / T_SPEED::ByteSendTimeUs; - } - - static void FillBuffers(uint8_t* i2sBuffer, - const uint8_t* data, - size_t sizeData, - size_t sizePixel) - { - uint16_t* pDma = (uint16_t*)i2sBuffer; - const uint8_t* pEnd = data + sizeData; - uint8_t element = 0; - for (const uint8_t* pData = data; pData < pEnd; pData++) - { - *(pDma++) = T_SPEED::Convert(((*pData) & 0x0f)); - *(pDma++) = T_SPEED::Convert(((*pData) >> 4) & 0x0f); - - element++; - if (element == sizePixel) - { - element = 0; - - for (uint8_t padding = 0; - padding < (T_SPEED::InterPixelTimeUs / T_SPEED::ByteSendTimeUs); - padding++) - { - *(pDma++) = T_SPEED::IdleLevel * 0xffff; - *(pDma++) = T_SPEED::IdleLevel * 0xffff; - } - } - } - } -}; - -template class NeoEsp8266DmaMethodBase : NeoEsp8266I2sMethodCore -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp8266DmaMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizePixel(elementSize), - _sizeData(pixelCount * elementSize + settingsSize) - { - size_t dmaPixelSize = DmaBytesPerPixelBytes * T_ENCODER::SpacingPixelSize(_sizePixel); - size_t dmaSettingsSize = DmaBytesPerPixelBytes * settingsSize; - - size_t i2sBufferSize = pixelCount * dmaPixelSize + dmaSettingsSize; - // size is rounded up to nearest c_I2sByteBoundarySize - i2sBufferSize = NeoUtil::RoundUp(i2sBufferSize, c_I2sByteBoundarySize); - - // calculate a buffer size that takes reset amount of time - size_t i2sResetSize = T_ENCODER::ResetTimeUs * DmaBytesPerPixelBytes / T_ENCODER::ByteSendTimeUs; - // size is rounded up to nearest c_I2sByteBoundarySize - i2sResetSize = NeoUtil::RoundUp(i2sResetSize, c_I2sByteBoundarySize); - size_t is2BufMaxBlockSize = (c_maxDmaBlockSize / dmaPixelSize) * dmaPixelSize; - - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - - AllocateI2s(i2sBufferSize, i2sResetSize, is2BufMaxBlockSize, T_ENCODER::IdleLevel); - } - - NeoEsp8266DmaMethodBase(MAYBE_UNUSED uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoEsp8266DmaMethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~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_ENCODER::ResetTimeUs) * waits)) - { - yield(); - } - - FreeI2s(); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return IsIdle(); - } - - void Initialize() - { - InitializeI2s(T_ENCODER::I2sClockDivisor, T_ENCODER::I2sBaseClockDivisor); - } - - void IRAM_ATTR Update(bool) - { - // wait for not actively sending data - while (!IsReadyToUpdate()) - { - yield(); - } - T_ENCODER::FillBuffers(_i2sBuffer, _data, _sizeData, _sizePixel); - - WriteI2s(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - // due to encoding required for i2s, we need 4 bytes to encode the pulses - static const uint16_t DmaBytesPerPixelBytes = 4; - - const size_t _sizePixel; // size of a pixel in _data - const size_t _sizeData; // Size of '_data' buffer - uint8_t* _data; // Holds LED color values - - uint32_t getPixelTime() const - { - return (T_ENCODER::ByteSendTimeUs * GetSendSize() / DmaBytesPerPixelBytes); - }; - -}; - - - -// normal -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaWs2812xMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaSk6812Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaTm1814Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaTm1829Method; -typedef NeoEsp8266DmaTm1814Method NeoEsp8266DmaTm1914Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266Dma800KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266Dma400KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaApa106Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaIntertekMethod; - - -// inverted -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedWs2812xMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedSk6812Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedTm1814Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedTm1829Method; -typedef NeoEsp8266DmaInvertedTm1814Method NeoEsp8266DmaInvertedTm1914Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInverted800KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInverted400KbpsMethod; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedApa106Method; -typedef NeoEsp8266DmaMethodBase> NeoEsp8266DmaInvertedIntertekMethod; - -// Dma method is the default method for Esp8266 -typedef NeoEsp8266DmaWs2812xMethod NeoWs2813Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2812xMethod; -typedef NeoEsp8266Dma800KbpsMethod NeoWs2812Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2811Method; -typedef NeoEsp8266DmaWs2812xMethod NeoWs2816Method; -typedef NeoEsp8266DmaSk6812Method NeoSk6812Method; -typedef NeoEsp8266DmaTm1814Method NeoTm1814Method; -typedef NeoEsp8266DmaTm1829Method NeoTm1829Method; -typedef NeoEsp8266DmaTm1914Method NeoTm1914Method; -typedef NeoEsp8266DmaSk6812Method NeoLc8812Method; -typedef NeoEsp8266DmaApa106Method NeoApa106Method; -typedef NeoEsp8266DmaIntertekMethod NeoIntertekMethod; - -typedef NeoEsp8266DmaWs2812xMethod Neo800KbpsMethod; -typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod; - -// inverted -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2813InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2812xInvertedMethod; -typedef NeoEsp8266DmaInverted800KbpsMethod NeoWs2812InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2811InvertedMethod; -typedef NeoEsp8266DmaInvertedWs2812xMethod NeoWs2816InvertedMethod; -typedef NeoEsp8266DmaInvertedSk6812Method NeoSk6812InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1814Method NeoTm1814InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1829Method NeoTm1829InvertedMethod; -typedef NeoEsp8266DmaInvertedTm1914Method NeoTm1914InvertedMethod; -typedef NeoEsp8266DmaInvertedSk6812Method NeoLc8812InvertedMethod; -typedef NeoEsp8266DmaInvertedApa106Method NeoApa106InvertedMethod; -typedef NeoEsp8266DmaInvertedIntertekMethod NeoInvertedIntertekMethod; - -typedef NeoEsp8266DmaInvertedWs2812xMethod Neo800KbpsInvertedMethod; -typedef NeoEsp8266DmaInverted400KbpsMethod Neo400KbpsInvertedMethod; -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h deleted file mode 100644 index 798bb0929f..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sDmx512Method.h +++ /dev/null @@ -1,354 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - -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 - -#include "../NeoUtil.h" - -#ifdef ARDUINO_ARCH_ESP8266 -#include "NeoEsp8266I2sMethodCore.h" - - -class NeoEsp8266I2sDmx512SpeedBase -{ -public: - // 4 us bit send, 250Kbps - static const uint32_t I2sClockDivisor = 20; // 0-63 - static const uint32_t I2sBaseClockDivisor = 32; // 0-63 - static const uint32_t ByteSendTimeUs = 44; // us it takes to send a single pixel element of 11 bits - static const uint32_t BreakMabUs = 96; // Break min 92, Mab min 12 - static const size_t BreakMabSize = 4; // roundupby((BreakMabUs/4us)/8,4) count of bytes needed for the Break+Mab timing - static const uint32_t MtbpUs = 11; // Mtbp, min 0, buy we use at least one byte of space (8*1.35) - static const size_t MtbpSize = 1; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing - // DMX requires the first slot to be zero - static const size_t HeaderSize = 1; -}; - -class NeoEsp8266I2sDmx512Speed : public NeoEsp8266I2sDmx512SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x1; // high - static const uint8_t StartBit = 0b00000000; - static const uint8_t StopBits = 0b00000011; - static const uint32_t Break = 0x00000000; // Break - static const uint32_t BreakMab = 0x00000007; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits( value ); - } -}; - -class NeoEsp8266I2sDmx512InvertedSpeed : public NeoEsp8266I2sDmx512SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x00; // low - static const uint8_t StartBit = 0b00000001; - static const uint8_t StopBits = 0b00000000; - static const uint32_t Break = 0xffffffff; // Break - static const uint32_t BreakMab = 0xfffffff8; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits( ~value ); - } -}; - - -class NeoEsp8266I2sWs2821SpeedBase -{ -public: - // 1.35 us bit send, 750Kbps - static const uint32_t I2sClockDivisor = 27; // 0-63 - static const uint32_t I2sBaseClockDivisor = 8; // 0-63 - static const uint32_t ByteSendTimeUs = 15; // us it takes to send a single pixel element of 11 bits - static const uint32_t BreakMabUs = 92; // Break min 88, Mab min 4 - static const size_t BreakMabSize = 12; // roundupby((BreakMabUs/1.35)/8,4) count of bytes needed for the Break+Mab timing - static const uint32_t MtbpUs = 88; // Mtbp, min 88 - static const size_t MtbpSize = 9; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing - - // DMX/WS2821 requires the first slot to be zero - static const size_t HeaderSize = 1; -}; - -class NeoEsp8266I2sWs2821Speed : public NeoEsp8266I2sWs2821SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x1; // high - static const uint8_t StartBit = 0b00000000; - static const uint8_t StopBits = 0b00000011; - static const uint32_t Break = 0x00000000; // Break - static const uint32_t BreakMab = 0x00000007; // Break + Mab (4~12us/1.35us) - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits(value); - } -}; - -class NeoEsp8266I2sWs2821InvertedSpeed : public NeoEsp8266I2sWs2821SpeedBase -{ -public: - static const uint8_t MtbpLevel = 0x00; // low - static const uint8_t StartBit = 0b00000001; - static const uint8_t StopBits = 0b00000000; - static const uint32_t Break = 0xffffffff; // Break - static const uint32_t BreakMab = 0xfffffff8; // Break + Mab - - static uint8_t Convert(uint8_t value) - { - // DMX requires LSB order - return NeoUtil::Reverse8Bits(~value); - } -}; - -template class NeoEsp8266I2sDmx512MethodBase : NeoEsp8266I2sMethodCore -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEsp8266I2sDmx512MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount * elementSize + settingsSize + T_SPEED::HeaderSize) - { - size_t dmaPixelBits = I2sBitsPerPixelBytes * elementSize; - size_t dmaSettingsBits = I2sBitsPerPixelBytes * (settingsSize + T_SPEED::HeaderSize); - - // bits + half rounding byte of bits / bits per byte - size_t i2sBufferSize = (pixelCount * dmaPixelBits + dmaSettingsBits + 4) / 8; - - i2sBufferSize = i2sBufferSize + T_SPEED::BreakMabSize; - - // size is rounded up to nearest c_I2sByteBoundarySize - i2sBufferSize = NeoUtil::RoundUp(i2sBufferSize, c_I2sByteBoundarySize); - - // size of a looping silent space rounded up to nearest c_I2sByteBoundarySize - size_t i2sResetSize = NeoUtil::RoundUp(T_SPEED::MtbpSize, c_I2sByteBoundarySize); - - // protocol limits use of full block size to c_I2sByteBoundarySize - size_t is2BufMaxBlockSize = (c_maxDmaBlockSize / c_I2sByteBoundarySize) * c_I2sByteBoundarySize; - - _data = static_cast(malloc(_sizeData)); - // first "slot" cleared due to protocol requiring it to be zero - memset(_data, 0x00, 1); - - AllocateI2s(i2sBufferSize, i2sResetSize, is2BufMaxBlockSize, T_SPEED::MtbpLevel); - } - - NeoEsp8266I2sDmx512MethodBase(MAYBE_UNUSED uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - NeoEsp8266I2sDmx512MethodBase(pixelCount, elementSize, settingsSize) - { - } - - ~NeoEsp8266I2sDmx512MethodBase() - { - 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::MtbpUs) * waits)) - { - yield(); - } - - FreeI2s(); - - free(_data); - } - - bool IsReadyToUpdate() const - { - return IsIdle(); - } - - void Initialize() - { - InitializeI2s(T_SPEED::I2sClockDivisor, T_SPEED::I2sBaseClockDivisor); - } - - void IRAM_ATTR Update(bool) - { - // wait for not actively sending data - while (!IsReadyToUpdate()) - { - yield(); - } - FillBuffers(); - - WriteI2s(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data + T_SPEED::HeaderSize; - }; - - size_t getDataSize() const - { - return _sizeData - T_SPEED::HeaderSize; - } - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - // given 11 sending bits per pixel byte, - static const uint16_t I2sBitsPerPixelBytes = 11; - - const size_t _sizeData; // Size of '_data' buffer - uint8_t* _data; // Holds LED color values - - // encodes the data with start and stop bits - // input buffer is bytes - // output stream is uint31_t - static void Encoder(const uint8_t* pSrc, const uint8_t* pSrcEnd, - uint32_t* pOutput, const uint32_t* pOutputEnd) - { - static const uint32_t Mtbp = 0xffffffff * T_SPEED::MtbpLevel; - const uint8_t* pData = pSrc; - - int8_t outputBit = 32; - uint32_t output = 0; - - // DATA stream, one start, two stop - while (pData < pSrcEnd) - { - uint8_t data = T_SPEED::Convert( *(pData++) ); - - if (outputBit > 10) - { - // simple - outputBit -= 1; - output |= T_SPEED::StartBit << outputBit; - - outputBit -= 8; - output |= data << outputBit; - - outputBit -= 2; - output |= T_SPEED::StopBits << outputBit; - } - else - { - // split across an output uint32_t - // handle start bit - if (outputBit < 1) - { - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 1; - output |= (T_SPEED::StartBit << outputBit); - - // handle data bits - if (outputBit < 8) - { - output |= data >> (8 - outputBit); - - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 8; - output |= data << outputBit; - - // handle stop bits - if (outputBit < 2) - { - output |= T_SPEED::StopBits >> (2 - outputBit); - - *(pOutput++) = output; - output = 0; - outputBit += 32; - } - outputBit -= 2; - output |= T_SPEED::StopBits << outputBit; - } - } - if (outputBit > 0) - { - // padd last output uint32_t with Mtbp - output |= Mtbp >> (32 - outputBit); - *(pOutput++) = output; - } - // fill the rest of the output with Mtbp - while (pOutput < pOutputEnd) - { - *(pOutput++) = Mtbp; - } - } - - - void FillBuffers() - { - uint32_t* pDma32 = reinterpret_cast(_i2sBuffer); - const uint32_t* pDma32End = reinterpret_cast(_i2sBuffer + _i2sBufferSize); - - // first insert Break space as needed - for (size_t count = 1; - count < (T_SPEED::BreakMabSize/sizeof(T_SPEED::Break)); - count++) - { - *(pDma32++) = T_SPEED::Break; - } - // then tail of break with mab - *(pDma32++) = T_SPEED::BreakMab; - - Encoder(_data, _data + _sizeData, pDma32, pDma32End); - } - - uint32_t getPixelTime() const - { - return (T_SPEED::ByteSendTimeUs * this->_sizeData); - }; - -}; - - -// normal -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Dmx512Method; -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Ws2821Method; - -// inverted -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Dmx512InvertedMethod; -typedef NeoEsp8266I2sDmx512MethodBase NeoEsp8266Ws2821InvertedMethod; - -#endif diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h b/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h deleted file mode 100644 index db67126ed8..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEsp8266I2sMethodCore.h +++ /dev/null @@ -1,362 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Esp8266. - -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 "Arduino.h" - -extern "C" -{ -#include "osapi.h" -#include "ets_sys.h" - -#include "i2s_reg.h" - -#ifdef ARDUINO_ESP8266_MAJOR //this define was added in ESP8266 Arduino Core version v3.0.1 -#include "core_esp8266_i2s.h" //for Arduino core >= 3.0.1 -#else -#include "i2s.h" //for Arduino core <= 3.0.0 -#endif - -#include "eagle_soc.h" -#include "esp8266_peri.h" -#include "slc_register.h" - -#include "osapi.h" -#include "ets_sys.h" -#include "user_interface.h" - -#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 -} - -struct slc_queue_item -{ - uint32 blocksize : 12; - uint32 datalen : 12; - uint32 unused : 5; - uint32 sub_sof : 1; - uint32 eof : 1; - uint32 owner : 1; - uint8* buf_ptr; - struct slc_queue_item* next_link_ptr; -}; - -enum NeoDmaState -{ - NeoDmaState_Idle, - NeoDmaState_Pending, - NeoDmaState_Sending -}; - -const uint16_t c_maxDmaBlockSize = 4095; - -const uint8_t c_I2sPin = 3; // due to I2S hardware, the pin used is restricted to this - -class NeoEsp8266I2sMethodCore -{ -private: - static const uint8_t c_StateBlockCount = 2; - static const size_t c_StateDataSize = 4; // mulitples of c_I2sByteBoundarySize - - // i2s sends 4 byte elements, - static const uint16_t c_I2sByteBoundarySize = 4; - -protected: - static NeoEsp8266I2sMethodCore* s_this; // for the ISR - - volatile NeoDmaState _dmaState; - - slc_queue_item* _i2sBufDesc; // dma block descriptors - uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc - - size_t _i2sBufferSize; // total size of _i2sBuffer - uint8_t* _i2sBuffer; // holds the DMA buffer that is referenced by _i2sBufDesc - - size_t _i2sIdleDataTotalSize; // total size of represented zeroes, mulitple uses of _i2sIdleData - size_t _i2sIdleDataSize; // size of _i2sIdleData - uint8_t* _i2sIdleData; - - uint16_t _is2BufMaxBlockSize; // max size based on size of a pixel of a single block - - size_t GetSendSize() const - { - return _i2sBufferSize + _i2sIdleDataTotalSize; - } - - // This routine is called as soon as the DMA routine has something to tell us. All we - // handle here is the RX_EOF_INT status, which indicate the DMA has sent a buffer whose - // descriptor has the 'EOF' field set to 1. - // in the case of this code, the second to last state descriptor - static void IRAM_ATTR i2s_slc_isr(void) - { - ETS_SLC_INTR_DISABLE(); - - uint32_t slc_intr_status = SLCIS; - - SLCIC = 0xFFFFFFFF; - - if ((slc_intr_status & SLCIRXEOF) && s_this) - { - if (s_this->_dmaState != NeoDmaState_Idle) - { - // first two items are the state blocks - slc_queue_item* itemLoop = s_this->_i2sBufDesc; - slc_queue_item* itemLoopBreaker = itemLoop + 1; - // set to loop on idle items - itemLoopBreaker->next_link_ptr = itemLoop; - - s_this->_dmaState = NeoDmaState_Idle; - } - } - - ETS_SLC_INTR_ENABLE(); - } - - NeoEsp8266I2sMethodCore() - { }; - - void AllocateI2s(const size_t i2sBufferSize, // expected multiples of c_I2sByteBoundarySize - const size_t i2sZeroesSize, // expected multiples of c_I2sByteBoundarySize - const size_t is2BufMaxBlockSize, - const uint8_t idleLevel) - { - _i2sBufferSize = i2sBufferSize; - _i2sIdleDataTotalSize = i2sZeroesSize; - _i2sIdleDataSize = _i2sIdleDataTotalSize; - - size_t countIdleQueueItems = 1; - if (_i2sIdleDataSize > 256) - { - // reuse a single idle data buffer of 256 with multiple dma slc_queue_items - countIdleQueueItems = _i2sIdleDataSize / 256 + 1; - _i2sIdleDataSize = 256; - } - else - { - _i2sIdleDataSize = NeoUtil::RoundUp(_i2sIdleDataSize, c_I2sByteBoundarySize); - } - _is2BufMaxBlockSize = is2BufMaxBlockSize; - - _i2sBuffer = static_cast(malloc(_i2sBufferSize)); - // no need to initialize it, it gets overwritten on every send - _i2sIdleData = static_cast(malloc(_i2sIdleDataSize)); - memset(_i2sIdleData, idleLevel * 0xff, _i2sIdleDataSize); - - _i2sBufDescCount = (_i2sBufferSize / _is2BufMaxBlockSize) + 1 + - countIdleQueueItems + - c_StateBlockCount; // need more for state/latch blocks - - _i2sBufDesc = (slc_queue_item*)malloc(_i2sBufDescCount * sizeof(slc_queue_item)); - - s_this = this; // store this for the ISR - } - - void FreeI2s() - { - StopI2s(); - - s_this = nullptr; - pinMode(c_I2sPin, INPUT); - - free(_i2sBuffer); - free(_i2sBufDesc); - free(_i2sIdleData); - } - - bool IsIdle() const - { - return (_dmaState == NeoDmaState_Idle); - } - - - void DmaItemInit(slc_queue_item* item, uint8_t* data, size_t sizeData, slc_queue_item* itemNext) - { - item->owner = 1; - item->eof = 0; // no need to trigger interrupt generally - item->sub_sof = 0; - item->datalen = sizeData; - item->blocksize = sizeData; - item->buf_ptr = data; - item->unused = 0; - item->next_link_ptr = itemNext; - } - - void InitializeI2s(const uint32_t i2sClockDivisor, const uint32_t i2sBaseClockDivisor) - { - StopI2s(); - - pinMode(c_I2sPin, FUNCTION_1); // I2S0_DATA - - uint8_t* is2Buffer = _i2sBuffer; - uint8_t* is2BufferEnd = _i2sBuffer + _i2sBufferSize; - uint32_t is2BufferSize; - uint16_t indexDesc = 0; - - // prepare the two state/latch descriptors - uint16_t stateDataSize = min(c_StateDataSize, _i2sIdleDataSize); - while (indexDesc < c_StateBlockCount) - { - DmaItemInit(&_i2sBufDesc[indexDesc], _i2sIdleData, stateDataSize, &(_i2sBufDesc[indexDesc + 1])); - - indexDesc++; - } - - // prepare main data block decriptors that point into our one static dma buffer - is2BufferSize = _i2sBufferSize; - while (is2Buffer < is2BufferEnd) - { - uint32_t blockSize = (is2BufferSize > _is2BufMaxBlockSize) ? _is2BufMaxBlockSize : is2BufferSize; - - DmaItemInit(&_i2sBufDesc[indexDesc], is2Buffer, blockSize, &(_i2sBufDesc[indexDesc + 1])); - - is2Buffer += blockSize; - is2BufferSize -= blockSize; - indexDesc++; - } - - // last data item triggers EOF ISR - _i2sBufDesc[indexDesc - 1].eof = 1; - - // prepare idle block decriptors that point into our one idle dma buffer - is2BufferSize = _i2sIdleDataTotalSize; - while (indexDesc < _i2sBufDescCount) - { - uint32_t blockSize = (is2BufferSize > _i2sIdleDataSize) ? _i2sIdleDataSize : is2BufferSize; - - DmaItemInit(&_i2sBufDesc[indexDesc], _i2sIdleData, blockSize, &(_i2sBufDesc[indexDesc + 1])); - - is2Buffer += blockSize; - is2BufferSize -= blockSize; - indexDesc++; - } - - // the last item will loop to the first item - _i2sBufDesc[indexDesc - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[0])); - - // the last state block will loop to the first state block by defualt - _i2sBufDesc[c_StateBlockCount - 1].next_link_ptr = reinterpret_cast(&(_i2sBufDesc[0])); - - // setup the rest of i2s DMA - // - ETS_SLC_INTR_DISABLE(); - - // start off in idel state as that is what it will be all setup to be - // for the interrupt - _dmaState = NeoDmaState_Idle; - - SLCC0 |= SLCRXLR | SLCTXLR; - SLCC0 &= ~(SLCRXLR | SLCTXLR); - SLCIC = 0xFFFFFFFF; - - // Configure DMA - SLCC0 &= ~(SLCMM << SLCM); // clear DMA MODE - SLCC0 |= (1 << SLCM); // set DMA MODE to 1 - SLCRXDC |= SLCBINR | SLCBTNR; // enable INFOR_NO_REPLACE and TOKEN_NO_REPLACE - SLCRXDC &= ~(SLCBRXFE | SLCBRXEM | SLCBRXFM); // disable RX_FILL, RX_EOF_MODE and RX_FILL_MODE - - // Feed DMA the 1st buffer desc addr - // To send data to the I2S subsystem, counter-intuitively we use the RXLINK part, not the TXLINK as you might - // 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 - // 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 - // 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 - - ETS_SLC_INTR_ENABLE(); - - //Start transmission - SLCTXL |= SLCTXLS; - SLCRXL |= SLCRXLS; - - I2S_CLK_ENABLE(); - I2SIC = 0x3F; - I2SIE = 0; - - //Reset I2S - I2SC &= ~(I2SRST); - I2SC |= I2SRST; - I2SC &= ~(I2SRST); - - // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only) - I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM) | (I2SRXFMM << I2SRXFM)); - I2SFC |= I2SDE; //Enable DMA - // Set RX/TX CHAN_MOD=0 - I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); - - // set the rate - uint32_t i2s_clock_div = i2sClockDivisor & I2SCDM; - uint8_t i2s_bck_div = i2sBaseClockDivisor & I2SBDM; - - //!trans master, !bits mod, rece slave mod, rece msb shift, right first, msb right - 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 WriteI2s() - { - // first two items are the state blocks - slc_queue_item* itemLoopBreaker = &(_i2sBufDesc[1]); - slc_queue_item* itemData = itemLoopBreaker + 1; - - // set to NOT loop on idle items - itemLoopBreaker->next_link_ptr = itemData; - - _dmaState = NeoDmaState_Sending; - } - - void StopI2s() - { - 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 - SLCRXL &= ~(SLCRXLAM << SLCRXLA); // clear RX descriptor address - - pinMode(c_I2sPin, INPUT); - } -}; - -#endif // ARDUINO_ARCH_ESP8266 \ No newline at end of file diff --git a/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h b/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h deleted file mode 100644 index b641646bee..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/NeoEspBitBangMethod.h +++ /dev/null @@ -1,366 +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 -. --------------------------------------------------------------------------*/ - -#pragma once - -#include "../NeoUtil.h" - -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - -#if defined(ARDUINO_ARCH_ESP8266) -#include -#endif -#if defined(CONFIG_IDF_TARGET_ESP32C3) -#define CYCLES_LOOPTEST (1) // adjustment due to loop exit test instruction cycles -#elif defined(CONFIG_IDF_TARGET_ESP32S3) -#define CYCLES_LOOPTEST (2) // adjustment due to loop exit test instruction cycles -#else -#define CYCLES_LOOPTEST (4) // adjustment due to loop exit test instruction cycles -#endif - -extern void neoEspBitBangWriteSpacingPixels(const uint8_t* pixels, - const uint8_t* end, - uint8_t pin, - uint32_t t0h, - uint32_t t1h, - uint32_t period, - size_t sizePixel, - uint32_t tSpacing, - bool invert); - - -class NeoEspNotInverted -{ -public: - const static uint8_t IdleLevel = LOW; -}; - -class NeoEspInverted -{ -public: - const static uint8_t IdleLevel = HIGH; -}; - -class NeoEspBitBangSpeedWs2811 -{ -public: - const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us - const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 300; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedWs2812x -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 300; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedSk6812 -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 80; - const static uint32_t TInterPixel = 0; -}; - -// Tm1814 normal is inverted signal -class NeoEspBitBangSpeedTm1814 -{ -public: - const static uint32_t T0H = (F_CPU / 2916666 - CYCLES_LOOPTEST); // 0.35us - const static uint32_t T1H = (F_CPU / 1666666 - CYCLES_LOOPTEST); // 0.75us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 200; - const static uint32_t TInterPixel = 0; -}; - -// Tm1829 normal is inverted signal -class NeoEspBitBangSpeedTm1829 -{ -public: - const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 200; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeed800Kbps -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeed400Kbps -{ -public: - const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST); - const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST); - const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST); - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedApa106 -{ -public: - const static uint32_t T0H = (F_CPU / 2857143 - CYCLES_LOOPTEST); // 0.35us - const static uint32_t T1H = (F_CPU / 740741 - CYCLES_LOOPTEST); // 1.35 - const static uint32_t Period = (F_CPU / 606061 - CYCLES_LOOPTEST); // 1.65us - - static const uint32_t ResetTimeUs = 50; - const static uint32_t TInterPixel = 0; -}; - -class NeoEspBitBangSpeedIntertek -{ -public: - const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us - const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us - const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit - - const static uint32_t ResetTimeUs = 12470; - const static uint32_t TInterPixel = (F_CPU / 50000); // 20us -}; - - -template class NeoEspBitBangEncode : public T_SPEED, public T_INVERTED -{ -public: - static void WritePixels(uint8_t pin, - const uint8_t* data, - size_t sizeData, - size_t sizePixel) - { - neoEspBitBangWriteSpacingPixels(data, - data + sizeData, - pin, - T_SPEED::T0H, - T_SPEED::T1H, - T_SPEED::Period, - sizePixel, - T_SPEED::TInterPixel, - T_INVERTED::IdleLevel); - } -}; - -template class NeoEspBitBangMethodBase -{ -public: - typedef NeoNoSettings SettingsObject; - - NeoEspBitBangMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizePixel(elementSize), - _sizeData(pixelCount * elementSize + settingsSize), - _pin(pin) - { - pinMode(pin, OUTPUT); - - _data = static_cast(malloc(_sizeData)); - // data cleared later in Begin() - } - - ~NeoEspBitBangMethodBase() - { - pinMode(_pin, INPUT); - - free(_data); - } - - bool IsReadyToUpdate() const - { - uint32_t delta = micros() - _endTime; - - return (delta >= T_ENCODER::ResetTimeUs); - } - - void Initialize() - { - digitalWrite(_pin, T_ENCODER::IdleLevel); - - _endTime = micros(); - } - - 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 - // 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 (!IsReadyToUpdate()) - { - yield(); // allows for system yield if needed - } - - // 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_ENCODER::WritePixels(_pin, - _data, - _sizeData, - _sizePixel); - -#if defined(ARDUINO_ARCH_ESP32) - portEXIT_CRITICAL(&updateMux); -#else - interrupts(); -#endif - - // save EOD time for latch on next call - _endTime = micros(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - } - -private: - const size_t _sizePixel; // size of a pixel in _data - const size_t _sizeData; // Size of '_data' buffer below - const uint8_t _pin; // output pin number - - uint32_t _endTime; // Latch timing reference - uint8_t* _data; // Holds LED color values -}; - - -#if defined(ARDUINO_ARCH_ESP32) - -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2811Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2812xMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangSk6812Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1814Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1829Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang800KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang400KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangApa106Method; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangIntertekMethod; - -typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2813Method; -typedef NeoEsp32BitBang800KbpsMethod NeoEsp32BitBangWs2812Method; -typedef NeoEsp32BitBangWs2812xMethod NeoEsp32BitBangWs2816Method; -typedef NeoEsp32BitBangTm1814Method NeoEsp32BitBangTm1914Method; -typedef NeoEsp32BitBangSk6812Method NeoEsp32BitBangLc8812Method; - -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2811InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangWs2812xInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangSk6812InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1814InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangTm1829InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang800KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBang400KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangApa106InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp32BitBangIntertekInvertedMethod; - -typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2813InvertedMethod; -typedef NeoEsp32BitBang800KbpsInvertedMethod NeoEsp32BitBangWs2812InvertedMethod; -typedef NeoEsp32BitBangWs2812xInvertedMethod NeoEsp32BitBangWs2816InvertedMethod; -typedef NeoEsp32BitBangTm1814InvertedMethod NeoEsp32BitBangTm1914InvertedMethod; -typedef NeoEsp32BitBangSk6812InvertedMethod NeoEsp32BitBangLc8812InvertedMethod; - -#else // defined(ARDUINO_ARCH_ESP8266) - -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2811Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2812xMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangSk6812Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1814Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1829Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang800KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang400KbpsMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangApa106Method; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangIntertekMethod; - -typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2813Method; -typedef NeoEsp8266BitBang800KbpsMethod NeoEsp8266BitBangWs2812Method; -typedef NeoEsp8266BitBangWs2812xMethod NeoEsp8266BitBangWs2816Method; -typedef NeoEsp8266BitBangTm1814Method NeoEsp8266BitBangTm1914Method; -typedef NeoEsp8266BitBangSk6812Method NeoEsp8266BitBangLc8812Method; - -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2811InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangWs2812xInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangSk6812InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1814InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangTm1829InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang800KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBang400KbpsInvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangApa106InvertedMethod; -typedef NeoEspBitBangMethodBase> NeoEsp8266BitBangIntertekInvertedMethod; - -typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2813InvertedMethod; -typedef NeoEsp8266BitBang800KbpsInvertedMethod NeoEsp8266BitBangWs2812InvertedMethod; -typedef NeoEsp8266BitBangWs2812xInvertedMethod NeoEsp8266BitBangWs2816InvertedMethod; -typedef NeoEsp8266BitBangTm1814InvertedMethod NeoEsp8266BitBangTm1914InvertedMethod; -typedef NeoEsp8266BitBangSk6812InvertedMethod NeoEsp8266BitBangLc8812InvertedMethod; - -#endif // defined(ARDUINO_ARCH_ESP32) - -// ESP bitbang doesn't have defaults and should avoided except for testing - -#endif // defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) diff --git a/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h deleted file mode 100644 index 800080ca56..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Sm16716GenericMethod.h +++ /dev/null @@ -1,140 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for SM16716 using general Pins - -Written by Michael C. Miller. -Contributed by Ivo H (ivoh95) - -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 - -#include "../NeoUtil.h" - -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - - -template class Sm16716MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - Sm16716MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _sizeData(pixelCount* elementSize + settingsSize), - _sizeFrame(6), // 48 bits - _wire(pinClock, pinData) - { - _data = static_cast(malloc(_sizeData)); - memset(_data, 0, _sizeData); - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Sm16716MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Sm16716MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Sm16716MethodBase() - { - free(_data); - } - - bool IsReadyToUpdate() const - { - return true; // dot stars don't have a required delay - } - -#if defined(ARDUINO_ARCH_ESP32) - // can't support hardware SPI due to weird extra bits - //void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) - //{ - // _wire.begin(sck, miso, mosi, ss); - //} -#endif - - void Initialize() - { - _wire.begin(); - } - - void Update(bool) - { - _wire.beginTransaction(); - - // start frame - for (size_t frameBytes = 0; frameBytes < _sizeFrame; frameBytes++) - { - _wire.transmitByte(0x00); - } - _wire.transmitBit(LOW); - _wire.transmitBit(LOW); // two extra 0s to make the 50 0 header - _wire.transmitBit(HIGH); // one to start the led frame - - for (size_t pixel = 0; pixel < (_sizeData / 3); pixel++) - { - _wire.transmitByte(_data[pixel]); - _wire.transmitByte(_data[pixel + 1]); - _wire.transmitByte(_data[pixel + 2]); - _wire.transmitBit(HIGH); //show the color and start the next frame - } - - _wire.endTransaction(); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - const size_t _sizeData; // Size of '_data' buffer below - const size_t _sizeFrame; - - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values -}; - -// can ONLY support our bitbang for wire due to requirement for custom transmitBit method -// to handle not byte oriented data stream -// -typedef Sm16716MethodBase Sm16716Method; diff --git a/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h b/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h deleted file mode 100644 index 1b58f6b6e3..0000000000 --- a/lib/NeoPixelBus/src/internal/methods/Tlc5947GenericMethod.h +++ /dev/null @@ -1,222 +0,0 @@ -/*------------------------------------------------------------------------- -NeoPixel library helper functions for Tlc5947 24 channel PWM controller using general Pins. - -Written by Michael C. Miller. -Written by Dennis Kasprzyk. - -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 - -#include "../NeoUtil.h" - -// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set -#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) -#include "TwoWireBitBangImpleAvr.h" -#else -#include "TwoWireBitBangImple.h" -#endif - -#define TLC5947_MODULE_PWM_CHANNEL_COUNT 24 - -class Tlc5947Converter8Bit -{ -public: - static const size_t sizeChannel = 1; - static void ConvertFrame(uint8_t* sendBufferPtr, uint8_t* channelPtr) - { - // Write 2 channels into 3 bytes scaling 8-bit to 12-bit per channel - for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) - { - uint8_t ch1 = *channelPtr--; - uint8_t ch2 = *channelPtr--; - - *sendBufferPtr++ = ch1; - *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 4); - *sendBufferPtr++ = ((ch2 << 4) & 0xf0) | (ch2 >> 4); - } - } -}; - -class Tlc5947Converter16Bit -{ -public: - static const size_t sizeChannel = 2; - static void ConvertFrame(uint8_t* sendBufferPtr, uint8_t* sourceBufferPtr) - { - uint16_t* channelPtr = (uint16_t*)sourceBufferPtr; - - // Write 2 channels into 3 bytes using upper 12-bit of each channel - for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) - { - uint8_t ch1 = *channelPtr--; - uint8_t ch2 = *channelPtr--; - - *sendBufferPtr++ = ch1 >> 8; - *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 12); - *sendBufferPtr++ = ch2 >> 4; - } - } -}; - - -template class Tlc5947MethodBase -{ -public: - typedef typename T_TWOWIRE::SettingsObject SettingsObject; - - // 24 channel * 12 bit - static const size_t sizeSendBuffer = 36; - - Tlc5947MethodBase(uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint8_t pinOutputEnable, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - _countModule((pixelCount * elementSize + TLC5947_MODULE_PWM_CHANNEL_COUNT - 1) / TLC5947_MODULE_PWM_CHANNEL_COUNT), - _sizeData(_countModule * TLC5947_MODULE_PWM_CHANNEL_COUNT + settingsSize), - _wire(pinClock, pinData), - _pinLatch(pinLatch), - _pinOutputEnable(pinOutputEnable) - { - _data = static_cast(malloc(_sizeData)); - pinMode(pinLatch, OUTPUT); - pinMode(pinOutputEnable, OUTPUT); - digitalWrite(pinOutputEnable, HIGH); - } - - Tlc5947MethodBase(uint8_t pinClock, uint8_t pinData, uint8_t pinLatch, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(pinClock, pinData, pinLatch, -1, pixelCount, elementSize, settingsSize) - { - } - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) - Tlc5947MethodBase(uint8_t pinLatch, uint8_t pinOutputEnable, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(SCK, MOSI, pinLatch, pinOutputEnable, pixelCount, elementSize, settingsSize) - { - } - - Tlc5947MethodBase(uint8_t pinLatch, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : - Tlc5947MethodBase(SCK, MOSI, pinLatch, -1, pixelCount, elementSize, settingsSize) - { - } -#endif - - ~Tlc5947MethodBase() - { - free(_data); - pinMode(_pinLatch, INPUT); - pinMode(_pinOutputEnable, INPUT); - } - - bool IsReadyToUpdate() const - { - 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) - { - _wire.begin(sck, miso, mosi, ss); - } -#endif - - void Initialize() - { - _wire.begin(); - memset(_data, 0, _sizeData); - } - - void Update(bool) - { - - digitalWrite(_pinOutputEnable, HIGH); - - digitalWrite(_pinLatch, LOW); - _wire.beginTransaction(); - - // We need to write the channels in reverse order. Get a Pointer to the last channel. - uint8_t* lastChannelPtr = _data + ((_countModule * TLC5947_MODULE_PWM_CHANNEL_COUNT - 1) * T_BITCONVERT::sizeChannel); - for (uint16_t countSend = 0; countSend < _countModule; countSend++) - { - // We pass a pointer to the last channel and ConvertFrame reads the channels backwards - T_BITCONVERT::ConvertFrame(_sendBuffer, lastChannelPtr); - _wire.transmitBytes(_sendBuffer, sizeSendBuffer); - lastChannelPtr -= TLC5947_MODULE_PWM_CHANNEL_COUNT * T_BITCONVERT::sizeChannel; - } - - _wire.endTransaction(); - digitalWrite(_pinLatch, HIGH); - digitalWrite(_pinLatch, LOW); - digitalWrite(_pinOutputEnable, LOW); - } - - bool AlwaysUpdate() - { - // this method requires update to be called only if changes to buffer - return false; - } - - uint8_t* getData() const - { - return _data; - }; - - size_t getDataSize() const - { - return _sizeData; - }; - - void applySettings(MAYBE_UNUSED const SettingsObject& settings) - { - _wire.applySettings(settings); - } - -private: - const uint16_t _countModule; // Number of tlc5947 modules - const size_t _sizeData; // Size of '_data' buffer below - - T_TWOWIRE _wire; - uint8_t* _data; // Holds LED color values - uint8_t _sendBuffer[sizeSendBuffer]; // Holds channel values for one module - uint8_t _pinLatch; - uint8_t _pinOutputEnable; -}; - -typedef Tlc5947MethodBase Tlc5947Method; -typedef Tlc5947MethodBase Tlc5947Method16Bit; - -#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) -#include "TwoWireSpiImple.h" - -// for standalone -typedef Tlc5947MethodBase> Tlc5947Spi30MhzMethod; -typedef Tlc5947MethodBase> Tlc5947Spi30MhzMethod16Bit; - -// for cascaded devices -typedef Tlc5947MethodBase> Tlc5947Spi15MhzMethod; -typedef Tlc5947MethodBase> Tlc5947Spi15MhzMethod16Bit; - -typedef Tlc5947MethodBase> Tlc5947SpiMethod; -typedef Tlc5947MethodBase> Tlc5947SpiMethod16Bit; - - -#endif - - - diff --git a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h b/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h deleted file mode 100644 index ef2da56bd1..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorAlternatingLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/*------------------------------------------------------------------------- -ColumnMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 - - -class ColumnMajorAlternatingLayout; -class ColumnMajorAlternating180Layout; - -class ColumnMajorAlternatingTilePreference -{ -public: - typedef ColumnMajorAlternatingLayout EvenRowEvenColumnLayout; - typedef ColumnMajorAlternatingLayout EvenRowOddColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowEvenColumnLayout; - typedef ColumnMajorAlternating180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 07 08 15 -// 01 06 09 14 -// 02 05 10 13 -// 03 04 11 12 -// -class ColumnMajorAlternatingLayout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 04 05 06 07 -// 11 10 09 08 -// 12 13 14 15 -// -class ColumnMajorAlternating90Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 12 11 04 03 -// 13 10 05 02 -// 14 09 06 01 -// 15 08 07 00 -// -class ColumnMajorAlternating180Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 08 09 10 11 -// 07 06 05 04 -// 00 01 02 03 -// -class ColumnMajorAlternating270Layout : public ColumnMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h b/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h deleted file mode 100644 index 242fd00c13..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/ColumnMajorLayout.h +++ /dev/null @@ -1,104 +0,0 @@ -/*------------------------------------------------------------------------- -ColumnMajorLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 - - -class ColumnMajorLayout; -class ColumnMajor90Layout; -class ColumnMajor180Layout; -class ColumnMajor270Layout; - -class ColumnMajorTilePreference -{ -public: - typedef ColumnMajorLayout EvenRowEvenColumnLayout; - typedef ColumnMajor270Layout EvenRowOddColumnLayout; - typedef ColumnMajor90Layout OddRowEvenColumnLayout; - typedef ColumnMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 04 08 12 -// 01 05 09 13 -// 02 06 10 14 -// 03 07 11 15 -// -class ColumnMajorLayout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + y; - } -}; - -// layout example of 4x4 -// 03 02 01 00 -// 07 06 05 04 -// 11 10 09 08 -// 15 14 13 12 -// -class ColumnMajor90Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return (width - 1 - x) + y * width; - } -}; - -// layout example of 4x4 -// 15 11 07 03 -// 14 10 06 02 -// 13 09 05 01 -// 12 08 04 00 -// -class ColumnMajor180Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + (height - 1 - y); - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 08 09 10 11 -// 04 05 06 07 -// 00 01 02 03 -// -class ColumnMajor270Layout : public ColumnMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return x + (height - 1 - y) * width; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h b/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h deleted file mode 100644 index 09a23c7127..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/RowMajorAlternatingLayout.h +++ /dev/null @@ -1,144 +0,0 @@ -/*------------------------------------------------------------------------- -RowMajorAlternatingLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 - - -class RowMajorAlternating270Layout; -class RowMajorAlternating90Layout; - -class RowMajorAlternatingTilePreference -{ -public: - typedef RowMajorAlternating270Layout EvenRowEvenColumnLayout; - typedef RowMajorAlternating270Layout EvenRowOddColumnLayout; - typedef RowMajorAlternating90Layout OddRowEvenColumnLayout; - typedef RowMajorAlternating90Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 07 06 05 04 -// 08 09 10 11 -// 15 14 13 12 -// -class RowMajorAlternatingLayout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - uint16_t index = y * width; - - if (y & 0x0001) - { - index += ((width - 1) - x); - } - else - { - index += x; - } - return index; - } -}; - -// layout example of 4x4 -// 15 08 07 00 -// 14 09 06 01 -// 13 10 05 02 -// 12 11 04 03 -// -class RowMajorAlternating90Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t mx = ((width - 1) - x); - uint16_t index = mx * height; - - if (mx & 0x0001) - { - index += ((height - 1) - y); - } - else - { - index += y; - } - return index; - } -}; - -// layout example of 4x4 -// 12 13 14 15 -// 11 10 09 08 -// 04 05 06 07 -// 03 02 01 00 -// -class RowMajorAlternating180Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t my = ((height - 1) - y); - uint16_t index = my * width; - - if (my & 0x0001) - { - index += x; - } - else - { - index += ((width - 1) - x); - } - return index; - } -}; - -// layout example of 4x4 -// 03 04 11 12 -// 02 05 10 13 -// 01 06 09 14 -// 00 07 08 15 -// -class RowMajorAlternating270Layout : public RowMajorAlternatingTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - uint16_t index = x * height; - - if (x & 0x0001) - { - index += y; - } - else - { - index += ((height - 1) - y); - } - return index; - } -}; diff --git a/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h b/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h deleted file mode 100644 index 90a6f65305..0000000000 --- a/lib/NeoPixelBus/src/internal/topologies/RowMajorLayout.h +++ /dev/null @@ -1,103 +0,0 @@ -/*------------------------------------------------------------------------- -RowMajorLayout provides a collection of class objects that are used with NeoTopology -object. -They define the specific layout of pixels and do the math to change the 2d -cordinate space to 1d cordinate space - -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 - -class RowMajorLayout; -class RowMajor90Layout; -class RowMajor180Layout; -class RowMajor270Layout; - -class RowMajorTilePreference -{ -public: - typedef RowMajorLayout EvenRowEvenColumnLayout; - typedef RowMajor270Layout EvenRowOddColumnLayout; - typedef RowMajor90Layout OddRowEvenColumnLayout; - typedef RowMajor180Layout OddRowOddColumnLayout; -}; - -// layout example of 4x4 -// 00 01 02 03 -// 04 05 06 07 -// 08 09 10 11 -// 12 13 14 15 -// -class RowMajorLayout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t /* height */, uint16_t x, uint16_t y) - { - return x + y * width; - } -}; - -// layout example of 4x4 -// 12 08 04 00 -// 13 09 05 01 -// 14 10 06 02 -// 15 11 07 03 -// -class RowMajor90Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) * height + y; - } -}; - -// layout example of 4x4 -// 15 14 13 12 -// 11 10 09 08 -// 07 06 05 04 -// 03 02 01 00 -// -class RowMajor180Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t width, uint16_t height, uint16_t x, uint16_t y) - { - return (width - 1 - x) + (height - 1 - y) * width; - } -}; - -// layout example of 4x4 -// 03 07 11 15 -// 02 06 10 14 -// 01 05 09 13 -// 00 04 08 12 -// -class RowMajor270Layout : public RowMajorTilePreference -{ -public: - static uint16_t Map(uint16_t /* width */, uint16_t height, uint16_t x, uint16_t y) - { - return x * height + (height - 1 - y); - } -}; diff --git a/lib/NeoPixelBus_wrapper/LICENSE b/lib/NeoPixelBus_wrapper/LICENSE new file mode 100644 index 0000000000..f288702d2f --- /dev/null +++ b/lib/NeoPixelBus_wrapper/LICENSE @@ -0,0 +1,674 @@ + 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_wrapper/README.md b/lib/NeoPixelBus_wrapper/README.md new file mode 100644 index 0000000000..8e03098e27 --- /dev/null +++ b/lib/NeoPixelBus_wrapper/README.md @@ -0,0 +1,27 @@ +# NeoPixelBus_wrapper + +**NeoPixelBus_wrapper**: A minimal wrapper to replace Adafruit_NeoPixel API to use Makuna's NeoPixelBus API. + +(c) 2023, Ton Huisman for [ESPEasy](https://github.com/letscontrolit/ESPEasy). + +### How to use + +- Add this library to your `lib` folder +- Add the [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) library to your `lib` folder +- Replace the `#include ` line by `#include ` +- Replace your type `Adafruit_NeoPixel` variable(s) by type `NeoPixelBus_wrapper` variable(s) +- When using runtime instantiation of the wrapper object, replace your `pixels = new Adafruit_NeoPixel(...)` call by `pixels = new NeoPixelBus_wrapper(...)` +- Compile, and presto! + +### Limitations + +- Currently only supports the most commonly used NeoPixel stripes `NEO_GRB` and `NEO_GRBW`, and the default `NEO_KHZ800` method. (That's all what is used in ESPEasy...) + +### Support + +For questions and improvement requests, please use the Github Issues system. + +### Reference + +- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) +- [Adafruit_NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) \ No newline at end of file diff --git a/lib/NeoPixelBus_wrapper/library.properties b/lib/NeoPixelBus_wrapper/library.properties new file mode 100644 index 0000000000..b00f7c338f --- /dev/null +++ b/lib/NeoPixelBus_wrapper/library.properties @@ -0,0 +1,10 @@ +name=NeoPixelBus_wrapper +version=0.1.0 +author=tonhuisman +maintainer=tonhuisman +sentence=Arduino wrapper library for interfacing Adafruit_NeoPixel applications to use Makuna NeoPixelBus +paragraph=Arduino wrapper library for interfacing Adafruit_NeoPixel applications to use Makuna NeoPixelBus +category=Display +url=https://github.com/tonhuisman/NeoPixelBus_wrapper +architectures=* +includes=NeoPixelBus by Makuna diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp new file mode 100644 index 0000000000..54c5c9dc77 --- /dev/null +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp @@ -0,0 +1,117 @@ +#ifndef _NEOPIXELBUS_WRAPPER_CPP +#define _NEOPIXELBUS_WRAPPER_CPP +#include "./NeoPixelBus_wrapper.h" + +NeoPixelBus_wrapper::NeoPixelBus_wrapper(uint16_t _maxPixels, + int16_t _gpioPin, + neoPixelType _stripType) + : numLEDs(_maxPixels) { + if (NEO_GRB == (_stripType & NEO_GRB)) { + #ifdef ESP8266 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); + #endif // ifdef ESP8266 + #ifdef ESP32 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); + #endif // ifdef ESP32 + } + + if (NEO_GRBW == (_stripType & NEO_GRBW)) { + #ifdef ESP8266 + neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); + #endif // ifdef ESP8266 + #ifdef ESP32 + neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); + #endif // ifdef ESP32 + } +} + +NeoPixelBus_wrapper::~NeoPixelBus_wrapper() { + delete neopixels_grb; + neopixels_grb = nullptr; + delete neopixels_grbw; + neopixels_grbw = nullptr; +} + +void NeoPixelBus_wrapper::begin() { + if (nullptr != neopixels_grb) { + neopixels_grb->Begin(); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->Begin(); + } +} + +void NeoPixelBus_wrapper::show(void) { + if (nullptr != neopixels_grb) { + neopixels_grb->Show(); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->Show(); + } +} + +void NeoPixelBus_wrapper::setBrightness(uint8_t b) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetBrightness(b); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetBrightness(b); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor(r, g, b)); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor(r, g, b)); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b, + uint8_t w) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor(r, g, b)); + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor(r, g, b, w)); + } +} + +void NeoPixelBus_wrapper::setPixelColor(uint16_t pxl, + uint32_t c) { + if (nullptr != neopixels_grb) { + neopixels_grb->SetPixelColor(pxl, RgbColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF)); // Unfold the Color(r,g,b,w) static + } + + if (nullptr != neopixels_grbw) { + neopixels_grbw->SetPixelColor(pxl, RgbwColor((c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF, (c >> 24) & 0xFF)); + } +} + +uint32_t NeoPixelBus_wrapper::getPixelColor(uint16_t n) { + if (nullptr != neopixels_grb) { + const RgbColor color = neopixels_grb->GetPixelColor(n); + return Color(color.R, color.G, color.B); + } + + if (nullptr != neopixels_grbw) { + const RgbwColor color = neopixels_grbw->GetPixelColor(n); + return Color(color.R, color.G, color.B, color.W); + } + + return 0u; // Fall-through value... +} + +#endif // ifndef _NEOPIXELBUS_WRAPPER_CPP diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h new file mode 100644 index 0000000000..10f1b88f0e --- /dev/null +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.h @@ -0,0 +1,64 @@ +#ifndef _HELPERS_NEOPIXELBUS_WRAPPER_H +#define _HELPERS_NEOPIXELBUS_WRAPPER_H + +#include +#include // Be sure to keep this header file when upgrading the NeoPixelBus library, + // and remove the deprecation warning if needed +// Some stuff from Adafruit_NeoPixel.h used in plugins +#ifndef NEO_GRB +# define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B +# define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) ///< Transmit as G,R,B,W +# define NEO_KHZ800 0x0000 ///< 800 KHz data transmission +typedef uint16_t neoPixelType; ///< 3rd arg to Adafruit_NeoPixel constructor +#endif // ifndef NEO_GRB + + +#define NEOPIXEL_LIB NeoPixelBrightnessBus // Neopixel library type +#if defined(ESP32) +# define METHOD NeoWs2812xMethod // Automatic method, user selected pin +#endif // if defined(ESP32) +#if defined(ESP8266) +# define METHOD NeoEsp8266Uart1800KbpsMethod // GPIO2 - use NeoEsp8266Uart0800KbpsMethod for GPIO1(TX) +#endif // if defined(ESP8266) + +struct NeoPixelBus_wrapper { +public: + + NeoPixelBus_wrapper(uint16_t _maxPixels, + int16_t _gpioPin, + neoPixelType _stripType); + virtual ~NeoPixelBus_wrapper(); + void begin(); + void show(void); + void setBrightness(uint8_t); + void setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b); + void setPixelColor(uint16_t pxl, + uint8_t r, + uint8_t g, + uint8_t b, + uint8_t w); + void setPixelColor(uint16_t pxl, + uint32_t c); + uint32_t getPixelColor(uint16_t n); + uint16_t numPixels(void) const { + return numLEDs; + } + + static uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { + return static_cast(w) << 24 | + static_cast(r) << 16 | + static_cast(g) << 8 | + static_cast(b); + } + +private: + + NEOPIXEL_LIB *neopixels_grb = nullptr; + NEOPIXEL_LIB *neopixels_grbw = nullptr; + uint16_t numLEDs = 0; +}; + +#endif // ifndef _HELPERS_NEOPIXELBUS_WRAPPER_H diff --git a/lib/ld2410/LICENSE b/lib/ld2410/LICENSE new file mode 100644 index 0000000000..8000a6faac --- /dev/null +++ b/lib/ld2410/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. 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 not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the 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 +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey 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 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 Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/lib/ld2410/README.md b/lib/ld2410/README.md new file mode 100644 index 0000000000..030b2bcdb2 --- /dev/null +++ b/lib/ld2410/README.md @@ -0,0 +1,89 @@ +# LD2410 +## Introduction + +An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. + +![](ld2410andbreakout.jpg) + +The code in this library is based heavily off this [piece of work for ESPHome](https://github.com/rain931215/ESPHome-LD2410) and the manufacturer datasheet. + +The LD2410, as sold for configuration with the common breakout boards shown above communicates over serial at 256000 baud by default. This library allows you to configure and use the sensor over this serial connection. As the LD2410 is a device that uses a high baud rate, a microcontroller with a spare hardware UART for this communication is preferable to bit-banged software serial. + +The modules also provide an 'active high' output on the 'OUT' pin which can be used to signal presence, based off the settings configured. Once the modules are configured it is not necessary to use their UART, but it provides much more information. + +## Connections + +The module must be powered by 5V or higher, but does 3.3v I/O, please consider this when working with the module. + +![](ld2410pinout.jpg) + +The default header pitch is 1.27mm, half the size of the usual 0.1" hobbyist pin headers so you may need to buy some, or carefully de-solder the existing pins to use the module. + +![](ld2410pcb.jpg) + +If you have the breakout board, you can use the VCC, GND, TX and RX pins to work with the module. + +## Reading distances + +The LD2410 has a number of 'gates', each of which correspond to a distance of about 0.75m and many of the settings/measurements are calculated from this. + +You set the sensitivity at each 'gate' on a scale 0-100, any object that doesn't register above this scale is not reported on. The defaults do a good job of spotting an adult person and estimating distance. + +Both moving and stationary targets are detected separately, with a value for each in centimetres. The accuracy of this distance isn't amazing but given this sensor is targeted as a replacement for something like a passive infrared sensor it's a very big improvement. + +The minimal sketch to read distances is in the example 'basicSensor.ino'. + +## Configuring the sensor + +Each 'gate' has a sensitivity value for stationary and moving targets. You can also set a maximum gate that ignores readings beyond a certain gate for both stationary and moving targets and an 'idle timeout' for how long it reports on something after moving away. + +A sketch to configure the sensor is in the example 'setupSensor.ino' it's an interactive sketch that will take commands sent over the Serial monitor. It should demonstrate all the various bits of the configuration you can change. + +## Methods/variables + +Many of the configuration methods return a boolean value. This is because the protocol between the LD2410 and the microcontroller involves requesting the change and the LD2410 acknowledges this with success or failure. This means these methods are synchronous, they will block until the LD2410 responds with succeed/fail or the transaction times out after 100ms. + +The presence/distance readings report the most recent values as the LD2410 continuously streams data, which is processed by calling *read()* as often as is practical. + +``` +bool ld2410::begin(Stream &radarStream, bool waitForRadar = true) - You must supply a Stream for the UART (eg. Serial1 that the LD2410 is connected to) and by default it waits for the radar to respond so it feeds back if it is connected +void debug(Stream &debugStream) - Enables debugging output of the library on a Stream you pass it (eg. Serial) +void read() - You must call this frequently in your main loop to process incoming frames from the LD2410 +bool isConnected() - Is the LD2410 connected and sending data regularly +bool presenceDetected() - Is a presence detected. Nice and simple +bool stationaryTargetDetected() - Is a stationary target detected. +uint16_t stationaryTargetDistance() - Distance to the stationary target in centimetres. +uint8_t stationaryTargetEnergy() - The 'energy'of the target on a scale 0-100, which also a kind of confidence value. +bool movingTargetDetected() - Is a moving target detected. +uint16_t movingTargetDistance() - Distance to the moving target in centimetres. +uint8_t movingTargetEnergy() - The 'energy'of the target on a scale 0-100, which also a kind of confidence value. +bool requestFirmwareVersion() - Request the firmware version, which is then available on the values below. +uint8_t firmware_major_version +uint8_t firmware_minor_version +uint32_t firmware_bugfix_version - This is coded as HEX +bool requestCurrentConfiguration() - Request the full current configuration, which you can then read with the variable & methods below. +uint8_t max_gate - The max gate ID reported by the sensor +uint8_t max_moving_gate - The highest gate ID that will report moving targets +uint8_t max_stationary_gate - The highers gate ID that will report stationary targets +uint8_t motion_sensitivity[max_gate + 1] - One value 0-100 per gate +uint8_t stationary_sensitivity[max_gate + 1] - One value 0-100 per gate +bool setMaxValues(uint8_t moving, uint8_t stationary, uint16_t inactivityTimer) - Set furthest gates and inactivitity timer for targets +bool setGateSensitivity(uint8_t gate, uint8_t moving, uint8_t stationary) - Set gate sensitivites 0-100 +bool requestRestart() - Request a restart of the LD2410. Which is needed to apply some settings. +bool requestFactoryReset() - Request a factory reset of the LD2410. You need to restart afterwards to take effect. +bool requestStartEngineeringMode() - Request engineering mode, which sends more data on targets. +bool requestEndEngineeringMode() - Request the end of engineering mode. +``` + +## Changelog + +- v0.1.1 - Readings for stationary and moving targets were transposed, now fixed. Fixes #1 - stationaryTargetDetected() always true. Many improvements to parsing of commands/acks from the LD2410 and better debug logging. +- v0.1.0 - Initial release + +## Known issues/to-do list + +The code is somewhat verbose/inefficient. + +No support for engineering mode data yet. + +Feel free to contact me with PRs, suggestions and improvements. diff --git a/lib/ld2410/examples/advanced/LD2410-alarm-final.json b/lib/ld2410/examples/advanced/LD2410-alarm-final.json new file mode 100644 index 0000000000..c0f5cd94b6 --- /dev/null +++ b/lib/ld2410/examples/advanced/LD2410-alarm-final.json @@ -0,0 +1,411 @@ +{ + "frameEnd": "*/", + "frameParser": "/* \n * @brief Frame parsing function, you can modify this to suit your needs.\n * \n * By customizing this code, you can use a single JSON project file to \n * process different kinds of frames that are sent by the microcontroller \n * or any data source that is connected to Serial Studio. Frame parsing code\n * is specific to every JSON project that you create.\n *\n * @param frame string with the latest received frame.\n * @param separator data separator sequence defined by the JSON project.\n *\n * @note. only data that is *inside* the data delimiters will\n * be processed by the frame parser.\n *\n * @note you can safely declare global variables outside the\n * @c parse() function.\n */\nfunction parse(frame, separator) {\n return frame.split(separator);\n}", + "frameStart": "/*", + "groups": [ + { + "datasets": [ + { + "alarm": 0, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 0, + "min": 0, + "title": "Moving", + "units": "cm", + "value": "%2", + "widget": "" + }, + { + "alarm": 0, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 0, + "min": 0, + "title": "Detection", + "units": "cm", + "value": "%3", + "widget": "" + }, + { + "alarm": 50, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Energy", + "units": "dBZ", + "value": "%4", + "widget": "" + } + ], + "title": "Moving Target", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": 0, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 0, + "min": 0, + "title": "Stationary", + "units": "cm", + "value": "%5", + "widget": "" + }, + { + "alarm": 0, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 0, + "min": 0, + "title": "Detection", + "units": "cm", + "value": "%6", + "widget": "" + }, + { + "alarm": 50, + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 0, + "min": 0, + "title": "Energy", + "units": "dBZ", + "value": "%7", + "widget": "" + } + ], + "title": "Stationary Target", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%8", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%9", + "widget": "gauge" + }, + { + "alarm": "%10", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%11", + "widget": "gauge" + } + ], + "title": "Gate 0", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%12", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%13", + "widget": "gauge" + }, + { + "alarm": "%14", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%15", + "widget": "gauge" + } + ], + "title": "Gate 1", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%16", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%17", + "widget": "gauge" + }, + { + "alarm": "%18", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%19", + "widget": "gauge" + } + ], + "title": "Gate 2", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%20", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%21", + "widget": "gauge" + }, + { + "alarm": "%22", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%23", + "widget": "gauge" + } + ], + "title": "Gate 3", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%24", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%25", + "widget": "gauge" + }, + { + "alarm": "%26", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%27", + "widget": "gauge" + } + ], + "title": "Gate 4", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%28", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%29", + "widget": "gauge" + }, + { + "alarm": "%30", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%31", + "widget": "gauge" + } + ], + "title": "Gate 5", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%32", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%33", + "widget": "gauge" + }, + { + "alarm": "%34", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%35", + "widget": "gauge" + } + ], + "title": "Gate 6", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%36", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%37", + "widget": "gauge" + }, + { + "alarm": "%38", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%39", + "widget": "gauge" + } + ], + "title": "Gate 7", + "widget": "multiplot" + }, + { + "datasets": [ + { + "alarm": "%40", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Movement Energy", + "units": "dBZ", + "value": "%41", + "widget": "gauge" + }, + { + "alarm": "%42", + "fft": false, + "fftSamples": 1024, + "graph": true, + "led": false, + "log": false, + "max": 100, + "min": 0, + "title": "Static Energy", + "units": "dBZ", + "value": "%43", + "widget": "gauge" + } + ], + "title": "Gate 8", + "widget": "multiplot" + } + ], + "separator": ",", + "title": "%1" +} diff --git a/lib/ld2410/examples/advanced/README.md b/lib/ld2410/examples/advanced/README.md new file mode 100644 index 0000000000..f839d2fa7c --- /dev/null +++ b/lib/ld2410/examples/advanced/README.md @@ -0,0 +1,12 @@ +Advanced udpToSerialStudio.cpp + +SerialStudio reads the UDP output of the ESP and plots the various +data points. The ESP also has a command console on both Serial +and UDP port 8091, which allow configuration of LD2410 device. + + +You will need the JSON project file in this folder and the app "SerialStudio" at this link: +- https://github.com/Serial-Studio/Serial-Studio/releases + +### This file maps to csv data: use via SerialStudio Setup option + ld2410-alarm-final.json buildWithAlarmSerialStudioCSV() diff --git a/lib/ld2410/examples/advanced/udpToSerialStudio.cpp b/lib/ld2410/examples/advanced/udpToSerialStudio.cpp new file mode 100644 index 0000000000..cb6ab5b370 --- /dev/null +++ b/lib/ld2410/examples/advanced/udpToSerialStudio.cpp @@ -0,0 +1,488 @@ +/* + * Example sketch for reporting on readings from the LD2410 using + * whatever settings are currently configured. + * + * The sketch assumes an ESP32 board with the LD2410 connected as Serial2 + * on pins 16 & 17, the serial configuration for other boards may vary. + * + * Program broadcasts [reporting data] on port 8090, and listens on + * port 8091 for commands or configuration requests, + * responses are sent to callers ip/port as discovered. + * + * Where [reporting data], can be CSV-like, JSON with Short or Long attributes as + * documented in [SerialStudio's page](https://github.com/Serial-Studio/Serial-Studio/wiki/Communication-Protocol) + * + * WIFI_SSID and WIFI_PASS are double-quoted environment variables with related values, + * -- example: export PLATFORMIO_BUILD_FLAGS=-DWIFI_PASS='"ssid-password"' -DWIFI_SSID='"ssid-value"' + * or + * -- example: export WIFI_PASS='"ssid-password"' + * -- export WIFI_SSID='"ssid-value"' + * + * Gates: + * - each gate is 0.75m or 30 inches + * 0 to 9 gates = 6.75m or 22 feet ish + * + * + */ + +#include +#include +#include +#include + +#define RXD2 16 // 8 +#define TXD2 17 // 9 +#define MAX_COMMAND_TOKENS 32 +#define SNAME "LD2410 Sensor 01" +#define SERIAL_STUDIO 1 + +#ifdef SERIAL_STUDIO +AsyncUDP udp; +#endif + +const char* ssid = WIFI_SSID; +const char* ssidPassword = WIFI_PASS; +const uint16_t sendPort = 8090; +const uint16_t listenPort = 8091; +IPAddress ipSerialStudio(10,100,1,5); + +uint16_t remotePort = 8090; // default value, will be overridden on reciept of udp request +IPAddress ipRemote(10,100,1,5); // default value, will be overridden on reciept of udp request + +ld2410 radar; +volatile bool udpFlag = false; // send for callback +uint32_t lastReading = 0; +uint32_t pos = 0; +uint32_t pos1 = 0; +uint32_t pos2 = 0; + +bool sending_enabled = true; +char buffer1[128]; +char serialBuffer[256]; +String command = ""; +String output = ""; + +/* + * Available Commands */ +String availableCommands() { + String sCmd = ""; + sCmd += "\nSupported commands:"; + sCmd += "\n\t( 1) help: this text."; + sCmd += "\n\t( 2) streamstart: start sending udp data to SerialStudio."; + sCmd += "\n\t( 3) streamstop: stop sending to SerialStream."; + sCmd += "\n\t( 4) read: read current values from the sensor"; + sCmd += "\n\t( 5) readconfig: read the configuration from the sensor"; + sCmd += "\n\t( 6) setmaxvalues (2-8) (0-65535)seconds"; + sCmd += "\n\t( 7) setsensitivity (2-8|255) (0-100)"; + sCmd += "\n\t( 8) restart: restart the sensor"; + sCmd += "\n\t( 9) readversion: read firmware version"; + sCmd += "\n\t(10) factoryreset: factory reset the sensor"; + sCmd += "\n\t(11) deviceinfo: LD2410 device info"; + sCmd += "\n\t(12) reboot: reboot hosting micro-controller\n"; + + return sCmd; +} + +/* + * Command Processor + * - there are two ommands not implemented + * - requestConfigurationModeBegin() + * - requestConfigurationModeEnd() + * Otherwise all commands are available as options + */ +String commandProcessor(String &cmdStr) { + String sBuf = "\n"; + int iCmd = cmdStr.toInt(); + cmdStr.trim(); + + if(cmdStr.equals("help") || iCmd == 1) + { + sBuf += availableCommands(); + } + else if(cmdStr.equals("streamstart") || iCmd == 2) + { + sending_enabled = true; + sBuf += "\nSerialStudio UDP Stream Enabled. \n"; + } + else if(cmdStr.equals("streamstop") || iCmd == 3) + { + sending_enabled = false; + sBuf += "\nSerialStudio UDP Stream Disabled.\n"; + } + else if(cmdStr.equals("read") || iCmd == 4) + { + sBuf += "\nReading from sensor: "; + if(radar.isConnected()) + { + sBuf += "OK\n"; + if(radar.presenceDetected()) + { + if(radar.stationaryTargetDetected()) + { + sBuf += "Stationary target: "; + sBuf += radar.stationaryTargetDistance(); + sBuf += " cm energy: "; + sBuf += radar.stationaryTargetEnergy(); + sBuf += " dBZ\n"; + } + if(radar.movingTargetDetected()) + { + sBuf += "Moving target: "; + sBuf += radar.movingTargetDistance(); + sBuf += " cm energy: "; + sBuf += radar.movingTargetEnergy(); + sBuf += " dBZ\n"; + } + if(!radar.stationaryTargetDetected() && !radar.movingTargetDetected()) { + sBuf += "No Detection, in Idle Hold window of: "; + sBuf += radar.cfgSensorIdleTimeInSeconds(); + sBuf += " seconds\n"; + } + } + else + { + sBuf += "\nnothing detected\n"; + } + } + else + { + sBuf += "failed to read\n"; + } + } + else if(cmdStr.equals("readconfig") || iCmd == 5) + { + sBuf += "\nReading configuration from sensor: "; + if(radar.requestCurrentConfiguration()) + { + sBuf += "OK\n"; + sBuf += "Maximum gate ID: "; + sBuf += radar.cfgMaxGate(); + sBuf += "\n"; + sBuf += "Maximum gate for moving targets: "; + sBuf += radar.cfgMaxMovingGate(); + sBuf += "\n"; + sBuf += "Maximum gate for stationary targets: "; + sBuf += radar.cfgMaxStationaryGate(); + sBuf += "\n"; + sBuf += "Idle time for targets: "; + sBuf += radar.cfgSensorIdleTimeInSeconds() ; + sBuf += "s\n"; + sBuf += "Gate sensitivity\n"; + + for(uint8_t gate = 0; gate < LD2410_MAX_GATES; gate++) + { + sBuf += "Gate "; + sBuf += gate; + sBuf += " moving targets: "; + sBuf += radar.cfgMovingGateSensitivity(gate); + sBuf += " dBZ stationary targets: "; + sBuf += radar.cfgStationaryGateSensitivity(gate); + sBuf += " dBZ\n"; + } + } + else + { + sBuf += "Failed\n"; + } + } + else if(cmdStr.startsWith("setmaxvalues") || iCmd == 6) + { + uint8_t firstSpace = cmdStr.indexOf(' '); + uint8_t secondSpace = cmdStr.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = cmdStr.indexOf(' ',secondSpace + 1); + + uint8_t newMovingMaxDistance = (cmdStr.substring(firstSpace,secondSpace)).toInt(); + uint8_t newStationaryMaxDistance = (cmdStr.substring(secondSpace,thirdSpace)).toInt(); + uint16_t inactivityTimer = (cmdStr.substring(thirdSpace,cmdStr.length())).toInt(); + + if(newMovingMaxDistance > 0 && newStationaryMaxDistance > 0 && newMovingMaxDistance <= 8 && newStationaryMaxDistance <= 8) + { + sBuf += "\nSetting max values to gate "; + sBuf += newMovingMaxDistance; + sBuf += " moving targets, gate "; + sBuf += newStationaryMaxDistance; + sBuf += " stationary targets, "; + sBuf += inactivityTimer; + sBuf += "s inactivity timer: "; + if(radar.setMaxValues(newMovingMaxDistance, newStationaryMaxDistance, inactivityTimer)) + { + sBuf += "OK, now restart to apply settings\n"; + } + else + { + sBuf += "failed\n"; + } + } + else + { + sBuf += "Can't set distances to "; + sBuf += newMovingMaxDistance; + sBuf += " moving "; + sBuf += newStationaryMaxDistance; + sBuf += " stationary, try again\n"; + } + } + else if(cmdStr.startsWith("setsensitivity") || iCmd == 7) + { + uint8_t firstSpace = cmdStr.indexOf(' '); + uint8_t secondSpace = cmdStr.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = cmdStr.indexOf(' ',secondSpace + 1); + + uint8_t gate = (cmdStr.substring(firstSpace,secondSpace)).toInt(); + uint8_t motionSensitivity = (cmdStr.substring(secondSpace,thirdSpace)).toInt(); + uint8_t stationarySensitivity = (cmdStr.substring(thirdSpace,cmdStr.length())).toInt(); + + // Command method 1 -- limit gate to 0-8 -- set one gate set + // Command method 2 -- limit gate to 255 -- set all gates to same sensitivity value + if(motionSensitivity >= 0 && stationarySensitivity >= 0 && motionSensitivity <= 100 && stationarySensitivity <= 100) + { + sBuf += "\nSetting gate "; + sBuf += gate; + sBuf += " motion sensitivity to "; + sBuf += motionSensitivity; + sBuf += " dBZ & stationary sensitivity to "; + sBuf += stationarySensitivity; + sBuf += " dBZ: \n"; + if(radar.setGateSensitivityThreshold(gate, motionSensitivity, stationarySensitivity)) + { + sBuf += "OK, now restart to apply settings\n"; + } + else + { + sBuf += "failed\n"; + } + } + else + { + sBuf += "Can't set gate "; + sBuf += gate; + sBuf += " motion sensitivity to "; + sBuf += motionSensitivity; + sBuf += " dBZ & stationary sensitivity to "; + sBuf += stationarySensitivity; + sBuf += " dBZ, try again\n"; + } + } + else if(cmdStr.equals("restart") || iCmd ==8) + { + if(radar.requestRestart()) + { + delay(1500); + if(radar.requestStartEngineeringMode()) { + sBuf += "\nRestarting sensor: OK\n"; + } + } + else + { + sBuf += "\nRestarting sensor: failed\n"; + } + } + else if(cmdStr.equals("readversion") || iCmd == 9) + { + sBuf += "\nRequesting firmware version: "; + if(radar.requestFirmwareVersion()) + { + sBuf += radar.cmdFirmwareVersion(); + } + else + { + sBuf += "Failed\n"; + } + } + else if(cmdStr.equals("factoryreset") || iCmd == 10) + { + sBuf += "\nFactory resetting sensor: "; + if(radar.requestFactoryReset()) + { + sBuf += "OK, now restart sensor to take effect\n"; + } + else + { + sBuf += "failed\n"; + } + } + else if(cmdStr.equals("deviceinfo") || iCmd == 11) + { + sBuf += "\nLD2410 Device Information: \n"; + sBuf += "Data reporting mode: "; + sBuf += (radar.isEngineeringMode() ? "Engineering Mode" : "Target Mode"); + sBuf += "\nCommunication protocol version: v"; + sBuf += radar.cmdProtocolVersion(); + sBuf += ".0\nCommunications Buffer Size: "; + sBuf += radar.cmdCommunicationBufferSize(); + sBuf += " bytes\nDevice firmare version: "; + sBuf += radar.cmdFirmwareVersion(); + sBuf += "\tEngineering retain data value: "; + sBuf += radar.engRetainDataValue(); + sBuf += "\n"; + } + else if(cmdStr.equals("reboot") || iCmd == 12) + { + ESP.restart(); + } + else + { + sBuf += "\nUnknown command: "; + sBuf += cmdStr; + sBuf += "\n"; + } + + cmdStr.clear(); + sBuf += "\n choose:> "; + + return sBuf; +} + +/* + * Accepts Serial chars and process chars as a command + * when the newline char is received + */ +void commandHandler() { + if(Serial.available()) + { + char typedCharacter = Serial.read(); + if(typedCharacter == '\n') { + Serial.print( commandProcessor(command) ); + } else { + Serial.print(typedCharacter); + if(typedCharacter != '\r') { // effectively ignore CRs + command += typedCharacter; + } + } + } +} + +#ifdef SERIAL_STUDIO +/* + * Send data via UDP */ +void sendToRequestor(String str, bool requestor = false) { + if(requestor) { + udp.connect(ipRemote,remotePort); + } else { + udp.connect(ipSerialStudio,sendPort); + } + // Serial.printf("DEBUG: SizeOf(serialBuffer)=%d Length(str)=%d Contents:%s", sizeof(serialBuffer), str.length(), str.c_str()); + udp.print(str); + return udp.close(); +} +#endif + +/* + * CSV like Values for SerialStudio App - see test folder */ +// %1,2,3, 4, 5,6,7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43 +/*LD2410 Sensor 01,0,0,62,43,0,0,50,15, 0, 0,50,15, 0, 0,40, 5,40,62,30, 9,40,45,20, 3,30,25,15, 6,30,18,15, 1,20,10,15, 2,20, 8,15, 7,20, 6*/ +String buildWithAlarmSerialStudioCSV() { + pos = snprintf(serialBuffer,sizeof(serialBuffer),"/*%s,%d,%d,%d,%d,%d,%d,",SNAME,radar.stationaryTargetDistance(),radar.detectionDistance(), radar.stationaryTargetEnergy(),radar.movingTargetDistance(), radar.detectionDistance(), radar.movingTargetEnergy()); + + for(int x = 0; x < LD2410_MAX_GATES; ++x) { + pos1 = snprintf(buffer1,sizeof(buffer1),"%d,%d,%d,%d,", radar.cfgMovingGateSensitivity(x), radar.engMovingDistanceGateEnergy(x), radar.cfgStationaryGateSensitivity(x), radar.engStaticDistanceGateEnergy(x)); + strcat(serialBuffer, buffer1); + pos += pos1; + } + serialBuffer[--pos] = 0; + strcat(serialBuffer, "*/\n"); + + return String(serialBuffer); +} + +void setup(void) +{ + delay(1000); + + // start console path + Serial.begin(115200); + delay(250); + + // start path to LD2410 + // radar.debug(Serial); + Serial2.begin (256000, SERIAL_8N1, RXD2, TXD2); //UART for monitoring the radar rx, tx + +#ifdef SERIAL_STUDIO + // Start WiFi + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, ssidPassword); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.print("WiFi connected with IP: "); + Serial.println(WiFi.localIP()); + // 10.100.1.186 + + if(udp.listen(listenPort)) { + Serial.print(F("Client Listening on port: ")); + Serial.println(listenPort); + udp.onPacket([](AsyncUDPPacket packet) { + Serial.print("UDP Packet Type: "); + Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast"); + Serial.print(", From: "); + Serial.print(packet.remoteIP()); + Serial.print(":"); + Serial.print(packet.remotePort()); + Serial.print(", To: "); + Serial.print(packet.localIP()); + Serial.print(":"); + Serial.print(packet.localPort()); + Serial.print(", Length: "); + Serial.print(packet.length()); + Serial.print(", Data: "); + Serial.write(packet.data(), packet.length()); + Serial.println(); + + // save path for response when using udp + ipRemote = packet.remoteIP(); + remotePort = packet.remotePort(); + + // Parse Commands -- executing inside a callback can be problematic + // Using udpFlag to have loop handle it + command = (const char*)packet.data(); + udpFlag=true; + }); + } + + Serial.println(F("Client Initialized...")); +#endif + + // Start LD2410 Sensor + if(radar.begin(Serial2)) + { + Serial.println(F("Sensor Initialized...")); + delay(500); + radar.requestStartEngineeringMode(); + } + else + { + Serial.println(F(" Sensor was not connected")); + } + + Serial.println(F("setup() Complete...")); + Serial.println( availableCommands() ); + Serial.print("\n choose> "); +} + +void loop() +{ + radar.ld2410_loop(); + + if(sending_enabled) { + if(radar.isConnected() && millis() - lastReading > 1000) //Report every 1000ms + { + lastReading = millis(); + #ifdef SERIAL_STUDIO + sendToRequestor( buildWithAlarmSerialStudioCSV(), false ); + #else + if(Serial.available()) { + Serial.print( buildWithAlarmSerialStudioCSV() ); + } + #endif + } + } + #ifdef SERIAL_STUDIO + if(udpFlag && (command.length() > 1)) { // handle cb request + sendToRequestor(commandProcessor(command), true); + udpFlag=false; + command.clear(); + } + #endif + commandHandler(); +} diff --git a/lib/ld2410/examples/basicSensor/basicSensor.ino b/lib/ld2410/examples/basicSensor/basicSensor.ino new file mode 100644 index 0000000000..a18f022614 --- /dev/null +++ b/lib/ld2410/examples/basicSensor/basicSensor.ino @@ -0,0 +1,120 @@ +/* + * Example sketch for reporting on readings from the LD2410 using whatever settings are currently configured. + * + * This has been tested on the following platforms... + * + * On ESP32, connect the LD2410 to GPIO pins 32&33 + * On ESP32S2, connect the LD2410 to GPIO pins 8&9 + * On ESP32C3, connect the LD2410 to GPIO pins 4&5 + * On Arduino Leonardo or other ATmega32u4 board connect the LD2410 to GPIO pins TX & RX hardware serial + * + * The serial configuration for other boards will vary and you'll need to assign them yourself + * + * There is no example for ESP8266 as it only has one usable UART and will not boot if the alternate UART pins are used for the radar. + * + * For this sketch and other examples to be useful the board needs to have two usable UARTs. + * + */ + +#if defined(ESP32) + #ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 32 + #define RADAR_TX_PIN 33 + #elif CONFIG_IDF_TARGET_ESP32S2 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 9 + #define RADAR_TX_PIN 8 + #elif CONFIG_IDF_TARGET_ESP32C3 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 4 + #define RADAR_TX_PIN 5 + #else + #error Target CONFIG_IDF_TARGET is not supported + #endif + #else // ESP32 Before IDF 4.0 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 32 + #define RADAR_TX_PIN 33 + #endif +#elif defined(__AVR_ATmega32U4__) + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 0 + #define RADAR_TX_PIN 1 +#endif + +#include + +ld2410 radar; + +uint32_t lastReading = 0; +bool radarConnected = false; + +void setup(void) +{ + MONITOR_SERIAL.begin(115200); //Feedback over Serial Monitor + //radar.debug(MONITOR_SERIAL); //Uncomment to show debug information from the library on the Serial Monitor. By default this does not show sensor reads as they are very frequent. + #if defined(ESP32) + RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); //UART for monitoring the radar + #elif defined(__AVR_ATmega32U4__) + RADAR_SERIAL.begin(256000); //UART for monitoring the radar + #endif + delay(500); + MONITOR_SERIAL.print(F("\nConnect LD2410 radar TX to GPIO:")); + MONITOR_SERIAL.println(RADAR_RX_PIN); + MONITOR_SERIAL.print(F("Connect LD2410 radar RX to GPIO:")); + MONITOR_SERIAL.println(RADAR_TX_PIN); + MONITOR_SERIAL.print(F("LD2410 radar sensor initialising: ")); + if(radar.begin(RADAR_SERIAL)) + { + MONITOR_SERIAL.println(F("OK")); + MONITOR_SERIAL.print(F("LD2410 firmware version: ")); + MONITOR_SERIAL.print(radar.firmware_major_version); + MONITOR_SERIAL.print('.'); + MONITOR_SERIAL.print(radar.firmware_minor_version); + MONITOR_SERIAL.print('.'); + MONITOR_SERIAL.println(radar.firmware_bugfix_version, HEX); + } + else + { + MONITOR_SERIAL.println(F("not connected")); + } +} + +void loop() +{ + radar.read(); + if(radar.isConnected() && millis() - lastReading > 1000) //Report every 1000ms + { + lastReading = millis(); + if(radar.presenceDetected()) + { + if(radar.stationaryTargetDetected()) + { + Serial.print(F("Stationary target: ")); + Serial.print(radar.stationaryTargetDistance()); + Serial.print(F("cm energy:")); + Serial.print(radar.stationaryTargetEnergy()); + Serial.print(' '); + } + if(radar.movingTargetDetected()) + { + Serial.print(F("Moving target: ")); + Serial.print(radar.movingTargetDistance()); + Serial.print(F("cm energy:")); + Serial.print(radar.movingTargetEnergy()); + } + Serial.println(); + } + else + { + Serial.println(F("No target")); + } + } +} diff --git a/lib/ld2410/examples/setupSensor/setupSensor.ino b/lib/ld2410/examples/setupSensor/setupSensor.ino new file mode 100644 index 0000000000..2f9073de0d --- /dev/null +++ b/lib/ld2410/examples/setupSensor/setupSensor.ino @@ -0,0 +1,330 @@ +/* + * Example sketch to show using configuration commands on the LD2410. + * + * This has been tested on the following platforms... + * + * On ESP32, connect the LD2410 to GPIO pins 32&33 + * On ESP32S2, connect the LD2410 to GPIO pins 8&9 + * On ESP32C3, connect the LD2410 to GPIO pins 4&5 + * On Arduino Leonardo or other ATmega32u4 board connect the LD2410 to GPIO pins TX & RX hardware serial + * + * The serial configuration for other boards will vary and you'll need to assign them yourself + * + * There is no example for ESP8266 as it only has one usable UART and will not boot if the alternate UART pins are used for the radar. + * + * For this sketch and other examples to be useful the board needs to have two usable UARTs. + * + */ + +#if defined(ESP32) + #ifdef ESP_IDF_VERSION_MAJOR // IDF 4+ + #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 32 + #define RADAR_TX_PIN 33 + #elif CONFIG_IDF_TARGET_ESP32S2 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 9 + #define RADAR_TX_PIN 8 + #elif CONFIG_IDF_TARGET_ESP32C3 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 4 + #define RADAR_TX_PIN 5 + #else + #error Target CONFIG_IDF_TARGET is not supported + #endif + #else // ESP32 Before IDF 4.0 + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 32 + #define RADAR_TX_PIN 33 + #endif +#elif defined(__AVR_ATmega32U4__) + #define MONITOR_SERIAL Serial + #define RADAR_SERIAL Serial1 + #define RADAR_RX_PIN 0 + #define RADAR_TX_PIN 1 +#endif + +#include + +ld2410 radar; +bool engineeringMode = false; +String command; + +void setup(void) +{ + MONITOR_SERIAL.begin(115200); //Feedback over Serial Monitor + delay(500); //Give a while for Serial Monitor to wake up + //radar.debug(Serial); //Uncomment to show debug information from the library on the Serial Monitor. By default this does not show sensor reads as they are very frequent. + #if defined(ESP32) + RADAR_SERIAL.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); //UART for monitoring the radar + #elif defined(__AVR_ATmega32U4__) + RADAR_SERIAL.begin(256000); //UART for monitoring the radar + #endif + delay(500); + MONITOR_SERIAL.print(F("\nConnect LD2410 radar TX to GPIO:")); + MONITOR_SERIAL.println(RADAR_RX_PIN); + MONITOR_SERIAL.print(F("Connect LD2410 radar RX to GPIO:")); + MONITOR_SERIAL.println(RADAR_TX_PIN); + MONITOR_SERIAL.print(F("LD2410 radar sensor initialising: ")); + if(radar.begin(RADAR_SERIAL)) + { + MONITOR_SERIAL.println(F("OK")); + MONITOR_SERIAL.print(F("LD2410 firmware version: ")); + MONITOR_SERIAL.print(radar.firmware_major_version); + MONITOR_SERIAL.print('.'); + MONITOR_SERIAL.print(radar.firmware_minor_version); + MONITOR_SERIAL.print('.'); + MONITOR_SERIAL.println(radar.firmware_bugfix_version, HEX); + } + else + { + MONITOR_SERIAL.println(F("not connected")); + } + MONITOR_SERIAL.println(F("Supported commands\nread: read current values from the sensor\nreadconfig: read the configuration from the sensor\nsetmaxvalues \nsetsensitivity \nenableengineeringmode: enable engineering mode\ndisableengineeringmode: disable engineering mode\nrestart: restart the sensor\nreadversion: read firmware version\nfactoryreset: factory reset the sensor\n")); +} + +void loop() +{ + radar.read(); //Always read frames from the sensor + if(MONITOR_SERIAL.available()) + { + char typedCharacter = MONITOR_SERIAL.read(); + if(typedCharacter == '\r' || typedCharacter == '\n') + { + command.trim(); + if(command.equals("read")) + { + command = ""; + MONITOR_SERIAL.print(F("Reading from sensor: ")); + if(radar.isConnected()) + { + MONITOR_SERIAL.println(F("OK")); + if(radar.presenceDetected()) + { + if(radar.stationaryTargetDetected()) + { + MONITOR_SERIAL.print(F("Stationary target: ")); + MONITOR_SERIAL.print(radar.stationaryTargetDistance()); + MONITOR_SERIAL.print(F("cm energy: ")); + MONITOR_SERIAL.println(radar.stationaryTargetEnergy()); + } + if(radar.movingTargetDetected()) + { + MONITOR_SERIAL.print(F("Moving target: ")); + MONITOR_SERIAL.print(radar.movingTargetDistance()); + MONITOR_SERIAL.print(F("cm energy: ")); + MONITOR_SERIAL.println(radar.movingTargetEnergy()); + } + } + else + { + MONITOR_SERIAL.println(F("nothing detected")); + } + } + else + { + MONITOR_SERIAL.println(F("failed to read")); + } + } + else if(command.equals("readconfig")) + { + command = ""; + MONITOR_SERIAL.print(F("Reading configuration from sensor: ")); + if(radar.requestCurrentConfiguration()) + { + MONITOR_SERIAL.println(F("OK")); + MONITOR_SERIAL.print(F("Maximum gate ID: ")); + MONITOR_SERIAL.println(radar.max_gate); + MONITOR_SERIAL.print(F("Maximum gate for moving targets: ")); + MONITOR_SERIAL.println(radar.max_moving_gate); + MONITOR_SERIAL.print(F("Maximum gate for stationary targets: ")); + MONITOR_SERIAL.println(radar.max_stationary_gate); + MONITOR_SERIAL.print(F("Idle time for targets: ")); + MONITOR_SERIAL.println(radar.sensor_idle_time); + MONITOR_SERIAL.println(F("Gate sensitivity")); + for(uint8_t gate = 0; gate <= radar.max_gate; gate++) + { + MONITOR_SERIAL.print(F("Gate ")); + MONITOR_SERIAL.print(gate); + MONITOR_SERIAL.print(F(" moving targets: ")); + MONITOR_SERIAL.print(radar.motion_sensitivity[gate]); + MONITOR_SERIAL.print(F(" stationary targets: ")); + MONITOR_SERIAL.println(radar.stationary_sensitivity[gate]); + } + } + else + { + MONITOR_SERIAL.println(F("Failed")); + } + } + else if(command.startsWith("setmaxvalues")) + { + uint8_t firstSpace = command.indexOf(' '); + uint8_t secondSpace = command.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = command.indexOf(' ',secondSpace + 1); + uint8_t newMovingMaxDistance = (command.substring(firstSpace,secondSpace)).toInt(); + uint8_t newStationaryMaxDistance = (command.substring(secondSpace,thirdSpace)).toInt(); + uint16_t inactivityTimer = (command.substring(thirdSpace,command.length())).toInt(); + if(newMovingMaxDistance > 0 && newStationaryMaxDistance > 0 && newMovingMaxDistance <= 8 && newStationaryMaxDistance <= 8) + { + MONITOR_SERIAL.print(F("Setting max values to gate ")); + MONITOR_SERIAL.print(newMovingMaxDistance); + MONITOR_SERIAL.print(F(" moving targets, gate ")); + MONITOR_SERIAL.print(newStationaryMaxDistance); + MONITOR_SERIAL.print(F(" stationary targets, ")); + MONITOR_SERIAL.print(inactivityTimer); + MONITOR_SERIAL.print(F("s inactivity timer: ")); + command = ""; + if(radar.setMaxValues(newMovingMaxDistance, newStationaryMaxDistance, inactivityTimer)) + { + MONITOR_SERIAL.println(F("OK, now restart to apply settings")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else + { + MONITOR_SERIAL.print(F("Can't set distances to ")); + MONITOR_SERIAL.print(newMovingMaxDistance); + MONITOR_SERIAL.print(F(" moving ")); + MONITOR_SERIAL.print(newStationaryMaxDistance); + MONITOR_SERIAL.println(F(" stationary, try again")); + command = ""; + } + } + else if(command.startsWith("setsensitivity")) + { + uint8_t firstSpace = command.indexOf(' '); + uint8_t secondSpace = command.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = command.indexOf(' ',secondSpace + 1); + uint8_t gate = (command.substring(firstSpace,secondSpace)).toInt(); + uint8_t motionSensitivity = (command.substring(secondSpace,thirdSpace)).toInt(); + uint8_t stationarySensitivity = (command.substring(thirdSpace,command.length())).toInt(); + if(motionSensitivity >= 0 && stationarySensitivity >= 0 && motionSensitivity <= 100 && stationarySensitivity <= 100) + { + MONITOR_SERIAL.print(F("Setting gate ")); + MONITOR_SERIAL.print(gate); + MONITOR_SERIAL.print(F(" motion sensitivity to ")); + MONITOR_SERIAL.print(motionSensitivity); + MONITOR_SERIAL.print(F(" & stationary sensitivity to ")); + MONITOR_SERIAL.print(stationarySensitivity); + MONITOR_SERIAL.println(F(": ")); + command = ""; + if(radar.setGateSensitivityThreshold(gate, motionSensitivity, stationarySensitivity)) + { + MONITOR_SERIAL.println(F("OK, now restart to apply settings")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else + { + MONITOR_SERIAL.print(F("Can't set gate ")); + MONITOR_SERIAL.print(gate); + MONITOR_SERIAL.print(F(" motion sensitivity to ")); + MONITOR_SERIAL.print(motionSensitivity); + MONITOR_SERIAL.print(F(" & stationary sensitivity to ")); + MONITOR_SERIAL.print(stationarySensitivity); + MONITOR_SERIAL.println(F(", try again")); + command = ""; + } + } + else if(command.equals("enableengineeringmode")) + { + command = ""; + MONITOR_SERIAL.print(F("Enabling engineering mode: ")); + if(radar.requestStartEngineeringMode()) + { + MONITOR_SERIAL.println(F("OK")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else if(command.equals("disableengineeringmode")) + { + command = ""; + MONITOR_SERIAL.print(F("Disabling engineering mode: ")); + if(radar.requestEndEngineeringMode()) + { + MONITOR_SERIAL.println(F("OK")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else if(command.equals("restart")) + { + command = ""; + MONITOR_SERIAL.print(F("Restarting sensor: ")); + if(radar.requestRestart()) + { + MONITOR_SERIAL.println(F("OK")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else if(command.equals("readversion")) + { + command = ""; + MONITOR_SERIAL.print(F("Requesting firmware version: ")); + if(radar.requestFirmwareVersion()) + { + Serial.print(radar.cmdFirmwareVersion()); + } + else + { + MONITOR_SERIAL.println(F("Failed")); + } + } + else if(command.equals("factoryreset")) + { + command = ""; + MONITOR_SERIAL.print(F("Factory resetting sensor: ")); + if(radar.requestFactoryReset()) + { + MONITOR_SERIAL.println(F("OK, now restart sensor to take effect")); + } + else + { + MONITOR_SERIAL.println(F("failed")); + } + } + else + { + MONITOR_SERIAL.print(F("Unknown command: ")); + MONITOR_SERIAL.println(command); + command = ""; + } + } + else + { + command += typedCharacter; + } + } + /* + if() //Some data has been received from the radar + { + if(radar.presenceDetected()) + { + MONITOR_SERIAL.print(F("Stationary target: ")); + MONITOR_SERIAL.println(radar.stationaryTargetDistance()); + MONITOR_SERIAL.print(F("Moving target: ")); + MONITOR_SERIAL.println(radar.movingTargetDistance()); + } + } + */ +} diff --git a/lib/ld2410/include/README b/lib/ld2410/include/README new file mode 100644 index 0000000000..194dcd4325 --- /dev/null +++ b/lib/ld2410/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/ld2410/keywords.txt b/lib/ld2410/keywords.txt new file mode 100644 index 0000000000..f78235c7d2 --- /dev/null +++ b/lib/ld2410/keywords.txt @@ -0,0 +1,50 @@ +ld2410 KEYWORD1 + +begin KEYWORD2 +debug KEYWORD2 +isConnected KEYWORD2 +read KEYWORD2 +presenceDetected KEYWORD2 + +ld2410_loop KEYWORD2 +isStationary KEYWORD2 +isMoving KEYWORD2 +isEngineeringMode KEYWORD2 +reportingDataComposition KEYWORD2 +detectionDistance KEYWORD2 + +stationaryTargetDetected KEYWORD2 +stationaryTargetDistance KEYWORD2 +stationaryTargetEnergy KEYWORD2 + +movingTargetDetected KEYWORD2 +movingTargetDistance KEYWORD2 +movingTargetEnergy KEYWORD2 + +engMovingDistanceGateEnergy KEYWORD2 +engStaticDistanceGateEnergy KEYWORD2 +engMaxMovingDistanceGate KEYWORD2 +engMaxStaticDistanceGate KEYWORD2 +engRetainDataValue KEYWORD2 + +requestRestart KEYWORD2 +requestFactoryReset KEYWORD2 +requestFirmwareVersion +requestCurrentConfiguration +requestStartEngineeringMode KEYWORD2 +requestEndEngineeringMode KEYWORD2 +setSerialBaudRate KEYWORD2 +setMaxValues KEYWORD2 +setGateSensitivityThreshold KEYWORD2 +requestConfigurationModeOpen KEYWORD2 +requestConfigurationModeClose KEYWORD2 + +cmdProtocolVersion KEYWORD2 +cmdFirmwareVersion KEYWORD2 + +cfgMaxGate KEYWORD2 +cfgMaxMovingGate KEYWORD2 +cfgMaxStationaryGate KEYWORD2 +cfgSensorIdleTimeInSeconds KEYWORD2 +cfgMovingGateSensitivity KEYWORD2 +cfgStationaryGateSensitivity KEYWORD2 diff --git a/lib/ld2410/ld2410andbreakout.jpg b/lib/ld2410/ld2410andbreakout.jpg new file mode 100644 index 0000000000..495617aaad Binary files /dev/null and b/lib/ld2410/ld2410andbreakout.jpg differ diff --git a/lib/ld2410/ld2410pcb.jpg b/lib/ld2410/ld2410pcb.jpg new file mode 100644 index 0000000000..df40c01a39 Binary files /dev/null and b/lib/ld2410/ld2410pcb.jpg differ diff --git a/lib/ld2410/ld2410pinout.jpg b/lib/ld2410/ld2410pinout.jpg new file mode 100644 index 0000000000..c573f882d0 Binary files /dev/null and b/lib/ld2410/ld2410pinout.jpg differ diff --git a/lib/ld2410/lib/README b/lib/ld2410/lib/README new file mode 100644 index 0000000000..6debab1e8b --- /dev/null +++ b/lib/ld2410/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/ld2410/library.properties b/lib/ld2410/library.properties new file mode 100644 index 0000000000..aba11498ea --- /dev/null +++ b/lib/ld2410/library.properties @@ -0,0 +1,11 @@ +name=ld2410 +version=0.1.3 +author=Nick Reynolds +maintainer=Nick Reynolds +sentence=An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. +paragraph= This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. +category=Sensors +url=https://github.com/ncmreynolds/ld2410 +depends= +includes=ld2410.h +architectures=* \ No newline at end of file diff --git a/lib/ld2410/platformio.ini b/lib/ld2410/platformio.ini new file mode 100644 index 0000000000..f9d52b4235 --- /dev/null +++ b/lib/ld2410/platformio.ini @@ -0,0 +1,32 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = examples/ +lib_dir = . + + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +board_build.mcu = esp32 +board_build.f_cpu = 240000000L +upload_speed = 921600 +monitor_speed = 256000 +monitor_encoding = hexlify +monitor_filters = log2file,time,esp32_exception_decoder + +build_flags = + -D PLATFORMIO_BUILD_FLAGS + -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY +; -D PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH + -DWIFI_PASS='"BeveilgdMetWpa"' + -DWIFI_SSID='"Kantoor3"' diff --git a/lib/ld2410/src/ld2410.cpp b/lib/ld2410/src/ld2410.cpp new file mode 100644 index 0000000000..ffd987da38 --- /dev/null +++ b/lib/ld2410/src/ld2410.cpp @@ -0,0 +1,1139 @@ +/* + * An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. + * + * This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different + *ranges to both static and moving targets can be configured. + * + * The code in this library is based off the manufacturer datasheet and reading of this initial piece of work for ESPHome + *https://github.com/rain931215/ESPHome-LD2410. + * + * https://github.com/ncmreynolds/ld2410 + * + * Released under LGPL-2.1 see https://github.com/ncmreynolds/ld2410/LICENSE for full license + * + */ +#ifndef ld2410_cpp +#define ld2410_cpp +#include "ld2410.h" + + +ld2410::ld2410() // Constructor function +{} + +ld2410::~ld2410() // Destructor function +{} + +uint16_t ld2410::serial_to_int_(uint8_t index) +{ + return (int16_t)radar_data_frame_[index] + (radar_data_frame_[index + 1] << 8); +} + +bool ld2410::debug_command_results_(const char *title) { + if (latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG_PRINT) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print("\n"); + debug_uart_->print(title); + debug_uart_->print(" OK\n"); + } + #endif // if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG_PRINT) && defined(LD2410_DEBUG) + return true; + } + else + { + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + debug_uart_->print("\n"); + debug_uart_->print(title); + debug_uart_->print(" Failed\n"); + } + #endif // ifdef LD2410_DEBUG + return false; + } +} + +bool ld2410::wait_for_command_ack_(uint8_t command) { + while (millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if (read_frame_()) + { + if (latest_ack_ == command) + { + bool rcode = latest_command_success_; + delay(50); + leave_configuration_mode_(); + return rcode; + } + } + } + return false; +} + +bool ld2410::begin(Stream& radarStream, bool waitForRadar) { + radar_uart_ = &radarStream; // Set the stream used for the LD2410 + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + debug_uart_->println(F("ld2410 started")); + } + #endif // ifdef LD2410_DEBUG + + if (waitForRadar) + { + if (requestRestart()) { + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) { + debug_uart_->print(F("\nLD2410 Reset: Ok")); + } + } else { + if (debug_uart_ != nullptr) { + debug_uart_->print(F("\nLD2410 Reset: No response")); + } + #endif // ifdef LD2410_DEBUG + } + delay(1500); // allow time for sensor to restart + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 Requesting Configuration: ")); + } + #endif // ifdef LD2410_DEBUG + + if (requestCurrentConfiguration()) + { + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nMax gate distance: ")); + debug_uart_->print(max_gate); + debug_uart_->print(F("\nMax motion detecting gate distance: ")); + debug_uart_->print(max_moving_gate); + debug_uart_->print(F("\nMax stationary detecting gate distance: ")); + debug_uart_->print(max_stationary_gate); + debug_uart_->print(F("\nSensitivity per gate")); + + for (uint8_t i = 0; i < sizeof(stationary_sensitivity); ++i) + { + debug_uart_->print(F("\nGate ")); + debug_uart_->print(i); + debug_uart_->print(F(" (")); + debug_uart_->print(i * 0.75); + debug_uart_->print('-'); + debug_uart_->print((i + 1) * 0.75); + debug_uart_->print(F(" metres) Motion: ")); + debug_uart_->print(motion_sensitivity[i]); + debug_uart_->print(F(" Stationary: ")); + debug_uart_->print(stationary_sensitivity[i]); + } + debug_uart_->print(F("\nSensor idle timeout: ")); + debug_uart_->print(sensor_idle_time); + debug_uart_->println('s'); + } + #endif // ifdef LD2410_DEBUG + return true; + } + #ifdef LD2410_DEBUG + else + { + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("no response")); + } + } + #endif // ifdef LD2410_DEBUG + } + else + { + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 library configured")); + } + #endif // ifdef LD2410_DEBUG + return true; + } + return false; +} + +#ifdef LD2410_DEBUG +void ld2410::debug(Stream& terminalStream) +{ + debug_uart_ = &terminalStream; // Set the stream used for the terminal + # if defined(ESP8266) + + if (&terminalStream == &Serial) + { + if (debug_uart_ != nullptr) { + debug_uart_->write(17); // Send an XON to stop the hung terminal after reset on ESP8266 + } + } + # endif // if defined(ESP8266) +} + +#endif // ifdef LD2410_DEBUG + +bool ld2410::isConnected() +{ + if (millis() - radar_uart_last_packet_ < radar_uart_timeout) // Use the last reading + { + return true; + } + return read_frame_(); // Try and read a frame if the current reading is too old +} + +bool ld2410::stationaryTargetDetected() +{ + return (target_type_ & TARGET_STATIONARY); +} + +bool ld2410::movingTargetDetected() +{ + return (target_type_ & TARGET_MOVING); +} + +String ld2410::cmdFirmwareVersion() { + String sVersion; + + sVersion = 'v'; + sVersion += firmware_major_version; + sVersion += '.'; + sVersion += firmware_minor_version; + sVersion += '.'; + sVersion += String(firmware_bugfix_version, HEX); + + return sVersion; +} + +/* Command / Response / Protocol Frame + * + * REQUEST + * FD FC FB FA -- Header + * dd dd -- Frame data length + * dd dd -- Command Word + * ... -- Command Value nBytes + * 04 03 02 01 -- Footer + * + * RESPONSE + * FD FC FB FA -- Header + * dd dd -- Frame data length + * dd dd -- ACK Word + * ... -- Response Values nBytes + * 04 03 02 01 -- Footer + */ +bool ld2410::isProtocolDataFrame_() { + return radar_data_frame_[0] == FRAME_PREFIX_PROTOCOL && + radar_data_frame_[1] == 0xFC && + radar_data_frame_[2] == 0xFB && + radar_data_frame_[3] == 0xFA && + radar_data_frame_[radar_data_frame_position_ - 4] == 0x04 && + radar_data_frame_[radar_data_frame_position_ - 3] == 0x03 && + radar_data_frame_[radar_data_frame_position_ - 2] == 0x02 && + radar_data_frame_[radar_data_frame_position_ - 1] == 0x01 + ; +} + +/* Data Frame + * + * F4 F3 F2 F1 -- header + * dd dd -- frame data length + * dd -- Type of Data (0x01=Engineering data, 0x02=Target data) + * 0xAA -- Marker + * ... -- target state + * ... -- reporting data + * 0x55 -- Marker + * 0x00 -- Check flag + * F8 F7 F6 F5 - Footer + */ +bool ld2410::isReportingDataFrame_() { + return radar_data_frame_[0] == FRAME_PREFIX_REPORTING && + radar_data_frame_[1] == 0xF3 && + radar_data_frame_[2] == 0xF2 && + radar_data_frame_[3] == 0xF1 && + radar_data_frame_[radar_data_frame_position_ - 4] == 0xF8 && + radar_data_frame_[radar_data_frame_position_ - 3] == 0xF7 && + radar_data_frame_[radar_data_frame_position_ - 2] == 0xF6 && + radar_data_frame_[radar_data_frame_position_ - 1] == 0xF5 + ; +} + +bool ld2410::read_frame_() +{ + if (!radar_uart_->available()) + { + return false; + } + const uint32_t _started = millis(); + int _available = radar_uart_->available(); + + while (_available && (millis() - _started < SERIAL_RECEIVE_MAX_MS)) { // Read for max. N msec + delay(0); + + if (frame_started_ == false) + { + uint8_t byte_read_ = radar_uart_->read(); + --_available; // 1 down + + if (byte_read_ == FRAME_PREFIX_REPORTING) + { + radar_data_frame_[radar_data_frame_position_++] = byte_read_; + frame_started_ = true; + ack_frame_ = false; + } + else if (byte_read_ == FRAME_PREFIX_PROTOCOL) + { + radar_data_frame_[radar_data_frame_position_++] = byte_read_; + frame_started_ = true; + ack_frame_ = true; + } + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nRcvd : 00 ")); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + } + else + { + if (radar_data_frame_position_ < configuration_buffer_size_) + { + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + if (radar_data_frame_position_ < 0x10) + { + debug_uart_->print('0'); + } + debug_uart_->print(radar_data_frame_position_, HEX); + debug_uart_->print(' '); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + radar_data_frame_[radar_data_frame_position_++] = radar_uart_->read(); + --_available; // 1 more down + + if (radar_data_frame_position_ > 7) // Can check for start and end + { + if (isReportingDataFrame_()) + { + if (parse_data_frame_()) + { + #if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F(" parsed data OK")); + } + #endif // if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + frame_started_ = false; + radar_data_frame_position_ = 0; + return true; + } + else + { + #if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F(" failed to parse data")); + } + #endif // if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + frame_started_ = false; + radar_data_frame_position_ = 0; + _errorCount++; + } + } + else if (isProtocolDataFrame_()) + { + if (parse_command_frame_()) + { + #if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F(" parsed command OK")); + } + #endif // if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + frame_started_ = false; + radar_data_frame_position_ = 0; + return true; + } + else + { + #if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F(" failed to parse command")); + } + #endif // if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + frame_started_ = false; + radar_data_frame_position_ = 0; + _errorCount++; + } + } + } + } + else + { + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && \ + defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 frame overran")); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && defined(LD2410_DEBUG) + frame_started_ = false; + radar_data_frame_position_ = 0; + _errorCount++; + } + } + + if (!_available && (millis() - _started < SERIAL_RECEIVE_GRACE_MS)) { // Data handled and time left? Read some more + _available = radar_uart_->available(); + } + } + return false; +} + +uint16_t ld2410::getErrorCountAndReset() { + uint16_t result = _errorCount; + + _errorCount = 0; + return result; +} + +void ld2410::print_frame_() +{ + #ifdef LD2410_DEBUG + + if (debug_uart_ != nullptr) + { + if (ack_frame_ == true) + { + debug_uart_->print(F("\nCmnd : ")); + } + else + { + debug_uart_->print(F("\nData : ")); + } + + for (uint8_t i = 0; i < radar_data_frame_position_; ++i) + { + if (radar_data_frame_[i] < 0x10) + { + debug_uart_->print('0'); + } + debug_uart_->print(radar_data_frame_[i], HEX); + debug_uart_->print(' '); + } + } + #endif // ifdef LD2410_DEBUG +} + +bool ld2410::parse_data_frame_() +{ + uint16_t intra_frame_data_length_ = serial_to_int_(4); // radar_data_frame_[4] + (radar_data_frame_[5] << 8); + + if (radar_data_frame_position_ != intra_frame_data_length_ + 10) + { + #if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nFrame length unexpected: ")); + debug_uart_->print(radar_data_frame_position_); + debug_uart_->print(F(" not ")); + debug_uart_->print(intra_frame_data_length_ + 10); + } + #endif // if defined(LD2410_DEBUG_DATA) && defined(LD2410_DEBUG) + _errorCount++; + return false; + } + + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + print_frame_(); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS)) && defined(LD2410_DEBUG) + data_ready_ = false; + + if ((radar_data_frame_[6] == FRAME_TYPE_REPORTING) && (radar_data_frame_[7] == FRAME_TYPE_FLAG)) // Engineering mode data + { + /* (Protocol) Target Data Reporting + * 02 AA d6,7 data type (target data) + * 02 d8 target type (stationary target) + * 51 00 d9,10 stationary target distance + * 00 d11 stationary target energy + * 00 00 d12,13 moving target distance + * 3B d14 moving target energy + * 00 00 d15,16 distance detection + + Engineering + * 08 d17 Max moving distance gate + * 08 d18 Max static distance gate + * 3C 22 05 03 03 04 03 06 05 d19,27 Movement distance gate energy + * 00 00 39 10 13 06 06 08 04 d28,36 Static distance gate energy + * 03 05 d37,d38 ?? v1283 d37 = lightsensor data, d38 = out pin sensor + * 55 00 d39,40 Frame flag + */ + engineering_mode_ = true; + target_type_ = radar_data_frame_[8]; + moving_target_distance_ = serial_to_int_(9); + moving_target_energy_ = radar_data_frame_[11]; + stationary_target_distance_ = serial_to_int_(12); + stationary_target_energy_ = radar_data_frame_[14]; + detection_distance_ = serial_to_int_(15); + + max_moving_distance_gate = radar_data_frame_[17]; + max_static_distance_gate = radar_data_frame_[18]; + light_sensor_data_ = radar_data_frame_[37]; + output_pin_data_ = radar_data_frame_[38]; + + uint8_t pos = 19; + + // motion_energy + for (uint8_t gate = 0; gate < sizeof(movement_distance_gate_energy); ++gate) { + movement_distance_gate_energy[gate] = radar_data_frame_[pos++]; + } + + // stationary_engergy + for (uint8_t gate = 0; gate < sizeof(static_distance_gate_engergy); ++gate) { + static_distance_gate_engergy[gate] = radar_data_frame_[pos++]; + } + engineering_retain_data_ = serial_to_int_(pos); // radar_data_frame_[pos++] + (radar_data_frame_[pos] << 8); // maybe + + #if defined(LD2410_DEBUG_PARSE) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nEngineering data - ")); + + if (target_type_ == TARGET_NONE) + { + debug_uart_->print(F(" no target")); + } + else if (target_type_ == TARGET_MOVING) + { + debug_uart_->print(F(" moving target:")); + } + else if (target_type_ == TARGET_STATIONARY) + { + debug_uart_->print(F(" stationary target:")); + } + else if (target_type_ == TARGET_MOVING_AND_STATIONARY) + { + debug_uart_->print(F(" moving & stationary targets:")); + } + debug_uart_->print(F(" moving at ")); + debug_uart_->print(moving_target_distance_); + debug_uart_->print(F("cm power ")); + debug_uart_->print(moving_target_energy_); + + debug_uart_->print(F(" max moving distance gate:")); + debug_uart_->print(max_moving_distance_gate); + debug_uart_->print(F(" max static distance gate:")); + debug_uart_->print(max_static_distance_gate); + debug_uart_->print(F(" moving/static distance gate energy: ")); + + for (uint8_t gate = 0; gate < sizeof(movement_distance_gate_energy); ++gate) { + debug_uart_->print(gate); + debug_uart_->print(": ["); + debug_uart_->print(movement_distance_gate_energy[gate]); + debug_uart_->print(","); + debug_uart_->print(static_distance_gate_engergy[gate]); + debug_uart_->print("] "); + } + debug_uart_->print("\n"); + } + #endif // if defined(LD2410_DEBUG_PARSE) && defined(LD2410_DEBUG) + + radar_uart_last_packet_ = millis(); + data_ready_ = true; + return true; + } + else if ((radar_data_frame_[6] == FRAME_TYPE_TARGET) && (radar_data_frame_[7] == FRAME_TYPE_FLAG)) // Normal target data + { + // moving_target_distance_ = radar_data_frame_[9] + (radar_data_frame_[10] << 8); + // stationary_target_distance_ = radar_data_frame_[12] + (radar_data_frame_[13] << 8); + engineering_mode_ = false; + target_type_ = radar_data_frame_[8]; + moving_target_distance_ = serial_to_int_(9); + moving_target_energy_ = radar_data_frame_[11]; + stationary_target_distance_ = serial_to_int_(12); + stationary_target_energy_ = radar_data_frame_[14]; + detection_distance_ = serial_to_int_(15); + #if defined(LD2410_DEBUG_PARSE) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nNormal data - ")); + + if (target_type_ == TARGET_NONE) + { + debug_uart_->print(F(" no target")); + } + else if (target_type_ == TARGET_MOVING) + { + debug_uart_->print(F(" moving target:")); + } + else if (target_type_ == TARGET_STATIONARY) + { + debug_uart_->print(F(" stationary target:")); + } + else if (target_type_ == TARGET_MOVING_AND_STATIONARY) + { + debug_uart_->print(F(" moving & stationary targets:")); + } + + if (radar_data_frame_[8] & TARGET_MOVING) + { + debug_uart_->print(F(" moving at ")); + debug_uart_->print(moving_target_distance_); + debug_uart_->print(F("cm power ")); + debug_uart_->print(moving_target_energy_); + } + + if (radar_data_frame_[8] & TARGET_STATIONARY) + { + debug_uart_->print(F(" stationary at ")); + debug_uart_->print(stationary_target_distance_); + debug_uart_->print(F("cm power ")); + debug_uart_->print(stationary_target_energy_); + } + } + #endif // if defined(LD2410_DEBUG_PARSE) && defined(LD2410_DEBUG) + radar_uart_last_packet_ = millis(); + data_ready_ = true; + return true; + } + else + { + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nUnknown frame type")); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && + // defined(LD2410_DEBUG) + _errorCount++; + print_frame_(); + } + + return false; +} + +bool ld2410::parse_command_frame_() +{ + uint16_t intra_frame_data_length_ = serial_to_int_(4); // radar_data_frame_[4] + (radar_data_frame_[5] << 8); + + #if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + print_frame_(); + debug_uart_->print(F("\nACK frame payload: ")); + debug_uart_->print(intra_frame_data_length_); + debug_uart_->print(F(" bytes")); + } + #endif // if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + latest_ack_ = radar_data_frame_[6]; + latest_command_success_ = (radar_data_frame_[8] == 0x00 && radar_data_frame_[9] == 0x00); + + switch (latest_ack_) + { + case CMD_CONFIGURATION_ENABLE: + + if (latest_command_success_) + { + configuration_protocol_version_ = serial_to_int_(10); // radar_data_frame_[10] + (radar_data_frame_[11] << 8); + configuration_buffer_size_ = serial_to_int_(12); // radar_data_frame_[12] + (radar_data_frame_[13] << 8); + } + return debug_command_results_("ACK for entering configuration mode"); + case CMD_CONFIGURATION_END: + return debug_command_results_("ACK for leaving configuration mode"); + case CMD_MAX_DISTANCE_AND_UNMANNED_DURATION: + return debug_command_results_("ACK for setting max values"); + case CMD_READ_PARAMETER: + + if (latest_command_success_) + { + max_gate = radar_data_frame_[11]; + max_moving_gate = radar_data_frame_[12]; + max_stationary_gate = radar_data_frame_[13]; + motion_sensitivity[0] = radar_data_frame_[14]; + motion_sensitivity[1] = radar_data_frame_[15]; + motion_sensitivity[2] = radar_data_frame_[16]; + motion_sensitivity[3] = radar_data_frame_[17]; + motion_sensitivity[4] = radar_data_frame_[18]; + motion_sensitivity[5] = radar_data_frame_[19]; + motion_sensitivity[6] = radar_data_frame_[20]; + motion_sensitivity[7] = radar_data_frame_[21]; + motion_sensitivity[8] = radar_data_frame_[22]; + stationary_sensitivity[0] = radar_data_frame_[23]; + stationary_sensitivity[1] = radar_data_frame_[24]; + stationary_sensitivity[2] = radar_data_frame_[25]; + stationary_sensitivity[3] = radar_data_frame_[26]; + stationary_sensitivity[4] = radar_data_frame_[27]; + stationary_sensitivity[5] = radar_data_frame_[28]; + stationary_sensitivity[6] = radar_data_frame_[29]; + stationary_sensitivity[7] = radar_data_frame_[30]; + stationary_sensitivity[8] = radar_data_frame_[31]; + sensor_idle_time = serial_to_int_(32); // radar_data_frame_[32]; + #if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nMax gate distance: ")); + debug_uart_->print(max_gate); + debug_uart_->print(F("\nMax motion detecting gate distance: ")); + debug_uart_->print(max_moving_gate); + debug_uart_->print(F("\nMax stationary detecting gate distance: ")); + debug_uart_->print(max_stationary_gate); + debug_uart_->print(F("\nSensitivity per gate")); + + for (uint8_t i = 0; i < sizeof(stationary_sensitivity); ++i) + { + debug_uart_->print(F("\nGate ")); + debug_uart_->print(i); + debug_uart_->print(F(" (")); + debug_uart_->print(i * 0.75); + debug_uart_->print('-'); + debug_uart_->print((i + 1) * 0.75); + debug_uart_->print(F(" metres) Motion: ")); + debug_uart_->print(motion_sensitivity[i]); + debug_uart_->print(F(" Stationary: ")); + debug_uart_->print(stationary_sensitivity[i]); + } + debug_uart_->print(F("\nSensor idle timeout: ")); + debug_uart_->print(sensor_idle_time); + debug_uart_->print('s'); + } + #endif // if defined(LD2410_DEBUG_COMMANDS) && defined(LD2410_DEBUG) + } else { + _errorCount++; + } + return debug_command_results_("ACK for current configuration"); + case CMD_ENGINEERING_ENABLE: + return debug_command_results_("ACK for enable engineering mode"); + case CMD_ENGINEERING_END: + return debug_command_results_("ACK for end engineering mode"); + case CMD_RANGE_GATE_SENSITIVITY: + return debug_command_results_("ACK for setting sensitivity values"); + case CMD_READ_FIRMWARE_VERSION: + + if (latest_command_success_) + { + firmware_major_version = radar_data_frame_[13]; + firmware_minor_version = radar_data_frame_[12]; + firmware_bugfix_version = radar_data_frame_[14]; + firmware_bugfix_version += radar_data_frame_[15] << 8; + firmware_bugfix_version += radar_data_frame_[16] << 16; + firmware_bugfix_version += radar_data_frame_[17] << 24; + } + return debug_command_results_("ACK for firmware version"); + case CMD_SET_SERIAL_PORT_BAUD: + return debug_command_results_("ACK for setting serial baud rate"); + case CMD_FACTORY_RESET: + return debug_command_results_("ACK for factory reset"); + case CMD_RESTART: + return debug_command_results_("ACK for restart"); + default: + #if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && defined(LD2410_DEBUG) + + if (debug_uart_ != nullptr) + { + debug_uart_->print(F("\nUnknown command response")); + print_frame_(); + } + #endif // if (defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) || defined(LD2410_DEBUG_PARSE)) && + // defined(LD2410_DEBUG) + return false; + } + return false; +} + +/* + * Specification request command be executed + * inside configuraiton mode wrapper. If command fails + * exit-configuration mode is not required. + */ +void ld2410::send_command_preamble_() +{ + // Command preamble + radar_uart_->write((uint8_t)char(0xFD)); + radar_uart_->write((uint8_t)char(0xFC)); + radar_uart_->write((uint8_t)char(0xFB)); + radar_uart_->write((uint8_t)char(0xFA)); +} + +void ld2410::send_command_postamble_() +{ + // Command end + radar_uart_->write((uint8_t)char(0x04)); + radar_uart_->write((uint8_t)char(0x03)); + radar_uart_->write((uint8_t)char(0x02)); + radar_uart_->write((uint8_t)char(0x01)); + radar_uart_->flush(); +} + +/* + * Wrapper to enable configuration mode for + * multiple command execution + */ +bool ld2410::requestConfigurationModeBegin() { + if (configuration_mode_active) { // guard + return true; + } + configuration_mode_active = enter_configuration_mode_(); + return configuration_mode_active; +} + +/* + * Wrapper to disable configuration mode for + * multiple command execution + */ +bool ld2410::requestConfigurationModeEnd() { + if (!configuration_mode_active) { // guard + return true; + } + configuration_mode_active = false; + configuration_mode_active = !leave_configuration_mode_(); + return configuration_mode_active; +} + +/* + * Configuration mode is required to be issued before + * any command execution. Multiple commands can be issued + * once configuraiton mode is enabled. When complete close with + * leave_configuration_mode(); + * + * Configuration mode is cancelled on any error by any + * given command, and leave is NOT required. + */ +bool ld2410::enter_configuration_mode_() +{ + if (configuration_mode_active) { + return true; + } + send_command_preamble_(); + + // Request + radar_uart_->write((uint8_t)char(0x04)); // Command is four bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_CONFIGURATION_ENABLE)); // Request enter command mode + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x01)); + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + + while (millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if (read_frame_()) + { + if (latest_ack_ == CMD_CONFIGURATION_ENABLE) + { + return latest_command_success_; + } + } + } + return false; +} + +bool ld2410::leave_configuration_mode_() +{ + if (configuration_mode_active) { + return true; + } + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_CONFIGURATION_END)); // Request leave command mode + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + + while (millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if (read_frame_()) + { + if (latest_ack_ == CMD_CONFIGURATION_END) + { + return latest_command_success_; + } + } + } + return false; +} + +bool ld2410::requestStartEngineeringMode() +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_ENGINEERING_ENABLE)); // Request enter engineering mode + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_ENGINEERING_ENABLE); + } + return false; +} + +bool ld2410::requestEndEngineeringMode() +{ + if (enter_configuration_mode_()) + { + delay(50); + enter_configuration_mode_(); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_ENGINEERING_END)); // Request leave engineering mode + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_ENGINEERING_END); + } + return false; +} + +bool ld2410::requestCurrentConfiguration() +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_READ_PARAMETER)); // Request current configuration + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_READ_PARAMETER); + } + return false; +} + +bool ld2410::requestFirmwareVersion() +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_READ_FIRMWARE_VERSION)); // Request firmware version + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_READ_FIRMWARE_VERSION); + } + return false; +} + +bool ld2410::requestRestart() +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_RESTART)); // Request restart + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_RESTART); + } + return false; +} + +bool ld2410::requestFactoryReset() +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Request firmware + radar_uart_->write((uint8_t)char(0x02)); // Command is two bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_FACTORY_RESET)); // Request factory reset + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_FACTORY_RESET); + } + return false; +} + +/* + * Serial Speed Choices: default is 7 + * 1 = 9600 + * 2 = 19200 + * 3 = 38400 + * 4 = 57600 + * 5 = 115200 + * 6 = 230400 + * 7 = 256000 + * 8 = 460800 + */ +bool ld2410::setSerialBaudRate(uint8_t cSpeed) +{ + if ((cSpeed < 0) || (cSpeed > LD2410_MAX_GATES)) { + return false; + } + + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + + // Serial baud Rate + radar_uart_->write((uint8_t)char(0x04)); // Command is four bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_SET_SERIAL_PORT_BAUD)); + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(cSpeed)); // Set serial baud rate 1-8, 9600-460800 default=7 + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_SET_SERIAL_PORT_BAUD); + } + return false; +} + +/* + * Set maximum gates and idle time + * + * maximum detection range gate: 2-8 + * unmanned duration: 0-65535 seconds + */ +bool ld2410::setMaxValues(uint16_t moving, uint16_t stationary, uint16_t inactivityTimer) +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + radar_uart_->write((uint8_t)char(0x14)); // Command is 20 bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_MAX_DISTANCE_AND_UNMANNED_DURATION)); // Request set max values + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x00)); // Moving gate command + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(moving & 0x00FF)); // Moving gate value + radar_uart_->write((uint8_t)char((moving & 0xFF00) >> 8)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x01)); // Stationary gate command + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(stationary & 0x00FF)); // Stationary gate value + radar_uart_->write((uint8_t)char((stationary & 0xFF00) >> 8)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x02)); // Inactivity timer command + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(inactivityTimer & 0x00FF)); // Inactivity timer + radar_uart_->write((uint8_t)char((inactivityTimer & 0xFF00) >> 8)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_MAX_DISTANCE_AND_UNMANNED_DURATION); + } + return false; +} + +/* + * configures the sensitivity of the distance gate + * + * Command word:0x0064 + * Command value: + * individual: + * 2 bytes distance gate word 0x0000 + 4 bytes distance gate value (2-8), + * 2 bytes motion sensitivity word 0x0001 + 4 bytes motion sensitivity value. (0-100) + * 2 bytes static sensitivity word 0x0002 + 4 bytes static sensitivity value. (0-100) + * or + * Grouped: (if input gate equals 255) + * 2 bytes distance gate: 0x0000 + 4 bytes distance gate value 0xFFFF + * 2 bytes motion sensitivity word 0x0001 + 4 bytes motion sensitivity value. (0-100) + * 2 bytes static sensitivity word 0x0002 + 4 bytes static sensitivity value. (0-100) + * + * Return value:2 bytes ACK status(0 success, 1 failure) + */ +bool ld2410::setGateSensitivityThreshold(uint8_t gate, uint8_t moving, uint8_t stationary) +{ + if (enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + radar_uart_->write((uint8_t)char(0x14)); // Command is 20 bytes long + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(CMD_RANGE_GATE_SENSITIVITY)); // Request set sensitivity values + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x00)); // Gate command + radar_uart_->write((uint8_t)char(0x00)); + + if (gate == 255) { + radar_uart_->write((uint8_t)char(0xFF)); // Gate value + radar_uart_->write((uint8_t)char(0xFF)); + radar_uart_->write((uint8_t)char(0xFF)); + radar_uart_->write((uint8_t)char(0xFF)); + } else { + radar_uart_->write((uint8_t)char(gate)); // Gate value + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + } + radar_uart_->write((uint8_t)char(0x01)); // Motion sensitivity command + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(moving)); // Motion sensitivity value + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x02)); // Stationary sensitivity command + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(stationary)); // Stationary sensitivity value + radar_uart_->write((uint8_t)char(0x00)); + radar_uart_->write((uint8_t)char(0x00)); // Spacer + radar_uart_->write((uint8_t)char(0x00)); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + return wait_for_command_ack_(CMD_RANGE_GATE_SENSITIVITY); + } + return false; +} + +#endif // ifndef ld2410_cpp diff --git a/lib/ld2410/src/ld2410.h b/lib/ld2410/src/ld2410.h new file mode 100644 index 0000000000..6007d57bd4 --- /dev/null +++ b/lib/ld2410/src/ld2410.h @@ -0,0 +1,324 @@ +/* + * An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. + * + * This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different + *ranges to both static and moving targets can be configured. + * + * The code in this library is based off the manufacturer datasheet and reading of this initial piece of work for ESPHome + *https://github.com/rain931215/ESPHome-LD2410. + * + * https://github.com/ncmreynolds/ld2410 + * + * Released under LGPL-2.1 see https://github.com/ncmreynolds/ld2410/LICENSE for full license + * + */ +#pragma once + +#include + +#if __cplusplus >= 202002L +# include +typedef std::atomic atomic_bool; +#else // if __cplusplus >= 202002L +typedef volatile bool atomic_bool; +#endif // if __cplusplus >= 202002L + +// #define LD2410_DEBUG // Send any debug to serial? +// #define LD2410_DEBUG_DATA //Debug all Data Frames +// #define LD2410_DEBUG_COMMANDS //Debug Command Acks +// #define LD2410_DEBUG_PARSE //Debug Reporting Frames + +// Exclude DEBUG logging when requested externally +#if defined(LIBRARIES_NO_LOG) && LIBRARIES_NO_LOG + # ifdef LD2410_DEBUG + # undef LD2410_DEBUG + # endif // ifdef LD2410_DEBUG +#endif // if defined(LIBRARIES_NO_LOG) && LIBRARIES_NO_LOG + +/* + * Protocol Command Words + */ +#define LD2410_MAX_FRAME_LENGTH 0x40 // or 64 bytes +#define LD2410_MAX_GATES 9 // 0 - 8 gates + +#define CMD_CONFIGURATION_ENABLE 0xFF +#define CMD_CONFIGURATION_END 0xFE +#define CMD_MAX_DISTANCE_AND_UNMANNED_DURATION 0x60 +#define CMD_READ_PARAMETER 0x61 +#define CMD_ENGINEERING_ENABLE 0x62 +#define CMD_ENGINEERING_END 0x63 +#define CMD_RANGE_GATE_SENSITIVITY 0x64 +#define CMD_READ_FIRMWARE_VERSION 0xA0 +#define CMD_SET_SERIAL_PORT_BAUD 0xA1 +#define CMD_FACTORY_RESET 0xA2 +#define CMD_RESTART 0xA3 + +/* + * Data Frame Formats + */ +#define FRAME_TYPE_REPORTING 0x01 +#define FRAME_TYPE_TARGET 0x02 +#define FRAME_PREFIX_PROTOCOL 0xFD +#define FRAME_PREFIX_REPORTING 0xF4 +#define FRAME_TYPE_FLAG 0xAA +#define FRAME_TYPE_MARKER 0x55 + +/* + * Target State Constants + */ +#define TARGET_NONE 0x00 +#define TARGET_MOVING 0x01 +#define TARGET_STATIONARY 0x02 +#define TARGET_MOVING_AND_STATIONARY 0x03 + + +#define SERIAL_RECEIVE_MAX_MS 5 // Read for max. N milliseconds, we'd need (64*(8+2))*(1/256000)=2.5msec to read an entire buffer +#define SERIAL_RECEIVE_GRACE_MS 2 // Read more if still this amount of milliseconds available + +class ld2410 { +public: + + ld2410(); // Constructor function + ~ld2410(); // Destructor function + + /* + * Primary APIs */ + bool begin(Stream&, + bool waitForRadar = true); // Start the ld2410 + #ifdef LD2410_DEBUG + void debug(Stream&); // Start debugging on a stream + #endif // ifdef LD2410_DEBUG + + bool ld2410_loop() { + return read_frame_(); + } // Sensor loop service + + bool presenceDetected() { + return target_type_ != 0; + } // last report data had a type + + bool isConnected(); + bool isStationary() { + return stationaryTargetDetected(); + } + + bool isMoving() { + return movingTargetDetected(); + } + + uint16_t detectionDistance() { + return detection_distance_; + } // Target Reporting Data + + bool dataReady() { + return data_ready_; + } + + /* + * Utilities -- depreciation candidates */ + uint8_t reportingDataComposition() { + return target_type_; + } // Target data state 0-3 + + bool isEngineeringMode() { + return engineering_mode_; + } // Reporting Data + + bool movingTargetDetected(); + bool stationaryTargetDetected(); + bool read() { + return read_frame_(); + } + + /* + * primary sensor responses */ + uint16_t stationaryTargetDistance() { + return stationary_target_distance_; + } // Target Reporting Data + + uint8_t stationaryTargetEnergy() { + return stationary_target_energy_; + } // Target Reporting Data + + uint16_t movingTargetDistance() { + return moving_target_distance_; + } // Target Reporting Data + + uint8_t movingTargetEnergy() { + return moving_target_energy_; + } // Target Reporting Data + + /* + * available if engineering mode is active */ + uint8_t engMovingDistanceGateEnergy(uint8_t gate) { + return (gate < LD2410_MAX_GATES) ? movement_distance_gate_energy[gate] : 255; + } // Engineering Reporting Data + + uint8_t engStaticDistanceGateEnergy(uint8_t gate) { + return (gate < LD2410_MAX_GATES) ? static_distance_gate_engergy[gate] : 255; + } // Engineering Reporting Data + + uint16_t engMaxMovingDistanceGate() { + return max_moving_distance_gate; + } // Engineering Reporting Data + + uint16_t engMaxStaticDistanceGate() { + return max_static_distance_gate; + } // Engineering Reporting Data + + uint16_t engRetainDataValue() { + return engineering_retain_data_; + } // Engineering Reporting Data, last value + + uint8_t engLightSensorValue() { + return light_sensor_data_; + } // Engineering Reporting Data, light sensor (undocumented) + + uint8_t engOutputPinState() { + return output_pin_data_; + } // Engineering Reporting Data, output pin state (undocumented) + + /* + * Commands */ + bool requestRestart(); + bool requestFactoryReset(); + bool requestFirmwareVersion(); + bool requestCurrentConfiguration(); + bool requestStartEngineeringMode(); + bool requestEndEngineeringMode(); + bool setSerialBaudRate(uint8_t cSpeed); + bool setMaxValues(uint16_t moving, + uint16_t stationary, + uint16_t inactivityTimer); // Realistically gate values are 0-8 but sent as uint16_t + bool setGateSensitivityThreshold(uint8_t gate, + uint8_t moving, + uint8_t stationary); + bool requestConfigurationModeBegin(); // support multi command executions BEGIN + bool requestConfigurationModeEnd(); // support multi command executions END + + /* + * available after related command has been executed */ + uint16_t cmdProtocolVersion() { + return configuration_protocol_version_; + } // Configuration mode response + + uint16_t cmdCommunicationBufferSize() { + return configuration_buffer_size_; + } // Configuration mode response + + String cmdFirmwareVersion(); // Returns value from command + + /* + * available after Read Parameter command has been executed */ + uint8_t cfgMaxGate() { + return max_gate; + } // Read Parameters command response + + uint8_t cfgMaxMovingGate() { + return max_moving_gate; + } // Read Parameters command response + + uint8_t cfgMaxStationaryGate() { + return max_stationary_gate; + } // Read Parameters command response + + uint16_t cfgSensorIdleTimeInSeconds() { + return sensor_idle_time; + } // Read Parameters command response + + uint8_t cfgMovingGateSensitivity(uint8_t gate) { + return (gate < LD2410_MAX_GATES) ? motion_sensitivity[gate] : 255; + } // Read Parameters command response + + uint8_t cfgStationaryGateSensitivity(uint8_t gate) { + return (gate < LD2410_MAX_GATES) ? stationary_sensitivity[gate] : 255; + } // Read Parameters command response + + uint16_t getErrorCountAndReset(); + +protected: + + /* + * Request Firmware Version command responses */ + char firmwareBuffer[LD2410_MAX_FRAME_LENGTH]; // 64 byte buffer + uint8_t firmware_major_version = 0; // Reported major version + uint8_t firmware_minor_version = 0; // Reported minor version + uint32_t firmware_bugfix_version = 0; // Reported bugfix version (coded as hex) + + /* + * Read Parameter command response data */ + uint8_t max_gate = 0; // Read parameter data + uint8_t max_moving_gate = 0; // Read parameter data + uint8_t max_stationary_gate = 0; // Read parameter data + uint16_t sensor_idle_time = 0; // Read parameter data + uint8_t motion_sensitivity[LD2410_MAX_GATES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Read parameter data + uint8_t stationary_sensitivity[LD2410_MAX_GATES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Read parameter data + + /* + * Protocol & Engineering Frame Data */ + uint16_t moving_target_distance_ = 0; // protocol mode info + uint8_t moving_target_energy_ = 0; // protocol mode info + uint16_t stationary_target_distance_ = 0; // protocol mode info + uint8_t stationary_target_energy_ = 0; // protocol mode info + uint16_t detection_distance_ = 0; // protocol & engineering mode info + uint8_t max_moving_distance_gate = 0; // engineering mode info + uint8_t max_static_distance_gate = 0; // engineering mode info + uint8_t movement_distance_gate_energy[LD2410_MAX_GATES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Engineering mode info + uint8_t static_distance_gate_engergy[LD2410_MAX_GATES] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Engineering mode info + uint16_t engineering_retain_data_ = 0; // last value in engineering data frame, extra + // retain ?? + uint8_t light_sensor_data_ = 0; // engineering mode, light sensor (undocumented) + uint8_t output_pin_data_ = 0; // engineering mode, output pin state + // (undocumented) + + /* + * Configuration mode response info */ + uint16_t configuration_protocol_version_ = 0; // From Enter Configuration Mode Response + uint16_t configuration_buffer_size_ = LD2410_MAX_FRAME_LENGTH; // From Enter Configuration Mode Response + +private: + + /* + * feature control variables */ + Stream *radar_uart_ = nullptr; + #ifdef LD2410_DEBUG + Stream *debug_uart_ = nullptr; // The stream used for the debugging + #endif // ifdef LD2410_DEBUG + + uint32_t radar_uart_timeout = 250; // How long to give up on receiving some useful data from the LD2410 + uint32_t radar_uart_last_packet_ = 0; // Time of the last packet from the radar + uint32_t radar_uart_last_command_ = 0; // Time of the last command sent to the radar + uint32_t radar_uart_command_timeout_ = 250; // Timeout for sending commands + + uint16_t _errorCount = 0; // Internal errorcounter, managed via getErrorCountAndReset() + + uint8_t latest_ack_ = 0; + uint8_t target_type_ = 0; + uint8_t radar_data_frame_position_ = 0; // Where in the frame we are currently writing + uint8_t radar_data_frame_[LD2410_MAX_FRAME_LENGTH]; // Store the incoming data from the radar, to check it's in a valid format + + bool frame_started_ = false; // Whether a frame is currently being read + bool ack_frame_ = false; // Whether the incoming frame is LIKELY an ACK frame + bool waiting_for_ack_ = false; // Whether a command has just been sent + bool engineering_mode_ = false; // Wheter engineering mode is active + bool latest_command_success_ = false; + bool configuration_mode_active = false; // Configuration state (multi-mode) + atomic_bool data_ready_ = false; // Can we read the current data? + + /* + * feature management functions */ + uint16_t serial_to_int_(uint8_t index); // Unpack bytes + bool debug_command_results_(const char *title); + bool wait_for_command_ack_(uint8_t command); + bool isProtocolDataFrame_(); // Command -Determine type of Frame + bool isReportingDataFrame_(); // Data - Determine type of Frame + + bool read_frame_(); // Try to read a frame from the UART + bool parse_data_frame_(); // Is the current data frame valid? + bool parse_command_frame_(); // Is the current command frame valid? + void print_frame_(); // Print the frame for debugging + void send_command_preamble_(); // Commands have the same preamble + void send_command_postamble_(); // Commands have the same postamble + bool enter_configuration_mode_(); // Necessary before sending any command + bool leave_configuration_mode_(); // Will not read values without leaving command mode +}; diff --git a/lib/ld2410/test/README b/lib/ld2410/test/README new file mode 100644 index 0000000000..4caa74e330 --- /dev/null +++ b/lib/ld2410/test/README @@ -0,0 +1,23 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html + + +SerialStudio reads the serial port output of the ESP and plot the various +data points. You will need the JSON project file in this folder and the +app "SerialStudio" at this link: + +- https://github.com/Serial-Studio/Serial-Studio/releases +- https://www.dobitaobyte.com.br/laboratorio-maker-05-serial-studio-monitor-serial-de-tempo-real/ + +### Both are maps to process csv data: use via SerialStudio Setup option + ld2410-alarm.json buildWithAlarmSerialStudioCSV() + ld2410-json.json buildSerialStudioCSV() diff --git a/platformio_core_defs.ini b/platformio_core_defs.ini index 453413849d..31a4a23689 100644 --- a/platformio_core_defs.ini +++ b/platformio_core_defs.ini @@ -250,6 +250,7 @@ build_flags = -DESP32_STAGE -DCONFIG_PM_ENABLE -DCONFIG_FREERTOS_USE_TICKLESS_IDLE=1 -DCONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3 + -DNEOPIXEL_ESP32_RMT_DEFAULT -I$PROJECT_DIR/src/include -include "sdkconfig.h" -include "ESPEasy_config.h" diff --git a/platformio_esp82xx_envs.ini b/platformio_esp82xx_envs.ini index db7e53193f..2b2f782616 100644 --- a/platformio_esp82xx_envs.ini +++ b/platformio_esp82xx_envs.ini @@ -329,6 +329,7 @@ platform = ${regular_platform.platform} platform_packages = ${regular_platform.platform_packages} build_flags = ${regular_platform.build_flags} ${esp8266_4M1M.build_flags} + -D WEBSERVER_USE_CDN_JS_CSS [env:normal_ESP8266_4M1M_VCC] extends = esp8266_4M1M @@ -338,6 +339,7 @@ build_flags = ${regular_platform.build_flags} ${esp8266_4M1M.build_flags} -D FEATURE_ADC_VCC=1 -D NO_LIMIT_BUILD_SIZE + -D WEBSERVER_USE_CDN_JS_CSS [env:normal_alt_wifi_ESP8266_4M1M] extends = esp8266_4M1M diff --git a/requirements.txt b/requirements.txt index 4a4dc0318c..3cd41b3baf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ platformio>=6.1.9 -pygit2>=1.10.1 +pygit2>=1.10.1 \ No newline at end of file diff --git a/src/Custom-sample.h b/src/Custom-sample.h index 8d7b8766d9..f0528361c3 100644 --- a/src/Custom-sample.h +++ b/src/Custom-sample.h @@ -151,6 +151,8 @@ #define DEFAULT_LONGITUDE 0.0f // Default Longitude #define DEFAULT_SYSLOG_IP "" // Syslog IP Address +#define DEFAULT_SYSLOG_PORT 0 // Standard syslog port: 514 +#define DEFAULT_SYSLOG_FACILITY 0 // kern #define DEFAULT_SYSLOG_LEVEL 0 // Syslog Log Level #define DEFAULT_SERIAL_LOG_LEVEL LOG_LEVEL_INFO // Serial Log Level #define DEFAULT_WEB_LOG_LEVEL LOG_LEVEL_INFO // Web Log Level @@ -159,13 +161,16 @@ #define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port #define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate -#define DEFAULT_SYSLOG_FACILITY 0 // kern #define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) #define BUILD_NO_DEBUG +// Custom built-in url for hosting JavaScript and CSS files. +#define CUSTOM_BUILD_CDN_URL "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/" + + // Special SSID/key setup only to be used in custom builds. @@ -345,75 +350,75 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define USES_P001 // Switch // #define USES_P002 // ADC // #define USES_P003 // Pulse -// #define USES_P004 // Dallas -// #define USES_P005 // DHT -// #define USES_P006 // BMP085 +// #define USES_P004 // 1-Wire Temperature (Dallas/Maxim DS18B20) +// #define USES_P005 // DHT11/12/22 SONOFF2301/7021/MS01 +// #define USES_P006 // BMP085/180 // #define USES_P007 // PCF8591 -// #define USES_P008 // RFID -// #define USES_P009 // MCP +// #define USES_P008 // Wiegand (RFID) +// #define USES_P009 // MCP23017 // #define USES_P010 // BH1750 -// #define USES_P011 // PME -// #define USES_P012 // LCD -// #define USES_P013 // HCSR04 -// #define USES_P014 // SI7021 +// #define USES_P011 // ProMini Extender +// #define USES_P012 // LCD2004 +// #define USES_P013 // HC-SR04/RCW-0001 +// #define USES_P014 // SI70xx/HTU21D // #define USES_P015 // TSL2561 // #define USES_P017 // PN532 -// #define USES_P018 // Dust +// #define USES_P018 // GP2Y10 // #define USES_P019 // PCF8574 // #define USES_P020 // Ser2Net -// #define USES_P021 // Level +// #define USES_P021 // Level Control // #define USES_P022 // PCA9685 -// #define USES_P023 // OLED +// #define USES_P023 // OLED SSD1306 // #define USES_P024 // MLX90614 // #define USES_P025 // ADS1x15 // #define USES_P026 // SysInfo // #define USES_P027 // INA219 -// #define USES_P028 // BME280 -// #define USES_P029 // Output +// #define USES_P028 // BMx280 +// #define USES_P029 // Domoticz MQTT Helper -// #define USES_P031 // SHT1X -// #define USES_P032 // MS5611 -// #define USES_P033 // Dummy +// #define USES_P031 // SHT1x +// #define USES_P032 // MS5611 (GY-63) +// #define USES_P033 // Dummy Device // #define USES_P034 // DHT12 -// #define USES_P036 // FrameOLED +// #define USES_P036 // OLED SSD1306/SH1106 Framed // #define P036_FEATURE_DISPLAY_PREVIEW 1 // Enable Preview feature, shows on-display content on Devices overview page // #define P036_FEATURE_ALIGN_PREVIEW 1 // Enable center/right-align feature when preview is enabled (auto-disabled for 1M builds) // #define P036_ENABLE_TICKER 1 // Enable ticker function -// #define USES_P037 // MQTTImport +// #define USES_P037 // MQTT Import // #define P037_MAPPING_SUPPORT 1 // Enable Value mapping support // #define P037_FILTER_SUPPORT 1 // Enable filtering support // #define P037_JSON_SUPPORT 1 // Enable Json support // #define USES_P038 // NeoPixel -// #define USES_P039 // Environment - Thermocouple +// #define USES_P039 // Thermocouple // #define USES_P040 // RFID - ID12LA/RDM6300 -// #define USES_P041 // NeoClock -// #define USES_P042 // Candle +// #define USES_P041 // NeoPixel (Word Clock) +// #define USES_P042 // NeoPixel (Candle) // #define USES_P043 // ClkOutput -// #define USES_P044 // P1WifiGateway +// #define USES_P044 // P1 Wifi Gateway // #define USES_P045 // MPU6050 -// #define USES_P046 // VentusW266 -// #define USES_P047 // I2C_soil_misture -// #define USES_P048 // Motoshield_v2 -// #define USES_P049 // MHZ19 +// #define USES_P046 // Ventus W266 +// #define USES_P047 // Soil moisture sensor +// #define USES_P048 // Motoshield v2 +// #define USES_P049 // MH-Z19 // #define USES_P050 // TCS34725 RGB Color Sensor with IR filter and White LED // #define USES_P051 // AM2320 // #define USES_P052 // SenseAir -// #define USES_P053 // PMSx003 +// #define USES_P053 // PMSx003 / PMSx003ST // #define USES_P054 // DMX512 // #define USES_P055 // Chiming -// #define USES_P056 // SDS011-Dust +// #define USES_P056 // SDS011/018/198 // #define USES_P057 // HT16K33_LED // #define USES_P058 // HT16K33_KeyPad -// #define USES_P059 // Encoder +// #define USES_P059 // Rotary Encoder // #define USES_P060 // MCP3221 -// #define USES_P061 // Keypad -// #define USES_P062 // MPR121_KeyPad -// #define USES_P063 // TTP229_KeyPad +// #define USES_P061 // PCF8574 / MCP23017 / PCA8575 +// #define USES_P062 // MPR121 +// #define USES_P063 // TTP229 // #define USES_P064 // APDS9960 Gesture // #define USES_P065 // DRF0299 // #define USES_P066 // VEML6040 @@ -424,18 +429,18 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define USES_P070 // NeoPixel_Clock // #define USES_P071 // Kamstrup401 // #define USES_P072 // HDC1000/HDC1008/HDC1010/HDC1050/HDC1080 -// #define USES_P073 // 7DG +// #define USES_P073 // 7-segment display // #define USES_P074 // TSL2591 // #define USES_P075 // Nextion -// #define USES_P076 // HWL8012 in POW r1 -// #define USES_P077 // CSE7766 in POW R2 -// #define USES_P078 // Eastron Modbus Energy meters -// #define USES_P079 // Wemos Motoshield +// #define USES_P076 // HLW8012/BL0937 (Shelly Plug S, Sonoff POW R1, Huafan SS, KMC 70011, Aplic WDP303075, SK03 Outdoor, BlitzWolf SHP, Teckin, Teckin US, Gosund SP1 v23) +// #define USES_P077 // CSE7766 (Sonoff S31, Sonoff POW R2, Sonoff POW R3xx(D), Sonoff Dual R3) +// #define USES_P078 // Eastron SDMxxx Modbus +// #define USES_P079 // Wemos / Lolin Motorshield // #define USES_P080 // iButton Sensor DS1990A // #define USES_P081 // Cron // #define USES_P082 // GPS -// #define USES_P083 // SGP30 +// #define USES_P083 // SGP30 TVOC // #define USES_P084 // VEML6070 // #define USES_P085 // AcuDC24x // #define USES_P086 // Receiving values according Homie convention. Works together with C014 Homie controller @@ -443,30 +448,30 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define USES_P088 // HeatpumpIR // #define USES_P089 // Ping -// #define USES_P090 // CCS811 -// #define USES_P091 // SerSwitch +// #define USES_P090 // CCS811 TVOC +// #define USES_P091 // Serial MCU controlled switch // #define USES_P092 // DLbus -// #define USES_P093 // MitsubishiHP -// #define USES_P094 // CULReader -// #define USES_P095 // ILI9341 +// #define USES_P093 // Mitsubishi Heat Pump +// #define USES_P094 // CUL Reader +// #define USES_P095 // ILI934x / ILI948x // #define USES_P096 // eInk -// #define USES_P097 // ESP32Touch -// #define USES_P098 // +// #define USES_P097 // ESP32 Touch +// #define USES_P098 // PWM Motor // #define USES_P099 // XPT2046 touchscreen // #define USES_P100 // DS2423 counter -// #define USES_P101 // WakeOnLan -// #define USES_P102 // PZEM004Tv3 +// #define USES_P101 // Wake On Lan +// #define USES_P102 // PZEM-004Tv30-Multiple // #define USES_P103 // Atlas Scientific EZO Sensors (pH, ORP, EZO, DO) -// #define USES_P104 // MAX7219 dotmatrix -// #define USES_P105 // AHT10/20/21 -// #define USES_P106 // BME680 -// #define USES_P107 // Si1145 +// #define USES_P104 // MAX7219 dot matrix +// #define USES_P105 // AHT10/AHT2x +// #define USES_P106 // BME68x +// #define USES_P107 // SI1145 // #define USES_P108 // DDS238-x ZN Modbus energy meters // #define USES_P109 // ThermoOLED // #define USES_P110 // VL53L0X Time of Flight sensor -// #define USES_P111 // RF522 RFID reader +// #define USES_P111 // MFRC522 RFID reader // #define USES_P112 // AS7265x // #define USES_P113 // VL53L1X ToF // #define USES_P114 // VEML6075 @@ -477,11 +482,13 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define USES_P119 // ITG3205 Gyro // #define USES_P120 // ADXL345 I2C Acceleration / Gravity -// #define USES_P124 // I2C MultiRelay +// #define USES_P121 // HMC5883L +// #define USES_P122 // SHT2x +// #define USES_P124 // I2C Multi Relay // #define USES_P125 // ADXL345 SPI Acceleration / Gravity // #define USES_P126 // 74HC595 Shift register // #define USES_P127 // CDM7160 -// #define USES_P128 // NeoPixelBusFX +// #define USES_P128 // NeoPixel (BusFX) // #define P128_USES_GRB // Default // #define P128_USES_GRBW // Select 1 option, only first one enabled from this list will be used // #define P128_USES_RGB @@ -492,7 +499,7 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define P128_ENABLE_FAKETV 1 // Enable(1)/Disable(0) FakeTV effect, disabled by default on ESP8266 (.bin size issue), enabled by default on ESP32 // #define USES_P129 // 74HC165 Input shiftregisters -// #define USES_P131 // NeoMatrix +// #define USES_P131 // NeoPixel Matrix // #define USES_P132 // INA3221 // #define USES_P133 // LTR390 UV // #define USES_P134 // A02YYUW @@ -506,10 +513,21 @@ static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { // #define P143_FEATURE_INCLUDE_M5STACK 0 // Enabled by default, can be turned off here // #define P143_FEATURE_INCLUDE_DFROBOT 0 // Enabled by default, can be turned off here // #define P143_FEATURE_COUNTER_COLORMAPPING 0 // Enabled by default, can be turned off here + +// #define USES_P144 // PM1006(K) (Vindriktning) +// #define USES_P145 // MQxxx (MQ135 CO2, MQ3 Alcohol) +// #define USES_P146 // Cache Reader // #define USES_P147 // SGP4x // #define P147_FEATURE_GASINDEXALGORITHM 0 // Enabled by default, can be turned off here +// #define USES_P148 // POWR3xxD/THR3xxD +// #define USES_P150 // TMP117 Temperature +// #define USES_P151 // Honeywell Pressure +// #define USES_P152 // ESP32 DAC +// #define USES_P153 // SHT4x +// #define USES_P154 // BMP3xx +// #define USES_P159 // Presence - LD2410 Radar detection /* ####################################################################################################### diff --git a/src/CustomIR-sample.h b/src/CustomIR-sample.h index 1de9a2a816..ebf76e1b62 100644 --- a/src/CustomIR-sample.h +++ b/src/CustomIR-sample.h @@ -240,15 +240,20 @@ // #define SEND_ARRIS 0 // #define DECODE_RHOSS 0 // #define SEND_RHOSS 0 -// #define DECODE_AIRTON 0 -// #define SEND_AIRTON 0 -// #define DECODE_COOLIX48 0 -// #define SEND_COOLIX48 0 + +// Since the upgrade to library version 2.8.6, a few more protocols had to be disabled, to fit the build in the 1M IR builds +// !!! This is the last upgrade that will be made to fit. Later upgrades will be available only for 4MB ESP8266 IR builds + +// Version 2.8.1 added devices: +#define DECODE_AIRTON 0 +#define SEND_AIRTON 0 +#define DECODE_COOLIX48 0 +#define SEND_COOLIX48 0 // ATTENTION: DISABLE new devices from library version 2.8.2 and newer by default to save ESPEasy .bin size // When extending this list: Add both the DECODE_ and SEND_ defines per new device! -// Version 2.8.2 added devices: +// Version 2.8.2 added protocols: #define DECODE_HITACHI_AC264 0 #define SEND_HITACHI_AC264 0 #define DECODE_KELON168 0 @@ -257,6 +262,8 @@ #define SEND_HITACHI_AC296 0 #define DECODE_DAIKIN200 0 #define SEND_DAIKIN200 0 + +// Version 2.8.3 added protocols: #define DECODE_HAIER_AC160 0 #define SEND_HAIER_AC160 0 #define DECODE_CARRIER_AC128 0 @@ -274,6 +281,16 @@ #define DECODE_DAIKIN312 0 #define SEND_DAIKIN312 0 +// Version 2.8.5 added protocols: +#define DECODE_GORENJE 0 +#define SEND_GORENJE 0 +#define DECODE_WOWWEE 0 +#define SEND_WOWWEE 0 +#define DECODE_CARRIER_AC84 0 +#define SEND_CARRIER_AC84 0 +#define DECODE_YORK 0 +#define SEND_YORK 0 + // Version 2.x.y added devices: #endif // ifndef _CUSTOM_IR_H diff --git a/src/_P007_PCF8591.ino b/src/_P007_PCF8591.ino index 9f13806200..4b049b328f 100644 --- a/src/_P007_PCF8591.ino +++ b/src/_P007_PCF8591.ino @@ -6,6 +6,7 @@ // ####################################################################################################### /** Changelog: + * 2023-11-24 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz * 2022-05-08 tonhuisman: Use ESPEasy core I2C functions where possible * Add support for use of the Analog output pin and 'analogout,' command * Add configuration of all possible analog input modes @@ -47,6 +48,7 @@ boolean Plugin_007(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].TimerOption = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; + Device[deviceCount].I2CMax100kHz = true; // Max 100 kHz allowed/supported break; } diff --git a/src/_P021_Level.ino b/src/_P021_Level.ino index 9554edd6e6..f87e506827 100644 --- a/src/_P021_Level.ino +++ b/src/_P021_Level.ino @@ -92,19 +92,23 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) addFormTextBox(F("Hysteresis"), F("physt"), toString(P021_TRIGGER_HYSTERESIS), 8); - addFormCheckBox(F("Invert Output"), F("inv"), P021_INVERT_OUTPUT == 1); + addFormCheckBox(F("Invert Output"), + F("inv"), + P021_INVERT_OUTPUT == 1); // inverted flag! - addFormCheckBox(F("Save 'Set Level' after change via
config
command"), F("psave_always"), P021_DONT_ALWAYS_SAVE == 0); - # ifndef BUILD_NO_DEBUG + addFormCheckBox(F("Save 'Set Level'/'Hysteresis' after change via
config
command"), + F("psave_always"), + P021_DONT_ALWAYS_SAVE == 0); + // # ifndef BUILD_NO_DEBUG addFormNote(F("Saving settings too often can wear out the flash chip on your ESP!")); - # endif // ifndef BUILD_NO_DEBUG + // # endif // ifndef BUILD_NO_DEBUG addFormNumericBox(F("Auto-save interval"), F("pautosave"), P021_AUTOSAVE_TIMER / 60, 0, 1440); // Present in minutes addUnit(F("minutes")); - # ifndef BUILD_NO_DEBUG - addFormNote(F("Interval to check if 'Set Level' is changed via
config
command and saves it. Max. 24h, 0 = Off")); - # endif // ifndef BUILD_NO_DEBUG + // # ifndef BUILD_NO_DEBUG + addFormNote(F("Interval to check if settings are changed via
config
command and saves that. Max. 24h, 0 = Off")); + // # endif // ifndef BUILD_NO_DEBUG success = true; break; @@ -127,17 +131,30 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_SET_CONFIG: { - String command = parseString(string, 1); + const String command = parseString(string, 1); + const bool isHysteresis = equals(command, F("sethysteresis")); - if (equals(command, F("setlevel"))) { - String value = parseString(string, 2); + if (equals(command, F("setlevel")) || isHysteresis) { + String value = parseString(string, 2); ESPEASY_RULES_FLOAT_TYPE result{}; if (!isError(Calculate(value, result))) { - if (!essentiallyEqual(static_cast(P021_TRIGGER_LEVEL), result)) { // Save only if different + bool isChanged = false; + + if (!isHysteresis && + !essentiallyEqual(static_cast(P021_TRIGGER_LEVEL), result)) { // Save only if different P021_TRIGGER_LEVEL = result; + isChanged = true; + } + + if (isHysteresis && + !essentiallyEqual(static_cast(P021_TRIGGER_HYSTERESIS), result)) { // Save only if different + P021_TRIGGER_HYSTERESIS = result; + isChanged = true; + } - if (P021_DONT_ALWAYS_SAVE == 0) { // save only if explicitly enabled + if (isChanged) { + if (P021_DONT_ALWAYS_SAVE == 0) { // save only if explicitly enabled P021_TRIGGER_LAST_STORED = P021_TRIGGER_LEVEL; SaveSettings(); } else { @@ -168,6 +185,11 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) string = toString(P021_TRIGGER_LEVEL); success = true; } + else + if (equals(command, F("gethysteresis"))) { + string = toString(P021_TRIGGER_HYSTERESIS); + success = true; + } break; } @@ -247,6 +269,7 @@ boolean Plugin_021(uint8_t function, struct EventStruct *event, String& string) break; } } + return success; } diff --git a/src/_P023_OLED.ino b/src/_P023_OLED.ino index b94618d51b..e0b6bbd4e8 100644 --- a/src/_P023_OLED.ino +++ b/src/_P023_OLED.ino @@ -7,6 +7,7 @@ // ####################################################################################################### /** Changelog: + * 2023-10-16 tonhuisman: Bugfix: Template parsing stopped after initial display since previous updates :-( * 2023-03-18 tonhuisman: Show current on-display content on Devices page (75% size, omits trailing empty lines) * Manually set content via command: oled,x,y, is included in the Devices page content * Make Interval optional diff --git a/src/_P024_MLX90614.ino b/src/_P024_MLX90614.ino index 5c11969e49..442d356a56 100644 --- a/src/_P024_MLX90614.ino +++ b/src/_P024_MLX90614.ino @@ -5,6 +5,10 @@ // #################################### Plugin 024: MLX90614 IR temperature I2C 0x5A) ############################################### // ####################################################################################################### +/** Changelog: + * 2023-11-23 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz + * 2023-11-23 tonhuisman: Add Changelog +*/ # include "src/PluginStructs/P024_data_struct.h" @@ -36,6 +40,7 @@ boolean Plugin_024(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].TimerOption = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].PluginStats = true; + Device[deviceCount].I2CMax100kHz = true; // Max 100 kHz allowed/supported break; } diff --git a/src/_P038_NeoPixel.ino b/src/_P038_NeoPixel.ino index ad5b66d692..b9bfd1fa6f 100644 --- a/src/_P038_NeoPixel.ino +++ b/src/_P038_NeoPixel.ino @@ -7,6 +7,7 @@ // ####################################################################################################### // Changelog: +// 2023-10-26, tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library // 2022-12-26, tonhuisman: Set initial brightness with default value 255, and allow 'only' values 1..255 // 2022-11-06, tonhuisman: Add Initial and Max brightness settings, and NeoPixelBright[,0..255] command, 0 = initial // Code optimizations diff --git a/src/_P041_NeoClock.ino b/src/_P041_NeoClock.ino index b9d28a0ea6..85a4ed5d5e 100644 --- a/src/_P041_NeoClock.ino +++ b/src/_P041_NeoClock.ino @@ -1,175 +1,185 @@ #include "_Plugin_Helper.h" #ifdef USES_P041 -//####################################################################################################### -//#################################### Plugin 041: NeoPixel clock ####################################### -//####################################################################################################### -#include +// ####################################################################################################### +// #################################### Plugin 041: NeoPixel clock ####################################### +// ####################################################################################################### -#define NUM_LEDS 114 +/** Changelog: + * 2023-11-04 tonhuisman: Formatted source using Uncrustify + * Update display at plugin start (no need to wait for the first minute to pass) + * Minor improvements + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library + * 2023-10 tonhuisman: Add changelog. + */ -uint8_t Plugin_041_red = 0; +# include + + +# define NUM_LEDS 114 + +uint8_t Plugin_041_red = 0; uint8_t Plugin_041_green = 0; -uint8_t Plugin_041_blue = 0; +uint8_t Plugin_041_blue = 0; -Adafruit_NeoPixel *Plugin_041_pixels; +NeoPixelBus_wrapper *Plugin_041_pixels = nullptr; -#define PLUGIN_041 -#define PLUGIN_ID_041 41 -#define PLUGIN_NAME_041 "Output - NeoPixel (Word Clock)" -#define PLUGIN_VALUENAME1_041 "Clock" +# define PLUGIN_041 +# define PLUGIN_ID_041 41 +# define PLUGIN_NAME_041 "Output - NeoPixel (Word Clock)" +# define PLUGIN_VALUENAME1_041 "Clock" boolean Plugin_041(uint8_t function, struct EventStruct *event, String& string) { boolean success = false; switch (function) { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_041; - Device[deviceCount].Type = DEVICE_TYPE_SINGLE; - Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = false; - Device[deviceCount].ValueCount = 0; - Device[deviceCount].SendDataOption = false; - break; - } + { + Device[++deviceCount].Number = PLUGIN_ID_041; + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_NONE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = false; + Device[deviceCount].ValueCount = 0; + Device[deviceCount].SendDataOption = false; + break; + } case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_041); - break; - } + { + string = F(PLUGIN_NAME_041); + break; + } case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_041)); - break; - } + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_041)); + break; + } case PLUGIN_GET_DEVICEGPIONAMES: - { - event->String1 = formatGpioName_output(F("Data")); - break; - } + { + event->String1 = formatGpioName_output(F("Data")); + break; + } case PLUGIN_WEBFORM_LOAD: - { - addFormNumericBox(F("Red"), F("red"), PCONFIG(0), 0, 255); - addFormNumericBox(F("Green"), F("green"), PCONFIG(1), 0, 255); - addFormNumericBox(F("Blue"), F("blue"), PCONFIG(2), 0, 255); - success = true; - break; - } + { + addFormNumericBox(F("Red"), F("red"), PCONFIG(0), 0, 255); + addFormNumericBox(F("Green"), F("green"), PCONFIG(1), 0, 255); + addFormNumericBox(F("Blue"), F("blue"), PCONFIG(2), 0, 255); + success = true; + break; + } case PLUGIN_WEBFORM_SAVE: - { - PCONFIG(0) = getFormItemInt(F("red")); - PCONFIG(1) = getFormItemInt(F("green")); - PCONFIG(2) = getFormItemInt(F("blue")); - Plugin_041_red = PCONFIG(0); - Plugin_041_green = PCONFIG(1); - Plugin_041_blue = PCONFIG(2); - success = true; - break; - } + { + PCONFIG(0) = getFormItemInt(F("red")); + PCONFIG(1) = getFormItemInt(F("green")); + PCONFIG(2) = getFormItemInt(F("blue")); + success = true; + break; + } case PLUGIN_INIT: + { + Plugin_041_red = PCONFIG(0); + Plugin_041_green = PCONFIG(1); + Plugin_041_blue = PCONFIG(2); + + if (Plugin_041_pixels == nullptr) { - if (Plugin_041_pixels == nullptr) - { - Plugin_041_pixels = new (std::nothrow) Adafruit_NeoPixel(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); - if (Plugin_041_pixels != nullptr) { - Plugin_041_pixels->begin(); // This initializes the NeoPixel library. - } + Plugin_041_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUM_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + + if (Plugin_041_pixels != nullptr) { + Plugin_041_pixels->begin(); // This initializes the NeoPixel library. + Plugin_041_update(); } - Plugin_041_red = PCONFIG(0); - Plugin_041_green = PCONFIG(1); - Plugin_041_blue = PCONFIG(2); - success = Plugin_041_pixels != nullptr; - break; } + success = Plugin_041_pixels != nullptr; + break; + } case PLUGIN_EXIT: - { - if (Plugin_041_pixels != nullptr) { - delete Plugin_041_pixels; - Plugin_041_pixels = nullptr; - } - break; + { + if (Plugin_041_pixels != nullptr) { + delete Plugin_041_pixels; + Plugin_041_pixels = nullptr; } + break; + } case PLUGIN_CLOCK_IN: + { + Plugin_041_update(); + success = true; + break; + } + + case PLUGIN_ONCE_A_SECOND: + { + // int ldrVal = map(analogRead(A0), 0, 1023, 15, 245); + // serialPrint("LDR value: "); + // serialPrintln(ldrVal); + // Plugin_041_pixels->setBrightness(255-ldrVal); + // Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. + success = true; + break; + } + + case PLUGIN_WRITE: + { + String cmd = parseString(string, 1); + + if (equals(cmd, F("neoclockcolor"))) { + Plugin_041_red = event->Par1; + Plugin_041_green = event->Par2; + Plugin_041_blue = event->Par3; Plugin_041_update(); success = true; - break; } - case PLUGIN_ONCE_A_SECOND: + if (equals(cmd, F("neotestall"))) { - //int ldrVal = map(analogRead(A0), 0, 1023, 15, 245); - //serialPrint("LDR value: "); - //serialPrintln(ldrVal); - //Plugin_041_pixels->setBrightness(255-ldrVal); - //Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. + for (int i = 0; i < NUM_LEDS; i++) { + Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); + } + Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. success = true; - break; } - case PLUGIN_WRITE: + if (equals(cmd, F("neotestloop"))) { - String cmd = parseString(string, 1); - if (cmd.equalsIgnoreCase(F("NeoClockColor"))) - { - Plugin_041_red = event->Par1; - Plugin_041_green = event->Par2; - Plugin_041_blue = event->Par3; - Plugin_041_update(); - success = true; - } - - if (cmd.equalsIgnoreCase(F("NeoTestAll"))) + for (int i = 0; i < NUM_LEDS; i++) { - for (int i = 0; i < NUM_LEDS; i++) - Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); + resetAndBlack(); + Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. - success = true; + delay(200); } - - if (cmd.equalsIgnoreCase(F("NeoTestLoop"))) - { - for (int i = 0; i < NUM_LEDS; i++) - { - resetAndBlack(); - Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(event->Par1, event->Par2, event->Par3)); - Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. - delay(200); - } - success = true; - } - - break; + success = true; } + break; + } } return success; } void Plugin_041_update() { - uint8_t Hours = node_time.hour(); + uint8_t Hours = node_time.hour(); uint8_t Minutes = node_time.minute(); + resetAndBlack(); timeToStrip(Hours, Minutes); Plugin_041_pixels->show(); // This sends the updated pixel color to the hardware. } - void resetAndBlack() { for (int i = 0; i < NUM_LEDS; i++) { Plugin_041_pixels->setPixelColor(i, Plugin_041_pixels->Color(0, 0, 0)); @@ -183,46 +193,48 @@ void pushToStrip(int ledId) { void timeToStrip(uint8_t hours, uint8_t minutes) { pushIT_IS(); - //show minutes - if (minutes >= 5 && minutes < 10) { + + // show minutes + if ((minutes >= 5) && (minutes < 10)) { pushFIVE1(); pushAFTER(); - } else if (minutes >= 10 && minutes < 15) { + } else if ((minutes >= 10) && (minutes < 15)) { pushTEN1(); pushAFTER(); - } else if (minutes >= 15 && minutes < 20) { + } else if ((minutes >= 15) && (minutes < 20)) { pushQUATER(); pushAFTER(); - } else if (minutes >= 20 && minutes < 25) { + } else if ((minutes >= 20) && (minutes < 25)) { pushTEN1(); pushFOR(); pushHALF(); - } else if (minutes >= 25 && minutes < 30) { + } else if ((minutes >= 25) && (minutes < 30)) { pushFIVE1(); pushFOR(); pushHALF(); - } else if (minutes >= 30 && minutes < 35) { + } else if ((minutes >= 30) && (minutes < 35)) { pushHALF(); - } else if (minutes >= 35 && minutes < 40) { + } else if ((minutes >= 35) && (minutes < 40)) { pushFIVE1(); pushAFTER(); pushHALF(); - } else if (minutes >= 40 && minutes < 45) { + } else if ((minutes >= 40) && (minutes < 45)) { pushTEN1(); pushAFTER(); pushHALF(); - } else if (minutes >= 45 && minutes < 50) { + } else if ((minutes >= 45) && (minutes < 50)) { pushQUATER(); pushFOR(); - } else if (minutes >= 50 && minutes < 55) { + } else if ((minutes >= 50) && (minutes < 55)) { pushTEN1(); pushFOR(); - } else if (minutes >= 55 && minutes < 60) { + } else if ((minutes >= 55) && (minutes < 60)) { pushFIVE1(); pushFOR(); } int singleMinutes = minutes % 5; + switch (singleMinutes) { case 1: pushM_ONE(); @@ -243,17 +255,20 @@ void timeToStrip(uint8_t hours, uint8_t minutes) pushM_FOUR(); break; } + if (hours >= 12) { hours -= 12; } + if (hours == 12) { hours = 0; } + if (minutes >= 20) { hours++; } - //show hours + // show hours switch (hours) { case 1: pushONE(); @@ -293,135 +308,179 @@ void timeToStrip(uint8_t hours, uint8_t minutes) pushTWELVE(); break; } - //show HOUR + + // show HOUR if (minutes < 5) { pushHOURE(); } } -void pushToStrip(const int* ids, size_t count) { +void pushToStrip(const int *ids, size_t count) { for (size_t i = 0; i < count; ++i) { pushToStrip(ids[i]); } } - void pushM_ONE() { pushToStrip(0); } + void pushM_TWO() { pushToStrip(12); } + void pushM_THREE() { pushToStrip(101); } + void pushM_FOUR() { pushToStrip(113); } + void pushIT_IS() { - constexpr int ids[] = {1, 2, 3, 5, 6}; + constexpr int ids[] = { 1, 2, 3, 5, 6 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushAFTER() { - constexpr int ids[] = {36, 37, 38, 39}; + constexpr int ids[] = { 36, 37, 38, 39 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushQUATER() { - constexpr int ids[] = {30, 31, 32, 33, 34}; + constexpr int ids[] = { 30, 31, 32, 33, 34 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFOR() { - constexpr int ids[] = {41, 42, 43, 44}; + constexpr int ids[] = { 41, 42, 43, 44 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushHALF() { - constexpr int ids[] = {50, 51, 52, 53}; + constexpr int ids[] = { 50, 51, 52, 53 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushONE() { - constexpr int ids[] = {63, 64, 65}; + constexpr int ids[] = { 63, 64, 65 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWO() { - constexpr int ids[] = {64, 65, 66, 67}; + constexpr int ids[] = { 64, 65, 66, 67 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTHREE() { - constexpr int ids[] = {109, 110, 111, 112}; + constexpr int ids[] = { 109, 110, 111, 112 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFOUR() { - constexpr int ids[] = {57, 58, 59, 60}; + constexpr int ids[] = { 57, 58, 59, 60 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFIVE1() { - constexpr int ids[] = {8, 9, 10, 11}; + constexpr int ids[] = { 8, 9, 10, 11 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushFIVE2() { - constexpr int ids[] = {92, 93, 94, 95}; + constexpr int ids[] = { 92, 93, 94, 95 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushSIX() { - constexpr int ids[] = {69, 88, 91}; + constexpr int ids[] = { 69, 88, 91 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushSEVEN() { - constexpr int ids[] = {69, 70, 71, 72, 73}; + constexpr int ids[] = { 69, 70, 71, 72, 73 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushEIGHT() { - constexpr int ids[] = {97, 98, 99, 100}; + constexpr int ids[] = { 97, 98, 99, 100 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushNINE() { - constexpr int ids[] = {73, 74, 75, 76, 77}; + constexpr int ids[] = { 73, 74, 75, 76, 77 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTEN() { - constexpr int ids[] = {54, 59, 76, 81}; + constexpr int ids[] = { 54, 59, 76, 81 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTEN1() { - constexpr int ids[] = {25, 26, 27, 28}; + constexpr int ids[] = { 25, 26, 27, 28 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushELEVEN() { - constexpr int ids[] = {107, 108, 109}; + constexpr int ids[] = { 107, 108, 109 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWELVE() { - constexpr int ids[] = {82, 83, 84, 85, 86, 87}; + constexpr int ids[] = { 82, 83, 84, 85, 86, 87 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } + void pushTWENTY() { - constexpr int ids[] = {16, 17, 18, 19, 20, 21, 22}; + constexpr int ids[] = { 16, 17, 18, 19, 20, 21, 22 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } void pushHOURE() { - constexpr int ids[] = {102,103,104}; + constexpr int ids[] = { 102, 103, 104 }; constexpr size_t count = NR_ELEMENTS(ids); + pushToStrip(ids, count); } diff --git a/src/_P042_Candle.ino b/src/_P042_Candle.ino index bcb309c321..3334ca0ee8 100644 --- a/src/_P042_Candle.ino +++ b/src/_P042_Candle.ino @@ -9,6 +9,7 @@ // Wifi Candle for ESPEasy by Dominik Schmidt (10.2016) /** Changelog: + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library * 2023-01-21 tonhuisman: Move to PluginStruct_base to enable multi-instance use of this plugin * 2023-01-21 tonhuisman: Further refactor and improve code, including GH feedback * Add setting for Led Count, defaults to 20 (was fixed size) diff --git a/src/_P070_NeoPixel_Clock.ino b/src/_P070_NeoPixel_Clock.ino index c759a94210..9415b32f45 100644 --- a/src/_P070_NeoPixel_Clock.ino +++ b/src/_P070_NeoPixel_Clock.ino @@ -7,6 +7,11 @@ // #################################### Plugin 070: NeoPixel ring clock ####################################### // ####################################################################################################### +/** Changelog: + * 2023-10-26 tonhuisman: Apply NeoPixelBus_wrapper as replacement for Adafruit_NeoPixel library + * 2023-10 tonhuisman: Add changelog. + */ + // A clock that uses a strip/ring of 60 WS2812 NeoPixel LEDs as display for a classic clock. // The hours are RED, the minutes are GREEN, the seconds are BLUE and the hour marks are WHITE. diff --git a/src/_P093_MitsubishiHP.ino b/src/_P093_MitsubishiHP.ino index 8a6f641c69..2c7db6e17d 100644 --- a/src/_P093_MitsubishiHP.ino +++ b/src/_P093_MitsubishiHP.ino @@ -6,6 +6,7 @@ // ####################################################################################################### /** Changelog: + * 2023-09-21 jfmennedy: Add support for "SetRemoteTemperature" Issue#4711 * 2023-05-04 tonhuisman: Add support for PLUGIN_GET_CONFIG_VALUE to enable fetching all available values (as included in the json) * 2023-05-04 tonhuisman: Start Changelog */ @@ -14,6 +15,7 @@ * Usage: [#] * Supported configNames are: (not case-sensitive) * - roomTemperature + * - remoteTemperature * - wideVane * - power * - mode diff --git a/src/_P117_SCD30.ino b/src/_P117_SCD30.ino index f1538234ce..873af22dbc 100644 --- a/src/_P117_SCD30.ino +++ b/src/_P117_SCD30.ino @@ -11,6 +11,7 @@ // Changelog: // +// 2023-11-24 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz // 2022-02-26 tonhuisman: Implement commands for get/set measurement interval, and a setting too. Bugfix. // 2022-02-26 tonhuisman: Implement commands for auto/manual CO2 calibration, and setting for auto calibration // 2021-11-20 tonhuisman: Implement multi-instance support (using PluginStruct) @@ -56,6 +57,7 @@ boolean Plugin_117(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].TimerOption = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].PluginStats = true; + Device[deviceCount].I2CMax100kHz = true; // Max 100 kHz allowed/supported break; } diff --git a/src/_P135_SCD4x.ino b/src/_P135_SCD4x.ino index 2867ab6562..7146006f93 100644 --- a/src/_P135_SCD4x.ino +++ b/src/_P135_SCD4x.ino @@ -6,6 +6,7 @@ // ####################################################################################################### /** + * 2023-11-23 tonhuisman: Add Device flag for I2CMax100kHz as this sensor won't work at 400 kHz * 2022-08-28 tonhuisman: Include 'CO2' in plugin name, to be in line with other CO2 plugins * 2022-08-24 tonhuisman: Removed [TESTING] tag * 2022-08-04 tonhuisman: Add forced recalibration subcommand scd4x,setfrc, @@ -49,6 +50,7 @@ boolean Plugin_135(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].TimerOption = true; Device[deviceCount].GlobalSyncOption = true; Device[deviceCount].PluginStats = true; + Device[deviceCount].I2CMax100kHz = true; // Max 100 kHz allowed/supported break; } diff --git a/src/_P159_LD2410.ino b/src/_P159_LD2410.ino new file mode 100644 index 0000000000..7c82f053a9 --- /dev/null +++ b/src/_P159_LD2410.ino @@ -0,0 +1,332 @@ +#include "_Plugin_Helper.h" + +// ####################################################################################################### +// ########################### Plugin 159: Radar Presence detection LD2410(/LD2420) #################### +// ####################################################################################################### + +/** Changelog: + * 2023-10-29 tonhuisman: Rework processing, allow Interval = 0, as now the events will be generated when a value changes, + * but at most once per 100 msec, to not overload the ESP. Fixed the LD2410 library to work correctly + * with the event-driven scheduler model of ESPEasy, instead of the continuous loop() run of Arduino + * Add getconfig values for configured sensitivity level per gate, see below + * 2023-10-28 tonhuisman: !! Breaking change (again): Insert Gate 0 value before Gate 1 value, both for Static and Moving + * energy, as that was missing until now. This is because of poor documentation, talking about 8 values + * where there are in fact 9 values, 0..8 ! + * Add support for getting all values (function PLUGIN_GET_CONFIG_VALUE), also when not configured + * like [#]. Available valuenames: see below. + * Add command ld2410,logall that writes all available values to the log (depending on Engineering mode) + * 2023-10-23 tonhuisman: !! Breaking change: Insert OutputPinState (undocumented) value after AmbientLight value + * shifting all Sensitivity value offsets by 1 !! + * 2023-10-22 tonhuisman: Add command handling: ld2410,factoryreset + * 2023-10-21 tonhuisman: Read data at 50/sec instead of 10/sec to catch up with the high speed of output + * Add/update settings for Sensitivity and nr. of active gates, idle seconds + * Shorten default value names, (breaking) change setting for Engineering mode + * Add setting for generating events only when a value has changed + * 2023-10-14 tonhuisman: Using ld2410 library from https://github.com/ncmreynolds/ld2410, but with PR #3 applied + * including a fix for index/index + 1, mentioned in the comments of that PR and timeout + * extended to 2500 msec + * 2023-10-14 tonhuisman: Initial plugin setup + */ + +/** Info: + * This plugin reads the presence and distance of stationary and moving objects detected by the HiLink LD2410 and LD2420 24 GHz Radar + * human presence detectors + */ + +/** Commands: + * ld2410,factoryreset : Reset sensor to factory defaults, also restarts the sensor like the task is just started. + * ld2410,logall : Send all available values to the log (INFO level) like: "LD2410: : " + */ + +/** ValueNames: (for PLUGIN_GET_CONFIG_VALUE support) + * Presence : Presence (0/1) + * StatPres : Stationary presence (0/1) + * MovPres : Moving presence (0/1) + * Distance : Distance in cm + * StatDist : Stationary distance in cm + * MovDist : Moving distance in cm + * StatEnergy : Stationary object energy level + * MovEnergy : Moving object energy level + * AmbLight : Ambient light level (0..255) (unknown unit) + * OutputPin : State of the output pin (0/1) + * StatEnergyGate0..StatEnergyGate8 : Stationary object energy level for gate 0..8, 75 cm/gate + * MovEnergyGate0..MovEnergyGate8 : Moving object energy for gate 0..8, 75 cm/gate + * StatSensGate0..StatSensGate8 : Stationary sensitivity setting gate 0..8 + * MovSensGate0..MovSensGate8 : Moving sensitivity setting gate 0..8 + */ + +#ifdef USES_P159 +# include "src/PluginStructs/P159_data_struct.h" // Sensor abstraction for P159 + +// Standard plugin defines +# define PLUGIN_159 +# define PLUGIN_ID_159 159 +# define PLUGIN_NAME_159 "Presence - LD2410" + + +boolean Plugin_159(uint8_t function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + // This case defines the device characteristics + + Device[++deviceCount].Number = PLUGIN_ID_159; + Device[deviceCount].Type = DEVICE_TYPE_SERIAL; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; + Device[deviceCount].ValueCount = 4; + Device[deviceCount].OutputDataType = Output_Data_type_t::Simple; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].GlobalSyncOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].TimerOptional = true; + Device[deviceCount].PluginStats = true; + Device[deviceCount].ExitTaskBeforeSave = false; // Enable calling PLUGIN_WEBFORM_SAVE on the instantiated object + + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_159); + + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + const int valueCount = P159_NR_OUTPUT_VALUES; + + for (uint8_t i = 0; i < VARS_PER_TASK; ++i) { + if (i < valueCount) { + const uint8_t pconfigIndex = i + P159_QUERY1_CONFIG_POS; + const uint8_t option = PCONFIG(pconfigIndex); + + if ((option >= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE8)) { + ExtraTaskSettings.setTaskDeviceValueName(i, concat(Plugin_159_valuename(P159_OUTPUT_STATIC_DISTANCE_GATE_index, false), + option - P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0)); + } else + if ((option >= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE8)) { + ExtraTaskSettings.setTaskDeviceValueName(i, concat(Plugin_159_valuename(P159_OUTPUT_MOVING_DISTANCE_GATE_index, false), + option - P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0)); + } else { + ExtraTaskSettings.setTaskDeviceValueName(i, Plugin_159_valuename(option, false)); + } + ExtraTaskSettings.TaskDeviceValueDecimals[i] = 0; // No values have decimals + } else { + ExtraTaskSettings.clearTaskDeviceValueName(i); + } + } + + break; + } + + case PLUGIN_GET_DEVICEGPIONAMES: + { + serialHelper_getGpioNames(event); + + break; + } + + case PLUGIN_WEBFORM_SHOW_CONFIG: + { + string += serialHelper_getSerialTypeLabel(event); + + success = true; + + break; + } + + case PLUGIN_GET_DEVICEVALUECOUNT: + { + event->Par1 = P159_NR_OUTPUT_VALUES; + + success = true; + + break; + } + + case PLUGIN_GET_DEVICEVTYPE: + { + event->sensorType = static_cast(PCONFIG(P159_SENSOR_TYPE_INDEX)); + event->idx = P159_SENSOR_TYPE_INDEX; + + success = true; + + break; + } + + + case PLUGIN_SET_DEFAULTS: + { + PCONFIG(0) = P159_OUTPUT_PRESENCE; + PCONFIG(1) = P159_OUTPUT_DISTANCE; + PCONFIG(2) = P159_OUTPUT_STATIONARY_ENERGY; + PCONFIG(3) = P159_OUTPUT_MOVING_ENERGY; + + PCONFIG(P159_SENSOR_TYPE_INDEX) = static_cast(Sensor_VType::SENSOR_TYPE_QUAD); + + success = true; + + break; + } + + case PLUGIN_WEBFORM_LOAD_OUTPUT_SELECTOR: + { + const uint8_t optionCount = P159_GET_ENGINEERING_MODE == 1 ? P159_NR_ENGINEERING_OUTPUT_OPTIONS : P159_NR_OUTPUT_OPTIONS; + String options[optionCount]; + + for (uint8_t option = 0; option < optionCount; ++option) { + if ((option >= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE8)) { + options[option] = concat(Plugin_159_valuename(P159_OUTPUT_STATIC_DISTANCE_GATE_index, true), + option - P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0); + } else + if ((option >= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE8)) { + options[option] = concat(Plugin_159_valuename(P159_OUTPUT_MOVING_DISTANCE_GATE_index, true), + option - P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0); + } else { + options[option] = Plugin_159_valuename(option, true); + } + } + + const int valueCount = P159_NR_OUTPUT_VALUES; + + for (uint8_t i = 0; i < valueCount; ++i) { + const uint8_t pconfigIndex = i + P159_QUERY1_CONFIG_POS; + sensorTypeHelper_loadOutputSelector(event, pconfigIndex, i, optionCount, options); + } + + success = true; + + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + addFormSelector_YesNo(F("Engineering mode"), F("eng"), P159_GET_ENGINEERING_MODE, true); + addFormNote(F("When changing this setting the page will be reloaded")); + + addFormCheckBox(F("Generate Events only when changed"), F("diff"), P159_GET_UPDATE_DIFF_ONLY); + + success = true; + + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + addFormSubHeader(F("Sensitivity settings")); + success = P159_data->plugin_webform_load(event); + } + + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + P159_SET_ENGINEERING_MODE(getFormItemInt(F("eng"))); + P159_SET_UPDATE_DIFF_ONLY(isFormItemChecked(F("diff"))); + + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + P159_data->plugin_webform_save(event); + } + + success = true; + + break; + } + case PLUGIN_INIT: + { + int8_t rxPin = serialHelper_getRxPin(event); + int8_t txPin = serialHelper_getTxPin(event); + ESPEasySerialPort portType = serialHelper_getSerialType(event); + + // Create the P159_data_struct object that will do all the sensor interaction + initPluginTaskData(event->TaskIndex, new (std::nothrow) P159_data_struct(portType, + rxPin, + txPin, + P159_GET_ENGINEERING_MODE == 1)); + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + success = nullptr != P159_data; + addLog(LOG_LEVEL_INFO, concat(F("P159 : INIT, success: "), success ? 1 : 0)); + + break; + } + + case PLUGIN_READ: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + success = P159_data->plugin_read(event); + } + + break; + } + + case PLUGIN_WRITE: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + success = P159_data->plugin_write(event, string); + } + + break; + } + + case PLUGIN_GET_CONFIG_VALUE: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + success = P159_data->plugin_get_config_value(event, string); + } + + break; + } + + case PLUGIN_EXIT: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P159_data) { + P159_data->disconnectSerial(); + } + + success = true; + + break; + } + + case PLUGIN_TEN_PER_SECOND: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if ((nullptr != P159_data) && !P159_data->isRunning()) { + success = P159_data->processSensor(event); // Not Running can have 50 msec delays included, so NOT in PLUGIN_FIFTY_PER_SECOND ! + } + + break; + } + case PLUGIN_FIFTY_PER_SECOND: + { + P159_data_struct *P159_data = static_cast(getPluginTaskData(event->TaskIndex)); + + if ((nullptr != P159_data) && P159_data->isRunning()) { + success = P159_data->processSensor(event); // When running no delays are inserted, so can go in PLUGIN_FIFTY_PER_SECOND + } + + break; + } + } // switch + + return success; +} // function + +#endif // ifdef USES_P159 diff --git a/src/src/Commands/InternalCommands.cpp b/src/src/Commands/InternalCommands.cpp index 79a647ba54..9b32c341cd 100644 --- a/src/src/Commands/InternalCommands.cpp +++ b/src/src/Commands/InternalCommands.cpp @@ -414,14 +414,17 @@ bool executeInternalCommand(command_case_data & data) COMMAND_CASE_A("posttohttp", Command_HTTP_PostToHTTP, -1); // HTTP.h #endif // if FEATURE_POST_TO_HTTP #if FEATURE_CUSTOM_PROVISIONING - COMMAND_CASE_A( "provisionconfig", Command_Provisioning_Config, 0); // Provisioning.h - COMMAND_CASE_A( "provisionsecurity", Command_Provisioning_Security, 0); // Provisioning.h + COMMAND_CASE_A( "provision", Command_Provisioning_Dispatcher, -1); // Provisioning.h + #ifdef PLUGIN_BUILD_MAX_ESP32 // FIXME DEPRECATED: Fallback for temporary backward compatibility + COMMAND_CASE_A( "provisionconfig", Command_Provisioning_ConfigFallback, 0); // Provisioning.h + COMMAND_CASE_A( "provisionsecurity", Command_Provisioning_SecurityFallback, 0); // Provisioning.h #if FEATURE_NOTIFIER - COMMAND_CASE_A( "provisionnotification", Command_Provisioning_Notification, 0); // Provisioning.h + COMMAND_CASE_A( "provisionnotification", Command_Provisioning_NotificationFallback, 0); // Provisioning.h #endif - COMMAND_CASE_A( "provisionprovision", Command_Provisioning_Provision, 0); // Provisioning.h - COMMAND_CASE_A( "provisionrules", Command_Provisioning_Rules, 1); // Provisioning.h - COMMAND_CASE_A( "provisionfirmware", Command_Provisioning_Firmware, 1); // Provisioning.h + COMMAND_CASE_A( "provisionprovision", Command_Provisioning_ProvisionFallback, 0); // Provisioning.h + COMMAND_CASE_A( "provisionrules", Command_Provisioning_RulesFallback, 1); // Provisioning.h + COMMAND_CASE_A( "provisionfirmware", Command_Provisioning_FirmwareFallback, 1); // Provisioning.h + #endif // ifdef PLUGIN_BUILD_MAX_ESP32 #endif COMMAND_CASE_A( "pulse", Command_GPIO_Pulse, 3); // GPIO.h #if FEATURE_MQTT diff --git a/src/src/Commands/Provisioning.cpp b/src/src/Commands/Provisioning.cpp index 8d0506a6d7..ce7ba429ad 100644 --- a/src/src/Commands/Provisioning.cpp +++ b/src/src/Commands/Provisioning.cpp @@ -9,46 +9,129 @@ # include "../Helpers/Networking.h" # include "../Helpers/StringConverter.h" -String Command_Provisioning_Config(struct EventStruct *event, const char *Line) +String Command_Provisioning_Dispatcher(struct EventStruct *event, + const char *Line) +{ + const String cmd = parseString(Line, 2); + + if (equals(cmd, F("config"))) { + return Command_Provisioning_Config(); + } else + if (equals(cmd, F("firmware"))) { + return Command_Provisioning_Firmware(event, Line); + } else + # if FEATURE_NOTIFIER + if (equals(cmd, F("notification"))) { + return Command_Provisioning_Notification(); + } else + # endif // if FEATURE_NOTIFIER + if (equals(cmd, F("provision"))) { + return Command_Provisioning_Provision(); + } else + if (equals(cmd, F("rules"))) { + return Command_Provisioning_Rules(event); + } else + if (equals(cmd, F("security"))) { + return Command_Provisioning_Security(); + } + return return_command_failed_flashstr(); +} + +String Command_Provisioning_Config() { return downloadFileType(FileType::CONFIG_DAT); } -String Command_Provisioning_Security(struct EventStruct *event, const char *Line) +String Command_Provisioning_Security() { return downloadFileType(FileType::SECURITY_DAT); } -#if FEATURE_NOTIFIER -String Command_Provisioning_Notification(struct EventStruct *event, const char *Line) +# if FEATURE_NOTIFIER +String Command_Provisioning_Notification() { return downloadFileType(FileType::NOTIFICATION_DAT); } -#endif -String Command_Provisioning_Provision(struct EventStruct *event, const char *Line) +# endif // if FEATURE_NOTIFIER + +String Command_Provisioning_Provision() { return downloadFileType(FileType::PROVISIONING_DAT); } -String Command_Provisioning_Rules(struct EventStruct *event, const char *Line) +String Command_Provisioning_Rules(struct EventStruct *event) +{ + if ((event->Par2 <= 0) || (event->Par2 > 4)) { + return F("Provision,Rules: rules index out of range"); + } + return downloadFileType(FileType::RULES_TXT, event->Par2 - 1); +} + +String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line) +{ + // FIXME TD-er: Must only allow to use set prefix in the provisioning settings + const String url = parseStringToEndKeepCase(Line, 3); + String error; + + downloadFirmware(url, error); // Events are sent from download handler + return error; +} + +# ifdef PLUGIN_BUILD_MAX_ESP32 +void Command_Provisioning_DeprecatedMessage(const String& param) { + addLog(LOG_LEVEL_ERROR, strformat(F("WARNING: 'Provision%s' is deprecated, change to 'Provision,%s'"), param.c_str(), param.c_str())); +} + +String Command_Provisioning_ConfigFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Config")); + return Command_Provisioning_Config(); +} + +String Command_Provisioning_SecurityFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Security")); + return Command_Provisioning_Security(); +} + +# if FEATURE_NOTIFIER +String Command_Provisioning_NotificationFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Notification")); + return Command_Provisioning_Notification(); +} + +String Command_Provisioning_ProvisionFallback(struct EventStruct *event, const char *Line) { + Command_Provisioning_DeprecatedMessage(F("Provision")); + return Command_Provisioning_Provision(); +} + +String Command_Provisioning_RulesFallback(struct EventStruct *event, const char *Line) +{ + Command_Provisioning_DeprecatedMessage(F("Rules,")); + if ((event->Par1 <= 0) || (event->Par1 > 4)) { return F("ProvisionRules: rules index out of range"); } return downloadFileType(FileType::RULES_TXT, event->Par1 - 1); } -String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line) +String Command_Provisioning_FirmwareFallback(struct EventStruct *event, const char *Line) { + Command_Provisioning_DeprecatedMessage(F("Firmware,")); + // FIXME TD-er: Must only allow to use set prefix in the provisioning settings const String url = parseStringToEndKeepCase(Line, 2); String error; - if (downloadFirmware(url, error)) { - // TODO TD-er: send events - } + + downloadFirmware(url, error); return error; } +# endif // if FEATURE_NOTIFIER + +# endif // ifdef PLUGIN_BUILD_MAX_ESP32 #endif // if FEATURE_CUSTOM_PROVISIONING diff --git a/src/src/Commands/Provisioning.h b/src/src/Commands/Provisioning.h index bc7316d8c8..99b504c1f8 100644 --- a/src/src/Commands/Provisioning.h +++ b/src/src/Commands/Provisioning.h @@ -7,22 +7,39 @@ class String; -String Command_Provisioning_Config(struct EventStruct *event, - const char *Line); -String Command_Provisioning_Security(struct EventStruct *event, - const char *Line); -#if FEATURE_NOTIFIER -String Command_Provisioning_Notification(struct EventStruct *event, - const char *Line); -#endif -String Command_Provisioning_Provision(struct EventStruct *event, - const char *Line); -String Command_Provisioning_Rules(struct EventStruct *event, - const char *Line); +String Command_Provisioning_Dispatcher(struct EventStruct *event, + const char *Line); +String Command_Provisioning_Config(); +String Command_Provisioning_Security(); +# if FEATURE_NOTIFIER +String Command_Provisioning_Notification(); +# endif // if FEATURE_NOTIFIER +String Command_Provisioning_Provision(); + +String Command_Provisioning_Rules(struct EventStruct *event); String Command_Provisioning_Firmware(struct EventStruct *event, const char *Line); +// FIXME DEPRECATED! +# ifdef PLUGIN_BUILD_MAX_ESP32 +String Command_Provisioning_ConfigFallback(struct EventStruct *event, + const char *Line); +String Command_Provisioning_SecurityFallback(struct EventStruct *event, + const char *Line); +# if FEATURE_NOTIFIER +String Command_Provisioning_NotificationFallback(struct EventStruct *event, + const char *Line); +# endif // if FEATURE_NOTIFIER +String Command_Provisioning_ProvisionFallback(struct EventStruct *event, + const char *Line); +String Command_Provisioning_RulesFallback(struct EventStruct *event, + const char *Line); + +String Command_Provisioning_FirmwareFallback(struct EventStruct *event, + const char *Line); +# endif // ifdef PLUGIN_BUILD_MAX_ESP32 + #endif // if FEATURE_CUSTOM_PROVISIONING #endif // ifndef COMMANDS_PROVISIONING_H diff --git a/src/src/CustomBuild/CompiletimeDefines.cpp b/src/src/CustomBuild/CompiletimeDefines.cpp index 506c30912f..775ef5fb48 100644 --- a/src/src/CustomBuild/CompiletimeDefines.cpp +++ b/src/src/CustomBuild/CompiletimeDefines.cpp @@ -112,8 +112,8 @@ const __FlashStringHelper * get_CDN_url_prefix() { #else // Some fallback tag // FIXME TD-er: Not sure which is better, serving the latest (which will have caching issues) or a tag which will become outdated - return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20220809/static/"); - //return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/"); + return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/"); + //return F("https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega-20231013/static/"); #endif } diff --git a/src/src/CustomBuild/ESPEasyDefaults.h b/src/src/CustomBuild/ESPEasyDefaults.h index 08f1c005e0..d4eba68df9 100644 --- a/src/src/CustomBuild/ESPEasyDefaults.h +++ b/src/src/CustomBuild/ESPEasyDefaults.h @@ -366,6 +366,9 @@ #ifndef DEFAULT_SYSLOG_FACILITY #define DEFAULT_SYSLOG_FACILITY 0 // kern #endif +#ifndef DEFAULT_SYSLOG_PORT +#define DEFAULT_SYSLOG_PORT 0 +#endif #ifndef DEFAULT_SYNC_UDP_PORT #define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) diff --git a/src/src/CustomBuild/StorageLayout.h b/src/src/CustomBuild/StorageLayout.h index 4e1d4d90ef..c9903597b5 100644 --- a/src/src/CustomBuild/StorageLayout.h +++ b/src/src/CustomBuild/StorageLayout.h @@ -55,7 +55,18 @@ */ #ifndef DAT_BASIC_SETTINGS_SIZE -# define DAT_BASIC_SETTINGS_SIZE 4096 +// For size of SettingsStruct stored at this area in config.dat +// See: run_compiletime_checks() +#ifdef ESP8266 +# if FEATURE_NON_STANDARD_24_TASKS +# define DAT_BASIC_SETTINGS_SIZE 4096 // Current Settings Struct size is ~2.3k, leave some room to extend +#else +# define DAT_BASIC_SETTINGS_SIZE 3072 // Current Settings Struct size is ~1.3k, leave some room to extend +#endif +#endif +#ifdef ESP32 +# define DAT_BASIC_SETTINGS_SIZE 6144 // Current Settings Struct size is ~3k, leave some room to extend +#endif #endif // ifndef DAT_BASIC_SETTINGS_SIZE @@ -95,6 +106,11 @@ # define DAT_EXTDCONTR_CRED_SIZE 1024 #endif // ifndef DAT_EXTDCONTR_CRED_SIZE +#ifndef DAT_CDN_SIZE +# define DAT_CDN_SIZE 1024 +#endif + + /* @@ -123,11 +139,15 @@ # define DAT_OFFSET_TASKS 4096 // 0x1000 each task = 2k, (1024 basic + 1024 bytes custom) # endif // ifndef DAT_OFFSET_TASKS # ifndef DAT_OFFSET_CONTROLLER - # define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller = 1k, 4 max + # define DAT_OFFSET_CONTROLLER (DAT_OFFSET_TASKS + (DAT_TASKS_DISTANCE * TASKS_MAX)) // each controller = 1k, 3 max, DAT_OFFSET_CDN is at position of any 4th controller. # endif // ifndef DAT_OFFSET_CONTROLLER # ifndef DAT_OFFSET_CUSTOM_CONTROLLER - # define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller config = 1k, 4 max + # define DAT_OFFSET_CUSTOM_CONTROLLER (DAT_OFFSET_CONTROLLER + (DAT_CONTROLLER_SIZE * CONTROLLER_MAX)) // each custom controller config = 1k, 3 max # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_CUSTOM_CONTROLLER - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif + # ifndef CONFIG_FILE_SIZE # define CONFIG_FILE_SIZE 65536 # endif // ifndef CONFIG_FILE_SIZE @@ -143,6 +163,9 @@ # ifndef DAT_OFFSET_CUSTOM_CONTROLLER # define DAT_OFFSET_CUSTOM_CONTROLLER 32768 // each custom controller config = 1k, 4 max. # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_TASKS - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif # ifdef LIMIT_BUILD_SIZE // Limit the config size for 1M builds, since their file system is also quite small # ifndef CONFIG_FILE_SIZE @@ -166,6 +189,9 @@ # ifndef DAT_OFFSET_CUSTOM_CONTROLLER # define DAT_OFFSET_CUSTOM_CONTROLLER 12288 // each custom controller config = 1k, 4 max. # endif // ifndef DAT_OFFSET_CUSTOM_CONTROLLER + # ifndef DAT_OFFSET_CDN + # define DAT_OFFSET_CDN (DAT_OFFSET_CONTROLLER - DAT_CDN_SIZE) // single CDN settings block of 1k + # endif # ifndef CONFIG_FILE_SIZE # define CONFIG_FILE_SIZE 131072 # endif // ifndef CONFIG_FILE_SIZE diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index 8e5333fec7..bcff52e2dd 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -1606,6 +1606,9 @@ To create/register a plugin, you have to : #ifndef USES_P154 #define USES_P154 // Environment - BMP3xx #endif + #ifndef USES_P159 + #define USES_P159 // Presence - LD2410 Radar detection + #endif #endif @@ -2276,6 +2279,9 @@ To create/register a plugin, you have to : #ifndef USES_P154 #define USES_P154 // Environment - BMP3xx #endif + #ifndef USES_P159 + #define USES_P159 // Presence - LD2410 Radar detection + #endif // Controllers #ifndef USES_C015 @@ -2942,8 +2948,22 @@ To create/register a plugin, you have to : #endif #ifndef FEATURE_SETTINGS_ARCHIVE +#ifdef ESP32 +#define FEATURE_SETTINGS_ARCHIVE 1 +#else #define FEATURE_SETTINGS_ARCHIVE 0 #endif +#endif + + +#if FEATURE_SETTINGS_ARCHIVE +#if defined(FEATURE_DOWNLOAD) && !FEATURE_DOWNLOAD +#undef FEATURE_DOWNLOAD +#endif +#ifndef FEATURE_DOWNLOAD +#define FEATURE_DOWNLOAD 1 +#endif +#endif #ifndef FEATURE_SSDP #define FEATURE_SSDP 0 @@ -3167,18 +3187,39 @@ To create/register a plugin, you have to : #ifndef FEATURE_CHART_STORAGE_LAYOUT #ifdef ESP32 - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 1 + #define FEATURE_CHART_STORAGE_LAYOUT 1 #endif #ifdef ESP8266 #ifndef LIMIT_BUILD_SIZE - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 1 + #define FEATURE_CHART_STORAGE_LAYOUT 1 #else - #define FEATURE_CHART_SETTINGS_FILE_LAYOUT 0 + #define FEATURE_CHART_STORAGE_LAYOUT 0 #endif #endif #endif - +#if !defined(CUSTOM_BUILD_CDN_URL) && !defined(FEATURE_ALTERNATIVE_CDN_URL) + #if defined(WEBSERVER_EMBED_CUSTOM_CSS) || defined(EMBED_ESPEASY_DEFAULT_MIN_CSS) || defined(EMBED_ESPEASY_DEFAULT_MIN_CSS_USE_GZ) + #define FEATURE_ALTERNATIVE_CDN_URL 0 // No need to configure custom CDN url when all content is included in build + #else + #define FEATURE_ALTERNATIVE_CDN_URL 1 + #endif +#endif // if !defined(CUSTOM_BUILD_CDN_URL) +#if defined(FEATURE_ALTERNATIVE_CDN_URL) && FEATURE_ALTERNATIVE_CDN_URL && defined(PLUGIN_BUILD_MINIMAL_OTA) + #undef FEATURE_ALTERNATIVE_CDN_URL + #define FEATURE_ALTERNATIVE_CDN_URL 0 +#endif + + + +// TODO TD-er: Test feature, must remove +/* +#ifdef FEATURE_ALTERNATIVE_CDN_URL +#undef FEATURE_ALTERNATIVE_CDN_URL +#endif +#define FEATURE_ALTERNATIVE_CDN_URL 1 +*/ + #endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H diff --git a/src/src/DataStructs/DeviceStruct.h b/src/src/DataStructs/DeviceStruct.h index 76cdf001f2..45d05a47b4 100644 --- a/src/src/DataStructs/DeviceStruct.h +++ b/src/src/DataStructs/DeviceStruct.h @@ -93,6 +93,7 @@ struct __attribute__((__packed__)) DeviceStruct // (F.e.: M5Stack Core/Core2 needs to power the TFT before SPI can be started) bool TaskLogsOwnPeaks : 1; // When PluginStats is enabled, a call to PLUGIN_READ will also check for peaks. With this enabled, the plugin must call to check for peaks itself. bool I2CNoDeviceCheck : 1; // When enabled, NO I2C check will be done on the I2C address returned from PLUGIN_I2C_GET_ADDRESS function call + bool I2CMax100kHz : 1; // When enabled, the device is only able to handle 100 kHz bus-clock speed, shows warning and enables "Force Slow I2C speed" by default }; diff --git a/src/src/DataStructs/FactoryDefaultPref.cpp b/src/src/DataStructs/FactoryDefaultPref.cpp index ba9401b42e..58023c5e9e 100644 --- a/src/src/DataStructs/FactoryDefaultPref.cpp +++ b/src/src/DataStructs/FactoryDefaultPref.cpp @@ -1,133 +1,167 @@ #include "../DataStructs/FactoryDefaultPref.h" #include "../../ESPEasy_common.h" -/* + ResetFactoryDefaultPreference_struct::ResetFactoryDefaultPreference_struct(uint32_t preference) : _preference(preference) {} -DeviceModel ResetFactoryDefaultPreference_struct::getDeviceModel() const { - return static_cast(_preference & 0xFF); +void ResetFactoryDefaultPreference_struct::set(uint32_t preference) +{ + _preference = preference; } -void ResetFactoryDefaultPreference_struct::setDeviceModel(DeviceModel model) { - _preference &= ~(0xFF); // set DeviceModel bits to 0 - _preference |= static_cast(model); -} +#ifdef ESP32 -bool ResetFactoryDefaultPreference_struct::keepWiFi() const { - return bitRead(_preference, 9); -} +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_PREF_KEY "FacDefPref" -void ResetFactoryDefaultPreference_struct::keepWiFi(bool keep) { - bitWrite(_preference, 9, keep); -} +bool ResetFactoryDefaultPreference_struct::init() +{ + ESPEasy_NVS_Helper nvs_helper; -bool ResetFactoryDefaultPreference_struct::keepNTP() const { - return bitRead(_preference, 10); + if (nvs_helper.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE))) { + return from_NVS(nvs_helper); + } + return false; } -void ResetFactoryDefaultPreference_struct::keepNTP(bool keep) { - bitWrite(_preference, 10, keep); +bool ResetFactoryDefaultPreference_struct::from_NVS(ESPEasy_NVS_Helper& preferences) +{ + return preferences.getPreference(F(FACTORY_DEFAULT_NVS_PREF_KEY), _preference); } -bool ResetFactoryDefaultPreference_struct::keepNetwork() const { - return bitRead(_preference, 11); +void ResetFactoryDefaultPreference_struct::to_NVS(ESPEasy_NVS_Helper& preferences) const +{ + preferences.setPreference(F(FACTORY_DEFAULT_NVS_PREF_KEY), _preference); } -void ResetFactoryDefaultPreference_struct::keepNetwork(bool keep) { - bitWrite(_preference, 11, keep); -} +#endif // ifdef ESP32 -bool ResetFactoryDefaultPreference_struct::keepLogSettings() const { - return bitRead(_preference, 12); -} -void ResetFactoryDefaultPreference_struct::keepLogSettings(bool keep) { - bitWrite(_preference, 12, keep); -} +/* + DeviceModel ResetFactoryDefaultPreference_struct::getDeviceModel() const { + return static_cast(_preference & 0xFF); + } + + void ResetFactoryDefaultPreference_struct::setDeviceModel(DeviceModel model) { + _preference &= ~(0xFF); // set DeviceModel bits to 0 + _preference |= static_cast(model); + } + + bool ResetFactoryDefaultPreference_struct::keepWiFi() const { + return bitRead(_preference, 9); + } + + void ResetFactoryDefaultPreference_struct::keepWiFi(bool keep) { + bitWrite(_preference, 9, keep); + } + + bool ResetFactoryDefaultPreference_struct::keepNTP() const { + return bitRead(_preference, 10); + } + + void ResetFactoryDefaultPreference_struct::keepNTP(bool keep) { + bitWrite(_preference, 10, keep); + } -bool ResetFactoryDefaultPreference_struct::keepUnitName() const { - return bitRead(_preference, 13); -} + bool ResetFactoryDefaultPreference_struct::keepNetwork() const { + return bitRead(_preference, 11); + } -void ResetFactoryDefaultPreference_struct::keepUnitName(bool keep) { - bitWrite(_preference, 13, keep); -} + void ResetFactoryDefaultPreference_struct::keepNetwork(bool keep) { + bitWrite(_preference, 11, keep); + } -// filenr = 0...3 for files rules1.txt ... rules4.txt -bool ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr) const { - return bitRead(_preference, 14 + filenr); -} + bool ResetFactoryDefaultPreference_struct::keepLogConsoleSettings() const { + return bitRead(_preference, 12); + } -void ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr, bool fetch) { - bitWrite(_preference, 14 + filenr, fetch); -} + void ResetFactoryDefaultPreference_struct::keepLogConsoleSettings(bool keep) { + bitWrite(_preference, 12, keep); + } -bool ResetFactoryDefaultPreference_struct::fetchNotificationDat() const { - return bitRead(_preference, 18); -} + bool ResetFactoryDefaultPreference_struct::keepUnitName() const { + return bitRead(_preference, 13); + } -void ResetFactoryDefaultPreference_struct::fetchNotificationDat(bool fetch) { - bitWrite(_preference, 18, fetch); -} + void ResetFactoryDefaultPreference_struct::keepUnitName(bool keep) { + bitWrite(_preference, 13, keep); + } -bool ResetFactoryDefaultPreference_struct::fetchSecurityDat() const { - return bitRead(_preference, 19); -} + // filenr = 0...3 for files rules1.txt ... rules4.txt + bool ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr) const { + return bitRead(_preference, 14 + filenr); + } -void ResetFactoryDefaultPreference_struct::fetchSecurityDat(bool fetch) { - bitWrite(_preference, 19, fetch); -} + void ResetFactoryDefaultPreference_struct::fetchRulesTXT(int filenr, bool fetch) { + bitWrite(_preference, 14 + filenr, fetch); + } -bool ResetFactoryDefaultPreference_struct::fetchConfigDat() const { - return bitRead(_preference, 20); -} + bool ResetFactoryDefaultPreference_struct::fetchNotificationDat() const { + return bitRead(_preference, 18); + } -void ResetFactoryDefaultPreference_struct::fetchConfigDat(bool fetch) { - bitWrite(_preference, 20, fetch); -} + void ResetFactoryDefaultPreference_struct::fetchNotificationDat(bool fetch) { + bitWrite(_preference, 18, fetch); + } -bool ResetFactoryDefaultPreference_struct::deleteFirst() const { - return bitRead(_preference, 21); -} + bool ResetFactoryDefaultPreference_struct::fetchSecurityDat() const { + return bitRead(_preference, 19); + } -void ResetFactoryDefaultPreference_struct::deleteFirst(bool checked) { - bitWrite(_preference, 21, checked); -} + void ResetFactoryDefaultPreference_struct::fetchSecurityDat(bool fetch) { + bitWrite(_preference, 19, fetch); + } -bool ResetFactoryDefaultPreference_struct::delete_Bak_Files() const { - return bitRead(_preference, 23); -} + bool ResetFactoryDefaultPreference_struct::fetchConfigDat() const { + return bitRead(_preference, 20); + } -void ResetFactoryDefaultPreference_struct::delete_Bak_Files(bool checked) { - bitWrite(_preference, 23, checked); -} + void ResetFactoryDefaultPreference_struct::fetchConfigDat(bool fetch) { + bitWrite(_preference, 20, fetch); + } -bool ResetFactoryDefaultPreference_struct::saveURL() const { - return bitRead(_preference, 22); -} + bool ResetFactoryDefaultPreference_struct::deleteFirst() const { + return bitRead(_preference, 21); + } -void ResetFactoryDefaultPreference_struct::saveURL(bool checked) { - bitWrite(_preference, 22, checked); -} + void ResetFactoryDefaultPreference_struct::deleteFirst(bool checked) { + bitWrite(_preference, 21, checked); + } -bool ResetFactoryDefaultPreference_struct::storeCredentials() const { - return bitRead(_preference, 24); -} + bool ResetFactoryDefaultPreference_struct::delete_Bak_Files() const { + return bitRead(_preference, 23); + } -void ResetFactoryDefaultPreference_struct::storeCredentials(bool checked) { - bitWrite(_preference, 24, checked); -} + void ResetFactoryDefaultPreference_struct::delete_Bak_Files(bool checked) { + bitWrite(_preference, 23, checked); + } -bool ResetFactoryDefaultPreference_struct::fetchProvisioningDat() const { - return bitRead(_preference, 25); -} + bool ResetFactoryDefaultPreference_struct::saveURL() const { + return bitRead(_preference, 22); + } -void ResetFactoryDefaultPreference_struct::fetchProvisioningDat(bool checked) { - bitWrite(_preference, 25, checked); -} + void ResetFactoryDefaultPreference_struct::saveURL(bool checked) { + bitWrite(_preference, 22, checked); + } + bool ResetFactoryDefaultPreference_struct::storeCredentials() const { + return bitRead(_preference, 24); + } -uint32_t ResetFactoryDefaultPreference_struct::getPreference() { - return _preference; -} -*/ \ No newline at end of file + void ResetFactoryDefaultPreference_struct::storeCredentials(bool checked) { + bitWrite(_preference, 24, checked); + } + + bool ResetFactoryDefaultPreference_struct::fetchProvisioningDat() const { + return bitRead(_preference, 25); + } + + void ResetFactoryDefaultPreference_struct::fetchProvisioningDat(bool checked) { + bitWrite(_preference, 25, checked); + } + + + uint32_t ResetFactoryDefaultPreference_struct::getPreference() { + return _preference; + } + */ diff --git a/src/src/DataStructs/FactoryDefaultPref.h b/src/src/DataStructs/FactoryDefaultPref.h index 68c1ffe9bd..57b23d10a3 100644 --- a/src/src/DataStructs/FactoryDefaultPref.h +++ b/src/src/DataStructs/FactoryDefaultPref.h @@ -7,31 +7,45 @@ #include "../../ESPEasy_common.h" +#ifdef ESP32 +# include "../Helpers/ESPEasy_NVS_Helper.h" +#endif // ifdef ESP32 + struct ResetFactoryDefaultPreference_struct { - ResetFactoryDefaultPreference_struct(uint32_t preference = 0) : _preference(preference) {} + ResetFactoryDefaultPreference_struct(uint32_t preference = 0); + + void set(uint32_t preference); + +#ifdef ESP32 + bool init(); + bool from_NVS(ESPEasy_NVS_Helper& preferences); + + void to_NVS(ESPEasy_NVS_Helper& preferences) const; +#endif // ifdef ESP32 private: union { struct { - uint32_t deviceModel : 8; - uint32_t unused_bit8 : 1; - uint32_t keepWiFi : 1; - uint32_t keepNTP : 1; - uint32_t keepNetwork : 1; - uint32_t keepLogSettings : 1; - uint32_t keepUnitName : 1; - uint32_t fetchRulesFile : 4; - uint32_t fetchNotificationDat : 1; - uint32_t fetchSecurityDat : 1; - uint32_t fetchConfigDat : 1; - uint32_t deleteFirst : 1; - uint32_t saveURL : 1; - uint32_t delete_Bak_Files : 1; - uint32_t storeCredentials : 1; - uint32_t fetchProvisioningDat : 1; - - uint32_t unused : 6; + uint32_t deviceModel : 8; + uint32_t unused_bit8 : 1; + uint32_t keepWiFi : 1; + uint32_t keepNTP : 1; + uint32_t keepNetwork : 1; + uint32_t keepLogConsoleSettings : 1; + uint32_t keepUnitName : 1; + uint32_t fetchRulesFile : 4; + uint32_t fetchNotificationDat : 1; + uint32_t fetchSecurityDat : 1; + uint32_t fetchConfigDat : 1; + uint32_t deleteFirst : 1; + uint32_t saveURL : 1; + uint32_t delete_Bak_Files : 1; + uint32_t storeCredentials : 1; + uint32_t fetchProvisioningDat : 1; + uint32_t keepCustomCdnUrl : 1; + + uint32_t unused : 5; } bits; uint32_t _preference{}; }; @@ -70,12 +84,12 @@ struct ResetFactoryDefaultPreference_struct { bits.keepNetwork = keep; } - bool keepLogSettings() const { - return bits.keepLogSettings; + bool keepLogConsoleSettings() const { + return bits.keepLogConsoleSettings; } - void keepLogSettings(bool keep) { - bits.keepLogSettings = keep; + void keepLogConsoleSettings(bool keep) { + bits.keepLogConsoleSettings = keep; } bool keepUnitName() const { @@ -86,12 +100,20 @@ struct ResetFactoryDefaultPreference_struct { bits.keepUnitName = keep; } + bool keepCustomCdnUrl() const { + return bits.keepCustomCdnUrl; + } + + void keepCustomCdnUrl(bool keep) { + bits.keepCustomCdnUrl = keep; + } + // filenr = 0...3 for files rules1.txt ... rules4.txt bool fetchRulesTXT(int filenr) const { return bitRead(bits.fetchRulesFile, filenr); } - void fetchRulesTXT(int filenr, bool fetch) { + void fetchRulesTXT(int filenr, bool fetch) { bitWrite(bits.fetchRulesFile, filenr, fetch); } @@ -159,7 +181,7 @@ struct ResetFactoryDefaultPreference_struct { bits.storeCredentials = checked; } - uint32_t getPreference() { + uint32_t getPreference() const { return _preference; } diff --git a/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp new file mode 100644 index 0000000000..69b10f41d8 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.cpp @@ -0,0 +1,32 @@ +#include "../DataStructs/FactoryDefault_CDN_customurl_NVS.h" + +#ifdef ESP32 + +# if FEATURE_ALTERNATIVE_CDN_URL +# include "../Helpers/ESPEasy_Storage.h" + +# define FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY "CDN_customurl" + +bool FactoryDefault_CDN_customurl_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + String _url; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY), _url)) { + set_CDN_url_custom(_url); + return true; + } + return false; +} + +void FactoryDefault_CDN_customurl_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.setPreference(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY), get_CDN_url_custom()); +} + +void FactoryDefault_CDN_customurl_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_CDN_CUSTOMURL_KEY)); +} + +# endif // if FEATURE_ALTERNATIVE_CDN_URL +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h new file mode 100644 index 0000000000..550340d46f --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_CDN_customurl_NVS.h @@ -0,0 +1,25 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H + + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 +# if FEATURE_ALTERNATIVE_CDN_URL + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_CDN_customurl_NVS { +public: + + static bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + static void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + static void clear_from_NVS(ESPEasy_NVS_Helper& preferences); +}; + +# endif // if FEATURE_ALTERNATIVE_CDN_URL +#endif // ifdef ESP32 + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_CDN_CUSTOMURL_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp new file mode 100644 index 0000000000..fe94739da2 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.cpp @@ -0,0 +1,77 @@ +#include "../DataStructs/FactoryDefault_LogConsoleSettings_NVS.h" + + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY "Log" +# define FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY "Console" + + +bool FactoryDefault_LogConsoleSettings_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + bool updated = false; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY), LogSettings)) { + updated = true; + Settings.SyslogLevel = LogSettings_bits.SyslogLevel; + Settings.SerialLogLevel = LogSettings_bits.SerialLogLevel; + Settings.WebLogLevel = LogSettings_bits.WebLogLevel; + Settings.SDLogLevel = LogSettings_bits.SDLogLevel; + Settings.SyslogFacility = LogSettings_bits.SyslogFacility; + Settings.SyslogPort = LogSettings_bits.SyslogPort; + + for (size_t i = 0; i < 4; ++i) { + Settings.Syslog_IP[i] = LogSettings_bits.Syslog_IP[i]; + } + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY), ConsoleSettings)) { + updated = true; + Settings.console_serial_port = ConsoleSettings_bits.console_serial_port; + Settings.UseSerial = ConsoleSettings_bits.UseSerial; + Settings.console_serial_rxpin = ConsoleSettings_bits.console_serial_rxpin; + Settings.console_serial_txpin = ConsoleSettings_bits.console_serial_txpin; + Settings.console_serial0_fallback = ConsoleSettings_bits.console_serial0_fallback; + Settings.BaudRate = ConsoleSettings_bits.BaudRate; + } + return updated; +} + +void FactoryDefault_LogConsoleSettings_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + { + LogSettings_bits.SyslogLevel = Settings.SyslogLevel; + LogSettings_bits.SerialLogLevel = Settings.SerialLogLevel; + LogSettings_bits.WebLogLevel = Settings.WebLogLevel; + LogSettings_bits.SDLogLevel = Settings.SDLogLevel; + LogSettings_bits.SyslogFacility = Settings.SyslogFacility; + LogSettings_bits.SyslogPort = Settings.SyslogPort; + + for (size_t i = 0; i < 4; ++i) { + LogSettings_bits.Syslog_IP[i] = Settings.Syslog_IP[i]; + } + preferences.setPreference(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY), LogSettings); + } + { + ConsoleSettings_bits.console_serial_port = Settings.console_serial_port; + ConsoleSettings_bits.UseSerial = Settings.UseSerial; + ConsoleSettings_bits.console_serial_rxpin = Settings.console_serial_rxpin; + ConsoleSettings_bits.console_serial_txpin = Settings.console_serial_txpin; + ConsoleSettings_bits.console_serial0_fallback = Settings.console_serial0_fallback; + ConsoleSettings_bits.BaudRate = Settings.BaudRate; + + preferences.setPreference(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY), ConsoleSettings); + } +} + +void FactoryDefault_LogConsoleSettings_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_LOG_SETTINGS_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_CONSOLE_SETTINGS_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h new file mode 100644 index 0000000000..d43c4529de --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_LogConsoleSettings_NVS.h @@ -0,0 +1,50 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_LogConsoleSettings_NVS { +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + union { + struct { + uint64_t SyslogLevel : 3; + uint64_t SerialLogLevel : 3; + uint64_t WebLogLevel : 3; + uint64_t SDLogLevel : 3; + uint64_t SyslogFacility : 4; + uint64_t SyslogPort : 16; + uint8_t Syslog_IP[4]; + } LogSettings_bits; + + uint64_t LogSettings{}; + }; + + union { + struct { + uint8_t console_serial_port : 7; + uint8_t UseSerial : 1; + int8_t console_serial_rxpin; + int8_t console_serial_txpin; + uint8_t console_serial0_fallback; + uint32_t BaudRate; + } ConsoleSettings_bits; + + uint64_t ConsoleSettings{}; + }; +}; + +#endif // ifdef ESP32 +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_LOG_CONSOLE_SETTINGS_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.cpp b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp new file mode 100644 index 0000000000..97a65c4437 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.cpp @@ -0,0 +1,87 @@ +#include "../DataStructs/FactoryDefault_Network_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_WIFI_IP_KEY "WiFI_IP" +# ifdef FEATURE_ETHERNET +# define FACTORY_DEFAULT_NVS_ETH_IP_KEY "ETH_IP" +# define FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY "ETH_HW_CONF" +# endif // ifdef FEATURE_ETHERNET + +bool FactoryDefault_Network_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + bool res = false; + + uint8_t *write = reinterpret_cast(&Settings); + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY), IP_data, sizeof(IP_data))) { + // TD-er: This data is stored in sequence, so we can do a single memcpy call + constexpr unsigned int offset = offsetof(SettingsStruct, IP); + memcpy(write + offset, IP_data, sizeof(IP_data)); + res = true; + } +# ifdef FEATURE_ETHERNET + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY), IP_data, sizeof(IP_data))) { + constexpr unsigned int offset = offsetof(SettingsStruct, ETH_IP); + + memcpy(write + offset, IP_data, sizeof(IP_data)); + res = true; + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY), ETH_HW_conf)) { + Settings.ETH_Phy_Addr = bits.ETH_Phy_Addr; + Settings.ETH_Pin_mdc = bits.ETH_Pin_mdc; + Settings.ETH_Pin_mdio = bits.ETH_Pin_mdio; + Settings.ETH_Pin_power = bits.ETH_Pin_power; + Settings.ETH_Phy_Type = static_cast(bits.ETH_Phy_Type); + Settings.ETH_Clock_Mode = static_cast(bits.ETH_Clock_Mode); + Settings.NetworkMedium = static_cast(bits.NetworkMedium); + res = true; + } +# endif // ifdef FEATURE_ETHERNET + return res; +} + +void FactoryDefault_Network_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) +{ + const uint8_t *read = reinterpret_cast(&Settings); + + { + constexpr unsigned int offset = offsetof(SettingsStruct, IP); + memcpy(IP_data, read + offset, sizeof(IP_data)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY), IP_data, sizeof(IP_data)); + } +# ifdef FEATURE_ETHERNET + { + constexpr unsigned int offset = offsetof(SettingsStruct, ETH_IP); + memcpy(IP_data, read + offset, sizeof(IP_data)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY), IP_data, sizeof(IP_data)); + } + { + bits.ETH_Phy_Addr = Settings.ETH_Phy_Addr; + bits.ETH_Pin_mdc = Settings.ETH_Pin_mdc; + bits.ETH_Pin_mdio = Settings.ETH_Pin_mdio; + bits.ETH_Pin_power = Settings.ETH_Pin_power; + bits.ETH_Phy_Type = static_cast(Settings.ETH_Phy_Type); + bits.ETH_Clock_Mode = static_cast(Settings.ETH_Clock_Mode); + bits.NetworkMedium = static_cast(Settings.NetworkMedium); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_ETH_HW_CONF_KEY), ETH_HW_conf); + } +# endif // ifdef FEATURE_ETHERNET +} + +void FactoryDefault_Network_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) +{ + preferences.remove(F(FACTORY_DEFAULT_NVS_WIFI_IP_KEY)); +# ifdef FEATURE_ETHERNET + preferences.remove(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_ETH_IP_KEY)); +# endif // ifdef FEATURE_ETHERNET +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_Network_NVS.h b/src/src/DataStructs/FactoryDefault_Network_NVS.h new file mode 100644 index 0000000000..7ed42dc243 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_Network_NVS.h @@ -0,0 +1,49 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + +class FactoryDefault_Network_NVS { +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + // IP + // GW + // SN + // DNS + uint8_t IP_data[16]{}; + +# ifdef FEATURE_ETHERNET + + union { + struct { + int8_t ETH_Phy_Addr; + int8_t ETH_Pin_mdc; + int8_t ETH_Pin_mdio; + int8_t ETH_Pin_power; + uint8_t ETH_Phy_Type; + uint8_t ETH_Clock_Mode; + uint8_t NetworkMedium; + uint8_t unused; + } bits; + + uint64_t ETH_HW_conf{}; + }; + + +# endif // ifdef FEATURE_ETHERNET +}; + +#endif // ifdef ESP32 +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_NETWORK_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp b/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp new file mode 100644 index 0000000000..08c67b7f94 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_UnitName_NVS.cpp @@ -0,0 +1,41 @@ +#include "../DataStructs/FactoryDefault_UnitName_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_UNIT_NAME_KEY "UnitName" + + +void FactoryDefault_UnitName_NVS::fromSettings() { + bitWrite(data[1], 0, Settings.appendUnitToHostname()); + data[0] = Settings.Unit; + memcpy((char *)(data + 2), Settings.Name, sizeof(Settings.Name)); +} + +void FactoryDefault_UnitName_NVS::applyToSettings() const { + Settings.appendUnitToHostname(bitRead(data[1], 0)); + Settings.Unit = data[0]; + memcpy(Settings.Name, (char *)(data + 2), sizeof(Settings.Name)); +} + +bool FactoryDefault_UnitName_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) { + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY), data, sizeof(data))) { + applyToSettings(); + return true; + } + return false; +} + +void FactoryDefault_UnitName_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) { + fromSettings(); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY), data, sizeof(data)); +} + +void FactoryDefault_UnitName_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) { + preferences.remove(F(FACTORY_DEFAULT_NVS_UNIT_NAME_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_UnitName_NVS.h b/src/src/DataStructs/FactoryDefault_UnitName_NVS.h new file mode 100644 index 0000000000..32fd261b6f --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_UnitName_NVS.h @@ -0,0 +1,39 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + + +class FactoryDefault_UnitName_NVS { +private: + + void fromSettings(); + + void applyToSettings() const; + +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + // Used data: + // byte 0: Unitnr + // byte 1: flags + // byte 2 ... 28 hostname + uint8_t data[32]{}; +}; + + +#endif // ifdef ESP32 + + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_UNITNAME_NVS_H diff --git a/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp b/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp new file mode 100644 index 0000000000..db31abf943 --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_WiFi_NVS.cpp @@ -0,0 +1,101 @@ +#include "../DataStructs/FactoryDefault_WiFi_NVS.h" + +#ifdef ESP32 + +# include "../Globals/Settings.h" +# include "../Globals/SecuritySettings.h" +# include "../Helpers/StringConverter.h" + +// Max. 15 char keys for ESPEasy Factory Default marked keys +# define FACTORY_DEFAULT_NVS_SSID1_KEY "WIFI_SSID1" +# define FACTORY_DEFAULT_NVS_WPA_PASS1_KEY "WIFI_PASS1" +# define FACTORY_DEFAULT_NVS_SSID2_KEY "WIFI_SSID2" +# define FACTORY_DEFAULT_NVS_WPA_PASS2_KEY "WIFI_PASS2" +# define FACTORY_DEFAULT_NVS_AP_PASS_KEY "WIFI_AP_PASS" +# define FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY "WIFI_Flags" + + +void FactoryDefault_WiFi_NVS::fromSettings() { + bits.IncludeHiddenSSID = Settings.IncludeHiddenSSID(); + bits.ApDontForceSetup = Settings.ApDontForceSetup(); + bits.DoNotStartAP = Settings.DoNotStartAP(); + bits.ForceWiFi_bg_mode = Settings.ForceWiFi_bg_mode(); + bits.WiFiRestart_connection_lost = Settings.WiFiRestart_connection_lost(); + bits.WifiNoneSleep = Settings.WifiNoneSleep(); + bits.gratuitousARP = Settings.gratuitousARP(); + bits.UseMaxTXpowerForSending = Settings.UseMaxTXpowerForSending(); + bits.UseLastWiFiFromRTC = Settings.UseLastWiFiFromRTC(); + bits.WaitWiFiConnect = Settings.WaitWiFiConnect(); + bits.SDK_WiFi_autoreconnect = Settings.SDK_WiFi_autoreconnect(); + bits.HiddenSSID_SlowConnectPerBSSID = Settings.HiddenSSID_SlowConnectPerBSSID(); +} + +void FactoryDefault_WiFi_NVS::applyToSettings() const { + Settings.IncludeHiddenSSID(bits.IncludeHiddenSSID); + Settings.ApDontForceSetup(bits.ApDontForceSetup); + Settings.DoNotStartAP(bits.DoNotStartAP); + Settings.ForceWiFi_bg_mode(bits.ForceWiFi_bg_mode); + Settings.WiFiRestart_connection_lost(bits.WiFiRestart_connection_lost); + Settings.WifiNoneSleep(bits.WifiNoneSleep); + Settings.gratuitousARP(bits.gratuitousARP); + Settings.UseMaxTXpowerForSending(bits.UseMaxTXpowerForSending); + Settings.UseLastWiFiFromRTC(bits.UseLastWiFiFromRTC); + Settings.WaitWiFiConnect(bits.WaitWiFiConnect); + Settings.SDK_WiFi_autoreconnect(bits.SDK_WiFi_autoreconnect); + Settings.HiddenSSID_SlowConnectPerBSSID(bits.HiddenSSID_SlowConnectPerBSSID); +} + +bool FactoryDefault_WiFi_NVS::applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences) { + String tmp; + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_SSID1_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiSSID, tmp, sizeof(SecuritySettings.WifiSSID)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiKey, tmp, sizeof(SecuritySettings.WifiKey)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_SSID2_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiSSID2, tmp, sizeof(SecuritySettings.WifiSSID2)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiKey2, tmp, sizeof(SecuritySettings.WifiKey2)); + } + + if (preferences.getPreference(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY), tmp)) { + safe_strncpy(SecuritySettings.WifiAPKey, tmp, sizeof(SecuritySettings.WifiAPKey)); + } + + + if (!preferences.getPreference(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY), data)) { + return false; + } + + applyToSettings(); + return true; +} + +void FactoryDefault_WiFi_NVS::fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences) { + fromSettings(); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY), data); + + // Store WiFi credentials + preferences.setPreference(F(FACTORY_DEFAULT_NVS_SSID1_KEY), String(SecuritySettings.WifiSSID)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY), String(SecuritySettings.WifiKey)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_SSID2_KEY), String(SecuritySettings.WifiSSID2)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY), String(SecuritySettings.WifiKey2)); + preferences.setPreference(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY), String(SecuritySettings.WifiAPKey)); +} + +void FactoryDefault_WiFi_NVS::clear_from_NVS(ESPEasy_NVS_Helper& preferences) { + preferences.remove(F(FACTORY_DEFAULT_NVS_SSID1_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WPA_PASS1_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_SSID2_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WPA_PASS2_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_AP_PASS_KEY)); + preferences.remove(F(FACTORY_DEFAULT_NVS_WIFI_FLAGS_KEY)); +} + +#endif // ifdef ESP32 diff --git a/src/src/DataStructs/FactoryDefault_WiFi_NVS.h b/src/src/DataStructs/FactoryDefault_WiFi_NVS.h new file mode 100644 index 0000000000..f184abdd7b --- /dev/null +++ b/src/src/DataStructs/FactoryDefault_WiFi_NVS.h @@ -0,0 +1,55 @@ +#ifndef DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H +#define DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H + + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +# include "../Helpers/ESPEasy_NVS_Helper.h" + + +class FactoryDefault_WiFi_NVS { +private: + + void fromSettings(); + + void applyToSettings() const; + +public: + + bool applyToSettings_from_NVS(ESPEasy_NVS_Helper& preferences); + + void fromSettings_to_NVS(ESPEasy_NVS_Helper& preferences); + + void clear_from_NVS(ESPEasy_NVS_Helper& preferences); + +private: + + union { + struct { + uint64_t IncludeHiddenSSID : 1; + uint64_t ApDontForceSetup : 1; + uint64_t DoNotStartAP : 1; + uint64_t ForceWiFi_bg_mode : 1; + uint64_t WiFiRestart_connection_lost : 1; + uint64_t WifiNoneSleep : 1; + uint64_t gratuitousARP : 1; + uint64_t UseMaxTXpowerForSending : 1; + uint64_t UseLastWiFiFromRTC : 1; + uint64_t WaitWiFiConnect : 1; + uint64_t SDK_WiFi_autoreconnect : 1; + uint64_t HiddenSSID_SlowConnectPerBSSID : 1; + + uint64_t unused : 52; + } bits; + + uint64_t data{}; + }; +}; + + +#endif // ifdef ESP32 + + +#endif // ifndef DATASTRUCTS_FACTORYDEFAULT_WIFI_NVS_H diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index 8c56888ca7..611f6f6af8 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -170,17 +170,23 @@ class SettingsStruct_tmpl // Wait for a second after calling WiFi.begin() // Especially useful for some FritzBox routers. - bool WaitWiFiConnect() const; - void WaitWiFiConnect(bool value); + bool WaitWiFiConnect() const { return VariousBits_2.WaitWiFiConnect; } + void WaitWiFiConnect(bool value) { VariousBits_2.WaitWiFiConnect = value; } + + // Connect to Hidden SSID using channel and BSSID + // This is much slower, but appears to be needed for some access points + // like MikroTik. + bool HiddenSSID_SlowConnectPerBSSID() const { return !VariousBits_2.HiddenSSID_SlowConnectPerBSSID; } + void HiddenSSID_SlowConnectPerBSSID(bool value) { VariousBits_2.HiddenSSID_SlowConnectPerBSSID = !value; } // Use Espressif's auto reconnect. - bool SDK_WiFi_autoreconnect() const; - void SDK_WiFi_autoreconnect(bool value); + bool SDK_WiFi_autoreconnect() const { return VariousBits_2.SDK_WiFi_autoreconnect; } + void SDK_WiFi_autoreconnect(bool value) { VariousBits_2.SDK_WiFi_autoreconnect = value; } #if FEATURE_RULES_EASY_COLOR_CODE // Inhibit RulesCodeCompletion - bool DisableRulesCodeCompletion() const; - void DisableRulesCodeCompletion(bool value); + bool DisableRulesCodeCompletion() const { return VariousBits_2.DisableRulesCodeCompletion; } + void DisableRulesCodeCompletion(bool value) { VariousBits_2.DisableRulesCodeCompletion = value; } #endif // if FEATURE_RULES_EASY_COLOR_CODE @@ -300,6 +306,8 @@ class SettingsStruct_tmpl pluginID_t getPluginID_for_task(taskIndex_t taskIndex) const; + void forceSave() { memset(md5, 0, 16); } + unsigned long PID = 0; int Version = 0; @@ -433,7 +441,7 @@ class SettingsStruct_tmpl uint32_t ResetFactoryDefaultPreference = 0; // Do not clear this one in the clearAll() uint32_t I2C_clockSpeed = 400000; uint16_t WebserverPort = 80; - uint16_t SyslogPort = 0; + uint16_t SyslogPort = DEFAULT_SYSLOG_PORT; int8_t ETH_Phy_Addr = -1; int8_t ETH_Pin_mdc = -1; @@ -467,7 +475,46 @@ class SettingsStruct_tmpl // Do not rename or move this checksum. // Checksum calculation will work "around" this uint8_t md5[16]{}; // Store checksum of the settings. - uint32_t VariousBits2 = 0; + union { + // VariousBits2 defaults to 0, keep in mind when adding bit lookups. + struct { + uint32_t WaitWiFiConnect : 1; // Bit 00 + uint32_t SDK_WiFi_autoreconnect : 1; // Bit 01 + uint32_t DisableRulesCodeCompletion : 1; // Bit 02 + uint32_t HiddenSSID_SlowConnectPerBSSID : 1; // Bit 03 // inverted + uint32_t unused_04 : 1; // Bit 04 + uint32_t unused_05 : 1; // Bit 05 + uint32_t unused_06 : 1; // Bit 06 + uint32_t unused_07 : 1; // Bit 07 + uint32_t unused_08 : 1; // Bit 08 + uint32_t unused_09 : 1; // Bit 09 + uint32_t unused_10 : 1; // Bit 10 + uint32_t unused_11 : 1; // Bit 11 + uint32_t unused_12 : 1; // Bit 12 + uint32_t unused_13 : 1; // Bit 13 + uint32_t unused_14 : 1; // Bit 14 + uint32_t unused_15 : 1; // Bit 15 + uint32_t unused_16 : 1; // Bit 16 + uint32_t unused_17 : 1; // Bit 17 + uint32_t unused_18 : 1; // Bit 18 + uint32_t unused_19 : 1; // Bit 19 + uint32_t unused_20 : 1; // Bit 20 + uint32_t unused_21 : 1; // Bit 21 + uint32_t unused_22 : 1; // Bit 22 + uint32_t unused_23 : 1; // Bit 23 + uint32_t unused_24 : 1; // Bit 24 + uint32_t unused_25 : 1; // Bit 25 + uint32_t unused_26 : 1; // Bit 26 + uint32_t unused_27 : 1; // Bit 27 + uint32_t unused_28 : 1; // Bit 28 + uint32_t unused_29 : 1; // Bit 29 + uint32_t unused_30 : 1; // Bit 30 + uint32_t unused_31 : 1; // Bit 31 + + } VariousBits_2; + uint32_t VariousBits2 = 0; + }; + uint8_t console_serial_port = DEFAULT_CONSOLE_PORT; int8_t console_serial_rxpin = DEFAULT_CONSOLE_PORT_RXPIN; diff --git a/src/src/DataStructs/WiFi_AP_Candidate.cpp b/src/src/DataStructs/WiFi_AP_Candidate.cpp index b1a799e170..971b5dc701 100644 --- a/src/src/DataStructs/WiFi_AP_Candidate.cpp +++ b/src/src/DataStructs/WiFi_AP_Candidate.cpp @@ -41,6 +41,15 @@ WiFi_AP_Candidate::WiFi_AP_Candidate(uint8_t networkItem) : index(0), flags(0) { enc_type = WiFi.encryptionType(networkItem); #ifdef ESP8266 isHidden = WiFi.isHidden(networkItem); + #ifdef CORE_POST_3_0_0 + const bss_info* it = reinterpret_cast(WiFi.getScanInfoByIndex(networkItem)); + if (it) { + phy_11b = it->phy_11b; + phy_11g = it->phy_11g; + phy_11n = it->phy_11n; + wps = it->wps; + } + #endif #endif // ifdef ESP8266 #ifdef ESP32 isHidden = ssid.isEmpty(); diff --git a/src/src/DataStructs_templ/SettingsStruct.cpp b/src/src/DataStructs_templ/SettingsStruct.cpp index 46cde6a3f9..f55248ff5a 100644 --- a/src/src/DataStructs_templ/SettingsStruct.cpp +++ b/src/src/DataStructs_templ/SettingsStruct.cpp @@ -334,7 +334,7 @@ void SettingsStruct_tmpl::CheckI2Cdevice(bool value) { // Inverted } #endif // if FEATURE_I2C_DEVICE_CHECK */ - +/* template bool SettingsStruct_tmpl::WaitWiFiConnect() const { return bitRead(VariousBits2, 0); @@ -368,7 +368,7 @@ void SettingsStruct_tmpl::DisableRulesCodeCompletion(bool value) { bitWrite(VariousBits2, 2, value); } #endif // if FEATURE_RULES_EASY_COLOR_CODE - +*/ template diff --git a/src/src/DataTypes/SettingsType.cpp b/src/src/DataTypes/SettingsType.cpp index f2985f4a94..322a500f18 100644 --- a/src/src/DataTypes/SettingsType.cpp +++ b/src/src/DataTypes/SettingsType.cpp @@ -23,6 +23,9 @@ const __FlashStringHelper * SettingsType::getSettingsTypeString(Enum settingsTyp #endif case Enum::SecuritySettings_Type: return F("SecuritySettings"); case Enum::ExtdControllerCredentials_Type: return F("ExtendedControllerCredentials"); + #if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: return F("CDN_url"); + #endif case Enum::SettingsType_MAX: break; } @@ -109,6 +112,19 @@ bool SettingsType::getSettingsParameters(Enum settingsType, int index, int& max_ struct_size = 0; break; } +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: + { + max_index = 1; + offset = DAT_OFFSET_CDN; + max_size = DAT_CDN_SIZE; + + // struct_size may differ. + struct_size = 0; + } + break; +#endif + case Enum::SettingsType_MAX: { max_index = -1; @@ -177,6 +193,10 @@ unsigned int SettingsType::getSVGcolor(Enum settingsType) { return 0xff00a2; case Enum::ExtdControllerCredentials_Type: return 0xc300ff; +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: + return 0xff6600; +#endif case Enum::SettingsType_MAX: break; } @@ -193,6 +213,9 @@ SettingsType::SettingsFileEnum SettingsType::getSettingsFile(Enum settingsType) case Enum::CustomTaskSettings_Type: case Enum::ControllerSettings_Type: case Enum::CustomControllerSettings_Type: +#if FEATURE_ALTERNATIVE_CDN_URL + case Enum::CdnSettings_Type: +#endif return SettingsFileEnum::FILE_CONFIG_type; case Enum::NotificationSettings_Type: return SettingsFileEnum::FILE_NOTIFICATION_type; diff --git a/src/src/DataTypes/SettingsType.h b/src/src/DataTypes/SettingsType.h index a9f2477ee3..11c18ad761 100644 --- a/src/src/DataTypes/SettingsType.h +++ b/src/src/DataTypes/SettingsType.h @@ -16,6 +16,9 @@ class SettingsType { NotificationSettings_Type, SecuritySettings_Type, ExtdControllerCredentials_Type, +#if FEATURE_ALTERNATIVE_CDN_URL + CdnSettings_Type, +#endif SettingsType_MAX }; diff --git a/src/src/ESPEasyCore/ESPEasyWiFiEvent.cpp b/src/src/ESPEasyCore/ESPEasyWiFiEvent.cpp index 3752977b06..96d6da0ea7 100644 --- a/src/src/ESPEasyCore/ESPEasyWiFiEvent.cpp +++ b/src/src/ESPEasyCore/ESPEasyWiFiEvent.cpp @@ -139,8 +139,16 @@ void WiFiEvent(WiFiEvent_t event, arduino_event_info_t info) { ignoreDisconnectEvent = true; #if ESP_IDF_VERSION_MAJOR > 3 WiFiEventData.markDisconnect(static_cast(info.wifi_sta_disconnected.reason)); + if (info.wifi_sta_disconnected.reason == WIFI_REASON_AUTH_EXPIRE) { + // See: https://github.com/espressif/arduino-esp32/issues/8877#issuecomment-1807677897 + WiFiSTAClass::_setStatus(WL_CONNECTION_LOST); + } #else WiFiEventData.markDisconnect(static_cast(info.disconnected.reason)); + if (info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE) { + // See: https://github.com/espressif/arduino-esp32/issues/8877#issuecomment-1807677897 + WiFiSTAClass::_setStatus(WL_CONNECTION_LOST); + } #endif WiFi.persistent(false); WiFi.disconnect(true); diff --git a/src/src/ESPEasyCore/ESPEasyWifi.cpp b/src/src/ESPEasyCore/ESPEasyWifi.cpp index d206302703..48d34a821b 100644 --- a/src/src/ESPEasyCore/ESPEasyWifi.cpp +++ b/src/src/ESPEasyCore/ESPEasyWifi.cpp @@ -297,11 +297,11 @@ bool WiFiConnected() { if ((WiFiEventData.timerAPstart.isSet()) && WiFiEventData.timerAPstart.timeReached()) { if (WiFiEventData.timerAPoff.isSet() && !WiFiEventData.timerAPoff.timeReached()) { - // Timer reached, so enable AP mode. - if (!WifiIsAP(WiFi.getMode())) { - if (!WiFiEventData.wifiConnectAttemptNeeded) { - addLog(LOG_LEVEL_INFO, F("WiFi : WiFiConnected(), start AP")); - if (!Settings.DoNotStartAP()) { + if (!Settings.DoNotStartAP()) { + // Timer reached, so enable AP mode. + if (!WifiIsAP(WiFi.getMode())) { + if (!WiFiEventData.wifiConnectAttemptNeeded) { + addLog(LOG_LEVEL_INFO, F("WiFi : WiFiConnected(), start AP")); WifiScan(false); setAP(true); } @@ -469,12 +469,14 @@ void AttemptWiFiConnect() { WiFiEventData.wifiConnectInProgress = true; const String key = WiFi_AP_CandidatesList::get_key(candidate.index); - if (candidate.allowQuickConnect() && !candidate.isHidden) { + if ((Settings.HiddenSSID_SlowConnectPerBSSID() || !candidate.isHidden) + && candidate.allowQuickConnect()) { WiFi.begin(candidate.ssid.c_str(), key.c_str(), candidate.channel, candidate.bssid.mac); } else { WiFi.begin(candidate.ssid.c_str(), key.c_str()); } - if (Settings.WaitWiFiConnect()) { + if (Settings.WaitWiFiConnect() || candidate.isHidden) { +// WiFi.waitForConnectResult(candidate.isHidden ? 3000 : 1000); // https://github.com/arendst/Tasmota/issues/14985 WiFi.waitForConnectResult(1000); // https://github.com/arendst/Tasmota/issues/14985 } delay(1); @@ -1386,15 +1388,24 @@ bool wifiAPmodeActivelyUsed() void setConnectionSpeed() { #ifdef ESP8266 - WiFiPhyMode_t phyMode = WIFI_PHY_MODE_11G; + // ESP8266 only supports 802.11g mode when running in STA+AP const bool forcedByAPmode = WifiIsAP(WiFi.getMode()); + WiFiPhyMode_t phyMode = (Settings.ForceWiFi_bg_mode() || forcedByAPmode) ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N; if (!forcedByAPmode) { - // ESP8266 only supports 802.11g mode when running in STA+AP -// const WiFi_AP_Candidate candidate = WiFi_AP_Candidates.getCurrent(); - - bool useAlternate = WiFi_AP_Candidates.attemptsLeft == 0; - if (Settings.ForceWiFi_bg_mode() == useAlternate) { - phyMode = WIFI_PHY_MODE_11N; + const WiFi_AP_Candidate candidate = WiFi_AP_Candidates.getCurrent(); + if (candidate.phy_known() && (candidate.phy_11g != candidate.phy_11n)) { + if ((WIFI_PHY_MODE_11G == phyMode) && !candidate.phy_11g) { + phyMode = WIFI_PHY_MODE_11N; + addLog(LOG_LEVEL_INFO, F("WIFI : AP is set to 802.11n only")); + } else if ((WIFI_PHY_MODE_11N == phyMode) && !candidate.phy_11n) { + phyMode = WIFI_PHY_MODE_11G; + addLog(LOG_LEVEL_INFO, F("WIFI : AP is set to 802.11g only")); + } + } else { + bool useAlternate = WiFiEventData.connectionFailures > 10; + if (useAlternate) { + phyMode = (WIFI_PHY_MODE_11G == phyMode) ? WIFI_PHY_MODE_11N : WIFI_PHY_MODE_11G; + } } } else { // No need to perform a next attempt. @@ -1421,6 +1432,15 @@ void setConnectionSpeed() { // Does not (yet) work, so commented out. #ifdef ESP32 + + // HT20 = 20 MHz channel width. + // HT40 = 40 MHz channel width. + // In theory, HT40 can offer upto 150 Mbps connection speed. + // However since HT40 is using nearly all channels on 2.4 GHz WiFi, + // Thus you are more likely to experience disturbances. + // The response speed and stability is better at HT20 for ESP units. + esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20); + uint8_t protocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G; // Default to BG if (!Settings.ForceWiFi_bg_mode() || (WiFiEventData.connectionFailures > 10)) { @@ -1428,7 +1448,23 @@ void setConnectionSpeed() { protocol |= WIFI_PROTOCOL_11N; } + const WiFi_AP_Candidate candidate = WiFi_AP_Candidates.getCurrent(); + if (candidate.phy_known()) { + // Check to see if the access point is set to "N-only" + if ((protocol & WIFI_PROTOCOL_11N) == 0) { + if (!candidate.phy_11b && !candidate.phy_11g && candidate.phy_11n) { + // Set to use BGN + protocol |= WIFI_PROTOCOL_11N; + addLog(LOG_LEVEL_INFO, F("WIFI : AP is set to 802.11n only")); + } + } + } + + if (WifiIsSTA(WiFi.getMode())) { + // Set to use "Long GI" making it more resilliant to reflections + // See: https://www.tp-link.com/us/configuration-guides/q_a_basic_wireless_concepts/?configurationId=2958#_idTextAnchor038 + esp_wifi_config_80211_tx_rate(WIFI_IF_STA, WIFI_PHY_RATE_MCS3_LGI); esp_wifi_set_protocol(WIFI_IF_STA, protocol); } diff --git a/src/src/ESPEasyCore/ESPEasy_setup.cpp b/src/src/ESPEasyCore/ESPEasy_setup.cpp index e36d6f75b4..f0c71a0561 100644 --- a/src/src/ESPEasyCore/ESPEasy_setup.cpp +++ b/src/src/ESPEasyCore/ESPEasy_setup.cpp @@ -147,6 +147,11 @@ void ESPEasy_setup() lowestRAM = FreeMem(); #endif // ifndef BUILD_NO_RAM_TRACKER +#ifdef ESP32 + ResetFactoryDefaultPreference.init(); +#endif + + PluginSetup(); CPluginSetup(); diff --git a/src/src/Helpers/ESPEasy_FactoryDefault.cpp b/src/src/Helpers/ESPEasy_FactoryDefault.cpp index 5203499511..efb7ced24a 100644 --- a/src/src/Helpers/ESPEasy_FactoryDefault.cpp +++ b/src/src/Helpers/ESPEasy_FactoryDefault.cpp @@ -25,12 +25,40 @@ #include "../Helpers/Hardware.h" #include "../Helpers/Misc.h" +#ifdef ESP32 + +// Store in NVS partition +#include "../Helpers/ESPEasy_NVS_Helper.h" + + +// Max. 15 char namespace for ESPEasy Factory Default settings +# define FACTORY_DEFAULT_NVS_NAMESPACE "ESPEasyFacDef" + +# include "../Helpers/StringConverter.h" +#include "../DataStructs/FactoryDefaultPref.h" +#include "../DataStructs/FactoryDefault_UnitName_NVS.h" +#include "../DataStructs/FactoryDefault_WiFi_NVS.h" +#include "../DataStructs/FactoryDefault_Network_NVS.h" +#include "../DataStructs/FactoryDefault_LogConsoleSettings_NVS.h" +# if FEATURE_ALTERNATIVE_CDN_URL +#include "../DataStructs/FactoryDefault_CDN_customurl_NVS.h" +#endif + + +#endif // ifdef ESP32 + + /********************************************************************************************\ Reset all settings to factory defaults \*********************************************************************************************/ void ResetFactory(bool formatFS) { + #ifdef ESP32 + ResetFactoryDefaultPreference.init(); + #endif + #if FEATURE_CUSTOM_PROVISIONING + if (ResetFactoryDefaultPreference.getPreference() == 0) { ResetFactoryDefaultPreference.setDeviceModel(static_cast(DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL)); @@ -45,13 +73,13 @@ void ResetFactory(bool formatFS) ResetFactoryDefaultPreference.saveURL(DEFAULT_PROVISIONING_SAVE_URL); ResetFactoryDefaultPreference.storeCredentials(DEFAULT_PROVISIONING_SAVE_CREDENTIALS); } - #endif + #endif // if FEATURE_CUSTOM_PROVISIONING const GpioFactorySettingsStruct gpio_settings(ResetFactoryDefaultPreference.getDeviceModel()); #ifndef BUILD_NO_RAM_TRACKER checkRAM(F("ResetFactory")); - #endif + #endif // ifndef BUILD_NO_RAM_TRACKER // Direct Serial is allowed here, since this is only an emergency task. serialPrint(F("RESET: Resetting factory defaults... using ")); @@ -102,6 +130,7 @@ void ResetFactory(bool formatFS) #if FEATURE_CUSTOM_PROVISIONING { MakeProvisioningSettings(ProvisioningSettings); + if (ProvisioningSettings.get()) { ProvisioningSettings->setUser(F(DEFAULT_PROVISIONING_USER)); ProvisioningSettings->setPass(F(DEFAULT_PROVISIONING_PASS)); @@ -110,7 +139,7 @@ void ResetFactory(bool formatFS) saveProvisioningSettings(*ProvisioningSettings); } } -#endif +#endif // if FEATURE_CUSTOM_PROVISIONING // pad files with extra zeros for future extensions InitFile(SettingsType::SettingsFileEnum::FILE_CONFIG_type); @@ -152,7 +181,7 @@ void ResetFactory(bool formatFS) Settings.clearControllers(); Settings.clearTasks(); - if (!ResetFactoryDefaultPreference.keepLogSettings()) { + if (!ResetFactoryDefaultPreference.keepLogConsoleSettings()) { Settings.clearLogSettings(); str2ip((char *)DEFAULT_SYSLOG_IP, Settings.Syslog_IP); @@ -161,8 +190,17 @@ void ResetFactory(bool formatFS) setLogLevelFor(LOG_TO_WEBLOG, DEFAULT_WEB_LOG_LEVEL); setLogLevelFor(LOG_TO_SDCARD, DEFAULT_SD_LOG_LEVEL); Settings.SyslogFacility = DEFAULT_SYSLOG_FACILITY; + Settings.SyslogPort = DEFAULT_SYSLOG_PORT; Settings.UseValueLogger = DEFAULT_USE_SD_LOG; - } + + // FIXME TD-er: Must also keep console settings. + Settings.console_serial_port = DEFAULT_CONSOLE_PORT; + Settings.console_serial_rxpin = DEFAULT_CONSOLE_PORT_RXPIN; + Settings.console_serial_txpin = DEFAULT_CONSOLE_PORT_TXPIN; + Settings.console_serial0_fallback = DEFAULT_CONSOLE_SER0_FALLBACK; + Settings.UseSerial = DEFAULT_USE_SERIAL; + Settings.BaudRate = DEFAULT_SERIAL_BAUD; +} if (!ResetFactoryDefaultPreference.keepUnitName()) { Settings.clearUnitNameSettings(); @@ -190,20 +228,22 @@ void ResetFactory(bool formatFS) Settings.Build = get_build_nr(); // Settings.IP_Octet = DEFAULT_IP_OCTET; -// Settings.Delay = DEFAULT_DELAY; - Settings.Pin_i2c_sda = gpio_settings.i2c_sda; - Settings.Pin_i2c_scl = gpio_settings.i2c_scl; - Settings.Pin_status_led = gpio_settings.status_led; -// Settings.Pin_status_led_Inversed = DEFAULT_PIN_STATUS_LED_INVERSED; - Settings.Pin_sd_cs = -1; - Settings.Pin_Reset = DEFAULT_PIN_RESET_BUTTON; - Settings.Protocol[0] = DEFAULT_PROTOCOL; -// Settings.deepSleep_wakeTime = 0; // Sleep disabled -// Settings.CustomCSS = false; -// Settings.InitSPI = DEFAULT_SPI; + // Settings.Delay = DEFAULT_DELAY; + Settings.Pin_i2c_sda = gpio_settings.i2c_sda; + Settings.Pin_i2c_scl = gpio_settings.i2c_scl; + Settings.Pin_status_led = gpio_settings.status_led; + + // Settings.Pin_status_led_Inversed = DEFAULT_PIN_STATUS_LED_INVERSED; + Settings.Pin_sd_cs = -1; + Settings.Pin_Reset = DEFAULT_PIN_RESET_BUTTON; + Settings.Protocol[0] = DEFAULT_PROTOCOL; + + // Settings.deepSleep_wakeTime = 0; // Sleep disabled + // Settings.CustomCSS = false; + // Settings.InitSPI = DEFAULT_SPI; // advanced Settings -// Settings.UseRules = DEFAULT_USE_RULES; + // Settings.UseRules = DEFAULT_USE_RULES; Settings.ControllerEnabled[0] = DEFAULT_CONTROLLER_ENABLED; Settings.MQTTRetainFlag_unused = DEFAULT_MQTT_RETAIN; Settings.MessageDelay_unused = DEFAULT_MQTT_DELAY; @@ -217,10 +257,8 @@ void ResetFactory(bool formatFS) Settings.Longitude = DEFAULT_LONGITUDE; #endif // ifdef DEFAULT_LONGITUDE -// Settings.UseSerial = DEFAULT_USE_SERIAL; -// Settings.BaudRate = DEFAULT_SERIAL_BAUD; - #ifdef ESP32 + // Ethernet related settings are never used on ESP8266 Settings.ETH_Phy_Addr = gpio_settings.eth_phyaddr; Settings.ETH_Pin_mdc = gpio_settings.eth_mdc; @@ -228,8 +266,8 @@ void ResetFactory(bool formatFS) Settings.ETH_Pin_power = gpio_settings.eth_power; Settings.ETH_Phy_Type = gpio_settings.eth_phytype; Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; -#endif - Settings.NetworkMedium = gpio_settings.network_medium; +#endif // ifdef ESP32 + Settings.NetworkMedium = gpio_settings.network_medium; /* Settings.GlobalSync = DEFAULT_USE_GLOBAL_SYNC; @@ -240,7 +278,8 @@ void ResetFactory(bool formatFS) Settings.ConnectionFailuresThreshold = DEFAULT_CON_FAIL_THRES; Settings.WireClockStretchLimit = DEFAULT_I2C_CLOCK_LIMIT; */ -// Settings.I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED; + + // Settings.I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED; Settings.JSONBoolWithoutQuotes(DEFAULT_JSON_BOOL_WITHOUT_QUOTES); Settings.EnableTimingStats(DEFAULT_ENABLE_TIMING_STATS); @@ -252,12 +291,12 @@ void ResetFactory(bool formatFS) #ifndef LIMIT_BUILD_SIZE addPredefinedPlugins(gpio_settings); addPredefinedRules(gpio_settings); -#endif +#endif // ifndef LIMIT_BUILD_SIZE #if DEFAULT_CONTROLLER { // Place in a scope to have its memory freed ASAP - MakeControllerSettings(ControllerSettings); //-V522 + MakeControllerSettings(ControllerSettings); // -V522 if (AllocatedControllerSettings()) { safe_strncpy(ControllerSettings->Subscribe, F(DEFAULT_SUB), sizeof(ControllerSettings->Subscribe)); @@ -271,7 +310,7 @@ void ResetFactory(bool formatFS) ControllerSettings->setHostname(F(DEFAULT_SERVER_HOST)); ControllerSettings->UseDNS = DEFAULT_SERVER_USEDNS; ControllerSettings->useExtendedCredentials(DEFAULT_USE_EXTD_CONTROLLER_CREDENTIALS); - ControllerSettings->Port = DEFAULT_PORT; + ControllerSettings->Port = DEFAULT_PORT; ControllerSettings->ClientTimeout = DEFAULT_CONTROLLER_TIMEOUT; setControllerUser(0, *ControllerSettings, F(DEFAULT_CONTROLLER_USER)); setControllerPass(0, *ControllerSettings, F(DEFAULT_CONTROLLER_PASS)); @@ -280,11 +319,52 @@ void ResetFactory(bool formatFS) } } #endif // if DEFAULT_CONTROLLER + +#ifdef ESP32 + { + ESPEasy_NVS_Helper preferences; + preferences.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE), true); + + if (ResetFactoryDefaultPreference.from_NVS(preferences)) { + Settings.ResetFactoryDefaultPreference = ResetFactoryDefaultPreference.getPreference(); + } + + if (ResetFactoryDefaultPreference.keepUnitName()) + { + FactoryDefault_UnitName_NVS unitNameNVS{}; + unitNameNVS.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepWiFi()) + { + FactoryDefault_WiFi_NVS wifiNVS{}; + wifiNVS.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepNetwork()) + { + // Restore Network IP settings + FactoryDefault_Network_NVS network_nvs; + network_nvs.applyToSettings_from_NVS(preferences); + } + if (ResetFactoryDefaultPreference.keepLogConsoleSettings()) + { + // Restore Log and Console settings + FactoryDefault_LogConsoleSettings_NVS log_console_nvs; + log_console_nvs.applyToSettings_from_NVS(preferences); + } + +#if FEATURE_ALTERNATIVE_CDN_URL + if (ResetFactoryDefaultPreference.keepCustomCdnUrl()) { + FactoryDefault_CDN_customurl_NVS::applyToSettings_from_NVS(preferences); + } +#endif + } +#endif + const bool forFactoryReset = true; SaveSettings(forFactoryReset); #ifndef BUILD_NO_RAM_TRACKER checkRAM(F("ResetFactory2")); - #endif + #endif // ifndef BUILD_NO_RAM_TRACKER serialPrintln(F("RESET: Successful, rebooting. (you might need to press the reset button if you've just flashed the firmware)")); // NOTE: this is a known ESP8266 bug, not our fault. :) @@ -296,11 +376,70 @@ void ResetFactory(bool formatFS) reboot(IntendedRebootReason_e::ResetFactory); } - /*********************************************************************************************\ Collect the stored preference for factory default \*********************************************************************************************/ void applyFactoryDefaultPref() { // TODO TD-er: Store it in more places to make it more persistent Settings.ResetFactoryDefaultPreference = ResetFactoryDefaultPreference.getPreference(); + +#ifdef ESP32 + ESPEasy_NVS_Helper preferences; + preferences.begin(F(FACTORY_DEFAULT_NVS_NAMESPACE)); + ResetFactoryDefaultPreference.to_NVS(preferences); + { + FactoryDefault_UnitName_NVS unitNameNVS{}; + if (ResetFactoryDefaultPreference.keepUnitName()) + { + // Store Unit nr and hostname + unitNameNVS.fromSettings_to_NVS(preferences); + } else { + unitNameNVS.clear_from_NVS(preferences); + } + } + { + FactoryDefault_WiFi_NVS wifiNVS{}; + if (ResetFactoryDefaultPreference.keepWiFi()) + { + // Store WiFi credentials + wifiNVS.fromSettings_to_NVS(preferences); + } else { + wifiNVS.clear_from_NVS(preferences); + } + } + { + FactoryDefault_Network_NVS network_nvs{}; + if (ResetFactoryDefaultPreference.keepNetwork()) + { + // Store Network IP settings + network_nvs.fromSettings_to_NVS(preferences); + } else { + network_nvs.clear_from_NVS(preferences); + } + } + { + FactoryDefault_LogConsoleSettings_NVS log_console_nvs{}; + if (ResetFactoryDefaultPreference.keepLogConsoleSettings()) + { + // Store Log and Console settings + log_console_nvs.fromSettings_to_NVS(preferences); + } else { + log_console_nvs.clear_from_NVS(preferences); + } + } +# if FEATURE_ALTERNATIVE_CDN_URL + { + if (ResetFactoryDefaultPreference.keepCustomCdnUrl()) + { + // Store custom CDN + FactoryDefault_CDN_customurl_NVS::fromSettings_to_NVS(preferences); + } else { + FactoryDefault_CDN_customurl_NVS::clear_from_NVS(preferences); + } + } +# endif // if FEATURE_ALTERNATIVE_CDN_URL + + + preferences.end(); +#endif // ifdef ESP32 } diff --git a/src/src/Helpers/ESPEasy_NVS_Helper.cpp b/src/src/Helpers/ESPEasy_NVS_Helper.cpp new file mode 100644 index 0000000000..af035386e0 --- /dev/null +++ b/src/src/Helpers/ESPEasy_NVS_Helper.cpp @@ -0,0 +1,124 @@ +#include "../Helpers/ESPEasy_NVS_Helper.h" + +#ifdef ESP32 + +# include "../Helpers/StringConverter.h" + + +ESPEasy_NVS_Helper::~ESPEasy_NVS_Helper() +{ + _preferences.end(); +} + +bool ESPEasy_NVS_Helper::begin(const String& nvs_namespace, bool readOnly) +{ + return _preferences.begin(nvs_namespace.c_str(), readOnly); +} + +void ESPEasy_NVS_Helper::end() +{ + _preferences.end(); +} + +void ESPEasy_NVS_Helper::remove(const String& key) +{ + _preferences.remove(key.c_str()); +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, String& value) +{ + value = _preferences.getString(key.c_str()); + + const bool res = !value.isEmpty(); + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const String& value) +{ + if (value.isEmpty()) { + _preferences.remove(key.c_str()); + } + else if (!_preferences.getString(key.c_str(), EMPTY_STRING.c_str()).equals(value)) { + _preferences.putString(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint32_t& value) +{ + constexpr uint32_t defaultValue = std::numeric_limits::max(); + + value = _preferences.getUInt(key.c_str(), defaultValue); + + const bool res = value != defaultValue; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint32_t& value) +{ + constexpr uint32_t defaultValue = std::numeric_limits::max(); + + if (value == defaultValue) { + _preferences.remove(key.c_str()); + } + else if (_preferences.getUInt(key.c_str()) != value) { + _preferences.putUInt(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint64_t& value) +{ + constexpr uint64_t defaultValue = std::numeric_limits::max(); + + value = _preferences.getULong64(key.c_str(), defaultValue); + + const bool res = value != defaultValue; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint64_t& value) +{ + constexpr uint64_t defaultValue = std::numeric_limits::max(); + + if (value == defaultValue) { + _preferences.remove(key.c_str()); + } + else if (_preferences.getULong64(key.c_str()) != value) { + _preferences.putULong64(key.c_str(), value); + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +bool ESPEasy_NVS_Helper::getPreference(const String& key, uint8_t *data, size_t length) +{ + const bool res = _preferences.getBytes(key.c_str(), data, length) == length; + + addLog(res ? LOG_LEVEL_INFO : LOG_LEVEL_ERROR, concat(F("NVS : Load "), key)); + return res; +} + +void ESPEasy_NVS_Helper::setPreference(const String& key, const uint8_t *data, size_t length) +{ + { + uint8_t tmp[length]{}; + + if (_preferences.getBytes(key.c_str(), tmp, length) == length) { + if (memcmp(tmp, data, length) == 0) { + return; + } + } + } + + if (_preferences.putBytes(key.c_str(), data, length) == length) { + addLog(LOG_LEVEL_INFO, concat(F("NVS : Save "), key)); + } +} + +#endif // ifdef ESP32 diff --git a/src/src/Helpers/ESPEasy_NVS_Helper.h b/src/src/Helpers/ESPEasy_NVS_Helper.h new file mode 100644 index 0000000000..d164f52821 --- /dev/null +++ b/src/src/Helpers/ESPEasy_NVS_Helper.h @@ -0,0 +1,58 @@ +#ifndef HELPERS_ESPEASY_NVS_HELPER_H +#define HELPERS_ESPEASY_NVS_HELPER_H + +#include "../../ESPEasy_common.h" + +#ifdef ESP32 + +// Store in NVS partition +# include + + +// Max. 15 char namespace for ESPEasy Factory Default settings +# define FACTORY_DEFAULT_NVS_NAMESPACE "ESPEasyFacDef" + + +class ESPEasy_NVS_Helper { +public: + ESPEasy_NVS_Helper() = default; + + ~ESPEasy_NVS_Helper(); + + bool begin(const String& nvs_namespace, + bool readOnly = false); + + void end(); + + void remove(const String& key); + + bool getPreference(const String& key, + String & value); + void setPreference(const String& key, + const String& value); + + bool getPreference(const String& key, + uint32_t & value); + void setPreference(const String & key, + const uint32_t& value); + + bool getPreference(const String& key, + uint64_t & value); + void setPreference(const String & key, + const uint64_t& value); + + bool getPreference(const String& key, + uint8_t *value, + size_t length); + void setPreference(const String & key, + const uint8_t *value, + size_t length); + +private: + + Preferences _preferences; +}; + + +#endif // ifdef ESP32 +#endif // ifndef HELPERS_ESPEASY_NVS_HELPER_H diff --git a/src/src/Helpers/ESPEasy_Storage.cpp b/src/src/Helpers/ESPEasy_Storage.cpp index c60b901c15..5a7b6dddf0 100644 --- a/src/src/Helpers/ESPEasy_Storage.cpp +++ b/src/src/Helpers/ESPEasy_Storage.cpp @@ -566,6 +566,10 @@ String SaveSettings(bool forFactoryReset) Settings.validate(); initSerial(); + if (forFactoryReset) { + Settings.forceSave(); + } + if (!COMPUTE_STRUCT_CHECKSUM_UPDATE(SettingsStruct, Settings) /* computeChecksum( @@ -646,14 +650,25 @@ void afterloadSettings() { ExtraTaskSettings.clear(); // make sure these will not contain old settings. // Load ResetFactoryDefaultPreference from provisioning.dat if available. + // FIXME TD-er: Must actually move content of Provisioning.dat to NVS and then delete file uint32_t pref_temp = Settings.ResetFactoryDefaultPreference; + #ifdef ESP32 + if (pref_temp == 0) { + if (ResetFactoryDefaultPreference.getPreference() == 0) { + // Try loading from NVS + ResetFactoryDefaultPreference.init(); + pref_temp = ResetFactoryDefaultPreference.getPreference(); + } + } + #endif #if FEATURE_CUSTOM_PROVISIONING if (fileExists(getFileName(FileType::PROVISIONING_DAT))) { MakeProvisioningSettings(ProvisioningSettings); if (ProvisioningSettings.get()) { loadProvisioningSettings(*ProvisioningSettings); if (ProvisioningSettings->matchingFlashSize()) { - pref_temp = ProvisioningSettings->ResetFactoryDefaultPreference.getPreference(); + if (pref_temp == 0 && ProvisioningSettings->ResetFactoryDefaultPreference.getPreference() != 0) + pref_temp = ProvisioningSettings->ResetFactoryDefaultPreference.getPreference(); } } } @@ -667,6 +682,7 @@ void afterloadSettings() { if (modelMatchingFlashSize(pref.getDeviceModel())) { ResetFactoryDefaultPreference = pref_temp; } + applyFactoryDefaultPref(); Scheduler.setEcoMode(Settings.EcoPowerMode()); #ifdef ESP32 setCpuFrequencyMhz(Settings.EcoPowerMode() ? 80 : 240); @@ -946,6 +962,7 @@ String LoadStringArray(SettingsType::Enum settingsType, int index, String string \*********************************************************************************************/ String SaveStringArray(SettingsType::Enum settingsType, int index, const String strings[], uint16_t nrStrings, uint16_t maxStringLength, uint32_t posInBlock) { + // FIXME TD-er: Must add some check to see if the existing data has changed before saving. int offset, max_size; if (!SettingsType::getSettingsParameters(settingsType, index, offset, max_size)) { @@ -1144,6 +1161,50 @@ String LoadTaskSettings(taskIndex_t TaskIndex) return result; } +#if FEATURE_ALTERNATIVE_CDN_URL +String _CDN_url_cache; +bool _CDN_url_loaded = false; + +String get_CDN_url_custom() { + if (!_CDN_url_loaded) { + String strings[] = {EMPTY_STRING}; + + LoadStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); + _CDN_url_cache = strings[0]; + _CDN_url_loaded = true; + } + return _CDN_url_cache; +} + +void set_CDN_url_custom(const String &url) { + _CDN_url_cache = url; + _CDN_url_cache.trim(); + if (!_CDN_url_cache.isEmpty() && !_CDN_url_cache.endsWith(F("/"))) { + _CDN_url_cache.concat('/'); + } + _CDN_url_loaded = true; + + String strings[] = { EMPTY_STRING }; + + LoadStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); + + if (url.equals(strings[0])) { + // No need to save, is already the same + return; + } + + strings[0] = url; + + SaveStringArray( + SettingsType::Enum::CdnSettings_Type, 0, + strings, NR_ELEMENTS(strings), 255, 0); +} +#endif // if FEATURE_ALTERNATIVE_CDN_URL + /********************************************************************************************\ Save Custom Task settings to file system \*********************************************************************************************/ @@ -2096,6 +2157,10 @@ String downloadFileType(FileType::Enum filetype, unsigned int filenr) return F("Not Allowed"); } + if (!ProvisioningSettings->url[0]) { + return F("Provision Config incomplete"); + } + url = ProvisioningSettings->url; user = ProvisioningSettings->user; pass = ProvisioningSettings->pass; diff --git a/src/src/Helpers/ESPEasy_Storage.h b/src/src/Helpers/ESPEasy_Storage.h index d32ea7a1e1..c5d05eb216 100644 --- a/src/src/Helpers/ESPEasy_Storage.h +++ b/src/src/Helpers/ESPEasy_Storage.h @@ -167,6 +167,14 @@ String SaveTaskSettings(taskIndex_t TaskIndex); \*********************************************************************************************/ String LoadTaskSettings(taskIndex_t TaskIndex); +/********************************************************************************************\ + Load/Save CDN custom setting from file system + \*********************************************************************************************/ +#if FEATURE_ALTERNATIVE_CDN_URL +String get_CDN_url_custom(); +void set_CDN_url_custom(const String &url); +#endif // if FEATURE_ALTERNATIVE_CDN_URL + /********************************************************************************************\ Save Custom Task settings to file system \*********************************************************************************************/ diff --git a/src/src/Helpers/Networking.cpp b/src/src/Helpers/Networking.cpp index f165cf40f2..60a9cc61c4 100644 --- a/src/src/Helpers/Networking.cpp +++ b/src/src/Helpers/Networking.cpp @@ -1767,6 +1767,7 @@ bool downloadFirmware(String filename, String& error) if (ProvisioningSettings.get()) { loadProvisioningSettings(*ProvisioningSettings); if (!ProvisioningSettings->allowedFlags.allowFetchFirmware) { + error = F("Not Allowed"); return false; } baseurl = ProvisioningSettings->url; diff --git a/src/src/Helpers/StringProvider.cpp b/src/src/Helpers/StringProvider.cpp index 7b974c457a..4426076c31 100644 --- a/src/src/Helpers/StringProvider.cpp +++ b/src/src/Helpers/StringProvider.cpp @@ -179,6 +179,8 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) { case LabelType::PERIODICAL_GRAT_ARP: return F("Periodical send Gratuitous ARP"); case LabelType::CONNECTION_FAIL_THRESH: return F("Connection Failure Threshold"); case LabelType::WAIT_WIFI_CONNECT: return F("Extra Wait WiFi Connect"); + case LabelType::CONNECT_HIDDEN_SSID: return F("Include Hidden SSID"); + case LabelType::HIDDEN_SSID_SLOW_CONNECT: return F("Hidden SSID Slow Connect"); case LabelType::SDK_WIFI_AUTORECONNECT: return F("Enable SDK WiFi Auto Reconnect"); case LabelType::BUILD_DESC: return F("Build"); @@ -463,6 +465,8 @@ String getValue(LabelType::Enum label) { case LabelType::PERIODICAL_GRAT_ARP: return jsonBool(Settings.gratuitousARP()); case LabelType::CONNECTION_FAIL_THRESH: retval = Settings.ConnectionFailuresThreshold; break; case LabelType::WAIT_WIFI_CONNECT: return jsonBool(Settings.WaitWiFiConnect()); + case LabelType::CONNECT_HIDDEN_SSID: return jsonBool(Settings.IncludeHiddenSSID()); + case LabelType::HIDDEN_SSID_SLOW_CONNECT: return jsonBool(Settings.HiddenSSID_SlowConnectPerBSSID()); case LabelType::SDK_WIFI_AUTORECONNECT: return jsonBool(Settings.WifiNoneSleep()); case LabelType::BUILD_DESC: return getSystemBuildString(); diff --git a/src/src/Helpers/StringProvider.h b/src/src/Helpers/StringProvider.h index 9ac08a48b8..ec07b4ff8c 100644 --- a/src/src/Helpers/StringProvider.h +++ b/src/src/Helpers/StringProvider.h @@ -130,6 +130,8 @@ struct LabelType { PERIODICAL_GRAT_ARP, CONNECTION_FAIL_THRESH, WAIT_WIFI_CONNECT, + HIDDEN_SSID_SLOW_CONNECT, + CONNECT_HIDDEN_SSID, SDK_WIFI_AUTORECONNECT, BUILD_DESC, diff --git a/src/src/Helpers/_CPlugin_init.cpp b/src/src/Helpers/_CPlugin_init.cpp index a5db9f2c8c..863debffb4 100644 --- a/src/src/Helpers/_CPlugin_init.cpp +++ b/src/src/Helpers/_CPlugin_init.cpp @@ -2070,7 +2070,7 @@ const CPlugin_ptr_t PROGMEM CPlugin_ptr[] = constexpr size_t ProtocolIndex_to_CPlugin_id_size = sizeof(ProtocolIndex_to_CPlugin_id); // Highest CPlugin ID included in the build -constexpr size_t Highest_CPlugin_id = ProtocolIndex_to_CPlugin_id[ProtocolIndex_to_CPlugin_id_size - 1]; +constexpr size_t Highest_CPlugin_id = ProtocolIndex_to_CPlugin_id_size == 0 ? 0 : ProtocolIndex_to_CPlugin_id[ProtocolIndex_to_CPlugin_id_size - 1]; constexpr size_t CPlugin_id_to_ProtocolIndex_size = Highest_CPlugin_id + 1; diff --git a/src/src/PluginStructs/P023_data_struct.cpp b/src/src/PluginStructs/P023_data_struct.cpp index 5f5eee2721..c0a818c50a 100644 --- a/src/src/PluginStructs/P023_data_struct.cpp +++ b/src/src/PluginStructs/P023_data_struct.cpp @@ -262,9 +262,10 @@ void P023_data_struct::StartUp_OLED(struct EventStruct *event) { bool P023_data_struct::plugin_read(struct EventStruct *event) { for (uint8_t x = 0; x < 8; x++) { - String newString = parseTemplate(strings[x], 16); - if (strings[x].length()) { + String tmp = strings[x]; + const String newString = parseTemplate(tmp, 16); + sendStrXY(newString.c_str(), x, 0); currentLines[x] = newString; } diff --git a/src/src/PluginStructs/P036_data_struct.cpp b/src/src/PluginStructs/P036_data_struct.cpp index dab5d0c070..22a32ac30c 100644 --- a/src/src/PluginStructs/P036_data_struct.cpp +++ b/src/src/PluginStructs/P036_data_struct.cpp @@ -415,6 +415,12 @@ void P036_data_struct::display_header() { display_time(); // only for 128pix wide displays } display_wifibars(); + +#ifdef OLEDDISPLAY_DOUBLE_BUFFER + // Update only small sections of the display, reducing the amount of data to be sent to the display + update_display(); +#endif + } void P036_data_struct::display_time() { diff --git a/src/src/PluginStructs/P038_data_struct.cpp b/src/src/PluginStructs/P038_data_struct.cpp index d4a4ffeaf9..352dc23e7a 100644 --- a/src/src/PluginStructs/P038_data_struct.cpp +++ b/src/src/PluginStructs/P038_data_struct.cpp @@ -26,9 +26,9 @@ bool P038_data_struct::plugin_init(struct EventStruct *event) { bool success = false; if (!isInitialized()) { - Plugin_038_pixels = new (std::nothrow) Adafruit_NeoPixel(_maxPixels, - _gpioPin, - (_stripType == P038_STRIP_TYPE_RGBW ? NEO_GRBW : NEO_GRB) + NEO_KHZ800); + Plugin_038_pixels = new (std::nothrow) NeoPixelBus_wrapper(_maxPixels, + _gpioPin, + (_stripType == P038_STRIP_TYPE_RGBW ? NEO_GRBW : NEO_GRB) + NEO_KHZ800); if (Plugin_038_pixels != nullptr) { Plugin_038_pixels->begin(); // This initializes the NeoPixel library. @@ -110,7 +110,7 @@ bool P038_data_struct::plugin_write(struct EventStruct *event, const String& str } } else - if (equals(cmd, F("neopixelline"))) { // NeoPixelLine + if (equals(cmd, F("neopixelline"))) { // NeoPixelLine int brightness = 0; validIntFromString(parseString(string, 7), brightness); // Get 7th argument aka Par6 diff --git a/src/src/PluginStructs/P038_data_struct.h b/src/src/PluginStructs/P038_data_struct.h index 84f07ecb03..24aa5d8093 100644 --- a/src/src/PluginStructs/P038_data_struct.h +++ b/src/src/PluginStructs/P038_data_struct.h @@ -4,7 +4,7 @@ #include "../../_Plugin_Helper.h" #ifdef USES_P038 -# include +# include // # define P038_DEBUG_LOG // Enable for some (extra) logging @@ -39,7 +39,7 @@ struct P038_data_struct : public PluginTaskData_base { private: - Adafruit_NeoPixel *Plugin_038_pixels = nullptr; + NeoPixelBus_wrapper *Plugin_038_pixels = nullptr; void HSV2RGBWorRGBandLog(float H, float S, diff --git a/src/src/PluginStructs/P042_data_struct.cpp b/src/src/PluginStructs/P042_data_struct.cpp index d44f168dd2..5f76ff71a2 100644 --- a/src/src/PluginStructs/P042_data_struct.cpp +++ b/src/src/PluginStructs/P042_data_struct.cpp @@ -22,7 +22,6 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { Candle_blue = P042_CONFIG_BLUE; Candle_bright = P042_CONFIG_BRIGHTNESS; Candle_pxlcnt = P042_CONFIG_PIXELCOUNT; - Candle_pxlcnt = P042_CONFIG_PIXELCOUNT; segment = Candle_pxlcnt / 4; if ((Candle_red == 0) && (Candle_green == 0) && (Candle_blue == 0)) { @@ -31,16 +30,16 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { Candle_type = static_cast(P042_CONFIG_CANDLETYPE); Candle_color = static_cast(P042_CONFIG_COLORTYPE); - if (!Candle_pixels || (GPIO_Set == false)) { + if ((nullptr == Candle_pixels) || !GPIO_Set) { GPIO_Set = validGpio(CONFIG_PIN1); if (GPIO_Set) { - if (Candle_pixels) { + if (nullptr != Candle_pixels) { delete Candle_pixels; } - Candle_pixels = new (std::nothrow) Adafruit_NeoPixel(P042_CONFIG_PIXELCOUNT, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + Candle_pixels = new (std::nothrow) NeoPixelBus_wrapper(P042_CONFIG_PIXELCOUNT, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); - if (Candle_pixels != nullptr) { + if (nullptr != Candle_pixels) { SetPixelsBlack(); Candle_pixels->setBrightness(Candle_bright); Candle_pixels->begin(); @@ -55,7 +54,7 @@ bool P042_data_struct::plugin_init(struct EventStruct *event) { } } - return Candle_pixels != nullptr; + return nullptr != Candle_pixels; } bool P042_data_struct::plugin_read(struct EventStruct *event) { diff --git a/src/src/PluginStructs/P042_data_struct.h b/src/src/PluginStructs/P042_data_struct.h index 414b5debf0..b039708104 100644 --- a/src/src/PluginStructs/P042_data_struct.h +++ b/src/src/PluginStructs/P042_data_struct.h @@ -5,7 +5,7 @@ #ifdef USES_P042 -# include +# include # define P042_NUM_PIXEL 20 // Defines the default amount of LED Pixels @@ -98,9 +98,9 @@ struct P042_data_struct : public PluginTaskData_base { // global variables unsigned long Candle_Update = 0; word Candle_Temp[3] = { 0 }; // Temp variables - boolean GPIO_Set = false; + bool GPIO_Set = false; - Adafruit_NeoPixel *Candle_pixels; + NeoPixelBus_wrapper *Candle_pixels = nullptr; }; diff --git a/src/src/PluginStructs/P070_data_struct.cpp b/src/src/PluginStructs/P070_data_struct.cpp index 1bc5c81bf3..81fad24a16 100644 --- a/src/src/PluginStructs/P070_data_struct.cpp +++ b/src/src/PluginStructs/P070_data_struct.cpp @@ -18,9 +18,9 @@ void P070_data_struct::reset() { } void P070_data_struct::init(struct EventStruct *event) { - if (!Plugin_070_pixels) + if (nullptr == Plugin_070_pixels) { - Plugin_070_pixels = new (std::nothrow) Adafruit_NeoPixel(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); + Plugin_070_pixels = new (std::nothrow) NeoPixelBus_wrapper(NUMBER_LEDS, CONFIG_PIN1, NEO_GRB + NEO_KHZ800); if (Plugin_070_pixels == nullptr) { return; diff --git a/src/src/PluginStructs/P070_data_struct.h b/src/src/PluginStructs/P070_data_struct.h index 4d3cd34c67..a48f6b9a0f 100644 --- a/src/src/PluginStructs/P070_data_struct.h +++ b/src/src/PluginStructs/P070_data_struct.h @@ -5,7 +5,7 @@ #ifdef USES_P070 -# include +#include # define NUMBER_LEDS 60 // number of LED in the strip @@ -39,7 +39,7 @@ struct P070_data_struct : public PluginTaskData_base { bool thick_12_mark = false; // thicker marking of the 12h position uint8_t marks[14] = { 0 }; // Positions of the hour marks and dials - Adafruit_NeoPixel *Plugin_070_pixels = nullptr; + NeoPixelBus_wrapper *Plugin_070_pixels = nullptr; }; diff --git a/src/src/PluginStructs/P093_data_struct.cpp b/src/src/PluginStructs/P093_data_struct.cpp index 3e25aa01fa..abda89fe6f 100644 --- a/src/src/PluginStructs/P093_data_struct.cpp +++ b/src/src/PluginStructs/P093_data_struct.cpp @@ -10,6 +10,10 @@ * * Plugin is based on "Arduino library to control Mitsubishi Heat Pumps" from * https://github.com/SwiCago/HeatPump. + * + * SetRemoteTemperature is based on following Issue and Resolve + * https://github.com/SwiCago/HeatPump/pull/144#issue-514996963 + * https://github.com/SwiCago/HeatPump/pull/144/commits/c50372c7632b9e7324caf0c0fc0773871645688e * */ @@ -78,7 +82,9 @@ bool P093_data_struct::read(String& result) const { result += _currentValues.compressorFrequency; } result += F(",\"temperature\":"); - result += toString(_currentValues.temperature, 1) + '}'; + result += toString(_currentValues.temperature, 1); + result += F(",\"remoteTemperature\":"); + result += toString(_currentValues.remoteTemperature, 1) + '}'; return true; } @@ -120,6 +126,9 @@ bool P093_data_struct::plugin_get_config_value(struct EventStruct *event, } else if (_includeStatus && equals(command, F("compressorfrequency"))) { string = _currentValues.compressorFrequency; + } else + if (equals(command, F("remotetemperature"))) { + string = toString(_currentValues.remoteTemperature, 1); } else { success = false; } @@ -149,6 +158,13 @@ void P093_data_struct::write(const String& command, const String& value) { _writeStatus.set(Vane); } else if ((equals(command, F("widevane"))) && lookup(value, _mappings.wideVane, _wantedSettings.wideVane)) { _writeStatus.set(WideVane); + } else if (equals(command, F("remotetemperature"))) { + float remotetemperature = 0; + + if (string2float(value, remotetemperature)) { + _wantedSettings.remoteTemperature = remotetemperature; + _writeStatus.set(RemoteTemperature); + } } # undef lookup @@ -294,6 +310,10 @@ void P093_data_struct::applySettingsLocally() { if (_writeStatus.isDirty(WideVane)) { _currentValues.wideVane = _wantedSettings.wideVane; } + + if (_writeStatus.isDirty(RemoteTemperature)) { + _currentValues.remoteTemperature = _wantedSettings.remoteTemperature; + } } void P093_data_struct::cancelWaitingAndTransitTo(P093_data_struct::State state) { @@ -359,8 +379,26 @@ void P093_data_struct::applySettings() { packet[7] |= 0x01; } + if (_writeStatus.isDirty(RemoteTemperature)) { + memset(packet + 6, 0, 15); + packet[5] = 0x07; + if(_wantedSettings.remoteTemperature > 0) { + packet[6] |= 0x01; + _wantedSettings.remoteTemperature = _wantedSettings.remoteTemperature * 2; + _wantedSettings.remoteTemperature = round(_wantedSettings.remoteTemperature); + _wantedSettings.remoteTemperature = _wantedSettings.remoteTemperature / 2; + if (_tempMode) { //units that don't support 0.5 increment + packet[8] = static_cast(_wantedSettings.remoteTemperature * 2.0f + 128.0f); + } else { //units that do support 0.5 increment + packet[7] = static_cast(3.0f + ((_wantedSettings.remoteTemperature - 10.0f) * 2.0f)); + } + } + else { + packet[6] = 0x00; + packet[8] = 0x80; //MHK1 send 80, even though it could be 00, since ControlByte is 00 + } + } packet[21] = checkSum(packet, 21); - sendPacket(packet, PACKET_LEN); } diff --git a/src/src/PluginStructs/P093_data_struct.h b/src/src/PluginStructs/P093_data_struct.h index 19bf81be0a..df95e65c38 100644 --- a/src/src/PluginStructs/P093_data_struct.h +++ b/src/src/PluginStructs/P093_data_struct.h @@ -118,12 +118,13 @@ struct P093_data_struct : public PluginTaskData_base { ReadTimeout }; - static const uint8_t Temperature = 0x01; - static const uint8_t Power = 0x02; - static const uint8_t Mode = 0x04; - static const uint8_t Fan = 0x08; - static const uint8_t Vane = 0x10; - static const uint8_t WideVane = 0x20; + static const uint8_t Temperature = 0x01; + static const uint8_t Power = 0x02; + static const uint8_t Mode = 0x04; + static const uint8_t Fan = 0x08; + static const uint8_t Vane = 0x10; + static const uint8_t WideVane = 0x20; + static const uint8_t RemoteTemperature = 0x30; struct WriteStatus { WriteStatus() : _flags(0) {} @@ -158,6 +159,7 @@ struct P093_data_struct : public PluginTaskData_base { uint8_t vane; uint8_t wideVane; float roomTemperature; + float remoteTemperature; bool operating; uint8_t compressorFrequency; @@ -165,23 +167,25 @@ struct P093_data_struct : public PluginTaskData_base { power(0), iSee(false), mode(0), - temperature(0), + temperature(0.0f), fan(0), vane(0), wideVane(0), - roomTemperature(0), + roomTemperature(0.0f), + remoteTemperature(0.0f), operating(false), compressorFrequency(0) {} bool operator!=(const Values& rhs) const { return power != rhs.power || mode != rhs.mode || - temperature != rhs.temperature || + !essentiallyEqual(temperature, rhs.temperature) || fan != rhs.fan || vane != rhs.vane || wideVane != rhs.wideVane || iSee != rhs.iSee || - roomTemperature != rhs.roomTemperature || + !essentiallyEqual(roomTemperature, rhs.roomTemperature) || + !essentiallyEqual(remoteTemperature, rhs.remoteTemperature) || operating != rhs.operating || compressorFrequency != rhs.compressorFrequency; } diff --git a/src/src/PluginStructs/P131_data_struct.cpp b/src/src/PluginStructs/P131_data_struct.cpp index 6ee9273b7e..7ec03ebab1 100644 --- a/src/src/PluginStructs/P131_data_struct.cpp +++ b/src/src/PluginStructs/P131_data_struct.cpp @@ -119,6 +119,7 @@ bool P131_data_struct::plugin_init(struct EventStruct *event) { if (success) { gfxHelper->initialize(); gfxHelper->setRotation(_rotation); + matrix->begin(); matrix->setBrightness(std::min(_maxbright, _brightness)); // Set brightness, so we don't get blinded by the light matrix->fillScreen(_bgcolor); // fill screen with black color matrix->show(); // Update the display @@ -264,8 +265,8 @@ void P131_data_struct::display_content(struct EventStruct *event, bool scrollOnly, uint8_t line) { if (isInitialized() && (nullptr != gfxHelper)) { - int16_t yPos = 0; - bool useVal = gfxHelper->getValidation(); + int16_t yPos = 0; + const bool useVal = gfxHelper->getValidation(); gfxHelper->setValidation(false); // Ignore validation to enable scrolling uint8_t x = 0; diff --git a/src/src/PluginStructs/P131_data_struct.h b/src/src/PluginStructs/P131_data_struct.h index 2c990c416a..4909822e7e 100644 --- a/src/src/PluginStructs/P131_data_struct.h +++ b/src/src/PluginStructs/P131_data_struct.h @@ -142,19 +142,20 @@ struct P131_data_struct : public PluginTaskData_base { Adafruit_NeoMatrix *matrix = nullptr; AdafruitGFX_helper *gfxHelper = nullptr; - uint8_t _matrixWidth = 8; - uint8_t _matrixHeight = 8; - uint8_t _tileWidth = 1; - uint8_t _tileHeight = 1; - int8_t _pin = -1; - uint8_t _matrixType = NEO_MATRIX_TOP | NEO_MATRIX_LEFT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE; - uint8_t _ledType = NEO_TILE_TOP | NEO_TILE_LEFT | NEO_TILE_ROWS | NEO_TILE_PROGRESSIVE; - uint8_t _rotation = 0; - uint8_t _fontscaling = 1; - AdaGFXTextPrintMode _textmode = AdaGFXTextPrintMode::ContinueToNextLine; + uint8_t _matrixWidth = 8; + uint8_t _matrixHeight = 8; + uint8_t _tileWidth = 1; + uint8_t _tileHeight = 1; + int8_t _pin = -1; + uint8_t _matrixType = NEO_MATRIX_TOP | NEO_MATRIX_LEFT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE | + NEO_TILE_TOP | NEO_TILE_LEFT | NEO_TILE_ROWS | NEO_TILE_PROGRESSIVE; + uint8_t _rotation = 0; + uint8_t _fontscaling = 1; + AdaGFXTextPrintMode _textmode = AdaGFXTextPrintMode::ContinueToNextLine; String _commandTrigger; uint8_t _brightness = 40; uint8_t _maxbright = 255; + neoPixelType _ledType = NEO_GRB + NEO_KHZ800; uint16_t _fgcolor = ADAGFX_WHITE; uint16_t _bgcolor = ADAGFX_BLACK; diff --git a/src/src/PluginStructs/P159_data_struct.cpp b/src/src/PluginStructs/P159_data_struct.cpp new file mode 100644 index 0000000000..4befe37fdd --- /dev/null +++ b/src/src/PluginStructs/P159_data_struct.cpp @@ -0,0 +1,427 @@ +#include "../PluginStructs/P159_data_struct.h" + +#ifdef USES_P159 + +const __FlashStringHelper* Plugin_159_valuename(uint8_t value_nr, + bool displayString) { + const __FlashStringHelper *strings[] { /*** ATTENTION: Don't change order of values as these are stored as user-selected!!! ***/ + F("Presence"), F("Presence"), + F("Stationary Presence"), F("StatPres"), + F("Moving Presence"), F("MovPres"), + F("Object distance"), F("Distance"), + F("Stationary Object distance"), F("StatDist"), + F("Moving Object distance"), F("MovDist"), + F("Stationary Object energy"), F("StatEnergy"), + F("Moving Object energy"), F("MovEnergy"), + F("Ambient light sensor"), F("AmbLight"), + F("Output pin state"), F("OutputPin"), + F("Stationary Object energy gate "), F("StatEnergyGate"), + F("Moving Object energy gate "), F("MovEnergyGate"), + F("Stationary sensitivity gate "), F("StatSensGate"), + F("Moving sensitivity gate "), F("MovSensGate"), + }; + const size_t index = (2 * value_nr) + (displayString ? 0 : 1); + constexpr size_t nrStrings = NR_ELEMENTS(strings); + + if (index < nrStrings) { + return strings[index]; + } + return F(""); +} + +P159_data_struct::P159_data_struct(ESPEasySerialPort portType, + int8_t rxPin, + int8_t txPin, + bool engineeringMode) { + _engineeringMode = engineeringMode; + + // Try to open the associated serial port + easySerial = new (std::nothrow) ESPeasySerial(portType, rxPin, txPin); + + if (nullptr != easySerial) { + easySerial->begin(256000); + radar = new (std::nothrow) ld2410(); + + if (nullptr != radar) { + if (radar->begin(*easySerial, false)) { + bool rst = radar->requestRestart(); + + // start initiated, now wait, next step: request configuration + milestone = millis(); + state = P159_state_e::Restarting; + addLog(LOG_LEVEL_INFO, concat(F("LD2410: Restart sensor: "), rst ? 1 : 0)); + } else { + delete radar; + radar = nullptr; + } + } + } + addLog(LOG_LEVEL_INFO, concat(F("LD2410: Initialized: "), isValid() ? 1 : 0)); +} // constructor + +void P159_data_struct::disconnectSerial() { + if (nullptr != easySerial) { + delete easySerial; + easySerial = nullptr; + } + + if (nullptr != radar) { + delete radar; + radar = nullptr; + } +} // disconnectSerial() + +bool P159_data_struct::processSensor(struct EventStruct *event) { + bool new_data = false; + + if (isValid()) { + uint32_t iStart = millis(); // FIXME Remove log + P159_state_e sState = state; + + switch (state) { + case P159_state_e::Initializing: + addLog(LOG_LEVEL_INFO, F("LD2410: Initializing...")); + break; + case P159_state_e::Restarting: + + if ((milestone > 0) && (timePassedSince(milestone) > P159_DELAY_RESTART)) { + state = P159_state_e::GetVersion; + milestone = 0; + radar->requestFirmwareVersion(); + } + break; + case P159_state_e::GetVersion: + + state = P159_state_e::GetConfiguration; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + addLog(LOG_LEVEL_INFO, concat(F("LD2410: Firmware version: "), radar->cmdFirmwareVersion())); + } + _configurationRead = radar->requestCurrentConfiguration(); + break; + case P159_state_e::GetConfiguration: + + state = P159_state_e::Engineering; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + addLog(LOG_LEVEL_INFO, concat(F("LD2410: Fetch configuration: "), _configurationRead ? 1 : 0)); + + if (_configurationRead) { + const uint8_t mGate = radar->cfgMaxGate(); + const uint8_t mMvGate = radar->cfgMaxMovingGate(); + const uint8_t mStGate = radar->cfgMaxStationaryGate(); + const uint8_t mMax = std::max(mGate, std::max(mMvGate, mStGate)); + addLog(LOG_LEVEL_INFO, strformat(F("LD2410: Sensor idle time: %d sec."), radar->cfgSensorIdleTimeInSeconds())); + addLog(LOG_LEVEL_INFO, strformat(F("LD2410: Max. gate: %d, max. moving gate: %d, max. stationary gate: %d"), + mGate, mMvGate, mStGate)); + + for (uint8_t i = 0; i <= mMax; ++i) { + addLog(LOG_LEVEL_INFO, strformat(F("LD2410: Sensitivity, gate %d (%.2f - %.2f mtr): moving:%3d, stationary:%3d"), + i, i * 0.75f, (i + 1) * 0.75f, + i <= mMvGate ? radar->cfgMovingGateSensitivity(i) : 0, + i <= mStGate ? radar->cfgStationaryGateSensitivity(i) : 0)); + } + } + } + break; + case P159_state_e::Engineering: + state = P159_state_e::Running; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + if (_engineeringMode) { + addLog(LOG_LEVEL_INFO, concat(F("LD2410: Engineering mode: "), radar->requestStartEngineeringMode() ? 1 : 0)); + } + addLog(LOG_LEVEL_INFO, F("LD2410: Enter Running state.")); + } + break; + case P159_state_e::Running: + new_data = radar->ld2410_loop(); + + if (new_data && radar->dataReady()) { + const int8_t valueCount = P159_NR_OUTPUT_VALUES; + bool result = false; + + for (int8_t i = 0; i < valueCount; ++i) { + const uint8_t pconfigIndex = i + P159_QUERY1_CONFIG_POS; + bool isChanged = false; + UserVar[event->BaseVarIndex + i] = getRadarValue(PCONFIG(pconfigIndex), UserVar[event->BaseVarIndex + i], isChanged); + + result |= isChanged; + } + + if (result && (timePassedSince(lastSent) >= P159_DELAY_SENDOUT)) { + lastSent = millis(); // Sending data incorporated in timing, just like PLUGIN_READ + sendData(event); + const uint16_t err = radar->getErrorCountAndReset(); + + if ((err != 0) && loglevelActiveFor(LOG_LEVEL_ERROR)) { + addLog(LOG_LEVEL_ERROR, concat(F("LD2410: Frame Errorcounter: "), err)); + } + } + } + break; + } + + if (P159_state_e::Running != sState) { // FIXME Remove log + addLog(LOG_LEVEL_INFO, strformat(F("LD2410: Starting state: %d duration: %d msec."), + static_cast(sState), timePassedSince(iStart))); + } + } // isValid() + + return new_data; +} // processSensor() + +bool P159_data_struct::plugin_read(struct EventStruct *event) { + bool result = false; + + if (isValid() && radar->isConnected()) { + const int8_t valueCount = P159_NR_OUTPUT_VALUES; + result = !P159_GET_UPDATE_DIFF_ONLY; + + for (int8_t i = 0; i < valueCount; ++i) { + const uint8_t pconfigIndex = i + P159_QUERY1_CONFIG_POS; + bool isChanged = false; + UserVar[event->BaseVarIndex + i] = getRadarValue(PCONFIG(pconfigIndex), UserVar[event->BaseVarIndex + i], isChanged); + + result |= isChanged; + } + + if (result && (timePassedSince(lastSent) < P159_DELAY_SENDOUT)) { // Avoid duplicate sendouts + result = false; + } else if (result) { + lastSent = millis(); + } + } + return result; +} // plugin_read() + +int P159_data_struct::getRadarValue(int16_t valueIndex, + int previousValue, + bool & isChanged) { + int result = previousValue; + + if (isValid()) { + switch (valueIndex) { + case P159_OUTPUT_PRESENCE: result = radar->presenceDetected() ? 1 : 0; break; + case P159_OUTPUT_STATIONARY_PRESENCE: result = radar->isStationary() ? 1 : 0; break; + case P159_OUTPUT_MOVING_PRESENCE: result = radar->isMoving() ? 1 : 0; break; + case P159_OUTPUT_DISTANCE: result = radar->detectionDistance(); break; + case P159_OUTPUT_STATIONARY_DISTANCE: result = radar->stationaryTargetDistance(); break; + case P159_OUTPUT_MOVING_DISTANCE: result = radar->movingTargetDistance(); break; + case P159_OUTPUT_STATIONARY_ENERGY: result = radar->stationaryTargetEnergy(); break; + case P159_OUTPUT_MOVING_ENERGY: result = radar->movingTargetEnergy(); break; + } + + if ((valueIndex >= P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE0) && (valueIndex <= P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE8)) { + result = radar->cfgStationaryGateSensitivity(valueIndex - P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE0); + } + else + if ((valueIndex >= P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0) && (valueIndex <= P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE8)) { + result = radar->cfgMovingGateSensitivity(valueIndex - P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0); + } + + if (_engineeringMode) { + if ((valueIndex >= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0) && (valueIndex <= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE8)) { + result = radar->engStaticDistanceGateEnergy(valueIndex - P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0); + } + else + if ((valueIndex >= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0) && (valueIndex <= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE8)) { + result = radar->engMovingDistanceGateEnergy(valueIndex - P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0); + } + else + if (P159_OUTPUT_LIGHT_SENSOR == valueIndex) { + result = radar->engLightSensorValue(); + } + else + if (P159_OUTPUT_PIN_STATE == valueIndex) { + result = radar->engOutputPinState(); + } + } + isChanged = result != previousValue; + } // isValid() + return result; +} // getRadarValue() + +void P159_data_struct::addJavascript() { + addHtml(F("" + )); +} + +bool P159_data_struct::plugin_webform_load(struct EventStruct *event) { + bool result = false; + + if (isValid()) { + if (!_configurationRead) { + _configurationRead = radar->requestCurrentConfiguration(); + } + + if (_configurationRead) { + addRowLabel(F("Firmware version: ")); + addHtml(radar->cmdFirmwareVersion()); + + const uint8_t mGate = radar->cfgMaxGate(); + const uint8_t mMvGate = radar->cfgMaxMovingGate(); + const uint8_t mStGate = radar->cfgMaxStationaryGate(); + const uint8_t mMax = std::max(mGate, std::max(mMvGate, mStGate)); + const uint16_t idleTime = radar->cfgSensorIdleTimeInSeconds(); + + addJavascript(); + addFormCheckBox(F("Modify sensor settings"), F("saveSens"), false); + + int idx = 0; + addFormNumericBox(F("Idle seconds"), getPluginCustomArgName(idx++), idleTime, 0, 65535, + # if FEATURE_TOOLTIPS + EMPTY_STRING, + # endif // if FEATURE_TOOLTIPS + true); + addUnit(F("0..65535 sec.")); + addFormNumericBox(F("Max. Moving gates"), getPluginCustomArgName(idx++), mMvGate, 2, 8, + # if FEATURE_TOOLTIPS + EMPTY_STRING, + # endif // if FEATURE_TOOLTIPS + true); + addUnit(F("2..8")); + addFormNumericBox(F("Max. Stationary gates"), getPluginCustomArgName(idx++), mStGate, 2, 8, + # if FEATURE_TOOLTIPS + EMPTY_STRING, + # endif // if FEATURE_TOOLTIPS + true); + addUnit(F("2..8")); + + addRowLabel(F("Sensitivity")); + html_table(EMPTY_STRING, false); // Sub-table + html_table_header(F("Gate"), 200); + html_table_header(F("Moving"), 100); + html_table_header(F("Stationary"), 100); + + for (uint8_t i = 0; i <= mMax; ++i) { + html_TR_TD(); + addHtml(strformat(F("Gate %d (%.2f - %.2f mtr)"), i, i * 0.75f, (i + 1) * 0.75f)); + html_TD(); + addNumericBox(getPluginCustomArgName(idx++), radar->cfgMovingGateSensitivity(i), 0, 100, true); + html_TD(); + addNumericBox(getPluginCustomArgName(idx++), radar->cfgStationaryGateSensitivity(i), 0, 100, true); + } + html_end_table(); + addHtml(strformat(F("\n"), + idx)); + result = true; + } + } + return result; +} + +bool P159_data_struct::plugin_webform_save(struct EventStruct *event) { + bool result = false; + const bool doSave = isFormItemChecked(F("saveSens")); + + if (isValid() && doSave) { + int idx = 0; + const uint16_t idle = getFormItemInt(getPluginCustomArgName(idx++)); + const uint8_t gMove = getFormItemInt(getPluginCustomArgName(idx++)); + const uint8_t gStat = getFormItemInt(getPluginCustomArgName(idx++)); + addLog(LOG_LEVEL_INFO, F("LD2410: Save sensitivity settings to sensor, start...")); + radar->requestConfigurationModeBegin(); + radar->setMaxValues(gMove, gStat, idle); + const uint16_t maxGate = radar->cfgMaxGate(); + + for (uint16_t gate = 0; gate <= maxGate; ++gate) { + const uint16_t sMove = getFormItemInt(getPluginCustomArgName(idx++)); + const uint16_t sStat = getFormItemInt(getPluginCustomArgName(idx++)); + + // Set sensitivity (level) to 100 to effectively disable sensitivity + radar->setGateSensitivityThreshold(gate, gate <= gMove ? sMove : 100, gate <= gStat ? sStat : 100); + } + radar->requestConfigurationModeEnd(); + addLog(LOG_LEVEL_INFO, F("LD2410: Save sensitivity settings to sensor, done.")); + } + return result; +} + +bool P159_data_struct::plugin_write(struct EventStruct *event, + String & string) { + bool result = false; + const String cmd = parseString(string, 1); + + if (isValid() && equals(cmd, F("ld2410"))) { + const String subcmd = parseString(string, 2); + + if (equals(subcmd, F("factoryreset"))) { + addLog(LOG_LEVEL_ERROR, F("LD2410: Performing unconditional sensor factory reset!")); + result = radar->requestFactoryReset(); + radar->requestRestart(); + + // start initiated, now wait, next step: request configuration + milestone = millis(); + state = P159_state_e::Restarting; + } else if (equals(subcmd, F("logall"))) { + result = plugin_get_config_value(event, string, true); + } + } + return result; +} + +bool P159_data_struct::plugin_get_config_value(struct EventStruct *event, + String & string, + bool logAll) { + bool result = false; + + if (isValid()) { + const String cmd = parseString(string, 1); + const int16_t count = P159_NR_MAX_OUTPUT_OPTIONS; + + for (int16_t option = 0; option < count; ++option) { + int16_t idx = option; + int16_t gate = -1; + + if ((option >= P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE0) && (option <= P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE8)) { + idx = P159_OUTPUT_STATIC_SENSOR_GATE_index; + gate = option - P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE0; + } else + if ((option >= P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0) && (option <= P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE8)) { + idx = P159_OUTPUT_MOVING_SENSOR_GATE_index; + gate = option - P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0; + } else + if ((option >= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE8)) { + if (_engineeringMode) { + idx = P159_OUTPUT_STATIC_DISTANCE_GATE_index; + gate = option - P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0; + } else { + idx = -1; + } + } else + if ((option >= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0) && (option <= P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE8)) { + if (_engineeringMode) { + idx = P159_OUTPUT_MOVING_DISTANCE_GATE_index; + gate = option - P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0; + } else { + idx = -1; + } + } + + if ((idx > -1) && (logAll || + cmd.equalsIgnoreCase(concat(Plugin_159_valuename(idx, false), (gate > -1) ? String(gate) : EMPTY_STRING)))) { + bool dummy; + string = getRadarValue(option, -1, dummy); + result = true; + + if (!logAll) { + break; + } else if (loglevelActiveFor(LOG_LEVEL_INFO)) { + addLog(LOG_LEVEL_INFO, strformat(F("LD2410: %s: %s"), + concat(Plugin_159_valuename(idx, true), (gate > -1) ? String(gate) : EMPTY_STRING).c_str(), + string.c_str())); + } + } + } + } + return result; +} + +#endif // USES_P159 diff --git a/src/src/PluginStructs/P159_data_struct.h b/src/src/PluginStructs/P159_data_struct.h new file mode 100644 index 0000000000..10ca327557 --- /dev/null +++ b/src/src/PluginStructs/P159_data_struct.h @@ -0,0 +1,120 @@ +#ifndef PLUGINSTRUCTS_P159_DATA_STRUCT_H +#define PLUGINSTRUCTS_P159_DATA_STRUCT_H + +#include "../../_Plugin_Helper.h" +#ifdef USES_P159 +# define PLUGIN_159_DEBUG false // set to true for extra log info + +# include +# include + +// place sensor type selector right after the output value settings +# define P159_QUERY1_CONFIG_POS 0 +# define P159_SENSOR_TYPE_INDEX (P159_QUERY1_CONFIG_POS + VARS_PER_TASK) +# define P159_NR_OUTPUT_VALUES getValueCountFromSensorType(static_cast(PCONFIG(P159_SENSOR_TYPE_INDEX))) + +# define P159_CONFIG_FLAGS PCONFIG_ULONG(0) + +# define P159_FLAG_ENGINEERING_MODE 0 +# define P159_FLAG_UPDATE_DIFF_ONLY 1 + +# define P159_GET_ENGINEERING_MODE bitRead(P159_CONFIG_FLAGS, P159_FLAG_ENGINEERING_MODE) +# define P159_SET_ENGINEERING_MODE(x) bitWrite(P159_CONFIG_FLAGS, P159_FLAG_ENGINEERING_MODE, x) +# define P159_GET_UPDATE_DIFF_ONLY bitRead(P159_CONFIG_FLAGS, P159_FLAG_UPDATE_DIFF_ONLY) +# define P159_SET_UPDATE_DIFF_ONLY(x) bitWrite(P159_CONFIG_FLAGS, P159_FLAG_UPDATE_DIFF_ONLY, x) + +# define P159_OUTPUT_PRESENCE 0 +# define P159_OUTPUT_STATIONARY_PRESENCE 1 +# define P159_OUTPUT_MOVING_PRESENCE 2 +# define P159_OUTPUT_DISTANCE 3 +# define P159_OUTPUT_STATIONARY_DISTANCE 4 +# define P159_OUTPUT_MOVING_DISTANCE 5 +# define P159_OUTPUT_STATIONARY_ENERGY 6 +# define P159_OUTPUT_MOVING_ENERGY 7 + +// Engineering mode: +# define P159_OUTPUT_LIGHT_SENSOR 8 +# define P159_OUTPUT_PIN_STATE 9 + +# define P159_OUTPUT_STATIC_DISTANCE_GATE_index 10 +# define P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE0 10 +# define P159_OUTPUT_STATIC_DISTANCE_ENERGY_GATE8 18 + +# define P159_OUTPUT_MOVING_DISTANCE_GATE_index 11 +# define P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE0 19 +# define P159_OUTPUT_MOVING_DISTANCE_ENERGY_GATE8 27 + +# define P159_OUTPUT_STATIC_SENSOR_GATE_index 12 +# define P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE0 28 +# define P159_OUTPUT_STATIC_SENSOR_ENERGY_GATE8 36 + +# define P159_OUTPUT_MOVING_SENSOR_GATE_index 13 +# define P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0 37 +# define P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE8 45 + +# define P159_NR_OUTPUT_OPTIONS 8 // Last P159_OUTPUT_*_DISTANCE value + 1 (count) +# define P159_NR_ENGINEERING_OUTPUT_OPTIONS 28 // Last P159_OUTPUT_*_DISTANCE value + 1 (count) ENGINEERING +# define P159_NR_MAX_OUTPUT_OPTIONS 46 // Last P159_OUTPUT_*_SENSOR value + 1 (count) + +# define P159_DELAY_RESTART 2500 // milliseconds to 'wait' (ignore) after a device-restart +# define P159_DELAY_SENDOUT 100 // Minimal milliseconds between sending data/events + +enum class P159_state_e : uint8_t { + Initializing = 0u, + Restarting = 1u, + GetVersion = 2u, + GetConfiguration = 3u, + Engineering = 4u, + Running = 5u, +}; + +const __FlashStringHelper* Plugin_159_valuename(uint8_t value_nr, + bool displayString); + +struct P159_data_struct : public PluginTaskData_base { + P159_data_struct(ESPEasySerialPort portType, + int8_t rxPin, + int8_t txPin, + bool engineeringMode); + virtual ~P159_data_struct() = default; + void disconnectSerial(); // Disconnect the serial port connected to the sensor + bool processSensor(struct EventStruct *event); // Process sensor, must be called regularly + bool plugin_read(struct EventStruct *event); + bool plugin_webform_load(struct EventStruct *event); + bool plugin_webform_save(struct EventStruct *event); + bool plugin_write(struct EventStruct *event, + String & string); + bool plugin_get_config_value(struct EventStruct *event, + String & string, + bool logAll = false); + + bool isValid() const { + return nullptr != easySerial && nullptr != radar; + } + + P159_state_e getCurrentState() const { + return state; + } + + bool isRunning() const { + return isValid() && P159_state_e::Running == state; + } + +private: + + int getRadarValue(int16_t valueIndex, + int previousValue, + bool & isChanged); + void addJavascript(); + + ESPeasySerial *easySerial = nullptr; // Serial port object + ld2410 *radar = nullptr; // Sensor object + uint32_t milestone = 0; // When can we do the next phase when not in Running state? + uint32_t lastSent = 0; // Last time we sent out data + P159_state_e state = P159_state_e::Initializing; + bool _engineeringMode = false; + bool _configurationRead = false; +}; + +#endif // USES_P159 +#endif // PLUGINSTRUCTS_P159_DATA_STRUCT_H diff --git a/src/src/Static/WebStaticData.cpp b/src/src/Static/WebStaticData.cpp index d360c5b388..7972988e98 100644 --- a/src/src/Static/WebStaticData.cpp +++ b/src/src/Static/WebStaticData.cpp @@ -13,7 +13,17 @@ String generate_external_URL(const String& fname, bool isEmbedded) { // Generate some URL indicating static files which will need to be served with some cache-control header return concat(F("static_"), Cache.fileCacheClearMoment) + '_' + fname; } - return concat(get_CDN_url_prefix(), fname); + #if FEATURE_ALTERNATIVE_CDN_URL + String cdn = get_CDN_url_custom(); + if (!cdn.isEmpty()) { + cdn = parseTemplate(cdn); // Replace system variables. + return concat(cdn, fname); // cdn.endsWith('/') check done at save + } else { + #endif // if FEATURE_ALTERNATIVE_CDN_URL + return concat(get_CDN_url_prefix(), fname); + #if FEATURE_ALTERNATIVE_CDN_URL + } + #endif // if FEATURE_ALTERNATIVE_CDN_URL } void serve_CDN_CSS(const __FlashStringHelper * fname, bool isEmbedded) { diff --git a/src/src/WebServer/AdvancedConfigPage.cpp b/src/src/WebServer/AdvancedConfigPage.cpp index 71ae6ed6cc..862f0618b2 100644 --- a/src/src/WebServer/AdvancedConfigPage.cpp +++ b/src/src/WebServer/AdvancedConfigPage.cpp @@ -131,6 +131,7 @@ void handle_advanced() { #endif // if FEATURE_I2C_DEVICE_CHECK Settings.WaitWiFiConnect(isFormItemChecked(LabelType::WAIT_WIFI_CONNECT)); + Settings.HiddenSSID_SlowConnectPerBSSID(isFormItemChecked(LabelType::HIDDEN_SSID_SLOW_CONNECT)); Settings.SDK_WiFi_autoreconnect(isFormItemChecked(LabelType::SDK_WIFI_AUTORECONNECT)); @@ -386,6 +387,7 @@ void handle_advanced() { addFormCheckBox(LabelType::WAIT_WIFI_CONNECT, Settings.WaitWiFiConnect()); addFormCheckBox(LabelType::SDK_WIFI_AUTORECONNECT, Settings.SDK_WiFi_autoreconnect()); + addFormCheckBox(LabelType::HIDDEN_SSID_SLOW_CONNECT, Settings.HiddenSSID_SlowConnectPerBSSID()); diff --git a/src/src/WebServer/ConfigPage.cpp b/src/src/WebServer/ConfigPage.cpp index ca75fd5f7a..55b25ec93b 100644 --- a/src/src/WebServer/ConfigPage.cpp +++ b/src/src/WebServer/ConfigPage.cpp @@ -80,7 +80,8 @@ void handle_config() { copyFormPassword(F("key2"), SecuritySettings.WifiKey2, sizeof(SecuritySettings.WifiKey2)); // Hidden SSID - Settings.IncludeHiddenSSID(isFormItemChecked(F("hiddenssid"))); + Settings.IncludeHiddenSSID(isFormItemChecked(LabelType::CONNECT_HIDDEN_SSID)); + Settings.HiddenSSID_SlowConnectPerBSSID(isFormItemChecked(LabelType::HIDDEN_SSID_SLOW_CONNECT)); // Access point password. copyFormPassword(F("apkey"), SecuritySettings.WifiAPKey, sizeof(SecuritySettings.WifiAPKey)); @@ -146,6 +147,9 @@ void handle_config() { webArg2ip(F("espethsubnet"), Settings.ETH_Subnet); webArg2ip(F("espethdns"), Settings.ETH_DNS); #endif // if FEATURE_ETHERNET + #if FEATURE_ALTERNATIVE_CDN_URL + set_CDN_url_custom(webArg(F("alturl"))); + #endif // if FEATURE_ALTERNATIVE_CDN_URL addHtmlError(SaveSettings()); } @@ -170,8 +174,11 @@ void handle_config() { addFormPasswordBox(F("Fallback WPA Key"), F("key2"), SecuritySettings.WifiKey2, 63); addFormNote(F("WPA Key must be at least 8 characters long")); - addFormCheckBox(F("Include Hidden SSID"), F("hiddenssid"), Settings.IncludeHiddenSSID()); + addFormCheckBox(LabelType::CONNECT_HIDDEN_SSID, Settings.IncludeHiddenSSID()); addFormNote(F("Must be checked to connect to a hidden SSID")); + + addFormCheckBox(LabelType::HIDDEN_SSID_SLOW_CONNECT, Settings.HiddenSSID_SlowConnectPerBSSID()); + addFormNote(F("Required for some AP brands like Mikrotik to connect to hidden SSID")); addFormSeparator(2); addFormPasswordBox(F("WPA AP Mode Key"), F("apkey"), SecuritySettings.WifiAPKey, 63); @@ -259,6 +266,15 @@ void handle_config() { addFormSeparator(2); + #if FEATURE_ALTERNATIVE_CDN_URL + addFormSubHeader(F("CDN (Content delivery network)")); + + addFormTextBox(F("Custom CDN URL"), F("alturl"), get_CDN_url_custom(), 255); + addFormNote(concat(F("Leave empty for default CDN url: "), get_CDN_url_prefix())); + + addFormSeparator(2); + #endif // if FEATURE_ALTERNATIVE_CDN_URL + html_TR_TD(); html_TD(); addSubmitButton(); diff --git a/src/src/WebServer/DevicesPage.cpp b/src/src/WebServer/DevicesPage.cpp index 9b076167de..9824386cf5 100644 --- a/src/src/WebServer/DevicesPage.cpp +++ b/src/src/WebServer/DevicesPage.cpp @@ -147,6 +147,14 @@ void handle_devices() { { // change of device: cleanup old device and reset default settings setTaskDevice_to_TaskIndex(taskdevicenumber, taskIndex); + const deviceIndex_t DeviceIndex = getDeviceIndex(taskdevicenumber); + + if (validDeviceIndex(DeviceIndex)) { + const DeviceStruct& device = Device[DeviceIndex]; + if ((device.Type == DEVICE_TYPE_I2C) && device.I2CMax100kHz) { // 100 kHz-only I2C device? + bitWrite(Settings.I2C_Flags[taskIndex], I2C_FLAGS_SLOW_SPEED, 1); // Then: Enable Force Slow I2C speed checkbox by default + } + } } else if (taskdevicenumber != INVALID_PLUGIN_ID) // save settings { @@ -936,7 +944,7 @@ void handle_devices_TaskSettingsPage(taskIndex_t taskIndex, uint8_t page) addPinConfig = false; if (Settings.TaskDeviceDataFeed[taskIndex] == 0) { - devicePage_show_I2C_config(taskIndex); + devicePage_show_I2C_config(taskIndex, DeviceIndex); } } @@ -1130,7 +1138,7 @@ void devicePage_show_serial_config(taskIndex_t taskIndex) } #endif -void devicePage_show_I2C_config(taskIndex_t taskIndex) +void devicePage_show_I2C_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex) { struct EventStruct TempEvent(taskIndex); @@ -1144,6 +1152,9 @@ void devicePage_show_I2C_config(taskIndex_t taskIndex) PluginCall(PLUGIN_WEBFORM_SHOW_I2C_PARAMS, &TempEvent, dummy); addFormCheckBox(F("Force Slow I2C speed"), F("taskdeviceflags0"), bitRead(Settings.I2C_Flags[taskIndex], I2C_FLAGS_SLOW_SPEED)); + if (Device[DeviceIndex].I2CMax100kHz) { + addFormNote(F("This device is specified for max. 100 kHz operation!")); + } # if FEATURE_I2CMULTIPLEXER diff --git a/src/src/WebServer/DevicesPage.h b/src/src/WebServer/DevicesPage.h index 03e858b2c0..8b7bece77b 100644 --- a/src/src/WebServer/DevicesPage.h +++ b/src/src/WebServer/DevicesPage.h @@ -56,7 +56,7 @@ void devicePage_show_pin_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex void devicePage_show_serial_config(taskIndex_t taskIndex); #endif -void devicePage_show_I2C_config(taskIndex_t taskIndex); +void devicePage_show_I2C_config(taskIndex_t taskIndex, deviceIndex_t DeviceIndex); void devicePage_show_output_data_type(taskIndex_t taskIndex, deviceIndex_t DeviceIndex); diff --git a/src/src/WebServer/FactoryResetPage.cpp b/src/src/WebServer/FactoryResetPage.cpp index 970aa4ce9a..ee1f2ffe38 100644 --- a/src/src/WebServer/FactoryResetPage.cpp +++ b/src/src/WebServer/FactoryResetPage.cpp @@ -51,7 +51,10 @@ void handle_factoryreset() { ResetFactoryDefaultPreference.keepWiFi(isFormItemChecked(F("kw"))); ResetFactoryDefaultPreference.keepNetwork(isFormItemChecked(F("knet"))); ResetFactoryDefaultPreference.keepNTP(isFormItemChecked(F("kntp"))); - ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog"))); + ResetFactoryDefaultPreference.keepLogConsoleSettings(isFormItemChecked(F("klog"))); +# if FEATURE_ALTERNATIVE_CDN_URL + ResetFactoryDefaultPreference.keepCustomCdnUrl(isFormItemChecked(F("kcdn"))); +#endif applyFactoryDefaultPref(); addHtmlError(SaveSettings()); } @@ -80,8 +83,13 @@ void handle_factoryreset() { addRowLabel(F("Keep NTP/DST config")); addCheckBox(F("kntp"), ResetFactoryDefaultPreference.keepNTP()); - addRowLabel(F("Keep log config")); - addCheckBox(F("klog"), ResetFactoryDefaultPreference.keepLogSettings()); + addRowLabel(F("Keep Console/Log config")); + addCheckBox(F("klog"), ResetFactoryDefaultPreference.keepLogConsoleSettings()); + +# if FEATURE_ALTERNATIVE_CDN_URL + addRowLabel(F("Keep Custom CDN url")); + addCheckBox(F("kcdn"), ResetFactoryDefaultPreference.keepCustomCdnUrl()); +#endif addTableSeparator(F("Pre-defined configurations"), 2, 3); addRowLabel(F("Pre-defined config")); @@ -157,8 +165,16 @@ void handle_factoryreset_json() { } if (hasArg(F("klog"))) { - ResetFactoryDefaultPreference.keepLogSettings(isFormItemChecked(F("klog"))); + ResetFactoryDefaultPreference.keepLogConsoleSettings(isFormItemChecked(F("klog"))); + } + +# if FEATURE_ALTERNATIVE_CDN_URL + if (hasArg(F("kcdn"))) { + ResetFactoryDefaultPreference.keepCustomCdnUrl(isFormItemChecked(F("kcdn"))); } +#endif + + #endif String error; bool performReset = false; diff --git a/src/src/WebServer/Markup.cpp b/src/src/WebServer/Markup.cpp index 0a97908bff..5184afa5a7 100644 --- a/src/src/WebServer/Markup.cpp +++ b/src/src/WebServer/Markup.cpp @@ -540,6 +540,21 @@ void addRowLabelValue(LabelType::Enum label) { addHtml(getValue(label)); } +void addRowLabelValues(const LabelType::Enum labels[]) { + size_t i = 0; + LabelType::Enum cur = static_cast(pgm_read_byte(labels + i)); + + while (true) { + const LabelType::Enum next = static_cast(pgm_read_byte(labels + i + 1)); + addRowLabelValue(cur); + if (next == LabelType::MAX_LABEL) { + return; + } + ++i; + cur = next; + } +} + void addRowLabelValue_copy(LabelType::Enum label) { addRowLabel_copy(getLabel(label)); addHtml(getValue(label)); diff --git a/src/src/WebServer/Markup.h b/src/src/WebServer/Markup.h index cf6d3d6b77..0d1553e986 100644 --- a/src/src/WebServer/Markup.h +++ b/src/src/WebServer/Markup.h @@ -175,6 +175,8 @@ void addRowLabel(LabelType::Enum label); void addRowLabelValue(LabelType::Enum label); +void addRowLabelValues(const LabelType::Enum labels[]); + void addRowLabelValue_copy(LabelType::Enum label); // ******************************************************************************** diff --git a/src/src/WebServer/SettingsArchive.cpp b/src/src/WebServer/SettingsArchive.cpp index 74ddb07720..c0e2ec9bc9 100644 --- a/src/src/WebServer/SettingsArchive.cpp +++ b/src/src/WebServer/SettingsArchive.cpp @@ -257,6 +257,7 @@ void storeDownloadFiletypeCheckbox(FileType::Enum filetype, unsigned int filenr) case FileType::NOTIFICATION_DAT: ResetFactoryDefaultPreference.fetchNotificationDat(isChecked); break; case FileType::RULES_TXT: { ResetFactoryDefaultPreference.fetchRulesTXT(filenr, isChecked); break; } case FileType::PROVISIONING_DAT: { ResetFactoryDefaultPreference.fetchProvisioningDat(isChecked); break; } + case FileType::MAX_FILETYPE: break; } diff --git a/src/src/WebServer/SetupPage.cpp b/src/src/WebServer/SetupPage.cpp index cb80354379..496471948c 100644 --- a/src/src/WebServer/SetupPage.cpp +++ b/src/src/WebServer/SetupPage.cpp @@ -111,7 +111,8 @@ void handle_setup() { safe_strncpy(SecuritySettings.WifiKey, password.c_str(), sizeof(SecuritySettings.WifiKey)); safe_strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID)); // Hidden SSID - Settings.IncludeHiddenSSID(isFormItemChecked(F("hiddenssid"))); + Settings.IncludeHiddenSSID(isFormItemChecked(LabelType::CONNECT_HIDDEN_SSID)); + Settings.HiddenSSID_SlowConnectPerBSSID(isFormItemChecked(LabelType::HIDDEN_SSID_SLOW_CONNECT)); addHtmlError(SaveSettings()); WiFiEventData.wifiSetupConnect = true; WiFiEventData.wifiConnectAttemptNeeded = true; @@ -200,9 +201,12 @@ void handle_setup() { addFormHeader(F("Advanced WiFi settings")); - addFormCheckBox(F("Include Hidden SSID"), F("hiddenssid"), Settings.IncludeHiddenSSID()); + addFormCheckBox(LabelType::CONNECT_HIDDEN_SSID, Settings.IncludeHiddenSSID()); addFormNote(F("Must be checked to connect to a hidden SSID")); + addFormCheckBox(LabelType::HIDDEN_SSID_SLOW_CONNECT, Settings.HiddenSSID_SlowConnectPerBSSID()); + addFormNote(F("Required for some AP brands like Mikrotik to connect to hidden SSID")); + html_BR(); html_BR(); diff --git a/src/src/WebServer/SysInfoPage.cpp b/src/src/WebServer/SysInfoPage.cpp index 345a711603..6ed75a3899 100644 --- a/src/src/WebServer/SysInfoPage.cpp +++ b/src/src/WebServer/SysInfoPage.cpp @@ -397,13 +397,22 @@ void handle_sysinfo_memory() { void handle_sysinfo_Ethernet() { if (active_network_medium == NetworkMedium_t::Ethernet) { addTableSeparator(F("Ethernet"), 2, 3); - addRowLabelValue(LabelType::ETH_STATE); - addRowLabelValue(LabelType::ETH_SPEED); - addRowLabelValue(LabelType::ETH_DUPLEX); - addRowLabelValue(LabelType::ETH_MAC); -// addRowLabelValue(LabelType::ETH_IP_ADDRESS_SUBNET); -// addRowLabelValue(LabelType::ETH_IP_GATEWAY); -// addRowLabelValue(LabelType::ETH_IP_DNS); + + static const LabelType::Enum labels[] PROGMEM = + { + LabelType::ETH_STATE, + LabelType::ETH_SPEED, + LabelType::ETH_DUPLEX, + LabelType::ETH_MAC, +// LabelType::ETH_IP_ADDRESS_SUBNET, +// LabelType::ETH_IP_GATEWAY, +// LabelType::ETH_IP_DNS, + + LabelType::MAX_LABEL + }; + + addRowLabelValues(labels); + } } @@ -412,18 +421,26 @@ void handle_sysinfo_Ethernet() { void handle_sysinfo_Network() { addTableSeparator(F("Network"), 2, 3); - # if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW) - addRowLabelValue(LabelType::ETH_WIFI_MODE); - # endif - - addRowLabelValue(LabelType::IP_CONFIG); - addRowLabelValue(LabelType::IP_ADDRESS_SUBNET); - addRowLabelValue(LabelType::GATEWAY); - addRowLabelValue(LabelType::CLIENT_IP); - addRowLabelValue(LabelType::DNS); - addRowLabelValue(LabelType::ALLOWED_IP_RANGE); - addRowLabelValue(LabelType::CONNECTED); - addRowLabelValue(LabelType::NUMBER_RECONNECTS); + { + static const LabelType::Enum labels[] PROGMEM = + { +# if FEATURE_ETHERNET || defined(USES_ESPEASY_NOW) + LabelType::ETH_WIFI_MODE, +# endif + LabelType::IP_CONFIG, + LabelType::IP_ADDRESS_SUBNET, + LabelType::GATEWAY, + LabelType::CLIENT_IP, + LabelType::DNS, + LabelType::ALLOWED_IP_RANGE, + LabelType::CONNECTED, + LabelType::NUMBER_RECONNECTS, + + LabelType::MAX_LABEL + }; + + addRowLabelValues(labels); + } addTableSeparator(F("WiFi"), 2, 3, F("Wifi")); @@ -474,27 +491,37 @@ void handle_sysinfo_Network() { #ifndef WEBSERVER_SYSINFO_MINIMAL void handle_sysinfo_WiFiSettings() { addTableSeparator(F("WiFi Settings"), 2, 3); - addRowLabelValue(LabelType::FORCE_WIFI_BG); - addRowLabelValue(LabelType::RESTART_WIFI_LOST_CONN); - addRowLabelValue(LabelType::FORCE_WIFI_NOSLEEP); + + static const LabelType::Enum labels[] PROGMEM = + { + LabelType::FORCE_WIFI_BG, + LabelType::RESTART_WIFI_LOST_CONN, + LabelType::FORCE_WIFI_NOSLEEP, # ifdef SUPPORT_ARP - addRowLabelValue(LabelType::PERIODICAL_GRAT_ARP); + LabelType::PERIODICAL_GRAT_ARP, # endif // ifdef SUPPORT_ARP - addRowLabelValue(LabelType::CONNECTION_FAIL_THRESH); + LabelType::CONNECTION_FAIL_THRESH, #if FEATURE_SET_WIFI_TX_PWR - addRowLabelValue(LabelType::WIFI_TX_MAX_PWR); - addRowLabelValue(LabelType::WIFI_CUR_TX_PWR); - addRowLabelValue(LabelType::WIFI_SENS_MARGIN); - addRowLabelValue(LabelType::WIFI_SEND_AT_MAX_TX_PWR); + LabelType::WIFI_TX_MAX_PWR, + LabelType::WIFI_CUR_TX_PWR, + LabelType::WIFI_SENS_MARGIN, + LabelType::WIFI_SEND_AT_MAX_TX_PWR, #endif - addRowLabelValue(LabelType::WIFI_NR_EXTRA_SCANS); + LabelType::WIFI_NR_EXTRA_SCANS, #ifdef USES_ESPEASY_NOW - addRowLabelValue(LabelType::USE_ESPEASY_NOW); - addRowLabelValue(LabelType::FORCE_ESPEASY_NOW_CHANNEL); + LabelType::USE_ESPEASY_NOW, + LabelType::FORCE_ESPEASY_NOW_CHANNEL, #endif - addRowLabelValue(LabelType::WIFI_USE_LAST_CONN_FROM_RTC); - addRowLabelValue(LabelType::WAIT_WIFI_CONNECT); - addRowLabelValue(LabelType::SDK_WIFI_AUTORECONNECT); + LabelType::WIFI_USE_LAST_CONN_FROM_RTC, + LabelType::WAIT_WIFI_CONNECT, + LabelType::HIDDEN_SSID_SLOW_CONNECT, + LabelType::CONNECT_HIDDEN_SSID, + LabelType::SDK_WIFI_AUTORECONNECT, + + LabelType::MAX_LABEL + }; + + addRowLabelValues(labels); } #endif @@ -526,25 +553,32 @@ void handle_sysinfo_Firmware() { void handle_sysinfo_SystemStatus() { addTableSeparator(F("System Status"), 2, 3); - // Actual Loglevel - addRowLabelValue(LabelType::SYSLOG_LOG_LEVEL); - addRowLabelValue(LabelType::SERIAL_LOG_LEVEL); - addRowLabelValue(LabelType::WEB_LOG_LEVEL); - # if FEATURE_SD - addRowLabelValue(LabelType::SD_LOG_LEVEL); - # endif // if FEATURE_SD - - addRowLabelValue(LabelType::ENABLE_SERIAL_PORT_CONSOLE); - addRowLabelValue(LabelType::CONSOLE_SERIAL_PORT); + static const LabelType::Enum labels[] PROGMEM = + { + // Actual Loglevel + LabelType::SYSLOG_LOG_LEVEL, + LabelType::SERIAL_LOG_LEVEL, + LabelType::WEB_LOG_LEVEL, +# if FEATURE_SD + LabelType::SD_LOG_LEVEL, +# endif // if FEATURE_SD + + LabelType::ENABLE_SERIAL_PORT_CONSOLE, + LabelType::CONSOLE_SERIAL_PORT, #if USES_ESPEASY_CONSOLE_FALLBACK_PORT - addRowLabelValue(LabelType::CONSOLE_FALLBACK_TO_SERIAL0); - addRowLabelValue(LabelType::CONSOLE_FALLBACK_PORT); + LabelType::CONSOLE_FALLBACK_TO_SERIAL0, + LabelType::CONSOLE_FALLBACK_PORT, #endif + LabelType::MAX_LABEL + }; + addRowLabelValues(labels); +#if FEATURE_CLEAR_I2C_STUCK if (Settings.EnableClearHangingI2Cbus()) { addRowLabelValue(LabelType::I2C_BUS_STATE); addRowLabelValue(LabelType::I2C_BUS_CLEARED_COUNT); } +#endif } #endif diff --git a/static/espeasy.js b/static/espeasy.js index 0484333552..86bcbafd72 100644 --- a/static/espeasy.js +++ b/static/espeasy.js @@ -104,6 +104,8 @@ var commonPlugins = [ "dac", "dac,1", "dac,2", //P153 "sht4x", "sht4x,startup", + //P159 + "ld2410", "ld2410,factoryreset", "ld2410,logall", ]; var pluginDispKind = [ //P095 diff --git a/static/espeasy.min.js b/static/espeasy.min.js index b625acaf21..04ce088c40 100644 --- a/static/espeasy.min.js +++ b/static/espeasy.min.js @@ -1 +1 @@ -var rEdit,commonAtoms=["And","Or"],commonKeywords=["If","Else","Elseif","Endif"],commonCommands=["AccessInfo","Background","Build","ClearAccessBlock","ClearRTCam","Config","ControllerDisable","ControllerEnable","DateTime","Debug","Dec","DeepSleep","DisablePriorityTask","DNS","DST","EraseSDKWiFi","ExecuteRules","Gateway","I2Cscanner","Inc","IP","Let","Load","LogEntry","LogPortStatus","LoopTimerSet","LoopTimerSet_ms","MemInfo","MemInfoDetail","Name","Password","PostToHTTP","Publish","Reboot","Reset","Save","SendTo","SendToHTTP","SendToUDP","Settings","Subnet","Subscribe","TaskClear","TaskClearAll","TaskDisable","TaskEnable","TaskRun","TaskValueSet","TaskValueSetAndRun","TimerPause","TimerResume","TimerSet","TimerSet_ms","TimeZone","UdpPort","UdpTest","Unit","UseNTP","WdConfig","WdRead","WiFi","WiFiAPkey","WiFiAllowAP","WiFiAPMode","WiFiConnect","WiFiDisconnect","WiFiKey","WiFiKey2","WiFiScan","WiFiSSID","WiFiSSID2","WiFiSTAMode","WiFi#Disconnected","Event","AsyncEvent","GPIO","GPIOToggle","LongPulse","LongPulse_mS","Monitor","Pulse","PWM","Servo","Status","Tone","RTTTL","UnMonitor",],commonString2=["Clock#Time","Login#Failed","MQTT#Connected","MQTT#Disconnected","MQTTimport#Connected","MQTTimport#Disconnected","Rules#Timer","System#Boot","System#BootMode","System#Sleep","System#Wake","TaskExit#","TaskInit#","Time#Initialized","Time#Set","WiFi#APmodeDisabled","WiFi#APmodeEnabled","WiFi#ChangedAccesspoint","WiFi#ChangedWiFichannel","WiFi#Connected"],commonPlugins=["ResetPulseCounter","SetPulseCounterTotal","LogPulseStatistic","analogout","MCPGPIO","MCPGPIOToggle","MCPLongPulse","MCPLongPulse_ms","MCPPulse","Status,MCP","Monitor,MCP","MonitorRange,MCP","UnMonitorRange,MCP","UnMonitor,MCP","MCPGPIORange","MCPGPIOPattern","MCPMode","MCPModeRange","LCDCmd","LCD","PCFGPIO","PCFGPIOToggle","PCFLongPulse","PCFLongPulse_ms","PCFPulse","Status,PCF","Monitor,PCF","MonitorRange,PCF","UnMonitorRange,PCF","UnMonitor,PCF","PCFGPIORange","PCFGPIOpattern","PCFMode","PCFmodeRange","pcapwm","pcafrq","mode2","OLED","OLEDCMD","OLEDCMD,on","OLEDCMD,off","OLEDCMD,clear","IRSEND","IRSENDAC","OledFramedCmd","OledFramedCmd,Display","OledFramedCmd,low","OledFramedCmd,med","OledFramedCmd,high","OledFramedCmd,Frame","OledFramedCmd,linecount","OledFramedCmd,leftalign","OledFramedCmd,align","OledFramedCmd,userDef1","OledFramedCmd,userDef2","NeoPixel","NeoPixelAll","NeoPixelLine","NeoPixelHSV","NeoPixelAllHSV","NeoPixelLineHSV","NeoPixelBright","MotorShieldCmd,DCMotor","MotorShieldCmd,Stepper","Sensair_SetRelay","PMSX003","PMSX003,Wake","PMSX003,Sleep","PMSX003,Reset","encwrite","Play","Vol","Eq","Mode","Repeat","tareChanA","tareChanB","7dn","7dst","7dsd","7dtext","7ddt","7dt","7dtfont","7dtbin","7don","7doff","7output","HLWCalibrate","HLWReset","WemosMotorShieldCMD","LolinMotorShieldCMD","GPS","GPS,Sleep","GPS,Wake","GPS#GotFix","GPS#LostFix","GPS#Travelled","homieValueSet","HeatPumpir","MitsubishiHP","MitsubishiHP,temperature","MitsubishiHP,power","MitsubishiHP,mode","MitsubishiHP,fan","MitsubishiHP,vane","MitsubishiHP,widevane","Culreader_Write","Touch","Touch,Rot","Touch,Flip","Touch,Enable","Touch,Disable","Touch,On","Touch,Off","Touch,Toggle","Touch,Setgrp","Touch,Incgrp","Touch,Decgrp","Touch,Incpage","Touch,Decpage","Touch,Updatebutton","WakeOnLan","DotMatrix","DotMatrix,clear","DotMatrix,update","DotMatrix,size","DotMatrix,txt","DotMatrix,settxt","DotMatrix,content","DotMatrix,alignment","DotMatrix,anim.in","DotMatrix,anim.out","DotMatrix,speed","DotMatrix,pause","DotMatrix,font","DotMatrix,layout","DotMatrix,inverted","DotMatrix,specialeffect","DotMatrix,offset","DotMatrix,brightness","DotMatrix,repeat","DotMatrix,setbar","DotMatrix,bar","Thermo","Thermo,Up","Thermo,Down","Thermo,Mode","Thermo,ModeBtn","Thermo,Setpoint","Max1704xclearalert","scdgetabc","scdgetalt","scdgettmp","scdsetcalibration","scdsetfrc","scdgetinterval","multirelay","multirelay,on","multirelay,off","multirelay,set","multirelay,get","multirelay,loop","ShiftOut","ShiftOut,Set","ShiftOut,SetNoUpdate","ShiftOut,Update","ShiftOut,SetAll","ShiftOut,SetAllNoUpdate","ShiftOut,SetAllLow","ShiftOut,SetAllHigh","ShiftOut,SetChipCount","ShiftOut,SetHexBin","cdmrst","nfx","nfx,off","nfx,on","nfx,dim","nfx,line,","nfx,hsvline,","nfx,one,","nfx,hsvone,","nfx,all,","nfx,rgb,","nfx,fade,","nfx,hsv,","nfx,colorfade,","nfx,rainbow","nfx,kitt,","nfx,comet,","nfx,theatre,","nfx,scan,","nfx,dualscan,","nfx,twinkle,","nfx,twinklefade,","nfx,sparkle,","nfx,wipe,","nfx,dualwipe","nfx,fire","nfx,fireflicker","nfx,faketv","nfx,simpleclock","nfx,stop","nfx,statusrequest","nfx,fadetime,","nfx,fadedelay,","nfx,speed,","nfx,count,","nfx,bgcolor","ShiftIn","ShiftIn,PinEvent","ShiftIn,ChipEvent","ShiftIn,SetChipCount","ShiftIn,SampleFrequency","ShiftIn,EventPerPin","scd4x","scd4x,storesettings","scd4x,facoryreset","scd4x,selftest","scd4x,setfrc,","axp","axp,ldo2","axp,ldo3","axp,ldoio","axp,gpio0","axp,gpio1","axp,gpio2","axp,gpio3","axp,gpio4","axp,dcdc2","axp,dcdc3","axp,ldo2map","axp,ldo3map","axp,ldoiomap","axp,dcdc2map","axp,dcdc3map","axp,ldo2perc","axp,ldo3perc","axp,ldoioperc","axp,dcdc2perc","axp,dcdc3perc","I2CEncoder","I2CEncoder,bright","I2CEncoder,led1","I2CEncoder,led2","I2CEncoder,gain","I2CEncoder,set","cachereader","cachereader,readpos","cachereader,sendtaskinfo","cachereader,flush","tm1621","tm1621,write,","tm1621,writerow,","tm1621,voltamp,","tm1621,energy,","tm1621,celcius,","tm1621,fahrenheit,","tm1621,humidity,","tm1621,raw,","dac","dac,1","dac,2","sht4x","sht4x,startup",],pluginDispKind=["tft","ili9341","ili9342","ili9481","ili9486","ili9488","eink","epaper","il3897","uc8151d","ssd1680","ws2in7","ws1in54","st77xx","st7735","st7789","st7796","neomatrix","neo","pcd8544",],pluginDispCmd=["cmd,on","cmd,off","cmd,clear","cmd,backlight","cmd,bright","cmd,deepsleep","cmd,seq_start","cmd,seq_end","cmd,inv","cmd,rot",",clear",",rot",",tpm",",txt",",txp",",txz",",txc",",txs",",txtfull",",asciitable",",font",",l",",lh",",lv",",lm",",lmr",",r",",rf",",c",",cf",",rf",",t",",tf",",rr",",rrf",",px",",pxh",",pxv",",bmp",",btn"],commonTag=["On","Do","Endon"],commonNumber=["toBin","toHex","Constrain","XOR","AND:","OR:","Ord","bitRead","bitSet","bitClear","bitWrite","urlencode"],commonMath=["Log","Ln","Abs","Exp","Sqrt","Sq","Round","Sin","Cos","Tan","aSin","aCos","aTan","Sin_d","Cos_d","Tan_d","aSin_d","aCos_d","aTan_d"],commonWarning=["delay","Delay","ResetFlashWriteCounter"],taskSpecifics=["settings.Enabled","settings.Interval","settings.ValueCount","settings.Controller1.Enabled","settings.Controller2.Enabled","settings.Controller3.Enabled","settings.Controller1.Idx","settings.Controller2.Idx","settings.Controller3.Idx"],AnythingElse=["%eventvalue%","%eventpar%","%eventname%","substring","%sysname%","%bootcause%","%systime%","%systm_hm%","%systm_hm_0%","%systm_hm_sp%","%systime_am%","%systime_am_0%","%systime_am_sp%","%systm_hm_am%","%systm_hm_am_0%","%systm_hm_am_sp%","%lcltime%","%sunrise%","%s_sunrise%","%m_sunrise%","%sunset%","%s_sunset%","%m_sunset%","%lcltime_am%","%syshour%","%syshour_0%","%sysmin%","%sysmin_0%","%syssec%","%syssec_0%","%sysday%","%sysday_0%","%sysmonth%","%sysmonth_0%","%sysyear%","%sysyear_0%","%sysyears%","%sysweekday%","%sysweekday_s%","%unixtime%","%uptime%","%uptime_ms%","%rssi%","%ip%","%unit%","%ssid%","%bssid%","%wi_ch%","%iswifi%","%vcc%","%mac%","%mac_int%","%isntp%","%ismqtt%","%dns%","%dns1%","%dns2%","%flash_freq%","%flash_size%","%flash_chip_vendor%","%flash_chip_model%","%fs_free%","%fs_size%","%cpu_id%","%cpu_freq%","%cpu_model%","%cpu_rev%","%cpu_cores%","%board_name%","%c_w_dir%","%c_c2f%","%c_ms2Bft%","%c_dew_th%","%c_alt_pres_sea%","%c_sea_pres_alt%","%c_cm2imp%","%c_mm2imp%","%c_m2day%","%c_m2dh%","%c_m2dhm%","%c_s2dhms%","%c_2hex%","%c_u2ip%","var","int"];for(const element2 of pluginDispKind)commonPlugins=commonPlugins.concat(element2);for(const element2 of pluginDispKind)for(const element3 of pluginDispCmd){let e=element2+element3;commonPlugins=commonPlugins.concat(e)}var EXTRAWORDS=commonAtoms.concat(commonPlugins,commonKeywords,commonCommands,commonString2,commonTag,commonNumber,commonMath,commonWarning,taskSpecifics,AnythingElse);function initCM(){CodeMirror.commands.autocomplete=function(e){e.showHint({hint:CodeMirror.hint.anyword})},(rEdit=CodeMirror.fromTextArea(document.getElementById("rules"),{tabSize:2,indentWithTabs:!1,lineNumbers:!0,autoCloseBrackets:!0,extraKeys:{"Ctrl-Space":"autocomplete",Tab(e){"null"===e.getMode().name?e.execCommand("insertTab"):e.somethingSelected()?e.execCommand("indentMore"):e.execCommand("insertSoftTab")},"Shift-Tab":e=>e.execCommand("indentLess")}})).on("change",function(){rEdit.save()}),rEdit.on("inputRead",function(e,t){var n=e.getCursor(),o=e.getTokenAt(n);/[\w%,.]/.test(t.text)&&"comment"!=o.type&&e.showHint({completeSingle:!1})})}!function(e){"object"==typeof exports&&"object"==typeof module?e(require("codemirror")):"function"==typeof define&&define.amd?define(["codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("espeasy",function(){var e={};function t(t,n){for(var o=0;oe.toLowerCase());commonCommands=commonCommands.concat(n);var o=commonString2.map(e=>e.toLowerCase());commonString2=commonString2.concat(o);var i=commonPlugins.map(e=>e.toLowerCase());commonPlugins=commonPlugins.concat(i);var a=commonAtoms.map(e=>e.toLowerCase());commonAtoms=commonAtoms.concat(a);var r=commonKeywords.map(e=>e.toLowerCase());commonKeywords=commonKeywords.concat(r);var s=commonTag.map(e=>e.toLowerCase());commonTag=commonTag.concat(s);var c=commonNumber.map(e=>e.toLowerCase());commonNumber=commonNumber.concat(c);var m=commonMath.map(e=>e.toLowerCase());commonMath=commonMath.concat(m);var l=AnythingElse.map(e=>e.toLowerCase());AnythingElse=AnythingElse.concat(l);var d=taskSpecifics.map(e=>e.toLowerCase());function u(t,n){if(t.eatSpace())return null;t.sol();var o=t.next();if(/\d/.test(o)){if("0"==o)return"x"===t.next()?(t.eatWhile(/\w/),"number"):(t.eatWhile(/\d|\./),"number");if(t.eatWhile(/\d|\./),!t.match("d")&&!t.match("output")&&(t.eol()||/\D/.test(t.peek())))return"number"}if(/\w/.test(o))for(let i of EXTRAWORDS){let a=i.substring(1);(i.includes(":")||i.includes(",")||i.includes("."))&&t.match(a)}if(/\w/.test(o)&&(t.eatWhile(/[\w]/),t.match(".gpio")||t.match(".pulse")||t.match(".frq")||t.match(".pwm")))return"def";if("\\"===o)return t.next(),null;if("("===o||")"===o)return"bracket";if("{"===o||"}"===o||":"===o)return"number";if("/"==o)return/\//.test(t.peek())?(t.skipToEnd(),"comment"):"operator";if("'"==o&&(t.eatWhile(/[^']/),t.match("'")))return"attribute";if("+"===o||"="===o||"<"===o||">"===o||"-"===o||","===o||"*"===o||"!"===o)return"operator";if("%"==o){if(/\d/.test(t.next()))return"number";if(t.eatWhile(/[^\s\%]/),t.match("%"))return"hr"}if("["==o&&(t.eatWhile(/[^\s\]]/),t.eat("]")))return"hr";t.eatWhile(/\w/);var r=t.current();return/\w/.test(o)&&t.match("#")?(t.eatWhile(/[\w.#]/),"string-2"):"#"===o?(t.eatWhile(/\w/),"number"):e.hasOwnProperty(r)?e[r]:null}return taskSpecifics=taskSpecifics.concat(d),t("atom",commonAtoms),t("keyword",commonKeywords),t("builtin",commonCommands),t("string-2",commonString2),t("def",commonPlugins),t("tag",commonTag),t("number",commonNumber),t("bracket",commonMath),t("warning",commonWarning),t("hr",AnythingElse),t("comment",taskSpecifics),{startState:function(){return{tokens:[]}},token:function(e,t){var n,o;return n=e,((o=t).tokens[0]||u)(n,o)},closeBrackets:"[]{}''\"\"``()",lineComment:"//",fold:"brace"}})}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):e(CodeMirror)}(function(e){var t={pairs:"()[]{}''\"\"",closeBefore:")]}'\":;>",triples:"",explode:"[]{}"},n=e.Pos;function o(e,n){return"pairs"==n&&"string"==typeof e?e:"object"==typeof e&&null!=e[n]?e[n]:t[n]}e.defineOption("autoCloseBrackets",!1,function(t,n,r){r&&r!=e.Init&&(t.removeKeyMap(i),t.state.closeBrackets=null),n&&(a(o(n,"pairs")),t.state.closeBrackets=n,t.addKeyMap(i))});var i={Backspace:function t(i){var a=s(i);if(!a||i.getOption("disableInput"))return e.Pass;for(var r=o(a,"pairs"),c=i.listSelections(),m=0;m=0;m--){var u=c[m].head;i.replaceRange("",n(u.line,u.ch-1),n(u.line,u.ch+1),"+delete")}},Enter:function t(n){var i=s(n),a=i&&o(i,"explode");if(!a||n.getOption("disableInput"))return e.Pass;for(var r=n.listSelections(),m=0;m=0&&i.getRange(y,n(y.line,y.ch+3))==a+a+a?"skipThree":"skip";else if(h&&y.ch>1&&p.indexOf(a)>=0&&i.getRange(n(y.line,y.ch-2),y)==a+a){if(y.ch>2&&/\bstring/.test(i.getTokenTypeAt(n(y.line,y.ch-2))))return e.Pass;P="addFour"}else if(h){var b=0==y.ch?" ":i.getRange(n(y.line,y.ch-1),y);if(e.isWordChar(M)||b==a||e.isWordChar(b))return e.Pass;P="both"}else{if(!(x&&(0===M.length||/\s/.test(M)||f.indexOf(M)>-1)))return e.Pass;P="both"}if(C){if(C!=P)return e.Pass}else C=P}var v=u%2?l.charAt(u-1):a,D=u%2?a:l.charAt(u+1);i.operation(function(){if("skip"==C)c(i,1);else if("skipThree"==C)c(i,3);else if("surround"==C){for(var e=i.getSelections(),t=0;t0?{line:r.head.line,ch:r.head.ch+t}:{line:r.head.line-1};n.push({anchor:s,head:s})}e.setSelections(n,i)}function m(t){var o=e.cmpPos(t.anchor,t.head)>0;return{anchor:new n(t.anchor.line,t.anchor.ch+(o?-1:1)),head:new n(t.head.line,t.head.ch+(o?1:-1))}}function l(e,t){var o=e.getRange(n(t.line,t.ch-1),n(t.line,t.ch+1));return 2==o.length?o:null}function d(e,t){var o=e.getTokenAt(n(t.line,t.ch+1));return/\bstring/.test(o.type)&&o.start==t.ch&&(0==t.ch||!/\bstring/.test(e.getTokenTypeAt(t)))}a(t.pairs+"`")}); \ No newline at end of file +var rEdit,commonAtoms=["And","Or"],commonKeywords=["If","Else","Elseif","Endif"],commonCommands=["AccessInfo","Background","Build","ClearAccessBlock","ClearRTCam","Config","ControllerDisable","ControllerEnable","DateTime","Debug","Dec","DeepSleep","DisablePriorityTask","DNS","DST","EraseSDKWiFi","ExecuteRules","Gateway","I2Cscanner","Inc","IP","Let","Load","LogEntry","LogPortStatus","LoopTimerSet","LoopTimerSet_ms","MemInfo","MemInfoDetail","Name","Password","PostToHTTP","Publish","Reboot","Reset","Save","SendTo","SendToHTTP","SendToUDP","Settings","Subnet","Subscribe","TaskClear","TaskClearAll","TaskDisable","TaskEnable","TaskRun","TaskValueSet","TaskValueSetAndRun","TimerPause","TimerResume","TimerSet","TimerSet_ms","TimeZone","UdpPort","UdpTest","Unit","UseNTP","WdConfig","WdRead","WiFi","WiFiAPkey","WiFiAllowAP","WiFiAPMode","WiFiConnect","WiFiDisconnect","WiFiKey","WiFiKey2","WiFiScan","WiFiSSID","WiFiSSID2","WiFiSTAMode","WiFi#Disconnected","Event","AsyncEvent","GPIO","GPIOToggle","LongPulse","LongPulse_mS","Monitor","Pulse","PWM","Servo","Status","Tone","RTTTL","UnMonitor",],commonString2=["Clock#Time","Login#Failed","MQTT#Connected","MQTT#Disconnected","MQTTimport#Connected","MQTTimport#Disconnected","Rules#Timer","System#Boot","System#BootMode","System#Sleep","System#Wake","TaskExit#","TaskInit#","Time#Initialized","Time#Set","WiFi#APmodeDisabled","WiFi#APmodeEnabled","WiFi#ChangedAccesspoint","WiFi#ChangedWiFichannel","WiFi#Connected"],commonPlugins=["ResetPulseCounter","SetPulseCounterTotal","LogPulseStatistic","analogout","MCPGPIO","MCPGPIOToggle","MCPLongPulse","MCPLongPulse_ms","MCPPulse","Status,MCP","Monitor,MCP","MonitorRange,MCP","UnMonitorRange,MCP","UnMonitor,MCP","MCPGPIORange","MCPGPIOPattern","MCPMode","MCPModeRange","LCDCmd","LCD","PCFGPIO","PCFGPIOToggle","PCFLongPulse","PCFLongPulse_ms","PCFPulse","Status,PCF","Monitor,PCF","MonitorRange,PCF","UnMonitorRange,PCF","UnMonitor,PCF","PCFGPIORange","PCFGPIOpattern","PCFMode","PCFmodeRange","pcapwm","pcafrq","mode2","OLED","OLEDCMD","OLEDCMD,on","OLEDCMD,off","OLEDCMD,clear","IRSEND","IRSENDAC","OledFramedCmd","OledFramedCmd,Display","OledFramedCmd,low","OledFramedCmd,med","OledFramedCmd,high","OledFramedCmd,Frame","OledFramedCmd,linecount","OledFramedCmd,leftalign","OledFramedCmd,align","OledFramedCmd,userDef1","OledFramedCmd,userDef2","NeoPixel","NeoPixelAll","NeoPixelLine","NeoPixelHSV","NeoPixelAllHSV","NeoPixelLineHSV","NeoPixelBright","MotorShieldCmd,DCMotor","MotorShieldCmd,Stepper","Sensair_SetRelay","PMSX003","PMSX003,Wake","PMSX003,Sleep","PMSX003,Reset","encwrite","Play","Vol","Eq","Mode","Repeat","tareChanA","tareChanB","7dn","7dst","7dsd","7dtext","7ddt","7dt","7dtfont","7dtbin","7don","7doff","7output","HLWCalibrate","HLWReset","WemosMotorShieldCMD","LolinMotorShieldCMD","GPS","GPS,Sleep","GPS,Wake","GPS#GotFix","GPS#LostFix","GPS#Travelled","homieValueSet","HeatPumpir","MitsubishiHP","MitsubishiHP,temperature","MitsubishiHP,power","MitsubishiHP,mode","MitsubishiHP,fan","MitsubishiHP,vane","MitsubishiHP,widevane","Culreader_Write","Touch","Touch,Rot","Touch,Flip","Touch,Enable","Touch,Disable","Touch,On","Touch,Off","Touch,Toggle","Touch,Setgrp","Touch,Incgrp","Touch,Decgrp","Touch,Incpage","Touch,Decpage","Touch,Updatebutton","WakeOnLan","DotMatrix","DotMatrix,clear","DotMatrix,update","DotMatrix,size","DotMatrix,txt","DotMatrix,settxt","DotMatrix,content","DotMatrix,alignment","DotMatrix,anim.in","DotMatrix,anim.out","DotMatrix,speed","DotMatrix,pause","DotMatrix,font","DotMatrix,layout","DotMatrix,inverted","DotMatrix,specialeffect","DotMatrix,offset","DotMatrix,brightness","DotMatrix,repeat","DotMatrix,setbar","DotMatrix,bar","Thermo","Thermo,Up","Thermo,Down","Thermo,Mode","Thermo,ModeBtn","Thermo,Setpoint","Max1704xclearalert","scdgetabc","scdgetalt","scdgettmp","scdsetcalibration","scdsetfrc","scdgetinterval","multirelay","multirelay,on","multirelay,off","multirelay,set","multirelay,get","multirelay,loop","ShiftOut","ShiftOut,Set","ShiftOut,SetNoUpdate","ShiftOut,Update","ShiftOut,SetAll","ShiftOut,SetAllNoUpdate","ShiftOut,SetAllLow","ShiftOut,SetAllHigh","ShiftOut,SetChipCount","ShiftOut,SetHexBin","cdmrst","nfx","nfx,off","nfx,on","nfx,dim","nfx,line,","nfx,hsvline,","nfx,one,","nfx,hsvone,","nfx,all,","nfx,rgb,","nfx,fade,","nfx,hsv,","nfx,colorfade,","nfx,rainbow","nfx,kitt,","nfx,comet,","nfx,theatre,","nfx,scan,","nfx,dualscan,","nfx,twinkle,","nfx,twinklefade,","nfx,sparkle,","nfx,wipe,","nfx,dualwipe","nfx,fire","nfx,fireflicker","nfx,faketv","nfx,simpleclock","nfx,stop","nfx,statusrequest","nfx,fadetime,","nfx,fadedelay,","nfx,speed,","nfx,count,","nfx,bgcolor","ShiftIn","ShiftIn,PinEvent","ShiftIn,ChipEvent","ShiftIn,SetChipCount","ShiftIn,SampleFrequency","ShiftIn,EventPerPin","scd4x","scd4x,storesettings","scd4x,facoryreset","scd4x,selftest","scd4x,setfrc,","axp","axp,ldo2","axp,ldo3","axp,ldoio","axp,gpio0","axp,gpio1","axp,gpio2","axp,gpio3","axp,gpio4","axp,dcdc2","axp,dcdc3","axp,ldo2map","axp,ldo3map","axp,ldoiomap","axp,dcdc2map","axp,dcdc3map","axp,ldo2perc","axp,ldo3perc","axp,ldoioperc","axp,dcdc2perc","axp,dcdc3perc","I2CEncoder","I2CEncoder,bright","I2CEncoder,led1","I2CEncoder,led2","I2CEncoder,gain","I2CEncoder,set","cachereader","cachereader,readpos","cachereader,sendtaskinfo","cachereader,flush","tm1621","tm1621,write,","tm1621,writerow,","tm1621,voltamp,","tm1621,energy,","tm1621,celcius,","tm1621,fahrenheit,","tm1621,humidity,","tm1621,raw,","dac","dac,1","dac,2","sht4x","sht4x,startup","ld2410","ld2410,factoryreset","ld2410,logall",],pluginDispKind=["tft","ili9341","ili9342","ili9481","ili9486","ili9488","eink","epaper","il3897","uc8151d","ssd1680","ws2in7","ws1in54","st77xx","st7735","st7789","st7796","neomatrix","neo","pcd8544",],pluginDispCmd=["cmd,on","cmd,off","cmd,clear","cmd,backlight","cmd,bright","cmd,deepsleep","cmd,seq_start","cmd,seq_end","cmd,inv","cmd,rot",",clear",",rot",",tpm",",txt",",txp",",txz",",txc",",txs",",txtfull",",asciitable",",font",",l",",lh",",lv",",lm",",lmr",",r",",rf",",c",",cf",",rf",",t",",tf",",rr",",rrf",",px",",pxh",",pxv",",bmp",",btn"],commonTag=["On","Do","Endon"],commonNumber=["toBin","toHex","Constrain","XOR","AND:","OR:","Ord","bitRead","bitSet","bitClear","bitWrite","urlencode"],commonMath=["Log","Ln","Abs","Exp","Sqrt","Sq","Round","Sin","Cos","Tan","aSin","aCos","aTan","Sin_d","Cos_d","Tan_d","aSin_d","aCos_d","aTan_d"],commonWarning=["delay","Delay","ResetFlashWriteCounter"],taskSpecifics=["settings.Enabled","settings.Interval","settings.ValueCount","settings.Controller1.Enabled","settings.Controller2.Enabled","settings.Controller3.Enabled","settings.Controller1.Idx","settings.Controller2.Idx","settings.Controller3.Idx"],AnythingElse=["%eventvalue%","%eventpar%","%eventname%","substring","%sysname%","%bootcause%","%systime%","%systm_hm%","%systm_hm_0%","%systm_hm_sp%","%systime_am%","%systime_am_0%","%systime_am_sp%","%systm_hm_am%","%systm_hm_am_0%","%systm_hm_am_sp%","%lcltime%","%sunrise%","%s_sunrise%","%m_sunrise%","%sunset%","%s_sunset%","%m_sunset%","%lcltime_am%","%syshour%","%syshour_0%","%sysmin%","%sysmin_0%","%syssec%","%syssec_0%","%sysday%","%sysday_0%","%sysmonth%","%sysmonth_0%","%sysyear%","%sysyear_0%","%sysyears%","%sysweekday%","%sysweekday_s%","%unixtime%","%uptime%","%uptime_ms%","%rssi%","%ip%","%unit%","%ssid%","%bssid%","%wi_ch%","%iswifi%","%vcc%","%mac%","%mac_int%","%isntp%","%ismqtt%","%dns%","%dns1%","%dns2%","%flash_freq%","%flash_size%","%flash_chip_vendor%","%flash_chip_model%","%fs_free%","%fs_size%","%cpu_id%","%cpu_freq%","%cpu_model%","%cpu_rev%","%cpu_cores%","%board_name%","%c_w_dir%","%c_c2f%","%c_ms2Bft%","%c_dew_th%","%c_alt_pres_sea%","%c_sea_pres_alt%","%c_cm2imp%","%c_mm2imp%","%c_m2day%","%c_m2dh%","%c_m2dhm%","%c_s2dhms%","%c_2hex%","%c_u2ip%","var","int"];for(const element2 of pluginDispKind)commonPlugins=commonPlugins.concat(element2);for(const element2 of pluginDispKind)for(const element3 of pluginDispCmd){let e=element2+element3;commonPlugins=commonPlugins.concat(e)}var EXTRAWORDS=commonAtoms.concat(commonPlugins,commonKeywords,commonCommands,commonString2,commonTag,commonNumber,commonMath,commonWarning,taskSpecifics,AnythingElse);function initCM(){CodeMirror.commands.autocomplete=function(e){e.showHint({hint:CodeMirror.hint.anyword})},(rEdit=CodeMirror.fromTextArea(document.getElementById("rules"),{tabSize:2,indentWithTabs:!1,lineNumbers:!0,autoCloseBrackets:!0,extraKeys:{"Ctrl-Space":"autocomplete",Tab(e){"null"===e.getMode().name?e.execCommand("insertTab"):e.somethingSelected()?e.execCommand("indentMore"):e.execCommand("insertSoftTab")},"Shift-Tab":e=>e.execCommand("indentLess")}})).on("change",function(){rEdit.save()}),rEdit.on("inputRead",function(e,t){var n=e.getCursor(),o=e.getTokenAt(n);/[\w%,.]/.test(t.text)&&"comment"!=o.type&&e.showHint({completeSingle:!1})})}!function(e){"object"==typeof exports&&"object"==typeof module?e(require("codemirror")):"function"==typeof define&&define.amd?define(["codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("espeasy",function(){var e={};function t(t,n){for(var o=0;oe.toLowerCase());commonCommands=commonCommands.concat(n);var o=commonString2.map(e=>e.toLowerCase());commonString2=commonString2.concat(o);var i=commonPlugins.map(e=>e.toLowerCase());commonPlugins=commonPlugins.concat(i);var a=commonAtoms.map(e=>e.toLowerCase());commonAtoms=commonAtoms.concat(a);var r=commonKeywords.map(e=>e.toLowerCase());commonKeywords=commonKeywords.concat(r);var s=commonTag.map(e=>e.toLowerCase());commonTag=commonTag.concat(s);var c=commonNumber.map(e=>e.toLowerCase());commonNumber=commonNumber.concat(c);var l=commonMath.map(e=>e.toLowerCase());commonMath=commonMath.concat(l);var m=AnythingElse.map(e=>e.toLowerCase());AnythingElse=AnythingElse.concat(m);var d=taskSpecifics.map(e=>e.toLowerCase());function u(t,n){if(t.eatSpace())return null;t.sol();var o=t.next();if(/\d/.test(o)){if("0"==o)return"x"===t.next()?(t.eatWhile(/\w/),"number"):(t.eatWhile(/\d|\./),"number");if(t.eatWhile(/\d|\./),!t.match("d")&&!t.match("output")&&(t.eol()||/\D/.test(t.peek())))return"number"}if(/\w/.test(o))for(let i of EXTRAWORDS){let a=i.substring(1);(i.includes(":")||i.includes(",")||i.includes("."))&&t.match(a)}if(/\w/.test(o)&&(t.eatWhile(/[\w]/),t.match(".gpio")||t.match(".pulse")||t.match(".frq")||t.match(".pwm")))return"def";if("\\"===o)return t.next(),null;if("("===o||")"===o)return"bracket";if("{"===o||"}"===o||":"===o)return"number";if("/"==o)return/\//.test(t.peek())?(t.skipToEnd(),"comment"):"operator";if("'"==o&&(t.eatWhile(/[^']/),t.match("'")))return"attribute";if("+"===o||"="===o||"<"===o||">"===o||"-"===o||","===o||"*"===o||"!"===o)return"operator";if("%"==o){if(/\d/.test(t.next()))return"number";if(t.eatWhile(/[^\s\%]/),t.match("%"))return"hr"}if("["==o&&(t.eatWhile(/[^\s\]]/),t.eat("]")))return"hr";t.eatWhile(/\w/);var r=t.current();return/\w/.test(o)&&t.match("#")?(t.eatWhile(/[\w.#]/),"string-2"):"#"===o?(t.eatWhile(/\w/),"number"):e.hasOwnProperty(r)?e[r]:null}return taskSpecifics=taskSpecifics.concat(d),t("atom",commonAtoms),t("keyword",commonKeywords),t("builtin",commonCommands),t("string-2",commonString2),t("def",commonPlugins),t("tag",commonTag),t("number",commonNumber),t("bracket",commonMath),t("warning",commonWarning),t("hr",AnythingElse),t("comment",taskSpecifics),{startState:function(){return{tokens:[]}},token:function(e,t){var n,o;return n=e,((o=t).tokens[0]||u)(n,o)},closeBrackets:"[]{}''\"\"``()",lineComment:"//",fold:"brace"}})}),function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):e(CodeMirror)}(function(e){var t={pairs:"()[]{}''\"\"",closeBefore:")]}'\":;>",triples:"",explode:"[]{}"},n=e.Pos;function o(e,n){return"pairs"==n&&"string"==typeof e?e:"object"==typeof e&&null!=e[n]?e[n]:t[n]}e.defineOption("autoCloseBrackets",!1,function(t,n,r){r&&r!=e.Init&&(t.removeKeyMap(i),t.state.closeBrackets=null),n&&(a(o(n,"pairs")),t.state.closeBrackets=n,t.addKeyMap(i))});var i={Backspace:function t(i){var a=s(i);if(!a||i.getOption("disableInput"))return e.Pass;for(var r=o(a,"pairs"),c=i.listSelections(),l=0;l=0;l--){var u=c[l].head;i.replaceRange("",n(u.line,u.ch-1),n(u.line,u.ch+1),"+delete")}},Enter:function t(n){var i=s(n),a=i&&o(i,"explode");if(!a||n.getOption("disableInput"))return e.Pass;for(var r=n.listSelections(),l=0;l=0&&i.getRange(y,n(y.line,y.ch+3))==a+a+a?"skipThree":"skip";else if(h&&y.ch>1&&p.indexOf(a)>=0&&i.getRange(n(y.line,y.ch-2),y)==a+a){if(y.ch>2&&/\bstring/.test(i.getTokenTypeAt(n(y.line,y.ch-2))))return e.Pass;P="addFour"}else if(h){var b=0==y.ch?" ":i.getRange(n(y.line,y.ch-1),y);if(e.isWordChar(M)||b==a||e.isWordChar(b))return e.Pass;P="both"}else{if(!(x&&(0===M.length||/\s/.test(M)||f.indexOf(M)>-1)))return e.Pass;P="both"}if(C){if(C!=P)return e.Pass}else C=P}var v=u%2?m.charAt(u-1):a,D=u%2?a:m.charAt(u+1);i.operation(function(){if("skip"==C)c(i,1);else if("skipThree"==C)c(i,3);else if("surround"==C){for(var e=i.getSelections(),t=0;t0?{line:r.head.line,ch:r.head.ch+t}:{line:r.head.line-1};n.push({anchor:s,head:s})}e.setSelections(n,i)}function l(t){var o=e.cmpPos(t.anchor,t.head)>0;return{anchor:new n(t.anchor.line,t.anchor.ch+(o?-1:1)),head:new n(t.head.line,t.head.ch+(o?1:-1))}}function m(e,t){var o=e.getRange(n(t.line,t.ch-1),n(t.line,t.ch+1));return 2==o.length?o:null}function d(e,t){var o=e.getTokenAt(n(t.line,t.ch+1));return/\bstring/.test(o.type)&&o.start==t.ch&&(0==t.ch||!/\bstring/.test(e.getTokenTypeAt(t)))}a(t.pairs+"`")}); \ No newline at end of file diff --git a/tools/pio/generate-compiletime-defines.py b/tools/pio/generate-compiletime-defines.py index 367430683f..f98dc961e6 100644 --- a/tools/pio/generate-compiletime-defines.py +++ b/tools/pio/generate-compiletime-defines.py @@ -57,14 +57,15 @@ def get_cdn_url_prefix(): tag = tags[0] # work-around to allow users to use files not yet available on a tagged version if '20220809' in tag: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/' tag = tag.replace('refs/tags/','@') return "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy{0}/static/".format(tag) except: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/' except ImportError: - return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy/static/' + return 'https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/' + def get_git_description(): @@ -144,4 +145,4 @@ def gen_compiletime_defines(node): print("\u001b[33m memory_type: \u001b[0m {}".format(env.BoardConfig().get("build.arduino.memory_type", "-"))) -env.AddBuildMiddleware(gen_compiletime_defines) \ No newline at end of file +env.AddBuildMiddleware(gen_compiletime_defines)
" D_STR_PROTOCOL "") + htmlSelectClimateProtocol(KEY_PROTOCOL, @@ -1066,6 +1165,9 @@ void handleAirCon(void) { "
" D_STR_MODEL "") + htmlSelectModel(KEY_MODEL, climate[chan]->next.model) + F("
" D_STR_COMMAND "") + + htmlSelectCommandType(KEY_COMMAND, climate[chan]->next.command) + + F("
" D_STR_POWER "") + htmlSelectBool(KEY_POWER, climate[chan]->next.power) + F("
" D_STR_SENSORTEMP "" + "") + + htmlDisableCheckbox(KEY_SENSORTEMP_DISABLED, KEY_SENSORTEMP, + noSensorTemp) + + F("
" D_STR_FAN "") + htmlSelectFanspeed(KEY_FANSPEED, climate[chan]->next.fanspeed) + F("
" D_STR_QUIET "") + htmlSelectBool(KEY_QUIET, climate[chan]->next.quiet) + F("
" D_STR_IFEEL "") + + htmlSelectBool(KEY_IFEEL, climate[chan]->next.iFeel) + + F("
" D_STR_TURBO "") + htmlSelectBool(KEY_TURBO, climate[chan]->next.turbo) + F("