summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/debug_menu.c130
-rw-r--r--apps/main.c3
-rw-r--r--apps/settings.c15
-rw-r--r--apps/settings.h1
-rw-r--r--apps/settings_menu.c14
5 files changed, 156 insertions, 7 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 1c1a8170d7..d4d08bc673 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -33,6 +33,8 @@
#include "rtc.h"
#include "debug.h"
#include "thread.h"
+#include "powermgmt.h"
+#include "system.h"
/*---------------------------------------------------*/
/* SPECIAL DEBUG STUFF */
@@ -154,7 +156,7 @@ void dbg_ports(void)
snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
lcd_puts(0, 5, buf);
- battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000;
+ battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
batt_int = battery_voltage / 100;
batt_frac = battery_voltage % 100;
@@ -255,7 +257,7 @@ void dbg_ports(void)
}
lcd_puts(0, 0, buf);
- battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000;
+ battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
batt_int = battery_voltage / 100;
batt_frac = battery_voltage % 100;
@@ -426,6 +428,129 @@ void dbg_mas_codec(void)
}
}
}
+
+/*
+ * view_battery() shows a automatically scaled graph of the battery voltage
+ * over time. Usable for estimating battery life / charging rate.
+ * The power_history array is updated in power_thread of powermgmt.c.
+ */
+
+#define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
+#define BAT_YSPACE (LCD_HEIGHT - 20)
+
+void view_battery(void)
+{
+ int view = 0;
+ int i, x, y;
+ int maxv, minv;
+ char buf[32];
+
+ while(1)
+ {
+ switch (view) {
+ case 0: /* voltage history graph */
+ /* Find maximum and minimum voltage for scaling */
+ maxv = minv = 0;
+ for (i = BAT_FIRST_VAL; i < POWER_HISTORY_LEN; i++) {
+ if (power_history[i] > maxv)
+ maxv = power_history[i];
+ if ((minv == 0) || ((power_history[i]) && (power_history[i] < minv)) )
+ minv = power_history[i];
+ }
+
+ if (minv < 1)
+ minv = 1;
+ if (maxv < 2)
+ maxv = 2;
+
+ lcd_clear_display();
+ lcd_puts(0, 0, "Battery voltage:");
+ snprintf(buf, 30, "scale %d.%02d-%d.%02d V", minv / 100, minv % 100, maxv / 100, maxv % 100);
+ lcd_puts(0, 1, buf);
+
+ x = 0;
+ for (i = BAT_FIRST_VAL+1; i < POWER_HISTORY_LEN; i++) {
+ y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
+ lcd_clearline(x, LCD_HEIGHT-1, x, 20);
+ lcd_drawline(x, LCD_HEIGHT-1, x, MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
+ x++;
+ }
+
+ break;
+
+ case 1: /* status: */
+ lcd_clear_display();
+ lcd_puts(0, 0, "Power status:");
+
+ y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
+ snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
+ lcd_puts(0, 1, buf);
+ y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
+ snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
+ lcd_puts(0, 2, buf);
+ snprintf(buf, 30, "Charger: %s", charger_inserted() ? "present" : "absent");
+ lcd_puts(0, 3, buf);
+#ifdef HAVE_CHARGE_CTRL
+ snprintf(buf, 30, "Charging: %s", charger_enabled ? "yes" : "no");
+ lcd_puts(0, 4, buf);
+#endif
+ y = 0;
+ for (i = 0; i < CHARGE_END_NEGD; i++)
+ y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100;
+ y = y / CHARGE_END_NEGD;
+
+ snprintf(buf, 30, "short delta: %d", y);
+ lcd_puts(0, 5, buf);
+
+ y = 0;
+ for (i = 0; i < CHARGE_END_ZEROD; i++)
+ y += power_history[POWER_HISTORY_LEN-1-i]*100 - power_history[POWER_HISTORY_LEN-1-i-1]*100;
+ y = y / CHARGE_END_ZEROD;
+
+ snprintf(buf, 30, "long delta: %d", y);
+ lcd_puts(0, 6, buf);
+
+#ifdef HAVE_CHARGE_CTRL
+ lcd_puts(0, 7, power_message);
+#endif
+ break;
+
+ case 2: /* voltage deltas: */
+ lcd_clear_display();
+ lcd_puts(0, 0, "Voltage deltas:");
+
+ for (i = 0; i <= 6; i++) {
+ y = power_history[POWER_HISTORY_LEN-1-i] - power_history[POWER_HISTORY_LEN-1-i-1];
+ snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
+ (y < 0) ? "-" : "",
+ ((y < 0) ? y * -1 : y) / 100, ((y < 0) ? y * -1 : y ) % 100);
+ lcd_puts(0, i+1, buf);
+ }
+ break;
+ }
+
+ lcd_update();
+ sleep(HZ/2);
+
+ switch(button_get(false))
+ {
+ case BUTTON_UP:
+ if (view)
+ view--;
+ break;
+
+ case BUTTON_DOWN:
+ if (view < 2)
+ view++;
+ break;
+
+ case BUTTON_LEFT:
+ case BUTTON_OFF:
+ return;
+ }
+ }
+}
+
#endif
void debug_menu(void)
@@ -443,6 +568,7 @@ void debug_menu(void)
{ "View MAS regs", dbg_mas },
#ifdef ARCHOS_RECORDER
{ "View MAS codec", dbg_mas_codec },
+ { "View battery", view_battery },
#endif
};
diff --git a/apps/main.c b/apps/main.c
index 83ccd7586f..df7d7c128f 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -30,6 +30,7 @@
#include "menu.h"
#include "system.h"
#include "usb.h"
+#include "powermgmt.h"
#include "adc.h"
#include "i2c.h"
#ifndef SIMULATOR
@@ -157,6 +158,8 @@ void init(void)
status_init();
usb_start_monitoring();
+
+ power_init();
}
int main(void)
diff --git a/apps/settings.c b/apps/settings.c
index 7f1c1af34d..4160721e8a 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -32,6 +32,7 @@
#include "ata.h"
#include "power.h"
#include "backlight.h"
+#include "powermgmt.h"
struct user_settings global_settings;
@@ -57,12 +58,12 @@ offset abs
0x0f 0x23 <scroll speed & WPS display byte>
0x10 0x24 <playlist options byte>
0x11 0x25 <AVC byte>
-
+
<all unused space filled with 0xff>
the geeky but useless statistics part:
0x24 <total uptime in seconds: 32 bits uint, actually unused for now>
-
+
0x2a <checksum 2 bytes: xor of 0x0-0x29>
Config memory is reset to 0xff and initialized with 'factory defaults' if
@@ -265,7 +266,8 @@ int settings_save( void )
rtc_config_block[0xe] = (unsigned char)
((global_settings.playlist_shuffle & 1) |
((global_settings.mp3filter & 1) << 1) |
- ((global_settings.sort_case & 1) << 2));
+ ((global_settings.sort_case & 1) << 2) |
+ ((global_settings.discharge & 1) << 3));
rtc_config_block[0xf] = (unsigned char)
((global_settings.scroll_speed << 3) |
@@ -332,8 +334,9 @@ void settings_load(void)
global_settings.playlist_shuffle = rtc_config_block[0xe] & 1;
global_settings.mp3filter = (rtc_config_block[0xe] >> 1) & 1;
global_settings.sort_case = (rtc_config_block[0xe] >> 2) & 1;
+ global_settings.discharge = (rtc_config_block[0xe] >> 3) & 1;
}
-
+
c = rtc_config_block[0xf] >> 3;
if (c != 31)
global_settings.scroll_speed = c;
@@ -350,6 +353,9 @@ void settings_load(void)
}
lcd_scroll_speed(global_settings.scroll_speed);
backlight_time(global_settings.backlight);
+#ifdef HAVE_CHARGE_CTRL
+ charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
+#endif
}
/*
@@ -373,6 +379,7 @@ void settings_reset(void) {
global_settings.mp3filter = true;
global_settings.sort_case = false;
global_settings.playlist_shuffle = false;
+ global_settings.discharge = 0;
global_settings.total_uptime = 0;
global_settings.scroll_speed = 8;
}
diff --git a/apps/settings.h b/apps/settings.h
index ba6f32c37a..b39ac73c89 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -45,6 +45,7 @@ struct user_settings
int contrast; /* lcd contrast: 0-100 0=low 100=high */
int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */
int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
+ bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
/* resume settings */
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 5c718869d9..4547966f38 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -32,6 +32,7 @@
#include "settings_menu.h"
#include "backlight.h"
#include "playlist.h" /* for playlist_shuffle */
+#include "powermgmt.h"
static void shuffle(void)
{
@@ -67,6 +68,14 @@ static void wps_set(void)
set_option("[WPS display]", &global_settings.wps_display, names, 3 );
}
+#ifdef HAVE_CHARGE_CTRL
+static void deep_discharge(void)
+{
+ set_bool( "[Deep discharge]", &global_settings.discharge );
+ charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
+}
+#endif
+
void settings_menu(void)
{
int m;
@@ -76,7 +85,10 @@ void settings_menu(void)
{ "Sort mode", sort_case },
{ "Backlight Timer", backlight_timer },
{ "Scroll speed", scroll_speed },
- { "While Playing", wps_set },
+ { "While Playing", wps_set },
+#ifdef HAVE_CHARGE_CTRL
+ { "Deep discharge", deep_discharge },
+#endif
};
bool old_shuffle = global_settings.playlist_shuffle;