Permalink
Browse files

drivers/onewire/ds18x20: Fix negative temperature calc for DS18B20.

  • Loading branch information...
1 parent 044f96c commit b2611d6be305c94359f67df875786858e05c3eb0 @syndycat syndycat committed with dpgeorge Jan 7, 2017
Showing with 4 additions and 1 deletion.
  1. +4 −1 drivers/onewire/ds18x20.py
@@ -93,6 +93,9 @@ def convert_temp(self, rom0, data):
temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c
return temp
elif rom0 == 0x28:
- return (temp_msb << 8 | temp_lsb) / 16
+ temp = (temp_msb << 8 | temp_lsb) / 16
+ if (temp_msb & 0xf8) == 0xf8: # for negative temperature
+ temp -= 0x1000
+ return temp
else:
assert False

0 comments on commit b2611d6

Please sign in to comment.