Skip to content

Commit

Permalink
API v3.0.37 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Jul 28, 2017
1 parent 888ea59 commit 00014f4
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 103 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Then, add the compile element to the dependencies closure in the module's *build

```gradle
dependencies {
compile 'com.mbientlab:metawear:3.0.32'
compile 'com.mbientlab:metawear:3.0.37'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 18
targetSdkVersion 25
versionCode 49
versionName "3.0.32"
versionCode 50
versionName "3.0.37"
}
buildTypes {
release {
Expand All @@ -47,4 +47,4 @@ dependencies {
compile 'com.parse.bolts:bolts-tasks:1.4.0'
testCompile 'org.json:json:20160810'
testCompile 'junit:junit:4.12'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* Created by etsai on 9/20/16.
*/
class GyroBmi160Impl extends ModuleImplBase implements GyroBmi160 {
private static final byte PACKED_ROT_REVISION= 1;
private final static byte POWER_MODE = 1, DATA_INTERRUPT_ENABLE = 2, CONFIG = 3, DATA = 5, PACKED_DATA= 0x7;
private final static String ROT_PRODUCER= "com.mbientlab.metawear.impl.GyroBmi160Impl.ROT_PRODUCER",
ROT_X_AXIS_PRODUCER= "com.mbientlab.metawear.impl.GyroBmi160Impl.ROT_X_AXIS_PRODUCER",
Expand Down Expand Up @@ -232,30 +233,33 @@ public void stop() {

@Override
public AsyncDataProducer packedAngularVelocity() {
if (packedRotationalSpeed == null) {
packedRotationalSpeed = new AsyncDataProducer() {
@Override
public Task<Route> addRouteAsync(RouteBuilder builder) {
return mwPrivate.queueRouteBuilder(builder, ROT_PACKED_PRODUCER);
}
if (mwPrivate.lookupModuleInfo(GYRO).revision >= PACKED_ROT_REVISION) {
if (packedRotationalSpeed == null) {
packedRotationalSpeed = new AsyncDataProducer() {
@Override
public Task<Route> addRouteAsync(RouteBuilder builder) {
return mwPrivate.queueRouteBuilder(builder, ROT_PACKED_PRODUCER);
}

@Override
public String name() {
return ROT_PACKED_PRODUCER;
}
@Override
public String name() {
return ROT_PACKED_PRODUCER;
}

@Override
public void start() {
mwPrivate.sendCommand(new byte[] {GYRO.id, DATA_INTERRUPT_ENABLE, 1, 0});
}
@Override
public void start() {
mwPrivate.sendCommand(new byte[]{GYRO.id, DATA_INTERRUPT_ENABLE, 1, 0});
}

@Override
public void stop() {
mwPrivate.sendCommand(new byte[] {GYRO.id, DATA_INTERRUPT_ENABLE, 0, 1});
}
};
@Override
public void stop() {
mwPrivate.sendCommand(new byte[]{GYRO.id, DATA_INTERRUPT_ENABLE, 0, 1});
}
};
}
return packedRotationalSpeed;
}
return packedRotationalSpeed;
return null;
}

@Override
Expand Down
18 changes: 8 additions & 10 deletions library/src/main/java/com/mbientlab/metawear/impl/MacroImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MacroImpl extends ModuleImplBase implements Macro {
private transient boolean isRecording= false;
private transient Queue<byte[]> commands;
private transient Pair<TaskCompletionSource<Byte>, Boolean> pendingMacro;
private transient byte newId;

MacroImpl(MetaWearBoardPrivate mwPrivate) {
super(mwPrivate);
Expand All @@ -61,7 +60,14 @@ protected void init() {
this.mwPrivate.addResponseHandler(new Pair<>(MACRO.id, BEGIN), new RegisterResponseHandler() {
@Override
public void onResponseReceived(byte[] response) {
newId = response[2];
while(!commands.isEmpty()) {
for(byte[] converted: convertToMacroCommand(commands.poll())) {
mwPrivate.sendCommand(converted);
}
}
mwPrivate.sendCommand(new byte[] {MACRO.id, END});

pendingMacro.first.setResult(response[2]);
}
});
}
Expand All @@ -85,14 +91,6 @@ public Task<Byte> endRecordAsync() {
@Override
public void run() {
mwPrivate.sendCommand(new byte[] {MACRO.id, BEGIN, (byte) (pendingMacro.second ? 1 : 0)});
while(!commands.isEmpty()) {
for(byte[] converted: convertToMacroCommand(commands.poll())) {
mwPrivate.sendCommand(converted);
}
}
mwPrivate.sendCommand(new byte[] {MACRO.id, END});

pendingMacro.first.setResult(newId);
}
}, WRITE_MACRO_DELAY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MagnetometerBmm150Impl extends ModuleImplBase implements MagnetometerBmm15
BFIELD_Y_AXIS_PRODUCER= "com.mbientlab.metawear.impl.MagnetometerBmm150Impl.BFIELD_Y_AXIS_PRODUCER",
BFIELD_Z_AXIS_PRODUCER= "com.mbientlab.metawear.impl.MagnetometerBmm150Impl.BFIELD_Z_AXIS_PRODUCER",
BFIELD_PACKED_PRODUCER= "com.mbientlab.metawear.impl.MagnetometerBmm150Impl.BFIELD_PACKED_PRODUCER";
private static final byte PACKED_BFIELD_REVISION= 1;
private static final byte POWER_MODE = 1,
DATA_INTERRUPT_ENABLE = 2, DATA_RATE = 3, DATA_REPETITIONS = 4, MAG_DATA = 5,
PACKED_MAG_DATA = 0x09;
Expand Down Expand Up @@ -126,7 +127,7 @@ private static class Bmm150SFloatData extends SFloatData {

@Override
protected float scale(MetaWearBoardPrivate mwPrivate) {
return 16.f;
return 16000000.f;
}

@Override
Expand Down Expand Up @@ -193,30 +194,33 @@ public void start() {

@Override
public AsyncDataProducer packedMagneticField() {
if (packedBfield == null) {
packedBfield = new AsyncDataProducer() {
@Override
public Task<Route> addRouteAsync(RouteBuilder builder) {
return mwPrivate.queueRouteBuilder(builder, BFIELD_PACKED_PRODUCER);
}
if (mwPrivate.lookupModuleInfo(MAGNETOMETER).revision >= PACKED_BFIELD_REVISION) {
if (packedBfield == null) {
packedBfield = new AsyncDataProducer() {
@Override
public Task<Route> addRouteAsync(RouteBuilder builder) {
return mwPrivate.queueRouteBuilder(builder, BFIELD_PACKED_PRODUCER);
}

@Override
public String name() {
return BFIELD_PACKED_PRODUCER;
}
@Override
public String name() {
return BFIELD_PACKED_PRODUCER;
}

@Override
public void stop() {
mwPrivate.sendCommand(new byte[]{MAGNETOMETER.id, DATA_INTERRUPT_ENABLE, 0, 1});
}
@Override
public void stop() {
mwPrivate.sendCommand(new byte[]{MAGNETOMETER.id, DATA_INTERRUPT_ENABLE, 0, 1});
}

@Override
public void start() {
mwPrivate.sendCommand(new byte[]{MAGNETOMETER.id, DATA_INTERRUPT_ENABLE, 1, 0});
}
};
@Override
public void start() {
mwPrivate.sendCommand(new byte[]{MAGNETOMETER.id, DATA_INTERRUPT_ENABLE, 1, 0});
}
};
}
return packedBfield;
}
return packedBfield;
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Created by etsai on 9/5/16.
*/
class Version implements Comparable<Version>, Serializable {
private static final Pattern VERSION_STRING_PATTERN = Pattern.compile("(\\d)+\\.(\\d)+\\.(\\d)");
private static final Pattern VERSION_STRING_PATTERN = Pattern.compile("(\\d)+\\.(\\d)+\\.(\\d)+");
private static final long serialVersionUID = -6928626294821091652L;

private final int major, minor, step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Task<Void> writeCharacteristicAsync(BtleGattCharacteristic gattCharr, Wri
dataProcessorId++;
scheduleMockResponse(response);
} else if (value[0] == 0xf && value[1] == 0x2) {
byte[] response = {value[2], 0x2, macroId};
byte[] response = {value[0], 0x2, macroId};
macroId++;
scheduleMockResponse(response);
} else if (value[0] == (byte) 0xb && value[1] == (byte) 0x85) {
Expand Down
49 changes: 6 additions & 43 deletions library/src/test/java/com/mbientlab/metawear/TestMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,8 @@ public void ledOnBoot() throws InterruptedException {
.highIntensity((byte) 16).lowIntensity((byte) 16)
.commit();
led.play();
macro.endRecordAsync().continueWith(new Continuation<Byte, Void>() {
@Override
public Void then(Task<Byte> task) throws Exception {
synchronized (TestMacro.this) {
TestMacro.this.notifyAll();
}
return null;
}
});

synchronized (this) {
this.wait();

assertArrayEquals(expected, junitPlatform.getCommands());
}
macro.endRecordAsync().waitForCompletion();
assertArrayEquals(expected, junitPlatform.getCommands());
}

@Test
Expand Down Expand Up @@ -147,21 +134,9 @@ public Task<Byte> then(Task<Route> task) throws Exception {
accelerometer.start();
return macro.endRecordAsync();
}
}).continueWith(new Continuation<Byte, Void>() {
@Override
public Void then(Task<Byte> task) throws Exception {
synchronized (TestMacro.this) {
TestMacro.this.notifyAll();
}
return null;
}
});

synchronized (this) {
this.wait();
}).waitForCompletion();

assertArrayEquals(expected, junitPlatform.getCommands());
}
assertArrayEquals(expected, junitPlatform.getCommands());
}

@Test
Expand Down Expand Up @@ -197,20 +172,8 @@ public void ledSwitch() throws InterruptedException {
public Task<Byte> then(Task<Route> task) throws Exception {
return macro.endRecordAsync();
}
}).continueWith(new Continuation<Byte, Void>() {
@Override
public Void then(Task<Byte> task) throws Exception {
synchronized (TestMacro.this) {
TestMacro.this.notifyAll();
}
return null;
}
});

synchronized (this) {
this.wait();
}).waitForCompletion();

assertArrayEquals(expected, junitPlatform.getCommands());
}
assertArrayEquals(expected, junitPlatform.getCommands());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public Void then(Task<Route> task) throws Exception {

@Test
public void bFieldComponentData() {
float[] expected = new float[] {-251.1250f, 165.1875f, 71.3125f};
float[] expected = new float[] {-0.0002511250f, 0.0001651875f, 0.0000713125f};
final float[] actual= new float[3];

mag.magneticField().addRouteAsync(new RouteBuilder() {
Expand Down Expand Up @@ -183,6 +183,6 @@ public Void then(Task<Route> task) throws Exception {
});
sendMockResponse(new byte[] {0x15, 0x05, 0x4e, (byte) 0xf0, 0x53, 0x0a, 0x75, 0x04});

assertArrayEquals(expected, actual, 0.001f);
assertArrayEquals(expected, actual, 0.0000003f);
}
}

0 comments on commit 00014f4

Please sign in to comment.