32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
import kp
|
|
from typing import List, Dict
|
|
|
|
class DeviceController:
|
|
def __init__(self):
|
|
self.connected_devices = []
|
|
|
|
def scan_devices(self):
|
|
return kp.core.scan_devices()
|
|
|
|
def connect_device(self, usb_port_id: int):
|
|
device_group = kp.core.connect_devices(usb_port_ids=[usb_port_id])
|
|
kp.core.set_timeout(device_group=device_group, milliseconds=5000)
|
|
return device_group
|
|
|
|
def load_firmware(self, device_group, product_id: int):
|
|
SCPU_FW_PATH = f'../../external/res/firmware/{product_id}/fw_scpu.bin'
|
|
NCPU_FW_PATH = f'../../external/res/firmware/{product_id}/fw_ncpu.bin'
|
|
kp.core.load_firmware_from_file(
|
|
device_group=device_group,
|
|
scpu_fw_path=SCPU_FW_PATH,
|
|
ncpu_fw_path=NCPU_FW_PATH
|
|
)
|
|
|
|
def parse_device_info(self, device) -> Dict:
|
|
return {
|
|
'usb_port_id': device.usb_port_id,
|
|
'product_id': device.product_id,
|
|
'kn_number': device.kn_number
|
|
}
|
|
|
|
|