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:
committed by
Brendan Le Foll
parent
013c04c7b9
commit
0e44dfac44
@@ -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);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,31 +24,34 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
import mraa.Pwm;
|
||||
|
||||
float value = 0;
|
||||
while (true) {
|
||||
value += 0.01;
|
||||
pwm.write(value);
|
||||
Thread.sleep(50);
|
||||
if (value >= 1) {
|
||||
value = 0;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()"); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user