LibDriver PMS3003
Loading...
Searching...
No Matches
driver_pms3003_read_test.c
Go to the documentation of this file.
1
36
38
39static pms3003_handle_t gs_handle;
40
49uint8_t pms3003_read_test(uint32_t times)
50{
51 uint8_t res;
52 uint32_t i;
53 pms3003_info_t info;
54
55 /* link interface function */
70
71 /* get pms3003 information */
72 res = pms3003_info(&info);
73 if (res != 0)
74 {
75 pms3003_interface_debug_print("pms3003: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip information */
82 pms3003_interface_debug_print("pms3003: chip is %s.\n", info.chip_name);
83 pms3003_interface_debug_print("pms3003: manufacturer is %s.\n", info.manufacturer_name);
84 pms3003_interface_debug_print("pms3003: interface is %s.\n", info.interface);
85 pms3003_interface_debug_print("pms3003: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 pms3003_interface_debug_print("pms3003: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 pms3003_interface_debug_print("pms3003: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 pms3003_interface_debug_print("pms3003: max current is %0.2fmA.\n", info.max_current_ma);
89 pms3003_interface_debug_print("pms3003: max temperature is %0.1fC.\n", info.temperature_max);
90 pms3003_interface_debug_print("pms3003: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 pms3003_interface_debug_print("pms3003: start read test.\n");
95
96 /* pms3003 init */
97 res = pms3003_init(&gs_handle);
98 if (res != 0)
99 {
100 pms3003_interface_debug_print("pms3003: init failed.\n");
101
102 return 1;
103 }
104
105 /* set normal mode */
107 if (res != 0)
108 {
109 pms3003_interface_debug_print("pms3003: set hard mode failed.\n");
110 (void)pms3003_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set active mode */
116 res = pms3003_set_mode(&gs_handle, PMS3003_MODE_ACTIVE);
117 if (res != 0)
118 {
119 pms3003_interface_debug_print("pms3003: set mode failed.\n");
120 (void)pms3003_deinit(&gs_handle);
121
122 return 1;
123 }
124
125 /* active read test */
126 pms3003_interface_debug_print("pms3003: active read test.\n");
127
128 for (i = 0; i < times; i++)
129 {
130 pms3003_data_t data;
131
132 /* delay 2000ms */
134
135 /* read */
136 res = pms3003_read(&gs_handle, &data);
137 if (res != 0)
138 {
139 pms3003_interface_debug_print("pms3003: read failed.\n");
140 (void)pms3003_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* output */
146 pms3003_interface_debug_print("pms3003: pm1p0 standard is %d ug/m3.\n", data.pm1p0_standard_ug_m3);
147 pms3003_interface_debug_print("pms3003: pm2p5 standard is %d ug/m3.\n", data.pm2p5_standard_ug_m3);
148 pms3003_interface_debug_print("pms3003: pm10 standard is %d ug/m3.\n", data.pm10_standard_ug_m3);
149 pms3003_interface_debug_print("pms3003: pm1p0 atmospheric is %d ug/m3.\n", data.pm1p0_atmospheric_ug_m3);
150 pms3003_interface_debug_print("pms3003: pm2p5 atmospheric is %d ug/m3.\n", data.pm2p5_atmospheric_ug_m3);
151 pms3003_interface_debug_print("pms3003: pm10 atmospheric is %d ug/m3.\n", data.pm10_atmospheric_ug_m3);
152 }
153
154 /* set passive mode */
155 res = pms3003_set_mode(&gs_handle, PMS3003_MODE_PASSIVE);
156 if (res != 0)
157 {
158 pms3003_interface_debug_print("pms3003: set mode failed.\n");
159 (void)pms3003_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* passive read test */
165 pms3003_interface_debug_print("pms3003: passive read test.\n");
166
167 for (i = 0; i < times; i++)
168 {
169 pms3003_data_t data;
170
171 /* delay 6000ms */
173
174 /* read */
175 res = pms3003_read(&gs_handle, &data);
176 if (res != 0)
177 {
178 pms3003_interface_debug_print("pms3003: read failed.\n");
179 (void)pms3003_deinit(&gs_handle);
180
181 return 1;
182 }
183
184 /* output */
185 pms3003_interface_debug_print("pms3003: pm1p0 standard is %d ug/m3.\n", data.pm1p0_standard_ug_m3);
186 pms3003_interface_debug_print("pms3003: pm2p5 standard is %d ug/m3.\n", data.pm2p5_standard_ug_m3);
187 pms3003_interface_debug_print("pms3003: pm10 standard is %d ug/m3.\n", data.pm10_standard_ug_m3);
188 pms3003_interface_debug_print("pms3003: pm1p0 atmospheric is %d ug/m3.\n", data.pm1p0_atmospheric_ug_m3);
189 pms3003_interface_debug_print("pms3003: pm2p5 atmospheric is %d ug/m3.\n", data.pm2p5_atmospheric_ug_m3);
190 pms3003_interface_debug_print("pms3003: pm10 atmospheric is %d ug/m3.\n", data.pm10_atmospheric_ug_m3);
191 }
192
193 /* sleep */
194 res = pms3003_sleep(&gs_handle);
195 if (res != 0)
196 {
197 pms3003_interface_debug_print("pms3003: sleep failed.\n");
198 (void)pms3003_deinit(&gs_handle);
199
200 return 1;
201 }
202
203 /* sleep */
204 pms3003_interface_debug_print("pms3003: sleep.\n");
205
206 /* delay 1000ms */
208
209 /* wake up */
210 res = pms3003_wake_up(&gs_handle);
211 if (res != 0)
212 {
213 pms3003_interface_debug_print("pms3003: wake up failed.\n");
214 (void)pms3003_deinit(&gs_handle);
215
216 return 1;
217 }
218
219 /* wake up */
220 pms3003_interface_debug_print("pms3003: wake up.\n");
221
222 /* finish read test */
223 pms3003_interface_debug_print("pms3003: finish read test.\n");
224 (void)pms3003_deinit(&gs_handle);
225
226 return 0;
227}
driver pms3003 read test header file
struct pms3003_data_s pms3003_data_t
pms3003 data structure definition
uint8_t pms3003_set_hard_mode(pms3003_handle_t *handle, pms3003_hard_mode_t mode)
set hard mode
uint8_t pms3003_set_mode(pms3003_handle_t *handle, pms3003_mode_t mode)
set mode
uint8_t pms3003_read(pms3003_handle_t *handle, pms3003_data_t *data)
read the data
uint8_t pms3003_wake_up(pms3003_handle_t *handle)
wake up
uint8_t pms3003_init(pms3003_handle_t *handle)
initialize the chip
uint8_t pms3003_deinit(pms3003_handle_t *handle)
close the chip
struct pms3003_info_s pms3003_info_t
pms3003 information structure definition
uint8_t pms3003_sleep(pms3003_handle_t *handle)
sleep
struct pms3003_handle_s pms3003_handle_t
pms3003 handle structure definition
uint8_t pms3003_info(pms3003_info_t *info)
get chip's information
@ PMS3003_MODE_ACTIVE
@ PMS3003_MODE_PASSIVE
@ PMS3003_HARD_MODE_NORMAL
uint8_t pms3003_interface_set_gpio_deinit(void)
interface set gpio deinit
uint8_t pms3003_interface_set_gpio_write(uint8_t level)
interface set gpio write
uint16_t pms3003_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t pms3003_interface_reset_gpio_write(uint8_t level)
interface reset gpio write
void pms3003_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t pms3003_interface_reset_gpio_deinit(void)
interface reset gpio deinit
uint8_t pms3003_interface_set_gpio_init(void)
interface set gpio init
uint8_t pms3003_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t pms3003_interface_uart_init(void)
interface uart init
uint8_t pms3003_interface_uart_flush(void)
interface uart flush
uint8_t pms3003_interface_reset_gpio_init(void)
interface reset gpio init
void pms3003_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t pms3003_interface_uart_deinit(void)
interface uart deinit
uint8_t pms3003_read_test(uint32_t times)
read test
uint16_t pm2p5_standard_ug_m3
uint16_t pm10_atmospheric_ug_m3
uint16_t pm1p0_standard_ug_m3
uint16_t pm1p0_atmospheric_ug_m3
uint16_t pm2p5_atmospheric_ug_m3
uint16_t pm10_standard_ug_m3
uint32_t driver_version
char manufacturer_name[32]