From 0d20dbbfde089b69a3e925d049bb864816c14599 Mon Sep 17 00:00:00 2001 From: norly Date: Mon, 8 Oct 2012 18:30:56 +0100 Subject: [PATCH] Check if battery/netif present, add fan support Also change power reading to work on newer kernels. --- runstatus.sh | 6 ++++-- statuses/Makefile | 2 +- statuses/battery.c | 17 ++++++++++++++--- statuses/netif.c | 2 ++ sysstatus.c | 15 +++++++++++---- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/runstatus.sh b/runstatus.sh index 0b73a7b..a7681f7 100755 --- a/runstatus.sh +++ b/runstatus.sh @@ -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/ diff --git a/statuses/Makefile b/statuses/Makefile index da19ecb..fc60af6 100644 --- a/statuses/Makefile +++ b/statuses/Makefile @@ -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) diff --git a/statuses/battery.c b/statuses/battery.c index e3e3c1b..96e1ddd 100644 --- a/statuses/battery.c +++ b/statuses/battery.c @@ -1,5 +1,6 @@ #include #include +#include #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); diff --git a/statuses/netif.c b/statuses/netif.c index 865e4a7..d5cc803 100644 --- a/statuses/netif.c +++ b/statuses/netif.c @@ -57,6 +57,8 @@ void status_netif(char *ifname) //fputs("^fg(red)", stdout); return; } + } else { + return; } strcpy(&ifpath[ifpathlen], "/statistics/rx_bytes"); diff --git a/sysstatus.c b/sysstatus.c index cac8333..ce6086b 100644 --- a/sysstatus.c +++ b/sysstatus.c @@ -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); -- 2.30.2