0

I'm curious that if I want to use some custom sensor hardware (HID compatible) to act like gamepad. And then use gamepad API to work with it with js/html. What I won't be able to do?

Specifically, what could be done on HID api but cannot be with GamePad api? (and vice versa, if there is)

Thaina Yu
  • 1,372
  • 2
  • 16
  • 27
  • It's not about the commons or differences. You will not be able to treat the HID device as a Gamepad as it would be a big security hole. – Sunny R Gupta Aug 27 '16 at 09:59
  • @SunnyRGupta I mean, if I make a HID device sensor, but connect it as button and analog stick imitation, OS can see it as gamepad and report value to gamepad API. So I want to know how many things capable – Thaina Yu Aug 27 '16 at 13:43
  • The only thing would be, you will only be able to read from the device and not write back anything via the JS Gamepad API. – Sunny R Gupta Aug 29 '16 at 07:18
  • @SunnyRGupta If I understand you right, you mean every kind of things capable of input from HID could be map to gamepad api, only output not capable right? If so could you post your comment as answer so I can accept it – Thaina Yu Aug 29 '16 at 12:27
  • That is exactly what I meant. Added as an answer. – Sunny R Gupta Aug 29 '16 at 12:58

1 Answers1

1

As far as the Gamepad API goes, it is originally a Read-Only API. Hence you could make your sensor as one which emits events every few ticks to hack your HID device into acting like a Gamepad.

The con of this method is that you would not be able to write back to the "sensor -> HID interface -> Gamepad Device" system via the APIs.

As long as that is not a requirement, feel free to use it in this combination.

BONUS: If you want duplex communication abilities, you might consider hosting a server on a machine that connects to the HID device and use Java/PHP/Node based serial communications protocol to read/write to the sensor.

Your frontend application where the JS is running can then poll your server via AJAX for reading/writing data.

Sunny R Gupta
  • 5,026
  • 1
  • 31
  • 40
  • I ask because I just not so sure that, are there any HID input or information that may not be able to mapped to gamepad API. So I want to asking it for sure. Output is not my concern – Thaina Yu Aug 29 '16 at 13:05