Compare commits

...

53 Commits

Author SHA1 Message Date
cde747439f upm: v1.0.2
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-08 15:47:13 -08:00
dfc7a710d4 firmata: extended data types on pins to allow subplatform usage
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-08 15:10:36 -08:00
130cb822e4 rf22: Initial implementation for RFM22B radios, C++ only & bindings
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-07 14:38:56 -08:00
c057fa6708 travis.yml: use different swig ppa for Travis CI builds
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-06 19:33:00 -08:00
c6ad8cb5ee utilities: use a better method for detecting zephyr kernel version
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-05 15:04:34 -07:00
024b43dfa3 utilities: fix new Zephyr k_timer based implementation
- Fixed the Zephyr kernel version checks to check for 0.1.6 rather
  than 1.6.0.
- fixed the k_timer implementation to actually work.  None of these
  were being called correctly.
- due to the fact that the k_timer API only has a 1ms resolution,
  re-implement upm_delay_us() (on 0.1.6 version of zephyr) as a busy
  loop using a upm_clock_t.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-05 13:41:19 -07:00
6667646d32 mb704x: Initial implementation; C; FTI; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-02 16:44:43 -07:00
e1e9067744 groups.md: Add MaxBotix manufacturer
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-02 16:44:43 -07:00
c4656bf8ba utilities: add Zephyr 1.6 k_timer support (pulled from zupm)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-02 16:44:43 -07:00
232089f400 cmake: Check for JAVA in top-level CMakeLists.txt
Moved require for Java/JNI/mraajava to top-level CMakeLists.txt
which will fail early if these are NOT found (vs failing in
the src-level CMakeLists.txt

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-29 15:14:32 -08:00
09144e712b cmake: Consolidated BUILDJAVAEXAMPLES and BUILDEXAMPLES
The java examples will now build if BUILDSWIGJAVA=on and
BUILDEXAMPLES=on.  This is similar to the C/C++ examples.

    * Replaced BUILDJAVAEXAMPLES w/BUILDEXAMPLES
    * Updated docs
    * Updated travis-ci

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-29 12:25:25 -08:00
2d94c2ed90 travis-ci: Turn on FTI source compiling in travis-ci
* Build FTI source w/travis

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-29 11:49:52 -08:00
91652a2da5 button: fix so that button intr C example is built
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-29 12:02:26 -07:00
929244b27a ims: Fixed IMS java example
* Fixed a compile issue for the JAVA example
    * Added C header to swig java/js interface files

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-29 09:56:57 -08:00
9a4f0cae0c ims: Added FTI and java example
* Added compiling FTI for IMS
    * Updated JAVA example, added to CMakeLists.txt

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-29 08:51:45 -08:00
402de082d3 ecezo: make sure to mraa_init() in ecezo_uart_init()
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-28 18:23:18 -07:00
ad275e1d41 ecezo: initial implementation; C, C++; FTI + examples
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-28 17:45:23 -07:00
d4559878df cmake: Removed -dirty from VERSION if git_describe fails
* Removed -dirty
    * Also removed redundant set(PACK_PACKAGE_VERSION ...
      since the first gets overwritten by the second

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-22 15:03:14 -08:00
971cb4ab51 ims: Initial turnin of I2C Moisture Sensor
* Added C library
    * Added CXX library
    * Added C/CXX/java/js/python examples

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-21 14:57:15 -08:00
a2698fd560 upm: v1.0.1
Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-21 12:20:03 -08:00
11e14a891f ms5803: remove utf8 delta-sigma characters from comment block
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-16 10:57:21 -07:00
803f9a9838 ms5803: initial implementation; C, C++; FTI + examples
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-14 17:26:42 -07:00
7bc9ef0150 cmake: disable some other warnings seen with edison gcc 4.9.1
Also, fix possible uninitialized access in ds1808lc C++ example.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-11 10:44:43 -07:00
72e8629d72 cmake: Make sure utilities directory gets added to cmake
If directories are specified with -DMODULE_LIST=blah, it's
possible to skip adding the utilities directory which is needed
by *most* sensor library targets in UPM.  Added a check for this
when using -DMODULE_LIST.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-08 21:58:05 -08:00
cdc33ceb9f bitbake: Fix for pthreads C test w/yocto
Fixed a problem where the C/CXX compile flags were getting
overwritten.  Fixed warnings in a few sensor drivers.

This commit fixes #485

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-08 16:28:54 -08:00
54771e63c1 my9221: C implementation; C example; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-08 17:13:22 -07:00
fde727b601 Button: Adding C sources and C examples
This commit adds C sources and examples for the button sensor.

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-11-08 13:38:52 -08:00
68091dcf43 werror: Don't emit -Wmisleading-indentation warnings
GCC-6 added -Wmisleading-indentation to -Wall.  Skip these for now.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-07 16:46:57 -08:00
1630ebfca4 otp538u: C implementation; FTI; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-07 13:53:43 -07:00
1aa748e3d6 docs: Removed 'Grove' from Comments
Signed-off-by: Suyash Lakhotia <suyashlakhotia@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-11-04 13:08:31 -07:00
b3991979ad examples: Changed Node.js module from jsupm_grove
Signed-off-by: Suyash Lakhotia <suyashlakhotia@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-11-04 13:08:31 -07:00
3eb3a0b825 guvas12d: C implementation; FTI; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-04 12:52:33 -06:00
9be920dbcd cxx_warnings: Misc changes to enable Werror
* CMake option to enable -Werror as default
    * Change to make sure all cxx examples have correct target name
    * Added PUBLIC CXX compiler flags to ads1x15 and ozw targets to
      work around compiler warnings
    * Renamed cmake variable for compiler warnings

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-03 16:45:32 -07:00
601d25cebc llvm: Fixed remaining warnings for llvm
This commit addresses warnings emitted from the llvm
compilers which were not encountered with gnu.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-03 14:14:37 -07:00
c900743f8d upm.i: turn off swig warnings relating to nested structs
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 13:54:46 -06:00
2b4e43281f Wunused-variable: fix several warnings
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 13:23:44 -06:00
630d12d963 mic: fix sign comparison warnings
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 13:23:44 -06:00
8da9f28157 gas: fix sign comparison warnings
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 13:23:44 -06:00
aab0c5afe2 lcm1602, st7735: Fix up some Worder warnings
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 12:51:07 -06:00
0589f445f0 Wreorder: fix a variety of re-ordering warnings
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 12:19:21 -06:00
d33e7e532e bacnetmstp: fix -Wreturn-type
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-03 12:14:26 -06:00
c63692b5fd Wreorder: Fixed a subset of reorder errors
This commit addresses warnings emitted from -Wreorder
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-03 10:19:59 -07:00
2f31aede0e Wno-unknown-pragmas: Fixed all unknown pragmas
This commit addresses all warnings emitted from -Wno-unknown-pragmas
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 22:57:38 -07:00
33471436bf Wunused-but-set-variable: Fixed all unused but set variables
This commit addresses all warnings emitted from
-Wunused-but-set-variable in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 22:45:52 -07:00
ee27485218 Wnon-virtual-dtor: Fixed all virtual functions w/o virtual destructor
This commit addresses all warnings emitted from -Wnon-virtual-dtor
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 22:35:53 -07:00
6bc22dcee2 Wunused-variable: Fixed all unused variables in src
Additional unused variables.

This commit addresses all warnings emitted from -Wunused-variable
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 22:29:59 -07:00
ae9b8fb13e Wsign-compare: Fixed all sign compare warnings in src
This commit addresses all warnings emitted from -Wunused-function
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 22:27:17 -07:00
1dd5cbb445 Wunused-function: Fixed all unused functions in src
This commit addresses all warnings emitted from -Wunused-function
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 21:55:19 -07:00
a3a1fdc81b Wunused-variable: Fixed all unused variables in src
This commit addresses all warnings emitted from -Wunused-variable
in the C++ src.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-11-02 21:44:27 -07:00
1f954a8cbf ppd42ns: C implementation; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-02 17:51:05 -06:00
8f6442e9c7 utilities: add new platform checks, implement new clock functions
The new clock functions provide a mechanism for measuring durations in
the ms (millisecond) or us (microsecond) range, in a platform
independant manner.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-02 17:51:05 -06:00
f2ad2c5679 upm_math.h: use new platform defines, include math.h on zephyr platforms
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-02 17:51:05 -06:00
d03de942c5 upm_platform.h: add new include for defining current platform (linux/zephyr, for now)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-11-02 17:51:05 -06:00
237 changed files with 11220 additions and 1536 deletions

View File

@ -15,7 +15,7 @@ compiler:
- clang - clang
- gcc - gcc
install: install:
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-dev/swig - sudo add-apt-repository --yes ppa:rosmo/swig3.0.7
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -y --force-yes -qq swig3.0 git - sudo apt-get install -y --force-yes -qq swig3.0 git
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig - sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
@ -36,7 +36,7 @@ script:
- sudo make install - sudo make install
- sudo ldconfig - sudo ldconfig
# Build/install UPM # Build/install UPM
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA -DBUILDTESTS=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js - cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDTESTS=ON -DBUILDFTI=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
addons: addons:
apt: apt:
sources: sources:

View File

@ -8,13 +8,12 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
option (BUILDSWIGPYTHON "Build swig python modules" ON) option (BUILDSWIGPYTHON "Build swig python modules" ON)
option (BUILDSWIGNODE "Build swig node modules" ON) option (BUILDSWIGNODE "Build swig node modules" ON)
option (BUILDSWIGJAVA "Build swig java modules" OFF) option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (BUILDEXAMPLES "Build C/C++ example binaries" OFF) option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
option (BUILDJAVAEXAMPLES "Build java example jars" 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 (NPM "Generate NPM/GYP tarballs" OFF) option (NPM "Generate NPM/GYP tarballs" OFF)
option (BUILDTESTS "Generate check-ups for upm" OFF) option (BUILDTESTS "Generate check-ups for upm" OFF)
option (WERROR "Make all warnings into errors." OFF) option (WERROR "Make all warnings into errors." ON)
# Warn if building in source root # Warn if building in source root
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
@ -71,6 +70,7 @@ include (CheckCXXCompilerFlag)
# This function checks to see if each flag is supported # This function checks to see if each flag is supported
# by the compiler before setting the compile option. # by the compiler before setting the compile option.
function (upm_add_compile_flags compiler) function (upm_add_compile_flags compiler)
set (_TMP_COMPILER_FLAGS "")
# Iterate the flags, check if supported # Iterate the flags, check if supported
foreach (flag ${ARGN}) foreach (flag ${ARGN})
# Check if this compile flag is supported # Check if this compile flag is supported
@ -85,15 +85,17 @@ function (upm_add_compile_flags compiler)
endforeach (flag ${ARGN}) endforeach (flag ${ARGN})
# Set the variable in the parent scope # Set the variable in the parent scope
set (CMAKE_${compiler}_FLAGS ${_TMP_COMPILER_FLAGS} PARENT_SCOPE) set (CMAKE_${compiler}_FLAGS "${CMAKE_${compiler}_FLAGS} ${_TMP_COMPILER_FLAGS}" PARENT_SCOPE)
endfunction () endfunction ()
# Compiler flags common to both C and CXX # Compiler flags common to both C and CXX
set (C_CXX_WARNING_FLAGS -Wall) # Enable -Wall
# GCC-6 added -Wmisleading-indentation to -Wall, skip these for now
set (C_CXX_WARNING_FLAGS -Wall -Wno-misleading-indentation -Wno-strict-aliasing)
# Errors as warnings? # Warnings as errors?
if (WERROR) if (WERROR)
list (APPEND C_CXX_WARNING_FLAGS -Werror) set (C_CXX_WARNING_FLAGS "-Werror ${C_CXX_WARNING_FLAGS}")
message (STATUS "Warnings as errors enabled (-Werror), disable with -DWERROR=off") message (STATUS "Warnings as errors enabled (-Werror), disable with -DWERROR=off")
endif (WERROR) endif (WERROR)
@ -136,6 +138,13 @@ if (BUILDSWIGNODE)
find_package (Node REQUIRED) find_package (Node REQUIRED)
endif (BUILDSWIGNODE) endif (BUILDSWIGNODE)
# Find JAVA/JNI
if (BUILDSWIGJAVA)
find_package (Java REQUIRED)
find_package (JNI REQUIRED)
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
endif (BUILDSWIGJAVA)
# Find swig if any wrapper is enabled # Find swig if any wrapper is enabled
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA) if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
find_package (SWIG 3.0.5 REQUIRED) find_package (SWIG 3.0.5 REQUIRED)
@ -184,7 +193,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags") git_describe (VERSION "--tags")
# If git_describe fails, use a dirty version # If git_describe fails, use a dirty version
if (${VERSION} MATCHES -NOTFOUND) if (${VERSION} MATCHES -NOTFOUND)
set (VERSION "v1.0.0-dirty") set (VERSION "v1.0.2")
message (WARNING "Failed to retrieve UPM version with 'git describe' (using " message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
"${VERSION}). Check that git is installed and this is a valid git repo.") "${VERSION}). Check that git is installed and this is a valid git repo.")
endif () endif ()
@ -378,7 +387,6 @@ endif()
if (RPM) if (RPM)
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}") message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_GENERATOR "RPM") set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "upm") set(CPACK_PACKAGE_NAME "upm")
set(upm_PACKAGE_ON_TAG ".") set(upm_PACKAGE_ON_TAG ".")
@ -415,7 +423,8 @@ if(BUILDEXAMPLES)
endif(BUILDCPP) endif(BUILDCPP)
endif() endif()
if(BUILDJAVAEXAMPLES) # Build java examples
if(BUILDSWIGJAVA AND BUILDEXAMPLES)
add_subdirectory (examples/java) add_subdirectory (examples/java)
endif() endif()

View File

@ -80,14 +80,10 @@ Building documentation
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
-DBUILDDOC=ON -DBUILDDOC=ON
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Build C++ example binaries Build C/C++/JAVA examples
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
-DBUILDEXAMPLES=ON -DBUILDEXAMPLES=ON
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Build Java examples
~~~~~~~~~~~~~
-DBUILDJAVAEXAMPLES=ON
~~~~~~~~~~~~~
If you intend to turn on all the options and build everything at once If you intend to turn on all the options and build everything at once
(C++, Java, Node, Python and Documentation) you will have to edit the (C++, Java, Node, Python and Documentation) you will have to edit the

View File

@ -4,6 +4,22 @@ 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:
### v1.0.2
* Minor cmake changes for Java builds and Java examples are now toggled with
the same BUILDEXAMPLES cmake switch
* Made some improvements in the utilities class for our C drivers
* Fixed issue with some drivers not being usable on subplatforms due to pin
numbers using uint8 type
* New sensors: ims, ecezo, mb704x, rf22
### v1.0.1
* Warnings as errors enabled for C/CXX (fixed warnings from -Wall and others)
* Fix for C/CXX compile flag append issue #485
* C sensor libraries for: my9221, otp538u, guvas12d, ppd42ns
* New sensor: ms5803
### v1.0.0 ### v1.0.0
* Added approximately 50 C sources for UPM drivers that can be used on both * Added approximately 50 C sources for UPM drivers that can be used on both

BIN
docs/images/ims.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
docs/images/rf22.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

View File

@ -24,6 +24,7 @@ hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
hm11.cxx HM11Sample.java hm11.js hm11.py hm11.cxx HM11Sample.java hm11.js hm11.py
hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py
htu21d.cxx HTU21DSample.java htu21d.js htu21d.py htu21d.cxx HTU21DSample.java htu21d.js htu21d.py
ims.cxx IMS_Example.java ims.js ims.py
itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py
joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py

View File

@ -1,3 +1,7 @@
# Selectively disable certain warnings for the examples
# nrf examples flag -Wtautological-compare
set (CXX_DISABLED_WARNINGS -Wno-tautological-compare)
# Extract module name from non-standard example name # Extract module name from non-standard example name
macro(get_module_name example_name module_name) macro(get_module_name example_name module_name)
string(LENGTH ${example_name} length) string(LENGTH ${example_name} length)
@ -32,6 +36,15 @@ macro(add_custom_example example_bin example_src example_module_list)
if (found_all_modules) if (found_all_modules)
add_executable (${example_bin} ${example_src}) add_executable (${example_bin} ${example_src})
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
# Disable warnings from CXX_DISABLED_WARNINGS
foreach(flag ${CXX_DISABLED_WARNINGS})
compiler_flag_supported(CXX is_supported ${flag})
if (is_supported)
target_compile_options(${example_bin} PRIVATE "${flag}")
endif(is_supported)
endforeach(flag ${CXX_DISABLED_WARNINGS})
foreach (module ${example_module_list}) foreach (module ${example_module_list})
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}") set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
include_directories (${module_dir}) include_directories (${module_dir})
@ -55,11 +68,6 @@ macro(add_example example_name)
get_module_name(${example_name} module_name) get_module_name(${example_name} module_name)
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}") set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
# nrf examples can flag a warning, make sure this isn't an error, currently
# this is done for all examples
set_source_files_properties(${example_src}
PROPERTIES COMPILE_FLAGS -Wno-tautological-compare)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}" if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
AND EXISTS ${module_dir} AND EXISTS ${module_dir}
AND IS_DIRECTORY ${module_dir}) AND IS_DIRECTORY ${module_dir})
@ -313,45 +321,51 @@ add_example (hka5)
add_example (dfrorp) add_example (dfrorp)
add_example (dfrec) add_example (dfrec)
add_example (sht1x) add_example (sht1x)
add_example (ms5803)
add_example (ims)
add_example (ecezo)
add_example (mb704x)
add_example (rf22-server)
add_example (rf22-client)
# These are special cases where you specify example binary, source file and module(s) # These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src) include_directories (${PROJECT_SOURCE_DIR}/src)
add_custom_example (groveled-multi-example groveled-multi.cxx grove) add_custom_example (groveled-multi-example-cxx groveled-multi.cxx grove)
add_custom_example (lcm1602-i2c-example lcm1602-i2c.cxx lcd) add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcd)
add_custom_example (lcm1602-parallel-example lcm1602-parallel.cxx lcd) add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcd)
add_custom_example (jhd1313m1-lcd-example jhd1313m1-lcd.cxx lcd) add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx lcd)
add_custom_example (es08a-example es08a.cxx servo) add_custom_example (es08a-example-cxx es08a.cxx servo)
add_custom_example (ssd1306-oled-example ssd1306-oled.cxx lcd) add_custom_example (ssd1306-oled-example-cxx ssd1306-oled.cxx lcd)
add_custom_example (ssd1308-oled-example ssd1308-oled.cxx lcd) add_custom_example (ssd1308-oled-example-cxx ssd1308-oled.cxx lcd)
add_custom_example (ssd1327-oled-example ssd1327-oled.cxx lcd) add_custom_example (ssd1327-oled-example-cxx ssd1327-oled.cxx lcd)
add_custom_example (sainsmartks-example sainsmartks.cxx lcd) add_custom_example (sainsmartks-example-cxx sainsmartks.cxx lcd)
add_custom_example (eboled-example eboled.cxx lcd) add_custom_example (eboled-example-cxx eboled.cxx lcd)
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150) add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example ak8975.cxx mpu9150) add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)
add_custom_example (mpu9250-example mpu9250.cxx mpu9150) add_custom_example (mpu9250-example-cxx mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example groveledbar.cxx my9221) add_custom_example (groveledbar-example-cxx groveledbar.cxx my9221)
add_custom_example (grovecircularled-example grovecircularled.cxx my9221) add_custom_example (grovecircularled-example-cxx grovecircularled.cxx my9221)
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bmp280") add_custom_example (temperature-sensor-example-cxx temperature-sensor.cxx "si7005;bmpx8x;bmp280")
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bmp280") add_custom_example (humidity-sensor-example-cxx humidity-sensor.cxx "si7005;bmp280")
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bmp280") add_custom_example (pressure-sensor-example-cxx pressure-sensor.cxx "bmpx8x;bmp280")
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713") add_custom_example (co2-sensor-example-cxx co2-sensor.cxx "t6713")
add_custom_example (adc-example adc-sensor.cxx "ads1x15") add_custom_example (adc-example-cxx adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009") add_custom_example (light-sensor-example-cxx light-sensor.cxx "si1132;max44009")
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h") add_custom_example (light-controller-example-cxx light-controller.cxx "lp8860;ds1808lc;hlg150h")
add_custom_example (bme280-example bme280.cxx bmp280) add_custom_example (bme280-example-cxx bme280.cxx bmp280)
add_custom_example (bma250e-example bma250e.cxx bmx055) add_custom_example (bma250e-example-cxx bma250e.cxx bmx055)
add_custom_example (bmg160-example bmg160.cxx bmx055) add_custom_example (bmg160-example-cxx bmg160.cxx bmx055)
add_custom_example (bmm150-example bmm150.cxx bmx055) add_custom_example (bmm150-example-cxx bmm150.cxx bmx055)
add_custom_example (bmc150-example bmc150.cxx bmx055) add_custom_example (bmc150-example-cxx bmc150.cxx bmx055)
add_custom_example (bmi055-example bmi055.cxx bmx055) add_custom_example (bmi055-example-cxx bmi055.cxx bmx055)
if (OPENZWAVE_FOUND) if (OPENZWAVE_FOUND)
include_directories(${OPENZWAVE_INCLUDE_DIRS}) include_directories(${OPENZWAVE_INCLUDE_DIRS})
add_custom_example (ozwdump-example ozwdump.cxx ozw) add_custom_example (ozwdump-example-cxx ozwdump.cxx ozw)
add_custom_example (aeotecss6-example aeotecss6.cxx ozw) add_custom_example (aeotecss6-example-cxx aeotecss6.cxx ozw)
add_custom_example (aeotecsdg2-example aeotecsdg2.cxx ozw) add_custom_example (aeotecsdg2-example-cxx aeotecsdg2.cxx ozw)
add_custom_example (aeotecdw2e-example aeotecdw2e.cxx ozw) add_custom_example (aeotecdw2e-example-cxx aeotecdw2e.cxx ozw)
add_custom_example (aeotecdsb09104-example aeotecdsb09104.cxx ozw) add_custom_example (aeotecdsb09104-example-cxx aeotecdsb09104.cxx ozw)
add_custom_example (tzemt400-example tzemt400.cxx ozw) add_custom_example (tzemt400-example-cxx tzemt400.cxx ozw)
endif() endif()
add_custom_example (nmea_gps_i2c_example-cxx nmea_gps_i2c.cxx nmea_gps) add_custom_example (nmea_gps_i2c_example-cxx nmea_gps_i2c.cxx nmea_gps)

View File

@ -23,7 +23,7 @@ void printState(upm::ILightController *lightController)
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
int status = 0; int status = 0;
upm::ILightController* lightController; upm::ILightController* lightController = nullptr;
try { try {
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS); lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);

81
examples/c++/ecezo.cxx Normal file
View File

@ -0,0 +1,81 @@
/*
* 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 <signal.h>
#include <upm_utilities.h>
#include <ecezo.hpp>
using namespace std;
using namespace upm;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
upm::ECEZO *sensor = new upm::ECEZO(0, 9600, false);
// For I2C, assuming the device is configured for address 0x64 on
// I2C bus 0, you could use something like:
//
// upm::ECEZO *sensor = new upm::ECEZO(0, 0x64, true);
while (shouldRun)
{
// this will take about 1 second to complete
sensor->update();
cout << "EC "
<< sensor->getEC()
<< " uS/cm, TDS "
<< sensor->getTDS()
<< " mg/L, Salinity "
<< sensor->getSalinity()
<< " PSS-78, SG "
<< sensor->getSG()
<< endl;
upm_delay(5);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -33,7 +33,6 @@ bool shouldRun = true;
// analog voltage, usually 3.3 or 5.0 // analog voltage, usually 3.3 or 5.0
#define GUVAS12D_AREF 5.0 #define GUVAS12D_AREF 5.0
#define SAMPLES_PER_QUERY 1024
void sig_handler(int signo) void sig_handler(int signo)
{ {
@ -46,8 +45,8 @@ int main()
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
//! [Interesting] //! [Interesting]
// The was tested with the Grove UV Sensor module. // This was tested with the Grove UV Sensor module.
// It has a sensing range from between 200-400nm. It's strongest // It has a sensing range from between 240-370nm. It's strongest
// response is around 320-360nm. // response is around 320-360nm.
// Instantiate a GUVAS12D on analog pin A0 // Instantiate a GUVAS12D on analog pin A0
@ -57,9 +56,10 @@ int main()
while (shouldRun) while (shouldRun)
{ {
cout << "AREF: " << GUVAS12D_AREF cout << "Volts: " << volts->volts()
<< ", Voltage value (higher means more UV): " << ", Intensity: " << volts->intensity()
<< volts->value(GUVAS12D_AREF, SAMPLES_PER_QUERY) << endl; << " mW/m^2"
<< endl;
sleep(1); sleep(1);
} }

View File

@ -71,7 +71,6 @@ void sendCommand(upm::HM11* ble, char *cmd)
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
//! [Interesting] //! [Interesting]
char buffer[BUFSIZ];
// Instantiate a HM11 BLE Module on UART 0 // Instantiate a HM11 BLE Module on UART 0
upm::HM11* ble = new upm::HM11(0); upm::HM11* ble = new upm::HM11(0);

69
examples/c++/ims.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "ims.hpp"
using namespace upm;
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 IMS instance using i2c bus 0 and default address
upm::IMS sensor(0);
while (shouldRun)
{
std::cout << "Version: "
<< sensor.get_version()
<< " light: "
<< sensor.get_light()
<< " moisture: "
<< sensor.get_moisture()
<< " temp: "
<< sensor.get_temperature()
<< " C"
<< std::endl;
sleep(1);
}
//! [Interesting]
std::cout << "Exiting..." << std::endl;
return 0;
}

View File

@ -48,7 +48,6 @@ main(int argc, char **argv)
sensor = new upm::LoL(); sensor = new upm::LoL();
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
unsigned char *buffer;
//buffer = sensor->getFramebuffer(); //buffer = sensor->getFramebuffer();
int x = 0, y = 0; int x = 0, y = 0;
while (!is_running) { while (!is_running) {

70
examples/c++/mb704x.cxx Normal file
View File

@ -0,0 +1,70 @@
/*
* 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 <signal.h>
#include <upm_utilities.h>
#include <mb704x.hpp>
using namespace std;
using namespace upm;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a MB704X sensor using default parameters (bus 0,
// address 112)
upm::MB704X *sensor = new upm::MB704X();
while (shouldRun)
{
cout << "Range: "
<< sensor->getRange()
<< " cm"
<< endl;
upm_delay_ms(500);
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

78
examples/c++/ms5803.cxx Normal file
View File

@ -0,0 +1,78 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "ms5803.hpp"
using namespace std;
using namespace upm;
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 MS5803 instance using i2c bus 0 and default address
upm::MS5803 *sensor = new upm::MS5803(0);
// For SPI, bus 0, you would pass -1 as the address, and a valid
// pin for CS (or -1 if you are using a hw pin you have no control
// over, like edison):
// MS5803(0, -1, 9);
while (shouldRun)
{
// update our values from the sensor
sensor->update();
cout << "Temperature: "
<< sensor->getTemperature()
<< " C, "
<< "Pressure: "
<< sensor->getPressure()
<< " mbar"
<< endl;
sleep(1);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -80,7 +80,6 @@ Used to test the UART TX characteristic notification
static uart_over_ble_t uart_over_ble; static uart_over_ble_t uart_over_ble;
static uint8_t uart_buffer[20]; static uint8_t uart_buffer[20];
static uint8_t uart_buffer_len = 0; static uint8_t uart_buffer_len = 0;
static uint8_t dummychar = 0;
void void
sig_handler(int signo) sig_handler(int signo)

View File

@ -45,14 +45,17 @@ int main ()
//! [Interesting] //! [Interesting]
// Instantiate a dust sensor on GPIO pin D8 // Instantiate a dust sensor on GPIO pin D8
upm::PPD42NS* dust = new upm::PPD42NS(8); upm::PPD42NS* dust = new upm::PPD42NS(8);
upm::dustData data; ppd42ns_dust_data data;
cout << "This program will give readings every 30 seconds until you stop it" << endl; cout << "This program will give readings every 30 seconds until "
<< "you stop it"
<< endl;
while (shouldRun) while (shouldRun)
{ {
data = dust->getData(); data = dust->getData();
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl; cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
cout << "Ratio: " << data.ratio << endl; cout << "Ratio: " << data.ratio << endl;
cout << "Concentration: " << data.concentration << endl; cout << "Concentration: " << data.concentration << endl;
cout << endl;
} }
//! [Interesting] //! [Interesting]

View File

@ -0,0 +1,72 @@
/*
* Author: Kiveisha Yevgeniy
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "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 <signal.h>
#include "rf22.hpp"
bool amWorking = true;
void
sig_handler (int signo) {
if (signo == SIGINT) {
amWorking = false;
}
}
//! [Interesting]
int
main (int argc, char ** argv) {
// SPI bus 0, CS pin 10, INTR pin 2
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
if (!rf22->init()) {
std::cout << "RF22 init failed" << std::endl;
return 0x1;
}
uint8_t data[] = "Hello World!";
uint8_t buf[RF22_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
signal (SIGINT, sig_handler);
while (amWorking) {
std::cout << "Sending to rf22_server" << std::endl;
// Send a message to rf22_server
rf22->send(data, sizeof(data));
rf22->waitPacketSent();
// Now wait for a reply
rf22->waitAvailableTimeout(1000000);
if (rf22->recv(buf, &len)) {
std::cout << "got response: " << (char*)buf << std::endl;
} else {
std::cout << "!!! NO RESPONSE !!!" << std::endl;
}
}
std::cout << "Exit 'rfm22-client'" << std::endl;
return 0;
}
//! [Interesting]

View File

@ -0,0 +1,73 @@
/*
* Author: Kiveisha Yevgeniy
* Copyright (c) 2015-2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "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 <signal.h>
#include "rf22.hpp"
bool amWorking = true;
void
sig_handler (int signo) {
if (signo == SIGINT) {
amWorking = false;
}
}
//! [Interesting]
int
main (int argc, char ** argv) {
// SPI bus 0, CS pin 10, INTR pin 2
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
if (!rf22->init()) {
std::cout << "RF22 init failed" << std::endl;
return 0x1;
}
uint8_t buf[RF22_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
signal (SIGINT, sig_handler);
while (amWorking) {
// rf22->waitAvailable();
rf22->waitAvailableTimeout (500);
// Should be a message for us now
if (rf22->recv(buf, &len)) {
std::cout << "got request: " << (char*)buf << std::endl;
// Send a reply
uint8_t data[] = "And hello back to you";
rf22->send(data, sizeof(data));
rf22->waitPacketSent();
} else {
// Do whatever you need.
}
}
delete rf22;
std::cout << "Exit 'rfm22-server'" << std::endl;
return 0;
}
//! [Interesting]

View File

@ -44,8 +44,6 @@ sig_handler(int signo)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
float voltage = 0;
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl; 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 sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup

View File

@ -30,7 +30,6 @@
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
mraa_result_t error = MRAA_SUCCESS;
upm::TSL2561 *sensor = NULL; upm::TSL2561 *sensor = NULL;
int loopCount = 100; int loopCount = 100;

View File

@ -23,7 +23,7 @@ macro(add_custom_example example_bin example_src example_module_list)
set(found_all_modules FALSE) set(found_all_modules FALSE)
endif() endif()
if (MODULE_LIST) if (MODULE_LIST)
list(FIND MODULE_LIST ${module}-c index) list(FIND MODULE_LIST ${module} index)
if (${index} EQUAL -1) if (${index} EQUAL -1)
set(found_all_modules FALSE) set(found_all_modules FALSE)
endif() endif()
@ -132,6 +132,15 @@ add_example (linefinder)
add_example (uln200xa) add_example (uln200xa)
add_example (mma7660) add_example (mma7660)
add_example (buzzer) add_example (buzzer)
add_example (ppd42ns)
add_example (guvas12d)
add_example (otp538u)
add_example (button)
add_example (my9221)
add_example (ms5803)
add_example (ims)
add_example (ecezo)
add_example (mb704x)
# Custom examples # Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps) add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
@ -139,3 +148,4 @@ add_custom_example (lcm1602-i2c-example-c lcm1602-i2c.c lcm1602)
add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602) add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602)
add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220) add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220)
add_custom_example (md-stepper-example-c md-stepper.c md) add_custom_example (md-stepper-example-c md-stepper.c md)
add_custom_example (button_intr-example-c button_intr.c button)

59
examples/c/button.c Normal file
View File

@ -0,0 +1,59 @@
/*
* Authors: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "button.h"
#include "upm_utilities.h"
#include "mraa.h"
int counter;
void button_isr(void *arg){
counter++;
}
int main()
{
counter = 0;
if (mraa_init() != MRAA_SUCCESS)
{
perror("Failed to initialize mraa\n");
return -1;
}
button_context dev = button_init(2);
button_install_isr(dev, MRAA_GPIO_EDGE_RISING, button_isr, NULL);
while(1){
printf("Interrupts: %d\n", counter);
upm_delay(3);
}
return 0;
}

54
examples/c/button_intr.c Normal file
View File

@ -0,0 +1,54 @@
/*
* Authors: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "button.h"
#include "upm_utilities.h"
#include "mraa.h"
int main()
{
if (mraa_init() != MRAA_SUCCESS)
{
perror("Failed to initialize mraa\n");
return -1;
}
button_context dev = button_init(2);
bool abc = 0;
while(1){
if(button_get_value(dev, &abc) != UPM_SUCCESS){
printf("an error has occured\n");
}
upm_delay(1);
printf("value retrieved: %d\n", abc);
}
return 0;
}

85
examples/c/ecezo.c Normal file
View File

@ -0,0 +1,85 @@
/*
* 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 <signal.h>
#include <upm_utilities.h>
#include <ecezo.h>
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
ecezo_context sensor = ecezo_uart_init(0, 9600);
// For I2C, assuming the device is configured for address 0x64 on
// I2C bus 0, you could use something like:
//
// ecezo_context sensor = ecezo_i2c_init(0, 0x64);
if (!sensor)
{
printf("ecezo_init() failed.\n");
return 1;
}
while (shouldRun)
{
// this will take about 1 second to complete
if (ecezo_update(sensor))
{
printf("ecezo_update() failed\n");
}
else
{
printf("EC %f uS/cm, TDS %f mg/L, Salinity %f PSS-78, SG %f\n",
ecezo_get_ec(sensor),
ecezo_get_tds(sensor),
ecezo_get_salinity(sensor),
ecezo_get_sg(sensor));
}
upm_delay(5);
}
//! [Interesting]
printf("Exiting\n");
ecezo_close(sensor);
return 0;
}

89
examples/c/guvas12d.c Normal file
View File

@ -0,0 +1,89 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include <guvas12d.h>
bool shouldRun = true;
// analog voltage, usually 3.3 or 5.0
#define GUVAS12D_AREF 5.0
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// This was tested with the Grove UV Sensor module.
// It has a sensing range from between 240-370nm. It's strongest
// response is around 320-360nm.
// Instantiate a GUVAS12D on analog pin A0
guvas12d_context uv = guvas12d_init(0, GUVAS12D_AREF);
if (!uv)
{
printf("guvas12d_init() failed\n");
return 1;
}
// The higher the voltage the more intense the UV radiation.
while (shouldRun)
{
float volts = 0;
float intensity = 0;
if (guvas12d_get_volts(uv, &volts))
{
printf("guvas12d_get_volts() failed\n");
return 1;
}
if (guvas12d_get_intensity(uv, &intensity))
{
printf("guvas12d_get_intensity() failed\n");
return 1;
}
printf("Volts: %f, Intensity %f mW/m^2\n", volts, intensity);
upm_delay(1);
}
printf("Exiting\n");
guvas12d_close(uv);
//! [Interesting]
return 0;
}

75
examples/c/ims.c Normal file
View File

@ -0,0 +1,75 @@
/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "ims.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
ims_context* sensor = ims_init(0, IMS_ADDRESS_DEFAULT);
if (!sensor)
{
printf("ims_init() failed\n");
return 1;
}
// Every second, sample the sensor outputs
while (shouldRun)
{
uint16_t version, light, moisture, temp;
if (ims_get_version(sensor, &version) == UPM_SUCCESS &&
ims_get_light(sensor, &light) == UPM_SUCCESS &&
ims_get_moisture(sensor, &moisture) == UPM_SUCCESS &&
ims_get_temperature(sensor, &temp) == UPM_SUCCESS)
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
version, light, moisture, temp/10.0);
else
break;
upm_delay(1);
}
//! [Interesting]
printf("Exiting\n");
ims_close(sensor);
return 0;
}

77
examples/c/mb704x.c Normal file
View File

@ -0,0 +1,77 @@
/*
* 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 <signal.h>
#include <upm_utilities.h>
#include <mb704x.h>
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a MB704X sensor on i2c bus 0, address 112.
mb704x_context sensor = mb704x_init(0, 112);
if (!sensor)
{
printf("mb704x_init() failed.\n");
return 1;
}
while (shouldRun)
{
// this will take about 1 second to complete
int range = mb704x_get_range(sensor);
if (range < 0)
{
printf("Error getting range.\n");
}
else
{
printf("Range: %d cm\n", range);
}
upm_delay_ms(500);
}
printf("Exiting\n");
mb704x_close(sensor);
//! [Interesting]
return 0;
}

79
examples/c/ms5803.c Normal file
View File

@ -0,0 +1,79 @@
/*
* 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 <stdio.h>
#include <signal.h>
#include "ms5803.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a MS5803 on analog I2C bus 0, at the default address
ms5803_context sensor = ms5803_init(0, MS5803_DEFAULT_I2C_ADDR, -1);
if (!sensor)
{
printf("ms5803_init() failed\n");
return 1;
}
// Every second, sample the sensor and output the pressure and
// temperature
while (shouldRun)
{
if (ms5803_update(sensor))
{
printf("ms5803_update() failed\n");
}
printf("Temperature: %f C, Pressure = %f mbar\n",
ms5803_get_temperature(sensor),
ms5803_get_pressure(sensor));
upm_delay(1);
}
//! [Interesting]
printf("Exiting\n");
ms5803_close(sensor);
return 0;
}

89
examples/c/my9221.c Normal file
View File

@ -0,0 +1,89 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include <my9221.h>
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
// clock. We only use a single instance.
my9221_context leds = my9221_init(8, 9, 1);
if (!leds)
{
printf("my9221_init() failed\n");
return 1;
}
while (shouldRun)
{
// count up
printf("Counting up: ");
for (int i=0; i<my9221_get_max_leds(leds); i++)
{
printf("%d ", i);
my9221_clear_all(leds);
my9221_set_led(leds, i, true);
upm_delay_ms(100);
}
printf("\n");
upm_delay_ms(100);
// count down
printf("Counting down: ");
for (int i=my9221_get_max_leds(leds) - 1; i>=0; i--)
{
printf("%d ", i);
my9221_clear_all(leds);
my9221_set_led(leds, i, true);
upm_delay_ms(100);
}
printf("\n");
upm_delay_ms(100);
}
printf("Exiting...\n");
my9221_close(leds);
//! [Interesting]
return 0;
}

81
examples/c/otp538u.c Normal file
View File

@ -0,0 +1,81 @@
/*
* 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 <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include <otp538u.h>
bool shouldRun = true;
// analog voltage, usually 3.3 or 5.0
#define OTP538U_AREF 5.0
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a OTP538U on analog pins A0 and A1
// A0 is used for the Ambient Temperature and A1 is used for the
// Object temperature.
otp538u_context temps = otp538u_init(0, 1, OTP538U_AREF);
// enable debugging if you would like
// otp538u_set_debug(temps, true);
// Output ambient and object temperatures
while (shouldRun)
{
float ambient = 0, object = 0;
if (otp538u_get_ambient_temperature(temps, &ambient))
printf("otp538u_get_ambient_temperature() failed\n");
else if (otp538u_get_object_temperature(temps, &object))
printf("otp538u_get_object_temperature() failed\n");
else
printf("Ambient temp: %f C, Object temp: %f C\n",
ambient, object);
printf("\n");
upm_delay(1);
}
printf("Exiting\n");
otp538u_close(temps);
//! [Interesting]
return 0;
}

66
examples/c/ppd42ns.c Normal file
View File

@ -0,0 +1,66 @@
/*
* 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 <stdio.h>
#include <signal.h>
#include <ppd42ns.h>
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a dust sensor on GPIO pin D8
ppd42ns_context dust = ppd42ns_init(8);
ppd42ns_dust_data data;
printf("This program will give readings every 30 seconds until "
"you stop it\n");
while (shouldRun)
{
data = ppd42ns_get_data(dust);
printf("Low pulse occupancy: %d\n", data.lowPulseOccupancy);
printf("Ratio: %f\n", data.ratio);
printf("Concentration: %f\n\n", data.concentration);
}
printf("Exiting...\n");
ppd42ns_close(dust);
//! [Interesting]
return 0;
}

View File

@ -156,6 +156,10 @@ add_example(HKA5_Example hka5)
add_example(DFRORP_Example dfrorp) add_example(DFRORP_Example dfrorp)
add_example(DFREC_Example dfrec) add_example(DFREC_Example dfrec)
add_example(SHT1X_Example sht1x) add_example(SHT1X_Example sht1x)
add_example(MS5803_Example ms5803)
add_example(ECEZO_Example ecezo)
add_example(IMS_Example ims)
add_example(MB704X_Example mb704x)
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd) add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
add_example_with_path(Jhd1313m1Sample lcd i2clcd) add_example_with_path(Jhd1313m1Sample lcd i2clcd)

View File

@ -0,0 +1,60 @@
/*
* 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_ecezo.ECEZO;
public class ECEZO_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
ECEZO sensor = new ECEZO(0, 9600, false);
// For I2C, assuming the device is configured for address 0x64 on
// I2C bus 0, you could use something like:
//
// ECEZO sensor = new ECEZO(0, 0x64, true);
while (true)
{
// update our values from the sensor
sensor.update();
System.out.println("EC "
+ sensor.getEC()
+ " uS/cm, TDS "
+ sensor.getTDS()
+ " mg/L, Salinity "
+ sensor.getSalinity()
+ " PSS-78, SG "
+ sensor.getSG());
Thread.sleep(5000);
}
// ! [Interesting]
}
}

View File

@ -1,6 +1,7 @@
/* /*
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com> * Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
* Copyright (c) 2015 Intel Corporation. * Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015-2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -25,18 +26,20 @@
public class GUVAS12DSample { public class GUVAS12DSample {
// analog voltage, usually 3.3 or 5.0 // analog voltage, usually 3.3 or 5.0
private static final float GUVAS12D_AREF = 5; private static final float GUVAS12D_AREF = 5;
private static final int SAMPLES_PER_QUERY = 1024;
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
// ! [Interesting] // ! [Interesting]
// Instantiate a GUVAS12D on analog pin A3 // Instantiate a GUVAS12D on analog pin A0
upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(3); upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(0,
GUVAS12D_AREF);
while (true) { while (true)
float value = volts.value(GUVAS12D_AREF, SAMPLES_PER_QUERY); {
System.out.println("Volts: "
System.out.println("AREF: " + GUVAS12D_AREF + volts.volts()
+ ", Voltage value (higher means more UV): " + value); + ", Intensity: "
+ volts.intensity()
+ " mW/m^2");
Thread.sleep(1000); Thread.sleep(1000);
} }

View File

@ -0,0 +1,53 @@
/*
* Author: Noel Eck <noel.eck@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.
*/
import upm_ims.IMS;
public class IMS_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a IMS instance using bus 0 and default i2c address
IMS sensor = new IMS((short)0);
while (true)
{
System.out.println("Version: "
+ sensor.get_version()
+ " light: "
+ sensor.get_light()
+ " moisture: "
+ sensor.get_moisture()
+ " temp: "
+ sensor.get_temperature()
+ " C");
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,48 @@
/*
* 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_mb704x.MB704X;
public class MB704X_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a MB704X sensor using default parameters (bus 0,
// address 112)
MB704X sensor = new MB704X();
while (true)
{
System.out.println("Range: "
+ sensor.getRange()
+ " cm");
Thread.sleep(500);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,56 @@
/*
* 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_ms5803.MS5803;
public class MS5803_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a MS5803 instance using bus 0 and default i2c address
MS5803 sensor = new MS5803(0);
// For SPI, bus 0, you would pass -1 as the address, and a
// valid pin for CS:
// MS5803(0, -1, 10);
while (true)
{
// update our values from the sensor
sensor.update();
System.out.println("Temperature: "
+ sensor.getTemperature()
+ " C, Pressure: "
+ sensor.getPressure()
+ " mbar");
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -28,7 +28,7 @@ public class PPD42NSSample {
// ! [Interesting] // ! [Interesting]
// Instantiate a dust sensor on GPIO pin D8 // Instantiate a dust sensor on GPIO pin D8
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8); upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
upm_ppd42ns.dustData data; upm_ppd42ns.ppd42ns_dust_data data;
System.out.println("This program will give readings every 30 seconds until you stop it"); System.out.println("This program will give readings every 30 seconds until you stop it");

View File

@ -22,11 +22,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// Load Grove module // Load UPM module
var groveSensor = require('jsupm_grove'); var upm = require('jsupm_button');
// Create the button object using GPIO pin 0 // Create the button object using GPIO pin 0
var button = new groveSensor.Button(0); var button = new upm.Button(0);
// Read the input and print, waiting one second between readings // Read the input and print, waiting one second between readings
function readButtonValue() { function readButtonValue() {

View File

@ -0,0 +1,59 @@
/*
* 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_ecezo');
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
var sensor = new sensorObj.ECEZO(0, 9600, false);
// For I2C, assuming the device is configured for address 0x64 on
// I2C bus 0, you could use something like:
//
// var sensor = new sensorObj.ECEZO(0, 0x64, true);
setInterval(function()
{
// update our values from the sensor
sensor.update();
console.log("EC "
+ sensor.getEC()
+ " uS/cm, TDS "
+ sensor.getTDS()
+ " mg/L, Salinity "
+ sensor.getSalinity()
+ " PSS-78, SG "
+ sensor.getSG());
}, 5000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -1,6 +1,7 @@
/* /*
* Author: Zion Orent <zorent@ics.com> * Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation. * Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014-2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -24,27 +25,23 @@
var UVSensor = require('jsupm_guvas12d'); var UVSensor = require('jsupm_guvas12d');
// Instantiate a UV sensor on analog pin A0
var myUVSensor = new UVSensor.GUVAS12D(0);
// analog voltage, usually 3.3 or 5.0 // analog voltage, usually 3.3 or 5.0
var g_GUVAS12D_AREF = 5.0; var g_GUVAS12D_AREF = 5.0;
var g_SAMPLES_PER_QUERY = 1024;
// Instantiate a UV sensor on analog pin A0
var myUVSensor = new UVSensor.GUVAS12D(0, g_GUVAS12D_AREF);
setInterval(function() setInterval(function()
{ {
var outputStr = "AREF: " + g_GUVAS12D_AREF var outputStr = "Volts: "
+ ", Voltage value (higher means more UV): " + myUVSensor.volts()
+ roundNum(myUVSensor.value(g_GUVAS12D_AREF, g_SAMPLES_PER_QUERY), 6); + ", Intensity: "
+ myUVSensor.intensity()
+ " mW/m^2";
console.log(outputStr); console.log(outputStr);
}, 1000); }, 1000);
function roundNum(num, decimalPlaces)
{
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
return (Math.round((num + extraNum) * (Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
}
// Print message when exiting // Print message when exiting
process.on('SIGINT', function() process.on('SIGINT', function()
{ {

View File

@ -0,0 +1,51 @@
/*
* Author: Noel Eck <noel.eck@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 sensorObj = require('jsupm_ims');
// Instantiate a IMS instance using bus 0 and default i2c address
var sensor = new sensorObj.IMS(0);
setInterval(function()
{
console.log("Version: "
+ sensor.get_version()
+ " light: "
+ sensor.get_light()
+ " moisture: "
+ sensor.get_moisture()
+ " temp: "
+ sensor.get_temperature().toFixed(2)
+ " C");
}, 1000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -22,10 +22,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// Load Grove module // Load UPM module
var ledSensor = require('jsupm_led'); var ledSensor = require('jsupm_led');
// Create the Grove LED object using GPIO pin 2 // Create the LED object using GPIO pin 2
var led = new ledSensor.Led(2); var led = new ledSensor.Led(2);
// Print the name // Print the name

View File

@ -0,0 +1,47 @@
/*
* 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_mb704x');
// Instantiate a MB704X sensor using default parameters (bus 0,
// address 112)
var sensor = new sensorObj.MB704X();
setInterval(function()
{
console.log("Range: "
+ sensor.getRange()
+ " cm");
}, 500);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -1,31 +1,31 @@
/* /*
* Author: Zion Orent <zorent@ics.com> * Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation. * Copyright (c) 2014 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
//Load Grove Moisture module //Load UPM module
var moisture = require('jsupm_moisture'); var moisture = require('jsupm_moisture');
// Instantiate a Grove Moisture sensor on analog pin A0 // Instantiate a Moisture sensor on analog pin A0
var myMoistureObj = new moisture.Moisture(0); var myMoistureObj = new moisture.Moisture(0);
// Values (approximate): // Values (approximate):
@ -33,8 +33,7 @@ var myMoistureObj = new moisture.Moisture(0);
// 300-600, sensor in humid soil // 300-600, sensor in humid soil
// 600+, sensor in wet soil or submerged in water // 600+, sensor in wet soil or submerged in water
// Read the value every second and print the corresponding moisture level // Read the value every second and print the corresponding moisture level
setInterval(function() setInterval(function() {
{
var result; var result;
var moisture_val = parseInt(myMoistureObj.value()); var moisture_val = parseInt(myMoistureObj.value());
if (moisture_val >= 0 && moisture_val < 300) if (moisture_val >= 0 && moisture_val < 300)
@ -47,8 +46,7 @@ setInterval(function()
}, 1000); }, 1000);
// Print message when exiting // Print message when exiting
process.on('SIGINT', function() process.on('SIGINT', function() {
{
console.log("Exiting..."); console.log("Exiting...");
process.exit(0); process.exit(0);
}); });

View File

@ -0,0 +1,53 @@
/*
* 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_ms5803');
// Instantiate a MS5803 instance using bus 0 and default i2c address
var sensor = new sensorObj.MS5803(0);
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// MS5803(0, -1, 10);
setInterval(function()
{
// update our values from the sensor
sensor.update();
console.log("Temperature: "
+ sensor.getTemperature()
+ " C, Pressure: "
+ sensor.getPressure()
+ " mbar");
}, 1000);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -22,11 +22,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// Load Grove module // Load UPM module
var groveSensor = require('jsupm_grove'); var upm = require('jsupm_relay');
// Create the relay switch object using GPIO pin 0 // Create the relay switch object using GPIO pin 0
var relay = new groveSensor.Relay(0); var relay = new upm.Relay(0);
// Close and then open the relay switch 3 times, // Close and then open the relay switch 3 times,
// waiting one second each time. The LED on the relay switch // waiting one second each time. The LED on the relay switch
@ -34,16 +34,15 @@ var relay = new groveSensor.Relay(0);
// The switch will also make a noise between transitions. // The switch will also make a noise between transitions.
var i = 0; var i = 0;
var waiting = setInterval(function() { var waiting = setInterval(function() {
if ( i % 2 == 0 ) { if (i % 2 == 0) {
relay.on(); relay.on();
if ( relay.isOn() ) if (relay.isOn())
console.log(relay.name() + " is on"); console.log(relay.name() + " is on");
} else { } else {
relay.off(); relay.off();
if ( relay.isOff() ) if (relay.isOff())
console.log(relay.name() + " is off"); console.log(relay.name() + " is off");
} }
i++; i++;
if ( i == 6) clearInterval(waiting); if (i == 6) clearInterval(waiting);
}, 1000); }, 1000);

View File

@ -22,28 +22,27 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
//setup/Initialization //initialization
var upm_grove = require('jsupm_grove'); var upm = require('jsupm_rotary');
//setup access analog input Analog pin #0 (A0) //setup access analog input Analog pin #0 (A0)
var groveRotary = new upm_grove.Rotary(0); var rotary = new upm.Rotary(0);
loop(); loop();
function loop() function loop() {
{ var abs = rotary.abs_value();
var abs = groveRotary.abs_value(); var absdeg = rotary.abs_deg();
var absdeg = groveRotary.abs_deg(); var absrad = rotary.abs_rad();
var absrad = groveRotary.abs_rad();
var rel = groveRotary.rel_value(); var rel = rotary.rel_value();
var reldeg = groveRotary.rel_deg(); var reldeg = rotary.rel_deg();
var relrad = groveRotary.rel_rad(); var relrad = rotary.rel_rad();
//write the knob value to the console in different formats //write the knob value to the console in different formats
console.log("Abs: " + abs + " " + Math.round(parseInt(absdeg)) + " " + absrad.toFixed(3)); console.log("Abs: " + abs + " " + Math.round(parseInt(absdeg)) + " " + absrad.toFixed(3));
console.log("Rel: " + rel + " " + Math.round(parseInt(reldeg)) + " " + relrad.toFixed(3)); console.log("Rel: " + rel + " " + Math.round(parseInt(reldeg)) + " " + relrad.toFixed(3));
//wait 2 s and call function again //wait 2s and call function again
setTimeout(loop, 2000); setTimeout(loop, 2000);
} }

View File

@ -1,48 +1,46 @@
/* /*
* Author: Zion Orent <zorent@ics.com> * Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation. * Copyright (c) 2014 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var voltageDivider = require('jsupm_vdiv'); var voltageDivider = require('jsupm_vdiv');
// Instantiate a Grove Voltage Divider sensor on analog pin A0 // Instantiate a Voltage Divider sensor on analog pin A0
var myVoltageDivider = new voltageDivider.VDiv(0); var myVoltageDivider = new voltageDivider.VDiv(0);
// collect data and output measured voltage according to the setting // collect data and output measured voltage according to the setting
// of the scaling switch (3 or 10) // of the scaling switch (3 or 10)
var val, gain3val, gain10val; var val, gain3val, gain10val;
function getVoltageInfo()
{ function getVoltageInfo() {
val = myVoltageDivider.value(100); val = myVoltageDivider.value(100);
gain3val = myVoltageDivider.computedValue(3, val); gain3val = myVoltageDivider.computedValue(3, val);
gain10val = myVoltageDivider.computedValue(10, val); gain10val = myVoltageDivider.computedValue(10, val);
console.log("ADC value: " + val + " Gain 3: " + gain3val console.log("ADC value: " + val + " Gain 3: " + gain3val + "v Gain 10: " + gain10val + "v");
+ "v Gain 10: " + gain10val + "v");
} }
setInterval(getVoltageInfo, 1000); setInterval(getVoltageInfo, 1000);
// Print message when exiting // Print message when exiting
process.on('SIGINT', function() process.on('SIGINT', function() {
{
myVoltageDivider = null; myVoltageDivider = null;
voltageDivider.cleanUp(); voltageDivider.cleanUp();
voltageDivider = null; voltageDivider = null;

View File

@ -22,15 +22,14 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// Load Grove module // Load UPM module
var waterSensor = require('jsupm_water'); var waterSensor = require('jsupm_water');
// Instantiate a Water sensor on digital pin D2 // Instantiate a Water sensor on digital pin D2
var water = new waterSensor.Water(2); var water = new waterSensor.Water(2);
// Read whether the sensor is wet/dry, waiting one second between readings // Read whether the sensor is wet/dry, waiting one second between readings
function readWaterState() function readWaterState() {
{
if (water.isWet()) if (water.isWet())
console.log("Sensor is wet"); console.log("Sensor is wet");
else else
@ -39,8 +38,7 @@ function readWaterState()
setInterval(readWaterState, 1000); setInterval(readWaterState, 1000);
// Print message when exiting // Print message when exiting
process.on('SIGINT', function() process.on('SIGINT', function() {
{
console.log("Exiting..."); console.log("Exiting...");
process.exit(0); process.exit(0);
}); });

View File

@ -1,30 +1,30 @@
/* /*
* Author: Zion Orent <zorent@ics.com> * Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2015 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var waterFlow_lib = require('jsupm_wfs'); var waterFlow_lib = require('jsupm_wfs');
// Instantiate a Grove Water Flow Sensor on digital pin D2 // Instantiate a Water Flow Sensor on digital pin D2
var myWaterFlow_obj = new waterFlow_lib.WFS(2); var myWaterFlow_obj = new waterFlow_lib.WFS(2);
// set the flow counter to 0 and start counting // set the flow counter to 0 and start counting
@ -33,8 +33,7 @@ myWaterFlow_obj.startFlowCounter();
var millis, flowCount, fr; var millis, flowCount, fr;
var myInterval = setInterval(function() var myInterval = setInterval(function() {
{
// we grab these (millis and flowCount) just for display // we grab these (millis and flowCount) just for display
// purposes in this example // purposes in this example
millis = myWaterFlow_obj.getMillis(); millis = myWaterFlow_obj.getMillis();
@ -53,8 +52,7 @@ var myInterval = setInterval(function()
// When exiting: clear interval and print message // When exiting: clear interval and print message
process.on('SIGINT', function() process.on('SIGINT', function() {
{
clearInterval(myInterval); clearInterval(myInterval);
myWaterFlow_obj.stopFlowCounter(); myWaterFlow_obj.stopFlowCounter();
myWaterFlow_obj = null myWaterFlow_obj = null

66
examples/python/ecezo.py Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_ecezo as sensorObj
def main():
# Instantiate a ECEZO sensor on uart 0 at 9600 baud.
sensor = sensorObj.ECEZO(0, 9600, False);
# For I2C, assuming the device is configured for address 0x64 on
# I2C bus 0, you could use something like:
#
# sensor = sensorObj.ECEZO(0, 0x64, True);
## 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)
while (1):
sensor.update()
print("EC "
+ str(sensor.getEC())
+ " uS/cm, TDS "
+ str(sensor.getTDS())
+ " mg/L, Salinity "
+ str(sensor.getSalinity())
+ " PSS-78, SG "
+ str(sensor.getSG()));
time.sleep(5)
if __name__ == '__main__':
main()

View File

@ -1,6 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# Author: Zion Orent <zorent@ics.com> # Author: Zion Orent <zorent@ics.com>
# Copyright (c) 2015 Intel Corporation. # Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2015-2016 Intel Corporation.
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -26,12 +27,11 @@ import time, sys, signal, atexit
from upm import pyupm_guvas12d as upmUV from upm import pyupm_guvas12d as upmUV
def main(): def main():
# Instantiate a UV sensor on analog pin A0
myUVSensor = upmUV.GUVAS12D(0);
# analog voltage, usually 3.3 or 5.0 # analog voltage, usually 3.3 or 5.0
GUVAS12D_AREF = 5.0; GUVAS12D_AREF = 5.0;
SAMPLES_PER_QUERY = 1024;
# Instantiate a UV sensor on analog pin A0
myUVSensor = upmUV.GUVAS12D(0, GUVAS12D_AREF);
## Exit handlers ## ## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C # This function stops python from printing a stacktrace when you hit control-C
@ -48,10 +48,8 @@ def main():
signal.signal(signal.SIGINT, SIGINTHandler) signal.signal(signal.SIGINT, SIGINTHandler)
while(1): while(1):
s = ("AREF: {0}, " s = ("Volts: {0}, Intensity: {1} mW/m^2".format(myUVSensor.volts(),
"Voltage value (higher means more UV): " myUVSensor.intensity()))
"{1}".format(GUVAS12D_AREF,
myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY)))
print(s) print(s)
time.sleep(1) time.sleep(1)

44
examples/python/ims.py Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/python
# Author: Noel Eck <noel.eck@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.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_ims
def main():
# Create an instance of the I2C Moisture Sensor
# I2C bus 0, default address = 0x20
ims = pyupm_ims.IMS(0)
print ('I2C moisture sensor example...')
while (1):
try:
print ('Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C' \
% (ims.get_version(), ims.get_light(), ims.get_moisture(),
ims.get_temperature()))
time.sleep(1)
except KeyboardInterrupt:
break
if __name__ == '__main__':
main()

56
examples/python/mb704x.py Executable file
View File

@ -0,0 +1,56 @@
#!/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.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_mb704x as sensorObj
def main():
# Instantiate a MB704X sensor using default parameters (bus 0,
# address 112)
sensor = sensorObj.MB704X();
## 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)
while (1):
print("Range: "
+ str(sensor.getRange())
+ " cm")
time.sleep(.5)
if __name__ == '__main__':
main()

58
examples/python/ms5803.py Executable file
View File

@ -0,0 +1,58 @@
#!/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.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_ms5803 as sensorObj
def main():
# Instantiate a MS5803 instance using bus 0 and default i2c address
sensor = sensorObj.MS5803(0)
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
# MS5803(0, -1, 10);
## Exit handlers ##
# This function stops python from printing a stacktrace when you
# hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
while (1):
sensor.update()
print("Temperature:", sensor.getTemperature(), "C,", end=' ')
print("Pressure: ", sensor.getPressure(), "mbar")
time.sleep(1)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,42 @@
/*
* Authors: 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.
*/
#ifndef UPM_PRESSURE_H_
#define UPM_PRESSURE_H_
#ifdef __cplusplus
extern "C" {
#endif
// Pressure function table
typedef struct _upm_pressure_ft {
upm_result_t (*upm_pressure_set_scale) (void* dev, float scale);
upm_result_t (*upm_pressure_set_offset) (void* dev, float offset);
upm_result_t (*upm_pressure_get_value) (void* dev, float* value);
} upm_pressure_ft;
#ifdef __cplusplus
}
#endif
#endif /* UPM_PRESSURE_H_ */

View File

@ -124,6 +124,7 @@ typedef struct _upm_sensor_ft* (*func_get_upm_sensor_ft)(upm_sensor_t sensor_typ
#include <fti/upm_humidity.h> #include <fti/upm_humidity.h>
#include <fti/upm_binary.h> #include <fti/upm_binary.h>
#include <fti/upm_rotaryencoder.h> #include <fti/upm_rotaryencoder.h>
#include <fti/upm_pressure.h>
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,5 +1,6 @@
/* /*
* Authors: * Authors:
* Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
@ -24,11 +25,13 @@
#ifndef UPM_MATH_H_ #ifndef UPM_MATH_H_
#define UPM_MATH_H_ #define UPM_MATH_H_
#include <upm_platform.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef linux #if defined(UPM_PLATFORM_LINUX) || defined(UPM_PLATFORM_ZEPHYR)
#include <math.h> #include <math.h>
#endif #endif

46
include/upm_platform.h Normal file
View File

@ -0,0 +1,46 @@
/*
* Authors: 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.
*/
#ifndef UPM_PLATFORM_H_
#define UPM_PLATFORM_H_
#ifdef __cplusplus
extern "C" {
#endif
#if defined(linux)
# define UPM_PLATFORM_LINUX (1)
#elif defined(CONFIG_BOARD_ARDUINO_101) || \
defined(CONFIG_BOARD_ARDUINO_101_SSS) || \
defined(CONFIG_BOARD_QUARK_D2000_CRB)
# define UPM_PLATFORM_ZEPHYR (1)
#else
# error "UPM: Unknown Platform!"
#endif
#ifdef __cplusplus
}
#endif
#endif /* UPM_PLATFORM_H_ */

View File

@ -1,3 +1,10 @@
# Selectively disable certain CXX warnings for SWIG wrappers
# SWIG wrappers emit -Wdelete-non-virtual-dtor and -Wunused-function warnings
set (SWIG_CXX_DISABLE_WARNINGS -Wno-delete-non-virtual-dtor
-Wno-unused-function
-Wno-maybe-uninitialized
-Wno-strict-aliasing)
macro (file_to_list readfile outlist) macro (file_to_list readfile outlist)
FILE(READ "${readfile}" contents) FILE(READ "${readfile}" contents)
STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}") STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
@ -55,9 +62,6 @@ macro (upm_target_link_libraries target_name)
endforeach(_library ${ARGN}) endforeach(_library ${ARGN})
endmacro (upm_target_link_libraries target_name) endmacro (upm_target_link_libraries target_name)
# Selectively do not emit warnings from the SWIG-generated wrappers
set (disabled_flags -Wno-delete-non-virtual-dtor -Wno-unused-function)
# Create a single swig target for python # Create a single swig target for python
macro(_upm_swig_python) macro(_upm_swig_python)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
@ -89,13 +93,13 @@ macro(_upm_swig_python)
"${PYTHON_INCLUDE_DIRS}") "${PYTHON_INCLUDE_DIRS}")
# Turn off flags for wrapper # Turn off flags for wrapper
foreach(flag ${disabled_flags}) foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
compiler_flag_supported(CXX is_supported ${flag}) compiler_flag_supported(CXX is_supported ${flag})
if (is_supported) if (is_supported)
target_compile_options(${python_wrapper_target} target_compile_options(${python_wrapper_target}
PRIVATE "${flag}") PRIVATE "${flag}")
endif(is_supported) endif(is_supported)
endforeach(flag ${disabled_flags}) endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
# Add C++ comments to ALL python modules (requires doc build) # Add C++ comments to ALL python modules (requires doc build)
if (BUILDDOC) if (BUILDDOC)
@ -180,13 +184,13 @@ macro(upm_swig_node)
) )
# Turn off flags for wrapper # Turn off flags for wrapper
foreach(flag ${disabled_flags}) foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
compiler_flag_supported(CXX is_supported ${flag}) compiler_flag_supported(CXX is_supported ${flag})
if (is_supported) if (is_supported)
target_compile_options(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} target_compile_options(${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PRIVATE "${flag}") PRIVATE "${flag}")
endif(is_supported) endif(is_supported)
endforeach(flag ${disabled_flags}) endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
set_target_properties (jsupm_${libname} PROPERTIES set_target_properties (jsupm_${libname} PROPERTIES
COMPILE_FLAGS "-DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}" COMPILE_FLAGS "-DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
@ -217,9 +221,6 @@ endmacro(upm_swig_node)
macro(upm_swig_java) macro(upm_swig_java)
# Skip if the libname is in the blacklist # Skip if the libname is in the blacklist
if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};") if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
FIND_PACKAGE (JNI REQUIRED)
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
include_directories ( include_directories (
${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2} ${JAVA_INCLUDE_PATH2}
@ -242,13 +243,13 @@ macro(upm_swig_java)
) )
# Turn off flags for wrapper # Turn off flags for wrapper
foreach(flag ${disabled_flags}) foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
compiler_flag_supported(CXX is_supported ${flag}) compiler_flag_supported(CXX is_supported ${flag})
if (is_supported) if (is_supported)
target_compile_options(${SWIG_MODULE_javaupm_${libname}_REAL_NAME} target_compile_options(${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
PRIVATE "${flag}") PRIVATE "${flag}")
endif(is_supported) endif(is_supported)
endforeach(flag ${disabled_flags}) endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${LIB_INSTALL_DIR}) install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
# Java jar files always need to go under lib/java, regardless of # Java jar files always need to go under lib/java, regardless of
@ -545,12 +546,23 @@ elseif (BUILDSWIGPYTHON)
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub") file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub")
endif (BUILDDOC AND BUILDSWIGPYTHON) endif (BUILDDOC AND BUILDSWIGPYTHON)
# Add subdirectories from MODULE_LIST if defined
# Example -DMODULE_LIST="dfrph;rotaryencoder"
if (MODULE_LIST) if (MODULE_LIST)
set(SUBDIRS ${MODULE_LIST}) set(SUBDIRS ${MODULE_LIST})
set(SUBDIRS ${SUBDIRS} upm) set(SUBDIRS ${SUBDIRS} upm)
else() else()
# Otherwise, add all subdirectories
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
endif() endif()
# If the SUBDIRS list does NOT include the utilities directory, add it since
# most sensor library targets depend on utilities
if (NOT "${SUBDIRS}" MATCHES utilities)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/utilities)
endif()
# Iterate over each directory in SUBDIRS
foreach(subdir ${SUBDIRS}) foreach(subdir ${SUBDIRS})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
add_subdirectory(${subdir}) add_subdirectory(${subdir})

View File

@ -97,9 +97,9 @@ namespace upm {
int value(); int value();
private: private:
mraa::Aio m_aioOUT;
mraa::Gpio m_gpioLOPlus; mraa::Gpio m_gpioLOPlus;
mraa::Gpio m_gpioLOMinus; mraa::Gpio m_gpioLOMinus;
mraa::Aio m_aioOUT;
float m_aref; float m_aref;
int m_ares; int m_ares;

View File

@ -3,3 +3,7 @@ set (libdescription "Analog to digital converter")
set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx) set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx)
set (module_hpp ${libname}.hpp ads1115.hpp ads1015.hpp) set (module_hpp ${libname}.hpp ads1115.hpp ads1015.hpp)
upm_module_init() upm_module_init()
compiler_flag_supported(CXX is_supported -Wno-overloaded-virtual)
if (is_supported)
target_compile_options(${libname} PUBLIC -Wno-overloaded-virtual)
endif(is_supported)

View File

@ -149,7 +149,6 @@ ADS1015::setDelay(){
ADS1X15::ADSMUXMODE ADS1X15::ADSMUXMODE
ADS1015::getMuxMode(unsigned int input) { ADS1015::getMuxMode(unsigned int input) {
ADS1X15::ADSMUXMODE mode;
switch (input) { switch (input) {
case 0: case 0:
return SINGLE_0; return SINGLE_0;

View File

@ -66,7 +66,7 @@ float ADXRS610::calibrateZeroPoint(unsigned int samples)
// The gyro should be in a stable, non-moving state // The gyro should be in a stable, non-moving state
float sum = 0; float sum = 0;
for (int i=0; i<samples; i++) for (unsigned int i=0; i<samples; i++)
sum += getDataVolts(); sum += getDataVolts();
return sum / samples; return sum / samples;

View File

@ -199,7 +199,12 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
tdata[ilen+3] = crc; tdata[ilen+3] = crc;
tdata[ilen+4] = (crc >> 8); tdata[ilen+4] = (crc >> 8);
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr); if (mraa_i2c_address(m_i2ControlCtx, m_controlAddr) != MRAA_SUCCESS)
{
fprintf(stdout, "Error, setting i2c address.\n");
return -1;
}
int iLoops = 5; int iLoops = 5;
mraa_set_priority(HIGH_PRIORITY); mraa_set_priority(HIGH_PRIORITY);
do { do {

View File

@ -197,7 +197,6 @@ class AM2315 {
time_t m_last_time; time_t m_last_time;
int m_base_priority; int m_base_priority;
pthread_t this_thread;
}; };
} }

View File

@ -831,6 +831,8 @@ string BACNETUTIL::getAllErrorString()
return string("UPM Error: ") + getUPMErrorString(); return string("UPM Error: ") + getUPMErrorString();
break; break;
} }
return string("Internal Error: Unknown ErrorType");
} }
string BACNETUTIL::getDeviceDescription() string BACNETUTIL::getDeviceDescription()

View File

@ -210,7 +210,7 @@ unsigned Device_Count(
uint32_t Device_Index_To_Instance( uint32_t Device_Index_To_Instance(
unsigned index) unsigned index)
{ {
index = index; //index = index;
return Object_Instance_Number; return Object_Instance_Number;
} }

View File

@ -42,11 +42,6 @@ using namespace std;
// conversion from fahrenheit to celsius and back // conversion from fahrenheit to celsius and back
static float f2c(float f)
{
return ((f - 32.0) / (9.0 / 5.0));
}
static float c2f(float c) static float c2f(float c)
{ {
return (c * (9.0 / 5.0) + 32.0); return (c * (9.0 / 5.0) + 32.0);

View File

@ -196,7 +196,6 @@ class BMPX8X : public IPressureSensor, public ITemperatureSensor {
std::string m_name; std::string m_name;
int m_controlAddr; int m_controlAddr;
int m_bus;
mraa::I2c m_i2ControlCtx; mraa::I2c m_i2ControlCtx;
uint8_t oversampling; uint8_t oversampling;

View File

@ -1418,12 +1418,12 @@ namespace upm {
mraa::I2c *m_i2c; mraa::I2c *m_i2c;
mraa::Spi *m_spi; mraa::Spi *m_spi;
// spi chip select
mraa::Gpio *m_gpioCS;
mraa::Gpio *m_gpioIntr1; mraa::Gpio *m_gpioIntr1;
mraa::Gpio *m_gpioIntr2; mraa::Gpio *m_gpioIntr2;
// spi chip select
mraa::Gpio *m_gpioCS;
uint8_t m_addr; uint8_t m_addr;
RESOLUTION_T m_resolution; RESOLUTION_T m_resolution;

View File

@ -1185,12 +1185,12 @@ namespace upm {
mraa::I2c *m_i2c; mraa::I2c *m_i2c;
mraa::Spi *m_spi; mraa::Spi *m_spi;
// spi chip select
mraa::Gpio *m_gpioCS;
mraa::Gpio *m_gpioIntr1; mraa::Gpio *m_gpioIntr1;
mraa::Gpio *m_gpioIntr2; mraa::Gpio *m_gpioIntr2;
// spi chip select
mraa::Gpio *m_gpioCS;
uint8_t m_addr; uint8_t m_addr;
// SPI chip select // SPI chip select

View File

@ -552,12 +552,12 @@ namespace upm {
mraa::I2c *m_i2c; mraa::I2c *m_i2c;
mraa::Spi *m_spi; mraa::Spi *m_spi;
// spi chip select
mraa::Gpio *m_gpioCS;
mraa::Gpio *m_gpioIntr; mraa::Gpio *m_gpioIntr;
mraa::Gpio *m_gpioDR; mraa::Gpio *m_gpioDR;
// spi chip select
mraa::Gpio *m_gpioCS;
uint8_t m_addr; uint8_t m_addr;
OPERATION_MODE_T m_opmode; OPERATION_MODE_T m_opmode;
@ -594,8 +594,6 @@ namespace upm {
private: private:
bool m_isSPI; bool m_isSPI;
// use the FIFO by default?
bool m_useFIFO;
// return a reference to a gpio pin pointer depending on intr // return a reference to a gpio pin pointer depending on intr
mraa::Gpio*& getPin(INTERRUPT_PINS_T intr); mraa::Gpio*& getPin(INTERRUPT_PINS_T intr);

View File

@ -481,7 +481,7 @@ string BNO055::readCalibrationData()
void BNO055::writeCalibrationData(string calibData) void BNO055::writeCalibrationData(string calibData)
{ {
if (calibData.size() != calibrationDataNumBytes) if (static_cast<int>(calibData.size()) != calibrationDataNumBytes)
{ {
throw std::invalid_argument(std::string(__FUNCTION__) throw std::invalid_argument(std::string(__FUNCTION__)
+ ": calibData string must be exactly " + ": calibData string must be exactly "

View File

@ -1,5 +1,7 @@
upm_mixed_module_init (NAME button upm_mixed_module_init (NAME button
DESCRIPTION "Momentary on/off button" DESCRIPTION "Momentary on/off button"
C_HDR button.h
C_SRC button.c
CPP_HDR button.hpp CPP_HDR button.hpp
CPP_SRC button.cxx CPP_SRC button.cxx
REQUIRES mraa) REQUIRES mraa)

86
src/button/button.c Normal file
View File

@ -0,0 +1,86 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "button.h"
button_context button_init(int pin){
// make sure that mraa is initialized
int mraa_rv;
if((mraa_rv = mraa_init()) != MRAA_SUCCESS){
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
return NULL;
}
button_context dev = (button_context) malloc(sizeof(struct _button_context));
if (dev == NULL){
printf("Unable to allocate space for the sensor structure\n");
return NULL;
}
dev->gpio_pin = pin;
dev->gpio = mraa_gpio_init(dev->gpio_pin);
mraa_gpio_dir(dev->gpio, MRAA_GPIO_IN);
dev->isr_installed = false;
return dev;
}
void button_close(button_context dev){
mraa_gpio_close(dev->gpio);
free(dev);
}
upm_result_t button_get_value(button_context dev, bool* val){
int ret = mraa_gpio_read(dev->gpio);
if(ret > 0)
*val = true;
else
*val = false;
return UPM_SUCCESS;
}
upm_result_t button_install_isr(button_context dev, mraa_gpio_edge_t edge_level, void (*isr)(void *), void *arg){
button_uninstall_isr(dev);
mraa_gpio_isr(dev->gpio, edge_level, isr, arg);
dev->isr_installed = true;
return UPM_SUCCESS;
}
upm_result_t button_uninstall_isr(button_context dev){
if(dev->isr_installed)
mraa_gpio_isr_exit(dev->gpio);
dev->isr_installed = false;
return UPM_SUCCESS;
}

98
src/button/button.h Normal file
View File

@ -0,0 +1,98 @@
/*
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Sarah Knepper <sarah.knepper@intel.com>
* Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2014 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "upm.h"
#include "mraa/gpio.h"
/**
* @brief Button library
* @defgroup buttonlib libupm-button
* @ingroup seeed gpio button gsk
*/
/**
* @library buttonlib
* @sensor button
* @comname Button
* @altname Grove Button
* @type button
* @man seeed
* @con gpio
* @kit gsk
*
* @brief API for the Button
*
* Basic UPM module for the button sensor
*
* @image html button.jpg
* @snippet button.cxx Interesting
*/
typedef struct _button_context {
mraa_gpio_context gpio;
uint8_t gpio_pin;
bool isr_installed;
} *button_context;
/**
* button init function
*
* @param gpio Pin to use
*/
button_context button_init(int pin);
/**
* button destructor
*/
void button_close(button_context dev);
/**
* Gets the value from the GPIO pin
*
* @return Value from the GPIO pin
*/
upm_result_t button_get_value(button_context dev, bool* val);
/**
* Installs an interrupt service routine (ISR) to be called when
* the button is activated or deactivated.
*
* @param fptr Pointer to a function to be called on interrupt
* @param arg Pointer to an object to be supplied as an
* argument to the ISR.
*/
upm_result_t button_install_isr(button_context dev, mraa_gpio_edge_t edge_level, void (*isr)(void *), void *arg);
/**
* Uninstalls the previously installed ISR
*
*/
upm_result_t button_uninstall_isr(button_context);

View File

@ -156,13 +156,14 @@ namespace upm {
protected: protected:
// temperature and humidity are optional features of this transmitter
mraa::Aio *m_aioTemp;
mraa::Aio *m_aioHum;
// CO2 reporting is always supported // CO2 reporting is always supported
mraa::Aio m_aioCO2; mraa::Aio m_aioCO2;
// temperature and humidity are optional features of this transmitter
mraa::Aio *m_aioHum;
mraa::Aio *m_aioTemp;
private: private:
float m_aref; float m_aref;
float m_rResistor; float m_rResistor;

9
src/ecezo/CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
upm_mixed_module_init (NAME ecezo
DESCRIPTION "EC EZO Atlas Scientific EC circuit"
C_HDR ecezo.h ecezo_defs.h
C_SRC ecezo.c
CPP_HDR ecezo.hpp
CPP_SRC ecezo.cxx
FTI_SRC ecezo_fti.c
CPP_WRAPS_C
REQUIRES mraa)

674
src/ecezo/ecezo.c Normal file
View File

@ -0,0 +1,674 @@
/*
* 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 <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <upm_utilities.h>
#include "ecezo.h"
// "Typical" command completion delay in ms
#define CMD_DELAY (350)
// uncomment for dubugging
//#define ECEZO_DEBUG (1)
// I2C read helper
static int readBytes(const ecezo_context dev, uint8_t *buffer, int len)
{
assert(dev != NULL);
assert(dev->i2c != NULL);
bool done = false;
int rv;
int retries = 10;
while (!done && (retries-- > 0))
{
if ((rv = mraa_i2c_read(dev->i2c, buffer, len)) < 0)
{
printf("%s: mraa_i2c_read(code) failed.\n", __FUNCTION__);
return rv;
}
#if defined(ECEZO_DEBUG)
printf("CODE: %02x\n", buffer[0]);
#endif
if (buffer[0] == 0xff || buffer[0] == 0x02)
{
// no data available, or error
return -1;
}
else if (buffer[0] == 0x01)
{
// data is ready
done = true;
// now we need to move the data one byte down so the rest
// of this driver can work as-is.
memmove(buffer, (buffer + 1), len - 1);
}
else
{
// buffer[0] 0xfe - data is pending. wait and loop again.
upm_delay_ms(CMD_DELAY);
}
}
if (retries <= 0)
{
printf("%s: timed out waiting for correct response.\n", __FUNCTION__);
return -1;
}
#if defined(ECEZO_DEBUG)
printf("%s: Got %d bytes\n", __FUNCTION__, rv);
for (int i=0; i<rv; i++)
{
printf("%02x (%c) ", buffer[i],
isprint(buffer[i]) ? buffer[i] : '@');
}
printf("\n");
#endif // ECEZO_DEBUG
return rv;
}
static upm_result_t generic_init(const ecezo_context dev)
{
assert(dev != NULL);
// do some generic initialization
bool error = false;
// turn off response (*OK) codes (UART only)
if (dev->uart)
{
if (ecezo_send_command(dev, "Response,0", NULL, 0) < 0)
error = true;
}
// turn off continuous sampling
if (ecezo_set_continuous(dev, false))
error = true;
// make sure all parameters are enabled
if (ecezo_send_command(dev, "O,EC,1", NULL, 0) < 0)
error = true;
if (ecezo_send_command(dev, "O,TDS,1", NULL, 0) < 0)
error = true;
if (ecezo_send_command(dev, "O,S,1", NULL, 0) < 0)
error = true;
if (ecezo_send_command(dev, "O,SG,1", NULL, 0) < 0)
error = true;
if (error)
return UPM_ERROR_OPERATION_FAILED;
else
return UPM_SUCCESS;
}
static upm_result_t decode_report(const ecezo_context dev, char *data)
{
assert(dev != NULL);
char *startptr = data;
char *endptr = NULL;
float val;
// the format of the data string should be: ec,tds,s,sg
// ec
val = strtof(startptr, &endptr);
if (startptr == endptr)
{
// error
return UPM_ERROR_OPERATION_FAILED;
}
dev->ec = val;
startptr = endptr + 1;
// tds
val = strtof(startptr, &endptr);
// error
if (startptr == endptr)
return UPM_ERROR_OPERATION_FAILED;
dev->tds = val;
startptr = endptr + 1;
// salinity
val = strtof(startptr, &endptr);
// error
if (startptr == endptr)
return UPM_ERROR_OPERATION_FAILED;
dev->salinity = val;
startptr = endptr + 1;
// sg
val = strtof(startptr, &endptr);
if (startptr == endptr)
return UPM_ERROR_OPERATION_FAILED;
dev->sg = val;
return UPM_SUCCESS;
}
static bool ecezo_data_available(const ecezo_context dev, unsigned int millis)
{
assert(dev != NULL);
// i2c, we don't support this
if (dev->i2c)
{
return false;
}
// uart
if (mraa_uart_data_available(dev->uart, millis))
return true;
else
return false;
}
// uart init
ecezo_context ecezo_uart_init(unsigned int uart, unsigned int baudrate)
{
// make sure MRAA is initialized
int mraa_rv;
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
{
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
return NULL;
}
ecezo_context dev =
(ecezo_context)malloc(sizeof(struct _ecezo_context));
if (!dev)
return NULL;
// zero out context
memset((void *)dev, 0, sizeof(struct _ecezo_context));
// initialize the MRAA contexts
// uart, default should be 8N1
if (!(dev->uart = mraa_uart_init(uart)))
{
printf("%s: mraa_uart_init() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
if (mraa_uart_set_baudrate(dev->uart, baudrate))
{
printf("%s: mraa_uart_set_baudrate() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
mraa_uart_set_flowcontrol(dev->uart, false, false);
if (generic_init(dev))
{
printf("%s: generic_init() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
return dev;
}
// i2c ublox init
ecezo_context ecezo_i2c_init(unsigned int bus, uint8_t addr)
{
// make sure MRAA is initialized
int mraa_rv;
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
{
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
return NULL;
}
ecezo_context dev =
(ecezo_context)malloc(sizeof(struct _ecezo_context));
if (!dev)
return NULL;
// zero out context
memset((void *)dev, 0, sizeof(struct _ecezo_context));
// initialize the MRAA contexts
if (!(dev->i2c = mraa_i2c_init(bus)))
{
printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
if (mraa_i2c_address(dev->i2c, addr))
{
printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
if (generic_init(dev))
{
printf("%s: generic_init() failed.\n", __FUNCTION__);
ecezo_close(dev);
return NULL;
}
return dev;
}
void ecezo_close(ecezo_context dev)
{
assert(dev != NULL);
if (dev->uart)
mraa_uart_stop(dev->uart);
if (dev->i2c)
mraa_i2c_stop(dev->i2c);
free(dev);
}
upm_result_t ecezo_set_continuous(const ecezo_context dev, bool enable)
{
int rv;
if (enable)
rv = ecezo_send_command(dev, "C,1", NULL, 0);
else
rv = ecezo_send_command(dev, "C,0", NULL, 0);
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
}
upm_result_t ecezo_set_temperature(const ecezo_context dev, float temp)
{
char buffer[ECEZO_MAX_BUFFER_LEN];
snprintf(buffer, ECEZO_MAX_BUFFER_LEN, "T,%f", temp);
int rv = ecezo_send_command(dev, buffer, NULL, 0);
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
}
upm_result_t ecezo_set_led(const ecezo_context dev, bool enable)
{
int rv;
if (enable)
rv = ecezo_send_command(dev, "L,1", NULL, 0);
else
rv = ecezo_send_command(dev, "L,0", NULL, 0);
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
}
upm_result_t ecezo_set_k_value(const ecezo_context dev, float k)
{
char buffer[ECEZO_MAX_BUFFER_LEN];
// the K value must be between 0.1 and 10.0
if (k < 0.1 || k > 10.0)
{
printf("%s: K value must be between 0.1 and 10.0\n", __FUNCTION__);
return UPM_ERROR_OUT_OF_RANGE;
}
snprintf(buffer, ECEZO_MAX_BUFFER_LEN, "K,%f", k);
int rv = ecezo_send_command(dev, buffer, NULL, 0);
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
}
upm_result_t ecezo_set_sleep(const ecezo_context dev, bool enable)
{
int rv = 0;
if (enable)
rv = ecezo_send_command(dev, "SLEEP", NULL, 0);
else
{
// "WAKE" isn't a real command, but should wake the device up.
// We ignore the return value, as it will likely be an error
// anyway.
ecezo_send_command(dev, "WAKE", NULL, 0);
}
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
}
int ecezo_read(const ecezo_context dev, char *buffer, size_t len)
{
assert(dev != NULL);
upm_delay_ms(CMD_DELAY); // delay CMD_DELAY ms to make sure cmd completed
// i2c
if (dev->i2c)
{
return readBytes(dev, (uint8_t *)buffer, len);
}
else
{
// UART
int bytesRead = 0;
while(bytesRead < len)
{
// we read one byte at a time, exiting when either len is
// reached, or a '\r' is found indicating the end of a
// sentence. Most commands (except 'R') require a minimum
// of 300ms to execute, so we wait up to CMD_DELAY ms after all
// data (if any) is read.
if (ecezo_data_available(dev, CMD_DELAY))
{
int br = mraa_uart_read(dev->uart, &buffer[bytesRead], 1);
if (br <= 0)
return br;
if (buffer[bytesRead] == '\r')
{
// if we found a CR, replace it with a 0 byte
buffer[bytesRead++] = 0;
return bytesRead;
}
bytesRead++;
}
else
{
// timed out - ok with responses disabled
return 0;
}
}
}
// anything else is an error
return -1;
}
upm_result_t ecezo_write(const ecezo_context dev, char *buffer, size_t len)
{
assert(dev != NULL);
if (dev->uart)
{
if (mraa_uart_write(dev->uart, buffer, len) != len)
{
printf("%s: mraa_uart_write() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
}
else
{
// I2C
if (mraa_i2c_write(dev->i2c, (uint8_t *)buffer, len))
{
printf("%s: mraa_i2c_write() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
}
return UPM_SUCCESS;
}
int ecezo_send_command(const ecezo_context dev, char *cmd, char *buffer,
int len)
{
assert(dev != NULL);
if (!cmd)
return -1;
// Our local buffer in case one isn't supplied
char localBuffer[ECEZO_MAX_BUFFER_LEN];
// our read buffer ptr
char *readBuffer = NULL;
if (!buffer || !len)
{
readBuffer = localBuffer;
len = ECEZO_MAX_BUFFER_LEN;
}
else
{
readBuffer = buffer;
}
#if defined(ECEZO_DEBUG)
printf("Command: %s\n", cmd);
#endif // ECEZO_DEBUG
// our write buffer
char writeBuffer[ECEZO_MAX_BUFFER_LEN];
strncpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN);
writeBuffer[ECEZO_MAX_BUFFER_LEN - 1] = 0;
int writelen = strlen(writeBuffer);
if (dev->uart)
{
if (strlen(writeBuffer) >= ECEZO_MAX_BUFFER_LEN - 2)
{
// too big. Should never happen in real life.
printf("%s: cmd writeBuffer too big.\n", __FUNCTION__);
return -1;
}
strcat(writeBuffer, "\r");
}
// for the uart this will now include the added CR, for I2C, this
// will now include the already existing \0 terminator.
writelen++;
// Let the games begin...
int retries = 10;
while (retries-- > 0)
{
if (ecezo_write(dev, writeBuffer, writelen))
{
printf("%s: ecezo_write() failed\n", __FUNCTION__);
return -1;
}
// we wait up to CMD_DELAY ms for an error response, which should be
// more than enough time. No response is also ok, since we
// disable the "*OK" response in the init.
memset((void *)readBuffer, 0, len);
int bytesRead = 0;
if ((bytesRead = ecezo_read(dev, readBuffer, len)) < 0)
{
return -1;
}
// for I2C, we are done at this point
if (dev->i2c)
break;
// for UART, we need some more checks
if (bytesRead && strstr(readBuffer, "*ER"))
{
// need to retry the command
#if defined(ECEZO_DEBUG)
printf("%s: *ER DETECTED, retry\n", __FUNCTION__);
#endif // ECEZO_DEBUG
continue;
}
else if (bytesRead && strchr(readBuffer, '*'))
{
// Some other diagnostic code, output it.
#if defined(ECEZO_DEBUG)
printf("%s: * diagnostic code detected (%s), retry\n",
__FUNCTION__, buffer);
#endif // ECEZO_DEBUG
continue;
}
else
{
// we are done here
#if defined(ECEZO_DEBUG)
printf("%s: bytesRead = %d\n", __FUNCTION__, bytesRead);
#endif // ECEZO_DEBUG
break;
}
}
if (retries <= 0)
{
printf("%s: read timed out and/or and retries exhausted\n",
__FUNCTION__);
return 0;
}
return len;
}
upm_result_t ecezo_update(const ecezo_context dev)
{
assert(dev != NULL);
// first we send a 'R' command to get a reading (takes a minimum
// of 1 second), then we parse out the string values into the
// context variables.
char buffer[ECEZO_MAX_BUFFER_LEN];
// first issue the report command
int rv = ecezo_send_command(dev, "R", buffer, ECEZO_MAX_BUFFER_LEN);
if (rv == 0)
{
printf("%s: timed out waiting for data\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
else if (rv < 0)
{
printf("%s: error retrieving data\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
// decode
if (decode_report(dev, buffer))
{
printf("%s: decode_report() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
float ecezo_get_ec(const ecezo_context dev)
{
assert(dev != NULL);
return dev->ec;
}
float ecezo_get_tds(const ecezo_context dev)
{
assert(dev != NULL);
return dev->tds;
}
float ecezo_get_salinity(const ecezo_context dev)
{
assert(dev != NULL);
return dev->salinity;
}
float ecezo_get_sg(const ecezo_context dev)
{
assert(dev != NULL);
return dev->sg;
}
upm_result_t ecezo_calibrate(const ecezo_context dev, ECEZO_CALIBRATION_T cal,
float ec)
{
assert(dev != NULL);
char cmdBuffer[ECEZO_MAX_BUFFER_LEN];
switch(cal)
{
case ECEZO_CALIBRATE_CLEAR:
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,clear");
break;
case ECEZO_CALIBRATE_DRY:
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,dry");
break;
case ECEZO_CALIBRATE_ONE:
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,one,%f", ec);
break;
case ECEZO_CALIBRATE_LOW:
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,low,%f", ec);
break;
case ECEZO_CALIBRATE_HIGH:
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,high,%f", ec);
break;
default:
// should be able to happen
printf("%s: invalid cal parameter\n", __FUNCTION__);
return UPM_ERROR_INVALID_PARAMETER;
}
return ecezo_send_command(dev, cmdBuffer, NULL, 0);
}

146
src/ecezo/ecezo.cxx Normal file
View File

@ -0,0 +1,146 @@
/*
* 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 <stdexcept>
#include "ecezo.hpp"
using namespace upm;
using namespace std;
ECEZO::ECEZO(unsigned int bus, unsigned int addrBaud, bool isI2C) :
m_ecezo(nullptr)
{
if (isI2C)
m_ecezo = ecezo_i2c_init(bus, addrBaud);
else
m_ecezo = ecezo_uart_init(bus, addrBaud);
if (!m_ecezo)
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_*_init() failed");
}
ECEZO::~ECEZO()
{
ecezo_close(m_ecezo);
}
void ECEZO::update()
{
if (ecezo_update(m_ecezo))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_update() failed");
}
void ECEZO::setTemperature(float temp)
{
if (ecezo_set_temperature(m_ecezo, temp))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_set_temperature() failed");
}
void ECEZO::setKValue(float k)
{
if (ecezo_set_k_value(m_ecezo, k))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_set_k_value() failed");
}
void ECEZO::setSleep(bool enable)
{
if (ecezo_set_sleep(m_ecezo, enable))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_set_sleep() failed");
}
float ECEZO::getEC()
{
return ecezo_get_ec(m_ecezo);
}
float ECEZO::getTDS()
{
return ecezo_get_tds(m_ecezo);
}
float ECEZO::getSalinity()
{
return ecezo_get_salinity(m_ecezo);
}
float ECEZO::getSG()
{
return ecezo_get_sg(m_ecezo);
}
void ECEZO::calibrate(ECEZO_CALIBRATION_T cal, float ec)
{
if (ecezo_calibrate(m_ecezo, cal, ec))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_calibrate() failed");
}
void ECEZO::setContinuous(bool enable)
{
if (ecezo_set_continuous(m_ecezo, enable))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_set_continuous() failed");
}
string ECEZO::sendCommand(string cmd)
{
char buffer[ECEZO_MAX_BUFFER_LEN];
int rv;
if ((rv = ecezo_send_command(m_ecezo, (char *)cmd.c_str(),
buffer, ECEZO_MAX_BUFFER_LEN)) < 0)
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_send_command() failed");
return string(buffer, rv);
}
string ECEZO::read()
{
char buffer[ECEZO_MAX_BUFFER_LEN];
int rv;
if ((rv = ecezo_read(m_ecezo, buffer, ECEZO_MAX_BUFFER_LEN)) < 0)
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_read() failed");
return string(buffer, rv);
}
void ECEZO::write(std::string data)
{
if (ecezo_write(m_ecezo, (char*)data.data(),
data.size()))
throw std::runtime_error(string(__FUNCTION__)
+ ": ecezo_write() failed");
}

267
src/ecezo/ecezo.h Normal file
View File

@ -0,0 +1,267 @@
/*
* 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>
#include <upm.h>
#include <mraa/uart.h>
#include <mraa/i2c.h>
#include <mraa/gpio.h>
#include "ecezo_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file ecezo.h
* @library ecezo
* @brief C API for the EC-EZO EC Sensor
*
* @include ecezo.c
*/
/**
* Device context
*/
typedef struct _ecezo_context {
mraa_uart_context uart;
mraa_i2c_context i2c;
// our values
float ec; // electrical conductivity
float tds; // total dissolved solids
float salinity;
float sg; // specific gravity
} *ecezo_context;
/**
* ECEZO Initializer for UART operation
*
* @param uart Specify which uart to use.
* @param baudrate Specify the baudrate to use. The device defaults
* to 9600 baud, though the datasheet implies the default is 38400.
* @return an initialized device context on success, NULL on error.
*/
ecezo_context ecezo_uart_init(unsigned int uart, unsigned int baudrate);
/**
* ECEZO Initializer for I2C operation
*
* @param bus Specify which the I2C bus to use.
* @param addr Specify the I2C address to use. This is
* configurable on the device, so there is no default.
* @return an initialized device context on success, NULL on error.
*/
ecezo_context ecezo_i2c_init(unsigned int bus, uint8_t addr);
/**
* ECEZO sensor close function
*/
void ecezo_close(ecezo_context dev);
/**
* Query the device for a reading, parse the response, and store
* the read values into the device context. This function must be
* called prior to calling any function that returns the data,
* like ecezo_get_ec().
*
* @param dev Device context
* @return UPM result
*/
upm_result_t ecezo_update(const ecezo_context dev);
/**
* For accurate readings, the temperature of the liquid being
* measured should be known. This function allows you to specify
* the liquid's temperature (in Celsius) so that proper
* compensation can take place. How you measure this temperature
* is up to you. By default, the device will assume a temperature
* of 25C.
*
* @param dev Device context
* @param temp The temperature of the liquid being measured
* @return UPM result
*/
upm_result_t ecezo_set_temperature(const ecezo_context dev, float temp);
/**
* Set the K value of the probe being used. By default, this is
* 1.0. Valid values are between 0.1 and 10.0.
*
* @param dev Device context
* @param k The K value of the probe
* @return UPM result
*/
upm_result_t ecezo_set_k_value(const ecezo_context dev, float k);
/**
* Enable or disable Sleep mode.
*
* @param dev Device context
* @param enable True to enable sleep mode, false to wake up
* @return UPM result
*/
upm_result_t ecezo_set_sleep(const ecezo_context dev, bool enable);
/**
* Retrieve the last measured Electrical Conductivity (EC) value
* in microsiemens. ecezo_update() must have been called before
* calling this function.
*
* @param dev Device context
* @return EC value in microsiemens
*/
float ecezo_get_ec(const ecezo_context dev);
/**
* Retrieve the last measured Total Dissolved solids (TDS) value.
* ecezo_update() must have been called before calling this
* function.
*
* @param dev Device context
* @return TDS value
*/
float ecezo_get_tds(const ecezo_context dev);
/**
* Retrieve the last measured Salinity value. ecezo_update() must
* have been called before calling this function.
*
* @param dev Device context
* @return Salinity value
*/
float ecezo_get_salinity(const ecezo_context dev);
/**
* Retrieve the last measured Specific Gravity (SG) value.
* ecezo_update() must have been called before calling this
* function.
*
* @param dev Device context
* @return SG value
*/
float ecezo_get_sg(const ecezo_context dev);
/**
* Specify calibration data for calibrating the device. See the
* datasheet for details on how calibration is performed. This
* function provides a mechanism for clearing out, and setting
* calibration data.
*
* A simple one point calibration might work as follows:
*
* 1. CLEAR the calibration data
* 2. with a dry probe, set the DRY point.
* 3. with the probe immersed in a standardized solution, set the
* ONE parameter to the solution's known EC value in microsiemens.
*
* A two point calibration might work as follows:
*
* 1. CLEAR the calibration data
* 2. with a dry probe, set the DRY point.
* 3. with the probe immersed in the lowest EC standardized
* solution, set the LOW parameter to the solution's known EC
* value in microsiemens.
* 4. with the probe immersed in the highest EC standardized
* solution, set the HIGH parameter to the solution's known EC
* value in microsiemens.
*
* @param dev Device context
* @param cal One of the ECEZO_CALIBRATION_T values
* @param ec The EC value of the calibration fluid. This
* parameter is ignored when cal is either ECEZO_CALIBRATE_CLEAR
* or ECEZO_CALIBRATE_DRY.
* @return UPM result
*/
upm_result_t ecezo_calibrate(const ecezo_context dev,
ECEZO_CALIBRATION_T cal,
float ec);
/**
* Enable or disable "continuous" operation. In continuous
* operation, the device will sample and emit readings every
* second. The driver disables this mode by default. If you wish
* to use continuous mode, you will be responsible for reading and
* parsing the returned data yourself.
*
* The functionality of this driver depends on continuous mode
* being disabled. When disabled, the driver will manually
* request a reading when desired via ecezo_update().
*
* @param dev Device context
* @param enable true to enable continuous mode, false to disable.
* @return UPM result
*/
upm_result_t ecezo_set_continuous(const ecezo_context dev, bool enable);
/**
* Directly send a command to the device and optionally get a
* response. This is a low level function and should not be
* called unless you know what you are doing.
*
* @param dev Device context
* @param cmd command to send to the device. See the datasheet
* for valid commands.
* @param buffer Optional buffer in which to return any data.
* NULL if you are not interested in any returned data.
* @param len Length of the buffer, or 0 if you are not interested
* in returned data
* @return Number of characters read back, 0 if a timeout or no
* data, -1 if an error
*/
int ecezo_send_command(const ecezo_context dev, char *cmd,
char *buffer, int len);
/**
* Read character data from the device. This is a low level
* function and should not be called unless you know what you are
* doing.
*
* @param dev sensor context
* @param buffer The character buffer to read data into.
* @param len The maximum size of the buffer
* @return The number of bytes successfully read, or -1 on error
*/
int ecezo_read(const ecezo_context dev, char *buffer, size_t len);
/**
* Write character data to the device. This is a low level
* function and should not be called unless you know what you are
* doing.
*
* @param dev sensor context
* @param buffer The character buffer containing data to write.
* @param len The number of bytes to write.
* @return The number of bytes successfully written, or -1 on error.
*/
upm_result_t ecezo_write(const ecezo_context dev, char *buffer, size_t len);
#ifdef __cplusplus
}
#endif

238
src/ecezo/ecezo.hpp Normal file
View File

@ -0,0 +1,238 @@
/*
* 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 <stdlib.h>
#include <unistd.h>
#include "ecezo.h"
namespace upm {
/**
* @brief API for the EC-EZO EC Sensor
* @defgroup ecezo libupm-ecezo
* @ingroup uart i2c liquid
*/
/**
* @library ecezo
* @sensor ecezo
* @comname EC-EZO EC Sensor
* @type liquid
* @man sparkfun
* @con uart i2c
* @web https://www.sparkfun.com/products/12908
*
* @brief API for the EC-EZO EC Sensor
*
* This driver was tested with the Atlas Scientific Electrical
* Conductivity kit.
*
* This device can operate in either UART or I2C modes.
*
* @snippet ecezo.cxx Interesting
*/
class ECEZO {
public:
/**
* ECEZO object constructor. This can use either UART
* (default) or I2C communications. For UART, specify the
* uart number as the bus parameter, the baudrate as the
* addrBaud parameter, and false for the isI2C parameter.
*
* For I2C, specify the bus parameter, the I2C address as the
* addrBaud parameter, and true for the isI2C parameter.
*
* @param bus Specify which uart or I2C bus to use
* @param addrBaud Specify the baudrate if using UART, or the
* I2C address of the device if using I2C.
* @param isI2C true if using I2C, false if using a UART
*/
ECEZO(unsigned int bus=0, unsigned int addrBaud=9600,
bool isI2C=false);
/**
* ECEZO object destructor
*/
~ECEZO();
/**
* Query the device for a reading, parse the response, and store
* the read values into the device context. This function must be
* called prior to calling any function that returns the data,
* like getEC().
*/
void update();
/**
* For accurate readings, the temperature of the liquid being
* measured should be known. This function allows you to specify
* the liquid's temperature (in Celsius) so that proper
* compensation can take place. How you measure this temperature
* is up to you. By default, the device will assume a temperature
* of 25C.
*
* @param temp The temperature of the liquid being measured
* @return UPM result
*/
void setTemperature(float temp);
/**
* Set the K value of the probe being used. By default, this is
* 1.0. Valid values are between 0.1 and 10.0.
*
* @param k The K value of the probe
*/
void setKValue(float k);
/**
* Enable or disable Sleep mode.
*
* @param enable True to enable sleep mode, false to wake up
*/
void setSleep(bool enable);
/**
* Retrieve the last measured Electrical Conductivity (EC)
* value in microsiemens. update() must have been called
* before calling this function.
*
* @return EC value in microsiemens
*/
float getEC();
/**
* Retrieve the last measured Total Dissolved solids (TDS) value.
* update() must have been called before calling this
* function.
*
* @return TDS value
*/
float getTDS();
/**
* Retrieve the last measured Salinity value. update() must
* have been called before calling this function.
*
* @return Salinity value
*/
float getSalinity();
/**
* Retrieve the last measured Specific Gravity (SG) value.
* update() must have been called before calling this
* function.
*
* @return SG value
*/
float getSG();
/**
* Specify calibration data for calibrating the device. See the
* datasheet for details on how calibration is performed. This
* function provides a mechanism for clearing out, and setting
* calibration data.
*
* A simple one point calibration might work as follows:
*
* 1. CLEAR the calibration data
* 2. with a dry probe, set the DRY point.
* 3. with the probe immersed in a standardized solution, set the
* ONE parameter to the solution's known EC value in microsiemens.
*
* A two point calibration might work as follows:
*
* 1. CLEAR the calibration data
* 2. with a dry probe, set the DRY point.
* 3. with the probe immersed in the lowest EC standardized
* solution, set the LOW parameter to the solution's known EC
* value in microsiemens.
* 4. with the probe immersed in the highest EC standardized
* solution, set the HIGH parameter to the solution's known EC
* value in microsiemens.
*
* @param cal One of the ECEZO_CALIBRATION_T values
* @param ec The EC value of the calibration fluid. This
* parameter is ignored when cal is either ECEZO_CALIBRATE_CLEAR
* or ECEZO_CALIBRATE_DRY.
*/
void calibrate(ECEZO_CALIBRATION_T cal, float ec);
protected:
// ecezo device context
ecezo_context m_ecezo;
/**
* Enable or disable "continuous" operation. In continuous
* operation, the device will sample and emit readings every
* second. The driver disables this mode by default. If you wish
* to use continuous mode, you will be responsible for reading and
* parsing the returned data yourself.
*
* The functionality of this driver depends on continuous mode
* being disabled. When disabled, the driver will manually
* request a reading when desired via ecezo_update().
*
* @param enable true to enable continuous mode, false to disable.
*/
void setContinuous(bool enable);
/**
* Directly send a command to the device and optionally get a
* response. This is a low level function and should not be
* called unless you know what you are doing.
*
* @param cmd a String containing the command to send to the
* device. See the datasheet for valid commands.
* @return The string response, if any
*/
std::string sendCommand(std::string cmd);
/**
* Read character data from the device. This is a low level
* function and should not be called unless you know what you are
* doing.
*
* @return A string containing the data read back, if any
*/
std::string read();
/**
* Write character data to the device. This is a low level
* function and should not be called unless you know what you are
* doing.
*
* @param data The string containing data to write.
*/
void write(std::string data);
private:
};
}

45
src/ecezo/ecezo_defs.h Normal file
View File

@ -0,0 +1,45 @@
/*
* 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
#ifdef __cplusplus
extern "C" {
#endif
// our maximum buffer size
#define ECEZO_MAX_BUFFER_LEN (64)
// calibration commands
typedef enum {
ECEZO_CALIBRATE_CLEAR = 0, // clear calibration
ECEZO_CALIBRATE_DRY, // cal dry point
ECEZO_CALIBRATE_ONE, // single point cal EC value
ECEZO_CALIBRATE_LOW, // 2-point cal, LOW EC value
ECEZO_CALIBRATE_HIGH // 2-point cal, HIGH EC value
} ECEZO_CALIBRATION_T;
#ifdef __cplusplus
}
#endif

88
src/ecezo/ecezo_fti.c Normal file
View File

@ -0,0 +1,88 @@
/*
* 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 "ecezo.h"
#include "upm_fti.h"
/**
* This file implements the Function Table Interface (FTI) for this sensor
*/
const char upm_ecezo_name[] = "ECEZO";
const char upm_ecezo_description[] = "EC-EZO EC sensor";
const upm_protocol_t upm_ecezo_protocol[] = {UPM_UART, UPM_I2C};
const upm_sensor_t upm_ecezo_category[] = {UPM_EC};
// forward declarations
const void* upm_ecezo_get_ft(upm_sensor_t sensor_type);
void* upm_ecezo_init_name();
void upm_ecezo_close(void *dev);
upm_result_t upm_ecezo_get_value(const void *dev, float *value);
static const upm_sensor_ft ft =
{
.upm_sensor_init_name = &upm_ecezo_init_name,
.upm_sensor_close = &upm_ecezo_close,
};
static const upm_ec_ft ecft =
{
.upm_ec_get_value = upm_ecezo_get_value
};
const void* upm_ecezo_get_ft(upm_sensor_t sensor_type)
{
switch(sensor_type)
{
case UPM_SENSOR:
return &ft;
case UPM_EC:
return &ecft;
default:
return NULL;
}
}
void* upm_ecezo_init_name()
{
return NULL;
}
void upm_ecezo_close(void *dev)
{
ecezo_close((ecezo_context)dev);
}
upm_result_t upm_ecezo_get_value(const void *dev, float *value)
{
upm_result_t rv;
if ((rv = ecezo_update((ecezo_context)dev)))
return rv;
*value = ecezo_get_ec((ecezo_context)dev);
return UPM_SUCCESS;
}

22
src/ecezo/javaupm_ecezo.i Normal file
View File

@ -0,0 +1,22 @@
%module javaupm_ecezo
%include "../upm.i"
%include "std_string.i"
%include "stdint.i"
%include "typemaps.i"
%include "ecezo_defs.h"
%include "ecezo.hpp"
%{
#include "ecezo.hpp"
%}
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_ecezo");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

9
src/ecezo/jsupm_ecezo.i Normal file
View File

@ -0,0 +1,9 @@
%module jsupm_ecezo
%include "../upm.i"
%include "std_string.i"
%include "ecezo_defs.h"
%include "ecezo.hpp"
%{
#include "ecezo.hpp"
%}

13
src/ecezo/pyupm_ecezo.i Normal file
View File

@ -0,0 +1,13 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_ecezo
%include "../upm.i"
%include "std_string.i"
%feature("autodoc", "3");
%include "ecezo_defs.h"
%include "ecezo.hpp"
%{
#include "ecezo.hpp"
%}

View File

@ -32,7 +32,7 @@
using namespace upm; using namespace upm;
ECS1030::ECS1030 (uint8_t pinNumber) { ECS1030::ECS1030 (int pinNumber) {
m_dataPinCtx = mraa_aio_init(pinNumber); m_dataPinCtx = mraa_aio_init(pinNumber);
if (m_dataPinCtx == NULL) { if (m_dataPinCtx == NULL) {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
@ -53,7 +53,6 @@ ECS1030::~ECS1030 () {
double double
ECS1030::getCurrency_A () { ECS1030::getCurrency_A () {
int sensorValue = 0; int sensorValue = 0;
float rLoad = 0;
float volt = 0; float volt = 0;
float rms = 0; float rms = 0;

View File

@ -83,7 +83,7 @@ class ECS1030 {
* *
* @param pinNumber Number of the data pin * @param pinNumber Number of the data pin
*/ */
ECS1030 (uint8_t pinNumber); ECS1030 (int pinNumber);
/** /**
* ECS1030 object destructor; basically, it closes the GPIO. * ECS1030 object destructor; basically, it closes the GPIO.

View File

@ -59,10 +59,10 @@ unsigned int ENC03R::value()
void ENC03R::calibrate(unsigned int samples) void ENC03R::calibrate(unsigned int samples)
{ {
unsigned int val; int val;
float total = 0.0; float total = 0.0;
for (int i=0; i<samples; i++) for (unsigned int i=0; i<samples; i++)
{ {
val = mraa_aio_read(m_aio); val = mraa_aio_read(m_aio);
if (val == -1) throw std::out_of_range(std::string(__FUNCTION__) + if (val == -1) throw std::out_of_range(std::string(__FUNCTION__) +

View File

@ -92,7 +92,7 @@ Gas::getSample () {
void void
Gas::printGraph (thresholdContext* ctx, uint8_t resolution) { Gas::printGraph (thresholdContext* ctx, uint8_t resolution) {
std::cout << "(" << ctx->runningAverage << ") | "; std::cout << "(" << ctx->runningAverage << ") | ";
for (int i = 0; i < ctx->runningAverage / resolution; i++) for (unsigned int i = 0; i < ctx->runningAverage / resolution; i++)
std::cout << "*"; std::cout << "*";
std::cout << std::endl; std::cout << std::endl;
} }

View File

@ -28,7 +28,7 @@
struct thresholdContext { struct thresholdContext {
long averageReading; long averageReading;
long runningAverage; unsigned long runningAverage;
int averagedOver; int averagedOver;
}; };

View File

@ -29,8 +29,6 @@
using namespace upm; using namespace upm;
using namespace std; using namespace std;
static const int defaultDelay = 100; // max wait time for read
GPRS::GPRS(int uart) : GPRS::GPRS(int uart) :
m_uart(uart) m_uart(uart)
{ {

View File

@ -315,9 +315,14 @@ and is not meant to be installed anywhere.
@brief Honeywell @brief Honeywell
@defgroup maxim Maxim Integrated @defgroup sparkfun Sparkfun
@ingroup byman @ingroup byman
@brief Maxim Integrated @brief Sparkfun
@defgroup maxbotix MaxBotixs
@ingroup byman
@brief MaxBotixs
@defgroup meas Measurement Specialties @defgroup meas Measurement Specialties

View File

@ -29,8 +29,6 @@
using namespace upm; using namespace upm;
using namespace std; using namespace std;
static const int defaultDelay = 100; // max wait time for read
GroveGPRS::GroveGPRS(int uart) : GroveGPRS::GroveGPRS(int uart) :
m_uart(uart) m_uart(uart)
{ {

View File

@ -98,7 +98,6 @@ bool GROVESCAM::dataAvailable(unsigned int millis)
timeout.tv_usec = (millis % 1000) * 1000; timeout.tv_usec = (millis % 1000) * 1000;
} }
int nfds;
fd_set readfds; fd_set readfds;
FD_ZERO(&readfds); FD_ZERO(&readfds);

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