ESPHome  2022.11.3
qmp6988.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/log.h"
5 #include "esphome/core/hal.h"
6 #include "esphome/core/helpers.h"
9 
10 namespace esphome {
11 namespace qmp6988 {
12 
13 #define QMP6988_U16_t unsigned short
14 #define QMP6988_S16_t short
15 #define QMP6988_U32_t unsigned int
16 #define QMP6988_S32_t int
17 #define QMP6988_U64_t unsigned long long
18 #define QMP6988_S64_t long long
19 
20 /* oversampling */
30 };
31 
32 /* filter */
40 };
41 
42 using qmp6988_cali_data_t = struct Qmp6988CaliData {
43  QMP6988_S32_t COE_a0;
44  QMP6988_S16_t COE_a1;
45  QMP6988_S16_t COE_a2;
46  QMP6988_S32_t COE_b00;
47  QMP6988_S16_t COE_bt1;
48  QMP6988_S16_t COE_bt2;
49  QMP6988_S16_t COE_bp1;
50  QMP6988_S16_t COE_b11;
51  QMP6988_S16_t COE_bp2;
52  QMP6988_S16_t COE_b12;
53  QMP6988_S16_t COE_b21;
54  QMP6988_S16_t COE_bp3;
55 };
56 
57 using qmp6988_fk_data_t = struct Qmp6988FkData {
58  float a0, b00;
59  float a1, a2, bt1, bt2, bp1, b11, bp2, b12, b21, bp3;
60 };
61 
62 using qmp6988_ik_data_t = struct Qmp6988IkData {
63  QMP6988_S32_t a0, b00;
64  QMP6988_S32_t a1, a2;
65  QMP6988_S64_t bt1, bt2, bp1, b11, bp2, b12, b21, bp3;
66 };
67 
68 using qmp6988_data_t = struct Qmp6988Data {
69  uint8_t chip_id;
70  uint8_t power_mode;
71  float temperature;
72  float pressure;
73  float altitude;
76 };
77 
79  public:
80  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
81  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
82 
83  void setup() override;
84  void dump_config() override;
85  float get_setup_priority() const override;
86  void update() override;
87 
88  void set_iir_filter(QMP6988IIRFilter iirfilter);
89  void set_temperature_oversampling(QMP6988Oversampling oversampling_t);
90  void set_pressure_oversampling(QMP6988Oversampling oversampling_p);
91 
92  protected:
94  sensor::Sensor *temperature_sensor_{nullptr};
95  sensor::Sensor *pressure_sensor_{nullptr};
96 
97  QMP6988Oversampling temperature_oversampling_{QMP6988_OVERSAMPLING_16X};
100 
101  void software_reset_();
102  bool get_calibration_data_();
103  bool device_check_();
104  void set_power_mode_(uint8_t power_mode);
105  void write_oversampling_temperature_(unsigned char oversampling_t);
106  void write_oversampling_pressure_(unsigned char oversampling_p);
107  void write_filter_(unsigned char filter);
108  void calculate_pressure_();
109  void calculate_altitude_(float pressure, float temp);
110 
111  QMP6988_S32_t get_compensated_pressure_(qmp6988_ik_data_t *ik, QMP6988_S32_t dp, QMP6988_S16_t tx);
112  QMP6988_S16_t get_compensated_temperature_(qmp6988_ik_data_t *ik, QMP6988_S32_t dt);
113 };
114 
115 } // namespace qmp6988
116 } // namespace esphome
void setup()
QMP6988_S16_t COE_bt1
Definition: qmp6988.h:47
float pressure
Definition: qmp6988.h:72
struct Qmp6988IkData { QMP6988_S32_t a0, b00 qmp6988_ik_data_t
Definition: qmp6988.h:63
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: qmp6988.h:81
float altitude
Definition: qmp6988.h:73
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: qmp6988.h:80
uint8_t power_mode
Definition: qmp6988.h:70
qmp6988_cali_data_t qmp6988_cali
Definition: qmp6988.h:74
QMP6988_S16_t COE_b11
Definition: qmp6988.h:50
float temperature
Definition: qmp6988.h:71
This class simplifies creating components that periodically check a state.
Definition: component.h:267
QMP6988_S16_t COE_b12
Definition: qmp6988.h:52
struct Qmp6988Data { uint8_t chip_id qmp6988_data_t
Definition: qmp6988.h:69
struct Qmp6988FkData { float a0, b00 qmp6988_fk_data_t
Definition: qmp6988.h:58
struct Qmp6988CaliData { QMP6988_S32_t COE_a0 qmp6988_cali_data_t
Definition: qmp6988.h:43
QMP6988_S16_t COE_bp2
Definition: qmp6988.h:51
QMP6988_S32_t COE_b00
Definition: qmp6988.h:46
qmp6988_ik_data_t ik
Definition: qmp6988.h:75
QMP6988_S16_t COE_bp1
Definition: qmp6988.h:49
Definition: a4988.cpp:4
QMP6988_S16_t COE_bt2
Definition: qmp6988.h:48
Base-class for all sensors.
Definition: sensor.h:48
QMP6988_S16_t COE_a2
Definition: qmp6988.h:45
QMP6988_S16_t COE_a1
Definition: qmp6988.h:44
QMP6988_S16_t COE_bp3
Definition: qmp6988.h:54
QMP6988_S16_t COE_b21
Definition: qmp6988.h:53