mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-06-20 21:12:38 +02:00
Added delay at the end of usbds_test(). Only send 1-byte in datapayload for the second msg. Minor adjustment. Removed invalid comment.
This commit is contained in:
parent
7f7564bff4
commit
a23a01c7bd
@ -6,7 +6,6 @@
|
||||
|
||||
//Example for usbds, see libnx usb.h. Switch-as-device<>host USB comms.
|
||||
//Linux detects this as a serial device.
|
||||
//Data transfer over USB works fine with this, however data isn't returned by "/dev/{device}" (depending on what is used for reading it) due to the header(?) from the device->host transfer not being valid.
|
||||
|
||||
Result usbds_test(u8 *tmpbuf)
|
||||
{
|
||||
@ -59,11 +58,12 @@ Result usbds_test(u8 *tmpbuf)
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
memset(tmpbuf, 0, 0x1000);
|
||||
tmpbuf[0] = 0x11;
|
||||
tmpbuf[1] = 0x1;
|
||||
char *strptr = "Hello World!\n";
|
||||
strncpy((char*)&tmpbuf[2], strptr, 0x1000-2);
|
||||
|
||||
tmpbuf[0] = 0x11;
|
||||
tmpbuf[1] = 0x1;
|
||||
|
||||
//Start a device->host transfer.
|
||||
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL);
|
||||
if(R_FAILED(ret))return ret;
|
||||
@ -85,13 +85,15 @@ Result usbds_test(u8 *tmpbuf)
|
||||
memcpy(&tmpbuf[2], &tmpbuf[0x400], 0x200-2);
|
||||
|
||||
//Start a device->host transfer.
|
||||
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x200, NULL);
|
||||
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x2+1, NULL);
|
||||
if(R_FAILED(ret))return ret;
|
||||
|
||||
//Wait for the transfer to finish.
|
||||
svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX);
|
||||
svcClearEvent(endpoint_in->CompletionEvent);
|
||||
|
||||
svcSleepThread(5000000000);//Delay 5s
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user