forked from Skuzzle-UK/ECUMASTER_CAN_DISPLAY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.ino
117 lines (103 loc) · 2.62 KB
/
clock.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
unsigned long lastMillis;
int hours = 00;
int minutes = 00;
uint8_t seconds = 00;
//////////////////////////////////////////////////////////////
void PrintSeconds()
{
if(!setMode){
if (seconds & 1)
{
display.printFixedN (69, 12, ":", STYLE_NORMAL, FONT_SIZE_2X);
}
else
{
display.printFixedN (69, 12, " ", STYLE_NORMAL, FONT_SIZE_2X);
}
}
else{
display.printFixedN (69, 12, " ", STYLE_NORMAL, FONT_SIZE_2X);
}
}
//////////////////////////////////////////////////////////////
void PrintMinutes()
{
char minutesStr[3] = "00";
minutesStr[0] = '0' + minutes / 10;
minutesStr[1] = '0' + minutes % 10;
display.printFixedN (78, 0, minutesStr, STYLE_NORMAL, FONT_SIZE_4X);
}
//////////////////////////////////////////////////////////////
void PrintHours()
{
char hoursStr[3] = "00";
hoursStr[0] = '0' + hours / 10;
hoursStr[1] = '0' + hours % 10;
display.printFixedN (20, 0, hoursStr, STYLE_NORMAL, FONT_SIZE_4X);
}
//////////////////////////////////////////////////////////////
void ClockSetup()
{
//rtc.begin();
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Remove comment to set time on compile of code
is_rtc_enabled = RTC_ENABLED;
lastMillis = lcd_millis();
PrintHours();
PrintMinutes();
}
//////////////////////////////////////////////////////////////
void CLOCK_SET_TIME(DIRECTION direction) {
DateTime now = rtc.now();
switch(direction){
case DIRECTION::UP: {
if (++hours > 23){
hours = 0;
}
seconds = 0;
break;
}
case DIRECTION::DOWN: {
if (++minutes > 59){
minutes = 0;
}
seconds = 0;
break;
}
}
rtc.adjust(DateTime(now.year(), now.month(), now.day(), hours, minutes, seconds));
}
//////////////////////////////////////////////////////////////
void ClockLoop()
{
if ((uint32_t)(lcd_millis() - lastMillis) >= 1000)
{
lastMillis += 1000;
if (++seconds > 59)
{
seconds = 0;
if (++minutes > 59)
{
minutes = 0;
if (++hours > 23)
{
hours = 0;
}
PrintHours();
}
PrintMinutes();
}
PrintSeconds();
}
}
//////////////////////////////////////////////////////////////
void RTC_Clock(){
DateTime now = rtc.now();
hours = now.hour();
minutes = now.minute();
seconds = now.second();
Serial.print(now.hour());
Serial.print(":");
Serial.print(now.minute());
Serial.print(".");
Serial.println(now.second());
}