GCC Code Coverage Report


Directory: ./
File: oled/OLEDPages.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 312 425 73.4%
Functions: 42 46 91.3%
Branches: 208 446 46.6%

Line Branch Exec Source
1 #include "fpp-pch.h"
2 #include <memory>
3
4 #include <fstream>
5
6 #include "OLEDPages.h"
7 #include "../common.h"
8
9 static std::unique_ptr<DisplayDriver> displayDriver{ nullptr };
10
11 OLEDPage::OLEDType OLEDPage::oledType = OLEDPage::OLEDType::SINGLE_COLOR;
12 bool OLEDPage::oledFlipped = false;
13 OLEDPage* OLEDPage::currentPage = nullptr;
14 bool OLEDPage::oledForcedOff = false;
15 bool OLEDPage::has4DirectionControls = false;
16
17 int OLEDPage::_capeImageWidth = 0;
18 int OLEDPage::_capeImageHeight = 0;
19 std::vector<uint8_t> OLEDPage::_capeImage;
20
21 static int DISPLAY_I2CBUS = 0;
22
23 37 bool OLEDPage::InitializeDisplay(int ledType) {
24
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 31 times.
37 if (ledType == 0) {
25 6 SetOLEDType(OLEDPage::OLEDType::NONE);
26 6 return false;
27 }
28
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
31 if (ledType <= 10 || ledType >= 32) {
29
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 displayDriver = std::make_unique<SSD1306DisplayDriver>(ledType);
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (!displayDriver->initialize(DISPLAY_I2CBUS)) {
31 ✗ displayDriver.reset(nullptr);
32 ✗ SetOLEDType(OLEDPage::OLEDType::NONE);
33 ✗ return false;
34 }
35
36
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 29 times.
31 if (ledType == 3 || ledType == 4) {
37 2 SetOLEDType(OLEDPage::OLEDType::SMALL);
38
3/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
29 } else if (ledType == 7 || ledType == 8) {
39 2 SetOLEDType(OLEDPage::OLEDType::TWO_COLOR);
40 } else {
41 27 SetOLEDType(OLEDPage::OLEDType::SINGLE_COLOR);
42 }
43
7/12
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 29 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 29 times.
31 if (ledType == 2 || ledType == 4 || ledType == 6 || ledType == 8 || ledType == 10 || ledType == 35) {
44 2 SetOLEDOrientationFlipped(true);
45 }
46
47 31 return true;
48 ✗ } else if (ledType <= 20) {
49 ✗ displayDriver = std::make_unique<I2C1602_2004_DisplayDriver>(ledType);
50 ✗ if (!displayDriver->initialize(DISPLAY_I2CBUS)) {
51 ✗ displayDriver.reset(nullptr);
52 ✗ SetOLEDType(OLEDPage::OLEDType::NONE);
53 ✗ return false;
54 }
55 ✗ SetOLEDType(OLEDPage::OLEDType::TEXT_ONLY);
56 ✗ return true;
57 }
58 ✗ return false;
59 }
60
61 31 int OLEDPage::GetI2CBus() {
62 31 return DISPLAY_I2CBUS;
63 }
64
65 37 void OLEDPage::SetOLEDType(OLEDType tp) {
66 37 oledType = tp;
67 37 }
68
69 31 void OLEDPage::displayBootingNotice(const std::string& msg) {
70
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (displayDriver) {
71
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 31 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
31 std::string m = msg.empty() ? "FPP Booting..." : msg;
72
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 readCapeImage();
73
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 displayDriver->clearDisplay();
74
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 displayDriver->printString(0, 0, m, true);
75
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 drawBitmap(0, 20, &_capeImage[0], _capeImageWidth, _capeImageHeight);
76
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 displayDriver->flushDisplay();
77 31 }
78 31 }
79
80 225 void OLEDPage::flushDisplay() {
81
1/2
✓ Branch 0 taken 225 times.
✗ Branch 1 not taken.
225 if (displayDriver) {
82 225 displayDriver->flushDisplay();
83 }
84 225 }
85 226 void OLEDPage::clearDisplay() {
86
1/2
✓ Branch 0 taken 226 times.
✗ Branch 1 not taken.
226 if (displayDriver) {
87 226 displayDriver->clearDisplay();
88 }
89 226 }
90 83 void OLEDPage::fillTriangle(short x0, short y0, short x1, short y1, short x2, short y2, bool white) {
91
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 if (displayDriver) {
92 83 displayDriver->fillTriangle(x0, y0, x1, y1, x2, y2, white);
93 }
94 83 }
95 144 void OLEDPage::drawLine(short x0, short y0, short x1, short y1, bool white) {
96
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if (displayDriver) {
97 144 displayDriver->drawLine(x0, y0, x1, y1, white);
98 }
99 144 }
100 160 void OLEDPage::drawBitmap(short x, short y, const unsigned char bitmap[], short w, short h, bool white) {
101
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if (displayDriver) {
102 160 displayDriver->drawBitmap(x, y, bitmap, w, h, white);
103 }
104 160 }
105 76 void OLEDPage::drawRect(short x0, short y0, short x1, short y1, bool white) {
106
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (displayDriver) {
107 76 displayDriver->drawRect(x0, y0, x1, y1, white);
108 }
109 76 }
110 152 void OLEDPage::fillRect(short x0, short y0, short x1, short y1, bool white) {
111
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (displayDriver) {
112 152 displayDriver->fillRect(x0, y0, x1, y1, white);
113 }
114 152 }
115
116 671 void OLEDPage::printString(int x, int y, const std::string& str, bool white) {
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 671 times.
671 if (oledForcedOff)
118 ✗ return;
119
1/2
✓ Branch 0 taken 671 times.
✗ Branch 1 not taken.
671 if (displayDriver) {
120 671 displayDriver->printString(x, y, str, white);
121 }
122 }
123 84 void OLEDPage::printStringCentered(int y, const std::string& str, bool white) {
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (oledForcedOff)
125 ✗ return;
126
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 if (displayDriver) {
127 84 displayDriver->printStringCentered(y, str, white);
128 }
129 }
130 450 int OLEDPage::GetLEDDisplayWidth() {
131
1/2
✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
450 if (displayDriver) {
132 450 return displayDriver->getWidth();
133 }
134 ✗ return 128;
135 }
136 520 int OLEDPage::GetLEDDisplayHeight() {
137
1/2
✓ Branch 0 taken 520 times.
✗ Branch 1 not taken.
520 if (displayDriver) {
138 520 return displayDriver->getHeight();
139 }
140 ✗ return 32;
141 }
142 31 void OLEDPage::displayOff() {
143
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (displayDriver) {
144 31 return displayDriver->displayOff();
145 }
146 }
147 ✗ int OLEDPage::getMinimumRefresh() {
148 ✗ if (displayDriver) {
149 ✗ return displayDriver->getMinimumRefresh();
150 }
151 ✗ return 1000;
152 }
153
154 70 OLEDPage::OLEDPage() :
155 70 autoDeleteOnHide(false) {
156 70 }
157
158 56 void OLEDPage::SetCurrentPage(OLEDPage* p) {
159
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 31 times.
56 if (currentPage) {
160 25 currentPage->hiding();
161
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 18 times.
25 if (currentPage->autoDeleteOnHide) {
162
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 delete currentPage;
163 }
164 }
165 56 currentPage = p;
166
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 if (currentPage) {
167 56 currentPage->displaying();
168 }
169 56 }
170
171 // trim from start (in place)
172 41376 static inline void ltrim(std::string& s) {
173
2/4
✓ Branch 0 taken 41376 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41376 times.
✗ Branch 3 not taken.
41376 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
174 76274 return !std::isspace(ch);
175 }));
176 41376 }
177 // trim from end (in place)
178 41376 static inline void rtrim(std::string& s) {
179
2/4
✓ Branch 0 taken 41376 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41376 times.
✗ Branch 3 not taken.
124128 s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
180 41314 return !std::isspace(ch);
181 41376 }).base(),
182 41376 s.end());
183 41376 }
184 // trim from both ends (in place)
185 41376 static inline void trim(std::string& s) {
186 41376 ltrim(s);
187 41376 rtrim(s);
188 41376 }
189 3148 static std::vector<std::string> splitAndTrim(const std::string& s, char seperator) {
190 3148 std::vector<std::string> output;
191 3148 std::string::size_type prev_pos = 0, pos = 0;
192
2/2
✓ Branch 0 taken 35080 times.
✓ Branch 1 taken 3148 times.
38228 while ((pos = s.find(seperator, pos)) != std::string::npos) {
193
1/2
✓ Branch 0 taken 35080 times.
✗ Branch 1 not taken.
35080 std::string substring(s.substr(prev_pos, pos - prev_pos));
194
1/2
✓ Branch 0 taken 35080 times.
✗ Branch 1 not taken.
35080 trim(substring);
195
2/4
✓ Branch 0 taken 35080 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35080 times.
✗ Branch 3 not taken.
35080 if (substring != "") {
196
1/2
✓ Branch 0 taken 35080 times.
✗ Branch 1 not taken.
35080 output.push_back(substring);
197 }
198 35080 prev_pos = ++pos;
199 35080 }
200
1/2
✓ Branch 0 taken 3148 times.
✗ Branch 1 not taken.
3148 std::string substring = s.substr(prev_pos, pos - prev_pos);
201
1/2
✓ Branch 0 taken 3148 times.
✗ Branch 1 not taken.
3148 trim(substring);
202
3/4
✓ Branch 0 taken 3148 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
✓ Branch 3 taken 2962 times.
3148 if (substring != "") {
203
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 output.push_back(substring); // Last word
204 }
205 3148 return output;
206 3148 }
207 static const unsigned char reverselookup[16] = {
208 0x0,
209 0x8,
210 0x4,
211 0xc,
212 0x2,
213 0xa,
214 0x6,
215 0xe,
216 0x1,
217 0x9,
218 0x5,
219 0xd,
220 0x3,
221 0xb,
222 0x7,
223 0xf,
224 };
225
226 34812 static inline uint8_t reverse(uint8_t n) {
227 // Reverse the top and bottom nibble then swap them.
228 34812 return (reverselookup[n & 0b1111] << 4) | reverselookup[n >> 4];
229 }
230
231 62 void OLEDPage::readCapeImage() {
232 // The image comes from the cape (its EEPROM, via fppcapedetect), so it is
233 // parsed as untrusted: a short "#define" line indexed past the split, a
234 // byte that wasn't hex threw out of stoi and ended fppoled, and nothing
235 // checked the bytes covered width x height before drawBitmap() read them.
236 // Anything off leaves no image.
237
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
62 if (FileExists("/home/fpp/media/tmp/cape-image.xbm") || FileExists("/var/tmp/cape-image.xbm")) {
238
3/6
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
124 std::string fn = FileExists("/home/fpp/media/tmp/cape-image.xbm") ? "/home/fpp/media/tmp/cape-image.xbm" : "/var/tmp/cape-image.xbm";
239
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 std::ifstream file(fn);
240
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 if (file.is_open()) {
241 62 std::string line;
242 62 bool readingBytes = false;
243 62 bool ok = true;
244 62 int width = 0;
245 62 int height = 0;
246 62 std::vector<uint8_t> image;
247
8/10
✓ Branch 0 taken 3206 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3206 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3206 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3148 times.
✓ Branch 7 taken 58 times.
✓ Branch 8 taken 3148 times.
✓ Branch 9 taken 62 times.
3210 while (ok && std::getline(file, line)) {
248
1/2
✓ Branch 0 taken 3148 times.
✗ Branch 1 not taken.
3148 trim(line);
249
2/2
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 2962 times.
3148 if (!readingBytes) {
250
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 124 times.
186 if (line.find("_width") != std::string::npos) {
251
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 std::vector<std::string> v = splitAndTrim(line, ' ');
252
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 width = v.size() > 2 ? std::atoi(v[2].c_str()) : 0;
253
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 62 times.
186 } else if (line.find("_height") != std::string::npos) {
254
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 std::vector<std::string> v = splitAndTrim(line, ' ');
255
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 height = v.size() > 2 ? std::atoi(v[2].c_str()) : 0;
256
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
124 } else if (line.find("{") != std::string::npos) {
257 62 readingBytes = true;
258
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 line = line.substr(line.find("{") + 1);
259 }
260 }
261
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 124 times.
3148 if (readingBytes) {
262
1/2
✓ Branch 0 taken 3024 times.
✗ Branch 1 not taken.
3024 std::vector<std::string> v = splitAndTrim(line, ',');
263
2/2
✓ Branch 0 taken 34874 times.
✓ Branch 1 taken 2962 times.
37836 for (auto& s : v) {
264 // The closing brace can share a token with the last
265 // byte ("0x00 };", no trailing comma): keep that byte.
266 34874 bool last = false;
267 34874 size_t brace = s.find("}");
268
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 34816 times.
34874 if (brace != std::string::npos) {
269 58 readingBytes = false;
270 58 last = true;
271
1/2
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
58 s.erase(brace);
272
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 58 times.
58 while (!s.empty() && isspace((unsigned char)s.back())) {
273 ✗ s.pop_back();
274 }
275 }
276
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 34816 times.
34874 if (s.empty()) {
277
1/2
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
58 if (last) {
278 62 break;
279 }
280 ✗ continue;
281 }
282 34816 char* end = nullptr;
283 34816 long i = strtol(s.c_str(), &end, 16);
284
8/12
✓ Branch 0 taken 34812 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 34812 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34812 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34812 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 34812 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 34812 times.
34816 if (end == s.c_str() || *end || i < 0 || i > 255 || image.size() >= 65536) {
285 4 ok = false;
286 4 break;
287 }
288 34812 uint8_t t8 = (uint8_t)i;
289 34812 t8 = ~t8;
290 34812 t8 = reverse(t8);
291
1/2
✓ Branch 0 taken 34812 times.
✗ Branch 1 not taken.
34812 image.push_back((uint8_t)t8);
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34812 times.
34812 if (last) {
293 ✗ break;
294 }
295 }
296 3024 }
297 }
298
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 file.close();
299
8/12
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 58 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 58 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 58 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 58 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 58 times.
✓ Branch 11 taken 4 times.
120 if (ok && width > 0 && width <= 256 && height > 0 && height <= 256 &&
300
1/2
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
58 image.size() >= (size_t)((width + 7) / 8) * height) {
301 58 _capeImageWidth = width;
302 58 _capeImageHeight = height;
303 58 _capeImage = std::move(image);
304 }
305 62 }
306 62 }
307 62 }
308
309 39 TitledOLEDPage::TitledOLEDPage(const std::string& t) :
310
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 title(t) {
311
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 37 times.
39 numRows = GetLEDDisplayHeight() == 128 ? 11 : 5;
312
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
39 if (oledType == OLEDPage::OLEDType::TWO_COLOR && oledFlipped) {
313 ✗ numRows = 4;
314
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 37 times.
39 } else if (oledType == OLEDPage::OLEDType::SMALL) {
315 2 numRows = 3;
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 } else if (oledType == OLEDPage::OLEDType::TEXT_ONLY) {
317 ✗ numRows = GetLEDDisplayHeight() / 8 - 1;
318 }
319 39 }
320 76 int TitledOLEDPage::displayTitle() {
321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if (oledForcedOff)
322 ✗ return 0;
323
324 76 int startY = 0;
325 76 int maxY = 63;
326
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 76 times.
76 switch (numRows) {
327 ✗ case 4:
328 ✗ maxY = 47;
329 ✗ break;
330 ✗ case 3:
331 ✗ maxY = 31;
332 ✗ break;
333 ✗ case 2:
334 ✗ maxY = 23;
335 ✗ break;
336 ✗ case 1:
337 ✗ maxY = 15;
338 ✗ break;
339 ✗ case 11:
340 ✗ maxY = 127;
341 ✗ break;
342 }
343
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
76 if (oledType == OLEDPage::OLEDType::TWO_COLOR && !oledFlipped) {
344 ✗ if (displayDriver && displayDriver->setFont("Roboto_Medium_14")) {
345 ✗ printStringCentered(startY, title);
346 ✗ displayDriver->setFont("");
347 } else {
348 ✗ printStringCentered(startY + 4, title);
349 }
350 ✗ startY += 16;
351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 } else if (oledType == OLEDPage::OLEDType::TEXT_ONLY) {
352 ✗ int mw = GetLEDDisplayWidth() / 6;
353 ✗ mw -= title.length();
354 ✗ std::string s = title;
355 ✗ if (mw > 4) {
356 ✗ s = " " + s + " ";
357 ✗ mw -= 2;
358 }
359 ✗ for (int x = 0; x < mw; x += 2) {
360 ✗ if (x != (mw - 1)) {
361 ✗ s = "=" + s + "=";
362 } else {
363 ✗ s += "=";
364 }
365 }
366 ✗ printString(0, startY, s);
367 ✗ startY += 8;
368 ✗ } else {
369 76 fillRect(0, 0, 128, 8);
370 76 drawRect(0, 0, 128, maxY + 1);
371 76 printStringCentered(startY, title, false);
372
1/2
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
76 if (maxY > 50) {
373 76 startY += 12;
374 ✗ } else if (maxY > 32) {
375 ✗ startY += 11;
376 } else {
377 ✗ startY += 8;
378 }
379 }
380 76 return startY;
381 }
382
383 1 PromptOLEDPage::PromptOLEDPage(const std::string& t, const std::string& m1, const std::string& m2,
384 1 const std::vector<std::string>& i) :
385 TitledOLEDPage(t),
386 1 msg1(m1),
387
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 msg2(m2),
388
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 items(i),
389 1 curSelected(0),
390
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 itemSelectedCallback(nullptr) {
391 1 }
392 2 PromptOLEDPage::PromptOLEDPage(const std::string& t, const std::string& m1, const std::string& m2,
393 const std::vector<std::string>& i,
394 2 const std::function<void(const std::string&)>& cb) :
395 TitledOLEDPage(t),
396 2 msg1(m1),
397
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 msg2(m2),
398
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 items(i),
399 2 curSelected(0),
400
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 itemSelectedCallback(cb) {
401 2 }
402 3 void PromptOLEDPage::displaying() {
403 3 curSelected = 0;
404 3 display();
405 3 }
406 4 void PromptOLEDPage::display() {
407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (oledForcedOff)
408 ✗ return;
409 4 clearDisplay();
410 4 int startY = displayTitle();
411
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 int skipY = numRows <= 3 ? 8 : (numRows == 4 ? 9 : 10);
412
413
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (numRows > 4) {
414 4 startY += skipY;
415 }
416
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (numRows != 1) {
417 4 printStringCentered(startY, msg1);
418 4 startY += skipY;
419
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (numRows > 2) {
420 4 printStringCentered(startY, msg2);
421 4 startY += skipY;
422 }
423 }
424
425
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!items.empty()) {
426 4 int skipX = 122 / items.size();
427
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 for (int x = 0; x < items.size(); x++) {
428
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (x == curSelected) {
429 4 fillRect(x * skipX + 4, startY, skipX, 8);
430 }
431 8 int l = items[x].length() * 6 / 2;
432 8 printString(x * skipX + 4 + skipX / 2 - l, startY, items[x], x != curSelected);
433 }
434 }
435 4 flushDisplay();
436 }
437 3 bool PromptOLEDPage::doAction(const std::string& action) {
438
5/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (action == "Down" || action == "Test/Down") {
439 1 curSelected++;
440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (curSelected == items.size()) {
441 ✗ curSelected = 0;
442 }
443 1 display();
444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (action == "Up") {
445 ✗ if (curSelected) {
446 ✗ curSelected--;
447 } else {
448 ✗ curSelected = items.size() - 1;
449 }
450 ✗ display();
451
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 } else if (action == "Enter") {
452 2 ItemSelected(items[curSelected]);
453 }
454 3 return false;
455 }
456 2 void PromptOLEDPage::ItemSelected(const std::string& item) {
457
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (itemSelectedCallback) {
458 2 itemSelectedCallback(item);
459 }
460 2 }
461
462 36 ListOLEDPage::ListOLEDPage(const std::string& t, const std::vector<std::string>& i, OLEDPage* p) :
463 TitledOLEDPage(t),
464 36 items(i),
465 36 curTop(0),
466
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 parent(p) {
467 36 }
468 ✗ void ListOLEDPage::displaying() {
469 ✗ curTop = 0;
470 ✗ display();
471 ✗ }
472 72 void ListOLEDPage::displayScrollArrows(int startY) {
473
2/6
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72 int maxY = numRows == 11 ? 127 : (numRows == 5 ? 63 : (numRows == 4 ? 47 : 31));
474
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 5 times.
72 if (items.size() > numRows) {
475
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 45 times.
67 if (curTop != 0) {
476 22 fillTriangle(116, startY + 8, 125, startY + 8, 120, startY);
477 }
478
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 6 times.
67 if ((curTop + numRows) < items.size()) {
479 61 fillTriangle(116, maxY - 10, 125, maxY - 10, 120, maxY - 2);
480 }
481 }
482 72 }
483
484 ✗ void ListOLEDPage::display() {
485 ✗ if (oledForcedOff)
486 ✗ return;
487 ✗ clearDisplay();
488 ✗ int startY = displayTitle();
489 ✗ displayScrollArrows(startY);
490 ✗ int skipY = numRows <= 3 ? 8 : (numRows == 4 ? 9 : 10);
491 ✗ int posX = 6;
492 ✗ if (oledType == OLEDPage::OLEDType::TEXT_ONLY) {
493 ✗ posX = 0;
494 }
495 ✗ for (int x = curTop; (x < items.size()) && (x < (curTop + numRows)); ++x) {
496 ✗ printString(posX, startY, items[x]);
497 ✗ startY += skipY;
498 }
499 ✗ flushDisplay();
500 }
501
502 ✗ bool ListOLEDPage::doAction(const std::string& action) {
503 ✗ if (action == "Down") {
504 ✗ if ((items.size() - curTop) < numRows) {
505 ✗ curTop++;
506 }
507 ✗ display();
508 ✗ } else if (action == "Test/Down") {
509 ✗ curTop++;
510 ✗ if ((items.size() - curTop) < numRows) {
511 ✗ curTop = 0;
512 }
513 ✗ display();
514 ✗ } else if (action == "Up") {
515 ✗ if (curTop) {
516 ✗ curTop--;
517 }
518 ✗ display();
519 ✗ } else if (action == "Enter" || (action == "Back" && parent)) {
520 ✗ SetCurrentPage(parent);
521 }
522 ✗ return true;
523 }
524
525 34 MenuOLEDPage::MenuOLEDPage(const std::string& t, const std::vector<std::string>& i, OLEDPage* p) :
526 ListOLEDPage(t, i, p),
527 34 curSelected(0),
528 34 itemSelectedCallback(nullptr) {
529 34 }
530 2 MenuOLEDPage::MenuOLEDPage(const std::string& t, const std::vector<std::string>& i,
531 const std::function<void(const std::string&)>& cb,
532 2 OLEDPage* p) :
533 ListOLEDPage(t, i, p),
534 2 curSelected(0),
535
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 itemSelectedCallback(cb) {
536 2 }
537 20 void MenuOLEDPage::displaying() {
538 20 curSelected = 0;
539 20 curTop = 0;
540 20 display();
541 20 }
542 72 void MenuOLEDPage::display() {
543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (oledForcedOff)
544 ✗ return;
545 72 clearDisplay();
546 72 int startY = displayTitle();
547 72 displayScrollArrows(startY);
548
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
72 int skipY = numRows <= 3 ? 8 : (numRows == 4 ? 9 : 10);
549
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 5 times.
72 int width = items.size() > numRows ? 110 : 120;
550 72 int posX = 6;
551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (oledType == OLEDPage::OLEDType::TEXT_ONLY) {
552 ✗ posX = 0;
553 }
554
6/6
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 353 times.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 353 times.
✓ Branch 5 taken 72 times.
425 for (int x = curTop; (x < items.size()) && (x < (curTop + numRows)); ++x) {
555
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 281 times.
353 if (curSelected == x) {
556 72 fillRect(4, startY, width, 8);
557 }
558 353 printString(posX, startY, items[x], curSelected != x);
559 353 startY += skipY;
560 }
561 72 flushDisplay();
562 }
563 69 bool MenuOLEDPage::doAction(const std::string& action) {
564 // printf("In menu action %s\n", action.c_str());
565
5/6
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 37 times.
✓ Branch 5 taken 32 times.
69 if (action == "Down" || action == "Test/Down") {
566 37 curSelected++;
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (curSelected >= items.size()) {
568 ✗ curSelected = 0;
569 ✗ curTop = 0;
570 }
571
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 37 times.
48 while ((curSelected - curTop) >= numRows) {
572 11 curTop++;
573 }
574 37 display();
575
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 19 times.
32 } else if (action == "Up") {
576
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (curSelected) {
577 13 curSelected--;
578
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 6 times.
13 if (curSelected < curTop) {
579 7 curTop = curSelected;
580 }
581 } else {
582 ✗ curSelected = items.size() - 1;
583 ✗ curTop = curSelected - numRows + 1;
584 ✗ if (curTop < 0) {
585 ✗ curTop = 0;
586 }
587 }
588 13 display();
589
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 } else if (action == "Enter") {
590 19 itemSelected(items[curSelected]);
591 ✗ } else if (action == "Back" && parent) {
592 ✗ SetCurrentPage(parent);
593 }
594 69 return true;
595 }
596
597 2 void MenuOLEDPage::itemSelected(const std::string& item) {
598
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (itemSelectedCallback) {
599 2 itemSelectedCallback(item);
600 }
601 2 }
602