a752c7ab
elopes
add first test an...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
* 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>
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
*
* @}
*/
#ifndef TEST_SRF08_I2C
#error "TEST_SRF08_I2C not defined"
#endif
#ifndef TEST_SRF08_SPEED
#error "TEST_SRF08_SPEED not defined"
#endif
#ifndef TEST_MODE
#error "TEST_MODE not defined"
#endif
#ifndef TEST_NUM_ECHOS
#error "TEST_NUM_ECHOS not defined"
#endif
#include <stdio.h>
#include "xtimer.h"
#include "srf08.h"
#include "periph/i2c.h"
#define SLEEP (1000 * 1000U)
static srf08_t srf08_0;
int main(void)
{
puts("SRF08 ultrasonic ranger test application\n");
printf("Initializing SRF08 sensor at I2C_%i... ", TEST_SRF08_I2C);
int res;
uint16_t range_array[TEST_NUM_ECHOS];
res = srf08_init(&srf08_0, TEST_SRF08_I2C, SRF08_DEFAULT_ADDR, TEST_SRF08_SPEED);
if (res < 0) {
printf("[Failed]");
return 1;
}
else {
puts("[Ok]\n");
while(1) {
int echo_number = srf08_get_distances(&srf08_0, range_array, TEST_NUM_ECHOS, TEST_MODE);
if (echo_number > 0) {
for (int i = 0; i < echo_number; i++) {
printf("stored distance = %i cm , echo%i\n", range_array[i], i + 1);
}
puts("--------------------------------------------");
}
else {
puts("An error occured");
}
xtimer_usleep(SLEEP);
}
}
}
|