[Development] some questions about QtGamePad

Matthew Woehlke mwoehlke.floss at gmail.com
Mon Feb 15 19:32:38 CET 2016


On 2016-02-15 13:04, Matthew Woehlke wrote:
> On 2016-02-15 06:36, pritam.ghanghas at gmail.com wrote:
>> Looking at the API it seems it has a very hard assumption on 2 sticks and
>> 18 buttons.
> 
> Please support arbitrary axes and buttons, as done in e.g. SDL.

I wrote a joystick API in Qt a while back. It had three signals (I
didn't get around to hat support):

  buttonPressed(int button);
  buttonReleased(int button);
  motion(QHash<int, double> axisPosition);

The first two are obvious. The third (you'd probably want to use a
different name) is emitted every time any axis value changes, and
reports the current value of *all* axes. (This is an optimization /
implementation detail; you could as easily have a signal per axis, or
indeed do both.) Although I didn't need to have current-state accessors
(consider if you really need these), they'd be easy enough to add.

Hat support would probably look like:

  hatMoved(int hat, HatDirection direction);

Looking at QGamepadManager, I notice that you treat the hat as a set of
buttons. That doesn't strike me as a good idea. Buttons are normally
orthogonal (that is, given any two buttons, both might be pressed at the
same time). While it's true that you can be lazy and report hats that
way, there are problems doing so. First, it precludes users mapping an
entire hat to a single digital 2-axis control (or at least makes it much
more difficult). Second, hat directions are *not* orthogonal; a hat is
more of a digital version of an axis-pair, i.e. two values that are
either {-1, 0, +1}. This isn't just a matter of how you can mash on the
controller, it's also a question of what the hardware protocol is
capable of reporting.

-- 
Matthew




More information about the Development mailing list