mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 12:21:11 +03:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
4faa71d239 | |||
5265bada9c | |||
84067826eb | |||
98e3621c93 | |||
d79799bab9 | |||
49e04593d8 | |||
bda66a3d06 | |||
84a77730be | |||
b08fc8d48d | |||
e64f192fb7 | |||
40fe6654eb | |||
e740335701 | |||
b257d91702 | |||
e7394217b1 | |||
baec9966f0 | |||
0fb56356fb | |||
e0ef6eea64 | |||
743730550c | |||
9ab9e2c403 | |||
8da6095c35 |
@ -17,9 +17,9 @@ compiler:
|
|||||||
- clang
|
- clang
|
||||||
- gcc
|
- gcc
|
||||||
install:
|
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 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 ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
- sudo update-java-alternatives -s java-8-oracle
|
||||||
before_script:
|
before_script:
|
||||||
|
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
|
|||||||
git_describe (VERSION "--tags")
|
git_describe (VERSION "--tags")
|
||||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||||
message (WARNING " - Install git to compile a production UPM!")
|
message (WARNING " - Install git to compile a production UPM!")
|
||||||
set (VERSION "v0.7.2-dirty")
|
set (VERSION "v0.7.3-dirty")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message (INFO " - UPM Version ${VERSION}")
|
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 "")
|
set (CMAKE_SWIG_FLAGS "")
|
||||||
|
|
||||||
option (BUILDDOC "Build all doc." OFF)
|
option (BUILDDOC "Build all doc." OFF)
|
||||||
option (BUILDSWIG "Build swig modules." ON)
|
|
||||||
option (BUILDSWIGPYTHON "Build swig python 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 (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 (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
|
||||||
option (IPK "Generate IPK using CPack" OFF)
|
option (IPK "Generate IPK using CPack" OFF)
|
||||||
option (RPM "Generate RPM using CPack" OFF)
|
option (RPM "Generate RPM using CPack" OFF)
|
||||||
option (BUILDTESTS "Generate check-ups for upm" ON)
|
option (BUILDTESTS "Generate check-ups for upm" ON)
|
||||||
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
||||||
|
|
||||||
# Find swig
|
# Find swig
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
||||||
if (BUILDSWIGNODE)
|
if (BUILDSWIGNODE)
|
||||||
find_package (SWIG 3.0.5 REQUIRED)
|
find_package (SWIG 3.0.5 REQUIRED)
|
||||||
else ()
|
else ()
|
||||||
@ -125,7 +124,7 @@ if (BUILDDOC)
|
|||||||
endif (DOXYGEN_FOUND)
|
endif (DOXYGEN_FOUND)
|
||||||
# Check if Sphinx is installed and add target to generate API documentation
|
# Check if Sphinx is installed and add target to generate API documentation
|
||||||
find_package (Sphinx)
|
find_package (Sphinx)
|
||||||
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
if(SPHINX_FOUND AND BUILDSWIGPYTHON)
|
||||||
# Python required for Sphinx build
|
# Python required for Sphinx build
|
||||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||||
@ -231,14 +230,6 @@ if (RPM)
|
|||||||
include(CPack)
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILDEXAMPLES)
|
|
||||||
add_subdirectory (examples/c++)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(BUILDJAVAEXAMPLES)
|
|
||||||
add_subdirectory (examples/java)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||||
if (BUILDPYTHON3)
|
if (BUILDPYTHON3)
|
||||||
set (PYTHONBUILD_VERSION 3)
|
set (PYTHONBUILD_VERSION 3)
|
||||||
@ -248,6 +239,14 @@ if (BUILDSWIGPYTHON OR BUILDTESTS)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
|
if(BUILDEXAMPLES)
|
||||||
|
add_subdirectory (examples/c++)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILDJAVAEXAMPLES)
|
||||||
|
add_subdirectory (examples/java)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if (BUILDTESTS)
|
if (BUILDTESTS)
|
||||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
|
@ -4,6 +4,10 @@ API Changes {#apichanges}
|
|||||||
Here's a list of other API changes made to the library that break source/binary
|
Here's a list of other API changes made to the library that break source/binary
|
||||||
compatibility between releases:
|
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
|
* 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
|
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
|
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
|
* **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()`
|
* **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
|
function was removed in favor of a more complete GFX library implementation
|
||||||
|
|
@ -4,6 +4,17 @@ Changelog {#changelog}
|
|||||||
Here's a list summarizing some of the key undergoing changes to our library
|
Here's a list summarizing some of the key undergoing changes to our library
|
||||||
from earlier versions:
|
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
|
### v0.7.2
|
||||||
|
|
||||||
* Mraa 1.1.1 required changes to UPM drivers and examples for IIO core
|
* Mraa 1.1.1 required changes to UPM drivers and examples for IIO core
|
||||||
|
@ -224,10 +224,6 @@ add_example (groveultrasonic)
|
|||||||
add_example (sx1276-lora)
|
add_example (sx1276-lora)
|
||||||
add_example (sx1276-fsk)
|
add_example (sx1276-fsk)
|
||||||
add_example (ili9341)
|
add_example (ili9341)
|
||||||
if (OPENZWAVE_FOUND)
|
|
||||||
include_directories(${OPENZWAVE_INCLUDE_DIRS})
|
|
||||||
add_example (ozw)
|
|
||||||
endif()
|
|
||||||
add_example (nlgpio16)
|
add_example (nlgpio16)
|
||||||
add_example (ads1x15)
|
add_example (ads1x15)
|
||||||
if (MODBUS_FOUND)
|
if (MODBUS_FOUND)
|
||||||
@ -272,6 +268,7 @@ add_example (bmp280)
|
|||||||
add_example (bno055)
|
add_example (bno055)
|
||||||
add_example (l3gd20)
|
add_example (l3gd20)
|
||||||
add_example (bmx055)
|
add_example (bmx055)
|
||||||
|
add_example (ms5611)
|
||||||
|
|
||||||
# These are special cases where you specify example binary, source file and module(s)
|
# These are special cases where you specify example binary, source file and module(s)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||||
@ -290,9 +287,9 @@ add_custom_example (ak8975-example ak8975.cxx mpu9150)
|
|||||||
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
||||||
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
||||||
add_custom_example (grovecircularled-example grovecircularled.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 (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bmp280")
|
||||||
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bmp280")
|
||||||
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bme280")
|
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bmp280")
|
||||||
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||||
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||||
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||||
@ -303,3 +300,13 @@ add_custom_example (bmg160-example bmg160.cxx bmx055)
|
|||||||
add_custom_example (bmm150-example bmm150.cxx bmx055)
|
add_custom_example (bmm150-example bmm150.cxx bmx055)
|
||||||
add_custom_example (bmc150-example bmc150.cxx bmx055)
|
add_custom_example (bmc150-example bmc150.cxx bmx055)
|
||||||
add_custom_example (bmi055-example bmi055.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>
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* 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
|
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
|
||||||
upm::APDS9930* light_proximity = new upm::APDS9930(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) {
|
while (shouldRun) {
|
||||||
float lux = light_proximity->getAmbient();
|
float lux = light_proximity->getAmbient();
|
||||||
cout << "Luminance value is " << lux << endl;
|
cout << "Luminance value is " << lux << endl;
|
||||||
@ -53,6 +62,8 @@ main()
|
|||||||
cout << "Proximity value is " << proximity << endl;
|
cout << "Proximity value is " << proximity << endl;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
light_proximity->enableProximity(false);
|
||||||
|
light_proximity->enableIlluminance(false);
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
cout << "Exiting" << endl;
|
cout << "Exiting" << endl;
|
||||||
|
@ -53,7 +53,7 @@ int main(int argc, char **argv)
|
|||||||
// Output data every second until interrupted
|
// Output data every second until interrupted
|
||||||
while (shouldRun)
|
while (shouldRun)
|
||||||
{
|
{
|
||||||
printf("Temperature: %f Celcius\n", bar->getTemperature());
|
printf("Temperature: %f Celsius\n", bar->getTemperature());
|
||||||
printf("Pressure: %f Millibars\n", bar->getPressure());
|
printf("Pressure: %f Millibars\n", bar->getPressure());
|
||||||
printf("Altitude: %f Meters\n", bar->getAltitude());
|
printf("Altitude: %f Meters\n", bar->getAltitude());
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ int main()
|
|||||||
cout << "1 - read temp \t" ;
|
cout << "1 - read temp \t" ;
|
||||||
cout << "2 - sleep mode \t";
|
cout << "2 - sleep mode \t";
|
||||||
cout << "3 - wake up" << endl;
|
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 << "5 - show status bits" << endl;
|
||||||
cout << "6 - Set Tcrit \t" ;
|
cout << "6 - Set Tcrit \t" ;
|
||||||
cout << "7 - Set Tupper \t" ;
|
cout << "7 - Set Tupper \t" ;
|
||||||
@ -53,7 +53,7 @@ int main()
|
|||||||
temp->shutDown(false);
|
temp->shutDown(false);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
cout << "set mode to " << (temp->isCelsius() ? "Fahrenheit" : "Celcius") << endl;
|
cout << "set mode to " << (temp->isCelsius() ? "Fahrenheit" : "Celsius") << endl;
|
||||||
temp->setMode(!temp->isCelsius());
|
temp->setMode(!temp->isCelsius());
|
||||||
break;
|
break;
|
||||||
case 5:
|
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>
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -25,7 +25,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "ozw.hpp"
|
#include "ozwdump.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -39,53 +39,49 @@ int main(int argc, char **argv)
|
|||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
defaultDev = string(argv[1]);
|
defaultDev = string(argv[1]);
|
||||||
|
|
||||||
// Instantiate an OZW instance
|
// Instantiate an OZWDUMP instance
|
||||||
upm::OZW *sensor = new upm::OZW();
|
upm::OZWDUMP *sensor = new upm::OZWDUMP();
|
||||||
|
|
||||||
// The first thing to do is create options, then lock them when done.
|
// The first thing to do is create options, then lock them when done.
|
||||||
sensor->optionsCreate();
|
sensor->optionsCreate();
|
||||||
sensor->optionsLock();
|
sensor->optionsLock();
|
||||||
|
|
||||||
// Next, initialize it.
|
// 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;
|
<< endl;
|
||||||
|
|
||||||
if (!sensor->init(defaultDev))
|
sensor->init(defaultDev);
|
||||||
{
|
|
||||||
cerr << "Init failed." << endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
cout << "Initialization complete" << endl;
|
cout << "Initialization complete" << endl;
|
||||||
|
|
||||||
cout << "Dumping nodes..." << endl;
|
cout << "Dumping nodes..." << endl;
|
||||||
|
|
||||||
sensor->dumpNodes();
|
sensor->dumpNodes(true);
|
||||||
|
|
||||||
// The following is example output of dumpNodes:
|
// The following is example output of dumpNodes:
|
||||||
//
|
//
|
||||||
// Dumping nodes...
|
// Dumping nodes...
|
||||||
// Node 1: Z-Stick Gen5
|
// Node 1: Z-Stick Gen5
|
||||||
// Node 2: Smart Switch 6
|
// 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: 2, Type: float, Label: Energy, Value: 1.190 kWh
|
||||||
// Index: 3, Type: float, Label: Previous Reading, 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: 4, Type: int32, Label: Interval, Value: 1521 seconds
|
||||||
// Index: 5, Type: float, Label: Power, Value: 0.000 W
|
// Index: 5, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
||||||
// Index: 7, Type: float, Label: Current, Value: 0.000 A
|
// Index: 7, Type: float, Label: Current, Value: 0.000 A
|
||||||
// Index: 8, Type: bool, Label: Exporting, Value: False
|
// Index: 8, Type: bool, Label: Exporting, Value: False
|
||||||
// Index: 45, Type: list, Label: Day, Value: Friday
|
// Index: 45, Type: list, Label: Day, Value: Friday
|
||||||
// Index: 46, Type: byte, Label: Hour, Value: 5
|
// Index: 46, Type: byte, Label: Hour, Value: 5
|
||||||
// Index: 47, Type: byte, Label: Minute, Value: 53
|
// Index: 47, Type: byte, Label: Minute, Value: 53
|
||||||
// Node 3: Multi Sensor
|
// 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: 1, Type: float, Label: Temperature, Value: 72.8 F
|
||||||
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
||||||
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
||||||
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
||||||
// Node 5: Minimote
|
// Node 5: Minimote
|
||||||
// Node 6: Smart Energy Switch
|
// 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
||||||
// Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
||||||
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
|
// 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
|
// 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
||||||
// Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 7, Type: float, Label: Previous Reading, 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: 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]
|
//! [Interesting]
|
||||||
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ int main ()
|
|||||||
try {
|
try {
|
||||||
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
while (true) {
|
while (true) {
|
||||||
int temperature = sensor->getTemperatureCelcius();
|
int temperature = sensor->getTemperatureCelsius();
|
||||||
int humidity = sensor->getHumidityRelative();
|
int humidity = sensor->getHumidityRelative();
|
||||||
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
||||||
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
||||||
|
@ -76,7 +76,7 @@ int main ()
|
|||||||
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
|
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
int value = temperatureSensor->getTemperatureCelcius();
|
int value = temperatureSensor->getTemperatureCelsius();
|
||||||
std::cout << "Temperature = " << value << "C" << std::endl;
|
std::cout << "Temperature = " << value << "C" << std::endl;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
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]
|
||||||
|
}
|
||||||
|
}
|
@ -144,4 +144,11 @@ add_example_with_path(BMG160_Example bmx055 bmx055)
|
|||||||
add_example_with_path(BMM150_Example bmx055 bmx055)
|
add_example_with_path(BMM150_Example bmx055 bmx055)
|
||||||
add_example_with_path(BMC150_Example bmx055 bmx055)
|
add_example_with_path(BMC150_Example bmx055 bmx055)
|
||||||
add_example_with_path(BMI055_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()
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
@ -37,7 +37,7 @@ bar.init();
|
|||||||
// Output data every second until interrupted
|
// Output data every second until interrupted
|
||||||
setInterval(function()
|
setInterval(function()
|
||||||
{
|
{
|
||||||
console.log("Temperature: " + bar.getTemperature() + " Celcius");
|
console.log("Temperature: " + bar.getTemperature() + " Celsius");
|
||||||
console.log("Pressure: " + bar.getPressure() + " Millibars");
|
console.log("Pressure: " + bar.getPressure() + " Millibars");
|
||||||
console.log("Altitude: " + bar.getAltitude() + " Meters");
|
console.log("Altitude: " + bar.getAltitude() + " Meters");
|
||||||
console.log("");
|
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>
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -31,7 +31,7 @@ var sensorObj = require('jsupm_ozw');
|
|||||||
|
|
||||||
/************** Main code **************/
|
/************** Main code **************/
|
||||||
// Instantiate an OZW instance
|
// Instantiate an OZW instance
|
||||||
var sensor = new sensorObj.OZW();
|
var sensor = new sensorObj.OZWDUMP();
|
||||||
|
|
||||||
var defaultDev = "/dev/ttyACM0";
|
var defaultDev = "/dev/ttyACM0";
|
||||||
|
|
||||||
@ -48,42 +48,38 @@ sensor.optionsLock();
|
|||||||
// Next, initialize it.
|
// Next, initialize it.
|
||||||
console.log("Initializing, this may take awhile depending on your ZWave network");
|
console.log("Initializing, this may take awhile depending on your ZWave network");
|
||||||
|
|
||||||
if (!sensor.init(defaultDev))
|
sensor.init(defaultDev);
|
||||||
{
|
|
||||||
console.log("Init failed.");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
console.log("Initialization complete");
|
console.log("Initialization complete");
|
||||||
|
|
||||||
console.log("Dumping nodes...");
|
console.log("Dumping nodes...");
|
||||||
|
|
||||||
sensor.dumpNodes();
|
sensor.dumpNodes(true);
|
||||||
|
|
||||||
// The following is example output of dumpNodes:
|
// The following is example output of dumpNodes:
|
||||||
//
|
//
|
||||||
// Dumping nodes...
|
// Dumping nodes...
|
||||||
// Node 1: Z-Stick Gen5
|
// Node 1: Z-Stick Gen5
|
||||||
// Node 2: Smart Switch 6
|
// 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: 2, Type: float, Label: Energy, Value: 1.190 kWh
|
||||||
// Index: 3, Type: float, Label: Previous Reading, 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: 4, Type: int32, Label: Interval, Value: 1521 seconds
|
||||||
// Index: 5, Type: float, Label: Power, Value: 0.000 W
|
// Index: 5, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
// Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
||||||
// Index: 7, Type: float, Label: Current, Value: 0.000 A
|
// Index: 7, Type: float, Label: Current, Value: 0.000 A
|
||||||
// Index: 8, Type: bool, Label: Exporting, Value: False
|
// Index: 8, Type: bool, Label: Exporting, Value: False
|
||||||
// Index: 45, Type: list, Label: Day, Value: Friday
|
// Index: 45, Type: list, Label: Day, Value: Friday
|
||||||
// Index: 46, Type: byte, Label: Hour, Value: 5
|
// Index: 46, Type: byte, Label: Hour, Value: 5
|
||||||
// Index: 47, Type: byte, Label: Minute, Value: 53
|
// Index: 47, Type: byte, Label: Minute, Value: 53
|
||||||
// Node 3: Multi Sensor
|
// 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: 1, Type: float, Label: Temperature, Value: 72.8 F
|
||||||
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
// Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
||||||
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
// Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
||||||
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
// Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
||||||
// Node 5: Minimote
|
// Node 5: Minimote
|
||||||
// Node 6: Smart Energy Switch
|
// 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
// Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
||||||
// Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
// Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
||||||
// Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
|
// 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
|
// 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
// Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
||||||
// Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
// Index: 7, Type: float, Label: Previous Reading, 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: 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:
|
|
||||||
//
|
|
||||||
// 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);
|
|
||||||
//
|
//
|
||||||
|
|
||||||
sensor = null;
|
sensor = null;
|
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)
|
@ -46,7 +46,7 @@ bar = barometerObj.HP20X()
|
|||||||
bar.init()
|
bar.init()
|
||||||
|
|
||||||
while(1):
|
while(1):
|
||||||
print "Temperature:", bar.getTemperature(), "Celcius"
|
print "Temperature:", bar.getTemperature(), "Celsius"
|
||||||
print "Pressure: ", bar.getPressure(), "Millibars"
|
print "Pressure: ", bar.getPressure(), "Millibars"
|
||||||
print "Altitude: ", bar.getAltitude(), "Meters"
|
print "Altitude: ", bar.getAltitude(), "Meters"
|
||||||
print
|
print
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# Author: Jon Trulson <jtrulson@ics.com>
|
# 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
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
# a copy of this software and associated documentation files (the
|
# a copy of this software and associated documentation files (the
|
||||||
@ -25,7 +25,7 @@ import time, sys, signal, atexit
|
|||||||
import pyupm_ozw as sensorObj
|
import pyupm_ozw as sensorObj
|
||||||
|
|
||||||
# Instantiate an OZW instance
|
# Instantiate an OZW instance
|
||||||
sensor = sensorObj.OZW()
|
sensor = sensorObj.OZWDUMP()
|
||||||
|
|
||||||
# This function lets you run code on exit
|
# This function lets you run code on exit
|
||||||
def exitHandler():
|
def exitHandler():
|
||||||
@ -46,41 +46,39 @@ sensor.optionsLock()
|
|||||||
# Next, initialize it.
|
# Next, initialize it.
|
||||||
print "Initializing, this may take awhile depending on your ZWave network"
|
print "Initializing, this may take awhile depending on your ZWave network"
|
||||||
|
|
||||||
if (not sensor.init(defaultDev)):
|
sensor.init(defaultDev)
|
||||||
print "Init failed."
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print "Initialization complete"
|
print "Initialization complete"
|
||||||
|
|
||||||
print "Dumping nodes..."
|
print "Dumping nodes..."
|
||||||
|
|
||||||
sensor.dumpNodes()
|
sensor.dumpNodes(True)
|
||||||
|
|
||||||
# The following is example output of dumpNodes:
|
# The following is example output of dumpNodes:
|
||||||
#
|
#
|
||||||
# Dumping nodes...
|
# Dumping nodes...
|
||||||
# Node 1: Z-Stick Gen5
|
# Node 1: Z-Stick Gen5
|
||||||
# Node 2: Smart Switch 6
|
# 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: 2, Type: float, Label: Energy, Value: 1.190 kWh
|
||||||
# Index: 3, Type: float, Label: Previous Reading, 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: 4, Type: int32, Label: Interval, Value: 1521 seconds
|
||||||
# Index: 5, Type: float, Label: Power, Value: 0.000 W
|
# Index: 5, Type: float, Label: Power, Value: 0.000 W
|
||||||
# Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
# Index: 6, Type: float, Label: Voltage, Value: 121.256 V
|
||||||
# Index: 7, Type: float, Label: Current, Value: 0.000 A
|
# Index: 7, Type: float, Label: Current, Value: 0.000 A
|
||||||
# Index: 8, Type: bool, Label: Exporting, Value: False
|
# Index: 8, Type: bool, Label: Exporting, Value: False
|
||||||
# Index: 45, Type: list, Label: Day, Value: Friday
|
# Index: 45, Type: list, Label: Day, Value: Friday
|
||||||
# Index: 46, Type: byte, Label: Hour, Value: 5
|
# Index: 46, Type: byte, Label: Hour, Value: 5
|
||||||
# Index: 47, Type: byte, Label: Minute, Value: 53
|
# Index: 47, Type: byte, Label: Minute, Value: 53
|
||||||
# Node 3: Multi Sensor
|
# 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: 1, Type: float, Label: Temperature, Value: 72.8 F
|
||||||
# Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
# Index: 2, Type: float, Label: Luminance, Value: 4 lux
|
||||||
# Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
# Index: 3, Type: float, Label: Relative Humidity, Value: 22 %
|
||||||
# Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
# Index: 17, Type: byte, Label: Battery Level, Value: 98 %
|
||||||
# Node 5: Minimote
|
# Node 5: Minimote
|
||||||
# Node 6: Smart Energy Switch
|
# 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
# Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
# Index: 3, Type: float, Label: Energy, Value: 1.609 kWh
|
||||||
# Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
# Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
# Index: 7, Type: float, Label: Previous Reading, Value: 1.609 W
|
||||||
# Index: 8, Type: int32, Label: Interval, Value: 1521 seconds
|
# 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
|
# 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: 2, Type: float, Label: Power, Value: 0.000 W
|
||||||
# Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
# Index: 3, Type: float, Label: Energy, Value: 0.000 kWh
|
||||||
# Index: 4, Type: float, Label: Previous Reading, 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: 6, Type: float, Label: Power, Value: 0.000 W
|
||||||
# Index: 7, Type: float, Label: Previous Reading, 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: 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:
|
|
||||||
#
|
|
||||||
# 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);
|
|
||||||
|
|
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)
|
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
||||||
|
|
||||||
macro(upm_SWIG_PYTHON)
|
macro(upm_SWIG_PYTHON)
|
||||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
if (BUILDSWIGPYTHON)
|
||||||
|
|
||||||
include_directories (
|
include_directories (
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||||
@ -50,7 +50,7 @@ macro(upm_SWIG_PYTHON)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(upm_SWIG_NODE)
|
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
|
# 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
|
# 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
|
# 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()
|
endmacro()
|
||||||
|
|
||||||
macro(upm_SWIG_JAVA)
|
macro(upm_SWIG_JAVA)
|
||||||
if (BUILDSWIGJAVA AND BUILDSWIG)
|
if (BUILDSWIGJAVA)
|
||||||
|
|
||||||
FIND_PACKAGE (JNI REQUIRED)
|
FIND_PACKAGE (JNI REQUIRED)
|
||||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
||||||
@ -166,7 +166,7 @@ macro(upm_doxygen)
|
|||||||
set (classname ${libname})
|
set (classname ${libname})
|
||||||
endif()
|
endif()
|
||||||
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
||||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
if (BUILDSWIGPYTHON)
|
||||||
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
|
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
|
||||||
add_dependencies (pydoc _pyupm_${libname})
|
add_dependencies (pydoc _pyupm_${libname})
|
||||||
else ()
|
else ()
|
||||||
|
@ -7,13 +7,11 @@ include_directories("../pca9685")
|
|||||||
upm_module_init()
|
upm_module_init()
|
||||||
add_dependencies(${libname} pca9685)
|
add_dependencies(${libname} pca9685)
|
||||||
target_link_libraries(${libname} pca9685)
|
target_link_libraries(${libname} pca9685)
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGNODE)
|
||||||
if (BUILDSWIGNODE)
|
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||||
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
swig_link_libraries (jsupm_${libname} pca9685)
|
||||||
swig_link_libraries (jsupm_${libname} pca9685)
|
endif()
|
||||||
endif()
|
if (BUILDSWIGPYTHON)
|
||||||
if (BUILDSWIGPYTHON)
|
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||||
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
swig_link_libraries (pyupm_${libname} pca9685)
|
||||||
swig_link_libraries (pyupm_${libname} pca9685)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -212,10 +212,10 @@ float ADIS16448::gyroScale(int16_t sensorData)
|
|||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Converts temperature data output from the sensorRead() function and returns temperature
|
// Converts temperature data output from the sensorRead() function and returns temperature
|
||||||
// in degrees Celcius
|
// in degrees Celsius
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// sensorData - data output from sensorRead()
|
// 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)
|
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
|
// Converts barometer data output from sensorRead() function and returns pressure in bar
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// sensorData - data output from sensorRead()
|
// 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)
|
float ADIS16448::pressureScale(int16_t sensorData)
|
||||||
{
|
{
|
||||||
@ -238,7 +238,7 @@ float ADIS16448::pressureScale(int16_t sensorData)
|
|||||||
// reading in Gauss
|
// reading in Gauss
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// sensorData - data output from sensorRead()
|
// 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)
|
float ADIS16448::magnetometerScale(int16_t sensorData)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +138,7 @@ namespace upm {
|
|||||||
float getZeroPoint() { return m_zeroPoint; };
|
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
|
* datasheet says that this value is very repeatable, but is not
|
||||||
* an accurate absolute temperature.
|
* an accurate absolute temperature.
|
||||||
*
|
*
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -41,7 +41,7 @@ APDS9930::APDS9930(int device)
|
|||||||
|
|
||||||
APDS9930::~APDS9930()
|
APDS9930::~APDS9930()
|
||||||
{
|
{
|
||||||
if(m_iio)
|
if (m_iio)
|
||||||
mraa_iio_close(m_iio);
|
mraa_iio_close(m_iio);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,3 +60,25 @@ APDS9930::getProximity()
|
|||||||
mraa_iio_read_int(m_iio, "in_proximity_raw", &iio_value);
|
mraa_iio_read_int(m_iio, "in_proximity_raw", &iio_value);
|
||||||
return 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>
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -75,6 +75,16 @@ class APDS9930
|
|||||||
* @return Proximity value
|
* @return Proximity value
|
||||||
*/
|
*/
|
||||||
int getProximity();
|
int getProximity();
|
||||||
|
/**
|
||||||
|
* Enable proximity
|
||||||
|
* @param enable state
|
||||||
|
*/
|
||||||
|
bool enableProximity(bool enable);
|
||||||
|
/**
|
||||||
|
* Enable illuminance
|
||||||
|
* @param enable state
|
||||||
|
*/
|
||||||
|
bool enableIlluminance(bool enable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mraa_iio_context m_iio;
|
mraa_iio_context m_iio;
|
||||||
|
@ -10,15 +10,13 @@ if (BACNET_FOUND)
|
|||||||
upm_module_init()
|
upm_module_init()
|
||||||
add_dependencies(${libname} ${BACNET_LIBRARIES})
|
add_dependencies(${libname} ${BACNET_LIBRARIES})
|
||||||
target_link_libraries(${libname} ${BACNET_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(${libname} ${BACNET_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGNODE)
|
||||||
if (BUILDSWIGNODE)
|
swig_link_libraries (jsupm_${libname} ${BACNET_LIBRARIES})
|
||||||
swig_link_libraries (jsupm_${libname} ${BACNET_LIBRARIES})
|
endif()
|
||||||
endif()
|
if (BUILDSWIGPYTHON)
|
||||||
if (BUILDSWIGPYTHON)
|
swig_link_libraries (pyupm_${libname} ${BACNET_LIBRARIES})
|
||||||
swig_link_libraries (pyupm_${libname} ${BACNET_LIBRARIES})
|
endif()
|
||||||
endif()
|
if (BUILDSWIGJAVA)
|
||||||
if (BUILDSWIGJAVA)
|
swig_link_libraries (javaupm_${libname} ${BACNET_LIBRARIES})
|
||||||
swig_link_libraries (javaupm_${libname} ${BACNET_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -40,7 +40,7 @@ using namespace std;
|
|||||||
|
|
||||||
// #define BMP280_USE_TEST_DATA
|
// #define BMP280_USE_TEST_DATA
|
||||||
|
|
||||||
// conversion from fahrenheit to celcius and back
|
// conversion from fahrenheit to celsius and back
|
||||||
|
|
||||||
static float f2c(float f)
|
static float f2c(float f)
|
||||||
{
|
{
|
||||||
|
@ -304,8 +304,8 @@ namespace upm {
|
|||||||
* to calling this method.
|
* to calling this method.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return data in Fahrenheit, false for
|
* @param fahrenheit true to return data in Fahrenheit, false for
|
||||||
* Celicus. Celcius is the default.
|
* Celicus. Celsius is the default.
|
||||||
* @return The temperature in degrees Celcius or Fahrenheit.
|
* @return The temperature in degrees Celsius or Fahrenheit.
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ namespace upm {
|
|||||||
return "BMP280";
|
return "BMP280";
|
||||||
};
|
};
|
||||||
|
|
||||||
int getTemperatureCelcius()
|
int getTemperatureCelsius()
|
||||||
{
|
{
|
||||||
return int(getTemperature(false));
|
return int(getTemperature(false));
|
||||||
};
|
};
|
||||||
|
@ -172,7 +172,7 @@ BMPX8X::getAltitude (float sealevelPressure) {
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BMPX8X::getTemperatureCelcius() {
|
BMPX8X::getTemperatureCelsius() {
|
||||||
return static_cast<int>(getTemperature() + 0.5);
|
return static_cast<int>(getTemperature() + 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,10 +144,10 @@ class BMPX8X : public IPressureSensor, public ITemperatureSensor {
|
|||||||
float getAltitude (float sealevelPressure = 101325);
|
float getAltitude (float sealevelPressure = 101325);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return latest calculated temperature value in Celcius
|
* Return latest calculated temperature value in Celsius
|
||||||
* See ITemperatureSensor
|
* See ITemperatureSensor
|
||||||
*/
|
*/
|
||||||
int getTemperatureCelcius();
|
int getTemperatureCelsius();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return latest calculated pressure value in Pascals
|
* Return latest calculated pressure value in Pascals
|
||||||
|
@ -33,19 +33,16 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
// conversion from celsius to fahrenheit
|
||||||
|
|
||||||
static float c2f(float c)
|
static float c2f(float c)
|
||||||
{
|
{
|
||||||
return (c * (9.0 / 5.0) + 32.0);
|
return (c * (9.0 / 5.0) + 32.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMA250E::BMA250E(int bus, uint8_t addr, int cs) :
|
BMA250E::BMA250E(int bus, int addr, int cs) :
|
||||||
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
||||||
{
|
{
|
||||||
m_addr = addr;
|
|
||||||
m_isSPI = false;
|
|
||||||
|
|
||||||
m_accX = 0;
|
m_accX = 0;
|
||||||
m_accY = 0;
|
m_accY = 0;
|
||||||
m_accZ = 0;
|
m_accZ = 0;
|
||||||
@ -53,7 +50,15 @@ BMA250E::BMA250E(int bus, uint8_t addr, int cs) :
|
|||||||
m_temperature = 0.0;
|
m_temperature = 0.0;
|
||||||
|
|
||||||
if (addr < 0)
|
if (addr < 0)
|
||||||
m_isSPI = true;
|
{
|
||||||
|
m_addr = 0;
|
||||||
|
m_isSPI = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_addr = uint8_t(addr);
|
||||||
|
m_isSPI = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_isSPI)
|
if (m_isSPI)
|
||||||
{
|
{
|
||||||
@ -127,6 +132,13 @@ BMA250E::~BMA250E()
|
|||||||
{
|
{
|
||||||
uninstallISR(INTERRUPT_INT1);
|
uninstallISR(INTERRUPT_INT1);
|
||||||
uninstallISR(INTERRUPT_INT2);
|
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)
|
void BMA250E::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
|
||||||
@ -160,20 +172,14 @@ void BMA250E::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
|
|||||||
|
|
||||||
void BMA250E::update()
|
void BMA250E::update()
|
||||||
{
|
{
|
||||||
int bufLen = 0;
|
int bufLen = 7; // max, non-FIFO
|
||||||
uint8_t startReg = 0;
|
uint8_t startReg = REG_ACCD_X_LSB;
|
||||||
|
|
||||||
if (m_useFIFO)
|
if (m_useFIFO)
|
||||||
{
|
{
|
||||||
bufLen = 6;
|
bufLen = 6;
|
||||||
startReg = REG_FIFO_DATA;
|
startReg = REG_FIFO_DATA;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// non FIFO, read acc regs directly (including temp)
|
|
||||||
bufLen = 7;
|
|
||||||
startReg = REG_ACCD_X_LSB;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t buf[bufLen];
|
uint8_t buf[bufLen];
|
||||||
|
|
||||||
|
@ -964,7 +964,7 @@ namespace upm {
|
|||||||
* @param cs The gpio pin to use for the SPI Chip Select. -1 for
|
* @param cs The gpio pin to use for the SPI Chip Select. -1 for
|
||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
*/
|
*/
|
||||||
BMA250E(int bus=BMA250E_I2C_BUS, uint8_t addr=BMA250E_DEFAULT_ADDR,
|
BMA250E(int bus=BMA250E_I2C_BUS, int addr=BMA250E_DEFAULT_ADDR,
|
||||||
int cs=-1);
|
int cs=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1014,8 +1014,8 @@ namespace upm {
|
|||||||
* calling this method.
|
* calling this method.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return data in Fahrenheit, false for
|
* @param fahrenheit true to return data in Fahrenheit, false for
|
||||||
* Celicus. Celcius is the default.
|
* Celicus. Celsius is the default.
|
||||||
* @return The temperature in degrees Celcius or Fahrenheit.
|
* @return The temperature in degrees Celsius or Fahrenheit.
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
BMC150::BMC150(int accelBus, uint8_t accelAddr, int accelCS,
|
BMC150::BMC150(int accelBus, int accelAddr, int accelCS,
|
||||||
int magBus, uint8_t magAddr, int magCS) :
|
int magBus, int magAddr, int magCS) :
|
||||||
m_accel(0), m_mag(0)
|
m_accel(0), m_mag(0)
|
||||||
{
|
{
|
||||||
// if -1 is supplied as a bus for any of these, we will not
|
// if -1 is supplied as a bus for any of these, we will not
|
||||||
|
@ -93,10 +93,10 @@ namespace upm {
|
|||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
*/
|
*/
|
||||||
BMC150(int accelBus=BMC150_DEFAULT_BUS,
|
BMC150(int accelBus=BMC150_DEFAULT_BUS,
|
||||||
uint8_t accelAddr=BMC150_DEFAULT_ACC_ADDR,
|
int accelAddr=BMC150_DEFAULT_ACC_ADDR,
|
||||||
int accelCS=-1,
|
int accelCS=-1,
|
||||||
int magBus=BMC150_DEFAULT_BUS,
|
int magBus=BMC150_DEFAULT_BUS,
|
||||||
uint8_t magAddr=BMC150_DEFAULT_MAG_ADDR,
|
int magAddr=BMC150_DEFAULT_MAG_ADDR,
|
||||||
int magCS=-1);
|
int magCS=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,19 +35,16 @@ using namespace std;
|
|||||||
|
|
||||||
#define BMG160_DEFAULT_CHIPID 0x0f
|
#define BMG160_DEFAULT_CHIPID 0x0f
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
// conversion from celsius to fahrenheit
|
||||||
|
|
||||||
static float c2f(float c)
|
static float c2f(float c)
|
||||||
{
|
{
|
||||||
return (c * (9.0 / 5.0) + 32.0);
|
return (c * (9.0 / 5.0) + 32.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMG160::BMG160(int bus, uint8_t addr, int cs) :
|
BMG160::BMG160(int bus, int addr, int cs) :
|
||||||
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
m_i2c(0), m_spi(0), m_gpioIntr1(0), m_gpioIntr2(0), m_gpioCS(0)
|
||||||
{
|
{
|
||||||
m_addr = addr;
|
|
||||||
m_isSPI = false;
|
|
||||||
|
|
||||||
m_gyrX = 0;
|
m_gyrX = 0;
|
||||||
m_gyrY = 0;
|
m_gyrY = 0;
|
||||||
m_gyrZ = 0;
|
m_gyrZ = 0;
|
||||||
@ -55,7 +52,15 @@ BMG160::BMG160(int bus, uint8_t addr, int cs) :
|
|||||||
m_temperature = 0.0;
|
m_temperature = 0.0;
|
||||||
|
|
||||||
if (addr < 0)
|
if (addr < 0)
|
||||||
m_isSPI = true;
|
{
|
||||||
|
m_addr = 0;
|
||||||
|
m_isSPI = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_addr = uint8_t(addr);
|
||||||
|
m_isSPI = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_isSPI)
|
if (m_isSPI)
|
||||||
{
|
{
|
||||||
@ -105,6 +110,13 @@ BMG160::~BMG160()
|
|||||||
{
|
{
|
||||||
uninstallISR(INTERRUPT_INT1);
|
uninstallISR(INTERRUPT_INT1);
|
||||||
uninstallISR(INTERRUPT_INT2);
|
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)
|
void BMG160::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
|
||||||
@ -132,20 +144,14 @@ void BMG160::init(POWER_MODE_T pwr, RANGE_T range, BW_T bw)
|
|||||||
|
|
||||||
void BMG160::update()
|
void BMG160::update()
|
||||||
{
|
{
|
||||||
int bufLen = 0;
|
int bufLen = 7; // max, non-FIFO
|
||||||
uint8_t startReg = 0;
|
uint8_t startReg = REG_RATE_X_LSB;
|
||||||
|
|
||||||
if (m_useFIFO)
|
if (m_useFIFO)
|
||||||
{
|
{
|
||||||
bufLen = 6;
|
bufLen = 6;
|
||||||
startReg = REG_FIFO_DATA;
|
startReg = REG_FIFO_DATA;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// non FIFO, read acc regs directly (including temp)
|
|
||||||
bufLen = 7;
|
|
||||||
startReg = REG_RATE_X_LSB;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t buf[bufLen];
|
uint8_t buf[bufLen];
|
||||||
|
|
||||||
|
@ -823,7 +823,7 @@ namespace upm {
|
|||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
* @param theChipID The chip ID to use for validation
|
* @param theChipID The chip ID to use for validation
|
||||||
*/
|
*/
|
||||||
BMG160(int bus=BMG160_I2C_BUS, uint8_t addr=BMG160_DEFAULT_ADDR,
|
BMG160(int bus=BMG160_I2C_BUS, int addr=BMG160_DEFAULT_ADDR,
|
||||||
int cs=-1);
|
int cs=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -873,8 +873,8 @@ namespace upm {
|
|||||||
* calling this method.
|
* calling this method.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return data in Fahrenheit, false for
|
* @param fahrenheit true to return data in Fahrenheit, false for
|
||||||
* Celicus. Celcius is the default.
|
* Celicus. Celsius is the default.
|
||||||
* @return The temperature in degrees Celcius or Fahrenheit.
|
* @return The temperature in degrees Celsius or Fahrenheit.
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
BMI055::BMI055(int accelBus, uint8_t accelAddr, int accelCS,
|
BMI055::BMI055(int accelBus, int accelAddr, int accelCS,
|
||||||
int gyroBus, uint8_t gyroAddr, int gyroCS) :
|
int gyroBus, int gyroAddr, int gyroCS) :
|
||||||
m_accel(0), m_gyro(0)
|
m_accel(0), m_gyro(0)
|
||||||
{
|
{
|
||||||
// if -1 is supplied as a bus for any of these, we will not
|
// if -1 is supplied as a bus for any of these, we will not
|
||||||
|
@ -85,10 +85,10 @@ namespace upm {
|
|||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
*/
|
*/
|
||||||
BMI055(int accelBus=BMA250E_I2C_BUS,
|
BMI055(int accelBus=BMA250E_I2C_BUS,
|
||||||
uint8_t accelAddr=BMA250E_DEFAULT_ADDR,
|
int accelAddr=BMA250E_DEFAULT_ADDR,
|
||||||
int accelCS=-1,
|
int accelCS=-1,
|
||||||
int gyroBus=BMG160_I2C_BUS,
|
int gyroBus=BMG160_I2C_BUS,
|
||||||
uint8_t gyroAddr=BMG160_DEFAULT_ADDR,
|
int gyroAddr=BMG160_DEFAULT_ADDR,
|
||||||
int gyroCS=-1);
|
int gyroCS=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,12 +92,9 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
BMM150::BMM150(int bus, uint8_t addr, int cs) :
|
BMM150::BMM150(int bus, int addr, int cs) :
|
||||||
m_i2c(0), m_spi(0), m_gpioIntr(0), m_gpioDR(0), m_gpioCS(0)
|
m_i2c(0), m_spi(0), m_gpioIntr(0), m_gpioDR(0), m_gpioCS(0)
|
||||||
{
|
{
|
||||||
m_addr = addr;
|
|
||||||
m_isSPI = false;
|
|
||||||
|
|
||||||
m_magX = 0;
|
m_magX = 0;
|
||||||
m_magY = 0;
|
m_magY = 0;
|
||||||
m_magZ = 0;
|
m_magZ = 0;
|
||||||
@ -119,7 +116,16 @@ BMM150::BMM150(int bus, uint8_t addr, int cs) :
|
|||||||
m_dig_xy1 = 0;
|
m_dig_xy1 = 0;
|
||||||
|
|
||||||
if (addr < 0)
|
if (addr < 0)
|
||||||
m_isSPI = true;
|
{
|
||||||
|
m_addr = 0;
|
||||||
|
m_isSPI = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_addr = uint8_t(addr);
|
||||||
|
m_isSPI = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_isSPI)
|
if (m_isSPI)
|
||||||
{
|
{
|
||||||
@ -177,6 +183,13 @@ BMM150::~BMM150()
|
|||||||
{
|
{
|
||||||
uninstallISR(INTERRUPT_INT);
|
uninstallISR(INTERRUPT_INT);
|
||||||
uninstallISR(INTERRUPT_DR);
|
uninstallISR(INTERRUPT_DR);
|
||||||
|
|
||||||
|
if (m_i2c)
|
||||||
|
delete m_i2c;
|
||||||
|
if (m_spi)
|
||||||
|
delete m_spi;
|
||||||
|
if(m_gpioCS)
|
||||||
|
delete m_gpioCS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BMM150::init(USAGE_PRESETS_T usage)
|
void BMM150::init(USAGE_PRESETS_T usage)
|
||||||
|
@ -320,7 +320,7 @@ namespace upm {
|
|||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
* @param theChipID The chip ID to use for validation
|
* @param theChipID The chip ID to use for validation
|
||||||
*/
|
*/
|
||||||
BMM150(int bus=BMM150_I2C_BUS, uint8_t addr=BMM150_DEFAULT_ADDR,
|
BMM150(int bus=BMM150_I2C_BUS, int addr=BMM150_DEFAULT_ADDR,
|
||||||
int cs=-1);
|
int cs=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +32,9 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
BMX055::BMX055(int accelBus, uint8_t accelAddr, int accelCS,
|
BMX055::BMX055(int accelBus, int accelAddr, int accelCS,
|
||||||
int gyroBus, uint8_t gyroAddr, int gyroCS,
|
int gyroBus, int gyroAddr, int gyroCS,
|
||||||
int magBus, uint8_t magAddr, int magCS) :
|
int magBus, int magAddr, int magCS) :
|
||||||
m_accel(0), m_gyro(0), m_mag(0)
|
m_accel(0), m_gyro(0), m_mag(0)
|
||||||
{
|
{
|
||||||
// if -1 is supplied as a bus for any of these, we will not
|
// if -1 is supplied as a bus for any of these, we will not
|
||||||
|
@ -100,13 +100,13 @@ namespace upm {
|
|||||||
* I2C or for SPI with a hardware controlled pin.
|
* I2C or for SPI with a hardware controlled pin.
|
||||||
*/
|
*/
|
||||||
BMX055(int accelBus=BMA250E_I2C_BUS,
|
BMX055(int accelBus=BMA250E_I2C_BUS,
|
||||||
uint8_t accelAddr=BMA250E_DEFAULT_ADDR,
|
int accelAddr=BMA250E_DEFAULT_ADDR,
|
||||||
int accelCS=-1,
|
int accelCS=-1,
|
||||||
int gyroBus=BMG160_I2C_BUS,
|
int gyroBus=BMG160_I2C_BUS,
|
||||||
uint8_t gyroAddr=BMG160_DEFAULT_ADDR,
|
int gyroAddr=BMG160_DEFAULT_ADDR,
|
||||||
int gyroCS=-1,
|
int gyroCS=-1,
|
||||||
int magBus=BMM150_I2C_BUS,
|
int magBus=BMM150_I2C_BUS,
|
||||||
uint8_t magAddr=BMM150_DEFAULT_ADDR,
|
int magAddr=BMM150_DEFAULT_ADDR,
|
||||||
int magCS=-1);
|
int magCS=-1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// conversion from fahrenheit to celcius and back
|
// conversion from fahrenheit to celsius and back
|
||||||
|
|
||||||
static float f2c(float f)
|
static float f2c(float f)
|
||||||
{
|
{
|
||||||
@ -245,20 +245,20 @@ void BNO055::setTemperatureSource(TEMP_SOURCES_T src)
|
|||||||
writeReg(REG_TEMP_SOURCE, src);
|
writeReg(REG_TEMP_SOURCE, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNO055::setTemperatureUnits(bool celcius)
|
void BNO055::setTemperatureUnits(bool celsius)
|
||||||
{
|
{
|
||||||
setPage(0);
|
setPage(0);
|
||||||
|
|
||||||
uint8_t reg = readReg(REG_UNIT_SEL);
|
uint8_t reg = readReg(REG_UNIT_SEL);
|
||||||
|
|
||||||
if (celcius)
|
if (celsius)
|
||||||
reg &= ~UNIT_SEL_TEMP_UNIT;
|
reg &= ~UNIT_SEL_TEMP_UNIT;
|
||||||
else
|
else
|
||||||
reg |= UNIT_SEL_TEMP_UNIT;
|
reg |= UNIT_SEL_TEMP_UNIT;
|
||||||
|
|
||||||
writeReg(REG_UNIT_SEL, reg);
|
writeReg(REG_UNIT_SEL, reg);
|
||||||
|
|
||||||
m_tempIsC = celcius;
|
m_tempIsC = celsius;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNO055::setAccelerometerUnits(bool mg)
|
void BNO055::setAccelerometerUnits(bool mg)
|
||||||
|
@ -896,7 +896,7 @@ namespace upm {
|
|||||||
*
|
*
|
||||||
* By default, the constructor sets the acceleration units to
|
* By default, the constructor sets the acceleration units to
|
||||||
* m/s^2, gyro and Euler units to degrees, and temperature to
|
* m/s^2, gyro and Euler units to degrees, and temperature to
|
||||||
* celcius. It then enters the NDOF fusion mode.
|
* celsius. It then enters the NDOF fusion mode.
|
||||||
*
|
*
|
||||||
* In addition, the internal clock is used so that compatibility
|
* In addition, the internal clock is used so that compatibility
|
||||||
* with other implementations is assured. If you are using a
|
* with other implementations is assured. If you are using a
|
||||||
@ -980,11 +980,11 @@ namespace upm {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Select the temperature units. This can be the Fahrenheit or
|
* Select the temperature units. This can be the Fahrenheit or
|
||||||
* Celcius.
|
* Celsius.
|
||||||
*
|
*
|
||||||
* @param celcius true for Celius, false for Fahrenheit.
|
* @param celsius true for Celius, false for Fahrenheit.
|
||||||
*/
|
*/
|
||||||
void setTemperatureUnits(bool celcius);
|
void setTemperatureUnits(bool celsius);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the operating mode for the device. This places the device
|
* Set the operating mode for the device. This places the device
|
||||||
@ -1060,8 +1060,8 @@ namespace upm {
|
|||||||
* calling this method.
|
* calling this method.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return data in Fahrenheit, false for
|
* @param fahrenheit true to return data in Fahrenheit, false for
|
||||||
* Celicus. Celcius is the default.
|
* Celicus. Celsius is the default.
|
||||||
* @return The temperature in degrees Celcius or Fahrenheit.
|
* @return The temperature in degrees Celsius or Fahrenheit.
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ using namespace std;
|
|||||||
// several aio reads.
|
// several aio reads.
|
||||||
static const int maxSamples = 50;
|
static const int maxSamples = 50;
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
// conversion from celsius to fahrenheit
|
||||||
|
|
||||||
static float c2f(float c)
|
static float c2f(float c)
|
||||||
{
|
{
|
||||||
|
@ -130,9 +130,9 @@ namespace upm {
|
|||||||
* constructor) then this function will always return 0C/32F.
|
* constructor) then this function will always return 0C/32F.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return the temperature in degrees
|
* @param fahrenheit true to return the temperature in degrees
|
||||||
* fahrenheit, false to return the temperature in degrees celcius.
|
* fahrenheit, false to return the temperature in degrees celsius.
|
||||||
* The default is false (degrees Celcius).
|
* The default is false (degrees Celsius).
|
||||||
* @return The last temperature reading in Celcius or Fahrenheit
|
* @return The last temperature reading in Celsius or Fahrenheit
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ namespace upm {
|
|||||||
bool m_hasTemp;
|
bool m_hasTemp;
|
||||||
bool m_hasHum;
|
bool m_hasHum;
|
||||||
|
|
||||||
// in Celcius
|
// in Celsius
|
||||||
float m_temperature;
|
float m_temperature;
|
||||||
|
|
||||||
float m_humidity;
|
float m_humidity;
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
// conversion from celsius to fahrenheit
|
||||||
static float c2f(float c)
|
static float c2f(float c)
|
||||||
{
|
{
|
||||||
return (c * (9.0 / 5.0) + 32.0);
|
return (c * (9.0 / 5.0) + 32.0);
|
||||||
|
@ -153,9 +153,9 @@ namespace upm {
|
|||||||
*
|
*
|
||||||
* @param index The device index to access (starts at 0).
|
* @param index The device index to access (starts at 0).
|
||||||
* @param fahrenheit true to return the temperature in degrees
|
* @param fahrenheit true to return the temperature in degrees
|
||||||
* fahrenheit, false to return the temperature in degrees celcius.
|
* fahrenheit, false to return the temperature in degrees celsius.
|
||||||
* The default is false (degrees Celcius).
|
* The default is false (degrees Celsius).
|
||||||
* @return The last temperature reading in Celcius or Fahrenheit
|
* @return The last temperature reading in Celsius or Fahrenheit
|
||||||
*/
|
*/
|
||||||
float getTemperature(int index, bool fahrenheit=false);
|
float getTemperature(int index, bool fahrenheit=false);
|
||||||
|
|
||||||
|
@ -11,18 +11,16 @@ if (BACNET_FOUND)
|
|||||||
include_directories("../bacnetmstp")
|
include_directories("../bacnetmstp")
|
||||||
upm_module_init()
|
upm_module_init()
|
||||||
target_link_libraries(${libname} bacnetmstp)
|
target_link_libraries(${libname} bacnetmstp)
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGNODE)
|
||||||
if (BUILDSWIGNODE)
|
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||||
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
swig_link_libraries (jsupm_${libname} bacnetmstp)
|
||||||
swig_link_libraries (jsupm_${libname} bacnetmstp)
|
endif()
|
||||||
endif()
|
if (BUILDSWIGPYTHON)
|
||||||
if (BUILDSWIGPYTHON)
|
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||||
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
swig_link_libraries (pyupm_${libname} bacnetmstp)
|
||||||
swig_link_libraries (pyupm_${libname} bacnetmstp)
|
endif()
|
||||||
endif()
|
if (BUILDSWIGJAVA)
|
||||||
if (BUILDSWIGJAVA)
|
set_target_properties(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||||
set_target_properties(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
swig_link_libraries (javaupm_${libname} bacnetmstp)
|
||||||
swig_link_libraries (javaupm_${libname} bacnetmstp)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
set (libname "grove")
|
set (libname "grove")
|
||||||
set (libdescription "upm grove module")
|
set (libdescription "upm grove module")
|
||||||
set (module_src ${libname}.cxx)
|
set (module_src grovebutton.cxx groveled.cxx grovelight.cxx groverelay.cxx groverotary.cxx groveslide.cxx grovetemp.cxx)
|
||||||
set (module_hpp ${libname}.hpp)
|
set (module_hpp grovebutton.hpp groveled.hpp grovelight.hpp groverelay.hpp groverotary.hpp groveslide.hpp grovetemp.hpp grovebase.hpp grove.hpp)
|
||||||
upm_module_init()
|
upm_module_init()
|
||||||
|
@ -1,307 +1 @@
|
|||||||
/*
|
|
||||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
|
||||||
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
|
||||||
* Contributions: Sarah Knepper <sarah.knepper@intel.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "grove.hpp"
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
|
|
||||||
//// GroveLed ////
|
|
||||||
|
|
||||||
GroveLed::GroveLed(int pin)
|
|
||||||
{
|
|
||||||
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_gpio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
|
||||||
m_name = "LED Socket";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveLed::~GroveLed()
|
|
||||||
{
|
|
||||||
mraa_gpio_close(m_gpio);
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa_result_t GroveLed::write(int value)
|
|
||||||
{
|
|
||||||
if (value >= 1) {
|
|
||||||
return mraa_gpio_write(m_gpio, 1);
|
|
||||||
}
|
|
||||||
return mraa_gpio_write(m_gpio, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa_result_t GroveLed::on()
|
|
||||||
{
|
|
||||||
return write(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa_result_t GroveLed::off()
|
|
||||||
{
|
|
||||||
return write(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveRelay ////
|
|
||||||
|
|
||||||
GroveRelay::GroveRelay(unsigned int pin)
|
|
||||||
{
|
|
||||||
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_gpio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
|
||||||
m_name = "Relay Switch";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveRelay::~GroveRelay()
|
|
||||||
{
|
|
||||||
mraa_gpio_close(m_gpio);
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa_result_t GroveRelay::on()
|
|
||||||
{
|
|
||||||
return mraa_gpio_write(m_gpio, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa_result_t GroveRelay::off()
|
|
||||||
{
|
|
||||||
return mraa_gpio_write(m_gpio, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GroveRelay::isOn()
|
|
||||||
{
|
|
||||||
return mraa_gpio_read(m_gpio) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GroveRelay::isOff()
|
|
||||||
{
|
|
||||||
return mraa_gpio_read(m_gpio) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveTemp ////
|
|
||||||
|
|
||||||
GroveTemp::GroveTemp(unsigned int pin, float scale)
|
|
||||||
{
|
|
||||||
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_name = "Temperature Sensor";
|
|
||||||
m_scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveTemp::~GroveTemp()
|
|
||||||
{
|
|
||||||
mraa_aio_close(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GroveTemp::value ()
|
|
||||||
{
|
|
||||||
float a = (float) mraa_aio_read(m_aio);
|
|
||||||
if (a == -1.0) return -1;
|
|
||||||
// Apply scale factor after error check
|
|
||||||
a *= m_scale;
|
|
||||||
float r = (float)(1023.0-a)*10000.0/a;
|
|
||||||
float t = 1.0/(log(r/10000.0)/3975.0 + 1.0/298.15)-273.15;
|
|
||||||
return (int) round(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveTemp::raw_value()
|
|
||||||
{
|
|
||||||
return (float) mraa_aio_read(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveLight ////
|
|
||||||
|
|
||||||
GroveLight::GroveLight(unsigned int pin)
|
|
||||||
{
|
|
||||||
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_name = "Light Sensor";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveLight::~GroveLight()
|
|
||||||
{
|
|
||||||
mraa_aio_close(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GroveLight::value()
|
|
||||||
{
|
|
||||||
// rough conversion to lux, using formula from Grove Starter Kit booklet
|
|
||||||
float a = (float) mraa_aio_read(m_aio);
|
|
||||||
if (a == -1.0) return -1;
|
|
||||||
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
|
|
||||||
return (int) round(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveLight::raw_value()
|
|
||||||
{
|
|
||||||
return (float) mraa_aio_read(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveRotary ////
|
|
||||||
|
|
||||||
GroveRotary::GroveRotary(unsigned int pin)
|
|
||||||
{
|
|
||||||
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_name = "Rotary Angle Sensor";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveRotary::~GroveRotary()
|
|
||||||
{
|
|
||||||
mraa_aio_close(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::abs_value()
|
|
||||||
{
|
|
||||||
return (float) mraa_aio_read(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::abs_deg()
|
|
||||||
{
|
|
||||||
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::abs_rad()
|
|
||||||
{
|
|
||||||
return GroveRotary::abs_deg() * M_PI / 180.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::rel_value()
|
|
||||||
{
|
|
||||||
return GroveRotary::abs_value() - 512.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::rel_deg()
|
|
||||||
{
|
|
||||||
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveRotary::rel_rad()
|
|
||||||
{
|
|
||||||
return GroveRotary::rel_deg() * M_PI / 180.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveSlide ////
|
|
||||||
|
|
||||||
GroveSlide::GroveSlide(unsigned int pin, float ref_voltage)
|
|
||||||
{
|
|
||||||
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_aio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_ref_voltage = ref_voltage;
|
|
||||||
m_name = "Slide Potentiometer";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveSlide::~GroveSlide()
|
|
||||||
{
|
|
||||||
mraa_aio_close(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveSlide::raw_value()
|
|
||||||
{
|
|
||||||
return (float) mraa_aio_read(m_aio);
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveSlide::voltage_value()
|
|
||||||
{
|
|
||||||
// conversion to Volts
|
|
||||||
float a = GroveSlide::raw_value();
|
|
||||||
a = m_ref_voltage * a / 1023.0 ;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GroveSlide::ref_voltage()
|
|
||||||
{
|
|
||||||
return m_ref_voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
//// GroveButton ////
|
|
||||||
|
|
||||||
GroveButton::GroveButton(unsigned int pin)
|
|
||||||
{
|
|
||||||
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_gpio_init() failed, invalid pin?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
|
|
||||||
m_name = "Button Sensor";
|
|
||||||
}
|
|
||||||
|
|
||||||
GroveButton::~GroveButton()
|
|
||||||
{
|
|
||||||
mraa_gpio_close(m_gpio);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GroveButton::name()
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GroveButton::value()
|
|
||||||
{
|
|
||||||
return mraa_gpio_read(m_gpio);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef JAVACALLBACK
|
|
||||||
void GroveButton::installISR(mraa::Edge level, jobject runnable)
|
|
||||||
{
|
|
||||||
installISR(level, mraa_java_isr_callback, runnable);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg)
|
|
||||||
{
|
|
||||||
if (m_isrInstalled)
|
|
||||||
uninstallISR();
|
|
||||||
|
|
||||||
// install our interrupt handler
|
|
||||||
mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg);
|
|
||||||
m_isrInstalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GroveButton::uninstallISR()
|
|
||||||
{
|
|
||||||
mraa_gpio_isr_exit(m_gpio);
|
|
||||||
m_isrInstalled = false;
|
|
||||||
}
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Contributions: Sarah Knepper <sarah.knepper@intel.com>
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -25,389 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <grovebutton.hpp>
|
||||||
#include <mraa/aio.hpp>
|
#include <groveled.hpp>
|
||||||
#include <mraa/gpio.hpp>
|
#include <grovelight.hpp>
|
||||||
|
#include <groverelay.hpp>
|
||||||
namespace upm {
|
#include <groverotary.hpp>
|
||||||
|
#include <groveslide.hpp>
|
||||||
/**
|
#include <grovetemp.hpp>
|
||||||
* @brief Generic library for basic Grove sensors
|
|
||||||
* @defgroup grove libupm-grove
|
|
||||||
* @ingroup seeed gpio pwm ainput button led light relay temp touch gsk eak hak
|
|
||||||
*/
|
|
||||||
class Grove {
|
|
||||||
public:
|
|
||||||
virtual ~Grove() {}
|
|
||||||
std::string name()
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
std::string m_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove LED
|
|
||||||
*
|
|
||||||
* UPM module for the Grove LED (or other similar light-emitting diodes).
|
|
||||||
* An LED is a small lightbulb that emits light in
|
|
||||||
* response to a small current. The longer wire of an LED connects
|
|
||||||
* to the positive seat (anode); the shorter wire connects to the
|
|
||||||
* negative seat (cathode). The flat side of the bulb corresponds
|
|
||||||
* to the cathode, while the rounded side corresponds to the anode.
|
|
||||||
*
|
|
||||||
* @ingroup grove gpio
|
|
||||||
* @snippet groveled.cxx Interesting
|
|
||||||
* @snippet groveled-multi.cxx Interesting
|
|
||||||
* @image html groveled.jpg
|
|
||||||
*/
|
|
||||||
class GroveLed: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove LED constructor
|
|
||||||
*
|
|
||||||
* @param gpio Pin to use
|
|
||||||
*/
|
|
||||||
GroveLed(int pin);
|
|
||||||
/**
|
|
||||||
* Grove LED destructor
|
|
||||||
*/
|
|
||||||
~GroveLed();
|
|
||||||
/**
|
|
||||||
* Turns the LED on or off, depending on the value.
|
|
||||||
* If the value is positive (greater than or equal
|
|
||||||
* to 1), the LED is turned on. Otherwise, for 0
|
|
||||||
* or negative values, the LED is turned off.
|
|
||||||
*
|
|
||||||
* @param value Tells the LED to turn on (for values >=1)
|
|
||||||
* or off (for values <1)
|
|
||||||
*
|
|
||||||
* @return 0 if successful, non-zero otherwise
|
|
||||||
*/
|
|
||||||
mraa_result_t write(int value);
|
|
||||||
/**
|
|
||||||
* Turns the LED off
|
|
||||||
*
|
|
||||||
* @return 0 if successful, non-zero otherwise
|
|
||||||
*/
|
|
||||||
mraa_result_t off();
|
|
||||||
/**
|
|
||||||
* Turns the LED on
|
|
||||||
*
|
|
||||||
* @return 0 if successful, non-zero otherwise
|
|
||||||
*/
|
|
||||||
mraa_result_t on();
|
|
||||||
private:
|
|
||||||
mraa_gpio_context m_gpio;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Relay
|
|
||||||
*
|
|
||||||
* UPM module for the Grove relay switch. Grove relay is a
|
|
||||||
* digital normally-open switch that uses low voltage or current to
|
|
||||||
* control a higher voltage and/or higher current. When closed,
|
|
||||||
* the indicator LED lights up and current is allowed to flow.
|
|
||||||
*
|
|
||||||
* @ingroup grove gpio
|
|
||||||
* @snippet groverelay.cxx Interesting
|
|
||||||
* @image html groverelay.jpg
|
|
||||||
*/
|
|
||||||
class GroveRelay: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove relay constructor
|
|
||||||
*
|
|
||||||
* @param gpio Pin to use
|
|
||||||
*/
|
|
||||||
GroveRelay(unsigned int pin);
|
|
||||||
/**
|
|
||||||
* Grove relay destructor
|
|
||||||
*/
|
|
||||||
~GroveRelay();
|
|
||||||
/**
|
|
||||||
* Sets the relay switch to on (closed). This allows current
|
|
||||||
* to flow and lights up the indicator LED.
|
|
||||||
*
|
|
||||||
* @return 0 if successful, non-zero otherwise
|
|
||||||
*/
|
|
||||||
mraa_result_t on();
|
|
||||||
/**
|
|
||||||
* Sets the relay switch to off (open). This stops current
|
|
||||||
* from flowing and the indicator LED is not lit.
|
|
||||||
*
|
|
||||||
* @return 0 if successful, non-zero otherwise
|
|
||||||
*/
|
|
||||||
mraa_result_t off();
|
|
||||||
/**
|
|
||||||
* Defines whether the relay switch is closed.
|
|
||||||
*
|
|
||||||
* @return True if the switch is on (closed), false otherwise
|
|
||||||
*/
|
|
||||||
bool isOn();
|
|
||||||
/**
|
|
||||||
* Defines whether the relay switch is open.
|
|
||||||
*
|
|
||||||
* @return True if the switch is off (open), false otherwise
|
|
||||||
*/
|
|
||||||
bool isOff();
|
|
||||||
private:
|
|
||||||
mraa_gpio_context m_gpio;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Temperature Sensor
|
|
||||||
*
|
|
||||||
* Basic UPM module for the Grove temperature sensor on analog
|
|
||||||
*
|
|
||||||
* @ingroup grove analog
|
|
||||||
* @snippet grovetemp.cxx Interesting
|
|
||||||
* @image html grovetemp.jpg
|
|
||||||
*/
|
|
||||||
class GroveTemp: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove analog temperature sensor constructor
|
|
||||||
*
|
|
||||||
* @param pin Analog pin to use
|
|
||||||
* @param scale Scaling factor for raw analog value from the ADC,
|
|
||||||
* useful for mixed 3.3V/5V boards
|
|
||||||
*/
|
|
||||||
GroveTemp(unsigned int pin, float scale = 1.0);
|
|
||||||
/**
|
|
||||||
* GroveTemp destructor
|
|
||||||
*/
|
|
||||||
~GroveTemp();
|
|
||||||
/**
|
|
||||||
* Gets the raw value from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Raw value from the ADC
|
|
||||||
*/
|
|
||||||
float raw_value();
|
|
||||||
/**
|
|
||||||
* Gets the temperature in Celsius from the sensor
|
|
||||||
*
|
|
||||||
* @return Normalized temperature in Celsius
|
|
||||||
*/
|
|
||||||
int value();
|
|
||||||
private:
|
|
||||||
mraa_aio_context m_aio;
|
|
||||||
float m_scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Light Sensor
|
|
||||||
*
|
|
||||||
* The Grove light sensor detects the intensity of the ambient light.
|
|
||||||
* As the light intensity of the environment increases, the resistance
|
|
||||||
* of the sensor decreases. This means the raw value from the
|
|
||||||
* analog pin is greater in bright light and smaller in the dark.
|
|
||||||
* An approximate lux value can also be returned.
|
|
||||||
*
|
|
||||||
* @ingroup grove analog
|
|
||||||
* @snippet grovelight.cxx Interesting
|
|
||||||
* @image html grovelight.jpg
|
|
||||||
*/
|
|
||||||
class GroveLight: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove analog light sensor constructor
|
|
||||||
*
|
|
||||||
* @param pin Analog pin to use
|
|
||||||
*/
|
|
||||||
GroveLight(unsigned int pin);
|
|
||||||
/**
|
|
||||||
* GroveLight destructor
|
|
||||||
*/
|
|
||||||
~GroveLight();
|
|
||||||
/**
|
|
||||||
* Gets the raw value from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Raw value from the ADC
|
|
||||||
*/
|
|
||||||
float raw_value();
|
|
||||||
/**
|
|
||||||
* Gets an approximate light value, in lux, from the sensor
|
|
||||||
*
|
|
||||||
* @return Normalized light reading in lux
|
|
||||||
*/
|
|
||||||
int value();
|
|
||||||
private:
|
|
||||||
mraa_aio_context m_aio;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Rotary Angle Sensor (Knob)
|
|
||||||
*
|
|
||||||
* Basic UPM module for the Grove rotary angle sensor (knob) on analog. Provides
|
|
||||||
* a set of functions to read the absolute pin value, degrees or radians, and another set
|
|
||||||
* to do the same relative to the center of the knob range.
|
|
||||||
*
|
|
||||||
* @ingroup grove analog
|
|
||||||
* @snippet groverotary.cxx Interesting
|
|
||||||
* @image html groverotary.jpeg
|
|
||||||
*/
|
|
||||||
class GroveRotary: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove rotary angle sensor constructor
|
|
||||||
*
|
|
||||||
* @param pin Number of the analog pin to use
|
|
||||||
*/
|
|
||||||
GroveRotary(unsigned int pin);
|
|
||||||
/**
|
|
||||||
* GroveRotary destructor
|
|
||||||
*/
|
|
||||||
~GroveRotary();
|
|
||||||
/**
|
|
||||||
* Gets the absolute raw value from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Unsigned value from the ADC
|
|
||||||
*/
|
|
||||||
float abs_value();
|
|
||||||
/**
|
|
||||||
* Gets absolute raw degrees from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Unsigned degrees from the ADC
|
|
||||||
*/
|
|
||||||
float abs_deg();
|
|
||||||
/**
|
|
||||||
* Gets absolute raw radians from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Unsigned radians from the ADC
|
|
||||||
*/
|
|
||||||
float abs_rad();
|
|
||||||
/**
|
|
||||||
* Gets the relative value from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Signed value from the ADC
|
|
||||||
*/
|
|
||||||
float rel_value();
|
|
||||||
/**
|
|
||||||
* Gets relative degrees from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Signed degrees from the ADC
|
|
||||||
*/
|
|
||||||
float rel_deg();
|
|
||||||
/**
|
|
||||||
* Gets relative radians from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Signed radians from the ADC
|
|
||||||
*/
|
|
||||||
float rel_rad();
|
|
||||||
private:
|
|
||||||
mraa_aio_context m_aio;
|
|
||||||
static const int m_max_angle = 300;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Slide Potentiometer
|
|
||||||
*
|
|
||||||
* Basic UPM module for the Grove slide potentiometer on analog that
|
|
||||||
* returns either a raw value or a scaled voltage value.
|
|
||||||
*
|
|
||||||
* @ingroup grove analog
|
|
||||||
* @snippet groveslide.cxx Interesting
|
|
||||||
* @image html groveslide.jpeg
|
|
||||||
*/
|
|
||||||
class GroveSlide: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove analog slide potentiometer constructor
|
|
||||||
*
|
|
||||||
* @param pin Number of the analog pin to use
|
|
||||||
*
|
|
||||||
* @param ref_voltage Reference voltage the board is set to, as a floating-point value; default is 5.0V
|
|
||||||
*/
|
|
||||||
GroveSlide(unsigned int pin, float ref_voltage = 5.0);
|
|
||||||
/**
|
|
||||||
* GroveSlide destructor
|
|
||||||
*/
|
|
||||||
~GroveSlide();
|
|
||||||
/**
|
|
||||||
* Gets the raw value from the AIO pin
|
|
||||||
*
|
|
||||||
* @return Raw value from the ADC
|
|
||||||
*/
|
|
||||||
float raw_value();
|
|
||||||
/**
|
|
||||||
* Gets the voltage value from the pin
|
|
||||||
*
|
|
||||||
* @return Voltage reading based on the reference voltage
|
|
||||||
*/
|
|
||||||
float voltage_value();
|
|
||||||
/**
|
|
||||||
* Gets the board's reference voltage passed on object initialization
|
|
||||||
*
|
|
||||||
* @return Reference voltage the class was set for
|
|
||||||
*/
|
|
||||||
float ref_voltage();
|
|
||||||
private:
|
|
||||||
mraa_aio_context m_aio;
|
|
||||||
float m_ref_voltage;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for the Grove Button
|
|
||||||
*
|
|
||||||
* Basic UPM module for the Grove button
|
|
||||||
*
|
|
||||||
* @ingroup grove gpio
|
|
||||||
* @snippet grovebutton.cxx Interesting
|
|
||||||
* @image html grovebutton.jpg
|
|
||||||
*/
|
|
||||||
class GroveButton: public Grove {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Grove button constructor
|
|
||||||
*
|
|
||||||
* @param gpio Pin to use
|
|
||||||
*/
|
|
||||||
GroveButton(unsigned int pin);
|
|
||||||
/**
|
|
||||||
* Grove button destructor
|
|
||||||
*/
|
|
||||||
~GroveButton();
|
|
||||||
/**
|
|
||||||
* Gets the name of the sensor
|
|
||||||
*
|
|
||||||
* @return Name of this sensor
|
|
||||||
*/
|
|
||||||
std::string name();
|
|
||||||
/**
|
|
||||||
* Gets the value from the GPIO pin
|
|
||||||
*
|
|
||||||
* @return Value from the GPIO pin
|
|
||||||
*/
|
|
||||||
int value();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Installs an interrupt service routine (ISR) to be called when
|
|
||||||
* the button is activated or deactivated.
|
|
||||||
*
|
|
||||||
* @param fptr Pointer to a function to be called on interrupt
|
|
||||||
* @param arg Pointer to an object to be supplied as an
|
|
||||||
* argument to the ISR.
|
|
||||||
*/
|
|
||||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
|
||||||
void installISR(mraa::Edge level, jobject runnable);
|
|
||||||
#else
|
|
||||||
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* Uninstalls the previously installed ISR
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void uninstallISR();
|
|
||||||
|
|
||||||
private:
|
|
||||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
|
||||||
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
|
|
||||||
#endif
|
|
||||||
bool m_isrInstalled;
|
|
||||||
std::string m_name;
|
|
||||||
mraa_gpio_context m_gpio;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
47
src/grove/grovebase.hpp
Normal file
47
src/grove/grovebase.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic library for basic Grove sensors
|
||||||
|
* @defgroup grove libupm-grove
|
||||||
|
* @ingroup seeed gpio pwm ainput button led light relay temp touch gsk eak hak
|
||||||
|
*/
|
||||||
|
class Grove {
|
||||||
|
public:
|
||||||
|
virtual ~Grove() {}
|
||||||
|
std::string name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
std::string m_name;
|
||||||
|
};
|
||||||
|
}
|
82
src/grove/grovebutton.cxx
Normal file
82
src/grove/grovebutton.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "grovebutton.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveButton::GroveButton(unsigned int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mraa_gpio_dir(m_gpio, MRAA_GPIO_IN);
|
||||||
|
m_name = "Button Sensor";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveButton::~GroveButton()
|
||||||
|
{
|
||||||
|
mraa_gpio_close(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GroveButton::name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GroveButton::value()
|
||||||
|
{
|
||||||
|
return mraa_gpio_read(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef JAVACALLBACK
|
||||||
|
void GroveButton::installISR(mraa::Edge level, jobject runnable)
|
||||||
|
{
|
||||||
|
installISR(level, mraa_java_isr_callback, runnable);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg)
|
||||||
|
{
|
||||||
|
if (m_isrInstalled)
|
||||||
|
uninstallISR();
|
||||||
|
|
||||||
|
// install our interrupt handler
|
||||||
|
mraa_gpio_isr(m_gpio, (mraa_gpio_edge_t) level, isr, arg);
|
||||||
|
m_isrInstalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveButton::uninstallISR()
|
||||||
|
{
|
||||||
|
mraa_gpio_isr_exit(m_gpio);
|
||||||
|
m_isrInstalled = false;
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor grovebutton
|
* @sensor grovebutton
|
||||||
@ -40,3 +49,56 @@
|
|||||||
* @image html grovebutton.jpg
|
* @image html grovebutton.jpg
|
||||||
* @snippet grovebutton.cxx Interesting
|
* @snippet grovebutton.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveButton: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove button constructor
|
||||||
|
*
|
||||||
|
* @param gpio Pin to use
|
||||||
|
*/
|
||||||
|
GroveButton(unsigned int pin);
|
||||||
|
/**
|
||||||
|
* Grove button destructor
|
||||||
|
*/
|
||||||
|
~GroveButton();
|
||||||
|
/**
|
||||||
|
* Gets the name of the sensor
|
||||||
|
*
|
||||||
|
* @return Name of this sensor
|
||||||
|
*/
|
||||||
|
std::string name();
|
||||||
|
/**
|
||||||
|
* Gets the value from the GPIO pin
|
||||||
|
*
|
||||||
|
* @return Value from the GPIO pin
|
||||||
|
*/
|
||||||
|
int value();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs an interrupt service routine (ISR) to be called when
|
||||||
|
* the button is activated or deactivated.
|
||||||
|
*
|
||||||
|
* @param fptr Pointer to a function to be called on interrupt
|
||||||
|
* @param arg Pointer to an object to be supplied as an
|
||||||
|
* argument to the ISR.
|
||||||
|
*/
|
||||||
|
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||||
|
void installISR(mraa::Edge level, jobject runnable);
|
||||||
|
#else
|
||||||
|
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Uninstalls the previously installed ISR
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void uninstallISR();
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||||
|
void installISR(mraa::Edge level, void (*isr)(void *), void *arg);
|
||||||
|
#endif
|
||||||
|
bool m_isrInstalled;
|
||||||
|
std::string m_name;
|
||||||
|
mraa_gpio_context m_gpio;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
67
src/grove/groveled.cxx
Normal file
67
src/grove/groveled.cxx
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "groveled.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveLed::GroveLed(int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||||
|
m_name = "LED Socket";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveLed::~GroveLed()
|
||||||
|
{
|
||||||
|
mraa_gpio_close(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_result_t GroveLed::write(int value)
|
||||||
|
{
|
||||||
|
if (value >= 1) {
|
||||||
|
return mraa_gpio_write(m_gpio, 1);
|
||||||
|
}
|
||||||
|
return mraa_gpio_write(m_gpio, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_result_t GroveLed::on()
|
||||||
|
{
|
||||||
|
return write(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_result_t GroveLed::off()
|
||||||
|
{
|
||||||
|
return write(0);
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor groveled
|
* @sensor groveled
|
||||||
@ -35,7 +44,7 @@
|
|||||||
* @brief API for the Grove LED
|
* @brief API for the Grove LED
|
||||||
*
|
*
|
||||||
* UPM module for the Grove LED (or other similar light-emitting diodes).
|
* UPM module for the Grove LED (or other similar light-emitting diodes).
|
||||||
* An LED is a small lightbulb that emits light in
|
* An LED is a small lightbulb that emits light in
|
||||||
* response to a small current. The longer wire of an LED connects
|
* response to a small current. The longer wire of an LED connects
|
||||||
* to the positive seat (anode); the shorter wire connects to the
|
* to the positive seat (anode); the shorter wire connects to the
|
||||||
* negative seat (cathode). The flat side of the bulb corresponds
|
* negative seat (cathode). The flat side of the bulb corresponds
|
||||||
@ -45,4 +54,43 @@
|
|||||||
* @snippet groveled.cxx Interesting
|
* @snippet groveled.cxx Interesting
|
||||||
* @snippet groveled-multi.cxx Interesting
|
* @snippet groveled-multi.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveLed: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove LED constructor
|
||||||
|
*
|
||||||
|
* @param gpio Pin to use
|
||||||
|
*/
|
||||||
|
GroveLed(int pin);
|
||||||
|
/**
|
||||||
|
* Grove LED destructor
|
||||||
|
*/
|
||||||
|
~GroveLed();
|
||||||
|
/**
|
||||||
|
* Turns the LED on or off, depending on the value.
|
||||||
|
* If the value is positive (greater than or equal
|
||||||
|
* to 1), the LED is turned on. Otherwise, for 0
|
||||||
|
* or negative values, the LED is turned off.
|
||||||
|
*
|
||||||
|
* @param value Tells the LED to turn on (for values >=1)
|
||||||
|
* or off (for values <1)
|
||||||
|
*
|
||||||
|
* @return 0 if successful, non-zero otherwise
|
||||||
|
*/
|
||||||
|
mraa_result_t write(int value);
|
||||||
|
/**
|
||||||
|
* Turns the LED off
|
||||||
|
*
|
||||||
|
* @return 0 if successful, non-zero otherwise
|
||||||
|
*/
|
||||||
|
mraa_result_t off();
|
||||||
|
/**
|
||||||
|
* Turns the LED on
|
||||||
|
*
|
||||||
|
* @return 0 if successful, non-zero otherwise
|
||||||
|
*/
|
||||||
|
mraa_result_t on();
|
||||||
|
private:
|
||||||
|
mraa_gpio_context m_gpio;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
63
src/grove/grovelight.cxx
Normal file
63
src/grove/grovelight.cxx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "grovelight.hpp"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveLight::GroveLight(unsigned int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_name = "Light Sensor";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveLight::~GroveLight()
|
||||||
|
{
|
||||||
|
mraa_aio_close(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GroveLight::value()
|
||||||
|
{
|
||||||
|
// rough conversion to lux, using formula from Grove Starter Kit booklet
|
||||||
|
float a = (float) mraa_aio_read(m_aio);
|
||||||
|
if (a == -1.0) return -1;
|
||||||
|
a = 10000.0/pow(((1023.0-a)*10.0/a)*15.0,4.0/3.0);
|
||||||
|
return (int) round(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveLight::raw_value()
|
||||||
|
{
|
||||||
|
return (float) mraa_aio_read(m_aio);
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/aio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor grovelight
|
* @sensor grovelight
|
||||||
@ -43,4 +52,31 @@
|
|||||||
* @image html grovelight.jpg
|
* @image html grovelight.jpg
|
||||||
* @snippet grovelight.cxx Interesting
|
* @snippet grovelight.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveLight: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove analog light sensor constructor
|
||||||
|
*
|
||||||
|
* @param pin Analog pin to use
|
||||||
|
*/
|
||||||
|
GroveLight(unsigned int pin);
|
||||||
|
/**
|
||||||
|
* GroveLight destructor
|
||||||
|
*/
|
||||||
|
~GroveLight();
|
||||||
|
/**
|
||||||
|
* Gets the raw value from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Raw value from the ADC
|
||||||
|
*/
|
||||||
|
float raw_value();
|
||||||
|
/**
|
||||||
|
* Gets an approximate light value, in lux, from the sensor
|
||||||
|
*
|
||||||
|
* @return Normalized light reading in lux
|
||||||
|
*/
|
||||||
|
int value();
|
||||||
|
private:
|
||||||
|
mraa_aio_context m_aio;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
69
src/grove/groverelay.cxx
Normal file
69
src/grove/groverelay.cxx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "groverelay.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveRelay::GroveRelay(unsigned int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_gpio = mraa_gpio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||||
|
m_name = "Relay Switch";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveRelay::~GroveRelay()
|
||||||
|
{
|
||||||
|
mraa_gpio_close(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_result_t GroveRelay::on()
|
||||||
|
{
|
||||||
|
return mraa_gpio_write(m_gpio, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa_result_t GroveRelay::off()
|
||||||
|
{
|
||||||
|
return mraa_gpio_write(m_gpio, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GroveRelay::isOn()
|
||||||
|
{
|
||||||
|
return mraa_gpio_read(m_gpio) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GroveRelay::isOff()
|
||||||
|
{
|
||||||
|
return mraa_gpio_read(m_gpio) == 0;
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor groverelay
|
* @sensor groverelay
|
||||||
@ -35,11 +44,52 @@
|
|||||||
* @brief API for the Grove Relay
|
* @brief API for the Grove Relay
|
||||||
*
|
*
|
||||||
* UPM module for the Grove relay switch. The Grove relay is a
|
* UPM module for the Grove relay switch. The Grove relay is a
|
||||||
* digital normally-open switch that uses low voltage or current to
|
* digital normally-open switch that uses low voltage or current to
|
||||||
* control a higher voltage and/or higher current. When closed,
|
* control a higher voltage and/or higher current. When closed,
|
||||||
* the indicator LED lights up and current is allowed to flow.
|
* the indicator LED lights up and current is allowed to flow.
|
||||||
*
|
*
|
||||||
* @image html groverelay.jpg
|
* @image html groverelay.jpg
|
||||||
* @snippet groverelay.cxx Interesting
|
* @snippet groverelay.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveRelay: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove relay constructor
|
||||||
|
*
|
||||||
|
* @param gpio Pin to use
|
||||||
|
*/
|
||||||
|
GroveRelay(unsigned int pin);
|
||||||
|
/**
|
||||||
|
* Grove relay destructor
|
||||||
|
*/
|
||||||
|
~GroveRelay();
|
||||||
|
/**
|
||||||
|
* Sets the relay switch to on (closed). This allows current
|
||||||
|
* to flow and lights up the indicator LED.
|
||||||
|
*
|
||||||
|
* @return 0 if successful, non-zero otherwise
|
||||||
|
*/
|
||||||
|
mraa_result_t on();
|
||||||
|
/**
|
||||||
|
* Sets the relay switch to off (open). This stops current
|
||||||
|
* from flowing and the indicator LED is not lit.
|
||||||
|
*
|
||||||
|
* @return 0 if successful, non-zero otherwise
|
||||||
|
*/
|
||||||
|
mraa_result_t off();
|
||||||
|
/**
|
||||||
|
* Defines whether the relay switch is closed.
|
||||||
|
*
|
||||||
|
* @return True if the switch is on (closed), false otherwise
|
||||||
|
*/
|
||||||
|
bool isOn();
|
||||||
|
/**
|
||||||
|
* Defines whether the relay switch is open.
|
||||||
|
*
|
||||||
|
* @return True if the switch is off (open), false otherwise
|
||||||
|
*/
|
||||||
|
bool isOff();
|
||||||
|
private:
|
||||||
|
mraa_gpio_context m_gpio;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
79
src/grove/groverotary.cxx
Normal file
79
src/grove/groverotary.cxx
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "groverotary.hpp"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveRotary::GroveRotary(unsigned int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_name = "Rotary Angle Sensor";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveRotary::~GroveRotary()
|
||||||
|
{
|
||||||
|
mraa_aio_close(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::abs_value()
|
||||||
|
{
|
||||||
|
return (float) mraa_aio_read(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::abs_deg()
|
||||||
|
{
|
||||||
|
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::abs_rad()
|
||||||
|
{
|
||||||
|
return GroveRotary::abs_deg() * M_PI / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::rel_value()
|
||||||
|
{
|
||||||
|
return GroveRotary::abs_value() - 512.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::rel_deg()
|
||||||
|
{
|
||||||
|
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveRotary::rel_rad()
|
||||||
|
{
|
||||||
|
return GroveRotary::rel_deg() * M_PI / 180.0;
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/aio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor groverotary
|
* @sensor groverotary
|
||||||
@ -42,4 +51,56 @@
|
|||||||
* @image html groverotary.jpeg
|
* @image html groverotary.jpeg
|
||||||
* @snippet groverotary.cxx Interesting
|
* @snippet groverotary.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveRotary: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove rotary angle sensor constructor
|
||||||
|
*
|
||||||
|
* @param pin Number of the analog pin to use
|
||||||
|
*/
|
||||||
|
GroveRotary(unsigned int pin);
|
||||||
|
/**
|
||||||
|
* GroveRotary destructor
|
||||||
|
*/
|
||||||
|
~GroveRotary();
|
||||||
|
/**
|
||||||
|
* Gets the absolute raw value from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Unsigned value from the ADC
|
||||||
|
*/
|
||||||
|
float abs_value();
|
||||||
|
/**
|
||||||
|
* Gets absolute raw degrees from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Unsigned degrees from the ADC
|
||||||
|
*/
|
||||||
|
float abs_deg();
|
||||||
|
/**
|
||||||
|
* Gets absolute raw radians from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Unsigned radians from the ADC
|
||||||
|
*/
|
||||||
|
float abs_rad();
|
||||||
|
/**
|
||||||
|
* Gets the relative value from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Signed value from the ADC
|
||||||
|
*/
|
||||||
|
float rel_value();
|
||||||
|
/**
|
||||||
|
* Gets relative degrees from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Signed degrees from the ADC
|
||||||
|
*/
|
||||||
|
float rel_deg();
|
||||||
|
/**
|
||||||
|
* Gets relative radians from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Signed radians from the ADC
|
||||||
|
*/
|
||||||
|
float rel_rad();
|
||||||
|
private:
|
||||||
|
mraa_aio_context m_aio;
|
||||||
|
static const int m_max_angle = 300;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
68
src/grove/groveslide.cxx
Normal file
68
src/grove/groveslide.cxx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "groveslide.hpp"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveSlide::GroveSlide(unsigned int pin, float ref_voltage)
|
||||||
|
{
|
||||||
|
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_ref_voltage = ref_voltage;
|
||||||
|
m_name = "Slide Potentiometer";
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveSlide::~GroveSlide()
|
||||||
|
{
|
||||||
|
mraa_aio_close(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveSlide::raw_value()
|
||||||
|
{
|
||||||
|
return (float) mraa_aio_read(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveSlide::voltage_value()
|
||||||
|
{
|
||||||
|
// conversion to Volts
|
||||||
|
float a = GroveSlide::raw_value();
|
||||||
|
a = m_ref_voltage * a / 1023.0 ;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveSlide::ref_voltage()
|
||||||
|
{
|
||||||
|
return m_ref_voltage;
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/aio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor groveslide
|
* @sensor groveslide
|
||||||
@ -39,4 +48,40 @@
|
|||||||
* @image html groveslide.jpeg
|
* @image html groveslide.jpeg
|
||||||
* @snippet groveslide.cxx Interesting
|
* @snippet groveslide.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveSlide: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove analog slide potentiometer constructor
|
||||||
|
*
|
||||||
|
* @param pin Number of the analog pin to use
|
||||||
|
*
|
||||||
|
* @param ref_voltage Reference voltage the board is set to, as a floating-point value; default is 5.0V
|
||||||
|
*/
|
||||||
|
GroveSlide(unsigned int pin, float ref_voltage = 5.0);
|
||||||
|
/**
|
||||||
|
* GroveSlide destructor
|
||||||
|
*/
|
||||||
|
~GroveSlide();
|
||||||
|
/**
|
||||||
|
* Gets the raw value from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Raw value from the ADC
|
||||||
|
*/
|
||||||
|
float raw_value();
|
||||||
|
/**
|
||||||
|
* Gets the voltage value from the pin
|
||||||
|
*
|
||||||
|
* @return Voltage reading based on the reference voltage
|
||||||
|
*/
|
||||||
|
float voltage_value();
|
||||||
|
/**
|
||||||
|
* Gets the board's reference voltage passed on object initialization
|
||||||
|
*
|
||||||
|
* @return Reference voltage the class was set for
|
||||||
|
*/
|
||||||
|
float ref_voltage();
|
||||||
|
private:
|
||||||
|
mraa_aio_context m_aio;
|
||||||
|
float m_ref_voltage;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
68
src/grove/grovetemp.cxx
Normal file
68
src/grove/grovetemp.cxx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "grovetemp.hpp"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveTemp::GroveTemp(unsigned int pin, float scale, int r0, int b)
|
||||||
|
{
|
||||||
|
if ( !(m_aio = mraa_aio_init(pin)) ) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_aio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_name = "Temperature Sensor";
|
||||||
|
m_scale = scale;
|
||||||
|
m_r0 = r0;
|
||||||
|
m_b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveTemp::~GroveTemp()
|
||||||
|
{
|
||||||
|
mraa_aio_close(m_aio);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GroveTemp::value ()
|
||||||
|
{
|
||||||
|
float a = (float) mraa_aio_read(m_aio);
|
||||||
|
if (a == -1.0) return -1;
|
||||||
|
// Apply scale factor after error check
|
||||||
|
a *= m_scale;
|
||||||
|
float r = (float)(1023.0-a)*(float)m_r0/a;
|
||||||
|
float t = 1.0/(log(r/(float)m_r0)/(float)m_b + 1.0/298.15)-273.15;
|
||||||
|
return (int) round(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
float GroveTemp::raw_value()
|
||||||
|
{
|
||||||
|
return (float) mraa_aio_read(m_aio);
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Place-holder Header for Documentation and future API change
|
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
*
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
* Sarah Knepper <sarah.knepper@intel.com>
|
||||||
|
* Copyright (c) 2014 - 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -22,7 +23,15 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mraa/aio.hpp>
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @library grove
|
* @library grove
|
||||||
* @sensor grovetemp
|
* @sensor grovetemp
|
||||||
@ -34,9 +43,50 @@
|
|||||||
*
|
*
|
||||||
* @brief API for the Grove Temperature Sensor
|
* @brief API for the Grove Temperature Sensor
|
||||||
*
|
*
|
||||||
* Basic UPM module for the Grove temperature sensor on analog
|
* Basic UPM module for the Grove temperature sensor on analog. This sensor
|
||||||
|
* uses a thermistor to measure ambient temperature. The conversion formula has
|
||||||
|
* been updated to work with versions 1.1 and 1.2 of the sensor. For the older
|
||||||
|
* v1.0 sensor you will have to specify R0 and B values when initializing the
|
||||||
|
* device. The range of this sensor is -40 to 125 C and accuracy is +/- 1.5 C.
|
||||||
*
|
*
|
||||||
* @image html grovetemp.jpg
|
* @image html grovetemp.jpg
|
||||||
* @snippet grovetemp.cxx Interesting
|
* @snippet grovetemp.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
class GroveTemp: public Grove {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove analog temperature sensor constructor
|
||||||
|
*
|
||||||
|
* @param pin Analog pin to use
|
||||||
|
* @param scale Scaling factor for raw analog value from the ADC,
|
||||||
|
* useful for mixed 3.3V/5V boards, default 1.0
|
||||||
|
* @param r0 zero power resistance, this is 100K (default) for
|
||||||
|
* v1.1-v1.2 and 10K for v1.0 of the sensor
|
||||||
|
* @param b thermistor nominal B constant, this is 4275 (default) for
|
||||||
|
* v1.1-v1.2 and 3975 for v1.0 of the sensor
|
||||||
|
*/
|
||||||
|
GroveTemp(unsigned int pin, float scale = 1.0, int r0 = 100000, int b = 4275);
|
||||||
|
/**
|
||||||
|
* GroveTemp destructor
|
||||||
|
*/
|
||||||
|
~GroveTemp();
|
||||||
|
/**
|
||||||
|
* Gets the raw value from the AIO pin
|
||||||
|
*
|
||||||
|
* @return Raw value from the ADC
|
||||||
|
*/
|
||||||
|
float raw_value();
|
||||||
|
/**
|
||||||
|
* Gets the temperature in Celsius from the sensor
|
||||||
|
*
|
||||||
|
* @return Normalized temperature in Celsius
|
||||||
|
*/
|
||||||
|
int value();
|
||||||
|
private:
|
||||||
|
mraa_aio_context m_aio;
|
||||||
|
float m_scale;
|
||||||
|
int m_r0;
|
||||||
|
int m_b;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -4,11 +4,50 @@
|
|||||||
|
|
||||||
%apply int {mraa::Edge}
|
%apply int {mraa::Edge}
|
||||||
|
|
||||||
|
%include "grove.hpp"
|
||||||
%{
|
%{
|
||||||
#include "grove.hpp"
|
#include "grove.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "grove.hpp"
|
%include "grovebase.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovebutton.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebutton.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveled.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveled.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovelight.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovelight.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverelay.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverelay.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverotary.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverotary.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveslide.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveslide.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovetemp.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovetemp.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
%pragma(java) jniclasscode=%{
|
||||||
static {
|
static {
|
||||||
@ -20,4 +59,3 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -1,8 +1,47 @@
|
|||||||
%module jsupm_grove
|
%module jsupm_grove
|
||||||
%include "../upm.i"
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%include "grove.hpp"
|
||||||
%{
|
%{
|
||||||
#include "grove.hpp"
|
#include "grove.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "grove.hpp"
|
%include "grovebase.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovebutton.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebutton.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveled.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveled.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovelight.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovelight.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverelay.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverelay.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverotary.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverotary.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveslide.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveslide.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovetemp.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovetemp.hpp"
|
||||||
|
%}
|
||||||
|
@ -5,11 +5,47 @@
|
|||||||
|
|
||||||
%feature("autodoc", "3");
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
%include "grove_doc.i"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
%include "grove.hpp"
|
%include "grove.hpp"
|
||||||
%{
|
%{
|
||||||
#include "grove.hpp"
|
#include "grove.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%include "grovebase.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebase.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovebutton.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovebutton.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveled.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveled.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovelight.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovelight.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverelay.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverelay.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groverotary.hpp"
|
||||||
|
%{
|
||||||
|
#include "groverotary.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveslide.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveslide.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovetemp.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovetemp.hpp"
|
||||||
|
%}
|
||||||
|
@ -38,7 +38,7 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* @brief Grove ultrasonic sensor library
|
* @brief Grove ultrasonic sensor library
|
||||||
* @defgroup groveultrasonic libupm-groveultrasonic
|
* @defgroup groveultrasonic libupm-groveultrasonic
|
||||||
* @ingroup grove gpio sound
|
* @ingroup seeed gpio sound
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,15 +9,13 @@ if (MODBUS_FOUND)
|
|||||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||||
upm_module_init()
|
upm_module_init()
|
||||||
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
|
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGNODE)
|
||||||
if (BUILDSWIGNODE)
|
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
|
||||||
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
|
endif()
|
||||||
endif()
|
if (BUILDSWIGPYTHON)
|
||||||
if (BUILDSWIGPYTHON)
|
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
|
||||||
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
|
endif()
|
||||||
endif()
|
if (BUILDSWIGJAVA)
|
||||||
if (BUILDSWIGJAVA)
|
swig_link_libraries (javaupm_${libname} ${MODBUS_LIBRARIES})
|
||||||
swig_link_libraries (javaupm_${libname} ${MODBUS_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
// conversion from celsius to fahrenheit
|
||||||
|
|
||||||
static float c2f(float c)
|
static float c2f(float c)
|
||||||
{
|
{
|
||||||
|
@ -125,9 +125,9 @@ namespace upm {
|
|||||||
* constructor) then this function will always return 0C/32F.
|
* constructor) then this function will always return 0C/32F.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return the temperature in degrees
|
* @param fahrenheit true to return the temperature in degrees
|
||||||
* fahrenheit, false to return the temperature in degrees celcius.
|
* fahrenheit, false to return the temperature in degrees celsius.
|
||||||
* The default is false (degrees Celcius).
|
* The default is false (degrees Celsius).
|
||||||
* @return The last temperature reading in Celcius or Fahrenheit
|
* @return The last temperature reading in Celsius or Fahrenheit
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ namespace upm {
|
|||||||
// does this sensor support temperature reporting?
|
// does this sensor support temperature reporting?
|
||||||
bool m_hasTemp;
|
bool m_hasTemp;
|
||||||
|
|
||||||
// in Celcius
|
// in Celsius
|
||||||
float m_temperature;
|
float m_temperature;
|
||||||
|
|
||||||
float m_humidity;
|
float m_humidity;
|
||||||
|
@ -9,12 +9,10 @@ if (MODBUS_FOUND)
|
|||||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||||
upm_module_init()
|
upm_module_init()
|
||||||
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
|
target_link_libraries(${libname} ${MODBUS_LIBRARIES})
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGNODE)
|
||||||
if (BUILDSWIGNODE)
|
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
|
||||||
swig_link_libraries (jsupm_${libname} ${MODBUS_LIBRARIES})
|
endif()
|
||||||
endif()
|
if (BUILDSWIGPYTHON)
|
||||||
if (BUILDSWIGPYTHON)
|
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
|
||||||
swig_link_libraries (pyupm_${libname} ${MODBUS_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// conversion from fahrenheit to celcius and back
|
// conversion from fahrenheit to celsius and back
|
||||||
|
|
||||||
static float f2c(float f)
|
static float f2c(float f)
|
||||||
{
|
{
|
||||||
@ -107,9 +107,9 @@ HWXPXX::HWXPXX(std::string device, int address, int baud, int bits, char parity,
|
|||||||
|
|
||||||
// temp scale
|
// temp scale
|
||||||
if (coils[0])
|
if (coils[0])
|
||||||
m_isCelcius = false;
|
m_isCelsius = false;
|
||||||
else
|
else
|
||||||
m_isCelcius = true;
|
m_isCelsius = true;
|
||||||
|
|
||||||
// current override switch status
|
// current override switch status
|
||||||
m_override = ((coils[1]) ? true : false);
|
m_override = ((coils[1]) ? true : false);
|
||||||
@ -243,7 +243,7 @@ void HWXPXX::update()
|
|||||||
// temperature, we always store as C
|
// temperature, we always store as C
|
||||||
float tmpF = float((int16_t)data[1]) / 10.0;
|
float tmpF = float((int16_t)data[1]) / 10.0;
|
||||||
|
|
||||||
if (m_isCelcius)
|
if (m_isCelsius)
|
||||||
m_temperature = tmpF;
|
m_temperature = tmpF;
|
||||||
else
|
else
|
||||||
m_temperature = f2c(tmpF);
|
m_temperature = f2c(tmpF);
|
||||||
@ -319,11 +319,11 @@ void HWXPXX::setTemperatureScale(bool fahrenheit)
|
|||||||
{
|
{
|
||||||
writeCoil(COIL_TEMP_SCALE, fahrenheit);
|
writeCoil(COIL_TEMP_SCALE, fahrenheit);
|
||||||
|
|
||||||
// now re-read and set m_isCelcius properly
|
// now re-read and set m_isCelsius properly
|
||||||
if (readCoil(COIL_TEMP_SCALE))
|
if (readCoil(COIL_TEMP_SCALE))
|
||||||
m_isCelcius = false;
|
m_isCelsius = false;
|
||||||
else
|
else
|
||||||
m_isCelcius = true;
|
m_isCelsius = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string HWXPXX::getSlaveID()
|
string HWXPXX::getSlaveID()
|
||||||
@ -361,11 +361,11 @@ void HWXPXX::setSlaveAddress(int addr)
|
|||||||
": modbus_set_slave() failed");
|
": modbus_set_slave() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// now re-read and set m_isCelcius properly
|
// now re-read and set m_isCelsius properly
|
||||||
if (readCoil(COIL_TEMP_SCALE))
|
if (readCoil(COIL_TEMP_SCALE))
|
||||||
m_isCelcius = false;
|
m_isCelsius = false;
|
||||||
else
|
else
|
||||||
m_isCelcius = true;
|
m_isCelsius = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWXPXX::setDebug(bool enable)
|
void HWXPXX::setDebug(bool enable)
|
||||||
|
@ -124,9 +124,9 @@ namespace upm {
|
|||||||
* the scale the device is operating in natively.
|
* the scale the device is operating in natively.
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to return the temperature in degrees
|
* @param fahrenheit true to return the temperature in degrees
|
||||||
* fahrenheit, false to return the temperature in degrees celcius.
|
* fahrenheit, false to return the temperature in degrees celsius.
|
||||||
* The default is false (degrees Celcius).
|
* The default is false (degrees Celsius).
|
||||||
* @return The last temperature reading in Celcius or Fahrenheit
|
* @return The last temperature reading in Celsius or Fahrenheit
|
||||||
*/
|
*/
|
||||||
float getTemperature(bool fahrenheit=false);
|
float getTemperature(bool fahrenheit=false);
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* Return the current temperature offset stored on the device.
|
* Return the current temperature offset stored on the device.
|
||||||
* This is a value between -50 and +50, specified in tenths of a
|
* This is a value between -50 and +50, specified in tenths of a
|
||||||
* degree in whatever scale (Celcius or Fahrenheit) is in use.
|
* degree in whatever scale (Celsius or Fahrenheit) is in use.
|
||||||
* This offset is applied to the returned temperature reading by the
|
* This offset is applied to the returned temperature reading by the
|
||||||
* device.
|
* device.
|
||||||
*
|
*
|
||||||
@ -194,7 +194,7 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* Set the stored temperature offset on the device. This is a
|
* Set the stored temperature offset on the device. This is a
|
||||||
* value between -50 and +50, specified in tenths of a degree in
|
* value between -50 and +50, specified in tenths of a degree in
|
||||||
* what ever scale (Celcius or Fahrenheit) is in use. This offset
|
* what ever scale (Celsius or Fahrenheit) is in use. This offset
|
||||||
* is applied to the returned temperature reading by the device.
|
* is applied to the returned temperature reading by the device.
|
||||||
*
|
*
|
||||||
* @param offset Offset in tenths of a degree with a range of -50 to +50
|
* @param offset Offset in tenths of a degree with a range of -50 to +50
|
||||||
@ -216,10 +216,10 @@ namespace upm {
|
|||||||
* detects this setting automatically and adjusts itself
|
* detects this setting automatically and adjusts itself
|
||||||
* accordingly, so this is generally never needed. It is used to
|
* accordingly, so this is generally never needed. It is used to
|
||||||
* set the native reporting scale of the temperature either in
|
* set the native reporting scale of the temperature either in
|
||||||
* degrees Celcius or Fahrenheit. Its setting will not affect
|
* degrees Celsius or Fahrenheit. Its setting will not affect
|
||||||
* the operation of getTemperature().
|
* the operation of getTemperature().
|
||||||
*
|
*
|
||||||
* @param fahrenheit true to set Fahrenheit, false to set Celcius
|
* @param fahrenheit true to set Fahrenheit, false to set Celsius
|
||||||
*/
|
*/
|
||||||
void setTemperatureScale(bool fahrenheit);
|
void setTemperatureScale(bool fahrenheit);
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ namespace upm {
|
|||||||
modbus_t *m_mbContext;
|
modbus_t *m_mbContext;
|
||||||
|
|
||||||
// is the device reporting in C or F?
|
// is the device reporting in C or F?
|
||||||
bool m_isCelcius;
|
bool m_isCelsius;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_debugging;
|
bool m_debugging;
|
||||||
|
@ -75,9 +75,9 @@ namespace upm {
|
|||||||
~LM35();
|
~LM35();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the temperature in degrees Celcius
|
* Returns the temperature in degrees Celsius
|
||||||
*
|
*
|
||||||
* @return The Temperature in degrees Celcius
|
* @return The Temperature in degrees Celsius
|
||||||
*/
|
*/
|
||||||
float getTemperature();
|
float getTemperature();
|
||||||
|
|
||||||
|
@ -1294,7 +1294,7 @@ namespace upm {
|
|||||||
* the correct value, so I made a 'guess'. If it's wrong, and you
|
* the correct value, so I made a 'guess'. If it's wrong, and you
|
||||||
* figure it out, send a patch!
|
* figure it out, send a patch!
|
||||||
*
|
*
|
||||||
* @return the temperature value in degrees Celcius
|
* @return the temperature value in degrees Celsius
|
||||||
*/
|
*/
|
||||||
float getTemperature();
|
float getTemperature();
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ namespace upm {
|
|||||||
* setMode - sets temperature reporting mode.
|
* setMode - sets temperature reporting mode.
|
||||||
*
|
*
|
||||||
* @param celsius. Default is true. If false all
|
* @param celsius. Default is true. If false all
|
||||||
* temps will be reported in fahrenhiet.
|
* temps will be reported in fahrenheit.
|
||||||
*/
|
*/
|
||||||
void setMode(bool celsius = true)
|
void setMode(bool celsius = true)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* @brief DFRobot CO2 Sensor
|
* @brief DFRobot CO2 Sensor
|
||||||
* @defgroup mg811 libupm-mg811
|
* @defgroup mg811 libupm-mg811
|
||||||
* @ingroup dfrobot analog gas
|
* @ingroup dfrobot analog gaseous
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +40,7 @@ namespace upm {
|
|||||||
* @sensor mg811
|
* @sensor mg811
|
||||||
* @comname DFRobot CO2 Sensor
|
* @comname DFRobot CO2 Sensor
|
||||||
* @altname MG811
|
* @altname MG811
|
||||||
* @type gas
|
* @type gaseous
|
||||||
* @man dfrobot
|
* @man dfrobot
|
||||||
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=1023
|
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=1023
|
||||||
* @con analog
|
* @con analog
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user