diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7bc01d9 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..b9b62aa --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + Sensor-Fusion-Demo + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b080d2d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..1d560f7 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index c521644..cc9bf55 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Sensor-Fusion Demo for Android +# Sensor fusion Demo for Android This application demonstrates the capabilities of various sensors and sensor-fusions. Data from the Gyroscope, Accelerometer and compass are combined in different ways and the result is shown as a cube that can be rotated by rotating the device. @@ -50,4 +50,6 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. + +This application also uses parts from the the Android Open Source Project, licensed under the [Apache License, Version 2.0]( http://www.apache.org/licenses/LICENSE-2.0). \ No newline at end of file diff --git a/ic_launcher-web.png b/ic_launcher-web.png new file mode 100644 index 0000000..a8bc5eb Binary files /dev/null and b/ic_launcher-web.png differ diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar new file mode 100644 index 0000000..cf12d28 Binary files /dev/null and b/libs/android-support-v4.jar differ diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..ce39f2d --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-18 diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..93027d2 Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..e66985e Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..ebb5191 Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..5dcc28d Binary files /dev/null and b/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml new file mode 100644 index 0000000..d9b6371 --- /dev/null +++ b/res/layout/activity_main.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/res/layout/activity_main_2.xml b/res/layout/activity_main_2.xml new file mode 100644 index 0000000..cf3f863 --- /dev/null +++ b/res/layout/activity_main_2.xml @@ -0,0 +1,8 @@ + + diff --git a/res/layout/fragment_main_activity2_dummy.xml b/res/layout/fragment_main_activity2_dummy.xml new file mode 100644 index 0000000..c8fbfe8 --- /dev/null +++ b/res/layout/fragment_main_activity2_dummy.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/res/layout/fragment_main_dummy.xml b/res/layout/fragment_main_dummy.xml new file mode 100644 index 0000000..e6854b5 --- /dev/null +++ b/res/layout/fragment_main_dummy.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/res/menu/main.xml b/res/menu/main.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/menu/main_activity2.xml b/res/menu/main_activity2.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/res/menu/main_activity2.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml new file mode 100644 index 0000000..44f01db --- /dev/null +++ b/res/values-sw600dp/dimens.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml new file mode 100644 index 0000000..61e3fa8 --- /dev/null +++ b/res/values-sw720dp-land/dimens.xml @@ -0,0 +1,9 @@ + + + + 128dp + + diff --git a/res/values-v11/styles.xml b/res/values-v11/styles.xml new file mode 100644 index 0000000..3c02242 --- /dev/null +++ b/res/values-v11/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/res/values-v14/styles.xml b/res/values-v14/styles.xml new file mode 100644 index 0000000..a91fd03 --- /dev/null +++ b/res/values-v14/styles.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..427b9ec --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Sensor fusion Demo + Settings + Sensor fusion Demo + + diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/src/org/hitlabnz/sensor_fusion_demo/RotationVector.java b/src/org/hitlabnz/sensor_fusion_demo/RotationVector.java new file mode 100644 index 0000000..fce8537 --- /dev/null +++ b/src/org/hitlabnz/sensor_fusion_demo/RotationVector.java @@ -0,0 +1,195 @@ +/* Copyright (C) 2007 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 org.hitlabnz.sensor_fusion_demo; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +import android.app.Activity; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.opengl.GLSurfaceView; +import android.os.Bundle; + +/** + * Wrapper activity demonstrating the use of the new {@link SensorEvent#values rotation vector sensor} ( + * {@link Sensor#TYPE_ROTATION_VECTOR TYPE_ROTATION_VECTOR}). + * + * @see Sensor + * @see SensorEvent + * @see SensorManager + * + */ +public class RotationVector extends Activity { + private GLSurfaceView mGLSurfaceView; + private SensorManager mSensorManager; + private MyRenderer mRenderer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Get an instance of the SensorManager + mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); + + // Create our Preview view and set it as the content of our + // Activity + mRenderer = new MyRenderer(); + mGLSurfaceView = new GLSurfaceView(this); + mGLSurfaceView.setRenderer(mRenderer); + setContentView(mGLSurfaceView); + } + + @Override + protected void onResume() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onResume(); + mRenderer.start(); + mGLSurfaceView.onResume(); + } + + @Override + protected void onPause() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onPause(); + mRenderer.stop(); + mGLSurfaceView.onPause(); + } + + class MyRenderer implements GLSurfaceView.Renderer, SensorEventListener { + private Cube mCube; + private Sensor mRotationVectorSensor; + private final float[] mRotationMatrix = new float[16]; + + public MyRenderer() { + // find the rotation-vector sensor + mRotationVectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); + + mCube = new Cube(); + // initialize the rotation matrix to identity + mRotationMatrix[0] = 1; + mRotationMatrix[4] = 1; + mRotationMatrix[8] = 1; + mRotationMatrix[12] = 1; + } + + public void start() { + // enable our sensor when the activity is resumed, ask for + // 10 ms updates. + mSensorManager.registerListener(this, mRotationVectorSensor, 10000); + } + + public void stop() { + // make sure to turn our sensor off when the activity is paused + mSensorManager.unregisterListener(this); + } + + public void onSensorChanged(SensorEvent event) { + // we received a sensor event. it is a good practice to check + // that we received the proper event + if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { + // convert the rotation-vector to a 4x4 matrix. the matrix + // is interpreted by Open GL as the inverse of the + // rotation-vector, which is what we want. + SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); + } + } + + public void onDrawFrame(GL10 gl) { + // clear screen + gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + + // set-up modelview matrix + gl.glMatrixMode(GL10.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0, 0, -3.0f); + gl.glMultMatrixf(mRotationMatrix, 0); + + // draw our object + gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); + gl.glEnableClientState(GL10.GL_COLOR_ARRAY); + + mCube.draw(gl); + } + + public void onSurfaceChanged(GL10 gl, int width, int height) { + // set view-port + gl.glViewport(0, 0, width, height); + // set projection matrix + float ratio = (float) width / height; + gl.glMatrixMode(GL10.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); + } + + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + // dither is enabled by default, we don't need it + gl.glDisable(GL10.GL_DITHER); + // clear screen in black + gl.glClearColor(0, 0, 0, 1); + } + + class Cube { + // initialize our cube + private FloatBuffer mVertexBuffer; + private FloatBuffer mColorBuffer; + private ByteBuffer mIndexBuffer; + + public Cube() { + final float vertices[] = { -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, + -1, 1, 1, }; + + final float colors[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 1, }; + + final byte indices[] = { 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4, 3, 4, 0, 4, 7, + 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 }; + + ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4); + vbb.order(ByteOrder.nativeOrder()); + mVertexBuffer = vbb.asFloatBuffer(); + mVertexBuffer.put(vertices); + mVertexBuffer.position(0); + + ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length * 4); + cbb.order(ByteOrder.nativeOrder()); + mColorBuffer = cbb.asFloatBuffer(); + mColorBuffer.put(colors); + mColorBuffer.position(0); + + mIndexBuffer = ByteBuffer.allocateDirect(indices.length); + mIndexBuffer.put(indices); + mIndexBuffer.position(0); + } + + public void draw(GL10 gl) { + gl.glEnable(GL10.GL_CULL_FACE); + gl.glFrontFace(GL10.GL_CW); + gl.glShadeModel(GL10.GL_SMOOTH); + gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); + gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer); + gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); + } + } + + public void onAccuracyChanged(Sensor sensor, int accuracy) { + } + } +} \ No newline at end of file