10#ifndef M5_UNIT_ENV_UNIT_SHT30_HPP
11#define M5_UNIT_ENV_UNIT_SHT30_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
35enum class MPS : uint8_t {
54 return value & (1U << 15);
59 return value & (1U << 13);
64 return value & (1U << 11);
69 return value & (1U << 10);
74 return value & (1U << 4);
79 return value & (1U << 1);
84 return value & (1U << 0);
94 std::array<uint8_t, 6>
raw{};
111class UnitSHT30 :
public Component,
public PeriodicMeasurementAdapter<UnitSHT30, sht30::Data> {
112 M5_UNIT_COMPONENT_HPP_BUILDER(
UnitSHT30, 0x44);
130 explicit UnitSHT30(
const uint8_t addr = DEFAULT_ADDRESS)
131 : Component(addr), _data{new
m5::container::CircularBuffer<sht30::Data>(1)}
133 auto ccfg = component_config();
134 ccfg.clock = 400 * 1000U;
135 component_config(ccfg);
141 virtual bool begin()
override;
142 virtual void update(
const bool force =
false)
override;
163 return !empty() ? oldest().temperature() : std::numeric_limits<float>::quiet_NaN();
168 return !empty() ? oldest().celsius() : std::numeric_limits<float>::quiet_NaN();
173 return !empty() ? oldest().fahrenheit() : std::numeric_limits<float>::quiet_NaN();
178 return !empty() ? oldest().humidity() : std::numeric_limits<float>::quiet_NaN();
192 return PeriodicMeasurementAdapter<UnitSHT30, sht30::Data>::startPeriodicMeasurement(mps, rep);
200 return PeriodicMeasurementAdapter<UnitSHT30, sht30::Data>::stopPeriodicMeasurement();
217 const bool stretch =
true);
299 bool stop_periodic_measurement();
305 std::unique_ptr<m5::container::CircularBuffer<sht30::Data>> _data{};
313constexpr uint16_t SINGLE_SHOT_ENABLE_STRETCH_HIGH{0x2C06};
314constexpr uint16_t SINGLE_SHOT_ENABLE_STRETCH_MEDIUM{0x2C0D};
315constexpr uint16_t SINGLE_SHOT_ENABLE_STRETCH_LOW{0x2C10};
316constexpr uint16_t SINGLE_SHOT_DISABLE_STRETCH_HIGH{0x2400};
317constexpr uint16_t SINGLE_SHOT_DISABLE_STRETCH_MEDIUM{0x240B};
318constexpr uint16_t SINGLE_SHOT_DISABLE_STRETCH_LOW{0x2416};
320constexpr uint16_t START_PERIODIC_MPS_HALF_HIGH{0x2032};
321constexpr uint16_t START_PERIODIC_MPS_HALF_MEDIUM{0x2024};
322constexpr uint16_t START_PERIODIC_MPS_HALF_LOW{0x202f};
324constexpr uint16_t START_PERIODIC_MPS_1_HIGH{0x2130};
325constexpr uint16_t START_PERIODIC_MPS_1_MEDIUM{0x2126};
326constexpr uint16_t START_PERIODIC_MPS_1_LOW{0x212D};
328constexpr uint16_t START_PERIODIC_MPS_2_HIGH{0x2236};
329constexpr uint16_t START_PERIODIC_MPS_2_MEDIUM{0x2220};
330constexpr uint16_t START_PERIODIC_MPS_2_LOW{0x222B};
332constexpr uint16_t START_PERIODIC_MPS_4_HIGH{0x2334};
333constexpr uint16_t START_PERIODIC_MPS_4_MEDIUM{0x2322};
334constexpr uint16_t START_PERIODIC_MPS_4_LOW{0x2329};
336constexpr uint16_t START_PERIODIC_MPS_10_HIGH{0x2737};
337constexpr uint16_t START_PERIODIC_MPS_10_MEDIUM{0x2721};
338constexpr uint16_t START_PERIODIC_MPS_10_LOW{0x272A};
340constexpr uint16_t STOP_PERIODIC_MEASUREMENT{0x3093};
341constexpr uint16_t ACCELERATED_RESPONSE_TIME{0x2B32};
342constexpr uint16_t READ_MEASUREMENT{0xE000};
344constexpr uint16_t SOFT_RESET{0x30A2};
346constexpr uint16_t START_HEATER{0x306D};
347constexpr uint16_t STOP_HEATER{0x3066};
349constexpr uint16_t READ_STATUS{0xF32D};
350constexpr uint16_t CLEAR_STATUS{0x3041};
352constexpr uint16_t GET_SERIAL_NUMBER_ENABLE_STRETCH{0x3780};
353constexpr uint16_t GET_SERIAL_NUMBER_DISABLE_STRETCH{0x3682};
Temperature and humidity, sensor unit.
Definition unit_SHT30.hpp:111
bool writeModeAccelerateResponseTime()
Write the mode to ART.
Definition unit_SHT30.cpp:206
config_t config()
Gets the configration.
Definition unit_SHT30.hpp:147
bool readSerialNumber(uint32_t &serialNumber)
Read the serial number value.
Definition unit_SHT30.cpp:290
bool softReset()
Soft reset.
Definition unit_SHT30.cpp:236
float celsius() const
Oldest measured temperature (Celsius)
Definition unit_SHT30.hpp:166
bool stopHeater()
Stop heater.
Definition unit_SHT30.cpp:285
void config(const config_t &cfg)
Set the configration.
Definition unit_SHT30.hpp:152
float humidity() const
Oldest measured humidity (RH)
Definition unit_SHT30.hpp:176
bool startPeriodicMeasurement(const sht30::MPS mps, const sht30::Repeatability rep)
Start periodic measurement.
Definition unit_SHT30.hpp:190
float fahrenheit() const
Oldest measured temperature (Fahrenheit)
Definition unit_SHT30.hpp:171
bool readStatus(sht30::Status &s)
Read status.
Definition unit_SHT30.cpp:220
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_SHT30.hpp:198
bool clearStatus()
Clear status.
Definition unit_SHT30.cpp:231
bool startHeater()
Start heater.
Definition unit_SHT30.cpp:280
bool measureSingleshot(sht30::Data &d, const sht30::Repeatability rep=sht30::Repeatability::High, const bool stretch=true)
Measurement single shot.
Definition unit_SHT30.cpp:140
float temperature() const
Oldest measured temperature (Celsius)
Definition unit_SHT30.hpp:161
bool generalReset()
General reset.
Definition unit_SHT30.cpp:253
Top level namespace of M5stack.
Settings for begin.
Definition unit_SHT30.hpp:119
bool start_heater
start heater on begin?
Definition unit_SHT30.hpp:127
sht30::Repeatability repeatability
Repeatability accuracy level if start on begin.
Definition unit_SHT30.hpp:125
bool start_periodic
Start periodic measurement on begin?
Definition unit_SHT30.hpp:121
sht30::MPS mps
Measuring frequency if start on begin.
Definition unit_SHT30.hpp:123
Measurement data group.
Definition unit_SHT30.hpp:93
float humidity() const
humidity (RH)
Definition unit_SHT30.cpp:82
std::array< uint8_t, 6 > raw
Definition unit_SHT30.hpp:94
float temperature() const
temperature (Celsius)
Definition unit_SHT30.hpp:96
float celsius() const
temperature (Celsius)
Definition unit_SHT30.cpp:72
float fahrenheit() const
temperature (Fahrenheit)
Definition unit_SHT30.cpp:77
Accessor for Status.
Definition unit_SHT30.hpp:50
bool trackingAlertRH() const
RH tracking alert (*)
Definition unit_SHT30.hpp:62
bool trackingAlert() const
Tracking alert (*)
Definition unit_SHT30.hpp:67
bool alertPending() const
Alert pending status (*)
Definition unit_SHT30.hpp:52
bool heater() const
Heater status.
Definition unit_SHT30.hpp:57
bool command() const
Command staus.
Definition unit_SHT30.hpp:77
bool reset() const
System reset detected (*)
Definition unit_SHT30.hpp:72
bool checksum() const
Write data checksum status.
Definition unit_SHT30.hpp:82
MPS
Measuring frequency.
Definition unit_SHT30.hpp:35
@ One
1 measurement per second
@ Four
4 measurement per second
@ Ten
10 measurement per second
@ Two
2 measurement per second
@ Half
0.5 measurement per second
Repeatability
Repeatability accuracy level.
Definition unit_SHT30.hpp:25
@ High
High repeatability.
@ Medium
Medium repeatability.