diff --git a/kiauh.sh b/kiauh.sh index c5c4b01..e9dd391 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -357,13 +357,13 @@ advanced_menu(){ 5) clear print_header - get_usb_id + get_printer_usb print_msg && clear_msg advanced_ui;; 6) clear print_header - get_usb_id && write_printer_id + get_printer_usb && write_printer_usb print_msg && clear_msg advanced_ui;; 7) @@ -510,7 +510,7 @@ backup_menu(){ ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" -for script in ${SRCDIR}/kiauh/scripts/*; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/"*; do . $script; done check_euid kiauh_status diff --git a/scripts/functions.sh b/scripts/functions.sh index ec1c1c6..581aeee 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -139,7 +139,7 @@ build_fw(){ } ### grab the printers id -get_usb_id(){ +get_printer_usb(){ warn_msg "Make sure your printer is the only USB device connected!" while true; do echo -e "${cyan}" @@ -150,17 +150,34 @@ get_usb_id(){ esac done status_msg "Identifying the correct USB port ..." - USB_ID=$(ls /dev/serial/by-id/*) + sleep 3 if [ -e /dev/serial/by-id/* ]; then - status_msg "The ID of your printer is:" - title_msg "$USB_ID" + if [ -e /dev/serial/by-id/* ]; then + PRINTER_USB=$(ls /dev/serial/by-id/*) + status_msg "The ID of your printer is:" + title_msg "$PRINTER_USB" + echo + else + warn_msg "Could not retrieve ID!" + echo + fi + elif [ -e /dev/serial/by-path/* ]; then + if [ -e /dev/serial/by-path/* ]; then + PRINTER_USB=$(ls /dev/serial/by-path/*) + status_msg "The path of your printer is:" + title_msg "$PRINTER_USB" + echo + else + warn_msg "Could not retrieve path!" + echo + fi else - warn_msg "Could not retrieve ID!" - return 1 - fi + warn_msg "Printer not plugged in or not detectable!" + echo +fi } -write_printer_id(){ +write_printer_usb(){ while true; do echo -e "${cyan}" read -p "###### Do you want to write the ID to your printer.cfg? (Y/n): " yn @@ -168,16 +185,17 @@ write_printer_id(){ case "$yn" in Y|y|Yes|yes|"") backup_printer_cfg -cat <> $PRINTER_CFG +cat <> $PRINTER_CFG ########################## ### CREATED WITH KIAUH ### ########################## [mcu] -serial: $USB_ID +serial: $PRINTER_USB ########################## ########################## -PRINTERID +PRINTERUSB + echo ok_msg "Config written!" break;; N|n|No|no) break;; @@ -204,7 +222,7 @@ flash_routine(){ echo -e "${default}" case "$yn" in Y|y|Yes|yes|"") - get_usb_id && flash_mcu && write_printer_id; break;; + get_printer_usb && flash_mcu && write_printer_usb; break;; N|n|No|no) break;; esac done @@ -212,7 +230,7 @@ flash_routine(){ flash_mcu(){ stop_klipper - if ! make flash FLASH_DEVICE="$USB_ID" ; then + if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then warn_msg "Flashing failed!" warn_msg "Please read the log above!" else diff --git a/scripts/ui.sh b/scripts/ui.sh index 9c09a77..f331ce8 100644 --- a/scripts/ui.sh +++ b/scripts/ui.sh @@ -120,8 +120,8 @@ advanced_ui(){ echo -e "| Firmware: | 9) [Remove branding] | " echo -e "| 3) [Build Firmware] | | " echo -e "| 4) [Flash MCU] | | " - echo -e "| 5) [Get Printer-ID] | | " - echo -e "| 6) [Write Printer-ID] | | " + echo -e "| 5) [Get Printer-USB] | | " + echo -e "| 6) [Write Printer-USB] | | " echo -e "| 7) [Write DWC2 config] | | " echo -e "| | | " quit_footer