diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2022-06-12 11:17:10 +0200 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2022-06-12 11:17:10 +0200 |
commit | d27ca93ac86697f8be6af3c751a5a527f3c07c88 (patch) | |
tree | db77703345d9874b1f2d31fd02f33f27c67ad221 | |
parent | 530c341960e528bb44dd6747f37c0c87c68537d8 (diff) |
Python scripts for communication over serial and scramble generation
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | comm.py | 34 | ||||
-rw-r--r-- | gen-scramble.py | 22 |
3 files changed, 57 insertions, 1 deletions
@@ -1,6 +1,6 @@ CXX = g++ # CXXFLAGS = -std=c++14 -g -Wall -Wshadow -Wextra -fsanitize=address -fsanitize=undefined -CXXFLAGS = -std=c++14 -O3 +CXXFLAGS = -std=c++14 -O3 -march=native C_FILES = $(wildcard src/*.cpp) H_FILES = $(wildcard src/*.h) @@ -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())) diff --git a/gen-scramble.py b/gen-scramble.py new file mode 100644 index 0000000..d1482cd --- /dev/null +++ b/gen-scramble.py @@ -0,0 +1,22 @@ +import sys +import random + +faces = "RLUDFB" +rot = " '2" + +def random_rotation(): + r = random.choice(faces) + random.choice(rot) + return r.strip() + +def gen_scramble(): + scramble = '' + for _ in range(int(sys.argv[2])): + scramble += random_rotation() + ' ' + return scramble.strip() + +if len(sys.argv) != 4: + print(f"Usage: python3 {sys.argv[0]} seed length scrambles") + exit(1) + +for i in range(int(sys.argv[3])): + print(gen_scramble()) |