]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/nunchuk.py
srd: Drop useless out_ann/out_proto init.
[libsigrokdecode.git] / decoders / nunchuk.py
index 635a7143a4159b33542b3013c94ef83630e066a6..86ec17111750dcf6ed2483317f6237f54abfa1a1 100644 (file)
@@ -30,7 +30,7 @@
 # https://www.sparkfun.com/products/9281
 #
 
-import sigrok
+import sigrokdecode as srd
 
 # States
 IDLE = 0
@@ -62,18 +62,7 @@ example_packets = [
     {'type': 'P',  'range': (32, 33), 'data': None, 'ann': ''},
 ]
 
-class Sample():
-    def __init__(self, data):
-        self.data = data
-    def probe(self, probe):
-        s = ord(self.data[probe / 8]) & (1 << (probe % 8))
-        return True if s else False
-
-def sampleiter(data, unitsize):
-    for i in range(0, len(data), unitsize):
-        yield(Sample(data[i:i+unitsize]))
-
-class Decoder(sigrok.Decoder):
+class Decoder(srd.Decoder):
     id = 'nunchuk'
     name = 'Nunchuk'
     longname = 'Nintendo Wii Nunchuk decoder'
@@ -84,15 +73,10 @@ class Decoder(sigrok.Decoder):
     license = 'gplv2+'
     inputs = ['i2c']
     outputs = ['nunchuck']
-    probes = {}
+    probes = [] # TODO
     options = {}
 
     def __init__(self, **kwargs):
-        self.probes = Decoder.probes.copy()
-
-        # TODO: Don't hardcode the number of channels.
-        self.channels = 8
-
         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
@@ -100,20 +84,18 @@ class Decoder(sigrok.Decoder):
         self.databytecount = 0
 
     def start(self, metadata):
-        self.unitsize = metadata['unitsize']
+        # self.out_proto = self.add(srd.SRD_OUTPUT_PROTO, 'nunchuk')
+        self.out_ann = self.add(srd.SRD_OUTPUT_ANN, 'nunchuk')
 
     def report(self):
         pass
 
-    def decode(self, data):
-        """Nintendo Wii Nunchuk decoder"""
-
+    def decode(self, timeoffset, duration, data):
         out = []
         o = {}
 
         # We should accept a list of samples and iterate...
-        # for sample in sampleiter(data['data'], self.unitsize):
-        for p in example_packets:
+        for p in example_packets: # TODO
 
             # TODO: Eliminate the need for ord().
             # s = ord(sample.data)
@@ -186,5 +168,7 @@ class Decoder(sigrok.Decoder):
                 self.state = INITIALIZED
                 self.databytecount = 0
 
-        self.put(out)
+        if out != []:
+            # self.put(0, 0, self.out_proto, out_proto)
+            self.put(0, 0, self.out_ann, out)