Esempio n. 1
0
def test_backend_read_analogue() -> None:
    """Test that we can read the digital state of a pin."""
    backend = SBArduinoHardwareBackend("COM0", SBArduinoSerial)
    serial = cast(SBArduinoSerial, backend._serial)
    serial.check_data_sent_by_constructor()

    readings = [212, 535, 662, 385]
    for i, expected_reading in enumerate(readings):
        # "read analogue" command reads all four pins at once.
        identifier = 14 + i
        for j, reading in enumerate(readings):
            serial.append_received_data(f"> a{j} {reading}".encode("utf-8"),
                                        newline=True)
        expected_voltage = (expected_reading / 1024.0) * 5.0
        measured_voltage = backend.read_gpio_pin_analogue_value(identifier)
        assert isclose(measured_voltage, expected_voltage)
        serial.check_sent_data(b"A\n")

    serial.check_all_received_data_consumed()
Esempio n. 2
0
def test_backend_read_analogue_requires_analogue_pin() -> None:
    """Check that pins 2-13 are not supported by read analogue."""
    backend = SBArduinoHardwareBackend("COM0", SBArduinoSerial)
    with pytest.raises(NotSupportedByHardwareError):
        backend.read_gpio_pin_analogue_value(13)