X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fgraycode%2Fpd.py;h=f3d45abcc0d0f544a28b0125c7aacd381ddac45b;hb=a06cb140e726217a8fbc1c0a98d6f46a8d3fd193;hp=2edc8373c61993ed016e2b20b8ae05bf12dd1cc0;hpb=b9b63977498f2114cf41d9039223481cbcaf3a45;p=libsigrokdecode.git diff --git a/decoders/graycode/pd.py b/decoders/graycode/pd.py index 2edc837..f3d45ab 100644 --- a/decoders/graycode/pd.py +++ b/decoders/graycode/pd.py @@ -20,20 +20,7 @@ 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'] + outputs = [] + tags = ['Encoding'] optional_channels = tuple( {'id': 'd{}'.format(i), 'name': 'D{}'.format(i), 'desc': 'Data line {}'.format(i)} for i in range(MAX_CHANNELS) @@ -106,14 +94,17 @@ class Decoder(srd.Decoder): ('phase', 'Phase'), ('increment', 'Increment'), ('count', 'Count'), - ('turns', 'Turns'), + ('turn', 'Turn'), ('interval', 'Interval'), ('average', 'Average'), ('rpm', 'Rate'), ) - annotation_rows = tuple((u, v, (i,)) for i, (u, v) in enumerate(annotations)) + annotation_rows = tuple((u + 's', v + 's', (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