-
Notifications
You must be signed in to change notification settings - Fork 0
/
EpaperDevice.cpp
217 lines (181 loc) · 6.62 KB
/
EpaperDevice.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
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
#include "EpaperDevice.h"
#include <Arduino.h>
#define LOGGING 1 // delete this line to turn logging off
#define COLORED 0
#define UNCOLORED 1
EpaperDevice::EpaperDevice(GpsDevice& gpsDevice, BMP180Device& bmp180Device) :
paint(image, 0, 0),
gpsDevice(gpsDevice),
bmp180Device(bmp180Device)
{ }
EpaperDevice::~EpaperDevice()
{ }
void EpaperDevice::init()
{
logmsg("initializing screen...");
if (epd.Init(lut_full_update) != 0) {
logmsg("e-Paper init failed");
return;
}
/**
* there are 2 memory areas embedded in the e-paper display
* and once the display is refreshed, the memory area will be auto-toggled,
* i.e. the next action of SetFrameMemory will set the other memory area
* therefore you have to clear the frame memory twice.
*/
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF); // bit set = white, bit reset = black
epd.DisplayFrame();
paint.SetRotate(ROTATE_0);
paint.SetWidth(200);
paint.SetHeight(24);
paint.Clear(COLORED);
paint.DrawStringAt(30, 4, "HIKING", &Font16, UNCOLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 10, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(30, 4, "data logger", &Font16, COLORED);
epd.SetFrameMemory(paint.GetImage(), 0, 30, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
delay(1000);
if (epd.Init(lut_partial_update) != 0) {
logmsg("e-Paper init failed");
return;
}
logmsg("blinking screen twice to clear away potential artifacts");
epd.ClearFrameMemory(0x00);
epd.DisplayFrame();
epd.ClearFrameMemory(0x00);
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF);
epd.DisplayFrame();
epd.ClearFrameMemory(0xFF);
epd.DisplayFrame();
// calling twice to set these on both eink framebuffers
// the screen auto-toggles between each framebuffers with each call to epd.DisplayFrame()
// we want the units and labels to be on both framebuffers so they show at all times.
logmsg("drawing labels");
drawLabels();
drawLabels();
logmsg("drawing units");
drawUnits();
drawUnits();
logmsg("drawing data");
drawData();
drawData();
logmsg("screen initialization complete.");
}
void EpaperDevice::drawUnits()
{
paint.SetWidth(28);
paint.SetHeight(30);
paint.SetRotate(ROTATE_270);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, altUnit, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 60, 7, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, tmpUnit, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 80, 7, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, prsUnit, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 110, 7, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
}
void EpaperDevice::drawLabels()
{
paint.SetWidth(28);
paint.SetHeight(45);
paint.SetRotate(ROTATE_270);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, latLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 15, 154, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, lonLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 35, 154, paint.GetWidth(), paint.GetHeight());
paint.SetWidth(28);
paint.SetHeight(55);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, altLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 60, 143, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, tmpLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 80, 143, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, prsLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 110, 143, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, dirLabel, &Font20, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 130, 143, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
}
void EpaperDevice::drawData()
{
paint.SetWidth(22);
paint.SetHeight(155);
paint.SetRotate(ROTATE_270);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, latData, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 15, 0, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, lonData, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 35, 0, paint.GetWidth(), paint.GetHeight());
paint.SetWidth(28);
paint.SetHeight(105);
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, altData, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 60, 38, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, tmpData, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 80, 38, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, prsData, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 110, 38, paint.GetWidth(), paint.GetHeight());
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, dir_data, &Font24, COLORED);
// y offset, x offset
epd.SetFrameMemory(paint.GetImage(), 130, 38, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
}
void EpaperDevice::fetchLat() {
gpsDevice.getLatitude().toCharArray(latData, 10);
logmsg("Fetched latitude of " + String(latData) + " from gps.");
}
void EpaperDevice::fetchLon() {
gpsDevice.getLongitude().toCharArray(lonData, 10);
logmsg("Fetched longitude of " + String(lonData) + " from gps.");
}
void EpaperDevice::fetchAlt() {
//gpsDevice.getAltitudeFeet().toCharArray(altData, 6);
//logmsg("Fetched altitude of " + String(altData) + " ft from gps.");
bmp180Device.getDisplayableAltitudeFt().toCharArray(altData, 6);
logmsg("Fetched altitude of " + String(altData) + " ft from bmp180.");
}
void EpaperDevice::fetchTmp() {
bmp180Device.getDisplayableTemperatureF().toCharArray(tmpData, 5);
logmsg("Fetched temperature of " + String(tmpData) + "F from from bmp180.");
}
void EpaperDevice::fetchPrs() {
bmp180Device.getDisplayablePressureMb().toCharArray(prsData, 7);
logmsg("Fetched pressure of " + String(prsData) + "mb from from bmp180.");
}
void EpaperDevice::fetchDir() {
}
void EpaperDevice::logmsg(String msg) {
#ifdef LOGGING
Serial.println(classname + " " + msg);
#endif
}