LibDriver AHT25
Loading...
Searching...
No Matches
driver_aht25_read_test.c
Go to the documentation of this file.
1
36
38
39static aht25_handle_t gs_handle;
40
49uint8_t aht25_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 uint32_t temperature_raw;
54 uint32_t humidity_raw;
55 float temperature;
56 uint8_t humidity;
57 aht25_info_t info;
58
59 /* link interface function */
67
68 /* get aht25 information */
69 res = aht25_info(&info);
70 if (res != 0)
71 {
72 aht25_interface_debug_print("aht25: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print aht25 information */
79 aht25_interface_debug_print("aht25: chip is %s.\n", info.chip_name);
80 aht25_interface_debug_print("aht25: manufacturer is %s.\n", info.manufacturer_name);
81 aht25_interface_debug_print("aht25: interface is %s.\n", info.interface);
82 aht25_interface_debug_print("aht25: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 aht25_interface_debug_print("aht25: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 aht25_interface_debug_print("aht25: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 aht25_interface_debug_print("aht25: max current is %0.2fmA.\n", info.max_current_ma);
86 aht25_interface_debug_print("aht25: max temperature is %0.1fC.\n", info.temperature_max);
87 aht25_interface_debug_print("aht25: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start basic read test */
91 aht25_interface_debug_print("aht25: start read test.\n");
92
93 /* aht25 init */
94 res = aht25_init(&gs_handle);
95 if (res != 0)
96 {
97 aht25_interface_debug_print("aht25: init failed.\n");
98
99 return 1;
100 }
101
102 /* delay 2000 ms for read */
104 for (i = 0; i < times; i++)
105 {
106 /* read temperature and humidity */
107 res = aht25_read_temperature_humidity(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature, (uint32_t *)&humidity_raw, (uint8_t *)&humidity);
108 if (res != 0)
109 {
110 aht25_interface_debug_print("aht25: read failed.\n");
111 (void)aht25_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* print result */
117 aht25_interface_debug_print("aht25: temperature: %.01fC.\n", temperature);
118 aht25_interface_debug_print("aht25: humidity: %d%%.\n", humidity);
119
120 /* delay 2000 ms*/
122 }
123
124 /* finish basic read test and exit */
125 aht25_interface_debug_print("aht25: finish read test.\n");
126 (void)aht25_deinit(&gs_handle);
127
128 return 0;
129}
driver aht25 read test header file
uint8_t aht25_info(aht25_info_t *info)
get chip's information
struct aht25_info_s aht25_info_t
aht25 information structure definition
uint8_t aht25_init(aht25_handle_t *handle)
initialize the chip
uint8_t aht25_read_temperature_humidity(aht25_handle_t *handle, uint32_t *temperature_raw, float *temperature_s, uint32_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
uint8_t aht25_deinit(aht25_handle_t *handle)
close the chip
struct aht25_handle_s aht25_handle_t
aht25 handle structure definition
void aht25_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t aht25_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t aht25_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
void aht25_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t aht25_interface_iic_deinit(void)
interface iic bus deinit
uint8_t aht25_interface_iic_init(void)
interface iic bus init
uint8_t aht25_read_test(uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]