fix:重新优化猫眼设置项逻辑

This commit is contained in:
liyi 2025-02-27 15:56:03 +08:00
parent 42a3231f96
commit 602050b90c
15 changed files with 706 additions and 1795 deletions

View File

@ -71,10 +71,10 @@ class XSConstantMacro {
static int lockEventTypeVideo = 40; static int lockEventTypeVideo = 40;
// //
static int catEyeWorkModePowerSaving = 1; // static int catEyeWorkModePowerSaving = 0; //
static int catEyeWorkModeStayCapture = 2; // static int catEyeWorkModeStayCapture = 1; //
static int catEyeWorkModeRealTimeMonitoring = 3; // static int catEyeWorkModeRealTimeMonitoring = 2; //
static int catEyeWorkModeCustom = 4; // static int catEyeWorkModeCustom = 3; //
// //
static int userTypeSuperAdmin = 110301; // static int userTypeSuperAdmin = 110301; //

View File

@ -21,7 +21,6 @@ class _LiveVideoPageState extends State<LiveVideoPage> {
@override @override
initState() { initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData();
} }
@override @override

View File

@ -5,6 +5,7 @@ import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
import 'package:star_lock/blue/io_tool/io_tool.dart'; import 'package:star_lock/blue/io_tool/io_tool.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeCustomMode/catEyeCustomMode_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeCustomMode/catEyeCustomMode_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
@ -16,78 +17,8 @@ import '../../../../../blue/sender_manage.dart';
class CatEyeCustomModeLogic extends BaseGetXController { class CatEyeCustomModeLogic extends BaseGetXController {
final CatEyeCustomModeState state = CatEyeCustomModeState(); final CatEyeCustomModeState state = CatEyeCustomModeState();
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
// final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
Future<LockSetInfoEntity> getLockSettingInfoData() async {
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
state.lockSetInfoData.value = entity.data!;
if (entity.data!.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
state.catEyeConfigData.value =
entity.data!.lockSettingInfo!.catEyeConfig![0];
if (state.catEyeConfigData.value.catEyeModeConfig != null) {
if (state.catEyeConfigData.value.catEyeModeConfig!.recordMode == 1) {
state.selectVideoSlot.value = '自定义时段'.tr;
} else {
state.selectVideoSlot.value = '全天'.tr;
}
state.recordTime.value =
state.catEyeConfigData.value.catEyeModeConfig!.recordTime ?? '';
state.detectionDistance.value = state
.catEyeConfigData.value.catEyeModeConfig!.detectionDistance ??
'';
state.realTimeMode.value =
state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode == 0
? '发生事件时查看'.tr
: '实时查看'.tr;
await _getConfigAndGenerateBleData();
await updateCatEyeSetConfig();
}
}
}
await _getConfigAndGenerateBleData();
await updateCatEyeSetConfig();
return entity;
}
_sendBlueMessage(SetSupportFunctionsWithParametersCommand command,
List<int> config) async {
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!);
IoSenderManage.setSupportFunctionsWithParametersCommand(
keyID: command.keyID,
userID: command.userID,
featureBit: command.featureBit,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
});
}
// 0- 1- // 0- 1-
void updateCatEyeModeConfig(int clickIndex) async { void updateCatEyeModeConfig(int clickIndex) async {
@ -118,244 +49,36 @@ class CatEyeCustomModeLogic extends BaseGetXController {
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr); showToast('设置成功'.tr);
await getLockSettingInfoData(); // await getLockSettingInfoData();
} }
} }
_getConfigAndGenerateBleData() { void updateCustomModeConfig(clickIndex) {
int originalCatEyeMode = state catEyeSetState.catEyeConfig.value.catEyeMode = 4;
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!; catEyeSetState.catEyeConfig.value.recordTime =
int recordMode = state.lockSetInfoData.value.lockSettingInfo! state.showsUpVideoList.value.indexOf(state.recordTime.value);
.catEyeConfig![0].catEyeModeConfig!.recordMode == catEyeSetState.catEyeConfig.value.detectionDistance =
0 state.detectionRangeList.value.indexOf(state.detectionDistance.value);
? 1 catEyeSetState.settingOptions.value = 5;
: 0; catEyeSetLogic.sendBlueMessage();
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
int recordStartTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
int recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
state.catEyeConfig.refresh();
} }
/// @override
Future<void> updateCatEyeSetConfig() async { void onInit() {
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; // super.onInit();
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; // if (catEyeSetState.catEyeConfig.value.recordMode == 0) {
final int startTime = state.selectVideoSlot.value = '自定义时段'.tr;
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM
final int endTime =
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; //
final int detectionDistance =
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8
final int realTimePicture =
state.catEyeConfig.value.realTimePicture ?? 0; //
final int automaticBrightening =
state.catEyeConfig.value.autoLightScreen ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 15
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; //
final int exceptionWarning =
state.catEyeConfig.value.abnormalWarn ?? 1; //
/// 0
final List<int> config = generateConfig(
operatingMode: operatingMode,
isAllDay: isAllDay,
startTime: startTime,
endTime: endTime,
recordingTime: recordingTime,
detectionDistance: detectionDistance,
realTimePicture: realTimePicture,
automaticBrightening: automaticBrightening,
brightScreenTime: brightScreenTime,
stayWarning: stayWarning,
exceptionWarning: exceptionWarning,
);
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 command = SetSupportFunctionsWithParametersCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(),
featureBit: 64,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList,
);
final packageData = command.packageData();
///
// StartChartManage().sendBleMessage(
// bluetoothDeviceName: BlueManage().connectDeviceName,
// bleStructData: packageData,
// );
await _sendBlueMessage(command, config);
}
//
List<int> generateConfig({
required int operatingMode,
required int isAllDay,
required int startTime,
required int endTime,
required int recordingTime,
required int detectionDistance,
required int realTimePicture,
required int automaticBrightening,
required int brightScreenTime,
required int stayWarning,
required int exceptionWarning,
}) {
//
List<int> config = [];
// operatingMode
config.add(operatingMode);
// 0
if (operatingMode != 3) {
config.addAll(
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else { } else {
config.add(isAllDay); state.selectVideoSlot.value = '全天'.tr;
config.addAll(_intToBytes(startTime, 2)); // StartTime 2
config.addAll(_intToBytes(endTime, 2)); // EndTime 2
config.add(recordingTime);
} }
state.recordTime.value = state.showsUpVideoList
.value[catEyeSetState.catEyeConfig.value.recordTime ?? 0];
state.detectionDistance.value = state.detectionRangeList
.value[catEyeSetState.catEyeConfig.value.detectionDistance ?? 0];
// detectionDistance realTimePicture 0 state.realTimeMode.value =
if (operatingMode != 3) { catEyeSetState.catEyeConfig.value.realTimeMode == 0
config.addAll([0, 0]); ? '发生事件时查看'.tr
} else { : '实时查看'.tr;
config.add(detectionDistance);
config.add(realTimePicture);
}
//
config.add(automaticBrightening);
config.add(brightScreenTime);
config.add(stayWarning);
config.add(exceptionWarning);
return config;
}
//
List<int> _intToBytes(int value, int length) {
List<int> bytes = [];
for (int i = length - 1; i >= 0; i--) {
bytes.add((value >> (8 * i)) & 0xFF);
}
return bytes;
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
int _handleDetectionDistance(String s) {
if (s == '约0.8米') {
return 0;
}
if (s == '约1.5米') {
return 1;
}
if (s == '约3.0米') {
return 2;
}
return 0;
} }
} }

View File

@ -1,4 +1,3 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -24,7 +23,7 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
@override @override
initState() { initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData(); // logic.getLockSettingInfoData();
} }
@override @override
@ -61,11 +60,13 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
? state.lockSetInfoData.value.lockSettingInfo! ? state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0] .catEyeConfig![0]
: null : null
}).then((value) => {logic.getLockSettingInfoData()}); });
}, },
), ),
), ),
_buildSubTitleItem('有人出现时录像'.tr, '有人在门口出现10秒后开始录像。'.tr + '\n' + '有人按门铃时立即录像'.tr, _buildSubTitleItem(
'有人出现时录像'.tr,
'有人在门口出现10秒后开始录像。'.tr + '\n' + '有人按门铃时立即录像'.tr,
state.recordTime.value, () { state.recordTime.value, () {
_openBottomItemSheet(state.showsUpVideoList.value, 0); _openBottomItemSheet(state.showsUpVideoList.value, 0);
}), }),
@ -96,7 +97,7 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
? state.lockSetInfoData.value.lockSettingInfo! ? state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0] .catEyeConfig![0]
: null : null
}).then((value) => {logic.getLockSettingInfoData()}); });
}, },
), ),
) )
@ -167,25 +168,26 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
Future _openBottomItemSheet(List bottomItemList, int clickIndex) async { Future _openBottomItemSheet(List bottomItemList, int clickIndex) async {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)), borderRadius: BorderRadiusDirectional.circular(10)),
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertBottomWidget( return AlertBottomWidget(
topTitle: '', topTitle: '',
items: bottomItemList, items: bottomItemList,
chooseCallback: (value) { chooseCallback: (value) {
if (clickIndex == 0) { if (clickIndex == 0) {
// //
state.recordTime.value = state.showsUpVideoList.value[value]; state.recordTime.value = state.showsUpVideoList.value[value];
} else if (clickIndex == 1) { } else if (clickIndex == 1) {
// //
state.detectionDistance.value = state.detectionDistance.value =
state.detectionRangeList.value[value]; state.detectionRangeList.value[value];
} }
logic.updateCatEyeModeConfig(clickIndex); logic.updateCustomModeConfig(clickIndex);
}, },
); );
}); },
);
} }
} }

View File

@ -2,21 +2,45 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
class CatEyeCustomModeState { // 0 1 class CatEyeCustomModeState {
// 0 1
CatEyeCustomModeState() { CatEyeCustomModeState() {
Map map = Get.arguments; Map map = Get.arguments;
if (map['lockSetInfoData'] != null) { if (map['lockSetInfoData'] != null) {
lockSetInfoData.value = map['lockSetInfoData']; lockSetInfoData.value = map['lockSetInfoData'];
if (lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
catEyeConfigData.value =
lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0];
if (catEyeConfigData.value.catEyeModeConfig != null) {
// if (catEyeConfigData.value.catEyeModeConfig!.recordMode == 0) {
// selectVideoSlot.value = '自定义时段'.tr;
// } else {
// selectVideoSlot.value = '全天'.tr;
// }
// recordTime.value =
// catEyeConfigData.value.catEyeModeConfig!.recordTime ?? '';
// detectionDistance.value =
// catEyeConfigData.value.catEyeModeConfig!.detectionDistance ?? 0;
// realTimeMode.value =
// catEyeConfigData.value.catEyeModeConfig!.realTimeMode == 0
// ? '发生事件时查看'.tr
// : '实时查看'.tr;
}
}
} }
if (map['catEyeConfigData'] != null) { if (map['catEyeConfigData'] != null) {
catEyeConfigData.value = map['catEyeConfigData']; catEyeConfigData.value = map['catEyeConfigData'];
} }
} }
RxBool isCheck = false.obs; RxBool isCheck = false.obs;
RxBool faceOn = false.obs; // RxBool faceOn = false.obs; //
RxBool autoBright = false.obs; // RxBool autoBright = false.obs; //
@ -31,21 +55,20 @@ class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查
'30${"".tr}', '30${"".tr}',
'60${"".tr}' '60${"".tr}'
].obs; ].obs;
RxList<String> detectionRangeList = <String>['约0.8米'.tr, '约1.5米'.tr, '约3.0米'.tr].obs; RxList<String> detectionRangeList =
<String>['约0.8米'.tr, '约1.5米'.tr, '约3.0米'.tr].obs;
// //
final TextStyle titleStyle = TextStyle( final TextStyle titleStyle = TextStyle(
color: Colors.black, fontSize: 24.sp, fontWeight: FontWeight.w500); color: Colors.black, fontSize: 24.sp, fontWeight: FontWeight.w500);
// //
final TextStyle subTipsStyle = final TextStyle subTipsStyle =
TextStyle(color: AppColors.placeholderTextColor, fontSize: 22.sp); TextStyle(color: AppColors.placeholderTextColor, fontSize: 22.sp);
late InlineSpan tipsPreviewSpan = TextSpan(children: <InlineSpan>[ late InlineSpan tipsPreviewSpan = TextSpan(children: <InlineSpan>[
TextSpan( TextSpan(text: '${"添加和使用面容开锁时".tr}:\n', style: titleStyle),
text: '${"添加和使用面容开锁时".tr}:\n', TextSpan(text: '添加和使用面容开锁时提示'.tr, style: subTipsStyle),
style: titleStyle),
TextSpan(
text: '添加和使用面容开锁时提示'.tr,
style: subTipsStyle),
]); ]);
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs; Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
@ -56,7 +79,6 @@ class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查
RxString detectionDistance = ''.obs; // RxString detectionDistance = ''.obs; //
RxString realTimeMode = ''.obs; RxString realTimeMode = ''.obs;
/// ///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs; Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
} }

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/blue/blue_manage.dart'; import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
import 'package:star_lock/blue/io_reply.dart'; import 'package:star_lock/blue/io_reply.dart';
@ -12,8 +11,8 @@ import 'package:star_lock/blue/sender_manage.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/eventBusEventManage.dart';
import 'package:star_lock/tools/storage.dart'; import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/versionUndate/versionUndate_entity.dart'; import 'package:star_lock/versionUndate/versionUndate_entity.dart';
@ -41,6 +40,12 @@ class CatEyeSetLogic extends BaseGetXController {
}); });
} }
@override
void onClose() {
_replySubscription.cancel();
super.onClose();
}
// //
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async { Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
final int status = reply.data[2]; final int status = reply.data[2];
@ -70,10 +75,17 @@ class CatEyeSetLogic extends BaseGetXController {
updateLightScreenTimeConfig(); updateLightScreenTimeConfig();
} }
break; break;
case 5: //
{
updateCatEyeModeConfig();
}
break;
default: default:
break; break;
} }
getLockSettingInfoData();
break; break;
case 0x06: case 0x06:
// //
break; break;
@ -82,109 +94,23 @@ class CatEyeSetLogic extends BaseGetXController {
} }
} }
//
Future<void> updateAutoLightScreenConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateAutoLightScreenConfig(
lockId: state.lockSetInfoData.value.lockId!,
autoLightScreen: state.isAutoBright.value == true ? 1 : 0,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreen =
state.isAutoBright.value == true ? 1 : 0;
state.catEyeConfig.refresh();
await getLockSettingInfoData();
}
}
//
Future<void> updateLightScreenTimeConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateLightScreenTimeConfig(
lockId: state.lockSetInfoData.value.lockId!,
autoLightScreenTime:
int.parse(state.selectBrightDuration.value.replaceAll(''.tr, '')),
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreenTime =
int.parse(state.selectBrightDuration.value.replaceAll(''.tr, ''));
state.catEyeConfig.refresh();
await getLockSettingInfoData();
}
}
//
Future<void> updateStayWarnConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateStayWarnConfig(
lockId: state.lockSetInfoData.value.lockId!,
stayWarn: state.isStayWarning.value == true ? 1 : 0,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreen =
state.isStayWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
await getLockSettingInfoData();
}
}
//
Future<void> updateAbnormalWarnConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateAbnormalWarnConfig(
lockId: state.lockSetInfoData.value.lockId!,
abnormalWarn: state.isExceptionWarning.value == true ? 1 : 0,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreen =
state.isExceptionWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
await getLockSettingInfoData();
}
}
// //
Future<LockSetInfoEntity> getLockSettingInfoData() async { Future<void> getLockSettingInfoData() async {
final LockSetInfoEntity entity = final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData( await ApiRepository.to.getLockSettingInfoData(
lockId: state.lockSetInfoData.value.lockId.toString(), lockId: state.lockSetInfoData.value.lockId.toString(),
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.lockSetInfoData.value = entity.data!; state.lockSetInfoData.value = entity.data!;
state.selectBrightDuration.value =
'${state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime}${''.tr}'; //
if (state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen == 0) {
state.isAutoBright.value = false;
} else {
state.isAutoBright.value = true;
}
//
if (state.lockSetInfoData.value.lockSettingInfo!.stayWarn == 0) {
state.isStayWarning.value = false;
} else {
state.isStayWarning.value = true;
}
//
if (state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn == 0) {
state.isExceptionWarning.value = false;
} else {
state.isExceptionWarning.value = true;
}
eventBus
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
// //
state.selectCatEyeWorkMode.value = ''; // state.selectCatEyeWorkMode.value = ''; //
if (state.lockSetInfoData.value.lockSettingInfo != null &&
// selectCatEyeWorkMode.value = catEyeConfigData.value.catEyeMode!; state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig != null &&
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.length >
if (state 0) {
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0] if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeMode == .catEyeMode ==
XSConstantMacro.catEyeWorkModePowerSaving) { XSConstantMacro.catEyeWorkModePowerSaving) {
@ -203,101 +129,109 @@ class CatEyeSetLogic extends BaseGetXController {
state.selectCatEyeWorkMode.value = '自定义模式'.tr; state.selectCatEyeWorkMode.value = '自定义模式'.tr;
} }
} }
state.updateCatEyeSetByState();
state.catEyeConfig.refresh();
} }
// state中的猫眼设置
await _updateCatEyeSetByState();
return entity;
} }
// state中的猫眼设置 //
_updateCatEyeSetByState() async { Future<void> updateAutoLightScreenConfig() async {
int originalCatEyeMode = 0; final VersionUndateEntity entity =
int recordMode = 0; await ApiRepository.to.updateAutoLightScreenConfig(
int recordStartTime = 0; lockId: state.lockSetInfoData.value.lockId!,
int recordEndTime = 0; autoLightScreen: state.isAutoBright.value == true ? 1 : 0,
int recordTime = 0;
int detectionDistance = 0;
int realTimeMode = 0;
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig != null &&
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.length > 0) {
originalCatEyeMode = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
recordMode = state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeModeConfig!.recordMode ==
0
? 1
: 0;
recordStartTime = _handleTimeToM(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.recordStartTime!);
recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]!
.catEyeModeConfig!.detectionDistance !=
null) {
detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
}
realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
}
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
); );
state.catEyeConfig.refresh(); if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreen =
state.isAutoBright.value == true ? 1 : 0;
state.catEyeConfig.refresh();
}
}
//
Future<void> updateLightScreenTimeConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateLightScreenTimeConfig(
lockId: state.lockSetInfoData.value.lockId!,
autoLightScreenTime:
int.parse(state.selectBrightDuration.value.replaceAll(''.tr, '')),
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.autoLightScreenTime =
int.parse(state.selectBrightDuration.value.replaceAll(''.tr, ''));
state.catEyeConfig.refresh();
}
}
//
Future<void> updateStayWarnConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateStayWarnConfig(
lockId: state.lockSetInfoData.value.lockId!,
stayWarn: state.isStayWarning.value == true ? 1 : 0,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.stayWarn =
state.isStayWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
}
}
//
Future<void> updateCatEyeModeConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateCatEyeModeConfig(
lockId: state.lockSetInfoData.value.lockId!,
catEyeConfig: [
<String, Object>{
'catEyeMode': state.catEyeConfig.value.catEyeMode!,
'catEyeModeConfig': <String, Object?>{
'recordMode': state.catEyeConfig.value.recordMode,
'recordStartTime': state.catEyeConfig.value.recordStartTime,
'recordEndTime': state.catEyeConfig.value.recordEndTime,
'recordTime': state.catEyeConfig.value.recordTime,
'detectionDistance': state.catEyeConfig.value.detectionDistance,
'realTimeMode': state.catEyeConfig.value.realTimeMode,
}
}
],
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
}
}
//
Future<void> updateAbnormalWarnConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateAbnormalWarnConfig(
lockId: state.lockSetInfoData.value.lockId!,
abnormalWarn: state.isExceptionWarning.value == true ? 1 : 0,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast(state.settingSuccess);
state.catEyeConfig.value.abnormalWarn =
state.isExceptionWarning.value == true ? 1 : 0;
state.catEyeConfig.refresh();
// await getLockSettingInfoData();
}
} }
/// ///
List<int> _buildCatEyeSetBlueMessage() { List<int> _buildCatEyeSetBlueMessage() {
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; // final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; //
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; // final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; //
final int startTime = final int startTime =
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM _handleTimeToM(state.catEyeConfig.value.recordStartTime!) ??
480; // 8:00 AM
final int endTime = final int endTime =
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM _handleTimeToM(state.catEyeConfig.value.recordEndTime!) ??
1080; // 6:00 PM
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; // final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; //
final int detectionDistance = final int detectionDistance =
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8 state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8
@ -354,8 +288,14 @@ class CatEyeSetLogic extends BaseGetXController {
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime [0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else { } else {
config.add(isAllDay); config.add(isAllDay);
config.addAll(_intToBytes(startTime, 2)); // StartTime 2 if (isAllDay == 1) {
config.addAll(_intToBytes(endTime, 2)); // EndTime 2 config.addAll(_intToBytes(0, 2)); // StartTime 2
config.addAll(_intToBytes(0, 2)); // EndTime 2
} else {
config.addAll(_intToBytes(startTime, 2)); // StartTime 2
config.addAll(_intToBytes(endTime, 2)); // EndTime 2
}
config.add(recordingTime); config.add(recordingTime);
} }
@ -385,54 +325,6 @@ class CatEyeSetLogic extends BaseGetXController {
return bytes; return bytes;
} }
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
// int hour = dateTime.hour;
// int minute = dateTime.minute;
// print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
int _handleDetectionDistance(String s) {
if (s == '约0.8米') {
return 0;
}
if (s == '约1.5米') {
return 1;
}
if (s == '约3.0米') {
return 2;
}
return 0;
}
void updateSettingOptions(int clickIndex, value) { void updateSettingOptions(int clickIndex, value) {
switch (clickIndex) { switch (clickIndex) {
case 1: // case 1: //
@ -458,7 +350,8 @@ class CatEyeSetLogic extends BaseGetXController {
break; break;
case 4: // case 4: //
{ {
state.isExceptionWarning.value = value; state.selectBrightDuration.value =
state.brightDurationTimeList[value];
state.settingOptions.value = 4; state.settingOptions.value = 4;
state.catEyeConfig.value.autoLightScreenTime = state.catEyeConfig.value.autoLightScreenTime =
_handleGetIntNumber(state.selectBrightDuration.value); _handleGetIntNumber(state.selectBrightDuration.value);
@ -467,6 +360,10 @@ class CatEyeSetLogic extends BaseGetXController {
default: default:
break; break;
} }
sendBlueMessage();
}
void sendBlueMessage() {
final message = _buildCatEyeSetBlueMessage(); final message = _buildCatEyeSetBlueMessage();
BlueManage().blueSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async { (BluetoothConnectionState connectionState) async {
@ -498,4 +395,32 @@ class CatEyeSetLogic extends BaseGetXController {
} }
}); });
} }
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
} }

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart'; import 'package:star_lock/appRouters.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/commonItem.dart';
@ -25,8 +26,6 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData();
} }
@override @override
@ -46,17 +45,18 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Navigator.pushNamed(context, Routers.catEyeWorkModePage, Navigator.pushNamed(
arguments: <String, Object?>{ context,
'lockSetInfoData': state.lockSetInfoData.value, Routers.catEyeWorkModePage,
'catEyeConfigData': state.lockSetInfoData.value arguments: <String, Object?>{
.lockSettingInfo!.catEyeConfig!.isNotEmpty 'lockSetInfoData': state.lockSetInfoData.value,
? state.lockSetInfoData.value.lockSettingInfo! 'catEyeConfigData': state.lockSetInfoData.value
.catEyeConfig![0] .lockSettingInfo!.catEyeConfig!.isNotEmpty
: null ? state.lockSetInfoData.value.lockSettingInfo!
}).then((Object? value) { .catEyeConfig![0]
logic.getLockSettingInfoData(); : null
}); },
);
})), })),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: '自动亮屏'.tr, leftTitel: '自动亮屏'.tr,
@ -125,19 +125,20 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
Future _openBottomItemSheet() async { Future _openBottomItemSheet() async {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)), borderRadius: BorderRadiusDirectional.circular(10)),
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertBottomWidget( return AlertBottomWidget(
topTitle: '', topTitle: '',
items: state.brightDurationTimeList, items: state.brightDurationTimeList,
chooseCallback: (int value) { chooseCallback: (int value) {
state.selectBrightDuration.value = state.selectBrightDuration.value =
state.brightDurationTimeList[value]; state.brightDurationTimeList[value];
logic.updateSettingOptions(4, true); logic.updateSettingOptions(4, value);
}, },
); );
}); },
);
} }
} }

View File

@ -1,5 +1,6 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart'; import 'package:get/get_rx/get_rx.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
class CatEyeSetState { class CatEyeSetState {
@ -28,6 +29,29 @@ class CatEyeSetState {
} else { } else {
isExceptionWarning.value = false; isExceptionWarning.value = false;
} }
selectCatEyeWorkMode.value = ''; //
if (lockSetInfoData.value.lockSettingInfo != null &&
lockSetInfoData.value.lockSettingInfo!.catEyeConfig != null &&
lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.length > 0) {
if (lockSetInfoData
.value.lockSettingInfo!.catEyeConfig![0].catEyeMode ==
XSConstantMacro.catEyeWorkModePowerSaving) {
selectCatEyeWorkMode.value = '省电模式'.tr;
} else if (lockSetInfoData
.value.lockSettingInfo!.catEyeConfig![0].catEyeMode ==
XSConstantMacro.catEyeWorkModeStayCapture) {
selectCatEyeWorkMode.value = '逗留抓拍模式'.tr;
} else if (lockSetInfoData
.value.lockSettingInfo!.catEyeConfig![0].catEyeMode ==
XSConstantMacro.catEyeWorkModeRealTimeMonitoring) {
selectCatEyeWorkMode.value = '实时监控模式'.tr;
} else if (lockSetInfoData
.value.lockSettingInfo!.catEyeConfig![0].catEyeMode ==
XSConstantMacro.catEyeWorkModeCustom) {
selectCatEyeWorkMode.value = '自定义模式'.tr;
}
}
updateCatEyeSetByState();
} }
} }
@ -42,9 +66,83 @@ class CatEyeSetState {
RxInt settingOptions = 0.obs; // RxInt settingOptions = 0.obs; //
final String settingSuccess = '设置成功'.tr; final String settingSuccess = '设置成功'.tr;
/// ///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs; Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
// state中的猫眼设置
updateCatEyeSetByState() async {
int originalCatEyeMode = 0;
int recordMode = 0;
int recordStartTime = 0;
int recordEndTime = 0;
int recordTime = 0;
int detectionDistance = 0;
int realTimeMode = 0;
if (lockSetInfoData.value.lockSettingInfo!.catEyeConfig != null &&
lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.length > 0) {
originalCatEyeMode =
lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
recordMode = lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeModeConfig!.recordMode!;
recordStartTime = _handleTimeToM(lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
recordEndTime = _handleTimeToM(lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
recordTime = lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeModeConfig!.recordTime!;
if (lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]!
.catEyeModeConfig!.detectionDistance !=
null) {
detectionDistance = lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.detectionDistance!;
}
realTimeMode = lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
.catEyeModeConfig!.realTimeMode!;
}
int stayWarn = lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn = lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
// catEyeMode
int adjustedCatEyeMode = originalCatEyeMode;
int brightScreenTime =
lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
catEyeConfig.refresh();
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
} }
class CatEyeSetEntity { class CatEyeSetEntity {
@ -64,7 +162,6 @@ class CatEyeSetEntity {
CatEyeSetEntity({ CatEyeSetEntity({
this.catEyeMode, this.catEyeMode,
this.recordMode, this.recordMode,
this.recordTime, this.recordTime,
this.realTimeMode, this.realTimeMode,

View File

@ -22,410 +22,28 @@ import 'package:star_lock/versionUndate/versionUndate_entity.dart';
class CatEyeWorkModeLogic extends BaseGetXController { class CatEyeWorkModeLogic extends BaseGetXController {
final CatEyeWorkModeState state = CatEyeWorkModeState(); final CatEyeWorkModeState state = CatEyeWorkModeState();
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state; final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
// void updateCustomModeConfig(clickIndex) {
late StreamSubscription<Reply> _replySubscription; catEyeSetState.catEyeConfig.value.catEyeMode = clickIndex;
catEyeSetState.settingOptions.value = 5;
void _initReplySubscription() { catEyeSetLogic.sendBlueMessage();
_replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
// ()
if (reply is SetSupportFunctionsWithParametersReply) {
_replySetSupportFunctionsWithParameters(reply);
}
});
} }
// @override
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async { void onInit() {
final int status = reply.data[2]; super.onInit();
switch (status) { catEyeSetState.catEyeConfig.refresh();
case 0x00: if (catEyeSetState.catEyeConfig.value.catEyeMode != null) {
// for (int i = 0; i < state.boolList.value.length; i++) {
cancelBlueConnetctToastTimer(); if (catEyeSetState.catEyeConfig.value.catEyeMode! == i) {
dismissEasyLoading(); state.boolList.value[i] = true;
updateCatEyeModeConfig(); } else {
break; state.boolList.value[i] = false;
case 0x06:
//
break;
default:
break;
}
}
//
Future<void> updateCatEyeModeConfig() async {
final VersionUndateEntity entity =
await ApiRepository.to.updateCatEyeModeConfig(
lockId: state.lockSetInfoData.value.lockId!,
catEyeConfig: [
<String, Object>{
'catEyeMode':
state.boolList.indexWhere((bool element) => element == true) + 1,
'catEyeModeConfig': <String, Object?>{
'recordMode': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordMode
: 0,
'recordStartTime': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordStartTime
: 0,
'recordEndTime': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordEndTime
: 0,
'recordTime': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordTime
: '',
'detectionDistance': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state
.catEyeConfigData.value.catEyeModeConfig?.detectionDistance
: '',
'realTimeMode': state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.realTimeMode!
: 0,
}
} }
],
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
getLockSettingInfoData();
}
}
void _sendBlueMessage(
SetSupportFunctionsWithParametersCommand command, List<int> config) {
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!);
IoSenderManage.setSupportFunctionsWithParametersCommand(
keyID: command.keyID,
userID: command.userID,
featureBit: command.featureBit,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
});
}
//
Future<void> getLockSettingInfoData() async {
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
state.lockSetInfoData.value = entity.data!;
if (entity.data!.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
state.catEyeConfigData.value =
entity.data!.lockSettingInfo!.catEyeConfig![0];
if (state.catEyeConfigData.value.catEyeMode ==
XSConstantMacro.catEyeWorkModePowerSaving) {
state.boolList.value = <bool>[true, false, false, false];
} else if (state.catEyeConfigData.value.catEyeMode ==
XSConstantMacro.catEyeWorkModeStayCapture) {
state.boolList.value = <bool>[false, true, false, false];
} else if (state.catEyeConfigData.value.catEyeMode ==
XSConstantMacro.catEyeWorkModeRealTimeMonitoring) {
state.boolList.value = <bool>[false, false, true, false];
} else if (state.catEyeConfigData.value.catEyeMode ==
XSConstantMacro.catEyeWorkModeCustom) {
state.boolList.value = <bool>[false, false, false, true];
}
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
} }
} }
} state.boolList.refresh();
_getConfigAndGenerateBleData() {
// state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode
int originalCatEyeMode = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
int recordMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.recordMode ==
0
? 1
: 0;
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
int recordStartTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
int recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
state.catEyeConfig.refresh();
}
///
void updateCatEyeSetConfig() async {
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; //
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; //
final int startTime =
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM
final int endTime =
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; //
final int detectionDistance =
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8
final int realTimePicture =
state.catEyeConfig.value.realTimePicture ?? 0; //
final int automaticBrightening =
state.catEyeConfig.value.autoLightScreen ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 15
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; //
final int exceptionWarning =
state.catEyeConfig.value.abnormalWarn ?? 1; //
/// 0
final List<int> config = generateConfig(
operatingMode: operatingMode,
isAllDay: isAllDay,
startTime: startTime,
endTime: endTime,
recordingTime: recordingTime,
detectionDistance: detectionDistance,
realTimePicture: realTimePicture,
automaticBrightening: automaticBrightening,
brightScreenTime: brightScreenTime,
stayWarning: stayWarning,
exceptionWarning: exceptionWarning,
);
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 command = SetSupportFunctionsWithParametersCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(),
featureBit: 64,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList,
);
_sendBlueMessage(command, config);
}
//
List<int> generateConfig({
required int operatingMode,
required int isAllDay,
required int startTime,
required int endTime,
required int recordingTime,
required int detectionDistance,
required int realTimePicture,
required int automaticBrightening,
required int brightScreenTime,
required int stayWarning,
required int exceptionWarning,
}) {
//
List<int> config = [];
// operatingMode
config.add(operatingMode);
// 0
if (operatingMode != 3) {
config.addAll(
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else {
config.add(isAllDay);
config.addAll(_intToBytes(startTime, 2)); // StartTime 2
config.addAll(_intToBytes(endTime, 2)); // EndTime 2
config.add(recordingTime);
}
// detectionDistance realTimePicture 0
if (operatingMode != 3) {
config.addAll([0, 0]);
} else {
config.add(detectionDistance);
config.add(realTimePicture);
}
//
config.add(automaticBrightening);
config.add(brightScreenTime);
config.add(stayWarning);
config.add(exceptionWarning);
return config;
}
//
List<int> _intToBytes(int value, int length) {
List<int> bytes = [];
for (int i = length - 1; i >= 0; i--) {
bytes.add((value >> (8 * i)) & 0xFF);
}
return bytes;
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
int _handleDetectionDistance(String s) {
if (s == '约0.8米') {
return 0;
}
if (s == '约1.5米') {
return 1;
}
if (s == '约3.0米') {
return 2;
}
return 0;
}
void updateCustomModeConfig() {
state.catEyeConfig.value.recordMode =
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordMode
: 0;
state.catEyeConfig.value.recordStartTime =
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordStartTime
: 0;
state.catEyeConfig.value.recordEndTime =
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.recordEndTime
: 0;
state.catEyeConfig.value.recordTime =
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? _handleGetIntNumber(
state.catEyeConfigData.value.catEyeModeConfig?.recordTime ?? '')
: 0;
state.catEyeConfig.value.detectionDistance = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? _handleDetectionDistance(
state.catEyeConfigData.value.catEyeModeConfig?.detectionDistance ??
'')
: 0;
state.catEyeConfig.value.realTimeMode =
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty
? state.catEyeConfigData.value.catEyeModeConfig?.realTimeMode!
: 0;
updateCatEyeSetConfig();
} }
} }

View File

@ -1,4 +1,3 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -24,129 +23,149 @@ class _CatEyeWorkModePageState extends State<CatEyeWorkModePage> {
@override @override
initState() { initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData(); // logic.getLockSettingInfoData();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: TitleAppBar( appBar: TitleAppBar(
barTitle: '猫眼工作模式'.tr, barTitle: '猫眼工作模式'.tr,
haveBack: true, haveBack: true,
backAction: () { backAction: () {
Navigator.pop(context, true); Navigator.pop(context, true);
}, },
backgroundColor: AppColors.mainColor), backgroundColor: AppColors.mainColor),
body: Obx(() => Column( body: Obx(
children: <Widget>[ () => Column(
SizedBox( children: <Widget>[
height: 30.h, SizedBox(
), height: 30.h,
_buildTipsView( ),
'省电模式'.tr + '\n', _buildTipsView(
'适合门口较为安全的环境。'.tr + '\n' + '仅发生特定事件才录像,并可查看实时画面。'.tr + '\n' + '一般情况下满电可使用7-8个月'.tr, '省电模式'.tr + '\n',
0), '适合门口较为安全的环境。'.tr +
SizedBox( '\n' +
height: 30.h, '仅发生特定事件才录像,并可查看实时画面。'.tr +
), '\n' +
_buildTipsView('逗留抓拍模式'.tr + '\n', '一般情况下满电可使用7-8个月'.tr,
'有人逗留或发生特定事件才录像,可随时查看'.tr + '\n' + '实时画面。'.tr + '\n' + '一般情况下满电可使用5~6个月。'.tr, 1), 0),
SizedBox( SizedBox(
height: 30.h, height: 30.h,
), ),
_buildTipsView( _buildTipsView(
'实时监控模式'.tr + '\n', '逗留抓拍模式'.tr + '\n',
'适合门口人员复杂、较不安全的环境。'.tr + '\n' + '有人出现就录像,可随时查看实时画面。'.tr + '\n' + '一般情况下满电可使用2~4个月。'.tr, '有人逗留或发生特定事件才录像,可随时查看'.tr +
2), '\n' +
SizedBox( '实时画面。'.tr +
height: 30.h, '\n' +
), '一般情况下满电可使用5~6个月。'.tr,
_buildTipsView( 1),
'自定义模式'.tr + '\n', '根据您家门口实际情况设置录像和实时画面功能。'.tr + '\n' + '可使用时长由具体设置决定。'.tr, 3) SizedBox(
], height: 30.h,
))); ),
_buildTipsView(
'实时监控模式'.tr + '\n',
'适合门口人员复杂、较不安全的环境。'.tr +
'\n' +
'有人出现就录像,可随时查看实时画面。'.tr +
'\n' +
'一般情况下满电可使用2~4个月。'.tr,
2),
SizedBox(
height: 30.h,
),
_buildTipsView('自定义模式'.tr + '\n',
'根据您家门口实际情况设置录像和实时画面功能。'.tr + '\n' + '可使用时长由具体设置决定。'.tr, 3)
],
),
),
);
} }
Widget _buildTipsView(String titleStr, String subTitle, int clickIndex) { Widget _buildTipsView(String titleStr, String subTitle, int clickIndex) {
return GestureDetector( return GestureDetector(
child: Container( child: Container(
width: ScreenUtil().screenWidth - 40.w, width: ScreenUtil().screenWidth - 40.w,
margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 10.h), margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 10.h),
decoration: BoxDecoration( decoration: BoxDecoration(
color: state.boolList.value[clickIndex] color: state.boolList.value[clickIndex]
? AppColors.blueViewBgColor ? AppColors.blueViewBgColor
: AppColors.greyBackgroundColor, : AppColors.greyBackgroundColor,
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
child: Padding( child: Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 20.w, top: 30.h, bottom: 30.h, right: 20.w), left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
if (state.boolList.value[clickIndex]) Image.asset( if (state.boolList.value[clickIndex])
'images/mine/icon_mine_blueSelect.png', Image.asset(
width: 20.w, 'images/mine/icon_mine_blueSelect.png',
height: 14.w, width: 20.w,
) else SizedBox( height: 14.w,
width: 20.w, )
height: 14.w, else
),
SizedBox(width: 10.w),
Expanded(
child: _buildRichText(
titleStr, subTitle, state.boolList.value[clickIndex]),
),
SizedBox( SizedBox(
width: 10.w, width: 20.w,
height: 14.w,
), ),
GestureDetector( SizedBox(width: 10.w),
child: Container( Expanded(
width: 90.w, child: _buildRichText(
height: 40.h, titleStr, subTitle, state.boolList.value[clickIndex]),
decoration: BoxDecoration( ),
color: Colors.transparent, SizedBox(
borderRadius: BorderRadius.circular(15.0), width: 10.w,
border: Border.all( ),
color: AppColors.placeholderTextColor, width: 1.w), GestureDetector(
), child: Container(
child: Center( width: 90.w,
child: Text( height: 40.h,
clickIndex == 3 ? '设置'.tr : '查看'.tr, decoration: BoxDecoration(
style: TextStyle( color: Colors.transparent,
color: AppColors.placeholderTextColor, borderRadius: BorderRadius.circular(15.0),
fontSize: 20.sp), border: Border.all(
), color: AppColors.placeholderTextColor, width: 1.w),
),
child: Center(
child: Text(
clickIndex == 3 ? '设置'.tr : '查看'.tr,
style: TextStyle(
color: AppColors.placeholderTextColor,
fontSize: 20.sp),
), ),
), ),
onTap: () {
//
if (clickIndex == 3) {
Navigator.pushNamed(
context, Routers.catEyeCustomModePage,
arguments: <String, LockSetInfoData>{
'lockSetInfoData': state.lockSetInfoData.value,
}).then((Object? value) => logic.getLockSettingInfoData());
} else {
//
showBottomSheet(context, clickIndex);
}
},
), ),
], onTap: () {
)), //
), if (clickIndex == 3) {
onTap: () { Navigator.pushNamed(context, Routers.catEyeCustomModePage,
for (int i = 0; i < state.boolList.value.length; i++) { arguments: <String, LockSetInfoData>{
if (clickIndex == i) { 'lockSetInfoData': state.lockSetInfoData.value,
state.boolList.value[clickIndex] = true; });
logic.updateCustomModeConfig(); } else {
logic.updateCatEyeModeConfig(); //
} else { showBottomSheet(context, clickIndex);
state.boolList.value[i] = false; }
} },
),
],
)),
),
onTap: () {
for (int i = 0; i < state.boolList.value.length; i++) {
if (clickIndex == i) {
state.boolList.value[clickIndex] = true;
logic.updateCustomModeConfig(i);
} else {
state.boolList.value[i] = false;
} }
}); }
state.boolList.refresh();
},
);
} }
Widget _buildRichText(String titleStr, String subTitle, bool isClick) { Widget _buildRichText(String titleStr, String subTitle, bool isClick) {
@ -175,14 +194,29 @@ class _CatEyeWorkModePageState extends State<CatEyeWorkModePage> {
builder: (BuildContext context) { builder: (BuildContext context) {
// //
if (clickIndex == 0) { if (clickIndex == 0) {
return _buildBottomSheetWidget(context, '省电模式'.tr, '有人按门铃或发生'.tr + '\n' + '异常事件时'.tr, return _buildBottomSheetWidget(
'不录像'.tr, '/', '有人按门铃或发生'.tr + '\n' + '异常事件时'.tr); context,
'省电模式'.tr,
'有人按门铃或发生'.tr + '\n' + '异常事件时'.tr,
'不录像'.tr,
'/',
'有人按门铃或发生'.tr + '\n' + '异常事件时'.tr);
} else if (clickIndex == 1) { } else if (clickIndex == 1) {
return _buildBottomSheetWidget(context, '逗留抓拍模式'.tr, return _buildBottomSheetWidget(
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr, '逗留达到10秒'.tr, '约1.5米'.tr, '随时'.tr); context,
'逗留抓拍模式'.tr,
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr,
'逗留达到10秒'.tr,
'约1.5米'.tr,
'随时'.tr);
} else if (clickIndex == 2) { } else if (clickIndex == 2) {
return _buildBottomSheetWidget( return _buildBottomSheetWidget(
context, '实时监控模式'.tr, '有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr, '立即录像'.tr, '约1.5米'.tr, '随时'.tr); context,
'实时监控模式'.tr,
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr,
'立即录像'.tr,
'约1.5米'.tr,
'随时'.tr);
} else { } else {
return Container(); return Container();
} }

View File

@ -1,37 +1,43 @@
import 'dart:ffi';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
class CatEyeWorkModeState { class CatEyeWorkModeState {
CatEyeWorkModeState() { CatEyeWorkModeState() {
Map map = Get.arguments; Map map = Get.arguments;
lockSetInfoData.value = map['lockSetInfoData']; lockSetInfoData.value = map['lockSetInfoData'];
// if (map['catEyeConfigData'] != null) { if (lockSetInfoData.value != null) {
// catEyeConfigData.value = map['catEyeConfigData']; // if (lockSetInfoData.value.lockSettingInfo?.catEyeConfig != null &&
// selectCatEyeWorkMode.value = catEyeConfigData.value.catEyeMode!; // lockSetInfoData.value.lockSettingInfo?.catEyeConfig!.length != 0) {
// catEyeConfigData.value =
// if (catEyeConfigData.value.catEyeMode == // lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0];
// XSConstantMacro.catEyeWorkModePowerSaving) { // if (catEyeConfigData.value.catEyeMode ==
// boolList[0] = true; // XSConstantMacro.catEyeWorkModePowerSaving) {
// } else if (catEyeConfigData.value.catEyeMode == // boolList.value = <bool>[true, false, false, false];
// XSConstantMacro.catEyeWorkModeStayCapture) { // } else if (catEyeConfigData.value.catEyeMode ==
// boolList[1] = true; // XSConstantMacro.catEyeWorkModeStayCapture) {
// } else if (catEyeConfigData.value.catEyeMode == // boolList.value = <bool>[false, true, false, false];
// XSConstantMacro.catEyeWorkModeRealTimeMonitoring) { // } else if (catEyeConfigData.value.catEyeMode ==
// boolList[2] = true; // XSConstantMacro.catEyeWorkModeRealTimeMonitoring) {
// } else if (catEyeConfigData.value.catEyeMode == // boolList.value = <bool>[false, false, true, false];
// XSConstantMacro.catEyeWorkModeCustom) { // } else if (catEyeConfigData.value.catEyeMode ==
// boolList[3] = true; // XSConstantMacro.catEyeWorkModeCustom) {
// } // boolList.value = <bool>[false, false, false, true];
// } else { // }
// catEyeConfigData.value = CatEyeConfig(); // } else {
// } // boolList.value = <bool>[false, false, false, false];
// }
}
} }
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs; Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
// var selectCatEyeWorkMode = 0.obs; // // var selectCatEyeWorkMode = 0.obs; //
RxList<bool> boolList = <bool>[false, false, false, false].obs; RxList<bool> boolList = <bool>[false, false, false, false].obs;
Rx<CatEyeConfig> catEyeConfigData = CatEyeConfig().obs; Rx<CatEyeConfig> catEyeConfigData = CatEyeConfig().obs;
///
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
} }

View File

@ -3,6 +3,7 @@ import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/blue/blue_manage.dart'; import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
import 'package:star_lock/blue/io_tool/io_tool.dart'; import 'package:star_lock/blue/io_tool/io_tool.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
@ -16,37 +17,8 @@ import 'package:star_lock/versionUndate/versionUndate_entity.dart';
class VideoSlotLogic extends BaseGetXController { class VideoSlotLogic extends BaseGetXController {
final VideoSlotState state = VideoSlotState(); final VideoSlotState state = VideoSlotState();
// final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
Future<LockSetInfoEntity> getLockSettingInfoData() async { final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
state.lockSetInfoData.value = entity.data!;
if (entity.data!.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
state.catEyeConfigData.value =
entity.data!.lockSettingInfo!.catEyeConfig![0];
if (state.catEyeConfigData.value.catEyeModeConfig != null) {
if (state.catEyeConfigData.value.catEyeModeConfig!.recordMode == 1) {
state.isCustom.value = true;
} else {
state.isCustom.value = false;
}
state.startDate.value = DateTool().dateToHNString(state
.catEyeConfigData.value.catEyeModeConfig!.recordStartTime!
.toString());
state.endDate.value = DateTool().dateToHNString(state
.catEyeConfigData.value.catEyeModeConfig!.recordEndTime!
.toString());
_getConfigAndGenerateBleData();
}
}
}
return entity;
}
// //
Future<void> updateCatEyeModeConfig() async { Future<void> updateCatEyeModeConfig() async {
@ -54,7 +26,7 @@ class VideoSlotLogic extends BaseGetXController {
? state.recordMode.value = 0 ? state.recordMode.value = 0
: state.recordMode.value = 1; : state.recordMode.value = 1;
if (state.recordMode.value == 1) { if (state.isCustom.isTrue) {
// //
DateTime now = DateTime.now(); DateTime now = DateTime.now();
@ -80,274 +52,45 @@ class VideoSlotLogic extends BaseGetXController {
// //
state.recordEndTime.value = state.recordEndTime.value =
todayAtTimee.add(Duration(days: 1)).millisecondsSinceEpoch; todayAtTimee.add(Duration(days: 1)).millisecondsSinceEpoch;
print('object');
}
final VersionUndateEntity entity =
await ApiRepository.to.updateCatEyeModeConfig(
lockId: state.lockSetInfoData.value.lockId!,
catEyeConfig: [
{
'catEyeMode': 4,
'catEyeModeConfig': {
'recordMode': state.recordMode.value,
'recordStartTime': state.recordStartTime.value,
'recordEndTime': state.recordEndTime.value,
'recordTime':
state.catEyeConfigData.value.catEyeModeConfig!.recordTime,
'detectionDistance': state
.catEyeConfigData.value.catEyeModeConfig!.detectionDistance,
'realTimeMode':
state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode,
}
}
],
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
Get.back();
}
}
_getConfigAndGenerateBleData() { catEyeSetState.settingOptions.value = 5;
int originalCatEyeMode = state catEyeSetState.catEyeConfig.value.catEyeMode = 3;
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!; catEyeSetState.catEyeConfig.value.recordMode = 0;
int recordMode = state.lockSetInfoData.value.lockSettingInfo! catEyeSetState.catEyeConfig.value.recordStartTime =
.catEyeConfig![0].catEyeModeConfig!.recordMode == state.recordStartTime.value;
0 catEyeSetState.catEyeConfig.value.recordEndTime =
? 1 state.recordEndTime.value;
: 0; catEyeSetLogic.sendBlueMessage();
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
int recordStartTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
int recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
state.catEyeConfig.refresh();
}
///
void updateCatEyeSetConfig() async {
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; //
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; //
final int startTime =
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM
final int endTime =
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; //
final int detectionDistance =
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8
final int realTimePicture =
state.catEyeConfig.value.realTimePicture ?? 0; //
final int automaticBrightening =
state.catEyeConfig.value.autoLightScreen ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 15
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; //
final int exceptionWarning =
state.catEyeConfig.value.abnormalWarn ?? 1; //
/// 0
final List<int> config = generateConfig(
operatingMode: operatingMode,
isAllDay: isAllDay,
startTime: startTime,
endTime: endTime,
recordingTime: recordingTime,
detectionDistance: detectionDistance,
realTimePicture: realTimePicture,
automaticBrightening: automaticBrightening,
brightScreenTime: brightScreenTime,
stayWarning: stayWarning,
exceptionWarning: exceptionWarning,
);
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 command = SetSupportFunctionsWithParametersCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(),
featureBit: 64,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList,
);
final packageData = command.packageData();
// List<int>
String hexString = packageData
.map((byte) => byte.toRadixString(16).padLeft(2, '0'))
.join(' ');
///
StartChartManage().sendBleMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
bleStructData: packageData,
);
}
//
List<int> generateConfig({
required int operatingMode,
required int isAllDay,
required int startTime,
required int endTime,
required int recordingTime,
required int detectionDistance,
required int realTimePicture,
required int automaticBrightening,
required int brightScreenTime,
required int stayWarning,
required int exceptionWarning,
}) {
//
List<int> config = [];
// operatingMode
config.add(operatingMode);
// 0
if (operatingMode != 3) {
config.addAll(
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else { } else {
config.add(isAllDay); catEyeSetState.settingOptions.value = 5;
config.addAll(_intToBytes(startTime, 2)); // StartTime 2 catEyeSetState.catEyeConfig.value.catEyeMode = 3;
config.addAll(_intToBytes(endTime, 2)); // EndTime 2 catEyeSetState.catEyeConfig.value.recordMode = 1;
config.add(recordingTime); catEyeSetState.catEyeConfig.value.recordStartTime = 0;
} catEyeSetState.catEyeConfig.value.recordEndTime = 0;
catEyeSetLogic.sendBlueMessage();
// detectionDistance realTimePicture 0
if (operatingMode != 3) {
config.addAll([0, 0]);
} else {
config.add(detectionDistance);
config.add(realTimePicture);
}
//
config.add(automaticBrightening);
config.add(brightScreenTime);
config.add(stayWarning);
config.add(exceptionWarning);
return config;
}
//
List<int> _intToBytes(int value, int length) {
List<int> bytes = [];
for (int i = length - 1; i >= 0; i--) {
bytes.add((value >> (8 * i)) & 0xFF);
}
return bytes;
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
} }
} }
int _handleDetectionDistance(String s) { @override
if (s == '约0.8米') { void onInit() {
return 0; // TODO: implement onInit
super.onInit();
state.isCustom.value = catEyeSetState.catEyeConfig.value.recordMode == 0;
state.startDate.value = _handleMinutesToTime(
catEyeSetState.catEyeConfig.value.recordStartTime!);
state.endDate.value = _handleMinutesToTime(
catEyeSetState.catEyeConfig.value.recordEndTime!);
}
String _handleMinutesToTime(int minutes) {
if (minutes < 0) {
throw ArgumentError("分钟数不能为负值");
} }
if (s == '约1.5米') {
return 1; //
} int hours = minutes ~/ 60; // 60
if (s == '约3.0米') { int mins = minutes % 60; //
return 2;
} // HH:mm
return 0; return "${hours.toString().padLeft(2, '0')}:${mins.toString().padLeft(2, '0')}";
} }
} }

View File

@ -25,42 +25,44 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
@override @override
initState() { initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: AppColors.mainBackgroundColor, backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar( appBar: TitleAppBar(
barTitle: '录像时段'.tr, barTitle: '录像时段'.tr,
haveBack: true, haveBack: true,
backAction: () { backAction: () {
Navigator.pop(context, true); Navigator.pop(context, true);
}, },
backgroundColor: AppColors.mainColor, backgroundColor: AppColors.mainColor,
actionsList: <Widget>[ actionsList: <Widget>[
TextButton( TextButton(
child: Text( child: Text(
'保存'.tr, '保存'.tr,
style: TextStyle(color: Colors.white, fontSize: 24.sp), style: TextStyle(color: Colors.white, fontSize: 24.sp),
),
onPressed: logic.updateCatEyeModeConfig,
), ),
onPressed: logic.updateCatEyeModeConfig,
),
],
),
body: Obx(
() => Column(
children: <Widget>[
SizedBox(
height: 30.h,
),
_buildTipsView('全天'.tr, 0),
SizedBox(
height: 30.h,
),
_buildCustomTimeView('自定义时间'.tr, 1),
], ],
), ),
body: Obx(() => Column( ),
children: <Widget>[ );
SizedBox(
height: 30.h,
),
_buildTipsView('全天'.tr, 0),
SizedBox(
height: 30.h,
),
_buildCustomTimeView('自定义时间'.tr, 1),
],
)));
} }
// //
@ -76,27 +78,31 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
child: Padding( child: Padding(
padding: EdgeInsets.only( padding:
left: 20.w, top: 30.h, bottom: 30.h, right: 20.w), EdgeInsets.only(left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
if (state.isCustom.value == false) Image.asset( if (state.isCustom.value == false)
'images/mine/icon_mine_blueSelect.png', Image.asset(
width: 20.w, 'images/mine/icon_mine_blueSelect.png',
height: 14.w, width: 20.w,
) else SizedBox( height: 14.w,
width: 20.w, )
height: 14.w, else
),
SizedBox(width: 10.w),
Expanded(
child: _buildRichText(titleStr, false),
),
SizedBox( SizedBox(
width: 10.w, width: 20.w,
height: 14.w,
), ),
], SizedBox(width: 10.w),
)), Expanded(
child: _buildRichText(titleStr, false),
),
SizedBox(
width: 10.w,
),
],
),
),
), ),
onTap: () { onTap: () {
if (clickIndex == 0) { if (clickIndex == 0) {
@ -127,17 +133,21 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
children: <Widget>[ children: <Widget>[
Row( Row(
children: <Widget>[ children: <Widget>[
if (state.isCustom.value == true) Image.asset( if (state.isCustom.value == true)
'images/mine/icon_mine_blueSelect.png', Image.asset(
width: 20.w, 'images/mine/icon_mine_blueSelect.png',
height: 14.w, width: 20.w,
) else SizedBox( height: 14.w,
width: 20.w, )
height: 14.w, else
), SizedBox(
width: 20.w,
height: 14.w,
),
SizedBox(width: 10.w), SizedBox(width: 10.w),
Expanded( Expanded(
child: _buildRichText('自定义时间'.tr, state.isCustom.value), child:
_buildRichText('自定义时间'.tr, state.isCustom.value),
), ),
SizedBox( SizedBox(
width: 10.w, width: 10.w,
@ -145,22 +155,31 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
], ],
), ),
// //
if (state.isCustom.value == false) Container() else Container( if (state.isCustom.value == false)
height: 1, Container()
margin: EdgeInsets.only( else
left: 20.w, Container(
right: 20.w, height: 1,
top: 20.h, margin: EdgeInsets.only(
bottom: 20.h), left: 20.w, right: 20.w, top: 20.h, bottom: 20.h),
color: state.isCustom.value == true color: state.isCustom.value == true
? AppColors.blueTextTipsColor ? AppColors.blueTextTipsColor
: Colors.black, : Colors.black,
), ),
if (state.isCustom.value == false) Container() else startAndEndTimeRow(false), if (state.isCustom.value == false)
if (state.isCustom.value == false) Container() else SizedBox( Container()
height: 30.h, else
), startAndEndTimeRow(false),
if (state.isCustom.value == false) Container() else startAndEndTimeRow(true), if (state.isCustom.value == false)
Container()
else
SizedBox(
height: 30.h,
),
if (state.isCustom.value == false)
Container()
else
startAndEndTimeRow(true),
], ],
)), )),
)), )),
@ -218,7 +237,8 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
PDuration selectDate = PDuration.parse(DateTime.tryParse( PDuration selectDate = PDuration.parse(DateTime.tryParse(
isEndTime == false ? state.startDate.value : state.endDate.value)); isEndTime == false ? state.startDate.value : state.endDate.value));
Pickers.showDatePicker(context, Pickers.showDatePicker(context,
selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) { selectDate: selectDate,
mode: DateMode.HM, onConfirm: (PDuration p) {
if (isEndTime == false) { if (isEndTime == false) {
state.startDate.value = DateTool().getYMDHNDateString(p, 3); state.startDate.value = DateTool().getYMDHNDateString(p, 3);
} else { } else {

View File

@ -3,6 +3,7 @@ import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/blue/blue_manage.dart'; import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart'; import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
import 'package:star_lock/blue/io_tool/io_tool.dart'; import 'package:star_lock/blue/io_tool/io_tool.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/liveVideo/liveVideo_state.dart'; import 'package:star_lock/main/lockDetail/lockSet/liveVideo/liveVideo_state.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart';
@ -15,299 +16,20 @@ import 'package:star_lock/versionUndate/versionUndate_entity.dart';
class LiveVideoLogic extends BaseGetXController { class LiveVideoLogic extends BaseGetXController {
final LiveVideoState state = LiveVideoState(); final LiveVideoState state = LiveVideoState();
// final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
Future<LockSetInfoEntity> getLockSettingInfoData() async { final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
final LockSetInfoEntity entity =
await ApiRepository.to.getLockSettingInfoData(
lockId: state.lockSetInfoData.value.lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
state.lockSetInfoData.value = entity.data!;
if (entity.data!.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
state.catEyeConfigData.value =
entity.data!.lockSettingInfo!.catEyeConfig![0];
if (state.catEyeConfigData.value.catEyeModeConfig != null) { void updateCatEyeModeConfig() {
state.realTimeMode.value = catEyeSetState.settingOptions.value = 5;
state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode!; catEyeSetState.catEyeConfig.value.catEyeMode = 4;
if (state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode == catEyeSetState.catEyeConfig.value.realTimeMode = state.realTimeMode.value;
1) { catEyeSetLogic.sendBlueMessage();
state.isLiveView.value = true;
} else {
state.isLiveView.value = false;
}
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
}
}
}
return entity;
} }
// @override
Future<void> updateCatEyeModeConfig() async { void onInit() {
final VersionUndateEntity entity = super.onInit();
await ApiRepository.to.updateCatEyeModeConfig( state.isLiveView.value =
lockId: state.lockSetInfoData.value.lockId ?? 0, catEyeSetState.catEyeConfig.value.realTimeMode == 1;
catEyeConfig: [
<String, Object>{
'catEyeMode': 4,
'catEyeModeConfig': <String, Object?>{
'recordMode':
state.catEyeConfigData.value.catEyeModeConfig!.recordMode,
'recordStartTime':
state.catEyeConfigData.value.catEyeModeConfig!.recordStartTime,
'recordEndTime':
state.catEyeConfigData.value.catEyeModeConfig!.recordEndTime,
'recordTime':
state.catEyeConfigData.value.catEyeModeConfig!.recordTime,
'detectionDistance': state
.catEyeConfigData.value.catEyeModeConfig!.detectionDistance,
'realTimeMode': state.realTimeMode.value,
}
}
],
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
_getConfigAndGenerateBleData();
updateCatEyeSetConfig();
Get.back();
}
}
_getConfigAndGenerateBleData() {
int originalCatEyeMode = state
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0].catEyeMode!;
int recordMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.recordMode ==
0
? 1
: 0;
int stayWarn = state.lockSetInfoData.value.lockSettingInfo!.stayWarn!;
int abnormalWarn =
state.lockSetInfoData.value.lockSettingInfo!.abnormalWarn!;
int autoLightScreen =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreen!;
int recordStartTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordStartTime!);
int recordEndTime = _handleTimeToM(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordEndTime!);
int recordTime = _handleGetIntNumber(state.lockSetInfoData.value
.lockSettingInfo!.catEyeConfig![0].catEyeModeConfig!.recordTime!);
int detectionDistance = _handleDetectionDistance(state
.lockSetInfoData
.value
.lockSettingInfo!
.catEyeConfig![0]
.catEyeModeConfig!
.detectionDistance!);
int realTimeMode = state.lockSetInfoData.value.lockSettingInfo!
.catEyeConfig![0].catEyeModeConfig!.realTimeMode!;
// catEyeMode
int adjustedCatEyeMode =
originalCatEyeMode > 0 ? originalCatEyeMode - 1 : originalCatEyeMode;
int brightScreenTime =
state.lockSetInfoData.value.lockSettingInfo!.autoLightScreenTime!;
/// v0.2
state.catEyeConfig.value = CatEyeSetEntity(
catEyeMode: adjustedCatEyeMode,
//
recordMode: recordMode,
// 0 1
recordStartTime: recordStartTime,
//recordStartTime与recordEndTime参数
recordEndTime: recordEndTime,
//recordStartTime与recordEndTime参数
realTimeMode: realTimeMode,
autoLightScreenTime: brightScreenTime,
stayWarn: stayWarn,
autoLightScreen: autoLightScreen,
//
abnormalWarn: abnormalWarn,
//
recordTime: recordTime,
//
detectionDistance: detectionDistance,
realTimePicture: realTimeMode,
);
state.catEyeConfig.refresh();
}
///
void updateCatEyeSetConfig() async {
final int operatingMode = state.catEyeConfig.value.catEyeMode ?? 1; //
final int isAllDay = state.catEyeConfig.value.recordMode ?? 1; //
final int startTime =
state.catEyeConfig.value.recordStartTime ?? 480; // 8:00 AM
final int endTime =
state.catEyeConfig.value.recordEndTime ?? 1080; // 6:00 PM
final int recordingTime = state.catEyeConfig.value.recordTime ?? 0; //
final int detectionDistance =
state.catEyeConfig.value.detectionDistance ?? 0; //0:0.8
final int realTimePicture =
state.catEyeConfig.value.realTimePicture ?? 0; //
final int automaticBrightening =
state.catEyeConfig.value.autoLightScreen ?? 1; //
final int brightScreenTime =
state.catEyeConfig.value.autoLightScreenTime ?? 10; // 15
final int stayWarning = state.catEyeConfig.value.stayWarn ?? 1; //
final int exceptionWarning =
state.catEyeConfig.value.abnormalWarn ?? 1; //
/// 0
final List<int> config = generateConfig(
operatingMode: operatingMode,
isAllDay: isAllDay,
startTime: startTime,
endTime: endTime,
recordingTime: recordingTime,
detectionDistance: detectionDistance,
realTimePicture: realTimePicture,
automaticBrightening: automaticBrightening,
brightScreenTime: brightScreenTime,
stayWarning: stayWarning,
exceptionWarning: exceptionWarning,
);
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 command = SetSupportFunctionsWithParametersCommand(
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
userID: await Storage.getUid(),
featureBit: 64,
featureParaLength: config.length,
featureData: config,
token: getTokenList,
needAuthor: 1,
publicKey: getPublicKeyList,
privateKey: getPrivateKeyList,
);
final packageData = command.packageData();
///
StartChartManage().sendBleMessage(
bluetoothDeviceName: BlueManage().connectDeviceName,
bleStructData: packageData,
);
}
//
List<int> generateConfig({
required int operatingMode,
required int isAllDay,
required int startTime,
required int endTime,
required int recordingTime,
required int detectionDistance,
required int realTimePicture,
required int automaticBrightening,
required int brightScreenTime,
required int stayWarning,
required int exceptionWarning,
}) {
//
List<int> config = [];
// operatingMode
config.add(operatingMode);
// 0
if (operatingMode != 3) {
config.addAll(
[0, 0, 0, 0, 0, 0]); // IsAllDay, StartTime, EndTime, recordingTime
} else {
config.add(isAllDay);
config.addAll(_intToBytes(startTime, 2)); // StartTime 2
config.addAll(_intToBytes(endTime, 2)); // EndTime 2
config.add(recordingTime);
}
// detectionDistance realTimePicture 0
if (operatingMode != 3) {
config.addAll([0, 0]);
} else {
config.add(detectionDistance);
config.add(realTimePicture);
}
//
config.add(automaticBrightening);
config.add(brightScreenTime);
config.add(stayWarning);
config.add(exceptionWarning);
return config;
}
//
List<int> _intToBytes(int value, int length) {
List<int> bytes = [];
for (int i = length - 1; i >= 0; i--) {
bytes.add((value >> (8 * i)) & 0xFF);
}
return bytes;
}
int _handleTimeToM(int recordStartTime) {
// DateTime
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(recordStartTime);
//
int hour = dateTime.hour;
int minute = dateTime.minute;
print("时: $hour, 分: $minute");
// 0
int minutesSinceMidnight = dateTime.hour * 60 + dateTime.minute;
return minutesSinceMidnight;
}
int _handleGetIntNumber(String recordTime) {
if (recordTime == '不录像') {
return 0;
}
if (recordTime == '立即录像') {
return 1;
}
// 使
RegExp regExp = RegExp(r'(\d+)秒');
Match? match = regExp.firstMatch(recordTime);
if (match != null && match.groupCount >= 1) {
//
int number = int.parse(match.group(1)!);
return number;
} else {
return 0;
}
}
int _handleDetectionDistance(String s) {
if (s == '约0.8米') {
return 0;
}
if (s == '约1.5米') {
return 1;
}
if (s == '约3.0米') {
return 2;
}
return 0;
} }
} }

View File

@ -21,7 +21,6 @@ class _LiveVideoPageState extends State<LiveVideoPage> {
@override @override
initState() { initState() {
super.initState(); super.initState();
logic.getLockSettingInfoData();
} }
@override @override