Contenu connexe
Similaire à USB Host APIで遊んでみた
Similaire à USB Host APIで遊んでみた (20)
Plus de Makoto Yamazaki (13)
USB Host APIで遊んでみた
- 2. • (@zaki50)
•
• Android
( StickyShortcut)
A3
- 4. USB Host
Android 3.1 Platform highlights
• Honeycomb 3.1
• OS
(HID Mass
Storage)
•
(
)
- 7. • : USB
UsbDeviceConnection
• : UsbDeviceConnection
- 8. • Intent
(IntentFilter )
•
(listDevices )
- 9. IntentFilter
AndroidManifest.xml
<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" />
res/device_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1234" product-id="5678" />
</resources>
- 11. private static final String ACTION_USB_PERMISSION = "hogehoge.USB_PERMISSION";
• IntentFilter private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
final UsbDevice device = (UsbDevice) intent
• BroadcastReceiver .getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (!intent.getBooleanExtra(UsbManager
.EXTRA_PERMISSION_GRANTED, false)) {
Log.i(TAG, "USB Permission denied");
PrintActivity.this.setResult(Activity.RESULT_CANCELED);
PrintActivity.this.finish();
return;
}
//
requestPermission }
}
}
};
//
registerReceiver(mUsbReceiver, new IntentFilter(ACTION_USB_PERMISSION));
final PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(
ACTION_USB_PERMISSION), 0);
mManager.requestPermission(device, pi);
- 12. USB
• vendor ID product ID
• Interface
• interface Endpoint
• Endpoint ( / )
- 13. Endpoint
• Control
↓
• Interrupt http://ja.wikipedia.org/wiki/
Universal_Serial_Bus
• Bulk
• Isochronous
- 15. UsbEndpoint endpoint = ...; // Endpoint
byte[] buffer = ...;
int timeoutMillis = 5000;
final int sent = conn.bulkTransfer(endpoint, buffer,
buffer.length, timeoutMillis);
•
• buffer offset
- 16. UsbDeviceConnection conn = ...;
UsbEndpoint in = ...;
ByteBuffer recvBuffer = ByteBuffer.allocate(in.getMaxPacketSize());
UsbRequest recvReq = new UsbRequest();
recvReq.initialize(conn, in); // Endpoint
while (true) {
recvReq.queue(recvBuffer, recvBuffer.remaining()); //
UsbRequest request = conn.requestWait(); //
if (request != recvReq) {
//
break;
}
// recvBuffer
}
- 19. • @touchRL
twitter RFID
• Windows
• Mac
- 22. • DevGuide (USB - Host)
http://developer.android.com/guide/topics/usb/host.html
•
http://developer.android.com/resources/samples/USB/
index.html
• (github)
• RL-700S http://goo.gl/fFA93
• RL-700S http://goo.gl/rV7TZ
Notes de l'éditeur
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n