Compare commits

..

46 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
611 changed files with 15609 additions and 2688 deletions

View File

@ -118,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)
@ -143,6 +145,8 @@ 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
@ -193,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.2")
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 ()

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

@ -4,6 +4,17 @@ 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

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/max30100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 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

@ -327,6 +327,8 @@ 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)
@ -369,3 +371,8 @@ if (OPENZWAVE_FOUND)
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

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

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

@ -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]

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

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

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

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

@ -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

@ -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

@ -141,6 +141,14 @@ 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)
@ -149,3 +157,6 @@ 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)

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

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

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

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

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

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

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

@ -160,6 +160,10 @@ 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)
@ -181,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

@ -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

@ -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,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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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,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);

View File

@ -24,16 +24,8 @@
var nunchuck_lib = require('jsupm_nunchuck');
// Instantiate a nunchuck controller bus 0
var nunchuck_obj = new nunchuck_lib.NUNCHUCK(0);
// always do this first
console.log("Initializing... ");
if (!nunchuck_obj.init())
{
console.log("nunchuck->init() failed.");
process.exit(0);
}
// Instantiate a nunchuck controller bus 3
var nunchuck_obj = new nunchuck_lib.NUNCHUCK(3);
setInterval(function()
{

View File

@ -0,0 +1,47 @@
/*
* 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.
*/
//Load Speaker module
var Speaker = require('jsupm_speaker');
// Instantiate a Speaker (PWM) pin D3 in PWM mode
var speaker = new 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);
// Print message when exiting
process.on('SIGINT', function()
{
console.log("Exiting...");
process.exit(0);
});

View File

@ -24,7 +24,8 @@
var waterFlow_lib = require('jsupm_wfs');
// Instantiate a Water Flow Sensor on digital pin D2
// Instantiate a Water Flow Sensor on digital pin D2. This must be an
// interrupt capable pin.
var myWaterFlow_obj = new waterFlow_lib.WFS(2);
// set the flow counter to 0 and start counting

View File

@ -0,0 +1,83 @@
# 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
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# 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).
from __future__ import print_function
from threading import Timer
from time import sleep
from upm import pyupm_ads1x15 as upm
def stop():
global running
running = False
def main():
global running
running = True
fileName = './ads1015.data' # Output filename
id = 0 # Sample number
# Initialize and configure the ADS1015
ads1015 = upm.ADS1015(0, 0x48)
# Put the ADC into differential mode for pins A0 and A1
ads1015.getSample(upm.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(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
try:
f = open(fileName, 'w')
except OSError as e:
print('Cannot open output file:', e)
return
# Setup a timer to stop logging after 10 seconds
t = Timer(10, stop)
t.start()
# Read sensor and write to file every 1 ms
while running:
f.write(str(id) + ' %.7f' % ads1015.getLastSample() + '\n')
id += 1
sleep(0.001)
# Close and exit
f.close()
print('Wrote', id, 'samples to file:', fileName)
return
if __name__ == '__main__':
main()

View File

@ -0,0 +1,86 @@
# 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
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# 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).
from __future__ import print_function
from threading import Timer
from time import sleep
from upm import pyupm_ads1x15 as upm
def stop():
global running
running = False
def main():
global running
running = True
fileName = './ads1115.data' # Output filename
id = 0 # Sample number
# 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 = 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(upm.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(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
try:
f = open(fileName, 'w')
except OSError as e:
print('Cannot open output file:', e)
return
# Setup a timer to stop logging after 10 seconds
t = Timer(10, stop)
t.start()
# Read sensor and write to file every 1 ms
while running:
f.write(str(id) + ' %.7f' % ads1115.getLastSample() + '\n')
id += 1
sleep(0.001)
# Close and exit
f.close()
print('Wrote', id, 'samples to file:', fileName)
return
if __name__ == '__main__':
main()

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
# 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
@ -45,25 +45,26 @@ def main():
# Instantiate an DS18B20 instance using the default values (uart 0)
sensor = sensorObj.DS18B20(0)
# locate and setup our devices
sensor.init()
print("Found", sensor.devicesFound(), "device(s)")
print()
if (not sensor.devicesFound()):
sys.exit(1);
# update and print available values every second
# update and print available values every 2 seconds
while (1):
# 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
print("Temperature:", sensor.getTemperature(0), "C /", end=' ')
print(sensor.getTemperature(0, True), "F")
# we show both C and F for temperature for the sensors
for i in range(sensor.devicesFound()):
print("Device:", i, end=' ')
print("Temperature:", sensor.getTemperature(i), "C /", end=' ')
print(sensor.getTemperature(i, True), "F")
time.sleep(1)
print()
time.sleep(2)
if __name__ == '__main__':
main()

View File

@ -55,10 +55,9 @@ def main():
print("Reference value: ", myAnalogGyro.calibrationValue())
while(1):
gyroVal = myAnalogGyro.value();
outputStr = ("Raw value: {0}, "
"angular velocity: {1}"
" deg/s".format(gyroVal, myAnalogGyro.angularVelocity(gyroVal)))
myAnalogGyro.update();
outputStr = ("Angular velocity: {0}"
" deg/s".format(myAnalogGyro.angularVelocity()))
print(outputStr)
time.sleep(.1)

157
examples/python/le910.py Executable file
View File

@ -0,0 +1,157 @@
#!/usr/bin/python
# 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.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_uartat as UARTAT
def main():
## Exit handlers ##
# This function stops python from printing a stacktrace when you
# hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from sensor
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
defaultDev = "/dev/ttyUSB0"
# if an argument was specified, use it as the device instead
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print("Using device:", defaultDev);
# Instantiate a UARTAT sensor on defaultDev at 115200 baud.
sensor = UARTAT.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 (not sensor.inCommandMode()):
print("Not in command mode, switching...")
sensor.commandMode("+++", 1000)
# flter out CR's in responses by default
sensor.filterCR(True)
print("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.
print("Modem and SIM information:")
bufferLength = 256
buffer = sensor.commandWithResponse("AT+ICCID\r", bufferLength)
if (buffer):
print("ICCID (SIM ID):", buffer)
buffer = sensor.commandWithResponse("AT+CGSN=1\r", bufferLength)
if (buffer):
print("IMEI: ", buffer)
# see if we are on the network....
buffer = sensor.commandWithResponse("AT+CREG?\r", bufferLength)
if (buffer):
print(buffer)
# look for "CGREG: 0,1" or "CGREG: 0,5"
if (sensor.find(buffer, "CREG: 0,1") or
sensor.find(buffer, "CREG: 0,5")):
print("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.
print("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):
# print out the response
print("RESPONSE: ")
print(buffer)
else:
print("No response.")
# destroy PDP context
sensor.setResponseWaitTime(250)
sensor.command("AT#SGACT=1,0\r")
else:
print("You do not appear to be connected to the network...")
else:
print("Error executing query\n")
# reset the modem
sensor.command("ATZ\r")
if __name__ == '__main__':
main()

71
examples/python/max30100.py Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/python
# Author: Noel Eck <noel.eck@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_max30100
# Callback class derived from CXX Callback
class mycallback(pyupm_max30100.Callback):
def __init__(self):
self.count = 0
pyupm_max30100.Callback.__init__(self)
def run(self, samp):
print("My callback sample IR: %d R: %d" % (samp.IR, samp.R))
def main():
# Create an instance of the oximiter
# I2C bus 0
x = pyupm_max30100.MAX30100(0)
print ('Oximeter sensor example...')
# Create an instance of the mycallback class
cb = mycallback().__disown__()
# Read the temperature and version
print ("Temperature: %d C" % x.temperature())
print ("Version: 0x%04x" % x.version())
# Set high-res (50 Hz, 16-bit)
x.high_res_enable(True)
# Set to sample SpO2
x.mode(pyupm_max30100.MAX30100_MODE_SPO2_EN);
# Read continuously, stepping up the LED current every second,
# us GPIO 0 as the interrupt pin
x.sample_continuous(0, False, cb)
for i in range(16):
print("Setting LED current = %d" % i)
x.current(i, i)
time.sleep(1)
# Read individual samples
for i in range(10):
val = x.sample();
print("Single value IR: %d R: %d " % (val.IR, val.R))
if __name__ == '__main__':
main()

99
examples/python/mcp2515-txrx.py Executable file
View File

@ -0,0 +1,99 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_mcp2515 as MCP2515
def main():
# Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
sensor = MCP2515.MCP2515(0, -1)
## Exit handlers ##
# This function stops python from printing a stacktrace when you
# hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from sensor
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# by default we just receive packets
do_tx = False;
if (len(sys.argv) > 1):
do_tx = True
# 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.
# 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.
while (True):
if (do_tx):
print("Loading a packet of 8 numbers (0-7) into a TX buffer...")
myPayload = "01234567";
sensor.loadTXBuffer(MCP2515.MCP2515_TX_BUFFER0, 0, False,
False, myPayload);
# now lets try to transmit it
print("Transmitting packet...")
sensor.transmitBuffer(MCP2515.MCP2515_TX_BUFFER0, True)
print("Transmit successful")
print()
time.sleep(.5)
else:
# RX mode
# Look for a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == MCP2515.MCP2515_RXMSG_RXB0):
print("Packet received in RXB0, decoding...")
# now lets retrieve and print it
sensor.getRXMsg(MCP2515.MCP2515_RX_BUFFER0)
sensor.printMsg();
print()
print("Exiting...")
if __name__ == '__main__':
main()

79
examples/python/mcp2515.py Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_mcp2515 as MCP2515
def main():
# Instantiate a MCP2515 on SPI bus 0 using a hw CS pin (-1).
sensor = MCP2515.MCP2515(0, -1)
## Exit handlers ##
# This function stops python from printing a stacktrace when you
# hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from sensor
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
print("Setting loopback mode...")
# 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.MCP2515_OPMODE_LOOPBACK);
# lets build up a packet and try loading it (8 bytes max).
myPayload = "01234567";
print("Loading a packet of 8 numbers (0-7) into a TX buffer...")
sensor.loadTXBuffer(MCP2515.MCP2515_TX_BUFFER0, 0, False, False, myPayload);
# now lets try to transmit it
print("Transmitting packet...")
sensor.transmitBuffer(MCP2515.MCP2515_TX_BUFFER0, True);
print("Transmit successful")
# There should now be a packet waiting for us in RXB0
if (sensor.rxStatusMsgs() == MCP2515.MCP2515_RXMSG_RXB0):
print("Packet received in RXB0, decoding...")
# now lets retrieve and print it
sensor.getRXMsg(MCP2515.MCP2515_RX_BUFFER0);
sensor.printMsg();
else:
print("No packet found, how strange.")
print("Exiting...")
if __name__ == '__main__':
main()

View File

@ -26,8 +26,8 @@ import time, sys, signal, atexit
from upm import pyupm_nunchuck as upmNunchuck
def main():
# Instantiate a nunchuck controller bus 0 on I2C
myNunchuck = upmNunchuck.NUNCHUCK(0)
# Instantiate a nunchuck controller bus 3 on I2C
myNunchuck = upmNunchuck.NUNCHUCK(3)
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
@ -43,12 +43,6 @@ def main():
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# always do this first
print("Initializing... ")
if (not myNunchuck.init()):
print("nunchuck->init() failed.")
sys.exit(0);
def buttonStateStr(buttonState):
return "pressed" if buttonState else "not pressed"

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

@ -0,0 +1,44 @@
#!/usr/bin/python
# 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 time, sys, signal, atexit
from upm import pyupm_speaker as upmspeaker
def main():
# Instantiate a Speaker (PWM) pin D3 in PWM mode
speaker = upmspeaker.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);
if __name__ == '__main__':
main()

View File

@ -26,7 +26,8 @@ import time, sys, signal, atexit
from upm import pyupm_wfs as upmwfs
def main():
# Instantiate a Water Flow Sensor on digital pin D2
# Instantiate a Water Flow Sensor on digital pin D2. This must be
# an interrupt capable GPIO.
myWaterFlow = upmwfs.WFS(2)
## Exit handlers ##

46
include/fti/upm_buttons.h Normal file
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.
*/
#ifndef UPM_BUTTONS_H_
#define UPM_BUTTONS_H_
#ifdef __cplusplus
extern "C" {
#endif
// Buttons function table
typedef struct _upm_buttons_ft {
// This function is used to query button state. The num_button
// specifies the total number of buttons present, and the values
// indicates each button's current value as an array of bools.
upm_result_t (*upm_buttons_get_num_buttons) (const void *dev,
unsigned int *num_buttons);
upm_result_t (*upm_buttons_get_values) (const void *dev,
bool *values);
} upm_buttons_ft;
#ifdef __cplusplus
}
#endif
#endif /* UPM_BUTTONS_H_ */

43
include/fti/upm_compass.h Normal file
View File

@ -0,0 +1,43 @@
/*
* 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.
*/
#ifndef UPM_COMPASS_H_
#define UPM_COMPASS_H_
#ifdef __cplusplus
extern "C" {
#endif
// Compass function table
typedef struct _upm_compass_ft {
upm_result_t (*upm_compass_set_scale) (void* dev, float scale);
upm_result_t (*upm_compass_set_offset) (void* dev, float offset);
// returns a heading in degrees
upm_result_t (*upm_compass_get_value) (void* dev, float *value);
} upm_compass_ft;
#ifdef __cplusplus
}
#endif
#endif /* UPM_COMPASS_H_ */

View File

@ -0,0 +1,42 @@
/*
* 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.
*/
#ifndef UPM_GYROSCOPE_H_
#define UPM_GYROSCOPE_H_
#ifdef __cplusplus
extern "C" {
#endif
// Gyroscope function table
typedef struct _upm_gyroscope_ft {
upm_result_t (*upm_gyroscope_set_scale) (void* dev, float* scale);
upm_result_t (*upm_gyroscope_set_offset) (void* dev, float* offset);
upm_result_t (*upm_gyroscope_get_value) (void* dev, float* value);
} upm_gyroscope_ft;
#ifdef __cplusplus
}
#endif
#endif /* UPM_GYROSCOPE_H_ */

View File

@ -75,7 +75,8 @@ typedef enum {
UPM_STREAM,
UPM_ORP,
UPM_BINARY,
UPM_ROTARYENCODER
UPM_ROTARYENCODER,
UPM_BUTTONS
} upm_sensor_t;
/* Supported IO protocols via MRAA */
@ -125,6 +126,10 @@ typedef struct _upm_sensor_ft* (*func_get_upm_sensor_ft)(upm_sensor_t sensor_typ
#include <fti/upm_binary.h>
#include <fti/upm_rotaryencoder.h>
#include <fti/upm_pressure.h>
#include <fti/upm_compass.h>
#include <fti/upm_gyroscope.h>
#include <fti/upm_buttons.h>
#include <fti/upm_joystick.h>
#ifdef __cplusplus
}

View File

@ -29,7 +29,7 @@
extern "C" {
#endif
#if defined(linux)
#if defined(__linux__)
# define UPM_PLATFORM_LINUX (1)
#elif defined(CONFIG_BOARD_ARDUINO_101) || \
defined(CONFIG_BOARD_ARDUINO_101_SSS) || \

View File

@ -1,6 +1,10 @@
# Selectively disable certain CXX warnings for SWIG wrappers
# SWIG wrappers emit -Wdelete-non-virtual-dtor and -Wunused-function warnings
set (SWIG_CXX_DISABLE_WARNINGS -Wno-delete-non-virtual-dtor
# Unfortunaly this quick fix for issue #518, adds a .c file to the
# java swig wrapper which then failes on CXX compiler warnings. For
# now, turn off warnings as errors for all the swig wrappers.
set (SWIG_CXX_DISABLE_WARNINGS -Wno-error
-Wno-delete-non-virtual-dtor
-Wno-unused-function
-Wno-maybe-uninitialized
-Wno-strict-aliasing)
@ -33,38 +37,88 @@ macro (upm_create_install_pkgconfig generated_file install_location)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
endmacro(upm_create_install_pkgconfig)
# Provides a means to call target_link_libraries AND the necessary
# swig_link_libaries. This iterates over all additional parameters AFTER
# the target name calling target_link_libraries/swig_link_libraries
# as necessary accordingly
macro (upm_target_link_libraries target_name)
# For each additional argument to upm_target_link_libraries...
foreach(_library ${ARGN})
# Add the dependency
target_link_libraries(${target_name} ${_library})
# This function iterates over all target names stored in CACHE variable
# UPM_LIBRARY_TARGETS and writes a .pc file to each build directory
function (_gen_pkg_config_per_target)
list(LENGTH UPM_LIBRARY_TARGETS n_targets)
message(STATUS "Generating pkg-config files for ${n_targets} libraries...")
set (n_ctargets 0)
set (n_cxxtargets 0)
# Iterate over the targets an build package config (.pc) files
foreach (target ${UPM_LIBRARY_TARGETS})
if (TARGET ${target})
get_target_property(libname ${target} PKG_CONFIG_NAME)
get_target_property(libdescription ${target} PKG_CONFIG_DESCRIPTION)
get_target_property(reqlibname ${target} PKG_EXT_REQ_LIBS)
get_target_property(BINARY_DIR ${target} BINARY_DIR)
get_target_property(DEPLIBS ${target} LINK_LIBRARIES)
# Remove this libname from the DEPLIBS (if it's there)
list(REMOVE_ITEM DEPLIBS ${libname})
# Check if any of the LINK_LIBRARIES are targets in this project,
# if so, add them to reqlibname
foreach (deplib ${DEPLIBS})
# If this target exists, get the actual library name (which equates
# to it's .pc filename, example: target dfrph = <upm-dfrph>.pc
if (TARGET ${deplib})
get_target_property(deplibname ${deplib} PKG_CONFIG_NAME)
list(APPEND reqlibname ${deplibname})
# If the deplib is mraa, add that verbatim (mraa's .pc file is mraa.pc)
elseif (${deplib} MATCHES mraa)
list(APPEND reqlibname mraa)
endif (TARGET ${deplib})
endforeach (deplib ${DEPLIBS})
# Make sure no dups exist
separate_arguments(reqlibname)
list(REMOVE_DUPLICATES reqlibname)
# Switch to comma separated Requires: field (per pkg-config docs)
string(REPLACE ";" "," reqlibname "${reqlibname}")
# Call the swig link library method for each library
if (BUILDSWIGNODE)
swig_link_libraries (jsupm_${libname} ${_library})
endif()
# Build python2 AND/OR python3 modules
if (BUILDSWIGPYTHON)
if (PYTHON2LIBS_FOUND)
swig_link_libraries (pyupm_${libname}-python2 ${_library})
endif (PYTHON2LIBS_FOUND)
if (PYTHON3LIBS_FOUND)
swig_link_libraries (pyupm_${libname}-python3 ${_library})
endif (PYTHON3LIBS_FOUND)
endif()
if (BUILDSWIGJAVA)
swig_link_libraries (javaupm_${libname} ${_library})
endif()
endforeach(_library ${ARGN})
endmacro (upm_target_link_libraries target_name)
# Keep some stats
string(REGEX MATCH "-c$" _isC ${target})
if (_isC)
MATH(EXPR n_ctargets "${n_ctargets}+1")
else ()
MATH(EXPR n_cxxtargets "${n_cxxtargets}+1")
endif()
upm_create_install_pkgconfig (${libname}.pc ${LIB_INSTALL_DIR}/pkgconfig)
endif (TARGET ${target})
endforeach (target ${UPM_LIBRARY_TARGETS})
message(STATUS "\tFound C libraries: ${n_ctargets}")
message(STATUS "\tFound CXX libraries: ${n_cxxtargets}")
message(STATUS "Generating pkg-config files for ${n_targets} libraries... Complete")
endfunction (_gen_pkg_config_per_target)
function (_get_target_dependency_interface_include_dirs target varIncludeDirs)
set (${varIncludeDirs} "")
# For each LINK_LIBRARIES of target
get_property(_targets TARGET ${target} PROPERTY LINK_LIBRARIES)
foreach (_target ${_targets})
# If the target currently exists, use its include directories
if (TARGET ${_target})
get_property(_tmp_prop_val TARGET ${_target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND ${varIncludeDirs} ${_tmp_prop_val})
# It's possible that the target does NOT exist yet, attempt to build an include directory
else ()
# Guess at a src dir name
file (TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/src/${_target}" _dirname)
if (EXISTS ${_dirname})
list(APPEND ${varIncludeDirs} ${_dirname})
else ()
endif (EXISTS ${_dirname})
endif (TARGET ${_target})
endforeach (_target ${_targets})
set(${varIncludeDirs} "${${varIncludeDirs}}" PARENT_SCOPE)
endfunction (_get_target_dependency_interface_include_dirs target varIncludeDirs)
# Create a single swig target for python
macro(_upm_swig_python)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
# Transitive headers don't appear to get picked up by swig_add_module call for
# wrapper generation. Get them manually and add them here.
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..
${DEPEND_DIRS})
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
@ -86,11 +140,12 @@ macro(_upm_swig_python)
# Get target library name (example _pyupm_a110x-python2)
set (python_wrapper_target ${SWIG_MODULE_${python_wrapper_name}_REAL_NAME})
swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES} ${libname})
swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname})
target_include_directories (${python_wrapper_target}
PUBLIC
"${PYTHON_INCLUDE_PATH}"
"${PYTHON_INCLUDE_DIRS}")
"${PYTHON_INCLUDE_DIRS}"
${DEPEND_DIRS})
# Turn off flags for wrapper
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
@ -170,17 +225,23 @@ macro(upm_swig_node)
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
endwhile ()
# Transitive headers don't appear to get picked up by swig_add_module call for
# wrapper generation. Get them manually and add them here.
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}/..
${DEPEND_DIRS}
)
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i)
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES} ${libname})
swig_link_libraries (jsupm_${libname} ${NODE_LIBRARIES} ${libname})
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PUBLIC
"${NODE_INCLUDE_DIRS}"
${DEPEND_DIRS}
)
# Turn off flags for wrapper
@ -221,23 +282,35 @@ endmacro(upm_swig_node)
macro(upm_swig_java)
# Skip if the libname is in the blacklist
if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
# Transitive headers don't appear to get picked up by swig_add_module call for
# wrapper generation. Get them manually and add them here.
_get_target_dependency_interface_include_dirs(${libname} DEPEND_DIRS)
include_directories (
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
${CMAKE_CURRENT_SOURCE_DIR}/..
${DEPEND_DIRS}
)
set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src")
swig_add_module (javaupm_${libname} java javaupm_${libname}.i)
swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARIES} ${MRAA_LIBRARIES} ${JAVA_LIBRARIES} ${libname})
# NOTE, ${module_src} is ONLY needed when swig'ing to JAVA. This is
# because *some* upm libraries have ifdef's for JAVA and SWIG in their
# source (cxx) which builds in different functionality. Because of this,
# the source must be added when building the JAVA wrapper.
# See issue #518
# TODO: Fix this somehow
swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src})
swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LIBRARY} ${JAVA_LIBRARIES} ${libname} interfaces)
target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
PUBLIC
"${JAVA_INCLUDE_DIRS}"
"${JAVA_INCLUDE_PATH}"
${DEPEND_DIRS}
)
set_target_properties (javaupm_${libname} PROPERTIES
COMPILE_FLAGS "-fpermissive -DJAVACALLBACK"
COMPILE_FLAGS "-fpermissive -DJAVACALLBACK -DSWIGJAVA"
PREFIX "lib"
SUFFIX ".so"
)
@ -322,7 +395,11 @@ if (BUILDSWIGNODE)
"${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
foreach (srcfile ${srcfiles})
file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
if (${srcfile} MATCHES ".c" OR ${srcfile} MATCHES ".cxx" OR ${srcfile} MATCHES ".cpp")
if(${srcfile} MATCHES ".c$")
get_filename_component(csource ${srcfile} NAME_WE)
file (RENAME ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/${csource}_c.c)
set (upm_LIB_SRCS_GYP "'${csource}_c.c',\n${upm_LIB_SRCS_GYP}")
elseif (${srcfile} MATCHES ".cxx$" OR ${srcfile} MATCHES ".cpp$")
set (upm_LIB_SRCS_GYP "'${srcfile}',\n${upm_LIB_SRCS_GYP}")
endif ()
endforeach ()
@ -338,10 +415,10 @@ if (BUILDSWIGNODE)
# Utilities and interfaces
file (COPY ${CMAKE_SOURCE_DIR}/src/utilities DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
file (COPY ${CMAKE_SOURCE_DIR}/src/upm DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
file (COPY ${CMAKE_SOURCE_DIR}/src/interfaces DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
set (upm_LIB_SRCS_GYP "'utilities/upm_utilities.c',\n${upm_LIB_SRCS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'utilities',\n${upm_LIB_INCLUDE_DIRS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'upm',\n${upm_LIB_INCLUDE_DIRS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'interfaces',\n${upm_LIB_INCLUDE_DIRS_GYP}")
# Add readme, package.json for NPM and node-gyp config file
configure_file (${PROJECT_SOURCE_DIR}/src/binding.gyp.in ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/binding.gyp @ONLY)
@ -384,6 +461,9 @@ function (UPM_MIXED_MODULE_INIT)
# C_SRC -> List of C source files
# FTI_SRC -> List of C FTI source files
# REQUIRES -> List requires libraries for pkg-config
# Exports to PARENT scope:
# libname -> CXX target name
# libnamec -> C target name (if used)
set (options CPP_WRAPS_C)
set (oneValueArgs NAME DESCRIPTION)
set (multiValueArgs CPP_HDR CPP_SRC C_HDR C_SRC FTI_SRC FTI_HDR REQUIRES)
@ -393,6 +473,9 @@ function (UPM_MIXED_MODULE_INIT)
# Set the description
set (libdescription ${UPM_MIXED_MODULE_INIT_DESCRIPTION})
# Make sure REQUIRES is a list
separate_arguments(UPM_MIXED_MODULE_INIT_REQUIRES)
# Always build C libs first
if (UPM_MIXED_MODULE_INIT_C_SRC)
set (libname ${UPM_MIXED_MODULE_INIT_NAME})
@ -400,11 +483,9 @@ function (UPM_MIXED_MODULE_INIT)
set (module_src ${UPM_MIXED_MODULE_INIT_C_SRC})
set (module_hpp ${UPM_MIXED_MODULE_INIT_C_HDR})
# Create the reqlibname list
string(REPLACE ";" " " reqlibname "${UPM_MIXED_MODULE_INIT_REQUIRES}")
# Append upmc-utilities to the reqlibs (but not on upm-utilities itself)
# Append the utilities-c target to each c target
if (NOT ${libname} MATCHES "utilities")
set (reqlibname "${reqlibname} upmc-utilities")
list (APPEND UPM_MIXED_MODULE_INIT_REQUIRES utilities-c)
endif()
# If building FTI, and FTI src exists, add it in
@ -419,7 +500,7 @@ function (UPM_MIXED_MODULE_INIT)
# Set a flag to tell upm_module_init that it's building a C library
set (IS_C_LIBRARY TRUE)
upm_module_init()
upm_module_init(${UPM_MIXED_MODULE_INIT_REQUIRES})
# add upmc-utilities as a dependancy to all C libs (but NOT to the
# utilities lib itself)
@ -439,13 +520,10 @@ function (UPM_MIXED_MODULE_INIT)
set (module_src ${UPM_MIXED_MODULE_INIT_CPP_SRC})
set (module_hpp ${UPM_MIXED_MODULE_INIT_CPP_HDR})
# Create the reqlibname list
string(REPLACE ";" " " reqlibname "${UPM_MIXED_MODULE_INIT_REQUIRES}")
# Reset the libname (upm_module_init can change it)
set (libname ${UPM_MIXED_MODULE_INIT_NAME})
unset (IS_C_LIBRARY)
upm_module_init()
upm_module_init(${UPM_MIXED_MODULE_INIT_REQUIRES})
# If the C++ wraps the C target, add the C target as a dependency
if (UPM_MIXED_MODULE_INIT_CPP_WRAPS_C)
@ -454,32 +532,47 @@ function (UPM_MIXED_MODULE_INIT)
## "export" the logical C++ lib target for the calling module's
## CMakeLists.txt
set (libnamecxx ${libname} PARENT_SCOPE)
set (libname ${libname} PARENT_SCOPE)
endif (BUILDCPP AND UPM_MIXED_MODULE_INIT_CPP_HDR)
endfunction (UPM_MIXED_MODULE_INIT)
macro(upm_module_init)
function(upm_module_init)
set (basename ${libname})
# If this is a C library, handle different collateral naming
if (IS_C_LIBRARY)
set (libname ${libname}-c)
# If this is a C library, export C library target name to parent's libname
set (libname ${libname} PARENT_SCOPE)
set (libprefix upmc-)
set (pcname upmc-${basename}.pc)
else ()
set (libprefix upm-)
set (pcname upm-${basename}.pc)
endif (IS_C_LIBRARY)
link_directories (${MRAA_LIBDIR})
# Create the target library from src/hdrs
add_library (${libname} SHARED ${module_src} ${module_hpp})
# Specify the current source directory as an INTERFACE include dir.
# This allows for transitive header dependencies via target_link_libraries
target_include_directories(${libname} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
# Iterate over all arguments passed to upm_module_init.
# 1. Add them via target_link_libraries
# 2. If mraa, then add a link and include dependency
foreach (linkflag ${ARGN})
target_link_libraries (${libname} ${linkflag})
# Add necessary MRAA components IF the target requires it
if (${linkflag} MATCHES mraa)
target_link_libraries (${libname} ${MRAA_LIBRARY})
# Always add a PUBLIC dependency to MRAA include dirs
target_include_directories (${libname} PUBLIC ${MRAA_INCLUDE_DIRS})
else ()
# Else, add the linkflag directly
target_link_libraries (${libname} ${linkflag})
endif (${linkflag} MATCHES mraa)
endforeach ()
include_directories (${MRAA_INCLUDE_DIRS} . ..)
target_link_libraries (${libname} ${MRAA_LIBRARIES})
set_target_properties(
${libname}
PROPERTIES PREFIX lib${libprefix}
@ -487,7 +580,6 @@ macro(upm_module_init)
SOVERSION ${upm_VERSION_MAJOR}
VERSION ${upm_VERSION_STRING}
)
upm_create_install_pkgconfig (${pcname} ${LIB_INSTALL_DIR}/pkgconfig)
# Don't SWIG C
if (NOT IS_C_LIBRARY)
@ -502,19 +594,28 @@ macro(upm_module_init)
endif (BUILDSWIGJAVA)
endif (NOT IS_C_LIBRARY)
# Add this target to the list of library target names
set(UPM_LIBRARY_TARGETS ${UPM_LIBRARY_TARGETS} ${libname} CACHE INTERNAL "List of ALL target names")
set_target_properties(${libname} PROPERTIES PKG_CONFIG_NAME "${libprefix}${basename}")
set_target_properties(${libname} PROPERTIES PKG_CONFIG_DESCRIPTION "${libdescription}")
set_target_properties(${libname} PROPERTIES PKG_EXT_REQ_LIBS "${reqlibname}")
# Skip doxygen run on C (for now)
if (BUILDDOC AND NOT IS_C_LIBRARY)
upm_doxygen()
endif()
# Install target library to lib dir
install (TARGETS ${libname} DESTINATION ${LIB_INSTALL_DIR})
# Install header files to include/upm/
install (FILES ${module_hpp} DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}")
endif()
endmacro(upm_module_init)
endfunction(upm_module_init)
# Top-level module init
if (BUILDSWIGPYTHON)
@ -546,11 +647,15 @@ elseif (BUILDSWIGPYTHON)
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub")
endif (BUILDDOC AND BUILDSWIGPYTHON)
# Provide a cached variable to save a list of library target names
set(UPM_LIBRARY_TARGETS "" CACHE INTERNAL "List of ALL target names")
# Add subdirectories from MODULE_LIST if defined
# Example -DMODULE_LIST="dfrph;rotaryencoder"
if (MODULE_LIST)
set(SUBDIRS ${MODULE_LIST})
set(SUBDIRS ${SUBDIRS} upm)
# Add interfaces directory
set(SUBDIRS ${SUBDIRS} interfaces)
else()
# Otherwise, add all subdirectories
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
@ -568,3 +673,6 @@ foreach(subdir ${SUBDIRS})
add_subdirectory(${subdir})
endif()
endforeach()
# Generate a pkg-config file (.pc) per target
_gen_pkg_config_per_target()

View File

@ -1,5 +1,5 @@
upm_mixed_module_init (NAME a110x
DESCRIPTION "Hall effect sensor"
DESCRIPTION "Hall Effect Sensor"
C_HDR a110x.h
C_SRC a110x.c
CPP_HDR a110x.hpp

View File

@ -36,7 +36,7 @@ namespace upm {
/**
* @library a110x
* @sensor a110x
* @comname A110X Hall Effect Sensor
* @comname Hall Effect Sensor
* @altname Grove Hall Sensor
* @altid A1101, A1102, A1103, A1004, A1106
* @type electric

View File

@ -1,5 +1,5 @@
upm_mixed_module_init (NAME ad8232
DESCRIPTION "Single lead heart rate monitor"
DESCRIPTION "Single Lead Heart Rate Monitor"
C_HDR ad8232.h
C_SRC ad8232.c
CPP_HDR ad8232.hpp

View File

@ -43,7 +43,7 @@ namespace upm {
/**
* @library ad8232
* @sensor ad8232
* @comname AD8232 Heart Rate Monitor
* @comname Single Lead Heart Rate Monitor
* @type medical
* @man sparkfun
* @web https://www.sparkfun.com/products/12650

View File

@ -2,8 +2,4 @@ set (libname "adafruitms1438")
set (libdescription "Module for the Adafruit Motor Shield 1438")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
set (reqlibname "upm-pca9685")
include_directories("../pca9685")
upm_module_init()
add_dependencies(${libname} pca9685)
upm_target_link_libraries(${libname} pca9685)
upm_module_init(pca9685)

View File

@ -46,7 +46,7 @@ namespace upm {
/**
* @library adafruitms1438
* @sensor adafruitms1438
* @comname Adafruit Motor Shield
* @comname Module for the Adafruit Motor Shield 1438
* @type motor
* @man adafruit
* @web http://www.adafruit.com/products/1438

View File

@ -1,5 +1,5 @@
set (libname "adafruitss")
set (libdescription "Adafruit pca9685 based 16-channel servo shield")
set (libdescription "Adafruit Servo Shield")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init()
upm_module_init(mraa)

View File

@ -1,5 +1,5 @@
set (libname "adc121c021")
set (libdescription "Adc121c021 I2C ADC converter module")
set (libdescription "I2C 12-bit Analog to Digital Converter with Alert Pin")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init()
upm_module_init(mraa)

View File

@ -72,7 +72,7 @@ namespace upm {
/**
* @library adc121c021
* @sensor adc121c021
* @comname ADC121C021 Analog-to-Digital Converter
* @comname I2C 12-bit Analog to Digital Converter with Alert Pin
* @altname Grove I2C ADC
* @type electric
* @man seeed

View File

@ -1,5 +1,5 @@
set (libname "adis16448")
set (libdescription "High-Precision IMU")
set (libdescription "Industrial Grade Ten Degrees of Freedom Inertial Sensor")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init()
upm_module_init(mraa)

View File

@ -92,7 +92,7 @@ namespace upm {
/**
* @library adis16448
* @sensor adis16448
* @comname ADIS16448 Accelerometer
* @comname Industrial Grade Ten Degrees of Freedom Inertial Sensor
* @type accelerometer
* @man generic
* @web http://www.analog.com/en/products/sensors/isensor-mems-inertial-measurement-units/adis16448.html

View File

@ -1,8 +1,8 @@
set (libname "ads1x15")
set (libdescription "Analog to digital converter")
set (libdescription "Texas Instruments I2C ADC Library")
set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx)
set (module_hpp ${libname}.hpp ads1115.hpp ads1015.hpp)
upm_module_init()
upm_module_init(interfaces mraa)
compiler_flag_supported(CXX is_supported -Wno-overloaded-virtual)
if (is_supported)
target_compile_options(${libname} PUBLIC -Wno-overloaded-virtual)

View File

@ -21,7 +21,11 @@
* 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 "ads1015.hpp"
#include "mraa/i2c.hpp"
using namespace upm;

View File

@ -26,7 +26,7 @@
#pragma once
#include "ads1x15.hpp"
#include "upm/iADC.hpp"
#include "interfaces/iADC.hpp"
#define ADS1015_VREF 2.048
@ -57,11 +57,11 @@ namespace upm {
/**
* @library ads1x15
* @sensor ADS1015
* @comname ADS1015 ADC
* @comname 12-bit ADC with Integrated MUX, PGA, Comparator, Oscillator, and Reference
* @type electric
* @man ti adafruit
* @con i2c
* @web web http://www.ti.com/lit/ds/symlink/ads1015.pdf
* @web http://www.ti.com/lit/ds/symlink/ads1015.pdf
*
* @brief API for ADS1015
*

View File

@ -57,7 +57,7 @@ namespace upm {
/**
* @library ads1x15
* @sensor ADS1115
* @comname ADS1115 ADC
* @comname 16-bit ADC with Integrated MUX, PGA, Comparator, Oscillator, and Reference
* @type electric
* @man ti adafruit
* @con i2c

View File

@ -24,6 +24,7 @@
#include "ads1x15.hpp"
#include "mraa/i2c.hpp"
#include <unistd.h>
#include <syslog.h>

View File

@ -26,8 +26,8 @@
#include <iostream>
#include <string>
#include "mraa.hpp"
#include "mraa/i2c.hpp"
namespace mraa {class I2c;}
/*=========================================================================
I2C ADDRESS/BITS
@ -419,6 +419,6 @@ namespace upm {
void updateConfigRegister(uint16_t update, bool read = false);
uint16_t swapWord(uint16_t value);
mraa::I2c* i2c;
mraa::I2c* i2c;
};}

View File

@ -8,6 +8,8 @@
#include "ads1115.hpp"
%}
%include "iModuleStatus.hpp"
%include "iADC.hpp"
%include "ads1x15.hpp"
%include "ads1015.hpp"
%include "ads1115.hpp"
@ -23,4 +25,4 @@
System.exit(1);
}
}
%}
%}

View File

@ -1,6 +1,9 @@
%module jsupm_ads1x15
%include "../upm.i"
%include "iModuleStatus.hpp"
%include "iADC.hpp"
%include "ads1x15.hpp"
%{
#include "ads1x15.hpp"
@ -14,4 +17,4 @@
%include "ads1115.hpp"
%{
#include "ads1115.hpp"
%}
%}

View File

@ -5,6 +5,9 @@
%feature("autodoc", "3");
%include "iModuleStatus.hpp"
%include "iADC.hpp"
%include "ads1x15.hpp"
%{
#include "ads1x15.hpp"
@ -18,4 +21,4 @@
%include "ads1115.hpp"
%{
#include "ads1115.hpp"
%}
%}

View File

@ -1,5 +1,5 @@
set (libname "adxl335")
set (libdescription "Adxl335 grove 3-axis anaolog accelerometer")
set (libdescription "Low-power, 3-axis +/- 3 g Accelerometer")
set (module_src ${libname}.cxx)
set (module_hpp ${libname}.hpp)
upm_module_init()
upm_module_init(mraa)

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