it was colliding with math log, renamed to applog

This commit is contained in:
2025-12-28 13:40:01 +01:00
parent 14b03f45f4
commit d873837660
8 changed files with 33 additions and 34 deletions

View File

@@ -40,11 +40,11 @@ LCDDisplay::~LCDDisplay() {
}
void LCDDisplay::open(bool reopen) {
log(LOG::INF, "Opening serial port at \"{}\"", _dev);
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) {
log(LOG::ERR, "Error opening serial port \"{}\"", _dev); // err
applog(LOG::ERR, "Error opening serial port \"{}\"", _dev); // err
exit(_lcd);
}
}
@@ -52,7 +52,7 @@ void LCDDisplay::open(bool reopen) {
void LCDDisplay::close() {
if (_lcd >= 0) {
::close(_lcd);
log(LOG::INF, "Closed LCD port");
applog(LOG::INF, "Closed LCD port");
}
_lcd = -1;
}
@@ -60,7 +60,7 @@ void LCDDisplay::close() {
void LCDDisplay::write(const uint8_t* cmdbuf, uint8_t len) {
int rc = ::write(_lcd, cmdbuf, len);
if(rc < 0) {
log(LOG::ERR, "failed to execute ::write, lost access to port?");
applog(LOG::ERR, "failed to execute ::write, lost access to port?");
this->open(true);
}
}
@@ -71,20 +71,20 @@ void LCDDisplay::clear() {
}
void LCDDisplay::setContrast(uint8_t contrast) {
log(LOG::INF, "Set contrast to {}", contrast);
applog(LOG::INF, "Set contrast to {}", contrast);
const uint8_t cmdbuf[] = {254, 80, contrast};
this->write(cmdbuf, sizeof(cmdbuf));
}
void LCDDisplay::setBacklight(bool enabled) {
log(LOG::INF, "Set backlight to {}", enabled);
applog(LOG::INF, "Set backlight to {}", enabled);
const uint8_t cmdbuf[] = {254, (uint8_t)(enabled ? 66 : 70), 255};
this->write(cmdbuf, enabled ? 3 : 2);
}
/* still doesnt work? */
void LCDDisplay::setBacklight(uint8_t brightness) {
log(LOG::INF, "Set backlight brightness to {}", brightness);
applog(LOG::INF, "Set backlight brightness to {}", brightness);
const uint8_t cmdbuf[] = {254, (uint8_t)(brightness ? 66 : 70), 255, brightness}; // 3rd char is timer, 4th is brightness
this->write(cmdbuf, brightness ? 4 : 2);
}

View File

@@ -13,12 +13,12 @@ void detectHwmon(cpuSensors* target, const std::string& pci) {
try {
target->hwmon = getFirstDir(path);
} catch (...) {
log(LOG::ERR, "NO CPU HWMON KERNEL MODULE DETECTED");
applog(LOG::ERR, "NO CPU HWMON KERNEL MODULE DETECTED");
return;
}
target->zenpower = false; // we were using readFileToStr to figure this out, we dont f/w it anymore, find another way (see if hwmon/in1_input exists?)
log(LOG::INF, "Detected module \"{}\" in path \"{}\"", target->zenpower ? "zenpower" : "k10temp", target->hwmon);
applog(LOG::INF, "Detected module \"{}\" in path \"{}\"", target->zenpower ? "zenpower" : "k10temp", target->hwmon);
}
void update(cpuSensors* c) {

View File

@@ -12,11 +12,11 @@ namespace gpu {
/* 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 = getFirstDir("/sys/bus/pci/devices/" + pci + "/hwmon");
log(LOG::INF, "Detected path \"{}\"", target->hwmon);
applog(LOG::INF, "Detected path \"{}\"", target->hwmon);
if (FILE* file = fopen((target->hwmon + REL_METRICS_PATH).c_str(), "r")) {
fclose(file);
log(LOG::INF, "found gpu_metrics");
applog(LOG::INF, "found gpu_metrics");
target->hasGpuMetrics = true;
}
}
@@ -86,7 +86,7 @@ void updateFromMetrics(gpuSensors* g) {
/* werid hardware i probably dont like, maybe fallback to reading from fs? */
default: {
log(LOG::WRN, "Unsupported gpu_metrics_v{}_{}", header->format_revision, header->content_revision);
applog(LOG::WRN, "Unsupported gpu_metrics_v{}_{}", header->format_revision, header->content_revision);
break;
}
}

View File

@@ -1,8 +1,7 @@
#include <libwebsockets.h>
#include <nlohmann/json.hpp>
#include <hass.hpp>
#include <log.hpp>
#include <nlohmann/json.hpp>
#include <string>
HomeAssistant::HomeAssistant(std::string addr, std::string ent) {
@@ -17,7 +16,7 @@ HomeAssistant::~HomeAssistant() {
void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in) {
switch (reason) {
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: {
log(LOG::ERR, "websocket conn error: {}", in ? in : "(null)");
applog(LOG::ERR, "websocket conn error: {}", in ? in : "(null)");
return;
}
@@ -34,7 +33,7 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
}
if (ha_type == "auth_ok") {
log(LOG::INF, "subscribing to entity \"{}\"", entity);
applog(LOG::INF, "subscribing to entity \"{}\"", entity);
json.clear();
json["id"] = id++;
json["type"] = "subscribe_entities";
@@ -45,30 +44,30 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
if (ha_type == "result") {
if (json["success"].get<bool>() != true)
log(LOG::ERR, "api said success was \"false\" on message id {}", id - 1);
applog(LOG::ERR, "api said success was \"false\" on message id {}", id - 1);
break;
}
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;
}
log(LOG::WRN, "unhandled event: {}", (char*)in);
applog(LOG::WRN, "unhandled event: {}", (char*)in);
break;
}
case LWS_CALLBACK_CLIENT_ESTABLISHED: {
log(LOG::INF, "Websocket connected");
applog(LOG::INF, "Websocket connected");
break;
}
case LWS_CALLBACK_CLIENT_CLOSED: {
log(LOG::INF, "Websocket closed");
applog(LOG::INF, "Websocket closed");
return;
}
@@ -127,7 +126,7 @@ int HomeAssistant::connect() {
context = lws_create_context(&info);
if (!context) {
log(LOG::ERR, "error creating context");
applog(LOG::ERR, "error creating context");
return -1;
}
@@ -144,7 +143,7 @@ int HomeAssistant::connect() {
websock = lws_client_connect_via_info(&i);
if (!websock) {
log(LOG::ERR, "error creating lws client");
applog(LOG::ERR, "error creating lws client");
return -1;
}
return 0;

View File

@@ -68,7 +68,7 @@ void sys::detectHwmon(sysSensors* s, const std::string& platform) {
try {
s->hwmon = getFirstDir("/sys/devices/platform/" + platform + "/hwmon");
} catch (...) {
log(LOG::ERR, "Can't open sys hwmon. Module loaded? Kernel params added?");
applog(LOG::ERR, "Can't open sys hwmon. Module loaded? Kernel params added?");
return;
}
}

View File

@@ -45,7 +45,7 @@ std::string pBytes(double bytes, bool isKbytes) {
ssize_t readFile(const char* path, char* buffer, size_t maxlen) {
int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
log(LOG::ERR, "Error reading {}", path);
applog(LOG::ERR, "Error reading {}", path);
return 0;
}
ssize_t len = read(fd, buffer, maxlen - 1);