-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPages.cpp
More file actions
295 lines (266 loc) · 7.19 KB
/
Copy pathPages.cpp
File metadata and controls
295 lines (266 loc) · 7.19 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* This file is part of the Eclipse2024 project. It is subject to the GPLv3
* license terms in the LICENSE file found in the top-level directory of this
* distribution and at
* https://github.com/jjackowski/eclipse2024/blob/master/LICENSE.
* No part of the Eclipse2024 project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*
* Copyright (C) 2024 Jeff Jackowski
*/
#include "Pages.hpp"
#include "Screen.hpp"
Page::SelectionResponse ClockPage::select(
const DisplayInfo &di,
SelectionCause sc
) {
if ((sc == SelectUser) || !di.goodfix || !di.errormsg.empty()) {
return SelectPage;
}
return SkipPage;
}
void ClockPage::show(const DisplayInfo &di, Screen *scr) {
// the title is used everywhere else
scr->hideTitle();
}
void ClockPage::hide(const DisplayInfo &di, Screen *scr) { }
Page::SelectionResponse GpsPage::select(const DisplayInfo &, SelectionCause) {
return SelectPage;
}
void GpsPage::show(const DisplayInfo &di, Screen *scr) {
scr->showTitle("GPS Status");
}
void GpsPage::update(const DisplayInfo &di, Screen *scr) {
std::ostringstream oss;
if (di.goodfix) {
scr->showText("Acc", 0, 0);
oss << di.locerr << 'm';
scr->showText(oss.str(), 1, 0);
scr->showText("Sats", 2, 0);
oss.str(std::string());
oss << di.sats;
scr->showText(oss.str(), 3, 0);
oss.str(std::string());
} else {
scr->showText("No fix", 0, 0);
scr->hideText(2, 0);
scr->hideText(3, 0);
if (di.curloc.lon == 0.0) {
scr->hideText(1, 0);
return;
} else {
scr->showText(" Old pos", 1, 0);
}
}
oss << "Lon " << std::setprecision(7) << std::setw(12) << std::fixed <<
di.curloc.lon;
scr->showText(oss.str(), 0, 1);
oss.str(std::string());
oss << "Lat " << std::setprecision(7) << std::setw(12) << std::fixed <<
di.curloc.lat;
scr->showText(oss.str(), 0, 2);
}
void GpsPage::hide(const DisplayInfo &di, Screen *scr) {
scr->hideText();
}
Page::SelectionResponse EclipsePage::select(
const DisplayInfo &di,
SelectionCause sc
) {
if ((sc == SelectUser) || (
// auto-select only with position fix
di.goodfix && (
// show if out of totality, or . . .
!di.inTotality ||
// . . . if the eclipse isn't over
(di.now < (di.end + DisplayInfo::afterTotality))
)
)) {
return SelectPage;
}
return SkipPage;
}
void EclipsePage::show(const DisplayInfo &di, Screen *scr) {
scr->showTitle("Eclipse");
}
void EclipsePage::update(const DisplayInfo &di, Screen *scr) {
if (di.inTotality) {
Hms time;
int start = di.start - DisplayInfo::beforeTotality;
int end = di.end + DisplayInfo::afterTotality;
if (di.now < start) {
scr->showText("Start", 0, 0);
time.set(start + DisplayStuff::getTimeZoneOffset());
scr->showText(time.time(), 1, 0);
time.set(start - di.now);
scr->showText("Wait", 0, 1);
} else if (di.now < end) {
time.set(end - di.now);
scr->showText("Remaining", 0, 1);
} else {
scr->showText("Over", 0, 1);
scr->hideText(1, 1);
}
if (di.now < end) {
scr->showText(time.duration(), 1, 1);
}
if (di.now >= start) {
scr->showText("End", 0, 0);
time.set(end + DisplayStuff::getTimeZoneOffset());
scr->showText(time.time(), 1, 0);
}
scr->showText("Duration", 0, 2);
time.set(end - start);
scr->showText(time.duration(), 1, 2);
} else {
scr->showText("Outside totality", 0, 2);
scr->hideText(0, 0);
scr->hideText(1, 0);
scr->hideText(0, 1);
scr->hideText(1, 1);
scr->hideText(1, 2);
}
}
void EclipsePage::hide(const DisplayInfo &di, Screen *scr) {
scr->hideText();
}
Page::SelectionResponse TotalityPage::select(
const DisplayInfo &di,
SelectionCause sc
) {
if (di.inTotality && ((sc == SelectUser) || (di.now < (di.end)))) {
return SelectPage;
}
return SkipPage;
}
void TotalityPage::show(const DisplayInfo &di, Screen *scr) {
scr->showTitle("Totality");
}
void TotalityPage::update(const DisplayInfo &di, Screen *scr) {
if (di.inTotality) {
Hms time;
if (di.now < di.start) {
scr->showText("Start", 0, 0);
time.set(di.start + DisplayStuff::getTimeZoneOffset());
scr->showText(time.time(), 1, 0);
time.set(di.start - di.now);
scr->showText("Wait", 0, 1);
} else if (di.now < di.end) {
time.set(di.end - di.now);
scr->showText("Remaining", 0, 1);
} else {
scr->showText("Over", 0, 1);
scr->hideText(1, 1);
}
if (di.now < di.end) {
scr->showText(time.duration(), 1, 1);
}
if (di.now >= di.start) {
scr->showText("End", 0, 0);
time.set(di.end + DisplayStuff::getTimeZoneOffset());
scr->showText(time.time(), 1, 0);
}
scr->showText("Duration", 0, 2);
time.set(di.end - di.start);
scr->showText(time.duration(), 1, 2);
} else {
scr->showText("Outside totality", 0, 2);
scr->hideText(0, 0);
scr->hideText(1, 0);
scr->hideText(0, 1);
scr->hideText(1, 1);
scr->hideText(1, 2);
}
}
void TotalityPage::hide(const DisplayInfo &di, Screen *scr) {
scr->hideText();
}
SystemPage::SystemPage() : lavg("/proc/loadavg") { }
Page::SelectionResponse SystemPage::select(const DisplayInfo &di, SelectionCause sc) {
if (
// user wants it
(sc == SelectUser) ||
(
(
di.goodfix &&
( // don't auto-show during the eclipse
(di.now < (di.start - DisplayInfo::beforeTotality)) ||
(di.now > (di.end + DisplayInfo::afterTotality))
)
) ||
// show when no good GPS fix
!di.goodfix
)
) {
return SelectPage;
}
return SkipPage;
}
void SystemPage::show(const DisplayInfo &di, Screen *scr) {
scr->showTitle("System");
scr->showText("Volt", 2, 0);
scr->showText("Pow", 2, 1);
scr->showText("Exp", 2, 2);
scr->showText("Load", 0, 0);
scr->showText("avg", 0, 1);
scr->showText(" ", 0, 2); // makes formating nice
}
void SystemPage::update(const DisplayInfo &di, Screen *scr) {
float a[3];
lavg >> a[0] >> a[1] >> a[2];
lavg.seekg(0);
std::ostringstream oss;
for (int y = 0; y < 3; ++y) {
oss << std::setprecision(2) << std::fixed << a[y];
scr->showText(oss.str(), 1, y);
oss.str(std::string());
}
oss << std::setprecision(1) << di.battVolt;
scr->showText(oss.str(), 3, 0);
oss.str(std::string());
oss << std::setprecision(1) << di.battPow;
scr->showText(oss.str(), 3, 1);
oss.str(std::string());
oss << std::setprecision(1) << di.powexpmovavg;
scr->showText(oss.str(), 3, 2);
}
void SystemPage::hide(const DisplayInfo &di, Screen *scr) {
scr->hideText();
}
Page::SelectionResponse SensorPage::select(
const DisplayInfo &di,
SelectionCause sc
) {
if ((di.temp > 0) || (di.relhumid > 0) || (di.uv > 0)) {
return SelectPage;
}
return SkipPage;
}
void SensorPage::show(const DisplayInfo &di, Screen *scr) {
scr->showTitle("Sensors");
}
void SensorPage::update(const DisplayInfo &di, Screen *scr) {
std::ostringstream oss;
oss << std::fixed;
if (di.temp > 0) {
scr->showText("Temp", 0, 0);
oss << std::setprecision(1) << di.temp;
scr->showText(oss.str(), 1, 0);
oss.str(std::string());
}
if (di.relhumid > 0) {
scr->showText("Humid", 0, 1);
oss << std::setprecision(1) << di.relhumid;
scr->showText(oss.str(), 1, 1);
oss.str(std::string());
}
if (di.uv > 0) {
scr->showText("UV", 0, 2);
oss << std::setprecision(1) << di.uvexpmovavg;
scr->showText(oss.str(), 1, 2);
}
}
void SensorPage::hide(const DisplayInfo &di, Screen *scr) {
scr->hideText();
}