+class Sample():
+ def __init__(self, data):
+ self.data = data
+ def probe(self, probe):
+ s = ord(self.data[probe / 8]) & (1 << (probe % 8))
+ return True if s else False
+
+def sampleiter(data, unitsize):
+ for i in range(0, len(data), unitsize):
+ yield(Sample(data[i:i+unitsize]))
+
+class Decoder():
+ name = 'Transition counter'
+ longname = '...'
+ desc = 'Counts rising/falling edges in the signal.'
+ longdesc = '...'
+ author = 'Uwe Hermann'
+ email = 'uwe@hermann-uwe.de'
+ license = 'gplv2+'
+ inputs = ['logic']
+ outputs = ['transitioncounts']
+ probes = {}
+ options = {}
+
+ def __init__(self, unitsize, **kwargs):
+ # Metadata comes in here, we don't care for now.
+ # print kwargs
+ self.unitsize = unitsize
+
+ self.probes = Decoder.probes.copy()
+
+ # TODO: Don't hardcode the number of channels.
+ self.channels = 8
+
+ self.lastsample = None
+ self.oldbit = [0] * self.channels
+ self.transitions = [0] * self.channels
+ self.rising = [0] * self.channels
+ self.falling = [0] * self.channels
+
+ def report(self):
+ pass
+
+ def decode(self, data):
+ """Counts the low->high and high->low transitions in the specified
+ channel(s) of the signal."""