t* dwmstatus for OpenBSD URI git clone git://git.codevoid.de/dwmstatus-sdk DIR Log DIR Files DIR Refs DIR LICENSE --- DIR commit a7ed94764ae00edced4ca65047ca006b655569a0 DIR parent b588d102e43fd5a299eeef9a70ae935c67790f14 URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de> Date: Sun, 28 Apr 2019 09:02:33 +0200 Add FanRPM and cleanup Diffstat: M dwmstatus.c | 46 ++++++++++--------------------- 1 file changed, 14 insertions(+), 32 deletions(-) --- DIR diff --git a/dwmstatus.c b/dwmstatus.c t@@ -7,25 +7,16 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> -#include <strings.h> #include <sys/time.h> -#include <time.h> -#include <sys/types.h> #include <sys/sysctl.h> #include <sys/sensors.h> #include <sys/ioctl.h> #include <sys/audioio.h> -#include <sys/socket.h> #include <machine/apmvar.h> -#include <sys/wait.h> -#include <signal.h> #include <fcntl.h> #include <X11/Xlib.h> #include <sys/param.h> #include <sys/mount.h> -#ifdef __linux__ -#include <sys/vfs.h> -#endif // configuration #define UPDATE_INTERVAL 10 t@@ -72,10 +63,18 @@ char * getcputemp() { struct sensor sensor; size_t slen = sizeof(sensor); int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 }; // Lenovo x230 - if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) { - return smprintf("err"); - } - return smprintf("%.0f", (sensor.value - 273150000) / 1000000.0); + if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) + return smprintf("%.0f", (sensor.value - 273150000) / 1000000.0); + return smprintf("err"); +} + +char * getfan() { + struct sensor sensor; + size_t slen = sizeof(sensor); + int mib[5] = { CTL_HW, HW_SENSORS, 5, SENSOR_FANRPM, 0 }; // Lenovo x230 + if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) + return smprintf("%i", sensor.value); + return smprintf("err"); } char * getvolume() { t@@ -175,14 +174,6 @@ char * readfile(char *base, char *file) { return smprintf("%s", line); } -char * gettemperature(char *base, char *sensor) { - char *co; - co = readfile(base, sensor); - if (co == NULL) - return smprintf(""); - return smprintf("%02.0f°C", atof(co) / 1000); -} - char * getbattery() { int fd; t@@ -212,14 +203,6 @@ void update() { char *time_utc = mktimes("%H:%M", "UTC"); char *date_utc = mktimes("%d.%m.%Y", "UTC"); - // cpu frequency - // cpufreq = smprintf("%i", getsysctl("dev.cpu.0.freq")); - - // battery - // battery = smprintf("%i", ge tsysctl("hw.acpi.battery.life")); - // audio volume - char *volume = getvolume(); - // free disk space (root/home) char *freehomespace = getfreespace("/home"); char *freerootspace = getfreespace("/"); t@@ -232,9 +215,9 @@ void update() { warn = " !!! LOW DISK SPACE WARNING @ ROOT !!! |"; // display status - setstatus(smprintf("Bat: %s%% | Vol: %s%% | Temp: %s°C | Load: %s | %s | %s;" + setstatus(smprintf("Bat: %s%% | Vol: %s%% | Temp: %s°C (%sRPM) | Load: %s | %s | %s;" "Network: %s | Address: %s |%s /home: %sMB | /: %sMB", - getbattery(), volume, getcputemp(), loadavg(), date, time, + getbattery(), getvolume(), getcputemp(), getfan(), loadavg(), date, time, "PowerMate 2.4GHz", "192.168.2.235", warn, freehomespace, freerootspace)); // free everything up t@@ -242,7 +225,6 @@ void update() { free(time_utc); free(date); free(date_utc); - free(volume); free(freehomespace); free(freerootspace); }