From ae22de285e027b81068e6d408077878add2e40f1 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 2 Dec 2002 16:07:56 +0000 Subject: Added two simple battery runtime meters (current + top). 'Current' resets automatically when the charger cable is connected, or manually by pressing PLAY in the viewer. We are now officially out of RTC space. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2897 a1c6a512-1295-4272-9138-f99709370657 --- apps/debug_menu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ apps/settings.c | 37 +++++++++++++++++++++++++-- apps/settings.h | 2 ++ 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 4dd98e0498..ae660d49c5 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -38,6 +38,7 @@ #include "font.h" #include "disk.h" #include "mpeg.h" +#include "settings.h" #ifdef HAVE_LCD_BITMAP #include "widgets.h" #include "peakmeter.h" @@ -1005,6 +1006,80 @@ bool dbg_mas_info(void) } #endif +static bool view_runtime(void) +{ + char s[32]; + bool done = false; + int state = 1; + + while(!done) + { + int y=0; + int t; + int key; + lcd_clear_display(); +#ifdef HAVE_LCD_BITMAP + lcd_puts(0, y++, "Running time:"); + y++; +#endif + + if (state & 1) { + t = global_settings.runtime; + lcd_puts(0, y++, "Current time"); + } + else { + t = global_settings.topruntime; + lcd_puts(0, y++, "Top time"); + } + + snprintf(s, sizeof(s), "%dh %dm %ds", + t / 3600, (t % 3600) / 60, t % 60); + lcd_puts(0, y++, s); + lcd_update(); + + /* Wait for a key to be pushed */ + key = button_get_w_tmo(HZ*5); + switch(key) { +#ifdef HAVE_PLAYER_KEYPAD + case BUTTON_STOP | BUTTON_REL: +#else + case BUTTON_OFF | BUTTON_REL: +#endif + done = true; + break; + + case BUTTON_LEFT: + case BUTTON_RIGHT: + if (state == 1) + state = 2; + else + state = 1; + break; + + case BUTTON_PLAY: + lcd_clear_display(); + lcd_puts(0,0,"Clear time?"); + lcd_puts(0,1,"PLAY = Yes"); + lcd_update(); + while (1) { + key = button_get_w_tmo(HZ*10); + if ( key & BUTTON_REL ) + continue; + if ( key == BUTTON_PLAY ) { + if ( state == 1 ) + global_settings.runtime = 0; + else + global_settings.topruntime = 0; + } + break; + } + break; + } + } + + return false; +} + bool debug_menu(void) { int m; @@ -1036,6 +1111,7 @@ bool debug_menu(void) { "pm histogram", peak_meter_histogram}, #endif /* PM_DEBUG */ #endif /* HAVE_LCD_BITMAP */ + { "View runtime", view_runtime }, }; m=menu_init( items, sizeof items / sizeof(struct menu_items) ); diff --git a/apps/settings.c b/apps/settings.c index ead61d88f8..3bfbd9670f 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -51,6 +51,7 @@ #include "lang.h" #include "language.h" #include "wps-display.h" +#include "powermgmt.h" struct user_settings global_settings; char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */ @@ -105,8 +106,10 @@ offset abs 0x23 0x37 0x24 0x38 0x25 0x39 - - +0x26 0x40 +0x27 0x41 +0x28 0x42 +0x29 0x43 0x2a @@ -343,6 +346,26 @@ int settings_save( void ) config_block[0x24] = (unsigned char)global_settings.rec_right_gain; config_block[0x25] = (unsigned char)global_settings.disk_poweroff & 1; + { + static long lasttime = 0; + + /* reset counter if charger is inserted */ + if ( charger_inserted() ) { + global_settings.runtime = 0; + } + else { + global_settings.runtime += (current_tick - lasttime) / HZ; + lasttime = current_tick; + } + if ( global_settings.runtime > global_settings.topruntime ) + global_settings.topruntime = global_settings.runtime; + + config_block[0x26]=(unsigned char)(global_settings.runtime & 0xff); + config_block[0x27]=(unsigned char)(global_settings.runtime >> 8); + config_block[0x28]=(unsigned char)(global_settings.topruntime & 0xff); + config_block[0x29]=(unsigned char)(global_settings.topruntime >> 8); + } + strncpy(&config_block[0xb8], global_settings.wps_file, MAX_FILENAME); strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME); strncpy(&config_block[0xe0], global_settings.font_file, MAX_FILENAME); @@ -602,6 +625,14 @@ void settings_load(void) if (config_block[0x25] != 0xFF) global_settings.disk_poweroff = config_block[0x25] & 1; + if (config_block[0x27] != 0xff) + global_settings.runtime = + config_block[0x26] | (config_block[0x27] << 8); + + if (config_block[0x29] != 0xff) + global_settings.topruntime = + config_block[0x28] | (config_block[0x29] << 8); + memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4); memcpy(&global_settings.resume_seed, &config_block[0xF8], 4); @@ -805,6 +836,8 @@ void settings_reset(void) { global_settings.wps_file[0] = 0; global_settings.font_file[0] = 0; global_settings.lang_file[0] = 0; + global_settings.runtime = 0; + global_settings.topruntime = 0; } diff --git a/apps/settings.h b/apps/settings.h index 8399874016..6d3678f44c 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -131,6 +131,8 @@ struct user_settings bool browse_current; /* 1=goto current song, 0=goto previous location */ + int runtime; /* current runtime since last charge */ + int topruntime; /* top known runtime */ }; /* prototypes */ -- cgit v1.2.3