diff options
author | Simon Elsbrock <simon@iodev.org> | 2012-08-23 16:42:38 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-08-28 18:05:11 +0200 |
commit | 68f438ec9eefbca5d735a1a7897d52e0e8e6f1c7 (patch) | |
tree | 47b3009417de351625131bc3525154acf8c70fcf /src | |
parent | 3baf27bf1d9b51fa8de3203a64993de2464ed356 (diff) |
add additional battery threshold type "percentage"
The battery threshold can now be configured as type "time" or
"percentage", but defaults to "time" to prevent unexpected behavior.
Also, low_threshold was set to a more reasonable default of 30.
Diffstat (limited to 'src')
-rw-r--r-- | src/print_battery_info.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 3e130c7..202d9bb 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -29,7 +29,7 @@ * worn off your battery is. * */ -void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity) { +void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity) { time_t empty_time; struct tm *empty_tm; char buf[1024]; @@ -127,8 +127,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); - (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", - (((float)remaining / (float)full_design) * 100)); + float percentage_remaining = (((float)remaining / (float)full_design) * 100); + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); if (present_rate > 0) { float remaining_time; @@ -146,8 +146,15 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char minutes = seconds / 60; seconds -= (minutes * 60); - if (status == CS_DISCHARGING && threshold > 0 && seconds_remaining < 60 * threshold) - START_COLOR("color_bad"); + if (status == CS_DISCHARGING && low_threshold > 0) { + if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0 + && percentage_remaining < low_threshold) { + START_COLOR("color_bad"); + } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0 + && seconds_remaining < 60 * low_threshold) { + START_COLOR("color_bad"); + } + } (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", max(hours, 0), max(minutes, 0), max(seconds, 0)); |