mirror of
https://github.com/eclipse/upm.git
synced 2025-07-25 21:21:18 +03:00
C++ Core: Add base class per sensor/actuator type
Adding base classes for UPM sensors and actuators. Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -120,7 +120,7 @@ if(BUILDEXAMPLES)
|
||||
|
||||
# Add all examples as an install component (if building examples)
|
||||
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm/
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm
|
||||
COMPONENT ${CMAKE_PROJECT_NAME}-examples
|
||||
FILES_MATCHING
|
||||
PATTERN "*.c"
|
||||
|
@ -4,15 +4,15 @@ file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cxx")
|
||||
# - Handle special cases here --------------------------------------------------
|
||||
|
||||
# Test humidity interface for 2 sensor libraries
|
||||
add_example(interfaces-humiditysensor.cxx TARGETS si7005 bmp280)
|
||||
add_example(core-humiditysensor.cxx TARGETS si7005 bmp280)
|
||||
# Test pressure interface for 2 sensor libraries
|
||||
add_example(interfaces-pressuresensor.cxx TARGETS bmp280 bmpx8x)
|
||||
add_example(core-pressuresensor.cxx TARGETS bmp280 bmpx8x)
|
||||
# Test temperature interface for 3 sensor libraries
|
||||
add_example(interfaces-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
|
||||
add_example(core-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
|
||||
# Test light interface for 2 sensor libraries
|
||||
add_example(interfaces-lightsensor.cxx TARGETS si1132 max44009)
|
||||
add_example(core-lightsensor.cxx TARGETS si1132 max44009)
|
||||
# Test light controller interface for 3 sensor libraries
|
||||
add_example(interfaces-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
|
||||
add_example(core-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
|
||||
|
||||
# - Create an executable for all other src files in this directory -------------
|
||||
foreach (_example_src ${example_src_list})
|
||||
|
@ -43,14 +43,14 @@ main()
|
||||
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
||||
gpio.dir(mraa::DIR_OUT_HIGH);
|
||||
|
||||
/* Show usage from the IADC interface */
|
||||
upm::IADC* adc = static_cast<upm::IADC*>(&sensor);
|
||||
/* Show usage from the iADC interface */
|
||||
upm::iADC* adc = static_cast<upm::iADC*>(&sensor);
|
||||
|
||||
if (adc == NULL) {
|
||||
std::cout << "ADC not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "ADC " << adc->getModuleName() << " detected. ";
|
||||
std::cout << "ADC " << adc->Name() << " detected. ";
|
||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||
while (true) {
|
||||
for (unsigned int i = 0; i < adc->getNumInputs(); ++i) {
|
||||
|
@ -38,14 +38,14 @@
|
||||
#define EDISON_GPIO_SI7005_CS 20
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// Simple example of using iHumiditySensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
// iHumiditySensor is then used to get readings from sensor
|
||||
|
||||
upm::IHumiditySensor*
|
||||
upm::iHumiditySensor*
|
||||
getHumiditySensor()
|
||||
{
|
||||
upm::IHumiditySensor* humiditySensor = NULL;
|
||||
upm::iHumiditySensor* humiditySensor = NULL;
|
||||
|
||||
try {
|
||||
humiditySensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
@ -66,22 +66,26 @@ getHumiditySensor()
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
|
||||
if (humiditySensor == NULL) {
|
||||
upm::iHumiditySensor* sensor = getHumiditySensor();
|
||||
|
||||
if (sensor == 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);
|
||||
|
||||
std::cout << "Humidity sensor " << sensor->Name() << " detected" << std::endl;
|
||||
|
||||
try {
|
||||
std::map<std::string, float> values = sensor->HumidityAll();
|
||||
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||
it != values.end(); ++it)
|
||||
std::cout << it->first << " = " << it->second
|
||||
<< sensor->Unit(it->first) << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
delete humiditySensor;
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ main(int argc, char** argv)
|
||||
|
||||
upm::ILightController* lightController = getLightController();
|
||||
if (lightController != NULL) {
|
||||
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||
//std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||
} else {
|
||||
std::cerr << "Error. Unsupported platform." << std::endl;
|
||||
return 1;
|
@ -36,14 +36,14 @@
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// Simple example of using iLightSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
// iLightSensor is then used to get readings from sensor
|
||||
|
||||
upm::ILightSensor*
|
||||
upm::iLightSensor*
|
||||
getLightSensor()
|
||||
{
|
||||
upm::ILightSensor* lightSensor = NULL;
|
||||
upm::iLightSensor* lightSensor = NULL;
|
||||
try {
|
||||
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return lightSensor;
|
||||
@ -62,22 +62,26 @@ getLightSensor()
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::ILightSensor* lightSensor = getLightSensor();
|
||||
if (lightSensor == NULL) {
|
||||
upm::iLightSensor* sensor = getLightSensor();
|
||||
|
||||
if (sensor == 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);
|
||||
|
||||
std::cout << "Light sensor " << sensor->Name() << " detected" << std::endl;
|
||||
|
||||
try {
|
||||
std::map<std::string, float> values = sensor->LightAll();
|
||||
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||
it != values.end(); ++it)
|
||||
std::cout << it->first << " = " << it->second
|
||||
<< sensor->Unit(it->first) << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
delete lightSensor;
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,14 +36,14 @@
|
||||
#define FT4222_I2C_BUS 0
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ILightSensor to determine
|
||||
// Simple example of using iPressureSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ILightSensor is then used to get readings from sensor
|
||||
// iPressureSensor is then used to get readings from sensor
|
||||
|
||||
upm::IPressureSensor*
|
||||
upm::iPressureSensor*
|
||||
getPressureSensor()
|
||||
{
|
||||
upm::IPressureSensor* pressureSensor = NULL;
|
||||
upm::iPressureSensor* pressureSensor = NULL;
|
||||
try {
|
||||
pressureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
return pressureSensor;
|
||||
@ -63,22 +63,26 @@ getPressureSensor()
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::IPressureSensor* pressureSensor = getPressureSensor();
|
||||
if (pressureSensor == NULL) {
|
||||
upm::iPressureSensor* sensor = getPressureSensor();
|
||||
|
||||
if (sensor == 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);
|
||||
|
||||
std::cout << "Pressure sensor " << sensor->Name() << " detected" << std::endl;
|
||||
|
||||
try {
|
||||
std::map<std::string, float> values = sensor->PressureAll();
|
||||
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||
it != values.end(); ++it)
|
||||
std::cout << it->first << " = " << it->second
|
||||
<< sensor->Unit(it->first) << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
delete pressureSensor;
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,14 +39,14 @@
|
||||
#define EDISON_GPIO_SI7005_CS 20
|
||||
|
||||
//! [Interesting]
|
||||
// Simple example of using ITemperatureSensor to determine
|
||||
// Simple example of using iTemperatureSensor to determine
|
||||
// which sensor is present and return its name.
|
||||
// ITemperatureSensor is then used to get readings from sensor
|
||||
// iTemperatureSensor is then used to get readings from sensor
|
||||
|
||||
upm::ITemperatureSensor*
|
||||
upm::iTemperatureSensor*
|
||||
getTemperatureSensor()
|
||||
{
|
||||
upm::ITemperatureSensor* temperatureSensor = NULL;
|
||||
upm::iTemperatureSensor* temperatureSensor = NULL;
|
||||
|
||||
try {
|
||||
temperatureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||
@ -73,23 +73,26 @@ getTemperatureSensor()
|
||||
int
|
||||
main()
|
||||
{
|
||||
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
|
||||
if (temperatureSensor == NULL) {
|
||||
upm::iTemperatureSensor* sensor = getTemperatureSensor();
|
||||
|
||||
if (sensor == 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);
|
||||
|
||||
std::cout << "Temperature sensor " << sensor->Name() << " detected" << std::endl;
|
||||
|
||||
try {
|
||||
std::map<std::string, float> values = sensor->TemperatureAll();
|
||||
for (std::map<std::string, float>::const_iterator it = values.begin();
|
||||
it != values.end(); ++it)
|
||||
std::cout << it->first << " = " << it->second
|
||||
<< sensor->Unit(it->first) << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
delete temperatureSensor;
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ main(int argc, char** argv)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||
upm::IMS sensor(0);
|
||||
upm::IMS sensor("i:0:0x20");
|
||||
|
||||
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||
while (shouldRun) {
|
||||
|
49
examples/c++/noelstemplightreader.cxx
Normal file
49
examples/c++/noelstemplightreader.cxx
Normal file
@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "core/iUpmObject.hpp"
|
||||
#include "noelstemplightreader.hpp"
|
||||
|
||||
void printMap(upm::NoelsTempLightReader &sensor, std::map<std::string, float> &data)
|
||||
{
|
||||
if (data.empty())
|
||||
std::cout << "Empty map" << std::endl;
|
||||
for (std::map<std::string, float>::const_iterator it = data.begin();
|
||||
it != data.end(); ++it)
|
||||
{
|
||||
std::cout << "label: " << it->first << ", value: " << it->second
|
||||
<< ", unit: " << sensor.Unit(it->first) << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
upm::NoelsTempLightReader sensor;
|
||||
std::cout << "iUpmObject JsonDefinition..." << std::endl << ((upm::iUpmObject&)sensor).JsonDefinition() << std::endl << std::endl;
|
||||
std::cout << "iSensorType JsonDefinition..." << std::endl << ((upm::iSensorType&)sensor).JsonDefinition() << std::endl << std::endl;
|
||||
std::cout << "iMraa JsonDefinition..." << std::endl << ((upm::iMraa&)sensor).JsonDefinition() << std::endl << std::endl;
|
||||
std::cout << "NoelsTempLightReader JsonDefinition..." << std::endl << sensor.JsonDefinition() << std::endl << std::endl;
|
||||
|
||||
std::cout << "Read all light values..." << std::endl;
|
||||
std::map<std::string, float> values = sensor.LightAll();
|
||||
printMap(sensor, values);
|
||||
|
||||
std::cout << "Read a single light value for light0..." << std::endl;
|
||||
std::cout << "Single value = " << sensor.LightForSource("light0") << std::endl << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << "Read a single light value for lightX (doesn't exist)..." << std::endl;
|
||||
sensor.LightForSource("lightX");
|
||||
}
|
||||
catch (const std::exception& e) { std::cout << e.what() << std::endl << std::endl;}
|
||||
|
||||
std::cout << "Read a light value for lightX (doesn't exist)..." << std::endl;
|
||||
values = sensor.LightForSources(std::vector<std::string>({"lightX"}));
|
||||
printMap(sensor, values);
|
||||
|
||||
std::cout << "Read all values as JsonDefinition..." << std::endl << sensor.JsonValues() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -31,7 +31,7 @@ int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::ES08A servo(5);
|
||||
upm::ES08A servo("p:5");
|
||||
|
||||
// Sets the shaft to 180, then to 90, then to 0,
|
||||
// then back to 90, and finally back to 180,
|
||||
|
@ -42,18 +42,18 @@ main()
|
||||
/* Create an instance of the T6713 sensor */
|
||||
upm::T6713 sensor(EDISON_I2C_BUS);
|
||||
|
||||
/* Show usage from the ICO2Sensor interface */
|
||||
upm::ICO2Sensor* cO2Sensor = static_cast<upm::ICO2Sensor*>(&sensor);
|
||||
/* Show usage from the iCO2Sensor interface */
|
||||
upm::iCO2Sensor* cO2Sensor = static_cast<upm::iCO2Sensor*>(&sensor);
|
||||
|
||||
if (cO2Sensor == NULL) {
|
||||
std::cout << "CO2 sensor not detected" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
|
||||
std::cout << "CO2 sensor " << cO2Sensor->Name() << " detected" << std::endl;
|
||||
while (true) {
|
||||
try {
|
||||
uint16_t value = cO2Sensor->getPpm();
|
||||
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
||||
uint16_t value = cO2Sensor->CO2ForSource(cO2Sensor->Sources()[0]);
|
||||
std::cout << "CO2 level = " << value << cO2Sensor->Units()[0] << std::endl;
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import upm_bmp280.*;
|
||||
import upm_interfaces.*;
|
||||
import upm_core.*;
|
||||
|
||||
public class BME280_Interface_Example
|
||||
{
|
||||
@ -35,9 +35,9 @@ public class BME280_Interface_Example
|
||||
// Instantiate a BME280 instance using default i2c bus and address
|
||||
BME280 sensor = new BME280();
|
||||
|
||||
ITemperatureSensor t_sensor = sensor;
|
||||
IHumiditySensor h_sensor = sensor;
|
||||
IPressureSensor p_sensor = sensor;
|
||||
iTemperatureSensor t_sensor = sensor;
|
||||
iHumiditySensor h_sensor = sensor;
|
||||
iPressureSensor p_sensor = sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
@ -51,15 +51,15 @@ public class BME280_Interface_Example
|
||||
System.out.println("Calling Interface Functions: ");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ t_sensor.getTemperatureCelsius()
|
||||
+ t_sensor.TemperatureForSource("temperature")
|
||||
+ " C / ");
|
||||
|
||||
System.out.println("Pressure: "
|
||||
+ p_sensor.getPressurePa()
|
||||
+ p_sensor.PressureForSource("pressure")
|
||||
+ " Pa");
|
||||
|
||||
System.out.println("Humidity: "
|
||||
+ h_sensor.getHumidityRelative()
|
||||
+ h_sensor.HumidityForSource("humidity")
|
||||
+ " %RH");
|
||||
|
||||
System.out.println();
|
||||
|
@ -24,9 +24,9 @@ include(UseJava)
|
||||
# add_example(SensorFooExample sensorfoo)
|
||||
#
|
||||
# # Creates SensorFooExample JAVA target, depends on targets: sensorfoo,
|
||||
# # and interfaces and will add both upm_sensorfoo.jar and upm_interfaces.jar
|
||||
# # and core and will add both upm_sensorfoo.jar and upm_core.jar
|
||||
# # to the javac classpath.
|
||||
# add_example(SensorFooExample "sensorfoo;interfaces"")
|
||||
# add_example(SensorFooExample "sensorfoo;core"")
|
||||
#
|
||||
function(add_example example_class_name dependency_list)
|
||||
set(example_file "${example_class_name}.java")
|
||||
@ -68,7 +68,7 @@ add_example(A110X_Example a110x)
|
||||
add_example(A110X_intr_Example a110x)
|
||||
add_example(Ad8232_Example ad8232)
|
||||
add_example(ADC121C021_Example adc121c021)
|
||||
add_example(Ads1015_Example "ads1x15;interfaces")
|
||||
add_example(Ads1015_Example "ads1x15;core")
|
||||
add_example(Ads1115_Example ads1x15)
|
||||
add_example(Adxl345_Example adxl345)
|
||||
add_example(AM2315_Example am2315)
|
||||
@ -78,13 +78,13 @@ add_example(BH1750_Example bh1750)
|
||||
add_example(BISS0001_Example biss0001)
|
||||
add_example(BMA250E_Example bma250e)
|
||||
add_example(BMC150_Example bmx055)
|
||||
add_example(BME280_Example "bmp280;interfaces")
|
||||
add_example(BME280_Example "bmp280;core")
|
||||
add_example(BMG160_Example bmg160)
|
||||
add_example(BMI055_Example bmx055)
|
||||
add_example(BMI160_Example bmi160)
|
||||
add_example(BMM150_Example bmm150)
|
||||
add_example(BMP280_Example "bmp280;interfaces")
|
||||
add_example(BMPX8X_Example "bmpx8x;interfaces")
|
||||
add_example(BMP280_Example "bmp280;core")
|
||||
add_example(BMPX8X_Example "bmpx8x;core")
|
||||
add_example(BMX055_Example bmx055)
|
||||
add_example(BNO055_Example bno055)
|
||||
add_example(Button_Example button)
|
||||
@ -101,7 +101,7 @@ add_example(ECS1030_Example ecs1030)
|
||||
add_example(EHR_Example ehr)
|
||||
add_example(Emg_Example emg)
|
||||
add_example(ENC03R_Example enc03r)
|
||||
add_example(ES08A_Example "servo;interfaces")
|
||||
add_example(ES08A_Example "servo;core")
|
||||
add_example(FlexSensor_Example flex)
|
||||
add_example(Gp2y0a_Example gp2y0a)
|
||||
add_example(GroveButton_Example grove)
|
||||
@ -229,9 +229,9 @@ add_example(YG1006_Example yg1006)
|
||||
add_example(ZFM20_Example zfm20)
|
||||
|
||||
if(SWIG_VERSION VERSION_GREATER 3.0.8)
|
||||
add_example(BME280_Interface_Example "bmp280;interfaces")
|
||||
add_example(IMS_Example "ims;interfaces")
|
||||
add_example(RHUSB_Example "rhusb;interfaces")
|
||||
add_example(BME280_Interface_Example "bmp280;core")
|
||||
add_example(IMS_Example "ims;core")
|
||||
add_example(RHUSB_Example "rhusb;core")
|
||||
endif()
|
||||
|
||||
if (OPENZWAVE_FOUND)
|
||||
|
@ -50,4 +50,4 @@ public class ES08A_Example {
|
||||
System.out.println("Set angle to 180");
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_ims.IMS;
|
||||
|
||||
public class IMS_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
@ -31,18 +29,18 @@ public class IMS_Example
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using bus 0 and default i2c address
|
||||
IMS sensor = new IMS((short)0);
|
||||
upm_ims.IMS sensor = new upm_ims.IMS((short)0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Version: "
|
||||
+ sensor.get_version()
|
||||
+ upm_ims.javaupm_ims.LibraryVersion()
|
||||
+ " light: "
|
||||
+ sensor.get_light()
|
||||
+ sensor.LightForSource("light")
|
||||
+ " moisture: "
|
||||
+ sensor.get_moisture()
|
||||
+ sensor.MoistureForSource("moisture")
|
||||
+ " temp: "
|
||||
+ sensor.get_temperature()
|
||||
+ sensor.TemperatureForSource("temperature")
|
||||
+ " C");
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
42
examples/java/NoelsTempLightReaderSample.java
Normal file
42
examples/java/NoelsTempLightReaderSample.java
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Author: Your Full Name <your@email.address>
|
||||
* Copyright (c) <year> <copyright holder>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import upm_noelstemplightreader.*;
|
||||
|
||||
public class NoelsTempLightReaderSample {
|
||||
public static void main (String args[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate new sensor instance
|
||||
upm_noelstemplightreader.NoelsTempLightReader sensor = new upm_noelstemplightreader.NoelsTempLightReader();
|
||||
|
||||
while (true) {
|
||||
|
||||
//System.out.println("NoelsTempLightReader says: " + sensor.Name());
|
||||
|
||||
// Repeate every 2 seconds
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
@ -39,6 +39,12 @@ public class RHUSB_Example {
|
||||
// Instantiate an RHUSB instance on defaultDev
|
||||
upm_rhusb.RHUSB sensor = new upm_rhusb.RHUSB(defaultDev);
|
||||
|
||||
// Print out info from the sensor core
|
||||
System.out.println("UPM Version:" + System.lineSeparator()
|
||||
+ upm_rhusb.javaupm_rhusb.LibraryVersion() + System.lineSeparator());
|
||||
System.out.println("JSON Definition:" + System.lineSeparator()
|
||||
+ sensor.JsonDefinition() + System.lineSeparator());
|
||||
|
||||
// output the firmware ID
|
||||
System.out.println("Firmware ID: " + sensor.getFirmwareID());
|
||||
|
||||
|
40
examples/javascript/noelstemplightreader.js
Normal file
40
examples/javascript/noelstemplightreader.js
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Author: Your Full Name <your@email.address>
|
||||
* Copyright (c) <year> <copyright holder>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
var jsupm_noelstemplightreader = require('jsupm_noelstemplightreader');
|
||||
|
||||
// Create an instance of the sensor
|
||||
var sensor = new upm_noelstemplightreader.NoelsTempLightReader(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
// Call a method from the noelstemplightreader
|
||||
console.log("NoelsTempLightReader says: " + sensor.helloWorld());
|
||||
|
||||
// Call loop every 2 seconds
|
||||
setTimeout(loop, 2000);
|
||||
}
|
39
examples/python/noelstemplightreader.py
Executable file
39
examples/python/noelstemplightreader.py
Executable file
@ -0,0 +1,39 @@
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Author: Your Full Name <your@email.address>
|
||||
# Copyright (c) <year> <copyright holder>
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
import time
|
||||
from upm import pyupm_noelstemplightreader
|
||||
|
||||
def main():
|
||||
# Create an instance of NoelsTempLightReader
|
||||
sensor = pyupm_noelstemplightreader.NoelsTempLightReader(0)
|
||||
|
||||
while True:
|
||||
print("NoelsTempLightReader says: %s" % sensor.helloWorld)
|
||||
|
||||
# Repeat every 2 seconds
|
||||
sleep(2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user