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; }