Browse Source

上传烧苗启动angent服务

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
efc0a05e20
  1. 44
      lib/modules/pairing/controllers/pairing_controller.dart

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

@ -122,32 +122,27 @@ class PairingController extends GetxController {
/// 监听蓝牙开关状态
void _setupBluetoothStateListener() {
_workers.add(
ever(_bluetoothManager.bluetoothStateRx, (String state) {
_workers.add(ever(_bluetoothManager.bluetoothStateRx, (String state) {
Logger.d(_tag, '蓝牙状态变化: $state');
_handleBluetoothStateChange(state);
})
);
}));
}
/// 监听经典蓝牙连接状态
void _setupClassicConnectionListener() {
_workers.add(
ever(_bluetoothManager.currentDeviceRx, (BluetoothDevice? device) {
_workers
.add(ever(_bluetoothManager.currentDeviceRx, (BluetoothDevice? device) {
Logger.d(_tag, '经典蓝牙设备变化: ${device?.name}');
_handleClassicDeviceChange(device);
})
);
}));
}
/// 监听BLE连接状态
void _setupBleConnectionListener() {
_workers.add(
ever(_bleManager.connectionStateRx, (int state) {
_workers.add(ever(_bleManager.connectionStateRx, (int state) {
Logger.d(_tag, 'BLE连接状态变化: $state');
_handleBleStateChange(state);
})
);
}));
}
// ==================== 状态处理 ====================
@ -209,7 +204,8 @@ class PairingController extends GetxController {
/// 处理BLE状态变化
void _handleBleStateChange(int state) {
if (_currentState.value == PairingState.waitingBle) {
if (state == 2) { // BLE已连接
if (state == 2) {
// BLE已连接
_bleTimeoutTimer?.cancel();
_transition(PairingState.completed);
}
@ -371,7 +367,6 @@ class PairingController extends GetxController {
_currentClassicDevice = classicDevice;
_transition(PairingState.verifying);
await _verifyDevice(classicDevice);
} catch (e) {
Logger.e(_tag, '状态检查失败: $e');
_setError(ErrorType.networkError, '检查失败,请重试');
@ -405,7 +400,8 @@ class PairingController extends GetxController {
// 检查设备名称是否包含 DeepSound 或 DeapSound
final deviceName = device.name ?? '';
if (deviceName.contains('DeepSound') || deviceName.contains('DeapSound')) {
if (deviceName.contains('DeepSound') ||
deviceName.contains('DeapSound')) {
Logger.i(_tag, '设备验证通过');
_verifiedDeviceAddress = device.address;
@ -413,13 +409,15 @@ class PairingController extends GetxController {
final pairedMacAddress = await _bleManager.getPairedMacAddress();
Logger.i(_tag, '已关联的MAC地址: $pairedMacAddress');
if (pairedMacAddress != null && pairedMacAddress.toUpperCase() == device.address.toUpperCase()) {
if (pairedMacAddress != null &&
pairedMacAddress.toUpperCase() == device.address.toUpperCase()) {
// 已有关联,检查BLE连接状态
Logger.i(_tag, '设备已关联,检查BLE连接状态');
final currentBleState = await _bleManager.getConnectionState();
Logger.i(_tag, '验证时BLE状态: $currentBleState');
if (currentBleState == 2) { // BleConnectionState.connected
if (currentBleState == 2) {
// BleConnectionState.connected
Logger.i(_tag, 'BLE已连接,直接完成配对');
_transition(PairingState.completed);
} else {
@ -484,7 +482,8 @@ class PairingController extends GetxController {
final currentBleState = await _bleManager.getConnectionState();
Logger.i(_tag, 'BLE当前连接状态: $currentBleState');
if (currentBleState == 2) { // BleConnectionState.connected
if (currentBleState == 2) {
// BleConnectionState.connected
Logger.i(_tag, 'BLE已经连接,直接完成配对');
_bleTimeoutTimer?.cancel();
_transition(PairingState.completed);
@ -493,7 +492,8 @@ class PairingController extends GetxController {
// 注册后台扫描以开始BLE配对
if (_verifiedDeviceAddress != null) {
final success = await _bleManager.registerBackgroundScan(macAddress: _verifiedDeviceAddress);
final success = await _bleManager.registerBackgroundScan(
macAddress: _verifiedDeviceAddress);
if (!success && _currentState.value == PairingState.waitingBle) {
_setError(ErrorType.bleTimeout, 'BLE配对启动失败');
}
@ -505,7 +505,8 @@ class PairingController extends GetxController {
}
/// 导航到主页
void _navigateToHome() {
void _navigateToHome() async {
await BleManager.to.startAgentService();
Future.delayed(const Duration(seconds: 1), () {
Get.offAllNamed(Routes.home);
});
@ -563,7 +564,8 @@ class PairingController extends GetxController {
}
/// 用户点击跳过按钮
void onSkipTap() {
void onSkipTap() async {
await BleManager.to.startAgentService();
Logger.i(_tag, '用户选择跳过配对');
Get.offAllNamed(Routes.home);
}

Loading…
Cancel
Save