upm  0.5.1
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 {
58 class HCSR04 {
59  public:
68  HCSR04 (uint8_t triggerPin, uint8_t echoPin);
72  ~HCSR04 ();
73 
77  double getDistance (int sys);
78 
79 
80  uint8_t m_doWork;
85  std::string name()
86  {
87  return m_name;
88  }
89 
90  private:
95  static void ackEdgeDetected (void *ctx);
96 
97  double timing();
98  mraa_gpio_context m_triggerPinCtx;
99  mraa_gpio_context m_echoPinCtx;
100 
101  long m_RisingTimeStamp;
102  long m_FallingTimeStamp;
103  uint8_t m_InterruptCounter;
104 
105  std::string m_name;
106 };
107 
108 }
~HCSR04()
Definition: hcsr04.cxx:66
uint8_t m_doWork
Definition: hcsr04.h:80
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:85
API for the HC-SR04 Ultrasonic Sensor.
Definition: hcsr04.h:58