Added iVDiv interface
ADD
include/interfaces/iVDiv.hpp
+/*
+ * Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
+ * 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 Voltage Dividing sensors
+*/
+ class iVDiv
+ {
+ public:
+ virtual ~iVDiv() {}
+
+ /**
+ * Gets the conversion value from the sensor
+ *
+ * @return ADC conversion value
+ */
+ virtual unsigned int getValue() = 0;
+
+ };
+}

MODIFY
src/grovevdiv/grovevdiv.cxx
src/grovevdiv/grovevdiv.cxx
@@ -60,9 +60,13 @@ unsigned int GroveVDiv::value(unsigned int samples)
return (sum / samples);
}
+unsigned int GroveVDiv::getValue()
+{
+ return GroveVDiv::value(1);
+}
+
float GroveVDiv::computedValue(uint8_t gain, unsigned int val, int vref, int res)
{
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
}
-

MODIFY
src/grovevdiv/grovevdiv.hpp
src/grovevdiv/grovevdiv.hpp
#include <iostream>
#include <stdint.h>
#include <mraa/aio.h>
+#include <interfaces/iVDiv.hpp>
// reference voltage in millivolts
#define GROVEVDIV_VREF 4980
@@ -59,7 +60,7 @@ namespace upm {
* @image html grovevdiv.jpg
* @snippet grovevdiv.cxx Interesting
*/
- class GroveVDiv {
+ class GroveVDiv : virtual public iVDiv {
public:
/**
* Grove Voltage Divider sensor constructor
@@ -81,6 +82,13 @@ namespace upm {
*/
unsigned int value(unsigned int samples);
+ /**
+ * Gets the conversion value from the sensor
+ *
+ * @return ADC conversion value
+ */
+ virtual unsigned int getValue();
+
/**
* Computes the measured voltage
*

MODIFY
src/vdiv/vdiv.cxx
src/vdiv/vdiv.cxx
@@ -60,9 +60,13 @@ unsigned int VDiv::value(unsigned int samples)
return (sum / samples);
}
+unsigned int VDiv::getValue()
+{
+ return VDiv::value(1);
+}
+
float VDiv::computedValue(uint8_t gain, unsigned int val, int vref, int res)
{
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
}
-

MODIFY
src/vdiv/vdiv.hpp
src/vdiv/vdiv.hpp
#include <iostream>
#include <stdint.h>
#include <mraa/aio.h>
+#include <interfaces/iVDiv.hpp>
// reference voltage in millivolts
#define VDIV_VREF 4980
@@ -58,7 +59,7 @@ namespace upm {
* @image html vdiv.jpg
* @snippet vdiv.cxx Interesting
*/
- class VDiv {
+ class VDiv : virtual public iVDiv {
public:
/**
* Voltage Divider sensor constructor
@@ -80,6 +81,13 @@ namespace upm {
*/
unsigned int value(unsigned int samples);
+ /**
+ * Gets the conversion value from the sensor
+ *
+ * @return ADC conversion value
+ */
+ virtual unsigned int getValue();
+
/**
* Computes the measured voltage
*

Added iVDiv interface

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>