summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/print_battery_info.c17
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));