mirror of
https://github.com/erjiang/usbscale.git
synced 2025-06-28 09:00:58 -06:00
Merge branch 'master' of github.com:erjiang/usbscale
This commit is contained in:
commit
76270a87a5
@ -1,2 +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"
|
||||
|
19
scales.h
19
scales.h
@ -10,17 +10,26 @@
|
||||
#include <stdint.h>
|
||||
|
||||
//
|
||||
// **scalesc** should be kept updated with the length of the list.
|
||||
// **NSCALES** should be kept updated with the length of the list.
|
||||
//
|
||||
int scalesc = 2;
|
||||
#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
|
||||
// ------
|
||||
//
|
||||
uint16_t scales[2][2] = {\
|
||||
// Stamps.com 10-lb USB scale
|
||||
uint16_t scales[NSCALES][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},
|
||||
// Mettler Toledo
|
||||
{0x0eb8, 0xf000}
|
||||
};
|
||||
|
13
usbscale.c
13
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,10 +215,13 @@ int main(void)
|
||||
printf("%x\n", data[i]);
|
||||
}
|
||||
#endif
|
||||
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");
|
||||
scale_result = -1;
|
||||
@ -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) {
|
||||
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;
|
||||
}
|
||||
@ -364,7 +373,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]) {
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user