usbscale icon indicating copy to clipboard operation
usbscale copied to clipboard

Auto detect scale and add to scales.h

Open o-k-a-y opened this issue 6 years ago • 5 comments
trafficstars

Is it possible when plugging in a new scale to add it to scales.h so there is no manual interference? Thanks!

o-k-a-y avatar Jul 05 '19 14:07 o-k-a-y

I guess you can make a PR, what do you think? Should be as simple as this.

(I'm not a maintainer here fwiw.)

sanmai avatar Jul 06 '19 00:07 sanmai

Auto-detection of USB scales would mean that there'd be no need for scales.h. It's a cool idea but I don't know how to implement it right now. Specifically, I don't know how to determine which USB devices are USB scales. Open to suggestions and/or PRs.

erjiang avatar Jul 06 '19 18:07 erjiang

This isn't really a solution for auto-detecting scales, but what if a flag were added for specifying a USB vendor and product at runtime? If the user-specified device is attached, the list in scales.h could be ignored and the user's device assumed to be a USB scale. That way if a scale isn't in scales.h this tool can still be used without recompiling.

It also occurs to me that a crude autodetection could be accomplished easily. If no USB scale is recognized, the program could prompt the user to plug in the scale, and wait for a new USB device to show up. The new device would then be assumed to be a scale. Moving the content of scales.h to a text file and parsing it at runtime would mean the program could dynamically add detected scales to the list so autodetection will only be required once. The program could check for scales.list (or whatever it would be called) in several locations, such as the working directory, /etc/usbscale, /usr/share/usbscale, et cetera. scales.list could be as simple as one USB ID per line, written like 1446:6a73.

skylarmt avatar Apr 15 '21 04:04 skylarmt

Taking in a USB vendor and product ID on the CLI sounds like a great addition.

It would be nice, of course, to figure out if there's a way to find any USB scale based on reported capability. The scale's report descriptor should contain this info, but it seems like the device needs to be unbound before it can be read and it's not realistic to unbind all your HIDs to find a scale.

erjiang avatar Apr 15 '21 19:04 erjiang

Maybe the easiest solution would be to parse scales.h at launch, if it exists; otherwise use the internal table.

TheWaterbug avatar Mar 23 '22 20:03 TheWaterbug