mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
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:
parent
a81b1836a3
commit
d3e0ae5771
22
examples/java/GroveLED_ex.java
Normal file
22
examples/java/GroveLED_ex.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
24
examples/java/GroveLight_ex.java
Normal file
24
examples/java/GroveLight_ex.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
examples/java/GroveSlide_ex.java
Normal file
24
examples/java/GroveSlide_ex.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
examples/java/GroveSpeaker_ex.java
Normal file
19
examples/java/GroveSpeaker_ex.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
26
examples/java/GroveTemp_ex.java
Normal file
26
examples/java/GroveTemp_ex.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -5,4 +5,19 @@
|
|||||||
#include "grove.h"
|
#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"
|
%include "grove.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user