Firmware SDK
twr_opt3001.h
1 #ifndef _TWR_OPT3001_H
2 #define _TWR_OPT3001_H
3 
4 #include <twr_i2c.h>
5 #include <twr_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
22 
24 
25 typedef struct twr_opt3001_t twr_opt3001_t;
26 
28 
29 typedef enum
30 {
31  TWR_OPT3001_STATE_ERROR = -1,
32  TWR_OPT3001_STATE_INITIALIZE = 0,
33  TWR_OPT3001_STATE_MEASURE = 1,
34  TWR_OPT3001_STATE_READ = 2,
35  TWR_OPT3001_STATE_UPDATE = 3
36 
37 } twr_opt3001_state_t;
38 
39 struct twr_opt3001_t
40 {
41  twr_i2c_channel_t _i2c_channel;
42  uint8_t _i2c_address;
43  twr_scheduler_task_id_t _task_id_interval;
44  twr_scheduler_task_id_t _task_id_measure;
45  void (*_event_handler)(twr_opt3001_t *, twr_opt3001_event_t, void *);
46  void *_event_param;
47  bool _measurement_active;
48  twr_tick_t _update_interval;
49  twr_opt3001_state_t _state;
50  twr_tick_t _tick_ready;
51  bool _illuminance_valid;
52  uint16_t _reg_result;
53 };
54 
56 
61 
62 void twr_opt3001_init(twr_opt3001_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
63 
66 
68 
73 
74 void twr_opt3001_set_event_handler(twr_opt3001_t *self, void (*event_handler)(twr_opt3001_t *, twr_opt3001_event_t, void *), void *event_param);
75 
79 
81 
86 
88 
94 
95 bool twr_opt3001_get_illuminance_raw(twr_opt3001_t *self, uint16_t *raw);
96 
102 
103 bool twr_opt3001_get_illuminance_lux(twr_opt3001_t *self, float *lux);
104 
106 
107 #endif // _TWR_OPT3001_H
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
void twr_opt3001_init(twr_opt3001_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize OPT3001 driver.
Definition: twr_opt3001.c:11
void twr_opt3001_set_event_handler(twr_opt3001_t *self, void(*event_handler)(twr_opt3001_t *, twr_opt3001_event_t, void *), void *event_param)
Set callback function.
Definition: twr_opt3001.c:35
struct twr_opt3001_t twr_opt3001_t
OPT3001 instance.
Definition: twr_opt3001.h:25
void twr_opt3001_set_update_interval(twr_opt3001_t *self, twr_tick_t interval)
Set measurement interval.
Definition: twr_opt3001.c:41
bool twr_opt3001_get_illuminance_lux(twr_opt3001_t *self, float *lux)
Get measured illuminance in lux.
Definition: twr_opt3001.c:83
void twr_opt3001_deinit(twr_opt3001_t *self)
Deinitialize OPT3001 driver.
Definition: twr_opt3001.c:26
bool twr_opt3001_measure(twr_opt3001_t *self)
Start measurement manually.
Definition: twr_opt3001.c:57
twr_opt3001_event_t
Callback events.
Definition: twr_opt3001.h:14
bool twr_opt3001_get_illuminance_raw(twr_opt3001_t *self, uint16_t *raw)
Get measured illuminance as raw value.
Definition: twr_opt3001.c:71
@ TWR_OPT3001_EVENT_UPDATE
Update event.
Definition: twr_opt3001.h:19
@ TWR_OPT3001_EVENT_ERROR
Error event.
Definition: twr_opt3001.h:16
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16