mirror of
https://github.com/erjiang/usbscale.git
synced 2025-06-27 08:30:58 -06:00
Remove trailing spaces
This commit is contained in:
parent
6ec35c72a3
commit
82a09725eb
32
usbscale.c
32
usbscale.c
@ -82,7 +82,7 @@ uint8_t get_first_endpoint_address(libusb_device* dev);
|
|||||||
// 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.
|
||||||
// The list is laid out so that the unit code returned by the scale is the
|
// The list is laid out so that the unit code returned by the scale is the
|
||||||
// index of its corresponding string.
|
// index of its corresponding string.
|
||||||
//
|
//
|
||||||
const char* UNITS[13] = {
|
const char* UNITS[13] = {
|
||||||
"units", // unknown unit
|
"units", // unknown unit
|
||||||
"mg", // milligram
|
"mg", // milligram
|
||||||
@ -117,7 +117,7 @@ int main(int argc, char **argv)
|
|||||||
// We first try to init libusb.
|
// We first try to init libusb.
|
||||||
//
|
//
|
||||||
r = libusb_init(NULL);
|
r = libusb_init(NULL);
|
||||||
//
|
//
|
||||||
// If `libusb_init` errored, then we quit immediately.
|
// If `libusb_init` errored, then we quit immediately.
|
||||||
//
|
//
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -143,7 +143,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "No USB scale found on this computer.\n");
|
fprintf(stderr, "No USB scale found on this computer.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Once we have a pointer to the USB scale in question, we open it.
|
// Once we have a pointer to the USB scale in question, we open it.
|
||||||
//
|
//
|
||||||
@ -204,7 +204,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "tared\n");
|
fprintf(stderr, "tared\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// For some reason, we get old data the first time, so let's just get that
|
// For some reason, we get old data the first time, so let's just get that
|
||||||
// out of the way now. It can't hurt to grab another packet from the scale.
|
// out of the way now. It can't hurt to grab another packet from the scale.
|
||||||
@ -219,7 +219,7 @@ int main(int argc, char **argv)
|
|||||||
&len,
|
&len,
|
||||||
10000 //timeout => 10 sec
|
10000 //timeout => 10 sec
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
// We read data from the scale in an infinite loop, stopping when
|
// We read data from the scale in an infinite loop, stopping when
|
||||||
// **print_scale_data** tells us that it's successfully gotten the weight
|
// **print_scale_data** tells us that it's successfully gotten the weight
|
||||||
// from the scale, or if the scale or transmissions indicates an error.
|
// from the scale, or if the scale or transmissions indicates an error.
|
||||||
@ -240,7 +240,7 @@ int main(int argc, char **argv)
|
|||||||
&len,
|
&len,
|
||||||
10000 //timeout => 10 sec
|
10000 //timeout => 10 sec
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
// If the data transfer succeeded, then we pass along the data we
|
// If the data transfer succeeded, then we pass along the data we
|
||||||
// received to **print_scale_data**.
|
// received to **print_scale_data**.
|
||||||
//
|
//
|
||||||
@ -264,8 +264,8 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// At the end, we make sure that we reattach the kernel driver that we
|
// At the end, we make sure that we reattach the kernel driver that we
|
||||||
// detached earlier, close the handle to the device, free the device list
|
// detached earlier, close the handle to the device, free the device list
|
||||||
// that we retrieved, and exit libusb.
|
// that we retrieved, and exit libusb.
|
||||||
@ -277,10 +277,10 @@ int main(int argc, char **argv)
|
|||||||
libusb_free_device_list(devs, 1);
|
libusb_free_device_list(devs, 1);
|
||||||
libusb_exit(NULL);
|
libusb_exit(NULL);
|
||||||
|
|
||||||
//
|
//
|
||||||
// The return code will be 0 for success or -1 for errors (see
|
// The return code will be 0 for success or -1 for errors (see
|
||||||
// `libusb_init` above if it's neither 0 nor -1).
|
// `libusb_init` above if it's neither 0 nor -1).
|
||||||
//
|
//
|
||||||
return scale_result;
|
return scale_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,11 +298,11 @@ int main(int argc, char **argv)
|
|||||||
//
|
//
|
||||||
static int print_scale_data(unsigned char* dat) {
|
static int print_scale_data(unsigned char* dat) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// We keep around `lastStatus` so that we're not constantly printing the
|
// We keep around `lastStatus` so that we're not constantly printing the
|
||||||
// same status message while waiting for a weighing. If the status hasn't
|
// same status message while waiting for a weighing. If the status hasn't
|
||||||
// changed from last time, **print_scale_data** prints nothing.
|
// changed from last time, **print_scale_data** prints nothing.
|
||||||
//
|
//
|
||||||
static uint8_t lastStatus = 0;
|
static uint8_t lastStatus = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -373,7 +373,7 @@ static int print_scale_data(unsigned char* dat) {
|
|||||||
fprintf(stderr, "Unknown status code: %d\n", status);
|
fprintf(stderr, "Unknown status code: %d\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastStatus = status;
|
lastStatus = status;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ static int print_scale_data(unsigned char* dat) {
|
|||||||
//
|
//
|
||||||
// find_scale
|
// find_scale
|
||||||
// ----------
|
// ----------
|
||||||
//
|
//
|
||||||
// **find_scale** takes a `libusb_device\*\*` list and loop through it,
|
// **find_scale** takes a `libusb_device\*\*` list and loop through it,
|
||||||
// matching each device's vendor and product IDs to the scales.h list. It
|
// matching each device's vendor and product IDs to the scales.h list. It
|
||||||
// return the first matching `libusb_device\*` or 0 if no matching device is
|
// return the first matching `libusb_device\*` or 0 if no matching device is
|
||||||
@ -406,7 +406,7 @@ static libusb_device* find_scale(libusb_device **devs)
|
|||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < NSCALES; i++) {
|
for (i = 0; i < NSCALES; i++) {
|
||||||
if(desc.idVendor == scales[i][0] &&
|
if(desc.idVendor == scales[i][0] &&
|
||||||
desc.idProduct == scales[i][1]) {
|
desc.idProduct == scales[i][1]) {
|
||||||
/*
|
/*
|
||||||
* Debugging data about found scale
|
* Debugging data about found scale
|
||||||
@ -442,7 +442,7 @@ static libusb_device* find_scale(libusb_device **devs)
|
|||||||
libusb_close(hand);
|
libusb_close(hand);
|
||||||
#endif
|
#endif
|
||||||
return dev;
|
return dev;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user