LibDriver HDC2080
Loading...
Searching...
No Matches
driver_hdc2080_shot.c
Go to the documentation of this file.
1
36
37#include "driver_hdc2080_shot.h"
38
39static hdc2080_handle_t gs_handle;
40
50{
51 uint8_t res;
52 uint8_t reg;
53 int8_t offset;
54
55 /* link interface function */
63
64 /* set addr pin */
65 res = hdc2080_set_addr_pin(&gs_handle, addr_pin);
66 if (res != 0)
67 {
68 hdc2080_interface_debug_print("hdc2080: set addr pin failed.\n");
69
70 return 1;
71 }
72
73 /* hdc2080 init */
74 res = hdc2080_init(&gs_handle);
75 if (res != 0)
76 {
77 hdc2080_interface_debug_print("hdc2080: init failed.\n");
78
79 return 1;
80 }
81
82 /* set default temperature resolution */
84 if (res != 0)
85 {
86 hdc2080_interface_debug_print("hdc2080: set temperature resolution failed.\n");
87 (void)hdc2080_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* set default humidity resolution */
94 if (res != 0)
95 {
96 hdc2080_interface_debug_print("hdc2080: set humidity resolution failed.\n");
97 (void)hdc2080_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* set humidity and temperature */
104 if (res != 0)
105 {
106 hdc2080_interface_debug_print("hdc2080: set mode failed.\n");
107 (void)hdc2080_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* set default heater */
114 if (res != 0)
115 {
116 hdc2080_interface_debug_print("hdc2080: set heater failed.\n");
117 (void)hdc2080_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* disable interrupt pin */
124 if (res != 0)
125 {
126 hdc2080_interface_debug_print("hdc2080: set interrupt pin failed.\n");
127 (void)hdc2080_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* set default interrupt polarity */
134 if (res != 0)
135 {
136 hdc2080_interface_debug_print("hdc2080: set interrupt polarity failed.\n");
137 (void)hdc2080_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* set default interrupt mode */
144 if (res != 0)
145 {
146 hdc2080_interface_debug_print("hdc2080: set interrupt mode failed.\n");
147 (void)hdc2080_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* 0.0% */
153 res = hdc2080_humidity_convert_to_register(&gs_handle, 0.0f, &reg);
154 if (res != 0)
155 {
156 hdc2080_interface_debug_print("hdc2080: humidity convert to register failed.\n");
157 (void)hdc2080_deinit(&gs_handle);
158
159 return 1;
160 }
161
162 /* set humidity high threshold */
163 res = hdc2080_set_humidity_high_threshold(&gs_handle, reg);
164 if (res != 0)
165 {
166 hdc2080_interface_debug_print("hdc2080: set humidity high threshold failed.\n");
167 (void)hdc2080_deinit(&gs_handle);
168
169 return 1;
170 }
171
172 /* set humidity low threshold */
173 res = hdc2080_set_humidity_low_threshold(&gs_handle, reg);
174 if (res != 0)
175 {
176 hdc2080_interface_debug_print("hdc2080: set humidity low threshold failed.\n");
177 (void)hdc2080_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* 0.0 */
183 res = hdc2080_temperature_convert_to_register(&gs_handle, 0.0f, &reg);
184 if (res != 0)
185 {
186 hdc2080_interface_debug_print("hdc2080: temperature convert to register failed.\n");
187 (void)hdc2080_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* set temperature high threshold */
193 res = hdc2080_set_temperature_high_threshold(&gs_handle, reg);
194 if (res != 0)
195 {
196 hdc2080_interface_debug_print("hdc2080: set temperature high threshold failed.\n");
197 (void)hdc2080_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* set temperature low threshold */
203 res = hdc2080_set_temperature_low_threshold(&gs_handle, reg);
204 if (res != 0)
205 {
206 hdc2080_interface_debug_print("hdc2080: set temperature low threshold failed.\n");
207 (void)hdc2080_deinit(&gs_handle);
208
209 return 1;
210 }
211
212 /* set default offset */
214 if (res != 0)
215 {
216 hdc2080_interface_debug_print("hdc2080: humidity offset convert to register failed.\n");
217 (void)hdc2080_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* set humidity offset adjustment */
223 res = hdc2080_set_humidity_offset_adjustment(&gs_handle, offset);
224 if (res != 0)
225 {
226 hdc2080_interface_debug_print("hdc2080: set humidity offset adjustment failed.\n");
227 (void)hdc2080_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* set default offset */
234 if (res != 0)
235 {
236 hdc2080_interface_debug_print("hdc2080: temperature offset convert to register failed.\n");
237 (void)hdc2080_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* set temperature offset adjustment */
243 res = hdc2080_set_temperature_offset_adjustment(&gs_handle, offset);
244 if (res != 0)
245 {
246 hdc2080_interface_debug_print("hdc2080: set temperature offset adjustment failed.\n");
247 (void)hdc2080_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* disable data ready */
254 if (res != 0)
255 {
256 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
257 (void)hdc2080_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* disable temperature high threshold */
264 if (res != 0)
265 {
266 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
267 (void)hdc2080_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* disable temperature low threshold */
274 if (res != 0)
275 {
276 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
277 (void)hdc2080_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* disable humidity high threshold */
284 if (res != 0)
285 {
286 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
287 (void)hdc2080_deinit(&gs_handle);
288
289 return 1;
290 }
291
292 /* disable humidity low threshold */
294 if (res != 0)
295 {
296 hdc2080_interface_debug_print("hdc2080: set interrupt failed.\n");
297 (void)hdc2080_deinit(&gs_handle);
298
299 return 1;
300 }
301
302 /* disable auto measurement */
304 if (res != 0)
305 {
306 hdc2080_interface_debug_print("hdc2080: set auto measurement mode failed.\n");
307 (void)hdc2080_deinit(&gs_handle);
308
309 return 1;
310 }
311
312 return 0;
313}
314
324uint8_t hdc2080_shot_read(float *temperature, float *humidity)
325{
326 uint8_t res;
327 uint16_t temperature_raw;
328 uint16_t humidity_raw;
329
330 /* read poll */
331 res = hdc2080_read_poll(&gs_handle);
332 if (res != 0)
333 {
334 return 1;
335 }
336
337 /* read temperature and humidity */
338 if (hdc2080_read_temperature_humidity(&gs_handle, (uint16_t *)&temperature_raw, temperature,
339 (uint16_t *)&humidity_raw, humidity) != 0)
340 {
341 return 1;
342 }
343
344 return 0;
345}
346
355uint8_t hdc2080_shot_get_temperature_max(float *temperature)
356{
357 uint8_t res;
358 uint8_t max;
359
360 /* get temperature max */
361 res = hdc2080_get_temperature_max(&gs_handle, &max);
362 if (res != 0)
363 {
364 return 1;
365 }
366
367 /* temperature convert to data */
368 res = hdc2080_temperature_convert_to_data(&gs_handle, max, temperature);
369 if (res != 0)
370 {
371 return 1;
372 }
373
374 return 0;
375}
376
385uint8_t hdc2080_shot_get_humidity_max(float *percent)
386{
387 uint8_t res;
388 uint8_t max;
389
390 /* get humidity max */
391 res = hdc2080_get_humidity_max(&gs_handle, &max);
392 if (res != 0)
393 {
394 return 1;
395 }
396
397 /* humidity convert to data */
398 res = hdc2080_humidity_convert_to_data(&gs_handle, max, percent);
399 if (res != 0)
400 {
401 return 1;
402 }
403
404 return 0;
405}
406
415{
416 /* deinit hdc2080 and close bus */
417 if (hdc2080_deinit(&gs_handle) != 0)
418 {
419 return 1;
420 }
421
422 return 0;
423}
driver hdc2080 shot header file
uint8_t hdc2080_init(hdc2080_handle_t *handle)
initialize the chip
uint8_t hdc2080_set_temperature_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set temperature offset adjustment
uint8_t hdc2080_set_temperature_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature low threshold
uint8_t hdc2080_set_auto_measurement_mode(hdc2080_handle_t *handle, hdc2080_auto_measurement_mode_t mode)
set auto measurement mode
struct hdc2080_handle_s hdc2080_handle_t
hdc2080 handle structure definition
uint8_t hdc2080_set_humidity_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set humidity resolution
uint8_t hdc2080_read_temperature_humidity(hdc2080_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read the temperature and humidity data
uint8_t hdc2080_deinit(hdc2080_handle_t *handle)
close the chip
uint8_t hdc2080_humidity_offset_convert_to_register(hdc2080_handle_t *handle, float percent, int8_t *reg)
convert the humidity offset to the register raw data
uint8_t hdc2080_set_temperature_resolution(hdc2080_handle_t *handle, hdc2080_resolution_t resolution)
set temperature resolution
uint8_t hdc2080_temperature_offset_convert_to_register(hdc2080_handle_t *handle, float deg, int8_t *reg)
convert the temperature offset to the register raw data
uint8_t hdc2080_temperature_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *deg)
convert the register raw data to the temperature
uint8_t hdc2080_humidity_convert_to_data(hdc2080_handle_t *handle, uint8_t reg, float *percent)
convert the register raw data to the humidity
uint8_t hdc2080_set_interrupt_pin(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable interrupt pin
uint8_t hdc2080_set_humidity_low_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity low threshold
uint8_t hdc2080_get_humidity_max(hdc2080_handle_t *handle, uint8_t *max)
get humidity max
uint8_t hdc2080_set_addr_pin(hdc2080_handle_t *handle, hdc2080_address_t addr_pin)
set the iic address pin
uint8_t hdc2080_set_mode(hdc2080_handle_t *handle, hdc2080_mode_t mode)
set the chip mode
uint8_t hdc2080_set_humidity_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set humidity high threshold
uint8_t hdc2080_set_interrupt_polarity(hdc2080_handle_t *handle, hdc2080_interrupt_polarity_t polarity)
set interrupt polarity
uint8_t hdc2080_set_interrupt_mode(hdc2080_handle_t *handle, hdc2080_interrupt_mode_t mode)
set interrupt mode
uint8_t hdc2080_set_humidity_offset_adjustment(hdc2080_handle_t *handle, int8_t offset)
set humidity offset adjustment
uint8_t hdc2080_set_heater(hdc2080_handle_t *handle, hdc2080_bool_t enable)
enable or disable heater
uint8_t hdc2080_humidity_convert_to_register(hdc2080_handle_t *handle, float percent, uint8_t *reg)
convert the humidity to the register raw data
uint8_t hdc2080_get_temperature_max(hdc2080_handle_t *handle, uint8_t *max)
get temperature max
uint8_t hdc2080_set_interrupt(hdc2080_handle_t *handle, hdc2080_interrupt_t interrupt, hdc2080_bool_t enable)
enable or disable interrupt
uint8_t hdc2080_temperature_convert_to_register(hdc2080_handle_t *handle, float deg, uint8_t *reg)
convert the temperature to the register raw data
uint8_t hdc2080_set_temperature_high_threshold(hdc2080_handle_t *handle, uint8_t threshold)
set temperature high threshold
uint8_t hdc2080_read_poll(hdc2080_handle_t *handle)
read poll
hdc2080_address_t
hdc2080 address enumeration definition
@ HDC2080_BOOL_FALSE
@ HDC2080_AUTO_MEASUREMENT_MODE_DISABLED
@ HDC2080_INTERRUPT_DRDY
@ HDC2080_INTERRUPT_HUMIDITY_HIGH_THRESHOLD
@ HDC2080_INTERRUPT_HUMIDITY_LOW_THRESHOLD
@ HDC2080_INTERRUPT_TEMPERATURE_LOW_THRESHOLD
@ HDC2080_INTERRUPT_TEMPERATURE_HIGH_THRESHOLD
@ HDC2080_MODE_HUMIDITY_TEMPERATURE
uint8_t hdc2080_shot_get_temperature_max(float *temperature)
shot get temperature max
uint8_t hdc2080_shot_read(float *temperature, float *humidity)
shot example read
uint8_t hdc2080_shot_init(hdc2080_address_t addr_pin)
shot example init
#define HDC2080_SHOT_DEFAULT_HUMIDITY_RESOLUTION
#define HDC2080_SHOT_DEFAULT_HUMIDITY_OFFSET
#define HDC2080_SHOT_DEFAULT_TEMPERATURE_OFFSET
uint8_t hdc2080_shot_get_humidity_max(float *percent)
shot get humidity max
#define HDC2080_SHOT_DEFAULT_HEATER
uint8_t hdc2080_shot_deinit(void)
shot example deinit
#define HDC2080_SHOT_DEFAULT_INTERRUPT_POLARITY
#define HDC2080_SHOT_DEFAULT_INTERRUPT_MODE
#define HDC2080_SHOT_DEFAULT_TEMPERATURE_RESOLUTION
hdc2080 shot example default definition
uint8_t hdc2080_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void hdc2080_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc2080_interface_iic_init(void)
interface iic bus init
uint8_t hdc2080_interface_iic_deinit(void)
interface iic bus deinit
uint8_t hdc2080_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void hdc2080_interface_debug_print(const char *const fmt,...)
interface print format data