X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fir_nec%2Fpd.py;h=bb52420fc19baf4662c74e5f720735f1bed7d503;hb=d4364948d0356f0659e1777cf771ed5bfc1f2072;hp=84b2e70a6ef77b85d97d9ad3a5134073f7735560;hpb=82ea183f48d9263ca802bb794ed0d099550ba6c8;p=libsigrokdecode.git diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py index 84b2e70..bb52420 100644 --- a/decoders/ir_nec/pd.py +++ b/decoders/ir_nec/pd.py @@ -31,13 +31,15 @@ class Decoder(srd.Decoder): desc = 'NEC infrared remote control protocol.' license = 'gplv2+' inputs = ['logic'] - outputs = ['ir_nec'] + outputs = [] + tags = ['IR'] channels = ( {'id': 'ir', 'name': 'IR', 'desc': 'Data line'}, ) options = ( {'id': 'polarity', 'desc': 'Polarity', 'default': 'active-low', 'values': ('active-low', 'active-high')}, + {'id': 'cd_freq', 'desc': 'Carrier Frequency', 'default': 0}, ) annotations = ( ('bit', 'Bit'), @@ -99,6 +101,9 @@ class Decoder(srd.Decoder): '%s' % btn[1]]]) def __init__(self): + self.reset() + + def reset(self): self.state = 'IDLE' self.ss_bit = self.ss_start = self.ss_other_edge = self.ss_remote = 0 self.data = self.count = self.active = None @@ -155,9 +160,36 @@ class Decoder(srd.Decoder): def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') + + cd_count = None + if self.options['cd_freq']: + cd_count = int(self.samplerate / self.options['cd_freq']) + 1 + prev_ir = None + while True: - # Wait for any edge (rising or falling). - (self.ir,) = self.wait({0: 'e'}) + # Detect changes in the presence of an active input signal. + # The decoder can either be fed an already filtered RX signal + # or optionally can detect the presence of a carrier. Periods + # of inactivity (signal changes slower than the carrier freq, + # if specified) pass on the most recently sampled level. This + # approach works for filtered and unfiltered input alike, and + # only slightly extends the active phase of input signals with + # carriers included by one period of the carrier frequency. + # IR based communication protocols can cope with this slight + # inaccuracy just fine by design. Enabling carrier detection + # on already filtered signals will keep the length of their + # active period, but will shift their signal changes by one + # carrier period before they get passed to decoding logic. + if cd_count: + (cur_ir,) = self.wait([{0: 'e'}, {'skip': cd_count}]) + if self.matched[0]: + cur_ir = self.active + if cur_ir == prev_ir: + continue + prev_ir = cur_ir + self.ir = cur_ir + else: + (self.ir,) = self.wait({0: 'e'}) if self.ir != self.active: # Save the non-active edge, then wait for the next edge.