LibDriver AHT30  1.0.0
AHT30 full-featured driver
driver_aht30_read_test.c
Go to the documentation of this file.
1 
37 #include "driver_aht30_read_test.h"
38 
39 static aht30_handle_t gs_handle;
49 uint8_t aht30_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  aht30_info_t info;
58 
59  /* link interface function */
67 
68  /* get aht30 information */
69  res = aht30_info(&info);
70  if (res != 0)
71  {
72  aht30_interface_debug_print("aht30: get info failed.\n");
73 
74  return 1;
75  }
76  else
77  {
78  /* print aht30 information */
79  aht30_interface_debug_print("aht30: chip is %s.\n", info.chip_name);
80  aht30_interface_debug_print("aht30: manufacturer is %s.\n", info.manufacturer_name);
81  aht30_interface_debug_print("aht30: interface is %s.\n", info.interface);
82  aht30_interface_debug_print("aht30: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83  aht30_interface_debug_print("aht30: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84  aht30_interface_debug_print("aht30: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85  aht30_interface_debug_print("aht30: max current is %0.2fmA.\n", info.max_current_ma);
86  aht30_interface_debug_print("aht30: max temperature is %0.1fC.\n", info.temperature_max);
87  aht30_interface_debug_print("aht30: min temperature is %0.1fC.\n", info.temperature_min);
88  }
89 
90  /* start basic read test */
91  aht30_interface_debug_print("aht30: start read test.\n");
92 
93  /* aht30 init */
94  res = aht30_init(&gs_handle);
95  if (res != 0)
96  {
97  aht30_interface_debug_print("aht30: 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 = aht30_read_temperature_humidity(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature, (uint32_t *)&humidity_raw, (uint8_t *)&humidity);
108  if (res != 0)
109  {
110  aht30_interface_debug_print("aht30: read failed.\n");
111  (void)aht30_deinit(&gs_handle);
112 
113  return 1;
114  }
115 
116  /* print result */
117  aht30_interface_debug_print("aht30: temperature: %.01fC.\n", temperature);
118  aht30_interface_debug_print("aht30: humidity: %d%%.\n", humidity);
119 
120  /* delay 2000 ms*/
122  }
123 
124  /* finish basic read test and exit */
125  aht30_interface_debug_print("aht30: finish read test.\n");
126  (void)aht30_deinit(&gs_handle);
127 
128  return 0;
129 }
driver aht30 read test header file
uint8_t aht30_deinit(aht30_handle_t *handle)
close the chip
Definition: driver_aht30.c:279
uint8_t aht30_init(aht30_handle_t *handle)
initialize the chip
Definition: driver_aht30.c:182
uint8_t aht30_read_temperature_humidity(aht30_handle_t *handle, uint32_t *temperature_raw, float *temperature_s, uint32_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
Definition: driver_aht30.c:317
uint8_t aht30_info(aht30_info_t *info)
get chip's information
Definition: driver_aht30.c:616
uint8_t aht30_interface_iic_init(void)
interface iic bus init
uint8_t aht30_interface_iic_deinit(void)
interface iic bus deinit
uint8_t aht30_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read
void aht30_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t aht30_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write
void aht30_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t aht30_read_test(uint32_t times)
read test
aht30 handle structure definition
Definition: driver_aht30.h:77
aht30 information structure definition
Definition: driver_aht30.h:91
float temperature_max
Definition: driver_aht30.h:99
float supply_voltage_max_v
Definition: driver_aht30.h:96
uint32_t driver_version
Definition: driver_aht30.h:100
float temperature_min
Definition: driver_aht30.h:98
float max_current_ma
Definition: driver_aht30.h:97
char manufacturer_name[32]
Definition: driver_aht30.h:93
float supply_voltage_min_v
Definition: driver_aht30.h:95
char interface[8]
Definition: driver_aht30.h:94
char chip_name[32]
Definition: driver_aht30.h:92