Skip to content

Commit e5f0655

Browse files
ernitrondpgeorge
authored andcommitted
esp8266/modules: Fix negative temperature in ds18x20 driver.
1 parent 10bde69 commit e5f0655

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

esp8266/modules/ds18x20.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ def read_temp(self, rom):
4343
t = buf[0] >> 1
4444
return t - 0.25 + (buf[7] - buf[6]) / buf[7]
4545
else:
46-
return (buf[1] << 8 | buf[0]) / 16
46+
t = buf[1] << 8 | buf[0]
47+
if t & 0x8000: # sign bit set
48+
t = -((t ^ 0xffff) + 1)
49+
return t / 16

0 commit comments

Comments
 (0)