[HD Mini General] munjeni:
vb is similar as a php and I understand it completely, now I ported your function to php

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)
$volt_discharge_resistor = $volt_discharge_resistor + 1;

//Apply voltage correction
$corrected_volt = $volt + $volt_discharge_resistor;

//If temp is too low
if (temp > 250)
$temp_correct_volt = $temp_correct_volt;
else
$temp_correct_volt = -($temp_correct_volt + (($temp_correction_const * ((250 - $temp) * abs($curr))) / 10000));

//Percentage calculation
if (($corrected_volt - $temp_correct_volt) >= $full_volt_threshold)
$result = 100;
else
{
if (($corrected_volt - $temp_correct_volt) >= $max_volt_threshold)
$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)
$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)
$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)
$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)
$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)
$result = (((($corrected_volt - $temp_correct_volt - $cri_volt_threshold) * 10) / $cri_volt_dynslope) + ($cri_volt_perc_start / 10));
else
$result = 0;
}
}
}
}
}
}

//avoid returning out of bounds values
if ($result > 99)
$result = 100;

if ($result < 0)
$result = 0;

//return batt value
return $result;
}

but not understand what is volt, $temp, $curr...you think rvolt or wvolt?...you think rtemp or wtemp? you think wcurrent or rcharge or maybe pwel current? I will implement function to webpage for all photon users to see, maybe some guys see something other that we not see!

Yes, I know I have to use the brain for this:), but I came home from work so I am a little tired

voltage going up if temperature going up