#include "StatusLED.h" #include #include #include namespace fs = std::filesystem; StatusLED::StatusLED(): m_mode{Mode::OK}, m_bpm{60} { } void StatusLED::add(const LED& led) { if (fs::exists(led.green) && fs::exists(led.red)) { 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) { m_bpm = bpm; } 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::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)); }