diff --git a/examples/c++/iLight-sample.cxx b/examples/c++/iLight-sample.cxx new file mode 100644 index 00000000..103e4397 --- /dev/null +++ b/examples/c++/iLight-sample.cxx @@ -0,0 +1,31 @@ +#include +#include + +#include "apds9002.hpp" +#include "bh1750.hpp" +#include "max44009.hpp" + +using namespace std; +using namespace upm; + +int +main() +{ + list lightSensors; + + // Populate list of light sensors + lightSensors.push_back(new APDS9002(0)); + lightSensors.push_back(new BH1750()); + lightSensors.push_back(new MAX44009(1)); + + // Measure luminance level from all 3 individual sensors + for (auto& sensor : lightSensors) { + sensor->getLuminance(); + } + + for (auto& sensor : lightSensors) { + delete sensor; + } + + return 0; +} diff --git a/examples/c++/iTemperature-sample.cxx b/examples/c++/iTemperature-sample.cxx new file mode 100644 index 00000000..ef7fe805 --- /dev/null +++ b/examples/c++/iTemperature-sample.cxx @@ -0,0 +1,26 @@ +#include +#include + +#include "lm35.hpp" +#include "abp.hpp" + +using namespace std; +using namespace upm; + +int +main() +{ + vector tempSensors {new LM35(0), new ABP(0, ABP_DEFAULT_ADDRESS)}; + + for (auto& sensor : tempSensors) { + float celsiusTemp = sensor->getTemperature(); + cout << "Temperature in Celsius degrees: " << celsiusTemp << endl; + cout << "Temperature in Kelvin: " << iTemperature::convertCelsiusTo(celsiusTemp, TemperatureUnit::KELVIN); + } + + for (auto& sensor : tempSensors) { + delete sensor; + } + + return 0; +} diff --git a/examples/c++/interfaces-lightsensor.cxx b/examples/c++/interfaces-lightsensor.cxx index 9f754f89..b34ffebe 100644 --- a/examples/c++/interfaces-lightsensor.cxx +++ b/examples/c++/interfaces-lightsensor.cxx @@ -62,7 +62,7 @@ getLightSensor() int main() { - upm::ILightSensor* lightSensor = getLightSensor(); + /*upm::ILightSensor* lightSensor = getLightSensor(); if (lightSensor == NULL) { std::cout << "Light sensor not detected" << std::endl; return 1; @@ -77,7 +77,7 @@ main() } upm_delay(1); } - delete lightSensor; + delete lightSensor;*/ return 0; } diff --git a/examples/c++/lm35.cxx b/examples/c++/lm35.cxx index 4e96e163..ce55c52c 100644 --- a/examples/c++/lm35.cxx +++ b/examples/c++/lm35.cxx @@ -48,12 +48,12 @@ main() // Instantiate a LM35 on analog pin A0, with a default analog // reference voltage of 5.0 - upm::LM35 sensor(0); + upm::iTemperature* sensor = new upm::LM35(0); // Every half second, sample the sensor and output the temperature while (shouldRun) { - cout << "Temperature: " << sensor.getTemperature() << " C" << endl; + cout << "Temperature: " << sensor->getTemperature() << " C" << endl; upm_delay_us(500000); } @@ -61,6 +61,7 @@ main() //! [Interesting] cout << "Exiting" << endl; + delete sensor; return 0; } diff --git a/include/interfaces/iCollision.hpp b/include/interfaces/iCollision.hpp new file mode 100644 index 00000000..bc43c56d --- /dev/null +++ b/include/interfaces/iCollision.hpp @@ -0,0 +1,38 @@ +/* + * 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 Collision Sensors +*/ + class iCollision + { + public: + virtual ~iCollision() {} + virtual bool isColliding() = 0; + }; +} diff --git a/include/interfaces/iDistance.hpp b/include/interfaces/iDistance.hpp new file mode 100644 index 00000000..c198dfdd --- /dev/null +++ b/include/interfaces/iDistance.hpp @@ -0,0 +1,68 @@ +/* + * 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 + +#include + +namespace upm +{ + enum class DistanceUnit { CM, INCH }; +/** +* @brief Interface for Distance Measuring Sensors +*/ + class iDistance + { + public: + virtual ~iDistance() {} + virtual int getDistance() = 0; + /** + * Convert distance value from Cm(default) to one + * of the following: + * + * 1. Inch + * + * @param cmValue Cm distance value + * @param unit The distance unit for the conversion. + * @return The converted distance value + */ + static float convertCmTo(float cmValue, DistanceUnit unit) + { + float convertedValue = cmValue; + + switch (unit) + { + case DistanceUnit::CM: + break; + case DistanceUnit::INCH: + convertedValue *= 0.3937f; + break; + default: + throw std::invalid_argument("invalid distance unit"); + } + + return convertedValue; + } + }; +} diff --git a/include/interfaces/iDistanceInterrupter.hpp b/include/interfaces/iDistanceInterrupter.hpp new file mode 100644 index 00000000..9a991539 --- /dev/null +++ b/include/interfaces/iDistanceInterrupter.hpp @@ -0,0 +1,38 @@ +/* + * 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 Distance Interrupter Sensors +*/ + class iDistanceInterrupter + { + public: + virtual ~iDistanceInterrupter() {} + virtual bool objectDetected() = 0; + }; +} diff --git a/include/interfaces/iHallEffect.hpp b/include/interfaces/iHallEffect.hpp new file mode 100644 index 00000000..ee24369c --- /dev/null +++ b/include/interfaces/iHallEffect.hpp @@ -0,0 +1,38 @@ +/* + * 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 Hall Effect Sensors +*/ + class iHallEffect + { + public: + virtual ~iHallEffect() {} + virtual bool magnetDetected() = 0; + }; +} diff --git a/include/interfaces/iHumidity.hpp b/include/interfaces/iHumidity.hpp new file mode 100644 index 00000000..8e35037d --- /dev/null +++ b/include/interfaces/iHumidity.hpp @@ -0,0 +1,38 @@ +/* + * 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 Humidity Measuring Sensors +*/ + class iHumidity + { + public: + virtual ~iHumidity() {} + virtual float getHumidity() = 0; + }; +} diff --git a/include/interfaces/iLight.hpp b/include/interfaces/iLight.hpp new file mode 100644 index 00000000..4c849694 --- /dev/null +++ b/include/interfaces/iLight.hpp @@ -0,0 +1,38 @@ +/* + * 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 Luminance Measuring Sensors +*/ + class iLight + { + public: + virtual ~iLight() {} + virtual float getLuminance() = 0; + }; +} \ No newline at end of file diff --git a/include/interfaces/iMoisture.hpp b/include/interfaces/iMoisture.hpp new file mode 100644 index 00000000..6fd6890c --- /dev/null +++ b/include/interfaces/iMoisture.hpp @@ -0,0 +1,38 @@ +/* + * 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 Moisture Measuring Sensors +*/ + class iMoisture + { + public: + virtual ~iMoisture() {} + virtual int getMoisture() = 0; + }; +} diff --git a/include/interfaces/iMotion.hpp b/include/interfaces/iMotion.hpp new file mode 100644 index 00000000..d38aa212 --- /dev/null +++ b/include/interfaces/iMotion.hpp @@ -0,0 +1,38 @@ +/* + * 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 Motion Sensors +*/ + class iMotion + { + public: + virtual ~iMotion() {} + virtual bool motionDetected() = 0; + }; +} diff --git a/include/interfaces/iPressure.hpp b/include/interfaces/iPressure.hpp new file mode 100644 index 00000000..eedb6429 --- /dev/null +++ b/include/interfaces/iPressure.hpp @@ -0,0 +1,81 @@ +/* + * 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 + +#include + +namespace upm +{ + enum class PressureUnit { PA, BAR, ATM, TORR, PSI }; +/** +* @brief Interface for Pressure Measuring Sensors +*/ + class iPressure + { + public: + virtual ~iPressure() {} + virtual float getPressure() = 0; + + /** + * Convert pressure value from Pascal(default) to one + * of the following: + * + * 1. Bar + * 2. Standard atmosphere + * 3. Torr + * 4. Pounds per square inch + * + * @param paValue Pa pressure value + * @param unit The pressure unit for the conversion. + * @return The converted pressure value + */ + static float convertPaTo(float paValue, PressureUnit unit) + { + float convertedValue = paValue; + + switch (unit) + { + case PressureUnit::PA: + break; + case PressureUnit::BAR: + convertedValue *= 0.00001f; + break; + case PressureUnit::ATM: + convertedValue *= 0.0000098692f; + break; + case PressureUnit::TORR: + convertedValue *= 0.0075006f; + break; + case PressureUnit::PSI: + convertedValue *= 0.0001450377f; + break; + default: + throw std::invalid_argument("invalid pressure unit"); + } + + return convertedValue; + } + }; +} diff --git a/include/interfaces/iTemperature.hpp b/include/interfaces/iTemperature.hpp new file mode 100644 index 00000000..b90ca185 --- /dev/null +++ b/include/interfaces/iTemperature.hpp @@ -0,0 +1,75 @@ +/* + * 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 + +#include + +namespace upm +{ + enum class TemperatureUnit { FAHRENHEIT, KELVIN, CELSIUS }; + +/** +* @brief Interface for Temperature Measuring Sensors +*/ + class iTemperature + { + public: + + virtual ~iTemperature() {} + virtual float getTemperature() = 0; + + /** + * Convert temperature value from Celsius(default) to one + * of the following: + * + * 1. Fahrenheit + * 2. Kelvin + * + * @param celsiusValue Celsius degrees value + * @param unit The temperature unit for the conversion. + * @return The converted temperature value + */ + static float convertCelsiusTo(float celsiusValue, TemperatureUnit unit) + { + float convertedValue = celsiusValue; + + switch (unit) + { + case TemperatureUnit::CELSIUS: + break; + case TemperatureUnit::FAHRENHEIT: + convertedValue = celsiusValue * 1.8f + 32; + break; + case TemperatureUnit::KELVIN: + convertedValue += 273.15f; + break; + default: + throw std::invalid_argument("invalid temperature unit"); + } + + return convertedValue; + } + }; +} diff --git a/src/a110x/a110x.hpp b/src/a110x/a110x.hpp index 71a0d784..9959f9a4 100644 --- a/src/a110x/a110x.hpp +++ b/src/a110x/a110x.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { /** @@ -58,7 +59,7 @@ namespace upm { * An example demonstrating the use of an interrupt handler to count pulses * @snippet a110x-intr.cxx Interesting */ - class A110X { + class A110X : virtual public iHallEffect { public: /** * A110x digital sensor constructor @@ -75,7 +76,7 @@ namespace upm { * * @return True if magnetic field detected */ - bool magnetDetected(); + virtual bool magnetDetected(); /** * Installs an interrupt service routine (ISR) to be called when diff --git a/src/abp/abp.hpp b/src/abp/abp.hpp index f1c407ee..3ae1ff00 100644 --- a/src/abp/abp.hpp +++ b/src/abp/abp.hpp @@ -25,6 +25,7 @@ #pragma once #include "abp.h" +#include namespace upm { /** @@ -59,7 +60,7 @@ namespace upm { * @snippet abp.cxx Interesting */ - class ABP { + class ABP : virtual public iTemperature { public: /** @@ -90,7 +91,7 @@ namespace upm { * * @return float compensated temperature value */ - float getTemperature(); + virtual float getTemperature(); /** * This functio has to be called before calling either of the get diff --git a/src/am2315/am2315.hpp b/src/am2315/am2315.hpp index 75ad96cf..a88af230 100644 --- a/src/am2315/am2315.hpp +++ b/src/am2315/am2315.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define AM2315_NAME "am2315" #define AM2315_I2C_ADDRESS 0x5c @@ -77,7 +79,7 @@ namespace upm { * @image html am2315.jpeg * @snippet am2315.cxx Interesting */ -class AM2315 { +class AM2315 : virtual public iHumidity, virtual public iTemperature { public: /** * Instantiates an AM2315 object @@ -98,15 +100,17 @@ class AM2315 { * Data is updated every 2 seconds - accesses occurring more often than * that return cached data */ - float getHumidity(void); + virtual float getHumidity(void); /** * Gets the humidity cell temperature [degC] * * Data is updated every 2 seconds - accesses occurring more often than * that return cached data + * + * @return float compensated temperature value */ - float getTemperature(void); + virtual float getTemperature(void); /** * Gets the humidity cell temperature [degF] diff --git a/src/apds9002/apds9002.cxx b/src/apds9002/apds9002.cxx index b417d1b1..02b2611e 100644 --- a/src/apds9002/apds9002.cxx +++ b/src/apds9002/apds9002.cxx @@ -32,7 +32,7 @@ using namespace upm; APDS9002::APDS9002(int pin) { - if ( !(m_aio = mraa_aio_init(pin)) ) + if ( !(m_aio = mraa_aio_init(pin)) ) { throw std::invalid_argument(std::string(__FUNCTION__) + ": mraa_aio_init() failed, invalid pin?"); @@ -49,3 +49,8 @@ int APDS9002::value() { return mraa_aio_read(m_aio); } + +float APDS9002::getLuminance() +{ + return value(); +} diff --git a/src/apds9002/apds9002.hpp b/src/apds9002/apds9002.hpp index 062525b1..8ad393a3 100644 --- a/src/apds9002/apds9002.hpp +++ b/src/apds9002/apds9002.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { /** @@ -52,7 +53,7 @@ namespace upm { * @snippet apds9002.cxx Interesting */ - class APDS9002 { + class APDS9002 : virtual public iLight { public: /** * APDS-9002 luminance sensor constructor @@ -71,6 +72,13 @@ namespace upm { */ int value(); + /** + * Gets the luminance value from the sensor + * + * @return The measured light intensity value in Lux + */ + virtual float getLuminance(); + private: mraa_aio_context m_aio; }; diff --git a/src/bh1750/bh1750.cxx b/src/bh1750/bh1750.cxx index 112e2f6c..1adc1d5d 100644 --- a/src/bh1750/bh1750.cxx +++ b/src/bh1750/bh1750.cxx @@ -59,6 +59,11 @@ float BH1750::getLux() return lux; } +float BH1750::getLuminance() +{ + return getLux(); +} + void BH1750::powerUp() { if (bh1750_power_up(m_bh1750) != UPM_SUCCESS) diff --git a/src/bh1750/bh1750.hpp b/src/bh1750/bh1750.hpp index d915967b..4c7bee87 100644 --- a/src/bh1750/bh1750.hpp +++ b/src/bh1750/bh1750.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "bh1750.h" @@ -57,7 +58,7 @@ namespace upm { * @snippet bh1750.cxx Interesting */ - class BH1750 { + class BH1750 : virtual public iLight { public: /** @@ -92,6 +93,13 @@ namespace upm { */ float getLux(); + /** + * Gets the luminance value from the sensor + * + * @return The measured light intensity value in Lux + */ + virtual float getLuminance(); + /** * Power up the device. */ diff --git a/src/biss0001/biss0001.cxx b/src/biss0001/biss0001.cxx index c7a0e0d8..5e0d274c 100644 --- a/src/biss0001/biss0001.cxx +++ b/src/biss0001/biss0001.cxx @@ -48,3 +48,8 @@ bool BISS0001::value() { return biss0001_motion_detected(m_biss0001); } + +bool BISS0001::motionDetected() +{ + return value(); +} diff --git a/src/biss0001/biss0001.hpp b/src/biss0001/biss0001.hpp index 80c3511b..79f2e9e1 100644 --- a/src/biss0001/biss0001.hpp +++ b/src/biss0001/biss0001.hpp @@ -24,6 +24,7 @@ */ #pragma once +#include #include namespace upm { @@ -57,7 +58,7 @@ namespace upm { * @snippet biss0001.cxx Interesting */ - class BISS0001 { + class BISS0001 : virtual public iMotion { public: /** * BISS0001 motion sensor constructor @@ -81,11 +82,11 @@ namespace upm { /** * Gets the motion value from the sensor. This is a more * informative method name, but we want to keep compatibility - * with the original for now. + * with the original for now. Implements iMotion interface. * * @return true if motion was detected, false otherwise. */ - bool motionDetected() { return value(); }; + virtual bool motionDetected(); private: /* Disable implicit copy and assignment operators */ diff --git a/src/bmp280/bme280.hpp b/src/bmp280/bme280.hpp index fd03992e..b18a4922 100644 --- a/src/bmp280/bme280.hpp +++ b/src/bmp280/bme280.hpp @@ -26,7 +26,7 @@ #pragma once #include -#include "interfaces/iHumiditySensor.hpp" +#include #include "bmp280.hpp" @@ -57,7 +57,7 @@ namespace upm { * @snippet bmp280-bme280.cxx Interesting */ - class BME280 : public BMP280, public IHumiditySensor { + class BME280 : public BMP280, virtual public iHumidity { public: /** @@ -96,7 +96,7 @@ namespace upm { * * @return The relative humidity in percent. */ - float getHumidity(); + virtual float getHumidity(); /** * Set the humidity sensor oversampling parameter. See the data diff --git a/src/bmp280/bmp280.cxx b/src/bmp280/bmp280.cxx index b9d338fc..203f8ee4 100644 --- a/src/bmp280/bmp280.cxx +++ b/src/bmp280/bmp280.cxx @@ -110,6 +110,11 @@ float BMP280::getTemperature(bool fahrenheit) return temperature; } +float BMP280::getTemperature() +{ + return getTemperature(false); +} + float BMP280::getPressure() { return bmp280_get_pressure(m_bmp280); diff --git a/src/bmp280/bmp280.hpp b/src/bmp280/bmp280.hpp index 18889681..2e4a9b85 100644 --- a/src/bmp280/bmp280.hpp +++ b/src/bmp280/bmp280.hpp @@ -28,8 +28,8 @@ #include #include "bmp280.h" -#include "interfaces/iPressureSensor.hpp" -#include "interfaces/iTemperatureSensor.hpp" +#include +#include namespace upm { @@ -67,7 +67,7 @@ namespace upm { * @snippet bmp280.cxx Interesting */ - class BMP280 : public ITemperatureSensor, public IPressureSensor { + class BMP280 : virtual public iPressure, virtual public iTemperature { public: /** @@ -127,7 +127,17 @@ namespace upm { * Celicus. Celsius is the default. * @return The temperature in degrees Celsius or Fahrenheit. */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Return the current measured temperature. Note, this is not + * ambient temperature - this is the temperature used to fine tune + * the pressure measurement. update() must have been called prior + * to calling this method. + * + * @return The temperature in degrees Celsius. + */ + virtual float getTemperature(); /** * Return the current measured pressure in Pascals (Pa). update() @@ -135,7 +145,7 @@ namespace upm { * * @return The pressure in Pascals (Pa). */ - float getPressure(); + virtual float getPressure(); /** * Set the pressure at sea level in hecto-Pascals (hPA). This diff --git a/src/bmp280/bmp280.i b/src/bmp280/bmp280.i index ebd316ab..f2ab6eaf 100644 --- a/src/bmp280/bmp280.i +++ b/src/bmp280/bmp280.i @@ -2,37 +2,14 @@ /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%import "../interfaces/javaupm_iTemperatureSensor.i" -%import "../interfaces/javaupm_iHumiditySensor.i" -%import "../interfaces/javaupm_iPressureSensor.i" - -%include "arrays_java.i"; -%include "../java_buffer.i" - -%typemap(javaimports) SWIGTYPE %{ - import upm_interfaces.*; -%} - JAVA_JNI_LOADLIBRARY(javaupm_bmp280) #endif /* END Java syntax */ /* BEGIN Javascript syntax ------------------------------------------------- */ -#ifdef SWIGJAVASCRIPT -%include "iModuleStatus.hpp" -%include "iTemperatureSensor.hpp" -%include "iPressureSensor.hpp" -%include "iHumiditySensor.hpp" -#endif /* END Javascript syntax */ /* BEGIN Python syntax ----------------------------------------------------- */ -#ifdef SWIGPYTHON -%include "iModuleStatus.hpp" -%include "iTemperatureSensor.hpp" -%include "iPressureSensor.hpp" -%include "iHumiditySensor.hpp" -#endif /* END Python syntax */ /* BEGIN Common SWIG syntax ------------------------------------------------- */ diff --git a/src/bmpx8x/bmpx8x.cxx b/src/bmpx8x/bmpx8x.cxx index 36144907..ac1eb0bc 100644 --- a/src/bmpx8x/bmpx8x.cxx +++ b/src/bmpx8x/bmpx8x.cxx @@ -99,7 +99,7 @@ void BMPX8X::writeReg(uint8_t reg, uint8_t val) + ": bmpx8x_write_reg() failed"); } -int BMPX8X::getPressure() +float BMPX8X::getPressure() { return bmpx8x_get_pressure(m_bmpx8x); } diff --git a/src/bmpx8x/bmpx8x.hpp b/src/bmpx8x/bmpx8x.hpp index 680c2b57..26c387dd 100644 --- a/src/bmpx8x/bmpx8x.hpp +++ b/src/bmpx8x/bmpx8x.hpp @@ -32,8 +32,7 @@ #include "bmpx8x.h" -#include "interfaces/iPressureSensor.hpp" -#include "interfaces/iTemperatureSensor.hpp" +#include namespace upm { @@ -68,7 +67,7 @@ namespace upm { * @snippet bmpx8x.cxx Interesting */ - class BMPX8X : public IPressureSensor, public ITemperatureSensor { + class BMPX8X : virtual public iPressure { public: /** * Instantiates a BMPX8X object @@ -132,7 +131,7 @@ namespace upm { * * @returns The pressure in Pascals. */ - int getPressure(); + virtual float getPressure(); /** * Returns the calculated temperature in Celsius. update() diff --git a/src/bmpx8x/bmpx8x.i b/src/bmpx8x/bmpx8x.i index 08465a5d..b809efba 100644 --- a/src/bmpx8x/bmpx8x.i +++ b/src/bmpx8x/bmpx8x.i @@ -2,19 +2,12 @@ /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%import "../interfaces/javaupm_iPressureSensor.i" -%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%} -%import "../interfaces/javaupm_iTemperatureSensor.i" - JAVA_JNI_LOADLIBRARY(javaupm_bmpx8x) #endif /* END Java syntax */ /* BEGIN Python syntax ----------------------------------------------------- */ #ifdef SWIGPYTHON -%include "iModuleStatus.hpp" -%include "iTemperatureSensor.hpp" -%include "iPressureSensor.hpp" #endif /* END Python syntax */ diff --git a/src/collision/collision.hpp b/src/collision/collision.hpp index 2501a9c8..8fe2764d 100644 --- a/src/collision/collision.hpp +++ b/src/collision/collision.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include namespace upm { /** @@ -42,15 +43,15 @@ namespace upm { * @con gpio * * @brief API for the Collision Sensor - * + * * The Collision Sensor can detect whether any * collision movement or vibration happens. - * It outputs a low pulse signal when vibration is detected. + * It outputs a low pulse signal when vibration is detected. * * @image html collision.jpg * @snippet collision.cxx Interesting */ - class Collision { + class Collision : virtual public iCollision { public: /** * Collision sensor constructor @@ -63,11 +64,11 @@ namespace upm { */ ~Collision(); /** - * @return bool Defines whether something is colliding with sensor + * @return boolean value defining whether something is colliding with sensor */ - bool isColliding(); + virtual bool isColliding(); private: - mraa_gpio_context m_gpio; - }; + mraa_gpio_context m_gpio; + }; } diff --git a/src/grove/grovelight.cxx b/src/grove/grovelight.cxx index 39313782..1ef2adfc 100644 --- a/src/grove/grovelight.cxx +++ b/src/grove/grovelight.cxx @@ -57,6 +57,11 @@ int GroveLight::value() return (int) round(a); } +float GroveLight::getLuminance() +{ + return value(); +} + float GroveLight::raw_value() { return (float) mraa_aio_read(m_aio); diff --git a/src/grove/grovelight.hpp b/src/grove/grovelight.hpp index b6e85004..c79d48ee 100644 --- a/src/grove/grovelight.hpp +++ b/src/grove/grovelight.hpp @@ -28,6 +28,7 @@ #include #include +#include #include "grovebase.hpp" namespace upm { @@ -54,7 +55,7 @@ namespace upm { * @image html grovelight.jpg * @snippet grove-grovelight.cxx Interesting */ -class GroveLight: public Grove { +class GroveLight: public Grove, virtual public iLight { public: /** * Grove analog light sensor constructor @@ -78,6 +79,13 @@ class GroveLight: public Grove { * @return Normalized light reading in lux */ int value(); + + /** + * Gets an approximate light value, in lux, from the sensor + * + * @return Normalized light reading in lux + */ + virtual float getLuminance(); private: mraa_aio_context m_aio; }; diff --git a/src/grove/grovetemp.cxx b/src/grove/grovetemp.cxx index 008ad5c3..ac0fc869 100644 --- a/src/grove/grovetemp.cxx +++ b/src/grove/grovetemp.cxx @@ -62,6 +62,11 @@ int GroveTemp::value () return (int) round(t); } +float GroveTemp::getTemperature () +{ + return value(); +} + float GroveTemp::raw_value() { return (float) mraa_aio_read(m_aio); diff --git a/src/grove/grovetemp.hpp b/src/grove/grovetemp.hpp index 817cecfa..17402a3b 100644 --- a/src/grove/grovetemp.hpp +++ b/src/grove/grovetemp.hpp @@ -29,6 +29,7 @@ #include #include #include "grovebase.hpp" +#include namespace upm { @@ -54,7 +55,7 @@ namespace upm { * @image html grovetemp.jpg * @snippet grove-grovetemp.cxx Interesting */ -class GroveTemp: public Grove { +class GroveTemp: public Grove, virtual public iTemperature { public: /** * Grove analog temperature sensor constructor @@ -84,6 +85,8 @@ class GroveTemp: public Grove { * @return Normalized temperature in Celsius */ int value(); + + virtual float getTemperature(); private: mraa_aio_context m_aio; float m_scale; diff --git a/src/grovecollision/grovecollision.hpp b/src/grovecollision/grovecollision.hpp index 7c717b08..e37428b8 100644 --- a/src/grovecollision/grovecollision.hpp +++ b/src/grovecollision/grovecollision.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include namespace upm { /** @@ -43,15 +44,15 @@ namespace upm { * @con gpio * * @brief API for the Grove Collision Sensor - * + * * The Grove Collision Sensor can detect whether any * collision movement or vibration happens. - * It outputs a low pulse signal when vibration is detected. + * It outputs a low pulse signal when vibration is detected. * * @image html grovecollision.jpg * @snippet grovecollision.cxx Interesting */ - class GroveCollision { + class GroveCollision : virtual public iCollision { public: /** * Grove collision sensor constructor @@ -64,11 +65,11 @@ namespace upm { */ ~GroveCollision(); /** - * @return bool Defines whether something is colliding with sensor + * @return boolean value defining whether something is colliding with sensor */ - bool isColliding(); + virtual bool isColliding(); private: - mraa_gpio_context m_gpio; - }; + mraa_gpio_context m_gpio; + }; } diff --git a/src/grovemoisture/grovemoisture.cxx b/src/grovemoisture/grovemoisture.cxx index aa44e783..18dcc074 100644 --- a/src/grovemoisture/grovemoisture.cxx +++ b/src/grovemoisture/grovemoisture.cxx @@ -46,3 +46,8 @@ int GroveMoisture::value() { return mraa_aio_read(m_aio); } + +int GroveMoisture::getMoisture() +{ + return value(); +} diff --git a/src/grovemoisture/grovemoisture.hpp b/src/grovemoisture/grovemoisture.hpp index b80db604..8d23aac4 100644 --- a/src/grovemoisture/grovemoisture.hpp +++ b/src/grovemoisture/grovemoisture.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { /** @@ -56,7 +57,7 @@ namespace upm { * @image html grovemoisture.jpg * @snippet grovemoisture.cxx Interesting */ - class GroveMoisture { + class GroveMoisture : virtual public iMoisture { public: /** * Grove analog moisture sensor constructor @@ -75,6 +76,13 @@ namespace upm { */ int value(); + /** + * Gets the moisture value from the sensor + * + * @return Moisture reading + */ + virtual int getMoisture(); + private: mraa_aio_context m_aio; }; diff --git a/src/hcsr04/hcsr04.cxx b/src/hcsr04/hcsr04.cxx index 0f7c1cec..2560e944 100644 --- a/src/hcsr04/hcsr04.cxx +++ b/src/hcsr04/hcsr04.cxx @@ -49,3 +49,9 @@ HCSR04::getDistance(HCSR04_U unit) { return hcsr04_get_distance(m_hcsr04, unit); } + +int +HCSR04::getDistance() +{ + return getDistance(HCSR04_CM); +} diff --git a/src/hcsr04/hcsr04.hpp b/src/hcsr04/hcsr04.hpp index 495cddf6..e1c55dcf 100644 --- a/src/hcsr04/hcsr04.hpp +++ b/src/hcsr04/hcsr04.hpp @@ -25,6 +25,7 @@ #pragma once #include "hcsr04.h" +#include namespace upm { /** @@ -49,7 +50,7 @@ namespace upm { * @image html groveultrasonic.jpg * @snippet hcsr04.cxx Interesting */ -class HCSR04 { +class HCSR04 : virtual public iDistance { public: /** * Instantiates an HCSR04 object @@ -70,6 +71,12 @@ class HCSR04 { */ double getDistance (HCSR04_U unit); + /** + * Gets the distance from the sensor + * + * @return distance measured in cm. + */ + virtual int getDistance(); private: hcsr04_context m_hcsr04; HCSR04(const HCSR04& src) { /* do not create copied constructor */ } diff --git a/src/hdc1000/hdc1000.cpp b/src/hdc1000/hdc1000.cpp index 48c1dceb..b8e8d361 100644 --- a/src/hdc1000/hdc1000.cpp +++ b/src/hdc1000/hdc1000.cpp @@ -125,6 +125,12 @@ HDC1000::getTemperature(int bSampleData) return (float)(m_temperature * 0.01); } +float +HDC1000::getTemperature() +{ + return getTemperature(false); +} + float HDC1000::getHumidity(int bSampleData) { @@ -133,3 +139,9 @@ HDC1000::getHumidity(int bSampleData) } return (float)(m_humidity * 0.01); } + +float +HDC1000::getHumidity() +{ + return getHumidity(false); +} diff --git a/src/hdc1000/hdc1000.hpp b/src/hdc1000/hdc1000.hpp index 2bcb5d55..36cb8cfc 100644 --- a/src/hdc1000/hdc1000.hpp +++ b/src/hdc1000/hdc1000.hpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #define HDC1000_NAME "hdc1000" #define HDC1000_i2C_ADDRESS 0x43 @@ -87,7 +89,7 @@ namespace upm { * * @snippet hdc1000.cxx Interesting */ -class HDC1000 { +class HDC1000 : virtual public iHumidity, virtual public iTemperature { public: /** * Instantiates an HDC1000 object @@ -123,7 +125,14 @@ class HDC1000 { * @param bSampleData Flag to read sensor * @return The humidity sensor temp in degC */ - float getHumidity(int bSampleData = false); + float getHumidity(int bSampleData); + + /** + * Get the current measured humidity [RH] + * + * @return The humidity sensor temp in degC + */ + virtual float getHumidity(); /** * Get the humidity cell temperature [degC] @@ -131,7 +140,14 @@ class HDC1000 { * @param bSampleData Flag to read sensor * @return The humidity sensor temp in degC */ - float getTemperature(int bSampleData = false); + float getTemperature(int bSampleData); + + /** + * Get the humidity cell temperature [degC] + * + * @return The humidity sensor temp in degC + */ + virtual float getTemperature(); private: diff --git a/src/hp20x/hp20x.cxx b/src/hp20x/hp20x.cxx index 3cbe0fe8..e093667a 100644 --- a/src/hp20x/hp20x.cxx +++ b/src/hp20x/hp20x.cxx @@ -190,7 +190,8 @@ float HP20X::getPressure() // now read the pressure writeCmd(CMD_READ_P); - return ((float)readData() / 100.0); + // Return result in Pa, not milibars. + return (float)readData(); } float HP20X::getAltitude() diff --git a/src/hp20x/hp20x.hpp b/src/hp20x/hp20x.hpp index 7e23e355..e1c9be39 100644 --- a/src/hp20x/hp20x.hpp +++ b/src/hp20x/hp20x.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define HP20X_I2C_BUS 0 #define HP20X_DEFAULT_I2C_ADDR 0x76 @@ -61,7 +63,7 @@ namespace upm { * @image html hp20x.jpg * @snippet hp20x.cxx Interesting */ - class HP20X { + class HP20X : virtual public iPressure, virtual public iTemperature { public: /** @@ -270,14 +272,14 @@ namespace upm { * * @return Temperature */ - float getTemperature(); + virtual float getTemperature(); /** * Returns the pressure in millibars * * @return Pressure */ - float getPressure(); + virtual float getPressure(); /** * Returns the computed altitude in meters diff --git a/src/htu21d/htu21d.cpp b/src/htu21d/htu21d.cpp index 9328d7f1..e7ae4518 100644 --- a/src/htu21d/htu21d.cpp +++ b/src/htu21d/htu21d.cpp @@ -99,6 +99,12 @@ HTU21D::getTemperature(int bSampleData) return (float)m_temperature / 1000; } +float +HTU21D::getTemperature() +{ + return getTemperature(0); +} + float HTU21D::getHumidity(int bSampleData) { @@ -108,6 +114,12 @@ HTU21D::getHumidity(int bSampleData) return (float)m_humidity / 1000; } +float +HTU21D::getHumidity() +{ + return getHumidity(0); +} + /* * Use the compensation equation from the datasheet to correct the * current reading diff --git a/src/htu21d/htu21d.hpp b/src/htu21d/htu21d.hpp index e4e603cd..13693d2e 100644 --- a/src/htu21d/htu21d.hpp +++ b/src/htu21d/htu21d.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #define HTU21D_NAME "htu21d" #define HTU21D_I2C_ADDRESS 0x40 @@ -79,7 +81,7 @@ namespace upm { * @image html htu21d.jpeg * @snippet htu21d.cxx Interesting */ -class HTU21D { +class HTU21D : virtual public iHumidity, virtual public iTemperature { public: /** * Instantiates an HTU21D object @@ -102,7 +104,14 @@ class HTU21D { * @param bSampleData Flag to sample sensor (default false) * @return Relative humidity in %RH */ - float getHumidity(int bSampleData = false); + float getHumidity(int bSampleData); + + /** + * Gets the current measured humidity [%RH] + * + * @return Relative humidity in %RH + */ + virtual float getHumidity(); /** * Gets the humidity cell temperature [degC] @@ -110,7 +119,14 @@ class HTU21D { * @param bSampleData Flag to sample sensor (default false) * @return Temperature in degC */ - float getTemperature(int bSampleData = false); + float getTemperature(int bSampleData); + + /** + * Gets the humidity cell temperature [degC] + * + * @return Temperature in degC + */ + virtual float getTemperature(); /** * Using the current humidity and temperature, the function diff --git a/src/hwxpxx/hwxpxx.cxx b/src/hwxpxx/hwxpxx.cxx index 3362cfa0..daa335a7 100644 --- a/src/hwxpxx/hwxpxx.cxx +++ b/src/hwxpxx/hwxpxx.cxx @@ -263,6 +263,11 @@ float HWXPXX::getTemperature(bool fahrenheit) return m_temperature; } +float HWXPXX::getTemperature() +{ + return getTemperature(false); +} + float HWXPXX::getHumidity() { return m_humidity; diff --git a/src/hwxpxx/hwxpxx.hpp b/src/hwxpxx/hwxpxx.hpp index 568fbc17..61d5cafa 100644 --- a/src/hwxpxx/hwxpxx.hpp +++ b/src/hwxpxx/hwxpxx.hpp @@ -26,6 +26,8 @@ #include #include +#include +#include namespace upm { @@ -64,7 +66,7 @@ namespace upm { * @snippet hwxpxx.cxx Interesting */ - class HWXPXX { + class HWXPXX : virtual public iHumidity, virtual public iTemperature { public: // MODBUS input registers typedef enum { @@ -128,7 +130,17 @@ namespace upm { * The default is false (degrees Celsius). * @return The last temperature reading in Celsius or Fahrenheit */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. If this option was not + * installed, this method will always return 0C/0F, depending on + * the scale the device is operating in natively. + * + * @return The last temperature reading in Celsius or Fahrenheit + */ + virtual float getTemperature(); /** * Get the current relative humidity. update() must have been called @@ -136,7 +148,7 @@ namespace upm { * * @return The last humidity reading */ - float getHumidity(); + virtual float getHumidity(); /** * Get the current slider switch position. update() must have diff --git a/src/ims/ims.cxx b/src/ims/ims.cxx index 58c1f869..bb9653dd 100644 --- a/src/ims/ims.cxx +++ b/src/ims/ims.cxx @@ -55,6 +55,11 @@ uint16_t IMS::get_moisture() return retval; } +int IMS::getMoisture() +{ + return get_moisture(); +} + uint16_t IMS::get_light() { uint16_t retval; @@ -73,6 +78,11 @@ float IMS::get_temperature() return static_cast(retval)/10.0; } +float IMS::getTemperature() +{ + return get_temperature(); +} + void IMS::reset_i2c_address(uint8_t address_new) { if (ims_reset_i2c_address(_dev, address_new) != UPM_SUCCESS) diff --git a/src/ims/ims.hpp b/src/ims/ims.hpp index 91be9a09..5a606297 100644 --- a/src/ims/ims.hpp +++ b/src/ims/ims.hpp @@ -24,6 +24,8 @@ #pragma once +#include +#include #include "ims.h" namespace upm { @@ -55,7 +57,7 @@ namespace upm { * @snippet ims.cxx Interesting */ -class IMS { +class IMS : virtual public iMoisture, virtual public iTemperature { public: /** * I2C Moisture Sensor constructor @@ -103,6 +105,13 @@ class IMS { */ uint16_t get_moisture(); + /** + * Get moisture reading from sensor + * @return Unitless, relative capacitance value (moisture) + * @throws std::runtime_error if I2C read command fails + */ + virtual int getMoisture(); + /** * Get light reading from LED on device. The technical data for the I2C * moisture sensor specifies a 3 second wait. Loop for 3 seconds @@ -122,6 +131,13 @@ class IMS { */ float get_temperature(); + /** + * Get temperature reading from device + * @return rd_data Temperature in degrees Celsius + * @throws std::runtime_error if I2C read command fails + */ + virtual float getTemperature(); + /** * Reset sensor * @throws std::runtime_error if I2C write command fails diff --git a/src/lidarlitev3/lidarlitev3.hpp b/src/lidarlitev3/lidarlitev3.hpp index 7772e718..9be5f944 100644 --- a/src/lidarlitev3/lidarlitev3.hpp +++ b/src/lidarlitev3/lidarlitev3.hpp @@ -26,6 +26,7 @@ #include #include +#include #define ADDR 0x62 // device address @@ -87,7 +88,7 @@ namespace upm { * * @snippet lidarlitev3.cxx Interesting */ -class LIDARLITEV3 { +class LIDARLITEV3 : virtual public iDistance { public: /** * Instantiates an LIDARLITEV3 object @@ -109,7 +110,7 @@ class LIDARLITEV3 { * Returns distance measurement on success * Retruns -1 on failure. */ - int getDistance (); + virtual int getDistance (); /** * Read diff --git a/src/light/light.cxx b/src/light/light.cxx index 5fe23180..4dcec6c8 100644 --- a/src/light/light.cxx +++ b/src/light/light.cxx @@ -57,6 +57,17 @@ int Light::value() return (int)roundf(value); } +float Light::getLuminance() +{ + float value; + + if (light_get_lux(m_light, &value)) + throw std::runtime_error(std::string(__FUNCTION__) + + ": light_get_normalized() failed."); + + return value; +} + float Light::raw_value() { // This is a hack. Deprecated. Should be removed ASAP. diff --git a/src/light/light.hpp b/src/light/light.hpp index bcaef823..2bf3f0c1 100644 --- a/src/light/light.hpp +++ b/src/light/light.hpp @@ -28,6 +28,7 @@ #pragma once #include +#include #include "light.h" @@ -58,7 +59,7 @@ namespace upm { * @image html light.jpg * @snippet light.cxx Interesting */ - class Light { + class Light : virtual public iLight { public: /** * Analog light sensor constructor @@ -91,6 +92,14 @@ namespace upm { */ int value(); + /** + * Gets an approximate light value in lux from the sensor + * + * @return Approximate light reading in lux + * @throws std::runtime_error on error + */ + virtual float getLuminance(); + /** * Set ADC reference voltage * diff --git a/src/lm35/lm35.hpp b/src/lm35/lm35.hpp index a63733bf..5a324f6b 100644 --- a/src/lm35/lm35.hpp +++ b/src/lm35/lm35.hpp @@ -26,6 +26,7 @@ #include #include #include "lm35.h" +#include namespace upm { /** @@ -58,7 +59,7 @@ namespace upm { * @snippet lm35.cxx Interesting */ - class LM35 { + class LM35 : virtual public iTemperature { public: /** @@ -79,7 +80,7 @@ namespace upm { * * @return The Temperature in degrees Celsius */ - float getTemperature(); + virtual float getTemperature(); /** * Set sensor scale. This scale is applied to the return values diff --git a/src/max31723/max31723.cxx b/src/max31723/max31723.cxx index 042627ab..dc27dfa7 100644 --- a/src/max31723/max31723.cxx +++ b/src/max31723/max31723.cxx @@ -49,7 +49,7 @@ MAX31723::MAX31723 (int bus, int csn) : m_spi(bus), m_csnPinCtx(csn) { writeRegister (R_STS_WRITE_CMD, B_CONT_READING); } -short +float MAX31723::getTemperature () { uint8_t msb = 0; short temperature = 0; diff --git a/src/max31723/max31723.hpp b/src/max31723/max31723.hpp index aad5de57..1ec0edde 100644 --- a/src/max31723/max31723.hpp +++ b/src/max31723/max31723.hpp @@ -29,6 +29,7 @@ #include #include +#include #define HIGH 1 #define LOW 0 @@ -60,7 +61,7 @@ namespace upm { * * @snippet max31723.cxx Interesting */ -class MAX31723 { +class MAX31723 : virtual public iTemperature { public: static const uint8_t R_STS_READ_CMD = 0x00; static const uint8_t R_STS_WRITE_CMD = 0x80; @@ -85,9 +86,11 @@ class MAX31723 { **/ /** - * Gets the on-board temperature. + * Returns the temperature in degrees Celsius + * + * @return The Temperature in degrees Celsius */ - short getTemperature (); + virtual float getTemperature (); /** * Returns the name of the component diff --git a/src/max44009/max44009.cxx b/src/max44009/max44009.cxx index 84e99f88..a7a6e208 100644 --- a/src/max44009/max44009.cxx +++ b/src/max44009/max44009.cxx @@ -41,7 +41,7 @@ MAX44009::MAX44009 (int bus, int devAddr) { status = mraa::SUCCESS; reset(); if (status != mraa::SUCCESS) - UPM_THROW("config failure"); + throw std::runtime_error(std::string(__FUNCTION__) + ": config failure"); } MAX44009::~MAX44009() { @@ -70,7 +70,7 @@ MAX44009::getVisibleRaw() { int length = i2c->readBytesReg(MAX44009_LUX_START_ADDR, data, MAX44009_LUX_LENGTH); if(length != MAX44009_LUX_LENGTH) - UPM_THROW("Read error"); + throw std::runtime_error(std::string(__FUNCTION__) + ": Read error"); return *value; } @@ -86,8 +86,12 @@ MAX44009::getVisibleLux() { // Check for overrange condition if(exponent == MAX44009_OVERRANGE_CONDITION) - UPM_THROW("Overrange error"); + throw std::runtime_error(std::string(__FUNCTION__) + ": Overrange error"); return pow((double)2,(double)exponent) * mantissa * 0.045; } +float +MAX44009::getLuminance() { + return getVisibleLux(); +} diff --git a/src/max44009/max44009.hpp b/src/max44009/max44009.hpp index 0b78b90f..b3eb916d 100644 --- a/src/max44009/max44009.hpp +++ b/src/max44009/max44009.hpp @@ -26,7 +26,7 @@ #include #include -#include "interfaces/iLightSensor.hpp" +#include /* ADDRESS AND NOT_FOUND VALUE */ #define MAX44009_ADDRESS ( 0x4A ) @@ -106,7 +106,7 @@ namespace upm { * @snippet max44009.cxx Interesting * */ -class MAX44009 : public ILightSensor { +class MAX44009 : virtual public iLight { public: /** * Instanciates a MAX44009 object @@ -131,6 +131,13 @@ class MAX44009 : public ILightSensor { */ double getVisibleLux(); + /** + * Gets the luminance value from the sensor + * + * @return The measured light intensity value in Lux + */ + virtual float getLuminance(); + virtual const char* getModuleName() { return "max44009"; } private: diff --git a/src/max44009/max44009.i b/src/max44009/max44009.i index 21c139e9..4aaf94ad 100644 --- a/src/max44009/max44009.i +++ b/src/max44009/max44009.i @@ -2,11 +2,6 @@ /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%include "arrays_java.i"; -%include "../java_buffer.i" -%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%} -%import "../interfaces/javaupm_iLightSensor.i" - JAVA_JNI_LOADLIBRARY(javaupm_max44009) #endif /* END Java syntax */ diff --git a/src/maxsonarez/maxsonarez.cxx b/src/maxsonarez/maxsonarez.cxx index d6974e71..4a7d3419 100644 --- a/src/maxsonarez/maxsonarez.cxx +++ b/src/maxsonarez/maxsonarez.cxx @@ -62,3 +62,8 @@ int MAXSONAREZ::inches() return int(volts / m_vI); } + +int MAXSONAREZ::getDistance() +{ + return (inches() * 2.54); +} diff --git a/src/maxsonarez/maxsonarez.hpp b/src/maxsonarez/maxsonarez.hpp index cdceacc9..e652fb74 100644 --- a/src/maxsonarez/maxsonarez.hpp +++ b/src/maxsonarez/maxsonarez.hpp @@ -26,6 +26,7 @@ #include #include #include +#include // EZ series is volts/512 #define MAXSONAREZ_RES 512 @@ -67,7 +68,7 @@ namespace upm { * @snippet maxsonarez.cxx Interesting */ - class MAXSONAREZ { + class MAXSONAREZ : virtual public iDistance { public: /** @@ -90,6 +91,13 @@ namespace upm { */ int inches(); + /** + * Gets the distance to the object in inches + * + * @return Distance to the object in inches + */ + virtual int getDistance(); + private: mraa_aio_context m_aio; float m_aref; diff --git a/src/mb704x/mb704x.cxx b/src/mb704x/mb704x.cxx index 725ad3cf..5eb344c3 100644 --- a/src/mb704x/mb704x.cxx +++ b/src/mb704x/mb704x.cxx @@ -47,3 +47,8 @@ int MB704X::getRange() { return mb704x_get_range(m_mb704x); } + +int MB704X::getDistance() +{ + return getRange(); +} diff --git a/src/mb704x/mb704x.hpp b/src/mb704x/mb704x.hpp index d40247ef..679fbcc9 100644 --- a/src/mb704x/mb704x.hpp +++ b/src/mb704x/mb704x.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -58,7 +59,7 @@ namespace upm { * @snippet mb704x.cxx Interesting */ - class MB704X { + class MB704X : virtual public iDistance { public: /** @@ -84,7 +85,12 @@ namespace upm { */ int getRange(); - + /** + * Gets the distance to the object in cm + * + * @return Distance to the object in cm + */ + virtual int getDistance(); protected: // mb704x device context mb704x_context m_mb704x; diff --git a/src/mcp9808/mcp9808.cxx b/src/mcp9808/mcp9808.cxx index 91e410fe..4e353def 100644 --- a/src/mcp9808/mcp9808.cxx +++ b/src/mcp9808/mcp9808.cxx @@ -67,6 +67,11 @@ MCP9808::getTemp(){ return getTempValue(result); } +float +MCP9808::getTemperature() { + return getTemp(); +} + void MCP9808::shutDown(bool sleep){ if(sleep) this->updateConfigRegister(MCP9808_CONFIG_SHUTDOWN); diff --git a/src/mcp9808/mcp9808.hpp b/src/mcp9808/mcp9808.hpp index 2f0e72da..d10880ee 100644 --- a/src/mcp9808/mcp9808.hpp +++ b/src/mcp9808/mcp9808.hpp @@ -28,6 +28,7 @@ #include #include +#include #define MCP9808_REG_CONFIG 0x01 #define MCP9808_REG_AMBIENT_TEMP 0x05 @@ -75,7 +76,7 @@ namespace upm { * @image html mcp9808.jpg * @snippet mcp9808.cxx Interesting */ - class MCP9808 { + class MCP9808 : virtual public iTemperature { public: /** @@ -177,6 +178,13 @@ namespace upm { */ float getTemp(void); + /** + * Returns the temperature in degrees Celsius + * + * @return The Temperature in degrees Celsius + */ + virtual float getTemperature(); + /** * Will cause the devices to either sleep or wakeup. * diff --git a/src/mlx90614/mlx90614.cxx b/src/mlx90614/mlx90614.cxx index 2115836d..0d18c68e 100644 --- a/src/mlx90614/mlx90614.cxx +++ b/src/mlx90614/mlx90614.cxx @@ -70,6 +70,11 @@ MLX90614::readAmbientTempC(void) { return readTemperature(MLX90614_TA); } +float +MLX90614::getTemperature() { + return readAmbientTempC(); +} + /* * ************** * private area diff --git a/src/mlx90614/mlx90614.hpp b/src/mlx90614/mlx90614.hpp index fae82427..8375d043 100644 --- a/src/mlx90614/mlx90614.hpp +++ b/src/mlx90614/mlx90614.hpp @@ -25,6 +25,7 @@ #include #include +#include #define DEVICE_ADDR 0x5A // device address @@ -73,7 +74,7 @@ namespace upm { * @image html mlx90614.jpg * @snippet mlx90614.cxx Interesting */ -class MLX90614 { +class MLX90614 : virtual public iTemperature { public: /** @@ -109,6 +110,13 @@ class MLX90614 { */ float readAmbientTempC(void); + /** + * Returns the temperature in degrees Celsius + * + * @return The Temperature in degrees Celsius + */ + virtual float getTemperature(); + /** * Returns the name of the component */ diff --git a/src/moisture/moisture.cxx b/src/moisture/moisture.cxx index 9b1964c1..a4a855e9 100644 --- a/src/moisture/moisture.cxx +++ b/src/moisture/moisture.cxx @@ -46,3 +46,8 @@ int Moisture::value() { return mraa_aio_read(m_aio); } + +int Moisture::getMoisture() +{ + return value(); +} diff --git a/src/moisture/moisture.hpp b/src/moisture/moisture.hpp index bdb72dcf..de8396fa 100644 --- a/src/moisture/moisture.hpp +++ b/src/moisture/moisture.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { /** @@ -55,7 +56,7 @@ namespace upm { * @image html moisture.jpg * @snippet moisture.cxx Interesting */ - class Moisture { + class Moisture : virtual public iMoisture { public: /** * Analog moisture sensor constructor @@ -74,6 +75,13 @@ namespace upm { */ int value(); + /** + * Gets the moisture value from the sensor + * + * @return Moisture reading + */ + virtual int getMoisture(); + private: mraa_aio_context m_aio; }; diff --git a/src/mpl3115a2/mpl3115a2.cpp b/src/mpl3115a2/mpl3115a2.cpp index ab23e1b7..8264512c 100644 --- a/src/mpl3115a2/mpl3115a2.cpp +++ b/src/mpl3115a2/mpl3115a2.cpp @@ -207,6 +207,11 @@ MPL3115A2::getPressure(int bSampleData) { return (float)m_iPressure / 100; } +float +MPL3115A2::getPressure() { + return getPressure(true); +} + float MPL3115A2::getTemperature(int bSampleData) { int ret; diff --git a/src/mpl3115a2/mpl3115a2.hpp b/src/mpl3115a2/mpl3115a2.hpp index 406eeed8..991c3766 100644 --- a/src/mpl3115a2/mpl3115a2.hpp +++ b/src/mpl3115a2/mpl3115a2.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #define MPL3115A2_NAME "mpl3115a2" @@ -79,7 +80,7 @@ namespace upm { * @image html mpl3115a2.jpg * @snippet mpl3115a2.cxx Interesting */ -class MPL3115A2 { +class MPL3115A2 : virtual public iPressure { public: /** * Instantiates an MPL3115A2 object @@ -141,7 +142,14 @@ class MPL3115A2 { * * @param bSampleData Sets non-zero to a sample reading */ - float getPressure(int bSampleData = true); + float getPressure(int bSampleData); + + /** + * Reads the current pressure value from MPL3115A2 [Pa] + * + * @return Pressure value in Pa + */ + virtual float getPressure(); /** * Reads the current temperature value from MPL3115A2 [degC] diff --git a/src/ms5611/ms5611.cxx b/src/ms5611/ms5611.cxx index b3b34c09..b2eb573a 100644 --- a/src/ms5611/ms5611.cxx +++ b/src/ms5611/ms5611.cxx @@ -58,13 +58,13 @@ MS5611::MS5611(int i2cBus, int address) i2c->address(address); prom = new uint16_t[MS5611_PROM_SIZE]; if (i2c->writeByte(MS5611_CMD_RESET != mraa::SUCCESS)) - UPM_THROW("Reset failed."); + throw std::runtime_error(std::string(__FUNCTION__) + ": Reset failed."); delayms(5); for (int i = 0; i < MS5611_PROM_SIZE; ++i) { uint8_t buf[2]; int bytesRead = i2c->readBytesReg(MS5611_CMD_READ_PROM + 2*i, buf, 2); if (bytesRead != 2) - UPM_THROW("PROM address failed."); + throw std::runtime_error(std::string(__FUNCTION__) + ": PROM address failed."); prom[i] = buf[0] << 8; prom[i] |= buf[1]; // printf("Read PROM entry %d = %04x\n", i, prom[i]); @@ -72,7 +72,7 @@ MS5611::MS5611(int i2cBus, int address) // printf("CRC = %X\n", promCrc4()); if (promCrc4() != (prom[7] & 0x000F)) - UPM_THROW("PROM checksum error."); + throw std::runtime_error(std::string(__FUNCTION__) + ": PROM checksum error."); setOverSampling(ULTRA_HIGH_RES); } @@ -153,11 +153,11 @@ uint32_t MS5611::readADC(int adcReg) uint32_t value; uint8_t buf[3]; if (i2c->writeByte(adcReg + osr) != mraa::SUCCESS) - UPM_THROW("Convert D2 failed"); + throw std::runtime_error(std::string(__FUNCTION__) + ": Convert D2 failed"); delayms(100); int bytesRead = i2c->readBytesReg(MS5611_CMD_ADC_READ, buf, 3); if (bytesRead != 3) - UPM_THROW("ADC read failed"); + throw std::runtime_error(std::string(__FUNCTION__) + ": ADC read failed"); // printf("%02X%02X%02X\n", buf[0], buf[1], buf[2]); value = ((uint32_t)buf[0] << 16) | ((uint32_t)buf[1] << 8) | buf[2]; return value; @@ -181,6 +181,11 @@ int MS5611::getTemperatureCelsius() return (temp + 50) / 100; } +float MS5611::getTemperature() +{ + return getTemperatureCelsius(); +} + int MS5611::getPressurePa() { @@ -208,3 +213,7 @@ int MS5611::getPressurePa() return pressure; } +float MS5611::getPressure() +{ + return getPressurePa(); +} diff --git a/src/ms5611/ms5611.hpp b/src/ms5611/ms5611.hpp index b2025285..74beb38f 100644 --- a/src/ms5611/ms5611.hpp +++ b/src/ms5611/ms5611.hpp @@ -22,8 +22,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "interfaces/iPressureSensor.hpp" -#include "interfaces/iTemperatureSensor.hpp" +#include +#include #include "mraa/i2c.hpp" namespace upm @@ -58,7 +58,7 @@ namespace upm * @snippet ms5611.cxx Interesting */ -class MS5611 : public IPressureSensor, public ITemperatureSensor +class MS5611 : virtual public iPressure, virtual public iTemperature { public: enum OsrMode @@ -71,8 +71,22 @@ public: virtual const char* getModuleName() { return "ms5611"; } void setOverSampling(OsrMode osrMode); int getTemperatureCelsius(); + + /** + * Returns the temperature in degrees Celsius + * + * @return The Temperature in degrees Celsius + */ + virtual float getTemperature(); int getPressurePa(); + /** + * Return the current measured pressure in Pascals (Pa). + * + * @return The pressure in Pascals (Pa). + */ + virtual float getPressure(); + private: /* Disable implicit copy and assignment operators */ MS5611(const MS5611&) = delete; diff --git a/src/ms5611/ms5611.i b/src/ms5611/ms5611.i index e02dde16..417cf077 100644 --- a/src/ms5611/ms5611.i +++ b/src/ms5611/ms5611.i @@ -2,10 +2,6 @@ /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%import "../interfaces/javaupm_iTemperatureSensor.i" -%import "../interfaces/javaupm_iPressureSensor.i" -%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%} - JAVA_JNI_LOADLIBRARY(javaupm_ms5611) #endif /* END Java syntax */ diff --git a/src/ms5803/ms5803.cxx b/src/ms5803/ms5803.cxx index 6cefa088..bd9669b2 100644 --- a/src/ms5803/ms5803.cxx +++ b/src/ms5803/ms5803.cxx @@ -77,7 +77,7 @@ float MS5803::getTemperature() float MS5803::getPressure() { - return ms5803_get_pressure(m_ms5803); + return (ms5803_get_pressure(m_ms5803) * 100); } void MS5803::loadCoefficients() diff --git a/src/ms5803/ms5803.hpp b/src/ms5803/ms5803.hpp index c314df8a..11f9ed90 100644 --- a/src/ms5803/ms5803.hpp +++ b/src/ms5803/ms5803.hpp @@ -24,6 +24,8 @@ #pragma once #include +#include +#include #include "ms5803.h" @@ -64,7 +66,7 @@ namespace upm { * * @snippet ms5803.cxx Interesting */ - class MS5803 { + class MS5803 : virtual public iPressure, virtual public iTemperature { public: /** @@ -130,7 +132,7 @@ namespace upm { * * @return Temperature in degrees C */ - float getTemperature(); + virtual float getTemperature(); /** * Return the latest measured pressure. update() must have @@ -139,7 +141,7 @@ namespace upm { * * @return Pressure in mbar */ - float getPressure(); + virtual float getPressure(); protected: ms5803_context m_ms5803; diff --git a/src/otp538u/otp538u.cxx b/src/otp538u/otp538u.cxx index 5bf93916..8cc77570 100644 --- a/src/otp538u/otp538u.cxx +++ b/src/otp538u/otp538u.cxx @@ -55,6 +55,11 @@ float OTP538U::ambientTemperature() return temp; } +float OTP538U::getTemperature() +{ + return ambientTemperature(); +} + float OTP538U::objectTemperature() { float temp = 0; diff --git a/src/otp538u/otp538u.hpp b/src/otp538u/otp538u.hpp index 2c2be593..6e406fac 100644 --- a/src/otp538u/otp538u.hpp +++ b/src/otp538u/otp538u.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { @@ -73,7 +74,7 @@ namespace upm { * @image html otp538u.jpg * @snippet otp538u.cxx Interesting */ - class OTP538U { + class OTP538U : virtual public iTemperature { public: /** * OTP538U constructor @@ -96,6 +97,13 @@ namespace upm { */ float ambientTemperature(); + /** + * Gets the ambient temperature in Celsius + * + * @return Ambient temperature + */ + virtual float getTemperature(); + /** * Gets the object temperature in Celsius * diff --git a/src/rfr359f/rfr359f.hpp b/src/rfr359f/rfr359f.hpp index 3e439668..05fe78ae 100644 --- a/src/rfr359f/rfr359f.hpp +++ b/src/rfr359f/rfr359f.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace upm { @@ -53,7 +54,7 @@ namespace upm { * @image html rfr359f.jpg * @snippet rfr359f.cxx Interesting */ - class RFR359F { + class RFR359F : virtual public iDistanceInterrupter { public: /** * RFR359F constructor @@ -72,7 +73,7 @@ namespace upm { * * @return True if the sensor has detected an object */ - bool objectDetected(); + virtual bool objectDetected(); private: mraa_gpio_context m_gpio; diff --git a/src/rhusb/rhusb.cxx b/src/rhusb/rhusb.cxx index e6e5fa7a..b6d906ac 100644 --- a/src/rhusb/rhusb.cxx +++ b/src/rhusb/rhusb.cxx @@ -99,6 +99,11 @@ float RHUSB::getTemperature(bool fahrenheit) return m_temperature; } +float RHUSB::getTemperature() +{ + return getTemperature(false); +} + float RHUSB::getHumidity() { return m_humidity; diff --git a/src/rhusb/rhusb.hpp b/src/rhusb/rhusb.hpp index ba3d08f0..eae764ff 100644 --- a/src/rhusb/rhusb.hpp +++ b/src/rhusb/rhusb.hpp @@ -25,6 +25,8 @@ #include #include +#include +#include namespace upm { @@ -53,7 +55,7 @@ namespace upm { * @snippet rhusb.cxx Interesting */ - class RHUSB { + class RHUSB : virtual public iHumidity, virtual public iTemperature { public: /** * RHUSB constructor @@ -83,7 +85,15 @@ namespace upm { * The default is false (degrees Celsius). * @return The last temperature reading in Celsius or Fahrenheit */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. + * + * @return The last temperature reading in Celsius + */ + virtual float getTemperature(); /** * Get the current relative humidity. update() must have been called @@ -91,7 +101,7 @@ namespace upm { * * @return The last humidity reading */ - float getHumidity(); + virtual float getHumidity(); /** * Get the firmware identification string. diff --git a/src/rsc/rsc.cxx b/src/rsc/rsc.cxx index 06285961..3e690ae0 100644 --- a/src/rsc/rsc.cxx +++ b/src/rsc/rsc.cxx @@ -166,9 +166,10 @@ float RSC::getTemperature() return rsc_get_temperature(m_rsc); } +#define INH20_TO_PA 248.84 float RSC::getPressure() { - return rsc_get_pressure(m_rsc); + return rsc_get_pressure(m_rsc) * INH20_TO_PA; } void RSC::setMode(RSC_MODE mode) diff --git a/src/rsc/rsc.hpp b/src/rsc/rsc.hpp index 7ba474d7..d8a4f2f8 100644 --- a/src/rsc/rsc.hpp +++ b/src/rsc/rsc.hpp @@ -26,6 +26,8 @@ #include "rsc.h" #include +#include +#include namespace upm { /** @@ -74,7 +76,7 @@ namespace upm { * * @snippet rsc.cxx Interesting */ - class RSC { + class RSC : virtual public iPressure, virtual public iTemperature { public: /** @@ -194,14 +196,14 @@ namespace upm { * * @return float compensated temperature value */ - float getTemperature(); + virtual float getTemperature(); /** * Function to get the compensated pressure value * * @return float compensated pressure value */ - float getPressure(); + virtual float getPressure(); /** * Function to set the mode for the RSC sensor: diff --git a/src/sht1x/sht1x.hpp b/src/sht1x/sht1x.hpp index 441febe4..d15fc396 100644 --- a/src/sht1x/sht1x.hpp +++ b/src/sht1x/sht1x.hpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include "sht1x.h" @@ -58,7 +60,7 @@ namespace upm { * @snippet sht1x.cxx Interesting */ - class SHT1X { + class SHT1X : virtual public iHumidity, virtual public iTemperature { public: /** @@ -91,7 +93,7 @@ namespace upm { * * @return The temperature in Celsius */ - float getTemperature(); + virtual float getTemperature(); /** * Query the relative humidity. update() must have been called @@ -99,7 +101,7 @@ namespace upm { * * @return The relative humidity. */ - float getHumidity(); + virtual float getHumidity(); /** * Read the status register. diff --git a/src/si1132/si1132.cxx b/src/si1132/si1132.cxx index 541d39d7..0f2f6ae4 100644 --- a/src/si1132/si1132.cxx +++ b/src/si1132/si1132.cxx @@ -81,7 +81,7 @@ SI1132::SI1132 (int bus) { // Reset chip to defaults status = reset(); if (status != mraa::SUCCESS) - UPM_THROW("config failure"); + throw std::runtime_error(std::string(__FUNCTION__) + ": config failure"); } SI1132::~SI1132() { @@ -138,7 +138,7 @@ mraa::Result SI1132::reset() { uint16_t SI1132::getVisibleRaw() { status = runCommand(SI1132_COMMAND_ALS_FORCE); if (status != mraa::SUCCESS) - UPM_THROW("command failed"); + throw std::runtime_error(std::string(__FUNCTION__) + ": command failed"); return i2c->readWordReg(SI1132_REG_ALS_VIS_DATA0); } @@ -152,6 +152,9 @@ double SI1132::getVisibleLux() { return static_cast(rawValue); } +float SI1132::getLuminance() { + return getVisibleLux(); +} mraa::Result SI1132::clearResponseRegister() { diff --git a/src/si1132/si1132.hpp b/src/si1132/si1132.hpp index 29524def..75b2adab 100644 --- a/src/si1132/si1132.hpp +++ b/src/si1132/si1132.hpp @@ -25,7 +25,7 @@ #include #include "mraa/i2c.hpp" -#include "interfaces/iLightSensor.hpp" +#include namespace upm { @@ -56,7 +56,7 @@ namespace upm { * * @snippet si1132.cxx Interesting */ -class SI1132 : public ILightSensor { +class SI1132 : virtual public iLight { public: /** * Instanciates a Si1132 object @@ -80,6 +80,13 @@ class SI1132 : public ILightSensor { */ double getVisibleLux(); + /** + * Gets the luminance value from the sensor + * + * @return The measured light intensity value in Lux + */ + virtual float getLuminance(); + virtual const char* getModuleName() { return "si1132"; } private: diff --git a/src/si7005/si7005.cxx b/src/si7005/si7005.cxx index 7f6765ba..0e4abc05 100644 --- a/src/si7005/si7005.cxx +++ b/src/si7005/si7005.cxx @@ -82,7 +82,7 @@ SI7005::SI7005 (int bus, int pin) { m_i2c = new mraa::I2c(m_bus); status = m_i2c->address(m_controlAddr); if (!isAvailable()) - UPM_THROW("config failure"); + throw std::runtime_error(std::string(__FUNCTION__) + ": config failure"); } SI7005::~SI7005() { @@ -102,6 +102,11 @@ SI7005::getTemperatureCelsius () { return static_cast(last_temperature + 0.5); } +float +SI7005::getTemperature() { + return getTemperatureCelsius(); +} + uint16_t SI7005::getHumidityRaw () { return getMeasurement( SI7005_CONFIG_HUMIDITY ); @@ -117,6 +122,10 @@ SI7005::getHumidityRelative () { return static_cast(linearHumidity + 0.5); } +float +SI7005::getHumidity () { + return getHumidityRelative(); +} uint16_t SI7005::getMeasurement(uint8_t configValue) { @@ -149,7 +158,7 @@ uint16_t SI7005::getMeasurement(uint8_t configValue) { // Check we got the data we need if(length != SI7005_REG_DATA_LENGTH) - UPM_THROW("read error"); + throw std::runtime_error(std::string(__FUNCTION__) + ": read error"); // Merge MSB and LSB rawData = ((uint16_t)( data[SI7005_REG_DATA_LOW] & 0xFFFF )) + ( (uint16_t)(( data[SI7005_REG_DATA_HIGH] & 0xFFFF ) << 8 )); diff --git a/src/si7005/si7005.hpp b/src/si7005/si7005.hpp index a121f721..d8160653 100644 --- a/src/si7005/si7005.hpp +++ b/src/si7005/si7005.hpp @@ -25,8 +25,8 @@ #include -#include "interfaces/iTemperatureSensor.hpp" -#include "interfaces/iHumiditySensor.hpp" +#include +#include /* ADDRESS AND NOT_FOUND VALUE */ #define SI7005_ADDRESS ( 0x40 ) @@ -59,7 +59,7 @@ namespace upm { * * @snippet si7005.cxx Interesting */ -class SI7005 : public ITemperatureSensor, public IHumiditySensor { +class SI7005 : virtual public iTemperature, virtual public iHumidity { public: /** * Instantiates a SI7005 object @@ -84,6 +84,13 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor { */ int getTemperatureCelsius (); + /** + * Get the current temperature. + * + * @return The last temperature reading in Celsius + */ + virtual float getTemperature(); + /** * Get relative humidity measurement. */ @@ -94,6 +101,13 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor { */ int getHumidityRelative (); + /** + * Get the current relative humidity. + * + * @return The last humidity reading + */ + virtual float getHumidity(); + /** * Returns sensor module name */ diff --git a/src/si7005/si7005.i b/src/si7005/si7005.i index cf15e116..5167adc7 100644 --- a/src/si7005/si7005.i +++ b/src/si7005/si7005.i @@ -2,13 +2,6 @@ /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%include "arrays_java.i"; -%include "../java_buffer.i" -%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%} - -%import "../interfaces/javaupm_iTemperatureSensor.i" -%import "../interfaces/javaupm_iHumiditySensor.i" - JAVA_JNI_LOADLIBRARY(javaupm_si7005) #endif /* END Java syntax */ diff --git a/src/t3311/t3311.cxx b/src/t3311/t3311.cxx index e660815d..506c2d9e 100644 --- a/src/t3311/t3311.cxx +++ b/src/t3311/t3311.cxx @@ -259,6 +259,11 @@ float T3311::getTemperature(bool fahrenheit) return m_temperature; } +float T3311::getTemperature() +{ + return getTemperature(false); +} + float T3311::getHumidity() { return m_humidity; diff --git a/src/t3311/t3311.hpp b/src/t3311/t3311.hpp index d519ae7f..1c18dcc6 100644 --- a/src/t3311/t3311.hpp +++ b/src/t3311/t3311.hpp @@ -26,6 +26,8 @@ #include #include +#include +#include namespace upm { @@ -60,7 +62,7 @@ namespace upm { * @snippet t3311.cxx Interesting */ - class T3311 { + class T3311 : virtual public iHumidity, virtual public iTemperature { public: // MODBUS input registers @@ -148,7 +150,15 @@ namespace upm { * The default is false (degrees Celsius). * @return The last temperature reading in Celsius or Fahrenheit */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. + * + * @return The last temperature reading in Celsius + */ + virtual float getTemperature(); /** * Get the current relative humidity. update() must have been called @@ -156,7 +166,7 @@ namespace upm { * * @return The last humidity reading */ - float getHumidity(); + virtual float getHumidity(); /** * Get the current computed value. update() must have been diff --git a/src/teams/teams.cxx b/src/teams/teams.cxx index e8e8fbcc..3a0cb4dc 100644 --- a/src/teams/teams.cxx +++ b/src/teams/teams.cxx @@ -112,6 +112,11 @@ float TEAMS::getTemperature(bool fahrenheit) return m_temperature; } +float TEAMS::getTemperature() +{ + return getTemperature(false); +} + int TEAMS::average(int samples) { if (samples <= 0) diff --git a/src/teams/teams.hpp b/src/teams/teams.hpp index cd31dd6c..1349e3f7 100644 --- a/src/teams/teams.hpp +++ b/src/teams/teams.hpp @@ -27,6 +27,7 @@ #include #include +#include // Unlikey to be changable #define TEAMS_DEFAULT_AREF 5.0 @@ -66,7 +67,7 @@ namespace upm { * @snippet teams.cxx Interesting */ - class TEAMS { + class TEAMS : virtual public iTemperature { public: /** @@ -104,7 +105,15 @@ namespace upm { * The default is false (degrees Celsius). * @return The last temperature reading in Celsius or Fahrenheit */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. + * + * @return The last temperature reading in Celsius or Fahrenheit + */ + virtual float getTemperature(); /** * When using a direct 4-20ma interface (rResistor supplied in the diff --git a/src/temperature/temperature.cxx b/src/temperature/temperature.cxx index 0938a230..a4cf7473 100644 --- a/src/temperature/temperature.cxx +++ b/src/temperature/temperature.cxx @@ -62,6 +62,11 @@ int Temperature::value () return (int) round(t); } +float Temperature::getTemperature () +{ + return value(); +} + float Temperature::raw_value() { return (float) mraa_aio_read(m_aio); diff --git a/src/temperature/temperature.hpp b/src/temperature/temperature.hpp index 17a3a4df..09b62198 100644 --- a/src/temperature/temperature.hpp +++ b/src/temperature/temperature.hpp @@ -28,6 +28,7 @@ #include #include +#include namespace upm { /** @@ -58,7 +59,7 @@ namespace upm { * @image html temp.jpg * @snippet temperature.cxx Interesting */ -class Temperature { +class Temperature : virtual public iTemperature { public: /** * Analog temperature sensor constructor @@ -96,6 +97,13 @@ class Temperature { * @return Normalized temperature in Celsius */ int value(); + + /** + * Gets the temperature in Celsius from the sensor + * + * @return Normalized temperature in Celsius + */ + virtual float getTemperature(); private: mraa_aio_context m_aio; float m_scale; diff --git a/src/tex00/tex00.cxx b/src/tex00/tex00.cxx index 95e31c67..9172a427 100644 --- a/src/tex00/tex00.cxx +++ b/src/tex00/tex00.cxx @@ -141,6 +141,11 @@ float TEX00::getTemperature(bool fahrenheit) return m_temperature; } +float TEX00::getTemperature() +{ + return getTemperature(false); +} + int TEX00::average(int samples) { if (samples <= 0) diff --git a/src/tex00/tex00.hpp b/src/tex00/tex00.hpp index 2bcc6db0..48a15da8 100644 --- a/src/tex00/tex00.hpp +++ b/src/tex00/tex00.hpp @@ -28,6 +28,7 @@ #include #include +#include #define TEX00_DEFAULT_AREF 5.0 @@ -74,7 +75,7 @@ namespace upm { * @snippet tex00.cxx Interesting */ - class TEX00 { + class TEX00 : virtual public iTemperature { public: typedef enum { @@ -126,7 +127,15 @@ namespace upm { * The default is false (degrees Celsius). * @return The last temperature reading in Celsius or Fahrenheit */ - float getTemperature(bool fahrenheit=false); + float getTemperature(bool fahrenheit); + + /** + * Get the current temperature. update() must have been called + * prior to calling this method. + * + * @return The last temperature reading in Celsius or Fahrenheit + */ + virtual float getTemperature(); /** * Return the smallest temperature that can be measured by the diff --git a/src/th02/th02.hpp b/src/th02/th02.hpp index 45a0f1d2..26e2d765 100644 --- a/src/th02/th02.hpp +++ b/src/th02/th02.hpp @@ -28,6 +28,8 @@ #include #include +#include +#include #define TH02_ADDR 0x40 // device address @@ -69,7 +71,7 @@ namespace upm { * @image html th02.jpg * @snippet th02.cxx Interesting */ -class TH02 { +class TH02 : virtual public iHumidity, virtual public iTemperature { public: /** * Instantiates a TH02 object @@ -82,14 +84,18 @@ class TH02 { ~TH02 (); /** - * Gets the temperature value from the sensor. + * Get the current temperature. + * + * @return The last temperature reading in Celsius */ - float getTemperature (); + virtual float getTemperature (); /** - * Gets the humidity value from the sensor. + * Get the current relative humidity. + * + * @return The last humidity reading */ - float getHumidity (); + virtual float getHumidity (); /** * Gets the sensor status. diff --git a/src/tsl2561/tsl2561.cxx b/src/tsl2561/tsl2561.cxx index 0876a92c..927984e4 100644 --- a/src/tsl2561/tsl2561.cxx +++ b/src/tsl2561/tsl2561.cxx @@ -189,6 +189,12 @@ TSL2561::getLux() return lux; } +float +TSL2561::getLuminance() +{ + return getLux(); +} + mraa::Result TSL2561::i2cWriteReg (uint8_t reg, uint8_t value) diff --git a/src/tsl2561/tsl2561.hpp b/src/tsl2561/tsl2561.hpp index 498d4f72..cf12001a 100644 --- a/src/tsl2561/tsl2561.hpp +++ b/src/tsl2561/tsl2561.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace upm { @@ -108,14 +109,14 @@ namespace upm { * @kit eak * * @brief API for the TSL2561 Digital Light Sensor - * + * * TSL2560 and TSL2561 are light-to-digital converters that transform * light intensity to a digital signal output capable of a direct I2C (TSL2561) interface * * @image html tsl2561.jpg * @snippet tsl2561.cxx Interesting */ -class TSL2561{ +class TSL2561 : virtual public iLight { public: /** * Instantiates a TSL2561 object @@ -139,6 +140,13 @@ class TSL2561{ */ int getLux(); + /** + * Gets the calculated lux reading from TSL2561 + * + * @return Calculated lux value from the sensor + */ + virtual float getLuminance(); + private: /** * Writes to a TSL2561 register diff --git a/src/urm37/urm37.cxx b/src/urm37/urm37.cxx index 485668a8..c7fcbc6d 100644 --- a/src/urm37/urm37.cxx +++ b/src/urm37/urm37.cxx @@ -67,6 +67,12 @@ float URM37::getDistance(int degrees) return (distance); } +int URM37::getDistance() +{ + /* TODO: compilation issue for swig. switched original method to not use default zero parameter. */ + return getDistance(0); +} + float URM37::getTemperature() { float temperature; diff --git a/src/urm37/urm37.hpp b/src/urm37/urm37.hpp index 0fe18442..bca87c51 100644 --- a/src/urm37/urm37.hpp +++ b/src/urm37/urm37.hpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "urm37.h" @@ -76,7 +78,7 @@ namespace upm { * @snippet urm37-uart.cxx Interesting */ - class URM37 { + class URM37 : virtual public iDistance, virtual public iTemperature { public: /** @@ -119,14 +121,22 @@ namespace upm { * ignored in analog mode. * @return The measured distance in cm */ - float getDistance(int degrees=0); + float getDistance(int degrees); + + /** + * Get the distance measurement. A return value of 65535.0 + * in UART mode indicates an invalid measurement. + * + * @return The measured distance in cm + */ + virtual int getDistance(); /** * Get the temperature measurement. This is only valid in UART mode. * * @return The measured temperature in degrees C */ - float getTemperature(); + virtual float getTemperature(); /** * In UART mode only, read a value from the EEPROM and return it.