diff --git a/main.py b/main.py index c2e4a3d..cba4ce7 100644 --- a/main.py +++ b/main.py @@ -65,7 +65,9 @@ from rgb import RGB #### OLT Commands #### LAST_BYTE = (0xE8) COMMANDS = [['NewGame', 0x83, 0x05], - ['AdminKill', 0x83, 0x00]] + ['AdminKill', 0x83, 0x00], + ['Explode', 0x83, 0x01], + ['Random', 0x83, 0x02]] #### Logging #### import logging @@ -93,34 +95,9 @@ async def alive_check(): onboar_led.off() await asyncio.sleep_ms(900) -### OLT Start game command functions ### -async def start_game_comand(btn, rgb, ir_tx): - logger.debug("Start game command on button press") - await rgb.set_red() - btn.press_func(None) - btn.release_func(None) - tx1 = 0x83 - tx2 = 0x05 - tx3 = 0xE8 - - while True: - btn.press.clear() - btn.release.clear() - await btn.press.wait() - logger.debug("Start game button pressed") - await rgb.set_green() - # IR TX send - logger.debug("Start game IR TX transmit") - asyncio.create_task(ir_tx.transmit(tx1, tx2, tx3, False)) - #loop = asyncio.get_running_loop() - #loop.set_exception_handler(exception_handler) - await asyncio.sleep_ms(50) - await btn.release.wait() - logger.debug("Start game button released") - await rgb.set_red() - +### OLT Command ### async def olt_command(cmd, btn, rgb, ir_tx, tx1, tx2, tx3): - logger.debug(f"Init OLT game command {cmd} on button {btn}") + logger.debug(f"Init OLT game command {cmd}") await rgb.set_red() btn.press_func(None) btn.release_func(None) @@ -129,16 +106,16 @@ async def olt_command(cmd, btn, rgb, ir_tx, tx1, tx2, tx3): btn.press.clear() btn.release.clear() await btn.press.wait() - logger.debug("Command button pressed") + logger.debug("Command {cmd} button pressed") await rgb.set_green() # IR TX send - logger.debug("Command IR TX transmit") + logger.debug("Command {cmd} IR TX transmit") asyncio.create_task(ir_tx.transmit(tx1, tx2, tx3, False)) #loop = asyncio.get_running_loop() #loop.set_exception_handler(exception_handler) await asyncio.sleep_ms(50) await btn.release.wait() - logger.debug("Command button released") + logger.debug("Command {cmd} button released") await rgb.set_red() @@ -157,8 +134,6 @@ async def main(proto): global rgb1 rgb1 = RGB() - - ### OLT IR RX ### logger.debug("OLT IR RX init") # User callback @@ -181,28 +156,13 @@ async def main(proto): ### Buttons ### logger.debug("Button init") - pin1 = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_UP) # Button 1 on membrane switch - btn1 = Pushbutton(pin1) - pin2 = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_UP) # Button 2 on membrane switch - btn2 = Pushbutton(pin2) - pin3 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) # Button 3 on membrane switch - btn3 = Pushbutton(pin3) - pin4 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP) # Button 4 on membrane switch - btn4 = Pushbutton(pin4) - - COMMANDS[0].append(btn1) - COMMANDS[1].append(btn2) - #COMMANDS[2].append(btn3) - #COMMANDS[3].append(btn4) - - #btn3.release_func(None) - #btn3.double_func(None) - #btn3.long_func(None) - for command, tx1, tx2, btn in COMMANDS: - logger.debug(f"command: {command} btn: {btn} tx1: {tx1} tx2: {tx2}") + PINS = ((COMMANDS[0], 20), (COMMANDS[1], 21), (COMMANDS[2], 18), (COMMANDS[3], 19)) + for cmd, pin in PINS: + btn = Pushbutton(machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP)) + command, tx1, tx2 = cmd + logger.debug(f"New command task: {command}, IR 0x{tx1:02X} 0x{tx2:02X} 0x{LAST_BYTE:02X}, btn: {btn._pin} ") asyncio.create_task(olt_command(command, btn, rgb1, ir_tx, tx1, tx2, LAST_BYTE)) - #asyncio.create_task(start_game_comand(btn3, rgb1, ir_tx)) ### Main loop ### while True: