LibDriver HDC1080
Loading...
Searching...
No Matches
driver_hdc1080_basic.c
Go to the documentation of this file.
1
36
38
39static hdc1080_handle_t gs_handle;
40
48uint8_t hdc1080_basic_init(void)
49{
50 uint8_t res;
51
52 /* link interface function */
61
62 /* hdc1080 init */
63 res = hdc1080_init(&gs_handle);
64 if (res != 0)
65 {
66 hdc1080_interface_debug_print("hdc1080: init failed.\n");
67
68 return 1;
69 }
70
71 /* set default heater */
73 if (res != 0)
74 {
75 hdc1080_interface_debug_print("hdc1080: set heater failed.\n");
76 (void)hdc1080_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default mode */
83 if (res != 0)
84 {
85 hdc1080_interface_debug_print("hdc1080: set mode failed.\n");
86 (void)hdc1080_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default temperature resolution */
93 if (res != 0)
94 {
95 hdc1080_interface_debug_print("hdc1080: set temperature resolution failed.\n");
96 (void)hdc1080_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set default humidity resolution */
103 if (res != 0)
104 {
105 hdc1080_interface_debug_print("hdc1080: set humidity resolution failed.\n");
106 (void)hdc1080_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 return 0;
112}
113
123uint8_t hdc1080_basic_read(float *temperature, float *humidity)
124{
125 uint16_t temperature_raw;
126 uint16_t humidity_raw;
127
128 /* read temperature and humidity */
129 if (hdc1080_read_temperature_humidity(&gs_handle, (uint16_t *)&temperature_raw, temperature,
130 (uint16_t *)&humidity_raw, humidity) != 0)
131 {
132 return 1;
133 }
134
135 return 0;
136}
137
146{
147 /* deinit hdc1080 and close bus */
148 if (hdc1080_deinit(&gs_handle) != 0)
149 {
150 return 1;
151 }
152
153 return 0;
154}
driver hdc1080 basic header file
struct hdc1080_handle_s hdc1080_handle_t
hdc1080 handle structure definition
uint8_t hdc1080_read_temperature_humidity(hdc1080_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 hdc1080_deinit(hdc1080_handle_t *handle)
close the chip
uint8_t hdc1080_set_heater(hdc1080_handle_t *handle, hdc1080_bool_t enable)
enable or disable heater
uint8_t hdc1080_set_mode(hdc1080_handle_t *handle, hdc1080_mode_t mode)
set the chip mode
uint8_t hdc1080_set_humidity_resolution(hdc1080_handle_t *handle, hdc1080_humidity_resolution_t resolution)
set humidity resolution
uint8_t hdc1080_init(hdc1080_handle_t *handle)
initialize the chip
uint8_t hdc1080_set_temperature_resolution(hdc1080_handle_t *handle, hdc1080_temperature_resolution_t resolution)
set temperature resolution
#define HDC1080_BASIC_DEFAULT_MODE
uint8_t hdc1080_basic_read(float *temperature, float *humidity)
basic example read
uint8_t hdc1080_basic_init(void)
basic example init
#define HDC1080_BASIC_DEFAULT_HUMIDITY_RESOLUTION
#define HDC1080_BASIC_DEFAULT_HEATER
hdc1080 basic example default definition
uint8_t hdc1080_basic_deinit(void)
basic example deinit
#define HDC1080_BASIC_DEFAULT_TEMPERATURE_RESOLUTION
uint8_t hdc1080_interface_iic_read_with_wait(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with wait
void hdc1080_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc1080_interface_iic_deinit(void)
interface iic bus deinit
void hdc1080_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc1080_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t hdc1080_interface_iic_init(void)
interface iic bus init
uint8_t hdc1080_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write