diff options
Diffstat (limited to 'minion/src/temperature.hpp')
-rw-r--r-- | minion/src/temperature.hpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/minion/src/temperature.hpp b/minion/src/temperature.hpp new file mode 100644 index 0000000..dcc213c --- /dev/null +++ b/minion/src/temperature.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include <stddef.h> +#include <stdint.h> + +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, + 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; +}; |