From 0148692068637a1e39beb01728c96f7f548381d1 Mon Sep 17 00:00:00 2001 From: endolf Date: Sun, 3 Jul 2005 20:05:34 +0000 Subject: 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 --- .../java/net/java/games/input/test/RumbleTest.java | 2 +- .../src/java/net/java/games/input/LinuxDevice.java | 25 +++++++ plugins/linux/src/native/Device.h | 2 + plugins/linux/src/native/EventDevice.cpp | 80 ++++++++++++++++++++-- plugins/linux/src/native/EventDevice.h | 7 +- plugins/linux/src/native/JoystickDevice.cpp | 8 +++ plugins/linux/src/native/JoystickDevice.h | 3 +- plugins/linux/src/native/MixedDevice.cpp | 8 +++ plugins/linux/src/native/MixedDevice.h | 3 +- plugins/linux/src/native/jinput.cpp | 32 ++++++++- .../src/native/net_java_games_input_LinuxDevice.h | 8 +++ .../net_java_games_input_LinuxDeviceRumbler.h | 20 ++++++ 12 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h 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;j1) 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 +/* 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 -- cgit v1.2.3