Loading...
Searching...
No Matches
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
31extern "C" {
32#endif
33
37enum {
42};
43
47typedef struct {
48 gpio_t trigger;
49 gpio_t echo;
51
55typedef struct {
57 int32_t distance;
58 uint32_t time;
59} srf04_t;
60
70int srf04_init(srf04_t *dev, const srf04_params_t *params);
71
77void srf04_trigger(const srf04_t *dev);
78
90int srf04_read(const srf04_t *dev);
91
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* SRF04_H */
Low-level GPIO peripheral driver interface definitions.
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.
int srf04_init(srf04_t *dev, const srf04_params_t *params)
Initialize gpio and interrupt.
@ SRF04_ERR_INVALID
error no valid measurement available
Definition srf04.h:39
@ SRF04_ERR_MEASURING
error sensor is measuring
Definition srf04.h:40
@ SRF04_OK
exit without error
Definition srf04.h:38
@ SRF04_ERR_GPIO
error initializing gpio
Definition srf04.h:41
stdio wrapper to extend the C libs stdio
GPIO pins for srf04 device.
Definition srf04.h:47
gpio_t trigger
GPIO Port the trigger pin is connected to.
Definition srf04.h:48
gpio_t echo
GPIO Port the echo pin is connected to.
Definition srf04.h:49
Device descriptor for srf04 sensor.
Definition srf04.h:55
uint32_t time
timestamp of trigger or echo
Definition srf04.h:58
int32_t distance
raw time of flight distance
Definition srf04.h:57
srf04_params_t p
GPIO Ports of device.
Definition srf04.h:56
xtimer interface definitions