feat:搜索模式,判断设备被重置的时候重置设备缓存列表
This commit is contained in:
parent
023067cdc0
commit
7f0087d153
@ -325,7 +325,8 @@ class BlueManage {
|
|||||||
mac != null) {
|
mac != null) {
|
||||||
scanSingleTimer?.cancel();
|
scanSingleTimer?.cancel();
|
||||||
//兼容android 的低配手机
|
//兼容android 的低配手机
|
||||||
await doNotSearchBLE(mac, connectStateCallBack);
|
await doNotSearchBLE(mac, connectStateCallBack,
|
||||||
|
isAddEquipment: isAddEquipment);
|
||||||
scanSingleTimer = Timer(3.seconds, () {
|
scanSingleTimer = Timer(3.seconds, () {
|
||||||
scanSingleTimer?.cancel();
|
scanSingleTimer?.cancel();
|
||||||
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
|
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
|
||||||
@ -384,6 +385,7 @@ class BlueManage {
|
|||||||
isAddEquipment == false) {
|
isAddEquipment == false) {
|
||||||
connectStateCallBack(BluetoothConnectionState.disconnected);
|
connectStateCallBack(BluetoothConnectionState.disconnected);
|
||||||
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds);
|
||||||
|
scanDevices.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//尝试连接设备
|
//尝试连接设备
|
||||||
@ -392,7 +394,8 @@ class BlueManage {
|
|||||||
|
|
||||||
//直接给蓝牙设备写入
|
//直接给蓝牙设备写入
|
||||||
Future<void> doNotSearchBLE(
|
Future<void> doNotSearchBLE(
|
||||||
String masAdds, ConnectStateCallBack connectStateCallBack) async {
|
String masAdds, ConnectStateCallBack connectStateCallBack,
|
||||||
|
{bool isAddEquipment = false}) async {
|
||||||
await FlutterBluePlus.stopScan();
|
await FlutterBluePlus.stopScan();
|
||||||
if (bluetoothConnectDevice == null ||
|
if (bluetoothConnectDevice == null ||
|
||||||
bluetoothConnectDevice?.remoteId.str != masAdds) {
|
bluetoothConnectDevice?.remoteId.str != masAdds) {
|
||||||
@ -401,12 +404,14 @@ class BlueManage {
|
|||||||
_initListenConnectionState();
|
_initListenConnectionState();
|
||||||
}
|
}
|
||||||
//尝试连接设备
|
//尝试连接设备
|
||||||
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
|
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack,
|
||||||
|
isAddEquipment: isAddEquipment);
|
||||||
}
|
}
|
||||||
|
|
||||||
//设备连接
|
//设备连接
|
||||||
Future<void> bluetoothDeviceConnect(BluetoothDevice bluetoothConnectDevice,
|
Future<void> bluetoothDeviceConnect(BluetoothDevice bluetoothConnectDevice,
|
||||||
ConnectStateCallBack connectStateCallBack) async {
|
ConnectStateCallBack connectStateCallBack,
|
||||||
|
{bool isAddEquipment = false}) async {
|
||||||
// 重连三次
|
// 重连三次
|
||||||
const int maxAttempts = 3;
|
const int maxAttempts = 3;
|
||||||
int attempt = 0;
|
int attempt = 0;
|
||||||
@ -430,23 +435,22 @@ class BlueManage {
|
|||||||
|
|
||||||
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
||||||
try {
|
try {
|
||||||
bluetoothConnectDevice!
|
final List<BluetoothService> services =
|
||||||
.discoverServices()
|
await bluetoothConnectDevice.discoverServices();
|
||||||
.then((List<BluetoothService> services) {
|
//循环判断服务
|
||||||
for (final BluetoothService service in services) {
|
for (final BluetoothService service in services) {
|
||||||
if (service.uuid == _serviceIdConnect) {
|
if (service.uuid == _serviceIdConnect) {
|
||||||
for (final BluetoothCharacteristic characteristic
|
for (final BluetoothCharacteristic characteristic
|
||||||
in service.characteristics) {
|
in service.characteristics) {
|
||||||
if (characteristic.characteristicUuid ==
|
if (characteristic.characteristicUuid ==
|
||||||
_characteristicIdSubscription) {
|
_characteristicIdSubscription) {
|
||||||
_subScribeToCharacteristic(characteristic);
|
_subScribeToCharacteristic(characteristic);
|
||||||
bluetoothConnectionState = BluetoothConnectionState.connected;
|
bluetoothConnectionState = BluetoothConnectionState.connected;
|
||||||
connectStateCallBack(bluetoothConnectionState!);
|
connectStateCallBack(bluetoothConnectionState!);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
bluetoothConnectionState = BluetoothConnectionState.disconnected;
|
bluetoothConnectionState = BluetoothConnectionState.disconnected;
|
||||||
connectStateCallBack(bluetoothConnectionState!);
|
connectStateCallBack(bluetoothConnectionState!);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user