LibDriver SPS30
Loading...
Searching...
No Matches
driver_sps30_basic.c
Go to the documentation of this file.
1
36
37#include "driver_sps30_basic.h"
38
39static sps30_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
66
67 /* set the interface */
68 res = sps30_set_interface(&gs_handle, interface);
69 if (res != 0)
70 {
71 sps30_interface_debug_print("sps30: set interface failed.\n");
72
73 return 1;
74 }
75
76 /* init the chip */
77 res = sps30_init(&gs_handle);
78 if (res != 0)
79 {
80 sps30_interface_debug_print("sps30: init failed.\n");
81
82 return 1;
83 }
84
85 /* set auto cleaning interval */
87 if (res != 0)
88 {
89 sps30_interface_debug_print("sps30: set auto cleaning interval failed.\n");
90 (void)sps30_deinit(&gs_handle);
91
92 return 1;
93 }
94
95 /* start measurement */
97 if (res != 0)
98 {
99 sps30_interface_debug_print("sps30: start measurement failed.\n");
100 (void)sps30_deinit(&gs_handle);
101
102 return 1;
103 }
104
105 return 0;
106}
107
116{
117 uint8_t res;
118
119 /* stop measurement */
120 res = sps30_stop_measurement(&gs_handle);
121 if (res != 0)
122 {
123 return 1;
124 }
125
126 /* deinit */
127 res = sps30_deinit(&gs_handle);
128 if (res != 0)
129 {
130 return 1;
131 }
132
133 return 0;
134}
135
145{
146 uint8_t res;
147
148 /* read data */
149 res = sps30_read(&gs_handle, pm);
150 if (res != 0)
151 {
152 return 1;
153 }
154 else
155 {
156 return 0;
157 }
158}
159
168{
169 if (sps30_start_fan_cleaning(&gs_handle) != 0)
170 {
171 return 1;
172 }
173 else
174 {
175 return 0;
176 }
177}
178
186uint8_t sps30_basic_reset(void)
187{
188 if (sps30_reset(&gs_handle) != 0)
189 {
190 return 1;
191 }
192 else
193 {
194 return 0;
195 }
196}
197
205uint8_t sps30_basic_sleep(void)
206{
207 if (sps30_sleep(&gs_handle) != 0)
208 {
209 return 1;
210 }
211 else
212 {
213 return 0;
214 }
215}
216
225{
226 if (sps30_wake_up(&gs_handle) != 0)
227 {
228 return 1;
229 }
230 else
231 {
232 return 0;
233 }
234}
235
244uint8_t sps30_basic_get_product_type(char type[9])
245{
246 if (sps30_get_product_type(&gs_handle, type) != 0)
247 {
248 return 1;
249 }
250 else
251 {
252 return 0;
253 }
254}
255
265{
266 if (sps30_get_serial_number(&gs_handle, sn) != 0)
267 {
268 return 1;
269 }
270 else
271 {
272 return 0;
273 }
274}
275
285uint8_t sps30_basic_get_version(uint8_t *major, uint8_t *minor)
286{
287 if (sps30_get_version(&gs_handle, major, minor) != 0)
288 {
289 return 1;
290 }
291 else
292 {
293 return 0;
294 }
295}
296
305uint8_t sps30_basic_get_status(uint32_t *status)
306{
307 if (sps30_get_device_status(&gs_handle, status) != 0)
308 {
309 return 1;
310 }
311 else
312 {
313 if (sps30_clear_device_status(&gs_handle) != 0)
314 {
315 return 1;
316 }
317 else
318 {
319 return 0;
320 }
321 }
322}
driver sps30 basic header file
uint8_t sps30_set_auto_cleaning_interval(sps30_handle_t *handle, uint32_t second)
set the auto cleaning interval
uint8_t sps30_start_fan_cleaning(sps30_handle_t *handle)
start the fan cleaning
uint8_t sps30_read(sps30_handle_t *handle, sps30_pm_t *pm)
read the result
uint8_t sps30_wake_up(sps30_handle_t *handle)
wake up the chip
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
uint8_t sps30_get_product_type(sps30_handle_t *handle, char type[9])
get the product type
uint8_t sps30_get_device_status(sps30_handle_t *handle, uint32_t *status)
get the device status
uint8_t sps30_reset(sps30_handle_t *handle)
reset the chip
struct sps30_handle_s sps30_handle_t
sps30 handle structure definition
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_sleep(sps30_handle_t *handle)
enter the sleep mode
uint8_t sps30_set_interface(sps30_handle_t *handle, sps30_interface_t interface)
set the chip interface
uint8_t sps30_clear_device_status(sps30_handle_t *handle)
clear the device status
struct sps30_pm_s sps30_pm_t
sps30 pm structure definition
uint8_t sps30_get_version(sps30_handle_t *handle, uint8_t *major, uint8_t *minor)
get the version
uint8_t sps30_get_serial_number(sps30_handle_t *handle, char sn[17])
get the serial number
uint8_t sps30_basic_get_status(uint32_t *status)
basic example get the status
uint8_t sps30_basic_get_serial_number(char sn[17])
basic example get the serial number
uint8_t sps30_basic_wake_up(void)
basic example wake up
uint8_t sps30_basic_sleep(void)
basic example sleep
uint8_t sps30_basic_start_fan_cleaning(void)
basic example start fan cleaning
uint8_t sps30_basic_get_product_type(char type[9])
basic example get the product type
uint8_t sps30_basic_init(sps30_interface_t interface)
basic example init
uint8_t sps30_basic_reset(void)
basic example reset
#define SPS30_BASIC_DEFAULT_FORMAT
sps30 basic example default definition
uint8_t sps30_basic_read(sps30_pm_t *pm)
basic example read
uint8_t sps30_basic_get_version(uint8_t *major, uint8_t *minor)
basic example get the version
uint8_t sps30_basic_deinit(void)
basic example deinit
#define SPS30_BASIC_DEFAULT_AUTO_CLEANING_INTERVAL
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