Check if battery/netif present, add fan support
authornorly <ny-git@enpas.org>
Mon, 8 Oct 2012 17:30:56 +0000 (18:30 +0100)
committernorly <ny-git@enpas.org>
Mon, 8 Oct 2012 17:31:57 +0000 (18:31 +0100)
Also change power reading to work on newer kernels.

runstatus.sh
statuses/Makefile
statuses/battery.c
statuses/netif.c
sysstatus.c

index 0b73a7bee8a631c1080b07ef65186eb323bc2aa8..a7681f77439148830bc5a2aeeb443e415e1dd9a1 100755 (executable)
@@ -1,14 +1,16 @@
 #!/bin/sh
 
+MAXRESX=1680
+
 RES=$(xrandr --prop | sed "s/Screen 0:[^,]*, current \(.*\) x \(.*\),.*/\1,\2/g;te;d;:e")
 RESX=${RES%%,*}
 RESY=${RES##*,}
 FONT="-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso8859-1"
 #FONT="-*-fixed-medium-r-semicondensed-*-13-*-*-*-*-*-*-*"
 
-if [ $((RESX)) -gt 1920 ]
+if [ $((RESX)) -gt $((MAXRESX)) ]
 then
-       RESX=1920
+       RESX=$((MAXRESX))
 fi
 
 cd ~/sysstatus/
index da19ecbeeb57fa6344cba20eb3de7777a11a86b6..fc60af6c0a4e893f0a5d8423f16cfe6a3aa56301 100644 (file)
@@ -1,4 +1,4 @@
-STATUSES=battery.o cpuusage.o datetime.o memusage.o netif.o temp.o uptime.o volume_alsa.o
+STATUSES=battery.o cpuusage.o datetime.o fan.o memusage.o netif.o temp.o uptime.o volume_alsa.o
 OTHERS=tools.o
 
 all: *.c *.h ../config.h Makefile $(STATUSES) $(OTHERS)
index e3e3c1b7a01f3bb2e4da790361835247443bba94..96e1ddd6d435aaa6204f14d5525c5714bffd5a60 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include "string.h"
 #include "battery.h"
 
@@ -20,6 +21,7 @@ void status_battery(char *batname)
        int batt_full = -1;
        int batt_percent = -1;
        int batt_current = 1;
+       int batt_power = 1;
        int batt_voltage = 0;
        float batt_time = -1;
        float batt_watts = -1;
@@ -38,6 +40,14 @@ void status_battery(char *batname)
        strcat(batpath, batname);
 
 
+       // Is the battery present?
+       if (access(batpath, F_OK))
+       {
+               //printf(" ^fg(grey)[%s] ", batname);
+               return;
+       }
+
+
        // Get info
        strcpy(&batpath[batpathlen], "/energy_now");
        stlen = fileRead(stline, sizeof(stline), batpath);
@@ -49,10 +59,10 @@ void status_battery(char *batname)
        if (stlen > 0)
                batt_full = atoi(stline);
 
-       strcpy(&batpath[batpathlen], "/current_now");
+       strcpy(&batpath[batpathlen], "/power_now");
        stlen = fileRead(stline, sizeof(stline), batpath);
        if (stlen > 0)
-               batt_current = atoi(stline);
+               batt_power = atoi(stline);
 
        strcpy(&batpath[batpathlen], "/voltage_now");
        stlen = fileRead(stline, sizeof(stline), batpath);
@@ -84,8 +94,9 @@ void status_battery(char *batname)
                        fputs("^fg(green)", stdout);
        }
 
+       batt_current = ((float)batt_power * 100) / ((float)batt_voltage / 100000);
        batt_time = (float)batt_now / (float)batt_current;
-       batt_watts = ((float)batt_voltage / 1000000) * ((float)batt_current / 10000000);
+       batt_watts = ((float)batt_power / 1000000);
 
        if (batt_watts == 0)    // fully charged and not in use
                printf(" %s: %d%% _ _ ", batname, batt_percent);
index 865e4a7a22962d7c5b471cd92f8dc370264e07d1..d5cc8037610a7b408eb6fda55c26fce3c3489399 100644 (file)
@@ -57,6 +57,8 @@ void status_netif(char *ifname)
                        //fputs("^fg(red)", stdout);
                        return;
                }
+       } else {
+               return;
        }
 
        strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes");
index cac8333056b29a66689ccc0c2a0a6fc674c0cb64..ce6086b4d2a6fe37aba376a8bf45b54c3a880052 100644 (file)
@@ -4,6 +4,7 @@
 #include "statuses/battery.h"
 #include "statuses/cpuusage.h"
 #include "statuses/datetime.h"
+#include "statuses/fan.h"
 #include "statuses/memusage.h"
 #include "statuses/netif.h"
 #include "statuses/volume_alsa.h"
@@ -18,17 +19,23 @@ void updatestatus()
        status_cpuusage();
 
        status_battery("BAT0");
+       status_battery("BAT1");
 
        status_memusage();
 
        status_netif("eth0");
-       status_netif("eth1");
+       //status_netif("eth1");
+       //status_netif("eth2");
        status_netif("wlan0");
-       status_netif("wlan1");
+       //status_netif("wlan1");
+       //status_netif("usb0");
        status_netif("ppp0");
 
-       status_temp("GPU: ", "/sys/class/hwmon/hwmon0/device/temp4_input");
-       status_temp("CPU: ", "/sys/class/hwmon/hwmon0/device/temp2_input");
+       //status_temp("GPU: ", "/sys/class/hwmon/hwmon0/device/temp4_input");
+       //status_temp("CPU: ", "/sys/class/hwmon/hwmon0/device/temp2_input");
+       status_temp("CPU: ", "/sys/class/hwmon/hwmon1/device/temp1_input");
+
+       status_fan("Fan: ", "/sys/class/hwmon/hwmon2/device/fan1_input");
 
        status_volume_alsa("default", "Master", 0);