upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hcsr04.hpp
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 #define CM 1
34 #define INC 0
35 
36 namespace upm {
59 class HCSR04 {
60  public:
67  HCSR04 (int triggerPin, int echoPin);
71  ~HCSR04 ();
72 
78  double getDistance (int sys);
79 
80 
81  uint8_t m_doWork;
86  std::string name()
87  {
88  return m_name;
89  }
90 
91  private:
96  static void ackEdgeDetected (void *ctx);
97 
98  double timing();
99  mraa_gpio_context m_triggerPinCtx;
100  mraa_gpio_context m_echoPinCtx;
101 
102  long m_RisingTimeStamp;
103  long m_FallingTimeStamp;
104  uint8_t m_InterruptCounter;
105 
106  std::string m_name;
107 };
108 
109 }
~HCSR04()
Definition: hcsr04.cxx:65
uint8_t m_doWork
Definition: hcsr04.hpp:81
HCSR04(int triggerPin, int echoPin)
Definition: hcsr04.cxx:41
double getDistance(int sys)
Definition: hcsr04.cxx:110
std::string name()
Definition: hcsr04.hpp:86
API for the HC-SR04 Ultrasonic Sensor.
Definition: hcsr04.hpp:59