From: Gerhard Sittig Date: Fri, 30 Dec 2022 13:09:03 +0000 (+0100) Subject: adf435x: use common bits to number conversion helper X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=317eaa7fd83fb049db97e863a306992a34fcf490;p=libsigrokdecode.git adf435x: use common bits to number conversion helper Use common support code to convert bit fields to integer numbers. Also unobfuscate the decode_bits() method and its returned values' layout. Improves readability and factors out common expressions. --- diff --git a/decoders/adf435x/pd.py b/decoders/adf435x/pd.py index 9ba88ca..8c31648 100644 --- a/decoders/adf435x/pd.py +++ b/decoders/adf435x/pd.py @@ -18,6 +18,7 @@ ## import sigrokdecode as srd +from common.srdhelper import bitpack_lsb def disabled_enabled(v): return ['Disabled', 'Enabled'][v] @@ -118,8 +119,10 @@ class Decoder(srd.Decoder): self.out_ann = self.register(srd.OUTPUT_ANN) def decode_bits(self, offset, width): - return (sum([(1 << i) if self.bits[offset + i][0] else 0 for i in range(width)]), - (self.bits[offset + width - 1][1], self.bits[offset][2])) + bits = self.bits[offset:][:width] + ss, es = bits[-1][1], bits[0][2] + value = bitpack_lsb(bits, 0) + return ( value, ( ss, es, )) def decode_field(self, name, offset, width, parser): val, pos = self.decode_bits(offset, width)