balthisar / cncjs-pendant-gamepad

Use a Videogame Controller as a CNCjs Pendant
MIT License
13 stars 8 forks source link

PS3 : HAT X- X+ Y- Y+ are buttons, not axes #3

Open mathojojo opened 2 years ago

mathojojo commented 2 years ago

Hello,

I could make my PS3 controller work on CNCjs with your gamepad pendant. Thank you.

There is just a problem with HAT buttons. Your gamepad.ts configuration file is considering them as Axes. It might be the case on most controller, I don't know. But on the PS3 Controller, X-, X+, Y- and Y+ are 4 differents buttons, not 2 axes.

So I can't use the hat, and Z axe can only be controlled with the Y- Y+ Hat buttons.

Can you fix it, or give me a way to make it work anyway ?

Thank you

mathojojo commented 2 years ago
  // This is the mapping for the PS3 controller
  //This controller has 6 axes (0 to 5) and 17 buttons (0 to 16)
  'Sony PLAYSTATION(R)3 Controller': {

    'buttons': {
      '3': 'KEYCODE_BUTTON_X',
      '0': 'KEYCODE_BUTTON_A',
      '1': 'KEYCODE_BUTTON_B',
      '2': 'KEYCODE_BUTTON_Y',
      '4': 'KEYCODE_BUTTON_L1',
      '5': 'KEYCODE_BUTTON_R1',
      '6': 'KEYCODE_BUTTON_LTRIGGER', // note: ALSO activates the axis.
      '7': 'KEYCODE_BUTTON_RTRIGGER', // note: ALSO activates the axis.
      '8': 'KEYCODE_BACK',
      '9': 'KEYCODE_BUTTON_START',
      '11': 'KEYCODE_BUTTON_THUMBL',
      '12': 'KEYCODE_BUTTON_THUMBR',
      '10': 'KEYCODE_HOME',
      '13': 'KEYCODE_BUTTON_HAT_X_PLUS',
      '14': 'KEYCODE_BUTTON_HAT_X_MINUS',
      '15': 'KEYCODE_BUTTON_HAT_Y_PLUS',
      '16': 'KEYCODE_BUTTON_HAT_Y_MINUS'
    },

I added 4 keys (13, 14, 15 and 16) accordingly to the PS3 controller HAT direction buttons. But of course, they won't be executed as the code doesn't know them.

And this is the answer for jstest /dev/input/js0 : Joystick (Sony PLAYSTATION(R)3 Controller) has 6 axes (X, Y, Z, Rx, Ry, Rz) and 17 buttons (BtnA, BtnB, BtnX, BtnY, BtnTL, BtnTR, BtnTL2, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR, (null), (null), (null), (null)).

The last 4 buttons seems to not have names, but they are the 13, 14, 15 and 16 hat pad buttons.