Example #1
0
def test_ultrasound_pulse_timeout() -> None:
    """Test that None is returned upon a timeout occurring."""
    backend = SBArduinoHardwareBackend("COM0", SBArduinoSerial)
    serial = cast(SBArduinoSerial, backend._serial)
    serial.check_data_sent_by_constructor()

    serial.append_received_data(b"> 0\n")
    duration = backend.get_ultrasound_pulse(3, 4)
    serial.check_sent_data(b"T 3 4\n")
    assert duration is None

    serial.check_all_received_data_consumed()
Example #2
0
def test_ultrasound_pulse_on_same_pin() -> None:
    """Test same pin for trigger and echo."""
    backend = SBArduinoHardwareBackend("COM0", SBArduinoSerial)
    serial = cast(SBArduinoSerial, backend._serial)
    serial.check_data_sent_by_constructor()

    serial.append_received_data(b"> 2345\n")
    duration = backend.get_ultrasound_pulse(3, 3)
    serial.check_sent_data(b"T 3 3\n")
    assert duration == timedelta(microseconds=2345)

    # Check backend updated its view of what modes the pins are in now.
    assert backend.get_gpio_pin_mode(3) is GPIOPinMode.DIGITAL_INPUT

    serial.check_all_received_data_consumed()
Example #3
0
def test_ultrasound_pulse() -> None:
    """Test that we can read an ultrasound pulse time."""
    backend = SBArduinoHardwareBackend("COM0", SBArduinoSerial)
    serial = cast(SBArduinoSerial, backend._serial)
    serial.check_data_sent_by_constructor()

    serial.append_received_data(b"> 2345\n")
    duration = backend.get_ultrasound_pulse(3, 4)
    serial.check_sent_data(b"T 3 4\n")
    assert duration == timedelta(microseconds=2345)

    # Check backend updated its view of what modes the pins are in now.
    assert backend.get_gpio_pin_mode(3) is GPIOPinMode.DIGITAL_OUTPUT
    assert backend.get_gpio_pin_digital_state(3) is False
    assert backend.get_gpio_pin_mode(4) is GPIOPinMode.DIGITAL_INPUT

    serial.check_all_received_data_consumed()