LibDriver SCD30
Loading...
Searching...
No Matches
driver_scd30_read_test.c
Go to the documentation of this file.
1
36
38
39static scd30_handle_t gs_handle;
40
50uint8_t scd30_read_test(scd30_interface_t interface, uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 scd30_info_t info;
55 scd30_data_t data;
56
57 /* link functions */
70
71 /* get information */
72 res = scd30_info(&info);
73 if (res != 0)
74 {
75 scd30_interface_debug_print("scd30: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip info */
82 scd30_interface_debug_print("scd30: chip is %s.\n", info.chip_name);
83 scd30_interface_debug_print("scd30: manufacturer is %s.\n", info.manufacturer_name);
84 scd30_interface_debug_print("scd30: interface is %s.\n", info.interface);
85 scd30_interface_debug_print("scd30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 scd30_interface_debug_print("scd30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 scd30_interface_debug_print("scd30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 scd30_interface_debug_print("scd30: max current is %0.2fmA.\n", info.max_current_ma);
89 scd30_interface_debug_print("scd30: max temperature is %0.1fC.\n", info.temperature_max);
90 scd30_interface_debug_print("scd30: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 scd30_interface_debug_print("scd30: start read test.\n");
95
96 /* set the interface */
97 res = scd30_set_interface(&gs_handle, interface);
98 if (res != 0)
99 {
100 scd30_interface_debug_print("scd30: set interface failed.\n");
101
102 return 1;
103 }
104
105 /* init the chip */
106 res = scd30_init(&gs_handle);
107 if (res != 0)
108 {
109 scd30_interface_debug_print("scd30: init failed.\n");
110
111 return 1;
112 }
113
114 /* set measurement interval 2s */
115 res = scd30_set_measurement_interval(&gs_handle, 2);
116 if (res != 0)
117 {
118 scd30_interface_debug_print("scd30: set measurement interval failed.\n");
119 (void)scd30_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* enable automatic self calibration */
126 if (res != 0)
127 {
128 scd30_interface_debug_print("scd30: set automatic self calibration failed.\n");
129 (void)scd30_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* output */
135 scd30_interface_debug_print("scd30: start measurement with pressure compensation test.\n");
136
137 /* start measurement */
139 if (res != 0)
140 {
141 scd30_interface_debug_print("scd30: start measurement with pressure compensation failed.\n");
142 (void)scd30_deinit(&gs_handle);
143
144 return 1;
145 }
146
147 /* delay 2000 ms */
149
150 for (i = 0; i < times; i++)
151 {
152 res = scd30_read(&gs_handle, &data);
153 if (res != 0)
154 {
155 scd30_interface_debug_print("scd30: read failed.\n");
156 (void)scd30_deinit(&gs_handle);
157
158 return 1;
159 }
160 scd30_interface_debug_print("scd30: co2 is %0.2fppm.\n", data.co2_ppm);
161 scd30_interface_debug_print("scd30: temperature is %0.2fC.\n", data.temperature_deg);
162 scd30_interface_debug_print("scd30: humidity is %0.2f%%.\n", data.humidity_percent);
163
164 /* delay 2000 ms */
166 }
167
168 /* stop measurement */
169 res = scd30_stop_measurement(&gs_handle);
170 if (res != 0)
171 {
172 scd30_interface_debug_print("scd30: stop measurement failed.\n");
173 (void)scd30_deinit(&gs_handle);
174
175 return 1;
176 }
177
178 /* output */
179 scd30_interface_debug_print("scd30: start measurement test.\n");
180
181 /* start measurement */
182 res = scd30_start_measurement(&gs_handle);
183 if (res != 0)
184 {
185 scd30_interface_debug_print("scd30: start measurement failed.\n");
186 (void)scd30_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* delay 2000 ms */
193
194 for (i = 0; i < times; i++)
195 {
196 res = scd30_read(&gs_handle, &data);
197 if (res != 0)
198 {
199 scd30_interface_debug_print("scd30: read failed.\n");
200 (void)scd30_deinit(&gs_handle);
201
202 return 1;
203 }
204 scd30_interface_debug_print("scd30: co2 is %0.2fppm.\n", data.co2_ppm);
205 scd30_interface_debug_print("scd30: temperature is %0.2fC.\n", data.temperature_deg);
206 scd30_interface_debug_print("scd30: humidity is %0.2f%%.\n", data.humidity_percent);
207
208 /* delay 2000 ms */
210 }
211
212 /* stop measurement */
213 res = scd30_stop_measurement(&gs_handle);
214 if (res != 0)
215 {
216 scd30_interface_debug_print("scd30: stop measurement failed.\n");
217 (void)scd30_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* finish read test */
223 scd30_interface_debug_print("scd30: finish read test.\n");
224 (void)scd30_deinit(&gs_handle);
225
226 return 0;
227}
driver scd30 read test header file
uint8_t scd30_init(scd30_handle_t *handle)
initialize the chip
struct scd30_info_s scd30_info_t
scd30 information structure definition
uint8_t scd30_deinit(scd30_handle_t *handle)
close the chip
struct scd30_data_s scd30_data_t
scd30 data structure definition
uint8_t scd30_stop_measurement(scd30_handle_t *handle)
stop the measurement
uint8_t scd30_read(scd30_handle_t *handle, scd30_data_t *data)
read the result
scd30_interface_t
scd30 interface enumeration definition
uint8_t scd30_set_interface(scd30_handle_t *handle, scd30_interface_t interface)
set the chip interface
uint8_t scd30_set_automatic_self_calibration(scd30_handle_t *handle, scd30_bool_t enable)
set automatic self calibration
uint8_t scd30_start_measurement(scd30_handle_t *handle)
start the measurement
uint8_t scd30_info(scd30_info_t *info)
get chip information
struct scd30_handle_s scd30_handle_t
scd30 handle structure definition
uint8_t scd30_set_measurement_interval(scd30_handle_t *handle, uint16_t second)
set the measurement interval
uint8_t scd30_start_measurement_with_pressure_compensation(scd30_handle_t *handle, uint16_t mbar)
start the measurement with pressure compensation
@ SCD30_BOOL_TRUE
uint8_t scd30_interface_uart_init(void)
interface uart init
uint8_t scd30_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t scd30_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t scd30_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
void scd30_interface_debug_print(const char *const fmt,...)
interface print format data
uint16_t scd30_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t scd30_interface_iic_init(void)
interface iic bus init
void scd30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t scd30_interface_uart_flush(void)
interface uart flush
uint8_t scd30_interface_iic_deinit(void)
interface iic bus deinit
uint8_t scd30_interface_uart_deinit(void)
interface uart deinit
uint8_t scd30_read_test(scd30_interface_t interface, uint32_t times)
read test
float temperature_deg
float humidity_percent
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
char interface[16]
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]