diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2018-05-27 09:27:08 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2018-05-29 23:57:48 +0200 |
commit | deabbb70a8c29116a116c0833b2da39def0b807b (patch) | |
tree | a904cd8745a3b0d780643e052e1e7b8a4e726647 /decoders/counter | |
parent | f2120b9ef962c3b0054705393767efd4fb08e06c (diff) | |
download | libsigrokdecode-deabbb70a8c29116a116c0833b2da39def0b807b.tar.gz libsigrokdecode-deabbb70a8c29116a116c0833b2da39def0b807b.zip |
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.
Diffstat (limited to 'decoders/counter')
-rw-r--r-- | decoders/counter/pd.py | 15 |
1 files changed, 8 insertions, 7 deletions
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) |