X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fam230x%2Fpd.py;h=2b54cde928f09b3a8f2fdb8257142aa2c5f405c0;hb=41bab68212533f4697ad378af574e06ea83e4fd9;hp=5375ab2bf5b1fb299518a69cf0c7856d38fcf870;hpb=ed758f091ebb31380868041da87812d3e4ea4a94;p=libsigrokdecode.git diff --git a/decoders/am230x/pd.py b/decoders/am230x/pd.py index 5375ab2..2b54cde 100644 --- a/decoders/am230x/pd.py +++ b/decoders/am230x/pd.py @@ -37,9 +37,9 @@ class SamplerateError(Exception): class Decoder(srd.Decoder): api_version = 2 id = 'am230x' - name = 'AM230x/DHTxx' - longname = 'Aosong AM230x/DHTxx' - desc = 'Aosong AM230x/DHTxx humidity/temperature sensor protocol.' + name = 'AM230x/DHTxx/RHTxx' + longname = 'Aosong AM230x/DHTxx/RHTxx' + desc = 'Aosong AM230x/DHTxx/RHTxx humidity/temperature sensor protocol.' license = 'gplv2+' inputs = ['logic'] outputs = ['am230x'] @@ -48,7 +48,7 @@ class Decoder(srd.Decoder): ) options = ( {'id': 'device', 'desc': 'Device type', - 'default': 'am230x', 'values': ('am230x', 'dht11')}, + 'default': 'am230x', 'values': ('am230x/rht', 'dht11')}, ) annotations = ( ('start', 'Start'), @@ -141,6 +141,29 @@ class Decoder(srd.Decoder): for t in timing[e]: self.cnt[e][t] = timing[e][t] * self.samplerate / 1000000 + def handle_byte(self, bit): + self.bits.append(bit) + self.putfs([2, ['Bit: %d' % bit, '%d' % bit]]) + self.fall = self.samplenum + self.state = 'WAIT FOR BIT HIGH' + if len(self.bits) % 8 == 0: + byte = self.bits2num(self.bits[-8:]) + self.putb([4, ['Byte: %#04x' % byte, '%#04x' % byte]]) + if len(self.bits) == 16: + h = self.calculate_humidity(self.bits[-16:]) + self.putv([5, ['Humidity: %.1f %%' % h, 'RH = %.1f %%' % h]]) + elif len(self.bits) == 32: + t = self.calculate_temperature(self.bits[-16:]) + self.putv([6, ['Temperature: %.1f °C' % t, 'T = %.1f °C' % t]]) + elif len(self.bits) == 40: + parity = self.bits2num(self.bits[-8:]) + if parity == self.calculate_checksum(self.bits[0:32]): + self.putb([7, ['Checksum: OK', 'OK']]) + else: + self.putb([7, ['Checksum: not OK', 'NOK']]) + self.state = 'WAIT FOR END' + self.bytepos.append(self.samplenum) + def decode(self, ss, es, data): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') @@ -204,27 +227,7 @@ class Decoder(srd.Decoder): else: self.reset() continue - self.bits.append(bit) - self.putfs([2, ['Bit: %d' % bit, '%d' % bit]]) - self.fall = self.samplenum - self.state = 'WAIT FOR BIT HIGH' - if len(self.bits) % 8 == 0: - byte = self.bits2num(self.bits[-8:]) - self.putb([4, ['Byte: %#04x' % byte, '%#04x' % byte]]) - if len(self.bits) == 16: - h = self.calculate_humidity(self.bits[-16:]) - self.putv([5, ['Humidity: %.1f %%' % h, 'RH = %.1f %%' % h]]) - elif len(self.bits) == 32: - t = self.calculate_temperature(self.bits[-16:]) - self.putv([6, ['Temperature: %.1f °C' % t, 'T = %.1f °C' % t]]) - elif len(self.bits) == 40: - parity = self.bits2num(self.bits[-8:]) - if parity == self.calculate_checksum(self.bits[0:32]): - self.putb([7, ['Checksum: OK', 'OK']]) - else: - self.putb([7, ['Checksum: not OK', 'NOK']]) - self.state = 'WAIT FOR END' - self.bytepos.append(self.samplenum) + self.handle_byte(bit) elif self.state == 'WAIT FOR END': if sda != 1: continue