From: Gerhard Sittig Date: Sun, 27 May 2018 07:27:08 +0000 (+0200) Subject: counter: move some init code to the start of decode() X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=deabbb70a8c29116a116c0833b2da39def0b807b;p=libsigrokdecode.git counter: move some init code to the start of decode() 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. --- diff --git a/decoders/counter/pd.py b/decoders/counter/pd.py index 696c8e9..384f978 100644 --- a/decoders/counter/pd.py +++ b/decoders/counter/pd.py @@ -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)