| Summary: | haptic system on android? | ||
|---|---|---|---|
| Product: | SDL | Reporter: | jintiao |
| Component: | haptic | Assignee: | Sylvain <sylvain.becker> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gen2brain, ny00, philipp.wiesemann, sylvain.becker |
| Version: | 2.0.3 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
android-haptic-support.patch
android-haptic-support.patch android-haptic-support.patch patch patch |
||
|
Description
jintiao
2015-12-01 10:21:16 UTC
Created attachment 2327 [details]
android-haptic-support.patch
I try to make the haptic system works on android, here's my patch
Thank you for working on a patch against SDL 2.0.3. It looks like it is not finished yet but I still want to point out that some parts do not work on older Android devices (the planned SDL 2.0.4 currently still supports API Level 10). There either need to be version checks at runtime or the whole minimal API level needs to be raised or maybe some parts could be replaced with the vibrator service which is more available (but not connected to single devices if this matters). (In reply to Philipp Wiesemann from comment #3) > It looks like it is not finished yet but I still want to point out that some > parts do not work on older Android devices (the planned SDL 2.0.4 currently > still supports API Level 10). After 2.0.4, we should probably bump the API Level requirement, honestly. I'll revisit these patches after 2.0.4 ships and see if we can make it work for 2.0.5. --ryan. Created attachment 2444 [details]
android-haptic-support.patch
Hi,
Attached is a rebased patch that can be applied to latest hg.
It builds fine but doesn't detect haptic device. It seems minimum api version is 16, and it did crash for me on version 14.
"SDL_syshaptic.c" is missing in the new patch. Created attachment 2445 [details]
android-haptic-support.patch
Sorry, this one is with diff --new-file .
Can you guys verify that this patch works? https://hg.libsdl.org/SDL/rev/c728c661cec7 Quick test, I think there is some issue at runtime :
public static void pollHapticDevices() {...}
public static void hapticRun(){...}
( https://hg.libsdl.org/SDL/file/c728c661cec7/android-project/src/org/libsdl/app/SDLActivity.java#l1712 )
should go in the class SDLActivity {}
(same way as: https://hg.libsdl.org/SDL/file/c728c661cec7/android-project/src/org/libsdl/app/SDLActivity.java#l790 )
Sylvain, can you give me a tested patch for that? Thanks! Created attachment 2832 [details]
patch
here's a patch so that it compiles, and add forward declarations to avoid warnings.
A remark :
I tried to run haptic on my smartphone and it did not work.
Probably, it works correctly with an external joystick with haptic (but I dont have one ..).
I thought it would also register the default internal vibrator of the phone ?
I tried to add the system vibrator service, in pollHapticDevices():
{
Vibrator vib = (Vibrator) SDLActivity.mSingleton.getContext().getSystemService(Context.VIBRATOR_SERVICE);
if(vib.hasVibrator ()) {
SDLHaptic haptic = new SDLHaptic();
haptic.device_id = 999999;
haptic.name = "VIBRATOR_SERVICE";
haptic.vib = vib;
// mHaptics.add(haptic); // dont add the device to the remove list
SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
}
}
And in run() method:
public void run(int device_id, int length) {
if (device_id == 999999) {
Vibrator vib = (Vibrator) SDLActivity.mSingleton.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vib.vibrate (length);
}
Did that work? There's another patch for vibration on Android in bug 3183 Created attachment 2845 [details]
patch
patch for SDLActivity.java:
- make it compile (same as previous patch).
- add vibrator service in the list of haptic devices. I use an hard-coded device_id for it ...
- I have removed also the function OpenURL that come by mistake from another commit.
you still can pick the warning patch diff of the previous patch (only file src/core/android/SDL_android.c)
*** Bug 3747 has been marked as a duplicate of this bug. *** This is in, thanks! https://hg.libsdl.org/SDL/rev/4276937a9792 |