examples/java: Update, indent and add [Interesting] tags to examples
authorPetre Eftime <petre.p.eftime@intel.com>
Wed, 30 Sep 2015 10:21:23 +0000 (13:21 +0300)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Thu, 1 Oct 2015 13:30:51 +0000 (14:30 +0100)
Signed-off-by: Petre Eftime <petre.p.eftime@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
examples/java/BlinkOnboard.java
examples/java/CyclePwm3.java
examples/java/Example.java
examples/java/GpioRead6.java
examples/java/Isr.java

index deada88..ee2bab4 100644 (file)
@@ -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.
  */
 
 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
index 91a5871..31bb25c 100644 (file)
  * 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]
     }
-  }
 }
index 7d25da3..e311043 100644 (file)
@@ -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]
index 77a3bcb..65854ea 100644 (file)
  * 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());
-  }
 }
index f50be90..1c29dec 100644 (file)
  */
 
 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()"); }
 }