214 lines
6.9 KiB
Dart
Executable File
214 lines
6.9 KiB
Dart
Executable File
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import 'package:star_lock/versionUndate/versionUndate_entity.dart';
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
|
import '../../../../blue/io_reply.dart';
|
|
import '../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../blue/sender_manage.dart';
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../tools/storage.dart';
|
|
|
|
class FaceUnlockLogic extends BaseGetXController {
|
|
final FaceUnlockState state = FaceUnlockState();
|
|
|
|
//设置面容开锁开关
|
|
Future<void> updateFaceSwitch() async {
|
|
final VersionUndateEntity entity = await ApiRepository.to.updateFaceSwitch(
|
|
lockId: state.lockSetInfoData.value.lockId ?? 0,
|
|
faceSwitch: state.faceOn.value == false ? 0 : 1,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr, something: (){
|
|
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
});
|
|
}
|
|
}
|
|
|
|
//设置面容感应距离
|
|
Future<void> updateFaceSenseDistance() async {
|
|
int faceInductionDistance = 0;
|
|
if(state.senseDistance.value == '远距离'.tr){
|
|
faceInductionDistance = 3;
|
|
}
|
|
|
|
if(state.senseDistance.value == '中距离'.tr){
|
|
faceInductionDistance = 2;
|
|
}
|
|
|
|
if(state.senseDistance.value == '近距离'.tr){
|
|
faceInductionDistance = 1;
|
|
}
|
|
|
|
if(state.senseDistance.value == '关闭'.tr){
|
|
faceInductionDistance = 0;
|
|
}
|
|
final VersionUndateEntity entity = await ApiRepository.to.updateFaceSenseDistance(
|
|
lockId: state.lockSetInfoData.value.lockId ?? 0,
|
|
faceInductionDistance: faceInductionDistance,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr, something: (){
|
|
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
});
|
|
}
|
|
}
|
|
|
|
//设置面容防误开
|
|
Future<void> updateFacePreventMisrun() async {
|
|
final VersionUndateEntity entity = await ApiRepository.to.updateFacePreventMisrun(
|
|
lockId: state.lockSetInfoData.value.lockId ?? 0,
|
|
faceEnErrUnlock: state.antiMisoperation.value,
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr, something: (){
|
|
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
|
});
|
|
}
|
|
}
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
if(reply is SetSupportFunctionsWithParametersReply && (state.ifCurrentScreen.value == true)) {
|
|
_replySetSupportFunctionsWithParameters(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 设置面容开锁数据解析
|
|
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
state.sureBtnState.value = 0;
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
switch(state.setType.value){
|
|
case 0:
|
|
updateFaceSwitch();
|
|
break;
|
|
case 1:
|
|
updateFaceSenseDistance();
|
|
break;
|
|
case 2:
|
|
updateFacePreventMisrun();
|
|
break;
|
|
}
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 设置支持功能(带参数)
|
|
Future<void> sendFaceUnlock() async {
|
|
if(state.sureBtnState.value == 1){
|
|
return;
|
|
}
|
|
state.sureBtnState.value = 1;
|
|
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: (){
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
|
if (connectionState == BluetoothConnectionState.connected) {
|
|
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
|
final List<int> getTokenList = changeStringListToIntList(token!);
|
|
|
|
final List<String>? publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
final List<int> getPublicKeyList = changeStringListToIntList(publicKey!);
|
|
|
|
final List<int> list = <int>[];
|
|
// 面容开锁开关
|
|
list.add(state.faceOn.value ? 1 : 0);
|
|
|
|
// 感应距离
|
|
int faceInductionDistance = 0;
|
|
if(state.senseDistance.value == '远距离'.tr){
|
|
faceInductionDistance = 3;
|
|
}else if(state.senseDistance.value == '中距离'.tr){
|
|
faceInductionDistance = 2;
|
|
}else if(state.senseDistance.value == '近距离'.tr){
|
|
faceInductionDistance = 1;
|
|
}else if(state.senseDistance.value == '关闭'.tr){
|
|
faceInductionDistance = 0;
|
|
}
|
|
list.add(faceInductionDistance);
|
|
|
|
// 防误开
|
|
list.add(state.antiMisoperation.value);
|
|
|
|
IoSenderManage.setSupportFunctionsWithParametersCommand(
|
|
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
userID: await Storage.getUid(),
|
|
featureBit: 5,
|
|
featureParaLength: 3,
|
|
featureData: list,
|
|
token: getTokenList,
|
|
needAuthor: 1,
|
|
publicKey: getPublicKeyList,
|
|
privateKey: getPrivateKeyList);
|
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
state.sureBtnState.value = 0;
|
|
if(state.ifCurrentScreen.value == true){
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
String getSensingDistanceString(){
|
|
if(state.senseDistance.value == '远距离'.tr){
|
|
return '感应到门前约1.5米有人时,将自动启动面部识别开锁。'.tr;
|
|
}else if(state.senseDistance.value == '中距离'.tr){
|
|
return '感应到门前约0.8米有人时,将自动启动面部识别开锁。'.tr;
|
|
}else if(state.senseDistance.value == '近距离'.tr){
|
|
return '感应到门前约0.5米有人时,将自动启动面部识别开锁。'.tr;
|
|
}else{
|
|
return '感应距离已关闭,需手动触摸键盘任意键,进行面部识别开锁。'.tr;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
// _readSupportFunctionsWithParameters();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
|
|
_replySubscription.cancel();
|
|
}
|
|
}
|