From 37f80be5bec46b64b6b995d166fed8d4dcfc380d Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Thu, 17 Oct 2024 19:12:11 -0400 Subject: [PATCH] NaviGator/scripts: add script for controlling the STC practice LED buoy (WIP for #1267) --- NaviGator/scripts/led_panel_xbee.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 NaviGator/scripts/led_panel_xbee.py diff --git a/NaviGator/scripts/led_panel_xbee.py b/NaviGator/scripts/led_panel_xbee.py new file mode 100755 index 000000000..f8b5f428d --- /dev/null +++ b/NaviGator/scripts/led_panel_xbee.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python3 +""" +Script to send a 3-series color code to the physical LED panel used at testing, +over XBee/Zigbee. +""" +import random +import time + +import serial.tools.list_ports + +# pip3 install digi-xbee +from digi.xbee.devices import XBeeDevice + + +def generate_code() -> str: + choices = list("RGB") + first_code = random.choice(choices) + choices.remove(first_code) + second_code = random.choice(choices) + choices.append(first_code) + choices.remove(second_code) + third_code = random.choice(choices) + return f"{first_code}{second_code}{third_code}" + + +if __name__ == "__main__": + print("Available devices:") + for port, _, _ in serial.tools.list_ports.comports(): + print(port) + print() + device_name = input("Which serial device do you want to connect to? > ") + device = XBeeDevice(device_name, 9600) + device.open() + print("Device is open! Resetting... ") + device.send_data_broadcast("off") + time.sleep(2) + code_to_send = input( + 'What code would you like to send (ie, "RGB")? You can also type "random". > ', + ) + code = code_to_send if code_to_send != "random" else generate_code() + device.send_data_broadcast(code) + print(f'Sent "{code}"! Turning off device...') + device.close()