Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_opt3001.h
1 #ifndef _BC_OPT3001_H
2 #define _BC_OPT3001_H
3 
4 #include <bc_i2c.h>
5 #include <bc_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef struct bc_opt3001_t bc_opt3001_t;
26 
28 
29 typedef enum
30 {
31  BC_OPT3001_STATE_ERROR = -1,
32  BC_OPT3001_STATE_INITIALIZE = 0,
33  BC_OPT3001_STATE_MEASURE = 1,
34  BC_OPT3001_STATE_READ = 2,
35  BC_OPT3001_STATE_UPDATE = 3
36 
37 } bc_opt3001_state_t;
38 
39 struct bc_opt3001_t
40 {
41  bc_i2c_channel_t _i2c_channel;
42  uint8_t _i2c_address;
43  bc_scheduler_task_id_t _task_id_interval;
44  bc_scheduler_task_id_t _task_id_measure;
45  void (*_event_handler)(bc_opt3001_t *, bc_opt3001_event_t, void *);
46  void *_event_param;
47  bool _measurement_active;
48  bc_tick_t _update_interval;
49  bc_opt3001_state_t _state;
50  bc_tick_t _tick_ready;
51  bool _illuminance_valid;
52  uint16_t _reg_result;
53 };
54 
56 
61 
62 void bc_opt3001_init(bc_opt3001_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
63 
68 
69 void bc_opt3001_set_event_handler(bc_opt3001_t *self, void (*event_handler)(bc_opt3001_t *, bc_opt3001_event_t, void *), void *event_param);
70 
74 
76 
81 
83 
89 
90 bool bc_opt3001_get_illuminance_raw(bc_opt3001_t *self, uint16_t *raw);
91 
97 
98 bool bc_opt3001_get_illuminance_lux(bc_opt3001_t *self, float *lux);
99 
101 
102 #endif // _BC_OPT3001_H
void bc_opt3001_set_event_handler(bc_opt3001_t *self, void(*event_handler)(bc_opt3001_t *, bc_opt3001_event_t, void *), void *event_param)
Set callback function.
Definition: bc_opt3001.c:26
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
void bc_opt3001_set_update_interval(bc_opt3001_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_opt3001.c:32
bool bc_opt3001_measure(bc_opt3001_t *self)
Start measurement manually.
Definition: bc_opt3001.c:48
bool bc_opt3001_get_illuminance_lux(bc_opt3001_t *self, float *lux)
Get measured illuminance in lux.
Definition: bc_opt3001.c:74
void bc_opt3001_init(bc_opt3001_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize OPT3001 driver.
Definition: bc_opt3001.c:11
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bool bc_opt3001_get_illuminance_raw(bc_opt3001_t *self, uint16_t *raw)
Get measured illuminance as raw value.
Definition: bc_opt3001.c:62
bc_opt3001_event_t
Callback events.
Definition: bc_opt3001.h:13
Error event.
Definition: bc_opt3001.h:16
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
struct bc_opt3001_t bc_opt3001_t
OPT3001 instance.
Definition: bc_opt3001.h:25
Update event.
Definition: bc_opt3001.h:19