Browse Source

Add light sensor driver

master
Christian Loch 3 years ago
parent
commit
b9ffab5c2b
2 changed files with 13 additions and 0 deletions
  1. +11
    -0
      components/sensors/sensors.c
  2. +2
    -0
      components/sensors/sensors.h

+ 11
- 0
components/sensors/sensors.c View File

@@ -122,6 +122,17 @@ void read_sensor2(int32_t* temp, uint32_t* pressure, uint32_t* 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()
{
// INIT SENSOR


+ 2
- 0
components/sensors/sensors.h View File

@@ -11,9 +11,11 @@
#include "bme280.h"
#include "bme280_defs.h"
#include "driver/i2c.h"
#include "math.h"

void init_sensors();
void read_sensor2(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_ */

Loading…
Cancel
Save