X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fir_nec%2Fpd.py;h=05c8c006655797ccf03b323f6cb92660f4e61dda;hb=85f616edfa157ae6ed8ea9ea4a72b930816e4dc9;hp=c05e4744dc6a76c06f3007c2387040bcfa71a096;hpb=17e0ba228dadb7a12aa0e11fa81fcbc4a7836349;p=libsigrokdecode.git diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py index c05e474..05c8c00 100644 --- a/decoders/ir_nec/pd.py +++ b/decoders/ir_nec/pd.py @@ -142,6 +142,7 @@ class Decoder(srd.Decoder): self.dazero = int(self.samplerate * 0.001125) - 1 # 1.125ms self.daone = int(self.samplerate * 0.00225) - 1 # 2.25ms self.stop = int(self.samplerate * 0.000652) - 1 # 0.652ms + self.idle_to = int(self.samplerate * 0.020) - 1 # 20ms, arbitrary choice def compare_with_tolerance(self, measured, base): return (measured >= base * (1 - self.tolerance) @@ -179,11 +180,10 @@ class Decoder(srd.Decoder): self.data = [] self.ss_bit = self.ss_start = self.samplenum return True + self.putd(show, want_len) if check and not valid: warn_show = bitpack(self.data) self.putx([Ann.WARN, ['{} error: 0x{:04X}'.format(name, warn_show)]]) - else: - self.putd(show, want_len) self.data = [] self.ss_bit = self.ss_start = self.samplenum return valid @@ -228,21 +228,27 @@ class Decoder(srd.Decoder): (self.ir,) = self.wait({Pin.IR: 'e'}) if self.ir != active: - # Save the non-active edge, then wait for the next edge. + # Save the location of the non-active edge (recessive), + # then wait for the next edge. Immediately process the + # end of the STOP bit which completes an IR frame. self.ss_other_edge = self.samplenum - continue + if self.state != 'STOP': + continue - b = self.samplenum - self.ss_bit + # Reset internal state for long periods of idle level. + width = self.samplenum - self.ss_bit + if width >= self.idle_to and self.state != 'STOP': + self.reset() # State machine. if self.state == 'IDLE': - if self.compare_with_tolerance(b, self.lc): + if self.compare_with_tolerance(width, self.lc): self.putpause('Long') self.putx([Ann.LEADER_CODE, ['Leader code', 'Leader', 'LC', 'L']]) self.ss_remote = self.ss_start self.data = [] self.state = 'ADDRESS' - elif self.compare_with_tolerance(b, self.rc): + elif self.compare_with_tolerance(width, self.rc): self.putpause('Short') self.putstop(self.samplenum) self.samplenum += self.stop @@ -250,23 +256,25 @@ class Decoder(srd.Decoder): self.data = [] self.ss_bit = self.ss_start = self.samplenum elif self.state == 'ADDRESS': - self.handle_bit(b) + self.handle_bit(width) if len(self.data) == want_addr_len: self.data_ok(False, want_addr_len) self.state = 'COMMAND' if self.is_extended else 'ADDRESS#' elif self.state == 'ADDRESS#': - self.handle_bit(b) + self.handle_bit(width) if len(self.data) == 16: - self.state = 'COMMAND' if self.data_ok(True, 8) else 'IDLE' + self.data_ok(True, 8) + self.state = 'COMMAND' elif self.state == 'COMMAND': - self.handle_bit(b) + self.handle_bit(width) if len(self.data) == 8: self.data_ok(False, 8) self.state = 'COMMAND#' elif self.state == 'COMMAND#': - self.handle_bit(b) + self.handle_bit(width) if len(self.data) == 16: - self.state = 'STOP' if self.data_ok(True, 8) else 'IDLE' + self.data_ok(True, 8) + self.state = 'STOP' elif self.state == 'STOP': self.putstop(self.ss_bit) self.putremote()