summaryrefslogtreecommitdiff
path: root/decoders/counter
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2018-05-27 09:18:09 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2018-05-29 23:57:48 +0200
commitf2120b9ef962c3b0054705393767efd4fb08e06c (patch)
tree9716f893cc3dc8b9f16aa262defb84961b256941 /decoders/counter
parentd11290fef0450c4f9b1c0f14d7c203de6ee02695 (diff)
downloadlibsigrokdecode-f2120b9ef962c3b0054705393767efd4fb08e06c.tar.gz
libsigrokdecode-f2120b9ef962c3b0054705393767efd4fb08e06c.zip
counter: use symbolic names for input pins, wait conditions, annotation rows
Replace magic numbers by symbolic references to (fixed and optional) decoder input signals, .wait() conditions, as well as annotation rows. Move some empty lines, to better reflect which code lines form groups of similar activity ("blocks" that logically belong together).
Diffstat (limited to 'decoders/counter')
-rw-r--r--decoders/counter/pd.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/decoders/counter/pd.py b/decoders/counter/pd.py
index 6dd8d91..696c8e9 100644
--- a/decoders/counter/pd.py
+++ b/decoders/counter/pd.py
@@ -19,6 +19,9 @@
import sigrokdecode as srd
+(PIN_DATA, PIN_RESET) = range(2)
+(ROW_EDGE, ROW_WORD, ROW_RESET) = range(3)
+
class Decoder(srd.Decoder):
api_version = 3
id = 'counter'
@@ -40,9 +43,9 @@ class Decoder(srd.Decoder):
('word_reset', 'Word reset'),
)
annotation_rows = (
- ('edge_counts', 'Edges', (0,)),
- ('word_counts', 'Words', (1,)),
- ('word_resets', 'Word resets', (2,)),
+ ('edge_counts', 'Edges', (ROW_EDGE,)),
+ ('word_counts', 'Words', (ROW_WORD,)),
+ ('word_resets', 'Word resets', (ROW_RESET,)),
)
options = (
{'id': 'data_edge', 'desc': 'Edges to count (data)', 'default': 'any',
@@ -77,23 +80,24 @@ class Decoder(srd.Decoder):
def decode(self):
opt_edge_map = {'rising': 'r', 'falling': 'f', 'any': 'e'}
- condition = [{0: opt_edge_map[self.edge]}]
-
- if self.has_channel(1):
- self.have_reset = True
- condition.append({1: opt_edge_map[self.options['reset_edge']]})
+ condition = [{PIN_DATA: opt_edge_map[self.edge]}]
+ self.have_reset = self.has_channel(PIN_RESET)
+ if self.have_reset:
+ cond_reset = len(condition)
+ condition.append({PIN_RESET: opt_edge_map[self.options['reset_edge']]})
while True:
self.wait(condition)
- if self.have_reset and self.matched[1]:
+
+ if self.have_reset and self.matched[cond_reset]:
self.edge_count = 0
self.word_count = 0
- self.putc(2, ['Word reset', 'Reset', 'Rst', 'R'])
+ self.putc(ROW_RESET, ['Word reset', 'Reset', 'Rst', 'R'])
continue
self.edge_count += 1
+ self.putc(ROW_EDGE, [str(self.edge_count)])
- self.putc(0, [str(self.edge_count)])
if self.divider > 0 and (self.edge_count % self.divider) == 0:
self.word_count += 1
- self.putc(1, [str(self.word_count)])
+ self.putc(ROW_WORD, [str(self.word_count)])