mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
Added bindings for iLight sensors.
Removed old interfaces C++ examples. Signed-off-by: Serban Waltter <serban.waltter@rinftech.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
c3d5d951e1
commit
2405f933de
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "bme280.hpp"
|
||||
#include "iHumiditySensor.hpp"
|
||||
#include "mraa/common.h"
|
||||
#include "si7005.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
#define EDISON_I2C_BUS 1
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
#define EDISON_GPIO_SI7005_CS 20
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
|
||||
upm::IHumiditySensor*
|
||||
getHumiditySensor()
|
||||
{
|
||||
upm::IHumiditySensor* humiditySensor = NULL;
|
||||
|
||||
try {
|
||||
humiditySensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return humiditySensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "BME280: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
try {
|
||||
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||
return humiditySensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||
}
|
||||
return humiditySensor;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
|
||||
if (humiditySensor == NULL) {
|
||||
std::cout << "Humidity sensor not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
|
||||
while (true) {
|
||||
try {
|
||||
int value = humiditySensor->getHumidityRelative();
|
||||
std::cout << "Humidity = " << value << "%" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
delete humiditySensor;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
@ -1,98 +0,0 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "ds1808lc.hpp"
|
||||
#include "hlg150h.hpp"
|
||||
#include "iLightController.hpp"
|
||||
#include "lp8860.hpp"
|
||||
|
||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||
#define GPIO_SI7005_CS 20 // Edison GP12
|
||||
#define HLG150H_GPIO_RELAY 21
|
||||
#define HLG150H_GPIO_PWM 22
|
||||
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightController to determine
|
||||
// which controller is present and return its name.
|
||||
// ILightController is then used to get readings from sensor
|
||||
|
||||
upm::ILightController*
|
||||
getLightController()
|
||||
{
|
||||
upm::ILightController* lightController = NULL;
|
||||
try {
|
||||
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||
return lightController;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "LP8860: " << e.what() << std::endl;
|
||||
}
|
||||
try {
|
||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||
return lightController;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "DS1808LC: " << e.what() << std::endl;
|
||||
}
|
||||
try {
|
||||
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||
return lightController;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "HLG150H: " << e.what() << std::endl;
|
||||
}
|
||||
return lightController;
|
||||
}
|
||||
|
||||
void
|
||||
printState(upm::ILightController* lightController)
|
||||
{
|
||||
if (lightController->isPowered()) {
|
||||
std::cout << "Light is powered, brightness = " << lightController->getBrightness()
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Light is not powered." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
int status = 0;
|
||||
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
|
||||
|
||||
upm::ILightController* lightController = getLightController();
|
||||
if (lightController != NULL) {
|
||||
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||
} else {
|
||||
std::cerr << "Error. Unsupported platform." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
std::cout << "Existing state: ";
|
||||
printState(lightController);
|
||||
if (argc == 2) {
|
||||
std::string arg = argv[1];
|
||||
int brightness = ::atoi(argv[1]);
|
||||
if (brightness > 0) {
|
||||
lightController->setPowerOn();
|
||||
lightController->setBrightness(brightness);
|
||||
} else
|
||||
lightController->setPowerOff();
|
||||
}
|
||||
std::cout << "Now: ";
|
||||
printState(lightController);
|
||||
} catch (std::exception& e) {
|
||||
std::cout << "Error: " << e.what() << std::endl;
|
||||
status = 1;
|
||||
}
|
||||
|
||||
delete lightController;
|
||||
return status;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "iLightSensor.hpp"
|
||||
#include "max44009.hpp"
|
||||
#include "mraa/common.h"
|
||||
#include "si1132.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
#define EDISON_I2C_BUS 1
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
|
||||
upm::ILightSensor*
|
||||
getLightSensor()
|
||||
{
|
||||
upm::ILightSensor* lightSensor = NULL;
|
||||
try {
|
||||
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return lightSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "SI1132: " << e.what() << std::endl;
|
||||
}
|
||||
try {
|
||||
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||
return lightSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "MAX44009: " << e.what() << std::endl;
|
||||
}
|
||||
return lightSensor;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
/*upm::ILightSensor* lightSensor = getLightSensor();
|
||||
if (lightSensor == NULL) {
|
||||
std::cout << "Light sensor not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
|
||||
while (true) {
|
||||
try {
|
||||
float value = lightSensor->getVisibleLux();
|
||||
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
delete lightSensor;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "bme280.hpp"
|
||||
#include "bmpx8x.hpp"
|
||||
#include "iPressureSensor.hpp"
|
||||
#include "mraa/common.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
#define EDISON_I2C_BUS 1
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
|
||||
upm::IPressureSensor*
|
||||
getPressureSensor()
|
||||
{
|
||||
upm::IPressureSensor* pressureSensor = NULL;
|
||||
try {
|
||||
pressureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return pressureSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "BME280: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
try {
|
||||
pressureSensor = new upm::BMPX8X(EDISON_I2C_BUS);
|
||||
return pressureSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "BMPX8X: " << e.what() << std::endl;
|
||||
}
|
||||
return pressureSensor;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::IPressureSensor* pressureSensor = getPressureSensor();
|
||||
if (pressureSensor == NULL) {
|
||||
std::cout << "Pressure sensor not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
|
||||
while (true) {
|
||||
try {
|
||||
int value = pressureSensor->getPressurePa();
|
||||
std::cout << "Pressure = " << value << " Pa" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
delete pressureSensor;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "bme280.hpp"
|
||||
#include "bmpx8x.hpp"
|
||||
#include "iTemperatureSensor.hpp"
|
||||
#include "mraa/common.h"
|
||||
#include "si7005.hpp"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
#define EDISON_I2C_BUS 1
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
#define EDISON_GPIO_SI7005_CS 20
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ITemperatureSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ITemperatureSensor is then used to get readings from sensor
|
||||
|
||||
upm::ITemperatureSensor*
|
||||
getTemperatureSensor()
|
||||
{
|
||||
upm::ITemperatureSensor* temperatureSensor = NULL;
|
||||
|
||||
try {
|
||||
temperatureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return temperatureSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "BME280: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
try {
|
||||
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||
return temperatureSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||
}
|
||||
try {
|
||||
temperatureSensor = new upm::BMPX8X(EDISON_I2C_BUS);
|
||||
return temperatureSensor;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "BMPX8X: " << e.what() << std::endl;
|
||||
}
|
||||
return temperatureSensor;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
|
||||
if (temperatureSensor == NULL) {
|
||||
std::cout << "Temperature sensor not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected"
|
||||
<< std::endl;
|
||||
while (true) {
|
||||
try {
|
||||
int value = temperatureSensor->getTemperatureCelsius();
|
||||
std::cout << "Temperature = " << value << "C" << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
delete temperatureSensor;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
30
examples/java/iLight_Example.java
Normal file
30
examples/java/iLight_Example.java
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Author: Serban Waltter <serban.waltter@rinftech.com>
|
||||
*/
|
||||
|
||||
import upm_new_interfaces.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import upm_apds9002.*;
|
||||
import upm_bh1750.*;
|
||||
import upm_max44009.*;
|
||||
|
||||
/**
|
||||
* iLight_Example
|
||||
*/
|
||||
public class iLight_Example {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArrayList<iLight> sensors = new ArrayList<iLight>();
|
||||
sensors.add(new APDS9002(0));
|
||||
sensors.add(new BH1750());
|
||||
sensors.add(new MAX44009(1));
|
||||
|
||||
while (true) {
|
||||
for (int i = 0; i < sensors.size(); i++) {
|
||||
System.out.println("Luminance from sensor " + i + " is " + sensors.get(i).getLuminance());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user