From 3ede86caf948d6e989fd056ea4f8d8c588939971 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 16 May 2022 12:44:58 +0200 Subject: feat(minion): add reading temperature sensor --- minion/src/temperature.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 minion/src/temperature.hpp (limited to 'minion/src/temperature.hpp') 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 +#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, + 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; +}; -- cgit v1.2.3-18-g5258