Skip to content

Commit

Permalink
If a pin cannot be configured, display a warning, but don't crash
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Nov 15, 2024
1 parent a117c89 commit 5d76dea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/oled/fppoled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
#endif
#include <thread>

class WarningHolder {
static void AddWarning(const std::string& w);
};

void WarningHolder::AddWarning(const std::string& w) {
printf("Warning: %s\n", w.c_str());
}

static FPPOLEDUtils* oled = nullptr;
void sigInteruptHandler(int sig) {
oled->cleanup();
Expand Down
7 changes: 6 additions & 1 deletion src/util/GPIOUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <thread>

#include "GPIOUtils.h"
#include "../Warnings.h"
#include "commands/Commands.h"

// No platform information on how to control pins
Expand Down Expand Up @@ -145,7 +146,11 @@ int GPIODCapabilities::configPin(const std::string& mode,
if (line.is_requested()) {
line.release();
}
line.request(req, 1);
try {
line.request(req, 1);
} catch (const std::exception& ex) {
WarningHolder::AddWarning("Could not configure pin " + name + " as " + mode + " (" + ex.what() + ")");
}
lastRequestType = req.request_type;
}
#endif
Expand Down

0 comments on commit 5d76dea

Please sign in to comment.