srf04.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef SRF04_H
22 #define SRF04_H
23 
24 #include <stdint.h>
25 #include <stdio.h>
26 
27 #include "periph/gpio.h"
28 #include "xtimer.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
37 enum {
38  SRF04_OK = 0,
42 };
43 
47 typedef struct {
48  gpio_t trigger;
49  gpio_t echo;
51 
55 typedef struct {
57  int distance;
58  uint32_t time;
59 } srf04_t;
60 
70 int srf04_init(srf04_t *dev, const srf04_params_t *params);
71 
77 void srf04_trigger(const srf04_t *dev);
78 
90 int srf04_read(const srf04_t* dev);
91 
103 int srf04_get_distance(const srf04_t* dev);
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* SRF04_H */
110 
srf04_t::p
srf04_params_t p
GPIO Ports of device.
Definition: srf04.h:56
srf04_get_distance
int srf04_get_distance(const srf04_t *dev)
Convenience function triggers a measurement and returns distance.
SRF04_ERR_INVALID
@ SRF04_ERR_INVALID
error no valid measurement available
Definition: srf04.h:39
srf04_trigger
void srf04_trigger(const srf04_t *dev)
Triggers measurement.
SRF04_ERR_GPIO
@ SRF04_ERR_GPIO
error initializing gpio
Definition: srf04.h:41
srf04_read
int srf04_read(const srf04_t *dev)
Returns time of flight in ms.
srf04_params_t::trigger
gpio_t trigger
GPIO Port the trigger pin is connected to.
Definition: srf04.h:48
srf04_t::time
uint32_t time
timestamp of trigger or echo
Definition: srf04.h:58
srf04_params_t::echo
gpio_t echo
GPIO Port the echo pin is connected to.
Definition: srf04.h:49
gpio.h
Low-level GPIO peripheral driver interface definitions.
SRF04_ERR_MEASURING
@ SRF04_ERR_MEASURING
error sensor is measuring
Definition: srf04.h:40
srf04_params_t
GPIO pins for srf04 device.
Definition: srf04.h:47
srf04_init
int srf04_init(srf04_t *dev, const srf04_params_t *params)
Initialize gpio and interrupt.
srf04_t::distance
int distance
raw time of flight distance
Definition: srf04.h:57
SRF04_OK
@ SRF04_OK
exit without error
Definition: srf04.h:38
srf04_t
Device descriptor for srf04 sensor.
Definition: srf04.h:55
xtimer.h
xtimer interface definitions