LibDriver AHT20
Loading...
Searching...
No Matches
driver_aht20_read_test.c
Go to the documentation of this file.
1
36
38
39static aht20_handle_t gs_handle;
40
49uint8_t aht20_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 aht20_info_t info;
58
59 /* link interface function */
67
68 /* get aht20 information */
69 res = aht20_info(&info);
70 if (res != 0)
71 {
72 aht20_interface_debug_print("aht20: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print aht20 information */
79 aht20_interface_debug_print("aht20: chip is %s.\n", info.chip_name);
80 aht20_interface_debug_print("aht20: manufacturer is %s.\n", info.manufacturer_name);
81 aht20_interface_debug_print("aht20: interface is %s.\n", info.interface);
82 aht20_interface_debug_print("aht20: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 aht20_interface_debug_print("aht20: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 aht20_interface_debug_print("aht20: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 aht20_interface_debug_print("aht20: max current is %0.2fmA.\n", info.max_current_ma);
86 aht20_interface_debug_print("aht20: max temperature is %0.1fC.\n", info.temperature_max);
87 aht20_interface_debug_print("aht20: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start basic read test */
91 aht20_interface_debug_print("aht20: start read test.\n");
92
93 /* aht20 init */
94 res = aht20_init(&gs_handle);
95 if (res != 0)
96 {
97 aht20_interface_debug_print("aht20: 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 = aht20_read_temperature_humidity(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature, (uint32_t *)&humidity_raw, (uint8_t *)&humidity);
108 if (res != 0)
109 {
110 aht20_interface_debug_print("aht20: read failed.\n");
111 (void)aht20_deinit(&gs_handle);
112
113 return 1;
114 }
115
116 /* print result */
117 aht20_interface_debug_print("aht20: temperature: %.01fC.\n", temperature);
118 aht20_interface_debug_print("aht20: humidity: %d%%.\n", humidity);
119
120 /* delay 2000 ms*/
122 }
123
124 /* finish basic read test and exit */
125 aht20_interface_debug_print("aht20: finish read test.\n");
126 (void)aht20_deinit(&gs_handle);
127
128 return 0;
129}
driver aht20 read test header file
uint8_t aht20_info(aht20_info_t *info)
get chip's information
uint8_t aht20_deinit(aht20_handle_t *handle)
close the chip
uint8_t aht20_init(aht20_handle_t *handle)
initialize the chip
uint8_t aht20_read_temperature_humidity(aht20_handle_t *handle, uint32_t *temperature_raw, float *temperature_s, uint32_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
struct aht20_info_s aht20_info_t
aht20 information structure definition
struct aht20_handle_s aht20_handle_t
aht20 handle structure definition
uint8_t aht20_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t aht20_interface_iic_init(void)
interface iic bus init
uint8_t aht20_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
void aht20_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t aht20_interface_iic_deinit(void)
interface iic bus deinit
void aht20_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t aht20_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]