From 8693a72ed6a85fb622a625da35f680e4c0b86d36 Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Wed, 20 Jun 2018 18:27:59 +0300 Subject: [PATCH] Added interface iRotaryAngle Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- include/interfaces/iProximity.hpp | 5 ++++ include/interfaces/iRotaryAngle.hpp | 44 +++++++++++++++++++++++++++++ src/grove/groverotary.cxx | 5 ++++ src/grove/groverotary.hpp | 11 +++++++- src/rotary/rotary.cxx | 5 ++++ src/rotary/rotary.hpp | 12 +++++++- src/rotaryencoder/rotaryencoder.cxx | 4 ++- src/rotaryencoder/rotaryencoder.hpp | 12 ++++++-- 8 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 include/interfaces/iRotaryAngle.hpp diff --git a/include/interfaces/iProximity.hpp b/include/interfaces/iProximity.hpp index 1f4a6ec6..75c940d5 100644 --- a/include/interfaces/iProximity.hpp +++ b/include/interfaces/iProximity.hpp @@ -34,6 +34,11 @@ namespace upm public: virtual ~iProximity() {} + /** + * Get proximity value from sensor data. + * + * @return Proximity value as volts. + */ virtual float getValue() = 0; }; } diff --git a/include/interfaces/iRotaryAngle.hpp b/include/interfaces/iRotaryAngle.hpp new file mode 100644 index 00000000..c1055d87 --- /dev/null +++ b/include/interfaces/iRotaryAngle.hpp @@ -0,0 +1,44 @@ +/* + * 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 Rotary Angle sensors +*/ + class iRotaryAngle + { + public: + virtual ~iRotaryAngle() {} + + /** + * Get rotation value from sensor data. + * + * @return rotation value. + */ + virtual float getValue() = 0; + }; +} diff --git a/src/grove/groverotary.cxx b/src/grove/groverotary.cxx index 925c97fd..ab57e870 100644 --- a/src/grove/groverotary.cxx +++ b/src/grove/groverotary.cxx @@ -77,3 +77,8 @@ float GroveRotary::rel_rad() { return GroveRotary::rel_deg() * M_PI / 180.0; } + +float GroveRotary::getValue() +{ + return GroveRotary::abs_value(); +} diff --git a/src/grove/groverotary.hpp b/src/grove/groverotary.hpp index f3d34430..34d07bde 100644 --- a/src/grove/groverotary.hpp +++ b/src/grove/groverotary.hpp @@ -29,6 +29,7 @@ #include #include #include "grovebase.hpp" +#include namespace upm { @@ -53,7 +54,7 @@ namespace upm { * @image html rotaryencoder.jpg * @snippet grove-groverotary.cxx Interesting */ -class GroveRotary: public Grove { +class GroveRotary: public Grove, virtual public iRotaryAngle { public: /** * Grove rotary angle sensor constructor @@ -101,6 +102,14 @@ class GroveRotary: public Grove { * @return Signed radians from the ADC */ float rel_rad(); + + /** + * Get rotation value as raw degrees from the AIO pin. + * + * @return rotation value. + */ + virtual float getValue(); + private: mraa_aio_context m_aio; static const int m_max_angle = 300; diff --git a/src/rotary/rotary.cxx b/src/rotary/rotary.cxx index 03fe8140..fe7e1f73 100644 --- a/src/rotary/rotary.cxx +++ b/src/rotary/rotary.cxx @@ -76,3 +76,8 @@ float Rotary::rel_rad() { return Rotary::rel_deg() * M_PI / 180.0; } + + float Rotary::getValue() + { + return Rotary::abs_value(); + } diff --git a/src/rotary/rotary.hpp b/src/rotary/rotary.hpp index 092eeb8e..25158ec5 100644 --- a/src/rotary/rotary.hpp +++ b/src/rotary/rotary.hpp @@ -30,6 +30,7 @@ #include #include "rotary.hpp" +#include namespace upm { @@ -59,7 +60,7 @@ namespace upm { * @image html rotary.jpg * @snippet rotary.cxx Interesting */ -class Rotary{ +class Rotary : virtual public iRotaryAngle { public: /** * Rotary angle sensor constructor @@ -77,6 +78,7 @@ class Rotary{ * @return Unsigned value from the ADC */ float abs_value(); + /** * Gets absolute raw degrees from the AIO pin * @@ -107,6 +109,14 @@ class Rotary{ * @return Signed radians from the ADC */ float rel_rad(); + + /** + * Get rotation value as raw degrees from the AIO pin. + * + * @return rotation value. + */ + virtual float getValue(); + std::string name(){ return "Rotary Angle Sensor";} private: mraa_aio_context m_aio; diff --git a/src/rotaryencoder/rotaryencoder.cxx b/src/rotaryencoder/rotaryencoder.cxx index 71370c7d..13544d79 100644 --- a/src/rotaryencoder/rotaryencoder.cxx +++ b/src/rotaryencoder/rotaryencoder.cxx @@ -53,4 +53,6 @@ int RotaryEncoder::position() return rotaryencoder_get_position(m_rotaryencoder); } - +float RotaryEncoder::getValue() { + return (float) RotaryEncoder::position(); +} diff --git a/src/rotaryencoder/rotaryencoder.hpp b/src/rotaryencoder/rotaryencoder.hpp index 9c715e44..926edda9 100644 --- a/src/rotaryencoder/rotaryencoder.hpp +++ b/src/rotaryencoder/rotaryencoder.hpp @@ -24,6 +24,7 @@ #pragma once #include "rotaryencoder.h" +#include namespace upm { @@ -60,7 +61,7 @@ namespace upm { * @snippet rotaryencoder.cxx Interesting */ - class RotaryEncoder { + class RotaryEncoder : virtual public iRotaryAngle { public: /** * RotaryEncoder constructor @@ -87,6 +88,13 @@ namespace upm { */ int position(); + /** + * Get rotation value from sensor data. + * + * @return rotation value. + */ + virtual float getValue(); + private: /* Disable implicit copy and assignment operators */ RotaryEncoder(const RotaryEncoder&) = delete; @@ -95,5 +103,3 @@ namespace upm { rotaryencoder_context m_rotaryencoder; }; } - -