From e62503c873833b33c63585c6f0810b824e5c6a6b Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 6 Jan 2016 01:00:02 -0600 Subject: [Android] Add support for the Wii U Gamecube adapter under Android. No way to properly enable it from an end user perspective yet. Doesn't require root. This same sort of system can be used for the Dolphinbar in the future for real wiimote support. --- .../dolphinemu/utils/Java_GCAdapter.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Java_GCAdapter.java (limited to 'Source/Android/app/src/main/java') 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 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 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; + } + } + + } + } +} -- cgit v1.2.3