LibDriver SHT30
Loading...
Searching...
No Matches
driver_sht30_alert_test.c
Go to the documentation of this file.
1
37
39
40static sht30_handle_t gs_handle;
41
47static void a_receive_callback(uint16_t type)
48{
49 switch (type)
50 {
52 {
53 sht30_interface_debug_print("sht30: irq alert pending status.\n");
54
55 break;
56 }
58 {
59 sht30_interface_debug_print("sht30: irq humidity alert.\n");
60
61 break;
62 }
64 {
65 sht30_interface_debug_print("sht30: irq temperature alert.\n");
66
67 break;
68 }
69 }
70}
71
80{
81 if (sht30_irq_handler(&gs_handle) != 0)
82 {
83 return 1;
84 }
85
86 return 0;
87}
88
103 float high_limit_temperature, float high_limit_humidity,
104 float low_limit_temperature, float low_limit_humidity,
105 uint32_t timeout)
106{
107 uint8_t res;
108 uint32_t i;
109 uint16_t set;
110 uint16_t clear;
111 sht30_info_t info;
112
113 /* link functions */
121 DRIVER_SHT30_LINK_RECEIVE_CALLBACK(&gs_handle, a_receive_callback);
122
123 /* sht30 info */
124 res = sht30_info(&info);
125 if (res != 0)
126 {
127 sht30_interface_debug_print("sht30: get info failed.\n");
128
129 return 1;
130 }
131 else
132 {
133 /* print chip information */
134 sht30_interface_debug_print("sht30: chip is %s.\n", info.chip_name);
135 sht30_interface_debug_print("sht30: manufacturer is %s.\n", info.manufacturer_name);
136 sht30_interface_debug_print("sht30: interface is %s.\n", info.interface);
137 sht30_interface_debug_print("sht30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
138 sht30_interface_debug_print("sht30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
139 sht30_interface_debug_print("sht30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
140 sht30_interface_debug_print("sht30: max current is %0.2fmA.\n", info.max_current_ma);
141 sht30_interface_debug_print("sht30: max temperature is %0.1fC.\n", info.temperature_max);
142 sht30_interface_debug_print("sht30: min temperature is %0.1fC.\n", info.temperature_min);
143 }
144
145 /* start alert test */
146 sht30_interface_debug_print("sht30: start alert test.\n");
147
148 /* set address pin */
149 res = sht30_set_addr_pin(&gs_handle, addr_pin);
150 if (res != 0)
151 {
152 sht30_interface_debug_print("sht30: set addr pin failed.\n");
153
154 return 1;
155 }
156
157 /* sht30 init */
158 res = sht30_init(&gs_handle);
159 if (res != 0)
160 {
161 sht30_interface_debug_print("sht30: init failed.\n");
162
163 return 1;
164 }
165
166 /* wait 10 ms */
168
169 /* set art */
170 res = sht30_set_art(&gs_handle);
171 if (res != 0)
172 {
173 sht30_interface_debug_print("sht30: set art failed.\n");
174 (void)sht30_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* wait 10 ms */
181
182 /* disable heater */
183 res = sht30_set_heater(&gs_handle, SHT30_BOOL_FALSE);
184 if (res != 0)
185 {
186 sht30_interface_debug_print("sht30: set heater failed.\n");
187 (void)sht30_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* wait 10 ms */
194
195 /* set high repeatability */
197 if (res != 0)
198 {
199 sht30_interface_debug_print("sht30: set repeatability failed.\n");
200 (void)sht30_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* alert limit convert to register */
206 res = sht30_alert_limit_convert_to_register(&gs_handle, high_limit_temperature, high_limit_humidity, &set);
207 if (res != 0)
208 {
209 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
210 (void)sht30_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* alert limit convert to register */
216 res = sht30_alert_limit_convert_to_register(&gs_handle, high_limit_temperature - 1.0f, high_limit_humidity + 1.0f, &clear);
217 if (res != 0)
218 {
219 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
220 (void)sht30_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* set high alert limit */
226 res = sht30_set_high_alert_limit(&gs_handle, set, clear);
227 if (res != 0)
228 {
229 sht30_interface_debug_print("sht30: set high alert limit failed.\n");
230 (void)sht30_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* alert limit convert to register */
236 res = sht30_alert_limit_convert_to_register(&gs_handle, low_limit_temperature, low_limit_humidity, &set);
237 if (res != 0)
238 {
239 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
240 (void)sht30_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* alert limit convert to register */
246 res = sht30_alert_limit_convert_to_register(&gs_handle, low_limit_temperature - 1.0f, low_limit_humidity + 1.0f, &clear);
247 if (res != 0)
248 {
249 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
250 (void)sht30_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* set low alert limit */
256 res = sht30_set_low_alert_limit(&gs_handle, set, clear);
257 if (res != 0)
258 {
259 sht30_interface_debug_print("sht30: set low alert limit failed.\n");
260 (void)sht30_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* output */
266 sht30_interface_debug_print("sht30: high limit temperature is %.02fC.\n", high_limit_temperature);
267 sht30_interface_debug_print("sht30: high limit humidity is %.02f%%.\n", high_limit_humidity);
268 sht30_interface_debug_print("sht30: low limit temperature is %.02fC.\n", low_limit_temperature);
269 sht30_interface_debug_print("sht30: low limit humidity is %.02f%%.\n", low_limit_humidity);
270
271 /* clear status */
272 res = sht30_clear_status(&gs_handle);
273 if (res != 0)
274 {
275 sht30_interface_debug_print("sht30: clear status failed.\n");
276 (void)sht30_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* start continuous read */
283 if (res != 0)
284 {
285 sht30_interface_debug_print("sht30: start continuous failed.\n");
286 (void)sht30_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 for (i = 0; i < timeout; i++)
292 {
294 }
295
296 /* stop continuous read */
297 res = sht30_stop_continuous_read(&gs_handle);
298 if (res != 0)
299 {
300 sht30_interface_debug_print("sht30: stop continuous failed.\n");
301 (void)sht30_deinit(&gs_handle);
302
303 return 1;
304 }
305
306 /* finish alert test */
307 sht30_interface_debug_print("sht30: finish alert test.\n");
308 (void)sht30_deinit(&gs_handle);
309
310 return 0;
311}
driver sht30 alert test header file
uint8_t sht30_stop_continuous_read(sht30_handle_t *handle)
stop reading
uint8_t sht30_info(sht30_info_t *info)
get chip's information
uint8_t sht30_start_continuous_read(sht30_handle_t *handle, sht30_rate_t rate)
start reading
uint8_t sht30_set_repeatability(sht30_handle_t *handle, sht30_repeatability_t repeatability)
set the measurement repeatability
uint8_t sht30_init(sht30_handle_t *handle)
initialize the chip
uint8_t sht30_set_art(sht30_handle_t *handle)
set the chip art
sht30_address_t
sht30 address enumeration definition
struct sht30_info_s sht30_info_t
sht30 information structure definition
uint8_t sht30_alert_limit_convert_to_register(sht30_handle_t *handle, float temperature, float humidity, uint16_t *reg)
alert limit convert to register raw data
uint8_t sht30_set_heater(sht30_handle_t *handle, sht30_bool_t enable)
enable or disable the chip heater
uint8_t sht30_irq_handler(sht30_handle_t *handle)
irq handler
uint8_t sht30_set_addr_pin(sht30_handle_t *handle, sht30_address_t addr_pin)
set the iic address pin
uint8_t sht30_set_high_alert_limit(sht30_handle_t *handle, uint16_t set, uint16_t clear)
set high alert limit
struct sht30_handle_s sht30_handle_t
sht30 handle structure definition
uint8_t sht30_clear_status(sht30_handle_t *handle)
clear the current status
uint8_t sht30_set_low_alert_limit(sht30_handle_t *handle, uint16_t set, uint16_t clear)
set low alert limit
uint8_t sht30_deinit(sht30_handle_t *handle)
close the chip
@ SHT30_RATE_10HZ
@ SHT30_REPEATABILITY_HIGH
@ SHT30_BOOL_FALSE
@ SHT30_STATUS_ALERT_PENDING_STATUS
@ SHT30_STATUS_HUMIDITY_ALERT
@ SHT30_STATUS_TEMPERATURE_ALERT
uint8_t sht30_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
uint8_t sht30_interface_iic_init(void)
interface iic bus init
uint8_t sht30_interface_iic_deinit(void)
interface iic bus deinit
void sht30_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sht30_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
void sht30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sht30_alert_test(sht30_address_t addr_pin, float high_limit_temperature, float high_limit_humidity, float low_limit_temperature, float low_limit_humidity, uint32_t timeout)
alert test
uint8_t sht30_alert_test_irq_handler(void)
alert test irq
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]