Skip to content

Commit 5d76dea

Browse files
committed
If a pin cannot be configured, display a warning, but don't crash
1 parent a117c89 commit 5d76dea

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/oled/fppoled.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
#endif
2929
#include <thread>
3030

31+
class WarningHolder {
32+
static void AddWarning(const std::string& w);
33+
};
34+
35+
void WarningHolder::AddWarning(const std::string& w) {
36+
printf("Warning: %s\n", w.c_str());
37+
}
38+
3139
static FPPOLEDUtils* oled = nullptr;
3240
void sigInteruptHandler(int sig) {
3341
oled->cleanup();

src/util/GPIOUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <thread>
1919

2020
#include "GPIOUtils.h"
21+
#include "../Warnings.h"
2122
#include "commands/Commands.h"
2223

2324
// No platform information on how to control pins
@@ -145,7 +146,11 @@ int GPIODCapabilities::configPin(const std::string& mode,
145146
if (line.is_requested()) {
146147
line.release();
147148
}
148-
line.request(req, 1);
149+
try {
150+
line.request(req, 1);
151+
} catch (const std::exception& ex) {
152+
WarningHolder::AddWarning("Could not configure pin " + name + " as " + mode + " (" + ex.what() + ")");
153+
}
149154
lastRequestType = req.request_type;
150155
}
151156
#endif

0 commit comments

Comments
 (0)