devmem2 0x00b01300 w 0x00000050 &> /dev/null
devmem2 0x00b01320 w 0x00000050 &> /dev/null

#Polynomials from TRM
a4='-0.0000000000092627'
a3='0.000000060373'
a2='-0.00017058'
a1='0.32512'
a0='-49.002'

temp1=$(devmem2 0x00b00308)
temp2=$(devmem2 0x00b00328)

temp1=${temp1##* } #Get last byte of devmem read
temp2=${temp2##* } #Get last byte of devmem read

temp1=${temp1:2} #Remove Hex Notation
temp2=${temp2:2} #Remove Hex Notation


temp1=$(echo "obase=2; ibase=16; $temp1" | bc | tail -c 11) #Convert to Binary and get last 10 bits
temp1=$(echo "obase=10; ibase=2; $temp1" | bc) #Convert to Dec
temp1=$(echo "(($a4 * ($temp1^4)) + ($a3 *($temp1^3)) + ($a2*($temp1^2)) + ($a1 * $temp1) + $a0)" | bc)

temp2=$(echo "obase=2; ibase=16; $temp2" | bc | tail -c 11) #Convert to Binary and get last 10 bits
temp2=$(echo "obase=10; ibase=2; $temp2" | bc) #Convert to Dec
temp2=$(echo "(($a4 * ($temp2^4)) + ($a3 *($temp2^3)) + ($a2*($temp2^2)) + ($a1 * $temp2) + $a0)" | bc)

avgTemp=$(echo "($temp1 + $temp2) / 2.00000" | bc -l) #Average Values



echo "T1: ${temp1:0:6} C"
echo "T2: ${temp2:0:6} C"
echo "Average: ${avgTemp:0:6} C"
