ABC2011 Summer デ部 Joysticks and Gamepads, USB Host

7,168 views
7,066 views

Published on

Published in: Technology, News & Politics
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,168
On SlideShare
0
From Embeds
0
Number of Embeds
3,445
Actions
Shares
0
Downloads
16
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

ABC2011 Summer デ部 Joysticks and Gamepads, USB Host

  1. 1. 3.1 Joysticks and Gamepads (@v vakame) Android appengine2011 7 17
  2. 2. HID2011 7 17
  3. 3. Joystick Gamepad ...2011 7 17
  4. 4. ↑↑2011 7 17
  5. 5. • Activity GenericMotionEvent • on dispatch • KeyEvent • GenericMotionEvent • MotionEvent#getHistoricalXXX USB Keyboard Mouse ↑↑2011 7 17
  6. 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. 7. 3.1 USB Host @vvakame2011 7 17
  8. 8. USB Host • Android Device • • Android Host • • LED … Android2011 7 17
  9. 9. API ADK2011 7 17
  10. 10. • UsbManager • UsbManager UsbDevice • UsbDevice UsbInterface • UsbInterface UsbEndpoint • UsbEndpoint • UsbDeviceConnection AndroidManifest USB Intent2011 7 17
  11. 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. 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); Web2011 7 17
  13. 13. http://amzn.to/glitterpanel2011 7 17

×