felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.81k stars 590 forks source link

Provide a default `device_filter.xml` resource #28

Open ge0rg opened 8 years ago

ge0rg commented 8 years ago

The USB Host SDK provides an intent filter for USB attach events, that can be used to auto-launch your app when a certain USB device is attached.

It would be great to have such a device_filter.xml file as part of the usbserial source code (or even AAR), based on the vendor/product IDs supported by UsbSerial. It is possible to create a momentary snapshot of the supported IDs thanks to the consistent style in the deviceids directory, using this black magic incantation (you just need to mix in some XML boilerplate):

perl -lne 'print "\t<usb-device vendor-id=\"$1\" product-id=\"$2\" />" if /new ConcreteDevice.0x([0-9a-f]{4}), 0x([0-9a-f]{4})/i' java/com/felhr/deviceids/*.java

However, it would be nicer and cleaner to have the XML either auto-generated in the build process or (manually?) updated with new device IDs. It is probably also possible to replace many of the entries by a vendor/class or similar combination, instead of listing all supported IDs.

felHR85 commented 8 years ago

I guess this would allow to auto open the serial port when the device is just connected. Am I right?

ge0rg commented 8 years ago

Exactly. If you have only one supporting app installed, it is opened directly; if you have multiple apps, you get a ttypical chooser intent dialog.

csobsidian commented 8 years ago

This should be implemented by the application and not by the library. Including it by default would mean every app would have this behavior even if they didnt want it.

ge0rg commented 8 years ago

The application needs to include a device filter XML for this feature to work. My suggestion is merely to provide such an XML file as part of the library, so that app developers have an easier time integrating.

bill-chadwick commented 6 years ago

Indeed XML file(s) ready populated with the vid+pid pairs in the /java/com/felhr/deviceids namespace source files would be very handy.

bill-chadwick commented 6 years ago

xml attached in text file below - created from sources off github

bill-chadwick commented 6 years ago

device_filter.txt