mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 22:13:52 +01:00
Merge pull request #4829 from haukepetersen/add_test_saul
tests: added SAUL test application
This commit is contained in:
commit
2e4a99eeec
11
tests/saul/Makefile
Normal file
11
tests/saul/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
APPLICATION = saul
|
||||
include ../Makefile.tests_common
|
||||
|
||||
# include and auto-initialize all available sensors
|
||||
USEMODULE += saul_reg
|
||||
USEMODULE += saul_default
|
||||
USEMODULE += auto_init_saul
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
11
tests/saul/README.md
Normal file
11
tests/saul/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
Expected result
|
||||
===============
|
||||
This test application is polling all available SAUL devices periodically for
|
||||
their data. This data is then printed to STDIO.
|
||||
|
||||
Background
|
||||
==========
|
||||
The actual devices that are actually polled depend on the devices that are
|
||||
configured for a particular platform. If you want to test the SAUL interface
|
||||
to a particular device, you should just connect it to your BOARD and include
|
||||
the corresponding device driver using the `USEMODULE` environment variable.
|
||||
57
tests/saul/main.c
Normal file
57
tests/saul/main.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Freie Universität Berlin
|
||||
*
|
||||
* 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 the SAUL interface of devices by periodically reading from
|
||||
* them
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "phydat.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
/**
|
||||
* @brief Read th sensors every second
|
||||
*/
|
||||
#define INTERVAL (1000000U)
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
phydat_t res;
|
||||
uint32_t last = xtimer_now();
|
||||
|
||||
puts("SAUL test application");
|
||||
|
||||
while (1) {
|
||||
saul_reg_t *dev = saul_reg;
|
||||
|
||||
if (dev == NULL) {
|
||||
puts("No SAUL devices present");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (dev) {
|
||||
int dim = saul_reg_read(dev, &res);
|
||||
phydat_dump(&res, dim);
|
||||
dev = dev->next;
|
||||
}
|
||||
|
||||
xtimer_usleep_until(&last, INTERVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user