feat: 支持获取 maximumWrtieLength (#14)
This commit is contained in:
@ -380,6 +380,33 @@ class MyCentralControllerHostApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> getMaximumWriteLength(int arg_myPeripheralKey, int arg_myTypeNumber) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.getMaximumWriteLength', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_myPeripheralKey, arg_myTypeNumber]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as int?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> discoverGATT(int arg_myPeripheralKey) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.discoverGATT', codec,
|
||||
|
@ -114,6 +114,22 @@ class MyCentralController extends CentralController
|
||||
await _myApi.disconnect(myPeripheral.hashCode);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> getMaximumWriteLength(
|
||||
Peripheral peripheral, {
|
||||
required GattCharacteristicWriteType type,
|
||||
}) async {
|
||||
await _throwWithoutState(CentralState.poweredOn);
|
||||
final myPeripheral = peripheral as MyPeripheral;
|
||||
final myTypeArgs = type.toMyArgs();
|
||||
final myTypeNumber = myTypeArgs.index;
|
||||
final maximumWriteLength = await _myApi.getMaximumWriteLength(
|
||||
myPeripheral.hashCode,
|
||||
myTypeNumber,
|
||||
);
|
||||
return maximumWriteLength;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> discoverGATT(Peripheral peripheral) async {
|
||||
await _throwWithoutState(CentralState.poweredOn);
|
||||
@ -206,14 +222,14 @@ class MyCentralController extends CentralController
|
||||
final myCharacteristic = characteristic as MyGattCharacteristic;
|
||||
final myService = myCharacteristic.myService;
|
||||
final myPeripheral = myService.myPeripheral;
|
||||
final typeArgs = type.toMyArgs();
|
||||
final typeNumber = typeArgs.index;
|
||||
final myTypeArgs = type.toMyArgs();
|
||||
final myTypeNumber = myTypeArgs.index;
|
||||
await _myApi.writeCharacteristic(
|
||||
myPeripheral.hashCode,
|
||||
myService.hashCode,
|
||||
myCharacteristic.hashCode,
|
||||
value,
|
||||
typeNumber,
|
||||
myTypeNumber,
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user