Files
bluetooth_low_energy/bluetooth_low_energy_ios/my_api.dart
Mr剑侠客 689b1fb045 2.0.1 (#10)
* fix: 修复 iOS 和 macOS 断开后 GATT 被清理导致操作无法完成的问题

* fix: 调整 GATT 缓存

* fix: 修改 iOS 蓝牙使用描述

* fix: 修复无法通过设备地址生成 UUID 的问题,修复由于 bluez 未重写 hashCode 和 equals 导致无法比较缓存实例的问题

* fix: 修改版本信息

* fix: 修复BUG

* fix: 调整示例程序

* fix: 优化代码

* fix: 修改版本号

* fix: 更新 REDEME.md

* fix: 更新依赖项

* fix: 项目调整

---------

Co-authored-by: jetson2 <jetson2@const.cc>
2023-08-18 18:24:24 +08:00

152 lines
3.1 KiB
Dart

import 'package:pigeon/pigeon.dart';
@ConfigurePigeon(
PigeonOptions(
dartOut: 'lib/src/my_api.g.dart',
dartOptions: DartOptions(),
swiftOut: 'ios/Classes/MyApi.g.swift',
swiftOptions: SwiftOptions(),
),
)
@HostApi()
abstract class MyCentralControllerHostApi {
@async
MyCentralControllerArgs setUp();
void tearDown();
void startDiscovery();
void stopDiscovery();
@async
void connect(int myPeripheralKey);
@async
void disconnect(int myPeripheralKey);
@async
void discoverGATT(int myPeripheralKey);
List<MyGattServiceArgs> getServices(int myPeripheralKey);
List<MyGattCharacteristicArgs> getCharacteristics(int myServiceKey);
List<MyGattDescriptorArgs> getDescriptors(int myCharacteristicKey);
@async
Uint8List readCharacteristic(
int myPeripheralKey,
int myServiceKey,
int myCharacteristicKey,
);
@async
void writeCharacteristic(
int myPeripheralKey,
int myServiceKey,
int myCharacteristicKey,
Uint8List value,
int myTypeNumber,
);
@async
void notifyCharacteristic(
int myPeripheralKey,
int myServiceKey,
int myCharacteristicKey,
bool state,
);
@async
Uint8List readDescriptor(
int myPeripheralKey,
int myCharacteristicKey,
int myDescriptorKey,
);
@async
void writeDescriptor(
int myPeripheralKey,
int myCharacteristicKey,
int myDescriptorKey,
Uint8List value,
);
}
@FlutterApi()
abstract class MyCentralControllerFlutterApi {
void onStateChanged(int myStateNumber);
void onDiscovered(
MyPeripheralArgs myPeripheralArgs,
int rssi,
MyAdvertisementArgs myAdvertisementArgs,
);
void onPeripheralStateChanged(int myPeripheralKey, bool state);
void onCharacteristicValueChanged(int myCharacteristicKey, Uint8List value);
}
class MyCentralControllerArgs {
final int myStateNumber;
MyCentralControllerArgs(this.myStateNumber);
}
class MyPeripheralArgs {
final int key;
final String uuid;
MyPeripheralArgs(this.key, this.uuid);
}
class MyAdvertisementArgs {
final String? name;
final Map<int?, Uint8List?> manufacturerSpecificData;
final List<String?> serviceUUIDs;
final Map<String?, Uint8List?> serviceData;
MyAdvertisementArgs(
this.name,
this.manufacturerSpecificData,
this.serviceUUIDs,
this.serviceData,
);
}
class MyGattServiceArgs {
final int key;
final String uuid;
MyGattServiceArgs(this.key, this.uuid);
}
class MyGattCharacteristicArgs {
final int key;
final String uuid;
final List<int?> myPropertyNumbers;
MyGattCharacteristicArgs(
this.key,
this.uuid,
this.myPropertyNumbers,
);
}
class MyGattDescriptorArgs {
final int key;
final String uuid;
MyGattDescriptorArgs(this.key, this.uuid);
}
enum MyCentralStateArgs {
unknown,
unsupported,
unauthorized,
poweredOff,
poweredOn,
}
enum MyGattCharacteristicPropertyArgs {
read,
write,
writeWithoutResponse,
notify,
indicate,
}
enum MyGattCharacteristicWriteTypeArgs {
// Write with response
withResponse,
// Write without response
withoutResponse,
// Write with response and waiting for confirmation
// reliable,
}