Más contenido relacionado
Más de Masahiro Wakame (20)
ABC2011 Summer デ部 Joysticks and Gamepads, USB Host
- 5. • Activity GenericMotionEvent
• on dispatch
• KeyEvent
• GenericMotionEvent
•
MotionEvent#getHistoricalXXX
USB Keyboard Mouse
↑↑
2011 7 17
- 6. public class MainActivity extends Activity {
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
Log.d("Joysticks", "x=" + x + ", y=" + y);
return super.dispatchGenericMotionEvent(event);
}
}
( )
2011 7 17
- 7. 3.1
USB Host
@vvakame
2011 7 17
- 8. USB Host
• Android Device
•
• Android Host
•
• LED
…
Android
2011 7 17
- 10. • UsbManager
• UsbManager UsbDevice
• UsbDevice UsbInterface
• UsbInterface UsbEndpoint
• UsbEndpoint
• UsbDeviceConnection
AndroidManifest
USB Intent
2011 7 17
- 11. AndroidManifest.xml
<manifest ...>
<application ...>
<activity ...>
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity>
</application>
<uses-sdk android:minSdkVersion="12" />
<uses-feature android:name="android.hardware.usb.host" />
</manifest>
/res/xml/device_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="3888" product-id="64" />
</resources>
2011 7 17
- 12. UsbManager usbManager;
UsbDevice usbDevice;
{ //
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
usbDevice = usbManager.getDeviceList().get("/dev/hogehoge");
}
{ //
// getIntent().getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED);
usbDevice = (UsbDevice) getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);
}
UsbInterface usbInterface = usbDevice.getInterface(0);
UsbEndpoint usbEndpoint = usbInterface.getEndpoint(0);
UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(usbDevice);
usbDeviceConnection.claimInterface(usbInterface, true);
usbDeviceConnection.bulkTransfer(usbEndpoint, ..., 100, 1000);
Web
2011 7 17