2014-12-05 13:29:36 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
2015-04-02 11:03:29 -06:00
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
2014-12-05 13:29:36 -07: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
|
|
|
|
|
2015-04-02 11:03:29 -06:00
|
|
|
#include <iostream>
|
2014-12-05 13:29:36 -07:00
|
|
|
#include <string>
|
|
|
|
#include <mraa/aio.h>
|
|
|
|
|
|
|
|
namespace upm {
|
2015-04-02 11:03:29 -06:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* @brief GP2Y0A-based IR Proximity Sensor library
|
2015-04-02 11:03:29 -06:00
|
|
|
* @defgroup gp2y0a libupm-gp2y0a
|
|
|
|
* @ingroup seeed analog light
|
|
|
|
*/
|
2014-12-05 13:29:36 -07:00
|
|
|
|
|
|
|
/**
|
2015-04-02 11:03:29 -06:00
|
|
|
* @library gp2y0a
|
2015-04-09 13:25:29 -07:00
|
|
|
* @sensor gp2y0a
|
2016-12-15 15:15:21 -08:00
|
|
|
* @comname Analog Infrared (IR) Based Distance Sensor
|
2015-06-01 15:44:07 -07:00
|
|
|
* @altname Grove 80cm IR Proximity Sensor
|
2015-04-09 13:25:29 -07:00
|
|
|
* @type light
|
|
|
|
* @man seeed
|
|
|
|
* @con analog
|
2016-12-15 15:15:21 -08:00
|
|
|
* @web http://wiki.seeed.cc/Grove-80cm_Infrared_Proximity_Sensor/
|
2015-04-02 11:03:29 -06:00
|
|
|
*
|
2015-06-01 10:56:03 -07:00
|
|
|
* @brief API for the GP2Y0A family of IR Proximity Sensors
|
2014-12-05 13:29:36 -07:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* Sensors of this family return an analog voltage corresponding to the distance
|
|
|
|
* of an object from the sensor. The voltage is lower when objects
|
2014-12-05 13:29:36 -07:00
|
|
|
* are far away; the voltage increases as objects get closer
|
2015-04-02 11:03:29 -06:00
|
|
|
* to the sensor.
|
2014-12-05 13:29:36 -07:00
|
|
|
*
|
2015-05-26 15:58:34 -07:00
|
|
|
* @image html gp2y0a.jpg
|
2015-04-02 11:03:29 -06:00
|
|
|
* @snippet gp2y0a.cxx Interesting
|
2014-12-05 13:29:36 -07:00
|
|
|
*/
|
2015-04-02 11:03:29 -06:00
|
|
|
class GP2Y0A {
|
2014-12-05 13:29:36 -07:00
|
|
|
public:
|
2015-04-02 11:03:29 -06:00
|
|
|
|
2014-12-05 13:29:36 -07:00
|
|
|
/**
|
2015-04-02 11:03:29 -06:00
|
|
|
* GP2Y0A sensor constructor
|
2014-12-05 13:29:36 -07:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param pin Analog pin to use
|
2014-12-05 13:29:36 -07:00
|
|
|
*/
|
2015-04-02 11:03:29 -06:00
|
|
|
GP2Y0A(int pin);
|
|
|
|
|
2014-12-05 13:29:36 -07:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* GP2Y0A destructor
|
2014-12-05 13:29:36 -07:00
|
|
|
*/
|
2015-04-02 11:03:29 -06:00
|
|
|
~GP2Y0A();
|
|
|
|
|
2014-12-05 13:29:36 -07:00
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Gets an average voltage value from the sensor
|
2014-12-05 13:29:36 -07:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param aref Reference voltage in use (usually 5.0V or 3.3V)
|
|
|
|
* @param samples Number of samples to average over
|
|
|
|
* @return Average voltage reading
|
2014-12-05 13:29:36 -07:00
|
|
|
*/
|
|
|
|
float value(float aref, uint8_t samples);
|
|
|
|
|
|
|
|
private:
|
|
|
|
mraa_aio_context m_aio;
|
2015-04-02 11:03:29 -06:00
|
|
|
// ADC resolution
|
|
|
|
int m_aRes;
|
2014-12-05 13:29:36 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|