Skip to content

Commit 335681e

Browse files
committed
Imported code for api v2.0.18
1 parent 64e2e89 commit 335681e

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ Then, add the compile element to the dependencies closure in the module's *build
2020

2121
```gradle
2222
dependencies {
23-
compile 'com.mbientlab:metawear:2.0.12'
23+
compile 'com.mbientlab:metawear:2.0.18'
2424
}
2525
```
2626

27+
## Attaching Source Code ##
28+
The MetaWear API aar comes packaged with the library's source code. To associate the source code with the AAR package:
29+
30+
1. Switch the project view to display the project structure
31+
2. Expand the "External Libraries" tab
32+
3. Right click "metawear-${version}" and select "Library Properties"
33+
4. Press the add button (green plus icon) and select "sources.jar" under the "jar" tab
34+
2735
## Declaring the Service ##
2836
Once your project has synced with the updated Gradle files, declare the MetaWear Bluetooth LE service in the module's *AndroidManifest.xml* file.
2937
```xml

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ android {
3131
defaultConfig {
3232
minSdkVersion 18
3333
targetSdkVersion 22
34-
versionCode 26
35-
versionName "2.0.12"
34+
versionCode 27
35+
versionName "2.0.18"
3636
}
3737
buildTypes {
3838
release {

library/src/main/java/com/mbientlab/metawear/MetaWearBleService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class MetaWearBleService extends Service {
7474
METAWEAR_SERVICE= UUID.fromString("326A9000-85CB-9195-D9DD-464CFBBAE75A"),
7575
METAWEAR_COMMAND= UUID.fromString("326A9001-85CB-9195-D9DD-464CFBBAE75A"),
7676
METAWEAR_NOTIFY= UUID.fromString("326A9006-85CB-9195-D9DD-464CFBBAE75A");
77+
private final static long FUTURE_CHECKER_PERIOD= 1000L;
7778

7879
private enum GattActionKey {
7980
NONE,
@@ -421,6 +422,8 @@ private void queueCommand(final int writeType, final byte[] command, final boole
421422
public boolean execute() {
422423
if (gatt != null && (override || gattConnectionStates.get(gatt.getDevice()).isReady.get())) {
423424
gattManager.setExpectedGattKey(GattActionKey.CHAR_WRITE);
425+
mwBoards.get(gatt.getDevice()).wroteCommand(command);
426+
424427
BluetoothGattService service = gatt.getService(METAWEAR_SERVICE);
425428
BluetoothGattCharacteristic mwCmdChar = service.getCharacteristic(METAWEAR_COMMAND);
426429
mwCmdChar.setWriteType(writeType);
@@ -470,9 +473,9 @@ public void sendCommand(boolean writeMacro, byte[] command) {
470473
queueCommand(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT, macroBytes);
471474
}
472475
} else {
473-
queueCommand(command[0] == MacroRegister.ENABLE.moduleOpcode() ?
474-
BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE :
475-
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
476+
queueCommand(command[0] == InfoRegister.MACRO.moduleOpcode() ?
477+
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT :
478+
BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE,
476479
command);
477480
}
478481
}
@@ -693,8 +696,6 @@ public boolean execute() {
693696
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
694697
gattManager.updateExecActionsState(false);
695698
gattManager.executeNext(GattActionKey.CHAR_WRITE);
696-
697-
mwBoards.get(gatt.getDevice()).wroteCommand(characteristic.getValue());
698699
}
699700

700701
@Override
@@ -959,7 +960,7 @@ public void executeOnUiThread() {
959960
public void executeOnBackgroundThread() {
960961
useHandler= false;
961962
futureTimer = new Timer();
962-
futureTimer.scheduleAtFixedRate(futureCheckerTask, 0, 1000);
963+
futureTimer.scheduleAtFixedRate(futureCheckerTask, 0, FUTURE_CHECKER_PERIOD);
963964
}
964965
}
965966

@@ -988,6 +989,7 @@ public IBinder onBind(Intent intent) {
988989
public void onCreate () {
989990
super.onCreate();
990991

992+
futureTimer.scheduleAtFixedRate(futureCheckerTask, 0, FUTURE_CHECKER_PERIOD);
991993
deviceStates= getSharedPreferences(DEVICE_STATE_KEY, MODE_PRIVATE);
992994
}
993995
}

library/src/main/java/com/mbientlab/metawear/impl/DefaultMetaWearBoard.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ private static String arrayToHexString(byte[] value) {
7272
}
7373

7474
StringBuilder builder= new StringBuilder();
75-
builder.append(String.format("[%02x", value[0]));
75+
builder.append(String.format("[0x%02x", value[0]));
7676
for(int i= 1; i < value.length; i++) {
77-
builder.append(String.format(", %02x", value[i]));
77+
builder.append(String.format(", 0x%02x", value[i]));
7878
}
7979
builder.append("]");
8080

@@ -968,7 +968,7 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
968968
byte second = (byte) ((DataSignalImpl.this.outputSize - 1) & 0x3 | (isSigned() ? 0x4 : 0) |
969969
(params.mode.ordinal() << 3));
970970
ByteBuffer buffer = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
971-
Number firmwareValue = numberToFirmwareUnits(thsConfig.limit), firmwareHysteresis= numberToFirmwareUnits(thsConfig.hysteresis);
971+
Number firmwareValue = parent.numberToFirmwareUnits(thsConfig.limit), firmwareHysteresis= parent.numberToFirmwareUnits(thsConfig.hysteresis);
972972
buffer.put((byte) 0xd).put(second).putInt(firmwareValue.intValue()).putShort(firmwareHysteresis.shortValue());
973973

974974
return buffer.array();
@@ -1054,7 +1054,7 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
10541054
///< Do not allow the delta mode to be changed
10551055
byte second = (byte) (((this.outputSize - 1) & 0x3) | (isSigned() ? 0x4 : 0) |
10561056
(params.mode.ordinal() << 3));
1057-
Number firmware = numberToFirmwareUnits(deltaConfig.threshold);
1057+
Number firmware = parent.numberToFirmwareUnits(deltaConfig.threshold);
10581058
ByteBuffer config = ByteBuffer.allocate(6).order(ByteOrder.LITTLE_ENDIAN).put((byte) 0xc).put(second).putInt(firmware.intValue());
10591059
return config.array();
10601060

@@ -1366,7 +1366,7 @@ public byte[] getFilterConfig() {
13661366
@Override
13671367
protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
13681368
Pulse pulseConfig= (Pulse) newConfig;
1369-
Number firmwareThs= numberToFirmwareUnits(pulseConfig.threshold);
1369+
Number firmwareThs= parent.numberToFirmwareUnits(pulseConfig.threshold);
13701370

13711371
///< Do not allow output type to switch
13721372
ByteBuffer buffer= ByteBuffer.allocate(10).put((byte) 0xb).put(parent.outputSize).put((byte) 0).put((byte) params.mode.ordinal())
@@ -1557,7 +1557,7 @@ public void setState(State newState) {
15571557
} else if (newState instanceof Average.State) {
15581558
stateBytes= new byte[0];
15591559
} else if (newState instanceof Delta.State) {
1560-
Number firmware= numberToFirmwareUnits(((Delta.State) newState).newPreviousValue);
1560+
Number firmware= parent.numberToFirmwareUnits(((Delta.State) newState).newPreviousValue);
15611561

15621562
stateBytes= ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(firmware.intValue()).array();
15631563
} else if (newState instanceof Passthrough.State) {
@@ -1744,6 +1744,11 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
17441744
rmsMode};
17451745
}
17461746

1747+
@Override
1748+
public Number numberToFirmwareUnits(Number input) {
1749+
return parent.numberToFirmwareUnits(input);
1750+
}
1751+
17471752
@Override
17481753
public boolean isSigned() {
17491754
return false;
@@ -2279,7 +2284,9 @@ protected DefaultMetaWearBoard(final Connection conn) {
22792284
final ResponseProcessor idProcessor= new ResponseProcessor() {
22802285
@Override
22812286
public Response process(byte[] response) {
2282-
pendingRoutes.peek().receivedId(response[2]);
2287+
if (!pendingRoutes.isEmpty()) {
2288+
pendingRoutes.peek().receivedId(response[2]);
2289+
}
22832290
return null;
22842291
}
22852292
};
@@ -2297,7 +2304,9 @@ public Response process(byte[] response) {
22972304
responses.put(new ResponseHeader(EventRegister.ENTRY), new ResponseProcessor() {
22982305
@Override
22992306
public Response process(byte[] response) {
2300-
currEventListener.receivedCommandId(response[2]);
2307+
if (currEventListener != null) {
2308+
currEventListener.receivedCommandId(response[2]);
2309+
}
23012310
return null;
23022311
}
23032312
});
@@ -2354,9 +2363,9 @@ public Response process(byte[] response) {
23542363
@Override
23552364
public Response process(byte[] response) {
23562365
try {
2357-
byte[] respBody= new byte[response.length - 3];
2366+
byte[] respBody = new byte[response.length - 3];
23582367
System.arraycopy(response, 3, respBody, 0, respBody.length);
2359-
ResponseHeader header= new ResponseHeader(response[0], response[1], response[2]);
2368+
ResponseHeader header = new ResponseHeader(response[0], response[1], response[2]);
23602369

23612370
if (bmi160AccMessageClasses.contains(dataProcMsgClasses.get(header))) {
23622371
Constructor<?> cTor = dataProcMsgClasses.get(header).getConstructor(byte[].class, float.class);
@@ -2370,6 +2379,8 @@ public Response process(byte[] response) {
23702379

23712380
Constructor<?> cTor = dataProcMsgClasses.get(header).getConstructor(byte[].class);
23722381
return new Response((Message) cTor.newInstance(respBody), header);
2382+
} catch (NullPointerException ex) {
2383+
return null;
23732384
} catch (Exception ex) {
23742385
throw new RuntimeException("Cannot create a message processor for filter output: " + Arrays.toString(response), ex);
23752386
}

library/src/main/java/com/mbientlab/metawear/module/Accelerometer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface Accelerometer extends MetaWearBoard.Module {
4242
*/
4343
void setOutputDataRate(float frequency);
4444
/**
45-
* Sets the sampling range for the accelerometer. The closet, valid range will be chosen depending
45+
* Sets the sampling range for the accelerometer. The closest, valid range will be chosen depending
4646
* on the underlying sensor
4747
* @param range Sampling range, in G's
4848
*/

0 commit comments

Comments
 (0)