summaryrefslogtreecommitdiffhomepage
path: root/StatusLED.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-20 20:39:10 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-20 20:39:10 +0100
commit5fd637644c7529bfdc5291215f3f8ee1edd304c4 (patch)
tree2f135c3cae2bc034aa27b33b39dca95b992cb69f /StatusLED.cpp
parentef578ac72a70bfbe8aee726d43374c841d77ade4 (diff)
Fixed status led
Diffstat (limited to 'StatusLED.cpp')
-rw-r--r--StatusLED.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/StatusLED.cpp b/StatusLED.cpp
index 3013ddb..711257d 100644
--- a/StatusLED.cpp
+++ b/StatusLED.cpp
@@ -1,21 +1,33 @@
#include "StatusLED.h"
+#include <iostream>
+
+#include <fmt/format.h>
+#include <libreichwein/file.h>
+
namespace fs = std::filesystem;
StatusLED::StatusLED(): m_mode{Mode::OK}, m_bpm{60}
{
}
-void StatusLED::addLED(const LED& led)
+void StatusLED::add(const LED& led)
{
if (fs::exists(led.green) && fs::exists(led.red)) {
- m_leds.push_back(led);
+ if (init(led)) {
+ m_leds.push_back(led);
+ update(led);
+ }
}
}
void StatusLED::setMode(Mode mode)
{
m_mode = mode;
+
+ for (const auto& i: m_leds) {
+ update(i);
+ }
}
void StatusLED::setBPM(int bpm)
@@ -23,10 +35,31 @@ void StatusLED::setBPM(int bpm)
m_bpm = bpm;
}
-void StatusLED::initLED(const LED& led)
+bool StatusLED::init(const LED& led)
{
+ try {
+ Reichwein::File::setFile(led.green / "trigger", "none");
+ Reichwein::File::setFile(led.red / "trigger", "none");
+ return true;
+ } catch (...) {
+ return false;
+ }
}
-void StatusLED::updateLED(const LED& led)
+void StatusLED::update(const LED& led)
{
+ int green{};
+ int red{};
+
+ if (m_mode == Mode::OK) {
+ green = 255;
+ } else if (m_mode == Mode::Error) {
+ red = 255;
+ } else {
+ throw std::runtime_error("LED mode unimplemented");
+ }
+
+ Reichwein::File::setFile(led.green / "brightness", fmt::format("{}", green));
+ Reichwein::File::setFile(led.red / "brightness", fmt::format("{}", red));
}
+