From f9818294d09ba8b7dd3614357ce185f79c8c45a1 Mon Sep 17 00:00:00 2001 From: BenediktO Date: Mon, 27 Jul 2020 08:32:52 +0200 Subject: ir_nec: Make the tolerance configurable Provide an option to adjust the IR NEC decoder's tolerance. Which makes signals accessible that are generated by cheap remotes which would not decode at all with the previous implementation and its fixed limit. [ gsi: rephrased commit message and implementation ] --- decoders/ir_nec/pd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'decoders') diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py index 05c8c00..0d79865 100644 --- a/decoders/ir_nec/pd.py +++ b/decoders/ir_nec/pd.py @@ -48,6 +48,7 @@ class Decoder(srd.Decoder): options = ( {'id': 'polarity', 'desc': 'Polarity', 'default': 'active-low', 'values': ('active-low', 'active-high')}, + {'id': 'tolerance', 'desc': 'Timing tolerance (%)', 'default': 5}, {'id': 'cd_freq', 'desc': 'Carrier Frequency', 'default': 0}, {'id': 'extended', 'desc': 'Extended NEC Protocol', 'default': 'no', 'values': ('yes', 'no')}, @@ -136,7 +137,7 @@ class Decoder(srd.Decoder): self.samplerate = value def calc_rate(self): - self.tolerance = 0.05 # +/-5% + self.tolerance = self.options['tolerance'] / 100 # 5% by default self.lc = int(self.samplerate * 0.0135) - 1 # 13.5ms self.rc = int(self.samplerate * 0.01125) - 1 # 11.25ms self.dazero = int(self.samplerate * 0.001125) - 1 # 1.125ms -- cgit v1.2.3-70-g09d2