-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherikaType.cpp
More file actions
172 lines (139 loc) · 5.57 KB
/
erikaType.cpp
File metadata and controls
172 lines (139 loc) · 5.57 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "erikaType.h"
#define DARKMODE false
const uint8_t BATTERY_SEGMENT_WIDTH = 7;
const uint8_t BATTERY_SEGMENT_HEIGHT = 11;
const uint8_t BATTERY_SEGMENT_SPACING = 9;
const uint8_t WEATHER_ICON_WIDTH = 48;
const uint8_t WEATHER_ICON_HEIGHT = 32;
#define TOP_LINE_Y 70
#define BOTTOM_LINE_Y 130
#define ICON_X 40
#define FONT1_FOR_BOTTOM Erika_Type_B12pt7b
#define FONT1_FOR_BOTTOM_SIZE 12
#define FONT2_FOR_BOTTOM Erika_Type_B10pt7b
#define FONT2_FOR_BOTTOM_SIZE 10
#define FONT1_FOR_TOP Erika_Type_B20pt7b
#define FONT1_FOR_TOP_SIZE 32
#define FONT2_FOR_TOP Erika_Type_B10pt7b
#define FONT2_FOR_TOP_SIZE 10
#define FONT_FOR_CENTER Erika_Type_B30pt7b
#define FONT_FOR_CENTER_SIZE 30
void erikaType::drawWatchFace(){
display.fillScreen(DARKMODE ? GxEPD_BLACK : GxEPD_WHITE);
display.setTextColor(DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
drawTime();
drawDate();
drawSteps();
drawWeather();
drawBattery();
display.drawBitmap(200-26-5,200-18-5, WIFI_CONFIGURED ? wifi : wifioff, 26, 18, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
if(BLE_CONFIGURED){
display.drawBitmap(ICON_X, BOTTOM_LINE_Y+10, bluetooth, 13, 21, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
display.drawLine(0,TOP_LINE_Y,200,TOP_LINE_Y,DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.drawLine(0,BOTTOM_LINE_Y,200,BOTTOM_LINE_Y,DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.drawLine(100,0,100,TOP_LINE_Y,DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.drawLine(100,BOTTOM_LINE_Y,100,200,DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
void erikaType::drawTime(){
display.setFont(&FONT_FOR_CENTER);
display.setCursor(5, 100+(FONT_FOR_CENTER_SIZE/2));
int displayHour;
if(HOUR_12_24==12){
displayHour = ((currentTime.Hour+11)%12)+1;
} else {
displayHour = currentTime.Hour;
}
if(displayHour < 10){
display.print(" ");
}
display.print(displayHour);
display.print(":");
if(currentTime.Minute < 10){
display.print("0");
}
display.println(currentTime.Minute);
}
void erikaType::drawDate(){
display.setFont(&FONT1_FOR_BOTTOM);
int16_t x1, y1;
uint16_t w, h;
String dayOfWeek = dayShortStr(currentTime.Wday);
display.getTextBounds(dayOfWeek,0, 0, &x1, &y1, &w, &h);
display.setCursor(110, BOTTOM_LINE_Y+FONT1_FOR_BOTTOM_SIZE+10);
display.println(dayOfWeek);
display.setCursor(110+w, BOTTOM_LINE_Y+FONT1_FOR_BOTTOM_SIZE+10);
display.println(currentTime.Day);
display.setFont(&FONT2_FOR_BOTTOM);
String month = monthShortStr(currentTime.Month);
display.setCursor(110, BOTTOM_LINE_Y+2*FONT1_FOR_BOTTOM_SIZE+20);
display.println(month);
}
void erikaType::drawSteps(){
display.setFont(&FONT1_FOR_TOP);
// reset step counter at midnight
if (currentTime.Hour == 0 && currentTime.Minute == 0){
sensor.resetStepCounter();
}
uint32_t stepCount = sensor.getCounter();
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(String(stepCount), 0, 0, &x1, &y1, &w, &h);
display.setCursor(100-10-w, TOP_LINE_Y-8);
display.println(stepCount);
display.setFont(&FONT2_FOR_TOP);
display.getTextBounds(String("Steps"),0, 0, &x1, &y1, &w, &h);
display.setCursor(100-10-w, TOP_LINE_Y-8-FONT1_FOR_TOP_SIZE-10);
display.println("Steps");
}
void erikaType::drawBattery(){
int8_t batteryLevel = 0;
float VBAT = getBatteryVoltage();
if (VBAT >= 3.3) {
batteryLevel = 100.0*(VBAT-3.3)/0.9;
}
int16_t x1, y1;
uint16_t w, h;
String batt(String(batteryLevel)+"%");
display.setFont(&FONT1_FOR_BOTTOM);
display.getTextBounds(batt,0, 0, &x1, &y1, &w, &h);
display.setCursor(100-10-w, BOTTOM_LINE_Y+FONT1_FOR_BOTTOM_SIZE+10);
display.println(batt);
display.setFont(&FONT2_FOR_BOTTOM);
display.getTextBounds(String("Batt"),0, 0, &x1, &y1, &w, &h);
display.setCursor(100-10-w, BOTTOM_LINE_Y+2*FONT1_FOR_BOTTOM_SIZE+20);
display.println("Batt");
}
void erikaType::drawWeather(){
weatherData currentWeather = getWeatherData();
int8_t temperature = currentWeather.temperature;
int16_t weatherConditionCode = currentWeather.weatherConditionCode;
const unsigned char* weatherIcon = 0;
//https://openweathermap.org/weather-conditions
if(weatherConditionCode > 801){//Cloudy
weatherIcon = cloudy;
}else if(weatherConditionCode == 801){//Few Clouds
weatherIcon = cloudsun;
}else if(weatherConditionCode == 800){//Clear
weatherIcon = sunny;
}else if(weatherConditionCode >=700){//Atmosphere
weatherIcon = atmosphere;
}else if(weatherConditionCode >=600){//Snow
weatherIcon = snow;
}else if(weatherConditionCode >=500){//Rain
weatherIcon = rain;
}else if(weatherConditionCode >=300){//Drizzle
weatherIcon = drizzle;
}else if(weatherConditionCode >=200){//Thunderstorm
weatherIcon = thunderstorm;
}
if (weatherIcon)
display.drawBitmap(200-WEATHER_ICON_WIDTH, 5, weatherIcon, WEATHER_ICON_WIDTH, WEATHER_ICON_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
int16_t x1, y1;
uint16_t w, h;
display.setFont(&FONT1_FOR_TOP);
display.getTextBounds(String(temperature),0, 0, &x1, &y1, &w, &h);
display.setCursor(110, TOP_LINE_Y-8);
display.println(temperature);
display.drawBitmap(110+w+4, TOP_LINE_Y-FONT1_FOR_TOP_SIZE, currentWeather.isMetric ? celsius : fahrenheit, 26, 20, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}