]> sigrok.org Git - libsigrokdecode.git/commitdiff
ir_nec: only use the samplerate after receiving the value
authorGerhard Sittig <redacted>
Sat, 25 Jul 2020 15:51:07 +0000 (17:51 +0200)
committerGerhard Sittig <redacted>
Sat, 25 Jul 2020 21:16:01 +0000 (23:16 +0200)
The metadata() method unconditionally referenced the samplerate even
though the value is only available conditionally. Move the references to
a location after the samplerate presence check.

decoders/ir_nec/pd.py

index 2e547d5a793b5978e069fee99b6c5cd905da0acc..07323a74aff3f97d2fe021aa5f05f463ace38336 100644 (file)
@@ -133,6 +133,8 @@ class Decoder(srd.Decoder):
     def metadata(self, key, value):
         if key == srd.SRD_CONF_SAMPLERATE:
             self.samplerate = value
+
+    def calc_rate(self):
         self.tolerance = 0.05 # +/-5%
         self.lc = int(self.samplerate * 0.0135) - 1 # 13.5ms
         self.rc = int(self.samplerate * 0.01125) - 1 # 11.25ms
@@ -177,6 +179,7 @@ class Decoder(srd.Decoder):
     def decode(self):
         if not self.samplerate:
             raise SamplerateError('Cannot decode without samplerate.')
+        self.calc_rate()
 
         cd_count = None
         if self.options['cd_freq']: