mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 13:15:18 -05:00
New Ondio feature: Battery type setting, for correct battery level display.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5717 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
8a77317e9c
commit
91846a1a8d
9 changed files with 80 additions and 18 deletions
|
|
@ -2925,3 +2925,21 @@ desc: ID3 virtual folder name
|
||||||
eng: "Found %d matches"
|
eng: "Found %d matches"
|
||||||
voice: ""
|
voice: ""
|
||||||
new:
|
new:
|
||||||
|
|
||||||
|
id: LANG_BATTERY_TYPE
|
||||||
|
desc: in battery settings
|
||||||
|
eng: "Battery type"
|
||||||
|
voice: "Battery type"
|
||||||
|
new:
|
||||||
|
|
||||||
|
id: LANG_BATTERY_TYPE_ALKALINE
|
||||||
|
desc: in battery settings
|
||||||
|
eng: "Alkaline"
|
||||||
|
voice: "Alkaline"
|
||||||
|
new:
|
||||||
|
|
||||||
|
id: LANG_BATTERY_TYPE_NIMH
|
||||||
|
desc: in battery settings
|
||||||
|
eng: "NiMH"
|
||||||
|
voice: "Nickel metal hydride"
|
||||||
|
new:
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,10 @@ static const struct bit_entry rtc_bits[] =
|
||||||
/* new stuff to be added here */
|
/* new stuff to be added here */
|
||||||
/* If values are just added to the end, no need to bump the version. */
|
/* If values are just added to the end, no need to bump the version. */
|
||||||
|
|
||||||
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
|
{1, S_O(battery_type), 0, "battery type", "alkaline,nimh" },
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Current sum of bits: 259 (worst case) */
|
/* Current sum of bits: 259 (worst case) */
|
||||||
/* Sum of all bit sizes must not grow beyond 288! */
|
/* Sum of all bit sizes must not grow beyond 288! */
|
||||||
};
|
};
|
||||||
|
|
@ -759,6 +763,9 @@ void settings_apply(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
set_battery_capacity(global_settings.battery_capacity);
|
set_battery_capacity(global_settings.battery_capacity);
|
||||||
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
|
set_battery_type(global_settings.battery_type);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
lcd_set_invert_display(global_settings.invert);
|
lcd_set_invert_display(global_settings.invert);
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ struct user_settings
|
||||||
bool discharge; /* maintain charge of at least: false = 85%, true = 10% */
|
bool discharge; /* maintain charge of at least: false = 85%, true = 10% */
|
||||||
bool trickle_charge; /* do trickle charging: 0=off, 1=on */
|
bool trickle_charge; /* do trickle charging: 0=off, 1=on */
|
||||||
int battery_capacity; /* in mAh */
|
int battery_capacity; /* in mAh */
|
||||||
|
int battery_type; /* for units which can take multiple types (Ondio). */
|
||||||
|
|
||||||
/* resume settings */
|
/* resume settings */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -707,6 +707,19 @@ static bool battery_capacity(void)
|
||||||
&set_battery_capacity, 50, BATTERY_CAPACITY_MIN,
|
&set_battery_capacity, 50, BATTERY_CAPACITY_MIN,
|
||||||
BATTERY_CAPACITY_MAX );
|
BATTERY_CAPACITY_MAX );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
|
static bool battery_type(void)
|
||||||
|
{
|
||||||
|
static const struct opt_items names[] = {
|
||||||
|
{ STR(LANG_BATTERY_TYPE_ALKALINE) },
|
||||||
|
{ STR(LANG_BATTERY_TYPE_NIMH) }
|
||||||
|
};
|
||||||
|
|
||||||
|
return set_option(str(LANG_BATTERY_TYPE), &global_settings.battery_type,
|
||||||
|
INT, names, 2, set_battery_type);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CHARGE_CTRL
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
|
|
@ -1250,6 +1263,9 @@ static bool battery_settings_menu(void)
|
||||||
#endif
|
#endif
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
{ ID2P(LANG_BATTERY_CAPACITY), battery_capacity },
|
{ ID2P(LANG_BATTERY_CAPACITY), battery_capacity },
|
||||||
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
|
{ ID2P(LANG_BATTERY_TYPE), battery_type },
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#ifndef HAVE_CHARGE_CTRL
|
#ifndef HAVE_CHARGE_CTRL
|
||||||
{ "Dummy", NULL }, /* to have an entry at all, in the simulator */
|
{ "Dummy", NULL }, /* to have an entry at all, in the simulator */
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
#define CONFIG_I2C I2C_ONDIO
|
#define CONFIG_I2C I2C_ONDIO
|
||||||
|
|
||||||
/* Type of mobile power */
|
/* Type of mobile power */
|
||||||
#define CONFIG_BATTERY BATT_3AAA_ALKALINE
|
#define CONFIG_BATTERY BATT_3AAA
|
||||||
|
|
||||||
/* Battery scale factor (average from 3 Ondios) */
|
/* Battery scale factor (average from 3 Ondios) */
|
||||||
#define BATTERY_SCALE_FACTOR 4735
|
#define BATTERY_SCALE_FACTOR 4735
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
#define CPU_FREQ 12000000
|
#define CPU_FREQ 12000000
|
||||||
|
|
||||||
/* Type of mobile power */
|
/* Type of mobile power */
|
||||||
#define CONFIG_BATTERY BATT_3AAA_ALKALINE
|
#define CONFIG_BATTERY BATT_3AAA
|
||||||
|
|
||||||
/* Battery scale factor (average from 3 Ondios) */
|
/* Battery scale factor (average from 3 Ondios) */
|
||||||
#define BATTERY_SCALE_FACTOR 4735
|
#define BATTERY_SCALE_FACTOR 4735
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,9 @@
|
||||||
#define GMINI100_PAD 4
|
#define GMINI100_PAD 4
|
||||||
|
|
||||||
/* CONFIG_BATTERY */
|
/* CONFIG_BATTERY */
|
||||||
#define BATT_LIION2200 2200 /* FM/V2 recorder type */
|
#define BATT_LIION2200 2200 /* FM/V2 recorder type */
|
||||||
#define BATT_4AA_NIMH 1500
|
#define BATT_4AA_NIMH 1500
|
||||||
#define BATT_3AAA_ALKALINE 1000
|
#define BATT_3AAA 1000 /* Ondio */
|
||||||
|
|
||||||
/* CONFIG_LCD */
|
/* CONFIG_LCD */
|
||||||
#define LCD_GMINI100 0
|
#define LCD_GMINI100 0
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,15 @@
|
||||||
#define BATTERY_LEVEL_FULL 400 /* 4.00V */
|
#define BATTERY_LEVEL_FULL 400 /* 4.00V */
|
||||||
#define BATTERY_CAPACITY_MIN 2200
|
#define BATTERY_CAPACITY_MIN 2200
|
||||||
#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */
|
#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */
|
||||||
#elif CONFIG_BATTERY == BATT_3AAA_ALKALINE /* Ondio, Alkalines */
|
#define BATTERY_TYPES_COUNT 1
|
||||||
|
#elif CONFIG_BATTERY == BATT_3AAA /* Ondio */
|
||||||
#define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */
|
#define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */
|
||||||
#define BATTERY_LEVEL_EMPTY 270 /* 2.70V */
|
#define BATTERY_LEVEL_EMPTY 270 /* 2.70V */
|
||||||
#define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */
|
#define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */
|
||||||
#define BATTERY_LEVEL_FULL 450 /* 4.50V */
|
#define BATTERY_LEVEL_FULL 475 /* 4.75V */
|
||||||
#define BATTERY_CAPACITY_MIN 500
|
#define BATTERY_CAPACITY_MIN 500
|
||||||
#define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */
|
#define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */
|
||||||
|
#define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */
|
||||||
#else /* Recorder, NiMH */
|
#else /* Recorder, NiMH */
|
||||||
#define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */
|
#define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */
|
||||||
#define BATTERY_LEVEL_EMPTY 465 /* 4.65V */
|
#define BATTERY_LEVEL_EMPTY 465 /* 4.65V */
|
||||||
|
|
@ -40,6 +42,7 @@
|
||||||
#define BATTERY_LEVEL_FULL 585 /* 5.85V */
|
#define BATTERY_LEVEL_FULL 585 /* 5.85V */
|
||||||
#define BATTERY_CAPACITY_MIN 1500
|
#define BATTERY_CAPACITY_MIN 1500
|
||||||
#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */
|
#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */
|
||||||
|
#define BATTERY_TYPES_COUNT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY)
|
#define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY)
|
||||||
|
|
@ -111,6 +114,7 @@ bool battery_level_safe(void);
|
||||||
|
|
||||||
void set_poweroff_timeout(int timeout);
|
void set_poweroff_timeout(int timeout);
|
||||||
void set_battery_capacity(int capacity); /* set local battery capacity value */
|
void set_battery_capacity(int capacity); /* set local battery capacity value */
|
||||||
|
void set_battery_type(int type); /* set local battery type */
|
||||||
|
|
||||||
void set_sleep_timer(int seconds);
|
void set_sleep_timer(int seconds);
|
||||||
int get_sleep_timer(void);
|
int get_sleep_timer(void);
|
||||||
|
|
|
||||||
|
|
@ -89,20 +89,21 @@ static const int poweroff_idle_timeout_value[15] =
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int percent_to_volt_decharge[11] =
|
static const short percent_to_volt_decharge[BATTERY_TYPES_COUNT][11] =
|
||||||
/* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */
|
/* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */
|
||||||
{
|
{
|
||||||
#if CONFIG_BATTERY == BATT_LIION2200
|
#if CONFIG_BATTERY == BATT_LIION2200
|
||||||
/* measured values */
|
/* measured values */
|
||||||
260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400
|
{ 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 }
|
||||||
#elif CONFIG_BATTERY == BATT_3AAA_ALKALINE
|
#elif CONFIG_BATTERY == BATT_3AAA
|
||||||
/* taken from a textbook alkaline discharge graph, not measured */
|
/* measured values */
|
||||||
270, 303, 324, 336, 348, 357, 366, 378, 390, 408, 450
|
{ 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* alkaline */
|
||||||
|
{ 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */
|
||||||
#else /* NiMH */
|
#else /* NiMH */
|
||||||
/* original values were taken directly after charging, but it should show
|
/* original values were taken directly after charging, but it should show
|
||||||
100% after turning off the device for some hours, too */
|
100% after turning off the device for some hours, too */
|
||||||
450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 /* orig. values:
|
{ 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 }
|
||||||
...,528,560 */
|
/* orig. values: ...,528,560 */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -115,6 +116,16 @@ void set_battery_capacity(int capacity)
|
||||||
battery_capacity = BATTERY_CAPACITY_MIN;
|
battery_capacity = BATTERY_CAPACITY_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
|
static int battery_type = 0;
|
||||||
|
|
||||||
|
void set_battery_type(int type)
|
||||||
|
{
|
||||||
|
battery_type = type;
|
||||||
|
battery_level_cached = -1; /* reset on type change */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200
|
#if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200
|
||||||
int charge_state = 0; /* at the beginning, the
|
int charge_state = 0; /* at the beginning, the
|
||||||
charger does nothing */
|
charger does nothing */
|
||||||
|
|
@ -136,7 +147,7 @@ int trickle_sec = 0; /* how many seconds should the
|
||||||
charger be enabled per
|
charger be enabled per
|
||||||
minute for trickle
|
minute for trickle
|
||||||
charging? */
|
charging? */
|
||||||
static const int percent_to_volt_charge[11] =
|
static const short percent_to_volt_charge[11] =
|
||||||
/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
|
/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
|
||||||
{
|
{
|
||||||
/* values guessed, see
|
/* values guessed, see
|
||||||
|
|
@ -170,7 +181,7 @@ int battery_time(void)
|
||||||
|
|
||||||
/* look into the percent_to_volt_* table and get a realistic battery level
|
/* look into the percent_to_volt_* table and get a realistic battery level
|
||||||
percentage */
|
percentage */
|
||||||
int voltage_to_percent(int voltage, const int* table)
|
int voltage_to_percent(int voltage, const short* table)
|
||||||
{
|
{
|
||||||
if (voltage <= table[0])
|
if (voltage <= table[0])
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -195,6 +206,9 @@ void battery_level_update(void)
|
||||||
int level = 0;
|
int level = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
int i;
|
int i;
|
||||||
|
#if BATTERY_TYPES_COUNT == 1 /* single type */
|
||||||
|
const int battery_type = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* calculate maximum over last 3 minutes (skip empty samples) */
|
/* calculate maximum over last 3 minutes (skip empty samples) */
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
|
|
@ -214,7 +228,8 @@ void battery_level_update(void)
|
||||||
|
|
||||||
#ifdef HAVE_CHARGE_CTRL
|
#ifdef HAVE_CHARGE_CTRL
|
||||||
if (charge_state == 0) { /* decharge */
|
if (charge_state == 0) { /* decharge */
|
||||||
level = voltage_to_percent(level, percent_to_volt_decharge);
|
level = voltage_to_percent(level,
|
||||||
|
percent_to_volt_decharge[battery_type]);
|
||||||
}
|
}
|
||||||
else if (charge_state == 1) { /* charge */
|
else if (charge_state == 1) { /* charge */
|
||||||
level = voltage_to_percent(level, percent_to_volt_charge);
|
level = voltage_to_percent(level, percent_to_volt_charge);
|
||||||
|
|
@ -223,7 +238,8 @@ void battery_level_update(void)
|
||||||
battery_level_cached = level = 100;
|
battery_level_cached = level = 100;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
level = voltage_to_percent(level, percent_to_volt_decharge);
|
level = voltage_to_percent(level,
|
||||||
|
percent_to_volt_decharge[battery_type]);
|
||||||
/* always use the decharge table */
|
/* always use the decharge table */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue