mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 19:14:27 +05:00
feat: support flashing of multiple connected mcus
This commit is contained in:
@@ -1,11 +1,3 @@
|
|||||||
#install_klipper(){
|
|
||||||
# get_user_selections_klipper
|
|
||||||
# klipper_setup
|
|
||||||
# build_fw
|
|
||||||
# flash_mcu
|
|
||||||
# write_printer_usb
|
|
||||||
#}
|
|
||||||
|
|
||||||
### base variables
|
### base variables
|
||||||
SYSTEMDDIR="/etc/systemd/system"
|
SYSTEMDDIR="/etc/systemd/system"
|
||||||
KLIPPY_ENV="${HOME}/klippy-env"
|
KLIPPY_ENV="${HOME}/klippy-env"
|
||||||
@@ -205,7 +197,6 @@ create_multi_klipper_instance(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
flash_routine(){
|
flash_routine(){
|
||||||
if [ "$FLASH_FIRMWARE" = "true" ]; then
|
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
||||||
@@ -223,59 +214,91 @@ flash_routine(){
|
|||||||
case "$yn" in
|
case "$yn" in
|
||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
echo -e "###### > Yes"
|
echo -e "###### > Yes"
|
||||||
CONFIRM_FLASHING="true"
|
get_mcu_id
|
||||||
CONFIRM_WRITE_PRINTER_USB="true"
|
|
||||||
get_printer_usb
|
|
||||||
break;;
|
break;;
|
||||||
N|n|No|no)
|
N|n|No|no)
|
||||||
echo -e "###### > No"
|
echo -e "###### > No"
|
||||||
CONFIRM_FLASHING="false"
|
|
||||||
CONFIRM_WRITE_PRINTER_USB="false"
|
|
||||||
break;;
|
break;;
|
||||||
*)
|
*)
|
||||||
print_unkown_cmd
|
print_unkown_cmd
|
||||||
print_msg && clear_msg;;
|
print_msg && clear_msg;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_mcu(){
|
flash_mcu(){
|
||||||
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then
|
if [ ${#mcu_list[@]} -ge 1 ]; then
|
||||||
|
top_border
|
||||||
|
echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |"
|
||||||
|
hr
|
||||||
|
echo -e "| Make sure, that you select the correct ID for the MCU |"
|
||||||
|
echo -e "| you have build the firmware for in the previous step! |"
|
||||||
|
blank_line
|
||||||
|
echo -e "| This is especially important if you use different MCU |"
|
||||||
|
echo -e "| models which each require their own firmware! |"
|
||||||
|
blank_line
|
||||||
|
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
|
||||||
|
bottom_border
|
||||||
|
|
||||||
|
### list all mcus
|
||||||
|
i=1
|
||||||
|
for mcu in ${mcu_list[@]}; do
|
||||||
|
### rewrite mcu to cut off everything except the important stuff
|
||||||
|
mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev)
|
||||||
|
echo -e "$i) ${cyan}$mcu${default}"
|
||||||
|
i=$(expr $i + 1)
|
||||||
|
done
|
||||||
|
while true; do
|
||||||
|
echo
|
||||||
|
read -p "${cyan}###### Please select the ID for flashing:${default} " selected_id
|
||||||
|
mcu_index=$(echo $((selected_id - 1)))
|
||||||
|
echo -e "\nYou have selected to flash:\n● MCU #$selected_id: ${mcu_list[$mcu_index]}\n"
|
||||||
|
while true; do
|
||||||
|
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
||||||
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
echo -e "###### > Yes"
|
||||||
|
status_msg "Flashing ${mcu_list[$mcu_index]} ..."
|
||||||
klipper_service "stop"
|
klipper_service "stop"
|
||||||
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
|
if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then
|
||||||
warn_msg "Flashing failed!"
|
warn_msg "Flashing failed!"
|
||||||
warn_msg "Please read the console output above!"
|
warn_msg "Please read the console output above!"
|
||||||
else
|
else
|
||||||
ok_msg "Flashing successfull!"
|
ok_msg "Flashing successfull!"
|
||||||
fi
|
fi
|
||||||
klipper_service "start"
|
klipper_service "start"
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
echo -e "###### > No"
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
print_unkown_cmd
|
||||||
|
print_msg && clear_msg;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
break
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
build_fw(){
|
build_fw(){
|
||||||
if [ "$BUILD_FIRMWARE" = "true" ]; then
|
|
||||||
if [ -d $KLIPPER_DIR ]; then
|
if [ -d $KLIPPER_DIR ]; then
|
||||||
cd $KLIPPER_DIR
|
cd $KLIPPER_DIR
|
||||||
status_msg "Initializing Firmware Setup ..."
|
status_msg "Initializing firmware Setup ..."
|
||||||
make menuconfig
|
make menuconfig
|
||||||
status_msg "Building Firmware ..."
|
status_msg "Building firmware ..."
|
||||||
make clean && make && ok_msg "Firmware built!"
|
make clean && make && ok_msg "Firmware built!"
|
||||||
else
|
else
|
||||||
warn_msg "Can not build Firmware without a Klipper directory!"
|
warn_msg "Can not build firmware without a Klipper directory!"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
### grab the printers id
|
### grab the mcu id
|
||||||
get_printer_usb(){
|
get_mcu_id(){
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
echo -e "| Please make sure your printer is connected to the Pi! |"
|
echo -e "| Please make sure your MCU is connected to the Pi! |"
|
||||||
echo -e "| If the printer is not connected yet, connect it now. |"
|
echo -e "| If the MCU is not connected yet, connect it now. |"
|
||||||
hr
|
|
||||||
echo -e "| Also make sure, that it is the only USB device |"
|
|
||||||
echo -e "| connected at for now! Otherwise this step may fail! |"
|
|
||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
echo -e "${cyan}"
|
echo -e "${cyan}"
|
||||||
@@ -283,70 +306,30 @@ get_printer_usb(){
|
|||||||
echo -e "${default}"
|
echo -e "${default}"
|
||||||
case "$yn" in
|
case "$yn" in
|
||||||
*)
|
*)
|
||||||
CONFIRM_PRINTER_USB="true"
|
|
||||||
break;;
|
break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
status_msg "Identifying the correct USB port ..."
|
status_msg "Identifying the ID of your MCU ..."
|
||||||
sleep 2
|
sleep 2
|
||||||
unset PRINTER_USB
|
unset MCU_ID
|
||||||
if [ -e /dev/serial/by-id/* ]; then
|
### if there are devices found, continue, else show warn message
|
||||||
if [ -e /dev/serial/by-id/* ]; then
|
if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then
|
||||||
PRINTER_USB=$(ls /dev/serial/by-id/*)
|
mcu_count=1
|
||||||
status_msg "The ID of your printer is:"
|
mcu_list=()
|
||||||
title_msg "$PRINTER_USB"
|
status_msg "The ID of your printers MCU is:"
|
||||||
|
### loop over the IDs, write every ID as an item of the array 'mcu_list'
|
||||||
|
for mcu in /dev/serial/by-id/*; do
|
||||||
|
declare "mcu_id_$mcu_count"="$mcu"
|
||||||
|
mcu_id="mcu_id_$mcu_count"
|
||||||
|
mcu_list+=("${!mcu_id}")
|
||||||
|
### rewrite mcu to cut off everything except the important stuff
|
||||||
|
mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev)
|
||||||
|
echo " ● MCU #$mcu_count: ${cyan}$mcu${default}"
|
||||||
|
mcu_count=$(expr $mcu_count + 1)
|
||||||
|
done
|
||||||
|
unset mcu_count
|
||||||
else
|
else
|
||||||
warn_msg "Could not retrieve ID!"
|
warn_msg "Could not retrieve ID!"
|
||||||
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"
|
|
||||||
else
|
|
||||||
warn_msg "Could not retrieve path!"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn_msg "Printer not plugged in or not detectable!"
|
warn_msg "Printer not plugged in or not detectable!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
write_printer_usb(){
|
|
||||||
locate_printer_cfg
|
|
||||||
if [ ! -z "$PRINTER_CFG" ] && [ "$CONFIRM_WRITE_PRINTER_USB" = "true" ]; then
|
|
||||||
SERIAL_OLD=$(grep "serial" $PRINTER_CFG | tail -1 | cut -d" " -f2)
|
|
||||||
SERIAL_NEW=$PRINTER_USB
|
|
||||||
if [ "$SERIAL_OLD" != "$SERIAL_NEW" ]; then
|
|
||||||
unset write_entries
|
|
||||||
backup_printer_cfg
|
|
||||||
write_entries+=("[mcu]\nserial: $SERIAL_NEW")
|
|
||||||
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
|
|
||||||
write_entries=("############################\n" "${write_entries[@]}")
|
|
||||||
#check for a SAVE_CONFIG entry
|
|
||||||
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
|
||||||
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
|
|
||||||
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
|
|
||||||
PRE_SC_LINE=$(expr $SC_LINE - 1)
|
|
||||||
SC_ENTRY="true"
|
|
||||||
else
|
|
||||||
SC_ENTRY="false"
|
|
||||||
fi
|
|
||||||
status_msg "Writing printer ID/path to printer.cfg ..."
|
|
||||||
if [ "$SC_ENTRY" = "true" ]; then
|
|
||||||
PRE_SC_LINE="$(expr $SC_LINE - 1)a"
|
|
||||||
for entry in "${write_entries[@]}"
|
|
||||||
do
|
|
||||||
sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
if [ "$SC_ENTRY" = "false" ]; then
|
|
||||||
LINE_COUNT="$(wc -l < $PRINTER_CFG)a"
|
|
||||||
for entry in "${write_entries[@]}"
|
|
||||||
do
|
|
||||||
sed -i "$LINE_COUNT $entry" $PRINTER_CFG
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
ok_msg "Done!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ advanced_ui(){
|
|||||||
echo -e "| Firmware: | 7) [Shell Command] | "
|
echo -e "| Firmware: | 7) [Shell Command] | "
|
||||||
echo -e "| 3) [Build only] | | "
|
echo -e "| 3) [Build only] | | "
|
||||||
echo -e "| 4) [Build + Flash MCU] | | "
|
echo -e "| 4) [Build + Flash MCU] | | "
|
||||||
echo -e "| 5) [Get Printer-USB] | | "
|
echo -e "| 5) [Get MCU ID] | | "
|
||||||
echo -e "| | | "
|
echo -e "| | | "
|
||||||
quit_footer
|
quit_footer
|
||||||
}
|
}
|
||||||
@@ -47,25 +47,23 @@ advanced_menu(){
|
|||||||
3)
|
3)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
|
||||||
build_fw
|
build_fw
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
4)
|
4)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
unset FLASH_FIRMWARE && FLASH_FIRMWARE="true"
|
|
||||||
flash_routine
|
flash_routine
|
||||||
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
### build in a sleep to give the user a chance to have a look at the
|
||||||
build_fw
|
### MCU IDs before directly starting to build the klipper firmware
|
||||||
unset CONFIRM_FLASHING && CONFIRM_FLASHING="true"
|
status_msg "Please wait..." && sleep 10 && build_fw
|
||||||
flash_mcu
|
flash_mcu
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
5)
|
5)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
get_printer_usb
|
get_mcu_id
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
6)
|
6)
|
||||||
|
|||||||
Reference in New Issue
Block a user