mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Merge a4b84824f84027381953a822ba7c3248061dab82 into 3790c0bbc1482a5ce17f264feeaf567458378ccb
This commit is contained in:
commit
4293414b57
28
examples/c++/iLight-sample.cxx
Normal file
28
examples/c++/iLight-sample.cxx
Normal 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;
|
||||
}
|
26
examples/c++/iTemperature-sample.cxx
Normal file
26
examples/c++/iTemperature-sample.cxx
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
52
include/interfaces/iClock.hpp
Normal file
52
include/interfaces/iClock.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 Real Time Clock (RTC) Modules
|
||||
*/
|
||||
class iClock
|
||||
{
|
||||
public:
|
||||
virtual ~iClock() {}
|
||||
|
||||
/**
|
||||
* Loads all the time values
|
||||
*
|
||||
* @return True if time data loaded successfully
|
||||
*/
|
||||
virtual bool loadTime() = 0;
|
||||
|
||||
/**
|
||||
* Sets the time. You should call loadTime() beforehand to
|
||||
* maintain consistency
|
||||
*
|
||||
* @return True if time is set successfully
|
||||
*/
|
||||
virtual bool setTime() = 0;
|
||||
};
|
||||
}
|
38
include/interfaces/iCollision.hpp
Normal file
38
include/interfaces/iCollision.hpp
Normal 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;
|
||||
};
|
||||
}
|
70
include/interfaces/iDistance.hpp
Normal file
70
include/interfaces/iDistance.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
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 iDistance::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;
|
||||
}
|
||||
}
|
38
include/interfaces/iDistanceInterrupter.hpp
Normal file
38
include/interfaces/iDistanceInterrupter.hpp
Normal 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;
|
||||
};
|
||||
}
|
45
include/interfaces/iEC.hpp
Normal file
45
include/interfaces/iEC.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 Electrical Conductivity (EC) Sensors
|
||||
*/
|
||||
class iEC
|
||||
{
|
||||
public:
|
||||
virtual ~iEC() {}
|
||||
|
||||
/**
|
||||
* Get computed EC (ms/cm) value from the sensor.
|
||||
*
|
||||
* @return EC value in ms/cm.
|
||||
*/
|
||||
virtual float getECValue() = 0;
|
||||
|
||||
};
|
||||
}
|
49
include/interfaces/iEmg.hpp
Normal file
49
include/interfaces/iEmg.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 Electromyography (EMG) Sensors
|
||||
*/
|
||||
class iEmg
|
||||
{
|
||||
public:
|
||||
virtual ~iEmg() {}
|
||||
|
||||
/**
|
||||
* Calibrates the EMG reader
|
||||
*/
|
||||
virtual void calibrate() = 0;
|
||||
|
||||
/**
|
||||
* Measures muscle signals from the reader
|
||||
*
|
||||
* @return Muscle output as analog voltage
|
||||
*/
|
||||
virtual int value() = 0;
|
||||
};
|
||||
}
|
38
include/interfaces/iHallEffect.hpp
Normal file
38
include/interfaces/iHallEffect.hpp
Normal 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;
|
||||
};
|
||||
}
|
44
include/interfaces/iHeartRate.hpp
Normal file
44
include/interfaces/iHeartRate.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 Heart Rate sensors
|
||||
*/
|
||||
class iHeartRate
|
||||
{
|
||||
public:
|
||||
virtual ~iHeartRate() {}
|
||||
|
||||
/**
|
||||
* Retrieve the computed heart rate
|
||||
*
|
||||
* @return Computed heart rate
|
||||
*/
|
||||
virtual int getHeartRate() = 0;
|
||||
};
|
||||
}
|
38
include/interfaces/iHumidity.hpp
Normal file
38
include/interfaces/iHumidity.hpp
Normal 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;
|
||||
};
|
||||
}
|
38
include/interfaces/iLight.hpp
Normal file
38
include/interfaces/iLight.hpp
Normal 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;
|
||||
};
|
||||
}
|
51
include/interfaces/iLineFinder.hpp
Normal file
51
include/interfaces/iLineFinder.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 Line Finder Modules
|
||||
*/
|
||||
class iLineFinder
|
||||
{
|
||||
public:
|
||||
virtual ~iLineFinder() {}
|
||||
|
||||
/**
|
||||
* Determines whether white has been detected
|
||||
*
|
||||
* @return True if white is detected
|
||||
*/
|
||||
virtual bool whiteDetected() = 0;
|
||||
/**
|
||||
* Determines whether black has been detected
|
||||
*
|
||||
* @return True if black is detected
|
||||
*/
|
||||
virtual bool blackDetected() = 0;
|
||||
|
||||
};
|
||||
}
|
38
include/interfaces/iMoisture.hpp
Normal file
38
include/interfaces/iMoisture.hpp
Normal 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;
|
||||
};
|
||||
}
|
38
include/interfaces/iMotion.hpp
Normal file
38
include/interfaces/iMotion.hpp
Normal 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;
|
||||
};
|
||||
}
|
83
include/interfaces/iPressure.hpp
Normal file
83
include/interfaces/iPressure.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
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 iPressure::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;
|
||||
}
|
||||
}
|
77
include/interfaces/iTemperature.hpp
Normal file
77
include/interfaces/iTemperature.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
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 iTemperature::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;
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iHallEffect.hpp>
|
||||
|
||||
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
|
||||
|
@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "abp.h"
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
#include <math.h>
|
||||
#include <interfaces/iHumidity.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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]
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iLight.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <interfaces/iLight.hpp>
|
||||
|
||||
#include "bh1750.h"
|
||||
|
||||
@ -57,13 +58,13 @@ namespace upm {
|
||||
* @snippet bh1750.cxx Interesting
|
||||
*/
|
||||
|
||||
class BH1750 {
|
||||
class BH1750 : virtual public iLight {
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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 mode The mode to start operation under. One of the
|
||||
* BH1750_OPMODES_T values. The default is the highest precision,
|
||||
@ -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.
|
||||
*/
|
||||
|
@ -48,3 +48,8 @@ bool BISS0001::value()
|
||||
{
|
||||
return biss0001_motion_detected(m_biss0001);
|
||||
}
|
||||
|
||||
bool BISS0001::motionDetected()
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <interfaces/iMotion.hpp>
|
||||
#include <biss0001.h>
|
||||
|
||||
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 */
|
||||
|
@ -26,7 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "interfaces/iHumiditySensor.hpp"
|
||||
#include <interfaces/iHumidity.hpp>
|
||||
|
||||
#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
|
||||
|
@ -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);
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include <string>
|
||||
#include "bmp280.h"
|
||||
|
||||
#include "interfaces/iPressureSensor.hpp"
|
||||
#include "interfaces/iTemperatureSensor.hpp"
|
||||
#include <interfaces/iPressure.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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
|
||||
|
@ -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 ------------------------------------------------- */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -32,8 +32,7 @@
|
||||
|
||||
#include "bmpx8x.h"
|
||||
|
||||
#include "interfaces/iPressureSensor.hpp"
|
||||
#include "interfaces/iTemperatureSensor.hpp"
|
||||
#include <interfaces/iPressure.hpp>
|
||||
|
||||
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()
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iCollision.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
@ -73,6 +73,12 @@ float DFREC::getEC()
|
||||
return dfrec_get_ec(m_dfrec);
|
||||
}
|
||||
|
||||
float DFREC::getECValue()
|
||||
{
|
||||
DFREC::update();
|
||||
return DFREC::getEC();
|
||||
}
|
||||
|
||||
float DFREC::getVolts()
|
||||
{
|
||||
return dfrec_get_volts(m_dfrec);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "dfrec.h"
|
||||
#include <interfaces/iEC.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -65,7 +66,7 @@ namespace upm {
|
||||
* @snippet dfrec.cxx Interesting
|
||||
*/
|
||||
|
||||
class DFREC {
|
||||
class DFREC : virtual public iEC {
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -120,6 +121,13 @@ namespace upm {
|
||||
*/
|
||||
float getEC();
|
||||
|
||||
/**
|
||||
* Get computed EC (ms/cm) value from the sensor. update() is called
|
||||
* in this function.
|
||||
* @return EC value in ms/cm.
|
||||
*/
|
||||
virtual float getECValue();
|
||||
|
||||
/**
|
||||
* Get the measured volts from the sensor. update() must have been
|
||||
* called prior to calling this function.
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <interfaces/iClock.hpp>
|
||||
|
||||
#define DS1307_I2C_BUS 0
|
||||
#define DS1307_I2C_ADDR 0x68
|
||||
@ -69,7 +70,7 @@ namespace upm {
|
||||
* @image html ds1307.jpg
|
||||
* @snippet ds1307.cxx Interesting
|
||||
*/
|
||||
class DS1307 {
|
||||
class DS1307 : virtual public iClock {
|
||||
public:
|
||||
/**
|
||||
* DS1307 constructor
|
||||
@ -83,7 +84,7 @@ namespace upm {
|
||||
*
|
||||
* @return True if time data loaded successfully
|
||||
*/
|
||||
bool loadTime();
|
||||
virtual bool loadTime();
|
||||
|
||||
/**
|
||||
* Sets the time. You should call loadTime() beforehand to
|
||||
@ -91,7 +92,7 @@ namespace upm {
|
||||
*
|
||||
* @return True if time is set successfully
|
||||
*/
|
||||
bool setTime();
|
||||
virtual bool setTime();
|
||||
|
||||
/**
|
||||
* Enables an oscillator on the clock.
|
||||
@ -132,7 +133,7 @@ namespace upm {
|
||||
* Converts a BCD value into decimal
|
||||
*
|
||||
* @param val BCD value to convert
|
||||
* @return Converted decimal value
|
||||
* @return Converted decimal value
|
||||
*/
|
||||
unsigned int bcdToDec(uint8_t val);
|
||||
|
||||
@ -190,5 +191,3 @@ namespace upm {
|
||||
mraa::I2c m_i2c;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,6 +81,12 @@ float ECEZO::getEC()
|
||||
return ecezo_get_ec(m_ecezo);
|
||||
}
|
||||
|
||||
float ECEZO::getECValue()
|
||||
{
|
||||
ECEZO::update();
|
||||
return ECEZO::getEC();
|
||||
}
|
||||
|
||||
float ECEZO::getTDS()
|
||||
{
|
||||
return ecezo_get_tds(m_ecezo);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ecezo.h"
|
||||
#include <interfaces/iEC.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -57,7 +58,7 @@ namespace upm {
|
||||
* @snippet ecezo.cxx Interesting
|
||||
*/
|
||||
|
||||
class ECEZO {
|
||||
class ECEZO : virtual public iEC {
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -127,6 +128,14 @@ namespace upm {
|
||||
*/
|
||||
float getEC();
|
||||
|
||||
/**
|
||||
* Measures and retrieves the Electrical Conductivity (EC)
|
||||
* value in microsiemens. update() is called during this function.
|
||||
*
|
||||
* @return EC value in microsiemens
|
||||
*/
|
||||
virtual float getECValue();
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Total Dissolved solids (TDS) value.
|
||||
* update() must have been called before calling this
|
||||
|
@ -65,12 +65,12 @@ uint32_t EHR::getMillis()
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
// compute the delta since m_startTime
|
||||
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
|
||||
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
|
||||
{
|
||||
elapsed.tv_usec += 1000000;
|
||||
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec - 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec;
|
||||
}
|
||||
@ -92,7 +92,7 @@ void EHR::clearBeatCounter()
|
||||
void EHR::startBeatCounter()
|
||||
{
|
||||
// install our interrupt handler
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
|
||||
&beatISR, this);
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ int EHR::heartRate()
|
||||
{
|
||||
uint32_t millis = getMillis();
|
||||
uint32_t beats = beatCounter();
|
||||
|
||||
|
||||
float heartRate = 0;
|
||||
// wait at least 5 seconds before attempting to compute the
|
||||
// heart rate
|
||||
@ -128,3 +128,8 @@ int EHR::heartRate()
|
||||
|
||||
return int(heartRate);
|
||||
}
|
||||
|
||||
int EHR::getHeartRate()
|
||||
{
|
||||
return EHR::heartRate();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iHeartRate.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -46,12 +47,12 @@ namespace upm {
|
||||
* @brief API for the Ear-clip Heart Rate Sensor
|
||||
*
|
||||
* UPM module for the ear-clip heart rate sensor. It is used to measure your
|
||||
* heart rate.
|
||||
* heart rate.
|
||||
*
|
||||
* @image html ehr.jpg
|
||||
* @image html ehr.jpg
|
||||
* @snippet ehr.cxx Interesting
|
||||
*/
|
||||
class EHR {
|
||||
class EHR : virtual public iHeartRate {
|
||||
public:
|
||||
/**
|
||||
* EHR constructor
|
||||
@ -110,17 +111,22 @@ namespace upm {
|
||||
*/
|
||||
int heartRate();
|
||||
|
||||
/**
|
||||
* Retrieve the computed heart rate
|
||||
*
|
||||
* @return Computed heart rate
|
||||
*/
|
||||
virtual int getHeartRate();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Beat interrupt service routine (ISR)
|
||||
*
|
||||
*/
|
||||
static void beatISR(void *ctx);
|
||||
|
||||
|
||||
volatile uint32_t m_beatCounter;
|
||||
struct timeval m_startTime;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include "interfaces/iEmg.hpp"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -43,14 +44,14 @@ namespace upm {
|
||||
* @con analog
|
||||
*
|
||||
* @brief API for the Grove EMG Muscle Signal Reader
|
||||
*
|
||||
*
|
||||
* Grove EMG muscle signal reader gathers small muscle signals,
|
||||
* then processes them, and returns the result
|
||||
*
|
||||
* @image html emg.jpg
|
||||
* @snippet emg.cxx Interesting
|
||||
*/
|
||||
class EMG {
|
||||
class EMG : virtual public iEmg {
|
||||
public:
|
||||
/**
|
||||
* Grove EMG reader constructor
|
||||
@ -66,18 +67,16 @@ namespace upm {
|
||||
/**
|
||||
* Calibrates the Grove EMG reader
|
||||
*/
|
||||
void calibrate();
|
||||
virtual void calibrate();
|
||||
|
||||
/**
|
||||
* Measures muscle signals from the reader
|
||||
*
|
||||
* @return Muscle output as analog voltage
|
||||
*/
|
||||
int value();
|
||||
virtual int value();
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <interfaces/iLight.hpp>
|
||||
#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;
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <string>
|
||||
#include <mraa/aio.hpp>
|
||||
#include "grovebase.hpp"
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iCollision.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ uint32_t GroveEHR::getMillis()
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
// compute the delta since m_startTime
|
||||
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
|
||||
if( (elapsed.tv_usec = now.tv_usec - m_startTime.tv_usec) < 0 )
|
||||
{
|
||||
elapsed.tv_usec += 1000000;
|
||||
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec - 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
elapsed.tv_sec = now.tv_sec - m_startTime.tv_sec;
|
||||
}
|
||||
@ -92,7 +92,7 @@ void GroveEHR::clearBeatCounter()
|
||||
void GroveEHR::startBeatCounter()
|
||||
{
|
||||
// install our interrupt handler
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_RISING,
|
||||
&beatISR, this);
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ int GroveEHR::heartRate()
|
||||
{
|
||||
uint32_t millis = getMillis();
|
||||
uint32_t beats = beatCounter();
|
||||
|
||||
|
||||
float heartRate = 0;
|
||||
// wait at least 5 seconds before attempting to compute the
|
||||
// heart rate
|
||||
@ -128,3 +128,8 @@ int GroveEHR::heartRate()
|
||||
|
||||
return int(heartRate);
|
||||
}
|
||||
|
||||
int GroveEHR::getHeartRate()
|
||||
{
|
||||
return GroveEHR::heartRate();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iHeartRate.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -48,12 +49,12 @@ namespace upm {
|
||||
* @brief API for the Grove Ear-clip Heart Rate Sensor
|
||||
*
|
||||
* UPM module for the Grove ear-clip heart rate sensor. It is used to measure your
|
||||
* heart rate.
|
||||
* heart rate.
|
||||
*
|
||||
* @image html groveehr.jpg
|
||||
* @image html groveehr.jpg
|
||||
* @snippet groveehr.cxx Interesting
|
||||
*/
|
||||
class GroveEHR {
|
||||
class GroveEHR : virtual public iHeartRate {
|
||||
public:
|
||||
/**
|
||||
* GroveEHR constructor
|
||||
@ -112,17 +113,22 @@ namespace upm {
|
||||
*/
|
||||
int heartRate();
|
||||
|
||||
/**
|
||||
* Retrieve the computed heart rate
|
||||
*
|
||||
* @return Computed heart rate
|
||||
*/
|
||||
virtual int getHeartRate();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Beat interrupt service routine (ISR)
|
||||
*
|
||||
*/
|
||||
static void beatISR(void *ctx);
|
||||
|
||||
|
||||
volatile uint32_t m_beatCounter;
|
||||
struct timeval m_startTime;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include "interfaces/iEmg.hpp"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -51,7 +52,7 @@ namespace upm {
|
||||
* @image html emg.jpg
|
||||
* @snippet groveemg.cxx Interesting
|
||||
*/
|
||||
class GroveEMG {
|
||||
class GroveEMG : virtual public iEmg {
|
||||
public:
|
||||
/**
|
||||
* Grove EMG reader constructor
|
||||
@ -67,18 +68,16 @@ namespace upm {
|
||||
/**
|
||||
* Calibrates the Grove EMG reader
|
||||
*/
|
||||
void calibrate();
|
||||
virtual void calibrate();
|
||||
|
||||
/**
|
||||
* Measures muscle signals from the reader
|
||||
*
|
||||
* @return Muscle output as analog voltage
|
||||
*/
|
||||
int value();
|
||||
virtual int value();
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,3 +68,8 @@ int GroveGSR::value()
|
||||
int val = mraa_aio_read(m_aio);
|
||||
return val;
|
||||
}
|
||||
|
||||
float GroveGSR::getECValue()
|
||||
{
|
||||
return (float) GroveGSR::value();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iEC.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -44,7 +45,7 @@ namespace upm {
|
||||
* @con analog
|
||||
*
|
||||
* @brief API for the Grove GSR Galvanic Skin Response Sensor
|
||||
*
|
||||
*
|
||||
* Measures the electrical conductance of skin
|
||||
* to measure strong emotional reactions.
|
||||
* In other words, it measures sweat on your fingers
|
||||
@ -53,7 +54,7 @@ namespace upm {
|
||||
* @image html gsr.jpg
|
||||
* @snippet grovegsr.cxx Interesting
|
||||
*/
|
||||
class GroveGSR {
|
||||
class GroveGSR : virtual public iEC {
|
||||
public:
|
||||
/**
|
||||
* Grove GSR sensor constructor
|
||||
@ -78,9 +79,14 @@ namespace upm {
|
||||
*/
|
||||
int value();
|
||||
|
||||
/**
|
||||
* Gets the electrical conductance of the skin from the sensor
|
||||
*
|
||||
* @return Electrical conductance of the skin
|
||||
*/
|
||||
virtual float getECValue();
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/gpio.h>
|
||||
#include <interfaces/iLineFinder.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -53,7 +54,7 @@ namespace upm {
|
||||
* @image html grovelinefinder.jpg
|
||||
* @snippet grovelinefinder.cxx Interesting
|
||||
*/
|
||||
class GroveLineFinder {
|
||||
class GroveLineFinder : virtual public iLineFinder {
|
||||
public:
|
||||
/**
|
||||
* Grove Line Finder digital sensor constructor
|
||||
@ -70,17 +71,15 @@ namespace upm {
|
||||
*
|
||||
* @return True if white is detected
|
||||
*/
|
||||
bool whiteDetected();
|
||||
virtual bool whiteDetected();
|
||||
/**
|
||||
* Determines whether black has been detected
|
||||
*
|
||||
* @return True if black is detected
|
||||
*/
|
||||
bool blackDetected();
|
||||
virtual bool blackDetected();
|
||||
|
||||
private:
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,3 +46,8 @@ int GroveMoisture::value()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
int GroveMoisture::getMoisture()
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iMoisture.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -65,3 +65,8 @@ int GSR::value()
|
||||
int val = mraa_aio_read(m_aio);
|
||||
return val;
|
||||
}
|
||||
|
||||
float GSR::getECValue()
|
||||
{
|
||||
return (float) GSR::value();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iEC.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -42,7 +43,7 @@ namespace upm {
|
||||
* @con analog
|
||||
*
|
||||
* @brief API for the Grove GSR Galvanic Skin Response Sensor
|
||||
*
|
||||
*
|
||||
* Measures the electrical conductance of skin
|
||||
* to measure strong emotional reactions.
|
||||
* In other words, it measures sweat on your fingers
|
||||
@ -51,7 +52,7 @@ namespace upm {
|
||||
* @image html gsr.jpg
|
||||
* @snippet gsr.cxx Interesting
|
||||
*/
|
||||
class GSR {
|
||||
class GSR : virtual public iEC {
|
||||
public:
|
||||
/**
|
||||
* Grove GSR sensor constructor
|
||||
@ -76,9 +77,14 @@ namespace upm {
|
||||
*/
|
||||
int value();
|
||||
|
||||
/**
|
||||
* Gets the electrical conductance of the skin from the sensor
|
||||
*
|
||||
* @return Electrical conductance of the skin
|
||||
*/
|
||||
virtual float getECValue();
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,3 +49,9 @@ HCSR04::getDistance(HCSR04_U unit)
|
||||
{
|
||||
return hcsr04_get_distance(m_hcsr04, unit);
|
||||
}
|
||||
|
||||
int
|
||||
HCSR04::getDistance()
|
||||
{
|
||||
return getDistance(HCSR04_CM);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "hcsr04.h"
|
||||
#include <interfaces/iDistance.hpp>
|
||||
|
||||
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 */ }
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
#include <interfaces/iHumidity.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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:
|
||||
|
||||
|
@ -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()
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
#include <mraa/common.hpp>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <interfaces/iPressure.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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
|
||||
|
@ -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
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
#include <interfaces/iHumidity.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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
|
||||
|
@ -263,6 +263,11 @@ float HWXPXX::getTemperature(bool fahrenheit)
|
||||
return m_temperature;
|
||||
}
|
||||
|
||||
float HWXPXX::getTemperature()
|
||||
{
|
||||
return getTemperature(false);
|
||||
}
|
||||
|
||||
float HWXPXX::getHumidity()
|
||||
{
|
||||
return m_humidity;
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
|
||||
#include <modbus/modbus.h>
|
||||
#include <interfaces/iHumidity.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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
|
||||
|
@ -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<float>(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)
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <interfaces/iMoisture.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
#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
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <interfaces/iDistance.hpp>
|
||||
|
||||
#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
|
||||
|
@ -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.
|
||||
|
@ -28,6 +28,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <interfaces/iLight.hpp>
|
||||
|
||||
#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
|
||||
*
|
||||
|
@ -24,6 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <linefinder.h>
|
||||
#include <interfaces/iLineFinder.hpp>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
@ -51,7 +52,7 @@ namespace upm {
|
||||
* @image html linefinder.jpg
|
||||
* @snippet linefinder.cxx Interesting
|
||||
*/
|
||||
class LineFinder {
|
||||
class LineFinder : virtual public iLineFinder {
|
||||
public:
|
||||
/**
|
||||
* Line Finder digital sensor constructor
|
||||
@ -70,14 +71,14 @@ namespace upm {
|
||||
*
|
||||
* @return True if white is detected
|
||||
*/
|
||||
bool whiteDetected();
|
||||
virtual bool whiteDetected();
|
||||
|
||||
/**
|
||||
* Determines whether black has been detected
|
||||
*
|
||||
* @return True if black is detected
|
||||
*/
|
||||
bool blackDetected();
|
||||
virtual bool blackDetected();
|
||||
|
||||
private:
|
||||
/* Disable implicit copy and assignment operators */
|
||||
@ -87,5 +88,3 @@ namespace upm {
|
||||
linefinder_context m_linefinder;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "lm35.h"
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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
|
||||
|
@ -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;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <mraa/gpio.hpp>
|
||||
|
||||
#include <mraa/spi.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
|
||||
#include "interfaces/iLightSensor.hpp"
|
||||
#include <interfaces/iLight.hpp>
|
||||
|
||||
/* 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:
|
||||
|
@ -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 */
|
||||
|
@ -62,3 +62,8 @@ int MAXSONAREZ::inches()
|
||||
|
||||
return int(volts / m_vI);
|
||||
}
|
||||
|
||||
int MAXSONAREZ::getDistance()
|
||||
{
|
||||
return (inches() * 2.54);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iDistance.hpp>
|
||||
|
||||
// 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;
|
||||
|
@ -47,3 +47,8 @@ int MB704X::getRange()
|
||||
{
|
||||
return mb704x_get_range(m_mb704x);
|
||||
}
|
||||
|
||||
int MB704X::getDistance()
|
||||
{
|
||||
return getRange();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <interfaces/iDistance.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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.
|
||||
*
|
||||
|
@ -70,6 +70,11 @@ MLX90614::readAmbientTempC(void) {
|
||||
return readTemperature(MLX90614_TA);
|
||||
}
|
||||
|
||||
float
|
||||
MLX90614::getTemperature() {
|
||||
return readAmbientTempC();
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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
|
||||
*/
|
||||
|
@ -46,3 +46,8 @@ int Moisture::value()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
int Moisture::getMoisture()
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <interfaces/iMoisture.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <string>
|
||||
#include <mraa/i2c.hpp>
|
||||
#include <math.h>
|
||||
#include <interfaces/iPressure.hpp>
|
||||
|
||||
#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]
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 <interfaces/iPressure.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
#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;
|
||||
|
@ -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 */
|
||||
|
@ -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()
|
||||
|
@ -24,6 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <interfaces/iPressure.hpp>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
#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;
|
||||
|
@ -55,6 +55,11 @@ float OTP538U::ambientTemperature()
|
||||
return temp;
|
||||
}
|
||||
|
||||
float OTP538U::getTemperature()
|
||||
{
|
||||
return ambientTemperature();
|
||||
}
|
||||
|
||||
float OTP538U::objectTemperature()
|
||||
{
|
||||
float temp = 0;
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <otp538u.h>
|
||||
#include <interfaces/iTemperature.hpp>
|
||||
|
||||
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
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user