1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/driver_ds75lx: add test application

This commit is contained in:
Alexandre Abadie 2019-05-09 16:12:31 +02:00
parent 35a3c4ddfe
commit 69a38f8b7b
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,6 @@
include ../Makefile.tests_common
USEMODULE += ds75lx
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include

View File

@ -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.

View File

@ -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 <alexandre.abadie@inria.fr>
*
* @}
*/
#include <stdio.h>
#include <inttypes.h>
#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;
}