Add callback, callback doesnt fire

This commit is contained in:
surkeh 2020-08-17 20:14:42 -07:00
parent 65a378a469
commit b841132264

View File

@ -65,16 +65,21 @@ struct hanvon {
char phys[32]; char phys[32];
}; };
void callback(struct libusb_transfer *transfer) {
int i = 0;
for(; i < 10; i++) {
printf("%c, ", transfer -> buffer[i]);
}
printf("placeholder\n");
}
libusb_device *FindHanvon( libusb_context **context); libusb_device *FindHanvon( libusb_context **context);
int HandleData( void ); int HandleData( void );
int main() int main()
{ {
libusb_context **context; libusb_context *context;
libusb_device *device; libusb_device *device;
libusb_device_handle *handle; libusb_device_handle *handle;
@ -82,7 +87,7 @@ int main()
if( state != STATE_SUCCESS ) if( state != STATE_SUCCESS )
return state; return state;
device = FindHanvon( context ); device = FindHanvon(& context );
if( device == NULL ) if( device == NULL )
return STATE_NOT_FOUND; return STATE_NOT_FOUND;
@ -92,7 +97,28 @@ int main()
// Wait and handle interrupts? // Wait and handle interrupts?
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,
handle,
ENDPOINT_ADDR,
buffer,
LEN,
callback,
NULL,
130); // milliseconds
state = libusb_submit_transfer(&tx);
if( state != STATE_SUCCESS )
return state;
for(;;) {
libusb_handle_events(context);
}
return state; return state;
} }