LibDriver SEN5X
Loading...
Searching...
No Matches
driver_sen5x.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_SEN5X_H
38#define DRIVER_SEN5X_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43#include <math.h>
44
45#ifdef __cplusplus
46extern "C"{
47#endif
48
54
59
63typedef enum
64{
65 SEN50 = 0x00,
66 SEN54 = 0x01,
67 SEN55 = 0x02,
69
78
91
101
125
147
151typedef struct sen50_data_s
152{
153 uint16_t pm1p0_raw;
154 uint16_t pm2p5_raw;
155 uint16_t pm4p0_raw;
156 uint16_t pm10_raw;
157 uint8_t pm_valid;
163
191
195typedef struct sen5x_raw_s
196{
197 int16_t humidity_raw;
199 uint16_t voc_raw;
200 uint16_t nox_raw;
203 float voc;
204 float nox;
206
210typedef struct sen5x_handle_s
211{
212 uint8_t (*iic_init)(void);
213 uint8_t (*iic_deinit)(void);
214 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
215 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
216 void (*delay_ms)(uint32_t ms);
217 void (*debug_print)(const char *const fmt, ...);
218 uint8_t type;
219 uint8_t inited;
221
237
241
248
255#define DRIVER_SEN5X_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
256
263#define DRIVER_SEN5X_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
264
271#define DRIVER_SEN5X_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
272
279#define DRIVER_SEN5X_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
280
287#define DRIVER_SEN5X_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
288
295#define DRIVER_SEN5X_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
296
303#define DRIVER_SEN5X_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
304
308
315
324uint8_t sen5x_info(sen5x_info_t *info);
325
335uint8_t sen5x_set_type(sen5x_handle_t *handle, sen5x_type_t type);
336
346uint8_t sen5x_get_type(sen5x_handle_t *handle, sen5x_type_t *type);
347
359uint8_t sen5x_init(sen5x_handle_t *handle);
360
372uint8_t sen5x_deinit(sen5x_handle_t *handle);
373
385
398
410
423
436uint8_t sen55_read(sen5x_handle_t *handle, sen55_data_t *output);
437
450uint8_t sen54_read(sen5x_handle_t *handle, sen54_data_t *output);
451
464uint8_t sen50_read(sen5x_handle_t *handle, sen50_data_t *output);
465
477uint8_t sen5x_read_pm_value(sen5x_handle_t *handle, sen5x_pm_t *pm);
478
491uint8_t sen5x_read_raw_value(sen5x_handle_t *handle, sen5x_raw_t *raw);
492
506uint8_t sen5x_set_temperature_compensation(sen5x_handle_t *handle, int16_t temperature_offset,
507 int16_t normalized_temperature_offset_slope,
508 uint16_t time_constant);
509
523uint8_t sen5x_get_temperature_compensation(sen5x_handle_t *handle, int16_t *temperature_offset,
524 int16_t *normalized_temperature_offset_slope,
525 uint16_t *time_constant);
526
543 float temperature_offset_degree,
544 float normalized_temperature_offset_slope_factor,
545 float time_constant_second,
546 int16_t *temperature_offset_reg,
547 int16_t *normalized_temperature_offset_slope_reg,
548 uint16_t *time_constant_reg);
549
566 int16_t temperature_offset_reg,
567 int16_t normalized_temperature_offset_slope_reg,
568 uint16_t time_constant_reg,
569 float *temperature_offset_degree,
570 float *normalized_temperature_offset_slope_factor,
571 float *time_constant_second);
572
584uint8_t sen5x_set_warm_start(sen5x_handle_t *handle, uint16_t param);
585
597uint8_t sen5x_get_warm_start(sen5x_handle_t *handle, uint16_t *param);
598
621uint8_t sen5x_set_voc_algorithm_tuning(sen5x_handle_t *handle, int16_t index_offset,
622 int16_t learning_time_offset_hour,
623 int16_t learning_time_gain_hour,
624 int16_t gating_max_duration_minute,
625 int16_t std_initial,
626 int16_t gain_factor);
627
644uint8_t sen5x_get_voc_algorithm_tuning(sen5x_handle_t *handle, int16_t *index_offset,
645 int16_t *learning_time_offset_hour,
646 int16_t *learning_time_gain_hour,
647 int16_t *gating_max_duration_minute,
648 int16_t *std_initial,
649 int16_t *gain_factor);
650
673uint8_t sen5x_set_nox_algorithm_tuning(sen5x_handle_t *handle, int16_t index_offset,
674 int16_t learning_time_offset_hour,
675 int16_t learning_time_gain_hour,
676 int16_t gating_max_duration_minute,
677 int16_t std_initial,
678 int16_t gain_factor);
679
696uint8_t sen5x_get_nox_algorithm_tuning(sen5x_handle_t *handle, int16_t *index_offset,
697 int16_t *learning_time_offset_hour,
698 int16_t *learning_time_gain_hour,
699 int16_t *gating_max_duration_minute,
700 int16_t *std_initial,
701 int16_t *gain_factor);
702
715
728
740uint8_t sen5x_set_voc_algorithm_state(sen5x_handle_t *handle, uint16_t state[4]);
741
753uint8_t sen5x_get_voc_algorithm_state(sen5x_handle_t *handle, uint16_t state[4]);
754
766
779uint8_t sen5x_set_auto_cleaning_interval(sen5x_handle_t *handle, uint32_t second);
780
792uint8_t sen5x_get_auto_cleaning_interval(sen5x_handle_t *handle, uint32_t *second);
793
805
817uint8_t sen5x_get_product_name(sen5x_handle_t *handle, char name[32]);
818
830uint8_t sen5x_get_serial_number(sen5x_handle_t *handle, char sn[32]);
831
843uint8_t sen5x_get_version(sen5x_handle_t *handle, uint8_t *version);
844
856uint8_t sen5x_get_device_status(sen5x_handle_t *handle, uint32_t *status);
857
869
880uint8_t sen5x_reset(sen5x_handle_t *handle);
881
885
892
906uint8_t sen5x_set_reg(sen5x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
907
921uint8_t sen5x_get_reg(sen5x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
922
926
930
931#ifdef __cplusplus
932}
933#endif
934
935#endif
uint8_t sen5x_set_nox_algorithm_tuning(sen5x_handle_t *handle, int16_t index_offset, int16_t learning_time_offset_hour, int16_t learning_time_gain_hour, int16_t gating_max_duration_minute, int16_t std_initial, int16_t gain_factor)
set nox algorithm tuning
uint8_t sen5x_temperature_compensation_convert_to_register(sen5x_handle_t *handle, float temperature_offset_degree, float normalized_temperature_offset_slope_factor, float time_constant_second, int16_t *temperature_offset_reg, int16_t *normalized_temperature_offset_slope_reg, uint16_t *time_constant_reg)
convert the temperature compensation to the register raw data
struct sen50_data_s sen50_data_t
sen50 data structure definition
uint8_t sen5x_info(sen5x_info_t *info)
get chip information
uint8_t sen5x_set_voc_algorithm_state(sen5x_handle_t *handle, uint16_t state[4])
set voc algorithm state
uint8_t sen5x_get_temperature_compensation(sen5x_handle_t *handle, int16_t *temperature_offset, int16_t *normalized_temperature_offset_slope, uint16_t *time_constant)
get temperature compensation
uint8_t sen5x_read_pm_value(sen5x_handle_t *handle, sen5x_pm_t *pm)
read the pm value
uint8_t sen5x_set_temperature_compensation(sen5x_handle_t *handle, int16_t temperature_offset, int16_t normalized_temperature_offset_slope, uint16_t time_constant)
set temperature compensation
uint8_t sen5x_get_warm_start(sen5x_handle_t *handle, uint16_t *param)
get warm start
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
sen5x_status_t
sen5x status enumeration definition
uint8_t sen54_read(sen5x_handle_t *handle, sen54_data_t *output)
read the result
uint8_t sen5x_read_data_flag(sen5x_handle_t *handle, sen5x_data_ready_flag_t *flag)
read the data flag
uint8_t sen5x_start_measurement_without_pm(sen5x_handle_t *handle)
start the measurement without pm
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 sen5x_get_nox_algorithm_tuning(sen5x_handle_t *handle, int16_t *index_offset, int16_t *learning_time_offset_hour, int16_t *learning_time_gain_hour, int16_t *gating_max_duration_minute, int16_t *std_initial, int16_t *gain_factor)
get nox algorithm tuning
uint8_t sen5x_get_type(sen5x_handle_t *handle, sen5x_type_t *type)
get the chip type
uint8_t sen50_read(sen5x_handle_t *handle, sen50_data_t *output)
read the result
sen5x_data_ready_flag_t
sen5x data ready flag enumeration definition
uint8_t sen5x_reset(sen5x_handle_t *handle)
reset the chip
uint8_t sen5x_get_rht_acceleration_mode(sen5x_handle_t *handle, sen5x_rht_acceleration_mode_t *mode)
get rht acceleration mode
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_get_voc_algorithm_tuning(sen5x_handle_t *handle, int16_t *index_offset, int16_t *learning_time_offset_hour, int16_t *learning_time_gain_hour, int16_t *gating_max_duration_minute, int16_t *std_initial, int16_t *gain_factor)
get voc algorithm tuning
uint8_t sen5x_clear_device_status(sen5x_handle_t *handle)
clear the device status
uint8_t sen5x_set_voc_algorithm_tuning(sen5x_handle_t *handle, int16_t index_offset, int16_t learning_time_offset_hour, int16_t learning_time_gain_hour, int16_t gating_max_duration_minute, int16_t std_initial, int16_t gain_factor)
set voc algorithm tuning
uint8_t sen5x_get_auto_cleaning_interval(sen5x_handle_t *handle, uint32_t *second)
get the auto cleaning interval
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_temperature_compensation_convert_to_data(sen5x_handle_t *handle, int16_t temperature_offset_reg, int16_t normalized_temperature_offset_slope_reg, uint16_t time_constant_reg, float *temperature_offset_degree, float *normalized_temperature_offset_slope_factor, float *time_constant_second)
convert the temperature compensation to the real data
uint8_t sen5x_disable_auto_cleaning_interval(sen5x_handle_t *handle)
disable the auto cleaning interval
uint8_t sen5x_set_rht_acceleration_mode(sen5x_handle_t *handle, sen5x_rht_acceleration_mode_t mode)
set rht acceleration mode
struct sen5x_info_s sen5x_info_t
sen5x information structure definition
uint8_t sen5x_init(sen5x_handle_t *handle)
initialize the chip
uint8_t sen5x_set_warm_start(sen5x_handle_t *handle, uint16_t param)
set warm start
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
sen5x_rht_acceleration_mode_t
sen5x rht acceleration mode enumeration definition
uint8_t sen5x_get_voc_algorithm_state(sen5x_handle_t *handle, uint16_t state[4])
get voc algorithm state
@ SEN5X_STATUS_FAN_SPEED_ERROR
@ SEN5X_STATUS_RHT_ERROR
@ SEN5X_STATUS_GAS_ERROR
@ SEN5X_STATUS_FAN_ERROR
@ SEN5X_STATUS_FAN_CLEANING_ACTIVE
@ SEN5X_STATUS_LASER_ERROR
@ SEN5X_DATA_READY_FLAG_NOT_READY
@ SEN5X_DATA_READY_FLAG_AVAILABLE
@ SEN50
@ SEN54
@ SEN55
@ SEN5X_RHT_ACCELERATION_MEDIUM
@ SEN5X_RHT_ACCELERATION_HIGH
@ SEN5X_RHT_ACCELERATION_LOW
uint8_t sen5x_set_reg(sen5x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t sen5x_get_reg(sen5x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
get the chip register
sen50 data structure definition
uint16_t pm10_raw
uint16_t pm1p0_raw
uint16_t pm2p5_raw
uint16_t pm4p0_raw
uint8_t pm_valid
sen54 data structure definition
float compensated_ambient_temperature_degree
int16_t compensated_ambient_temperature_raw
int16_t compensated_ambient_humidity_raw
uint16_t pm10_raw
uint16_t pm1p0_raw
float compensated_ambient_humidity_percentage
uint16_t pm2p5_raw
uint16_t pm4p0_raw
uint8_t pm_valid
int16_t voc_raw
sen55 data structure definition
float compensated_ambient_temperature_degree
int16_t compensated_ambient_temperature_raw
int16_t compensated_ambient_humidity_raw
uint16_t pm10_raw
uint16_t pm1p0_raw
float compensated_ambient_humidity_percentage
uint16_t pm2p5_raw
int16_t nox_raw
uint16_t pm4p0_raw
uint8_t pm_valid
int16_t voc_raw
sen5x handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
sen5x information structure definition
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]
sen5x pm structure definition
uint16_t mass_concentration_pm4p0_raw
float pm1p0_cm3
uint16_t number_concentration_pm10_raw
float typical_particle_um
uint16_t number_concentration_pm0p5_raw
uint16_t number_concentration_pm1p0_raw
uint16_t mass_concentration_pm2p5_raw
float pm4p0_cm3
uint16_t mass_concentration_pm1p0_raw
uint16_t number_concentration_pm4p0_raw
uint16_t number_concentration_pm2p5_raw
float pm1p0_ug_m3
uint16_t mass_concentration_pm10_raw
float pm0p5_cm3
float pm4p0_ug_m3
float pm10_ug_m3
uint8_t pm_valid
float pm2p5_cm3
float pm2p5_ug_m3
uint16_t typical_particle_raw
sen5x raw structure definition
uint16_t nox_raw
float humidity_percentage
int16_t temperature_raw
float temperature_degree
uint16_t voc_raw
int16_t humidity_raw