Public Member Functions | Static Public Attributes | List of all members
RotaryEncoder Class Reference

Event-driven rotary encoder class. Events are split into stable and unstable updates to prevent flooding the mqtt channel with many messages while the slider is being set, while allowing for a local display element (i.e. an led) to give real-time feedback. More...

#include <RotaryEncoder.h>

Public Member Functions

void check ()
 Polls the encoders's _inputFlag and detects events. This should be called in the sketch's loop() function. More...
 
int getId ()
 Returns the encoder id. More...
 
int getPostition ()
 Returns the current encoder postion. More...
 
void initInterrupts (void(*function)())
 Set the function to be called when a pin interrupt occurs. Ideally this wouldn't be needed and the pin interrupt would just call RotaryEncoder::tick(), but only static member functions can be used as callbacks for pin interrupts, so a wrapper function has to be written in the global scope and passed back into the button object. More...
 
 RotaryEncoder (int pinA, int pinB, int id=99)
 Class constructor. More...
 
void setEventHandler (void(*function)(RotaryEncoder *, uint8_t, int))
 Set the function that is called any time an encoder event is detected. Some example callback functions can be found in the InputNode example. More...
 
void setPosition (int value)
 Sets the encoder postion. Useful for resetting it back to zero for example. More...
 
void ICACHE_RAM_ATTR tick ()
 Raises the button's _inputFlag. This should be wrapped in a function in the global scope and fed into RotaryEncoder::initInterrupts() More...
 

Static Public Attributes

static const uint8_t kEventStableUpdate = 0
 Event ID for a stable update (potentiometer has been changed, then been stable longer than _interval). More...
 
static const uint8_t kEventUnstableUpdate = 1
 Event ID for a stable update (potentiometer has been changed, but not stopped moving yet). More...
 

Detailed Description

Event-driven rotary encoder class. Events are split into stable and unstable updates to prevent flooding the mqtt channel with many messages while the slider is being set, while allowing for a local display element (i.e. an led) to give real-time feedback.

Constructor & Destructor Documentation

◆ RotaryEncoder()

RotaryEncoder::RotaryEncoder ( int  pinA,
int  pinB,
int  id = 99 
)

Class constructor.

Member Function Documentation

◆ check()

void RotaryEncoder::check ( )

Polls the encoders's _inputFlag and detects events. This should be called in the sketch's loop() function.

◆ getId()

int RotaryEncoder::getId ( )

Returns the encoder id.

◆ getPostition()

int RotaryEncoder::getPostition ( )

Returns the current encoder postion.

◆ initInterrupts()

void RotaryEncoder::initInterrupts ( void(*)()  function)

Set the function to be called when a pin interrupt occurs. Ideally this wouldn't be needed and the pin interrupt would just call RotaryEncoder::tick(), but only static member functions can be used as callbacks for pin interrupts, so a wrapper function has to be written in the global scope and passed back into the button object.

◆ setEventHandler()

void RotaryEncoder::setEventHandler ( void(*)(RotaryEncoder *, uint8_t, int)  function)

Set the function that is called any time an encoder event is detected. Some example callback functions can be found in the InputNode example.

◆ setPosition()

void RotaryEncoder::setPosition ( int  value)

Sets the encoder postion. Useful for resetting it back to zero for example.

◆ tick()

void ICACHE_RAM_ATTR RotaryEncoder::tick ( )

Raises the button's _inputFlag. This should be wrapped in a function in the global scope and fed into RotaryEncoder::initInterrupts()

Member Data Documentation

◆ kEventStableUpdate

const uint8_t RotaryEncoder::kEventStableUpdate = 0
static

Event ID for a stable update (potentiometer has been changed, then been stable longer than _interval).

◆ kEventUnstableUpdate

const uint8_t RotaryEncoder::kEventUnstableUpdate = 1
static

Event ID for a stable update (potentiometer has been changed, but not stopped moving yet).


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