-
Notifications
You must be signed in to change notification settings - Fork 3
/
DisplayLiFi.h
76 lines (67 loc) · 2 KB
/
DisplayLiFi.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef DISPLAYLIFILIB_DISPLAYLIFI_H
#define DISPLAYLIFILIB_DISPLAYLIFI_H
#include <Arduino.h>
#define SERIAL_DEBUG_DISPLAY_LIFI_VERBOSE
#define SERIAL_DEBUG_DISPLAY_LIFI
#if defined(UNITTEST_BUILD) && defined(SERIAL_DEBUG_DISPLAY_LIFI)
#undef SERIAL_DEBUG_DISPLAY_LIFI
#endif
#if defined(UNITTEST_BUILD) && defined(SERIAL_DEBUG_DISPLAY_LIFI)
#undef SERIAL_DEBUG_DISPLAY_LIFI_VERBOSE
#endif
class DisplayLiFi {
public:
enum ERROR {
NONE,
CALIBRATION,
INVALID_SIGNAL
};
static const int LEADER_CODE_SIGNAL_DURATION = 800;
private:
typedef void (*LeaderCodeListener)(char* receivedString);
int analogPort_;
int previousSignal_;
unsigned long previousTime_;
int bufferIndex_;
char receivedString_[64]; // TODO: reduce memory usage
int receivedIndex_;
int buffer_;
int signalThresholdHigh_;
int signalThresholdLow_;
LeaderCodeListener leaderCodeListener_;
void clearReceivedString();
void init(int analogPort);
void init(int analogPort, LeaderCodeListener leaderCodeListener1);
void callLeaderCodeListener();
boolean isCalibration_;
unsigned long calibrationStartTime_;
unsigned long calibrationUpdatedTime_;
int calibrationMax_;
int calibrationMin_;
int calibrationMaxRecently_;
int calibrationMinRecently_;
int calibrationDurationMSec_;
enum ERROR error_;
void setError(enum ERROR err) {
error_ = err;
}
public:
DisplayLiFi(int analogPort);
DisplayLiFi(int analogPort, LeaderCodeListener leaderCodeListener);
void setSignalThresholdHigh(int threshold);
void setSignalThresholdLow(int threshold);
int getSignalThresholdHigh();
int getSignalThresholdLow();
void pushSignal(int signal);
char* getReceivedString();
void startCalibration(int milliseconds);
boolean loop();
int getBuffer() {
return buffer_;
};
enum ERROR getError() {
return error_;
}
int detectSignal(int val) const;
};
#endif //DISPLAYLIFILIB_DISPLAYLIFI_H