forked from len0rd/rockbox
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
This commit is contained in:
parent
7249c8807c
commit
ae22de285e
3 changed files with 113 additions and 2 deletions
|
@ -38,6 +38,7 @@
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "disk.h"
|
#include "disk.h"
|
||||||
#include "mpeg.h"
|
#include "mpeg.h"
|
||||||
|
#include "settings.h"
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
#include "widgets.h"
|
#include "widgets.h"
|
||||||
#include "peakmeter.h"
|
#include "peakmeter.h"
|
||||||
|
@ -1005,6 +1006,80 @@ bool dbg_mas_info(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
bool debug_menu(void)
|
||||||
{
|
{
|
||||||
int m;
|
int m;
|
||||||
|
@ -1036,6 +1111,7 @@ bool debug_menu(void)
|
||||||
{ "pm histogram", peak_meter_histogram},
|
{ "pm histogram", peak_meter_histogram},
|
||||||
#endif /* PM_DEBUG */
|
#endif /* PM_DEBUG */
|
||||||
#endif /* HAVE_LCD_BITMAP */
|
#endif /* HAVE_LCD_BITMAP */
|
||||||
|
{ "View runtime", view_runtime },
|
||||||
};
|
};
|
||||||
|
|
||||||
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
|
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "wps-display.h"
|
#include "wps-display.h"
|
||||||
|
#include "powermgmt.h"
|
||||||
|
|
||||||
struct user_settings global_settings;
|
struct user_settings global_settings;
|
||||||
char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */
|
char rockboxdir[] = ROCKBOX_DIR; /* config/font/data file directory */
|
||||||
|
@ -105,8 +106,10 @@ offset abs
|
||||||
0x23 0x37 <rec. left gain (bit 0-3)>
|
0x23 0x37 <rec. left gain (bit 0-3)>
|
||||||
0x24 0x38 <rec. right gain (bit 0-3)>
|
0x24 0x38 <rec. right gain (bit 0-3)>
|
||||||
0x25 0x39 <disk_spindown flag>
|
0x25 0x39 <disk_spindown flag>
|
||||||
|
0x26 0x40 <runtime low byte>
|
||||||
<all unused space filled with 0xff>
|
0x27 0x41 <runtime high byte>
|
||||||
|
0x28 0x42 <topruntime low byte>
|
||||||
|
0x29 0x43 <topruntime high byte>
|
||||||
|
|
||||||
0x2a <checksum 2 bytes: xor of 0x0-0x29>
|
0x2a <checksum 2 bytes: xor of 0x0-0x29>
|
||||||
|
|
||||||
|
@ -343,6 +346,26 @@ int settings_save( void )
|
||||||
config_block[0x24] = (unsigned char)global_settings.rec_right_gain;
|
config_block[0x24] = (unsigned char)global_settings.rec_right_gain;
|
||||||
config_block[0x25] = (unsigned char)global_settings.disk_poweroff & 1;
|
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[0xb8], global_settings.wps_file, MAX_FILENAME);
|
||||||
strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME);
|
strncpy(&config_block[0xcc], global_settings.lang_file, MAX_FILENAME);
|
||||||
strncpy(&config_block[0xe0], global_settings.font_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)
|
if (config_block[0x25] != 0xFF)
|
||||||
global_settings.disk_poweroff = config_block[0x25] & 1;
|
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_first_index, &config_block[0xF4], 4);
|
||||||
memcpy(&global_settings.resume_seed, &config_block[0xF8], 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.wps_file[0] = 0;
|
||||||
global_settings.font_file[0] = 0;
|
global_settings.font_file[0] = 0;
|
||||||
global_settings.lang_file[0] = 0;
|
global_settings.lang_file[0] = 0;
|
||||||
|
global_settings.runtime = 0;
|
||||||
|
global_settings.topruntime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,8 @@ struct user_settings
|
||||||
bool browse_current; /* 1=goto current song,
|
bool browse_current; /* 1=goto current song,
|
||||||
0=goto previous location */
|
0=goto previous location */
|
||||||
|
|
||||||
|
int runtime; /* current runtime since last charge */
|
||||||
|
int topruntime; /* top known runtime */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue