summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c19
1 files changed, 13 insertions, 6 deletions
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);