-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeSet.ino
129 lines (117 loc) · 3.66 KB
/
TimeSet.ino
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "FlixCapacitor.h"
namespace SetTime {
typedef enum TimeChangeMode_e {
Default = (1 << 0),
Hour = (1 << 1),
Minute = (1 << 2),
Brightness = (1 << 3),
Save = (1 << 4),
Last = (1 << 5),
} TimeMode;
}
;
SetTime::TimeMode mode = SetTime::Default;
uint8_t h, m, brightness;
void nextMode() {
if (mode == SetTime::Last)
mode = SetTime::Default;
else
mode = (SetTime::TimeMode) ((int) mode << 1);
}
void configureTime() {
displayModeChange("Change Time?", "UP = Yes, Click = NO");
delay(500);
while (true) {
if (millis() - lastJoystickAction > 100) {
lastJoystickAction = millis();
if (joystick.yUp()) {
delay(500);
break;
} else if (joystick.yDown() || joystick.buttonPressed()) {
delay(500);
return;
}
}
}
mode = SetTime::Hour;
resetScreen();
h = hour(), m = minute();
while (mode != SetTime::Default) {
switch (mode) {
case SetTime::Hour:
displayNotice("To set HOUR: Up/Down", "Click > Next");
delay(500);
selectNumber(&h, 1, 12, updateTimeCallback);
break;
case SetTime::Minute:
displayNotice("To set MINUTE: Up/Down", "Click > Next");
delay(500);
selectNumber(&m, 0, 59, updateTimeCallback);
break;
case SetTime::Brightness:
displayNotice("To set Brightness:", "UP/DOWN, Click > Next");
delay(500);
selectNumber(&brightness, 0, 15, updateBrigthnessCallback);
break;
case SetTime::Save:
sprintf(buf, "Set time to %2d:%02d?", h, m);
displayNotice(buf, "Yes = UP, No = Click...");
delay(500);
while(true) {
if (millis() - lastJoystickAction > 100) {
lastJoystickAction = millis();
if (joystick.yUp()) {
tmElements_t tmTime;
breakTime(now(), tmTime);
tmTime.Hour = h;
tmTime.Minute = m;
Serial.println(buf);
time_t t = makeTime(tmTime);
setTime(t);
Teensy3Clock.set(t);
break;
} else if (joystick.yDown() || joystick.buttonPressed()){
delay(500);
break;
}
}
}
/* no break */
case SetTime::Last:
mode = SetTime::Default;
/* no break */
case SetTime::Default:
return;
break;
};
nextMode();
}
}
void updateTimeCallback() {
displayTime(h, m);
}
void updateBrigthnessCallback() {
matrix.setBrightness(brightness);
printv(F("Brightness value [0-15] set to "), brightness);
}
void selectNumber(uint8_t *current, int min, int max, displayUpdateCallback callback) {
while(true) {
if (millis() - lastJoystickAction > 100) {
lastJoystickAction = millis();
if (joystick.buttonPressed()) {
delay(500);
break;
} else if (joystick.yUp()) {
*current = *current + 1;
if (*current > max) *current = max;
} else if (joystick.yDown()) {
*current = abs(*current - 1);
if (*current < min) *current = min;
}
if (callback != NULL)
callback();
}
delay(50);
}
return;
}