aboutsummaryrefslogtreecommitdiff
path: root/demokit
diff options
context:
space:
mode:
Diffstat (limited to 'demokit')
-rw-r--r--demokit/app/Android.mk28
-rw-r--r--demokit/app/AndroidManifest.xml50
-rw-r--r--demokit/app/res/drawable-hdpi/droid_off.pngbin2291 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-hdpi/droid_on.pngbin3765 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-hdpi/greenball.pngbin4423 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-hdpi/icon.pngbin5950 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-hdpi/redball.pngbin4357 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-ldpi/droid_off.pngbin1607 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-ldpi/droid_on.pngbin2191 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-ldpi/greenball.pngbin2521 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-ldpi/icon.pngbin3196 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-ldpi/redball.pngbin2487 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-mdpi/droid_off.pngbin1806 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-mdpi/droid_on.pngbin2607 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-mdpi/greenball.pngbin4423 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-mdpi/icon.pngbin4025 -> 0 bytes
-rw-r--r--demokit/app/res/drawable-mdpi/redball.pngbin4357 -> 0 bytes
-rw-r--r--demokit/app/res/layout/main.xml88
-rw-r--r--demokit/app/res/values/strings.xml34
-rw-r--r--demokit/app/res/xml/accessory_filter.xml18
-rw-r--r--demokit/app/src/com/google/DemoKit/DemoKitActivity.java531
-rw-r--r--demokit/app/src/com/google/DemoKit/UsbAccessoryActivity.java46
-rw-r--r--demokit/demokit.pde405
23 files changed, 0 insertions, 1200 deletions
diff --git a/demokit/app/Android.mk b/demokit/app/Android.mk
deleted file mode 100644
index 293c212..0000000
--- a/demokit/app/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := DemoKit
-
-LOCAL_JAVA_LIBRARIES := com.android.future.usb.accessory
-
-include $(BUILD_PACKAGE)
diff --git a/demokit/app/AndroidManifest.xml b/demokit/app/AndroidManifest.xml
deleted file mode 100644
index d873887..0000000
--- a/demokit/app/AndroidManifest.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.google.DemoKit"
- android:versionCode="1"
- android:versionName="1.0">
-
- <uses-sdk android:targetSdkVersion="11" />
-
- <application android:label="DemoKit"
- android:icon="@drawable/icon"
- android:hardwareAccelerated="true">
- <uses-library android:name="com.android.future.usb.accessory" />
-
- <activity android:name="DemoKitActivity"
- android:label="DemoKit">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
- <!-- This activity receives USB_ACCESSORY_ATTACHED Intents and springboards to main Gallery activity. -->
- <activity android:name="UsbAccessoryActivity" android:label="DemoKit"
- android:taskAffinity=""
- android:launchMode="singleInstance">
- <intent-filter>
- <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
- </intent-filter>
-
- <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
- android:resource="@xml/accessory_filter" />
- </activity>
-
- </application>
-</manifest>
diff --git a/demokit/app/res/drawable-hdpi/droid_off.png b/demokit/app/res/drawable-hdpi/droid_off.png
deleted file mode 100644
index c908bf8..0000000
--- a/demokit/app/res/drawable-hdpi/droid_off.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-hdpi/droid_on.png b/demokit/app/res/drawable-hdpi/droid_on.png
deleted file mode 100644
index 0bd2390..0000000
--- a/demokit/app/res/drawable-hdpi/droid_on.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-hdpi/greenball.png b/demokit/app/res/drawable-hdpi/greenball.png
deleted file mode 100644
index 7851232..0000000
--- a/demokit/app/res/drawable-hdpi/greenball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-hdpi/icon.png b/demokit/app/res/drawable-hdpi/icon.png
deleted file mode 100644
index 0496e35..0000000
--- a/demokit/app/res/drawable-hdpi/icon.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-hdpi/redball.png b/demokit/app/res/drawable-hdpi/redball.png
deleted file mode 100644
index fba2f5d..0000000
--- a/demokit/app/res/drawable-hdpi/redball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-ldpi/droid_off.png b/demokit/app/res/drawable-ldpi/droid_off.png
deleted file mode 100644
index 75a1bf6..0000000
--- a/demokit/app/res/drawable-ldpi/droid_off.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-ldpi/droid_on.png b/demokit/app/res/drawable-ldpi/droid_on.png
deleted file mode 100644
index 41dd449..0000000
--- a/demokit/app/res/drawable-ldpi/droid_on.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-ldpi/greenball.png b/demokit/app/res/drawable-ldpi/greenball.png
deleted file mode 100644
index 3a814fc..0000000
--- a/demokit/app/res/drawable-ldpi/greenball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-ldpi/icon.png b/demokit/app/res/drawable-ldpi/icon.png
deleted file mode 100644
index ee36e96..0000000
--- a/demokit/app/res/drawable-ldpi/icon.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-ldpi/redball.png b/demokit/app/res/drawable-ldpi/redball.png
deleted file mode 100644
index 6e0add3..0000000
--- a/demokit/app/res/drawable-ldpi/redball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-mdpi/droid_off.png b/demokit/app/res/drawable-mdpi/droid_off.png
deleted file mode 100644
index e7fcabf..0000000
--- a/demokit/app/res/drawable-mdpi/droid_off.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-mdpi/droid_on.png b/demokit/app/res/drawable-mdpi/droid_on.png
deleted file mode 100644
index 121f517..0000000
--- a/demokit/app/res/drawable-mdpi/droid_on.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-mdpi/greenball.png b/demokit/app/res/drawable-mdpi/greenball.png
deleted file mode 100644
index 7851232..0000000
--- a/demokit/app/res/drawable-mdpi/greenball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-mdpi/icon.png b/demokit/app/res/drawable-mdpi/icon.png
deleted file mode 100644
index b01345c..0000000
--- a/demokit/app/res/drawable-mdpi/icon.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/drawable-mdpi/redball.png b/demokit/app/res/drawable-mdpi/redball.png
deleted file mode 100644
index fba2f5d..0000000
--- a/demokit/app/res/drawable-mdpi/redball.png
+++ /dev/null
Binary files differ
diff --git a/demokit/app/res/layout/main.xml b/demokit/app/res/layout/main.xml
deleted file mode 100644
index 4becaa0..0000000
--- a/demokit/app/res/layout/main.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:addStatesFromChildren="true">
- <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_gravity="center_vertical" android:orientation="vertical" android:showDividers="beginning|middle|end" android:layout_weight="1" android:layout_height="wrap_content" android:baselineAligned="false" android:gravity="center_vertical" android:layout_marginBottom="8dip">
- <TextView android:id="@+id/textView17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/buttons" android:layout_marginRight="8dip"></TextView>
- <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:verticalScrollbarPosition="right" android:layout_width="match_parent" android:layout_gravity="fill_horizontal">
- <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="@string/button1" android:layout_gravity="center_vertical" android:layout_marginRight="8dip"></TextView>
- <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/droid_off" android:id="@+id/button1Image"></ImageView>
- </LinearLayout>
- <LinearLayout android:id="@+id/linearLayout5" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content" android:id="@+id/textView2" android:layout_height="wrap_content" android:text="@string/button2" android:layout_gravity="center_vertical" android:layout_marginRight="8dip"></TextView>
- <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/droid_off" android:id="@+id/button2Image"></ImageView>
- </LinearLayout>
- <LinearLayout android:id="@+id/linearLayout6" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content" android:id="@+id/textView3" android:layout_height="wrap_content" android:text="@string/button3" android:layout_gravity="center_vertical" android:layout_marginRight="8dip"></TextView>
- <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/droid_off" android:id="@+id/button3Image"></ImageView>
- </LinearLayout>
- </TableRow>
- <TableRow android:id="@+id/tableRow14" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:id="@+id/textView19" android:layout_height="wrap_content" android:layout_width="wrap_content"></TextView>
- <TextView android:id="@+id/textView20" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center_horizontal" android:text="@string/led1"></TextView>
- <TextView android:layout_gravity="center_horizontal" android:id="@+id/textView21" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/led2"></TextView>
- <TextView android:layout_gravity="center_horizontal" android:id="@+id/textView22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/led3"></TextView>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow4" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center_vertical" android:layout_marginBottom="8dip">
- <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:text="@string/red"></TextView>
- <SeekBar android:layout_height="wrap_content" android:max="255" android:id="@+id/led1Red" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led2Red" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led3Red" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow5" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center_vertical" android:layout_marginBottom="8dip">
- <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:text="@string/green"></TextView>
- <SeekBar android:layout_height="wrap_content" android:max="255" android:id="@+id/led1Green" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led2Green" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led3Green" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow6" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center_vertical" android:layout_marginBottom="8dip">
- <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:text="@string/blue"></TextView>
- <SeekBar android:layout_height="wrap_content" android:max="255" android:id="@+id/led1Blue" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led2Blue" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- <SeekBar android:id="@+id/led3Blue" android:layout_height="wrap_content" android:max="255" android:layout_marginRight="16dip" android:layout_width="250dip"></SeekBar>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow2" android:layout_width="match_parent" android:layout_weight="1" android:gravity="center_vertical" android:layout_marginBottom="8dip">
- <TextView android:id="@+id/textView18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/relays" android:layout_marginRight="8dip"></TextView>
- <LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:text="@string/relay1" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip"></TextView>
- <ToggleButton android:text="ToggleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/relay1Button"></ToggleButton>
- </LinearLayout>
- <LinearLayout android:id="@+id/linearLayout7" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content" android:id="@+id/textView14" android:layout_height="wrap_content" android:text="@string/relay2" android:layout_marginRight="8dip"></TextView>
- <ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:layout_height="wrap_content" android:id="@+id/relay2Button"></ToggleButton>
- </LinearLayout>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow3" android:layout_width="match_parent" android:layout_weight="1" android:layout_marginBottom="8dip">
- <TextView android:text="@string/temperature" android:id="@+id/textView15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip"></TextView>
- <TextView android:id="@+id/temperature" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
- </TableRow>
- <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow13" android:layout_width="match_parent" android:layout_weight="1" android:layout_marginBottom="8dip">
- <TextView android:text="@string/light" android:id="@+id/textView16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dip"></TextView>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/light"></TextView>
- </TableRow>
- <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_marginRight="8dip" android:id="@+id/textView8" android:layout_width="wrap_content" android:text="@string/servos" android:layout_height="wrap_content"></TextView>
- <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:id="@+id/servo1" android:max="255" android:progress="127"></SeekBar>
- <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:id="@+id/servo2" android:max="255" android:progress="127"></SeekBar>
- <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="8dip" android:id="@+id/servo3" android:max="255" android:progress="127"></SeekBar>
- </TableRow>
- <TableRow android:layout_width="match_parent" android:id="@+id/tableRow8" android:layout_height="wrap_content">
- <TextView android:id="@+id/textView9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/joystick"></TextView>
- <LinearLayout android:id="@+id/linearLayout3" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content" android:id="@+id/textView10" android:layout_height="wrap_content" android:text="@string/x" android:layout_marginRight="8dip"></TextView>
- <TextView android:layout_width="wrap_content" android:id="@+id/joyX" android:layout_height="wrap_content"></TextView>
- </LinearLayout>
- <LinearLayout android:id="@+id/linearLayout4" android:layout_width="wrap_content" android:layout_height="wrap_content">
- <TextView android:layout_width="wrap_content" android:id="@+id/textView12" android:layout_height="wrap_content" android:text="@string/y" android:layout_marginRight="8dip"></TextView>
- <TextView android:layout_width="wrap_content" android:id="@+id/joyY" android:layout_height="wrap_content"></TextView>
- </LinearLayout>
- </TableRow>
- <TableRow android:layout_width="match_parent" android:id="@+id/tableRow9" android:layout_height="wrap_content">
- <TextView android:id="@+id/textView11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/cap"></TextView>
- <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="left" android:src="@drawable/redball" android:id="@+id/cap"></ImageView>
- </TableRow>
- </TableLayout>
-
-</LinearLayout>
diff --git a/demokit/app/res/values/strings.xml b/demokit/app/res/values/strings.xml
deleted file mode 100644
index 54be6eb..0000000
--- a/demokit/app/res/values/strings.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="hello">Hello World, DemoKitActivity!</string>
- <string name="app_name">DemoKit</string>
- <string name="button1">1</string>
- <string name="button2">2</string>
- <string name="button3">3</string>
- <string name="led1Red">Led 1 Red</string>
- <string name="led1Green">Led 1 Green</string>
- <string name="led1Blue">Led 1 Blue</string>
- <string name="led2Red">Led 2 Red</string>
- <string name="led2Green">Led 2 Green</string>
- <string name="led2Blue">Led 2 Blue</string>
- <string name="led3Red">Led 3 Red</string>
- <string name="led3Green">Led 3 Green</string>
- <string name="led3Blue">Led 3 Blue</string>
- <string name="relay1">1</string>
- <string name="relay2">2</string>
- <string name="temperature">Temperature</string>
- <string name="light">Light</string>
- <string name="buttons">Buttons</string>
- <string name="relays">Relays</string>
- <string name="led1">Led 1</string>
- <string name="led2">Led 2</string>
- <string name="led3">Led 3</string>
- <string name="red">Red</string>
- <string name="green">Green</string>
- <string name="blue">Blue</string>
- <string name="servos">Servos</string>
- <string name="x">X</string>
- <string name="y">Y</string>
- <string name="joystick">Joystick</string>
- <string name="cap">Cap Button</string>
-</resources>
diff --git a/demokit/app/res/xml/accessory_filter.xml b/demokit/app/res/xml/accessory_filter.xml
deleted file mode 100644
index 5631b03..0000000
--- a/demokit/app/res/xml/accessory_filter.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<resources>
- <usb-accessory manufacturer="Google, Inc." model="DemoKit" version="1.0" />
-</resources>
diff --git a/demokit/app/src/com/google/DemoKit/DemoKitActivity.java b/demokit/app/src/com/google/DemoKit/DemoKitActivity.java
deleted file mode 100644
index 338276f..0000000
--- a/demokit/app/src/com/google/DemoKit/DemoKitActivity.java
+++ /dev/null
@@ -1,531 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.DemoKit;
-
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.ParcelFileDescriptor;
-import android.util.Log;
-
-import android.widget.ImageView;
-import android.widget.TextView;
-import android.widget.SeekBar;
-import android.widget.ToggleButton;
-import android.widget.CompoundButton;
-import android.graphics.drawable.Drawable;
-
-import com.android.future.usb.UsbAccessory;
-import com.android.future.usb.UsbManager;
-
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-
-public class DemoKitActivity extends Activity implements Runnable, SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener {
- private static final String TAG = "DemoKit";
-
- private static final String ACTION_USB_PERMISSION =
- "com.google.DemoKit.action.USB_PERMISSION";
-
- private UsbManager mUsbManager;
- private PendingIntent mPermissionIntent;
- private boolean mPermissionRequestPending;
-
- UsbAccessory mAccessory;
- ParcelFileDescriptor mFileDescriptor;
- FileInputStream mInputStream;
- FileOutputStream mOutputStream;
-
- ImageView mButton1Image;
- ImageView mButton2Image;
- ImageView mButton3Image;
-
- SeekBar mLed1Red;
- SeekBar mLed1Green;
- SeekBar mLed1Blue;
- SeekBar mLed2Red;
- SeekBar mLed2Green;
- SeekBar mLed2Blue;
- SeekBar mLed3Red;
- SeekBar mLed3Green;
- SeekBar mLed3Blue;
-
- ToggleButton mRelay1Button;
- ToggleButton mRelay2Button;
-
- TextView mTemperature;
- TextView mLight;
-
- SeekBar mServo1;
- SeekBar mServo2;
- SeekBar mServo3;
-
- TextView mJoyX;
- TextView mJoyY;
-
- ImageView mCap;
-
-
- Drawable mSwitchOff;
- Drawable mSwitchOn;
-
- private static final int MESSAGE_SWITCH = 1;
- private static final int MESSAGE_TEMPERATURE = 2;
- private static final int MESSAGE_LIGHT = 3;
- private static final int MESSAGE_JOY = 4;
-
- private class SwitchMsg {
- private byte sw;
- private byte state;
- public SwitchMsg(byte sw, byte state) {
- this.sw = sw;
- this.state = state;
- }
-
- public byte getSw() {
- return sw;
- }
-
- public byte getState() {
- return state;
- }
- }
-
- private class TemperatureMsg {
- private int temperature;
-
- public TemperatureMsg(int temperature) {
- this.temperature = temperature;
- }
-
- public int getTemperature() {
- return temperature;
- }
- }
-
- private class LightMsg {
- private int light;
-
- public LightMsg(int light) {
- this.light = light;
- }
-
- public int getLight() {
- return light;
- }
- }
-
- private class JoyMsg {
- private int x;
- private int y;
-
- public JoyMsg(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- public int getX() {
- return x;
- }
-
- public int getY() {
- return y;
- }
- }
-
- private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (ACTION_USB_PERMISSION.equals(action)) {
- synchronized (this) {
- UsbAccessory accessory = UsbManager.getAccessory(intent);
- if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
- openAccessory(accessory);
- } else {
- Log.d(TAG, "permission denied for accessory " + accessory);
- }
- mPermissionRequestPending = false;
- }
- } else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
- UsbAccessory accessory = UsbManager.getAccessory(intent);
- if (accessory != null && accessory.equals(mAccessory)) {
- closeAccessory();
- }
- }
- }
- };
-
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mUsbManager = UsbManager.getInstance(this);
- mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
- IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
- filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
- registerReceiver(mUsbReceiver, filter);
-
- setContentView(R.layout.main);
-
- mButton1Image = (ImageView)findViewById(R.id.button1Image);
- mButton2Image = (ImageView)findViewById(R.id.button2Image);
- mButton3Image = (ImageView)findViewById(R.id.button3Image);
-
- mLed1Red = (SeekBar)findViewById(R.id.led1Red);
- mLed1Red.setOnSeekBarChangeListener(this);
- mLed1Green = (SeekBar)findViewById(R.id.led1Green);
- mLed1Green.setOnSeekBarChangeListener(this);
- mLed1Blue = (SeekBar)findViewById(R.id.led1Blue);
- mLed1Blue.setOnSeekBarChangeListener(this);
-
- mLed2Red = (SeekBar)findViewById(R.id.led2Red);
- mLed2Red.setOnSeekBarChangeListener(this);
- mLed2Green = (SeekBar)findViewById(R.id.led2Green);
- mLed2Green.setOnSeekBarChangeListener(this);
- mLed2Blue = (SeekBar)findViewById(R.id.led2Blue);
- mLed2Blue.setOnSeekBarChangeListener(this);
-
- mLed3Red = (SeekBar)findViewById(R.id.led3Red);
- mLed3Red.setOnSeekBarChangeListener(this);
- mLed3Green = (SeekBar)findViewById(R.id.led3Green);
- mLed3Green.setOnSeekBarChangeListener(this);
- mLed3Blue = (SeekBar)findViewById(R.id.led3Blue);
- mLed3Blue.setOnSeekBarChangeListener(this);
-
- mRelay1Button = (ToggleButton)findViewById(R.id.relay1Button);
- mRelay1Button.setOnCheckedChangeListener(this);
- mRelay2Button = (ToggleButton)findViewById(R.id.relay2Button);
- mRelay2Button.setOnCheckedChangeListener(this);
-
- mTemperature = (TextView)findViewById(R.id.temperature);
- mLight = (TextView)findViewById(R.id.light);
-
- mServo1 = (SeekBar)findViewById(R.id.servo1);
- mServo1.setOnSeekBarChangeListener(this);
- mServo2 = (SeekBar)findViewById(R.id.servo2);
- mServo2.setOnSeekBarChangeListener(this);
- mServo3 = (SeekBar)findViewById(R.id.servo3);
- mServo3.setOnSeekBarChangeListener(this);
-
- mJoyX = (TextView)findViewById(R.id.joyX);
- mJoyY = (TextView)findViewById(R.id.joyY);
-
- mCap = (ImageView)findViewById(R.id.cap);
-
- mSwitchOff = getResources().getDrawable(R.drawable.droid_off);
- mSwitchOn = getResources().getDrawable(R.drawable.droid_on);
-
- enableControls(false);
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- Intent intent = getIntent();
- Log.d(TAG, "intent: " + intent);
- UsbAccessory[] accessories = mUsbManager.getAccessoryList();
- UsbAccessory accessory = (accessories == null ? null : accessories[0]);
- if (accessory != null) {
- if (mUsbManager.hasPermission(accessory)) {
- openAccessory(accessory);
- } else {
- synchronized (mUsbReceiver) {
- if (!mPermissionRequestPending) {
- mUsbManager.requestPermission(accessory, mPermissionIntent);
- mPermissionRequestPending = true;
- }
- }
- }
- } else {
- Log.d(TAG, "mAccessory is null");
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- closeAccessory();
- }
-
- @Override
- public void onDestroy() {
- unregisterReceiver(mUsbReceiver);
- super.onDestroy();
- }
-
- private void openAccessory(UsbAccessory accessory) {
- Log.d(TAG, "openAccessory: " + accessory);
- mFileDescriptor = mUsbManager.openAccessory(accessory);
- if (mFileDescriptor != null) {
- mAccessory = accessory;
- FileDescriptor fd = mFileDescriptor.getFileDescriptor();
- mInputStream = new FileInputStream(fd);
- mOutputStream = new FileOutputStream(fd);
- Thread thread = new Thread(null, this, "AccessoryChat");
- thread.start();
- Log.d(TAG, "openAccessory succeeded");
- enableControls(true);
- } else {
- Log.d(TAG, "openAccessory fail");
- }
- }
-
- private void closeAccessory() {
- enableControls(false);
-
- mButton1Image.setImageDrawable(mSwitchOff);
- mButton2Image.setImageDrawable(mSwitchOff);
- mButton3Image.setImageDrawable(mSwitchOff);
- mCap.setImageDrawable(mSwitchOff);
- mLed1Red.setProgress(0);
- mLed1Green.setProgress(0);
- mLed1Blue.setProgress(0);
- mLed2Red.setProgress(0);
- mLed2Green.setProgress(0);
- mLed2Blue.setProgress(0);
- mLed3Red.setProgress(0);
- mLed3Green.setProgress(0);
- mLed3Blue.setProgress(0);
- mServo1.setProgress(0);
- mServo2.setProgress(0);
- mServo3.setProgress(0);
- mTemperature.setText("");
- mLight.setText("");
- mJoyX.setText("");
- mJoyY.setText("");
- mRelay1Button.setChecked(false);
- mRelay2Button.setChecked(false);
-
- try {
- if (mFileDescriptor != null) {
- mFileDescriptor.close();
- }
- } catch (IOException e) {
- } finally {
- mFileDescriptor = null;
- mAccessory = null;
- }
- }
-
- private void enableControls(boolean enable) {
- mLed1Red.setEnabled(enable);
- mLed1Green.setEnabled(enable);
- mLed1Blue.setEnabled(enable);
- mLed2Red.setEnabled(enable);
- mLed2Green.setEnabled(enable);
- mLed2Blue.setEnabled(enable);
- mLed3Red.setEnabled(enable);
- mLed3Green.setEnabled(enable);
- mLed3Blue.setEnabled(enable);
- mServo1.setEnabled(enable);
- mServo2.setEnabled(enable);
- mServo3.setEnabled(enable);
- mRelay1Button.setEnabled(enable);
- mRelay2Button.setEnabled(enable);
- }
-
- private int composeInt(byte hi, byte lo) {
- int val = (int)hi & 0xff;
- val *= 256;
- val += (int)lo & 0xff;
- return val;
- }
-
- public void run() {
- int ret = 0;
- byte[] buffer = new byte[16384];
- int i;
-
- while (ret >= 0) {
- try {
- ret = mInputStream.read(buffer);
- } catch (IOException e) {
- break;
- }
-
- Log.d(TAG, "got bytes " + ret);
- i = 0;
- while (i < ret) {
- int len = ret - i;
-
- switch (buffer[i]) {
- case 0x1:
- if (len >= 3) {
- Message m = Message.obtain(mHandler, MESSAGE_SWITCH);
- m.obj = new SwitchMsg(buffer[i+1], buffer[i+2]);
- mHandler.sendMessage(m);
- }
- i += 3;
- break;
-
- case 0x4:
- if (len >= 3) {
- Message m = Message.obtain(mHandler, MESSAGE_TEMPERATURE);
- m.obj = new TemperatureMsg(composeInt(buffer[i+1], buffer[i+2]));
- mHandler.sendMessage(m);
- }
- i += 3;
- break;
-
- case 0x5:
- if (len >= 3) {
- Message m = Message.obtain(mHandler, MESSAGE_LIGHT);
- m.obj = new LightMsg(composeInt(buffer[i+1], buffer[i+2]));
- mHandler.sendMessage(m);
- }
- i += 3;
- break;
-
- case 0x6:
- if (len >= 3) {
- Message m = Message.obtain(mHandler, MESSAGE_JOY);
- m.obj = new JoyMsg(buffer[i+1], buffer[i+2]);
- mHandler.sendMessage(m);
- }
- i += 3;
- break;
-
- default:
- Log.d(TAG, "unknown msg: " + buffer[i]);
- i = len;
- break;
- }
- }
-
- }
- Log.d(TAG, "thread out");
- }
-
- Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MESSAGE_SWITCH:
- SwitchMsg o = (SwitchMsg)msg.obj;
- if (o.getSw() == 0)
- mButton1Image.setImageDrawable(o.getState() != 0 ? mSwitchOn : mSwitchOff);
- else if (o.getSw() == 1)
- mButton2Image.setImageDrawable(o.getState() != 0 ? mSwitchOn : mSwitchOff);
- else if (o.getSw() == 2)
- mButton3Image.setImageDrawable(o.getState() != 0 ? mSwitchOn : mSwitchOff);
- else if (o.getSw() == 3)
- mCap.setImageDrawable(o.getState() != 0 ? mSwitchOn : mSwitchOff);
- break;
-
- case MESSAGE_TEMPERATURE:
- TemperatureMsg t = (TemperatureMsg)msg.obj;
- mTemperature.setText(String.format("%04x", t.getTemperature()));
- break;
-
- case MESSAGE_LIGHT:
- LightMsg l = (LightMsg)msg.obj;
- mLight.setText(String.format("%04x", l.getLight()));
- break;
-
- case MESSAGE_JOY:
- JoyMsg j = (JoyMsg)msg.obj;
- mJoyX.setText(String.format("%d", j.getX()));
- mJoyY.setText(String.format("%d", j.getY()));
- break;
-
- }
- }
- };
-
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- byte[] buffer = new byte[3];
- if (progress > 255)
- progress = 255;
-
- buffer[0] = 0x2;
- buffer[1] = -1;
- buffer[2] = (byte) progress;
-
- if (seekBar == mLed1Red)
- buffer[1] = 0x0;
- else if (seekBar == mLed1Green)
- buffer[1] = 0x1;
- else if (seekBar == mLed1Blue)
- buffer[1] = 0x2;
- else if (seekBar == mLed2Red)
- buffer[1] = 0x3;
- else if (seekBar == mLed2Green)
- buffer[1] = 0x4;
- else if (seekBar == mLed2Blue)
- buffer[1] = 0x5;
- else if (seekBar == mLed3Red)
- buffer[1] = 0x6;
- else if (seekBar == mLed3Green)
- buffer[1] = 0x7;
- else if (seekBar == mLed3Blue)
- buffer[1] = 0x8;
- else if (seekBar == mServo1)
- buffer[1] = 0x10;
- else if (seekBar == mServo2)
- buffer[1] = 0x11;
- else if (seekBar == mServo3)
- buffer[1] = 0x12;
-
- if (buffer[1] != -1) {
- try {
- mOutputStream.write(buffer);
- } catch (IOException e) {
- Log.e(TAG, "write failed", e);
- }
- }
-
- }
-
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
-
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- byte[] buffer = new byte[3];
- buffer[0] = 0x3;
- buffer[1] = -1;
- buffer[2] = isChecked ? (byte)0x1 : (byte)0x0;
-
- if (buttonView == mRelay1Button)
- buffer[1] = 0;
- else if (buttonView == mRelay2Button)
- buffer[1] = 1;
-
- if (buffer[1] != -1) {
- try {
- mOutputStream.write(buffer);
- } catch (IOException e) {
- Log.e(TAG, "write failed", e);
- }
- }
- }
-}
-
diff --git a/demokit/app/src/com/google/DemoKit/UsbAccessoryActivity.java b/demokit/app/src/com/google/DemoKit/UsbAccessoryActivity.java
deleted file mode 100644
index d451e38..0000000
--- a/demokit/app/src/com/google/DemoKit/UsbAccessoryActivity.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.DemoKit;
-
-
-import android.app.Activity;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-
-/* This Activity does nothing but receive USB_DEVICE_ATTACHED events from the
- * USB service and springboards to the main Gallery activity
- */
-public final class UsbAccessoryActivity extends Activity {
-
- static final String TAG = "UsbAccessoryActivity";
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Intent intent = new Intent(this, DemoKitActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException e) {
- Log.e(TAG, "unable to start DemoKit activity", e);
- }
- finish();
- }
-}
diff --git a/demokit/demokit.pde b/demokit/demokit.pde
deleted file mode 100644
index 5a4d29a..0000000
--- a/demokit/demokit.pde
+++ /dev/null
@@ -1,405 +0,0 @@
-#include <Wire.h>
-#include <Servo.h>
-
-#include <Max3421e.h>
-#include <Usb.h>
-#include <AndroidAccessory.h>
-
-#define LED3_RED 2
-#define LED3_GREEN 4
-#define LED3_BLUE 3
-
-#define LED2_RED 5
-#define LED2_GREEN 7
-#define LED2_BLUE 6
-
-#define LED1_RED 8
-#define LED1_GREEN 10
-#define LED1_BLUE 9
-
-#define SERVO1 11
-#define SERVO2 12
-#define SERVO3 13
-
-#define TOUCH 14
-
-#define RELAY1 A0
-#define RELAY2 A1
-
-#define LIGHT_SENSOR A2
-#define TEMP_SENSOR A3
-
-#define BUTTON1 A6
-#define BUTTON2 A7
-#define BUTTON3 A8
-
-#define JOY_SWITCH A9 // pulls line down when pressed
-#define JOY_nINT A10 // active low interrupt input
-#define JOY_nRESET A11 // active low reset output
-
-AndroidAccessory acc("Google, Inc.",
- "DemoKit",
- "DemoKit Arduino Board",
- "1.0",
- "http://www.android.com",
- "0000000012345678");
-Servo servos[3];
-
-void setup();
-void loop();
-
-void init_buttons()
-{
- pinMode( BUTTON1, INPUT );
- pinMode( BUTTON2, INPUT );
- pinMode( BUTTON3, INPUT );
-
- digitalWrite( BUTTON1, HIGH ); // enable the internal pullups
- digitalWrite( BUTTON2, HIGH );
- digitalWrite( BUTTON3, HIGH );
-}
-
-
-void init_relays()
-{
- pinMode( RELAY1, OUTPUT );
- pinMode( RELAY2, OUTPUT );
-}
-
-
-void init_leds()
-{
- digitalWrite( LED1_RED, 1 );
- digitalWrite( LED1_GREEN, 1 );
- digitalWrite( LED1_BLUE, 1 );
-
- pinMode( LED1_RED, OUTPUT );
- pinMode( LED1_GREEN, OUTPUT );
- pinMode( LED1_BLUE, OUTPUT );
-
- digitalWrite( LED2_RED, 1 );
- digitalWrite( LED2_GREEN, 1 );
- digitalWrite( LED2_BLUE, 1 );
-
- pinMode( LED2_RED, OUTPUT );
- pinMode( LED2_GREEN, OUTPUT );
- pinMode( LED2_BLUE, OUTPUT );
-
- digitalWrite( LED3_RED, 1 );
- digitalWrite( LED3_GREEN, 1 );
- digitalWrite( LED3_BLUE, 1 );
-
- pinMode( LED3_RED, OUTPUT );
- pinMode( LED3_GREEN, OUTPUT );
- pinMode( LED3_BLUE, OUTPUT );
-}
-
-void init_joystick( int threshold );
-
-byte b1, b2, b3, c;
-void setup()
-{
- Serial.begin( 115200 );
- Serial.print("\r\nStart");
-
- init_leds();
- init_relays();
- init_buttons();
- init_joystick( 5 ); // initialize with thresholding enabled, dead zone of 5 units
-
-
- servos[0].attach(SERVO1);
- servos[0].write(90);
- servos[1].attach(SERVO2);
- servos[1].write(90);
- servos[2].attach(SERVO3);
- servos[2].write(90);
-
-
- b1 = digitalRead(BUTTON1);
- b2 = digitalRead(BUTTON2);
- b3 = digitalRead(BUTTON3);
- c = captouched();
-
- acc.powerOn();
-}
-
-void loop()
-{
- byte err;
- byte idle;
- static byte count = 0;
- byte msg[3];
-
- if (acc.isConnected()) {
- int len = acc.read(msg, sizeof(msg), 1);
- int i;
- byte b;
- uint16_t val;
- int x, y;
- char c0;
-
- if (len > 0) {
- // XXX: assumes only one command per packet
- Serial.print(msg[0], HEX);
- Serial.print(":");
- Serial.print(msg[1], HEX);
- Serial.print(":");
- Serial.println(msg[2], HEX);
- if (msg[0] == 0x2) {
- if (msg[1] == 0x0)
- analogWrite( LED1_RED, 255 - msg[2]);
- else if (msg[1] == 0x1)
- analogWrite( LED1_GREEN, 255 - msg[2]);
- else if (msg[1] == 0x2)
- analogWrite( LED1_BLUE, 255 - msg[2]);
- else if (msg[1] == 0x3)
- analogWrite( LED2_RED, 255 - msg[2]);
- else if (msg[1] == 0x4)
- analogWrite( LED2_GREEN, 255 - msg[2]);
- else if (msg[1] == 0x5)
- analogWrite( LED2_BLUE, 255 - msg[2]);
- else if (msg[1] == 0x6)
- analogWrite( LED3_RED, 255 - msg[2]);
- else if (msg[1] == 0x7)
- analogWrite( LED3_GREEN, 255 - msg[2]);
- else if (msg[1] == 0x8)
- analogWrite( LED3_BLUE, 255 - msg[2]);
- else if (msg[1] == 0x10)
- servos[0].write(map(msg[2], 0, 255, 0, 180));
- else if (msg[1] == 0x11)
- servos[1].write(map(msg[2], 0, 255, 0, 180));
- else if (msg[1] == 0x12)
- servos[2].write(map(msg[2], 0, 255, 0, 180));
- } else if (msg[0] == 0x3) {
- if (msg[1] == 0x0)
- digitalWrite( RELAY1, msg[2] ? HIGH : LOW );
- else if (msg[1] == 0x1)
- digitalWrite( RELAY2, msg[2] ? HIGH : LOW );
-
- }
-
- }
-
- msg[0] = 0x1;
-
- b = digitalRead(BUTTON1);
- if (b != b1) {
- msg[1] = 0;
- msg[2] = b ? 0 : 1;
- acc.write(msg, 3);
- b1 = b;
- }
-
- b = digitalRead(BUTTON2);
- if (b != b2) {
- msg[1] = 1;
- msg[2] = b ? 0 : 1;
- acc.write(msg, 3);
- b2 = b;
- }
-
- b = digitalRead(BUTTON3);
- if (b != b3) {
- msg[1] = 2;
- msg[2] = b ? 0 : 1;
- acc.write(msg, 3);
- b3 = b;
- }
-
- switch (count++ % 0x10) {
-
- case 0:
- val = analogRead(TEMP_SENSOR);
- msg[0] = 0x4;
- msg[1] = val >> 8;
- msg[2] = val & 0xff;
- acc.write(msg, 3);
- break;
-
- case 0x4:
- val = analogRead(LIGHT_SENSOR);
- msg[0] = 0x5;
- msg[1] = val >> 8;
- msg[2] = val & 0xff;
- acc.write(msg, 3);
- break;
-
- case 0x8:
- read_joystick(&x, &y);
- msg[0] = 0x6;
- msg[1] = constrain(x, -128, 127);
- msg[2] = constrain(y, -128, 127);
- acc.write(msg, 3);
- break;
-
-#if 0
- /* captoutched needs to be asynchonous */
- case 0xc:
- c0 = captouched();
- if (c0 != c) {
- msg[0] = 0x1;
- msg[1] = 3;
- msg[2] = c0 ? 0 : 1;
- acc.write(msg, 3);
- c = c0;
- }
- break;
-#endif
- }
- }
-
- delay(10);
-}
-
-// ==============================================================================
-// Austria Microsystems i2c Joystick
-
-/*
- If a threshold is provided, the dead zone will be programmed such that interrupts will not
- be generated unless the threshold is exceeded.
-
- Note that if you use that mode, you will have to use passage of time with no new interrupts
- to detect that the stick has been released and has returned to center.
-
- If you need to explicitly track return to center, pass 0 as the threshold. "Center" will
- still bounce around a little
-*/
-
-
-void init_joystick( int threshold )
-{
- byte status = 0;
-
- pinMode( JOY_SWITCH, INPUT );
- digitalWrite( JOY_SWITCH, HIGH ); // enable the internal pullup
-
- pinMode( JOY_nINT, INPUT );
- digitalWrite( JOY_nINT, HIGH ); // enable the internal pullup
-
- pinMode( JOY_nRESET, OUTPUT );
-
- digitalWrite( JOY_nRESET, 1 );
- delay(1);
- digitalWrite( JOY_nRESET, 0 );
- delay(1);
- digitalWrite( JOY_nRESET, 1 );
-
- Wire.begin();
-
- do {
- status = read_joy_reg( 0x0f ); // XXX need timeout
- } while ((status & 0xf0) != 0xf0);
-
- write_joy_reg( 0x2e, 0x86 ); // invert magnet polarity setting, per datasheet
-
- calibrate_joystick( threshold ); // calibrate & set up dead zone area
-}
-
-
-int offset_X, offset_Y;
-
-void calibrate_joystick( int dz )
-{
- char iii;
- int x_cal = 0;
- int y_cal = 0;
-
- write_joy_reg( 0x0f, 0x00 ); // Low Power Mode, 20ms auto wakeup
- // INTn output enabled
- // INTn active after each measurement
- // Normal (non-Reset) mode
- delay(1);
-
- read_joy_reg( 0x11 ); // dummy read of Y_reg to reset interrupt
-
- for( iii = 0; iii != 16; iii++ ) { // read coords 16 times & average
- while( !joystick_interrupt() ) // poll for interrupt
- ;
- x_cal += read_joy_reg( 0x10 ); // X pos
- y_cal += read_joy_reg( 0x11 ); // Y pos
- }
-
- offset_X = -(x_cal>>4); // divide by 16 to get average
- offset_Y = -(y_cal>>4);
-
- //sprintf(msgbuf, "offsets = %d, %d\n", offset_X, offset_Y);
- //Serial.print(msgbuf);
-
- write_joy_reg( 0x12, dz - offset_X ); // Xp, LEFT threshold for INTn
- write_joy_reg( 0x13, -dz - offset_X ); // Xn, RIGHT threshold for INTn
- write_joy_reg( 0x14, dz - offset_Y ); // Yp, UP threshold for INTn
- write_joy_reg( 0x15, -dz - offset_Y ); // Yn, DOWN threshold for INTn
-
- if ( dz ) // dead zone threshold detect requested?
- write_joy_reg( 0x0f, 0x04 ); // Low Power Mode, 20ms auto wakeup
- // INTn output enabled
- // INTn active when movement exceeds dead zone
- // Normal (non-Reset) mode
-}
-
-
-void read_joystick( int *x, int *y )
-{
- *x = read_joy_reg( 0x10 ) + offset_X;
- *y = read_joy_reg( 0x11 ) + offset_Y; // reading Y clears the interrupt
-}
-
-char joystick_interrupt()
-{
- return ( digitalRead( JOY_nINT ) == 0 );
-}
-
-
-#define JOY_I2C_ADDR 0x40
-
-char read_joy_reg( char reg_addr )
-{
- char c;
-
- Wire.beginTransmission( JOY_I2C_ADDR );
- Wire.send( reg_addr );
- Wire.endTransmission();
-
- Wire.requestFrom( JOY_I2C_ADDR, 1 );
-
- while(Wire.available())
- c = Wire.receive();
-
- return c;
-}
-
-void write_joy_reg( char reg_addr, char val )
-{
- Wire.beginTransmission( JOY_I2C_ADDR );
- Wire.send( reg_addr );
- Wire.send( val );
- Wire.endTransmission();
-}
-
-/* Capacitive touch technique from Mario Becker, Fraunhofer IGD, 2007 http://www.igd.fhg.de/igd-a4 */
-
-char captouched()
-{
- char iii, jjj, retval;
-
- retval = 0;
-
- for( jjj = 0; jjj != 10; jjj++ ) {
- delay( 10 );
-
- pinMode( TOUCH, INPUT );
- digitalWrite( TOUCH, HIGH );
-
- for ( iii = 0; iii < 16; iii++ )
- if( digitalRead( TOUCH ) )
- break;
-
- digitalWrite( TOUCH, LOW );
- pinMode( TOUCH, OUTPUT );
-
- retval += iii;
- }
-
- return retval;
-}