Switch input provides the button and rotary encoder input capabilities provided by this library. There is a globally defined variable switches
declared that you can use directly. To add a rotary encoder, see the helper functions further down. There's also a rotary encoder emulation based on Up and Down buttons.
More...
Go to the source code of this file.
Classes | |
class | SwitchListener |
class | KeyboardItem |
class | EncoderListener |
class | RotaryEncoder |
class | AbstractHwRotaryEncoder |
class | HardwareRotaryEncoder |
class | HwStateRotaryEncoder |
class | EncoderUpDownButtons |
class | SwitchInput |
Typedefs | |
typedef void(* | KeyCallbackFn) (pinid_t key, bool heldDown) |
typedef void(* | EncoderCallbackFn) (int newValue) |
Enumerations | |
enum | KeyPressState : uint8_t { NOT_PRESSED , DEBOUNCING1 , DEBOUNCING2 , PRESSED , BUTTON_HELD } |
enum | EncoderUserIntention : uint8_t { CHANGE_VALUE = 0 , SCROLL_THROUGH_ITEMS , SCROLL_THROUGH_SIDEWAYS , DIRECTION_ONLY } |
enum | HWAccelerationMode : uint8_t { HWACCEL_NONE , HWACCEL_REGULAR , HWACCEL_SLOWER } |
enum | EncoderType : uint8_t { QUARTER_CYCLE , HALF_CYCLE , FULL_CYCLE } |
enum | SwitchInterruptMode { SWITCHES_NO_POLLING , SWITCHES_POLL_KEYS_ONLY , SWITCHES_POLL_EVERYTHING } |
Functions | |
void | setupStateMachineRotaryEncoder (pinid_t pinA, pinid_t pinB, EncoderCallbackFn callback, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType encoderType=FULL_CYCLE) |
void | setupStateMachineRotaryEncoder (pinid_t pinA, pinid_t pinB, EncoderListener *listener, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType encoderType=FULL_CYCLE) |
void | setupRotaryEncoderWithInterrupt (pinid_t pinA, pinid_t pinB, EncoderCallbackFn callback, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType encoderType=FULL_CYCLE) |
void | setupRotaryEncoderWithInterrupt (pinid_t pinA, pinid_t pinB, EncoderListener *listener, HWAccelerationMode accelerationMode=HWACCEL_REGULAR, EncoderType encoderType=FULL_CYCLE) |
void | setupUpDownButtonEncoder (pinid_t pinUp, pinid_t pinDown, EncoderCallbackFn callback, int speed=20) |
void | setupUpDownButtonEncoder (pinid_t pinUp, pinid_t pinDown, EncoderListener *listener, int speed=20) |
void | setupUpDownButtonEncoder (pinid_t pinUp, pinid_t pinDown, pinid_t pinLeft, pinid_t pinRight, SwitchListener *passThroughListener, EncoderListener *listener, int speed=20) |
void | setupUpDownButtonEncoder (pinid_t pinUp, pinid_t pinDown, pinid_t pinLeft, pinid_t pinRight, SwitchListener *passThroughListener, EncoderCallbackFn encoderCallbackFn, int speed=20) |
Variables | |
SwitchInput | switches |
Switch input provides the button and rotary encoder input capabilities provided by this library. There is a globally defined variable switches
declared that you can use directly. To add a rotary encoder, see the helper functions further down. There's also a rotary encoder emulation based on Up and Down buttons.
typedef void(* KeyCallbackFn) (pinid_t key, bool heldDown) |
The signature for a callback function that is registered with addSwitch, you can also implement the SwitchListener interface instead to receive updates.
key | the pin associated with the pin |
heldDown | if the button has been held down |
typedef void(* EncoderCallbackFn) (int newValue) |
The signature for the encoder callback, in addition to this, you can also implement the EncoderListener interface instead to receive updates.
newValue | the value of the rotary encoder |
enum EncoderUserIntention : uint8_t |
When working with rotary encoders there's three possible ways that the user will interact, and it is this intent that we need to capture, they are either using it for direction only, to scroll through items, or to change a value.
enum HWAccelerationMode : uint8_t |
This enumeration is used to control how acceleration is handled within a particular instance of a HardwareRotaryEncoder.
enum EncoderType : uint8_t |
enum SwitchInterruptMode |
An enumeration of values, one of which is used when calling switches.init to tell switches what to poll for, or not to poll at all.
void setupStateMachineRotaryEncoder | ( | pinid_t | pinA, |
pinid_t | pinB, | ||
EncoderCallbackFn | callback, | ||
HWAccelerationMode | accelerationMode = HWACCEL_REGULAR , |
||
EncoderType | encoderType = FULL_CYCLE |
||
) |
Initialise a hardware rotary encoder on the pins passed in, when the value changes the callback function will be called. This library will set pinA and pinB to INPUT_PULLUP, and debounces internally. In most cases no additional components are needed. This function automatically adds the encoder to the global switches instance. This uses the state machine encoder, which is presently in BETA at best.
pinA | the first pin of the encoder, this pin must handle interrupts. |
pinB | the third pin of the encoder, the middle pin goes to ground. |
callback | the function that will receive the new state of the encoder on changes. |
accelerationMode | the mode of acceleration to use |
encoderType | the type of encoder being used |
void setupStateMachineRotaryEncoder | ( | pinid_t | pinA, |
pinid_t | pinB, | ||
EncoderListener * | listener, | ||
HWAccelerationMode | accelerationMode = HWACCEL_REGULAR , |
||
EncoderType | encoderType = FULL_CYCLE |
||
) |
Initialise a hardware rotary encoder on the pins passed in, when the value changes the OO listener will be invoked. This library will set pinA and pinB to INPUT_PULLUP, and debounces internally. In most cases no additional components are needed. This function automatically adds the encoder to the global switches instance. This uses the state machine encoder, which is presently in BETA at best.
Essentially this does:
auto* enc = new EncoderUpDownButtons(pinUp, pinDown, callback); switches.setEncoder(0, enc);
pinA | the first pin of the encoder, this pin must handle interrupts. |
pinB | the third pin of the encoder, the middle pin goes to ground. |
listener | the function that will receive the new state of the encoder on changes. |
accelerationMode | the mode of acceleration to use |
encoderType | the type of encoder being used |
void setupRotaryEncoderWithInterrupt | ( | pinid_t | pinA, |
pinid_t | pinB, | ||
EncoderCallbackFn | callback, | ||
HWAccelerationMode | accelerationMode = HWACCEL_REGULAR , |
||
EncoderType | encoderType = FULL_CYCLE |
||
) |
Initialise a hardware rotary encoder on the pins passed in, when the value changes the callback function will be called. This library will set pinA and pinB to INPUT_PULLUP, and debounces internally. In most cases no additional components are needed. This function automatically adds the encoder to the global switches instance.
Essentially this does:
auto* enc = new EncoderUpDownButtons(pinUp, pinDown, callback); switches.setEncoder(0, enc);
pinA | the first pin of the encoder, this pin must handle interrupts. |
pinB | the third pin of the encoder, the middle pin goes to ground. |
callback | the function that will receive the new state of the encoder on changes. |
accelerationMode | the mode of acceleration to use |
encoderType | the type of encoder being used |
void setupRotaryEncoderWithInterrupt | ( | pinid_t | pinA, |
pinid_t | pinB, | ||
EncoderListener * | listener, | ||
HWAccelerationMode | accelerationMode = HWACCEL_REGULAR , |
||
EncoderType | encoderType = FULL_CYCLE |
||
) |
Initialise a hardware rotary encoder on the pins passed in, when the value changes the OO listener will be invoked. This library will set pinA and pinB to INPUT_PULLUP, and debounces internally. In most cases no additional components are needed. This function automatically adds the encoder to the global switches instance.
Essentially this does:
auto* enc = new EncoderUpDownButtons(pinUp, pinDown, callback); switches.setEncoder(0, enc);
pinA | the first pin of the encoder, this pin must handle interrupts. |
pinB | the third pin of the encoder, the middle pin goes to ground. |
listener | the function that will receive the new state of the encoder on changes. |
accelerationMode | the mode of acceleration to use |
encoderType | the type of encoder being used |
void setupUpDownButtonEncoder | ( | pinid_t | pinUp, |
pinid_t | pinDown, | ||
EncoderCallbackFn | callback, | ||
int | speed = 20 |
||
) |
Initialise an encoder that uses up and down buttons to handle the same functions as a hardware encoder. This function automatically adds the encoder to the global switches instance.
Essentially this does:
auto* enc = new EncoderUpDownButtons(pinUp, pinDown, callback); switches.setEncoder(0, enc);
pinUp | the up button |
pinDown | the down button |
callback | the function that will receive the new state on change. |
void setupUpDownButtonEncoder | ( | pinid_t | pinUp, |
pinid_t | pinDown, | ||
EncoderListener * | listener, | ||
int | speed = 20 |
||
) |
Initialise an encoder that uses up and down buttons to handle the same functions as a hardware encoder. This function automatically adds the encoder to the global switches instance. This version takes an OO listener implementing EncoderListener.
Essentially this does:
auto* enc = new EncoderUpDownButtons(pinUp, pinDown, listener); switches.setEncoder(0, enc);
pinUp | the up button |
pinDown | the down button |
listener | the OO listener that will receive the new state on change. |
void setupUpDownButtonEncoder | ( | pinid_t | pinUp, |
pinid_t | pinDown, | ||
pinid_t | pinLeft, | ||
pinid_t | pinRight, | ||
SwitchListener * | passThroughListener, | ||
EncoderListener * | listener, | ||
int | speed = 20 |
||
) |
Initialise an encoder that uses up and down buttons to handle the same functions as a hardware encoder. This function automatically adds the encoder to the global switches instance. This version takes an OO listener implementing EncoderListener. This version supports the idea of rotating the cursor key operation if needed by changing the intent to be sideways.
pinUp | the up button |
pinDown | the down button |
pinLeft | the left button |
pinRight | the right button |
passThroughListener | a listener that will receive notifications for left and right presses. |
listener | the OO listener that will receive the new state on change. |
void setupUpDownButtonEncoder | ( | pinid_t | pinUp, |
pinid_t | pinDown, | ||
pinid_t | pinLeft, | ||
pinid_t | pinRight, | ||
SwitchListener * | passThroughListener, | ||
EncoderCallbackFn | encoderCallbackFn, | ||
int | speed = 20 |
||
) |
Initialise an encoder that uses up and down buttons to handle the same functions as a hardware encoder. This function automatically adds the encoder to the global switches instance. This version takes an OO listener implementing EncoderListener. This version supports the idea of rotating the cursor key operation if needed by changing the intent to be sideways.
pinUp | the up button |
pinDown | the down button |
pinLeft | the left button |
pinRight | the right button |
passThroughListener | a listener that will receive notifications for left and right presses. |
encoderCallbackFn | will receive the new value on change. |
|
extern |
This is the global switch input variable. Do not create other instances of this class.