After spending some time trying to think of a way to map "stick 0 axis 2" to something more human-readable, I took a minute to run a Google search, and found out that SDL has this nice database of controllers. Such a database allows to determine if "stick 0" is a d-pad, thumb-controller, or something else.
SDL's database relies on SDL-style GUIDs for joysticks. With Allegro, presently there is no way to get such a GUID, or data from which it could be constructed (Allegro 5 API only returns human-readable name of joystick).
So, what I'm thinking about, shouldn't Allegro borrow this functionality from SDL? At least as far a GUID generation, but preferably also loading of SDL-style controller database files and classification of buttons/sticks by user's request.
Some thoughts on possible API:
int al_get_joystick_guid( ALLEGRO_JOYSTICK *joystick, char *buffer, int length ); // Allow user access to GUIDs; maybe use something like ALLEGRO_JOYSTICK_GUID instead of buffer and length?
int al_load_joystick_mapping( const char *filename ); // To load controller database
int al_register_joystick_mapping( const char *mapping_string ); // To register a new mapping string, without loading it from file
bool al_has_mapping_for_joystick( ALLEGRO_JOYSTICK *joystick ); // To check if Allegro has a registered mapping for specified joystick (in case user want some special handling for this case)
ALLEGRO_JOYSTICK_BUTTON al_get_joystick_button_mapping( ALLEGRO_JOYSTICK *joystick, int button ); // To convert button index into more descriptive constant
ALLEGRO_JOYSTICK_STICK al_get_joystick_stick_mapping( ALLEGRO_JOYSTICK *joystick, int stick ); // To convert stick index into more descriptive constant
// ALLEGRO_JOYSTICK_BUTTON and ALLEGRO_JOYSTICK_STICK could be pretty much copied from SDL:
Such API would allow Allegro users to:
a) Define default control schemes for games more intelligently (i.e. "'A' button is Fire vs. '0th' button is Fire). This applies more to sticks/axis than to buttons, since they vary wildly (my Logitech F310 uses 2nd stick for D-pad, for heavens sake!).
b) Display control scheme for user more intelligently in tutorial or control definition menu (i.e. draw a picture of D-pad instead of writing godawful things like "Stick 2 Axis 2 Positive"
The second problem could be solved by displaying results from al_get_joystick_button_name and al_get_joystick_stick/axis_name to user, but this is not a very good solution, since these results are platform-dependent and localized by system, and therefore could require font with Unicode characters support when the game itself does not require one.
The first problem, presently, could not be solved at all, unless you want to create a mapping database that depends on reported controller name (you don't).
If developers think this is a good idea, I guess I can work on borrowing SDL implementation of joystick GUID generation and the rest of functionality. It shouldn't be too hard, and shouldn't touch the rest of library too much.
Or maybe I'm missing some alternative solution? If so, please tell me Mapping problem currently stops me from completing nearly-ready game, and I'm itching to do something about it!