2 ## This file is part of the sigrok project.
4 ## Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 def sigrokdecode_count_transitions(inbuf):
22 """Counts the low->high and high->low transitions in the specified
23 channel(s) of the signal."""
27 # TODO: Don't hardcode the number of channels.
30 oldbit = [0] * channels
31 transitions = [0] * channels
32 rising = [0] * channels
33 falling = [0] * channels
40 for i in xrange(channels):
41 curbit = (s & (1 << i) != 0)
44 # Loop over all samples.
45 # TODO: Handle LAs with more/less than 8 channels.
48 for i in xrange(channels):
49 curbit = (s & (1 << i) != 0)
50 if (oldbit[i] == 0 and curbit == 1):
52 elif (oldbit[i] == 1 and curbit == 0):
56 # Total number of transitions is the sum of rising and falling edges.
57 for i in xrange(channels):
58 transitions[i] = rising[i] + falling[i]
60 outbuf += "Rising edges: "
61 for i in xrange(channels):
62 outbuf += str(rising[i]) + " "
63 outbuf += "\nFalling edges: "
64 for i in xrange(channels):
65 outbuf += str(falling[i]) + " "
66 outbuf += "\nTransitions: "
67 for i in xrange(channels):
68 outbuf += str(transitions[i]) + " "
73 # Use psyco (if available) as it results in huge performance improvements.
76 psyco.bind(sigrokdecode_count_transitions)