]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/am230x/pd.py
swd: Drop unnecessary debug code.
[libsigrokdecode.git] / decoders / am230x / pd.py
index 05489d9ebb876c4bb9b3ceb5dbc67d14cc37bbeb..5375ab2bf5b1fb299518a69cf0c7856d38fcf870 100644 (file)
@@ -24,8 +24,8 @@ import sigrokdecode as srd
 timing = {
     'START LOW'     : {'min': 750, 'max': 25000},
     'START HIGH'    : {'min': 10, 'max': 10000},
-    'RESPONSE LOW'  : {'min': 70, 'max': 90},
-    'RESPONSE HIGH' : {'min': 70, 'max': 90},
+    'RESPONSE LOW'  : {'min': 50, 'max': 90},
+    'RESPONSE HIGH' : {'min': 50, 'max': 90},
     'BIT LOW'       : {'min': 45, 'max': 90},
     'BIT 0 HIGH'    : {'min': 20, 'max': 35},
     'BIT 1 HIGH'    : {'min': 65, 'max': 80},
@@ -37,9 +37,9 @@ class SamplerateError(Exception):
 class Decoder(srd.Decoder):
     api_version = 2
     id = 'am230x'
-    name = 'AM230x'
-    longname = 'AM230x humidity and temperature sensors'
-    desc = 'Proprietary single wire communication bus.'
+    name = 'AM230x/DHTxx'
+    longname = 'Aosong AM230x/DHTxx'
+    desc = 'Aosong AM230x/DHTxx humidity/temperature sensor protocol.'
     license = 'gplv2+'
     inputs = ['logic']
     outputs = ['am230x']
@@ -47,8 +47,8 @@ class Decoder(srd.Decoder):
         {'id': 'sda', 'name': 'SDA', 'desc': 'Single wire serial data line'},
     )
     options = (
-        {'id': 'dht11', 'desc': 'DHT11 compatibility mode',
-            'default': 'no', 'values': ('no', 'yes')},
+        {'id': 'device', 'desc': 'Device type',
+            'default': 'am230x', 'values': ('am230x', 'dht11')},
     )
     annotations = (
         ('start', 'Start'),
@@ -95,13 +95,13 @@ class Decoder(srd.Decoder):
 
     def bits2num(self, bitlist):
         number = 0
-        for i in range(0, len(bitlist)):
-            number += bitlist[-1-i] * 2**i
+        for i in range(len(bitlist)):
+            number += bitlist[-1 - i] * 2**i
         return number
 
     def calculate_humidity(self, bitlist):
         h = 0
-        if self.options['dht11'] == 'yes':
+        if self.options['device'] == 'dht11':
             h = self.bits2num(bitlist[0:8])
         else:
             h = self.bits2num(bitlist) / 10
@@ -109,7 +109,7 @@ class Decoder(srd.Decoder):
 
     def calculate_temperature(self, bitlist):
         t = 0
-        if self.options['dht11'] == 'yes':
+        if self.options['device'] == 'dht11':
             t = self.bits2num(bitlist[0:8])
         else:
             t = self.bits2num(bitlist[1:]) / 10
@@ -119,7 +119,7 @@ class Decoder(srd.Decoder):
 
     def calculate_checksum(self, bitlist):
         checksum = 0
-        for i in range(8, len(bitlist)+1, 8):
+        for i in range(8, len(bitlist) + 1, 8):
             checksum += self.bits2num(bitlist[i-8:i])
         return checksum % 256
 
@@ -185,7 +185,7 @@ class Decoder(srd.Decoder):
                     self.bytepos.append(self.samplenum)
                     self.state = 'WAIT FOR BIT HIGH'
                 else:
-                    self.reset_variables()
+                    self.reset()
             elif self.state == 'WAIT FOR BIT HIGH':
                 if sda != 1:
                     continue