aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorendolf <[email protected]>2005-07-03 20:05:34 +0000
committerendolf <[email protected]>2005-07-03 20:05:34 +0000
commit0148692068637a1e39beb01728c96f7f548381d1 (patch)
tree1cb0afbe916c750a265f20c6be6b01c25828e9b8
parent41dc35be2b5b581e6cf85fa6ade392a149c09904 (diff)
Linux rumbler support
IT DOES NOT WORK YET though. I'm in contact with the kernel module developers as I think it's a kernel bug git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@104 e343933a-64c8-49c5-92b1-88f2ce3e89e8
-rw-r--r--coreAPI/src/java/net/java/games/input/test/RumbleTest.java2
-rw-r--r--plugins/linux/src/java/net/java/games/input/LinuxDevice.java25
-rw-r--r--plugins/linux/src/native/Device.h2
-rw-r--r--plugins/linux/src/native/EventDevice.cpp80
-rw-r--r--plugins/linux/src/native/EventDevice.h7
-rw-r--r--plugins/linux/src/native/JoystickDevice.cpp8
-rw-r--r--plugins/linux/src/native/JoystickDevice.h3
-rw-r--r--plugins/linux/src/native/MixedDevice.cpp8
-rw-r--r--plugins/linux/src/native/MixedDevice.h3
-rw-r--r--plugins/linux/src/native/jinput.cpp32
-rw-r--r--plugins/linux/src/native/net_java_games_input_LinuxDevice.h8
-rw-r--r--plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h20
12 files changed, 188 insertions, 10 deletions
diff --git a/coreAPI/src/java/net/java/games/input/test/RumbleTest.java b/coreAPI/src/java/net/java/games/input/test/RumbleTest.java
index 64fe204..ef61ebd 100644
--- a/coreAPI/src/java/net/java/games/input/test/RumbleTest.java
+++ b/coreAPI/src/java/net/java/games/input/test/RumbleTest.java
@@ -24,7 +24,7 @@ public class RumbleTest {
Rumbler[] rumblers = controllers[i].getRumblers();
System.out.println("Found " + rumblers.length + " rumblers");
for(int j=0;j<rumblers.length;j++) {
- System.out.println("Rumbler " + rumblers[j].getAxisName() + " on axis " + rumblers[j].getAxisIdentifier().getName());
+ System.out.println("Rumbler " + rumblers[j].getAxisName() + " on axis " + rumblers[j].getAxisIdentifier());
System.out.println("Rumbling with intensity: " + 0.5f);
rumblers[j].rumble(0.5f);
try {
diff --git a/plugins/linux/src/java/net/java/games/input/LinuxDevice.java b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java
index 6ccd4e7..228886e 100644
--- a/plugins/linux/src/java/net/java/games/input/LinuxDevice.java
+++ b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java
@@ -176,6 +176,18 @@ public class LinuxDevice extends AbstractController {
components = (Component[]) axesArray.toArray(components);
guessType();
+
+ if(getFFEnabled()) {
+ System.out.println("Java code thinks FF is enabled for device " + name);
+ Rumbler[] tempRumblers = rumblers;
+ rumblers = new Rumbler[rumblers.length+1];
+ System.arraycopy(tempRumblers,0,rumblers,0,tempRumblers.length);
+ rumblers[rumblers.length-1] = new LinuxDeviceRumbler(nativeID);
+ System.out.println("rumblers.length: " + rumblers.length);
+ System.out.println("getRumblers().length: " + getRumblers().length);
+ } else {
+ System.out.println("Java code thinks FF is disabled for device " + name);
+ }
}
/*public Axis[] getAxes(){
@@ -564,6 +576,13 @@ public class LinuxDevice extends AbstractController {
private void getSupportedRelAxes(int supportedRelAxes[]) {
getNativeSupportedRelAxes(nativeID, supportedRelAxes);
}
+
+ /** Returns the status of FF support for this device
+ *
+ */
+ private boolean getFFEnabled() {
+ return getNativeFFEnabled(nativeID);
+ }
/** Native call to get the supported absolute axes for a device
* @param deviceID The native device number
@@ -611,6 +630,12 @@ public class LinuxDevice extends AbstractController {
* @return The port type
*/
private native int getNativePortType(int deviceID);
+
+ /** Gets the status of FF support for this device
+ * @param deviceID The device to get the port type for
+ * @return The port type
+ */
+ private native boolean getNativeFFEnabled(int deviceID);
/**
* A device that represents a joystick coolie hat.
diff --git a/plugins/linux/src/native/Device.h b/plugins/linux/src/native/Device.h
index 020df30..a300408 100644
--- a/plugins/linux/src/native/Device.h
+++ b/plugins/linux/src/native/Device.h
@@ -64,6 +64,8 @@ class Device {
virtual int getAbsAxisMinimum(int axisNumber) = 0;
virtual int getAbsAxisMaximum(int axisNumber) = 0;
virtual int getAbsAxisFuzz(int axisNumber) = 0;
+ virtual bool getFFEnabled() = 0;
+ virtual void rumble(float force) = 0;
};
#endif //eventInterface_Device_h
diff --git a/plugins/linux/src/native/EventDevice.cpp b/plugins/linux/src/native/EventDevice.cpp
index 10428b1..e5430c5 100644
--- a/plugins/linux/src/native/EventDevice.cpp
+++ b/plugins/linux/src/native/EventDevice.cpp
@@ -46,7 +46,7 @@ EventDevice::EventDevice(char *deviceFileName) {
char errorMessage[512];
sprintf(errorMessage, "Error opening device %s read/write, Force Feedback disabled for this device\n", deviceFileName);
perror(errorMessage);
-
+
fd = open(deviceFileName, O_RDONLY | O_NONBLOCK);
if(fd<0) {
/*char errorMessage[512];
@@ -55,6 +55,27 @@ EventDevice::EventDevice(char *deviceFileName) {
inited = 0;
return;
}
+ } else {
+ if(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ff_bitmask)), ff_bitmask) < 0) {
+ char errorMessage[512];
+ sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
+ perror(errorMessage);
+ }
+ if(getBit(FF_RUMBLE, ff_bitmask)==1) {
+ ffSupported = 1;
+ //LOG_TRACE("Force feedback supported for %s\n", deviceFileName);
+ int n_effects = 0;
+ if (ioctl(fd, EVIOCGEFFECTS, &n_effects) == -1) {
+ char errorMessage[512];
+ sprintf(errorMessage, "Failed to get number of effects for device %s\n", deviceFileName);
+ perror(errorMessage);
+ }
+ LOG_TRACE("Device %s supports %d simultanious effects\n", deviceFileName, n_effects);
+ effect_playing = false;
+ } else {
+ ffSupported = 0;
+ LOG_TRACE("Force feedback not supported for %s %d\n", deviceFileName, getBit(FF_RUMBLE, ff_bitmask));
+ }
}
if(ioctl(fd, EVIOCGNAME(sizeof(tempName)), tempName) < 0) {
@@ -105,9 +126,7 @@ EventDevice::EventDevice(char *deviceFileName) {
numAbsAxes = 0;
}
- if(getBit(EV_FF, evtype_bitmask)) {
- ffSupported = 1;
- } else {
+ if(!getBit(EV_FF, evtype_bitmask)) {
ffSupported = 0;
}
@@ -382,3 +401,56 @@ int EventDevice::getAbsAxisMaximum(int axisNumber) {
int EventDevice::getAbsAxisFuzz(int axisNumber) {
return abs_features[axisNumber].fuzz;
}
+
+bool EventDevice::getFFEnabled() {
+ if(ffSupported==1) {
+ //LOG_TRACE("FF is supported for %s\n", getName());
+ return true;
+ }
+ //LOG_TRACE("FF is not supported for %s\n", getName());
+ return false;
+}
+
+void EventDevice::rumble(float force) {
+ if(force>1) force=1;
+ if(force<-1) force=-1;
+ LOG_TRACE("Rumbling at %d%%, (shh, pretend)\n", (int)(force*100));
+
+ if(effect_playing==true) {
+ stop.type=EV_FF;
+ stop.code = effect.id;
+ stop.value=0;
+
+ if (ioctl(fd, EVIOCRMFF, effect.id) == -1) {
+ perror("Remove effect");
+ }
+
+ }
+
+ effect.type=FF_RUMBLE;
+ effect.id=-1;
+ effect.u.rumble.strong_magnitude = (int)(0x8000*force);
+ effect.u.rumble.weak_magnitude = (int)(0xc000*force);
+ effect.replay.length = 5000;
+ effect.replay.delay = 0;
+
+ if (ioctl(fd, EVIOCSFF, &effect) == -1) {
+ perror("Upload effect");
+ }
+
+ play.type = EV_FF;
+ play.code=effect.id;
+ play.value=1;
+
+ if(effect_playing==true) {
+ if (write(fd, (const void*) &stop, sizeof(stop)) == -1) {
+ perror("Failed to stop effect");
+ }
+ }
+ if (write(fd, (const void*) &play, sizeof(play)) == -1) {
+ perror("Failed to play effect");
+ } else {
+ effect_playing=true;
+ }
+
+}
diff --git a/plugins/linux/src/native/EventDevice.h b/plugins/linux/src/native/EventDevice.h
index 58f9195..dd63269 100644
--- a/plugins/linux/src/native/EventDevice.h
+++ b/plugins/linux/src/native/EventDevice.h
@@ -56,10 +56,14 @@ class EventDevice : public Device {
uint8_t key_bitmask[KEY_MAX/8 + 1];
uint8_t rel_bitmask[REL_MAX/8 + 1];
uint8_t abs_bitmask[ABS_MAX/8 + 1];
+ uint8_t ff_bitmask[16];
struct input_absinfo *abs_features;
int absAxisLookup[ABS_MAX];
int relAxisLookup[REL_MAX];
int buttonLookup[KEY_MAX];
+ struct ff_effect effect;
+ struct input_event play, stop;
+ bool effect_playing;
public:
EventDevice(char *deviceFilename);
@@ -80,7 +84,8 @@ class EventDevice : public Device {
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
int isValidDevice();
-
+ bool getFFEnabled();
+ void rumble(float force);
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/JoystickDevice.cpp b/plugins/linux/src/native/JoystickDevice.cpp
index 8f6521f..5adab3e 100644
--- a/plugins/linux/src/native/JoystickDevice.cpp
+++ b/plugins/linux/src/native/JoystickDevice.cpp
@@ -186,3 +186,11 @@ int JoystickDevice::getAbsAxisMaximum(int axisNumber) {
int JoystickDevice::getAbsAxisFuzz(int axisNumber) {
return 0;
}
+
+bool JoystickDevice::getFFEnabled() {
+ return false;
+}
+
+void JoystickDevice::rumble(float force) {
+ return;
+}
diff --git a/plugins/linux/src/native/JoystickDevice.h b/plugins/linux/src/native/JoystickDevice.h
index 642087d..34c3de1 100644
--- a/plugins/linux/src/native/JoystickDevice.h
+++ b/plugins/linux/src/native/JoystickDevice.h
@@ -62,7 +62,8 @@ class JoystickDevice : public Device {
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
int isValidDevice();
-
+ bool getFFEnabled();
+ void rumble(float force);
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/MixedDevice.cpp b/plugins/linux/src/native/MixedDevice.cpp
index 7f402ec..b904ca5 100644
--- a/plugins/linux/src/native/MixedDevice.cpp
+++ b/plugins/linux/src/native/MixedDevice.cpp
@@ -113,3 +113,11 @@ int MixedDevice::getAbsAxisMaximum(int axisNumber) {
int MixedDevice::getAbsAxisFuzz(int axisNumber) {
return joystickDevice->getAbsAxisFuzz(axisNumber);
}
+
+bool MixedDevice::getFFEnabled() {
+ return eventDevice->getFFEnabled();
+}
+
+void MixedDevice::rumble(float force) {
+ eventDevice->rumble(force);
+}
diff --git a/plugins/linux/src/native/MixedDevice.h b/plugins/linux/src/native/MixedDevice.h
index be468d6..3d434fd 100644
--- a/plugins/linux/src/native/MixedDevice.h
+++ b/plugins/linux/src/native/MixedDevice.h
@@ -62,7 +62,8 @@ class MixedDevice : public Device {
int getAbsAxisMinimum(int axisNumber);
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
-
+ bool getFFEnabled();
+ void rumble(float force);
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/jinput.cpp b/plugins/linux/src/native/jinput.cpp
index 69f24c5..769415a 100644
--- a/plugins/linux/src/native/jinput.cpp
+++ b/plugins/linux/src/native/jinput.cpp
@@ -32,6 +32,7 @@
#include "net_java_games_input_LinuxDevice.h"
#include "net_java_games_input_LinuxEnvironmentPlugin.h"
#include "net_java_games_input_LinuxKeyboard.h"
+#include "net_java_games_input_LinuxDeviceRumbler.h"
#include "Device.h"
#include "EventDevice.h"
@@ -302,7 +303,7 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativePortType
(JNIEnv *, jobject, jint deviceID) {
LOG_TRACE("Getting bus type for device %d\n", deviceID);
- jinputDeviceList[deviceID]->getBusType();
+ return jinputDeviceList[deviceID]->getBusType();
}
/* Inaccessible static: NO_RUMBLERS */
@@ -357,5 +358,32 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxKeyboard_getNativePortType
(JNIEnv *, jobject, jint deviceID) {
LOG_TRACE("Getting bus type for keyboard device %d\n", deviceID);
- jinputDeviceList[deviceID]->getBusType();
+ return jinputDeviceList[deviceID]->getBusType();
+}
+
+/*
+ * Class: net_java_games_input_LinuxDevice
+ * Method: getFFEnabled
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxDevice_getNativeFFEnabled
+ (JNIEnv *, jobject, jint deviceID) {
+
+ LOG_TRACE("Getting FFEnabled status for device %d\n", deviceID);
+ if(jinputDeviceList[deviceID]->getFFEnabled()) {
+ //LOG_TRACE("jinput lib thinks device %d is ff enabled\n", deviceID);
+ return JNI_TRUE;
+ }
+ //LOG_TRACE("jinput lib thinks device %d is ff disabled\n", deviceID);
+ return JNI_FALSE;
+}
+
+/*
+ * Class: net_java_games_input_LinuxRumblerDevice
+ * Method: nativeRumble
+ * Signature: (IF)V
+ */
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeRumble
+ (JNIEnv *, jobject, jint deviceID, jfloat force) {
+ jinputDeviceList[deviceID]->rumble(force);
}
diff --git a/plugins/linux/src/native/net_java_games_input_LinuxDevice.h b/plugins/linux/src/native/net_java_games_input_LinuxDevice.h
index 50a4e8b..13cba3e 100644
--- a/plugins/linux/src/native/net_java_games_input_LinuxDevice.h
+++ b/plugins/linux/src/native/net_java_games_input_LinuxDevice.h
@@ -73,6 +73,14 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativeAbsAxisMin
*/
JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxDevice_getNativePortType
(JNIEnv *, jobject, jint);
+
+/*
+ * Class: net_java_games_input_LinuxDevice
+ * Method: getFFEnabled
+ * Signature: (I)Z
+ */
+JNIEXPORT jboolean JNICALL Java_net_java_games_input_LinuxDevice_getNativeFFEnabled
+ (JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
diff --git a/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h b/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h
new file mode 100644
index 0000000..90eced0
--- /dev/null
+++ b/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h
@@ -0,0 +1,20 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class net_java_games_input_LinuxDeviceRumbler */
+
+#ifndef _Included_net_java_games_input_LinuxDeviceRumbler
+#define _Included_net_java_games_input_LinuxDeviceRumbler
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: net_java_games_input_LinuxDeviceRumbler
+ * Method: nativeRumble
+ * Signature: (IF)V
+ */
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeRumble
+ (JNIEnv *, jobject, jint, jfloat);
+#ifdef __cplusplus
+}
+#endif
+#endif