From 2595c0b623a85476d2e4b31526e907a9f53a96c8 Mon Sep 17 00:00:00 2001 From: Stefan Andritoiu Date: Mon, 24 Aug 2015 15:06:54 +0300 Subject: [PATCH] java: added examples and solved some issues with the naming convention Signed-off-by: Stefan Andritoiu Signed-off-by: Mihai Tudor Panu --- .../java/{A110x_ex.java => A110xSample.java} | 2 +- examples/java/BISS0001Sample.java | 27 +++++++++++++ examples/java/ES08ASample.java | 38 +++++++++++++++++++ examples/java/GUVAS12DSample.java | 30 +++++++++++++++ examples/java/GroveButtonSample.java | 23 +++++++++++ .../{GroveLED_ex.java => GroveLEDSample.java} | 2 +- ...oveLight_ex.java => GroveLightSample.java} | 2 +- examples/java/GroveMoistureSample.java | 30 +++++++++++++++ examples/java/GroveRelaySample.java | 27 +++++++++++++ ...oveSlide_ex.java => GroveSlideSample.java} | 2 +- ...peaker_ex.java => GroveSpeakerSample.java} | 2 +- ...GroveTemp_ex.java => GroveTempSample.java} | 2 +- examples/java/RotaryEncoderSample.java | 23 +++++++++++ 13 files changed, 204 insertions(+), 6 deletions(-) rename examples/java/{A110x_ex.java => A110xSample.java} (94%) create mode 100644 examples/java/BISS0001Sample.java create mode 100644 examples/java/ES08ASample.java create mode 100644 examples/java/GUVAS12DSample.java create mode 100644 examples/java/GroveButtonSample.java rename examples/java/{GroveLED_ex.java => GroveLEDSample.java} (93%) rename examples/java/{GroveLight_ex.java => GroveLightSample.java} (94%) create mode 100644 examples/java/GroveMoistureSample.java create mode 100644 examples/java/GroveRelaySample.java rename examples/java/{GroveSlide_ex.java => GroveSlideSample.java} (94%) rename examples/java/{GroveSpeaker_ex.java => GroveSpeakerSample.java} (92%) rename examples/java/{GroveTemp_ex.java => GroveTempSample.java} (94%) create mode 100644 examples/java/RotaryEncoderSample.java diff --git a/examples/java/A110x_ex.java b/examples/java/A110xSample.java similarity index 94% rename from examples/java/A110x_ex.java rename to examples/java/A110xSample.java index 4f1e741d..8f4d2579 100644 --- a/examples/java/A110x_ex.java +++ b/examples/java/A110xSample.java @@ -1,4 +1,4 @@ -public class A110x_ex { +public class A110xSample { static { try { System.loadLibrary("javaupm_a110x"); diff --git a/examples/java/BISS0001Sample.java b/examples/java/BISS0001Sample.java new file mode 100644 index 00000000..a6b2fcee --- /dev/null +++ b/examples/java/BISS0001Sample.java @@ -0,0 +1,27 @@ +public class BISS0001Sample{ + + static { + try { + System.loadLibrary("javaupm_biss0001"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + upm_biss0001.BISS0001 motion = new upm_biss0001.BISS0001(7); + + while (true) { + boolean value = motion.value(); + + if(value) + System.out.println("Detecting moving object"); + else + System.out.println("No moving objects detected"); + + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/ES08ASample.java b/examples/java/ES08ASample.java new file mode 100644 index 00000000..2e27bd13 --- /dev/null +++ b/examples/java/ES08ASample.java @@ -0,0 +1,38 @@ +//import upm_servo.ES08A; + +public class ES08ASample{ + static { + try { + System.loadLibrary("javaupm_servo"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + 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"); + 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"); + Thread.sleep(1000); + + servo.setAngle (180); + System.out.println("Set angle to 180"); + } +} \ No newline at end of file diff --git a/examples/java/GUVAS12DSample.java b/examples/java/GUVAS12DSample.java new file mode 100644 index 00000000..e4d25bd1 --- /dev/null +++ b/examples/java/GUVAS12DSample.java @@ -0,0 +1,30 @@ +//import upm_guvas12d.GUVAS12D; + +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; + + + static { + try { + System.loadLibrary("javaupm_guvas12d"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + 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 ); + + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/GroveButtonSample.java b/examples/java/GroveButtonSample.java new file mode 100644 index 00000000..a3cd886a --- /dev/null +++ b/examples/java/GroveButtonSample.java @@ -0,0 +1,23 @@ +public class GroveButtonSample{ + + 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 { + // 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()); + + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/GroveLED_ex.java b/examples/java/GroveLEDSample.java similarity index 93% rename from examples/java/GroveLED_ex.java rename to examples/java/GroveLEDSample.java index bd24e8fc..278e51fa 100644 --- a/examples/java/GroveLED_ex.java +++ b/examples/java/GroveLEDSample.java @@ -1,4 +1,4 @@ -public class GroveLED_ex { +public class GroveLEDSample { static { try { System.loadLibrary("javaupm_grove"); diff --git a/examples/java/GroveLight_ex.java b/examples/java/GroveLightSample.java similarity index 94% rename from examples/java/GroveLight_ex.java rename to examples/java/GroveLightSample.java index 18e89502..9c43dfc3 100644 --- a/examples/java/GroveLight_ex.java +++ b/examples/java/GroveLightSample.java @@ -1,4 +1,4 @@ -public class GroveLight_ex { +public class GroveLightSample { static { try { System.loadLibrary("javaupm_grove"); diff --git a/examples/java/GroveMoistureSample.java b/examples/java/GroveMoistureSample.java new file mode 100644 index 00000000..d4332681 --- /dev/null +++ b/examples/java/GroveMoistureSample.java @@ -0,0 +1,30 @@ +public class GroveMoistureSample{ + static { + try { + System.loadLibrary("javaupm_grovemoisture"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main (String args[]) throws InterruptedException { + 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"; + else if ((moisture_val >= 0 && moisture_val < 300)) + result = "Moist"; + else + result = "Wet"; + + System.out.println("Moisture Value: " + moisture_val + ", " + result ); + + Thread.sleep(1000); + } + } +} diff --git a/examples/java/GroveRelaySample.java b/examples/java/GroveRelaySample.java new file mode 100644 index 00000000..1fc7ac75 --- /dev/null +++ b/examples/java/GroveRelaySample.java @@ -0,0 +1,27 @@ +public class GroveRelaySample{ + 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 { + // Create the button object using UART + upm_grove.GroveRelay relay = new upm_grove.GroveRelay(5); + + for( int i = 0 ; i < 3 ; i++ ){ + relay.on(); + if( relay.isOn() ) + System.out.println("Relay is on"); + Thread.sleep(1000); + + relay.off(); + if( relay.isOff() ) + System.out.println("Relay is off"); + Thread.sleep(1000); + } + } +} \ No newline at end of file diff --git a/examples/java/GroveSlide_ex.java b/examples/java/GroveSlideSample.java similarity index 94% rename from examples/java/GroveSlide_ex.java rename to examples/java/GroveSlideSample.java index 40f4c493..5556b4ee 100644 --- a/examples/java/GroveSlide_ex.java +++ b/examples/java/GroveSlideSample.java @@ -1,4 +1,4 @@ -public class GroveSlide_ex { +public class GroveSlideSample { static { try { System.loadLibrary("javaupm_grove"); diff --git a/examples/java/GroveSpeaker_ex.java b/examples/java/GroveSpeakerSample.java similarity index 92% rename from examples/java/GroveSpeaker_ex.java rename to examples/java/GroveSpeakerSample.java index 6db3dcfa..a1a1e01b 100644 --- a/examples/java/GroveSpeaker_ex.java +++ b/examples/java/GroveSpeakerSample.java @@ -1,4 +1,4 @@ -public class GroveSpeaker_ex { +public class GroveSpeakerSample { static { try { System.loadLibrary("javaupm_grovespeaker"); diff --git a/examples/java/GroveTemp_ex.java b/examples/java/GroveTempSample.java similarity index 94% rename from examples/java/GroveTemp_ex.java rename to examples/java/GroveTempSample.java index 56f2a35b..ec386dfe 100644 --- a/examples/java/GroveTemp_ex.java +++ b/examples/java/GroveTempSample.java @@ -1,4 +1,4 @@ -public class GroveTemp_ex { +public class GroveTempSample { static { try { System.loadLibrary("javaupm_grove"); diff --git a/examples/java/RotaryEncoderSample.java b/examples/java/RotaryEncoderSample.java new file mode 100644 index 00000000..301cae4d --- /dev/null +++ b/examples/java/RotaryEncoderSample.java @@ -0,0 +1,23 @@ +public class RotaryEncoderSample{ + + static { + try { + System.loadLibrary("javaupm_rotaryencoder"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // 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); + } + } + +} \ No newline at end of file