Re: [AD] ex_joystick_hotplugging.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2010-08-22, Thomas Fjellstrom <tfjellstrom@xxxxxxxxxx> wrote:
> On August 22, 2010, Peter Wang wrote:
> > 
> > Rather, ALLEGRO_JOYSTICK handles should persist after reconfiguration,
> > and they should continue to refer to the same physical devices (which
> > are still plugged in).  No re-getting of handles required.
> > 
...
> Sounds good to me. It would be best if we could somehow detect whether or not 
> the device is the same or not, and give a slot back to the same device. But 
> when I checked my joystick, it didn't have any kind of unique id. :( so the 
> best we could /really/ rely on is the name, and maybe some other hardware 
> properties. And try and give the slot back based on that. Failing that, yes, 
> just repopulate which ever slot is free.
> 
> Does make it easier for the average allegro user.

I have implemented it for Linux.  I can update the Windows driver too,
unless someone else wants to.  Someone will need to do Mac.

Here is an example of the new behaviour.  Initially three devices are
connected.  Internally we have an array of three ALLEGRO_JOYSTICK
handles.  Each handle is in one of the states: unused, born, alive, dying.

al_init_joystick():

    [js0-alive, js1-alive, js2-alive]

    al_get_num_joysticks() == 3
    al_get_joystick(0) == js0, etc.

The physical-device-represented-by-js1 is unplugged:

    [js0-alive, js1-dying, js2-alive]

    al_get_num_joysticks() == 3
    al_get_num_joystick(1) == js1  (state change not immediately visible)

After al_reconfigure_joysticks():

    [js0-alive, js1-unused, js2-alive]

    al_get_num_joysticks() == 2
    al_get_joystick(1) == js2  (unused handles are invisible)

Another device is plugged in:

    [js0-alive, js1-born, js2-alive]

    al_get_num_joysticks() == 2
    al_get_joystick(1) == js2  (state change not immediately visible)

After al_reconfigure_joysticks():

    [js0-alive, js1-alive, js2-alive]

    al_get_num_joysticks() == 3
    al_get_joystick(1) == js1

Peter




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/