]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/onewire_link/pd.py
uart/i2cfilter: Don't check multiple-choice options.
[libsigrokdecode.git] / decoders / onewire_link / pd.py
index 9503d15b93fb7c80eca3144b1728652fb3db857c..c8d6cd75406d7dbc3c045113e226dd703bc7c10c 100644 (file)
@@ -20,6 +20,9 @@
 
 import sigrokdecode as srd
 
+class SamplerateError(Exception):
+    pass
+
 class Decoder(srd.Decoder):
     api_version = 2
     id = 'onewire_link'
@@ -185,8 +188,8 @@ class Decoder(srd.Decoder):
                  % (time_min*1000000, time_max*1000000)]])
 
     def decode(self, ss, es, data):
-        if self.samplerate is None:
-            raise Exception("Cannot decode without samplerate.")
+        if not self.samplerate:
+            raise SamplerateError('Cannot decode without samplerate.')
         for (self.samplenum, (owr, pwr)) in data:
             # State machine.
             if self.state == 'WAIT FOR FALLING EDGE':
@@ -251,10 +254,10 @@ class Decoder(srd.Decoder):
                     # Save the sample number for the rising edge.
                     self.rise = self.samplenum
                     self.putfr([2, ['Reset', 'Rst', 'R']])
-                    self.state = "WAIT FOR PRESENCE DETECT"
+                    self.state = 'WAIT FOR PRESENCE DETECT'
                 # Otherwise this is assumed to be a data bit.
                 else:
-                    self.state = "WAIT FOR FALLING EDGE"
+                    self.state = 'WAIT FOR FALLING EDGE'
             elif self.state == 'WAIT FOR PRESENCE DETECT':
                 # Sample presence status.
                 t = self.samplenum - self.rise