10#ifndef M5_UNIT_ENV_UNIT_SHT40_HPP
11#define M5_UNIT_ENV_UNIT_SHT40_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
51 std::array<uint8_t, 6>
raw{};
70class UnitSHT40 :
public Component,
public PeriodicMeasurementAdapter<UnitSHT40, sht40::Data> {
71 M5_UNIT_COMPONENT_HPP_BUILDER(
UnitSHT40, 0x44);
89 explicit UnitSHT40(
const uint8_t addr = DEFAULT_ADDRESS)
90 : Component(addr), _data{new
m5::container::CircularBuffer<
sht40::Data>(1)}
92 auto ccfg = component_config();
93 ccfg.clock = 400 * 1000U;
94 component_config(ccfg);
100 virtual bool begin()
override;
101 virtual void update(
const bool force =
false)
override;
122 return !empty() ? oldest().temperature() : std::numeric_limits<float>::quiet_NaN();
127 return !empty() ? oldest().celsius() : std::numeric_limits<float>::quiet_NaN();
132 return !empty() ? oldest().fahrenheit() : std::numeric_limits<float>::quiet_NaN();
137 return !empty() ? oldest().humidity() : std::numeric_limits<float>::quiet_NaN();
153 const float duty = 0.05f)
155 return PeriodicMeasurementAdapter<UnitSHT40, sht40::Data>::startPeriodicMeasurement(precision, heater, duty);
163 return PeriodicMeasurementAdapter<UnitSHT40, sht40::Data>::stopPeriodicMeasurement();
223 bool stop_periodic_measurement();
231 std::unique_ptr<m5::container::CircularBuffer<sht40::Data>> _data{};
233 uint8_t _cmd{}, _measureCmd{};
234 types::elapsed_time_t _latest_heater{}, _interval_heater{};
235 uint32_t _duration_measure{}, _duration_heater{};
241constexpr uint8_t MEASURE_HIGH_HEATER_1S{0x39};
242constexpr uint8_t MEASURE_HIGH_HEATER_100MS{0x32};
243constexpr uint8_t MEASURE_HIGH{0xFD};
245constexpr uint8_t MEASURE_MEDIUM_HEATER_1S{0x2F};
246constexpr uint8_t MEASURE_MEDIUM_HEATER_100MS{0x24};
247constexpr uint8_t MEASURE_MEDIUM{0xF6};
249constexpr uint8_t MEASURE_LOW_HEATER_1S{0x1E};
250constexpr uint8_t MEASURE_LOW_HEATER_100MS{0x15};
251constexpr uint8_t MEASURE_LOW{0xE0};
253constexpr uint8_t GET_SERIAL_NUMBER{0x89};
254constexpr uint8_t SOFT_RESET{0x94};
Temperature and humidity, sensor unit.
Definition unit_SHT40.hpp:70
bool softReset()
Soft reset.
Definition unit_SHT40.cpp:209
bool readSerialNumber(uint32_t &serialNumber)
Read the serial number value.
Definition unit_SHT40.cpp:242
float humidity() const
Oldest measured humidity (RH)
Definition unit_SHT40.hpp:135
bool generalReset()
General reset.
Definition unit_SHT40.cpp:230
config_t config()
Gets the configration.
Definition unit_SHT40.hpp:106
void config(const config_t &cfg)
Set the configration.
Definition unit_SHT40.hpp:111
bool measureSingleshot(sht40::Data &d, const sht40::Precision precision=sht40::Precision::High, const sht40::Heater heater=sht40::Heater::None)
Measurement single shot.
Definition unit_SHT40.cpp:176
float fahrenheit() const
Oldest measured temperature (Fahrenheit)
Definition unit_SHT40.hpp:130
bool startPeriodicMeasurement(const sht40::Precision precision, const sht40::Heater heater, const float duty=0.05f)
Start periodic measurement.
Definition unit_SHT40.hpp:152
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_SHT40.hpp:161
float celsius() const
Oldest measured temperature (Celsius)
Definition unit_SHT40.hpp:125
float temperature() const
Oldest measured temperature (Celsius)
Definition unit_SHT40.hpp:120
Top level namespace of M5stack.
Settings for begin.
Definition unit_SHT40.hpp:78
float heater_duty
Heater duty cycle if start on begin [~ 0.05f].
Definition unit_SHT40.hpp:86
sht40::Precision precision
Precision level if start on begin.
Definition unit_SHT40.hpp:82
bool start_periodic
Start periodic measurement on begin?
Definition unit_SHT40.hpp:80
sht40::Heater heater
Heater behavior if start on begin.
Definition unit_SHT40.hpp:84
Measurement data group.
Definition unit_SHT40.hpp:50
float celsius() const
temperature (Celsius)
Definition unit_SHT40.cpp:55
std::array< uint8_t, 6 > raw
RAW data.
Definition unit_SHT40.hpp:51
float fahrenheit() const
temperature (Fahrenheit)
Definition unit_SHT40.cpp:60
bool heater
Measured data after heater is activated if true.
Definition unit_SHT40.hpp:52
float humidity() const
humidity (RH)
Definition unit_SHT40.cpp:66
float temperature() const
temperature (Celsius)
Definition unit_SHT40.hpp:55
Precision
precision level
Definition unit_SHT40.hpp:30
Heater
Heater behavior.
Definition unit_SHT40.hpp:40
@ Short
Activate heater for 0.1s.
@ Long
Activate heater for 1s.