Skip to content

Commit 8a53d41

Browse files
- add Feature to send the norm of a acceleration, gyro or magnetometer data
- add a feature to send the time domain signal statistics
1 parent 9cccf4f commit 8a53d41

12 files changed

+364
-60
lines changed

BlueSTExample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
}
2323

2424
dependencies {
25-
compile fileTree(dir: 'libs', include: ['*.jar'])
26-
compile project(':BlueSTSDK')
27-
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
25+
implementation fileTree(dir: 'libs', include: ['*.jar'])
26+
implementation project(':BlueSTSDK')
27+
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
2828
}

BlueSTSDK/src/main/java/com/st/BlueSTSDK/Feature.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ void setEnable(boolean enable) {
241241
mIsEnabled = enable;
242242
}//setEnable
243243

244+
public void enableNotification(){
245+
mParent.enableNotification(this);
246+
}
247+
248+
public void disableNotification(){
249+
mParent.disableNotification(this);
250+
}
251+
244252
/**
245253
* call the method {@link com.st.BlueSTSDK.Feature.FeatureListener#onUpdate(Feature,
246254
* Feature.Sample)} for each listener that subscribe to this feature.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.st.BlueSTSDK.Features;
2+
3+
import com.st.BlueSTSDK.Feature;
4+
import com.st.BlueSTSDK.Node;
5+
import com.st.BlueSTSDK.Utils.NumberConversion;
6+
7+
public class FeatureAccelerationNorm extends Feature {
8+
/**
9+
* Name of the feature
10+
*/
11+
public static final String FEATURE_NAME = "AccelerometerNorm";
12+
/**
13+
* data units
14+
*/
15+
public static final String FEATURE_UNIT = "mg";
16+
/**
17+
* name of the data
18+
*/
19+
public static final String FEATURE_DATA_NAME = "Norm";
20+
/**
21+
* max acceleration handle by the sensor
22+
*/
23+
public static final short DATA_MAX = 2000;
24+
/**
25+
* min acceleration handle by the sensor
26+
*/
27+
public static final short DATA_MIN = 0;
28+
29+
/**
30+
* build the feature
31+
*
32+
* @param n node that will provide the data
33+
*/
34+
public FeatureAccelerationNorm(Node n) {
35+
super(FEATURE_NAME, n,
36+
new Field[]{
37+
new Field(FEATURE_DATA_NAME, FEATURE_UNIT, Field.Type.Int16,
38+
DATA_MAX, DATA_MIN)
39+
});
40+
}//FeatureAcceleration
41+
42+
public static int getAccelerationNorm(Sample sample){
43+
if(hasValidIndex(sample,0)){
44+
return sample.data[0].intValue();
45+
}
46+
return -1;
47+
}
48+
49+
@Override
50+
protected ExtractResult extractData(long timestamp, byte[] data, int dataOffset) {
51+
if (data.length - dataOffset < 2)
52+
throw new IllegalArgumentException("There are no 2 bytes available to read");
53+
Sample temp = new Sample(timestamp,new Number[]{
54+
NumberConversion.LittleEndian.bytesToInt16(data, dataOffset)
55+
},getFieldsDesc());
56+
return new ExtractResult(temp,2);
57+
}
58+
}

BlueSTSDK/src/main/java/com/st/BlueSTSDK/Features/FeatureEulerAngle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FeatureEulerAngle extends Feature {
2525
* create a feature that export the euler angle data with a different name
2626
* @param node node that will export the data
2727
*/
28-
protected FeatureEulerAngle(Node node) {
28+
public FeatureEulerAngle(Node node) {
2929
super(FEATURE_NAME, node, new Field[]{
3030
new Field(FEATURE_DATA_NAME[YAW_INDEX], FEATURE_UNIT[YAW_INDEX], Field.Type.Float,
3131
DATA_MAX[YAW_INDEX], DATA_MIN[YAW_INDEX]),

BlueSTSDK/src/main/java/com/st/BlueSTSDK/Features/FeatureFFTAmplitude.java

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package com.st.BlueSTSDK.Features;
22

33
import android.support.annotation.NonNull;
4+
import android.util.Log;
45

56
import com.st.BlueSTSDK.Node;
67
import com.st.BlueSTSDK.Utils.NumberConversion;
78

9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.Collections;
12+
import java.util.List;
13+
814
public class FeatureFFTAmplitude extends DeviceTimestampFeature {
915
public static final String FEATURE_NAME = "FFT Amplitude";
1016
/**
@@ -31,7 +37,7 @@ public static boolean isComplete(Sample s){
3137
return false;
3238
}
3339

34-
public static int getDataLoadPercentage(Sample s){
40+
public static byte getDataLoadPercentage(Sample s){
3541
if (s instanceof FFTSample){
3642
return ((FFTSample) s).getDataLoadPercentage();
3743
}
@@ -80,12 +86,25 @@ public static float[] getComponent(Sample s, int index){
8086
return new float[0];
8187
}
8288

89+
public static List<float[]> getComponents(Sample s){
90+
if (!(s instanceof FFTSample)){
91+
return Collections.emptyList();
92+
}
93+
FFTSample sample = (FFTSample)s;
94+
int nComponents = sample.nComponents;
95+
List<float[]>components = new ArrayList<>(nComponents);
96+
for (int i = 0; i < nComponents; i++) {
97+
components.add(sample.getComponent(i));
98+
}
99+
return Collections.unmodifiableList(components);
100+
}
101+
83102

84103
private static class FFTSample extends Sample{
85104

86-
public final int nSample;
87-
public final short nComponents;
88-
public final float freqStep;
105+
final int nSample;
106+
final short nComponents;
107+
final float freqStep;
89108

90109
private byte[] rawData;
91110
private int nLastData;
@@ -100,15 +119,17 @@ private static class FFTSample extends Sample{
100119
}
101120

102121
void appendData(byte[] data , int offset){
103-
int dataToCopy = data.length - offset;
122+
int spaceAvailable = rawData.length-nLastData;
123+
int dataAvailable = data.length - offset;
124+
int dataToCopy = Math.min(spaceAvailable,dataAvailable);
104125
System.arraycopy(data,offset,rawData,nLastData,dataToCopy);
105126
nLastData += dataToCopy;
106127
}
107128

108-
int getDataLoadPercentage(){
129+
byte getDataLoadPercentage(){
109130
if(rawData.length == 0)
110131
return 0;
111-
return (nLastData*100)/rawData.length;
132+
return (byte) ((nLastData*100)/rawData.length);
112133
}
113134

114135
boolean isComplete(){
@@ -133,10 +154,13 @@ float[] getComponent(int index){
133154

134155
}
135156

157+
private FFTSample mPartialSample;
158+
136159
private FFTSample readHeaderData(long timestamp, byte[] data, int dataOffset){
137160
if(data.length-dataOffset < 7){
138161
throw new IllegalArgumentException("There are no 7 bytes available to read");
139162
}
163+
Log.d("FFT",Arrays.toString(data));
140164

141165
int nSample = NumberConversion.LittleEndian.bytesToUInt16(data, dataOffset);
142166
short nComponents = NumberConversion.byteToUInt8(data, dataOffset+2);
@@ -149,8 +173,17 @@ private FFTSample readHeaderData(long timestamp, byte[] data, int dataOffset){
149173
return sample;
150174
}
151175

176+
@Override
177+
public void enableNotification() {
178+
mPartialSample=null;
179+
super.enableNotification();
180+
}
152181

153-
private FFTSample mPartialSample;
182+
@Override
183+
public void disableNotification(){
184+
mPartialSample=null;
185+
super.disableNotification();
186+
}
154187

155188
@Override
156189
protected ExtractResult extractData(long timestamp, byte[] data, int dataOffset) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.st.BlueSTSDK.Features;
2+
3+
import com.st.BlueSTSDK.Feature;
4+
import com.st.BlueSTSDK.Node;
5+
import com.st.BlueSTSDK.Utils.NumberConversion;
6+
7+
public class FeatureGyroscopeNorm extends Feature {
8+
/**
9+
* Name of the feature
10+
*/
11+
public static final String FEATURE_NAME = "GyroscopeNorm";
12+
/**
13+
* data units
14+
*/
15+
public static final String FEATURE_UNIT = "dps";
16+
/**
17+
* name of the data
18+
*/
19+
public static final String FEATURE_DATA_NAME = "Norm";
20+
/**
21+
* max Gyroscope handle by the sensor
22+
*/
23+
public static final short DATA_MAX = 2000;
24+
/**
25+
* min Gyroscope handle by the sensor
26+
*/
27+
public static final short DATA_MIN = 0;
28+
29+
/**
30+
* build the feature
31+
*
32+
* @param n node that will provide the data
33+
*/
34+
public FeatureGyroscopeNorm(Node n) {
35+
super(FEATURE_NAME, n,
36+
new Field[]{
37+
new Field(FEATURE_DATA_NAME, FEATURE_UNIT, Field.Type.Float,
38+
DATA_MAX, DATA_MIN)
39+
});
40+
}//FeatureGyroscopeNorm
41+
42+
public static float getGyroscopeNorm(Sample sample){
43+
if(hasValidIndex(sample,0)){
44+
return sample.data[0].floatValue();
45+
}
46+
return Float.NaN;
47+
}
48+
49+
@Override
50+
protected ExtractResult extractData(long timestamp, byte[] data, int dataOffset) {
51+
if (data.length - dataOffset < 2)
52+
throw new IllegalArgumentException("There are no 2 bytes available to read");
53+
Sample temp = new Sample(timestamp,new Number[]{
54+
NumberConversion.LittleEndian.bytesToInt16(data, dataOffset)/10.0f
55+
},getFieldsDesc());
56+
return new ExtractResult(temp,2);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.st.BlueSTSDK.Features;
2+
3+
import com.st.BlueSTSDK.Feature;
4+
import com.st.BlueSTSDK.Node;
5+
import com.st.BlueSTSDK.Utils.NumberConversion;
6+
7+
public class FeatureMagnetometerNorm extends Feature {
8+
/**
9+
* Name of the feature
10+
*/
11+
public static final String FEATURE_NAME = "MagnetometerNorm";
12+
/**
13+
* data units
14+
*/
15+
public static final String FEATURE_UNIT = "mGa";
16+
/**
17+
* name of the data
18+
*/
19+
public static final String FEATURE_DATA_NAME = "Norm";
20+
/**
21+
* max Magnetometer handle by the sensor
22+
*/
23+
public static final short DATA_MAX = 2000;
24+
/**
25+
* min Magnetometer handle by the sensor
26+
*/
27+
public static final short DATA_MIN = 0;
28+
29+
/**
30+
* build the feature
31+
*
32+
* @param n node that will provide the data
33+
*/
34+
public FeatureMagnetometerNorm(Node n) {
35+
super(FEATURE_NAME, n,
36+
new Field[]{
37+
new Field(FEATURE_DATA_NAME, FEATURE_UNIT, Field.Type.Int16,
38+
DATA_MAX, DATA_MIN)
39+
});
40+
}//FeatureMagnetometerNorm
41+
42+
public static float getMagnetometerNorm(Sample sample){
43+
if(hasValidIndex(sample,0)){
44+
return sample.data[0].floatValue();
45+
}
46+
return -1;
47+
}
48+
49+
@Override
50+
protected ExtractResult extractData(long timestamp, byte[] data, int dataOffset) {
51+
if (data.length - dataOffset < 2)
52+
throw new IllegalArgumentException("There are no 2 bytes available to read");
53+
Sample temp = new Sample(timestamp,new Number[]{
54+
NumberConversion.LittleEndian.bytesToInt16(data, dataOffset)/10.0f
55+
},getFieldsDesc());
56+
return new ExtractResult(temp,2);
57+
}
58+
}

0 commit comments

Comments
 (0)