LibDriver SGP30
Loading...
Searching...
No Matches
driver_sgp30_read_test.c
Go to the documentation of this file.
1
37
39
40static sgp30_handle_t gs_handle;
41
50uint8_t sgp30_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 uint16_t co2_eq_ppm;
55 uint16_t tvoc_ppb;
56 sgp30_info_t info;
57
58 /* link functions */
66
67 /* sgp30 info */
68 res = sgp30_info(&info);
69 if (res != 0)
70 {
71 sgp30_interface_debug_print("sgp30: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print chip information */
78 sgp30_interface_debug_print("sgp30: chip is %s.\n", info.chip_name);
79 sgp30_interface_debug_print("sgp30: manufacturer is %s.\n", info.manufacturer_name);
80 sgp30_interface_debug_print("sgp30: interface is %s.\n", info.interface);
81 sgp30_interface_debug_print("sgp30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 sgp30_interface_debug_print("sgp30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 sgp30_interface_debug_print("sgp30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 sgp30_interface_debug_print("sgp30: max current is %0.2fmA.\n", info.max_current_ma);
85 sgp30_interface_debug_print("sgp30: max temperature is %0.1fC.\n", info.temperature_max);
86 sgp30_interface_debug_print("sgp30: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* start read test */
90 sgp30_interface_debug_print("sgp30: start read test.\n");
91
92 /* sgp30 init */
93 res = sgp30_init(&gs_handle);
94 if (res != 0)
95 {
96 sgp30_interface_debug_print("sgp30: init failed.\n");
97
98 return 1;
99 }
100
101 /* soft reset */
102 res = sgp30_soft_reset(&gs_handle);
103 if (res != 0)
104 {
105 sgp30_interface_debug_print("sgp30: soft failed.\n");
106 (void)sgp30_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* delay 100 ms */
113
114 /* iaq init */
115 res = sgp30_iaq_init(&gs_handle);
116 if (res != 0)
117 {
118 sgp30_interface_debug_print("sgp30: iaq init failed.\n");
119 (void)sgp30_deinit(&gs_handle);
120
121 return 1;
122 }
123 sgp30_interface_debug_print("sgp30: raw read.\n");
124 for (i = 0; i < times; i++)
125 {
126 /* delay 1000 ms */
128 res = sgp30_get_measure_raw(&gs_handle, (uint16_t *)&co2_eq_ppm, (uint16_t *)&tvoc_ppb);
129 if (res != 0)
130 {
131 sgp30_interface_debug_print("sgp30: read failed.\n");
132 (void)sgp30_deinit(&gs_handle);
133
134 return 1;
135 }
136 sgp30_interface_debug_print("sgp30: raw co2 eq is %d.\n", co2_eq_ppm);
137 sgp30_interface_debug_print("sgp30: raw tvoc is %d.\n", tvoc_ppb);
138 }
139 sgp30_interface_debug_print("sgp30: normal read.\n");
140 for (i = 0; i < times; i++)
141 {
142 /* delay 1000 ms */
144 res = sgp30_read(&gs_handle, (uint16_t *)&co2_eq_ppm, (uint16_t *)&tvoc_ppb);
145 if (res != 0)
146 {
147 sgp30_interface_debug_print("sgp30: read failed.\n");
148 (void)sgp30_deinit(&gs_handle);
149
150 return 1;
151 }
152 sgp30_interface_debug_print("sgp30: co2 eq is %d ppm.\n", co2_eq_ppm);
153 sgp30_interface_debug_print("sgp30: tvoc is %d ppb.\n", tvoc_ppb);
154 }
155
156 /* finish read test */
157 sgp30_interface_debug_print("sgp30: finish read test.\n");
158 (void)sgp30_deinit(&gs_handle);
159
160 return 0;
161}
driver sgp30 read test header file
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_deinit(sgp30_handle_t *handle)
close the chip
struct sgp30_info_s sgp30_info_t
sgp30 information structure definition
uint8_t sgp30_get_measure_raw(sgp30_handle_t *handle, uint16_t *tvoc, uint16_t *co2_eq)
get the iaq measure raw result
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_info(sgp30_info_t *info)
get chip information
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_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
uint8_t sgp30_read_test(uint32_t times)
read test
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]