[HD Mini General] -r0bin-:
ok, i have an algorithm that makes sense, tested and validated on all the discharge data i have:

ismail, bruce, ciccius, mqd, pwel, smudooo and munjeni

only issue is az35: i get veeery strange values on volt sensor, goes up and down for no reasons, thus its impossible to get a suitable result.

there is an issue for sure:

- try to upgrade both radio + ROM

- try to calibrate your battery

- buy a new battery...

(i could not validate on discharge data generated by PowerSpy v1.0 because wCurrent is missing)

my algorithm is written in Visual Basic (Excel language) but it is mainly inspired from Raphael.

if you're interested by VB, here is it. Munjeni, i think you can easily adapt it on PHP. i will re-write it next week in a new kernel and we'll start the trials ;)

Note: symbol ' is used for comments, so everything written after this symbol does not count!

Function calcBattPercents(volt, temp, curr)
'Initialize battery params
battery_capacity = 1200
termination_current = 36 '//3% of batt capacity
temp_correction = 0
temp_correction_const = 26 '16
volt_discharge_res_coeff = 27
cri_volt_threshold = 3300 '1,5%
low_volt_threshold = 3600 '5%
min_volt_threshold = 3670 '10%
mid_volt_threshold = 3750 '30%
med_volt_threshold = 3815 '57%
max_volt_threshold = 3950 '76,5%
full_volt_threshold = 4100 '4200 '100%
cri_volt_perc_start = 15
low_volt_perc_start = 50
min_volt_perc_start = 100
mid_volt_perc_start = 300
med_volt_perc_start = 570
max_volt_perc_start = 765
cri_volt_dynslope = 860 '200
low_volt_dynslope = 140 '48
min_volt_dynslope = 40 '26
mid_volt_dynslope = 24 '41
med_volt_dynslope = 69 '69
max_volt_dynslope = 64 '106 '96

'Init local vars
result = 0
calc_algo = 0
temp_correct_volt = 0
corr_return = 0

'Compute volt discharge resistor
volt_discharge_resistor = (Abs(curr) * volt_discharge_res_coeff) / 100
If (volt_discharge_resistor < 0) Then
volt_discharge_resistor = volt_discharge_resistor + 1
End If

'Apply voltage correction
corrected_volt = volt + volt_discharge_resistor

'If temp is too low
If (temp > 250) Then
temp_correct_volt = temp_correct_volt
Else
temp_correct_volt = -(temp_correct_volt + ((temp_correction_const * ((250 - temp) * Abs(curr))) / 10000))
End If

'Percentage calculation
If ((corrected_volt - temp_correct_volt) >= full_volt_threshold) Then
result = 100
Else
If ((corrected_volt - temp_correct_volt) >= max_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - max_volt_threshold) * 10) / max_volt_dynslope) + (max_volt_perc_start / 10))
Else
If ((corrected_volt - temp_correct_volt) >= med_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - med_volt_threshold) * 10) / med_volt_dynslope) + (med_volt_perc_start / 10))
Else
If ((corrected_volt - temp_correct_volt) >= mid_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - mid_volt_threshold) * 10) / mid_volt_dynslope) + (mid_volt_perc_start / 10))
Else
If ((corrected_volt - temp_correct_volt) >= min_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - min_volt_threshold) * 10) / min_volt_dynslope) + (min_volt_perc_start / 10))
Else
If ((corrected_volt - temp_correct_volt) >= low_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - low_volt_threshold) * 10) / low_volt_dynslope) + (low_volt_perc_start / 10))
Else
If ((corrected_volt - temp_correct_volt) >= cri_volt_threshold) Then
result = ((((corrected_volt - temp_correct_volt - cri_volt_threshold) * 10) / cri_volt_dynslope) + (cri_volt_perc_start / 10))
Else
result = 0
End If
End If
End If
End If
End If
End If
End If

'avoid returning out of bounds values
If (result > 99) Then
result = 100
End If
If (result < 0) Then
result = 0
End If

'return batt value
calcBattPercents = result
End Function

let me know what you think about it