-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetDate.h
98 lines (85 loc) · 2.85 KB
/
setDate.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef CONFETTI_SET_DATE
#define CONFETTI_SET_DATE
void updateSetDateUI() {
updateInitUI();
updateTitleUI("Configuration - Set Date");
ttgo->tft->setCursor(0, 32+48);
ttgo->tft->setTextFont(6);
snprintf(buf, sizeof(buf), "%d%02d%02d", yyear, mmonth, dday);
ttgo->tft->println(buf);
ttgo->tft->setTextFont(4);
ttgo->tft->setCursor(40, 32+24);
ttgo->tft->print("+");
ttgo->tft->setCursor(40, 32+96);
ttgo->tft->print("-");
ttgo->tft->setCursor(120, 32+24);
ttgo->tft->print("+");
ttgo->tft->setCursor(120, 32+96);
ttgo->tft->print("-");
ttgo->tft->setCursor(200, 32+24);
ttgo->tft->print("+");
ttgo->tft->setCursor(200, 32+96);
ttgo->tft->print("-");
ttgo->tft->drawBitmap(30-12, 240-24, EXIT_24, 24, 24, TFT_WHITE);
ttgo->tft->drawBitmap(150-12, 240-24, TIME_24, 24, 24, TFT_WHITE);
ttgo->tft->drawBitmap(210-12, 240-24, DIAMOND_24, 24, 24, TFT_WHITE);
}
uint8_t normal_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLeapYear(uint8_t x) {
return (x % 100 == 0? x % 400 == 0 : x % 4 == 0);
}
void enterSetDateScreen() {
clearMainUI();
updateSetDateUI();
int16_t x, y;
uint8_t key = 10;
while (true) {
waitTouchDown(x, y);
waitTouchUp(x, y);
// Cancel button.
if (X_IN_FIRST_QUARTER(x) && y > 240-32) { requested = MENU; break; }
// Time button.
if (X_IN_THIRD_QUARTER(x) && y > 240-32) { requested = SET_TIME; break; }
// OK button.
if (X_IN_FOURTH_QUARTER(x) && y > 240-32) {
RTC_Date tnow = ttgo->rtc->getDateTime();
ttgo->rtc->setDateTime(yyear, mmonth, dday, tnow.hour, tnow.minute, tnow.second);
break;
}
// + button.
if (y < 32+48) {
if (x < 80) {
yyear++;
if (dday == 29 && !isLeapYear(yyear)) { dday = 28; }
}
else if (x < 160) { mmonth++; if (mmonth > 12) { mmonth = 1; } }
else {
dday++;
if (
(isLeapYear(yyear) && mmonth == 2 && dday > 29)
|| (dday > normal_month[mmonth])
) {
dday = 1;
}
}
}
// - button.
if (y > 32+96) {
if (x < 80) { yyear--; }
else if (x < 160) { mmonth--; if (mmonth < 1) { mmonth = 12; } }
else {
dday--;
if (dday < 1) {
dday = isLeapYear(yyear) && mmonth == 2? 29 : normal_month[mmonth];
}
}
}
ttgo->tft->setCursor(0, 32+48);
ttgo->tft->setTextFont(6);
snprintf(buf, sizeof(buf), "%d%02d%02d", yyear, mmonth, dday);
ttgo->tft->print(buf);
}
leave:
clearMainUI();
}
#endif