From: Michael Gernoth Date: Sun, 7 Jul 2013 20:04:56 +0000 (+0200) Subject: add and export function to send only a null frame X-Git-Tag: v0.100~76 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/commitdiff_plain/2a6eaefc7786a666d27c52a8e9bb0c1c4aeb2843 add and export function to send only a null frame --- diff --git a/hmcfgusb.c b/hmcfgusb.c index 1ba9b24..ce8c595 100644 --- a/hmcfgusb.c +++ b/hmcfgusb.c @@ -140,6 +140,20 @@ static libusb_device_handle *hmcfgusb_find() { return NULL; } +int hmcfgusb_send_null_frame(struct hmcfgusb_dev *usbdev) +{ + int err; + int cnt; + + err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, NULL, 0, &cnt, USB_TIMEOUT); + if (err) { + fprintf(stderr, "Can't send data: %s\n", usb_strerror(err)); + return 0; + } + + return 1; +} + int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len, int done) { int err; @@ -159,9 +173,7 @@ int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len } if (done) { - err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, send_data, 0, &cnt, USB_TIMEOUT); - if (err) { - fprintf(stderr, "Can't send data: %s\n", usb_strerror(err)); + if (!hmcfgusb_send_null_frame(usbdev)) { return 0; } } diff --git a/hmcfgusb.h b/hmcfgusb.h index 8a0751a..e50f831 100644 --- a/hmcfgusb.h +++ b/hmcfgusb.h @@ -32,6 +32,7 @@ struct hmcfgusb_dev { }; int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len, int done); +int hmcfgusb_send_null_frame(struct hmcfgusb_dev *usbdev); struct hmcfgusb_dev *hmcfgusb_init(hmcfgusb_cb_fn cb, void *data); int hmcfgusb_add_pfd(struct hmcfgusb_dev *dev, int fd, short events); int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout);