diff --git a/tests/driver_ccs811/README.md b/tests/driver_ccs811/README.md index 6157e45f6fb1faaad0ac31585bd14637c755ad50..c76e3a40af324218b19dac7fba949782316d95f4 100644 --- a/tests/driver_ccs811/README.md +++ b/tests/driver_ccs811/README.md @@ -1,28 +1,15 @@ # About + This is a manual test application for the CCS811 driver. It shows how the sensor can be used for periodic polling as well as with interrupts. # Usage -The test application demonstrates the use of the CCS811. It uses the default -configuration parameters, that is, the measurement mode -```CCS811_MODE_1S``` with one measurement per second. - -The application can use both approaches to wait for new data: - -1. using the data-ready interrupt (```CCS811_INT_DATA_READY```): - ``` - #define USE_CSS811_DATA_READY_INT (1) - ``` +The test application demonstrates the use of the CCS811 using -2. using the data-ready status function (```ccs811_data_ready```) - ``` - #define USE_CSS811_DATA_READY_INT (0) - ``` +- data-ready status function ```ccs811_data_ready``` to wait for new data and +- default configuration parameters, that is, the measurement mode + ```CCS811_MODE_1S``` with one measurement per second. -If data-ready interrupts are used, the default configuration parameter for the -interrupt pin can be overriden by ```CCS811_PARAM_INT_PIN``` before -```ccs811_params.h``` is included. -``` -#define CCS811_PARAM_INT_PIN (GPIO_PIN(0, 12)) -``` +Please refer ```$(RIOTBASE)/tests/driver_ccs811_full``` to learn how +to use the CCS811 with interrupts. diff --git a/tests/driver_ccs811/main.c b/tests/driver_ccs811/main.c index dc95faf44f397403a5bcdc96c330dca078e68c00..f3e7ddb43c31463104d8c556f3c81f7bce8650d5 100644 --- a/tests/driver_ccs811/main.c +++ b/tests/driver_ccs811/main.c @@ -8,27 +8,19 @@ /** * @ingroup tests - * @brief Test application for the Sensirion SHT30/SHT31/SHT35 device driver + * @brief Test application for the AMS CCS811 device driver * @author Gunar Schorcht <gunar@schorcht.net> * @file * - * The test application demonstrates the use of the CCS811. It uses the default - * configuration parameters, that is, the measurement mode #CCS811_MODE_1S with - * one measurement per second. + * The test application demonstrates the use of the CCS811 using * - * The application can use both approaches to wait for new data + * - data-ready status function ```ccs811_data_ready``` to wait for + * new data and + * - default configuration parameters, that is, the measurement mode + * ```CCS811_MODE_1S``` with one measurement per second. * - * - using the data-ready interrupt #CCS811_INT_DATA_READY or - * - using the data-ready status function #ccs811_data_ready - * - * To use the data-ready interrupt, use module ```ccs811_full``` and - * define ```USE_CCS811_DATA_READY_INT``` in CFLAGS variable of the - * make command, for example: - * - * ``` - * USEMODULE=ccs811_full CFLAGS="-DUSE_CCS811_DATA_READY_INT" \ - * make flash BOARD=... -C tests/driver_ccs811 - * ``` + * Please refer ```$(RIOTBASE)/tests/driver_ccs811_full``` to learn how + * to use the CCS811 with interrupts. */ #include <stdio.h> @@ -40,24 +32,6 @@ #include "ccs811.h" #include "ccs811_params.h" -#if USE_CCS811_DATA_READY_INT && !MODULE_CCS811_FULL -#error To use interrupt handling the *ccs811_full* module has to be enabled -#endif - -#define CCS811_LOW 600 -#define CCS811_HIGH 1000 - -kernel_pid_t p_main; - -#ifdef USE_CCS811_DATA_READY_INT -static void ccs811_isr (void *arg) -{ - /* send a message to trigger main thread to handle the interrupt */ - msg_t msg; - msg_send(&msg, p_main); -} -#endif - int main(void) { ccs811_t sensor; @@ -66,54 +40,25 @@ int main(void) printf("+------------Initializing------------+\n"); -#ifdef USE_CCS811_DATA_READY_INT - gpio_init_int (ccs811_params[0].int_pin, GPIO_IN, GPIO_FALLING, - ccs811_isr, 0); -#endif /* USE_CCS811_DATA_READY_INT */ - /* initialize the sensor with default configuration parameters */ if (ccs811_init (&sensor, &ccs811_params[0]) != CCS811_OK) { puts("Initialization failed\n"); return 1; } -#ifdef USE_CCS811_DATA_READY_INT - /* activate data ready interrupt */ - if (ccs811_set_int_mode (&sensor, CCS811_INT_DATA_READY) != CCS811_OK) { - puts("Activating interrupt failed\n"); - return 1; - } -#endif /* USE_CCS811_DATA_READY_INT */ - - /* save the pid of main thread */ - p_main = sched_active_pid; - printf("\n+--------Starting Measurements--------+\n"); while (1) { - uint16_t tvoc; uint16_t eco2; -#ifdef USE_CCS811_DATA_READY_INT - - /* wait for data ready interrupt */ - msg_t msg; - msg_receive(&msg); - -#else /* USE_CCS811_DATA_READY_INT */ - - /* wait for new data by means of the data-ready status function */ + /* wait and check for for new data every 10 ms */ while (ccs811_data_ready (&sensor) != CCS811_OK) { - /* sleep 10 ms */ xtimer_usleep(10000); } -#endif /* USE_CCS811_DATA_READY_INT */ - - /* read the data */ + /* read the data and print them on success */ if (ccs811_read_iaq(&sensor, &tvoc, &eco2, 0, 0) != CCS811_OK) { - /* print values */ printf("TVOC [ppb]: %d\neCO2 [ppm]: %d\n", tvoc, eco2); puts("+-------------------------------------+"); } diff --git a/tests/driver_ccs811_full/Makefile b/tests/driver_ccs811_full/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..65d442465b056b1f364ba49ec6878809d0764cd6 --- /dev/null +++ b/tests/driver_ccs811_full/Makefile @@ -0,0 +1,5 @@ +include ../Makefile.tests_common + +USEMODULE += ccs811_full + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_ccs811_full/README.md b/tests/driver_ccs811_full/README.md new file mode 100644 index 0000000000000000000000000000000000000000..003e6622d3fa91499bb09b8eb30dcc0dd744d3cd --- /dev/null +++ b/tests/driver_ccs811_full/README.md @@ -0,0 +1,24 @@ +# About + +This is a manual test application for the CCS811 driver. It shows how the +sensor can be used for periodic polling as well as with interrupts. + +# Usage + +The test application demonstrates the use of the CCS811 and pseudomodule +```ccs811_full``` using + +- data-ready interrupt ```CCS811_INT_DATA_READY``` and +- default configuration parameters, that is, the measurement mode + ```CCS811_MODE_1S``` with one measurement per second. + +The default configuration parameter for the interrupt pin has to be +overridden according to the hardware configuration by defining +```CCS811_PARAM_INT_PIN``` before ```ccs811_params.h``` is included, e.g., +``` +#define CCS811_PARAM_INT_PIN (GPIO_PIN(0, 7)) +``` +or via the CFLAGS variable in the make command. +``` +CFLAGS="-DCCS811_PARAM_INT_PIN=\(GPIO_PIN\(0,7\)\)" make -C tests/driver_ccs811 BOARD=... +``` diff --git a/tests/driver_ccs811_full/main.c b/tests/driver_ccs811_full/main.c new file mode 100644 index 0000000000000000000000000000000000000000..34729ffaf84198d170811a21e4e19a9bf0c5939e --- /dev/null +++ b/tests/driver_ccs811_full/main.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2018 Gunar Schorcht + * + * 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 + * @brief Test application for the AMS CCS811 device driver + * @author Gunar Schorcht <gunar@schorcht.net> + * @file + * + * The test application demonstrates the use of the CCS811 and pseudomodule + * ```ccs811_full``` using + * + * - data-ready interrupt ```CCS811_INT_DATA_READY``` and + * - default configuration parameters, that is, the measurement mode + * ```CCS811_MODE_1S``` with one measurement per second. + * + * The default configuration parameter for the interrupt pin has to be + * overridden according to the hardware configuration by defining + * ```CCS811_PARAM_INT_PIN``` before ```ccs811_params.h``` is included, e.g., + * ``` + * #define CCS811_PARAM_INT_PIN (GPIO_PIN(0, 7)) + * ``` + * or via the CFLAGS variable in the make command. + * ``` + * CFLAGS="-DCCS811_PARAM_INT_PIN=\(GPIO_PIN\(0,7\)\)" make -C tests/driver_ccs811 BOARD=... + * ``` + */ + +#include <stdio.h> +#include <string.h> + +#include "thread.h" +#include "xtimer.h" + +#include "ccs811.h" +#include "ccs811_params.h" + +kernel_pid_t p_main; + +static void ccs811_isr (void *arg) +{ + /* send a message to trigger main thread to handle the interrupt */ + msg_t msg; + msg_send(&msg, p_main); +} + +int main(void) +{ + ccs811_t sensor; + + puts("CCS811 test application\n"); + + printf("+------------Initializing------------+\n"); + + /* initialize the sensor with default configuration parameters */ + if (ccs811_init (&sensor, &ccs811_params[0]) != CCS811_OK) { + puts("Initialization failed\n"); + return 1; + } + + /* initialize the interrupt pin */ + gpio_init_int (ccs811_params[0].int_pin, GPIO_IN, GPIO_FALLING, + ccs811_isr, 0); + + /* activate data ready interrupt */ + if (ccs811_set_int_mode (&sensor, CCS811_INT_DATA_READY) != CCS811_OK) { + puts("Activating interrupt failed\n"); + return 1; + } + + /* save the pid of main thread */ + p_main = sched_active_pid; + + printf("\n+--------Starting Measurements--------+\n"); + + while (1) { + + uint16_t tvoc; + uint16_t eco2; + + /* wait for data ready interrupt */ + msg_t msg; + msg_receive(&msg); + + /* read the data */ + if (ccs811_read_iaq(&sensor, &tvoc, &eco2, 0, 0) != CCS811_OK) { + /* print values */ + printf("TVOC [ppb]: %d\neCO2 [ppm]: %d\n", tvoc, eco2); + puts("+-------------------------------------+"); + } + else { + printf("Could not read data from sensor\n"); + } + } + + return 0; +}