LibDriver GP2Y1051AU0F  1.0.0
GP2Y1051AU0F full-featured driver
driver_gp2y1051au0f_read_test.c
Go to the documentation of this file.
1 
38 
39 static gp2y1051au0f_handle_t gs_handle;
49 uint8_t gp2y1051au0f_read_test(uint32_t times)
50 {
51  uint8_t res;
52  uint32_t i;
54 
55  /* link interface function */
63 
64  /* get gp2y1051au0f information */
65  res = gp2y1051au0f_info(&info);
66  if (res != 0)
67  {
68  gp2y1051au0f_interface_debug_print("gp2y1051au0f: get info failed.\n");
69 
70  return 1;
71  }
72  else
73  {
74  /* print chip information */
75  gp2y1051au0f_interface_debug_print("gp2y1051au0f: chip is %s.\n", info.chip_name);
76  gp2y1051au0f_interface_debug_print("gp2y1051au0f: manufacturer is %s.\n", info.manufacturer_name);
77  gp2y1051au0f_interface_debug_print("gp2y1051au0f: interface is %s.\n", info.interface);
78  gp2y1051au0f_interface_debug_print("gp2y1051au0f: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
79  gp2y1051au0f_interface_debug_print("gp2y1051au0f: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
80  gp2y1051au0f_interface_debug_print("gp2y1051au0f: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
81  gp2y1051au0f_interface_debug_print("gp2y1051au0f: max current is %0.2fmA.\n", info.max_current_ma);
82  gp2y1051au0f_interface_debug_print("gp2y1051au0f: max temperature is %0.1fC.\n", info.temperature_max);
83  gp2y1051au0f_interface_debug_print("gp2y1051au0f: min temperature is %0.1fC.\n", info.temperature_min);
84  }
85 
86  /* gp2y1051au0f init */
87  res = gp2y1051au0f_init(&gs_handle);
88  if (res != 0)
89  {
90  gp2y1051au0f_interface_debug_print("gp2y1051au0f: init failed.\n");
91 
92  return 1;
93  }
94 
95  /* start read test */
96  gp2y1051au0f_interface_debug_print("gp2y1051au0f: start read test.\n");
97 
98  for (i = 0; i < times; i++)
99  {
100  uint16_t raw;
101  float mg_m3;
102 
103  /* delay 2000ms */
105 
106  /* read */
107  res = gp2y1051au0f_read(&gs_handle, &raw, &mg_m3);
108  if (res != 0)
109  {
110  gp2y1051au0f_interface_debug_print("gp2y1051au0f: read failed.\n");
111  (void)gp2y1051au0f_deinit(&gs_handle);
112 
113  return 1;
114  }
115 
116  /* output */
117  gp2y1051au0f_interface_debug_print("gp2y1051au0f: dust density is %0.2fmg/m3.\n", mg_m3);
118  }
119 
120  /* finish read test */
121  gp2y1051au0f_interface_debug_print("gp2y1051au0f: finish read test.\n");
122  (void)gp2y1051au0f_deinit(&gs_handle);
123 
124  return 0;
125 }
driver gp2y1051au0f read test header file
uint8_t gp2y1051au0f_read(gp2y1051au0f_handle_t *handle, uint16_t *raw, float *mg_m3)
read the data
uint8_t gp2y1051au0f_info(gp2y1051au0f_info_t *info)
get chip's information
uint8_t gp2y1051au0f_init(gp2y1051au0f_handle_t *handle)
initialize the chip
uint8_t gp2y1051au0f_deinit(gp2y1051au0f_handle_t *handle)
close the chip
uint8_t gp2y1051au0f_interface_uart_deinit(void)
interface uart deinit
uint8_t gp2y1051au0f_interface_uart_flush(void)
interface uart flush
void gp2y1051au0f_interface_delay_ms(uint32_t ms)
interface delay ms
uint16_t gp2y1051au0f_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t gp2y1051au0f_interface_uart_init(void)
interface uart init
void gp2y1051au0f_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t gp2y1051au0f_read_test(uint32_t times)
read test
gp2y1051au0f handle structure definition
gp2y1051au0f information structure definition