diff options
-rw-r--r-- | apps/status.c | 4 | ||||
-rw-r--r-- | apps/wps-display.c | 10 | ||||
-rw-r--r-- | firmware/powermgmt.c | 19 |
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) | |||
175 | } | 175 | } |
176 | 176 | ||
177 | #ifdef HAVE_LCD_BITMAP | 177 | #ifdef HAVE_LCD_BITMAP |
178 | if (battery_state) | 178 | if (battery_state && (info.battlevel > -1)) |
179 | statusbar_icon_battery(info.battlevel, plug_state); | 179 | statusbar_icon_battery(info.battlevel, plug_state); |
180 | |||
180 | statusbar_icon_volume(info.volume); | 181 | statusbar_icon_volume(info.volume); |
181 | statusbar_icon_play_state(current_mode + Icon_Play); | 182 | statusbar_icon_play_state(current_mode + Icon_Play); |
182 | switch (info.repeat) { | 183 | switch (info.repeat) { |
@@ -202,6 +203,7 @@ void status_draw(bool force_redraw) | |||
202 | 203 | ||
203 | 204 | ||
204 | #if defined(HAVE_LCD_CHARCELLS) | 205 | #if defined(HAVE_LCD_CHARCELLS) |
206 | if (info.battlevel > -1) | ||
205 | lcd_icon(ICON_BATTERY, battery_state); | 207 | lcd_icon(ICON_BATTERY, battery_state); |
206 | lcd_icon(ICON_BATTERY_1, info.battlevel > 25); | 208 | lcd_icon(ICON_BATTERY_1, info.battlevel > 25); |
207 | lcd_icon(ICON_BATTERY_2, info.battlevel > 50); | 209 | 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, | |||
478 | return buf; | 478 | return buf; |
479 | 479 | ||
480 | case 't': /* estimated battery time */ | 480 | case 't': /* estimated battery time */ |
481 | snprintf(buf, buf_size, "%dh %dm", | 481 | { |
482 | battery_time() / 60, | 482 | int t = battery_time(); |
483 | battery_time() % 60); | 483 | if (t >= 0) |
484 | snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60); | ||
485 | else | ||
486 | strncpy(buf, "?h ?m", buf_size); | ||
484 | return buf; | 487 | return buf; |
488 | } | ||
485 | } | 489 | } |
486 | break; | 490 | break; |
487 | 491 | ||
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) | |||
184 | int c = 0; | 184 | int c = 0; |
185 | int i; | 185 | int i; |
186 | 186 | ||
187 | /* calculate average over last 3 minutes (skip empty samples) */ | 187 | /* calculate maximum over last 3 minutes (skip empty samples) */ |
188 | for (i = 0; i < 3; i++) | 188 | for (i = 0; i < 3; i++) |
189 | if (power_history[POWER_HISTORY_LEN-1-i]) { | 189 | if (power_history[POWER_HISTORY_LEN-1-i] > c) |
190 | level += power_history[POWER_HISTORY_LEN-1-i]; | 190 | c = power_history[POWER_HISTORY_LEN-1-i]; |
191 | c++; | ||
192 | } | ||
193 | 191 | ||
194 | if (c) | 192 | if (c) |
195 | level = level / c; /* avg */ | 193 | level = c; |
196 | else /* history was empty, get a fresh sample */ | 194 | else /* history was empty, get a fresh sample */ |
197 | level = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | 195 | level = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; |
198 | 196 | ||
@@ -448,6 +446,12 @@ static void power_thread(void) | |||
448 | 446 | ||
449 | while (1) | 447 | while (1) |
450 | { | 448 | { |
449 | /* never read power while disk is spinning, unless in USB mode */ | ||
450 | if (ata_disk_is_active() && !usb_inserted()) { | ||
451 | sleep(HZ * 2); | ||
452 | continue; | ||
453 | } | ||
454 | |||
451 | /* Make POWER_AVG measurements and calculate an average of that to | 455 | /* Make POWER_AVG measurements and calculate an average of that to |
452 | * reduce the effect of backlights/disk spinning/other variation. | 456 | * reduce the effect of backlights/disk spinning/other variation. |
453 | */ | 457 | */ |
@@ -777,6 +781,8 @@ void powermgmt_init(void) | |||
777 | 781 | ||
778 | /* init history to 0 */ | 782 | /* init history to 0 */ |
779 | memset(power_history, 0x00, sizeof(power_history)); | 783 | memset(power_history, 0x00, sizeof(power_history)); |
784 | |||
785 | #if 0 | ||
780 | /* initialize the history with a single sample to prevent level | 786 | /* initialize the history with a single sample to prevent level |
781 | flickering during the first minute of execution */ | 787 | flickering during the first minute of execution */ |
782 | power_history[POWER_HISTORY_LEN-1] = | 788 | power_history[POWER_HISTORY_LEN-1] = |
@@ -798,6 +804,7 @@ void powermgmt_init(void) | |||
798 | if (power_history[POWER_HISTORY_LEN-1] < BATTERY_LEVEL_DANGEROUS) | 804 | if (power_history[POWER_HISTORY_LEN-1] < BATTERY_LEVEL_DANGEROUS) |
799 | charger_enable(true); | 805 | charger_enable(true); |
800 | #endif | 806 | #endif |
807 | #endif | ||
801 | 808 | ||
802 | create_thread(power_thread, power_stack, sizeof(power_stack), | 809 | create_thread(power_thread, power_stack, sizeof(power_stack), |
803 | power_thread_name); | 810 | power_thread_name); |