add bar drawing, use pointers more

This commit is contained in:
Drath
2025-05-03 20:20:15 +02:00
parent e08f6c8077
commit 8632cab336
7 changed files with 99 additions and 41 deletions

View File

@@ -115,24 +115,40 @@ mem_usage_t getDisk(std::string mount) {
auto getCpuTemp(std::string hw) {
struct {
double tdie;
double tctl;
double tccd1;
double pcore = 0.0;
double psoc = 0.0;
double ptotal = 0.0;
double vcore = 0.0;
double vsoc = 0.0;
} cpu;
cpu.tctl = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
cpu.tccd1 = (double)(std::stoul(readFile(hw + "/temp3_input")) / 1000.0);
if (readFile(hw + "/name") == "zenpower") {
cpu.tdie = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
cpu.tctl = (double)(std::stoul(readFile(hw + "/temp2_input")) / 1000.0);
cpu.tccd1 = (double)(std::stoul(readFile(hw + "/temp3_input")) / 1000.0);
cpu.pcore = (double)(std::stoul(readFile(hw + "/power1_input")) / 1000000.0);
cpu.psoc = (double)(std::stoul(readFile(hw + "/power2_input")) / 1000000.0);
cpu.ptotal = cpu.pcore + cpu.psoc;
cpu.vcore = (double)(std::stoul(readFile(hw + "/in1_input")) / 1000.0);
cpu.vsoc = (double)(std::stoul(readFile(hw + "/in2_input")) / 1000.0);
} else {
cpu.tctl = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
cpu.tccd1 = (double)(std::stoul(readFile(hw + "/temp3_input")) / 1000.0);
}
return cpu;
}
void collectAndDraw(LCDDisplay *lcd) {
}
int main(int argc, char *argv[]) {
bool daemon_mode = (argc > 1 && std::string(argv[1]) == "-d");
/* init lcd, set contrast and backlight */
/* init lcd and chars, set contrast and backlight */
LCDDisplay lcd(LCD_PORT, 0010002);
lcd.setCustomChar(0, {16, 6, 9, 8, 8, 9, 6, 0}); // celcius
/* only set in daemon mode, so we dont burn through eeprom writes if running with watch -n 1 when testing */
if (daemon_mode) {
lcd.setContrast(LCD_CONTRAST);
lcd.setBacklight(true);
@@ -141,7 +157,21 @@ int main(int argc, char *argv[]) {
/* initial vars */
std::array<std::string, 4> lines;
auto cpu_hwmon = findHwmonPath("k10temp");
auto gpu_hwmon = "/sys/class/drm/card1/device";
if (cpu_hwmon.size() == 0) {
std::cout << "[Hwmon] k10temp not found, trying zenpower" << std::endl;
cpu_hwmon = findHwmonPath("zenpower");
}
std::string gpu_hwmon;
GpuMetricsHeader_t gpu_mtr_rev;
for(uint8_t i = 0; i < 10; i++) {
gpu_hwmon = "/sys/class/drm/card" + std::to_string(i) + "/device";
gpu_mtr_rev = getGpuMetricsRev(gpu_hwmon + "/gpu_metrics");
if(gpu_mtr_rev.structure_size > 0)
break;
}
/* loop setup */
std::cout << "[Chrono] Running in daemon mode, " << LCD_INTERVAL_MS << "ms interval" << std::endl;
@@ -154,24 +184,25 @@ int main(int argc, char *argv[]) {
auto ram = getRam();
auto anime = getDisk("/mnt/anime");
auto home = getDisk("/var/home/drath");
auto gpu = getGpu(gpu_hwmon);
auto gpu = getGpu(gpu_mtr_rev, gpu_hwmon);
auto cpu = getCpuTemp(cpu_hwmon);
lines[0] = td[1] + " " + td[0] + pad(getAvgs(), 20);
lines[0] = td[1] + " " + td[0] + lcd.bar(1, gpu.core_usage / 100.0) + pad(getAvgs(), 17);
lines[1] = pad(pNum(cpu.tctl) + "/" + pNum(cpu.tccd1) + "C", 8, true);
lines[1] = pad(pNum(cpu.tctl) + "/" + pNum(cpu.tccd1) + lcd.cc[0], 8, true);
lines[1] += pad(pBytes(ram.used, true) + "B", 7, true);
lines[1] += fill(7);
lines[1] += pad(pBytes(gpu.vram_used) + "B", 7);
lines[1] += pad(std::to_string(gpu.edge_temp) + "/" + std::to_string(gpu.hotspot_temp) + "/" + std::to_string(gpu.mem_temp) + "C", 11);
lines[1] += pad(std::to_string(gpu.edge_temp) + "/" + std::to_string(gpu.hotspot_temp) + "/" + std::to_string(gpu.mem_temp) + lcd.cc[0], 11);
lines[2] = pad("home: " + pBytes(home.free), 11, true);
lines[2] += fill(15);
lines[2] = pad(pNum(cpu.ptotal, 1) + "W", 8, true);
lines[2] += pad("home: " + pBytes(home.free), 12);
lines[2] += fill(6);
lines[2] += pad(pNum(gpu.fan_speed) + "R", 5);
lines[2] += pad(std::to_string(gpu.power_avg) + "/" + std::to_string(gpu.power_cap) + "W", 9);
lines[3] = pad("anime: " + pBytes(anime.free), 13, true);
lines[3] += fill(8);
lines[3] = pad(pNum(cpu.vcore, 3) + "V", 6, true);
lines[3] += fill(15);
lines[3] += pad(pNum(gpu.core_clock) + "/" + pNum(gpu.mem_clock) + "MHz ", 13);
lines[3] += pad(pNum(gpu.vcore, 3) + "V", 5);