diff options
author | Marcel Hellwig <keks@cookiesoft.de> | 2012-07-10 11:45:45 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-07-11 19:11:08 +0200 |
commit | 1271ff2aa4bac659d5a24c08f86205df971a58af (patch) | |
tree | dcc158c21833c556de345161ad1a96cf91fb73a5 /src/print_battery_info.c | |
parent | f5c96008b0c5ec41b6f136b0af41c56f6af2ccb8 (diff) |
Calculate the consumption if POWER_SUPPLY_POWER_NOW does not exist in uevent
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r-- | src/print_battery_info.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 74d4460..d3a931c 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -42,7 +42,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char char *outwalk = buffer; int full_design = -1, remaining = -1, - present_rate = -1; + present_rate = -1, + voltage = -1, + current = -1; charging_status_t status = CS_DISCHARGING; memset(statusbuf, '\0', sizeof(statusbuf)); @@ -74,7 +76,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW")) remaining = atoi(walk+1); else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW")) - present_rate = atoi(walk+1); + current = atoi(walk+1); + else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW")) + voltage = atoi(walk+1); else if (BEGINS_WITH(last, "POWER_SUPPLY_POWER_NOW")) present_rate = atoi(walk+1); else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Charging")) @@ -97,6 +101,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char } } + if (present_rate == -1) /* on some systems POWER_SUPPLY_POWER_NOW does not exist, so we have to calculate it */ + present_rate = ((float)voltage / 1000.0) * ((float)current / 1000.0); + if ((full_design == -1) || (remaining == -1)) { OUTPUT_FULL_TEXT("No battery"); return; |