2022-01-08 12:13:29 +00:00
|
|
|
#pragma once
|
2022-01-09 09:08:31 +00:00
|
|
|
//#include <Arduino.h>
|
|
|
|
//#include "Observer.h"
|
2022-01-08 12:13:29 +00:00
|
|
|
#include "SinglePortPlugin.h"
|
|
|
|
#include "HardwareInput.h"
|
|
|
|
|
|
|
|
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:
|
|
|
|
RotaryEncoderInterruptBase(
|
2022-01-09 09:08:31 +00:00
|
|
|
const char *name,
|
2022-01-08 12:13:29 +00:00
|
|
|
uint8_t pinA, uint8_t pinB, uint8_t pinPress,
|
|
|
|
char eventCw, char eventCcw, char eventPressed,
|
|
|
|
// 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:
|
|
|
|
virtual int32_t runOnce();
|
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:
|
|
|
|
uint8_t _pinA;
|
|
|
|
uint8_t _pinB;
|
|
|
|
char _eventCw;
|
|
|
|
char _eventCcw;
|
|
|
|
char _eventPressed;
|
2022-01-09 09:08:31 +00:00
|
|
|
};
|