#!/usr/bin/env python3

import subprocess
import serial
import sys

print(sys.argv)

port = sys.argv[1]

cmd = sys.argv[1]

for cmd in sys.argv[1:]:
    print(cmd)
    match cmd:
        case "src":
            subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", ".", ":" ], cwd="src")
        case "lib":
            subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", "lib", ":" ])
        case "ls":
            subprocess.call(["mpremote", "connect", port, "fs", "ls", ":" ])
        case "reset":
            with serial.Serial(port, baudrate=115200) as ser:
                ser.write(b'\x03\x03\x04')
        case "follow":
            with serial.Serial(port, baudrate=115200) as ser:
                while True:
                    if ser.in_waiting > 0:  # Check if there is data in the buffer
                        data = ser.readline().decode('utf-8').strip()  # Read and decode the data
                        print(data)