In order to read servo signals, the library attaches an interrupt handler to an interrupt-capable pin that fires whenever the pin changes state. The library reads the rising/falling edges and calculates the time elapsed between the two to find the length of the servo pulses.
On some platforms, notably the Uno R4 (#28) and ESP32 (#19) the interrupt request (IRQ) table is not set up until the main() function is entered. The version 1 library idiom, following Arduino-y convention, is to declare ServoInputPin objects as globals. These objects call the interrupt handler during the constructor to apply the function hook. Because the request table is not setup until main(), these calls fail and the library will not work until the user tries to attach the interrupt themselves.
This PR removes this call to attach the interrupt in the constructor, and instead requires the user do it themselves before the library can begin parsing signals. This is a breaking change to the API, and necessitates a new major library version.
Because of that, I've taken the opportunity to make a few other breaking changes:
The library attachInterrupt() and detachInterrupt() functions have been refactored to simply attach() and detach(). This matches the syntax of the Servo library, and should fix issues with platforms that use macros instead of global functions for their interrupt handler (#27).
All boolean types have been refactored to simply bool, which is the proper C type
Since the user is now responsible for interrupt attachment/detachment, I've also added reference counting that will automatically detach the interrupt whenever no more class instances for a given pin exist.
In order to read servo signals, the library attaches an interrupt handler to an interrupt-capable pin that fires whenever the pin changes state. The library reads the rising/falling edges and calculates the time elapsed between the two to find the length of the servo pulses.
On some platforms, notably the Uno R4 (#28) and ESP32 (#19) the interrupt request (IRQ) table is not set up until the
main()
function is entered. The version 1 library idiom, following Arduino-y convention, is to declareServoInputPin
objects as globals. These objects call the interrupt handler during the constructor to apply the function hook. Because the request table is not setup untilmain()
, these calls fail and the library will not work until the user tries to attach the interrupt themselves.This PR removes this call to attach the interrupt in the constructor, and instead requires the user do it themselves before the library can begin parsing signals. This is a breaking change to the API, and necessitates a new major library version.
Because of that, I've taken the opportunity to make a few other breaking changes:
attachInterrupt()
anddetachInterrupt()
functions have been refactored to simplyattach()
anddetach()
. This matches the syntax of theServo
library, and should fix issues with platforms that use macros instead of global functions for their interrupt handler (#27).boolean
types have been refactored to simplybool
, which is the proper C typeSince the user is now responsible for interrupt attachment/detachment, I've also added reference counting that will automatically detach the interrupt whenever no more class instances for a given pin exist.