X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fnunchuk.py;h=635a7143a4159b33542b3013c94ef83630e066a6;hp=d3a76c93f3c613afe8a7a6d11dce91d93f156147;hb=bffd9bc09c76aa2189f89e76fd4a0aa314418193;hpb=012cfd0d620a42165e964c9443bbcde1e4d24b6d diff --git a/decoders/nunchuk.py b/decoders/nunchuk.py index d3a76c9..635a714 100644 --- a/decoders/nunchuk.py +++ b/decoders/nunchuk.py @@ -22,7 +22,22 @@ # Nintendo Wii Nunchuk decoder # +# # TODO: Description +# +# http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck +# http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/ +# https://www.sparkfun.com/products/9281 +# + +import sigrok + +# States +IDLE = 0 +START = 1 +NUNCHUK_SLAVE = 2 +INIT = 3 +INITIALIZED = 4 # FIXME: This is just some example input for testing purposes... example_packets = [ @@ -58,7 +73,8 @@ def sampleiter(data, unitsize): for i in range(0, len(data), unitsize): yield(Sample(data[i:i+unitsize])) -class Decoder(): +class Decoder(sigrok.Decoder): + id = 'nunchuk' name = 'Nunchuk' longname = 'Nintendo Wii Nunchuk decoder' desc = 'Decodes the Nintendo Wii Nunchuk I2C-based protocol.' @@ -77,10 +93,7 @@ class Decoder(): # TODO: Don't hardcode the number of channels. self.channels = 8 - self.IDLE, self.START, self.NUNCHUK_SLAVE, self.INIT, \ - self.INITIALIZED = range(5) - - self.state = self.IDLE # TODO: Can we assume a certain initial state? + 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 @@ -106,7 +119,7 @@ class Decoder(): # s = ord(sample.data) if p['type'] == 'S': # TODO: Handle 'Sr' here, too? - self.state = self.START + self.state = START elif p['type'] == 'Sr': pass # FIXME @@ -123,7 +136,7 @@ class Decoder(): else: pass # TODO: What to do here? Ignore? Error? - elif p['type'] == 'DR' and self.state == self.INITIALIZED: + elif p['type'] == 'DR' and self.state == INITIALIZED: if self.databytecount == 0: self.sx = p['data'] elif self.databytecount == 1: @@ -154,26 +167,24 @@ class Decoder(): # TODO: If 6 bytes read -> save and reset # TODO - elif p['type'] == 'DR' and self.state != self.INITIALIZED: + elif p['type'] == 'DR' and self.state != INITIALIZED: pass elif p['type'] == 'DW': - if p['data'] == 0x40 and self.state == self.START: - self.state = self.INIT - elif p['data'] == 0x00 and self.state == self.INIT: + if p['data'] == 0x40 and self.state == START: + self.state = INIT + elif p['data'] == 0x00 and self.state == INIT: o = {'type': 'I', 'range': (0, 0), 'data': []} o['data'] = [0x40, 0x00] out.append(o) - self.state = self.INITIALIZED + self.state = INITIALIZED else: pass # TODO elif p['type'] == 'P': out.append(o) - self.state = self.INITIALIZED + self.state = INITIALIZED self.databytecount = 0 - sigrok.put(out) - -import sigrok + self.put(out)