diff --git a/include/LCDDisplay.hpp b/include/LCDDisplay.hpp index 558334c..7e41237 100644 --- a/include/LCDDisplay.hpp +++ b/include/LCDDisplay.hpp @@ -9,20 +9,6 @@ #include class LCDDisplay { - private: - int _lcd = -1; - std::string _dev; - std::array writebuf{}; // 4x40 chars + 2x4 setcursor commands - static constexpr bool dualDisp = (LCD_LINES * LCD_COLS > 80); // is it dual display device or not, evauluated from the size at compile time - - void open(bool reopen = false); - void write(const uint8_t* cmdbuf, uint8_t len); - void close(); - - // we avoid using these, use buffer (even if these are faster for small writes, perhaps a rewrite is in order) - void writeStr(const std::string& str); - void writeStr(uint8_t row, uint8_t col, const std::string& str); - public: explicit LCDDisplay(const std::string& dev, uint32_t baud = 0010002); // from termios-baud.h, B115200 ~LCDDisplay(); @@ -41,6 +27,20 @@ class LCDDisplay { // returns custom char no. c, small enough to define in header static constexpr char cc(const uint8_t c) { return static_cast(c % 8); } + + private: + int lcd = -1; + std::string dev; + std::array writebuf{}; // 4x40 chars + 2x4 setcursor commands + static constexpr bool dualDisp = (LCD_LINES * LCD_COLS > 80); // is it dual display device or not, evauluated from the size at compile time + + void open(bool reopen = false); + void write(const uint8_t* cmdbuf, uint8_t len); + void close(); + + // we avoid using these, use buffer (even if these are faster for small writes, perhaps a rewrite is in order) + void writeStr(const std::string& str); + void writeStr(uint8_t row, uint8_t col, const std::string& str); }; #endif diff --git a/include/gpu_metrics.hpp b/include/gpu_metrics.hpp index 7088aa1..11cd56a 100644 --- a/include/gpu_metrics.hpp +++ b/include/gpu_metrics.hpp @@ -795,6 +795,6 @@ struct gpu_metrics_v3_0 { /* Metrics table alpha filter time constant [us] */ uint32_t time_filter_alphavalue; }; -} // namespace gpu +} // namespace metrics #endif diff --git a/include/hass.hpp b/include/hass.hpp index 3c448d6..b606800 100644 --- a/include/hass.hpp +++ b/include/hass.hpp @@ -7,7 +7,7 @@ #include class HomeAssistant { - public: + public: struct Config { std::string address; std::string entity; diff --git a/src/LCDDisplay.cpp b/src/LCDDisplay.cpp index e4b0a8a..22c7dc4 100644 --- a/src/LCDDisplay.cpp +++ b/src/LCDDisplay.cpp @@ -12,7 +12,7 @@ /* lcd size hardcoded to 4x40 idgaf */ LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) { - _dev = dev; + this->dev = dev; this->open(); // calls this (LCDDisplay) open() function, LCDDisplay::open() struct termios term{}; @@ -21,15 +21,15 @@ LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) { term.c_iflag = 0; term.c_oflag = 0; term.c_lflag = 0; - tcflush(_lcd, TCIFLUSH); - tcsetattr(_lcd, TCSANOW, &term); + tcflush(lcd, TCIFLUSH); + tcsetattr(lcd, TCSANOW, &term); // init linebuf to spaces this->clearBuf(); // disable underline and block cursor constexpr uint8_t cmdbuf[] = {254, 75, 254, 84}; - ::write(_lcd, &cmdbuf, sizeof(cmdbuf)); + ::write(lcd, &cmdbuf, sizeof(cmdbuf)); // clear display and set cursor home this->clear(); @@ -40,25 +40,25 @@ LCDDisplay::~LCDDisplay() { } void LCDDisplay::open(const bool reopen) { - applog(LOG::INF, "Opening serial port at \"{}\"", _dev); - if (_lcd < 0 || reopen) - _lcd = ::open(_dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); // ::open calls the global open() instead of LCDDisplay::open() - if (_lcd < 0) { - applog(LOG::ERR, "Error opening serial port \"{}\"", _dev); // err - exit(_lcd); + applog(LOG::INF, "Opening serial port at \"{}\"", dev); + if (lcd < 0 || reopen) + lcd = ::open(dev.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); // ::open calls the global open() instead of LCDDisplay::open() + if (lcd < 0) { + applog(LOG::ERR, "Error opening serial port \"{}\"", dev); // err + exit(lcd); } } void LCDDisplay::close() { - if (_lcd >= 0) { - ::close(_lcd); + if (lcd >= 0) { + ::close(lcd); applog(LOG::INF, "LCD port closed"); } - _lcd = -1; + lcd = -1; } void LCDDisplay::write(const uint8_t* cmdbuf, const uint8_t len) { - if (::write(_lcd, cmdbuf, len) != len) { + if (::write(lcd, cmdbuf, len) != len) { applog(LOG::ERR, "failed to execute ::write, lost access to port?"); this->open(true); } diff --git a/src/app.cpp b/src/app.cpp index a51f561..580c35c 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -20,8 +20,8 @@ void Application::hassThread(const std::stop_token& st) { applog(LOG::START, "Thread started"); HomeAssistant::Config config; config.address = m_config.hass.url; - config.entity = m_config.hass.entity; - config.token = m_config.hass.token; + config.entity = m_config.hass.entity; + config.token = m_config.hass.token; HomeAssistant pc_power(config); pc_power.connect(); @@ -87,7 +87,7 @@ void Application::displayThread(const std::stop_token& st) { // actual main display loop while (!st.stop_requested()) { m_control.display.try_acquire_for(std::chrono::milliseconds(static_cast(m_config.lcd.refresh_interval_ms * 1.25))); // holds the loop until sensor data is ready, max 1.25x of the loop time - if (st.stop_requested()) break; // needed, otherwise it wont quit correctly + if (st.stop_requested()) break; // needed, otherwise it wont quit correctly { std::lock_guard lock(m_control.sensors); diff --git a/src/cpu.cpp b/src/cpu.cpp index a466127..714b710 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -19,7 +19,7 @@ void detectHwmon(cpuSensors* target, const std::string& pci) { return; } - target->module = utils::fileExists(target->hwmon + "/in1_input") ? zenpower : k10temp; // idk if this is reliable, we're trying to avoid just reading the name + target->module = utils::fileExists(target->hwmon + "/in1_input") ? zenpower : k10temp; // idk if this is reliable, we're trying to avoid just reading the name target->num_cores = std::thread::hardware_concurrency(); applog(LOG::INF, "Detected {} cores, module enum #{} in path \"{}\"", target->num_cores, static_cast(target->module), target->hwmon); } diff --git a/src/hass.cpp b/src/hass.cpp index 7b4d757..fc12015 100644 --- a/src/hass.cpp +++ b/src/hass.cpp @@ -6,7 +6,7 @@ #include #include -HomeAssistant::HomeAssistant(const Config& config){ +HomeAssistant::HomeAssistant(const Config& config) { m_config = config; } diff --git a/src/utils.cpp b/src/utils.cpp index f91805e..c3eede0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,8 +1,9 @@ +#include + #include #include #include #include -#include namespace utils { @@ -28,4 +29,4 @@ std::string getFirstDir(const std::string_view& path) { return ""; } -} \ No newline at end of file +} // namespace utils \ No newline at end of file