def __init__(self, arduino: Arduino, digital_pin_no: int, pwm_pin_no: int, analog_pin_no: int) -> None: self.set_pins( Pin(digital_pin_no), Pin(pwm_pin_no, is_pwm=True), Pin(analog_pin_no, is_analog=True), ) self.set_board(arduino)
def __init__(self, board: Arduino, pin_no: int) -> None: self._pin_no = pin_no self._brightness = 255 self._current_state = 0 self.set_pins(Pin(pin_id=pin_no, is_pwm=True)) self.set_board(board) self.connect()
def test_analog_write_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.analog_write(2, 0) test_arduino.register_component("component_id_1", pins=(Pin(2), )) test_arduino.analog_write(2, 1, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.analog_write(2, 1) with pytest.raises(ProtectedPinError): test_arduino.analog_write(2, 1, token="component_id_2")
def test_digital_write_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.digital_write(0, HIGH) test_arduino.register_component("component_id_1", pins=(Pin(0), )) test_arduino.digital_write(0, HIGH, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.digital_write(0, HIGH) with pytest.raises(ProtectedPinError): test_arduino.digital_write(0, HIGH, token="component_id_2")
def test_pin_mode_can_only_be_done_by_registered_component( test_arduino: Arduino, ) -> None: test_arduino.pin_mode(0, INPUT) test_arduino.register_component("component_id_1", pins=(Pin(0), )) test_arduino.pin_mode(0, INPUT, token="component_id_1") with pytest.raises(ProtectedPinError): test_arduino.pin_mode(0, INPUT) with pytest.raises(ProtectedPinError): test_arduino.pin_mode(0, INPUT, token="component_id_2")
def test_arduino() -> Arduino: pins = ( Pin(0), Pin(1, is_analog=True), Pin(2, is_pwm=True), Pin(3), Pin(4), Pin(5), ) return Arduino(pins=pins, port="", conn_class=get_mock_conn_class(), rx_pin=4, tx_pin=5)
def test_component_can_be_re_registered_after_being_deregistered( test_arduino: Arduino, ) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) test_arduino.deregister_component("component_id_1") test_arduino.register_component("component_id_1", pins=(Pin(2), Pin(3)))
def test_pins_must_be_compatible_when_registering_an_analog_pin( test_arduino: Arduino, ) -> None: with pytest.raises(NotAnalogPinError): test_arduino.register_component("component_id_1", pins=(Pin(0, is_analog=True), ))
def test_pins_must_exist_for_component_to_exist(test_arduino: Arduino) -> None: with pytest.raises(PinDoesNotExistError): test_arduino.register_component("component_id_1", pins=(Pin(6), ))
def test_component_can_only_be_registered_once(test_arduino: Arduino) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) with pytest.raises(ComponentAlreadyRegisteredError): test_arduino.register_component("component_id_1", pins=(Pin(2), Pin(3)))
def test_pins_cannot_be_registered_to_a_reserved_pin( test_arduino: Arduino) -> None: with pytest.raises(PinIsReservedForSerialCommsError): test_arduino.register_component("component_id_1", pins=(Pin(4), ))
def test_pins_cannot_be_reused(test_arduino: Arduino) -> None: test_arduino.register_component("component_id_1", pins=(Pin(0), Pin(1))) with pytest.raises(PinAlreadyRegisteredError): test_arduino.register_component("component_id_2", pins=(Pin(1), Pin(2)))
def __init__(self, board: Arduino, pin_no: int) -> None: self._pin_no = pin_no self.set_pins(Pin(pin_id=pin_no)) self.set_board(board) self.connect()
def default_pin() -> Pin: return Pin(0)
def non_default_pin() -> Pin: return Pin(0, is_pwm=True, is_analog=True)