optimize_gcode_mmu.awk #!/bin/awk -f BEGIN { hottemp=205 delta=15 nbgcodebefore=5 posgcodewipe=4 coldtemp=hottemp-delta nbchange=0 purgestate=0 nbgcodewipe=4 curposwipe=0 } { if ( $1 == "M104" ) { hottemp=int(substr($2,2)); coldtemp=hottemp-delta; printf(";Update temperature printing:%s Cold:%s\n",hottemp,coldtemp); } if ( $1 ~ /^T[0-9]$/ && nbchange > 0) { printf("M104 S%s\n",hottemp) print $0; next; } if ( $0 == "; CP TOOLCHANGE UNLOAD" ){ nbchange++; printf("; Change numero:%s\n",nbchange); if ( nbchange > 0 ) { printf("M104 S%s\n",coldtemp); }; print($0) next; } if ( $0 == "; CP TOOLCHANGE WIPE") { purgestats=1; print($0); next; } if ( $0 == "; CP TOOLCHANGE END") { purgestats=0; nbgcodewipe=curposwipe if ( nbgcodewipe > nbgcodebefore ) { posgcodewipe=nbgcodewipe-nbgcodebefore } curposwipe=0; print($0); next; } if ( purgestats == 1 && nbchange > 0 ) { if ( $1 == "G1") { curposwipe++; if ( curposwipe == posgcodewipe ) { if ( nbchange < 20 ) { printf("M300 S800 P350\nM109 S%s\nM300 S1000 P200\n",hottemp) ; } else { printf("M109 S%s\n",hottemp) ; } print($0) next; } } } print($0) } # Loop section END{} # End section