Merge pull request #1 from erjiang/master

Merge upstream changes
This commit is contained in:
Matthias Nieuwenhuisen 2016-03-03 16:54:26 +01:00
commit 0d3d6d2055
4 changed files with 48 additions and 16 deletions

View File

@ -1,4 +1,9 @@
SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="7b7c", ATTR{idProduct}=="0100", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="7b7c", ATTR{idProduct}=="0100", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="0550", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="0550", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="3550", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="0eb8", ATTR{idProduct}=="f000", MODE="0776" SUBSYSTEM=="usb", ATTR{idVendor}=="0eb8", ATTR{idProduct}=="f000", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="6096", ATTR{idProduct}=="0158", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="0b67", ATTR{idProduct}=="555e", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="0922", ATTR{idProduct}=="8004", MODE="0776"
SUBSYSTEM=="usb", ATTR{idVendor}=="0922", ATTR{idProduct}=="8003", MODE="0776"

View File

@ -1,5 +1,4 @@
LDLIBS=-lm -lusb-1.0 LDLIBS=-lm -lusb-1.0
CC=gcc
CFLAGS=-Os -Wall CFLAGS=-Os -Wall
DOCCO=docco DOCCO=docco
@ -9,7 +8,7 @@ usbscale: usbscale.c scales.h
lsusb: lsusb.c scales.h lsusb: lsusb.c scales.h
docs: usbscale.c docs: usbscale.c
docco usbscale.c $(DOCCO) usbscale.c
clean: clean:
rm -f lsscale rm -f lsscale

View File

@ -12,7 +12,7 @@
// //
// **NSCALES** should be kept updated with the length of the list. // **NSCALES** should be kept updated with the length of the list.
// //
#define NSCALES 5 #define NSCALES 9
// //
// What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing) // What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing)
@ -30,8 +30,16 @@ uint16_t scales[NSCALES][2] = {\
{0x7b7c, 0x0100}, {0x7b7c, 0x0100},
// Stamps.com Stainless Steel 5 lb. Digital Scale // Stamps.com Stainless Steel 5 lb. Digital Scale
{0x2474, 0x0550}, {0x2474, 0x0550},
// Stamps.com Stainless Steel 35 lb. Digital Scale
{0x2474, 0x3550},
// Mettler Toledo // Mettler Toledo
{0x0eb8, 0xf000}, {0x0eb8, 0xf000},
// SANFORD Dymo 10 lb USB Postal Scale
{0x6096, 0x0158},
// Fairbanks Scales SCB-R9000 // Fairbanks Scales SCB-R9000
{0x0b67, 0x555e} {0x0b67, 0x555e},
// Dymo-CoStar Corp. M25 Digital Postal Scale
{0x0922, 0x8004},
// DYMO 1772057 Digital Postal Scale
{0x0922, 0x8003}
}; };

View File

@ -60,6 +60,12 @@ static libusb_device* find_scale(libusb_device**);
// program should read again (i.e. continue looping). // program should read again (i.e. continue looping).
// //
static int print_scale_data(unsigned char*); static int print_scale_data(unsigned char*);
//
// take device and fetch bEndpointAddress for the first endpoint
//
uint8_t get_first_endpoint_address(libusb_device* dev);
// //
// **UNITS** is an array of all the unit abbreviations as set forth by *HID // **UNITS** is an array of all the unit abbreviations as set forth by *HID
// Point of Sale Usage Tables*, version 1.02, by the USB Implementers' Forum. // Point of Sale Usage Tables*, version 1.02, by the USB Implementers' Forum.
@ -197,8 +203,7 @@ int main(void)
handle, handle,
//bmRequestType => direction: in, type: class, //bmRequestType => direction: in, type: class,
// recipient: interface // recipient: interface
LIBUSB_ENDPOINT_IN | //LIBUSB_REQUEST_TYPE_CLASS | get_first_endpoint_address(dev),
LIBUSB_RECIPIENT_INTERFACE,
data, data,
WEIGH_REPORT_SIZE, // length of data WEIGH_REPORT_SIZE, // length of data
&len, &len,
@ -276,16 +281,12 @@ static int print_scale_data(unsigned char* dat) {
uint8_t report = dat[0]; uint8_t report = dat[0];
uint8_t status = dat[1]; uint8_t status = dat[1];
uint8_t unit = dat[2]; uint8_t unit = dat[2];
uint8_t expt = dat[3]; // Accoring to the docs, scaling applied to the data as a base ten exponent
double weight = (double)(dat[4] + (dat[5] << 8)) / 10; int8_t expt = dat[3];
// convert to machine order at all times
if(expt != 255 && expt != 0) { double weight = (double) le16toh(dat[5] << 8 | dat[4]);
if (expt > 127) { // since the expt is signed, we do not need no trickery
weight = weight * pow(10, expt-255); weight = weight * pow(10, expt);
} else {
weight = pow(weight, expt);
}
}
// //
// The scale's first byte, its "report", is always 3. // The scale's first byte, its "report", is always 3.
@ -418,3 +419,22 @@ static libusb_device* find_scale(libusb_device **devs)
return NULL; return NULL;
} }
uint8_t get_first_endpoint_address(libusb_device* dev)
{
// default value
uint8_t endpoint_address = LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE; //| LIBUSB_RECIPIENT_ENDPOINT;
struct libusb_config_descriptor *config;
int r = libusb_get_config_descriptor(dev, 0, &config);
if (r == 0) {
// assuming we have only one endpoint
endpoint_address = config->interface[0].altsetting[0].endpoint[0].bEndpointAddress;
libusb_free_config_descriptor(config);
}
#ifdef DEBUG
printf("bEndpointAddress 0x%02x\n", endpoint_address);
#endif
return endpoint_address;
}