diff --git a/include/LCDDisplay.hpp b/include/LCDDisplay.hpp index 8e8f195..558334c 100644 --- a/include/LCDDisplay.hpp +++ b/include/LCDDisplay.hpp @@ -12,7 +12,7 @@ class LCDDisplay { private: int _lcd = -1; std::string _dev; - std::array writebuf{}; // 4x40 chars + 2x4 setcursor commands + 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); diff --git a/include/cpu.hpp b/include/cpu.hpp index 9641c6f..b1ce0b0 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -8,7 +8,9 @@ namespace cpu { -enum Module : uint8_t { unknown, k10temp, zenpower }; +enum Module : uint8_t { unknown, + k10temp, + zenpower }; struct cpuSensors { Module module = unknown; diff --git a/include/log.hpp b/include/log.hpp index b244573..f22d5d6 100644 --- a/include/log.hpp +++ b/include/log.hpp @@ -69,9 +69,9 @@ void log(LOG level, const std::source_location& loc, std::format_string { auto now = std::chrono::system_clock::now(); auto local = std::chrono::current_zone()->to_local(now); - std::string msg = std::format("{:%x %H:%M:%S }", floor(local)); // timestamp - std::format_to(std::back_inserter(msg), pattern, color, pFname(loc.function_name()), reset); // tag - std::format_to(std::back_inserter(msg), str, std::forward(args)...); // actual log message + std::string msg = std::format("{:%x %H:%M:%S }", floor(local)); // timestamp + std::format_to(std::back_inserter(msg), pattern, color, pFname(loc.function_name()), reset); // tag + std::format_to(std::back_inserter(msg), str, std::forward(args)...); // actual log message std::scoped_lock lock(fmtx); gzFile file = gzopen(LOG_FILE_LOCATION, "ab"); @@ -82,7 +82,7 @@ void log(LOG level, const std::source_location& loc, std::format_string } #endif } -} +} // namespace utils #else diff --git a/include/utils.hpp b/include/utils.hpp index be87199..2ae9ff9 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -3,11 +3,12 @@ #include #include + #include #include #include -#include #include +#include #include namespace utils { @@ -54,7 +55,6 @@ inline ssize_t readFile(const std::string& path, std::array& buffer) { return len; } - /* reads a number fast and divides it if needed */ template inline void fastReadNum(const std::string& path, std::array& buf, T& result) { diff --git a/src/LCDDisplay.cpp b/src/LCDDisplay.cpp index 1532c7b..bfeb44a 100644 --- a/src/LCDDisplay.cpp +++ b/src/LCDDisplay.cpp @@ -13,7 +13,7 @@ /* lcd size hardcoded to 4x40 idgaf */ LCDDisplay::LCDDisplay(const std::string& dev, const uint32_t baud) { _dev = dev; - this->open(); // calls this (LCDDisplay) open() function, LCDDisplay::open() + this->open(); // calls this (LCDDisplay) open() function, LCDDisplay::open() struct termios term{}; // Setup the serial port 8 data bits, no parity, 1 stopbit, no flow control @@ -42,7 +42,7 @@ 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() + _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); diff --git a/src/cpu.cpp b/src/cpu.cpp index 7dceab4..4b98273 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -18,7 +18,7 @@ void detectHwmon(cpuSensors* target, const std::string& pci) { return; } - if (utils::fileExists(target->hwmon+ "/in1_input")) // idk if this is reliable, we're trying to avoid just reading the name + if (utils::fileExists(target->hwmon + "/in1_input")) // idk if this is reliable, we're trying to avoid just reading the name target->module = k10temp; applog(LOG::INF, "Detected module no. {} in path \"{}\"", target->module ? "zenpower" : "k10temp", target->hwmon); } @@ -51,11 +51,11 @@ void update(cpuSensors* c) { // commented out unused values so its faster if (c->module == zenpower) { - utils::fastReadNum<1000>(c->hwmon + "/temp1_input", buf, c->tdie); - utils::fastReadNum<1000>(c->hwmon + "/temp2_input", buf, c->tctl); - utils::fastReadNum<1000>(c->hwmon + "/temp3_input", buf, c->tccd1); - // utils::fastReadNum<1000>(c->hwmon + "/in1_input", buf, c->vcore); - // utils::fastReadNum<1000>(c->hwmon + "/in2_input", buf, c->vsoc); + utils::fastReadNum<1000>(c->hwmon + "/temp1_input", buf, c->tdie); + utils::fastReadNum<1000>(c->hwmon + "/temp2_input", buf, c->tctl); + utils::fastReadNum<1000>(c->hwmon + "/temp3_input", buf, c->tccd1); + // utils::fastReadNum<1000>(c->hwmon + "/in1_input", buf, c->vcore); + // utils::fastReadNum<1000>(c->hwmon + "/in2_input", buf, c->vsoc); } if (c->module == k10temp) { diff --git a/src/gpu.cpp b/src/gpu.cpp index 37e3205..700e82d 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -11,21 +11,21 @@ namespace gpu { const std::string rel_metrics_path = "/../../gpu_metrics"; // gpu_metrics path relative to hwmon path -constexpr uint16_t max_metrics_length = 512; // length of the metrics buffer +constexpr uint16_t max_metrics_length = 512; // length of the metrics buffer /* takes pointer to a target gpu::sensors struct and updates its hwmon path and detects gpu_metrics */ void detectHwmon(gpuSensors* target, const std::string& pci) { target->hwmon = utils::getFirstDir("/sys/bus/pci/devices/" + pci + "/hwmon"); applog(LOG::INF, "Detected path \"{}\"", target->hwmon); - if(utils::fileExists(target->hwmon + rel_metrics_path)) { + if (utils::fileExists(target->hwmon + rel_metrics_path)) { applog(LOG::INF, "found gpu_metrics"); target->hasGpuMetrics = true; } } /* some metrics are missing in gpu_metrics, we always fill them from fs, unused metrics are commented out */ -void fillMissingMetrics(gpuSensors* g) {; +void fillMissingMetrics(gpuSensors* g) { static std::array buf; utils::fastReadNum<1000>(g->hwmon + "/in0_input", buf, g->vcore); // g->fan_pwm = std::stoi(readFile(g->hwmon + "/pwm1", 4)) * 100 / 256; diff --git a/src/hass.cpp b/src/hass.cpp index b111cab..7ff1689 100644 --- a/src/hass.cpp +++ b/src/hass.cpp @@ -52,9 +52,9 @@ void HomeAssistant::event_handler(struct lws* wsi, const enum lws_callback_reaso if (ha_type == "event") { json = json["event"]; - if(json.contains("a")) + if (json.contains("a")) state = std::stof(json["a"][entity]["s"].get()); - if(json.contains("c")) + if (json.contains("c")) state = std::stof(json["c"][entity]["+"]["s"].get()); break; } @@ -75,7 +75,7 @@ void HomeAssistant::event_handler(struct lws* wsi, const enum lws_callback_reaso case LWS_CALLBACK_CLIENT_WRITEABLE: { /* skip whole callback if there's no tx to send */ - if (! tx.empty()) { + if (!tx.empty()) { const size_t msgLen = LWS_PRE + tx.size(); auto* buf = static_cast(malloc(msgLen)); if (buf) { diff --git a/src/sys.cpp b/src/sys.cpp index 2f04f37..ba4ae54 100644 --- a/src/sys.cpp +++ b/src/sys.cpp @@ -30,10 +30,10 @@ void sys::getTimeDate(TimeDate* td) { } void sys::getRam(Memory* mem) { - static std::array buf; // file is longer but we only need first 128 chars + static std::array buf; // file is longer but we only need first 128 chars utils::readFile("/proc/meminfo", buf); mem->free = getVal("MemAvailable:", std::string_view(buf)); - mem->total = getVal("MemTotal:", std::string_view(buf)); // shouldn't really update this on each loop + mem->total = getVal("MemTotal:", std::string_view(buf)); // shouldn't really update this on each loop mem->used = mem->total - mem->free; }