mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
b9988469ba | |||
4fff3a500d | |||
a53ab5cb80 | |||
bd8104f6ee | |||
dbac88d225 | |||
70bcdfefa4 | |||
762c28f000 | |||
283fce619e | |||
7a5c8a6cb3 | |||
4342b880b9 | |||
ddddbd024d | |||
67e0ceb48d | |||
2298846fef | |||
567476b89a | |||
d345006c03 | |||
7f0e03b0e3 | |||
08a46ee8e6 | |||
fb88fda5cb | |||
90d856d128 | |||
d2e0327c30 | |||
2e97aa9979 | |||
cdb75e8c13 | |||
dac31a0347 | |||
0749f130e1 | |||
1bbb9386b7 | |||
f914159e21 | |||
849711c47d | |||
0a91eb0b46 | |||
806b00c2b7 | |||
e8151640a1 | |||
123e611f45 | |||
8d5278b9d4 | |||
ab96e8f3a3 | |||
d3b864362d | |||
6769d976a0 | |||
bd47b9ed45 | |||
6ea65a16a4 | |||
0849fbc674 | |||
e25be536a1 | |||
a70629e3b2 | |||
fed0478dc9 | |||
fcb4d9d36d | |||
5eb8af6d70 | |||
3c93eba4af | |||
78953b110f | |||
53124e9704 | |||
cde747439f | |||
dfc7a710d4 | |||
130cb822e4 | |||
c057fa6708 | |||
c6ad8cb5ee | |||
024b43dfa3 | |||
6667646d32 | |||
e1e9067744 | |||
c4656bf8ba | |||
232089f400 | |||
09144e712b | |||
2d94c2ed90 | |||
91652a2da5 | |||
929244b27a | |||
9a4f0cae0c | |||
402de082d3 | |||
ad275e1d41 | |||
d4559878df | |||
971cb4ab51 |
@ -15,7 +15,7 @@ compiler:
|
||||
- clang
|
||||
- gcc
|
||||
install:
|
||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-dev/swig
|
||||
- sudo add-apt-repository --yes ppa:rosmo/swig3.0.7
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y --force-yes -qq swig3.0 git
|
||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||
@ -36,7 +36,7 @@ script:
|
||||
- sudo make install
|
||||
- sudo ldconfig
|
||||
# Build/install UPM
|
||||
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA -DBUILDTESTS=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
|
||||
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDTESTS=ON -DBUILDFTI=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
@ -8,8 +8,7 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
|
||||
option (BUILDSWIGPYTHON "Build swig python modules" ON)
|
||||
option (BUILDSWIGNODE "Build swig node modules" ON)
|
||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||
option (BUILDEXAMPLES "Build C/C++ example binaries" OFF)
|
||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (NPM "Generate NPM/GYP tarballs" OFF)
|
||||
@ -119,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)
|
||||
@ -139,6 +140,15 @@ if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
endif (BUILDSWIGNODE)
|
||||
|
||||
# Find JAVA/JNI
|
||||
if (BUILDSWIGJAVA)
|
||||
find_package (Java REQUIRED)
|
||||
find_package (JNI REQUIRED)
|
||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
||||
# Also, get full path to the mraajava library
|
||||
find_library(MRAAJAVA_LIBRARY NAMES mraajava PATHS ${MRAA_LIBDIR} NO_DEFAULT_PATH)
|
||||
endif (BUILDSWIGJAVA)
|
||||
|
||||
# Find swig if any wrapper is enabled
|
||||
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
||||
find_package (SWIG 3.0.5 REQUIRED)
|
||||
@ -187,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.1-dirty")
|
||||
set (VERSION "v1.1.0")
|
||||
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
|
||||
"${VERSION}). Check that git is installed and this is a valid git repo.")
|
||||
endif ()
|
||||
@ -381,7 +391,6 @@ endif()
|
||||
|
||||
if (RPM)
|
||||
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
|
||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_PACKAGE_NAME "upm")
|
||||
set(upm_PACKAGE_ON_TAG ".")
|
||||
@ -418,7 +427,8 @@ if(BUILDEXAMPLES)
|
||||
endif(BUILDCPP)
|
||||
endif()
|
||||
|
||||
if(BUILDJAVAEXAMPLES)
|
||||
# Build java examples
|
||||
if(BUILDSWIGJAVA AND BUILDEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
|
3
LICENSE
3
LICENSE
@ -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
|
||||
|
30
README.md
30
README.md
@ -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
|
||||
==============
|
||||
|
||||
|
@ -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.
|
||||
|
@ -80,14 +80,10 @@ Building documentation
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDDOC=ON
|
||||
~~~~~~~~~~~~~
|
||||
Build C++ example binaries
|
||||
Build C/C++/JAVA examples
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDEXAMPLES=ON
|
||||
~~~~~~~~~~~~~
|
||||
Build Java examples
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDJAVAEXAMPLES=ON
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
If you intend to turn on all the options and build everything at once
|
||||
(C++, Java, Node, Python and Documentation) you will have to edit the
|
||||
|
@ -4,6 +4,26 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### v1.1.0
|
||||
|
||||
* Reworked cmake handling of internal and external dependencies
|
||||
* Documentation improvements for sensor names, sensor descriptions, external
|
||||
contributor guides and added new section on installing UPM on a supported OS
|
||||
* Fixed issues with C11 builds on some WRLinux gateways and Debian systems
|
||||
* New examples and functionality for speaker and ads1x15 modules
|
||||
* Modified JAVA builds to ensure the SWIG generated wrappers include all
|
||||
functionality and typemaps
|
||||
* New sensors: mcp2515, max30100, uartat, le910
|
||||
|
||||
### v1.0.2
|
||||
|
||||
* Minor cmake changes for Java builds and Java examples are now toggled with
|
||||
the same BUILDEXAMPLES cmake switch
|
||||
* Made some improvements in the utilities class for our C drivers
|
||||
* Fixed issue with some drivers not being usable on subplatforms due to pin
|
||||
numbers using uint8 type
|
||||
* New sensors: ims, ecezo, mb704x, rf22
|
||||
|
||||
### v1.0.1
|
||||
|
||||
* Warnings as errors enabled for C/CXX (fixed warnings from -Wall and others)
|
||||
|
@ -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
348
docs/guidelines.md
Normal 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
BIN
docs/images/es9257.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
docs/images/ims.png
Normal file
BIN
docs/images/ims.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
BIN
docs/images/max30100.png
Normal file
BIN
docs/images/max30100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
BIN
docs/images/rf22.jpg
Normal file
BIN
docs/images/rf22.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
77
docs/installing.md
Normal file
77
docs/installing.md
Normal 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>');
|
||||
```
|
@ -24,6 +24,7 @@ hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
|
||||
hm11.cxx HM11Sample.java hm11.js hm11.py
|
||||
hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py
|
||||
htu21d.cxx HTU21DSample.java htu21d.js htu21d.py
|
||||
ims.cxx IMS_Example.java ims.js ims.py
|
||||
itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py
|
||||
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py
|
||||
joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py
|
||||
|
@ -322,6 +322,13 @@ add_example (dfrorp)
|
||||
add_example (dfrec)
|
||||
add_example (sht1x)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
add_example (rf22-server)
|
||||
add_example (rf22-client)
|
||||
add_example (mcp2515)
|
||||
add_example (max30100)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
@ -364,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
102
examples/c++/ads1015.cxx
Normal 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
105
examples/c++/ads1115.cxx
Normal 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;
|
||||
}
|
||||
|
@ -316,5 +316,5 @@ int main()
|
||||
|
||||
delete ads;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -49,9 +49,6 @@ int main(int argc, char **argv)
|
||||
// Instantiate an DS18B20 instance using the default values (uart 0)
|
||||
upm::DS18B20 sensor;
|
||||
|
||||
// locate and setup our devices
|
||||
sensor.init();
|
||||
|
||||
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
||||
cout << endl;
|
||||
|
||||
@ -59,18 +56,26 @@ int main(int argc, char **argv)
|
||||
if (!sensor.devicesFound())
|
||||
return 1;
|
||||
|
||||
// update and print available values every second
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values for the first sensor
|
||||
sensor.update(0);
|
||||
// update our values for all of the detected sensors
|
||||
sensor.update(-1);
|
||||
|
||||
// we show both C and F for temperature for the first sensor
|
||||
cout << "Temperature: " << sensor.getTemperature(0)
|
||||
<< " C / " << sensor.getTemperature(0, true) << " F"
|
||||
<< endl;
|
||||
// we show both C and F for temperature for the sensors
|
||||
int i;
|
||||
for (i=0; i<sensor.devicesFound(); i++)
|
||||
{
|
||||
cout << "Device "
|
||||
<< i
|
||||
<< ": Temperature: "
|
||||
<< sensor.getTemperature(i)
|
||||
<< " C / " << sensor.getTemperature(i, true) << " F"
|
||||
<< endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
81
examples/c++/ecezo.cxx
Normal file
81
examples/c++/ecezo.cxx
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <ecezo.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
upm::ECEZO *sensor = new upm::ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// upm::ECEZO *sensor = new upm::ECEZO(0, 0x64, true);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
sensor->update();
|
||||
|
||||
cout << "EC "
|
||||
<< sensor->getEC()
|
||||
<< " uS/cm, TDS "
|
||||
<< sensor->getTDS()
|
||||
<< " mg/L, Salinity "
|
||||
<< sensor->getSalinity()
|
||||
<< " PSS-78, SG "
|
||||
<< sensor->getSG()
|
||||
<< endl;
|
||||
|
||||
upm_delay(5);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -32,16 +32,17 @@ main(int argc, char **argv)
|
||||
//! [Interesting]
|
||||
// Instantiate on I2C
|
||||
upm::Hmc5883l* compass = new upm::Hmc5883l(0);
|
||||
int16_t *pos;
|
||||
|
||||
compass->set_declination(0.2749); // Set your declination from true north in radians
|
||||
compass->set_declination(0.2749); // Set your declination from
|
||||
// true north in radians
|
||||
|
||||
// Print out the coordinates, heading, and direction every second
|
||||
while(true){
|
||||
compass->update(); // Update the coordinates
|
||||
pos = compass->coordinates();
|
||||
const int16_t *pos = compass->coordinates();
|
||||
fprintf(stdout, "coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
|
||||
fprintf(stdout, "heading: %5.2f direction: %3.2f\n", compass->heading(), compass->direction());
|
||||
fprintf(stdout, "heading: %5.2f direction: %3.2f\n",
|
||||
compass->heading(), compass->direction());
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
69
examples/c++/ims.cxx
Normal file
69
examples/c++/ims.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ims.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||
upm::IMS sensor(0);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
std::cout << "Version: "
|
||||
<< sensor.get_version()
|
||||
<< " light: "
|
||||
<< sensor.get_light()
|
||||
<< " moisture: "
|
||||
<< sensor.get_moisture()
|
||||
<< " temp: "
|
||||
<< sensor.get_temperature()
|
||||
<< " C"
|
||||
<< std::endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
175
examples/c++/le910.cxx
Normal file
175
examples/c++/le910.cxx
Normal 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
99
examples/c++/max30100.cxx
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "max30100.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
// Example Callback handler
|
||||
class mycallback : public Callback
|
||||
{
|
||||
public:
|
||||
virtual void run(max30100_value samp)
|
||||
{
|
||||
std::cout << "My callback sample IR: "
|
||||
<< samp.IR << " R: " << samp.R << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MAX30100 instance using i2c bus 0
|
||||
upm::MAX30100 sensor(0);
|
||||
|
||||
// Create an instance of the Callback class
|
||||
mycallback cb;
|
||||
|
||||
// Read the temperature and version
|
||||
std::cout << "Temperature: " << sensor.temperature() << " C" << std::endl;
|
||||
std::cout << "Version: " << sensor.version() << std::endl;
|
||||
|
||||
// Set high-res (50 Hz, 16-bit)
|
||||
sensor.high_res_enable(true);
|
||||
|
||||
// Set to sample SpO2
|
||||
sensor.mode(MAX30100_MODE_SPO2_EN);
|
||||
|
||||
// Read continuously, stepping up the LED current every second,
|
||||
// us GPIO 0 as the interrupt pin
|
||||
sensor.sample_continuous(0, false, &cb);
|
||||
for (int i = MAX30100_LED_CURRENT_0_0_MA;
|
||||
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
|
||||
{
|
||||
// Toggle the LED current
|
||||
std::cout << "Setting LED current = " << i << std::endl;
|
||||
|
||||
sensor.current((MAX30100_LED_CURRENT)i, (MAX30100_LED_CURRENT)i);
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
// Read individual samples
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
max30100_value val = sensor.sample();
|
||||
std::cout << "Single value IR: " << val.IR << " R: " << val.R << std::endl;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
70
examples/c++/mb704x.cxx
Normal file
70
examples/c++/mb704x.cxx
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <mb704x.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
upm::MB704X *sensor = new upm::MB704X();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Range: "
|
||||
<< sensor->getRange()
|
||||
<< " cm"
|
||||
<< endl;
|
||||
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
125
examples/c++/mcp2515-txrx.cxx
Normal file
125
examples/c++/mcp2515-txrx.cxx
Normal 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
79
examples/c++/mcp2515.cxx
Normal 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;
|
||||
}
|
@ -159,5 +159,5 @@ int main()
|
||||
|
||||
}while (command != -1 );
|
||||
//! [Interesting]
|
||||
return MRAA_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,5 +74,5 @@ int main()
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
72
examples/c++/rf22-client.cxx
Normal file
72
examples/c++/rf22-client.cxx
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Kiveisha Yevgeniy
|
||||
* Copyright (c) 2015-2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "rf22.hpp"
|
||||
|
||||
bool amWorking = true;
|
||||
|
||||
void
|
||||
sig_handler (int signo) {
|
||||
if (signo == SIGINT) {
|
||||
amWorking = false;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
int
|
||||
main (int argc, char ** argv) {
|
||||
// SPI bus 0, CS pin 10, INTR pin 2
|
||||
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
|
||||
|
||||
if (!rf22->init()) {
|
||||
std::cout << "RF22 init failed" << std::endl;
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
uint8_t buf[RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
signal (SIGINT, sig_handler);
|
||||
while (amWorking) {
|
||||
std::cout << "Sending to rf22_server" << std::endl;
|
||||
// Send a message to rf22_server
|
||||
rf22->send(data, sizeof(data));
|
||||
rf22->waitPacketSent();
|
||||
// Now wait for a reply
|
||||
|
||||
rf22->waitAvailableTimeout(1000000);
|
||||
|
||||
if (rf22->recv(buf, &len)) {
|
||||
std::cout << "got response: " << (char*)buf << std::endl;
|
||||
} else {
|
||||
std::cout << "!!! NO RESPONSE !!!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Exit 'rfm22-client'" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
73
examples/c++/rf22-server.cxx
Normal file
73
examples/c++/rf22-server.cxx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Kiveisha Yevgeniy
|
||||
* Copyright (c) 2015-2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "rf22.hpp"
|
||||
|
||||
bool amWorking = true;
|
||||
|
||||
void
|
||||
sig_handler (int signo) {
|
||||
if (signo == SIGINT) {
|
||||
amWorking = false;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
int
|
||||
main (int argc, char ** argv) {
|
||||
// SPI bus 0, CS pin 10, INTR pin 2
|
||||
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
|
||||
|
||||
if (!rf22->init()) {
|
||||
std::cout << "RF22 init failed" << std::endl;
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
uint8_t buf[RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
signal (SIGINT, sig_handler);
|
||||
while (amWorking) {
|
||||
// rf22->waitAvailable();
|
||||
rf22->waitAvailableTimeout (500);
|
||||
|
||||
// Should be a message for us now
|
||||
if (rf22->recv(buf, &len)) {
|
||||
std::cout << "got request: " << (char*)buf << std::endl;
|
||||
|
||||
// Send a reply
|
||||
uint8_t data[] = "And hello back to you";
|
||||
rf22->send(data, sizeof(data));
|
||||
rf22->waitPacketSent();
|
||||
} else {
|
||||
// Do whatever you need.
|
||||
}
|
||||
}
|
||||
|
||||
delete rf22;
|
||||
std::cout << "Exit 'rfm22-server'" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
55
examples/c++/speaker_pwm.cxx
Normal file
55
examples/c++/speaker_pwm.cxx
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ macro(add_custom_example example_bin example_src example_module_list)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
if (MODULE_LIST)
|
||||
list(FIND MODULE_LIST ${module}-c index)
|
||||
list(FIND MODULE_LIST ${module} index)
|
||||
if (${index} EQUAL -1)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
@ -136,9 +136,19 @@ add_example (ppd42ns)
|
||||
add_example (guvas12d)
|
||||
add_example (otp538u)
|
||||
add_example (button)
|
||||
add_example (button_intr)
|
||||
add_example (my9221)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
add_example (mcp2515)
|
||||
add_example (max30100)
|
||||
add_example (speaker)
|
||||
add_example (cjq4435)
|
||||
add_example (hmc5883l)
|
||||
add_example (wfs)
|
||||
add_example (enc03r)
|
||||
add_example (nunchuck)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
@ -146,3 +156,7 @@ add_custom_example (lcm1602-i2c-example-c lcm1602-i2c.c lcm1602)
|
||||
add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602)
|
||||
add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220)
|
||||
add_custom_example (md-stepper-example-c md-stepper.c md)
|
||||
add_custom_example (button_intr-example-c button_intr.c button)
|
||||
add_custom_example (mcp2515-txrx-example-c mcp2515-txrx.c mcp2515)
|
||||
add_custom_example (le910-example-c le910.c uartat)
|
||||
add_custom_example (speaker_pwm-example-c speaker_pwm.c speaker)
|
||||
|
82
examples/c/cjq4435.c
Normal file
82
examples/c/cjq4435.c
Normal 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;
|
||||
}
|
@ -56,7 +56,7 @@ int main(int argc, char **argv)
|
||||
|
||||
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
|
||||
|
||||
// update and print available values every second
|
||||
// update and print available values every 2 seconds
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values for all sensors
|
||||
|
85
examples/c/ecezo.c
Normal file
85
examples/c/ecezo.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <ecezo.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
ecezo_context sensor = ecezo_uart_init(0, 9600);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// ecezo_context sensor = ecezo_i2c_init(0, 0x64);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("ecezo_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
if (ecezo_update(sensor))
|
||||
{
|
||||
printf("ecezo_update() failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("EC %f uS/cm, TDS %f mg/L, Salinity %f PSS-78, SG %f\n",
|
||||
ecezo_get_ec(sensor),
|
||||
ecezo_get_tds(sensor),
|
||||
ecezo_get_salinity(sensor),
|
||||
ecezo_get_sg(sensor));
|
||||
}
|
||||
|
||||
upm_delay(5);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
ecezo_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
90
examples/c/enc03r.c
Normal file
90
examples/c/enc03r.c
Normal 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
82
examples/c/hmc5883l.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2017 Intel Corporation.
|
||||
*
|
||||
* Ported based on original C++ code by:
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
|
||||
#include "hmc5883l.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an HMC8883L on I2C bus 0
|
||||
hmc5883l_context sensor = hmc5883l_init(0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("%s: hmc5883l_init() failed\n", __FUNCTION__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
hmc5883l_set_declination(sensor, 0.2749); // Set your declination
|
||||
// from true north in
|
||||
// radians
|
||||
|
||||
// Print out the coordinates, heading, and direction every second
|
||||
while (shouldRun)
|
||||
{
|
||||
hmc5883l_update(sensor); // Update the coordinates
|
||||
const int16_t *pos = hmc5883l_coordinates(sensor);
|
||||
|
||||
printf("coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
|
||||
printf("heading: %5.2f direction: %3.2f\n",
|
||||
hmc5883l_heading(sensor), hmc5883l_direction(sensor));
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
hmc5883l_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
75
examples/c/ims.c
Normal file
75
examples/c/ims.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ims.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
ims_context* sensor = ims_init(0, IMS_ADDRESS_DEFAULT);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("ims_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Every second, sample the sensor outputs
|
||||
while (shouldRun)
|
||||
{
|
||||
uint16_t version, light, moisture, temp;
|
||||
|
||||
if (ims_get_version(sensor, &version) == UPM_SUCCESS &&
|
||||
ims_get_light(sensor, &light) == UPM_SUCCESS &&
|
||||
ims_get_moisture(sensor, &moisture) == UPM_SUCCESS &&
|
||||
ims_get_temperature(sensor, &temp) == UPM_SUCCESS)
|
||||
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
||||
version, light, moisture, temp/10.0);
|
||||
else
|
||||
break;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
printf("Exiting\n");
|
||||
ims_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
169
examples/c/le910.c
Normal file
169
examples/c/le910.c
Normal 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
130
examples/c/max30100.c
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "max30100.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void my_sample_handler(max30100_value sample, void* arg)
|
||||
{
|
||||
printf("My callback sample IR: %d R: %d\n",
|
||||
sample.IR, sample.R);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
max30100_context* sensor = max30100_init(0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("max30100_init() failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get the temperature */
|
||||
float temp;
|
||||
if (max30100_get_temperature(sensor, &temp) != UPM_SUCCESS)
|
||||
{
|
||||
printf("max30100_get_temperature failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
/* Get the version */
|
||||
uint16_t version;
|
||||
if (max30100_get_version(sensor, &version) != UPM_SUCCESS)
|
||||
{
|
||||
printf("max30100_get_version failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
printf("Temperature: %f C\n", temp);
|
||||
printf("Version: 0x%04x\n", version);
|
||||
|
||||
/* Set high-res (50 Hz, 16-bit) */
|
||||
if (max30100_set_high_res(sensor, true) != UPM_SUCCESS)
|
||||
{
|
||||
printf("max30100_set_high_res failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
/* Set to sample SpO2 */
|
||||
if (max30100_set_mode(sensor, MAX30100_MODE_SPO2_EN) != UPM_SUCCESS)
|
||||
{
|
||||
printf("max30100_set_mode failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
/* Read continuously, stepping up the LED current every second,
|
||||
* us GPIO 0 as the interrupt pin */
|
||||
max30100_sample_continuous(sensor, 0, false, &my_sample_handler, sensor);
|
||||
for (int i = MAX30100_LED_CURRENT_0_0_MA;
|
||||
i <= MAX30100_LED_CURRENT_50_0_MA && shouldRun; i++)
|
||||
{
|
||||
/* Toggle the LED current */
|
||||
printf("Setting LED current = %d\n", i);
|
||||
|
||||
if ( max30100_set_current(sensor, (MAX30100_LED_CURRENT)i,
|
||||
(MAX30100_LED_CURRENT)i) != UPM_SUCCESS )
|
||||
{
|
||||
printf("max30100_set_current failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
/* Read individual samples */
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
max30100_value samp;
|
||||
if (max30100_sample(sensor, &samp) != UPM_SUCCESS)
|
||||
{
|
||||
printf("max30100_sample failed\n");
|
||||
goto max30100_exit;
|
||||
}
|
||||
|
||||
printf("Single value IR: %d R: %d\n", samp.IR, samp.R);
|
||||
}
|
||||
|
||||
max30100_exit:
|
||||
//! [Interesting]
|
||||
printf("Exiting\n");
|
||||
max30100_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
77
examples/c/mb704x.c
Normal file
77
examples/c/mb704x.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <mb704x.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor on i2c bus 0, address 112.
|
||||
mb704x_context sensor = mb704x_init(0, 112);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("mb704x_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
int range = mb704x_get_range(sensor);
|
||||
if (range < 0)
|
||||
{
|
||||
printf("Error getting range.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Range: %d cm\n", range);
|
||||
}
|
||||
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
mb704x_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
144
examples/c/mcp2515-txrx.c
Normal file
144
examples/c/mcp2515-txrx.c
Normal 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
101
examples/c/mcp2515.c
Normal 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
84
examples/c/nunchuck.c
Normal 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
55
examples/c/speaker.c
Normal 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
61
examples/c/speaker_pwm.c
Normal 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
91
examples/c/wfs.c
Normal 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;
|
||||
}
|
100
examples/java/Ads1015Sample.java
Normal file
100
examples/java/Ads1015Sample.java
Normal 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);
|
||||
}
|
||||
}
|
103
examples/java/Ads1115Sample.java
Normal file
103
examples/java/Ads1115Sample.java
Normal 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);
|
||||
}
|
||||
}
|
@ -157,6 +157,13 @@ add_example(DFRORP_Example dfrorp)
|
||||
add_example(DFREC_Example dfrec)
|
||||
add_example(SHT1X_Example sht1x)
|
||||
add_example(MS5803_Example ms5803)
|
||||
add_example(ECEZO_Example ecezo)
|
||||
add_example(IMS_Example ims)
|
||||
add_example(MB704X_Example mb704x)
|
||||
add_example(MCP2515_Example mcp2515)
|
||||
add_example(Ads1015Sample ads1x15)
|
||||
add_example(MAX30100_Example max30100)
|
||||
add_example(Ads1115Sample ads1x15)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
@ -178,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)
|
||||
|
60
examples/java/ECEZO_Example.java
Normal file
60
examples/java/ECEZO_Example.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_ecezo.ECEZO;
|
||||
|
||||
public class ECEZO_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
ECEZO sensor = new ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// ECEZO sensor = new ECEZO(0, 0x64, true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
System.out.println("EC "
|
||||
+ sensor.getEC()
|
||||
+ " uS/cm, TDS "
|
||||
+ sensor.getTDS()
|
||||
+ " mg/L, Salinity "
|
||||
+ sensor.getSalinity()
|
||||
+ " PSS-78, SG "
|
||||
+ sensor.getSG());
|
||||
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -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]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
53
examples/java/IMS_Example.java
Normal file
53
examples/java/IMS_Example.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_ims.IMS;
|
||||
|
||||
public class IMS_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using bus 0 and default i2c address
|
||||
IMS sensor = new IMS((short)0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Version: "
|
||||
+ sensor.get_version()
|
||||
+ " light: "
|
||||
+ sensor.get_light()
|
||||
+ " moisture: "
|
||||
+ sensor.get_moisture()
|
||||
+ " temp: "
|
||||
+ sensor.get_temperature()
|
||||
+ " C");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
167
examples/java/LE910_Example.java
Normal file
167
examples/java/LE910_Example.java
Normal 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]
|
||||
}
|
||||
}
|
88
examples/java/MAX30100_Example.java
Normal file
88
examples/java/MAX30100_Example.java
Normal 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());
|
||||
}
|
||||
}
|
||||
|
48
examples/java/MB704X_Example.java
Normal file
48
examples/java/MB704X_Example.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_mb704x.MB704X;
|
||||
|
||||
public class MB704X_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
MB704X sensor = new MB704X();
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Range: "
|
||||
+ sensor.getRange()
|
||||
+ " cm");
|
||||
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
73
examples/java/MCP2515_Example.java
Normal file
73
examples/java/MCP2515_Example.java
Normal 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]
|
||||
}
|
||||
}
|
94
examples/java/MCP2515_TXRX_Example.java
Normal file
94
examples/java/MCP2515_TXRX_Example.java
Normal 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]
|
||||
}
|
||||
}
|
@ -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]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
46
examples/java/SpeakerPWMSample.java
Normal file
46
examples/java/SpeakerPWMSample.java
Normal 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]
|
||||
}
|
||||
|
||||
}
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
70
examples/javascript/ads1015.js
Normal file
70
examples/javascript/ads1015.js
Normal 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);
|
||||
|
74
examples/javascript/ads1115.js
Normal file
74
examples/javascript/ads1115.js
Normal 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);
|
||||
|
@ -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()
|
||||
|
59
examples/javascript/ecezo.js
Normal file
59
examples/javascript/ecezo.js
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_ecezo');
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
var sensor = new sensorObj.ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// var sensor = new sensorObj.ECEZO(0, 0x64, true);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
console.log("EC "
|
||||
+ sensor.getEC()
|
||||
+ " uS/cm, TDS "
|
||||
+ sensor.getTDS()
|
||||
+ " mg/L, Salinity "
|
||||
+ sensor.getSalinity()
|
||||
+ " PSS-78, SG "
|
||||
+ sensor.getSG());
|
||||
|
||||
}, 5000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -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);
|
||||
});
|
||||
|
51
examples/javascript/ims.js
Normal file
51
examples/javascript/ims.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_ims');
|
||||
|
||||
// Instantiate a IMS instance using bus 0 and default i2c address
|
||||
var sensor = new sensorObj.IMS(0);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Version: "
|
||||
+ sensor.get_version()
|
||||
+ " light: "
|
||||
+ sensor.get_light()
|
||||
+ " moisture: "
|
||||
+ sensor.get_moisture()
|
||||
+ " temp: "
|
||||
+ sensor.get_temperature().toFixed(2)
|
||||
+ " C");
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
166
examples/javascript/le910.js
Normal file
166
examples/javascript/le910.js
Normal 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);
|
57
examples/javascript/max30100.js
Normal file
57
examples/javascript/max30100.js
Normal 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);
|
||||
});
|
47
examples/javascript/mb704x.js
Normal file
47
examples/javascript/mb704x.js
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_mb704x');
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
var sensor = new sensorObj.MB704X();
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Range: "
|
||||
+ sensor.getRange()
|
||||
+ " cm");
|
||||
|
||||
}, 500);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
94
examples/javascript/mcp2515-txrx.js
Normal file
94
examples/javascript/mcp2515-txrx.js
Normal 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);
|
||||
});
|
66
examples/javascript/mcp2515.js
Normal file
66
examples/javascript/mcp2515.js
Normal 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);
|
@ -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()
|
||||
{
|
||||
|
47
examples/javascript/speaker_pwm.js
Normal file
47
examples/javascript/speaker_pwm.js
Normal 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);
|
||||
});
|
@ -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
|
||||
|
83
examples/python/ads1015.py
Normal file
83
examples/python/ads1015.py
Normal 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()
|
||||
|
86
examples/python/ads1115.py
Normal file
86
examples/python/ads1115.py
Normal 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()
|
||||
|
@ -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()
|
||||
|
66
examples/python/ecezo.py
Executable file
66
examples/python/ecezo.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_ecezo as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
sensor = sensorObj.ECEZO(0, 9600, False);
|
||||
|
||||
# For I2C, assuming the device is configured for address 0x64 on
|
||||
# I2C bus 0, you could use something like:
|
||||
#
|
||||
# sensor = sensorObj.ECEZO(0, 0x64, True);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
print("EC "
|
||||
+ str(sensor.getEC())
|
||||
+ " uS/cm, TDS "
|
||||
+ str(sensor.getTDS())
|
||||
+ " mg/L, Salinity "
|
||||
+ str(sensor.getSalinity())
|
||||
+ " PSS-78, SG "
|
||||
+ str(sensor.getSG()));
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -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)
|
||||
|
44
examples/python/ims.py
Executable file
44
examples/python/ims.py
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Noel Eck <noel.eck@intel.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_ims
|
||||
|
||||
def main():
|
||||
# Create an instance of the I2C Moisture Sensor
|
||||
# I2C bus 0, default address = 0x20
|
||||
ims = pyupm_ims.IMS(0)
|
||||
|
||||
print ('I2C moisture sensor example...')
|
||||
while (1):
|
||||
try:
|
||||
print ('Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C' \
|
||||
% (ims.get_version(), ims.get_light(), ims.get_moisture(),
|
||||
ims.get_temperature()))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
157
examples/python/le910.py
Executable file
157
examples/python/le910.py
Executable 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
71
examples/python/max30100.py
Executable 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()
|
56
examples/python/mb704x.py
Executable file
56
examples/python/mb704x.py
Executable file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_mb704x as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
# address 112)
|
||||
sensor = sensorObj.MB704X();
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
print("Range: "
|
||||
+ str(sensor.getRange())
|
||||
+ " cm")
|
||||
|
||||
time.sleep(.5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
99
examples/python/mcp2515-txrx.py
Executable file
99
examples/python/mcp2515-txrx.py
Executable 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
79
examples/python/mcp2515.py
Executable 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()
|
@ -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
44
examples/python/speaker_pwm.py
Executable 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()
|
@ -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
46
include/fti/upm_buttons.h
Normal 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
43
include/fti/upm_compass.h
Normal 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_ */
|
42
include/fti/upm_gyroscope.h
Normal file
42
include/fti/upm_gyroscope.h
Normal 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_ */
|
@ -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
|
||||
}
|
||||
|
@ -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) || \
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user