summaryrefslogtreecommitdiff
path: root/decoders/timing/pd.py
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-07-03 10:54:34 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-07-07 22:50:46 +0200
commit6a1b97e6b19f96d3f8df2f92c8d2dd82c1ecc3bb (patch)
tree969ad1359fd4d75aeca2cea28c33f4c9de98196d /decoders/timing/pd.py
parent6d073960f77a0abe397b86c636eead4622eb7563 (diff)
downloadlibsigrokdecode-6a1b97e6b19f96d3f8df2f92c8d2dd82c1ecc3bb.tar.gz
libsigrokdecode-6a1b97e6b19f96d3f8df2f92c8d2dd82c1ecc3bb.zip
timing: eliminate magic numbers, remove unused variables
Use symbolic identifiers for pin numbers and annotation classes. Remove unused variables.
Diffstat (limited to 'decoders/timing/pd.py')
-rw-r--r--decoders/timing/pd.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/decoders/timing/pd.py b/decoders/timing/pd.py
index 3c70eca..03d19e6 100644
--- a/decoders/timing/pd.py
+++ b/decoders/timing/pd.py
@@ -45,6 +45,12 @@ def normalize_time(t):
else:
return '%f' % t
+class Pin:
+ (DATA,) = range(1)
+
+class Ann:
+ (TIME, AVG, DELTA,) = range(3)
+
class Decoder(srd.Decoder):
api_version = 3
id = 'timing'
@@ -64,9 +70,9 @@ class Decoder(srd.Decoder):
('delta', 'Delta'),
)
annotation_rows = (
- ('times', 'Times', (0,)),
- ('averages', 'Averages', (1,)),
- ('deltas', 'Deltas', (2,)),
+ ('times', 'Times', (Ann.TIME,)),
+ ('averages', 'Averages', (Ann.AVG,)),
+ ('deltas', 'Deltas', (Ann.DELTA,)),
)
options = (
{ 'id': 'avg_period', 'desc': 'Averaging period', 'default': 100 },
@@ -81,8 +87,6 @@ class Decoder(srd.Decoder):
self.samplerate = None
self.last_samplenum = None
self.last_n = deque()
- self.chunks = 0
- self.level_changed = False
self.last_t = None
def metadata(self, key, value):
@@ -98,11 +102,11 @@ class Decoder(srd.Decoder):
raise SamplerateError('Cannot decode without samplerate.')
while True:
if self.edge == 'rising':
- pin = self.wait({0: 'r'})
+ pin = self.wait({Pin.DATA: 'r'})
elif self.edge == 'falling':
- pin = self.wait({0: 'f'})
+ pin = self.wait({Pin.DATA: 'f'})
else:
- pin = self.wait({0: 'e'})
+ pin = self.wait({Pin.DATA: 'e'})
if not self.last_samplenum:
self.last_samplenum = self.samplenum
@@ -116,13 +120,13 @@ class Decoder(srd.Decoder):
self.last_n.popleft()
self.put(self.last_samplenum, self.samplenum, self.out_ann,
- [0, [normalize_time(t)]])
+ [Ann.TIME, [normalize_time(t)]])
if self.options['avg_period'] > 0:
self.put(self.last_samplenum, self.samplenum, self.out_ann,
- [1, [normalize_time(sum(self.last_n) / len(self.last_n))]])
+ [Ann.AVG, [normalize_time(sum(self.last_n) / len(self.last_n))]])
if self.last_t and self.options['delta'] == 'yes':
self.put(self.last_samplenum, self.samplenum, self.out_ann,
- [2, [normalize_time(t - self.last_t)]])
+ [Ann.DELTA, [normalize_time(t - self.last_t)]])
self.last_t = t
self.last_samplenum = self.samplenum