#include <StateMachineEncoder.h>
Public Member Functions | |
| StateRotaryEncoderBuilder & | withEncoderPins (const pinid_t l_pinA, const pinid_t l_pinB) |
| StateRotaryEncoderBuilder & | withEncoderNum (const uint8_t l_encoderNum) |
| StateRotaryEncoderBuilder & | withPullUpInput (const bool l_needPullup) |
| StateRotaryEncoderBuilder & | withCallback (const EncoderCallbackFn l_callback) |
| StateRotaryEncoderBuilder & | withListener (EncoderListener *l_listener) |
| StateRotaryEncoderBuilder & | interruptOnSinglePin (const pinid_t l_interruptPin) |
| StateRotaryEncoderBuilder & | interruptOnBothPins () |
| StateRotaryEncoderBuilder & | interruptOnTimer () |
| StateRotaryEncoderBuilder & | withAccelerationMode (const HWAccelerationMode l_accelerationMode) |
| StateRotaryEncoderBuilder & | withEncoderType (const EncoderType l_encoderType) |
| bool | configurationValid () const |
| bool | build () const |
Builder class for configuring a state machine based rotary encoder with various options such as pins, callbacks, listeners, interrupt handling, acceleration modes, and encoder types. Note that unlike other IoAbstraction based rotary encoders, this encoder requires either a dedicated interrupt or a hardware timer to be used. The configuration will not be considered valid unless one of the interrupt/timer modes is set.
Interrupt modes that are supported:
If you define the timer mode, it is your responsibility to ensure that the timer is configured to generate interrupts at a rate that is appropriate for your application. For example, on ARM, SYS_TICK is configured to generate interrupts at a rate of 1ms. You could attach to this and it should be fast enough to catch 99.9% of movements.
|
inline |
Configure the A and B pins of the encoder.
| l_pinA | the A pin |
| l_pinB | the B pin |
|
inline |
IoAbstraction's Switches allows more than one rotary encoder, this defaults to 0 and for most will not need to be changed. Important note: this class can only provide one encoder, as it is a singleton.
| l_encoderNum | the encoder number, defaults to 0 |
|
inline |
You can configure whether the encoder pins need pullup input enabled or not. If you do not enable INPUT_PULLUP then you must ensure that the pins are pulled up externally and probably add some capacitance to reduce noise.
| l_needPullup | true if the pins need pullup input enabled |
|
inline |
The encoder will use the provided callback function to notify of changes.
| l_callback | a callback function matching EncoderCallbackFn |
|
inline |
The encoder will use the provided listener to notify of changes.
| l_listener | a listener matching EncoderListener |
|
inline |
The encoder will use the provided interrupt pin to update its state. This single interrupt pin must be the combination of the A and B pins. I.E. most likely a hardware or of both pins. Only use this when interrupt capable pins are in short supply.
| l_interruptPin | the interrupt pin to use |
|
inline |
Enable interrupts on both the A and B pins. This requires that both are interrupt capable pins.
|
inline |
Indicate to the builder that you are going to use either a hardware timer or manually configure interrupts. If you use a timer, it must be very frequent, I would recommend at least 1000Hz. If you manually configure interrupts it must capture both the A and B pins. In either case you must call encoderInterruptHandler() on every event.
|
inline |
Set the acceleration mode for the encoder, it defaults to regular acceleration.
| l_accelerationMode | the acceleration mode to use |
|
inline |
Sets the encoder type, it defaults to FULL_CYCLE. At the moment only full and half encoders are supported.
| l_encoderType | the encoder type that you have. |
|
inlinenodiscard |
Checks if the configuration is valid by making sure at least the basic configuration is sensible. It is not guaranteed that this returning true will provide a working encoder.
| bool StateRotaryEncoderBuilder::build | ( | ) | const |
A somewhat internal method used by the setupStateMachineRotaryEncoder function to build the encoder and register it with switches and taskmanager.