From ae9d6034760e643c3dd5f5f7323226134bc02702 Mon Sep 17 00:00:00 2001 From: Tomas Krejci Date: Fri, 17 May 2024 00:32:12 +0200 Subject: [PATCH] up --- lib/olt_lib/ir_tx/rp2_rmt.py | 7 ++--- test_olt_ir.py | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 test_olt_ir.py diff --git a/lib/olt_lib/ir_tx/rp2_rmt.py b/lib/olt_lib/ir_tx/rp2_rmt.py index 8f2c754..6ded5b5 100644 --- a/lib/olt_lib/ir_tx/rp2_rmt.py +++ b/lib/olt_lib/ir_tx/rp2_rmt.py @@ -1,8 +1,5 @@ -# rp2_rmt.py A RMT-like class for the RP2. - -# Released under the MIT License (MIT). See LICENSE. - -# Copyright (c) 2021-2024 Peter Hinch +# A RMT-like class for the RP2. +# Tomas Krejci [Njord] # There are two asm_pio programs, pulsetrain and irqtrain. Only the second is used. # Both operate on a FIFO containing times in μs. The first toggles a pin when a diff --git a/test_olt_ir.py b/test_olt_ir.py new file mode 100644 index 0000000..5998bd7 --- /dev/null +++ b/test_olt_ir.py @@ -0,0 +1,57 @@ +## Test IR TX/RX for OpenLaserTag +## Tomas Krejci [Njord] + +# Run this to characterise a remote. +import ustruct +from sys import platform +import time +import gc +from machine import Pin, freq +from olt_lib.ir_rx.print_error import print_error # Optional print of error codes + +# Import all implemented classes +from olt_lib.ir_rx.olt import LT_24, SONY_12, SONY_15, SONY_20 + +# Define pin according to platform +if platform == "pyboard": + p = Pin("X3", Pin.IN) +elif platform == "esp8266": + freq(160000000) + p = Pin(13, Pin.IN) +elif platform == "esp32" or platform == "esp32_LoBo": + p = Pin(23, Pin.IN) +elif platform == "rp2": + p = Pin(16, Pin.IN) + + + +# User callback +def cb(byte1, byte2, byte3, packet): + print(f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}") + +def test(proto=0): + 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 + # A real application would do something here... + try: + while True: + print("running") + time.sleep(5) + gc.collect() + except KeyboardInterrupt: + ir.close() + + +# **** DISPLAY GREETING **** +s = """Test for IR receiver. Run: +from ir_rx.test import test +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.""" + +print(s) \ No newline at end of file