add COMMANDS, add pin info for OLT remote

This commit is contained in:
Tomas Krejci 2024-05-28 02:08:47 +02:00
parent 85ca755700
commit a15e7214b7
2 changed files with 59 additions and 5 deletions

View File

@ -1,3 +1,4 @@
# OpenLaserTag remote box
Box Z62, 2xAA:
@ -19,5 +20,14 @@ pin3 GND
IR TX TSAL6200
### Pi Pico pin:
Pi Pico pin:
pin 16 - IR RX
pin 17 - IR TX
pin 18 - button 3
pin 19 - button
pin 20 - button
pin 21 - button
pin 22 - Red LED
pin 26 - Green LED
pin 27 - Blue LED

52
main.py
View File

@ -62,6 +62,11 @@ import primitives.queue as queue
from primitives import Switch, Pushbutton
from rgb import RGB
#### OLT Commands ####
LAST_BYTE = (0xE8)
COMMANDS = [['NewGame', 0x83, 0x05],
['AdminKill', 0x83, 0x00]]
#### Logging ####
import logging
global logger
@ -114,7 +119,31 @@ async def start_game_comand(btn, rgb, ir_tx):
logger.debug("Start game button released")
await rgb.set_red()
async def olt_command(cmd, btn, rgb, ir_tx, tx1, tx2, tx3):
logger.debug(f"Init OLT game command {cmd} on button {btn}")
await rgb.set_red()
btn.press_func(None)
btn.release_func(None)
while True:
btn.press.clear()
btn.release.clear()
await btn.press.wait()
logger.debug("Command button pressed")
await rgb.set_green()
# IR TX send
logger.debug("Command 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")
await rgb.set_red()
### main ###
async def main(proto):
@ -148,13 +177,28 @@ 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)
asyncio.create_task(start_game_comand(btn3, rgb1, ir_tx))
#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}")
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: