LibDriver SGP40
Loading...
Searching...
No Matches
driver_sgp40_basic.c
Go to the documentation of this file.
1
36
37#include "driver_sgp40_basic.h"
39
40static sgp40_handle_t gs_handle;
41static sgp40_gas_index_algorithm_t gs_voc_handle;
42
50uint8_t sgp40_basic_init(void)
51{
52 uint8_t res;
53
54 /* link functions */
62
63 /* sgp40 init */
64 res = sgp40_init(&gs_handle);
65 if (res != 0)
66 {
67 sgp40_interface_debug_print("sgp40: init failed.\n");
68
69 return 1;
70 }
71
72 /* soft reset */
73 res = sgp40_soft_reset(&gs_handle);
74 if (res != 0)
75 {
76 sgp40_interface_debug_print("sgp40: soft failed.\n");
77 (void)sgp40_deinit(&gs_handle);
78
79 return 1;
80 }
81
82 /* voc algorithm init */
84
85 return 0;
86}
87
95uint8_t sgp40_basic_deinit(void)
96{
97 /* close sgp40 */
98 if (sgp40_deinit(&gs_handle) != 0)
99 {
100 return 1;
101 }
102
103 return 0;
104}
105
116uint8_t sgp40_basic_read(float temperature, float humidity, int32_t *voc_gas_index)
117{
118 uint8_t res;
119 uint16_t raw_humidity;
120 uint16_t raw_temperature;
121 uint16_t sraw_voc;
122
123 /* humidity convert to register */
124 res = sgp40_humidity_convert_to_register(&gs_handle, humidity, &raw_humidity);
125 if (res != 0)
126 {
127 sgp40_interface_debug_print("sgp40: humidity convert to register failed.\n");
128
129 return 1;
130 }
131
132 /* temperature convert to register */
133 res = sgp40_temperature_convert_to_register(&gs_handle, temperature, &raw_temperature);
134 if (res != 0)
135 {
136 sgp40_interface_debug_print("sgp40: temperature convert to register failed.\n");
137
138 return 1;
139 }
140
141 /* get measure raw */
142 res = sgp40_get_measure_raw(&gs_handle, raw_humidity, raw_temperature, &sraw_voc);
143 if (res != 0)
144 {
145 sgp40_interface_debug_print("sgp40: get measure raw failed.\n");
146
147 return 1;
148 }
149
150 /* algorithm process */
151 sgp40_algorithm_process(&gs_voc_handle, sraw_voc, voc_gas_index);
152
153 return 0;
154}
155
164uint8_t sgp40_basic_read_without_compensation(int32_t *voc_gas_index)
165{
166 uint8_t res;
167 uint16_t sraw_voc;
168
169 /* get measure raw */
170 res = sgp40_get_measure_raw_without_compensation(&gs_handle, &sraw_voc);
171 if (res != 0)
172 {
173 sgp40_interface_debug_print("sgp40: get measure raw without compensation failed.\n");
174
175 return 1;
176 }
177
178 /* algorithm process */
179 sgp40_algorithm_process(&gs_voc_handle, sraw_voc, voc_gas_index);
180
181 return 0;
182}
183
192uint8_t sgp40_basic_get_serial_id(uint16_t id[3])
193{
194 uint8_t res;
195
196 /* get serial id */
197 res = sgp40_get_serial_id(&gs_handle, id);
198 if (res != 0)
199 {
200 sgp40_interface_debug_print("sgp40: get serial id failed.\n");
201
202 return 1;
203 }
204
205 return 0;
206}
driver sgp40 algorithm header file
driver sgp40 basic header file
void sgp40_algorithm_init(sgp40_gas_index_algorithm_t *params, int32_t algorithm_type)
algorithm init
struct sgp40_gas_index_algorithm_s sgp40_gas_index_algorithm_t
sgp40 gas index algorithm structure definition
#define SGP40_ALGORITHM_TYPE_VOC
sgp40 algorithm type definition
void sgp40_algorithm_process(sgp40_gas_index_algorithm_t *params, int32_t sraw, int32_t *gas_index)
algorithm process
uint8_t sgp40_get_measure_raw(sgp40_handle_t *handle, uint16_t raw_humidity, uint16_t raw_temperature, uint16_t *sraw_voc)
get the measure raw result
uint8_t sgp40_get_serial_id(sgp40_handle_t *handle, uint16_t id[3])
get the chip serial id
uint8_t sgp40_init(sgp40_handle_t *handle)
initialize the chip
uint8_t sgp40_soft_reset(sgp40_handle_t *handle)
soft reset the chip
uint8_t sgp40_get_measure_raw_without_compensation(sgp40_handle_t *handle, uint16_t *sraw_voc)
get the measure raw result without compensation
uint8_t sgp40_humidity_convert_to_register(sgp40_handle_t *handle, float rh, uint16_t *reg)
convert the humidity to the register data
uint8_t sgp40_deinit(sgp40_handle_t *handle)
close the chip
struct sgp40_handle_s sgp40_handle_t
sgp40 handle structure definition
uint8_t sgp40_temperature_convert_to_register(sgp40_handle_t *handle, float temp, uint16_t *reg)
convert the temperature to the register data
uint8_t sgp40_basic_deinit(void)
basic example deinit
uint8_t sgp40_basic_get_serial_id(uint16_t id[3])
basic example get serial id
uint8_t sgp40_basic_read(float temperature, float humidity, int32_t *voc_gas_index)
basic example read
uint8_t sgp40_basic_read_without_compensation(int32_t *voc_gas_index)
basic example read without compensation
uint8_t sgp40_basic_init(void)
basic example init
uint8_t sgp40_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t sgp40_interface_iic_deinit(void)
interface iic bus deinit
void sgp40_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sgp40_interface_iic_init(void)
interface iic bus init
uint8_t sgp40_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
void sgp40_interface_debug_print(const char *const fmt,...)
interface print format data