-
Notifications
You must be signed in to change notification settings - Fork 1
/
beastie.cpp
142 lines (112 loc) · 3.52 KB
/
beastie.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
#include "beastie.h"
void Beastie::drawWatchFace() {
display.fillScreen(GxEPD_BLACK);
display.drawBitmap(0, 0, daemon_img, 200, 200, GxEPD_WHITE);
drawX();
drawWDay();
drawDate();
drawTime();
drawSteps();
drawBattery();
//drawTemperature();
for (uint8_t i=0; i<3; i++) {
// Reduce ghosting
display.display(true);
}
}
void Beastie::drawWDay() {
display.setFont(&conso10pt7b);
display.setTextColor(GxEPD_WHITE);
int16_t x1, y1;
uint16_t w, h;
String dayOfWeek = dayShortStr(currentTime.Wday);
display.getTextBounds(String(dayOfWeek), 0, 0, &x1, &y1, &w, &h);
display.setCursor(151 - w/2, 67);
display.println(String(dayOfWeek));
}
void Beastie::drawDate() {
display.setFont(&conso12pt7b);
display.setTextColor(GxEPD_WHITE);
int16_t x1, y1;
uint16_t w, h;
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.getTextBounds(String(dateStr), 0, 0, &x1, &y1, &w, &h);
display.setCursor(151 - w/2, 88);
display.println(String(dateStr));
}
void Beastie::drawTime() {
display.setFont(&conso17pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(111, 119);
display.fillRoundRect(111, 95, 85, 29, 4, GxEPD_WHITE);
if (currentTime.Hour < 10) {
display.print("0");
}
display.print(currentTime.Hour);
display.print(":");
if (currentTime.Minute < 10) {
display.print("0");
}
display.print(currentTime.Minute);
}
void Beastie::drawSteps() {
display.setFont(&conso11pt7b);
display.setTextColor(GxEPD_WHITE);
if (currentTime.Hour == 23 && currentTime.Minute == 59) {
sensor.resetStepCounter();
}
int16_t x1, y1;
uint16_t w, h;
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.setCursor(152 - w/2, 143);
display.println(String(stepStr));
}
void Beastie::drawTemperature() {
display.setFont(&conso10pt7b);
display.setTextColor(GxEPD_WHITE);
display.setCursor(4, 18);
uint8_t temperatureRTC = RTC.temperature() / 4;
if (settings.weatherUnit == "imperial") {
temperatureRTC = temperatureRTC * (9/5) + 32;
}
if (temperatureRTC < 10) {
display.print("0");
}
display.print(temperatureRTC);
display.setCursor(22, 11);
display.print(".");
display.setCursor(29, 16);
if (settings.weatherUnit == "imperial") {
display.print("f");
} else {
display.print("c");
}
}
void Beastie::drawBattery() {
float BATTV = getBatteryVoltage() - 3.60;
int batt_w = constrain(((33.33 * BATTV) + 0.9), 0, 20);
display.fillRoundRect(138, 150, 30, 10, 5, GxEPD_WHITE);
display.fillRoundRect(140, 152, 26, 6, 4, GxEPD_BLACK);
if (BATTV > 0) {
if (batt_w % 2 != 0) {
display.fillRoundRect(153 - (batt_w/2)-1, 154, batt_w, 2, 3, GxEPD_WHITE);
}
display.fillRoundRect(153 - batt_w/2, 154, batt_w, 2, 3, GxEPD_WHITE);
}
}
void Beastie::drawX() {
display.setFont(&conso11pt7b);
display.setTextColor(GxEPD_WHITE);
display.setCursor(149, 50);
display.print("x");
}