diff options
author | ernitron <ernitron@gmail.com> | 2016-10-31 10:54:44 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-11-02 22:58:49 +1100 |
commit | e5f06559e6762b00e36a66901ba092676cd8e019 (patch) | |
tree | e3429f3acabbc2a4d0cbf7bd953a38a1d82a4f2d /esp8266/modules/ds18x20.py | |
parent | 10bde6933e45289eeb8b0a564b088fadc4309c17 (diff) | |
download | micropython-e5f06559e6762b00e36a66901ba092676cd8e019.tar.gz micropython-e5f06559e6762b00e36a66901ba092676cd8e019.zip |
esp8266/modules: Fix negative temperature in ds18x20 driver.
Diffstat (limited to 'esp8266/modules/ds18x20.py')
-rw-r--r-- | esp8266/modules/ds18x20.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/esp8266/modules/ds18x20.py b/esp8266/modules/ds18x20.py index eb22e2ae30..fc53048f8e 100644 --- a/esp8266/modules/ds18x20.py +++ b/esp8266/modules/ds18x20.py @@ -43,4 +43,7 @@ class DS18X20: t = buf[0] >> 1 return t - 0.25 + (buf[7] - buf[6]) / buf[7] else: - return (buf[1] << 8 | buf[0]) / 16 + t = buf[1] << 8 | buf[0] + if t & 0x8000: # sign bit set + t = -((t ^ 0xffff) + 1) + return t / 16 |