diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 19:02:18 +0200 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 20:36:15 +0200 |
commit | b213c0461126495175aaa36fba85f50606594e39 (patch) | |
tree | b40acb9c5067c04232bec42b1d223807ecce4989 | |
parent | b3fafeb4e192a1496fb6a36460ac940992d618a0 (diff) | |
download | libsigrokdecode-b213c0461126495175aaa36fba85f50606594e39.tar.gz libsigrokdecode-b213c0461126495175aaa36fba85f50606594e39.zip |
caliper: refactor and unobfuscate timeout handling
Move math expressions with always identical values out of the loop, and
improve readability of the packet timeout condition in the process.
-rw-r--r-- | decoders/caliper/pd.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/decoders/caliper/pd.py b/decoders/caliper/pd.py index 6d07a87..404e830 100644 --- a/decoders/caliper/pd.py +++ b/decoders/caliper/pd.py @@ -82,12 +82,14 @@ class Decoder(srd.Decoder): timeout_ms = self.options['timeout_ms'] want_unit = self.options['unit'] show_all = self.options['changes'] == 'no' + snum_per_ms = self.samplerate / 1000 + timeout_snum = timeout_ms * snum_per_ms while True: - clk, data = self.wait([{0: 'r'}, {'skip': round(self.samplerate / 1000)}]) + clk, data = self.wait([{0: 'r'}, {'skip': round(snum_per_ms)}]) # Timeout after inactivity. if timeout_ms > 0: - if self.samplenum > self.es_cmd + (self.samplerate / (1000 / timeout_ms)): + if self.samplenum > self.es_cmd + timeout_snum: if self.bits > 0: self.putg(self.ss_cmd, self.samplenum, 1, [ 'timeout with %s bits in buffer' % (self.bits), |