From 3cf41266a0125935c58edb64941f2a27a0fab3c4 Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Wed, 28 Oct 2009 10:58:12 +0000 Subject: [PATCH] patch for FULL battery by peter.ebden --- src/battery/battery.c | 18 ++++++++++++++++-- src/battery/battery.h | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index d5bf0a9..1e7feea 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -145,7 +145,11 @@ void init_battery_panel(void *p) update_battery(&battery_state); snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage); - snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); + if(battery_state.state == BATTERY_FULL) { + strcpy(buf_bat_time, "Full"); + } else { + snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); + } get_text_size(bat1_font_desc, &bat_percentage_height_ink, &bat_percentage_height, panel->area.height, buf_bat_percentage, strlen(buf_bat_percentage)); get_text_size(bat2_font_desc, &bat_time_height_ink, &bat_time_height, panel->area.height, buf_bat_time, strlen(buf_bat_time)); @@ -206,6 +210,7 @@ void update_battery() { battery_state.state = BATTERY_UNKNOWN; if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING; if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING; + if(strcasecmp(tmp, "Full\n")==0) battery_state.state = BATTERY_FULL; if(current_now > 0) { switch(battery_state.state) { @@ -236,6 +241,11 @@ void update_battery() { } battery_state.percentage = new_percentage; + + // clamp percentage to 100 in case battery is misreporting that its current charge is more than its max + if(battery_state.percentage > 100) { + battery_state.percentage = 100; + } } @@ -281,7 +291,11 @@ void resize_battery(void *obj) battery->area.redraw = 1; snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage); - snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); + if(battery_state.state == BATTERY_FULL) { + strcpy(buf_bat_time, "Full"); + } else { + snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); + } // vertical panel doen't adjust width if (!panel_horizontal) return; diff --git a/src/battery/battery.h b/src/battery/battery.h index 5fb1fdf..c0b4c4f 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -30,7 +30,8 @@ typedef struct Battery { enum chargestate { BATTERY_UNKNOWN, BATTERY_CHARGING, - BATTERY_DISCHARGING + BATTERY_DISCHARGING, + BATTERY_FULL }; typedef struct battime { -- 2.45.2