summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2012-11-27 18:38:24 +0000
committernorly <ny-git@enpas.org>2012-11-27 18:38:24 +0000
commit9102c7c65421f2ef3e415c7e76a741657e34663b (patch)
tree6fa52cd8b7bccc76b20d89ebabee34d7fa78e65a
parentea0de655211296526a44967e0a4010c064ac5158 (diff)
Clean up battery status, fix wrong time estimate
-rw-r--r--statuses/battery.c45
-rw-r--r--sysstatus.c1
2 files changed, 22 insertions, 24 deletions
diff --git a/statuses/battery.c b/statuses/battery.c
index 96e1ddd..4c35999 100644
--- a/statuses/battery.c
+++ b/statuses/battery.c
@@ -17,14 +17,12 @@ void status_battery(char *batname)
char stline[16];
ssize_t stlen;
- int batt_now = 0;
- 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;
+ int chargeNow = 0;
+ int chargeFull = -1;
+ int chargePercent = -1;
+ int battW = 1;
+ int battV = 0;
+ float battTime = -1;
// Prepare path
@@ -52,33 +50,33 @@ void status_battery(char *batname)
strcpy(&batpath[batpathlen], "/energy_now");
stlen = fileRead(stline, sizeof(stline), batpath);
if (stlen > 0)
- batt_now = atoi(stline);
+ chargeNow = atoi(stline);
strcpy(&batpath[batpathlen], "/energy_full");
stlen = fileRead(stline, sizeof(stline), batpath);
if (stlen > 0)
- batt_full = atoi(stline);
+ chargeFull = atoi(stline);
strcpy(&batpath[batpathlen], "/power_now");
stlen = fileRead(stline, sizeof(stline), batpath);
if (stlen > 0)
- batt_power = atoi(stline);
+ battW = atoi(stline);
strcpy(&batpath[batpathlen], "/voltage_now");
stlen = fileRead(stline, sizeof(stline), batpath);
if (stlen > 0)
- batt_voltage = atoi(stline);
+ battV = atoi(stline);
// Prettyprint
- if (batt_full > 0)
- batt_percent = batt_now / (batt_full / 100);
+ if (chargeFull > 0)
+ chargePercent = chargeNow / (chargeFull / 100);
- if (batt_percent <= 40) // 40
+ if (chargePercent <= 40) // 40
{
- if (batt_percent <= 25) // 25
+ if (chargePercent <= 25) // 25
{
- if (batt_percent <= 10) // 10
+ if (chargePercent <= 10) // 10
fputs("^fg(red)", stdout);
else // 11-25%
fputs("^fg(orange)", stdout);
@@ -88,19 +86,18 @@ void status_battery(char *batname)
}
else
{
- if (batt_percent > 70) // 70
+ if (chargePercent > 70) // 70
fputs("^fg(white)", stdout);
else // 41-70%
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_power / 1000000);
+ battTime = (float)chargeNow / (float)battW;
- if (batt_watts == 0) // fully charged and not in use
- printf(" %s: %d%% _ _ ", batname, batt_percent);
+ if (battW == 0) // fully charged and not in use
+ printf(" %s: %d%% _ _ ",
+ batname, chargePercent);
else
printf(" %s: %d%% %.1fh %.1fW ",
- batname, batt_percent, batt_time, batt_watts);
+ batname, chargePercent, battTime, (float)battW / 1000000.0);
}
diff --git a/sysstatus.c b/sysstatus.c
index 9433da1..aed988c 100644
--- a/sysstatus.c
+++ b/sysstatus.c
@@ -28,6 +28,7 @@ void updatestatus()
//status_netif("eth2");
status_netif("wlan0");
//status_netif("wlan1");
+ status_netif("wlan2");
//status_netif("usb0");
status_netif("ppp0");