Index: apps/misc.c
===================================================================
RCS file: /cvsroot/rockbox/apps/misc.c,v
retrieving revision 1.55
diff -u -r1.55 misc.c
--- apps/misc.c	21 Feb 2006 01:23:29 -0000	1.55
+++ apps/misc.c	16 Mar 2006 16:10:39 -0000
@@ -491,11 +491,22 @@
     if(!charger_inserted())
 #endif
     {
+        if (!battery_level_safe())
+            gui_syncsplash(3*HZ, true, "%s %s",
+                           str(LANG_WARNING_BATTERY_EMPTY),
+                           str(LANG_SHUTTINGDOWN));
+        else if (battery_level_critical())
+            gui_syncsplash(3*HZ, true, "%s %s",
+                           str(LANG_WARNING_BATTERY_LOW),
+                           str(LANG_SHUTTINGDOWN));
+        else {
         lcd_clear_display();
         gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN));
+        }
         if (callback != NULL)
             callback(parameter);
 
+        if (!battery_level_critical()) /* do not save on critical battery */
         system_flush();
         
         shutdown_hw();
Index: apps/lang/deutsch.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/deutsch.lang,v
retrieving revision 1.92
diff -u -r1.92 deutsch.lang
--- apps/lang/deutsch.lang	6 Dec 2005 13:27:00 -0000	1.92
+++ apps/lang/deutsch.lang	16 Mar 2006 16:10:50 -0000
@@ -3459,3 +3459,15 @@
 eng: "Mode:"
 voice: ""
 new: "Modus:"
+
+id: LANG_WARNING_BATTERY_LOW
+desc: general warning
+eng: "WARNING! Low Battery!"
+voice:
+new: "WARNUNG! Batterie fast leer!"
+
+id: LANG_WARNING_BATTERY_EMPTY
+desc: general warning
+eng: "Battery empty! RECHARGE!"
+voice:
+new: "Batterie ist leer! AUFLADEN!"
Index: apps/lang/english.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/english.lang,v
retrieving revision 1.226
diff -u -r1.226 english.lang
--- apps/lang/english.lang	4 Mar 2006 23:53:09 -0000	1.226
+++ apps/lang/english.lang	16 Mar 2006 16:10:57 -0000
@@ -3796,3 +3796,15 @@
 eng: "Searching... %d found (%s)"
 voice: ""
 new:
+
+id: LANG_WARNING_BATTERY_LOW
+desc: general warning
+eng: "WARNING! Low Battery!"
+voice:
+new:
+
+id: LANG_WARNING_BATTERY_EMPTY
+desc: general warning
+eng: "Battery empty! RECHARGE!"
+voice:
+new:
Index: firmware/powermgmt.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/powermgmt.c,v
retrieving revision 1.104
diff -u -r1.104 powermgmt.c
--- firmware/powermgmt.c	13 Mar 2006 16:11:29 -0000	1.104
+++ firmware/powermgmt.c	16 Mar 2006 16:11:02 -0000
@@ -49,6 +49,9 @@
 #ifdef HAVE_LCD_BITMAP
 #include "font.h"
 #endif
+#if defined(HAVE_RECORDING) && (CONFIG_CODEC == SWCODEC)
+#include "pcm_record.h"
+#endif
 #include "logf.h"
 #include "lcd-remote.h"
 
@@ -93,6 +96,11 @@
     return battery_level() >= 10;
 }
 
+bool battery_level_critical(void)
+{
+    return false;
+}
+
 void set_poweroff_timeout(int timeout)
 {
     (void)timeout;
@@ -107,7 +115,6 @@
 {
 }
 
-
 #else /* not SIMULATOR ******************************************************/
 
 static const int poweroff_idle_timeout_value[15] =
@@ -115,35 +122,45 @@
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
 };
 
-static const unsigned int battery_level_dangerous[BATTERY_TYPES_COUNT] =
+static const short battery_level_dangerous[BATTERY_TYPES_COUNT] =
 {
-#if CONFIG_BATTERY == BATT_LIION2200 /* FM Recorder, LiIon */
+#if CONFIG_BATTERY == BATT_LIION2200   /* FM Recorder: LiIon */
     280
-#elif CONFIG_BATTERY == BATT_3AAA /* Ondio */
-    310, 345    /* alkaline, NiHM */
-#elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver H1x0 */
-    339
-#else /* Player/recorder, NiMH */
+#elif CONFIG_BATTERY == BATT_3AAA      /* Ondio: Alkaline, NiHM */
+    310, 345
+#elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver Hxxx: LiPolymer */
+    338
+#else                                  /* Player/recorder: NiMH */
     475
 #endif
 };
 
+static const short battery_level_shutoff[BATTERY_TYPES_COUNT] =
+{
+#if   CONFIG_BATTERY == BATT_LIION2200 /* FM Recorder */
+    258
+#elif CONFIG_BATTERY == BATT_3AAA      /* Ondio */
+    270, 280
+#elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver Hxxx */
+    299
+#else                                  /* Player/recorder */
+    440
+#endif
+};
+
+/* voltages [centivolt] of 0%, 10%, ... 100% when charging disabled */
 static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
-/* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */
 {
 #if CONFIG_BATTERY == BATT_LIION2200
     /* measured values */
     { 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 }
 #elif CONFIG_BATTERY == BATT_3AAA
     /* measured values */
-    { 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* alkaline */
+    { 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* Alkaline */
     { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 }  /* NiMH */
 #elif CONFIG_BATTERY == BATT_LIPOL1300
     /* Below 337 the backlight starts flickering during HD access */
-    /* Calibrated for Ionity 1900 mAh battery. If necessary, re-calibrate
-     * for the 1300 mAh stock battery. */
-//  { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 }
-    { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 }
+    { 337, 365, 370, 374, 378, 382, 387, 393, 400, 408, 416 }
 #else /* NiMH */
     /* original values were taken directly after charging, but it should show
        100% after turning off the device for some hours, too */
@@ -155,13 +172,12 @@
 #ifdef HAVE_CHARGING
 charger_input_state_type charger_input_state IDATA_ATTR;
 
-/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
+/* voltages [centivolt] of 0%, 10%, ... 100% when charging enabled */
 static const short percent_to_volt_charge[11] =
 {
 #if CONFIG_BATTERY == BATT_LIPOL1300
-    /* Calibrated for 1900 mAh Ionity battery (estimated 90% charge when 
-     entering in trickle-charging). We will never reach 100%. */
-    340, 390, 394, 399, 400, 404, 407, 413, 417, 422, 426
+    /* values measured over one full charging cycle */
+    354, 386, 393, 398, 400, 402, 404, 408, 413, 418, 423 /* LiPo */
 #else
     /* values guessed, see
        http://www.seattlerobotics.org/encoder/200210/LiIon2.pdf until someone
@@ -203,23 +219,30 @@
  * Average battery voltage and charger voltage, filtered via a digital
  * exponential filter.
  */
-static unsigned int battery_centivolts;/* filtered battery voltage, centvolts */
 static unsigned int avgbat;     /* average battery voltage (filtering) */
+static int battery_centivolts;/* filtered battery voltage, centvolts */
+#ifdef HAVE_CHARGE_CTRL
 #define BATT_AVE_SAMPLES	32  /* filter constant / @ 2Hz sample rate */
+#elif CONFIG_BATTERY == BATT_LIPOL1300
+#define BATT_AVE_SAMPLES   128  /* slow filter for iriver */
+#else
+#define BATT_AVE_SAMPLES    64  /* medium filter constant for all others */
+#endif
 
 /* battery level (0-100%) of this minute, updated once per minute */
-static int battery_percent  = -1;
+static int battery_percent;
 static int battery_capacity = BATTERY_CAPACITY_MIN; /* default value, mAH */
 static int battery_type     = 0;
 
 /* Power history: power_history[0] is the newest sample */
 unsigned short power_history[POWER_HISTORY_LEN];
 
-static char power_stack[DEFAULT_STACK_SIZE + DEBUG_STACK];
+static char power_stack[DEFAULT_STACK_SIZE/2 + DEBUG_STACK];
 static const char power_thread_name[] = "power";
 
 static int poweroff_timeout = 0;
-static int powermgmt_est_runningtime_min = -1;
+static int powermgmt_est_runningtime_min;
+static bool low_battery = false;
 
 static bool sleeptimer_active = false;
 static long sleeptimer_endtick;
@@ -229,11 +252,6 @@
 static void battery_status_update(void);
 static int runcurrent(void);
 
-unsigned int battery_voltage(void)
-{
-    return battery_centivolts;
-}
-
 void reset_poweroff_timer(void)
 {
     last_event_tick = current_tick;
@@ -270,10 +288,28 @@
     return battery_percent;
 }
 
+/* Returns filtered battery voltage [centivolts] */
+unsigned int battery_voltage(void)
+{
+    return battery_centivolts;
+}
+
+/* Returns battery voltage from ADC [centivolts] */
+int battery_adc_voltage(void)
+{
+    return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR + 5000) / 10000;
+}
+
 /* Tells if the battery level is safe for disk writes */
 bool battery_level_safe(void)
 {
-    return battery_centivolts > battery_level_dangerous[battery_type];
+    return (battery_centivolts > battery_level_dangerous[battery_type]);
+}
+
+/* Tells if the battery is in critical powersaving state */
+bool battery_level_critical(void)
+{
+    return ((battery_capacity * battery_percent / BATTERY_CAPACITY_MIN) < 10);
 }
 
 void set_poweroff_timeout(int timeout)
@@ -301,8 +337,7 @@
         return 0;
 }
 
-/* look into the percent_to_volt_* table and get a realistic battery level
-       percentage */
+/* look into the percent_to_volt_* table and get a realistic battery level */
 static int voltage_to_percent(int voltage, const short* table)
 {
     if (voltage <= table[0])
@@ -328,7 +363,33 @@
 {
     int level;
 
-#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)
+#if CONFIG_BATTERY == BATT_LIPOL1300
+    if (charger_input_state == NO_CHARGER) {
+        /* discharging. calculate new battery level and average with last */
+        level = voltage_to_percent(battery_centivolts,
+                percent_to_volt_discharge[battery_type]);
+        if (level != (battery_percent - 1))
+            level = (level + battery_percent + 1) / 2;
+    }
+    else if (charger_input_state == CHARGER_UNPLUGGED) {
+        /* just unplugged. adjust filtered values */
+        battery_centivolts -= percent_to_volt_charge[battery_percent/10] -
+                              percent_to_volt_discharge[0][battery_percent/10];
+        avgbat = battery_centivolts * 10000 * BATT_AVE_SAMPLES;
+        level  = battery_percent;
+    }
+    else if (charger_input_state == CHARGER_PLUGGED) {
+        /* just plugged in. adjust battery values */
+        battery_centivolts += percent_to_volt_charge[battery_percent/10] -
+                              percent_to_volt_discharge[0][battery_percent/10];
+        avgbat = battery_centivolts * 10000 * BATT_AVE_SAMPLES;
+        level  = MIN(12 * battery_percent / 10, 99);
+    }
+    else { /* charging. calculate new battery level */
+        level = voltage_to_percent(battery_centivolts,
+                percent_to_volt_charge);
+    }
+#elif defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)
     if (charge_state == DISCHARGING) {
         level = voltage_to_percent(battery_centivolts,
                 percent_to_volt_discharge[battery_type]);
@@ -338,7 +399,7 @@
         level = MIN(voltage_to_percent(battery_centivolts,
                     percent_to_volt_charge), 99);
     }
-    else { /* in topoff/trickle charge, the battery is by definition 100% full */
+    else { /* in topoff/trickle charge, battery is by definition 100% full */
         level = 100;
     }
 #else
@@ -347,35 +408,71 @@
             percent_to_volt_discharge[battery_type]);
 #endif
 
-#ifndef HAVE_MMC  /* this adjustment is only needed for HD based */
-    if (battery_percent == -1) { /* first run of this procedure */
-        /* The battery voltage is usually a little lower directly after
-           turning on, because the disk was used heavily. Raise it by 5. % */
-        level = (level > 95) ? 100 : level + 5;
-    }
-#endif
-    battery_percent = level;
 
     /* calculate estimated remaining running time */
     /* discharging: remaining running time */
     /* charging:    remaining charging time */
-#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)
+#ifdef HAVE_CHARGE_CTRL
     if (charge_state == CHARGING) {
-        powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100
-                                      * 60 / (CURRENT_MAX_CHG - runcurrent());
+        powermgmt_est_runningtime_min = (100 - level) * battery_capacity * 60
+                                      / 100 / (CURRENT_MAX_CHG - runcurrent());
     }
     else
+#elif CONFIG_BATTERY == BATT_LIPOL1300
+    if (charger_inserted()) {
+#ifdef IRIVER_H300_SERIES
+        /* H300_SERIES use CURRENT_MAX_CHG for basic charge time (80%)
+         * plus 110 min top off charge time */
+        powermgmt_est_runningtime_min = ((100-level) * battery_capacity * 80
+                                         /100 / CURRENT_MAX_CHG) + 110;
+#else
+        /* H100_SERIES scaled for 160 min basic charge time (80%) on
+         * 1600 mAh battery plus 110 min top off charge time */
+        powermgmt_est_runningtime_min = ((100 - level) * battery_capacity
+                                         / 993) + 110;
+#endif
+        level = (level * 80) / 100;
+        if (level > 72) { /* > 91% */
+            int i = POWER_HISTORY_LEN;
+            int d = 1;
+#ifdef HAVE_CHARGE_STATE
+            if (charge_state == DISCHARGING)
+                d = -2;
 #endif
+            while ((i > 2) && (d > 0)) /* search zero or neg. delta */
+                d = power_history[0] - power_history[--i];
+            if ((((d == 0) && (i > 6)) || (d == -1)) && (i < 118)) {
+                /* top off charging */
+                level = MIN(80 + (i*19 / 113), 99);  /* show 81% .. 99% */
+                powermgmt_est_runningtime_min = MAX(116 - i, 0);
+            }
+            else if ((d < 0) || (i > 117)) {
+                /* charging finished */
+                level = 100;
+                powermgmt_est_runningtime_min = battery_capacity * 60
+                                                / runcurrent();
+            }
+        }
+    }
+    else
+#endif /* BATT_LIPOL1300 */
     {
-        powermgmt_est_runningtime_min = level * battery_capacity / 100 
-                                      * 60 / runcurrent();
+        if (battery_centivolts > (percent_to_volt_discharge[0][0] - 2))
+            powermgmt_est_runningtime_min = (level + battery_percent) * 60 *
+                                         battery_capacity / 200 / runcurrent();
+        else
+            powermgmt_est_runningtime_min = (battery_centivolts -
+                                             battery_level_shutoff[0]) / 2;
     }
+
+    battery_percent = level;
 }
 
 /*
  * We shut off in the following cases:
  * 1) The unit is idle, not playing music
  * 2) The unit is playing music, but is paused
+ * 3) The battery level has reached shutdown limit
  *
  * We do not shut off in the following cases:
  * 1) The USB is connected
@@ -397,6 +494,38 @@
     }
 #endif
 
+    /* For low battery condition do some power-saving stuff */
+    if (!low_battery && battery_level_critical()) {
+#if CONFIG_BACKLIGHT == BL_IRIVER_H100
+        backlight_set_fade_in(0);
+        backlight_set_fade_out(0);
+#endif
+#ifdef CONFIG_BACKLIGHT
+        if (backlight_get_current_timeout() > 2)
+#endif
+            backlight_set_timeout(2);
+#ifdef HAVE_REMOTE_LCD
+        remote_backlight_set_timeout(2);
+#endif
+        ata_spindown(3);
+#ifdef HAVE_ATA_POWER_OFF
+        ata_poweroff(true);
+#endif
+        low_battery = true;
+    } else if (low_battery && (battery_percent > 11)) {
+        backlight_set_timeout(10);
+        ata_spindown(10);
+        low_battery = false;
+    }
+
+    /* switch off unit if battery level is too low for reliable operation */
+    if(battery_centivolts < battery_level_shutoff[battery_type]) {
+        if(!shutdown_timeout) {
+            backlight_on();
+            sys_poweroff();
+        }
+    }
+
     if(timeout &&
 #ifdef CONFIG_TUNER
        (!radio_powered()) &&
@@ -467,6 +596,30 @@
         current += CURRENT_BACKLIGHT;
 #endif
 
+#if defined(HAVE_RECORDING)
+#if CONFIG_CODEC == SWCODEC        
+    unsigned int audio_stat = pcm_rec_status();
+#else
+    int audio_stat = audio_status();
+#endif
+    if (audio_stat & AUDIO_STATUS_RECORD)
+        current += CURRENT_RECORD;
+#endif
+
+#ifdef HAVE_SPDIF_POWER
+#ifdef SPDIF_POWER_INVERTED
+    if (GPIO1_OUT & 0x01000000)
+#else
+    if (!(GPIO1_OUT & 0x01000000))
+#endif
+        current += CURRENT_SPDIF_OUT;
+#endif
+
+#ifdef HAVE_REMOTE_LCD
+    if ((GPIO_READ & 0x40000000) == 0)
+        current += CURRENT_REMOTE;
+#endif
+
     return(current);
 }
 
@@ -550,7 +703,6 @@
                 }
                 break;
         }
-        
 #endif /* HAVE_CHARGE_STATE */
 
         small_ticks = MIN(HZ/2, ticks);
@@ -575,30 +727,40 @@
          * likely always be spinning in USB mode).
          */
         if (!ata_disk_is_active() || usb_inserted()) {
-            avgbat = avgbat - (avgbat / BATT_AVE_SAMPLES) +
-                     adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR;
+            avgbat += adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR
+                      - (avgbat / BATT_AVE_SAMPLES);
             /*
              * battery_centivolts is the centivolt-scaled filtered battery value.
              */
-            battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
-
-            /* update battery status every time an update is available */
-            battery_status_update();
-
+            battery_centivolts = (avgbat / BATT_AVE_SAMPLES + 5000) / 10000;
         }
+        else if (battery_percent < 8) {
+            /* If battery is low, observe voltage during disk activity.
+             * Shut down if voltage drops below shutoff level.
+             */
+            battery_centivolts = (battery_adc_voltage() +
+                                  battery_centivolts + 1) / 2;
+            if (!shutdown_timeout &&
+                (battery_centivolts < battery_level_shutoff[battery_type]))
+                sys_poweroff();
+            else
+                avgbat += battery_centivolts * 10000
+                          - (avgbat / BATT_AVE_SAMPLES);
+        }
+
 #ifdef HAVE_CHARGE_CTRL
         if (ata_disk_is_active()) {
             /* flag hdd use for charging calculation */
             disk_activity_last_cycle = true;
         }
 #endif
+
 #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
         /*
          * If we have a lot of pending writes or if the disk is spining,
          * fsync the debug log file.
          */
-        if((wrcount > 10) ||
-           ((wrcount > 0) && ata_disk_is_active())) {
+        if((wrcount > 10) || ((wrcount > 0) && ata_disk_is_active())) {
             fsync(fd);
             wrcount = 0;
         }
@@ -632,10 +794,35 @@
 
     /* initialize the voltages for the exponential filter */
 
-    avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * 
-        BATT_AVE_SAMPLES;
+    avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR + 15000;
+
+#ifndef HAVE_MMC  /* this adjustment is only needed for HD based */
+        /* The battery voltage is usually a little lower directly after
+           turning on, because the disk was used heavily. Raise it by 5% */
+#ifdef HAVE_CHARGING
+    if(!charger_inserted()) /* only if charger not connected */
+#endif
+        avgbat += (percent_to_volt_discharge[battery_type][6] -
+                   percent_to_volt_discharge[battery_type][5]) * 5000;
+#endif /* not HAVE_MMC */
+
+    avgbat = avgbat * BATT_AVE_SAMPLES;
     battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
 
+#ifdef HAVE_CHARGING
+    if(charger_inserted()) {
+        battery_percent  = voltage_to_percent(battery_centivolts,
+                           percent_to_volt_charge);
+#if CONFIG_BATTERY == BATT_LIPOL1300
+        charger_input_state = CHARGER;
+#endif
+    } else
+#endif
+    {   battery_percent  = voltage_to_percent(battery_centivolts,
+                           percent_to_volt_discharge[battery_type]);
+        battery_percent += (battery_percent < 100);
+    }
+
 #if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
     fd      = -1;
     wrcount = 0;
@@ -652,6 +839,9 @@
         /* insert new value at the start, in centivolts 8-) */
         power_history[0] = battery_centivolts;
 
+        /* update battery status every minute */
+        battery_status_update();
+
 #if CONFIG_BATTERY == BATT_LIION2200
         /* We use the information from the ADC_EXT_POWER ADC channel, which
            tells us the charging current from the LTC1734. When DC is
@@ -973,6 +1163,17 @@
     /* If the main thread fails to shut down the system, we will force a
        power off after an 8 second timeout */
     shutdown_timeout = HZ*8;
+#if defined(HAVE_RECORDING)
+#if CONFIG_CODEC == SWCODEC        
+    unsigned int audio_stat = pcm_rec_status();
+#else
+    int audio_stat = audio_status();
+#endif
+    if (audio_stat & AUDIO_STATUS_RECORD) {
+        audio_stop_recording();
+        shutdown_timeout += 8*HZ;
+    }
+#endif
     
     queue_post(&button_queue, SYS_POWEROFF, NULL);
 }
@@ -987,25 +1188,32 @@
         fd = -1;
     }
 #endif
+
     audio_stop();
+    if (!battery_level_critical()) { /* do not save on critical battery */
 #ifdef HAVE_LCD_BITMAP
     glyph_cache_save();
 #endif
     ata_flush();
+    }
+    if(ata_disk_is_active())
     ata_spindown(1);
-    while(ata_disk_is_active())
-        sleep(HZ/10);
-
+    backlight_off();
+#ifdef HAVE_REMOTE_LCD
+    remote_backlight_off();
+#endif
     mp3_shutdown();
 #ifdef HAVE_UDA1380
     uda1380_close();
 #elif defined(HAVE_TLV320)
     tlv320_close();
 #endif
-    backlight_off();
+    /* If HD is still active we try to wait for spindown, otherwise the
+       shutdown_timeout in power_thread_sleep will force a power off */ 
+    while(ata_disk_is_active())
+        sleep(HZ/10);
     lcd_set_contrast(0);
 #ifdef HAVE_REMOTE_LCD
-    remote_backlight_off();
     lcd_remote_set_contrast(0);
 #endif
     power_off();
Index: firmware/export/powermgmt.h
===================================================================
RCS file: /cvsroot/rockbox/firmware/export/powermgmt.h,v
retrieving revision 1.29
diff -u -r1.29 powermgmt.h
--- firmware/export/powermgmt.h	4 Mar 2006 09:48:53 -0000	1.29
+++ firmware/export/powermgmt.h	16 Mar 2006 16:11:03 -0000
@@ -113,14 +113,27 @@
 # define CURRENT_NORMAL     95  /* average, nearly proportional to 1/U */
 # define CURRENT_USB         1  /* host powered in USB mode; avoid zero-div */
 # define CURRENT_BACKLIGHT   0  /* no backlight */
+
 #else            /* Values for HD based jukeboxes */
-# ifdef IRIVER_H100_SERIES
-#  define CURRENT_NORMAL    80
-# else
+#ifdef IRIVER_H100_SERIES
+# define CURRENT_NORMAL     80  /* 16h playback on 1300mAh battery */
+# define CURRENT_BACKLIGHT  23  /* from IriverBattery twiki page */
+# define CURRENT_SPDIF_OUT  10  /* optical SPDIF output on */
+#else
 #  define CURRENT_NORMAL    145  /* usual current in mA when using the AJB including some disk/backlight/... activity */
-# endif /* not IRIVER_H100_SERIES */
-# define CURRENT_USB       500  /* usual current in mA in USB mode */
-# define CURRENT_BACKLIGHT  30  /* additional current when backlight is always on */
+# define CURRENT_BACKLIGHT  30  /* additional current when backlight always on */
+#endif /* not IRIVER_H100_SERIES */
+#define CURRENT_USB        500  /* usual current in mA in USB mode */
+#ifdef IRIVER_H100_SERIES
+# define CURRENT_RECORD    105  /* additional current while recording */
+#elif defined(IRIVER_H300_SERIES)
+# define CURRENT_RECORD    110
+#elif defined(HAVE_RECORDING)
+# define CURRENT_RECORD     35  /* FIXME: this needs adjusting */
+#endif
+#ifdef HAVE_REMOTE_LCD
+# define CURRENT_REMOTE      8  /* add. current when H100-remote connected */
+#endif
 
 # define CURRENT_MIN_CHG    70  /* minimum charge current */
 # define MIN_CHG_V        8500  /* at 8.5v charger voltage get CURRENT_MIN_CHG */
@@ -132,7 +145,6 @@
 # define MAX_CHG_V       10250  /* anything over 10.25v gives CURRENT_MAX_CHG */
 #endif /* not HAVE_MMC */
 
-extern unsigned int bat;       /* filtered battery voltage, centivolts */
 extern unsigned short power_history[POWER_HISTORY_LEN];
 
 /* Start up power management thread */
@@ -140,14 +152,16 @@
 
 #endif /* SIMULATOR */
 
-/* Returns battery level in percent */
-int battery_level(void);
+/* Returns battery status */
+int battery_level(void); /* percent */
 int battery_time(void); /* minutes */
-
+int battery_adc_voltage(void); /* voltage from ADC in centivolts */
 unsigned int battery_voltage(void); /* filtered batt. voltage in centivolts */
 
 /* Tells if the battery level is safe for disk writes */
 bool battery_level_safe(void);
+/* Tells if battery is in critical power saving state */
+bool battery_level_critical(void);
 
 void set_poweroff_timeout(int timeout);
 void set_battery_capacity(int capacity); /* set local battery capacity value */
