]> sigrok.org Git - libsigrokdecode.git/blobdiff - scripts/transitioncounter.py
Fix compile for Python >= 3.0.
[libsigrokdecode.git] / scripts / transitioncounter.py
index c16ce46aacc67a90cb5c00bec11a66ba6416dbf5..a6d331e85fc1af676d87edbebdce96c28d343a0a 100644 (file)
@@ -18,7 +18,7 @@
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-def sigrokdecode_count_transitions(inbuf):
+def decode(inbuf):
        """Counts the low->high and high->low transitions in the specified
           channel(s) of the signal."""
 
@@ -35,10 +35,7 @@ def sigrokdecode_count_transitions(inbuf):
        rising = [0] * channels
        falling = [0] * channels
 
-       # print len(inbuf)
-       # print type(inbuf)
-
-       # Presets...
+       # Initial values.
        oldbyte = inbuf[0]
        for i in range(channels):
                oldbit[i] = (oldbyte & (1 << i)) >> i
@@ -59,6 +56,7 @@ def sigrokdecode_count_transitions(inbuf):
                        elif (oldbit[i] == 1 and curbit == 0):
                                falling[i] += 1
                        oldbit[i] = curbit
+               oldbyte = s
 
        # Total number of transitions is the sum of rising and falling edges.
        for i in range(channels):
@@ -77,10 +75,20 @@ def sigrokdecode_count_transitions(inbuf):
 
        return outbuf
 
+def register():
+       return {
+               'id': 'transitioncounter',
+               'name': 'Transition counter',
+               'desc': 'Count rising/falling edges',
+               'inputformats': ['raw'],
+               'signalnames': {}, # FIXME
+               'outputformats': ['transitioncounts'],
+       }
+
 # Use psyco (if available) as it results in huge performance improvements.
 try:
        import psyco
-       psyco.bind(sigrokdecode_count_transitions)
+       psyco.bind(decode)
 except ImportError:
        pass