diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-01-30 16:25:46 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-01-30 16:25:46 +0000 |
commit | 91846a1a8d94dc8c7540efe3bbc8216f6ded7cb2 (patch) | |
tree | 8a8f0c328495e0631e568c1bdbe7c151e2590190 | |
parent | 8a77317e9c7c708153d8547bfccc3b4ef2324e3c (diff) | |
download | rockbox-91846a1a8d94dc8c7540efe3bbc8216f6ded7cb2.tar.gz rockbox-91846a1a8d94dc8c7540efe3bbc8216f6ded7cb2.zip |
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
-rw-r--r-- | apps/lang/english.lang | 18 | ||||
-rw-r--r-- | apps/settings.c | 7 | ||||
-rw-r--r-- | apps/settings.h | 1 | ||||
-rw-r--r-- | apps/settings_menu.c | 16 | ||||
-rw-r--r-- | firmware/export/config-ondiofm.h | 2 | ||||
-rw-r--r-- | firmware/export/config-ondiosp.h | 2 | ||||
-rw-r--r-- | firmware/export/config.h | 6 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 8 | ||||
-rw-r--r-- | firmware/powermgmt.c | 38 |
9 files changed, 80 insertions, 18 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 795bde69f8..6ef4d40390 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -2925,3 +2925,21 @@ desc: ID3 virtual folder name | |||
2925 | eng: "Found %d matches" | 2925 | eng: "Found %d matches" |
2926 | voice: "" | 2926 | voice: "" |
2927 | new: | 2927 | new: |
2928 | |||
2929 | id: LANG_BATTERY_TYPE | ||
2930 | desc: in battery settings | ||
2931 | eng: "Battery type" | ||
2932 | voice: "Battery type" | ||
2933 | new: | ||
2934 | |||
2935 | id: LANG_BATTERY_TYPE_ALKALINE | ||
2936 | desc: in battery settings | ||
2937 | eng: "Alkaline" | ||
2938 | voice: "Alkaline" | ||
2939 | new: | ||
2940 | |||
2941 | id: LANG_BATTERY_TYPE_NIMH | ||
2942 | desc: in battery settings | ||
2943 | eng: "NiMH" | ||
2944 | voice: "Nickel metal hydride" | ||
2945 | new: | ||
diff --git a/apps/settings.c b/apps/settings.c index de4254edad..e16d546bb6 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -235,6 +235,10 @@ static const struct bit_entry rtc_bits[] = | |||
235 | /* new stuff to be added here */ | 235 | /* new stuff to be added here */ |
236 | /* If values are just added to the end, no need to bump the version. */ | 236 | /* If values are just added to the end, no need to bump the version. */ |
237 | 237 | ||
238 | #if BATTERY_TYPES_COUNT > 1 | ||
239 | {1, S_O(battery_type), 0, "battery type", "alkaline,nimh" }, | ||
240 | #endif | ||
241 | |||
238 | /* Current sum of bits: 259 (worst case) */ | 242 | /* Current sum of bits: 259 (worst case) */ |
239 | /* Sum of all bit sizes must not grow beyond 288! */ | 243 | /* Sum of all bit sizes must not grow beyond 288! */ |
240 | }; | 244 | }; |
@@ -759,6 +763,9 @@ void settings_apply(void) | |||
759 | #endif | 763 | #endif |
760 | 764 | ||
761 | set_battery_capacity(global_settings.battery_capacity); | 765 | set_battery_capacity(global_settings.battery_capacity); |
766 | #if BATTERY_TYPES_COUNT > 1 | ||
767 | set_battery_type(global_settings.battery_type); | ||
768 | #endif | ||
762 | 769 | ||
763 | #ifdef HAVE_LCD_BITMAP | 770 | #ifdef HAVE_LCD_BITMAP |
764 | lcd_set_invert_display(global_settings.invert); | 771 | lcd_set_invert_display(global_settings.invert); |
diff --git a/apps/settings.h b/apps/settings.h index b28f4cedea..8a12b2623c 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -185,6 +185,7 @@ struct user_settings | |||
185 | bool discharge; /* maintain charge of at least: false = 85%, true = 10% */ | 185 | bool discharge; /* maintain charge of at least: false = 85%, true = 10% */ |
186 | bool trickle_charge; /* do trickle charging: 0=off, 1=on */ | 186 | bool trickle_charge; /* do trickle charging: 0=off, 1=on */ |
187 | int battery_capacity; /* in mAh */ | 187 | int battery_capacity; /* in mAh */ |
188 | int battery_type; /* for units which can take multiple types (Ondio). */ | ||
188 | 189 | ||
189 | /* resume settings */ | 190 | /* resume settings */ |
190 | 191 | ||
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 63f1415af8..b19f2eda3c 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -707,6 +707,19 @@ static bool battery_capacity(void) | |||
707 | &set_battery_capacity, 50, BATTERY_CAPACITY_MIN, | 707 | &set_battery_capacity, 50, BATTERY_CAPACITY_MIN, |
708 | BATTERY_CAPACITY_MAX ); | 708 | BATTERY_CAPACITY_MAX ); |
709 | } | 709 | } |
710 | |||
711 | #if BATTERY_TYPES_COUNT > 1 | ||
712 | static bool battery_type(void) | ||
713 | { | ||
714 | static const struct opt_items names[] = { | ||
715 | { STR(LANG_BATTERY_TYPE_ALKALINE) }, | ||
716 | { STR(LANG_BATTERY_TYPE_NIMH) } | ||
717 | }; | ||
718 | |||
719 | return set_option(str(LANG_BATTERY_TYPE), &global_settings.battery_type, | ||
720 | INT, names, 2, set_battery_type); | ||
721 | } | ||
722 | #endif | ||
710 | #endif | 723 | #endif |
711 | 724 | ||
712 | #ifdef HAVE_CHARGE_CTRL | 725 | #ifdef HAVE_CHARGE_CTRL |
@@ -1250,6 +1263,9 @@ static bool battery_settings_menu(void) | |||
1250 | #endif | 1263 | #endif |
1251 | #ifndef SIMULATOR | 1264 | #ifndef SIMULATOR |
1252 | { ID2P(LANG_BATTERY_CAPACITY), battery_capacity }, | 1265 | { ID2P(LANG_BATTERY_CAPACITY), battery_capacity }, |
1266 | #if BATTERY_TYPES_COUNT > 1 | ||
1267 | { ID2P(LANG_BATTERY_TYPE), battery_type }, | ||
1268 | #endif | ||
1253 | #else | 1269 | #else |
1254 | #ifndef HAVE_CHARGE_CTRL | 1270 | #ifndef HAVE_CHARGE_CTRL |
1255 | { "Dummy", NULL }, /* to have an entry at all, in the simulator */ | 1271 | { "Dummy", NULL }, /* to have an entry at all, in the simulator */ |
diff --git a/firmware/export/config-ondiofm.h b/firmware/export/config-ondiofm.h index 99d4c483ea..79e7adbe58 100644 --- a/firmware/export/config-ondiofm.h +++ b/firmware/export/config-ondiofm.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #define CONFIG_I2C I2C_ONDIO | 26 | #define CONFIG_I2C I2C_ONDIO |
27 | 27 | ||
28 | /* Type of mobile power */ | 28 | /* Type of mobile power */ |
29 | #define CONFIG_BATTERY BATT_3AAA_ALKALINE | 29 | #define CONFIG_BATTERY BATT_3AAA |
30 | 30 | ||
31 | /* Battery scale factor (average from 3 Ondios) */ | 31 | /* Battery scale factor (average from 3 Ondios) */ |
32 | #define BATTERY_SCALE_FACTOR 4735 | 32 | #define BATTERY_SCALE_FACTOR 4735 |
diff --git a/firmware/export/config-ondiosp.h b/firmware/export/config-ondiosp.h index 41bc83bf60..bda078a792 100644 --- a/firmware/export/config-ondiosp.h +++ b/firmware/export/config-ondiosp.h | |||
@@ -20,7 +20,7 @@ | |||
20 | #define CPU_FREQ 12000000 | 20 | #define CPU_FREQ 12000000 |
21 | 21 | ||
22 | /* Type of mobile power */ | 22 | /* Type of mobile power */ |
23 | #define CONFIG_BATTERY BATT_3AAA_ALKALINE | 23 | #define CONFIG_BATTERY BATT_3AAA |
24 | 24 | ||
25 | /* Battery scale factor (average from 3 Ondios) */ | 25 | /* Battery scale factor (average from 3 Ondios) */ |
26 | #define BATTERY_SCALE_FACTOR 4735 | 26 | #define BATTERY_SCALE_FACTOR 4735 |
diff --git a/firmware/export/config.h b/firmware/export/config.h index 4a55fbc622..64694af794 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -45,9 +45,9 @@ | |||
45 | #define GMINI100_PAD 4 | 45 | #define GMINI100_PAD 4 |
46 | 46 | ||
47 | /* CONFIG_BATTERY */ | 47 | /* CONFIG_BATTERY */ |
48 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ | 48 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ |
49 | #define BATT_4AA_NIMH 1500 | 49 | #define BATT_4AA_NIMH 1500 |
50 | #define BATT_3AAA_ALKALINE 1000 | 50 | #define BATT_3AAA 1000 /* Ondio */ |
51 | 51 | ||
52 | /* CONFIG_LCD */ | 52 | /* CONFIG_LCD */ |
53 | #define LCD_GMINI100 0 | 53 | #define LCD_GMINI100 0 |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 2847156f46..ce006e9145 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -26,13 +26,15 @@ | |||
26 | #define BATTERY_LEVEL_FULL 400 /* 4.00V */ | 26 | #define BATTERY_LEVEL_FULL 400 /* 4.00V */ |
27 | #define BATTERY_CAPACITY_MIN 2200 | 27 | #define BATTERY_CAPACITY_MIN 2200 |
28 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ | 28 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ |
29 | #elif CONFIG_BATTERY == BATT_3AAA_ALKALINE /* Ondio, Alkalines */ | 29 | #define BATTERY_TYPES_COUNT 1 |
30 | #elif CONFIG_BATTERY == BATT_3AAA /* Ondio */ | ||
30 | #define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */ | 31 | #define BATTERY_LEVEL_SHUTDOWN 260 /* 2.60V */ |
31 | #define BATTERY_LEVEL_EMPTY 270 /* 2.70V */ | 32 | #define BATTERY_LEVEL_EMPTY 270 /* 2.70V */ |
32 | #define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */ | 33 | #define BATTERY_LEVEL_DANGEROUS 280 /* 2.80V */ |
33 | #define BATTERY_LEVEL_FULL 450 /* 4.50V */ | 34 | #define BATTERY_LEVEL_FULL 475 /* 4.75V */ |
34 | #define BATTERY_CAPACITY_MIN 500 | 35 | #define BATTERY_CAPACITY_MIN 500 |
35 | #define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */ | 36 | #define BATTERY_CAPACITY_MAX 1500 /* max. capacity selectable in settings */ |
37 | #define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */ | ||
36 | #else /* Recorder, NiMH */ | 38 | #else /* Recorder, NiMH */ |
37 | #define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */ | 39 | #define BATTERY_LEVEL_SHUTDOWN 450 /* 4.50V */ |
38 | #define BATTERY_LEVEL_EMPTY 465 /* 4.65V */ | 40 | #define BATTERY_LEVEL_EMPTY 465 /* 4.65V */ |
@@ -40,6 +42,7 @@ | |||
40 | #define BATTERY_LEVEL_FULL 585 /* 5.85V */ | 42 | #define BATTERY_LEVEL_FULL 585 /* 5.85V */ |
41 | #define BATTERY_CAPACITY_MIN 1500 | 43 | #define BATTERY_CAPACITY_MIN 1500 |
42 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ | 44 | #define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable in settings */ |
45 | #define BATTERY_TYPES_COUNT 1 | ||
43 | #endif | 46 | #endif |
44 | 47 | ||
45 | #define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY) | 48 | #define BATTERY_RANGE (BATTERY_LEVEL_FULL - BATTERY_LEVEL_EMPTY) |
@@ -111,6 +114,7 @@ bool battery_level_safe(void); | |||
111 | 114 | ||
112 | void set_poweroff_timeout(int timeout); | 115 | void set_poweroff_timeout(int timeout); |
113 | void set_battery_capacity(int capacity); /* set local battery capacity value */ | 116 | void set_battery_capacity(int capacity); /* set local battery capacity value */ |
117 | void set_battery_type(int type); /* set local battery type */ | ||
114 | 118 | ||
115 | void set_sleep_timer(int seconds); | 119 | void set_sleep_timer(int seconds); |
116 | int get_sleep_timer(void); | 120 | int get_sleep_timer(void); |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 26759b647d..08f0be7d5f 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -89,20 +89,21 @@ static const int poweroff_idle_timeout_value[15] = | |||
89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 | 89 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 30, 45, 60 |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static const int percent_to_volt_decharge[11] = | 92 | static const short percent_to_volt_decharge[BATTERY_TYPES_COUNT][11] = |
93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ | 93 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging disabled */ |
94 | { | 94 | { |
95 | #if CONFIG_BATTERY == BATT_LIION2200 | 95 | #if CONFIG_BATTERY == BATT_LIION2200 |
96 | /* measured values */ | 96 | /* measured values */ |
97 | 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 | 97 | { 260, 285, 295, 303, 311, 320, 330, 345, 360, 380, 400 } |
98 | #elif CONFIG_BATTERY == BATT_3AAA_ALKALINE | 98 | #elif CONFIG_BATTERY == BATT_3AAA |
99 | /* taken from a textbook alkaline discharge graph, not measured */ | 99 | /* measured values */ |
100 | 270, 303, 324, 336, 348, 357, 366, 378, 390, 408, 450 | 100 | { 280, 325, 341, 353, 364, 374, 385, 395, 409, 427, 475 }, /* alkaline */ |
101 | { 310, 355, 363, 369, 372, 374, 376, 378, 380, 386, 405 } /* NiMH */ | ||
101 | #else /* NiMH */ | 102 | #else /* NiMH */ |
102 | /* original values were taken directly after charging, but it should show | 103 | /* original values were taken directly after charging, but it should show |
103 | 100% after turning off the device for some hours, too */ | 104 | 100% after turning off the device for some hours, too */ |
104 | 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 /* orig. values: | 105 | { 450, 481, 491, 497, 503, 507, 512, 514, 517, 525, 540 } |
105 | ...,528,560 */ | 106 | /* orig. values: ...,528,560 */ |
106 | #endif | 107 | #endif |
107 | }; | 108 | }; |
108 | 109 | ||
@@ -115,6 +116,16 @@ void set_battery_capacity(int capacity) | |||
115 | battery_capacity = BATTERY_CAPACITY_MIN; | 116 | battery_capacity = BATTERY_CAPACITY_MIN; |
116 | } | 117 | } |
117 | 118 | ||
119 | #if BATTERY_TYPES_COUNT > 1 | ||
120 | static int battery_type = 0; | ||
121 | |||
122 | void set_battery_type(int type) | ||
123 | { | ||
124 | battery_type = type; | ||
125 | battery_level_cached = -1; /* reset on type change */ | ||
126 | } | ||
127 | #endif | ||
128 | |||
118 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 | 129 | #if defined(HAVE_CHARGE_CTRL) || CONFIG_BATTERY == BATT_LIION2200 |
119 | int charge_state = 0; /* at the beginning, the | 130 | int charge_state = 0; /* at the beginning, the |
120 | charger does nothing */ | 131 | charger does nothing */ |
@@ -136,7 +147,7 @@ int trickle_sec = 0; /* how many seconds should the | |||
136 | charger be enabled per | 147 | charger be enabled per |
137 | minute for trickle | 148 | minute for trickle |
138 | charging? */ | 149 | charging? */ |
139 | static const int percent_to_volt_charge[11] = | 150 | static const short percent_to_volt_charge[11] = |
140 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ | 151 | /* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */ |
141 | { | 152 | { |
142 | /* values guessed, see | 153 | /* values guessed, see |
@@ -170,7 +181,7 @@ int battery_time(void) | |||
170 | 181 | ||
171 | /* look into the percent_to_volt_* table and get a realistic battery level | 182 | /* look into the percent_to_volt_* table and get a realistic battery level |
172 | percentage */ | 183 | percentage */ |
173 | int voltage_to_percent(int voltage, const int* table) | 184 | int voltage_to_percent(int voltage, const short* table) |
174 | { | 185 | { |
175 | if (voltage <= table[0]) | 186 | if (voltage <= table[0]) |
176 | return 0; | 187 | return 0; |
@@ -195,6 +206,9 @@ void battery_level_update(void) | |||
195 | int level = 0; | 206 | int level = 0; |
196 | int c = 0; | 207 | int c = 0; |
197 | int i; | 208 | int i; |
209 | #if BATTERY_TYPES_COUNT == 1 /* single type */ | ||
210 | const int battery_type = 0; | ||
211 | #endif | ||
198 | 212 | ||
199 | /* calculate maximum over last 3 minutes (skip empty samples) */ | 213 | /* calculate maximum over last 3 minutes (skip empty samples) */ |
200 | for (i = 0; i < 3; i++) | 214 | for (i = 0; i < 3; i++) |
@@ -214,7 +228,8 @@ void battery_level_update(void) | |||
214 | 228 | ||
215 | #ifdef HAVE_CHARGE_CTRL | 229 | #ifdef HAVE_CHARGE_CTRL |
216 | if (charge_state == 0) { /* decharge */ | 230 | if (charge_state == 0) { /* decharge */ |
217 | level = voltage_to_percent(level, percent_to_volt_decharge); | 231 | level = voltage_to_percent(level, |
232 | percent_to_volt_decharge[battery_type]); | ||
218 | } | 233 | } |
219 | else if (charge_state == 1) { /* charge */ | 234 | else if (charge_state == 1) { /* charge */ |
220 | level = voltage_to_percent(level, percent_to_volt_charge); | 235 | level = voltage_to_percent(level, percent_to_volt_charge); |
@@ -223,7 +238,8 @@ void battery_level_update(void) | |||
223 | battery_level_cached = level = 100; | 238 | battery_level_cached = level = 100; |
224 | } | 239 | } |
225 | #else | 240 | #else |
226 | level = voltage_to_percent(level, percent_to_volt_decharge); | 241 | level = voltage_to_percent(level, |
242 | percent_to_volt_decharge[battery_type]); | ||
227 | /* always use the decharge table */ | 243 | /* always use the decharge table */ |
228 | #endif | 244 | #endif |
229 | 245 | ||