Skip to content

Commit

Permalink
NaviGator/scripts: add script for controlling the STC practice LED bu…
Browse files Browse the repository at this point in the history
…oy (WIP for #1267)
  • Loading branch information
cbrxyz committed Oct 17, 2024
1 parent 015c5e8 commit 37f80be
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions NaviGator/scripts/led_panel_xbee.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 37f80be

Please sign in to comment.