develop_sky #3
@ -45,8 +45,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||||
if (reply is VoicePackageConfigureReply) {
|
||||
// 语言包配置开始
|
||||
_handlerStartVoicePackageConfigure(reply);
|
||||
@ -72,8 +71,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
|
||||
final model = state.lockSetInfoData.value.lockBasicInfo?.model;
|
||||
|
||||
final PassthroughListResponse entity =
|
||||
await ApiRepository.to.getPassthroughList(data: {
|
||||
final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
|
||||
'vendor': vendor!,
|
||||
'model': model!,
|
||||
});
|
||||
@ -110,18 +108,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
final passthroughItem = PassthroughItem(
|
||||
lang: element.lang,
|
||||
timbres: element.timbres,
|
||||
langText:
|
||||
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
|
||||
langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
|
||||
name: element.name,
|
||||
);
|
||||
state.languages.add(passthroughItem);
|
||||
}
|
||||
});
|
||||
state.languages.refresh();
|
||||
final lang = state
|
||||
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
|
||||
final timbre = state
|
||||
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
|
||||
final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
|
||||
final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
|
||||
// 传统 for 循环,直接通过索引访问
|
||||
for (int i = 0; i < state.languages.length; i++) {
|
||||
final language = state.languages[i]; // 当前元素
|
||||
@ -156,8 +151,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
// APP层的语言
|
||||
Locale? currentLocale = Get.locale; // 直接获取最新语言
|
||||
if (currentLocale != null) {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == currentLocale.toString());
|
||||
final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
}
|
||||
}
|
||||
@ -192,15 +186,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey =
|
||||
await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList =
|
||||
changeStringListToIntList(privateKey!);
|
||||
final List<String>? signKey =
|
||||
await Storage.getStringList(saveBlueSignKey);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
final String uid = await Storage.getUid() ?? '';
|
||||
final String md5Str = md5.convert(data).toString().toUpperCase();
|
||||
@ -219,8 +209,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
privateKey: getPrivateKeyList)
|
||||
.packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
}
|
||||
@ -233,16 +222,14 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
BlueManage().writeCharacteristicWithResponse(
|
||||
GetDeviceModelCommand(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
@ -251,8 +238,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 开始配置语音包
|
||||
void _handlerStartVoicePackageConfigure(
|
||||
VoicePackageConfigureReply reply) async {
|
||||
void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
|
||||
final int status = reply.data[6];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -280,8 +266,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
if (state.data == null) return;
|
||||
state.voiceSubcontractingIndex = 0;
|
||||
state.voiceSubcontractingCount =
|
||||
(state.data!.length + state.voiceSubcontractingSize - 1) ~/
|
||||
state.voiceSubcontractingSize;
|
||||
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
|
||||
state.progress.value = 0.0; // 开始前重置进度
|
||||
_sendNextPackage();
|
||||
}
|
||||
@ -332,8 +317,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
Uint8List packageData = state.data!.sublist(start, end);
|
||||
|
||||
// 更新分包进度
|
||||
state.progress.value =
|
||||
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
|
||||
state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
|
||||
EasyLoading.showProgress(state.progress.value,
|
||||
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
|
||||
await _sendLanguageFileBleMessage(
|
||||
@ -342,8 +326,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
);
|
||||
}
|
||||
|
||||
_sendLanguageFileBleMessage(
|
||||
{required int index, required Uint8List data}) async {
|
||||
_sendLanguageFileBleMessage({required int index, required Uint8List data}) async {
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
@ -354,17 +337,15 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
data: data,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
// showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _handlerVoicePackageConfigureProcess(
|
||||
VoicePackageConfigureProcessReply reply) {
|
||||
void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
|
||||
// 取消超时定时器(已收到回复,无需继续等待)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
_isTimeout = false; // 重置超时标志
|
||||
@ -431,8 +412,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _executeLogic(
|
||||
VoicePackageConfigureConfirmationReply reply) async {
|
||||
Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
|
||||
await _handlerVoicePackageConfigureConfirmation(reply);
|
||||
}
|
||||
|
||||
@ -440,9 +420,12 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
VoicePackageConfigureConfirmationReply reply,
|
||||
) async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
showBlueConnetctToastTimer(
|
||||
action: () {
|
||||
dismissEasyLoading();
|
||||
},
|
||||
isShowBlueConnetctToast: false,
|
||||
);
|
||||
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
|
||||
data: {
|
||||
'lang': state.tempLangStr.value,
|
||||
@ -452,10 +435,8 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showSuccess('设置成功'.tr, something: () async {
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
|
||||
state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.timbre = state.tempTimbreStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
|
||||
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
@ -466,11 +447,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
languageCode: state.tempLangStr.value,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
// showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
@ -491,8 +471,7 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
}
|
||||
}
|
||||
|
||||
void handleLockCurrentVoicePacketResult(
|
||||
ReadLockCurrentVoicePacketReply reply) {
|
||||
void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -501,25 +480,21 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
|
||||
const int languageCodeStartIndex = 3;
|
||||
const int languageCodeLength = 20;
|
||||
const int languageCodeEndIndex =
|
||||
languageCodeStartIndex + languageCodeLength; // 23
|
||||
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);
|
||||
List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
|
||||
|
||||
String languageCode = String.fromCharCodes(languageCodeBytes);
|
||||
|
||||
languageCode = languageCode.trim(); // 移除首尾空格
|
||||
languageCode =
|
||||
languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes)
|
||||
languageCode = languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes)
|
||||
|
||||
if (languageCode != null && languageCode != '') {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == languageCode);
|
||||
final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
|
||||
if (indexWhere != -1) {
|
||||
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
@ -541,9 +516,11 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
|
||||
void readLockLanguage() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
showBlueConnetctToastTimer(
|
||||
isShowBlueConnetctToast: false,
|
||||
action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
@ -552,11 +529,10 @@ class SpeechLanguageSettingsLogic extends BaseGetXController {
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
// showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -43,8 +43,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
|
||||
if (reply is VoicePackageConfigureReply) {
|
||||
// 语言包配置开始
|
||||
_handlerStartVoicePackageConfigure(reply);
|
||||
@ -78,12 +77,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _executeLogic(
|
||||
VoicePackageConfigureConfirmationReply reply) async {
|
||||
Future<void> _executeLogic(VoicePackageConfigureConfirmationReply reply) async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
showBlueConnetctToastTimer(
|
||||
action: () {
|
||||
dismissEasyLoading();
|
||||
},
|
||||
isShowBlueConnetctToast: false,
|
||||
);
|
||||
final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre(
|
||||
data: {
|
||||
'lang': state.tempLangStr.value,
|
||||
@ -93,10 +94,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showSuccess('设置成功'.tr, something: () async {
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang =
|
||||
state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre
|
||||
?.timbre = state.tempTimbreStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = state.tempLangStr.value;
|
||||
state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre = state.tempTimbreStr.value;
|
||||
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
@ -107,16 +106,14 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
languageCode: state.tempLangStr.value,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
// showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
eventBus
|
||||
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||||
Get.offAllNamed(Routers.starLockMain);
|
||||
});
|
||||
}
|
||||
@ -145,8 +142,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
// APP层的语言
|
||||
Locale? currentLocale = Get.locale; // 直接获取最新语言
|
||||
if (currentLocale != null) {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == currentLocale.toString());
|
||||
final indexWhere = state.languages.indexWhere((element) => element.lang == currentLocale.toString());
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
}
|
||||
}
|
||||
@ -176,15 +172,11 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
final List<String>? privateKey =
|
||||
await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList =
|
||||
changeStringListToIntList(privateKey!);
|
||||
final List<String>? signKey =
|
||||
await Storage.getStringList(saveBlueSignKey);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> signKeyDataList = changeStringListToIntList(signKey!);
|
||||
final String uid = await Storage.getUid() ?? '';
|
||||
final String md5Str = md5.convert(data).toString().toUpperCase();
|
||||
@ -203,8 +195,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
privateKey: getPrivateKeyList)
|
||||
.packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
|
||||
@ -216,8 +207,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
});
|
||||
}
|
||||
|
||||
void _handlerVoicePackageConfigureProcess(
|
||||
VoicePackageConfigureProcessReply reply) {
|
||||
void _handlerVoicePackageConfigureProcess(VoicePackageConfigureProcessReply reply) {
|
||||
// 取消超时定时器(已收到回复,无需继续等待)
|
||||
_sendTimeoutTimer?.cancel();
|
||||
_isTimeout = false; // 重置超时标志
|
||||
@ -235,8 +225,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 开始配置语音包
|
||||
void _handlerStartVoicePackageConfigure(
|
||||
VoicePackageConfigureReply reply) async {
|
||||
void _handlerStartVoicePackageConfigure(VoicePackageConfigureReply reply) async {
|
||||
final int status = reply.data[6];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -265,8 +254,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
final vendor = state.lockSetInfoData.value.lockBasicInfo?.vendor;
|
||||
final model = state.lockSetInfoData.value.lockBasicInfo?.model;
|
||||
|
||||
final PassthroughListResponse entity =
|
||||
await ApiRepository.to.getPassthroughList(data: {
|
||||
final PassthroughListResponse entity = await ApiRepository.to.getPassthroughList(data: {
|
||||
'vendor': vendor!,
|
||||
'model': model!,
|
||||
});
|
||||
@ -302,8 +290,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
final passthroughItem = PassthroughItem(
|
||||
lang: element.lang,
|
||||
timbres: element.timbres,
|
||||
langText:
|
||||
ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
|
||||
langText: ExtensionLanguageType.fromLocale(locales[indexOf]).lanTitle,
|
||||
name: element.name,
|
||||
);
|
||||
|
||||
@ -311,10 +298,8 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
}
|
||||
});
|
||||
state.languages.refresh();
|
||||
final lang = state
|
||||
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
|
||||
final timbre = state
|
||||
.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
|
||||
final lang = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang;
|
||||
final timbre = state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre;
|
||||
state.languages.value.forEach((element) {
|
||||
final timbres = element.timbres;
|
||||
timbres.forEach((item) {
|
||||
@ -335,8 +320,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
if (state.data == null) return;
|
||||
state.voiceSubcontractingIndex = 0;
|
||||
state.voiceSubcontractingCount =
|
||||
(state.data!.length + state.voiceSubcontractingSize - 1) ~/
|
||||
state.voiceSubcontractingSize;
|
||||
(state.data!.length + state.voiceSubcontractingSize - 1) ~/ state.voiceSubcontractingSize;
|
||||
state.progress.value = 0.0; // 开始前重置进度
|
||||
_sendNextPackage();
|
||||
}
|
||||
@ -380,8 +364,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
Uint8List packageData = state.data!.sublist(start, end);
|
||||
|
||||
// 更新分包进度
|
||||
state.progress.value =
|
||||
(state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
|
||||
state.progress.value = (state.voiceSubcontractingIndex + 1) / state.voiceSubcontractingCount;
|
||||
EasyLoading.showProgress(state.progress.value,
|
||||
status: '正在发送数据 ${(state.progress.value * 100).toStringAsFixed(0)}%');
|
||||
_sendLanguageFileBleMessage(
|
||||
@ -391,8 +374,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
_sendLanguageFileBleMessage({required int index, required Uint8List data}) {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
BlueManage().writeCharacteristicWithResponse(
|
||||
VoicePackageConfigureProcess(
|
||||
@ -401,8 +383,7 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
data: data,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
// showBlueConnetctToast();
|
||||
@ -445,9 +426,12 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
void readLockLanguage() async {
|
||||
showEasyLoading();
|
||||
showBlueConnetctToastTimer(action: () {
|
||||
dismissEasyLoading();
|
||||
});
|
||||
showBlueConnetctToastTimer(
|
||||
action: () {
|
||||
dismissEasyLoading();
|
||||
},
|
||||
isShowBlueConnetctToast: false,
|
||||
);
|
||||
await BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
@ -456,17 +440,15 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
).packageData(),
|
||||
);
|
||||
} else if (deviceConnectionState ==
|
||||
BluetoothConnectionState.disconnected) {
|
||||
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
dismissEasyLoading();
|
||||
cancelBlueConnetctToastTimer();
|
||||
showBlueConnetctToast();
|
||||
// showBlueConnetctToast();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void handleLockCurrentVoicePacketResult(
|
||||
ReadLockCurrentVoicePacketReply reply) {
|
||||
void handleLockCurrentVoicePacketResult(ReadLockCurrentVoicePacketReply reply) {
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
@ -475,28 +457,24 @@ class LockVoiceSettingLogic extends BaseGetXController {
|
||||
|
||||
const int languageCodeStartIndex = 3;
|
||||
const int languageCodeLength = 20;
|
||||
const int languageCodeEndIndex =
|
||||
languageCodeStartIndex + languageCodeLength; // 23
|
||||
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);
|
||||
List<int> languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex);
|
||||
|
||||
String languageCode = String.fromCharCodes(languageCodeBytes);
|
||||
|
||||
languageCode = languageCode.trim(); // 移除首尾空格
|
||||
languageCode =
|
||||
languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes)
|
||||
languageCode = languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes)
|
||||
|
||||
print('LanguageCode: $languageCode'); // 例如: zh_CN, en_US
|
||||
|
||||
if (languageCode != null && languageCode != '') {
|
||||
final indexWhere = state.languages
|
||||
.indexWhere((element) => element.lang == languageCode);
|
||||
final indexWhere = state.languages.indexWhere((element) => element.lang == languageCode);
|
||||
if (indexWhere != -1) {
|
||||
print('锁板上的语言是:$languageCode,下标是:$indexWhere');
|
||||
state.selectPassthroughListIndex.value = indexWhere;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user