upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
hcsr04.h
Go to the documentation of this file.
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Author: Rafael Neri <rafael.neri@gmail.com>
4  * Author: Jun Kato <i@junkato.jp>
5  * Contributions by: Abhishek Malik <abhishek.malik@intel.com>
6  * Copyright (c) 2014-2015 Intel Corporation.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <stdio.h>
30 #include <string.h>
31 #include <mraa/gpio.h>
32 #include <sys/time.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 typedef enum {
39  HCSR04_CM = 0,
40  HCSR04_INCH } HCSR04_U;
41 
50 typedef struct _hcsr04_context {
51  mraa_gpio_context trigPin;
52  mraa_gpio_context echoPin;
53  int interruptCounter;
54  long startTime;
55  long endTime;
57 
65 hcsr04_context hcsr04_init(int triggerPin, int echoPin);
66 
73 
80 double hcsr04_get_distance(hcsr04_context dev, HCSR04_U unit);
81 
82 #ifdef __cplusplus
83 }
84 #endif
double hcsr04_get_distance(hcsr04_context dev, HCSR04_U unit)
Definition: hcsr04.c:91
void hcsr04_close(hcsr04_context dev)
Definition: hcsr04.c:85
hcsr04_context hcsr04_init(int triggerPin, int echoPin)
Definition: hcsr04.c:30
Definition: hcsr04.h:50