Gamepad('GetNumButtons', 1) returns zero

Hi,

I have an Xbox 360 controller hooked up to a USB port on my MacBook Air running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I got Mac OS to recognize the controller by installing a driver that is available at http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver. The driver enables the OS to detect the controller as evidenced in the system profiler. Matlab also seems to have no problem detecting the controller, as a call to Gamepad('GetNumGamepads') returns "1". However, for some reason Gamepad doesn't see any of the buttons on the controller (i.e., GetNumButtons returns zero). The only other thing that Gamepad seems to recognize is the thumbpad on the controller (i.e., GetNumAxes returns "4" ). I've also tried a generic Xbox controller (an off-brand knockoff), but got the same result as with an original Microsoft controller. Does anyone have any experience with connecting an Xbox controller to a Mac in Matlab/PTB? Or can anyone recommend a different controller that will work better? My experiment requires a gamepad style controller with at least 5 buttons.

Thanks!

Jin
Not exactly the same, but FYI I use WinXp and the vrjoystick matlab toolbox with no problem with an xbox360 controller. All the buttons are visible.

On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@...> wrote:

Hi,

I have an Xbox 360 controller hooked up to a USB port on my MacBook Air running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I got Mac OS to recognize the controller by installing a driver that is available at http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver. The driver enables the OS to detect the controller as evidenced in the system profiler. Matlab also seems to have no problem detecting the controller, as a call to Gamepad('GetNumGamepads') returns "1". However, for some reason Gamepad doesn't see any of the buttons on the controller (i.e., GetNumButtons returns zero). The only other thing that Gamepad seems to recognize is the thumbpad on the controller (i.e., GetNumAxes returns "4" ). I've also tried a generic Xbox controller (an off-brand knockoff), but got the same result as with an original Microsoft controller. Does anyone have any experience with connecting an Xbox controller to a Mac in Matlab/PTB? Or can anyone recommend a different controller that will work better? My experiment requires a gamepad style controller with at least 5 buttons.

Thanks!

Jin


vrjoystick seems like a no go on my computer. I get the following message when I try to create a joystick object with the controller connected: "??? Joystick input is not supported on this platform." Maybe it just doesn't like my computing environment. I'll try on a different computer and report back here. Thanks.

--- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@...> wrote:
>
> Not exactly the same, but FYI I use WinXp and the vrjoystick matlab toolbox
> with no problem with an xbox360 controller. All the buttons are visible.
>
> On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@...> wrote:
>
> > **
> >
> >
> > Hi,
> >
> > I have an Xbox 360 controller hooked up to a USB port on my MacBook Air
> > running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I got
> > Mac OS to recognize the controller by installing a driver that is available
> > at
> > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.The driver enables the OS to detect the controller as evidenced in the
> > system profiler. Matlab also seems to have no problem detecting the
> > controller, as a call to Gamepad('GetNumGamepads') returns "1". However,
> > for some reason Gamepad doesn't see any of the buttons on the controller
> > (i.e., GetNumButtons returns zero). The only other thing that Gamepad seems
> > to recognize is the thumbpad on the controller (i.e., GetNumAxes returns
> > "4" ). I've also tried a generic Xbox controller (an off-brand knockoff),
> > but got the same result as with an original Microsoft controller. Does
> > anyone have any experience with connecting an Xbox controller to a Mac in
> > Matlab/PTB? Or can anyone recommend a different controller that will work
> > better? My experiment requires a gamepad style controller with at least 5
> > buttons.
> >
> > Thanks!
> >
> > Jin
> >
> >
> >
>
I'm not a mac person, but if I had to guess (wildly) I'd say it's the driver. Are you sure you really need a special driver for it to be supported at all? Under XP if you don't install the Xinput driver the 360 pad is detected like a regular HID joystick with slightly funny handling of the corner analog switches, but otherwise is fully functional.

On Thu, Aug 15, 2013 at 5:20 PM, jhstx5 <jhstx5@...> wrote:

vrjoystick seems like a no go on my computer. I get the following message when I try to create a joystick object with the controller connected: "??? Joystick input is not supported on this platform." Maybe it just doesn't like my computing environment. I'll try on a different computer and report back here. Thanks.



--- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@...> wrote:
>
> Not exactly the same, but FYI I use WinXp and the vrjoystick matlab toolbox
> with no problem with an xbox360 controller. All the buttons are visible.
>
> On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@...> wrote:
>
> > **

> >
> >
> > Hi,
> >
> > I have an Xbox 360 controller hooked up to a USB port on my MacBook Air
> > running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I got
> > Mac OS to recognize the controller by installing a driver that is available
> > at
> > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.The driver enables the OS to detect the controller as evidenced in the

> > system profiler. Matlab also seems to have no problem detecting the
> > controller, as a call to Gamepad('GetNumGamepads') returns "1". However,
> > for some reason Gamepad doesn't see any of the buttons on the controller
> > (i.e., GetNumButtons returns zero). The only other thing that Gamepad seems
> > to recognize is the thumbpad on the controller (i.e., GetNumAxes returns
> > "4" ). I've also tried a generic Xbox controller (an off-brand knockoff),
> > but got the same result as with an original Microsoft controller. Does
> > anyone have any experience with connecting an Xbox controller to a Mac in
> > Matlab/PTB? Or can anyone recommend a different controller that will work
> > better? My experiment requires a gamepad style controller with at least 5
> > buttons.
> >
> > Thanks!
> >
> > Jin
> >
> >
> >
>


No. WinJoystickMex only supports up to 4 buttons. However, GetGamepadIndices should give you an index for a joystick that you could use as 'deviceIndex' for KbCheck and KbQueueCreate to treat the joystick buttons as a tiny keyboard, e.g., to abuse it as a response box.

That said, the same might work on OSX. Treating keyboards, keypads, mouse buttons, joystick/gamepad buttons etc. as "keyboards" is implemented on all OS'es. Of course if the XBOX 360 controller acts weird wrt. buttons, KbCheck et al. might have trouble with those buttons as well.

-mario

--- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@...> wrote:
>
> I'm not sure if this is diagnostic since I'm not the one having the
> problem, but under Win XP without any special drivers I do get some output
> from our 360 controller, though about half the buttons are missing:
>
> [x, y, z, buttons] = WinJoystickMex(0)
>
> x =
>
> 32983
>
>
> y =
>
> 32876
>
>
> z =
>
> 32767
>
>
> buttons =
>
> 0 0 0 0
>
> In comparison, the built in matlab toolkit detects them all.
>
> >> joy = vrjoystick(1)
>
> joy =
>
> vrjoystick object: 1-by-1
>
> >> [axes, buttons, povs] = read(joy)
>
> axes =
>
> 0 0 0 0 0
>
>
> buttons =
>
> 0 0 0 0 0 0 0 0 0 0
>
>
> povs =
>
> -1
>
>
> On Fri, Aug 16, 2013 at 10:07 AM, Mario <mario.kleiner@...>wrote:
>
> > **
> >
> >
> >
> >
> > Maybe the buttons are there and just don't get detected on OSX? If at
> > least GetNumAxes returned something meaningful, then the controller at
> > least shows up as a HID device, so there's some hope.
> >
> > You can try this:
> >
> > % Find gamepads index, hopefully only a single index:
> > gamepadIndices = GetGamepadIndices;
> >
> > % Get all elements of that gamepad:
> > elements = PsychHID('Elements', gamepadIndices);
> >
> > Now you can manually search 'elements' which is an array of structs for
> > the missing buttons. GamePad(), as you can see in lines 170-175 in an up to
> > date ptb, identifies buttons by there HID elements.usagePageValue
> >
> > Line 172 says:
> >
> > if ~isempty(elements(j).usagePageValue) &&
> > (elements(j).usagePageValue==buttonUsagePageValue)
> >
> > Maybe your XBOX controller doesn't use a usagePageValue of
> > buttonUsagePageValue == 9 for its buttons, but some other value. You'll
> > maybe find an appropriate value by matching the values returned in
> > elements.usagePageValue against the number of buttons. Then you could
> > modify line 109:
> >
> > buttonUsagePageValue=9; % anything on the button usage page is a button
> >
> > to set a proper value instead of 9. As you can see from the code, all
> > other elements seem to live on usagePage 1 and are differentiated by the
> > usageValue.
> >
> > I assume MS did something non-standard here with their XBOX controller.
> >
> > If in doubt, report back all the content of the elements struct array and
> > any other info about that controller, e.g., number of buttons, hats,
> > switches, sliders, whatever.
> > -mario
> >
> >
> > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > >
> > > I'm not a mac person, but if I had to guess (wildly) I'd say it's the
> > > driver. Are you sure you really need a special driver for it to be
> > > supported at all? Under XP if you don't install the Xinput driver the 360
> > > pad is detected like a regular HID joystick with slightly funny handling
> > of
> > > the corner analog switches, but otherwise is fully functional.
> > >
> > > On Thu, Aug 15, 2013 at 5:20 PM, jhstx5 <jhstx5@> wrote:
> > >
> > > > **
> >
> > > >
> > > >
> > > > vrjoystick seems like a no go on my computer. I get the following
> > message
> > > > when I try to create a joystick object with the controller connected:
> > "???
> > > > Joystick input is not supported on this platform." Maybe it just
> > doesn't
> > > > like my computing environment. I'll try on a different computer and
> > report
> > > > back here. Thanks.
> > > >
> > > >
> > > > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > > > >
> > > > > Not exactly the same, but FYI I use WinXp and the vrjoystick matlab
> > > > toolbox
> > > > > with no problem with an xbox360 controller. All the buttons are
> > visible.
> > > > >
> > > > > On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@> wrote:
> > > > >
> > > > > > **
> > > >
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have an Xbox 360 controller hooked up to a USB port on my
> > MacBook Air
> > > > > > running OS 10.8.4 with Matlab R2010a and the latest PTB
> > extensions. I
> > > > got
> > > > > > Mac OS to recognize the controller by installing a driver that is
> > > > available
> > > > > > at
> > > > > >
> > > >
> > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.Thedriverenables the OS to detect the controller as evidenced in the
> >
> > > >
> > > > > > system profiler. Matlab also seems to have no problem detecting the
> > > > > > controller, as a call to Gamepad('GetNumGamepads') returns "1".
> > > > However,
> > > > > > for some reason Gamepad doesn't see any of the buttons on the
> > > > controller
> > > > > > (i.e., GetNumButtons returns zero). The only other thing that
> > Gamepad
> > > > seems
> > > > > > to recognize is the thumbpad on the controller (i.e., GetNumAxes
> > > > returns
> > > > > > "4" ). I've also tried a generic Xbox controller (an off-brand
> > > > knockoff),
> > > > > > but got the same result as with an original Microsoft controller.
> > Does
> > > > > > anyone have any experience with connecting an Xbox controller to a
> > Mac
> > > > in
> > > > > > Matlab/PTB? Or can anyone recommend a different controller that
> > will
> > > > work
> > > > > > better? My experiment requires a gamepad style controller with at
> > > > least 5
> > > > > > buttons.
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > Jin
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>
That's the only thing that doesn't seem to work (again, XP):

>> GetGamepadIndices
ans =
2 2
>> [keyIsDown, secs, keyCode, deltaSecs] = KbCheck(2)
PsychHID-ERROR: Tried to start processing on keyboard queue for deviceIndex 2, but setting device state notifications failed!
Error in function KbCheck: Usage error
Starting keyboard queue failed!


On Fri, Aug 16, 2013 at 12:16 PM, Mario <mario.kleiner@...> wrote:



No. WinJoystickMex only supports up to 4 buttons. However, GetGamepadIndices should give you an index for a joystick that you could use as 'deviceIndex' for KbCheck and KbQueueCreate to treat the joystick buttons as a tiny keyboard, e.g., to abuse it as a response box.

That said, the same might work on OSX. Treating keyboards, keypads, mouse buttons, joystick/gamepad buttons etc. as "keyboards" is implemented on all OS'es. Of course if the XBOX 360 controller acts weird wrt. buttons, KbCheck et al. might have trouble with those buttons as well.



-mario

--- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@...> wrote:
>
> I'm not sure if this is diagnostic since I'm not the one having the
> problem, but under Win XP without any special drivers I do get some output
> from our 360 controller, though about half the buttons are missing:
>
> [x, y, z, buttons] = WinJoystickMex(0)
>
> x =
>
> 32983
>
>
> y =
>
> 32876
>
>
> z =
>
> 32767
>
>
> buttons =
>
> 0 0 0 0
>
> In comparison, the built in matlab toolkit detects them all.
>
> >> joy = vrjoystick(1)
>
> joy =
>
> vrjoystick object: 1-by-1
>
> >> [axes, buttons, povs] = read(joy)
>
> axes =
>
> 0 0 0 0 0
>
>
> buttons =
>
> 0 0 0 0 0 0 0 0 0 0
>
>
> povs =
>
> -1
>
>
> On Fri, Aug 16, 2013 at 10:07 AM, Mario <mario.kleiner@...>wrote:
>
> > **

> >
> >
> >
> >
> > Maybe the buttons are there and just don't get detected on OSX? If at
> > least GetNumAxes returned something meaningful, then the controller at
> > least shows up as a HID device, so there's some hope.
> >
> > You can try this:
> >
> > % Find gamepads index, hopefully only a single index:
> > gamepadIndices = GetGamepadIndices;
> >
> > % Get all elements of that gamepad:
> > elements = PsychHID('Elements', gamepadIndices);
> >
> > Now you can manually search 'elements' which is an array of structs for
> > the missing buttons. GamePad(), as you can see in lines 170-175 in an up to
> > date ptb, identifies buttons by there HID elements.usagePageValue
> >
> > Line 172 says:
> >
> > if ~isempty(elements(j).usagePageValue) &&
> > (elements(j).usagePageValue==buttonUsagePageValue)
> >
> > Maybe your XBOX controller doesn't use a usagePageValue of
> > buttonUsagePageValue == 9 for its buttons, but some other value. You'll
> > maybe find an appropriate value by matching the values returned in
> > elements.usagePageValue against the number of buttons. Then you could
> > modify line 109:
> >
> > buttonUsagePageValue=9; % anything on the button usage page is a button
> >
> > to set a proper value instead of 9. As you can see from the code, all
> > other elements seem to live on usagePage 1 and are differentiated by the
> > usageValue.
> >
> > I assume MS did something non-standard here with their XBOX controller.
> >
> > If in doubt, report back all the content of the elements struct array and
> > any other info about that controller, e.g., number of buttons, hats,
> > switches, sliders, whatever.
> > -mario
> >
> >
> > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > >
> > > I'm not a mac person, but if I had to guess (wildly) I'd say it's the
> > > driver. Are you sure you really need a special driver for it to be
> > > supported at all? Under XP if you don't install the Xinput driver the 360
> > > pad is detected like a regular HID joystick with slightly funny handling
> > of
> > > the corner analog switches, but otherwise is fully functional.
> > >
> > > On Thu, Aug 15, 2013 at 5:20 PM, jhstx5 <jhstx5@> wrote:
> > >
> > > > **
> >
> > > >
> > > >
> > > > vrjoystick seems like a no go on my computer. I get the following
> > message
> > > > when I try to create a joystick object with the controller connected:
> > "???
> > > > Joystick input is not supported on this platform." Maybe it just
> > doesn't
> > > > like my computing environment. I'll try on a different computer and
> > report
> > > > back here. Thanks.
> > > >
> > > >
> > > > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > > > >
> > > > > Not exactly the same, but FYI I use WinXp and the vrjoystick matlab
> > > > toolbox
> > > > > with no problem with an xbox360 controller. All the buttons are
> > visible.
> > > > >
> > > > > On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@> wrote:
> > > > >
> > > > > > **
> > > >
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have an Xbox 360 controller hooked up to a USB port on my
> > MacBook Air
> > > > > > running OS 10.8.4 with Matlab R2010a and the latest PTB
> > extensions. I
> > > > got
> > > > > > Mac OS to recognize the controller by installing a driver that is
> > > > available
> > > > > > at
> > > > > >
> > > >
> > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.Thedriverenables the OS to detect the controller as evidenced in the

> >
> > > >
> > > > > > system profiler. Matlab also seems to have no problem detecting the
> > > > > > controller, as a call to Gamepad('GetNumGamepads') returns "1".
> > > > However,
> > > > > > for some reason Gamepad doesn't see any of the buttons on the
> > > > controller
> > > > > > (i.e., GetNumButtons returns zero). The only other thing that
> > Gamepad
> > > > seems
> > > > > > to recognize is the thumbpad on the controller (i.e., GetNumAxes
> > > > returns
> > > > > > "4" ). I've also tried a generic Xbox controller (an off-brand
> > > > knockoff),
> > > > > > but got the same result as with an original Microsoft controller.
> > Does
> > > > > > anyone have any experience with connecting an Xbox controller to a
> > Mac
> > > > in
> > > > > > Matlab/PTB? Or can anyone recommend a different controller that
> > will
> > > > work
> > > > > > better? My experiment requires a gamepad style controller with at
> > > > least 5
> > > > > > buttons.
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > Jin
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> >
> >
>


Sorry for the late reply, but I just got a chance to try this. I got a result of 2 for "GetGamepadIndices", and "PsychHID('Elements', gamepadIndices)" returned an array of structs with 6 values, in order of X axis, Y axis, X rotation, Y rotation, and button input. All other structs in the array (1x26) were empty. I suppose this means the OS is only able to detect one button? Odd, because the buttons all show up and respond to input in the little utility that came with the driver download from tattiebogle.net. Maybe the driver is not interfacing well with Matlab? BTW, the controller has one D-pad, two analog control sticks, and 11 buttons (including the two analogue trigger buttons).

P.S. I thought my PTB was up to date, but it wasn't when I first ran into this issue. Got the same results after updating as well, however.

--- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@...> wrote:
>
>
>
>
>
>
> Maybe the buttons are there and just don't get detected on OSX? If at least GetNumAxes returned something meaningful, then the controller at least shows up as a HID device, so there's some hope.
>
> You can try this:
>
> % Find gamepads index, hopefully only a single index:
> gamepadIndices = GetGamepadIndices;
>
> % Get all elements of that gamepad:
> elements = PsychHID('Elements', gamepadIndices);
>
> Now you can manually search 'elements' which is an array of structs for the missing buttons. GamePad(), as you can see in lines 170-175 in an up to date ptb, identifies buttons by there HID elements.usagePageValue
>
> Line 172 says:
>
> if ~isempty(elements(j).usagePageValue) && (elements(j).usagePageValue==buttonUsagePageValue)
>
> Maybe your XBOX controller doesn't use a usagePageValue of buttonUsagePageValue == 9 for its buttons, but some other value. You'll maybe find an appropriate value by matching the values returned in elements.usagePageValue against the number of buttons. Then you could modify line 109:
>
> buttonUsagePageValue=9; % anything on the button usage page is a button
>
> to set a proper value instead of 9. As you can see from the code, all other elements seem to live on usagePage 1 and are differentiated by the usageValue.
>
> I assume MS did something non-standard here with their XBOX controller.
>
> If in doubt, report back all the content of the elements struct array and any other info about that controller, e.g., number of buttons, hats, switches, sliders, whatever.
> -mario
>
>
>
> --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> >
> > I'm not a mac person, but if I had to guess (wildly) I'd say it's the
> > driver. Are you sure you really need a special driver for it to be
> > supported at all? Under XP if you don't install the Xinput driver the 360
> > pad is detected like a regular HID joystick with slightly funny handling of
> > the corner analog switches, but otherwise is fully functional.
> >
> > On Thu, Aug 15, 2013 at 5:20 PM, jhstx5 <jhstx5@> wrote:
> >
> > > **
> > >
> > >
> > > vrjoystick seems like a no go on my computer. I get the following message
> > > when I try to create a joystick object with the controller connected: "???
> > > Joystick input is not supported on this platform." Maybe it just doesn't
> > > like my computing environment. I'll try on a different computer and report
> > > back here. Thanks.
> > >
> > >
> > > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > > >
> > > > Not exactly the same, but FYI I use WinXp and the vrjoystick matlab
> > > toolbox
> > > > with no problem with an xbox360 controller. All the buttons are visible.
> > > >
> > > > On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@> wrote:
> > > >
> > > > > **
> > >
> > > > >
> > > > >
> > > > > Hi,
> > > > >
> > > > > I have an Xbox 360 controller hooked up to a USB port on my MacBook Air
> > > > > running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I
> > > got
> > > > > Mac OS to recognize the controller by installing a driver that is
> > > available
> > > > > at
> > > > >
> > > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.Thedriver enables the OS to detect the controller as evidenced in the
> > >
> > > > > system profiler. Matlab also seems to have no problem detecting the
> > > > > controller, as a call to Gamepad('GetNumGamepads') returns "1".
> > > However,
> > > > > for some reason Gamepad doesn't see any of the buttons on the
> > > controller
> > > > > (i.e., GetNumButtons returns zero). The only other thing that Gamepad
> > > seems
> > > > > to recognize is the thumbpad on the controller (i.e., GetNumAxes
> > > returns
> > > > > "4" ). I've also tried a generic Xbox controller (an off-brand
> > > knockoff),
> > > > > but got the same result as with an original Microsoft controller. Does
> > > > > anyone have any experience with connecting an Xbox controller to a Mac
> > > in
> > > > > Matlab/PTB? Or can anyone recommend a different controller that will
> > > work
> > > > > better? My experiment requires a gamepad style controller with at
> > > least 5
> > > > > buttons.
> > > > >
> > > > > Thanks!
> > > > >
> > > > > Jin
> > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> >
>
Can you provide the full output of the struct array?
And of the struct array from devs = PsychHID('Devices');

PsychHID detects HID devices and enumerates their HID elements. If that special driver you refer to doesn't present the Gamepad properly as a standard HID gamepad device with standard HID buttons, it can't get properly detected. The empty structs hint that validation of those elements as valid HID elements failed, so they were skipped during enumeration.

One thing you could try is "fly blind" and just query button state like this:

value = PsychHID('RawState', gamepadIndices, elementidx);

and set elementidx to a value between 1 and 26. If you get lucky, some of the elementidx indices corresponding to one of the empty slots in your 26 element struct array will yield useable return 'value's which describes the state of the buttons despite those elements being rated invalid. If you are unlucky, this won't happen, or Matlab will simply crash, given you try to access elements which were rated as "invalid". Will probably fail, but is worth a try.

-mario

--- In psychtoolbox@yahoogroups.com, "jhstx5" <jhstx5@...> wrote:
>
> Sorry for the late reply, but I just got a chance to try this. I got a result of 2 for "GetGamepadIndices", and "PsychHID('Elements', gamepadIndices)" returned an array of structs with 6 values, in order of X axis, Y axis, X rotation, Y rotation, and button input. All other structs in the array (1x26) were empty. I suppose this means the OS is only able to detect one button? Odd, because the buttons all show up and respond to input in the little utility that came with the driver download from tattiebogle.net. Maybe the driver is not interfacing well with Matlab? BTW, the controller has one D-pad, two analog control sticks, and 11 buttons (including the two analogue trigger buttons).
>
> P.S. I thought my PTB was up to date, but it wasn't when I first ran into this issue. Got the same results after updating as well, however.
>
> --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> >
> >
> >
> >
> >
> >
> > Maybe the buttons are there and just don't get detected on OSX? If at least GetNumAxes returned something meaningful, then the controller at least shows up as a HID device, so there's some hope.
> >
> > You can try this:
> >
> > % Find gamepads index, hopefully only a single index:
> > gamepadIndices = GetGamepadIndices;
> >
> > % Get all elements of that gamepad:
> > elements = PsychHID('Elements', gamepadIndices);
> >
> > Now you can manually search 'elements' which is an array of structs for the missing buttons. GamePad(), as you can see in lines 170-175 in an up to date ptb, identifies buttons by there HID elements.usagePageValue
> >
> > Line 172 says:
> >
> > if ~isempty(elements(j).usagePageValue) && (elements(j).usagePageValue==buttonUsagePageValue)
> >
> > Maybe your XBOX controller doesn't use a usagePageValue of buttonUsagePageValue == 9 for its buttons, but some other value. You'll maybe find an appropriate value by matching the values returned in elements.usagePageValue against the number of buttons. Then you could modify line 109:
> >
> > buttonUsagePageValue=9; % anything on the button usage page is a button
> >
> > to set a proper value instead of 9. As you can see from the code, all other elements seem to live on usagePage 1 and are differentiated by the usageValue.
> >
> > I assume MS did something non-standard here with their XBOX controller.
> >
> > If in doubt, report back all the content of the elements struct array and any other info about that controller, e.g., number of buttons, hats, switches, sliders, whatever.
> > -mario
> >
> >
> >
> > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > >
> > > I'm not a mac person, but if I had to guess (wildly) I'd say it's the
> > > driver. Are you sure you really need a special driver for it to be
> > > supported at all? Under XP if you don't install the Xinput driver the 360
> > > pad is detected like a regular HID joystick with slightly funny handling of
> > > the corner analog switches, but otherwise is fully functional.
> > >
> > > On Thu, Aug 15, 2013 at 5:20 PM, jhstx5 <jhstx5@> wrote:
> > >
> > > > **
> > > >
> > > >
> > > > vrjoystick seems like a no go on my computer. I get the following message
> > > > when I try to create a joystick object with the controller connected: "???
> > > > Joystick input is not supported on this platform." Maybe it just doesn't
> > > > like my computing environment. I'll try on a different computer and report
> > > > back here. Thanks.
> > > >
> > > >
> > > > --- In psychtoolbox@yahoogroups.com, Alan Robinson <arcogsci@> wrote:
> > > > >
> > > > > Not exactly the same, but FYI I use WinXp and the vrjoystick matlab
> > > > toolbox
> > > > > with no problem with an xbox360 controller. All the buttons are visible.
> > > > >
> > > > > On Wed, Aug 14, 2013 at 7:42 PM, jhstx5 <jhstx5@> wrote:
> > > > >
> > > > > > **
> > > >
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have an Xbox 360 controller hooked up to a USB port on my MacBook Air
> > > > > > running OS 10.8.4 with Matlab R2010a and the latest PTB extensions. I
> > > > got
> > > > > > Mac OS to recognize the controller by installing a driver that is
> > > > available
> > > > > > at
> > > > > >
> > > > http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver.Thedriver enables the OS to detect the controller as evidenced in the
> > > >
> > > > > > system profiler. Matlab also seems to have no problem detecting the
> > > > > > controller, as a call to Gamepad('GetNumGamepads') returns "1".
> > > > However,
> > > > > > for some reason Gamepad doesn't see any of the buttons on the
> > > > controller
> > > > > > (i.e., GetNumButtons returns zero). The only other thing that Gamepad
> > > > seems
> > > > > > to recognize is the thumbpad on the controller (i.e., GetNumAxes
> > > > returns
> > > > > > "4" ). I've also tried a generic Xbox controller (an off-brand
> > > > knockoff),
> > > > > > but got the same result as with an original Microsoft controller. Does
> > > > > > anyone have any experience with connecting an Xbox controller to a Mac
> > > > in
> > > > > > Matlab/PTB? Or can anyone recommend a different controller that will
> > > > work
> > > > > > better? My experiment requires a gamepad style controller with at
> > > > least 5
> > > > > > buttons.
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > Jin
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
>
Here is what jhstx5 posted without all the erroneous HTML surrounding it:

Many apologies for the late response. I've been getting a 'could not send message error' for a couple of weeks, but the problem seems to have gone away now (no thanks to yahoo support).


I'm not sure why I'm getting 2 for GetGamepadIndeces, so I tried "flying blind" (i.e., PsychHID('RawState', gamepadIndices, elementidx);) with gamepadIndices=1 and gamepadIndices=2. When gamepadIndices=1, I obtained zero values for elementidx 1 through 8 and then the following error for any elementindx greater than 8:


INTERNAL PSYCHTOOLBOX ERROR

error: PsychError_internal

general description: Unspecified error, probably a Psychtoolbox bug

specific description: Invalid device index specified. Has a device has been unplugged? Try rebuilding the device list

module name: PsychHID

subfunction call: RawState

file name: Common/PsychHID/PsychHIDHelpers.c

function name: PsychHIDGetElementRecordFromDeviceRecordAndElementIndex

line number: 693

??? Error using ==> PsychHID

See error message printed above.

When I flew blind with gamepadindices set to 2, I obtained zero values for all elementidx between 1 and 100 (by iterating elementidx through a for loop; didn't try anything above 100). Thinking these zero values were legitimate, I tried flying blind while holding down a few buttons on the gamepad, but failed to obtain any "1" values. I attached the full structs for devs = PsychHID('Devices'); and elements = PsychHID('Elements', gamepadIndices); and below is the command line output (the fields) for each variable.


devs =


1x6 struct array with fields:

usagePageValue

usageValue

usageName

index

transport

vendorID

productID

version

manufacturer

product

serialNumber

locationID

interfaceID

totalElements

features

inputs

outputs

collections

axes

buttons

hats

sliders

dials

wheels


elements =


1x26 struct array with fields:

typeMaskName

name

deviceIndex

elementIndex

typeValue

typeName

usagePageValue

usageValue

usageName

dataSize

rangeMin

rangeMax

scaledRangeMin

scaledRangeMax

relative

wrapping

nonLinear

preferredState

nullState

calMin

calMax

scalingMin

scalingMax

Happy to report that a PS3 controller works with no special drivers on Mac OS 10.8.4. A total of 19 buttons are recognized (the "D" pad appears to be recognized as buttons, which makes sense), and one of the analogue joysticks is recognized as an "Axes". One big problem, however: the controller starts to "rumble/vibrate" as soon as you plug it in and continues to rumble until it is unplugged. I tried searching the struct array generated by PsychHID('Elements', gamepadindex) to look for some kind of vibrate or rumble function that could be turned off, but none were available. It could be that the controller I have is defective or off in some way because it is a cheap generic version of the original Sony controller. Either way, there must be some way to manipulate the on/off state of the rumble function through PsychHID? 



--- In psychtoolbox@yahoogroups.com, <jhstx5@...> wrote:

Thanks for the definitive answer. I will try the PS3 controller as someone else suggested and let you know if I get better results.--Jin


From: Mario <mario.kleiner@...>
To: psychtoolbox@yahoogroups.com
Sent: Wednesday, September 4, 2013 4:01 PM
Subject: [psychtoolbox] Re: Gamepad('GetNumButtons', 1) returns zero

 


Looks like "Game over" on OSX. The device doesn't enumerate properly as HID device.

Sorry,
-mario

--- In psychtoolbox@yahoogroups.com, Matthew Edmundson <medmunds@...> wrote:
>
> Here is what jhstx5 posted without all the erroneous HTML surrounding it:
>
> Many apologies for the late response. I've been getting a 'could not send
> message error' for a couple of weeks, but the problem seems to have gone
> away now (no thanks to yahoo support).
>
>
> I'm not sure why I'm getting 2 for GetGamepadIndeces, so I tried "flying
> blind" (i.e., PsychHID('RawState', gamepadIndices, elementidx);) with
> gamepadIndices=1 and gamepadIndices=2. When gamepadIndices=1, I obtained
> zero values for elementidx 1 through 8 and then the following error for any
> elementindx greater than 8:
>
>
> INTERNAL PSYCHTOOLBOX ERROR
>
> error: PsychError_internal
>
> general description: Unspecified error, probably a Psychtoolbox bug
>
> specific description: Invalid device index specified. Has a device has been
> unplugged? Try rebuilding the device list
>
> module name: PsychHID
>
> subfunction call: RawState
>
> file name: Common/PsychHID/PsychHIDHelpers.c
>
> function name: PsychHIDGetElementRecordFromDeviceRecordAndElementIndex
>
> line number: 693
>
> ??? Error using ==> PsychHID
>
> See error message printed above.
>
> When I flew blind with gamepadindices set to 2, I obtained zero values for
> all elementidx between 1 and 100 (by iterating elementidx through a for
> loop; didn't try anything above 100). Thinking these zero values were
> legitimate, I tried flying blind while holding down a few buttons on the
> gamepad, but failed to obtain any "1" values. I attached the full structs
> for devs = PsychHID('Devices'); and elements = PsychHID('Elements',
> gamepadIndices); and below is the command line output (the fields) for each
> variable.
>
>
> devs =
>
>
> 1x6 struct array with fields:
>
> usagePageValue
>
> usageValue
>
> usageName
>
> index
>
> transport
>
> vendorID
>
> productID
>
> version
>
> manufacturer
>
> product
>
> serialNumber
>
> locationID
>
> interfaceID
>
> totalElements
>
> features
>
> inputs
>
> outputs
>
> collections
>
> axes
>
> buttons
>
> hats
>
> sliders
>
> dials
>
> wheels
>
>
> elements =
>
>
> 1x26 struct array with fields:
>
> typeMaskName
>
> name
>
> deviceIndex
>
> elementIndex
>
> typeValue
>
> typeName
>
> usagePageValue
>
> usageValue
>
> usageName
>
> dataSize
>
> rangeMin
>
> rangeMax
>
> scaledRangeMin
>
> scaledRangeMax
>
> relative
>
> wrapping
>
> nonLinear
>
> preferredState
>
> nullState
>
> calMin
>
> calMax
>
> scalingMin
>
> scalingMax
>



Thank you so much! This works well with Xbox One Controller. Joystick inputs as well as A B X and Y. There are no trigger buttons that will work.

[x, y, z, buttons] = WinJoystickMex(0)

I am on version 3.0.17 - Flavor: beta - Corresponds to SVN Revision 12153

Not sure if there is a question in here, but the KbQueue functions should usually also be able to record joystick button events, e.g., KbEventGet.