diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-16 12:44:58 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-16 13:50:22 +0200 |
commit | 3ede86caf948d6e989fd056ea4f8d8c588939971 (patch) | |
tree | a3226c6b9005ddc24a4af7a3c38722eb113963d4 /minion/src/temperature.hpp | |
parent | 6aa69cdcd8720d835e922323cdcf79147c9b3154 (diff) |
feat(minion): add reading temperature sensor
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; +}; |