-
Notifications
You must be signed in to change notification settings - Fork 0
/
displayTime.ino
127 lines (111 loc) · 4.48 KB
/
displayTime.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
// An advanced Time Display
// This is a drop-in replacement for the displayTime()
// In the original Instructable. s such, it redraws GUI
// every minute so you will see a little flicker.
#include <esp_sleep.h>
void displayTime(boolean fullUpdate) {
ttgo->power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
//bool irq = false;
// Get the current date
RTC_Date tnow = ttgo->rtc->getDateTime();
hh = tnow.hour;
mm = tnow.minute;
ss = tnow.second;
dday = tnow.day;
mmonth = tnow.month;
yyear = tnow.year;
ttgo->tft->setTextSize(1);
if (fullUpdate) {
//Draw the back graphics - Top of display
ttgo->tft->fillScreen(TFT_BLACK);
ttgo->tft->fillRoundRect(0, 0, 239, 120, 40, TFT_PURPLE);
ttgo->tft->fillRoundRect(40, 20, 196, 80, 20, TFT_BLACK);
ttgo->tft->fillRect(80, 20, 159, 80, TFT_BLACK);
ttgo->tft->fillRect(170, 0, 45, 20, TFT_BLACK);
ttgo->tft->fillRect(110, 0, 4, 20, TFT_BLACK);
ttgo->tft->fillRect(0, 45, 50, 7, TFT_BLACK);
ttgo->tft->fillRect(0, 70, 50, 7, TFT_BLACK);
ttgo->tft->fillRect(215, 0, 24, 20, TFT_DARKCYAN);
//Draw the back graphics - Bottom of display
ttgo->tft->fillRoundRect(0, 130, 239, 109, 40, TFT_MAROON);
ttgo->tft->fillRoundRect(40, 150, 199, 88, 20, TFT_BLACK);
ttgo->tft->fillRect(0, 179, 50, 10, TFT_BLACK);
ttgo->tft->fillRect(100, 160, 40, 10, TFT_YELLOW);
ttgo->tft->fillRect(140, 160, 40, 10, TFT_DARKGREEN);
ttgo->tft->fillRect(180, 160, 40, 10, TFT_RED);
ttgo->tft->setTextColor(TFT_WHITE, TFT_BLACK);
ttgo->tft->drawString("Temp", 66, 158, 2);
ttgo->tft->fillRoundRect(119, 210, 120, 29, 15, TFT_DARKCYAN);
// Display Temp Marker - you may need to adjust the x value based on your normal ADC results
float temp = ttgo->power->getTemp();
ttgo->tft->fillRoundRect(int(temp) + 124, 160, 10, 20, 5, TFT_WHITE);
// Display Time
// Font 7 is a 7-seg display but only contains
// characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
ttgo->tft->setTextColor(0xFBE0, TFT_BLACK);
int xpos = 55;
if (hh < 10) xpos += ttgo->tft->drawChar('0', xpos, 35, 7);
xpos += ttgo->tft->drawNumber(hh, xpos, 35, 7);
xpos += 3;
xpos += ttgo->tft->drawChar(':', xpos, 35, 7);
if (mm < 10) xpos += ttgo->tft->drawChar('0', xpos, 35, 7);
ttgo->tft->drawNumber(mm, xpos, 35, 7);
// Display Battery Level
ttgo->tft->setTextSize(1);
ttgo->tft->setTextColor(TFT_YELLOW);
ttgo->tft->drawString("Power", 124, 2, 2);
ttgo->tft->setTextColor(TFT_GREEN);
int per = ttgo->power->getBattPercentage();
per = ttgo->power->getBattPercentage();
ttgo->tft->drawString(String(per) + "%", 179, 2, 2);
ttgo->tft->setTextColor(TFT_GREENYELLOW);
ttgo->tft->drawString(String(dday), 50, 188, 6);
// Turn off the battery adc <-- WHY!!!!
ttgo->power->adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false);
// Draw Month
char mStr[4] = {"\0"};
switch (mmonth) {
case 1: strcat(mStr, "Jan"); break;
case 2: strcat(mStr, "Feb"); break;
case 3: strcat(mStr, "Mar"); break;
case 4: strcat(mStr, "Apr"); break;
case 5: strcat(mStr, "May"); break;
case 6: strcat(mStr, "Jun"); break;
case 7: strcat(mStr, "Jul"); break;
case 8: strcat(mStr, "Aug"); break;
case 9: strcat(mStr, "Sep"); break;
case 10: strcat(mStr, "Oct"); break;
case 11: strcat(mStr, "Nov"); break;
case 12: strcat(mStr, "Dec"); break;
}
ttgo->tft->setTextColor(TFT_WHITE);
ttgo->tft->drawString(mStr, 9, 194, 2);
}
// Build a bargraph for 10 seconds...
// makinkg sure to show at least 1 complete cycle.
//count = 0;
rs = tnow.second;
int secmod = rs % 10; // Show growing bar for 10 seconds
if (secmod) {
ttgo->tft->fillRect(126 + secmod * 10, 215, 6, 15, TFT_ORANGE);
} else {
ttgo->tft->fillRoundRect(119, 210, 120, 29, 15, TFT_DARKCYAN);
count = count + 1;
}
if (count > disptime) {
count = 0;
ttgo->displaySleep();
WiFi.mode(WIFI_OFF);
//setCpuFrequencyMhz(20);
ttgo->power->enableIRQ(AXP202_PEK_SHORTPRESS_IRQ, true);
ttgo->power->setPowerOutPut(AXP202_LDO2, false);
ttgo->power->enableIRQ(AXP202_PEK_SHORTPRESS_IRQ, true);
ttgo->power->clearIRQ();
esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
count = 0;
//ttgo->powerOff();
esp_deep_sleep_start();
} else {
count = count + 1;
}
}