From e23d241f8c84653963309a4647e897b5d56fb769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Tue, 9 Jan 2024 13:51:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/lib/appRouters.dart | 2 +- star_lock/lib/blue/blue_manage.dart | 30 +++++++++++-------- .../lcokSet/lockSet/lockSet_logic.dart | 24 +++++++-------- .../lockDetail/lockDetail_logic.dart | 6 ++-- .../lockDetail/lockDetail_page.dart | 4 +++ .../realTimePicture_logic.dart | 2 +- .../realTimePicture/realTimePicture_page.dart | 2 +- .../realTimePicture_state.dart | 0 8 files changed, 38 insertions(+), 32 deletions(-) rename star_lock/lib/main/lockDetail/{lockDetail => }/realTimePicture/realTimePicture_logic.dart (99%) rename star_lock/lib/main/lockDetail/{lockDetail => }/realTimePicture/realTimePicture_page.dart (99%) rename star_lock/lib/main/lockDetail/{lockDetail => }/realTimePicture/realTimePicture_state.dart (100%) diff --git a/star_lock/lib/appRouters.dart b/star_lock/lib/appRouters.dart index f4b0beb6..7038a57e 100644 --- a/star_lock/lib/appRouters.dart +++ b/star_lock/lib/appRouters.dart @@ -15,7 +15,6 @@ import 'package:star_lock/main/lockDetail/lcokSet/msgNotification/msgNotificatio import 'package:star_lock/main/lockDetail/lcokSet/notificationMode/notificationMode_page.dart'; import 'package:star_lock/main/lockDetail/lcokSet/openDoorDirection/openDoorDirection_page.dart'; import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_main_page.dart'; -import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyDetailChangeDate/passwordKeyDetailChangeDate_page.dart'; import 'package:star_lock/mine/about/webviewShow_page.dart'; import 'package:star_lock/mine/mine/safeVerify/safeVerify_page.dart'; @@ -101,6 +100,7 @@ import 'main/lockDetail/lcokSet/wirelessKeyboard/seletWirelessKeyboard/seletWire import 'main/lockDetail/lcokSet/wirelessKeyboard/wirelessKeyboardList/wirelessKeyboard_page.dart'; import 'main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart'; import 'main/lockDetail/monitoring/monitoringRealTimeScreen/monitoringRealTimeScreen_page.dart'; +import 'main/lockDetail/realTimePicture/realTimePicture_page.dart'; import 'main/lockDetail/remoteControl/addRemoteControl/addRemoteControlManage/addRemoteControlManage_page.dart'; import 'main/lockDetail/remoteControl/remoteControlList/remoteControlList_page.dart'; import 'main/lockDetail/videoLog/editVideoLog/editVideoLog_page.dart'; diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 7a3b5c9f..02800e0d 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -114,6 +114,7 @@ class BlueManage { // 蓝牙已开启,可以进行蓝牙操作 if(deviceConnectionState != DeviceConnectionState.connected){ if(isAddEquipment == false){ + // print("666666666"); startScan(); } @@ -121,6 +122,7 @@ class BlueManage { stateCallBack(deviceConnectionState!); }); }else{ + stopScan(); stateCallBack(deviceConnectionState!); } }else{ @@ -137,34 +139,32 @@ class BlueManage { if (knownDeviceIndex >= 0) { // 存在的时候赋值 connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; - stopScan(); } else { // 不存在的时候返回-1 然后循环5秒 var index = 0; Completer? completer = Completer(); - Timer.periodic(const Duration(seconds: 1), (timer) { + Timer.periodic(const Duration(seconds: 1), (timer) async { ///定时任务 // print("timer index0:$index"); if(index >= 9){ // 当超过5秒的时候取消定时任务 弹窗显示连接失败 - completer.complete(); - stopScan(); - timer.cancel(); connectDeviceMacAddress = ""; + connectStateCallBack(DeviceConnectionState.disconnected); + completer.complete(); + await stopScan(); + timer.cancel(); // deviceConnectionState = DeviceConnectionState.disconnected; // print("timer index1:$index"); - connectStateCallBack(DeviceConnectionState.disconnected); }else{ // 每秒判断数组列表里面是否有这个设备 final knownDeviceIndex = scanDevices.indexWhere((d) => d.name == deviceName); if (knownDeviceIndex >= 0) { // 存在的时候销毁定时器,赋值 + connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; completer.complete(); - stopScan(); timer.cancel(); // print("timer index2:$index"); - connectDeviceMacAddress = scanDevices[knownDeviceIndex].id; // var uuidStr = (scanDevices[knownDeviceIndex].serviceUuids.isNotEmpty ? scanDevices[knownDeviceIndex].serviceUuids[0] : "").toString(); // if(uuidStr[31] == "0"){ @@ -184,16 +184,17 @@ class BlueManage { // 等待Completer完成 await completer.future; } - print("connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); - + print("1 connectDeviceId:$connectDeviceMacAddress connectDeviceName:$connectDeviceName"); + await stopScan(); if (connectDeviceMacAddress.isEmpty) { return; } + // print("33333333333333333333333"); _currentConnectionStream = _flutterReactiveBle!.connectToDevice(id: connectDeviceMacAddress, connectionTimeout: const Duration(seconds: 5)).listen((connectionStateUpdate) async { // 获取状态 deviceConnectionState = connectionStateUpdate.connectionState; - print('deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}'); + print('2 deviceConnectionState:$deviceConnectionState connectionStateUpdate.connectionState:${connectionStateUpdate.connectionState}'); if (connectionStateUpdate.connectionState == DeviceConnectionState.connected) { // 如果状态是连接的开始发现服务 try { @@ -326,7 +327,9 @@ class BlueManage { // 停止扫描蓝牙设备 Future stopScan() async { + // print("444444444"); if(_scanSubscription != null){ + // print("555555555555"); _scanSubscription?.cancel(); _scanSubscription = null; } @@ -335,10 +338,11 @@ class BlueManage { // 断开连接 Future disconnect(String deviceMAC) async { try { - if(_currentConnectionStream != null){ + connectDeviceMacAddress = ""; + // if(_currentConnectionStream != null){ _currentConnectionStream?.cancel(); _currentConnectionStream = null; - } + // } print('disconnecting to device: $deviceMAC'); } on Exception catch (e, _) { diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart index e9d6eece..31f3c01e 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_logic.dart @@ -501,18 +501,18 @@ class LockSetLogic extends BaseGetXController { if (entity.errorCode!.codeIsSuccessful) { Get.back(); - // if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){ - // // 如果是已连接状态 直接调用协议 - // // 已配对 表示这把锁未被初始化,还处于被添加状态 - // if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { - // // 如果是锁拥有者直接删除锁,调用初始化协议 - // factoryDataResetAction(); - // } else { - // // 不是锁拥有者,调用删除钥匙协议 - // deletUserAction(); - // } - // return; - // } + if(BlueManage().deviceConnectionState == DeviceConnectionState.connected){ + // 如果是已连接状态 直接调用协议 + // 已配对 表示这把锁未被初始化,还处于被添加状态 + if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { + // 如果是锁拥有者直接删除锁,调用初始化协议 + factoryDataResetAction(); + } else { + // 不是锁拥有者,调用删除钥匙协议 + deletUserAction(); + } + return; + } if (state.currentDeviceUUid.value.isNotEmpty) { // 已经扫描到了当前设备 停止扫描,直接删除锁 diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index 3aa17108..520529ce 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -410,6 +410,8 @@ class LockDetailLogic extends BaseGetXController { Future openDoorAction(int openMode) async { showBlueConnetctToastTimer(action:() { state.openLockBtnState.value = 0; + BlueManage().stopScan(); + // state.animationController.reset(); // state.animationController.forward(); }); @@ -578,10 +580,6 @@ class LockDetailLogic extends BaseGetXController { } } - longPressCloseDoor(){ - - } - // 获取手机联网token,根据锁设置里面获取的开锁时是否联网来判断是否调用这个接口 void getLockNetToken() async { LockNetTokenEntity entity = await ApiRepository.to diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart index acd6f7d8..b6f7dba7 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_page.dart @@ -634,6 +634,8 @@ class _LockDetailPageState extends State // print("LockDetailPage===didPop"); state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); + BlueManage().stopScan(); + state.openLockBtnState.value = 0; state.animationController.reset(); state.animationController.forward(); state.animationController.dispose(); @@ -654,6 +656,8 @@ class _LockDetailPageState extends State // print("LockDetailPage===didPushNext"); state.ifCurrentScreen.value = false; logic.cancelBlueConnetctToastTimer(); + BlueManage().stopScan(); + state.openLockBtnState.value = 0; state.animationController.reset(); state.animationController.forward(); } diff --git a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart b/star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_logic.dart similarity index 99% rename from star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart rename to star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_logic.dart index 3b10ae03..d4110e4d 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart +++ b/star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_logic.dart @@ -5,7 +5,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_voice_processor/flutter_voice_processor.dart'; import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_state.dart'; import 'package:star_lock/talk/call/callTalk.dart'; import '../../../../talk/call/g711.dart'; @@ -13,6 +12,7 @@ import '../../../../talk/udp/udp_manage.dart'; import '../../../../talk/udp/udp_senderManage.dart'; import '../../../../tools/baseGetXController.dart'; import '../../../../tools/eventBusEventManage.dart'; +import 'realTimePicture_state.dart'; class RealTimePictureLogic extends BaseGetXController { final RealTimePictureState state = RealTimePictureState(); diff --git a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart b/star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_page.dart similarity index 99% rename from star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart rename to star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_page.dart index fccb2fea..2130c048 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_page.dart +++ b/star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_page.dart @@ -4,11 +4,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/showTFView.dart'; import '../../../../tools/toast.dart'; +import 'realTimePicture_logic.dart'; class RealTimePicturePage extends StatefulWidget { const RealTimePicturePage({Key? key}) : super(key: key); diff --git a/star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_state.dart b/star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_state.dart similarity index 100% rename from star_lock/lib/main/lockDetail/lockDetail/realTimePicture/realTimePicture_state.dart rename to star_lock/lib/main/lockDetail/realTimePicture/realTimePicture_state.dart