counter: explicit option text to .wait() edge mapping
authorGerhard Sittig <gerhard.sittig@gmx.net>
Sun, 27 May 2018 07:06:48 +0000 (09:06 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Tue, 29 May 2018 21:57:48 +0000 (23:57 +0200)
The previous implementation used the fact that libsigrok's internal API
happens to use the first letter of the user visible English option text.
Two locations mapped edge choices to API literals in different ways.
Unify them, introduce an explicit option text to literal value mapping.

(Many if not all decoder implementations do that. More adjustment to use
common code could be beneficial.)

decoders/counter/pd.py

index cbb6a5f7f2bf09dfe7d0b306e0d417727bdbdf33..6dd8d918549dfe69a9117360f7410b262b5e9e72 100644 (file)
@@ -75,13 +75,13 @@ class Decoder(srd.Decoder):
         self.put(self.samplenum, self.samplenum, self.out_ann, [cls, annlist])
 
     def decode(self):
-        condition = [{'rising':  {0: 'r'},
-                      'falling': {0: 'f'},
-                      'any':     {0: 'e'},}[self.edge]]
+        opt_edge_map = {'rising': 'r', 'falling': 'f', 'any': 'e'}
+
+        condition = [{0: opt_edge_map[self.edge]}]
 
         if self.has_channel(1):
             self.have_reset = True
-            condition.append({1: self.options['reset_edge'][0]})
+            condition.append({1: opt_edge_map[self.options['reset_edge']]})
 
         while True:
             self.wait(condition)