[HD Mini General] -r0bin-:
i see you have moved forward, good job guys!

i agree with you, better to use integer than float or double (performance issue)

rId is supposed to be "raw battery id". i dont know what is the use of it.

it is not used in raph/topaz battery code, for now on we don't need it.

what i understood:

voltage is the main indicator:

- close to 4,2v you have 100%

- close to 3,6v you have 5%

current tells you when your battery is full (100mA current under windows = 100%)

temperature affects the calculation (low temperature reduce battery performance, voltage reduces too).

look at function: batt_current_temp_correction

I looked at our battery dll, it is not 100% similar to raphael, I hope it is compatible.

there might be other links between indicators, but you have the main algorithm.

see htc_battery_level_compute to have an idea how it is done, there are many corrections to the voltage, and they use a model with slopes and points which we need to fine tune:

/* Charge graph :
*
* Li-ion battery charging is made in two steps :
* 1 / Constant current charge : During this step, the voltage of the battery reach it's max value.
* At the end of this step, the battery charge level is about 70%
* 2 / Constant voltage charge : During this step, the charge current will decrease until it reach
* 3% of the rated battery capacity.
* The battery can be considered fully charged when the charge current is 3% or less.
*
* 1st part of charging process :
* ------------------------------
* Voltage (%)
* ^
* 100% | x
* |
* max_volt_min_percentage | x
* |
* mid_volt_min_percentage | x
* |
* low_volt_min_percentage | x
* |
* 0% +--------x-------------------------------------------------> Voltage
* | | | | |
* critical_volt low_volt mid_volt max_volt full_volt
* _threshold _threshold _threshold _threshold _threshold
*
*	2nd part of charging process (C = battery capacity in current -> 900mAh batt => 900mA):
*	------------------------------
* Current
* ^
* C | x	x
* |
* | x
* |
* | x
* |
* | x
* 3% C | x
* +------------------------------------> Percent of charge
* | | | |
* 70% 100%
*
* added:
* the discharging curve can be define via *6 points* and every point can be positioning on the courve (like if you would try to draw the curve via lines
* therefore you can define a slope value and start height
* see paramter below, and also you can find on XDA developers a XLS files where you can see the algo how it works in detail
* also in the XLS can the values be tested (you only need log data from your model - via grep kernellog for "battlog")
*/

/* Percentage calculus :
*
* - portion range in Volts is ( #next portion#_threshold - #current portion#_threshold )
* - portion range in % is ( #next portion#_min_percentage - #current portion#_min_percentage )
*
* - % of charge in the current portion of the graph = ( current voltage - #current portion#_threshold) / (portion range in Volts)
*	This value will be between 0 and 1
* - % of charge in the global percentage = % of charge in the current portion of the graph * (#current portion#_perc_range)
*	This value will be between 0 and (#current portion#_perc_range)
* *****************************************************************************************
* * % of charge = % of charge in the global percentage + #current portion#_min_percentage *
* *****************************************************************************************
*/

if someone knows where this xls file is (Battery_Calculator.xls on XDA) it interests me. i searched but couldnt find it, i guess it must be old :-/