import time

from RPi import GPIO

"""This module controls the Motor and Servo control.

This module provides an interface for interacting with
the motor on the Traxxas Slash using a Raspberry Pi
3B+.
"""

class MotorController:
    def __init__(self, pin_number, frequency, duty_cycle=0):
        self._duty_cycle = duty_cycle
        self._operating_frequency = frequency
        self._running = False
        self.pin_number = pin_number

        # Pulse width was mentioned to be 6-7.2% by uni group.

        GPIO.setmode(GPIO.OUT)
        GPIO.setup(self.pin_number, self._operating_frequency)
        self._control_pin = GPIO.PWM(self.pin_number, self._duty_cycle)


    @property
    def duty_cycle(self):
        return self._duty_cycle

    @duty_cycle.setter
    def duty_cycle(self, value):
        if value > 0 and value < 100:
            self._duty_cycle = value
            # Change the current duty cycle of the GPIO.
            self._control_pin.changeDutyCycle

    def start(self):
        if self._running:
            return
        else:
            self._control_pin.start(self._duty_cycle)

    def stop(self):
        self._control_pin.stop()

    def arm(self):
        # Set pulse width 0


        # Wait 1s

        # Set pulse width to maximum

        # Wait 1s

        # set pulse width minimum

        # Wait 1s
        
        # Set pulse width to idle

        pass

    def setThrottle(self, throttle: float):
        pass

class MotorDetails:
    def __init__(self):
        pass

    @property
    def minDutyCycle(self):
        return self._minDutyCycle
    
    @minDutyCycle.setter
    def minDutyCycle(self, value):
        self._minDutyCycle = value

    @property
    def maxDutyCycle(self):
        return self._maxDutyCycle
    
    @maxDutyCycle.setter
    def maxDutyCycle(self, value):
        self._maxDutyCycle = value

    @property
    def idle(self):
        return self._idle
    
    @idle.setter
    def idle(self, value):
        self._idle = value

class Connection:
    def __init__(self):
        pass

    