Compare commits

...

9 Commits

Author SHA1 Message Date
59bb33ff7f net autodetect 2026-10-02 13:13:16 +02:00
a92122b41d more reliable gpu path 2026-10-01 20:49:55 +02:00
1469485f3d take full path for the pci dev 2026-10-01 20:49:45 +02:00
252e146576 linuxsmartie used SPLASH 2026-09-30 13:52:39 +02:00
5fe9c57b6e hw handles most of the init sequence now, also reinits whole lcd for
good measure
2026-09-30 13:52:14 +02:00
c764ce9367 lcd now supports 2 extra commands 2026-09-30 13:51:05 +02:00
106de77287 set backlight, dont disable on shutdown 2026-09-28 21:25:33 +02:00
84b8207531 peroper backlight set func 2026-09-28 21:25:21 +02:00
ab4674f6f4 ha tfu distrobox 2026-09-27 21:39:50 +02:00
8 changed files with 61 additions and 28 deletions

View File

@@ -58,13 +58,14 @@ Text04="$dll(hwinfo,1,Vcore,3)V $Right($dll(hwinfo,1,Average Effective Clock,a)M
- CPU cache/iod, likely impossible, zenpower doesnt show it
- GPU clock limit, probably impossible, gpu_metrics doesnt show it?
### Shit needed to compile on Debian 13
### Shit needed to compile on Fedora (44).
V simple:
```bash
sudo apt install build-essential meson libusb-1.0-0-dev pkgconf zlib1g-dev
sudo dnf -y install gcc make libusb1-devel
make -j
```
You're probably on some meme immutable distro so use Debian 13 on distrobox. Any distro with GCC and cmake should work tbh.
You're probably on some meme immutable distro so use toolbox. The [custom toolbox](https://git.drath.cc/drath/dev-toolbx) you have already has everything pre-installed.
### Additional notes

View File

@@ -1,6 +0,0 @@
[linuxsmartie]
additional_packages="build-essential libusb-1.0-0-dev pkgconf zlib1g-dev"
image=quay.io/toolbx-images/debian-toolbox:13
init=false
replace=true
start_now=true

View File

@@ -19,9 +19,12 @@ struct lcd_t {
typedef uint8_t lcd_glyph_t[8];
void lcd_close(struct lcd_t *lcd);
void lcd_reinit(struct lcd_t *lcd);
void lcd_splash(struct lcd_t *lcd);
void lcd_clear(struct lcd_t *lcd);
void lcd_set_contrast(struct lcd_t *lcd, uint8_t contrast);
void lcd_set_backlight(struct lcd_t *lcd, bool enabled);
void lcd_set_brightness(struct lcd_t *lcd, uint8_t brightness);
void lcd_set_cursor(struct lcd_t *lcd, uint8_t row, uint8_t col);
void lcd_set_custom_char(struct lcd_t *lcd, uint8_t index, const lcd_glyph_t *glyph);
void lcd_write_buf(struct lcd_t *lcd, uint8_t row, uint8_t col, const char *str);
@@ -31,4 +34,4 @@ void lcd_flush_buf(struct lcd_t *lcd);
char lcd_bar(struct lcd_t *lcd, uint8_t char_id, double value);
int lcd_init(struct lcd_t *lcd);
#endif
#endif

View File

@@ -15,7 +15,7 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) {
t->module = unknown;
t->num_cores = (uint8_t)sysconf(_SC_NPROCESSORS_ONLN);
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci_dev);
snprintf(t->hwmon, sizeof(t->hwmon), "%s/hwmon", pci_dev);
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
if (ret != 0) {
t->hwmon[0] = '\0';

View File

@@ -18,7 +18,7 @@ static sensor_file_t* sensors;
static int gpu_metrics_fd;
void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci);
snprintf(t->hwmon, sizeof(t->hwmon), "%s/hwmon", pci);
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
if (ret != 0) {
t->hwmon[0] = '\0';
@@ -36,7 +36,7 @@ void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
char raw_metrics[max_metrics_length];
read(gpu_metrics_fd, raw_metrics, sizeof(raw_metrics));
const struct metrics_table_header *header = (struct metrics_table_header *)raw_metrics;
applog(LOG_INF, "Found gpu_metrics_v%d_%d", header->format_revision, header->content_revision);
applog(LOG_INF, "Found gpu_metrics_v%d_%d at %s", header->format_revision, header->content_revision, p);
}
sensors = malloc(sizeof(sensor_file_t) * (t->has_gpu_metrics ? 10 : 5));

View File

@@ -2,12 +2,12 @@
#include "log.h"
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
static int lcd_open(struct lcd_t *lcd, const bool reopen) {
@@ -41,6 +41,16 @@ static void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, const uint16_t l
}
}
void lcd_reinit(struct lcd_t *lcd) {
constexpr uint8_t cmdbuf[] = {0xFE, 63};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
}
void lcd_splash(struct lcd_t *lcd) {
constexpr uint8_t cmdbuf[] = {0xFE, 65};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
}
void lcd_clear(struct lcd_t *lcd) {
constexpr uint8_t cmdbuf[] = {0xFE, 88};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
@@ -58,6 +68,12 @@ void lcd_set_backlight(struct lcd_t *lcd, const bool enabled) {
lcd_write(lcd, cmdbuf, enabled ? 3 : 2);
}
void lcd_set_brightness(struct lcd_t *lcd, const uint8_t brightness) {
applog(LOG_INF, "Set backlight brightness to %d", brightness);
const uint8_t cmdbuf[] = {0xFE, 152, brightness};
lcd_write(lcd, cmdbuf, 3);
}
void lcd_set_cursor(struct lcd_t *lcd, const uint8_t row, const uint8_t col) {
const uint8_t cmdbuf[] = {0xFE, 71, col + 1, row + 1};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
@@ -133,9 +149,6 @@ int lcd_init(struct lcd_t *lcd) {
}
lcd_clear_buf(lcd);
constexpr uint8_t cmdbuf[] = {0xFE, 75, 0xFE, 84};
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
lcd_clear(lcd);
lcd_reinit(lcd);
return 0;
}
}

View File

@@ -19,9 +19,8 @@
static constexpr uint8_t lcd_contrast = 250;
static constexpr uint16_t refresh_interval_ms = 1000;
static constexpr char netif[] = "enp7s0";
static constexpr char cpu_pcidev[] = "0000:00:18.3";
static constexpr char gpu_pcidev[] = "0000:0a:00.0";
static constexpr char cpu_pcidev[] = "/sys/bus/pci/devices/0000:00:18.3";
static constexpr char gpu_pcidev[] = "/sys/class/drm/renderD128/device";
static struct {
pthread_mutex_t sensors_mtx;
@@ -52,7 +51,7 @@ static void *sensors_thread(void *arg) {
/* set up paths for the sensors */
strcpy(sensors->home.mountpoint, "/home/drath");
strcpy(sensors->gry.mountpoint, "/var/mnt/gry");
strcpy(sensors->net.device, netif);
// strcpy(sensors->net.device, netif);
cpu_detect(&sensors->cpu, cpu_pcidev);
gpu_detect(&sensors->gpu, gpu_pcidev);
sys_detect(&sensors->sys, "nct6775.656");
@@ -99,6 +98,7 @@ static void *display_thread(void *arg) {
.baud = 0010002, // from termios-baud.h, B115200
};
lcd_init(&lcd);
lcd_set_brightness(&lcd, 255);
lcd_set_backlight(&lcd, true);
lcd_set_contrast(&lcd, lcd_contrast);
@@ -174,9 +174,7 @@ static void *display_thread(void *arg) {
lcd_clear_buf(&lcd);
}
lcd_write_buf(&lcd, 2, 16, "Goodbye"); // center
lcd_set_backlight(&lcd, false);
lcd_flush_buf(&lcd);
lcd_splash(&lcd);
lcd_close(&lcd);
applog(LOG_WRN, "display thread stopped");
return nullptr;

View File

@@ -2,6 +2,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/statvfs.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <time.h>
#include "log.h"
@@ -91,7 +94,28 @@ void sys_get_network(struct network_t *network) {
}
void sys_netdev_detect(struct network_t *network) {
applog(LOG_INF, "Opening netdev %s", network->device);
struct ifaddrs *ifaddr;
getifaddrs(&ifaddr);
char addr[INET_ADDRSTRLEN];
for (const struct ifaddrs *ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
// ugliest fucking if
if (!ifa->ifa_addr ||
ifa->ifa_addr->sa_family != AF_INET ||
!(ifa->ifa_flags & IFF_UP) ||
!(ifa->ifa_flags & IFF_RUNNING) ||
ifa->ifa_flags & IFF_LOOPBACK)
continue;
const struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr));
if (strncmp("10.0.1.", addr, 7) == 0) {
strcpy(network->device, ifa->ifa_name);
break;
}
}
freeifaddrs(ifaddr);
applog(LOG_INF, "Detected %s with addr %s", network->device, addr);
static char path[128];
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/", network->device);
open_sensor(&network->f_rx, path, "rx_bytes", nullptr, 1, SENSOR_U64);