Processing, the ADK and accessory mode
in
Android Processing
•
2 years ago
Hi,
I recently got my hands on one of the new
Google ADK boards. I've done a lot of Processing work, but not a lot of straight Java or Android programing. (Although, I have started to learn Android).
I'm wondering if any one has made any progress in getting a processing sketch, running on Android, to speak to the ADK board via the accessory mode?
In the mean time, I was wondering if anyone had any advice on ways to tackle this problem.
Currently I've been trying something like this
- import android.hardware.usb;
- UsbAccessory mAccessory;
- ParcelFileDescriptor mFileDescriptor;
- FileInputStream mInputStream;
- FileOutputStream mOutputStream;
- float w, h;
- String[] fontList;
- PFont androidFont;
- void onResume() {
- super.onResume();
- println("RESUMED! (Sketch Entered...)");
- UsbAccessory accessory = UsbManager.getAccessory(intent);
- }
- void onPause() {
- println("PAUSED! (Sketch Exited...)");
- super.onPause();
- }
- private void openAccessory() {
- // Log.d(TAG, "openAccessory: " + accessory);
- mFileDescriptor = mUsbManager.openAccessory(mAccessory);
- if (mFileDescriptor != null) {
- FileDescriptor fd = mFileDescriptor.getFileDescriptor();
- mInputStream = new FileInputStream(fd);
- mOutputStream = new FileOutputStream(fd);
- Thread thread = new Thread(null, this, "AccessoryThread");
- thread.start();
- }
- }
- void setup() {
- size(screenWidth, screenHeight, A2D);
- w = screenWidth;
- h = screenHeight;
- orientation(PORTRAIT);
- // Setup Fonts:
- fontList = PFont.list();
- androidFont = createFont(fontList[0], 16, true);
- textFont(androidFont);
- }
- void draw() {
- fill(0);
- rect(0,0,w,h);
- fill(255);
- text("I LIVE",10,20);
- }
The tip of the problem is an error for the import android.hardware.usb; line.
Also, the manifest.xml file, ideally, needs to be updated (
see here for the official docs)
I've done this, which I know does not work:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package=""
- android:versionCode="1"
- android:versionName="1.0">
- <!-- <uses-sdk android:minSdkVersion="10" /> -->
- <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="11" />
- <uses-feature android:name="android.hardware.usb.accessory" />
- <application android:label=""
- android:icon="@drawable/icon"
- android:debuggable="true">
- <uses-library android:name="com.android.future.usb.accessory" />
- <activity android:name="">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
I'll keep hacking at it, but if you've got any advice for me, I'd love to hear it.
Thanks.
3