Skip to content

Commit 64e2e89

Browse files
committed
Imported source code for v2.0.12
1 parent 759e939 commit 64e2e89

File tree

9 files changed

+129
-41
lines changed

9 files changed

+129
-41
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ 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.7'
23+
compile 'com.mbientlab:metawear:2.0.12'
2424
}
2525
```
2626

@@ -47,7 +47,7 @@ import android.content.*;
4747
import android.os.Bundle;
4848
import android.os.IBinder;
4949

50-
import com.mbientlab.metawear.impl.MetaWearBleService;
50+
import com.mbientlab.metawear.MetaWearBleService;
5151

5252
public class ExampleActivity extends Activity implements ServiceConnection {
5353
private MetaWearBleService.LocalBinder serviceBinder;

example/example.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
</content>
9191
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
9292
<orderEntry type="sourceFolder" forTests="false" />
93-
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
9493
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
9594
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
95+
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
9696
<orderEntry type="module" module-name="library" exported="" />
9797
</component>
9898
</module>

example/src/main/java/com/mbientlab/metawear/example/MainActivity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.mbientlab.metawear.MetaWearBleService;
5252
import com.mbientlab.metawear.data.Units;
5353
import com.mbientlab.metawear.module.*;
54+
import com.mbientlab.metawear.module.Bmp280Barometer.StandbyTime;
5455
import com.mbientlab.metawear.processor.*;
5556
import com.mbientlab.metawear.processor.Maths;
5657
import com.mbientlab.metawear.DataSignal;
@@ -1215,10 +1216,11 @@ public void barometerMe(View v) {
12151216
final Switch mySwitch= (Switch) v;
12161217

12171218
try {
1218-
final Barometer barometerModule= mwBoard.getModule(Barometer.class);
1219+
final Bmp280Barometer barometerModule= mwBoard.getModule(Bmp280Barometer.class);
12191220
if (mySwitch.isChecked()) {
12201221
if (!barometerSetup) {
1221-
barometerModule.routeData().fromPressure().process(new Time(Time.OutputMode.ABSOLUTE, 1000)).stream("pressure_sub").commit()
1222+
barometerModule.configure().setPressureOversampling(Bmp280Barometer.OversamplingMode.ULTRA_HIGH).commit();
1223+
barometerModule.routeData().fromPressure().stream("pressure_sub").commit()
12221224
.onComplete(new CompletionHandler<RouteManager>() {
12231225
@Override
12241226
public void success(RouteManager result) {
@@ -1228,10 +1230,9 @@ public void process(Message msg) {
12281230
Log.i("test", String.format("Pressure= %.3f", msg.getData(Float.class)));
12291231
}
12301232
});
1231-
barometerModule.start();
12321233
}
12331234
});
1234-
barometerModule.routeData().fromAltitude().process(new Time(Time.OutputMode.ABSOLUTE, 1000)).stream("altitude_sub").commit()
1235+
barometerModule.routeData().fromAltitude().stream("altitude_sub").commit()
12351236
.onComplete(new CompletionHandler<RouteManager>() {
12361237
@Override
12371238
public void success(RouteManager result) {

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 25
35-
versionName "2.0.7"
34+
versionCode 26
35+
versionName "2.0.12"
3636
}
3737
buildTypes {
3838
release {

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

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void run() {
212212
}
213213
};
214214
private class GattConnectionState {
215-
public final HashMap<UUID, String> devInfoValues= new HashMap<>();
215+
public final HashMap<DevInfoCharacteristic, String> devInfoValues= new HashMap<>();
216216

217217
public final HashMap<Byte, ModuleInfoImpl> moduleInfo= new HashMap<>();
218218
public final AndroidBleConnection androidConn;
@@ -243,7 +243,9 @@ public void checkConnectionReady() {
243243
try {
244244
SharedPreferences.Editor editor = deviceStates.edit();
245245
JSONObject newCachedState = new JSONObject();
246-
newCachedState.put("firmware", devInfoValues.get(DevInfoCharacteristic.FIRMWARE_VERSION.uuid()));
246+
for(DevInfoCharacteristic it: DevInfoCharacteristic.values()) {
247+
newCachedState.put(it.key(), devInfoValues.get(it));
248+
}
247249

248250
JSONObject newModuleState = new JSONObject();
249251
for (ModuleInfoImpl it : moduleInfo.values()) {
@@ -274,11 +276,11 @@ public void run() {
274276

275277
public MetaWearBoard.DeviceInformation buildDeviceInfo() {
276278
return new MetaWearBoard.DeviceInformation() {
277-
@Override public String manufacturer() { return devInfoValues.get(DevInfoCharacteristic.MANUFACTURER_NAME.uuid()); }
278-
@Override public String serialNumber() { return devInfoValues.get(DevInfoCharacteristic.SERIAL_NUMBER.uuid()); }
279-
@Override public String firmwareRevision() { return devInfoValues.get(DevInfoCharacteristic.FIRMWARE_VERSION.uuid()); }
280-
@Override public String hardwareRevision() { return devInfoValues.get(DevInfoCharacteristic.HARDWARE_VERSION.uuid()); }
281-
@Override public String modelNumber() { return devInfoValues.get(DevInfoCharacteristic.MODEL_NUMBER.uuid()); }
279+
@Override public String manufacturer() { return devInfoValues.get(DevInfoCharacteristic.MANUFACTURER_NAME); }
280+
@Override public String serialNumber() { return devInfoValues.get(DevInfoCharacteristic.SERIAL_NUMBER); }
281+
@Override public String firmwareRevision() { return devInfoValues.get(DevInfoCharacteristic.FIRMWARE_VERSION); }
282+
@Override public String hardwareRevision() { return devInfoValues.get(DevInfoCharacteristic.HARDWARE_VERSION); }
283+
@Override public String modelNumber() { return devInfoValues.get(DevInfoCharacteristic.MODEL_NUMBER); }
282284
@Override public String toString() {
283285
return String.format("{manufacturer: %s, serialNumber: %s, firmwareRevision: %s, hardwareRevision: %s, modelNumber: %s}",
284286
manufacturer(), serialNumber(), firmwareRevision(), hardwareRevision(), modelNumber());
@@ -743,31 +745,64 @@ public void run() {
743745
gattManager.executeNext(GattActionKey.DESCRIPTOR_WRITE);
744746
int newCount= state.nDescriptors.decrementAndGet();
745747
if (newCount == 0) {
746-
for(final DevInfoCharacteristic it: DevInfoCharacteristic.values()) {
747-
gattManager.queueAction(new Action() {
748-
@Override
749-
public boolean execute() {
750-
BluetoothGattService service= gatt.getService(DevInfoCharacteristic.serviceUuid());
751-
BluetoothGattCharacteristic devInfoChar= service.getCharacteristic(it.uuid());
752-
753-
if (devInfoChar != null) {
754-
gattManager.setExpectedGattKey(GattActionKey.CHAR_READ);
755-
gatt.readCharacteristic(devInfoChar);
756-
return true;
757-
}
748+
String cachedState= deviceStates.getString(gatt.getDevice().getAddress(), "");
758749

759-
state.devInfoValues.put(it.uuid(), Constant.METAWEAR_R_MODULE);
760-
state.checkConnectionReady();
761-
return false;
762-
}
763-
});
750+
if (cachedState.isEmpty()) {
751+
readDeviceInformation(gatt, state);
752+
} else {
753+
try {
754+
JSONObject jsonCachedState = new JSONObject(cachedState);
755+
state.devInfoValues.put(DevInfoCharacteristic.MODEL_NUMBER, jsonCachedState.getString(DevInfoCharacteristic.MODEL_NUMBER.key()));
756+
state.devInfoValues.put(DevInfoCharacteristic.HARDWARE_VERSION, jsonCachedState.getString(DevInfoCharacteristic.HARDWARE_VERSION.key()));
757+
state.devInfoValues.put(DevInfoCharacteristic.MANUFACTURER_NAME, jsonCachedState.getString(DevInfoCharacteristic.MANUFACTURER_NAME.key()));
758+
state.devInfoValues.put(DevInfoCharacteristic.SERIAL_NUMBER, jsonCachedState.getString(DevInfoCharacteristic.SERIAL_NUMBER.key()));
759+
760+
gattManager.queueAction(new Action() {
761+
@Override
762+
public boolean execute() {
763+
BluetoothGattService service = gatt.getService(DevInfoCharacteristic.serviceUuid());
764+
BluetoothGattCharacteristic devInfoChar = service.getCharacteristic(DevInfoCharacteristic.FIRMWARE_VERSION.uuid());
765+
766+
if (devInfoChar != null) {
767+
gattManager.setExpectedGattKey(GattActionKey.CHAR_READ);
768+
gatt.readCharacteristic(devInfoChar);
769+
return true;
770+
}
771+
return false;
772+
}
773+
});
774+
} catch (JSONException e) {
775+
readDeviceInformation(gatt, state);
776+
}
764777
}
765778

766779
gattManager.executeNext(GattActionKey.NONE);
767780
}
768781
}
769782
}
770783

784+
private void readDeviceInformation(final BluetoothGatt gatt, final GattConnectionState state) {
785+
for (final DevInfoCharacteristic it : DevInfoCharacteristic.values()) {
786+
gattManager.queueAction(new Action() {
787+
@Override
788+
public boolean execute() {
789+
BluetoothGattService service = gatt.getService(DevInfoCharacteristic.serviceUuid());
790+
BluetoothGattCharacteristic devInfoChar = service.getCharacteristic(it.uuid());
791+
792+
if (devInfoChar != null) {
793+
gattManager.setExpectedGattKey(GattActionKey.CHAR_READ);
794+
gatt.readCharacteristic(devInfoChar);
795+
return true;
796+
}
797+
798+
state.devInfoValues.put(it, Constant.METAWEAR_R_MODULE);
799+
state.checkConnectionReady();
800+
return false;
801+
}
802+
});
803+
}
804+
}
805+
771806
@Override
772807
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
773808
gattManager.updateExecActionsState(true);
@@ -803,13 +838,18 @@ public void run() {
803838
}
804839
} else {
805840
String charStringValue= new String(characteristic.getValue());
806-
state.devInfoValues.put(characteristic.getUuid(), charStringValue);
841+
state.devInfoValues.put(DevInfoCharacteristic.uuidToDevInfoCharacteristic(characteristic.getUuid()),
842+
charStringValue);
843+
807844
if (characteristic.getUuid().equals(DevInfoCharacteristic.FIRMWARE_VERSION.uuid())) {
808845
Version deviceFirmware= new Version(charStringValue);
809846

810847
if (deviceFirmware.compareTo(Constant.SERVICE_DISCOVERY_MIN_FIRMWARE) < 0) {
848+
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.AMBIENT_LIGHT, (byte) -1, false));
849+
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.BAROMETER, (byte) -1, false));
850+
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.GSR, (byte) -1, false));
811851
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.TEMPERATURE, Constant.SINGLE_CHANNEL_TEMP_IMPLEMENTATION, true));
812-
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.ACCELEROMETER, Constant.SINGLE_CHANNEL_TEMP_IMPLEMENTATION, true));
852+
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.ACCELEROMETER, Constant.MMA8452Q_IMPLEMENTATION, true));
813853
board.receivedModuleInfo(new DummyModuleInfo(InfoRegister.GYRO, (byte) -1, false));
814854
} else {
815855
String cachedState= deviceStates.getString(gatt.getDevice().getAddress(), "");
@@ -818,7 +858,7 @@ public void run() {
818858
} else {
819859
try {
820860
JSONObject jsonCachedState= new JSONObject(cachedState);
821-
String cachedFirmware= jsonCachedState.getString("firmware");
861+
String cachedFirmware= jsonCachedState.getString(DevInfoCharacteristic.FIRMWARE_VERSION.key());
822862

823863
if (!cachedFirmware.equals(charStringValue)) {
824864
state.discoverModuleInfo();
@@ -913,7 +953,7 @@ public void executeOnUiThread() {
913953
}
914954

915955
/**
916-
* Executes asynchronous tasks on a background thread. This is the default behaviour, to keep minimize
956+
* Executes asynchronous tasks on a background thread. This is the default behaviour, to minimize
917957
* activity on the UI thread.
918958
*/
919959
public void executeOnBackgroundThread() {

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,7 @@ public Response process(byte[] response) {
26752675
});
26762676

26772677
byte[] extra= info.extra();
2678+
tempSources.clear();
26782679
for(byte i= 0; i < extra.length; i++) {
26792680
try {
26802681
Constructor<?> cTor = tempDriverClasses[extra[i]].getConstructor(DefaultMetaWearBoard.class, byte.class, byte.class);
@@ -4317,8 +4318,9 @@ public void setAxisSamplingRange(float range) {
43174318
final float[] values= new float[] { 2.f, 4.f, 8.f, 16.f };
43184319
int closest= closestIndex(values, range);
43194320

4321+
bmi160AccRange= Bmi160Accelerometer.AccRange.values()[closest];
43204322
bmi160DataSampling[1]&= 0xf0;
4321-
bmi160DataSampling[1]|= Bmi160Accelerometer.AccRange.values()[closest].bitMask();
4323+
bmi160DataSampling[1]|= bmi160AccRange.bitMask();
43224324
writeRegister(Bmi160AccelerometerRegister.DATA_CONFIG, bmi160DataSampling);
43234325
}
43244326

@@ -4484,6 +4486,11 @@ private class NrfDieImpl extends SourceImpl implements MultiChannelTemperature.N
44844486
public NrfDieImpl(byte driver, byte channel) {
44854487
super(driver, channel);
44864488
}
4489+
4490+
@Override
4491+
public String getName() {
4492+
return "NRF On-Die Sensor";
4493+
}
44874494
}
44884495
private class ExtThermistorImpl extends SourceImpl implements MultiChannelTemperature.ExtThermistor {
44894496
public ExtThermistorImpl(byte driver, byte channel) {
@@ -4494,16 +4501,31 @@ public ExtThermistorImpl(byte driver, byte channel) {
44944501
public void configure(byte analogReadPin, byte pulldownPin, boolean activeHigh) {
44954502
writeRegister(MultiChannelTempRegister.MODE, channel(), analogReadPin, pulldownPin, (byte) (activeHigh ? 1 : 0));
44964503
}
4504+
4505+
@Override
4506+
public String getName() {
4507+
return "External Thermistor";
4508+
}
44974509
}
44984510
private class BMP280Impl extends SourceImpl implements MultiChannelTemperature.BMP280 {
44994511
public BMP280Impl(byte driver, byte channel) {
45004512
super(driver, channel);
45014513
}
4514+
4515+
@Override
4516+
public String getName() {
4517+
return "BMP280 Sensor";
4518+
}
45024519
}
45034520
private class PresetThermistorImpl extends SourceImpl implements MultiChannelTemperature.PresetThermistor {
45044521
public PresetThermistorImpl(byte driver, byte channel) {
45054522
super(driver, channel);
45064523
}
4524+
4525+
@Override
4526+
public String getName() {
4527+
return "On-board Thermistor";
4528+
}
45074529
}
45084530
private final Class[] tempDriverClasses = new Class[] { NrfDieImpl.class, ExtThermistorImpl.class, BMP280Impl.class, PresetThermistorImpl.class};
45094531

@@ -4663,9 +4685,9 @@ public DataSignal fromAltitude() {
46634685
@Override
46644686
public ConfigEditor configure() {
46654687
return new ConfigEditor() {
4666-
private OversamplingMode samplingMode;
4667-
private FilterMode filterMode;
4668-
private StandbyTime time;
4688+
private OversamplingMode samplingMode= OversamplingMode.STANDARD;
4689+
private FilterMode filterMode= FilterMode.OFF;
4690+
private StandbyTime time= StandbyTime.TIME_0_5;
46694691

46704692
@Override
46714693
public ConfigEditor setPressureOversampling(OversamplingMode mode) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.mbientlab.metawear.impl;
2626

27+
import java.util.HashMap;
2728
import java.util.UUID;
2829

2930
/**
@@ -37,15 +38,32 @@ public enum DevInfoCharacteristic {
3738
HARDWARE_VERSION("27");
3839

3940
private final UUID uuid;
41+
private final String key;
42+
4043
DevInfoCharacteristic(String uuidPart) {
4144
uuid= UUID.fromString(String.format("00002a%s-0000-1000-8000-00805f9b34fb", uuidPart));
45+
key= this.name().toLowerCase();
4246
}
4347

4448
public UUID uuid() {
4549
return uuid;
4650
}
51+
public String key() {
52+
return key;
53+
}
4754

4855
public static UUID serviceUuid() {
4956
return UUID.fromString(String.format("0000%s-0000-1000-8000-00805f9b34fb", "180a"));
5057
}
58+
59+
private static final HashMap<UUID, DevInfoCharacteristic> uuidLookupMap;
60+
static {
61+
uuidLookupMap= new HashMap<>();
62+
for(DevInfoCharacteristic it: DevInfoCharacteristic.values()) {
63+
uuidLookupMap.put(it.uuid(), it);
64+
}
65+
}
66+
public static DevInfoCharacteristic uuidToDevInfoCharacteristic(UUID uuid) {
67+
return uuidLookupMap.get(uuid);
68+
}
5169
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public interface Bmp280Barometer extends Barometer {
3535
* @author Eric Tsai
3636
*/
3737
enum OversamplingMode {
38+
SKIP,
3839
ULTRA_LOW_POWER,
3940
LOW_POWER,
4041
STANDARD,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ interface Source {
6969
* @return Channel position
7070
*/
7171
byte channel();
72+
73+
/**
74+
* Retrieves a readable name for the temperature source
75+
* @return Name for the source
76+
*/
77+
String getName();
7278
}
7379

7480
/**

0 commit comments

Comments
 (0)