mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Added iVDiv interface
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:
parent
b2441100fa
commit
ec58633ca5
45
include/interfaces/iVDiv.hpp
Normal file
45
include/interfaces/iVDiv.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
@ -56,13 +56,17 @@ unsigned int GroveVDiv::value(unsigned int samples)
|
|||||||
if (sum == -1) return 0;
|
if (sum == -1) return 0;
|
||||||
usleep(2000);
|
usleep(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sum / 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)
|
float GroveVDiv::computedValue(uint8_t gain, unsigned int val, int vref, int res)
|
||||||
{
|
{
|
||||||
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
|
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <mraa/aio.h>
|
#include <mraa/aio.h>
|
||||||
|
#include <interfaces/iVDiv.hpp>
|
||||||
|
|
||||||
// reference voltage in millivolts
|
// reference voltage in millivolts
|
||||||
#define GROVEVDIV_VREF 4980
|
#define GROVEVDIV_VREF 4980
|
||||||
@ -59,7 +60,7 @@ namespace upm {
|
|||||||
* @image html grovevdiv.jpg
|
* @image html grovevdiv.jpg
|
||||||
* @snippet grovevdiv.cxx Interesting
|
* @snippet grovevdiv.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class GroveVDiv {
|
class GroveVDiv : virtual public iVDiv {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Grove Voltage Divider sensor constructor
|
* Grove Voltage Divider sensor constructor
|
||||||
@ -81,6 +82,13 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
unsigned int value(unsigned int samples);
|
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
|
* Computes the measured voltage
|
||||||
*
|
*
|
||||||
|
@ -56,13 +56,17 @@ unsigned int VDiv::value(unsigned int samples)
|
|||||||
if (sum == -1) return 0;
|
if (sum == -1) return 0;
|
||||||
usleep(2000);
|
usleep(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sum / 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)
|
float VDiv::computedValue(uint8_t gain, unsigned int val, int vref, int res)
|
||||||
{
|
{
|
||||||
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
|
return ((float(gain) * float(val) * float(vref) / float(res)) / 1000.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <mraa/aio.h>
|
#include <mraa/aio.h>
|
||||||
|
#include <interfaces/iVDiv.hpp>
|
||||||
|
|
||||||
// reference voltage in millivolts
|
// reference voltage in millivolts
|
||||||
#define VDIV_VREF 4980
|
#define VDIV_VREF 4980
|
||||||
@ -58,7 +59,7 @@ namespace upm {
|
|||||||
* @image html vdiv.jpg
|
* @image html vdiv.jpg
|
||||||
* @snippet vdiv.cxx Interesting
|
* @snippet vdiv.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class VDiv {
|
class VDiv : virtual public iVDiv {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Voltage Divider sensor constructor
|
* Voltage Divider sensor constructor
|
||||||
@ -80,6 +81,13 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
unsigned int value(unsigned int samples);
|
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
|
* Computes the measured voltage
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user