From 12fec2f5ec76c3bdae3885de12056a52b6313d24 Mon Sep 17 00:00:00 2001 From: Tomas Krejci Date: Tue, 28 May 2024 18:16:44 +0200 Subject: [PATCH] send IR RX on BLE UART --- main.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index da20d18..468b50a 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,20 @@ else: from pyb import Pin, LED import uasyncio as asyncio + +#### BLE UART ### +import ble_uart +import bluetooth +import time + + +def print_handler(): + print(uart.read().decode().strip()) + + +ble = bluetooth.BLE() +uart = ble_uart.Ble_uart(ble, on_rx=print_handler, name="OpenLaserTag Device") + #### OLT IR RX imports ### import ustruct from sys import platform @@ -122,6 +136,17 @@ async def olt_command(cmd, btn, rgb, ir_tx, tx1, tx2, tx3): await rgb.set_red() +# IR RX callback +async def cb(byte1, byte2, byte3, packet): + print( + f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}" + ) + uart.write(f"IR RX 0x{packet:06x}\n") + await rgb1.set_blue() + await asyncio.sleep_ms(200) + await rgb1.set_red() + + ### main ### async def main(proto): logger.debug("main start") @@ -129,27 +154,18 @@ async def main(proto): ### alive check ### asyncio.create_task(alive_check()) - ### RGB ### + ### RGB LED ### logger.debug("RGB init") global rgb1 rgb1 = RGB() - ### OLT IR RX ### + ### OpenLaserTag IR RX ### logger.debug("OLT IR RX init") - # User callback - async def cb(byte1, byte2, byte3, packet): - print( - f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}" - ) - await rgb1.set_blue() - await asyncio.sleep_ms(200) - await rgb1.set_red() - ir_rx = LT_24_RX(ir_rx_pin, cb) # Instantiate receiver ir_rx.error_function(print_error) # Show debug information - ### OLT IR TX ### + ### OpenLaserTag IR TX ### logger.debug("OLT IR TX init") ir_tx = LT_24_TX(ir_tx_pin, 56000) # My decoder chip is 56KHz