summaryrefslogtreecommitdiff
path: root/decoders/timing/pd.py
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-07-03 12:33:28 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-07-07 22:50:46 +0200
commit74c9c926a8936b6e7b781639908d1016e2088307 (patch)
treed07ce3744ddf17443691cf8f6dfac1793c54df91 /decoders/timing/pd.py
parent7e09e39c756c17ff783405ac13e0d3fa211fe8e7 (diff)
downloadlibsigrokdecode-74c9c926a8936b6e7b781639908d1016e2088307.tar.gz
libsigrokdecode-74c9c926a8936b6e7b781639908d1016e2088307.zip
timing: only queue when averaging, rephrase put calls
Reduce the amount of work which the timing decoder needs to do. Only keep the deque() filled when averaging is active. Rephrase .put() calls to reduce text line lengths (and for consistency with a pending change). Move another options lookup for deltas out of the main loop.
Diffstat (limited to 'decoders/timing/pd.py')
-rw-r--r--decoders/timing/pd.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/decoders/timing/pd.py b/decoders/timing/pd.py
index 071c990..1295477 100644
--- a/decoders/timing/pd.py
+++ b/decoders/timing/pd.py
@@ -115,6 +115,7 @@ class Decoder(srd.Decoder):
raise SamplerateError('Cannot decode without samplerate.')
edge = self.options['edge']
avg_period = self.options['avg_period']
+ delta = self.options['delta'] == 'yes'
terse = self.options['terse'] == 'yes'
ss = None
last_n = deque()
@@ -134,21 +135,23 @@ class Decoder(srd.Decoder):
samples = es - ss
t = samples / self.samplerate
- if t > 0:
- last_n.append(t)
- if len(last_n) > avg_period:
- last_n.popleft()
-
if terse:
- self.put(ss, es, self.out_ann, [Ann.TERSE, terse_times(t)])
+ cls, txt = Ann.TERSE, terse_times(t)
+ self.put(ss, es, self.out_ann, [cls, txt])
else:
- self.put(ss, es, self.out_ann, [Ann.TIME, [normalize_time(t)]])
+ cls, txt = Ann.TIME, [normalize_time(t)]
+ self.put(ss, es, self.out_ann, [cls, txt])
if avg_period > 0:
- self.put(ss, es, self.out_ann,
- [Ann.AVG, [normalize_time(sum(last_n) / len(last_n))]])
- if last_t and self.options['delta'] == 'yes':
- self.put(ss, es, self.out_ann,
- [Ann.DELTA, [normalize_time(t - last_t)]])
+ if t > 0:
+ last_n.append(t)
+ if len(last_n) > avg_period:
+ last_n.popleft()
+ average = sum(last_n) / len(last_n)
+ cls, txt = Ann.AVG, normalize_time(average)
+ self.put(ss, es, self.out_ann, [cls, [txt]])
+ if last_t and delta:
+ cls, txt = Ann.DELTA, normalize_time(t - last_t)
+ self.put(ss, es, self.out_ann, [cls, [txt]])
last_t = t
ss = es