Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
Encoder.h
1#pragma once
2
15class Encoder
16{
17public:
18 typedef enum {
19 CCW = -1,
20 NONE = 0,
21 CW = 1,
22 } Rotation;
23
32
33 Encoder() { setup(0, ANY); };
34
38 Encoder(unsigned int debounce, Polarity polarity = ANY) { setup(debounce, polarity); };
39
48 void setup(unsigned int debounce, Polarity polarity = ANY);
49
55 void reset(int position = 0);
56
63 Rotation process(bool a, bool b);
64
68 int get();
69private:
70 bool validEdge(bool a);
71 unsigned int debouncing_;
72 unsigned int debounce_;
73 int position_;
74 Polarity polarity_;
75 bool a_;
76 bool lastA_;
77 bool primed_;
78};
Connect a quadrature rotary encoder.
Definition Encoder.h:16
Rotation process(bool a, bool b)
Definition Encoder.cpp:27
void setup(unsigned int debounce, Polarity polarity=ANY)
Definition Encoder.cpp:4
Polarity
Definition Encoder.h:27
@ ANY
Trigger on any edge.
Definition Encoder.h:28
@ ACTIVE_HIGH
Trigger on negative edges.
Definition Encoder.h:30
@ ACTIVE_LOW
Trigger on negative edges.
Definition Encoder.h:29
Encoder(unsigned int debounce, Polarity polarity=ANY)
Definition Encoder.h:38
void reset(int position=0)
Definition Encoder.cpp:13
Rotation
Definition Encoder.h:18
@ CW
The encoder rotate clockwise.
Definition Encoder.h:21
@ CCW
The encoder rotated counter-clockwise.
Definition Encoder.h:19
@ NONE
The encoder did not rotate.
Definition Encoder.h:20
int get()
Definition Encoder.cpp:63