add bar drawing, use pointers more
This commit is contained in:
@@ -36,24 +36,24 @@ LCDDisplay::~LCDDisplay() {
|
||||
|
||||
void LCDDisplay::clear() {
|
||||
uint8_t cmdbuf[] = {254, 88};
|
||||
write(_lcd, cmdbuf, 2);
|
||||
write(_lcd, &cmdbuf, 2);
|
||||
}
|
||||
|
||||
void LCDDisplay::setContrast(uint8_t contrast) {
|
||||
std::cout << "[LCDDisplay] Set contrast to " << std::to_string(contrast) << std::endl;
|
||||
uint8_t cmdbuf[] = {254, 80, contrast};
|
||||
write(_lcd, cmdbuf, 3);
|
||||
write(_lcd, &cmdbuf, 3);
|
||||
}
|
||||
|
||||
void LCDDisplay::setBacklight(bool enabled) {
|
||||
std::cout << "[LCDDisplay] Backlight set to " << std::to_string(enabled) << std::endl;
|
||||
uint8_t cmdbuf[] = {254, (uint8_t)(enabled ? 66 : 70), 255};
|
||||
write(_lcd, cmdbuf, enabled ? 3 : 2);
|
||||
write(_lcd, &cmdbuf, enabled ? 3 : 2);
|
||||
}
|
||||
|
||||
void LCDDisplay::setCursor(uint8_t row, uint8_t col) {
|
||||
uint8_t cmdbuf[] = {254, 71, (uint8_t)(col + 1), (uint8_t)(row + 1)};
|
||||
write(_lcd, cmdbuf, 4);
|
||||
write(_lcd, &cmdbuf, 4);
|
||||
}
|
||||
|
||||
void LCDDisplay::writeStr(std::string str) {
|
||||
@@ -62,7 +62,7 @@ void LCDDisplay::writeStr(std::string str) {
|
||||
|
||||
void LCDDisplay::writeLines(std::array<std::string, 4> lines) {
|
||||
for (auto& line : lines) {
|
||||
if(line.size() > 40) {
|
||||
if (line.size() > 40) {
|
||||
std::cerr << "Line " << line << " too long! (" << line.size() << " chars)" << std::endl;
|
||||
continue;
|
||||
}
|
||||
@@ -85,10 +85,22 @@ void LCDDisplay::writeSStream(std::stringstream& ss) {
|
||||
writeStr(s.substr(80, 159));
|
||||
}
|
||||
|
||||
|
||||
void LCDDisplay::setCustomChar(uint8_t index, std::array<uint8_t, 8> cchar) {
|
||||
uint8_t cmdbuf[11];
|
||||
cmdbuf[0] = 254; cmdbuf[1] = 78; cmdbuf[2] = index;
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
cmdbuf[i+3] = cchar[i];
|
||||
write(_lcd, cmdbuf, 11);
|
||||
cmdbuf[0] = 254;
|
||||
cmdbuf[1] = 78;
|
||||
cmdbuf[2] = index;
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
cmdbuf[i + 3] = cchar[i];
|
||||
write(_lcd, &cmdbuf, 11);
|
||||
}
|
||||
|
||||
char LCDDisplay::bar(uint8_t char_id, double value) {
|
||||
std::array<uint8_t, 8> b;
|
||||
b.fill(0b01110);
|
||||
for(uint8_t i = 0; i < (1.0 - value) * 8; i++)
|
||||
b[i] = 0;
|
||||
setCustomChar(char_id, b);
|
||||
return cc[char_id];
|
||||
}
|
||||
19
src/gpu.cpp
19
src/gpu.cpp
@@ -5,12 +5,6 @@
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
struct GpuMetricsHeader_t {
|
||||
uint16_t structure_size;
|
||||
uint8_t format_revision;
|
||||
uint8_t content_revision;
|
||||
};
|
||||
|
||||
struct GpuMetrics_v1_1_t {
|
||||
uint16_t temperature_edge;
|
||||
uint16_t temperature_hotspot;
|
||||
@@ -95,11 +89,11 @@ GpuMetricsHeader_t getGpuMetricsRev(std::string path) {
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (f.good()) {
|
||||
f.read(reinterpret_cast<char *>(&header), sizeof(header));
|
||||
std::cout << "[GpuMetrics] Read GpuMetrics format v" << std::to_string(header.format_revision) << "_" << std::to_string(header.content_revision);
|
||||
std::cout << "[GpuMetrics] header at path " + path + " read, GpuMetrics_v" << std::to_string(header.format_revision) << "_" << std::to_string(header.content_revision);
|
||||
std::cout << ", size " << std::to_string(header.structure_size) << std::endl;
|
||||
f.close();
|
||||
} else {
|
||||
std::cerr << "[GpuMetrics] Error reading gpu metrics header" << std::endl;
|
||||
std::cerr << "[GpuMetrics] error reading header at path " + path << std::endl;
|
||||
}
|
||||
|
||||
return header;
|
||||
@@ -122,15 +116,14 @@ auto getGpuMetrics(GpuMetricsHeader_t h, std::string path) {
|
||||
}
|
||||
|
||||
// clean abstraction of gpu_metrics + extra metrics from fs
|
||||
gpu_t getGpu(std::string hw) {
|
||||
gpu_t getGpu(GpuMetricsHeader_t header, std::string hw) {
|
||||
gpu_t gpu;
|
||||
auto h = getGpuMetricsRev(hw + "/gpu_metrics");
|
||||
auto metrics = getGpuMetrics(h, hw + "/gpu_metrics");
|
||||
auto metrics = getGpuMetrics(header, hw + "/gpu_metrics");
|
||||
|
||||
// we want as much data as posible from gpu_metrics so we dont read filesystem as much
|
||||
gpu.fan_speed = std::stol(readFile(hw + "/hwmon/hwmon2/fan1_input"));
|
||||
gpu.core_clock = metrics.average_vclk1_frequency; // why not gfxclock?
|
||||
gpu.mem_clock = metrics.average_gfxclk_frequency; // why gfxclock? min mem clock seems to be 96mhz, this is probably including time sleeping
|
||||
gpu.core_clock = metrics.average_vclk1_frequency; // why not gfxclock?
|
||||
gpu.mem_clock = metrics.average_gfxclk_frequency; // why gfxclock? min mem clock seems to be 96mhz, this is probably including time sleeping
|
||||
gpu.vcore = std::stod(readFile(hw + "/hwmon/hwmon2/in0_input")) / 1000.0;
|
||||
gpu.power_avg = metrics.average_socket_power;
|
||||
gpu.power_cap = std::stol(readFile(hw + "/hwmon/hwmon2/power1_cap", 6));
|
||||
|
||||
Reference in New Issue
Block a user