lt RX run

This commit is contained in:
Tomas Krejci 2024-05-16 15:33:08 +02:00
parent 78a4c2ac32
commit 327c30d795
3 changed files with 17 additions and 22 deletions

View File

@ -5,26 +5,26 @@
# Copyright Peter Hinch 2020 Released under the MIT license
from utime import ticks_us, ticks_diff
from ir_rx import IR_RX
from olt_lib.ir_rx import IR_RX
class SONY_ABC(IR_RX): # Abstract base class
def __init__(self, pin, bits, callback, *args):
# 20 bit block has 42 edges and lasts <= 39ms nominal. Add 4ms to time
# for tolerances except in 20 bit case where timing is tight with a
# 24 bit block has 50 edges and lasts <= 39ms nominal. Add 4ms to time
# for tolerances except in 24 bit case where timing is tight with a
# repeat period of 45ms.
t = int(3 + bits * 1.8) + (1 if bits == 20 else 4)
super().__init__(pin, 2 + bits * 2, t, callback, *args)
self._addr = 0
self._bits = 20
self._bits = 24
def decode(self, _):
try:
nedges = self.edge # No. of edges detected
self.verbose and print('nedges', nedges)
if nedges > 42:
if nedges > 50:
raise RuntimeError(self.OVERRUN)
bits = (nedges - 2) // 2
if nedges not in (26, 32, 42) or bits > self._bits:
if nedges not in (26, 32, 42, 50) or bits > self._bits:
raise RuntimeError(self.BADBLOCK)
self.verbose and print('SIRC {}bit'.format(bits))
width = ticks_diff(self._times[1], self._times[0])
@ -68,3 +68,6 @@ class SONY_20(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 20, callback, *args)
class LT_24(SONY_ABC):
def __init__(self, pin, callback, *args):
super().__init__(pin, 24, callback, *args)

View File

@ -3,7 +3,7 @@
# Author: Peter Hinch
# Copyright Peter Hinch 2020 Released under the MIT license
from ir_rx import IR_RX
from olt_lib.ir_rx import IR_RX
_errors = {IR_RX.BADSTART : 'Invalid start pulse',
IR_RX.BADBLOCK : 'Error: bad block',

View File

@ -10,13 +10,10 @@ from sys import platform
import time
import gc
from machine import Pin, freq
from ir_rx.print_error import print_error # Optional print of error codes
from olt_lib.ir_rx.print_error import print_error # Optional print of error codes
# Import all implemented classes
from ir_rx.nec import NEC_8, NEC_16, SAMSUNG
from ir_rx.sony import SONY_12, SONY_15, SONY_20
from ir_rx.philips import RC5_IR, RC6_M0
from ir_rx.mce import MCE
from olt_lib.ir_rx.olt import LT_24, SONY_12, SONY_15, SONY_20
# Define pin according to platform
if platform == "pyboard":
@ -38,7 +35,7 @@ def cb(data, addr, ctrl):
def test(proto=0):
classes = (NEC_8, NEC_16, SONY_12, SONY_15, SONY_20, RC5_IR, RC6_M0, MCE, SAMSUNG)
classes = (LT_24, SONY_12, SONY_15, SONY_20)
ir = classes[proto](p, cb) # Instantiate receiver
ir.error_function(print_error) # Show debug information
# ir.verbose = True
@ -55,15 +52,10 @@ def test(proto=0):
# **** DISPLAY GREETING ****
s = """Test for IR receiver. Run:
from ir_rx.test import test
test() for NEC 8 bit protocol,
test(1) for NEC 16 bit,
test(2) for Sony SIRC 12 bit,
test(3) for Sony SIRC 15 bit,
test(4) for Sony SIRC 20 bit,
test(5) for Philips RC-5 protocol,
test(6) for RC6 mode 0.
test(7) for Microsoft Vista MCE.
test(8) for Samsung.
test() for LT 24 bit protocol,
test(1) for Sony SIRC 12 bit,
test(2) for Sony SIRC 15 bit,
test(3) for Sony SIRC 20 bit,
Hit ctrl-c to stop, then ctrl-d to soft reset."""