From a886c311e8711d7d9f8418403a4e11104018d1ef Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Wed, 7 Apr 2021 11:32:51 +0200 Subject: [PATCH] tests/driver_sm_pwm_01c: initial import --- tests/driver_sm_pwm_01c/Makefile | 8 ++++ tests/driver_sm_pwm_01c/Makefile.ci | 3 ++ tests/driver_sm_pwm_01c/README.md | 27 +++++++++++ tests/driver_sm_pwm_01c/app.config.test | 6 +++ tests/driver_sm_pwm_01c/main.c | 61 +++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 tests/driver_sm_pwm_01c/Makefile create mode 100644 tests/driver_sm_pwm_01c/Makefile.ci create mode 100644 tests/driver_sm_pwm_01c/README.md create mode 100644 tests/driver_sm_pwm_01c/app.config.test create mode 100644 tests/driver_sm_pwm_01c/main.c diff --git a/tests/driver_sm_pwm_01c/Makefile b/tests/driver_sm_pwm_01c/Makefile new file mode 100644 index 0000000000..fd72cdb8cd --- /dev/null +++ b/tests/driver_sm_pwm_01c/Makefile @@ -0,0 +1,8 @@ +BOARD ?= samr21-xpro + +include ../Makefile.tests_common + +USEMODULE += progress_bar +USEMODULE += sm_pwm_01c + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_sm_pwm_01c/Makefile.ci b/tests/driver_sm_pwm_01c/Makefile.ci new file mode 100644 index 0000000000..790fd42a4c --- /dev/null +++ b/tests/driver_sm_pwm_01c/Makefile.ci @@ -0,0 +1,3 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-l011k4 + # diff --git a/tests/driver_sm_pwm_01c/README.md b/tests/driver_sm_pwm_01c/README.md new file mode 100644 index 0000000000..0cde5df57a --- /dev/null +++ b/tests/driver_sm_pwm_01c/README.md @@ -0,0 +1,27 @@ +# Test Application for the Amphenol SM_PWM_01C infrared dust sensor + +## About + +This is a simple test application for the SM_PWM_01C driver. + +## Expected result + +If everything works then you should see the progress bar vary if dust +concentration changes in the room, or manually block the infrared inputs +to force a change. + +Overly exaggerated values (blocked infrared sensor) can be seen here: + +``` +# main(): This is RIOT! (Version: 2021.04-devel-1044-gfd36c-HEAD) +# sm_pwm_01c driver test application +# starting weighted average PM2.5 and PM10 measurements +# +# PM2.5 level: 1272 ug/m3|███████████ | +# PM10 level: 490 ug/m3|████ | +```` + +## Details + +By default a moving average over a 30s window is returned ad the +read value. The progress bar is updated every 200ms. diff --git a/tests/driver_sm_pwm_01c/app.config.test b/tests/driver_sm_pwm_01c/app.config.test new file mode 100644 index 0000000000..b91916cc53 --- /dev/null +++ b/tests/driver_sm_pwm_01c/app.config.test @@ -0,0 +1,6 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. +CONFIG_MODULE_SM_PWM_01C=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_USEC=y +CONFIG_MODULE_PROGRESS_BAR=y diff --git a/tests/driver_sm_pwm_01c/main.c b/tests/driver_sm_pwm_01c/main.c new file mode 100644 index 0000000000..6b202910ae --- /dev/null +++ b/tests/driver_sm_pwm_01c/main.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * @file + * @brief Test application for SM_PWM_01C driver + * + * @author Francisco Molina + * @} + */ + +#include + +#include "ztimer.h" + +#include "sm_pwm_01c.h" +#include "sm_pwm_01c_params.h" + +#include "progress_bar.h" + +static progress_bar_t progress_bar_list[2]; + +int main(void) +{ + sm_pwm_01c_t dev; + + puts("sm_pwm_01c driver test application"); + if (sm_pwm_01c_init(&dev, &sm_pwm_01c_params[0]) != 0) { + puts("init device [ERROR]"); + return -1; + } + + puts("starting weighted average PM2.5 and PM10 measurements\n"); + sm_pwm_01c_start(&dev); + progress_bar_prepare_multi(2); + + while (1) { + ztimer_sleep(ZTIMER_USEC, 200 * US_PER_MS); + sm_pwm_01c_data_t data; + sm_pwm_01c_read_data(&dev, &data); + sprintf(progress_bar_list[0].prefix, + "%s %4d ug/m3", "PM2.5 level:", + data.mc_pm_2p5); + sprintf(progress_bar_list[1].prefix, "%s %4d ug/m3", "PM10 level:", + data.mc_pm_10); + progress_bar_list[0].value = data.mc_pm_2p5 > + 3000 ? 100 : (data.mc_pm_2p5 * 100) / 3000; + progress_bar_list[1].value = data.mc_pm_10 > + 3000 ? 100 : (data.mc_pm_10 * 100) / 3000; + progress_bar_update_multi(progress_bar_list, 2); + } + + return 0; +}