erjiang / usbscale

Reads weight data from USB scales.
GNU General Public License v3.0
90 stars 22 forks source link

Auto detect scale and add to scales.h #19

Open o-k-a-y opened 5 years ago

o-k-a-y commented 5 years ago

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

sanmai commented 5 years ago

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

(I'm not a maintainer here fwiw.)

erjiang commented 5 years ago

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.

skylarmt commented 3 years ago

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.

erjiang commented 3 years ago

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.

TheWaterbug commented 2 years ago

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