aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetre Eftime <petre.p.eftime@intel.com>2015-09-30 13:21:23 +0300
committerBrendan Le Foll <brendan.le.foll@intel.com>2015-10-01 14:30:51 +0100
commit0e44dfac44570c65a325bb717dc4888d6cb6cd92 (patch)
treed32f7619b6fd6017b6c0859a80fb53721fb96832
parent013c04c7b961695b367dfa9a9f66f9c1989da1cb (diff)
examples/java: Update, indent and add [Interesting] tags to examples
Signed-off-by: Petre Eftime <petre.p.eftime@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
-rw-r--r--examples/java/BlinkOnboard.java93
-rw-r--r--examples/java/CyclePwm3.java49
-rw-r--r--examples/java/Example.java16
-rw-r--r--examples/java/GpioRead6.java41
-rw-r--r--examples/java/Isr.java38
5 files changed, 131 insertions, 106 deletions
diff --git a/examples/java/BlinkOnboard.java b/examples/java/BlinkOnboard.java
index deada88..ee2bab4 100644
--- a/examples/java/BlinkOnboard.java
+++ b/examples/java/BlinkOnboard.java
@@ -1,3 +1,8 @@
+import mraa.Dir;
+import mraa.Gpio;
+import mraa.Platform;
+import mraa.mraa;
+
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2014 Intel Corporation.
@@ -25,52 +30,52 @@
*/
public class BlinkOnboard {
- static {
- try {
- System.loadLibrary("mraajava");
- } catch (UnsatisfiedLinkError e) {
- System.err.println(
- "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
- e);
- System.exit(1);
- }
- }
- public static void main(String argv[]) throws InterruptedException {
- mraa.mraa_platform_t platform = mraa.mraa.getPlatformType();
- mraa.Gpio gpio, gpio_in;
- if (platform == mraa.mraa_platform_t.INTEL_GALILEO_GEN1) {
- gpio = new mraa.Gpio(3);
- } else if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) {
- gpio = new mraa.Gpio(21);
- } else {
- gpio = new mraa.Gpio(13);
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
}
- System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n",
- mraa.mraa.getVersion(), platform.toString());
+ public static void main(String argv[]) throws InterruptedException {
+ Platform platform = mraa.getPlatformType();
+ Gpio gpio, gpio_in;
+ if (platform == Platform.INTEL_GALILEO_GEN1) {
+ gpio = new Gpio(3);
+ } else if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
+ gpio = new Gpio(21);
+ } else {
+ gpio = new Gpio(13);
+ }
+ System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n",
+ mraa.getVersion(), platform.toString());
- gpio.dir(mraa.Dir.DIR_OUT);
- // on platforms with physical button use gpio_in
- if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) {
- gpio_in = new mraa.Gpio(14);
- gpio_in.dir(mraa.Dir.DIR_IN);
- System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!");
- } else {
- gpio_in = null;
- }
+ gpio.dir(Dir.DIR_OUT);
+ // on platforms with physical button use gpio_in
+ if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
+ gpio_in = new Gpio(14);
+ gpio_in.dir(Dir.DIR_IN);
+ System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!");
+ } else {
+ gpio_in = null;
+ }
- boolean state = false;
- while (true) {
- if (gpio_in != null && gpio_in.read() == 0) {
- return;
- }
- if (state) {
- state = false;
- gpio.write(1);
- } else {
- state = true;
- gpio.write(0);
- }
- Thread.sleep(1000);
+ boolean state = false;
+ while (true) {
+ if (gpio_in != null && gpio_in.read() == 0) {
+ return;
+ }
+ if (state) {
+ state = false;
+ gpio.write(1);
+ } else {
+ state = true;
+ gpio.write(0);
+ }
+ Thread.sleep(1000);
+ }
}
- }
} \ No newline at end of file
diff --git a/examples/java/CyclePwm3.java b/examples/java/CyclePwm3.java
index 91a5871..31bb25c 100644
--- a/examples/java/CyclePwm3.java
+++ b/examples/java/CyclePwm3.java
@@ -24,31 +24,34 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+import mraa.Pwm;
+
public class CyclePwm3 {
- static {
- try {
- System.loadLibrary("mraajava");
- } catch (UnsatisfiedLinkError e) {
- System.err.println(
- "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
- e);
- System.exit(1);
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
}
- }
- public static void main(String argv[]) throws InterruptedException {
- mraa.mraa.init();
- mraa.Pwm pwm = new mraa.Pwm(3);
- pwm.period_us(200);
- pwm.enable(true);
+ public static void main(String argv[]) throws InterruptedException {
+ //! [Interesting]
+ Pwm pwm = new mraa.Pwm(3);
+ pwm.period_us(200);
+ pwm.enable(true);
- float value = 0;
- while (true) {
- value += 0.01;
- pwm.write(value);
- Thread.sleep(50);
- if (value >= 1) {
- value = 0;
- }
+ float value = 0;
+ while (true) {
+ value += 0.01;
+ pwm.write(value);
+ Thread.sleep(50);
+ if (value >= 1) {
+ value = 0;
+ }
+ }
+ //! [Interesting]
}
- }
}
diff --git a/examples/java/Example.java b/examples/java/Example.java
index 7d25da3..e311043 100644
--- a/examples/java/Example.java
+++ b/examples/java/Example.java
@@ -1,6 +1,8 @@
/*
- * Author: Alexander Komarov <alexander.komarov@intel.com>
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2014 Intel Corporation.
+ * Author: Petre Eftime <petre.p.eftime@intel.com>
+ * Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -22,6 +24,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+//! [Interesting]
+import mraa.mraa;
+
public class Example {
static {
try {
@@ -34,8 +39,11 @@ public class Example {
}
}
public static void main(String argv[]) {
- mraa.mraa.init();
- System.out.println(mraa.mraa.getVersion());
+ String board = mraa.getPlatformName();
+ String version = mraa.getVersion();
+ System.out.println("hello mraa");
+ System.out.println(String.format("Version: %s", version));
+ System.out.println(String.format("Running on %s", board));
};
}
-;
+//! [Interesting]
diff --git a/examples/java/GpioRead6.java b/examples/java/GpioRead6.java
index 77a3bcb..65854ea 100644
--- a/examples/java/GpioRead6.java
+++ b/examples/java/GpioRead6.java
@@ -24,21 +24,32 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+import mraa.Dir;
+import mraa.Gpio;
+import mraa.mraa;
+
public class GpioRead6 {
- static {
- try {
- System.loadLibrary("mraajava");
- } catch (UnsatisfiedLinkError e) {
- System.err.println(
- "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
- e);
- System.exit(1);
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
+ }
+ public static void main(String argv[]) throws InterruptedException {
+ System.out.println(String.format("MRAA Version: %s\nStarting Read on IO6\n", mraa.getVersion()));
+ //! [Interesting]
+ Gpio gpio = new Gpio(6);
+
+ gpio.dir(Dir.DIR_IN);
+
+ while (true) {
+ System.out.format("Gpio is %d\n", gpio.read());
+ Thread.sleep(1000);
+ }
+ //! [Interesting]
}
- }
- public static void main(String argv[]) {
- mraa.mraa.init();
- mraa.Gpio gpio_in = new mraa.Gpio(6);
- gpio_in.dir(mraa.Dir.DIR_IN);
- System.out.format("Gpio is %d\n", gpio_in.read());
- }
}
diff --git a/examples/java/Isr.java b/examples/java/Isr.java
index f50be90..1c29dec 100644
--- a/examples/java/Isr.java
+++ b/examples/java/Isr.java
@@ -23,32 +23,30 @@
*/
public class Isr {
- static {
- try {
- System.loadLibrary("mraajava");
- } catch (UnsatisfiedLinkError e) {
- System.err.println(
- "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
- e);
- System.exit(1);
+ static {
+ try {
+ System.loadLibrary("mraajava");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println(
+ "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
+ e);
+ System.exit(1);
+ }
}
- }
- public static void main(String argv[]) {
- mraa.mraa.init();
+ public static void main(String argv[]) throws InterruptedException {
+ mraa.mraa.init();
- mraa.Gpio gpio = new mraa.Gpio(7);
+ mraa.Gpio gpio = new mraa.Gpio(7);
- mraa.IsrCallback callback = new JavaCallback();
+ mraa.IsrCallback callback = new JavaCallback();
- gpio.isr(mraa.Edge.EDGE_RISING, callback, null);
- while (true)
- ;
- };
+ gpio.isr(mraa.Edge.EDGE_RISING, callback);
+ Thread.sleep(0);
+ };
}
-;
class JavaCallback extends mraa.IsrCallback {
- public JavaCallback() { super(); }
+ public JavaCallback() { super(); }
- public void run() { System.out.println("JavaCallback.run()"); }
+ public void run() { System.out.println("JavaCallback.run()"); }
}