summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/modules
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-08-29 12:45:07 +1000
committerDamien George <damien.p.george@gmail.com>2016-08-29 12:45:07 +1000
commit59a9509703c6e525b3419ffea1b69f3b6992e006 (patch)
tree5be15cb27d0924e6090326b1bae624a8df0381ef /esp8266/modules
parent8e9b98e974ff141ba78918021f3203f620d1de8a (diff)
downloadmicropython-59a9509703c6e525b3419ffea1b69f3b6992e006.tar.gz
micropython-59a9509703c6e525b3419ffea1b69f3b6992e006.zip
esp8266/modules/ds18x20.py: Add support for DS18S20 devices.
Diffstat (limited to 'esp8266/modules')
-rw-r--r--esp8266/modules/ds18x20.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/esp8266/modules/ds18x20.py b/esp8266/modules/ds18x20.py
index 9c5bb8eb6b..eb22e2ae30 100644
--- a/esp8266/modules/ds18x20.py
+++ b/esp8266/modules/ds18x20.py
@@ -11,7 +11,7 @@ class DS18X20:
self.buf = bytearray(9)
def scan(self):
- return [rom for rom in self.ow.scan() if rom[0] == 0x28]
+ return [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]
def convert_temp(self):
self.ow.reset(True)
@@ -35,4 +35,12 @@ class DS18X20:
def read_temp(self, rom):
buf = self.read_scratch(rom)
- return (buf[1] << 8 | buf[0]) / 16
+ if rom[0] == 0x10:
+ if buf[1]:
+ t = buf[0] >> 1 | 0x80
+ t = -((~t + 1) & 0xff)
+ else:
+ t = buf[0] >> 1
+ return t - 0.25 + (buf[7] - buf[6]) / buf[7]
+ else:
+ return (buf[1] << 8 | buf[0]) / 16