mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-19 22:04:27 +05:00
fix: correctly find connected USB DFU devices (#555)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -7,7 +7,15 @@
|
|||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
|
||||||
from subprocess import PIPE, STDOUT, CalledProcessError, Popen, check_output, run
|
from subprocess import (
|
||||||
|
DEVNULL,
|
||||||
|
PIPE,
|
||||||
|
STDOUT,
|
||||||
|
CalledProcessError,
|
||||||
|
Popen,
|
||||||
|
check_output,
|
||||||
|
run,
|
||||||
|
)
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.klipper import KLIPPER_DIR
|
from components.klipper import KLIPPER_DIR
|
||||||
@@ -32,8 +40,10 @@ def find_firmware_file() -> bool:
|
|||||||
f3 = "klipper.bin"
|
f3 = "klipper.bin"
|
||||||
f4 = "klipper.uf2"
|
f4 = "klipper.uf2"
|
||||||
fw_file_exists: bool = (
|
fw_file_exists: bool = (
|
||||||
target.joinpath(f1).exists() and target.joinpath(f2).exists()
|
(target.joinpath(f1).exists() and target.joinpath(f2).exists())
|
||||||
) or target.joinpath(f3).exists() or target.joinpath(f4).exists()
|
or target.joinpath(f3).exists()
|
||||||
|
or target.joinpath(f4).exists()
|
||||||
|
)
|
||||||
|
|
||||||
return target_exists and fw_file_exists
|
return target_exists and fw_file_exists
|
||||||
|
|
||||||
@@ -62,9 +72,13 @@ def find_uart_device() -> List[str]:
|
|||||||
|
|
||||||
def find_usb_dfu_device() -> List[str]:
|
def find_usb_dfu_device() -> List[str]:
|
||||||
try:
|
try:
|
||||||
command = '"lsusb | grep "DFU" | cut -d " " -f 6 2>/dev/null"'
|
output = check_output("lsusb", shell=True, text=True, stderr=DEVNULL)
|
||||||
output = check_output(command, shell=True, text=True)
|
device_list = []
|
||||||
return output.splitlines()
|
if output:
|
||||||
|
devices = output.splitlines()
|
||||||
|
device_list = [d.split(" ")[5] for d in devices if "DFU" in d]
|
||||||
|
return device_list
|
||||||
|
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
Logger.print_error("Unable to find a USB DFU device!")
|
Logger.print_error("Unable to find a USB DFU device!")
|
||||||
Logger.print_error(e, prefix=False)
|
Logger.print_error(e, prefix=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user