8000 drivers/onewire/ds18x20: Fix negative temperature calc for DS18B20. · pcurry/circuitpython@b2611d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2611d6

Browse files
syndycatdpgeorge
authored andcommitted
drivers/onewire/ds18x20: Fix negative temperature calc for DS18B20.
1 parent 044f96c commit b2611d6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/onewire/ds18x20.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def convert_temp(self, rom0, data):
9393
temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c
9494
return temp
9595
elif rom0 == 0x28:
96-
return (temp_msb << 8 | temp_lsb) / 16
96+
temp = (temp_msb << 8 | temp_lsb) / 16
97+
if (temp_msb & 0xf8) == 0xf8: # for negative temperature
98+
temp -= 0x1000
99+
return temp
97100
else:
98101
assert False

0 commit comments

Comments
 (0)
0