LibDriver SPS30
Loading...
Searching...
No Matches
driver_sps30_read_test.c
Go to the documentation of this file.
1
36
38
39static sps30_handle_t gs_handle;
40
50uint8_t sps30_read_test(sps30_interface_t interface, uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 sps30_info_t info;
55 sps30_pm_t pm;
56
57 /* link functions */
70
71 /* get information */
72 res = sps30_info(&info);
73 if (res != 0)
74 {
75 sps30_interface_debug_print("sps30: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 sps30_interface_debug_print("sps30: chip is %s.\n", info.chip_name);
83 sps30_interface_debug_print("sps30: manufacturer is %s.\n", info.manufacturer_name);
84 sps30_interface_debug_print("sps30: interface is %s.\n", info.interface);
85 sps30_interface_debug_print("sps30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 sps30_interface_debug_print("sps30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 sps30_interface_debug_print("sps30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 sps30_interface_debug_print("sps30: max current is %0.2fmA.\n", info.max_current_ma);
89 sps30_interface_debug_print("sps30: max temperature is %0.1fC.\n", info.temperature_max);
90 sps30_interface_debug_print("sps30: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 sps30_interface_debug_print("sps30: start read test.\n");
95
96 /* set the interface */
97 res = sps30_set_interface(&gs_handle, interface);
98 if (res != 0)
99 {
100 sps30_interface_debug_print("sps30: set interface failed.\n");
101
102 return 1;
103 }
104
105 /* init the chip */
106 res = sps30_init(&gs_handle);
107 if (res != 0)
108 {
109 sps30_interface_debug_print("sps30: init failed.\n");
110
111 return 1;
112 }
113
114 /* set auto cleaning interval */
115 res = sps30_set_auto_cleaning_interval(&gs_handle, 3600 * 24);
116 if (res != 0)
117 {
118 sps30_interface_debug_print("sps30: set auto cleaning interval failed.\n");
119 (void)sps30_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* IEEE754 read test */
125 sps30_interface_debug_print("sps30: IEEE754 read test.\n");
126
127 /* start measurement */
129 if (res != 0)
130 {
131 sps30_interface_debug_print("sps30: start measurement failed.\n");
132 (void)sps30_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* delay 2000 ms */
139
140 for (i = 0; i < times; i++)
141 {
142 res = sps30_read(&gs_handle, &pm);
143 if (res != 0)
144 {
145 sps30_interface_debug_print("sps30: read failed.\n");
146 (void)sps30_deinit(&gs_handle);
147
148 return 1;
149 }
150 sps30_interface_debug_print("sps30: pm1.0 is %0.2f ug/m3.\n", pm.pm1p0_ug_m3);
151 sps30_interface_debug_print("sps30: pm2.5 is %0.2f ug/m3.\n", pm.pm2p5_ug_m3);
152 sps30_interface_debug_print("sps30: pm4.0 is %0.2f ug/m3.\n", pm.pm4p0_ug_m3);
153 sps30_interface_debug_print("sps30: pm10.0 is %0.2f ug/m3.\n", pm.pm10_ug_m3);
154 sps30_interface_debug_print("sps30: pm0.5 is %0.2f cm3.\n", pm.pm0p5_cm3);
155 sps30_interface_debug_print("sps30: pm1.0 is %0.2f cm3.\n", pm.pm1p0_cm3);
156 sps30_interface_debug_print("sps30: pm2.5 is %0.2f cm3.\n", pm.pm2p5_cm3);
157 sps30_interface_debug_print("sps30: pm4.0 is %0.2f cm3.\n", pm.pm4p0_cm3);
158 sps30_interface_debug_print("sps30: pm10.0 is %0.2f cm3.\n", pm.pm10_cm3);
159 sps30_interface_debug_print("sps30: typical is %0.2f um.\n", pm.typical_particle_um);
160
161 /* delay 2000 ms */
163 }
164
165 /* stop measurement */
166 res = sps30_stop_measurement(&gs_handle);
167 if (res != 0)
168 {
169 sps30_interface_debug_print("sps30: stop measurement failed.\n");
170 (void)sps30_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* delay 2000 ms */
177
178 /* UINT16 read test */
179 sps30_interface_debug_print("sps30: UINT16 read test.\n");
180
181 /* start measurement */
183 if (res != 0)
184 {
185 sps30_interface_debug_print("sps30: start measurement failed.\n");
186 (void)sps30_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* delay 2000 ms */
193
194 for (i = 0; i < times; i++)
195 {
196 res = sps30_read(&gs_handle, &pm);
197 if (res != 0)
198 {
199 sps30_interface_debug_print("sps30: read failed.\n");
200 (void)sps30_deinit(&gs_handle);
201
202 return 1;
203 }
204 sps30_interface_debug_print("sps30: pm1.0 is %0.2f ug/m3.\n", pm.pm1p0_ug_m3);
205 sps30_interface_debug_print("sps30: pm2.5 is %0.2f ug/m3.\n", pm.pm2p5_ug_m3);
206 sps30_interface_debug_print("sps30: pm4.0 is %0.2f ug/m3.\n", pm.pm4p0_ug_m3);
207 sps30_interface_debug_print("sps30: pm10.0 is %0.2f ug/m3.\n", pm.pm10_ug_m3);
208 sps30_interface_debug_print("sps30: pm0.5 is %0.2f cm3.\n", pm.pm0p5_cm3);
209 sps30_interface_debug_print("sps30: pm1.0 is %0.2f cm3.\n", pm.pm1p0_cm3);
210 sps30_interface_debug_print("sps30: pm2.5 is %0.2f cm3.\n", pm.pm2p5_cm3);
211 sps30_interface_debug_print("sps30: pm4.0 is %0.2f cm3.\n", pm.pm4p0_cm3);
212 sps30_interface_debug_print("sps30: pm10.0 is %0.2f cm3.\n", pm.pm10_cm3);
213 sps30_interface_debug_print("sps30: typical is %0.2f um.\n", pm.typical_particle_um);
214
215
216 /* delay 2000 ms */
218 }
219
220 /* stop measurement */
221 res = sps30_stop_measurement(&gs_handle);
222 if (res != 0)
223 {
224 sps30_interface_debug_print("sps30: stop measurement failed.\n");
225 (void)sps30_deinit(&gs_handle);
226
227 return 1;
228 }
229
230 /* delay 2000 ms */
232
233 /* finish read test */
234 sps30_interface_debug_print("sps30: finish read test.\n");
235 (void)sps30_deinit(&gs_handle);
236
237 return 0;
238}
driver sps30 read test header file
uint8_t sps30_set_auto_cleaning_interval(sps30_handle_t *handle, uint32_t second)
set the auto cleaning interval
uint8_t sps30_read(sps30_handle_t *handle, sps30_pm_t *pm)
read the result
struct sps30_info_s sps30_info_t
sps30 information structure definition
sps30_interface_t
sps30 interface enumeration definition
uint8_t sps30_start_measurement(sps30_handle_t *handle, sps30_format_t format)
start the measurement
uint8_t sps30_stop_measurement(sps30_handle_t *handle)
stop the measurement
struct sps30_handle_s sps30_handle_t
sps30 handle structure definition
uint8_t sps30_info(sps30_info_t *info)
get chip information
uint8_t sps30_deinit(sps30_handle_t *handle)
close the chip
uint8_t sps30_init(sps30_handle_t *handle)
initialize the chip
uint8_t sps30_set_interface(sps30_handle_t *handle, sps30_interface_t interface)
set the chip interface
struct sps30_pm_s sps30_pm_t
sps30 pm structure definition
@ SPS30_FORMAT_UINT16
@ SPS30_FORMAT_IEEE754
uint8_t sps30_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint16_t sps30_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t sps30_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t sps30_interface_iic_deinit(void)
interface iic bus deinit
void sps30_interface_debug_print(const char *const fmt,...)
interface print format data
void sps30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sps30_interface_iic_init(void)
interface iic bus init
uint8_t sps30_interface_uart_flush(void)
interface uart flush
uint8_t sps30_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t sps30_interface_uart_init(void)
interface uart init
uint8_t sps30_interface_uart_deinit(void)
interface uart deinit
uint8_t sps30_read_test(sps30_interface_t interface, uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
char interface[16]
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]
float pm1p0_cm3
float typical_particle_um
float pm4p0_cm3
float pm1p0_ug_m3
float pm0p5_cm3
float pm4p0_ug_m3
float pm10_ug_m3
float pm2p5_cm3
float pm2p5_ug_m3