diff --git a/Android/angel-sample-app/angel-sdk-debug/angel-sdk-debug.aar b/Android/angel-sample-app/angel-sdk-debug/angel-sdk-debug.aar index 4545a44..ecea408 100644 Binary files a/Android/angel-sample-app/angel-sdk-debug/angel-sdk-debug.aar and b/Android/angel-sample-app/angel-sdk-debug/angel-sdk-debug.aar differ diff --git a/Android/angel-sample-app/build.gradle b/Android/angel-sample-app/build.gradle index 84517e0..b41ba41 100644 --- a/Android/angel-sample-app/build.gradle +++ b/Android/angel-sample-app/build.gradle @@ -4,15 +4,15 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3+' + classpath 'com.android.tools.build:gradle:2.1.0' } } -apply plugin: 'android' +apply plugin: 'com.android.application' android { compileSdkVersion 19 - buildToolsVersion "19.1" + buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 18 diff --git a/Android/angel-sample-app/gradle/wrapper/gradle-wrapper.properties b/Android/angel-sample-app/gradle/wrapper/gradle-wrapper.properties index 4161ffa..969570f 100644 --- a/Android/angel-sample-app/gradle/wrapper/gradle-wrapper.properties +++ b/Android/angel-sample-app/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Jul 19 09:42:07 IDT 2015 +#Fri May 13 14:34:46 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/Android/angel-sample-app/src/main/java/com/angel/sample_app/HomeActivity.java b/Android/angel-sample-app/src/main/java/com/angel/sample_app/HomeActivity.java index 5ee1175..6e3aea1 100644 --- a/Android/angel-sample-app/src/main/java/com/angel/sample_app/HomeActivity.java +++ b/Android/angel-sample-app/src/main/java/com/angel/sample_app/HomeActivity.java @@ -47,6 +47,7 @@ import com.angel.sdk.ChAccelerationEnergyMagnitude; import com.angel.sdk.ChAccelerationWaveform; import com.angel.sdk.ChBatteryLevel; +import com.angel.sdk.ChGyroscopeWaveform; import com.angel.sdk.ChHeartRateMeasurement; import com.angel.sdk.ChOpticalWaveform; import com.angel.sdk.ChStepCount; @@ -88,6 +89,12 @@ public void run() { mBlueOpticalWaveformView.setStrokeColor(0xffffffff); mAccelerationWaveformView = (GraphView) findViewById(R.id.graph_acceleration); mAccelerationWaveformView.setStrokeColor(0xfff7a300); + mGyroscopeXWaveformView = (GraphView) findViewById(R.id.graph_gyro_x); + mGyroscopeXWaveformView.setStrokeColor(0xfff7a300); + mGyroscopeYWaveformView = (GraphView) findViewById(R.id.graph_gyro_y); + mGyroscopeYWaveformView.setStrokeColor(0xfff7a300); + mGyroscopeZWaveformView = (GraphView) findViewById(R.id.graph_gyro_z); + mGyroscopeZWaveformView.setStrokeColor(0xfff7a300); } } @@ -173,6 +180,7 @@ private void connect(String deviceAddress) { public void onBluetoothServicesDiscovered(BleDevice bleDevice) { bleDevice.getService(SrvWaveformSignal.class).getAccelerationWaveform().enableNotifications(mAccelerationWaveformListener); bleDevice.getService(SrvWaveformSignal.class).getOpticalWaveform().enableNotifications(mOpticalWaveformListener); + bleDevice.getService(SrvWaveformSignal.class).getGyroscopeWaveform().enableNotifications(mGyroscopeWaveformListener); } @Override @@ -231,6 +239,22 @@ public void onValueReady(ChAccelerationWaveform.AccelerationWaveformValue accele } }; + private final BleCharacteristic.ValueReadyCallback mGyroscopeWaveformListener = new BleCharacteristic.ValueReadyCallback() { + @Override + public void onValueReady(ChGyroscopeWaveform.GyroscopeWaveformValue gyroscopeWaveformValue) { + if (gyroscopeWaveformValue != null && gyroscopeWaveformValue.wave != null + && mGyroscopeXWaveformView != null + && mGyroscopeYWaveformView != null + && mGyroscopeZWaveformView != null) + for (ChGyroscopeWaveform.GyroscopeXYZValues item : gyroscopeWaveformValue.wave) { + mGyroscopeXWaveformView.addValue(item.getX()); + mGyroscopeYWaveformView.addValue(item.getY()); + mGyroscopeZWaveformView.addValue(item.getZ()); + } + + } + }; + private final BleCharacteristic.ValueReadyCallback mOpticalWaveformListener = new BleCharacteristic.ValueReadyCallback() { @Override public void onValueReady(ChOpticalWaveform.OpticalWaveformValue opticalWaveformValue) { @@ -387,6 +411,20 @@ private void displayAccelerationEnergyMagnitude(final int accelerationEnergyMagn imageView.startAnimation(effect); } + private void displayGyroscopeWaveForm(final int accelerationEnergyMagnitude) { + TextView textView = (TextView) findViewById(R.id.textview_acceleration); + Assert.assertNotNull(textView); + textView.setText(accelerationEnergyMagnitude + "g"); + + ScaleAnimation effect = new ScaleAnimation(1f, 0.5f, 1f, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); + effect.setDuration(ANIMATION_DURATION); + effect.setRepeatMode(Animation.REVERSE); + effect.setRepeatCount(1); + + View imageView = findViewById(R.id.imageview_acceleration); + imageView.startAnimation(effect); + } + private void displayOnDisconnect() { displaySignalStrength(-99); displayBatteryLevel(0); @@ -406,6 +444,7 @@ private void unscheduleUpdaters() { private int orientation; private GraphView mAccelerationWaveformView, mBlueOpticalWaveformView, mGreenOpticalWaveformView; + private GraphView mGyroscopeXWaveformView,mGyroscopeYWaveformView,mGyroscopeZWaveformView; private BleDevice mBleDevice; private String mBleDeviceAddress; diff --git a/Android/angel-sample-app/src/main/res/layout-land/activity_measurements.xml b/Android/angel-sample-app/src/main/res/layout-land/activity_measurements.xml index 6dd849c..d6a71f0 100644 --- a/Android/angel-sample-app/src/main/res/layout-land/activity_measurements.xml +++ b/Android/angel-sample-app/src/main/res/layout-land/activity_measurements.xml @@ -68,4 +68,70 @@ android:layout_alignParentBottom="true" android:id="@+id/view_line_3" /> + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/angel-sdk/gradle/wrapper/gradle-wrapper.properties b/Android/angel-sdk/gradle/wrapper/gradle-wrapper.properties index 0c71e76..698664d 100644 --- a/Android/angel-sdk/gradle/wrapper/gradle-wrapper.properties +++ b/Android/angel-sdk/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Fri May 13 13:39:49 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip diff --git a/Android/angel-sdk/src/main/java/com/angel/sdk/ChGyroscopeWaveform.java b/Android/angel-sdk/src/main/java/com/angel/sdk/ChGyroscopeWaveform.java new file mode 100644 index 0000000..13d42b5 --- /dev/null +++ b/Android/angel-sdk/src/main/java/com/angel/sdk/ChGyroscopeWaveform.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015, Seraphim Sense Ltd. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.angel.sdk; + +import android.bluetooth.BluetoothGattCharacteristic; +import android.util.Log; + +import java.util.ArrayList; +import java.util.UUID; + +public class ChGyroscopeWaveform extends BleCharacteristic { + public final static UUID CHARACTERISTIC_UUID = UUID.fromString("5df14ec3-fed1-4428-83bf-28ade00b0d98"); + private String TAG = ChGyroscopeWaveform.class.getSimpleName(); + + public ChGyroscopeWaveform(BluetoothGattCharacteristic gattCharacteristic, BleDevice bleDevice) { + super(CHARACTERISTIC_UUID, gattCharacteristic, bleDevice); + } + + public ChGyroscopeWaveform() { + super(CHARACTERISTIC_UUID); + } + + @Override + protected GyroscopeWaveformValue processCharacteristicValue() { + GyroscopeWaveformValue result = new GyroscopeWaveformValue(); + + BluetoothGattCharacteristic ch = getBaseGattCharacteristic(); + byte[] buffer = ch.getValue(); + + final int SAMPLE_SIZE = 6; + for (int i = SAMPLE_SIZE - 1; i < buffer.length; i += SAMPLE_SIZE) { + + int x = ((unsignedByte(buffer[i - 5]) << 8) | unsignedByte(buffer[i - 4])); + int y = ((unsignedByte(buffer[i - 3]) << 8) | unsignedByte(buffer[i - 2])); + int z = ((unsignedByte(buffer[i - 1]) << 8) | unsignedByte(buffer[i])); + + GyroscopeXYZValues xyz = new GyroscopeXYZValues(convertGyro(x), convertGyro(y), convertGyro(z)); + + //Log.d(TAG, String.format("X=%f, Y=%f, Z=%f", xyz.getX(), xyz.getY(), xyz.getZ())); + result.wave.add(xyz); + } + + return result; + } + + //Based on the Experiment02.pdf + private float convertGyro(int gyro) { + float samplingRate = 100.0f; // Hz + float sensitivity = 500.0f; // deg/sec + int halfRange = 2 << 15;// 16-bit signed value + + return gyro * sensitivity / halfRange / samplingRate; + } + + public class GyroscopeWaveformValue { + public ArrayList wave = new ArrayList(); + } + + public class GyroscopeXYZValues { + private float mX; + private float mY; + private float mZ; + + public GyroscopeXYZValues(float x, float y, float z) { + mX = x; + mY = y; + mZ = z; + } + + public float getX() { + return mX; + } + + public float getY() { + return mY; + } + + public float getZ() { + return mZ; + } + } + + + private static int unsignedByte(byte x) { + return x & 0xFF; + } +} diff --git a/Android/angel-sdk/src/main/java/com/angel/sdk/SrvWaveformSignal.java b/Android/angel-sdk/src/main/java/com/angel/sdk/SrvWaveformSignal.java index 29fb509..c9cc301 100644 --- a/Android/angel-sdk/src/main/java/com/angel/sdk/SrvWaveformSignal.java +++ b/Android/angel-sdk/src/main/java/com/angel/sdk/SrvWaveformSignal.java @@ -39,7 +39,6 @@ public class SrvWaveformSignal extends BleService { public final static UUID SERVICE_UUID = UUID.fromString("481d178c-10dd-11e4-b514-b2227cce2b54"); - public SrvWaveformSignal(BluetoothGattService gattService, BleDevice bleDevice) { super(SERVICE_UUID, gattService, bleDevice); @@ -50,6 +49,7 @@ public SrvWaveformSignal(BluetoothGattService gattService, BleDevice bleDevice) // we have mistakes with the definition of one of the characteristics mOpticalWaveform = createAndRegisterCharacteristic(ChOpticalWaveform.class); mAccelerationWaveform = createAndRegisterCharacteristic(ChAccelerationWaveform.class); + mGyroscopeWaveform = createAndRegisterCharacteristic(ChGyroscopeWaveform.class); } catch (InstantiationException e) { throw new AssertionError(); } catch (IllegalAccessException e) { @@ -61,8 +61,8 @@ public SrvWaveformSignal(BluetoothGattService gattService, BleDevice bleDevice) } catch (InvocationTargetException e) { throw new AssertionError(); } - - if (mOpticalWaveform == null || mAccelerationWaveform == null) { + + if (mOpticalWaveform == null || mAccelerationWaveform == null || mGyroscopeWaveform == null) { throw new AssertionError(); } } @@ -78,14 +78,19 @@ public ChOpticalWaveform getOpticalWaveform() { return mOpticalWaveform; } - + /** Get access to Acceleration Waveform characteristic */ public ChAccelerationWaveform getAccelerationWaveform() { return mAccelerationWaveform; } - - + + /** Get access to Gyroscope Waveform characteristic */ + public ChGyroscopeWaveform getGyroscopeWaveform() { + return mGyroscopeWaveform; + } + + private ChOpticalWaveform mOpticalWaveform; private ChAccelerationWaveform mAccelerationWaveform; - + private ChGyroscopeWaveform mGyroscopeWaveform; }