diff options
| author | Damien George <damien.p.george@gmail.com> | 2020-02-27 15:36:53 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2020-02-28 10:33:03 +1100 |
| commit | 69661f3343bedf86e514337cff63d96cc42f8859 (patch) | |
| tree | af5dfb380ffdb75dda84828f63cf9d840d992f0f /drivers/dht/dht.py | |
| parent | 3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff) | |
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'drivers/dht/dht.py')
| -rw-r--r-- | drivers/dht/dht.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/dht/dht.py b/drivers/dht/dht.py index eed61df7c..1163b382b 100644 --- a/drivers/dht/dht.py +++ b/drivers/dht/dht.py @@ -6,6 +6,7 @@ try: except: from pyb import dht_readinto + class DHTBase: def __init__(self, pin): self.pin = pin @@ -14,9 +15,10 @@ class DHTBase: def measure(self): buf = self.buf dht_readinto(self.pin, buf) - if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]: + if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF != buf[4]: raise Exception("checksum error") + class DHT11(DHTBase): def humidity(self): return self.buf[0] @@ -24,12 +26,13 @@ class DHT11(DHTBase): def temperature(self): return self.buf[2] + class DHT22(DHTBase): def humidity(self): return (self.buf[0] << 8 | self.buf[1]) * 0.1 def temperature(self): - t = ((self.buf[2] & 0x7f) << 8 | self.buf[3]) * 0.1 + t = ((self.buf[2] & 0x7F) << 8 | self.buf[3]) * 0.1 if self.buf[2] & 0x80: t = -t return t |
