-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathi2c_bh1750fvi_tr.h
49 lines (39 loc) · 1.29 KB
/
i2c_bh1750fvi_tr.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
40
41
42
43
44
45
46
#ifndef i2c_bh1750fvi_tr_h
#define i2c_bh1750fvi_tr_h
#include <Wire.h>
#include <M5_DLight.h> // https://github.com/m5stack/M5-DLight/
#include "NmeaXDR.h"
#include "Nmea0183Msg.h"
#define BH1750FVI_TR_I2C_ADDR 0x23
M5_DLight i2c_bh1750fvi_tr_sensor(BH1750FVI_TR_I2C_ADDR);
void i2c_bh1750fvi_tr_report() {
uint16_t lux = i2c_bh1750fvi_tr_sensor.getLUX();
gen_nmea0183_xdr("$BBXDR,X,%.1f,L,ILLU", (float)lux);
}
bool i2c_bh1750fvi_tr_try_init() {
bool i2c_bh1750fvi_tr_found = false;
for (int i = 0; i < 3; i++) {
Wire.beginTransmission(BH1750FVI_TR_I2C_ADDR);
i2c_bh1750fvi_tr_found = !Wire.endTransmission();
if (i2c_bh1750fvi_tr_found) {
i2c_bh1750fvi_tr_sensor.begin();
break;
}
delay(10);
}
if (i2c_bh1750fvi_tr_found) {
gen_nmea0183_msg("$BBTXT,01,01,01,ENVIRONMENT found bh1750fvi-tr sensor at address=0x%s", String(BH1750FVI_TR_I2C_ADDR, HEX).c_str());
// CONTINUOUSLY_H_RESOLUTION_MODE
// CONTINUOUSLY_H_RESOLUTION_MODE2
// CONTINUOUSLY_L_RESOLUTION_MODE
// ONE_TIME_H_RESOLUTION_MODE
// ONE_TIME_H_RESOLUTION_MODE2
// ONE_TIME_L_RESOLUTION_MODE
i2c_bh1750fvi_tr_sensor.setMode(CONTINUOUSLY_L_RESOLUTION_MODE);
app.onRepeat(2000, []() {
i2c_bh1750fvi_tr_report();
});
}
return i2c_bh1750fvi_tr_found;
}
#endif