whole lotta shit clion made me do
This commit is contained in:
@@ -21,7 +21,7 @@ struct sensors {
|
||||
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
|
||||
};
|
||||
|
||||
void start(void);
|
||||
void start();
|
||||
|
||||
} // namespace app
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ struct cpuSensors {
|
||||
};
|
||||
|
||||
void detectHwmon(cpuSensors* target, const std::string& pci);
|
||||
void update(cpuSensors* g);
|
||||
void update(cpuSensors* c);
|
||||
|
||||
} // namespace cpu
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef GPU_METRICS_HPP
|
||||
#define GPU_METRICS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/* STRUCTS COPIED WHOLESALE FROM LINUX SOURCE CODE, formatted and wrapped around a namespace
|
||||
@@ -792,4 +795,6 @@ struct gpu_metrics_v3_0 {
|
||||
/* Metrics table alpha filter time constant [us] */
|
||||
uint32_t time_filter_alphavalue;
|
||||
};
|
||||
} // namespace gpu
|
||||
} // namespace gpu
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,19 +14,19 @@ class HomeAssistant {
|
||||
std::string entity;
|
||||
uint16_t id = 2;
|
||||
std::string tx;
|
||||
struct lws_context* context = NULL;
|
||||
lws* websock = NULL;
|
||||
struct lws_context* context = nullptr;
|
||||
lws* websock = nullptr;
|
||||
void event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in);
|
||||
static int callback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len);
|
||||
|
||||
public:
|
||||
HomeAssistant(std::string addr, std::string ent);
|
||||
HomeAssistant(const std::string& addr, const std::string& ent);
|
||||
~HomeAssistant();
|
||||
|
||||
float state = 0.0f;
|
||||
int connect();
|
||||
void service(int timeout_ms = 0);
|
||||
void disconnect();
|
||||
void disconnect() const;
|
||||
void service(int timeout_ms = 0) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -6,11 +6,11 @@
|
||||
|
||||
namespace sys {
|
||||
|
||||
const char months[][4] = {"sty", "lut", "mar", "kwi", "maj", "cze", "lip", "sie", "wrz", "paz", "lis", "gru"};
|
||||
const char wdays[][4] = {"Nie", "Pon", "Wto", "Sro", "Czw", "Pia", "Sob"};
|
||||
constexpr char months[][4] = {"sty", "lut", "mar", "kwi", "maj", "cze", "lip", "sie", "wrz", "paz", "lis", "gru"};
|
||||
constexpr char wdays[][4] = {"Nie", "Pon", "Wto", "Sro", "Czw", "Pia", "Sob"};
|
||||
|
||||
struct sysSensors {
|
||||
std::string hwmon = "";
|
||||
std::string hwmon;
|
||||
uint16_t fan_speed[2] = {0}; // left and right cpu fans
|
||||
uint8_t t_sensor = 0; // ntc temp sensor
|
||||
};
|
||||
|
||||
14
src/app.cpp
14
src/app.cpp
@@ -110,7 +110,7 @@ void displayThread(const std::stop_token& st, app::sensors& s) {
|
||||
// prepare some tricky sensors
|
||||
std::string gpu_temps = std::to_string(s.gpu.temp_edge);
|
||||
if (s.gpu.temp_hotspot)
|
||||
gpu_temps = utils::pad(lcd.cc(1) + std::to_string(s.gpu.temp_hotspot - s.gpu.temp_edge) + lcd.cc(0), 4) + " " + utils::pad(gpu_temps + "/" + std::to_string(s.gpu.temp_hotspot), 5);
|
||||
gpu_temps = utils::pad(LCDDisplay::cc(1) + std::to_string(s.gpu.temp_hotspot - s.gpu.temp_edge) + LCDDisplay::cc(0), 4) + utils::pad(gpu_temps + "/" + std::to_string(s.gpu.temp_hotspot), 6);
|
||||
|
||||
uint16_t cpu_fan = 0;
|
||||
for (const auto& fan : s.sys.fan_speed)
|
||||
@@ -123,22 +123,22 @@ void displayThread(const std::stop_token& st, app::sensors& s) {
|
||||
lcd.writeBuf(0, 31, utils::pNum(s.avg[1], s.avg[1] > 10 ? 1 : 2));
|
||||
lcd.writeBuf(0, 36, utils::pNum(s.avg[2], s.avg[2] > 10 ? 1 : 2));
|
||||
|
||||
lcd.writeBuf(1, 0, utils::pad(std::to_string(s.cpu.tctl) + "/" + std::to_string(s.cpu.tccd1) + lcd.cc(0), 8, utils::just::left));
|
||||
lcd.writeBuf(1, 0, utils::pad(std::to_string(s.cpu.tctl) + "/" + std::to_string(s.cpu.tccd1) + LCDDisplay::cc(0), 8, utils::just::left));
|
||||
lcd.writeBuf(1, 7, utils::pad(utils::pBytes(s.ram.used, true), 6, utils::just::left));
|
||||
lcd.writeBuf(1, 13, utils::pad(utils::pNum(s.hass_state) + "W", 4));
|
||||
lcd.writeBuf(1, 19, std::to_string(s.sys.t_sensor) + lcd.cc(0)); // t_sensor temp
|
||||
lcd.writeBuf(1, 19, std::to_string(s.sys.t_sensor) + LCDDisplay::cc(0)); // t_sensor temp
|
||||
lcd.writeBuf(1, 32 - gpu_temps.size(), utils::pad(utils::pBytes(s.gpu.vram_used), 6));
|
||||
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + lcd.cc(0));
|
||||
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + LCDDisplay::cc(0));
|
||||
|
||||
lcd.writeBuf(2, 0, utils::pad(std::to_string(static_cast<int>(s.cpu.ptotal)) + "W", 8, utils::just::left));
|
||||
lcd.writeBuf(2, s.cpu.ptotal < 100 ? 4 : 5, std::to_string(cpu_fan) + "R"); // avg fan speed
|
||||
lcd.writeBuf(2, 12, lcd.cc(3) + utils::pBytes(s.net.upload));
|
||||
lcd.writeBuf(2, 19, lcd.cc(4) + utils::pBytes(s.net.download));
|
||||
lcd.writeBuf(2, 12, LCDDisplay::cc(3) + utils::pBytes(s.net.upload));
|
||||
lcd.writeBuf(2, 19, LCDDisplay::cc(4) + utils::pBytes(s.net.download));
|
||||
lcd.writeBuf(2, 26, utils::pad(std::to_string(s.gpu.fan_speed) + "R", 5));
|
||||
lcd.writeBuf(2, 31, utils::pad(std::to_string(s.gpu.power_avg) + "/" + std::to_string(s.gpu.power_cap) + "W", 9));
|
||||
|
||||
lcd.writeBuf(3, 0, std::to_string(s.cpu.avg_freq) + "MHz");
|
||||
lcd.writeBuf(3, 14, utils::pad(lcd.cc(2) + utils::pBytes(s.home.usage.free), 6));
|
||||
lcd.writeBuf(3, 14, utils::pad(LCDDisplay::cc(2) + utils::pBytes(s.home.usage.free), 6));
|
||||
lcd.writeBuf(3, 21, utils::pad(std::to_string(s.gpu.clock_core) + "/" + std::to_string(s.gpu.clock_mem) + "MHz ", 13));
|
||||
lcd.writeBuf(3, 34, utils::pad(utils::pNum(s.gpu.vcore, 3) + "V", 5));
|
||||
}
|
||||
|
||||
17
src/cpu.cpp
17
src/cpu.cpp
@@ -34,8 +34,7 @@ void update(cpuSensors* c) {
|
||||
// read power from intel-rapl? works on amd too, btop uses this trick, seems accurate
|
||||
// it tracks with "socket power" in hwinfo on windows, its actually the same thing i had in lcdsmartie
|
||||
curr.ts = std::chrono::steady_clock::now();
|
||||
// utils::fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", curr.energy);
|
||||
curr.energy = utils::fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", buf);
|
||||
utils::fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", buf, curr.energy);
|
||||
c->ptotal = static_cast<float>(curr.energy - prev.energy) / static_cast<float>(std::chrono::duration_cast<std::chrono::microseconds>(curr.ts - prev.ts).count());
|
||||
prev = curr;
|
||||
|
||||
@@ -51,14 +50,14 @@ void update(cpuSensors* c) {
|
||||
|
||||
// commented out unused values so its faster
|
||||
if (c->zenpower) {
|
||||
c->tdie = utils::fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tctl = utils::fastReadNum(c->hwmon + "/temp2_input", buf) / 1000;
|
||||
c->tccd1 = utils::fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
c->vcore = utils::fastReadNum(c->hwmon + "/in1_input", buf) / 1000.0;
|
||||
c->vsoc = utils::fastReadNum(c->hwmon + "/in2_input", buf) / 1000.0;
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/temp1_input", buf, c->tdie);
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/temp2_input", buf, c->tctl);
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/temp3_input", buf, c->tccd1);
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/in1_input", buf, c->vcore);
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/in2_input", buf, c->vsoc);
|
||||
} else {
|
||||
c->tctl = utils::fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tccd1 = utils::fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/temp1_input", buf, c->tctl);
|
||||
utils::fastReadNumDiv<1000>(c->hwmon + "/temp3_input", buf, c->tccd1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/gpu.cpp
18
src/gpu.cpp
@@ -26,23 +26,23 @@ void detectHwmon(gpuSensors* target, const std::string& pci) {
|
||||
/* some metrics are missing in gpu_metrics, we always fill them from fs, unused metrics are commented out */
|
||||
void fillMissingMetrics(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
g->vcore = utils::fastReadNum(g->hwmon + "/in0_input", buf) / 1000.0;
|
||||
utils::fastReadNumDiv<1000>(g->hwmon + "/in0_input", buf, g->vcore);
|
||||
// g->fan_pwm = std::stoi(readFile(g->hwmon + "/pwm1", 4)) * 100 / 256;
|
||||
g->fan_speed = utils::fastReadNum(g->hwmon + "/fan1_input", buf);
|
||||
g->power_cap = utils::fastReadNum(g->hwmon + "/power1_cap", buf) / 1000000;
|
||||
utils::fastReadNum(g->hwmon + "/fan1_input", buf, g->fan_speed);
|
||||
utils::fastReadNumDiv<1000000>(g->hwmon + "/power1_cap", buf, g->power_cap);
|
||||
// utils::fastReadNum(g->hwmon + "/power1_cap_max", g->power_cap_max) / 1000000;
|
||||
g->vram_used = utils::fastReadNum(g->hwmon + "/../../mem_info_vram_used", buf);
|
||||
utils::fastReadNum(g->hwmon + "/../../mem_info_vram_used", buf, g->vram_used);
|
||||
// utils::fastReadNum(g->hwmon + "/../../mem_info_vram_total", g->vram_total);
|
||||
}
|
||||
|
||||
/* get sensors for pre-vega cards (rx480/580) */
|
||||
void updateFromFs(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
g->clock_core = utils::fastReadNum(g->hwmon + "/freq1_input", buf) / 1000000;
|
||||
g->clock_mem = utils::fastReadNum(g->hwmon + "/freq2_input", buf) / 1000000;
|
||||
g->power_avg = utils::fastReadNum(g->hwmon + "/power1_input", buf) / 1000000;
|
||||
g->temp_edge = utils::fastReadNum(g->hwmon + "/temp1_input", buf) / 1000;
|
||||
g->usage_core = utils::fastReadNum(g->hwmon + "/../../gpu_busy_percent", buf);
|
||||
utils::fastReadNumDiv<1000000>(g->hwmon + "/freq1_input", buf, g->clock_core);
|
||||
utils::fastReadNumDiv<1000000>(g->hwmon + "/freq2_input", buf, g->clock_mem);
|
||||
utils::fastReadNumDiv<1000000>(g->hwmon + "/power1_input", buf, g->power_avg);
|
||||
utils::fastReadNumDiv<1000>(g->hwmon + "/temp1_input", buf, g->temp_edge);
|
||||
utils::fastReadNum(g->hwmon + "/../../gpu_busy_percent", buf, g->usage_core);
|
||||
}
|
||||
|
||||
/* get sensors for vega and newer (rx5700xt, rx7800xt [*]) */
|
||||
|
||||
46
src/hass.cpp
46
src/hass.cpp
@@ -1,10 +1,12 @@
|
||||
#include <libwebsockets.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <hass.hpp>
|
||||
#include <log.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
|
||||
HomeAssistant::HomeAssistant(std::string addr, std::string ent) {
|
||||
HomeAssistant::HomeAssistant(const std::string& addr, const std::string& ent) {
|
||||
address = addr;
|
||||
entity = ent;
|
||||
}
|
||||
@@ -13,7 +15,7 @@ HomeAssistant::~HomeAssistant() {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in) {
|
||||
void HomeAssistant::event_handler(struct lws* wsi, const enum lws_callback_reasons reason, char* in) {
|
||||
switch (reason) {
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: {
|
||||
applog(LOG::ERR, "websocket conn error: {}", in ? in : "(null)");
|
||||
@@ -22,7 +24,7 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
|
||||
|
||||
case LWS_CALLBACK_CLIENT_RECEIVE: {
|
||||
nlohmann::json json = nlohmann::json::parse(in);
|
||||
std::string ha_type = json["type"].get<std::string>();
|
||||
const std::string ha_type = json["type"].get<std::string>();
|
||||
|
||||
if (ha_type == "auth_required") {
|
||||
json.clear();
|
||||
@@ -57,7 +59,7 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
|
||||
break;
|
||||
}
|
||||
|
||||
applog(LOG::WRN, "unhandled event: {}", (char*)in);
|
||||
applog(LOG::WRN, "unhandled event: {}", static_cast<char*>(in));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -73,9 +75,9 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
|
||||
|
||||
case LWS_CALLBACK_CLIENT_WRITEABLE: {
|
||||
/* skip whole callback if there's no tx to send */
|
||||
if (tx.size() > 0) {
|
||||
size_t msgLen = LWS_PRE + tx.size();
|
||||
unsigned char* buf = (unsigned char*)malloc(msgLen);
|
||||
if (! tx.empty()) {
|
||||
const size_t msgLen = LWS_PRE + tx.size();
|
||||
auto* buf = static_cast<unsigned char*>(malloc(msgLen));
|
||||
if (buf) {
|
||||
memcpy(&buf[LWS_PRE], tx.c_str(), tx.size());
|
||||
lws_write(wsi, &buf[LWS_PRE], tx.size(), LWS_WRITE_TEXT);
|
||||
@@ -91,32 +93,32 @@ void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons rea
|
||||
}
|
||||
}
|
||||
|
||||
int HomeAssistant::callback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t) {
|
||||
HomeAssistant* self = static_cast<HomeAssistant*>(user);
|
||||
self->event_handler(wsi, reason, (char*)in);
|
||||
int HomeAssistant::callback(struct lws* wsi, const enum lws_callback_reasons reason, void* user, void* in, size_t) {
|
||||
auto* self = static_cast<HomeAssistant*>(user);
|
||||
self->event_handler(wsi, reason, static_cast<char*>(in));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HomeAssistant::connect() {
|
||||
struct lws_client_connect_info i;
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_client_connect_info i{};
|
||||
struct lws_context_creation_info info{};
|
||||
|
||||
lws_set_log_level(LLL_ERR | LLL_WARN, lwsl_emit_syslog);
|
||||
|
||||
memset(&i, 0, sizeof(i));
|
||||
memset(&info, 0, sizeof info);
|
||||
std::memset(&i, 0, sizeof(i));
|
||||
std::memset(&info, 0, sizeof info);
|
||||
|
||||
static const struct lws_protocols protocols[] = {
|
||||
{"lws-minimal-client", callback, sizeof(void*), 0, 0, NULL, 0},
|
||||
static constexpr struct lws_protocols protocols[] = {
|
||||
{"lws-minimal-client", callback, sizeof(void*), 0, 0, nullptr, 0},
|
||||
LWS_PROTOCOL_LIST_TERM};
|
||||
|
||||
static const struct lws_extension extensions[] = {
|
||||
static constexpr struct lws_extension extensions[] = {
|
||||
{"permessage-deflate",
|
||||
lws_extension_callback_pm_deflate,
|
||||
"permessage-deflate"
|
||||
"; client_no_context_takeover"
|
||||
"; client_max_window_bits"},
|
||||
{NULL, NULL, NULL}};
|
||||
{nullptr, nullptr, nullptr}};
|
||||
|
||||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
info.port = CONTEXT_PORT_NO_LISTEN;
|
||||
@@ -137,7 +139,7 @@ int HomeAssistant::connect() {
|
||||
i.host = i.address;
|
||||
i.origin = i.address;
|
||||
i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_PRIORITIZE_READS;
|
||||
i.protocol = NULL;
|
||||
i.protocol = nullptr;
|
||||
i.userdata = this;
|
||||
i.local_protocol_name = "lws-minimal-client";
|
||||
|
||||
@@ -149,11 +151,11 @@ int HomeAssistant::connect() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HomeAssistant::service(int timeout_ms) {
|
||||
void HomeAssistant::service(const int timeout_ms) const {
|
||||
lws_callback_on_writable(websock);
|
||||
lws_service(context, timeout_ms);
|
||||
}
|
||||
|
||||
void HomeAssistant::disconnect() {
|
||||
void HomeAssistant::disconnect() const {
|
||||
lws_context_destroy(context);
|
||||
}
|
||||
|
||||
44
src/sys.cpp
44
src/sys.cpp
@@ -1,5 +1,6 @@
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <log.hpp>
|
||||
@@ -7,36 +8,37 @@
|
||||
#include <sys.hpp>
|
||||
#include <utils.hpp>
|
||||
|
||||
int getVal(std::string_view target, std::string_view content) {
|
||||
int getVal(const std::string_view target, std::string_view content) {
|
||||
int result = -1;
|
||||
std::size_t start = content.find(target);
|
||||
if (start != std::string::npos) {
|
||||
int begin = start + target.length();
|
||||
std::size_t end = content.find("kB", start);
|
||||
result = std::strtol(content.substr(begin, end - begin).data(), NULL, 10);
|
||||
if (const std::size_t start = content.find(target); start != std::string::npos) {
|
||||
content.remove_prefix(start + target.length());
|
||||
const std::size_t end = content.find(" kB");
|
||||
while (std::isspace(content.front()))
|
||||
content.remove_prefix(1);
|
||||
std::from_chars(content.data(), content.data() + end, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void sys::getTimeDate(TimeDate* td) {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto local = std::chrono::current_zone()->to_local(now);
|
||||
std::chrono::year_month_day ymd{floor<std::chrono::days>(local)};
|
||||
std::chrono::weekday wd{floor<std::chrono::days>(local)};
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto local = std::chrono::current_zone()->to_local(now);
|
||||
const std::chrono::year_month_day ymd{floor<std::chrono::days>(local)};
|
||||
const std::chrono::weekday wd{floor<std::chrono::days>(local)};
|
||||
td->time = std::format("{:%H:%M:%S}", floor<std::chrono::seconds>(local));
|
||||
td->date = std::format("{}, {} {}", wdays[wd.c_encoding()], ymd.day(), months[(unsigned)ymd.month() - 1]);
|
||||
td->date = std::format("{}, {} {}", wdays[wd.c_encoding()], ymd.day(), months[static_cast<unsigned>(ymd.month()) - 1]);
|
||||
}
|
||||
|
||||
void sys::getRam(Memory* mem) {
|
||||
static char buf[128]; // file is longer but we only need first 128 chars
|
||||
utils::readFile("/proc/meminfo", buf, sizeof(buf));
|
||||
mem->free = getVal("MemAvailable:", std::string_view(buf));
|
||||
mem->total = getVal("MemTotal:", std::string_view(buf));
|
||||
mem->total = getVal("MemTotal:", std::string_view(buf)); // shouldn't really update this on each loop
|
||||
mem->used = mem->total - mem->free;
|
||||
}
|
||||
|
||||
void sys::getDisk(Disk* disk) {
|
||||
struct statvfs diskData;
|
||||
struct statvfs diskData{};
|
||||
statvfs(disk->mountpoint.c_str(), &diskData);
|
||||
disk->usage.free = diskData.f_bfree * diskData.f_frsize;
|
||||
disk->usage.used = (diskData.f_blocks - diskData.f_bfree) * diskData.f_frsize;
|
||||
@@ -50,14 +52,14 @@ void sys::getNetwork(Network* net, const std::string& device) {
|
||||
uint64_t tx = 0;
|
||||
};
|
||||
|
||||
static char buf[24];
|
||||
static char buf[32];
|
||||
static _net prev;
|
||||
_net current;
|
||||
|
||||
current.ts = std::chrono::steady_clock::now();
|
||||
current.rx = utils::fastReadNum("/sys/class/net/" + device + "/statistics/rx_bytes", buf);
|
||||
current.tx = utils::fastReadNum("/sys/class/net/" + device + "/statistics/tx_bytes", buf);
|
||||
float ts_diff = std::chrono::duration_cast<std::chrono::microseconds>(current.ts - prev.ts).count() / 1000000.0f;
|
||||
utils::fastReadNum("/sys/class/net/" + device + "/statistics/rx_bytes", buf, current.rx);
|
||||
utils::fastReadNum("/sys/class/net/" + device + "/statistics/tx_bytes", buf, current.tx);
|
||||
const double ts_diff = std::chrono::duration_cast<std::chrono::microseconds>(current.ts - prev.ts).count() / 1000000.0f;
|
||||
net->download = (current.rx - prev.rx) / ts_diff;
|
||||
net->upload = (current.tx - prev.tx) / ts_diff;
|
||||
prev = current;
|
||||
@@ -74,10 +76,10 @@ void sys::detectHwmon(sysSensors* s, const std::string& platform) {
|
||||
}
|
||||
|
||||
void sys::updateSensors(sysSensors* s) {
|
||||
if (s->hwmon.length() < 1)
|
||||
if (s->hwmon.empty())
|
||||
return;
|
||||
static char buf[8];
|
||||
s->fan_speed[0] = utils::fastReadNum(s->hwmon + "/fan2_input", buf);
|
||||
s->fan_speed[1] = utils::fastReadNum(s->hwmon + "/fan7_input", buf);
|
||||
s->t_sensor = utils::fastReadNum(s->hwmon + "/temp5_input", buf) / 1000;
|
||||
utils::fastReadNum(s->hwmon + "/fan2_input", buf, s->fan_speed[0]);
|
||||
utils::fastReadNum(s->hwmon + "/fan7_input", buf, s->fan_speed[1]);
|
||||
utils::fastReadNumDiv<1000>(s->hwmon + "/temp5_input", buf, s->t_sensor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user