Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Additional Joystick Information #1426

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/refman/joystick.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ handles may become inactive, and vice versa.

See also: [al_reconfigure_joysticks]

## API: al_get_joystick_device_id

Return the device id of the given joystick.

## API: al_get_joystick_name

Return the name of the given joystick.
Expand Down
2 changes: 2 additions & 0 deletions include/allegro5/internal/aintern_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct ALLEGRO_JOYSTICK_DRIVER
AL_METHOD(void, get_joystick_state, (ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_state));
AL_METHOD(const char *, get_name, (ALLEGRO_JOYSTICK *joy));
AL_METHOD(bool, get_active, (ALLEGRO_JOYSTICK *joy));
AL_METHOD(int, get_device_id, (ALLEGRO_JOYSTICK *joy));
} ALLEGRO_JOYSTICK_DRIVER;


Expand Down Expand Up @@ -71,6 +72,7 @@ typedef struct _AL_JOYSTICK_INFO
int num_buttons;
_AL_JOYSTICK_STICK_INFO stick[_AL_MAX_JOYSTICK_STICKS];
_AL_JOYSTICK_BUTTON_INFO button[_AL_MAX_JOYSTICK_BUTTONS];
int device_id;
} _AL_JOYSTICK_INFO;


Expand Down
1 change: 1 addition & 0 deletions include/allegro5/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ AL_FUNC(int, al_get_joystick_num_buttons, (ALLEGRO_JOYSTICK *));
AL_FUNC(const char*, al_get_joystick_button_name, (ALLEGRO_JOYSTICK *, int buttonn));

AL_FUNC(void, al_get_joystick_state, (ALLEGRO_JOYSTICK *, ALLEGRO_JOYSTICK_STATE *ret_state));
AL_FUNC(int, al_get_joystick_device_id, (ALLEGRO_JOYSTICK *));

AL_FUNC(ALLEGRO_EVENT_SOURCE *, al_get_joystick_event_source, (void));

Expand Down
3 changes: 2 additions & 1 deletion src/android/android_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,6 @@ ALLEGRO_JOYSTICK_DRIVER _al_android_joystick_driver = {
andjoy_release_joystick,
andjoy_get_joystick_state,
andjoy_get_name,
andjoy_get_active
andjoy_get_active,
andjoy_get_device_id
};
13 changes: 12 additions & 1 deletion src/gp2xwiz/wiz_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ static void joywiz_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_ST
}


static int joywiz_get_joystick_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("joywiz_get_joystick_device_id: not implemented");
return 0;
}




/* the driver vtable */
ALLEGRO_JOYSTICK_DRIVER _al_joydrv_gp2xwiz =
Expand All @@ -241,7 +251,8 @@ ALLEGRO_JOYSTICK_DRIVER _al_joydrv_gp2xwiz =
joywiz_get_num_joysticks,
joywiz_get_joystick,
joywiz_release_joystick,
joywiz_get_joystick_state
joywiz_get_joystick_state,
joywiz_get_joystick_device_id
};


11 changes: 10 additions & 1 deletion src/iphone/iphone_joystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ static bool ijoy_get_active(ALLEGRO_JOYSTICK *joy)
return true;
}

static int ijoy_get_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("ijoy_get_device_id: not implemented");
return 0;
}

static ALLEGRO_JOYSTICK_DRIVER iphone_joystick_driver = {
AL_ID('I', 'P', 'H', 'O'),
"",
Expand All @@ -134,7 +142,8 @@ static bool ijoy_get_active(ALLEGRO_JOYSTICK *joy)
ijoy_release_joystick,
ijoy_get_joystick_state,
ijoy_get_name,
ijoy_get_active
ijoy_get_active,
ijoy_get_device_id
};

ALLEGRO_JOYSTICK_DRIVER *_al_get_iphone_joystick_driver(void)
Expand Down
13 changes: 13 additions & 0 deletions src/joynu.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ void al_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_st
new_joystick_driver->get_joystick_state(joy, ret_state);
}



/* Function: al_get_joystick_device_id
*/
int al_get_joystick_device_id(ALLEGRO_JOYSTICK *joy)
{
ASSERT(new_joystick_driver);

return new_joystick_driver->get_device_id(joy);
}



/*
* Local Variables:
* c-basic-offset: 3
Expand Down
10 changes: 10 additions & 0 deletions src/macosx/hidjoy-10.4.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ static bool get_joystick_active(ALLEGRO_JOYSTICK *joy_)
return true;
}

static int get_joystick_device_id(ALLEGRO_JOYSTICK *joy_)
{
(void)joy_;
// TODO: Add implementation here
ALLEGRO_INFO("get_joystick_device_id: not implemented");
return 0;
}


static bool reconfigure_joysticks(void)
{
return false;
Expand All @@ -318,6 +327,7 @@ static bool reconfigure_joysticks(void)
vt->reconfigure_joysticks = reconfigure_joysticks;
vt->get_name = get_joystick_name;
vt->get_active = get_joystick_active;
vt->get_device_id = get_joystick_device_id;
}
return vt;
}
Expand Down
10 changes: 10 additions & 0 deletions src/macosx/hidjoy.m
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,15 @@ static bool get_joystick_active(ALLEGRO_JOYSTICK *joy_)
return joy->cfg_state == JOY_STATE_ALIVE || joy->cfg_state == JOY_STATE_DYING;
}

static int get_joystick_device_id(ALLEGRO_JOYSTICK *joy_)
{
(void)joy_;
// TODO: Add implementation here
ALLEGRO_INFO("get_joystick_device_id: not implemented");
return 0;
}


ALLEGRO_JOYSTICK_DRIVER* _al_osx_get_joystick_driver_10_5(void)
{
static ALLEGRO_JOYSTICK_DRIVER* vt = NULL;
Expand All @@ -759,6 +768,7 @@ static bool get_joystick_active(ALLEGRO_JOYSTICK *joy_)
vt->get_joystick_state = get_joystick_state;
vt->get_name = get_joystick_name;
vt->get_active = get_joystick_active;
vt->get_device_id = get_joystick_device_id;
}
return vt;
}
Expand Down
9 changes: 9 additions & 0 deletions src/sdl/sdl_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ static bool sdl_get_active(ALLEGRO_JOYSTICK *joy)
return SDL_JoystickGetAttached(sdl);
}

static int sdl_get_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("sdl_get_device_id: not implemented");
return 0;
}

ALLEGRO_JOYSTICK_DRIVER *_al_sdl_joystick_driver(void)
{
if (vt)
Expand All @@ -202,6 +210,7 @@ ALLEGRO_JOYSTICK_DRIVER *_al_sdl_joystick_driver(void)
vt->get_joystick_state = sdl_get_joystick_state;;
vt->get_name = sdl_get_name;
vt->get_active = sdl_get_active;
vt->get_device_id = sdl_get_device_id;

return vt;
}
11 changes: 10 additions & 1 deletion src/win/wjoyall.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static void joyall_release_joystick(ALLEGRO_JOYSTICK *joy);
static void joyall_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_state);
static const char *joyall_get_name(ALLEGRO_JOYSTICK *joy);
static bool joyall_get_active(ALLEGRO_JOYSTICK *joy);
static int joyall_get_device_id(ALLEGRO_JOYSTICK *joy);


/* the driver vtable */
Expand All @@ -100,7 +101,8 @@ ALLEGRO_JOYSTICK_DRIVER _al_joydrv_windows_all =
joyall_release_joystick,
joyall_get_joystick_state,
joyall_get_name,
joyall_get_active
joyall_get_active,
joyall_get_device_id
};

/* Mutex to protect state access. XXX is this needed? */
Expand Down Expand Up @@ -226,5 +228,12 @@ static bool joyall_get_active(ALLEGRO_JOYSTICK *joy)
return joy->driver->get_active(joy);
}

static int joyall_get_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("joyall_get_device_id: not implemented");
return 0;
}

#endif /* #ifdef ALLEGRO_CFG_XINPUT */
14 changes: 13 additions & 1 deletion src/win/wjoydxnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static void joydx_release_joystick(ALLEGRO_JOYSTICK *joy);
static void joydx_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_state);
static const char *joydx_get_name(ALLEGRO_JOYSTICK *joy);
static bool joydx_get_active(ALLEGRO_JOYSTICK *joy);
static int joydx_get_device_id(ALLEGRO_JOYSTICK *joy);

static void joydx_inactivate_joy(ALLEGRO_JOYSTICK_DIRECTX *joy);

Expand Down Expand Up @@ -138,7 +139,8 @@ ALLEGRO_JOYSTICK_DRIVER _al_joydrv_directx =
joydx_release_joystick,
joydx_get_joystick_state,
joydx_get_name,
joydx_get_active
joydx_get_active,
joydx_get_device_id
};


Expand Down Expand Up @@ -1390,6 +1392,16 @@ static bool joydx_get_active(ALLEGRO_JOYSTICK *joy)
}


static int joydx_get_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("joydx_get_device_id: not implemented");
return 0;
}



/* joydx_thread_proc: [joystick thread]
* Thread loop function for the joystick thread.
*/
Expand Down
13 changes: 12 additions & 1 deletion src/win/wjoyxi.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void joyxi_release_joystick(ALLEGRO_JOYSTICK *joy);
static void joyxi_get_joystick_state(ALLEGRO_JOYSTICK *joy, ALLEGRO_JOYSTICK_STATE *ret_state);
static const char *joyxi_get_name(ALLEGRO_JOYSTICK *joy);
static bool joyxi_get_active(ALLEGRO_JOYSTICK *joy);
static int joyxi_get_device_id(ALLEGRO_JOYSTICK *joy);


/* the driver vtable */
Expand All @@ -103,7 +104,8 @@ ALLEGRO_JOYSTICK_DRIVER _al_joydrv_xinput =
joyxi_release_joystick,
joyxi_get_joystick_state,
joyxi_get_name,
joyxi_get_active
joyxi_get_active,
joyxi_get_device_id
};

#define XINPUT_MIN_VERSION 3
Expand Down Expand Up @@ -718,4 +720,13 @@ static bool joyxi_get_active(ALLEGRO_JOYSTICK *joy)
}


static int joyxi_get_device_id(ALLEGRO_JOYSTICK *joy)
{
(void)joy;
// TODO: Add implementation here
ALLEGRO_INFO("joyxi_get_device_id: not implemented");
return 0;
}


#endif /* #ifdef ALLEGRO_CFG_XINPUT */