|
|
|
@ -76,6 +76,9 @@ class PairingController extends GetxController { |
|
|
|
|
|
|
|
bool isShowSkipButton = false; //是否显示跳过按钮 |
|
|
|
|
|
|
|
final availableDevices = <BluetoothDevice>[].obs; // 可用设备列表 |
|
|
|
final selectedDevice = Rx<BluetoothDevice?>(null); // 用户选中的设备 |
|
|
|
|
|
|
|
// ========== 监听器管理 ========== |
|
|
|
final List<Worker> _workers = []; |
|
|
|
Timer? _bleTimeoutTimer; |
|
|
|
@ -601,13 +604,23 @@ class PairingController extends GetxController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//自动绑定设备 0 未合作商 1 合作商 2,已绑定 |
|
|
|
//自动绑定设备 0 未合作商 1 合作商 9经典蓝牙已绑定 10,ble蓝牙已绑定 |
|
|
|
Future<int> authbindingDevice(BluetoothDevice device) async { |
|
|
|
// if (User.instance.earphoneauthcode != "" && |
|
|
|
// User.instance.earphonemac == device.address) { |
|
|
|
// // 已经绑定 |
|
|
|
// return 9; |
|
|
|
// } |
|
|
|
// 检查是否已有绑定的设备 |
|
|
|
final existingDevice = User.instance.devices.firstWhere( |
|
|
|
(d) => d.devicetype == 0 && d.devicemac == device.address, |
|
|
|
orElse: () => UserDevice( |
|
|
|
id: -1, |
|
|
|
uid: '', |
|
|
|
devicetype: -1, |
|
|
|
devicename: '', |
|
|
|
devicemac: '', |
|
|
|
license: ''), |
|
|
|
); |
|
|
|
if (existingDevice.id != -1) { |
|
|
|
// 已经绑定 |
|
|
|
return 9; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查设备名称是否包含 DeepSound 或 DeapSound |
|
|
|
final deviceName = device.name; |
|
|
|
@ -663,14 +676,26 @@ class PairingController extends GetxController { |
|
|
|
_bleManager.stopScan(); |
|
|
|
deviceCode.value = code; |
|
|
|
_verifiedDeviceAddress = device.address; |
|
|
|
// 检查是否已经绑定 |
|
|
|
// if (User.instance.earphonelicense != "" && |
|
|
|
// User.instance.earphonemac == device.address) { |
|
|
|
// // 已经绑定 |
|
|
|
// return 10; |
|
|
|
// } else { |
|
|
|
return 1; |
|
|
|
// } |
|
|
|
//检查是否已经绑定 |
|
|
|
final existingDevice = User.instance.devices.firstWhere( |
|
|
|
(d) => |
|
|
|
d.devicetype == 2 && |
|
|
|
d.license != "" && |
|
|
|
d.devicemac == device.address, |
|
|
|
orElse: () => UserDevice( |
|
|
|
id: -1, |
|
|
|
uid: '', |
|
|
|
devicetype: -1, |
|
|
|
devicename: '', |
|
|
|
devicemac: '', |
|
|
|
license: ''), |
|
|
|
); |
|
|
|
if (existingDevice.id != -1) { |
|
|
|
// 已经绑定 |
|
|
|
return 10; |
|
|
|
} else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
break; |
|
|
|
@ -681,9 +706,13 @@ class PairingController extends GetxController { |
|
|
|
} |
|
|
|
await Future.delayed(Duration(seconds: 1)); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
//可以跳转1 |
|
|
|
else { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -919,4 +948,13 @@ class PairingController extends GetxController { |
|
|
|
Logger.e(_tag, '清除设备关联失败: $e'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 用户选择设备后调用 |
|
|
|
void onDeviceSelected(BluetoothDevice device) { |
|
|
|
Logger.i(_tag, '用户选择了设备: ${device.name} (${device.address})'); |
|
|
|
selectedDevice.value = device; |
|
|
|
_currentClassicDevice = device; |
|
|
|
_transition(PairingState.verifying); |
|
|
|
_verifyDevice(device); |
|
|
|
} |
|
|
|
} |
|
|
|
|