* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit b588d102e43fd5a299eeef9a70ae935c67790f14
   DIR parent 7bf763a0426f1124a7eca8f21255e496e9747ea2
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Sat, 27 Apr 2019 11:52:51 +0200
       
       Add CPU temperature sensor reading
       
       Diffstat:
         M dwmstatus.c                         |      28 +++++++++++++---------------
       
       1 file changed, 13 insertions(+), 15 deletions(-)
       ---
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -12,6 +12,7 @@
        #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>
       @@ -67,12 +68,15 @@ char * getfreespace(const char *path) {
            return smprintf("%ld", (vfs.f_bavail * vfs.f_bsize) / 1024 / 1024);
        }
        
       -//char * getsysctl(char *input_str) {
       -//    char   *ret_val;
       -//    size_t ret_size;
       -//
       -//    return "not implemented";
       -//}
       +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);
       +}
        
        char * getvolume() {
        
       @@ -149,8 +153,7 @@ char * loadavg(void) {
            if (getloadavg(avgs, 3) < 0)
                return smprintf("");
        
       -    // return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
       -    return smprintf("%.2f", avgs[0]);
       +    return smprintf("%.2f|%.2f|%.2f", avgs[0], avgs[1], avgs[2]);
        }
        
        char * readfile(char *base, char *file) {
       @@ -209,16 +212,11 @@ void update() {
            char *time_utc = mktimes("%H:%M", "UTC");
            char *date_utc = mktimes("%d.%m.%Y", "UTC");
        
       -    // cpu temperature
       -    // char *cputemp;
       -    // cputemp  = smprintf("%i", ZEROCTOC((int)getsysctl("hw.acpi.thermal.tz0.temperature")));
       -
            // 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();
        
       @@ -234,9 +232,9 @@ void update() {
                warn = "     !!! LOW DISK SPACE WARNING @ ROOT !!!    |";
        
            // display status
       -    setstatus(smprintf("Battery: %s%% | Volume: %s%% | Load: %s | %s | %s;"
       +    setstatus(smprintf("Bat: %s%% | Vol: %s%% | Temp: %s°C | Load: %s | %s | %s;"
                               "Network: %s | Address: %s |%s /home: %sMB | /: %sMB",
       -                       getbattery(), volume, loadavg(), date, time,
       +                       getbattery(), volume, getcputemp(), loadavg(), date, time,
                               "PowerMate 2.4GHz", "192.168.2.235", warn, freehomespace, freerootspace));
        
            // free everything up