X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fnunchuk%2Fnunchuk.py;h=b91e3ea51b56e40e2c2063876f1713bb9a8bb71e;hp=f9019050439a359727e2b3c7bd754d818f0d4616;hb=2b7160383cc189f721600c04be17a980e216dfd6;hpb=156509ca42f0df2380c9f205f9aad337e1a07802 diff --git a/decoders/nunchuk/nunchuk.py b/decoders/nunchuk/nunchuk.py index f901905..b91e3ea 100644 --- a/decoders/nunchuk/nunchuk.py +++ b/decoders/nunchuk/nunchuk.py @@ -22,13 +22,6 @@ 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' @@ -43,11 +36,11 @@ class Decoder(srd.Decoder): optional_probes = [] # TODO options = {} annotations = [ - ['TODO', 'TODO'], + ['TODO', 'TODO'], ] 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 +53,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 +73,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 +107,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