mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-01-04 07:49:57 +01:00
Added cleanup stuff for rumblers, it doesn't fix the code, but is nice
This commit is contained in:
parent
d4c72ba15c
commit
04e3538e83
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EventDevice::cleanup() {
|
||||
char message[512];
|
||||
sprintf(message, "Closing device %s\n", name);
|
||||
LOG_TRACE(message);
|
||||
close(fd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class EventDevice : public Device {
|
|||
int isValidDevice();
|
||||
bool getFFEnabled();
|
||||
void rumble(float force);
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
#endif //eventInterface_eventDevice_h
|
||||
|
|
|
|||
|
|
@ -194,3 +194,7 @@ bool JoystickDevice::getFFEnabled() {
|
|||
void JoystickDevice::rumble(float force) {
|
||||
return;
|
||||
}
|
||||
|
||||
void JoystickDevice::cleanup() {
|
||||
close(fd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ class JoystickDevice : public Device {
|
|||
int isValidDevice();
|
||||
bool getFFEnabled();
|
||||
void rumble(float force);
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
#endif //eventInterface_eventDevice_h
|
||||
|
|
|
|||
|
|
@ -121,3 +121,8 @@ bool MixedDevice::getFFEnabled() {
|
|||
void MixedDevice::rumble(float force) {
|
||||
eventDevice->rumble(force);
|
||||
}
|
||||
|
||||
void MixedDevice::cleanup() {
|
||||
joystickDevice->cleanup();
|
||||
eventDevice->cleanup();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ class MixedDevice : public Device {
|
|||
int getAbsAxisFuzz(int axisNumber);
|
||||
bool getFFEnabled();
|
||||
void rumble(float force);
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
#endif //eventInterface_eventDevice_h
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue