summaryrefslogtreecommitdiff
path: root/decoders/ir_nec
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2014-03-07 21:49:12 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2014-03-10 15:40:10 +0100
commit12fecc8ffc48a92ce1678aa9b4988f85bebe21a9 (patch)
tree8ac8dc50e2123c226ab60dbbd85c62cdaf957ab8 /decoders/ir_nec
parent5bb61a25d31c4c32f5109c38d7fd31c9e0d2c441 (diff)
downloadlibsigrokdecode-12fecc8ffc48a92ce1678aa9b4988f85bebe21a9.tar.gz
libsigrokdecode-12fecc8ffc48a92ce1678aa9b4988f85bebe21a9.zip
ir_nec: Add support for higher-level remote control annotations.
Diffstat (limited to 'decoders/ir_nec')
-rw-r--r--decoders/ir_nec/lists.py52
-rw-r--r--decoders/ir_nec/pd.py27
2 files changed, 76 insertions, 3 deletions
diff --git a/decoders/ir_nec/lists.py b/decoders/ir_nec/lists.py
new file mode 100644
index 0000000..c9dc595
--- /dev/null
+++ b/decoders/ir_nec/lists.py
@@ -0,0 +1,52 @@
+##
+## This file is part of the libsigrokdecode project.
+##
+## Copyright (C) 2014 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+
+# Addresses/devices. Items that are not listed are reserved/unknown.
+address = {
+ 0x40: 'Matsui TV',
+}
+
+digits = {
+ 0: ['0', '0'],
+ 1: ['1', '1'],
+ 2: ['2', '2'],
+ 3: ['3', '3'],
+ 4: ['4', '4'],
+ 5: ['5', '5'],
+ 6: ['6', '6'],
+ 7: ['7', '7'],
+ 8: ['8', '8'],
+ 9: ['9', '9'],
+}
+
+# Commands. Items that are not listed are reserved/unknown.
+command = {
+ 0x40: dict(list(digits.items()) + list({
+ 11: ['-/--', '-/--'],
+ 16: ['Mute', 'M'],
+ 18: ['Standby', 'StBy'],
+ 26: ['Volume up', 'Vol+'],
+ 27: ['Program up', 'P+'],
+ 30: ['Volume down', 'Vol-'],
+ 31: ['Program down', 'P-'],
+ 68: ['AV', 'AV'],
+ }.items())),
+}
+
diff --git a/decoders/ir_nec/pd.py b/decoders/ir_nec/pd.py
index 1368e41..459cbe2 100644
--- a/decoders/ir_nec/pd.py
+++ b/decoders/ir_nec/pd.py
@@ -19,6 +19,7 @@
##
import sigrokdecode as srd
+from .lists import *
class Decoder(srd.Decoder):
api_version = 1
@@ -48,12 +49,14 @@ class Decoder(srd.Decoder):
['cmd', 'Command'],
['cmd-inv', 'Command#'],
['repeat-code', 'Repeat code'],
+ ['remote', 'Remote'],
['warnings', 'Warnings'],
]
annotation_rows = (
('bits', 'Bits', (0, 1, 2, 3, 4)),
('fields', 'Fields', (5, 6, 7, 8, 9, 10)),
- ('warnings', 'Warnings', (11,)),
+ ('remote', 'Remote', (11,)),
+ ('warnings', 'Warnings', (12,)),
)
def putx(self, data):
@@ -82,10 +85,22 @@ class Decoder(srd.Decoder):
self.put(self.ss_other_edge, self.samplenum, self.out_ann,
[idx, [p + ' pause', '%s-pause' % p[0], '%sP' % p[0], 'P']])
+ def putremote(self):
+ dev = address.get(self.addr, 'Unknown device')
+ buttons = command.get(self.addr, None)
+ if buttons is None:
+ btn = ['Unknown', 'Unk']
+ else:
+ btn = buttons.get(self.cmd, ['Unknown', 'Unk'])
+ self.put(self.ss_remote, self.ss_bit + self.stop, self.out_ann,
+ [11, ['%s: %s' % (dev, btn[0]), '%s: %s' % (dev, btn[1]),
+ '%s' % btn[1]]])
+
def __init__(self, **kwargs):
self.state = 'IDLE'
- self.ss_bit = self.ss_start = self.ss_other_edge = 0
+ self.ss_bit = self.ss_start = self.ss_other_edge = self.ss_remote = 0
self.data = self.count = self.active = self.old_ir = None
+ self.addr = self.cmd = None
def start(self):
# self.out_python = self.register(srd.OUTPUT_PYTHON)
@@ -118,13 +133,17 @@ class Decoder(srd.Decoder):
def data_ok(self):
ret, name = (self.data >> 8) & (self.data & 0xff), self.state.title()
if self.count == 8:
+ if self.state == 'ADDRESS':
+ self.addr = self.data
+ if self.state == 'COMMAND':
+ self.cmd = self.data
self.putd(self.data)
self.ss_start = self.samplenum
return True
if ret == 0:
self.putd(self.data >> 8)
else:
- self.putx([11, ['%s error: 0x%04X' % (name, self.data)]])
+ self.putx([12, ['%s error: 0x%04X' % (name, self.data)]])
self.data = self.count = 0
self.ss_bit = self.ss_start = self.samplenum
return ret == 0
@@ -150,6 +169,7 @@ class Decoder(srd.Decoder):
if b in range(self.lc - self.margin, self.lc + self.margin):
self.putpause('Long')
self.putx([5, ['Leader code', 'Leader', 'LC', 'L']])
+ self.ss_remote = self.ss_start
self.data = self.count = 0
self.state = 'ADDRESS'
elif b in range(self.rc - self.margin, self.rc + self.margin):
@@ -177,6 +197,7 @@ class Decoder(srd.Decoder):
self.state = 'STOP' if self.data_ok() else 'IDLE'
elif self.state == 'STOP':
self.putstop(self.ss_bit)
+ self.putremote()
self.ss_bit = self.ss_start = self.samplenum
self.state = 'IDLE'
else: