Compare commits

..

23 Commits

Author SHA1 Message Date
4faa71d239 upm: v0.7.3
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-04 17:19:04 -07:00
5265bada9c ms5611: description and some doxygen tags updated
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-04 17:12:45 -07:00
84067826eb upm.h: Added manufacturwer entry for Measurement Specialties
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-04 17:12:28 -07:00
98e3621c93 ms5611: Initial implementation
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-04 17:12:10 -07:00
d79799bab9 docs: updated doxygen tags for some sensors
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-04 17:11:52 -07:00
49e04593d8 build: remove unnecessary BUILDSWIG option
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-08-03 11:54:36 -06:00
bda66a3d06 grovetemp: updated conversion formula for v1.2 compatibility
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-02 10:16:46 -07:00
84a77730be examples: updated module names for some C++ examples
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-01 18:33:00 -07:00
b08fc8d48d grove: split code base for grove sensors into individual files
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-08-01 18:25:36 -07:00
e64f192fb7 apds9930: enable sensor before read out sensor data
Changes in library:
- enableProximity() function is to enable or disable proximity sensor
- enableIlluminance() function is to enable or disable illuminance sensor
- run clang-format

Changes in example:
- proximity and illuminance kernel IIO-based driver init state is power off,
  require enable before read out sensor data. Sleep time is needed after
  enable, the sleep time may vary on different platform.
- run clang-format

Signed-off-by: Lay, Kuan Loon <kuan.loon.lay@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-07-22 16:30:25 -07:00
40fe6654eb ublox6: Add most popular baud rates to GPS enums
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-07-22 15:33:05 -07:00
e740335701 travis.yml: force install of swig3.0 even if not authenticated
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-07-19 15:17:57 -07:00
b257d91702 mpr121: fixed default value for filter configuration register
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-07-19 10:08:52 -07:00
e7394217b1 mlx90614: set i2c bus speed to 100 kHz on init to match sensor specs
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-07-14 14:41:03 -07:00
baec9966f0 spelling: correct many misspellings of celsius
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-07-12 17:42:01 -06:00
0fb56356fb bmx055: fix up some issues reported by static analysis
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-07-12 16:05:22 -06:00
e0ef6eea64 ozw: fix up some issues reported by static analysis
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-07-12 16:05:13 -06:00
743730550c CMakeLists.txt: move example subdir adds after add_subdirectory(src) is called
This will ensure that all src modules are scanned first before
examples (c++/java).

In certain cases when doing parallel builds with many cores (8), the
examples for MODBUS, BACNET, and OPENZWAVE would not be built, since
their dependant libraries had not yet been located (in the src/
dir(s) via pkg_check_modules()), by the time the examples were being
compiled.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-07-06 16:49:55 -06:00
9ab9e2c403 ozw: Rework and add some device specific drivers and examples.
This commit reworks ozw somewhat and adds some device specific drivers
with examples.  All of these drivers are kept in the UPM ozw library.

The OZW class has been reworked to make it a proper singleton, since
the OpenZWave::Manager() it depends on is already a singleton.  This
avoids issues such as opening and initializing OpenZWave multiple
times.

A new, relatively thin base class, ozwInterface is also now present.
This class wraps some basic functionality, and handles initialization
of the OZW base class.  It is intended to be inherited by device
driver classes.  It operates on a node id for a device.  Each OZW
device is referenced by a node id, which does not change unless the
device is removed (and possibly re-added) to a Z-Wave network.

Finally, a series of device specific drivers have been implemented.
These provide basic functionality to monitor and in some cases control
the operation of a Z-Wave device.  They are the following:

ozwdump - This is a fake 'device' driver that initializes an OZW
network and dumps information on all of the nodes (devices) present.
Along with each node, available information on each valueid associated
with that node is also printed.  This fake device and it's examples
replace the original ozw example.

aeotecss6 - Aeotec Smart Switch 6.  This device allows control of the
switch, as well as reporting of information the switch makes
available, such as current consumption, volts, watts, and accumulated
energy use (kWh).

aeotecsdg2 - Aeotec Smart Dimmer Gen 2.  This device is similar to the
Smart Switch 6, but also provides dimming functionality.  It also
provides information on energy use.

aeotecdw2e - Aeotec Door/Window Sensor 2nd Edition.  This device is a
magnetic switch with an embedded tamper switch used to detect the
opening/closing of windows and doors.  This is a battery powered
device.

aeotecdsb09104 - Aeotec Home Energy Monitor.  This device is intended
to be installed at the MAINS or Breaker box.  It reports current and
cumulative energy consumption.

tzemt400 - Trane TZEMT400 Thermostat.  This device is a thermostat
with Z-Wave functionality.  The variant tested was the
TZEMT400BB32MAA.  The driver reports various information on the status
of the thermostat, as well as the current measured temperature.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-07-06 15:13:00 -06:00
8da6095c35 travis: Updated ppa for swig3.0
UPM requires swig 3.0.5 which *was* offered in fenics-exp, but is
no longer available there.  Switched to fenics-dev.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-07-01 10:18:01 -07:00
1849e22154 upm: v0.7.2
Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-06-30 16:28:44 -07:00
dec9b2096e mraa: Updated mraa dependecy to 1.1.1
There were api changes for iio kernel support on mraa which cascade to
UPM - setting the minimum version of mraa required.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-06-30 15:15:50 -07:00
e1df8b5bf6 iio_core: Patches for IIO core kernel standard
Applying patches from Kuan Loon Lay.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-06-30 14:57:19 -07:00
167 changed files with 6079 additions and 1320 deletions

View File

@ -17,9 +17,9 @@ compiler:
- clang
- gcc
install:
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-dev/swig
- sudo apt-get update -qq
- sudo apt-get install -y -qq swig3.0 git
- sudo apt-get install -y --force-yes -qq swig3.0 git
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
- sudo update-java-alternatives -s java-8-oracle
before_script:

View File

@ -10,7 +10,7 @@ find_package (PkgConfig REQUIRED)
# Force a libmraa search and minimum required version every time a config is generated
unset(MRAA_FOUND CACHE)
pkg_check_modules (MRAA REQUIRED mraa>=1.0.0)
pkg_check_modules (MRAA REQUIRED mraa>=1.1.1)
message (INFO " found mraa version: ${MRAA_VERSION}")
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
message (WARNING " - Install git to compile a production UPM!")
set (VERSION "v0.7.1-dirty")
set (VERSION "v0.7.3-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")
@ -49,20 +49,19 @@ set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_
set (CMAKE_SWIG_FLAGS "")
option (BUILDDOC "Build all doc." OFF)
option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (BUILDTESTS "Generate check-ups for upm" ON)
option (ENABLECXX11 "Enable C++11 standards support" ON)
# Find swig
if (BUILDSWIG)
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
if (BUILDSWIGNODE)
find_package (SWIG 3.0.5 REQUIRED)
else ()
@ -125,7 +124,7 @@ if (BUILDDOC)
endif (DOXYGEN_FOUND)
# Check if Sphinx is installed and add target to generate API documentation
find_package (Sphinx)
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
if(SPHINX_FOUND AND BUILDSWIGPYTHON)
# Python required for Sphinx build
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
@ -231,14 +230,6 @@ if (RPM)
include(CPack)
endif()
if(BUILDEXAMPLES)
add_subdirectory (examples/c++)
endif()
if(BUILDJAVAEXAMPLES)
add_subdirectory (examples/java)
endif()
if (BUILDSWIGPYTHON OR BUILDTESTS)
if (BUILDPYTHON3)
set (PYTHONBUILD_VERSION 3)
@ -248,6 +239,14 @@ if (BUILDSWIGPYTHON OR BUILDTESTS)
endif ()
add_subdirectory (src)
if(BUILDEXAMPLES)
add_subdirectory (examples/c++)
endif()
if(BUILDJAVAEXAMPLES)
add_subdirectory (examples/java)
endif()
if (BUILDTESTS)
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)

View File

@ -4,6 +4,10 @@ API Changes {#apichanges}
Here's a list of other API changes made to the library that break source/binary
compatibility between releases:
* There were frequent misspellings of the word *Celsius* in the UPM
code. In some cases, these were in method names, which will cause
some API compatibility issues. These have all been corrected for UPM
versions after v.0.7.2.
* Our **C++ header files** changed their extension from *.h* to *.hpp* in
version 0.7.0, Intel provided examples and code samples also reflect this
change but you will need to modify your `#include` directives in existing code
@ -12,4 +16,3 @@ compatibility between releases:
* **stepmotor** driver API was changed significantly from v.0.4.1 to v.0.5.0
* **eboled** library was greatly improved in version 0.4.0 and the `draw()`
function was removed in favor of a more complete GFX library implementation

View File

@ -4,6 +4,23 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library
from earlier versions:
### v0.7.3
* Fixed several existing drivers and updated Grove Temperature sensor to use
new formula for v1.1+ by default
* Separated codebase for upm_grove module that bundles some of the starter kit
sensors into individual source files
* Documentation and doxygen tag updates with correct spelling for Celsius in
several places, this also affects API compatibility
* Removed superfluous BUILDSWIG option, some build recipes might be impacted
* New sensor: ms5611
### v0.7.2
* Mraa 1.1.1 required changes to UPM drivers and examples for IIO core
kernel support
* Rev'ed libmraa requirement to 1.1.1
### v0.7.1
* Fix for building python2 vs python3 bindings

View File

@ -224,10 +224,6 @@ add_example (groveultrasonic)
add_example (sx1276-lora)
add_example (sx1276-fsk)
add_example (ili9341)
if (OPENZWAVE_FOUND)
include_directories(${OPENZWAVE_INCLUDE_DIRS})
add_example (ozw)
endif()
add_example (nlgpio16)
add_example (ads1x15)
if (MODBUS_FOUND)
@ -272,6 +268,7 @@ add_example (bmp280)
add_example (bno055)
add_example (l3gd20)
add_example (bmx055)
add_example (ms5611)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
@ -290,9 +287,9 @@ add_custom_example (ak8975-example ak8975.cxx mpu9150)
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example groveledbar.cxx my9221)
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bme280")
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bme280")
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bmp280")
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bmp280")
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bmp280")
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
@ -303,3 +300,13 @@ add_custom_example (bmg160-example bmg160.cxx bmx055)
add_custom_example (bmm150-example bmm150.cxx bmx055)
add_custom_example (bmc150-example bmc150.cxx bmx055)
add_custom_example (bmi055-example bmi055.cxx bmx055)
if (OPENZWAVE_FOUND)
include_directories(${OPENZWAVE_INCLUDE_DIRS})
add_custom_example (ozwdump-example ozwdump.cxx ozw)
add_custom_example (aeotecss6-example aeotecss6.cxx ozw)
add_custom_example (aeotecsdg2-example aeotecsdg2.cxx ozw)
add_custom_example (aeotecdw2e-example aeotecdw2e.cxx ozw)
add_custom_example (aeotecdsb09104-example aeotecdsb09104.cxx ozw)
add_custom_example (tzemt400-example tzemt400.cxx ozw)
endif()

View File

@ -0,0 +1,123 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "aeotecdsb09104.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an Aeotec DSB09104 instance, on device node 12. You
// will almost certainly need to change this to reflect your own
// network. Use the ozwdump example to see what nodes are
// available.
upm::AeotecDSB09104 *sensor = new upm::AeotecDSB09104(12);
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
cout << "Querying data..." << endl;
while (shouldRun)
{
sensor->update();
cout << "Watts, Channel 1: "
<< sensor->getWattsC1()
<< " W"
<< endl;
cout << "Watts, Channel 2: "
<< sensor->getWattsC2()
<< " W"
<< endl;
cout << "Watts, Channel 3: "
<< sensor->getWattsC3()
<< " W"
<< endl;
cout << "Energy, Channel 1: "
<< sensor->getEnergyC1()
<< " kWh"
<< endl;
cout << "Energy, Channel 2: "
<< sensor->getEnergyC2()
<< " kWh"
<< endl;
cout << "Energy, Channel 3: "
<< sensor->getEnergyC3()
<< " kWh"
<< endl;
cout << "Battery Level: "
<< sensor->getBatteryLevel()
<< "%"
<< endl;
cout << endl;
sleep(3);
}
// sensor->dumpNodes(true);
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

109
examples/c++/aeotecdw2e.cxx Normal file
View File

@ -0,0 +1,109 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "aeotecdw2e.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an Aeotec Door/Window 2nd Edition sensor instance, on
// device node 10. You will almost certainly need to change this to
// reflect your own network. Use the ozwdump example to see what
// nodes are available.
upm::AeotecDW2E *sensor = new upm::AeotecDW2E(10);
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
cout << "Querying data..." << endl;
while (shouldRun)
{
if (sensor->isDeviceAvailable())
{
cout << "Alarm status: "
<< sensor->isAlarmTripped()
<< endl;
cout << "Tamper Switch status: "
<< sensor->isTamperTripped()
<< endl;
cout << "Battery Level: "
<< sensor->getBatteryLevel()
<< "%"
<< endl;
cout << endl;
}
else
{
cout << "Device has not yet responded to probe."
<< endl;
cout << "Try waking it, or wait until it wakes itself if configured"
<< " to do so."
<< endl;
cout << endl;
}
sleep(1);
}
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

127
examples/c++/aeotecsdg2.cxx Normal file
View File

@ -0,0 +1,127 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "aeotecsdg2.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an Aeotec Smart Dimmer Gen2 instance, on device node
// 9. You will almost certainly need to change this to reflect your
// own network. Use the ozwdump example to see what nodes are
// available.
upm::AeotecSDG2 *sensor = new upm::AeotecSDG2(9);
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
// turn light on
cout << "Turning switch on, then sleeping for 5 secs" << endl;
sensor->on();
sleep(5);
cout << "Querying data..." << endl;
bool dim = false;
while (shouldRun)
{
// put on a light show...
if (dim)
sensor->setLevel(25);
else
sensor->on();
dim = !dim;
sensor->update();
cout << "Current Level: "
<< sensor->getLevel()
<< endl;
cout << "Volts: "
<< sensor->getVolts()
<< " volts"
<< endl;
cout << "Energy Consumption: "
<< sensor->getEnergy()
<< " kWh"
<< endl;
cout << "Watts: "
<< sensor->getWatts()
<< endl;
cout << "Current: "
<< sensor->getCurrent()
<< " amps"
<< endl;
cout << endl;
sleep(5);
}
cout << "Turning switch off and sleeping for 5 seconds..." << endl;
sensor->off();
sleep(5);
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

117
examples/c++/aeotecss6.cxx Normal file
View File

@ -0,0 +1,117 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "aeotecss6.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an Aeotec SS6 instance, on device node 11. You will
// almost certainly need to change this to reflect your own network.
// Use the ozwdump example to see what nodes are available.
upm::AeotecSS6 *sensor = new upm::AeotecSS6(11);
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
// turn light on
cout << "Turning switch on, then sleeping for 5 secs" << endl;
sensor->on();
sleep(5);
cout << "Querying data..." << endl;
while (shouldRun)
{
sensor->update();
cout << "Switch status: "
<< sensor->isOn()
<< endl;
cout << "Volts: "
<< sensor->getVolts()
<< " volts"
<< endl;
cout << "Energy Consumption: "
<< sensor->getEnergy()
<< " kWh"
<< endl;
cout << "Watts: "
<< sensor->getWatts()
<< endl;
cout << "Current: "
<< sensor->getCurrent()
<< " amps"
<< endl;
cout << endl;
sleep(3);
}
cout << "Turning switch off and sleeping for 5 seconds..." << endl;
sensor->off();
sleep(5);
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -46,6 +46,15 @@ main()
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
upm::APDS9930* light_proximity = new upm::APDS9930(4);
// Kernel driver implement sleep 5000-5100us after enable illuminance sensor
light_proximity->enableIlluminance(true);
// Kernel driver implement sleep 5000-5100us after enable proximity sensor
light_proximity->enableProximity(true);
// Tested this value works. Please change it on your platform
usleep(120000);
while (shouldRun) {
float lux = light_proximity->getAmbient();
cout << "Luminance value is " << lux << endl;
@ -53,6 +62,8 @@ main()
cout << "Proximity value is " << proximity << endl;
sleep(1);
}
light_proximity->enableProximity(false);
light_proximity->enableIlluminance(false);
//! [Interesting]
cout << "Exiting" << endl;

View File

@ -53,7 +53,7 @@ int main(int argc, char **argv)
// Output data every second until interrupted
while (shouldRun)
{
printf("Temperature: %f Celcius\n", bar->getTemperature());
printf("Temperature: %f Celsius\n", bar->getTemperature());
printf("Pressure: %f Millibars\n", bar->getPressure());
printf("Altitude: %f Meters\n", bar->getAltitude());

11
examples/c++/kxcjk1013.cxx Executable file → Normal file
View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,8 +22,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <signal.h>
#include "kxcjk1013.hpp"
@ -44,7 +45,8 @@ data_callback(char* data)
{
float x, y, z;
accelerometer->extract3Axis(data, &x, &y, &z);
printf("% .1f % .1f % .1f\n", x, y, z);
cout << fixed << setprecision(1);
cout << x << '\t' << y << '\t' << z << "[m/s^2]" << endl;
}
int
@ -54,7 +56,10 @@ main()
//! [Interesting]
// Instantiate a KXCJK1013 Accelerometer Sensor on iio device 0
accelerometer = new upm::KXCJK1013(0);
// Available scales are 0.009582(2g), 0.019163(4g), and 0.038326(8g)
accelerometer->setScale(0.019163);
// Available sampling frequency are 0.781000, 1.563000, 3.125000, 6.250000, 12.500000, 25, 50,
// 100, 200, 400, 800, and 1600
accelerometer->setSamplingFrequency(25.0);
accelerometer->enable3AxisChannel();
accelerometer->installISR(data_callback, NULL);

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,8 +22,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <signal.h>
#include "l3gd20.hpp"
@ -43,8 +44,10 @@ void
data_callback(char* data)
{
float x, y, z;
if (gyroscope->extract3Axis(data, &x, &y, &z))
printf("% .2f % .2f % .2f\n", x, y, z);
if (gyroscope->extract3Axis(data, &x, &y, &z)) {
cout << fixed << setprecision(1);
cout << x << '\t' << y << '\t' << z << "[rad/sec]" << endl;
}
}
int
@ -54,7 +57,9 @@ main()
//! [Interesting]
// Instantiate a L3GD20 Gyroscope Sensor on iio device 3
gyroscope = new upm::L3GD20(3);
// Available scales are 0.000153(250dps), 0.000305(500dps), and 0.001222(2000dps)
gyroscope->setScale(0.001222);
// Available sampling frequency are 95, 190, 380, and 760
gyroscope->setSamplingFrequency(95.0);
gyroscope->enable3AxisChannel();
gyroscope->installISR(data_callback, NULL);

View File

@ -18,7 +18,7 @@ int main()
cout << "1 - read temp \t" ;
cout << "2 - sleep mode \t";
cout << "3 - wake up" << endl;
cout << "4 - set mode to " << (temp->isCelsius() == true ? "Fahrenheit" : "Celcius") << endl;
cout << "4 - set mode to " << (temp->isCelsius() == true ? "Fahrenheit" : "Celsius") << endl;
cout << "5 - show status bits" << endl;
cout << "6 - Set Tcrit \t" ;
cout << "7 - Set Tupper \t" ;
@ -53,7 +53,7 @@ int main()
temp->shutDown(false);
break;
case 4:
cout << "set mode to " << (temp->isCelsius() ? "Fahrenheit" : "Celcius") << endl;
cout << "set mode to " << (temp->isCelsius() ? "Fahrenheit" : "Celsius") << endl;
temp->setMode(!temp->isCelsius());
break;
case 5:

63
examples/c++/ms5611.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "ms5611.hpp"
static int is_running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
is_running = 1;
}
}
//! [Interesting]
int
main(int argc, char **argv)
{
upm::MS5611* sensor = new upm::MS5611(0);
signal(SIGINT, sig_handler);
while (!is_running) {
int value = sensor->getTemperatureCelsius();
std::cout << "Temperature = " << value << "C" << std::endl;
value = sensor->getPressurePa();
std::cout << "Pressure = " << value << "Pa" << std::endl;
sleep(1);
}
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}
//! [Interesting]

View File

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -25,7 +25,7 @@
#include <unistd.h>
#include <iostream>
#include "ozw.hpp"
#include "ozwdump.hpp"
using namespace std;
@ -39,53 +39,49 @@ int main(int argc, char **argv)
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate an OZW instance
upm::OZW *sensor = new upm::OZW();
// Instantiate an OZWDUMP instance
upm::OZWDUMP *sensor = new upm::OZWDUMP();
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
if (!sensor->init(defaultDev))
{
cerr << "Init failed." << endl;
return 0;
}
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
cout << "Dumping nodes..." << endl;
sensor->dumpNodes();
sensor->dumpNodes(true);
// The following is example output of dumpNodes:
//
// Dumping nodes...
// Node 1: Z-Stick Gen5
// Node 2: Smart Switch 6
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Energy, Value: 1.190 kWh
// Index: 3, Type: float, Label: Previous Reading, Value: 1.190 kWh
// Index: 4, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 5, Type: float, Label: Power, Value: 0.000 W
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
// Index: 7, Type: float, Label: Current, Value: 0.000 A
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Node 3: Multi Sensor
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 1, Type: float, Label: Temperature, Value: 72.8 F
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
// Node 5: Minimote
// Node 6: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 1.609 kWh
@ -93,9 +89,9 @@ int main(int argc, char **argv)
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
// Index: 9, Type: bool, Label: Exporting, Value: False
// Node 7: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 0.000 kWh
@ -103,39 +99,14 @@ int main(int argc, char **argv)
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 0.000 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
// Index: 9, Type: bool, Label: Exporting, Value: False
//
// So, with the above in mind:
//
// 1. Query the temperature on node 3 and print it out (as a
// string), along with the units of measure:
//
// cout << "Temperature: " << sensor->getValueAsString(3, 1)
// << " " << sensor->getValueUnits(3, 1) << endl;
//
// 2. query the same temperature as a float:
//
// float temperature = sensor->getValueAsFloat(3, 1);
//
// 3. Turn on the light plugged into the switch on Node 7, wait 5
// seconds, then turn it back off again:
//
// cout << "Turning ON node 7" << endl;
// sensor->setValueAsBool(7, 0, true);
//
// cout << "Sleeping for 5 seconds" << endl;
// sleep(5);
//
// cout << "Turning OFF node 7" << endl;
// sensor->setValueAsBool(7, 0, false);
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -35,7 +35,7 @@ int main ()
try {
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
while (true) {
int temperature = sensor->getTemperatureCelcius();
int temperature = sensor->getTemperatureCelsius();
int humidity = sensor->getHumidityRelative();
std::cout << "Temperature = " << temperature << "C" << std::endl;
std::cout << "Humidity = " << humidity << "%" << std::endl;

View File

@ -76,7 +76,7 @@ int main ()
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = temperatureSensor->getTemperatureCelcius();
int value = temperatureSensor->getTemperatureCelsius();
std::cout << "Temperature = " << value << "C" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;

114
examples/c++/tzemt400.cxx Normal file
View File

@ -0,0 +1,114 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "tzemt400.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
// Instantiate a TZEMT400 instance, on device node 13. You will
// almost certainly need to change this to reflect your own network.
// Use the ozwdump example to see what nodes are available.
upm::TZEMT400 *sensor = new upm::TZEMT400(13);
// The first thing to do is create options, then lock them when done.
sensor->optionsCreate();
sensor->optionsLock();
// Next, initialize it.
cout << "Initializing, this may take awhile depending on your ZWave network"
<< endl;
sensor->init(defaultDev);
cout << "Initialization complete" << endl;
cout << "Querying data..." << endl;
while (shouldRun)
{
sensor->update();
// we show both C and F for temperatures
cout << "Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
cout << "Mode: "
<< sensor->getMode()
<< endl;
cout << "Operating State: "
<< sensor->getOperatingState()
<< endl;
cout << "Heating Point: " << sensor->getHeatingPointTemperature()
<< " C / " << sensor->getHeatingPointTemperature(true) << " F"
<< endl;
cout << "Cooling Point: " << sensor->getCoolingPointTemperature()
<< " C / " << sensor->getCoolingPointTemperature(true) << " F"
<< endl;
cout << "Fan Mode: "
<< sensor->getFanMode()
<< endl;
cout << "Fan State: "
<< sensor->getFanState()
<< endl;
cout << endl;
sleep(5);
}
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -0,0 +1,96 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
import upm_ozw.AeotecDSB09104;
public class AeotecDSB09104_Example
{
private static String defaultDev = "/dev/ttyACM0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
// Instantiate an Aeotec DSB09104 instance, on device node 12.
// You will almost certainly need to change this to reflect
// your own network. Use the ozwdump example to see what
// nodes are available.
AeotecDSB09104 sensor = new AeotecDSB09104(12);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
System.out.println("Initializing, this may take awhile depending "
+ "on your ZWave network");
sensor.init(defaultDev);
System.out.println("Initialization complete");
System.out.println("Querying data...");
while (true)
{
sensor.update();
System.out.println("Watts, Channel 1: "
+ sensor.getWattsC1()
+ " W");
System.out.println("Watts, Channel 2: "
+ sensor.getWattsC2()
+ " W");
System.out.println("Watts, Channel 3: "
+ sensor.getWattsC3()
+ " W");
System.out.println("Energy, Channel 1: "
+ sensor.getEnergyC1()
+ " kWh");
System.out.println("Energy, Channel 2: "
+ sensor.getEnergyC2()
+ " kWh");
System.out.println("Energy, Channel 3: "
+ sensor.getEnergyC3()
+ " kWh");
System.out.println("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
System.out.println();
Thread.sleep(3000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,89 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
import upm_ozw.AeotecDW2E;
public class AeotecDW2E_Example
{
private static String defaultDev = "/dev/ttyACM0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
// Instantiate an Aeotec Door/Window 2nd Edition sensor
// instance, on device node 10. You will almost certainly
// need to change this to reflect your own network. Use the
// ozwdump example to see what nodes are available.
AeotecDW2E sensor = new AeotecDW2E(10);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
System.out.println("Initializing, this may take awhile depending "
+ "on your ZWave network");
sensor.init(defaultDev);
System.out.println("Initialization complete");
System.out.println("Querying data...");
while (true)
{
if (sensor.isDeviceAvailable())
{
System.out.println("Alarm status: "
+ sensor.isAlarmTripped());
System.out.println("Tamper Switch status: "
+ sensor.isTamperTripped());
System.out.println("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
System.out.println();
}
else
{
System.out.println("Device has not yet responded "
+ "to probe.");
System.out.println("Try waking it, or wait until "
+ "it wakes itself if "
+ "configured to do so.");
System.out.println();
}
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,100 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
import upm_ozw.AeotecSDG2;
public class AeotecSDG2_Example
{
private static String defaultDev = "/dev/ttyACM0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
// Instantiate an Aeotec Smart Dimmer Gen2 instance, on device node
// 9. You will almost certainly need to change this to reflect your
// own network. Use the ozwdump example to see what nodes are
// available.
AeotecSDG2 sensor = new AeotecSDG2(9);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
System.out.println("Initializing, this may take awhile depending "
+ "on your ZWave network");
sensor.init(defaultDev);
System.out.println("Initialization complete");
// turn light on
System.out.println("Turning switch on, then sleeping for 5 secs");
sensor.on();
Thread.sleep(5000);
System.out.println("Querying data...");
boolean dim = false;
while (true)
{
// put on a light show...
if (dim)
sensor.setLevel(25);
else
sensor.on();
dim = !dim;
sensor.update();
System.out.println("Switch status: "
+ sensor.isOn());
System.out.println("Volts: "
+ sensor.getVolts()
+ " volts");
System.out.println("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
System.out.println("Watts: "
+ sensor.getWatts());
System.out.println("Current: "
+ sensor.getCurrent()
+ " amps");
System.out.println();
Thread.sleep(5000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,91 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
import upm_ozw.AeotecSS6;
public class AeotecSS6_Example
{
private static String defaultDev = "/dev/ttyACM0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
// Instantiate an Aeotec Smart Switch 6 instance, on device
// node 11. You will almost certainly need to change this to
// reflect your own network. Use the ozwdump example to see
// what nodes are available.
AeotecSS6 sensor = new AeotecSS6(11);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
System.out.println("Initializing, this may take awhile depending "
+ "on your ZWave network");
sensor.init(defaultDev);
System.out.println("Initialization complete");
// turn light on
System.out.println("Turning switch on, then sleeping for 5 secs");
sensor.on();
Thread.sleep(5000);
System.out.println("Querying data...");
while (true)
{
sensor.update();
System.out.println("Switch status: "
+ sensor.isOn());
System.out.println("Volts: "
+ sensor.getVolts()
+ " volts");
System.out.println("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
System.out.println("Watts: "
+ sensor.getWatts());
System.out.println("Current: "
+ sensor.getCurrent()
+ " amps");
System.out.println();
Thread.sleep(3000);
}
// ! [Interesting]
}
}

View File

@ -144,4 +144,11 @@ add_example_with_path(BMG160_Example bmx055 bmx055)
add_example_with_path(BMM150_Example bmx055 bmx055)
add_example_with_path(BMC150_Example bmx055 bmx055)
add_example_with_path(BMI055_Example bmx055 bmx055)
if (OPENZWAVE_FOUND)
add_example_with_path(AeotecSS6_Example ozw ozw)
add_example_with_path(AeotecSDG2_Example ozw ozw)
add_example_with_path(AeotecDW2E_Example ozw ozw)
add_example_with_path(AeotecDSB09104_Example ozw ozw)
add_example_with_path(TZEMT400_Example ozw ozw)
endif()

View File

@ -0,0 +1,98 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
import upm_ozw.TZEMT400;
public class TZEMT400_Example
{
private static String defaultDev = "/dev/ttyACM0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
// Instantiate a TZEMT400 instance, on device node 13. You
// will almost certainly need to change this to reflect your
// own network. Use the ozwdump example to see what nodes are
// available.
TZEMT400 sensor = new TZEMT400(13);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
System.out.println("Initializing, this may take awhile depending "
+ "on your ZWave network");
sensor.init(defaultDev);
System.out.println("Initialization complete");
System.out.println("Querying data...");
while (true)
{
sensor.update();
System.out.println("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
System.out.println("Mode: "
+ sensor.getMode());
System.out.println("Operating State: "
+ sensor.getOperatingState());
System.out.println("Heating Point: "
+ sensor.getHeatingPointTemperature()
+ " C / "
+ sensor.getHeatingPointTemperature(true)
+ " F");
System.out.println("Cooling Point: "
+ sensor.getCoolingPointTemperature()
+ " C / "
+ sensor.getCoolingPointTemperature(true)
+ " F");
System.out.println("Fan Mode: "
+ sensor.getFanMode());
System.out.println("Fan State: "
+ sensor.getFanState());
System.out.println();
Thread.sleep(5000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,103 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec DSB09104 instance, on device node 12. You
// will almost certainly need to change this to reflect your own
// network. Use the ozwdump example to see what nodes are
// available.
var sensor = new sensorObj.AeotecDSB09104(12);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Watts, Channel 1: "
+ sensor.getWattsC1()
+ " W");
console.log("Watts, Channel 2: "
+ sensor.getWattsC2()
+ " W");
console.log("Watts, Channel 3: "
+ sensor.getWattsC3()
+ " W");
console.log("Energy, Channel 1: "
+ sensor.getEnergyC1()
+ " kWh");
console.log("Energy, Channel 2: "
+ sensor.getEnergyC2()
+ " kWh");
console.log("Energy, Channel 3: "
+ sensor.getEnergyC3()
+ " kWh");
console.log("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
console.log();
}, 3000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,95 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Door/Window 2nd Edition sensor instance, on
// device node 10. You will almost certainly need to change this to
// reflect your own network. Use the ozwdump example to see what
// nodes are available.
var sensor = new sensorObj.AeotecDW2E(10);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
if (sensor.isDeviceAvailable())
{
console.log("Alarm status: "
+ sensor.isAlarmTripped());
console.log("Tamper Switch status: "
+ sensor.isTamperTripped());
console.log("Battery Level: "
+ sensor.getBatteryLevel()
+ "%");
console.log();
}
else
{
console.log("Device has not yet responded to probe.");
console.log("Try waking it, or wait until it wakes itself if "
+ "configured to do so.");
console.log();
}
}, 1000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,119 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
var sensorObj = require('jsupm_ozw');
function sleepFor(millis)
{
var now = new Date().getTime();
while(new Date().getTime() < now + millis)
{
/* do nothing */
}
}
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Smart Dimmer Gen2 instance, on device node
// 9. You will almost certainly need to change this to reflect your
// own network. Use the ozwdump example to see what nodes are
// available.
var sensor = new sensorObj.AeotecSDG2(9);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
// turn light on
console.log("Turning switch on, then sleeping for 5 secs");
sensor.on();
sleepFor(5000);
console.log("Querying data...");
var dim = false;
setInterval(function()
{
// put on a light show...
if (dim)
sensor.setLevel(25);
else
sensor.on();
dim = !dim;
sensor.update();
console.log("Current Level: "
+ sensor.getLevel());
console.log("Volts: "
+ sensor.getVolts()
+ " volts");
console.log("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
console.log("Watts: "
+ sensor.getWatts());
console.log("Current: "
+ sensor.getCurrent()
+ " amps");
console.log();
}, 5000);
// exit on ^C
process.on('SIGINT', function()
{
console.log("Turning switch off and sleeping for 5 seconds...");
sensor.off();
sleepFor(5000);
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,110 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
var sensorObj = require('jsupm_ozw');
function sleepFor(millis)
{
var now = new Date().getTime();
while(new Date().getTime() < now + millis)
{
/* do nothing */
}
}
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate an Aeotec Smart Switch 6 instance, on device node 11.
// You will almost certainly need to change this to reflect your own
// network. Use the ozwdump example to see what nodes are available.
var sensor = new sensorObj.AeotecSS6(11);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
// turn light on
console.log("Turning switch on, then sleeping for 5 secs");
sensor.on();
sleepFor(5000);
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Switch status: "
+ sensor.isOn());
console.log("Volts: "
+ sensor.getVolts()
+ " volts");
console.log("Energy Consumption: "
+ sensor.getEnergy()
+ " kWh");
console.log("Watts: "
+ sensor.getWatts());
console.log("Current: "
+ sensor.getCurrent()
+ " amps");
console.log();
}, 3000);
// exit on ^C
process.on('SIGINT', function()
{
console.log("Turning switch off and sleeping for 5 seconds...");
sensor.off();
sleepFor(5000);
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -37,7 +37,7 @@ bar.init();
// Output data every second until interrupted
setInterval(function()
{
console.log("Temperature: " + bar.getTemperature() + " Celcius");
console.log("Temperature: " + bar.getTemperature() + " Celsius");
console.log("Pressure: " + bar.getPressure() + " Millibars");
console.log("Altitude: " + bar.getAltitude() + " Meters");
console.log("");

View File

@ -0,0 +1,50 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2016 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.
*/
var factory = require('jsupm_ms5611');
// Instantiate a MS5611 instance using default i2c bus and address
var sensor = new factory.MS5611();
// now output data every 250 milliseconds
setInterval(function()
{
var temperature = sensor.getTemperatureCelsius();
var pressure = sensor.getPressurePa();
console.log("Temperature: " + temperature + " C");
console.log("Pressure: " + pressure + " Pa");
}, 250);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -3,7 +3,7 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -31,7 +31,7 @@ var sensorObj = require('jsupm_ozw');
/************** Main code **************/
// Instantiate an OZW instance
var sensor = new sensorObj.OZW();
var sensor = new sensorObj.OZWDUMP();
var defaultDev = "/dev/ttyACM0";
@ -48,42 +48,38 @@ sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
if (!sensor.init(defaultDev))
{
console.log("Init failed.");
process.exit(0);
}
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Dumping nodes...");
sensor.dumpNodes();
sensor.dumpNodes(true);
// The following is example output of dumpNodes:
//
// Dumping nodes...
// Node 1: Z-Stick Gen5
// Node 2: Smart Switch 6
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Energy, Value: 1.190 kWh
// Index: 3, Type: float, Label: Previous Reading, Value: 1.190 kWh
// Index: 4, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 5, Type: float, Label: Power, Value: 0.000 W
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
// Index: 7, Type: float, Label: Current, Value: 0.000 A
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Index: 8, Type: bool, Label: Exporting, Value: False
// Index: 45, Type: list, Label: Day, Value: Friday
// Index: 46, Type: byte, Label: Hour, Value: 5
// Index: 47, Type: byte, Label: Minute, Value: 53
// Node 3: Multi Sensor
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 0, Type: bool, Label: Sensor, Value: True
// Index: 1, Type: float, Label: Temperature, Value: 72.8 F
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
// Node 5: Minimote
// Node 6: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 1.609 kWh
@ -91,9 +87,9 @@ sensor.dumpNodes();
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
// Index: 9, Type: bool, Label: Exporting, Value: False
// Node 7: Smart Energy Switch
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 0, Type: bool, Label: Switch, Value: False
// Index: 2, Type: float, Label: Power, Value: 0.000 W
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
// Index: 4, Type: float, Label: Previous Reading, Value: 0.000 kWh
@ -101,24 +97,7 @@ sensor.dumpNodes();
// Index: 6, Type: float, Label: Power, Value: 0.000 W
// Index: 7, Type: float, Label: Previous Reading, Value: 0.000 W
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
// Index: 9, Type: bool, Label: Exporting, Value: False
//
// So, with the above in mind:
//
// 1. Query the temperature on node 3 and print it out (as a
// string), along with the units of measure:
//
// console.log("Temperature: " + sensor.getValueAsString(3, 1) +
// " " + sensor.getValueUnits(3, 1));
//
// 2. query the same temperature as a float:
//
// var temperature = sensor.getValueAsFloat(3, 1);
//
// 3. Turn on the light plugged into the switch on Node 7
//
// console.log("Turning ON node 7");
// sensor.setValueAsBool(7, 0, true);
// Index: 9, Type: bool, Label: Exporting, Value: False
//
sensor = null;

View File

@ -0,0 +1,104 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 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.
*/
var sensorObj = require('jsupm_ozw');
/************** Main code **************/
var defaultDev = "/dev/ttyACM0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
// Instantiate a TZEMT400 instance, on device node 13. You will
// almost certainly need to change this to reflect your own network.
// Use the ozwdump example to see what nodes are available.
var sensor = new sensorObj.TZEMT400(13);
// The first thing to do is create options, then lock them when done.
sensor.optionsCreate();
sensor.optionsLock();
// Next, initialize it.
console.log("Initializing, this may take awhile depending on your ZWave network");
sensor.init(defaultDev);
console.log("Initialization complete");
console.log("Querying data...");
setInterval(function()
{
sensor.update();
console.log("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
console.log("Mode: "
+ sensor.getMode());
console.log("Operating State: "
+ sensor.getOperatingState());
console.log("Heating Point: "
+ sensor.getHeatingPointTemperature()
+ " C / "
+ sensor.getHeatingPointTemperature(true)
+ " F");
console.log("Cooling Point: "
+ sensor.getCoolingPointTemperature()
+ " C / "
+ sensor.getCoolingPointTemperature(true)
+ " F");
console.log("Fan Mode: "
+ sensor.getFanMode());
console.log("Fan State: "
+ sensor.getFanState());
console.log();
}, 5000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,88 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
# Instantiate an Aeotec DSB09104 instance, on device node 12. You
# will almost certainly need to change this to reflect your own
# network. Use the ozwdump example to see what nodes are available.
sensor = sensorObj.AeotecDSB09104(12)
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
sensor.init(defaultDev)
print "Initialization complete"
print "Querying data..."
while (True):
sensor.update()
print "Watts, Channel 1:",
print sensor.getWattsC1(),
print "W"
print "Watts, Channel 2:",
print sensor.getWattsC2(),
print "W"
print "Watts, Channel 3:",
print sensor.getWattsC3(),
print "W"
print "Energy, Channel 1:",
print sensor.getEnergyC1(),
print "kWh"
print "Energy, Channel 2:",
print sensor.getEnergyC2(),
print "kWh"
print "Energy, Channel 3:",
print sensor.getEnergyC3(),
print "kWh"
print "Battery Level:",
print sensor.getBatteryLevel(),
print "%"
print
time.sleep(3)

View File

@ -0,0 +1,80 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
# Instantiate an Aeotec Door/Window 2nd Edition sensor instance, on
# device node 10. You will almost certainly need to change this to
# reflect your own network. Use the ozwdump example to see what nodes
# are available.
sensor = sensorObj.AeotecDW2E(10)
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
sensor.init(defaultDev)
print "Initialization complete"
print "Querying data..."
while (True):
if (sensor.isDeviceAvailable()):
print "Alarm status:",
print sensor.isAlarmTripped()
print "Tamper Switch status:",
print sensor.isTamperTripped()
print "Battery Level:",
print sensor.getBatteryLevel(),
print "%"
print
else:
print "Device has not yet responded to probe."
print "Try waking it, or wait until it wakes itself if ",
print "configured to do so."
print
time.sleep(1)

View File

@ -0,0 +1,96 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# This function lets you run code on exit
def exitHandler():
print "Turning switch off and sleeping for 5 seconds..."
sensor.off()
time.sleep(5)
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
# Instantiate an Aeotec Smart Dimmer Gen2 instance, on device node
# 9. You will almost certainly need to change this to reflect your
# own network. Use the ozwdump example to see what nodes are
# available.
sensor = sensorObj.AeotecSDG2(9)
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
sensor.init(defaultDev)
print "Initialization complete"
# turn light on
print "Turning switch on, then sleeping for 5 secs"
sensor.on();
time.sleep(5);
print "Querying data..."
dim = False;
while (True):
# put on a light show...
if (dim):
sensor.setLevel(25)
else:
sensor.on()
dim = not dim;
sensor.update()
print "Current Level:",
print sensor.getLevel()
print "Volts:",
print sensor.getVolts(),
print "volts"
print "Energy Consumption:",
print sensor.getEnergy(),
print "kWh"
print "Watts:",
print sensor.getWatts()
print "Current:",
print sensor.getCurrent(),
print "amps"
print
time.sleep(5)

View File

@ -0,0 +1,87 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# This function lets you run code on exit
def exitHandler():
print "Turning switch off and sleeping for 5 seconds..."
sensor.off()
time.sleep(5)
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
# Instantiate an Aeotec Smart Switch 6 instance, on device node 11.
# You will almost certainly need to change this to reflect your own
# network. Use the ozwdump example to see what nodes are available.
sensor = sensorObj.AeotecSS6(11)
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
sensor.init(defaultDev)
print "Initialization complete"
# turn light on
print "Turning switch on, then sleeping for 5 secs"
sensor.on();
time.sleep(5);
print "Querying data..."
while (True):
sensor.update()
print "Switch status:",
print sensor.isOn()
print "Volts:",
print sensor.getVolts(),
print "volts"
print "Energy Consumption:",
print sensor.getEnergy(),
print "kWh"
print "Watts:",
print sensor.getWatts()
print "Current:",
print sensor.getCurrent(),
print "amps"
print
time.sleep(3)

View File

@ -46,7 +46,7 @@ bar = barometerObj.HP20X()
bar.init()
while(1):
print "Temperature:", bar.getTemperature(), "Celcius"
print "Temperature:", bar.getTemperature(), "Celsius"
print "Pressure: ", bar.getPressure(), "Millibars"
print "Altitude: ", bar.getAltitude(), "Meters"
print

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2015 Intel Corporation.
# Copyright (c) 2015-2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@ -25,7 +25,7 @@ import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# Instantiate an OZW instance
sensor = sensorObj.OZW()
sensor = sensorObj.OZWDUMP()
# This function lets you run code on exit
def exitHandler():
@ -46,41 +46,39 @@ sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
if (not sensor.init(defaultDev)):
print "Init failed."
sys.exit(1)
sensor.init(defaultDev)
print "Initialization complete"
print "Dumping nodes..."
sensor.dumpNodes()
sensor.dumpNodes(True)
# The following is example output of dumpNodes:
#
# Dumping nodes...
# Node 1: Z-Stick Gen5
# Node 2: Smart Switch 6
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 2, Type: float, Label: Energy, Value: 1.190 kWh
# Index: 3, Type: float, Label: Previous Reading, Value: 1.190 kWh
# Index: 4, Type: int32, Label: Interval, Value: 1521 seconds
# Index: 5, Type: float, Label: Power, Value: 0.000 W
# Index: 6, Type: float, Label: Voltage, Value: 121.256 V
# Index: 7, Type: float, Label: Current, Value: 0.000 A
# Index: 8, Type: bool, Label: Exporting, Value: False
# Index: 45, Type: list, Label: Day, Value: Friday
# Index: 46, Type: byte, Label: Hour, Value: 5
# Index: 47, Type: byte, Label: Minute, Value: 53
# Index: 8, Type: bool, Label: Exporting, Value: False
# Index: 45, Type: list, Label: Day, Value: Friday
# Index: 46, Type: byte, Label: Hour, Value: 5
# Index: 47, Type: byte, Label: Minute, Value: 53
# Node 3: Multi Sensor
# Index: 0, Type: bool, Label: Sensor, Value: True
# Index: 0, Type: bool, Label: Sensor, Value: True
# Index: 1, Type: float, Label: Temperature, Value: 72.8 F
# Index: 2, Type: float, Label: Luminance, Value: 4 lux
# Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
# Index: 17, Type: byte, Label: Battery Level, Value: 98 %
# Node 5: Minimote
# Node 6: Smart Energy Switch
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 2, Type: float, Label: Power, Value: 0.000 W
# Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
# Index: 4, Type: float, Label: Previous Reading, Value: 1.609 kWh
@ -88,9 +86,9 @@ sensor.dumpNodes()
# Index: 6, Type: float, Label: Power, Value: 0.000 W
# Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
# Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
# Index: 9, Type: bool, Label: Exporting, Value: False
# Index: 9, Type: bool, Label: Exporting, Value: False
# Node 7: Smart Energy Switch
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 0, Type: bool, Label: Switch, Value: False
# Index: 2, Type: float, Label: Power, Value: 0.000 W
# Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
# Index: 4, Type: float, Label: Previous Reading, Value: 0.000 kWh
@ -98,29 +96,4 @@ sensor.dumpNodes()
# Index: 6, Type: float, Label: Power, Value: 0.000 W
# Index: 7, Type: float, Label: Previous Reading, Value: 0.000 W
# Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
# Index: 9, Type: bool, Label: Exporting, Value: False
#
# So, with the above in mind:
#
# 1. Query the temperature on node 3 and print it out (as a
# string), along with the units of measure:
#
# print "Temperature:", sensor.getValueAsString(3, 1),
# sensor->getValueUnits(3, 1)
#
# 2. query the same temperature as a float:
#
# temperature = sensor.getValueAsFloat(3, 1)
#
# 3. Turn on the light plugged into the switch on Node 7, wait 5
# seconds, then turn it back off again:
#
# print "Turning ON node 7"
# sensor.setValueAsBool(7, 0, true)
#
# print "Sleeping for 5 seconds";
# time.sleep(5)
#
# print "Turning OFF node 7"
# sensor.setValueAsBool(7, 0, false);
# Index: 9, Type: bool, Label: Exporting, Value: False

View File

@ -0,0 +1,82 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 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.
import time, sys, signal, atexit
import pyupm_ozw as sensorObj
# This function lets you run code on exit
def exitHandler():
print "Exiting..."
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
defaultDev = "/dev/ttyACM0"
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
# Instantiate a TZEMT400 instance, on device node 13. You will
# almost certainly need to change this to reflect your own network.
# Use the ozwdump example to see what nodes are available.
sensor = sensorObj.TZEMT400(13)
# The first thing to do is create options, then lock them when done.
sensor.optionsCreate()
sensor.optionsLock()
# Next, initialize it.
print "Initializing, this may take awhile depending on your ZWave network"
sensor.init(defaultDev)
print "Initialization complete"
print "Querying data..."
while (True):
sensor.update()
print "Temperature:", sensor.getTemperature(), "C /",
print sensor.getTemperature(True), "F"
print "Mode:",
print sensor.getMode()
print "Operating State:",
print sensor.getOperatingState()
print "Heating Point:", sensor.getHeatingPointTemperature(), "C /",
print sensor.getHeatingPointTemperature(True), "F"
print "Cooling Point:", sensor.getCoolingPointTemperature(), "C /",
print sensor.getCoolingPointTemperature(True), "F"
print "Fan Mode:",
print sensor.getFanMode()
print "Fan State:",
print sensor.getFanState()
print
time.sleep(5)

View File

@ -27,7 +27,7 @@ macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
macro(upm_SWIG_PYTHON)
if (BUILDSWIGPYTHON AND BUILDSWIG)
if (BUILDSWIGPYTHON)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}/..
@ -50,7 +50,7 @@ macro(upm_SWIG_PYTHON)
endmacro()
macro(upm_SWIG_NODE)
if (BUILDSWIGNODE AND BUILDSWIG)
if (BUILDSWIGNODE)
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
@ -112,7 +112,7 @@ macro(upm_SWIG_NODE)
endmacro()
macro(upm_SWIG_JAVA)
if (BUILDSWIGJAVA AND BUILDSWIG)
if (BUILDSWIGJAVA)
FIND_PACKAGE (JNI REQUIRED)
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
@ -166,7 +166,7 @@ macro(upm_doxygen)
set (classname ${libname})
endif()
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
if (BUILDSWIGPYTHON AND BUILDSWIG)
if (BUILDSWIGPYTHON)
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
add_dependencies (pydoc _pyupm_${libname})
else ()

View File

@ -7,13 +7,11 @@ include_directories("../pca9685")
upm_module_init()
add_dependencies(${libname} pca9685)
target_link_libraries(${libname} pca9685)
if (BUILDSWIG)
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} pca9685)
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} pca9685)
endif()
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} pca9685)
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} pca9685)
endif()

View File

@ -212,10 +212,10 @@ float ADIS16448::gyroScale(int16_t sensorData)
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Converts temperature data output from the sensorRead() function and returns temperature
// in degrees Celcius
// in degrees Celsius
/////////////////////////////////////////////////////////////////////////////////////////////
// sensorData - data output from sensorRead()
// return - (float) signed/scaled temperature in degrees Celcius
// return - (float) signed/scaled temperature in degrees Celsius
/////////////////////////////////////////////////////////////////////////////////////////
float ADIS16448::tempScale(int16_t sensorData)
{
@ -226,7 +226,7 @@ float ADIS16448::tempScale(int16_t sensorData)
// Converts barometer data output from sensorRead() function and returns pressure in bar
/////////////////////////////////////////////////////////////////////////////////////////////
// sensorData - data output from sensorRead()
// return - (float) signed/scaled temperature in degrees Celcius
// return - (float) signed/scaled temperature in degrees Celsius
/////////////////////////////////////////////////////////////////////////////////////////
float ADIS16448::pressureScale(int16_t sensorData)
{
@ -238,7 +238,7 @@ float ADIS16448::pressureScale(int16_t sensorData)
// reading in Gauss
/////////////////////////////////////////////////////////////////////////////////////////////
// sensorData - data output from sensorRead()
// return - (float) signed/scaled temperature in degrees Celcius
// return - (float) signed/scaled temperature in degrees Celsius
/////////////////////////////////////////////////////////////////////////////////////////
float ADIS16448::magnetometerScale(int16_t sensorData)
{

View File

@ -138,7 +138,7 @@ namespace upm {
float getZeroPoint() { return m_zeroPoint; };
/**
* Return the measured temperature in Celcius. Note, the
* Return the measured temperature in Celsius. Note, the
* datasheet says that this value is very repeatable, but is not
* an accurate absolute temperature.
*

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -41,7 +41,7 @@ APDS9930::APDS9930(int device)
APDS9930::~APDS9930()
{
if(m_iio)
if (m_iio)
mraa_iio_close(m_iio);
}
@ -60,3 +60,25 @@ APDS9930::getProximity()
mraa_iio_read_int(m_iio, "in_proximity_raw", &iio_value);
return iio_value;
}
bool
APDS9930::enableProximity(bool enable)
{
if (enable)
mraa_iio_write_int(m_iio, "in_proximity_en", 1);
else
mraa_iio_write_int(m_iio, "in_proximity_en", 0);
return true;
}
bool
APDS9930::enableIlluminance(bool enable)
{
if (enable)
mraa_iio_write_int(m_iio, "in_illuminance_en", 1);
else
mraa_iio_write_int(m_iio, "in_illuminance_en", 0);
return true;
}

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -75,6 +75,16 @@ class APDS9930
* @return Proximity value
*/
int getProximity();
/**
* Enable proximity
* @param enable state
*/
bool enableProximity(bool enable);
/**
* Enable illuminance
* @param enable state
*/
bool enableIlluminance(bool enable);
private:
mraa_iio_context m_iio;

View File

@ -10,15 +10,13 @@ if (BACNET_FOUND)
upm_module_init()
add_dependencies(${libname} ${BACNET_LIBRARIES})
target_link_libraries(${libname} ${BACNET_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
if (BUILDSWIG)
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${BACNET_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${BACNET_LIBRARIES})
endif()
if (BUILDSWIGJAVA)
swig_link_libraries (javaupm_${libname} ${BACNET_LIBRARIES})
endif()
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${BACNET_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${BACNET_LIBRARIES})
endif()
if (BUILDSWIGJAVA)
swig_link_libraries (javaupm_${libname} ${BACNET_LIBRARIES})
endif()
endif ()

View File

@ -40,7 +40,7 @@ using namespace std;
// #define BMP280_USE_TEST_DATA
// conversion from fahrenheit to celcius and back
// conversion from fahrenheit to celsius and back
static float f2c(float f)
{

View File

@ -304,8 +304,8 @@ namespace upm {
* to calling this method.
*
* @param fahrenheit true to return data in Fahrenheit, false for
* Celicus. Celcius is the default.
* @return The temperature in degrees Celcius or Fahrenheit.
* Celicus. Celsius is the default.
* @return The temperature in degrees Celsius or Fahrenheit.
*/
float getTemperature(bool fahrenheit=false);
@ -393,7 +393,7 @@ namespace upm {
return "BMP280";
};
int getTemperatureCelcius()
int getTemperatureCelsius()
{
return int(getTemperature(false));
};

View File

@ -172,7 +172,7 @@ BMPX8X::getAltitude (float sealevelPressure) {
int
BMPX8X::getTemperatureCelcius() {
BMPX8X::getTemperatureCelsius() {
return static_cast<int>(getTemperature() + 0.5);
}

View File

@ -144,10 +144,10 @@ class BMPX8X : public IPressureSensor, public ITemperatureSensor {
float getAltitude (float sealevelPressure = 101325);
/**
* Return latest calculated temperature value in Celcius
* Return latest calculated temperature value in Celsius
* See ITemperatureSensor
*/
int getTemperatureCelcius();
int getTemperatureCelsius();
/**
* Return latest calculated pressure value in Pascals

View File

@ -33,19 +33,16 @@
using namespace upm;
using namespace std;
// conversion from celcius to fahrenheit
// conversion from celsius to fahrenheit
static float c2f(float c)
{
return (c * (9.0 / 5.0) + 32.0);
}
BMA250E::BMA250E(int bus, uint8_t addr, int cs) :
BMA250E::BMA250E(int bus, int addr, int cs) :
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
{
m_addr = addr;
m_isSPI = false;
m_accX = 0;
m_accY = 0;
m_accZ = 0;
@ -53,7 +50,15 @@ BMA250E::BMA250E(int bus, uint8_t addr, int cs) :
m_temperature = 0.0;
if (addr < 0)
m_isSPI = true;
{
m_addr = 0;
m_isSPI = true;
}
else
{
m_addr = uint8_t(addr);
m_isSPI = false;
}
if (m_isSPI)
{
@ -127,6 +132,13 @@ BMA250E::~BMA250E()
{
uninstallISR(INTERRUPT_INT1);
uninstallISR(INTERRUPT_INT2);
if (m_i2c)
delete m_i2c;
if (m_spi)
delete m_spi;
if(m_gpioCS)
delete m_gpioCS;
}
void BMA250E::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
@ -160,20 +172,14 @@ void BMA250E::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
void BMA250E::update()
{
int bufLen = 0;
uint8_t startReg = 0;
int bufLen = 7; // max, non-FIFO
uint8_t startReg = REG_ACCD_X_LSB;
if (m_useFIFO)
{
bufLen = 6;
startReg = REG_FIFO_DATA;
}
else
{
// non FIFO, read acc regs directly (including temp)
bufLen = 7;
startReg = REG_ACCD_X_LSB;
}
uint8_t buf[bufLen];

View File

@ -964,7 +964,7 @@ namespace upm {
* @param cs The gpio pin to use for the SPI Chip Select. -1 for
* I2C or for SPI with a hardware controlled pin.
*/
BMA250E(int bus=BMA250E_I2C_BUS, uint8_t addr=BMA250E_DEFAULT_ADDR,
BMA250E(int bus=BMA250E_I2C_BUS, int addr=BMA250E_DEFAULT_ADDR,
int cs=-1);
/**
@ -1014,8 +1014,8 @@ namespace upm {
* calling this method.
*
* @param fahrenheit true to return data in Fahrenheit, false for
* Celicus. Celcius is the default.
* @return The temperature in degrees Celcius or Fahrenheit.
* Celicus. Celsius is the default.
* @return The temperature in degrees Celsius or Fahrenheit.
*/
float getTemperature(bool fahrenheit=false);

View File

@ -32,8 +32,8 @@
using namespace upm;
using namespace std;
BMC150::BMC150(int accelBus, uint8_t accelAddr, int accelCS,
int magBus, uint8_t magAddr, int magCS) :
BMC150::BMC150(int accelBus, int accelAddr, int accelCS,
int magBus, int magAddr, int magCS) :
m_accel(0), m_mag(0)
{
// if -1 is supplied as a bus for any of these, we will not

View File

@ -93,10 +93,10 @@ namespace upm {
* I2C or for SPI with a hardware controlled pin.
*/
BMC150(int accelBus=BMC150_DEFAULT_BUS,
uint8_t accelAddr=BMC150_DEFAULT_ACC_ADDR,
int accelAddr=BMC150_DEFAULT_ACC_ADDR,
int accelCS=-1,
int magBus=BMC150_DEFAULT_BUS,
uint8_t magAddr=BMC150_DEFAULT_MAG_ADDR,
int magAddr=BMC150_DEFAULT_MAG_ADDR,
int magCS=-1);
/**

View File

@ -35,19 +35,16 @@ using namespace std;
#define BMG160_DEFAULT_CHIPID 0x0f
// conversion from celcius to fahrenheit
// conversion from celsius to fahrenheit
static float c2f(float c)
{
return (c * (9.0 / 5.0) + 32.0);
}
BMG160::BMG160(int bus, uint8_t addr, int cs) :
BMG160::BMG160(int bus, int addr, int cs) :
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
{
m_addr = addr;
m_isSPI = false;
m_gyrX = 0;
m_gyrY = 0;
m_gyrZ = 0;
@ -55,7 +52,15 @@ BMG160::BMG160(int bus, uint8_t addr, int cs) :
m_temperature = 0.0;
if (addr < 0)
m_isSPI = true;
{
m_addr = 0;
m_isSPI = true;
}
else
{
m_addr = uint8_t(addr);
m_isSPI = false;
}
if (m_isSPI)
{
@ -105,6 +110,13 @@ BMG160::~BMG160()
{
uninstallISR(INTERRUPT_INT1);
uninstallISR(INTERRUPT_INT2);
if (m_i2c)
delete m_i2c;
if (m_spi)
delete m_spi;
if(m_gpioCS)
delete m_gpioCS;
}
void BMG160::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
@ -132,20 +144,14 @@ void BMG160::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
void BMG160::update()
{
int bufLen = 0;
uint8_t startReg = 0;
int bufLen = 7; // max, non-FIFO
uint8_t startReg = REG_RATE_X_LSB;
if (m_useFIFO)
{
bufLen = 6;
startReg = REG_FIFO_DATA;
}
else
{
// non FIFO, read acc regs directly (including temp)
bufLen = 7;
startReg = REG_RATE_X_LSB;
}
uint8_t buf[bufLen];

View File

@ -823,7 +823,7 @@ namespace upm {
* I2C or for SPI with a hardware controlled pin.
* @param theChipID The chip ID to use for validation
*/
BMG160(int bus=BMG160_I2C_BUS, uint8_t addr=BMG160_DEFAULT_ADDR,
BMG160(int bus=BMG160_I2C_BUS, int addr=BMG160_DEFAULT_ADDR,
int cs=-1);
/**
@ -873,8 +873,8 @@ namespace upm {
* calling this method.
*
* @param fahrenheit true to return data in Fahrenheit, false for
* Celicus. Celcius is the default.
* @return The temperature in degrees Celcius or Fahrenheit.
* Celicus. Celsius is the default.
* @return The temperature in degrees Celsius or Fahrenheit.
*/
float getTemperature(bool fahrenheit=false);

View File

@ -32,8 +32,8 @@
using namespace upm;
using namespace std;
BMI055::BMI055(int accelBus, uint8_t accelAddr, int accelCS,
int gyroBus, uint8_t gyroAddr, int gyroCS) :
BMI055::BMI055(int accelBus, int accelAddr, int accelCS,
int gyroBus, int gyroAddr, int gyroCS) :
m_accel(0), m_gyro(0)
{
// if -1 is supplied as a bus for any of these, we will not

View File

@ -85,10 +85,10 @@ namespace upm {
* I2C or for SPI with a hardware controlled pin.
*/
BMI055(int accelBus=BMA250E_I2C_BUS,
uint8_t accelAddr=BMA250E_DEFAULT_ADDR,
int accelAddr=BMA250E_DEFAULT_ADDR,
int accelCS=-1,
int gyroBus=BMG160_I2C_BUS,
uint8_t gyroAddr=BMG160_DEFAULT_ADDR,
int gyroAddr=BMG160_DEFAULT_ADDR,
int gyroCS=-1);
/**

View File

@ -92,12 +92,9 @@
using namespace upm;
using namespace std;
BMM150::BMM150(int bus, uint8_t addr, int cs) :
BMM150::BMM150(int bus, int addr, int cs) :
m_i2c(0), m_spi(0), m_gpioIntr(0), m_gpioDR(0), m_gpioCS(0)
{
m_addr = addr;
m_isSPI = false;
m_magX = 0;
m_magY = 0;
m_magZ = 0;
@ -119,7 +116,16 @@ BMM150::BMM150(int bus, uint8_t addr, int cs) :
m_dig_xy1 = 0;
if (addr < 0)
m_isSPI = true;
{
m_addr = 0;
m_isSPI = true;
}
else
{
m_addr = uint8_t(addr);
m_isSPI = false;
}
if (m_isSPI)
{
@ -177,6 +183,13 @@ BMM150::~BMM150()
{
uninstallISR(INTERRUPT_INT);
uninstallISR(INTERRUPT_DR);
if (m_i2c)
delete m_i2c;
if (m_spi)
delete m_spi;
if(m_gpioCS)
delete m_gpioCS;
}
void BMM150::init(USAGE_PRESETS_T usage)

View File

@ -320,7 +320,7 @@ namespace upm {
* I2C or for SPI with a hardware controlled pin.
* @param theChipID The chip ID to use for validation
*/
BMM150(int bus=BMM150_I2C_BUS, uint8_t addr=BMM150_DEFAULT_ADDR,
BMM150(int bus=BMM150_I2C_BUS, int addr=BMM150_DEFAULT_ADDR,
int cs=-1);
/**

View File

@ -32,9 +32,9 @@
using namespace upm;
using namespace std;
BMX055::BMX055(int accelBus, uint8_t accelAddr, int accelCS,
int gyroBus, uint8_t gyroAddr, int gyroCS,
int magBus, uint8_t magAddr, int magCS) :
BMX055::BMX055(int accelBus, int accelAddr, int accelCS,
int gyroBus, int gyroAddr, int gyroCS,
int magBus, int magAddr, int magCS) :
m_accel(0), m_gyro(0), m_mag(0)
{
// if -1 is supplied as a bus for any of these, we will not

View File

@ -100,13 +100,13 @@ namespace upm {
* I2C or for SPI with a hardware controlled pin.
*/
BMX055(int accelBus=BMA250E_I2C_BUS,
uint8_t accelAddr=BMA250E_DEFAULT_ADDR,
int accelAddr=BMA250E_DEFAULT_ADDR,
int accelCS=-1,
int gyroBus=BMG160_I2C_BUS,
uint8_t gyroAddr=BMG160_DEFAULT_ADDR,
int gyroAddr=BMG160_DEFAULT_ADDR,
int gyroCS=-1,
int magBus=BMM150_I2C_BUS,
uint8_t magAddr=BMM150_DEFAULT_ADDR,
int magAddr=BMM150_DEFAULT_ADDR,
int magCS=-1);
/**

View File

@ -33,7 +33,7 @@
using namespace upm;
using namespace std;
// conversion from fahrenheit to celcius and back
// conversion from fahrenheit to celsius and back
static float f2c(float f)
{
@ -245,20 +245,20 @@ void BNO055::setTemperatureSource(TEMP_SOURCES_T src)
writeReg(REG_TEMP_SOURCE, src);
}
void BNO055::setTemperatureUnits(bool celcius)
void BNO055::setTemperatureUnits(bool celsius)
{
setPage(0);
uint8_t reg = readReg(REG_UNIT_SEL);
if (celcius)
if (celsius)
reg &= ~UNIT_SEL_TEMP_UNIT;
else
reg |= UNIT_SEL_TEMP_UNIT;
writeReg(REG_UNIT_SEL, reg);
m_tempIsC = celcius;
m_tempIsC = celsius;
}
void BNO055::setAccelerometerUnits(bool mg)

View File

@ -896,7 +896,7 @@ namespace upm {
*
* By default, the constructor sets the acceleration units to
* m/s^2, gyro and Euler units to degrees, and temperature to
* celcius. It then enters the NDOF fusion mode.
* celsius. It then enters the NDOF fusion mode.
*
* In addition, the internal clock is used so that compatibility
* with other implementations is assured. If you are using a
@ -980,11 +980,11 @@ namespace upm {
/**
* Select the temperature units. This can be the Fahrenheit or
* Celcius.
* Celsius.
*
* @param celcius true for Celius, false for Fahrenheit.
* @param celsius true for Celius, false for Fahrenheit.
*/
void setTemperatureUnits(bool celcius);
void setTemperatureUnits(bool celsius);
/**
* Set the operating mode for the device. This places the device
@ -1060,8 +1060,8 @@ namespace upm {
* calling this method.
*
* @param fahrenheit true to return data in Fahrenheit, false for
* Celicus. Celcius is the default.
* @return The temperature in degrees Celcius or Fahrenheit.
* Celicus. Celsius is the default.
* @return The temperature in degrees Celsius or Fahrenheit.
*/
float getTemperature(bool fahrenheit=false);

View File

@ -33,7 +33,7 @@ using namespace std;
// several aio reads.
static const int maxSamples = 50;
// conversion from celcius to fahrenheit
// conversion from celsius to fahrenheit
static float c2f(float c)
{

View File

@ -130,9 +130,9 @@ namespace upm {
* constructor) then this function will always return 0C/32F.
*
* @param fahrenheit true to return the temperature in degrees
* fahrenheit, false to return the temperature in degrees celcius.
* The default is false (degrees Celcius).
* @return The last temperature reading in Celcius or Fahrenheit
* fahrenheit, false to return the temperature in degrees celsius.
* The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit
*/
float getTemperature(bool fahrenheit=false);
@ -174,7 +174,7 @@ namespace upm {
bool m_hasTemp;
bool m_hasHum;
// in Celcius
// in Celsius
float m_temperature;
float m_humidity;

View File

@ -31,7 +31,7 @@
using namespace upm;
using namespace std;
// conversion from celcius to fahrenheit
// conversion from celsius to fahrenheit
static float c2f(float c)
{
return (c * (9.0 / 5.0) + 32.0);

View File

@ -153,9 +153,9 @@ namespace upm {
*
* @param index The device index to access (starts at 0).
* @param fahrenheit true to return the temperature in degrees
* fahrenheit, false to return the temperature in degrees celcius.
* The default is false (degrees Celcius).
* @return The last temperature reading in Celcius or Fahrenheit
* fahrenheit, false to return the temperature in degrees celsius.
* The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit
*/
float getTemperature(int index, bool fahrenheit=false);

View File

@ -11,18 +11,16 @@ if (BACNET_FOUND)
include_directories("../bacnetmstp")
upm_module_init()
target_link_libraries(${libname} bacnetmstp)
if (BUILDSWIG)
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} bacnetmstp)
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} bacnetmstp)
endif()
if (BUILDSWIGJAVA)
set_target_properties(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (javaupm_${libname} bacnetmstp)
endif()
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} bacnetmstp)
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} bacnetmstp)
endif()
if (BUILDSWIGJAVA)
set_target_properties(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (javaupm_${libname} bacnetmstp)
endif()
endif ()

View File

@ -1,5 +1,5 @@
set (libname "grove")
set (libdescription "upm grove module")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (module_src grovebutton.cxx groveled.cxx grovelight.cxx groverelay.cxx groverotary.cxx groveslide.cxx grovetemp.cxx)
set (module_hpp grovebutton.hpp groveled.hpp grovelight.hpp groverelay.hpp groverotary.hpp groveslide.hpp grovetemp.hpp grovebase.hpp grove.hpp)
upm_module_init()

View File

@ -1,307 +1 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Contributions: Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 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 <iostream>
#include <string>
#include <stdexcept>
#include "grove.hpp"
#include "math.h"
using namespace upm;
//// GroveLed ////
GroveLed::GroveLed(int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
m_name = "LED Socket";
}
GroveLed::~GroveLed()
{
mraa_gpio_close(m_gpio);
}
mraa_result_t GroveLed::write(int value)
{
if (value >= 1) {
return mraa_gpio_write(m_gpio, 1);
}
return mraa_gpio_write(m_gpio, 0);
}
mraa_result_t GroveLed::on()
{
return write(1);
}
mraa_result_t GroveLed::off()
{
return write(0);
}
//// GroveRelay ////
GroveRelay::GroveRelay(unsigned int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
m_name = "Relay Switch";
}
GroveRelay::~GroveRelay()
{
mraa_gpio_close(m_gpio);
}
mraa_result_t GroveRelay::on()
{
return mraa_gpio_write(m_gpio, 1);
}
mraa_result_t GroveRelay::off()
{
return mraa_gpio_write(m_gpio, 0);
}
bool GroveRelay::isOn()
{
return mraa_gpio_read(m_gpio) == 1;
}
bool GroveRelay::isOff()
{
return mraa_gpio_read(m_gpio) == 0;
}
//// GroveTemp ////
GroveTemp::GroveTemp(unsigned int pin, float scale)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Temperature Sensor";
m_scale = scale;
}
GroveTemp::~GroveTemp()
{
mraa_aio_close(m_aio);
}
int GroveTemp::value ()
{
float a = (float) mraa_aio_read(m_aio);
if (a == -1.0) return -1;
// Apply scale factor after error check
a *= m_scale;
float r = (float)(1023.0-a)*10000.0/a;
float t = 1.0/(log(r/10000.0)/3975.0 + 1.0/298.15)-273.15;
return (int) round(t);
}
float GroveTemp::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
//// GroveLight ////
GroveLight::GroveLight(unsigned int pin)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Light Sensor";
}
GroveLight::~GroveLight()
{
mraa_aio_close(m_aio);
}
int GroveLight::value()
{
// rough conversion to lux, using formula from Grove Starter Kit booklet
float a = (float) mraa_aio_read(m_aio);
if (a == -1.0) return -1;
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
return (int) round(a);
}
float GroveLight::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
//// GroveRotary ////
GroveRotary::GroveRotary(unsigned int pin)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Rotary Angle Sensor";
}
GroveRotary::~GroveRotary()
{
mraa_aio_close(m_aio);
}
float GroveRotary::abs_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveRotary::abs_deg()
{
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::abs_rad()
{
return GroveRotary::abs_deg() * M_PI / 180.0;
}
float GroveRotary::rel_value()
{
return GroveRotary::abs_value() - 512.0;
}
float GroveRotary::rel_deg()
{
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::rel_rad()
{
return GroveRotary::rel_deg() * M_PI / 180.0;
}
//// GroveSlide ////
GroveSlide::GroveSlide(unsigned int pin, float ref_voltage)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_ref_voltage = ref_voltage;
m_name = "Slide Potentiometer";
}
GroveSlide::~GroveSlide()
{
mraa_aio_close(m_aio);
}
float GroveSlide::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveSlide::voltage_value()
{
// conversion to Volts
float a = GroveSlide::raw_value();
a = m_ref_voltage * a / 1023.0 ;
return a;
}
float GroveSlide::ref_voltage()
{
return m_ref_voltage;
}
//// GroveButton ////
GroveButton::GroveButton(unsigned int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
m_name = "Button Sensor";
}
GroveButton::~GroveButton()
{
mraa_gpio_close(m_gpio);
}
std::string GroveButton::name()
{
return m_name;
}
int GroveButton::value()
{
return mraa_gpio_read(m_gpio);
}
#ifdef JAVACALLBACK
void GroveButton::installISR(mraa::Edge level, jobject runnable)
{
installISR(level, mraa_java_isr_callback, runnable);
}
#endif
void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg)
{
if (m_isrInstalled)
uninstallISR();
// install our interrupt handler
mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg);
m_isrInstalled = true;
}
void GroveButton::uninstallISR()
{
mraa_gpio_isr_exit(m_gpio);
m_isrInstalled = false;
}

View File

@ -1,8 +1,8 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Contributions: Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -25,389 +25,10 @@
*/
#pragma once
#include <string>
#include <mraa/aio.hpp>
#include <mraa/gpio.hpp>
namespace upm {
/**
* @brief Generic library for basic Grove sensors
* @defgroup grove libupm-grove
* @ingroup seeed gpio pwm ainput button led light relay temp touch gsk eak hak
*/
class Grove {
public:
virtual ~Grove() {}
std::string name()
{
return m_name;
}
protected:
std::string m_name;
};
/**
* @brief API for the Grove LED
*
* UPM module for the Grove LED (or other similar light-emitting diodes).
* An LED is a small lightbulb that emits light in
* response to a small current. The longer wire of an LED connects
* to the positive seat (anode); the shorter wire connects to the
* negative seat (cathode). The flat side of the bulb corresponds
* to the cathode, while the rounded side corresponds to the anode.
*
* @ingroup grove gpio
* @snippet groveled.cxx Interesting
* @snippet groveled-multi.cxx Interesting
* @image html groveled.jpg
*/
class GroveLed: public Grove {
public:
/**
* Grove LED constructor
*
* @param gpio Pin to use
*/
GroveLed(int pin);
/**
* Grove LED destructor
*/
~GroveLed();
/**
* Turns the LED on or off, depending on the value.
* If the value is positive (greater than or equal
* to 1), the LED is turned on. Otherwise, for 0
* or negative values, the LED is turned off.
*
* @param value Tells the LED to turn on (for values >=1)
* or off (for values <1)
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t write(int value);
/**
* Turns the LED off
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t off();
/**
* Turns the LED on
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t on();
private:
mraa_gpio_context m_gpio;
};
/**
* @brief API for the Grove Relay
*
* UPM module for the Grove relay switch. Grove relay is a
* digital normally-open switch that uses low voltage or current to
* control a higher voltage and/or higher current. When closed,
* the indicator LED lights up and current is allowed to flow.
*
* @ingroup grove gpio
* @snippet groverelay.cxx Interesting
* @image html groverelay.jpg
*/
class GroveRelay: public Grove {
public:
/**
* Grove relay constructor
*
* @param gpio Pin to use
*/
GroveRelay(unsigned int pin);
/**
* Grove relay destructor
*/
~GroveRelay();
/**
* Sets the relay switch to on (closed). This allows current
* to flow and lights up the indicator LED.
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t on();
/**
* Sets the relay switch to off (open). This stops current
* from flowing and the indicator LED is not lit.
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t off();
/**
* Defines whether the relay switch is closed.
*
* @return True if the switch is on (closed), false otherwise
*/
bool isOn();
/**
* Defines whether the relay switch is open.
*
* @return True if the switch is off (open), false otherwise
*/
bool isOff();
private:
mraa_gpio_context m_gpio;
};
/**
* @brief API for the Grove Temperature Sensor
*
* Basic UPM module for the Grove temperature sensor on analog
*
* @ingroup grove analog
* @snippet grovetemp.cxx Interesting
* @image html grovetemp.jpg
*/
class GroveTemp: public Grove {
public:
/**
* Grove analog temperature sensor constructor
*
* @param pin Analog pin to use
* @param scale Scaling factor for raw analog value from the ADC,
* useful for mixed 3.3V/5V boards
*/
GroveTemp(unsigned int pin, float scale = 1.0);
/**
* GroveTemp destructor
*/
~GroveTemp();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets the temperature in Celsius from the sensor
*
* @return Normalized temperature in Celsius
*/
int value();
private:
mraa_aio_context m_aio;
float m_scale;
};
/**
* @brief API for the Grove Light Sensor
*
* The Grove light sensor detects the intensity of the ambient light.
* As the light intensity of the environment increases, the resistance
* of the sensor decreases. This means the raw value from the
* analog pin is greater in bright light and smaller in the dark.
* An approximate lux value can also be returned.
*
* @ingroup grove analog
* @snippet grovelight.cxx Interesting
* @image html grovelight.jpg
*/
class GroveLight: public Grove {
public:
/**
* Grove analog light sensor constructor
*
* @param pin Analog pin to use
*/
GroveLight(unsigned int pin);
/**
* GroveLight destructor
*/
~GroveLight();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets an approximate light value, in lux, from the sensor
*
* @return Normalized light reading in lux
*/
int value();
private:
mraa_aio_context m_aio;
};
/**
* @brief API for the Grove Rotary Angle Sensor (Knob)
*
* Basic UPM module for the Grove rotary angle sensor (knob) on analog. Provides
* a set of functions to read the absolute pin value, degrees or radians, and another set
* to do the same relative to the center of the knob range.
*
* @ingroup grove analog
* @snippet groverotary.cxx Interesting
* @image html groverotary.jpeg
*/
class GroveRotary: public Grove {
public:
/**
* Grove rotary angle sensor constructor
*
* @param pin Number of the analog pin to use
*/
GroveRotary(unsigned int pin);
/**
* GroveRotary destructor
*/
~GroveRotary();
/**
* Gets the absolute raw value from the AIO pin
*
* @return Unsigned value from the ADC
*/
float abs_value();
/**
* Gets absolute raw degrees from the AIO pin
*
* @return Unsigned degrees from the ADC
*/
float abs_deg();
/**
* Gets absolute raw radians from the AIO pin
*
* @return Unsigned radians from the ADC
*/
float abs_rad();
/**
* Gets the relative value from the AIO pin
*
* @return Signed value from the ADC
*/
float rel_value();
/**
* Gets relative degrees from the AIO pin
*
* @return Signed degrees from the ADC
*/
float rel_deg();
/**
* Gets relative radians from the AIO pin
*
* @return Signed radians from the ADC
*/
float rel_rad();
private:
mraa_aio_context m_aio;
static const int m_max_angle = 300;
};
/**
* @brief API for the Grove Slide Potentiometer
*
* Basic UPM module for the Grove slide potentiometer on analog that
* returns either a raw value or a scaled voltage value.
*
* @ingroup grove analog
* @snippet groveslide.cxx Interesting
* @image html groveslide.jpeg
*/
class GroveSlide: public Grove {
public:
/**
* Grove analog slide potentiometer constructor
*
* @param pin Number of the analog pin to use
*
* @param ref_voltage Reference voltage the board is set to, as a floating-point value; default is 5.0V
*/
GroveSlide(unsigned int pin, float ref_voltage = 5.0);
/**
* GroveSlide destructor
*/
~GroveSlide();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets the voltage value from the pin
*
* @return Voltage reading based on the reference voltage
*/
float voltage_value();
/**
* Gets the board's reference voltage passed on object initialization
*
* @return Reference voltage the class was set for
*/
float ref_voltage();
private:
mraa_aio_context m_aio;
float m_ref_voltage;
};
/**
* @brief API for the Grove Button
*
* Basic UPM module for the Grove button
*
* @ingroup grove gpio
* @snippet grovebutton.cxx Interesting
* @image html grovebutton.jpg
*/
class GroveButton: public Grove {
public:
/**
* Grove button constructor
*
* @param gpio Pin to use
*/
GroveButton(unsigned int pin);
/**
* Grove button destructor
*/
~GroveButton();
/**
* Gets the name of the sensor
*
* @return Name of this sensor
*/
std::string name();
/**
* Gets the value from the GPIO pin
*
* @return Value from the GPIO pin
*/
int value();
/**
* Installs an interrupt service routine (ISR) to be called when
* the button is activated or deactivated.
*
* @param fptr Pointer to a function to be called on interrupt
* @param arg Pointer to an object to be supplied as an
* argument to the ISR.
*/
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(mraa::Edge level, jobject runnable);
#else
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
#endif
/**
* Uninstalls the previously installed ISR
*
*/
void uninstallISR();
private:
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
#endif
bool m_isrInstalled;
std::string m_name;
mraa_gpio_context m_gpio;
};
}
#include <grovebutton.hpp>
#include <groveled.hpp>
#include <grovelight.hpp>
#include <groverelay.hpp>
#include <groverotary.hpp>
#include <groveslide.hpp>
#include <grovetemp.hpp>

47
src/grove/grovebase.hpp Normal file
View File

@ -0,0 +1,47 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <string>
namespace upm {
/**
* @brief Generic library for basic Grove sensors
* @defgroup grove libupm-grove
* @ingroup seeed gpio pwm ainput button led light relay temp touch gsk eak hak
*/
class Grove {
public:
virtual ~Grove() {}
std::string name()
{
return m_name;
}
protected:
std::string m_name;
};
}

82
src/grove/grovebutton.cxx Normal file
View File

@ -0,0 +1,82 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "grovebutton.hpp"
using namespace upm;
GroveButton::GroveButton(unsigned int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
m_name = "Button Sensor";
}
GroveButton::~GroveButton()
{
mraa_gpio_close(m_gpio);
}
std::string GroveButton::name()
{
return m_name;
}
int GroveButton::value()
{
return mraa_gpio_read(m_gpio);
}
#ifdef JAVACALLBACK
void GroveButton::installISR(mraa::Edge level, jobject runnable)
{
installISR(level, mraa_java_isr_callback, runnable);
}
#endif
void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg)
{
if (m_isrInstalled)
uninstallISR();
// install our interrupt handler
mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg);
m_isrInstalled = true;
}
void GroveButton::uninstallISR()
{
mraa_gpio_isr_exit(m_gpio);
m_isrInstalled = false;
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/gpio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor grovebutton
@ -40,3 +49,56 @@
* @image html grovebutton.jpg
* @snippet grovebutton.cxx Interesting
*/
class GroveButton: public Grove {
public:
/**
* Grove button constructor
*
* @param gpio Pin to use
*/
GroveButton(unsigned int pin);
/**
* Grove button destructor
*/
~GroveButton();
/**
* Gets the name of the sensor
*
* @return Name of this sensor
*/
std::string name();
/**
* Gets the value from the GPIO pin
*
* @return Value from the GPIO pin
*/
int value();
/**
* Installs an interrupt service routine (ISR) to be called when
* the button is activated or deactivated.
*
* @param fptr Pointer to a function to be called on interrupt
* @param arg Pointer to an object to be supplied as an
* argument to the ISR.
*/
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(mraa::Edge level, jobject runnable);
#else
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
#endif
/**
* Uninstalls the previously installed ISR
*
*/
void uninstallISR();
private:
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
#endif
bool m_isrInstalled;
std::string m_name;
mraa_gpio_context m_gpio;
};
}

67
src/grove/groveled.cxx Normal file
View File

@ -0,0 +1,67 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "groveled.hpp"
using namespace upm;
GroveLed::GroveLed(int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
m_name = "LED Socket";
}
GroveLed::~GroveLed()
{
mraa_gpio_close(m_gpio);
}
mraa_result_t GroveLed::write(int value)
{
if (value >= 1) {
return mraa_gpio_write(m_gpio, 1);
}
return mraa_gpio_write(m_gpio, 0);
}
mraa_result_t GroveLed::on()
{
return write(1);
}
mraa_result_t GroveLed::off()
{
return write(0);
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/gpio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor groveled
@ -35,7 +44,7 @@
* @brief API for the Grove LED
*
* UPM module for the Grove LED (or other similar light-emitting diodes).
* An LED is a small lightbulb that emits light in
* An LED is a small lightbulb that emits light in
* response to a small current. The longer wire of an LED connects
* to the positive seat (anode); the shorter wire connects to the
* negative seat (cathode). The flat side of the bulb corresponds
@ -45,4 +54,43 @@
* @snippet groveled.cxx Interesting
* @snippet groveled-multi.cxx Interesting
*/
class GroveLed: public Grove {
public:
/**
* Grove LED constructor
*
* @param gpio Pin to use
*/
GroveLed(int pin);
/**
* Grove LED destructor
*/
~GroveLed();
/**
* Turns the LED on or off, depending on the value.
* If the value is positive (greater than or equal
* to 1), the LED is turned on. Otherwise, for 0
* or negative values, the LED is turned off.
*
* @param value Tells the LED to turn on (for values >=1)
* or off (for values <1)
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t write(int value);
/**
* Turns the LED off
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t off();
/**
* Turns the LED on
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t on();
private:
mraa_gpio_context m_gpio;
};
}

63
src/grove/grovelight.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "grovelight.hpp"
#include "math.h"
using namespace upm;
GroveLight::GroveLight(unsigned int pin)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Light Sensor";
}
GroveLight::~GroveLight()
{
mraa_aio_close(m_aio);
}
int GroveLight::value()
{
// rough conversion to lux, using formula from Grove Starter Kit booklet
float a = (float) mraa_aio_read(m_aio);
if (a == -1.0) return -1;
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
return (int) round(a);
}
float GroveLight::raw_value()
{
return (float) mraa_aio_read(m_aio);
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/aio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor grovelight
@ -43,4 +52,31 @@
* @image html grovelight.jpg
* @snippet grovelight.cxx Interesting
*/
class GroveLight: public Grove {
public:
/**
* Grove analog light sensor constructor
*
* @param pin Analog pin to use
*/
GroveLight(unsigned int pin);
/**
* GroveLight destructor
*/
~GroveLight();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets an approximate light value, in lux, from the sensor
*
* @return Normalized light reading in lux
*/
int value();
private:
mraa_aio_context m_aio;
};
}

69
src/grove/groverelay.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "groverelay.hpp"
using namespace upm;
GroveRelay::GroveRelay(unsigned int pin)
{
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_gpio_init() failed, invalid pin?");
return;
}
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
m_name = "Relay Switch";
}
GroveRelay::~GroveRelay()
{
mraa_gpio_close(m_gpio);
}
mraa_result_t GroveRelay::on()
{
return mraa_gpio_write(m_gpio, 1);
}
mraa_result_t GroveRelay::off()
{
return mraa_gpio_write(m_gpio, 0);
}
bool GroveRelay::isOn()
{
return mraa_gpio_read(m_gpio) == 1;
}
bool GroveRelay::isOff()
{
return mraa_gpio_read(m_gpio) == 0;
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/gpio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor groverelay
@ -35,11 +44,52 @@
* @brief API for the Grove Relay
*
* UPM module for the Grove relay switch. The Grove relay is a
* digital normally-open switch that uses low voltage or current to
* control a higher voltage and/or higher current. When closed,
* digital normally-open switch that uses low voltage or current to
* control a higher voltage and/or higher current. When closed,
* the indicator LED lights up and current is allowed to flow.
*
* @image html groverelay.jpg
* @snippet groverelay.cxx Interesting
*/
class GroveRelay: public Grove {
public:
/**
* Grove relay constructor
*
* @param gpio Pin to use
*/
GroveRelay(unsigned int pin);
/**
* Grove relay destructor
*/
~GroveRelay();
/**
* Sets the relay switch to on (closed). This allows current
* to flow and lights up the indicator LED.
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t on();
/**
* Sets the relay switch to off (open). This stops current
* from flowing and the indicator LED is not lit.
*
* @return 0 if successful, non-zero otherwise
*/
mraa_result_t off();
/**
* Defines whether the relay switch is closed.
*
* @return True if the switch is on (closed), false otherwise
*/
bool isOn();
/**
* Defines whether the relay switch is open.
*
* @return True if the switch is off (open), false otherwise
*/
bool isOff();
private:
mraa_gpio_context m_gpio;
};
}

79
src/grove/groverotary.cxx Normal file
View File

@ -0,0 +1,79 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "groverotary.hpp"
#include "math.h"
using namespace upm;
GroveRotary::GroveRotary(unsigned int pin)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Rotary Angle Sensor";
}
GroveRotary::~GroveRotary()
{
mraa_aio_close(m_aio);
}
float GroveRotary::abs_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveRotary::abs_deg()
{
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::abs_rad()
{
return GroveRotary::abs_deg() * M_PI / 180.0;
}
float GroveRotary::rel_value()
{
return GroveRotary::abs_value() - 512.0;
}
float GroveRotary::rel_deg()
{
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::rel_rad()
{
return GroveRotary::rel_deg() * M_PI / 180.0;
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/aio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor groverotary
@ -42,4 +51,56 @@
* @image html groverotary.jpeg
* @snippet groverotary.cxx Interesting
*/
class GroveRotary: public Grove {
public:
/**
* Grove rotary angle sensor constructor
*
* @param pin Number of the analog pin to use
*/
GroveRotary(unsigned int pin);
/**
* GroveRotary destructor
*/
~GroveRotary();
/**
* Gets the absolute raw value from the AIO pin
*
* @return Unsigned value from the ADC
*/
float abs_value();
/**
* Gets absolute raw degrees from the AIO pin
*
* @return Unsigned degrees from the ADC
*/
float abs_deg();
/**
* Gets absolute raw radians from the AIO pin
*
* @return Unsigned radians from the ADC
*/
float abs_rad();
/**
* Gets the relative value from the AIO pin
*
* @return Signed value from the ADC
*/
float rel_value();
/**
* Gets relative degrees from the AIO pin
*
* @return Signed degrees from the ADC
*/
float rel_deg();
/**
* Gets relative radians from the AIO pin
*
* @return Signed radians from the ADC
*/
float rel_rad();
private:
mraa_aio_context m_aio;
static const int m_max_angle = 300;
};
}

68
src/grove/groveslide.cxx Normal file
View File

@ -0,0 +1,68 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "groveslide.hpp"
#include "math.h"
using namespace upm;
GroveSlide::GroveSlide(unsigned int pin, float ref_voltage)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_ref_voltage = ref_voltage;
m_name = "Slide Potentiometer";
}
GroveSlide::~GroveSlide()
{
mraa_aio_close(m_aio);
}
float GroveSlide::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveSlide::voltage_value()
{
// conversion to Volts
float a = GroveSlide::raw_value();
a = m_ref_voltage * a / 1023.0 ;
return a;
}
float GroveSlide::ref_voltage()
{
return m_ref_voltage;
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/aio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor groveslide
@ -39,4 +48,40 @@
* @image html groveslide.jpeg
* @snippet groveslide.cxx Interesting
*/
class GroveSlide: public Grove {
public:
/**
* Grove analog slide potentiometer constructor
*
* @param pin Number of the analog pin to use
*
* @param ref_voltage Reference voltage the board is set to, as a floating-point value; default is 5.0V
*/
GroveSlide(unsigned int pin, float ref_voltage = 5.0);
/**
* GroveSlide destructor
*/
~GroveSlide();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets the voltage value from the pin
*
* @return Voltage reading based on the reference voltage
*/
float voltage_value();
/**
* Gets the board's reference voltage passed on object initialization
*
* @return Reference voltage the class was set for
*/
float ref_voltage();
private:
mraa_aio_context m_aio;
float m_ref_voltage;
};
}

68
src/grove/grovetemp.cxx Normal file
View File

@ -0,0 +1,68 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 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 <iostream>
#include <string>
#include <stdexcept>
#include "grovetemp.hpp"
#include "math.h"
using namespace upm;
GroveTemp::GroveTemp(unsigned int pin, float scale, int r0, int b)
{
if ( !(m_aio = mraa_aio_init(pin)) ) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
m_name = "Temperature Sensor";
m_scale = scale;
m_r0 = r0;
m_b = b;
}
GroveTemp::~GroveTemp()
{
mraa_aio_close(m_aio);
}
int GroveTemp::value ()
{
float a = (float) mraa_aio_read(m_aio);
if (a == -1.0) return -1;
// Apply scale factor after error check
a *= m_scale;
float r = (float)(1023.0-a)*(float)m_r0/a;
float t = 1.0/(log(r/(float)m_r0)/(float)m_b + 1.0/298.15)-273.15;
return (int) round(t);
}
float GroveTemp::raw_value()
{
return (float) mraa_aio_read(m_aio);
}

View File

@ -1,7 +1,8 @@
/*
* Place-holder Header for Documentation and future API change
*
* Copyright (c) 2014 Intel Corporation.
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,7 +23,15 @@
* 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 <string>
#include <mraa/aio.hpp>
#include "grovebase.hpp"
namespace upm {
/**
* @library grove
* @sensor grovetemp
@ -34,9 +43,50 @@
*
* @brief API for the Grove Temperature Sensor
*
* Basic UPM module for the Grove temperature sensor on analog
* Basic UPM module for the Grove temperature sensor on analog. This sensor
* uses a thermistor to measure ambient temperature. The conversion formula has
* been updated to work with versions 1.1 and 1.2 of the sensor. For the older
* v1.0 sensor you will have to specify R0 and B values when initializing the
* device. The range of this sensor is -40 to 125 C and accuracy is +/- 1.5 C.
*
* @image html grovetemp.jpg
* @snippet grovetemp.cxx Interesting
*/
class GroveTemp: public Grove {
public:
/**
* Grove analog temperature sensor constructor
*
* @param pin Analog pin to use
* @param scale Scaling factor for raw analog value from the ADC,
* useful for mixed 3.3V/5V boards, default 1.0
* @param r0 zero power resistance, this is 100K (default) for
* v1.1-v1.2 and 10K for v1.0 of the sensor
* @param b thermistor nominal B constant, this is 4275 (default) for
* v1.1-v1.2 and 3975 for v1.0 of the sensor
*/
GroveTemp(unsigned int pin, float scale = 1.0, int r0 = 100000, int b = 4275);
/**
* GroveTemp destructor
*/
~GroveTemp();
/**
* Gets the raw value from the AIO pin
*
* @return Raw value from the ADC
*/
float raw_value();
/**
* Gets the temperature in Celsius from the sensor
*
* @return Normalized temperature in Celsius
*/
int value();
private:
mraa_aio_context m_aio;
float m_scale;
int m_r0;
int m_b;
};
}

View File

@ -4,11 +4,50 @@
%apply int {mraa::Edge}
%include "grove.hpp"
%{
#include "grove.hpp"
%}
%include "grove.hpp"
%include "grovebase.hpp"
%{
#include "grovebase.hpp"
%}
%include "grovebutton.hpp"
%{
#include "grovebutton.hpp"
%}
%include "groveled.hpp"
%{
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"
%}
%include "groverotary.hpp"
%{
#include "groverotary.hpp"
%}
%include "groveslide.hpp"
%{
#include "groveslide.hpp"
%}
%include "grovetemp.hpp"
%{
#include "grovetemp.hpp"
%}
%pragma(java) jniclasscode=%{
static {
@ -20,4 +59,3 @@
}
}
%}

View File

@ -1,8 +1,47 @@
%module jsupm_grove
%include "../upm.i"
%include "grove.hpp"
%{
#include "grove.hpp"
%}
%include "grove.hpp"
%include "grovebase.hpp"
%{
#include "grovebase.hpp"
%}
%include "grovebutton.hpp"
%{
#include "grovebutton.hpp"
%}
%include "groveled.hpp"
%{
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"
%}
%include "groverotary.hpp"
%{
#include "groverotary.hpp"
%}
%include "groveslide.hpp"
%{
#include "groveslide.hpp"
%}
%include "grovetemp.hpp"
%{
#include "grovetemp.hpp"
%}

View File

@ -5,11 +5,47 @@
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "grove_doc.i"
#endif
%include "grove.hpp"
%{
#include "grove.hpp"
%}
%include "grovebase.hpp"
%{
#include "grovebase.hpp"
%}
%include "grovebutton.hpp"
%{
#include "grovebutton.hpp"
%}
%include "groveled.hpp"
%{
#include "groveled.hpp"
%}
%include "grovelight.hpp"
%{
#include "grovelight.hpp"
%}
%include "groverelay.hpp"
%{
#include "groverelay.hpp"
%}
%include "groverotary.hpp"
%{
#include "groverotary.hpp"
%}
%include "groveslide.hpp"
%{
#include "groveslide.hpp"
%}
%include "grovetemp.hpp"
%{
#include "grovetemp.hpp"
%}

View File

@ -38,7 +38,7 @@ namespace upm {
/**
* @brief Grove ultrasonic sensor library
* @defgroup groveultrasonic libupm-groveultrasonic
* @ingroup grove gpio sound
* @ingroup seeed gpio sound
*/
/**

View File

@ -9,15 +9,13 @@ if (MODBUS_FOUND)
include_directories(${MODBUS_INCLUDE_DIRS})
upm_module_init()
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
if (BUILDSWIG)
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGJAVA)
swig_link_libraries (javaupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGJAVA)
swig_link_libraries (javaupm_${libname} ${MODBUS_LIBRARIES})
endif()
endif ()

View File

@ -29,7 +29,7 @@
using namespace upm;
using namespace std;
// conversion from celcius to fahrenheit
// conversion from celsius to fahrenheit
static float c2f(float c)
{

View File

@ -125,9 +125,9 @@ namespace upm {
* constructor) then this function will always return 0C/32F.
*
* @param fahrenheit true to return the temperature in degrees
* fahrenheit, false to return the temperature in degrees celcius.
* The default is false (degrees Celcius).
* @return The last temperature reading in Celcius or Fahrenheit
* fahrenheit, false to return the temperature in degrees celsius.
* The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit
*/
float getTemperature(bool fahrenheit=false);
@ -154,7 +154,7 @@ namespace upm {
// does this sensor support temperature reporting?
bool m_hasTemp;
// in Celcius
// in Celsius
float m_temperature;
float m_humidity;

View File

@ -9,12 +9,10 @@ if (MODBUS_FOUND)
include_directories(${MODBUS_INCLUDE_DIRS})
upm_module_init()
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
if (BUILDSWIG)
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
endif()
endif ()

View File

@ -32,7 +32,7 @@
using namespace upm;
using namespace std;
// conversion from fahrenheit to celcius and back
// conversion from fahrenheit to celsius and back
static float f2c(float f)
{
@ -107,9 +107,9 @@ HWXPXX::HWXPXX(std::string device, int address, int baud, int bits, char parity,
// temp scale
if (coils[0])
m_isCelcius = false;
m_isCelsius = false;
else
m_isCelcius = true;
m_isCelsius = true;
// current override switch status
m_override = ((coils[1]) ? true : false);
@ -243,7 +243,7 @@ void HWXPXX::update()
// temperature, we always store as C
float tmpF = float((int16_t)data[1]) / 10.0;
if (m_isCelcius)
if (m_isCelsius)
m_temperature = tmpF;
else
m_temperature = f2c(tmpF);
@ -319,11 +319,11 @@ void HWXPXX::setTemperatureScale(bool fahrenheit)
{
writeCoil(COIL_TEMP_SCALE, fahrenheit);
// now re-read and set m_isCelcius properly
// now re-read and set m_isCelsius properly
if (readCoil(COIL_TEMP_SCALE))
m_isCelcius = false;
m_isCelsius = false;
else
m_isCelcius = true;
m_isCelsius = true;
}
string HWXPXX::getSlaveID()
@ -361,11 +361,11 @@ void HWXPXX::setSlaveAddress(int addr)
": modbus_set_slave() failed");
}
// now re-read and set m_isCelcius properly
// now re-read and set m_isCelsius properly
if (readCoil(COIL_TEMP_SCALE))
m_isCelcius = false;
m_isCelsius = false;
else
m_isCelcius = true;
m_isCelsius = true;
}
void HWXPXX::setDebug(bool enable)

View File

@ -124,9 +124,9 @@ namespace upm {
* the scale the device is operating in natively.
*
* @param fahrenheit true to return the temperature in degrees
* fahrenheit, false to return the temperature in degrees celcius.
* The default is false (degrees Celcius).
* @return The last temperature reading in Celcius or Fahrenheit
* fahrenheit, false to return the temperature in degrees celsius.
* The default is false (degrees Celsius).
* @return The last temperature reading in Celsius or Fahrenheit
*/
float getTemperature(bool fahrenheit=false);
@ -173,7 +173,7 @@ namespace upm {
/**
* Return the current temperature offset stored on the device.
* This is a value between -50 and +50, specified in tenths of a
* degree in whatever scale (Celcius or Fahrenheit) is in use.
* degree in whatever scale (Celsius or Fahrenheit) is in use.
* This offset is applied to the returned temperature reading by the
* device.
*
@ -194,7 +194,7 @@ namespace upm {
/**
* Set the stored temperature offset on the device. This is a
* value between -50 and +50, specified in tenths of a degree in
* what ever scale (Celcius or Fahrenheit) is in use. This offset
* what ever scale (Celsius or Fahrenheit) is in use. This offset
* is applied to the returned temperature reading by the device.
*
* @param offset Offset in tenths of a degree with a range of -50 to +50
@ -216,10 +216,10 @@ namespace upm {
* detects this setting automatically and adjusts itself
* accordingly, so this is generally never needed. It is used to
* set the native reporting scale of the temperature either in
* degrees Celcius or Fahrenheit. Its setting will not affect
* degrees Celsius or Fahrenheit. Its setting will not affect
* the operation of getTemperature().
*
* @param fahrenheit true to set Fahrenheit, false to set Celcius
* @param fahrenheit true to set Fahrenheit, false to set Celsius
*/
void setTemperatureScale(bool fahrenheit);
@ -269,7 +269,7 @@ namespace upm {
modbus_t *m_mbContext;
// is the device reporting in C or F?
bool m_isCelcius;
bool m_isCelsius;
private:
bool m_debugging;

0
src/kxcjk1013/CMakeLists.txt Executable file → Normal file
View File

0
src/kxcjk1013/jsupm_kxcjk1013.i Executable file → Normal file
View File

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