-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEPDisplay.h
218 lines (176 loc) · 6.2 KB
/
EPDisplay.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// EPaper setup
#include <GxEPD.h>
#include <GxGDEH0154D67/GxGDEH0154D67.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
#define EPD_RST_PIN 21
#define EPD_BUSY_PIN 20
#define EPD_DC_PIN 22
#define EPD_CS_PIN 23
GxIO_Class io(SPI, EPD_CS_PIN, EPD_DC_PIN, EPD_RST_PIN);
GxEPD_Class display(io, EPD_RST_PIN, EPD_BUSY_PIN);
typedef struct {
uint16_t co2 = 0;
float temperature = 0;
uint8_t humidity = 0;
bool lowbatt = false;
} DisplayDataType;
DisplayDataType DisplayData;
void MeasurementsDisplay()
// uint16_t co2, float temperature, uint8_t humidity
{
int16_t tbx, tby;
uint16_t tbw, tbh, x, y;
String strco2 = String(DisplayData.co2, DEC);
String strtemp = String(DisplayData.temperature, 1);
String strhum = String(DisplayData.humidity, DEC);
String strstatic = "";
display.setRotation(1);
display.setTextColor(GxEPD_BLACK);
display.fillScreen(GxEPD_BLACK);
display.fillRect(2,2,196,196,GxEPD_WHITE);
display.fillRect(0,99,200,2,GxEPD_BLACK);
display.fillRect(99,100,2,100,GxEPD_BLACK);
strstatic = "ppm CO2";
display.setFont(&FreeMonoBold12pt7b);
display.getTextBounds(strstatic, 0, 0, &tbx, &tby, &tbw, &tbh);
//DPRINT("TEXTBOX: x="); DPRINT(tbx); DPRINT(" y="); DPRINT(tby); DPRINT(" w="); DPRINT(tbw); DPRINT(" h="); DPRINTLN(tbh);
x = display.width() - tbw - tbx - 10 ;
y = display.height() / 2 - tbh - tby - 10;
display.setCursor(x, y);
strstatic = "ppm CO";
display.print(strstatic);
x = display.getCursorX();
y = display.getCursorY() + 5;
display.setCursor(x, y);
display.setFont(&FreeMonoBold9pt7b);
display.print("2");
strstatic = "oC";
display.setFont(&FreeMonoBold12pt7b);
display.getTextBounds(strstatic, 0, 0, &tbx, &tby, &tbw, &tbh);
x = display.width() / 2 - tbw - tbx - 10 ;
y = display.height() / 2 - tbh - tby - 10 + display.height() / 2;
display.setCursor(x, y - 5);
display.setFont(&FreeMonoBold9pt7b);
display.print("o");
x = display.getCursorX();
display.setCursor(x, y);
display.setFont(&FreeMonoBold12pt7b);
display.print("C");
strstatic = "%rH";
display.setFont(&FreeMonoBold12pt7b);
display.getTextBounds(strstatic, 0, 0, &tbx, &tby, &tbw, &tbh);
x = display.width() / 2 - tbw - tbx - 10 + display.width() / 2;
display.setCursor(x, y);
display.print(strstatic);
display.setFont(&FreeMonoBold24pt7b);
display.getTextBounds(strco2, 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
x = ((display.width() - tbw) / 2) - tbx;
y = ((display.height() / 2 - tbh) / 2) - tby - display.height() / 20;
display.setCursor(x, y);
display.print(strco2);
display.setFont(&FreeMonoBold18pt7b);
display.getTextBounds(strtemp, 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
x = ((display.width() / 2 - tbw) / 2) - tbx;
y = ((display.height() / 2 - tbh) / 2) - tby + display.height() / 2 - display.height() / 40;
display.setCursor(x, y);
display.print(strtemp);
display.getTextBounds(strhum, 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
x = ((display.width() / 2 - tbw) / 2) - tbx + display.width() / 2;
//y = ((display.height() / 2 - tbh) / 2) - tby + display.height() / 2;
display.setCursor(x, y);
display.print(strhum);
if (DisplayData.lowbatt)
{
display.drawRect(15,25,11,5,GxEPD_BLACK);
display.drawRect(10,30,20,30,GxEPD_BLACK);
display.fillRect(10,60,20,10,GxEPD_BLACK);
}
}
void EmptyBattDisplay()
{
int16_t tbx, tby;
uint16_t tbw, tbh, x, y;
String strstatic = "";
DPRINTLN("Empty batt display");
display.setRotation(1);
display.setTextColor(GxEPD_BLACK);
display.fillScreen(GxEPD_BLACK);
display.fillRect(2,2,196,196,GxEPD_WHITE);
display.drawRect(50,30,90,30,GxEPD_BLACK);
display.drawRect(140,35,10,20,GxEPD_BLACK);
display.drawLine(70,80,120,10,GxEPD_BLACK);
display.setFont(&FreeMonoBold12pt7b);
strstatic = "Connect";
display.getTextBounds(strstatic, 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
x = ((display.width() - tbw) / 2) - tbx;
y = ((display.height() - tbh) / 2) - tby + display.height() / 4 - 12;
display.setCursor(x, y);
display.print(strstatic);
strstatic = "USB Charger!";
display.getTextBounds(strstatic, 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
x = ((display.width() - tbw) / 2) - tbx;
y = ((display.height() - tbh) / 2) - tby + display.height() / 4 + 12;
display.setCursor(x, y);
display.print(strstatic);
}
// all library classes are placed in the namespace 'as'
using namespace as;
class ePaperType : public Alarm {
private:
bool mUpdateDisplay;
bool shMeasurementsDisplay;
bool shEmptyBattDisplay;
public:
ePaperType () : Alarm(0), mUpdateDisplay(false), shEmptyBattDisplay(false) {}
virtual ~ePaperType () {}
bool showEmptyBattDisplay() {
return shEmptyBattDisplay;
}
void showEmptyBattDisplay(bool s) {
shEmptyBattDisplay = s;
}
bool mustUpdateDisplay() {
return mUpdateDisplay;
}
void mustUpdateDisplay(bool m) {
mUpdateDisplay = m;
}
void init() {
/*
u8g2Fonts.begin(display);
u8g2Fonts.setFontMode(1);
u8g2Fonts.setFontDirection(0);
*/
}
void setRefreshAlarm (uint32_t t) {
//isWaiting(true);
sysclock.cancel(*this);
Alarm::set(millis2ticks(t));
sysclock.add(*this);
}
virtual void trigger (__attribute__((unused)) AlarmClock& clock) {
DPRINTLN("ePaper refresh triggered");
if (this->mustUpdateDisplay()) {
this->mustUpdateDisplay(false);
display.init();
if (this->showEmptyBattDisplay() == true ) {
display.drawPaged(EmptyBattDisplay);
this->showEmptyBattDisplay(false);
}
else {
display.drawPaged(MeasurementsDisplay);
}
pinMode(EPD_RST_PIN,INPUT); //fix current into reset pin in v2 of Waveshare display
}
}
};