Browse Source

上传蓝牙连接 流程调整 方便测试

weicu
liwei1dao 1 year ago
parent
commit
f2b035f4f8
  1. 14
      lib/modules/pairing/controllers/pairing_controller.dart

14
lib/modules/pairing/controllers/pairing_controller.dart

@ -186,13 +186,11 @@ class PairingController extends GetxController {
Logger.info('蓝牙已关闭'); Logger.info('蓝牙已关闭');
} }
}); });
Logger.info('liwei----------------- _setupServiceStateListeners 1');
// 监听当前设备变化 - 使用公开的currentDeviceRx字段 // 监听当前设备变化 - 使用公开的currentDeviceRx字段
_deviceWorker = _deviceWorker =
ever(_bluetoothService.currentDeviceRx, (BluetoothDevice? device) { ever(_bluetoothService.currentDeviceRx, (BluetoothDevice? device) {
if (device != null && !_isNavigatingToHome) { if (device != null && !_isNavigatingToHome) {
Logger.info('配对页面发现设备已连接: ${device.name}'); Logger.info('配对页面发现设备已连接: ${device.name}');
Logger.info('liwei----------------- _setupServiceStateListeners 2');
// 当经典蓝牙设备连接成功,尝试进行Companion关联 // 当经典蓝牙设备连接成功,尝试进行Companion关联
_handleDeviceConnected(); _handleDeviceConnected();
} }
@ -202,15 +200,12 @@ class PairingController extends GetxController {
/// 处理设备连接成功事件 /// 处理设备连接成功事件
Future<void> _handleDeviceConnected() async { Future<void> _handleDeviceConnected() async {
Logger.info('liwei----------------- _handleDeviceConnected 1');
if (!isDeviceConnected || _isNavigatingToHome) return; if (!isDeviceConnected || _isNavigatingToHome) return;
Logger.info('liwei----------------- _handleDeviceConnected 2');
// 如果已经完成关联,直接跳转 // 如果已经完成关联,直接跳转
if (_companionAssociated.value) { if (_companionAssociated.value) {
_autoNavigateToHome(); _autoNavigateToHome();
return; return;
} }
Logger.info('liwei----------------- _handleDeviceConnected 3');
// 启动关联流程 // 启动关联流程
_startCompanionAssociation(); _startCompanionAssociation();
} }
@ -283,7 +278,6 @@ class PairingController extends GetxController {
/// 启动Companion设备关联流程 /// 启动Companion设备关联流程
Future<void> _startCompanionAssociation() async { Future<void> _startCompanionAssociation() async {
Logger.info('liwei----------------- _startCompanionAssociation 1');
// 如果不是Android平台,已经跳转到首页,已经完成关联或正在进行关联,直接返回 // 如果不是Android平台,已经跳转到首页,已经完成关联或正在进行关联,直接返回
if (!Platform.isAndroid || if (!Platform.isAndroid ||
_isNavigatingToHome || _isNavigatingToHome ||
@ -291,7 +285,6 @@ class PairingController extends GetxController {
_isAssociating) { _isAssociating) {
return; return;
} }
Logger.info('liwei----------------- _startCompanionAssociation 2');
// 设置关联状态标志 // 设置关联状态标志
_isAssociating = true; _isAssociating = true;
_updateStatusDescription(); _updateStatusDescription();
@ -305,7 +298,6 @@ class PairingController extends GetxController {
_autoNavigateToHome(); _autoNavigateToHome();
return; return;
} }
Logger.info('liwei----------------- _startCompanionAssociation 3');
// 检查是否已有配对的MAC地址 // 检查是否已有配对的MAC地址
final pairedMac = await _bleService.getPairedMacAddress(); final pairedMac = await _bleService.getPairedMacAddress();
if (pairedMac != null) { if (pairedMac != null) {
@ -314,6 +306,7 @@ class PairingController extends GetxController {
Logger.info('已关联的Companion设备与当前连接的设备一致'); Logger.info('已关联的Companion设备与当前连接的设备一致');
_companionAssociated.value = true; _companionAssociated.value = true;
await _bleService.registerBackgroundScan(); await _bleService.registerBackgroundScan();
// 调试情况下注释 保证正常能启动服务
// _autoNavigateToHome(); // _autoNavigateToHome();
// return; // return;
} else { } else {
@ -322,7 +315,6 @@ class PairingController extends GetxController {
await _bleService.clearAssociations(); await _bleService.clearAssociations();
} }
} }
Logger.info('liwei----------------- _startCompanionAssociation 4');
// 开始关联流程 // 开始关联流程
if (currentDevice != null) { if (currentDevice != null) {
Logger.info('开始Companion设备关联流程, 设备MAC: ${currentDevice!.address}'); Logger.info('开始Companion设备关联流程, 设备MAC: ${currentDevice!.address}');
@ -331,7 +323,8 @@ class PairingController extends GetxController {
deviceNamePattern: currentDevice!.name, deviceNamePattern: currentDevice!.name,
macAddress: currentDevice!.address, macAddress: currentDevice!.address,
); );
success = true; Logger.info('Companion设备关联结果: $success');
success = true; //李伟测试用,去掉关联流程
if (success) { if (success) {
Logger.info('Companion设备关联成功'); Logger.info('Companion设备关联成功');
_companionAssociated.value = true; _companionAssociated.value = true;
@ -339,7 +332,6 @@ class PairingController extends GetxController {
// 注册后台扫描,确保应用被杀死后仍能被唤醒 // 注册后台扫描,确保应用被杀死后仍能被唤醒
await _bleService.registerBackgroundScan( await _bleService.registerBackgroundScan(
macAddress: currentDevice!.address); macAddress: currentDevice!.address);
Logger.info('liwei----------------- _startCompanionAssociation 5');
// 启动BLE后台服务(可选) // 启动BLE后台服务(可选)
await _startAgentService(); await _startAgentService();

Loading…
Cancel
Save