Merge branch 'develop'
Conflicts: .project src/main/c/wiiusej_WiiUseApi.c src/main/java/wiiusej/WiiUseApi.java src/main/java/wiiusej/WiiUseApiManager.java src/main/java/wiiusej/Wiimote.java src/main/java/wiiusej/values/GForce.java src/main/java/wiiusej/values/IRSource.java src/main/java/wiiusej/values/Orientation.java src/main/java/wiiusej/values/RawAcceleration.java src/main/java/wiiusej/wiiusejevents/GenericEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/ClassicControllerButtonsEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/ClassicControllerEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/GuitarHeroButtonsEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/GuitarHeroEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/IREvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/MotionSensingEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java src/main/java/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java src/main/java/wiiusej/wiiusejevents/utils/EventsGatherer.java src/main/java/wiiusej/wiiusejevents/utils/WiiUseApiListener.java src/main/java/wiiusej/wiiusejevents/utils/WiimoteListener.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/ClassicControllerInsertedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/ClassicControllerRemovedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/GuitarHeroInsertedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/GuitarHeroRemovedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java src/main/java/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java
This commit is contained in:
21
.classpath
Normal file
21
.classpath
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
#include "wiiusej_WiiUseApi.h"
|
||||
@@ -339,7 +337,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout
|
||||
(JNIEnv *env, jobject obj, jint id, jshort normalTimeout, jshort expansionTimeout) {
|
||||
wiiuse_set_timeout(wiimotes, nbMaxWiimotes, normalTimeout, expansionTimeout);
|
||||
wiiuse_set_timeout(wiimotes, nbMaxWiimotes, (byte) normalTimeout, (byte) expansionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,22 +399,26 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_windowsSetBluetoothStack
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
(JNIEnv *env, jobject obj, jobject gath) {
|
||||
|
||||
/* Variables Declarations */
|
||||
int i;
|
||||
int i, a;
|
||||
short leds = 0;
|
||||
jclass cls = (*env)->GetObjectClass(env, gath);
|
||||
jmethodID mid;
|
||||
|
||||
//printf("avant poll, nbMaxwiimotes : %i \n",nbMaxWiimotes);
|
||||
if (wiiuse_poll(wiimotes, nbMaxWiimotes)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
* So go through each one and check if anything happened.
|
||||
*/
|
||||
//printf("il y a des events\n");
|
||||
for (i=0; i < nbMaxWiimotes; ++i) {
|
||||
//printf("recupe events wiimote : %i\n",nbMaxWiimotes);
|
||||
switch (wiimotes[i]->event) {
|
||||
case WIIUSE_EVENT:
|
||||
/* a generic event occured */
|
||||
|
||||
//printf("Generic event\n");
|
||||
mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
@@ -430,11 +432,11 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
* Also make sure that we see at least 1 dot.
|
||||
*/
|
||||
if (WIIUSE_USING_IR(wiimotes[i])) {
|
||||
int a;
|
||||
//printf("IR event\n");
|
||||
|
||||
WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a);
|
||||
|
||||
mid = (*env)->GetMethodID(env, cls, "prepareIRevent",
|
||||
"(IIFIIIIIISSSF)V");
|
||||
mid = (*env)->GetMethodID(env, cls, "prepareIRevent", "(IIFIIIIIISSSF)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -465,6 +467,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
|
||||
/* Motion Sensing */
|
||||
if (WIIUSE_USING_ACC(wiimotes[i])) {
|
||||
//printf("acc event\n");
|
||||
/* set orientation and gravity force */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addMotionSensingValues", "(FIZFFFFFFFFFSSS)V");
|
||||
@@ -526,7 +529,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
gh->js.max.x,gh->js.max.y,
|
||||
gh->js.min.x,gh->js.min.y,
|
||||
gh->js.center.x,gh->js.center.y);
|
||||
}if (wiimotes[i]->exp.type == EXP_CLASSIC) {
|
||||
} else if (wiimotes[i]->exp.type == EXP_CLASSIC) {
|
||||
/* put classic controller values in wiimote generic event */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V");
|
||||
@@ -550,12 +553,25 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
cl->rjs.max.x,cl->rjs.max.y,
|
||||
cl->rjs.min.x,cl->rjs.min.y,
|
||||
cl->rjs.center.x,cl->rjs.center.y);
|
||||
} else if (wiimotes[i]->exp.type == EXP_BALANCE_BOARD) {
|
||||
/* put balance board values in wiimote generic event */
|
||||
mid = (*env)->GetMethodID(env, cls,
|
||||
"addBalanceBoardEventToPreparedWiimoteEvent", "(FFFF)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
struct balance_board_t* bb = (balance_board_t*)&wiimotes[i]->exp.bb;
|
||||
(*env)->CallVoidMethod(env, gath, mid,
|
||||
/* weight */
|
||||
bb->tr,
|
||||
bb->br,
|
||||
bb->bl,
|
||||
bb->tl);
|
||||
}
|
||||
}
|
||||
|
||||
/* add generic event to java object used to gather events in c environment */
|
||||
mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
|
||||
"()V");
|
||||
mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent", "()V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -634,6 +650,24 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_BALANCE_BOARD_CTRL_INSERTED:
|
||||
/* the balance board was just connected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addBalanceBoardInsertedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_BALANCE_BOARD_CTRL_REMOVED:
|
||||
/* the balance board disconnected */
|
||||
mid = (*env)->GetMethodID(env, cls, "addBalanceBoardRemovedEvent", "(I)V");
|
||||
if (mid == 0) {
|
||||
return;
|
||||
}
|
||||
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
|
||||
break;
|
||||
|
||||
case WIIUSE_STATUS:
|
||||
/* a status event occured */
|
||||
mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V");
|
||||
@@ -660,3 +694,75 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Calibration *
|
||||
JNIEXPORT jshortArray JNICALL Java_wiiusej_WiiUseApi_getCalibration
|
||||
(JNIEnv *env, jobject obj, jint id) {
|
||||
struct wiimote_t wm = *wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id);
|
||||
jshort calibration[6] = {
|
||||
wm.accel_calib.cal_zero.x,
|
||||
wm.accel_calib.cal_zero.y,
|
||||
wm.accel_calib.cal_zero.z,
|
||||
wm.accel_calib.cal_g.x,
|
||||
wm.accel_calib.cal_g.y,
|
||||
wm.accel_calib.cal_g.z};
|
||||
jshortArray jShorts = (*env)->NewShortArray(env, 6);
|
||||
(*env)->SetShortArrayRegion(env, jShorts, 0, 6, calibration);
|
||||
return jShorts;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Speaker
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_enableSpeaker(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_enable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_disableSpeaker(JNIEnv *env, jobject obj, jint id){
|
||||
wiiuse_speaker_disable(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_muteSpeaker(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_mute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_unmuteSpeaker(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_unmute(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSpeaker(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_activate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_deactivate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat(JNIEnv *env, jobject obj, jint id, jbyte format) {
|
||||
wiiuse_speaker_format(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), format);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate(JNIEnv *env, jobject obj, jint id, jbyte rate, jbyte freq) {
|
||||
wiiuse_speaker_rate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), rate, freq);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume(JNIEnv *env, jobject obj, jint id, jdouble vol) {
|
||||
wiiuse_speaker_volume(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), vol);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig(JNIEnv *env, jobject obj, jint id) {
|
||||
wiiuse_speaker_config(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData(JNIEnv *env, jobject obj, jint id, jbyteArray jbArray) {
|
||||
jbyte *jbData = (*env)->GetByteArrayElements(env, jbArray, JNI_FALSE);
|
||||
/* Todo: Check for data loss by using signed vs unsigned bytes */
|
||||
int len = (int) (*env)->GetArrayLength(env, jbArray);
|
||||
/*byte data[len];
|
||||
int i = 0;
|
||||
for (i = 0; i < len; ++i) {
|
||||
data[i] = (byte) jbData[i];
|
||||
}*/
|
||||
wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (byte*) jbData, len);
|
||||
(*env)->ReleaseByteArrayElements(env, jbArray, jbData, JNI_FALSE);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
package wiiusej;
|
||||
|
||||
import com.github.boukefalos.jlibloader.Native;
|
||||
|
||||
import wiiusej.wiiusejevents.utils.EventsGatherer;
|
||||
|
||||
/**
|
||||
@@ -28,8 +26,7 @@ import wiiusej.wiiusejevents.utils.EventsGatherer;
|
||||
public class WiiUseApi {
|
||||
|
||||
static {
|
||||
Native.load("com.github.boukefalos", "libwiiuse");
|
||||
Native.load("com.github.boukefalos", "jlibwiiuse");
|
||||
System.loadLibrary("WiiuseJ");
|
||||
}
|
||||
|
||||
private static WiiUseApi instance = new WiiUseApi();
|
||||
@@ -351,4 +348,19 @@ public class WiiUseApi {
|
||||
*/
|
||||
native void specialPoll(EventsGatherer gath);
|
||||
|
||||
|
||||
/**
|
||||
* Speaker
|
||||
*/
|
||||
native void enableSpeaker(int id);
|
||||
native void disableSpeaker(int id);
|
||||
native void muteSpeaker(int id);
|
||||
native void unmuteSpeaker(int id);
|
||||
native void activateSpeaker(int id);
|
||||
native void deactivateSpeaker(int id);
|
||||
native void setSpeakerFormat(int id, byte format);
|
||||
native void setSpeakerRate(int id, byte rate, byte freq);
|
||||
native void setSpeakerVolume(int id, double volume);
|
||||
native void setSpeakerConfig(int id);
|
||||
native void streamSpeakerData(int id, byte[] block);
|
||||
}
|
||||
|
||||
@@ -661,4 +661,51 @@ public class WiiUseApiManager extends Thread {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Speaker
|
||||
*/
|
||||
public void enableSpeaker(int id) {
|
||||
wiiuse.enableSpeaker(id);
|
||||
}
|
||||
|
||||
public void disableSpeaker(int id) {
|
||||
wiiuse.disableSpeaker(id);
|
||||
}
|
||||
|
||||
public void muteSpeaker(int id) {
|
||||
wiiuse.muteSpeaker(id);
|
||||
}
|
||||
|
||||
public void unmuteSpeaker(int id) {
|
||||
wiiuse.unmuteSpeaker(id);
|
||||
}
|
||||
|
||||
public void activateSpeaker(int id) {
|
||||
wiiuse.activateSpeaker(id);
|
||||
}
|
||||
|
||||
public void deactivateSpeaker(int id) {
|
||||
wiiuse.deactivateSpeaker(id);
|
||||
}
|
||||
|
||||
public void setSpeakerFormat(int id, byte format) {
|
||||
wiiuse.setSpeakerFormat(id, format);
|
||||
}
|
||||
|
||||
public void setSpeakerRate(int id, byte rate, byte freq) {
|
||||
wiiuse.setSpeakerRate(id, rate, freq);
|
||||
}
|
||||
|
||||
public void setSpeakerVolume(int id, double volume) {
|
||||
wiiuse.setSpeakerVolume(id, volume);
|
||||
}
|
||||
|
||||
public void setSpeakerConfig(int id) {
|
||||
wiiuse.setSpeakerConfig(id);
|
||||
}
|
||||
|
||||
public void streamSpeakerData(int id, byte[] block) {
|
||||
wiiuse.streamSpeakerData(id, block);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import javax.swing.event.EventListenerList;
|
||||
|
||||
import wiiusej.wiiusejevents.utils.WiiUseApiListener;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
@@ -327,6 +329,10 @@ public class Wiimote implements WiiUseApiListener {
|
||||
notifyClassicControllerInsertedEventListeners((ClassicControllerInsertedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED) {
|
||||
notifyClassicControllerRemovedEventListeners((ClassicControllerRemovedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_BALANCE_BOARD_CTRL_INSERTED) {
|
||||
notifyBalanceBoardInsertedEventListeners((BalanceBoardInsertedEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_BALANCE_BOARD_CTRL_REMOVED) {
|
||||
notifyBalanceBoardRemovedEventListeners((BalanceBoardRemovedEvent) e);
|
||||
}
|
||||
/*
|
||||
* events not managed yet || e.getEventType() == WIIUSE_READ_DATA
|
||||
@@ -487,9 +493,77 @@ public class Wiimote implements WiiUseApiListener {
|
||||
}
|
||||
}
|
||||
|
||||
protected void notifyBalanceBoardInsertedEventListeners(BalanceBoardInsertedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onBalanceBoardInsertedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notifyBalanceBoardRemovedEventListeners(BalanceBoardRemovedEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onBalanceBoardRemovedEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wiimote with ID : " + id;
|
||||
}
|
||||
|
||||
public void rumble(int milliseconds) {
|
||||
activateRumble();
|
||||
try {
|
||||
Thread.sleep(milliseconds);
|
||||
} catch (InterruptedException e) {
|
||||
} finally {
|
||||
deactivateRumble();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Speaker
|
||||
*/
|
||||
public void enableSpeaker() {
|
||||
manager.enableSpeaker(id);
|
||||
}
|
||||
|
||||
public void disableSpeaker() {
|
||||
manager.disableSpeaker(id);
|
||||
}
|
||||
|
||||
public void muteSpeaker() {
|
||||
manager.muteSpeaker(id);
|
||||
}
|
||||
|
||||
public void unmuteSpeaker() {
|
||||
manager.unmuteSpeaker(id);
|
||||
}
|
||||
|
||||
public void activateSpeaker() {
|
||||
manager.activateSpeaker(id);
|
||||
}
|
||||
|
||||
public void deactivateSpeaker() {
|
||||
manager.deactivateSpeaker(id);
|
||||
}
|
||||
|
||||
public void setSpeakerFormat(byte format) {
|
||||
manager.setSpeakerFormat(id, format);
|
||||
}
|
||||
|
||||
public void setSpeakerRate(byte rate, byte freq) {
|
||||
manager.setSpeakerRate(id, rate, freq);
|
||||
}
|
||||
|
||||
public void setSpeakerVolume(double volume) {
|
||||
manager.setSpeakerVolume(id, volume);
|
||||
}
|
||||
|
||||
public void setSpeakerConfig() {
|
||||
manager.setSpeakerConfig(id);
|
||||
}
|
||||
|
||||
public void streamSpeakerData(byte[] block) {
|
||||
manager.streamSpeakerData(id, block);
|
||||
}
|
||||
}
|
||||
|
||||
33
src/main/java/wiiusej/values/Acceleration.java
Normal file
33
src/main/java/wiiusej/values/Acceleration.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package wiiusej.values;
|
||||
|
||||
public class Acceleration {
|
||||
protected double x;
|
||||
protected double y;
|
||||
protected double z;
|
||||
|
||||
public Acceleration(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public double[] toArray() {
|
||||
return new double[] {getX(), getY(), getZ()};
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Acceleration : (" + x + ", " + y + ", " + z + ")";
|
||||
}
|
||||
}
|
||||
31
src/main/java/wiiusej/values/Calibration.java
Normal file
31
src/main/java/wiiusej/values/Calibration.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package wiiusej.values;
|
||||
|
||||
public class Calibration {
|
||||
protected RawAcceleration zeroAcceleration;
|
||||
protected RawAcceleration gAcceleration;
|
||||
protected RawAcceleration differenceAcceleration;
|
||||
|
||||
public Calibration(RawAcceleration zeroAcceleration, RawAcceleration gAcceleration) {
|
||||
this.zeroAcceleration = zeroAcceleration;
|
||||
this.gAcceleration = gAcceleration;
|
||||
differenceAcceleration = new RawAcceleration(
|
||||
(short) (gAcceleration.getX() - zeroAcceleration.getX()),
|
||||
(short) (gAcceleration.getY() - zeroAcceleration.getY()),
|
||||
(short) (gAcceleration.getZ() - zeroAcceleration.getZ()));
|
||||
}
|
||||
|
||||
public RawAcceleration getZeroAcceleration() {
|
||||
return zeroAcceleration;
|
||||
}
|
||||
|
||||
public RawAcceleration getGAcceleration() {
|
||||
return gAcceleration;
|
||||
}
|
||||
|
||||
public Acceleration getAcceleration(RawAcceleration rawAcceleration) {
|
||||
return new Acceleration(
|
||||
(rawAcceleration.getX() - zeroAcceleration.getX()) / (double) differenceAcceleration.getX(),
|
||||
(rawAcceleration.getY() - zeroAcceleration.getY()) / (double) differenceAcceleration.getY(),
|
||||
(rawAcceleration.getZ() - zeroAcceleration.getZ()) / (double) differenceAcceleration.getZ());
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents gravity force on each axis.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForce {
|
||||
public class GForce implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class that represents the orientation of the wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class Orientation {
|
||||
public class Orientation implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private float roll;
|
||||
private float pitch;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents raw acceleration on each axis.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class RawAcceleration {
|
||||
public class RawAcceleration implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private short x;
|
||||
private short y;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.wiiusejevents;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Abstract mother class representing an event with a wiimote id.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class GenericEvent {
|
||||
public abstract class GenericEvent implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package wiiusej.wiiusejevents.physicalevents;
|
||||
|
||||
public class BalanceBoardButtonsEvent extends ButtonsEvent {
|
||||
protected static short BALANCE_BOARD_BUTTON = 0x0001;
|
||||
|
||||
public BalanceBoardButtonsEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package wiiusej.wiiusejevents.physicalevents;
|
||||
|
||||
public class BalanceBoardEvent extends ExpansionEvent {
|
||||
protected JoystickEvent balanceBoardJoystickEvent;
|
||||
|
||||
public BalanceBoardEvent(int id, float topRight, float bottomRight,
|
||||
float bottomLeft, float topLeft) {
|
||||
super(id);
|
||||
System.out.println(String.format("%f %f %f %f", topRight, bottomRight, bottomLeft, topLeft));
|
||||
/*balanceBoardJoystickEvent = new JoystickEvent(id, angle,
|
||||
magnitude, max1, max2, min1, min2, center1, center2);*/
|
||||
}
|
||||
|
||||
public boolean isThereBalanceBoardJoystickEvent() {
|
||||
return balanceBoardJoystickEvent != null;
|
||||
}
|
||||
|
||||
public JoystickEvent getBalanceBoardJoystickEvent() {
|
||||
return balanceBoardJoystickEvent;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** Balance Board EVENT : WIIMOTE ID :" + getWiimoteId()
|
||||
+ " ********/\n";
|
||||
out += balanceBoardJoystickEvent;
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import wiiusej.wiiusejevents.GenericEvent;
|
||||
* @author guiguito
|
||||
*/
|
||||
public class MotionSensingEvent extends GenericEvent {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
/* Motion Sensing */
|
||||
private Orientation orientation;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package wiiusej.wiiusejevents.utils;
|
||||
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
@@ -362,6 +364,14 @@ public class EventsGatherer {
|
||||
}
|
||||
}
|
||||
|
||||
public void addBalanceBoardEventToPreparedWiimoteEvent(float topRight,
|
||||
float bottomRight, float bottomLeft, float topLeft) {
|
||||
if (genericEvent != null) {
|
||||
genericEvent.setBalanceBoardEvent(topRight, bottomRight,
|
||||
bottomLeft, topLeft);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the prepared WiimoteEvent to the gatherer.
|
||||
*/
|
||||
@@ -484,6 +494,16 @@ public class EventsGatherer {
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
public void addBalanceBoardInsertedEvent(int id) {
|
||||
BalanceBoardInsertedEvent evt = new BalanceBoardInsertedEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
public void addBalanceBoardRemovedEvent(int id) {
|
||||
BalanceBoardRemovedEvent evt = new BalanceBoardRemovedEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the events.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,8 @@ import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
@@ -142,4 +144,6 @@ public interface WiimoteListener extends java.util.EventListener {
|
||||
*/
|
||||
void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent e);
|
||||
|
||||
void onBalanceBoardInsertedEvent(BalanceBoardInsertedEvent e);
|
||||
void onBalanceBoardRemovedEvent(BalanceBoardRemovedEvent e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package wiiusej.wiiusejevents.wiiuseapievents;
|
||||
|
||||
public class BalanceBoardInsertedEvent extends WiiUseApiEvent {
|
||||
public BalanceBoardInsertedEvent(int id) {
|
||||
super(id, WIIUSE_BALANCE_BOARD_CTRL_INSERTED);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** BALANCE BOARD INSERTED EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package wiiusej.wiiusejevents.wiiuseapievents;
|
||||
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
|
||||
|
||||
public class BalanceBoardRemovedEvent extends WiiUseApiEvent {
|
||||
public BalanceBoardRemovedEvent(int id) {
|
||||
super(id, WIIUSE_BALANCE_BOARD_CTRL_REMOVED);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** BALANCE BOARD INSERTED EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import wiiusej.wiiusejevents.GenericEvent;
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class WiiUseApiEvent extends GenericEvent{
|
||||
|
||||
public static int NONE_EVENT = 0;
|
||||
public static int GENERIC_EVENT = 1;
|
||||
public static int STATUS_EVENT = 2;
|
||||
@@ -36,6 +35,8 @@ public abstract class WiiUseApiEvent extends GenericEvent{
|
||||
public static int WIIUSE_CLASSIC_CTRL_REMOVED = 8;
|
||||
public static int WIIUSE_GUITAR_HERO_3_CTRL_INSERTED = 9;
|
||||
public static int WIIUSE_GUITAR_HERO_3_CTRL_REMOVED = 10;
|
||||
public static int WIIUSE_BALANCE_BOARD_CTRL_INSERTED = 11;
|
||||
public static int WIIUSE_BALANCE_BOARD_CTRL_REMOVED = 12;
|
||||
|
||||
/* Event Type */
|
||||
private int eventType;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package wiiusej.wiiusejevents.wiiuseapievents;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.BalanceBoardEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
|
||||
@@ -405,6 +406,12 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
center2);
|
||||
}
|
||||
|
||||
public void setBalanceBoardEvent(float topRight, float bottomRight,
|
||||
float bottomLeft, float topLeft) {
|
||||
expansionEvent = new BalanceBoardEvent(getWiimoteId(), topRight,
|
||||
bottomRight, bottomLeft, topLeft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
@@ -437,5 +444,4 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user