Loading...
Searching...
No Matches
srf04 ultra sonic range finder

Device driver for the srf04 ultra sonic range finder. More...

Detailed Description

Device driver for the srf04 ultra sonic range finder.

Files

file  srf04.h
 Device driver for the srf04 ultra sonic range finder.
 
file  srf04_params.h
 Default configuration for srf04 devices.
 

Data Structures

struct  srf04_params_t
 GPIO pins for srf04 device. More...
 
struct  srf04_t
 Device descriptor for srf04 sensor. More...
 

Enumerations

enum  { SRF04_OK = 0 , SRF04_ERR_INVALID = -1 , SRF04_ERR_MEASURING = -2 , SRF04_ERR_GPIO = -3 }
 Status and error return codes. More...
 

Functions

int srf04_init (srf04_t *dev, const srf04_params_t *params)
 Initialize gpio and interrupt.
 
void srf04_trigger (const srf04_t *dev)
 Triggers measurement.
 
int srf04_read (const srf04_t *dev)
 Returns time of flight in ms.
 
int srf04_get_distance (const srf04_t *dev)
 Convenience function triggers a measurement and returns distance.
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
SRF04_OK 

exit without error

SRF04_ERR_INVALID 

error no valid measurement available

SRF04_ERR_MEASURING 

error sensor is measuring

SRF04_ERR_GPIO 

error initializing gpio

Definition at line 37 of file srf04.h.

Function Documentation

◆ srf04_get_distance()

int srf04_get_distance ( const srf04_t dev)

Convenience function triggers a measurement and returns distance.

Note
This function will return after 50 ms once new data is available
Parameters
[in]devdevice descriptor of sensor
Returns
time of flight in mm
SRF04_MEASURING if measurement is in progress
SRF04_INVALID if no valid measurement is available

◆ srf04_init()

int srf04_init ( srf04_t dev,
const srf04_params_t params 
)

Initialize gpio and interrupt.

Parameters
[out]devdevice descriptor of sensor to initialize
[in]paramsinit param struct holding gpio trigger and echo pins
Returns
SRF04_OK on success
SRF04_GPIO on gpio init failure

◆ srf04_read()

int srf04_read ( const srf04_t dev)

Returns time of flight in ms.

Note
should not be invoked within 50 ms after triggering
Parameters
[in]devdevice descriptor of sensor
Returns
time of flight in ms
SRF04_MEASURING if measurement is in progress
SRF04_INVALID if no valid measurement is available

◆ srf04_trigger()

void srf04_trigger ( const srf04_t dev)

Triggers measurement.

Parameters
[in]devdevice descriptor of sensor