* feat: 重构项目 * feat: 添加 bluez_central_manager * feat: 联合插件 * feat: 拆分项目 * feat: 实现 linux 部分接口 * feat: 重新创建项目 * feat: 定义接口 * feat: 实现接入插件 * feat: 清空接入插件示例代码 * feat: 开发 linux 插件 * feat: 调整接口 * 临时提交 * feat: 实现 Android 接口 * fix: 修复 Android 问题 * fix: 移除多余文件 * feat: 重构项目 (#5) * fix: 移除多余的状态判断 * fix: 外围设备断开时检查是否存在未完成的操作 * feat: 尝试使用 win32 实现接口 * fix: 修复大小写问题 * feat: 实现 macOS 接口 * feat: 实现 macOS 接口 * fix:支持使用16位短字符串生成UUID * fix: 修复未清理已完成操作的问题 * fix: 规范命名 * 添加蓝牙使用描述 * fix: 更新 README.md
141 lines
2.9 KiB
Dart
141 lines
2.9 KiB
Dart
import 'package:pigeon/pigeon.dart';
|
|
|
|
@ConfigurePigeon(
|
|
PigeonOptions(
|
|
dartOut: 'lib/src/my_api.g.dart',
|
|
dartOptions: DartOptions(),
|
|
swiftOut: 'macos/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 myCharacteristicKey);
|
|
@async
|
|
void writeCharacteristic(
|
|
int myPeripheralKey,
|
|
int myCharacteristicKey,
|
|
Uint8List value,
|
|
int myTypeNumber,
|
|
);
|
|
@async
|
|
void notifyCharacteristic(
|
|
int myPeripheralKey,
|
|
int myCharacteristicKey,
|
|
bool state,
|
|
);
|
|
@async
|
|
Uint8List readDescriptor(int myPeripheralKey, int myDescriptorKey);
|
|
@async
|
|
void writeDescriptor(
|
|
int myPeripheralKey,
|
|
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,
|
|
}
|