from subprocess import run, DEVNULL
from os import path
from enum import Enum
from time import sleep

class Direction(Enum):
    FORWARD = "Forward.complex" # car go vroom vroom random distances
    BACKWARD = "Back.complex" # same here but backwards
    LEFT = "Left.complex" # 360 + n*36 degrees at a time
    RIGHT = "Right.complex" # 360 + n*40  degrees at a time
    FINE_FORWARD = "Fine_forward.complex" # 30cm 
    FINE_BACKWARD = "Fine_back.complex" # 30~cm

class RCCar:
    def __init__(self):
        self.sample_rate = 2_000_000
        self.frequency = 27_150_000
        self.bandwidth = 4_000_000
        # Get path of current file
        self.angle = 0
        self.forward = 0
        self.backward = 0
        self.signals = path.dirname(path.realpath(__file__)) + "/signals/"
    
    def move(self, movement_file) -> str:
        
        silent = run(["hackrf_transfer",
              "-t", f"{self.signals}{movement_file}",
              "-f", str(self.frequency),
              "-s", str(self.sample_rate), 
              "-b", str(self.bandwidth), 
              "-x", "47",
              
            ],
            stdout = DEVNULL,
            stderr = DEVNULL
            
            )
        return movement_file
    
    def test_move(self):
        for direction in Direction:
            self.move(direction.value)
            sleep(1)


if __name__ == "__main__":
    car = RCCar()
    car.test_move()