GCC Code Coverage Report


Directory: ./
File: oled/FPPOLEDUtils.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 295 383 77.0%
Functions: 16 17 94.1%
Branches: 473 1026 46.1%

Line Branch Exec Source
1 #include "fpp-pch.h"
2
3 #include "fpp-json.h"
4
5 #include <sys/ioctl.h>
6 #include <sys/mman.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <gpiod.h>
10 #include <poll.h>
11 #include <set>
12 #include <unistd.h>
13
14 #include "I2C.h"
15
16 #include "FPPOLEDUtils.h"
17 #include "../common.h"
18 #include "../util/BBBUtils.h"
19
20 #include "FPPStatusOLEDPage.h"
21 #include "OLEDPages.h"
22
23 // Every interval in the run loop -- the 1s status refresh, button debounce,
24 // the display-off timeout -- is measured on this, never on GetTime(). The
25 // wall clock is routinely stepped during boot: the cape RTC registering with
26 // an unset 2000-01-01 time steps it back years, NTP steps it forward. A
27 // backward step left the refresh waiting for wall time to pass the pre-step
28 // timestamp, freezing the display on "Booting..." with fppd running.
29 717 static long long MonotonicMicros() {
30 struct timespec ts;
31 717 clock_gettime(CLOCK_MONOTONIC, &ts);
32 717 return ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
33 }
34
35 // shared memory area so other processes can see if the display is on
36 // as well as let fppoled know to force it off (if the pins need to be
37 // reconfigured so I2C no longer will work)
38
39 struct DisplayStatus {
40 unsigned int i2cBus;
41 volatile unsigned int displayOn;
42 volatile unsigned int forceOff;
43 };
44 static DisplayStatus* currentStatus;
45 static std::string controlPin;
46
47 extern I2C_DeviceT I2C_DEV_2;
48
49 31 FPPOLEDUtils::FPPOLEDUtils(int ledType) :
50 31 _ledType(ledType) {
51
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 int smfd = shm_open("fppoled", O_CREAT | O_RDWR, 0);
52 31 ftruncate(smfd, 1024);
53 31 currentStatus = (DisplayStatus*)mmap(0, 1024, PROT_WRITE | PROT_READ, MAP_SHARED, smfd, 0);
54
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 close(smfd);
55
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 int i2cb = OLEDPage::GetI2CBus();
56 31 currentStatus->i2cBus = i2cb;
57 31 currentStatus->displayOn = true;
58 31 currentStatus->forceOff = false;
59 31 statusPage = nullptr;
60 31 }
61 ✗ FPPOLEDUtils::~FPPOLEDUtils() {
62 ✗ cleanup();
63 ✗ delete statusPage;
64 ✗ }
65 31 void FPPOLEDUtils::cleanup() {
66
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 31 times.
59 for (auto& a : actions) {
67
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 delete a;
68 }
69 31 actions.clear();
70 31 }
71
72 std::atomic<int> FPPOLEDUtils::exitSignal{ 0 };
73
74 static const std::string EMPTY_STRING = "";
75
76 // gpio.json "rising"/"falling" entries were a single command object in FPP 9
77 // ({ "command": ..., "args": [...] }) and are an array of command objects in
78 // FPP 10 ([ { "command": ... }, ... ], possibly empty). Indexing an array value
79 // with a string key throws Json::LogicError and aborts fppoled, so look the
80 // navigation command up in a way that tolerates both shapes. Returns the argument
81 // of the first "OLED Navigation" command on the edge that has one, or "" if none.
82 66 static std::string findOLEDNavAction(const Json::Value& entry, const char* edge) {
83
3/6
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 66 times.
132 if (!JsonHas(entry, edge)) {
84 ✗ return "";
85 }
86
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 const Json::Value& v = entry[edge];
87 44 auto navArg = [](const Json::Value& cmd) -> std::string {
88
13/36
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 44 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 44 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 44 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 44 times.
✓ Branch 14 taken 44 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 44 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 44 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 44 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 44 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 44 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
220 if (!cmd.isObject() || JsonString(cmd, "command") != "OLED Navigation") {
89 ✗ return "";
90 }
91 44 const Json::Value& args = cmd["args"];
92
4/8
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 44 times.
✗ Branch 7 not taken.
44 if (args.isArray() && !args.empty() && args[0].isConvertibleTo(Json::stringValue)) {
93 44 return args[0].asString();
94 }
95 ✗ return "";
96 };
97
2/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
66 if (v.isObject()) {
98 ✗ return navArg(v);
99 }
100
2/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
66 if (v.isArray()) {
101
3/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 22 times.
66 for (Json::ArrayIndex i = 0; i < v.size(); i++) {
102
2/4
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
44 std::string a = navArg(v[i]);
103
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if (!a.empty()) {
104 44 return a;
105 }
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 }
107 }
108
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
44 return "";
109 }
110
111 29 FPPOLEDUtils::InputAction::~InputAction() {
112
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 29 times.
63 for (auto& a : actions) {
113
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 delete a;
114 }
115 29 actions.clear();
116 29 }
117
118 363 bool FPPOLEDUtils::InputAction::Action::checkAction(int i, long long ntimeus) {
119
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 297 times.
363 if (gpiodPin) {
120 66 i = gpiodPin->getValue();
121 }
122
6/6
✓ Branch 0 taken 237 times.
✓ Branch 1 taken 126 times.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 136 times.
✓ Branch 4 taken 93 times.
✓ Branch 5 taken 8 times.
363 if (i <= actionValueMax && i >= actionValueMin && (ntimeus > nextActionTime)) {
123 // at least 10ms since last action. Should cover any debounce time
124 93 nextActionTime = ntimeus + minActionInterval;
125 93 return true;
126 }
127 270 return false;
128 }
129 254 const std::string& FPPOLEDUtils::InputAction::checkAction(int i, long long ntimeus) {
130
2/2
✓ Branch 0 taken 363 times.
✓ Branch 1 taken 161 times.
524 for (auto& a : actions) {
131
3/4
✓ Branch 0 taken 363 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 270 times.
363 if (a->checkAction(i, ntimeus)) {
132 93 return a->action;
133 }
134 }
135 161 return EMPTY_STRING;
136 }
137
138 31 bool FPPOLEDUtils::setupControlPin(const std::string& file) {
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (FileExists(file)) {
140 ✗ Json::Value root;
141 ✗ if (LoadJsonFromFile(file, root, JsonRoot::Object)) {
142 ✗ if (root.isMember("controls") && root["controls"].isMember("I2CEnable")) {
143 ✗ controlPin = root["controls"]["I2CEnable"].asString();
144 ✗ LogInfo(VB_GPIO, "Using control pin %s\n", controlPin.c_str());
145
146 ✗ const PinCapabilities& pin = PinCapabilities::getPinByName(controlPin);
147 ✗ pin.configPin("gpio", true);
148 ✗ pin.setValue(1);
149 ✗ return true;
150 }
151 }
152 ✗ }
153 31 return false;
154 }
155
156 22 FPPOLEDUtils::InputAction* FPPOLEDUtils::configureGPIOPin(const std::string& pinName,
157 const std::string& mode,
158 const std::string& edge,
159 const std::string& name) {
160 22 const PinCapabilities& pin = PinCapabilities::getPinByName(pinName);
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (pin.ptr() == nullptr) {
162 // Unresolved pin (e.g. an expander chip that hasn't probed yet). Let the
163 // caller skip it instead of building a polling action on the null pin.
164 ✗ return nullptr;
165 }
166
167 // configPin() puts the process name ("FPPOLED-") in front of it
168 22 pin.configPin(mode, false, name);
169
170 // configPin() warns and carries on when the line request fails, which it does
171 // for a pin the kernel has handed to a peripheral -- under strict pinmux that
172 // is permanent for, say, a button sharing GPIO15 with an enabled uart0. Such
173 // a pin cannot be read: getValue() returns a flat 0, and for an active-low
174 // input 0 is "pressed", so registering it would fire the action continuously.
175 //
176 // This is NOT the same as having no event file. An expander line with no
177 // interrupt has no fd and is polled through getValue(), which is a working
178 // path and must keep working; the question here is only whether the line was
179 // ever acquired.
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (!pin.isAcquired()) {
181 ✗ LogWarn(VB_GPIO, "Skipping input %s: the line could not be acquired, so it cannot be read\n",
182 pinName.c_str());
183 ✗ return nullptr;
184 }
185
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 InputAction* action = new InputAction();
187 22 action->pin = pinName;
188 22 action->mode = mode;
189 22 action->gpiodPin = pin.ptr();
190
191 // Always request BOTH edges, even when this pin only acts on one of them.
192 // Some I2C GPIO expanders (e.g. the pca9675/pcf857x behind a device-tree
193 // interrupt line) have an irqchip that interrupts on every line change and
194 // ignores the requested edge type. If we ask the kernel for a single edge,
195 // gpiolib blindly stamps every interrupt with that edge, so a button's
196 // release gets reported as another press and the action fires twice. When
197 // both edges are requested, gpiolib samples the line level per interrupt and
198 // reports the true direction; checkAction() then filters to the wanted edge
199 // via the per-action min/max value. On regular SoC GPIOs the extra (release)
200 // edge is simply filtered out, so this is safe everywhere. The unused `edge`
201 // hint is retained in the signature for callers/back-compat.
202 (void)edge;
203 22 action->file = pin.requestEventFile(true, true);
204 22 return action;
205 }
206 33 void FPPOLEDUtils::setInputFlag(const std::string& action) {
207
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 23 times.
33 if (action == "Up") {
208 10 inputFlags |= 0x01;
209
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 14 times.
23 } else if (action == "Down") {
210 9 inputFlags |= 0x02;
211
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 } else if (action == "Back") {
212 1 inputFlags |= 0x04;
213
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 } else if (action == "Enter") {
214 13 inputFlags |= 0x08;
215 ✗ } else if (action == "Test") {
216 ✗ inputFlags |= 0x10;
217 ✗ } else if (action == "Test/Down") {
218 ✗ inputFlags |= 0x10;
219 ✗ inputFlags |= 0x02;
220 }
221 33 }
222
223 31 bool FPPOLEDUtils::parseInputActionFromGPIO(const std::string& file) {
224 char vbuffer[256];
225 31 bool needsPolling = false;
226
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 21 times.
31 if (FileExists(file)) {
227
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 Json::Value root;
228
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if (LoadJsonFromFile(file, root, JsonRoot::Array)) {
229
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 10 times.
32 for (int x = 0; x < root.size(); x++) {
230
8/16
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 22 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 22 times.
22 if (!root[x].isObject() || !root[x]["enabled"].asBool()) {
231 ✗ continue;
232 }
233
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
44 std::string edge = "";
234
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 std::string actionValue = "";
235
3/6
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
22 std::string mode = root[x]["mode"].asString();
236
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 if (mode == "") {
237 ✗ mode = "gpio";
238 }
239
3/6
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
22 std::string pinName = root[x]["pin"].asString();
240
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 std::string fallingAction = findOLEDNavAction(root[x], "falling");
241
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 std::string risingAction = findOLEDNavAction(root[x], "rising");
242
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (!fallingAction.empty()) {
243
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 edge = "falling";
244
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 setInputFlag(fallingAction);
245 }
246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (!risingAction.empty()) {
247 ✗ if (edge == "falling") {
248 ✗ edge = "both";
249 } else {
250 ✗ edge = "rising";
251 }
252 ✗ setInputFlag(risingAction);
253 }
254
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 if (edge != "") {
255
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 InputAction* action = configureGPIOPin(pinName, mode, edge, risingAction.empty() ? fallingAction : risingAction);
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (action == nullptr) {
257 // pin didn't resolve to a real GPIO line -- skip rather than
258 // poll a null pin (getValue()==0) and flood with phantom presses
259 ✗ LogWarn(VB_GPIO, "Skipping input %s: GPIO line not available\n", pinName.c_str());
260 ✗ continue;
261 }
262
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 if (risingAction != "") {
263 ✗ LogInfo(VB_GPIO, "Configuring pin %s as input of type %s (mode: %s, file: %d)\n", action->pin.c_str(), risingAction.c_str(), action->mode.c_str(), action->file);
264 ✗ action->actions.push_back(new FPPOLEDUtils::InputAction::Action(risingAction, 1, 1, 100000, action->file == -1 ? action->gpiodPin : nullptr));
265 }
266
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
22 if (fallingAction != "") {
267
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 LogInfo(VB_GPIO, "Configuring pin %s as input of type %s (mode: %s, file: %d)\n", action->pin.c_str(), fallingAction.c_str(), action->mode.c_str(), action->file);
268
6/12
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 22 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
22 action->actions.push_back(new FPPOLEDUtils::InputAction::Action(fallingAction, 0, 0, 100000, action->file == -1 ? action->gpiodPin : nullptr));
269 }
270
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 actions.push_back(action);
271
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 21 times.
22 if (action->file == -1) {
272 1 needsPolling = true;
273 }
274 }
275
6/12
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✗ Branch 11 not taken.
22 }
276 }
277 10 }
278 31 return needsPolling;
279 }
280
281 31 bool FPPOLEDUtils::parseInputActions(const std::string& file) {
282 char vbuffer[256];
283 31 bool needsPolling = false;
284
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 24 times.
31 if (FileExists(file)) {
285
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 Json::Value root;
286
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 if (LoadJsonFromFile(file, root, JsonRoot::Object)) {
287
4/6
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 7 times.
14 for (int x = 0; x < root["inputs"].size(); x++) {
288
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 InputAction* action = new InputAction();
289
4/8
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
7 std::string pin = root["inputs"][x]["pin"].asString();
290
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 for (auto& a : actions) {
291
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 if (a->pin == pin && action) {
292
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 delete action;
293 1 action = nullptr;
294 // Built up and logged as one line: a log line is one
295 // record with its own timestamp/prefix, so the piecemeal
296 // printf() version would come out as a header line
297 // followed by an orphaned line per action.
298 1 std::string configured;
299
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 for (auto aa : a->actions) {
300
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 configured += aa->action;
301
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 configured += " ";
302 }
303
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogInfo(VB_GPIO, "Skipping %s. Already configured for actions: %s\n", pin.c_str(), configured.c_str());
304 1 }
305 }
306
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (action == nullptr) {
307 1 continue;
308 }
309
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 action->pin = pin;
310
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
6 action->mode = root["inputs"][x]["mode"].asString();
311
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (action->mode.find("gpio") != std::string::npos) {
312
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
5 std::string edge = root["inputs"][x]["edge"].asString();
313
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
5 std::string type = root["inputs"][x]["type"].asString();
314
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 int actionValue = (edge == "falling" ? 0 : 1);
315
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 const PinCapabilities& pin = PinCapabilities::getPinByName(action->pin);
316
317
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (pin.ptr() == nullptr) {
318 // The pin didn't resolve to a real GPIO line -- e.g. an i2c
319 // expander whose chip hasn't probed yet (run() waits for this,
320 // but bail defensively if it timed out). Falling through would
321 // create a polling action on the null pin, whose getValue() is
322 // always 0, flooding the menu with phantom presses.
323 ✗ LogWarn(VB_GPIO, "Skipping input %s: GPIO line not available\n", action->pin.c_str());
324 ✗ delete action;
325 ✗ continue;
326 }
327
328
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 action->gpiodPin = pin.ptr();
329
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string nameDesc = type;
330
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
5 if (type == "gpiod") {
331
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 nameDesc = "Interrupt";
332 }
333
334
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 pin.configPin(action->mode, false, nameDesc);
335 // Request BOTH edges even though each button only acts on one.
336 // I2C GPIO expanders (pca9675/pcf857x) interrupt on every line
337 // change and ignore the requested edge type; asking for a single
338 // edge makes the kernel mislabel the button release as another
339 // press, firing the action twice. With both edges requested,
340 // gpiolib reports the true direction and checkAction() (below)
341 // filters to the desired edge via actionValue. Harmless on real
342 // SoC GPIOs, where the extra release edge is just filtered out.
343
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 action->file = pin.requestEventFile(true, true);
344
345
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
5 if (type == "gpiod") {
346 // this is the mode for various gpio extenders like the pca9675 chip that
347 // use a single interrupt line (configured above) for all the buttons.
348 // The above will trigger an interrupt after which we will need to
349 // use libgpiod to get the value of each button to figure out
350 // which triggered the action. Thus, there are multiple actions
351
352
4/8
✓ 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.
4 std::string label = root["inputs"][x]["chip"].asString();
353
6/10
✓ 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 8 times.
✓ Branch 9 taken 4 times.
12 for (int a = 0; a < root["inputs"][x]["actions"].size(); a++) {
354
6/12
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
8 std::string buttonaction = root["inputs"][x]["actions"][a]["action"].asString();
355
6/12
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
8 int gpioline = root["inputs"][x]["actions"][a]["line"].asInt();
356
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 std::string pinName = label + "-" + std::to_string(gpioline);
357
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 auto& pinCap = PinCapabilities::getPinByName(pinName);
358
359
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (pinCap.ptr()) {
360
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
16 pinCap.configPin("gpio", false, buttonaction);
361
362
5/12
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
8 action->actions.push_back(new FPPOLEDUtils::InputAction::Action(buttonaction, 0, 0, 100000, pinCap.ptr()));
363 // Record which navigation buttons exist, exactly as the
364 // one-pin-per-button branch below does. Menus that need a
365 // full Up/Down/Back/Enter set (the Network config pages)
366 // are hidden when this isn't done, so a cape whose buttons
367 // hang off an expander would silently lose them.
368
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 setInputFlag(buttonaction);
369 }
370 8 }
371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (action->file == -1) {
372 // No interrupt line: the buttons are still readable via
373 // getValue() on each expander line, but only if we poll.
374 ✗ needsPolling = true;
375 }
376
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
5 } else if (action->file == -1) {
377 1 needsPolling = true;
378
5/12
✓ 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.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1 action->actions.push_back(new FPPOLEDUtils::InputAction::Action(type, actionValue, actionValue, 100000, pin.ptr()));
379 } else {
380 ✗ LogInfo(VB_GPIO, "Configuring pin %s as input of type %s (mode: %s)\n", action->pin.c_str(), type.c_str(), action->mode.c_str());
381 ✗ action->actions.push_back(new FPPOLEDUtils::InputAction::Action(type, actionValue, actionValue, 100000));
382 ✗ setInputFlag(type);
383 }
384
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 actions.push_back(action);
385
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
6 } else if (action->mode == "ain") {
386 char path[256];
387
4/8
✓ 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.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 snprintf(path, sizeof(path), "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw", root["inputs"][x]["input"].asInt());
388
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (FileExists(path)) {
389
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 action->file = open(path, O_RDONLY);
390
6/10
✓ 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 3 times.
✓ Branch 9 taken 1 times.
4 for (int a = 0; a < root["inputs"][x]["actions"].size(); a++) {
391
6/12
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 std::string buttonaction = root["inputs"][x]["actions"][a]["action"].asString();
392
6/12
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 int minValue = root["inputs"][x]["actions"][a]["minValue"].asInt();
393
6/12
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 int maxValue = root["inputs"][x]["actions"][a]["maxValue"].asInt();
394
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 LogInfo(VB_GPIO, "Configuring AIN input of type %s with range %d-%d\n", buttonaction.c_str(), minValue, maxValue);
395
4/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
3 action->actions.push_back(new FPPOLEDUtils::InputAction::Action(buttonaction, minValue, maxValue, 250000));
396
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 setInputFlag(buttonaction);
397 3 }
398
399
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 actions.push_back(action);
400 1 needsPolling = true;
401 }
402 }
403
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 }
404 }
405 7 }
406
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 fflush(stdout);
407 31 return needsPolling;
408 }
409
410 // Gather the GPIO input pin names referenced by the fppoled input configs so
411 // run() can wait for them to become resolvable before configuring them.
412 31 static std::set<std::string> collectConfiguredGpioPins() {
413 31 std::set<std::string> names;
414
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 Json::Value root;
415 // cape-inputs.json: { "inputs": [ { "pin", "mode":"gpio*", "type", [chip/actions] } ] }
416
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 24 times.
38 if (FileExists("/home/fpp/media/tmp/cape-inputs.json") &&
417
9/16
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 24 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 24 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 24 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
45 LoadJsonFromFile("/home/fpp/media/tmp/cape-inputs.json", root, JsonRoot::Object)) {
418
4/6
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 7 times.
14 for (int x = 0; x < root["inputs"].size(); x++) {
419
4/8
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✗ Branch 7 not taken.
7 std::string mode = root["inputs"][x]["mode"].asString();
420
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (mode.find("gpio") == std::string::npos) {
421 1 continue;
422 }
423
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
6 std::string pin = root["inputs"][x]["pin"].asString();
424
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!pin.empty()) {
425
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 names.insert(pin);
426 }
427
7/12
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 2 times.
6 if (root["inputs"][x]["type"].asString() == "gpiod") {
428
4/8
✓ 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.
4 std::string label = root["inputs"][x]["chip"].asString();
429
6/10
✓ 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 8 times.
✓ Branch 9 taken 4 times.
12 for (int a = 0; a < root["inputs"][x]["actions"].size(); a++) {
430
6/12
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
8 int gpioline = root["inputs"][x]["actions"][a]["line"].asInt();
431
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
8 names.insert(label + "-" + std::to_string(gpioline));
432 }
433 4 }
434
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 }
435 }
436 // gpio.json: [ { "enabled", "pin", "rising"/"falling": [ {"command":"OLED Navigation","args":[..]} ] } ]
437 // (FPP 9 wrote a single command object instead of an array; findOLEDNavAction accepts both)
438
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 root = Json::Value();
439
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 21 times.
41 if (FileExists("/home/fpp/media/config/gpio.json") &&
440
9/16
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 21 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 21 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 21 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
51 LoadJsonFromFile("/home/fpp/media/config/gpio.json", root, JsonRoot::Array)) {
441
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 10 times.
32 for (int x = 0; x < root.size(); x++) {
442
8/16
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 22 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 22 times.
22 if (!root[x].isObject() || !root[x]["enabled"].asBool()) {
443 ✗ continue;
444 }
445
3/8
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
44 bool nav = !findOLEDNavAction(root[x], "falling").empty() ||
446
2/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 22 times.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
22 !findOLEDNavAction(root[x], "rising").empty();
447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (!nav) {
448 ✗ continue;
449 }
450
3/6
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
22 std::string pin = root[x]["pin"].asString();
451
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (!pin.empty()) {
452
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 names.insert(pin);
453 }
454 22 }
455 }
456 31 return names;
457 31 }
458
459 // Cape GPIO expanders (e.g. the pca9675 the buttons live on) are instantiated by
460 // a device-tree overlay applied during cape detection, and their I2C driver
461 // probes asynchronously -- the gpiochip (and its named lines) can appear a short
462 // time after cape_detect_done. If we configure the inputs before then, every pin
463 // resolves to the null pin and the menu floods with phantom presses. Wait, re-
464 // scanning as chips appear, until all configured input pins resolve (or we hit
465 // the timeout, after which the null-pin guards keep us from flooding).
466 31 static void waitForInputPins() {
467
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 std::set<std::string> names = collectConfiguredGpioPins();
468
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 15 times.
31 if (names.empty()) {
469 16 return;
470 }
471 15 const int maxWaitMS = 15000;
472 15 int waited = 0;
473 while (true) {
474 25 std::vector<std::string> missing;
475
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 25 times.
80 for (const auto& n : names) {
476
4/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 45 times.
55 if (PinCapabilities::getPinByName(n).ptr() == nullptr) {
477
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 missing.push_back(n);
478 }
479 }
480
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 10 times.
25 if (missing.empty()) {
481
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14 times.
15 if (waited) {
482
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogInfo(VB_GPIO, "All %d configured input pin(s) resolved after %dms\n", (int)names.size(), waited);
483 }
484 15 return;
485 }
486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (waited >= maxWaitMS) {
487 ✗ std::string missingNames;
488 ✗ for (const auto& n : missing) {
489 ✗ missingNames += " ";
490 ✗ missingNames += n;
491 }
492 ✗ LogWarn(VB_GPIO, "Timed out after %dms waiting for %d input pin(s) to appear:%s\n", waited, (int)missing.size(), missingNames.c_str());
493 ✗ return;
494 ✗ }
495
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 usleep(200000);
496 10 waited += 200;
497
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 PinCapabilities::RescanGPIO();
498
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 15 times.
35 }
499 31 }
500
501 31 void FPPOLEDUtils::run() {
502 char vbuffer[256];
503
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 waitForInputPins();
504
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
62 setupControlPin("/home/fpp/media/tmp/cape-info.json");
505
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
62 bool needsPolling = parseInputActionFromGPIO("/home/fpp/media/config/gpio.json");
506
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 needsPolling |= parseInputActions("/home/fpp/media/tmp/cape-inputs.json");
507
508
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
62 std::vector<struct pollfd> fdset(actions.size());
509
510
4/6
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 31 times.
31 if (actions.size() == 0 && _ledType == 0) {
511 // no display and no actions, nothing to do.
512 ✗ exit(0);
513 }
514
515 31 OLEDPage::SetHas4DirectionControls((inputFlags & 0x0F) == 0x0F);
516
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 LogInfo(VB_GPIO, "Input flags: 0x%02X (Up/Down/Back/Enter all present: %s)\n",
517 inputFlags, OLEDPage::Has4DirectionControls() ? "yes" : "no");
518
519
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 statusPage = new FPPStatusOLEDPage();
520
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 OLEDPage::SetCurrentPage(statusPage);
521
522 31 long long lastUpdateTime = 0;
523 31 long long ntime = MonotonicMicros();
524 31 long long lastActionTime = MonotonicMicros();
525
2/2
✓ Branch 0 taken 359 times.
✓ Branch 1 taken 31 times.
421 while (exitSignal.load() == 0) {
526 359 bool forcedOff = currentStatus->forceOff;
527
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 359 times.
359 if (OLEDPage::IsForcedOff() && !forcedOff) {
528 // turning back on
529 ✗ if (controlPin != "") {
530 ✗ LogInfo(VB_GPIO, "Re-enabling I2C Bus via pin: %s\n", controlPin.c_str());
531 ✗ const PinCapabilities& pin = PinCapabilities::getPinByName(controlPin);
532 ✗ pin.configPin("gpio", true);
533 ✗ pin.setValue(1);
534 }
535 ✗ OLEDPage::SetForcedOff(forcedOff);
536 ✗ currentStatus->displayOn = true;
537 ✗ OLEDPage::SetCurrentPage(statusPage);
538 ✗ lastActionTime = MonotonicMicros();
539
3/6
✓ Branch 0 taken 359 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 359 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 359 times.
359 } else if (!OLEDPage::IsForcedOff() && forcedOff) {
540 ✗ if (currentStatus->displayOn) {
541 ✗ if (OLEDPage::GetOLEDType() != OLEDPage::OLEDType::NONE) {
542 ✗ OLEDPage::displayOff();
543 }
544 }
545 ✗ if (controlPin != "") {
546 ✗ LogInfo(VB_GPIO, "Disabling I2C Bus via pin: %s\n", controlPin.c_str());
547 ✗ const PinCapabilities& pin = PinCapabilities::getPinByName(controlPin);
548 ✗ pin.configPin("gpio", true);
549 ✗ pin.setValue(0);
550 }
551 ✗ OLEDPage::SetForcedOff(forcedOff);
552 ✗ currentStatus->displayOn = false;
553 ✗ OLEDPage::SetCurrentPage(statusPage);
554 }
555
2/2
✓ Branch 0 taken 203 times.
✓ Branch 1 taken 156 times.
359 if (ntime > (lastUpdateTime + 1000000)) {
556 203 bool displayOn = currentStatus->displayOn;
557
6/8
✓ Branch 0 taken 203 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 203 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 116 times.
✓ Branch 5 taken 87 times.
✓ Branch 6 taken 116 times.
✓ Branch 7 taken 87 times.
203 if (OLEDPage::GetCurrentPage() && OLEDPage::GetCurrentPage()->doIteration(displayOn)) {
558 116 lastActionTime = MonotonicMicros();
559 }
560 203 currentStatus->displayOn = displayOn;
561 203 lastUpdateTime = ntime;
562 }
563
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 279 times.
359 if (actions.empty()) {
564
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 sleep(1);
565 80 ntime = MonotonicMicros();
566 } else {
567 279 memset((void*)&fdset[0], 0, sizeof(struct pollfd) * actions.size());
568 279 int actionCount = 0;
569
2/2
✓ Branch 0 taken 558 times.
✓ Branch 1 taken 279 times.
837 for (int x = 0; x < actions.size(); x++) {
570
7/8
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✓ Branch 3 taken 56 times.
✓ Branch 4 taken 459 times.
✓ Branch 5 taken 43 times.
✓ Branch 6 taken 459 times.
✓ Branch 7 taken 99 times.
558 if (actions[x]->mode != "ain" && actions[x]->file >= 0) {
571 459 fdset[actionCount].fd = actions[x]->file;
572 459 fdset[actionCount].events = POLLIN | POLLPRI;
573 459 actions[x]->pollIndex = actionCount;
574 459 actionCount++;
575 }
576 }
577
578
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 99 times.
279 if (actionCount) {
579 // Wake no later than the next 1s page iteration. The status
580 // page counts iterations as seconds ("FPP Booting..." becomes
581 // "No Network" after 60), so a longer idle wait slows all of
582 // its timing down by the same factor.
583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180 times.
180 int timeout = needsPolling ? 100 : 1000;
584 180 long long untilUpdate = (lastUpdateTime + 1000000 - MonotonicMicros()) / 1000 + 1;
585
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 97 times.
180 if (untilUpdate < timeout) {
586
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 timeout = untilUpdate < 1 ? 1 : (int)untilUpdate;
587 }
588
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 poll(&fdset[0], actionCount, timeout);
589 } else {
590
1/2
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
99 usleep(100000);
591 }
592 279 ntime = MonotonicMicros();
593
2/2
✓ Branch 0 taken 558 times.
✓ Branch 1 taken 279 times.
837 for (int x = 0; x < actions.size(); x++) {
594 558 std::string action;
595 // printf("%x: %s f: %d pi: %d\n", x, actions[x]->pin.c_str(), actions[x]->file, actions[x]->pollIndex);
596
3/4
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 502 times.
558 if (actions[x]->mode == "ain") {
597 56 lseek(actions[x]->file, 0, SEEK_SET);
598
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 int len = read(actions[x]->file, vbuffer, 255);
599 56 int v = atoi(vbuffer);
600
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
56 action = actions[x]->checkAction(v, ntime);
601
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 459 times.
502 } else if (actions[x]->file == -1) {
602
2/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
43 action = actions[x]->checkAction(0, ntime);
603
2/2
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 304 times.
459 } else if (fdset[actions[x]->pollIndex].revents) {
604
1/2
✓ Branch 0 taken 155 times.
✗ Branch 1 not taken.
155 int v = actions[x]->gpiodPin->readEventFromFile();
605
2/4
✓ Branch 0 taken 155 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 155 times.
✗ Branch 3 not taken.
155 action = actions[x]->checkAction(v, ntime);
606 }
607
5/8
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 465 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 93 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 558 times.
558 if (action != "" && !currentStatus->displayOn) {
608 // just turn the display on if button is hit
609 ✗ if (!currentStatus->forceOff) {
610 ✗ currentStatus->displayOn = true;
611 ✗ OLEDPage::SetCurrentPage(statusPage);
612 ✗ lastUpdateTime = 0;
613 ✗ lastActionTime = ntime;
614 ✗ } else if ((action == "Test" || action == "Test/Down") && ((ntime - lastActionTime) > 70000)) {
615 ✗ LogDebug(VB_COMMAND, "OLED button action: %s (gap since last action: %lldus)\n", action.c_str(), (long long)(ntime - lastActionTime));
616 ✗ lastUpdateTime = 0;
617 ✗ lastActionTime = ntime;
618 ✗ if (OLEDPage::GetCurrentPage()) {
619 ✗ OLEDPage::GetCurrentPage()->doAction(action);
620 }
621 }
622
7/8
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 465 times.
✓ Branch 4 taken 91 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 91 times.
✓ Branch 7 taken 467 times.
558 } else if (action != "" && ((ntime - lastActionTime) > 70000)) { // account for some debounce time
623
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 LogDebug(VB_COMMAND, "OLED button action: %s (gap since last action: %lldus)\n", action.c_str(), (long long)(ntime - lastActionTime));
624 // force immediate update
625 91 lastUpdateTime = 0;
626 91 lastActionTime = ntime;
627
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 if (OLEDPage::GetCurrentPage()) {
628
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 OLEDPage::GetCurrentPage()->doAction(action);
629 }
630 }
631 558 }
632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (ntime > (lastActionTime + 180000000)) {
633 ✗ if (OLEDPage::GetCurrentPage() != statusPage) {
634 ✗ OLEDPage::SetCurrentPage(statusPage);
635 }
636 ✗ OLEDPage::displayOff();
637 ✗ currentStatus->displayOn = false;
638 }
639 }
640 }
641 31 }
642