Pebble 2/LE: honor reconnect tries
This commit is contained in:
parent
44f74270df
commit
3eda2d4b81
|
@ -44,11 +44,7 @@ class PebbleGATTClient extends BluetoothGattCallback {
|
|||
mContext = context;
|
||||
mBtDevice = btDevice;
|
||||
mPebbleLESupport = pebbleLESupport;
|
||||
}
|
||||
|
||||
boolean initialize() {
|
||||
connectToPebble(mBtDevice);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||
|
@ -185,7 +181,6 @@ class PebbleGATTClient extends BluetoothGattCallback {
|
|||
if (mBluetoothGatt != null) {
|
||||
this.close();
|
||||
}
|
||||
//mBtDevice.createBond();
|
||||
mBluetoothGatt = btDevice.connectGatt(mContext, false, this);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ class PebbleGATTServer extends BluetoothGattServerCallback {
|
|||
LOG.warn("unexpected write request");
|
||||
return;
|
||||
}
|
||||
mPebbleLESupport.mIsConnected = true;
|
||||
LOG.info("write request: offset = " + offset + " value = " + GB.hexdump(value, 0, -1));
|
||||
int header = value[0] & 0xff;
|
||||
int command = header & 7;
|
||||
|
@ -180,8 +181,10 @@ class PebbleGATTServer extends BluetoothGattServerCallback {
|
|||
}
|
||||
|
||||
void close() {
|
||||
mBluetoothGattServer.cancelConnection(mBtDevice);
|
||||
mBluetoothGattServer.clearServices();
|
||||
mBluetoothGattServer.close();
|
||||
if (mBluetoothGattServer != null) {
|
||||
mBluetoothGattServer.cancelConnection(mBtDevice);
|
||||
mBluetoothGattServer.clearServices();
|
||||
mBluetoothGattServer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
|
@ -20,8 +19,9 @@ public class PebbleLESupport {
|
|||
private PipedInputStream mPipedInputStream;
|
||||
private PipedOutputStream mPipedOutputStream;
|
||||
private int mMTU = 20;
|
||||
boolean mIsConnected = false;
|
||||
|
||||
public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) {
|
||||
public PebbleLESupport(Context context, final BluetoothDevice btDevice, PipedInputStream pipedInputStream, PipedOutputStream pipedOutputStream) throws IOException {
|
||||
mBtDevice = btDevice;
|
||||
mPipedInputStream = new PipedInputStream();
|
||||
mPipedOutputStream = new PipedOutputStream();
|
||||
|
@ -35,8 +35,16 @@ public class PebbleLESupport {
|
|||
mPebbleGATTServer = new PebbleGATTServer(this, context, mBtDevice);
|
||||
if (mPebbleGATTServer.initialize()) {
|
||||
mPebbleGATTClient = new PebbleGATTClient(this, context, mBtDevice);
|
||||
mPebbleGATTClient.initialize();
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
if (mIsConnected) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
this.close();
|
||||
throw new IOException("conntection failed");
|
||||
}
|
||||
|
||||
void writeToPipedOutputStream(byte[] value, int offset, int count) {
|
||||
|
|
Loading…
Reference in New Issue