"""
Read the MAX31865 / PT100 repeatedly.
"""

import time

from sentinel.sensors.max31865 import (
    MAX31865TemperatureSensor,
)


def main() -> None:
    """Print PT100 temperature and resistance."""
    sensor = MAX31865TemperatureSensor(
        spi_bus=0,
        spi_device=0,
        wires=3,
        rtd_nominal_ohms=100.0,
        reference_resistor_ohms=430.0,
        filter_hz=50,
    )

    print("MAX31865 / PT100 test")
    print("Ctrl+C to stop.")

    try:
        while True:
            resistance = (
                sensor.read_resistance_ohms()
            )

            temperature = (
                sensor._temperature_from_resistance(
                    resistance
                )
            )

            print(
                f"R={resistance:.3f} Ω | "
                f"T={temperature:.3f} °C"
            )

            time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        sensor.close()


if __name__ == "__main__":
    main()
