Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Encoder.h
1 #pragma once
2 
15 class Encoder
16 {
17 public:
18  typedef enum {
19  CCW = -1,
20  NONE = 0,
21  CW = 1,
22  } Rotation;
23 
27  typedef enum {
28  ANY,
31  } Polarity;
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();
69 private:
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 };
Polarity
Definition: Encoder.h:27
Rotation process(bool a, bool b)
Definition: Encoder.cpp:27
Trigger on negative edges.
Definition: Encoder.h:30
Connect a quadrature rotary encoder.
Definition: Encoder.h:15
Encoder(unsigned int debounce, Polarity polarity=ANY)
Definition: Encoder.h:38
Trigger on any edge.
Definition: Encoder.h:28
The encoder rotate clockwise.
Definition: Encoder.h:21
The encoder did not rotate.
Definition: Encoder.h:20
The encoder rotated counter-clockwise.
Definition: Encoder.h:19
void setup(unsigned int debounce, Polarity polarity=ANY)
Definition: Encoder.cpp:4
void reset(int position=0)
Definition: Encoder.cpp:13
Rotation
Definition: Encoder.h:18
Trigger on negative edges.
Definition: Encoder.h:29