LibDriver AHT40
Loading...
Searching...
No Matches
driver_aht40_read_test.c
Go to the documentation of this file.
1
36
38
39static aht40_handle_t gs_handle;
40
49uint8_t aht40_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint16_t temperature_raw;
53 uint16_t humidity_raw;
54 uint32_t i;
55 float temperature;
56 float humidity;
57 aht40_info_t info;
58
59 /* link interface function */
67
68 /* get aht40 information */
69 res = aht40_info(&info);
70 if (res != 0)
71 {
72 aht40_interface_debug_print("aht40: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print aht40 information */
79 aht40_interface_debug_print("aht40: chip is %s.\n", info.chip_name);
80 aht40_interface_debug_print("aht40: manufacturer is %s.\n", info.manufacturer_name);
81 aht40_interface_debug_print("aht40: interface is %s.\n", info.interface);
82 aht40_interface_debug_print("aht40: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 aht40_interface_debug_print("aht40: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 aht40_interface_debug_print("aht40: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 aht40_interface_debug_print("aht40: max current is %0.2fmA.\n", info.max_current_ma);
86 aht40_interface_debug_print("aht40: max temperature is %0.1fC.\n", info.temperature_max);
87 aht40_interface_debug_print("aht40: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start basic read test */
91 aht40_interface_debug_print("aht40: start read test.\n");
92
93 /* aht40 init */
94 res = aht40_init(&gs_handle);
95 if (res != 0)
96 {
97 aht40_interface_debug_print("aht40: 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 = aht40_read_temperature_humidity(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature,
108 (uint16_t *)&humidity_raw, (float *)&humidity);
109 if (res != 0)
110 {
111 aht40_interface_debug_print("aht40: read failed.\n");
112 (void)aht40_deinit(&gs_handle);
113
114 return 1;
115 }
116
117 /* print result */
118 aht40_interface_debug_print("aht40: temperature: %.01fC.\n", temperature);
119 aht40_interface_debug_print("aht40: humidity: %.01f%%.\n", humidity);
120
121 /* delay 2000 ms*/
123 }
124
125 /* finish basic read test and exit */
126 aht40_interface_debug_print("aht40: finish read test.\n");
127 (void)aht40_deinit(&gs_handle);
128
129 return 0;
130}
driver aht40 read test header file
struct aht40_info_s aht40_info_t
aht40 information structure definition
uint8_t aht40_init(aht40_handle_t *handle)
initialize the chip
uint8_t aht40_info(aht40_info_t *info)
get chip's information
struct aht40_handle_s aht40_handle_t
aht40 handle structure definition
uint8_t aht40_read_temperature_humidity(aht40_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 aht40_deinit(aht40_handle_t *handle)
close the chip
void aht40_interface_debug_print(const char *const fmt,...)
interface print format data
void aht40_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t aht40_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t aht40_interface_iic_init(void)
interface iic bus init
uint8_t aht40_interface_iic_deinit(void)
interface iic bus deinit
uint8_t aht40_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t aht40_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]