]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/graycode/pd.py
decoders: Various cosmetic/consistency/typo fixes.
[libsigrokdecode.git] / decoders / graycode / pd.py
index 2edc8373c61993ed016e2b20b8ae05bf12dd1cc0..63014a29dd6366aa44db9221bef11c749ca07751 100644 (file)
 import math
 import sigrokdecode as srd
 from collections import deque
-
-def bitpack(bits):
-    res = 0
-    for i, b in enumerate(bits):
-        res |= b << i
-    return res
-
-def bitunpack(num, minbits=0):
-    res = []
-    while num or minbits > 0:
-        res.append(num & 1)
-        num >>= 1
-        minbits -= 1
-    return tuple(res)
+from common.srdhelper import bitpack, bitunpack
 
 def gray_encode(plain):
     return plain & (plain >> 1)
@@ -90,10 +77,11 @@ class Decoder(srd.Decoder):
     id = 'graycode'
     name = 'Gray code'
     longname = 'Gray code and rotary encoder'
-    desc = 'Accumulate rotary encoder increments, provide timing statistics.'
+    desc = 'Accumulate rotary encoder increments, provide statistics.'
     license = 'gplv2+'
     inputs = ['logic']
     outputs = ['graycode']
+    tags = ['Encoding']
     optional_channels = tuple(
         {'id': 'd{}'.format(i), 'name': 'D{}'.format(i), 'desc': 'Data line {}'.format(i)}
         for i in range(MAX_CHANNELS)
@@ -114,6 +102,9 @@ class Decoder(srd.Decoder):
     annotation_rows = tuple((u, v, (i,)) for i, (u, v) in enumerate(annotations))
 
     def __init__(self):
+        self.reset()
+
+    def reset(self):
         self.num_channels = 0
         self.samplerate = None
         self.last_n = deque()
@@ -185,7 +176,7 @@ class Decoder(srd.Decoder):
             if self.options['edges']:
                 self.turns.set(self.samplenum, self.count.get() // self.options['edges'])
 
-            if self.samplerate is not None:
+            if self.samplerate:
                 period = (curtime - prevtime) / self.samplerate
                 freq = abs(phasedelta_raw) / period