summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-08-12 20:03:06 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-08-12 20:19:06 +0200
commit65c6eed857b94c4ab8712c5ca4926d463529c4ff (patch)
treec819576dd08219f8fe8ab6326778bc3081803adb /decoders
parent82639220d4ca1d0eb24768f2d857b8f8183795fa (diff)
downloadlibsigrokdecode-65c6eed857b94c4ab8712c5ca4926d463529c4ff.tar.gz
libsigrokdecode-65c6eed857b94c4ab8712c5ca4926d463529c4ff.zip
sdq: use symbolic names for pins and annotation classes
Eliminate magic numbers which are too hard to read and too easy to get wrong during maintenance. Prefer symbolic identifiers instead for pins and annotation classes.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/sdq/pd.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/decoders/sdq/pd.py b/decoders/sdq/pd.py
index c65faa8..d37458d 100644
--- a/decoders/sdq/pd.py
+++ b/decoders/sdq/pd.py
@@ -23,6 +23,12 @@ import sigrokdecode as srd
class SamplerateError(Exception):
pass
+class Pin:
+ SDQ, = range(1)
+
+class Ann:
+ BIT, BYTE, BREAK, = range(3)
+
class Decoder(srd.Decoder):
api_version = 3
id = 'sdq'
@@ -45,9 +51,9 @@ class Decoder(srd.Decoder):
('break', 'Break'),
)
annotation_rows = (
- ('bits', 'Bits', (0,)),
- ('bytes', 'Bytes', (1,)),
- ('breaks', 'Breaks', (2,)),
+ ('bits', 'Bits', (Ann.BIT,)),
+ ('bytes', 'Bytes', (Ann.BYTE,)),
+ ('breaks', 'Breaks', (Ann.BREAK,)),
)
def puts(self, data):
@@ -77,16 +83,16 @@ class Decoder(srd.Decoder):
def handle_bit(self, bit):
self.bits.append(bit)
- self.putetu([0, ['Bit: %d' % bit, '%d' % bit]])
+ self.putetu([Ann.BIT, ['Bit: %d' % bit, '%d' % bit]])
if len(self.bits) == 8:
byte = bitpack(self.bits)
- self.putbetu([1, ['Byte: %#04x' % byte, '%#04x' % byte]])
+ self.putbetu([Ann.BYTE, ['Byte: %#04x' % byte, '%#04x' % byte]])
self.bits = []
self.bytepos = 0
def handle_break(self):
- self.puts([2, ['Break', 'BR']])
+ self.puts([Ann.BREAK, ['Break', 'BR']])
self.bits = []
self.startsample = self.samplenum
self.bytepos = 0
@@ -100,14 +106,14 @@ class Decoder(srd.Decoder):
break_threshold = self.bit_width * 1.2
# Wait until the line is high before inspecting input data.
- sdq, = self.wait({0: 'h'})
+ sdq, = self.wait({Pin.SDQ: 'h'})
while True:
# Get the length of a low pulse (falling to rising edge).
- sdq, = self.wait({0: 'f'})
+ sdq, = self.wait({Pin.SDQ: 'f'})
self.startsample = self.samplenum
if self.bytepos == 0:
self.bytepos = self.samplenum
- sdq, = self.wait({0: 'r'})
+ sdq, = self.wait({Pin.SDQ: 'r'})
# Check for 0 or 1 data bits, or the BREAK symbol.
delta = self.samplenum - self.startsample