#include <SwitchInput.h>
Public Member Functions | |
RotaryEncoder (EncoderCallbackFn callback) | |
RotaryEncoder (EncoderListener *listener) | |
void | changePrecision (uint16_t maxValue, int currentValue, bool rolloverOnMax=false, int step=1) |
void | replaceCallback (EncoderCallbackFn callbackFn) |
void | replaceCallbackListener (EncoderListener *callbackFn) |
int | getCurrentReading () const |
void | setCurrentReading (int reading) |
void | increment (int8_t incVal) |
virtual void | encoderChanged () |
bool | didLastSyncSucceed () |
void | setUserIntention (EncoderUserIntention intention) |
EncoderUserIntention | getUserIntention () |
void | runCallback (int newVal) |
bsize_t | getMaximumValue () |
Protected Types | |
enum | EncoderFlagBits { LAST_SYNC_STATUS =0 , WRAP_AROUND_MODE , OO_LISTENER_CALLBACK , LAST_ENCODER_DIRECTION_UP } |
Protected Attributes | |
uint16_t | maximumValue |
uint16_t | currentReading |
uint8_t | stepSize |
union { | |
EncoderCallbackFn | callback |
EncoderListener * | encoderListener |
} | notify |
uint8_t | flags |
EncoderUserIntention | intent |
Rotary encoder is the base class of both the hardware rotary encoder and the up / down button version. It handles storing the current value, setting and managing the range of allowed values and calling back when the encoder changes.
void RotaryEncoder::changePrecision | ( | uint16_t | maxValue, |
int | currentValue, | ||
bool | rolloverOnMax = false , |
||
int | step = 1 |
||
) |
Change the precision of the rotary encoder, setting the maximum allowable value and the current value. If you set the maximum value to a positive value, then the encoder will work like a potentiometer between 0 and the maximum value. However, if you set maximum to zero, then the encoder works in direction mode, where you'll get called back with either 0-unchanged, 1-up, -1-down.
maxValue | the largest value allowed or zero for direction only mode |
currentValue | the current value (zero for direction mode) |
void RotaryEncoder::replaceCallback | ( | EncoderCallbackFn | callbackFn | ) |
Change the callback that will be used to notify of changes in the encoder value, this must never be null.
callbackFn | the new callback function |
void RotaryEncoder::replaceCallbackListener | ( | EncoderListener * | callbackFn | ) |
Change the callback that will be used to notify of changes in the encoder value, this must never be null.
callbackFn | the new callback function |
|
inline |
Gets the current value of the encoder.
|
inline |
Sets the current value of the encoder.
reading | will become the new current value. |
void RotaryEncoder::increment | ( | int8_t | incVal | ) |
Change the value represented by the encoder by incVal. Normally called internally.
incVal | the amount by which to change the encoder. |
|
inlinevirtual |
internal method not for external use..
Reimplemented in HwStateRotaryEncoder, and HardwareRotaryEncoder.
|
inline |
Used to get the last sync status of the underlying IoAbstraction. Useful when working with devices over i2c to check if the comms worked.
void RotaryEncoder::setUserIntention | ( | EncoderUserIntention | intention | ) |
For joystick and up/down button encoders there is a difference between scroll using the encoder, and presenting the menu using the encoder, unlike rotary encoders where both modes feel natural the same way, there is a need to invert scrolling on button and joysticks.
|
inline |