aboutsummaryrefslogtreecommitdiff
path: root/drivers/onewire/ds18x20.py
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/onewire/ds18x20.py')
-rw-r--r--drivers/onewire/ds18x20.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/onewire/ds18x20.py b/drivers/onewire/ds18x20.py
index 272642239..ad2d9f52c 100644
--- a/drivers/onewire/ds18x20.py
+++ b/drivers/onewire/ds18x20.py
@@ -4,8 +4,9 @@
from micropython import const
_CONVERT = const(0x44)
-_RD_SCRATCH = const(0xbe)
-_WR_SCRATCH = const(0x4e)
+_RD_SCRATCH = const(0xBE)
+_WR_SCRATCH = const(0x4E)
+
class DS18X20:
def __init__(self, onewire):
@@ -26,7 +27,7 @@ class DS18X20:
self.ow.writebyte(_RD_SCRATCH)
self.ow.readinto(self.buf)
if self.ow.crc8(self.buf):
- raise Exception('CRC error')
+ raise Exception("CRC error")
return self.buf
def write_scratch(self, rom, buf):
@@ -40,12 +41,12 @@ class DS18X20:
if rom[0] == 0x10:
if buf[1]:
t = buf[0] >> 1 | 0x80
- t = -((~t + 1) & 0xff)
+ t = -((~t + 1) & 0xFF)
else:
t = buf[0] >> 1
return t - 0.25 + (buf[7] - buf[6]) / buf[7]
else:
t = buf[1] << 8 | buf[0]
- if t & 0x8000: # sign bit set
- t = -((t ^ 0xffff) + 1)
+ if t & 0x8000: # sign bit set
+ t = -((t ^ 0xFFFF) + 1)
return t / 16