upmc: Updates for building C modules w/base UPM

Test commit for building C UPM modules.

    * Added C include directory
    * Added C utilities directory
    * Rename C++ upm.h -> upm.hpp to make room for C upm.h
    * Added upm_mixed_module_init function to src/CMakeLists.txt.  This
      function takes filesnames similar to upm_module_init and does a
      bit of processing before calling upm_module_init.
    * Added c example directory.  Changed c++ example names.
    * Added dfrph implemention for testing (C++ wraps C).  Added mraa
      to .pc requires for dfrph.  Tested against stand-alone project.
      Added dfrph c example.
    * Update implemention of pkg-config file generation.
    * Added two cmake cache variables: BUILDCPP and BUILDFTI
    * Removed src from swig_add_module calls, added libname to
      swig_link_libraries calls.  Shrinks swig'ed binaries by ~13%.
    * Added install target in upm/CMakeLists.txt to install C header,
      directory.  Is this where we want this?
    * C FTI header directory is include/fti

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-08-17 17:58:21 -07:00
parent d866b25f85
commit c1f9d15f67
46 changed files with 1945 additions and 87 deletions

View File

@@ -23,52 +23,54 @@
*/
#include <iostream>
#include <stdexcept>
#include "dfrph.hpp"
using namespace std;
using namespace upm;
DFRPH::DFRPH(int pin, float aref) :
m_aio(pin)
DFRPH::DFRPH(int pin, float vref) : _dev(dfrph_init(pin))
{
m_aRes = (1 << m_aio.getBit());
m_aref = aref;
m_offset = 0.0;
if (_dev == NULL)
throw std::invalid_argument(std::string(__FUNCTION__) +
": dfrph_init() failed, invalid pin?");
}
DFRPH::~DFRPH()
{
}
float DFRPH::volts()
{
int val = m_aio.read();
return(val * (m_aref / m_aRes));
dfrph_close(_dev);
}
void DFRPH::setOffset(float offset)
{
m_offset = offset;
dfrph_set_offset(_dev, offset);
}
void DFRPH::setScale(float scale)
{
dfrph_set_scale(_dev, scale);
}
float DFRPH::volts()
{
float volts = 0.0;
dfrph_get_raw_volts(_dev, &volts);
return volts;
}
float DFRPH::pH(unsigned int samples)
{
if (!samples)
samples = 1;
float ph_avg = 0.0;
float sum = 0.0;
// Read at least 1 sample
if (samples == 0) samples = 1;
for (int i=0; i<samples; i++)
float ph = 0.0;
for (int i =0; i < samples; i++)
{
sum += volts();
usleep(20000);
dfrph_get_ph(_dev, &ph);
ph_avg += ph;
}
sum /= samples;
// 3.5 is a 'magic' DFRobot number. Seems to work though :)
return (3.5 * sum + m_offset);
return ph_avg/samples;
}