summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2014-03-07 14:55:54 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2014-03-10 15:39:33 +0100
commit00962e763e610d8535dd9df1ac97377b3fb727a7 (patch)
treec523e38cf723c58fb9eb240699cf6a1415b51f33 /decoders
parent5e6fa9cc6c1ac53de29350722f86e7524cc53442 (diff)
downloadlibsigrokdecode-00962e763e610d8535dd9df1ac97377b3fb727a7.tar.gz
libsigrokdecode-00962e763e610d8535dd9df1ac97377b3fb727a7.zip
Rename 'ir_nec6122' PD to 'ir_nec', minor fixes and simplifications.
This IR protocol is commonly referred to as "the NEC protocol", and can be generated by various means (not only via the NEC µPD6121/µPD6122 ICs). Drop some unneeded variables and fix/simplify the code a bit.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/ir_nec/__init__.py (renamed from decoders/ir_nec6122/__init__.py)2
-rw-r--r--decoders/ir_nec/pd.py (renamed from decoders/ir_nec6122/pd.py)78
2 files changed, 34 insertions, 46 deletions
diff --git a/decoders/ir_nec6122/__init__.py b/decoders/ir_nec/__init__.py
index 972d5a9..84bf428 100644
--- a/decoders/ir_nec6122/__init__.py
+++ b/decoders/ir_nec/__init__.py
@@ -19,7 +19,7 @@
##
'''
-NEC 6121/6122 is a biphase/manchester based infrared remote control protocol.
+NEC is a pulse-distance based infrared remote control protocol.
'''
from .pd import *
diff --git a/decoders/ir_nec6122/pd.py b/decoders/ir_nec/pd.py
index ba1cdf9..542139d 100644
--- a/decoders/ir_nec6122/pd.py
+++ b/decoders/ir_nec/pd.py
@@ -22,56 +22,48 @@ import sigrokdecode as srd
class Decoder(srd.Decoder):
api_version = 1
- id = 'ir_nec6122'
- name = 'IR NEC 6122'
- longname = '1-Wire Infrared remote controller NEC 6122'
- desc = 'Unidirectional, asynchronous serial bus.'
+ id = 'ir_nec'
+ name = 'IR NEC'
+ longname = 'IR NEC'
+ desc = 'NEC infrared remote control protocol.'
license = 'gplv2+'
inputs = ['logic']
- outputs = ['ir_nec6122']
+ outputs = ['ir_nec']
probes = [
{'id': 'ir', 'name': 'IR', 'desc': 'Data line'},
]
optional_probes = []
options = {
- 'level': ['Tirgger Level L/H', 0],
- 'cnt_peroid': ['Peroid time (us)', 13500],
- 'cnt_repeat': ['Repeat time (us)', 11250],
- 'cnt_repeat_end': ['Repeat end time (us)', 562],
- 'cnt_accuracy': ['Accuracy range (us)', 100],
- 'cnt_dazero': ['Data 0 time (us)', 1125],
- 'cnt_daone': ['Data 1 time (us)', 2250],
+ 'cnt_lc': ['Leader code time (µs)', 13500],
+ 'cnt_rc': ['Repeat code time (µs)', 11250],
+ 'cnt_rc_end': ['Repeat code end time (µs)', 562],
+ 'cnt_accuracy': ['Accuracy range (µs)', 100],
+ 'cnt_dazero': ['Data 0 time (µs)', 1125],
+ 'cnt_daone': ['Data 1 time (µs)', 2250],
'polarity': ['Polarity', 'active-low'],
- }
+ }
annotations = [
['bit', 'Bit'],
- ['preoid', 'Preoid'],
+ ['lc', 'Leader code'],
['info', 'Info'],
['error', 'Error'],
]
annotation_rows = (
- ('fields', 'Fields', (1, 2, 3, 4, 5, 6)),
('bits', 'Bits', (0,)),
+ ('fields', 'Fields', (1, 2, 3)),
)
def putx(self, data):
- self.put(self.ss_edge, self.samplenum, self.out_ann, data)
-
- def putx(self, data):
self.put(self.ss_start, self.samplenum, self.out_ann, data)
def putb(self, data):
self.put(self.ss_bit, self.samplenum, self.out_ann, data)
def __init__(self, **kwargs):
- self.olddata = None
- self.ss_edge = 0
self.ss_bit = 0
- self.first_transition = True
- self.bitwidth = None
self.state = 'IDLE'
- self.data = 0;
- self.count = 0;
+ self.data = 0
+ self.count = 0
self.ss_start = 0
self.act_polar = 0
@@ -88,12 +80,12 @@ class Decoder(srd.Decoder):
x = float(self.options['cnt_accuracy']) / 1000000.0
self.margin = int(samplerate * x) - 1
- x = float(self.options['cnt_peroid']) / 1000000.0
- self.preoid = int(samplerate * x) - 1
- x = float(self.options['cnt_repeat']) / 1000000.0
- self.repeat = int(samplerate * x) - 1
- x = float(self.options['cnt_repeat_end']) / 1000000.0
- self.repeat_end = int(samplerate * x) - 1
+ x = float(self.options['cnt_lc']) / 1000000.0
+ self.lc = int(samplerate * x) - 1
+ x = float(self.options['cnt_rc']) / 1000000.0
+ self.rc = int(samplerate * x) - 1
+ x = float(self.options['cnt_rc_end']) / 1000000.0
+ self.rc_end = int(samplerate * x) - 1
x = float(self.options['cnt_dazero']) / 1000000.0
self.dazero = int(samplerate * x) - 1
x = float(self.options['cnt_daone']) / 1000000.0
@@ -103,11 +95,9 @@ class Decoder(srd.Decoder):
def handle_bits(self, tick):
ret = 0xff
- if tick in range(self.dazero - self.margin,
- self.dazero + self.margin):
+ if tick in range(self.dazero - self.margin, self.dazero + self.margin):
ret = 0
- elif tick in range(self.daone - self.margin,
- self.daone + self.margin):
+ elif tick in range(self.daone - self.margin, self.daone + self.margin):
ret = 1
if ret < 2:
@@ -116,7 +106,7 @@ class Decoder(srd.Decoder):
self.count = self.count + 1
self.ss_bit = self.samplenum
- return ret;
+ return ret
def data_judge(self, name):
buf = int((self.data & 0xff00) / 0x100)
@@ -126,7 +116,7 @@ class Decoder(srd.Decoder):
self.putx([2, ['%s: 0x%02x' % (name, buf)]])
else:
self.putx([3, ['%s Error: 0x%04x' % (name, self.data)]])
-
+
self.data = self.count = 0
self.ss_bit = self.ss_start = self.samplenum
return ret
@@ -136,7 +126,7 @@ class Decoder(srd.Decoder):
raise Exception("Cannot decode without samplerate.")
for (self.samplenum, pins) in data:
self.ir = pins[0]
-
+
# Wait for any edge (rising or falling).
if self.old_ir == self.ir:
continue
@@ -145,24 +135,22 @@ class Decoder(srd.Decoder):
b = self.samplenum - self.ss_bit
# State machine.
if self.state == 'IDLE':
- if b in range(self.preoid - self.margin,
- self.preoid + self.margin):
- self.putx([1, ['Preoid', 'Pre', 'P']])
+ if b in range(self.lc - self.margin, self.lc + self.margin):
+ self.putx([1, ['Leader code', 'Leader', 'LC', 'L']])
self.data = self.count = 0
self.state = 'ADDRESS'
- elif b in range(self.repeat - self.margin,
- self.repeat + self.margin):
- self.putx([1, ['Repeat', 'Rep', 'R']])
+ elif b in range(self.rc - self.margin, self.rc + self.margin):
+ self.putx([1, ['Repeat code', 'Repeat', 'RC', 'R']])
self.data = self.count = 0
self.ss_bit = self.ss_start = self.samplenum
elif self.state == 'ADDRESS':
self.handle_bits(b)
if self.count > 15:
if self.data_judge(self.state) == 0:
- self.state = 'CODE'
+ self.state = 'COMMAND'
else:
self.state = 'IDLE'
- elif self.state == 'CODE':
+ elif self.state == 'COMMAND':
self.handle_bits(b)
if self.count > 15:
self.data_judge(self.state)