Skip to content

Commit

Permalink
Merge pull request #3 from frawau/master
Browse files Browse the repository at this point in the history
RCA-38 protocol
  • Loading branch information
elupus committed Aug 31, 2020
2 parents f0a53da + 70af040 commit 219c4b3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Philips RC-6 Protocol
irgen -i rc6 -d 16 -1 0 -o raw
RCA RCA-38 Protocol
---------------------

.. code-block:: bash
irgen -i rca38 -d 15 -1 0 -o raw
Raw
---
Expand Down
46 changes: 44 additions & 2 deletions src/irgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

gen_raw_rc6_protocols = ['rc6']

gen_raw_protocols = [*gen_raw_nec_protocols, *gen_raw_rc5_protocols, *gen_raw_rc6_protocols]
gen_raw_rca38_protocols = ['rca38']

gen_raw_protocols = [*gen_raw_nec_protocols, *gen_raw_rc5_protocols, *gen_raw_rc6_protocols, *gen_raw_rca38_protocols]

def uX_to_bin(v, x):
if(v < 0):
Expand Down Expand Up @@ -148,6 +150,40 @@ def encode(value):
yield logical_bit * -3 # Trailing zero to separate


def gen_raw_rca38(protocol, device, subdevice, function, **kwargs):
logical_bit = 460
def encode_bit(s):
if s == '1':
yield logical_bit * 1
yield logical_bit * -4
else:
yield logical_bit * 1
yield logical_bit * -2

def rev_encode_bit(s):
if s == '1':
yield from encode_bit('0')
else:
yield from encode_bit('1')

def encode_uX(x, l, f):
for s in uX_to_bin(x, l):
yield from f(s)


#Starting burst
yield logical_bit * 8
yield logical_bit * -8
# Device and function
yield from encode_uX(device, 4, encode_bit)
yield from encode_uX(function, 8, encode_bit)
#Reversed device and function
yield from encode_uX(device, 4, rev_encode_bit)
yield from encode_uX(function, 8, rev_encode_bit)
#Ending burst
yield logical_bit * 1
yield logical_bit * -16

def gen_raw_general(protocol, device, subdevice, function, **kwargs):
if protocol.lower() in gen_raw_nec_protocols:
yield from gen_raw_nec(protocol.lower(),
Expand All @@ -167,6 +203,12 @@ def gen_raw_general(protocol, device, subdevice, function, **kwargs):
int(subdevice),
int(function))

if protocol.lower() in gen_raw_rca38_protocols:
yield from gen_raw_rca38(protocol.lower(),
int(device),
int(subdevice),
int(function))


def gen_simplified_from_raw(x):
"""
Expand Down Expand Up @@ -336,4 +378,4 @@ def fixup(x):
def gen_pronto_from_raw(seq1, seq2, base=None, freq=None):
data = gen_pronto_from_raw_int(seq1, seq2, base, freq)
for value in data:
yield "{0:0{1}x}".format(value,4)
yield "{0:0{1}x}".format(value,4)
7 changes: 7 additions & 0 deletions tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ def test_broadlink_decode_encode():
raw = list(irgen.gen_raw_from_broadlink_base64(data))
data2 = bytes(irgen.gen_broadlink_base64_from_raw(raw))
assert data == data2

def test_rca38_decode_encode():
"""
data was generated with IrScrutinizer-2.2.6 device 12, OBC 123
"""
data = [+3680,-3680,+460,-1840,+460,-1840,+460,-920,+460,-920,+460,-920,+460,-1840,+460,-1840,+460,-1840,+460,-1840,+460,-920,+460,-1840,+460,-1840,+460,-920,+460,-920,+460,-1840,+460,-1840,+460,-1840,+460,-920,+460,-920,+460,-920,+460,-920,+460,-1840,+460,-920,+460,-920,+460,-7360]
assert data == list(irgen.gen_raw_general('rca38', 12, -1, 123))

0 comments on commit 219c4b3

Please sign in to comment.