2015-08-27 22:39:09 -03:00
|
|
|
/*
|
2014-06-04 14:57:19 +00:00
|
|
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
2015-08-27 22:39:09 -03:00
|
|
|
* Author: Rafael Neri <rafael.neri@gmail.com>
|
|
|
|
* Copyright (c) 2014-2015 Intel Corporation.
|
2014-06-04 14:57:19 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-06-07 10:46:57 -07:00
|
|
|
#include "hcsr04.h"
|
2014-06-04 14:57:19 +00:00
|
|
|
|
|
|
|
namespace upm {
|
2014-09-22 16:37:36 +01:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* @brief HC-SR04 Ultrasonic Sensor library
|
2014-09-22 16:37:36 +01:00
|
|
|
* @defgroup hcsr04 libupm-hcsr04
|
2015-04-13 11:39:10 -07:00
|
|
|
* @ingroup generic gpio sound
|
2014-09-22 16:37:36 +01:00
|
|
|
*/
|
|
|
|
|
2014-06-10 07:24:56 +00:00
|
|
|
/**
|
2015-04-13 11:39:10 -07:00
|
|
|
* @library hcsr04
|
|
|
|
* @sensor hcsr04
|
2016-12-15 15:15:21 -08:00
|
|
|
* @comname Ultrasonic Distance Measuring Sensor
|
2015-04-13 11:39:10 -07:00
|
|
|
* @type sound
|
|
|
|
* @man generic
|
|
|
|
* @con gpio
|
2016-12-15 15:15:21 -08:00
|
|
|
* @web https://www.sparkfun.com/products/13959
|
2015-04-13 11:39:10 -07:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @brief API for the HC-SR04 Ultrasonic Sensor
|
2014-06-10 07:24:56 +00:00
|
|
|
*
|
2015-09-08 11:03:36 -07:00
|
|
|
* This module defines the HC-SR04 interface for libhcsr04
|
2014-06-10 07:24:56 +00:00
|
|
|
*
|
2016-02-09 08:49:15 -08:00
|
|
|
* @image html groveultrasonic.jpg
|
2014-06-10 07:24:56 +00:00
|
|
|
* @snippet hcsr04.cxx Interesting
|
|
|
|
*/
|
2014-06-04 14:57:19 +00:00
|
|
|
class HCSR04 {
|
|
|
|
public:
|
2014-06-10 07:24:56 +00:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Instantiates an HCSR04 object
|
2014-06-10 07:24:56 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param triggerPin Pin to trigger the sensor for distance
|
|
|
|
* @param echoPin Pulse response to triggering
|
2014-06-10 07:24:56 +00:00
|
|
|
*/
|
2016-12-08 15:10:36 -08:00
|
|
|
HCSR04 (int triggerPin, int echoPin);
|
2014-06-10 07:24:56 +00:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* HCSR04 object destructor
|
2014-06-10 07:24:56 +00:00
|
|
|
*/
|
2014-06-04 14:57:19 +00:00
|
|
|
~HCSR04 ();
|
2014-06-10 07:24:56 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Gets the distance from the sensor
|
2017-04-10 16:59:39 -07:00
|
|
|
*
|
2017-06-07 10:46:57 -07:00
|
|
|
* @param unit Selects units for measurement
|
2014-06-10 07:24:56 +00:00
|
|
|
*/
|
2017-06-07 10:46:57 -07:00
|
|
|
double getDistance (HCSR04_U unit);
|
2014-06-04 14:57:19 +00:00
|
|
|
|
|
|
|
private:
|
2017-06-07 10:46:57 -07:00
|
|
|
hcsr04_context m_hcsr04;
|
|
|
|
HCSR04(const HCSR04& src) { /* do not create copied constructor */ }
|
|
|
|
HCSR04& operator=(const HCSR04&) {return *this;}
|
|
|
|
};
|
2014-06-04 14:57:19 +00:00
|
|
|
}
|