]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/counter/pd.py
decoders: Various cosmetic/consistency/typo fixes.
[libsigrokdecode.git] / decoders / counter / pd.py
index b01b5e6273ff35a93de1a9d647485f09b66b40c8..f1134bd14f61cb3b6bba3049608992baf249bc89 100644 (file)
@@ -27,10 +27,11 @@ class Decoder(srd.Decoder):
     id = 'counter'
     name = 'Counter'
     longname = 'Edge counter'
-    desc = 'Count number of edges.'
+    desc = 'Count the number of edges in a signal.'
     license = 'gplv2+'
     inputs = ['logic']
     outputs = []
+    tags = ['Util']
     channels = (
         {'id': 'data', 'name': 'Data', 'desc': 'Data line'},
     )
@@ -55,6 +56,9 @@ class Decoder(srd.Decoder):
             'default': 'falling', 'values': ('rising', 'falling')},
         {'id': 'edge_off', 'desc': 'Edge counter value after start/reset', 'default': 0},
         {'id': 'word_off', 'desc': 'Word counter value after start/reset', 'default': 0},
+        {'id': 'dead_cycles', 'desc': 'Ignore this many edges after reset', 'default': 0},
+        {'id': 'start_with_reset', 'desc': 'Assume decode starts with reset',
+            'default': 'no', 'values': ('no', 'yes')},
     )
 
     def __init__(self):
@@ -92,6 +96,12 @@ class Decoder(srd.Decoder):
         edge_start = None
         word_count = int(self.options['word_off'])
         word_start = None
+
+        if self.options['start_with_reset'] == 'yes':
+            dead_count = int(self.options['dead_cycles'])
+        else:
+            dead_count = 0
+
         while True:
             self.wait(condition)
             now = self.samplenum
@@ -102,6 +112,13 @@ class Decoder(srd.Decoder):
                 word_count = int(self.options['word_off'])
                 word_start = now
                 self.putc(ROW_RESET, now, ['Word reset', 'Reset', 'Rst', 'R'])
+                dead_count = int(self.options['dead_cycles'])
+                continue
+
+            if dead_count:
+                dead_count -= 1
+                edge_start = now
+                word_start = now
                 continue
 
             # Implementation note: In the absence of a RESET condition
@@ -121,7 +138,8 @@ class Decoder(srd.Decoder):
             self.putc(ROW_EDGE, edge_start, ["{:d}".format(edge_count)])
             edge_start = now
 
-            if divider and (edge_count % divider) == 0:
+            word_edge_count = edge_count - int(self.options['edge_off'])
+            if divider and (word_edge_count % divider) == 0:
                 word_count += 1
                 self.putc(ROW_WORD, word_start, ["{:d}".format(word_count)])
                 word_start = now