-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRotaryEncoder.h
33 lines (26 loc) · 1.03 KB
/
RotaryEncoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef ROTARYENCODER_H
#define ROTARYENCODER_H
#include "Driver.h"
#include <functional>
class RotaryEncoder : Driver
{
public:
explicit RotaryEncoder(int aPin, int bPin, int swPin);
int position() const { return this->_position; }
void setRotaryCallback(std::function<void(int)> callback) { this->rotaryCallback = callback; }
void setSwitchCallback(std::function<void(bool)> callback) { this->switchCallback = callback; }
private:
void rotaryEventHandler(int gpio, uint32_t events);
void switchEventHandler(int gpio, uint32_t events);
const Pin& aPin() const { return this->pin(RotaryEncoder::_aIdx); }
const Pin& bPin() const { return this->pin(RotaryEncoder::_bIdx); }
const Pin& swPin() const { return this->pin(RotaryEncoder::_swIdx); }
static constexpr int _aIdx = 0;
static constexpr int _bIdx = 1;
static constexpr int _swIdx = 2;
std::function<void(int)> rotaryCallback;
std::function<void(bool)> switchCallback;
int _position;
int _direction;
};
#endif // ROTARYENCODER_H