Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_sps30.h
1 #ifndef _BC_SPS30_H
2 #define _BC_SPS30_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_sps30_t bc_sps30_t;
26 
28 
29 typedef enum
30 {
31  BC_SPS30_STATE_ERROR = -1,
32  BC_SPS30_STATE_READY = 0,
33  BC_SPS30_STATE_INITIALIZE = 1,
34  BC_SPS30_STATE_GET_SERIAL_NUMBER = 2,
35  BC_SPS30_STATE_READ_SERIAL_NUMBER = 3,
36  BC_SPS30_STATE_START_MEASUREMENT = 4,
37  BC_SPS30_STATE_SET_DATAREADY_FLAG = 5,
38  BC_SPS30_STATE_READ_DATAREADY_FLAG = 6,
39  BC_SPS30_STATE_GET_MEASUREMENT_DATA = 7,
40  BC_SPS30_STATE_READ_MEASUREMENT_DATA = 8,
41  BC_SPS30_STATE_STOP_MEASUREMENT = 9
42 
43 } bc_sps30_state_t;
44 
46 
47 typedef struct
48 {
50  float mc_1p0;
51 
53  float mc_2p5;
54 
56  float mc_4p0;
57 
59  float mc_10p0;
60 
61 } bc_sps30_mass_concentration_t;
62 
64 
65 typedef struct
66 {
68  float nc_0p5;
69 
71  float nc_1p0;
72 
74  float nc_2p5;
75 
77  float nc_4p0;
78 
80  float nc_10p0;
81 
82 } bc_sps30_number_concentration_t;
83 
84 struct bc_sps30_t
85 {
86  bc_i2c_channel_t _i2c_channel;
87  uint8_t _i2c_address;
88  bc_scheduler_task_id_t _task_id_interval;
89  bc_scheduler_task_id_t _task_id_measure;
90  void (*_event_handler)(bc_sps30_t *, bc_sps30_event_t, void *);
91  void *_event_param;
92  bc_tick_t _update_interval;
93  bc_sps30_state_t _state;
94  bool _measurement_valid;
95  bc_sps30_mass_concentration_t _mass_concentration;
96  bc_sps30_number_concentration_t _number_concentration;
97  float _typical_particle_size;
98  bc_tick_t _startup_time;
99  bc_tick_t _start_time;
100 };
101 
103 
108 
109 void bc_sps30_init(bc_sps30_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address);
110 
115 
116 void bc_sps30_set_event_handler(bc_sps30_t *self, void (*event_handler)(bc_sps30_t *, bc_sps30_event_t, void *), void *event_param);
117 
121 
122 void bc_sps30_set_startup_time(bc_sps30_t *self, bc_tick_t startup_time);
123 
127 
129 
134 
135 bool bc_sps30_measure(bc_sps30_t *self);
136 
142 
143 bool bc_sps30_get_mass_concentration(bc_sps30_t *self, bc_sps30_mass_concentration_t *mass_concentration);
144 
150 
151 bool bc_sps30_get_number_concentration(bc_sps30_t *self, bc_sps30_number_concentration_t *number_concentration);
152 
158 
159 bool bc_sps30_get_typical_particle_size(bc_sps30_t *self, float *typical_particle_size);
160 
162 
163 #endif // _BC_SPS30_H
bool bc_sps30_get_typical_particle_size(bc_sps30_t *self, float *typical_particle_size)
Get measured typical particle size in μm.
Definition: bc_sps30.c:106
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Error event.
Definition: bc_sps30.h:16
void bc_sps30_set_event_handler(bc_sps30_t *self, void(*event_handler)(bc_sps30_t *, bc_sps30_event_t, void *), void *event_param)
Set callback function.
Definition: bc_sps30.c:35
void bc_sps30_init(bc_sps30_t *self, bc_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize SPS30.
Definition: bc_sps30.c:20
bool bc_sps30_measure(bc_sps30_t *self)
Start measurement manually.
Definition: bc_sps30.c:60
void bc_sps30_set_startup_time(bc_sps30_t *self, bc_tick_t startup_time)
Set startup time (how long the fan blows air before the measurement)
Definition: bc_sps30.c:41
bool bc_sps30_get_mass_concentration(bc_sps30_t *self, bc_sps30_mass_concentration_t *mass_concentration)
Get measured mass concentration in μg/m3.
Definition: bc_sps30.c:75
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bc_sps30_event_t
Callback events.
Definition: bc_sps30.h:13
bc_i2c_channel_t
I2C channels.
Definition: bc_i2c.h:15
struct bc_sps30_t bc_sps30_t
SPS30 instance.
Definition: bc_sps30.h:25
Update event.
Definition: bc_sps30.h:19
bool bc_sps30_get_number_concentration(bc_sps30_t *self, bc_sps30_number_concentration_t *number_concentration)
Get measured number concentration in #/cm3.
Definition: bc_sps30.c:90
void bc_sps30_set_update_interval(bc_sps30_t *self, bc_tick_t interval)
Set measurement interval.
Definition: bc_sps30.c:46