aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/linux/src/native
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/linux/src/native')
-rw-r--r--plugins/linux/src/native/Device.h1
-rw-r--r--plugins/linux/src/native/EventDevice.cpp79
-rw-r--r--plugins/linux/src/native/EventDevice.h1
-rw-r--r--plugins/linux/src/native/JoystickDevice.cpp4
-rw-r--r--plugins/linux/src/native/JoystickDevice.h1
-rw-r--r--plugins/linux/src/native/MixedDevice.cpp5
-rw-r--r--plugins/linux/src/native/MixedDevice.h1
-rw-r--r--plugins/linux/src/native/jinput.cpp10
-rw-r--r--plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h8
9 files changed, 70 insertions, 40 deletions
diff --git a/plugins/linux/src/native/Device.h b/plugins/linux/src/native/Device.h
index a300408..61fe621 100644
--- a/plugins/linux/src/native/Device.h
+++ b/plugins/linux/src/native/Device.h
@@ -66,6 +66,7 @@ class Device {
virtual int getAbsAxisFuzz(int axisNumber) = 0;
virtual bool getFFEnabled() = 0;
virtual void rumble(float force) = 0;
+ virtual void cleanup() = 0;
};
#endif //eventInterface_Device_h
diff --git a/plugins/linux/src/native/EventDevice.cpp b/plugins/linux/src/native/EventDevice.cpp
index ff2a1d9..a0b0888 100644
--- a/plugins/linux/src/native/EventDevice.cpp
+++ b/plugins/linux/src/native/EventDevice.cpp
@@ -27,10 +27,10 @@
#include "eventInterfaceTypes.h"
#include "EventDevice.h"
#include <stdio.h>
-#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <linux/input.h>
#include <malloc.h>
#include <errno.h>
@@ -56,7 +56,7 @@ EventDevice::EventDevice(char *deviceFileName) {
return;
}
} else {
- if(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(ff_bitmask)), ff_bitmask) < 0) {
+ if(ioctl(fd, EVIOCGBIT(EV_FF, sizeof(uint8_t) * 16), ff_bitmask) < 0) {
char errorMessage[512];
sprintf(errorMessage, "Error reading device %s\n", deviceFileName);
perror(errorMessage);
@@ -71,7 +71,20 @@ EventDevice::EventDevice(char *deviceFileName) {
perror(errorMessage);
}
LOG_TRACE("Device %s supports %d simultanious effects\n", deviceFileName, n_effects);
+
effect_playing = false;
+ effect.type=FF_RUMBLE;
+ effect.id=-1;
+ effect.u.rumble.strong_magnitude = (int)(0x8000);
+ effect.u.rumble.weak_magnitude = (int)(0xc000);
+ effect.replay.length = 5000;
+ effect.replay.delay = 0;
+ LOG_TRACE("Uploading effect %d\n", effect.id);
+ if (ioctl(fd, EVIOCSFF, &effect) == -1) {
+ perror("Upload effect");
+ }
+
+
} else {
ffSupported = 0;
LOG_TRACE("Force feedback not supported for %s %d\n", deviceFileName, getBit(FF_RUMBLE, ff_bitmask));
@@ -416,48 +429,34 @@ void EventDevice::rumble(float force) {
if(force<-1) force=-1;
//LOG_TRACE("Rumbling at %d%%, (shh, pretend)\n", (int)(force*100));
- if(effect_playing==true) {
+ if(effect_playing==true && force==0) {
stop.type=EV_FF;
stop.code = effect.id;
stop.value=0;
-
- LOG_TRACE("Removing effect %d\n", effect.id);
- if (ioctl(fd, EVIOCRMFF, &effect) == -1) {
- perror("Remove effect");
- }
-
- } else {
- effect.id=-1;
- }
-
- 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 = 15000;
- effect.replay.delay = 0;
-
- if(effect_playing==true) {
- LOG_TRACE("Stoping %d\n", stop.code);
- if (write(fd, (const void*) &stop, sizeof(stop)) == -1) {
+ LOG_TRACE("Stopping effect %d\n", stop.code);
+ if (write(fd, (const void*) &stop, sizeof(stop)) == -1) {
perror("Failed to stop effect");
+ } else {
+ effect_playing=false;
}
- effect_playing=false;
}
- LOG_TRACE("Uploading effect %d\n", effect.id);
- if (ioctl(fd, EVIOCSFF, &effect) == -1) {
- perror("Upload effect");
- }
-
- play.type = EV_FF;
- play.code=effect.id;
- play.value=1;
-
- LOG_TRACE("Playing effect %d\n", play.code);
- if (write(fd, (const void*) &play, sizeof(play)) == -1) {
- perror("Failed to play effect");
- } else {
- effect_playing=true;
- }
-
+ if(effect_playing==false && force!=0) {
+ play.type = EV_FF;
+ play.code=effect.id;
+ play.value=1;
+
+ LOG_TRACE("Playing effect %d\n", play.code);
+ if (write(fd, (const void*) &play, sizeof(play)) == -1) {
+ perror("Failed to play effect");
+ } else {
+ effect_playing=true;
+ }
+ }
+}
+
+void EventDevice::cleanup() {
+ char message[512];
+ sprintf(message, "Closing device %s\n", name);
+ LOG_TRACE(message);
+ close(fd);
}
diff --git a/plugins/linux/src/native/EventDevice.h b/plugins/linux/src/native/EventDevice.h
index dd63269..1a79493 100644
--- a/plugins/linux/src/native/EventDevice.h
+++ b/plugins/linux/src/native/EventDevice.h
@@ -86,6 +86,7 @@ class EventDevice : public Device {
int isValidDevice();
bool getFFEnabled();
void rumble(float force);
+ void cleanup();
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/JoystickDevice.cpp b/plugins/linux/src/native/JoystickDevice.cpp
index 5adab3e..59d69eb 100644
--- a/plugins/linux/src/native/JoystickDevice.cpp
+++ b/plugins/linux/src/native/JoystickDevice.cpp
@@ -194,3 +194,7 @@ bool JoystickDevice::getFFEnabled() {
void JoystickDevice::rumble(float force) {
return;
}
+
+void JoystickDevice::cleanup() {
+ close(fd);
+}
diff --git a/plugins/linux/src/native/JoystickDevice.h b/plugins/linux/src/native/JoystickDevice.h
index 34c3de1..87afa4d 100644
--- a/plugins/linux/src/native/JoystickDevice.h
+++ b/plugins/linux/src/native/JoystickDevice.h
@@ -64,6 +64,7 @@ class JoystickDevice : public Device {
int isValidDevice();
bool getFFEnabled();
void rumble(float force);
+ void cleanup();
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/MixedDevice.cpp b/plugins/linux/src/native/MixedDevice.cpp
index b904ca5..bb113ea 100644
--- a/plugins/linux/src/native/MixedDevice.cpp
+++ b/plugins/linux/src/native/MixedDevice.cpp
@@ -121,3 +121,8 @@ bool MixedDevice::getFFEnabled() {
void MixedDevice::rumble(float force) {
eventDevice->rumble(force);
}
+
+void MixedDevice::cleanup() {
+ joystickDevice->cleanup();
+ eventDevice->cleanup();
+}
diff --git a/plugins/linux/src/native/MixedDevice.h b/plugins/linux/src/native/MixedDevice.h
index 3d434fd..3239ed4 100644
--- a/plugins/linux/src/native/MixedDevice.h
+++ b/plugins/linux/src/native/MixedDevice.h
@@ -64,6 +64,7 @@ class MixedDevice : public Device {
int getAbsAxisFuzz(int axisNumber);
bool getFFEnabled();
void rumble(float force);
+ void cleanup();
};
#endif //eventInterface_eventDevice_h
diff --git a/plugins/linux/src/native/jinput.cpp b/plugins/linux/src/native/jinput.cpp
index 769415a..2b8128f 100644
--- a/plugins/linux/src/native/jinput.cpp
+++ b/plugins/linux/src/native/jinput.cpp
@@ -387,3 +387,13 @@ JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeRumble
(JNIEnv *, jobject, jint deviceID, jfloat force) {
jinputDeviceList[deviceID]->rumble(force);
}
+
+/*
+ * Class: net_java_games_input_LinuxRumblerDevice
+ * Method: nativeCleanup
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeCleanup
+ (JNIEnv *, jobject, jint deviceID) {
+ jinputDeviceList[deviceID]->cleanup();
+}
diff --git a/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h b/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h
index 90eced0..085f22d 100644
--- a/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h
+++ b/plugins/linux/src/native/net_java_games_input_LinuxDeviceRumbler.h
@@ -14,6 +14,14 @@ extern "C" {
*/
JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeRumble
(JNIEnv *, jobject, jint, jfloat);
+
+/*
+ * Class: net_java_games_input_LinuxDeviceRumbler
+ * Method: nativeCleanup
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_net_java_games_input_LinuxDeviceRumbler_nativeCleanup
+ (JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif