diff options
| author | Ryan Houdek <Sonicadvance1@gmail.com> | 2016-01-06 15:07:09 -0500 |
|---|---|---|
| committer | Ryan Houdek <Sonicadvance1@gmail.com> | 2016-01-06 15:07:09 -0500 |
| commit | 342496563dc2fd129c6ab3831b181eb0875f46d0 (patch) | |
| tree | cf10091da87c9c6c7ab3f5270bb96a7098d6052c /Source/Android/app/src/main/java | |
| parent | 87e753b104375d0983071f144638f98bef6ef719 (diff) | |
| parent | e62503c873833b33c63585c6f0810b824e5c6a6b (diff) | |
Merge pull request #3455 from Sonicadvance1/GC_adapter_android
[Android] Add support for the Wii U Gamecube adapter under Android.
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java new file mode 100644 index 0000000000..51d00ad348 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java @@ -0,0 +1,91 @@ +package org.dolphinemu.dolphinemu.utils; + +import android.app.Activity; +import android.hardware.usb.UsbConfiguration; +import android.hardware.usb.UsbConstants; +import android.hardware.usb.UsbDevice; +import android.hardware.usb.UsbDeviceConnection; +import android.hardware.usb.UsbEndpoint; +import android.hardware.usb.UsbInterface; +import android.hardware.usb.UsbManager; + +import java.util.HashMap; +import java.util.Iterator; + +public class Java_GCAdapter { + public static UsbManager manager; + public static Activity our_activity; + static byte[] controller_payload = new byte[37]; + static byte HasRead; + + static UsbDeviceConnection usb_con; + static UsbInterface usb_intf; + static UsbEndpoint usb_in; + static UsbEndpoint usb_out; + + public static void Shutdown() + { + usb_con.close(); + } + public static int GetFD() { return usb_con.getFileDescriptor(); } + + public static boolean QueryAdapter() + { + HashMap<String, UsbDevice> devices = manager.getDeviceList(); + Iterator it = devices.entrySet().iterator(); + while (it.hasNext()) + { + HashMap.Entry pair = (HashMap.Entry) it.next(); + UsbDevice dev = (UsbDevice) pair.getValue(); + if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e) + if (manager.hasPermission(dev)) + return true; + } + return false; + } + + public static void InitAdapter() + { + byte[] init = { 0x13 }; + usb_con.bulkTransfer(usb_in, init, init.length, 0); + } + + public static int Input() { + int read = usb_con.bulkTransfer(usb_in, controller_payload, controller_payload.length, 16); + return read; + } + + public static int Output(byte[] rumble) { + int size = usb_con.bulkTransfer(usb_out, rumble, 5, 16); + return size; + } + + public static void OpenAdapter() + { + HashMap<String, UsbDevice> devices = manager.getDeviceList(); + Iterator it = devices.entrySet().iterator(); + while (it.hasNext()) + { + HashMap.Entry pair = (HashMap.Entry)it.next(); + UsbDevice dev = (UsbDevice)pair.getValue(); + if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e) { + 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; + } + } + + } + } +} |
