clang format all of this
This commit is contained in:
@@ -12,7 +12,7 @@ class LCDDisplay {
|
||||
private:
|
||||
int _lcd = -1;
|
||||
std::string _dev;
|
||||
std::array<char, LCD_LINES * LCD_COLS + 8> writebuf{}; // 4x40 chars + 2x4 setcursor commands
|
||||
std::array<char, LCD_LINES * LCD_COLS + 8> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -69,9 +69,9 @@ void log(LOG level, const std::source_location& loc, std::format_string<Args...>
|
||||
{
|
||||
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<std::chrono::milliseconds>(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>(args)...); // actual log message
|
||||
std::string msg = std::format("{:%x %H:%M:%S }", floor<std::chrono::milliseconds>(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>(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<Args...>
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace utils
|
||||
|
||||
#else
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <log.hpp>
|
||||
#include <filesystem>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace utils {
|
||||
@@ -54,7 +55,6 @@ inline ssize_t readFile(const std::string& path, std::array<char, N>& buffer) {
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/* reads a number fast and divides it if needed */
|
||||
template <uint32_t Divider = 1, typename T, size_t N>
|
||||
inline void fastReadNum(const std::string& path, std::array<char, N>& buf, T& result) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
12
src/cpu.cpp
12
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) {
|
||||
|
||||
@@ -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<char, 32> buf;
|
||||
utils::fastReadNum<1000>(g->hwmon + "/in0_input", buf, g->vcore);
|
||||
// g->fan_pwm = std::stoi(readFile(g->hwmon + "/pwm1", 4)) * 100 / 256;
|
||||
|
||||
@@ -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<std::string>());
|
||||
if(json.contains("c"))
|
||||
if (json.contains("c"))
|
||||
state = std::stof(json["c"][entity]["+"]["s"].get<std::string>());
|
||||
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<unsigned char*>(malloc(msgLen));
|
||||
if (buf) {
|
||||
|
||||
@@ -30,10 +30,10 @@ void sys::getTimeDate(TimeDate* td) {
|
||||
}
|
||||
|
||||
void sys::getRam(Memory* mem) {
|
||||
static std::array<char, 128> buf; // file is longer but we only need first 128 chars
|
||||
static std::array<char, 128> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user