1
0
Fork 0
forked from len0rd/rockbox

battery_bench: Log battery current information

Works on targets supporting CURRENT_MEASURE.

Change-Id: I021b995c46fab923287ad54e72863695ef9ed58a
This commit is contained in:
Aidan MacDonald 2021-11-30 19:29:54 +00:00
parent 9ae983068a
commit fc678bd001
3 changed files with 19 additions and 2 deletions

View file

@ -804,6 +804,7 @@ static const struct plugin_api rockbox_api = {
the API gets incompatible */
warn_on_pl_erase,
playlist_insert_playlist,
battery_current,
};
static int plugin_buffer_handle;

View file

@ -155,7 +155,7 @@ int plugin_open(const char *plugin, const char *parameter);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 246
#define PLUGIN_API_VERSION 247
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
@ -931,6 +931,7 @@ struct plugin_api {
bool (*warn_on_pl_erase)(void);
int (*playlist_insert_playlist)(struct playlist_info* playlist,
const char *filename, int position, bool queue);
int (*battery_current)(void);
};
/* plugin header */

View file

@ -268,7 +268,10 @@ static struct batt_info
* a power of 2 */
unsigned secs;
int eta;
unsigned int voltage;
int voltage;
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
int current;
#endif
short level;
unsigned short flags;
} bat[BUF_SIZE/sizeof(struct batt_info)];
@ -368,6 +371,9 @@ static void flush_buffer(void)
rb->fdprintf(fd,
"%02d:%02d:%02d, %05d, %03d%%, "
"%02d:%02d, %04d, "
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
" %04d, "
#endif
#if CONFIG_CHARGING
" %c"
#if CONFIG_CHARGING >= CHARGING_MONITOR
@ -382,6 +388,9 @@ static void flush_buffer(void)
HMS(bat[i].secs), bat[i].secs, bat[i].level,
bat[i].eta / 60, bat[i].eta % 60,
bat[i].voltage
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
, bat[i].current
#endif
#if CONFIG_CHARGING
, (bat[i].flags & BIT_CHARGER) ? 'A' : '-'
#if CONFIG_CHARGING >= CHARGING_MONITOR
@ -419,6 +428,9 @@ static void thread(void)
bat[buf_idx].level = rb->battery_level();
bat[buf_idx].eta = rb->battery_time();
bat[buf_idx].voltage = rb->battery_voltage();
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
bat[buf_idx].current = rb->battery_current();
#endif
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
bat[buf_idx].flags = charge_state();
#endif
@ -579,6 +591,9 @@ enum plugin_status plugin_start(const void* parameter)
rb->fdprintf(fd,
"# Time:, Seconds:, Level:, Time Left:, Voltage[mV]:"
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
", Current[mA]:"
#endif
#if CONFIG_CHARGING
", C:"
#endif