mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-28 14:02:38 +00:00
Merge pull request #3626 from Sonicadvance1/more_robust_gcadapter
Improve stability of the Wii U Gamecube Controller adapter under Android.
This commit is contained in:
commit
c82feb6c08
2 changed files with 128 additions and 99 deletions
|
@ -9,6 +9,7 @@ import android.hardware.usb.UsbDeviceConnection;
|
|||
import android.hardware.usb.UsbEndpoint;
|
||||
import android.hardware.usb.UsbInterface;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.services.USBPermService;
|
||||
|
@ -76,32 +77,16 @@ public class Java_GCAdapter {
|
|||
}
|
||||
|
||||
public static int Input() {
|
||||
if (usb_in != null)
|
||||
{
|
||||
int read = usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
|
||||
return read;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Is this right?
|
||||
return 0;
|
||||
}
|
||||
int read = usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16);
|
||||
return read;
|
||||
}
|
||||
|
||||
public static int Output(byte[] rumble) {
|
||||
if (usb_out != null)
|
||||
{
|
||||
int size = usb_con.bulkTransfer(usb_out, rumble, 5, 16);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Is this right?
|
||||
return 0;
|
||||
}
|
||||
int size = usb_con.bulkTransfer(usb_out, rumble, 5, 16);
|
||||
return size;
|
||||
}
|
||||
|
||||
public static void OpenAdapter()
|
||||
public static boolean OpenAdapter()
|
||||
{
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
Iterator it = devices.entrySet().iterator();
|
||||
|
@ -113,20 +98,47 @@ public class Java_GCAdapter {
|
|||
if (manager.hasPermission(dev))
|
||||
{
|
||||
usb_con = manager.openDevice(dev);
|
||||
UsbConfiguration conf = dev.getConfiguration(0);
|
||||
usb_intf = conf.getInterface(0);
|
||||
usb_con.claimInterface(usb_intf, true);
|
||||
for (int i = 0; i < usb_intf.getEndpointCount(); ++i)
|
||||
if (usb_intf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
|
||||
usb_in = usb_intf.getEndpoint(i);
|
||||
else
|
||||
usb_out = usb_intf.getEndpoint(i);
|
||||
|
||||
InitAdapter();
|
||||
return;
|
||||
Log.info("GCAdapter: Number of configurations: " + dev.getConfigurationCount());
|
||||
Log.info("GCAdapter: Number of interfaces: " + dev.getInterfaceCount());
|
||||
|
||||
if (dev.getConfigurationCount() > 0 && dev.getInterfaceCount() > 0)
|
||||
{
|
||||
UsbConfiguration conf = dev.getConfiguration(0);
|
||||
usb_intf = conf.getInterface(0);
|
||||
usb_con.claimInterface(usb_intf, true);
|
||||
|
||||
Log.info("GCAdapter: Number of endpoints: " + usb_intf.getEndpointCount());
|
||||
|
||||
if (usb_intf.getEndpointCount() == 2)
|
||||
{
|
||||
for (int i = 0; i < usb_intf.getEndpointCount(); ++i)
|
||||
if (usb_intf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
|
||||
usb_in = usb_intf.getEndpoint(i);
|
||||
else
|
||||
usb_out = usb_intf.getEndpoint(i);
|
||||
|
||||
InitAdapter();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_con.releaseInterface(usb_intf);
|
||||
}
|
||||
}
|
||||
|
||||
NativeLibrary.sEmulationActivity.runOnUiThread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Toast.makeText(NativeLibrary.sEmulationActivity, "GameCube Adapter couldn't be opened. Please re-plug the device.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
usb_con.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue