lil code formatting

This commit is contained in:
2026-01-14 00:11:48 +01:00
parent 6297317f93
commit 61e804785b
8 changed files with 38 additions and 37 deletions

View File

@@ -9,20 +9,6 @@
#include <string>
class LCDDisplay {
private:
int _lcd = -1;
std::string _dev;
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);
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<char>(c % 8); }
private:
int lcd = -1;
std::string dev;
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);
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

View File

@@ -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

View File

@@ -7,7 +7,7 @@
#include <string>
class HomeAssistant {
public:
public:
struct Config {
std::string address;
std::string entity;

View File

@@ -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);
}

View File

@@ -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<int>(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);

View File

@@ -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<uint8_t>(target->module), target->hwmon);
}

View File

@@ -6,7 +6,7 @@
#include <nlohmann/json.hpp>
#include <string>
HomeAssistant::HomeAssistant(const Config& config){
HomeAssistant::HomeAssistant(const Config& config) {
m_config = config;
}

View File

@@ -1,8 +1,9 @@
#include <utils.hpp>
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <utils.hpp>
namespace utils {
@@ -28,4 +29,4 @@ std::string getFirstDir(const std::string_view& path) {
return "";
}
}
} // namespace utils