From d27ca93ac86697f8be6af3c751a5a527f3c07c88 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Sun, 12 Jun 2022 11:17:10 +0200 Subject: Python scripts for communication over serial and scramble generation --- comm.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 comm.py (limited to 'comm.py') diff --git a/comm.py b/comm.py new file mode 100644 index 0000000..bd07978 --- /dev/null +++ b/comm.py @@ -0,0 +1,34 @@ +import serial +import sys +import time + +device = sys.argv[1] +bandwidth = 115200 + +rot_str = [ + "R", "R\'", "R2", + "L", "L\'", "L2", + "U", "U\'", "U2", + "D", "D\'", "D2", + "F", "F\'", "F2", + "B", "B\'", "B2", +] + +def rot_to_byte(rot): + return rot_str.index(rot) + +with serial.Serial(device, bandwidth, timeout=1) as ser: + print("Sleepin for some time") + time.sleep(4) + print("Ready!") + while True: + rots = input().strip().split(' ') + print(rots) + for rot in rots: + if not rot in rot_str: + print(f"Invalid rotation {rot}, discarding.") + rots = [] + for rot in rots: + ser.write(bytes([rot_to_byte(rot)])) + print(f"Sending rotation: {rot}") + print(str(ser.readline())) -- cgit v1.2.3