LibDriver SHT85
Loading...
Searching...
No Matches
driver_sht85_basic.c
Go to the documentation of this file.
1
36
37#include "driver_sht85_basic.h"
38
39static sht85_handle_t gs_handle;
40
48uint8_t sht85_basic_init(void)
49{
50 uint8_t res;
51
52 /* link functions */
60
61 /* sht85 init */
62 res = sht85_init(&gs_handle);
63 if (res != 0)
64 {
65 sht85_interface_debug_print("sht85: init failed.\n");
66
67 return 1;
68 }
69
70 /* wait 10 ms */
72
73 /* set default repeatability */
75 if (res != 0)
76 {
77 sht85_interface_debug_print("sht85: set repeatability failed.\n");
78 (void)sht85_deinit(&gs_handle);
79
80 return 1;
81 }
82
83 /* set art */
84 res = sht85_set_art(&gs_handle);
85 if (res != 0)
86 {
87 sht85_interface_debug_print("sht85: set art failed.\n");
88 (void)sht85_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 /* wait 10 ms */
95
96 /* set default heater */
98 if (res != 0)
99 {
100 sht85_interface_debug_print("sht85: set heater failed.\n");
101 (void)sht85_deinit(&gs_handle);
102
103 return 1;
104 }
105
106 /* wait 10 ms */
108
109 /* start continuous read */
111 if (res != 0)
112 {
113 sht85_interface_debug_print("sht85: start continuous read failed.\n");
114 (void)sht85_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 return 0;
120}
121
131uint8_t sht85_basic_read(float *temperature, float *humidity)
132{
133 uint16_t temperature_raw;
134 uint16_t humidity_raw;
135
136 /* read data */
137 if (sht85_continuous_read(&gs_handle, (uint16_t *)&temperature_raw, temperature, (uint16_t *)&humidity_raw, humidity) != 0)
138 {
139 return 1;
140 }
141
142 return 0;
143}
144
153{
154 uint8_t res;
155
156 /* stop continuous read */
157 res = sht85_stop_continuous_read(&gs_handle);
158 if (res != 0)
159 {
160 return 1;
161 }
162
163 /* delay 100ms */
165
166 /* close sht85 */
167 if (sht85_deinit(&gs_handle) != 0)
168 {
169 return 1;
170 }
171
172 return 0;
173}
174
183uint8_t sht85_basic_get_serial_number(uint8_t sn[4])
184{
185 /* get serial number */
186 if (sht85_get_serial_number(&gs_handle, sn) != 0)
187 {
188 return 1;
189 }
190
191 return 0;
192}
driver sht85 basic header file
uint8_t sht85_start_continuous_read(sht85_handle_t *handle, sht85_rate_t rate)
start reading
uint8_t sht85_continuous_read(sht85_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data continuously
uint8_t sht85_set_heater(sht85_handle_t *handle, sht85_bool_t enable)
enable or disable the chip heater
uint8_t sht85_get_serial_number(sht85_handle_t *handle, uint8_t sn[4])
get serial number
uint8_t sht85_init(sht85_handle_t *handle)
initialize the chip
uint8_t sht85_set_repeatability(sht85_handle_t *handle, sht85_repeatability_t repeatability)
set the measurement repeatability
uint8_t sht85_stop_continuous_read(sht85_handle_t *handle)
stop reading
uint8_t sht85_deinit(sht85_handle_t *handle)
close the chip
uint8_t sht85_set_art(sht85_handle_t *handle)
set the chip art
struct sht85_handle_s sht85_handle_t
sht85 handle structure definition
uint8_t sht85_basic_get_serial_number(uint8_t sn[4])
basic example get serial number
#define SHT85_BASIC_DEFAULT_HEATER
uint8_t sht85_basic_init(void)
basic example init
uint8_t sht85_basic_read(float *temperature, float *humidity)
basic example read
#define SHT85_BASIC_DEFAULT_REPEATABILITY
#define SHT85_BASIC_DEFAULT_RATE
sht85 basic example default definition
uint8_t sht85_basic_deinit(void)
basic example deinit
uint8_t sht85_interface_iic_deinit(void)
interface iic bus deinit
uint8_t sht85_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
void sht85_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t sht85_interface_iic_init(void)
interface iic bus init
uint8_t sht85_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 sht85_interface_delay_ms(uint32_t ms)
interface delay ms