-# FIXME: This is just some example input for testing purposes...
-example_packets = [
- # START condition.
- {'type': 'S', 'range': (10, 11), 'data': None, 'ann': ''},
-
- # Nunchuk init: Write 0x40,0x00 to slave address 0x54.
- {'type': 'AW', 'range': (12, 13), 'data': 0x54, 'ann': ''},
- {'type': 'DW', 'range': (14, 15), 'data': 0x40, 'ann': ''},
- {'type': 'AW', 'range': (16, 17), 'data': 0x54, 'ann': ''},
- {'type': 'DW', 'range': (18, 19), 'data': 0x00, 'ann': ''},
-
- # Get data: Read 6 bytes of data.
- {'type': 'DR', 'range': (20, 21), 'data': 0x11, 'ann': ''},
- {'type': 'DR', 'range': (22, 23), 'data': 0x22, 'ann': ''},
- {'type': 'DR', 'range': (24, 25), 'data': 0x33, 'ann': ''},
- {'type': 'DR', 'range': (26, 27), 'data': 0x44, 'ann': ''},
- {'type': 'DR', 'range': (28, 29), 'data': 0x55, 'ann': ''},
- {'type': 'DR', 'range': (30, 31), 'data': 0x66, 'ann': ''},
-
- # STOP condition.
- {'type': 'P', 'range': (32, 33), 'data': None, 'ann': ''},
-]
-
-def decode(l):
- print(l)
- sigrok.put(l)
-
-
-def decode2(inbuf):
- """Nintendo Wii Nunchuk decoder"""
-
- # FIXME: Get the data in the correct format in the first place.
- inbuf = [ord(x) for x in inbuf]
- out = []
- o = {}
-
- # TODO: Pass in metadata.
-
- # States
- IDLE, START, NUNCHUK_SLAVE, INIT, INITIALIZED = range(5)
- state = IDLE # TODO: Can we assume a certain initial state?
-
- sx = sy = ax = ay = az = bz = bc = 0
-
- databytecount = 0
-
- # Loop over all I2C packets.
- for p in example_packets:
- if p['type'] == 'S': # TODO: Handle 'Sr' here, too?
- state = START
-
- elif p['type'] == 'Sr':
+import sigrokdecode as srd
+
+# States
+IDLE = 0
+START = 1
+NUNCHUK_SLAVE = 2
+INIT = 3
+INITIALIZED = 4
+
+class Decoder(srd.Decoder):
+ id = 'nunchuk'
+ name = 'Nunchuk'
+ longname = 'Nintendo Wii Nunchuk'
+ desc = 'Decodes the Nintendo Wii Nunchuk I2C-based protocol.'
+ longdesc = '...'
+ author = 'Uwe Hermann'
+ email = 'uwe@hermann-uwe.de'
+ license = 'gplv2+'
+ inputs = ['i2c']
+ outputs = ['nunchuck']
+ probes = [] # TODO
+ options = {}
+ annotations = [
+ ['TODO', 'TODO'],
+ ]
+
+ def __init__(self, **kwargs):
+ self.state = IDLE # TODO: Can we assume a certain initial state?
+ self.sx = self.sy = self.ax = self.ay = self.az = self.bz = self.bc = 0
+ self.databytecount = 0
+
+ def start(self, metadata):
+ # self.out_proto = self.add(srd.OUTPUT_PROTO, 'nunchuk')
+ self.out_ann = self.add(srd.OUTPUT_ANN, 'nunchuk')
+
+ def report(self):
+ pass
+
+ def decode(self, ss, es, data):
+
+ cmd, databyte, ack_bit = data
+
+ if cmd == 'START': # TODO: Handle 'Sr' here, too?
+ self.state = START
+
+ elif cmd == 'START REPEAT':