From 2a08b1a73a407bbc5159f0d93f80a457b9b84d7a Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Wed, 16 Jul 2014 14:41:15 -0400 Subject: [PATCH 1/9] Add user-contributed SANFORD Dymo 10 lb scale --- scales.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scales.h b/scales.h index 99a6d18..fb4dc95 100644 --- a/scales.h +++ b/scales.h @@ -12,7 +12,7 @@ // // **NSCALES** should be kept updated with the length of the list. // -#define NSCALES 5 +#define NSCALES 6 // // What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing) @@ -32,6 +32,8 @@ uint16_t scales[NSCALES][2] = {\ {0x2474, 0x0550}, // Mettler Toledo {0x0eb8, 0xf000}, + // SANFORD Dymo 10 lb USB Postal Scale + {0x6096, 0x0158}, // Fairbanks Scales SCB-R9000 {0x0b67, 0x555e} }; From eb90d0afb12a73a5142b7fbbb46af6b42056791a Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Tue, 16 Jun 2015 11:42:26 -0400 Subject: [PATCH 2/9] Copy over some vendor/product IDs from scales.h --- 50-usb-scale.rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index 59e94a9..ad3ca82 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -2,3 +2,5 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", 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}=="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" From af28f08c70ff5bae22c49b3a781ac7c274deb395 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Tue, 16 Jun 2015 11:44:09 -0400 Subject: [PATCH 3/9] Clean up Makefile --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b4945e5..587fe0e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ LDLIBS=-lm -lusb-1.0 -CC=gcc CFLAGS=-Os -Wall DOCCO=docco @@ -9,7 +8,7 @@ usbscale: usbscale.c scales.h lsusb: lsusb.c scales.h docs: usbscale.c - docco usbscale.c + $(DOCCO) usbscale.c clean: rm -f lsscale From f685c3c355fe19014ff22a3b67f6c6eb9dfbee3a Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Thu, 18 Jun 2015 17:06:55 -0400 Subject: [PATCH 4/9] Add Stamps.com Stainless Steel 35 lb. Digital Scale Thanks to jt70471 who reported this device on Github as issue #10 --- 50-usb-scale.rules | 1 + scales.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index ad3ca82..618d84b 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -1,6 +1,7 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="1446", ATTR{idProduct}=="6a73", 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}=="3550", 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" diff --git a/scales.h b/scales.h index fb4dc95..1435f2f 100644 --- a/scales.h +++ b/scales.h @@ -30,6 +30,8 @@ uint16_t scales[NSCALES][2] = {\ {0x7b7c, 0x0100}, // Stamps.com Stainless Steel 5 lb. Digital Scale {0x2474, 0x0550}, + // Stamps.com Stainless Steel 35 lb. Digital Scale + {0x2474, 0x3550}, // Mettler Toledo {0x0eb8, 0xf000}, // SANFORD Dymo 10 lb USB Postal Scale From c0f3c1ea055a4e28997f7ec1b326a39c4d1760d0 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 23 Oct 2015 15:46:55 +0900 Subject: [PATCH 5/9] scales.h: correct number of known scales --- scales.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scales.h b/scales.h index 1435f2f..a6dc5ec 100644 --- a/scales.h +++ b/scales.h @@ -12,7 +12,7 @@ // // **NSCALES** should be kept updated with the length of the list. // -#define NSCALES 6 +#define NSCALES 7 // // What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing) From d2f0d6ea615c11a5b21d95c1e68c0e4fdd216fbe Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 23 Oct 2015 17:01:02 +0900 Subject: [PATCH 6/9] print_scale_data: correctly apply exponent --- usbscale.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/usbscale.c b/usbscale.c index 8099449..376e3e0 100644 --- a/usbscale.c +++ b/usbscale.c @@ -276,16 +276,12 @@ static int print_scale_data(unsigned char* dat) { uint8_t report = dat[0]; uint8_t status = dat[1]; uint8_t unit = dat[2]; - uint8_t expt = dat[3]; - double weight = (double)(dat[4] + (dat[5] << 8)) / 10; - - if(expt != 255 && expt != 0) { - if (expt > 127) { - weight = weight * pow(10, expt-255); - } else { - weight = pow(weight, expt); - } - } + // Accoring to the docs, scaling applied to the data as a base ten exponent + int8_t expt = dat[3]; + // convert to machine order at all times + double weight = (double) le16toh(dat[5] << 8 | dat[4]); + // since the expt is signed, we do not need no trickery + weight = weight * pow(10, expt); // // The scale's first byte, its "report", is always 3. From 4ef120b93479a771ba2d03c06ea4c6bdcaf645ea Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 23 Oct 2015 17:59:59 +0900 Subject: [PATCH 7/9] 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. --- scales.h | 6 ++++-- usbscale.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/scales.h b/scales.h index a6dc5ec..dc693bd 100644 --- a/scales.h +++ b/scales.h @@ -12,7 +12,7 @@ // // **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) @@ -37,5 +37,7 @@ uint16_t scales[NSCALES][2] = {\ // SANFORD Dymo 10 lb USB Postal Scale {0x6096, 0x0158}, // Fairbanks Scales SCB-R9000 - {0x0b67, 0x555e} + {0x0b67, 0x555e}, + // Dymo-CoStar Corp. M25 Digital Postal Scale + {0x0922, 0x8004} }; diff --git a/usbscale.c b/usbscale.c index 376e3e0..d052fd8 100644 --- a/usbscale.c +++ b/usbscale.c @@ -60,6 +60,12 @@ static libusb_device* find_scale(libusb_device**); // program should read again (i.e. continue looping). // 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 // Point of Sale Usage Tables*, version 1.02, by the USB Implementers' Forum. @@ -197,8 +203,7 @@ int main(void) handle, //bmRequestType => direction: in, type: class, // recipient: interface - LIBUSB_ENDPOINT_IN | //LIBUSB_REQUEST_TYPE_CLASS | - LIBUSB_RECIPIENT_INTERFACE, + get_first_endpoint_address(dev), data, WEIGH_REPORT_SIZE, // length of data &len, @@ -414,3 +419,22 @@ static libusb_device* find_scale(libusb_device **devs) 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; +} From 6ff81583dbf87bc88a9a2f167499b75230f265b6 Mon Sep 17 00:00:00 2001 From: Kristofer Sommestad Date: Wed, 28 Oct 2015 18:19:21 +0100 Subject: [PATCH 8/9] Added missing Dymo scale to rules.d file --- 50-usb-scale.rules | 1 + 1 file changed, 1 insertion(+) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index 618d84b..9cf6fda 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -5,3 +5,4 @@ SUBSYSTEM=="usb", ATTR{idVendor}=="2474", ATTR{idProduct}=="3550", 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" From 1ee1e85cbe1a498836e854885f717fcedacb371f Mon Sep 17 00:00:00 2001 From: Kristofer Sommestad Date: Wed, 28 Oct 2015 18:19:30 +0100 Subject: [PATCH 9/9] Added support for DYMO 1772057 Digital Postal Scale --- 50-usb-scale.rules | 1 + scales.h | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index 9cf6fda..c540173 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -6,3 +6,4 @@ 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" diff --git a/scales.h b/scales.h index dc693bd..52a605e 100644 --- a/scales.h +++ b/scales.h @@ -12,7 +12,7 @@ // // **NSCALES** should be kept updated with the length of the list. // -#define NSCALES 8 +#define NSCALES 9 // // What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing) @@ -39,5 +39,7 @@ uint16_t scales[NSCALES][2] = {\ // Fairbanks Scales SCB-R9000 {0x0b67, 0x555e}, // Dymo-CoStar Corp. M25 Digital Postal Scale - {0x0922, 0x8004} + {0x0922, 0x8004}, + // DYMO 1772057 Digital Postal Scale + {0x0922, 0x8003} };