#pragma once #include #include namespace TemperatureSensorTiming { constexpr auto START_SIGNAL_TIME_MILLIS = 18U; constexpr auto RESPONSE_SIGNAL_WAIT_TIME_MICROS = 40U; constexpr auto RESPONSE_SIGNAL_TIME_MICROS = 80U; constexpr auto START_TO_TRANSMIT_SIGNAL_TIME_MICROS = 50U; constexpr auto DATA_TRANSMIT_TIMEOUT_MICROS = 80U; } // namespace TemperatureSensorTiming constexpr auto TEMPERATURE_SENSOR_RESPONSE_DATA_BYTE_CNT = 5U; constexpr auto BITS_IN_BYTE = 8U; enum class TemperatureSensorStatus { OK, LOW_RESPONSE_SIGNAL_TIMEOUT, HIGH_RESPONSE_SIGNAL_TIMEOUT, START_TO_TRANSMIT_SIGNAL_TIMEOUT, DATA_TRANSMIT_TIMEOUT, CHECKSUM_ERROR }; class TemperatureSensor { public: explicit TemperatureSensor(uint8_t pin) noexcept; auto read_temperature() noexcept -> TemperatureSensorStatus; auto temperature() const noexcept -> uint8_t; private: const uint8_t _pin; uint8_t _temperature{}; auto _wait_read(uint8_t level, size_t timeout_micros) noexcept -> bool; void _restore_pin() noexcept; };