srf02.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
3  * 2015 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
25 #ifndef SRF02_H
26 #define SRF02_H
27 
28 #include <stdint.h>
29 #include "periph/i2c.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 #define SRF02_DEFAULT_ADDR (0xe0) /* 224 decimal */
39 
43 #define SRF02_RANGE_DELAY (70000U)
44 
48 typedef struct {
50  uint8_t addr;
51 } srf02_t;
52 
56 typedef enum {
63 } srf02_mode_t;
64 
75 int srf02_init(srf02_t *dev, i2c_t i2c, uint8_t addr);
76 
95 int srf02_trigger(const srf02_t *dev, srf02_mode_t mode);
96 
105 uint16_t srf02_read(const srf02_t *dev);
106 
122 uint16_t srf02_get_distance(const srf02_t *dev, srf02_mode_t mode);
123 
133 int srf02_set_addr(srf02_t *dev, uint8_t new_addr);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* SRF02_H */
140 
srf02_t::addr
uint8_t addr
I2C bus address of the sensor.
Definition: srf02.h:50
srf02_set_addr
int srf02_set_addr(srf02_t *dev, uint8_t new_addr)
Program the given device with a new bus address.
SRF02_MODE_FAKE_INCH
@ SRF02_MODE_FAKE_INCH
result in inches (no pulse send)
Definition: srf02.h:60
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
SRF02_MODE_REAL_INCH
@ SRF02_MODE_REAL_INCH
result in inches
Definition: srf02.h:57
srf02_read
uint16_t srf02_read(const srf02_t *dev)
Read the results of the last ranging operation.
srf02_mode_t
srf02_mode_t
Possible measurement modes of the SRF02 sensor.
Definition: srf02.h:56
srf02_t::i2c
i2c_t i2c
I2C device the sensor is connected to.
Definition: srf02.h:49
srf02_trigger
int srf02_trigger(const srf02_t *dev, srf02_mode_t mode)
Trigger a new measurement.
srf02_init
int srf02_init(srf02_t *dev, i2c_t i2c, uint8_t addr)
Initialize the SRF02 ultrasonic sensor.
srf02_t
Device descriptor for SRF02 sensors.
Definition: srf02.h:48
SRF02_MODE_REAL_MS
@ SRF02_MODE_REAL_MS
result in microseconds
Definition: srf02.h:59
SRF02_MODE_REAL_CM
@ SRF02_MODE_REAL_CM
result in centimeters
Definition: srf02.h:58
srf02_get_distance
uint16_t srf02_get_distance(const srf02_t *dev, srf02_mode_t mode)
Get the distance measured from the SRF02 ultrasonic sensor.
SRF02_MODE_FAKE_CM
@ SRF02_MODE_FAKE_CM
result in cm (no pulse send)
Definition: srf02.h:61
i2c.h
Low-level I2C peripheral driver interface definition.
SRF02_MODE_FAKE_MS
@ SRF02_MODE_FAKE_MS
result in ms (no pulse send)
Definition: srf02.h:62