diff options
Diffstat (limited to 'decoders/ir_irmp/pd.py')
-rw-r--r-- | decoders/ir_irmp/pd.py | 38 |
1 files changed, 31 insertions, 7 deletions
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() |