-
Notifications
You must be signed in to change notification settings - Fork 0
/
light-sensor.h
52 lines (44 loc) · 999 Bytes
/
light-sensor.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
47
48
49
50
51
52
#pragma once
#include <iostream>
#include <wiringPiI2C.h>
#include <thread>
#include <chrono>
#define DEVICE_ID (0x29)
#define SENSOR_COMMAND (0xA0)
#define SENSOR_ENABLE_POWERON (0x01)
#define SENSOR_ENABLE_POWEROFF (0x00)
#define SENSOR_ENABLE_AEN (0x02)
#define SENSOR_LUX_DF (408.0F)
#define SENSOR_LUX_COEFB (1.64F)
#define SENSOR_LUX_COEFC (0.59F)
#define SENSOR_LUX_COEFD (0.86F)
enum
{
SENSOR_REGISTER_ENABLE = 0x00,
SENSOR_REGISTER_C0DATAL = 0x14,
SENSOR_REGISTER_C0DATAH = 0x15,
SENSOR_REGISTER_C1DATAL = 0x16,
SENSOR_REGISTER_C1DATAH = 0x17
};
struct LightData
{
uint16_t visible;
uint16_t infrared;
uint16_t fullSpectrum;
uint32_t lux;
};
class LightSensor
{
public:
LightSensor(int32_t sensorId = -1);
LightData getLightData();
private:
uint32_t getLuminosity();
uint32_t calcLux(uint16_t ch0, uint16_t ch1);
bool init();
void start();
void stop();
int32_t _sensorId;
bool _initialized;
int _i2cId;
};