2022-01-08 12:13:29 +00:00
|
|
|
#pragma once
|
2022-01-11 15:02:55 +00:00
|
|
|
|
|
|
|
#include "SinglePortPlugin.h" // TODO: what header file to include?
|
2022-01-12 08:26:42 +00:00
|
|
|
#include "InputBroker.h"
|
2022-01-08 12:13:29 +00:00
|
|
|
|
|
|
|
enum RotaryEncoderInterruptBaseStateType
|
|
|
|
{
|
2022-01-09 09:08:31 +00:00
|
|
|
ROTARY_EVENT_OCCURRED,
|
|
|
|
ROTARY_EVENT_CLEARED
|
2022-01-08 12:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum RotaryEncoderInterruptBaseActionType
|
|
|
|
{
|
2022-01-09 09:08:31 +00:00
|
|
|
ROTARY_ACTION_NONE,
|
|
|
|
ROTARY_ACTION_PRESSED,
|
|
|
|
ROTARY_ACTION_CW,
|
|
|
|
ROTARY_ACTION_CCW
|
2022-01-08 12:13:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RotaryEncoderInterruptBase :
|
|
|
|
public Observable<const InputEvent *>,
|
|
|
|
private concurrency::OSThread
|
|
|
|
{
|
|
|
|
public:
|
2022-01-24 18:39:17 +00:00
|
|
|
explicit RotaryEncoderInterruptBase(
|
2022-01-11 12:12:04 +00:00
|
|
|
const char *name);
|
|
|
|
void init(
|
|
|
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
|
|
|
char eventCw, char eventCcw, char eventPressed,
|
2022-01-08 12:13:29 +00:00
|
|
|
// std::function<void(void)> onIntA, std::function<void(void)> onIntB, std::function<void(void)> onIntPress);
|
|
|
|
void (*onIntA)(), void (*onIntB)(), void (*onIntPress)());
|
|
|
|
void intPressHandler();
|
|
|
|
void intAHandler();
|
|
|
|
void intBHandler();
|
|
|
|
|
|
|
|
protected:
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2022-01-12 21:50:37 +00:00
|
|
|
RotaryEncoderInterruptBaseStateType intHandler(
|
|
|
|
bool actualPinRaising,
|
|
|
|
int otherPinLevel,
|
|
|
|
RotaryEncoderInterruptBaseActionType action,
|
|
|
|
RotaryEncoderInterruptBaseStateType state);
|
|
|
|
|
2022-01-09 09:08:31 +00:00
|
|
|
volatile RotaryEncoderInterruptBaseStateType rotaryStateCW = ROTARY_EVENT_CLEARED;
|
|
|
|
volatile RotaryEncoderInterruptBaseStateType rotaryStateCCW = ROTARY_EVENT_CLEARED;
|
2022-01-08 12:13:29 +00:00
|
|
|
volatile int rotaryLevelA = LOW;
|
|
|
|
volatile int rotaryLevelB = LOW;
|
2022-01-09 09:08:31 +00:00
|
|
|
volatile RotaryEncoderInterruptBaseActionType action = ROTARY_ACTION_NONE;
|
2022-01-08 12:13:29 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-24 07:00:14 +00:00
|
|
|
uint8_t _pinA = 0;
|
|
|
|
uint8_t _pinB = 0;
|
|
|
|
char _eventCw = InputEventChar_KEY_NONE;
|
|
|
|
char _eventCcw = InputEventChar_KEY_NONE;
|
|
|
|
char _eventPressed = InputEventChar_KEY_NONE;
|
2022-01-11 15:02:55 +00:00
|
|
|
const char *_originName;
|
2022-01-24 07:00:14 +00:00
|
|
|
};
|