My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

mftest 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env bash
  2. #
  3. # mftest Select a test to apply and build
  4. # mftest -b [#] Build the auto-detected environment
  5. # mftest -u [#] Upload the auto-detected environment
  6. # mftest [name] [index] [-y] Set config options and optionally build a test
  7. #
  8. MFINFO=$(mfinfo) || exit 1
  9. [[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
  10. TESTPATH=buildroot/share/tests
  11. STATE_FILE=$( echo ./.pio/.mftestrc )
  12. SED=$(which gsed || which sed)
  13. shopt -s extglob nocasematch
  14. # Matching patterns
  15. ISNUM='^[0-9]+$'
  16. ISCMD='^(restore|opt|exec|use|pins|env)_'
  17. ISEXEC='^exec_'
  18. ISCONT='\\ *$'
  19. # Get the environment and test number from the command
  20. TESTENV=${1:-'-'}
  21. CHOICE=${2:-0}
  22. AUTOENV=0
  23. # Allow shorthand for test name
  24. case $TESTENV in
  25. tree) pio run -d . -e include_tree ; exit 1 ;;
  26. due) TESTENV='DUE' ;;
  27. esp) TESTENV='esp32' ;;
  28. lin*) TESTENV='linux_native' ;;
  29. lpc?(8)) TESTENV='LPC1768' ;;
  30. lpc9) TESTENV='LPC1769' ;;
  31. m128) TESTENV='mega1280' ;;
  32. m256) TESTENV='mega2560' ;;
  33. mega) TESTENV='mega2560' ;;
  34. stm) TESTENV='STM32F103RE' ;;
  35. f1) TESTENV='STM32F103RE' ;;
  36. f4) TESTENV='STM32F4' ;;
  37. f7) TESTENV='STM32F7' ;;
  38. s6) TESTENV='FYSETC_S6' ;;
  39. teensy) TESTENV='teensy31' ;;
  40. t31) TESTENV='teensy31' ;;
  41. t32) TESTENV='teensy31' ;;
  42. t35) TESTENV='teensy35' ;;
  43. t36) TESTENV='teensy35' ;;
  44. -h|--help) echo -e "$(basename $0) : Marlin Firmware test, build, and upload\n"
  45. echo "Usage: $(basename $0) ................. Select env and test to apply / run"
  46. echo " $(basename $0) [-y] env ........ Select a test for env to apply / run"
  47. echo " $(basename $0) [-y] env test ... Apply / run the specified env test"
  48. echo " $(basename $0) -b [variant] .... Auto-build the specified variant"
  49. echo " $(basename $0) -u [variant] .... Auto-build and upload the specified variant"
  50. echo
  51. echo "env shortcuts: tree due esp lin lpc|lpc8 lpc9 m128 m256|mega stm|f1 f4 f7 s6 teensy|t31|t32 t35|t36"
  52. exit
  53. ;;
  54. # Build with the last-built env
  55. -r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
  56. read TESTENV <"$STATE_FILE"
  57. pio run -d . -e $TESTENV
  58. exit
  59. ;;
  60. -[bu]) MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | $SED 's/BOARD_//' )
  61. [[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
  62. BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
  63. BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
  64. BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
  65. [[ -z $BNUM ]] && { echo "Error - Can't find $MB in boards list." ; exit 1 ; }
  66. readarray -t ENVS <<< $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E '#include.+//.+env:.+' | grep -oE 'env:[^ ]+' | $SED -E 's/env://' )
  67. [[ -z $ENVS ]] && { echo "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
  68. ECOUNT=${#ENVS[*]}
  69. if [[ $ECOUNT == 1 ]]; then
  70. TARGET=$ENVS
  71. else
  72. if [[ $CHOICE == 0 ]]; then
  73. #
  74. # List env names and numbers. Get selection.
  75. #
  76. echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
  77. IND=0 ; for ENV in "${ENVS[@]}"; do let IND++ ; echo " $IND) $ENV" ; done
  78. if [[ $ECOUNT > 1 ]]; then
  79. for (( ; ; ))
  80. do
  81. read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
  82. [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
  83. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
  84. echo ">>> Invalid environment choice '$CHOICE'."
  85. done
  86. echo
  87. fi
  88. else
  89. echo "Detected \"$BDESC\" | $MB ($BNUM)."
  90. [[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 1 ; }
  91. fi
  92. TARGET="${ENVS[$CHOICE-1]}"
  93. echo "Selected $TARGET"
  94. fi
  95. echo "$TARGET" >"$STATE_FILE"
  96. if [[ $TESTENV == "-u" ]]; then
  97. echo "Build/Uploading environment $TARGET for board $MB ($BNUM)..." ; echo
  98. pio run -t upload -e $TARGET
  99. else
  100. echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
  101. pio run -e $TARGET
  102. fi
  103. exit
  104. ;;
  105. # The -y flag may come first
  106. -y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
  107. -[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
  108. -) ;;
  109. esac
  110. #
  111. # List available tests and ask for selection
  112. #
  113. if [[ $TESTENV == '-' ]]; then
  114. IND=0
  115. NAMES=()
  116. for FILE in $( ls -1 $TESTPATH/*-tests )
  117. do
  118. let IND++
  119. TNAME=${FILE/-tests/}
  120. TNAME=${TNAME/$TESTPATH\//}
  121. NAMES+=($TNAME)
  122. (( IND < 10 )) && echo -n " "
  123. echo " $IND) $TNAME"
  124. done
  125. echo
  126. for (( ; ; ))
  127. do
  128. read -p "Select a test to apply (1-$IND) : " NAMEIND
  129. [[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
  130. [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
  131. echo "Invalid selection."
  132. done
  133. fi
  134. # Get the contents of the test file
  135. OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
  136. # Count up the number of tests
  137. TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
  138. # User entered a number?
  139. (( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
  140. if [[ $CHOICE == 0 ]]; then
  141. #
  142. # List test descriptions with numbers and get selection
  143. #
  144. echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
  145. IND=0
  146. while IFS= read -r LINE
  147. do
  148. if [[ $LINE =~ $ISEXEC ]]; then
  149. DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
  150. (( ++IND < 10 )) && echo -n " "
  151. echo " $IND) $DESC"
  152. fi
  153. done
  154. }
  155. CHOICE=1
  156. if [[ $TESTCOUNT > 1 ]]; then
  157. for (( ; ; ))
  158. do
  159. read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
  160. [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
  161. [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
  162. echo ">>> Invalid test selection '$CHOICE'."
  163. done
  164. fi
  165. fi
  166. #
  167. # Run the specified test lines
  168. #
  169. echo "$OUT" | {
  170. IND=0
  171. GOTX=0
  172. CMD=""
  173. while IFS= read -r LINE
  174. do
  175. if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
  176. ((!IND)) && let IND++
  177. if [[ $LINE =~ $ISEXEC ]]; then
  178. ((IND++ > CHOICE)) && break
  179. else
  180. ((!HEADER)) && {
  181. HEADER=1
  182. echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
  183. }
  184. ((IND == CHOICE)) && {
  185. GOTX=1
  186. [[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' )
  187. [[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
  188. }
  189. fi
  190. fi
  191. done
  192. }
  193. # Make clear it's a TEST
  194. opt_set CUSTOM_MACHINE_NAME "\"$TESTENV-tests ($CHOICE)\""
  195. # Get a -y parameter the lazy way
  196. [[ "$2" == "-y" || "$3" == "-y" ]] && BUILD_YES='Y'
  197. # Build the test too?
  198. if [[ $BUILD_YES != 'Y' ]]; then
  199. echo
  200. read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
  201. fi
  202. [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
  203. pio run -d . -e $TESTENV
  204. echo "$TESTENV" >"$STATE_FILE"
  205. }