setPreferredPhy method

Future<void> setPreferredPhy({
  1. required int txPhy,
  2. required int rxPhy,
  3. required PhyCoding option,
})

Set the preferred connection (Android Only)

  • txPhy bitwise OR of all allowed phys for Tx, e.g. (Phy.le2m.mask | Phy.leCoded.mask)
  • txPhy bitwise OR of all allowed phys for Rx, e.g. (Phy.le2m.mask | Phy.leCoded.mask)
  • option preferred coding to use when transmitting on Phy.leCoded Please note that this is just a recommendation given to the system.

Implementation

Future<void> setPreferredPhy({
  required int txPhy,
  required int rxPhy,
  required PhyCoding option,
}) async {
  // check android
  if (Platform.isAndroid == false) {
    throw FlutterBluePlusException(ErrorPlatform.fbp, "setPreferredPhy",
        FbpErrorCode.androidOnly.index, "android-only");
  }

  // check connected
  if (isDisconnected) {
    throw FlutterBluePlusException(ErrorPlatform.fbp, "setPreferredPhy",
        FbpErrorCode.deviceIsDisconnected.index, "device is not connected");
  }

  var request = BmPreferredPhy(
    remoteId: remoteId,
    txPhy: txPhy,
    rxPhy: rxPhy,
    phyOptions: option.index,
  );

  // invoke
  await FlutterBluePlus._invokeMethod('setPreferredPhy', request.toMap());
}