Jump to content


How do I map buttons for SDL


12 replies to this topic

#1 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 21 October 2008 - 02:34 PM

I have a logitech dual action gamepad, that I want to use SDL for input, I have code like in the doc wiki tutorial on SDL but I don't get any input registered by my program I can post code later.
Thanks:happy: .
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#2 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 21 October 2008 - 04:23 PM

Did you open the joystick and enable joystick events?
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#3 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 21 October 2008 - 05:49 PM

I open it like this
//{player 1 joystick
SDL_Joystick *joystick1;
SDL_JoystickEventState(SDL_ENABLE);
if(SDL_NumJoysticks()>0) joystick1 = SDL_JoystickOpen(0);
//}
and I trie to access it like this
//{SDL event receiver
switch( event.type )
{
    //{keyboard events
    case SDL_KEYDOWN:
    /* handle keyboard stuff here */
    break;
    //}

   //{joystick events

   case SDL_JOYHATMOTION:  // Handle Hat Motion

    if ( event.jhat.value && SDL_HAT_UP )
    {
        menu_item ++;
    }

    if ( event.jhat.value && SDL_HAT_DOWN )
    {
        menu_item --;
    }
    break;

    //}
}
//}

//}
I did'nt do anything to my gamepad, just plugged it in out of the box.
By trying to access the joystick "hat" I'm accessing the "D pad" right?.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 21 October 2008 - 06:01 PM

Just a note, please use [code]...[/code] when posting code on the forum. Thanks!
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 21 October 2008 - 06:05 PM

Oh sorry, I did'nt see that option. But do I need to use the logitech profiler
to map anything, I know that I open the gamepad, I tested putting analog control instead of D pad but it still does'nt do it.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#6 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 23 October 2008 - 03:27 AM

Did you initialize the joystick sub-system (i.e. bitwise-or SDL_INIT_JOYSTICK with your other parameters in the SDL_Init call)? Also, I'm not sure if your gamepad acts as a HAT switch. Have you tried any buttons?
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#7 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 23 October 2008 - 02:53 PM

I tried the analog to.
//initialize SDL

    if(SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_TIMER) < 0)  return 1;

that's how I init SDL. I use irrlicht with would this conflict?.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#8 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 28 October 2008 - 03:32 AM

What operating system are you using? If it is Windows, does the joystick show up as a human interface device (HID)?

Do you check the value of joystick1 to make sure it is not NULL or unassigned? Your code snippet does not show proper handling of not detecting any joysticks.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#9 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 28 October 2008 - 02:39 PM

Not showing up as NULL, and it shows up fine in the game controllers section of the Windows XP control pad.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#10 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 29 October 2008 - 03:00 AM

I believe I recall the Dual Action having a button that changes the behavior of the D-pad. I believe it shows up as a pair of axes in one configuration, but I don't know if it works as a HAT switch or not. Are you sure you are not getting any button events? Also, are you pumping the SDL message loop properly?

Have you gotten keyboard events to work first? Here is a simple tutorial.
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#11 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 29 October 2008 - 02:54 PM

Okay I'll read that tutorial and trie to get it working, I use Irrlicht though so could it be swallowing up events?.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#12 3DModelerMan

    Member

  • Members
  • PipPip
  • 79 posts

Posted 29 October 2008 - 03:17 PM

YAAAAAAAAAAAAAAAAAY!!!!!!!!! I got it working the device was swallowing up events just init the SDL before Irrlicht and it works!.
Thanks guy!:yes: .
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!

#13 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 31 October 2008 - 01:52 PM

Irrlicht was swallowing the events? That's good to know for future reference. I'm glad you got it working!
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users