添加 Utilies 中的 upload fw function

This commit is contained in:
Mason Huang 2025-04-10 12:41:00 +08:00
parent 527b183576
commit 2d14543f06

View File

@ -8,6 +8,7 @@ import kp
from src.config import UXUI_ASSETS, WINDOW_SIZE, BACKGROUND_COLOR, DongleModelMap
from src.controllers.device_controller import DeviceController
from src.services.device_service import check_available_device
from ..config import FW_DIR
class UtilitiesScreen(QWidget):
# Signals for navigation
@ -820,13 +821,55 @@ class UtilitiesScreen(QWidget):
def update_firmware(self):
"""Update firmware for the selected device"""
selected_rows = self.device_table.selectedItems()
if not selected_rows:
QMessageBox.warning(self, "Warning", "Please select a device to update firmware")
return
# In a real application, you would implement the firmware update logic here
QMessageBox.information(self, "Info", "Firmware update functionality will be implemented in a future update")
try:
# 檢查是否有選擇設備
selected_rows = self.device_table.selectionModel().selectedRows()
if not selected_rows:
QMessageBox.warning(self, "警告", "請選擇要更新韌體的設備")
return
# 獲取選擇的設備資訊
row_index = selected_rows[0].row()
device_model = self.device_table.item(row_index, 0).text() # 設備型號
port_id = self.device_table.item(row_index, 1).text() # Port ID
# 顯示進度條
self.show_progress(f"正在更新 {device_model} 的韌體...", 0)
# 連接設備
device_group = kp.core.connect_devices(usb_port_ids=[int(port_id)])
# 構建韌體檔案路徑
scpu_fw_path = os.path.join(FW_DIR, device_model, "fw_scpu.bin")
ncpu_fw_path = os.path.join(FW_DIR, device_model, "fw_ncpu.bin")
# 檢查韌體檔案是否存在
if not os.path.exists(scpu_fw_path) or not os.path.exists(ncpu_fw_path):
self.hide_progress()
QMessageBox.critical(self, "錯誤", f"找不到 {device_model} 的韌體檔案")
return
# 更新進度
self.update_progress(30)
# 載入韌體
kp.core.load_firmware_from_file(
device_group=device_group,
scpu_fw_path=scpu_fw_path,
ncpu_fw_path=ncpu_fw_path
)
# 更新進度
self.update_progress(100)
# 顯示成功訊息
QMessageBox.information(self, "成功", f"{device_model} 的韌體已成功更新")
except Exception as e:
self.hide_progress()
QMessageBox.critical(self, "錯誤", f"更新韌體時發生錯誤: {str(e)}")
finally:
self.hide_progress()
def install_drivers(self):
"""Install drivers for all supported Kneron devices"""