feat:搜索模式,判断设备被重置的时候重置设备缓存列表

This commit is contained in:
anfe 2024-06-06 11:28:02 +08:00
parent 023067cdc0
commit 7f0087d153

View File

@ -325,7 +325,8 @@ class BlueManage {
mac != null) {
scanSingleTimer?.cancel();
//android
await doNotSearchBLE(mac, connectStateCallBack);
await doNotSearchBLE(mac, connectStateCallBack,
isAddEquipment: isAddEquipment);
scanSingleTimer = Timer(3.seconds, () {
scanSingleTimer?.cancel();
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
@ -384,6 +385,7 @@ class BlueManage {
isAddEquipment == false) {
connectStateCallBack(BluetoothConnectionState.disconnected);
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
scanDevices.clear();
return;
}
//
@ -392,7 +394,8 @@ class BlueManage {
//
Future<void> doNotSearchBLE(
String masAdds, ConnectStateCallBack connectStateCallBack) async {
String masAdds, ConnectStateCallBack connectStateCallBack,
{bool isAddEquipment = false}) async {
await FlutterBluePlus.stopScan();
if (bluetoothConnectDevice == null ||
bluetoothConnectDevice?.remoteId.str != masAdds) {
@ -401,12 +404,14 @@ class BlueManage {
_initListenConnectionState();
}
//
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack,
isAddEquipment: isAddEquipment);
}
//
Future<void> bluetoothDeviceConnect(BluetoothDevice bluetoothConnectDevice,
ConnectStateCallBack connectStateCallBack) async {
ConnectStateCallBack connectStateCallBack,
{bool isAddEquipment = false}) async {
//
const int maxAttempts = 3;
int attempt = 0;
@ -430,23 +435,22 @@ class BlueManage {
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
try {
bluetoothConnectDevice!
.discoverServices()
.then((List<BluetoothService> services) {
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic
in service.characteristics) {
if (characteristic.characteristicUuid ==
_characteristicIdSubscription) {
_subScribeToCharacteristic(characteristic);
bluetoothConnectionState = BluetoothConnectionState.connected;
connectStateCallBack(bluetoothConnectionState!);
}
final List<BluetoothService> services =
await bluetoothConnectDevice.discoverServices();
//
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic
in service.characteristics) {
if (characteristic.characteristicUuid ==
_characteristicIdSubscription) {
_subScribeToCharacteristic(characteristic);
bluetoothConnectionState = BluetoothConnectionState.connected;
connectStateCallBack(bluetoothConnectionState!);
}
}
}
});
}
} on Exception catch (e) {
bluetoothConnectionState = BluetoothConnectionState.disconnected;
connectStateCallBack(bluetoothConnectionState!);