import asyncio import serial_asyncio from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig, EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig, EffectSwipeAndChange) from host_driver import MusicMouseProtocol, RfidTokenRead rfid_token_map = { bytes.fromhex("0000000000"): "None", bytes.fromhex("88041174e9"): "Elephant", bytes.fromhex("8804ce7230"): "Fox", bytes.fromhex("88040d71f0"): "Owl", } def on_firmware_msg(protocol, message): print("Got message", message) if isinstance(message, RfidTokenRead) and message.id in rfid_token_map: if rfid_token_map[message.id] == "Elephant": print("Elephant") eff = EffectStaticConfig(ColorRGBW(0, 0, 1, 0)) protocol.send_message(eff) elif rfid_token_map[message.id] == "Fox": print("Fox") eff = EffectRandomTwoColorInterpolationConfig() protocol.send_message(eff) elif rfid_token_map[message.id] == "Owl": print("Owl") eff = EffectSwipeAndChange() eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0) protocol.send_message(eff) elif rfid_token_map[message.id] == "None": eff = EffectAlexaSwipeConfig() eff.forward = False print("Nothing") protocol.send_message(eff) loop = asyncio.get_event_loop() coro = serial_asyncio.create_serial_connection(loop, MusicMouseProtocol, '/dev/ttyUSB0', baudrate=115200) transport, protocol = loop.run_until_complete(coro) protocol.register_message_callback(on_firmware_msg) loop.run_forever() loop.close()