From 69a38f8b7b5407cdccf8051fa01ede4c8ce96d32 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Thu, 9 May 2019 16:12:31 +0200 Subject: [PATCH] tests/driver_ds75lx: add test application --- tests/driver_ds75lx/Makefile | 6 ++++ tests/driver_ds75lx/README.md | 6 ++++ tests/driver_ds75lx/main.c | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests/driver_ds75lx/Makefile create mode 100644 tests/driver_ds75lx/README.md create mode 100644 tests/driver_ds75lx/main.c diff --git a/tests/driver_ds75lx/Makefile b/tests/driver_ds75lx/Makefile new file mode 100644 index 0000000000..3f05415860 --- /dev/null +++ b/tests/driver_ds75lx/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +USEMODULE += ds75lx +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_ds75lx/README.md b/tests/driver_ds75lx/README.md new file mode 100644 index 0000000000..251b07647f --- /dev/null +++ b/tests/driver_ds75lx/README.md @@ -0,0 +1,6 @@ +## About +This is a test application for the Maxim DS75LX Temperature sensor. + +## Usage +The application will initialize the DS75LX sensor and, every 2 seconds, reads +and display the temperature measured by the sensor. diff --git a/tests/driver_ds75lx/main.c b/tests/driver_ds75lx/main.c new file mode 100644 index 0000000000..fa1fa607c0 --- /dev/null +++ b/tests/driver_ds75lx/main.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 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 the DS75LX temperature sensor + * + * @author Alexandre Abadie + * + * @} + */ + +#include +#include + +#include "ds75lx.h" +#include "ds75lx_params.h" +#include "xtimer.h" + +int main(void) +{ + ds75lx_t dev; + int result; + + puts("DS75LX test application\n"); + + printf("+------------Initializing------------+\n"); + result = ds75lx_init(&dev, &ds75lx_params[0]); + if (result != DS75LX_OK) { + puts("[Error] Failed to initialize DS75LX sensor"); + return 1; + } + + puts("Initialization successful\n"); + + printf("\n+--------Starting Measurements--------+\n"); + int16_t temperature; + while (1) { + ds75lx_wakeup(&dev); + /* Get temperature in degrees celsius */ + ds75lx_read_temperature(&dev, &temperature); + ds75lx_shutdown(&dev); + + bool negative = (temperature < 0); + if (negative) { + temperature = -temperature; + } + + printf("Temperature [°C]: %c%d.%02d\n", + negative ? '-': ' ', + (int)(temperature / 100), + (int)(temperature % 100)); + + xtimer_sleep(2); + } + + return 0; +}