-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGroveEncoder.h
More file actions
56 lines (35 loc) · 1.11 KB
/
GroveEncoder.h
File metadata and controls
56 lines (35 loc) · 1.11 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
GroveEncoder.h - Header for Grove Encoder library
Copyright (C) 2016 David Antler
All rights reserved.
This software may be modified and distributed under the terms
of the included license. See the LICENSE file for details.
*/
#ifndef GROVE_ENCODER_LIB_H_
#define GROVE_ENCODER_LIB_H_
/* Note: PIN_DATA_SIZE must be a power of two due to the queue implementation. */
#define PIN_DATA_SIZE 128
class GroveEncoder {
public:
GroveEncoder(int pin, void (*optionalCallBack)(int, bool));
int getValue();
int button_flag;
void setValue(int newValue);
void resetValue();
/* This is private, but it needs to be public/static */
static void privateIntHandler();
void updateEncoderFast();
private:
int LOW_PIN, HIGH_PIN;
volatile int value;
int readIndex;
int writeIndex;
unsigned char pinDataQueue[PIN_DATA_SIZE];
void (*optCallBack)(int, bool);
inline bool pushToQueue(unsigned char myValue);
inline bool queueIsEmpty();
inline bool queueIsFull();
inline unsigned char popFromQueue();
void processQueue();
};
#endif