mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 12:21:11 +03:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
4faa71d239 | |||
5265bada9c | |||
84067826eb | |||
98e3621c93 | |||
d79799bab9 | |||
49e04593d8 | |||
bda66a3d06 | |||
84a77730be | |||
b08fc8d48d | |||
e64f192fb7 | |||
40fe6654eb | |||
e740335701 | |||
b257d91702 | |||
e7394217b1 | |||
baec9966f0 | |||
0fb56356fb | |||
e0ef6eea64 | |||
743730550c | |||
9ab9e2c403 | |||
8da6095c35 | |||
1849e22154 | |||
dec9b2096e | |||
e1df8b5bf6 | |||
634208e3dc | |||
05ca452831 | |||
19b0b0c2f1 | |||
9a74a3b4f5 | |||
25c0f8ebb1 | |||
33e2c03b48 | |||
3c5d498ae5 | |||
93fea877e3 | |||
b7f038de3d | |||
f03696b7a5 | |||
8fb7907a4e | |||
66bd4ee8c8 | |||
fd707242a9 |
@ -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:
|
||||
|
@ -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.0-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,16 +230,6 @@ if (RPM)
|
||||
include(CPack)
|
||||
endif()
|
||||
|
||||
add_subdirectory (src)
|
||||
|
||||
if(BUILDEXAMPLES)
|
||||
add_subdirectory (examples/c++)
|
||||
endif()
|
||||
|
||||
if(BUILDJAVAEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
@ -249,6 +238,16 @@ if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
endif ()
|
||||
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)
|
||||
enable_testing ()
|
||||
|
@ -4,7 +4,7 @@ UPM (Useful Packages & Modules) Sensor/Actuator repository for MRAA
|
||||
The UPM repository provides software drivers for a wide variety of commonly
|
||||
used sensors and actuators. These software drivers interact with the
|
||||
underlying hardware platform (or microcontroller), as well as with the attached
|
||||
sensors, through calls to [MRAA](github.com/intel-iot-devkit/mraa) APIs.
|
||||
sensors, through calls to [MRAA](https://github.com/intel-iot-devkit/mraa) APIs.
|
||||
|
||||
Programmers can access the interfaces for each sensor by including the sensor’s
|
||||
corresponding header file and instantiating the associated sensor class. In the
|
||||
|
@ -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
|
||||
|
@ -4,6 +4,30 @@ 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
|
||||
* Fixes for jhd1313m1 row/font size and reset
|
||||
* Added bacnet utility class
|
||||
* New sensors: bmx055, bmi055, bmc160, bma250e, bmg150, bmm150, t8100, tb7300
|
||||
|
||||
### v0.7.0
|
||||
|
||||
* C++ header files have been renamed from *.h to *.hpp along with all Intel
|
||||
|
@ -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)
|
||||
@ -262,6 +258,8 @@ if (BACNET_FOUND)
|
||||
# we need access to bacnetmstp headers too
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src/bacnetmstp)
|
||||
add_example (e50hx)
|
||||
add_example (t8100)
|
||||
add_example (tb7300)
|
||||
endif()
|
||||
add_example (vcap)
|
||||
add_example (ds2413)
|
||||
@ -269,6 +267,8 @@ add_example (ds18b20)
|
||||
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)
|
||||
@ -287,11 +287,26 @@ 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")
|
||||
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||
add_custom_example (bme280-example bme280.cxx bmp280)
|
||||
add_custom_example (bma250e-example bma250e.cxx bmx055)
|
||||
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()
|
||||
|
123
examples/c++/aeotecdsb09104.cxx
Normal file
123
examples/c++/aeotecdsb09104.cxx
Normal 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
109
examples/c++/aeotecdw2e.cxx
Normal 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
127
examples/c++/aeotecsdg2.cxx
Normal 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
117
examples/c++/aeotecss6.cxx
Normal 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;
|
||||
}
|
@ -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;
|
||||
|
83
examples/c++/bma250e.cxx
Normal file
83
examples/c++/bma250e.cxx
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 "bma250e.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMA250E using default I2C parameters
|
||||
upm::BMA250E *sensor = new upm::BMA250E();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMA250E(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
82
examples/c++/bmc150.cxx
Normal file
82
examples/c++/bmc150.cxx
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 "bmc150.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMC150 using default I2C parameters
|
||||
upm::BMC150 *sensor = new upm::BMC150();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor->getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " uT"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
83
examples/c++/bmg160.cxx
Normal file
83
examples/c++/bmg160.cxx
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 "bmg160.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMG160 using default I2C parameters
|
||||
upm::BMG160 *sensor = new upm::BMG160();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMG160(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " degrees/s"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
82
examples/c++/bmi055.cxx
Normal file
82
examples/c++/bmi055.cxx
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 "bmi055.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMI055 using default I2C parameters
|
||||
upm::BMI055 *sensor = new upm::BMI055();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor->getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " degrees/s"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
78
examples/c++/bmm150.cxx
Normal file
78
examples/c++/bmm150.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "bmm150.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMM150 using default I2C parameters
|
||||
upm::BMM150 *sensor = new upm::BMM150();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: BMM150(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " uT"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
89
examples/c++/bmx055.cxx
Normal file
89
examples/c++/bmx055.cxx
Normal 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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "bmx055.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an BMX055 using default I2C parameters
|
||||
upm::BMX055 *sensor = new upm::BMX055();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor->update();
|
||||
|
||||
sensor->getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor->getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " degrees/s"
|
||||
<< endl;
|
||||
|
||||
sensor->getMagnetometer(&x, &y, &z);
|
||||
cout << "Magnetometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " uT"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -74,8 +74,8 @@ int main(int argc, char **argv)
|
||||
// sensor->setDebug(true);
|
||||
|
||||
cout << endl;
|
||||
cout << "Device Description: " << sensor->getDescription() << endl;
|
||||
cout << "Device Location: " << sensor->getLocation() << endl;
|
||||
cout << "Device Description: " << sensor->getDeviceDescription() << endl;
|
||||
cout << "Device Location: " << sensor->getDeviceLocation() << endl;
|
||||
cout << endl;
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
|
@ -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
11
examples/c++/kxcjk1013.cxx
Executable file → Normal 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);
|
||||
|
@ -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);
|
||||
|
@ -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
63
examples/c++/ms5611.cxx
Normal 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]
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
117
examples/c++/t8100.cxx
Normal file
117
examples/c++/t8100.cxx
Normal 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 "t8100.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an T8100 object for an T8100 device that has 568000
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
T8100 *sensor = new T8100(568000);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor->initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor->setDebug(true);
|
||||
|
||||
cout << endl;
|
||||
cout << "Device Description: " << sensor->getDeviceDescription() << endl;
|
||||
cout << "Device Location: " << sensor->getDeviceLocation() << endl;
|
||||
cout << endl;
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values
|
||||
sensor->update();
|
||||
|
||||
cout << "CO2 Concentration: "
|
||||
<< sensor->getCO2()
|
||||
<< " ppm"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / "
|
||||
<< sensor->getTemperature(true)
|
||||
<< " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor->getHumidity()
|
||||
<< " %RH"
|
||||
<< endl;
|
||||
|
||||
cout << "Relay State: " << sensor->getRelayState()
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
124
examples/c++/tb7300.cxx
Normal file
124
examples/c++/tb7300.cxx
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 "tb7300.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an TB7300 object for an TB7300 device that has 73001
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
TB7300 *sensor = new TB7300(73001);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor->initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor->setDebug(true);
|
||||
|
||||
cout << endl;
|
||||
cout << "Device Name: " << sensor->getDeviceName() << endl;
|
||||
cout << "Device Description: " << sensor->getDeviceDescription() << endl;
|
||||
cout << "Device Location: " << sensor->getDeviceLocation() << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "Fan Mode: "
|
||||
<< sensor->getMultiStateValueText(TB7300::MV_Fan_Mode)
|
||||
<< endl;
|
||||
|
||||
cout << "Fan Status: "
|
||||
<< sensor->getMultiStateValueText(TB7300::MV_Fan_Status)
|
||||
<< endl;
|
||||
|
||||
cout << "System Mode: "
|
||||
<< sensor->getMultiStateValueText(TB7300::MV_System_Mode)
|
||||
<< endl;
|
||||
|
||||
cout << "Service Alarm: "
|
||||
<< sensor->getBinaryInputText(TB7300::BI_Service_Alarm)
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
// update and print the room temperature every 5 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / "
|
||||
<< sensor->getTemperature(true)
|
||||
<< " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -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
114
examples/c++/tzemt400.cxx
Normal 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;
|
||||
}
|
96
examples/java/AeotecDSB09104_Example.java
Normal file
96
examples/java/AeotecDSB09104_Example.java
Normal 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]
|
||||
}
|
||||
}
|
89
examples/java/AeotecDW2E_Example.java
Normal file
89
examples/java/AeotecDW2E_Example.java
Normal 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]
|
||||
}
|
||||
}
|
100
examples/java/AeotecSDG2_Example.java
Normal file
100
examples/java/AeotecSDG2_Example.java
Normal 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]
|
||||
}
|
||||
}
|
91
examples/java/AeotecSS6_Example.java
Normal file
91
examples/java/AeotecSS6_Example.java
Normal 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]
|
||||
}
|
||||
}
|
64
examples/java/BMA250E_Example.java
Normal file
64
examples/java/BMA250E_Example.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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_bmx055.BMA250E;
|
||||
|
||||
public class BMA250E_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMA250E instance using default i2c bus and address
|
||||
BMA250E sensor = new BMA250E();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// BMA250E(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float dataA[] = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + dataA[0]
|
||||
+ " y: " + dataA[1]
|
||||
+ " z: " + dataA[2]
|
||||
+ " g");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
61
examples/java/BMC150_Example.java
Normal file
61
examples/java/BMC150_Example.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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_bmx055.BMC150;
|
||||
|
||||
public class BMC150_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMC150 instance using default i2c bus and address
|
||||
BMC150 sensor = new BMC150();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float data[] = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " g");
|
||||
|
||||
data = sensor.getMagnetometer();
|
||||
|
||||
System.out.println("Magnetometer x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " uT");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
64
examples/java/BMG160_Example.java
Normal file
64
examples/java/BMG160_Example.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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_bmx055.BMG160;
|
||||
|
||||
public class BMG160_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMG160 instance using default i2c bus and address
|
||||
BMG160 sensor = new BMG160();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// BMG160(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float dataA[] = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + dataA[0]
|
||||
+ " y: " + dataA[1]
|
||||
+ " z: " + dataA[2]
|
||||
+ " degrees/s");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
61
examples/java/BMI055_Example.java
Normal file
61
examples/java/BMI055_Example.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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_bmx055.BMI055;
|
||||
|
||||
public class BMI055_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMI055 instance using default i2c bus and address
|
||||
BMI055 sensor = new BMI055();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float data[] = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " degrees/s");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
58
examples/java/BMM150_Example.java
Normal file
58
examples/java/BMM150_Example.java
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_bmx055.BMM150;
|
||||
|
||||
public class BMM150_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMM150 instance using default i2c bus and address
|
||||
BMM150 sensor = new BMM150();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// BMM150(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float dataA[] = sensor.getMagnetometer();
|
||||
|
||||
System.out.println("Magnetometer x: " + dataA[0]
|
||||
+ " y: " + dataA[1]
|
||||
+ " z: " + dataA[2]
|
||||
+ " uT");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
69
examples/java/BMX055_Example.java
Normal file
69
examples/java/BMX055_Example.java
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_bmx055.BMX055;
|
||||
|
||||
public class BMX055_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a BMX055 instance using default i2c bus and address
|
||||
BMX055 sensor = new BMX055();
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
float data[] = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " degrees/s");
|
||||
|
||||
|
||||
data = sensor.getMagnetometer();
|
||||
|
||||
System.out.println("Magnetometer x: " + data[0]
|
||||
+ " y: " + data[1]
|
||||
+ " z: " + data[2]
|
||||
+ " uT");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -124,10 +124,13 @@ if (MODBUS_FOUND)
|
||||
endif()
|
||||
if (BACNET_FOUND)
|
||||
add_example(E50HX_Example e50hx)
|
||||
add_example(T8100_Example t8100)
|
||||
add_example(TB7300_Example tb7300)
|
||||
endif()
|
||||
add_example(VCAP_Example vcap)
|
||||
add_example(BMP280_Example bmp280)
|
||||
add_example(BNO055_Example bno055)
|
||||
add_example(BMX055_Example bmx055)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
@ -136,4 +139,16 @@ add_example_with_path(Lcm1602_parallelSample lcd i2clcd)
|
||||
add_example_with_path(SSD1308_oledSample lcd i2clcd)
|
||||
add_example_with_path(SSD1327_oledSample lcd i2clcd)
|
||||
add_example_with_path(BME280_Example bmp280 bmp280)
|
||||
add_example_with_path(BMA250E_Example bmx055 bmx055)
|
||||
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()
|
||||
|
||||
|
@ -58,8 +58,10 @@ public class E50HX_Example
|
||||
// sensor.setDebug(true);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Device Description: " + sensor.getDescription());
|
||||
System.out.println("Device Location: " + sensor.getLocation());
|
||||
System.out.println("Device Description: "
|
||||
+ sensor.getDeviceDescription());
|
||||
System.out.println("Device Location: "
|
||||
+ sensor.getDeviceLocation());
|
||||
System.out.println();
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
@ -84,7 +86,6 @@ public class E50HX_Example
|
||||
System.out.println();
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
|
97
examples/java/T8100_Example.java
Normal file
97
examples/java/T8100_Example.java
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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_t8100.T8100;
|
||||
|
||||
public class T8100_Example
|
||||
{
|
||||
private static String defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// You will need to edit this example to conform to your site
|
||||
// and your devices, specifically the Device Object Instance
|
||||
// ID passed to the constructor, and the arguments to
|
||||
// initMaster() that are appropriate for your BACnet network.
|
||||
|
||||
if (args.length > 0)
|
||||
defaultDev = args[0];
|
||||
System.out.println("Using device " + defaultDev);
|
||||
System.out.println("Initializing...");
|
||||
|
||||
// Instantiate an T8100 object for an T8100 device that has
|
||||
// 568000 as it's unique Device Object Instance ID. NOTE: You
|
||||
// will certainly want to change this to the correct value for
|
||||
// your device(s).
|
||||
T8100 sensor = new T8100(568000);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001
|
||||
// as our unique Device Object Instance ID, 2 as our MAC
|
||||
// address and using default values for maxMaster and
|
||||
// maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor.setDebug(true);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Device Description: "
|
||||
+ sensor.getDeviceDescription());
|
||||
System.out.println("Device Location: " + sensor.getDeviceLocation());
|
||||
System.out.println();
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
while (true)
|
||||
{
|
||||
// update our values
|
||||
sensor.update();
|
||||
|
||||
System.out.println("CO2 Concentration: "
|
||||
+ sensor.getCO2()
|
||||
+ " ppm");
|
||||
|
||||
// we show both C and F for temperature
|
||||
System.out.println("Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println("Humidity: "
|
||||
+ sensor.getHumidity()
|
||||
+ " %RH");
|
||||
|
||||
System.out.println("Relay State: "
|
||||
+ sensor.getRelayState());
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
99
examples/java/TB7300_Example.java
Normal file
99
examples/java/TB7300_Example.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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_tb7300.TB7300;
|
||||
|
||||
public class TB7300_Example
|
||||
{
|
||||
private static String defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// You will need to edit this example to conform to your site
|
||||
// and your devices, specifically the Device Object Instance
|
||||
// ID passed to the constructor, and the arguments to
|
||||
// initMaster() that are appropriate for your BACnet network.
|
||||
|
||||
if (args.length > 0)
|
||||
defaultDev = args[0];
|
||||
System.out.println("Using device " + defaultDev);
|
||||
System.out.println("Initializing...");
|
||||
|
||||
// Instantiate an TB7300 object for an TB7300 device that has
|
||||
// 73001 as it's unique Device Object Instance ID. NOTE: You
|
||||
// will certainly want to change this to the correct value for
|
||||
// your device(s).
|
||||
TB7300 sensor = new TB7300(73001);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001
|
||||
// as our unique Device Object Instance ID, 2 as our MAC
|
||||
// address and using default values for maxMaster and
|
||||
// maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor.setDebug(true);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Device Name: "
|
||||
+ sensor.getDeviceName());
|
||||
System.out.println("Device Description: "
|
||||
+ sensor.getDeviceDescription());
|
||||
System.out.println("Device Location: " + sensor.getDeviceLocation());
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Fan Mode: "
|
||||
+ sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_Fan_Mode));
|
||||
System.out.println("Fan Status: "
|
||||
+ sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_Fan_Status));
|
||||
System.out.println("System Mode: "
|
||||
+ sensor.getMultiStateValueText(TB7300.MULTISTATE_VALUES_T.MV_System_Mode));
|
||||
System.out.println("Service Alarm:"
|
||||
+ sensor.getBinaryInputText(TB7300.BINARY_INPUTS_T.BI_Service_Alarm));
|
||||
|
||||
System.out.println();
|
||||
|
||||
// update and print the room temperature every 5 seconds
|
||||
while (true)
|
||||
{
|
||||
// update our values
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
System.out.println("Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
98
examples/java/TZEMT400_Example.java
Normal file
98
examples/java/TZEMT400_Example.java
Normal 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]
|
||||
}
|
||||
}
|
103
examples/javascript/aeotecdsb09104.js
Normal file
103
examples/javascript/aeotecdsb09104.js
Normal 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);
|
||||
});
|
95
examples/javascript/aeotecdw2e.js
Normal file
95
examples/javascript/aeotecdw2e.js
Normal 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);
|
||||
});
|
119
examples/javascript/aeotecsdg2.js
Normal file
119
examples/javascript/aeotecsdg2.js
Normal 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);
|
||||
});
|
110
examples/javascript/aeotecss6.js
Normal file
110
examples/javascript/aeotecss6.js
Normal 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);
|
||||
});
|
72
examples/javascript/bma250e.js
Normal file
72
examples/javascript/bma250e.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMA250E instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMA250E();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMA250E(0, -1, 10);
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(x, y, z);
|
||||
console.log("Accelerometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " g");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
69
examples/javascript/bmc150.js
Normal file
69
examples/javascript/bmc150.js
Normal file
@ -0,0 +1,69 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMC150 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMC150();
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(x, y, z);
|
||||
console.log("Accelerometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " g");
|
||||
|
||||
sensor.getMagnetometer(x, y, z);
|
||||
console.log("Magnetometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " uT");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
72
examples/javascript/bmg160.js
Normal file
72
examples/javascript/bmg160.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMG160 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMG160();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMG160(0, -1, 10);
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getGyroscope(x, y, z);
|
||||
console.log("Gyroscope x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " degrees/s");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
69
examples/javascript/bmi055.js
Normal file
69
examples/javascript/bmi055.js
Normal file
@ -0,0 +1,69 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMI055 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMI055();
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(x, y, z);
|
||||
console.log("Accelerometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " g");
|
||||
|
||||
sensor.getGyroscope(x, y, z);
|
||||
console.log("Gyroscope x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " degrees/s");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
65
examples/javascript/bmm150.js
Normal file
65
examples/javascript/bmm150.js
Normal file
@ -0,0 +1,65 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMM150 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMM150();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// BMM150(0, -1, 10);
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getMagnetometer(x, y, z);
|
||||
console.log("Magnetometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " uT");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
76
examples/javascript/bmx055.js
Normal file
76
examples/javascript/bmx055.js
Normal file
@ -0,0 +1,76 @@
|
||||
/*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_bmx055');
|
||||
|
||||
// Instantiate a BMX055 instance using default i2c bus and address
|
||||
var sensor = new sensorObj.BMX055();
|
||||
|
||||
var x = new sensorObj.new_floatp();
|
||||
var y = new sensorObj.new_floatp();
|
||||
var z = new sensorObj.new_floatp();
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(x, y, z);
|
||||
console.log("Accelerometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " g");
|
||||
|
||||
sensor.getGyroscope(x, y, z);
|
||||
console.log("Gyroscope x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " degrees/s");
|
||||
|
||||
sensor.getMagnetometer(x, y, z);
|
||||
console.log("Magnetometer x: "
|
||||
+ sensorObj.floatp_value(x)
|
||||
+ " y: " + sensorObj.floatp_value(y)
|
||||
+ " z: " + sensorObj.floatp_value(z)
|
||||
+ " uT");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -63,8 +63,8 @@ sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
// sensor.setDebug(true);
|
||||
|
||||
console.log("");
|
||||
console.log("Device Description:", sensor.getDescription());
|
||||
console.log("Device Location:", sensor.getLocation());
|
||||
console.log("Device Description:", sensor.getDeviceDescription());
|
||||
console.log("Device Location:", sensor.getDeviceLocation());
|
||||
console.log("");
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
|
@ -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("");
|
||||
|
50
examples/javascript/ms5611.js
Normal file
50
examples/javascript/ms5611.js
Normal 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);
|
||||
});
|
@ -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;
|
98
examples/javascript/t8100.js
Normal file
98
examples/javascript/t8100.js
Normal file
@ -0,0 +1,98 @@
|
||||
/*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_t8100');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
|
||||
var defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// 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);
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an T8100 object for an T8100 device that has 568000
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
var sensor = new sensorObj.T8100(568000);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor.setDebug(true);
|
||||
|
||||
console.log("");
|
||||
console.log("Device Description:", sensor.getDeviceDescription());
|
||||
console.log("Device Location:", sensor.getDeviceLocation());
|
||||
console.log("");
|
||||
|
||||
// update and print a few values every 5 seconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values
|
||||
sensor.update();
|
||||
|
||||
console.log("CO2 Concentration:", sensor.getCO2(), "ppm");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
|
||||
console.log("Humidity:", sensor.getHumidity(), "%RH");
|
||||
|
||||
console.log("Relay State:", sensor.getRelayState());
|
||||
|
||||
console.log("");
|
||||
|
||||
}, 5000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
102
examples/javascript/tb7300.js
Normal file
102
examples/javascript/tb7300.js
Normal file
@ -0,0 +1,102 @@
|
||||
/*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_tb7300');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
// You will need to edit this example to conform to your site and your
|
||||
// devices, specifically the Device Object Instance ID passed to the
|
||||
// constructor, and the arguments to initMaster() that are
|
||||
// appropriate for your BACnet network.
|
||||
|
||||
var defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// 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);
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an TB7300 object for an TB7300 device that has 73001
|
||||
// as it's unique Device Object Instance ID. NOTE: You will
|
||||
// certainly want to change this to the correct value for your
|
||||
// device(s).
|
||||
var sensor = new sensorObj.TB7300(73001);
|
||||
|
||||
// Initialize our BACnet master, if it has not already been
|
||||
// initialized, with the device and baudrate, choosing 1000001 as
|
||||
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||
// using default values for maxMaster and maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||
|
||||
// Uncomment to enable debugging output
|
||||
// sensor.setDebug(true);
|
||||
|
||||
console.log("");
|
||||
console.log("Device Name:", sensor.getDeviceName());
|
||||
console.log("Device Description:", sensor.getDeviceDescription());
|
||||
console.log("Device Location:", sensor.getDeviceLocation());
|
||||
console.log("");
|
||||
|
||||
console.log("Fan Mode:",
|
||||
sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Mode));
|
||||
console.log("Fan Status:",
|
||||
sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Status));
|
||||
console.log("System Mode:",
|
||||
sensor.getMultiStateValueText(sensorObj.TB7300.MV_System_Mode));
|
||||
console.log("Service Alarm:",
|
||||
sensor.getBinaryInputText(sensorObj.TB7300.BI_Service_Alarm));
|
||||
console.log("");
|
||||
|
||||
// update and print the room temperature every 5 seconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
console.log("");
|
||||
|
||||
}, 5000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
104
examples/javascript/tzemt400.js
Normal file
104
examples/javascript/tzemt400.js
Normal 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);
|
||||
});
|
88
examples/python/aeotecdsb09104.py
Normal file
88
examples/python/aeotecdsb09104.py
Normal 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)
|
80
examples/python/aeotecdw2e.py
Normal file
80
examples/python/aeotecdw2e.py
Normal 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)
|
96
examples/python/aeotecsdg2.py
Normal file
96
examples/python/aeotecsdg2.py
Normal 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)
|
87
examples/python/aeotecss6.py
Normal file
87
examples/python/aeotecss6.py
Normal 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)
|
66
examples/python/bma250e.py
Normal file
66
examples/python/bma250e.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.BMA250E()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# BMA250E(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getAccelerometer(x, y, z)
|
||||
print "Accelerometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " g"
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Compensation Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
65
examples/python/bmc150.py
Normal file
65
examples/python/bmc150.py
Normal file
@ -0,0 +1,65 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMC150 instance using default i2c bus and address
|
||||
sensor = sensorObj.BMC150()
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getAccelerometer(x, y, z)
|
||||
print "Accelerometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " g"
|
||||
|
||||
sensor.getMagnetometer(x, y, z)
|
||||
print "Magnetometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " uT"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
66
examples/python/bmg160.py
Normal file
66
examples/python/bmg160.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.BMG160()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# BMG160(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getGyroscope(x, y, z)
|
||||
print "Gyroscope x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " degrees/s"
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Compensation Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
65
examples/python/bmi055.py
Normal file
65
examples/python/bmi055.py
Normal file
@ -0,0 +1,65 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMI055 instance using default i2c bus and address
|
||||
sensor = sensorObj.BMI055()
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getAccelerometer(x, y, z)
|
||||
print "Accelerometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " g"
|
||||
|
||||
sensor.getGyroscope(x, y, z)
|
||||
print "Gyroscope x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " degrees/s"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
62
examples/python/bmm150.py
Normal file
62
examples/python/bmm150.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.BMM150()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# BMM150(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getMagnetometer(x, y, z)
|
||||
print "Magnetometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " uT"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
71
examples/python/bmx055.py
Normal file
71
examples/python/bmx055.py
Normal file
@ -0,0 +1,71 @@
|
||||
#!/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_bmx055 as sensorObj
|
||||
|
||||
# Instantiate a BMX055 instance using default i2c bus and address
|
||||
sensor = sensorObj.BMX055()
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
x = sensorObj.new_floatp()
|
||||
y = sensorObj.new_floatp()
|
||||
z = sensorObj.new_floatp()
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
sensor.getAccelerometer(x, y, z)
|
||||
print "Accelerometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " g"
|
||||
|
||||
sensor.getGyroscope(x, y, z)
|
||||
print "Gyroscope x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " degrees/s"
|
||||
|
||||
sensor.getMagnetometer(x, y, z)
|
||||
print "Magnetometer x:", sensorObj.floatp_value(x),
|
||||
print " y:", sensorObj.floatp_value(y),
|
||||
print " z:", sensorObj.floatp_value(z),
|
||||
print " uT"
|
||||
|
||||
print
|
||||
time.sleep(.250)
|
@ -69,8 +69,8 @@ sensor.initMaster(defaultDev, 38400, 1000001, 2)
|
||||
|
||||
# output the serial number and firmware revision
|
||||
print
|
||||
print "Device Description:", sensor.getDescription()
|
||||
print "Device Location:", sensor.getLocation()
|
||||
print "Device Description:", sensor.getDeviceDescription()
|
||||
print "Device Location:", sensor.getDeviceLocation()
|
||||
print
|
||||
|
||||
# update and print available values every second
|
||||
|
@ -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
|
||||
|
@ -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
|
97
examples/python/t8100.py
Normal file
97
examples/python/t8100.py
Normal file
@ -0,0 +1,97 @@
|
||||
#!/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_t8100 as sensorObj
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting..."
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# You will need to edit this example to conform to your site and your
|
||||
# devices, specifically the Device Object Instance ID passed to the
|
||||
# constructor, and the arguments to initMaster() that are
|
||||
# appropriate for your BACnet network.
|
||||
|
||||
defaultDev = "/dev/ttyUSB0"
|
||||
|
||||
# if an argument was specified, use it as the device instead
|
||||
if (len(sys.argv) > 1):
|
||||
defaultDev = sys.argv[1]
|
||||
|
||||
print "Using device", defaultDev
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an T8100 object for an T8100 device that has 568000
|
||||
# as it's unique Device Object Instance ID. NOTE: You will
|
||||
# certainly want to change this to the correct value for your
|
||||
# device(s).
|
||||
sensor = sensorObj.T8100(568000)
|
||||
|
||||
# Initialize our BACnet master, if it has not already been
|
||||
# initialized, with the device and baudrate, choosing 1000001 as
|
||||
# our unique Device Object Instance ID, 2 as our MAC address and
|
||||
# using default values for maxMaster and maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2)
|
||||
|
||||
# Uncomment to enable debugging output
|
||||
# sensor.setDebug(True);
|
||||
|
||||
# output the serial number and firmware revision
|
||||
print
|
||||
print "Device Description:", sensor.getDeviceDescription()
|
||||
print "Device Location:", sensor.getDeviceLocation()
|
||||
print
|
||||
|
||||
# update and print available values every 5 seconds
|
||||
while (1):
|
||||
# update our values
|
||||
sensor.update();
|
||||
|
||||
print "CO2 Concentration:",
|
||||
print sensor.getCO2(),
|
||||
print "ppm"
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(),
|
||||
print "C /", sensor.getTemperature(True), "F"
|
||||
|
||||
print "Humidity:",
|
||||
print sensor.getHumidity(),
|
||||
print "%RH"
|
||||
|
||||
print "Relay State:",
|
||||
print sensor.getRelayState()
|
||||
|
||||
print
|
||||
time.sleep(5)
|
96
examples/python/tb7300.py
Normal file
96
examples/python/tb7300.py
Normal 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_tb7300 as sensorObj
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting..."
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# You will need to edit this example to conform to your site and your
|
||||
# devices, specifically the Device Object Instance ID passed to the
|
||||
# constructor, and the arguments to initMaster() that are
|
||||
# appropriate for your BACnet network.
|
||||
|
||||
defaultDev = "/dev/ttyUSB0"
|
||||
|
||||
# if an argument was specified, use it as the device instead
|
||||
if (len(sys.argv) > 1):
|
||||
defaultDev = sys.argv[1]
|
||||
|
||||
print "Using device", defaultDev
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an TB7300 object for an TB7300 device that has 73001
|
||||
# as it's unique Device Object Instance ID. NOTE: You will
|
||||
# certainly want to change this to the correct value for your
|
||||
# device(s).
|
||||
sensor = sensorObj.TB7300(73001)
|
||||
|
||||
# Initialize our BACnet master, if it has not already been
|
||||
# initialized, with the device and baudrate, choosing 1000001 as
|
||||
# our unique Device Object Instance ID, 2 as our MAC address and
|
||||
# using default values for maxMaster and maxInfoFrames
|
||||
sensor.initMaster(defaultDev, 38400, 1000001, 2)
|
||||
|
||||
# Uncomment to enable debugging output
|
||||
# sensor.setDebug(True);
|
||||
|
||||
# output the serial number and firmware revision
|
||||
print
|
||||
print "Device Name:", sensor.getDeviceName()
|
||||
print "Device Description:", sensor.getDeviceDescription()
|
||||
print "Device Location:", sensor.getDeviceLocation()
|
||||
print
|
||||
|
||||
print "Fan Mode:", sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Mode)
|
||||
print "Fan Status:",
|
||||
print sensor.getMultiStateValueText(sensorObj.TB7300.MV_Fan_Status)
|
||||
print "System Mode:",
|
||||
print sensor.getMultiStateValueText(sensorObj.TB7300.MV_System_Mode)
|
||||
print "Service Alarm:",
|
||||
print sensor.getBinaryInputText(sensorObj.TB7300.BI_Service_Alarm)
|
||||
print
|
||||
|
||||
# update and print the room temperature every 5 seconds
|
||||
while (1):
|
||||
# update our values
|
||||
sensor.update();
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(),
|
||||
print "C /", sensor.getTemperature(True), "F"
|
||||
|
||||
print
|
||||
time.sleep(5)
|
82
examples/python/tzemt400.py
Normal file
82
examples/python/tzemt400.py
Normal 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)
|
@ -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 ()
|
||||
@ -178,6 +178,7 @@ endmacro()
|
||||
if (SWIG_FOUND)
|
||||
if (BUILDSWIGPYTHON)
|
||||
if(NOT PYTHONLIBS_FOUND)
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
@ -1,7 +1,7 @@
|
||||
set (libname "bacnetmstp")
|
||||
set (libdescription "upm driver module for BACnet MS/TP devices")
|
||||
set (module_src ${libname}.cxx device-client.c)
|
||||
set (module_hpp ${libname}.hpp)
|
||||
set (module_src ${libname}.cxx device-client.c bacnetutil.cxx)
|
||||
set (module_hpp ${libname}.hpp bacnetutil.hpp)
|
||||
|
||||
pkg_check_modules(BACNET libbacnet)
|
||||
if (BACNET_FOUND)
|
||||
@ -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 ()
|
||||
|
@ -57,7 +57,7 @@ BACNETMSTP::BACNETMSTP()
|
||||
|
||||
memset(m_rxBuffer, 0, MAX_MPDU);
|
||||
|
||||
m_returnedValue = {0};
|
||||
m_returnedValue.clear();
|
||||
m_targetAddress = {0};
|
||||
m_invokeID = 0;
|
||||
m_errorDetected = false;
|
||||
@ -165,6 +165,15 @@ void BACNETMSTP::handlerReadPropertyAck(uint8_t* service_request,
|
||||
int len = 0;
|
||||
BACNET_READ_PROPERTY_DATA data;
|
||||
|
||||
// clear our stored data
|
||||
instance()->m_returnedValue.clear();
|
||||
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
memset((void *)&value, 0, sizeof(value));
|
||||
|
||||
uint8_t *application_data = 0;
|
||||
int application_data_len = 0;
|
||||
|
||||
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||
(service_data->invoke_id == instance()->m_invokeID))
|
||||
{
|
||||
@ -173,19 +182,49 @@ void BACNETMSTP::handlerReadPropertyAck(uint8_t* service_request,
|
||||
|
||||
len = rp_ack_decode_service_request(service_request, service_len,
|
||||
&data);
|
||||
// FIXME: we don't currently handle arrays (len < service_len)
|
||||
|
||||
// store any delivered data elements
|
||||
if (len > 0)
|
||||
{
|
||||
bacapp_decode_application_data(data.application_data,
|
||||
data.application_data_len,
|
||||
&(instance()->m_returnedValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
// shouldn't happen?
|
||||
cerr << __FUNCTION__ << ": decode app data failed" << endl;
|
||||
application_data_len = data.application_data_len;
|
||||
application_data = data.application_data;
|
||||
|
||||
while (true)
|
||||
{
|
||||
len = bacapp_decode_application_data(application_data,
|
||||
application_data_len,
|
||||
&value);
|
||||
if (len > 0)
|
||||
{
|
||||
// store a copy
|
||||
instance()->m_returnedValue.push_back(value);
|
||||
|
||||
if (len < application_data_len)
|
||||
{
|
||||
// there is more data
|
||||
application_data += len;
|
||||
application_data_len -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we are done
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// shouldn't happen?
|
||||
cerr << __FUNCTION__ << ": decode app data failed" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (instance()->m_debugging)
|
||||
cerr << __FUNCTION__ << ": STORED "
|
||||
<< instance()->m_returnedValue.size()
|
||||
<< " data elements." << endl;
|
||||
}
|
||||
|
||||
void BACNETMSTP::handlerWritePropertyAck(BACNET_ADDRESS* src,
|
||||
@ -553,7 +592,7 @@ bool BACNETMSTP::readProperty(uint32_t targetDeviceInstanceID,
|
||||
m_command.readPropArgs.objType = objType;
|
||||
m_command.readPropArgs.objInstance = objInstance;
|
||||
m_command.readPropArgs.objProperty = objProperty;
|
||||
m_command.readPropArgs.arrayIndex = arrayIndex; // not implemented in the ack handler!
|
||||
m_command.readPropArgs.arrayIndex = arrayIndex;
|
||||
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": calling dispatchRequest()..." << endl;
|
||||
@ -591,7 +630,7 @@ bool BACNETMSTP::writeProperty(uint32_t targetDeviceInstanceID,
|
||||
m_command.writePropArgs.objProperty = objProperty;
|
||||
m_command.writePropArgs.propValue = propValue;
|
||||
m_command.writePropArgs.propPriority = propPriority;
|
||||
m_command.writePropArgs.arrayIndex = arrayIndex; // not implemented!
|
||||
m_command.writePropArgs.arrayIndex = arrayIndex;
|
||||
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": calling dispatchRequest()..." << endl;
|
||||
@ -605,158 +644,163 @@ bool BACNETMSTP::writeProperty(uint32_t targetDeviceInstanceID,
|
||||
return error;
|
||||
}
|
||||
|
||||
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::getData()
|
||||
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::getData(int index)
|
||||
{
|
||||
return m_returnedValue;
|
||||
return m_returnedValue.at(index);
|
||||
}
|
||||
|
||||
uint8_t BACNETMSTP::getDataType()
|
||||
int BACNETMSTP::getDataNumElements()
|
||||
{
|
||||
return m_returnedValue.tag;
|
||||
return m_returnedValue.size();
|
||||
}
|
||||
|
||||
float BACNETMSTP::getDataTypeReal()
|
||||
uint8_t BACNETMSTP::getDataType(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_REAL)
|
||||
return m_returnedValue.type.Real;
|
||||
return m_returnedValue.at(index).tag;
|
||||
}
|
||||
|
||||
float BACNETMSTP::getDataTypeReal(int index)
|
||||
{
|
||||
if (getDataType(index) == BACNET_APPLICATION_TAG_REAL)
|
||||
return m_returnedValue.at(index).type.Real;
|
||||
else
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Not of Real type, trying to convert..." << endl;
|
||||
|
||||
// try to convert or throw
|
||||
switch (getDataType())
|
||||
switch (getDataType(index))
|
||||
{
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
return (getDataTypeBoolean() ? 1.0 : 0.0);
|
||||
return (getDataTypeBoolean(index) ? 1.0 : 0.0);
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
return float(getDataTypeUnsignedInt());
|
||||
return float(getDataTypeUnsignedInt(index));
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
return float(getDataTypeSignedInt());
|
||||
return float(getDataTypeSignedInt(index));
|
||||
default:
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to Real");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool BACNETMSTP::getDataTypeBoolean()
|
||||
bool BACNETMSTP::getDataTypeBoolean(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_BOOLEAN)
|
||||
return ((m_returnedValue.type.Boolean) ? true : false);
|
||||
if (getDataType(index) == BACNET_APPLICATION_TAG_BOOLEAN)
|
||||
return ((m_returnedValue.at(index).type.Boolean) ? true : false);
|
||||
else
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to Bool");
|
||||
}
|
||||
|
||||
unsigned int BACNETMSTP::getDataTypeUnsignedInt()
|
||||
unsigned int BACNETMSTP::getDataTypeUnsignedInt(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return m_returnedValue.type.Unsigned_Int;
|
||||
if (getDataType(index) == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return m_returnedValue.at(index).type.Unsigned_Int;
|
||||
else
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to UnsignedInt");
|
||||
}
|
||||
|
||||
int BACNETMSTP::getDataTypeSignedInt()
|
||||
int BACNETMSTP::getDataTypeSignedInt(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_SIGNED_INT)
|
||||
return m_returnedValue.type.Signed_Int;
|
||||
if (getDataType(index) == BACNET_APPLICATION_TAG_SIGNED_INT)
|
||||
return m_returnedValue.at(index).type.Signed_Int;
|
||||
else
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to SignedInt");
|
||||
}
|
||||
|
||||
#if defined(BACAPP_DOUBLE)
|
||||
double BACNETMSTP::getDataTypeDouble()
|
||||
double BACNETMSTP::getDataTypeDouble(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_DOUBLE)
|
||||
return m_returnedValue.type.Double;
|
||||
return m_returnedValue.at(index).type.Double;
|
||||
else
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Not of Double type, trying to convert..." << endl;
|
||||
|
||||
// try to convert or throw
|
||||
switch (getDataType())
|
||||
switch (getDataType(index))
|
||||
{
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
return double(getDataTypeReal());
|
||||
return double(getDataTypeReal(index));
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
return (getDataTypeBoolean() ? 1.0 : 0.0);
|
||||
return (getDataTypeBoolean(index) ? 1.0 : 0.0);
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
return double(getDataTypeUnsignedInt());
|
||||
return double(getDataTypeUnsignedInt(index));
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
return double(getDataTypeSignedInt());
|
||||
return double(getDataTypeSignedInt(index));
|
||||
default:
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to Double");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // BACAPP_DOUBLE
|
||||
|
||||
unsigned int BACNETMSTP::getDataTypeEnum()
|
||||
unsigned int BACNETMSTP::getDataTypeEnum(int index)
|
||||
{
|
||||
if (getDataType() == BACNET_APPLICATION_TAG_ENUMERATED)
|
||||
return m_returnedValue.type.Enumerated;
|
||||
if (getDataType(index) == BACNET_APPLICATION_TAG_ENUMERATED)
|
||||
return m_returnedValue.at(index).type.Enumerated;
|
||||
else
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to Enum");
|
||||
}
|
||||
|
||||
std::string BACNETMSTP::getDataTypeString()
|
||||
std::string BACNETMSTP::getDataTypeString(int index)
|
||||
{
|
||||
string retval;
|
||||
|
||||
// Here, we can try to accomodate all the types
|
||||
switch(getDataType())
|
||||
switch(getDataType(index))
|
||||
{
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
retval = std::to_string(getDataTypeReal());
|
||||
retval = std::to_string(getDataTypeReal(index));
|
||||
break;
|
||||
|
||||
#if defined(BACAPP_DOUBLE)
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
retval = std::to_string(getDataTypeDouble());
|
||||
retval = std::to_string(getDataTypeDouble(index));
|
||||
break;
|
||||
#endif // BACAPP_DOUBLE
|
||||
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
retval = std::to_string(getDataTypeUnsignedInt());
|
||||
retval = std::to_string(getDataTypeUnsignedInt(index));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
retval = std::to_string(getDataTypeSignedInt());
|
||||
retval = std::to_string(getDataTypeSignedInt(index));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
retval = (getDataTypeBoolean() ? string("true") : string("false"));
|
||||
retval = (getDataTypeBoolean(index) ? string("true") : string("false"));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||
retval = string(characterstring_value(&m_returnedValue.type.Character_String),
|
||||
retval = string(characterstring_value(&m_returnedValue.at(index).type.Character_String),
|
||||
|
||||
characterstring_length(&m_returnedValue.type.Character_String));
|
||||
characterstring_length(&m_returnedValue.at(index).type.Character_String));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
{
|
||||
string tmpstr((char *)octetstring_value(&m_returnedValue.type.Octet_String),
|
||||
string tmpstr((char *)octetstring_value(&m_returnedValue.at(index).type.Octet_String),
|
||||
|
||||
octetstring_length(&m_returnedValue.type.Octet_String));
|
||||
octetstring_length(&m_returnedValue.at(index).type.Octet_String));
|
||||
retval = string2HexString(tmpstr);
|
||||
}
|
||||
|
||||
@ -764,11 +808,12 @@ std::string BACNETMSTP::getDataTypeString()
|
||||
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
{
|
||||
int len = bitstring_bits_used(&m_returnedValue.type.Bit_String);
|
||||
int len = bitstring_bits_used(&m_returnedValue.at(index).type.Bit_String);
|
||||
|
||||
for (int i=0; i<len; i++)
|
||||
{
|
||||
if (bitstring_bit(&m_returnedValue.type.Bit_String, uint8_t(i)))
|
||||
if (bitstring_bit(&m_returnedValue.at(index).type.Bit_String,
|
||||
uint8_t(i)))
|
||||
retval += "1";
|
||||
else
|
||||
retval += "0";
|
||||
@ -783,7 +828,7 @@ std::string BACNETMSTP::getDataTypeString()
|
||||
default:
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": data type ("
|
||||
+ std::to_string(int(getDataType()))
|
||||
+ std::to_string(int(getDataType(index)))
|
||||
+ ") is not convertible to String");
|
||||
break;
|
||||
}
|
||||
@ -860,6 +905,17 @@ BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataString(string value)
|
||||
return data;
|
||||
}
|
||||
|
||||
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataEnum(uint32_t value)
|
||||
{
|
||||
BACNET_APPLICATION_DATA_VALUE data;
|
||||
|
||||
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||
|
||||
data.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||
data.type.Enumerated = value;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
string BACNETMSTP::string2HexString(string input)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// we only support a BACnet RS-485 MS/TP datalink
|
||||
#define BACDL_MSTP 1
|
||||
@ -185,8 +186,7 @@ namespace upm {
|
||||
* instance you wish to access. It should be one of the
|
||||
* BACNET_PROPERTY_ID values.
|
||||
* @param arrayIndex This specifies the index number of an array
|
||||
* property. This is not currently supported. Until it is, leave
|
||||
* the default at BACNET_ARRAY_ALL.
|
||||
* property. The default is BACNET_ARRAY_ALL.
|
||||
* @return true if an error occurred, false otherwise.
|
||||
*/
|
||||
bool readProperty(uint32_t targetDeviceInstanceID,
|
||||
@ -225,8 +225,7 @@ namespace upm {
|
||||
* information in the bacnet-stack documentation as to whether
|
||||
* this is even supported.
|
||||
* @param arrayIndex This specifies the index number of an array
|
||||
* property. This is not currently supported. Until it is, leave
|
||||
* the default at BACNET_ARRAY_ALL.
|
||||
* property. The default is BACNET_ARRAY_ALL.
|
||||
* @return true if an error occurred, false otherwise.
|
||||
*/
|
||||
bool writeProperty(uint32_t targetDeviceInstanceID,
|
||||
@ -242,19 +241,32 @@ namespace upm {
|
||||
* to return a BACNET_APPLICATION_DATA_VALUE structure containing
|
||||
* the returned data.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return a BACNET_APPLICATION_DATA_VALUE structure containing
|
||||
* the returned data.
|
||||
*/
|
||||
BACNET_APPLICATION_DATA_VALUE getData();
|
||||
BACNET_APPLICATION_DATA_VALUE getData(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
* used to return the number of data elements returned. This will
|
||||
* usually be 1, unless reading an array.
|
||||
*
|
||||
* @return The number of data elements received.
|
||||
*/
|
||||
int getDataNumElements();
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
* used to return the BACnet data type of the returned data. It
|
||||
* will be one of the BACNET_APPLICATION_TAG_* values.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A BACNET_APPLICATION_TAG_* value
|
||||
*/
|
||||
uint8_t getDataType();
|
||||
uint8_t getDataType(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -263,9 +275,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_REAL, and the value returned cannot be
|
||||
* safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A floating point value representing the returned data
|
||||
*/
|
||||
float getDataTypeReal();
|
||||
float getDataTypeReal(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -274,9 +288,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_BOOLEAN, and the value returned cannot
|
||||
* be safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A boolean value representing the returned data
|
||||
*/
|
||||
bool getDataTypeBoolean();
|
||||
bool getDataTypeBoolean(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -285,9 +301,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_UNSIGNED_INT, and the value returned
|
||||
* cannot be safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return An unsigned int value representing the returned data
|
||||
*/
|
||||
unsigned int getDataTypeUnsignedInt();
|
||||
unsigned int getDataTypeUnsignedInt(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -296,9 +314,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_SIGNED_INT, and the value returned
|
||||
* cannot be safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A signed int value representing the returned data
|
||||
*/
|
||||
int getDataTypeSignedInt();
|
||||
int getDataTypeSignedInt(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -308,9 +328,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_CHARACTER_STRING, and the value returned
|
||||
* cannot be safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A string value representing the returned data
|
||||
*/
|
||||
std::string getDataTypeString();
|
||||
std::string getDataTypeString(int index=0);
|
||||
|
||||
/**
|
||||
* After a successful readProperty request, this method can be
|
||||
@ -318,9 +340,11 @@ namespace upm {
|
||||
* enumeration. If the data type (getDataType()) is not a
|
||||
* BACNET_APPLICATION_TAG_ENUMERATED an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return An unsigned int representing a BACnet enumerant
|
||||
*/
|
||||
unsigned int getDataTypeEnum();
|
||||
unsigned int getDataTypeEnum(int index=0);
|
||||
|
||||
#if defined(BACAPP_DOUBLE)
|
||||
/**
|
||||
@ -330,9 +354,11 @@ namespace upm {
|
||||
* BACNET_APPLICATION_TAG_DOUBLE, and the value returned cannot be
|
||||
* safely converted, an exception is thrown.
|
||||
*
|
||||
* @param index into the list of returned data. 0 (first) is the
|
||||
* default.
|
||||
* @return A double floating point value representing the returned data
|
||||
*/
|
||||
double getDataTypeDouble();
|
||||
double getDataTypeDouble(int index=0);
|
||||
#endif // BACAPP_DOUBLE
|
||||
|
||||
/**
|
||||
@ -392,6 +418,18 @@ namespace upm {
|
||||
*/
|
||||
BACNET_APPLICATION_DATA_VALUE createDataString(std::string value);
|
||||
|
||||
/**
|
||||
* This method is used to create and return an initialized
|
||||
* BACNET_APPLICATION_DATA_VALUE containing an enumeration. A
|
||||
* pointer to this returned structure can then be used with
|
||||
* writeProperty().
|
||||
*
|
||||
* @param value The BACnet enumeration to initialize the
|
||||
* structure to.
|
||||
* @return An initialized structure containing the value
|
||||
*/
|
||||
BACNET_APPLICATION_DATA_VALUE createDataEnum(uint32_t value);
|
||||
|
||||
/**
|
||||
* Return an enumration of the last error type to occur. The
|
||||
* value returned will be one of the BACERR_TYPE_T values.
|
||||
@ -664,7 +702,7 @@ namespace upm {
|
||||
std::string m_upmErrorString;
|
||||
|
||||
// our returned data from readProperty()
|
||||
BACNET_APPLICATION_DATA_VALUE m_returnedValue;
|
||||
std::vector<BACNET_APPLICATION_DATA_VALUE> m_returnedValue;
|
||||
|
||||
// current bound target address of dispatched service request
|
||||
// (read/write prop, etc)
|
||||
|
925
src/bacnetmstp/bacnetutil.cxx
Normal file
925
src/bacnetmstp/bacnetutil.cxx
Normal file
@ -0,0 +1,925 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "bacnetutil.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
|
||||
BACNETUTIL::BACNETUTIL(uint32_t targetDeviceObjectID) :
|
||||
m_instance(0)
|
||||
{
|
||||
// Save our device's ID
|
||||
m_targetDeviceObjectID = targetDeviceObjectID;
|
||||
|
||||
// create the BACNETMSTP instance here if it does not already exist,
|
||||
// and store the pointer in our class to save on some typing.
|
||||
|
||||
m_instance = BACNETMSTP::instance();
|
||||
|
||||
// now see if it has been initialized yet for init()
|
||||
m_initialized = m_instance->isInitialized();
|
||||
|
||||
setDebug(false);
|
||||
|
||||
// we disable this by default for performance reasons
|
||||
checkReliability(false);
|
||||
|
||||
// empty our unit caches
|
||||
m_avUnitCache.clear();
|
||||
m_aiUnitCache.clear();
|
||||
|
||||
// empty our msv info store
|
||||
m_msvInfo.clear();
|
||||
|
||||
// empty our binary info stores
|
||||
m_bvInfo.clear();
|
||||
m_biInfo.clear();
|
||||
}
|
||||
|
||||
BACNETUTIL::~BACNETUTIL()
|
||||
{
|
||||
}
|
||||
|
||||
void BACNETUTIL::initMaster(std::string port, int baudRate,
|
||||
int deviceInstanceID, int macAddr, int maxMaster,
|
||||
int maxInfoFrames)
|
||||
{
|
||||
// first we check to see if the bacnetmstp instance has already been
|
||||
// initialized (determined in the ctor). If not, we will do so here
|
||||
// with the arguments specified. If it has already been
|
||||
// initialized, then we do not bother calling bacnetmstp's init
|
||||
// again as it will just be ignored.
|
||||
|
||||
if (!m_initialized)
|
||||
m_instance->initMaster(port, baudRate, deviceInstanceID,
|
||||
macAddr, maxMaster, maxInfoFrames);
|
||||
|
||||
// either it threw an exception, was already initialized or it's
|
||||
// initialized now...
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void BACNETUTIL::setDebug(bool enable)
|
||||
{
|
||||
m_debugging = enable;
|
||||
|
||||
// we also enable/disable debugging in BACNETMSTP
|
||||
m_instance->setDebug(enable);
|
||||
}
|
||||
|
||||
float BACNETUTIL::getAnalogValue(uint32_t objInstance)
|
||||
{
|
||||
// check reliability first, if enabled
|
||||
if (m_checkReliability)
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_VALUE,
|
||||
objInstance, PROP_RELIABILITY))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (reliability): " << getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_RELIABILITY reliable =
|
||||
static_cast<BACNET_RELIABILITY>(m_instance->getDataTypeEnum());
|
||||
|
||||
if (reliable != RELIABILITY_NO_FAULT_DETECTED)
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Reliability check failed" << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": Reliability check failed");
|
||||
}
|
||||
}
|
||||
|
||||
// now get the value
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (value): " << getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeReal();
|
||||
}
|
||||
|
||||
void BACNETUTIL::setAnalogValue(uint32_t objInstance,
|
||||
float value)
|
||||
{
|
||||
// Write the value
|
||||
BACNET_APPLICATION_DATA_VALUE myData =
|
||||
m_instance->createDataReal(value);
|
||||
|
||||
// write it
|
||||
if (m_instance->writeProperty(m_targetDeviceObjectID, OBJECT_ANALOG_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE,
|
||||
&myData))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
}
|
||||
|
||||
string BACNETUTIL::getAnalogValueUnits(uint32_t objInstance)
|
||||
{
|
||||
// see if it exists
|
||||
if (m_avUnitCache.count(objInstance) == 0)
|
||||
{
|
||||
// then we need to fetch it
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_VALUE,
|
||||
objInstance, PROP_UNITS))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
// set to empty string
|
||||
m_avUnitCache[objInstance] = string("");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cache it for future calls
|
||||
m_avUnitCache[objInstance] =
|
||||
string(bactext_engineering_unit_name(m_instance->getDataTypeEnum()));
|
||||
}
|
||||
}
|
||||
|
||||
return m_avUnitCache[objInstance];
|
||||
}
|
||||
|
||||
float BACNETUTIL::getAnalogInput(uint32_t objInstance)
|
||||
{
|
||||
// check reliability first, if enabled
|
||||
if (m_checkReliability)
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_INPUT,
|
||||
objInstance, PROP_RELIABILITY))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (reliability): "
|
||||
<< getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_RELIABILITY reliable =
|
||||
static_cast<BACNET_RELIABILITY>(m_instance->getDataTypeEnum());
|
||||
|
||||
if (reliable != RELIABILITY_NO_FAULT_DETECTED)
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Reliability check failed" << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": Reliability check failed");
|
||||
}
|
||||
}
|
||||
|
||||
// now get the value
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_INPUT,
|
||||
objInstance, PROP_PRESENT_VALUE))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (value): " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeReal();
|
||||
}
|
||||
|
||||
bool BACNETUTIL::getBinaryInput(uint32_t objInstance)
|
||||
{
|
||||
// check the BV info, and update/cache the data if needed
|
||||
updateBinaryInputInfo(objInstance);
|
||||
|
||||
// check reliability first, if enabled
|
||||
if (m_checkReliability)
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_BINARY_INPUT,
|
||||
objInstance, PROP_RELIABILITY))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (reliability): "
|
||||
<< getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_RELIABILITY reliable =
|
||||
static_cast<BACNET_RELIABILITY>(m_instance->getDataTypeEnum());
|
||||
|
||||
if (reliable != RELIABILITY_NO_FAULT_DETECTED)
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Reliability check failed" << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": Reliability check failed");
|
||||
}
|
||||
}
|
||||
|
||||
// now get the value
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_BINARY_INPUT,
|
||||
objInstance, PROP_PRESENT_VALUE))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (value): " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_BINARY_PV bpv =
|
||||
static_cast<BACNET_BINARY_PV>(m_instance->getDataTypeEnum());
|
||||
|
||||
return (bpv == BINARY_INACTIVE) ? false : true;
|
||||
}
|
||||
|
||||
bool BACNETUTIL::getBinaryValue(uint32_t objInstance)
|
||||
{
|
||||
// check the BV info, and update/cache the data if needed
|
||||
updateBinaryValueInfo(objInstance);
|
||||
|
||||
// check reliability first, if enabled
|
||||
if (m_checkReliability)
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_BINARY_VALUE,
|
||||
objInstance, PROP_RELIABILITY))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (reliability): "
|
||||
<< getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_RELIABILITY reliable =
|
||||
static_cast<BACNET_RELIABILITY>(m_instance->getDataTypeEnum());
|
||||
|
||||
if (reliable != RELIABILITY_NO_FAULT_DETECTED)
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Reliability check failed" << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": Reliability check failed");
|
||||
}
|
||||
}
|
||||
|
||||
// now get the value
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_BINARY_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (value): " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_BINARY_PV bpv =
|
||||
static_cast<BACNET_BINARY_PV>(m_instance->getDataTypeEnum());
|
||||
|
||||
return (bpv == BINARY_INACTIVE) ? false : true;
|
||||
}
|
||||
|
||||
void BACNETUTIL::setBinaryValue(uint32_t objInstance,
|
||||
bool value)
|
||||
{
|
||||
BACNET_BINARY_PV bpv = (value) ? BINARY_ACTIVE : BINARY_INACTIVE;
|
||||
|
||||
// Write the value
|
||||
BACNET_APPLICATION_DATA_VALUE myData =
|
||||
m_instance->createDataEnum(bpv);
|
||||
|
||||
// write it
|
||||
if (m_instance->writeProperty(m_targetDeviceObjectID, OBJECT_BINARY_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE,
|
||||
&myData))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
}
|
||||
|
||||
string BACNETUTIL::getAnalogInputUnits(uint32_t objInstance)
|
||||
{
|
||||
// see if it exists
|
||||
if (m_aiUnitCache.count(objInstance) == 0)
|
||||
{
|
||||
// then we need to fetch it
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_ANALOG_INPUT,
|
||||
objInstance, PROP_UNITS))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
// set to empty string
|
||||
m_aiUnitCache[objInstance] = string("");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cache it for future calls
|
||||
m_aiUnitCache[objInstance] =
|
||||
string(bactext_engineering_unit_name(m_instance->getDataTypeEnum()));
|
||||
}
|
||||
}
|
||||
|
||||
return m_aiUnitCache[objInstance];
|
||||
}
|
||||
|
||||
unsigned int BACNETUTIL::getMultiStateValue(uint32_t objInstance)
|
||||
{
|
||||
// check the MSV info, and update/cache the data if needed
|
||||
updateMultiStateValueInfo(objInstance);
|
||||
|
||||
// check reliability first, if enabled
|
||||
if (m_checkReliability)
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_MULTI_STATE_VALUE,
|
||||
objInstance, PROP_RELIABILITY))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (reliability): "
|
||||
<< getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
BACNET_RELIABILITY reliable =
|
||||
static_cast<BACNET_RELIABILITY>(m_instance->getDataTypeEnum());
|
||||
|
||||
if (reliable != RELIABILITY_NO_FAULT_DETECTED)
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": Reliability check failed" << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": Reliability check failed");
|
||||
}
|
||||
}
|
||||
|
||||
// now get the value
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_MULTI_STATE_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": (value): " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeUnsignedInt();
|
||||
}
|
||||
|
||||
void BACNETUTIL::updateMultiStateValueInfo(uint32_t objInstance)
|
||||
{
|
||||
// bail if we already have information on this msv
|
||||
if (m_msvInfo.count(objInstance) != 0)
|
||||
return;
|
||||
|
||||
// we need to fetch information on MSV's - number of states, and
|
||||
// possibly the state-text, if present
|
||||
|
||||
// get the number of values possible (required)
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_MULTI_STATE_VALUE,
|
||||
objInstance, PROP_NUMBER_OF_STATES))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (number of states): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
|
||||
// Add the entry...
|
||||
m_msvInfo[objInstance].numStates = m_instance->getDataTypeUnsignedInt();
|
||||
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": number of states: "
|
||||
<< m_msvInfo[objInstance].numStates
|
||||
<< endl;
|
||||
|
||||
// now get the state-text. This is optional, so we will not throw
|
||||
// here.
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_MULTI_STATE_VALUE,
|
||||
objInstance, PROP_STATE_TEXT))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (state-text): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// store them
|
||||
int numElements = m_instance->getDataNumElements();
|
||||
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": numElements: " << numElements << endl;
|
||||
|
||||
if (numElements > 0)
|
||||
{
|
||||
for (int i=0; i<numElements; i++)
|
||||
{
|
||||
m_msvInfo[objInstance].stateList.push_back(m_instance->getDataTypeString(i));
|
||||
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << int(objInstance) << ", "
|
||||
<< i << ": "
|
||||
<< "added state text string: "
|
||||
<< m_msvInfo[objInstance].stateList.at(i)
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void BACNETUTIL::deleteMultiStateValueInfo(uint32_t objInstance)
|
||||
{
|
||||
// if there is no data stored for this objInstance yet, then we do
|
||||
// not need to do anything.
|
||||
if (m_msvInfo.count(objInstance) == 0)
|
||||
return;
|
||||
|
||||
// Now, we just erase the entry, and it will be updated the next
|
||||
// time the MSV is accessed.
|
||||
m_msvInfo.erase(objInstance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string BACNETUTIL::lookupMultiStateValueText(uint32_t objInstance,
|
||||
unsigned int value)
|
||||
{
|
||||
// verify that we have the relevant object data cached. If not, go
|
||||
// get it.
|
||||
updateMultiStateValueInfo(objInstance);
|
||||
|
||||
// verify that value is valid for this object
|
||||
if (value == 0 || value > m_msvInfo[objInstance].numStates)
|
||||
throw std::out_of_range(std::string(__FUNCTION__)
|
||||
+ ": value supplied is invalid. Maximum "
|
||||
+ "allowed values are 1 to "
|
||||
+ std::to_string(m_msvInfo[objInstance].numStates)
|
||||
+ " for this object");
|
||||
|
||||
|
||||
// at this point either it failed or suceeded. If it suceeded, then
|
||||
// we will see if any state text was retrieved. If no text is
|
||||
// available (it is an optional property), then we will simply
|
||||
// return the value itself as a string.
|
||||
|
||||
if (m_msvInfo[objInstance].stateList.size() > 0)
|
||||
{
|
||||
// we have state-text and a usable value.
|
||||
|
||||
// value should never be 0 at this point, so compensate for
|
||||
// indexing into stateList which is 0-based.
|
||||
value--;
|
||||
|
||||
return m_msvInfo[objInstance].stateList.at(value);
|
||||
}
|
||||
|
||||
// no stateList text available, so just return value as a string
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
unsigned int BACNETUTIL::getMultiStateValueMaxStates(uint32_t objInstance)
|
||||
{
|
||||
// check the MSV info, and update/cache the data if needed
|
||||
updateMultiStateValueInfo(objInstance);
|
||||
|
||||
return m_msvInfo[objInstance].numStates;
|
||||
}
|
||||
|
||||
string BACNETUTIL::getMultiStateValueText(uint32_t objInstance)
|
||||
{
|
||||
unsigned int value = getMultiStateValue(objInstance);
|
||||
|
||||
return lookupMultiStateValueText(objInstance, value);
|
||||
}
|
||||
|
||||
void BACNETUTIL::setMultiStateValue(uint32_t objInstance,
|
||||
unsigned int value)
|
||||
{
|
||||
// check the MSV info, and update/cache the data if needed
|
||||
updateMultiStateValueInfo(objInstance);
|
||||
|
||||
// Check value against the valid limits
|
||||
|
||||
if (value == 0 || value > m_msvInfo[objInstance].numStates)
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": value supplied is invalid. Maximum "
|
||||
+ "allowed values are 1 to "
|
||||
+ std::to_string(m_msvInfo[objInstance].numStates)
|
||||
+ " for this object");
|
||||
|
||||
// Write the value
|
||||
BACNET_APPLICATION_DATA_VALUE myData =
|
||||
m_instance->createDataUnsignedInt(value);
|
||||
|
||||
// write it
|
||||
if (m_instance->writeProperty(m_targetDeviceObjectID,
|
||||
OBJECT_MULTI_STATE_VALUE,
|
||||
objInstance, PROP_PRESENT_VALUE,
|
||||
&myData))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": "
|
||||
+ getAllErrorString());
|
||||
}
|
||||
}
|
||||
|
||||
void BACNETUTIL::updateBinaryValueInfo(uint32_t objInstance)
|
||||
{
|
||||
// bail if we already have information on this object
|
||||
if (m_bvInfo.count(objInstance) != 0)
|
||||
return;
|
||||
|
||||
// fetch inactive/active text. These are optional accordingto the
|
||||
// spec, so we will not throw if they do not exist.
|
||||
|
||||
// get inactive text
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_BINARY_VALUE,
|
||||
objInstance, PROP_INACTIVE_TEXT))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (inactive text): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
m_bvInfo[objInstance].inactiveText = "inactive";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bvInfo[objInstance].inactiveText = m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
// get active text
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_BINARY_VALUE,
|
||||
objInstance, PROP_ACTIVE_TEXT))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (active text): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
m_bvInfo[objInstance].activeText = "active";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bvInfo[objInstance].activeText = m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void BACNETUTIL::deleteBinaryValueInfo(uint32_t objInstance)
|
||||
{
|
||||
// if there is no data stored for this objInstance yet, then we do
|
||||
// not need to do anything.
|
||||
if (m_bvInfo.count(objInstance) == 0)
|
||||
return;
|
||||
|
||||
// Now, we just erase the entry, and it will be updated the next
|
||||
// time it is accessed.
|
||||
m_bvInfo.erase(objInstance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void BACNETUTIL::updateBinaryInputInfo(uint32_t objInstance)
|
||||
{
|
||||
// bail if we already have information on this object
|
||||
if (m_biInfo.count(objInstance) != 0)
|
||||
return;
|
||||
|
||||
// fetch inactive/active text. These are optional accordingto the
|
||||
// spec, so we will not throw if they do not exist.
|
||||
|
||||
// get inactive text
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_BINARY_INPUT,
|
||||
objInstance, PROP_INACTIVE_TEXT))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (inactive text): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
m_biInfo[objInstance].inactiveText = "inactive";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_biInfo[objInstance].inactiveText = m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
// get active text
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID,
|
||||
OBJECT_BINARY_INPUT,
|
||||
objInstance, PROP_ACTIVE_TEXT))
|
||||
{
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__
|
||||
<< ": (active text): "
|
||||
<< getAllErrorString()
|
||||
<< endl;
|
||||
|
||||
m_biInfo[objInstance].activeText = "active";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_biInfo[objInstance].activeText = m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void BACNETUTIL::deleteBinaryInputInfo(uint32_t objInstance)
|
||||
{
|
||||
// if there is no data stored for this objInstance yet, then we do
|
||||
// not need to do anything.
|
||||
if (m_biInfo.count(objInstance) == 0)
|
||||
return;
|
||||
|
||||
// Now, we just erase the entry, and it will be updated the next
|
||||
// time it is accessed.
|
||||
m_biInfo.erase(objInstance);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string BACNETUTIL::lookupBinaryInputText(uint32_t objInstance, bool value)
|
||||
{
|
||||
// cache relevant data if necessary
|
||||
updateBinaryInputInfo(objInstance);
|
||||
|
||||
if (value)
|
||||
return m_biInfo[objInstance].activeText;
|
||||
else
|
||||
return m_biInfo[objInstance].inactiveText;
|
||||
}
|
||||
|
||||
string BACNETUTIL::getBinaryInputText(uint32_t objInstance)
|
||||
{
|
||||
bool value = getBinaryInput(objInstance);
|
||||
|
||||
return lookupBinaryInputText(objInstance, value);
|
||||
}
|
||||
|
||||
string BACNETUTIL::lookupBinaryValueText(uint32_t objInstance, bool value)
|
||||
{
|
||||
// cache relevant data if necessary
|
||||
updateBinaryValueInfo(objInstance);
|
||||
|
||||
if (value)
|
||||
return m_bvInfo[objInstance].activeText;
|
||||
else
|
||||
return m_bvInfo[objInstance].inactiveText;
|
||||
}
|
||||
|
||||
string BACNETUTIL::getBinaryValueText(uint32_t objInstance)
|
||||
{
|
||||
bool value = getBinaryValue(objInstance);
|
||||
|
||||
return lookupBinaryValueText(objInstance, value);
|
||||
}
|
||||
|
||||
BACNETMSTP::BACERR_TYPE_T BACNETUTIL::getErrorType()
|
||||
{
|
||||
return m_instance->getErrorType();
|
||||
}
|
||||
|
||||
uint8_t BACNETUTIL::getRejectReason()
|
||||
{
|
||||
return m_instance->getRejectReason();
|
||||
}
|
||||
|
||||
std::string BACNETUTIL::getRejectString()
|
||||
{
|
||||
return m_instance->getRejectString();
|
||||
}
|
||||
|
||||
uint8_t BACNETUTIL::getAbortReason()
|
||||
{
|
||||
return m_instance->getAbortReason();
|
||||
}
|
||||
|
||||
std::string BACNETUTIL::getAbortString()
|
||||
{
|
||||
return m_instance->getAbortString();
|
||||
}
|
||||
|
||||
BACNET_ERROR_CLASS BACNETUTIL::getErrorClass()
|
||||
{
|
||||
return m_instance->getErrorClass();
|
||||
}
|
||||
|
||||
BACNET_ERROR_CODE BACNETUTIL::getErrorCode()
|
||||
{
|
||||
return m_instance->getErrorCode();
|
||||
}
|
||||
|
||||
std::string BACNETUTIL::getUPMErrorString()
|
||||
{
|
||||
return m_instance->getUPMErrorString();
|
||||
}
|
||||
|
||||
std::string BACNETUTIL::getErrorString()
|
||||
{
|
||||
return m_instance->getErrorString();
|
||||
};
|
||||
|
||||
string BACNETUTIL::getAllErrorString()
|
||||
{
|
||||
switch (m_instance->getErrorType())
|
||||
{
|
||||
case BACNETMSTP::BACERR_TYPE_NONE:
|
||||
return string("No Error");
|
||||
break;
|
||||
|
||||
case BACNETMSTP::BACERR_TYPE_REJECT:
|
||||
return string("Reject: ") + getRejectString();
|
||||
break;
|
||||
|
||||
case BACNETMSTP::BACERR_TYPE_ABORT:
|
||||
return string("Abort: ") + getAbortString();
|
||||
break;
|
||||
|
||||
case BACNETMSTP::BACERR_TYPE_ERROR:
|
||||
return string("Error: ") + getErrorString();
|
||||
break;
|
||||
|
||||
case BACNETMSTP::BACERR_TYPE_UPM:
|
||||
return string("UPM Error: ") + getUPMErrorString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string BACNETUTIL::getDeviceDescription()
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_DEVICE,
|
||||
m_targetDeviceObjectID, PROP_DESCRIPTION))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
string BACNETUTIL::getDeviceLocation()
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_DEVICE,
|
||||
m_targetDeviceObjectID, PROP_LOCATION))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
bool BACNETUTIL::setDeviceLocation(string location)
|
||||
{
|
||||
BACNET_APPLICATION_DATA_VALUE myLocation =
|
||||
m_instance->createDataString(location);
|
||||
|
||||
// write the Device Object Location
|
||||
if (m_instance->writeProperty(m_targetDeviceObjectID, OBJECT_DEVICE,
|
||||
m_targetDeviceObjectID, PROP_LOCATION,
|
||||
&myLocation))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string BACNETUTIL::getDeviceName()
|
||||
{
|
||||
if (m_instance->readProperty(m_targetDeviceObjectID, OBJECT_DEVICE,
|
||||
m_targetDeviceObjectID, PROP_OBJECT_NAME))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return m_instance->getDataTypeString();
|
||||
}
|
||||
|
||||
bool BACNETUTIL::setDeviceName(string name)
|
||||
{
|
||||
if (name.size() < 1)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": name must have at least one character");
|
||||
}
|
||||
|
||||
BACNET_APPLICATION_DATA_VALUE myName =
|
||||
m_instance->createDataString(name);
|
||||
|
||||
// write the Device Object Location
|
||||
if (m_instance->writeProperty(m_targetDeviceObjectID, OBJECT_DEVICE,
|
||||
m_targetDeviceObjectID, PROP_OBJECT_NAME,
|
||||
&myName))
|
||||
{
|
||||
// error occurred
|
||||
if (m_debugging)
|
||||
cerr << __FUNCTION__ << ": " << getAllErrorString() << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
559
src/bacnetmstp/bacnetutil.hpp
Normal file
559
src/bacnetmstp/bacnetutil.hpp
Normal file
@ -0,0 +1,559 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "bacnetmstp.hpp"
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @library bacnetmstp
|
||||
* @comname UPM Utility API for BACnet
|
||||
* @con uart
|
||||
*
|
||||
* @brief UPM Utility API for BACnet
|
||||
*
|
||||
* This class implements some common access functions that are
|
||||
* useful to any driver making use of the bacnetmstp driver.
|
||||
*
|
||||
* It provides some basic functionality for reading and writing a
|
||||
* proprty (with and without relability checking) as well as access
|
||||
* to error conditions. It is intended to be inherited by your
|
||||
* driver class.
|
||||
*/
|
||||
|
||||
class BACNETUTIL {
|
||||
public:
|
||||
|
||||
/**
|
||||
* BACNETUTIL constructor
|
||||
*
|
||||
*/
|
||||
BACNETUTIL(uint32_t targetDeviceObjectID);
|
||||
|
||||
/**
|
||||
* BACNETUTIL Destructor
|
||||
*/
|
||||
virtual ~BACNETUTIL();
|
||||
|
||||
/**
|
||||
* This function initializes the underlying BACNETMSTP Master
|
||||
* singleton in the event it has not already been initialized. If
|
||||
* the BACNETMSTP Master singleton has already been initialized,
|
||||
* then this call will be ignored.
|
||||
*
|
||||
* @param port The serial port that the RS-485 interface is
|
||||
* connected to.
|
||||
* @param baudRate The baudrate of the RS-485 interface. All
|
||||
* devices on a BACnet RS-485 bus must run at the same baudrate.
|
||||
* Valid values are 9600, 19200, 38400, 57600, 76800, and 115200.
|
||||
* @param deviceInstanceNumber This is the unique Device Object
|
||||
* Instance number that will be used for our BACnet Master in
|
||||
* order to communicate over the BACnet interface. This number
|
||||
* must be between 1-4194302 and must be unique on the BACnet
|
||||
* network.
|
||||
* @param macAddr This is the MAC address of our BACnet Master.
|
||||
* It must be unique on the BACnet segment, and must be between
|
||||
* 1-127.
|
||||
* @param maxMaster This specifies to our Master the maximum MAC
|
||||
* address used by any other Masters on the BACnet network. This
|
||||
* must be between 1-127, the default is 127. Do not change this
|
||||
* unless you know what you are doing or you could introduce
|
||||
* token passing errors on the BACnet network.
|
||||
* @param maxInfoFrames This number specifies the maximum number
|
||||
* of transmissions (like requests for data) our Master is allowed
|
||||
* to make before passing the token to the next Master. The
|
||||
* default is 1.
|
||||
*/
|
||||
virtual void initMaster(std::string port, int baudRate,
|
||||
int deviceInstanceNumber,
|
||||
int macAddr, int maxMaster=DEFAULT_MAX_MASTER,
|
||||
int maxInfoFrames=1);
|
||||
|
||||
/**
|
||||
* Enable some debugging output in this module as well as the
|
||||
* BACNETMSTP module. Debugging is disabled by default.
|
||||
*
|
||||
* @param enable true to enable, false to disable.
|
||||
*/
|
||||
virtual void setDebug(bool enable);
|
||||
|
||||
/**
|
||||
* Retrieve the Present_Value property of an Analog Value object.
|
||||
* If checkReliability() has been enabled, then the Reliability
|
||||
* property of the object will be retrieved first. If the
|
||||
* Reliability property is anything other than
|
||||
* RELIABILITY_NO_FAULT_DETECTED, then the method will throw.
|
||||
* Reliability checking is disabled by default for performance
|
||||
* reasons.
|
||||
*
|
||||
* @param objInstance The Analog Value Object instance.
|
||||
* @return The floating point value requested.
|
||||
*/
|
||||
virtual float getAnalogValue(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Set the Present_Value property of an Analog Value object. This
|
||||
* method will throw on an error.
|
||||
*
|
||||
* @param objInstance The Analog Value Object instance.
|
||||
* @param value The data value to write.
|
||||
*/
|
||||
virtual void setAnalogValue(uint32_t objInstance,
|
||||
float value);
|
||||
|
||||
/**
|
||||
* Retrieve the Present_Value property of an Analog Input object.
|
||||
* If checkReliability() has been enabled, then the Reliability
|
||||
* property of the object will be retrieved first. If the
|
||||
* Reliability property is anything other than
|
||||
* RELIABILITY_NO_FAULT_DETECTED, then the method will throw.
|
||||
* Reliability checking is disabled by default for performance
|
||||
* reasons.
|
||||
*
|
||||
* @param objInstance The Analog Input Object instance.
|
||||
* @return the floating point value requested.
|
||||
*/
|
||||
virtual float getAnalogInput(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Query an Analog Value object for the unit code, translate it
|
||||
* into a string and cache the result for future use. Return the
|
||||
* BACnet text for the Unit enumeration. Unit enumerations are
|
||||
* things like 'kilowatt-hours', 'volts', etc. For Objects which
|
||||
* do not have a Units property defined for them, or for which
|
||||
* Units has no meaning, 'no-units' will typically be returned and
|
||||
* cached for the object.
|
||||
*
|
||||
* @param objInstance The Analog Value Object instance.
|
||||
* @return A string representing the Object's Unit property.
|
||||
*/
|
||||
virtual std::string getAnalogValueUnits(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Query an Analog Input object for the unit code, translate it
|
||||
* into a string and cache the result for future use. Return the
|
||||
* BACnet text for the Unit enumeration. Unit enumerations are
|
||||
* things like 'kilowatt-hours', 'volts', etc. For Objects which
|
||||
* do not have a Units property defined for them, or for which
|
||||
* Units has no meaning, 'no-units' will typically be returned and
|
||||
* cached for the object.
|
||||
*
|
||||
* @param objInstance The Analog Input Object instance.
|
||||
* @return A string representing the Object's Unit property.
|
||||
*/
|
||||
virtual std::string getAnalogInputUnits(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Retrieve the Present_Value property of a Binary Input object.
|
||||
* If checkReliability() has been enabled, then the Reliability
|
||||
* property of the object will be retrieved first. If the
|
||||
* Reliability property is anything other than
|
||||
* RELIABILITY_NO_FAULT_DETECTED, then the method will throw.
|
||||
* Reliability checking is disabled by default for performance
|
||||
* reasons.
|
||||
*
|
||||
* @param objInstance The Object Instance number to query
|
||||
* @return the boolean point value requested
|
||||
*/
|
||||
virtual bool getBinaryInput(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Lookup (retrieve if necessary) the Inactive_Text and
|
||||
* Active_Text properties of a Binary Input object. These text
|
||||
* properties are optional and can provide a string representing a
|
||||
* given state (true/false) that can be more informational than
|
||||
* just the boolean value the object represents. This is useful
|
||||
* in applications that display this data to a user for example.
|
||||
* If this text is not present in the object (as it is not
|
||||
* required), then a string representation of the value will be
|
||||
* returned instead ("active" and "inactive").
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object
|
||||
* @param value The value you want to lookup the text
|
||||
* representation for.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string lookupBinaryInputText(uint32_t objInstance, bool value);
|
||||
|
||||
/**
|
||||
* Return a string representation of the Present_Value property of
|
||||
* a BinaryInput object. This method just calls getBinaryInput()
|
||||
* on the object, uses lookupBinaryInputText() to lookup the
|
||||
* corresponding text value, and returns the result.
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string getBinaryInputText(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Retrieve the Present_Value property of a Binary Value object.
|
||||
* If checkReliability() has been enabled, then the Reliability
|
||||
* property of the object will be retrieved first. If the
|
||||
* Reliability property is anything other than
|
||||
* RELIABILITY_NO_FAULT_DETECTED, then the method will throw.
|
||||
* Reliability checking is disabled by default for performance
|
||||
* reasons.
|
||||
*
|
||||
* @param objInstance The Object Instance number to query
|
||||
* @return the boolean point value requested
|
||||
*/
|
||||
virtual bool getBinaryValue(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Set the Present_Value property of a Binary Value object. This
|
||||
* method will throw on an error.
|
||||
*
|
||||
* @param objInstance The Analog Value Object instance.
|
||||
* @param value The data value to write
|
||||
*/
|
||||
virtual void setBinaryValue(uint32_t objInstance,
|
||||
bool value);
|
||||
|
||||
/**
|
||||
* Lookup (retrieve if necessary) the Inactive_Text and
|
||||
* Active_Text properties of a Binary Value object. These text
|
||||
* properties are optional and can provide a string representing a
|
||||
* given state (true/false) that can be more informational than
|
||||
* just the boolean value the object represents. This is useful
|
||||
* in applications that display this data to a user for example.
|
||||
* If this text is not present in the object (as it is not
|
||||
* required), then a string representation of the value will be
|
||||
* returned instead ("active" and "inactive").
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @param value The value you want to lookup the text
|
||||
* representation for.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string lookupBinaryValueText(uint32_t objInstance, bool value);
|
||||
|
||||
/**
|
||||
* Return a string representation of the Present_Value property of
|
||||
* a Binary Value object. This method just calls getBinaryValue()
|
||||
* on the object, uses lookupBinaryValueText() to lookup the
|
||||
* corresponding text value, and returns the result.
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string getBinaryValueText(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Retrieve the Present_Value property of a Multi State Value
|
||||
* object. If checkReliability() has been enabled, then the
|
||||
* Reliability property of the object will be retrieved first. If
|
||||
* the Reliability property is anything other than
|
||||
* RELIABILITY_NO_FAULT_DETECTED, then the method will throw.
|
||||
* Reliability checking is disabled by default for performance
|
||||
* reasons.
|
||||
*
|
||||
* @param objInstance The Object Instance number to query.
|
||||
* @return The Present_Value property of the object.
|
||||
*/
|
||||
virtual unsigned int getMultiStateValue(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Lookup (retrieve if necessary) the State_Text strings
|
||||
* corresponding to the supplied value of a MultiStateValue
|
||||
* object. State_Text is an optional property that can provide
|
||||
* strings representing a given state that can be more
|
||||
* informational than just the unsigned integer the object
|
||||
* represents. This is useful in applications that display this
|
||||
* data to a user for example. If this text is not present in the
|
||||
* object (as it is not required), then a string representation of
|
||||
* the integer value will be returned instead.
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @param value The value you want to lookup the text
|
||||
* representation for.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string lookupMultiStateValueText(uint32_t objInstance,
|
||||
unsigned int value);
|
||||
|
||||
/**
|
||||
* Return a string representation of the Present_Value property of
|
||||
* a MultiStateValue object. This method just calls
|
||||
* getMultiStateValue() on the object, uses
|
||||
* lookupMultiStateValueText() to lookup the corresponding
|
||||
* State_Text value, and returns the result.
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @return The string representing the value.
|
||||
*/
|
||||
virtual std::string getMultiStateValueText(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Return the maximum legal value of a Multi State Value Object.
|
||||
* The value represents the highest value the Present_Value
|
||||
* porperty of the object will allow.
|
||||
*
|
||||
* @param objInstance The Object Instance number of the object.
|
||||
* @return The highest Present_Value the object supports.
|
||||
*/
|
||||
virtual unsigned int getMultiStateValueMaxStates(uint32_t objInstance);
|
||||
|
||||
/**
|
||||
* Set the Present_Value property of a Multi State Value object.
|
||||
* The value provided must not be 0, and must not exceed the
|
||||
* object's Number_Of_States property. Use
|
||||
* getMultiStateValueMaxStates() to determine the maximum value
|
||||
* the object supports. This method will throw on an error.
|
||||
*
|
||||
* @param objInstance The MultiStateValue Object instance.
|
||||
* @param value The data value to write.
|
||||
*/
|
||||
virtual void setMultiStateValue(uint32_t objInstance,
|
||||
unsigned int value);
|
||||
|
||||
/**
|
||||
* Enable or disable reliability checking. When retrieving data,
|
||||
* the Present_Value property is returned. There is also an
|
||||
* optional property called Reliability that can be checked to
|
||||
* ensure that the Present_Value property is currently valid.
|
||||
*
|
||||
* Enabling Reliability Checking has the data retrieval functions
|
||||
* check for a RELIABILITY_NO_FAULT_DETECTED value for the
|
||||
* Reliability property before querying the Present_Value
|
||||
* property. If anything other than RELIABILITY_NO_FAULT_DETECTED
|
||||
* is set, then the method will throw.
|
||||
*
|
||||
* This checking is disabled by default since it will double the
|
||||
* number of queries needed to retrieve a given value. In
|
||||
* addition, since it is an optional property, calling it for an
|
||||
* object that does not support it will also throw. However, if
|
||||
* you need to ensure that the values returned are always
|
||||
* completely valid as determined by the device firmware, and the
|
||||
* objects you are querying support the reliability property, you
|
||||
* can enable this.
|
||||
*
|
||||
* @param enable true to check Reliability before returning a
|
||||
* value, false otherwise.
|
||||
*/
|
||||
virtual void checkReliability(bool enable)
|
||||
{
|
||||
m_checkReliability = enable;
|
||||
};
|
||||
|
||||
/**
|
||||
* Query the Device Object of the device and return it's
|
||||
* Description property. This typically contains information like
|
||||
* the Vendor, model and serial number of a device.
|
||||
*
|
||||
* @return A string containing the Device Object's Description property.
|
||||
*/
|
||||
virtual std::string getDeviceDescription();
|
||||
|
||||
/**
|
||||
* Query the Device Object of the device and return it's Location
|
||||
* property. This typically contains a string indication of a
|
||||
* customer specific value. Use setLocation() to change.
|
||||
*
|
||||
* @return A string containing the Device Object's Location property.
|
||||
*/
|
||||
virtual std::string getDeviceLocation();
|
||||
|
||||
/**
|
||||
* Set the Device Object's Location property. This must be a
|
||||
* string containing no more than 63 characters. Not all devices
|
||||
* allow setting the location.
|
||||
*
|
||||
* @param location The new location to set, if supported.
|
||||
* @return true if the operation succeeded, otherwise false.
|
||||
*/
|
||||
virtual bool setDeviceLocation(std::string location);
|
||||
|
||||
/**
|
||||
* Query the Device Object of the device and return it's Name
|
||||
* property. This should contain a unique string value. Use
|
||||
* setName() to change. Note, according to the spec, the Device
|
||||
* Object Name must be unique within a given BACnet network.
|
||||
*
|
||||
* @return A string containing the Object's Name property.
|
||||
*/
|
||||
virtual std::string getDeviceName();
|
||||
|
||||
/**
|
||||
* Set the Device Object's Name property. This must be a string
|
||||
* containing at least one character and no more than 63
|
||||
* characters. Note, according to the spec, the Device Object
|
||||
* Name must be unique within a given BACnet network.
|
||||
*
|
||||
* @param name The name to set.
|
||||
* @return true if the operation succeeded, false otherwise
|
||||
*/
|
||||
virtual bool setDeviceName(std::string name);
|
||||
|
||||
/**
|
||||
* This is a utility function that will return a string reporting
|
||||
* on the various types of errors that can occur in BACnet
|
||||
* operation.
|
||||
*
|
||||
* @return A string containing the last error message.
|
||||
*/
|
||||
virtual std::string getAllErrorString();
|
||||
|
||||
/**
|
||||
* Return an enumration of the last error type to occur. The
|
||||
* value returned will be one of the BACNETMSTP::BACERR_TYPE_T
|
||||
* values.
|
||||
*
|
||||
* @return The last error type to occur, one of the
|
||||
* BACNETMSTP::BACERR_TYPE_T values.
|
||||
*/
|
||||
virtual BACNETMSTP::BACERR_TYPE_T getErrorType();
|
||||
|
||||
/**
|
||||
* In the event of a BACnet Reject error, return the error code.
|
||||
*
|
||||
* @return The Reject error code.
|
||||
*/
|
||||
virtual uint8_t getRejectReason();
|
||||
|
||||
/**
|
||||
* In the event of a BACnet Reject error, return the error string.
|
||||
*
|
||||
* @return The Reject error string.
|
||||
*/
|
||||
virtual std::string getRejectString();
|
||||
|
||||
/**
|
||||
* In the event of a BACnet Abort error, return the Abort reason code.
|
||||
*
|
||||
* @return The Abort reason code.
|
||||
*/
|
||||
virtual uint8_t getAbortReason();
|
||||
|
||||
/**
|
||||
* In the event of a BACnet Abort error, return the Abort string.
|
||||
*
|
||||
* @return The Abort error string.
|
||||
*/
|
||||
virtual std::string getAbortString();
|
||||
|
||||
/**
|
||||
* In the event of a general BACnet error, return the BACnet error class.
|
||||
*
|
||||
* @return One of the BACNET_ERROR_CLASS error class codes
|
||||
*/
|
||||
virtual BACNET_ERROR_CLASS getErrorClass();
|
||||
|
||||
/**
|
||||
* In the event of a general BACnet error, return the BACnet error code.
|
||||
*
|
||||
* @return One of the BACNET_ERROR_CODE error codes
|
||||
*/
|
||||
virtual BACNET_ERROR_CODE getErrorCode();
|
||||
|
||||
/**
|
||||
* In the event of a general BACnet error, return the BACnet error
|
||||
* string.
|
||||
*
|
||||
* @return A string representing the BACnet error class and code.
|
||||
*/
|
||||
virtual std::string getErrorString();
|
||||
|
||||
/**
|
||||
* In the event of a non-BACnet UPM error, return a string
|
||||
* describing the error.
|
||||
*
|
||||
* @return A string representing the UPM error.
|
||||
*/
|
||||
virtual std::string getUPMErrorString();
|
||||
|
||||
protected:
|
||||
// update our stored info for an MSV
|
||||
virtual void updateMultiStateValueInfo(uint32_t objInstance);
|
||||
// delete our stored info for an MSV
|
||||
virtual void deleteMultiStateValueInfo(uint32_t objInstance);
|
||||
|
||||
// update our stored info for a BV
|
||||
virtual void updateBinaryValueInfo(uint32_t objInstance);
|
||||
// delete our stored info for a BV
|
||||
virtual void deleteBinaryValueInfo(uint32_t objInstance);
|
||||
|
||||
// update our stored info for a BI
|
||||
virtual void updateBinaryInputInfo(uint32_t objInstance);
|
||||
// delete our stored info for a BI
|
||||
virtual void deleteBinaryInputInfo(uint32_t objInstance);
|
||||
|
||||
// also enable mstp debugging in BACNETMSTP
|
||||
bool m_debugging;
|
||||
|
||||
// whether or not to verify reliability before reading a value.
|
||||
bool m_checkReliability;
|
||||
|
||||
// our target Device Object ID
|
||||
uint32_t m_targetDeviceObjectID;
|
||||
|
||||
// a copy of the BACNETMSTP singleton instance pointer
|
||||
BACNETMSTP* m_instance;
|
||||
|
||||
// are we initialized?
|
||||
bool m_initialized;
|
||||
|
||||
// storage for Binary Input and Binary Value Data. This will
|
||||
// generate SWIG warnings which can be ignored as we do not expose
|
||||
// this struct outside the class.
|
||||
typedef struct {
|
||||
std::string inactiveText;
|
||||
std::string activeText;
|
||||
} binaryData_t;
|
||||
|
||||
typedef std::map<uint32_t, binaryData_t> binaryInfo_t;
|
||||
|
||||
// storage for binary input/value information
|
||||
binaryInfo_t m_bvInfo;
|
||||
binaryInfo_t m_biInfo;
|
||||
|
||||
// storage for multi-state data. This will generate SWIG
|
||||
// warnings which can be ignored as we do not expose this struct
|
||||
// outside the class.
|
||||
typedef struct {
|
||||
unsigned int numStates;
|
||||
std::vector<std::string>stateList;
|
||||
} multiStateData_t;
|
||||
|
||||
// our information storage for MSV's
|
||||
typedef std::map<uint32_t, multiStateData_t> multiStateInfo_t;
|
||||
|
||||
multiStateInfo_t m_msvInfo;
|
||||
|
||||
// Unit cache for AV
|
||||
typedef std::map<uint32_t, std::string> avCacheMap_t;
|
||||
avCacheMap_t m_avUnitCache;
|
||||
|
||||
// Unit cache for AI
|
||||
typedef std::map<uint32_t, std::string> aiCacheMap_t;
|
||||
aiCacheMap_t m_aiUnitCache;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
%module javaupm_bacnetmstp
|
||||
%include "../upm.i"
|
||||
%include "typemaps.i"
|
||||
%include "cpointer.i"
|
||||
%include "arrays_java.i";
|
||||
%include "../java_buffer.i"
|
||||
%include "carrays_uint32_t.i"
|
||||
|
||||
%{
|
||||
#include "bacnetmstp.hpp"
|
||||
#include "bacnetutil.hpp"
|
||||
%}
|
||||
|
||||
%include "bacnetmstp.hpp"
|
||||
%include "bacnetutil.hpp"
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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));
|
||||
};
|
||||
|
@ -172,7 +172,7 @@ BMPX8X::getAltitude (float sealevelPressure) {
|
||||
|
||||
|
||||
int
|
||||
BMPX8X::getTemperatureCelcius() {
|
||||
BMPX8X::getTemperatureCelsius() {
|
||||
return static_cast<int>(getTemperature() + 0.5);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
5
src/bmx055/CMakeLists.txt
Normal file
5
src/bmx055/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "bmx055")
|
||||
set (libdescription "Bosch bmx055, bmi055, bma250e, bmc150, bmg160, bmm150")
|
||||
set (module_src ${libname}.cxx bma250e.cxx bmg160.cxx bmm150.cxx bmc150.cxx bmi055.cxx)
|
||||
set (module_hpp ${libname}.hpp bma250e.hpp bmg160.hpp bmm150.hpp bmc150.cxx bmi055.hpp)
|
||||
upm_module_init()
|
741
src/bmx055/bma250e.cxx
Normal file
741
src/bmx055/bma250e.cxx
Normal file
@ -0,0 +1,741 @@
|
||||
/*
|
||||
* 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 <stdexcept>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#include "bma250e.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
// conversion from celsius to fahrenheit
|
||||
|
||||
static float c2f(float c)
|
||||
{
|
||||
return (c * (9.0 / 5.0) + 32.0);
|
||||
}
|
||||
|
||||
BMA250E::BMA250E(int bus, int addr, int cs) :
|
||||
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
||||
{
|
||||
m_accX = 0;
|
||||
m_accY = 0;
|
||||
m_accZ = 0;
|
||||
m_accScale = 0;
|
||||
m_temperature = 0.0;
|
||||
|
||||
if (addr < 0)
|
||||
{
|
||||
m_addr = 0;
|
||||
m_isSPI = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_addr = uint8_t(addr);
|
||||
m_isSPI = false;
|
||||
}
|
||||
|
||||
if (m_isSPI)
|
||||
{
|
||||
m_spi = new mraa::Spi(bus);
|
||||
|
||||
// Only create cs context if we are actually using a valid pin.
|
||||
// A hardware controlled pin should specify cs as -1.
|
||||
if (cs >= 0)
|
||||
{
|
||||
m_gpioCS = new mraa::Gpio(cs);
|
||||
m_gpioCS->dir(mraa::DIR_OUT);
|
||||
}
|
||||
|
||||
m_spi->mode(mraa::SPI_MODE0);
|
||||
m_spi->frequency(5000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
m_i2c = new mraa::I2c(bus);
|
||||
|
||||
mraa::Result rv;
|
||||
if ((rv = m_i2c->address(m_addr)) != mraa::SUCCESS)
|
||||
{
|
||||
throw std::runtime_error(string(__FUNCTION__) +
|
||||
": I2c.address() failed");
|
||||
}
|
||||
}
|
||||
|
||||
// check the chip id
|
||||
|
||||
uint8_t chipID = getChipID();
|
||||
|
||||
m_useFIFO = false;
|
||||
|
||||
// check the various chips id's and set appropriate capabilities.
|
||||
// Bail if the chip id is unknown.
|
||||
switch (chipID)
|
||||
{
|
||||
case 0xf9: // standalone bma250e
|
||||
m_resolution = RESOLUTION_10BITS;
|
||||
m_fifoAvailable = true;
|
||||
|
||||
break;
|
||||
|
||||
case 0xfa: // bmx055, bmi055 variants, 12b resolution
|
||||
m_resolution = RESOLUTION_12BITS;
|
||||
m_fifoAvailable = true;
|
||||
|
||||
break;
|
||||
|
||||
case 0x03: // bmc050 variant, no FIFO, 12b resolution
|
||||
m_resolution = RESOLUTION_12BITS;
|
||||
m_fifoAvailable = false;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": invalid chip ID. Expected "
|
||||
+ "3, 249, or 250 "
|
||||
+ ", got "
|
||||
+ std::to_string(int(chipID)));
|
||||
}
|
||||
|
||||
// call init with default options
|
||||
init();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
setPowerMode(pwr);
|
||||
usleep(50000); // 50ms, in case we are waking up
|
||||
|
||||
// set our range and bandwidth
|
||||
setRange(range);
|
||||
setBandwidth(bw);
|
||||
|
||||
// make sure register shadowing is enabled
|
||||
enableRegisterShadowing(true);
|
||||
|
||||
// enable output filtering
|
||||
enableOutputFiltering(true);
|
||||
|
||||
// use the FIFO by default, if we have one
|
||||
fifoConfig(FIFO_MODE_BYPASS, FIFO_DATA_SEL_XYZ);
|
||||
enableFIFO(true);
|
||||
|
||||
// make sure low power mode LPM2 is enabled in case we go to low
|
||||
// power or suspend mode. LPM1 mode (the default) requires register
|
||||
// writes to be drastically slowed down when enabled, which we
|
||||
// cannot handle.
|
||||
setLowPowerMode2();
|
||||
|
||||
// settle
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
void BMA250E::update()
|
||||
{
|
||||
int bufLen = 7; // max, non-FIFO
|
||||
uint8_t startReg = REG_ACCD_X_LSB;
|
||||
|
||||
if (m_useFIFO)
|
||||
{
|
||||
bufLen = 6;
|
||||
startReg = REG_FIFO_DATA;
|
||||
}
|
||||
|
||||
uint8_t buf[bufLen];
|
||||
|
||||
if (readRegs(startReg, buf, bufLen) != bufLen)
|
||||
{
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": readRegs() failed to read "
|
||||
+ std::to_string(bufLen)
|
||||
+ " bytes");
|
||||
}
|
||||
|
||||
uint8_t mask, shift;
|
||||
float divisor;
|
||||
|
||||
switch (m_resolution)
|
||||
{
|
||||
case RESOLUTION_10BITS:
|
||||
mask = _ACCD10_LSB_MASK;
|
||||
shift = _ACCD10_LSB_SHIFT;
|
||||
divisor = 64.0;
|
||||
|
||||
break;
|
||||
|
||||
case RESOLUTION_12BITS:
|
||||
mask = _ACCD12_LSB_MASK;
|
||||
shift = _ACCD12_LSB_SHIFT;
|
||||
divisor = 16.0;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error(string(__FUNCTION__)
|
||||
+ ": internal error: invalid resolution "
|
||||
+ std::to_string(int(m_resolution)));
|
||||
}
|
||||
|
||||
int16_t val;
|
||||
|
||||
// x
|
||||
val = int16_t(buf[1] << 8 | (buf[0] & (mask << shift)));
|
||||
m_accX = float(val / divisor);
|
||||
|
||||
// y
|
||||
val = int16_t(buf[3] << 8 | (buf[2] & (mask << shift)));
|
||||
m_accY = float(val / divisor);
|
||||
|
||||
// z
|
||||
val = int16_t(buf[5] << 8 | (buf[4] & (mask << shift)));
|
||||
m_accZ = float(val / divisor);
|
||||
|
||||
// get the temperature...
|
||||
|
||||
uint8_t temp = 0;
|
||||
if (m_useFIFO)
|
||||
{
|
||||
// we have to read temperature separately...
|
||||
temp = readReg(REG_TEMP);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we've already got it
|
||||
temp = buf[6];
|
||||
}
|
||||
|
||||
// .5K/LSB, 23C center point
|
||||
m_temperature = (float(temp) / 2.0) + 23.0;
|
||||
}
|
||||
|
||||
void BMA250E::enableFIFO(bool useFIFO)
|
||||
{
|
||||
if (m_fifoAvailable)
|
||||
m_useFIFO = useFIFO;
|
||||
}
|
||||
|
||||
uint8_t BMA250E::readReg(uint8_t reg)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
uint8_t pkt[2] = {reg, 0};
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(pkt, pkt, 2))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer() failed");
|
||||
}
|
||||
csOff();
|
||||
|
||||
return pkt[1];
|
||||
}
|
||||
else
|
||||
return m_i2c->readReg(reg);
|
||||
}
|
||||
|
||||
int BMA250E::readRegs(uint8_t reg, uint8_t *buffer, int len)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
|
||||
uint8_t sbuf[len + 1];
|
||||
memset((char *)sbuf, 0, len + 1);
|
||||
sbuf[0] = reg;
|
||||
|
||||
// We need to do it this way for edison - ie: use a single
|
||||
// transfer rather than breaking it up into two like we used to.
|
||||
// This means a buffer copy is now required, but that's the way
|
||||
// it goes.
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(sbuf, sbuf, len + 1))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer(buf) failed");
|
||||
}
|
||||
csOff();
|
||||
|
||||
// now copy it into user buffer
|
||||
for (int i=0; i<len; i++)
|
||||
buffer[i] = sbuf[i + 1];
|
||||
|
||||
return len;
|
||||
}
|
||||
else
|
||||
return m_i2c->readBytesReg(reg, buffer, len);
|
||||
}
|
||||
|
||||
void BMA250E::writeReg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg &= 0x7f; // mask off 0x80 for writing
|
||||
uint8_t pkt[2] = {reg, val};
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(pkt, NULL, 2))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer() failed");
|
||||
}
|
||||
csOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_i2c->writeReg(reg, val) != mraa::SUCCESS)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": I2c.writeReg() failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BMA250E::csOn()
|
||||
{
|
||||
if (m_gpioCS)
|
||||
m_gpioCS->write(0);
|
||||
}
|
||||
|
||||
void BMA250E::csOff()
|
||||
{
|
||||
if (m_gpioCS)
|
||||
m_gpioCS->write(1);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getChipID()
|
||||
{
|
||||
return readReg(REG_CHIP_ID);
|
||||
}
|
||||
|
||||
void BMA250E::getAccelerometer(float *x, float *y, float *z)
|
||||
{
|
||||
if (x)
|
||||
*x = (m_accX * m_accScale) / 1000.0;
|
||||
|
||||
if (y)
|
||||
*y = (m_accY * m_accScale) / 1000.0;
|
||||
|
||||
if (z)
|
||||
*z = (m_accZ * m_accScale) / 1000.0;
|
||||
}
|
||||
|
||||
float *BMA250E::getAccelerometer()
|
||||
{
|
||||
static float v[3];
|
||||
|
||||
getAccelerometer(&v[0], &v[1], &v[2]);
|
||||
return v;
|
||||
}
|
||||
|
||||
float BMA250E::getTemperature(bool fahrenheit)
|
||||
{
|
||||
if (fahrenheit)
|
||||
return c2f(m_temperature);
|
||||
else
|
||||
return m_temperature;
|
||||
}
|
||||
|
||||
void BMA250E::reset()
|
||||
{
|
||||
writeReg(REG_SOFTRESET, BMA250E_RESET_BYTE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
void BMA250E::setRange(RANGE_T range)
|
||||
{
|
||||
switch (m_resolution)
|
||||
{
|
||||
case RESOLUTION_10BITS:
|
||||
switch(range)
|
||||
{
|
||||
case RANGE_2G:
|
||||
m_accScale = 3.91; // milli-gravities
|
||||
break;
|
||||
|
||||
case RANGE_4G:
|
||||
m_accScale = 7.81;
|
||||
break;
|
||||
|
||||
case RANGE_8G:
|
||||
m_accScale = 15.63;
|
||||
break;
|
||||
|
||||
case RANGE_16G:
|
||||
m_accScale = 31.25;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RESOLUTION_12BITS:
|
||||
switch(range)
|
||||
{
|
||||
case RANGE_2G:
|
||||
m_accScale = 0.98; // milli-gravities
|
||||
break;
|
||||
|
||||
case RANGE_4G:
|
||||
m_accScale = 1.95;
|
||||
break;
|
||||
|
||||
case RANGE_8G:
|
||||
m_accScale = 3.91;
|
||||
break;
|
||||
|
||||
case RANGE_16G:
|
||||
m_accScale = 7.81;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
writeReg(REG_PMU_RANGE, range);
|
||||
}
|
||||
|
||||
void BMA250E::setBandwidth(BW_T bw)
|
||||
{
|
||||
writeReg(REG_PMU_BW, bw);
|
||||
}
|
||||
|
||||
void BMA250E::setPowerMode(POWER_MODE_T power)
|
||||
{
|
||||
// mask off reserved bits
|
||||
uint8_t reg = readReg(REG_PMU_LPW) & ~_PMU_LPW_RESERVED_MASK;
|
||||
|
||||
reg &= ~(_PMU_LPW_POWER_MODE_MASK << _PMU_LPW_POWER_MODE_SHIFT);
|
||||
reg |= (power << _PMU_LPW_POWER_MODE_SHIFT);
|
||||
|
||||
writeReg(REG_PMU_LPW, power);
|
||||
}
|
||||
|
||||
void BMA250E::fifoSetWatermark(int wm)
|
||||
{
|
||||
// do nothing if we don't have a FIFO
|
||||
if (!m_fifoAvailable)
|
||||
return;
|
||||
|
||||
// mask off illegal values
|
||||
uint8_t reg = uint8_t(wm) & _FIFO_CONFIG_0_WATER_MARK_MASK;
|
||||
|
||||
writeReg(REG_FIFO_CONFIG_0, reg);
|
||||
}
|
||||
|
||||
void BMA250E::fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes)
|
||||
{
|
||||
// do nothing if we don't have a FIFO
|
||||
if (!m_fifoAvailable)
|
||||
return;
|
||||
|
||||
uint8_t reg = ( (mode << _FIFO_CONFIG_1_FIFO_MODE_SHIFT) |
|
||||
(axes << _FIFO_CONFIG_1_FIFO_DATA_SHIFT) );
|
||||
|
||||
writeReg(REG_FIFO_CONFIG_1, reg);
|
||||
}
|
||||
|
||||
void BMA250E::setSelfTest(bool sign, bool amp, SELFTTEST_AXIS_T axis)
|
||||
{
|
||||
uint8_t reg = (axis << _PMU_SELFTTEST_AXIS_SHIFT);
|
||||
|
||||
if (amp)
|
||||
reg |= PMU_SELFTTEST_AMP;
|
||||
|
||||
if (sign)
|
||||
reg |= PMU_SELFTTEST_SIGN;
|
||||
|
||||
writeReg(REG_PMU_SELFTEST, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptEnable0()
|
||||
{
|
||||
return readReg(REG_INT_EN_0) & ~_INT_EN_0_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptEnable0(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_0_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_0, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptEnable1()
|
||||
{
|
||||
return readReg(REG_INT_EN_1) & ~_INT_EN_1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptEnable1(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_1_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_1, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptEnable2()
|
||||
{
|
||||
return readReg(REG_INT_EN_2) & ~_INT_EN_2_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptEnable2(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_2_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_2, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptMap0()
|
||||
{
|
||||
return readReg(REG_INT_MAP_0);
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptMap0(uint8_t bits)
|
||||
{
|
||||
writeReg(REG_INT_MAP_0, bits);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptMap1()
|
||||
{
|
||||
return readReg(REG_INT_MAP_1) & ~_INT_MAP_1_INT1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptMap1(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_MAP_1_INT1_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_MAP_1, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptMap2()
|
||||
{
|
||||
return readReg(REG_INT_MAP_2);
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptMap2(uint8_t bits)
|
||||
{
|
||||
writeReg(REG_INT_MAP_2, bits);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptSrc()
|
||||
{
|
||||
return readReg(REG_INT_SRC) & ~_INT_SRC_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptSrc(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_SRC_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_SRC, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptOutputControl()
|
||||
{
|
||||
return readReg(REG_INT_OUT_CTRL) & ~_INT_OUT_CTRL_INT1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptOutputControl(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_OUT_CTRL_INT1_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_OUT_CTRL, reg);
|
||||
}
|
||||
|
||||
void BMA250E::clearInterruptLatches()
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg |= INT_RST_LATCH_RESET_INT;
|
||||
|
||||
writeReg(REG_INT_RST_LATCH, reg);
|
||||
}
|
||||
|
||||
BMA250E::RST_LATCH_T BMA250E::getInterruptLatchBehavior()
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg &= (_INT_RST_LATCH_MASK << _INT_RST_LATCH_SHIFT);
|
||||
|
||||
return static_cast<RST_LATCH_T>(reg);
|
||||
}
|
||||
|
||||
void BMA250E::setInterruptLatchBehavior(RST_LATCH_T latch)
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg &= ~(_INT_RST_LATCH_MASK << _INT_RST_LATCH_SHIFT);
|
||||
reg |= (latch << _INT_RST_LATCH_SHIFT);
|
||||
|
||||
writeReg(REG_INT_RST_LATCH, reg);
|
||||
}
|
||||
|
||||
void BMA250E::enableRegisterShadowing(bool shadow)
|
||||
{
|
||||
uint8_t reg = readReg(REG_ACC_HBW) & ~_ACC_HBW_RESERVED_BITS;
|
||||
|
||||
if (shadow)
|
||||
reg &= ~ACC_HBW_SHADOW_DIS;
|
||||
else
|
||||
reg |= ACC_HBW_SHADOW_DIS;
|
||||
|
||||
writeReg(REG_ACC_HBW, reg);
|
||||
}
|
||||
|
||||
void BMA250E::enableOutputFiltering(bool filter)
|
||||
{
|
||||
uint8_t reg = readReg(REG_ACC_HBW) & ~_ACC_HBW_RESERVED_BITS;
|
||||
|
||||
if (filter)
|
||||
reg &= ~ACC_HBW_DATA_HIGH_BW;
|
||||
else
|
||||
reg |= ACC_HBW_DATA_HIGH_BW;
|
||||
|
||||
writeReg(REG_ACC_HBW, reg);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptStatus0()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_0);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptStatus1()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_1) & ~_INT_STATUS_1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptStatus2()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_2);
|
||||
}
|
||||
|
||||
uint8_t BMA250E::getInterruptStatus3Bits()
|
||||
{
|
||||
// filter out the orientation bitfield..
|
||||
return readReg(REG_INT_STATUS_3) &
|
||||
~(_INT_STATUS_3_ORIENT_MASK << _INT_STATUS_3_ORIENT_SHIFT);
|
||||
}
|
||||
|
||||
BMA250E::ORIENT_T BMA250E::getInterruptStatus3Orientation()
|
||||
{
|
||||
// grab just the orientation bitfield
|
||||
uint8_t reg = readReg(REG_INT_STATUS_3) &
|
||||
(_INT_STATUS_3_ORIENT_MASK << _INT_STATUS_3_ORIENT_SHIFT);
|
||||
|
||||
reg >>= _INT_STATUS_3_ORIENT_SHIFT;
|
||||
|
||||
return static_cast<ORIENT_T>(reg);
|
||||
}
|
||||
|
||||
void BMA250E::setLowPowerMode2()
|
||||
{
|
||||
uint8_t reg = readReg(REG_PMU_LOW_POWER) & ~_LOW_POWER_RESERVED_BITS;
|
||||
|
||||
// we simply set the low power mode to 2. Low power mode 1 slows
|
||||
// down register write accesses, and we can't handle that. In the
|
||||
// words of the late Admiral Akbar: "We cannot handle firepower of
|
||||
// that magnitude!" :(
|
||||
|
||||
reg |= LOW_POWER_LOWPOWER_MODE;
|
||||
|
||||
writeReg(REG_PMU_LOW_POWER, reg);
|
||||
}
|
||||
|
||||
#if defined(SWIGJAVA) || (JAVACALLBACK)
|
||||
void BMA250E::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
|
||||
jobject runnable)
|
||||
{
|
||||
// delete any existing ISR and GPIO context
|
||||
uninstallISR(intr);
|
||||
|
||||
// create gpio context
|
||||
getPin(intr) = new mraa::Gpio(gpio);
|
||||
|
||||
getPin(intr)->dir(mraa::DIR_IN);
|
||||
getPin(intr)->isr(level, runnable);
|
||||
}
|
||||
#else
|
||||
void BMA250E::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
|
||||
void (*isr)(void *), void *arg)
|
||||
{
|
||||
// delete any existing ISR and GPIO context
|
||||
uninstallISR(intr);
|
||||
|
||||
// create gpio context
|
||||
getPin(intr) = new mraa::Gpio(gpio);
|
||||
|
||||
getPin(intr)->dir(mraa::DIR_IN);
|
||||
getPin(intr)->isr(level, isr, arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
void BMA250E::uninstallISR(INTERRUPT_PINS_T intr)
|
||||
{
|
||||
if (getPin(intr))
|
||||
{
|
||||
getPin(intr)->isrExit();
|
||||
delete getPin(intr);
|
||||
|
||||
getPin(intr) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mraa::Gpio*& BMA250E::getPin(INTERRUPT_PINS_T intr)
|
||||
{
|
||||
switch(intr)
|
||||
{
|
||||
case INTERRUPT_INT1:
|
||||
return m_gpioIntr1;
|
||||
break;
|
||||
|
||||
case INTERRUPT_INT2:
|
||||
return m_gpioIntr2;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::out_of_range(string(__FUNCTION__) +
|
||||
": Invalid interrupt enum passed");
|
||||
}
|
||||
}
|
1461
src/bmx055/bma250e.hpp
Normal file
1461
src/bmx055/bma250e.hpp
Normal file
File diff suppressed because it is too large
Load Diff
120
src/bmx055/bmc150.cxx
Normal file
120
src/bmx055/bmc150.cxx
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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 <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "bmc150.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
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
|
||||
// instantiate them
|
||||
|
||||
if (accelBus >= 0)
|
||||
m_accel = new BMA250E(accelBus, accelAddr, accelCS);
|
||||
|
||||
if (magBus >= 0)
|
||||
m_mag = new BMM150(magBus, magAddr, magCS);
|
||||
|
||||
// now initialize them...
|
||||
if (m_accel)
|
||||
m_accel->init();
|
||||
|
||||
if (m_mag)
|
||||
m_mag->init();
|
||||
}
|
||||
|
||||
BMC150::~BMC150()
|
||||
{
|
||||
if (m_accel)
|
||||
delete m_accel;
|
||||
|
||||
if (m_mag)
|
||||
delete m_mag;
|
||||
}
|
||||
|
||||
void BMC150::initAccelerometer(BMA250E::POWER_MODE_T pwr,
|
||||
BMA250E::RANGE_T range,
|
||||
BMA250E::BW_T bw)
|
||||
{
|
||||
if (m_accel)
|
||||
m_accel->init(pwr, range, bw);
|
||||
}
|
||||
|
||||
void BMC150::initMagnetometer(BMM150::USAGE_PRESETS_T usage)
|
||||
{
|
||||
if (m_mag)
|
||||
m_mag->init(usage);
|
||||
}
|
||||
|
||||
void BMC150::update()
|
||||
{
|
||||
if (m_accel)
|
||||
m_accel->update();
|
||||
|
||||
if (m_mag)
|
||||
m_mag->update();
|
||||
}
|
||||
|
||||
void BMC150::getAccelerometer(float *x, float *y, float *z)
|
||||
{
|
||||
if (m_accel)
|
||||
m_accel->getAccelerometer(x, y, z);
|
||||
}
|
||||
|
||||
float *BMC150::getAccelerometer()
|
||||
{
|
||||
if (m_accel)
|
||||
return m_accel->getAccelerometer();
|
||||
else
|
||||
{
|
||||
static float v[3] = {0.0f, 0.0f, 0.0f};
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
void BMC150::getMagnetometer(float *x, float *y, float *z)
|
||||
{
|
||||
if (m_mag)
|
||||
m_mag->getMagnetometer(x, y, z);
|
||||
}
|
||||
|
||||
float *BMC150::getMagnetometer()
|
||||
{
|
||||
if (m_mag)
|
||||
return m_mag->getMagnetometer();
|
||||
else
|
||||
{
|
||||
static float v[3] = {0.0f, 0.0f, 0.0f};
|
||||
return v;
|
||||
}
|
||||
}
|
196
src/bmx055/bmc150.hpp
Normal file
196
src/bmx055/bmc150.hpp
Normal file
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "bma250e.hpp"
|
||||
#include "bmm150.hpp"
|
||||
|
||||
#define BMC150_DEFAULT_BUS 0
|
||||
#define BMC150_DEFAULT_ACC_ADDR 0x10
|
||||
#define BMC150_DEFAULT_MAG_ADDR 0x12
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @library bmx055
|
||||
* @sensor bmc150
|
||||
* @comname BMC150 6-axis eCompass
|
||||
* @type accelerometer compass
|
||||
* @man mouser
|
||||
* @con i2c gpio spi
|
||||
* @web http://www.mouser.com/ProductDetail/Bosch-Sensortec/0330SB0156/?qs=sGAEpiMZZMsrChSOYEGTCd8nwjostN1SWavW0HYOOXw%3d
|
||||
*
|
||||
* @brief API for the BMC150 6-axis eCompass
|
||||
*
|
||||
*
|
||||
* The BMC150 is an integrated electronic compass solution for
|
||||
* consumer market applications. It comprises a 12bit leading edge
|
||||
* triaxial, low-g acceleration sensor and an ultra-low power, high
|
||||
* precision triaxial magnetic field sensor. It allows measurements
|
||||
* of acceleration and magnetic field in three perpendicular
|
||||
* axes. Performance and features of both sensing technologies are
|
||||
* carefully tuned and perfectly match the demanding requirements of
|
||||
* all 6-axis mobile applications such as electronic compass,
|
||||
* navigation or augmented reality.
|
||||
|
||||
* The BMC150 is essentially 2 separate devices in one: the BMA250E
|
||||
* Accelerometer and the BMM150 Magnetometer. They are completely
|
||||
* independant of each other.
|
||||
*
|
||||
* This driver provides a very simple interface to these 2 devices.
|
||||
* If finer control is desired, you should just use the separate
|
||||
* BMA25E and BMM150 device classes directly. This driver simply
|
||||
* initializes both devices, and provides a mechanism to read
|
||||
* accelerometer and magnetometer data from them.
|
||||
*
|
||||
* @snippet bmc150.cxx Interesting
|
||||
*/
|
||||
|
||||
class BMC150 {
|
||||
public:
|
||||
/**
|
||||
* BMC150 constructor.
|
||||
*
|
||||
* This device can support both I2C and SPI. For SPI, set the addr
|
||||
* to -1, and specify a positive integer representing the Chip
|
||||
* Select (CS) pin for the cs argument. If you are using a
|
||||
* hardware CS pin (like edison with arduino breakout), then you
|
||||
* can connect the proper pin to the hardware CS pin on your MCU
|
||||
* and supply -1 for cs. The default operating mode is I2C.
|
||||
*
|
||||
* @param accelBus I2C or SPI bus to use. -1 to skip initializing
|
||||
* this device.
|
||||
* @param accelAddr The address for this device. -1 for SPI.
|
||||
* @param accelCS The gpio pin to use for the SPI Chip Select. -1 for
|
||||
* I2C or for SPI with a hardware controlled pin.
|
||||
* @param magBus I2C or SPI bus to use. -1 to skip initializing
|
||||
* this device.
|
||||
* @param magAddr The address for this device. -1 for SPI.
|
||||
* @param magCS The gpio pin to use for the SPI Chip Select. -1 for
|
||||
* I2C or for SPI with a hardware controlled pin.
|
||||
*/
|
||||
BMC150(int accelBus=BMC150_DEFAULT_BUS,
|
||||
int accelAddr=BMC150_DEFAULT_ACC_ADDR,
|
||||
int accelCS=-1,
|
||||
int magBus=BMC150_DEFAULT_BUS,
|
||||
int magAddr=BMC150_DEFAULT_MAG_ADDR,
|
||||
int magCS=-1);
|
||||
|
||||
/**
|
||||
* BMC150 Destructor.
|
||||
*/
|
||||
~BMC150();
|
||||
|
||||
/**
|
||||
* Update the internal stored values from sensor data.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Initialize the accelerometer and start operation. This
|
||||
* function is called from the constructor so will not typically
|
||||
* need to be called by a user unless the device is reset or you
|
||||
* want to change these values.
|
||||
*
|
||||
* @param pwr One of the BMA250E::POWER_MODE_T values. The default is
|
||||
* BMA250E::POWER_MODE_NORMAL.
|
||||
* @param range One of the BMA250E::RANGE_T values. The default is
|
||||
* BMA250E::RANGE_2G.
|
||||
* @param bw One of the filtering BMA250E::BW_T values. The default is
|
||||
* BMA250E::BW_250.
|
||||
*/
|
||||
void initAccelerometer(BMA250E::POWER_MODE_T pwr=BMA250E::POWER_MODE_NORMAL,
|
||||
BMA250E::RANGE_T range=BMA250E::RANGE_2G,
|
||||
BMA250E::BW_T bw=BMA250E::BW_250);
|
||||
|
||||
/**
|
||||
* Initialize the magnetometer and start operation. This function
|
||||
* is called from the constructor so will not typically need to be
|
||||
* called by a user unless the device is reset or you want to
|
||||
* change these values. This method will call
|
||||
* BMM150::setPresetMode() with the passed parameter.
|
||||
*
|
||||
* @param usage One of the BMM150::USAGE_PRESETS_T values. The default is
|
||||
* BMM150::USAGE_HIGH_ACCURACY.
|
||||
*/
|
||||
void initMagnetometer(BMM150::USAGE_PRESETS_T usage=BMM150::USAGE_HIGH_ACCURACY);
|
||||
|
||||
/**
|
||||
* Return accelerometer data in gravities. update() must have
|
||||
* been called prior to calling this method.
|
||||
*
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it.
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it.
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it.
|
||||
*/
|
||||
void getAccelerometer(float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* Return accelerometer data in gravities in the form of a
|
||||
* floating point array. The pointer returned by this function is
|
||||
* statically allocated and will be rewritten on each call.
|
||||
* update() must have been called prior to calling this method.
|
||||
*
|
||||
* @return A floating point array containing x, y, and z in
|
||||
* that order.
|
||||
*/
|
||||
float *getAccelerometer();
|
||||
|
||||
/**
|
||||
* Return magnetometer data in micro-Teslas (uT). update() must
|
||||
* have been called prior to calling this method.
|
||||
*
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it.
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it.
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it.
|
||||
*/
|
||||
void getMagnetometer(float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* Return magnetometer data in micro-Teslas (uT) in the form of a
|
||||
* floating point array. The pointer returned by this function is
|
||||
* statically allocated and will be rewritten on each call.
|
||||
* update() must have been called prior to calling this method.
|
||||
*
|
||||
* @return A floating point array containing x, y, and z in
|
||||
* that order.
|
||||
*/
|
||||
float *getMagnetometer();
|
||||
|
||||
|
||||
protected:
|
||||
BMA250E *m_accel;
|
||||
BMM150 *m_mag;
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
587
src/bmx055/bmg160.cxx
Normal file
587
src/bmx055/bmg160.cxx
Normal file
@ -0,0 +1,587 @@
|
||||
/*
|
||||
* 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 <stdexcept>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#include "bmg160.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
#define BMG160_DEFAULT_CHIPID 0x0f
|
||||
|
||||
// conversion from celsius to fahrenheit
|
||||
|
||||
static float c2f(float c)
|
||||
{
|
||||
return (c * (9.0 / 5.0) + 32.0);
|
||||
}
|
||||
|
||||
BMG160::BMG160(int bus, int addr, int cs) :
|
||||
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
||||
{
|
||||
m_gyrX = 0;
|
||||
m_gyrY = 0;
|
||||
m_gyrZ = 0;
|
||||
m_gyrScale = 0;
|
||||
m_temperature = 0.0;
|
||||
|
||||
if (addr < 0)
|
||||
{
|
||||
m_addr = 0;
|
||||
m_isSPI = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_addr = uint8_t(addr);
|
||||
m_isSPI = false;
|
||||
}
|
||||
|
||||
if (m_isSPI)
|
||||
{
|
||||
m_spi = new mraa::Spi(bus);
|
||||
|
||||
// Only create cs context if we are actually using a valid pin.
|
||||
// A hardware controlled pin should specify cs as -1.
|
||||
if (cs >= 0)
|
||||
{
|
||||
m_gpioCS = new mraa::Gpio(cs);
|
||||
m_gpioCS->dir(mraa::DIR_OUT);
|
||||
}
|
||||
|
||||
m_spi->mode(mraa::SPI_MODE0);
|
||||
m_spi->frequency(5000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
m_i2c = new mraa::I2c(bus);
|
||||
|
||||
mraa::Result rv;
|
||||
if ((rv = m_i2c->address(m_addr)) != mraa::SUCCESS)
|
||||
{
|
||||
throw std::runtime_error(string(__FUNCTION__) +
|
||||
": I2c.address() failed");
|
||||
}
|
||||
}
|
||||
|
||||
// check the chip id
|
||||
|
||||
uint8_t chipID = getChipID();
|
||||
if (chipID != BMG160_DEFAULT_CHIPID)
|
||||
{
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": invalid chip ID. Expected "
|
||||
+ std::to_string(int(BMG160_DEFAULT_CHIPID))
|
||||
+ ", got "
|
||||
+ std::to_string(int(chipID)));
|
||||
}
|
||||
|
||||
// call init with default options
|
||||
init();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
setPowerMode(pwr);
|
||||
usleep(50000); // 50ms, in case we are waking up
|
||||
|
||||
// set our range and bandwidth
|
||||
setRange(range);
|
||||
setBandwidth(bw);
|
||||
|
||||
// make sure register shadowing is enabled
|
||||
enableRegisterShadowing(true);
|
||||
|
||||
// enable output filtering
|
||||
enableOutputFiltering(true);
|
||||
|
||||
// use the FIFO by default
|
||||
fifoConfig(FIFO_MODE_BYPASS, FIFO_DATA_SEL_XYZ);
|
||||
enableFIFO(true);
|
||||
|
||||
// settle
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
void BMG160::update()
|
||||
{
|
||||
int bufLen = 7; // max, non-FIFO
|
||||
uint8_t startReg = REG_RATE_X_LSB;
|
||||
|
||||
if (m_useFIFO)
|
||||
{
|
||||
bufLen = 6;
|
||||
startReg = REG_FIFO_DATA;
|
||||
}
|
||||
|
||||
uint8_t buf[bufLen];
|
||||
|
||||
if (readRegs(startReg, buf, bufLen) != bufLen)
|
||||
{
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": readRegs() failed to read "
|
||||
+ std::to_string(bufLen)
|
||||
+ " bytes");
|
||||
}
|
||||
|
||||
int16_t val;
|
||||
|
||||
// x
|
||||
val = int16_t(buf[1] << 8 | buf[0]);
|
||||
m_gyrX = float(val);
|
||||
|
||||
// y
|
||||
val = int16_t(buf[3] << 8 | buf[2]);
|
||||
m_gyrY = float(val);
|
||||
|
||||
// z
|
||||
val = int16_t(buf[5] << 8 | buf[4]);
|
||||
m_gyrZ = float(val);
|
||||
|
||||
// get the temperature...
|
||||
|
||||
uint8_t temp = 0;
|
||||
if (m_useFIFO)
|
||||
{
|
||||
// we have to read temperature separately...
|
||||
temp = readReg(REG_TEMP);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we already got it
|
||||
temp = buf[6];
|
||||
}
|
||||
|
||||
// .5K/LSB, 23C center point
|
||||
m_temperature = (float(temp) / 2.0) + 23.0;
|
||||
}
|
||||
|
||||
void BMG160::enableFIFO(bool useFIFO)
|
||||
{
|
||||
m_useFIFO = useFIFO;
|
||||
}
|
||||
|
||||
uint8_t BMG160::readReg(uint8_t reg)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
uint8_t pkt[2] = {reg, 0};
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(pkt, pkt, 2))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer() failed");
|
||||
}
|
||||
csOff();
|
||||
|
||||
return pkt[1];
|
||||
}
|
||||
else
|
||||
return m_i2c->readReg(reg);
|
||||
}
|
||||
|
||||
int BMG160::readRegs(uint8_t reg, uint8_t *buffer, int len)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
|
||||
uint8_t sbuf[len + 1];
|
||||
memset((char *)sbuf, 0, len + 1);
|
||||
sbuf[0] = reg;
|
||||
|
||||
// We need to do it this way for edison - ie: use a single
|
||||
// transfer rather than breaking it up into two like we used to.
|
||||
// This means a buffer copy is now required, but that's the way
|
||||
// it goes.
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(sbuf, sbuf, len + 1))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer(buf) failed");
|
||||
}
|
||||
csOff();
|
||||
|
||||
// now copy it into user buffer
|
||||
for (int i=0; i<len; i++)
|
||||
buffer[i] = sbuf[i + 1];
|
||||
|
||||
return len;
|
||||
}
|
||||
else
|
||||
return m_i2c->readBytesReg(reg, buffer, len);
|
||||
}
|
||||
|
||||
void BMG160::writeReg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
if (m_isSPI)
|
||||
{
|
||||
reg &= 0x7f; // mask off 0x80 for writing
|
||||
uint8_t pkt[2] = {reg, val};
|
||||
|
||||
csOn();
|
||||
if (m_spi->transfer(pkt, NULL, 2))
|
||||
{
|
||||
csOff();
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": Spi.transfer() failed");
|
||||
}
|
||||
csOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
mraa::Result rv;
|
||||
if ((rv = m_i2c->writeReg(reg, val)) != mraa::SUCCESS)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__)
|
||||
+ ": I2c.writeReg() failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BMG160::csOn()
|
||||
{
|
||||
if (m_gpioCS)
|
||||
m_gpioCS->write(0);
|
||||
}
|
||||
|
||||
void BMG160::csOff()
|
||||
{
|
||||
if (m_gpioCS)
|
||||
m_gpioCS->write(1);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getChipID()
|
||||
{
|
||||
return readReg(REG_CHIP_ID);
|
||||
}
|
||||
|
||||
void BMG160::getGyroscope(float *x, float *y, float *z)
|
||||
{
|
||||
if (x)
|
||||
*x = (m_gyrX * m_gyrScale) / 1000.0;
|
||||
|
||||
if (y)
|
||||
*y = (m_gyrY * m_gyrScale) / 1000.0;
|
||||
|
||||
if (z)
|
||||
*z = (m_gyrZ * m_gyrScale) / 1000.0;
|
||||
}
|
||||
|
||||
float *BMG160::getGyroscope()
|
||||
{
|
||||
static float v[3];
|
||||
|
||||
getGyroscope(&v[0], &v[1], &v[2]);
|
||||
return v;
|
||||
}
|
||||
|
||||
float BMG160::getTemperature(bool fahrenheit)
|
||||
{
|
||||
if (fahrenheit)
|
||||
return c2f(m_temperature);
|
||||
else
|
||||
return m_temperature;
|
||||
}
|
||||
|
||||
void BMG160::reset()
|
||||
{
|
||||
writeReg(REG_SOFTRESET, BMG160_RESET_BYTE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
void BMG160::setRange(RANGE_T range)
|
||||
{
|
||||
switch(range)
|
||||
{
|
||||
case RANGE_125:
|
||||
m_gyrScale = 3.8; // milli-degrees
|
||||
break;
|
||||
|
||||
case RANGE_250:
|
||||
m_gyrScale = 7.6;
|
||||
break;
|
||||
|
||||
case RANGE_500:
|
||||
m_gyrScale = 15.3;
|
||||
break;
|
||||
|
||||
case RANGE_1000:
|
||||
m_gyrScale = 30.5;
|
||||
break;
|
||||
|
||||
case RANGE_2000:
|
||||
m_gyrScale = 61.0;
|
||||
break;
|
||||
}
|
||||
|
||||
// we also have to write a fixed '0x10' to the high-order bits for
|
||||
// some reason (according to datasheet)
|
||||
uint8_t reg = range | (_GYR_RANGE_FIXED_VALUE << _GYR_RANGE_FIXED_SHIFT);
|
||||
writeReg(REG_GYR_RANGE, reg);
|
||||
}
|
||||
|
||||
void BMG160::setBandwidth(BW_T bw)
|
||||
{
|
||||
writeReg(REG_GYR_BW, bw);
|
||||
}
|
||||
|
||||
void BMG160::setPowerMode(POWER_MODE_T power)
|
||||
{
|
||||
// mask off reserved bits
|
||||
uint8_t reg = readReg(REG_LPM1) & ~_LPM1_RESERVED_MASK;
|
||||
|
||||
reg &= ~(_LPM1_POWER_MODE_MASK << _LPM1_POWER_MODE_SHIFT);
|
||||
reg |= (power << _LPM1_POWER_MODE_SHIFT);
|
||||
|
||||
writeReg(REG_LPM1, power);
|
||||
}
|
||||
|
||||
void BMG160::fifoSetWatermark(int wm)
|
||||
{
|
||||
// mask off illegal values
|
||||
uint8_t reg = uint8_t(wm) & _FIFO_CONFIG_0_WATER_MARK_MASK;
|
||||
|
||||
writeReg(REG_FIFO_CONFIG_0, reg);
|
||||
}
|
||||
|
||||
void BMG160::fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes)
|
||||
{
|
||||
uint8_t reg = ( (mode << _FIFO_CONFIG_1_FIFO_MODE_SHIFT) |
|
||||
(axes << _FIFO_CONFIG_1_FIFO_DATA_SHIFT) );
|
||||
|
||||
writeReg(REG_FIFO_CONFIG_1, reg);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptEnable0()
|
||||
{
|
||||
return readReg(REG_INT_EN_0) & ~_INT_EN_0_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMG160::setInterruptEnable0(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_0_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_0, reg);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptMap0()
|
||||
{
|
||||
return readReg(REG_INT_MAP_0) & ~_INT_MAP_0_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMG160::setInterruptMap0(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_MAP_0_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_MAP_0, reg);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptMap1()
|
||||
{
|
||||
return readReg(REG_INT_MAP_1);
|
||||
}
|
||||
|
||||
void BMG160::setInterruptMap1(uint8_t bits)
|
||||
{
|
||||
writeReg(REG_INT_MAP_1, bits);
|
||||
}
|
||||
|
||||
// REG_INT_EN1, for some strange reason
|
||||
uint8_t BMG160::getInterruptSrc()
|
||||
{
|
||||
return readReg(REG_INT_EN_1) & ~_INT_EN_1_INT1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMG160::setInterruptSrc(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_1_INT1_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_1, reg);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptOutputControl()
|
||||
{
|
||||
return readReg(REG_INT_EN_1) & ~_INT_EN_1_INT1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
void BMG160::setInterruptOutputControl(uint8_t bits)
|
||||
{
|
||||
uint8_t reg = bits & ~_INT_EN_1_INT1_RESERVED_BITS;
|
||||
|
||||
writeReg(REG_INT_EN_1, reg);
|
||||
}
|
||||
|
||||
void BMG160::clearInterruptLatches()
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg |= INT_RST_LATCH_RESET_INT;
|
||||
|
||||
writeReg(REG_INT_RST_LATCH, reg);
|
||||
}
|
||||
|
||||
BMG160::RST_LATCH_T BMG160::getInterruptLatchBehavior()
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg &= (_INT_RST_LATCH_MASK << _INT_RST_LATCH_SHIFT);
|
||||
|
||||
return static_cast<RST_LATCH_T>(reg);
|
||||
}
|
||||
|
||||
void BMG160::setInterruptLatchBehavior(RST_LATCH_T latch)
|
||||
{
|
||||
uint8_t reg = readReg(REG_INT_RST_LATCH) & ~_INT_RST_LATCH_RESERVED_BITS;
|
||||
|
||||
reg &= ~(_INT_RST_LATCH_MASK << _INT_RST_LATCH_SHIFT);
|
||||
reg |= (latch << _INT_RST_LATCH_SHIFT);
|
||||
|
||||
writeReg(REG_INT_RST_LATCH, reg);
|
||||
}
|
||||
|
||||
void BMG160::enableRegisterShadowing(bool shadow)
|
||||
{
|
||||
uint8_t reg = readReg(REG_RATE_HBW) & ~_RATE_HBW_RESERVED_BITS;
|
||||
|
||||
if (shadow)
|
||||
reg &= ~RATE_HBW_SHADOW_DIS;
|
||||
else
|
||||
reg |= RATE_HBW_SHADOW_DIS;
|
||||
|
||||
writeReg(REG_RATE_HBW, reg);
|
||||
}
|
||||
|
||||
void BMG160::enableOutputFiltering(bool filter)
|
||||
{
|
||||
uint8_t reg = readReg(REG_RATE_HBW) & ~_RATE_HBW_RESERVED_BITS;
|
||||
|
||||
if (filter)
|
||||
reg &= ~RATE_HBW_DATA_HIGH_BW;
|
||||
else
|
||||
reg |= RATE_HBW_DATA_HIGH_BW;
|
||||
|
||||
writeReg(REG_RATE_HBW, reg);
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptStatus0()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_0) & ~_INT_STATUS_0_RESERVED_BITS;
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptStatus1()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_1) & ~_INT_STATUS_1_RESERVED_BITS;
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptStatus2()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_2) & ~_INT_STATUS_2_RESERVED_BITS;
|
||||
}
|
||||
|
||||
uint8_t BMG160::getInterruptStatus3()
|
||||
{
|
||||
return readReg(REG_INT_STATUS_3) & ~_INT_STATUS_3_RESERVED_BITS;
|
||||
}
|
||||
|
||||
#if defined(SWIGJAVA) || (JAVACALLBACK)
|
||||
void BMG160::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
|
||||
jobject runnable)
|
||||
{
|
||||
// delete any existing ISR and GPIO context
|
||||
uninstallISR(intr);
|
||||
|
||||
// create gpio context
|
||||
getPin(intr) = new mraa::Gpio(gpio);
|
||||
|
||||
getPin(intr)->dir(mraa::DIR_IN);
|
||||
getPin(intr)->isr(level, runnable);
|
||||
}
|
||||
#else
|
||||
void BMG160::installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
|
||||
void (*isr)(void *), void *arg)
|
||||
{
|
||||
// delete any existing ISR and GPIO context
|
||||
uninstallISR(intr);
|
||||
|
||||
// create gpio context
|
||||
getPin(intr) = new mraa::Gpio(gpio);
|
||||
|
||||
getPin(intr)->dir(mraa::DIR_IN);
|
||||
getPin(intr)->isr(level, isr, arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
void BMG160::uninstallISR(INTERRUPT_PINS_T intr)
|
||||
{
|
||||
if (getPin(intr))
|
||||
{
|
||||
getPin(intr)->isrExit();
|
||||
delete getPin(intr);
|
||||
|
||||
getPin(intr) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mraa::Gpio*& BMG160::getPin(INTERRUPT_PINS_T intr)
|
||||
{
|
||||
switch(intr)
|
||||
{
|
||||
case INTERRUPT_INT1:
|
||||
return m_gpioIntr1;
|
||||
break;
|
||||
|
||||
case INTERRUPT_INT2:
|
||||
return m_gpioIntr2;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::out_of_range(string(__FUNCTION__) +
|
||||
": Invalid interrupt enum passed");
|
||||
}
|
||||
}
|
1223
src/bmx055/bmg160.hpp
Normal file
1223
src/bmx055/bmg160.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user