From e34863f2238fdbc090bdce35baf4bf858519dfd8 Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Thu, 8 Oct 2015 14:30:12 +0300 Subject: [PATCH] java: Added java samples and applied coding style rules to all previous samples Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- examples/java/ADC121C021Sample.java | 55 +++++++ examples/java/Adxl345Sample.java | 59 +++---- examples/java/BMPX8XSample.java | 21 +-- examples/java/BuzzerSample.java | 64 ++++++++ examples/java/CJQ4435Sample.java | 26 ++-- examples/java/DS1307Sample.java | 83 ++++++++++ examples/java/ENC03RSample.java | 24 +-- examples/java/ES08ASample.java | 48 +++--- examples/java/GROVESCAMSample.java | 38 ++--- examples/java/GUVAS12DSample.java | 27 ++-- examples/java/GroveButtonSample.java | 18 +-- examples/java/GroveButton_intrSample.java | 65 ++++++++ examples/java/GroveEHRSample.java | 24 +-- examples/java/GroveLed_multiSample.java | 54 +++++++ examples/java/GroveLightSample.java | 14 +- examples/java/GroveLineFinderSample.java | 23 ++- examples/java/GroveMDSample.java | 24 +-- examples/java/GroveMoistureSample.java | 24 +-- examples/java/GroveRelaySample.java | 24 +-- examples/java/GroveRotarySample.java | 36 ++--- examples/java/GroveSpeakerSample.java | 20 +-- examples/java/GroveVDivSample.java | 21 +-- examples/java/GroveWFSSample.java | 16 +- examples/java/GroveWaterSample.java | 26 ++-- examples/java/HCSR04Sample.java | 76 +++++++++ examples/java/HM11Sample.java | 105 +++++++++++++ examples/java/HMTRPSample.java | 131 ++++++++++++++++ examples/java/HTU21DSample.java | 54 +++++-- examples/java/Hmc5883lSample.java | 30 ++-- examples/java/Itg3200Sample.java | 29 ++-- examples/java/Jhd1313m1Sample.java | 51 +++++++ examples/java/LDT0028Sample.java | 16 +- examples/java/LSM303Sample.java | 29 ++-- examples/java/Lcm1602_i2cSample.java | 58 +++++++ examples/java/Lcm1602_parallelSample.java | 61 ++++++++ examples/java/LoL_exampleSample.java | 58 +++++++ examples/java/M24LR64ESample.java | 64 ++++++++ examples/java/MAX44000Sample.java | 16 +- examples/java/MHZ16Sample.java | 23 +-- examples/java/MMA7455Sample.java | 51 +++++++ examples/java/MMA7660Sample.java | 28 ++-- examples/java/MPL3115A2Sample.java | 16 +- examples/java/MPR121Sample.java | 32 ++-- examples/java/MPU9150Sample.java | 31 ++-- examples/java/MQ2Sample.java | 26 ++-- examples/java/MQ303ASample.java | 32 ++-- examples/java/MQ5Sample.java | 26 ++-- examples/java/MY9221Sample.java | 48 ++++++ examples/java/MicrophoneSample.java | 27 ++-- examples/java/NRF24L01_receiverSample.java | 84 ++++++++++ examples/java/NRF24L01_transmitterSample.java | 75 +++++++++ examples/java/NUNCHUCKSample.java | 37 ++--- examples/java/OTP538USample.java | 25 +-- examples/java/PPD42NSSample.java | 17 +-- examples/java/RFR359FSample.java | 25 ++- examples/java/RPR220Sample.java | 20 +-- examples/java/RPR220_intrSample.java | 24 +-- examples/java/RotaryEncoderSample.java | 18 +-- examples/java/SSD1308_oledSample.java | 98 ++++++++++++ examples/java/SSD1327_oledSample.java | 144 ++++++++++++++++++ examples/java/ST7735Sample.java | 86 +++++++++++ examples/java/StepMotorSample.java | 62 ++++++++ examples/java/TM1637Sample.java | 24 +-- examples/java/TP401Sample.java | 60 ++++---- examples/java/TSL2561Sample.java | 49 ++++++ examples/java/TTP223Sample.java | 24 +-- examples/java/ULN200XASample.java | 18 +-- examples/java/Ublox6Sample.java | 46 +++--- examples/java/WT5001Sample.java | 121 +++++++++++++++ examples/java/YG1006Sample.java | 25 ++- examples/java/ZFM20Sample.java | 48 +++--- 71 files changed, 2433 insertions(+), 649 deletions(-) create mode 100644 examples/java/ADC121C021Sample.java create mode 100644 examples/java/BuzzerSample.java create mode 100644 examples/java/DS1307Sample.java create mode 100644 examples/java/GroveButton_intrSample.java create mode 100644 examples/java/GroveLed_multiSample.java create mode 100644 examples/java/HCSR04Sample.java create mode 100644 examples/java/HM11Sample.java create mode 100644 examples/java/HMTRPSample.java create mode 100644 examples/java/Jhd1313m1Sample.java create mode 100644 examples/java/Lcm1602_i2cSample.java create mode 100644 examples/java/Lcm1602_parallelSample.java create mode 100644 examples/java/LoL_exampleSample.java create mode 100644 examples/java/M24LR64ESample.java create mode 100644 examples/java/MMA7455Sample.java create mode 100644 examples/java/MY9221Sample.java create mode 100644 examples/java/NRF24L01_receiverSample.java create mode 100644 examples/java/NRF24L01_transmitterSample.java create mode 100644 examples/java/SSD1308_oledSample.java create mode 100644 examples/java/SSD1327_oledSample.java create mode 100644 examples/java/ST7735Sample.java create mode 100644 examples/java/StepMotorSample.java create mode 100644 examples/java/TSL2561Sample.java create mode 100644 examples/java/WT5001Sample.java diff --git a/examples/java/ADC121C021Sample.java b/examples/java/ADC121C021Sample.java new file mode 100644 index 00000000..54ca02b2 --- /dev/null +++ b/examples/java/ADC121C021Sample.java @@ -0,0 +1,55 @@ +/* + * Author: Stefan Andritoiu + * 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 ADC121C021Sample { + + static { + try { + System.loadLibrary("javaupm_adc121c021"); + } 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 ADC121C021 on I2C bus 0 + upm_adc121c021.ADC121C021 adc = new upm_adc121c021.ADC121C021(0); + + // An analog sensor, such as a Grove light sensor, + // must be attached to the adc· + // Prints the value and corresponding voltage every 50 milliseconds + while (true) { + int val = adc.value(); + + System.out.println("ADC value: " + val + "Volts = " + adc.valueToVolts(val)); + + Thread.sleep(1000); + } + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/Adxl345Sample.java b/examples/java/Adxl345Sample.java index d73971d8..fbabc96e 100644 --- a/examples/java/Adxl345Sample.java +++ b/examples/java/Adxl345Sample.java @@ -22,35 +22,40 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +//NOT TESTED!!! public class Adxl345Sample { - static { - try { - System.loadLibrary("javaupm_adxl345"); - } catch (UnsatisfiedLinkError e) { - System.err.println("error in loading native library"); - System.exit(-1); - } - } - public static void main(String argv[]) throws InterruptedException { -//! [Interesting] - // Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout - upm_adxl345.Adxl345 obj = new upm_adxl345.Adxl345(0); - int[] raw = new int[3]; - float[] accel = new float[3]; + static { + try { + System.loadLibrary("javaupm_adxl345"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } - while (true) { - obj.update(); - raw = obj.getRawValues(); - accel = obj.getAcceleration(); + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + short[] val; + float[] accel; - System.out.println("raw data: " + raw[0] + " " + raw[1] + " " + - raw[2]); - System.out.println("accel data: " + accel[0] + " " + accel[1] + " " - + accel[2]); + // Note: Sensor only works at 3.3V on the Intel Edison with Arduino + // breakout + upm_adxl345.Adxl345 sensor = new upm_adxl345.Adxl345(0); - Thread.sleep(1000); - } -//! [Interesting] - } -} + while (true) { + sensor.update(); + val = sensor.getRawValues(); + accel = sensor.getAcceleration(); + + System.out.println("Current scale: " + sensor.getScale()); + System.out.println("Raw Values: X: " + val[0] + " Y: " + val[1] + + " Z: " + val[2]); + System.out.println("Acceleration: X: " + accel[0] + "g Y: " + + accel[1] + "g Z: " + accel[2] + "g"); + + Thread.sleep(1000); + } + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/BMPX8XSample.java b/examples/java/BMPX8XSample.java index d1c7dc6f..2c6aeb80 100644 --- a/examples/java/BMPX8XSample.java +++ b/examples/java/BMPX8XSample.java @@ -27,30 +27,31 @@ public class BMPX8XSample { static { try { - System.loadLibrary("upm_bmpx8x"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_bmpx8x"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a BMPX8X sensor on I2C upm_bmpx8x.BMPX8X sensor = new upm_bmpx8x.BMPX8X(0); - + // Print the pressure, altitude, sea level, and - // temperature values every second - while(true){ + // temperature values every second + while (true) { System.out.println("Pressure: " + sensor.getPressure()); System.out.println("Altitude: " + sensor.getAltitude()); - System.out.println("Sealevel pressure: " + sensor.getSealevelPressure()); + System.out.println("Sealevel pressure: " + + sensor.getSealevelPressure()); System.out.println("Temperature: " + sensor.getTemperature()); System.out.println(); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/BuzzerSample.java b/examples/java/BuzzerSample.java new file mode 100644 index 00000000..30dbb1d8 --- /dev/null +++ b/examples/java/BuzzerSample.java @@ -0,0 +1,64 @@ +/* + * Author: Stefan Andritoiu + * 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 BuzzerSample { + + static { + try { + System.loadLibrary("javaupm_buzzer"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + int chord[] = { + upm_buzzer.javaupm_buzzer.DO, + upm_buzzer.javaupm_buzzer.RE, + upm_buzzer.javaupm_buzzer.MI, + upm_buzzer.javaupm_buzzer.FA, + upm_buzzer.javaupm_buzzer.SOL, + upm_buzzer.javaupm_buzzer.LA, + upm_buzzer.javaupm_buzzer.SI}; + + // Instantiate a buzzer on digital pin D5 + upm_buzzer.Buzzer sound = new upm_buzzer.Buzzer(5); + + // print sensor name + System.out.println(sound.name()); + + for (int i = 0; i < chord.length; i++) { + // play each note for one second + int note = sound.playSound(chord[i], 1000000); + System.out.println(note); + + Thread.sleep(100); + } + // ! [Interesting] + sound.stopSound(); + } + +} \ No newline at end of file diff --git a/examples/java/CJQ4435Sample.java b/examples/java/CJQ4435Sample.java index abebf0a5..90a0a76b 100644 --- a/examples/java/CJQ4435Sample.java +++ b/examples/java/CJQ4435Sample.java @@ -22,42 +22,40 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class CJQ4435Sample{ - +public class CJQ4435Sample { + static { try { System.loadLibrary("javaupm_cjq4435"); - }catch (UnsatisfiedLinkError e) { + } 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 CJQ4435 MOSFET on a PWM capable digital pin D3 - upm_cjq4435.CJQ4435 mosfet = new upm_cjq4435.CJQ4435(3); - + upm_cjq4435.CJQ4435 mosfet = new upm_cjq4435.CJQ4435(3); + mosfet.setPeriodMS(10); mosfet.enable(true); - - while(true){ + + while (true) { // start with a duty cycle of 0.0 (off) and increment to 1.0 (on) - for (float i=0; i <= 1; i+=0.1){ + for (float i = 0; i <= 1; i += 0.1) { mosfet.setDutyCycle(i); Thread.sleep(100); } Thread.sleep(1000); - + // Now take it back down // start with a duty cycle of 1.0 (on) and decrement to 0.0 (off) - for (float i=1; i >= 0; i-=0.1){ + for (float i = 1; i >= 0; i -= 0.1) { mosfet.setDutyCycle(i); Thread.sleep(100); } Thread.sleep(1000); } - //! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/DS1307Sample.java b/examples/java/DS1307Sample.java new file mode 100644 index 00000000..a0785f8c --- /dev/null +++ b/examples/java/DS1307Sample.java @@ -0,0 +1,83 @@ +/* + * Author: Stefan Andritoiu + * 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 DS1307Sample { + + static { + try { + System.loadLibrary("javaupm_ds1307"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + static private void printTime(upm_ds1307.DS1307 rtc) { + System.out.print("The time is: " + rtc.getMonth() + "/" + rtc.getDayOfMonth() + "/" + + rtc.getYear() + " " + rtc.getHours() + ":" + rtc.getMinutes() + ":" + + rtc.getSeconds()); + + if (rtc.getAmPmMode()) { + if (rtc.getAmPmMode()) + System.out.print(" PM"); + else + System.out.print(" AM"); + } + + System.out.println(); + + if (rtc.getAmPmMode()) + System.out.println("Clock is in AM/PM mode"); + else + System.out.println("Clock is in 24h mode"); + + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + // Instantiate a DS1037 on I2C bus 0 + upm_ds1307.DS1307 rtc = new upm_ds1307.DS1307(0); + + // always do this first + System.out.println("Loading the current time..."); + if (!rtc.loadTime()) { + System.err.println("rtc->loadTime() failed."); + System.exit(-1); + } + + printTime(rtc); + + // set the year as an example + System.out.println("setting the year to 50"); + rtc.setYear(50); + rtc.setTime(); + + // reload the time and print it + rtc.loadTime(); + printTime(rtc); + + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/ENC03RSample.java b/examples/java/ENC03RSample.java index 908262cd..1d2e4bb1 100644 --- a/examples/java/ENC03RSample.java +++ b/examples/java/ENC03RSample.java @@ -25,40 +25,40 @@ //NOT TESTED!!! public class ENC03RSample { private static final long CALIBRATION_SAMPLES = 1000; - + static { try { System.loadLibrary("javaupm_enc03r"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] - + // ! [Interesting] + // Instantiate a ENC03R on analog pin A0 upm_enc03r.ENC03R gyro = new upm_enc03r.ENC03R(0); - + System.out.println("Please place the sensor in a stable location, and do not"); System.out.println("move it while calibration takes place"); System.out.println("This may take a couple of minutes."); - + gyro.calibrate(CALIBRATION_SAMPLES); System.out.println("Calibration complete. Reference value: " + gyro.calibrationValue()); - + // Read the input and print both the raw value and the angular velocity, // waiting 1 second between readings - while(true){ + while (true) { long val = gyro.value(); double av = gyro.angularVelocity(val); - + System.out.println("Raw value: " + val + ", angular velocity: " + av + " deg/s"); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/ES08ASample.java b/examples/java/ES08ASample.java index b9dc8e36..1726fd66 100644 --- a/examples/java/ES08ASample.java +++ b/examples/java/ES08ASample.java @@ -22,43 +22,41 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//import upm_servo.ES08A; - -public class ES08ASample{ +public class ES08ASample { static { try { System.loadLibrary("javaupm_servo"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] upm_servo.ES08A servo = new upm_servo.ES08A(6); - + // Sets the shaft to 180, then to 90, then to 0, - // then back to 90, and finally back to 180, - // pausing for a second in between each angle - servo.setAngle (180); - System.out.println("Set angle to 180"); + // then back to 90, and finally back to 180, + // pausing for a second in between each angle + servo.setAngle(180); + System.out.println("Set angle to 180"); Thread.sleep(1000); - servo.setAngle (90); - System.out.println("Set angle to 90"); - Thread.sleep(1000); - - servo.setAngle (0); - System.out.println("Set angle to 0"); - Thread.sleep(1000); - - servo.setAngle (90); - System.out.println("Set angle to 90"); + servo.setAngle(90); + System.out.println("Set angle to 90"); Thread.sleep(1000); - servo.setAngle (180); - System.out.println("Set angle to 180"); - //! [Interesting] + servo.setAngle(0); + System.out.println("Set angle to 0"); + Thread.sleep(1000); + + servo.setAngle(90); + System.out.println("Set angle to 90"); + Thread.sleep(1000); + + servo.setAngle(180); + System.out.println("Set angle to 180"); + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GROVESCAMSample.java b/examples/java/GROVESCAMSample.java index 5b6f76ad..176c4aea 100644 --- a/examples/java/GROVESCAMSample.java +++ b/examples/java/GROVESCAMSample.java @@ -23,53 +23,53 @@ */ //NOT TESTED!!! -public class GROVESCAMSample{ +public class GROVESCAMSample { static { try { System.loadLibrary("javaupm_grovescam"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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()){ + + // 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()) + + if (camera.init()) System.out.println("Initialized..."); else System.out.println("Initialization failed"); - - if(camera.preCapture()) + + if (camera.preCapture()) System.out.println("preCapture succeeded..."); else System.out.println("preCapture failed."); - - if(camera.doCapture()) + + if (camera.doCapture()) System.out.println("doCapture succeeded..."); else System.out.println("doCapture failed."); - - if(camera.getImageSize() > 0){ + + if (camera.getImageSize() > 0) { System.out.println("Storing image.jpg..."); - - if(camera.storeImage("image.jpg")) + + if (camera.storeImage("image.jpg")) System.out.println("storeImage succeeded..."); else System.out.println("storeImage failed."); - + } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/GUVAS12DSample.java b/examples/java/GUVAS12DSample.java index 14e5220d..1f90215a 100644 --- a/examples/java/GUVAS12DSample.java +++ b/examples/java/GUVAS12DSample.java @@ -22,9 +22,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//import upm_guvas12d.GUVAS12D; - -public class GUVAS12DSample{ +public class GUVAS12DSample { // analog voltage, usually 3.3 or 5.0 private static final float GUVAS12D_AREF = 5; private static final int SAMPLES_PER_QUERY = 1024; @@ -32,25 +30,26 @@ public class GUVAS12DSample{ static { try { System.loadLibrary("javaupm_guvas12d"); - }catch (UnsatisfiedLinkError e) { + } 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 GUVAS12D on analog pin A3 - upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(3); - + // ! [Interesting] + // Instantiate a GUVAS12D on analog pin A3 + upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(3); + while (true) { float value = volts.value(GUVAS12D_AREF, SAMPLES_PER_QUERY); - - System.out.println("AREF: " + GUVAS12D_AREF + ", Voltage value (higher means more UV): " + value ); - + + System.out.println("AREF: " + GUVAS12D_AREF + + ", Voltage value (higher means more UV): " + value); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveButtonSample.java b/examples/java/GroveButtonSample.java index 903d81a4..c04601ef 100644 --- a/examples/java/GroveButtonSample.java +++ b/examples/java/GroveButtonSample.java @@ -22,28 +22,28 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveButtonSample{ +public class GroveButtonSample { static { try { System.loadLibrary("javaupm_grove"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Create the button object using UART upm_grove.GroveButton button = new upm_grove.GroveButton(0); - + while (true) { - System.out.println(button.name() +" value is " + button.value()); - + System.out.println(button.name() + " value is " + button.value()); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveButton_intrSample.java b/examples/java/GroveButton_intrSample.java new file mode 100644 index 00000000..abe7ab09 --- /dev/null +++ b/examples/java/GroveButton_intrSample.java @@ -0,0 +1,65 @@ +import upm_grove.IsrCallback; + +/* + * Author: Stefan Andritoiu + * 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 GroveButton_intrSample { + + public static int counter = 0; + + static { + try { + System.loadLibrary("javaupm_grove"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_grove.GroveButton b = new upm_grove.GroveButton(2); + + IsrCallback callback = new ButtonISR(); + b.installISR(0, callback); + + while (true) { + System.out.println("Counter: " + counter); + Thread.sleep(1000); + } + // ! [Interesting] + } +} + +class ButtonISR extends IsrCallback { + public ButtonISR() { + super(); + } + + public void run() { + GroveButton_intrSample.counter++; + System.out.println("+++++++++"); + } +} \ No newline at end of file diff --git a/examples/java/GroveEHRSample.java b/examples/java/GroveEHRSample.java index dbfce885..6514af2f 100644 --- a/examples/java/GroveEHRSample.java +++ b/examples/java/GroveEHRSample.java @@ -24,39 +24,39 @@ //NOT TESTED!!! public class GroveEHRSample { - + static { try { System.loadLibrary("javaupm_groveehr"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + 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(); - + 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] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/GroveLed_multiSample.java b/examples/java/GroveLed_multiSample.java new file mode 100644 index 00000000..d2a400f4 --- /dev/null +++ b/examples/java/GroveLed_multiSample.java @@ -0,0 +1,54 @@ +/* + * Author: Stefan Andritoiu + * 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 GroveLed_multiSample { + + static { + try { + System.loadLibrary("javaupm_grove"); + } 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 LED on D2. Here we are controlling a Grove + // Multi-color flash LED. We just just need to turn it on - it will + // then cycle through various colors (red, green, blue, purple) on it's + // own until turned off. + upm_grove.GroveLed led = new upm_grove.GroveLed(2); + + // start the light show + led.on(); + + // just sleep until interrupted + while (true) { + Thread.sleep(1); + } + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/GroveLightSample.java b/examples/java/GroveLightSample.java index 85a17858..cf9ec35a 100644 --- a/examples/java/GroveLightSample.java +++ b/examples/java/GroveLightSample.java @@ -32,19 +32,19 @@ public class GroveLightSample { } } - public static void main (String args[]) throws InterruptedException { - //! [Interesting] - upm_grove.GroveLight gl = new upm_grove.GroveLight(2); - + public static void main(String args[]) throws InterruptedException { + // ! [Interesting] + upm_grove.GroveLight gl = new upm_grove.GroveLight(2); + while (true) { float raw_value = gl.raw_value(); float value = gl.value(); System.out.println("raw value: " + raw_value); System.out.println("value: " + value); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveLineFinderSample.java b/examples/java/GroveLineFinderSample.java index 8f84135b..95a3b1d9 100644 --- a/examples/java/GroveLineFinderSample.java +++ b/examples/java/GroveLineFinderSample.java @@ -22,34 +22,33 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveLineFinderSample{ - +public class GroveLineFinderSample { + static { try { System.loadLibrary("javaupm_grovelinefinder"); - }catch (UnsatisfiedLinkError e) { + } 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 Line Finder sensor on digital pin D2 + // ! [Interesting] + // Instantiate a Grove Line Finder sensor on digital pin D2 upm_grovelinefinder.GroveLineFinder finder = new upm_grovelinefinder.GroveLineFinder(2); // check every second for the presence of white detection - while(true){ + while (true) { boolean val = finder.whiteDetected(); - if(val){ + if (val) { System.out.println("White detected"); - } - else{ + } else { System.out.println("Black detected"); } Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveMDSample.java b/examples/java/GroveMDSample.java index 1a401b05..19d16f60 100644 --- a/examples/java/GroveMDSample.java +++ b/examples/java/GroveMDSample.java @@ -22,37 +22,41 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveMDSample{ +public class GroveMDSample { private static final short speed50 = 127; private static final short speed0 = 0; - + static { try { System.loadLibrary("javaupm_grovemd"); - }catch (UnsatisfiedLinkError e) { + } 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 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% + // 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.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 ); + motors.setMotorDirections(upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CCW, + upm_grovemd.GroveMD.DC_DIRECTION_T.DIR_CCW); Thread.sleep(3000); - - // stop motors + + // stop motors System.out.println("Stopping motors"); motors.setMotorSpeeds(speed0, speed0); + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/GroveMoistureSample.java b/examples/java/GroveMoistureSample.java index 766a567f..261b8b20 100644 --- a/examples/java/GroveMoistureSample.java +++ b/examples/java/GroveMoistureSample.java @@ -22,35 +22,35 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveMoistureSample{ +public class GroveMoistureSample { static { try { System.loadLibrary("javaupm_grovemoisture"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - public static void main (String args[]) throws InterruptedException { - //! [Interesting] - upm_grovemoisture.GroveMoisture gm = new upm_grovemoisture.GroveMoisture(1); + public static void main(String args[]) throws InterruptedException { + // ! [Interesting] + upm_grovemoisture.GroveMoisture gm = new upm_grovemoisture.GroveMoisture(1); while (true) { int moisture_val = gm.value(); String result; - + if (moisture_val >= 0 && moisture_val < 300) - result = "Dry"; + result = "Dry"; else if ((moisture_val >= 0 && moisture_val < 300)) result = "Moist"; else result = "Wet"; - - System.out.println("Moisture Value: " + moisture_val + ", " + result ); - + + System.out.println("Moisture Value: " + moisture_val + ", " + result); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveRelaySample.java b/examples/java/GroveRelaySample.java index 3c6313f2..2058a68b 100644 --- a/examples/java/GroveRelaySample.java +++ b/examples/java/GroveRelaySample.java @@ -22,32 +22,32 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveRelaySample{ +public class GroveRelaySample { static { try { System.loadLibrary("javaupm_grove"); - }catch (UnsatisfiedLinkError e) { + } 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 button object using UART + // ! [Interesting] + // Create the button object using UART upm_grove.GroveRelay relay = new upm_grove.GroveRelay(5); - - for( int i = 0 ; i < 3 ; i++ ){ + + for (int i = 0; i < 3; i++) { relay.on(); - if( relay.isOn() ) + if (relay.isOn()) System.out.println("Relay is on"); Thread.sleep(1000); - + relay.off(); - if( relay.isOff() ) + if (relay.isOff()) System.out.println("Relay is off"); Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveRotarySample.java b/examples/java/GroveRotarySample.java index 330faf66..7918b863 100644 --- a/examples/java/GroveRotarySample.java +++ b/examples/java/GroveRotarySample.java @@ -22,35 +22,37 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveRotarySample{ +public class GroveRotarySample { static { try { System.loadLibrary("javaupm_grove"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] - upm_grove.GroveRotary knob = new upm_grove.GroveRotary(0); - + // ! [Interesting] + upm_grove.GroveRotary knob = new upm_grove.GroveRotary(0); + while (true) { - float abs_value = knob.abs_value(); // Absolute raw value - float abs_deg = knob.abs_deg(); // Absolute degrees - float abs_rad = knob.abs_rad(); // Absolute radians + float abs_value = knob.abs_value(); // Absolute raw value + float abs_deg = knob.abs_deg(); // Absolute degrees + float abs_rad = knob.abs_rad(); // Absolute radians float rel_value = knob.rel_value(); // Relative raw value - float rel_deg = knob.rel_deg(); // Relative degrees - float rel_rad = knob.rel_rad(); // Relative radians - - System.out.println( "Absolute: " + abs_value + " raw, " + abs_deg + " deg, " + abs_rad + " rad" ); - System.out.println( "Relative: " + rel_value + " raw, " + rel_deg + " deg, " + rel_rad + " rad" ); - + float rel_deg = knob.rel_deg(); // Relative degrees + float rel_rad = knob.rel_rad(); // Relative radians + + System.out.println("Absolute: " + abs_value + " raw, " + abs_deg + " deg, " + abs_rad + + " rad"); + System.out.println("Relative: " + rel_value + " raw, " + rel_deg + " deg, " + rel_rad + + " rad"); + Thread.sleep(3000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/GroveSpeakerSample.java b/examples/java/GroveSpeakerSample.java index dabb7935..4cee32d2 100644 --- a/examples/java/GroveSpeakerSample.java +++ b/examples/java/GroveSpeakerSample.java @@ -22,28 +22,28 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveSpeakerSample{ +public class GroveSpeakerSample { static { try { System.loadLibrary("javaupm_grovespeaker"); - }catch (UnsatisfiedLinkError e) { + } 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 Speaker on digital pin D2 + // ! [Interesting] + // Instantiate a Grove Speaker on digital pin D2 upm_grovespeaker.GroveSpeaker speaker = new upm_grovespeaker.GroveSpeaker(2); - + // Play all 7 of the lowest notes speaker.playAll(); - + // Play a medium C-sharp speaker.playSound('c', true, "med"); - //! [Interesting] - } + // ! [Interesting] + } -} +} \ No newline at end of file diff --git a/examples/java/GroveVDivSample.java b/examples/java/GroveVDivSample.java index 9367cf7a..aa0ed62b 100644 --- a/examples/java/GroveVDivSample.java +++ b/examples/java/GroveVDivSample.java @@ -29,30 +29,31 @@ public class GroveVDivSample { static { try { - System.loadLibrary("upm_grovevdiv"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_grovevdiv"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a Grove Voltage Divider sensor on analog pin A0 upm_grovevdiv.GroveVDiv vDiv = new upm_grovevdiv.GroveVDiv(0); - + // collect data and output measured voltage according to the setting // of the scaling switch (3 or 10) - while(true){ + while (true) { long val = vDiv.value(100); float gain3val = vDiv.computedValue(gain3, val); float gain10val = vDiv.computedValue(gain10, val); - - System.out.println("ADC value: " + val + ", Gain 3: " + gain3val + "v, Gain 10: " + gain10val); - + + System.out.println("ADC value: " + val + ", Gain 3: " + gain3val + "v, Gain 10: " + + gain10val); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/GroveWFSSample.java b/examples/java/GroveWFSSample.java index 6e186d04..6545c434 100644 --- a/examples/java/GroveWFSSample.java +++ b/examples/java/GroveWFSSample.java @@ -28,26 +28,26 @@ public class GroveWFSSample { static { try { System.loadLibrary("javaupm_grovewfs"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { System.out.print("Millis: " + flow.getMillis() + " FlowCount: " + flow.flowCounter()); System.out.println(" Flow Rate: " + flow.flowRate() + " LPM"); - + Thread.sleep(2000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/GroveWaterSample.java b/examples/java/GroveWaterSample.java index e20f0701..2e382e5b 100644 --- a/examples/java/GroveWaterSample.java +++ b/examples/java/GroveWaterSample.java @@ -22,35 +22,33 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class GroveWaterSample{ +public class GroveWaterSample { static { try { System.loadLibrary("javaupm_grovewater"); - }catch (UnsatisfiedLinkError e) { + } 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 sensor on digital pin D2 + // ! [Interesting] + // Instantiate a Grove Water sensor on digital pin D2 upm_grovewater.GroveWater water = new upm_grovewater.GroveWater(2); - + while (true) { boolean val = water.isWet(); - if (val){ + if (val) { System.out.println("Sensor is wet"); + } else { + System.out.println("Sensor is dry"); } - else{ - System.out.println("Sensor is dry"); - } - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } - -} +} \ No newline at end of file diff --git a/examples/java/HCSR04Sample.java b/examples/java/HCSR04Sample.java new file mode 100644 index 00000000..aaddd13c --- /dev/null +++ b/examples/java/HCSR04Sample.java @@ -0,0 +1,76 @@ +/* + * Author: Stefan Andritoiu + * 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_hcsr04.IsrCallback; + +//NOT TESTED!!! +public class HCSR04Sample { + + static { + try { + System.loadLibrary("javaupm_hcsr04"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + // ! [Interesting] + public static void main(String[] args) throws InterruptedException { + HCSR04ISR callback = new HCSR04ISR(); + + upm_hcsr04.HCSR04 sonar = new upm_hcsr04.HCSR04((short) 5, (short) 6, callback); + callback.setSonar(sonar); + Thread.sleep(1000); + + while (true) { + System.out.println("Get distance"); + double distance = sonar.getDistance(upm_hcsr04.javaupm_hcsr04Constants.CM); + System.out.println("Distance: " + distance); + + Thread.sleep(5000); + } + } +} + +class HCSR04ISR extends IsrCallback { + + private upm_hcsr04.HCSR04 sonar = null; + + public HCSR04ISR() { + super(); + } + + public void setSonar(upm_hcsr04.HCSR04 sonar) { + this.sonar = sonar; + } + + public void run() { + if (sonar != null) + sonar.ackEdgeDetected(); + else + System.out.println("No HCSR04ISR instance given to callback"); + } +} +// ! [Interesting] \ No newline at end of file diff --git a/examples/java/HM11Sample.java b/examples/java/HM11Sample.java new file mode 100644 index 00000000..f90d28a9 --- /dev/null +++ b/examples/java/HM11Sample.java @@ -0,0 +1,105 @@ +/* + * Author: Stefan Andritoiu + * 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 HM11Sample { + + private static final int BUFSIZ = 1024; + + static { + try { + System.loadLibrary("javaupm_hm11"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + private static void printUsage() { + System.out.println("Usage: java HM11Sample [AT command]"); + + System.out.println("If an argument is supplied on the command line, that argument is"); + System.out.println("sent to the module and the response is printed out."); + System.out.println("If no argument is used, then the address and PIN of the module"); + System.out.println("are queried and the results printed out."); + + } + + private static void sendCommand(upm_hm11.HM11 ble, byte[] cmd) { + byte[] buffer = new byte[BUFSIZ]; + ble.writeData(cmd); + + // wait up to 1 second + if (ble.dataAvailable(1000)) { + ble.readData(buffer); + } else { + System.err.println("Timed out waiting for response"); + } + + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + // Instantiate a HM11 BLE Module on UART 0 + upm_hm11.HM11 ble = new upm_hm11.HM11(0); + + // make sure port is initialized properly. 9600 baud is the default. + if (!ble.setupTty()) { + System.err.println("Failed to setup tty port parameters"); + System.exit(-1); + } + + printUsage(); + + if (args.length > 0) { + System.out.println("Sending command line argument (" + args[0] + ")..."); + sendCommand(ble, args[0].getBytes()); + } else { + // query the module address + String addr = "AT+ADDR?"; + System.out.println("Querying module address (" + addr + ")..."); + sendCommand(ble, addr.getBytes()); + + Thread.sleep(1000); + + // query the module address + String pin = "AT+PASS?"; + System.out.println("Querying module pin (" + pin + ")..."); + sendCommand(ble, pin.getBytes()); + + // Other potentially useful commands are: + // + // AT+VERS? - query module version + // AT+ROLE0 - set as slave + // AT+ROLE1 - set as master + // AT+CLEAR - clear all previous settings + // AT+RESET - restart the device + // + // A comprehensive list is available from the datasheet at: + // http://www.seeedstudio.com/wiki/images/c/cd/Bluetooth4_en.pdf + + } + // ! [Interesting] + } +} diff --git a/examples/java/HMTRPSample.java b/examples/java/HMTRPSample.java new file mode 100644 index 00000000..32a89fd7 --- /dev/null +++ b/examples/java/HMTRPSample.java @@ -0,0 +1,131 @@ +/* + * Author: Stefan Andritoiu + * 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 HMTRPSample { + + static private final int bufferLength = 255; + + static { + try { + System.loadLibrary("javaupm_hmtrp"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + private static void printUsage() { + System.out.println("Usage:"); + System.out.println("Pass a commandline argument (any argument) to this program"); + System.out.println("to query the radio configuration and output it. NOTE: the"); + System.out.println("radio must be in CONFIG mode for this to work."); + System.out.println("Running this program without arguments will simply transmit"); + System.out.println("'Hello World!' every second, and output any data received from"); + System.out.println("another radio."); + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + // Instantiate a HMTRP radio device on uart 0 + upm_hmtrp.HMTRP radio = new upm_hmtrp.HMTRP(0); + + // make sure port is initialized properly. 9600 baud is the default. + if (!radio.setupTty()) { + System.err.println("Failed to setup tty port parameters"); + System.exit(-1); + } + printUsage(); + + // By default, this radio simply transmits data sent via writeData() + // and reads any available data via readData(). + + // It can be placed into a configuration mode by grounding the + // CONFIG pin on the module. When this is done, the various + // configuration query and config methods can be used. In this + // example, by default, we just read any data available fom the + // device, and periodically transmit "Hello World". + + // If any argument was specified on the command line, do a simple + // configuration query and output the results. The radio must be in· + // CONFIG mode for this to work. + + if (args.length > 0) { + // config mode + long[] freq = {0}; + long[] dataRate = {0}; + int[] rxBandwidth = {0}; + short[] modulation = {0}; + short[] txPower = {0}; + long[] uartBaud = {0}; + + if (radio.getConfig(freq, dataRate, rxBandwidth, modulation, txPower, uartBaud)) { + System.out.println("Radio configuration:"); + System.out.println("freq: " + freq[0] + " dataRate: " + dataRate[0] + + " rxBandwidth: " + rxBandwidth[0] + "Khz"); + System.out.println("modulation: " + modulation[0] + "Khz txPower: " + txPower[0] + + " uartBaud: " + uartBaud[0]); + } else { + System.err.println("getConfig() failed. Make sure the radio is in CONFIG mode."); + } + } else { + // normal read/write mode + byte[] radioBuffer = new byte[bufferLength]; + byte[] hello = "Hello World".getBytes(); + int counter = 0; + + System.out.println("Running in normal read/write mode."); + + while (true) { + // we don't want the read to block in this example, so always + // check to see if data is available first. + if (radio.dataAvailable()) { + int rv = radio.readData(radioBuffer); + + if (rv > 0) { + System.out.print("Received: "); + for (int i = 0; i < radioBuffer.length; i++) + System.out.print((char) radioBuffer[i]); + System.out.println(); + } else { + System.err.println("Port read error."); + break; + } + continue; + } + + Thread.sleep(100); + + counter++; + // every second, transmit "Hello World!" + if (counter > 10) { + System.out.println("Transmitting hello world..."); + radio.writeData(hello); + counter = 0; + } + } + } + // ! [Interesting] + } +} diff --git a/examples/java/HTU21DSample.java b/examples/java/HTU21DSample.java index a1b0c901..a402d046 100644 --- a/examples/java/HTU21DSample.java +++ b/examples/java/HTU21DSample.java @@ -1,33 +1,59 @@ -import upm_htu21d.javaupm_htu21dConstants; +/* + * Author: Stefan Andritoiu + * 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 HTU21DSample{ +//NOT TESTED!!! +public class HTU21DSample { static { try { System.loadLibrary("javaupm_htu21d"); - }catch (UnsatisfiedLinkError e) { + } 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(); - + // ! [Interesting] + float humidity = 0; + float temperature = 0; + float compRH = 0; + + upm_htu21d.HTU21D sensor = new upm_htu21d.HTU21D(0); + sensor.testSensor(); + while (true) { compRH = sensor.getCompRH(); humidity = sensor.getHumidity(); temperature = sensor.getTemperature(); - - System.out.println( "Humidity: " + humidity + ", Temperature: " + temperature + ", compensated RH: " + compRH); - + + System.out.println("Humidity: " + humidity + ", Temperature: " + temperature + + ", compensated RH: " + compRH); + Thread.sleep(5000); } + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/Hmc5883lSample.java b/examples/java/Hmc5883lSample.java index 4efe121c..ed9a1da4 100644 --- a/examples/java/Hmc5883lSample.java +++ b/examples/java/Hmc5883lSample.java @@ -22,39 +22,39 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//NOT TESTED!!! public class Hmc5883lSample { static { try { System.loadLibrary("javaupm_hmc5883l"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate on I2C - upm_hmc5883l.Hmc5883l compas = new upm_hmc5883l.Hmc5883l(0); - + upm_hmc5883l.Hmc5883l compas = new upm_hmc5883l.Hmc5883l(0); + int[] pos; - + // Set your declination from true north in radians compas.set_declination(0.2749f); - - while(true){ + + while (true) { // Update the coordinates compas.update(); - + pos = compas.coordinates(); - System.out.println("Coor: " + pos[0] + " " + pos[1] + " " + pos[2]); - System.out.println("Heading: " + compas.heading() + " Direction:" + compas.heading()); - - Thread.sleep(1000); + System.out.println("Coor: " + (short) pos[0] + " " + (short) pos[1] + " " + + (short) pos[2]); + System.out.println("Heading: " + compas.heading() + " Direction:" + compas.direction()); + + Thread.sleep(2000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/Itg3200Sample.java b/examples/java/Itg3200Sample.java index 59b2a196..e76316a1 100644 --- a/examples/java/Itg3200Sample.java +++ b/examples/java/Itg3200Sample.java @@ -24,36 +24,37 @@ //NOT TESTED!!! public class Itg3200Sample { - + static { try { System.loadLibrary("javaupm_itg3200"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + 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()); - + + 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] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/Jhd1313m1Sample.java b/examples/java/Jhd1313m1Sample.java new file mode 100644 index 00000000..5145136c --- /dev/null +++ b/examples/java/Jhd1313m1Sample.java @@ -0,0 +1,51 @@ +/* + * Author: Stefan Andritoiu + * 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 Jhd1313m1Sample { + + static { + try { + System.loadLibrary("javaupm_i2clcd"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_i2clcd.Jhd1313m1 lcd = new upm_i2clcd.Jhd1313m1(0); + + lcd.setCursor(0, 0); + lcd.write("Hello World"); + lcd.setCursor(1, 2); + lcd.write("Hello World"); + + System.out.println("Sleeping for 5 seconds"); + Thread.sleep(5000); + lcd.clear(); + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/LDT0028Sample.java b/examples/java/LDT0028Sample.java index 2b80dadf..152d81ed 100644 --- a/examples/java/LDT0028Sample.java +++ b/examples/java/LDT0028Sample.java @@ -28,24 +28,24 @@ public class LDT0028Sample { static { try { System.loadLibrary("javaupm_ldt0028"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] - + // ! [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){ + + while (true) { System.out.println("Sample value: " + sensor.getSample()); Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/LSM303Sample.java b/examples/java/LSM303Sample.java index f47b1421..f3d4d4bc 100644 --- a/examples/java/LSM303Sample.java +++ b/examples/java/LSM303Sample.java @@ -27,15 +27,15 @@ public class LSM303Sample { static { try { - System.loadLibrary("upm_lsm303"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_lsm303"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate LSM303 compass on I2C upm_lsm303.LSM303 sensor = new upm_lsm303.LSM303(0); @@ -43,23 +43,26 @@ public class LSM303Sample { sensor.getCoordinates(); int[] coor = sensor.getRawCoorData(); // in XYZ order.· // The sensor returns XZY, but the driver compensates and makes it XYZ - + // Print out the X, Y, and Z coordinate data using two different methods System.out.println("coor: rX " + coor[0] + " - rY " + coor[1] + " - rZ " + coor[2]); - System.out.println("coor: gX " + sensor.getCoorX() + " - gY " + sensor.getCoorY() + " - gZ " + sensor.getCoorZ()); - + System.out.println("coor: gX " + sensor.getCoorX() + " - gY " + sensor.getCoorY() + + " - gZ " + sensor.getCoorZ()); + // Get and print out the heading System.out.println("heading: " + sensor.getHeading()); - + // Get the acceleration sensor.getAcceleration(); int[] accel = sensor.getRawAccelData(); - - // Print out the X, Y, and Z acceleration data using two different methods + + // Print out the X, Y, and Z acceleration data using two different + // methods System.out.println("acc: rX " + accel[0] + " - rY " + accel[1] + " - rZ " + accel[2]); - System.out.println("acc: gX " + sensor.getAccelX() + " - gY " + sensor.getAccelY() + " - gZ " + sensor.getAccelZ()); - - //! [Interesting] + System.out.println("acc: gX " + sensor.getAccelX() + " - gY " + sensor.getAccelY() + + " - gZ " + sensor.getAccelZ()); + + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/Lcm1602_i2cSample.java b/examples/java/Lcm1602_i2cSample.java new file mode 100644 index 00000000..8b49744a --- /dev/null +++ b/examples/java/Lcm1602_i2cSample.java @@ -0,0 +1,58 @@ +/* + * Author: Stefan Andritoiu + * 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 Lcm1602_i2cSample { + + static { + try { + System.loadLibrary("javaupm_i2clcd"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602(0, 0x27); + + lcd.setCursor(0, 0); + lcd.write("Hello World"); + Thread.sleep(3000); + + lcd.setCursor(1, 2); + lcd.write("Hello World"); + Thread.sleep(3000); + + lcd.setCursor(2, 4); + lcd.write("Hello World"); + Thread.sleep(3000); + + lcd.setCursor(3, 6); + lcd.write("Hello World"); + Thread.sleep(3000); + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/Lcm1602_parallelSample.java b/examples/java/Lcm1602_parallelSample.java new file mode 100644 index 00000000..69064a63 --- /dev/null +++ b/examples/java/Lcm1602_parallelSample.java @@ -0,0 +1,61 @@ +/* + * Author: Stefan Andritoiu + * 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 Lcm1602_parallelSample { + + static { + try { + System.loadLibrary("javaupm_i2clcd"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + // LCD connection: + // LCD RS pin to digital pin 8 + // LCD Enable pin to digital pin 13 + // LCD D4 pin to digital pin 2 + // LCD D5 pin to digital pin 3 + // LCD D6 pin to digital pin 4 + // LCD D7 pin to digital pin 5 + // LCD R/W pin to ground + // 10K trimmer potentiometer: + // ends to +5V and ground + // wiper to LCD VO pin (pin 3) + upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602(8, 13, 2, 3, 4, 5, 20, 2); + + lcd.setCursor(0, 0); + lcd.write("Hello World"); + lcd.setCursor(1, 2); + lcd.write("Hello World"); + + System.out.println("Sleeping for 5 seconds"); + Thread.sleep(5000); + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/LoL_exampleSample.java b/examples/java/LoL_exampleSample.java new file mode 100644 index 00000000..73e8e6fc --- /dev/null +++ b/examples/java/LoL_exampleSample.java @@ -0,0 +1,58 @@ +/* + * Author: Stefan Andritoiu + * 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 LoL_exampleSample { + + static { + try { + System.loadLibrary("javaupm_lol"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_lol.LoL sensor = new upm_lol.LoL(); + + int x = 0, y = 0; + while (true) { + // revert pixel + short pixel = sensor.getPixel(x, y); + pixel = (short) ((pixel == 0) ? 1 : 0); + sensor.setPixel(x, y, pixel); + + if (++x == 13) { + x = 0; + y++; + } + if (y == 9) + y = 0; + Thread.sleep(10); + } + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/M24LR64ESample.java b/examples/java/M24LR64ESample.java new file mode 100644 index 00000000..d9aa235d --- /dev/null +++ b/examples/java/M24LR64ESample.java @@ -0,0 +1,64 @@ +/* + * Author: Stefan Andritoiu + * 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 M24LR64ESample { + + static { + try { + System.loadLibrary("javaupm_m24lr64e"); + } 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 M24LR64E on I2C bus 0 + upm_m24lr64e.M24LR64E nfcTag = new upm_m24lr64e.M24LR64E(0); + + // This example accesses the device in the 'user' (default) mode, + // reads the last byte of data in the EEPROM, inverts it, writes + // it back, and then re-reads it. + + // Read the last byte of the EEPROM area + int addr = upm_m24lr64e.M24LR64E.EEPROM_I2C_LENGTH - 1; + System.out.println("Address: " + addr); + short read = nfcTag.readByte(addr); + System.out.println("Read: " + read); + + // Now change it to it's opposite and write it + read = (short) (~read & 0xff); + nfcTag.writeByte(addr, read); + System.out.println("Wrote: " + read); + + // Now read it back + read = nfcTag.readByte(addr); + System.out.println("Read: " + read); + + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/MAX44000Sample.java b/examples/java/MAX44000Sample.java index 5e39ec7d..144d1fd0 100644 --- a/examples/java/MAX44000Sample.java +++ b/examples/java/MAX44000Sample.java @@ -27,21 +27,21 @@ public class MAX44000Sample { static { try { - System.loadLibrary("upm_max44000"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_max44000"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] upm_max44000.MAX44000 sensor = new upm_max44000.MAX44000(0); - - while(true){ + + while (true) { System.out.println("proximity value = " + sensor.getAmbient()); Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/MHZ16Sample.java b/examples/java/MHZ16Sample.java index bb784e80..9f75159d 100644 --- a/examples/java/MHZ16Sample.java +++ b/examples/java/MHZ16Sample.java @@ -24,35 +24,36 @@ //NOT TESTED!!! public class MHZ16Sample { - + static { try { System.loadLibrary("javaupm_mhz16"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { co2.getData(gas, temp); - System.out.println("CO2 concentration: " + gas[0] + "PPM, Temperature (in C): " + temp[0]); - + System.out.println("CO2 concentration: " + gas[0] + "PPM, Temperature (in C): " + + temp[0]); + Thread.sleep(2000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MMA7455Sample.java b/examples/java/MMA7455Sample.java new file mode 100644 index 00000000..98532e3b --- /dev/null +++ b/examples/java/MMA7455Sample.java @@ -0,0 +1,51 @@ +/* + * Author: Stefan Andritoiu + * 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 MMA7455Sample { + + static { + try { + System.loadLibrary("javaupm_mma7455"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_mma7455.MMA7455 sensor = new upm_mma7455.MMA7455(0); + short[] val; + + while (true) { + val = sensor.readData(); + System.out.println("Accelerometer X: " + val[0] + ", Y: " + val[1] + ", Z: " + val[2]); + + Thread.sleep(1000); + } + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/MMA7660Sample.java b/examples/java/MMA7660Sample.java index cc7d2a20..58be0884 100644 --- a/examples/java/MMA7660Sample.java +++ b/examples/java/MMA7660Sample.java @@ -28,35 +28,37 @@ public class MMA7660Sample { static { try { System.loadLibrary("javaupm_mma7660"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { int[] rawValues = accel.getRawValues(); - System.out.println("Raw Values: x = " + rawValues[0] + " y = " + rawValues[1] + " x = " + rawValues[2]); - + 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]); - + System.out.println("Raw Values: x = " + acceleration[0] + " y = " + acceleration[1] + + " x = " + acceleration[2]); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MPL3115A2Sample.java b/examples/java/MPL3115A2Sample.java index ff998068..46cfadb1 100644 --- a/examples/java/MPL3115A2Sample.java +++ b/examples/java/MPL3115A2Sample.java @@ -27,28 +27,28 @@ public class MPL3115A2Sample { static { try { - System.loadLibrary("upm_mpl3115a2"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_mpl3115a2"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a MPL3115A2 sensor on I2C upm_mpl3115a2.MPL3115A2 sensor = new upm_mpl3115a2.MPL3115A2(0); - - while(true){ + + while (true) { System.out.println("Pressure: " + sensor.getPressure()); System.out.println("Altitude: " + sensor.getAltitude()); System.out.println("Sealevel pressure: " + sensor.getSealevelPressure()); System.out.println("Temperature: " + sensor.getTemperature()); System.out.println(); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MPR121Sample.java b/examples/java/MPR121Sample.java index c2e77d23..bbf788d7 100644 --- a/examples/java/MPR121Sample.java +++ b/examples/java/MPR121Sample.java @@ -1,38 +1,38 @@ -public class MPR121Sample{ - +public class MPR121Sample { + static { try { System.loadLibrary("javaupm_mpr121"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - - private static void printButtons(upm_mpr121.MPR121 touch){ + + 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 + " "); + if ((touch.getM_buttonStates() & (1 << i)) != 0) { + System.out.print(i + " "); buttonPresed = true; } } - - if (!buttonPresed) + + if (!buttonPresed) System.out.print("None "); - - System.out.println(); + + 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 + + // init according to AN3944 defaults touch.configAN3944(); - + while (true) { touch.readButtons(); printButtons(touch); diff --git a/examples/java/MPU9150Sample.java b/examples/java/MPU9150Sample.java index 819be995..35f9affc 100644 --- a/examples/java/MPU9150Sample.java +++ b/examples/java/MPU9150Sample.java @@ -27,33 +27,36 @@ public class MPU9150Sample { static { try { - System.loadLibrary("upm_mpu9150"); - }catch (UnsatisfiedLinkError e) { + System.loadLibrary("javaupm_mpu9150"); + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] upm_mpu9150.MPU9150 sensor = new upm_mpu9150.MPU9150(); - + sensor.init(); - - while(true){ + + while (true) { sensor.update(); - + float[] accel = sensor.getAccelerometer(); - System.out.println("Accelerometer: " + "AX: " + accel[0] + " AY: " + accel[1] + " AZ: " + accel[2] ); + System.out.println("Accelerometer: " + "AX: " + accel[0] + " AY: " + accel[1] + " AZ: " + + accel[2]); float[] gyro = sensor.getGyroscope(); - System.out.println("Gryoscope: " + "GX: " + gyro[0] + " GY: " + gyro[1] + " GZ: " + gyro[2] ); - + System.out.println("Gryoscope: " + "GX: " + gyro[0] + " GY: " + gyro[1] + " GZ: " + + gyro[2]); + float[] magn = sensor.getMagnetometer(); - System.out.println("Magnetometer: " + "MX: " + magn[0] + " MY: " + magn[1] + " MZ: " + magn[2] ); - + System.out.println("Magnetometer: " + "MX: " + magn[0] + " MY: " + magn[1] + " MZ: " + + magn[2]); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MQ2Sample.java b/examples/java/MQ2Sample.java index 11a1ca7e..46a4bfcf 100644 --- a/examples/java/MQ2Sample.java +++ b/examples/java/MQ2Sample.java @@ -25,41 +25,41 @@ //NOT TESTED!!! public class MQ2Sample { private static final short resolution = 5; - + static { try { System.loadLibrary("javaupm_gas"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { int len = sensor.getSampledWindow(2, buffer); - - if(len != 0){ + + if (len != 0) { int thresh = sensor.findThreshold(ctx, 30, buffer); sensor.printGraph(ctx, resolution); - if (thresh != 0){ + if (thresh != 0) { System.out.println("---Threshold reached---"); } } - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MQ303ASample.java b/examples/java/MQ303ASample.java index 3a567ae6..a11d9f3f 100644 --- a/examples/java/MQ303ASample.java +++ b/examples/java/MQ303ASample.java @@ -22,43 +22,41 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class MQ303ASample{ +public class MQ303ASample { static { try { System.loadLibrary("javaupm_mq303a"); - }catch (UnsatisfiedLinkError e) { + } 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 mq303a sensor on analog pin A0 - + // Instantiate an mq303a sensor on analog pin A0 + // This device uses a heater powered from an analog I/O pin.· // If using A0 as the data pin, then you need to use A1, as the heater - // pin (if using a grove mq303a). For A1, we can use the D15 gpio,· + // pin (if using a grove mq303a). For A1, we can use the D15 gpio,· // setup as an output, and drive it low to power the heater. - upm_mq303a.MQ303A mq303a = new upm_mq303a.MQ303A(1,15); - + upm_mq303a.MQ303A mq303a = new upm_mq303a.MQ303A(1, 15); + System.out.println("Enabling heater and waiting 2 minutes for warmup."); mq303a.heaterEnable(true); Thread.sleep(120000); - + System.out.println("This sensor may need to warm until the value drops below about 450."); - - for(int i = 1 ; i < 10 ; i++){ + + for (int i = 1; i < 10; i++) { int val = mq303a.value(); System.out.println("Alcohol detected (higher means stronger alcohol): " + val); - + Thread.sleep(1000); } - + mq303a.heaterEnable(false); System.out.println("Exiting"); - //! [Interesting] - } + } -} +} \ No newline at end of file diff --git a/examples/java/MQ5Sample.java b/examples/java/MQ5Sample.java index c1f90c69..082697f9 100644 --- a/examples/java/MQ5Sample.java +++ b/examples/java/MQ5Sample.java @@ -24,41 +24,41 @@ public class MQ5Sample { private static final short resolution = 7; - + static { try { System.loadLibrary("javaupm_gas"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { int len = sensor.getSampledWindow(2, buffer); - - if(len != 0){ + + if (len != 0) { int thresh = sensor.findThreshold(ctx, 30, buffer); sensor.printGraph(ctx, resolution); - if (thresh != 0){ + if (thresh != 0) { System.out.println("---Threshold reached---"); } } - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/MY9221Sample.java b/examples/java/MY9221Sample.java new file mode 100644 index 00000000..0c390b7d --- /dev/null +++ b/examples/java/MY9221Sample.java @@ -0,0 +1,48 @@ +/* + * Author: Stefan Andritoiu + * 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 MY9221Sample { + + static { + try { + System.loadLibrary("javaupm_my9221"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // 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); + + while (true) { + for (short idx = 1; idx < 11; idx++) { + bar.setBarLevel(idx); + Thread.sleep(100); + } + } + } + +} \ No newline at end of file diff --git a/examples/java/MicrophoneSample.java b/examples/java/MicrophoneSample.java index 4603f13f..8b3d9434 100644 --- a/examples/java/MicrophoneSample.java +++ b/examples/java/MicrophoneSample.java @@ -22,43 +22,44 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class MicrophoneSample{ - +public class MicrophoneSample { + static { try { System.loadLibrary("javaupm_mic"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + 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()); + if (thresh != 0) { + System.out.println("---Threshold reached--- " + ctx.getRunningAverage() + " " + + ctx.getAverageReading()); } } } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/NRF24L01_receiverSample.java b/examples/java/NRF24L01_receiverSample.java new file mode 100644 index 00000000..631fb8a3 --- /dev/null +++ b/examples/java/NRF24L01_receiverSample.java @@ -0,0 +1,84 @@ +/* + * Author: Stefan Andritoiu + * 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_nrf24l01.Callback; + +//NOT TESTED!!! +public class NRF24L01_receiverSample { + + static private final byte[] local_address = {0x01, 0x01, 0x01, 0x01, 0x01}; + static private final byte[] broadcast_address = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF}; + + static { + try { + System.loadLibrary("javaupm_nrf24l01"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_nrf24l01.NRF24L01 comm = new upm_nrf24l01.NRF24L01((short) 7, (short) 8); + + Callback callback = new ReceiverCallback(comm); + + comm.setSourceAddress(local_address); + comm.setDestinationAddress(broadcast_address); + comm.setPayload((short) upm_nrf24l01.javaupm_nrf24l01Constants.MAX_BUFFER); + comm.configure(); + comm.setSpeedRate(upm_nrf24l01.speed_rate_t.NRF_250KBPS); + comm.setChannel((short) 99); + comm.setDataReceivedHandler(callback); + + while (true) { + comm.pollListener(); + } + + // ! [Interesting] + } +} + +class ReceiverCallback extends Callback { + + private upm_nrf24l01.NRF24L01 comm = null; + + public ReceiverCallback(upm_nrf24l01.NRF24L01 comm) { + super(); + this.comm = comm; + } + public void run() { + if (comm != null) { + short[] rx_buffer = comm.getM_rxBuffer(); + System.out.print("Received: "); + for (int i = 0; i < rx_buffer.length; i++) + System.out.print(rx_buffer[i]); + System.out.println(); + } else { + System.out.println("No NRF24L01 instance given to callback"); + } + } +} \ No newline at end of file diff --git a/examples/java/NRF24L01_transmitterSample.java b/examples/java/NRF24L01_transmitterSample.java new file mode 100644 index 00000000..e646351b --- /dev/null +++ b/examples/java/NRF24L01_transmitterSample.java @@ -0,0 +1,75 @@ +/* + * Author: Stefan Andritoiu + * 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_nrf24l01.Callback; + +//NOT TESTED!!! +public class NRF24L01_transmitterSample { + + static private final byte[] destAddress = {0x01, 0x01, 0x01, 0x01, 0x01}; + static private final byte[] srcAddress = {0x01, 0x01, 0x01, 0x01, 0x01}; + static private byte[] tx_buffer = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x00}; + + static { + try { + System.loadLibrary("javaupm_nrf24l01"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_nrf24l01.NRF24L01 comm = new upm_nrf24l01.NRF24L01((short) 7, (short) 8); + + Callback callback = new TransmitterCallback(); + + comm.setSourceAddress(srcAddress); + comm.setDestinationAddress(destAddress); + comm.setPayload((short) upm_nrf24l01.javaupm_nrf24l01Constants.MAX_BUFFER); + comm.setChannel((short) 99); + comm.configure(); + comm.setDataReceivedHandler(callback); + + while (true) { + comm.send(tx_buffer); + System.out.println("devi2 :: sending data ...."); + for (int i = 0; i < tx_buffer.length; i++) + System.out.print(tx_buffer[i]); + System.out.println(); + Thread.sleep(3000); + } + // ! [Interesting] + } +} + +class TransmitterCallback extends Callback { + public TransmitterCallback() { + super(); + } + public void run() { + } +} \ No newline at end of file diff --git a/examples/java/NUNCHUCKSample.java b/examples/java/NUNCHUCKSample.java index 29b39199..a4d3c139 100644 --- a/examples/java/NUNCHUCKSample.java +++ b/examples/java/NUNCHUCKSample.java @@ -22,22 +22,22 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class NUNCHUCKSample{ - +public class NUNCHUCKSample { + static { try { System.loadLibrary("javaupm_nunchuck"); - }catch (UnsatisfiedLinkError e) { + } 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 nunchuck controller bus 0 + // ! [Interesting] + // Instantiate a nunchuck controller bus 0 upm_nunchuck.NUNCHUCK nunchuck = new upm_nunchuck.NUNCHUCK(0); - + // always do this first System.out.println("Initializing... "); if (!nunchuck.init()) { @@ -45,25 +45,26 @@ public class NUNCHUCKSample{ return; } - while(true){ + while (true) { nunchuck.update(); - System.out.println( "stickX: " + nunchuck.getStickX() + ", stickY: " + nunchuck.getStickY() ); - System.out.println( "accelX: " + nunchuck.getAccelX() + ", accelY: " + nunchuck.getAccelY() - +", accelZ: " + nunchuck.getAccelZ()); - - if(nunchuck.getButtonC()) + System.out.println("stickX: " + nunchuck.getStickX() + ", stickY: " + + nunchuck.getStickY()); + System.out.println("accelX: " + nunchuck.getAccelX() + ", accelY: " + + nunchuck.getAccelY() + ", accelZ: " + nunchuck.getAccelZ()); + + if (nunchuck.getButtonC()) System.out.println("Button C pressed"); else System.out.println("Button C not pressed"); - - if(nunchuck.getButtonZ()) + + if (nunchuck.getButtonZ()) System.out.println("Button Z pressed"); else System.out.println("Button Z not pressed"); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/OTP538USample.java b/examples/java/OTP538USample.java index 9b11e508..be9ce150 100644 --- a/examples/java/OTP538USample.java +++ b/examples/java/OTP538USample.java @@ -22,30 +22,31 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class OTP538USample{ +public class OTP538USample { private static final float OTP538U_AREF = 5; - + static { try { System.loadLibrary("javaupm_otp538u"); - }catch (UnsatisfiedLinkError e) { + } 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 OTP538U on analog pins A0 and A1 - // A0 is used for the Ambient Temperature and A1 is used for the Object temperature. + // ! [Interesting] + // Instantiate a OTP538U on analog pins A0 and A1 + // A0 is used for the Ambient Temperature and A1 is used for the Object + // temperature. upm_otp538u.OTP538U temps = new upm_otp538u.OTP538U(0, 1, OTP538U_AREF); while (true) { - System.out.println( "Ambient temp: " + temps.ambientTemperature() + " C" ); - System.out.println( "Object temp: " + temps.objectTemperature() + " C" ); - + System.out.println("Ambient temp: " + temps.ambientTemperature() + " C"); + System.out.println("Object temp: " + temps.objectTemperature() + " C"); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/PPD42NSSample.java b/examples/java/PPD42NSSample.java index a6b64f68..d543f1ac 100644 --- a/examples/java/PPD42NSSample.java +++ b/examples/java/PPD42NSSample.java @@ -22,34 +22,33 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//NOT TESTED!!! public class PPD42NSSample { static { try { System.loadLibrary("javaupm_ppd42ns"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a dust sensor on GPIO pin D8 upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8); upm_ppd42ns.dustData data; - + System.out.println("This program will give readings every 30 seconds until you stop it"); - - while(true){ + + while (true) { data = dust.getData(); - + System.out.println("Low pulse occupancy: " + data.getLowPulseOccupancy()); System.out.println("Ratio: " + data.getRatio()); System.out.println("Concentration: " + data.getConcentration()); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/RFR359FSample.java b/examples/java/RFR359FSample.java index f1839209..869820e3 100644 --- a/examples/java/RFR359FSample.java +++ b/examples/java/RFR359FSample.java @@ -22,33 +22,32 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class RFR359FSample{ +public class RFR359FSample { static { try { System.loadLibrary("javaupm_rfr359f"); - }catch (UnsatisfiedLinkError e) { + } 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 RFR359F digital pin D2 + // ! [Interesting] + // Instantiate an RFR359F digital pin D2 upm_rfr359f.RFR359F dInterruptor = new upm_rfr359f.RFR359F(2); - - while(true){ + + while (true) { if (dInterruptor.objectDetected()) { System.out.println("Object detected"); - } - else{ + } else { System.out.println("Area is clear!"); } - + Thread.sleep(100); } - //! [Interesting] + // ! [Interesting] } - -} + +} \ No newline at end of file diff --git a/examples/java/RPR220Sample.java b/examples/java/RPR220Sample.java index 4659500d..4318c4ae 100644 --- a/examples/java/RPR220Sample.java +++ b/examples/java/RPR220Sample.java @@ -23,31 +23,31 @@ */ public class RPR220Sample { - + static { try { System.loadLibrary("javaupm_rpr220"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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()) + + while (true) { + if (sensor.blackDetected()) System.out.println("Black detected"); else System.out.println("Black NOT detected"); - + Thread.sleep(100); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/RPR220_intrSample.java b/examples/java/RPR220_intrSample.java index b1832521..5d72d4ac 100644 --- a/examples/java/RPR220_intrSample.java +++ b/examples/java/RPR220_intrSample.java @@ -25,41 +25,41 @@ import upm_rpr220.IsrCallback; public class RPR220_intrSample { - - public static int counter=0; - + + public static int counter = 0; + static { try { System.loadLibrary("javaupm_rpr220"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + + while (true) { System.out.println("Counter: " + counter); Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } class RPRISR extends IsrCallback { - public RPRISR(){ + public RPRISR() { super(); } - public void run(){ + public void run() { RPR220_intrSample.counter++; } } \ No newline at end of file diff --git a/examples/java/RotaryEncoderSample.java b/examples/java/RotaryEncoderSample.java index c6526f19..a20b93c8 100644 --- a/examples/java/RotaryEncoderSample.java +++ b/examples/java/RotaryEncoderSample.java @@ -22,28 +22,28 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class RotaryEncoderSample{ +public class RotaryEncoderSample { static { try { System.loadLibrary("javaupm_rotaryencoder"); - }catch (UnsatisfiedLinkError e) { + } 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 button object using UART + // ! [Interesting] + // Create the button object using UART upm_rotaryencoder.RotaryEncoder rotaryencoder = new upm_rotaryencoder.RotaryEncoder(2, 3); - + while (true) { System.out.println("Position: " + rotaryencoder.position()); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/SSD1308_oledSample.java b/examples/java/SSD1308_oledSample.java new file mode 100644 index 00000000..b74b62b6 --- /dev/null +++ b/examples/java/SSD1308_oledSample.java @@ -0,0 +1,98 @@ +/* + * Author: Stefan Andritoiu + * 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 SSD1308_oledSample { + + static { + try { + System.loadLibrary("javaupm_i2clcd"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + static private final int[] IntelLogo = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 192, + 192, 192, 224, 224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, + 60, 62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31, 30, 62, 62, 62, 62, + 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240, 224, 224, 224, 192, 128, 128, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, + 128, 128, 128, 128, 128, 128, 128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 192, + 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195, 195, 7, 15, 15, 63, 127, + 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0, 0, 0, 0, 0, 0, 128, 192, 192, 240, + 248, 124, 124, 60, 0, 0, 0, 0, 159, 159, 159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 0, 0, 0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128, + 128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128, 128, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 3, 7, 3, 3, + 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255, 255, 255, 0, 0, 224, 248, 252, 252, + 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, + 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, + 255, 255, 255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15, + 15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143, 135, 135, 143, + 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255, 255, 255, 255, 255, 255, + 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 224, 248, 248, 255, 255, 255, 255, + 255, 127, 15, 255, 255, 255, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, + 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, + 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, + 255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255, 255, 255, 255, + 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231, 231, 231, 199, 135, 0, 0, + 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 224, 240, 248, 248, 252, 254, + 255, 255, 255, 127, 63, 63, 31, 15, 7, 7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, + 240, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, + 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7, 7, 7, + 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7, 7, 3, 3, 3, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15, 31, 127, 127, 127, 255, 255, + 252, 252, 252, 248, 240, 240, 240, 224, 224, 224, 192, 192, 192, 192, 128, 128, 128, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, + 192, 192, 192, 224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, + 252, 254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 15, + 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127, 127, 127, 255, 255, 255, 255, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, + 127, 127, 127, 127, 63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, + 3, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0}; + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_i2clcd.SSD1308 lcd = new upm_i2clcd.SSD1308(0); + + byte[] image = new byte[IntelLogo.length]; + for (int i = 0; i < IntelLogo.length; i++) + image[i] = (byte) IntelLogo[i]; + + lcd.clear(); + lcd.draw(image); + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/SSD1327_oledSample.java b/examples/java/SSD1327_oledSample.java new file mode 100644 index 00000000..bc7e984f --- /dev/null +++ b/examples/java/SSD1327_oledSample.java @@ -0,0 +1,144 @@ +/* + * Author: Stefan Andritoiu + * 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 SSD1327_oledSample { + + static { + try { + System.loadLibrary("javaupm_i2clcd"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + static private final int[] SeeedLogo = new int[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x03, + 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x01, 0xC0, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x07, 0x80, 0x01, 0xE0, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, + 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, + 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x38, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x80, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3C, 0x0F, 0x80, 0x01, 0xE0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x0F, 0x80, 0x03, 0xE0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x07, + 0x80, 0x03, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x07, 0x80, 0x03, + 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x07, 0x80, 0x03, 0xC1, 0xF0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x87, 0xC0, 0x07, 0xC1, 0xF0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0F, 0xC3, 0xC0, 0x07, 0x87, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xE1, 0xE0, 0x07, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, + 0xE0, 0x0F, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0xF0, 0x0E, + 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x70, 0x1C, 0x3F, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x30, 0x18, 0x7E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x18, 0x30, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x1F, 0x88, 0x21, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0F, 0xC4, 0x47, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0xE0, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x06, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x06, 0x00, 0x00, 0x60, 0x00, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xDF, 0xE1, + 0x9F, 0xEC, 0x7E, 0xE6, 0x73, 0x9C, 0xE7, 0x39, 0xCE, 0x1C, 0xDF, 0xE1, 0xB9, 0xEC, + 0xE7, 0xE0, 0x61, 0xD8, 0x66, 0x1B, 0x86, 0x1C, 0x06, 0x61, 0xB0, 0x6D, 0xC3, 0x7C, + 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x0F, 0x86, 0x61, 0xB0, 0x6D, 0x83, 0x3E, 0x7F, 0xFF, + 0xFF, 0xFF, 0x06, 0x07, 0xC6, 0x61, 0xB0, 0x6D, 0x83, 0xC3, 0x61, 0x18, 0x46, 0x03, + 0x86, 0x18, 0x66, 0x61, 0xB0, 0x6D, 0xC3, 0xFE, 0x7F, 0x9F, 0xE7, 0xF9, 0xFE, 0x1F, + 0xE6, 0x3F, 0x9F, 0xEC, 0xFE, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xC6, 0x3F, + 0x9F, 0xEC, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x20, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x44, 0x00, 0x00, 0x20, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, + 0xF3, 0xCF, 0x70, 0x9E, 0x79, 0xE7, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x9E, 0x68, + 0x20, 0xB2, 0xC8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x9E, 0x6F, 0x20, 0xB2, + 0xF9, 0xE7, 0x80, 0x00, 0x00, 0x00, 0x00, 0x46, 0x9A, 0x61, 0x20, 0xB2, 0xCB, 0x60, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xF3, 0xCF, 0x30, 0x9E, 0x79, 0xE7, 0x90, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x7C, 0x02, 0x00, 0x00, 0x82, 0x60, 0x00, 0x00, 0xF8, 0x00, 0x00, + 0x40, 0x40, 0x02, 0x00, 0x00, 0x83, 0x60, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x40, 0x60, + 0xB7, 0x79, 0xE7, 0x81, 0xC7, 0x92, 0x70, 0x89, 0xE7, 0x9E, 0x78, 0x7C, 0xE2, 0xC9, + 0x2C, 0x81, 0xCC, 0xD2, 0x40, 0xFB, 0x21, 0xB2, 0x48, 0x40, 0x62, 0xF9, 0x2C, 0x80, + 0x8C, 0xD2, 0x40, 0x8B, 0xE7, 0xB0, 0x48, 0x40, 0xE2, 0xC9, 0x2C, 0x80, 0x84, 0xD2, + 0x40, 0x8B, 0x2D, 0x92, 0x48, 0x7D, 0xB3, 0x79, 0x27, 0x80, 0x87, 0x9E, 0x40, 0x8D, + 0xE7, 0x9E, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_i2clcd.SSD1327 lcd = new upm_i2clcd.SSD1327(0); + + // If you don't set the display to be white, the seeed logo will appear + // jagged + lcd.setGrayLevel((short) 12); + + byte[] image = new byte[SeeedLogo.length]; + for (int i = 0; i < SeeedLogo.length; i++) + image[i] = (byte) SeeedLogo[i]; + + lcd.draw(image); + + // Simple print hello world + for (short i = 0; i < 12; i++) { + lcd.setCursor(i, 0); + lcd.setGrayLevel(i); + lcd.write("Hello World"); + } + + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/ST7735Sample.java b/examples/java/ST7735Sample.java new file mode 100644 index 00000000..1cd50b11 --- /dev/null +++ b/examples/java/ST7735Sample.java @@ -0,0 +1,86 @@ +/* + * Author: Stefan Andritoiu + * 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 ST7735Sample { + + static { + try { + System.loadLibrary("javaupm_st7735"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_st7735.ST7735 lcd = new upm_st7735.ST7735((short) 7, (short) 4, (short) 9, (short) 8); + + lcd.fillScreen(upm_st7735.javaupm_st7735Constants.ST7735_RED); + lcd.refresh(); + + lcd.fillScreen(upm_st7735.javaupm_st7735Constants.ST7735_CYAN); + lcd.refresh(); + + lcd.fillScreen(upm_st7735.javaupm_st7735Constants.ST7735_BLACK); + lcd.refresh(); + + lcd.drawLine((short) 10, (short) 10, (short) 10, (short) 100, + upm_st7735.javaupm_st7735Constants.ST7735_MAGENTA); + lcd.drawLine((short) 20, (short) 20, (short) 10, (short) 100, + upm_st7735.javaupm_st7735Constants.ST7735_YELLOW); + lcd.drawLine((short) 30, (short) 30, (short) 50, (short) 100, + upm_st7735.javaupm_st7735Constants.ST7735_WHITE); + lcd.refresh(); + + lcd.drawPixel((short) 20, (short) 20, upm_st7735.javaupm_st7735Constants.ST7735_GREEN); + lcd.refresh(); + + lcd.drawTriangle((short) 50, (short) 50, (short) 80, (short) 80, (short) 60, (short) 90, + upm_st7735.javaupm_st7735Constants.ST7735_GREEN); + lcd.refresh(); + + lcd.drawCircle((short) 100, (short) 110, (short) 10, + upm_st7735.javaupm_st7735Constants.ST7735_BLUE); + lcd.refresh(); + + lcd.setTextWrap((short) 0); + + lcd.setCursor((short) 0, (short) 30); + lcd.setTextColor(upm_st7735.javaupm_st7735Constants.ST7735_RED, + upm_st7735.javaupm_st7735Constants.ST7735_RED); + lcd.setTextSize((short) 1); + lcd.print("Hello World!"); + + lcd.setCursor((short) 10, (short) 50); + lcd.setTextColor(upm_st7735.javaupm_st7735Constants.ST7735_RED, + upm_st7735.javaupm_st7735Constants.ST7735_YELLOW); + lcd.setTextSize((short) 2); + lcd.print("BIG"); + + lcd.refresh(); + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/StepMotorSample.java b/examples/java/StepMotorSample.java new file mode 100644 index 00000000..6dee3a21 --- /dev/null +++ b/examples/java/StepMotorSample.java @@ -0,0 +1,62 @@ +/* + * Author: Stefan Andritoiu + * 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 StepMotorSample { + + static { + try { + System.loadLibrary("javaupm_stepmotor"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + upm_stepmotor.StepMotor sensor = new upm_stepmotor.StepMotor(4, 6); + + while (true) { + sensor.setSpeed(500); + sensor.stepForward(500); + Thread.sleep(10); + sensor.stepBackwards(500); + Thread.sleep(10); + + sensor.setSpeed(750); + sensor.stepForward(500); + Thread.sleep(10); + sensor.stepBackwards(500); + Thread.sleep(10); + + sensor.setSpeed(1000); + sensor.stepForward(500); + Thread.sleep(10); + sensor.stepBackwards(500); + Thread.sleep(10); + } + // ! [Interesting] + } +} \ No newline at end of file diff --git a/examples/java/TM1637Sample.java b/examples/java/TM1637Sample.java index 37e01bde..2caf66df 100644 --- a/examples/java/TM1637Sample.java +++ b/examples/java/TM1637Sample.java @@ -30,38 +30,38 @@ public class TM1637Sample { static { try { System.loadLibrary("javaupm_tm1637"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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){ + while (true) { now = LocalDateTime.now(); int hour = now.getHour(); int min = now.getMinute(); int sec = now.getSecond(); - - System.out.println (hour + ":" + min + ":" + sec); + + System.out.println(hour + ":" + min + ":" + sec); myDisplay.writeString(hour + ":" + min); - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/TP401Sample.java b/examples/java/TP401Sample.java index 83100f75..2f815181 100644 --- a/examples/java/TP401Sample.java +++ b/examples/java/TP401Sample.java @@ -22,50 +22,54 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class TP401Sample{ +public class TP401Sample { static { try { System.loadLibrary("javaupm_gas"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - - private static String airQuality(int value){ - if(value < 50) return "Fresh Air"; - if(value < 200) return "Normal Indoor Air"; - if(value < 400) return "Low Pollution"; - if(value < 600) return "High Pollution - Action Recommended"; + + private static String airQuality(int value) { + if (value < 50) + return "Fresh Air"; + if (value < 200) + return "Normal Indoor Air"; + if (value < 400) + return "Low Pollution"; + if (value < 600) + return "High Pollution - Action Recommended"; return "Very High Pollution - Take Action Immediately"; } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] - // Instantiate new grove air quality sensor on analog pin A0 + // ! [Interesting] + // Instantiate new grove air quality sensor on analog pin A0 upm_gas.TP401 airSensor = new upm_gas.TP401(0); - + System.out.println(airSensor.name()); System.out.println("Heating sensor for 3 minutes..."); // wait 3 minutes for sensor to warm up - for(int i = 0; i < 3; i++) { - if(i != 0) - System.out.println("Please wait, " + i + " minute(s) passed.."); - Thread.sleep(60000); - } - System.out.println( "Sensor ready!"); - - while(true){ - int value = airSensor.getSample(); // Read raw value - float ppm = airSensor.getPPM(); // Read CO ppm (can vary slightly from previous read) - - System.out.println("raw: " + value + " ppm: " + ppm + " " + airQuality(value) ); - + for (int i = 0; i < 3; i++) { + if (i != 0) + System.out.println("Please wait, " + i + " minute(s) passed.."); + Thread.sleep(60000); + } + System.out.println("Sensor ready!"); + + while (true) { + int value = airSensor.getSample(); // Read raw value + float ppm = airSensor.getPPM(); // Read CO ppm (can vary slightly + // from previous read) + + System.out.println("raw: " + value + " ppm: " + ppm + " " + airQuality(value)); + Thread.sleep(100); } - //! [Interesting] + // ! [Interesting] } - -} +} \ No newline at end of file diff --git a/examples/java/TSL2561Sample.java b/examples/java/TSL2561Sample.java new file mode 100644 index 00000000..999aaaa8 --- /dev/null +++ b/examples/java/TSL2561Sample.java @@ -0,0 +1,49 @@ +/* + * Author: Stefan Andritoiu + * 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 TSL2561Sample { + + static { + try { + System.loadLibrary("javaupm_tsl2561"); + } 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 TSL2561 Digital Light Sensor on I2C + upm_tsl2561.TSL2561 sensor = new upm_tsl2561.TSL2561(); + + while (true) { + System.out.println("Lux = " + sensor.getLux()); + + Thread.sleep(1000); + } + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/TTP223Sample.java b/examples/java/TTP223Sample.java index e8507f22..a6c90754 100644 --- a/examples/java/TTP223Sample.java +++ b/examples/java/TTP223Sample.java @@ -22,30 +22,30 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class TTP223Sample{ +public class TTP223Sample { static { try { System.loadLibrary("javaupm_ttp223"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] - upm_ttp223.TTP223 touch = new upm_ttp223.TTP223(7); - + // ! [Interesting] + upm_ttp223.TTP223 touch = new upm_ttp223.TTP223(7); + while (true) { - if(touch.isPressed()) - System.out.println( touch.name() + " is pressed" ); + if (touch.isPressed()) + System.out.println(touch.name() + " is pressed"); else - System.out.println( touch.name() + " is not pressed" ); - + System.out.println(touch.name() + " is not pressed"); + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/ULN200XASample.java b/examples/java/ULN200XASample.java index 9da48a42..ee89f926 100644 --- a/examples/java/ULN200XASample.java +++ b/examples/java/ULN200XASample.java @@ -28,35 +28,35 @@ public class ULN200XASample { static { try { System.loadLibrary("javaupm_uln200xa"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a Stepper motor on a ULN200XA Dual H-Bridge. // Wire the pins so that I1 is pin D8, I2 is pin D9, I3 is pin D10 and // I4 is pin D11 upm_uln200xa.ULN200XA uln200xa = new upm_uln200xa.ULN200XA(4096, 8, 9, 10, 11); - + uln200xa.setSpeed(5); System.out.println("Rotating 1 revolution clockwise."); uln200xa.setDirection(upm_uln200xa.ULN200XA.ULN200XA_DIRECTION_T.DIR_CW); uln200xa.stepperSteps(4096); - + System.out.println("Sleeping for 2 seconds..."); Thread.sleep(2000); - + System.out.println("Rotating 1/2 revolution counter clockwise."); uln200xa.setDirection(upm_uln200xa.ULN200XA.ULN200XA_DIRECTION_T.DIR_CCW); uln200xa.stepperSteps(2048); - + // turn off the power uln200xa.release(); - //! [Interesting] - + // ! [Interesting] + System.out.println("Exiting..."); } diff --git a/examples/java/Ublox6Sample.java b/examples/java/Ublox6Sample.java index b605bfb7..f5f8eb2a 100644 --- a/examples/java/Ublox6Sample.java +++ b/examples/java/Ublox6Sample.java @@ -23,60 +23,60 @@ */ public class Ublox6Sample { - private static final int BUFFERLENGTH = 256; - + private static final int BUFFERLENGTH = 256; + static { try { System.loadLibrary("javaupm_ublox6"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a Ublox6 GPS device on uart 0 upm_ublox6.Ublox6 nmea = new upm_ublox6.Ublox6(0); - - // make sure port is initialized properly. 9600 baud is the default. - if(!nmea.setupTty()){ + + // make sure port is initialized properly. 9600 baud is the default. + if (!nmea.setupTty()) { throw new RuntimeException("Failed to setup tty port parameters"); - } - + } + // 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 + // 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 + // you can set with writeData(). Please refer to the Ublox-6 data // sheet for further information on the formats of the data sent and // received, and the various operating modes available. byte[] nmeaBuffer = new byte[BUFFERLENGTH]; - - while(true){ + + while (true) { // we don't want the read to block in this example, so always // check to see if data is available first. - if (nmea.dataAvailable()){ + if (nmea.dataAvailable()) { int rv = nmea.readData(nmeaBuffer); - if(rv > 0) + if (rv > 0) for (int i = 0; i < rv; i++) - System.out.print((char)nmeaBuffer[i]); - - if (rv < 0){ // some sort of read error occurred - System.err.println("Port read error.") ; + System.out.print((char) nmeaBuffer[i]); + + if (rv < 0) { // some sort of read error occurred + System.err.println("Port read error."); break; } continue; } - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } } \ No newline at end of file diff --git a/examples/java/WT5001Sample.java b/examples/java/WT5001Sample.java new file mode 100644 index 00000000..a99b6382 --- /dev/null +++ b/examples/java/WT5001Sample.java @@ -0,0 +1,121 @@ +/* + * Author: Stefan Andritoiu + * 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 WT5001Sample { + + static { + try { + System.loadLibrary("javaupm_wt5001"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + static private void printUsage() { + System.out.println("Usage: java WT5001Sample "); + System.out.println("Commands:"); + System.out.println("0 - stop playing"); + System.out.println("1 - start playing track 1"); + System.out.println("2 - pause/un-pause playback"); + System.out.println("3 - next track"); + System.out.println("4 - previous track"); + } + + public static void main(String[] args) throws InterruptedException { + // ! [Interesting] + // Instantiate a WT5001 serial MP3 player on uart 0 + upm_wt5001.WT5001 mp3 = new upm_wt5001.WT5001(0); + + int cmd = -1; + if (args.length > 0) + cmd = Integer.parseInt(args[0]); + + // make sure port is initialized properly. 9600 baud is the default + if (!mp3.setupTty()) { + System.err.println("error in loading native library"); + System.exit(-1); + } + + switch (cmd) { + case 0 : + mp3.stop(); + break; + + case 1 : + mp3.play(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD, 1); + break; + + case 2 : + mp3.pause(); + break; + + case 3 : + mp3.next(); + break; + + case 4 : + mp3.previous(); + break; + + default : + // nothing, just output usage, and info below + printUsage(); + break; + } + + // print out some information + short vol[] = new short[1]; + if (mp3.getVolume(vol)) + System.out.println("The current volume is: " + vol[0]); + + short ps[] = new short[1]; + if (mp3.getPlayState(ps)) + System.out.println("The current play state is: " + ps[0]); + + int numf[] = new int[1]; + if (mp3.getNumFiles(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD, numf)) + System.out.println("The number of files on the SD card is: " + numf[0]); + + int curf[] = new int[1]; + if (mp3.getCurrentFile(curf)) + System.out.println("The current file is: " + curf[0]); + + int year[] = new int[1]; + short month[] = new short[1]; + short day[] = new short[1]; + if (mp3.getDate(year, month, day)) + System.out.println("The device date is: " + year[0] + "/" + month[0] + "/" + day[0]); + + short hour[] = new short[1]; + short minute[] = new short[1]; + short second[] = new short[1]; + if (mp3.getTime(hour, minute, second)) + System.out + .println("The device time is: " + hour[0] + ":" + minute[0] + ":" + second[0]); + // ! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/YG1006Sample.java b/examples/java/YG1006Sample.java index 51f9cf1d..fcb8dea2 100644 --- a/examples/java/YG1006Sample.java +++ b/examples/java/YG1006Sample.java @@ -22,34 +22,33 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -public class YG1006Sample{ - +public class YG1006Sample { + static { try { System.loadLibrary("javaupm_yg1006"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [Interesting] // Instantiate a yg1006 flame sensor on digital pin D2 upm_yg1006.YG1006 flame = new upm_yg1006.YG1006(2); - + while (true) { boolean val = flame.flameDetected(); - if (val){ + if (val) { System.out.println("Flame detected"); + } else { + System.out.println("No flame detected"); } - else{ - System.out.println("No flame detected"); - } - + Thread.sleep(1000); } - //! [Interesting] + // ! [Interesting] } -} +} \ No newline at end of file diff --git a/examples/java/ZFM20Sample.java b/examples/java/ZFM20Sample.java index 7317e5cc..22e80133 100644 --- a/examples/java/ZFM20Sample.java +++ b/examples/java/ZFM20Sample.java @@ -24,76 +24,74 @@ //NOT TESTED!!! public class ZFM20Sample { - + static { try { System.loadLibrary("javaupm_zfm20"); - }catch (UnsatisfiedLinkError e) { + } catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - + public static void main(String[] args) throws InterruptedException { - //! [Interesting] + // ! [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()){ + + // 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 + + // now verify the password. If this fails, any other commands // will be ignored, so we just bail. - if(fp.verifyPassword()){ + if (fp.verifyPassword()) { System.out.println("Password verified."); - } - else{ + } 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()); + 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() ){ + 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() ){ + 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{ + } 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] + + // ! [Interesting] } } \ No newline at end of file