IoAbstraction
Public Member Functions | Protected Types | Protected Attributes | List of all members
RotaryEncoder Class Reference

#include <SwitchInput.h>

Inheritance diagram for RotaryEncoder:
AbstractHwRotaryEncoder EncoderUpDownButtons JoystickSwitchInput HardwareRotaryEncoder HwStateRotaryEncoder

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
 
EncoderListenerencoderListener
 
notify
 
uint8_t flags
 
EncoderUserIntention intent
 

Detailed Description

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.

Member Function Documentation

◆ changePrecision()

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.

Parameters
maxValuethe largest value allowed or zero for direction only mode
currentValuethe current value (zero for direction mode)

◆ replaceCallback()

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.

Parameters
callbackFnthe new callback function

◆ replaceCallbackListener()

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.

Parameters
callbackFnthe new callback function

◆ getCurrentReading()

int RotaryEncoder::getCurrentReading ( ) const
inline

Gets the current value of the encoder.

◆ setCurrentReading()

void RotaryEncoder::setCurrentReading ( int  reading)
inline

Sets the current value of the encoder.

Parameters
readingwill become the new current value.

◆ increment()

void RotaryEncoder::increment ( int8_t  incVal)

Change the value represented by the encoder by incVal. Normally called internally.

Parameters
incValthe amount by which to change the encoder.

◆ encoderChanged()

virtual void RotaryEncoder::encoderChanged ( )
inlinevirtual

internal method not for external use..

Reimplemented in HwStateRotaryEncoder, and HardwareRotaryEncoder.

◆ didLastSyncSucceed()

bool RotaryEncoder::didLastSyncSucceed ( )
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.

Returns
true if the sync was successful, otherwise.

◆ setUserIntention()

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.

◆ getMaximumValue()

bsize_t RotaryEncoder::getMaximumValue ( )
inline
Returns
the maximum value that this encoder can be set to.

The documentation for this class was generated from the following files: