summaryrefslogtreecommitdiff
path: root/apps/debug_menu.c
diff options
context:
space:
mode:
authorHeikki Hannikainen <hessuh@rockbox.org>2002-08-06 10:52:51 +0000
committerHeikki Hannikainen <hessuh@rockbox.org>2002-08-06 10:52:51 +0000
commit6eb4254dfa78677a1e336d0f820d5b7fe05eba14 (patch)
treec7fdd02800453984c42323914ddf55ac36ade4a2 /apps/debug_menu.c
parent3f809e716dea26d77bf2cd8e70c3d709c3c25169 (diff)
Added battery charger for the recorder and a power management debugger.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/debug_menu.c')
-rw-r--r--apps/debug_menu.c130
1 files changed, 128 insertions, 2 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
};