fix: 修复设置语音包后等待几秒后出现操作失败的问题
This commit is contained in:
parent
8fd1dac254
commit
cfde51c063
@ -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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user