diff options
Diffstat (limited to 'plugins/linux/src/native')
-rw-r--r-- | plugins/linux/src/native/Device.h | 2 | ||||
-rw-r--r-- | plugins/linux/src/native/EventDevice.cpp | 80 | ||||
-rw-r--r-- | plugins/linux/src/native/EventDevice.h | 7 | ||||
-rw-r--r-- | plugins/linux/src/native/JoystickDevice.cpp | 8 | ||||
-rw-r--r-- | plugins/linux/src/native/JoystickDevice.h | 3 | ||||
-rw-r--r-- | plugins/linux/src/native/MixedDevice.cpp | 8 | ||||
-rw-r--r-- | plugins/linux/src/native/MixedDevice.h | 3 | ||||
-rw-r--r-- | plugins/linux/src/native/jinput.cpp | 32 | ||||
-rw-r--r-- | plugins/linux/src/native/net_java_games_input_LinuxDevice.h | 8 | ||||
-rw-r--r-- | plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h | 20 |
10 files changed, 162 insertions, 9 deletions
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 |