]> sigrok.org Git - libsigrokdecode.git/commitdiff
counter: move some init code to the start of decode()
authorGerhard Sittig <redacted>
Sun, 27 May 2018 07:27:08 +0000 (09:27 +0200)
committerUwe Hermann <redacted>
Tue, 29 May 2018 21:57:48 +0000 (23:57 +0200)
Since PD API v3 the .decode() method is called exactly once, and
contains a main loop itself. Move initialization code that sets up
.decode() related logic to the start of the .decode() routine.

decoders/counter/pd.py

index 696c8e9f4ec1c82d32918c69d28fccc65737ced6..384f978f536b5af2ed3ee10eeb8a8bdc47b45f26 100644 (file)
@@ -59,9 +59,7 @@ class Decoder(srd.Decoder):
         self.reset()
 
     def reset(self):
-        self.edge_count = 0
-        self.word_count = 0
-        self.have_reset = None
+        pass
 
     def metadata(self, key, value):
         if key == srd.SRD_CONF_SAMPLERATE:
@@ -69,10 +67,6 @@ class Decoder(srd.Decoder):
 
     def start(self):
         self.out_ann = self.register(srd.OUTPUT_ANN)
-        self.edge = self.options['data_edge']
-        self.divider = self.options['divider']
-        if self.divider < 0:
-            self.divider = 0
 
     def putc(self, cls, annlist):
         self.put(self.samplenum, self.samplenum, self.out_ann, [cls, annlist])
@@ -80,12 +74,19 @@ class Decoder(srd.Decoder):
     def decode(self):
         opt_edge_map = {'rising': 'r', 'falling': 'f', 'any': 'e'}
 
+        self.edge = self.options['data_edge']
+        self.divider = self.options['divider']
+        if self.divider < 0:
+            self.divider = 0
+
         condition = [{PIN_DATA: opt_edge_map[self.edge]}]
         self.have_reset = self.has_channel(PIN_RESET)
         if self.have_reset:
             cond_reset = len(condition)
             condition.append({PIN_RESET: opt_edge_map[self.options['reset_edge']]})
 
+        self.edge_count = 0
+        self.word_count = 0
         while True:
             self.wait(condition)