Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_sgpc3.h
1 #ifndef _BC_SGPC3_H
2 #define _BC_SGPC3_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_sgpc3_t bc_sgpc3_t;
26 
28 
29 typedef enum
30 {
31  BC_SGPC3_STATE_ERROR = -1,
32  BC_SGPC3_STATE_INITIALIZE = 0,
33  BC_SGPC3_STATE_GET_FEATURE_SET = 1,
34  BC_SGPC3_STATE_READ_FEATURE_SET = 2,
35  BC_SGPC3_STATE_SET_POWER_MODE = 3,
36  BC_SGPC3_STATE_INIT_AIR_QUALITY = 4,
37  BC_SGPC3_STATE_SET_HUMIDITY = 5,
38  BC_SGPC3_STATE_MEASURE_AIR_QUALITY = 6,
39  BC_SGPC3_STATE_READ_AIR_QUALITY = 7
40 
41 } bc_sgpc3_state_t;
42 
43 struct bc_sgpc3_t
44 {
45  bc_i2c_channel_t _i2c_channel;
46  uint8_t _i2c_address;
47  bc_scheduler_task_id_t _task_id_interval;
48  bc_scheduler_task_id_t _task_id_measure;
49  void (*_event_handler)(bc_sgpc3_t *, bc_sgpc3_event_t, void *);
50  void *_event_param;
51  bc_tick_t _update_interval;
52  bc_sgpc3_state_t _state;
53  bc_tick_t _tick_ready;
54  bc_tick_t _tick_last_measurement;
55  bool _hit_error;
56  bool _measurement_valid;
57  uint16_t _tvoc;
58  uint16_t _ah_scaled;
59 };
60 
62 
67 
68 void bc_sgpc3_init(bc_sgpc3_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
69 
74 
75 void bc_sgpc3_set_event_handler(bc_sgpc3_t *self, void (*event_handler)(bc_sgpc3_t *, bc_sgpc3_event_t, void *), void *event_param);
76 
80 
82 
87 
88 bool bc_sgpc3_measure(bc_sgpc3_t *self);
89 
95 
96 bool bc_sgpc3_get_tvoc_ppb(bc_sgpc3_t *self, uint16_t *ppb);
97 
103 
104 float bc_sgpc3_set_compensation(bc_sgpc3_t *self, float *t_celsius, float *rh_percentage);
105 
107 
108 #endif // _BC_SGPC3_H
bc_sgpc3_event_t
Callback events.
Definition: bc_sgpc3.h:13
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
void bc_sgpc3_set_update_interval(bc_sgpc3_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sgpc3.c:39
void bc_sgpc3_init(bc_sgpc3_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SGPC3.
Definition: bc_sgpc3.c:18
Update event.
Definition: bc_sgpc3.h:19
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bool bc_sgpc3_get_tvoc_ppb(bc_sgpc3_t *self, uint16_t *ppb)
Get measured TVOC in ppb (parts per billion)
Definition: bc_sgpc3.c:74
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
bool bc_sgpc3_measure(bc_sgpc3_t *self)
Start measurement manually.
Definition: bc_sgpc3.c:55
Error event.
Definition: bc_sgpc3.h:16
void bc_sgpc3_set_event_handler(bc_sgpc3_t *self, void(*event_handler)(bc_sgpc3_t *, bc_sgpc3_event_t, void *), void *event_param)
Set callback function.
Definition: bc_sgpc3.c:33
float bc_sgpc3_set_compensation(bc_sgpc3_t *self, float *t_celsius, float *rh_percentage)
Set sensor compensation (absolute humidity is calculated from temperature and relative humidity) ...
Definition: bc_sgpc3.c:86
struct bc_sgpc3_t bc_sgpc3_t
SGPC3 instance.
Definition: bc_sgpc3.h:25