Added interfaces iEC,iEmg,iClock,iHeartRate,iLineFinder

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:
Stefan Andritoiu
2018-06-20 18:24:26 +03:00
committed by Serban Waltter
parent e7820f2831
commit 69464ae93b
22 changed files with 368 additions and 59 deletions

View File

@ -73,6 +73,12 @@ float DFREC::getEC()
return dfrec_get_ec(m_dfrec);
}
float DFREC::getECValue()
{
DFREC::update();
return DFREC::getEC();
}
float DFREC::getVolts()
{
return dfrec_get_volts(m_dfrec);

View File

@ -31,6 +31,7 @@
#include <string.h>
#include "dfrec.h"
#include <interfaces/iEC.hpp>
namespace upm {
/**
@ -65,7 +66,7 @@ namespace upm {
* @snippet dfrec.cxx Interesting
*/
class DFREC {
class DFREC : virtual public iEC {
public:
/**
@ -120,6 +121,13 @@ namespace upm {
*/
float getEC();
/**
* Get computed EC (ms/cm) value from the sensor. update() is called
* in this function.
* @return EC value in ms/cm.
*/
virtual float getECValue();
/**
* Get the measured volts from the sensor. update() must have been
* called prior to calling this function.

View File

@ -28,6 +28,7 @@
#include <string>
#include <mraa/i2c.hpp>
#include <interfaces/iClock.hpp>
#define DS1307_I2C_BUS 0
#define DS1307_I2C_ADDR 0x68
@ -69,7 +70,7 @@ namespace upm {
* @image html ds1307.jpg
* @snippet ds1307.cxx Interesting
*/
class DS1307 {
class DS1307 : virtual public iClock {
public:
/**
* DS1307 constructor
@ -83,7 +84,7 @@ namespace upm {
*
* @return True if time data loaded successfully
*/
bool loadTime();
virtual bool loadTime();
/**
* Sets the time. You should call loadTime() beforehand to
@ -91,7 +92,7 @@ namespace upm {
*
* @return True if time is set successfully
*/
bool setTime();
virtual bool setTime();
/**
* Enables an oscillator on the clock.
@ -132,7 +133,7 @@ namespace upm {
* Converts a BCD value into decimal
*
* @param val BCD value to convert
* @return Converted decimal value
* @return Converted decimal value
*/
unsigned int bcdToDec(uint8_t val);
@ -190,5 +191,3 @@ namespace upm {
mraa::I2c m_i2c;
};
}

View File

@ -81,6 +81,12 @@ float ECEZO::getEC()
return ecezo_get_ec(m_ecezo);
}
float ECEZO::getECValue()
{
ECEZO::update();
return ECEZO::getEC();
}
float ECEZO::getTDS()
{
return ecezo_get_tds(m_ecezo);

View File

@ -30,6 +30,7 @@
#include <unistd.h>
#include "ecezo.h"
#include <interfaces/iEC.hpp>
namespace upm {
/**
@ -57,7 +58,7 @@ namespace upm {
* @snippet ecezo.cxx Interesting
*/
class ECEZO {
class ECEZO : virtual public iEC {
public:
/**
@ -127,6 +128,14 @@ namespace upm {
*/
float getEC();
/**
* Measures and retrieves the Electrical Conductivity (EC)
* value in microsiemens. update() is called during this function.
*
* @return EC value in microsiemens
*/
virtual float getECValue();
/**
* Retrieve the last measured Total Dissolved solids (TDS) value.
* update() must have been called before calling this

View File

@ -65,12 +65,12 @@ uint32_t EHR::getMillis()
gettimeofday(&now, NULL);
// compute the delta since m_startTime
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
{
elapsed.tv_usec += 1000000;
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec - 1;
}
else
}
else
{
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec;
}
@ -92,7 +92,7 @@ void EHR::clearBeatCounter()
void EHR::startBeatCounter()
{
// install our interrupt handler
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
&beatISR, this);
}
@ -117,7 +117,7 @@ int EHR::heartRate()
{
uint32_t millis = getMillis();
uint32_t beats = beatCounter();
float heartRate = 0;
// wait at least 5 seconds before attempting to compute the
// heart rate
@ -128,3 +128,8 @@ int EHR::heartRate()
return int(heartRate);
}
int EHR::getHeartRate()
{
return EHR::heartRate();
}

View File

@ -27,6 +27,7 @@
#include <stdint.h>
#include <sys/time.h>
#include <mraa/gpio.h>
#include <interfaces/iHeartRate.hpp>
namespace upm {
/**
@ -46,12 +47,12 @@ namespace upm {
* @brief API for the Ear-clip Heart Rate Sensor
*
* UPM module for the ear-clip heart rate sensor. It is used to measure your
* heart rate.
* heart rate.
*
* @image html ehr.jpg
* @image html ehr.jpg
* @snippet ehr.cxx Interesting
*/
class EHR {
class EHR : virtual public iHeartRate {
public:
/**
* EHR constructor
@ -110,17 +111,22 @@ namespace upm {
*/
int heartRate();
/**
* Retrieve the computed heart rate
*
* @return Computed heart rate
*/
virtual int getHeartRate();
private:
/**
* Beat interrupt service routine (ISR)
*
*/
static void beatISR(void *ctx);
volatile uint32_t m_beatCounter;
struct timeval m_startTime;
mraa_gpio_context m_gpio;
};
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.h>
#include "interfaces/iEmg.hpp"
namespace upm {
/**
@ -43,14 +44,14 @@ namespace upm {
* @con analog
*
* @brief API for the Grove EMG Muscle Signal Reader
*
*
* Grove EMG muscle signal reader gathers small muscle signals,
* then processes them, and returns the result
*
* @image html emg.jpg
* @snippet emg.cxx Interesting
*/
class EMG {
class EMG : virtual public iEmg {
public:
/**
* Grove EMG reader constructor
@ -66,18 +67,16 @@ namespace upm {
/**
* Calibrates the Grove EMG reader
*/
void calibrate();
virtual void calibrate();
/**
* Measures muscle signals from the reader
*
* @return Muscle output as analog voltage
*/
int value();
virtual int value();
private:
mraa_aio_context m_aio;
};
}

View File

@ -65,12 +65,12 @@ uint32_t GroveEHR::getMillis()
gettimeofday(&now, NULL);
// compute the delta since m_startTime
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
{
elapsed.tv_usec += 1000000;
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec - 1;
}
else
}
else
{
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec;
}
@ -92,7 +92,7 @@ void GroveEHR::clearBeatCounter()
void GroveEHR::startBeatCounter()
{
// install our interrupt handler
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
&beatISR, this);
}
@ -117,7 +117,7 @@ int GroveEHR::heartRate()
{
uint32_t millis = getMillis();
uint32_t beats = beatCounter();
float heartRate = 0;
// wait at least 5 seconds before attempting to compute the
// heart rate
@ -128,3 +128,8 @@ int GroveEHR::heartRate()
return int(heartRate);
}
int GroveEHR::getHeartRate()
{
return GroveEHR::heartRate();
}

View File

@ -27,6 +27,7 @@
#include <stdint.h>
#include <sys/time.h>
#include <mraa/gpio.h>
#include <interfaces/iHeartRate.hpp>
namespace upm {
/**
@ -48,12 +49,12 @@ namespace upm {
* @brief API for the Grove Ear-clip Heart Rate Sensor
*
* UPM module for the Grove ear-clip heart rate sensor. It is used to measure your
* heart rate.
* heart rate.
*
* @image html groveehr.jpg
* @image html groveehr.jpg
* @snippet groveehr.cxx Interesting
*/
class GroveEHR {
class GroveEHR : virtual public iHeartRate {
public:
/**
* GroveEHR constructor
@ -112,17 +113,22 @@ namespace upm {
*/
int heartRate();
/**
* Retrieve the computed heart rate
*
* @return Computed heart rate
*/
virtual int getHeartRate();
private:
/**
* Beat interrupt service routine (ISR)
*
*/
static void beatISR(void *ctx);
volatile uint32_t m_beatCounter;
struct timeval m_startTime;
mraa_gpio_context m_gpio;
};
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.h>
#include "interfaces/iEmg.hpp"
namespace upm {
/**
@ -51,7 +52,7 @@ namespace upm {
* @image html emg.jpg
* @snippet groveemg.cxx Interesting
*/
class GroveEMG {
class GroveEMG : virtual public iEmg {
public:
/**
* Grove EMG reader constructor
@ -67,18 +68,16 @@ namespace upm {
/**
* Calibrates the Grove EMG reader
*/
void calibrate();
virtual void calibrate();
/**
* Measures muscle signals from the reader
*
* @return Muscle output as analog voltage
*/
int value();
virtual int value();
private:
mraa_aio_context m_aio;
};
}

View File

@ -68,3 +68,8 @@ int GroveGSR::value()
int val = mraa_aio_read(m_aio);
return val;
}
float GroveGSR::getECValue()
{
return (float) GroveGSR::value();
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.h>
#include <interfaces/iEC.hpp>
namespace upm {
/**
@ -44,7 +45,7 @@ namespace upm {
* @con analog
*
* @brief API for the Grove GSR Galvanic Skin Response Sensor
*
*
* Measures the electrical conductance of skin
* to measure strong emotional reactions.
* In other words, it measures sweat on your fingers
@ -53,7 +54,7 @@ namespace upm {
* @image html gsr.jpg
* @snippet grovegsr.cxx Interesting
*/
class GroveGSR {
class GroveGSR : virtual public iEC {
public:
/**
* Grove GSR sensor constructor
@ -78,9 +79,14 @@ namespace upm {
*/
int value();
/**
* Gets the electrical conductance of the skin from the sensor
*
* @return Electrical conductance of the skin
*/
virtual float getECValue();
private:
mraa_aio_context m_aio;
};
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/gpio.h>
#include <interfaces/iLineFinder.hpp>
namespace upm {
/**
@ -53,7 +54,7 @@ namespace upm {
* @image html grovelinefinder.jpg
* @snippet grovelinefinder.cxx Interesting
*/
class GroveLineFinder {
class GroveLineFinder : virtual public iLineFinder {
public:
/**
* Grove Line Finder digital sensor constructor
@ -70,17 +71,15 @@ namespace upm {
*
* @return True if white is detected
*/
bool whiteDetected();
virtual bool whiteDetected();
/**
* Determines whether black has been detected
*
* @return True if black is detected
*/
bool blackDetected();
virtual bool blackDetected();
private:
mraa_gpio_context m_gpio;
};
}

View File

@ -65,3 +65,8 @@ int GSR::value()
int val = mraa_aio_read(m_aio);
return val;
}
float GSR::getECValue()
{
return (float) GSR::value();
}

View File

@ -25,6 +25,7 @@
#include <string>
#include <mraa/aio.h>
#include <interfaces/iEC.hpp>
namespace upm {
/**
@ -42,7 +43,7 @@ namespace upm {
* @con analog
*
* @brief API for the Grove GSR Galvanic Skin Response Sensor
*
*
* Measures the electrical conductance of skin
* to measure strong emotional reactions.
* In other words, it measures sweat on your fingers
@ -51,7 +52,7 @@ namespace upm {
* @image html gsr.jpg
* @snippet gsr.cxx Interesting
*/
class GSR {
class GSR : virtual public iEC {
public:
/**
* Grove GSR sensor constructor
@ -76,9 +77,14 @@ namespace upm {
*/
int value();
/**
* Gets the electrical conductance of the skin from the sensor
*
* @return Electrical conductance of the skin
*/
virtual float getECValue();
private:
mraa_aio_context m_aio;
};
}

View File

@ -24,6 +24,7 @@
#pragma once
#include <linefinder.h>
#include <interfaces/iLineFinder.hpp>
namespace upm {
/**
@ -51,7 +52,7 @@ namespace upm {
* @image html linefinder.jpg
* @snippet linefinder.cxx Interesting
*/
class LineFinder {
class LineFinder : virtual public iLineFinder {
public:
/**
* Line Finder digital sensor constructor
@ -70,14 +71,14 @@ namespace upm {
*
* @return True if white is detected
*/
bool whiteDetected();
virtual bool whiteDetected();
/**
* Determines whether black has been detected
*
* @return True if black is detected
*/
bool blackDetected();
virtual bool blackDetected();
private:
/* Disable implicit copy and assignment operators */
@ -87,5 +88,3 @@ namespace upm {
linefinder_context m_linefinder;
};
}