gpu delta, needs cleanup
This commit is contained in:
20
main.cpp
20
main.cpp
@@ -41,7 +41,7 @@ struct Sensors {
|
||||
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
|
||||
};
|
||||
|
||||
void sighandler(int s) { // can i remove int s
|
||||
void sighandler(int s) { // can i remove int s
|
||||
std::println("[Signal] got SIGINT/SIGTERM, exiting...");
|
||||
sem::main.release();
|
||||
sem::display.release();
|
||||
@@ -101,8 +101,11 @@ void displayThread(std::stop_token st, Sensors* s) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s->mtx);
|
||||
|
||||
auto gpu_temps = (s->gpu.temp_hotspot) ? "/" + std::to_string(s->gpu.temp_hotspot) : "";
|
||||
gpu_temps += (s->gpu.temp_mem) ? "/" + std::to_string(s->gpu.temp_mem) : "";
|
||||
std::string gpu_temps;
|
||||
// gpu_temps += pad("d" + std::to_string(s->gpu.temp_hotspot - s->gpu.temp_edge), 3, true) + lcd.cc[0];
|
||||
gpu_temps += std::to_string(s->gpu.temp_edge);
|
||||
gpu_temps += (s->gpu.temp_hotspot) ? "/" + std::to_string(s->gpu.temp_hotspot) : "";
|
||||
// gpu_temps += (s->gpu.temp_mem) ? "/" + std::to_string(s->gpu.temp_mem) : "";
|
||||
|
||||
lcd.writeBuf(0, 0, pad(s->td.date, 11, true) + " " + s->td.time + lcd.bar(1, s->gpu.usage_core / 100.0) /* + pad(s->loadavg, 17)*/);
|
||||
lcd.writeBuf(0, 26, pNum(s->avg[0], s->avg[0] > 10 ? 1 : 2));
|
||||
@@ -111,9 +114,9 @@ void displayThread(std::stop_token st, Sensors* s) {
|
||||
|
||||
lcd.writeBuf(1, 0, pad(std::to_string(s->cpu.tctl) + "/" + std::to_string(s->cpu.tccd1) + lcd.cc[0], 8, true));
|
||||
lcd.writeBuf(1, 8, pad(pBytes(s->ram.used, true) + "B", 7, true));
|
||||
lcd.writeBuf(1, 16, pad(pNum(s->hass_state) + "W", 4));
|
||||
lcd.writeBuf(1, 22, pad(pBytes(s->gpu.vram_used) + "B", 7));
|
||||
lcd.writeBuf(1, 29, pad(std::to_string(s->gpu.temp_edge) + gpu_temps + lcd.cc[0], 11));
|
||||
lcd.writeBuf(1, 20, pad(pBytes(s->gpu.vram_used) + "B", 7));
|
||||
if (s->gpu.temp_hotspot) lcd.writeBuf(1, 28, "d" + std::to_string(s->gpu.temp_hotspot - s->gpu.temp_edge) + lcd.cc[0] + " ");
|
||||
lcd.writeBuf(1, 32, pad(gpu_temps + lcd.cc[0], 8));
|
||||
|
||||
lcd.writeBuf(2, 0, pad(pNum(s->cpu.ptotal, 1) + "W", 8, true));
|
||||
lcd.writeBuf(2, 8, "home:" + pad(pBytes(s->home.free), 5));
|
||||
@@ -124,6 +127,7 @@ void displayThread(std::stop_token st, Sensors* s) {
|
||||
|
||||
lcd.writeBuf(3, 0, pad(pNum(s->cpu.vcore, 3) + "V", 7, true));
|
||||
lcd.writeBuf(3, 7, std::to_string(s->cpu.avg_freq) + "MHz");
|
||||
lcd.writeBuf(3, 16, pad(pNum(s->hass_state) + "W", 4));
|
||||
lcd.writeBuf(3, 21, pad(std::to_string(s->gpu.clock_core) + "/" + std::to_string(s->gpu.clock_mem) + "MHz ", 13));
|
||||
lcd.writeBuf(3, 34, pad(pNum(s->gpu.vcore, 3) + "V", 5));
|
||||
}
|
||||
@@ -143,7 +147,7 @@ int main(int argc, char* argv[]) {
|
||||
Sensors* pSensors = new Sensors;
|
||||
std::println("[main] size of sensor struct is {} bytes", sizeof(Sensors));
|
||||
|
||||
std::function<void(std::stop_token st, Sensors * s)> funcs[] = {displayThread, hassThread, sensorsThread}; // array of functions
|
||||
std::function<void(std::stop_token st, Sensors * s)> funcs[] = {displayThread, hassThread, sensorsThread}; // array of functions
|
||||
|
||||
/* what the fucking kind of code is this
|
||||
this code below spins up display/sensors/homeassistant functions as threads and halts until sem::main is released in sighandler
|
||||
@@ -154,7 +158,7 @@ int main(int argc, char* argv[]) {
|
||||
{
|
||||
std::vector<std::jthread> threads;
|
||||
for (auto& f : funcs)
|
||||
threads.emplace_back(f, pSensors); // params: function, stop_token (implied), pointer to sensor struct
|
||||
threads.emplace_back(f, pSensors); // params: function, stop_token (implied), pointer to sensor struct
|
||||
|
||||
sem::main.acquire();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user