upm  0.5.0
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
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 #define CM 1
34 #define INC 0
35 
36 namespace upm {
57 class HCSR04 {
58  public:
67  HCSR04 (uint8_t triggerPin, uint8_t echoPin);
71  ~HCSR04 ();
72 
76  double getDistance (int sys);
77 
78 
79  uint8_t m_doWork;
84  std::string name()
85  {
86  return m_name;
87  }
88 
89  private:
94  static void ackEdgeDetected (void *ctx);
95 
96  double timing();
97  mraa_gpio_context m_triggerPinCtx;
98  mraa_gpio_context m_echoPinCtx;
99 
100  long m_RisingTimeStamp;
101  long m_FallingTimeStamp;
102  uint8_t m_InterruptCounter;
103 
104  std::string m_name;
105 };
106 
107 }
~HCSR04()
Definition: hcsr04.cxx:66
uint8_t m_doWork
Definition: hcsr04.h:79
HCSR04(uint8_t triggerPin, uint8_t echoPin)
Definition: hcsr04.cxx:41
double getDistance(int sys)
Definition: hcsr04.cxx:111
std::string name()
Definition: hcsr04.h:84
API for the HC-SR04 Ultrasonic Sensor.
Definition: hcsr04.h:57