10#ifndef M5_UNIT_ENV_UNIT_QMP6988_HPP
11#define M5_UNIT_ENV_UNIT_QMP6988_HPP
12#include <M5UnitComponent.hpp>
13#include <m5_utility/stl/extension.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
102 int32_t b00{}, bt1{}, bp1{};
104 int32_t b11{}, bp2{}, b12{}, b21{}, bp3{}, a0{}, a1{}, a2{};
113 std::array<uint8_t, 6>
raw{};
122 const Calibration* calib{};
131class UnitQMP6988 :
public Component,
public PeriodicMeasurementAdapter<UnitQMP6988, qmp6988::Data> {
152 explicit UnitQMP6988(
const uint8_t addr = DEFAULT_ADDRESS)
153 : Component(addr), _data{new
m5::container::CircularBuffer<qmp6988::Data>(1)}
155 auto ccfg = component_config();
156 ccfg.clock = 400 * 1000U;
157 component_config(ccfg);
159 virtual ~UnitQMP6988()
163 virtual bool begin()
override;
164 virtual void update(
const bool force =
false)
override;
185 return !empty() ? oldest().temperature() : std::numeric_limits<float>::quiet_NaN();
190 return !empty() ? oldest().celsius() : std::numeric_limits<float>::quiet_NaN();
195 return !empty() ? oldest().fahrenheit() : std::numeric_limits<float>::quiet_NaN();
200 return !empty() ? oldest().pressure() : std::numeric_limits<float>::quiet_NaN();
219 return PeriodicMeasurementAdapter<UnitQMP6988, qmp6988::Data>::startPeriodicMeasurement(osrsPressure,
220 osrsTemperature, f, st);
225 return PeriodicMeasurementAdapter<UnitQMP6988, qmp6988::Data>::startPeriodicMeasurement();
233 return PeriodicMeasurementAdapter<UnitQMP6988, qmp6988::Data>::stopPeriodicMeasurement();
350 bool start_periodic_measurement();
353 bool stop_periodic_measurement();
355 bool read_calibration(qmp6988::Calibration& c);
357 bool read_measurement(
qmp6988::Data& d,
const bool only_temperature =
false);
358 bool is_data_ready();
363 std::unique_ptr<m5::container::CircularBuffer<qmp6988::Data>> _data{};
364 qmp6988::Calibration _calibration{};
366 bool _only_temperature{};
373constexpr uint8_t CHIP_ID{0xD1};
375constexpr uint8_t READ_PRESSURE{0xF7};
376constexpr uint8_t READ_TEMPERATURE{0xFA};
378constexpr uint8_t IO_SETUP{0xF5};
379constexpr uint8_t CONTROL_MEASUREMENT{0xF4};
380constexpr uint8_t GET_STATUS{0xF3};
381constexpr uint8_t IIR_FILTER{0xF1};
383constexpr uint8_t SOFT_RESET{0xE0};
385constexpr uint8_t READ_COMPENSATION_COEFFICIENT{0xA0};
Barometric pressure sensor to measure atmospheric pressure and altitude estimation.
Definition unit_QMP6988.hpp:131
float celsius() const
Oldest measured temperature (Celsius)
Definition unit_QMP6988.hpp:188
bool writeOversampling(const qmp6988::Oversampling osrsPressure, const qmp6988::Oversampling osrsTemperature)
Write the oversampling conditions.
Definition unit_QMP6988.cpp:378
bool readStandbyTime(qmp6988::Standby &st)
Read the standby time.
Definition unit_QMP6988.cpp:481
bool measureSingleshot(qmp6988::Data &d, const qmp6988::Oversampling osrsPressure, const qmp6988::Oversampling osrsTemperature, const qmp6988::Filter f)
Measurement single shot.
Definition unit_QMP6988.cpp:328
bool readFilter(qmp6988::Filter &f)
Read the IIR filter co-efficient.
Definition unit_QMP6988.cpp:462
bool writePowerMode(const qmp6988::PowerMode mode)
Write the power mode.
Definition unit_QMP6988.cpp:441
bool writeFilter(const qmp6988::Filter f)
Write the IIR filter co-efficient.
Definition unit_QMP6988.cpp:472
float fahrenheit() const
Oldest measured temperature (Fahrenheit)
Definition unit_QMP6988.hpp:193
bool softReset()
Soft reset.
Definition unit_QMP6988.cpp:512
bool readOversampling(qmp6988::Oversampling &osrsPressure, qmp6988::Oversampling &osrsTemperature)
Read the oversampling conditions.
Definition unit_QMP6988.cpp:367
bool writeOversamplingPressure(const qmp6988::Oversampling osrsPressure)
Write the oversampling conditions for pressure.
Definition unit_QMP6988.cpp:395
config_t config()
Gets the configration.
Definition unit_QMP6988.hpp:169
float temperature() const
Oldest measured temperature (Celsius)
Definition unit_QMP6988.hpp:183
bool writeOversamplingTemperature(const qmp6988::Oversampling osrsTemperature)
Write the oversampling conditions for temperature.
Definition unit_QMP6988.cpp:410
bool startPeriodicMeasurement(const qmp6988::Oversampling osrsPressure, const qmp6988::Oversampling osrsTemperature, const qmp6988::Filter f, const qmp6988::Standby st)
Start periodic measurement.
Definition unit_QMP6988.hpp:215
void config(const config_t &cfg)
Set the configration.
Definition unit_QMP6988.hpp:174
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_QMP6988.hpp:231
bool writeStandbyTime(const qmp6988::Standby st)
Write the standby time.
Definition unit_QMP6988.cpp:491
bool startPeriodicMeasurement()
Start periodic measurement using current settings.
Definition unit_QMP6988.hpp:223
bool writeUseCaseSetting(const qmp6988::UseCase uc)
Write the settings based on use cases.
Definition unit_QMP6988.cpp:506
float pressure() const
Oldest measured pressure (Pa)
Definition unit_QMP6988.hpp:198
bool readPowerMode(qmp6988::PowerMode &mode)
Read the power mode.
Definition unit_QMP6988.cpp:431
Top level namespace of M5stack.
Settings for begin.
Definition unit_QMP6988.hpp:139
qmp6988::Filter filter
Filter if start on begin.
Definition unit_QMP6988.hpp:147
qmp6988::Standby standby
Standby time if start on begin.
Definition unit_QMP6988.hpp:149
qmp6988::Oversampling osrs_pressure
pressure oversampling if start on begin
Definition unit_QMP6988.hpp:143
qmp6988::Oversampling osrs_temperature
temperature oversampling if start on begin
Definition unit_QMP6988.hpp:145
bool start_periodic
Start periodic measurement on begin?
Definition unit_QMP6988.hpp:141
Measurement data group.
Definition unit_QMP6988.hpp:112
float temperature() const
temperature (Celsius)
Definition unit_QMP6988.hpp:115
float fahrenheit() const
temperature (Fahrenheit)
Definition unit_QMP6988.cpp:189
float celsius() const
temperature (Celsius)
Definition unit_QMP6988.cpp:178
float pressure() const
pressure (Pa)
Definition unit_QMP6988.cpp:194
std::array< uint8_t, 6 > raw
Definition unit_QMP6988.hpp:113
UseCase
Preset settings.
Definition unit_QMP6988.hpp:92
OversamplingSetting
Oversampling Settings.
Definition unit_QMP6988.hpp:52
@ HighSpeed
osrsP:X2 osrsT:X1
@ HighAccuracy
osrsP:X16 osrsT:X2
@ UltraHightAccuracy
osrsP:X32 osrsT:X4
@ Standard
osrsP:X8 osrsT:X1
PowerMode
Operation mode.
Definition unit_QMP6988.hpp:26
Filter
Filtter setting.
Definition unit_QMP6988.hpp:64
Oversampling
Oversampling value.
Definition unit_QMP6988.hpp:37
Standby
Measurement standby time for power mode Normal.
Definition unit_QMP6988.hpp:77