|
|
@ -1,4 +1,3 @@ |
|
|
import 'package:ble_service/ble_service.dart'; |
|
|
|
|
|
import 'package:classic_bluetooth/classic_bluetooth.dart'; |
|
|
import 'package:classic_bluetooth/classic_bluetooth.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
@ -54,7 +53,6 @@ class OtaUpgradeController extends GetxController { |
|
|
|
|
|
|
|
|
// 蓝牙管理服务,用于获取设备信息和通信 |
|
|
// 蓝牙管理服务,用于获取设备信息和通信 |
|
|
final _bleManager = Get.find<BleManager>(); |
|
|
final _bleManager = Get.find<BleManager>(); |
|
|
final BleService _bleService = BleService(); |
|
|
|
|
|
final maxRetryAttempts = 3; // 最大重试次数 |
|
|
final maxRetryAttempts = 3; // 最大重试次数 |
|
|
int currentRetryCount = 0; |
|
|
int currentRetryCount = 0; |
|
|
|
|
|
|
|
|
@ -73,7 +71,7 @@ class OtaUpgradeController extends GetxController { |
|
|
@override |
|
|
@override |
|
|
void onClose() { |
|
|
void onClose() { |
|
|
jlota.onOtaClose(); |
|
|
jlota.onOtaClose(); |
|
|
_bleService.setEnterOta(false); |
|
|
_bleManager.setEnterOta(false); |
|
|
isUpgrade.value = false; |
|
|
isUpgrade.value = false; |
|
|
super.onClose(); |
|
|
super.onClose(); |
|
|
} |
|
|
} |
|
|
@ -177,8 +175,7 @@ class OtaUpgradeController extends GetxController { |
|
|
_address = connectedDevices.first.address; |
|
|
_address = connectedDevices.first.address; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await _bleService.setEnterOta(true); |
|
|
await _bleManager.setEnterOta(true); |
|
|
await _bleService.disconnect(); |
|
|
|
|
|
|
|
|
|
|
|
await Future.delayed(const Duration(seconds: 2)); |
|
|
await Future.delayed(const Duration(seconds: 2)); |
|
|
|
|
|
|
|
|
@ -422,7 +419,7 @@ class OtaUpgradeController extends GetxController { |
|
|
if (event.event == 'onError') { |
|
|
if (event.event == 'onError') { |
|
|
type.value = OtaEvent.UPGRADE_FAILED; |
|
|
type.value = OtaEvent.UPGRADE_FAILED; |
|
|
isUpgrade.value = false; |
|
|
isUpgrade.value = false; |
|
|
Get.snackbar('升级失败', '请检查设备连接或升级包'); |
|
|
Get.snackbar('升级失败', '请检查设备连接或升级包,错误码:${event.code}'); |
|
|
} |
|
|
} |
|
|
if (event.event == 'NOCONNECTION') { |
|
|
if (event.event == 'NOCONNECTION') { |
|
|
type.value = OtaEvent.CONNECTION_DISCONNECTION; |
|
|
type.value = OtaEvent.CONNECTION_DISCONNECTION; |
|
|
|