My question would be, what a proper/good generic way could be to add standard Point of View Hat input to BABYLON.GenericPad class?
Gamepads with DPads
Some joysticks and gamepads are equipped with something called a Hat Switch or a Point of View adjustment knob. This is a default HID feature and shows up in the standard Gamepad configuration dialog box in Windows.
In my case I have a very generic $5 wired USB gamepad which looks like a Dual Shock controller in almost every way. It has the same amount of (software exposed) buttons, 2 handles, and vibration/rumble option.
DPad exposed as POV hat
It also has a button + LED to toggle between digital and analog controller mode:
- In digital mode it converts the DPad buttons to the same as the left stick (so DPad up-right becomes leftStick.x = 1 and leftStick.y = -1
- In analog mode the DPad buttons work as a point of view hat switch. DPad up-right becomes axis[9] = -0.71429. The left stick then works independently of the DPad buttons.
Reported axis values for POV hat
We will continue with the analog mode, as that is the POV mode:
No DPad button pressed (if pressed, shows up as arrow in any of the 8 marked directions)
DPad button Up+Right pressed.
When no DPad is pressed, then Windows won’t show an arrow in any of the 8 directions on that gamepad configuration screen.
Apparently, POV (Hat Switch in HID) is most often exposed to the web on gamepad axis 9 (so the 10th axis).
- POV will show up as axis[9] with a value between -1 and 1 inclusive, when a DPad is pressed.
- When no DPad is pressed, a constant ‘NULL’ meaning value outside -1 and 1 range will be reported (e.g. 3.28571 but I’ve also seen 1.24 etc.).
Converting POV hat axis value to DPad directions
Decoding of the axis values is quite simple. The values for the number of DPad combinations (angles) are linearly spread out over -1 and 1 axis[9] range. So for n=8 directions, Up become -1, Up-Right becomes -0.71429, etc. until you have 1 for Up-Left. Some systems divide the range over n+1, meaning that you’ll end up at a little less than 1 for Up-Left.
POV hat as BABYLON.GenericDPad?
Hence I have the impression that a good way to model standard POV hat data at the last axis (axis[9]) would be to expose something like a DPad also on the BABYLON.GenericPad. And then convert the axis[9] values to (a combination of) pressed/released GenericDPad ‘buttons’. Similarly to how you can subscribe to XBox360DPad and DualShockDPad observers.
RSVP
Such a POV Hat 2 DPad feature would probably enable a lot of USB Gamepads out there with 4 extra ‘buttons’ to play with in your BabylonJS apps.
- How do you guys and gals think about this?