Skip to content

Commit

Permalink
TandemBluetoothHandler: only set MTU when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed May 3, 2023
1 parent a7e9bc0 commit b2a0025
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ public void onServicesDiscovered(@NotNull BluetoothPeripheral peripheral) {
// If setting the MTU returns an error, the pump is likely not accepting connections and needs to be open
// to the pairing menu.
// TODO: the t:connect Android app sets a higher MTU of 240 on the connection
peripheral.requestMtu(185);
int mtu = 185;
Timber.d("TandemBluetoothHandler: current MTU %d", peripheral.getCurrentMtu());
if (peripheral.getCurrentMtu() != mtu) {
peripheral.requestMtu(mtu);
} else {
Timber.i("TandemBluetoothHandler: skipping MTU because value is already %d", mtu);
remainingConnectionInitializationSteps.remove(ConnectionInitializationStep.MTU_UPDATED);
}

// Request a new connection priority
peripheral.requestConnectionPriority(ConnectionPriority.HIGH);
Expand Down Expand Up @@ -611,10 +618,9 @@ private Optional<BluetoothPeripheral> getAlreadyBondedPump() {
String name = device.getName();
@SuppressLint("MissingPermission")
String address = device.getAddress();
Timber.d("TandemBluetoothHandler: bondedDevices on adapter includes: %s (%s)", name, address);
if (!Strings.isNullOrEmpty(name) && name.startsWith("tslim X2")) {
BluetoothPeripheral peripheral = central.getPeripheral(address);
Timber.d("TandemBluetoothHandler: '%s' appears to be a Tandem device, returning", name);
Timber.d("TandemBluetoothHandler: bondedDevice on adapter '%s' (%s) appears to be a Tandem device, returning", name, address);
return Optional.of(peripheral);
}
}
Expand Down

0 comments on commit b2a0025

Please sign in to comment.