robatwilliams / awesome-webhid

Curated list of resources relating to the WebHID (Human Interface Device) API
171 stars 19 forks source link

Question on connect/disconnect events #11

Closed mame82 closed 4 years ago

mame82 commented 5 years ago

Hi,

as you have quit a bit of knowledge on WebHID, you could maybe answer my question.

O'm currently working on a Single Page App utilizing WebHID to interact with a custom device. Everything works well, so far (see BLExy videos on youtube for reference).

What I don't get to work are the disconnect events on navigator.hid, which is an issue, as I'm not able to recognize removal of the USB device and sending reports simply fails (HIDDevice instance is left behind with open property set to true).

I'm using latest Chrome 78 in Linux x64.

I hope you could drop a hint on how to detect device disconnection.

Cheers Marcus

robatwilliams commented 5 years ago

I've not tried those, but from the following comment I think they might not be implemented yet - https://bugs.chromium.org/p/chromium/issues/detail?id=890096#c38

reillyeon commented 5 years ago

Connect and disconnect events are not yet implemented.

CC @nondebug

tijmenvangulik commented 5 years ago

I made the following a work around in ergometer-space.org:

This works fine for me

Tijmen

On 30 Oct 2019, at 22:50, Robat Williams notifications@github.com wrote:

I've not tried those, but from the following comment I think they might not be implemented yet - https://bugs.chromium.org/p/chromium/issues/detail?id=890096#c38 https://bugs.chromium.org/p/chromium/issues/detail?id=890096#c38 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/robatwilliams/awesome-webhid/issues/11?email_source=notifications&email_token=AAVG7NVUH6JS5WBSJWH2LXDQRH6TDA5CNFSM4JHAVTXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECV4JJQ#issuecomment-548127910, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVG7NWRW6N3BF2W3WDNJYDQRH6TDANCNFSM4JHAVTXA.

robatwilliams commented 4 years ago

Discussion is resolved by https://github.com/robatwilliams/awesome-webhid/issues/11#issuecomment-548162549

mame82 commented 4 years ago

Thx for the answers.

In my case, USB HID input reports are sent infrequently by the device, either to indicate state changes or in response to output reports from the host (representing requests in upper protocol layers). This means sending kind of "keep-alive" HID reports, only to detect disconnects isn't ideal. Additionally it would introduce unnecessary overhead to the microcontroller of the USB device if it has to produce keep-alive reports or to filter out dummy reports, in case they're sent from the host.

So I think it would be the best to wait for implementation of connect/disconnect events.

todbot commented 4 years ago

Hi @mame82, I think you can send to the device from the host, even if the device isn’t configured to receive, and the HID driver will either send the packet or error out if device is disconnected. Basically do the keep-alive, but have it host-originated.

mame82 commented 4 years ago

@todbot

Yes, but afaik the respective (input) reports would end up as control transfers at ep0 and force an idle response from the device - or am I wrong in that?