LibDriver SEN5X
Loading...
Searching...
No Matches
driver_sen5x_basic.c
Go to the documentation of this file.
1
36
37#include "driver_sen5x_basic.h"
38
39static sen5x_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
61
62 /* set the type */
63 res = sen5x_set_type(&gs_handle, type);
64 if (res != 0)
65 {
66 sen5x_interface_debug_print("sen5x: set type failed.\n");
67
68 return 1;
69 }
70
71 /* init the chip */
72 res = sen5x_init(&gs_handle);
73 if (res != 0)
74 {
75 sen5x_interface_debug_print("sen5x: init failed.\n");
76
77 return 1;
78 }
79
80 /* set auto cleaning interval */
82 if (res != 0)
83 {
84 sen5x_interface_debug_print("sen5x: set auto cleaning interval failed.\n");
85 (void)sen5x_deinit(&gs_handle);
86
87 return 1;
88 }
89
90 /* start measurement */
91 res = sen5x_start_measurement(&gs_handle);
92 if (res != 0)
93 {
94 sen5x_interface_debug_print("sen5x: start measurement failed.\n");
95 (void)sen5x_deinit(&gs_handle);
96
97 return 1;
98 }
99
100 return 0;
101}
102
111{
112 uint8_t res;
113
114 /* stop measurement */
115 res = sen5x_stop_measurement(&gs_handle);
116 if (res != 0)
117 {
118 return 1;
119 }
120
121 /* deinit */
122 res = sen5x_deinit(&gs_handle);
123 if (res != 0)
124 {
125 return 1;
126 }
127
128 return 0;
129}
130
140{
141 uint8_t res;
142
143 /* read raw value */
144 res = sen5x_read_raw_value(&gs_handle, raw);
145 if (res != 0)
146 {
147 return 1;
148 }
149
150 return 0;
151}
152
162{
163 uint8_t res;
164
165 /* read pm value */
166 res = sen5x_read_pm_value(&gs_handle, pm);
167 if (res != 0)
168 {
169 return 1;
170 }
171
172 return 0;
173}
174
184{
185 uint8_t res;
186
187 /* read data */
188 res = sen55_read(&gs_handle, output);
189 if (res != 0)
190 {
191 return 1;
192 }
193
194 return 0;
195}
196
206{
207 uint8_t res;
208
209 /* read data */
210 res = sen54_read(&gs_handle, output);
211 if (res != 0)
212 {
213 return 1;
214 }
215
216 return 0;
217}
218
228{
229 uint8_t res;
230
231 /* read data */
232 res = sen50_read(&gs_handle, output);
233 if (res != 0)
234 {
235 return 1;
236 }
237
238 return 0;
239}
240
249{
250 if (sen5x_start_fan_cleaning(&gs_handle) != 0)
251 {
252 return 1;
253 }
254
255 return 0;
256}
257
265uint8_t sen5x_basic_reset(void)
266{
267 if (sen5x_reset(&gs_handle) != 0)
268 {
269 return 1;
270 }
271
272 return 0;
273}
274
283uint8_t sen5x_basic_get_product_name(char name[32])
284{
285 if (sen5x_get_product_name(&gs_handle, name) != 0)
286 {
287 return 1;
288 }
289
290 return 0;
291}
292
302{
303 if (sen5x_get_serial_number(&gs_handle, sn) != 0)
304 {
305 return 1;
306 }
307
308 return 0;
309}
310
319uint8_t sen5x_basic_get_version(uint8_t *version)
320{
321 if (sen5x_get_version(&gs_handle, version) != 0)
322 {
323 return 1;
324 }
325
326 return 0;
327}
328
337uint8_t sen5x_basic_get_status(uint32_t *status)
338{
339 if (sen5x_get_device_status(&gs_handle, status) != 0)
340 {
341 return 1;
342 }
343 else
344 {
345 if (sen5x_clear_device_status(&gs_handle) != 0)
346 {
347 return 1;
348 }
349
350 return 0;
351 }
352}
driver sen5x basic header file
struct sen50_data_s sen50_data_t
sen50 data structure definition
uint8_t sen5x_read_pm_value(sen5x_handle_t *handle, sen5x_pm_t *pm)
read the pm value
uint8_t sen5x_read_raw_value(sen5x_handle_t *handle, sen5x_raw_t *raw)
read raw value
uint8_t sen55_read(sen5x_handle_t *handle, sen55_data_t *output)
read the result
uint8_t sen5x_set_type(sen5x_handle_t *handle, sen5x_type_t type)
set the chip type
uint8_t sen54_read(sen5x_handle_t *handle, sen54_data_t *output)
read the result
uint8_t sen5x_get_device_status(sen5x_handle_t *handle, uint32_t *status)
get the device status
uint8_t sen5x_start_fan_cleaning(sen5x_handle_t *handle)
start the fan cleaning
uint8_t sen5x_get_version(sen5x_handle_t *handle, uint8_t *version)
get the version
uint8_t sen5x_start_measurement(sen5x_handle_t *handle)
start the measurement
uint8_t sen50_read(sen5x_handle_t *handle, sen50_data_t *output)
read the result
uint8_t sen5x_reset(sen5x_handle_t *handle)
reset the chip
sen5x_type_t
sen5x type enumeration definition
uint8_t sen5x_deinit(sen5x_handle_t *handle)
close the chip
uint8_t sen5x_get_serial_number(sen5x_handle_t *handle, char sn[32])
get the serial number
struct sen5x_handle_s sen5x_handle_t
sen5x handle structure definition
uint8_t sen5x_get_product_name(sen5x_handle_t *handle, char name[32])
get the product name
uint8_t sen5x_clear_device_status(sen5x_handle_t *handle)
clear the device status
struct sen55_data_s sen55_data_t
sen55 data structure definition
struct sen5x_raw_s sen5x_raw_t
sen5x raw structure definition
struct sen54_data_s sen54_data_t
sen54 data structure definition
struct sen5x_pm_s sen5x_pm_t
sen5x pm structure definition
uint8_t sen5x_init(sen5x_handle_t *handle)
initialize the chip
uint8_t sen5x_set_auto_cleaning_interval(sen5x_handle_t *handle, uint32_t second)
set the auto cleaning interval
uint8_t sen5x_stop_measurement(sen5x_handle_t *handle)
stop the measurement
uint8_t sen5x_basic_reset(void)
basic example reset
uint8_t sen50_basic_read(sen50_data_t *output)
basic example read
uint8_t sen5x_basic_get_status(uint32_t *status)
basic example get the status
uint8_t sen55_basic_read_pm_value(sen5x_pm_t *pm)
basic example read pm value
uint8_t sen5x_basic_get_serial_number(char sn[32])
basic example get the serial number
uint8_t sen54_basic_read(sen54_data_t *output)
basic example read
#define SEN5X_BASIC_DEFAULT_AUTO_CLEANING_INTERVAL
sen5x basic example default definition
uint8_t sen5x_basic_get_version(uint8_t *version)
basic example get the version
uint8_t sen5x_basic_start_fan_cleaning(void)
basic example start fan cleaning
uint8_t sen5x_basic_init(sen5x_type_t type)
basic example init
uint8_t sen55_basic_read_raw_value(sen5x_raw_t *raw)
basic example read raw value
uint8_t sen5x_basic_deinit(void)
basic example deinit
uint8_t sen5x_basic_get_product_name(char name[32])
basic example get the product name
uint8_t sen55_basic_read(sen55_data_t *output)
basic example read
uint8_t sen5x_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t sen5x_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t sen5x_interface_iic_init(void)
interface iic bus init
uint8_t sen5x_interface_iic_deinit(void)
interface iic bus deinit
void sen5x_interface_delay_ms(uint32_t ms)
interface delay ms
void sen5x_interface_debug_print(const char *const fmt,...)
interface print format data