summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-07-22 19:55:07 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-07-22 20:21:55 +0200
commit50207d809ae7181e6bb96f1611b599a1f78d27c5 (patch)
treed5a5ee766364bd92614610748971afe8e3487922 /decoders
parent499bf266989634a02e33e5361a720f853934fe03 (diff)
downloadlibsigrokdecode-50207d809ae7181e6bb96f1611b599a1f78d27c5.tar.gz
libsigrokdecode-50207d809ae7181e6bb96f1611b599a1f78d27c5.zip
ir_sirc: reduce smarts to improve maintenance (.wait() API change)
Eliminate redundancy in time to snum conversions and vice versa. Don't locally overload .wait() with unexpected semantics and neither change its parameters nor return values. Give reviewers and maintainers a chance to see what's happening when they inspect call sites. The 'signals' identifier is unusual for pin states, use the more common 'pins' instead for consistency with other decoders. Reflect when return values are not used, so that readers need to juggle fewer details in their head.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/ir_sirc/pd.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/decoders/ir_sirc/pd.py b/decoders/ir_sirc/pd.py
index d73c57b..10e5f6f 100644
--- a/decoders/ir_sirc/pd.py
+++ b/decoders/ir_sirc/pd.py
@@ -78,36 +78,37 @@ class Decoder(srd.Decoder):
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
+ self.snum_per_us = self.samplerate / 1e6
def putg(self, ss, es, cls, texts):
self.put(ss, es, self.out_ann, [cls, texts])
def tolerance(self, ss, es, expected):
- microseconds = 1000000 * (es - ss) / self.samplerate
+ microseconds = (es - ss) / self.snum_per_us
tolerance = expected * 0.30
return (expected - tolerance) < microseconds < (expected + tolerance)
- def wait(self, *conds, timeout=None):
+ def wait_wrap(self, conds, timeout=None):
conds = list(conds)
if timeout is not None:
- to = int(self.samplerate * timeout / 1000000)
+ to = int(timeout * self.snum_per_us)
conds.append({'skip': to})
ss = self.samplenum
- signals = super(Decoder, self).wait(conds)
+ pins = self.wait(conds)
es = self.samplenum
- return signals, ss, es, self.matched
+ return pins, ss, es, self.matched
def read_pulse(self, high, time):
e = 'f' if high else 'r'
max_time = int(time * 1.30)
- signals, ss, es, (edge, timeout) = self.wait({0: e}, timeout=max_time)
+ pins, ss, es, (edge, timeout) = self.wait_wrap([{0: e}], max_time)
if timeout or not self.tolerance(ss, es, time):
raise SIRCError('Timeout')
- return signals, ss, es, (edge, timeout)
+ return pins, ss, es, (edge, timeout)
def read_bit(self):
e = 'f' if self.active else 'r'
- signals, high_ss, high_es, (edge, timeout) = self.wait({0: e}, timeout=2000)
+ _, high_ss, high_es, (edge, timeout) = self.wait_wrap([{0: e}], 2000)
if timeout:
raise SIRCError('Bit High Timeout')
if self.tolerance(high_ss, high_es, 1200):
@@ -117,10 +118,10 @@ class Decoder(srd.Decoder):
else:
raise SIRCError('Bit Low Timeout')
try:
- signals, low_ss, low_es, matched = self.read_pulse(not self.active, 600)
+ _, low_ss, low_es, matched = self.read_pulse(not self.active, 600)
good = True
except SIRCError:
- low_es = high_es + int(600 * self.samplerate / 1000000)
+ low_es = high_es + int(600 * self.snum_per_us)
good = False
self.putg(high_ss, low_es, 0, ['{}'.format(bit)])
return bit, high_ss, low_es, good
@@ -128,8 +129,8 @@ class Decoder(srd.Decoder):
def read_signal(self):
# Start code
try:
- signals, agc_ss, agc_es, matched = self.read_pulse(self.active, 2400)
- signals, pause_ss, pause_es, matched = self.read_pulse(not self.active, 600)
+ _, agc_ss, agc_es, matched = self.read_pulse(self.active, 2400)
+ _, pause_ss, pause_es, matched = self.read_pulse(not self.active, 600)
except SIRCError:
raise SIRCErrorSilent('not an SIRC message')
self.putg(agc_ss, agc_es, 1, ['AGC', 'A'])
@@ -188,7 +189,7 @@ class Decoder(srd.Decoder):
while True:
e = 'h' if self.active else 'l'
- signal, ss, es, matched = self.wait({0: e})
+ signal, ss, es, matched = self.wait_wrap([{0: e}], None)
try:
address, command, extended, payload_ss, payload_es = self.read_signal()
names, commands = ADDRESSES.get((address, extended), (['Unknown Device: ', 'UNK: '], {}))