1
0
Fork 0
forked from len0rd/rockbox

FS#13538 export and import battery level tables

when battery_bench is run
exports a file in the rockbox directory called 'battery_levels.default'

if the user wants their own levels they can rename the file battery_levels.cfg
and it will be loaded at boot

some minimal error checking is performed prior to using the values

added manual entry

Change-Id: Ia0126faced0c7229fcf8385a1bcb584b5a9dc378
This commit is contained in:
William Wilgus 2025-01-11 18:54:53 -05:00 committed by William Wilgus
parent 3539dd5a70
commit 10f8312db4
79 changed files with 611 additions and 298 deletions

View file

@ -913,10 +913,11 @@ static bool tsc2100_debug(void)
static bool view_battery(void)
{
extern struct battery_tables_t device_battery_tables; /* powermgmt.c */
unsigned short *power_history = device_battery_tables.history;
int view = 0;
int i, x, y, z, y1, y2, grid, graph;
unsigned short maxv, minv;
lcd_setfont(FONT_SYSFIXED);
while(1)

View file

@ -437,6 +437,7 @@ static void init(void)
settings_reset();
settings_load();
settings_apply(true);
init_battery_tables();
#ifdef HAVE_DIRCACHE
init_dircache(true);
init_dircache(false);
@ -701,7 +702,9 @@ static void init(void)
settings_reset();
}
#endif
CHART(">init_battery_tables");
init_battery_tables();
CHART("<init_battery_tables");
#ifdef HAVE_DIRCACHE
CHART(">init_dircache(true)");
rc = init_dircache(true);

View file

@ -86,6 +86,8 @@ static void* plugin_get_audio_buffer(size_t *buffer_size);
static void plugin_release_audio_buffer(void);
static void plugin_tsr(int (*exit_callback)(bool));
extern struct battery_tables_t device_battery_tables; /* powermgmt.c */
#ifdef HAVE_PLUGIN_CHECK_OPEN_CLOSE
/* File handle leak prophylaxis */
#include "bitarray.h"
@ -842,6 +844,7 @@ static const struct plugin_api rockbox_api = {
/* new stuff at the end, sort into place next time
the API gets incompatible */
add_playbacklog,
&device_battery_tables,
};
static int plugin_buffer_handle;

View file

@ -991,6 +991,7 @@ struct plugin_api {
/* new stuff at the end, sort into place next time
the API gets incompatible */
void (*add_playbacklog)(struct mp3entry *id3);
struct battery_tables_t *device_battery_tables;
};
/* plugin header */

View file

@ -24,6 +24,22 @@
#include "plugin.h"
#include "lang_enum.h"
/* matches struct in powermgmt.h */
struct battery_tables_t {
unsigned short * const history;
unsigned short * const disksafe;
unsigned short * const shutoff;
unsigned short * const discharge;
#if CONFIG_CHARGING
unsigned short * const charge;
const size_t elems;
bool isdefault;
#endif
};
#define BATTERY_LEVELS_DEFAULT ROCKBOX_DIR"/battery_levels.default"
#define BATTERY_LEVELS_USER ROCKBOX_DIR"/battery_levels.cfg"
#define BATTERY_LOG HOME_DIR "/battery_bench.txt"
#define BUF_SIZE 16000
@ -265,7 +281,7 @@
#endif
/****************************** Plugin Entry Point ****************************/
static long start_tick;
long start_tick;
/* Struct for battery information */
static struct batt_info
@ -507,6 +523,66 @@ static void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, in
putsxy((lcd_width - strwdt)/2, line*(strhgt), str);
}
void do_export_battery_tables(void)
{
size_t elems = rb->device_battery_tables->elems;
if (!rb->device_battery_tables->isdefault)
return; /* no need to print out non-defaults */
unsigned int i;
int fd;
/* write out the default battery levels file */
if (!rb->file_exists(BATTERY_LEVELS_DEFAULT))
{
fd = rb->open(BATTERY_LEVELS_DEFAULT, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd >= 0)
{
rb->fdprintf(fd, "# Rename to %s\n# " MODEL_NAME " Battery Levels (%s)\n\n",
BATTERY_LEVELS_USER, rb->rbversion);
rb->fdprintf(fd, "# Battery voltage(millivolt) lower than this %s\n",
"player will shutdown");
rb->fdprintf(fd, "shutoff: %d\n\n", *rb->device_battery_tables->shutoff);
rb->fdprintf(fd, "# Battery voltage(millivolt) lower than this %s\n",
"won't access the disk to write");
rb->fdprintf(fd, "disksafe: %d\n\n", *rb->device_battery_tables->disksafe);
rb->fdprintf(fd, "# Battery voltage(millivolt) of {");
for(i= 0;i < elems;i++)
{
rb->fdprintf(fd, "%u%%, ", i * 10);
}
rb->lseek(fd, -2, SEEK_CUR); /*remove last comma */
rb->fdprintf(fd, "} when charging %sabled\n", "dis");
rb->fdprintf(fd, "discharge: {");
for(i= 0;i < elems;i++)
{
rb->fdprintf(fd, "%u, ", rb->device_battery_tables->discharge[i]);
}
rb->lseek(fd, -2, SEEK_CUR); /*remove last comma */
rb->fdprintf(fd, "}\n\n");
#if CONFIG_CHARGING
rb->fdprintf(fd, "# Battery voltage(millivolt) of {");
for(i= 0;i < elems;i++)
{
rb->fdprintf(fd, "%u%%, ", i * 10);
}
rb->lseek(fd, -2, SEEK_CUR); /*remove last comma */
rb->fdprintf(fd, "} when charging %sabled\n", "en");
rb->fdprintf(fd, "charge: {");
for(i= 0;i < elems;i++)
{
rb->fdprintf(fd, "%u, ", rb->device_battery_tables->charge[i]);
}
rb->lseek(fd, -2, SEEK_CUR); /*remove last comma */
rb->fdprintf(fd, "}\n\n");
#endif
rb->close(fd);
}
}
}
enum plugin_status plugin_start(const void* parameter)
{
int button, fd;
@ -543,6 +619,7 @@ enum plugin_status plugin_start(const void* parameter)
#endif
if (!resume)
{
do_export_battery_tables();
do
{
button = rb->button_get(true);