···478478 return buf;
479479480480 case 't': /* estimated battery time */
481481- snprintf(buf, buf_size, "%dh %dm",
482482- battery_time() / 60,
483483- battery_time() % 60);
481481+ {
482482+ int t = battery_time();
483483+ if (t >= 0)
484484+ snprintf(buf, buf_size, "%dh %dm", t / 60, t % 60);
485485+ else
486486+ strncpy(buf, "?h ?m", buf_size);
484487 return buf;
488488+ }
485489 }
486490 break;
487491
+13-6
firmware/powermgmt.c
···184184 int c = 0;
185185 int i;
186186187187- /* calculate average over last 3 minutes (skip empty samples) */
187187+ /* calculate maximum over last 3 minutes (skip empty samples) */
188188 for (i = 0; i < 3; i++)
189189- if (power_history[POWER_HISTORY_LEN-1-i]) {
190190- level += power_history[POWER_HISTORY_LEN-1-i];
191191- c++;
192192- }
189189+ if (power_history[POWER_HISTORY_LEN-1-i] > c)
190190+ c = power_history[POWER_HISTORY_LEN-1-i];
193191194192 if (c)
195195- level = level / c; /* avg */
193193+ level = c;
196194 else /* history was empty, get a fresh sample */
197195 level = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
198196···448446449447 while (1)
450448 {
449449+ /* never read power while disk is spinning, unless in USB mode */
450450+ if (ata_disk_is_active() && !usb_inserted()) {
451451+ sleep(HZ * 2);
452452+ continue;
453453+ }
454454+451455 /* Make POWER_AVG measurements and calculate an average of that to
452456 * reduce the effect of backlights/disk spinning/other variation.
453457 */
···777781778782 /* init history to 0 */
779783 memset(power_history, 0x00, sizeof(power_history));
784784+785785+#if 0
780786 /* initialize the history with a single sample to prevent level
781787 flickering during the first minute of execution */
782788 power_history[POWER_HISTORY_LEN-1] =
···797803 /* if the battery is nearly empty, start charging immediately */
798804 if (power_history[POWER_HISTORY_LEN-1] < BATTERY_LEVEL_DANGEROUS)
799805 charger_enable(true);
806806+#endif
800807#endif
801808802809 create_thread(power_thread, power_stack, sizeof(power_stack),