From a589f92cec222082e0444046d56065d4bc320531 Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Wed, 20 Jun 2018 18:24:26 +0300 Subject: [PATCH] Added interfaces iEC,iEmg,iClock,iHeartRate,iLineFinder Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- include/interfaces/iClock.hpp | 52 +++++++++++++++++++++++++ include/interfaces/iEC.hpp | 45 +++++++++++++++++++++ include/interfaces/iEmg.hpp | 49 +++++++++++++++++++++++ include/interfaces/iHeartRate.hpp | 44 +++++++++++++++++++++ include/interfaces/iLineFinder.hpp | 51 ++++++++++++++++++++++++ src/dfrec/dfrec.cxx | 6 +++ src/dfrec/dfrec.hpp | 10 ++++- src/ds1307/ds1307.hpp | 11 +++--- src/ecezo/ecezo.cxx | 6 +++ src/ecezo/ecezo.hpp | 11 +++++- src/ehr/ehr.cxx | 15 ++++--- src/ehr/ehr.hpp | 18 ++++++--- src/emg/emg.hpp | 11 +++--- src/groveehr/groveehr.cxx | 15 ++++--- src/groveehr/groveehr.hpp | 18 ++++++--- src/groveemg/groveemg.hpp | 9 ++--- src/grovegsr/grovegsr.cxx | 5 +++ src/grovegsr/grovegsr.hpp | 14 +++++-- src/grovelinefinder/grovelinefinder.hpp | 9 ++--- src/gsr/gsr.cxx | 5 +++ src/gsr/gsr.hpp | 14 +++++-- src/linefinder/linefinder.hpp | 9 ++--- 22 files changed, 368 insertions(+), 59 deletions(-) create mode 100644 include/interfaces/iClock.hpp create mode 100644 include/interfaces/iEC.hpp create mode 100644 include/interfaces/iEmg.hpp create mode 100644 include/interfaces/iHeartRate.hpp create mode 100644 include/interfaces/iLineFinder.hpp diff --git a/include/interfaces/iClock.hpp b/include/interfaces/iClock.hpp new file mode 100644 index 00000000..c1eb64a8 --- /dev/null +++ b/include/interfaces/iClock.hpp @@ -0,0 +1,52 @@ +/* + * Author: Mihai Stefanescu + * 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 Real Time Clock (RTC) Modules +*/ + class iClock + { + public: + virtual ~iClock() {} + + /** + * Loads all the time values + * + * @return True if time data loaded successfully + */ + virtual bool loadTime() = 0; + + /** + * Sets the time. You should call loadTime() beforehand to + * maintain consistency + * + * @return True if time is set successfully + */ + virtual bool setTime() = 0; + }; +} diff --git a/include/interfaces/iEC.hpp b/include/interfaces/iEC.hpp new file mode 100644 index 00000000..da885f0c --- /dev/null +++ b/include/interfaces/iEC.hpp @@ -0,0 +1,45 @@ +/* + * Author: Mihai Stefanescu + * 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 Electrical Conductivity (EC) Sensors +*/ + class iEC + { + public: + virtual ~iEC() {} + + /** + * Get computed EC (ms/cm) value from the sensor. + * + * @return EC value in ms/cm. + */ + virtual float getECValue() = 0; + + }; +} diff --git a/include/interfaces/iEmg.hpp b/include/interfaces/iEmg.hpp new file mode 100644 index 00000000..e0ed3f1c --- /dev/null +++ b/include/interfaces/iEmg.hpp @@ -0,0 +1,49 @@ +/* + * Author: Mihai Stefanescu + * 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 Electromyography (EMG) Sensors +*/ + class iEmg + { + public: + virtual ~iEmg() {} + + /** + * Calibrates the EMG reader + */ + virtual void calibrate() = 0; + + /** + * Measures muscle signals from the reader + * + * @return Muscle output as analog voltage + */ + virtual int value() = 0; + }; +} diff --git a/include/interfaces/iHeartRate.hpp b/include/interfaces/iHeartRate.hpp new file mode 100644 index 00000000..2ecaec8e --- /dev/null +++ b/include/interfaces/iHeartRate.hpp @@ -0,0 +1,44 @@ +/* + * Author: Mihai Stefanescu + * 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 Heart Rate sensors +*/ + class iHeartRate + { + public: + virtual ~iHeartRate() {} + + /** + * Retrieve the computed heart rate + * + * @return Computed heart rate + */ + virtual int getHeartRate() = 0; + }; +} diff --git a/include/interfaces/iLineFinder.hpp b/include/interfaces/iLineFinder.hpp new file mode 100644 index 00000000..ca823ef2 --- /dev/null +++ b/include/interfaces/iLineFinder.hpp @@ -0,0 +1,51 @@ +/* + * Author: Mihai Stefanescu + * 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 Line Finder Modules +*/ + class iLineFinder + { + public: + virtual ~iLineFinder() {} + + /** + * Determines whether white has been detected + * + * @return True if white is detected + */ + virtual bool whiteDetected() = 0; + /** + * Determines whether black has been detected + * + * @return True if black is detected + */ + virtual bool blackDetected() = 0; + + }; +} diff --git a/src/dfrec/dfrec.cxx b/src/dfrec/dfrec.cxx index 1c899620..e6965f04 100644 --- a/src/dfrec/dfrec.cxx +++ b/src/dfrec/dfrec.cxx @@ -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); diff --git a/src/dfrec/dfrec.hpp b/src/dfrec/dfrec.hpp index c62e9353..0f6893df 100644 --- a/src/dfrec/dfrec.hpp +++ b/src/dfrec/dfrec.hpp @@ -31,6 +31,7 @@ #include #include "dfrec.h" +#include 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. diff --git a/src/ds1307/ds1307.hpp b/src/ds1307/ds1307.hpp index d5d205cb..f1bf032d 100644 --- a/src/ds1307/ds1307.hpp +++ b/src/ds1307/ds1307.hpp @@ -28,6 +28,7 @@ #include #include +#include #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; }; } - - diff --git a/src/ecezo/ecezo.cxx b/src/ecezo/ecezo.cxx index 1bbcd815..cb78c114 100644 --- a/src/ecezo/ecezo.cxx +++ b/src/ecezo/ecezo.cxx @@ -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); diff --git a/src/ecezo/ecezo.hpp b/src/ecezo/ecezo.hpp index 2d2e64ff..3923edd9 100644 --- a/src/ecezo/ecezo.hpp +++ b/src/ecezo/ecezo.hpp @@ -30,6 +30,7 @@ #include #include "ecezo.h" +#include 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 diff --git a/src/ehr/ehr.cxx b/src/ehr/ehr.cxx index bdab8a98..39667efe 100644 --- a/src/ehr/ehr.cxx +++ b/src/ehr/ehr.cxx @@ -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(); +} diff --git a/src/ehr/ehr.hpp b/src/ehr/ehr.hpp index e83cded9..f22f5f4c 100644 --- a/src/ehr/ehr.hpp +++ b/src/ehr/ehr.hpp @@ -27,6 +27,7 @@ #include #include #include +#include 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; }; } - - diff --git a/src/emg/emg.hpp b/src/emg/emg.hpp index bc9c3e3d..7582e7ef 100644 --- a/src/emg/emg.hpp +++ b/src/emg/emg.hpp @@ -25,6 +25,7 @@ #include #include +#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; }; } - - diff --git a/src/groveehr/groveehr.cxx b/src/groveehr/groveehr.cxx index 953e5f5a..cea08dbc 100644 --- a/src/groveehr/groveehr.cxx +++ b/src/groveehr/groveehr.cxx @@ -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(); +} diff --git a/src/groveehr/groveehr.hpp b/src/groveehr/groveehr.hpp index 596644de..f4b680f8 100644 --- a/src/groveehr/groveehr.hpp +++ b/src/groveehr/groveehr.hpp @@ -27,6 +27,7 @@ #include #include #include +#include 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; }; } - - diff --git a/src/groveemg/groveemg.hpp b/src/groveemg/groveemg.hpp index e5d4b077..3585d9b1 100644 --- a/src/groveemg/groveemg.hpp +++ b/src/groveemg/groveemg.hpp @@ -25,6 +25,7 @@ #include #include +#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; }; } - - diff --git a/src/grovegsr/grovegsr.cxx b/src/grovegsr/grovegsr.cxx index 17b19c58..64a9a9fc 100644 --- a/src/grovegsr/grovegsr.cxx +++ b/src/grovegsr/grovegsr.cxx @@ -68,3 +68,8 @@ int GroveGSR::value() int val = mraa_aio_read(m_aio); return val; } + +float GroveGSR::getECValue() +{ + return (float) GroveGSR::value(); +} diff --git a/src/grovegsr/grovegsr.hpp b/src/grovegsr/grovegsr.hpp index 4cca0354..d56649dc 100644 --- a/src/grovegsr/grovegsr.hpp +++ b/src/grovegsr/grovegsr.hpp @@ -25,6 +25,7 @@ #include #include +#include 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; }; } - - diff --git a/src/grovelinefinder/grovelinefinder.hpp b/src/grovelinefinder/grovelinefinder.hpp index 442070da..cb00289b 100644 --- a/src/grovelinefinder/grovelinefinder.hpp +++ b/src/grovelinefinder/grovelinefinder.hpp @@ -25,6 +25,7 @@ #include #include +#include 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; }; } - - diff --git a/src/gsr/gsr.cxx b/src/gsr/gsr.cxx index 19d4f3e6..cd9f3817 100644 --- a/src/gsr/gsr.cxx +++ b/src/gsr/gsr.cxx @@ -65,3 +65,8 @@ int GSR::value() int val = mraa_aio_read(m_aio); return val; } + +float GSR::getECValue() +{ + return (float) GSR::value(); +} diff --git a/src/gsr/gsr.hpp b/src/gsr/gsr.hpp index b6d5e43a..8c2e22e7 100644 --- a/src/gsr/gsr.hpp +++ b/src/gsr/gsr.hpp @@ -25,6 +25,7 @@ #include #include +#include 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; }; } - - diff --git a/src/linefinder/linefinder.hpp b/src/linefinder/linefinder.hpp index 4ad4d219..5d66d084 100644 --- a/src/linefinder/linefinder.hpp +++ b/src/linefinder/linefinder.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include 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; }; } - -