Skip to content

Commit

Permalink
Imported api v3.0.7
Browse files Browse the repository at this point in the history
Added missing Constant.java file
  • Loading branch information
scaryghost committed Mar 9, 2017
1 parent daba59e commit cb1d4a1
Show file tree
Hide file tree
Showing 88 changed files with 748 additions and 480 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.+'
compile 'com.mbientlab:metawear:3.0.7'
}
```

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.2.1'
classpath 'com.android.tools.build:gradle:2.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 30 15:56:16 PDT 2016
#Fri Mar 03 11:31:01 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
4 changes: 2 additions & 2 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 45
versionName "3.0.0"
versionCode 46
versionName "3.0.7"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand All @@ -78,7 +80,7 @@
*/
public class BtleService extends Service {
private static UUID CHARACTERISTIC_CONFIG= UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
private static String DOWNLOAD_DIR_NAME = "download";
private static String DOWNLOAD_DIR_NAME = "download", LOG_TAG = "metawear-btle";

private final BluetoothGattCallback btleGattCallback= new BluetoothGattCallback() {
@Override
Expand Down Expand Up @@ -140,13 +142,46 @@ public void run() {
} else {
final BluetoothGattService service = gatt.getService(MetaWearBoard.METAWEAR_GATT_SERVICE);
if (service == null) {
platform.closeGatt();
taskFutures.add(backgroundThreadPool.submit(new Runnable() {
@Override
public void run() {
platform.setConnectTaskError(new RuntimeException("MetaWear GATT service does not exist: " + MetaWearBoard.METAWEAR_GATT_SERVICE.toString()));
boolean dfuServiceExists = false;
platform.nDescriptors = 0;
ArrayList<Callable<Boolean>> enNotifyActions = new ArrayList<>();

for (final BluetoothGattService it : gatt.getServices()) {
if (it.getUuid().equals(MetaWearBoard.METABOOT_SERVICE)) {
dfuServiceExists= true;
}
}));
for (final BluetoothGattCharacteristic characteristic : it.getCharacteristics()) {
int charProps = characteristic.getProperties();
if ((charProps & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
platform.nDescriptors++;
enNotifyActions.add(new Callable<Boolean>() {
@Override
public Boolean call() {
gatt.setCharacteristicNotification(characteristic, true);

gattScheduler.setExpectedGattKey(GattActionKey.DESCRIPTOR_WRITE);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_CONFIG);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);

return true;
}
});
}
}
}

if (!dfuServiceExists) {
platform.closeGatt();
taskFutures.add(backgroundThreadPool.submit(new Runnable() {
@Override
public void run() {
platform.setConnectTaskError(new RuntimeException("Bluetooth LE device is not recognized by the API"));
}
}));
} else {
gattScheduler.queueActions(enNotifyActions);
}
} else {
platform.nDescriptors= 1;

Expand Down Expand Up @@ -281,6 +316,11 @@ void updateExecActionsState() {
void queueAction(Callable<Boolean> newAction) {
actions.add(newAction);
}

void queueActions(Collection<Callable<Boolean>> newActions) {
actions.addAll(newActions);
}

void executeNext(GattActionKey key) {
if (!actions.isEmpty()) {
if (key == gattKey || !isExecActions.get()) {
Expand Down Expand Up @@ -342,7 +382,7 @@ void closeGatt() {
try {
androidBtGatt.getClass().getMethod("refresh").invoke(androidBtGatt);
} catch (final Exception e) {
Log.e("MetaWear", "Error refreshing gatt cache", e);
Log.e(LOG_TAG, "Error refreshing gatt cache", e);
} finally {
androidBtGatt.close();
androidBtGatt = null;
Expand Down Expand Up @@ -478,7 +518,7 @@ public Boolean call() {

@Override
public boolean serviceExists(UUID serviceUuid) {
return androidBtGatt.getService(MetaWearBoard.METABOOT_SERVICE) != null;
return androidBtGatt.getService(serviceUuid) != null;
}

@Override
Expand Down Expand Up @@ -557,7 +597,7 @@ public void run() {
try {
next.get();
} catch (Exception e) {
Log.e("MetaWear", "Background task reported an error", e);
Log.e(LOG_TAG, "Background task reported an error", e);
}
} else {
notYetCompleted.add(next);
Expand Down
80 changes: 80 additions & 0 deletions library/src/main/java/com/mbientlab/metawear/impl/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2014-2015 MbientLab Inc. All rights reserved.
*
* IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software
* license agreement between the user who downloaded the software, his/her employer (which must be your
* employer) and MbientLab Inc, (the "License"). You may not use this Software unless you agree to abide by the
* terms of the License which can be found at www.mbientlab.com/terms. The License limits your use, and you
* acknowledge, that the Software may be modified, copied, and distributed when used in conjunction with an
* MbientLab Inc, product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare
* derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any
* purpose.
*
* YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MBIENTLAB OR ITS LICENSORS BE LIABLE OR
* OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE
* THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT,
* PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY,
* SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*
* Should you have any questions regarding your right to use this Software, contact MbientLab via email:
* [email protected].
*/

package com.mbientlab.metawear.impl;

import java.util.HashMap;

/**
* Created by etsai on 9/20/16.
*/
class Constant {
static final byte COMMAND_LENGTH = 18;

enum Module {
SWITCH(0x01),
LED(0x02),
ACCELEROMETER(0x03),
TEMPERATURE(0x04),
GPIO(0x05),
NEO_PIXEL(0x06),
IBEACON(0x07),
HAPTIC(0x08),
DATA_PROCESSOR(0x09),
EVENT(0x0a),
LOGGING(0x0b),
TIMER(0x0c),
SERIAL_PASSTHROUGH(0x0d),
MACRO(0x0f),
GSR(0x10),
SETTINGS(0x11),
BAROMETER(0x12),
GYRO(0x13),
AMBIENT_LIGHT(0x14),
MAGNETOMETER(0x15),
HUMIDITY(0x16),
COLOR_DETECTOR(0x17),
PROXIMITY(0x18),
SENSOR_FUSION(0x19),
DEBUG(0xfe);

public final byte id;

Module(int id) {
this.id= (byte) id;
}

private static final HashMap<Byte, Module> byteToEnum;
static {
byteToEnum= new HashMap<>();
for(Module it: Module.values()) {
byteToEnum.put(it.id, it);
}
}

public static Module lookupEnum(byte id) {
return byteToEnum.get(id);
}
}
}
8 changes: 0 additions & 8 deletions library/src/main/java/com/mbientlab/metawear/impl/Tuple3.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ class Tuple3<T, U, V> {
this.third = third;
}

public ResponseHeader markAsRead() {
return new ResponseHeader(module, (byte) (register | 0x80), id);
}

public ResponseHeader clearRead() {
return new ResponseHeader(module, (byte) (register & 0x7f), id);
}

@Override
public boolean equals(Object o) {
// Generated by IntelliJ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface MwBridge {
}

public int nConnects = 0, nDisconnects = 0;
public MetaWearBoardInfo boardInfo= MetaWearBoardInfo.RPRO;
public MetaWearBoardInfo boardInfo= new MetaWearBoardInfo();
public String firmware= "1.2.3", boardStateSuffix;
public boolean delayModuleInfoResponse= false, deserializeModuleInfo= false, serializeModuleInfo = false, enableMetaBootState = false, delayReadDevInfo = false;
private final Map<Byte, byte[]> customModuleInfo= new HashMap<>();
Expand Down
Loading

0 comments on commit cb1d4a1

Please sign in to comment.