-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NaviGator/scripts: add script for controlling the STC practice LED bu…
…oy (WIP for #1267)
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |