webdfu icon indicating copy to clipboard operation
webdfu copied to clipboard

Decouple the library from the example

Open Ecco opened this issue 6 years ago • 7 comments

The current demo works really well, but it is rather painful to reuse.

My understanding is that dfu.js and dfuse.js were thought as an easily-reusable library, and that dfu-util.js is responsible for hooking up the library to the demo HTML.

The problem is, dfu-util.js still does some heavy lifting : for example, see the connect function which tries to figure out if a given device is DfuSe-compliant or not. Re-using this code currently means duplicating this function.

It would be very useful to have a minimal UI-less demo to make sure reusing this library is easy.

Ecco avatar Oct 27 '17 13:10 Ecco

Yeah, dfu.js and dfuse.js are more or less directly ported from dfu-util, whereas dfu-util.js is a bit more interactive than the real dfu-util.

My initial thoughts for refactoring some of that logic would be to add a new connectDfuInterface function that would absorb the descriptor-reading code in connect and in the call to navigator.usb.requestDevice. The user could then pass in an async callback to handle selecting the interface (which could either be interactive or pick a known-in-advance interface by interface number, name, etc).

devanlai avatar Oct 29 '17 19:10 devanlai

I think the community would value an agnostic dfu library too. For example, I'd like to use something like that with node-serialport instead of webusb, or a driver I write on my own.

We're you also considering breaking out interface such that webusb, node-serialport, etc depend on dap.js?

beriberikix avatar Jul 18 '18 14:07 beriberikix

@beriberikix I'm not sure that I understand what you're proposing. Right now, webdfu is basically just a driver/front-end for USB DFU class devices. It would be a major departure from the USB DFU spec to make something that could also work over serial or over CMSIS-DAP/SWD.

devanlai avatar Jul 19 '18 15:07 devanlai

Ah, I realize my mistake, I was confusing two posts :)

My actual goal is to use this in a pure Node.js, non-browser context. Is that possible?

beriberikix avatar Jul 19 '18 16:07 beriberikix

I haven't tried this personally (or Node.js, for that matter), but there is a Node.js implementation of the WebUSB spec that you could try: https://github.com/thegecko/webusb

devanlai avatar Jul 19 '18 16:07 devanlai

https://github.com/thegecko/webusb/issues/24

beriberikix avatar Jul 19 '18 16:07 beriberikix

It would be great to see if webdfu works with the webusb node implementation!

thegecko avatar Jul 21 '18 12:07 thegecko