mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
Added iVDiv interface
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:

committed by
Serban Waltter

parent
b2441100fa
commit
ec58633ca5
@ -56,13 +56,17 @@ unsigned int GroveVDiv::value(unsigned int samples)
|
||||
if (sum == -1) return 0;
|
||||
usleep(2000);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#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
|
||||
*
|
||||
|
@ -56,13 +56,17 @@ unsigned int VDiv::value(unsigned int samples)
|
||||
if (sum == -1) return 0;
|
||||
usleep(2000);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#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
|
||||
*
|
||||
|
Reference in New Issue
Block a user