1
0

Add light sensor driver

This commit is contained in:
Christian Loch 2021-02-11 00:30:36 +01:00
parent 42af035ae6
commit b9ffab5c2b
2 changed files with 13 additions and 0 deletions

View File

@ -122,6 +122,17 @@ void read_sensor2(int32_t* temp, uint32_t* pressure, uint32_t* humidity) {
*humidity = comp_data.humidity; *humidity = comp_data.humidity;
} }
double read_light_sensor() {
uint8_t raw_high = 0;
i2c_read(0x4a, 0x03, &raw_high, 1);
uint8_t exp = raw_high >> 4;
uint8_t mant = raw_high & 0b00001111;
return pow(2, exp) * mant * 0.72;
}
void init_sensors() void init_sensors()
{ {
// INIT SENSOR // INIT SENSOR

View File

@ -11,9 +11,11 @@
#include "bme280.h" #include "bme280.h"
#include "bme280_defs.h" #include "bme280_defs.h"
#include "driver/i2c.h" #include "driver/i2c.h"
#include "math.h"
void init_sensors(); void init_sensors();
void read_sensor2(int32_t* temp, uint32_t* pressure, uint32_t* humidity); void read_sensor2(int32_t* temp, uint32_t* pressure, uint32_t* humidity);
void read_sensor(int32_t* temp, uint32_t* pressure, uint32_t* humidity); void read_sensor(int32_t* temp, uint32_t* pressure, uint32_t* humidity);
double read_light_sensor();
#endif /* COMPONENTS_SENSORS_SENSORS_H_ */ #endif /* COMPONENTS_SENSORS_SENSORS_H_ */