]> Dogcows Code - chaz/tint2/commitdiff
patch for FULL battery by peter.ebden
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Wed, 28 Oct 2009 10:58:12 +0000 (10:58 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Wed, 28 Oct 2009 10:58:12 +0000 (10:58 +0000)
src/battery/battery.c
src/battery/battery.h

index d5bf0a98851b870961beb299b2410254979b7e93..1e7feea3bde02da5fe2644a0460a5171fa92079f 100644 (file)
@@ -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;
 
index 5fb1fdf13abfb82ae66684d90d63110ee93da189..c0b4c4f8f80bffa8215a0ce923917b481db0421e 100644 (file)
@@ -30,7 +30,8 @@ typedef struct Battery {
 enum chargestate {
        BATTERY_UNKNOWN,
        BATTERY_CHARGING,
-       BATTERY_DISCHARGING
+       BATTERY_DISCHARGING,
+       BATTERY_FULL
 };
 
 typedef struct battime {
This page took 0.026317 seconds and 4 git commands to generate.