From 1ccf002bbf77b6eca97577292f65937f333fb70e Mon Sep 17 00:00:00 2001 From: surkeh Date: Tue, 15 Sep 2020 16:27:29 -0700 Subject: [PATCH] Submit transfer works, callbacks work. Need to interpret data --- hanvon-libusb.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/hanvon-libusb.c b/hanvon-libusb.c index 13cadb1..ec84956 100644 --- a/hanvon-libusb.c +++ b/hanvon-libusb.c @@ -68,7 +68,7 @@ struct hanvon { void callback(struct libusb_transfer *transfer) { int i = 0; for(; i < 10; i++) { - printf("%c, ", transfer -> buffer[i]); + printf("0x%x, ", transfer -> buffer[i]); } printf("placeholder\n"); } @@ -149,32 +149,32 @@ int main() return 0; } - printf("Got to this point\n"); - - // Wait and handle interrupts? - struct libusb_transfer tx; + struct libusb_transfer *tx; const int ENDPOINT_ADDR = 0x81; // bEndpointAddress from lsusb -v const unsigned int LEN = 10; // wMaxPacketSize from lsusb -v unsigned char buffer[LEN]; - // assign timeout of 1s, for any action is too much as is - libusb_fill_interrupt_transfer( &tx, + + // Allocate memory for transfer, configure, then submit + tx = libusb_alloc_transfer(0); + libusb_fill_interrupt_transfer( tx, h, ENDPOINT_ADDR, buffer, LEN, callback, NULL, - 130); // milliseconds + 130); // timeout in milliseconds + + do { + state = libusb_submit_transfer(tx); + if (state < 0 ) { + return state; + } + libusb_handle_events(NULL); + } while (1); - state = libusb_submit_transfer(&tx); - if (state < 0 ) { - return state; - } - for(;;) { - libusb_handle_events(NULL); - } return state; }