-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGroveEncoder.h
45 lines (36 loc) · 1.06 KB
/
GroveEncoder.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
34
35
36
37
38
39
40
41
42
43
44
/**
* 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));
int getValue();
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);
inline bool pushToQueue(unsigned char myValue);
inline bool queueIsEmpty();
inline bool queueIsFull();
inline unsigned char popFromQueue();
void processQueue();
};
#endif