-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.h
64 lines (55 loc) · 1.23 KB
/
interface.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
// Class to manage the interface activated with the Rotary Encoder
//
enum Interface_Mode
{
NORMAL,
VIEWCOUNT,
VOLUME,
Interface_Mode_COUNT
};
class InterfaceMode
{
Interface_Mode mode;
unsigned long lastChangeMillis;
public:
InterfaceMode() : mode(NORMAL), lastChangeMillis(millis()) {}
void nextMode()
{
mode = static_cast<Interface_Mode>((mode + 1) % Interface_Mode_COUNT);
lastChangeMillis = millis();
}
void prevMode()
{
if (mode == 0)
{
mode = static_cast<Interface_Mode>(Interface_Mode_COUNT - 1);
}
else
{
mode = static_cast<Interface_Mode>(mode - 1);
}
lastChangeMillis = millis();
}
void setModeNormal(void) {
mode = NORMAL;
}
Interface_Mode getMode()
{
return mode;
}
void resetTime()
{
lastChangeMillis = millis();
}
bool checkReset()
{
unsigned long currentMillis = millis();
unsigned long delayMillis = 10000; // 10 seconds
if (mode != NORMAL && currentMillis - lastChangeMillis >= delayMillis)
{
mode = NORMAL;
return true;
}
return false;
}
};