Private
Public Access
2
0

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>
This commit is contained in:
Petre Eftime
2015-09-30 13:21:23 +03:00
committed by Brendan Le Foll
parent 013c04c7b9
commit 0e44dfac44
5 changed files with 133 additions and 108 deletions

View 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> * Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Copyright (c) 2014 Intel Corporation. * Copyright (c) 2014 Intel Corporation.
@@ -36,23 +41,23 @@ public class BlinkOnboard {
} }
} }
public static void main(String argv[]) throws InterruptedException { public static void main(String argv[]) throws InterruptedException {
mraa.mraa_platform_t platform = mraa.mraa.getPlatformType(); Platform platform = mraa.getPlatformType();
mraa.Gpio gpio, gpio_in; Gpio gpio, gpio_in;
if (platform == mraa.mraa_platform_t.INTEL_GALILEO_GEN1) { if (platform == Platform.INTEL_GALILEO_GEN1) {
gpio = new mraa.Gpio(3); gpio = new Gpio(3);
} else if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) { } else if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
gpio = new mraa.Gpio(21); gpio = new Gpio(21);
} else { } else {
gpio = new mraa.Gpio(13); gpio = new Gpio(13);
} }
System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n", System.out.format("Welcome to libmraa\n Version: %s\n Running on %s\n",
mraa.mraa.getVersion(), platform.toString()); mraa.getVersion(), platform.toString());
gpio.dir(mraa.Dir.DIR_OUT); gpio.dir(Dir.DIR_OUT);
// on platforms with physical button use gpio_in // on platforms with physical button use gpio_in
if (platform == mraa.mraa_platform_t.INTEL_MINNOWBOARD_MAX) { if (platform == Platform.INTEL_MINNOWBOARD_MAX) {
gpio_in = new mraa.Gpio(14); gpio_in = new Gpio(14);
gpio_in.dir(mraa.Dir.DIR_IN); gpio_in.dir(Dir.DIR_IN);
System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!"); System.out.println("Press and hold S1 to stop, Press SW1 to shutdown!");
} else { } else {
gpio_in = null; gpio_in = null;

View File

@@ -24,6 +24,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import mraa.Pwm;
public class CyclePwm3 { public class CyclePwm3 {
static { static {
try { try {
@@ -36,8 +38,8 @@ public class CyclePwm3 {
} }
} }
public static void main(String argv[]) throws InterruptedException { public static void main(String argv[]) throws InterruptedException {
mraa.mraa.init(); //! [Interesting]
mraa.Pwm pwm = new mraa.Pwm(3); Pwm pwm = new mraa.Pwm(3);
pwm.period_us(200); pwm.period_us(200);
pwm.enable(true); pwm.enable(true);
@@ -50,5 +52,6 @@ public class CyclePwm3 {
value = 0; value = 0;
} }
} }
//! [Interesting]
} }
} }

View 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. * 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 * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * 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. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
//! [Interesting]
import mraa.mraa;
public class Example { public class Example {
static { static {
try { try {
@@ -34,8 +39,11 @@ public class Example {
} }
} }
public static void main(String argv[]) { public static void main(String argv[]) {
mraa.mraa.init(); String board = mraa.getPlatformName();
System.out.println(mraa.mraa.getVersion()); 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]

View File

@@ -24,6 +24,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import mraa.Dir;
import mraa.Gpio;
import mraa.mraa;
public class GpioRead6 { public class GpioRead6 {
static { static {
try { try {
@@ -35,10 +39,17 @@ public class GpioRead6 {
System.exit(1); System.exit(1);
} }
} }
public static void main(String argv[]) { public static void main(String argv[]) throws InterruptedException {
mraa.mraa.init(); System.out.println(String.format("MRAA Version: %s\nStarting Read on IO6\n", mraa.getVersion()));
mraa.Gpio gpio_in = new mraa.Gpio(6); //! [Interesting]
gpio_in.dir(mraa.Dir.DIR_IN); Gpio gpio = new Gpio(6);
System.out.format("Gpio is %d\n", gpio_in.read());
gpio.dir(Dir.DIR_IN);
while (true) {
System.out.format("Gpio is %d\n", gpio.read());
Thread.sleep(1000);
}
//! [Interesting]
} }
} }

View File

@@ -33,19 +33,17 @@ public class Isr {
System.exit(1); System.exit(1);
} }
} }
public static void main(String argv[]) { public static void main(String argv[]) throws InterruptedException {
mraa.mraa.init(); 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); gpio.isr(mraa.Edge.EDGE_RISING, callback);
while (true) Thread.sleep(0);
;
}; };
} }
;
class JavaCallback extends mraa.IsrCallback { class JavaCallback extends mraa.IsrCallback {
public JavaCallback() { super(); } public JavaCallback() { super(); }