diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-17 23:04:34 +0200 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 15:48:50 +0200 |
commit | 8c3291c74998bddac4b355d2ffbaf94e22bad3a7 (patch) | |
tree | 4bfaac9d36777cddd650d963c7be40f741037171 /decoders | |
parent | e8e8bec61ce9b855c078e2ca1de55f648af5204a (diff) | |
download | libsigrokdecode-8c3291c74998bddac4b355d2ffbaf94e22bad3a7.tar.gz libsigrokdecode-8c3291c74998bddac4b355d2ffbaf94e22bad3a7.zip |
ir_irmp: add support for button "release" flag
Recent upstream IRMP core versions introduced a "release" flag in
addition to the "repeat" flag. Prepare the decoder to present these
flags when libraries should pass them in results.
The flags' being orthogonal slightly complicates the logic which
constructs annotation texts. Do provide text variants for all previously
supported zoom levels, yet try to keep the implementation as simple as
possible: Match list lengths for simplified folding. Always print the
flags field even if none of the flags is active (kind of was done before
this change as well, just not visible). This approach easily accepts
more flags as needed in future versions.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/ir_irmp/irmp_library.py | 2 | ||||
-rw-r--r-- | decoders/ir_irmp/pd.py | 38 |
2 files changed, 33 insertions, 7 deletions
diff --git a/decoders/ir_irmp/irmp_library.py b/decoders/ir_irmp/irmp_library.py index 22a74b0..d542a1d 100644 --- a/decoders/ir_irmp/irmp_library.py +++ b/decoders/ir_irmp/irmp_library.py @@ -41,6 +41,7 @@ class IrmpLibrary: ] FLAG_REPETITION = 1 << 0 + FLAG_RELEASE = 1 << 1 def _library_filename(self): ''' @@ -103,6 +104,7 @@ class IrmpLibrary: 'address': self._data.address, 'command': self._data.command, 'repeat': bool(self._data.flags & self.FLAG_REPETITION), + 'release': bool(self._data.flags & self.FLAG_RELEASE), 'start': self._data.start_sample, 'end': self._data.end_sample, } diff --git a/decoders/ir_irmp/pd.py b/decoders/ir_irmp/pd.py index ef3da4d..cb69fd0 100644 --- a/decoders/ir_irmp/pd.py +++ b/decoders/ir_irmp/pd.py @@ -49,21 +49,45 @@ class Decoder(srd.Decoder): ) def putframe(self, data): + '''Emit annotation for an IR frame.''' + + # Cache result data fields in local variables. Get the ss/es + # timestamps, scaled to sample numbers. nr = data['proto_nr'] name = data['proto_name'] addr = data['address'] cmd = data['command'] repeat = data['repeat'] - rep = ['repeat', 'rep', 'r'] if repeat else ['', '', ''] + release = data['release'] ss = data['start'] * self.rate_factor es = data['end'] * self.rate_factor - self.put(ss, es, self.out_ann, [0, [ - 'Protocol: {nr} ({name}), Address 0x{addr:04x}, Command: 0x{cmd:04x} {rep[0]}'.format(**locals()), - 'P: {name} ({nr}), Addr: 0x{addr:x}, Cmd: 0x{cmd:x} {rep[1]}'.format(**locals()), - 'P: {nr} A: 0x{addr:x} C: 0x{cmd:x} {rep[1]}'.format(**locals()), - 'C:{cmd:x} A:{addr:x} {rep[2]}'.format(**locals()), + + # Prepare display texts for several zoom levels. + # Implementor's note: Keep list lengths for flags aligned during + # maintenance. Make sure there are as many flags text variants + # as are referenced by annotation text variants. Differing list + # lengths or dynamic refs will severely complicate the logic. + rep_txts = ['repeat', 'rep', 'r'] + rel_txts = ['release', 'rel', 'R'] + flag_txts = [None,] * len(rep_txts) + for zoom in range(len(flag_txts)): + flag_txts[zoom] = [] + if repeat: + flag_txts[zoom].append(rep_txts[zoom]) + if release: + flag_txts[zoom].append(rel_txts[zoom]) + flag_txts = [' '.join(t) or '-' for t in flag_txts] + flg = flag_txts # Short name for .format() references. + txts = [ + 'Protocol: {name} ({nr}), Address 0x{addr:04x}, Command: 0x{cmd:04x}, Flags: {flg[0]}'.format(**locals()), + 'P: {name} ({nr}), Addr: 0x{addr:x}, Cmd: 0x{cmd:x}, Flg: {flg[1]}'.format(**locals()), + 'P: {nr} A: 0x{addr:x} C: 0x{cmd:x} F: {flg[1]}'.format(**locals()), + 'C:{cmd:x} A:{addr:x} {flg[2]}'.format(**locals()), 'C:{cmd:x}'.format(**locals()), - ]]) + ] + + # Emit the annotation from details which were constructed above. + self.put(ss, es, self.out_ann, [0, txts]) def __init__(self): self.irmp = irmp_library.IrmpLibrary() |