X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fnunchuk%2Fnunchuk.py;h=b91e3ea51b56e40e2c2063876f1713bb9a8bb71e;hp=0e5e7420843745311e7c86a482e6188b42845cab;hb=2b7160383cc189f721600c04be17a980e216dfd6;hpb=1b75abfdd3e00ef590c9d1905863f6f2cb5a8632 diff --git a/decoders/nunchuk/nunchuk.py b/decoders/nunchuk/nunchuk.py index 0e5e742..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' @@ -47,7 +40,7 @@ class Decoder(srd.Decoder): ] 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 @@ -63,7 +56,7 @@ class Decoder(srd.Decoder): 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