add network

This commit is contained in:
Drath Vader
2025-11-28 00:49:19 +01:00
parent 869e5896c9
commit 3411be9262

View File

@@ -34,7 +34,7 @@ struct Sensors {
double avg[3] = {0.0f};
sys::Memory ram;
sys::Disk home;
// sys::Network net;
sys::Network net;
sys::sysSensors sys;
cpu::cpuSensors cpu;
gpu::gpuSensors gpu;
@@ -81,7 +81,7 @@ void sensorsThread(std::stop_token st, Sensors* s) {
getloadavg(s->avg, 3);
sys::getRam(&s->ram);
sys::getDisk(&s->home);
// sys::getNetwork(&s->net, "enp4s0f0");
sys::getNetwork(&s->net, "enp4s0f0");
sys::updateSensors(&s->sys);
cpu::update(&s->cpu);
gpu::update(&s->gpu);
@@ -104,6 +104,8 @@ void displayThread(std::stop_token st, Sensors* s) {
lcd.setCustomChar(0, {16, 6, 9, 8, 8, 9, 6, 0}); // celcius
lcd.setCustomChar(1, {0, 0, 4, 10, 10, 17, 31, 0}); // delta
lcd.setCustomChar(2, {0, 0, 8, 21, 21, 2, 0, 0}); // home (tilde)
lcd.setCustomChar(3, {4, 14, 21, 4, 4, 4 , 0}); // up arrow
lcd.setCustomChar(4, {4, 4, 4, 21, 14, 4 , 0}); // down arrow
// welcome msg
lcd.writeBuf(2, 0, center("Waiting for sensors...", 40));
@@ -119,7 +121,7 @@ void displayThread(std::stop_token st, Sensors* s) {
// prepare some tricky sensors
std::string gpu_temps = std::to_string(s->gpu.temp_edge);
if (s->gpu.temp_hotspot)
gpu_temps = pad(lcd.cc(1) + std::to_string(s->gpu.temp_hotspot - s->gpu.temp_edge) + lcd.cc(0), 4) + pad(gpu_temps + "/" + std::to_string(s->gpu.temp_hotspot), 6);
gpu_temps = pad(lcd.cc(1) + std::to_string(s->gpu.temp_hotspot - s->gpu.temp_edge) + lcd.cc(0), 4) + " " + pad(gpu_temps + "/" + std::to_string(s->gpu.temp_hotspot), 5);
uint16_t cpu_fan = 0;
for (auto &fan : s->sys.fan_speed)
@@ -133,14 +135,16 @@ void displayThread(std::stop_token st, Sensors* s) {
lcd.writeBuf(0, 36, pNum(s->avg[2], s->avg[2] > 10 ? 1 : 2));
lcd.writeBuf(1, 0, pad(std::to_string(s->cpu.tctl) + "/" + std::to_string(s->cpu.tccd1) + lcd.cc(0), 8, JUST::LEFT));
lcd.writeBuf(1, 8, pad(pBytes(s->ram.used, true), 7, JUST::LEFT));
lcd.writeBuf(1, 30 - gpu_temps.size(), pad(pBytes(s->gpu.vram_used), 7));
lcd.writeBuf(1, 7, pad(pBytes(s->ram.used, true), 6, JUST::LEFT));
lcd.writeBuf(1, 13, pad(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, 32 - gpu_temps.size(), pad(pBytes(s->gpu.vram_used), 6));
lcd.writeBuf(1, 39 - gpu_temps.size(), gpu_temps + lcd.cc(0));
lcd.writeBuf(1, 15, std::to_string(s->sys.t_sensor) + lcd.cc(0)); // t_sensor temp
lcd.writeBuf(2, 0, pad(std::to_string((int)s->cpu.ptotal) + "W", 8, JUST::LEFT));
lcd.writeBuf(2, s->cpu.ptotal < 100 ? 4 : 5, std::to_string(cpu_fan) + "R"); // avg fan speed
lcd.writeBuf(2, 16, pad(pNum(s->hass_state) + "W", 4));
lcd.writeBuf(2, 12, lcd.cc(3) + pBytes(s->net.upload));
lcd.writeBuf(2, 19, lcd.cc(4) + pBytes(s->net.download));
lcd.writeBuf(2, 26, pad(std::to_string(s->gpu.fan_speed) + "R", 5));
lcd.writeBuf(2, 31, pad(std::to_string(s->gpu.power_avg) + "/" + std::to_string(s->gpu.power_cap) + "W", 9));