upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
hcsr04.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Author: Rafael Neri <rafael.neri@gmail.com>
4  * Copyright (c) 2014-2015 Intel Corporation.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #pragma once
26 
27 #include <string>
28 #include <mraa/aio.h>
29 #include <mraa/gpio.h>
30 #include <mraa/pwm.h>
31 #include <sys/time.h>
32 
33 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
34 #include "../IsrCallback.h"
35 #endif
36 
37 #define CM 1
38 #define INC 0
39 
40 namespace upm {
61 class HCSR04 {
62  public:
71  HCSR04 (uint8_t triggerPin, uint8_t echoPin);
75  ~HCSR04 ();
76 
80  double getDistance (int sys);
81 
82 
83  uint8_t m_doWork;
88  std::string name()
89  {
90  return m_name;
91  }
92 
93  private:
98  static void ackEdgeDetected (void *ctx);
99 
100  double timing();
101  mraa_gpio_context m_triggerPinCtx;
102  mraa_gpio_context m_echoPinCtx;
103 
104  long m_RisingTimeStamp;
105  long m_FallingTimeStamp;
106  uint8_t m_InterruptCounter;
107 
108  std::string m_name;
109 };
110 
111 }
~HCSR04()
Definition: hcsr04.cxx:62
uint8_t m_doWork
Definition: hcsr04.h:83
HCSR04(uint8_t triggerPin, uint8_t echoPin)
Definition: hcsr04.cxx:37
Definition: a110x.h:33
double getDistance(int sys)
Definition: hcsr04.cxx:107
std::string name()
Definition: hcsr04.h:88
API for the HC-SR04 Ultrasonic Sensor.
Definition: hcsr04.h:61