LibDriver DHT11  2.0.0
DHT11 full-featured driver
driver_dht11_read_test.c
Go to the documentation of this file.
1 
38 #include "driver_dht11_read_test.h"
39 
40 static dht11_handle_t gs_handle;
50 uint8_t dht11_read_test(uint32_t times)
51 {
52  uint8_t res;
53  uint32_t i;
54  uint16_t temperature_raw;
55  uint16_t humidity_raw;
56  float temperature;
57  uint8_t humidity;
58  dht11_info_t info;
59 
60  /* link interface function */
71 
72  /* get dht11 information */
73  res = dht11_info(&info);
74  if (res != 0)
75  {
76  dht11_interface_debug_print("dht11: get info failed.\n");
77 
78  return 1;
79  }
80  else
81  {
82  /* print dht11 information */
83  dht11_interface_debug_print("dht11: chip is %s.\n", info.chip_name);
84  dht11_interface_debug_print("dht11: manufacturer is %s.\n", info.manufacturer_name);
85  dht11_interface_debug_print("dht11: interface is %s.\n", info.interface);
86  dht11_interface_debug_print("dht11: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87  dht11_interface_debug_print("dht11: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88  dht11_interface_debug_print("dht11: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89  dht11_interface_debug_print("dht11: max current is %0.2fmA.\n", info.max_current_ma);
90  dht11_interface_debug_print("dht11: max temperature is %0.1fC.\n", info.temperature_max);
91  dht11_interface_debug_print("dht11: min temperature is %0.1fC.\n", info.temperature_min);
92  }
93 
94  /* start basic read test */
95  dht11_interface_debug_print("dht11: start read test.\n");
96 
97  /* dht11 init */
98  res = dht11_init(&gs_handle);
99  if (res != 0)
100  {
101  dht11_interface_debug_print("dht11: init failed.\n");
102 
103  return 1;
104  }
105 
106  /* delay 2000 ms for read */
108  for (i = 0; i < times; i++)
109  {
110  /* read temperature and humidity */
111  res = dht11_read_temperature_humidity(&gs_handle, (uint16_t *)&temperature_raw, (float *)&temperature, (uint16_t *)&humidity_raw, (uint8_t *)&humidity);
112  if (res != 0)
113  {
114  dht11_interface_debug_print("dht11: read failed.\n");
115  (void)dht11_deinit(&gs_handle);
116 
117  return 1;
118  }
119 
120  /* print result */
121  dht11_interface_debug_print("dht11: temperature: %.01fC.\n", temperature);
122  dht11_interface_debug_print("dht11: humidity: %d%%.\n", humidity);
123 
124  /* delay 2000 ms*/
126  }
127 
128  /* finish basic read test and exit */
129  dht11_interface_debug_print("dht11: finish read test.\n");
130  (void)dht11_deinit(&gs_handle);
131 
132  return 0;
133 }
driver dht11 read test header file
uint8_t dht11_read_temperature_humidity(dht11_handle_t *handle, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, uint8_t *humidity_s)
read the temperature and humidity data
Definition: driver_dht11.c:324
uint8_t dht11_info(dht11_info_t *info)
get chip's information
Definition: driver_dht11.c:584
uint8_t dht11_init(dht11_handle_t *handle)
initialize the chip
Definition: driver_dht11.c:467
uint8_t dht11_deinit(dht11_handle_t *handle)
close the chip
Definition: driver_dht11.c:554
uint8_t dht11_interface_init(void)
interface bus init
uint8_t dht11_interface_deinit(void)
interface bus deinit
uint8_t dht11_interface_read(uint8_t *value)
interface bus read
uint8_t dht11_interface_write(uint8_t value)
interface bus write
void dht11_interface_delay_us(uint32_t us)
interface delay us
void dht11_interface_debug_print(const char *const fmt,...)
interface print format data
void dht11_interface_enable_irq(void)
interface enable the interrupt
void dht11_interface_disable_irq(void)
interface disable the interrupt
void dht11_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t dht11_read_test(uint32_t times)
read test
dht11 handle structure definition
Definition: driver_dht11.h:64
dht11 info structure definition
Definition: driver_dht11.h:81
float temperature_max
Definition: driver_dht11.h:89
float supply_voltage_max_v
Definition: driver_dht11.h:86
uint32_t driver_version
Definition: driver_dht11.h:90
float temperature_min
Definition: driver_dht11.h:88
float max_current_ma
Definition: driver_dht11.h:87
char manufacturer_name[32]
Definition: driver_dht11.h:83
float supply_voltage_min_v
Definition: driver_dht11.h:85
char interface[8]
Definition: driver_dht11.h:84
char chip_name[32]
Definition: driver_dht11.h:82