LibDriver SGP30
Loading...
Searching...
No Matches
driver_sgp30_advance.c
Go to the documentation of this file.
1
37
39
40static sgp30_handle_t gs_handle;
41
49uint8_t sgp30_advance_init(void)
50{
51 uint8_t res;
52
53 /* link functions */
61
62 /* sgp30 init */
63 res = sgp30_init(&gs_handle);
64 if (res != 0)
65 {
66 sgp30_interface_debug_print("sgp30: init failed.\n");
67
68 return 1;
69 }
70
71 /* soft reset */
72 res = sgp30_soft_reset(&gs_handle);
73 if (res != 0)
74 {
75 sgp30_interface_debug_print("sgp30: soft reset failed.\n");
76
77 return 1;
78 }
79
80 /* wait 100 ms */
82
83 /* iaq init */
84 res = sgp30_iaq_init(&gs_handle);
85 if (res != 0)
86 {
87 sgp30_interface_debug_print("sgp30: iaq init failed.\n");
88 (void)sgp30_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 return 0;
94}
95
104{
105 /* close sgp30 */
106 if (sgp30_deinit(&gs_handle) != 0)
107 {
108 return 1;
109 }
110 else
111 {
112 return 0;
113 }
114}
115
125uint8_t sgp30_advance_read(uint16_t *co2_eq_ppm, uint16_t *tvoc_ppb)
126{
127 /* read data */
128 if (sgp30_read(&gs_handle, co2_eq_ppm, tvoc_ppb) != 0)
129 {
130 return 1;
131 }
132 else
133 {
134 return 0;
135 }
136}
137
146uint8_t sgp30_advance_get_serial_id(uint16_t id[3])
147{
148 /* get serial id */
149 if (sgp30_get_serial_id(&gs_handle, id) != 0)
150 {
151 return 1;
152 }
153 else
154 {
155 return 0;
156 }
157}
158
168uint8_t sgp30_advance_get_feature(uint8_t *product_type, uint8_t *product_version)
169{
170 /* get feature set */
171 if (sgp30_get_feature_set(&gs_handle, product_type, product_version) != 0)
172 {
173 return 1;
174 }
175 else
176 {
177 return 0;
178 }
179}
180
190uint8_t sgp30_advance_set_iaq_baseline(uint16_t tvoc, uint16_t co2_eq)
191{
192 /* set iaq baseline */
193 if (sgp30_set_iaq_baseline(&gs_handle, tvoc, co2_eq) != 0)
194 {
195 return 1;
196 }
197 else
198 {
199 return 0;
200 }
201}
202
212uint8_t sgp30_advance_get_iaq_baseline(uint16_t *tvoc, uint16_t *co2_eq)
213{
214 /* get iaq baseline */
215 if (sgp30_get_iaq_baseline(&gs_handle, tvoc, co2_eq) != 0)
216 {
217 return 1;
218 }
219 else
220 {
221 return 0;
222 }
223}
224
234uint8_t sgp30_advance_set_absolute_humidity(float temp, float rh)
235{
236 uint8_t res;
237 uint16_t reg;
238
239 /* humidity convert to register */
240 res = sgp30_absolute_humidity_convert_to_register(&gs_handle, temp, rh, (uint16_t *)&reg);
241 if (res != 0)
242 {
243 return 1;
244 }
245
246 /* set absolute humidity */
247 res = sgp30_set_absolute_humidity(&gs_handle, reg);
248 if (res != 0)
249 {
250 return 1;
251 }
252
253 return 0;
254}
driver sgp30 advance header file
uint8_t sgp30_get_iaq_baseline(sgp30_handle_t *handle, uint16_t *tvoc, uint16_t *co2_eq)
get the chip iaq baseline
struct sgp30_handle_s sgp30_handle_t
sgp30 handle structure definition
uint8_t sgp30_init(sgp30_handle_t *handle)
initialize the chip
uint8_t sgp30_absolute_humidity_convert_to_register(sgp30_handle_t *handle, float temp, float rh, uint16_t *reg)
convert the absolute humidity to the register data
uint8_t sgp30_deinit(sgp30_handle_t *handle)
close the chip
uint8_t sgp30_get_serial_id(sgp30_handle_t *handle, uint16_t id[3])
get the chip serial id
uint8_t sgp30_set_iaq_baseline(sgp30_handle_t *handle, uint16_t tvoc, uint16_t co2_eq)
set the chip iaq baseline
uint8_t sgp30_set_absolute_humidity(sgp30_handle_t *handle, uint16_t humidity)
set the chip absolute_humidity
uint8_t sgp30_read(sgp30_handle_t *handle, uint16_t *co2_eq_ppm, uint16_t *tvoc_ppb)
read the iaq measure result
uint8_t sgp30_get_feature_set(sgp30_handle_t *handle, uint8_t *product_type, uint8_t *product_version)
get the chip feature
uint8_t sgp30_soft_reset(sgp30_handle_t *handle)
soft reset the chip
uint8_t sgp30_iaq_init(sgp30_handle_t *handle)
initialize the chip iaq
uint8_t sgp30_advance_get_serial_id(uint16_t id[3])
advance example get the serial id
uint8_t sgp30_advance_get_feature(uint8_t *product_type, uint8_t *product_version)
advance example get the chip feature
uint8_t sgp30_advance_set_absolute_humidity(float temp, float rh)
advance example set the absolute humidity
uint8_t sgp30_advance_set_iaq_baseline(uint16_t tvoc, uint16_t co2_eq)
advance example set the chip iaq baseline
uint8_t sgp30_advance_init(void)
advance example init
uint8_t sgp30_advance_deinit(void)
advance example deinit
uint8_t sgp30_advance_read(uint16_t *co2_eq_ppm, uint16_t *tvoc_ppb)
advance example read
uint8_t sgp30_advance_get_iaq_baseline(uint16_t *tvoc, uint16_t *co2_eq)
advance example get the chip iaq baseline
uint8_t sgp30_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t sgp30_interface_iic_init(void)
interface iic bus init
uint8_t sgp30_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void sgp30_interface_delay_ms(uint32_t ms)
interface delay ms
void sgp30_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sgp30_interface_iic_deinit(void)
interface iic bus deinit