mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 02:24:27 +05:00
script: refactoring of the flash routine
script: uart devices can be detected/selected now script: first implementation of a little help page
This commit is contained in:
@@ -176,246 +176,3 @@ create_klipper_service(){
|
||||
unset i
|
||||
fi
|
||||
}
|
||||
|
||||
flash_routine(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
||||
hr
|
||||
echo -e "| Flashing a Smoothie based board with this method will |"
|
||||
echo -e "| certainly fail. This applies to boards like the SKR |"
|
||||
echo -e "| V1.3 / V1.4. You have to copy the firmware file to |"
|
||||
echo -e "| the SD card manually and rename it to 'firmware.bin'. |"
|
||||
hr
|
||||
echo -e "| You can find the file in: ~/klipper/out/klipper.bin |"
|
||||
bottom_border
|
||||
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"
|
||||
FLASH_FIRMWARE="true"
|
||||
get_mcu_id
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
FLASH_FIRMWARE="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
flash_routine_sd(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
||||
hr
|
||||
echo -e "| If you have a Smoothie based board with an already |"
|
||||
echo -e "| flashed Klipper Firmware, you can now choose to flash |"
|
||||
echo -e "| directly from the internal SD if your control board |"
|
||||
echo -e "| is supported by that function. |"
|
||||
bottom_border
|
||||
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"
|
||||
FLASH_FW_SD="true"
|
||||
get_mcu_id
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
FLASH_FW_SD="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
select_mcu_id(){
|
||||
if [ ${#mcu_list[@]} -ge 1 ]; then
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}!!! ATTENTION !!!${default} |"
|
||||
hr
|
||||
echo -e "| Make sure, to select the correct number for the MCU! |"
|
||||
echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### List of available MCU:${default}"
|
||||
### list all mcus
|
||||
id=0
|
||||
for mcu in ${mcu_list[@]}; do
|
||||
let id++
|
||||
echo -e " $id) $mcu"
|
||||
done
|
||||
### verify user input
|
||||
sel_index=""
|
||||
while [[ ! ($sel_index =~ ^[1-9]+$) ]] || [ $sel_index -gt $id ]; do
|
||||
echo
|
||||
read -p "${cyan}###### Select MCU to flash:${default} " sel_index
|
||||
if [[ ! ($sel_index =~ ^[1-9]+$) ]]; then
|
||||
warn_msg "Invalid input!"
|
||||
elif [ $sel_index -lt 1 ] || [ $sel_index -gt $id ]; then
|
||||
warn_msg "Please select a number between 1 and $id!"
|
||||
fi
|
||||
mcu_index=$(echo $((sel_index - 1)))
|
||||
selected_mcu_id="${mcu_list[$mcu_index]}"
|
||||
done
|
||||
### process flashing
|
||||
while true; do
|
||||
echo -e "\n###### You selected:\n ● MCU #$sel_index: $selected_mcu_id\n"
|
||||
read -p "${cyan}###### Continue? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Flashing $selected_mcu_id ..."
|
||||
if [ "$FLASH_FIRMWARE" = "true" ]; then
|
||||
flash_mcu
|
||||
fi
|
||||
if [ "$FLASH_FW_SD" = "true" ]; then
|
||||
flash_mcu_sd
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
flash_mcu(){
|
||||
do_action_service "stop" "klipper"
|
||||
if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
flash_mcu_sd(){
|
||||
do_action_service "stop" "klipper"
|
||||
|
||||
### write each supported board to the array to make it selectable
|
||||
board_list=()
|
||||
for board in $(~/klipper/scripts/flash-sdcard.sh -l | tail -n +2); do
|
||||
board_list+=($board)
|
||||
done
|
||||
|
||||
i=0
|
||||
top_border
|
||||
echo -e "| Please select the type of board that corresponds to |"
|
||||
echo -e "| the currently selected MCU ID you chose before. |"
|
||||
blank_line
|
||||
echo -e "| The following boards are currently supported: |"
|
||||
hr
|
||||
### display all supported boards to the user
|
||||
for board in ${board_list[@]}; do
|
||||
if [ $i -lt 10 ]; then
|
||||
printf "| $i) %-50s|\n" "${board_list[$i]}"
|
||||
else
|
||||
printf "| $i) %-49s|\n" "${board_list[$i]}"
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
quit_footer
|
||||
|
||||
### make the user select one of the boards
|
||||
while true; do
|
||||
read -p "${cyan}###### Please select board type:${default} " choice
|
||||
if [ $choice = "q" ] || [ $choice = "Q" ]; then
|
||||
clear && advanced_menu && break
|
||||
elif [ $choice -le ${#board_list[@]} ]; then
|
||||
selected_board="${board_list[$choice]}"
|
||||
break
|
||||
else
|
||||
clear && print_header
|
||||
ERROR_MSG="Invalid choice!" && print_msg && clear_msg
|
||||
flash_mcu_sd
|
||||
fi
|
||||
done
|
||||
|
||||
while true; do
|
||||
top_border
|
||||
echo -e "| If your board is flashed with firmware that connects |"
|
||||
echo -e "| at a custom baud rate, please change it now. |"
|
||||
blank_line
|
||||
echo -e "| If you are unsure, stick to the default 250000! |"
|
||||
bottom_border
|
||||
echo -e "${cyan}###### Please set the baud rate:${default} "
|
||||
unset baud_rate
|
||||
while [[ ! $baud_rate =~ ^[0-9]+$ ]]; do
|
||||
read -e -i "250000" -e baud_rate
|
||||
selected_baud_rate=$baud_rate
|
||||
break
|
||||
done
|
||||
break
|
||||
done
|
||||
|
||||
if ! ${HOME}/klipper/scripts/flash-sdcard.sh -b "$selected_baud_rate" "$selected_mcu_id" "$selected_board" ; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
|
||||
do_action_service "start" "klipper"
|
||||
}
|
||||
|
||||
build_fw(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Initializing firmware build ..."
|
||||
dep=(build-essential dpkg-dev make)
|
||||
dependency_check
|
||||
make clean
|
||||
make menuconfig
|
||||
status_msg "Building firmware ..."
|
||||
make && ok_msg "Firmware built!"
|
||||
else
|
||||
warn_msg "Can not build firmware without a Klipper directory!"
|
||||
fi
|
||||
}
|
||||
|
||||
### grab the mcu id
|
||||
get_mcu_id(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Please make sure your MCU is connected to the Pi! |"
|
||||
echo -e "| If the MCU is not connected yet, connect it now. |"
|
||||
bottom_border
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Press ANY KEY to continue ... " -n 1 -r
|
||||
echo -e "${default}"
|
||||
status_msg "Identifying the ID of your MCU ..."
|
||||
sleep 1
|
||||
unset MCU_ID
|
||||
### if there are devices found, continue, else show warn message
|
||||
if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then
|
||||
mcu_count=1
|
||||
mcu_list=()
|
||||
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}")
|
||||
echo " ● MCU #$mcu_count: ${cyan}$mcu${default}"
|
||||
mcu_count=$(expr $mcu_count + 1)
|
||||
done
|
||||
unset mcu_count
|
||||
else
|
||||
warn_msg "Could not retrieve ID!"
|
||||
warn_msg "Printer not plugged in or not detectable!"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user