lil code formatting
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
|
||||
HomeAssistant::HomeAssistant(const Config& config){
|
||||
HomeAssistant::HomeAssistant(const Config& config) {
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user