-
Notifications
You must be signed in to change notification settings - Fork 1
/
skully.cpp
151 lines (127 loc) · 4.2 KB
/
skully.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "skully.h"
void Skully::drawWatchFace() {
display.fillScreen(GxEPD_BLACK);
display.drawBitmap(0, 0, pirate, 200, 200, GxEPD_WHITE);
drawTime();
drawWDay();
drawDate();
drawSteps();
drawBattery();
//drawTemperature();
for (uint8_t i=0; i<3; i++) {
// Reduce ghosting
display.display(true);
}
}
void Skully::drawTime() {
display.setFont(&GorgeousPixel30pt7b);
display.setTextColor(GxEPD_WHITE);
int16_t xh1, yh1;
uint16_t wh1, hh1;
int16_t xh2, yh2;
uint16_t wh2, hh2;
int16_t xm1, ym1;
uint16_t wm1, hm1;
int16_t xm2, ym2;
uint16_t wm2, hm2;
String h = String(currentTime.Hour);
String m = String(currentTime.Minute);
String h1 = String(h.substring(0,1));
String h2 = String(h.substring(1,2));
String m1 = String(m.substring(0,1));
String m2 = String(m.substring(1,2));
display.getTextBounds(String(h1), 0, 0, &xh1, &yh1, &wh1, &hh1);
display.getTextBounds(String(h2), 0, 0, &xh2, &yh2, &wh2, &hh2);
display.getTextBounds(String(m1), 0, 0, &xm1, &ym1, &wm1, &hm1);
display.getTextBounds(String(m2), 0, 0, &xm2, &ym2, &wm2, &hm2);
display.setCursor(142 - wh1/2, 144);
if (currentTime.Hour < 10) {
display.print("0");
display.setCursor(174 - wh1/2, 144);
display.print(String(h1));
} else {
display.print(String(h1));
display.setCursor(174 - wh2/2, 144);
display.print(String(h2));
}
display.setCursor(142 - wm1/2, 192);
if (currentTime.Minute < 10) {
display.print("0");
display.setCursor(174 - wm1/2, 192);
display.print(String(m1));
} else {
display.print(String(m1));
display.setCursor(174 - wm2/2, 192);
display.print(String(m2));
}
}
void Skully::drawWDay() {
display.setFont(&GorgeousPixel11pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t x1, y1;
uint16_t w, h;
String dayOfWeek = dayShortStr(currentTime.Wday);
dayOfWeek.toUpperCase();
display.getTextBounds(String(dayOfWeek), 0, 0, &x1, &y1, &w, &h);
display.fillRect(186 - w, 50, w + 8, h + 5, GxEPD_WHITE);
display.setCursor(189 - w, 68);
display.println(String(dayOfWeek));
}
void Skully::drawDate() {
display.setFont(&GorgeousPixel9pt7b);
display.setTextColor(GxEPD_WHITE);
display.setCursor(4, 195);
String monthStr = String(currentTime.Month);
String dayStr = String(currentTime.Day);
monthStr = currentTime.Month < 10 ? "0" + monthStr : monthStr;
dayStr = currentTime.Day < 10 ? "0" + dayStr : dayStr;
String dateStr = dayStr + "." + monthStr;
display.print(String(dateStr));
}
void Skully::drawSteps() {
display.setFont(&GorgeousPixel9pt7b);
display.setTextColor(GxEPD_WHITE);
int16_t x1, y1;
uint16_t w, h;
if (currentTime.Hour == 23 && currentTime.Minute == 59) {
sensor.resetStepCounter();
}
uint32_t stepCount = sensor.getCounter();
char stepStr[32];
itoa(stepCount, stepStr, 10);
int stepStrL = strlen(stepStr);
memset(stepStr, '0', 5);
itoa(stepCount, stepStr + max(5-stepStrL, 0), 10);
display.getTextBounds(String(stepStr), 0, 0, &x1, &y1, &w, &h);
display.drawRect(186 - w, 71, w + 8, h + 8, GxEPD_WHITE);
display.setCursor(189 - w, 87);
display.println(stepStr);
}
void Skully::drawBattery() {
float BATTV = getBatteryVoltage() - 3.60;
int batt_w = constrain(((33.33 * BATTV) + 0.9), 0, 20);
display.fillRect(166, 5, 28, 12, GxEPD_WHITE);
display.fillRect(163, 9, 3, 4, GxEPD_WHITE);
display.fillRect(168, 7, 24, 8, GxEPD_BLACK);
if (BATTV > 0) {
display.fillRect(190 - batt_w, 9, batt_w, 4, GxEPD_WHITE);
}
}
void Skully::drawTemperature() {
display.setFont(&GorgeousPixel8pt7b);
display.setTextColor(GxEPD_WHITE);
display.setCursor(4, 179);
uint8_t temperatureRTC = RTC.temperature() / 4;
if (settings.weatherUnit == "imperial") {
temperatureRTC = temperatureRTC * (9/5) + 32;
}
if (temperatureRTC < 10) {
display.print("0");
}
display.print(temperatureRTC);
if (settings.weatherUnit == "imperial") {
display.print("f");
} else {
display.print("c");
}
}