Fix formatting and replace tabs with spaces
This commit is contained in:
parent
867d83c215
commit
72da5c73db
|
@ -65,20 +65,17 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
* right-to-left, so only the least significant nibbles need to be
|
||||
* specified.
|
||||
*/
|
||||
if ((serno = strchr(port, ':')) != NULL)
|
||||
{
|
||||
/* first, drop all colons there if any */
|
||||
if ((serno = strchr(port, ':')) != NULL) {
|
||||
/* First, drop all colons there if any */
|
||||
cp2 = ++serno;
|
||||
|
||||
while ((cp2 = strchr(cp2, ':')) != NULL)
|
||||
{
|
||||
while ((cp2 = strchr(cp2, ':')) != NULL) {
|
||||
x = strlen(cp2) - 1;
|
||||
memmove(cp2, cp2 + 1, x);
|
||||
cp2[x] = '\0';
|
||||
}
|
||||
|
||||
if (strlen(serno) > 12)
|
||||
{
|
||||
if (strlen(serno) > 12) {
|
||||
pmsg_error("invalid serial number %s\n", serno);
|
||||
return -1;
|
||||
}
|
||||
|
@ -99,21 +96,18 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
}
|
||||
|
||||
walk = list;
|
||||
while (walk)
|
||||
{
|
||||
while (walk) {
|
||||
pmsg_notice("usbhid_open(): found %ls, serno: %ls\n", walk->product_string, walk->serial_number);
|
||||
size_t slen = wcslen(walk->serial_number);
|
||||
if (slen >= serlen &&
|
||||
wcscmp(walk->serial_number + slen - serlen, wserno) == 0)
|
||||
if (slen >= serlen && wcscmp(walk->serial_number + slen - serlen, wserno) == 0)
|
||||
{
|
||||
/* found matching serial number */
|
||||
/* Found matching serial number */
|
||||
break;
|
||||
}
|
||||
pmsg_debug("usbhid_open(): serial number does not match\n");
|
||||
walk = walk->next;
|
||||
}
|
||||
if (walk == NULL)
|
||||
{
|
||||
if (walk == NULL) {
|
||||
pmsg_error("no matching device found\n");
|
||||
hid_free_enumeration(list);
|
||||
return -1;
|
||||
|
@ -121,17 +115,12 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
pmsg_debug("usbhid_open(): opening path %s\n", walk->path);
|
||||
dev = hid_open_path(walk->path);
|
||||
hid_free_enumeration(list);
|
||||
if (dev == NULL)
|
||||
{
|
||||
if (dev == NULL) {
|
||||
pmsg_error("found device, but hid_open_path() failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* No serial number requested, pass straight to hid_open()
|
||||
*/
|
||||
} else {
|
||||
/* No serial number requested, pass straight to hid_open() */
|
||||
dev = hid_open(pinfo.usbinfo.vid, pinfo.usbinfo.pid, NULL);
|
||||
if (dev == NULL)
|
||||
{
|
||||
|
@ -169,8 +158,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
* be incremented by one, as the report ID will be omitted by the
|
||||
* hidapi library.
|
||||
*/
|
||||
if (pinfo.usbinfo.vid == USB_VENDOR_ATMEL)
|
||||
{
|
||||
if (pinfo.usbinfo.vid == USB_VENDOR_ATMEL) {
|
||||
pmsg_debug("usbhid_open(): probing for max packet size\n");
|
||||
memset(usbbuf, 0, sizeof usbbuf);
|
||||
usbbuf[0] = 0; /* no HID reports used */
|
||||
|
@ -183,7 +171,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
memset(usbbuf, 0, sizeof usbbuf);
|
||||
int res = hid_read_timeout(dev, usbbuf, 10 /* bytes */, 50 /* milliseconds */);
|
||||
if (res == 0) {
|
||||
/* no timely response, assume 512 byte size */
|
||||
/* No timely response, assume 512 byte size */
|
||||
hid_write(dev, usbbuf, (512 - 64) + 1);
|
||||
fd->usb.max_xfer = 512;
|
||||
res = hid_read_timeout(dev, usbbuf, 10, 50);
|
||||
|
@ -211,8 +199,7 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void usbhid_close(union filedescriptor *fd)
|
||||
{
|
||||
static void usbhid_close(union filedescriptor *fd) {
|
||||
hid_device *udev = (hid_device *)fd->usb.handle;
|
||||
|
||||
if (udev == NULL)
|
||||
|
@ -222,22 +209,20 @@ static void usbhid_close(union filedescriptor *fd)
|
|||
}
|
||||
|
||||
|
||||
static int usbhid_send(const union filedescriptor *fd, const unsigned char *bp, size_t mlen)
|
||||
{
|
||||
static int usbhid_send(const union filedescriptor *fd, const unsigned char *bp, size_t mlen) {
|
||||
hid_device *udev = (hid_device *)fd->usb.handle;
|
||||
int rv;
|
||||
int i = mlen;
|
||||
const unsigned char * p = bp;
|
||||
unsigned char usbbuf[USBDEV_MAX_XFER_3 + 1];
|
||||
|
||||
|
||||
int tx_size;
|
||||
|
||||
if (udev == NULL)
|
||||
return -1;
|
||||
|
||||
tx_size = (mlen < USBDEV_MAX_XFER_3)? mlen: USBDEV_MAX_XFER_3;
|
||||
usbbuf[0] = 0; /* no report ID used */
|
||||
usbbuf[0] = 0; /* No report ID used */
|
||||
memcpy(usbbuf + 1, bp, tx_size);
|
||||
rv = hid_write(udev, usbbuf, tx_size + 1);
|
||||
if (rv < 0) {
|
||||
|
@ -247,18 +232,15 @@ static int usbhid_send(const union filedescriptor *fd, const unsigned char *bp,
|
|||
if (rv != tx_size + 1)
|
||||
pmsg_error("short write to USB: %d bytes out of %d written\n", rv, tx_size + 1);
|
||||
|
||||
if (verbose > 4)
|
||||
{
|
||||
if (verbose > 4) {
|
||||
pmsg_trace2("sent: ");
|
||||
|
||||
while (i) {
|
||||
unsigned char c = *p;
|
||||
if (isprint(c)) {
|
||||
if (isprint(c))
|
||||
msg_trace2("%c ", c);
|
||||
}
|
||||
else {
|
||||
else
|
||||
msg_trace2(". ");
|
||||
}
|
||||
msg_trace2("[%02x] ", c);
|
||||
|
||||
p++;
|
||||
|
@ -269,8 +251,7 @@ static int usbhid_send(const union filedescriptor *fd, const unsigned char *bp,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int usbhid_recv(const union filedescriptor *fd, unsigned char *buf, size_t nbytes)
|
||||
{
|
||||
static int usbhid_recv(const union filedescriptor *fd, unsigned char *buf, size_t nbytes) {
|
||||
hid_device *udev = (hid_device *)fd->usb.handle;
|
||||
int i, rv;
|
||||
unsigned char * p = buf;
|
||||
|
@ -282,18 +263,15 @@ static int usbhid_recv(const union filedescriptor *fd, unsigned char *buf, size_
|
|||
if (i != nbytes)
|
||||
pmsg_error("short read, read only %d out of %lu bytes\n", i, (unsigned long) nbytes);
|
||||
|
||||
if (verbose > 4)
|
||||
{
|
||||
if (verbose > 4) {
|
||||
pmsg_trace2("recv: ");
|
||||
|
||||
while (i) {
|
||||
unsigned char c = *p;
|
||||
if (isprint(c)) {
|
||||
if (isprint(c))
|
||||
msg_trace2("%c ", c);
|
||||
}
|
||||
else {
|
||||
else
|
||||
msg_trace2(". ");
|
||||
}
|
||||
msg_trace2("[%02x] ", c);
|
||||
|
||||
p++;
|
||||
|
@ -301,12 +279,10 @@ static int usbhid_recv(const union filedescriptor *fd, unsigned char *buf, size_
|
|||
}
|
||||
msg_trace2("\n");
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int usbhid_drain(const union filedescriptor *fd, int display)
|
||||
{
|
||||
static int usbhid_drain(const union filedescriptor *fd, int display) {
|
||||
/*
|
||||
* There is not much point in trying to flush any data
|
||||
* on an USB endpoint, as the endpoint is supposed to
|
||||
|
@ -324,8 +300,7 @@ static int usbhid_drain(const union filedescriptor *fd, int display)
|
|||
/*
|
||||
* Device descriptor.
|
||||
*/
|
||||
struct serial_device usbhid_serdev =
|
||||
{
|
||||
struct serial_device usbhid_serdev = {
|
||||
.open = usbhid_open,
|
||||
.close = usbhid_close,
|
||||
.send = usbhid_send,
|
||||
|
|
Loading…
Reference in New Issue