From 75c7bd8d12aa414a2b369d814fb83de685039727 Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Wed, 20 Jun 2018 18:27:11 +0300 Subject: [PATCH] Added iProximity interface Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- include/interfaces/iProximity.hpp | 39 +++++++++++++++++++++++++++++++ src/gp2y0a/gp2y0a.cxx | 5 ++++ src/gp2y0a/gp2y0a.hpp | 19 +++++++++++---- src/max44000/max44000.cxx | 5 ++++ src/max44000/max44000.hpp | 11 +++++++-- 5 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 include/interfaces/iProximity.hpp diff --git a/include/interfaces/iProximity.hpp b/include/interfaces/iProximity.hpp new file mode 100644 index 00000000..1f4a6ec6 --- /dev/null +++ b/include/interfaces/iProximity.hpp @@ -0,0 +1,39 @@ +/* + * Author: Mihai Stefanescu + * Copyright (c) 2018 Intel Corporation. + * + * 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 + +namespace upm +{ +/** + * @brief Interface for Proximity sensors +*/ + class iProximity + { + public: + virtual ~iProximity() {} + + virtual float getValue() = 0; + }; +} diff --git a/src/gp2y0a/gp2y0a.cxx b/src/gp2y0a/gp2y0a.cxx index 0b375a90..a89a11d6 100644 --- a/src/gp2y0a/gp2y0a.cxx +++ b/src/gp2y0a/gp2y0a.cxx @@ -67,3 +67,8 @@ float GP2Y0A::value(float aref, uint8_t samples) return volts; } + +float GP2Y0A::getValue() +{ + return GP2Y0A::value(5.0, (uint8_t) 1); +} diff --git a/src/gp2y0a/gp2y0a.hpp b/src/gp2y0a/gp2y0a.hpp index fdfd5c89..52845206 100644 --- a/src/gp2y0a/gp2y0a.hpp +++ b/src/gp2y0a/gp2y0a.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace upm { /** @@ -46,15 +47,15 @@ namespace upm { * * @brief API for the GP2Y0A family of IR Proximity Sensors * - * Sensors of this family return an analog voltage corresponding to the distance + * Sensors of this family return an analog voltage corresponding to the distance * of an object from the sensor. The voltage is lower when objects * are far away; the voltage increases as objects get closer - * to the sensor. + * to the sensor. * * @image html gp2y0a.jpg * @snippet gp2y0a.cxx Interesting */ - class GP2Y0A { + class GP2Y0A : virtual public iProximity { public: /** @@ -78,11 +79,19 @@ namespace upm { */ float value(float aref, uint8_t samples); + /** + * Gets the voltage value from the sensor from a single sample + * A refernce voltage of 5.0V is used for the reading. + * + * @return Voltage reading from a single sample + */ + virtual float getValue(); + + + private: mraa_aio_context m_aio; // ADC resolution int m_aRes; }; } - - diff --git a/src/max44000/max44000.cxx b/src/max44000/max44000.cxx index d6fa6011..5207029a 100644 --- a/src/max44000/max44000.cxx +++ b/src/max44000/max44000.cxx @@ -58,6 +58,11 @@ MAX44000::getProximity () { return data; } +float +MAX44000::getValue() { + return (float) MAX44000::getProximity(); +} + uint16_t MAX44000::getAmbient () { uint16_t data = 0; diff --git a/src/max44000/max44000.hpp b/src/max44000/max44000.hpp index 333c73cb..f70dc957 100644 --- a/src/max44000/max44000.hpp +++ b/src/max44000/max44000.hpp @@ -25,6 +25,7 @@ #include #include +#include #define ADDR 0x4A // device address @@ -71,14 +72,14 @@ namespace upm { * Maxim Integrated* * [MAX44000](http://datasheets.maximintegrated.com/en/ds/MAX44000.pdf) * is an ambient and infrared proximity sensor. This module was tested on the - * Maxim Integrated + * Maxim Integrated * [MAX44000PMB1 PMOD module] * (http://datasheets.maximintegrated.com/en/ds/MAX44000PMB1.pdf) from the * analog PMOD kit. * * @snippet max44000.cxx Interesting */ -class MAX44000 { +class MAX44000 : virtual public iProximity { public: /** * Instantiates an MAX44000 object @@ -99,6 +100,12 @@ class MAX44000 { * Reads the proximity value from the sensor (based on ambient data). */ uint16_t getProximity (); + + /** + * Reads the proximity value from the sensor. + */ + virtual float getValue (); + /** * Reads the ambient value from the sensor (based on ambient data). */