Support for DYMO M25 Digital Postal Scale

Dymo M25 Scale uses different endpoint from the default (LIBUSB_RECIPIENT_ENDPOINT instead of LIBUSB_RECIPIENT_INTERFACE), hence we need to find it in the device's configuration.
This commit is contained in:
Alexey Kopytko 2015-10-23 17:59:59 +09:00
parent d2f0d6ea61
commit 4ef120b934
2 changed files with 30 additions and 4 deletions

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 7 #define NSCALES 8
// //
// 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)
@ -37,5 +37,7 @@ uint16_t scales[NSCALES][2] = {\
// SANFORD Dymo 10 lb USB Postal Scale // SANFORD Dymo 10 lb USB Postal Scale
{0x6096, 0x0158}, {0x6096, 0x0158},
// Fairbanks Scales SCB-R9000 // Fairbanks Scales SCB-R9000
{0x0b67, 0x555e} {0x0b67, 0x555e},
// Dymo-CoStar Corp. M25 Digital Postal Scale
{0x0922, 0x8004}
}; };

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,
@ -414,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;
}