Skip to content

Commit

Permalink
Implement SDL_HapticStopEffect on Android (thanks Rachel!)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 24, 2018
1 parent a794126 commit 09ab752
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Expand Up @@ -81,6 +81,14 @@ public static void hapticRun(int device_id, int length) {
mHapticHandler.run(device_id, length);
}

/**
* This method is called by SDL using JNI.
*/
public static void hapticStop(int device_id)
{
mHapticHandler.stop(device_id);
}

// Check if a given device is considered a possible SDL joystick
public static boolean isDeviceSDLJoystick(int deviceId) {
InputDevice device = InputDevice.getDevice(deviceId);
Expand Down Expand Up @@ -422,6 +430,13 @@ public void run(int device_id, int length) {
}
}

public void stop(int device_id) {
SDLHaptic haptic = getHaptic(device_id);
if (haptic != null) {
haptic.vib.cancel();
}
}

public void pollHapticDevices() {

final int deviceId_VIBRATOR_SERVICE = 999999;
Expand Down
10 changes: 9 additions & 1 deletion src/core/android/SDL_android.c
Expand Up @@ -258,6 +258,7 @@ static jclass mControllerManagerClass;
static jmethodID midPollInputDevices;
static jmethodID midPollHapticDevices;
static jmethodID midHapticRun;
static jmethodID midHapticStop;

/* static fields */
static jfieldID fidSeparateMouseAndTouch;
Expand Down Expand Up @@ -430,8 +431,10 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv* mEn
"pollHapticDevices", "()V");
midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
"hapticRun", "(II)V");
midHapticStop = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
"hapticStop", "(I)V");

if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun || !midHapticStop) {
__android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLControllerManager.java?");
}

Expand Down Expand Up @@ -1892,6 +1895,11 @@ void Android_JNI_HapticRun(int device_id, int length)
(*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticRun, device_id, length);
}

void Android_JNI_HapticStop(int device_id)
{
JNIEnv *env = Android_JNI_GetEnv();
(*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticStop, device_id);
}

/* See SDLActivity.java for constants. */
#define COMMAND_SET_KEEP_SCREEN_ON 5
Expand Down
1 change: 1 addition & 0 deletions src/core/android/SDL_android.h
Expand Up @@ -79,6 +79,7 @@ void Android_JNI_PollInputDevices(void);
/* Haptic support */
void Android_JNI_PollHapticDevices(void);
void Android_JNI_HapticRun(int device_id, int length);
void Android_JNI_HapticStop(int device_id);

/* Video */
void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
Expand Down
1 change: 1 addition & 0 deletions src/haptic/android/SDL_syshaptic.c
Expand Up @@ -238,6 +238,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
int
SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
{
Android_JNI_HapticStop (((SDL_hapticlist_item *)haptic->hwdata)->device_id);
return 0;
}

Expand Down

0 comments on commit 09ab752

Please sign in to comment.