mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
14 Commits
v0.6.0
...
travischec
Author | SHA1 | Date | |
---|---|---|---|
5a15daab1c | |||
8734767a5c | |||
b4535a6403 | |||
3d37f957bf | |||
3722dfc780 | |||
b113a46813 | |||
aa30b59e44 | |||
159d2eee07 | |||
7fd9f0c508 | |||
3ca9bfe80f | |||
90983fde9d | |||
ee19daedee | |||
61dbfe4f23 | |||
224a915538 |
12
.travis.yml
12
.travis.yml
@ -6,9 +6,11 @@ env:
|
|||||||
- NODE5=true
|
- NODE5=true
|
||||||
- NODE012=true
|
- NODE012=true
|
||||||
install:
|
install:
|
||||||
|
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
|
||||||
|
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
||||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/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 -qq swig3.0 python git cmake
|
||||||
- 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:
|
||||||
@ -20,19 +22,13 @@ before_script:
|
|||||||
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
script:
|
script:
|
||||||
- git clone https://github.com/intel-iot-devkit/mraa.git
|
- git clone https://github.com/intel-iot-devkit/mraa.git
|
||||||
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
|
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make && sudo make install
|
||||||
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
|
||||||
- export CPLUS_INCLUDE_PATH=$PWD/include
|
|
||||||
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
|
||||||
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
sources:
|
||||||
- llvm-toolchain-precise-3.6
|
- llvm-toolchain-precise-3.6
|
||||||
- ubuntu-toolchain-r-test
|
- ubuntu-toolchain-r-test
|
||||||
- george-edison55-precise-backports
|
|
||||||
packages:
|
packages:
|
||||||
- clang-3.6
|
- clang-3.6
|
||||||
- g++-4.8
|
- g++-4.8
|
||||||
- cmake
|
|
||||||
- cmake-data
|
|
||||||
|
@ -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.6.0-dirty")
|
set (VERSION "v0.5.1-dirty")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message (INFO " - UPM Version ${VERSION}")
|
message (INFO " - UPM Version ${VERSION}")
|
||||||
@ -58,8 +58,7 @@ option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
|||||||
option (BUILDSWIGJAVA "Build swig java modules" 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" OFF)
|
||||||
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
|
||||||
|
|
||||||
# Find swig
|
# Find swig
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIG)
|
||||||
@ -78,27 +77,6 @@ include (TargetArch)
|
|||||||
target_architecture (DETECTED_ARCH)
|
target_architecture (DETECTED_ARCH)
|
||||||
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
||||||
|
|
||||||
# enable c++11 standards support
|
|
||||||
if (ENABLECXX11)
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
||||||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
||||||
if (COMPILER_SUPPORTS_CXX11)
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
elseif (COMPILER_SUPPORTS_CXX0X)
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
else()
|
|
||||||
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
# 3.1+ uses this generic method to enable c++11
|
|
||||||
set (CMAKE_CXX_STANDARD 11)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(WARNING "Some modules require C++11 support, and may not build without it.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (BUILDDOC)
|
if (BUILDDOC)
|
||||||
# Add a target to generate API documentation with Doxygen
|
# Add a target to generate API documentation with Doxygen
|
||||||
find_package (Doxygen)
|
find_package (Doxygen)
|
||||||
@ -122,7 +100,7 @@ if (BUILDDOC)
|
|||||||
find_package (Sphinx)
|
find_package (Sphinx)
|
||||||
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
||||||
# Python required for Sphinx build
|
# Python required for Sphinx build
|
||||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
find_package (PythonLibs)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||||
@ -205,9 +183,10 @@ if (RPM)
|
|||||||
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
||||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_PACKAGE_NAME "upm")
|
set(CPACK_PACKAGE_NAME "libupm${upm_VERSION_MAJOR}")
|
||||||
|
set(CPACK_PACKAGE_RELEASE 1)
|
||||||
set(CPACK_PACKAGE_VERSION
|
set(CPACK_PACKAGE_VERSION
|
||||||
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}.${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}-${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
||||||
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
||||||
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
||||||
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
||||||
@ -218,7 +197,7 @@ if (RPM)
|
|||||||
COMMAND tr \\n \\t
|
COMMAND tr \\n \\t
|
||||||
COMMAND sed -e s/\\t//
|
COMMAND sed -e s/\\t//
|
||||||
OUTPUT_VARIABLE DIST_TAG)
|
OUTPUT_VARIABLE DIST_TAG)
|
||||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
|
||||||
include(CPack)
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -238,10 +217,12 @@ if (BUILDSWIGPYTHON OR BUILDTESTS)
|
|||||||
else ()
|
else ()
|
||||||
set (PYTHONBUILD_VERSION 2.7)
|
set (PYTHONBUILD_VERSION 2.7)
|
||||||
endif ()
|
endif ()
|
||||||
|
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
|
include_directories(${PYTHON_INCLUDE_PATH})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (BUILDTESTS)
|
if (BUILDTESTS)
|
||||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
|
||||||
enable_testing ()
|
enable_testing ()
|
||||||
add_subdirectory (tests)
|
add_subdirectory (tests)
|
||||||
endif()
|
endif()
|
||||||
|
19
README.md
19
README.md
@ -12,19 +12,6 @@ to provide identification/pin location on the board.
|
|||||||
Typically an update() function will be called in order to get new data from the
|
Typically an update() function will be called in order to get new data from the
|
||||||
sensor in order to reduce load when doing multiple reads to sensor data.
|
sensor in order to reduce load when doing multiple reads to sensor data.
|
||||||
|
|
||||||
Although implementation and API design is up to the developer, C++ interfaces have
|
|
||||||
been defined for the following sensor/actuator types and developers are encouraged to
|
|
||||||
implement them. Interface header files are in the src/upm folder.
|
|
||||||
|
|
||||||
* Light controller
|
|
||||||
* Light sensor
|
|
||||||
* Temperature sensor
|
|
||||||
* Humidity sensor
|
|
||||||
* Pressure sensor
|
|
||||||
* Analog to digital converter
|
|
||||||
|
|
||||||
Feedback on interface design and additions for new types are welcome
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
||||||
@ -64,6 +51,10 @@ A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
However implementation and API design is completely up to the developer, some
|
||||||
|
enumerable sensors for example may provide much clever instantiation. Displays
|
||||||
|
may also create more complex structures in order to interface with them.
|
||||||
|
|
||||||
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
||||||
|
|
||||||
Multi-sensor samples for the starter and specialized kits can be found in the
|
Multi-sensor samples for the starter and specialized kits can be found in the
|
||||||
@ -90,7 +81,7 @@ See building documentation [here](docs/building.md).
|
|||||||
|
|
||||||
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
||||||
|
|
||||||
There is also an example available gfor max31855 [sensor](docs/max31855.md).
|
There is also an example available for max31855 [sensor](docs/max31855.md).
|
||||||
|
|
||||||
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
||||||
|
|
||||||
|
@ -4,19 +4,6 @@ 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.6.0
|
|
||||||
|
|
||||||
* Introduced C++ Interfaces for several sensor categories that will help
|
|
||||||
consolidate the sensor APIs with uniform function names upon implementation
|
|
||||||
* Greatly improved Node.js detection and handling during build and install,
|
|
||||||
and should be now compatible with all major versions
|
|
||||||
* Added a driver for the Curie IMU (accelerometer + gyroscope) that works with
|
|
||||||
the new Firmata support implemented by MRAA
|
|
||||||
* Continued to provide several JAVA fixes and examples
|
|
||||||
* Many new industrial and maker sensors: cwlsxxa, teams, tex00, h803x, apa102,
|
|
||||||
smartdrive, bmi160, bme280, ds1808lc, hlg150, lp8860, max44009, si1132, t6713,
|
|
||||||
si7005, ssd1351
|
|
||||||
|
|
||||||
### v0.5.1
|
### v0.5.1
|
||||||
|
|
||||||
* Updated the API and added new functionality for the MY9221 class and derived
|
* Updated the API and added new functionality for the MY9221 class and derived
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 72 KiB |
@ -859,7 +859,7 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
# Note that the wildcards are matched against the file with absolute path, so to
|
# Note that the wildcards are matched against the file with absolute path, so to
|
||||||
# exclude all test directories for example use the pattern */test/*
|
# exclude all test directories for example use the pattern */test/*
|
||||||
|
|
||||||
EXCLUDE_PATTERNS = bosch_*
|
EXCLUDE_PATTERNS =
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
|
@ -48,7 +48,7 @@ mpu9150.cxx MPU9150Sample.java
|
|||||||
mq2.cxx MQ2Sample.java
|
mq2.cxx MQ2Sample.java
|
||||||
mq303a.cxx MQ303ASample.java
|
mq303a.cxx MQ303ASample.java
|
||||||
mq5.cxx MQ5Sample.java
|
mq5.cxx MQ5Sample.java
|
||||||
groveledbar GroveLEDBar
|
my9221-ledbar.cxx MY9221_ledbarSample.java
|
||||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
||||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
||||||
nunchuck.cxx NUNCHUCKSample.java
|
nunchuck.cxx NUNCHUCKSample.java
|
||||||
|
@ -234,27 +234,12 @@ if (MODBUS_FOUND)
|
|||||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||||
add_example (t3311)
|
add_example (t3311)
|
||||||
add_example (hwxpxx)
|
add_example (hwxpxx)
|
||||||
add_example (h803x)
|
|
||||||
endif()
|
endif()
|
||||||
add_example (hdxxvxta)
|
add_example (hdxxvxta)
|
||||||
add_example (rhusb)
|
add_example (rhusb)
|
||||||
add_example (apds9930)
|
add_example (apds9930)
|
||||||
add_example (kxcjk1013)
|
add_example (kxcjk1013)
|
||||||
add_example (ssd1351)
|
add_example (ssd1351)
|
||||||
add_example (bme280)
|
|
||||||
add_example (ds1808lc)
|
|
||||||
add_example (hlg150h)
|
|
||||||
add_example (lp8860)
|
|
||||||
add_example (max44009)
|
|
||||||
add_example (si1132)
|
|
||||||
add_example (si7005)
|
|
||||||
add_example (t6713)
|
|
||||||
add_example (cwlsxxa)
|
|
||||||
add_example (teams)
|
|
||||||
add_example (apa102)
|
|
||||||
add_example (tex00)
|
|
||||||
add_example (bmi160)
|
|
||||||
add_example (smartdrive)
|
|
||||||
if (HAVE_FIRMATA)
|
if (HAVE_FIRMATA)
|
||||||
add_example (curieimu)
|
add_example (curieimu)
|
||||||
endif ()
|
endif ()
|
||||||
@ -276,10 +261,3 @@ 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;bmp180;bme280")
|
|
||||||
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
|
||||||
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
|
|
||||||
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
|
||||||
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
|
||||||
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
|
||||||
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "ads1015.h"
|
|
||||||
#include "mraa/gpio.hpp"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
#define EDISON_GPIO_SI7005_CS 20
|
|
||||||
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using IADC to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// IADC is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::IADC* getADC()
|
|
||||||
{
|
|
||||||
upm::IADC* adc = NULL;
|
|
||||||
try {
|
|
||||||
adc = new upm::ADS1015(EDISON_I2C_BUS);
|
|
||||||
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
|
||||||
gpio.dir(mraa::DIR_OUT_HIGH);
|
|
||||||
return adc;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "ADS1015: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return adc;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::IADC* adc = getADC();
|
|
||||||
if (adc == NULL) {
|
|
||||||
std::cout << "ADC not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
|
||||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
|
|
||||||
std::cout << "Input " << i;
|
|
||||||
try {
|
|
||||||
float voltage = adc->getVoltage(i);
|
|
||||||
std::cout << ": Voltage = " << voltage << "V" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete adc;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
* Copyright (c) 2016 Yannick Adam
|
|
||||||
*
|
|
||||||
* 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 "apa102.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
//! [Interesting]
|
|
||||||
// Instantiate a strip of 30 LEDs on SPI bus 0
|
|
||||||
upm::APA102* ledStrip = new upm::APA102(800, 0);
|
|
||||||
|
|
||||||
// Set all LEDs to Red
|
|
||||||
ledStrip->setAllLeds(31, 255, 0, 0);
|
|
||||||
|
|
||||||
// Set a section (10 to 20) to blue
|
|
||||||
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
|
|
||||||
|
|
||||||
// Set a single LED to green
|
|
||||||
ledStrip->setLed(15, 31, 0, 255, 0);
|
|
||||||
|
|
||||||
delete ledStrip;
|
|
||||||
//! [Interesting]
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "bme280.h"
|
|
||||||
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
upm::BME280* bme280 = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
while (true) {
|
|
||||||
int temperature = bme280->getTemperatureCelcius();
|
|
||||||
int humidity = bme280->getHumidityRelative();
|
|
||||||
int pressure = bme280->getPressurePa();
|
|
||||||
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
|
||||||
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
|
||||||
std::cout << "Pressure = " << pressure << "Pa" << std::endl;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete bme280;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "bmi160.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int shouldRun = true;
|
|
||||||
|
|
||||||
void sig_handler(int signo)
|
|
||||||
{
|
|
||||||
if (signo == SIGINT)
|
|
||||||
shouldRun = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
signal(SIGINT, sig_handler);
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
// Instantiate a BMI160 instance using default i2c bus and address
|
|
||||||
upm::BMI160 *sensor = new upm::BMI160();
|
|
||||||
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
float dataX, dataY, dataZ;
|
|
||||||
|
|
||||||
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
|
|
||||||
cout << "Accelerometer: ";
|
|
||||||
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
|
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
sensor->getGyroscope(&dataX, &dataY, &dataZ);
|
|
||||||
cout << "Gryoscope: ";
|
|
||||||
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
|
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
|
|
||||||
cout << "Magnetometer: ";
|
|
||||||
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
|
|
||||||
<< dataZ << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "t6713.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ICO2Sensor to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// ICO2Sensor is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::ICO2Sensor* getCO2Sensor()
|
|
||||||
{
|
|
||||||
upm::ICO2Sensor* cO2Sensor = NULL;
|
|
||||||
try {
|
|
||||||
cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
return cO2Sensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "T6713: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return cO2Sensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::ICO2Sensor* cO2Sensor = getCO2Sensor();
|
|
||||||
if (cO2Sensor == NULL) {
|
|
||||||
std::cout << "CO2 sensor not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
uint16_t value = cO2Sensor->getPpm();
|
|
||||||
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete cO2Sensor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "cwlsxxa.h"
|
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
cout << "Initializing..." << endl;
|
|
||||||
|
|
||||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
|
||||||
// humidity and A2 for temperature
|
|
||||||
upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
cout << "Temperature: " << sensor->getTemperature()
|
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Humidity: " << sensor->getHumidity()
|
|
||||||
<< " %" << endl;
|
|
||||||
|
|
||||||
cout << "CO2: " << sensor->getCO2()
|
|
||||||
<< " ppm" << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
|
||||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
|
||||||
|
|
||||||
void printState(upm::ILightController *lightController)
|
|
||||||
{
|
|
||||||
if (lightController->isPowered())
|
|
||||||
{
|
|
||||||
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Light is not powered." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
upm::ILightController* lightController;
|
|
||||||
|
|
||||||
try {
|
|
||||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
|
||||||
std::cout << "Existing state: "; printState(lightController);
|
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
std::string arg = argv[1];
|
|
||||||
int brightness = ::atoi(argv[1]);
|
|
||||||
if (brightness > 0) {
|
|
||||||
lightController->setPowerOn();
|
|
||||||
lightController->setBrightness(brightness);
|
|
||||||
} else
|
|
||||||
lightController->setPowerOff();
|
|
||||||
}
|
|
||||||
std::cout << "Now: ";printState(lightController);
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cout << "Error: " << e.what() << std::endl;
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete lightController;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "h803x.h"
|
|
||||||
|
|
||||||
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/ttyUSB0";
|
|
||||||
|
|
||||||
// if an argument was specified, use it as the device instead
|
|
||||||
if (argc > 1)
|
|
||||||
defaultDev = string(argv[1]);
|
|
||||||
|
|
||||||
cout << "Using device " << defaultDev << endl;
|
|
||||||
cout << "Initializing..." << endl;
|
|
||||||
|
|
||||||
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
|
||||||
// default comm parameters (9600, 8, N, 2)
|
|
||||||
upm::H803X *sensor = new upm::H803X(defaultDev, 1);
|
|
||||||
|
|
||||||
// output the Slave ID string
|
|
||||||
cout << "Slave ID: " << sensor->getSlaveID() << endl;
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
// H8035 / H8036
|
|
||||||
cout << "Consumption (kWh): " << sensor->getConsumption() << endl;
|
|
||||||
cout << "Real Power (kW): " << sensor->getRealPower() << endl;
|
|
||||||
|
|
||||||
if (sensor->isH8036())
|
|
||||||
{
|
|
||||||
// The H8036 has much more data available...
|
|
||||||
|
|
||||||
cout << "Reactive Power (kVAR): " << sensor->getReactivePower()
|
|
||||||
<< endl;
|
|
||||||
cout << "Apparent Power (kVA): " << sensor->getApparentPower()
|
|
||||||
<< endl;
|
|
||||||
cout << "Power Factor: " << sensor->getPowerFactor()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Line to Line: " << sensor->getVoltsLineToLine()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Line to Neutral: " << sensor->getVoltsLineToNeutral()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Current: " << sensor->getCurrent()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Real Power Phase A (kW): " << sensor->getRealPowerPhaseA()
|
|
||||||
<< endl;
|
|
||||||
cout << "Real Power Phase B (kW): " << sensor->getRealPowerPhaseB()
|
|
||||||
<< endl;
|
|
||||||
cout << "Real Power Phase C (kW): " << sensor->getRealPowerPhaseC()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Power Factor Phase A: " << sensor->getPowerFactorPhaseA()
|
|
||||||
<< endl;
|
|
||||||
cout << "Power Factor Phase B: " << sensor->getPowerFactorPhaseB()
|
|
||||||
<< endl;
|
|
||||||
cout << "Power Factor Phase C: " << sensor->getPowerFactorPhaseC()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Volts Phase A to B: " << sensor->getVoltsPhaseAToB()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Phase B to C: " << sensor->getVoltsPhaseBToC()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Phase A to C: " << sensor->getVoltsPhaseAToC()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Phase A to Neutral: "
|
|
||||||
<< sensor->getVoltsPhaseAToNeutral()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Phase B to Neutral: "
|
|
||||||
<< sensor->getVoltsPhaseBToNeutral()
|
|
||||||
<< endl;
|
|
||||||
cout << "Volts Phase C to Neutral: "
|
|
||||||
<< sensor->getVoltsPhaseCToNeutral()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Current Phase A: " << sensor->getCurrentPhaseA()
|
|
||||||
<< endl;
|
|
||||||
cout << "Current Phase B: " << sensor->getCurrentPhaseB()
|
|
||||||
<< endl;
|
|
||||||
cout << "Current Phase C: " << sensor->getCurrentPhaseC()
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << "Avg Real Power (kW): " << sensor->getAvgRealPower()
|
|
||||||
<< endl;
|
|
||||||
cout << "Min Real Power (kW): " << sensor->getMinRealPower()
|
|
||||||
<< endl;
|
|
||||||
cout << "Max Real Power (kW): " << sensor->getMaxRealPower()
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
sleep(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "hlg150h.h"
|
|
||||||
|
|
||||||
#define HLG150H_GPIO_RELAY 21
|
|
||||||
#define HLG150H_GPIO_PWM 22
|
|
||||||
|
|
||||||
void printState(upm::ILightController *lightController)
|
|
||||||
{
|
|
||||||
if (lightController->isPowered())
|
|
||||||
{
|
|
||||||
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Light is not powered." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
upm::ILightController* lightController;
|
|
||||||
|
|
||||||
try {
|
|
||||||
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
|
||||||
std::cout << "Existing state: "; printState(lightController);
|
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
std::string arg = argv[1];
|
|
||||||
int brightness = ::atoi(argv[1]);
|
|
||||||
if (brightness > 0) {
|
|
||||||
lightController->setPowerOn();
|
|
||||||
lightController->setBrightness(brightness);
|
|
||||||
} else
|
|
||||||
lightController->setPowerOff();
|
|
||||||
}
|
|
||||||
std::cout << "Now: ";printState(lightController);
|
|
||||||
delete lightController;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cout << "Error: " << e.what() << std::endl;
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "si7005.h"
|
|
||||||
#include "bme280.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
#define EDISON_GPIO_SI7005_CS 20
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ILightSensor to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// ILightSensor is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::IHumiditySensor* getHumiditySensor()
|
|
||||||
{
|
|
||||||
upm::IHumiditySensor* humiditySensor = NULL;
|
|
||||||
try {
|
|
||||||
humiditySensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
return humiditySensor ;
|
|
||||||
} catch (std::exception& e)
|
|
||||||
{
|
|
||||||
std::cerr <<"BME280: "<<e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
|
||||||
return humiditySensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "SI7005: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return humiditySensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
|
|
||||||
if (humiditySensor == NULL) {
|
|
||||||
std::cout << "Humidity sensor not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
int value = humiditySensor->getHumidityRelative();
|
|
||||||
std::cout << "Humidity = " << value << "%" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete humiditySensor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,98 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "lp8860.h"
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
#include "hlg150h.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
|
||||||
#define GPIO_SI7005_CS 20 // Edison GP12
|
|
||||||
#define HLG150H_GPIO_RELAY 21
|
|
||||||
#define HLG150H_GPIO_PWM 22
|
|
||||||
#define LP8860_GPIO_PWR 45 // Edison GP45
|
|
||||||
#define DS1808_GPIO_PWR 15 // Edison GP165
|
|
||||||
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ILightController to determine
|
|
||||||
// which controller is present and return its name.
|
|
||||||
// ILightController is then used to get readings from sensor
|
|
||||||
|
|
||||||
upm::ILightController* getLightController()
|
|
||||||
{
|
|
||||||
upm::ILightController* lightController = NULL;
|
|
||||||
try {
|
|
||||||
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
|
||||||
return lightController;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "LP8860: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
|
||||||
return lightController;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "DS1808LC: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
|
||||||
return lightController;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "HLG150H: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return lightController;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void printState(upm::ILightController *lightController)
|
|
||||||
{
|
|
||||||
if (lightController->isPowered())
|
|
||||||
{
|
|
||||||
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Light is not powered." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
|
|
||||||
|
|
||||||
upm::ILightController *lightController = getLightController();
|
|
||||||
if (lightController != NULL)
|
|
||||||
{
|
|
||||||
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Error. Unsupported platform." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
std::cout << "Existing state: "; printState(lightController);
|
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
std::string arg = argv[1];
|
|
||||||
int brightness = ::atoi(argv[1]);
|
|
||||||
if (brightness > 0) {
|
|
||||||
lightController->setPowerOn();
|
|
||||||
lightController->setBrightness(brightness);
|
|
||||||
} else
|
|
||||||
lightController->setPowerOff();
|
|
||||||
}
|
|
||||||
std::cout << "Now: ";printState(lightController);
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cout << "Error: " << e.what() << std::endl;
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete lightController;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "max44009.h"
|
|
||||||
#include "si1132.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ILightSensor to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// ILightSensor is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::ILightSensor* getLightSensor()
|
|
||||||
{
|
|
||||||
upm::ILightSensor* lightSensor = NULL;
|
|
||||||
try {
|
|
||||||
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
return lightSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "SI1132: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
|
||||||
return lightSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "MAX44009: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return lightSensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::ILightSensor* lightSensor = getLightSensor();
|
|
||||||
if (lightSensor == NULL) {
|
|
||||||
std::cout << "Light sensor not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
float value = lightSensor->getVisibleLux();
|
|
||||||
std::cout << "Light level = " << value << " lux" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete lightSensor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,52 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "lp8860.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
|
||||||
#define LP8860_GPIO_PWR 45 // Edison GP45
|
|
||||||
|
|
||||||
|
|
||||||
void printState(upm::ILightController *lightController)
|
|
||||||
{
|
|
||||||
if (lightController->isPowered())
|
|
||||||
{
|
|
||||||
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Light is not powered." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
|
||||||
{
|
|
||||||
int status = 0;
|
|
||||||
upm::LP8860* lightController;
|
|
||||||
|
|
||||||
try {
|
|
||||||
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
|
||||||
std::cout << "Existing state: "; printState(lightController);
|
|
||||||
if (argc == 2)
|
|
||||||
{
|
|
||||||
std::string arg = argv[1];
|
|
||||||
int brightness = ::atoi(argv[1]);
|
|
||||||
if (brightness > 0) {
|
|
||||||
lightController->setPowerOn();
|
|
||||||
lightController->setBrightness(brightness);
|
|
||||||
} else
|
|
||||||
lightController->setPowerOff();
|
|
||||||
}
|
|
||||||
std::cout << "Now: ";printState(lightController);
|
|
||||||
delete lightController;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cout << "Error: " << e.what() << std::endl;
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "max44009.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
|
||||||
while (true) {
|
|
||||||
float value = lightSensor->getVisibleLux();
|
|
||||||
std::cout << "Light level = " << value << " lux" << std::endl;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete lightSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "bmp180.h"
|
|
||||||
#include "bme280.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ILightSensor to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// ILightSensor is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::IPressureSensor* getPressureSensor()
|
|
||||||
{
|
|
||||||
upm::IPressureSensor* pressureSensor = NULL;
|
|
||||||
try {
|
|
||||||
pressureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
return pressureSensor ;
|
|
||||||
} catch (std::exception& e)
|
|
||||||
{
|
|
||||||
std::cerr <<"BME280: "<<e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
pressureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
|
||||||
return pressureSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "BMP180: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return pressureSensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::IPressureSensor* pressureSensor = getPressureSensor();
|
|
||||||
if (pressureSensor == NULL) {
|
|
||||||
std::cout << "Pressure sensor not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
int value = pressureSensor->getPressurePa();
|
|
||||||
std::cout << "Pressure = " << value << " Pa" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete pressureSensor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "si1132.h"
|
|
||||||
|
|
||||||
#define FT4222_I2C_BUS 1
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
while (true) {
|
|
||||||
float value = lightSensor->getVisibleLux();
|
|
||||||
std::cout << "Light level = " << value << " lux" << std::endl;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete lightSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "si7005.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define EDISON_GPIO_SI7005_CS 20
|
|
||||||
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
|
||||||
while (true) {
|
|
||||||
int temperature = sensor->getTemperatureCelcius();
|
|
||||||
int humidity = sensor->getHumidityRelative();
|
|
||||||
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
|
||||||
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete sensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Author: Oussema Harbi <oussema.elharbi@gmail.com>
|
|
||||||
* Copyright (c) <2016> <Oussema Harbi>
|
|
||||||
*
|
|
||||||
* 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 "smartdrive.h"
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
upm::SmartDrive *drive = NULL;
|
|
||||||
|
|
||||||
void
|
|
||||||
sig_handler(int signo)
|
|
||||||
{
|
|
||||||
printf("got signal\n");
|
|
||||||
if (signo == SIGINT) {
|
|
||||||
printf("exiting application\n");
|
|
||||||
if (drive != NULL)
|
|
||||||
delete drive;
|
|
||||||
exit (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
float voltage = 0;
|
|
||||||
|
|
||||||
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
|
|
||||||
sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Instantiate a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
|
|
||||||
drive = new upm::SmartDrive(0);
|
|
||||||
|
|
||||||
std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
|
|
||||||
//Set motor M1 to run for 120 seconds, with speed of 15RPM, waith for it to finish and then Brake It
|
|
||||||
drive->Run_Seconds(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 15, 120, true, SmartDrive_Action_Brake);
|
|
||||||
std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
|
|
||||||
//Rotate motor M2 2270 degrees, in reverse sense, with speed of 10RPM, return immediately from function call
|
|
||||||
drive->Run_Degrees(SmartDrive_Motor_ID_2, SmartDrive_Dir_Reverse, 10, 2270, false, SmartDrive_Action_Float);
|
|
||||||
//While motor is running, Display its status
|
|
||||||
drive->PrintMotorStatus(SmartDrive_Motor_ID_2);
|
|
||||||
sleep(2); //Sleep for 2 seconds
|
|
||||||
//Stop motor M2 and then finish program
|
|
||||||
drive->StopMotor(SmartDrive_Motor_ID_2, SmartDrive_Action_BrakeHold);
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
std::cout << "Demo complete. GoodBye" << std::endl;
|
|
||||||
|
|
||||||
delete drive;
|
|
||||||
drive = NULL;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "t6713.h"
|
|
||||||
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
|
|
||||||
try {
|
|
||||||
upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
while (true) {
|
|
||||||
uint16_t value = cO2Sensor->getPpm();
|
|
||||||
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete cO2Sensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "teams.h"
|
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
cout << "Initializing..." << endl;
|
|
||||||
|
|
||||||
// Instantiate an TEAMS instance, using A0 for temperature, and
|
|
||||||
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
|
||||||
// interface)
|
|
||||||
upm::TEAMS *sensor = new upm::TEAMS(0, 165.0);
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
// is the sensor connected? (current >= 4ma)
|
|
||||||
cout << "Is Connected: " << sensor->isConnected() << endl;
|
|
||||||
|
|
||||||
// print computed current on the loop. This includes the offset,
|
|
||||||
// if one was set by setOffsetMilliamps().
|
|
||||||
cout << "Milliamps: " << sensor->getRawMilliamps() << endl;
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
cout << "Temperature: " << sensor->getTemperature()
|
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
|
||||||
<< endl;
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "si7005.h"
|
|
||||||
#include "bmp180.h"
|
|
||||||
#include "bme280.h"
|
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
|
||||||
#define FT4222_I2C_BUS 0
|
|
||||||
|
|
||||||
#define EDISON_GPIO_SI7005_CS 20
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
// Simple example of using ITemperatureSensor to determine
|
|
||||||
// which sensor is present and return its name.
|
|
||||||
// ITemperatureSensor is then used to get readings from sensor
|
|
||||||
|
|
||||||
|
|
||||||
upm::ITemperatureSensor* getTemperatureSensor()
|
|
||||||
{
|
|
||||||
upm::ITemperatureSensor* temperatureSensor = NULL;
|
|
||||||
try {
|
|
||||||
temperatureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
|
||||||
return temperatureSensor;
|
|
||||||
} catch (std::exception& e)
|
|
||||||
{
|
|
||||||
std::cerr <<"BME280: "<<e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
|
||||||
return temperatureSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "SI7005: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
temperatureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
|
||||||
return temperatureSensor;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << "BMP180: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
return temperatureSensor;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
|
|
||||||
if (temperatureSensor == NULL) {
|
|
||||||
std::cout << "Temperature sensor not detected" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
int value = temperatureSensor->getTemperatureCelcius();
|
|
||||||
std::cout << "Temperature = " << value << "C" << std::endl;
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
std::cerr << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
delete temperatureSensor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "tex00.h"
|
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
cout << "Initializing..." << endl;
|
|
||||||
|
|
||||||
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
|
||||||
// this example, we are using a 10K Ohm balance resistor and a TED
|
|
||||||
// (10k type 2) thermistor.
|
|
||||||
upm::TEX00 *sensor = new upm::TEX00(0, 10000,
|
|
||||||
upm::TEX00::STYPE_THERMISTOR_TED);
|
|
||||||
|
|
||||||
cout << "Minimum temperature: " << sensor->getTemperatureRangeMin()
|
|
||||||
<< " C" << endl;
|
|
||||||
cout << "Maximum temperature: " << sensor->getTemperatureRangeMax()
|
|
||||||
<< " C" << endl;
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
while (shouldRun)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor->update();
|
|
||||||
|
|
||||||
if (sensor->isOutOfRange())
|
|
||||||
{
|
|
||||||
cout << "Temperature out of range" << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we show both C and F for temperature
|
|
||||||
cout << "Temperature: " << sensor->getTemperature()
|
|
||||||
<< " C / " << sensor->getTemperature(true) << " F"
|
|
||||||
<< endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Exiting..." << endl;
|
|
||||||
|
|
||||||
delete sensor;
|
|
||||||
|
|
||||||
//! [Interesting]
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
* Copyright (c) 2016 Yannick Adam
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class APA102Sample {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
// ! [Interesting]
|
|
||||||
// Instantiate a strip of 30 LEDs on SPI bus 0
|
|
||||||
upm_apa102.APA102 ledStrip =
|
|
||||||
new upm_apa102.APA102(30, (short)0, false, (byte)-1);
|
|
||||||
|
|
||||||
System.out.println("Set all LEDs to blue");
|
|
||||||
ledStrip.setAllLeds((short)31, (short)0, (short)0, (short)255);
|
|
||||||
|
|
||||||
System.out.println("Set LEDs between 10 and 20 to green");
|
|
||||||
ledStrip.setLeds(10, 20, (short)31, (short)0, (short)255, (short)0);
|
|
||||||
|
|
||||||
System.out.println("Set a single LED to red at index 15");
|
|
||||||
ledStrip.setLed(15, (short)31, (short)255, (short)0, (short)0);
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,6 +25,18 @@ import upm_ad8232.AD8232;
|
|||||||
|
|
||||||
public class Ad8232Example {
|
public class Ad8232Example {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_ad8232");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_bmi160.BMI160;
|
|
||||||
|
|
||||||
public class BMI160_Example
|
|
||||||
{
|
|
||||||
public static void main(String[] args) throws InterruptedException
|
|
||||||
{
|
|
||||||
// ! [Interesting]
|
|
||||||
System.out.println("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate a BMI160 instance using default i2c bus and address
|
|
||||||
BMI160 sensor = new BMI160();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
float dataA[] = sensor.getAccelerometer();
|
|
||||||
|
|
||||||
System.out.println("Accelerometer: "
|
|
||||||
+ "AX: "
|
|
||||||
+ dataA[0]
|
|
||||||
+ " AY: "
|
|
||||||
+ dataA[1]
|
|
||||||
+ " AZ: "
|
|
||||||
+ dataA[2]);
|
|
||||||
|
|
||||||
float dataG[] = sensor.getGyroscope();
|
|
||||||
|
|
||||||
System.out.println("Gryoscope: "
|
|
||||||
+ "GX: "
|
|
||||||
+ dataG[0]
|
|
||||||
+ " GY: "
|
|
||||||
+ dataG[1]
|
|
||||||
+ " GZ: "
|
|
||||||
+ dataG[2]);
|
|
||||||
|
|
||||||
float dataM[] = sensor.getMagnetometer();
|
|
||||||
|
|
||||||
System.out.println("Magnetometer: "
|
|
||||||
+ "MX: "
|
|
||||||
+ dataM[0]
|
|
||||||
+ " MY: "
|
|
||||||
+ dataM[1]
|
|
||||||
+ " MZ: "
|
|
||||||
+ dataM[2]);
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
Thread.sleep(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -105,14 +105,7 @@ add_example(Ad8232Example ad8232)
|
|||||||
add_example(Gp2y0aExample gp2y0a)
|
add_example(Gp2y0aExample gp2y0a)
|
||||||
add_example(Th02Example th02)
|
add_example(Th02Example th02)
|
||||||
add_example(FlexSensorExample flex)
|
add_example(FlexSensorExample flex)
|
||||||
add_example(CWLSXXA_Example cwlsxxa)
|
|
||||||
add_example(TEAMS_Example teams)
|
|
||||||
add_example(APA102Sample apa102)
|
|
||||||
add_example(TEX00_Example tex00)
|
|
||||||
add_example(BMI160_Example bmi160)
|
|
||||||
if (MODBUS_FOUND)
|
|
||||||
add_example(H803X_Example h803x)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
||||||
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_cwlsxxa.CWLSXXA;
|
|
||||||
|
|
||||||
public class CWLSXXA_Example
|
|
||||||
{
|
|
||||||
public static void main(String[] args) throws InterruptedException
|
|
||||||
{
|
|
||||||
// ! [Interesting]
|
|
||||||
|
|
||||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
|
||||||
// humidity and A2 for temperature
|
|
||||||
CWLSXXA sensor = new CWLSXXA(0, 1, 2);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
System.out.println("Temperature: "
|
|
||||||
+ sensor.getTemperature()
|
|
||||||
+ " C / "
|
|
||||||
+ sensor.getTemperature(true)
|
|
||||||
+ " F");
|
|
||||||
|
|
||||||
System.out.println("Humidity: "
|
|
||||||
+ sensor.getHumidity()
|
|
||||||
+ " %");
|
|
||||||
|
|
||||||
System.out.println("CO2: "
|
|
||||||
+ sensor.getCO2()
|
|
||||||
+ " ppm");
|
|
||||||
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_h803x.H803X;
|
|
||||||
|
|
||||||
public class H803X_Example
|
|
||||||
{
|
|
||||||
private static String defaultDev = "/dev/ttyUSB0";
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException
|
|
||||||
{
|
|
||||||
// ! [Interesting]
|
|
||||||
if (args.length > 0)
|
|
||||||
defaultDev = args[0];
|
|
||||||
System.out.println("Using device " + defaultDev);
|
|
||||||
System.out.println("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
|
||||||
// default comm parameters (9600, 8, N, 2)
|
|
||||||
H803X sensor = new H803X(defaultDev, 1);
|
|
||||||
|
|
||||||
// output the Slave ID (manufacturer, model, serno)
|
|
||||||
System.out.println("Slave ID: " + sensor.getSlaveID());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// H8035 / H8036
|
|
||||||
System.out.println("Consumption (kWh): "
|
|
||||||
+ sensor.getConsumption());
|
|
||||||
System.out.println("Real Power (kW): "
|
|
||||||
+ sensor.getRealPower());
|
|
||||||
|
|
||||||
if (sensor.isH8036())
|
|
||||||
{
|
|
||||||
// The H8036 has much more data available...
|
|
||||||
|
|
||||||
System.out.println("Reactive Power (kVAR): "
|
|
||||||
+ sensor.getReactivePower());
|
|
||||||
System.out.println("Apparent Power (kVA): "
|
|
||||||
+ sensor.getApparentPower());
|
|
||||||
System.out.println("Power Factor: "
|
|
||||||
+ sensor.getPowerFactor());
|
|
||||||
System.out.println("Volts Line to Line: "
|
|
||||||
+ sensor.getVoltsLineToLine());
|
|
||||||
System.out.println("Volts Line to Neutral: "
|
|
||||||
+ sensor.getVoltsLineToNeutral());
|
|
||||||
|
|
||||||
System.out.println("Current: " + sensor.getCurrent());
|
|
||||||
|
|
||||||
System.out.println("Real Power Phase A (kW): "
|
|
||||||
+ sensor.getRealPowerPhaseA());
|
|
||||||
System.out.println("Real Power Phase B (kW): "
|
|
||||||
+ sensor.getRealPowerPhaseB());
|
|
||||||
System.out.println("Real Power Phase C (kW): "
|
|
||||||
+ sensor.getRealPowerPhaseC());
|
|
||||||
|
|
||||||
System.out.println("Power Factor Phase A: "
|
|
||||||
+ sensor.getPowerFactorPhaseA());
|
|
||||||
System.out.println("Power Factor Phase B: "
|
|
||||||
+ sensor.getPowerFactorPhaseB());
|
|
||||||
System.out.println("Power Factor Phase C: "
|
|
||||||
+ sensor.getPowerFactorPhaseC());
|
|
||||||
|
|
||||||
System.out.println("Volts Phase A to B: "
|
|
||||||
+ sensor.getVoltsPhaseAToB());
|
|
||||||
System.out.println("Volts Phase B to C: "
|
|
||||||
+ sensor.getVoltsPhaseBToC());
|
|
||||||
System.out.println("Volts Phase A to C: "
|
|
||||||
+ sensor.getVoltsPhaseAToC());
|
|
||||||
System.out.println("Volts Phase A to Neutral: "
|
|
||||||
+ sensor.getVoltsPhaseAToNeutral());
|
|
||||||
System.out.println("Volts Phase B to Neutral: "
|
|
||||||
+ sensor.getVoltsPhaseBToNeutral());
|
|
||||||
System.out.println("Volts Phase C to Neutral: "
|
|
||||||
+ sensor.getVoltsPhaseCToNeutral());
|
|
||||||
|
|
||||||
System.out.println("Current Phase A: "
|
|
||||||
+ sensor.getCurrentPhaseA());
|
|
||||||
System.out.println("Current Phase B: "
|
|
||||||
+ sensor.getCurrentPhaseB());
|
|
||||||
System.out.println("Current Phase C: "
|
|
||||||
+ sensor.getCurrentPhaseC());
|
|
||||||
|
|
||||||
System.out.println("Avg Real Power (kW): "
|
|
||||||
+ sensor.getAvgRealPower());
|
|
||||||
System.out.println("Min Real Power (kW): "
|
|
||||||
+ sensor.getMinRealPower());
|
|
||||||
System.out.println("Max Real Power (kW): "
|
|
||||||
+ sensor.getMaxRealPower());
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_teams.TEAMS;
|
|
||||||
|
|
||||||
public class TEAMS_Example
|
|
||||||
{
|
|
||||||
public static void main(String[] args) throws InterruptedException
|
|
||||||
{
|
|
||||||
// ! [Interesting]
|
|
||||||
System.out.println("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an TEAMS instance, using A0 for temperature, and
|
|
||||||
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
|
||||||
// interface)
|
|
||||||
TEAMS sensor = new TEAMS(0, 165.0f);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// is the sensor connected? (current >= 4ma)
|
|
||||||
System.out.println("Is Connected: " + sensor.isConnected());
|
|
||||||
|
|
||||||
// print computed current on the loop. This includes
|
|
||||||
// the offset, if one was set by setOffsetMilliamps().
|
|
||||||
System.out.println("Milliamps: " + sensor.getRawMilliamps());
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
System.out.println("Temperature: "
|
|
||||||
+ sensor.getTemperature()
|
|
||||||
+ " C / "
|
|
||||||
+ sensor.getTemperature(true)
|
|
||||||
+ " F");
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_tex00.TEX00;
|
|
||||||
|
|
||||||
public class TEX00_Example
|
|
||||||
{
|
|
||||||
public static void main(String[] args) throws InterruptedException
|
|
||||||
{
|
|
||||||
// ! [Interesting]
|
|
||||||
System.out.println("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
|
||||||
// this example, we are using a 10K Ohm balance resistor and a TED
|
|
||||||
// (10k type 2) thermistor.
|
|
||||||
TEX00 sensor = new TEX00(0, 10000.0f,
|
|
||||||
TEX00.SENSOR_TYPES_T.STYPE_THERMISTOR_TED);
|
|
||||||
|
|
||||||
System.out.println("Minimum temperature: "
|
|
||||||
+ sensor.getTemperatureRangeMin());
|
|
||||||
System.out.println("Maximum temperature: "
|
|
||||||
+ sensor.getTemperatureRangeMax());
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
if (sensor.isOutOfRange())
|
|
||||||
{
|
|
||||||
System.out.println("Temperature out of range");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we show both C and F for temperature
|
|
||||||
System.out.println("Temperature: "
|
|
||||||
+ sensor.getTemperature()
|
|
||||||
+ " C / "
|
|
||||||
+ sensor.getTemperature(true)
|
|
||||||
+ " F");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println();
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ! [Interesting]
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,6 +25,18 @@ import upm_th02.TH02;
|
|||||||
|
|
||||||
public class Th02Example {
|
public class Th02Example {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_th02");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
|
||||||
/*jshint unused:true */
|
|
||||||
/*
|
|
||||||
* Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
* Copyright (c) 2016 Yannick Adam
|
|
||||||
*
|
|
||||||
* 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 lib = require('jsupm_apa102');
|
|
||||||
|
|
||||||
// Instantiate a strip of 30 LEDs on SPI Bus 0
|
|
||||||
var ledStrip = new lib.APA102(30, 0);
|
|
||||||
|
|
||||||
// Set all LEDs to blue
|
|
||||||
ledStrip.setAllLeds(31, 0, 0, 255);
|
|
||||||
|
|
||||||
// Set a mid-section to red
|
|
||||||
ledStrip.setLeds(10,20, 31, 255, 0, 0);
|
|
||||||
|
|
||||||
// Set a single led to green
|
|
||||||
ledStrip.setLed(15, 31, 0, 255, 0);
|
|
||||||
|
|
||||||
|
|
||||||
// Exit
|
|
||||||
ledStrip = null;
|
|
||||||
process.exit(0);
|
|
@ -1,51 +0,0 @@
|
|||||||
/*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 bme280pkg = require('jsupm_bme280');
|
|
||||||
|
|
||||||
// Instantiate a BME280 Sensor on I2C sub-platform bus 0
|
|
||||||
var bme280 = new bme280pkg.BME280(512);
|
|
||||||
|
|
||||||
// update every second and print the values
|
|
||||||
var myInterval = setInterval(function()
|
|
||||||
{
|
|
||||||
// print detected value
|
|
||||||
console.log("Temperature: " + bme280.getTemperatureCelcius() + "C");
|
|
||||||
console.log("Humidity: " + bme280.getHumidityRelative() + "%");
|
|
||||||
console.log("Pressure: " + bme280.getPressurePa() + "Pa");
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
// When exiting: clear interval and print message
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
clearInterval(myInterval);
|
|
||||||
bme280 = null
|
|
||||||
bme280pkg = null;
|
|
||||||
console.log("Exiting");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,71 +0,0 @@
|
|||||||
/*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_bmi160');
|
|
||||||
|
|
||||||
// Instantiate a BMI160 instance using default i2c bus and address
|
|
||||||
var sensor = new sensorObj.BMI160();
|
|
||||||
|
|
||||||
var x = new sensorObj.new_floatp();
|
|
||||||
var y = new sensorObj.new_floatp();
|
|
||||||
var z = new sensorObj.new_floatp();
|
|
||||||
|
|
||||||
// Output data every half second until interrupted
|
|
||||||
setInterval(function()
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
sensor.getAccelerometer(x, y, z);
|
|
||||||
console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) +
|
|
||||||
" AY: " + sensorObj.floatp_value(y) +
|
|
||||||
" AZ: " + sensorObj.floatp_value(z));
|
|
||||||
|
|
||||||
sensor.getGyroscope(x, y, z);
|
|
||||||
console.log("Gyroscope: GX: " + sensorObj.floatp_value(x) +
|
|
||||||
" AY: " + sensorObj.floatp_value(y) +
|
|
||||||
" AZ: " + sensorObj.floatp_value(z));
|
|
||||||
|
|
||||||
sensor.getMagnetometer(x, y, z);
|
|
||||||
console.log("Magnetometer: MX: " + sensorObj.floatp_value(x) +
|
|
||||||
" MY: " + sensorObj.floatp_value(y) +
|
|
||||||
" MZ: " + sensorObj.floatp_value(z));
|
|
||||||
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
// exit on ^C
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
sensor = null;
|
|
||||||
sensorObj.cleanUp();
|
|
||||||
sensorObj = null;
|
|
||||||
console.log("Exiting.");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,66 +0,0 @@
|
|||||||
/*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_cwlsxxa');
|
|
||||||
|
|
||||||
|
|
||||||
/************** Main code **************/
|
|
||||||
|
|
||||||
console.log("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
|
||||||
// humidity and A2 for temperature
|
|
||||||
var sensor = new sensorObj.CWLSXXA(0, 1, 2);
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
setInterval(function()
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
console.log("Temperature:", sensor.getTemperature(),
|
|
||||||
"C /", sensor.getTemperature(true), "F");
|
|
||||||
|
|
||||||
console.log("Humidity:", sensor.getHumidity(), "%");
|
|
||||||
|
|
||||||
console.log("CO2:", sensor.getCO2(), "ppm");
|
|
||||||
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
sensor = null;
|
|
||||||
sensorObj.cleanUp();
|
|
||||||
sensorObj = null;
|
|
||||||
console.log("Exiting...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,115 +0,0 @@
|
|||||||
/*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_h803x');
|
|
||||||
|
|
||||||
|
|
||||||
/************** Main code **************/
|
|
||||||
|
|
||||||
var defaultDev = "/dev/ttyUSB0";
|
|
||||||
|
|
||||||
// if an argument was specified, use it as the device instead
|
|
||||||
if (process.argv.length > 2)
|
|
||||||
{
|
|
||||||
defaultDev = process.argv[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Using device " + defaultDev);
|
|
||||||
console.log("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
|
||||||
// default comm parameters (9600, 8, N, 2)
|
|
||||||
var sensor = new sensorObj.H803X(defaultDev, 1);
|
|
||||||
|
|
||||||
// output the Slave ID (manufacturer, model, serno)
|
|
||||||
console.log("Slave ID:", sensor.getSlaveID());
|
|
||||||
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
setInterval(function()
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// H8035 / H8036
|
|
||||||
console.log("Consumption (kWh):", sensor.getConsumption());
|
|
||||||
console.log("Real Power (kW):", sensor.getRealPower());
|
|
||||||
|
|
||||||
if (sensor.isH8036())
|
|
||||||
{
|
|
||||||
// The H8036 has much more data available...
|
|
||||||
|
|
||||||
console.log("Reactive Power (kVAR):", sensor.getReactivePower());
|
|
||||||
console.log("Apparent Power (kVA):", sensor.getApparentPower());
|
|
||||||
console.log("Power Factor:", sensor.getPowerFactor());
|
|
||||||
console.log("Volts Line to Line:", sensor.getVoltsLineToLine());
|
|
||||||
console.log("Volts Line to Neutral:", sensor.getVoltsLineToNeutral());
|
|
||||||
|
|
||||||
console.log("Current:", sensor.getCurrent());
|
|
||||||
|
|
||||||
console.log("Real Power Phase A (kW):", sensor.getRealPowerPhaseA());
|
|
||||||
console.log("Real Power Phase B (kW):", sensor.getRealPowerPhaseB());
|
|
||||||
console.log("Real Power Phase C (kW):", sensor.getRealPowerPhaseC());
|
|
||||||
|
|
||||||
console.log("Power Factor Phase A:", sensor.getPowerFactorPhaseA());
|
|
||||||
console.log("Power Factor Phase B:", sensor.getPowerFactorPhaseB());
|
|
||||||
console.log("Power Factor Phase C:", sensor.getPowerFactorPhaseC());
|
|
||||||
|
|
||||||
console.log("Volts Phase A to B:", sensor.getVoltsPhaseAToB());
|
|
||||||
console.log("Volts Phase B to C:", sensor.getVoltsPhaseBToC());
|
|
||||||
console.log("Volts Phase A to C:", sensor.getVoltsPhaseAToC());
|
|
||||||
console.log("Volts Phase A to Neutral: ",
|
|
||||||
sensor.getVoltsPhaseAToNeutral());
|
|
||||||
console.log("Volts Phase B to Neutral: ",
|
|
||||||
sensor.getVoltsPhaseBToNeutral());
|
|
||||||
console.log("Volts Phase C to Neutral: ",
|
|
||||||
sensor.getVoltsPhaseCToNeutral());
|
|
||||||
|
|
||||||
console.log("Current Phase A:", sensor.getCurrentPhaseA());
|
|
||||||
console.log("Current Phase B:", sensor.getCurrentPhaseB());
|
|
||||||
console.log("Current Phase C:", sensor.getCurrentPhaseC());
|
|
||||||
|
|
||||||
console.log("Avg Real Power (kW):", sensor.getAvgRealPower());
|
|
||||||
console.log("Min Real Power (kW):", sensor.getMinRealPower());
|
|
||||||
console.log("Max Real Power (kW):", sensor.getMaxRealPower());
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
sensor = null;
|
|
||||||
sensorObj.cleanUp();
|
|
||||||
sensorObj = null;
|
|
||||||
console.log("Exiting...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,70 +0,0 @@
|
|||||||
/*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_teams');
|
|
||||||
|
|
||||||
|
|
||||||
/************** Main code **************/
|
|
||||||
|
|
||||||
console.log("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an TEAMS instance, using A0 for temperature, and
|
|
||||||
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
|
||||||
// interface)
|
|
||||||
var sensor = new sensorObj.TEAMS(0, 165.0);
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
setInterval(function()
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
// is the sensor connected? (current >= 4ma)
|
|
||||||
console.log("Is Connected:", sensor.isConnected());
|
|
||||||
|
|
||||||
// print computed current on the loop. This includes the offset,
|
|
||||||
// if one was set by setOffsetMilliamps().
|
|
||||||
console.log("Milliamps:", sensor.getRawMilliamps());
|
|
||||||
|
|
||||||
// we show both C and F for temperature
|
|
||||||
console.log("Temperature:", sensor.getTemperature(),
|
|
||||||
"C /", sensor.getTemperature(true), "F");
|
|
||||||
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
sensor = null;
|
|
||||||
sensorObj.cleanUp();
|
|
||||||
sensorObj = null;
|
|
||||||
console.log("Exiting...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,77 +0,0 @@
|
|||||||
/*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_tex00');
|
|
||||||
|
|
||||||
|
|
||||||
/************** Main code **************/
|
|
||||||
|
|
||||||
console.log("Initializing...");
|
|
||||||
|
|
||||||
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
|
||||||
// this example, we are using a 10K Ohm balance resistor and a TED
|
|
||||||
// (10k type 2) thermistor.
|
|
||||||
var sensor = new sensorObj.TEX00(0, 10000,
|
|
||||||
sensorObj.TEX00.STYPE_THERMISTOR_TED);
|
|
||||||
|
|
||||||
console.log("Minimum temperature:", sensor.getTemperatureRangeMin(),
|
|
||||||
"C");
|
|
||||||
console.log("Maximum temperature:", sensor.getTemperatureRangeMax(),
|
|
||||||
"C");
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
// update and print available values every second
|
|
||||||
setInterval(function()
|
|
||||||
{
|
|
||||||
// update our values from the sensor
|
|
||||||
sensor.update();
|
|
||||||
|
|
||||||
if (sensor.isOutOfRange())
|
|
||||||
{
|
|
||||||
console.log("Temperature out of range");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we show both C and F for temperature
|
|
||||||
console.log("Temperature:", sensor.getTemperature(),
|
|
||||||
"C /", sensor.getTemperature(true), "F");
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("");
|
|
||||||
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
process.on('SIGINT', function()
|
|
||||||
{
|
|
||||||
sensor = null;
|
|
||||||
sensorObj.cleanUp();
|
|
||||||
sensorObj = null;
|
|
||||||
console.log("Exiting...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
@ -1,48 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
# Copyright (c) 2016 Yannick Adam
|
|
||||||
#
|
|
||||||
# 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_apa102 as mylib
|
|
||||||
|
|
||||||
# Instantiate a strip of 30 LEDs on SPI bus 0
|
|
||||||
ledStrip = mylib.APA102(30, 0, False)
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
print "Setting all LEDs to Green"
|
|
||||||
ledStrip.setAllLeds(31, 0, 255, 0)
|
|
||||||
|
|
||||||
print "Setting LEDs between 10 and 20 to Red"
|
|
||||||
ledStrip.setLeds(10, 20, 31, 255, 0, 0)
|
|
||||||
|
|
||||||
print "Setting LED 15 to Blue"
|
|
||||||
ledStrip.setLed(15, 31, 0, 0, 255)
|
|
||||||
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
#!/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_bmi160 as sensorObj
|
|
||||||
|
|
||||||
# Instantiate a BMI160 instance using default i2c bus and address
|
|
||||||
sensor = sensorObj.BMI160()
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
x = sensorObj.new_floatp()
|
|
||||||
y = sensorObj.new_floatp()
|
|
||||||
z = sensorObj.new_floatp()
|
|
||||||
|
|
||||||
while (1):
|
|
||||||
sensor.update()
|
|
||||||
sensor.getAccelerometer(x, y, z)
|
|
||||||
print "Accelerometer: AX: ", sensorObj.floatp_value(x),
|
|
||||||
print " AY: ", sensorObj.floatp_value(y),
|
|
||||||
print " AZ: ", sensorObj.floatp_value(z)
|
|
||||||
|
|
||||||
sensor.getGyroscope(x, y, z)
|
|
||||||
print "Gyroscope: GX: ", sensorObj.floatp_value(x),
|
|
||||||
print " GY: ", sensorObj.floatp_value(y),
|
|
||||||
print " GZ: ", sensorObj.floatp_value(z)
|
|
||||||
|
|
||||||
sensor.getMagnetometer(x, y, z)
|
|
||||||
print "Magnetometer: MX: ", sensorObj.floatp_value(x),
|
|
||||||
print " MY: ", sensorObj.floatp_value(y),
|
|
||||||
print " MZ: ", sensorObj.floatp_value(z)
|
|
||||||
|
|
||||||
print
|
|
||||||
time.sleep(.5)
|
|
@ -1,61 +0,0 @@
|
|||||||
#!/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_cwlsxxa as sensorObj
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
print "Initializing..."
|
|
||||||
|
|
||||||
# Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
|
||||||
# humidity and A2 for temperature
|
|
||||||
sensor = sensorObj.CWLSXXA(0, 1, 2)
|
|
||||||
|
|
||||||
# update and print available values every second
|
|
||||||
while (1):
|
|
||||||
# update our values from the sensor
|
|
||||||
sensor.update()
|
|
||||||
|
|
||||||
# we show both C and F for temperature
|
|
||||||
print "Temperature:", sensor.getTemperature(), "C /",
|
|
||||||
print sensor.getTemperature(True), "F"
|
|
||||||
|
|
||||||
print "Humidity:", sensor.getHumidity(), "%"
|
|
||||||
|
|
||||||
print "CO2:", sensor.getCO2(), "ppm"
|
|
||||||
|
|
||||||
print
|
|
||||||
time.sleep(1)
|
|
@ -1,106 +0,0 @@
|
|||||||
#!/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_h803x as sensorObj
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting..."
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
defaultDev = "/dev/ttyUSB0"
|
|
||||||
|
|
||||||
# if an argument was specified, use it as the device instead
|
|
||||||
if (len(sys.argv) > 1):
|
|
||||||
defaultDev = sys.argv[1]
|
|
||||||
|
|
||||||
print "Using device", defaultDev
|
|
||||||
print "Initializing..."
|
|
||||||
|
|
||||||
# Instantiate an H803X instance, using MODBUS slave address 1, and
|
|
||||||
# default comm parameters (9600, 8, N, 2)
|
|
||||||
sensor = sensorObj.H803X(defaultDev, 1)
|
|
||||||
|
|
||||||
# output the serial number and firmware revision
|
|
||||||
print "Slave ID:", sensor.getSlaveID()
|
|
||||||
|
|
||||||
print
|
|
||||||
|
|
||||||
# update and print available values every second
|
|
||||||
while (1):
|
|
||||||
# update our values from the sensor
|
|
||||||
sensor.update()
|
|
||||||
|
|
||||||
# H8035 / H8036
|
|
||||||
print "Consumption (kWh):", sensor.getConsumption()
|
|
||||||
print "Real Power (kW):", sensor.getRealPower()
|
|
||||||
|
|
||||||
if (sensor.isH8036()):
|
|
||||||
# The H8036 has much more data available...
|
|
||||||
|
|
||||||
print "Reactive Power (kVAR):", sensor.getReactivePower()
|
|
||||||
print "Apparent Power (kVA):", sensor.getApparentPower()
|
|
||||||
print "Power Factor:", sensor.getPowerFactor()
|
|
||||||
print "Volts Line to Line:", sensor.getVoltsLineToLine()
|
|
||||||
print "Volts Line to Neutral:", sensor.getVoltsLineToNeutral()
|
|
||||||
|
|
||||||
print "Current:", sensor.getCurrent()
|
|
||||||
|
|
||||||
print "Real Power Phase A (kW):", sensor.getRealPowerPhaseA()
|
|
||||||
print "Real Power Phase B (kW):", sensor.getRealPowerPhaseB()
|
|
||||||
print "Real Power Phase C (kW):", sensor.getRealPowerPhaseC()
|
|
||||||
|
|
||||||
print "Power Factor Phase A:", sensor.getPowerFactorPhaseA()
|
|
||||||
print "Power Factor Phase B:", sensor.getPowerFactorPhaseB()
|
|
||||||
print "Power Factor Phase C:", sensor.getPowerFactorPhaseC()
|
|
||||||
|
|
||||||
print "Volts Phase A to B:", sensor.getVoltsPhaseAToB()
|
|
||||||
print "Volts Phase B to C:", sensor.getVoltsPhaseBToC()
|
|
||||||
print "Volts Phase A to C:", sensor.getVoltsPhaseAToC()
|
|
||||||
print "Volts Phase A to Neutral: ",
|
|
||||||
print sensor.getVoltsPhaseAToNeutral()
|
|
||||||
print "Volts Phase B to Neutral: ",
|
|
||||||
print sensor.getVoltsPhaseBToNeutral()
|
|
||||||
print "Volts Phase C to Neutral: ",
|
|
||||||
print sensor.getVoltsPhaseCToNeutral()
|
|
||||||
|
|
||||||
print "Current Phase A:", sensor.getCurrentPhaseA()
|
|
||||||
print "Current Phase B:", sensor.getCurrentPhaseB()
|
|
||||||
print "Current Phase C:", sensor.getCurrentPhaseC()
|
|
||||||
|
|
||||||
print "Avg Real Power (kW):", sensor.getAvgRealPower()
|
|
||||||
print "Min Real Power (kW):", sensor.getMinRealPower()
|
|
||||||
print "Max Real Power (kW):", sensor.getMaxRealPower()
|
|
||||||
|
|
||||||
print
|
|
||||||
time.sleep(2)
|
|
@ -1,65 +0,0 @@
|
|||||||
#!/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_teams as sensorObj
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
print "Initializing..."
|
|
||||||
|
|
||||||
# Instantiate an TEAMS instance, using A0 for temperature, and
|
|
||||||
# 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
|
||||||
# interface)
|
|
||||||
sensor = sensorObj.TEAMS(0, 165.0)
|
|
||||||
|
|
||||||
# update and print available values every second
|
|
||||||
while (1):
|
|
||||||
# update our values from the sensor
|
|
||||||
sensor.update()
|
|
||||||
|
|
||||||
# is the sensor connected? (current >= 4ma)
|
|
||||||
print "Is Connected:", sensor.isConnected()
|
|
||||||
|
|
||||||
# print computed current on the loop. This includes the offset,
|
|
||||||
# if one was set by setOffsetMilliamps().
|
|
||||||
print "Milliamps:", sensor.getRawMilliamps()
|
|
||||||
|
|
||||||
# we show both C and F for temperature
|
|
||||||
print "Temperature:", sensor.getTemperature(), "C /",
|
|
||||||
print sensor.getTemperature(True), "F"
|
|
||||||
|
|
||||||
print
|
|
||||||
time.sleep(1)
|
|
@ -1,65 +0,0 @@
|
|||||||
#!/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_tex00 as sensorObj
|
|
||||||
|
|
||||||
## Exit handlers ##
|
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
|
||||||
def SIGINTHandler(signum, frame):
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
# This function lets you run code on exit
|
|
||||||
def exitHandler():
|
|
||||||
print "Exiting"
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Register exit handlers
|
|
||||||
atexit.register(exitHandler)
|
|
||||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
|
||||||
|
|
||||||
print "Initializing..."
|
|
||||||
|
|
||||||
# Instantiate an TEX00 instance, using A0 for the analog input. In
|
|
||||||
# this example, we are using a 10K Ohm balance resistor and a TED
|
|
||||||
# (10k type 2) thermistor.
|
|
||||||
sensor = sensorObj.TEX00(0, 10000, sensorObj.TEX00.STYPE_THERMISTOR_TED)
|
|
||||||
|
|
||||||
print "Minimum temperature:", sensor.getTemperatureRangeMin(), "C"
|
|
||||||
print "Maximum temperature:", sensor.getTemperatureRangeMax(), "C"
|
|
||||||
print
|
|
||||||
|
|
||||||
# update and print available values every second
|
|
||||||
while (1):
|
|
||||||
# update our values from the sensor
|
|
||||||
sensor.update()
|
|
||||||
|
|
||||||
if (sensor.isOutOfRange()):
|
|
||||||
print "Temperature out of range"
|
|
||||||
else:
|
|
||||||
# we show both C and F for temperature
|
|
||||||
print "Temperature:", sensor.getTemperature(), "C /",
|
|
||||||
print sensor.getTemperature(True), "F"
|
|
||||||
|
|
||||||
print
|
|
||||||
time.sleep(1)
|
|
@ -28,7 +28,6 @@ endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
|||||||
|
|
||||||
macro(upm_SWIG_PYTHON)
|
macro(upm_SWIG_PYTHON)
|
||||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||||
|
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||||
@ -57,8 +56,6 @@ macro(upm_SWIG_NODE)
|
|||||||
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
||||||
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
endwhile ()
|
endwhile ()
|
||||||
|
|
||||||
# include_directories (${NODE_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
@ -80,22 +77,19 @@ macro(upm_SWIG_NODE)
|
|||||||
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
||||||
if (NOT ENABLECXX11)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||||
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
|
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
|
||||||
endif ()
|
|
||||||
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
|
|
||||||
else ()
|
|
||||||
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
|
|
||||||
endif ()
|
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
|
|
||||||
endif ()
|
endif ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
|
||||||
|
else ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
|
||||||
|
endif ()
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
@ -171,11 +165,6 @@ macro(upm_doxygen)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
if (SWIG_FOUND)
|
if (SWIG_FOUND)
|
||||||
if (BUILDSWIGPYTHON)
|
|
||||||
if(NOT PYTHONLIBS_FOUND)
|
|
||||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
if (BUILDSWIGNODE)
|
if (BUILDSWIGNODE)
|
||||||
if(NOT NODE_FOUND)
|
if(NOT NODE_FOUND)
|
||||||
find_package(Node)
|
find_package(Node)
|
||||||
|
@ -30,63 +30,15 @@ ADS1015::setSPS(ADSSAMPLERATE rate){
|
|||||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
|
ADS1015::ADS1015(int bus, uint8_t address) : ADS1X15(bus, address) {
|
||||||
m_name = "ADS1015";
|
m_name = "ADS1015";
|
||||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||||
m_bitShift = 4;
|
m_bitShift = 4;
|
||||||
ADS1X15::getCurrentConfig();
|
ADS1X15::getCurrentConfig();
|
||||||
if (vref < 0.0 || vref > 6.144)
|
|
||||||
UPM_THROW("vref out of range");
|
|
||||||
else if (vref > 4.096)
|
|
||||||
setGain(GAIN_TWOTHIRDS);
|
|
||||||
else if (vref > 2.048)
|
|
||||||
setGain(GAIN_ONE);
|
|
||||||
else if (vref > 1.024)
|
|
||||||
setGain(GAIN_TWO);
|
|
||||||
else if (vref > 0.512)
|
|
||||||
setGain(GAIN_FOUR);
|
|
||||||
else if (vref > 0.256)
|
|
||||||
setGain(GAIN_EIGHT);
|
|
||||||
else
|
|
||||||
setGain(GAIN_SIXTEEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::~ADS1015(){};
|
ADS1015::~ADS1015(){};
|
||||||
|
|
||||||
const char*
|
|
||||||
ADS1015::getModuleName() {
|
|
||||||
return m_name.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
ADS1015::getNumInputs() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
ADS1015::getResolutionInBits() {
|
|
||||||
return 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t
|
|
||||||
ADS1015::getRawValue(unsigned int input) {
|
|
||||||
ADS1X15::ADSMUXMODE mode = getMuxMode(input);
|
|
||||||
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
|
|
||||||
usleep(m_conversionDelay);
|
|
||||||
uint16_t value = i2c->readWordReg(ADS1X15_REG_POINTER_CONVERT);
|
|
||||||
value = value >> m_bitShift;
|
|
||||||
return swapWord(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
float
|
|
||||||
ADS1015::getVoltage(unsigned int input) {
|
|
||||||
ADSMUXMODE mode = getMuxMode(input);
|
|
||||||
return getSample(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Private functions
|
//Private functions
|
||||||
float
|
float
|
||||||
ADS1015::getMultiplier(void){
|
ADS1015::getMultiplier(void){
|
||||||
@ -147,20 +99,4 @@ ADS1015::setDelay(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1X15::ADSMUXMODE
|
|
||||||
ADS1015::getMuxMode(unsigned int input) {
|
|
||||||
ADS1X15::ADSMUXMODE mode;
|
|
||||||
switch (input) {
|
|
||||||
case 0:
|
|
||||||
return SINGLE_0;
|
|
||||||
case 1:
|
|
||||||
return SINGLE_1;
|
|
||||||
case 2:
|
|
||||||
return SINGLE_2;
|
|
||||||
case 3:
|
|
||||||
return SINGLE_3;
|
|
||||||
default:
|
|
||||||
UPM_THROW("Invalid input");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -26,9 +26,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ads1x15.h"
|
#include "ads1x15.h"
|
||||||
#include "upm/iADC.h"
|
|
||||||
|
|
||||||
#define ADS1015_VREF 2.048
|
|
||||||
|
|
||||||
/*=========================================================================
|
/*=========================================================================
|
||||||
CONVERSION DELAY (in microS)
|
CONVERSION DELAY (in microS)
|
||||||
@ -83,7 +82,7 @@ namespace upm {
|
|||||||
* @image html ads1015.jpg
|
* @image html ads1015.jpg
|
||||||
* @snippet ads1x15.cxx Interesting
|
* @snippet ads1x15.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class ADS1015 : public ADS1X15, public IADC {
|
class ADS1015 : public ADS1X15 {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -112,16 +111,12 @@ namespace upm {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1015 constructor
|
* ADS1X15 constructor
|
||||||
*
|
|
||||||
* This constructor includes a vref parameter that can be used
|
|
||||||
* to set gain so it matches full scale value of input
|
|
||||||
*
|
*
|
||||||
* @param bus i2c bus the sensor is attached to.
|
* @param bus i2c bus the sensor is attached to.
|
||||||
* @param address. Optional device address. Default is 0x48.
|
* @param address. Device address. Default is 0x48.
|
||||||
* @param vref. Optional reference (i.e. half full swing) voltage. Default is 2.048V
|
|
||||||
*/
|
*/
|
||||||
ADS1015 (int bus, uint8_t address = 0x48, float vref = ADS1015_VREF);
|
ADS1015 (int bus, uint8_t address = 0x48);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1X15 destructor
|
* ADS1X15 destructor
|
||||||
@ -137,48 +132,9 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get number of inputs
|
|
||||||
*
|
|
||||||
* @return number of inputs
|
|
||||||
*/
|
|
||||||
unsigned int getNumInputs();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read current value for current single ended analogue input
|
|
||||||
*
|
|
||||||
* @return current conversion value
|
|
||||||
*/
|
|
||||||
uint16_t getRawValue(unsigned int input);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read current voltage for current single ended analogue input
|
|
||||||
*
|
|
||||||
* @return current voltage
|
|
||||||
*/
|
|
||||||
float getVoltage(unsigned int input);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read current voltage for current single ended analogue input
|
|
||||||
*
|
|
||||||
* @return current voltage
|
|
||||||
*/
|
|
||||||
unsigned int getResolutionInBits();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns module name
|
|
||||||
*
|
|
||||||
* @return modulename as const char*
|
|
||||||
*/
|
|
||||||
const char* getModuleName();
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getMultiplier(void);
|
float getMultiplier(void);
|
||||||
void setDelay(void);
|
void setDelay(void);
|
||||||
|
|
||||||
private:
|
|
||||||
ADS1X15::ADSMUXMODE getMuxMode(unsigned int input);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -233,8 +233,7 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
|
|||||||
uint8_t
|
uint8_t
|
||||||
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
||||||
{
|
{
|
||||||
uint8_t tdata[16] = { AM2315_READ, static_cast<uint8_t>(reg),
|
uint8_t tdata[16] = { AM2315_READ, reg, ilen };
|
||||||
static_cast<uint8_t>(ilen) };
|
|
||||||
|
|
||||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||||
int iLoops = 5;
|
int iLoops = 5;
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
set (libname "apa102")
|
|
||||||
set (libdescription "upm apa102 led strip spi output module")
|
|
||||||
set (module_src ${libname}.cxx)
|
|
||||||
set (module_h ${libname}.h)
|
|
||||||
upm_module_init()
|
|
@ -1,166 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
* Copyright (c) 2016 Yannick Adam
|
|
||||||
*
|
|
||||||
* 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 <cstring>
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "apa102.h"
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
|
|
||||||
APA102::APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode, int8_t csn)
|
|
||||||
: m_ledCount(ledCount), m_batchMode(batchMode)
|
|
||||||
{
|
|
||||||
mraa::Result res = mraa::SUCCESS;
|
|
||||||
m_leds = NULL;
|
|
||||||
|
|
||||||
// Optional chip select pin
|
|
||||||
m_csnPinCtx = NULL;
|
|
||||||
if (csn > -1) {
|
|
||||||
m_csnPinCtx = new mraa::Gpio(csn);
|
|
||||||
res = m_csnPinCtx->dir(mraa::DIR_OUT);
|
|
||||||
if (res != mraa::SUCCESS) {
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": GPIO failed to set direction");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CSOff();
|
|
||||||
// Initialize SPI
|
|
||||||
m_spi = new mraa::Spi(spiBus);
|
|
||||||
|
|
||||||
// Initialize LED array
|
|
||||||
uint16_t endFrameLength = (m_ledCount + 15) / 16; // End frame should be (leds/2) bits
|
|
||||||
m_frameLength = endFrameLength + (m_ledCount + 1) * 4;
|
|
||||||
if ((m_leds = (uint8_t*) malloc(m_frameLength))) {
|
|
||||||
memset(m_leds, 0x00, m_frameLength - 4); // Clear state
|
|
||||||
memset(&m_leds[m_frameLength - endFrameLength], 0xFF, endFrameLength); // Frame End
|
|
||||||
|
|
||||||
// Need to set the brightness to "0" for each Led
|
|
||||||
for (int i = 1; i <= m_ledCount; i++) {
|
|
||||||
m_leds[i * 4] = 224;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": Failed to allocate memory for LED Strip");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
APA102::~APA102()
|
|
||||||
{
|
|
||||||
// Clear leds
|
|
||||||
if (m_leds) {
|
|
||||||
free(m_leds);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear SPI
|
|
||||||
if (m_spi) {
|
|
||||||
delete m_spi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear GPIO
|
|
||||||
if (m_csnPinCtx) {
|
|
||||||
delete m_csnPinCtx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
|
||||||
{
|
|
||||||
setLeds(ledIdx, ledIdx, brightness, r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
|
||||||
{
|
|
||||||
setLeds(0, m_ledCount - 1, brightness, r, g, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
|
||||||
{
|
|
||||||
uint16_t s_idx = (startIdx + 1) * 4;
|
|
||||||
uint16_t e_idx = (endIdx + 1) * 4;
|
|
||||||
|
|
||||||
for (uint16_t i = s_idx; i <= e_idx; i += 4) {
|
|
||||||
m_leds[i] = brightness | 224;
|
|
||||||
m_leds[i + 1] = b;
|
|
||||||
m_leds[i + 2] = g;
|
|
||||||
m_leds[i + 3] = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_batchMode) {
|
|
||||||
pushState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
|
|
||||||
{
|
|
||||||
uint16_t s_idx = (startIdx + 1) * 4;
|
|
||||||
memcpy(&m_leds[s_idx], colors, (endIdx - startIdx + 1) * 4);
|
|
||||||
|
|
||||||
if (!m_batchMode) {
|
|
||||||
pushState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
APA102::pushState(void)
|
|
||||||
{
|
|
||||||
CSOn();
|
|
||||||
m_spi->write(m_leds, m_frameLength);
|
|
||||||
CSOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* **************
|
|
||||||
* private area
|
|
||||||
* **************
|
|
||||||
*/
|
|
||||||
|
|
||||||
mraa::Result
|
|
||||||
APA102::CSOn()
|
|
||||||
{
|
|
||||||
if (m_csnPinCtx) {
|
|
||||||
return m_csnPinCtx->write(HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa::Result
|
|
||||||
APA102::CSOff()
|
|
||||||
{
|
|
||||||
if (m_csnPinCtx) {
|
|
||||||
return m_csnPinCtx->write(LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
|
||||||
}
|
|
@ -1,143 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yannick Adam <yannick.adam@gmail.com>
|
|
||||||
* Copyright (c) 2016 Yannick Adam
|
|
||||||
*
|
|
||||||
* 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 <mraa/gpio.hpp>
|
|
||||||
#include <mraa/spi.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define HIGH 1
|
|
||||||
#define LOW 0
|
|
||||||
|
|
||||||
namespace upm
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief APA102 RGB LED Strip driver library
|
|
||||||
* @defgroup apa102 libupm-apa102
|
|
||||||
* @ingroup spi led
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @library apa102
|
|
||||||
* @sensor apa102
|
|
||||||
* @comname APA102/DotStar LED Strip
|
|
||||||
* @type led
|
|
||||||
* @man adafruit
|
|
||||||
* @con spi
|
|
||||||
*
|
|
||||||
* @brief API for controlling APA102/DotStar RGB LED Strips
|
|
||||||
*
|
|
||||||
* APA102 LED Strips provide individually controllable LEDs through a SPI interface.
|
|
||||||
* For each LED, brightness (0-31) and RGB (0-255) values can be set.
|
|
||||||
*
|
|
||||||
* @image html apa102.jpg
|
|
||||||
* @snippet apa102.cxx Interesting
|
|
||||||
*/
|
|
||||||
class APA102
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Instantiates a new APA102 LED Strip
|
|
||||||
*
|
|
||||||
* @param ledCount Number of APA102 leds in the strip
|
|
||||||
* @param spiBus SPI Bus number
|
|
||||||
* @param batchMode (optional) Immediatly write to SPI (false, default) or wait for a pushState
|
|
||||||
* call (true)
|
|
||||||
* @param csn (optional) Chip Select Pin
|
|
||||||
*/
|
|
||||||
APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode = false, int8_t csn = -1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APA102 destructor
|
|
||||||
*/
|
|
||||||
~APA102();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the color for a single led
|
|
||||||
*
|
|
||||||
* @param ledIdx Index of the LED in the strip (0 based)
|
|
||||||
* @param brightness Brightness value (0-31)
|
|
||||||
* @param r Red component (0-255)
|
|
||||||
* @param g Green component (0-255)
|
|
||||||
* @param b Blue component (0-255)
|
|
||||||
*/
|
|
||||||
void setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the color for all leds
|
|
||||||
*
|
|
||||||
* @param brightness Brightness value (0-31)
|
|
||||||
* @param r Red component (0-255)
|
|
||||||
* @param g Green component (0-255)
|
|
||||||
* @param b Blue component (0-255)
|
|
||||||
*/
|
|
||||||
void setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the color for a range of leds
|
|
||||||
*
|
|
||||||
* @param startIdx Start index of the range of LEDs in the strip (0 based)
|
|
||||||
* @param endIdx End index of the range of LEDs in the strip (0 based)
|
|
||||||
* @param brightness Brightness value (0-31)
|
|
||||||
* @param r Red component (0-255)
|
|
||||||
* @param g Green component (0-255)
|
|
||||||
* @param b Blue component (0-255)
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Advanced) Manually control the colors of a range of LEDS
|
|
||||||
* Best used to maximize performance
|
|
||||||
*
|
|
||||||
* @param startIdx Start index of the range of LEDs to update (0 based)
|
|
||||||
* @param endIdx End index of the range of LEDs to update (0 based)
|
|
||||||
* @param colors Pointer to an array of bytes. Each color is described as the following:
|
|
||||||
* B1: Brightness (224-255) B2: Blue (0-255) B3: Green (0-255) B4: Red
|
|
||||||
*(0-255)
|
|
||||||
* No check done on the boundaries
|
|
||||||
*/
|
|
||||||
void setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Outputs the current LED data to the SPI bus
|
|
||||||
* Note: Only required if batch mode is set to TRUE
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void pushState();
|
|
||||||
|
|
||||||
private:
|
|
||||||
mraa::Spi* m_spi;
|
|
||||||
mraa::Gpio* m_csnPinCtx;
|
|
||||||
|
|
||||||
uint16_t m_ledCount;
|
|
||||||
uint8_t* m_leds;
|
|
||||||
uint16_t m_frameLength;
|
|
||||||
|
|
||||||
bool m_batchMode;
|
|
||||||
|
|
||||||
mraa::Result CSOn();
|
|
||||||
mraa::Result CSOff();
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
%module javaupm_apa102
|
|
||||||
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "typemaps.i"
|
|
||||||
|
|
||||||
%typemap(jtype) (uint8_t *colors) "byte[]"
|
|
||||||
%typemap(jstype) (uint8_t *colors) "byte[]"
|
|
||||||
%typemap(jni) (uint8_t *colors) "jbyteArray"
|
|
||||||
%typemap(javain) (uint8_t *colors) "$javainput"
|
|
||||||
|
|
||||||
%typemap(in) (uint8_t *colors) {
|
|
||||||
$1 = (uint8_t*)JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "apa102.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "apa102.h"
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_apa102");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,19 +0,0 @@
|
|||||||
%module jsupm_apa102
|
|
||||||
|
|
||||||
%include "../upm.i"
|
|
||||||
%inline %{
|
|
||||||
#include <node_buffer.h>
|
|
||||||
%}
|
|
||||||
|
|
||||||
%typemap(in) (uint8_t *colors) {
|
|
||||||
if (!node::Buffer::HasInstance($input)) {
|
|
||||||
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
|
|
||||||
}
|
|
||||||
$1 = (uint8_t*) node::Buffer::Data($input);
|
|
||||||
}
|
|
||||||
|
|
||||||
%include "apa102.h"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "apa102.h"
|
|
||||||
%}
|
|
@ -1,25 +0,0 @@
|
|||||||
// Include doxygen-generated documentation
|
|
||||||
%include "pyupm_doxy2swig.i"
|
|
||||||
|
|
||||||
%module pyupm_apa102
|
|
||||||
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
|
||||||
|
|
||||||
// setLeds
|
|
||||||
%typemap(in) (uint8_t *colors) {
|
|
||||||
if (PyByteArray_Check($input)) {
|
|
||||||
$1 = (uint8_t*) PyByteArray_AsString($input);
|
|
||||||
} else {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "bytearray expected");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%include "apa102.h"
|
|
||||||
|
|
||||||
%{
|
|
||||||
|
|
||||||
#include "apa102.h"
|
|
||||||
%}
|
|
@ -1,6 +0,0 @@
|
|||||||
include_directories(..)
|
|
||||||
set (libname "bme280")
|
|
||||||
set (libdescription "upm bme280 temperature humidity pressure sensor module")
|
|
||||||
set (module_src ${libname}.cxx bme280driver.cxx)
|
|
||||||
set (module_h ${libname}.h bme280driver.h)
|
|
||||||
upm_module_init()
|
|
@ -1,485 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Aditya Nagal <adityax.nagal@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 <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "bme280.h"
|
|
||||||
#include "bme280driver.h"
|
|
||||||
/************** I2C buffer length ******/
|
|
||||||
#define I2C_BUFFER_LEN 26
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
|
||||||
* struct bme280_t parameters can be accessed by using bme280
|
|
||||||
* bme280_t having the following parameters
|
|
||||||
* Bus write function pointer: BME280_WR_FUNC_PTR
|
|
||||||
Bus read function pointer: BME280_RD_FUNC_PTR
|
|
||||||
* Delay function pointer: delay_msec
|
|
||||||
* I2C address: dev_addr
|
|
||||||
* Chip id of the sensor: chip_id
|
|
||||||
*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
struct bme280_t bme280;
|
|
||||||
|
|
||||||
static struct bme280_t *p_bme280; /**< pointer to BME280 */
|
|
||||||
mraa::I2c* BME280::m_i2c = NULL;
|
|
||||||
int BME280::m_bus = 0;
|
|
||||||
|
|
||||||
BME280::BME280 (int bus, int devAddr) {
|
|
||||||
m_bus = bus;
|
|
||||||
if( m_i2c == NULL)
|
|
||||||
{
|
|
||||||
m_i2c = new mraa::I2c(m_bus);
|
|
||||||
m_i2c->address(BME280_I2C_ADDRESS1);
|
|
||||||
//Based on the requirement, configure I2C interface.
|
|
||||||
I2C_routine();
|
|
||||||
/*--------------------------------------------------------------------------*
|
|
||||||
* This function used to assign the value/reference of
|
|
||||||
* the following parameters
|
|
||||||
* I2C address
|
|
||||||
* Bus Write
|
|
||||||
* Bus read
|
|
||||||
* Chip id
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
bme280_init(&bme280);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BME280::~BME280() {
|
|
||||||
delete m_i2c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor temperature
|
|
||||||
* \param: None
|
|
||||||
* \return: compensated temperature
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getTemperatureInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated temperature*/
|
|
||||||
int32_t v_data_uncomp_tem_int32 = getTemperatureRawInternal();
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ TRUE PRESSURE, TEMPERATURE AND HUMIDITY DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
/* API is used to read the true temperature*/
|
|
||||||
/* Input value as uncompensated temperature and output format*/
|
|
||||||
int32_t v_actual_temp_int32 = bme280_compensate_temperature_int32(v_data_uncomp_tem_int32);
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ TRUE TEMPERATURE ********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
return v_actual_temp_int32;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor pressure
|
|
||||||
* \param: None
|
|
||||||
* \return: compensated pressure
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getPressureInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated pressure*/
|
|
||||||
int32_t v_data_uncomp_pres_int32 = getPressureRawInternal();
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ TRUE PRESSURE DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
/* API is used to read the true pressure*/
|
|
||||||
/* Input value as uncompensated pressure */
|
|
||||||
uint32_t v_actual_press_uint32 = bme280_compensate_pressure_int32(v_data_uncomp_pres_int32);
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ TRUE PRESSURE ********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
return v_actual_press_uint32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor humidity
|
|
||||||
* \param: None
|
|
||||||
* \return: compensated humidity
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getHumidityInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated pressure*/
|
|
||||||
int32_t v_data_uncomp_hum_int32 = getHumidityRawInternal();
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ TRUE HUMIDITY DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
/* API is used to read the true humidity*/
|
|
||||||
/* Input value as uncompensated humidity and output format*/
|
|
||||||
uint32_t v_actual_humity_uint32 = bme280_compensate_humidity_int32(v_data_uncomp_hum_int32);
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ TRUE HUMIDITY ********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
return v_actual_humity_uint32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor temperature
|
|
||||||
* \param: None
|
|
||||||
* \return: uncompensated temperature
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getTemperatureRawInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated temperature*/
|
|
||||||
int32_t v_data_uncomp_tem_int32 = BME280_INIT_VALUE;
|
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
|
||||||
* the sensor as "NORMAL"
|
|
||||||
* data acquisition/read/write is possible in this mode
|
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
|
||||||
/* Set the power mode as NORMAL*/
|
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
|
||||||
/* For reading the temperature data it is required to
|
|
||||||
* set the OSS setting of temperature
|
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
|
||||||
|
|
||||||
/* set the temperature oversampling*/
|
|
||||||
bme280_set_oversamp_temperature(BME280_OVERSAMP_4X);
|
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ UNCOMPENSATED TEMPERATURE DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
/* API is used to read the uncompensated temperature*/
|
|
||||||
bme280_read_uncomp_temperature(&v_data_uncomp_tem_int32);
|
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ UNCOMPENSATED TEMPERATURE ********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*
|
|
||||||
************************* START DE-INITIALIZATION ***********************
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
/* For de-initialization it is required to set the mode of
|
|
||||||
* the sensor as "SLEEP"
|
|
||||||
* the device reaches the lowest power consumption only
|
|
||||||
* In SLEEP mode no measurements are performed
|
|
||||||
* All registers are accessible
|
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
|
||||||
/* Set the power mode as SLEEP*/
|
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
|
||||||
/*---------------------------------------------------------------------*
|
|
||||||
************************* END DE-INITIALIZATION **********************
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
return v_data_uncomp_tem_int32;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor pressure
|
|
||||||
* \param: None
|
|
||||||
* \return: uncompensated pressure
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getPressureRawInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated pressure*/
|
|
||||||
int32_t v_data_uncomp_pres_int32 = BME280_INIT_VALUE;
|
|
||||||
|
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
|
||||||
* the sensor as "NORMAL"
|
|
||||||
* data acquisition/read/write is possible in this mode
|
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
|
||||||
/* Set the power mode as NORMAL*/
|
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
|
||||||
/* For reading the pressure data it is required to
|
|
||||||
* set the OSS setting of humidity, pressure and temperature
|
|
||||||
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
|
||||||
* data acquisition options of the device.
|
|
||||||
* changes to this registers only become effective after a write operation to
|
|
||||||
* "BME280_CTRLMEAS_REG" register.
|
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
|
||||||
|
|
||||||
/* set the pressure oversampling*/
|
|
||||||
bme280_set_oversamp_pressure(BME280_OVERSAMP_2X);
|
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ UNCOMPENSATED PRESSURE DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* API is used to read the uncompensated pressure*/
|
|
||||||
bme280_read_uncomp_pressure(&v_data_uncomp_pres_int32);
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ UNCOMPENSATED PRESSURE ********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*
|
|
||||||
************************* START DE-INITIALIZATION ***********************
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
/* For de-initialization it is required to set the mode of
|
|
||||||
* the sensor as "SLEEP"
|
|
||||||
* the device reaches the lowest power consumption only
|
|
||||||
* In SLEEP mode no measurements are performed
|
|
||||||
* All registers are accessible
|
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
|
||||||
/* Set the power mode as SLEEP*/
|
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
|
||||||
/*---------------------------------------------------------------------*
|
|
||||||
************************* END DE-INITIALIZATION **********************
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
return v_data_uncomp_pres_int32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* This function is an example for reading sensor humidity
|
|
||||||
* \param: None
|
|
||||||
* \return: uncompensated humidity
|
|
||||||
*/
|
|
||||||
|
|
||||||
int32_t BME280::getHumidityRawInternal(void)
|
|
||||||
{
|
|
||||||
/* The variable used to read uncompensated pressure*/
|
|
||||||
int32_t v_data_uncomp_hum_int32 = BME280_INIT_VALUE;
|
|
||||||
|
|
||||||
/* For initialization it is required to set the mode of
|
|
||||||
* the sensor as "NORMAL"
|
|
||||||
* data acquisition/read/write is possible in this mode
|
|
||||||
* by using the below API able to set the power mode as NORMAL*/
|
|
||||||
/* Set the power mode as NORMAL*/
|
|
||||||
bme280_set_power_mode(BME280_NORMAL_MODE);
|
|
||||||
/* For reading humidity data it is required to
|
|
||||||
* set the OSS setting of humidity
|
|
||||||
* The "BME280_CTRLHUM_REG_OSRSH" register sets the humidity
|
|
||||||
* data acquisition options of the device.
|
|
||||||
* changes to this registers only become effective after a write operation to
|
|
||||||
* "BME280_CTRLMEAS_REG" register.
|
|
||||||
* In the code automated reading and writing of "BME280_CTRLHUM_REG_OSRSH"
|
|
||||||
* register first set the "BME280_CTRLHUM_REG_OSRSH" and then read and write
|
|
||||||
* the "BME280_CTRLMEAS_REG" register in the function*/
|
|
||||||
bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
|
|
||||||
|
|
||||||
|
|
||||||
/************************* END INITIALIZATION *************************/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
|
||||||
************ START READ HUMIDITY DATA ********
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
/* API is used to read the uncompensated humidity*/
|
|
||||||
bme280_read_uncomp_humidity(&v_data_uncomp_hum_int32);
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------*
|
|
||||||
************ END READ UNCOMPENSATED PRESSURE AND TEMPERATURE********
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*
|
|
||||||
************************* START DE-INITIALIZATION ***********************
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
/* For de-initialization it is required to set the mode of
|
|
||||||
* the sensor as "SLEEP"
|
|
||||||
* the device reaches the lowest power consumption only
|
|
||||||
* In SLEEP mode no measurements are performed
|
|
||||||
* All registers are accessible
|
|
||||||
* by using the below API able to set the power mode as SLEEP*/
|
|
||||||
/* Set the power mode as SLEEP*/
|
|
||||||
bme280_set_power_mode(BME280_SLEEP_MODE);
|
|
||||||
/*---------------------------------------------------------------------*
|
|
||||||
************************* END DE-INITIALIZATION **********************
|
|
||||||
*---------------------------------------------------------------------*/
|
|
||||||
return v_data_uncomp_hum_int32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*
|
|
||||||
* The following function is used to map the I2C bus read, write, delay and
|
|
||||||
* device address with global structure bme280
|
|
||||||
*-------------------------------------------------------------------------*/
|
|
||||||
int8_t BME280::I2C_routine()
|
|
||||||
{
|
|
||||||
/*--------------------------------------------------------------------------*
|
|
||||||
* By using bme280 the following structure parameter can be accessed
|
|
||||||
* Bus write function pointer: BME280_WR_FUNC_PTR
|
|
||||||
* Bus read function pointer: BME280_RD_FUNC_PTR
|
|
||||||
* Delay function pointer: delay_msec
|
|
||||||
* I2C address: dev_addr
|
|
||||||
*--------------------------------------------------------------------------*/
|
|
||||||
// bme280.bus_write = &BME280::BME280_I2C_bus_write;
|
|
||||||
bme280.bus_write = BME280_I2C_bus_write;
|
|
||||||
|
|
||||||
//bme280.bus_write = BME280_I2C_bus_write_dummy;
|
|
||||||
bme280.bus_read = BME280_I2C_bus_read;
|
|
||||||
bme280.dev_addr = BME280_I2C_ADDRESS1;
|
|
||||||
bme280.delay_msec = BME280_delay_msek;
|
|
||||||
|
|
||||||
return BME280_INIT_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------*
|
|
||||||
* The device address defined in the bme280.h file
|
|
||||||
*-----------------------------------------------------------------------*/
|
|
||||||
int32_t BME280::i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt)
|
|
||||||
{
|
|
||||||
mraa::Result ret;
|
|
||||||
m_i2c->address(dev_addr);
|
|
||||||
|
|
||||||
if((ret = m_i2c->write((const uint8_t*) (ptr), cnt)) != 0)
|
|
||||||
{
|
|
||||||
UPM_THROW("I2C write error");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* \Brief: The function is used as I2C bus write
|
|
||||||
* \Return : Status of the I2C write
|
|
||||||
* \param dev_addr : The device address of the sensor
|
|
||||||
* \param reg_addr : Address of the first register, will data is going to be written
|
|
||||||
* \param reg_data : It is a value hold in the array,
|
|
||||||
* will be used for write the value into the register
|
|
||||||
* \param cnt : The no of byte of data to be write
|
|
||||||
*/
|
|
||||||
|
|
||||||
int8_t BME280::BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
|
||||||
|
|
||||||
{
|
|
||||||
int32_t iError = BME280_INIT_VALUE;
|
|
||||||
static uint8_t array[I2C_BUFFER_LEN];
|
|
||||||
for (int i=0; i<I2C_BUFFER_LEN; i++) array[i]=0;
|
|
||||||
|
|
||||||
uint8_t stringpos = BME280_INIT_VALUE;
|
|
||||||
array[BME280_INIT_VALUE] = reg_addr;
|
|
||||||
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
|
||||||
array[stringpos + BME280_ONE_U8X] = *(reg_data + stringpos);
|
|
||||||
}
|
|
||||||
iError = i2c_write_string(dev_addr,array, cnt+1);
|
|
||||||
return (int8_t)iError;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t BME280::i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt)
|
|
||||||
{
|
|
||||||
mraa::Result ret;
|
|
||||||
|
|
||||||
m_i2c->address(dev_addr);
|
|
||||||
|
|
||||||
if( m_i2c->readBytesReg(reg_addr, ptr, cnt) != cnt)
|
|
||||||
{
|
|
||||||
UPM_THROW("bme280 register read failed");
|
|
||||||
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* \Brief: The function is used as I2C bus read
|
|
||||||
* \Return : Status of the I2C read
|
|
||||||
* \param dev_addr : The device address of the sensor
|
|
||||||
* \param reg_addr : Address of the first register, will data is going to be read
|
|
||||||
* \param reg_data : This data read from the sensor, which is hold in an array
|
|
||||||
* \param cnt : The no of data byte of to be read
|
|
||||||
*/
|
|
||||||
int8_t BME280::BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
|
|
||||||
{
|
|
||||||
int32_t iError = BME280_INIT_VALUE;
|
|
||||||
uint8_t array[I2C_BUFFER_LEN] = {BME280_INIT_VALUE};
|
|
||||||
uint8_t stringpos = BME280_INIT_VALUE;
|
|
||||||
array[BME280_INIT_VALUE] = reg_addr;
|
|
||||||
i2c_write_read_string(dev_addr,reg_addr,array,cnt);
|
|
||||||
for (stringpos = BME280_INIT_VALUE; stringpos < cnt; stringpos++) {
|
|
||||||
*(reg_data + stringpos) = array[stringpos];
|
|
||||||
}
|
|
||||||
return (int8_t)iError;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Brief : The delay routine
|
|
||||||
* \param : delay in ms
|
|
||||||
*/
|
|
||||||
void BME280::BME280_delay_msek(uint16_t mseconds)
|
|
||||||
{
|
|
||||||
struct timespec sleepTime;
|
|
||||||
|
|
||||||
sleepTime.tv_sec = mseconds / 1000; // Number of seconds
|
|
||||||
sleepTime.tv_nsec = ( mseconds % 1000 ) * 1000000; // Convert fractional seconds to nanoseconds
|
|
||||||
|
|
||||||
// Iterate nanosleep in a loop until the total sleep time is the original
|
|
||||||
// value of the seconds parameter
|
|
||||||
while ( ( nanosleep( &sleepTime, &sleepTime ) != 0 ) && ( errno == EINTR ) );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get temperature measurement.
|
|
||||||
*/
|
|
||||||
uint16_t BME280::getTemperatureRaw (){ return BME280::getTemperatureRawInternal(); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get temperature measurement.
|
|
||||||
*/
|
|
||||||
int BME280::getTemperatureCelcius (){ return (BME280::getTemperatureInternal() + 50) /100; }
|
|
||||||
/**
|
|
||||||
* Get relative humidity measurement.
|
|
||||||
*/
|
|
||||||
uint16_t BME280::getHumidityRaw (){ return BME280::getHumidityRawInternal(); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get relative humidity measurement.
|
|
||||||
*/
|
|
||||||
int BME280::getHumidityRelative (){ return (BME280::getHumidityInternal() + 500) / 1000; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return pressure
|
|
||||||
*/
|
|
||||||
uint32_t BME280::getPressureRaw(){ return BME280::getPressureRawInternal(); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return calculated pressure (Pa)
|
|
||||||
*/
|
|
||||||
int BME280::getPressurePa(){ return BME280::getPressureInternal(); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
|||||||
#include <mraa/i2c.hpp>
|
|
||||||
#include "upm/iPressureSensor.h"
|
|
||||||
#include "upm/iTemperatureSensor.h"
|
|
||||||
#include "upm/iHumiditySensor.h"
|
|
||||||
#ifndef __BME280_H__
|
|
||||||
#define __BME280_H__
|
|
||||||
|
|
||||||
|
|
||||||
//#define BME280_MDELAY_DATA_TYPE uint32_t
|
|
||||||
|
|
||||||
/****************************************************/
|
|
||||||
/**\name I2C ADDRESS DEFINITIONS */
|
|
||||||
/***************************************************/
|
|
||||||
#define BME280_I2C_ADDRESS1 (0x76)
|
|
||||||
#define BME280_I2C_ADDRESS2 (0x77)
|
|
||||||
#define BME280_ONE_U8X (1)
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BME280 : public ITemperatureSensor, public IHumiditySensor, public IPressureSensor {
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instanciates a BME280 object
|
|
||||||
*
|
|
||||||
* @param bus number of used bus
|
|
||||||
* @param devAddr address of used i2c device
|
|
||||||
* @param mode BME280 mode
|
|
||||||
*/
|
|
||||||
BME280 (int bus, int devAddr = BME280_I2C_ADDRESS1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BME280 object destructor, basicaly it close i2c connection.
|
|
||||||
*/
|
|
||||||
~BME280 ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get temperature measurement.
|
|
||||||
*/
|
|
||||||
uint16_t getTemperatureRaw ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get temperature measurement.
|
|
||||||
*/
|
|
||||||
int getTemperatureCelcius ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get relative humidity measurement.
|
|
||||||
*/
|
|
||||||
uint16_t getHumidityRaw ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get relative humidity measurement.
|
|
||||||
*/
|
|
||||||
int getHumidityRelative ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns sensor module name
|
|
||||||
*/
|
|
||||||
const char* getModuleName() { return "BME280"; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return pressure
|
|
||||||
*/
|
|
||||||
uint32_t getPressureRaw();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return calculated pressure (Pa)
|
|
||||||
*/
|
|
||||||
int getPressurePa();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return temperature
|
|
||||||
*/
|
|
||||||
int32_t getTemperatureInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return pressure
|
|
||||||
*/
|
|
||||||
int32_t getPressureInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return humidity
|
|
||||||
*/
|
|
||||||
int32_t getHumidityInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return temperature
|
|
||||||
*/
|
|
||||||
int32_t getTemperatureRawInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return pressure
|
|
||||||
*/
|
|
||||||
int32_t getPressureRawInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return humidity
|
|
||||||
*/
|
|
||||||
int32_t getHumidityRawInternal(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the correct chip is present at the given address.
|
|
||||||
*/
|
|
||||||
bool isAvailable();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**************************************************************/
|
|
||||||
/**\name STRUCTURE DEFINITIONS */
|
|
||||||
/**************************************************************/
|
|
||||||
/*!
|
|
||||||
* @brief This structure holds all device specific calibration parameters
|
|
||||||
*/
|
|
||||||
|
|
||||||
static mraa::I2c* m_i2c;
|
|
||||||
static int m_bus;
|
|
||||||
|
|
||||||
static int32_t i2c_write_string(uint8_t dev_addr,uint8_t* ptr, uint8_t cnt);
|
|
||||||
static int32_t i2c_write_read_string(uint8_t dev_addr,uint8_t reg_addr , uint8_t * ptr, uint8_t cnt);
|
|
||||||
static int8_t I2C_routine();
|
|
||||||
static int8_t BME280_I2C_bus_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt);
|
|
||||||
static void BME280_delay_msek(uint16_t msek);
|
|
||||||
static int8_t BME280_I2C_bus_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,23 +0,0 @@
|
|||||||
%module javaupm_bme280
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "arrays_java.i";
|
|
||||||
%include "../java_buffer.i"
|
|
||||||
%include "cpointer.i"
|
|
||||||
%include "typemaps.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "bme280.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "bme280.h"
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_bme280");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,8 +0,0 @@
|
|||||||
%module jsupm_bme280
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "bme280.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "bme280.h"
|
|
@ -1,10 +0,0 @@
|
|||||||
%module pyupm_bme280
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%include "stdint.i"
|
|
||||||
|
|
||||||
%include "bme280.h"
|
|
||||||
%{
|
|
||||||
#include "bme280.h"
|
|
||||||
%}
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
set (libname "bmi160")
|
|
||||||
set (libdescription "Bosch BMI160 Accelerometer, Gyroscope and BMM150 Magnetometer")
|
|
||||||
set (module_src ${libname}.cxx bosch_bmi160.c)
|
|
||||||
set (module_h ${libname}.h)
|
|
||||||
upm_module_init()
|
|
@ -1,433 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// we have to do it the old skool way
|
|
||||||
#include <mraa/i2c.h>
|
|
||||||
|
|
||||||
#include "bmi160.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "bosch_bmi160.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
// We do not need this define anyway. It conflicts with mraa::SUCCESS.
|
|
||||||
#undef SUCCESS
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static mraa_i2c_context i2cContext = NULL;
|
|
||||||
|
|
||||||
// Our bmi160 info structure
|
|
||||||
struct bmi160_t s_bmi160;
|
|
||||||
|
|
||||||
// bus read and write functions for use with the bmi driver code
|
|
||||||
s8 bmi160_i2c_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
|
|
||||||
{
|
|
||||||
if (!i2cContext)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": i2c context is NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
int retries = 10;
|
|
||||||
|
|
||||||
// There seems to be some occasional flakyness with reads when
|
|
||||||
// moving the sensor around
|
|
||||||
while (retries >= 0)
|
|
||||||
{
|
|
||||||
int rv = mraa_i2c_read_bytes_data(i2cContext, reg_addr, reg_data, cnt);
|
|
||||||
|
|
||||||
if (rv < 0)
|
|
||||||
{
|
|
||||||
usleep(100000);
|
|
||||||
retries--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": mraa_i2c_read_bytes_data() failed");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
s8 bmi160_i2c_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
|
|
||||||
{
|
|
||||||
if (!i2cContext)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": i2c context is NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME fprintf(stderr, "%s: %02x: cnt %d\n", __FUNCTION__, reg_addr, cnt);
|
|
||||||
uint8_t buffer[cnt + 1];
|
|
||||||
|
|
||||||
buffer[0] = reg_addr;
|
|
||||||
for (int i=0; i<cnt; i++)
|
|
||||||
buffer[i+1] = reg_data[i];
|
|
||||||
|
|
||||||
mraa_result_t rv = mraa_i2c_write(i2cContext, buffer, cnt+1);
|
|
||||||
|
|
||||||
if (rv != MRAA_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": mraa_i2c_write() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// delay for some milliseconds
|
|
||||||
void bmi160_delay_ms(u32 msek)
|
|
||||||
{
|
|
||||||
usleep(msek * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BMI160::BMI160(int bus, uint8_t address)
|
|
||||||
{
|
|
||||||
m_addr = address;
|
|
||||||
|
|
||||||
// We need to use the C MRAA interface to avoid issue with C++ <-> C
|
|
||||||
// calling convention issues, also we need a global
|
|
||||||
// mraa_i2c_context
|
|
||||||
|
|
||||||
if (!(i2cContext = mraa_i2c_init(bus)))
|
|
||||||
{
|
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
|
||||||
": mraa_i2c_init() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mraa_i2c_address(i2cContext, m_addr) != MRAA_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": mraa_i2c_address() failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// init the driver interface functions
|
|
||||||
s_bmi160.bus_write = bmi160_i2c_bus_write;
|
|
||||||
s_bmi160.bus_read = bmi160_i2c_bus_read;
|
|
||||||
s_bmi160.delay_msec = bmi160_delay_ms;
|
|
||||||
s_bmi160.dev_addr = m_addr;
|
|
||||||
|
|
||||||
// Init our driver interface pointers
|
|
||||||
bmi160_init(&s_bmi160);
|
|
||||||
|
|
||||||
m_accelX = 0.0;
|
|
||||||
m_accelY = 0.0;
|
|
||||||
m_accelZ = 0.0;
|
|
||||||
|
|
||||||
m_gyroX = 0.0;
|
|
||||||
m_gyroY = 0.0;
|
|
||||||
m_gyroZ = 0.0;
|
|
||||||
|
|
||||||
m_magX = 0.0;
|
|
||||||
m_magY = 0.0;
|
|
||||||
m_magZ = 0.0;
|
|
||||||
|
|
||||||
m_accelScale = 1.0;
|
|
||||||
m_gyroScale = 1.0;
|
|
||||||
|
|
||||||
m_magEnabled = false;
|
|
||||||
|
|
||||||
if (!init())
|
|
||||||
{
|
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
|
||||||
": init() failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BMI160::~BMI160()
|
|
||||||
{
|
|
||||||
mraa_i2c_stop(i2cContext);
|
|
||||||
i2cContext = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BMI160::init()
|
|
||||||
{
|
|
||||||
// This should be interesting...
|
|
||||||
const u32 C_BMI160_THIRTY_U8X = 30;
|
|
||||||
|
|
||||||
enableMagnetometer(true);
|
|
||||||
|
|
||||||
/*Set the accel mode as Normal write in the register 0x7E*/
|
|
||||||
bmi160_set_command_register(ACCEL_MODE_NORMAL);
|
|
||||||
|
|
||||||
/* bmi160_delay_ms in ms*/
|
|
||||||
bmi160_delay_ms(C_BMI160_THIRTY_U8X);
|
|
||||||
|
|
||||||
/*Set the gyro mode as Normal write in the register 0x7E*/
|
|
||||||
bmi160_set_command_register(GYRO_MODE_NORMAL);
|
|
||||||
|
|
||||||
/* bmi160_delay_ms in ms*/
|
|
||||||
bmi160_delay_ms(C_BMI160_THIRTY_U8X);
|
|
||||||
|
|
||||||
/* Set the accel bandwidth as OSRS4 */
|
|
||||||
bmi160_set_accel_bw(BMI160_ACCEL_OSR4_AVG1);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
/* Set the gryo bandwidth as Normal */
|
|
||||||
bmi160_set_gyro_bw(BMI160_GYRO_NORMAL_MODE);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
/* set gyro data rate as 200Hz*/
|
|
||||||
bmi160_set_gyro_output_data_rate(BMI160_GYRO_OUTPUT_DATA_RATE_200HZ);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
/* set accel data rate as 200Hz*/
|
|
||||||
bmi160_set_accel_output_data_rate(BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ,
|
|
||||||
BMI160_ACCEL_OSR4_AVG1);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
setAccelerometerScale(ACCEL_RANGE_2G);
|
|
||||||
setGyroscopeScale(GYRO_RANGE_125);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BMI160::update()
|
|
||||||
{
|
|
||||||
struct bmi160_gyro_t gyroxyz;
|
|
||||||
struct bmi160_accel_t accelxyz;
|
|
||||||
struct bmi160_mag_xyz_s32_t magxyz;
|
|
||||||
|
|
||||||
// read gyro data
|
|
||||||
bmi160_read_gyro_xyz(&gyroxyz);
|
|
||||||
|
|
||||||
// read accel data
|
|
||||||
bmi160_read_accel_xyz(&accelxyz);
|
|
||||||
|
|
||||||
// read mag data
|
|
||||||
if (m_magEnabled)
|
|
||||||
bmi160_bmm150_mag_compensate_xyz(&magxyz);
|
|
||||||
|
|
||||||
// read the sensor time
|
|
||||||
u32 v_sensor_time;
|
|
||||||
bmi160_get_sensor_time(&v_sensor_time);
|
|
||||||
m_sensorTime = (unsigned int)v_sensor_time;
|
|
||||||
|
|
||||||
m_accelX = float(accelxyz.x);
|
|
||||||
m_accelY = float(accelxyz.y);
|
|
||||||
m_accelZ = float(accelxyz.z);
|
|
||||||
|
|
||||||
m_gyroX = float(gyroxyz.x);
|
|
||||||
m_gyroY = float(gyroxyz.y);
|
|
||||||
m_gyroZ = float(gyroxyz.z);
|
|
||||||
|
|
||||||
if (m_magEnabled)
|
|
||||||
{
|
|
||||||
m_magX = float(magxyz.x);
|
|
||||||
m_magY = float(magxyz.y);
|
|
||||||
m_magZ = float(magxyz.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::setAccelerometerScale(ACCEL_RANGE_T scale)
|
|
||||||
{
|
|
||||||
s8 v_range = BMI160_ACCEL_RANGE_2G;
|
|
||||||
// store scaling factor
|
|
||||||
|
|
||||||
switch (scale)
|
|
||||||
{
|
|
||||||
case ACCEL_RANGE_2G:
|
|
||||||
v_range = BMI160_ACCEL_RANGE_2G;
|
|
||||||
m_accelScale = 16384.0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACCEL_RANGE_4G:
|
|
||||||
v_range = BMI160_ACCEL_RANGE_4G;
|
|
||||||
m_accelScale = 8192.0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACCEL_RANGE_8G:
|
|
||||||
v_range = BMI160_ACCEL_RANGE_8G;
|
|
||||||
m_accelScale = 4096.0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ACCEL_RANGE_16G:
|
|
||||||
v_range = BMI160_ACCEL_RANGE_16G;
|
|
||||||
m_accelScale = 2048.0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // should never occur, but...
|
|
||||||
m_accelScale = 1.0; // set a safe, though incorrect value
|
|
||||||
throw std::logic_error(string(__FUNCTION__) +
|
|
||||||
": internal error, unsupported scale");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bmi160_set_accel_range(v_range);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::setGyroscopeScale(GYRO_RANGE_T scale)
|
|
||||||
{
|
|
||||||
u8 v_range = BMI160_GYRO_RANGE_2000_DEG_SEC;
|
|
||||||
|
|
||||||
// store scaling factor
|
|
||||||
|
|
||||||
switch (scale)
|
|
||||||
{
|
|
||||||
case GYRO_RANGE_125:
|
|
||||||
v_range = BMI160_GYRO_RANGE_125_DEG_SEC;
|
|
||||||
m_gyroScale = 262.4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GYRO_RANGE_250:
|
|
||||||
v_range = BMI160_GYRO_RANGE_250_DEG_SEC;
|
|
||||||
m_gyroScale = 131.2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GYRO_RANGE_500:
|
|
||||||
v_range = BMI160_GYRO_RANGE_500_DEG_SEC;
|
|
||||||
m_gyroScale = 65.6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GYRO_RANGE_1000:
|
|
||||||
v_range = BMI160_GYRO_RANGE_1000_DEG_SEC;
|
|
||||||
m_gyroScale = 32.8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GYRO_RANGE_2000:
|
|
||||||
v_range = BMI160_GYRO_RANGE_2000_DEG_SEC;
|
|
||||||
m_gyroScale = 16.4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // should never occur, but...
|
|
||||||
m_gyroScale = 1.0; // set a safe, though incorrect value
|
|
||||||
throw std::logic_error(string(__FUNCTION__) +
|
|
||||||
": internal error, unsupported scale");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bmi160_set_gyro_range(v_range);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::getAccelerometer(float *x, float *y, float *z)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
*x = m_accelX / m_accelScale;
|
|
||||||
|
|
||||||
if (y)
|
|
||||||
*y = m_accelY / m_accelScale;
|
|
||||||
|
|
||||||
if (z)
|
|
||||||
*z = m_accelZ / m_accelScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::getGyroscope(float *x, float *y, float *z)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
*x = m_gyroX / m_gyroScale;
|
|
||||||
|
|
||||||
if (y)
|
|
||||||
*y = m_gyroY / m_gyroScale;
|
|
||||||
|
|
||||||
if (z)
|
|
||||||
*z = m_gyroZ / m_gyroScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::getMagnetometer(float *x, float *y, float *z)
|
|
||||||
{
|
|
||||||
if (x)
|
|
||||||
*x = m_magX;
|
|
||||||
|
|
||||||
if (y)
|
|
||||||
*y = m_magY;
|
|
||||||
|
|
||||||
if (z)
|
|
||||||
*z = m_magZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
float *BMI160::getAccelerometer()
|
|
||||||
{
|
|
||||||
float *values = new float[3]; // x, y, and then z
|
|
||||||
|
|
||||||
getAccelerometer(&values[0], &values[1], &values[2]);
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
float *BMI160::getGyroscope()
|
|
||||||
{
|
|
||||||
float *values = new float[3]; // x, y, and then z
|
|
||||||
|
|
||||||
getGyroscope(&values[0], &values[1], &values[2]);
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
float *BMI160::getMagnetometer()
|
|
||||||
{
|
|
||||||
float *values = new float[3]; // x, y, and then z
|
|
||||||
|
|
||||||
getMagnetometer(&values[0], &values[1], &values[2]);
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMI160::enableMagnetometer(bool enable)
|
|
||||||
{
|
|
||||||
// butchered from support example
|
|
||||||
if (!enable)
|
|
||||||
{
|
|
||||||
bmi160_set_bmm150_mag_and_secondary_if_power_mode(MAG_SUSPEND_MODE);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
bmi160_set_if_mode(0x00);
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
m_magEnabled = false;
|
|
||||||
m_magX = 0;
|
|
||||||
m_magY = 0;
|
|
||||||
m_magZ = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u8 v_bmm_chip_id_u8 = BMI160_INIT_VALUE;
|
|
||||||
/* Init the magnetometer */
|
|
||||||
bmi160_bmm150_mag_interface_init(&v_bmm_chip_id_u8);
|
|
||||||
|
|
||||||
/* bmi160_delay_ms in ms*/
|
|
||||||
bmi160_delay_ms(BMI160_GEN_READ_WRITE_DELAY);
|
|
||||||
|
|
||||||
m_magEnabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int BMI160::getSensorTime()
|
|
||||||
{
|
|
||||||
return m_sensorTime;
|
|
||||||
}
|
|
@ -1,251 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define BMI160_I2C_BUS 0
|
|
||||||
#define BMI160_DEFAULT_I2C_ADDR 0x69
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief BMI160 3-axis Accelerometer, Gyroscope and Magnetometer
|
|
||||||
* @defgroup bmi160 libupm-bmi160
|
|
||||||
* @ingroup i2c accelerometer compass
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @library bmi160
|
|
||||||
* @sensor bmi160
|
|
||||||
* @comname UPM API for the BMI160 3-axis Accelerometer, Gyroscope
|
|
||||||
* and Magnetometer
|
|
||||||
* @type accelerometer compass
|
|
||||||
* @man mouser
|
|
||||||
* @con i2c
|
|
||||||
* @web http://www.mouser.com/ProductDetail/Bosch-Sensortec/0330SB2187/?qs=sGAEpiMZZMvi6wO7nhr1L9JELKA6cYRX60mAGNTn0fQ%3d
|
|
||||||
*
|
|
||||||
* @brief UPM API for the BMI160 3-axis Accelerometer, Gyroscope and
|
|
||||||
* Magnetometer
|
|
||||||
*
|
|
||||||
* The Bosch BMI160 is a 3-axis Accelerometer and Gyroscope.
|
|
||||||
* Additionally it supports an external Magnetometer, accessed
|
|
||||||
* through the BMI160's register interface. This driver was
|
|
||||||
* developed with a BMI160 "Shuttle" board, which included a BMM150
|
|
||||||
* Magnetometer.
|
|
||||||
*
|
|
||||||
* The device is driven by either 1.8v or 3.3vdc. This driver
|
|
||||||
* incorporates the Bosch BMI160 driver code at
|
|
||||||
* https://github.com/BoschSensortec/BMI160_driver .
|
|
||||||
*
|
|
||||||
* While not all of the functionality of this device is supported
|
|
||||||
* initially, the inclusion of the Bosch driver in the source code
|
|
||||||
* makes it possible to support whatever features are required that
|
|
||||||
* the driver can support.
|
|
||||||
*
|
|
||||||
* @snippet bmi160.cxx Interesting
|
|
||||||
*/
|
|
||||||
class BMI160 {
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
ACCEL_RANGE_2G = 0, // 2 Gravities
|
|
||||||
ACCEL_RANGE_4G,
|
|
||||||
ACCEL_RANGE_8G,
|
|
||||||
ACCEL_RANGE_16G
|
|
||||||
} ACCEL_RANGE_T;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GYRO_RANGE_125 = 0, // 125 degrees/sec
|
|
||||||
GYRO_RANGE_250,
|
|
||||||
GYRO_RANGE_500,
|
|
||||||
GYRO_RANGE_1000,
|
|
||||||
GYRO_RANGE_2000
|
|
||||||
} GYRO_RANGE_T;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bmi160 constructor
|
|
||||||
*
|
|
||||||
* @param bus i2c bus to use
|
|
||||||
* @param address the address for this device
|
|
||||||
*/
|
|
||||||
BMI160(int bus=BMI160_I2C_BUS, uint8_t address=BMI160_DEFAULT_I2C_ADDR);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMI160 Destructor
|
|
||||||
*/
|
|
||||||
~BMI160();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a measurement and store the current sensor values
|
|
||||||
* internally. This function must be called prior to retrieving
|
|
||||||
* any sensor values, for example getAccelerometer().
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void update();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the scaling mode of the accelerometer
|
|
||||||
*
|
|
||||||
* @param scale one of the ACCEL_RANGE_T values
|
|
||||||
*/
|
|
||||||
void setAccelerometerScale(ACCEL_RANGE_T scale);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the scaling mode of the gyroscope
|
|
||||||
*
|
|
||||||
* @param scale one of the GYRO_RANGE_T values
|
|
||||||
*/
|
|
||||||
void setGyroscopeScale(GYRO_RANGE_T scale);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Accelerometer values. This function returns a pointer
|
|
||||||
* to 3 floating point values: X, Y, and Z, in that order. The
|
|
||||||
* values returned are in gravities. update() must have been
|
|
||||||
* called prior to calling this method.
|
|
||||||
*
|
|
||||||
* The caller is reponsible for freeing the returned pointer.
|
|
||||||
*
|
|
||||||
* @return Pointer to 3 floating point values: X, Y, and Z in
|
|
||||||
* gravities.
|
|
||||||
*/
|
|
||||||
float *getAccelerometer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Accelerometer values. The values returned are in
|
|
||||||
* gravities. update() must have been called prior to calling
|
|
||||||
* this method.
|
|
||||||
*
|
|
||||||
* @param x A pointer into which the X value will be returned
|
|
||||||
* @param y A pointer into which the Y value will be returned
|
|
||||||
* @param z A pointer into which the Z value will be returned
|
|
||||||
*/
|
|
||||||
void getAccelerometer(float *x, float *y, float *z);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Gyroscope values. This function returns a pointer to 3
|
|
||||||
* floating point values: X, Y, and Z, in that order. The values
|
|
||||||
* values returned are in degrees per second. update() must have
|
|
||||||
* been called prior to calling this method.
|
|
||||||
*
|
|
||||||
* The caller is reponsible for freeing the returned pointer.
|
|
||||||
*
|
|
||||||
* @return Pointer to 3 floating point values: X, Y, and Z in
|
|
||||||
* degrees per second.
|
|
||||||
*/
|
|
||||||
float *getGyroscope();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Gyroscope values. The values returned are in degrees
|
|
||||||
* per second. update() must have been called prior to calling
|
|
||||||
* this method.
|
|
||||||
*
|
|
||||||
* @param x A pointer into which the X value will be returned
|
|
||||||
* @param y A pointer into which the Y value will be returned
|
|
||||||
* @param z A pointer into which the Z value will be returned
|
|
||||||
*/
|
|
||||||
void getGyroscope(float *x, float *y, float *z);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Magnetometer values. This function returns a pointer
|
|
||||||
* to 3 floating point values: X, Y, and Z, in that order. The
|
|
||||||
* values values returned are in micro Teslas. update() must have
|
|
||||||
* been called prior to calling this method. If the Magnetometer
|
|
||||||
* has been disabled, the return values will always be 0, 0, and
|
|
||||||
* 0.
|
|
||||||
*
|
|
||||||
* The caller is reponsible for freeing the returned pointer.
|
|
||||||
*
|
|
||||||
* @return Pointer to 3 floating point values: X, Y, and Z in
|
|
||||||
* micro Teslas.
|
|
||||||
*/
|
|
||||||
float *getMagnetometer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Magnetometer values. The values returned are in micro
|
|
||||||
* Teslas. update() must have been called prior to calling this
|
|
||||||
* method.
|
|
||||||
*
|
|
||||||
* @param x A pointer into which the X value will be returned
|
|
||||||
* @param y A pointer into which the Y value will be returned
|
|
||||||
* @param z A pointer into which the Z value will be returned
|
|
||||||
*/
|
|
||||||
void getMagnetometer(float *x, float *y, float *z);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable or disable the Magnetometer. By default, the
|
|
||||||
* magnetometer is enabled.
|
|
||||||
*
|
|
||||||
* @param enable true to enable the magnetometer, false to disable.
|
|
||||||
*/
|
|
||||||
void enableMagnetometer(bool enable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the sensor time. This is a 24bit value that increments
|
|
||||||
* every 39us. It will wrap around once the 24b resolution is
|
|
||||||
* exceeded.
|
|
||||||
*
|
|
||||||
* @return The current sensor time.
|
|
||||||
*/
|
|
||||||
unsigned int getSensorTime();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// uncompensated accelerometer and gyroscope values
|
|
||||||
float m_accelX;
|
|
||||||
float m_accelY;
|
|
||||||
float m_accelZ;
|
|
||||||
|
|
||||||
float m_gyroX;
|
|
||||||
float m_gyroY;
|
|
||||||
float m_gyroZ;
|
|
||||||
|
|
||||||
float m_magX;
|
|
||||||
float m_magY;
|
|
||||||
float m_magZ;
|
|
||||||
|
|
||||||
unsigned int m_sensorTime;
|
|
||||||
|
|
||||||
// accelerometer and gyro scaling factors, depending on their Full
|
|
||||||
// Scale (Range) settings.
|
|
||||||
float m_accelScale;
|
|
||||||
float m_gyroScale;
|
|
||||||
|
|
||||||
// is the magnetometer enabled?
|
|
||||||
bool m_magEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set up initial values and start operation
|
|
||||||
*
|
|
||||||
* @return true if successful
|
|
||||||
*/
|
|
||||||
virtual bool init();
|
|
||||||
|
|
||||||
private:
|
|
||||||
// due to the way we need to 'hook' into the bmi driver, the i2c
|
|
||||||
// context is a static variable defined in the .cxx implmentation.
|
|
||||||
|
|
||||||
uint8_t m_addr;
|
|
||||||
};
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,41 +0,0 @@
|
|||||||
%module javaupm_bmi160
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "typemaps.i"
|
|
||||||
%include "arrays_java.i"
|
|
||||||
%include "../java_buffer.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "bmi160.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
|
|
||||||
%typemap(jni) float * "jfloatArray"
|
|
||||||
%typemap(jstype) float * "float[]"
|
|
||||||
%typemap(jtype) float * "float[]"
|
|
||||||
|
|
||||||
%typemap(javaout) float * {
|
|
||||||
return $jnicall;
|
|
||||||
}
|
|
||||||
|
|
||||||
%typemap(out) float * {
|
|
||||||
$result = JCALL1(NewFloatArray, jenv, 3);
|
|
||||||
JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1);
|
|
||||||
delete [] $1;
|
|
||||||
}
|
|
||||||
|
|
||||||
%ignore getAccelerometer(float *, float *, float *);
|
|
||||||
%ignore getGyroscope(float *, float *, float *);
|
|
||||||
%ignore getMagnetometer(float *, float *, float *);
|
|
||||||
|
|
||||||
%include "bmi160.h"
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_bmi160");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,10 +0,0 @@
|
|||||||
%module jsupm_bmi160
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "cpointer.i"
|
|
||||||
|
|
||||||
%pointer_functions(float, floatp);
|
|
||||||
|
|
||||||
%include "bmi160.h"
|
|
||||||
%{
|
|
||||||
#include "bmi160.h"
|
|
||||||
%}
|
|
@ -1,55 +0,0 @@
|
|||||||
/** \mainpage
|
|
||||||
*
|
|
||||||
****************************************************************************
|
|
||||||
* Copyright (C) 2014 Bosch Sensortec GmbH
|
|
||||||
*
|
|
||||||
* File : bmi160.h
|
|
||||||
*
|
|
||||||
* Date : 2014/10/27
|
|
||||||
*
|
|
||||||
* Revision : 2.0.6 $
|
|
||||||
*
|
|
||||||
* Usage: Sensor Driver for BMI160 sensor
|
|
||||||
*
|
|
||||||
****************************************************************************
|
|
||||||
*
|
|
||||||
* \section License
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* Neither the name of the copyright holder nor the names of the
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
|
|
||||||
* OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
||||||
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
||||||
* ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
|
||||||
*
|
|
||||||
* The information provided is believed to be accurate and reliable.
|
|
||||||
* The copyright holder assumes no responsibility
|
|
||||||
* for the consequences of use
|
|
||||||
* of such information nor for any infringement of patents or
|
|
||||||
* other rights of third parties which may result from its use.
|
|
||||||
* No license is granted by implication or otherwise under any patent or
|
|
||||||
* patent rights of the copyright holder.
|
|
||||||
**************************************************************************/
|
|
@ -1,16 +0,0 @@
|
|||||||
// Include doxygen-generated documentation
|
|
||||||
%include "pyupm_doxy2swig.i"
|
|
||||||
%module pyupm_bmi160
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "cpointer.i"
|
|
||||||
|
|
||||||
%include "stdint.i"
|
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
|
||||||
|
|
||||||
%pointer_functions(float, floatp);
|
|
||||||
|
|
||||||
%include "bmi160.h"
|
|
||||||
%{
|
|
||||||
#include "bmi160.h"
|
|
||||||
%}
|
|
@ -1,6 +0,0 @@
|
|||||||
include_directories(..)
|
|
||||||
set (libname "bmp180")
|
|
||||||
set (libdescription "upm BMP180")
|
|
||||||
set (module_src ${libname}.cxx)
|
|
||||||
set (module_h ${libname}.h)
|
|
||||||
upm_module_init()
|
|
@ -1,286 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "bmp180.h"
|
|
||||||
|
|
||||||
/* CALIBRATION */
|
|
||||||
#define BMP180_PROM_START_ADDR (0xAA)
|
|
||||||
#define BMP180_PROM_DATA_LEN (22)
|
|
||||||
|
|
||||||
#define BMP180_CALIB_DATA_SIZE (22)
|
|
||||||
#define BMP180_CALIB_PARAM_AC1_MSB (0)
|
|
||||||
#define BMP180_CALIB_PARAM_AC1_LSB (1)
|
|
||||||
#define BMP180_CALIB_PARAM_AC2_MSB (2)
|
|
||||||
#define BMP180_CALIB_PARAM_AC2_LSB (3)
|
|
||||||
#define BMP180_CALIB_PARAM_AC3_MSB (4)
|
|
||||||
#define BMP180_CALIB_PARAM_AC3_LSB (5)
|
|
||||||
#define BMP180_CALIB_PARAM_AC4_MSB (6)
|
|
||||||
#define BMP180_CALIB_PARAM_AC4_LSB (7)
|
|
||||||
#define BMP180_CALIB_PARAM_AC5_MSB (8)
|
|
||||||
#define BMP180_CALIB_PARAM_AC5_LSB (9)
|
|
||||||
#define BMP180_CALIB_PARAM_AC6_MSB (10)
|
|
||||||
#define BMP180_CALIB_PARAM_AC6_LSB (11)
|
|
||||||
#define BMP180_CALIB_PARAM_B1_MSB (12)
|
|
||||||
#define BMP180_CALIB_PARAM_B1_LSB (13)
|
|
||||||
#define BMP180_CALIB_PARAM_B2_MSB (14)
|
|
||||||
#define BMP180_CALIB_PARAM_B2_LSB (15)
|
|
||||||
#define BMP180_CALIB_PARAM_MB_MSB (16)
|
|
||||||
#define BMP180_CALIB_PARAM_MB_LSB (17)
|
|
||||||
#define BMP180_CALIB_PARAM_MC_MSB (18)
|
|
||||||
#define BMP180_CALIB_PARAM_MC_LSB (19)
|
|
||||||
#define BMP180_CALIB_PARAM_MD_MSB (20)
|
|
||||||
#define BMP180_CALIB_PARAM_MD_LSB (21)
|
|
||||||
|
|
||||||
/* REGISTERS */
|
|
||||||
#define BMP180_TEMPERATURE_DATA_LENGTH ((uint8_t)2)
|
|
||||||
#define BMP180_PRESSURE_DATA_LENGTH ((uint8_t)3)
|
|
||||||
|
|
||||||
#define BMP180_CHIP_ID_REG (0xD0)
|
|
||||||
#define BMP180_VERSION_REG (0xD1)
|
|
||||||
|
|
||||||
#define BMP180_CTRL_MEAS_REG (0xF4)
|
|
||||||
#define BMP180_ADC_OUT_MSB_REG (0xF6)
|
|
||||||
#define BMP180_ADC_OUT_LSB_REG (0xF7)
|
|
||||||
|
|
||||||
#define BMP180_SOFT_RESET_REG (0xE0)
|
|
||||||
|
|
||||||
/* temperature measurement */
|
|
||||||
#define BMP180_T_MEASURE (0x2E)
|
|
||||||
|
|
||||||
/* pressure measurement*/
|
|
||||||
#define BMP180_P_MEASURE (0x34)
|
|
||||||
|
|
||||||
#define BMP180_TEMPERATURE_DATA_BYTES (2)
|
|
||||||
#define BMP180_PRESSURE_DATA_BYTES (3)
|
|
||||||
#define BMP180_TEMPERATURE_LSB_DATA (1)
|
|
||||||
#define BMP180_TEMPERATURE_MSB_DATA (0)
|
|
||||||
#define BMP180_PRESSURE_MSB_DATA (0)
|
|
||||||
#define BMP180_PRESSURE_LSB_DATA (1)
|
|
||||||
#define BMP180_PRESSURE_XLSB_DATA (2)
|
|
||||||
|
|
||||||
#define BMP180_PARAM_MG (3038)
|
|
||||||
#define BMP180_PARAM_MH (-7357)
|
|
||||||
#define BMP180_PARAM_MI (3791)
|
|
||||||
|
|
||||||
/* ID */
|
|
||||||
#define BMP180_ID (0x55)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
|
|
||||||
BMP180::BMP180 (int bus, int devAddr, uint8_t mode) {
|
|
||||||
m_name = "BMP180";
|
|
||||||
m_controlAddr = devAddr;
|
|
||||||
m_bus = bus;
|
|
||||||
|
|
||||||
m_i2c = new mraa::I2c(m_bus);
|
|
||||||
|
|
||||||
// Set mode
|
|
||||||
if (mode > BMP180_ULTRAHIGHRES) {
|
|
||||||
mode = BMP180_ULTRAHIGHRES;
|
|
||||||
}
|
|
||||||
oversampling = mode;
|
|
||||||
|
|
||||||
// Check this is a BMP180 chip and get calibration data
|
|
||||||
if (!isAvailable() || !getCalibrationData())
|
|
||||||
UPM_THROW("Init failed");
|
|
||||||
|
|
||||||
getTemperatureCelcius();
|
|
||||||
}
|
|
||||||
|
|
||||||
BMP180::~BMP180() {
|
|
||||||
delete m_i2c;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
BMP180::getPressurePa () {
|
|
||||||
int pressure;
|
|
||||||
int32_t x1, x2, x3, b3, b6, value;
|
|
||||||
uint32_t b4, b7;
|
|
||||||
uint32_t raw_pressure = getPressureRaw();
|
|
||||||
|
|
||||||
/*****calculate B6************/
|
|
||||||
b6 = b5 - 4000;
|
|
||||||
|
|
||||||
/*****calculate B3************/
|
|
||||||
x1 = (b6 * b6) >> 12;
|
|
||||||
x1 *= b2;
|
|
||||||
x1 >>= 11;
|
|
||||||
|
|
||||||
x2 = (ac2 * b6);
|
|
||||||
x2 >>= 11;
|
|
||||||
|
|
||||||
x3 = x1 + x2;
|
|
||||||
b3 = (((((int32_t) ac1) * 4 + x3) << oversampling) + 2) >> 2;
|
|
||||||
|
|
||||||
/*****calculate B4************/
|
|
||||||
x1 = (ac3 * b6) >> 13;
|
|
||||||
x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
|
|
||||||
x3 = ((x1 + x2) + 2) >> 2;
|
|
||||||
b4 = (ac4 * (uint32_t)(x3 + 32768)) >> 15;
|
|
||||||
b7 = ((uint32_t)(raw_pressure - b3) * (50000 >> oversampling));
|
|
||||||
|
|
||||||
if (b4 == 0)
|
|
||||||
UPM_THROW("b4 == 0");
|
|
||||||
|
|
||||||
if (b7 < 0x80000000)
|
|
||||||
pressure = (b7 << 1) / b4;
|
|
||||||
else
|
|
||||||
pressure = (b7 / b4) << 1;
|
|
||||||
|
|
||||||
x1 = pressure >> 8;
|
|
||||||
x1 *= x1;
|
|
||||||
x1 = (x1 * BMP180_PARAM_MG) >> 16;
|
|
||||||
x2 = (pressure * BMP180_PARAM_MH) >> 16;
|
|
||||||
|
|
||||||
/*pressure in Pa*/
|
|
||||||
pressure += (x1 + x2 + BMP180_PARAM_MI) >> 4;
|
|
||||||
return pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
BMP180::getTemperatureCelcius () {
|
|
||||||
uint32_t temp;
|
|
||||||
int32_t x1, x2;
|
|
||||||
|
|
||||||
temp = (uint32_t) getTemperatureRaw();
|
|
||||||
|
|
||||||
/* calculate temperature*/
|
|
||||||
x1 = (((int32_t) temp - (int32_t) ac6) * (int32_t) ac5) >> 15;
|
|
||||||
|
|
||||||
// Check divisor
|
|
||||||
if (x1 == 0 && md == 0)
|
|
||||||
UPM_THROW("x1 == 0 && md == 0");
|
|
||||||
|
|
||||||
x2 = ((int32_t) mc << 11) / (x1 + md);
|
|
||||||
b5 = x1 + x2;
|
|
||||||
|
|
||||||
int value = ((b5 + 8) >> 4);
|
|
||||||
return (value + 5) / 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
BMP180::getPressureRaw () {
|
|
||||||
uint8_t data[BMP180_PRESSURE_DATA_BYTES];
|
|
||||||
|
|
||||||
m_i2c->address(m_controlAddr);
|
|
||||||
status = m_i2c->writeReg(BMP180_CTRL_MEAS_REG, BMP180_P_MEASURE + (oversampling << 6));
|
|
||||||
if (status != mraa::SUCCESS)
|
|
||||||
UPM_THROW("BMP180_CTRL_MEAS_REG write failed");
|
|
||||||
|
|
||||||
if (oversampling == BMP180_ULTRALOWPOWER) {
|
|
||||||
usleep(5000);
|
|
||||||
} else if (oversampling == BMP180_STANDARD) {
|
|
||||||
usleep(8000);
|
|
||||||
} else if (oversampling == BMP180_HIGHRES) {
|
|
||||||
usleep(14000);
|
|
||||||
} else {
|
|
||||||
usleep(26000);
|
|
||||||
}
|
|
||||||
|
|
||||||
int length = m_i2c->readBytesReg(BMP180_ADC_OUT_MSB_REG, data, BMP180_PRESSURE_DATA_LENGTH);
|
|
||||||
if (length != BMP180_PRESSURE_DATA_LENGTH)
|
|
||||||
UPM_THROW("BMP180_ADC_OUT_MSB_REG read failed");
|
|
||||||
|
|
||||||
return (uint32_t)((((uint32_t)data[BMP180_PRESSURE_MSB_DATA] << 16)
|
|
||||||
| ((uint32_t) data[BMP180_PRESSURE_LSB_DATA] << 8)
|
|
||||||
| (uint32_t) data[BMP180_PRESSURE_XLSB_DATA]) >> (8 - oversampling));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t
|
|
||||||
BMP180::getTemperatureRaw () {
|
|
||||||
uint8_t data[BMP180_TEMPERATURE_DATA_BYTES];
|
|
||||||
|
|
||||||
m_i2c->address(m_controlAddr);
|
|
||||||
status = m_i2c->writeReg(BMP180_CTRL_MEAS_REG, BMP180_T_MEASURE);
|
|
||||||
if (status != mraa::SUCCESS)
|
|
||||||
UPM_THROW("BMP180_CTRL_MEAS_REG write failed");
|
|
||||||
|
|
||||||
usleep(5000);
|
|
||||||
|
|
||||||
int length = m_i2c->readBytesReg(BMP180_ADC_OUT_MSB_REG, data, BMP180_TEMPERATURE_DATA_LENGTH);
|
|
||||||
if (length != BMP180_TEMPERATURE_DATA_LENGTH)
|
|
||||||
UPM_THROW("BMP180_ADC_OUT_MSB_REG read failed");
|
|
||||||
|
|
||||||
return (uint16_t)((((int32_t)((int8_t)data[BMP180_TEMPERATURE_MSB_DATA])) << 8)
|
|
||||||
| (data[BMP180_TEMPERATURE_LSB_DATA]));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
BMP180::getCalibrationData() {
|
|
||||||
|
|
||||||
// Holds calibration data
|
|
||||||
uint8_t calibration_data[BMP180_CALIB_DATA_SIZE];
|
|
||||||
|
|
||||||
/* Read calibration data */
|
|
||||||
m_i2c->address(m_controlAddr);
|
|
||||||
int length = m_i2c->readBytesReg(BMP180_PROM_START_ADDR, calibration_data, BMP180_PROM_DATA_LEN);
|
|
||||||
|
|
||||||
// Check we read all calibration data
|
|
||||||
if(length != BMP180_PROM_DATA_LEN) { return false; }
|
|
||||||
|
|
||||||
ac1 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC1_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC1_LSB]);
|
|
||||||
ac2 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC2_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC2_LSB]);
|
|
||||||
ac3 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_AC3_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC3_LSB]);
|
|
||||||
ac4 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC4_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC4_LSB]);
|
|
||||||
ac5 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC5_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC5_LSB]);
|
|
||||||
ac6 = (uint16_t)(((uint32_t)((uint8_t)calibration_data[BMP180_CALIB_PARAM_AC6_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_AC6_LSB]);
|
|
||||||
|
|
||||||
b1 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_B1_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_B1_LSB]);
|
|
||||||
b2 = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_B2_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_B2_LSB]);
|
|
||||||
|
|
||||||
mb = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MB_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_MB_LSB]);
|
|
||||||
mc = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MC_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_MC_LSB]);
|
|
||||||
md = (int16_t)(((int32_t)((int8_t)calibration_data[BMP180_CALIB_PARAM_MD_MSB] << 8))
|
|
||||||
| calibration_data[BMP180_CALIB_PARAM_MD_LSB]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
BMP180::isAvailable() {
|
|
||||||
m_i2c->address(m_controlAddr);
|
|
||||||
if (m_i2c->readReg(BMP180_CHIP_ID_REG) != BMP180_ID) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
|
||||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2014 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Credits to Adafruit.
|
|
||||||
* Based on Adafruit BMP180 library.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <mraa/i2c.hpp>
|
|
||||||
#include "upm/iPressureSensor.h"
|
|
||||||
#include "upm/iTemperatureSensor.h"
|
|
||||||
|
|
||||||
#define BMP180_ADDR 0x77 // device address
|
|
||||||
|
|
||||||
/* MODES */
|
|
||||||
#define BMP180_ULTRALOWPOWER 0
|
|
||||||
#define BMP180_STANDARD 1
|
|
||||||
#define BMP180_HIGHRES 2
|
|
||||||
#define BMP180_ULTRAHIGHRES 3
|
|
||||||
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief BPM180 atmospheric pressure sensor library
|
|
||||||
* @defgroup BMP180 libupm-BMP180
|
|
||||||
* @ingroup bosch seeed adafruit sparkfun i2c pressure ipressuresensor
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for Bosch BMP180 Pressure Sensor
|
|
||||||
*
|
|
||||||
* The Bosch BMP180 is a high precision, ultra-low
|
|
||||||
* power consumption pressure sensor. It has a range of between
|
|
||||||
* 30,000 and 110,000 Pa.
|
|
||||||
*
|
|
||||||
* @library BMP180
|
|
||||||
* @sensor BMP180
|
|
||||||
* @comname Bosch BMP Atmospheric Pressure Sensor
|
|
||||||
* @altname BMP180
|
|
||||||
* @type pressure
|
|
||||||
* @man bosch adafruit sparkfun
|
|
||||||
* @con i2c
|
|
||||||
* @if ipressuresensor
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class BMP180 : public IPressureSensor, public ITemperatureSensor {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Instanciates a BMP180 object
|
|
||||||
*
|
|
||||||
* @param bus number of used bus
|
|
||||||
* @param devAddr address of used i2c device
|
|
||||||
* @param mode BMP180 mode
|
|
||||||
*/
|
|
||||||
BMP180 (int bus, int devAddr=BMP180_ADDR, uint8_t mode=BMP180_ULTRAHIGHRES);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMP180 object destructor, basicaly it close i2c connection.
|
|
||||||
*/
|
|
||||||
~BMP180 ();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return pressure
|
|
||||||
*/
|
|
||||||
uint32_t getPressureRaw();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return calculated pressure (Pa)
|
|
||||||
*/
|
|
||||||
int getPressurePa();
|
|
||||||
|
|
||||||
uint16_t getTemperatureRaw();
|
|
||||||
/**
|
|
||||||
* Return latest calculated temperature value in Celcius
|
|
||||||
*/
|
|
||||||
int getTemperatureCelcius();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the correct chip is present at the given address.
|
|
||||||
*/
|
|
||||||
bool isAvailable();
|
|
||||||
const char* getModuleName() { return m_name.c_str(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string m_name;
|
|
||||||
|
|
||||||
int m_controlAddr;
|
|
||||||
int m_bus;
|
|
||||||
mraa::I2c* m_i2c;
|
|
||||||
mraa::Result status;
|
|
||||||
|
|
||||||
uint8_t oversampling;
|
|
||||||
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
|
|
||||||
uint16_t ac4, ac5, ac6;
|
|
||||||
|
|
||||||
int32_t b5;
|
|
||||||
|
|
||||||
bool getCalibrationData();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
%module javaupm_bmp180
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "arrays_java.i";
|
|
||||||
%include "../java_buffer.i"
|
|
||||||
%include "cpointer.i"
|
|
||||||
%include "typemaps.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "bmp180.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "bmp180.h"
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_bmp180");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,8 +0,0 @@
|
|||||||
%module jsupm_bmp180
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "bmp180.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "bmp180.h"
|
|
@ -1,10 +0,0 @@
|
|||||||
%module pyupm_bmp180
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%include "stdint.i"
|
|
||||||
|
|
||||||
%include "bmp180.h"
|
|
||||||
%{
|
|
||||||
#include "bmp180.h"
|
|
||||||
%}
|
|
||||||
|
|
@ -33,9 +33,9 @@
|
|||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_controlAddr(devAddr), m_i2ControlCtx(bus) {
|
BMPX8X::BMPX8X (int bus, int devAddr, uint8_t mode) : m_controlAddr(devAddr), m_i2ControlCtx(bus) {
|
||||||
|
|
||||||
m_name = "BMPX8X";
|
m_name = "BMPX8X";
|
||||||
|
|
||||||
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
mraa::Result ret = m_i2ControlCtx.address(m_controlAddr);
|
||||||
if (ret != mraa::SUCCESS) {
|
if (ret != mraa::SUCCESS) {
|
||||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
@ -93,8 +93,7 @@ BMPX8X::getPressure () {
|
|||||||
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
|
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
|
||||||
|
|
||||||
if (B7 < 0x80000000) {
|
if (B7 < 0x80000000) {
|
||||||
p = (B7 * 2) / B4
|
p = (B7 * 2) / B4;
|
||||||
;
|
|
||||||
} else {
|
} else {
|
||||||
p = (B7 / B4) * 2;
|
p = (B7 / B4) * 2;
|
||||||
}
|
}
|
||||||
@ -170,18 +169,6 @@ BMPX8X::getAltitude (float sealevelPressure) {
|
|||||||
return altitude;
|
return altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
BMPX8X::getTemperatureCelcius() {
|
|
||||||
return static_cast<int>(getTemperature() + 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
BMPX8X::getModuleName() {
|
|
||||||
return m_name.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32_t
|
int32_t
|
||||||
BMPX8X::computeB5(int32_t UT) {
|
BMPX8X::computeB5(int32_t UT) {
|
||||||
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <mraa/i2c.hpp>
|
#include <mraa/i2c.hpp>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "upm/iTemperatureSensor.h"
|
|
||||||
|
|
||||||
#define ADDR 0x77 // device address
|
#define ADDR 0x77 // device address
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ namespace upm {
|
|||||||
* @snippet bmpx8x.cxx Interesting
|
* @snippet bmpx8x.cxx Interesting
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BMPX8X : public ITemperatureSensor {
|
class BMPX8X {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Instantiates a BMPX8X object
|
* Instantiates a BMPX8X object
|
||||||
@ -142,19 +141,6 @@ class BMPX8X : public ITemperatureSensor {
|
|||||||
*/
|
*/
|
||||||
float getAltitude (float sealevelPressure = 101325);
|
float getAltitude (float sealevelPressure = 101325);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return latest calculated temperature value in Celcius
|
|
||||||
* See ITemperatureSensor
|
|
||||||
*/
|
|
||||||
int getTemperatureCelcius();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns name of module. This is the string in library name after libupm_
|
|
||||||
|
|
||||||
* @return name of module
|
|
||||||
*/
|
|
||||||
const char* getModuleName();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates B5 (check the spec for more information)
|
* Calculates B5 (check the spec for more information)
|
||||||
*
|
*
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
set (libname "cwlsxxa")
|
|
||||||
set (libdescription "upm Veris CWLSXXA CO2/Temperature/Humidity transmitter")
|
|
||||||
set (module_src ${libname}.cxx)
|
|
||||||
set (module_h ${libname}.h)
|
|
||||||
upm_module_init()
|
|
@ -1,183 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 <iostream>
|
|
||||||
|
|
||||||
#include "cwlsxxa.h"
|
|
||||||
|
|
||||||
using namespace upm;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// for current loop reads that seems a little noisy, we average over
|
|
||||||
// several aio reads.
|
|
||||||
static const int maxSamples = 50;
|
|
||||||
|
|
||||||
// conversion from celcius to fahrenheit
|
|
||||||
|
|
||||||
static float c2f(float c)
|
|
||||||
{
|
|
||||||
return (c * (9.0 / 5.0) + 32.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CWLSXXA::CWLSXXA(int gPin, int hPin, int tPin, float rResistor, float aref) :
|
|
||||||
m_aioCO2(gPin), m_aioHum(0), m_aioTemp(0)
|
|
||||||
{
|
|
||||||
m_hasHum = (hPin >= 0) ? true : false;
|
|
||||||
m_hasTemp = (tPin >= 0) ? true : false;
|
|
||||||
|
|
||||||
if (m_hasTemp)
|
|
||||||
{
|
|
||||||
m_aioTemp = new mraa::Aio(tPin);
|
|
||||||
m_aResTemp = (1 << m_aioTemp->getBit());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_aResTemp = 0;
|
|
||||||
|
|
||||||
if (m_hasHum)
|
|
||||||
{
|
|
||||||
m_aioHum = new mraa::Aio(hPin);
|
|
||||||
m_aResHum = (1 << m_aioHum->getBit());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_aResHum = 0;
|
|
||||||
|
|
||||||
m_aResCO2 = (1 << m_aioCO2.getBit());
|
|
||||||
|
|
||||||
m_temperature = 0.0;
|
|
||||||
m_humidity = 0.0;
|
|
||||||
m_co2 = 0.0;
|
|
||||||
|
|
||||||
m_aref = aref;
|
|
||||||
m_rResistor = rResistor;
|
|
||||||
}
|
|
||||||
|
|
||||||
CWLSXXA::~CWLSXXA()
|
|
||||||
{
|
|
||||||
if (m_aioHum)
|
|
||||||
delete m_aioHum;
|
|
||||||
if (m_aioTemp)
|
|
||||||
delete m_aioTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWLSXXA::update()
|
|
||||||
{
|
|
||||||
// temperature
|
|
||||||
int val;
|
|
||||||
float volts;
|
|
||||||
float milliamps = 0.0;
|
|
||||||
|
|
||||||
int samples;
|
|
||||||
if (m_rResistor)
|
|
||||||
samples = maxSamples;
|
|
||||||
else
|
|
||||||
samples = 1;
|
|
||||||
|
|
||||||
|
|
||||||
// temperature
|
|
||||||
if (m_hasTemp)
|
|
||||||
{
|
|
||||||
// fortunately, this sensor always reports temperatures in C,
|
|
||||||
// regardless of the configuration of the LCD display (for
|
|
||||||
// models that have an LCD display)
|
|
||||||
|
|
||||||
val = average(m_aioTemp, samples);
|
|
||||||
|
|
||||||
volts = (float(val) * (m_aref / m_aResTemp));
|
|
||||||
|
|
||||||
// valid range is 10-35C, current loop range is 16ma (20ma - 4ma)
|
|
||||||
if (!m_rResistor)
|
|
||||||
m_temperature = ((volts / m_aref) * 25.0) + 10.0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
|
|
||||||
if (milliamps < 0.0) // not connected
|
|
||||||
milliamps = 0.0;
|
|
||||||
m_temperature = (milliamps * (25.0 / 16.0)) + 10.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// humidity
|
|
||||||
if (m_hasHum)
|
|
||||||
{
|
|
||||||
val = average(m_aioHum, samples);
|
|
||||||
volts = (float(val) * (m_aref / m_aResHum));
|
|
||||||
|
|
||||||
// range is 0-100
|
|
||||||
if (!m_rResistor)
|
|
||||||
m_humidity = ((volts / m_aref) * 100.0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
|
|
||||||
if (milliamps < 0.0) // not connected
|
|
||||||
milliamps = 0.0;
|
|
||||||
m_humidity = milliamps * (100.0 / 16.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CO2
|
|
||||||
val = average(&m_aioCO2, samples);
|
|
||||||
volts = (float(val) * (m_aref / m_aResCO2));
|
|
||||||
|
|
||||||
// CO2 range is 0-2000ppm
|
|
||||||
if (!m_rResistor)
|
|
||||||
m_co2 = ((volts / m_aref) * 2000.0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
milliamps = ((volts / m_rResistor * 1000.0) - 4.0);
|
|
||||||
if (milliamps < 0.0) // not connected
|
|
||||||
milliamps = 0.0;
|
|
||||||
m_co2 = milliamps * (2000.0 / 16.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float CWLSXXA::getTemperature(bool fahrenheit)
|
|
||||||
{
|
|
||||||
if (fahrenheit)
|
|
||||||
return c2f(m_temperature);
|
|
||||||
else
|
|
||||||
return m_temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
float CWLSXXA::getHumidity()
|
|
||||||
{
|
|
||||||
return m_humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
float CWLSXXA::getCO2()
|
|
||||||
{
|
|
||||||
return m_co2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CWLSXXA::average(mraa::Aio *aio, int samples)
|
|
||||||
{
|
|
||||||
if (samples <= 0)
|
|
||||||
samples = 1;
|
|
||||||
|
|
||||||
int avg = 0;
|
|
||||||
for (int i=0; i<samples; i++)
|
|
||||||
avg += aio->read();
|
|
||||||
|
|
||||||
return (avg / samples);
|
|
||||||
}
|
|
@ -1,189 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Jon Trulson <jtrulson@ics.com>
|
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <mraa/aio.hpp>
|
|
||||||
|
|
||||||
// Unlikey to be changable without external circuitry (voltage divider)
|
|
||||||
#define CWLSXXA_DEFAULT_AREF 5.0
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
/**
|
|
||||||
* @brief Veris CWLSXXA CO2 Sensor
|
|
||||||
* @defgroup cwlsxxa libupm-cwlsxxa
|
|
||||||
* @ingroup veris ainput temp gaseous
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @library cwlsxxa
|
|
||||||
* @sensor cwlsxxa
|
|
||||||
* @comname Veris CWLSXXA CO2 Sensor Family
|
|
||||||
* @type temp gaseous
|
|
||||||
* @man veris
|
|
||||||
* @con ainput
|
|
||||||
* @web http://www.veris.com/Item/CWLSHTA.aspx
|
|
||||||
*
|
|
||||||
* @brief API for the Veris CWLSXXA CO2 Sensor Family
|
|
||||||
*
|
|
||||||
* The driver was developed using the CWLSHTA CO2 Gas sensor. The
|
|
||||||
* 'T' variant supports a temperature transmitter, and the 'H'
|
|
||||||
* variant supports a humidity sensor. All 3 signals are provided
|
|
||||||
* by the device as analog 0-5Vdc, 0-10Vdc, or 4-20ma loop current
|
|
||||||
* outputs. For devices supporting temperature, the valid
|
|
||||||
* temperature range is 10C to 50C. The humidity ranges from 0%
|
|
||||||
* to 100% (non-condensing). The CO2 sensor ranges from 0 to 2000
|
|
||||||
* ppm.
|
|
||||||
*
|
|
||||||
* This driver was developed using the 5Vdc outputs and the 4-20ma
|
|
||||||
* outputs. For voltage outputs, your MCU must be configured for
|
|
||||||
* 5V operation. In addition, you must configure the sensor (via
|
|
||||||
* it's configuration switches) to output 0-5VDC only. Using any
|
|
||||||
* other analog reference voltage will require the appropriate
|
|
||||||
* external circuitry (such as a voltage divider) in order to
|
|
||||||
* interface safely with your MCU.
|
|
||||||
*
|
|
||||||
* In addition, the sensor can be configured for 4-20ma usage, by
|
|
||||||
* specifying the correct receiver resistance (in ohms) in the
|
|
||||||
* constructor. This sensor was tested with a Cooking Hacks
|
|
||||||
* (Libelium) 4-channel 4-20ma Arduino interface shield. For this
|
|
||||||
* interface, the receiver resistance was specified as 165.0 ohms.
|
|
||||||
*
|
|
||||||
* For devices which do not support temperature, use '-1' as the
|
|
||||||
* temperature pin number in the object constructor. If
|
|
||||||
* temperature measurement is disabled, getTemperature() will always
|
|
||||||
* return 0C/32F.
|
|
||||||
*
|
|
||||||
* For devices which do not support humidity, use '-1' as the
|
|
||||||
* temperature pin number in the object constructor. If
|
|
||||||
* humidity measurement is disabled, getHumidity() will always
|
|
||||||
* return 0.
|
|
||||||
*
|
|
||||||
* @snippet cwlsxxa.cxx Interesting
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CWLSXXA {
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CWLSXXA object constructor
|
|
||||||
*
|
|
||||||
* @param gPin Analog pin to use for the CO2 measurement
|
|
||||||
* @param hPin Analog pin to use for the humidity measurement. If
|
|
||||||
* your device does not support humidity, use -1 as the value so
|
|
||||||
* that humidity will not be queried and an analog pin won't be
|
|
||||||
* wasted.
|
|
||||||
* @param tPin Analog pin to use for temperature. If your device
|
|
||||||
* does not support temperature, use -1 as the value so that
|
|
||||||
* temperature will not be queried and an analog pin won't be
|
|
||||||
* wasted.
|
|
||||||
* @param rResistor The receiver resistance in ohms, when using a
|
|
||||||
* 4-20ma current loop interface. When specified, this value will
|
|
||||||
* be used in computing the current based on the voltage read when
|
|
||||||
* scaling the return values. Default is 0.0, for standard
|
|
||||||
* scaling based on voltage output rather than current (4-20ma
|
|
||||||
* mode).
|
|
||||||
* @param aref The analog reference voltage, default 5.0
|
|
||||||
*/
|
|
||||||
CWLSXXA(int gPin, int hPin, int tPin, float rResistor=0.0,
|
|
||||||
float aref=CWLSXXA_DEFAULT_AREF);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CWLSXXA object destructor
|
|
||||||
*/
|
|
||||||
~CWLSXXA();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read current values from the sensor and update internal stored
|
|
||||||
* values. This method must be called prior to querying any
|
|
||||||
* values, such as CO2, temperature, or humidity.
|
|
||||||
*/
|
|
||||||
void update();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current temperature. update() must have been called
|
|
||||||
* prior to calling this method. If temperature measurement was
|
|
||||||
* disabled (by passing -1 as the temperature pin in the
|
|
||||||
* constructor) then this function will always return 0C/32F.
|
|
||||||
*
|
|
||||||
* @param fahrenheit true to return the temperature in degrees
|
|
||||||
* fahrenheit, false to return the temperature in degrees celcius.
|
|
||||||
* The default is false (degrees Celcius).
|
|
||||||
* @return The last temperature reading in Celcius or Fahrenheit
|
|
||||||
*/
|
|
||||||
float getTemperature(bool fahrenheit=false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current relative humidity. update() must have been called
|
|
||||||
* prior to calling this method. If humidity measurement was
|
|
||||||
* disabled (by passing -1 as the te pin in the
|
|
||||||
* constructor) then this function will always return 0.
|
|
||||||
*
|
|
||||||
* @return The last humidity reading
|
|
||||||
*/
|
|
||||||
float getHumidity();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current CO2 concentration in Parts Per Million (PPM).
|
|
||||||
* update() must have been called prior to calling this method.
|
|
||||||
*
|
|
||||||
* @return The last CO2 reading
|
|
||||||
*/
|
|
||||||
float getCO2();
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// temperature and humidity are optional features of this transmitter
|
|
||||||
mraa::Aio *m_aioTemp;
|
|
||||||
mraa::Aio *m_aioHum;
|
|
||||||
|
|
||||||
// CO2 reporting is always supported
|
|
||||||
mraa::Aio m_aioCO2;
|
|
||||||
|
|
||||||
private:
|
|
||||||
float m_aref;
|
|
||||||
float m_rResistor;
|
|
||||||
int m_aResTemp;
|
|
||||||
int m_aResHum;
|
|
||||||
int m_aResCO2;
|
|
||||||
|
|
||||||
// does this sensor support temperature and/or humidity reporting?
|
|
||||||
bool m_hasTemp;
|
|
||||||
bool m_hasHum;
|
|
||||||
|
|
||||||
// in Celcius
|
|
||||||
float m_temperature;
|
|
||||||
|
|
||||||
float m_humidity;
|
|
||||||
|
|
||||||
// in PPM
|
|
||||||
float m_co2;
|
|
||||||
|
|
||||||
int average(mraa::Aio *aio, int samples);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
%module jsupm_cwlsxxa
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "std_string.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "cwlsxxa.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "cwlsxxa.h"
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
// Include doxygen-generated documentation
|
|
||||||
%include "pyupm_doxy2swig.i"
|
|
||||||
%module pyupm_cwlsxxa
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "std_string.i"
|
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "cwlsxxa.h"
|
|
||||||
%}
|
|
||||||
%include "cwlsxxa.h"
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
include_directories(..)
|
|
||||||
set (libname "ds1808lc")
|
|
||||||
set (libdescription “DS1808 lighting controller”)
|
|
||||||
set (module_src ${libname}.cxx mraa-utils.cxx)
|
|
||||||
set (module_h ${libname}.h)
|
|
||||||
upm_module_init()
|
|
@ -1,134 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <cmath>
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
#include "mraa-utils.h"
|
|
||||||
|
|
||||||
#define DS1808_I2C_ADDR 0x28
|
|
||||||
#define DS1808_POT2_OFFSET 0x40
|
|
||||||
#define DS1808_MAX_POT_VALUE 0x20
|
|
||||||
#define DS1808_LOW_VALUE 32 // Lowest pot value that the eye can differentiate from 0
|
|
||||||
#define DS1808_HIGH_VALUE 51 // Highest pot value that the eye can differentiate from full
|
|
||||||
|
|
||||||
|
|
||||||
namespace upm {
|
|
||||||
DS1808LC::DS1808LC(int gpioPower, int i2cBus)
|
|
||||||
{
|
|
||||||
mraa_set_log_level(7);
|
|
||||||
pinPower = gpioPower;
|
|
||||||
i2c = new mraa::I2c(i2cBus);
|
|
||||||
status = i2c->address(DS1808_I2C_ADDR);
|
|
||||||
getBrightness();
|
|
||||||
}
|
|
||||||
|
|
||||||
DS1808LC::~DS1808LC()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DS1808LC::isPowered()
|
|
||||||
{
|
|
||||||
return static_cast<bool>(MraaUtils::getGpio(pinPower));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DS1808LC::setPowerOn()
|
|
||||||
{
|
|
||||||
if (!isPowered())
|
|
||||||
{
|
|
||||||
MraaUtils::setGpio(pinPower, 1);
|
|
||||||
setBrightness(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DS1808LC::setPowerOff()
|
|
||||||
{
|
|
||||||
MraaUtils::setGpio(pinPower, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int DS1808LC::getBrightness()
|
|
||||||
{
|
|
||||||
uint8_t values[2];
|
|
||||||
|
|
||||||
if (i2c->read(values, 2) == 2) {
|
|
||||||
return getPercentBrightness(values[0], values[1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
UPM_THROW("i2c read error");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DS1808LC::setBrightness(int dutyPercent)
|
|
||||||
{
|
|
||||||
uint8_t values[2];
|
|
||||||
values[0] = getPot1Value(dutyPercent);
|
|
||||||
values[1] = getPot2Value(dutyPercent);
|
|
||||||
status = i2c->write(values, 2);
|
|
||||||
if (status != mraa::SUCCESS)
|
|
||||||
UPM_THROW("i2c write error");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Helper Function
|
|
||||||
//
|
|
||||||
|
|
||||||
uint8_t DS1808LC::getPot1Value(int dutyPercent) {
|
|
||||||
uint8_t result = 0;
|
|
||||||
int scaledResistance = getScaledResistance(dutyPercent);
|
|
||||||
|
|
||||||
if (scaledResistance > DS1808_MAX_POT_VALUE)
|
|
||||||
result = DS1808_MAX_POT_VALUE;
|
|
||||||
else {
|
|
||||||
result = scaledResistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t DS1808LC::getPot2Value(int dutyPercent) {
|
|
||||||
uint8_t result = 0;
|
|
||||||
int scaledResistance = getScaledResistance(dutyPercent);
|
|
||||||
|
|
||||||
if (scaledResistance <= DS1808_MAX_POT_VALUE)
|
|
||||||
result = 0;
|
|
||||||
else {
|
|
||||||
result = scaledResistance - DS1808_MAX_POT_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result > DS1808_MAX_POT_VALUE)
|
|
||||||
result = DS1808_MAX_POT_VALUE;
|
|
||||||
|
|
||||||
return result | DS1808_POT2_OFFSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DS1808LC::getPercentBrightness(uint8_t val1, uint8_t val2) {
|
|
||||||
val2 = val2 & (~DS1808_POT2_OFFSET);
|
|
||||||
int scaledResistance = val1 + val2;
|
|
||||||
int percent;
|
|
||||||
|
|
||||||
if (scaledResistance < DS1808_LOW_VALUE)
|
|
||||||
percent = 100;
|
|
||||||
else if (scaledResistance > DS1808_HIGH_VALUE)
|
|
||||||
percent = 0;
|
|
||||||
else
|
|
||||||
percent = 100 - (((scaledResistance - DS1808_LOW_VALUE) * 100) / (DS1808_HIGH_VALUE - DS1808_LOW_VALUE));
|
|
||||||
return percent;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DS1808LC::getScaledResistance(int dutyPercent) {
|
|
||||||
int scaledResistance;
|
|
||||||
|
|
||||||
if (dutyPercent == 0)
|
|
||||||
scaledResistance = 2 * DS1808_MAX_POT_VALUE;
|
|
||||||
else if (dutyPercent == 100)
|
|
||||||
scaledResistance = 0;
|
|
||||||
else
|
|
||||||
scaledResistance = (((100 - dutyPercent) * (DS1808_HIGH_VALUE - DS1808_LOW_VALUE)) / 100) + DS1808_LOW_VALUE;
|
|
||||||
return scaledResistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@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 "upm/iLightController.h"
|
|
||||||
#include "mraa/i2c.hpp"
|
|
||||||
|
|
||||||
namespace upm
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief DS1808LC lighting controller library
|
|
||||||
* @defgroup DS1808LC libupm-ds1808lc
|
|
||||||
* @ingroup ds1808lc i2c maxim light ilightcontroller
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief API for DS1808 Dual Log Digital Potentiometer as a Light Controller
|
|
||||||
*
|
|
||||||
* The Maxim Integrated
|
|
||||||
* [DS1808](http://www.maximintegrated.com/en/products/analog/data-converters/digital-potentiometers/DS1808.html)
|
|
||||||
* Dual Log Digital Potentiometer
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @library ds1808lc
|
|
||||||
* @sensor ds1808lc
|
|
||||||
* @comname Maxim DS1808 as lighting controller
|
|
||||||
* @altname DS1808LC
|
|
||||||
* @type light
|
|
||||||
* @man maxim
|
|
||||||
* @con i2c
|
|
||||||
* @if ilightcontroller
|
|
||||||
*/
|
|
||||||
class DS1808LC : public upm::ILightController
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DS1808LC(int gpioPower, int i2cBus);
|
|
||||||
~DS1808LC();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const char* getModuleName() { return "ds1808lc"; }
|
|
||||||
bool isPowered();
|
|
||||||
void setPowerOn();
|
|
||||||
void setPowerOff();
|
|
||||||
int getBrightness();
|
|
||||||
void setBrightness(int dutyPercent);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int getPercentBrightness(uint8_t val1, uint8_t val2);
|
|
||||||
uint8_t getPot1Value(int dutyPercent);
|
|
||||||
uint8_t getPot2Value(int dutyPercent);
|
|
||||||
int getScaledResistance(int dutyPercent);
|
|
||||||
|
|
||||||
mraa::Result status;
|
|
||||||
mraa::I2c* i2c;
|
|
||||||
int pinPower;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
|||||||
%module javaupm_ds1808lc
|
|
||||||
%include "../upm.i"
|
|
||||||
%include "arrays_java.i";
|
|
||||||
%include "../java_buffer.i"
|
|
||||||
%include "cpointer.i"
|
|
||||||
%include "typemaps.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "ds1808lc.h"
|
|
||||||
|
|
||||||
%pragma(java) jniclasscode=%{
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("javaupm_ds1808lc");
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
System.err.println("Native code library failed to load. \n" + e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%}
|
|
@ -1,8 +0,0 @@
|
|||||||
%module jsupm_ds1808lc
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "ds1808lc.h"
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@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 "mraa-utils.h"
|
|
||||||
#include "mraa/gpio.hpp"
|
|
||||||
|
|
||||||
#define UPM_THROW(msg) throw std::runtime_error(std::string(__FUNCTION__) + ": " + (msg))
|
|
||||||
|
|
||||||
void MraaUtils::setGpio(int pin, int level)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
mraa_result_t status = MRAA_ERROR_NO_RESOURCES;
|
|
||||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
|
||||||
if (gpio != NULL)
|
|
||||||
{
|
|
||||||
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
|
|
||||||
status = mraa_gpio_write(gpio, level);
|
|
||||||
mraa_gpio_close(gpio);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
*/
|
|
||||||
mraa::Gpio gpio(pin);
|
|
||||||
gpio.dir(mraa::DIR_OUT);
|
|
||||||
if (gpio.write(level) != mraa::SUCCESS)
|
|
||||||
UPM_THROW("gpio write failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int MraaUtils::getGpio(int pin)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
mraa_result_t status = MRAA_ERROR_NO_RESOURCES;
|
|
||||||
mraa_gpio_context gpio = mraa_gpio_init(pin);
|
|
||||||
if (gpio != NULL)
|
|
||||||
{
|
|
||||||
status = mraa_gpio_dir(gpio, MRAA_GPIO_IN);
|
|
||||||
int value = mraa_gpio_read(gpio);
|
|
||||||
if (value != -1)
|
|
||||||
*level = value;
|
|
||||||
else
|
|
||||||
status = MRAA_ERROR_NO_RESOURCES;
|
|
||||||
mraa_gpio_close(gpio);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
*/
|
|
||||||
mraa::Gpio gpio(pin);
|
|
||||||
gpio.dir(mraa::DIR_IN);
|
|
||||||
return gpio.read();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Author: Henry Bruce <henry.bruce@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mraa/types.h"
|
|
||||||
|
|
||||||
class __attribute__ ((visibility("hidden"))) MraaUtils
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void setGpio(int pin, int level);
|
|
||||||
static int getGpio(int pin);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
%module pyupm_ds1808lc
|
|
||||||
%include "../upm.i"
|
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
|
||||||
|
|
||||||
%include "ds1808lc.h"
|
|
||||||
%{
|
|
||||||
#include "ds1808lc.h"
|
|
||||||
%}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user