18#include "TaskManager.h"
19#include <SimpleCollections.h>
25#define HOLD_THRESHOLD 20
29#ifndef SWITCHES_ACCELERATION_DIVISOR
30#define SWITCHES_ACCELERATION_DIVISOR 2
39#define MAX_KEYS DEFAULT_LIST_SIZE
46#ifndef MAX_ROTARY_ENCODERS
47#define MAX_ROTARY_ENCODERS 4
53#ifndef SWITCH_POLL_INTERVAL
54#define SWITCH_POLL_INTERVAL 20
63#ifndef REJECT_DIRECTION_CHANGE_THRESHOLD
64#define REJECT_DIRECTION_CHANGE_THRESHOLD 10000
72enum KeyPressState : uint8_t {
80#define KEY_PRESS_STATE_MASK 0x0f
81#define KEY_LISTENER_MODE_BIT 7
82#define KEY_LOGIC_IS_INVERTED 6
128 KeyPressState previousState;
131 uint8_t acceleration;
132 uint8_t repeatInterval;
141 KeyboardItem(pinid_t pin,
SwitchListener* switchListener, uint8_t repeatInterval = NO_REPEAT,
bool keyLogicIsInverted =
false);
144 void checkAndTrigger(uint8_t pin);
147 bool isDebouncing()
const {
return getState() == DEBOUNCING1 || getState() == DEBOUNCING2; }
148 bool isPressed()
const {
return getState() == PRESSED || getState() == BUTTON_HELD; }
149 bool isHeld()
const {
return getState() == BUTTON_HELD; }
150 pinid_t getPin()
const {
return pin; }
151 pinid_t getKey()
const {
return pin; }
153 void trigger(
bool held);
154 void triggerRelease(
bool held);
156 KeyPressState getState()
const {
return (KeyPressState)(stateFlags & KEY_PRESS_STATE_MASK); }
157 void setState(KeyPressState state) {
158 stateFlags &= ~KEY_PRESS_STATE_MASK;
159 stateFlags |= (state & KEY_PRESS_STATE_MASK);
161 bool isUsingListener() {
return bitRead(stateFlags, KEY_LISTENER_MODE_BIT); }
162 bool isLogicInverted() {
return bitRead(stateFlags, KEY_LOGIC_IS_INVERTED); }
167 void setRepeatInterval(uint8_t newInterval) { repeatInterval = newInterval;}
207 enum EncoderFlagBits { LAST_SYNC_STATUS=0, WRAP_AROUND_MODE, OO_LISTENER_CALLBACK, LAST_ENCODER_DIRECTION_UP };
208 uint16_t maximumValue;
209 uint16_t currentReading;
229 void changePrecision(uint16_t maxValue,
int currentValue,
bool rolloverOnMax =
false,
int step = 1);
282 void runCallback(
int newVal) {
283 if(bitRead(flags, OO_LISTENER_CALLBACK)) {
284 notify.encoderListener->encoderHasChanged(newVal);
286 notify.callback(newVal);
324 unsigned long lastChange;
348 int amountFromChange(
unsigned long change);
349 void handleChangeRaw(
bool increase);
362 uint8_t pulseCounter = 0;
397 int8_t currentEncoderState = 0;
422 int8_t stateFor(uint8_t bits);
432 const pinid_t upPin, downPin, backPin, nextPin;
434 const bool canRotate;
490 void onPressed(pinid_t pin,
bool held)
override;
491 void onReleased(pinid_t pin,
bool held)
override;
500#define SW_FLAG_PULLUP_LOGIC 0
501#define SW_FLAG_INTERRUPT_DRIVEN 1
502#define SW_FLAG_INTERRUPT_DEBOUNCE 2
503#define SW_FLAG_ENCODER_IS_POLLING 3
534 BtreeList<pinid_t, KeyboardItem> keys;
535 volatile uint8_t swFlags;
589 bool addSwitch(pinid_t pin,
KeyCallbackFn callback, uint8_t repeat = NO_REPEAT,
bool invertLogic =
false);
674 void changeEncoderPrecision(uint8_t slot, uint16_t precision, uint16_t currentValue,
bool rollover,
int step=1);
698 bool pullUp = bitRead(swFlags, SW_FLAG_PULLUP_LOGIC);
700 return (pullUp && !invertedLogic) || (!pullUp && invertedLogic);
706 bool isInterruptDriven() {
return bitRead(swFlags, SW_FLAG_INTERRUPT_DRIVEN);}
742 return keys.removeByKey(pin);
754 bool internalAddSwitch(pinid_t pin,
bool invertLogic);
756 friend void onSwitchesInterrupt(pinid_t);
Using basic IoFacilities allows one to abstract away the use of IoExpanders, such that the switching ...
Definition SwitchInput.h:322
void setEncoderType(EncoderType et)
Definition SwitchInput.h:344
void setAccelerationMode(HWAccelerationMode mode)
Definition SwitchInput.h:338
Definition BasicIoAbstraction.h:38
Definition SwitchInput.h:190
virtual void encoderHasChanged(int newValue)=0
Definition SwitchInput.h:359
void encoderChanged() override
Definition SwitchInput.cpp:436
Definition SwitchInput.h:395
void encoderChanged() override
Definition SwitchInput.cpp:635
Definition SwitchInput.h:125
Definition SwitchInput.h:205
bool didLastSyncSucceed()
Definition SwitchInput.h:270
int getCurrentReading() const
Definition SwitchInput.h:246
virtual void encoderChanged()
Definition SwitchInput.h:263
void replaceCallbackListener(EncoderListener *callbackFn)
Definition SwitchInput.cpp:308
void setUserIntention(EncoderUserIntention intention)
Definition SwitchInput.cpp:313
void replaceCallback(EncoderCallbackFn callbackFn)
Definition SwitchInput.cpp:303
void increment(int8_t incVal)
Definition SwitchInput.cpp:324
void setCurrentReading(int reading)
Definition SwitchInput.h:252
bsize_t getMaximumValue()
Definition SwitchInput.h:293
void changePrecision(uint16_t maxValue, int currentValue, bool rolloverOnMax=false, int step=1)
Definition SwitchInput.cpp:294
Definition SwitchInput.h:91
virtual void onPressed(pinid_t pin, bool held)=0
virtual void onReleased(pinid_t pin, bool held)=0