Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Haptic on Android - al_install_haptic() returns 0.

This thread is locked; no one can reply to it. rss feed Print
Haptic on Android - al_install_haptic() returns 0.
Ian Lewis
Member #15,817
December 2014

Hello All,

I'm trying to add haptic effects to my Android game.

al_install_haptic() always returns zero, and so I can't go any further :-(

I have already (successfully) called al_create_display(), and I have added <uses-permission android:name="android.permission.VIBRATE" /> to my manifest.

Have I missed anything?

Anyone have any ideas what might be causing this?

Follow up questions:
Should I expect the display, or the touch input to be haptic capable? (i.e. should I be using al_get_haptic_from_display() or al_get_haptic_from_touch_input()? )

I know I can check with al_is_display_haptic() & al_is_touch_input_haptic(), but all the touch input functions need a parameter of type ALLEGRO_TOUCH_INPUT, and I can't see where I get that from..... Any clues?

Cheers

Ian.

beoran
Member #12,636
March 2011

I wrote most of the haptics a few years ago, but it is still somewhat half baked and untested on Android and IOS. This is due to a lack of actual users of the API , so your feedback is appreciated.

On mobile platforms, the display should be haptic capable, other inputs are likely not so.

It is possible that you have hit a bug. Could you post some example code that exhibits the problem, then I will look into it.

Ian Lewis
Member #15,817
December 2014

Thanks beoran.

Here's a stripped-down section of the start of my code which seems to show the problem.

#SelectExpand
1#include <stdio.h> 2#include <stdlib.h> 3#include <math.h> 4 5#define ALLEGRO_UNSTABLE 1 //needed for haptics. 6 7#include "allegro5/allegro.h" 8#include "allegro5/allegro_image.h" 9#include "allegro5/allegro_primitives.h" 10#include "allegro5/allegro_font.h" 11#include "allegro5/allegro_ttf.h" 12#include "allegro5/allegro_audio.h" 13#include "allegro5/allegro_acodec.h" 14#include <allegro5/allegro_android.h> 15 16 17ALLEGRO_DISPLAY *display; 18ALLEGRO_HAPTIC *hap; 19ALLEGRO_HAPTIC_EFFECT_ID *hapID; 20 21int game(int argc, char **argv ) 22{ 23 /* Init Allegro 5 + addons. */ 24 al_init(); 25 26 //init other bits of allegro 27 al_init_image_addon(); 28 al_init_primitives_addon(); 29 al_init_font_addon(); 30 al_init_ttf_addon(); 31 al_install_mouse(); 32 al_install_keyboard(); 33 al_install_audio(); 34 al_init_acodec_addon(); 35 al_android_set_apk_fs_interface(); 36 37 al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS,ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE,ALLEGRO_REQUIRE); 38 39 display = al_create_display(960, 540); //Moto E resolution 40 41 ALLEGRO_TOUCH_INPUT *touch; 42 int temp = al_install_haptic(); //returns 0 43 if (al_is_haptic_installed()) 44 { 45 if (al_is_display_haptic(display)) //never get to here 46 hap = al_get_haptic_from_display(display); 47 } 48 49 while(1); //ends up here 50 51}

and here's the AndroidManifest.xml

#SelectExpand
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.tootiredgames.gravstorm" > 4 5 <uses-permission android:name="android.permission.INTERNET" /> 6 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 7 <uses-permission android:name="android.permission.VIBRATE" /> 8 9 <application 10 android:allowBackup="true" 11 android:icon="@mipmap/ic_launcher" 12 android:label="@string/app_name" 13 android:roundIcon="@mipmap/ic_launcher_round" 14 android:supportsRtl="true" 15 android:theme="@style/AppTheme" 16 android:windowSoftInputMode="stateVisible"> 17 <activity android:name=".MainActivity" 18 android:configChanges="orientation|screenSize" 19 android:screenOrientation="landscape" > 20 <intent-filter> 21 <action android:name="android.intent.action.MAIN" /> 22 <category android:name="android.intent.category.LAUNCHER" /> 23 </intent-filter> 24 </activity> 25 </application> 26 27</manifest>

beoran
Member #12,636
March 2011

It seems i forgot that I didn't implement haptics for Android and iOS at all. It only works on Linux and Windows for now. How silly of me!

Seeing my current situation I can't say when I will get to implemening the Android haptics driver for Allegro5. It's not that hard, though, so you could try it yourself if you need this urgently. I will try to assist you as I can.

Edit: on second thought, it doesn't seem right to leave you up shit creek without a paddle. I will write the driver myself asap. I would appreciate your help to test it though.

Ian Lewis
Member #15,817
December 2014

Ah, well that would explain it :-)

Thanks very much for the offer. I appreciate it, but don't let it get in the way of anything more important in your life :-)

Yes, I'm happy to test it. Let me know when you have something to test. I'll PM you my email address, in case that's useful.

Cheers,

Ian.

Go to: