##
'''
-This decoder handles the proprietary single wire communication protocol used by
-the AM230x series of digital humidity and temperature sensors.
+This decoder handles the proprietary single wire communication protocol used
+by the Aosong AM230x/DHTxx series of digital humidity and temperature sensors.
Sample rate:
-A sample rate of at least 200 kHz is recommended to properly detect all the
+A sample rate of at least 200kHz is recommended to properly detect all the
elements of the protocol.
Options:
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']
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):
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