优化蓝牙功能

This commit is contained in:
魏少阳 2023-10-12 14:00:49 +08:00
parent 55ea66a535
commit 13ad3117c1
7 changed files with 116 additions and 40 deletions

View File

@ -73,7 +73,7 @@ class BlueManage{
if(device.name.isEmpty){ if(device.name.isEmpty){
return; return;
} }
print("startScanDevice:${device}"); // print("startScanDevice:${device}");
// //
if(isScanAll == true){ if(isScanAll == true){
if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString().contains("758824"))&& (device.rssi >= -100)) { if (((device.serviceUuids.isNotEmpty ? device.serviceUuids[0] : "").toString().contains("758824"))&& (device.rssi >= -100)) {

View File

@ -53,6 +53,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
Expanded( Expanded(
child: ListView( child: ListView(
children: [ children: [
//
CommonItem( CommonItem(
leftTitel: leftTitel:
TranslationLoader.lanKeys!.basicInformation!.tr, TranslationLoader.lanKeys!.basicInformation!.tr,
@ -65,18 +66,20 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
}); });
}), }),
SizedBox(height: 10.h,), SizedBox(height: 10.h,),
//
Visibility( Visibility(
visible: true, visible: true,
child:CommonItem( child:CommonItem(
leftTitel: TranslationLoader.lanKeys!.doorMagnetic!.tr, leftTitel: TranslationLoader.lanKeys!.doorMagnetic!.tr,
rightTitle: "", rightTitle: "",
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Get.toNamed(Routers.doorMagneticPage); // Get.toNamed(Routers.doorMagneticPage);
// Toast.show(msg: "功能暂未开放"); Toast.show(msg: "功能暂未开放");
}) })
), ),
// 线
Visibility( Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
@ -86,11 +89,12 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
isHaveLine: false, isHaveLine: false,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Get.toNamed(Routers.wirelessKeyboardPage); // Get.toNamed(Routers.wirelessKeyboardPage);
// Toast.show(msg: "功能暂未开放"); Toast.show(msg: "功能暂未开放");
}) })
), ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
//
Obx(() => Visibility( Obx(() => Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
@ -106,6 +110,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
arguments: state.getKeyInfosData.value); arguments: state.getKeyInfosData.value);
})) }))
), ),
//
Obx(() { Obx(() {
var titleStr = ""; var titleStr = "";
if (state.getKeyInfosData.value.lockSound == 1) { if (state.getKeyInfosData.value.lockSound == 1) {
@ -142,6 +147,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
}) })
); );
}), }),
//
Obx(() => Visibility( Obx(() => Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
@ -156,6 +162,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
arguments: state.getKeyInfosData.value); arguments: state.getKeyInfosData.value);
}))), }))),
SizedBox(height: 10.h), SizedBox(height: 10.h),
//
Obx(() => Visibility( Obx(() => Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
@ -171,6 +178,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
arguments: state.getKeyInfosData.value); arguments: state.getKeyInfosData.value);
})) }))
), ),
//
Obx(() => Visibility( Obx(() => Visibility(
visible:true, visible:true,
child: CommonItem( child: CommonItem(
@ -185,6 +193,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
arguments: state.getKeyInfosData.value); arguments: state.getKeyInfosData.value);
})) }))
), ),
//
Obx(() => Visibility( Obx(() => Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
@ -210,16 +219,19 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
isHaveLine: true, isHaveLine: true,
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: rightWidget:
SizedBox(width: 60.w, child: _openCheckInSwitch()))), SizedBox(width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ), // ),
// Obx(() => // Obx(() =>
Visibility( Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
leftTitel: '感应距离', leftTitel: '感应距离',
rightTitle: "", rightTitle: "",
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
}
)), )),
// ), // ),
// Obx(() => // Obx(() =>
@ -231,7 +243,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
isHaveLine: true, isHaveLine: true,
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: rightWidget:
SizedBox(width: 60.w, child: _openCheckInSwitch()))), SizedBox(width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ), // ),
// Obx(() => // Obx(() =>
Visibility( Visibility(
@ -242,7 +254,7 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
isHaveLine: true, isHaveLine: true,
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: rightWidget:
SizedBox(width: 60.w, child: _openCheckInSwitch()))), SizedBox(width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ), // ),
// Obx(() => // Obx(() =>
Visibility( Visibility(
@ -253,26 +265,32 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
isHaveLine: true, isHaveLine: true,
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: rightWidget:
SizedBox(width: 60.w, child: _openCheckInSwitch()))), SizedBox(width: 60.w, child: _otherUnHaveDoneSwitch()))),
// ), // ),
// Obx(() => // Obx(() =>
Visibility( Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
leftTitel: '开门方向设置', leftTitel: '开门方向设置',
rightTitle: "右开", rightTitle: "",
isHaveDirection: true, isHaveDirection: true,
isHaveLine: true, isHaveLine: true,
action: () {
Toast.show(msg: "功能暂未开放");
}
)), )),
// ), // ),
// Obx(() => // Obx(() =>
Visibility( Visibility(
visible: true, visible: true,
child: CommonItem( child: CommonItem(
leftTitel: '电机功率设置', leftTitel: '电机功率设置',
rightTitle: "", rightTitle: "",
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () {
Toast.show(msg: "功能暂未开放");
}
)), )),
// ), // ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
@ -459,6 +477,18 @@ class _LockSetPageState extends State<LockSetPage> with RouteAware {
); );
} }
CupertinoSwitch _otherUnHaveDoneSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: false,
onChanged: (value) {
Toast.show(msg: "功能暂未开放");
},
);
}
void showCupertinoAlertDialog( void showCupertinoAlertDialog(
BuildContext context, BuildContext context,
) { ) {

View File

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:date_format/date_format.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import '../../../../blue/blue_manage.dart'; import '../../../../blue/blue_manage.dart';
@ -53,8 +54,11 @@ class LockTimeLogic extends BaseGetXController{
(0xff & lockTime[2]) << 8 | (0xff & lockTime[2]) << 8 |
(0xFF & lockTime[3])); (0xFF & lockTime[3]));
String dataEime = DateTool().dateToYMDHNSString("${value}"); String dataEime = DateTool().dateToYMDHNSString("$value");
state.dateTime.value = dataEime; state.dateTime.value = dataEime;
// String dataEime = DateTool().dateToYMDHNSString("${value}");
// state.dateTime.value = dataEime;
print("lockTime:$lockTime value:$value dataEime:$dataEime"); print("lockTime:$lockTime value:$value dataEime:$dataEime");
break; break;
case 0x06: case 0x06:
@ -87,6 +91,17 @@ class LockTimeLogic extends BaseGetXController{
case 0x00: case 0x00:
// //
print("${reply.commandType}数据解析成功"); print("${reply.commandType}数据解析成功");
// var lockTime = reply.data.sublist(4, 8);
//
// int value = (
// (0xff & lockTime[(0)]) << 24 |
// (0xff & lockTime[1]) << 16 |
// (0xff & lockTime[2]) << 8 |
// (0xFF & lockTime[3]));
//
// String dataEime = DateTool().dateToYMDHNSString("$value");
// state.dateTime.value = dataEime;
// _getLockStatus(); // _getLockStatus();
Toast.show(msg:"锁时间更新成功"); Toast.show(msg:"锁时间更新成功");
break; break;
@ -155,7 +170,7 @@ class LockTimeLogic extends BaseGetXController{
}); });
} }
// //
void getLockTimeFromGateway() async{ void getLockTimeFromGateway() async{
var entity = await ApiRepository.to.getLockTimeFromGateway( var entity = await ApiRepository.to.getLockTimeFromGateway(
lockId: state.getKeyInfosData.value.lockId.toString(), lockId: state.getKeyInfosData.value.lockId.toString(),
@ -165,13 +180,13 @@ class LockTimeLogic extends BaseGetXController{
} }
} }
// //
void getServerDatetime() async{ void getServerDatetime() async{
var entity = await ApiRepository.to.getServerDatetimeData( var entity = await ApiRepository.to.getServerDatetimeData(
lockId: state.getKeyInfosData.value.lockId.toString(), lockId: state.getKeyInfosData.value.lockId.toString(),
); );
if(entity.errorCode!.codeIsSuccessful){ if(entity.errorCode!.codeIsSuccessful){
String dataEime = DateTool().dateToYMDHNSString("${int.parse(entity.data!.date.toString())~/1000}"); String dataEime = DateTool().dateToYMDHNSString("${int.parse(entity.data!.date!)}");
state.dateTime.value = dataEime; state.dateTime.value = dataEime;
sendTiming(); sendTiming();
} }
@ -184,7 +199,8 @@ class LockTimeLogic extends BaseGetXController{
print("onReady()"); print("onReady()");
_initReplySubscription(); _initReplySubscription();
getLockTimeFromGateway(); // getLockTimeFromGateway();
getServerDatetime();
} }
@override @override
@ -193,7 +209,7 @@ class LockTimeLogic extends BaseGetXController{
super.onInit(); super.onInit();
print("onInit()"); print("onInit()");
_getLockStatus(); // _getLockStatus();
} }
@override @override

View File

@ -3,6 +3,7 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:star_lock/blue/io_protocol/io_editUser.dart'; import 'package:star_lock/blue/io_protocol/io_editUser.dart';
import 'package:star_lock/blue/io_protocol/io_factoryDataReset.dart'; import 'package:star_lock/blue/io_protocol/io_factoryDataReset.dart';
import 'package:star_lock/blue/io_protocol/io_getLockStatu.dart'; import 'package:star_lock/blue/io_protocol/io_getLockStatu.dart';
@ -500,17 +501,18 @@ class LockDetailLogic extends BaseGetXController{
privateKey:getPrivateKeyList, privateKey:getPrivateKeyList,
); );
} }
}, isShowLoading: false); }, isShowLoading: true);
} }
void startScanAction(){ void startScanAction(){
BlueManage().startScan(true, (v){ BlueManage().startScan(true, (v){
// print("startScanAllDevice:${v}"); print("startScanAllDevice:${v}");
final knownDeviceIndex = v.indexWhere((d) => d.name == state.keyInfos.value.bluetooth!.bluetoothDeviceName!); final knownDeviceIndex = v.indexWhere((d) => d.name == state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
// //
if (knownDeviceIndex >= 0) { if (knownDeviceIndex >= 0) {
connectBlue(v[knownDeviceIndex].id, state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
BlueManage().connectDeviceMacAddress = v[knownDeviceIndex].id; BlueManage().connectDeviceMacAddress = v[knownDeviceIndex].id;
connectBlue(v[knownDeviceIndex].id, state.keyInfos.value.bluetooth!.bluetoothDeviceName!);
BlueManage().stopScan();
} }
}); });
} }
@ -521,8 +523,16 @@ class LockDetailLogic extends BaseGetXController{
super.onReady(); super.onReady();
print("onReady()"); print("onReady()");
_initReplySubscription(); _initReplySubscription();
getMicrophonePermission()
startScanAction(); .then((value) {
if (value) {
//
startScanAction();
}else{
//
openAppSettings();//app系统设置
}
});
} }
@override @override
@ -541,4 +551,23 @@ class LockDetailLogic extends BaseGetXController{
// TODO: implement onClose // TODO: implement onClose
_replySubscription.cancel(); _replySubscription.cancel();
} }
///
Future<bool> getMicrophonePermission() async {
// You can request multiple permissions at once.
Map<Permission, PermissionStatus> statuses = await [
Permission.bluetoothScan,
Permission.bluetoothConnect,
Permission.location,
].request();
//granted denied permanentlyDenied
if (statuses[Permission.bluetoothScan]!.isGranted &&
statuses[Permission.bluetoothConnect]!.isGranted &&
statuses[Permission.location]!.isGranted) {
return true;
}
return false;
}
} }

View File

@ -61,6 +61,9 @@ class _LockDetailPageState extends State<LockDetailPage> with RouteAware {
state.keyInfos.value.bluetooth!.signKey!.cast<int>(); state.keyInfos.value.bluetooth!.signKey!.cast<int>();
var saveSignKeyList = changeIntListToStringList(signKeyData); var saveSignKeyList = changeIntListToStringList(signKeyData);
Storage.setStringList(saveBlueSignKey, saveSignKeyList); Storage.setStringList(saveBlueSignKey, saveSignKeyList);
// token
Storage.setStringList(saveBlueToken, ["0", "0", "0", "0"]);
// print("publicKeyData:$publicKeyData saveStrList:$saveStrList privateKeyData:$privateKeyData savePrivateKeyList:$savePrivateKeyList"); // print("publicKeyData:$publicKeyData saveStrList:$saveStrList privateKeyData:$privateKeyData savePrivateKeyList:$savePrivateKeyList");
// logic.startScanAction(); // logic.startScanAction();

View File

@ -386,7 +386,7 @@ class SaveLockLogic extends BaseGetXController {
List<int> signKeyDataList = changeStringListToIntList(signKey!); List<int> signKeyDataList = changeStringListToIntList(signKey!);
bluetooth['signKey'] = signKeyDataList; bluetooth['signKey'] = signKeyDataList;
print("addUser:publicKeyDataList$publicKeyDataList getPrivateKeyList:$getPrivateKeyList signKeyDataList:$signKeyDataList"); // print("addUser:publicKeyDataList$publicKeyDataList getPrivateKeyList:$getPrivateKeyList signKeyDataList:$signKeyDataList");
var entity = await ApiRepository.to.bindingBlueAdmin( var entity = await ApiRepository.to.bindingBlueAdmin(
bindingDate:DateTime.now().millisecondsSinceEpoch.toString(), bindingDate:DateTime.now().millisecondsSinceEpoch.toString(),

View File

@ -27,9 +27,7 @@ class DateTool {
String dateToYMDHNSString(String timeDate){ String dateToYMDHNSString(String timeDate){
int time = int.parse(timeDate); int time = int.parse(timeDate);
DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time); DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
String appointmentDate = formatDate(nowDate, [yyyy,'.',mm,'.',dd,' ',HH,':',nn ,':',ss]); String appointmentDate = formatDate(nowDate, [yyyy,'.',mm,'.',dd,' ',HH,':',nn ,':',ss]);
return appointmentDate; return appointmentDate;
} }