LibDriver SHT30
Loading...
Searching...
No Matches
driver_sht30_alert.c
Go to the documentation of this file.
1
37
38#include "driver_sht30_alert.h"
39
40static sht30_handle_t gs_handle;
41
50{
51 if (sht30_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55
56 return 0;
57}
58
76uint8_t sht30_alert_init(sht30_address_t addr_pin, void (*callback)(uint16_t type),
77 float high_limit_temperature_set, float high_limit_humidity_set,
78 float high_limit_temperature_clear, float high_limit_humidity_clear,
79 float low_limit_temperature_set, float low_limit_humidity_set,
80 float low_limit_temperature_clear, float low_limit_humidity_clear)
81{
82 uint8_t res;
83 uint16_t set;
84 uint16_t clear;
85
86 /* link functions */
94 DRIVER_SHT30_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
95
96 /* set addr pin */
97 res = sht30_set_addr_pin(&gs_handle, addr_pin);
98 if (res != 0)
99 {
100 sht30_interface_debug_print("sht30: set addr pin failed.\n");
101
102 return 1;
103 }
104
105 /* sht30 init */
106 res = sht30_init(&gs_handle);
107 if (res != 0)
108 {
109 sht30_interface_debug_print("sht30: init failed.\n");
110
111 return 1;
112 }
113
114 /* wait 10 ms */
116
117 /* set default repeatability */
119 if (res != 0)
120 {
121 sht30_interface_debug_print("sht30: set repeatability failed.\n");
122 (void)sht30_deinit(&gs_handle);
123
124 return 1;
125 }
126
127 /* set art */
128 res = sht30_set_art(&gs_handle);
129 if (res != 0)
130 {
131 sht30_interface_debug_print("sht30: set art failed.\n");
132 (void)sht30_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* wait 10 ms */
139
140 /* set default heater */
142 if (res != 0)
143 {
144 sht30_interface_debug_print("sht30: set heater failed.\n");
145 (void)sht30_deinit(&gs_handle);
146
147 return 1;
148 }
149
150 /* wait 10 ms */
152
153 /* alert limit convert to register */
154 res = sht30_alert_limit_convert_to_register(&gs_handle, high_limit_temperature_set, high_limit_humidity_set, &set);
155 if (res != 0)
156 {
157 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
158 (void)sht30_deinit(&gs_handle);
159
160 return 1;
161 }
162
163 /* alert limit convert to register */
164 res = sht30_alert_limit_convert_to_register(&gs_handle, high_limit_temperature_clear, high_limit_humidity_clear, &clear);
165 if (res != 0)
166 {
167 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
168 (void)sht30_deinit(&gs_handle);
169
170 return 1;
171 }
172
173 /* set high alert limit */
174 res = sht30_set_high_alert_limit(&gs_handle, set, clear);
175 if (res != 0)
176 {
177 sht30_interface_debug_print("sht30: set high alert limit failed.\n");
178 (void)sht30_deinit(&gs_handle);
179
180 return 1;
181 }
182
183 /* alert limit convert to register */
184 res = sht30_alert_limit_convert_to_register(&gs_handle, low_limit_temperature_set, low_limit_humidity_set, &set);
185 if (res != 0)
186 {
187 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
188 (void)sht30_deinit(&gs_handle);
189
190 return 1;
191 }
192
193 /* alert limit convert to register */
194 res = sht30_alert_limit_convert_to_register(&gs_handle, low_limit_temperature_clear, low_limit_humidity_clear, &clear);
195 if (res != 0)
196 {
197 sht30_interface_debug_print("sht30: alert limit convert to register failed.\n");
198 (void)sht30_deinit(&gs_handle);
199
200 return 1;
201 }
202
203 /* set low alert limit */
204 res = sht30_set_low_alert_limit(&gs_handle, set, clear);
205 if (res != 0)
206 {
207 sht30_interface_debug_print("sht30: set low alert limit failed.\n");
208 (void)sht30_deinit(&gs_handle);
209
210 return 1;
211 }
212
213 /* clear status */
214 res = sht30_clear_status(&gs_handle);
215 if (res != 0)
216 {
217 sht30_interface_debug_print("sht30: clear status failed.\n");
218 (void)sht30_deinit(&gs_handle);
219
220 return 1;
221 }
222
223 /* start continuous read */
225 if (res != 0)
226 {
227 sht30_interface_debug_print("sht30: start continuous read failed.\n");
228 (void)sht30_deinit(&gs_handle);
229
230 return 1;
231 }
232
233 return 0;
234}
235
245uint8_t sht30_alert_read(float *temperature, float *humidity)
246{
247 uint16_t temperature_raw;
248 uint16_t humidity_raw;
249
250 /* read data */
251 if (sht30_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, temperature, (uint16_t *)&humidity_raw, humidity) != 0)
252 {
253 return 1;
254 }
255
256 return 0;
257}
258
267{
268 uint8_t res;
269
270 /* stop continuous read */
271 res = sht30_stop_continuous_read(&gs_handle);
272 if (res != 0)
273 {
274 return 1;
275 }
276
277 /* delay 100ms */
279
280 /* close sht30 */
281 if (sht30_deinit(&gs_handle) != 0)
282 {
283 return 1;
284 }
285
286 return 0;
287}
288
297uint8_t sht30_alert_get_serial_number(uint8_t sn[4])
298{
299 /* get serial number */
300 if (sht30_get_serial_number(&gs_handle, sn) != 0)
301 {
302 return 1;
303 }
304
305 return 0;
306}
driver sht30 alert header file
uint8_t sht30_stop_continuous_read(sht30_handle_t *handle)
stop reading
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
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_continuous_read(sht30_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data continuously
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_get_serial_number(sht30_handle_t *handle, uint8_t sn[4])
get serial number
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
#define SHT30_ALERT_DEFAULT_RATE
sht30 alert example default definition
#define SHT30_ALERT_DEFAULT_REPEATABILITY
uint8_t sht30_alert_irq_handler(void)
alert irq
uint8_t sht30_alert_read(float *temperature, float *humidity)
alert example read
uint8_t sht30_alert_get_serial_number(uint8_t sn[4])
alert example get serial number
uint8_t sht30_alert_deinit(void)
alert example deinit
#define SHT30_ALERT_DEFAULT_HEATER
uint8_t sht30_alert_init(sht30_address_t addr_pin, void(*callback)(uint16_t type), float high_limit_temperature_set, float high_limit_humidity_set, float high_limit_temperature_clear, float high_limit_humidity_clear, float low_limit_temperature_set, float low_limit_humidity_set, float low_limit_temperature_clear, float low_limit_humidity_clear)
alert example init
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