temp.c (1093B)
1 #include <dirent.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 #include "../util.h" 7 #include "temp.h" 8 9 #define ICON " " 10 #define DEGREES "°C" 11 12 #define TEMPDIR "/sys/bus/platform/devices/coretemp.0/hwmon" 13 #define MAX_CHARS_PER_LINE 10 14 15 size_t tempu(char *str, int sigval) 16 { 17 // get correct hwmon device 18 DIR *d; 19 d = opendir(TEMPDIR); 20 char fullpath[100] = TEMPDIR; /* 100 is randomly chosen */ 21 22 struct dirent *dir; 23 // i'm too lazy for error handling 24 while (dir = readdir(d)) { 25 if (!strncmp(dir->d_name, "hwmon", 5)) { 26 strcat(fullpath, "/"); 27 strcat(fullpath, dir->d_name); 28 strcat(fullpath, "/temp1_input"); 29 } 30 } 31 closedir(d); 32 33 FILE *tempfile; 34 char tempstring[MAX_CHARS_PER_LINE]; 35 unsigned int tempnum; 36 37 tempfile = fopen(fullpath, "r"); 38 fgets(tempstring, MAX_CHARS_PER_LINE, tempfile); 39 fclose(tempfile); 40 tempnum = atoi(tempstring); 41 tempnum /= 1000; 42 43 return SPRINTF(str, ICON "%02d" DEGREES, tempnum); 44 } 45 46 void tempc(int button) 47 { 48 TERMCMD("s-tui"); 49 }