From: Gerhard Sittig Date: Fri, 17 Jul 2020 21:04:34 +0000 (+0200) Subject: ir_irmp: add support for button "release" flag X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8c3291c74998bddac4b355d2ffbaf94e22bad3a7;p=libsigrokdecode.git 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. --- 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() diff --git a/irmp/irmp-main-sharedlib.h b/irmp/irmp-main-sharedlib.h index 05e7b53..94065f3 100644 --- a/irmp/irmp-main-sharedlib.h +++ b/irmp/irmp-main-sharedlib.h @@ -46,6 +46,7 @@ struct irmp_result_data { }; #define IRMP_DATA_FLAG_REPETITION (1 << 0) +#define IRMP_DATA_FLAG_RELEASE (1 << 1) /** * @brief Query the IRMP library's configured sample rate.