summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2021-12-26 08:38:05 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2021-12-26 13:45:09 +0100
commit8c4477692114cfb1a823d847b70c8ea96caa7301 (patch)
treeff4c5965ff631addd5729e0ec4d68792e7d1a66b /decoders
parent7395d57b3c722229d18aa70fbee7e60a60902304 (diff)
downloadlibsigrokdecode-8c4477692114cfb1a823d847b70c8ea96caa7301.tar.gz
libsigrokdecode-8c4477692114cfb1a823d847b70c8ea96caa7301.zip
ir_irmp: sigrok PD, make use of IRMP decoder core locking
Rephrase how the external IRMP library gets loaded, to provide better diagnostics to users. All decoder instances are equal after the recent introduction of locking support. Move the "reset state" call for the IRMP decoder core to the .decode() method's main loop, where the context manager holds the instance lock. This allows "parallel" execution of multiple IRMP decoders in the same sigrok application, assuming that the context manager scope will be left at some point in time. This fixes bug #1581 when applications communicate EOF to decoders. Move some Python object members to local variables. They exclusively are used within the .decode() method. Update the copyright for the non-trivial changes.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/ir_irmp/pd.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/decoders/ir_irmp/pd.py b/decoders/ir_irmp/pd.py
index 979c1e0..b8df819 100644
--- a/decoders/ir_irmp/pd.py
+++ b/decoders/ir_irmp/pd.py
@@ -3,6 +3,7 @@
##
## Copyright (C) 2014 Gump Yang <gump.yang@gmail.com>
## Copyright (C) 2019 Rene Staffen
+## Copyright (C) 2020-2021 Gerhard Sittig <gerhard.sittig@gmx.net>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@@ -97,7 +98,7 @@ class Decoder(srd.Decoder):
self.reset()
def reset(self):
- self.want_reset = True
+ pass
def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
@@ -113,25 +114,26 @@ class Decoder(srd.Decoder):
except Exception as e:
txt = e.args[0]
raise LibraryError(txt)
- if self.irmp:
- self.lib_rate = self.irmp.get_sample_rate()
- if not self.irmp or not self.lib_rate:
- raise LibraryError('Cannot access IRMP library. One instance limit exceeded?')
+ if not self.irmp:
+ raise LibraryError('Cannot access IRMP library.')
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
- if self.samplerate % self.lib_rate:
- raise SamplerateError('Capture samplerate must be multiple of library samplerate ({})'.format(self.lib_rate))
- self.rate_factor = int(self.samplerate / self.lib_rate)
- if self.want_reset:
- self.irmp.reset_state()
- self.want_reset = False
+ lib_rate = self.irmp.get_sample_rate()
+ if not lib_rate:
+ raise LibraryError('Cannot determine IRMP library\'s samplerate.')
+ if self.samplerate % lib_rate:
+ raise SamplerateError('Capture samplerate must be multiple of library samplerate ({})'.format(lib_rate))
+
+ self.rate_factor = int(self.samplerate / lib_rate)
+ active = 0 if self.options['polarity'] == 'active-low' else 1
- self.active = 0 if self.options['polarity'] == 'active-low' else 1
ir, = self.wait()
- while True:
- if self.active == 1:
- ir = 1 - ir
- if self.irmp.add_one_sample(ir):
- data = self.irmp.get_result_data()
- self.putframe(data)
- ir, = self.wait([{'skip': self.rate_factor}])
+ with self.irmp:
+ self.irmp.reset_state()
+ while True:
+ if active == 1:
+ ir = 1 - ir
+ if self.irmp.add_one_sample(ir):
+ data = self.irmp.get_result_data()
+ self.putframe(data)
+ ir, = self.wait([{'skip': self.rate_factor}])