java: fixed grove API and added some examples

Signed-off-by: Andrei Vasiliu <andrei.vasiliu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Andrei Vasiliu 2015-08-12 16:44:30 +03:00 committed by Mihai Tudor Panu
parent a81b1836a3
commit d3e0ae5771
6 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,22 @@
public class GroveLED_ex {
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 {
upm_grove.GroveLed led = new upm_grove.GroveLed(2);
for (int i = 0; i < 10; ++i) {
led.on();
Thread.sleep(1000);
led.off();
Thread.sleep(1000);
}
led.delete();
}
}

View File

@ -0,0 +1,24 @@
public class GroveLight_ex {
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 {
upm_grove.GroveLight gl = new upm_grove.GroveLight(2);
while (true) {
float raw_value = gl.raw_value();
float value = gl.value();
System.out.println("raw value: " + raw_value);
System.out.println("value: " + value);
Thread.sleep(1000);
}
}
}

View File

@ -0,0 +1,24 @@
public class GroveSlide_ex {
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 {
upm_grove.GroveSlide slide = new upm_grove.GroveSlide(0);
while (true) {
float raw_value = slide.raw_value();
float value = slide.voltage_value();
System.out.println("raw value: " + raw_value);
System.out.println("value: " + value);
Thread.sleep(2500);
}
}
}

View File

@ -0,0 +1,19 @@
public class GroveSpeaker_ex {
static {
try {
System.loadLibrary("javaupm_grovespeaker");
} catch (UnsatisfiedLinkError e) {
System.err.println("error in loading native library");
System.exit(-1);
}
}
public static void main (String args[]) throws InterruptedException {
upm_grovespeaker.GroveSpeaker speaker = new upm_grovespeaker.GroveSpeaker(3);
speaker.playAll();
speaker.playSound('c', true, "med");
temp.delete();
}
}

View File

@ -0,0 +1,26 @@
public class GroveTemp_ex {
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 {
upm_grove.GroveTemp temp = new upm_grove.GroveTemp(3);
for (int i = 0; i < 10; ++i) {
int celsius = temp.value();
int fahrneheit = celsius * 2 + 32;
System.out.println("Celsius: " + celsius);
System.out.println("Fahrneheit: " + fahrneheit);
Thread.sleep(1000);
}
temp.delete();
}
}

View File

@ -5,4 +5,19 @@
#include "grove.h"
%}
%typemap(jni) mraa_result_t "jint"
%typemap(jstype) mraa_result_t "int"
%typemap(jtype) mraa_result_t "int"
%typemap(javaout) mraa_result_t {
return $jnicall;
}
%typemap(out) mraa_result_t {
$result = (int)$1;
}
%include "grove.h"