Compare commits

..

110 Commits

Author SHA1 Message Date
39c55b23d9 upm: version 0.6.0
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-25 14:13:16 -07:00
09b0f0adaa .travis.yml: updated cmake and fixed builds
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-25 14:12:53 -07:00
00b0092fc1 cmake: fixed flow for finding libs & include dirs
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-25 14:10:31 -07:00
ec85072011 upm: removed some temporary files left over among sources
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 14:25:13 -07:00
60221dbcd6 cmake: disable TGZ from builds when IPK used
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:23:23 -07:00
a35e58c54c curieimu: Adds examples for both JS and Python that load MRAA Firmata subplatform
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:23:18 -07:00
1b8cb1361c cmake: add workaround for cmake 2.7
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:23:13 -07:00
aeb948282a cmake: Fix issues with node v4/v5
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:23:06 -07:00
1b649021f1 .travis.yml: Make travis test node4/node5 and node0.12
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:23:01 -07:00
10d784ea7e cmake: add BUILDPYTHON3 flag
Use the same methodology as in mraa, by default build for python2, if requested
use python3 for everything

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:18:50 -07:00
a48f457057 FindNode.cmake: Improve FindNode cmake module
Use mraa's FindNode since it's alot more robus and can handle NVM better

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:18:44 -07:00
d8fc664178 curieimu: Add WIP for Python example
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:13:34 -07:00
83b0512ffb Updates implementation and examples to use dynamic-friendly interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:13:29 -07:00
3e7fca21ee Complete accel and gyro implementations for new dynamic friendly interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:13:22 -07:00
8c7d6483d3 curieimu: modify calls to use update methodology to fix python/java/js API
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:13:17 -07:00
22636fb47a curieimu: Make compilation dependant on mraa_firmata_init
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:13:11 -07:00
fb5c809ff8 curieimu: Plugin to interface with the arduino101's IMU
Internal sensor onboard the Curie/Arduino101 can be accessed via Firmata using
this plugin. You will need mraa compiled with -DFIRMATA=ON for this to work and
be using Firmata with the CurieIMU firmata extension for ExtensibleFirmata

Signed-off-by: Ron Evans <ron@hybridgroup.com>
Signed-off-by: Justin Zemlyansky <jlstigman@live.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-03-24 13:11:31 -07:00
0d20cdb25a doxygen: removed Bosch base lib from docs since only used internally
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 12:57:57 -07:00
f2b10afa35 pn532: fix a couple more narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:57 -07:00
56e1d2214f grovescam: fix a couple more narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:49 -07:00
e80e1bda2c am2315: fix narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:40 -07:00
98f9dc54ff zfm20: fix narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:29 -07:00
611f72c491 sx1276: fix narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:20 -07:00
6f68e07aa5 pn532: fix narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:11 -07:00
be34f53a51 grovescam: fix narrowing conversions (c++11)
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:06:03 -07:00
7a133cf891 cmake: Enable C++11 standards support
This patch checks for, and enables C++11 support for building UPM.
This should work for all cmake versions currently supported by UPM
(2.8.11+), and any compiler (clang/gcc) that was released in this
decade.

Support can be specifically disabled by passing '-DENABLECXX11=OFF' to
cmake, though modules requiring this support will not build.

C++11 support is enabled by default.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:05:54 -07:00
49611e5ac0 smartdrive: build example and add manufacturer to list
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:05:07 -07:00
e5385eb510 smartdrive: patch example
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-24 11:00:47 -07:00
de1a46aa59 smartdrive: Replace mraa_result_t by mraa::Result in smartdrive.cxx
Signed-off-by: Oussema Harbi <oussema.elharbi@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:15:43 -07:00
7e402ede34 smartdrive: upm implementation for SmartDrive from openelectronics.com
Signed-off-by: Oussema Harbi <oussema.elharbi@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:13:10 -07:00
4381f8bd2e apa102: addded C++ snippet to documentation
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:05:33 -07:00
757104e013 java: turned on sanity checks in travis
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:04:46 -07:00
6c08313cb7 doxy: Corrected sample mapping
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:03:41 -07:00
6d4714df3c java: Added kxcjk1013 to javaswig blacklist because of unclean bindings. Removed javaupm_kxcjk1013.i and javaupm_nrf8001.i
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:02:37 -07:00
75e42c6731 java: eliminated loadlibrary code from examples
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-23 17:01:19 -07:00
5a5637a431 h803x: Initial implementation
This module implements support for the Veris H8035 and H8036 Energy
Meters.

The H8036 is similar to the H8035, but provides much more data.

The Enercept H8035/H8036 is an innovative three-phase networked
(Modbus RTU) power transducer that combines electronics and high
accuracy industrial grade CTs in a single package. The need for
external electrical enclosures is eliminated, greatly reducing
installation time and cost. Color-coordination between voltage leads
and CTs makes phase matching easy. Additionally, these transducers
automatically detect and compensate for phase reversal, eliminating
the concern of CT load orientation. Up to 63 Transducers can be
daisy-chained on a single RS-485 network.

This module was developed using libmodbus 3.1.2, and the H8035.  The
H8036 has not been tested.  libmodbus 3.1.2 must be present for this
module to build.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 22:58:17 -07:00
e062b9b85c bmi160: Initial implementation
The Bosch BMI160 is a 3-axis Accelerometer and Gyroscope.
Additionally it supports an external Magnetometer, accessed through
the BMI160's register interface.  This driver was developed with a
BMI160 "Shuttle" board, which included a BMM150 Magnetometer.

The device is driven by either 1.8v or 3.3vdc.  This driver
incorporates the Bosch BMI160 driver code at
https://github.com/BoschSensortec/BMI160_driver .

While not all of the functionality of this device is supported
initially, the inclusion of the Bosch driver in the source code
makes it possible to support whatever features are required that
the driver bosch driver itself can support.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 22:52:31 -07:00
b778476597 tex00: Initial Implementation
The Veris TEX00 temperature sensor family is made up of a series of
RTD thermistors in wall mount packaging.

This driver was developed using the TED00, which utilizes a 10K Ohm
Type 2 thermistor.  However, this driver can support the other 12
variants of the TE series as well by providing the correct sensor type
to the class constructor.  These other sensor types have not been
tested.  Only the TED00 hardware was tested with this driver.

This sensor must be connected as part of a voltage divider, with the
balancing resistor ideally matched to the sensor's 25C detection
range.  For the TED00 (10kt2), a 10K Ohm (1% tolerance) resistor was
used in a circuit like the following:

GND o----|TED00(10k2)|----o----|balanceResistor(10K)|----o VCC (+5vdc)
                          |
                          |
                          |----o A0 (analog input to MCU)

A 3.3vdc voltage can be used as well if desired.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 17:16:21 -07:00
9fb4be1b44 APA102: Initial implementation
Signed-off-by: Yannick Adam <yannick.adam@gmail.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 16:57:08 -07:00
42ff8b3a6e teams: Initial implementation
The driver adds support for the Veris TEAMS Temperature Transmitter.

It provides it's output via a 4-20ma current loop.  The supported
temperature range is 10C to 35C.

This sensor was developed with a Cooking Hacks (Libelium)
4-channel 4-20ma Arduino interface shield.  For this interface,
the receiver resistance (rResistor) was specified as 165.0
ohms.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 16:49:37 -07:00
a8d96bd2d9 cwlsxxa: Initial implementation
The driver was developed using the Veris CWLSHTA CO2 Gas sensor.  The
'T' variant supports a temperature sensor, and the 'H' variant
supports a humidity sensor.

All 3 signals are provided by the device as analog 0-5Vdc, 0-10Vdc, or
4-20ma loop current outputs.  For devices supporting temperature, the
valid temperature range is 10C to 50C.  The humidity ranges from 0% to
100% (non-condensing).  The CO2 sensor ranges from 0 to 2000 ppm.

This driver was developed using the 5Vdc outputs and the 4-20ma
outputs.  For voltage outputs, your MCU must be configured for 5V
operation.  In addition, you must configure the sensor (via it's
configuration switches) to output 0-5VDC only.  Using any other analog
reference voltage will require the appropriate external circuitry
(such as a voltage divider) in order to interface safely with your
MCU.

In addition, the sensor can be configured for 4-20ma usage, by
specifying the correct receiver resistance (in ohms) in the
constructor.  This sensor was tested with a Cooking Hacks (Libelium)
4-channel 4-20ma Arduino interface shield.  For this interface, the
receiver resistance was specified as 165.0 ohms.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 16:36:10 -07:00
f3a2e0d77c CMakeCache.txt: Removing CMakeCache files which are breaking the build on Ninja
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 14:14:48 -07:00
a348f23a3b SWIG: Corrected Swig interface files
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 12:17:08 -07:00
efe80a4450 SWIG: Added python and node swig files for interfaces
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 12:16:52 -07:00
411656d965 SWIG: Added java swig interface files
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-22 12:16:03 -07:00
c007385847 Example: bme280 Javascript sample
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:05:33 -07:00
8490a63309 FindNode: Update cmake module to support Fedora22 and check for errors
FindNode.cmake reports failure it cannot detect all required include files.
Module is now called with REQUIRED flag to prevent generation of makefiles
that will not build.

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:04:53 -07:00
2331548f25 Example: t6713 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:03:43 -07:00
777f081f84 Example: si7005 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:03:16 -07:00
56666872d9 Example: si1132 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:02:46 -07:00
c16f80f226 Example: max44009 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:02:20 -07:00
ee8433d92a Example: lp8860 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 16:01:32 -07:00
dd3e88fa59 Example: hlg150h C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:56:41 -07:00
224fe03d98 Example: ds1808lc C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:56:26 -07:00
9e7eae070a Example: bme280 C++ example
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:55:02 -07:00
9bc3d2ded0 interfaces: Removed isConfigured() from IModuleStaus
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:54:35 -07:00
f268437cd5 upm.h: Added C++ interface doxygen categories.
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:53:55 -07:00
aff6e9c77f interfaces: Removed get*Raw() methods
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:53:31 -07:00
d642d63d21 Swig: Added JavaScript and Python swig files for bme280
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:52:30 -07:00
17fd502cb5 ads1x15: ads1015 module now implements IADC. Removed ads1015_iadc.
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:51:06 -07:00
b08da722f7 cmake: Updated RPM packaging config to match DEB.
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:50:43 -07:00
4220dd25b4 examples: Updated IADC example to use updated interface
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:50:33 -07:00
bbdbe56355 ads1015: Added ads1015_iadc module that implements IADC.
An ADS1015 implementation existed in the inferface fork before the ADS1x15
moulde was added to upstream repo. This retrofits the IADC interface onto
an implementation derived from ads1x15

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:49:13 -07:00
e7a5118f86 cmake: Added src folder to include directory list
This is required so that interface include files are taken from
local src folder before looking in /usr/include/upm where an older version
may exist.

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:48:50 -07:00
fe8906fb51 interface: Updated IADC
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:48:37 -07:00
f35f6cc064 README: Added overview of C++ interfaces
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:48:17 -07:00
389bd32f81 examples: Added c++ interface based sensor/actuator examples
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:46:55 -07:00
f2b8921f1e t6713: Initial Implementation Amphenol Telaire 6713 Series CO2 sensor
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:45:26 -07:00
6f080db5cb si7005: Initial Implementation Silicon Labs Si7005 humidity and temperature sensor
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:44:48 -07:00
4aeccf7714 si1132: Initial Implementation Silicon Labs SI1132 light sensor.
Only visible light readings are currently supported.

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:43:37 -07:00
33734dc2e2 max44009: Initial Implementation Maxim 44009 light sensor
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:42:15 -07:00
1f1a1bce8e lp8860: Initial Implementation TI LP8860 LED lighting controller
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:41:18 -07:00
bd7930f249 hlg150: Initial Implementation Meanwell HLG150 based LED light controller
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:40:33 -07:00
d183c9574d ds1808lc: Initial Implementation Maxim DS1808 based LED lighting controller
DS1808 is a general purpose potentiometer but this implementation
is limited to controlling brightness of custom LED lighting hardware.
Ideally there should be a DS1808 module used by a seperate
lighting module.

Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:38:52 -07:00
63066bcc0b bmp180: Added Bosch BMP180 temperature/pressure sensor
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:38:12 -07:00
15d91d4797 bme280: Added Bosch BME280 temperature/humidity/pressure sensor
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:37:35 -07:00
031ed7bf95 interfaces: Added initial set of sensor/actuator interfaces
Signed-off-by: Henry Bruce <henry.bruce@intel.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-17 15:35:38 -07:00
1aa445b74e Java:Added example for Flex Sensor and added newly added sensors to the CMakeLists.txt
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-10 15:55:21 -08:00
e6ad752a2c Example: gp2y0a, Grove - 80 cm Infrared Proximity Sensor
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-08 15:12:52 -08:00
144937995c ssd1351: Initial implementation
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-03-04 08:19:56 -08:00
0b49cbab9b Java: Exampled added for heart rate monitor and Grove temp and humidity sensor (high accuracy)
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
2016-03-03 11:21:05 -08:00
f1f9d9ec2e upm: version 0.5.1
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:08:35 -08:00
74d625c797 a110x: trigger ISR on both edges
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:07:28 -08:00
2695ef3361 itg3200: fixed calibration off by one
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 18:00:45 -08:00
a9548f3ff4 adafruitms1438: stop RPATH being added in CMakeLists.txt
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 17:23:32 -08:00
3ed0e14487 h3lis331dl: Fix sensor init
Signed-off-by: Alexandru Palalau <alexandru.palalau@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 15:38:52 -08:00
1a80400fa9 my9221: java: CMakelists: remove MY9221* add GroveLEDBar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:52:32 -08:00
9845b24dea my9221: java: rename example from MY9221_ledbarSample to GroveLEDBar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:51:50 -08:00
af7f544387 my9221: fixup groveledbar java example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:51:07 -08:00
ac5c20afad my9221: remove duplicate MY9221Sample.java example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:50:26 -08:00
9f3557aa20 my9221: remove old grovecircularled driver
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:49:46 -08:00
d112266170 my9221: python: rename example from my9221 to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:49:00 -08:00
94fdd86896 my9221: fixup groveledbar python example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:48:18 -08:00
c0c99fd87a my9221: fixup grovecircularled python example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:47:37 -08:00
684919f069 my9221: fixup grovecircularled JS example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:46:56 -08:00
37add7eb33 my9221: JS: rename example from my9221 to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:46:16 -08:00
e17dc9a22e my9221: fixup JS example and interface files
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:45:32 -08:00
84c3445412 my9221: fixup example CMakelists after upstream rebase
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:44:48 -08:00
6b2850557e my9221: remove old ledbar example
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:44:04 -08:00
f94ee6a388 my9221: rename my9221-updown example to groveledbar
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:43:18 -08:00
cbb289438e my9221: rewrite to include new functionality and serve as a base class
This driver has been rewritten to support some new functionality, be
more generic and fix up some old bugs.  Multiple MY9221's can now be
chained together and are supported by the MY9221 base class.

In addition, the Grove LED Bar and Grove Circular LED drivers have
been incoporated into the my9221 library, using the new MY9221 class
as their base class.  Examples have been fixed to work with the new
library, and renamed where needed.

The current grovecircularled driver has been removed as it is now a
part of the my9221 library.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 11:42:21 -08:00
71b0791239 java: Corrected Java button sample and added it to auto build examples
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:56:50 -08:00
757a2ce342 docs: Modified building_java_bindings guide to use Runnables instead of IsrCallbacks
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:49:35 -08:00
3fab5625c7 java: Updated install path for Java library file
Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-16 10:35:45 -08:00
5324808e82 docs: minor doc, image and example fixes for some lcds
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-10 12:58:23 -08:00
7d64e5458f docs: added new sensor images
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-10 10:59:42 -08:00
ab15d1e98f ads1015: fixed sensor typo in doxygen tags
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 14:09:26 -08:00
d9b761469d jhd1313m1: renamed node and python examples to match class name
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 13:12:18 -08:00
2098449c56 upm: sync build requirements with new MRAA version
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 12:41:03 -08:00
63c75be370 docs: fixed manufacturer name for ak8975 & groveultrasonic
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2016-02-08 12:07:47 -08:00
280 changed files with 52012 additions and 646 deletions

View File

@ -1,21 +1,38 @@
language: cpp
compiler:
- gcc
- clang
env:
- CC=gcc CXX=gcc
- CC=clang CXX=clang++
- NODE4=true
- NODE5=true
- NODE012=true
install:
- sudo add-apt-repository --yes ppa:kalakris/cmake
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
- sudo apt-get update -qq
- sudo apt-get install -y -qq swig3.0 python git cmake
- sudo apt-get install -y -qq swig3.0 git
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
- sudo update-java-alternatives -s java-8-oracle
before_script:
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
script:
- git clone --branch=master https://github.com/intel-iot-devkit/mraa.git
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include .. && make && make install
- git clone https://github.com/intel-iot-devkit/mraa.git
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
- export CPLUS_INCLUDE_PATH=$PWD/include
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
addons:
apt:
sources:
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- clang-3.6
- g++-4.8
- cmake
- cmake-data

View File

@ -10,7 +10,7 @@ find_package (PkgConfig REQUIRED)
# Force a libmraa search and minimum required version every time a config is generated
unset(MRAA_FOUND CACHE)
pkg_check_modules (MRAA REQUIRED mraa>=0.9.0)
pkg_check_modules (MRAA REQUIRED mraa>=0.9.1)
message (INFO " found mraa version: ${MRAA_VERSION}")
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
message (WARNING " - Install git to compile a production UPM!")
set (VERSION "v0.5.0-dirty")
set (VERSION "v0.6.0-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")
@ -51,13 +51,15 @@ set (CMAKE_SWIG_FLAGS "")
option (BUILDDOC "Build all doc." OFF)
option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
option (BUILDSWIGJAVA "Build swig java modules" OFF)
option (IPK "Generate IPK using CPack" OFF)
option (RPM "Generate RPM using CPack" OFF)
option (BUILDTESTS "Generate check-ups for upm" OFF)
option (BUILDTESTS "Generate check-ups for upm" ON)
option (ENABLECXX11 "Enable C++11 standards support" ON)
# Find swig
if (BUILDSWIG)
@ -76,6 +78,27 @@ include (TargetArch)
target_architecture (DETECTED_ARCH)
message( INFO " - Target arch is ${DETECTED_ARCH}")
# enable c++11 standards support
if (ENABLECXX11)
include(CheckCXXCompilerFlag)
if (CMAKE_VERSION VERSION_LESS "3.1")
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
endif()
else()
# 3.1+ uses this generic method to enable c++11
set (CMAKE_CXX_STANDARD 11)
endif()
else()
message(WARNING "Some modules require C++11 support, and may not build without it.")
endif()
if (BUILDDOC)
# Add a target to generate API documentation with Doxygen
find_package (Doxygen)
@ -99,7 +122,7 @@ if (BUILDDOC)
find_package (Sphinx)
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
# Python required for Sphinx build
find_package (PythonLibs)
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
@ -156,7 +179,7 @@ if (IPK)
endif ()
message (INFO " - Package arch is ${TARGET_ARCH}")
set(CPACK_GENERATOR "DEB" "TGZ")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${TARGET_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
@ -182,10 +205,9 @@ if (RPM)
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "libupm${upm_VERSION_MAJOR}")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_NAME "upm")
set(CPACK_PACKAGE_VERSION
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}-${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}.${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
@ -196,7 +218,7 @@ if (RPM)
COMMAND tr \\n \\t
COMMAND sed -e s/\\t//
OUTPUT_VARIABLE DIST_TAG)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
include(CPack)
endif()
@ -210,10 +232,16 @@ if(BUILDJAVAEXAMPLES)
add_subdirectory (examples/java)
endif()
if (BUILDSWIGPYTHON OR BUILDTESTS)
if (BUILDPYTHON3)
set (PYTHONBUILD_VERSION 3)
else ()
set (PYTHONBUILD_VERSION 2.7)
endif ()
endif ()
if (BUILDTESTS)
find_package (PythonInterp REQUIRED)
if (${PYTHONINTERP_FOUND})
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
enable_testing ()
add_subdirectory (tests)
endif()
endif()

View File

@ -12,6 +12,19 @@ to provide identification/pin location on the board.
Typically an update() function will be called in order to get new data from the
sensor in order to reduce load when doing multiple reads to sensor data.
Although implementation and API design is up to the developer, C++ interfaces have
been defined for the following sensor/actuator types and developers are encouraged to
implement them. Interface header files are in the src/upm folder.
* Light controller
* Light sensor
* Temperature sensor
* Humidity sensor
* Pressure sensor
* Analog to digital converter
Feedback on interface design and additions for new types are welcome
### Example
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
@ -51,10 +64,6 @@ A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer
}
```
However implementation and API design is completely up to the developer, some
enumerable sensors for example may provide much clever instantiation. Displays
may also create more complex structures in order to interface with them.
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
Multi-sensor samples for the starter and specialized kits can be found in the
@ -81,7 +90,7 @@ See building documentation [here](docs/building.md).
Porting [link](docs/porting.md) has more information on making new UPM modules.
There is also an example available for max31855 [sensor](docs/max31855.md).
There is also an example available gfor max31855 [sensor](docs/max31855.md).
Guide on creating Java [bindings](docs/creating_java_bindings.md).

View File

@ -1,4 +1,12 @@
find_program (NODE_EXECUTABLE NAMES node
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
macro(add_include_dir dir)
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
endif()
endmacro()
find_program (NODEJS_EXECUTABLE NAMES node nodejs
HINTS
$ENV{NODE_DIR}
PATH_SUFFIXES bin
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
include (FindPackageHandleStandardArgs)
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs)
# If compat-libuv package exists, it must be at start of include path
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
if (UV_ROOT_DIR)
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
add_include_dir(${UV_ROOT_DIR})
endif()
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
# Now look for node. Flag an error if not found
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
if (NODE_ROOT_DIR)
add_include_dir(${NODE_ROOT_DIR}/include/src)
add_include_dir(${NODE_ROOT_DIR}/include/node)
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
else()
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - node.h not found")
endif()
# Check that v8.h is in NODEJS_INCLUDE_DIRS
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT V8_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - v8.h not found")
endif()
# Check that uv.h is in NODEJS_INCLUDE_DIRS
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
if (NOT UV_ROOT_DIR)
unset(NODEJS_INCLUDE_DIRS)
message(ERROR " - uv.h not found")
endif()
find_package_handle_standard_args (Nodejs DEFAULT_MSG
NODEJS_EXECUTABLE
NODEJS_INCLUDE_DIRS
)
find_package_handle_standard_args (Node DEFAULT_MSG
NODE_EXECUTABLE
NODE_INCLUDE_DIRS
)
if (NODE_EXECUTABLE)
execute_process(COMMAND ${NODE_EXECUTABLE} --version
if (NODEJS_EXECUTABLE)
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _NODE_VERSION_RESULT)
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
OUTPUT_VARIABLE _V8_VERSION
RESULT_VARIABLE _V8_RESULT)
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
@ -55,7 +87,11 @@ if (NODE_EXECUTABLE)
set (V8_VERSION_STRING "3.28.72")
message ("defaulted to node 0.10.30")
endif ()
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
message ("INFO - Node version is " ${NODE_VERSION_STRING})
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
mark_as_advanced (NODEJS_EXECUTABLE)
endif ()
mark_as_advanced (NODE_EXECUTABLE)

View File

@ -4,18 +4,41 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library
from earlier versions:
### v0.6.0
* Introduced C++ Interfaces for several sensor categories that will help
consolidate the sensor APIs with uniform function names upon implementation
* Greatly improved Node.js detection and handling during build and install,
and should be now compatible with all major versions
* Added a driver for the Curie IMU (accelerometer + gyroscope) that works with
the new Firmata support implemented by MRAA
* Continued to provide several JAVA fixes and examples
* Many new industrial and maker sensors: cwlsxxa, teams, tex00, h803x, apa102,
smartdrive, bmi160, bme280, ds1808lc, hlg150, lp8860, max44009, si1132, t6713,
si7005, ssd1351
### v0.5.1
* Updated the API and added new functionality for the MY9221 class and derived
sensors: grovecircularled and groveledbar, along with new code samples that
show these changes
* Provided a fix for one JAVA example that uses interrupts and updated library
install paths
* Several documentation improvements and pictures were added for new sensors
* A few other sensors received minor patches
### v0.5.0
* First implementations for industrial grade Modbus sensors, along with first
sensor examples that use the new iio system driver in MRAA.
sensor examples that use the new iio system driver in MRAA
* Significant improvements to the stepmotor driver that will now allow precise
control using any GPIO pin and extended the API with new functionality.
control using any GPIO pin and extended the API with new functionality
* Further improved JAVA bindings and sensor ISRs have been modified to
implement Runnable objects.
implement Runnable objects
* Improved Python typemaps and error checking, documentation now includes
detailed function descriptions.
detailed function descriptions
* Simplified the build process by eliminating the need to define redundant
MRAA related environment variables.
MRAA related environment variables
* New sensors: nlgpio16, ads1x15, t3311, hdxxvxta, hwxpxx, rhusb, ili9341,
apds9930, kxcjk1013
@ -55,7 +78,7 @@ from earlier versions:
includes last remaining images and grouping sensors by kits
* Added support for Sparkfun Sensor Blocks (OLED & IMU)
* Fully reworked API for at42qt1070, mpu9150 and lcd classes, while
maintaining backwards compatibility for existing lcd displays.
maintaining backwards compatibility for existing lcd displays
* Extended doxygen tags for better integration with automated documentation
generators
* New sensors: rgbringcoder, hp20x, pn532, sainsmartks, lsm9ds0, eboled

View File

@ -253,61 +253,29 @@ __SWIG:__
###Implementing callbacks in Java
Method calls from the Java instance are passed to the C++ instance transparently via C wrapper functions. In the default usage of SWIG, this arrangement is asymmetric in the sense that no corresponding mechanism exists to pass method calls down the inheritance chain from C++ to Java. To address this problem, SWIG introduces new classes called directors at the bottom of the C++ inheritance chain. The job of the directors is to route method calls correctly, either to C++ implementations higher in the inheritance chain or to Java implementations lower in the inheritance chain. The upshot is that C++ classes can be extended in Java and from C++ these extensions look exactly like native C++ classes. For more on Java directors, read the ["Cross language polymorphism using directors"](http://www.swig.org/Doc3.0/SWIGDocumentation.html#Java_directors) chapter of the SWIG documentation.
To enable directors, add the "directors" option to the %module directive, and use the %feature("director") directive to tell SWIG which classes and methods should get directors. If only a class is specified, the %feature is applied to all virtual methods in that class. If no class or method is specified, the %feature is applied globally to all virtual methods.
```
%module(directors="1") modulename
%feature("director") IsrCallback;
```
Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA.
__Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__
We create a new C++ class, that will be wrapped by SWIG, called _IsrCallback_; and a method _generic\_callback\_isr(void\* data)_ that takes an instance of IsrCallback as argument.
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
```c++
#if defined(SWIGJAVA)
class IsrCallback
void A110X::installISR(jobject runnable)
{
public:
virtual ~IsrCallback()
{
}
virtual void run()
{ /* empty, overridden in Java*/
}
private:
};
static void generic_callback_isr (void* data)
{
IsrCallback* callback = (IsrCallback*) data;
if (callback == NULL)
return;
callback->run();
installISR(mraa_java_isr_callback, runnable);
}
#endif
```
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _IsrCallback_ class and _generic\_callback\_isr()_ in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
We extend the sensor class with another method, _installISR\(IsrCallback \*cb\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _generic\_callback\_isr\(\)_ method as the interrupt service routine \(ISR\) to be called, with the _IsrCallback_ object (referenced by *cb) as argument.
```c++
#if defined(SWIGJAVA)
void A110X::installISR( IsrCallback *cb)
{
installISR(generic_callback_isr, cb);
}
#endif
```
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(IsrCallback \*cb\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
```c++
public:
#if defined(SWIGJAVA)
void installISR(IsrCallback *cb);
void installISR(jobject runnable);
#else
void installISR(void (*isr)(void *), void *arg);
#endif
@ -317,7 +285,7 @@ private:
#endif
```
To use callback in java, we create a ISR class, which extends the new IsrCallback class created by SWIG, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
```java
public class A110X_intrSample {
@ -326,7 +294,7 @@ public class A110X_intrSample {
public static void main(String[] args) throws InterruptedException {
upm_a110x.A110X hall = new upm_a110x.A110X(2);
IsrCallback callback = new A110XISR();
A110XISR callback = new A110XISR();
hall.installISR(callback);
while(true){
@ -336,7 +304,7 @@ public class A110X_intrSample {
}
}
class A110XISR extends IsrCallback {
class A110XISR implements Runnable {
public A110XISR(){
super();
}
@ -383,18 +351,3 @@ by
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
```
__Use GlobalRef instead of WeakRef__
By default, SWIG uses WeakRef to the Java objects handled by a director. Once Java objects run out of scope they can get cleaned up. In many cases WeakRef is undesirable as we may still want to be able to run methods or access fields in the objects passed to the JNI layer (e.g. we want to pass a runnable-like object which should be called when something happens). To use GlobalRefs instead, the following line must be added after the director declaration:
```
SWIG_DIRECTOR_OWNED(module)
```
For, example, in case of a module called IsrCallback (used for interrupts in MRAA and UPM), we would declare said module as such:
```
%feature ("director") IsrCallback;
SWIG_DIRECTOR_OWNED(IsrCallback)
```

BIN
docs/images/adxrs610.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
docs/images/apa102.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
docs/images/bma220.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
docs/images/dfrph.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
docs/images/eboled.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
docs/images/keypadlcd.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
docs/images/lm35.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
docs/images/lsm9ds0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
docs/images/mg811.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
docs/images/mpu60x0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
docs/images/mpu9250.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
docs/images/pn532.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
docs/images/ssd1351.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
docs/images/urm37.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
docs/images/xbee.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@ -859,7 +859,7 @@ EXCLUDE_SYMLINKS = NO
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories for example use the pattern */test/*
EXCLUDE_PATTERNS =
EXCLUDE_PATTERNS = bosch_*
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
# (namespaces, classes, functions, etc.) that should be excluded from the

View File

@ -48,7 +48,7 @@ mpu9150.cxx MPU9150Sample.java
mq2.cxx MQ2Sample.java
mq303a.cxx MQ303ASample.java
mq5.cxx MQ5Sample.java
my9221-ledbar.cxx MY9221_ledbarSample.java
groveledbar GroveLEDBar
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
nunchuck.cxx NUNCHUCKSample.java

View File

@ -91,8 +91,6 @@ add_example (grovebutton)
add_example (groverotary)
add_example (groveslide)
add_example (buzzer-sound)
add_example (my9221-ledbar)
add_example (my9221-updown)
add_example (nrf24l01-transmitter)
add_example (nrf24l01-receiver)
add_example (nrf24l01-broadcast)
@ -203,7 +201,6 @@ add_example (h3lis331dl)
add_example (ad8232)
add_example (grovescam)
add_example (m24lr64e)
add_example (grovecircularled)
add_example (rgbringcoder)
add_example (hp20x)
add_example (pn532)
@ -237,11 +234,30 @@ if (MODBUS_FOUND)
include_directories(${MODBUS_INCLUDE_DIRS})
add_example (t3311)
add_example (hwxpxx)
add_example (h803x)
endif()
add_example (hdxxvxta)
add_example (rhusb)
add_example (apds9930)
add_example (kxcjk1013)
add_example (ssd1351)
add_example (bme280)
add_example (ds1808lc)
add_example (hlg150h)
add_example (lp8860)
add_example (max44009)
add_example (si1132)
add_example (si7005)
add_example (t6713)
add_example (cwlsxxa)
add_example (teams)
add_example (apa102)
add_example (tex00)
add_example (bmi160)
add_example (smartdrive)
if (HAVE_FIRMATA)
add_example (curieimu)
endif ()
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)
@ -258,3 +274,12 @@ add_custom_example (eboled-example eboled.cxx lcd)
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150)
add_custom_example (ak8975-example ak8975.cxx mpu9150)
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
add_custom_example (groveledbar-example groveledbar.cxx my9221)
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmp180;bme280")
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")

View File

@ -0,0 +1,80 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "ads1015.h"
#include "mraa/gpio.hpp"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
#define EDISON_GPIO_SI7005_CS 20
//! [Interesting]
// Simple example of using IADC to determine
// which sensor is present and return its name.
// IADC is then used to get readings from sensor
upm::IADC* getADC()
{
upm::IADC* adc = NULL;
try {
adc = new upm::ADS1015(EDISON_I2C_BUS);
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
gpio.dir(mraa::DIR_OUT_HIGH);
return adc;
} catch (std::exception& e) {
std::cerr << "ADS1015: " << e.what() << std::endl;
}
return adc;
}
int main ()
{
upm::IADC* adc = getADC();
if (adc == NULL) {
std::cout << "ADC not detected" << std::endl;
return 1;
}
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
while (true) {
for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
std::cout << "Input " << i;
try {
float voltage = adc->getVoltage(i);
std::cout << ": Voltage = " << voltage << "V" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
sleep(1);
}
delete adc;
return 0;
}
//! [Interesting]

View File

@ -1,6 +1,6 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -22,42 +22,30 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include "apa102.h"
#include <iostream>
#include "my9221.h"
#include <signal.h>
#include <unistd.h>
int running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
using namespace std;
int
main(int argc, char** argv)
{
//! [Interesting]
upm::MY9221 *bar = new upm::MY9221(8, 9);
// Instantiate a strip of 30 LEDs on SPI bus 0
upm::APA102* ledStrip = new upm::APA102(800, 0);
signal(SIGINT, sig_handler);
// Set all LEDs to Red
ledStrip->setAllLeds(31, 255, 0, 0);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
}
}
// Set a section (10 to 20) to blue
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
// Set a single LED to green
ledStrip->setLed(15, 31, 0, 255, 0);
delete ledStrip;
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete bar;
return 0;
}

51
examples/c++/bme280.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "bme280.h"
#define FT4222_I2C_BUS 0
int main ()
{
try {
upm::BME280* bme280 = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
while (true) {
int temperature = bme280->getTemperatureCelcius();
int humidity = bme280->getHumidityRelative();
int pressure = bme280->getPressurePa();
std::cout << "Temperature = " << temperature << "C" << std::endl;
std::cout << "Humidity = " << humidity << "%" << std::endl;
std::cout << "Pressure = " << pressure << "Pa" << std::endl;
sleep(1);
}
delete bme280;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
//! [Interesting]

82
examples/c++/bmi160.cxx Normal file
View File

@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "bmi160.h"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a BMI160 instance using default i2c bus and address
upm::BMI160 *sensor = new upm::BMI160();
while (shouldRun)
{
// update our values from the sensor
sensor->update();
float dataX, dataY, dataZ;
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
cout << "Accelerometer: ";
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
<< dataZ << endl;
sensor->getGyroscope(&dataX, &dataY, &dataZ);
cout << "Gryoscope: ";
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
<< dataZ << endl;
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
cout << "Magnetometer: ";
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
<< dataZ << endl;
cout << endl;
usleep(500000);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}

View File

@ -0,0 +1,71 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "t6713.h"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
//! [Interesting]
// Simple example of using ICO2Sensor to determine
// which sensor is present and return its name.
// ICO2Sensor is then used to get readings from sensor
upm::ICO2Sensor* getCO2Sensor()
{
upm::ICO2Sensor* cO2Sensor = NULL;
try {
cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
return cO2Sensor;
} catch (std::exception& e) {
std::cerr << "T6713: " << e.what() << std::endl;
}
return cO2Sensor;
}
int main ()
{
upm::ICO2Sensor* cO2Sensor = getCO2Sensor();
if (cO2Sensor == NULL) {
std::cout << "CO2 sensor not detected" << std::endl;
return 1;
}
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
uint16_t value = cO2Sensor->getPpm();
std::cout << "CO2 level = " << value << " ppm" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
sleep(1);
}
delete cO2Sensor;
return 0;
}
//! [Interesting]

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

@ -0,0 +1,81 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Author: Ron Evans (@deadprogram)
* Author: Justin Zemlyansky (@JustInDevelopment)
* 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 "curieimu.hpp"
#include "mraa.h"
#include "mraa/firmata.h"
#include <math.h>
int
main(int argc, char **argv)
{
//! [Interesting]
mraa_init();
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
upm::CurieImu* sensor = new upm::CurieImu();
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
sensor->updateAccel();
int x = sensor->getAccelX(),
y = sensor->getAccelY(),
z = sensor->getAccelZ();
printf("accelerometer is: %d, %d, %d\n", x, y, z);
sensor->updateGyro();
int a = sensor->getGyroX(),
b = sensor->getGyroY(),
c = sensor->getGyroZ();
printf("gyroscope is: %d, %d, %d\n", a, b, c);
int axis, direction;
sensor->enableShockDetection(true);
for(int i=0; i<300; i++) {
if (sensor->isShockDetected()) {
sensor->getNextShock();
axis = sensor->getAxis();
direction = sensor->getDirection();
printf("shock data is: %d, %d\n", axis, direction);
}
usleep(10000);
}
sensor->updateMotion();
int m = sensor->getAccelX(),
n = sensor->getAccelY(),
o = sensor->getAccelZ(),
p = sensor->getGyroX(),
q = sensor->getGyroY(),
r = sensor->getGyroZ();
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
delete sensor;
return 0;
}

82
examples/c++/cwlsxxa.cxx Normal file
View File

@ -0,0 +1,82 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "cwlsxxa.h"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
cout << "Initializing..." << endl;
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
// humidity and A2 for temperature
upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor->update();
// we show both C and F for temperature
cout << "Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
cout << "Humidity: " << sensor->getHumidity()
<< " %" << endl;
cout << "CO2: " << sensor->getCO2()
<< " ppm" << endl;
cout << endl;
sleep(1);
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

51
examples/c++/ds1808lc.cxx Normal file
View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include "ds1808lc.h"
#define EDISON_I2C_BUS 1 // Edison I2C-1
#define DS1808_GPIO_PWR 15 // Edison GP165
void printState(upm::ILightController *lightController)
{
if (lightController->isPowered())
{
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
}
else
{
std::cout << "Light is not powered." << std::endl;
}
}
int main( int argc, char **argv )
{
int status = 0;
upm::ILightController* lightController;
try {
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
std::cout << "Existing state: "; printState(lightController);
if (argc == 2)
{
std::string arg = argv[1];
int brightness = ::atoi(argv[1]);
if (brightness > 0) {
lightController->setPowerOn();
lightController->setBrightness(brightness);
} else
lightController->setPowerOff();
}
std::cout << "Now: ";printState(lightController);
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
status = 1;
}
delete lightController;
return status;
}

View File

@ -43,9 +43,9 @@ int main()
//! [Interesting]
// Instantiate a Grove Circular LED on gpio pins 5 and 4
// Instantiate a Grove Circular LED on D9 for data, D8 for clock
upm::GroveCircularLED *circle = new upm::GroveCircularLED(5, 4);
upm::GroveCircularLED *circle = new upm::GroveCircularLED(9, 8);
int level = 0;
while (shouldRun)
@ -54,6 +54,7 @@ int main()
level = (level + 1) % 24;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;

View File

@ -25,7 +25,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "my9221.h"
#include "groveledbar.h"
using namespace std;
@ -44,26 +44,25 @@ int main ()
//! [Interesting]
// Instantiate a MY9221, we use D2 for the data, and D3 for the
// data clock. This was tested with a Grove LED bar.
upm::MY9221* bar = new upm::MY9221(2, 3);
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
// clock. This was tested with a Grove LED bar.
upm::GroveLEDBar* bar = new upm::GroveLEDBar(8, 9);
while (shouldRun)
{
// count up from green to red
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, true);
usleep(50000);
usleep(100000);
}
sleep(1);
// count down from red to green
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, false);
usleep(50000);
usleep(100000);
}
sleep(1);
}
@ -71,7 +70,7 @@ int main ()
cout << "Exiting..." << endl;
// turn off the LED's
bar->setBarLevel(0, true);
bar->setBarLevel(0);
delete bar;
return 0;

149
examples/c++/h803x.cxx Normal file
View File

@ -0,0 +1,149 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "h803x.h"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
string defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
cout << "Using device " << defaultDev << endl;
cout << "Initializing..." << endl;
// Instantiate an H803X instance, using MODBUS slave address 1, and
// default comm parameters (9600, 8, N, 2)
upm::H803X *sensor = new upm::H803X(defaultDev, 1);
// output the Slave ID string
cout << "Slave ID: " << sensor->getSlaveID() << endl;
cout << endl;
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor->update();
// H8035 / H8036
cout << "Consumption (kWh): " << sensor->getConsumption() << endl;
cout << "Real Power (kW): " << sensor->getRealPower() << endl;
if (sensor->isH8036())
{
// The H8036 has much more data available...
cout << "Reactive Power (kVAR): " << sensor->getReactivePower()
<< endl;
cout << "Apparent Power (kVA): " << sensor->getApparentPower()
<< endl;
cout << "Power Factor: " << sensor->getPowerFactor()
<< endl;
cout << "Volts Line to Line: " << sensor->getVoltsLineToLine()
<< endl;
cout << "Volts Line to Neutral: " << sensor->getVoltsLineToNeutral()
<< endl;
cout << "Current: " << sensor->getCurrent()
<< endl;
cout << "Real Power Phase A (kW): " << sensor->getRealPowerPhaseA()
<< endl;
cout << "Real Power Phase B (kW): " << sensor->getRealPowerPhaseB()
<< endl;
cout << "Real Power Phase C (kW): " << sensor->getRealPowerPhaseC()
<< endl;
cout << "Power Factor Phase A: " << sensor->getPowerFactorPhaseA()
<< endl;
cout << "Power Factor Phase B: " << sensor->getPowerFactorPhaseB()
<< endl;
cout << "Power Factor Phase C: " << sensor->getPowerFactorPhaseC()
<< endl;
cout << "Volts Phase A to B: " << sensor->getVoltsPhaseAToB()
<< endl;
cout << "Volts Phase B to C: " << sensor->getVoltsPhaseBToC()
<< endl;
cout << "Volts Phase A to C: " << sensor->getVoltsPhaseAToC()
<< endl;
cout << "Volts Phase A to Neutral: "
<< sensor->getVoltsPhaseAToNeutral()
<< endl;
cout << "Volts Phase B to Neutral: "
<< sensor->getVoltsPhaseBToNeutral()
<< endl;
cout << "Volts Phase C to Neutral: "
<< sensor->getVoltsPhaseCToNeutral()
<< endl;
cout << "Current Phase A: " << sensor->getCurrentPhaseA()
<< endl;
cout << "Current Phase B: " << sensor->getCurrentPhaseB()
<< endl;
cout << "Current Phase C: " << sensor->getCurrentPhaseC()
<< endl;
cout << "Avg Real Power (kW): " << sensor->getAvgRealPower()
<< endl;
cout << "Min Real Power (kW): " << sensor->getMinRealPower()
<< endl;
cout << "Max Real Power (kW): " << sensor->getMaxRealPower()
<< endl;
}
cout << endl;
sleep(2);
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

51
examples/c++/hlg150h.cxx Normal file
View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include "hlg150h.h"
#define HLG150H_GPIO_RELAY 21
#define HLG150H_GPIO_PWM 22
void printState(upm::ILightController *lightController)
{
if (lightController->isPowered())
{
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
}
else
{
std::cout << "Light is not powered." << std::endl;
}
}
int main( int argc, char **argv )
{
int status = 0;
upm::ILightController* lightController;
try {
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
std::cout << "Existing state: "; printState(lightController);
if (argc == 2)
{
std::string arg = argv[1];
int brightness = ::atoi(argv[1]);
if (brightness > 0) {
lightController->setPowerOn();
lightController->setBrightness(brightness);
} else
lightController->setPowerOff();
}
std::cout << "Now: ";printState(lightController);
delete lightController;
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
status = 1;
}
return status;
}

View File

@ -0,0 +1,82 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "si7005.h"
#include "bme280.h"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
#define EDISON_GPIO_SI7005_CS 20
//! [Interesting]
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// ILightSensor is then used to get readings from sensor
upm::IHumiditySensor* getHumiditySensor()
{
upm::IHumiditySensor* humiditySensor = NULL;
try {
humiditySensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
return humiditySensor ;
} catch (std::exception& e)
{
std::cerr <<"BME280: "<<e.what() << std::endl;
}
try {
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
return humiditySensor;
} catch (std::exception& e) {
std::cerr << "SI7005: " << e.what() << std::endl;
}
return humiditySensor;
}
int main ()
{
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
if (humiditySensor == NULL) {
std::cout << "Humidity sensor not detected" << std::endl;
return 1;
}
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = humiditySensor->getHumidityRelative();
std::cout << "Humidity = " << value << "%" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
sleep(1);
}
delete humiditySensor;
return 0;
}
//! [Interesting]

View File

@ -0,0 +1,98 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include "lp8860.h"
#include "ds1808lc.h"
#include "hlg150h.h"
#define EDISON_I2C_BUS 1 // Edison I2C-1
#define GPIO_SI7005_CS 20 // Edison GP12
#define HLG150H_GPIO_RELAY 21
#define HLG150H_GPIO_PWM 22
#define LP8860_GPIO_PWR 45 // Edison GP45
#define DS1808_GPIO_PWR 15 // Edison GP165
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
//! [Interesting]
// Simple example of using ILightController to determine
// which controller is present and return its name.
// ILightController is then used to get readings from sensor
upm::ILightController* getLightController()
{
upm::ILightController* lightController = NULL;
try {
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
return lightController;
} catch (std::exception& e) {
std::cerr << "LP8860: " << e.what() << std::endl;
}
try {
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
return lightController;
} catch (std::exception& e) {
std::cerr << "DS1808LC: " << e.what() << std::endl;
}
try {
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
return lightController;
} catch (std::exception& e) {
std::cerr << "HLG150H: " << e.what() << std::endl;
}
return lightController;
}
void printState(upm::ILightController *lightController)
{
if (lightController->isPowered())
{
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
}
else
{
std::cout << "Light is not powered." << std::endl;
}
}
int main( int argc, char **argv )
{
int status = 0;
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
upm::ILightController *lightController = getLightController();
if (lightController != NULL)
{
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
}
else
{
std::cerr << "Error. Unsupported platform." << std::endl;
return 1;
}
try {
std::cout << "Existing state: "; printState(lightController);
if (argc == 2)
{
std::string arg = argv[1];
int brightness = ::atoi(argv[1]);
if (brightness > 0) {
lightController->setPowerOn();
lightController->setBrightness(brightness);
} else
lightController->setPowerOff();
}
std::cout << "Now: ";printState(lightController);
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
status = 1;
}
delete lightController;
return status;
}

View File

@ -0,0 +1,78 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "max44009.h"
#include "si1132.h"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
//! [Interesting]
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// ILightSensor is then used to get readings from sensor
upm::ILightSensor* getLightSensor()
{
upm::ILightSensor* lightSensor = NULL;
try {
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
return lightSensor;
} catch (std::exception& e) {
std::cerr << "SI1132: " << e.what() << std::endl;
}
try {
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
return lightSensor;
} catch (std::exception& e) {
std::cerr << "MAX44009: " << e.what() << std::endl;
}
return lightSensor;
}
int main ()
{
upm::ILightSensor* lightSensor = getLightSensor();
if (lightSensor == NULL) {
std::cout << "Light sensor not detected" << std::endl;
return 1;
}
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
float value = lightSensor->getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
sleep(1);
}
delete lightSensor;
return 0;
}
//! [Interesting]

52
examples/c++/lp8860.cxx Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include "lp8860.h"
#define EDISON_I2C_BUS 1 // Edison I2C-1
#define LP8860_GPIO_PWR 45 // Edison GP45
void printState(upm::ILightController *lightController)
{
if (lightController->isPowered())
{
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
}
else
{
std::cout << "Light is not powered." << std::endl;
}
}
int main( int argc, char **argv )
{
int status = 0;
upm::LP8860* lightController;
try {
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
std::cout << "Existing state: "; printState(lightController);
if (argc == 2)
{
std::string arg = argv[1];
int brightness = ::atoi(argv[1]);
if (brightness > 0) {
lightController->setPowerOn();
lightController->setBrightness(brightness);
} else
lightController->setPowerOff();
}
std::cout << "Now: ";printState(lightController);
delete lightController;
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
status = 1;
}
return status;
}

46
examples/c++/max44009.cxx Normal file
View File

@ -0,0 +1,46 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "max44009.h"
#define EDISON_I2C_BUS 1
int main ()
{
try {
upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
while (true) {
float value = lightSensor->getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl;
sleep(1);
}
delete lightSensor;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

View File

@ -0,0 +1,81 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "bmp180.h"
#include "bme280.h"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
//! [Interesting]
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// ILightSensor is then used to get readings from sensor
upm::IPressureSensor* getPressureSensor()
{
upm::IPressureSensor* pressureSensor = NULL;
try {
pressureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
return pressureSensor ;
} catch (std::exception& e)
{
std::cerr <<"BME280: "<<e.what() << std::endl;
}
try {
pressureSensor = new upm::BMP180(EDISON_I2C_BUS);
return pressureSensor;
} catch (std::exception& e) {
std::cerr << "BMP180: " << e.what() << std::endl;
}
return pressureSensor;
}
int main ()
{
upm::IPressureSensor* pressureSensor = getPressureSensor();
if (pressureSensor == NULL) {
std::cout << "Pressure sensor not detected" << std::endl;
return 1;
}
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = pressureSensor->getPressurePa();
std::cout << "Pressure = " << value << " Pa" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
sleep(1);
}
delete pressureSensor;
return 0;
}
//! [Interesting]

46
examples/c++/si1132.cxx Normal file
View File

@ -0,0 +1,46 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "si1132.h"
#define FT4222_I2C_BUS 1
int main ()
{
try {
upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
while (true) {
float value = lightSensor->getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl;
sleep(1);
}
delete lightSensor;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

51
examples/c++/si7005.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "si7005.h"
#define EDISON_I2C_BUS 1
#define EDISON_GPIO_SI7005_CS 20
int main ()
{
try {
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
while (true) {
int temperature = sensor->getTemperatureCelcius();
int humidity = sensor->getHumidityRelative();
std::cout << "Temperature = " << temperature << "C" << std::endl;
std::cout << "Humidity = " << humidity << "%" << std::endl;
sleep(1);
}
delete sensor;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
//! [Interesting]

View File

@ -0,0 +1,75 @@
/*
* The MIT License (MIT)
*
* Author: Oussema Harbi <oussema.elharbi@gmail.com>
* Copyright (c) <2016> <Oussema Harbi>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "smartdrive.h"
#include <signal.h>
upm::SmartDrive *drive = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
if (drive != NULL)
delete drive;
exit (0);
}
}
int
main(int argc, char **argv)
{
float voltage = 0;
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
//! [Interesting]
// Instantiate a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
drive = new upm::SmartDrive(0);
std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
//Set motor M1 to run for 120 seconds, with speed of 15RPM, waith for it to finish and then Brake It
drive->Run_Seconds(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 15, 120, true, SmartDrive_Action_Brake);
std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
//Rotate motor M2 2270 degrees, in reverse sense, with speed of 10RPM, return immediately from function call
drive->Run_Degrees(SmartDrive_Motor_ID_2, SmartDrive_Dir_Reverse, 10, 2270, false, SmartDrive_Action_Float);
//While motor is running, Display its status
drive->PrintMotorStatus(SmartDrive_Motor_ID_2);
sleep(2); //Sleep for 2 seconds
//Stop motor M2 and then finish program
drive->StopMotor(SmartDrive_Motor_ID_2, SmartDrive_Action_BrakeHold);
//! [Interesting]
std::cout << "Demo complete. GoodBye" << std::endl;
delete drive;
drive = NULL;
return 0;
}

61
examples/c++/ssd1351.cxx Normal file
View File

@ -0,0 +1,61 @@
#include "mraa.hpp"
#include <iostream>
#include <unistd.h>
#include "ssd1351.h"
#define BLACK 0x0000
#define WHITE 0xFFFF
#define INTEL_BLUE 0x0BF8
int main(int argc, char **argv)
{
// Define colors (16-bit RGB on 5/6/5 bits)
int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
0x7800, 0x780F, 0x7BE0, 0xC618,
0x7BEF, 0x001F, 0x07E0, 0x07FF,
0xF800, 0xF81F, 0xFFE0, 0xFFFF};
//! [Interesting]
// Initialize display with pins
// oc = 0, dc = 1, r = 2, si = 11, cl = 13
upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
// Test lines pixel by pixel
for(int i = 0; i < SSD1351HEIGHT; i++) {
for(int j = 0; j < SSD1351WIDTH; j++) {
display->drawPixel(i, j, colors[i/8]);
}
}
display->refresh();
sleep(5);
// Test rectangles
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
for (int j = 0; j < SSD1351WIDTH/32; j++) {
display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
}
}
display->refresh();
sleep(5);
// Test circles
display->fillScreen(0x2104);
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
for (int j = 0; j < SSD1351WIDTH/32; j++) {
display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
}
}
display->refresh();
sleep(5);
// Test Text
display->fillScreen(INTEL_BLUE);
display->setTextColor(WHITE, INTEL_BLUE);
display->setTextSize(4);
display->setCursor(7, 30);
display->print("Intel");
display->setCursor(5, 70);
display->print("IoTDK");
display->refresh();
//! [Interesting]
}

48
examples/c++/t6713.cxx Normal file
View File

@ -0,0 +1,48 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "t6713.h"
#define FT4222_I2C_BUS 0
int main ()
{
try {
upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
while (true) {
uint16_t value = cO2Sensor->getPpm();
std::cout << "CO2 level = " << value << " ppm" << std::endl;
sleep(1);
}
delete cO2Sensor;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

84
examples/c++/teams.cxx Normal file
View File

@ -0,0 +1,84 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "teams.h"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
cout << "Initializing..." << endl;
// Instantiate an TEAMS instance, using A0 for temperature, and
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
// interface)
upm::TEAMS *sensor = new upm::TEAMS(0, 165.0);
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor->update();
// is the sensor connected? (current >= 4ma)
cout << "Is Connected: " << sensor->isConnected() << endl;
// print computed current on the loop. This includes the offset,
// if one was set by setOffsetMilliamps().
cout << "Milliamps: " << sensor->getRawMilliamps() << endl;
// we show both C and F for temperature
cout << "Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
cout << endl;
sleep(1);
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,90 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "si7005.h"
#include "bmp180.h"
#include "bme280.h"
#define EDISON_I2C_BUS 1
#define FT4222_I2C_BUS 0
#define EDISON_GPIO_SI7005_CS 20
//! [Interesting]
// Simple example of using ITemperatureSensor to determine
// which sensor is present and return its name.
// ITemperatureSensor is then used to get readings from sensor
upm::ITemperatureSensor* getTemperatureSensor()
{
upm::ITemperatureSensor* temperatureSensor = NULL;
try {
temperatureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
return temperatureSensor;
} catch (std::exception& e)
{
std::cerr <<"BME280: "<<e.what() << std::endl;
}
try {
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
return temperatureSensor;
} catch (std::exception& e) {
std::cerr << "SI7005: " << e.what() << std::endl;
}
try {
temperatureSensor = new upm::BMP180(EDISON_I2C_BUS);
return temperatureSensor;
} catch (std::exception& e) {
std::cerr << "BMP180: " << e.what() << std::endl;
}
return temperatureSensor;
}
int main ()
{
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
if (temperatureSensor == NULL) {
std::cout << "Temperature sensor not detected" << std::endl;
return 1;
}
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = temperatureSensor->getTemperatureCelcius();
std::cout << "Temperature = " << value << "C" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
sleep(1);
}
delete temperatureSensor;
return 0;
}
//! [Interesting]

91
examples/c++/tex00.cxx Normal file
View File

@ -0,0 +1,91 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "tex00.h"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
cout << "Initializing..." << endl;
// Instantiate an TEX00 instance, using A0 for the analog input. In
// this example, we are using a 10K Ohm balance resistor and a TED
// (10k type 2) thermistor.
upm::TEX00 *sensor = new upm::TEX00(0, 10000,
upm::TEX00::STYPE_THERMISTOR_TED);
cout << "Minimum temperature: " << sensor->getTemperatureRangeMin()
<< " C" << endl;
cout << "Maximum temperature: " << sensor->getTemperatureRangeMax()
<< " C" << endl;
cout << endl;
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor->update();
if (sensor->isOutOfRange())
{
cout << "Temperature out of range" << endl;
}
else
{
// we show both C and F for temperature
cout << "Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
}
cout << endl;
sleep(1);
}
cout << "Exiting..." << endl;
delete sensor;
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,44 @@
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class APA102Sample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a strip of 30 LEDs on SPI bus 0
upm_apa102.APA102 ledStrip =
new upm_apa102.APA102(30, (short)0, false, (byte)-1);
System.out.println("Set all LEDs to blue");
ledStrip.setAllLeds((short)31, (short)0, (short)0, (short)255);
System.out.println("Set LEDs between 10 and 20 to green");
ledStrip.setLeds(10, 20, (short)31, (short)0, (short)255, (short)0);
System.out.println("Set a single LED to red at index 15");
ledStrip.setLed(15, (short)31, (short)255, (short)0, (short)0);
// ! [Interesting]
}
}

View File

@ -0,0 +1,50 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_ad8232.AD8232;
public class Ad8232Example {
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
// and an analog pin, 0 (OUTPUT)
AD8232 ad8232 = new AD8232(10, 11, 0);
while(true){
// Output the raw numbers from the ADC, for plotting elsewhere.
// A return of 0 indicates a Lead Off (LO) condition.
// In theory, this data could be fed to software like Processing
// (https://www.processing.org/) to plot the data just like an
// EKG you would see in a hospital.
System.out.println(ad8232.value());
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following error has occured: "+e.getMessage());
}
}
}
}

View File

@ -0,0 +1,78 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_bmi160.BMI160;
public class BMI160_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
System.out.println("Initializing...");
// Instantiate a BMI160 instance using default i2c bus and address
BMI160 sensor = new BMI160();
while (true)
{
// update our values from the sensor
sensor.update();
float dataA[] = sensor.getAccelerometer();
System.out.println("Accelerometer: "
+ "AX: "
+ dataA[0]
+ " AY: "
+ dataA[1]
+ " AZ: "
+ dataA[2]);
float dataG[] = sensor.getGyroscope();
System.out.println("Gryoscope: "
+ "GX: "
+ dataG[0]
+ " GY: "
+ dataG[1]
+ " GZ: "
+ dataG[2]);
float dataM[] = sensor.getMagnetometer();
System.out.println("Magnetometer: "
+ "MX: "
+ dataM[0]
+ " MY: "
+ dataM[1]
+ " MZ: "
+ dataM[2]);
System.out.println();
Thread.sleep(500);
}
// ! [Interesting]
}
}

View File

@ -29,6 +29,7 @@ add_example(DS1307Sample ds1307)
add_example(ENC03RSample enc03r)
add_example(ES08ASample servo)
add_example(GroveButtonSample grove)
add_example(GroveButton_intrSample grove)
add_example(GroveCollision grovecollision)
add_example(GroveEHRSample groveehr)
add_example(GroveEmg groveemg)
@ -77,8 +78,7 @@ add_example(MPU9150Sample mpu9150)
add_example(MQ2Sample gas)
add_example(MQ303ASample mq303a)
add_example(MQ5Sample gas)
add_example(MY9221_ledbarSample my9221)
add_example(MY9221Sample my9221)
add_example(GroveLEDBar my9221)
add_example(NRF24L01_receiverSample nrf24l01)
add_example(NRF24L01_transmitterSample nrf24l01)
add_example(NUNCHUCKSample nunchuck)
@ -101,7 +101,18 @@ add_example(WaterLevelSensor waterlevel)
add_example(WT5001Sample wt5001)
add_example(YG1006Sample yg1006)
add_example(ZFM20Sample zfm20)
add_example(Ad8232Example ad8232)
add_example(Gp2y0aExample gp2y0a)
add_example(Th02Example th02)
add_example(FlexSensorExample flex)
add_example(CWLSXXA_Example cwlsxxa)
add_example(TEAMS_Example teams)
add_example(APA102Sample apa102)
add_example(TEX00_Example tex00)
add_example(BMI160_Example bmi160)
if (MODBUS_FOUND)
add_example(H803X_Example h803x)
endif()
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)

View File

@ -0,0 +1,62 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_cwlsxxa.CWLSXXA;
public class CWLSXXA_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
// humidity and A2 for temperature
CWLSXXA sensor = new CWLSXXA(0, 1, 2);
while (true)
{
// update our values from the sensor
sensor.update();
// we show both C and F for temperature
System.out.println("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
System.out.println("Humidity: "
+ sensor.getHumidity()
+ " %");
System.out.println("CO2: "
+ sensor.getCO2()
+ " ppm");
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,41 @@
import upm_flex.Flex;
public class FlexSensorExample {
static {
try {
System.loadLibrary("javaupm_flex");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// The was tested with a Spectra Symbol flex sensor.
// We attached a 22K resistor to a breadboard,
// with 1 end attached to GND and the other connected to
// both the flex sensor and A0.
// The flex sensor was connected on 1 pin to the 22K resistor and A0
// and on the other pin to 5V.
// Instantiate a Flex sensor on analog pin A0
Flex flex = new Flex(0);
while(true){
System.out.println("Flex Sensor value is: "+flex.value());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//! [Interesting]
}
}

View File

@ -0,0 +1,68 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_gp2y0a.GP2Y0A;
public class Gp2y0aExample {
public static final float GP2Y0A_AREF = 5;
public static final short SAMPLES_PER_QUERY = 20;
static {
try {
System.loadLibrary("javaupm_gp2y0a");
System.loadLibrary("mraajava");
} catch (UnsatisfiedLinkError e) {
System.err.println(
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
e);
System.exit(1);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Note, for the Grove 80cm version of this sensor, due to the way
// it is wired, you need to plug this into the A0 port, where it
// will use the available A1 pin for data.
// Instantiate a GP2Y0A on analog pin A1
GP2Y0A gp2y0a = new GP2Y0A(1);
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
// the measured voltage will probably not exceed 3.3 volts.
// Every second, print the averaged voltage value (averaged over 20 samples).
while(true){
System.out.println("AREF: " + GP2Y0A_AREF + "\t, Voltage Value (Higher means Closer): "+ gp2y0a.value(GP2Y0A_AREF, SAMPLES_PER_QUERY));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following exception occured: "+e.getMessage());
}
}
//! [Interesting]
}
}

View File

@ -22,9 +22,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_grove.IsrCallback;
//NOT TESTED!!!
public class GroveButton_intrSample {
public static int counter = 0;
@ -33,8 +30,8 @@ public class GroveButton_intrSample {
// ! [Interesting]
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
IsrCallback callback = new ButtonISR();
b.installISR(mraa.Edge.EDGE_RISING.swigValue(), callback);
ButtonISR callback = new ButtonISR();
b.installISR(2, callback);
while (true) {
System.out.println("Counter: " + counter);
@ -44,7 +41,7 @@ public class GroveButton_intrSample {
}
}
class ButtonISR extends IsrCallback {
class ButtonISR implements Runnable {
public ButtonISR() {
super();
}

View File

@ -22,12 +22,12 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class MY9221_ledbarSample{
public class GroveLEDBar {
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
upm_my9221.GroveLEDBar bar = new upm_my9221.GroveLEDBar((short) 8, (short) 9);
while (true) {
for (short idx = 1; idx < 11; idx++) {

View File

@ -0,0 +1,123 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_h803x.H803X;
public class H803X_Example
{
private static String defaultDev = "/dev/ttyUSB0";
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
if (args.length > 0)
defaultDev = args[0];
System.out.println("Using device " + defaultDev);
System.out.println("Initializing...");
// Instantiate an H803X instance, using MODBUS slave address 1, and
// default comm parameters (9600, 8, N, 2)
H803X sensor = new H803X(defaultDev, 1);
// output the Slave ID (manufacturer, model, serno)
System.out.println("Slave ID: " + sensor.getSlaveID());
System.out.println();
while (true)
{
// update our values from the sensor
sensor.update();
// H8035 / H8036
System.out.println("Consumption (kWh): "
+ sensor.getConsumption());
System.out.println("Real Power (kW): "
+ sensor.getRealPower());
if (sensor.isH8036())
{
// The H8036 has much more data available...
System.out.println("Reactive Power (kVAR): "
+ sensor.getReactivePower());
System.out.println("Apparent Power (kVA): "
+ sensor.getApparentPower());
System.out.println("Power Factor: "
+ sensor.getPowerFactor());
System.out.println("Volts Line to Line: "
+ sensor.getVoltsLineToLine());
System.out.println("Volts Line to Neutral: "
+ sensor.getVoltsLineToNeutral());
System.out.println("Current: " + sensor.getCurrent());
System.out.println("Real Power Phase A (kW): "
+ sensor.getRealPowerPhaseA());
System.out.println("Real Power Phase B (kW): "
+ sensor.getRealPowerPhaseB());
System.out.println("Real Power Phase C (kW): "
+ sensor.getRealPowerPhaseC());
System.out.println("Power Factor Phase A: "
+ sensor.getPowerFactorPhaseA());
System.out.println("Power Factor Phase B: "
+ sensor.getPowerFactorPhaseB());
System.out.println("Power Factor Phase C: "
+ sensor.getPowerFactorPhaseC());
System.out.println("Volts Phase A to B: "
+ sensor.getVoltsPhaseAToB());
System.out.println("Volts Phase B to C: "
+ sensor.getVoltsPhaseBToC());
System.out.println("Volts Phase A to C: "
+ sensor.getVoltsPhaseAToC());
System.out.println("Volts Phase A to Neutral: "
+ sensor.getVoltsPhaseAToNeutral());
System.out.println("Volts Phase B to Neutral: "
+ sensor.getVoltsPhaseBToNeutral());
System.out.println("Volts Phase C to Neutral: "
+ sensor.getVoltsPhaseCToNeutral());
System.out.println("Current Phase A: "
+ sensor.getCurrentPhaseA());
System.out.println("Current Phase B: "
+ sensor.getCurrentPhaseB());
System.out.println("Current Phase C: "
+ sensor.getCurrentPhaseC());
System.out.println("Avg Real Power (kW): "
+ sensor.getAvgRealPower());
System.out.println("Min Real Power (kW): "
+ sensor.getMinRealPower());
System.out.println("Max Real Power (kW): "
+ sensor.getMaxRealPower());
}
System.out.println();
Thread.sleep(2000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,64 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_teams.TEAMS;
public class TEAMS_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
System.out.println("Initializing...");
// Instantiate an TEAMS instance, using A0 for temperature, and
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
// interface)
TEAMS sensor = new TEAMS(0, 165.0f);
while (true)
{
// update our values from the sensor
sensor.update();
// is the sensor connected? (current >= 4ma)
System.out.println("Is Connected: " + sensor.isConnected());
// print computed current on the loop. This includes
// the offset, if one was set by setOffsetMilliamps().
System.out.println("Milliamps: " + sensor.getRawMilliamps());
// we show both C and F for temperature
System.out.println("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
System.out.println();
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,71 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_tex00.TEX00;
public class TEX00_Example
{
public static void main(String[] args) throws InterruptedException
{
// ! [Interesting]
System.out.println("Initializing...");
// Instantiate an TEX00 instance, using A0 for the analog input. In
// this example, we are using a 10K Ohm balance resistor and a TED
// (10k type 2) thermistor.
TEX00 sensor = new TEX00(0, 10000.0f,
TEX00.SENSOR_TYPES_T.STYPE_THERMISTOR_TED);
System.out.println("Minimum temperature: "
+ sensor.getTemperatureRangeMin());
System.out.println("Maximum temperature: "
+ sensor.getTemperatureRangeMax());
System.out.println();
while (true)
{
// update our values from the sensor
sensor.update();
if (sensor.isOutOfRange())
{
System.out.println("Temperature out of range");
}
else
{
// we show both C and F for temperature
System.out.println("Temperature: "
+ sensor.getTemperature()
+ " C / "
+ sensor.getTemperature(true)
+ " F");
}
System.out.println();
Thread.sleep(1000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,47 @@
/*
* Author: Abhishek Malik <abhishek.malik@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_th02.TH02;
public class Th02Example {
public static void main(String[] args) {
// TODO Auto-generated method stub
float temperature = 0;
float humidity = 0;
TH02 sensor = new TH02();
while(true){
temperature = sensor.getTemperature();
humidity = sensor.getHumidity();
System.out.println("Temperature = "+temperature+", Humidity = "+humidity);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
System.out.println("The following exception has occured: "+e.getMessage());
}
}
}
}

View File

@ -0,0 +1,44 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var lib = require('jsupm_apa102');
// Instantiate a strip of 30 LEDs on SPI Bus 0
var ledStrip = new lib.APA102(30, 0);
// Set all LEDs to blue
ledStrip.setAllLeds(31, 0, 0, 255);
// Set a mid-section to red
ledStrip.setLeds(10,20, 31, 255, 0, 0);
// Set a single led to green
ledStrip.setLed(15, 31, 0, 255, 0);
// Exit
ledStrip = null;
process.exit(0);

View File

@ -0,0 +1,51 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var bme280pkg = require('jsupm_bme280');
// Instantiate a BME280 Sensor on I2C sub-platform bus 0
var bme280 = new bme280pkg.BME280(512);
// update every second and print the values
var myInterval = setInterval(function()
{
// print detected value
console.log("Temperature: " + bme280.getTemperatureCelcius() + "C");
console.log("Humidity: " + bme280.getHumidityRelative() + "%");
console.log("Pressure: " + bme280.getPressurePa() + "Pa");
}, 1000);
// When exiting: clear interval and print message
process.on('SIGINT', function()
{
clearInterval(myInterval);
bme280 = null
bme280pkg = null;
console.log("Exiting");
process.exit(0);
});

View File

@ -0,0 +1,71 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_bmi160');
// Instantiate a BMI160 instance using default i2c bus and address
var sensor = new sensorObj.BMI160();
var x = new sensorObj.new_floatp();
var y = new sensorObj.new_floatp();
var z = new sensorObj.new_floatp();
// Output data every half second until interrupted
setInterval(function()
{
// update our values from the sensor
sensor.update();
sensor.getAccelerometer(x, y, z);
console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) +
" AY: " + sensorObj.floatp_value(y) +
" AZ: " + sensorObj.floatp_value(z));
sensor.getGyroscope(x, y, z);
console.log("Gyroscope: GX: " + sensorObj.floatp_value(x) +
" AY: " + sensorObj.floatp_value(y) +
" AZ: " + sensorObj.floatp_value(z));
sensor.getMagnetometer(x, y, z);
console.log("Magnetometer: MX: " + sensorObj.floatp_value(x) +
" MY: " + sensorObj.floatp_value(y) +
" MZ: " + sensorObj.floatp_value(z));
console.log();
}, 500);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,52 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Ron Evans (@deadprogram)
* 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 mraa = require('mraa');
console.log('MRAA Version: ' + mraa.getVersion());
// open connection to Firmata
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
var curieImu = require('jsupm_curieimu');
var myCurie = new curieImu.CurieImu();
var outputStr;
var myInterval = setInterval(function()
{
myCurie.updateAccel();
outputStr = "accel: x " + myCurie.getAccelX()
+ " - y " + myCurie.getAccelY()
+ " - z " + myCurie.getAccelZ();
console.log(outputStr);
}, 500);
// Print message when exiting
process.on('SIGINT', function()
{
clearInterval(myInterval);
console.log("Exiting");
process.exit(0);
});

View File

@ -0,0 +1,66 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_cwlsxxa');
/************** Main code **************/
console.log("Initializing...");
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
// humidity and A2 for temperature
var sensor = new sensorObj.CWLSXXA(0, 1, 2);
// update and print available values every second
setInterval(function()
{
// update our values from the sensor
sensor.update();
// we show both C and F for temperature
console.log("Temperature:", sensor.getTemperature(),
"C /", sensor.getTemperature(true), "F");
console.log("Humidity:", sensor.getHumidity(), "%");
console.log("CO2:", sensor.getCO2(), "ppm");
console.log("");
}, 1000);
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);
});

View File

@ -25,9 +25,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Instantiate a Grove Circular LED on gpio pins 5 and 4
var GCL = require("jsupm_grovecircularled");
var circle = new GCL.GroveCircularLED(5, 4);
// Instantiate a Grove Circular LED on gpio pins 9 and 8
var GCL = require("jsupm_my9221");
var circle = new GCL.GroveCircularLED(9, 8);
var level = 0;
// Show a spinner.

View File

@ -26,9 +26,9 @@
var LEDBar = require("jsupm_my9221");
// Instantiate a MY9221, we use D2 for the data, and D3 for the
// Instantiate a MY9221, we use D8 for the data, and D9 for the
// data clock. This was tested with a Grove LED bar.
var myLEDBar = new LEDBar.MY9221(2, 3);
var myLEDBar = new LEDBar.GroveLEDBar(8, 9);
var directionBool = true;

View File

@ -0,0 +1,115 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_h803x');
/************** Main code **************/
var defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (process.argv.length > 2)
{
defaultDev = process.argv[2];
}
console.log("Using device " + defaultDev);
console.log("Initializing...");
// Instantiate an H803X instance, using MODBUS slave address 1, and
// default comm parameters (9600, 8, N, 2)
var sensor = new sensorObj.H803X(defaultDev, 1);
// output the Slave ID (manufacturer, model, serno)
console.log("Slave ID:", sensor.getSlaveID());
console.log("");
// update and print available values every second
setInterval(function()
{
// update our values from the sensor
sensor.update();
// H8035 / H8036
console.log("Consumption (kWh):", sensor.getConsumption());
console.log("Real Power (kW):", sensor.getRealPower());
if (sensor.isH8036())
{
// The H8036 has much more data available...
console.log("Reactive Power (kVAR):", sensor.getReactivePower());
console.log("Apparent Power (kVA):", sensor.getApparentPower());
console.log("Power Factor:", sensor.getPowerFactor());
console.log("Volts Line to Line:", sensor.getVoltsLineToLine());
console.log("Volts Line to Neutral:", sensor.getVoltsLineToNeutral());
console.log("Current:", sensor.getCurrent());
console.log("Real Power Phase A (kW):", sensor.getRealPowerPhaseA());
console.log("Real Power Phase B (kW):", sensor.getRealPowerPhaseB());
console.log("Real Power Phase C (kW):", sensor.getRealPowerPhaseC());
console.log("Power Factor Phase A:", sensor.getPowerFactorPhaseA());
console.log("Power Factor Phase B:", sensor.getPowerFactorPhaseB());
console.log("Power Factor Phase C:", sensor.getPowerFactorPhaseC());
console.log("Volts Phase A to B:", sensor.getVoltsPhaseAToB());
console.log("Volts Phase B to C:", sensor.getVoltsPhaseBToC());
console.log("Volts Phase A to C:", sensor.getVoltsPhaseAToC());
console.log("Volts Phase A to Neutral: ",
sensor.getVoltsPhaseAToNeutral());
console.log("Volts Phase B to Neutral: ",
sensor.getVoltsPhaseBToNeutral());
console.log("Volts Phase C to Neutral: ",
sensor.getVoltsPhaseCToNeutral());
console.log("Current Phase A:", sensor.getCurrentPhaseA());
console.log("Current Phase B:", sensor.getCurrentPhaseB());
console.log("Current Phase C:", sensor.getCurrentPhaseC());
console.log("Avg Real Power (kW):", sensor.getAvgRealPower());
console.log("Min Real Power (kW):", sensor.getMinRealPower());
console.log("Max Real Power (kW):", sensor.getMaxRealPower());
}
console.log("");
}, 2000);
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);
});

View File

@ -0,0 +1,70 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_teams');
/************** Main code **************/
console.log("Initializing...");
// Instantiate an TEAMS instance, using A0 for temperature, and
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
// interface)
var sensor = new sensorObj.TEAMS(0, 165.0);
// update and print available values every second
setInterval(function()
{
// update our values from the sensor
sensor.update();
// is the sensor connected? (current >= 4ma)
console.log("Is Connected:", sensor.isConnected());
// print computed current on the loop. This includes the offset,
// if one was set by setOffsetMilliamps().
console.log("Milliamps:", sensor.getRawMilliamps());
// we show both C and F for temperature
console.log("Temperature:", sensor.getTemperature(),
"C /", sensor.getTemperature(true), "F");
console.log("");
}, 1000);
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);
});

View File

@ -0,0 +1,77 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var sensorObj = require('jsupm_tex00');
/************** Main code **************/
console.log("Initializing...");
// Instantiate an TEX00 instance, using A0 for the analog input. In
// this example, we are using a 10K Ohm balance resistor and a TED
// (10k type 2) thermistor.
var sensor = new sensorObj.TEX00(0, 10000,
sensorObj.TEX00.STYPE_THERMISTOR_TED);
console.log("Minimum temperature:", sensor.getTemperatureRangeMin(),
"C");
console.log("Maximum temperature:", sensor.getTemperatureRangeMax(),
"C");
console.log("");
// update and print available values every second
setInterval(function()
{
// update our values from the sensor
sensor.update();
if (sensor.isOutOfRange())
{
console.log("Temperature out of range");
}
else
{
// we show both C and F for temperature
console.log("Temperature:", sensor.getTemperature(),
"C /", sensor.getTemperature(true), "F");
}
console.log("");
}, 1000);
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting...");
process.exit(0);
});

48
examples/python/apa102.py Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/python
# Author: Yannick Adam <yannick.adam@gmail.com>
# Copyright (c) 2016 Yannick Adam
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_apa102 as mylib
# Instantiate a strip of 30 LEDs on SPI bus 0
ledStrip = mylib.APA102(30, 0, False)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# Register exit handlers
signal.signal(signal.SIGINT, SIGINTHandler)
print "Setting all LEDs to Green"
ledStrip.setAllLeds(31, 0, 255, 0)
print "Setting LEDs between 10 and 20 to Red"
ledStrip.setLeds(10, 20, 31, 255, 0, 0)
print "Setting LED 15 to Blue"
ledStrip.setLed(15, 31, 0, 0, 255)

66
examples/python/bmi160.py Normal file
View File

@ -0,0 +1,66 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_bmi160 as sensorObj
# Instantiate a BMI160 instance using default i2c bus and address
sensor = sensorObj.BMI160()
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
x = sensorObj.new_floatp()
y = sensorObj.new_floatp()
z = sensorObj.new_floatp()
while (1):
sensor.update()
sensor.getAccelerometer(x, y, z)
print "Accelerometer: AX: ", sensorObj.floatp_value(x),
print " AY: ", sensorObj.floatp_value(y),
print " AZ: ", sensorObj.floatp_value(z)
sensor.getGyroscope(x, y, z)
print "Gyroscope: GX: ", sensorObj.floatp_value(x),
print " GY: ", sensorObj.floatp_value(y),
print " GZ: ", sensorObj.floatp_value(z)
sensor.getMagnetometer(x, y, z)
print "Magnetometer: MX: ", sensorObj.floatp_value(x),
print " MY: ", sensorObj.floatp_value(y),
print " MZ: ", sensorObj.floatp_value(z)
print
time.sleep(.5)

View File

@ -0,0 +1,56 @@
#!/usr/bin/python
# Author: Ron Evans (@deadprogram)
# 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 mraa
print (mraa.getVersion())
# open connection to Firmata
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
import time, sys, signal, atexit
import pyupm_curieimu as curieimu
sensor = curieimu.CurieImu()
## Exit handlers ##
def SIGINTHandler(signum, frame):
raise SystemExit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
while(1):
sensor.updateAccel();
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
sensor.getAccelX(), sensor.getAccelY(),
sensor.getAccelZ())
print outputStr
time.sleep(1)

View File

@ -0,0 +1,61 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_cwlsxxa as sensorObj
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
print "Initializing..."
# Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
# humidity and A2 for temperature
sensor = sensorObj.CWLSXXA(0, 1, 2)
# update and print available values every second
while (1):
# update our values from the sensor
sensor.update()
# we show both C and F for temperature
print "Temperature:", sensor.getTemperature(), "C /",
print sensor.getTemperature(True), "F"
print "Humidity:", sensor.getHumidity(), "%"
print "CO2:", sensor.getCO2(), "ppm"
print
time.sleep(1)

View File

@ -23,7 +23,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_grovecircularled as upmGroveCircularLED
import pyupm_my9221 as upmGroveCircularLED
# Exit handlers
def SIGINTHandler(signum, frame):
@ -39,8 +39,8 @@ atexit.register(exitHandler)
# This function stops python from printing a stacktrace when you hit control-C
signal.signal(signal.SIGINT, SIGINTHandler)
# Instantiate a Grove Circular LED on gpio pins 5 and 4
circle = upmGroveCircularLED.GroveCircularLED(5, 4)
# Instantiate a Grove Circular LED on gpio pins 9 and 8
circle = upmGroveCircularLED.GroveCircularLED(9, 8)
level = 0

View File

@ -24,9 +24,9 @@
import time, sys, signal, atexit
import pyupm_my9221 as upmMy9221
# Instantiate a MY9221, we use D2 for the data, and D3 for the
# Instantiate a MY9221, we use D8 for the data, and D9 for the
# data clock. This was tested with a Grove LED bar.
myLEDBar = upmMy9221.MY9221(2, 3)
myLEDBar = upmMy9221.GroveLEDBar(8, 9)
# Exit handlers

106
examples/python/h803x.py Normal file
View File

@ -0,0 +1,106 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_h803x as sensorObj
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting..."
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
defaultDev = "/dev/ttyUSB0"
# if an argument was specified, use it as the device instead
if (len(sys.argv) > 1):
defaultDev = sys.argv[1]
print "Using device", defaultDev
print "Initializing..."
# Instantiate an H803X instance, using MODBUS slave address 1, and
# default comm parameters (9600, 8, N, 2)
sensor = sensorObj.H803X(defaultDev, 1)
# output the serial number and firmware revision
print "Slave ID:", sensor.getSlaveID()
print
# update and print available values every second
while (1):
# update our values from the sensor
sensor.update()
# H8035 / H8036
print "Consumption (kWh):", sensor.getConsumption()
print "Real Power (kW):", sensor.getRealPower()
if (sensor.isH8036()):
# The H8036 has much more data available...
print "Reactive Power (kVAR):", sensor.getReactivePower()
print "Apparent Power (kVA):", sensor.getApparentPower()
print "Power Factor:", sensor.getPowerFactor()
print "Volts Line to Line:", sensor.getVoltsLineToLine()
print "Volts Line to Neutral:", sensor.getVoltsLineToNeutral()
print "Current:", sensor.getCurrent()
print "Real Power Phase A (kW):", sensor.getRealPowerPhaseA()
print "Real Power Phase B (kW):", sensor.getRealPowerPhaseB()
print "Real Power Phase C (kW):", sensor.getRealPowerPhaseC()
print "Power Factor Phase A:", sensor.getPowerFactorPhaseA()
print "Power Factor Phase B:", sensor.getPowerFactorPhaseB()
print "Power Factor Phase C:", sensor.getPowerFactorPhaseC()
print "Volts Phase A to B:", sensor.getVoltsPhaseAToB()
print "Volts Phase B to C:", sensor.getVoltsPhaseBToC()
print "Volts Phase A to C:", sensor.getVoltsPhaseAToC()
print "Volts Phase A to Neutral: ",
print sensor.getVoltsPhaseAToNeutral()
print "Volts Phase B to Neutral: ",
print sensor.getVoltsPhaseBToNeutral()
print "Volts Phase C to Neutral: ",
print sensor.getVoltsPhaseCToNeutral()
print "Current Phase A:", sensor.getCurrentPhaseA()
print "Current Phase B:", sensor.getCurrentPhaseB()
print "Current Phase C:", sensor.getCurrentPhaseC()
print "Avg Real Power (kW):", sensor.getAvgRealPower()
print "Min Real Power (kW):", sensor.getMinRealPower()
print "Max Real Power (kW):", sensor.getMaxRealPower()
print
time.sleep(2)

65
examples/python/teams.py Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_teams as sensorObj
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
print "Initializing..."
# Instantiate an TEAMS instance, using A0 for temperature, and
# 165.0 ohms for the rResistor value (for the libelium 4-20ma
# interface)
sensor = sensorObj.TEAMS(0, 165.0)
# update and print available values every second
while (1):
# update our values from the sensor
sensor.update()
# is the sensor connected? (current >= 4ma)
print "Is Connected:", sensor.isConnected()
# print computed current on the loop. This includes the offset,
# if one was set by setOffsetMilliamps().
print "Milliamps:", sensor.getRawMilliamps()
# we show both C and F for temperature
print "Temperature:", sensor.getTemperature(), "C /",
print sensor.getTemperature(True), "F"
print
time.sleep(1)

65
examples/python/tex00.py Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_tex00 as sensorObj
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
print "Initializing..."
# Instantiate an TEX00 instance, using A0 for the analog input. In
# this example, we are using a 10K Ohm balance resistor and a TED
# (10k type 2) thermistor.
sensor = sensorObj.TEX00(0, 10000, sensorObj.TEX00.STYPE_THERMISTOR_TED)
print "Minimum temperature:", sensor.getTemperatureRangeMin(), "C"
print "Maximum temperature:", sensor.getTemperatureRangeMax(), "C"
print
# update and print available values every second
while (1):
# update our values from the sensor
sensor.update()
if (sensor.isOutOfRange()):
print "Temperature out of range"
else:
# we show both C and F for temperature
print "Temperature:", sensor.getTemperature(), "C /",
print sensor.getTemperature(True), "F"
print
time.sleep(1)

View File

@ -28,6 +28,7 @@ endmacro (upm_CREATE_INSTALL_PKGCONFIG)
macro(upm_SWIG_PYTHON)
if (BUILDSWIGPYTHON AND BUILDSWIG)
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
@ -46,16 +47,30 @@ endmacro()
macro(upm_SWIG_NODE)
if (BUILDSWIGNODE AND BUILDSWIG)
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
# we hack together from our findnode module.
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
while (V8_VERSION_HEX_length LESS 8)
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
endwhile ()
# include_directories (${NODE_INCLUDE_DIRS})
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PUBLIC
"${NODE_INCLUDE_DIRS}"
)
set_target_properties (jsupm_${libname} PROPERTIES
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}"
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
PREFIX ""
SUFFIX ".node"
)
@ -65,12 +80,29 @@ macro(upm_SWIG_NODE)
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
endif()
endif()
if (NOT ENABLECXX11)
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
endif ()
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
else ()
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
endif ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
endif ()
endif ()
endif()
createpackagejson(${libname})
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
endif()
endmacro()
@ -100,12 +132,8 @@ macro(upm_SWIG_JAVA)
PREFIX "lib"
SUFFIX ".so"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libjavaupm_${libname}.so
DESTINATION lib/java
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar
DESTINATION lib/java
)
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
@ -144,11 +172,10 @@ endmacro()
if (SWIG_FOUND)
if (BUILDSWIGPYTHON)
find_package (PythonLibs)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
endif(BUILDSWIGPYTHON)
if(NOT PYTHONLIBS_FOUND)
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
endif()
endif()
if (BUILDSWIGNODE)
if(NOT NODE_FOUND)
find_package(Node)
@ -156,17 +183,18 @@ if (SWIG_FOUND)
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
endif()
find_path (NODE_ROOT_DIR "node/node.h")
find_path (NODE_ROOT_DIR "include/node/node.h")
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
${NODE_ROOT_DIR}/include/src
${NODE_ROOT_DIR}/include/node
${NODE_ROOT_DIR}/include/deps/v8/include
${NODE_ROOT_DIR}/include/deps/uv/include
)
macro(createpackagejson)
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
endmacro()
endif(BUILDSWIGNODE)

View File

@ -70,7 +70,7 @@ void A110X::installISR(void (*isr)(void *), void *arg)
uninstallISR();
// install our interrupt handler
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_FALLING,
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_BOTH,
isr, arg);
m_isrInstalled = true;
}

View File

@ -9,9 +9,11 @@ add_dependencies(${libname} pca9685)
target_link_libraries(${libname} pca9685)
if (BUILDSWIG)
if (BUILDSWIGNODE)
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (jsupm_${libname} pca9685 ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
endif()
if (BUILDSWIGPYTHON)
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
swig_link_libraries (pyupm_${libname} pca9685 ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
endif()
endif()

View File

@ -30,15 +30,63 @@ ADS1015::setSPS(ADSSAMPLERATE rate){
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
}
ADS1015::ADS1015(int bus, uint8_t address) : ADS1X15(bus, address) {
ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
m_name = "ADS1015";
m_conversionDelay = ADS1015_CONVERSIONDELAY;
m_bitShift = 4;
ADS1X15::getCurrentConfig();
if (vref < 0.0 || vref > 6.144)
UPM_THROW("vref out of range");
else if (vref > 4.096)
setGain(GAIN_TWOTHIRDS);
else if (vref > 2.048)
setGain(GAIN_ONE);
else if (vref > 1.024)
setGain(GAIN_TWO);
else if (vref > 0.512)
setGain(GAIN_FOUR);
else if (vref > 0.256)
setGain(GAIN_EIGHT);
else
setGain(GAIN_SIXTEEN);
}
ADS1015::~ADS1015(){};
const char*
ADS1015::getModuleName() {
return m_name.c_str();
}
unsigned int
ADS1015::getNumInputs() {
return 4;
}
unsigned int
ADS1015::getResolutionInBits() {
return 12;
}
uint16_t
ADS1015::getRawValue(unsigned int input) {
ADS1X15::ADSMUXMODE mode = getMuxMode(input);
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
usleep(m_conversionDelay);
uint16_t value = i2c->readWordReg(ADS1X15_REG_POINTER_CONVERT);
value = value >> m_bitShift;
return swapWord(value);
}
float
ADS1015::getVoltage(unsigned int input) {
ADSMUXMODE mode = getMuxMode(input);
return getSample(mode);
}
//Private functions
float
ADS1015::getMultiplier(void){
@ -99,4 +147,20 @@ ADS1015::setDelay(){
}
}
ADS1X15::ADSMUXMODE
ADS1015::getMuxMode(unsigned int input) {
ADS1X15::ADSMUXMODE mode;
switch (input) {
case 0:
return SINGLE_0;
case 1:
return SINGLE_1;
case 2:
return SINGLE_2;
case 3:
return SINGLE_3;
default:
UPM_THROW("Invalid input");
}
}

View File

@ -26,8 +26,9 @@
#pragma once
#include "ads1x15.h"
#include "upm/iADC.h"
#define ADS1015_VREF 2.048
/*=========================================================================
CONVERSION DELAY (in microS)
@ -55,8 +56,8 @@
namespace upm {
/**
* @library ads1x15
* @sensor ADS1115
* @comname ADS1115 ADC
* @sensor ADS1015
* @comname ADS1015 ADC
* @type electric
* @man ti adafruit
* @con i2c
@ -82,7 +83,7 @@ namespace upm {
* @image html ads1015.jpg
* @snippet ads1x15.cxx Interesting
*/
class ADS1015 : public ADS1X15 {
class ADS1015 : public ADS1X15, public IADC {
public:
@ -111,12 +112,16 @@ namespace upm {
/**
* ADS1X15 constructor
* ADS1015 constructor
*
* This constructor includes a vref parameter that can be used
* to set gain so it matches full scale value of input
*
* @param bus i2c bus the sensor is attached to.
* @param address. Device address. Default is 0x48.
* @param address. Optional device address. Default is 0x48.
* @param vref. Optional reference (i.e. half full swing) voltage. Default is 2.048V
*/
ADS1015 (int bus, uint8_t address = 0x48);
ADS1015 (int bus, uint8_t address = 0x48, float vref = ADS1015_VREF);
/**
* ADS1X15 destructor
@ -132,9 +137,48 @@ namespace upm {
*/
void setSPS(ADSSAMPLERATE rate = SPS_1600);
/**
* Get number of inputs
*
* @return number of inputs
*/
unsigned int getNumInputs();
/**
* Read current value for current single ended analogue input
*
* @return current conversion value
*/
uint16_t getRawValue(unsigned int input);
/**
* Read current voltage for current single ended analogue input
*
* @return current voltage
*/
float getVoltage(unsigned int input);
/**
* Read current voltage for current single ended analogue input
*
* @return current voltage
*/
unsigned int getResolutionInBits();
/**
* Returns module name
*
* @return modulename as const char*
*/
const char* getModuleName();
protected:
float getMultiplier(void);
void setDelay(void);
private:
ADS1X15::ADSMUXMODE getMuxMode(unsigned int input);
};
}

View File

@ -65,6 +65,7 @@ namespace upm {
*
* This driver was developed using the DFRobot ADXRS610 Gyro Beakout board.
*
* @image html adxrs610.jpg
* @snippet adxrs610.cxx Interesting
*/

View File

@ -233,7 +233,8 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
uint8_t
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
{
uint8_t tdata[16] = { AM2315_READ, reg, ilen };
uint8_t tdata[16] = { AM2315_READ, static_cast<uint8_t>(reg),
static_cast<uint8_t>(ilen) };
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
int iLoops = 5;

View File

@ -0,0 +1,5 @@
set (libname "apa102")
set (libdescription "upm apa102 led strip spi output module")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

166
src/apa102/apa102.cxx Normal file
View File

@ -0,0 +1,166 @@
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <stdlib.h>
#include <unistd.h>
#include "apa102.h"
using namespace upm;
APA102::APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode, int8_t csn)
: m_ledCount(ledCount), m_batchMode(batchMode)
{
mraa::Result res = mraa::SUCCESS;
m_leds = NULL;
// Optional chip select pin
m_csnPinCtx = NULL;
if (csn > -1) {
m_csnPinCtx = new mraa::Gpio(csn);
res = m_csnPinCtx->dir(mraa::DIR_OUT);
if (res != mraa::SUCCESS) {
throw std::invalid_argument(std::string(__FUNCTION__) +
": GPIO failed to set direction");
}
}
CSOff();
// Initialize SPI
m_spi = new mraa::Spi(spiBus);
// Initialize LED array
uint16_t endFrameLength = (m_ledCount + 15) / 16; // End frame should be (leds/2) bits
m_frameLength = endFrameLength + (m_ledCount + 1) * 4;
if ((m_leds = (uint8_t*) malloc(m_frameLength))) {
memset(m_leds, 0x00, m_frameLength - 4); // Clear state
memset(&m_leds[m_frameLength - endFrameLength], 0xFF, endFrameLength); // Frame End
// Need to set the brightness to "0" for each Led
for (int i = 1; i <= m_ledCount; i++) {
m_leds[i * 4] = 224;
}
} else {
throw std::runtime_error(std::string(__FUNCTION__) +
": Failed to allocate memory for LED Strip");
}
}
APA102::~APA102()
{
// Clear leds
if (m_leds) {
free(m_leds);
}
// Clear SPI
if (m_spi) {
delete m_spi;
}
// Clear GPIO
if (m_csnPinCtx) {
delete m_csnPinCtx;
}
}
void
APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
{
setLeds(ledIdx, ledIdx, brightness, r, g, b);
}
void
APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
{
setLeds(0, m_ledCount - 1, brightness, r, g, b);
}
void
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
{
uint16_t s_idx = (startIdx + 1) * 4;
uint16_t e_idx = (endIdx + 1) * 4;
for (uint16_t i = s_idx; i <= e_idx; i += 4) {
m_leds[i] = brightness | 224;
m_leds[i + 1] = b;
m_leds[i + 2] = g;
m_leds[i + 3] = r;
}
if (!m_batchMode) {
pushState();
}
}
void
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
{
uint16_t s_idx = (startIdx + 1) * 4;
memcpy(&m_leds[s_idx], colors, (endIdx - startIdx + 1) * 4);
if (!m_batchMode) {
pushState();
}
}
void
APA102::pushState(void)
{
CSOn();
m_spi->write(m_leds, m_frameLength);
CSOff();
}
/*
* **************
* private area
* **************
*/
mraa::Result
APA102::CSOn()
{
if (m_csnPinCtx) {
return m_csnPinCtx->write(HIGH);
}
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
}
mraa::Result
APA102::CSOff()
{
if (m_csnPinCtx) {
return m_csnPinCtx->write(LOW);
}
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
}

143
src/apa102/apa102.h Normal file
View File

@ -0,0 +1,143 @@
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <mraa/gpio.hpp>
#include <mraa/spi.hpp>
#include <string>
#define HIGH 1
#define LOW 0
namespace upm
{
/**
* @brief APA102 RGB LED Strip driver library
* @defgroup apa102 libupm-apa102
* @ingroup spi led
*/
/**
* @library apa102
* @sensor apa102
* @comname APA102/DotStar LED Strip
* @type led
* @man adafruit
* @con spi
*
* @brief API for controlling APA102/DotStar RGB LED Strips
*
* APA102 LED Strips provide individually controllable LEDs through a SPI interface.
* For each LED, brightness (0-31) and RGB (0-255) values can be set.
*
* @image html apa102.jpg
* @snippet apa102.cxx Interesting
*/
class APA102
{
public:
/**
* Instantiates a new APA102 LED Strip
*
* @param ledCount Number of APA102 leds in the strip
* @param spiBus SPI Bus number
* @param batchMode (optional) Immediatly write to SPI (false, default) or wait for a pushState
* call (true)
* @param csn (optional) Chip Select Pin
*/
APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode = false, int8_t csn = -1);
/**
* APA102 destructor
*/
~APA102();
/**
* Change the color for a single led
*
* @param ledIdx Index of the LED in the strip (0 based)
* @param brightness Brightness value (0-31)
* @param r Red component (0-255)
* @param g Green component (0-255)
* @param b Blue component (0-255)
*/
void setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
/**
* Change the color for all leds
*
* @param brightness Brightness value (0-31)
* @param r Red component (0-255)
* @param g Green component (0-255)
* @param b Blue component (0-255)
*/
void setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
/**
* Change the color for a range of leds
*
* @param startIdx Start index of the range of LEDs in the strip (0 based)
* @param endIdx End index of the range of LEDs in the strip (0 based)
* @param brightness Brightness value (0-31)
* @param r Red component (0-255)
* @param g Green component (0-255)
* @param b Blue component (0-255)
*/
void
setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
/**
* (Advanced) Manually control the colors of a range of LEDS
* Best used to maximize performance
*
* @param startIdx Start index of the range of LEDs to update (0 based)
* @param endIdx End index of the range of LEDs to update (0 based)
* @param colors Pointer to an array of bytes. Each color is described as the following:
* B1: Brightness (224-255) B2: Blue (0-255) B3: Green (0-255) B4: Red
*(0-255)
* No check done on the boundaries
*/
void setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors);
/**
* Outputs the current LED data to the SPI bus
* Note: Only required if batch mode is set to TRUE
*
*/
void pushState();
private:
mraa::Spi* m_spi;
mraa::Gpio* m_csnPinCtx;
uint16_t m_ledCount;
uint8_t* m_leds;
uint16_t m_frameLength;
bool m_batchMode;
mraa::Result CSOn();
mraa::Result CSOff();
};
}

View File

@ -0,0 +1,30 @@
%module javaupm_apa102
%include "../upm.i"
%include "typemaps.i"
%typemap(jtype) (uint8_t *colors) "byte[]"
%typemap(jstype) (uint8_t *colors) "byte[]"
%typemap(jni) (uint8_t *colors) "jbyteArray"
%typemap(javain) (uint8_t *colors) "$javainput"
%typemap(in) (uint8_t *colors) {
$1 = (uint8_t*)JCALL2(GetByteArrayElements, jenv, $input, NULL);
}
%{
#include "apa102.h"
%}
%include "apa102.h"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_apa102");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

19
src/apa102/jsupm_apa102.i Normal file
View File

@ -0,0 +1,19 @@
%module jsupm_apa102
%include "../upm.i"
%inline %{
#include <node_buffer.h>
%}
%typemap(in) (uint8_t *colors) {
if (!node::Buffer::HasInstance($input)) {
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
}
$1 = (uint8_t*) node::Buffer::Data($input);
}
%include "apa102.h"
%{
#include "apa102.h"
%}

25
src/apa102/pyupm_apa102.i Normal file
View File

@ -0,0 +1,25 @@
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%module pyupm_apa102
%include "../upm.i"
%feature("autodoc", "3");
// setLeds
%typemap(in) (uint8_t *colors) {
if (PyByteArray_Check($input)) {
$1 = (uint8_t*) PyByteArray_AsString($input);
} else {
PyErr_SetString(PyExc_ValueError, "bytearray expected");
return NULL;
}
}
%include "apa102.h"
%{
#include "apa102.h"
%}

View File

@ -63,6 +63,7 @@ namespace upm {
*
* This driver was developed on a DFRobot BMA (Tiny).
*
* @image html bma220.jpg
* @snippet bma220.cxx Interesting
*/

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