Compare commits

...

99 Commits

Author SHA1 Message Date
b9988469ba upm: v1.1.0
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-13 16:11:37 -08:00
4fff3a500d apichanges: list i2clcd library and individual display modules being split
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-13 16:09:44 -08:00
a53ab5cb80 docs: updated sections on porting and documentation authoring
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-09 16:50:00 -08:00
bd8104f6ee tests: exclude build dir and update expected number of duplicates
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-09 16:49:27 -08:00
dbac88d225 ads1x15: extend examples for both ads1015 and ads1115 and clarify which one is used where
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-09 15:11:59 -08:00
70bcdfefa4 lcm1602/jhd1313m1: temporarily rename headers to avoid duplicates
This should be reverted when these 2 classes are removed from the i2clcd library. Will also require updating all the examples to load the new modules instead.

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-09 15:06:12 -08:00
762c28f000 docs: Changed magnometer to magnetometer
Replaced all occurances.  While there are a few references
to magnometer out there, magnetometer is used much more broadly.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-08 13:56:28 -08:00
283fce619e doc: Scrubbed ALL sensor library descriptions
In an effort to clean-up and standardize UPM library
documentation, this commit updates (and in most cases,
unifies) the CMake description string AND CXX header
@comname string.

Strings were taken from datasheets when possible, spelling
mistakes were addressed, copy/paste errors where fixed,
Title Case was used, etc.

    * Tested/updated/added @web tags
    * Added/updated invalid sensor images
    * Added/updated @man tags, added missing manufacturers

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-08 11:50:00 -08:00
7a5c8a6cb3 swigjava: Added SWIGJAVA define to java module build
SWIGJAVA is defined for the swig interface file processing but is not
defined for the sensor library source build.  There are multiple sensors
that appear to rely solely on SWIGJAVA - these are not building
correctly.  Adding SWIGJAVA define for the java module src build.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-07 15:37:46 -08:00
4342b880b9 st7735: add typemaps to uint8_t arrays for js and python
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-06 21:28:04 -08:00
ddddbd024d tests: temporarily allow duplicate headers until cleanup
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-06 21:28:01 -08:00
67e0ceb48d tests: add test for duplicate headers
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-06 19:30:02 -08:00
2298846fef install.md: added install instructions for different OSes
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-02-06 19:02:35 -08:00
567476b89a cmake: Explicit dependency for mraa and interfaces
A handful of modules do not require mraa.  Captured this in
    src/CMakeLists.txt - only add mraa dependency for targets which
    use:

        upm_module_init(mraa ... )
            or
        upm_mixed_module_init(... REQUIRES mraa)

    All sensors which use UPM interfaces (src/interfaces) now
    explicitly add the interfaces target:

        upm_module_init(interfaces ... )
            or
        upm_mixed_module_init(... REQUIRES interfaces)

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-06 16:52:27 -08:00
d345006c03 cmake: Dependency refactoring for includes and libs
This commit attempts to use a more cmake-friendly approach when
handling inter-target dependencies.  A combination of macros and
include_directories usage provided overzealous compile -I/blah
entries which equates to large catch-all build commands.  For
example, the last CXX target contains include directories for nearly
all preceeding targets (~190).  Library dependencies were also often
wrong or missing.

    * Removed nearly all used of include_directories (swig cmake
      commands still appear to need these for generating the swig
      command line)
    * Updated usage of target_link_libraries in upm_module_init,
      also changed to using target_include_directories per target.
      This greatly simplifies upm/mixed_module_init usage for libraries
      which depend on other libraries (in this project).

        example (src/tb7300/CMakeLists.txt)
            old:
                 # upm-libbacnetmstp will bring in libbacnet, I hope
                 set (reqlibname "upm-bacnetmstp")
                 include_directories(${BACNET_INCLUDE_DIRS})
                 include_directories("../bacnetmstp")
                 upm_module_init()
                 upm_target_link_libraries(${libname} bacnetmstp)
            new:
                 upm_module_init(bacnetmstp)

      The reason here, is that tb7300 depends on bacnetmstp, which
      depends on BACNET includes/libs, so tb7300 gets the headers and
      libraries transitively via its dependency on bacnetmstp.
    * Updated pkg-config .pc file generation flow to reflect changes
      with dependencies.
    * Create a real target for the interfaces (CXX abstract sensor
      classes).  Renamed the directory from 'upm/src/upm' to
      'upm/src/interfaces'  Also changed the install location of the
      interface headers to include/upm/interfaces.  Updated interface
      header usage to reflect this.
    * Updated a few sensor libs to use fwd declarations for mraa.
      Ideally the UPM libs would do more of this which eases the
      burden on anyone building on top of the sensor libraries since
      they would not need to know about mraa headers.
    * Fixed examples which use symbols not defined in local includes

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-06 10:23:28 -08:00
7f0e03b0e3 cmake: Convert module_init to function
This is a housekeeping commit to move the upm_module_init
macro to a function.  The scope resolution of the function
call adds a bit more protection for the variables used inside
this macro/function.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-05 21:30:20 -08:00
08a46ee8e6 grovecollision,groveeldriver,groveelectromagnet,waterlevel: remove unnecessary librt dependency
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-02 14:36:51 -07:00
fb88fda5cb upm_utilities: Add a _POSIX_C_SOURCE define if needed
In certain systems, where -std=c11 is used, certain posix extensions
are disabled unless specifically enabled.  On these systems, this
could cause usleep() and/or nanosleep() to fail with an implicit
declaration warning.  This patch ensures that at least POSIX 200809 is
used, if otherwise undefined.

This should fix Issue #513.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-02 13:58:41 -07:00
90d856d128 utilities: use nanosleep() instead of usleep() for upm_delay*() functions
usleep() has been deprecated, and can cause compile problems on never
glibc versions (debian jesse).  We now use nanosleep() on linux
systems to implement delays.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-02 12:32:04 -07:00
d2e0327c30 src/CMakLists.txt: re-disable other warnings for SWIG building
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-02 12:31:57 -07:00
2e97aa9979 speaker: fix some incorrect comments/documentation
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-01 17:59:15 -07:00
cdb75e8c13 swig_java: Fix for #518 - java wrapper implementations
This commit fixes #518 by adding source back into the CXX swig-
generated wrapper.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-02-01 16:15:30 -08:00
dac31a0347 speaker: Add pwm functionality and 5 new examples to demonstrate
These changes add the ability to intialize a speaker instance to use a
PWM pin instead of a standard GPIO pin in order to emit sounds.

The current GPIO functionality is fairly constrained by the
implementation -- it only permits playing cerain hardcoded "notes".

The PWM support allows one to emit specific frequencies (currently
between 50-32Khz) using a PWM pin.  Of course, you may still be
constrained by the limits of your PWM hardware in the end.

There are a few new functions provided to support this PWM mode.  To
use the PWM mode of speaker, use the speaker_init_pwm() initialization
routine instead of speaker_init() (for C). For C++ and the SWIG
languages, pass "true" as the second argument to the constructor to
enable PWM mode.  The default is "false", to match current default
behavior (GPIO).

Functions that are not related to a given mode (GPIO vs. PWM) will do
nothing if not usable in that mode.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-02-01 17:08:05 -07:00
0749f130e1 nunchuck: C port; FTI; C++ wraps C
Some API changes were made as well, see docs/apichanges.md.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-31 13:08:20 -07:00
1bbb9386b7 enc03r: C port; FTI; C++ wraps C
The API for this driver has changed.  See docs/apichanges.md.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-30 12:06:32 -07:00
f914159e21 ims: Small logging change for C init method
Added a bit more description if the library cannot set I2C
standard mode.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-01-27 11:16:24 -08:00
849711c47d wfs: C port; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-26 15:13:01 -07:00
0a91eb0b46 hmc5883l: C port; FTI; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-25 17:42:38 -07:00
806b00c2b7 uartat: add missing uartat_defs.h to SWIG interface files
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-24 17:31:57 -07:00
e8151640a1 uartat, le910: initial implementation.
uartat is the underlying UART driver, specifically for use with
AT-style command driven devices like modems.

The le910 support is provided in the form of examples that make use
of the uartat driver to interact with the device.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-24 14:02:03 -07:00
123e611f45 cjq4435: C port, C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-20 12:02:30 -07:00
8d5278b9d4 CMakeLists.txt: Bump minimum MRAA version to 1.4.0
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-19 16:26:48 -07:00
ab96e8f3a3 speaker: C port, C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-19 13:54:47 -07:00
d3b864362d ds18b20: rewrite C++ to wrap C, add FTI, update examples
Previously, the C++ and C versions of this driver were separate.  Now
the C++ implementation wraps the C implementation.

In addition, the C++ init() function has been deprecated.  It
currently does nothing, and examples have been modified to remove it's
calls.  This function will be removed in a separate release.

The examples have been further modified to update all detected devices
and print their respective temperatures, instead of only reporting the
on the first device detected.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-18 13:33:44 -07:00
6769d976a0 max30100: ISR recover attempt
Handle failure in ISR routine - attempt to read status and
FIFO registers and continue sampleing (vs exiting and turning
off continuous sampling).

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-01-11 15:52:41 -08:00
bd47b9ed45 max30100: Initial commit - MAX30100 pulse oximeter
* c/c++ source
    * java/js/python/c/c++ examples
    * Doc image (png)
    * Tested on Intel Edison
    * TODO: Tuning for SpO2 reading

Signed-off-by: Noel Eck <noel.eck@intel.com>
2017-01-10 11:29:30 -08:00
6ea65a16a4 upm_platform: use __linux__ define to detect linux platforms
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-01-10 10:51:13 -07:00
0849fbc674 ads1x15: added elaborate examples for TI ADS1015 ADC
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2017-01-05 21:20:58 -08:00
e25be536a1 ims: Small typo fix
Changed ISM to IMS.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2016-12-20 23:25:26 -08:00
a70629e3b2 mcp2515: fix return from rx_status_filtermatch; Travis CI (clang)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-20 13:01:04 -07:00
fed0478dc9 mcp2515: fix conversion error reported by Travis CI (clang)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-20 12:47:43 -07:00
fcb4d9d36d mcp2515: Initial implementation; C; C++
The mcp2515 is a CAN bus controller.  It was developed using the Seeed
CAN bus shield.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-20 12:17:14 -07:00
5eb8af6d70 upm.i: treat upm_result_t like an int in SWIG
Signed-off-by: Jon Trulson <jtrulson@ics.com>
2016-12-20 12:17:09 -07:00
3c93eba4af LICENSE: Update license to be clearer and add 2016 copyright
MIT licenses should start with the following line to identify it as an MIT
license.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-12-15 17:50:59 -08:00
78953b110f npm: small improvement in logic for handling C sources
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-15 16:44:36 -08:00
53124e9704 npm: rename c sources to avoid node-gyp makefile target collision
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-12-13 17:14:21 -08:00
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
775 changed files with 26794 additions and 4189 deletions

View File

@ -15,7 +15,7 @@ compiler:
- clang
- gcc
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 install -y --force-yes -qq swig3.0 git
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
@ -36,7 +36,7 @@ script:
- sudo make install
- sudo ldconfig
# 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:
apt:
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 (BUILDSWIGNODE "Build swig node modules" ON)
option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (BUILDEXAMPLES "Build C/C++ example binaries" OFF)
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (NPM "Generate NPM/GYP tarballs" 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
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
@ -71,6 +70,7 @@ include (CheckCXXCompilerFlag)
# This function checks to see if each flag is supported
# by the compiler before setting the compile option.
function (upm_add_compile_flags compiler)
set (_TMP_COMPILER_FLAGS "")
# Iterate the flags, check if supported
foreach (flag ${ARGN})
# Check if this compile flag is supported
@ -85,15 +85,17 @@ function (upm_add_compile_flags compiler)
endforeach (flag ${ARGN})
# 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 ()
# 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)
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")
endif (WERROR)
@ -116,8 +118,10 @@ find_package (PkgConfig REQUIRED)
# Force a libmraa search and minimum required version every time a config is generated
unset(MRAA_FOUND CACHE)
set(MRAA_MINIMUM 1.1.1)
set(MRAA_MINIMUM 1.4.0)
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
# Also, get full path to the mraa library
find_library(MRAA_LIBRARY NAMES mraa PATHS ${MRAA_LIBDIR} NO_DEFAULT_PATH)
# Check for BACNET
pkg_check_modules (BACNET libbacnet)
@ -136,6 +140,15 @@ if (BUILDSWIGNODE)
find_package (Node REQUIRED)
endif (BUILDSWIGNODE)
# Find JAVA/JNI
if (BUILDSWIGJAVA)
find_package (Java REQUIRED)
find_package (JNI REQUIRED)
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
# Also, get full path to the mraajava library
find_library(MRAAJAVA_LIBRARY NAMES mraajava PATHS ${MRAA_LIBDIR} NO_DEFAULT_PATH)
endif (BUILDSWIGJAVA)
# Find swig if any wrapper is enabled
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
find_package (SWIG 3.0.5 REQUIRED)
@ -184,7 +197,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
# If git_describe fails, use a dirty version
if (${VERSION} MATCHES -NOTFOUND)
set (VERSION "v1.0.0-dirty")
set (VERSION "v1.1.0")
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
"${VERSION}). Check that git is installed and this is a valid git repo.")
endif ()
@ -378,7 +391,6 @@ endif()
if (RPM)
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "upm")
set(upm_PACKAGE_ON_TAG ".")
@ -415,7 +427,8 @@ if(BUILDEXAMPLES)
endif(BUILDCPP)
endif()
if(BUILDJAVAEXAMPLES)
# Build java examples
if(BUILDSWIGJAVA AND BUILDEXAMPLES)
add_subdirectory (examples/java)
endif()

View File

@ -1,4 +1,5 @@
Copyright © 2014-2015 Intel Corporation
The MIT License (MIT)
Copyright © 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

View File

@ -82,6 +82,10 @@ please refer to the Intel Developer Zone IDE page.
<a href="https://software.intel.com/iot/software/ide"><img src="docs/icons/allides.png"/></a>
### Installing UPM
Find notes on how to install UPM on various OS'es on this [page](docs/installing.md).
### Building UPM
See building documentation [here](docs/building.md).
@ -90,24 +94,34 @@ See building documentation [here](docs/building.md).
### Making your own UPM module
Porting [link](docs/porting.md) has more information on making new UPM modules.
A quick way to add a new sensor driver is to port existing code from another
platform (e.g. Arduino) and swap the IO calls to the MRAA API. This of course
assumes either ownership of the original code or licensing that allows
unrestricted redistribution.
There is also an example available gfor max31855 [sensor](docs/max31855.md).
The [porting](docs/porting.md) section has more information on this process,
and there is an example available based on the max31855 [sensor](docs/max31855.md).
Guide on creating Java [bindings](docs/creating_java_bindings.md).
Read more on creating Java [bindings](docs/creating_java_bindings.md) for your
new driver.
### Naming conventions and rules for new UPM contributions
### Guidelines and rules for new UPM contributions
Before you begin development, take a look at our naming [conventions](docs/naming.md).
The name you pick for a newly added sensor needs to be unique in the UPM library.
Also, please read the guidelines for contributions [to UPM](docs/contributions.md).
Don't forget to check the documentation [section](docs/documentation.md).
Then, please go over this short set of rules for new [contributions](docs/contributions.md).
Make sure you add yourself as an author on every new code file submitted.
If you are providing a fix with significant changes, feel free to add yourself
as a contributor. Signing-off your commits is mandatory.
Documenting your code is also a big part of the task. We have a strict set of
tags used to classify our sensors and their capabilities. You can find out more
about this in our [section](docs/documentation.md) on documenting a sensor API.
Finally, if you really want to ensure consistency with the rest of the library,
and the intel-iot-devkit repositories in general, take a look at our extensive
[author guide](docs/guidelines.md).
API Documentation
==============

View File

@ -4,6 +4,31 @@ API Changes {#apichanges}
Here's a list of other API changes made to the library that break source/binary
compatibility between releases:
* **i2clcd/jhd1313m1/lcm1602** LCD devices supported by the i2clcd module are
being separated into individual libraries. The APIs will be preserved, but
we recommend changing your code to use the new libraries as they become
available. Once this transition is complete, the i2clcd module will be
deprecated. So far, the following libraries have been made available
separately: jhd1313m1, lcm1602.
* **nunchuck** This driver no longer supports the init() function.
All initialization is now done in the C nunchuck_init() function,
or the C++ constructor. In addition, the *NUNCHUCK_I2C_ADDR*
define is no longer exposed, as it is not possible to use any other
I2C address than *0x52*. The readBytes() and writeByte() functions
are also no longer exposed, since aside from what the driver does
to initialize and read data, there are no other options available.
* **enc03r** This driver no longer supports the value() function. In
addition, an update() function has been added. This function must be
called prior to calling angularVelocity(). angularVelocity() no
longer accepts an argument. Additional functions have been added,
however they do not affect compatibility with previous versions.
* **ds18b20** The C++ interface init() function has been deprecated.
It is still present, but currently does nothing. It will be removed
in a future release.
* **grove<name>** Starting with UPM 1.0 the Grove libraries have been renamed
from *upm-grove<name>* to simply *upm-<name>*. Class names also match this new
format, with old classes marked as deprecated throughout the documentation.
@ -11,27 +36,35 @@ compatibility between releases:
groveelectromagnet, groveemg, grovegprs, grovegsr, grovelinefinder, grovemd,
grovemoisture, groveo2, grovescam, grovespeaker, groveultrasonic, grovevdiv,
grovewater, grovewfs.
* **grove** As of UPM 1.0 the Grove classes for sensors in the starter kit are
being separated into individual libraries. The old classes will be deprecated
over time and eventually removed. Corresponding libraries have the grove
prefix removed. Affected classes are GroveButton, GroveLed, GroveLight,
GroveRelay, GroveRotary, GroveSlide and GroveTemp.
* The **ublox6** driver has been replaced with a generic implementation called
nmea_gps as of UPM 1.0. This driver should handle all generic serial GPS
devices that output NMEA data going forward. This new driver has been tested
with ublox6, DFRobot VK2828U7 (ublox7) and ublox LEA-6H GPS devices.
* **grove** Binary compatibility was broken for the GroveTemp class as of UPM
v0.7.3. C++ code using this class has to be recompiled.
* There were frequent misspellings of the word *Celsius* in the UPM
code. In some cases, these were in method names, which will cause
some API compatibility issues. These have all been corrected for UPM
versions after v.0.7.2.
* Our **C++ header files** changed their extension from *.h* to *.hpp* in
version 0.7.0, Intel provided examples and code samples also reflect this
change but you will need to modify your `#include` directives in existing
code.
* **my9221**, **groveledbar** and **grovecircularled** are now all part of the
same library (my9221) and new functionality was added going to v.0.5.1.
* **stepmotor** driver API was changed significantly from v.0.4.1 to v.0.5.0.
* **eboled** library was greatly improved in version 0.4.0 and the `draw()`
function was removed in favor of a more complete GFX library implementation.

View File

@ -80,14 +80,10 @@ Building documentation
~~~~~~~~~~~~~
-DBUILDDOC=ON
~~~~~~~~~~~~~
Build C++ example binaries
Build C/C++/JAVA examples
~~~~~~~~~~~~~
-DBUILDEXAMPLES=ON
~~~~~~~~~~~~~
Build Java examples
~~~~~~~~~~~~~
-DBUILDJAVAEXAMPLES=ON
~~~~~~~~~~~~~
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

View File

@ -4,6 +4,33 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library
from earlier versions:
### v1.1.0
* Reworked cmake handling of internal and external dependencies
* Documentation improvements for sensor names, sensor descriptions, external
contributor guides and added new section on installing UPM on a supported OS
* Fixed issues with C11 builds on some WRLinux gateways and Debian systems
* New examples and functionality for speaker and ads1x15 modules
* Modified JAVA builds to ensure the SWIG generated wrappers include all
functionality and typemaps
* New sensors: mcp2515, max30100, uartat, le910
### 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
* Added approximately 50 C sources for UPM drivers that can be used on both

View File

@ -4,7 +4,7 @@ Writing sensor documentation {#documentation}
It is highly encouraged to provide at least some basic documentation for the
sensors that you want to add to UPM:
- If you don't add documentation, the code review will take very long and
- If you don't add documentation, the code review will take very long and
your contribution could be rejected.
- Try to have no warnings in doxygen, this is generally fairly easy.
- Have the specific sensor manufacturer/model & version that you used, if you
@ -15,7 +15,7 @@ sensors that you want to add to UPM:
####The sensor block
This is added just before the class declaration in your header(.h) file and has
This is added just before the class declaration in your header(.h) file and has
mandatory fields. For single sensor libraries, this block will actually
follow immediately after the library block. If you have multiple physical
sensors, add this to every one.
@ -36,7 +36,7 @@ Here's an example (disregard the "@verbatim" tags in your actual code):
* @kit <component-kit>
*
* @brief Short class/sensor description
*
*
* Then add a longer
* description here.
*
@ -52,8 +52,9 @@ Here's an example (disregard the "@verbatim" tags in your actual code):
- `<chip-id>` Usually the chip number used by the sensor. When this is not
available or relevant, use a unique descriptor that makes sense. Must match
class name. *Mandatory*
- `<component-name>` A short name for your sensor, try to avoid including the
manufacturer's name here. *Mandatory*
- `<component-name>` Title Case descriptive name for your sensor, try to avoid
including the manufacturer's name here. Examples: Digital Pressure Sensor,
Serial MP3 Module, etc... *Mandatory*
- `<alt-name>` Alternative names that your sensor driver might have. This may
include manufacturer's name. *Optional*
- `<alt-id>` Alternative chip-ids that your sensor driver supports. *Optional*

348
docs/guidelines.md Normal file
View File

@ -0,0 +1,348 @@
# Code Commenting And Documentation Authoring Guidelines
#### [Part I. Code Commenting](#code-commenting)
[Grammar](#grammar)
- [Active vs passive voice](#voice)
- [Capitalization](#capitalization)
- [No possessive case](#possessive-case)
- [Present tense](#present-tense)
- [Second person vs the user / reader / programmer / engineer](#second-person)
- [Third person vs infinitive](#third-person)
[Punctuation](#punctuation)
- [Comma in enumerations](#comma)
- [No period at the end of description](#period)
[Specific word usage](#word-usage)
- [Abbreviations and acronyms](#abbr-acr)
- [Adjectives containing numbers](#adj-num)
- [App vs application](#app)
- [Function vs method](#func-meth)
- [Onboard vs on-board](#onboard)
- [Sensor name vs sensor model](#name-model)
- [Setup vs set up](#setup)
- [Wi-Fi vs WiFi / Wifi / Wi-fi / wifi / wi-fi](#setup)
[Trademarks](#trademarks)
- [Intel products](#intel-prod)
- [Third-party technology](#third-party)
- [Trademark + noun](#tm-noun)
#### [Part II. Documentation Authoring](#doc-authoring)
[Grammar](#da-grammar)
- [Capitalization](#da-capitalization)
[Styling](#da-styling)
- [Bolding](#da-bolding)
- [Backticks](#da-backticks)
- [Links](#da-links)
- [Numbered list vs bullet points](#da-lists)
[Specific word usage](#da-word-usage)
- [Login vs log in](#da-login)
- [Click](#da-click)
- [SSH](#da-ssh)
# <a name="code-commenting"></a>Code Commenting Guidelines
## <a name="grammar"></a>Grammar
### <a name="voice"></a>Active vs passive voice
Where possible, prefer active voice over passive.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| It can be put into the configuration mode by grounding the CONFIG pin on the transceiver. | - You can put it into the configuration mode by grounding the CONFIG pin on the transceiver.<br>- To put it into the configuration mode, ground the CONFIG pin on the transceiver.<br>- Put it into the configuration mode by grounding the CONFIG pin on the transceiver. |
### <a name="capitalization"></a>Capitalization
- Capitalize the first word in the description of an entity.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| checks to see if there is data available for reading | Checks to see if there is data available for reading |
| @param len length of the buffer | @param len Length of the buffer |
- Be consistent with the capitalization of boolean values.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Returns True on success, false otherwise | - Returns true on success, false otherwise<br>- Returns True on success, False otherwise |
### <a name="possessive-case"></a>No possessive case
Do not use possessive case to avoid unnecessary personalization.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| method's output | - method output<br>- output of the method |
### <a name="present-tense"></a>Present tense
Use the present simple tense instead of future, past, or present perfect.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| When specified, this value will be used in computing the voltage. | When specified, this value is used in computing the voltage. |
| Once the data has been read… | Once the data is read… |
### <a name="second-person"></a>Second person vs the user / reader / programmer / engineer
Use second person when addressing the target reader of your comment.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| The user can easily override this method. | You can easily override this method. |
### <a name="third-person"></a>Third person vs infinitive
Use third-person verb forms in short descriptions of classes, methods, functions, etc., not infinitive.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Get the proximity value from the sensor | Gets the proximity value from the sensor |
## <a name="punctuation"></a>Punctuation
### <a name="comma"></a>Comma in enumerations
Add an extra comma before the last item in a list joined by **and** / **or**.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Returns raw values for the X, Y and Z axes. | Returns raw values for the X, Y, and Z axes. |
### <a name="period"></a>No period at the end of description
Do not put a period if the description of an entity is one sentence long.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Returns the name of the sensor. | Returns the name of the sensor |
| Sets the frequency modulation<br>Valid values are between 10 and 160 (in kHz) | Sets the frequency modulation. Valid values are between 10 and 160 (in kHz). |
| @param millis Maximum time in milliseconds to wait for the input<br>-1 means waiting forever (default) | @param millis Maximum time in milliseconds to wait for the input. -1 means waiting forever (default). |
<font color="purple">**Exception:**</font> if the description contains more than one sentence, put periods after each sentence.
## <a name="word-usage"></a>Specific word usage
### <a name="abbr-acr"></a>Abbreviations and acronyms
- Spell out the first occurrence or the first prominent use of an abbreviation or acronym, followed by a shortened form.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| @brief API for the GP2Y0A family of IR Proximity Sensors | @brief API for the GP2Y0A family of infrared (IR) Proximity Sensors |
- Do not use Latin abbreviations.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Works best with halved values; e.g., 1.0, 0.5, 0.25, etc. | Works best with halved values; for example, 1.0, 0.5, 0.25, and so on. |
- Know exactly what the abbreviation or acronym means to avoid unnecessary duplication.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| - LCD display<br>- ISR routine | - LCD / liquid-crystal display<br>- ISR / interrupt service routine |
### <a name="adj-num"></a>Adjectives containing numbers
Adjectives of the form **number + noun / participle** should be hyphenated. It does not matter if a number is represented by one or more digits or spelled out.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| - 4 wire stepper motor<br>- 3 axis gyroscope<br>- zero based indexing<br>- one byte register | - 4-wire stepper motor<br>- 3-axis gyroscope<br>- zero-based indexing<br>- one-byte register |
### <a name="app"></a>App vs application
Use **app** when referring to a program running on a device, and **application** when referring to a program running on a desktop / laptop computer.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| The wiki page for this device includes a link to an Android\* application that can be used to read the device via NFC. | The wiki page for this device includes a link to an Android\* app that can be used to read the device via NFC. |
### <a name="func-meth"></a>Function vs method
If a function is associated with a class, use **method** instead.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| class WheelEncoder {<br>...<br>/**<br>* Starts the counter. This function also clears<br>* the current count and resets the clock.<br>*/<br>void startCounter(); | class WheelEncoder {<br>...<br>/**<br>* Starts the counter. This method also clears<br>* the current count and resets the clock.<br>*/<br>void startCounter(); |
### <a name="onboard"></a>Onboard vs on-board
Use **onboard**.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| This ADC features an on-board reference and oscillator. | This ADC features an onboard reference and oscillator. |
### <a name="name-model"></a>Sensor name vs sensor model
Use a sensor name alone or a sensor model followed by a sensor name, not a sensor model alone.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| ADXL345 is compatible with… | - The ADXL345 3-axis digital accelerometer is compatible with…<br>- The accelerometer is compatible with… |
<font color="purple">**Exception:**</font> you can use a sensor model alone when introducing a
sensor for the first time:
ADXL345 is a 3-axis digital accelerometer…
### <a name="setup"></a>Setup vs set up
**Setup** is a noun, **set up** is a verb.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| It does not require any additional set up. | It does not require any additional setup. |
| For instructions on how to setup…, refer to... | For instructions on how to set up…, refer to... |
### <a name="wi-fi"></a>Wi-Fi vs WiFi / Wifi / Wi-fi / wifi / wi-fi
Use **Wi-Fi**.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| It was tested with the XBee\* S6B WiFi module. | It is tested with the XBee\* S6B Wi-Fi\* module. |
## <a name="trademarks"></a>Trademarks
### <a name="intel-prod"></a>Intel products
Use the correct official names of Intel products. When in doubt, check the TM names database.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| It is a 64x48 pixel OLED display that connects directly to an edison via its 80-pin connector. | It is a 64x48 pixel OLED display that connects directly to an Intel(R) Edison board via its 80-pin connector. |
**Note:** if an Intel product has a legally approved short name, you may use it in subsequent instances, after spelling it out the first time.
### <a name="third-party"></a>Third-party technology
Add an asterisk (\*) after a name to indicate a third-party trademark or registered intellectual property. If you are not sure whether an asterisk is necessary after a particular name, the rule of thumb is to put one, to be on the safe side.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| The Grove MQ2 Gas Sensor module is useful for gas leakage detection. | The Grove\* MQ2 Gas Sensor module is useful for gas leakage detection. |
### <a name="tm-noun"></a>Trademark + noun
Always follow trademarks by an appropriate noun. For a list of approved nouns for a particular trademark, check the TM names database.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| It is a 64x48 pixel OLED display that connects directly to an Intel(R) Edison via its 80-pin connector. | It is a 64x48 pixel OLED display that connects directly to an Intel(R) Edison board via its 80-pin connector. |
# <a name="doc-authoring"></a>Documentation Authoring Guidelines
## <a name="da-grammar"></a>Grammar
### <a name="da-capitalization"></a>Capitalization
For titles, use sentence capitalization.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Add a New Device | Add a new device |
## <a name="da-styling"></a>Styling
### <a name="da-bolding"></a>Bolding
For GUI elements and file names, use bolding instead of quotes.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| In the “Environment Variables” window, click “OK”. | In the **Environment Variables** window, click **OK**. |
| Copy the “example.zip” archive into the installation directory. | Copy the **example.zip** archive into the installation directory. |
### <a name="da-backticks"></a>Backticks
Enclose program commands, code blocks, and file paths in backticks (\`).
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| To create a new device, use the **create-thing** command. | To create a new device, use the \`create-thing\` (rendered as `create-thing`) command. |
| Go to **C:\Users\me\Documents\GitHub\intel-iot-examples-mqtt\support\aws**. | Go to \`C:\Users\me\Documents\GitHub\intel-iot-examples-mqtt\support\aws\` (rendered as `C:\Users\me\Documents\GitHub\intel-iot-examples-mqtt\support\aws`). |
### <a name="da-links"></a>Links
Do not use embedded links to third-party websites.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Create an account on [Microsoft Azure](https://azure.microsoft.com/en-us), if you do not yet have one. | Create an account on [https://azure.microsoft.com/en-us](https://azure.microsoft.com/en-us), if you do not yet have one. |
### <a name="da-lists"></a>Numbered list vs bullet points
- For a logical sequence of steps, use a numbered list.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| When running your C++ code on the Edison, you need to set the MQTT parameters in Eclipse. Go to "Run configurations", and change the "Commands to execute before application" to the following:<br><br>Click on the "Apply" button to save these settings.<br>Click on the "Run" button to run the code on the Edison. | When running your C++ code on the Intel® Edison board, you need to set the MQTT\* client parameters in Eclipse\*. To do that:<br>1. Go to **Run configurations** and, in the **Commands to execute before application** field, type the following:<br><br>2. Click the **Apply** button to save these settings.<br>3. Click the **Run** button to run the code on your board. |
- For a list of equally important options, use a bulleted list.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| From this exercise, developers will learn how to:<br>1. Connect the Intel® Edison board...<br>2. Run these code samples in the Intel® System Studio IoT Edition...<br>3. Set up a web application server... | From this exercise, developers will learn how to:<br>- Connect the Intel® Edison board…<br>- Run these code samples in the Intel® System Studio IoT Edition…<br>- Set up a web application server… |
## <a name="da-word-usage"></a>Specific word usage
### <a name="da-login"></a>Login vs log in
**Login** is a noun, **log in** is a verb.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Provide your log in and password. | Provide your login and password. |
| Login to your account. | Log in( )to your account. |
### <a name="da-click"></a>Click
Omit **on** after **click**.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| Click on **Advanced system settings**. | Click **Advanced system settings**. |
### <a name="da-ssh"></a>SSH
Do not use SSH as a verb. It is considered slang and is to be avoided.
| <font color="red">**Incorrect**</font> | <font color="green">**Correct**</font> |
| --- | --- |
| SSH into your Intel® Edison board. | Establish an SSH connection to your Intel® Edison board. |

BIN
docs/images/es9257.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
docs/images/ims.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
docs/images/max30100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
docs/images/rf22.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

77
docs/installing.md Normal file
View File

@ -0,0 +1,77 @@
Installing UPM {#installing}
============
UPM packages are provided for some of the major supported distributions, making
it very easy to install UPM and its dependencies without having to go through a
full build.
### Poky Linux
Yocto Project based Poky Linux builds are provided for Intel Galileo, Intel
Edison and Minnowboard. These are the official images released with the Intel
IoT Developer Kit and can found [here](https://iotdk.intel.com/images/3.5/).
To update to the latest stable UPM version:
```bash
echo "src intel-iotdk https://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586/" > /etc/opkg/intel-iotdk.conf
opkg update
opkg upgrade mraa upm
```
If you would like to try the development version use `intelgalactic-dev`
instead.
### WindRiver Pulsar Linux
WR Pulsar uses SmartPM for software updates. Updating to the latest UPM version
requires:
```bash
smart channel -y --add upm_mraa_channel type=rpm-md name="MRAA/UPM" baseurl=http://iotdk.intel.com/repos/pulsar/8/x64
smart update
smart install -y mraa upm
```
For Pulsar 7 use the following baseurl instead: `baseurl=http://iotdk.intel.com/repos/pulsar/7/x64`
Wind River Linux 7 uses 01.org repositories and will have a default update
channel that includes MRAA & UPM. Thus you only have to update and install.
### Ubuntu Desktop/Server
MRAA and UPM are available through a Personal Package Archive (PPA) on Ubuntu
that can be found [here](https://launchpad.net/~mraa/+archive/ubuntu/mraa).
To install:
```bash
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libupm-dev python-upm python3-upm upm-examples
```
Note that the Ubuntu PPA only provides the C/C++ and Python packages. Node.js
developers will have to install MRAA and UPM using NPM instead.
### Node.js bindings only (NPM)
This option allows compiling MRAA/UPM on any system with npm and node-gyp.
The UPM modules have a hard dependency on MRAA, thus you will have to install
it first. Also, make sure Node can find MRAA by updating the `NODE_PATH`
variable if necessary. A global installation is preferred:
`npm install mraa -g`
After this, to install a UPM module using npm simply type:
`npm install jsupm_<module-name> -g`
In order to initialize the platform, require MRAA *before* you load a UPM
module in your code:
```js
require('mraa');
var lib = require('jsupm_<module-name>');
```

View File

@ -24,6 +24,7 @@ hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
hm11.cxx HM11Sample.java hm11.js hm11.py
hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.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
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.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
macro(get_module_name example_name module_name)
string(LENGTH ${example_name} length)
@ -32,6 +36,15 @@ macro(add_custom_example example_bin example_src example_module_list)
if (found_all_modules)
add_executable (${example_bin} ${example_src})
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})
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
include_directories (${module_dir})
@ -55,11 +68,6 @@ macro(add_example example_name)
get_module_name(${example_name} 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}"
AND EXISTS ${module_dir}
AND IS_DIRECTORY ${module_dir})
@ -313,45 +321,58 @@ add_example (hka5)
add_example (dfrorp)
add_example (dfrec)
add_example (sht1x)
add_example (ms5803)
add_example (ims)
add_example (ecezo)
add_example (mb704x)
add_example (rf22-server)
add_example (rf22-client)
add_example (mcp2515)
add_example (max30100)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
add_custom_example (groveled-multi-example groveled-multi.cxx grove)
add_custom_example (lcm1602-i2c-example lcm1602-i2c.cxx lcd)
add_custom_example (lcm1602-parallel-example lcm1602-parallel.cxx lcd)
add_custom_example (jhd1313m1-lcd-example jhd1313m1-lcd.cxx lcd)
add_custom_example (es08a-example es08a.cxx servo)
add_custom_example (ssd1306-oled-example ssd1306-oled.cxx lcd)
add_custom_example (ssd1308-oled-example ssd1308-oled.cxx lcd)
add_custom_example (ssd1327-oled-example ssd1327-oled.cxx lcd)
add_custom_example (sainsmartks-example sainsmartks.cxx lcd)
add_custom_example (eboled-example eboled.cxx lcd)
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example ak8975.cxx mpu9150)
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example groveledbar.cxx my9221)
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bmp280")
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bmp280")
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bmp280")
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
add_custom_example (bme280-example bme280.cxx bmp280)
add_custom_example (bma250e-example bma250e.cxx bmx055)
add_custom_example (bmg160-example bmg160.cxx bmx055)
add_custom_example (bmm150-example bmm150.cxx bmx055)
add_custom_example (bmc150-example bmc150.cxx bmx055)
add_custom_example (bmi055-example bmi055.cxx bmx055)
add_custom_example (groveled-multi-example-cxx groveled-multi.cxx grove)
add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcd)
add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcd)
add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx lcd)
add_custom_example (es08a-example-cxx es08a.cxx servo)
add_custom_example (ssd1306-oled-example-cxx ssd1306-oled.cxx lcd)
add_custom_example (ssd1308-oled-example-cxx ssd1308-oled.cxx lcd)
add_custom_example (ssd1327-oled-example-cxx ssd1327-oled.cxx lcd)
add_custom_example (sainsmartks-example-cxx sainsmartks.cxx lcd)
add_custom_example (eboled-example-cxx eboled.cxx lcd)
add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)
add_custom_example (mpu9250-example-cxx mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example-cxx groveledbar.cxx my9221)
add_custom_example (grovecircularled-example-cxx grovecircularled.cxx my9221)
add_custom_example (temperature-sensor-example-cxx temperature-sensor.cxx "si7005;bmpx8x;bmp280")
add_custom_example (humidity-sensor-example-cxx humidity-sensor.cxx "si7005;bmp280")
add_custom_example (pressure-sensor-example-cxx pressure-sensor.cxx "bmpx8x;bmp280")
add_custom_example (co2-sensor-example-cxx co2-sensor.cxx "t6713")
add_custom_example (adc-example-cxx adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example-cxx light-sensor.cxx "si1132;max44009")
add_custom_example (light-controller-example-cxx light-controller.cxx "lp8860;ds1808lc;hlg150h")
add_custom_example (bme280-example-cxx bme280.cxx bmp280)
add_custom_example (bma250e-example-cxx bma250e.cxx bmx055)
add_custom_example (bmg160-example-cxx bmg160.cxx bmx055)
add_custom_example (bmm150-example-cxx bmm150.cxx bmx055)
add_custom_example (bmc150-example-cxx bmc150.cxx bmx055)
add_custom_example (bmi055-example-cxx bmi055.cxx bmx055)
if (OPENZWAVE_FOUND)
include_directories(${OPENZWAVE_INCLUDE_DIRS})
add_custom_example (ozwdump-example ozwdump.cxx ozw)
add_custom_example (aeotecss6-example aeotecss6.cxx ozw)
add_custom_example (aeotecsdg2-example aeotecsdg2.cxx ozw)
add_custom_example (aeotecdw2e-example aeotecdw2e.cxx ozw)
add_custom_example (aeotecdsb09104-example aeotecdsb09104.cxx ozw)
add_custom_example (tzemt400-example tzemt400.cxx ozw)
add_custom_example (ozwdump-example-cxx ozwdump.cxx ozw)
add_custom_example (aeotecss6-example-cxx aeotecss6.cxx ozw)
add_custom_example (aeotecsdg2-example-cxx aeotecsdg2.cxx ozw)
add_custom_example (aeotecdw2e-example-cxx aeotecdw2e.cxx ozw)
add_custom_example (aeotecdsb09104-example-cxx aeotecdsb09104.cxx ozw)
add_custom_example (tzemt400-example-cxx tzemt400.cxx ozw)
endif()
add_custom_example (nmea_gps_i2c_example-cxx nmea_gps_i2c.cxx nmea_gps)
add_custom_example (mcp2515-txrx-example-cxx mcp2515-txrx.cxx mcp2515)
add_custom_example (ads1015-example-cxx ads1015.cxx ads1x15)
add_custom_example (le910-example-cxx le910.cxx uartat)
add_custom_example (speaker_pwm-example-cxx speaker_pwm.cxx speaker)
add_custom_example (ads1115-example-cxx ads1015.cxx ads1x15)

102
examples/c++/ads1015.cxx Normal file
View File

@ -0,0 +1,102 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one the ADS1015 ADC on the Grove Joule
* Shield or the Sparkfun ADC Block for Edison with devices that output a small
* differential voltage (e.g. geophones, piezoelectric bands or pads,
* thermocouples).
*/
#include <fstream>
#include <string>
#include <thread>
#include <unistd.h>
#include "ads1015.hpp"
using namespace std;
using namespace upm;
bool running = true; // Controls main read/write loop
// Thread function
void stop()
{
sleep(10);
running = false;
}
int main()
{
long id = 0; // Sample number
string fileName = "./ads1015.data"; // Output filename
ofstream f;
// Initialize and configure the ADS1015
ADS1015 *ads1015 = new upm::ADS1015(0, 0x48);
// Put the ADC into differential mode for pins A0 and A1
ads1015->getSample(ADS1X15::DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1015->setGain(ADS1X15::GAIN_TWO);
// Set the sample rate to 3300 samples per second (max) and turn on continuous
// sampling
ads1015->setSPS(ADS1015::SPS_3300);
ads1015->setContinuous(true);
// Enable exceptions from the output stream
f.exceptions(ofstream::failbit | ofstream::badbit);
// Open the file
try{
f.open(fileName);
// Output formatting
f.setf(ios_base::fixed);
f.precision(7);
// Start the thread that will stop logging after 10 seconds
thread timer (stop);
// Read sensor data and write it to the output file every ms
while(running){
f << id++ << " " << ads1015->getLastSample() << endl;
usleep(1000);
}
// Clean-up and exit
timer.join();
f.close();
delete ads1015;
} catch (ios_base::failure &e) {
cout << "Failed to write to file: " << e.what() << endl;
return 1;
}
cout << "Wrote " << id << " samples to file: " << fileName << endl;
return 0;
}

105
examples/c++/ads1115.cxx Normal file
View File

@ -0,0 +1,105 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one of the ADS1115 ADCs on the
* DFRobot Joule Shield with devices that output a small differential
* voltage (e.g. geophones, piezoelectric bands or pads, thermocouples).
*/
#include <fstream>
#include <string>
#include <thread>
#include <unistd.h>
#include "ads1115.hpp"
using namespace std;
using namespace upm;
bool running = true; // Controls main read/write loop
// Thread function
void stop()
{
sleep(10);
running = false;
}
int main()
{
long id = 0; // Sample number
string fileName = "./ads1115.data"; // Output filename
ofstream f;
// Initialize and configure the ADS1115 for the SM-24 Geophone
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
// - 0x48 gives access to pins A0 - A3
// - 0x49 gives access to pins A4 - A7
ADS1115 *ads1115 = new upm::ADS1115(0, 0x48);
// Put the ADC into differential mode for pins A0 and A1,
// the SM-24 Geophone is connected to these pins
ads1115->getSample(ADS1X15::DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1115->setGain(ADS1X15::GAIN_TWO);
// Set the sample rate to 860 samples per second (max) and turn on continuous
// sampling
ads1115->setSPS(ADS1115::SPS_860);
ads1115->setContinuous(true);
// Enable exceptions from the output stream
f.exceptions(ofstream::failbit | ofstream::badbit);
// Open the file
try{
f.open(fileName);
// Output formatting
f.setf(ios_base::fixed);
f.precision(7);
// Start the thread that will stop logging after 10 seconds
thread timer (stop);
// Read sensor data and write it to the output file every ms
while(running){
f << id++ << " " << ads1115->getLastSample() << endl;
usleep(1000);
}
// Clean-up and exit
timer.join();
f.close();
delete ads1115;
} catch (ios_base::failure &e) {
cout << "Failed to write to file: " << e.what() << endl;
return 1;
}
cout << "Wrote " << id << " samples to file: " << fileName << endl;
return 0;
}

View File

@ -316,5 +316,5 @@ int main()
delete ads;
return MRAA_SUCCESS;
return 0;
}

View File

@ -33,45 +33,45 @@ int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
upm::CJQ4435* mosfet = new upm::CJQ4435(3);
mosfet->setPeriodMS(10);
mosfet->enable(true);
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
upm::CJQ4435* mosfet = new upm::CJQ4435(3);
while (shouldRun)
mosfet->setPeriodMS(10);
mosfet->enable(true);
while (shouldRun)
{
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
for (float i=0.0; i <= 1.0; i+=0.1)
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
for (float i=0.0; i <= 1.0; i+=0.1)
{
mosfet->setDutyCycle(i);
usleep(100000);
mosfet->setDutyCycle(i);
usleep(100000);
}
sleep(1);
// Now take it back down
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
for (float i=1.0; i >= 0.0; i-=0.1)
sleep(1);
// Now take it back down
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
for (float i=1.0; i >= 0.0; i-=0.1)
{
mosfet->setDutyCycle(i);
usleep(100000);
mosfet->setDutyCycle(i);
usleep(100000);
}
sleep(1);
sleep(1);
}
//! [Interesting]
cout << "Exiting..." << endl;
cout << "Exiting..." << endl;
delete mosfet;
return 0;
delete mosfet;
return 0;
}

View File

@ -20,13 +20,13 @@ void printState(upm::ILightController *lightController)
}
}
int main( int argc, char **argv )
{
int status = 0;
upm::ILightController* lightController;
try {
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
int main( int argc, char **argv )
{
int status = 0;
upm::ILightController* lightController = nullptr;
try {
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
std::cout << "Existing state: "; printState(lightController);
if (argc == 2)
{

View File

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2016-2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -49,9 +49,6 @@ int main(int argc, char **argv)
// Instantiate an DS18B20 instance using the default values (uart 0)
upm::DS18B20 sensor;
// locate and setup our devices
sensor.init();
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
cout << endl;
@ -59,18 +56,26 @@ int main(int argc, char **argv)
if (!sensor.devicesFound())
return 1;
// update and print available values every second
// update and print available values every 2 seconds
while (shouldRun)
{
// update our values for the first sensor
sensor.update(0);
// update our values for all of the detected sensors
sensor.update(-1);
// we show both C and F for temperature for the first sensor
cout << "Temperature: " << sensor.getTemperature(0)
<< " C / " << sensor.getTemperature(0, true) << " F"
<< endl;
// we show both C and F for temperature for the sensors
int i;
for (i=0; i<sensor.devicesFound(); i++)
{
cout << "Device "
<< i
<< ": Temperature: "
<< sensor.getTemperature(i)
<< " C / " << sensor.getTemperature(i, true) << " F"
<< endl;
}
cout << endl;
sleep(1);
sleep(2);
}
cout << "Exiting..." << endl;

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

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014 Intel Corporation.
* Copyright (c) 2014-2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -36,44 +36,45 @@ bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a ENC03R on analog pin A0
upm::ENC03R *gyro = new upm::ENC03R(0);
// The first thing we need to do is calibrate the sensor.
cout << "Please place the sensor in a stable location, and do not" << endl;
cout << "move it while calibration takes place." << endl;
cout << "This may take a couple of minutes." << endl;
// Instantiate a ENC03R on analog pin A0
upm::ENC03R *gyro = new upm::ENC03R(0);
gyro->calibrate(CALIBRATION_SAMPLES);
cout << "Calibration complete. Reference value: "
<< gyro->calibrationValue() << endl;
// The first thing we need to do is calibrate the sensor.
cout << "Please place the sensor in a stable location, and do not" << endl;
cout << "move it while calibration takes place." << endl;
cout << "This may take a couple of minutes." << endl;
// Read the input and print both the raw value and the angular velocity,
// waiting 0.1 seconds between readings
while (shouldRun)
gyro->calibrate(CALIBRATION_SAMPLES);
cout << "Calibration complete. Reference value: "
<< gyro->calibrationValue() << endl;
// Read the input and print both the raw value and the angular velocity,
// waiting 0.1 seconds between readings
while (shouldRun)
{
unsigned int val = gyro->value();
double av = gyro->angularVelocity(val);
gyro->update();
cout << "Raw value: " << val << ", "
<< "angular velocity: " << av << " deg/s" << endl;
usleep(100000);
cout << "Angular velocity: "
<< gyro->angularVelocity()
<< " deg/s"
<< endl;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;
cout << "Exiting" << endl;
delete gyro;
return 0;
delete gyro;
return 0;
}

View File

@ -33,40 +33,40 @@ bool shouldRun = true;
// analog voltage, usually 3.3 or 5.0
#define GUVAS12D_AREF 5.0
#define SAMPLES_PER_QUERY 1024
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// The was tested with the Grove UV Sensor module.
// It has a sensing range from between 200-400nm. It's strongest
// response is around 320-360nm.
// 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
upm::GUVAS12D *volts = new upm::GUVAS12D(0);
// The higher the voltage the more intense the UV radiation.
// Instantiate a GUVAS12D on analog pin A0
upm::GUVAS12D *volts = new upm::GUVAS12D(0);
while (shouldRun)
// The higher the voltage the more intense the UV radiation.
while (shouldRun)
{
cout << "AREF: " << GUVAS12D_AREF
<< ", Voltage value (higher means more UV): "
<< volts->value(GUVAS12D_AREF, SAMPLES_PER_QUERY) << endl;
sleep(1);
cout << "Volts: " << volts->volts()
<< ", Intensity: " << volts->intensity()
<< " mW/m^2"
<< endl;
sleep(1);
}
//! [Interesting]
cout << "Exiting" << endl;
cout << "Exiting" << endl;
delete volts;
return 0;
delete volts;
return 0;
}

View File

@ -40,7 +40,7 @@ void printUsage(char *progname)
<< endl;
cout << "sent to the module and the response is printed out." << endl;
cout << endl;
cout << "If no argument is used, then the address and PIN of the module"
cout << "If no argument is used, then the address and PIN of the module"
<< endl;
cout << "are queried and the results printed out." << endl;
cout << endl;
@ -52,12 +52,12 @@ void sendCommand(upm::HM11* ble, char *cmd)
{
char buffer[BUFSIZ];
ble->writeData(cmd, strlen(cmd));
// wait up to 1 second
if (ble->dataAvailable(1000))
{
memset(buffer, 0, BUFSIZ);
ble->readData(buffer, BUFSIZ - 1);
cout << "Returned: " << buffer << endl;
}
@ -71,7 +71,6 @@ void sendCommand(upm::HM11* ble, char *cmd)
int main (int argc, char **argv)
{
//! [Interesting]
char buffer[BUFSIZ];
// Instantiate a HM11 BLE Module on UART 0
upm::HM11* ble = new upm::HM11(0);

View File

@ -32,16 +32,17 @@ main(int argc, char **argv)
//! [Interesting]
// Instantiate on I2C
upm::Hmc5883l* compass = new upm::Hmc5883l(0);
int16_t *pos;
compass->set_declination(0.2749); // Set your declination from true north in radians
compass->set_declination(0.2749); // Set your declination from
// true north in radians
// Print out the coordinates, heading, and direction every second
while(true){
compass->update(); // Update the coordinates
pos = compass->coordinates();
const int16_t *pos = compass->coordinates();
fprintf(stdout, "coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
fprintf(stdout, "heading: %5.2f direction: %3.2f\n", compass->heading(), compass->direction());
fprintf(stdout, "heading: %5.2f direction: %3.2f\n",
compass->heading(), compass->direction());
sleep(1);
}
//! [Interesting]

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;
}

175
examples/c++/le910.cxx Normal file
View File

@ -0,0 +1,175 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <string>
#include "uartat.hpp"
#include "upm_utilities.h"
using namespace std;
const size_t bufferLength = 256;
int main(int argc, char **argv)
{
//! [Interesting]
string defaultDev = string("/dev/ttyUSB0");
if (argc > 1)
defaultDev = string(argv[1]);
cout << "Using device: " << defaultDev << endl;
// Instantiate a UARTAT sensor on defaultDev at 115200 baud.
upm::UARTAT *sensor = new upm::UARTAT(defaultDev, 115200);
// This is a simplistic example that tries to configure the LE910,
// and use it's built-in socket capabilities to connect to a
// remote host, obtain a small piece of data, and return it. It's
// mainly intended to show you how you can use the various AT
// commands supported by the LE910 to perform simple tasks.
//
// You must have a valid SIM card with an active data plan for
// this example to do anything interesting.
//
// See the LE910 AT Commands reference for full information on
// what is possible with this device. The uartat driver is
// intended to make it a little easier to control AT-style
// devices, but is by no means a full-featured communication
// infrastructure. A "real" application will probably need to be
// much more sophisticated with regard to parsing, doing retries,
// etc.
//
// For experimenting with various AT commands, try using an
// interactive terminal emulator like minicom or screen.
// make sure we are in command mode
if (!sensor->inCommandMode())
{
cout << "Not in command mode, switching..." << endl;
sensor->commandMode("+++", 1000);
}
// flter out CR's in responses by default
sensor->filterCR(true);
cout << "Configuring modem..." << endl;
// discard any waiting characters
sensor->drain();
// reset modem
sensor->command("ATZ\r");
// turn off command echo, set verbosity to 1, enable data
// connection mode
sensor->command("ATE0 V1 +FCLASS=0\r");
sensor->drain();
// Now issue some commands and output the results.
cout << "Modem and SIM information:" << endl;
std::string buffer;
buffer = sensor->commandWithResponse("AT+ICCID\r", bufferLength);
if (!buffer.empty())
cout << "ICCID (SIM ID): "
<< buffer
<< endl;
buffer = sensor->commandWithResponse("AT+CGSN=1\r", bufferLength);
if (!buffer.empty())
cout << "IMEI: "
<< buffer
<< endl;
// see if we are on the network....
buffer = sensor->commandWithResponse("AT+CREG?\r", bufferLength);
if (!buffer.empty())
{
cout << buffer << endl;
// look for "CGREG: 0,1" or "CGREG: 0,5"
if (sensor->find(buffer, "CREG: 0,1") ||
sensor->find(buffer, "CREG: 0,5"))
{
cout << "Connected to the cell data network." << endl;
// wait up to 5 seconds for responses now...
sensor->setResponseWaitTime(5000);
// setup PDP context (socket 1). An ERROR repsonse is
// possible if the PDP context is already set up.
sensor->command("AT#SGACT=1,1\r");
// setup a TCP socket to nist.gov and read the timestamp.
cout << "Connecting to time-a.nist.gov, TCP port 13" << endl;
// Wait up to 60 seconds to find the NO CARRIER
// string, which will be present at the end, if the
// connection succeeded and the requested data was
// obtained.
buffer =
sensor->commandWaitFor("AT#SD=1,0,13,\"time-a.nist.gov\"\r",
bufferLength, "\nNO CARRIER\n", 60000);
if (!buffer.empty())
{
// print out the response
cout << "RESPONSE: "
<< endl
<< buffer
<< endl;
}
else
{
cout << "No response." << endl;
}
// destroy PDP context
sensor->setResponseWaitTime(250);
sensor->command("AT#SGACT=1,0\r");
}
else
{
cout << "You do not appear to be connected to the network..."
<< endl;
}
}
else
{
cout << "Error executing query\n" << endl;
}
// reset the modem
sensor->command("ATZ\r");
cout << "Exiting" << endl;
delete sensor;
//! [Interesting]
return 0;
}

View File

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

99
examples/c++/max30100.cxx Normal file
View File

@ -0,0 +1,99 @@
/*
* 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 "max30100.hpp"
using namespace upm;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
// Example Callback handler
class mycallback : public Callback
{
public:
virtual void run(max30100_value samp)
{
std::cout << "My callback sample IR: "
<< samp.IR << " R: " << samp.R << std::endl;
}
};
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a MAX30100 instance using i2c bus 0
upm::MAX30100 sensor(0);
// Create an instance of the Callback class
mycallback cb;
// Read the temperature and version
std::cout << "Temperature: " << sensor.temperature() << " C" << std::endl;
std::cout << "Version: " << sensor.version() << std::endl;
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(MAX30100_MODE_SPO2_EN);
// Read continuously, stepping up the LED current every second,
// us GPIO 0 as the interrupt pin
sensor.sample_continuous(0, false, &cb);
for (int i = MAX30100_LED_CURRENT_0_0_MA;
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
{
// Toggle the LED current
std::cout << "Setting LED current = " << i << std::endl;
sensor.current((MAX30100_LED_CURRENT)i, (MAX30100_LED_CURRENT)i);
upm_delay(1);
}
// Read individual samples
for (int i = 0; i < 10; i++)
{
max30100_value val = sensor.sample();
std::cout << "Single value IR: " << val.IR << " R: " << val.R << std::endl;
}
//! [Interesting]
std::cout << "Exiting..." << std::endl;
return 0;
}

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;
}

View File

@ -0,0 +1,125 @@
/*
* 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 <iostream>
#include <signal.h>
#include <upm_utilities.h>
#include "mcp2515.hpp"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
// by default we just receive packets
bool do_tx = false;
// if an argument is given, we will transmit packets
if (argc > 1)
do_tx = true;
//! [Interesting]
// NOTE: This example assumes that only two devices are connected
// to the CAN bus, and that both devices are running this example;
// one in TX (transmit) mode, and one in RX (receive) mode.
// If this is not the case, then in rx mode you may see other
// packets from other devices, or not, depending on whether the
// speed is correct for the network. In tx mode, errors may be
// generated on the bus, especially if the CAN bus speed does not
// match the rest of the network.
// You should start the receiver example first. The transmitter
// example will fail after about 5 seconds (timeout) of not being
// able to transmit a message.
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
upm::MCP2515 *sensor = new upm::MCP2515(0, 9);
// By default, after initialization, the baud rate is set to
// 50Kbps, and the mode is NORMAL, so we don't need to set any of
// that here.
// our TX payload. If transmitting, the first number will be
// incremented (and rollover) on each transmission.
string myPayload = "01234567";
while (shouldRun)
{
if (do_tx)
{
cout << "Loading a packet of 8 numbers (0-7) into a TX buffer..."
<< endl;
sensor->loadTXBuffer(MCP2515_TX_BUFFER0, 0, false, false,
myPayload);
// now lets try to transmit it
cout << "Transmitting packet..." << endl;
sensor->transmitBuffer(MCP2515_TX_BUFFER0, true);
myPayload[0]++;
cout << "Transmit successful" << endl;
cout << endl;
upm_delay_ms(500);
}
else
{
// RX mode
// Look for a packet waiting for us in RXB0
if (sensor->rxStatusMsgs() == MCP2515_RXMSG_RXB0)
{
cout << "Packet received in RXB0, decoding..." << endl;
// now lets retrieve and print it
sensor->getRXMsg(MCP2515_RX_BUFFER0);
sensor->printMsg();
cout << endl;
}
upm_delay_ms(100);
}
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

79
examples/c++/mcp2515.cxx 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 <iostream>
#include "mcp2515.hpp"
using namespace std;
int main(int argc, char **argv)
{
//! [Interesting]
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
upm::MCP2515 *sensor = new upm::MCP2515(0, -1);
cout << "Setting loopback mode..." << endl;
// set the mode to loopback mode. In loopback mode, transmitted
// packets are sent directly to an appropriate receive buffer
// without actually going out onto the CAN bus.
sensor->setOpmode(MCP2515_OPMODE_LOOPBACK);
// lets build up a packet and try loading it (8 bytes max).
string myPayload = "01234567";
cout << "Loading a packet of 8 numbers (0-7) into a TX buffer..." << endl;
sensor->loadTXBuffer(MCP2515_TX_BUFFER0, 0, false, false, myPayload);
// now lets try to transmit it
cout << "Transmitting packet..." << endl;
sensor->transmitBuffer(MCP2515_TX_BUFFER0, true);
cout << "Transmit successful" << endl;
// There should now be a packet waiting for us in RXB0
if (sensor->rxStatusMsgs() == MCP2515_RXMSG_RXB0)
{
cout << "Packet received in RXB0, decoding..." << endl;
// now lets retrieve and print it
sensor->getRXMsg(MCP2515_RX_BUFFER0);
sensor->printMsg();
}
else
{
cout << "No packet found, how strange." << endl;
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

View File

@ -159,5 +159,5 @@ int main()
}while (command != -1 );
//! [Interesting]
return MRAA_SUCCESS;
return 0;
}

View File

@ -74,5 +74,5 @@ int main()
delete sensor;
//! [Interesting]
return MRAA_SUCCESS;
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 uint8_t uart_buffer[20];
static uint8_t uart_buffer_len = 0;
static uint8_t dummychar = 0;
void
sig_handler(int signo)

View File

@ -43,37 +43,29 @@ int main(int argc, char **argv)
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a nunchuck controller bus 0
upm::NUNCHUCK *nunchuck = new upm::NUNCHUCK(0);
// always do this first
cout << "Initializing... " << endl;
if (!nunchuck->init())
{
cerr << "nunchuck->init() failed." << endl;
return 0;
}
// Instantiate a nunchuck controller bus 3
upm::NUNCHUCK *nunchuck = new upm::NUNCHUCK(3);
while (shouldRun)
{
nunchuck->update();
cout << "stickX: " << nunchuck->stickX
cout << "stickX: " << nunchuck->stickX
<< ", stickY: " << nunchuck->stickY << endl;
cout << "accelX: " << nunchuck->accelX
<< ", accelY: " << nunchuck->accelY
cout << "accelX: " << nunchuck->accelX
<< ", accelY: " << nunchuck->accelY
<< ", accelZ: " << nunchuck->accelZ << endl;
cout << "button C: "
cout << "button C: "
<< ((nunchuck->buttonC) ? "pressed" : "not pressed") << endl;
cout << "button Z: "
cout << "button Z: "
<< ((nunchuck->buttonZ) ? "pressed" : "not pressed") << endl;
cout << endl;
usleep(100000);
}
//! [Interesting]
delete nunchuck;
return 0;
}

View File

@ -33,31 +33,34 @@ int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a dust sensor on GPIO pin D8
upm::PPD42NS* dust = new upm::PPD42NS(8);
upm::dustData data;
cout << "This program will give readings every 30 seconds until you stop it" << endl;
while (shouldRun)
{
data = dust->getData();
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
cout << "Ratio: " << data.ratio << endl;
cout << "Concentration: " << data.concentration << endl;
}
// Instantiate a dust sensor on GPIO pin D8
upm::PPD42NS* dust = new upm::PPD42NS(8);
ppd42ns_dust_data data;
cout << "This program will give readings every 30 seconds until "
<< "you stop it"
<< endl;
while (shouldRun)
{
data = dust->getData();
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
cout << "Ratio: " << data.ratio << endl;
cout << "Concentration: " << data.concentration << endl;
cout << endl;
}
//! [Interesting]
cout << "Exiting" << endl;
cout << "Exiting" << endl;
delete dust;
return 0;
delete dust;
return 0;
}

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

View File

@ -0,0 +1,55 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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 "speaker.hpp"
using namespace std;
int main ()
{
//! [Interesting]
// Instantiate a Speaker (PWM) pin D3 in PWM mode
upm::Speaker* speaker = new upm::Speaker(3, true);
// emit a series of frequencies for 500ms each
speaker->emit(50, 500);
speaker->emit(75, 500);
speaker->emit(125, 500);
speaker->emit(250, 500);
speaker->emit(500, 500);
speaker->emit(1000, 500);
speaker->emit(2000, 500);
speaker->emit(3000, 500);
speaker->emit(5000, 500);
speaker->emit(10000, 500);
cout << "Exiting" << endl;
delete speaker;
//! [Interesting]
return 0;
}

View File

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

View File

@ -33,46 +33,47 @@ int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a Water Flow Sensor on digital pin D2
upm::WFS* flow = new upm::WFS(2);
// set the flow counter to 0 and start counting
flow->clearFlowCounter();
flow->startFlowCounter();
// Instantiate a Water Flow Sensor on digital pin D2. This must
// be an interrupt capable pin.
upm::WFS* flow = new upm::WFS(2);
while (shouldRun)
// set the flow counter to 0 and start counting
flow->clearFlowCounter();
flow->startFlowCounter();
while (shouldRun)
{
// we grab these (,illis and flowCount) just for display
// purposes in this example
uint32_t millis = flow->getMillis();
uint32_t flowCount = flow->flowCounter();
// we grab these (millis and flowCount) just for display
// purposes in this example
uint32_t millis = flow->getMillis();
uint32_t flowCount = flow->flowCounter();
float fr = flow->flowRate();
float fr = flow->flowRate();
// output milliseconds passed, flow count, and computed flow rate
cout << "Millis: " << millis << " Flow Count: " << flowCount;
cout << " Flow Rate: " << fr << " LPM" << endl;
// output milliseconds passed, flow count, and computed flow rate
cout << "Millis: " << millis << " Flow Count: " << flowCount;
cout << " Flow Rate: " << fr << " LPM" << endl;
// best to gather data for at least one second for reasonable
// results.
sleep(2);
// best to gather data for at least one second for reasonable
// results.
sleep(2);
}
flow->stopFlowCounter();
flow->stopFlowCounter();
//! [Interesting]
cout << "Exiting..." << endl;
cout << "Exiting..." << endl;
delete flow;
return 0;
delete flow;
return 0;
}

View File

@ -23,7 +23,7 @@ macro(add_custom_example example_bin example_src example_module_list)
set(found_all_modules FALSE)
endif()
if (MODULE_LIST)
list(FIND MODULE_LIST ${module}-c index)
list(FIND MODULE_LIST ${module} index)
if (${index} EQUAL -1)
set(found_all_modules FALSE)
endif()
@ -132,6 +132,23 @@ add_example (linefinder)
add_example (uln200xa)
add_example (mma7660)
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)
add_example (mcp2515)
add_example (max30100)
add_example (speaker)
add_example (cjq4435)
add_example (hmc5883l)
add_example (wfs)
add_example (enc03r)
add_example (nunchuck)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
@ -139,3 +156,7 @@ 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 (rpr220-intr-example-c rpr220-intr.c rpr220)
add_custom_example (md-stepper-example-c md-stepper.c md)
add_custom_example (button_intr-example-c button_intr.c button)
add_custom_example (mcp2515-txrx-example-c mcp2515-txrx.c mcp2515)
add_custom_example (le910-example-c le910.c uartat)
add_custom_example (speaker_pwm-example-c speaker_pwm.c speaker)

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;
}

82
examples/c/cjq4435.c Normal file
View File

@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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 "cjq4435.h"
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
cjq4435_context mosfet = cjq4435_init(3);
if (!mosfet)
{
printf("cjq4435_init() failed.\n");
return 1;
}
cjq4435_set_period_ms(mosfet, 10);
cjq4435_enable(mosfet, true);
while (shouldRun)
{
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
for (float i=0.0; i <= 1.0; i+=0.1)
{
cjq4435_set_duty_cycle(mosfet, i);
upm_delay_ms(100);
}
upm_delay(1);
// Now bring it back down
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
for (float i=1.0; i >= 0.0; i-=0.1)
{
cjq4435_set_duty_cycle(mosfet, i);
upm_delay_ms(100);
}
upm_delay(1);
}
printf("Exiting...\n");
cjq4435_close(mosfet);
//! [Interesting]
return 0;
}

View File

@ -56,7 +56,7 @@ int main(int argc, char **argv)
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
// update and print available values every second
// update and print available values every 2 seconds
while (shouldRun)
{
// update our values for all sensors

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;
}

90
examples/c/enc03r.c Normal file
View File

@ -0,0 +1,90 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014-2017 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 <upm_platform.h>
#include "enc03r.h"
bool shouldRun = true;
// The number of samples used for calibration
#if defined(UPM_PLATFORM_ZEPHYR)
# define CALIBRATION_SAMPLES 500
#else
# define CALIBRATION_SAMPLES 1000
#endif
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a ENC03R on analog pin A0
enc03r_context sensor = enc03r_init(0, 5.0);
if (!sensor)
{
printf("%s: enc03r_init() failed\n", __FUNCTION__);
return 1;
}
// The first thing we need to do is calibrate the sensor.
printf("Please place the sensor in a stable location, and do not\n");
printf("move it while calibration takes place.\n");
printf("This may take a little time to complete.\n");
enc03r_calibrate(sensor, CALIBRATION_SAMPLES);
printf("Calibration complete. Reference value: %f\n\n",
enc03r_calibration_value(sensor));
// Read the input and print both the raw value and the angular velocity,
// waiting 0.1 seconds between readings
while (shouldRun)
{
enc03r_update(sensor);
printf("Angular velocity: %f deg/s\n",
enc03r_angular_velocity(sensor));
upm_delay_ms(100);
}
printf("Exiting\n");
enc03r_close(sensor);
//! [Interesting]
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;
}

82
examples/c/hmc5883l.c Normal file
View File

@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* Ported based on original C++ code by:
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include "hmc5883l.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate an HMC8883L on I2C bus 0
hmc5883l_context sensor = hmc5883l_init(0);
if (!sensor)
{
printf("%s: hmc5883l_init() failed\n", __FUNCTION__);
return 1;
}
hmc5883l_set_declination(sensor, 0.2749); // Set your declination
// from true north in
// radians
// Print out the coordinates, heading, and direction every second
while (shouldRun)
{
hmc5883l_update(sensor); // Update the coordinates
const int16_t *pos = hmc5883l_coordinates(sensor);
printf("coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
printf("heading: %5.2f direction: %3.2f\n",
hmc5883l_heading(sensor), hmc5883l_direction(sensor));
upm_delay(1);
}
hmc5883l_close(sensor);
//! [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;
}

169
examples/c/le910.c Normal file
View File

@ -0,0 +1,169 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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 "uartat.h"
#include "upm_utilities.h"
const size_t bufferLength = 256;
int main(int argc, char **argv)
{
//! [Interesting]
char *defaultDev = "/dev/ttyUSB0";
if (argc > 1)
defaultDev = argv[1];
printf("Using device: %s\n", defaultDev);
// Instantiate a UARTAT sensor on defaultDev at 115200 baud.
uartat_context sensor = uartat_init_tty(defaultDev, 115200);
if (!sensor)
{
printf("uartat_init_tty() failed.\n");
return 1;
}
// This is a simplistic example that tries to configure the LE910,
// and use it's built-in socket capabilities to connect to a
// remote host, obtain a small piece of data, and return it. It's
// mainly intended to show you how you can use the various AT
// commands supported by the LE910 to perform simple tasks.
//
// You must have a valid SIM card with an active data plan for
// this example to do anything interesting.
//
// See the LE910 AT Commands reference for full information on
// what is possible with this device. The uartat driver is
// intended to make it a little easier to control AT-style
// devices, but is by no means a full-featured communication
// infrastructure. A "real" application will probably need to be
// much more sophisticated, and custom designed for the desired
// task.
//
// For experimenting with various AT commands, try using an
// interactive terminal emulator like minicom or screen.
char buffer[bufferLength];
// make sure we are in command mode
if (!uartat_in_command_mode(sensor))
{
printf("Not in command mode, switching...\n");
uartat_command_mode(sensor, "+++", 1000);
}
// flter out CR's in responses by default
uartat_filter_cr(sensor, true);
printf("Configuring modem...\n");
// discard any waiting characters
uartat_drain(sensor);
// reset modem
uartat_command(sensor, "ATZ\r");
// turn off command echo, set verbosity to 1, enable data
// connection mode
uartat_command(sensor, "ATE0 V1 +FCLASS=0\r");
uartat_drain(sensor);
// Now issue some commands and output the results.
printf("Modem and SIM information:\n");
if (uartat_command_with_response(sensor, "AT+ICCID\r",
buffer, bufferLength))
printf("ICCID (SIM ID): %s\n", buffer);
if (uartat_command_with_response(sensor, "AT+CGSN=1\r",
buffer, bufferLength))
printf("IMEI: %s\n", buffer);
// see if we are on the network....
if (uartat_command_with_response(sensor, "AT+CREG?\r",
buffer, bufferLength))
{
printf("%s\n", buffer);
// look for "CGREG: 0,1" or "CGREG: 0,5"
if (uartat_find(sensor, buffer, "CREG: 0,1") ||
uartat_find(sensor, buffer, "CREG: 0,5"))
{
printf("Connected to the cell data network.\n");
// wait up to 5 seconds for responses now...
uartat_set_response_wait_time(sensor, 5000);
// setup PDP context (socket 1). An ERROR response is
// possible if the PDP context is already set up.
uartat_command(sensor, "AT#SGACT=1,1\r");
// setup a TCP socket to nist.gov and read the timestamp.
printf("Connecting to time-a.nist.gov, TCP port 13\n");
// Wait up to 60 seconds to find the NO CARRIER
// string, which will be present at the end, if the
// connection succeeded and the requested data was
// obtained.
if (uartat_command_waitfor(sensor,
"AT#SD=1,0,13,\"time-a.nist.gov\"\r",
buffer, bufferLength,
"\nNO CARRIER\n", 60000))
{
// print out the response
printf("RESPONSE:\r%s\r", buffer);
}
else
{
printf("No response.\n");
}
// destroy PDP context
uartat_set_response_wait_time(sensor, 250);
uartat_command(sensor, "AT#SGACT=1,0\r");
}
else
{
printf("You do not appear to be connected to the network...\n");
}
}
else
{
printf("Error executing query\n");
}
// reset the modem
uartat_command(sensor, "ATZ\r");
printf("Exiting\n");
uartat_close(sensor);
//! [Interesting]
return 0;
}

130
examples/c/max30100.c Normal file
View File

@ -0,0 +1,130 @@
/*
* 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 "max30100.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
void my_sample_handler(max30100_value sample, void* arg)
{
printf("My callback sample IR: %d R: %d\n",
sample.IR, sample.R);
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
max30100_context* sensor = max30100_init(0);
if (!sensor)
{
printf("max30100_init() failed\n");
return -1;
}
/* Get the temperature */
float temp;
if (max30100_get_temperature(sensor, &temp) != UPM_SUCCESS)
{
printf("max30100_get_temperature failed\n");
goto max30100_exit;
}
/* Get the version */
uint16_t version;
if (max30100_get_version(sensor, &version) != UPM_SUCCESS)
{
printf("max30100_get_version failed\n");
goto max30100_exit;
}
printf("Temperature: %f C\n", temp);
printf("Version: 0x%04x\n", version);
/* Set high-res (50 Hz, 16-bit) */
if (max30100_set_high_res(sensor, true) != UPM_SUCCESS)
{
printf("max30100_set_high_res failed\n");
goto max30100_exit;
}
/* Set to sample SpO2 */
if (max30100_set_mode(sensor, MAX30100_MODE_SPO2_EN) != UPM_SUCCESS)
{
printf("max30100_set_mode failed\n");
goto max30100_exit;
}
/* Read continuously, stepping up the LED current every second,
* us GPIO 0 as the interrupt pin */
max30100_sample_continuous(sensor, 0, false, &my_sample_handler, sensor);
for (int i = MAX30100_LED_CURRENT_0_0_MA;
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
{
/* Toggle the LED current */
printf("Setting LED current = %d\n", i);
if ( max30100_set_current(sensor, (MAX30100_LED_CURRENT)i,
(MAX30100_LED_CURRENT)i) != UPM_SUCCESS )
{
printf("max30100_set_current failed\n");
goto max30100_exit;
}
upm_delay(1);
}
/* Read individual samples */
for (int i = 0; i < 10; i++)
{
max30100_value samp;
if (max30100_sample(sensor, &samp) != UPM_SUCCESS)
{
printf("max30100_sample failed\n");
goto max30100_exit;
}
printf("Single value IR: %d R: %d\n", samp.IR, samp.R);
}
max30100_exit:
//! [Interesting]
printf("Exiting\n");
max30100_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;
}

144
examples/c/mcp2515-txrx.c Normal file
View File

@ -0,0 +1,144 @@
/*
* 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 "mcp2515.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
// by default we just receive packets
bool do_tx = false;
// if an argument is given, we will transmit packets
if (argc > 1)
do_tx = true;
//! [Interesting]
// NOTE: This example assumes that only two devices are connected
// to the CAN bus, and that both devices are running this example;
// one in TX (transmit) mode, and one in RX (receive) mode.
// If this is not the case, then in rx mode you may see other
// packets from other devices, or not, depending on whether the
// speed is correct for the network. In tx mode, errors may be
// generated on the bus, especially if the CAN bus speed does not
// match the rest of the network.
// You should start the receiver example first. The transmitter
// example will fail after about 5 seconds (timeout) of not being
// able to transmit a message.
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
mcp2515_context sensor = mcp2515_init(0, -1);
if (!sensor)
{
printf("mcp2515_init() failed\n");
return 1;
}
// By default, after initialization, the baud rate is set to
// 50Kbps, and the mode is NORMAL, so we don't need to set any of
// that here.
if (!do_tx)
printf("RX mode, waiting for packets...\n");
// our TX payload. If transmitting, the first number will be
// incremented (and rollover) on each transmission.
uint8_t myPayload[8] = {0, 1, 2, 3, 4, 5, 6, 7};
while (shouldRun)
{
if (do_tx)
{
// lets build up a packet and try loading it.
printf("Loading a packet of 8 numbers into a tx buffer...\n");
if (mcp2515_load_tx_buffer(sensor, MCP2515_TX_BUFFER0, 0,
false, false, myPayload, 8))
{
printf("mcp2515_load_tx_buffer() failed\n");
return 1;
}
// now lets try to transmit it
printf("Transmitting packet...\n");
upm_result_t rv = 0;
if ((rv = mcp2515_transmit_buffer(sensor, MCP2515_TX_BUFFER0,
true)))
{
printf("mcp2515_transmit_buffer() failed with code %d\n", rv);
return 1;
}
// increment the first number for each transmission
myPayload[0]++;
printf("Transmit successful\n\n");
upm_delay_ms(500);
}
else
{
// RX mode
// Look for a packet waiting for us in RXB0
if (mcp2515_rx_status_msgs(sensor) == MCP2515_RXMSG_RXB0)
{
printf("Packet received in RXB0, decoding...\n");
// now lets retrieve it
MCP2515_MSG_T msg;
if (mcp2515_get_rx_msg(sensor, MCP2515_RX_BUFFER0, &msg))
{
printf("mcp2515_get_rx_msg() failed\n");
return 1;
}
mcp2515_print_msg(sensor, &msg);
printf("\n");
}
upm_delay_ms(100);
}
}
printf("Exiting...\n");
mcp2515_close(sensor);
//! [Interesting]
return 0;
}

101
examples/c/mcp2515.c Normal file
View File

@ -0,0 +1,101 @@
/*
* 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 "mcp2515.h"
int main(int argc, char **argv)
{
//! [Interesting]
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
mcp2515_context sensor = mcp2515_init(0, -1);
if (!sensor)
{
printf("mcp2515_init() failed\n");
return 1;
}
printf("Setting loopback mode...\n");
// set the mode to loopback mode. In loopback mode, transmitted
// packets are sent directly to an appropriate receive buffer
// without actually going out onto the CAN bus.
if (mcp2515_set_opmode(sensor, MCP2515_OPMODE_LOOPBACK))
{
printf("mcp2515_set_opmode(loopback) failed.\n");
return 1;
}
// lets build up a packet and try loading it.
uint8_t myPayload[8] = {0, 1, 2, 3, 4, 5, 6, 7};
printf("Loading a packet of 8 numbers (0-7) into a TX buffer...\n");
if (mcp2515_load_tx_buffer(sensor, MCP2515_TX_BUFFER0, 0, false, false,
myPayload, 8))
{
printf("mcp2515_load_tx_buffer() failed\n");
return 1;
}
// now lets try to transmit it
printf("Transmitting packet...\n");
upm_result_t rv = 0;
if ((rv = mcp2515_transmit_buffer(sensor, MCP2515_TX_BUFFER0, true)))
{
printf("mcp2515_transmit_buffer() failed with code %d\n", rv);
return 1;
}
printf("Transmit successful\n");
// There should now be a packet waiting for us in RXB0
if (mcp2515_rx_status_msgs(sensor) == MCP2515_RXMSG_RXB0)
{
printf("Packet received in RXB0, decoding...\n");
// now lets retrieve it
MCP2515_MSG_T msg;
if (mcp2515_get_rx_msg(sensor, MCP2515_RX_BUFFER0, &msg))
{
printf("mcp2515_get_rx_msg() failed\n");
return 1;
}
mcp2515_print_msg(sensor, &msg);
}
else
{
printf("No packet found, how strange.\n");
}
printf("Exiting...\n");
mcp2515_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;
}

84
examples/c/nunchuck.c Normal file
View File

@ -0,0 +1,84 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include "nunchuck.h"
bool 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 nunchuck controller bus 3
nunchuck_context sensor = nunchuck_init(3);
if (!sensor)
{
printf("%s: nunchuck_init() failed\n", __FUNCTION__);
return 1;
}
while (shouldRun)
{
if (nunchuck_update(sensor))
{
printf("%s: nunchuck_update() failed\n", __FUNCTION__);
nunchuck_close(sensor);
return 1;
}
int x, y, z;
nunchuck_get_stick(sensor, &x, &y);
printf("stickX: %d stickY: %d\n", x, y);
nunchuck_get_acceleration(sensor, &x, &y, &z);
printf("accelX: %d accelY: %d accelZ: %d\n", x, y, z);
bool bc, bz;
nunchuck_get_buttons(sensor, &bc, &bz);
printf("button C: %s\n",
((bc) ? "pressed" : "not pressed"));
printf("button Z: %s\n\n",
((bz) ? "pressed" : "not pressed"));
upm_delay_ms(100);
}
nunchuck_close(sensor);
//! [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;
}

55
examples/c/speaker.c Normal file
View File

@ -0,0 +1,55 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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 "speaker.h"
int main ()
{
//! [Interesting]
// Instantiate a Speaker on digital pin D2
speaker_context speaker = speaker_init(2);
if (!speaker)
{
printf("speaker_init() failed\n");
return 1;
}
// Play all 7 of the lowest notes
speaker_play_all(speaker);
// Play a medium C-sharp
speaker_play_sound(speaker, 'c', true, "med");
printf("Exiting\n");
speaker_close(speaker);
//! [Interesting]
return 0;
}

61
examples/c/speaker_pwm.c Normal file
View File

@ -0,0 +1,61 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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 "speaker.h"
int main ()
{
//! [Interesting]
// Instantiate a Speaker (PWM) on digital pin D3
speaker_context speaker = speaker_init_pwm(26);
if (!speaker)
{
printf("speaker_init() failed\n");
return 1;
}
// emit a series of frequencies for 500ms each
speaker_emit(speaker, 50, 500);
speaker_emit(speaker, 75, 500);
speaker_emit(speaker, 125, 500);
speaker_emit(speaker, 250, 500);
speaker_emit(speaker, 500, 500);
speaker_emit(speaker, 1000, 500);
speaker_emit(speaker, 2000, 500);
speaker_emit(speaker, 3000, 500);
speaker_emit(speaker, 5000, 500);
speaker_emit(speaker, 10000, 500);
printf("Exiting\n");
speaker_close(speaker);
//! [Interesting]
return 0;
}

91
examples/c/wfs.c Normal file
View File

@ -0,0 +1,91 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2014-02017 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 "wfs.h"
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 Water Flow Sensor on digital pin D2. This must
// be an interrupt capable pin.
wfs_context sensor = wfs_init(2);
if (!sensor)
{
printf("%s: wfs_init() failed\n", __FUNCTION__);
return 1;
}
// set the flow counter to 0 and start counting
wfs_clear_flow_counter(sensor);
if (wfs_start_flow_counter(sensor))
{
printf("%s: wfs_start_flow_counter() failed\n", __FUNCTION__);
wfs_close(sensor);
return 1;
}
while (shouldRun)
{
// we grab these (millis and flowCount) just for display
// purposes in this example
uint32_t millis = wfs_get_millis(sensor);
uint32_t flowCount = wfs_flow_counter(sensor);
float fr = wfs_flow_rate(sensor);
// output milliseconds passed, flow count, and computed flow rate
printf("Millis: %8d Flow Count: %5d Flow Rate: %f LPM\n",
millis, flowCount, fr);
// best to gather data for at least one second for reasonable
// results.
upm_delay(2);
}
wfs_stop_flow_counter(sensor);
printf("Exiting...\n");
wfs_close(sensor);
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,100 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one the ADS1015 ADC on the Grove Joule
* Shield or the Sparkfun ADC Block for Edison with devices that output a small
* differential voltage (e.g. geophones, piezoelectric bands or pads,
* thermocouples).
*/
import java.io.*;
import java.util.concurrent.*;
import upm_ads1x15.*;
public class Ads1015Sample
{
static boolean running = true;
static int id = 0; // Sample number
static String fileName = "./ads1015.data"; // Output filename
public static void main(String[] args) throws InterruptedException
{
// Open the output file
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(fileName);
bw = new BufferedWriter(fw);
} catch (IOException e) {
System.out.println("Failed to open output file for writing: " + e.toString());
System.exit(1);
}
// Initialize and configure the ADS1015
ADS1015 ads1015 = new ADS1015(0, (short)0x48);
// Put the ADC into differential mode for pins A0 and A1
ads1015.getSample(ADS1X15.ADSMUXMODE.DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1015.setGain(ADS1X15.ADSGAIN.GAIN_TWO);
// Set the sample rate to 3300 samples per second (max) and turn on continuous
// sampling
ads1015.setSPS(ADS1015.ADSSAMPLERATE.SPS_3300);
ads1015.setContinuous(true);
// Schedule a task to stop logging after 10 seconds
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
running = false;
}
}, 10, TimeUnit.SECONDS);
// Read from sensor and write to file every ms
while(running){
try {
bw.write(id + " " + String.format("%.7f", ads1015.getLastSample()) + "\n");
} catch (IOException e) {
System.out.println("Failed to write sample " + id + " to file: "+ e.toString());
System.exit(1);
}
id++;
Thread.sleep(1);
}
// Close and exit
try {
bw.close();
fw.close();
} catch (IOException e) {
System.out.println("Failed to close output file cleanly: " + e.toString());
System.exit(1);
}
System.out.println("Wrote " + id + " samples to file: " + fileName);
System.exit(0);
}
}

View File

@ -0,0 +1,103 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one of the ADS1115 ADCs on the
* DFRobot Joule Shield with devices that output a small differential
* voltage (e.g. geophones, piezoelectric bands or pads, thermocouples).
*/
import java.io.*;
import java.util.concurrent.*;
import upm_ads1x15.*;
public class Ads1115Sample
{
static boolean running = true;
static int id = 0; // Sample number
static String fileName = "./ads1115.data"; // Output filename
public static void main(String[] args) throws InterruptedException
{
// Open the output file
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(fileName);
bw = new BufferedWriter(fw);
} catch (IOException e) {
System.out.println("Failed to open output file for writing: " + e.toString());
System.exit(1);
}
// Initialize and configure the ADS1115 for the SM-24 Geophone
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
// - 0x48 gives access to pins A0 - A3
// - 0x49 gives access to pins A4 - A7
ADS1115 ads1115 = new ADS1115(0, (short)0x48);
// Put the ADC into differential mode for pins A0 and A1,
// the SM-24 Geophone is connected to these pins
ads1115.getSample(ADS1X15.ADSMUXMODE.DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1115.setGain(ADS1X15.ADSGAIN.GAIN_TWO);
// Set the sample rate to 860 samples per second (max) and turn on continuous
// sampling
ads1115.setSPS(ADS1115.ADSDATARATE.SPS_860);
ads1115.setContinuous(true);
// Schedule a task to stop logging after 10 seconds
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
running = false;
}
}, 10, TimeUnit.SECONDS);
// Read from sensor and write to file every ms
while(running){
try {
bw.write(id + " " + String.format("%.7f", ads1115.getLastSample()) + "\n");
} catch (IOException e) {
System.out.println("Failed to write sample " + id + " to file: "+ e.toString());
System.exit(1);
}
id++;
Thread.sleep(1);
}
// Close and exit
try {
bw.close();
fw.close();
} catch (IOException e) {
System.out.println("Failed to close output file cleanly: " + e.toString());
System.exit(1);
}
System.out.println("Wrote " + id + " samples to file: " + fileName);
System.exit(0);
}
}

View File

@ -156,6 +156,14 @@ add_example(HKA5_Example hka5)
add_example(DFRORP_Example dfrorp)
add_example(DFREC_Example dfrec)
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(MCP2515_Example mcp2515)
add_example(Ads1015Sample ads1x15)
add_example(MAX30100_Example max30100)
add_example(Ads1115Sample ads1x15)
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
@ -177,3 +185,6 @@ if (OPENZWAVE_FOUND)
add_example_with_path(TZEMT400_Example ozw ozw)
endif()
add_example_with_path(NMEAGPS_I2C_Example nmea_gps nmea_gps)
add_example_with_path(MCP2515_TXRX_Example mcp2515 mcp2515)
add_example_with_path(LE910_Example uartat uartat)
add_example_with_path(SpeakerPWMSample speaker speaker)

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

@ -22,7 +22,7 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//NOT TESTED!!!
public class ENC03RSample {
private static final long CALIBRATION_SAMPLES = 1000;
@ -42,14 +42,15 @@ public class ENC03RSample {
// Read the input and print both the raw value and the angular velocity,
// waiting 1 second between readings
while (true) {
long val = gyro.value();
double av = gyro.angularVelocity(val);
gyro.update();
System.out.println("Raw value: " + val + ", angular velocity: " + av + " deg/s");
System.out.println("Angular velocity: "
+ gyro.angularVelocity()
+ " deg/s");
Thread.sleep(1000);
Thread.sleep(100);
}
// ! [Interesting]
}
}
}

View File

@ -1,6 +1,7 @@
/*
* 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
* a copy of this software and associated documentation files (the
@ -23,24 +24,26 @@
*/
public class GUVAS12DSample {
// analog voltage, usually 3.3 or 5.0
private static final float GUVAS12D_AREF = 5;
private static final int SAMPLES_PER_QUERY = 1024;
// analog voltage, usually 3.3 or 5.0
private static final float GUVAS12D_AREF = 5;
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a GUVAS12D on analog pin A3
upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(3);
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a GUVAS12D on analog pin A0
upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(0,
GUVAS12D_AREF);
while (true) {
float value = volts.value(GUVAS12D_AREF, SAMPLES_PER_QUERY);
while (true)
{
System.out.println("Volts: "
+ volts.volts()
+ ", Intensity: "
+ volts.intensity()
+ " mW/m^2");
System.out.println("AREF: " + GUVAS12D_AREF
+ ", Voltage value (higher means more UV): " + value);
Thread.sleep(1000);
}
// ! [Interesting]
}
Thread.sleep(1000);
}
// ! [Interesting]
}
}
}

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,167 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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_uartat.UARTAT;
public class LE910_Example
{
private static String defaultDev = "/dev/ttyUSB0";
static private final int bufferLength = 256;
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
System.out.println("Initializing...");
// Instantiate a UARTAT sensor on defaultDev at 115200 baud.
UARTAT sensor = new UARTAT(defaultDev, 115200);
// This is a simplistic example that tries to configure the LE910,
// and use it's built-in socket capabilities to connect to a
// remote host, obtain a small piece of data, and return it. It's
// mainly intended to show you how you can use the various AT
// commands supported by the LE910 to perform simple tasks.
//
// You must have a valid SIM card with an active data plan for
// this example to do anything interesting.
//
// See the LE910 AT Commands reference for full information on
// what is possible with this device. The uartat driver is
// intended to make it a little easier to control AT-style
// devices, but is by no means a full-featured communication
// infrastructure. A "real" application will probably need to be
// much more sophisticated with regard to parsing, doing retries,
// etc.
//
// For experimenting with various AT commands, try using an
// interactive terminal emulator like minicom or screen.
// make sure we are in command mode
if (!sensor.inCommandMode())
{
System.out.println("Not in command mode, switching...");
sensor.commandMode("+++", 1000);
}
// flter out CR's in responses by default
sensor.filterCR(true);
System.out.println("Configuring modem...");
// discard any waiting characters
sensor.drain();
// reset modem
sensor.command("ATZ\r");
// turn off command echo, set verbosity to 1, enable data
// connection mode
sensor.command("ATE0 V1 +FCLASS=0\r");
sensor.drain();
// Now issue some commands and output the results.
System.out.println("Modem and SIM information:");
String buffer;
buffer = sensor.commandWithResponse("AT+ICCID\r", bufferLength);
if (buffer.length() > 0)
{
System.out.println("ICCID (SIM ID): " + buffer);
}
buffer = sensor.commandWithResponse("AT+CGSN=1\r", bufferLength);
if (buffer.length() > 0)
{
System.out.println("IMEI: " + buffer);
}
// see if we are on the network....
buffer = sensor.commandWithResponse("AT+CREG?\r", bufferLength);
if (buffer.length() > 0)
{
System.out.println(buffer);
// look for "CGREG: 0,1" or "CGREG: 0,5"
if (sensor.find(buffer, "CREG: 0,1") ||
sensor.find(buffer, "CREG: 0,5"))
{
System.out.println("Connected to the cell data network.");
// wait up to 5 seconds for responses now...
sensor.setResponseWaitTime(5000);
// setup PDP context (socket 1). An ERROR repsonse is
// possible if the PDP context is already set up.
sensor.command("AT#SGACT=1,1\r");
// setup a TCP socket to nist.gov and read the timestamp.
System.out.println("Connecting to time-a.nist.gov, TCP port 13");
// Wait up to 60 seconds to find the NO CARRIER
// string, which will be present at the end, if the
// connection succeeded and the requested data was
// obtained.
buffer =
sensor.commandWaitFor("AT#SD=1,0,13,\"time-a.nist.gov\"\r",
bufferLength, "\nNO CARRIER\n", 60000);
if (buffer.length() > 0)
{
// print out the response
System.out.println("RESPONSE: ");
System.out.println(buffer);
}
else
{
System.out.println("No response.");
}
// destroy PDP context
sensor.setResponseWaitTime(250);
sensor.command("AT#SGACT=1,0\r");
}
else
{
System.out.println("You do not appear to be connected to the network...");
}
}
else
{
System.out.println("Error executing query\n");
}
// reset the modem
sensor.command("ATZ\r");
System.out.println("Exiting");
// ! [Interesting]
}
}

View File

@ -0,0 +1,88 @@
/*
* 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_max30100.*;
public class MAX30100_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a MAX30100 instance using bus 0
MAX30100 sensor = new MAX30100((short)0);
System.out.println("Oximeter sensor example...");
// Read the temperature and version
System.out.format("Temperature: %f C\n", sensor.temperature());
System.out.format("Version: 0x%04x\n", sensor.version());
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(MAX30100_MODE.MAX30100_MODE_SPO2_EN);
Callback cb = new JavaCallback();
// Read continuously, stepping up the LED current every second,
// us GPIO 0 as the interrupt pin
sensor.sample_continuous(0, false, cb);
for (int i = 0; i <= 15; i++)
{
// Toggle the LED current
System.out.format("Setting LED current = %d\n", i);
sensor.current(MAX30100_LED_CURRENT.swigToEnum(i),
MAX30100_LED_CURRENT.swigToEnum(i));
Thread.sleep(1000);
}
sensor.sample_stop();
// Read individual samples
for (int i = 0; i < 10; i++) {
max30100_value val = sensor.sample();
System.out.format("Single value IR: %d R: %d\n", val.getIR(), val.getR());
}
// ! [Interesting]
}
}
class JavaCallback extends Callback
{
public JavaCallback()
{
super();
}
public void run(max30100_value val)
{
System.out.format("My callback sample IR: %d R: %d\n", val.getIR(), val.getR());
}
}

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,73 @@
/*
* 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_mcp2515.MCP2515;
public class MCP2515_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
MCP2515 sensor = new MCP2515(0, -1);
// set the mode to loopback mode. In loopback mode, transmitted
// packets are sent directly to an appropriate receive buffer
// without actually going out onto the CAN bus.
sensor.setOpmode(upm_mcp2515.MCP2515_OPMODE_T.MCP2515_OPMODE_LOOPBACK);
// lets build up a packet and try loading it (8 bytes max).
String myPayload = "01234567";
System.out.println("Loading a packet of 8 numbers (0-7) into a TX buffer...");
sensor.loadTXBuffer(upm_mcp2515.MCP2515_TX_BUFFER_T.MCP2515_TX_BUFFER0,
0, false, false, myPayload);
// now lets try to transmit it
System.out.println("Transmitting packet...");
sensor.transmitBuffer(upm_mcp2515.MCP2515_TX_BUFFER_T.MCP2515_TX_BUFFER0,
true);
System.out.println("Transmit successful");
// There should now be a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == upm_mcp2515.MCP2515_RXMSG_T.MCP2515_RXMSG_RXB0)
{
System.out.println("Packet received in RXB0, decoding...");
// now lets retrieve and print it
sensor.getRXMsg(upm_mcp2515.MCP2515_RX_BUFFER_T.MCP2515_RX_BUFFER0);
sensor.printMsg();
}
else
{
System.out.println("No packet found, how strange.");
}
System.out.println("Exiting...");
// ! [Interesting]
}
}

View File

@ -0,0 +1,94 @@
/*
* 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_mcp2515.MCP2515;
public class MCP2515_TXRX_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// by default we just receive packets
Boolean do_tx = false;
if (args.length > 0)
do_tx = true;
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
MCP2515 sensor = new MCP2515(0, -1);
// NOTE: This example assumes that only two devices are connected
// to the CAN bus, and that both devices are running this example;
// one in TX (transmit) mode, and one in RX (receive) mode.
// If this is not the case, then in rx mode you may see other
// packets from other devices, or not, depending on whether the
// speed is correct for the network. In tx mode, errors may be
// generated on the bus, especially if the CAN bus speed does not
// match the rest of the network.
// You should start the receiver example first. The transmitter
// example will fail after about 5 seconds (timeout) of not being
// able to transmit a message.
while (true)
{
if (do_tx)
{
// lets build up a packet and try loading it (8 bytes max).
String myPayload = "01234567";
System.out.println("Loading a packet of 8 numbers (0-7) into a TX buffer...");
sensor.loadTXBuffer(upm_mcp2515.MCP2515_TX_BUFFER_T.MCP2515_TX_BUFFER0,
0, false, false, myPayload);
// now lets try to transmit it
System.out.println("Transmitting packet...");
sensor.transmitBuffer(upm_mcp2515.MCP2515_TX_BUFFER_T.MCP2515_TX_BUFFER0,
true);
System.out.println("Transmit successful");
System.out.println();
Thread.sleep(500);
}
else
{
// There should now be a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == upm_mcp2515.MCP2515_RXMSG_T.MCP2515_RXMSG_RXB0)
{
System.out.println("Packet received in RXB0, decoding...");
// now lets retrieve and print it
sensor.getRXMsg(upm_mcp2515.MCP2515_RX_BUFFER_T.MCP2515_RX_BUFFER0);
sensor.printMsg();
System.out.println();
}
Thread.sleep(100);
}
}
// ! [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

@ -24,38 +24,38 @@
public class NUNCHUCKSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a nunchuck controller bus 0
upm_nunchuck.NUNCHUCK nunchuck = new upm_nunchuck.NUNCHUCK(0);
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a nunchuck controller bus 0
upm_nunchuck.NUNCHUCK nunchuck = new upm_nunchuck.NUNCHUCK(3);
// always do this first
System.out.println("Initializing... ");
if (!nunchuck.init()) {
System.err.println("nunchuck->init() failed.");
return;
}
while (true)
{
nunchuck.update();
System.out.println("stickX: "
+ nunchuck.getStickX()
+ ", stickY: "
+ nunchuck.getStickY());
System.out.println("accelX: "
+ nunchuck.getAccelX()
+ ", accelY: "
+ nunchuck.getAccelY()
+ ", accelZ: "
+ nunchuck.getAccelZ());
while (true) {
nunchuck.update();
System.out.println("stickX: " + nunchuck.getStickX() + ", stickY: "
+ nunchuck.getStickY());
System.out.println("accelX: " + nunchuck.getAccelX() + ", accelY: "
+ nunchuck.getAccelY() + ", accelZ: " + nunchuck.getAccelZ());
if (nunchuck.getButtonC())
System.out.println("Button C pressed");
else
System.out.println("Button C not pressed");
if (nunchuck.getButtonC())
System.out.println("Button C pressed");
else
System.out.println("Button C not pressed");
if (nunchuck.getButtonZ())
System.out.println("Button Z pressed");
else
System.out.println("Button Z not pressed");
if (nunchuck.getButtonZ())
System.out.println("Button Z pressed");
else
System.out.println("Button Z not pressed");
Thread.sleep(100);
}
// ! [Interesting]
}
Thread.sleep(1000);
}
// ! [Interesting]
}
}
}

View File

@ -24,22 +24,22 @@
public class PPD42NSSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a dust sensor on GPIO pin D8
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
upm_ppd42ns.dustData data;
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a dust sensor on GPIO pin D8
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
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");
while (true) {
data = dust.getData();
while (true) {
data = dust.getData();
System.out.println("Low pulse occupancy: " + data.getLowPulseOccupancy());
System.out.println("Ratio: " + data.getRatio());
System.out.println("Concentration: " + data.getConcentration());
}
// ! [Interesting]
}
System.out.println("Low pulse occupancy: " + data.getLowPulseOccupancy());
System.out.println("Ratio: " + data.getRatio());
System.out.println("Concentration: " + data.getConcentration());
}
// ! [Interesting]
}
}
}

View File

@ -0,0 +1,46 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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.
*/
public class SpeakerPWMSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a Speaker (PWM) pin D3 in PWM mode
upm_speaker.Speaker speaker = new upm_speaker.Speaker(3, true);
// emit a series of frequencies for 500ms each
speaker.emit(50, 500);
speaker.emit(75, 500);
speaker.emit(125, 500);
speaker.emit(250, 500);
speaker.emit(500, 500);
speaker.emit(1000, 500);
speaker.emit(2000, 500);
speaker.emit(3000, 500);
speaker.emit(5000, 500);
speaker.emit(10000, 500);
// ! [Interesting]
}
}

View File

@ -25,20 +25,23 @@
//NOT TESTED!!!
public class WFSSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a Water Flow Sensor on digital pin D2
upm_wfs.WFS flow = new upm_wfs.WFS(2);
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
flow.clearFlowCounter();
flow.startFlowCounter();
// Instantiate a Water Flow Sensor on
// digital pin D2. This must be an
// interrupt capable pin.
upm_wfs.WFS flow = new upm_wfs.WFS(2);
while (true) {
System.out.print("Millis: " + flow.getMillis() + " FlowCount: " + flow.flowCounter());
System.out.println(" Flow Rate: " + flow.flowRate() + " LPM");
flow.clearFlowCounter();
flow.startFlowCounter();
Thread.sleep(2000);
}
// ! [Interesting]
}
while (true) {
System.out.print("Millis: " + flow.getMillis() + " FlowCount: " + flow.flowCounter());
System.out.println(" Flow Rate: " + flow.flowRate() + " LPM");
Thread.sleep(2000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,70 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one the ADS1015 ADC on the Grove Joule
* Shield or the Sparkfun ADC Block for Edison with devices that output a small
* differential voltage (e.g. geophones, piezoelectric bands or pads,
* thermocouples).
*/
var mraa = require('mraa'); // Not used directly but required if jsupm_ads1x15 was installed from NPM
var upm = require('jsupm_ads1x15');
var fs = require('fs'); // Values will be written to a file
var file = "./ads1015.data" // Output filename
var id = 0; // Sample number
var ival; // Interval function for sampling
// Initialize and configure the ADS1015
var ads1015 = new upm.ADS1015(0, 0x48);
// Put the ADC into differential mode for pins A0 and A1
ads1015.getSample(upm.ADS1X15_MUX_DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1015.setGain(upm.ADS1X15.GAIN_TWO);
// Set the sample rate to 3300 samples per second (max) and turn on continuous
// sampling
ads1015.setSPS(upm.ADS1015.SPS_3300);
ads1015.setContinuous(true);
// Open the output file and start reading data once open
// Will overwrite file if it already exists
var stream = fs.createWriteStream(file);
stream.once('open', function() {
ival = setInterval(function() {
// Write data pairs of ID + Value for easy plotting
stream.write(id + " " + ads1015.getLastSample().toFixed(7) + "\n");
id++;
}, 1); // Wait 1 ms between reads, (actuall call adds another ~1 ms overhead)
});
// Stop after 10 seconds and close the file
setTimeout(function() {
clearInterval(ival);
stream.end();
console.log("Wrote " + id + " samples to file: " + file);
}, 10000);

View File

@ -0,0 +1,74 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@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.
*/
/* This example demonstrates how to use one of the ADS1115 ADCs on the
* DFRobot Joule Shield with devices that output a small differential
* voltage (e.g. geophones, piezoelectric bands or pads, thermocouples).
*/
var mraa = require('mraa'); // Not used directly but required if jsupm_ads1x15 was installed from NPM
var upm = require('jsupm_ads1x15');
var fs = require('fs'); // Values will be written to a file
var file = "./ads1115.data" // Output filename
var id = 0; // Sample number
var ival; // Interval function for sampling
// There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
// - 0x48 gives access to pins A0 - A3
// - 0x49 gives access to pins A4 - A7
var ads1115 = new upm.ADS1115(0, 0x48);
// Configure the ADS1115 for the SM-24 Geophone
// Put the ADC into differential mode for pins A0 and A1,
// the SM-24 Geophone is connected to these pins
ads1115.getSample(upm.ADS1X15_MUX_DIFF_0_1);
// Set the gain based on expected VIN range to -/+ 2.048 V
// Can be adjusted based on application to as low as -/+ 0.256 V, see API
// documentation for details
ads1115.setGain(upm.ADS1X15.GAIN_TWO);
// Set the sample rate to 860 samples per second (max) and turn on continuous
// sampling
ads1115.setSPS(upm.ADS1115.SPS_860);
ads1115.setContinuous(true);
// Open the output file and start reading data once open
// Will overwrite file if it already exists
var stream = fs.createWriteStream(file);
stream.once('open', function() {
ival = setInterval(function() {
// Write data pairs of ID + Value for easy plotting
stream.write(id + " " + ads1115.getLastSample().toFixed(7) + "\n");
id++;
}, 1); // Wait 1 ms between reads, (actuall call adds another ~1 ms overhead)
});
// Stop after 10 seconds and close the file
setTimeout(function() {
clearInterval(ival);
stream.end();
console.log("Wrote " + id + " samples to file: " + file);
}, 10000);

View File

@ -22,11 +22,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Load Grove module
var groveSensor = require('jsupm_grove');
// Load UPM module
var upm = require('jsupm_button');
// 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
function readButtonValue() {

View File

@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2016-2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -33,9 +33,6 @@ console.log("Initializing...");
// Instantiate an DS18B20 instance using the default values (uart 0)
var sensor = new sensorObj.DS18B20(0);
// locate and setup our devices
sensor.init();
console.log("Found", sensor.devicesFound(), "device(s)");
console.log("");
@ -44,17 +41,21 @@ if (!sensor.devicesFound())
process.exit(1);
}
// update and print available values every second
// update and print available values every 2 seconds
setInterval(function()
{
// update our values for the first sensor
sensor.update(0);
// update our values for all of the detected sensors
sensor.update(-1);
// we show both C and F for temperature for the first sensor
console.log("Temperature:", sensor.getTemperature(0),
"C /", sensor.getTemperature(0, true), "F");
// we show both C and F for temperature for the sensors
for (var i=0; i<sensor.devicesFound(); i++)
{
console.log("Device:", i, "Temperature:", sensor.getTemperature(i),
"C /", sensor.getTemperature(i, true), "F");
}
}, 1000);
console.log();
}, 2000);
process.on('SIGINT', function()

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

@ -30,8 +30,8 @@ var myGyro = new analogGyro.ENC03R(0);
var CALIBRATION_SAMPLES = 1000;
console.log("Please place the sensor in a stable location,\n" +
"and do not move it while calibration takes place.\n" +
"This may take a couple of minutes.");
"and do not move it while calibration takes place.\n" +
"This may take a couple of minutes.");
myGyro.calibrate(CALIBRATION_SAMPLES);
console.log("Calibration complete. Reference value: " +
@ -41,23 +41,22 @@ console.log("Calibration complete. Reference value: " +
// waiting 0.1 seconds between readings
setInterval(function()
{
var gyroVal = myGyro.value();
var outputStr = "Raw value: " + gyroVal + ", " +
"angular velocity: " +
roundNum(myGyro.angularVelocity(gyroVal), 5) + " deg/s";
console.log(outputStr);
myGyro.update();
var outputStr = "Angular velocity: " +
roundNum(myGyro.angularVelocity(), 5) + " deg/s";
console.log(outputStr);
}, 100);
function roundNum(num, decimalPlaces)
{
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
return (Math.round((num + extraNum) * (Math.pow(10, 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
process.on('SIGINT', function()
{
console.log("Exiting...");
process.exit(0);
console.log("Exiting...");
process.exit(0);
});

View File

@ -1,6 +1,7 @@
/*
* 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
* a copy of this software and associated documentation files (the
@ -24,26 +25,22 @@
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
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()
{
var outputStr = "AREF: " + g_GUVAS12D_AREF
+ ", Voltage value (higher means more UV): "
+ roundNum(myUVSensor.value(g_GUVAS12D_AREF, g_SAMPLES_PER_QUERY), 6);
console.log(outputStr);
}, 1000);
var outputStr = "Volts: "
+ myUVSensor.volts()
+ ", Intensity: "
+ myUVSensor.intensity()
+ " mW/m^2";
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));
}
console.log(outputStr);
}, 1000);
// Print message when exiting
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

@ -0,0 +1,166 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 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_uartat');
var defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device:", defaultDev);
console.log("Initializing...");
// Instantiate a UARTAT sensor on defaultDev at 115200 baud.
var sensor = new sensorObj.UARTAT(defaultDev, 115200);
// This is a simplistic example that tries to configure the LE910,
// and use it's built-in socket capabilities to connect to a
// remote host, obtain a small piece of data, and return it. It's
// mainly intended to show you how you can use the various AT
// commands supported by the LE910 to perform simple tasks.
//
// You must have a valid SIM card with an active data plan for
// this example to do anything interesting.
//
// See the LE910 AT Commands reference for full information on
// what is possible with this device. The uartat driver is
// intended to make it a little easier to control AT-style
// devices, but is by no means a full-featured communication
// infrastructure. A "real" application will probably need to be
// much more sophisticated with regard to parsing, doing retries,
// etc.
//
// For experimenting with various AT commands, try using an
// interactive terminal emulator like minicom or screen.
// make sure we are in command mode
if (!sensor.inCommandMode())
{
console.log("Not in command mode, switching...");
sensor.commandMode("+++", 1000);
}
// flter out CR's in responses by default
sensor.filterCR(true);
console.log("Configuring modem...");
// discard any waiting characters
sensor.drain();
// reset modem
sensor.command("ATZ\r");
// turn off command echo, set verbosity to 1, enable data
// connection mode
sensor.command("ATE0 V1 +FCLASS=0\r");
sensor.drain();
// Now issue some commands and output the results.
console.log("Modem and SIM information:");
var buffer;
var bufferLength = 256;
buffer = sensor.commandWithResponse("AT+ICCID\r", bufferLength);
if (buffer.length > 0)
{
console.log("ICCID (SIM ID):", buffer);
}
buffer = sensor.commandWithResponse("AT+CGSN=1\r", bufferLength);
if (buffer.length > 0)
{
console.log("IMEI: ", buffer);
}
// see if we are on the network....
buffer = sensor.commandWithResponse("AT+CREG?\r", bufferLength);
if (buffer.length > 0)
{
console.log(buffer);
// look for "CGREG: 0,1" or "CGREG: 0,5"
if (sensor.find(buffer, "CREG: 0,1") ||
sensor.find(buffer, "CREG: 0,5"))
{
console.log("Connected to the cell data network.");
// wait up to 5 seconds for responses now...
sensor.setResponseWaitTime(5000);
// setup PDP context (socket 1). An ERROR repsonse is
// possible if the PDP context is already set up.
sensor.command("AT#SGACT=1,1\r");
// setup a TCP socket to nist.gov and read the timestamp.
console.log("Connecting to time-a.nist.gov, TCP port 13");
// Wait up to 60 seconds to find the NO CARRIER
// string, which will be present at the end, if the
// connection succeeded and the requested data was
// obtained.
buffer =
sensor.commandWaitFor("AT#SD=1,0,13,\"time-a.nist.gov\"\r",
bufferLength, "\nNO CARRIER\n", 60000);
if (buffer.length > 0)
{
// print out the response
console.log("RESPONSE: ");
console.log(buffer);
}
else
{
console.log("No response.");
}
// destroy PDP context
sensor.setResponseWaitTime(250);
sensor.command("AT#SGACT=1,0\r");
}
else
{
console.log("You do not appear to be connected to the network...");
}
}
else
{
console.log("Error executing query\n");
}
// reset the modem
sensor.command("ATZ\r");
console.log("Exiting");
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
process.exit(0);

View File

@ -22,10 +22,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Load Grove module
// Load UPM module
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);
// Print the name

View File

@ -0,0 +1,57 @@
/*
* 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_max30100');
// Instantiate a MAX30100 instance using bus 0
var sensor = new sensorObj.MAX30100(0);
console.log('Oximeter sensor example...');
// Read the temperature and version
console.log ('Temperature: %d C', sensor.temperature());
console.log ('Version: 0x%s', sensor.version().toString(16));
// Set high-res (50 Hz, 16-bit)
sensor.high_res_enable(true);
// Set to sample SpO2
sensor.mode(sensorObj.MAX30100_MODE_SPO2_EN);
// Read individual samples
for (var i = 0; i < 10; i++)
{
var val = sensor.sample();
console.log('Single value IR: %d R: %d ', val.IR, val.R);
}
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log('Exiting.');
process.exit(0);
});

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

@ -0,0 +1,94 @@
/*
* 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_mcp2515');
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
var sensor = new sensorObj.MCP2515(0, -1);
// NOTE: This example assumes that only two devices are connected
// to the CAN bus, and that both devices are running this example;
// one in TX (transmit) mode, and one in RX (receive) mode.
// If this is not the case, then in rx mode you may see other
// packets from other devices, or not, depending on whether the
// speed is correct for the network. In tx mode, errors may be
// generated on the bus, especially if the CAN bus speed does not
// match the rest of the network.
// You should start the receiver example first. The transmitter
// example will fail after about 5 seconds (timeout) of not being
// able to transmit a message.
function transmit(sensor)
{
// lets build up a packet and try loading it (8 bytes max).
var myPayload = "01234567";
console.log("Loading a packet of 8 numbers (0-7) into a TX buffer...");
sensor.loadTXBuffer(sensorObj.MCP2515_TX_BUFFER0,
0, false, false, myPayload);
// now lets try to transmit it
console.log("Transmitting packet...");
sensor.transmitBuffer(sensorObj.MCP2515_TX_BUFFER0, true);
console.log("Transmit successful");
console.log();
}
function receive(sensor)
{
// There should now be a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == sensorObj.MCP2515_RXMSG_RXB0)
{
console.log("Packet received in RXB0, decoding...");
// now lets retrieve and print it
sensor.getRXMsg(sensorObj.MCP2515_RX_BUFFER0);
sensor.printMsg();
console.log();
}
}
// by default we just receive packets
if (process.argv.length > 2)
{
// transmit mode
interval = setInterval(function() { transmit(sensor); }, 500);
}
else
{
// receive mode
interval = setInterval(function() { receive(sensor); }, 100);
}
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);
});

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.
*/
var sensorObj = require('jsupm_mcp2515');
// Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
var sensor = new sensorObj.MCP2515(0, -1);
// set the mode to loopback mode. In loopback mode, transmitted
// packets are sent directly to an appropriate receive buffer
// without actually going out onto the CAN bus.
sensor.setOpmode(sensorObj.MCP2515_OPMODE_LOOPBACK);
// lets build up a packet and try loading it (8 bytes max).
var myPayload = "01234567";
console.log("Loading a packet of 8 numbers (0-7) into a TX buffer...");
sensor.loadTXBuffer(sensorObj.MCP2515_TX_BUFFER0, 0, false, false, myPayload);
// now lets try to transmit it
console.log("Transmitting packet...");
sensor.transmitBuffer(sensorObj.MCP2515_TX_BUFFER0, true);
console.log("Transmit successful");
// There should now be a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == sensorObj.MCP2515_RXMSG_RXB0)
{
console.log("Packet received in RXB0, decoding...");
// now lets retrieve and print it
sensor.getRXMsg(sensorObj.MCP2515_RX_BUFFER0);
sensor.printMsg();
}
else
{
console.log("No packet found, how strange.");
}
console.log("Exiting...");
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
process.exit(0);

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