Merge branch 'develop_sky_liyi' into 'develop_sky'
fix:增加和读取锁板上的语音包设置 See merge request StarlockTeam/app-starlock!268
This commit is contained in:
commit
2347ba871f
@ -48,7 +48,7 @@ class ReadLockCurrentVoicePacketReply extends Reply {
|
||||
CommandType commandType, List<int> dataDetail)
|
||||
: super.parseData(commandType, dataDetail) {
|
||||
data = dataDetail;
|
||||
status = data[6];
|
||||
status = data[2];
|
||||
errorWithStstus(status);
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ class SetVoicePackageFinalResultReply extends Reply {
|
||||
CommandType commandType, List<int> dataDetail)
|
||||
: super.parseData(commandType, dataDetail) {
|
||||
data = dataDetail;
|
||||
status = data[6];
|
||||
status = data[2];
|
||||
errorWithStstus(status);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,9 +18,11 @@ import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readAdminPassword.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readSupportFunctionsNoParameters.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readSupportFunctionsWithParameters.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_referEventRecordTime.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsNoParameters.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setSupportFunctionsWithParameters.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_timing.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigure.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigureProcess.dart';
|
||||
@ -317,6 +319,18 @@ class CommandReciverManager {
|
||||
commandType, data);
|
||||
}
|
||||
break;
|
||||
case CommandType.readLockCurrentVoicePacket:
|
||||
{
|
||||
reply =
|
||||
ReadLockCurrentVoicePacketReply.parseData(commandType, data);
|
||||
}
|
||||
break;
|
||||
case CommandType.setLockCurrentVoicePacket:
|
||||
{
|
||||
reply =
|
||||
SetVoicePackageFinalResultReply.parseData(commandType, data);
|
||||
}
|
||||
break;
|
||||
case CommandType.generalExtendedCommond:
|
||||
{
|
||||
// 子命令类型
|
||||
|
||||
@ -12,6 +12,7 @@ import 'package:star_lock/blue/blue_manage.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_getDeviceModel.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigure.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigureProcess.dart';
|
||||
@ -55,9 +56,12 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
handleVoiceConfigureThrottled(reply);
|
||||
} else if (reply is SetVoicePackageFinalResultReply) {
|
||||
handleSetResult(reply);
|
||||
} else if (reply is ReadLockCurrentVoicePacketReply) {
|
||||
handleLockCurrentVoicePacketResult(reply);
|
||||
}
|
||||
});
|
||||
await initList();
|
||||
readLockLanguage();
|
||||
}
|
||||
|
||||
/// 获取列表
|
||||
@ -438,42 +442,22 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
// await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
// (BluetoothConnectionState deviceConnectionState) async {
|
||||
// if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
// await BlueManage().writeCharacteristicWithResponse(
|
||||
// SetVoicePackageFinalResult(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// languageCode: state.tempLangStr.value,
|
||||
// ).packageData(),
|
||||
// );
|
||||
// } else if (deviceConnectionState ==
|
||||
// BluetoothConnectionState.disconnected) {
|
||||
// dismissEasyLoading();
|
||||
// cancelBlueConnetctToastTimer();
|
||||
// showBlueConnetctToast();
|
||||
// }
|
||||
// });
|
||||
cancelBlueConnetctToastTimer();
|
||||
final LoginEntity entity =
|
||||
await ApiRepository.to.settingCurrentVoiceTimbre(
|
||||
data: {
|
||||
'lang': state.tempLangStr.value,
|
||||
'timbre': state.tempTimbreStr.value,
|
||||
},
|
||||
lockId: state.lockSetInfoData.value.lockId!,
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
await BlueManage().writeCharacteristicWithResponse(
|
||||
SetVoicePackageFinalResult(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
languageCode: state.tempLangStr.value,
|
||||
).packageData(),
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showSuccess('设置成功'.tr, something: () {
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.lang = state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.timbre = state.tempTimbreStr.value;
|
||||
eventBus.fire(
|
||||
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
});
|
||||
}
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
showToast('设置'.tr + '失败'.tr);
|
||||
@ -511,4 +495,75 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void handleLockCurrentVoicePacketResult(
|
||||
ReadLockCurrentVoicePacketReply reply) {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
cancelBlueConnetctToastTimer();
|
||||
|
||||
const int languageCodeStartIndex = 3;
|
||||
const int languageCodeLength = 20;
|
||||
const int languageCodeEndIndex =
|
||||
languageCodeStartIndex + languageCodeLength; // 23
|
||||
|
||||
if (reply.data.length < languageCodeEndIndex) {
|
||||
throw Exception(
|
||||
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
|
||||
}
|
||||
List<int> languageCodeBytes =
|
||||
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
|
||||
|
||||
String languageCode = String.fromCharCodes(languageCodeBytes);
|
||||
|
||||
languageCode = languageCode.trim(); // 移除首尾空格
|
||||
languageCode =
|
||||
languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes)
|
||||
|
||||
|
||||
if (languageCode != null && languageCode != '') {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == languageCode);
|
||||
if (indexWhere != -1) {
|
||||
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
}
|
||||
}
|
||||
dismissEasyLoading();
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
final List<int> token = reply.data.sublist(2, 6);
|
||||
if (state.data != null) {
|
||||
sendFileToDevice(state.data!, token);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void readLockLanguage() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
await BlueManage().writeCharacteristicWithResponse(
|
||||
ReadLockCurrentVoicePacket(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,12 @@ class _SpeechLanguageSettingsPageState
|
||||
final soundType = state.soundTypeList.value[index];
|
||||
return CommonItem(
|
||||
leftTitel: soundType,
|
||||
leftTitleStyle: TextStyle(
|
||||
fontSize: 22.sp,
|
||||
fontWeight: state.selectSoundTypeIndex.value == index
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
),
|
||||
rightTitle: '',
|
||||
isHaveLine: !isLastItem,
|
||||
isHaveDirection: false,
|
||||
@ -94,7 +100,8 @@ class _SpeechLanguageSettingsPageState
|
||||
height: 8.h,
|
||||
),
|
||||
// 语言包列表区
|
||||
Container(
|
||||
Obx(
|
||||
() => Container(
|
||||
color: Colors.transparent,
|
||||
child: Column(
|
||||
children: List.generate(
|
||||
@ -103,11 +110,18 @@ class _SpeechLanguageSettingsPageState
|
||||
final item = state.languages[index];
|
||||
return CommonItem(
|
||||
leftTitel: item.langText,
|
||||
leftTitleStyle: TextStyle(
|
||||
fontSize: 22.sp,
|
||||
fontWeight: state.selectPassthroughListIndex.value == index
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
),
|
||||
rightTitle: '',
|
||||
isHaveLine: true,
|
||||
isHaveDirection: false,
|
||||
isHaveRightWidget: true,
|
||||
leftTitleMaxWidth: 0.9.sw, // 设置左侧标题最大宽度
|
||||
leftTitleMaxWidth: 0.9.sw,
|
||||
// 设置左侧标题最大宽度
|
||||
rightWidget:
|
||||
state.selectPassthroughListIndex.value == index
|
||||
? Image(
|
||||
@ -126,6 +140,7 @@ class _SpeechLanguageSettingsPageState
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -133,16 +148,6 @@ class _SpeechLanguageSettingsPageState
|
||||
}
|
||||
|
||||
|
||||
List<Widget> _buildList() {
|
||||
final appLocalLanguages = state.languages;
|
||||
return List.generate(
|
||||
appLocalLanguages.length,
|
||||
(index) => _buildItem(
|
||||
appLocalLanguages[index],
|
||||
index,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@ -152,24 +157,4 @@ class _SpeechLanguageSettingsPageState
|
||||
}
|
||||
}
|
||||
|
||||
_buildItem(PassthroughItem item, index) {
|
||||
return CommonItem(
|
||||
leftTitel: item.langText,
|
||||
rightTitle: '',
|
||||
isHaveLine: true,
|
||||
isHaveDirection: false,
|
||||
isHaveRightWidget: true,
|
||||
rightWidget: state.selectPassthroughListIndex.value == index
|
||||
? Image(
|
||||
image: const AssetImage('images/icon_item_checked.png'),
|
||||
width: 30.w,
|
||||
height: 30.w,
|
||||
fit: BoxFit.contain,
|
||||
)
|
||||
: Container(),
|
||||
action: () {
|
||||
state.selectPassthroughListIndex.value = index;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import 'package:star_lock/app_settings/app_colors.dart';
|
||||
import 'package:star_lock/blue/blue_manage.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_getDeviceModel.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_readVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_setVoicePackageFinalResult.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigure.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_voicePackageConfigureProcess.dart';
|
||||
import 'package:star_lock/blue/io_reply.dart';
|
||||
@ -53,6 +54,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
handleVoiceConfigureThrottled(reply);
|
||||
} else if (reply is ReadLockCurrentVoicePacketReply) {
|
||||
handleLockCurrentVoicePacketResult(reply);
|
||||
} else if (reply is SetVoicePackageFinalResultReply) {
|
||||
handleSetResult(reply);
|
||||
}
|
||||
});
|
||||
initList();
|
||||
@ -77,7 +80,35 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
Future<void> _executeLogic(
|
||||
VoicePackageConfigureConfirmationReply reply) async {
|
||||
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
await BlueManage().writeCharacteristicWithResponse(
|
||||
SetVoicePackageFinalResult(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
languageCode: state.tempLangStr.value,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleSetResult(SetVoicePackageFinalResultReply reply) async {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
cancelBlueConnetctToastTimer();
|
||||
final LoginEntity entity =
|
||||
await ApiRepository.to.settingCurrentVoiceTimbre(
|
||||
data: {
|
||||
'lang': state.tempLangStr.value,
|
||||
'timbre': state.tempTimbreStr.value,
|
||||
@ -86,17 +117,22 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showSuccess('设置成功'.tr, something: () {
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
|
||||
state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.lang = state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.timbre = state.tempTimbreStr.value;
|
||||
|
||||
eventBus
|
||||
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
eventBus.fire(
|
||||
PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
Get.offAllNamed(Routers.starLockMain);
|
||||
});
|
||||
}
|
||||
dismissEasyLoading();
|
||||
break;
|
||||
default:
|
||||
showToast('设置'.tr + '失败'.tr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void saveSpeechLanguageSettings() async {
|
||||
@ -201,14 +237,12 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
// 开始配置语音包
|
||||
void _handlerStartVoicePackageConfigure(
|
||||
VoicePackageConfigureReply reply) async {
|
||||
final int status = reply.data[3];
|
||||
final int status = reply.data[6];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
cancelBlueConnetctToastTimer();
|
||||
|
||||
_startSendLanguageFile();
|
||||
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
@ -218,7 +252,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
showToast('获取设备型号失败'.tr);
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -409,6 +444,10 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
void readLockLanguage() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
@ -428,7 +467,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
void handleLockCurrentVoicePacketResult(
|
||||
ReadLockCurrentVoicePacketReply reply) {
|
||||
final int status = reply.data[6];
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
@ -462,6 +501,16 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
// 6. 使用提取到的 languageCode
|
||||
print('LanguageCode: $languageCode'); // 例如: zh_CN, en_US
|
||||
|
||||
if (languageCode != null && languageCode != '') {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == languageCode);
|
||||
if (indexWhere != -1) {
|
||||
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
}
|
||||
}
|
||||
dismissEasyLoading();
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user