From 31b3ac1c67ff7654d294e9dce0a3c3bbc9514774 Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Fri, 10 Feb 2017 22:11:54 +0100 Subject: [PATCH] move iso.c to transfer.c, as it's used for all transfers. move transfer callback to transfer.go. --- usb/iso.go | 7 ------- usb/{iso.c => transfer.c} | 14 ++------------ usb/transfer.go | 6 ++++++ 3 files changed, 8 insertions(+), 19 deletions(-) rename usb/{iso.c => transfer.c} (92%) diff --git a/usb/iso.go b/usb/iso.go index e29d4a6..01a9062 100644 --- a/usb/iso.go +++ b/usb/iso.go @@ -23,15 +23,8 @@ import "C" import ( "log" "time" - "unsafe" ) -//export transfer_callback -func transfer_callback(cptr unsafe.Pointer) { - ch := *(*chan struct{})(cptr) - close(ch) -} - func isochronous_xfer(e *endpoint, buf []byte, timeout time.Duration) (int, error) { t, err := e.newUSBTransfer(TRANSFER_TYPE_ISOCHRONOUS, buf) if err != nil { diff --git a/usb/iso.c b/usb/transfer.c similarity index 92% rename from usb/iso.c rename to usb/transfer.c index 6aac81b..14585e6 100644 --- a/usb/iso.c +++ b/usb/transfer.c @@ -18,25 +18,15 @@ #include void print_xfer(struct libusb_transfer *xfer); -void transfer_callback(void *); +void xfer_callback(void *); void callback(struct libusb_transfer *xfer) { - //printf("Callback!\n"); - //print_xfer(xfer); - transfer_callback(xfer->user_data); + xfer_callback(xfer->user_data); } int submit(struct libusb_transfer *xfer) { xfer->callback = &callback; xfer->status = -1; - //print_xfer(xfer); - //printf("Transfer submitted\n"); - - /* fake - strcpy(xfer->buffer, "hello"); - xfer->actual_length = 5; - callback(xfer); - return 0; */ return libusb_submit_transfer(xfer); } diff --git a/usb/transfer.go b/usb/transfer.go index 8e447d3..4018ba2 100644 --- a/usb/transfer.go +++ b/usb/transfer.go @@ -29,6 +29,12 @@ import ( "unsafe" ) +//export xfer_callback +func xfer_callback(cptr unsafe.Pointer) { + ch := *(*chan struct{})(cptr) + close(ch) +} + type usbTransfer struct { xfer *C.struct_libusb_transfer pkts []*C.struct_libusb_packet_descriptor