fix: small flash routine rework + user input validation

This commit is contained in:
th33xitus
2021-07-04 20:09:25 +02:00
parent 765f016ea2
commit d3726733e5
2 changed files with 46 additions and 49 deletions

View File

@@ -239,52 +239,55 @@ flash_routine_sd(){
select_mcu_id(){ select_mcu_id(){
if [ ${#mcu_list[@]} -ge 1 ]; then if [ ${#mcu_list[@]} -ge 1 ]; then
echo
top_border top_border
echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |" echo -e "| ${red}!!! ATTENTION !!!${default} |"
hr hr
echo -e "| Make sure, that you select the correct ID for the MCU |" echo -e "| Make sure, to select the correct number 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} |" echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |"
bottom_border bottom_border
echo -e "${cyan}###### List of available MCU:${default}"
### list all mcus ### list all mcus
i=1 id=0
for mcu in ${mcu_list[@]}; do for mcu in ${mcu_list[@]}; do
echo -e "$i) ${cyan}$mcu${default}" let id++
i=$(expr $i + 1) echo -e " $id) $mcu"
done done
while true; do ### verify user input
sel_index=""
while [[ ! ($sel_index =~ ^[1-9]+$) ]] || [ $sel_index -gt $id ]; do
echo echo
read -p "${cyan}###### Please select the ID for flashing:${default} " selected_index read -p "${cyan}###### Select MCU to flash:${default} " sel_index
mcu_index=$(echo $((selected_index - 1))) 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]}" selected_mcu_id="${mcu_list[$mcu_index]}"
echo -e "\nYou have selected to flash:\n● MCU #$selected_index: $selected_mcu_id\n" done
while true; do ### process flashing
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn while true; do
case "$yn" in echo -e "\n###### You selected:\n ● MCU #$sel_index: $selected_mcu_id\n"
Y|y|Yes|yes|"") read -p "${cyan}###### Continue? (Y/n):${default} " yn
echo -e "###### > Yes" case "$yn" in
status_msg "Flashing $selected_mcu_id ..." Y|y|Yes|yes|"")
if [ "$FLASH_FIRMWARE" = "true" ]; then echo -e "###### > Yes"
flash_mcu status_msg "Flashing $selected_mcu_id ..."
fi if [ "$FLASH_FIRMWARE" = "true" ]; then
if [ "$FLASH_FW_SD" = "true" ]; then flash_mcu
flash_mcu_sd fi
fi if [ "$FLASH_FW_SD" = "true" ]; then
break;; flash_mcu_sd
N|n|No|no) fi
echo -e "###### > No" break;;
break;; N|n|No|no)
*) echo -e "###### > No"
print_unkown_cmd break;;
print_msg && clear_msg;; *)
esac print_unkown_cmd
done print_msg && clear_msg;;
break esac
done done
fi fi
} }
@@ -389,17 +392,11 @@ get_mcu_id(){
echo -e "| Please make sure your MCU is connected to the Pi! |" echo -e "| Please make sure your MCU is connected to the Pi! |"
echo -e "| If the MCU is not connected yet, connect it now. |" echo -e "| If the MCU is not connected yet, connect it now. |"
bottom_border bottom_border
while true; do echo -e "${cyan}"
echo -e "${cyan}" read -p "###### Press ANY KEY to continue ... " -n 1 -r
read -p "###### Press ENTER to continue ... " yn echo -e "${default}"
echo -e "${default}"
case "$yn" in
*)
break;;
esac
done
status_msg "Identifying the ID of your MCU ..." status_msg "Identifying the ID of your MCU ..."
sleep 2 sleep 1
unset MCU_ID unset MCU_ID
### if there are devices found, continue, else show warn message ### if there are devices found, continue, else show warn message
if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then

View File

@@ -44,7 +44,7 @@ advanced_menu(){
clear && print_header clear && print_header
flash_routine flash_routine
if [ $FLASH_FIRMWARE = "true" ]; then if [ $FLASH_FIRMWARE = "true" ]; then
status_msg "Please wait..." && sleep 5 && build_fw status_msg "Please wait..." && sleep 3 && build_fw
select_mcu_id select_mcu_id
fi fi
print_msg && clear_msg print_msg && clear_msg
@@ -53,7 +53,7 @@ advanced_menu(){
clear && print_header clear && print_header
flash_routine_sd flash_routine_sd
if [ $FLASH_FW_SD = "true" ]; then if [ $FLASH_FW_SD = "true" ]; then
status_msg "Please wait..." && sleep 5 && build_fw status_msg "Please wait..." && sleep 3 && build_fw
select_mcu_id select_mcu_id
fi fi
print_msg && clear_msg print_msg && clear_msg