X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fnunchuk%2Fnunchuk.py;h=0c4cf11277f7825320f33cda1fe87210a753100c;hp=cd6fa213cdaec5297dd9cf22c2ea86bfa96643e2;hb=ee3e279c7558b388410d16cbce9db6c80e9c0c67;hpb=e4f822680083b65e34b9c8b091025f66ea6efde6 diff --git a/decoders/nunchuk/nunchuk.py b/decoders/nunchuk/nunchuk.py index cd6fa21..0c4cf11 100644 --- a/decoders/nunchuk/nunchuk.py +++ b/decoders/nunchuk/nunchuk.py @@ -22,20 +22,12 @@ import sigrokdecode as srd -# States -IDLE = 0 -START = 1 -NUNCHUK_SLAVE = 2 -INIT = 3 -INITIALIZED = 4 - class Decoder(srd.Decoder): api_version = 1 id = 'nunchuk' name = 'Nunchuk' longname = 'Nintendo Wii Nunchuk' desc = 'Decodes the Nintendo Wii Nunchuk I2C-based protocol.' - longdesc = '...' license = 'gplv2+' inputs = ['i2c'] outputs = ['nunchuck'] @@ -43,11 +35,11 @@ class Decoder(srd.Decoder): optional_probes = [] # TODO options = {} annotations = [ - ['TODO', 'TODO'], + ['Text', 'Human-readable text'], ] def __init__(self, **kwargs): - self.state = 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 self.databytecount = 0 @@ -60,10 +52,10 @@ class Decoder(srd.Decoder): def decode(self, ss, es, data): - cmd, databyte, ack_bit = data + cmd, databyte = data if cmd == 'START': # TODO: Handle 'Sr' here, too? - self.state = START + self.state = 'START' elif cmd == 'START REPEAT': pass # FIXME @@ -80,7 +72,7 @@ class Decoder(srd.Decoder): else: pass # TODO: What to do here? Ignore? Error? - elif cmd == 'DATA READ' and self.state == INITIALIZED: + elif cmd == 'DATA READ' and self.state == 'INITIALIZED': if self.databytecount == 0: self.sx = databyte elif self.databytecount == 1: @@ -114,23 +106,23 @@ class Decoder(srd.Decoder): # TODO: If 6 bytes read -> save and reset # TODO - elif cmd == 'DATA READ' and self.state != INITIALIZED: + elif cmd == 'DATA READ' and self.state != 'INITIALIZED': pass elif cmd == 'DATA WRITE': - if self.state == IDLE: - self.state = INITIALIZED + if self.state == 'IDLE': + self.state = 'INITIALIZED' return - if databyte == 0x40 and self.state == START: - self.state = INIT - elif databyte == 0x00 and self.state == INIT: + if databyte == 0x40 and self.state == 'START': + self.state = 'INIT' + elif databyte == 0x00 and self.state == 'INIT': self.put(ss, es, self.out_ann, [0, ['Initialize nunchuk']]) - self.state = INITIALIZED + self.state = 'INITIALIZED' else: pass # TODO elif cmd == 'STOP': - self.state = INITIALIZED + self.state = 'INITIALIZED' self.databytecount = 0