From: Gerhard Sittig Date: Sun, 27 May 2018 07:35:25 +0000 (+0200) Subject: counter: use local variables instead of instance variables X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=821a21418cb64f77f444c440752ac09a8bc97fb6;p=libsigrokdecode.git counter: use local variables instead of instance variables Since values get accessed within the .decode() method exclusively, we need not store data in instance variables of the decoder object. Use another variable for the "reset edge" option as well for consistency. --- diff --git a/decoders/counter/pd.py b/decoders/counter/pd.py index 384f978..4b5085b 100644 --- a/decoders/counter/pd.py +++ b/decoders/counter/pd.py @@ -74,31 +74,32 @@ 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 + data_edge = self.options['data_edge'] + divider = self.options['divider'] + if divider < 0: + divider = 0 + reset_edge = self.options['reset_edge'] - condition = [{PIN_DATA: opt_edge_map[self.edge]}] - self.have_reset = self.has_channel(PIN_RESET) - if self.have_reset: + condition = [{PIN_DATA: opt_edge_map[data_edge]}] + have_reset = self.has_channel(PIN_RESET) + if have_reset: cond_reset = len(condition) - condition.append({PIN_RESET: opt_edge_map[self.options['reset_edge']]}) + condition.append({PIN_RESET: opt_edge_map[reset_edge]}) - self.edge_count = 0 - self.word_count = 0 + edge_count = 0 + word_count = 0 while True: self.wait(condition) - if self.have_reset and self.matched[cond_reset]: - self.edge_count = 0 - self.word_count = 0 + if have_reset and self.matched[cond_reset]: + edge_count = 0 + word_count = 0 self.putc(ROW_RESET, ['Word reset', 'Reset', 'Rst', 'R']) continue - self.edge_count += 1 - self.putc(ROW_EDGE, [str(self.edge_count)]) + edge_count += 1 + self.putc(ROW_EDGE, [str(edge_count)]) - if self.divider > 0 and (self.edge_count % self.divider) == 0: - self.word_count += 1 - self.putc(ROW_WORD, [str(self.word_count)]) + if divider and (edge_count % divider) == 0: + word_count += 1 + self.putc(ROW_WORD, [str(word_count)])