1616
1717#include "tmo_battery_ctrl.h"
1818
19- #define TABLE_LEN 11
19+ #define BATTERY_TABLE_LEN 15
2020#define TABLE_VOLTAGE 0
2121#define TABLE_PERCENT 1
2222
23- // 100% value based on actual new battery measurement
24- static float battery_discharging_tbl [TABLE_LEN ][2 ] = {
25- {4.145 , 100.0 },
26- {4.072 , 90.0 },
27- {3.992 , 80.0 },
28- {3.923 , 70.0 },
29- {3.858 , 60.0 },
30- {3.806 , 50.0 },
31- {3.775 , 40.0 },
32- {3.752 , 30.0 },
33- {3.729 , 20.0 },
34- {3.686 , 10.0 },
35- {3.632 , 0.0 }};
36-
37- // 100% value based on actual new battery measurement
38- static float battery_charging_tbl [TABLE_LEN ][2 ] = {
39- {4.175 , 100.0 },
40- {4.130 , 90.0 },
41- {4.071 , 80.0 },
42- {4.005 , 70.0 },
43- {3.934 , 60.0 },
44- {3.886 , 50.0 },
45- {3.853 , 40.0 },
46- {3.833 , 30.0 },
47- {3.800 , 20.0 },
48- {3.741 , 10.0 },
49- {3.597 , 0.0 }};
23+ extern float battery_discharging_tbl [BATTERY_TABLE_LEN ][2 ];
24+ extern float battery_charging_tbl [BATTERY_TABLE_LEN ][2 ];
5025
5126bool is_battery_charging ()
5227{
@@ -61,7 +36,7 @@ bool is_battery_charging()
6136
6237float get_remaining_capacity (float battery_voltage )
6338{
64- float (* voltage_capacity_table )[TABLE_LEN ][2 ];
39+ float (* voltage_capacity_table )[BATTERY_TABLE_LEN ][2 ];
6540 float high_voltage = 0.0 ;
6641 float low_voltage = 0.0 ;
6742 uint32_t i ;
@@ -77,22 +52,22 @@ float get_remaining_capacity(float battery_voltage)
7752 return 100.0 ;
7853 }
7954
80- if (battery_voltage <= (* voltage_capacity_table )[TABLE_LEN - 1 ][TABLE_VOLTAGE ]) {
55+ if (battery_voltage <= (* voltage_capacity_table )[BATTERY_TABLE_LEN - 1 ][TABLE_VOLTAGE ]) {
8156 return 0.0 ;
8257 }
8358
8459 // find the table percentage entries that correspond
8560 // to the voltage and interpolate between the two
8661
87- for (i = 1 ; i < TABLE_LEN ; i ++ ) {
62+ for (i = 1 ; i < BATTERY_TABLE_LEN ; i ++ ) {
8863 if (battery_voltage > (* voltage_capacity_table )[i ][TABLE_VOLTAGE ]) {
8964 high_voltage = (* voltage_capacity_table )[i - 1 ][TABLE_VOLTAGE ];
9065 low_voltage = (* voltage_capacity_table )[i ][TABLE_VOLTAGE ];
9166 break ;
9267 }
9368 }
9469
95- if ((i >= TABLE_LEN ) || (high_voltage == low_voltage )) {
70+ if ((i >= BATTERY_TABLE_LEN ) || (high_voltage == low_voltage )) {
9671 return 0.0 ;
9772 }
9873
0 commit comments