11#ifndef EXCLUDE_EVENT_ENCODER
13#ifndef EVENT_ENCODER_H
14#define EVENT_ENCODER_H
17#include "EventInputBase.h"
18#include <EncoderAdapter.h>
35 #if defined(FUNCTIONAL_SUPPORTED)
115 #if defined(FUNCTIONAL_SUPPORTED)
117 template <
typename T>
121 (instance->*method)(et, ie);
189 positionDivider = divider;
215 EncoderAdapter *encoder;
217 uint8_t positionDivider = 4;
218 int32_t currentPosition = 0;
219 int32_t oldPosition = 0;
220 unsigned int rateLimit = 0;
221 unsigned long rateLimitCounter = 0;
222 int encoderIncrement = 0;
The EventEncoder class is for quadrature encoder inputs providing the position & encoder increment,...
Definition: EventEncoder.h:31
void readIncrement()
Read and set the increment during update()
Definition: EventEncoder.cpp:71
long position()
The current position of the encoder. Can be reset with resetPosition()
Definition: EventEncoder.h:160
void update()
Update the state from the underlying encoder library.
Definition: EventEncoder.cpp:55
void setPositionDivider(uint8_t divider=4)
Quadrature encoders usually have four states for each 'click' of the rotary control,...
Definition: EventEncoder.h:187
CallbackFunction callbackFunction
The callback function member.
Definition: EventEncoder.h:50
void setCallback(T *instance, void(T::*method)(InputEventType, EventEncoder &))
Set the Callback function to a class method.
Definition: EventEncoder.h:118
void onEnabled() override
Can be ovrriden by derived classes but base method must be called.
Definition: EventEncoder.cpp:42
std::function< void(InputEventType et, EventEncoder &ie)> CallbackFunction
If std::function is supported, this creates the callback type.
Definition: EventEncoder.h:39
void invoke(InputEventType et) override
To be overriden by derived classes.
Definition: EventEncoder.cpp:35
void unsetCallback() override
Unset a previously set callback function or method.
Definition: EventEncoder.cpp:50
int16_t increment()
Returns a positive (CW) or negative (CCW) integer.
Definition: EventEncoder.h:155
void begin()
Initialise the EventEncoder.
Definition: EventEncoder.cpp:31
uint8_t getPositionDivider()
Get the currently set position divider value.
Definition: EventEncoder.h:198
void resetPosition(long pos=0)
Reset the counted position of the encoder.
Definition: EventEncoder.h:205
void setCallback(CallbackFunction f)
Set the Callback function.
Definition: EventEncoder.h:101
EventEncoder(EncoderAdapter *encoderAdapter)
Construct an EventEncoder input from an EncoderAdapter
Definition: EventEncoder.cpp:23
~EventEncoder()
Destroy the EventEncoder input.
Definition: EventEncoder.cpp:27
void setRateLimit(long ms=0)
Encoder callbacks are normally fired on every loop() but for MPG style encoders this can fire a huge ...
Definition: EventEncoder.h:176