Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] Charger indicator
From: Magnus Holmgren (lear_at_algonet.se)
Date: 2002-08-25


Hi,

The attached patch generalizes the charging indicator (animating the
battery), so that it works on players as well as recorders (I also made
the animation a little faster). That includes blinking the indicator if
the level is low. As I only have a player to test with, I might have
broken something for the recorder...

Note that this isn't perfect: the battery isn't always animated, because
status_draw isn't always called upon regularly (e.g., while in some
menus)... Should perhaps the status bar be handled by a separate thread?

I also patched the main menu (for players only), since the battery info
display seemes to be incorrect while the charger is active.

-- 
Magnus Holmgren

Index: apps/status.c
===================================================================
RCS file: /cvsroot/rockbox/apps/status.c,v
retrieving revision 1.19
diff -u -b -r1.19 status.c
--- apps/status.c 21 Aug 2002 11:51:24 -0000 1.19
+++ apps/status.c 24 Aug 2002 21:50:39 -0000
@@ -32,12 +32,13 @@
 
 static enum playmode current_mode = STATUS_STOP;
 
+static long switch_tick;
+static bool plug_state;
+static bool battery_state;
+static int battery_charge_step = 0;
+
 #ifdef HAVE_LCD_BITMAP
 bool statusbar_enabled = true;
-long switch_tick;
-bool plug_state;
-bool battery_state;
-int battery_charge_step = 0;
 #endif
 
 void status_init(void)
@@ -63,11 +64,53 @@
 
 void status_draw(void)
 {
-#if defined(HAVE_LCD_CHARCELLS)
     int battlevel = battery_level();
+#if !defined(HAVE_LCD_BITMAP) || defined(HAVE_CHARGE_CTRL)
+ if (charger_inserted())
+ {
+ battery_state = true;
+ plug_state = true;
+
+#ifdef HAVE_LCD_BITMAP
+ if (charger_enabled)
+ {
+#endif
+ /* animate battery if charging */
+ battlevel = battery_charge_step * 34; /* 34 for a better look */
+ battlevel = battlevel > 100 ? 100 : battlevel;
+
+ if (TIME_AFTER(current_tick, switch_tick))
+ {
+ battery_charge_step = (battery_charge_step + 1) % 4;
+ switch_tick = current_tick + (HZ / 2);
+ }
+#ifdef HAVE_LCD_BITMAP
+ }
+#endif
+ }
+ else
+ {
+ plug_state = false;
+
+ if (battery_level_safe())
+ {
+ battery_state = true;
+ }
+ else /* blink battery if level is low */
+ {
+ if (TIME_AFTER(current_tick, switch_tick))
+ {
+ switch_tick = current_tick + (HZ / 2);
+ battery_state =! battery_state;
+ }
+ }
+ }
+#endif
+
+#if defined(HAVE_LCD_CHARCELLS)
     int volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
     
- lcd_icon(ICON_BATTERY, true);
+ lcd_icon(ICON_BATTERY, battery_state);
     if(battlevel > 25)
         lcd_icon(ICON_BATTERY_1, true);
     else
@@ -126,35 +169,11 @@
     }
 #endif
 #ifdef HAVE_LCD_BITMAP
- int battlevel = battery_level();
     int volume = mpeg_val2phys(SOUND_VOLUME, global_settings.volume);
 
     if(global_settings.statusbar && statusbar_enabled) {
         statusbar_wipe();
 #ifdef HAVE_CHARGE_CTRL
- if(charger_inserted()) {
- battery_state = true;
- plug_state = true;
- if(charger_enabled) { /* animate battery if charging */
- battlevel = battery_charge_step * 34; /* 34 for a better look */
- battlevel = battlevel > 100 ? 100 : battlevel;
- if(TIME_AFTER(current_tick, switch_tick)) {
- battery_charge_step=(battery_charge_step+1)%4;
- switch_tick = current_tick + HZ;
- }
- }
- }
- else {
- plug_state=false;
- if(battery_level_safe())
- battery_state = true;
- else /* blink battery if level is low */
- if(TIME_AFTER(current_tick, switch_tick)) {
- switch_tick = current_tick+HZ;
- battery_state =! battery_state;
- }
- }
-
         if(battery_state) statusbar_icon_battery(battlevel, plug_state);
 #else
         statusbar_icon_battery(battlevel, false);
Index: apps/main_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/main_menu.c,v
retrieving revision 1.52
diff -u -b -r1.52 main_menu.c
--- apps/main_menu.c 23 Aug 2002 12:32:52 -0000 1.52
+++ apps/main_menu.c 24 Aug 2002 21:50:44 -0000
@@ -159,7 +159,15 @@
 #endif
 
 #ifdef HAVE_LCD_CHARCELLS
+ if (charger_inserted())
+ {
+ snprintf(s, sizeof(s), "Batt: charg");
+ }
+ else
+ {
         snprintf(s, sizeof(s), "Batt: %d%%%s", battery_level(), battery_level_safe() ? "" : "!");
+ }
+
         lcd_puts(0, 1, s);
 #else
 #ifdef HAVE_CHARGE_CTRL



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa