2014-12-11 16:13:49 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Hamburg University of Applied Sciences
|
|
|
|
*
|
|
|
|
* 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 SRF08 ultrasonic range sensor
|
|
|
|
*
|
|
|
|
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
|
2015-04-13 13:07:56 +02:00
|
|
|
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
|
2018-06-27 08:25:51 +02:00
|
|
|
* @author Kevin Weiss <kevin.weiss@haw-hamburg.de>
|
2014-12-11 16:13:49 +01:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-09-03 21:36:13 +02:00
|
|
|
#include "xtimer.h"
|
2014-12-11 16:13:49 +01:00
|
|
|
#include "srf08.h"
|
2020-02-21 12:07:39 +01:00
|
|
|
#include "srf08_params.h"
|
2014-12-11 16:13:49 +01:00
|
|
|
#include "periph/i2c.h"
|
|
|
|
|
2020-02-21 12:07:39 +01:00
|
|
|
#ifndef TEST_MODE
|
|
|
|
#define TEST_MODE (SRF08_MODE_CM)
|
|
|
|
#endif
|
|
|
|
#ifndef TEST_NUM_ECHOS
|
|
|
|
#define TEST_NUM_ECHOS (3U)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SLEEP_USEC (1000 * US_PER_MS)
|
2014-12-11 16:13:49 +01:00
|
|
|
|
2020-02-21 12:07:39 +01:00
|
|
|
static srf08_t srf08_0;
|
2014-12-11 16:13:49 +01:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
puts("SRF08 ultrasonic ranger test application\n");
|
2020-02-21 12:07:39 +01:00
|
|
|
printf("Initializing SRF08 sensor at I2C_%i... ", srf08_params[0].i2c);
|
2014-12-11 16:13:49 +01:00
|
|
|
|
|
|
|
int res;
|
|
|
|
|
2020-02-21 12:07:39 +01:00
|
|
|
res = srf08_init(&srf08_0, &srf08_params[0]);
|
2014-12-11 16:13:49 +01:00
|
|
|
|
|
|
|
if (res < 0) {
|
|
|
|
printf("[Failed]");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
puts("[Ok]\n");
|
|
|
|
|
|
|
|
while(1) {
|
2020-02-24 10:36:21 +01:00
|
|
|
uint16_t range_array[TEST_NUM_ECHOS];
|
2018-06-27 08:25:51 +02:00
|
|
|
int echo_number = srf08_get_distances(&srf08_0, range_array,
|
|
|
|
TEST_NUM_ECHOS, TEST_MODE);
|
2014-12-11 16:13:49 +01:00
|
|
|
|
|
|
|
if (echo_number > 0) {
|
|
|
|
for (int i = 0; i < echo_number; i++) {
|
2018-06-27 08:25:51 +02:00
|
|
|
printf("stored distance = %i cm , echo%i\n",
|
|
|
|
range_array[i], i + 1);
|
2014-12-11 16:13:49 +01:00
|
|
|
}
|
|
|
|
puts("--------------------------------------------");
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2019-09-14 15:47:10 +02:00
|
|
|
puts("An error occurred");
|
2014-12-11 16:13:49 +01:00
|
|
|
}
|
2019-10-10 01:04:47 +02:00
|
|
|
xtimer_usleep(SLEEP_USEC);
|
2014-12-11 16:13:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|