From 6c4cb07a2fd61b556b7c97b57efbda456bb67b85 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 23 Mar 2021 12:10:27 +0100 Subject: [PATCH] tests/driver_sgp30: initial import --- tests/driver_sgp30/Makefile | 7 ++++ tests/driver_sgp30/README.md | 17 ++++++++ tests/driver_sgp30/app.config.test | 3 ++ tests/driver_sgp30/main.c | 63 ++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 tests/driver_sgp30/Makefile create mode 100644 tests/driver_sgp30/README.md create mode 100644 tests/driver_sgp30/app.config.test create mode 100644 tests/driver_sgp30/main.c diff --git a/tests/driver_sgp30/Makefile b/tests/driver_sgp30/Makefile new file mode 100644 index 0000000000..ee201199df --- /dev/null +++ b/tests/driver_sgp30/Makefile @@ -0,0 +1,7 @@ +include ../Makefile.tests_common + +USEMODULE += sgp30 + +# DISABLE_MODULE += sgp30_strict + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_sgp30/README.md b/tests/driver_sgp30/README.md new file mode 100644 index 0000000000..235c227762 --- /dev/null +++ b/tests/driver_sgp30/README.md @@ -0,0 +1,17 @@ +driver_sgp30 +============ + +This is a manual test application for the SGP30 driver. It shows how the +sensor can be used for periodic polling. + +Usage +===== + +The test application demonstrates the use of the SGP30. By default the +`sgp30_strict` module is used, which means that periodic readings are +issued every 1s, and a warm-up period of 15s is enforced, before this +`sgp30_read_measurements` returns with `-EAGAIN`. + +`sgp30_strict` can be disabled by compiling with `DISABLE_MODULE=sgp30_strict`. +With this when `sgp30_read_measurements` is called during the first 15s +constant values of 400ppm CO2eq and 0ppb TVOC. diff --git a/tests/driver_sgp30/app.config.test b/tests/driver_sgp30/app.config.test new file mode 100644 index 0000000000..f8833cddc9 --- /dev/null +++ b/tests/driver_sgp30/app.config.test @@ -0,0 +1,3 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. +CONFIG_MODULE_SGP30=y diff --git a/tests/driver_sgp30/main.c b/tests/driver_sgp30/main.c new file mode 100644 index 0000000000..2b6347185e --- /dev/null +++ b/tests/driver_sgp30/main.c @@ -0,0 +1,63 @@ +/* + * 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 SGP30 driver test application + * + * @author Francisco Molina + * + * @} + */ + +#include + +#include "sgp30.h" +#include "sgp30_params.h" + +#include "ztimer.h" + +int main(void) +{ + sgp30_t sensor; + + puts("SGP30 test application\n"); + + printf("+------------Initializing------------+\n"); + + /* initialize the sensor with default configuration parameters */ + if (sgp30_init(&sensor, &sgp30_params[0]) != 0) { + puts("Initialization failed\n"); + return 1; + } + + printf("\n+--------Starting Measurements--------+\n"); + + while (1) { + sgp30_data_t data; + + /* read the data and print them on success */ + int ret = sgp30_read_measurements(&sensor, &data); + if (ret == 0) { + printf("TVOC [ppb]: %d\neCO2 [ppm]: %d\n", data.tvoc, data.eco2); + puts("+-------------------------------------+"); + } + else if (ret == -EAGAIN) { + printf("Device is not yet ready\n"); + } + else { + printf("Could not read data from sensor\n"); + } + ztimer_sleep(ZTIMER_USEC, 100000LU); + } + + return 0; +}