def __init__(self, pin): self._pin = pin self._motor = PWM.BBIO_PWM_Adapter(PWM.get_platform_pwm()) self._motor.set_frequency(self._pin, self._freq)
def test_set_frequency(self): bbio_pwm = Mock() pwm = PWM.BBIO_PWM_Adapter(bbio_pwm) pwm.start('P9_16', 50) pwm.set_frequency('P9_16', 1000) bbio_pwm.set_frequency.assert_called_with('P9_16', 1000)
def test_set_duty_cycle_valid(self): bbio_pwm = Mock() pwm = PWM.BBIO_PWM_Adapter(bbio_pwm) pwm.start('P9_16', 50) pwm.set_duty_cycle('P9_16', 75) bbio_pwm.set_duty_cycle.assert_called_with('P9_16', 75)
def test_set_duty_cycle_invalid(self): bbio_pwm = Mock() pwm = PWM.BBIO_PWM_Adapter(bbio_pwm) pwm.start('P9_16', 50) self.assertRaises(ValueError, pwm.set_duty_cycle, 'P9_16', 150) self.assertRaises(ValueError, pwm.set_duty_cycle, 'P9_16', -10)
def test_setup(self): bbio_pwm = Mock() pwm = PWM.BBIO_PWM_Adapter(bbio_pwm) pwm.start('P9_16', 50) bbio_pwm.start.assert_called_with('P9_16', 50, 2000)