IoAbstraction
Public Member Functions | List of all members
HardwareRotaryEncoder Class Reference

#include <SwitchInput.h>

Inheritance diagram for HardwareRotaryEncoder:
AbstractHwRotaryEncoder RotaryEncoder

Public Member Functions

 HardwareRotaryEncoder (pinid_t pinA, pinid_t pinB, EncoderCallbackFn callback, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType=FULL_CYCLE)
 
 HardwareRotaryEncoder (pinid_t pinA, pinid_t pinB, EncoderListener *listener, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType=FULL_CYCLE)
 
void encoderChanged () override
 
- Public Member Functions inherited from AbstractHwRotaryEncoder
 AbstractHwRotaryEncoder (EncoderCallbackFn callback)
 
 AbstractHwRotaryEncoder (EncoderListener *listener)
 
void setAccelerationMode (HWAccelerationMode mode)
 
void setEncoderType (EncoderType et)
 
- Public Member Functions inherited from RotaryEncoder
 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)
 
bool didLastSyncSucceed ()
 
void setUserIntention (EncoderUserIntention intention)
 
EncoderUserIntention getUserIntention ()
 
void runCallback (int newVal)
 
bsize_t getMaximumValue ()
 

Additional Inherited Members

- Protected Types inherited from RotaryEncoder
enum  EncoderFlagBits { LAST_SYNC_STATUS =0 , WRAP_AROUND_MODE , OO_LISTENER_CALLBACK , LAST_ENCODER_DIRECTION_UP }
 
- Protected Member Functions inherited from AbstractHwRotaryEncoder
void initialiseBase (pinid_t pinA, pinid_t pinB, HWAccelerationMode accelerationMode, EncoderType)
 
int amountFromChange (unsigned long change)
 
void handleChangeRaw (bool increase)
 
- Protected Attributes inherited from AbstractHwRotaryEncoder
unsigned long lastChange
 
pinid_t pinA
 
pinid_t pinB
 
HWAccelerationMode accelerationMode
 
EncoderType encoderType
 
- Protected Attributes inherited from RotaryEncoder
uint16_t maximumValue
 
uint16_t currentReading
 
uint8_t stepSize
 
union {
EncoderCallbackFn callback
 
EncoderListenerencoderListener
 
notify
 
uint8_t flags
 
EncoderUserIntention intent
 

Detailed Description

An implementation of RotaryEncoder that supports the most common types of rotary encoder, needed no additional hardware in most cases. For single encoders registered with switches see the helper method. This is now only used by switches helper functions when legacy mode is enabled using TC_LEGACY_ENCODER. For all new cases we recommend using HwStateRotaryEncoder instead.

See also
setupRotaryEncoderWithInterrupt

Constructor & Destructor Documentation

◆ HardwareRotaryEncoder() [1/2]

HardwareRotaryEncoder::HardwareRotaryEncoder ( pinid_t  pinA,
pinid_t  pinB,
EncoderCallbackFn  callback,
HWAccelerationMode  accelerationMode = HWACCEL_REGULAR,
EncoderType  encoderType = FULL_CYCLE 
)

Create an instance of a hardware rotary encoder specifying the A and B pin, the acceleration parameters and encoder type. It is your responsibility to register this encoder with switches using setEncoder(n, encoderPtr) if you use the constructor.

Parameters
pinAthe A pin of the encoder
pinBthe B pin of the encoder
callbackthe function callback to be called when triggered
accelerationModethe amount of acceleration to use

◆ HardwareRotaryEncoder() [2/2]

HardwareRotaryEncoder::HardwareRotaryEncoder ( pinid_t  pinA,
pinid_t  pinB,
EncoderListener listener,
HWAccelerationMode  accelerationMode = HWACCEL_REGULAR,
EncoderType  encoderType = FULL_CYCLE 
)

Create an instance of a hardware rotary encoder specifiying the A and B pin, the acceleration parameters and encoder type. It is your responsibility to register this encoder with switches using setEncoder(n, encoderPtr) if you use the constructor. This constructor takes an OO listener instead of a callback function, the listener implements EncoderListener.

Parameters
pinAthe A pin of the encoder
pinBthe B pin of the encoder
listenerthe OO listener extending from EncoderListener
accelerationModethe amount of acceleration to use

Member Function Documentation

◆ encoderChanged()

void HardwareRotaryEncoder::encoderChanged ( )
overridevirtual

internal method not for external use..

Calculate the new state from signals A and B.

Signal A and B form a quadrature signal pattern like this:

Signal A: __|¯¯|__|¯¯|__ (HIGH/LOW alternating) Signal B: _|¯¯|__|¯¯|__|_ (90 degrees phase-shifted from A)

Each combination of A and B represents one of four states:

  • State 0: A=0, B=0 --> Binary: 00
  • State 1: A=1, B=0 --> Binary: 10
  • State 2: A=1, B=1 --> Binary: 11
  • State 3: A=0, B=1 --> Binary: 01

Transitions between these states determine the direction of rotation:

  • Clockwise (CW): 0 -> 1 -> 3 -> 2 -> 0
  • Counterclockwise (CCW): 0 -> 2 -> 3 -> 1 -> 0

The new state is calculated by combining the values of signals A and B:

  • newState = (A << 1) | B

Reimplemented from RotaryEncoder.


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