Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Android/angel-sample-app/angel-sdk-debug/angel-sdk-debug.aar
Binary file not shown.
6 changes: 3 additions & 3 deletions Android/angel-sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -231,6 +239,22 @@ public void onValueReady(ChAccelerationWaveform.AccelerationWaveformValue accele
}
};

private final BleCharacteristic.ValueReadyCallback<ChGyroscopeWaveform.GyroscopeWaveformValue> mGyroscopeWaveformListener = new BleCharacteristic.ValueReadyCallback<ChGyroscopeWaveform.GyroscopeWaveformValue>() {
@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<ChOpticalWaveform.OpticalWaveformValue> mOpticalWaveformListener = new BleCharacteristic.ValueReadyCallback<ChOpticalWaveform.OpticalWaveformValue>() {
@Override
public void onValueReady(ChOpticalWaveform.OpticalWaveformValue opticalWaveformValue) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,70 @@
android:layout_alignParentBottom="true"
android:id="@+id/view_line_3" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<com.angel.sample_app.GraphView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/graph_gyro_x"
android:layout_alignParentTop="true"
android:layout_above="@+id/view_line_4"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFF"
android:layout_alignParentBottom="true"
android:id="@+id/view_line_4" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<com.angel.sample_app.GraphView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/graph_gyro_y"
android:layout_alignParentTop="true"
android:layout_above="@+id/view_line_5"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFF"
android:layout_alignParentBottom="true"
android:id="@+id/view_line_5" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<com.angel.sample_app.GraphView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/graph_gyro_z"
android:layout_alignParentTop="true"
android:layout_above="@+id/view_line_6"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFF"
android:layout_alignParentBottom="true"
android:id="@+id/view_line_6" />
</RelativeLayout>
</LinearLayout>
4 changes: 2 additions & 2 deletions Android/angel-sdk/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
116 changes: 116 additions & 0 deletions Android/angel-sdk/src/main/java/com/angel/sdk/ChGyroscopeWaveform.java
Original file line number Diff line number Diff line change
@@ -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<ChGyroscopeWaveform.GyroscopeWaveformValue> {
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<GyroscopeXYZValues> wave = new ArrayList<GyroscopeXYZValues>();
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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();
}
}
Expand All @@ -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;
}