dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

commit 333e9e02bf76b7371c7a1d2fc4812e54785ac88b
parent 10a89e5d9d74ef7261eaedf5f3ed0923440a180f
Author: tongong <tongong@gmx.net>
Date:   Sun, 11 Jul 2021 22:41:09 +0200

fixed temperature block [dsblocks]

Diffstat:
Msuckless/dsblocks/blocks/temp.c | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/suckless/dsblocks/blocks/temp.c b/suckless/dsblocks/blocks/temp.c @@ -1,5 +1,7 @@ +#include <dirent.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "../util.h" #include "temp.h" @@ -7,16 +9,32 @@ #define ICON " " #define DEGREES "°C" -#define TEMPFILE "/sys/class/hwmon/hwmon0/temp1_input" +#define TEMPDIR "/sys/bus/platform/devices/coretemp.0/hwmon" #define MAX_CHARS_PER_LINE 10 size_t tempu(char *str, int sigval) { + // get correct hwmon device + DIR *d; + d = opendir(TEMPDIR); + char fullpath[100] = TEMPDIR; /* 100 is randomly chosen */ + + struct dirent *dir; + // i'm too lazy for error handling + while (dir = readdir(d)) { + if (!strncmp(dir->d_name, "hwmon", 5)) { + strcat(fullpath, "/"); + strcat(fullpath, dir->d_name); + strcat(fullpath, "/temp1_input"); + } + } + closedir(d); + FILE *tempfile; char tempstring[MAX_CHARS_PER_LINE]; unsigned int tempnum; - tempfile = fopen(TEMPFILE, "r"); + tempfile = fopen(fullpath, "r"); fgets(tempstring, MAX_CHARS_PER_LINE, tempfile); fclose(tempfile); tempnum = atoi(tempstring);