From 5acc91ec4f1d7c14f72c40ff4d739c77a17c27f3 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Sun, 14 Oct 2012 00:19:57 -0700 Subject: [PATCH 1/4] Added "Stamps.com Stainless Steel 5 lb. ..." --- scales.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scales.h b/scales.h index 9336c1c..60a00ff 100644 --- a/scales.h +++ b/scales.h @@ -12,15 +12,17 @@ // // **scalesc** should be kept updated with the length of the list. // -int scalesc = 2; +int scalesc = 3; // // Scales // ------ // -uint16_t scales[2][2] = {\ - // Stamps.com 10-lb USB scale +uint16_t scales[3][2] = {\ + // Stamps.com Model 510 5LB Scale {0x1446, 0x6a73}, // USPS (Elane) PS311 "XM Elane Elane UParcel 30lb" - {0x7b7c, 0x0100} + {0x7b7c, 0x0100}, + // Stamps.com Stainless Steel 5 lb. Digital Scale + {0x2474, 0x0550} }; From cef66896ec09f8533046d2e09b2e84fcfeb10781 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Sun, 14 Oct 2012 00:21:52 -0700 Subject: [PATCH 2/4] Made the number of valid scales a defined constant --- scales.h | 6 +++--- usbscale.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scales.h b/scales.h index 60a00ff..ac7c811 100644 --- a/scales.h +++ b/scales.h @@ -10,15 +10,15 @@ #include // -// **scalesc** should be kept updated with the length of the list. +// **NSCALES** should be kept updated with the length of the list. // -int scalesc = 3; +#define NSCALES 3 // // Scales // ------ // -uint16_t scales[3][2] = {\ +uint16_t scales[NSCALES][2] = {\ // Stamps.com Model 510 5LB Scale {0x1446, 0x6a73}, // USPS (Elane) PS311 "XM Elane Elane UParcel 30lb" diff --git a/usbscale.c b/usbscale.c index 001ea64..90bf46a 100644 --- a/usbscale.c +++ b/usbscale.c @@ -364,7 +364,7 @@ static libusb_device* find_scale(libusb_device **devs) return NULL; } int i; - for (i = 0; i < scalesc; i++) { + for (i = 0; i < NSCALES; i++) { if(desc.idVendor == scales[i][0] && desc.idProduct == scales[i][1]) { /* From 7a6ac78c5fb6b6b5835c1e738998a693e907c117 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Mon, 15 Oct 2012 21:30:17 -0700 Subject: [PATCH 3/4] Also add udev entry for stamps.com 5lb steel scale --- 50-usb-scale.rules | 1 + 1 file changed, 1 insertion(+) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index 8cb3d66..2a8e51c 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -1,2 +1,3 @@ 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" From 8246022ddb2cae1587ac4b0765c4838721271781 Mon Sep 17 00:00:00 2001 From: Dmitriy Kozmenko Date: Mon, 30 Sep 2013 13:59:58 -0400 Subject: [PATCH 4/4] Added: Mettler Toledo Fixed: Skip first result Added: Set exponent --- 50-usb-scale.rules | 1 + scales.h | 11 +++++++++-- usbscale.c | 19 ++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/50-usb-scale.rules b/50-usb-scale.rules index 2a8e51c..59e94a9 100644 --- a/50-usb-scale.rules +++ b/50-usb-scale.rules @@ -1,3 +1,4 @@ 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" diff --git a/scales.h b/scales.h index ac7c811..9106922 100644 --- a/scales.h +++ b/scales.h @@ -12,7 +12,12 @@ // // **NSCALES** should be kept updated with the length of the list. // -#define NSCALES 3 +#define NSCALES 4 + +// +// What is the number of the weighing result to show, as the first result may be incorrect (from the previous weighing) +// +#define WEIGH_COUNT 2 // // Scales @@ -24,5 +29,7 @@ uint16_t scales[NSCALES][2] = {\ // USPS (Elane) PS311 "XM Elane Elane UParcel 30lb" {0x7b7c, 0x0100}, // Stamps.com Stainless Steel 5 lb. Digital Scale - {0x2474, 0x0550} + {0x2474, 0x0550}, + // Mettler Toledo + {0x0eb8, 0xf000} }; diff --git a/usbscale.c b/usbscale.c index 90bf46a..8099449 100644 --- a/usbscale.c +++ b/usbscale.c @@ -94,6 +94,8 @@ int main(void) libusb_device* dev; libusb_device_handle* handle; + int weigh_count = WEIGH_COUNT -1; + // // We first try to init libusb. // @@ -213,9 +215,12 @@ int main(void) printf("%x\n", data[i]); } #endif - scale_result = print_scale_data(data); - if(scale_result != 1) - break; + if (weigh_count < 1) { + scale_result = print_scale_data(data); + if(scale_result != 1) + break; + } + weigh_count--; } else { fprintf(stderr, "Error in USB transfer\n"); @@ -275,13 +280,17 @@ static int print_scale_data(unsigned char* dat) { double weight = (double)(dat[4] + (dat[5] << 8)) / 10; if(expt != 255 && expt != 0) { - weight = pow(weight, expt); + if (expt > 127) { + weight = weight * pow(10, expt-255); + } else { + weight = pow(weight, expt); + } } // // The scale's first byte, its "report", is always 3. // - if(report != 0x03) { + if(report != 0x03 && report != 0x04) { fprintf(stderr, "Error reading scale data\n"); return -1; }