Merge 3572a176c2d81ea60c37395f5b5fa57acbb7b3f7 into 9a959b578cb69a5f0766f415da640bcbd3ebabb1

This commit is contained in:
Stefan Andritoiu 2018-06-01 20:53:44 +00:00 committed by GitHub
commit e12edf8773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
102 changed files with 1072 additions and 183 deletions

View File

@ -0,0 +1,28 @@
#include <iostream>
#include <vector>
#include <memory>
#include "apds9002.hpp"
#include "bh1750.hpp"
#include "max44009.hpp"
using namespace std;
using namespace upm;
int
main()
{
vector<unique_ptr<iLight>> lightSensors;
// Populate list of light sensors
lightSensors.push_back(unique_ptr<iLight>(new APDS9002(0)));
lightSensors.push_back(unique_ptr<iLight>(new BH1750()));
lightSensors.push_back(unique_ptr<iLight>(new MAX44009(1)));
// Measure luminance level from all 3 individual sensors
for (auto& sensor : lightSensors) {
sensor->getLuminance();
}
return 0;
}

View File

@ -0,0 +1,26 @@
#include <iostream>
#include <vector>
#include "lm35.hpp"
#include "abp.hpp"
using namespace std;
using namespace upm;
int
main()
{
vector<iTemperature*> tempSensors {new LM35(0), new ABP(0, ABP_DEFAULT_ADDRESS)};
for (auto sensor : tempSensors) {
cout << sensor->getTemperature() << endl;
}
for (iTemperature* sensor : tempSensors) {
delete sensor;
}
tempSensors.clear();
return 0;
}

View File

@ -62,7 +62,7 @@ getLightSensor()
int int
main() main()
{ {
upm::ILightSensor* lightSensor = getLightSensor(); /*upm::ILightSensor* lightSensor = getLightSensor();
if (lightSensor == NULL) { if (lightSensor == NULL) {
std::cout << "Light sensor not detected" << std::endl; std::cout << "Light sensor not detected" << std::endl;
return 1; return 1;
@ -77,7 +77,7 @@ main()
} }
upm_delay(1); upm_delay(1);
} }
delete lightSensor; delete lightSensor;*/
return 0; return 0;
} }

View File

@ -48,12 +48,12 @@ main()
// Instantiate a LM35 on analog pin A0, with a default analog // Instantiate a LM35 on analog pin A0, with a default analog
// reference voltage of 5.0 // 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 // Every half second, sample the sensor and output the temperature
while (shouldRun) { while (shouldRun) {
cout << "Temperature: " << sensor.getTemperature() << " C" << endl; cout << "Temperature: " << sensor->getTemperature() << " C" << endl;
upm_delay_us(500000); upm_delay_us(500000);
} }
@ -61,6 +61,7 @@ main()
//! [Interesting] //! [Interesting]
cout << "Exiting" << endl; cout << "Exiting" << endl;
delete sensor;
return 0; return 0;
} }

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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 Measuring Sensors
*/
class iDistance
{
public:
virtual ~iDistance() {}
virtual int getDistance() = 0;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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 Pressure Measuring Sensors
*/
class iPressure
{
public:
virtual ~iPressure() {}
virtual float getPressure() = 0;
};
}

View File

@ -0,0 +1,38 @@
/*
* Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com>
* 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 Temperature Measuring Sensors
*/
class iTemperature
{
public:
virtual ~iTemperature() {}
virtual float getTemperature() = 0;
};
}

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/gpio.h> #include <mraa/gpio.h>
#include <interfaces/iHallEffect.hpp>
namespace upm { namespace upm {
/** /**
@ -58,7 +59,7 @@ namespace upm {
* An example demonstrating the use of an interrupt handler to count pulses * An example demonstrating the use of an interrupt handler to count pulses
* @snippet a110x-intr.cxx Interesting * @snippet a110x-intr.cxx Interesting
*/ */
class A110X { class A110X : virtual public iHallEffect {
public: public:
/** /**
* A110x digital sensor constructor * A110x digital sensor constructor
@ -75,7 +76,7 @@ namespace upm {
* *
* @return True if magnetic field detected * @return True if magnetic field detected
*/ */
bool magnetDetected(); virtual bool magnetDetected();
/** /**
* Installs an interrupt service routine (ISR) to be called when * Installs an interrupt service routine (ISR) to be called when

View File

@ -25,6 +25,7 @@
#pragma once #pragma once
#include "abp.h" #include "abp.h"
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
/** /**
@ -59,7 +60,7 @@ namespace upm {
* @snippet abp.cxx Interesting * @snippet abp.cxx Interesting
*/ */
class ABP { class ABP : virtual public iTemperature {
public: public:
/** /**
@ -90,7 +91,7 @@ namespace upm {
* *
* @return float compensated temperature value * @return float compensated temperature value
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* This functio has to be called before calling either of the get * This functio has to be called before calling either of the get

View File

@ -26,6 +26,8 @@
#include <string> #include <string>
#include <mraa/i2c.h> #include <mraa/i2c.h>
#include <math.h> #include <math.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#define AM2315_NAME "am2315" #define AM2315_NAME "am2315"
#define AM2315_I2C_ADDRESS 0x5c #define AM2315_I2C_ADDRESS 0x5c
@ -77,7 +79,7 @@ namespace upm {
* @image html am2315.jpeg * @image html am2315.jpeg
* @snippet am2315.cxx Interesting * @snippet am2315.cxx Interesting
*/ */
class AM2315 { class AM2315 : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
* Instantiates an AM2315 object * Instantiates an AM2315 object
@ -98,15 +100,17 @@ class AM2315 {
* Data is updated every 2 seconds - accesses occurring more often than * Data is updated every 2 seconds - accesses occurring more often than
* that return cached data * that return cached data
*/ */
float getHumidity(void); virtual float getHumidity(void);
/** /**
* Gets the humidity cell temperature [degC] * Gets the humidity cell temperature [degC]
* *
* Data is updated every 2 seconds - accesses occurring more often than * Data is updated every 2 seconds - accesses occurring more often than
* that return cached data * that return cached data
*
* @return float compensated temperature value
*/ */
float getTemperature(void); virtual float getTemperature(void);
/** /**
* Gets the humidity cell temperature [degF] * Gets the humidity cell temperature [degF]

View File

@ -32,7 +32,7 @@ using namespace upm;
APDS9002::APDS9002(int pin) 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__) + throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?"); ": mraa_aio_init() failed, invalid pin?");
@ -49,3 +49,8 @@ int APDS9002::value()
{ {
return mraa_aio_read(m_aio); return mraa_aio_read(m_aio);
} }
float APDS9002::getLuminance()
{
return value();
}

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/aio.h> #include <mraa/aio.h>
#include <interfaces/iLight.hpp>
namespace upm { namespace upm {
/** /**
@ -52,7 +53,7 @@ namespace upm {
* @snippet apds9002.cxx Interesting * @snippet apds9002.cxx Interesting
*/ */
class APDS9002 { class APDS9002 : virtual public iLight {
public: public:
/** /**
* APDS-9002 luminance sensor constructor * APDS-9002 luminance sensor constructor
@ -71,6 +72,13 @@ namespace upm {
*/ */
int value(); int value();
/**
* Gets the luminance value from the sensor
*
* @return The measured light intensity value in Lux
*/
virtual float getLuminance();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
}; };

View File

@ -59,6 +59,11 @@ float BH1750::getLux()
return lux; return lux;
} }
float BH1750::getLuminance()
{
return getLux();
}
void BH1750::powerUp() void BH1750::powerUp()
{ {
if (bh1750_power_up(m_bh1750) != UPM_SUCCESS) if (bh1750_power_up(m_bh1750) != UPM_SUCCESS)

View File

@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <interfaces/iLight.hpp>
#include "bh1750.h" #include "bh1750.h"
@ -57,13 +58,13 @@ namespace upm {
* @snippet bh1750.cxx Interesting * @snippet bh1750.cxx Interesting
*/ */
class BH1750 { class BH1750 : virtual public iLight {
public: public:
/** /**
* BH1750 object constructor (Analog mode) * BH1750 object constructor (Analog mode)
* *
* @param bus The I2C bus to use * @param bus The I2C bus to use
* @param addr The I2C address of the device * @param addr The I2C address of the device
* @param mode The mode to start operation under. One of the * @param mode The mode to start operation under. One of the
* BH1750_OPMODES_T values. The default is the highest precision, * BH1750_OPMODES_T values. The default is the highest precision,
@ -92,6 +93,13 @@ namespace upm {
*/ */
float getLux(); float getLux();
/**
* Gets the luminance value from the sensor
*
* @return The measured light intensity value in Lux
*/
virtual float getLuminance();
/** /**
* Power up the device. * Power up the device.
*/ */

View File

@ -48,3 +48,8 @@ bool BISS0001::value()
{ {
return biss0001_motion_detected(m_biss0001); return biss0001_motion_detected(m_biss0001);
} }
bool BISS0001::motionDetected()
{
return value();
}

View File

@ -24,6 +24,7 @@
*/ */
#pragma once #pragma once
#include <interfaces/iMotion.hpp>
#include <biss0001.h> #include <biss0001.h>
namespace upm { namespace upm {
@ -57,7 +58,7 @@ namespace upm {
* @snippet biss0001.cxx Interesting * @snippet biss0001.cxx Interesting
*/ */
class BISS0001 { class BISS0001 : virtual public iMotion {
public: public:
/** /**
* BISS0001 motion sensor constructor * BISS0001 motion sensor constructor
@ -81,11 +82,11 @@ namespace upm {
/** /**
* Gets the motion value from the sensor. This is a more * Gets the motion value from the sensor. This is a more
* informative method name, but we want to keep compatibility * 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. * @return true if motion was detected, false otherwise.
*/ */
bool motionDetected() { return value(); }; virtual bool motionDetected();
private: private:
/* Disable implicit copy and assignment operators */ /* Disable implicit copy and assignment operators */

View File

@ -26,7 +26,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include "interfaces/iHumiditySensor.hpp" #include <interfaces/iHumidity.hpp>
#include "bmp280.hpp" #include "bmp280.hpp"
@ -57,7 +57,7 @@ namespace upm {
* @snippet bmp280-bme280.cxx Interesting * @snippet bmp280-bme280.cxx Interesting
*/ */
class BME280 : public BMP280, public IHumiditySensor { class BME280 : public BMP280, virtual public iHumidity {
public: public:
/** /**
@ -96,7 +96,7 @@ namespace upm {
* *
* @return The relative humidity in percent. * @return The relative humidity in percent.
*/ */
float getHumidity(); virtual float getHumidity();
/** /**
* Set the humidity sensor oversampling parameter. See the data * Set the humidity sensor oversampling parameter. See the data

View File

@ -110,6 +110,11 @@ float BMP280::getTemperature(bool fahrenheit)
return temperature; return temperature;
} }
float BMP280::getTemperature()
{
return getTemperature(false);
}
float BMP280::getPressure() float BMP280::getPressure()
{ {
return bmp280_get_pressure(m_bmp280); return bmp280_get_pressure(m_bmp280);

View File

@ -28,8 +28,8 @@
#include <string> #include <string>
#include "bmp280.h" #include "bmp280.h"
#include "interfaces/iPressureSensor.hpp" #include <interfaces/iPressure.hpp>
#include "interfaces/iTemperatureSensor.hpp" #include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -67,7 +67,7 @@ namespace upm {
* @snippet bmp280.cxx Interesting * @snippet bmp280.cxx Interesting
*/ */
class BMP280 : public ITemperatureSensor, public IPressureSensor { class BMP280 : virtual public iPressure, virtual public iTemperature {
public: public:
/** /**
@ -127,7 +127,17 @@ namespace upm {
* Celicus. Celsius is the default. * Celicus. Celsius is the default.
* @return The temperature in degrees Celsius or Fahrenheit. * @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() * Return the current measured pressure in Pascals (Pa). update()
@ -135,7 +145,7 @@ namespace upm {
* *
* @return The pressure in Pascals (Pa). * @return The pressure in Pascals (Pa).
*/ */
float getPressure(); virtual float getPressure();
/** /**
* Set the pressure at sea level in hecto-Pascals (hPA). This * Set the pressure at sea level in hecto-Pascals (hPA). This

View File

@ -2,37 +2,14 @@
/* BEGIN Java syntax ------------------------------------------------------- */ /* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA #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) JAVA_JNI_LOADLIBRARY(javaupm_bmp280)
#endif #endif
/* END Java syntax */ /* END Java syntax */
/* BEGIN Javascript syntax ------------------------------------------------- */ /* BEGIN Javascript syntax ------------------------------------------------- */
#ifdef SWIGJAVASCRIPT
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
%include "iHumiditySensor.hpp"
#endif
/* END Javascript syntax */ /* END Javascript syntax */
/* BEGIN Python syntax ----------------------------------------------------- */ /* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
%include "iHumiditySensor.hpp"
#endif
/* END Python syntax */ /* END Python syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */ /* BEGIN Common SWIG syntax ------------------------------------------------- */

View File

@ -99,7 +99,7 @@ void BMPX8X::writeReg(uint8_t reg, uint8_t val)
+ ": bmpx8x_write_reg() failed"); + ": bmpx8x_write_reg() failed");
} }
int BMPX8X::getPressure() float BMPX8X::getPressure()
{ {
return bmpx8x_get_pressure(m_bmpx8x); return bmpx8x_get_pressure(m_bmpx8x);
} }

View File

@ -32,8 +32,7 @@
#include "bmpx8x.h" #include "bmpx8x.h"
#include "interfaces/iPressureSensor.hpp" #include <interfaces/iPressure.hpp>
#include "interfaces/iTemperatureSensor.hpp"
namespace upm { namespace upm {
@ -68,7 +67,7 @@ namespace upm {
* @snippet bmpx8x.cxx Interesting * @snippet bmpx8x.cxx Interesting
*/ */
class BMPX8X : public IPressureSensor, public ITemperatureSensor { class BMPX8X : virtual public iPressure {
public: public:
/** /**
* Instantiates a BMPX8X object * Instantiates a BMPX8X object
@ -132,7 +131,7 @@ namespace upm {
* *
* @returns The pressure in Pascals. * @returns The pressure in Pascals.
*/ */
int getPressure(); virtual float getPressure();
/** /**
* Returns the calculated temperature in Celsius. update() * Returns the calculated temperature in Celsius. update()

View File

@ -2,19 +2,12 @@
/* BEGIN Java syntax ------------------------------------------------------- */ /* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA #ifdef SWIGJAVA
%import "../interfaces/javaupm_iPressureSensor.i"
%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%}
%import "../interfaces/javaupm_iTemperatureSensor.i"
JAVA_JNI_LOADLIBRARY(javaupm_bmpx8x) JAVA_JNI_LOADLIBRARY(javaupm_bmpx8x)
#endif #endif
/* END Java syntax */ /* END Java syntax */
/* BEGIN Python syntax ----------------------------------------------------- */ /* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON #ifdef SWIGPYTHON
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
#endif #endif
/* END Python syntax */ /* END Python syntax */

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <mraa/gpio.h> #include <mraa/gpio.h>
#include <interfaces/iCollision.hpp>
namespace upm { namespace upm {
/** /**
@ -42,15 +43,15 @@ namespace upm {
* @con gpio * @con gpio
* *
* @brief API for the Collision Sensor * @brief API for the Collision Sensor
* *
* The Collision Sensor can detect whether any * The Collision Sensor can detect whether any
* collision movement or vibration happens. * 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 * @image html collision.jpg
* @snippet collision.cxx Interesting * @snippet collision.cxx Interesting
*/ */
class Collision { class Collision : virtual public iCollision {
public: public:
/** /**
* Collision sensor constructor * Collision sensor constructor
@ -63,11 +64,11 @@ namespace upm {
*/ */
~Collision(); ~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: private:
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;
}; };
} }

View File

@ -57,6 +57,11 @@ int GroveLight::value()
return (int) round(a); return (int) round(a);
} }
float GroveLight::getLuminance()
{
return value();
}
float GroveLight::raw_value() float GroveLight::raw_value()
{ {
return (float) mraa_aio_read(m_aio); return (float) mraa_aio_read(m_aio);

View File

@ -28,6 +28,7 @@
#include <string> #include <string>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
#include <interfaces/iLight.hpp>
#include "grovebase.hpp" #include "grovebase.hpp"
namespace upm { namespace upm {
@ -54,7 +55,7 @@ namespace upm {
* @image html grovelight.jpg * @image html grovelight.jpg
* @snippet grove-grovelight.cxx Interesting * @snippet grove-grovelight.cxx Interesting
*/ */
class GroveLight: public Grove { class GroveLight: public Grove, virtual public iLight {
public: public:
/** /**
* Grove analog light sensor constructor * Grove analog light sensor constructor
@ -78,6 +79,13 @@ class GroveLight: public Grove {
* @return Normalized light reading in lux * @return Normalized light reading in lux
*/ */
int value(); int value();
/**
* Gets an approximate light value, in lux, from the sensor
*
* @return Normalized light reading in lux
*/
virtual float getLuminance();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
}; };

View File

@ -62,6 +62,11 @@ int GroveTemp::value ()
return (int) round(t); return (int) round(t);
} }
float GroveTemp::getTemperature ()
{
return value();
}
float GroveTemp::raw_value() float GroveTemp::raw_value()
{ {
return (float) mraa_aio_read(m_aio); return (float) mraa_aio_read(m_aio);

View File

@ -29,6 +29,7 @@
#include <string> #include <string>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
#include "grovebase.hpp" #include "grovebase.hpp"
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -54,7 +55,7 @@ namespace upm {
* @image html grovetemp.jpg * @image html grovetemp.jpg
* @snippet grove-grovetemp.cxx Interesting * @snippet grove-grovetemp.cxx Interesting
*/ */
class GroveTemp: public Grove { class GroveTemp: public Grove, virtual public iTemperature {
public: public:
/** /**
* Grove analog temperature sensor constructor * Grove analog temperature sensor constructor
@ -84,6 +85,8 @@ class GroveTemp: public Grove {
* @return Normalized temperature in Celsius * @return Normalized temperature in Celsius
*/ */
int value(); int value();
virtual float getTemperature();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
float m_scale; float m_scale;

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <mraa/gpio.h> #include <mraa/gpio.h>
#include <interfaces/iCollision.hpp>
namespace upm { namespace upm {
/** /**
@ -43,15 +44,15 @@ namespace upm {
* @con gpio * @con gpio
* *
* @brief API for the Grove Collision Sensor * @brief API for the Grove Collision Sensor
* *
* The Grove Collision Sensor can detect whether any * The Grove Collision Sensor can detect whether any
* collision movement or vibration happens. * 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 * @image html grovecollision.jpg
* @snippet grovecollision.cxx Interesting * @snippet grovecollision.cxx Interesting
*/ */
class GroveCollision { class GroveCollision : virtual public iCollision {
public: public:
/** /**
* Grove collision sensor constructor * Grove collision sensor constructor
@ -64,11 +65,11 @@ namespace upm {
*/ */
~GroveCollision(); ~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: private:
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;
}; };
} }

View File

@ -46,3 +46,8 @@ int GroveMoisture::value()
{ {
return mraa_aio_read(m_aio); return mraa_aio_read(m_aio);
} }
int GroveMoisture::getMoisture()
{
return value();
}

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/aio.h> #include <mraa/aio.h>
#include <interfaces/iMoisture.hpp>
namespace upm { namespace upm {
/** /**
@ -56,7 +57,7 @@ namespace upm {
* @image html grovemoisture.jpg * @image html grovemoisture.jpg
* @snippet grovemoisture.cxx Interesting * @snippet grovemoisture.cxx Interesting
*/ */
class GroveMoisture { class GroveMoisture : virtual public iMoisture {
public: public:
/** /**
* Grove analog moisture sensor constructor * Grove analog moisture sensor constructor
@ -75,6 +76,13 @@ namespace upm {
*/ */
int value(); int value();
/**
* Gets the moisture value from the sensor
*
* @return Moisture reading
*/
virtual int getMoisture();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
}; };

View File

@ -49,3 +49,9 @@ HCSR04::getDistance(HCSR04_U unit)
{ {
return hcsr04_get_distance(m_hcsr04, unit); return hcsr04_get_distance(m_hcsr04, unit);
} }
int
HCSR04::getDistance()
{
return getDistance(HCSR04_CM);
}

View File

@ -25,6 +25,7 @@
#pragma once #pragma once
#include "hcsr04.h" #include "hcsr04.h"
#include <interfaces/iDistance.hpp>
namespace upm { namespace upm {
/** /**
@ -49,7 +50,7 @@ namespace upm {
* @image html groveultrasonic.jpg * @image html groveultrasonic.jpg
* @snippet hcsr04.cxx Interesting * @snippet hcsr04.cxx Interesting
*/ */
class HCSR04 { class HCSR04 : virtual public iDistance {
public: public:
/** /**
* Instantiates an HCSR04 object * Instantiates an HCSR04 object
@ -70,6 +71,12 @@ class HCSR04 {
*/ */
double getDistance (HCSR04_U unit); double getDistance (HCSR04_U unit);
/**
* Gets the distance from the sensor
*
* @return distance measured in cm.
*/
virtual int getDistance();
private: private:
hcsr04_context m_hcsr04; hcsr04_context m_hcsr04;
HCSR04(const HCSR04& src) { /* do not create copied constructor */ } HCSR04(const HCSR04& src) { /* do not create copied constructor */ }

View File

@ -125,6 +125,12 @@ HDC1000::getTemperature(int bSampleData)
return (float)(m_temperature * 0.01); return (float)(m_temperature * 0.01);
} }
float
HDC1000::getTemperature()
{
return getTemperature(false);
}
float float
HDC1000::getHumidity(int bSampleData) HDC1000::getHumidity(int bSampleData)
{ {
@ -133,3 +139,9 @@ HDC1000::getHumidity(int bSampleData)
} }
return (float)(m_humidity * 0.01); return (float)(m_humidity * 0.01);
} }
float
HDC1000::getHumidity()
{
return getHumidity(false);
}

View File

@ -29,6 +29,8 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <math.h> #include <math.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#define HDC1000_NAME "hdc1000" #define HDC1000_NAME "hdc1000"
#define HDC1000_i2C_ADDRESS 0x43 #define HDC1000_i2C_ADDRESS 0x43
@ -87,7 +89,7 @@ namespace upm {
* *
* @snippet hdc1000.cxx Interesting * @snippet hdc1000.cxx Interesting
*/ */
class HDC1000 { class HDC1000 : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
* Instantiates an HDC1000 object * Instantiates an HDC1000 object
@ -123,7 +125,14 @@ class HDC1000 {
* @param bSampleData Flag to read sensor * @param bSampleData Flag to read sensor
* @return The humidity sensor temp in degC * @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] * Get the humidity cell temperature [degC]
@ -131,7 +140,14 @@ class HDC1000 {
* @param bSampleData Flag to read sensor * @param bSampleData Flag to read sensor
* @return The humidity sensor temp in degC * @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: private:

View File

@ -190,7 +190,8 @@ float HP20X::getPressure()
// now read the pressure // now read the pressure
writeCmd(CMD_READ_P); writeCmd(CMD_READ_P);
return ((float)readData() / 100.0); // Return result in Pa, not milibars.
return (float)readData();
} }
float HP20X::getAltitude() float HP20X::getAltitude()

View File

@ -26,6 +26,8 @@
#include <string> #include <string>
#include <mraa/common.hpp> #include <mraa/common.hpp>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <interfaces/iPressure.hpp>
#include <interfaces/iTemperature.hpp>
#define HP20X_I2C_BUS 0 #define HP20X_I2C_BUS 0
#define HP20X_DEFAULT_I2C_ADDR 0x76 #define HP20X_DEFAULT_I2C_ADDR 0x76
@ -61,7 +63,7 @@ namespace upm {
* @image html hp20x.jpg * @image html hp20x.jpg
* @snippet hp20x.cxx Interesting * @snippet hp20x.cxx Interesting
*/ */
class HP20X { class HP20X : virtual public iPressure, virtual public iTemperature {
public: public:
/** /**
@ -270,14 +272,14 @@ namespace upm {
* *
* @return Temperature * @return Temperature
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* Returns the pressure in millibars * Returns the pressure in millibars
* *
* @return Pressure * @return Pressure
*/ */
float getPressure(); virtual float getPressure();
/** /**
* Returns the computed altitude in meters * Returns the computed altitude in meters

View File

@ -99,6 +99,12 @@ HTU21D::getTemperature(int bSampleData)
return (float)m_temperature / 1000; return (float)m_temperature / 1000;
} }
float
HTU21D::getTemperature()
{
return getTemperature(0);
}
float float
HTU21D::getHumidity(int bSampleData) HTU21D::getHumidity(int bSampleData)
{ {
@ -108,6 +114,12 @@ HTU21D::getHumidity(int bSampleData)
return (float)m_humidity / 1000; return (float)m_humidity / 1000;
} }
float
HTU21D::getHumidity()
{
return getHumidity(0);
}
/* /*
* Use the compensation equation from the datasheet to correct the * Use the compensation equation from the datasheet to correct the
* current reading * current reading

View File

@ -26,6 +26,8 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <math.h> #include <math.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#define HTU21D_NAME "htu21d" #define HTU21D_NAME "htu21d"
#define HTU21D_I2C_ADDRESS 0x40 #define HTU21D_I2C_ADDRESS 0x40
@ -79,7 +81,7 @@ namespace upm {
* @image html htu21d.jpeg * @image html htu21d.jpeg
* @snippet htu21d.cxx Interesting * @snippet htu21d.cxx Interesting
*/ */
class HTU21D { class HTU21D : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
* Instantiates an HTU21D object * Instantiates an HTU21D object
@ -102,7 +104,14 @@ class HTU21D {
* @param bSampleData Flag to sample sensor (default false) * @param bSampleData Flag to sample sensor (default false)
* @return Relative humidity in %RH * @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] * Gets the humidity cell temperature [degC]
@ -110,7 +119,14 @@ class HTU21D {
* @param bSampleData Flag to sample sensor (default false) * @param bSampleData Flag to sample sensor (default false)
* @return Temperature in degC * @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 * Using the current humidity and temperature, the function

View File

@ -263,6 +263,11 @@ float HWXPXX::getTemperature(bool fahrenheit)
return m_temperature; return m_temperature;
} }
float HWXPXX::getTemperature()
{
return getTemperature(false);
}
float HWXPXX::getHumidity() float HWXPXX::getHumidity()
{ {
return m_humidity; return m_humidity;

View File

@ -26,6 +26,8 @@
#include <string> #include <string>
#include <modbus/modbus.h> #include <modbus/modbus.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -64,7 +66,7 @@ namespace upm {
* @snippet hwxpxx.cxx Interesting * @snippet hwxpxx.cxx Interesting
*/ */
class HWXPXX { class HWXPXX : virtual public iHumidity, virtual public iTemperature {
public: public:
// MODBUS input registers // MODBUS input registers
typedef enum { typedef enum {
@ -128,7 +130,17 @@ namespace upm {
* The default is false (degrees Celsius). * The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit * @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 * Get the current relative humidity. update() must have been called
@ -136,7 +148,7 @@ namespace upm {
* *
* @return The last humidity reading * @return The last humidity reading
*/ */
float getHumidity(); virtual float getHumidity();
/** /**
* Get the current slider switch position. update() must have * Get the current slider switch position. update() must have

View File

@ -55,6 +55,11 @@ uint16_t IMS::get_moisture()
return retval; return retval;
} }
int IMS::getMoisture()
{
return get_moisture();
}
uint16_t IMS::get_light() uint16_t IMS::get_light()
{ {
uint16_t retval; uint16_t retval;
@ -73,6 +78,11 @@ float IMS::get_temperature()
return static_cast<float>(retval)/10.0; return static_cast<float>(retval)/10.0;
} }
float IMS::getTemperature()
{
return get_temperature();
}
void IMS::reset_i2c_address(uint8_t address_new) void IMS::reset_i2c_address(uint8_t address_new)
{ {
if (ims_reset_i2c_address(_dev, address_new) != UPM_SUCCESS) if (ims_reset_i2c_address(_dev, address_new) != UPM_SUCCESS)

View File

@ -24,6 +24,8 @@
#pragma once #pragma once
#include <interfaces/iMoisture.hpp>
#include <interfaces/iTemperature.hpp>
#include "ims.h" #include "ims.h"
namespace upm { namespace upm {
@ -55,7 +57,7 @@ namespace upm {
* @snippet ims.cxx Interesting * @snippet ims.cxx Interesting
*/ */
class IMS { class IMS : virtual public iMoisture, virtual public iTemperature {
public: public:
/** /**
* I2C Moisture Sensor constructor * I2C Moisture Sensor constructor
@ -103,6 +105,13 @@ class IMS {
*/ */
uint16_t get_moisture(); 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 * Get light reading from LED on device. The technical data for the I2C
* moisture sensor specifies a 3 second wait. Loop for 3 seconds * moisture sensor specifies a 3 second wait. Loop for 3 seconds
@ -122,6 +131,13 @@ class IMS {
*/ */
float get_temperature(); 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 * Reset sensor
* @throws std::runtime_error if I2C write command fails * @throws std::runtime_error if I2C write command fails

View File

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <interfaces/iDistance.hpp>
#define ADDR 0x62 // device address #define ADDR 0x62 // device address
@ -87,7 +88,7 @@ namespace upm {
* *
* @snippet lidarlitev3.cxx Interesting * @snippet lidarlitev3.cxx Interesting
*/ */
class LIDARLITEV3 { class LIDARLITEV3 : virtual public iDistance {
public: public:
/** /**
* Instantiates an LIDARLITEV3 object * Instantiates an LIDARLITEV3 object
@ -109,7 +110,7 @@ class LIDARLITEV3 {
* Returns distance measurement on success * Returns distance measurement on success
* Retruns -1 on failure. * Retruns -1 on failure.
*/ */
int getDistance (); virtual int getDistance ();
/** /**
* Read * Read

View File

@ -57,6 +57,17 @@ int Light::value()
return (int)roundf(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() float Light::raw_value()
{ {
// This is a hack. Deprecated. Should be removed ASAP. // This is a hack. Deprecated. Should be removed ASAP.

View File

@ -28,6 +28,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <interfaces/iLight.hpp>
#include "light.h" #include "light.h"
@ -58,7 +59,7 @@ namespace upm {
* @image html light.jpg * @image html light.jpg
* @snippet light.cxx Interesting * @snippet light.cxx Interesting
*/ */
class Light { class Light : virtual public iLight {
public: public:
/** /**
* Analog light sensor constructor * Analog light sensor constructor
@ -91,6 +92,14 @@ namespace upm {
*/ */
int value(); 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 * Set ADC reference voltage
* *

View File

@ -26,6 +26,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "lm35.h" #include "lm35.h"
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
/** /**
@ -58,7 +59,7 @@ namespace upm {
* @snippet lm35.cxx Interesting * @snippet lm35.cxx Interesting
*/ */
class LM35 { class LM35 : virtual public iTemperature {
public: public:
/** /**
@ -79,7 +80,7 @@ namespace upm {
* *
* @return The Temperature in degrees Celsius * @return The Temperature in degrees Celsius
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* Set sensor scale. This scale is applied to the return values * Set sensor scale. This scale is applied to the return values

View File

@ -49,7 +49,7 @@ MAX31723::MAX31723 (int bus, int csn) : m_spi(bus), m_csnPinCtx(csn) {
writeRegister (R_STS_WRITE_CMD, B_CONT_READING); writeRegister (R_STS_WRITE_CMD, B_CONT_READING);
} }
short float
MAX31723::getTemperature () { MAX31723::getTemperature () {
uint8_t msb = 0; uint8_t msb = 0;
short temperature = 0; short temperature = 0;

View File

@ -29,6 +29,7 @@
#include <mraa/gpio.hpp> #include <mraa/gpio.hpp>
#include <mraa/spi.hpp> #include <mraa/spi.hpp>
#include <interfaces/iTemperature.hpp>
#define HIGH 1 #define HIGH 1
#define LOW 0 #define LOW 0
@ -60,7 +61,7 @@ namespace upm {
* *
* @snippet max31723.cxx Interesting * @snippet max31723.cxx Interesting
*/ */
class MAX31723 { class MAX31723 : virtual public iTemperature {
public: public:
static const uint8_t R_STS_READ_CMD = 0x00; static const uint8_t R_STS_READ_CMD = 0x00;
static const uint8_t R_STS_WRITE_CMD = 0x80; 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 * Returns the name of the component

View File

@ -41,7 +41,7 @@ MAX44009::MAX44009 (int bus, int devAddr) {
status = mraa::SUCCESS; status = mraa::SUCCESS;
reset(); reset();
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
UPM_THROW("config failure"); throw std::runtime_error(std::string(__FUNCTION__) + ": config failure");
} }
MAX44009::~MAX44009() { MAX44009::~MAX44009() {
@ -70,7 +70,7 @@ MAX44009::getVisibleRaw() {
int length = i2c->readBytesReg(MAX44009_LUX_START_ADDR, data, MAX44009_LUX_LENGTH); int length = i2c->readBytesReg(MAX44009_LUX_START_ADDR, data, MAX44009_LUX_LENGTH);
if(length != MAX44009_LUX_LENGTH) if(length != MAX44009_LUX_LENGTH)
UPM_THROW("Read error"); throw std::runtime_error(std::string(__FUNCTION__) + ": Read error");
return *value; return *value;
} }
@ -86,8 +86,12 @@ MAX44009::getVisibleLux() {
// Check for overrange condition // Check for overrange condition
if(exponent == MAX44009_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; return pow((double)2,(double)exponent) * mantissa * 0.045;
} }
float
MAX44009::getLuminance() {
return getVisibleLux();
}

View File

@ -26,7 +26,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include "interfaces/iLightSensor.hpp" #include <interfaces/iLight.hpp>
/* ADDRESS AND NOT_FOUND VALUE */ /* ADDRESS AND NOT_FOUND VALUE */
#define MAX44009_ADDRESS ( 0x4A ) #define MAX44009_ADDRESS ( 0x4A )
@ -106,7 +106,7 @@ namespace upm {
* @snippet max44009.cxx Interesting * @snippet max44009.cxx Interesting
* *
*/ */
class MAX44009 : public ILightSensor { class MAX44009 : virtual public iLight {
public: public:
/** /**
* Instanciates a MAX44009 object * Instanciates a MAX44009 object
@ -131,6 +131,13 @@ class MAX44009 : public ILightSensor {
*/ */
double getVisibleLux(); 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"; } virtual const char* getModuleName() { return "max44009"; }
private: private:

View File

@ -2,11 +2,6 @@
/* BEGIN Java syntax ------------------------------------------------------- */ /* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA #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) JAVA_JNI_LOADLIBRARY(javaupm_max44009)
#endif #endif
/* END Java syntax */ /* END Java syntax */

View File

@ -62,3 +62,9 @@ int MAXSONAREZ::inches()
return int(volts / m_vI); return int(volts / m_vI);
} }
int MAXSONAREZ::getDistance()
{
// TODO: call static conversion first.
return inches();
}

View File

@ -26,6 +26,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <mraa/aio.h> #include <mraa/aio.h>
#include <interfaces/iDistance.hpp>
// EZ series is volts/512 // EZ series is volts/512
#define MAXSONAREZ_RES 512 #define MAXSONAREZ_RES 512
@ -67,7 +68,7 @@ namespace upm {
* @snippet maxsonarez.cxx Interesting * @snippet maxsonarez.cxx Interesting
*/ */
class MAXSONAREZ { class MAXSONAREZ : virtual public iDistance {
public: public:
/** /**
@ -90,6 +91,13 @@ namespace upm {
*/ */
int inches(); int inches();
/**
* Gets the distance to the object in inches
*
* @return Distance to the object in inches
*/
virtual int getDistance();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
float m_aref; float m_aref;

View File

@ -47,3 +47,8 @@ int MB704X::getRange()
{ {
return mb704x_get_range(m_mb704x); return mb704x_get_range(m_mb704x);
} }
int MB704X::getDistance()
{
return getRange();
}

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <interfaces/iDistance.hpp>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -58,7 +59,7 @@ namespace upm {
* @snippet mb704x.cxx Interesting * @snippet mb704x.cxx Interesting
*/ */
class MB704X { class MB704X : virtual public iDistance {
public: public:
/** /**
@ -84,7 +85,12 @@ namespace upm {
*/ */
int getRange(); int getRange();
/**
* Gets the distance to the object in cm
*
* @return Distance to the object in cm
*/
virtual int getDistance();
protected: protected:
// mb704x device context // mb704x device context
mb704x_context m_mb704x; mb704x_context m_mb704x;

View File

@ -67,6 +67,11 @@ MCP9808::getTemp(){
return getTempValue(result); return getTempValue(result);
} }
float
MCP9808::getTemperature() {
return getTemp();
}
void void
MCP9808::shutDown(bool sleep){ MCP9808::shutDown(bool sleep){
if(sleep) this->updateConfigRegister(MCP9808_CONFIG_SHUTDOWN); if(sleep) this->updateConfigRegister(MCP9808_CONFIG_SHUTDOWN);

View File

@ -28,6 +28,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <interfaces/iTemperature.hpp>
#define MCP9808_REG_CONFIG 0x01 #define MCP9808_REG_CONFIG 0x01
#define MCP9808_REG_AMBIENT_TEMP 0x05 #define MCP9808_REG_AMBIENT_TEMP 0x05
@ -75,7 +76,7 @@ namespace upm {
* @image html mcp9808.jpg * @image html mcp9808.jpg
* @snippet mcp9808.cxx Interesting * @snippet mcp9808.cxx Interesting
*/ */
class MCP9808 { class MCP9808 : virtual public iTemperature {
public: public:
/** /**
@ -177,6 +178,13 @@ namespace upm {
*/ */
float getTemp(void); 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. * Will cause the devices to either sleep or wakeup.
* *

View File

@ -70,6 +70,11 @@ MLX90614::readAmbientTempC(void) {
return readTemperature(MLX90614_TA); return readTemperature(MLX90614_TA);
} }
float
MLX90614::getTemperature() {
return readAmbientTempC();
}
/* /*
* ************** * **************
* private area * private area

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <interfaces/iTemperature.hpp>
#define DEVICE_ADDR 0x5A // device address #define DEVICE_ADDR 0x5A // device address
@ -73,7 +74,7 @@ namespace upm {
* @image html mlx90614.jpg * @image html mlx90614.jpg
* @snippet mlx90614.cxx Interesting * @snippet mlx90614.cxx Interesting
*/ */
class MLX90614 { class MLX90614 : virtual public iTemperature {
public: public:
/** /**
@ -109,6 +110,13 @@ class MLX90614 {
*/ */
float readAmbientTempC(void); float readAmbientTempC(void);
/**
* Returns the temperature in degrees Celsius
*
* @return The Temperature in degrees Celsius
*/
virtual float getTemperature();
/** /**
* Returns the name of the component * Returns the name of the component
*/ */

View File

@ -46,3 +46,8 @@ int Moisture::value()
{ {
return mraa_aio_read(m_aio); return mraa_aio_read(m_aio);
} }
int Moisture::getMoisture()
{
return value();
}

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/aio.h> #include <mraa/aio.h>
#include <interfaces/iMoisture.hpp>
namespace upm { namespace upm {
/** /**
@ -55,7 +56,7 @@ namespace upm {
* @image html moisture.jpg * @image html moisture.jpg
* @snippet moisture.cxx Interesting * @snippet moisture.cxx Interesting
*/ */
class Moisture { class Moisture : virtual public iMoisture {
public: public:
/** /**
* Analog moisture sensor constructor * Analog moisture sensor constructor
@ -74,6 +75,13 @@ namespace upm {
*/ */
int value(); int value();
/**
* Gets the moisture value from the sensor
*
* @return Moisture reading
*/
virtual int getMoisture();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
}; };

View File

@ -207,6 +207,11 @@ MPL3115A2::getPressure(int bSampleData) {
return (float)m_iPressure / 100; return (float)m_iPressure / 100;
} }
float
MPL3115A2::getPressure() {
return getPressure(true);
}
float float
MPL3115A2::getTemperature(int bSampleData) { MPL3115A2::getTemperature(int bSampleData) {
int ret; int ret;

View File

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <math.h> #include <math.h>
#include <interfaces/iPressure.hpp>
#define MPL3115A2_NAME "mpl3115a2" #define MPL3115A2_NAME "mpl3115a2"
@ -79,7 +80,7 @@ namespace upm {
* @image html mpl3115a2.jpg * @image html mpl3115a2.jpg
* @snippet mpl3115a2.cxx Interesting * @snippet mpl3115a2.cxx Interesting
*/ */
class MPL3115A2 { class MPL3115A2 : virtual public iPressure {
public: public:
/** /**
* Instantiates an MPL3115A2 object * Instantiates an MPL3115A2 object
@ -141,7 +142,14 @@ class MPL3115A2 {
* *
* @param bSampleData Sets non-zero to a sample reading * @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] * Reads the current temperature value from MPL3115A2 [degC]

View File

@ -58,13 +58,13 @@ MS5611::MS5611(int i2cBus, int address)
i2c->address(address); i2c->address(address);
prom = new uint16_t[MS5611_PROM_SIZE]; prom = new uint16_t[MS5611_PROM_SIZE];
if (i2c->writeByte(MS5611_CMD_RESET != mraa::SUCCESS)) if (i2c->writeByte(MS5611_CMD_RESET != mraa::SUCCESS))
UPM_THROW("Reset failed."); throw std::runtime_error(std::string(__FUNCTION__) + ": Reset failed.");
delayms(5); delayms(5);
for (int i = 0; i < MS5611_PROM_SIZE; ++i) { for (int i = 0; i < MS5611_PROM_SIZE; ++i) {
uint8_t buf[2]; uint8_t buf[2];
int bytesRead = i2c->readBytesReg(MS5611_CMD_READ_PROM + 2*i, buf, 2); int bytesRead = i2c->readBytesReg(MS5611_CMD_READ_PROM + 2*i, buf, 2);
if (bytesRead != 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[0] << 8;
prom[i] |= buf[1]; prom[i] |= buf[1];
// printf("Read PROM entry %d = %04x\n", i, prom[i]); // 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()); // printf("CRC = %X\n", promCrc4());
if (promCrc4() != (prom[7] & 0x000F)) if (promCrc4() != (prom[7] & 0x000F))
UPM_THROW("PROM checksum error."); throw std::runtime_error(std::string(__FUNCTION__) + ": PROM checksum error.");
setOverSampling(ULTRA_HIGH_RES); setOverSampling(ULTRA_HIGH_RES);
} }
@ -153,11 +153,11 @@ uint32_t MS5611::readADC(int adcReg)
uint32_t value; uint32_t value;
uint8_t buf[3]; uint8_t buf[3];
if (i2c->writeByte(adcReg + osr) != mraa::SUCCESS) if (i2c->writeByte(adcReg + osr) != mraa::SUCCESS)
UPM_THROW("Convert D2 failed"); throw std::runtime_error(std::string(__FUNCTION__) + ": Convert D2 failed");
delayms(100); delayms(100);
int bytesRead = i2c->readBytesReg(MS5611_CMD_ADC_READ, buf, 3); int bytesRead = i2c->readBytesReg(MS5611_CMD_ADC_READ, buf, 3);
if (bytesRead != 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]); // printf("%02X%02X%02X\n", buf[0], buf[1], buf[2]);
value = ((uint32_t)buf[0] << 16) | ((uint32_t)buf[1] << 8) | buf[2]; value = ((uint32_t)buf[0] << 16) | ((uint32_t)buf[1] << 8) | buf[2];
return value; return value;
@ -181,6 +181,11 @@ int MS5611::getTemperatureCelsius()
return (temp + 50) / 100; return (temp + 50) / 100;
} }
float MS5611::getTemperature()
{
return getTemperatureCelsius();
}
int MS5611::getPressurePa() int MS5611::getPressurePa()
{ {
@ -208,3 +213,7 @@ int MS5611::getPressurePa()
return pressure; return pressure;
} }
float MS5611::getPressure()
{
return getPressurePa();
}

View File

@ -22,8 +22,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "interfaces/iPressureSensor.hpp" #include <interfaces/iPressure.hpp>
#include "interfaces/iTemperatureSensor.hpp" #include <interfaces/iTemperature.hpp>
#include "mraa/i2c.hpp" #include "mraa/i2c.hpp"
namespace upm namespace upm
@ -58,7 +58,7 @@ namespace upm
* @snippet ms5611.cxx Interesting * @snippet ms5611.cxx Interesting
*/ */
class MS5611 : public IPressureSensor, public ITemperatureSensor class MS5611 : virtual public iPressure, virtual public iTemperature
{ {
public: public:
enum OsrMode enum OsrMode
@ -71,8 +71,22 @@ public:
virtual const char* getModuleName() { return "ms5611"; } virtual const char* getModuleName() { return "ms5611"; }
void setOverSampling(OsrMode osrMode); void setOverSampling(OsrMode osrMode);
int getTemperatureCelsius(); int getTemperatureCelsius();
/**
* Returns the temperature in degrees Celsius
*
* @return The Temperature in degrees Celsius
*/
virtual float getTemperature();
int getPressurePa(); int getPressurePa();
/**
* Return the current measured pressure in Pascals (Pa).
*
* @return The pressure in Pascals (Pa).
*/
virtual float getPressure();
private: private:
/* Disable implicit copy and assignment operators */ /* Disable implicit copy and assignment operators */
MS5611(const MS5611&) = delete; MS5611(const MS5611&) = delete;

View File

@ -2,10 +2,6 @@
/* BEGIN Java syntax ------------------------------------------------------- */ /* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA #ifdef SWIGJAVA
%import "../interfaces/javaupm_iTemperatureSensor.i"
%import "../interfaces/javaupm_iPressureSensor.i"
%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%}
JAVA_JNI_LOADLIBRARY(javaupm_ms5611) JAVA_JNI_LOADLIBRARY(javaupm_ms5611)
#endif #endif
/* END Java syntax */ /* END Java syntax */

View File

@ -77,7 +77,7 @@ float MS5803::getTemperature()
float MS5803::getPressure() float MS5803::getPressure()
{ {
return ms5803_get_pressure(m_ms5803); return (ms5803_get_pressure(m_ms5803) * 100);
} }
void MS5803::loadCoefficients() void MS5803::loadCoefficients()

View File

@ -24,6 +24,8 @@
#pragma once #pragma once
#include <string> #include <string>
#include <interfaces/iPressure.hpp>
#include <interfaces/iTemperature.hpp>
#include "ms5803.h" #include "ms5803.h"
@ -64,7 +66,7 @@ namespace upm {
* *
* @snippet ms5803.cxx Interesting * @snippet ms5803.cxx Interesting
*/ */
class MS5803 { class MS5803 : virtual public iPressure, virtual public iTemperature {
public: public:
/** /**
@ -130,7 +132,7 @@ namespace upm {
* *
* @return Temperature in degrees C * @return Temperature in degrees C
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* Return the latest measured pressure. update() must have * Return the latest measured pressure. update() must have
@ -139,7 +141,7 @@ namespace upm {
* *
* @return Pressure in mbar * @return Pressure in mbar
*/ */
float getPressure(); virtual float getPressure();
protected: protected:
ms5803_context m_ms5803; ms5803_context m_ms5803;

View File

@ -55,6 +55,11 @@ float OTP538U::ambientTemperature()
return temp; return temp;
} }
float OTP538U::getTemperature()
{
return ambientTemperature();
}
float OTP538U::objectTemperature() float OTP538U::objectTemperature()
{ {
float temp = 0; float temp = 0;

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <otp538u.h> #include <otp538u.h>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -73,7 +74,7 @@ namespace upm {
* @image html otp538u.jpg * @image html otp538u.jpg
* @snippet otp538u.cxx Interesting * @snippet otp538u.cxx Interesting
*/ */
class OTP538U { class OTP538U : virtual public iTemperature {
public: public:
/** /**
* OTP538U constructor * OTP538U constructor
@ -96,6 +97,13 @@ namespace upm {
*/ */
float ambientTemperature(); float ambientTemperature();
/**
* Gets the ambient temperature in Celsius
*
* @return Ambient temperature
*/
virtual float getTemperature();
/** /**
* Gets the object temperature in Celsius * Gets the object temperature in Celsius
* *

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <mraa/gpio.h> #include <mraa/gpio.h>
#include <interfaces/iDistanceInterrupter.hpp>
namespace upm { namespace upm {
@ -53,7 +54,7 @@ namespace upm {
* @image html rfr359f.jpg * @image html rfr359f.jpg
* @snippet rfr359f.cxx Interesting * @snippet rfr359f.cxx Interesting
*/ */
class RFR359F { class RFR359F : virtual public iDistanceInterrupter {
public: public:
/** /**
* RFR359F constructor * RFR359F constructor
@ -72,7 +73,7 @@ namespace upm {
* *
* @return True if the sensor has detected an object * @return True if the sensor has detected an object
*/ */
bool objectDetected(); virtual bool objectDetected();
private: private:
mraa_gpio_context m_gpio; mraa_gpio_context m_gpio;

View File

@ -99,6 +99,11 @@ float RHUSB::getTemperature(bool fahrenheit)
return m_temperature; return m_temperature;
} }
float RHUSB::getTemperature()
{
return getTemperature(false);
}
float RHUSB::getHumidity() float RHUSB::getHumidity()
{ {
return m_humidity; return m_humidity;

View File

@ -25,6 +25,8 @@
#include <string> #include <string>
#include <mraa/uart.hpp> #include <mraa/uart.hpp>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -53,7 +55,7 @@ namespace upm {
* @snippet rhusb.cxx Interesting * @snippet rhusb.cxx Interesting
*/ */
class RHUSB { class RHUSB : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
* RHUSB constructor * RHUSB constructor
@ -83,7 +85,15 @@ namespace upm {
* The default is false (degrees Celsius). * The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit * @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 * Get the current relative humidity. update() must have been called
@ -91,7 +101,7 @@ namespace upm {
* *
* @return The last humidity reading * @return The last humidity reading
*/ */
float getHumidity(); virtual float getHumidity();
/** /**
* Get the firmware identification string. * Get the firmware identification string.

View File

@ -166,9 +166,10 @@ float RSC::getTemperature()
return rsc_get_temperature(m_rsc); return rsc_get_temperature(m_rsc);
} }
#define INH20_TO_PA 248.84
float RSC::getPressure() float RSC::getPressure()
{ {
return rsc_get_pressure(m_rsc); return rsc_get_pressure(m_rsc) * INH20_TO_PA;
} }
void RSC::setMode(RSC_MODE mode) void RSC::setMode(RSC_MODE mode)

View File

@ -26,6 +26,8 @@
#include "rsc.h" #include "rsc.h"
#include <string> #include <string>
#include <interfaces/iPressure.hpp>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
/** /**
@ -74,7 +76,7 @@ namespace upm {
* *
* @snippet rsc.cxx Interesting * @snippet rsc.cxx Interesting
*/ */
class RSC { class RSC : virtual public iPressure, virtual public iTemperature {
public: public:
/** /**
@ -194,14 +196,14 @@ namespace upm {
* *
* @return float compensated temperature value * @return float compensated temperature value
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* Function to get the compensated pressure value * Function to get the compensated pressure value
* *
* @return float compensated pressure value * @return float compensated pressure value
*/ */
float getPressure(); virtual float getPressure();
/** /**
* Function to set the mode for the RSC sensor: * Function to set the mode for the RSC sensor:

View File

@ -28,6 +28,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#include "sht1x.h" #include "sht1x.h"
@ -58,7 +60,7 @@ namespace upm {
* @snippet sht1x.cxx Interesting * @snippet sht1x.cxx Interesting
*/ */
class SHT1X { class SHT1X : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
@ -91,7 +93,7 @@ namespace upm {
* *
* @return The temperature in Celsius * @return The temperature in Celsius
*/ */
float getTemperature(); virtual float getTemperature();
/** /**
* Query the relative humidity. update() must have been called * Query the relative humidity. update() must have been called
@ -99,7 +101,7 @@ namespace upm {
* *
* @return The relative humidity. * @return The relative humidity.
*/ */
float getHumidity(); virtual float getHumidity();
/** /**
* Read the status register. * Read the status register.

View File

@ -81,7 +81,7 @@ SI1132::SI1132 (int bus) {
// Reset chip to defaults // Reset chip to defaults
status = reset(); status = reset();
if (status != mraa::SUCCESS) if (status != mraa::SUCCESS)
UPM_THROW("config failure"); throw std::runtime_error(std::string(__FUNCTION__) + ": config failure");
} }
SI1132::~SI1132() { SI1132::~SI1132() {
@ -138,7 +138,7 @@ mraa::Result SI1132::reset() {
uint16_t SI1132::getVisibleRaw() { uint16_t SI1132::getVisibleRaw() {
status = runCommand(SI1132_COMMAND_ALS_FORCE); status = runCommand(SI1132_COMMAND_ALS_FORCE);
if (status != mraa::SUCCESS) 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); return i2c->readWordReg(SI1132_REG_ALS_VIS_DATA0);
} }
@ -152,6 +152,9 @@ double SI1132::getVisibleLux() {
return static_cast<double>(rawValue); return static_cast<double>(rawValue);
} }
float SI1132::getLuminance() {
return getVisibleLux();
}
mraa::Result SI1132::clearResponseRegister() mraa::Result SI1132::clearResponseRegister()
{ {

View File

@ -25,7 +25,7 @@
#include <string> #include <string>
#include "mraa/i2c.hpp" #include "mraa/i2c.hpp"
#include "interfaces/iLightSensor.hpp" #include <interfaces/iLight.hpp>
namespace upm { namespace upm {
@ -56,7 +56,7 @@ namespace upm {
* *
* @snippet si1132.cxx Interesting * @snippet si1132.cxx Interesting
*/ */
class SI1132 : public ILightSensor { class SI1132 : virtual public iLight {
public: public:
/** /**
* Instanciates a Si1132 object * Instanciates a Si1132 object
@ -80,6 +80,13 @@ class SI1132 : public ILightSensor {
*/ */
double getVisibleLux(); 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"; } virtual const char* getModuleName() { return "si1132"; }
private: private:

View File

@ -82,7 +82,7 @@ SI7005::SI7005 (int bus, int pin) {
m_i2c = new mraa::I2c(m_bus); m_i2c = new mraa::I2c(m_bus);
status = m_i2c->address(m_controlAddr); status = m_i2c->address(m_controlAddr);
if (!isAvailable()) if (!isAvailable())
UPM_THROW("config failure"); throw std::runtime_error(std::string(__FUNCTION__) + ": config failure");
} }
SI7005::~SI7005() { SI7005::~SI7005() {
@ -102,6 +102,11 @@ SI7005::getTemperatureCelsius () {
return static_cast<int>(last_temperature + 0.5); return static_cast<int>(last_temperature + 0.5);
} }
float
SI7005::getTemperature() {
return getTemperatureCelsius();
}
uint16_t uint16_t
SI7005::getHumidityRaw () { SI7005::getHumidityRaw () {
return getMeasurement( SI7005_CONFIG_HUMIDITY ); return getMeasurement( SI7005_CONFIG_HUMIDITY );
@ -117,6 +122,10 @@ SI7005::getHumidityRelative () {
return static_cast<int>(linearHumidity + 0.5); return static_cast<int>(linearHumidity + 0.5);
} }
float
SI7005::getHumidity () {
return getHumidityRelative();
}
uint16_t SI7005::getMeasurement(uint8_t configValue) { 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 // Check we got the data we need
if(length != SI7005_REG_DATA_LENGTH) if(length != SI7005_REG_DATA_LENGTH)
UPM_THROW("read error"); throw std::runtime_error(std::string(__FUNCTION__) + ": read error");
// Merge MSB and LSB // Merge MSB and LSB
rawData = ((uint16_t)( data[SI7005_REG_DATA_LOW] & 0xFFFF )) + ( (uint16_t)(( data[SI7005_REG_DATA_HIGH] & 0xFFFF ) << 8 )); rawData = ((uint16_t)( data[SI7005_REG_DATA_LOW] & 0xFFFF )) + ( (uint16_t)(( data[SI7005_REG_DATA_HIGH] & 0xFFFF ) << 8 ));

View File

@ -25,8 +25,8 @@
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include "interfaces/iTemperatureSensor.hpp" #include <interfaces/iTemperature.hpp>
#include "interfaces/iHumiditySensor.hpp" #include <interfaces/iHumidity.hpp>
/* ADDRESS AND NOT_FOUND VALUE */ /* ADDRESS AND NOT_FOUND VALUE */
#define SI7005_ADDRESS ( 0x40 ) #define SI7005_ADDRESS ( 0x40 )
@ -59,7 +59,7 @@ namespace upm {
* *
* @snippet si7005.cxx Interesting * @snippet si7005.cxx Interesting
*/ */
class SI7005 : public ITemperatureSensor, public IHumiditySensor { class SI7005 : virtual public iTemperature, virtual public iHumidity {
public: public:
/** /**
* Instantiates a SI7005 object * Instantiates a SI7005 object
@ -84,6 +84,13 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
*/ */
int getTemperatureCelsius (); int getTemperatureCelsius ();
/**
* Get the current temperature.
*
* @return The last temperature reading in Celsius
*/
virtual float getTemperature();
/** /**
* Get relative humidity measurement. * Get relative humidity measurement.
*/ */
@ -94,6 +101,13 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
*/ */
int getHumidityRelative (); int getHumidityRelative ();
/**
* Get the current relative humidity.
*
* @return The last humidity reading
*/
virtual float getHumidity();
/** /**
* Returns sensor module name * Returns sensor module name
*/ */

View File

@ -2,13 +2,6 @@
/* BEGIN Java syntax ------------------------------------------------------- */ /* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA #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) JAVA_JNI_LOADLIBRARY(javaupm_si7005)
#endif #endif
/* END Java syntax */ /* END Java syntax */

View File

@ -259,6 +259,11 @@ float T3311::getTemperature(bool fahrenheit)
return m_temperature; return m_temperature;
} }
float T3311::getTemperature()
{
return getTemperature(false);
}
float T3311::getHumidity() float T3311::getHumidity()
{ {
return m_humidity; return m_humidity;

View File

@ -26,6 +26,8 @@
#include <string> #include <string>
#include <modbus/modbus.h> #include <modbus/modbus.h>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
@ -60,7 +62,7 @@ namespace upm {
* @snippet t3311.cxx Interesting * @snippet t3311.cxx Interesting
*/ */
class T3311 { class T3311 : virtual public iHumidity, virtual public iTemperature {
public: public:
// MODBUS input registers // MODBUS input registers
@ -148,7 +150,15 @@ namespace upm {
* The default is false (degrees Celsius). * The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit * @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 * Get the current relative humidity. update() must have been called
@ -156,7 +166,7 @@ namespace upm {
* *
* @return The last humidity reading * @return The last humidity reading
*/ */
float getHumidity(); virtual float getHumidity();
/** /**
* Get the current computed value. update() must have been * Get the current computed value. update() must have been

View File

@ -112,6 +112,11 @@ float TEAMS::getTemperature(bool fahrenheit)
return m_temperature; return m_temperature;
} }
float TEAMS::getTemperature()
{
return getTemperature(false);
}
int TEAMS::average(int samples) int TEAMS::average(int samples)
{ {
if (samples <= 0) if (samples <= 0)

View File

@ -27,6 +27,7 @@
#include <iostream> #include <iostream>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
#include <interfaces/iTemperature.hpp>
// Unlikey to be changable // Unlikey to be changable
#define TEAMS_DEFAULT_AREF 5.0 #define TEAMS_DEFAULT_AREF 5.0
@ -66,7 +67,7 @@ namespace upm {
* @snippet teams.cxx Interesting * @snippet teams.cxx Interesting
*/ */
class TEAMS { class TEAMS : virtual public iTemperature {
public: public:
/** /**
@ -104,7 +105,15 @@ namespace upm {
* The default is false (degrees Celsius). * The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit * @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 * When using a direct 4-20ma interface (rResistor supplied in the

View File

@ -62,6 +62,11 @@ int Temperature::value ()
return (int) round(t); return (int) round(t);
} }
float Temperature::getTemperature ()
{
return value();
}
float Temperature::raw_value() float Temperature::raw_value()
{ {
return (float) mraa_aio_read(m_aio); return (float) mraa_aio_read(m_aio);

View File

@ -28,6 +28,7 @@
#include <string> #include <string>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
#include <interfaces/iTemperature.hpp>
namespace upm { namespace upm {
/** /**
@ -58,7 +59,7 @@ namespace upm {
* @image html temp.jpg * @image html temp.jpg
* @snippet temperature.cxx Interesting * @snippet temperature.cxx Interesting
*/ */
class Temperature { class Temperature : virtual public iTemperature {
public: public:
/** /**
* Analog temperature sensor constructor * Analog temperature sensor constructor
@ -96,6 +97,13 @@ class Temperature {
* @return Normalized temperature in Celsius * @return Normalized temperature in Celsius
*/ */
int value(); int value();
/**
* Gets the temperature in Celsius from the sensor
*
* @return Normalized temperature in Celsius
*/
virtual float getTemperature();
private: private:
mraa_aio_context m_aio; mraa_aio_context m_aio;
float m_scale; float m_scale;

View File

@ -141,6 +141,11 @@ float TEX00::getTemperature(bool fahrenheit)
return m_temperature; return m_temperature;
} }
float TEX00::getTemperature()
{
return getTemperature(false);
}
int TEX00::average(int samples) int TEX00::average(int samples)
{ {
if (samples <= 0) if (samples <= 0)

View File

@ -28,6 +28,7 @@
#include <vector> #include <vector>
#include <mraa/aio.hpp> #include <mraa/aio.hpp>
#include <interfaces/iTemperature.hpp>
#define TEX00_DEFAULT_AREF 5.0 #define TEX00_DEFAULT_AREF 5.0
@ -74,7 +75,7 @@ namespace upm {
* @snippet tex00.cxx Interesting * @snippet tex00.cxx Interesting
*/ */
class TEX00 { class TEX00 : virtual public iTemperature {
public: public:
typedef enum { typedef enum {
@ -126,7 +127,15 @@ namespace upm {
* The default is false (degrees Celsius). * The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit * @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 * Return the smallest temperature that can be measured by the

View File

@ -28,6 +28,8 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <interfaces/iHumidity.hpp>
#include <interfaces/iTemperature.hpp>
#define TH02_ADDR 0x40 // device address #define TH02_ADDR 0x40 // device address
@ -69,7 +71,7 @@ namespace upm {
* @image html th02.jpg * @image html th02.jpg
* @snippet th02.cxx Interesting * @snippet th02.cxx Interesting
*/ */
class TH02 { class TH02 : virtual public iHumidity, virtual public iTemperature {
public: public:
/** /**
* Instantiates a TH02 object * Instantiates a TH02 object
@ -82,14 +84,18 @@ class TH02 {
~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. * Gets the sensor status.

View File

@ -189,6 +189,12 @@ TSL2561::getLux()
return lux; return lux;
} }
float
TSL2561::getLuminance()
{
return getLux();
}
mraa::Result mraa::Result
TSL2561::i2cWriteReg (uint8_t reg, uint8_t value) TSL2561::i2cWriteReg (uint8_t reg, uint8_t value)

View File

@ -31,6 +31,7 @@
#include <string> #include <string>
#include <mraa/i2c.hpp> #include <mraa/i2c.hpp>
#include <math.h> #include <math.h>
#include <interfaces/iLight.hpp>
namespace upm { namespace upm {
@ -108,14 +109,14 @@ namespace upm {
* @kit eak * @kit eak
* *
* @brief API for the TSL2561 Digital Light Sensor * @brief API for the TSL2561 Digital Light Sensor
* *
* TSL2560 and TSL2561 are light-to-digital converters that transform * TSL2560 and TSL2561 are light-to-digital converters that transform
* light intensity to a digital signal output capable of a direct I2C (TSL2561) interface * light intensity to a digital signal output capable of a direct I2C (TSL2561) interface
* *
* @image html tsl2561.jpg * @image html tsl2561.jpg
* @snippet tsl2561.cxx Interesting * @snippet tsl2561.cxx Interesting
*/ */
class TSL2561{ class TSL2561 : virtual public iLight {
public: public:
/** /**
* Instantiates a TSL2561 object * Instantiates a TSL2561 object
@ -139,6 +140,13 @@ class TSL2561{
*/ */
int getLux(); int getLux();
/**
* Gets the calculated lux reading from TSL2561
*
* @return Calculated lux value from the sensor
*/
virtual float getLuminance();
private: private:
/** /**
* Writes to a TSL2561 register * Writes to a TSL2561 register

Some files were not shown because too many files have changed in this diff Show More