LibDriver SHT35
Loading...
Searching...
No Matches
driver_sht35_alert_test.c
Go to the documentation of this file.
1
37
39
40static sht35_handle_t gs_handle;
41
47static void a_receive_callback(uint16_t type)
48{
49 switch (type)
50 {
52 {
53 sht35_interface_debug_print("sht35: irq alert pending status.\n");
54
55 break;
56 }
58 {
59 sht35_interface_debug_print("sht35: irq humidity alert.\n");
60
61 break;
62 }
64 {
65 sht35_interface_debug_print("sht35: irq temperature alert.\n");
66
67 break;
68 }
69 }
70}
71
80{
81 if (sht35_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 sht35_info_t info;
112
113 /* link functions */
121 DRIVER_SHT35_LINK_RECEIVE_CALLBACK(&gs_handle, a_receive_callback);
122
123 /* sht35 info */
124 res = sht35_info(&info);
125 if (res != 0)
126 {
127 sht35_interface_debug_print("sht35: get info failed.\n");
128
129 return 1;
130 }
131 else
132 {
133 /* print chip information */
134 sht35_interface_debug_print("sht35: chip is %s.\n", info.chip_name);
135 sht35_interface_debug_print("sht35: manufacturer is %s.\n", info.manufacturer_name);
136 sht35_interface_debug_print("sht35: interface is %s.\n", info.interface);
137 sht35_interface_debug_print("sht35: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
138 sht35_interface_debug_print("sht35: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
139 sht35_interface_debug_print("sht35: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
140 sht35_interface_debug_print("sht35: max current is %0.2fmA.\n", info.max_current_ma);
141 sht35_interface_debug_print("sht35: max temperature is %0.1fC.\n", info.temperature_max);
142 sht35_interface_debug_print("sht35: min temperature is %0.1fC.\n", info.temperature_min);
143 }
144
145 /* start alert test */
146 sht35_interface_debug_print("sht35: start alert test.\n");
147
148 /* set address pin */
149 res = sht35_set_addr_pin(&gs_handle, addr_pin);
150 if (res != 0)
151 {
152 sht35_interface_debug_print("sht35: set addr pin failed.\n");
153
154 return 1;
155 }
156
157 /* sht35 init */
158 res = sht35_init(&gs_handle);
159 if (res != 0)
160 {
161 sht35_interface_debug_print("sht35: init failed.\n");
162
163 return 1;
164 }
165
166 /* wait 10 ms */
168
169 /* set art */
170 res = sht35_set_art(&gs_handle);
171 if (res != 0)
172 {
173 sht35_interface_debug_print("sht35: set art failed.\n");
174 (void)sht35_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* wait 10 ms */
181
182 /* disable heater */
183 res = sht35_set_heater(&gs_handle, SHT35_BOOL_FALSE);
184 if (res != 0)
185 {
186 sht35_interface_debug_print("sht35: set heater failed.\n");
187 (void)sht35_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* wait 10 ms */
194
195 /* set high repeatability */
197 if (res != 0)
198 {
199 sht35_interface_debug_print("sht35: set repeatability failed.\n");
200 (void)sht35_deinit(&gs_handle);
201
202 return 1;
203 }
204
205 /* alert limit convert to register */
206 res = sht35_alert_limit_convert_to_register(&gs_handle, high_limit_temperature, high_limit_humidity, &set);
207 if (res != 0)
208 {
209 sht35_interface_debug_print("sht35: alert limit convert to register failed.\n");
210 (void)sht35_deinit(&gs_handle);
211
212 return 1;
213 }
214
215 /* alert limit convert to register */
216 res = sht35_alert_limit_convert_to_register(&gs_handle, high_limit_temperature - 1.0f, high_limit_humidity + 1.0f, &clear);
217 if (res != 0)
218 {
219 sht35_interface_debug_print("sht35: alert limit convert to register failed.\n");
220 (void)sht35_deinit(&gs_handle);
221
222 return 1;
223 }
224
225 /* set high alert limit */
226 res = sht35_set_high_alert_limit(&gs_handle, set, clear);
227 if (res != 0)
228 {
229 sht35_interface_debug_print("sht35: set high alert limit failed.\n");
230 (void)sht35_deinit(&gs_handle);
231
232 return 1;
233 }
234
235 /* alert limit convert to register */
236 res = sht35_alert_limit_convert_to_register(&gs_handle, low_limit_temperature, low_limit_humidity, &set);
237 if (res != 0)
238 {
239 sht35_interface_debug_print("sht35: alert limit convert to register failed.\n");
240 (void)sht35_deinit(&gs_handle);
241
242 return 1;
243 }
244
245 /* alert limit convert to register */
246 res = sht35_alert_limit_convert_to_register(&gs_handle, low_limit_temperature - 1.0f, low_limit_humidity + 1.0f, &clear);
247 if (res != 0)
248 {
249 sht35_interface_debug_print("sht35: alert limit convert to register failed.\n");
250 (void)sht35_deinit(&gs_handle);
251
252 return 1;
253 }
254
255 /* set low alert limit */
256 res = sht35_set_low_alert_limit(&gs_handle, set, clear);
257 if (res != 0)
258 {
259 sht35_interface_debug_print("sht35: set low alert limit failed.\n");
260 (void)sht35_deinit(&gs_handle);
261
262 return 1;
263 }
264
265 /* output */
266 sht35_interface_debug_print("sht35: high limit temperature is %.02fC.\n", high_limit_temperature);
267 sht35_interface_debug_print("sht35: high limit humidity is %.02f%%.\n", high_limit_humidity);
268 sht35_interface_debug_print("sht35: low limit temperature is %.02fC.\n", low_limit_temperature);
269 sht35_interface_debug_print("sht35: low limit humidity is %.02f%%.\n", low_limit_humidity);
270
271 /* clear status */
272 res = sht35_clear_status(&gs_handle);
273 if (res != 0)
274 {
275 sht35_interface_debug_print("sht35: clear status failed.\n");
276 (void)sht35_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* start continuous read */
283 if (res != 0)
284 {
285 sht35_interface_debug_print("sht35: start continuous failed.\n");
286 (void)sht35_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 = sht35_stop_continuous_read(&gs_handle);
298 if (res != 0)
299 {
300 sht35_interface_debug_print("sht35: stop continuous failed.\n");
301 (void)sht35_deinit(&gs_handle);
302
303 return 1;
304 }
305
306 /* finish alert test */
307 sht35_interface_debug_print("sht35: finish alert test.\n");
308 (void)sht35_deinit(&gs_handle);
309
310 return 0;
311}
driver sht35 alert test header file
uint8_t sht35_set_repeatability(sht35_handle_t *handle, sht35_repeatability_t repeatability)
set the measurement repeatability
uint8_t sht35_info(sht35_info_t *info)
get chip's information
uint8_t sht35_deinit(sht35_handle_t *handle)
close the chip
uint8_t sht35_alert_limit_convert_to_register(sht35_handle_t *handle, float temperature, float humidity, uint16_t *reg)
alert limit convert to register raw data
uint8_t sht35_stop_continuous_read(sht35_handle_t *handle)
stop reading
uint8_t sht35_init(sht35_handle_t *handle)
initialize the chip
uint8_t sht35_clear_status(sht35_handle_t *handle)
clear the current status
sht35_address_t
sht35 address enumeration definition
uint8_t sht35_set_heater(sht35_handle_t *handle, sht35_bool_t enable)
enable or disable the chip heater
struct sht35_info_s sht35_info_t
sht35 information structure definition
uint8_t sht35_start_continuous_read(sht35_handle_t *handle, sht35_rate_t rate)
start reading
uint8_t sht35_set_low_alert_limit(sht35_handle_t *handle, uint16_t set, uint16_t clear)
set low alert limit
struct sht35_handle_s sht35_handle_t
sht35 handle structure definition
uint8_t sht35_irq_handler(sht35_handle_t *handle)
irq handler
uint8_t sht35_set_high_alert_limit(sht35_handle_t *handle, uint16_t set, uint16_t clear)
set high alert limit
uint8_t sht35_set_art(sht35_handle_t *handle)
set the chip art
uint8_t sht35_set_addr_pin(sht35_handle_t *handle, sht35_address_t addr_pin)
set the iic address pin
@ SHT35_RATE_10HZ
@ SHT35_STATUS_HUMIDITY_ALERT
@ SHT35_STATUS_TEMPERATURE_ALERT
@ SHT35_STATUS_ALERT_PENDING_STATUS
@ SHT35_REPEATABILITY_HIGH
@ SHT35_BOOL_FALSE
uint8_t sht35_interface_iic_init(void)
interface iic bus init
uint8_t sht35_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 sht35_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t sht35_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 sht35_interface_iic_deinit(void)
interface iic bus deinit
void sht35_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sht35_alert_test(sht35_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 sht35_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]