You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.0 KiB

#ifndef _ROTARY_H
#define _ROTARY_H
#include <Arduino.h>
#include <functional>
//#include <ClickEncoder.h>
// usually the rotary encoders three pins have the ground pin in the middle
enum PinAssignments {
encoderPinA = 2, // right
encoderPinB = 3, // left
clearButton = 8 // another two pins
};
class Rotary {
public:
Rotary();
bool begin(uint8_t pinA, uint8_t pinB, uint8_t pinButton);
bool registerCallback(std::function<void(int, int, int)> callback);
static void IRAM_ATTR doEncoder(void);
static Rotary* instance;
volatile int encoderPos = 0;
int encoderPosOld = 0;
bool buttonPressed = false;
int value = 0;
uint32_t debounceMillis;
uint32_t debounceDelay = 1;
uint32_t debouncePulses = 0;
int countDirection = 0;
TaskHandle_t xTaskToNotify;
private:
uint8_t pinA;
uint8_t pinB;
uint8_t pinButton;
std::function<void(int, int, int)> callback = nullptr;
TaskHandle_t taskHandle;
void task(void*);
static void cTaskWrapper(void*);
};
#endif /* _ROTARY_H */