Don't show battery meter until a proper power reading has been done

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4042 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2003-11-19 14:14:41 +00:00
parent db4bee4308
commit f6b6db4167
3 changed files with 23 additions and 10 deletions

View file

@ -175,8 +175,9 @@ void status_draw(bool force_redraw)
}
#ifdef HAVE_LCD_BITMAP
if (battery_state)
if (battery_state && (info.battlevel > -1))
statusbar_icon_battery(info.battlevel, plug_state);
statusbar_icon_volume(info.volume);
statusbar_icon_play_state(current_mode + Icon_Play);
switch (info.repeat) {
@ -202,6 +203,7 @@ void status_draw(bool force_redraw)
#if defined(HAVE_LCD_CHARCELLS)
if (info.battlevel > -1)
lcd_icon(ICON_BATTERY, battery_state);
lcd_icon(ICON_BATTERY_1, info.battlevel > 25);
lcd_icon(ICON_BATTERY_2, info.battlevel > 50);

View file

@ -478,10 +478,14 @@ static char* get_tag(struct mp3entry* id3,
return buf;
case 't': /* estimated battery time */
snprintf(buf, buf_size, "%dh %dm",
battery_time() / 60,
battery_time() % 60);
{
int t = battery_time();
if (t >= 0)
snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60);
else
strncpy(buf, "?h ?m", buf_size);
return buf;
}
}
break;

View file

@ -184,15 +184,13 @@ void battery_level_update(void)
int c = 0;
int i;
/* calculate average over last 3 minutes (skip empty samples) */
/* calculate maximum over last 3 minutes (skip empty samples) */
for (i = 0; i < 3; i++)
if (power_history[POWER_HISTORY_LEN-1-i]) {
level += power_history[POWER_HISTORY_LEN-1-i];
c++;
}
if (power_history[POWER_HISTORY_LEN-1-i] > c)
c = power_history[POWER_HISTORY_LEN-1-i];
if (c)
level = level / c; /* avg */
level = c;
else /* history was empty, get a fresh sample */
level = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
@ -448,6 +446,12 @@ static void power_thread(void)
while (1)
{
/* never read power while disk is spinning, unless in USB mode */
if (ata_disk_is_active() && !usb_inserted()) {
sleep(HZ * 2);
continue;
}
/* Make POWER_AVG measurements and calculate an average of that to
* reduce the effect of backlights/disk spinning/other variation.
*/
@ -777,6 +781,8 @@ void powermgmt_init(void)
/* init history to 0 */
memset(power_history, 0x00, sizeof(power_history));
#if 0
/* initialize the history with a single sample to prevent level
flickering during the first minute of execution */
power_history[POWER_HISTORY_LEN-1] =
@ -797,6 +803,7 @@ void powermgmt_init(void)
/* if the battery is nearly empty, start charging immediately */
if (power_history[POWER_HISTORY_LEN-1] < BATTERY_LEVEL_DANGEROUS)
charger_enable(true);
#endif
#endif
create_thread(power_thread, power_stack, sizeof(power_stack),