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:
parent
35a3c4ddfe
commit
69a38f8b7b
6
tests/driver_ds75lx/Makefile
Normal file
6
tests/driver_ds75lx/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += ds75lx
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
6
tests/driver_ds75lx/README.md
Normal file
6
tests/driver_ds75lx/README.md
Normal 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.
|
66
tests/driver_ds75lx/main.c
Normal file
66
tests/driver_ds75lx/main.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user