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
9#pragma once
10
22
23#include <stdint.h>
24#include <stdio.h>
25
26#include "periph/gpio.h"
27#include "xtimer.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36enum {
41};
42
46typedef struct {
47 gpio_t trigger;
48 gpio_t echo;
50
54typedef struct {
56 int32_t distance;
57 uint32_t time;
58} srf04_t;
59
69int srf04_init(srf04_t *dev, const srf04_params_t *params);
70
76void srf04_trigger(const srf04_t *dev);
77
89int srf04_read(const srf04_t *dev);
90
103
104#ifdef __cplusplus
105}
106#endif
107
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:38
@ SRF04_ERR_MEASURING
error sensor is measuring
Definition srf04.h:39
@ SRF04_OK
exit without error
Definition srf04.h:37
@ SRF04_ERR_GPIO
error initializing gpio
Definition srf04.h:40
GPIO pins for srf04 device.
Definition srf04.h:46
gpio_t trigger
GPIO Port the trigger pin is connected to.
Definition srf04.h:47
gpio_t echo
GPIO Port the echo pin is connected to.
Definition srf04.h:48
Device descriptor for srf04 sensor.
Definition srf04.h:54
uint32_t time
timestamp of trigger or echo
Definition srf04.h:57
int32_t distance
raw time of flight distance
Definition srf04.h:56
srf04_params_t p
GPIO Ports of device.
Definition srf04.h:55
xtimer interface definitions