aboutsummaryrefslogtreecommitdiff
path: root/comm.py
blob: bd07978ab4fb10b9eda664114a83d9791b99026f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()))