diff --git a/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart b/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart index 2d02acd1c..5692515e2 100644 --- a/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart +++ b/lib/modules/ota_upgrade/controllers/ota_core_contropller.dart @@ -53,6 +53,123 @@ class OtaCoreService { // ==================== 设备检查功能 ==================== + /// 检查BLE设备连接状态 + /// 返回true表示设备已连接,可以进行升级 + /// 返回false表示设备未连接,不能进行升级 + bool checkBleConnectionStatus() { + try { + // 检查BLE管理器的连接状态 + if (!_bleManager.isConnected) { + //_showBleDisconnectedDialog(); + return false; + } + + // 检查设备信息是否可用 + final deviceInfo = _bleManager.deviceInfo.value; + if (deviceInfo == null) { + _showDeviceInfoUnavailableDialog(); + return false; + } + + return true; + } catch (e) { + _showBleCheckFailedSnackbar('检查BLE连接状态时发生错误:$e'); + return false; + } + } + + /// 显示BLE设备未连接对话框 + void _showBleDisconnectedDialog() { + Get.dialog( + AlertDialog( + title: Text( + 'BLE设备未连接', + style: TextStyle( + color: Colors.red[700], + fontWeight: FontWeight.w600, + ), + ), + content: Text( + '固件升级需要连接BLE设备\n请确保设备已正确连接后再试', + style: TextStyle( + color: Colors.red[600], + ), + ), + actions: [ + TextButton( + onPressed: () => Get.back(), + style: TextButton.styleFrom( + foregroundColor: Colors.red[700], + ), + child: const Text('确定'), + ), + ], + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + side: BorderSide( + color: Colors.red.withValues(alpha: 0.3), + width: 1, + ), + ), + backgroundColor: Colors.red[50], + ), + ); + } + + /// 显示设备信息不可用对话框 + void _showDeviceInfoUnavailableDialog() { + Get.dialog( + AlertDialog( + title: Text( + '设备信息不可用', + style: TextStyle( + color: Colors.orange[700], + fontWeight: FontWeight.w600, + ), + ), + content: Text( + '无法获取设备信息\n请重新连接设备或稍后再试', + style: TextStyle( + color: Colors.orange[600], + ), + ), + actions: [ + TextButton( + onPressed: () => Get.back(), + style: TextButton.styleFrom( + foregroundColor: Colors.orange[700], + ), + child: const Text('确定'), + ), + ], + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + side: BorderSide( + color: Colors.orange.withValues(alpha: 0.3), + width: 1, + ), + ), + backgroundColor: Colors.orange[50], + ), + ); + } + + /// 显示BLE连接检查失败提示 + /// [message] 错误信息 + void _showBleCheckFailedSnackbar(String message) { + Get.snackbar( + 'BLE连接检查失败', + message, + snackPosition: SnackPosition.BOTTOM, + backgroundColor: Colors.red[600], + colorText: Colors.white, + icon: const Icon( + Icons.bluetooth_disabled, + color: Colors.white, + ), + ); + } + /// 检查设备电量是否满足升级条件 /// 返回true表示电量充足,可以进行升级 /// 返回false表示电量不足,不能进行升级 diff --git a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart index 50d9385b4..9e56c02d8 100644 --- a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart +++ b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart @@ -27,11 +27,12 @@ class OtaUpgradeController extends GetxController { final RxDouble downloadProgress = 0.0.obs; final RxDouble progress = 0.0.obs; final RxInt type = OtaCoreService.NOT_STARTED.obs; - final RxBool isUpdateAvailable = true.obs; + final RxBool isUpdateAvailable = false.obs; final RxBool isDownloading = false.obs; final RxBool isUpgrade = false.obs; - final RxBool isFetchingDeviceInfo = true.obs; + final RxBool isFetchingDeviceInfo = false.obs; final RxBool showDetailedStatus = false.obs; + final RxBool isBleConnected = true.obs; String _address = ''; String _updatePackageAddress = ''; @@ -53,6 +54,14 @@ class OtaUpgradeController extends GetxController { /// 初始化控制器 /// 设置事件监听并加载版本信息 Future _initializeController() async { + // 首先检查BLE设备连接状态 + if (!_coreService.checkBleConnectionStatus()) { + //isFetchingDeviceInfo.value = false; + //errorMessage.value = 'unconnected'.tr; + isBleConnected.value = false; + + return; + } _listenToOtaEvents(); await _loadVersionInfo(); } diff --git a/lib/modules/ota_upgrade/views/ota_upgrade_view.dart b/lib/modules/ota_upgrade/views/ota_upgrade_view.dart index 922964c9d..e9011531a 100644 --- a/lib/modules/ota_upgrade/views/ota_upgrade_view.dart +++ b/lib/modules/ota_upgrade/views/ota_upgrade_view.dart @@ -397,7 +397,8 @@ class OtaUpgradeView extends GetView { ), // 版本状态指示器 SizedBox(height: 14.h), - _buildVersionStatusIndicator(isDarkMode), + if (controller.isBleConnected.value) + _buildVersionStatusIndicator(isDarkMode), ], ); } @@ -836,7 +837,9 @@ class OtaUpgradeView extends GetView { label: Text( controller.isUpdateAvailable.value ? 'ota_updateNow'.tr - : 'latestVersion'.tr, // 立即更新 : 已是最新版本 + : controller.isBleConnected.value + ? 'latestVersion'.tr // 立即更新 : 已是最新版本 + : 'unconnected'.tr, style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.w600, diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/SimpleAudioReceiver.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/SimpleAudioReceiver.kt index f2e39abcb..0db39b71a 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/SimpleAudioReceiver.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/tools/SimpleAudioReceiver.kt @@ -236,7 +236,7 @@ class SimpleAudioReceiver(private val context: Context) { private fun runMicrophoneCapture() { try { // 首先设置通话音频模式 - setupCommunicationAudioMode() + //setupCommunicationAudioMode() val supportedSampleRates = intArrayOf(16000, 8000, 11025, 22050, 44100) val sampleRate = supportedSampleRates.firstOrNull { rate -> val bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat)