Charging state reporting for iriver players. Values calibrated with

1900 mAh Ionity battery; might need recalibration with the stock
battery.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9030 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2006-03-13 16:11:30 +00:00
parent b4171645a5
commit 451ee0b11c
6 changed files with 65 additions and 22 deletions

View File

@ -109,9 +109,7 @@ void gui_statusbar_init(struct gui_statusbar * bar)
{
bar->last_volume = -1000; /* -1000 means "first update ever" */
bar->battery_icon_switch_tick = 0;
#ifdef HAVE_CHARGING
bar->battery_charge_step = 0;
#endif
bar->animated_level = 0;
}
void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
@ -199,11 +197,20 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
{
#endif
/* animate in three steps (34% per step for a better look) */
bar->info.battlevel = bar->battery_charge_step * 34;
if (bar->info.battlevel > 100)
bar->info.battlevel = 100;
#ifndef HAVE_CHARGE_STATE
bar->info.battlevel = 0;
#endif
if(TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) {
bar->battery_charge_step=(bar->battery_charge_step+1)%4;
if (bar->animated_level == 100)
{
bar->animated_level = bar->info.battlevel;
}
else
{
bar->animated_level += 34;
if (bar->animated_level > 100)
bar->animated_level = 100;
}
bar->battery_icon_switch_tick = current_tick + HZ;
}
}
@ -211,6 +218,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
else
#endif /* HAVE_CHARGING */
{
bar->animated_level = 0;
if (bar->info.battery_safe)
battery_state = true;
else {
@ -224,7 +232,8 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
}
#ifdef HAVE_LCD_BITMAP
if (battery_state)
gui_statusbar_icon_battery(display, bar->info.battlevel);
gui_statusbar_icon_battery(display, bar->info.battlevel,
bar->animated_level);
#ifdef HAVE_USB_POWER
if (bar->info.usb_power)
display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
@ -316,11 +325,15 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
/*
* Print battery icon to status bar
*/
void gui_statusbar_icon_battery(struct screen * display, int percent)
void gui_statusbar_icon_battery(struct screen * display, int percent,
int animated_percent)
{
int fill;
int fill, endfill;
char buffer[5];
unsigned int width, height;
#if LCD_DEPTH > 1
unsigned int prevfg = LCD_DEFAULT_FG;
#endif
/* fill battery */
fill = percent;
@ -329,6 +342,12 @@ void gui_statusbar_icon_battery(struct screen * display, int percent)
if (fill > 100)
fill = 100;
endfill = animated_percent;
if (endfill < 0)
endfill = 0;
if (endfill > 100)
endfill = 100;
#if (defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)) && \
!defined(SIMULATOR) /* Certain charge controlled targets */
/* show graphical animation when charging instead of numbers */
@ -358,6 +377,20 @@ void gui_statusbar_icon_battery(struct screen * display, int percent)
fill = fill * 15 / 100;
display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
fill, 5);
#if LCD_DEPTH > 1
if (display->depth > 1)
{
prevfg = display->get_foreground();
display->set_foreground(LCD_DARKGRAY);
}
#endif
endfill = endfill * 15 / 100 - fill;
display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
STATUSBAR_Y_POS + 1, endfill, 5);
#if LCD_DEPTH > 1
if (display->depth > 1)
display->set_foreground(prevfg);
#endif
}
if (percent == -1) {

View File

@ -53,9 +53,6 @@ struct status_info {
#ifdef HAVE_USB_POWER
bool usb_power;
#endif
#ifdef HAVE_CHARGING
int battery_charge_step;
#endif
};
struct gui_statusbar
@ -63,12 +60,9 @@ struct gui_statusbar
/* Volume icon stuffs */
long volume_icon_switch_tick;
int last_volume;
long battery_icon_switch_tick;
#ifdef HAVE_CHARGING
int battery_charge_step;
#endif
int animated_level;
struct status_info info;
struct status_info lastinfo;
@ -101,7 +95,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
*/
extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
void gui_statusbar_icon_battery(struct screen * display, int percent);
void gui_statusbar_icon_battery(struct screen * display, int percent, int animated_percent);
bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
void gui_statusbar_icon_play_state(struct screen * display, int state);
void gui_statusbar_icon_play_mode(struct screen * display, int mode);

View File

@ -150,8 +150,13 @@ void charger_enable(bool on)
#endif
#ifdef HAVE_CHARGE_STATE
/* Returns true if the unit is charging the batteries. */
bool charging_state(void) {
#if defined(IRIVER_H100_SERIES)
return charger_inserted();
#else /* Iriver H300 */
return (GPIO_READ & 0x00800000)?true:false;
#endif
}
#endif

View File

@ -78,6 +78,9 @@
/* Define this if the platform can charge batteries */
#define HAVE_CHARGING 1
/* For units with a hardware charger that reports charge state */
#define HAVE_CHARGE_STATE 1
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING

View File

@ -73,6 +73,9 @@
/* Define this if the platform can charge batteries */
#define HAVE_CHARGING 1
/* For units with a hardware charger that reports charge state */
#define HAVE_CHARGE_STATE 1
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING

View File

@ -140,7 +140,10 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{ 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */
#elif CONFIG_BATTERY == BATT_LIPOL1300
/* Below 337 the backlight starts flickering during HD access */
{ 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 }
/* Calibrated for Ionity 1900 mAh battery. If necessary, re-calibrate
* for the 1300 mAh stock battery. */
// { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 }
{ 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 }
#else /* NiMH */
/* original values were taken directly after charging, but it should show
100% after turning off the device for some hours, too */
@ -156,7 +159,9 @@ charger_input_state_type charger_input_state IDATA_ATTR;
static const short percent_to_volt_charge[11] =
{
#if CONFIG_BATTERY == BATT_LIPOL1300
340, 349, 358, 367, 376, 385, 394, 403, 408, 413, 418 /* Estimated */
/* Calibrated for 1900 mAh Ionity battery (estimated 90% charge when
entering in trickle-charging). We will never reach 100%. */
340, 390, 394, 399, 400, 404, 407, 413, 417, 422, 426
#else
/* values guessed, see
http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone
@ -533,8 +538,8 @@ static void power_thread_sleep(int ticks)
#ifdef HAVE_CHARGE_STATE
switch (charger_input_state) {
case CHARGER_UNPLUGGED:
charge_state = DISCHARGING;
case NO_CHARGER:
charge_state = DISCHARGING;
break;
case CHARGER_PLUGGED:
case CHARGER: