summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2003-11-19 14:14:41 +0000
committerBjörn Stenberg <bjorn@haxx.se>2003-11-19 14:14:41 +0000
commitf6b6db4167e0b133420138fb9ef94fdfa2e32a08 (patch)
treed2b99b7cb275a400bab0ae3b5d7a69bb35ed63d3
parentdb4bee4308ba88fdc0a3aa6b570c7782419a4b8d (diff)
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
-rw-r--r--apps/status.c4
-rw-r--r--apps/wps-display.c10
-rw-r--r--firmware/powermgmt.c19
3 files changed, 23 insertions, 10 deletions
diff --git a/apps/status.c b/apps/status.c
index c6f4e4944c..7e9233a63f 100644
--- a/apps/status.c
+++ b/apps/status.c
@@ -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);
diff --git a/apps/wps-display.c b/apps/wps-display.c
index c6621b1e62..563bb265be 100644
--- a/apps/wps-display.c
+++ b/apps/wps-display.c
@@ -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;
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index cca44e01bd..80b6a80b2b 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -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] =
@@ -798,6 +804,7 @@ void powermgmt_init(void)
if (power_history[POWER_HISTORY_LEN-1] < BATTERY_LEVEL_DANGEROUS)
charger_enable(true);
#endif
+#endif
create_thread(power_thread, power_stack, sizeof(power_stack),
power_thread_name);