This time using customized interrupts to fill RMT memory on-the-fly.
* Added getChannel() to RFControl
* Add 3rd, optional, boolean argument to RFControl(int pin, bool refTick, bool defaultDrive) to that RMT can be initialized but without the default driver (allows for use of custom interrupt code instead)
Pixels now lets you reserve memory for pixels so that the call to start the RF transmission can be done for multiple pixels at once. However, gain is not as much as expected. May need to revisit if driving a large matrix of pixels is needed.
Reflects increase in max number of LWIP sockets from 10 (Arduino-ESP32 v2.0.0) to 16 (Arduino-ESP32 v2.0.1). Since HomeSpan needs at least 2 (one for Server and 1 free for new connections), this leaves 14 connections for controllers. A big improvement over only having 8!
Constructor now allows you to specify high/low timings for 1-bit and 0-bit, as well as timing for reset delay. Default parameters are included if none are specified.
Also add getPin() to RFControl (which is used by SK68XX Class) as well as boolean operator overrides for both RFControl and PwmPin/ServoPin so that instances can be checked for validity.
Optional method to automatically turn off Status LED after a *duration* seconds. LED will resume normal operation any time it is re-triggered with a new pattern. This also resets the elapsed time used to check for autoOff.
Added true/false parsing to all integer-based Characteristics. Previously true/false was only parsed for BOOL Characteristics. For integer-based on/off Characteristics, the Home App would send a 0 for off, and a 1 for on, consistent with HAP-R2. BUT...when using Home App AUTOMATIONS, the Home App would send true/false for integer-based Characteristics, which is inconsistent with HAP-R2. This meant automations worked with lights (that use the boolean ON Characteristic) but not with fans (that use the uint8 ACTIVE Characteristic).
With this "fix", true/false will be recognized all the time (except for float- and string-based Characteristics. Confirmed that fans now work with Home App Automations.
This allows you to add an optional "description" to a Characteristic. This is not the same as the name of a Service and is generally not used by the Home App. However, it appears to be consumed by the Eve app, which can be helpful in some circumstances when developing custom characteristics.
The update from Arduino-ESP32 2.0.0 to 2.0.1 contained significant changes to the structures used by the IDF for generic timers. This broke the Blinker code (would not compile for ESP32-S2 and C3 chips).
The solution: Modified Blinker::isrTimer() to use a *generic* interrupt-clearing function when available (IDF version >= 4.0.0). Below 4.0.0 the code continues to manually clear the interrupt flag by resetting specific structure variables, though the logic is simpler since this is only needed for the ESP32 chip (the S2 and C3 are not supported in earlier versions of Arduino-ESP32).
This provides for full compatibility with Arduino-ESP32 versions 2.0.1, 2.0.0, and 1.0.6. The use of a generic interrupt clearing function when IDF>=4.0.0 will hopefully make this future-proof to any further changes by Espressif to the underlying timer structures.
The loop over TimedWrites incorrectly erased iterators inside a for-loop. For some reason this never caused an issue on the ESP32, but crashed on the ESP32-C3. Solution is to change the for-loop to a while-loop with proper handling of the iterator when an element is deleted. This appears to fix the problem.
Characteristic::ConfiguredNameStatic() is no longer needed since you can now change permissions on ConfiguredStatic to remove PW with removePerms(PW). Updated Television Example accordingly.
To Do: Add getLinks() and setPerms/addPerms/removePerms to API Reference Documentation
This returns a vector of linked Services that can be used in a for-each loop as such:
for(auto services : getLinks()){ ... }
Must cast services into specific Service type to access anything not generic to the SpanService class
Second optional argument to setVal() determines whether or not HomeSpan sends notification of new value to HomeKit. Default if left blank is "true" for backwards compatibility.
And also converted ERRORS to WARNINGS when a Characteristic that is not in the REQ or OPT list is specified for a Service. This allows the user to add any Characteristic to any Service without forcing an Error (just a Warning).
Ranges are now checked for all Characteristics at the end of the configuration, instead of at the end of each Accessory definition. This is much cleaner and the output is easier to read.
To do: Revisit use of REQ and OPT - what should constitute a fatal error and what should be a warning.
To do: Revisit Character definitions - attempt to normalize using the methods implemented for Custom Characteristics
No need to specify both FORMAT and TYPE. For example, specifying UINT16 automatically sets type to be uint16_t.
To do: Explore if this can be used for standard Characteristics - revisit standard Characteristics definitions and structure to see if it can be simplified.
This "custom" Characteristic is identical to ConfiguredName() but only allows paired-read and notifications. By excluding paired-write it prevents the user from editing the name of a TV input source from the Home App. This is useful when some sources are fixed, such as "netflix" instead of generic, such as "hdmi 1".
Allows you to overlay a carrier wave on the RF Signal - in practice this is only used for IR signals (not RF). Automatically scales frequency to account for 80x difference between APB Clock and Ref Tick Clock depending on which is used. Checks to ensure resulting parameters (high period and low period) are all in bounds (0,65536) and reports an error if they are not.
Added second argument to RFControl(uint8_t pin, boolean refClock=true) to allow choice of Ref Tick (1 MHz) clock or APB (80 MHz) clock. Default is to use 1 MHz Ref Tick.
Also fixed bug in logic that divides clock for ESP32-C3. Factor should be 79, not 80, since divider is apparently configured to divide by factor+1.
Instead of limiting number of ticks to 15-bits (32767), RFControl allows for tick size to be any 32-bit number. If ticks > 32767, RFControl adds repeated LOW or HIGH phases as needed to match full duration. This provides for much more flexibility in creating pulse trains that include very long-duration "spaces" between repeats.
This will cause a Warning (not an Error) at compile time indicating the class has been deprecated and that the Characteristic::setRange() method should be used instead. Sketch will still run and SpanRange will still function correctly if used. Will delete from code base at some point in the future.
Re-worked code to allow for NO Status LED Pin and NO Control Pin. If Control Pin is not set explicitly with homeSpan.setControlPin(), there will be no Control Pin. There is no longer a default since there are too many board variations with S2 and C3 chips now supported. Same for Status Pin - it will not be defined unless set explicitly with homeSpan.setStatusPin(), with the exception that if LED_BUILTIN is defined (i.e. there is a built-in LED), then the Status LED Pin will default to LED_BUILTIN if not explicitly defined. MUST UPDATE DOCUMENTATION - THIS CHANGES DEFAULT BEHAVIOR OF HOMESPAN AND MAY REQUIRE UPDATES TO EXISTING SKETCHES
moved gpio_set_direction to start() method so that it is called every time needed in case another part of the program (i.e. DEV_Identify) calls pinMode() and resets the pin to a strict OUTPUT.
Testing completed for RFControl and PWM on all three ESP32 chip types.
To Do: update RFControl documentation to include total number of usable channels per chip, as well as the alternate version of start();
PWM has now been fully tested and verified with an ESP32 device under Arduino-ESP32 versions 1.0.6 and 2.0.0, and with an ESP32-S2 device under Arduino-ESP32 version 2.0.0. Tests confirmed using both high (5000 Hz) and low (1 Hz or 5Hz) frequencies to ensure timers are correctly configured.
Next Task: Update RFControl routines for 2.0.0 and ESP32-S2 compatibility.
Accounts for new *required* elements of the LEDC channel and timer structures to be set in later versions of the IDF. These elements are not available in earlier versions of the IDF and the program can't be compiled unless ignored.
Arduino-ESP32 has modified the Mbed TLS library so that it uses ESP32 hardware acceleration. However, there is a 512-byte limit to the size of the variables used in an exponential modulo calculation. One of the steps in the SRP code used a 768-byte variable, which cannot be handled in version 2.0.0 though it works fine in version 1.0.6. Solution was to simply reduce the 768-byte variable by modulo N prior to performing the exponential modulo calculation.
New IDF parameter in 2.0.0 for LEDC allows PWM signal to be inverted! Need to ensure flags.output_inverted is set to 0!
Also: Deleted old PWM class, which was saved for backwards compatibility. This "breaks" HomeSpan for those using the old PWM class (instead of LedPin).
Also: Added checks to ensure that frequency is achievable (for S2 and C3, the 14-bit duty resolution is insufficient to allow frequencies slower than 5 Hz - this is not a practical limit when using LedPin to drive actual LEDs and lights).
Should now work with ESP32-S2 and C3. Allows for as many LEDs and Servos as there are channels and timers across low and high (esp32 only) modes. Allows LED to be set with floating point precession instead of just uint8. Allows specification of LED frequency for each LED (1-65535 Hz). Automatically provides maximum duty resolution for frequency chosen.