Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
0c0ae185
Commit
0c0ae185
authored
6 years ago
by
MrKevinWeiss
Committed by
dylad
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
drivers/srf08: cleanup and fixes for new api
parent
98f6fd49
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
drivers/include/srf08.h
+8
-7
8 additions, 7 deletions
drivers/include/srf08.h
drivers/srf08/srf08.c
+13
-19
13 additions, 19 deletions
drivers/srf08/srf08.c
tests/driver_srf08/main.c
+6
-3
6 additions, 3 deletions
tests/driver_srf08/main.c
with
27 additions
and
29 deletions
drivers/include/srf08.h
+
8
−
7
View file @
0c0ae185
...
...
@@ -22,6 +22,7 @@
*
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
* @author Kevin Weiss <kevin.weiss@haw-hamburg.de>
*/
#ifndef SRF08_H
...
...
@@ -79,9 +80,9 @@ typedef enum {
SRF08_MODE_INCH
=
0x50
,
/**< result in inches */
SRF08_MODE_CM
=
0x51
,
/**< result in centimeters */
SRF08_MODE_MICRO_SEC
=
0x52
,
/**< result in centimeters */
SRF08_ANN_MODE_INCH
=
0x53
,
/**< synchronous measurement in inch
es
*/
SRF08_ANN_MODE_CM
=
0x54
,
/**< synchronous measurement in c
entimeters
*/
SRF08_ANN_MODE_MICRO_SEC
=
0x55
/**< synchronous measurement in
microsecond
s */
SRF08_ANN_MODE_INCH
=
0x53
,
/**< synchronous measurement in inch */
SRF08_ANN_MODE_CM
=
0x54
,
/**< synchronous measurement in c
m
*/
SRF08_ANN_MODE_MICRO_SEC
=
0x55
/**< synchronous measurement in
u
s */
}
srf08_mode_t
;
/**
...
...
@@ -99,7 +100,7 @@ typedef enum {
* @return -4 on max. gain error
*
*/
int
srf08_init
(
srf08_t
*
dev
,
i2c_t
i2c
,
uint8_t
addr
,
i2c_speed_t
speed
);
int
srf08_init
(
srf08_t
*
dev
,
i2c_t
i2c
,
uint8_t
addr
);
/**
* @brief Set the maximum range of the SRF08.
...
...
@@ -119,9 +120,9 @@ int srf08_set_max_range(const srf08_t *dev, uint8_t max_range);
* @brief Set the maximum of the analog stages.
*
* @ note
* This value is just a limitation of the maximum amplification and not the
actual.
* While measuing, this value starts at its minimum and increases
approx. each 75 us
* until the maximum value is reached.
* This value is just a limitation of the maximum amplification and not the
*
actual.
While measu
r
ing, this value starts at its minimum and increases
*
approx. each 75 us
until the maximum value is reached.
*
* @param[in] dev device descriptor of an SRF08 sensor
* @param[in] max_gain the maximal gain value.
...
...
This diff is collapsed.
Click to expand it.
drivers/srf08/srf08.c
+
13
−
19
View file @
0c0ae185
...
...
@@ -17,6 +17,7 @@
*
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
* @author Kevin Weiss <kevin.weiss@haw-hamburg.de>
*
* @}
*/
...
...
@@ -27,30 +28,20 @@
#include
"srf08.h"
#include
"periph/i2c.h"
#define ENABLE_DEBUG (
0
)
#define ENABLE_DEBUG (
1
)
#include
"debug.h"
int
srf08_init
(
srf08_t
*
dev
,
i2c_t
i2c
,
uint8_t
addr
,
i2c_speed_t
speed
)
int
srf08_init
(
srf08_t
*
dev
,
i2c_t
i2c
,
uint8_t
addr
)
{
int
status
=
0
;
(
void
)
speed
;
(
void
)
status
;
(
void
)
addr
;
(
void
)
i2c
;
dev
->
i2c
=
i2c
;
dev
->
addr
=
addr
;
/* Acquire exclusive access to the bus. */
i2c_acquire
(
dev
->
i2c
);
/* initialize i2c interface */
i2c_init
(
dev
->
i2c
);
/* Release the bus for other threads. */
i2c_release
(
dev
->
i2c
);
if
(
status
<
0
)
{
return
-
1
;
}
/* set the maximum range */
if
(
srf08_set_max_range
(
dev
,
SRF08_MAX_RANGE_6M
)
<
0
)
{
return
-
3
;
...
...
@@ -93,7 +84,8 @@ int srf08_set_max_gain(const srf08_t *dev, uint8_t gain)
}
int
srf08_get_distances
(
const
srf08_t
*
dev
,
uint16_t
*
range_array
,
int
num_echos
,
srf08_mode_t
ranging_mode
)
int
srf08_get_distances
(
const
srf08_t
*
dev
,
uint16_t
*
range_array
,
int
num_echos
,
srf08_mode_t
ranging_mode
)
{
int
status
;
int
echo_number
=
0
;
...
...
@@ -104,11 +96,12 @@ int srf08_get_distances(const srf08_t *dev, uint16_t *range_array, int num_echos
/* Acquire exclusive access to the bus. */
i2c_acquire
(
dev
->
i2c
);
/* set ranging mode */
status
=
i2c_write_reg
(
dev
->
i2c
,
dev
->
addr
,
SRF08_COMMAND_REG
,
ranging_mode
,
0
);
status
=
i2c_write_reg
(
dev
->
i2c
,
dev
->
addr
,
SRF08_COMMAND_REG
,
ranging_mode
,
0
);
/* Release the bus for other threads. */
i2c_release
(
dev
->
i2c
);
if
(
!
status
)
{
if
(
status
!=
0
)
{
DEBUG
(
"Write the ranging command to the i2c-interface is failed
\n
"
);
return
-
1
;
}
...
...
@@ -127,11 +120,12 @@ int srf08_get_distances(const srf08_t *dev, uint16_t *range_array, int num_echos
/* Acquire exclusive access to the bus. */
i2c_acquire
(
dev
->
i2c
);
/* read the echo bytes */
status
=
i2c_read_regs
(
dev
->
i2c
,
dev
->
addr
,
register_location
,
range_bytes
,
sizeof
(
range_bytes
),
0
);
status
=
i2c_read_regs
(
dev
->
i2c
,
dev
->
addr
,
register_location
,
range_bytes
,
sizeof
(
range_bytes
),
0
);
/* Release the bus for other threads. */
i2c_release
(
dev
->
i2c
);
if
(
!
status
)
{
if
(
status
!=
0
)
{
DEBUG
(
"Read the echo bytes from the i2c-interface is failed
\n
"
);
return
-
3
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/driver_srf08/main.c
+
6
−
3
View file @
0c0ae185
...
...
@@ -15,6 +15,7 @@
*
* @author Peter Kietzmann <peter.kietzmann@haw-hamburg.de>
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
* @author Kevin Weiss <kevin.weiss@haw-hamburg.de>
*
* @}
*/
...
...
@@ -49,7 +50,7 @@ int main(void)
int
res
;
uint16_t
range_array
[
TEST_NUM_ECHOS
];
res
=
srf08_init
(
&
srf08_0
,
TEST_SRF08_I2C
,
SRF08_DEFAULT_ADDR
,
TEST_SRF08_SPEED
);
res
=
srf08_init
(
&
srf08_0
,
TEST_SRF08_I2C
,
SRF08_DEFAULT_ADDR
);
if
(
res
<
0
)
{
printf
(
"[Failed]"
);
...
...
@@ -61,11 +62,13 @@ int main(void)
while
(
1
)
{
int
echo_number
=
srf08_get_distances
(
&
srf08_0
,
range_array
,
TEST_NUM_ECHOS
,
TEST_MODE
);
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
);
printf
(
"stored distance = %i cm , echo%i
\n
"
,
range_array
[
i
],
i
+
1
);
}
puts
(
"--------------------------------------------"
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment