fix:重新优化猫眼设置项逻辑
This commit is contained in:
parent
42a3231f96
commit
602050b90c
@ -71,10 +71,10 @@ class XSConstantMacro {
|
||||
static int lockEventTypeVideo = 40;
|
||||
|
||||
//猫眼工作模式
|
||||
static int catEyeWorkModePowerSaving = 1; //省电模式
|
||||
static int catEyeWorkModeStayCapture = 2; //逗留抓拍模式
|
||||
static int catEyeWorkModeRealTimeMonitoring = 3; //实时监控模式
|
||||
static int catEyeWorkModeCustom = 4; //自定义模式
|
||||
static int catEyeWorkModePowerSaving = 0; //省电模式
|
||||
static int catEyeWorkModeStayCapture = 1; //逗留抓拍模式
|
||||
static int catEyeWorkModeRealTimeMonitoring = 2; //实时监控模式
|
||||
static int catEyeWorkModeCustom = 3; //自定义模式
|
||||
|
||||
//管理员类型
|
||||
static int userTypeSuperAdmin = 110301; //超级管理员
|
||||
|
||||
@ -21,7 +21,6 @@ class _LiveVideoPageState extends State<LiveVideoPage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -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_tool/io_tool.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/lockSet/lockSetInfo_entity.dart';
|
||||
import 'package:star_lock/network/api_repository.dart';
|
||||
@ -16,78 +17,8 @@ import '../../../../../blue/sender_manage.dart';
|
||||
|
||||
class CatEyeCustomModeLogic extends BaseGetXController {
|
||||
final CatEyeCustomModeState state = CatEyeCustomModeState();
|
||||
|
||||
// 获取锁设置信息
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
|
||||
final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
|
||||
|
||||
//设置猫眼工作模式 0-有人出现时录像 1-人体侦测距离
|
||||
void updateCatEyeModeConfig(int clickIndex) async {
|
||||
@ -118,244 +49,36 @@ class CatEyeCustomModeLogic extends BaseGetXController {
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast('设置成功'.tr);
|
||||
await getLockSettingInfoData();
|
||||
// await getLockSettingInfoData();
|
||||
}
|
||||
}
|
||||
|
||||
_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 updateCustomModeConfig(clickIndex) {
|
||||
catEyeSetState.catEyeConfig.value.catEyeMode = 4;
|
||||
catEyeSetState.catEyeConfig.value.recordTime =
|
||||
state.showsUpVideoList.value.indexOf(state.recordTime.value);
|
||||
catEyeSetState.catEyeConfig.value.detectionDistance =
|
||||
state.detectionRangeList.value.indexOf(state.detectionDistance.value);
|
||||
catEyeSetState.settingOptions.value = 5;
|
||||
catEyeSetLogic.sendBlueMessage();
|
||||
}
|
||||
|
||||
/// 更新锁板上的猫眼配置
|
||||
Future<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,
|
||||
// );
|
||||
|
||||
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
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (catEyeSetState.catEyeConfig.value.recordMode == 0) {
|
||||
state.selectVideoSlot.value = '自定义时段'.tr;
|
||||
} else {
|
||||
config.add(isAllDay);
|
||||
config.addAll(_intToBytes(startTime, 2)); // StartTime 占用2个字节
|
||||
config.addAll(_intToBytes(endTime, 2)); // EndTime 占用2个字节
|
||||
config.add(recordingTime);
|
||||
state.selectVideoSlot.value = '全天'.tr;
|
||||
}
|
||||
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
|
||||
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;
|
||||
state.realTimeMode.value =
|
||||
catEyeSetState.catEyeConfig.value.realTimeMode == 0
|
||||
? '发生事件时查看'.tr
|
||||
: '实时查看'.tr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -24,7 +23,7 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
logic.getLockSettingInfoData();
|
||||
// logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -61,11 +60,13 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
|
||||
? state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0]
|
||||
: null
|
||||
}).then((value) => {logic.getLockSettingInfoData()});
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildSubTitleItem('有人出现时录像'.tr, '有人在门口出现10秒后开始录像。'.tr + '\n' + '有人按门铃时立即录像'.tr,
|
||||
_buildSubTitleItem(
|
||||
'有人出现时录像'.tr,
|
||||
'有人在门口出现10秒后开始录像。'.tr + '\n' + '有人按门铃时立即录像'.tr,
|
||||
state.recordTime.value, () {
|
||||
_openBottomItemSheet(state.showsUpVideoList.value, 0);
|
||||
}),
|
||||
@ -96,7 +97,7 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
|
||||
? state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0]
|
||||
: null
|
||||
}).then((value) => {logic.getLockSettingInfoData()});
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
@ -167,25 +168,26 @@ class _CatEyeCustomModePageState extends State<CatEyeCustomModePage> {
|
||||
|
||||
Future _openBottomItemSheet(List bottomItemList, int clickIndex) async {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadiusDirectional.circular(10)),
|
||||
builder: (BuildContext context) {
|
||||
return AlertBottomWidget(
|
||||
topTitle: '',
|
||||
items: bottomItemList,
|
||||
chooseCallback: (value) {
|
||||
if (clickIndex == 0) {
|
||||
//有人出现时录像
|
||||
state.recordTime.value = state.showsUpVideoList.value[value];
|
||||
} else if (clickIndex == 1) {
|
||||
//人体侦测距离
|
||||
state.detectionDistance.value =
|
||||
state.detectionRangeList.value[value];
|
||||
}
|
||||
logic.updateCatEyeModeConfig(clickIndex);
|
||||
},
|
||||
);
|
||||
});
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadiusDirectional.circular(10)),
|
||||
builder: (BuildContext context) {
|
||||
return AlertBottomWidget(
|
||||
topTitle: '',
|
||||
items: bottomItemList,
|
||||
chooseCallback: (value) {
|
||||
if (clickIndex == 0) {
|
||||
//有人出现时录像
|
||||
state.recordTime.value = state.showsUpVideoList.value[value];
|
||||
} else if (clickIndex == 1) {
|
||||
//人体侦测距离
|
||||
state.detectionDistance.value =
|
||||
state.detectionRangeList.value[value];
|
||||
}
|
||||
logic.updateCustomModeConfig(clickIndex);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,21 +2,45 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.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/lockSet/lockSetInfo_entity.dart';
|
||||
|
||||
class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查看
|
||||
class CatEyeCustomModeState {
|
||||
//实时画面 0发生事件事查看 1实时查看
|
||||
|
||||
CatEyeCustomModeState() {
|
||||
Map map = Get.arguments;
|
||||
if (map['lockSetInfoData'] != null) {
|
||||
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) {
|
||||
catEyeConfigData.value = map['catEyeConfigData'];
|
||||
}
|
||||
}
|
||||
|
||||
RxBool isCheck = false.obs;
|
||||
RxBool faceOn = false.obs; //面容开锁
|
||||
RxBool autoBright = false.obs; //自动亮屏
|
||||
@ -31,21 +55,20 @@ class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查
|
||||
'30${"秒".tr}',
|
||||
'60${"秒".tr}'
|
||||
].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(
|
||||
color: Colors.black, fontSize: 24.sp, fontWeight: FontWeight.w500);
|
||||
|
||||
//默认样式
|
||||
final TextStyle subTipsStyle =
|
||||
TextStyle(color: AppColors.placeholderTextColor, fontSize: 22.sp);
|
||||
|
||||
late InlineSpan tipsPreviewSpan = TextSpan(children: <InlineSpan>[
|
||||
TextSpan(
|
||||
text: '${"添加和使用面容开锁时".tr}:\n',
|
||||
style: titleStyle),
|
||||
TextSpan(
|
||||
text: '添加和使用面容开锁时提示'.tr,
|
||||
style: subTipsStyle),
|
||||
TextSpan(text: '${"添加和使用面容开锁时".tr}:\n', style: titleStyle),
|
||||
TextSpan(text: '添加和使用面容开锁时提示'.tr, style: subTipsStyle),
|
||||
]);
|
||||
|
||||
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
|
||||
@ -56,7 +79,6 @@ class CatEyeCustomModeState { //实时画面 0发生事件事查看 1实时查
|
||||
RxString detectionDistance = ''.obs; //人体侦测距离
|
||||
RxString realTimeMode = ''.obs;
|
||||
|
||||
|
||||
/// 猫眼配置
|
||||
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.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/io_protocol/io_setSupportFunctionsWithParameters.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/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.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/eventBusEventManage.dart';
|
||||
import 'package:star_lock/tools/storage.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 {
|
||||
final int status = reply.data[2];
|
||||
@ -70,10 +75,17 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
updateLightScreenTimeConfig();
|
||||
}
|
||||
break;
|
||||
case 5: //修改猫眼工作模式
|
||||
{
|
||||
updateCatEyeModeConfig();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
getLockSettingInfoData();
|
||||
break;
|
||||
|
||||
case 0x06:
|
||||
//无权限
|
||||
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 =
|
||||
await ApiRepository.to.getLockSettingInfoData(
|
||||
lockId: state.lockSetInfoData.value.lockId.toString(),
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
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 = ''; //猫眼工作模式
|
||||
|
||||
// selectCatEyeWorkMode.value = catEyeConfigData.value.catEyeMode!;
|
||||
|
||||
if (state
|
||||
.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.isNotEmpty) {
|
||||
if (state.lockSetInfoData.value.lockSettingInfo != null &&
|
||||
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig != null &&
|
||||
state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig!.length >
|
||||
0) {
|
||||
if (state.lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0]
|
||||
.catEyeMode ==
|
||||
XSConstantMacro.catEyeWorkModePowerSaving) {
|
||||
@ -203,101 +129,109 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
state.selectCatEyeWorkMode.value = '自定义模式'.tr;
|
||||
}
|
||||
}
|
||||
state.updateCatEyeSetByState();
|
||||
|
||||
state.catEyeConfig.refresh();
|
||||
}
|
||||
// 更新state中的猫眼设置
|
||||
await _updateCatEyeSetByState();
|
||||
return entity;
|
||||
}
|
||||
|
||||
// 更新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 (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,
|
||||
//设置自动亮屏
|
||||
Future<void> updateAutoLightScreenConfig() async {
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateAutoLightScreenConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
autoLightScreen: state.isAutoBright.value == true ? 1 : 0,
|
||||
);
|
||||
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() {
|
||||
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
|
||||
_handleTimeToM(state.catEyeConfig.value.recordStartTime!) ??
|
||||
480; // 8:00 AM
|
||||
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 detectionDistance =
|
||||
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
|
||||
} else {
|
||||
config.add(isAllDay);
|
||||
config.addAll(_intToBytes(startTime, 2)); // StartTime 占用2个字节
|
||||
config.addAll(_intToBytes(endTime, 2)); // EndTime 占用2个字节
|
||||
if (isAllDay == 1) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -385,54 +325,6 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
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) {
|
||||
switch (clickIndex) {
|
||||
case 1: //自动亮屏
|
||||
@ -458,7 +350,8 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
break;
|
||||
case 4: //设置亮屏持续时间
|
||||
{
|
||||
state.isExceptionWarning.value = value;
|
||||
state.selectBrightDuration.value =
|
||||
state.brightDurationTimeList[value];
|
||||
state.settingOptions.value = 4;
|
||||
state.catEyeConfig.value.autoLightScreenTime =
|
||||
_handleGetIntNumber(state.selectBrightDuration.value);
|
||||
@ -467,6 +360,10 @@ class CatEyeSetLogic extends BaseGetXController {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
sendBlueMessage();
|
||||
}
|
||||
|
||||
void sendBlueMessage() {
|
||||
final message = _buildCatEyeSetBlueMessage();
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.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_state.dart';
|
||||
import 'package:star_lock/tools/commonItem.dart';
|
||||
@ -25,8 +26,6 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -46,17 +45,18 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
|
||||
isHaveLine: true,
|
||||
isHaveDirection: true,
|
||||
action: () {
|
||||
Navigator.pushNamed(context, Routers.catEyeWorkModePage,
|
||||
arguments: <String, Object?>{
|
||||
'lockSetInfoData': state.lockSetInfoData.value,
|
||||
'catEyeConfigData': state.lockSetInfoData.value
|
||||
.lockSettingInfo!.catEyeConfig!.isNotEmpty
|
||||
? state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0]
|
||||
: null
|
||||
}).then((Object? value) {
|
||||
logic.getLockSettingInfoData();
|
||||
});
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routers.catEyeWorkModePage,
|
||||
arguments: <String, Object?>{
|
||||
'lockSetInfoData': state.lockSetInfoData.value,
|
||||
'catEyeConfigData': state.lockSetInfoData.value
|
||||
.lockSettingInfo!.catEyeConfig!.isNotEmpty
|
||||
? state.lockSetInfoData.value.lockSettingInfo!
|
||||
.catEyeConfig![0]
|
||||
: null
|
||||
},
|
||||
);
|
||||
})),
|
||||
Obx(() => CommonItem(
|
||||
leftTitel: '自动亮屏'.tr,
|
||||
@ -125,19 +125,20 @@ class _CatEyeSetPageState extends State<CatEyeSetPage> {
|
||||
|
||||
Future _openBottomItemSheet() async {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadiusDirectional.circular(10)),
|
||||
builder: (BuildContext context) {
|
||||
return AlertBottomWidget(
|
||||
topTitle: '',
|
||||
items: state.brightDurationTimeList,
|
||||
chooseCallback: (int value) {
|
||||
state.selectBrightDuration.value =
|
||||
state.brightDurationTimeList[value];
|
||||
logic.updateSettingOptions(4, true);
|
||||
},
|
||||
);
|
||||
});
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadiusDirectional.circular(10)),
|
||||
builder: (BuildContext context) {
|
||||
return AlertBottomWidget(
|
||||
topTitle: '',
|
||||
items: state.brightDurationTimeList,
|
||||
chooseCallback: (int value) {
|
||||
state.selectBrightDuration.value =
|
||||
state.brightDurationTimeList[value];
|
||||
logic.updateSettingOptions(4, value);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:get/get.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';
|
||||
|
||||
class CatEyeSetState {
|
||||
@ -28,6 +29,29 @@ class CatEyeSetState {
|
||||
} else {
|
||||
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; // 设置项
|
||||
final String settingSuccess = '设置成功'.tr;
|
||||
|
||||
|
||||
/// 猫眼配置
|
||||
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 {
|
||||
@ -64,7 +162,6 @@ class CatEyeSetEntity {
|
||||
|
||||
CatEyeSetEntity({
|
||||
this.catEyeMode,
|
||||
|
||||
this.recordMode,
|
||||
this.recordTime,
|
||||
this.realTimeMode,
|
||||
|
||||
@ -22,410 +22,28 @@ import 'package:star_lock/versionUndate/versionUndate_entity.dart';
|
||||
|
||||
class CatEyeWorkModeLogic extends BaseGetXController {
|
||||
final CatEyeWorkModeState state = CatEyeWorkModeState();
|
||||
|
||||
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
|
||||
final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
|
||||
|
||||
// 获取解析后的数据
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
|
||||
void _initReplySubscription() {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
// 设置支持功能解析(带参数)
|
||||
if (reply is SetSupportFunctionsWithParametersReply) {
|
||||
_replySetSupportFunctionsWithParameters(reply);
|
||||
}
|
||||
});
|
||||
void updateCustomModeConfig(clickIndex) {
|
||||
catEyeSetState.catEyeConfig.value.catEyeMode = clickIndex;
|
||||
catEyeSetState.settingOptions.value = 5;
|
||||
catEyeSetLogic.sendBlueMessage();
|
||||
}
|
||||
|
||||
// 设置支持功能解析
|
||||
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
cancelBlueConnetctToastTimer();
|
||||
dismissEasyLoading();
|
||||
updateCatEyeModeConfig();
|
||||
break;
|
||||
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,
|
||||
}
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
catEyeSetState.catEyeConfig.refresh();
|
||||
if (catEyeSetState.catEyeConfig.value.catEyeMode != null) {
|
||||
for (int i = 0; i < state.boolList.value.length; i++) {
|
||||
if (catEyeSetState.catEyeConfig.value.catEyeMode! == i) {
|
||||
state.boolList.value[i] = true;
|
||||
} else {
|
||||
state.boolList.value[i] = false;
|
||||
}
|
||||
],
|
||||
);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_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();
|
||||
state.boolList.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -24,129 +23,149 @@ class _CatEyeWorkModePageState extends State<CatEyeWorkModePage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
logic.getLockSettingInfoData();
|
||||
// logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: TitleAppBar(
|
||||
barTitle: '猫眼工作模式'.tr,
|
||||
haveBack: true,
|
||||
backAction: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
backgroundColor: AppColors.mainColor),
|
||||
body: Obx(() => Column(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
height: 30.h,
|
||||
),
|
||||
_buildTipsView(
|
||||
'省电模式'.tr + ':\n',
|
||||
'适合门口较为安全的环境。'.tr + '\n' + '仅发生特定事件才录像,并可查看实时画面。'.tr + '\n' + '一般情况下,满电可使用7-8个月'.tr,
|
||||
0),
|
||||
SizedBox(
|
||||
height: 30.h,
|
||||
),
|
||||
_buildTipsView('逗留抓拍模式'.tr + ':\n',
|
||||
'有人逗留或发生特定事件才录像,可随时查看'.tr + '\n' + '实时画面。'.tr + '\n' + '一般情况下,满电可使用5~6个月。'.tr, 1),
|
||||
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)
|
||||
],
|
||||
)));
|
||||
backgroundColor: Colors.white,
|
||||
appBar: TitleAppBar(
|
||||
barTitle: '猫眼工作模式'.tr,
|
||||
haveBack: true,
|
||||
backAction: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
backgroundColor: AppColors.mainColor),
|
||||
body: Obx(
|
||||
() => Column(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
height: 30.h,
|
||||
),
|
||||
_buildTipsView(
|
||||
'省电模式'.tr + ':\n',
|
||||
'适合门口较为安全的环境。'.tr +
|
||||
'\n' +
|
||||
'仅发生特定事件才录像,并可查看实时画面。'.tr +
|
||||
'\n' +
|
||||
'一般情况下,满电可使用7-8个月'.tr,
|
||||
0),
|
||||
SizedBox(
|
||||
height: 30.h,
|
||||
),
|
||||
_buildTipsView(
|
||||
'逗留抓拍模式'.tr + ':\n',
|
||||
'有人逗留或发生特定事件才录像,可随时查看'.tr +
|
||||
'\n' +
|
||||
'实时画面。'.tr +
|
||||
'\n' +
|
||||
'一般情况下,满电可使用5~6个月。'.tr,
|
||||
1),
|
||||
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) {
|
||||
return GestureDetector(
|
||||
child: Container(
|
||||
width: ScreenUtil().screenWidth - 40.w,
|
||||
margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 10.h),
|
||||
decoration: BoxDecoration(
|
||||
color: state.boolList.value[clickIndex]
|
||||
? AppColors.blueViewBgColor
|
||||
: AppColors.greyBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (state.boolList.value[clickIndex]) Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
) else SizedBox(
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _buildRichText(
|
||||
titleStr, subTitle, state.boolList.value[clickIndex]),
|
||||
),
|
||||
child: Container(
|
||||
width: ScreenUtil().screenWidth - 40.w,
|
||||
margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 10.h),
|
||||
decoration: BoxDecoration(
|
||||
color: state.boolList.value[clickIndex]
|
||||
? AppColors.blueViewBgColor
|
||||
: AppColors.greyBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (state.boolList.value[clickIndex])
|
||||
Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
width: 10.w,
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
width: 90.w,
|
||||
height: 40.h,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
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),
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _buildRichText(
|
||||
titleStr, subTitle, state.boolList.value[clickIndex]),
|
||||
),
|
||||
SizedBox(
|
||||
width: 10.w,
|
||||
),
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
width: 90.w,
|
||||
height: 40.h,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
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: () {
|
||||
for (int i = 0; i < state.boolList.value.length; i++) {
|
||||
if (clickIndex == i) {
|
||||
state.boolList.value[clickIndex] = true;
|
||||
logic.updateCustomModeConfig();
|
||||
logic.updateCatEyeModeConfig();
|
||||
} else {
|
||||
state.boolList.value[i] = false;
|
||||
}
|
||||
onTap: () {
|
||||
//自定义模式跳转
|
||||
if (clickIndex == 3) {
|
||||
Navigator.pushNamed(context, Routers.catEyeCustomModePage,
|
||||
arguments: <String, LockSetInfoData>{
|
||||
'lockSetInfoData': state.lockSetInfoData.value,
|
||||
});
|
||||
} else {
|
||||
//其他模式弹框
|
||||
showBottomSheet(context, clickIndex);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
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) {
|
||||
@ -175,14 +194,29 @@ class _CatEyeWorkModePageState extends State<CatEyeWorkModePage> {
|
||||
builder: (BuildContext context) {
|
||||
//构建弹框中的内容
|
||||
if (clickIndex == 0) {
|
||||
return _buildBottomSheetWidget(context, '省电模式'.tr, '有人按门铃或发生'.tr + '\n' + '异常事件时'.tr,
|
||||
'不录像'.tr, '/', '有人按门铃或发生'.tr + '\n' + '异常事件时'.tr);
|
||||
return _buildBottomSheetWidget(
|
||||
context,
|
||||
'省电模式'.tr,
|
||||
'有人按门铃或发生'.tr + '\n' + '异常事件时'.tr,
|
||||
'不录像'.tr,
|
||||
'/',
|
||||
'有人按门铃或发生'.tr + '\n' + '异常事件时'.tr);
|
||||
} else if (clickIndex == 1) {
|
||||
return _buildBottomSheetWidget(context, '逗留抓拍模式'.tr,
|
||||
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr, '逗留达到10秒'.tr, '约1.5米'.tr, '随时'.tr);
|
||||
return _buildBottomSheetWidget(
|
||||
context,
|
||||
'逗留抓拍模式'.tr,
|
||||
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr,
|
||||
'逗留达到10秒'.tr,
|
||||
'约1.5米'.tr,
|
||||
'随时'.tr);
|
||||
} else if (clickIndex == 2) {
|
||||
return _buildBottomSheetWidget(
|
||||
context, '实时监控模式'.tr, '有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr, '立即录像'.tr, '约1.5米'.tr, '随时'.tr);
|
||||
context,
|
||||
'实时监控模式'.tr,
|
||||
'有人出现、按门铃'.tr + '\n' + '或发生异常事件时'.tr,
|
||||
'立即录像'.tr,
|
||||
'约1.5米'.tr,
|
||||
'随时'.tr);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
|
||||
@ -1,37 +1,43 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
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/lockSet/lockSetInfo_entity.dart';
|
||||
|
||||
class CatEyeWorkModeState {
|
||||
|
||||
CatEyeWorkModeState() {
|
||||
Map map = Get.arguments;
|
||||
lockSetInfoData.value = map['lockSetInfoData'];
|
||||
// if (map['catEyeConfigData'] != null) {
|
||||
// catEyeConfigData.value = map['catEyeConfigData'];
|
||||
// selectCatEyeWorkMode.value = catEyeConfigData.value.catEyeMode!;
|
||||
|
||||
// if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModePowerSaving) {
|
||||
// boolList[0] = true;
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeStayCapture) {
|
||||
// boolList[1] = true;
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeRealTimeMonitoring) {
|
||||
// boolList[2] = true;
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeCustom) {
|
||||
// boolList[3] = true;
|
||||
// }
|
||||
// } else {
|
||||
// catEyeConfigData.value = CatEyeConfig();
|
||||
// }
|
||||
if (lockSetInfoData.value != null) {
|
||||
// if (lockSetInfoData.value.lockSettingInfo?.catEyeConfig != null &&
|
||||
// lockSetInfoData.value.lockSettingInfo?.catEyeConfig!.length != 0) {
|
||||
// catEyeConfigData.value =
|
||||
// lockSetInfoData.value.lockSettingInfo!.catEyeConfig![0];
|
||||
// if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModePowerSaving) {
|
||||
// boolList.value = <bool>[true, false, false, false];
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeStayCapture) {
|
||||
// boolList.value = <bool>[false, true, false, false];
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeRealTimeMonitoring) {
|
||||
// boolList.value = <bool>[false, false, true, false];
|
||||
// } else if (catEyeConfigData.value.catEyeMode ==
|
||||
// XSConstantMacro.catEyeWorkModeCustom) {
|
||||
// boolList.value = <bool>[false, false, false, true];
|
||||
// }
|
||||
// } else {
|
||||
// boolList.value = <bool>[false, false, false, false];
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
|
||||
|
||||
// var selectCatEyeWorkMode = 0.obs; //猫眼工作模式
|
||||
RxList<bool> boolList = <bool>[false, false, false, false].obs;
|
||||
Rx<CatEyeConfig> catEyeConfigData = CatEyeConfig().obs;
|
||||
/// 猫眼配置
|
||||
Rx<CatEyeSetEntity> catEyeConfig = CatEyeSetEntity().obs;
|
||||
}
|
||||
|
||||
@ -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/io_protocol/io_setSupportFunctionsWithParameters.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/videoSlot/videoSlot_state.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 {
|
||||
final VideoSlotState state = VideoSlotState();
|
||||
|
||||
// 获取锁设置信息
|
||||
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.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;
|
||||
}
|
||||
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
|
||||
final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
|
||||
|
||||
//设置猫眼工作模式
|
||||
Future<void> updateCatEyeModeConfig() async {
|
||||
@ -54,7 +26,7 @@ class VideoSlotLogic extends BaseGetXController {
|
||||
? state.recordMode.value = 0
|
||||
: state.recordMode.value = 1;
|
||||
|
||||
if (state.recordMode.value == 1) {
|
||||
if (state.isCustom.isTrue) {
|
||||
// 获取当前日期
|
||||
DateTime now = DateTime.now();
|
||||
|
||||
@ -80,274 +52,45 @@ class VideoSlotLogic extends BaseGetXController {
|
||||
// 获取明天时间的时间戳
|
||||
state.recordEndTime.value =
|
||||
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() {
|
||||
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();
|
||||
|
||||
// 将 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
|
||||
catEyeSetState.settingOptions.value = 5;
|
||||
catEyeSetState.catEyeConfig.value.catEyeMode = 3;
|
||||
catEyeSetState.catEyeConfig.value.recordMode = 0;
|
||||
catEyeSetState.catEyeConfig.value.recordStartTime =
|
||||
state.recordStartTime.value;
|
||||
catEyeSetState.catEyeConfig.value.recordEndTime =
|
||||
state.recordEndTime.value;
|
||||
catEyeSetLogic.sendBlueMessage();
|
||||
} 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;
|
||||
catEyeSetState.settingOptions.value = 5;
|
||||
catEyeSetState.catEyeConfig.value.catEyeMode = 3;
|
||||
catEyeSetState.catEyeConfig.value.recordMode = 1;
|
||||
catEyeSetState.catEyeConfig.value.recordStartTime = 0;
|
||||
catEyeSetState.catEyeConfig.value.recordEndTime = 0;
|
||||
catEyeSetLogic.sendBlueMessage();
|
||||
}
|
||||
}
|
||||
|
||||
int _handleDetectionDistance(String s) {
|
||||
if (s == '约0.8米') {
|
||||
return 0;
|
||||
@override
|
||||
void onInit() {
|
||||
// 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;
|
||||
}
|
||||
if (s == '约3.0米') {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
|
||||
// 计算小时和分钟
|
||||
int hours = minutes ~/ 60; // 整除 60 得到小时数
|
||||
int mins = minutes % 60; // 取模得到分钟数
|
||||
|
||||
// 格式化为 HH:mm 字符串
|
||||
return "${hours.toString().padLeft(2, '0')}:${mins.toString().padLeft(2, '0')}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,42 +25,44 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.mainBackgroundColor,
|
||||
appBar: TitleAppBar(
|
||||
barTitle: '录像时段'.tr,
|
||||
haveBack: true,
|
||||
backAction: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
backgroundColor: AppColors.mainColor,
|
||||
actionsList: <Widget>[
|
||||
TextButton(
|
||||
child: Text(
|
||||
'保存'.tr,
|
||||
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
||||
),
|
||||
onPressed: logic.updateCatEyeModeConfig,
|
||||
backgroundColor: AppColors.mainBackgroundColor,
|
||||
appBar: TitleAppBar(
|
||||
barTitle: '录像时段'.tr,
|
||||
haveBack: true,
|
||||
backAction: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
backgroundColor: AppColors.mainColor,
|
||||
actionsList: <Widget>[
|
||||
TextButton(
|
||||
child: Text(
|
||||
'保存'.tr,
|
||||
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
||||
),
|
||||
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),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (state.isCustom.value == false) Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
) else SizedBox(
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _buildRichText(titleStr, false),
|
||||
),
|
||||
padding:
|
||||
EdgeInsets.only(left: 20.w, top: 30.h, bottom: 30.h, right: 20.w),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
if (state.isCustom.value == false)
|
||||
Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
width: 10.w,
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
],
|
||||
)),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _buildRichText(titleStr, false),
|
||||
),
|
||||
SizedBox(
|
||||
width: 10.w,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
if (clickIndex == 0) {
|
||||
@ -127,17 +133,21 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
if (state.isCustom.value == true) Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
) else SizedBox(
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
if (state.isCustom.value == true)
|
||||
Image.asset(
|
||||
'images/mine/icon_mine_blueSelect.png',
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
width: 20.w,
|
||||
height: 14.w,
|
||||
),
|
||||
SizedBox(width: 10.w),
|
||||
Expanded(
|
||||
child: _buildRichText('自定义时间'.tr, state.isCustom.value),
|
||||
child:
|
||||
_buildRichText('自定义时间'.tr, state.isCustom.value),
|
||||
),
|
||||
SizedBox(
|
||||
width: 10.w,
|
||||
@ -145,22 +155,31 @@ class _VideoSlotPageState extends State<VideoSlotPage> {
|
||||
],
|
||||
),
|
||||
//如果选中了全天模式,就不显示下面的时间选择
|
||||
if (state.isCustom.value == false) Container() else Container(
|
||||
height: 1,
|
||||
margin: EdgeInsets.only(
|
||||
left: 20.w,
|
||||
right: 20.w,
|
||||
top: 20.h,
|
||||
bottom: 20.h),
|
||||
color: state.isCustom.value == true
|
||||
? AppColors.blueTextTipsColor
|
||||
: Colors.black,
|
||||
),
|
||||
if (state.isCustom.value == false) Container() else startAndEndTimeRow(false),
|
||||
if (state.isCustom.value == false) Container() else SizedBox(
|
||||
height: 30.h,
|
||||
),
|
||||
if (state.isCustom.value == false) Container() else startAndEndTimeRow(true),
|
||||
if (state.isCustom.value == false)
|
||||
Container()
|
||||
else
|
||||
Container(
|
||||
height: 1,
|
||||
margin: EdgeInsets.only(
|
||||
left: 20.w, right: 20.w, top: 20.h, bottom: 20.h),
|
||||
color: state.isCustom.value == true
|
||||
? AppColors.blueTextTipsColor
|
||||
: Colors.black,
|
||||
),
|
||||
if (state.isCustom.value == false)
|
||||
Container()
|
||||
else
|
||||
startAndEndTimeRow(false),
|
||||
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(
|
||||
isEndTime == false ? state.startDate.value : state.endDate.value));
|
||||
Pickers.showDatePicker(context,
|
||||
selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) {
|
||||
selectDate: selectDate,
|
||||
mode: DateMode.HM, onConfirm: (PDuration p) {
|
||||
if (isEndTime == false) {
|
||||
state.startDate.value = DateTool().getYMDHNDateString(p, 3);
|
||||
} else {
|
||||
|
||||
@ -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/io_protocol/io_setSupportFunctionsWithParameters.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/liveVideo/liveVideo_state.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 {
|
||||
final LiveVideoState state = LiveVideoState();
|
||||
|
||||
// 获取锁设置信息
|
||||
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];
|
||||
final CatEyeSetLogic catEyeSetLogic = Get.put(CatEyeSetLogic());
|
||||
final CatEyeSetState catEyeSetState = Get.find<CatEyeSetLogic>().state;
|
||||
|
||||
if (state.catEyeConfigData.value.catEyeModeConfig != null) {
|
||||
state.realTimeMode.value =
|
||||
state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode!;
|
||||
if (state.catEyeConfigData.value.catEyeModeConfig!.realTimeMode ==
|
||||
1) {
|
||||
state.isLiveView.value = true;
|
||||
} else {
|
||||
state.isLiveView.value = false;
|
||||
}
|
||||
_getConfigAndGenerateBleData();
|
||||
updateCatEyeSetConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
void updateCatEyeModeConfig() {
|
||||
catEyeSetState.settingOptions.value = 5;
|
||||
catEyeSetState.catEyeConfig.value.catEyeMode = 4;
|
||||
catEyeSetState.catEyeConfig.value.realTimeMode = state.realTimeMode.value;
|
||||
catEyeSetLogic.sendBlueMessage();
|
||||
}
|
||||
|
||||
//设置猫眼工作模式
|
||||
Future<void> updateCatEyeModeConfig() async {
|
||||
final VersionUndateEntity entity =
|
||||
await ApiRepository.to.updateCatEyeModeConfig(
|
||||
lockId: state.lockSetInfoData.value.lockId ?? 0,
|
||||
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;
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
state.isLiveView.value =
|
||||
catEyeSetState.catEyeConfig.value.realTimeMode == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ class _LiveVideoPageState extends State<LiveVideoPage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
logic.getLockSettingInfoData();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user