ESPHome  2024.10.2
bme280_base.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace bme280_base {
8 
11  uint16_t t1; // 0x88 - 0x89
12  int16_t t2; // 0x8A - 0x8B
13  int16_t t3; // 0x8C - 0x8D
14 
15  uint16_t p1; // 0x8E - 0x8F
16  int16_t p2; // 0x90 - 0x91
17  int16_t p3; // 0x92 - 0x93
18  int16_t p4; // 0x94 - 0x95
19  int16_t p5; // 0x96 - 0x97
20  int16_t p6; // 0x98 - 0x99
21  int16_t p7; // 0x9A - 0x9B
22  int16_t p8; // 0x9C - 0x9D
23  int16_t p9; // 0x9E - 0x9F
24 
25  uint8_t h1; // 0xA1
26  int16_t h2; // 0xE1 - 0xE2
27  uint8_t h3; // 0xE3
28  int16_t h4; // 0xE4 - 0xE5[3:0]
29  int16_t h5; // 0xE5[7:4] - 0xE6
30  int8_t h6; // 0xE7
31 };
32 
45 };
46 
57 };
58 
61  public:
62  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
63  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
64  void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
65 
67  void set_temperature_oversampling(BME280Oversampling temperature_over_sampling);
69  void set_pressure_oversampling(BME280Oversampling pressure_over_sampling);
71  void set_humidity_oversampling(BME280Oversampling humidity_over_sampling);
73  void set_iir_filter(BME280IIRFilter iir_filter);
74 
75  // ========== INTERNAL METHODS ==========
76  // (In most use cases you won't need these)
77  void setup() override;
78  void dump_config() override;
79  float get_setup_priority() const override;
80  void update() override;
81 
82  protected:
84  float read_temperature_(const uint8_t *data, int32_t *t_fine);
86  float read_pressure_(const uint8_t *data, int32_t t_fine);
88  float read_humidity_(const uint8_t *data, int32_t t_fine);
89  uint8_t read_u8_(uint8_t a_register);
90  uint16_t read_u16_le_(uint8_t a_register);
91  int16_t read_s16_le_(uint8_t a_register);
92 
93  virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
94  virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
95  virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
96  virtual bool read_byte_16(uint8_t a_register, uint16_t *data) = 0;
97 
99  BME280Oversampling temperature_oversampling_{BME280_OVERSAMPLING_16X};
103  sensor::Sensor *temperature_sensor_{nullptr};
104  sensor::Sensor *pressure_sensor_{nullptr};
105  sensor::Sensor *humidity_sensor_{nullptr};
106  enum ErrorCode {
107  NONE = 0,
110  } error_code_{NONE};
111 };
112 
113 } // namespace bme280_base
114 } // namespace esphome
void setup()
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: bme280_base.h:63
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: bme280_base.h:62
This class simplifies creating components that periodically check a state.
Definition: component.h:283
BME280IIRFilter
Enum listing all Infinite Impulse Filter values for the BME280.
Definition: bme280_base.h:51
BME280CalibrationData calibration_
Definition: bme280_base.h:98
Internal struct storing the calibration values of an BME280.
Definition: bme280_base.h:10
BME280Oversampling
Enum listing all Oversampling values for the BME280.
Definition: bme280_base.h:38
std::string size_t len
Definition: helpers.h:292
This class implements support for the BME280 Temperature+Pressure+Humidity sensor.
Definition: bme280_base.h:60
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition: bme280_base.h:64