GCC Code Coverage Report


Directory: ./
File: oled/FPPStatusOLEDPage.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 313 558 56.1%
Functions: 15 24 62.5%
Branches: 363 1104 32.9%

Line Branch Exec Source
1 #include "fpp-pch.h"
2
3 #include "fpp-json.h"
4 #include <fstream>
5
6 #include <linux/nl80211.h>
7 #include <net/if.h>
8 #include <netlink/genl/ctrl.h>
9 #include <netlink/genl/genl.h>
10 #include <netlink/netlink.h>
11
12 #include <netinet/in.h>
13 #include <ifaddrs.h>
14 #include <netdb.h>
15 #include <unistd.h>
16
17 #include "../common.h"
18 #include "../CurlSocket.h"
19
20 #include "FPPMainMenu.h"
21 #include "FPPStatusOLEDPage.h"
22
23 #define MAX_PAGE 2
24
25 // nl80211 query for station signal strength. Replaces the legacy
26 // SIOCGIWRANGE/SIOCGIWSTATS ioctl path, which causes the kernel to log
27 // "uses wireless extensions which will stop working for Wi-Fi 7 hardware;
28 // use nl80211" and won't be supported by Wi-Fi 7 drivers.
29 namespace {
30 struct SignalQuery {
31 int signal_dbm = 0;
32 bool found = false;
33 int done = 0;
34 };
35
36 ✗ int signalValidCb(struct nl_msg* msg, void* arg) {
37 ✗ auto* q = static_cast<SignalQuery*>(arg);
38 ✗ auto* gnlh = static_cast<struct genlmsghdr*>(nlmsg_data(nlmsg_hdr(msg)));
39 struct nlattr* tb[NL80211_ATTR_MAX + 1];
40 ✗ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
41 genlmsg_attrlen(gnlh, 0), nullptr);
42 ✗ if (!tb[NL80211_ATTR_STA_INFO]) {
43 ✗ return NL_SKIP;
44 }
45 struct nlattr* sinfo[NL80211_STA_INFO_MAX + 1];
46 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {};
47 ✗ stats_policy[NL80211_STA_INFO_SIGNAL].type = NLA_U8;
48 ✗ if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
49 ✗ tb[NL80211_ATTR_STA_INFO], stats_policy) != 0) {
50 ✗ return NL_SKIP;
51 }
52 ✗ if (sinfo[NL80211_STA_INFO_SIGNAL]) {
53 // Reported as u8 but is a signed dBm value.
54 ✗ q->signal_dbm = (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
55 ✗ q->found = true;
56 }
57 ✗ return NL_SKIP;
58 }
59
60 ✗ int signalFinishCb(struct nl_msg*, void* arg) {
61 ✗ static_cast<SignalQuery*>(arg)->done = 1;
62 ✗ return NL_SKIP;
63 }
64
65 ✗ int signalAckCb(struct nl_msg*, void* arg) {
66 ✗ static_cast<SignalQuery*>(arg)->done = 1;
67 ✗ return NL_STOP;
68 }
69
70 ✗ int signalErrorCb(struct sockaddr_nl*, struct nlmsgerr*, void* arg) {
71 ✗ static_cast<SignalQuery*>(arg)->done = 1;
72 ✗ return NL_SKIP;
73 }
74 } // namespace
75
76 ✗ int FPPStatusOLEDPage::getSignalStrength(char* iwname) {
77 ✗ unsigned int ifindex = if_nametoindex(iwname);
78 ✗ if (ifindex == 0) {
79 ✗ return 0;
80 }
81
82 ✗ struct nl_sock* sk = nl_socket_alloc();
83 ✗ if (!sk) {
84 ✗ return 0;
85 }
86 ✗ if (genl_connect(sk) != 0) {
87 ✗ nl_socket_free(sk);
88 ✗ return 0;
89 }
90 ✗ int family = genl_ctrl_resolve(sk, "nl80211");
91 ✗ if (family < 0) {
92 // Not a wireless interface (or nl80211 unavailable).
93 ✗ nl_socket_free(sk);
94 ✗ return 0;
95 }
96
97 ✗ struct nl_msg* msg = nlmsg_alloc();
98 ✗ struct nl_cb* cb = nl_cb_alloc(NL_CB_DEFAULT);
99 ✗ if (!msg || !cb) {
100 ✗ if (msg) nlmsg_free(msg);
101 ✗ if (cb) nl_cb_put(cb);
102 ✗ nl_socket_free(sk);
103 ✗ return 0;
104 }
105
106 ✗ SignalQuery q;
107 ✗ genlmsg_put(msg, 0, 0, family, 0, NLM_F_DUMP,
108 NL80211_CMD_GET_STATION, 0);
109 ✗ nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex);
110
111 ✗ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, signalValidCb, &q);
112 ✗ nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, signalFinishCb, &q);
113 ✗ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, signalAckCb, &q);
114 ✗ nl_cb_err(cb, NL_CB_CUSTOM, signalErrorCb, &q);
115
116 ✗ if (nl_send_auto(sk, msg) >= 0) {
117 ✗ while (!q.done) {
118 ✗ int r = nl_recvmsgs(sk, cb);
119 ✗ if (r < 0) {
120 ✗ break;
121 }
122 }
123 }
124
125 ✗ nlmsg_free(msg);
126 ✗ nl_cb_put(cb);
127 ✗ nl_socket_free(sk);
128
129 ✗ if (!q.found) {
130 ✗ return 0;
131 }
132 // Map dBm to a 0-100 quality. -50 dBm or better -> 100%, -100 dBm or
133 // worse -> 0%; linear in between. Matches the "2*(level+100)" rule
134 // commonly used by wpa_supplicant/iw consumers.
135 ✗ int pct = 2 * (q.signal_dbm + 100);
136 ✗ if (pct < 0) {
137 ✗ pct = 0;
138 ✗ } else if (pct > 100) {
139 ✗ pct = 100;
140 }
141 ✗ return pct;
142 }
143
144 static bool debug = false;
145
146 18 static int writer(char* data, size_t size, size_t nmemb,
147 std::string* writerData) {
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (writerData == NULL)
149 ✗ return 0;
150 18 writerData->append(data, size * nmemb);
151 18 return size * nmemb;
152 }
153
154 31 FPPStatusOLEDPage::FPPStatusOLEDPage() :
155
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 _currentTest(""),
156 31 _testSpeed(500),
157 31 _curPage(0),
158 31 _doFullStatus(true),
159 31 _iterationCount(0),
160 62 _hasSensors(false) {
161
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl = curl_easy_init();
162
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 SetCurlCloseOnExec(curl);
163
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
164
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:32322/fppd/status");
165
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
166
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 50);
167
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 250);
168
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
169
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
170
171
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 readCapeImage();
172
3/8
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 31 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
31 mainMenu = new FPPMainMenu(this);
173 31 }
174 ✗ FPPStatusOLEDPage::~FPPStatusOLEDPage() {
175 ✗ curl_easy_cleanup(curl);
176 ✗ delete mainMenu;
177 ✗ }
178
179 ✗ void FPPStatusOLEDPage::outputNetwork(int idx, int y) {
180 ✗ printString(0, y, networks[idx]);
181 ✗ if (signalStrength[idx]) {
182 ✗ y = y + 7;
183 ✗ int cur = 5;
184 ✗ for (int x = 0; x < 7; x++) {
185 ✗ if (signalStrength[idx] > cur) {
186 ✗ drawLine(127 - (x / 2), y, 128, y);
187 }
188 ✗ y--;
189 ✗ cur += 15;
190 }
191 }
192 ✗ }
193
194 6 static bool compareLines(int x, std::vector<std::string>& lines1, std::vector<std::string>& lines2) {
195
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
6 if (x < lines1.size() && x < lines2.size()) {
196 ✗ return lines1[x] != lines2[x];
197
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 } else if (x < lines1.size() || x < lines2.size()) {
198 6 return true;
199 }
200 ✗ return false;
201 }
202
203 12 bool FPPStatusOLEDPage::checkIfStatusChanged(Json::Value& result) {
204
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 std::string mode = result["mode_name"].asString();
205
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 mode[0] = toupper(mode[0]);
206
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (currentMode != mode) {
207 6 return true;
208 }
209
210 // if the status has materially changed, turn the oled back on
211 6 std::vector<std::string> lines;
212
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int maxLines = getLinesPage0(lines, result, true);
213
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (compareLines(0, lines, _lastStatusLines)) {
214 // main status
215
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 _lastStatusLines = lines;
216 6 return true;
217 }
218 ✗ if (compareLines(1, lines, _lastStatusLines)) {
219 // running sequence
220 ✗ _lastStatusLines = lines;
221 ✗ return true;
222 }
223 ✗ if (compareLines(2, lines, _lastStatusLines)) {
224 // running song
225 ✗ _lastStatusLines = lines;
226 ✗ return true;
227 }
228 ✗ if (compareLines(5, lines, _lastStatusLines)) {
229 // running playlist
230 ✗ _lastStatusLines = lines;
231 ✗ return true;
232 }
233
234 ✗ return false;
235 12 }
236
237 18 int FPPStatusOLEDPage::getLinesPage0(std::vector<std::string>& lines,
238 Json::Value& result,
239 bool allowBlank) {
240
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 std::string status = result["status_name"].asString();
241
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 currentMode = result["mode_name"].asString();
242
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 currentMode[0] = toupper(currentMode[0]);
243
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 std::string line = currentMode;
244
2/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18 bool isIdle = (status == "idle" || status == "testing");
245 18 int maxLines = 6;
246
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 if (currentMode != "Bridge") {
247 // bridge is always "idle" which isn't really true
248
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 line += ": " + status;
249 } else {
250 // bridge mode doesn't output a playlist section
251 ✗ isIdle = false;
252 ✗ maxLines = 5;
253 }
254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (line.length() > 21) {
255 ✗ line.resize(21);
256 }
257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 lines.push_back(line);
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!_doFullStatus) {
259 ✗ return 1;
260 }
261
262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!isIdle) {
263 ✗ std::string line = result["current_sequence"].asString();
264 ✗ if (line != "" || allowBlank) {
265 ✗ lines.push_back(line);
266 }
267 ✗ line = result["current_song"].asString();
268 ✗ if (line != "" || allowBlank) {
269 ✗ lines.push_back(line);
270 }
271 ✗ line = result["time_elapsed"].asString();
272 ✗ if (line != "" || allowBlank) {
273 ✗ if (line != "") {
274 ✗ line = "Elapsed: " + line;
275 }
276 ✗ lines.push_back(line);
277 }
278 ✗ line = result["time_remaining"].asString();
279 ✗ if (line != "" || allowBlank) {
280 ✗ if (line != "") {
281 ✗ line = "Remaining: " + line;
282 }
283 ✗ lines.push_back(line);
284 }
285 ✗ line = result["current_playlist"]["playlist"].asString();
286 ✗ if (line != "" || allowBlank) {
287 ✗ if (line != "") {
288 ✗ line = "PL: " + line;
289 }
290 ✗ lines.push_back(line);
291 }
292 ✗ }
293
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 _hasSensors = result["sensors"].size() > 0;
294 18 return maxLines;
295 18 }
296 4 int FPPStatusOLEDPage::getLinesPage1(std::vector<std::string>& lines,
297 Json::Value& result,
298 bool allowBlank) {
299 4 std::vector<std::string> topLines;
300
4/6
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 4 times.
20 for (int x = 0; x < result["sensors"].size(); x++) {
301 16 std::string line;
302
7/12
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
✓ Branch 11 taken 4 times.
16 if (result["sensors"][x]["valueType"].asString() == "Temperature") {
303
9/18
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 12 times.
✗ Branch 17 not taken.
12 line = result["sensors"][x]["label"].asString() + result["sensors"][x]["formatted"].asString();
304
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 line += "C (";
305
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 float i = result["sensors"][x]["value"].asFloat();
306 12 i *= 1.8;
307 12 i += 32;
308 char buf[25];
309 12 snprintf(buf, sizeof(buf), "%.1f", i);
310
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 line += buf;
311
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 line += "F)";
312 } else {
313
10/20
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4 times.
✗ Branch 19 not taken.
4 line = result["sensors"][x]["label"].asString() + " " + result["sensors"][x]["formatted"].asString();
314 }
315
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
16 if (topLines.size() < _topLine) {
316
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 topLines.push_back(line);
317 } else {
318
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 lines.push_back(line);
319 }
320 16 }
321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (lines.empty()) {
322 ✗ _topLine = 0;
323 }
324
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 for (auto& l : topLines) {
325
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 lines.push_back(l);
326 }
327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (lines.empty()) {
328 ✗ return getLinesPage0(lines, result, allowBlank);
329 }
330 4 return 6;
331 4 }
332 148 int FPPStatusOLEDPage::outputTopPart(int startY, int count) {
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
148 if (networks.size() > 1) {
334 ✗ int idx = (count / 3) % networks.size();
335 ✗ int lines = GetLEDDisplayHeight() >= 64 ? 2 : 1;
336 ✗ if (networks.size() <= 5 && GetLEDDisplayHeight() > 65) {
337 ✗ idx = 0;
338 ✗ lines = networks.size() < 5 ? networks.size() : 5;
339 ✗ if (lines < 2)
340 ✗ lines = 2;
341 }
342 ✗ if (networks.size() <= lines) {
343 ✗ idx = 0;
344 }
345 ✗ outputNetwork(idx, startY);
346 ✗ startY += 8;
347 ✗ if (GetLEDDisplayHeight() > 65) {
348 ✗ startY += 2; // little extra space
349 }
350 ✗ for (int x = 1; x < lines; x++) {
351 ✗ idx++;
352 ✗ if (idx >= networks.size()) {
353 ✗ idx = 0;
354 }
355 ✗ outputNetwork(idx, startY);
356 ✗ startY += 8;
357 ✗ if (GetLEDDisplayHeight() > 65) {
358 ✗ startY += 2; // little extra space
359 }
360 }
361 } else {
362 // fppd answering means boot is done; past that, no address is "No Network"
363
3/4
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
✓ Branch 3 taken 17 times.
148 if (count < 60 && !_fppdSeen) {
364
2/4
✓ Branch 0 taken 131 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
262 printString(0, startY, "FPP Booting...");
365 } else {
366
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
34 printString(0, startY, "No Network");
367 }
368 148 startY += 8;
369
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 6 times.
148 if (GetLEDDisplayHeight() >= 64) {
370 142 startY += 8;
371 }
372 }
373 148 return startY;
374 }
375 149 bool FPPStatusOLEDPage::getCurrentStatus(Json::Value& result) {
376 149 buffer.clear();
377 149 bool gotStatus = false;
378 149 auto rc = curl_easy_perform(curl);
379
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 133 times.
149 if (rc == CURLE_OK) {
380
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (LoadJsonFromString(buffer, result)) {
381
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 std::string status = result["status_name"].asString();
382 16 return true;
383
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
16 } else if (debug) {
384 ✗ LogWarn(VB_GENERAL, "Invalid json\n");
385 }
386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
133 } else if (debug) {
387 ✗ LogWarn(VB_GENERAL, "Curl returned bad status: %d\n", rc);
388 }
389 133 return false;
390 }
391
392 148 int FPPStatusOLEDPage::outputBottomPart(int startY, int count, bool statusValid, Json::Value& result) {
393
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 132 times.
148 if (statusValid) {
394 16 std::vector<std::string> lines;
395 16 std::string line;
396 16 int maxLines = 5;
397
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 if (_curPage == 0) {
398
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 maxLines = getLinesPage0(lines, result, GetLEDDisplayHeight() >= 64);
399 } else {
400
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 maxLines = getLinesPage1(lines, result, GetLEDDisplayHeight() >= 64);
401 }
402
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (maxLines > lines.size()) {
403 16 maxLines = lines.size();
404 }
405
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 if (GetLEDDisplayHeight() >= 64) {
406
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 16 times.
44 for (int x = 0; x < maxLines; x++) {
407
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 line = lines[x];
408
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 24 times.
28 if (line.length() > 21) {
409
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 line.resize(21);
410 }
411
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 printString(0, startY, line);
412 28 startY += 8;
413
2/4
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
28 if (GetLEDDisplayHeight() > 65) {
414 ✗ startY += 2;
415 }
416 }
417 } else {
418 ✗ int numLines = (GetLEDDisplayHeight() - startY) / 8;
419 ✗ int idx = count % maxLines;
420 ✗ if (numLines >= maxLines) {
421 ✗ idx = 0;
422 }
423 ✗ line = lines[idx];
424 ✗ if (line.length() > 21) {
425 ✗ line.resize(21);
426 }
427 ✗ printString(0, startY, line);
428 ✗ startY += 8;
429 ✗ idx++;
430 ✗ if (idx == maxLines) {
431 ✗ idx = 0;
432 }
433 ✗ if (maxLines > 1) {
434 ✗ line = lines[idx];
435 ✗ if (line.length() > 21) {
436 ✗ line.resize(21);
437 }
438 ✗ printString(0, startY, line);
439 }
440 }
441 16 } else {
442
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 if (count < 75) {
443 // if less than 75 seconds since start, we'll assume we are booting up
444
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 std::string line = "Booting.";
445 132 int idx = count % 8;
446
2/2
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 132 times.
504 for (int i = 0; i < idx; i++) {
447
1/2
✓ Branch 0 taken 372 times.
✗ Branch 1 not taken.
372 line += ".";
448 }
449
1/2
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
132 printString(10, startY, line);
450 132 startY += 8;
451 132 } else {
452 ✗ printString(0, startY, "FPPD is not running..");
453 ✗ startY += 8;
454 }
455
3/4
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
132 if (_capeImageWidth && oledType != OLEDType::TEXT_ONLY) {
456 128 int y = startY;
457
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if (oledType != OLEDType::TWO_COLOR) {
458 128 --y;
459 }
460
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 124 times.
128 if (GetLEDDisplayHeight() > 65) {
461 4 y += 4;
462 }
463
464 128 drawBitmap(0, y, &_capeImage[0], _capeImageWidth, _capeImageHeight);
465 }
466 }
467 148 return startY;
468 }
469
470 149 bool FPPStatusOLEDPage::doIteration(bool& displayOn) {
471 149 _iterationCount++;
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (oledType == OLEDType::NONE) {
473 ✗ return false;
474 }
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (oledForcedOff)
476 ✗ return false;
477
478 149 bool retVal = false;
479 149 int lastNSize = networks.size();
480
4/6
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 148 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 149 times.
✗ Branch 5 not taken.
149 if ((_iterationCount % 30) == 0 || networks.size() <= 1) {
481 // every 30 seconds, rescan network for new connections
482
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 fillInNetworks();
483 // if networks aren't configured or have changed, keep the oled on
484
4/6
✓ Branch 0 taken 118 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 149 times.
✗ Branch 5 not taken.
149 if (lastNSize != networks.size() || networks.size() <= 1) {
485 149 retVal = true;
486 149 displayOn = true;
487 }
488 }
489
490
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 Json::Value result;
491
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 bool statusValid = getCurrentStatus(result);
492
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 133 times.
149 if (statusValid) {
493 16 _fppdSeen = true;
494
5/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 4 times.
16 if (!displayOn || _lastStatusLines.empty()) {
495
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 displayOn = checkIfStatusChanged(result);
496
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (displayOn) {
497 12 retVal = true;
498 }
499 }
500 }
501
502
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 if (displayOn) {
503
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 clearDisplay();
504 149 int startY = 0;
505 149 int count = _iterationCount;
506 149 bool doWiFi = false;
507
12/18
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 32 times.
✓ Branch 8 taken 33 times.
✓ Branch 9 taken 116 times.
✓ Branch 10 taken 33 times.
✓ Branch 11 taken 116 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 148 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
215 if (count > 15 && loadWiFiImage()) {
508 1 count -= 15;
509 1 count %= 30;
510 1 doWiFi = count < 15;
511 }
512
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 148 times.
149 if (doWiFi) {
513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 displayWiFiQR();
514
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
148 } else if (oledType != OLEDType::TWO_COLOR || !oledFlipped) {
515
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 startY = outputTopPart(startY, _iterationCount);
516
3/4
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
148 if (oledType != OLEDType::TWO_COLOR && oledType != OLEDType::TEXT_ONLY) {
517 // two color display doesn't need the separator line
518
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 drawLine(0, startY, 127, startY);
519 144 startY++;
520
3/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 140 times.
144 if (GetLEDDisplayHeight() > 65) {
521 4 startY += 2;
522 }
523 }
524
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 startY = outputBottomPart(startY, _iterationCount, statusValid, result);
525 } else {
526 // strange case... with 2 color display flipped, we still need to keep the
527 // network part in the "yellow" which is now below the main part
528 ✗ outputBottomPart(0, _iterationCount, statusValid, result);
529 ✗ outputTopPart(48, _iterationCount);
530 }
531
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 flushDisplay();
532 }
533 149 return retVal;
534 149 }
535
536 149 void FPPStatusOLEDPage::fillInNetworks() {
537 149 networks.clear();
538 149 signalStrength.clear();
539
540 char hostname[HOST_NAME_MAX];
541 int result;
542 149 result = gethostname(hostname, HOST_NAME_MAX);
543
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 std::string hn = "Host: ";
544
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 hn += hostname;
545
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 networks.push_back(hn);
546
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 signalStrength.push_back(0);
547
548 // get all the addresses
549 struct ifaddrs *interfaces, *tmp;
550 149 getifaddrs(&interfaces);
551 149 tmp = interfaces;
552 char addressBuf[128];
553
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 149 times.
599 while (tmp) {
554
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
450 int max = OLEDPage::GetLEDDisplayWidth() / 6;
555
3/4
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 149 times.
✓ Branch 3 taken 301 times.
450 if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) {
556
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 if (strncmp("usb", tmp->ifa_name, 3) != 0) {
557 // skip the usb* interfaces as we won't support multisync on those
558
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 GetInterfaceAddress(tmp->ifa_name, addressBuf, NULL, NULL);
559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149 times.
149 if (strcmp(addressBuf, "127.0.0.1")) {
560 ✗ hn = tmp->ifa_name;
561 ✗ hn += ":";
562 ✗ hn += addressBuf;
563 ✗ if (hn.size() > max) {
564 ✗ hn = addressBuf;
565 }
566 ✗ networks.push_back(hn);
567 ✗ int i = getSignalStrength(tmp->ifa_name);
568 ✗ signalStrength.push_back(i);
569 }
570 }
571
1/2
✓ Branch 0 taken 301 times.
✗ Branch 1 not taken.
301 } else if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) {
572 // FIXME for ipv6 multisync
573 } else {
574 // printf("Not a netork: %s\n", tmp->ifa_name);
575 }
576 450 tmp = tmp->ifa_next;
577 }
578 149 freeifaddrs(interfaces);
579 149 }
580
581 2 void FPPStatusOLEDPage::runTest(const std::string& test, bool ms) {
582
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogInfo(VB_GENERAL, "Running Test: %s Speed: %dms\n", test.c_str(), _testSpeed);
583
584
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Json::Value val;
585
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (test == "Off") {
586
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 val["command"] = "Test Stop";
587
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 val["args"] = Json::Value(Json::ValueType::arrayValue);
588
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 _currentTest = "";
589 } else {
590
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 val["command"] = "Test Start";
591
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 val["args"] = Json::Value(Json::ValueType::arrayValue);
592
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 val["args"].append(std::to_string(_testSpeed));
593
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 _currentTest = test;
594 }
595 2 _multisyncTest = ms;
596
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 val["multisyncCommand"] = _multisyncTest;
597
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 val["multisyncHosts"] = "";
598
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string channelRange = "";
599
600
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (test == "R-G-B Chase") {
601 ✗ val["args"].append("RGB Chase");
602 ✗ val["args"].append(channelRange);
603 ✗ val["args"].append("R-G-B");
604
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (test == "R-G-B-W Chase") {
605 ✗ val["args"].append("RGB Chase");
606 ✗ val["args"].append(channelRange);
607 ✗ val["args"].append("R-G-B-All");
608
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (test == "R-G-B-W-N Chase") {
609 ✗ val["args"].append("RGB Chase");
610 ✗ val["args"].append(channelRange);
611 ✗ val["args"].append("R-G-B-All-None");
612
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (test == "R-G-B Cycle") {
613 ✗ val["args"].append("RGB Cycle");
614 ✗ val["args"].append(channelRange);
615 ✗ val["args"].append("R-G-B");
616
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (test == "R-G-B-W Cycle") {
617 ✗ val["args"].append("RGB Cycle");
618 ✗ val["args"].append(channelRange);
619 ✗ val["args"].append("R-G-B-All");
620
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (test == "R-G-B-W-N Cycle") {
621 ✗ val["args"].append("RGB Cycle");
622 ✗ val["args"].append(channelRange);
623 ✗ val["args"].append("R-G-B-All-None");
624
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 } else if (test == "White") {
625
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 val["args"].append("RGB Single Color");
626
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 val["args"].append(channelRange);
627
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 val["args"].append("#ffffff");
628
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 } else if (test == "Red") {
629 ✗ val["args"].append("RGB Single Color");
630 ✗ val["args"].append(channelRange);
631 ✗ val["args"].append("#ff0000");
632
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 } else if (test == "Green") {
633 ✗ val["args"].append("RGB Single Color");
634 ✗ val["args"].append(channelRange);
635 ✗ val["args"].append("#00ff00");
636
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 } else if (test == "Blue") {
637 ✗ val["args"].append("RGB Single Color");
638 ✗ val["args"].append(channelRange);
639 ✗ val["args"].append("#0000ff");
640
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 } else if (_currentTest != "") {
641 ✗ LogWarn(VB_GENERAL, "Unknown test %s\n", test.c_str());
642 ✗ return;
643 }
644
645
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 std::string data = SaveJsonToString(val);
646
647
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogDebug(VB_COMMAND, "fppoled sending command to /api/command: %s\n", data.c_str());
648
649 2 buffer.clear();
650
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 CURL* curl = curl_easy_init();
651
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 SetCurlCloseOnExec(curl);
652
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
653
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/api/command");
654
655
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
656
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 50);
657
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 250);
658
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_POST, 1);
659
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
660
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1L);
661
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
662
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
663
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_perform(curl);
664
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 curl_easy_cleanup(curl);
665
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 }
666 static std::vector<std::string> TESTS = { "Off", "R-G-B Cycle", "R-G-B-W-N Cycle", "R-G-B Chase", "R-G-B-W-N Chase" };
667 ✗ void FPPStatusOLEDPage::cycleTest() {
668 ✗ int idx = 1;
669 ✗ for (int x = 0; x < TESTS.size(); x++) {
670 ✗ if (TESTS[x] == _currentTest) {
671 ✗ idx = x + 1;
672 ✗ break;
673 }
674 }
675 ✗ if (idx >= TESTS.size()) {
676 ✗ idx = 0;
677 }
678 ✗ _currentTest = TESTS[idx];
679 ✗ runTest(_currentTest, _multisyncTest);
680 ✗ }
681
682 1 void FPPStatusOLEDPage::displayWiFiQR() {
683 1 clearDisplay();
684 1 int dh = GetLEDDisplayHeight();
685 1 int y = 0;
686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (oledType == OLEDType::TWO_COLOR) {
687 ✗ if (GetOLEDOrientationFlipped()) {
688 ✗ y = 0;
689 ✗ } else if (_wifiImageHeight > 48) {
690 ✗ y = 15;
691 } else {
692 ✗ y = 16;
693 }
694 } else {
695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (_wifiImageHeight > dh) {
696 ✗ y = 0;
697 } else {
698 1 y = (dh - _wifiImageHeight) / 2;
699 }
700 }
701 1 drawBitmap(2, y, &_wifiImage[0], _wifiImageWidth, _wifiImageHeight);
702
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 printString(12 + _wifiImageWidth, y + 12, "WiFi");
703
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 printString(12 + _wifiImageWidth, y + 20, "Hot Spot");
704 1 }
705
706 33 bool FPPStatusOLEDPage::loadWiFiImage(const std::string& tp) {
707
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
33 std::string fn = "/home/fpp/media/tmp/wifi-" + tp + ".ascii";
708
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32 times.
33 if (_wifiImageWidth) {
709
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!FileExists(fn)) {
710 // file no longer exists, clear
711 1 _wifiImageWidth = 0;
712 1 _wifiImageHeight = 0;
713 1 _wifiImage.clear();
714 1 return false;
715 }
716 ✗ return true;
717 }
718 32 _wifiImageWidth = 0;
719 32 _wifiImageHeight = 0;
720 32 int maxSz = 0;
721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (GetOLEDType() == OLEDPage::OLEDType::SMALL) {
722 ✗ maxSz = 15;
723
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 } else if (GetOLEDType() == OLEDPage::OLEDType::SINGLE_COLOR) {
724 32 maxSz = 66;
725 ✗ } else if (GetOLEDType() == OLEDPage::OLEDType::TWO_COLOR) {
726 ✗ maxSz = 50;
727 }
728
6/8
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 31 times.
32 if (maxSz && FileExists(fn)) {
729
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::ifstream file(fn);
730
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (file.is_open()) {
731 1 std::string line;
732 1 bool readingBytes = false;
733 1 int scale = 2;
734
4/6
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✓ Branch 5 taken 1 times.
22 while (std::getline(file, line)) {
735
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (_wifiImageWidth == 0) {
736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (line.size() > maxSz) {
737 // going to have to scale, first check if we can get the "H" version
738 ✗ if (tp == "L" && loadWiFiImage("H")) {
739 ✗ return true;
740 }
741 ✗ _wifiImageWidth = (int)line.size() / 2;
742 ✗ scale = 1;
743 } else {
744 1 _wifiImageWidth = (int)line.size();
745 }
746 }
747
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 21 times.
63 for (int lc = 0; lc < scale; lc++) {
748
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 42 times.
294 for (int x = 0; x < (_wifiImageWidth / scale);) {
749 252 uint8_t v = 0;
750
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 252 times.
1260 for (int y = 0; y < 8 / scale; y++) {
751 1008 int idx = x * 2 + y * 2;
752 1008 v <<= 1;
753
7/8
✓ Branch 0 taken 882 times.
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 882 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 440 times.
✓ Branch 5 taken 442 times.
✓ Branch 6 taken 440 times.
✓ Branch 7 taken 568 times.
1008 if (idx < line.size() && line[idx] == '#') {
754 440 v |= 1;
755
1/2
✓ Branch 0 taken 440 times.
✗ Branch 1 not taken.
440 if (scale == 2) {
756 440 v <<= 1;
757 440 v |= 1;
758 }
759
1/2
✓ Branch 0 taken 568 times.
✗ Branch 1 not taken.
568 } else if (scale == 2) {
760 568 v <<= 1;
761 }
762 }
763 252 x += 8 / scale;
764
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 _wifiImage.push_back(v);
765 }
766 42 ++_wifiImageHeight;
767 }
768 }
769
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 file.close();
770
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 }
771 1 return true;
772 1 }
773 31 return false;
774 33 }
775
776 19 bool FPPStatusOLEDPage::doAction(const std::string& action) {
777 // printf("In do action %s %d %s\n", action.c_str(), _testSpeed, _currentTest.c_str());
778
4/8
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
19 if (action == "Test" || action == "Test/Down" || action == "Test Multisync") {
779 ✗ _multisyncTest = action == "Test Multisync";
780 ✗ _testSpeed = 500;
781 ✗ cycleTest();
782 ✗ _curPage = 0;
783 ✗ _topLine = 0;
784
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
19 } else if (action == "Up" && _currentTest != "") {
785 ✗ _testSpeed *= 2;
786 ✗ runTest(_currentTest, _multisyncTest);
787
4/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
19 } else if (action == "Down" && _currentTest != "") {
788 ✗ _testSpeed /= 2;
789 ✗ if (_testSpeed < 100) {
790 ✗ _testSpeed = 100;
791 }
792 ✗ runTest(_currentTest, _multisyncTest);
793
7/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 17 times.
19 } else if (action == "Down" && _hasSensors && _curPage == 1) {
794 2 _topLine++;
795
7/10
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 16 times.
17 } else if (action == "Up" && _hasSensors && _curPage == 1 && _topLine > 0) {
796 1 _topLine--;
797
5/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 2 times.
16 } else if (action == "Enter" && !oledForcedOff) {
798
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (_hasSensors) {
799 1 _curPage++;
800 1 _topLine = 0;
801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (_curPage == MAX_PAGE) {
802 ✗ _curPage = 0;
803 ✗ SetCurrentPage(mainMenu);
804 }
805 } else {
806 13 SetCurrentPage(mainMenu);
807 }
808 }
809 19 return false;
810 }
811