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



Rockbox mail archive

Subject: Re: Charging screen, Re: An other battery issue with flashed rockbox
From: Nix (nix_at_esperi.demon.co.uk)
Date: 2003-07-19


On Fri, 18 Jul 2003, Henrik Backe yowled:
> Also you could examine Mike Holden's USB battery info patch
> at http://www.mikeholden.org/~rockbox/patches/battery.diff
> It does not apply correctly any more, but I don't think it will take to much
> work to
> get it to work.

A few days ago I posted one that worked (well, that worked as of a few
days ago).

Here it is again:

diff -durN rockbox-devel-orig/apps/debug_menu.c rockbox-devel-battery/apps/debug_menu.c
--- rockbox-devel-orig/apps/debug_menu.c 2003-05-26 14:01:50.000000000 +0100
+++ rockbox-devel-battery/apps/debug_menu.c 2003-07-05 23:45:39.000000000 +0100
@@ -799,9 +799,9 @@
                 snprintf(buf, 30, "Charger: %s",
                          charger_inserted() ? "present" : "absent");
                 lcd_puts(0, 3, buf);
-#ifdef HAVE_CHARGE_CTRL
+#ifdef HAVE_CHARGE_DETECT
                 snprintf(buf, 30, "Charging: %s",
- charger_enabled ? "yes" : "no");
+ charger_is_enabled() ? "yes" : "no");
                 lcd_puts(0, 4, buf);
 #endif
                 y = ( power_history[POWER_HISTORY_LEN-1] * 100
@@ -845,7 +845,7 @@
                 lcd_clear_display();
 
 #ifdef HAVE_CHARGE_CTRL
- snprintf(buf, 30, "charge_state: %d", charge_state);
+ snprintf(buf, 30, "charge_state: %d", charger_status());
                 lcd_puts(0, 0, buf);
 
                 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
diff -durN rockbox-devel-orig/apps/main_menu.c rockbox-devel-battery/apps/main_menu.c
--- rockbox-devel-orig/apps/main_menu.c 2003-07-05 20:33:40.000000000 +0100
+++ rockbox-devel-battery/apps/main_menu.c 2003-07-05 23:45:39.000000000 +0100
@@ -190,11 +190,11 @@
             lcd_puts(0, y++, s);
             
 #ifdef HAVE_CHARGE_CTRL
- if (charge_state == 1)
+ if (charger_status() == 1)
                 snprintf(s, sizeof(s), str(LANG_BATTERY_CHARGE));
- else if (charge_state == 2)
+ else if (charger_status() == 2)
                 snprintf(s, sizeof(s), str(LANG_BATTERY_TOPOFF_CHARGE));
- else if (charge_state == 3)
+ else if (charger_status() == 3)
                 snprintf(s, sizeof(s), str(LANG_BATTERY_TRICKLE_CHARGE));
             else
 #endif
diff -durN rockbox-devel-orig/apps/recorder/icons.c rockbox-devel-battery/apps/recorder/icons.c
--- rockbox-devel-orig/apps/recorder/icons.c 2003-07-05 20:35:22.000000000 +0100
+++ rockbox-devel-battery/apps/recorder/icons.c 2003-07-05 23:45:39.000000000 +0100
@@ -27,6 +27,7 @@
 #include "settings.h"
 
 #include "icons.h"
+#include "usb.h"
 
 unsigned char slider_bar[] =
 {
@@ -159,12 +160,13 @@
 #ifdef SIMULATOR
     if (global_settings.battery_type) {
 #else
-#ifdef HAVE_CHARGE_CTRL /* Recorder */
+#ifdef HAVE_CHARGE_DETECT /* Recorder & FM */
     /* show graphical animation when charging instead of numbers */
- if ((global_settings.battery_type) && (charge_state != 1)) {
-#else /* FM */
+ if (((global_settings.battery_type) && (charger_status() != 1)) ||
+ usb_inserted()) {
+#else
     if (global_settings.battery_type) {
-#endif /* HAVE_CHARGE_CTRL */
+#endif /* HAVE_CHARGE_DETECT */
 #endif
         /* Numeric display */
         snprintf(buffer, sizeof(buffer), "%3d", percent);
diff -durN rockbox-devel-orig/apps/screens.c rockbox-devel-battery/apps/screens.c
--- rockbox-devel-orig/apps/screens.c 2003-07-05 20:34:02.000000000 +0100
+++ rockbox-devel-battery/apps/screens.c 2003-07-05 23:46:15.000000000 +0100
@@ -32,6 +32,7 @@
 #include "playlist.h"
 #include "sprintf.h"
 #include "kernel.h"
+#include "powermgmt.h"
 
 #ifdef HAVE_LCD_BITMAP
 #define BMPHEIGHT_usb_logo 32
@@ -74,9 +75,20 @@
 
 void usb_display_info(void)
 {
- lcd_clear_display();
+ unsigned char buffer[7];
+#ifdef HAVE_LCD_BITMAP
+ unsigned int width, height;
+#endif
+ int runtime = battery_time();
+ int hour = runtime / 60;
+ int minute = runtime % 60;
+
+ snprintf(buffer, sizeof(buffer), "%2dh%02dm", hour, minute);
 
 #ifdef HAVE_LCD_BITMAP
+ lcd_getstringsize(buffer, &width, &height);
+ lcd_clear_display();
+
     /* lcd_bitmap() only supports 16 pixels height! */
     lcd_bitmap(usb_logo, 6, 16,
                BMPWIDTH_usb_logo, 8, false);
@@ -87,9 +99,11 @@
     lcd_bitmap(usb_logo+BMPWIDTH_usb_logo*3, 6, 40,
                BMPWIDTH_usb_logo, 8, false);
     status_draw(true);
+ lcd_putsxy(0, LCD_HEIGHT - height, buffer);
     lcd_update();
 #else
     lcd_puts(0, 0, "[USB Mode]");
+ lcd_puts(0, 1, buffer);
     status_set_param(false);
     status_set_audio(false);
     status_set_usb(true);
diff -durN rockbox-devel-orig/apps/status.c rockbox-devel-battery/apps/status.c
--- rockbox-devel-orig/apps/status.c 2003-06-08 23:02:17.000000000 +0100
+++ rockbox-devel-battery/apps/status.c 2003-07-05 23:45:39.000000000 +0100
@@ -33,6 +33,7 @@
 #include "icons.h"
 #endif
 #include "powermgmt.h"
+#include "usb.h"
 
 static enum playmode current_mode = STATUS_STOP;
 
@@ -135,22 +136,27 @@
         if (info.inserted) {
             battery_state = true;
             plug_state = true;
-#ifdef HAVE_CHARGE_CTRL
+#ifdef HAVE_CHARGE_DETECT
             /* zero battery run time if charging */
- if (charge_state > 0)
+ if (charger_status() > 0)
                 global_settings.runtime = 0;
             
             /* animate battery if charging */
- if (charge_state == 1) {
+ if (charger_status() == 1) {
 #else
             {
 #endif
- /* animate in three steps (34% per step for a better look) */
- info.battlevel = battery_charge_step * 34;
- if (info.battlevel > 100)
- info.battlevel = 100;
+ if (!usb_inserted()) {
+ /* animate in three steps (34% per step for a better look) */
+ info.battlevel = battery_charge_step * 34;
+ if (info.battlevel > 100)
+ info.battlevel = 100;
+ }
                 if(TIME_AFTER(current_tick, switch_tick)) {
                     battery_charge_step=(battery_charge_step+1)%4;
+ if (usb_inserted()) {
+ plug_state = battery_charge_step%2;
+ }
                     switch_tick = current_tick + HZ;
                 }
             }
@@ -171,19 +177,21 @@
 #ifdef HAVE_LCD_BITMAP
         if (battery_state)
             statusbar_icon_battery(info.battlevel, plug_state);
- statusbar_icon_volume(info.volume);
- statusbar_icon_play_state(current_mode + Icon_Play);
- switch (info.repeat) {
- case REPEAT_ONE:
- statusbar_icon_play_mode(Icon_RepeatOne);
- break;
+ if (!usb_inserted()) {
+ statusbar_icon_volume(info.volume);
+ statusbar_icon_play_state(current_mode + Icon_Play);
+ switch (info.repeat) {
+ case REPEAT_ONE:
+ statusbar_icon_play_mode(Icon_RepeatOne);
+ break;
 
- case REPEAT_ALL:
- statusbar_icon_play_mode(Icon_Repeat);
- break;
+ case REPEAT_ALL:
+ statusbar_icon_play_mode(Icon_Repeat);
+ break;
+ }
+ if (info.shuffle)
+ statusbar_icon_shuffle();
         }
- if (info.shuffle)
- statusbar_icon_shuffle();
         if (info.keylock)
             statusbar_icon_lock();
 #ifdef HAVE_RTC
diff -durN rockbox-devel-orig/apps/tree.c rockbox-devel-battery/apps/tree.c
--- rockbox-devel-orig/apps/tree.c 2003-07-05 20:34:10.000000000 +0100
+++ rockbox-devel-battery/apps/tree.c 2003-07-05 23:45:39.000000000 +0100
@@ -1183,6 +1183,7 @@
             case SYS_USB_CONNECTED:
                 status_set_playmode(STATUS_STOP);
                 usb_screen();
+ status_draw(true);
                 reload_root = true;
                 break;
 
diff -durN rockbox-devel-orig/firmware/drivers/power.c rockbox-devel-battery/firmware/drivers/power.c
--- rockbox-devel-orig/firmware/drivers/power.c 2003-07-05 20:36:12.000000000 +0100
+++ rockbox-devel-battery/firmware/drivers/power.c 2003-07-05 23:45:39.000000000 +0100
@@ -29,6 +29,22 @@
 
 #ifndef SIMULATOR
 
+bool charger_is_enabled(void)
+{
+#ifdef HAVE_CHARGE_CTRL
+ /* Recorder */
+ return charger_enabled;
+#else
+#ifdef HAVE_FMADC
+ /* FM */
+ return adc_read(ADC_EXT_POWER) > 0x0C0;
+#else
+ /* Player */
+ return 0;
+#endif /* HAVE_FMADC */
+#endif /* HAVE_CHARGE_CTRL */
+}
+
 bool charger_inserted(void)
 {
 #ifdef HAVE_CHARGE_CTRL
diff -durN rockbox-devel-orig/firmware/export/config-fmrecorder.h rockbox-devel-battery/firmware/export/config-fmrecorder.h
--- rockbox-devel-orig/firmware/export/config-fmrecorder.h 2003-05-05 23:04:36.000000000 +0100
+++ rockbox-devel-battery/firmware/export/config-fmrecorder.h 2003-07-05 23:45:39.000000000 +0100
@@ -16,6 +16,9 @@
 /* Define this if you have a FM Recorder key system */
 #define HAVE_FMADC 1
 
+/* Define this if you have charging detection */
+#define HAVE_CHARGE_DETECT
+
 /* Define this if you have a LiIon battery */
 #define HAVE_LIION
 
diff -durN rockbox-devel-orig/firmware/export/config-recorder.h rockbox-devel-battery/firmware/export/config-recorder.h
--- rockbox-devel-orig/firmware/export/config-recorder.h 2003-05-05 23:41:56.000000000 +0100
+++ rockbox-devel-battery/firmware/export/config-recorder.h 2003-07-05 23:45:39.000000000 +0100
@@ -16,6 +16,9 @@
 /* Define this if you have charging control */
 #define HAVE_CHARGE_CTRL
 
+/* Define this if you have charging detection */
+#define HAVE_CHARGE_DETECT
+
 /* Define this if you have ATA power-off control */
 #define HAVE_ATA_POWER_OFF
 
diff -durN rockbox-devel-orig/firmware/export/power.h rockbox-devel-battery/firmware/export/power.h
--- rockbox-devel-orig/firmware/export/power.h 2003-02-07 10:07:49.000000000 +0000
+++ rockbox-devel-battery/firmware/export/power.h 2003-07-05 23:45:39.000000000 +0100
@@ -19,10 +19,7 @@
 #ifndef _POWER_H_
 #define _POWER_H_
 
-#ifdef HAVE_CHARGE_CTRL
-extern bool charger_enabled;
-#endif
-
+bool charger_is_enabled(void);
 bool charger_inserted(void);
 void charger_enable(bool on);
 void ide_power_enable(bool on);
diff -durN rockbox-devel-orig/firmware/export/powermgmt.h rockbox-devel-battery/firmware/export/powermgmt.h
--- rockbox-devel-orig/firmware/export/powermgmt.h 2003-05-05 23:40:58.000000000 +0100
+++ rockbox-devel-battery/firmware/export/powermgmt.h 2003-07-05 23:45:39.000000000 +0100
@@ -68,7 +68,6 @@
 extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */
 void enable_trickle_charge(bool on);
 extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
-extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */
 
 #endif /* HAVE_CHARGE_CTRL */
 
@@ -84,6 +83,12 @@
 
 #endif /* SIMULATOR */
 
+/* Returns charging status */
+/* FM, 0: not charging, 1: charging */
+/* Recorder, 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */
+/* Player, always returns 0 */
+int charger_status(void);
+
 /* Returns battery level in percent */
 int battery_level(void);
 int battery_time(void); /* minutes */
diff -durN rockbox-devel-orig/firmware/powermgmt.c rockbox-devel-battery/firmware/powermgmt.c
--- rockbox-devel-orig/firmware/powermgmt.c 2003-06-11 23:29:51.000000000 +0100
+++ rockbox-devel-battery/firmware/powermgmt.c 2003-07-05 23:45:39.000000000 +0100
@@ -40,6 +40,11 @@
 
 #ifdef SIMULATOR
 
+int charger_status(void)
+{
+ return 0;
+}
+
 int battery_level(void)
 {
     return 75;
@@ -146,6 +151,22 @@
 
 unsigned short power_history[POWER_HISTORY_LEN];
 
+int charger_status(void)
+{
+#ifdef HAVE_CHARGE_CTRL
+ /* Recorder */
+ return charge_state;
+#else
+#ifdef HAVE_FMADC
+ /* FM */
+ return adc_read(ADC_EXT_POWER) > 0x0C0;
+#else
+ /* Player */
+ return 0;
+#endif /* HAVE_FMADC */
+#endif /* HAVE_CHARGE_CTRL */
+}
+
 int battery_time(void)
 {
     return powermgmt_est_runningtime_min;
@@ -598,7 +619,7 @@
                 /* the charger is enabled here only in one case: if it was
                    turned on at boot time (power_init) */
                 /* turn it off now */
- if (charger_enabled)
+ if (charger_is_enabled())
                     charger_enable(false);
             }
 
diff -durN rockbox-devel-orig/firmware/usb.c rockbox-devel-battery/firmware/usb.c
--- rockbox-devel-orig/firmware/usb.c 2003-07-05 20:35:49.000000000 +0100
+++ rockbox-devel-battery/firmware/usb.c 2003-07-05 23:45:39.000000000 +0100
@@ -348,4 +348,9 @@
 {
 }
 
+bool usb_inserted(void)
+{
+ return 0;
+}
+
 #endif

-- 
`We cannot get a new line down the pipe due to a blockage and we cannot
 dig up the road to clear the blockage because it is covered with the
 wrong type of tarmac.' --- British Telecom, via Mark Lowes



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