LibDriver HDC302X
Loading...
Searching...
No Matches
driver_hdc302x_shot.c
Go to the documentation of this file.
1
36
37#include "driver_hdc302x_shot.h"
38
39static hdc302x_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link interface function */
62
63 /* set addr */
64 res = hdc302x_set_addr(&gs_handle, addr);
65 if (res != 0)
66 {
67 hdc302x_interface_debug_print("hdc302x: set addr pin failed.\n");
68
69 return 1;
70 }
71
72 /* hdc302x init */
73 res = hdc302x_init(&gs_handle);
74 if (res != 0)
75 {
76 hdc302x_interface_debug_print("hdc302x: init failed.\n");
77
78 return 1;
79 }
80
81 /* set default low power mode */
83 if (res != 0)
84 {
85 hdc302x_interface_debug_print("hdc302x: set low power mode failed.\n");
86 (void)hdc302x_deinit(&gs_handle);
87
88 return 1;
89 }
90
91#if (HDC302X_SHOT_DEFAULT_HEATER != 0)
92 /* enable heater */
93 res = hdc302x_enable_heater(&gs_handle);
94 if (res != 0)
95 {
96 hdc302x_interface_debug_print("hdc302x: enable heater failed.\n");
97 (void)hdc302x_deinit(&gs_handle);
98
99 return 1;
100 }
101#else
102 /* disable heater */
103 res = hdc302x_disable_heater(&gs_handle);
104 if (res != 0)
105 {
106 hdc302x_interface_debug_print("hdc302x: disable heater failed.\n");
107 (void)hdc302x_deinit(&gs_handle);
108
109 return 1;
110 }
111#endif
112
113 /* set default heater power */
115 if (res != 0)
116 {
117 hdc302x_interface_debug_print("hdc302x: set heater power failed.\n");
118 (void)hdc302x_deinit(&gs_handle);
119
120 return 1;
121 }
122
123 return 0;
124}
125
135uint8_t hdc302x_shot_read(float *temperature, float *humidity)
136{
137 uint16_t temperature_raw;
138 uint16_t humidity_raw;
139
140 /* read data */
141 if (hdc302x_single_read(&gs_handle, (uint16_t *)&temperature_raw, temperature,
142 (uint16_t *)&humidity_raw, humidity) != 0)
143 {
144 return 1;
145 }
146
147 return 0;
148}
149
158{
159 /* close hdc302x */
160 if (hdc302x_deinit(&gs_handle) != 0)
161 {
162 return 1;
163 }
164
165 return 0;
166}
167
176{
177 /* soft reset */
178 if (hdc302x_soft_reset(&gs_handle) != 0)
179 {
180 return 1;
181 }
182
183 return 0;
184}
185
194uint8_t hdc302x_shot_get_nist_id(uint8_t id[6])
195{
196 /* get nist id */
197 if (hdc302x_get_nist_id(&gs_handle, id) != 0)
198 {
199 return 1;
200 }
201
202 return 0;
203}
driver hdc302x shot header file
uint8_t hdc302x_disable_heater(hdc302x_handle_t *handle)
disable heater
uint8_t hdc302x_set_heater_power(hdc302x_handle_t *handle, uint16_t power)
set heater power
uint8_t hdc302x_enable_heater(hdc302x_handle_t *handle)
enable heater
uint8_t hdc302x_set_addr(hdc302x_handle_t *handle, hdc302x_address_t addr)
set the iic address
uint8_t hdc302x_deinit(hdc302x_handle_t *handle)
close the chip
hdc302x_address_t
hdc302x address enumeration definition
uint8_t hdc302x_single_read(hdc302x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
single read
uint8_t hdc302x_set_low_power_mode(hdc302x_handle_t *handle, hdc302x_low_power_mode_t mode)
set low power mode
uint8_t hdc302x_get_nist_id(hdc302x_handle_t *handle, uint8_t id[6])
get nist id
uint8_t hdc302x_init(hdc302x_handle_t *handle)
initialize the chip
struct hdc302x_handle_s hdc302x_handle_t
hdc302x handle structure definition
uint8_t hdc302x_soft_reset(hdc302x_handle_t *handle)
soft reset
uint8_t hdc302x_shot_get_nist_id(uint8_t id[6])
shot example get nist id
#define HDC302X_SHOT_DEFAULT_LOW_POWER_MODE
hdc302x shot example default definition
#define HDC302X_SHOT_DEFAULT_HEATER_POWER
uint8_t hdc302x_shot_deinit(void)
shot example deinit
uint8_t hdc302x_shot_init(hdc302x_address_t addr)
shot example init
uint8_t hdc302x_shot_soft_reset(void)
shot example soft reset
uint8_t hdc302x_shot_read(float *temperature, float *humidity)
shot example read
uint8_t hdc302x_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write address16
void hdc302x_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hdc302x_interface_iic_init(void)
interface iic bus init
uint8_t hdc302x_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read address16
void hdc302x_interface_receive_callback(uint16_t type)
interface receive callback
void hdc302x_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hdc302x_interface_iic_deinit(void)
interface iic bus deinit