send IR RX on BLE UART

This commit is contained in:
Tomas Krejci 2024-05-28 18:16:44 +02:00
parent bc983bdd39
commit 12fec2f5ec

40
main.py
View File

@ -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