aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorendolf <[email protected]>2005-07-16 15:09:04 +0000
committerendolf <[email protected]>2005-07-16 15:09:04 +0000
commit93647ae6e78b257377ae4805eb7a8e5a568733da (patch)
tree501c4fe7cd1147b23221774843e0358ae58887fb
parentd85221f6061b39249b11b26744c1eac1a65a4a45 (diff)
Added cleanup stuff for rumblers, it doesn't fix the code, but is nice
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@106 e343933a-64c8-49c5-92b1-88f2ce3e89e8
-rw-r--r--coreAPI/src/java/net/java/games/input/test/RumbleTest.java4
-rw-r--r--plugins/linux/src/java/net/java/games/input/LinuxDeviceRumbler.java13
-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
11 files changed, 85 insertions, 42 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 ef61ebd..b653198 100644
--- a/coreAPI/src/java/net/java/games/input/test/RumbleTest.java
+++ b/coreAPI/src/java/net/java/games/input/test/RumbleTest.java
@@ -37,7 +37,7 @@ public class RumbleTest {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
- System.out.println("Fading rumble to -1");
+ /*System.out.println("Fading rumble to -1");
for(float k=1.0f;k>-1.0f;) {
long startTime = System.currentTimeMillis();
rumblers[j].rumble(k);
@@ -50,7 +50,7 @@ public class RumbleTest {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- }
+ }*/
System.out.println("Rumbling with intensity: " + 0.0f);
rumblers[j].rumble(0f);
try {
diff --git a/plugins/linux/src/java/net/java/games/input/LinuxDeviceRumbler.java b/plugins/linux/src/java/net/java/games/input/LinuxDeviceRumbler.java
index 5c704a9..48d0502 100644
--- a/plugins/linux/src/java/net/java/games/input/LinuxDeviceRumbler.java
+++ b/plugins/linux/src/java/net/java/games/input/LinuxDeviceRumbler.java
@@ -8,6 +8,12 @@ public class LinuxDeviceRumbler implements Rumbler {
public LinuxDeviceRumbler(int deviceID) {
this.deviceID = deviceID;
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ cleanup();
+ }
+ });
}
public void rumble(float intensity) {
@@ -25,5 +31,12 @@ public class LinuxDeviceRumbler implements Rumbler {
return null;
}
+ private void cleanup() {
+ nativeCleanup(deviceID);
+ }
+
private native void nativeRumble(int deviceID, float intensity);
+
+ private native void nativeCleanup(int deviceID);
+
}
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