summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2018-05-27 09:35:25 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2018-05-29 23:57:48 +0200
commit821a21418cb64f77f444c440752ac09a8bc97fb6 (patch)
treeb7687b28320acf81a0c1a8fcb64ca870d9c87d5d
parentdeabbb70a8c29116a116c0833b2da39def0b807b (diff)
downloadlibsigrokdecode-821a21418cb64f77f444c440752ac09a8bc97fb6.tar.gz
libsigrokdecode-821a21418cb64f77f444c440752ac09a8bc97fb6.zip
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.
-rw-r--r--decoders/counter/pd.py37
1 files changed, 19 insertions, 18 deletions
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)])