-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.h
173 lines (160 loc) · 7.32 KB
/
display.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
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
173
#include "icons/01d-sun.h"
#include "icons/02d-sun.h"
#include "icons/02d-cloud.h"
#include "icons/03d-cloud.h"
#include "icons/04d-cloud.h"
#include "icons/04d-cloud-back.h"
#include "icons/09d-cloud.h"
#include "icons/09d-rain.h"
#include "icons/10d-cloud.h"
#include "icons/10d-sun.h"
#include "icons/11d-cloud.h"
#include "icons/11d-lightning.h"
#include "icons/13d-snow.h"
#include "icons/50d-fog.h"
#include "Fonts/Cantarell_Regular_euro8pt8b.h"
#include "Fonts/Cantarell_Bold_euro9pt8b.h"
#include "Fonts/FreeMonoBold_euro14pt8b.h"
#include "Fonts/Cantarell_Bold_euro16pt8b.h"
#define FONT_TINY Cantarell_Regular_euro8pt8b
#define FONT_SMALL Cantarell_Bold_euro9pt8b
#define FONT_NORMAL FreeMonoBold_euro14pt8b
#define FONT_BIG Cantarell_Bold_euro16pt8b
void drawTinyTextRightAlign(int x, int y, char* text, int color) {
display.setFont(&FONT_TINY);
display.setTextColor(color);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
display.setCursor(x - tbw, y);
display.println(text);
}
void drawSmallTextCenterAlign(int x, int y, char* text, int color) {
display.setFont(&FONT_SMALL);
display.setTextColor(color);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
display.setCursor(x - (tbw / 2), y);
display.println(text);
}
void drawTextCenterAlign(int x, int y, char* text, int color) {
display.setFont(&FONT_NORMAL);
display.setTextColor(color);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
display.setCursor(x - (tbw / 2), y);
display.println(text);
}
void drawBigTextCenterAlign(int x, int y, char* text) {
display.setFont(&FONT_BIG);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
display.setCursor(x - (tbw / 2), y);
display.println(text);
}
void drawIcon(int x, int y, char* icon) {
if (strcmp(icon, "01d") == 0) {
// 01d - Sun
display.drawBitmap(x, y, icon_01d_sun_bits, icon_01d_sun_width, icon_01d_sun_height, GxEPD_RED);
} else if (strcmp(icon, "01n") == 0) {
// 01d - Sun - night
display.drawBitmap(x, y, icon_01d_sun_bits, icon_01d_sun_width, icon_01d_sun_height, GxEPD_BLACK);
} else if (strcmp(icon, "02d") == 0) {
// 02d - Cloud, sun
display.drawBitmap(x, y, icon_02d_sun_bits, icon_02d_sun_width, icon_02d_sun_height, GxEPD_RED);
display.drawBitmap(x, y, icon_02d_cloud_bits, icon_02d_cloud_width, icon_02d_cloud_height, GxEPD_BLACK);
} else if (strcmp(icon, "02n") == 0) {
// 02d - Cloud, sun - night
display.drawBitmap(x, y, icon_02d_sun_bits, icon_02d_sun_width, icon_02d_sun_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_02d_cloud_bits, icon_02d_cloud_width, icon_02d_cloud_height, GxEPD_BLACK);
} else if (strcmp(icon, "03d") == 0 || strcmp(icon, "03n") == 0) {
// 03d - Cloud
display.drawBitmap(x, y, icon_03d_cloud_bits, icon_03d_cloud_width, icon_03d_cloud_height, GxEPD_BLACK);
} else if (strcmp(icon, "04d") == 0) {
// 04d - Cloud, second cloud
display.drawBitmap(x, y, icon_04d_cloud_bits, icon_04d_cloud_width, icon_04d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_04d_cloud_back_bits, icon_04d_cloud_back_width, icon_04d_cloud_back_height, GxEPD_RED);
} else if (strcmp(icon, "04n") == 0) {
// 04d - Cloud, second cloud - night
display.drawBitmap(x, y, icon_04d_cloud_bits, icon_04d_cloud_width, icon_04d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_04d_cloud_back_bits, icon_04d_cloud_back_width, icon_04d_cloud_back_height, GxEPD_BLACK);
} else if (strcmp(icon, "09d") == 0) {
// 09d - Clouds, rain
display.drawBitmap(x, y, icon_09d_cloud_bits, icon_09d_cloud_width, icon_09d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_09d_rain_bits, icon_09d_rain_width, icon_09d_rain_height, GxEPD_BLACK);
} else if (strcmp(icon, "09n") == 0) {
// 09d - Clouds, rain - night
display.drawBitmap(x, y, icon_09d_cloud_bits, icon_09d_cloud_width, icon_09d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_09d_rain_bits, icon_09d_rain_width, icon_09d_rain_height, GxEPD_BLACK);
} else if (strcmp(icon, "10d") == 0) {
// 10d - Clouds, sun, rain
display.drawBitmap(x, y, icon_10d_cloud_bits, icon_10d_cloud_width, icon_10d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_10d_sun_bits, icon_10d_sun_width, icon_10d_sun_height, GxEPD_BLACK);
} else if (strcmp(icon, "10n") == 0) {
// 10d - Clouds, sun, rain - night
display.drawBitmap(x, y, icon_10d_cloud_bits, icon_10d_cloud_width, icon_10d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_10d_sun_bits, icon_10d_sun_width, icon_10d_sun_height, GxEPD_BLACK);
} else if (strcmp(icon, "11d") == 0) {
// 11d - Clouds, lightning
display.drawBitmap(x, y, icon_11d_cloud_bits, icon_11d_cloud_width, icon_11d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_11d_ligthning_bits, icon_11d_ligthning_width, icon_11d_ligthning_height, GxEPD_RED);
} else if (strcmp(icon, "11n") == 0) {
// 11d - Clouds, lightning - night
display.drawBitmap(x, y, icon_11d_cloud_bits, icon_11d_cloud_width, icon_11d_cloud_height, GxEPD_BLACK);
display.drawBitmap(x, y, icon_11d_ligthning_bits, icon_11d_ligthning_width, icon_11d_ligthning_height, GxEPD_BLACK);
} else if (strcmp(icon, "13d") == 0 || strcmp(icon, "13n") == 0) {
// 13d - Snow
display.drawBitmap(x, y, icon_13d_snow_bits, icon_13d_snow_width, icon_13d_snow_height, GxEPD_BLACK);
} else if (strcmp(icon, "50d") == 0 ||strcmp(icon, "50n") == 0) {
// 50d - Fog
display.drawBitmap(x, y, icon_50d_fog_bits, icon_50d_fog_width, icon_50d_fog_height, GxEPD_BLACK);
}
}
void displayDayMinMax(int x, char* title, char* icon, char* temp1, char* temp2, char* humidity) {
int centerOffset = 38;
drawBigTextCenterAlign(x + centerOffset, 28, title);
drawIcon(x, 22, icon);
drawTextCenterAlign(x + centerOffset, 112, temp1, GxEPD_BLACK);
drawTextCenterAlign(x + centerOffset, 138, temp2, GxEPD_BLACK);
drawSmallTextCenterAlign(x + centerOffset, 157, humidity, GxEPD_BLACK);
}
void displayWeather(Weather* weather) {
display.fillScreen(GxEPD_WHITE);
display.firstPage();
do
{
displayDayMinMax(5, "H+1", weather->iconH1, weather->feelsLikeH1, weather->tempH1, weather->humidityH1);
displayDayMinMax(95, "J", weather->iconD, weather->tempMinD, weather->tempMaxD, weather->humidityD);
displayDayMinMax(185, "J+1", weather->iconD1, weather->tempMinD1, weather->tempMaxD1, weather->humidityD1);
drawTinyTextRightAlign(258, 173, weather->updated, GxEPD_BLACK);
} while (display.nextPage());
}
void displayLocalTemp(LocalTemp* localTemp) {
int x = 5;
int y = 100;
int w = 90;
int h = 38;
display.setPartialWindow(x, y, w, h);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
drawTextCenterAlign(x + 40, y + 24, localTemp->temp, GxEPD_BLACK);
} while (display.nextPage());
}
void displayError(char* text) {
int x = 0;
int y = display.height() - 20;
int w = display.width() / 2;
int h = 20;
display.setFont(&FONT_SMALL);
display.setTextColor(GxEPD_RED);
display.setPartialWindow(x, y, w, h);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x + 5, y + 12);
display.print(text);
} while (display.nextPage());
}