10#ifndef M5_UNIT_ENV_UNIT_BNP280_HPP
11#define M5_UNIT_ENV_UNIT_BNP280_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
106 uint8_t value[12 * 2]{};
123 } __attribute__((packed));
131 std::array<uint8_t, 6>
raw{};
150class UnitBMP280 :
public Component,
public PeriodicMeasurementAdapter<UnitBMP280, bmp280::Data> {
151 M5_UNIT_COMPONENT_HPP_BUILDER(
UnitBMP280, 0x76);
171 explicit UnitBMP280(
const uint8_t addr = DEFAULT_ADDRESS)
172 : Component(addr), _data{new
m5::container::CircularBuffer<
bmp280::Data>(1)}
174 auto ccfg = component_config();
175 ccfg.clock = 400 * 1000U;
176 component_config(ccfg);
178 virtual ~UnitBMP280()
182 virtual bool begin()
override;
183 virtual void update(
const bool force =
false)
override;
204 return !empty() ? oldest().temperature() : std::numeric_limits<float>::quiet_NaN();
209 return !empty() ? oldest().celsius() : std::numeric_limits<float>::quiet_NaN();
214 return !empty() ? oldest().fahrenheit() : std::numeric_limits<float>::quiet_NaN();
219 return !empty() ? oldest().pressure() : std::numeric_limits<float>::quiet_NaN();
238 return PeriodicMeasurementAdapter<UnitBMP280, bmp280::Data>::startPeriodicMeasurement(
239 osrsPressure, osrsTemperature, filter, st);
244 return PeriodicMeasurementAdapter<UnitBMP280, bmp280::Data>::startPeriodicMeasurement();
253 return PeriodicMeasurementAdapter<UnitBMP280, bmp280::Data>::stopPeriodicMeasurement();
275 return measure_singleshot(d);
375 bool start_periodic_measurement();
376 bool stop_periodic_measurement();
381 bool is_data_ready();
386 std::unique_ptr<m5::container::CircularBuffer<bmp280::Data>> _data{};
388 bmp280::Trimming _trimming{};
395constexpr uint8_t CHIP_ID{0xD0};
397constexpr uint8_t SOFT_RESET{0xE0};
398constexpr uint8_t GET_STATUS{0xF3};
399constexpr uint8_t CONTROL_MEASUREMENT{0xF4};
400constexpr uint8_t CONFIG{0xF5};
402constexpr uint8_t GET_MEASUREMENT{0XF7};
403constexpr uint8_t GET_PRESSURE{0xF7};
404constexpr uint8_t GET_PRESSURE_MSB{0xF7};
405constexpr uint8_t GET_PRESSURE_LSB{0xF8};
406constexpr uint8_t GET_PRESSURE_XLSB{0xF9};
407constexpr uint8_t GET_TEMPERATURE{0XFA};
408constexpr uint8_t GET_TEMPERATURE_MSB{0XFA};
409constexpr uint8_t GET_TEMPERATURE_LSB{0XFB};
410constexpr uint8_t GET_TEMPERATURE_XLSB{0XFC};
412constexpr uint8_t TRIMMING_DIG{0x88};
413constexpr uint8_t TRIMMING_DIG_T1{0x88};
414constexpr uint8_t TRIMMING_DIG_T2{0x8A};
415constexpr uint8_t TRIMMING_DIG_T3{0x8C};
416constexpr uint8_t TRIMMING_DIG_P1{0x8E};
417constexpr uint8_t TRIMMING_DIG_P2{0x90};
418constexpr uint8_t TRIMMING_DIG_P3{0x92};
419constexpr uint8_t TRIMMING_DIG_P4{0x94};
420constexpr uint8_t TRIMMING_DIG_P5{0x96};
421constexpr uint8_t TRIMMING_DIG_P6{0x98};
422constexpr uint8_t TRIMMING_DIG_P7{0x9A};
423constexpr uint8_t TRIMMING_DIG_P8{0x9C};
424constexpr uint8_t TRIMMING_DIG_P9{0x9A};
425constexpr uint8_t TRIMMING_DIG_RESERVED{0xA0};
Pressure and temperature sensor unit.
Definition unit_BMP280.hpp:150
bool measureSingleshot(bmp280::Data &d)
Measurement single shot using current settings.
Definition unit_BMP280.hpp:273
bool writeFilter(const bmp280::Filter &f)
Write the IIR filter co-efficient.
Definition unit_BMP280.cpp:497
float pressure() const
Oldest measured pressure (Pa)
Definition unit_BMP280.hpp:217
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_BMP280.hpp:251
bool writePowerMode(const bmp280::PowerMode m)
Write the power mode.
Definition unit_BMP280.cpp:463
bool writeStandbyTime(const bmp280::Standby s)
Write the standby time.
Definition unit_BMP280.cpp:530
bool readStandbyTime(bmp280::Standby &s)
Read the standby time.
Definition unit_BMP280.cpp:520
float temperature() const
Oldest measured temperature (Celsius)
Definition unit_BMP280.hpp:202
bool writeOversampling(const bmp280::Oversampling osrsPressure, const bmp280::Oversampling osrsTemperature)
Write the oversampling conditions.
Definition unit_BMP280.cpp:401
bool softReset()
Soft reset.
Definition unit_BMP280.cpp:551
float fahrenheit() const
Oldest measured temperature (Fahrenheit)
Definition unit_BMP280.hpp:212
bool writeOversamplingTemperature(const bmp280::Oversampling osrsTemperature)
Write the oversampling conditions for temperature.
Definition unit_BMP280.cpp:432
bool writeOversamplingPressure(const bmp280::Oversampling osrsPressure)
Write the oversampling conditions for pressure.
Definition unit_BMP280.cpp:417
void config(const config_t &cfg)
Set the configration.
Definition unit_BMP280.hpp:193
bool measureSingleshot(bmp280::Data &d, const bmp280::Oversampling osrsPressure, const bmp280::Oversampling osrsTemperature, const bmp280::Filter filter)
Measurement single shot.
Definition unit_BMP280.cpp:347
bool startPeriodicMeasurement(const bmp280::Oversampling osrsPressure, const bmp280::Oversampling osrsTemperature, const bmp280::Filter filter, const bmp280::Standby st)
Start periodic measurement.
Definition unit_BMP280.hpp:234
bool startPeriodicMeasurement()
Start periodic measurement using current settings.
Definition unit_BMP280.hpp:242
bool readPowerMode(bmp280::PowerMode &m)
Read the power mode.
Definition unit_BMP280.cpp:453
config_t config()
Gets the configration.
Definition unit_BMP280.hpp:188
bool writeUseCaseSetting(const bmp280::UseCase uc)
Write the settings based on use cases.
Definition unit_BMP280.cpp:545
float celsius() const
Oldest measured temperature (Celsius)
Definition unit_BMP280.hpp:207
bool readFilter(bmp280::Filter &f)
Read the IIR filter co-efficient.
Definition unit_BMP280.cpp:487
bool readOversampling(bmp280::Oversampling &osrsPressure, bmp280::Oversampling &osrsTemperature)
Read the oversampling conditions.
Definition unit_BMP280.cpp:390
Top level namespace of M5stack.
Settings for begin.
Definition unit_BMP280.hpp:158
bmp280::Oversampling osrs_pressure
Pressure oversampling if start on begin.
Definition unit_BMP280.hpp:162
bmp280::Standby standby
Standby time if start on begin.
Definition unit_BMP280.hpp:168
bmp280::Filter filter
Filter if start on begin.
Definition unit_BMP280.hpp:166
bmp280::Oversampling osrs_temperature
Temperature oversampling if start on begin.
Definition unit_BMP280.hpp:164
bool start_periodic
Start periodic measurement on begin?
Definition unit_BMP280.hpp:160
Measurement data group.
Definition unit_BMP280.hpp:130
const Trimming * trimming
For calculate.
Definition unit_BMP280.hpp:132
float temperature() const
temperature (Celsius)
Definition unit_BMP280.hpp:135
float pressure() const
pressure (Pa)
Definition unit_BMP280.cpp:228
float fahrenheit() const
temperature (Fahrenheit)
Definition unit_BMP280.cpp:223
std::array< uint8_t, 6 > raw
RAW data [0,1,2]:pressure [3,4,5]:temperature.
Definition unit_BMP280.hpp:131
float celsius() const
temperature (Celsius)
Definition unit_BMP280.cpp:212
Definition unit_BMP280.hpp:105
Oversampling
Oversampling factor.
Definition unit_BMP280.hpp:40
@ Skipped
Skipped (No measurements are performed)
Filter
Filter setting.
Definition unit_BMP280.hpp:65
OversamplingSetting
Oversampling Settings.
Definition unit_BMP280.hpp:53
@ StandardResolution
18 bit / 0.66 Pa, 16 bit / 0.0050 C
@ HighResolution
19 bit / 0.33 Pa, 16 bit / 0.0050 C
@ UltraHighResolution
20 bit / 0.16 Pa, 17 bit / 0.0025 C
PowerMode
Operation mode.
Definition unit_BMP280.hpp:30
@ Normal
Periodic measurements are performed.
UseCase
Preset settings.
Definition unit_BMP280.hpp:92
@ Weather
Weather monitoring.
@ Indoor
Indoor navigation.
@ Elevator
Elevator / floor change detection.
@ Dynamic
Handheld device dynamic.
Standby
Measurement standby time for power mode Normal.
Definition unit_BMP280.hpp:77