summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorsyndycat <syndycat@yahoo.com>2017-01-07 13:36:11 +0200
committerDamien George <damien.p.george@gmail.com>2017-01-08 19:26:22 +1100
commitb2611d6be305c94359f67df875786858e05c3eb0 (patch)
treee6555dd5867726a58db6f172308d9b3065598037
parent044f96c33010ae99cd5423358f4e41021423777b (diff)
downloadmicropython-b2611d6be305c94359f67df875786858e05c3eb0.tar.gz
micropython-b2611d6be305c94359f67df875786858e05c3eb0.zip
drivers/onewire/ds18x20: Fix negative temperature calc for DS18B20.
-rw-r--r--drivers/onewire/ds18x20.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/onewire/ds18x20.py b/drivers/onewire/ds18x20.py
index a2f7f5c3da..342f4b28ae 100644
--- a/drivers/onewire/ds18x20.py
+++ b/drivers/onewire/ds18x20.py
@@ -93,6 +93,9 @@ class DS18X20(object):
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