fix: 修复设置语音包后等待几秒后出现操作失败的问题

This commit is contained in:
liyi 2025-09-19 10:20:23 +08:00
parent 8fd1dac254
commit cfde51c063
2 changed files with 85 additions and 131 deletions

View File

@ -45,8 +45,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
@override @override
void onInit() async { void onInit() async {
super.onInit(); super.onInit();
_replySubscription = _replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is VoicePackageConfigureReply) { if (reply is VoicePackageConfigureReply) {
// //
_handlerStartVoicePackageConfigure(reply); _handlerStartVoicePackageConfigure(reply);
@ -72,8 +71,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor; final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
final model = state.lockSetInfoData.value.lockBasicInfo?.model; final model = state.lockSetInfoData.value.lockBasicInfo?.model;
final PassthroughListResponse entity = final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
await ApiRepository.to.getPassthroughList(data: {
'vendor': vendor!, 'vendor': vendor!,
'model': model!, 'model': model!,
}); });
@ -110,18 +108,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
final passthroughItem = PassthroughItem( final passthroughItem = PassthroughItem(
lang: element.lang, lang: element.lang,
timbres: element.timbres, timbres: element.timbres,
langText: langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
name: element.name, name: element.name,
); );
state.languages.add(passthroughItem); state.languages.add(passthroughItem);
} }
}); });
state.languages.refresh(); state.languages.refresh();
final lang = state final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang; final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
final timbre = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
// for 访 // for 访
for (int i = 0; i < state.languages.length; i++) { for (int i = 0; i < state.languages.length; i++) {
final language = state.languages[i]; // final language = state.languages[i]; //
@ -156,8 +151,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
// APP层的语言 // APP层的语言
Locale? currentLocale = Get.locale; // Locale? currentLocale = Get.locale; //
if (currentLocale != null) { if (currentLocale != null) {
final indexWhere = state.languages final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
.indexWhere((element) => element.lang == currentLocale.toString());
state.selectPassthroughListIndex.value = indexWhere; state.selectPassthroughListIndex.value = indexWhere;
} }
} }
@ -192,15 +186,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
final List<String>? privateKey = final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
await Storage.getStringList(saveBluePrivateKey); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<int> getPrivateKeyList = final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
changeStringListToIntList(privateKey!);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!); final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final String uid = await Storage.getUid() ?? ''; final String uid = await Storage.getUid() ?? '';
final String md5Str = md5.convert(data).toString().toUpperCase(); final String md5Str = md5.convert(data).toString().toUpperCase();
@ -219,8 +209,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
privateKey: getPrivateKeyList) privateKey: getPrivateKeyList)
.packageData(), .packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
} }
@ -233,16 +222,14 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
BlueManage().writeCharacteristicWithResponse( BlueManage().writeCharacteristicWithResponse(
GetDeviceModelCommand( GetDeviceModelCommand(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); showBlueConnetctToast();
@ -251,8 +238,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
} }
// //
void _handlerStartVoicePackageConfigure( void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
VoicePackageConfigureReply reply) async {
final int status = reply.data[6]; final int status = reply.data[6];
switch (status) { switch (status) {
case 0x00: case 0x00:
@ -280,8 +266,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
if (state.data == null) return; if (state.data == null) return;
state.voiceSubcontractingIndex = 0; state.voiceSubcontractingIndex = 0;
state.voiceSubcontractingCount = state.voiceSubcontractingCount =
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ (state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
state.voiceSubcontractingSize;
state.progress.value = 0.0; // state.progress.value = 0.0; //
_sendNextPackage(); _sendNextPackage();
} }
@ -332,8 +317,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
Uint8List packageData = state.data!.sublist(start, end); Uint8List packageData = state.data!.sublist(start, end);
// //
state.progress.value = state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
EasyLoading.showProgress(state.progress.value, EasyLoading.showProgress(state.progress.value,
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%'); status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
await _sendLanguageFileBleMessage( await _sendLanguageFileBleMessage(
@ -342,8 +326,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
); );
} }
_sendLanguageFileBleMessage( _sendLanguageFileBleMessage({required int index, required Uint8List data}) async {
{required int index, required Uint8List data}) async {
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -354,17 +337,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
data: data, data: data,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); // showBlueConnetctToast();
} }
}); });
} }
void _handlerVoicePackageConfigureProcess( void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
VoicePackageConfigureProcessReply reply) {
// //
_sendTimeoutTimer?.cancel(); _sendTimeoutTimer?.cancel();
_isTimeout = false; // _isTimeout = false; //
@ -431,8 +412,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
}); });
} }
Future<void> _executeLogic( Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
VoicePackageConfigureConfirmationReply reply) async {
await _handlerVoicePackageConfigureConfirmation(reply); await _handlerVoicePackageConfigureConfirmation(reply);
} }
@ -440,9 +420,12 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
VoicePackageConfigureConfirmationReply reply, VoicePackageConfigureConfirmationReply reply,
) async { ) async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(
dismissEasyLoading(); action: () {
}); dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre( final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
data: { data: {
'lang': state.tempLangStr.value, 'lang': state.tempLangStr.value,
@ -452,10 +435,8 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () async { showSuccess('设置成功'.tr, something: () async {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
state.tempLangStr.value; state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
@ -466,11 +447,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
languageCode: state.tempLangStr.value, languageCode: state.tempLangStr.value,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); // showBlueConnetctToast();
} }
}); });
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
@ -491,8 +471,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
} }
} }
void handleLockCurrentVoicePacketResult( void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
ReadLockCurrentVoicePacketReply reply) {
final int status = reply.data[2]; final int status = reply.data[2];
switch (status) { switch (status) {
case 0x00: case 0x00:
@ -501,25 +480,21 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
const int languageCodeStartIndex = 3; const int languageCodeStartIndex = 3;
const int languageCodeLength = 20; const int languageCodeLength = 20;
const int languageCodeEndIndex = const int languageCodeEndIndex = languageCodeStartIndex + languageCodeLength; // 23
languageCodeStartIndex + languageCodeLength; // 23
if (reply.data.length < languageCodeEndIndex) { if (reply.data.length < languageCodeEndIndex) {
throw Exception( throw Exception(
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}'); 'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
} }
List<int> languageCodeBytes = List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
String languageCode = String.fromCharCodes(languageCodeBytes); String languageCode = String.fromCharCodes(languageCodeBytes);
languageCode = languageCode.trim(); // languageCode = languageCode.trim(); //
languageCode = languageCode = languageCode.replaceAll('\u0000', ''); // (null bytes)
languageCode.replaceAll('\u0000', ''); // (null bytes)
if (languageCode != null && languageCode != '') { if (languageCode != null && languageCode != '') {
final indexWhere = state.languages final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
.indexWhere((element) => element.lang == languageCode);
if (indexWhere != -1) { if (indexWhere != -1) {
print('锁板上的语言是:$languageCode,下标是:$indexWhere'); print('锁板上的语言是:$languageCode,下标是:$indexWhere');
state.selectPassthroughListIndex.value = indexWhere; state.selectPassthroughListIndex.value = indexWhere;
@ -541,9 +516,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
void readLockLanguage() async { void readLockLanguage() async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(
dismissEasyLoading(); isShowBlueConnetctToast: false,
}); action: () {
dismissEasyLoading();
});
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -552,11 +529,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); // showBlueConnetctToast();
} }
}); });
} }

View File

@ -43,8 +43,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
@override @override
void onInit() async { void onInit() async {
super.onInit(); super.onInit();
_replySubscription = _replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
if (reply is VoicePackageConfigureReply) { if (reply is VoicePackageConfigureReply) {
// //
_handlerStartVoicePackageConfigure(reply); _handlerStartVoicePackageConfigure(reply);
@ -78,12 +77,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
}); });
} }
Future<void> _executeLogic( Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
VoicePackageConfigureConfirmationReply reply) async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(
dismissEasyLoading(); action: () {
}); dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre( final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
data: { data: {
'lang': state.tempLangStr.value, 'lang': state.tempLangStr.value,
@ -93,10 +94,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
); );
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showSuccess('设置成功'.tr, something: () async { showSuccess('设置成功'.tr, something: () async {
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
state.tempLangStr.value; state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
?.timbre = state.tempTimbreStr.value;
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
@ -107,16 +106,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
languageCode: state.tempLangStr.value, languageCode: state.tempLangStr.value,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); // showBlueConnetctToast();
} }
}); });
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
eventBus eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
Get.offAllNamed(Routers.starLockMain); Get.offAllNamed(Routers.starLockMain);
}); });
} }
@ -145,8 +142,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
// APP层的语言 // APP层的语言
Locale? currentLocale = Get.locale; // Locale? currentLocale = Get.locale; //
if (currentLocale != null) { if (currentLocale != null) {
final indexWhere = state.languages final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
.indexWhere((element) => element.lang == currentLocale.toString());
state.selectPassthroughListIndex.value = indexWhere; state.selectPassthroughListIndex.value = indexWhere;
} }
} }
@ -176,15 +172,11 @@ class LockVoiceSettingLogic extends BaseGetXController {
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
dismissEasyLoading(); dismissEasyLoading();
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
final List<String>? privateKey = final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
await Storage.getStringList(saveBluePrivateKey); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
final List<int> getPrivateKeyList = final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
changeStringListToIntList(privateKey!);
final List<String>? signKey =
await Storage.getStringList(saveBlueSignKey);
final List<int> signKeyDataList = changeStringListToIntList(signKey!); final List<int> signKeyDataList = changeStringListToIntList(signKey!);
final String uid = await Storage.getUid() ?? ''; final String uid = await Storage.getUid() ?? '';
final String md5Str = md5.convert(data).toString().toUpperCase(); final String md5Str = md5.convert(data).toString().toUpperCase();
@ -203,8 +195,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
privateKey: getPrivateKeyList) privateKey: getPrivateKeyList)
.packageData(), .packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
@ -216,8 +207,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
}); });
} }
void _handlerVoicePackageConfigureProcess( void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
VoicePackageConfigureProcessReply reply) {
// //
_sendTimeoutTimer?.cancel(); _sendTimeoutTimer?.cancel();
_isTimeout = false; // _isTimeout = false; //
@ -235,8 +225,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
} }
// //
void _handlerStartVoicePackageConfigure( void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
VoicePackageConfigureReply reply) async {
final int status = reply.data[6]; final int status = reply.data[6];
switch (status) { switch (status) {
case 0x00: case 0x00:
@ -265,8 +254,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor; final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
final model = state.lockSetInfoData.value.lockBasicInfo?.model; final model = state.lockSetInfoData.value.lockBasicInfo?.model;
final PassthroughListResponse entity = final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
await ApiRepository.to.getPassthroughList(data: {
'vendor': vendor!, 'vendor': vendor!,
'model': model!, 'model': model!,
}); });
@ -302,8 +290,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
final passthroughItem = PassthroughItem( final passthroughItem = PassthroughItem(
lang: element.lang, lang: element.lang,
timbres: element.timbres, timbres: element.timbres,
langText: langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
name: element.name, name: element.name,
); );
@ -311,10 +298,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
} }
}); });
state.languages.refresh(); state.languages.refresh();
final lang = state final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang; final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
final timbre = state
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
state.languages.value.forEach((element) { state.languages.value.forEach((element) {
final timbres = element.timbres; final timbres = element.timbres;
timbres.forEach((item) { timbres.forEach((item) {
@ -335,8 +320,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
if (state.data == null) return; if (state.data == null) return;
state.voiceSubcontractingIndex = 0; state.voiceSubcontractingIndex = 0;
state.voiceSubcontractingCount = state.voiceSubcontractingCount =
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ (state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
state.voiceSubcontractingSize;
state.progress.value = 0.0; // state.progress.value = 0.0; //
_sendNextPackage(); _sendNextPackage();
} }
@ -380,8 +364,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
Uint8List packageData = state.data!.sublist(start, end); Uint8List packageData = state.data!.sublist(start, end);
// //
state.progress.value = state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
EasyLoading.showProgress(state.progress.value, EasyLoading.showProgress(state.progress.value,
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%'); status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
_sendLanguageFileBleMessage( _sendLanguageFileBleMessage(
@ -391,8 +374,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
} }
_sendLanguageFileBleMessage({required int index, required Uint8List data}) { _sendLanguageFileBleMessage({required int index, required Uint8List data}) {
BlueManage().blueSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
(BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
BlueManage().writeCharacteristicWithResponse( BlueManage().writeCharacteristicWithResponse(
VoicePackageConfigureProcess( VoicePackageConfigureProcess(
@ -401,8 +383,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
data: data, data: data,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
// showBlueConnetctToast(); // showBlueConnetctToast();
@ -445,9 +426,12 @@ class LockVoiceSettingLogic extends BaseGetXController {
void readLockLanguage() async { void readLockLanguage() async {
showEasyLoading(); showEasyLoading();
showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(
dismissEasyLoading(); action: () {
}); dismissEasyLoading();
},
isShowBlueConnetctToast: false,
);
await BlueManage().blueSendData(BlueManage().connectDeviceName, await BlueManage().blueSendData(BlueManage().connectDeviceName,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
@ -456,17 +440,15 @@ class LockVoiceSettingLogic extends BaseGetXController {
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
).packageData(), ).packageData(),
); );
} else if (deviceConnectionState == } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
BluetoothConnectionState.disconnected) {
dismissEasyLoading(); dismissEasyLoading();
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
showBlueConnetctToast(); // showBlueConnetctToast();
} }
}); });
} }
void handleLockCurrentVoicePacketResult( void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
ReadLockCurrentVoicePacketReply reply) {
final int status = reply.data[2]; final int status = reply.data[2];
switch (status) { switch (status) {
case 0x00: case 0x00:
@ -475,28 +457,24 @@ class LockVoiceSettingLogic extends BaseGetXController {
const int languageCodeStartIndex = 3; const int languageCodeStartIndex = 3;
const int languageCodeLength = 20; const int languageCodeLength = 20;
const int languageCodeEndIndex = const int languageCodeEndIndex = languageCodeStartIndex + languageCodeLength; // 23
languageCodeStartIndex + languageCodeLength; // 23
if (reply.data.length < languageCodeEndIndex) { if (reply.data.length < languageCodeEndIndex) {
throw Exception( throw Exception(
'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}'); 'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}');
} }
List<int> languageCodeBytes = List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
String languageCode = String.fromCharCodes(languageCodeBytes); String languageCode = String.fromCharCodes(languageCodeBytes);
languageCode = languageCode.trim(); // languageCode = languageCode.trim(); //
languageCode = languageCode = languageCode.replaceAll('\u0000', ''); // (null bytes)
languageCode.replaceAll('\u0000', ''); // (null bytes)
print('LanguageCode: $languageCode'); // : zh_CN, en_US print('LanguageCode: $languageCode'); // : zh_CN, en_US
if (languageCode != null && languageCode != '') { if (languageCode != null && languageCode != '') {
final indexWhere = state.languages final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
.indexWhere((element) => element.lang == languageCode);
if (indexWhere != -1) { if (indexWhere != -1) {
print('锁板上的语言是:$languageCode,下标是:$indexWhere'); print('锁板上的语言是:$languageCode,下标是:$indexWhere');
state.selectPassthroughListIndex.value = indexWhere; state.selectPassthroughListIndex.value = indexWhere;