java: Added java examples for some sensors

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Stefan Andritoiu 2015-10-02 17:31:43 +03:00 committed by Mihai Tudor Panu
parent 9d63545d44
commit 5ff625eaf4
24 changed files with 1187 additions and 28 deletions

View File

@ -23,29 +23,30 @@
*/
public class A110XSample {
static {
try {
System.loadLibrary("javaupm_a110x");
} catch (UnsatisfiedLinkError e) {
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String argv[]) throws InterruptedException {
//! [Interesting]
// Instantiate an A110X sensor on digital pin D2
upm_a110x.A110X a110x = new upm_a110x.A110X(2);
while(true) {
if(a110x.magnetDetected()) {
System.out.println("magnet detected...");
}
else {
System.out.println("magnet not detected...");
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate an A110X sensor on digital pin D2
upm_a110x.A110X hall = new upm_a110x.A110X(2);
// check every second for the presence of a magnetic field (south polarity)
while(true){
if(hall.magnetDetected())
System.out.println("Magnet (south polarity) detected.");
else
System.out.println("No magnet detected.");
Thread.sleep(1000);
}
//! [Interesting]
//! [Interesting]
}
}
}

View File

@ -0,0 +1,68 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
import upm_a110x.IsrCallback;
public class A110X_intrSample {
public static int counter=0;
static {
try {
System.loadLibrary("javaupm_a110x");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate an A110X sensor on digital pin D2
upm_a110x.A110X hall = new upm_a110x.A110X(2);
// This example uses a user-supplied interrupt handler to count
// pulses that occur when a magnetic field of the correct polarity
// is detected. This could be used to measure the rotations per
// minute (RPM) of a rotor for example.
IsrCallback callback = new A110XISR();
hall.installISR(callback);
while(true){
System.out.println("Counter: " + counter);
Thread.sleep(1000);
}
//! [Interesting]
}
}
class A110XISR extends IsrCallback {
public A110XISR(){
super();
}
public void run(){
A110X_intrSample.counter++;
}
}

View File

@ -28,7 +28,7 @@ public class ENC03RSample {
static {
try {
System.loadLibrary("upm_enc03r");
System.loadLibrary("javaupm_enc03r");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);

View File

@ -0,0 +1,75 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class GROVESCAMSample{
static {
try {
System.loadLibrary("javaupm_grovescam");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a Grove Serial Camera on UART 0
upm_grovescam.GROVESCAM camera = new upm_grovescam.GROVESCAM(0);
// make sure port is initialized properly. 115200 baud is the default.
if(!camera.setupTty()){
System.err.println("Failed to setup tty port parameters");
System.exit(-1);
}
if(camera.init())
System.out.println("Initialized...");
else
System.out.println("Initialization failed");
if(camera.preCapture())
System.out.println("preCapture succeeded...");
else
System.out.println("preCapture failed.");
if(camera.doCapture())
System.out.println("doCapture succeeded...");
else
System.out.println("doCapture failed.");
if(camera.getImageSize() > 0){
System.out.println("Storing image.jpg...");
if(camera.storeImage("image.jpg"))
System.out.println("storeImage succeeded...");
else
System.out.println("storeImage failed.");
}
//! [Interesting]
}
}

View File

@ -0,0 +1,62 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class GroveEHRSample {
static {
try {
System.loadLibrary("javaupm_groveehr");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
upm_groveehr.GroveEHR heart = new upm_groveehr.GroveEHR(2);
// set the beat counter to 0, init the clock and start counting beats
heart.clearBeatCounter();
heart.initClock();
heart.startBeatCounter();
while(true){
long millis = heart.getMillis();
long beats = heart.beatCounter();
// heartRate() requires that at least 5 seconds pass before
// returning anything other than 0
int hr = heart.heartRate();
// output milliseconds passed, beat count, and computed heart rate
System.out.println("Millis: " + millis + ", Beats: " + beats + ", Heart rate: " + hr);
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,58 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
public class GroveMDSample{
private static final short speed50 = 127;
private static final short speed0 = 0;
static {
try {
System.loadLibrary("javaupm_grovemd");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
// Instantiate an I2C Grove Motor Driver on I2C bus 0
upm_grovemd.GroveMD motors = new upm_grovemd.GroveMD();
// set direction to clockwise (CW) and set speed to 50%
System.out.println("Spin M1 and M2 at half speed for 3 seconds");
motors.setMotorDirections(upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CW, upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CW );
motors.setMotorSpeeds(speed50, speed50);
Thread.sleep(3000);
// counter clockwise (CCW)
System.out.println("Reversing M1 and M2 for 3 seconds");
motors.setMotorDirections(upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CCW, upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CCW );
Thread.sleep(3000);
// stop motors
System.out.println("Stopping motors");
motors.setMotorSpeeds(speed0, speed0);
}
}

View File

@ -0,0 +1,53 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class GroveWFSSample {
static {
try {
System.loadLibrary("javaupm_grovewfs");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a Grove Water Flow Sensor on digital pin D2
upm_grovewfs.GroveWFS flow = new upm_grovewfs.GroveWFS(2);
flow.clearFlowCounter();
flow.startFlowCounter();
while(true){
System.out.print("Millis: " + flow.getMillis() + " FlowCount: " + flow.flowCounter());
System.out.println(" Flow Rate: " + flow.flowRate() + " LPM");
Thread.sleep(2000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,61 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class H3LIS331DLSample {
static {
try {
System.loadLibrary("javaupm_h3lis331dl");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
int[] val;
float[] accel;
// Instantiate an H3LIS331DL on I2C bus 0
upm_h3lis331dl.H3LIS331DL sensor = new upm_h3lis331dl.H3LIS331DL(0);
// Initialize the device with default values
sensor.init();
while(true){
sensor.update();
val = sensor.getRawXYZ();
System.out.println( "Raw: X: " + val[0] + " Y: " + val[1] + " Z: " + val[2] );
accel = sensor.getAcceleration();
System.out.println( "Acceleration: X: " + accel[0] + " Y: " + accel[1] + " Z: " + accel[2] );
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,33 @@
import upm_htu21d.javaupm_htu21dConstants;
public class HTU21DSample{
static {
try {
System.loadLibrary("javaupm_htu21d");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
float humidity = 0;
float temperature = 0;
float compRH = 0;
upm_htu21d.HTU21D sensor = new upm_htu21d.HTU21D(1);
sensor.testSensor();
while (true) {
compRH = sensor.getCompRH();
humidity = sensor.getHumidity();
temperature = sensor.getTemperature();
System.out.println( "Humidity: " + humidity + ", Temperature: " + temperature + ", compensated RH: " + compRH);
Thread.sleep(5000);
}
}
}

View File

@ -0,0 +1,59 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class Itg3200Sample {
static {
try {
System.loadLibrary("javaupm_itg3200");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
int[] rot;
float[] ang;
// Note: Sensor not supported on Intel Edison with Arduino breakout
upm_itg3200.Itg3200 gyro = new upm_itg3200.Itg3200(0);
while(true){
gyro.update();
rot = gyro.getRawValues();
ang = gyro.getRotation();
System.out.println( "Raw Values: X: " + rot[0] + " Y: " + rot[1] + " Z: " + rot[2] );
System.out.println( "Angular Velocities: X: " + ang[0] + " Y: " + ang[1] + " Z: " + ang[2]);
System.out.println( "Temp: " + gyro.getTemperature() + ", Raw: " + gyro.getRawTemp());
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -22,12 +22,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//NOT TESTED!!!
public class Joystick12_exampleSample {
static {
try {
System.loadLibrary("upm_joystick12");
System.loadLibrary("javaupm_joystick12");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);

View File

@ -0,0 +1,51 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class LDT0028Sample {
static {
try {
System.loadLibrary("javaupm_ldt0028");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
upm_ldt0028.LDT0028 sensor = new upm_ldt0028.LDT0028(0);
System.out.println("Sensor name: " + sensor.name());
while(true){
System.out.println("Sample value: " + sensor.getSample());
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,58 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class MHZ16Sample {
static {
try {
System.loadLibrary("javaupm_mhz16");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
int[] gas = new int[1];
int[] temp = new int[1];
// Instantiate a MHZ16 serial CO2 sensor on uart 0.
upm_mhz16.MHZ16 co2 = new upm_mhz16.MHZ16(0);
System.out.println("Make sure that the sensor has had at least 3 minutes to warm up");
System.out.println("or you will not get valid results.");
System.out.println("The temperature reported is not the ambient temperature,");
System.out.println("but rather the temperature of the sensor elements.");
while(true){
co2.getData(gas, temp);
System.out.println("CO2 concentration: " + gas[0] + "PPM, Temperature (in C): " + temp[0]);
Thread.sleep(2000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,62 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class MMA7660Sample {
static {
try {
System.loadLibrary("javaupm_mma7660");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate an MMA7660 on I2C bus 0
upm_mma7660.MMA7660 accel = new upm_mma7660.MMA7660(0);
// place device in standby mode so we can write registers
accel.setModeStandby();
// enable 64 samples per second
accel.setSampleRate(upm_mma7660.MMA7660.MMA7660_AUTOSLEEP_T.AUTOSLEEP_64);
// place device into active mode
accel.setModeActive();
while(true){
int[] rawValues = accel.getRawValues();
System.out.println("Raw Values: x = " + rawValues[0] + " y = " + rawValues[1] + " x = " + rawValues[2]);
float[] acceleration = accel.getAcceleration();
System.out.println("Raw Values: x = " + acceleration[0] + " y = " + acceleration[1] + " x = " + acceleration[2]);
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,43 @@
public class MPR121Sample{
static {
try {
System.loadLibrary("javaupm_mpr121");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
private static void printButtons(upm_mpr121.MPR121 touch){
boolean buttonPresed = false;
System.out.print("Buttons pressed: ");
for (int i = 0; i < 12; i++) {
if ( (touch.getM_buttonStates() & (1 << i)) != 0 ) {
System.out.print( i + " ");
buttonPresed = true;
}
}
if (!buttonPresed)
System.out.print("None ");
System.out.println();
}
public static void main(String[] args) throws InterruptedException {
// Instantiate an MPR121 on I2C bus 0
upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0);
// init according to AN3944 defaults
touch.configAN3944();
while (true) {
touch.readButtons();
printButtons(touch);
Thread.sleep(1000);
}
}
}

View File

@ -0,0 +1,65 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class MQ2Sample {
private static final short resolution = 5;
static {
try {
System.loadLibrary("javaupm_gas");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
short[] buffer = new short[128];
// Attach gas sensor to A0
upm_gas.MQ2 sensor = new upm_gas.MQ2(0);
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
ctx.setAverageReading(0);
ctx.setRunningAverage(0);
ctx.setAveragedOver(2);
while(true){
int len = sensor.getSampledWindow(2, buffer);
if(len != 0){
int thresh = sensor.findThreshold(ctx, 30, buffer);
sensor.printGraph(ctx, resolution);
if (thresh != 0){
System.out.println("---Threshold reached---");
}
}
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,64 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
public class MQ5Sample {
private static final short resolution = 7;
static {
try {
System.loadLibrary("javaupm_gas");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
short[] buffer = new short[128];
// Attach gas sensor to A0
upm_gas.MQ5 sensor = new upm_gas.MQ5(0);
upm_gas.thresholdContext ctx = new upm_gas.thresholdContext();
ctx.setAverageReading(0);
ctx.setRunningAverage(0);
ctx.setAveragedOver(2);
while(true){
int len = sensor.getSampledWindow(2, buffer);
if(len != 0){
int thresh = sensor.findThreshold(ctx, 30, buffer);
sensor.printGraph(ctx, resolution);
if (thresh != 0){
System.out.println("---Threshold reached---");
}
}
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,64 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
public class MicrophoneSample{
static {
try {
System.loadLibrary("javaupm_mic");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
short[] buffer = new short[128];
// Attach microphone to analog port A0
upm_mic.Microphone sensor = new upm_mic.Microphone(0);
upm_mic.thresholdContext ctx = new upm_mic.thresholdContext();
ctx.setAverageReading(0);
ctx.setRunningAverage(0);
ctx.setAveragedOver(2);
// Repeatedly, take a sample every 2 microseconds;
// find the average of 128 samples; and
// print a running graph of the averages
while (true) {
int len = sensor.getSampledWindow(2, buffer);
if(len != 0){
int thresh = sensor.findThreshold(ctx, 30, buffer);
sensor.printGraph(ctx);
if (thresh != 0){
System.out.println("---Threshold reached--- " + ctx.getRunningAverage() + " " + ctx.getAverageReading());
}
}
}
//! [Interesting]
}
}

View File

@ -0,0 +1,53 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
public class RPR220Sample {
static {
try {
System.loadLibrary("javaupm_rpr220");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// This example uses a simple method to determine current status
// Instantiate an RPR220 digital pin D2
upm_rpr220.RPR220 sensor = new upm_rpr220.RPR220(2);
while(true){
if(sensor.blackDetected())
System.out.println("Black detected");
else
System.out.println("Black NOT detected");
Thread.sleep(100);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,65 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
import upm_rpr220.IsrCallback;
public class RPR220_intrSample {
public static int counter=0;
static {
try {
System.loadLibrary("javaupm_rpr220");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// This example uses an interrupt handler to increment a counter
// Instantiate an RPR220 digital pin D2
upm_rpr220.RPR220 sensor = new upm_rpr220.RPR220(2);
IsrCallback callback = new RPRISR();
sensor.installISR(callback);
while(true){
System.out.println("Counter: " + counter);
Thread.sleep(1000);
}
//! [Interesting]
}
}
class RPRISR extends IsrCallback {
public RPRISR(){
super();
}
public void run(){
RPR220_intrSample.counter++;
}
}

View File

@ -0,0 +1,67 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
import java.time.LocalDateTime;
//NOT TESTED!!!
public class TM1637Sample {
static {
try {
System.loadLibrary("javaupm_tm1637");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// TM1637 on pins 0 (clk) and 1 (dio)
upm_tm1637.TM1637 myDisplay = new upm_tm1637.TM1637(0, 1);
// Start a box using 7-segment encoding
myDisplay.write(0x39, 0x09, 0x09);
// Finish box using writeAt function
myDisplay.writeAt(3, ']');
// Wait 3 seconds
Thread.sleep(3000);
LocalDateTime now;
while(true){
now = LocalDateTime.now();
int hour = now.getHour();
int min = now.getMinute();
int sec = now.getSecond();
System.out.println (hour + ":" + min + ":" + sec);
myDisplay.writeString(hour + ":" + min);
Thread.sleep(1000);
}
//! [Interesting]
}
}

View File

@ -22,7 +22,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//NOT TESTED!!!
public class Ublox6Sample {
private static final int BUFFERLENGTH = 256;
@ -45,11 +44,11 @@ public class Ublox6Sample {
throw new RuntimeException("Failed to setup tty port parameters");
}
// Collect and output NMEA data. There are various libraries out on
// the Internet, such as tinyGPS or tinyGPS++ that can handle
// decoding NMEA data and presenting it in a more easily accessible
// format. This example will just check for, and read raw NMEA data
// from the device and output it on standard output.
// Collect and output NMEA data. There are various libraries out on
// the Internet, that can handle decoding NMEA data and presenting
// it in a more easily accessible format. This example will just
// check for, and read raw NMEA data from the device and output it
// on standard output.
// This device also supports numerous configuration options, which
// you can set with writeData(). Please refer to the Ublox-6 data
@ -65,10 +64,10 @@ public class Ublox6Sample {
int rv = nmea.readData(nmeaBuffer);
if(rv > 0)
for (int i = 0; i < nmeaBuffer.length; i++)
System.out.print(nmeaBuffer[i]);
for (int i = 0; i < rv; i++)
System.out.print((char)nmeaBuffer[i]);
if (rv < 0){ // some sort of read error occured
if (rv < 0){ // some sort of read error occurred
System.err.println("Port read error.") ;
break;
}

View File

@ -35,7 +35,7 @@ public class YG1006Sample{
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a yg1006 flame sensor on digital pin D2
// Instantiate a yg1006 flame sensor on digital pin D2
upm_yg1006.YG1006 flame = new upm_yg1006.YG1006(2);
while (true) {

View File

@ -0,0 +1,99 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@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.
*/
//NOT TESTED!!!
public class ZFM20Sample {
static {
try {
System.loadLibrary("javaupm_zfm20");
}catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
// Instantiate a ZFM20 Fingerprint reader on UART 0
upm_zfm20.ZFM20 fp = new upm_zfm20.ZFM20(0);
// make sure port is initialized properly. 57600 baud is the default
if(!fp.setupTty()){
System.err.println("Failed to setup tty port parameters");
System.exit(-1);
}
// first, set the default password and address
fp.setPassword(upm_zfm20.javaupm_zfm20.ZFM20_DEFAULT_PASSWORD);
fp.setAddress(upm_zfm20.javaupm_zfm20.ZFM20_DEFAULT_ADDRESS);
// now verify the password. If this fails, any other commands
// will be ignored, so we just bail.
if(fp.verifyPassword()){
System.out.println("Password verified.");
}
else{
System.err.println("Password verification failed.");
System.exit(-1);
}
// how many valid stored templates (fingerprints) do we have?
System.out.println("Total stored templates: " + fp.getNumTemplates());
// now spin waiting for a fingerprint to successfully image
System.out.println("Waiting for finger print...");
while(fp.generateImage() == upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_NO_FINGER.swigValue());
// in theory, we have an image
System.out.println("Image captured, converting...");
short rv = fp.image2Tz(1);
if( rv != upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_OK.swigValue() ){
System.err.println("Image conversion failed with error code " + rv);
System.exit(-1);
}
System.out.println("Image conversion succeeded");
// we search for a print matching slot 1, where we shored our last
// converted fingerprint
int[] id = new int[1];
int[] score = new int[1];
rv = fp.search(1, id, score);
if( rv != upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_OK.swigValue() ){
if( rv == upm_zfm20.ZFM20.ZFM20_ERRORS_T.ERR_FP_NOTFOUND.swigValue() ){
System.out.println("Fingerprint not found");
System.exit(0);
}
else{
System.err.println("Search failed with error code " + rv);
System.exit(-1);
}
}
System.out.println("Fingerprint found!");
System.out.println("ID: " + id + ", Score: " + score);
//! [Interesting]
}
}