From 90524273ec5c61791d80adcd2b769732d2fb76cf Mon Sep 17 00:00:00 2001 From: Serban Waltter Date: Thu, 26 Jul 2018 18:04:31 +0300 Subject: [PATCH] Updated interfaces and sensors Signed-off-by: Serban Waltter Signed-off-by: Mihai Tudor Panu --- .../interfaces/{iRotaryAngle.hpp => iAngle.hpp} | 8 ++++---- include/interfaces/iClock.hpp | 14 +++----------- include/interfaces/iEmg.hpp | 12 ------------ include/interfaces/iGps.hpp | 8 -------- include/interfaces/iPH.hpp | 6 ++---- include/interfaces/iPressure.hpp | 2 +- include/interfaces/iVDiv.hpp | 2 +- src/dfrph/dfrph.cxx | 5 +++++ src/dfrph/dfrph.hpp | 7 +++++++ src/ds1307/ds1307.hpp | 7 +++---- src/grove/groverotary.cxx | 4 ++-- src/grove/groverotary.hpp | 6 +++--- src/hp20x/hp20x.hpp | 2 +- src/ms5803/ms5803.hpp | 4 ++-- src/rotary/rotary.cxx | 4 ++-- src/rotary/rotary.hpp | 6 +++--- src/rotaryencoder/rotaryencoder.cxx | 4 ++-- src/rotaryencoder/rotaryencoder.hpp | 6 +++--- 18 files changed, 44 insertions(+), 63 deletions(-) rename include/interfaces/{iRotaryAngle.hpp => iAngle.hpp} (92%) diff --git a/include/interfaces/iRotaryAngle.hpp b/include/interfaces/iAngle.hpp similarity index 92% rename from include/interfaces/iRotaryAngle.hpp rename to include/interfaces/iAngle.hpp index c1055d87..af013ecc 100644 --- a/include/interfaces/iRotaryAngle.hpp +++ b/include/interfaces/iAngle.hpp @@ -29,16 +29,16 @@ namespace upm /** * @brief Interface for Rotary Angle sensors */ - class iRotaryAngle + class iAngle { public: - virtual ~iRotaryAngle() {} + virtual ~iAngle() {} /** * Get rotation value from sensor data. * - * @return rotation value. + * @return rotation value in degrees. */ - virtual float getValue() = 0; + virtual float getAngle() = 0; }; } diff --git a/include/interfaces/iClock.hpp b/include/interfaces/iClock.hpp index c1eb64a8..8f2a251b 100644 --- a/include/interfaces/iClock.hpp +++ b/include/interfaces/iClock.hpp @@ -35,18 +35,10 @@ namespace upm virtual ~iClock() {} /** - * Loads all the time values + * Returns the time since epoch in seconds * - * @return True if time data loaded successfully + * @return time since epoch in seconds */ - 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; + virtual unsigned long getTime() = 0; }; } diff --git a/include/interfaces/iEmg.hpp b/include/interfaces/iEmg.hpp index 3b2895fb..d372c31d 100644 --- a/include/interfaces/iEmg.hpp +++ b/include/interfaces/iEmg.hpp @@ -34,18 +34,6 @@ namespace upm 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; - /** * Read scaled/offset voltage from the sensor * diff --git a/include/interfaces/iGps.hpp b/include/interfaces/iGps.hpp index d9a34a47..0f629007 100644 --- a/include/interfaces/iGps.hpp +++ b/include/interfaces/iGps.hpp @@ -40,13 +40,5 @@ namespace upm * @param enable true to enable the device, false otherwise. */ virtual void enable(bool enable) = 0; - - /** - * Set the baudrate of the device. - * - * @param baudrate The baud rate to set for the device. - */ - virtual void setBaudrate(unsigned int baudrate) = 0; - }; } diff --git a/include/interfaces/iPH.hpp b/include/interfaces/iPH.hpp index 436c5063..900e4325 100644 --- a/include/interfaces/iPH.hpp +++ b/include/interfaces/iPH.hpp @@ -35,13 +35,11 @@ namespace upm virtual ~iPH() {} /** - * Take a number of samples and return the detected pH value. The - * default number of samples is 15. + * Returns the detected pH value. * - * @param samples The number of samples to average over, default 15 * @return The pH value detected */ - virtual float pH(unsigned int samples = 15) = 0; + virtual float getPH() = 0; }; } diff --git a/include/interfaces/iPressure.hpp b/include/interfaces/iPressure.hpp index acf08eba..deb059bb 100644 --- a/include/interfaces/iPressure.hpp +++ b/include/interfaces/iPressure.hpp @@ -40,7 +40,7 @@ namespace upm /** * Measures applied pressure * - * @return gets pressure value + * @return gets pressure value in Pa */ virtual float getPressure() = 0; diff --git a/include/interfaces/iVDiv.hpp b/include/interfaces/iVDiv.hpp index e46acb82..4625e9c6 100644 --- a/include/interfaces/iVDiv.hpp +++ b/include/interfaces/iVDiv.hpp @@ -37,7 +37,7 @@ namespace upm /** * Gets the conversion value from the sensor * - * @return ADC conversion value + * @return ADC conversion value in volts */ virtual unsigned int getValue() = 0; diff --git a/src/dfrph/dfrph.cxx b/src/dfrph/dfrph.cxx index 88cd1126..1a1f15ee 100644 --- a/src/dfrph/dfrph.cxx +++ b/src/dfrph/dfrph.cxx @@ -74,3 +74,8 @@ float DFRPH::pH(unsigned int samples) return ph_avg/samples; } + +float DFRPH::getPH() +{ + return pH(10); +} diff --git a/src/dfrph/dfrph.hpp b/src/dfrph/dfrph.hpp index 8bde94ac..ff0a0e4c 100644 --- a/src/dfrph/dfrph.hpp +++ b/src/dfrph/dfrph.hpp @@ -132,6 +132,13 @@ namespace upm { */ virtual float pH(unsigned int samples = 15); + /** + * Returns the detected pH value. + * + * @return The pH value detected + */ + virtual float getPH(); + private: /** * Don't allow copies of this class diff --git a/src/ds1307/ds1307.hpp b/src/ds1307/ds1307.hpp index f1bf032d..5b7a9b5b 100644 --- a/src/ds1307/ds1307.hpp +++ b/src/ds1307/ds1307.hpp @@ -28,7 +28,6 @@ #include #include -#include #define DS1307_I2C_BUS 0 #define DS1307_I2C_ADDR 0x68 @@ -70,7 +69,7 @@ namespace upm { * @image html ds1307.jpg * @snippet ds1307.cxx Interesting */ - class DS1307 : virtual public iClock { + class DS1307 { public: /** * DS1307 constructor @@ -84,7 +83,7 @@ namespace upm { * * @return True if time data loaded successfully */ - virtual bool loadTime(); + bool loadTime(); /** * Sets the time. You should call loadTime() beforehand to @@ -92,7 +91,7 @@ namespace upm { * * @return True if time is set successfully */ - virtual bool setTime(); + bool setTime(); /** * Enables an oscillator on the clock. diff --git a/src/grove/groverotary.cxx b/src/grove/groverotary.cxx index ab57e870..3c280e46 100644 --- a/src/grove/groverotary.cxx +++ b/src/grove/groverotary.cxx @@ -78,7 +78,7 @@ float GroveRotary::rel_rad() return GroveRotary::rel_deg() * M_PI / 180.0; } -float GroveRotary::getValue() +float GroveRotary::getAngle() { - return GroveRotary::abs_value(); + return GroveRotary::abs_deg(); } diff --git a/src/grove/groverotary.hpp b/src/grove/groverotary.hpp index 34d07bde..e9326750 100644 --- a/src/grove/groverotary.hpp +++ b/src/grove/groverotary.hpp @@ -29,7 +29,7 @@ #include #include #include "grovebase.hpp" -#include +#include namespace upm { @@ -54,7 +54,7 @@ namespace upm { * @image html rotaryencoder.jpg * @snippet grove-groverotary.cxx Interesting */ -class GroveRotary: public Grove, virtual public iRotaryAngle { +class GroveRotary: public Grove, virtual public iAngle { public: /** * Grove rotary angle sensor constructor @@ -108,7 +108,7 @@ class GroveRotary: public Grove, virtual public iRotaryAngle { * * @return rotation value. */ - virtual float getValue(); + virtual float getAngle(); private: mraa_aio_context m_aio; diff --git a/src/hp20x/hp20x.hpp b/src/hp20x/hp20x.hpp index e1c9be39..d725e794 100644 --- a/src/hp20x/hp20x.hpp +++ b/src/hp20x/hp20x.hpp @@ -275,7 +275,7 @@ namespace upm { virtual float getTemperature(); /** - * Returns the pressure in millibars + * Returns the pressure in pascal * * @return Pressure */ diff --git a/src/ms5803/ms5803.hpp b/src/ms5803/ms5803.hpp index 11f9ed90..d6ec20ac 100644 --- a/src/ms5803/ms5803.hpp +++ b/src/ms5803/ms5803.hpp @@ -137,9 +137,9 @@ namespace upm { /** * Return the latest measured pressure. update() must have * been called prior to calling this function. The returned - * value is in millibars. + * value is in pascal. * - * @return Pressure in mbar + * @return Pressure in Pa */ virtual float getPressure(); diff --git a/src/rotary/rotary.cxx b/src/rotary/rotary.cxx index fe7e1f73..afcfa8b6 100644 --- a/src/rotary/rotary.cxx +++ b/src/rotary/rotary.cxx @@ -77,7 +77,7 @@ float Rotary::rel_rad() return Rotary::rel_deg() * M_PI / 180.0; } - float Rotary::getValue() + float Rotary::getAngle() { - return Rotary::abs_value(); + return Rotary::abs_deg(); } diff --git a/src/rotary/rotary.hpp b/src/rotary/rotary.hpp index 25158ec5..6cd44235 100644 --- a/src/rotary/rotary.hpp +++ b/src/rotary/rotary.hpp @@ -30,7 +30,7 @@ #include #include "rotary.hpp" -#include +#include namespace upm { @@ -60,7 +60,7 @@ namespace upm { * @image html rotary.jpg * @snippet rotary.cxx Interesting */ -class Rotary : virtual public iRotaryAngle { +class Rotary : virtual public iAngle { public: /** * Rotary angle sensor constructor @@ -115,7 +115,7 @@ class Rotary : virtual public iRotaryAngle { * * @return rotation value. */ - virtual float getValue(); + virtual float getAngle(); std::string name(){ return "Rotary Angle Sensor";} private: diff --git a/src/rotaryencoder/rotaryencoder.cxx b/src/rotaryencoder/rotaryencoder.cxx index 13544d79..b536d728 100644 --- a/src/rotaryencoder/rotaryencoder.cxx +++ b/src/rotaryencoder/rotaryencoder.cxx @@ -53,6 +53,6 @@ int RotaryEncoder::position() return rotaryencoder_get_position(m_rotaryencoder); } -float RotaryEncoder::getValue() { - return (float) RotaryEncoder::position(); +float RotaryEncoder::getAngle() { + return (float) RotaryEncoder::position() / 20.0 * 360; } diff --git a/src/rotaryencoder/rotaryencoder.hpp b/src/rotaryencoder/rotaryencoder.hpp index 926edda9..4c6fecd4 100644 --- a/src/rotaryencoder/rotaryencoder.hpp +++ b/src/rotaryencoder/rotaryencoder.hpp @@ -24,7 +24,7 @@ #pragma once #include "rotaryencoder.h" -#include +#include namespace upm { @@ -61,7 +61,7 @@ namespace upm { * @snippet rotaryencoder.cxx Interesting */ - class RotaryEncoder : virtual public iRotaryAngle { + class RotaryEncoder : virtual public iAngle { public: /** * RotaryEncoder constructor @@ -93,7 +93,7 @@ namespace upm { * * @return rotation value. */ - virtual float getValue(); + virtual float getAngle(); private: /* Disable implicit copy and assignment operators */