Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_sgp30.h
1 #ifndef _BC_SGP30_H
2 #define _BC_SGP30_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_sgp30_t bc_sgp30_t;
26 
28 
29 typedef enum
30 {
31  BC_SGP30_STATE_ERROR = -1,
32  BC_SGP30_STATE_INITIALIZE = 0,
33  BC_SGP30_STATE_GET_FEATURE_SET = 1,
34  BC_SGP30_STATE_READ_FEATURE_SET = 2,
35  BC_SGP30_STATE_INIT_AIR_QUALITY = 3,
36  BC_SGP30_STATE_SET_HUMIDITY = 4,
37  BC_SGP30_STATE_MEASURE_AIR_QUALITY = 5,
38  BC_SGP30_STATE_READ_AIR_QUALITY = 6
39 
40 } bc_sgp30_state_t;
41 
42 struct bc_sgp30_t
43 {
44  bc_i2c_channel_t _i2c_channel;
45  uint8_t _i2c_address;
46  bc_scheduler_task_id_t _task_id_interval;
47  bc_scheduler_task_id_t _task_id_measure;
48  void (*_event_handler)(bc_sgp30_t *, bc_sgp30_event_t, void *);
49  void *_event_param;
50  bc_tick_t _update_interval;
51  bc_sgp30_state_t _state;
52  bc_tick_t _tick_ready;
53  bc_tick_t _tick_last_measurement;
54  bool _hit_error;
55  bool _measurement_valid;
56  uint16_t _co2eq;
57  uint16_t _tvoc;
58  uint16_t _ah_scaled;
59 };
60 
62 
67 
68 void bc_sgp30_init(bc_sgp30_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
69 
74 
75 void bc_sgp30_set_event_handler(bc_sgp30_t *self, void (*event_handler)(bc_sgp30_t *, bc_sgp30_event_t, void *), void *event_param);
76 
80 
82 
87 
88 bool bc_sgp30_measure(bc_sgp30_t *self);
89 
95 
96 bool bc_sgp30_get_co2eq_ppm(bc_sgp30_t *self, uint16_t *ppm);
97 
103 
104 bool bc_sgp30_get_tvoc_ppb(bc_sgp30_t *self, uint16_t *ppb);
105 
111 
112 float bc_sgp30_set_compensation(bc_sgp30_t *self, float *t_celsius, float *rh_percentage);
113 
115 
116 #endif // _BC_SGP30_H
void bc_sgp30_set_update_interval(bc_sgp30_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sgp30.c:38
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
bool bc_sgp30_get_co2eq_ppm(bc_sgp30_t *self, uint16_t *ppm)
Get measured CO2eq in ppm (parts per million)
Definition: bc_sgp30.c:73
void bc_sgp30_set_event_handler(bc_sgp30_t *self, void(*event_handler)(bc_sgp30_t *, bc_sgp30_event_t, void *), void *event_param)
Set callback function.
Definition: bc_sgp30.c:32
struct bc_sgp30_t bc_sgp30_t
SGP30 instance.
Definition: bc_sgp30.h:25
bc_sgp30_event_t
Callback events.
Definition: bc_sgp30.h:13
bool bc_sgp30_measure(bc_sgp30_t *self)
Start measurement manually.
Definition: bc_sgp30.c:54
Error event.
Definition: bc_sgp30.h:16
float bc_sgp30_set_compensation(bc_sgp30_t *self, float *t_celsius, float *rh_percentage)
Set sensor compensation (absolute humidity is calculated from temperature and relative humidity) ...
Definition: bc_sgp30.c:97
void bc_sgp30_init(bc_sgp30_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SGP30.
Definition: bc_sgp30.c:17
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
Update event.
Definition: bc_sgp30.h:19
bool bc_sgp30_get_tvoc_ppb(bc_sgp30_t *self, uint16_t *ppb)
Get measured TVOC in ppb (parts per billion)
Definition: bc_sgp30.c:85