Compare commits
12 Commits
f46e7df5f3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 59bb33ff7f | |||
| a92122b41d | |||
| 1469485f3d | |||
| 252e146576 | |||
| 5fe9c57b6e | |||
| c764ce9367 | |||
| 106de77287 | |||
| 84b8207531 | |||
| ab4674f6f4 | |||
| 764dd1a4a9 | |||
| 244213f396 | |||
| 74362a0dad |
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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));
|
||||
|
||||
39
src/lcd.c
39
src/lcd.c
@@ -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,25 +41,41 @@ 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[] = {254, 88};
|
||||
constexpr uint8_t cmdbuf[] = {0xFE, 88};
|
||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||
}
|
||||
|
||||
void lcd_set_contrast(struct lcd_t *lcd, const uint8_t contrast) {
|
||||
applog(LOG_INF, "Set contrast to %d", contrast);
|
||||
const uint8_t cmdbuf[] = {254, 80, contrast};
|
||||
const uint8_t cmdbuf[] = {0xFE, 80, contrast};
|
||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||
}
|
||||
|
||||
void lcd_set_backlight(struct lcd_t *lcd, const bool enabled) {
|
||||
applog(LOG_INF, "Set backlight to %s", enabled ? "true" : "false");
|
||||
const uint8_t cmdbuf[] = {254, (enabled ? 66 : 70), 255};
|
||||
const uint8_t cmdbuf[] = {0xFE, (enabled ? 66 : 70), 255};
|
||||
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[] = {254, 71, col + 1, row + 1};
|
||||
const uint8_t cmdbuf[] = {0xFE, 71, col + 1, row + 1};
|
||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||
}
|
||||
|
||||
@@ -99,7 +115,7 @@ inline void lcd_clear_buf(struct lcd_t *lcd) {
|
||||
memset(lcd->writebuf.text, ' ', sizeof(lcd->writebuf.text));
|
||||
// prepare commands for custom chars
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
const uint8_t charbuf[] = {254, 78, i};
|
||||
const uint8_t charbuf[] = {0xFE, 78, i};
|
||||
memcpy(lcd->writebuf.cchar[i], charbuf, sizeof(charbuf));
|
||||
}
|
||||
}
|
||||
@@ -107,7 +123,7 @@ inline void lcd_clear_buf(struct lcd_t *lcd) {
|
||||
|
||||
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */
|
||||
void lcd_flush_buf(struct lcd_t *lcd) {
|
||||
constexpr uint8_t set_disp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
|
||||
constexpr uint8_t set_disp[] = {0xFE, 71, 1, 1}; // set cursor to char 1, line 1
|
||||
memcpy(&lcd->writebuf.text[0], set_disp, 4);
|
||||
memcpy(&lcd->writebuf.text[2 * LCD_COLS + 4], set_disp, 4);
|
||||
lcd->writebuf.text[2 * LCD_COLS + 7] = 3; // overwrite set cursor c1 l1 to c1 l3
|
||||
@@ -133,9 +149,6 @@ int lcd_init(struct lcd_t *lcd) {
|
||||
}
|
||||
|
||||
lcd_clear_buf(lcd);
|
||||
constexpr uint8_t cmdbuf[] = {254, 75, 254, 84};
|
||||
lcd_write(lcd, cmdbuf, sizeof(cmdbuf));
|
||||
|
||||
lcd_clear(lcd);
|
||||
lcd_reinit(lcd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main.c
16
src/main.c
@@ -19,9 +19,8 @@
|
||||
|
||||
static constexpr uint8_t lcd_contrast = 250;
|
||||
static constexpr uint16_t refresh_interval_ms = 1000;
|
||||
static constexpr char netif[] = "enp4s0f0";
|
||||
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");
|
||||
@@ -95,10 +94,11 @@ static void *display_thread(void *arg) {
|
||||
|
||||
/* lcd setup */
|
||||
struct lcd_t lcd = {
|
||||
.port = "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6616407E37AA12F-if00",
|
||||
.port = "/dev/serial/by-id/usb-Drath_Technologies_Serial_Display_Controller_00002-if00",
|
||||
.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;
|
||||
@@ -236,4 +234,4 @@ int main() {
|
||||
pthread_join(display_pthread, nullptr);
|
||||
free(sensors);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/sys.c
26
src/sys.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user