]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/i2c.py
srd: Remove decode() docstrings.
[libsigrokdecode.git] / decoders / i2c.py
index 9ff89c9755993c797fc54ee9e34f475c92a525e0..cf16d3a28dc0ab86937a170bedba6a22e404e583 100644 (file)
@@ -148,7 +148,7 @@ class Sample():
     def __init__(self, data):
         self.data = data
     def probe(self, probe):
-        s = ord(self.data[probe / 8]) & (1 << (probe % 8))
+        s = self.data[probe / 8] & (1 << (probe % 8))
         return True if s else False
 
 def sampleiter(data, unitsize):
@@ -313,11 +313,24 @@ class Decoder(sigrok.Decoder):
         self.is_repeat_start = 0
         self.wr = -1
 
-    def decode(self, data):
-        """I2C protocol decoder"""
+    def put(self, output_id, data):
+        timeoffset = self.timeoffset + ((self.samplenum - self.bitcount) * self.period)
+        if self.bitcount > 0:
+            duration = self.bitcount * self.period
+        else:
+            duration = self.period
+        print("**", timeoffset, duration)
+        super(Decoder, self).put(timeoffset, duration, output_id, data)
+
+    def decode(self, timeoffset, duration, data):
+        self.timeoffset = timeoffset
+        self.duration = duration
+        print("++", timeoffset, duration, len(data))
+        # duration of one bit in ps, only valid for this call to decode()
+        self.period = int(duration / len(data))
 
         # We should accept a list of samples and iterate...
-        for sample in sampleiter(data['data'], self.unitsize):
+        for sample in sampleiter(data, self.unitsize):
 
             # TODO: Eliminate the need for ord().
             s = ord(sample.data)