forked from bareboat-necessities/bbn_esp32_sensors_hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2c_qmp6988.h
39 lines (32 loc) · 1022 Bytes
/
i2c_qmp6988.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef i2c_qmp6988_h
#define i2c_qmp6988_h
#include <M5UnitENV.h>
#include "NmeaXDR.h"
#include "Nmea0183Msg.h"
#define QMP6988_SLAVE_ADDRESS_L (0x70)
#define QMP6988_SLAVE_ADDRESS_H (0x56)
QMP6988 i2c_qmp6988_sensor;
void i2c_qmp6988_report() {
if (i2c_qmp6988_sensor.update()) {
gen_nmea0183_xdr("$BBXDR,C,%.2f,C,TEMP_QMP6988", i2c_qmp6988_sensor.cTemp); // C
gen_nmea0183_xdr("$BBXDR,P,%.2f,P,PRES_QMP6988", i2c_qmp6988_sensor.pressure); // Pa
}
}
bool i2c_qmp6988_try_init() {
bool i2c_qmp6988_found = false;
for (int i = 0; i < 3; i++) {
i2c_qmp6988_found = i2c_qmp6988_sensor.begin(&Wire1, QMP6988_SLAVE_ADDRESS_L, G38, G39, 100000UL);
if (i2c_qmp6988_found) {
break;
}
delay(10);
}
if (i2c_qmp6988_found) {
gen_nmea0183_msg("$BBTXT,01,01,01,ENVIRONMENT found qmp6988 sensor at address=0x%s", String(QMP6988_SLAVE_ADDRESS_L, HEX).c_str());
app.onRepeat(5000, []() {
i2c_qmp6988_report();
});
}
return i2c_qmp6988_found;
}
#endif