fix error in 1-wire data conversion for DS18B20

This commit is contained in:
eddyem 2016-04-21 08:46:20 +03:00
parent 4979163d6f
commit 39ce6c651b
2 changed files with 6 additions and 4 deletions

Binary file not shown.

View File

@ -387,10 +387,12 @@ int32_t gettemp(uint8_t *scratchpad){
}else{ // DS18B20
v = l>>4 | ((m & 7)<<4) | (m & 0x80);
t = ((int32_t)v) * 10L;
m = l & 0x0f; // add decimal
t += (int32_t)m; // t = v*10 + l*1.25 -> convert
if(m > 1) ++t; // 1->1, 2->3, 3->4, 4->5, 5->6
else if(m > 5) t += 2L; // 6->8, 7->9
m = (l & 0x0f) >> 1; // add decimal
// 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 ->
// 0 1 1 2 3 3 4 4 5 6 6 7 8 8 9 9
t += (int32_t)m; // t = v*10 + l*0.625 -> convert
if(m) ++t; // 1->1, 2->3, 3->4, 4->5, 5->6
if(m > 5) ++t; // 6->8, 7->9
}
return t;
}