#!/bin/sh # # usage: # ./quacks-ingredients-make-copy-gcodes Tests_L # Uses # quacks-ingredients-L$l,Tests_L.auto.stl # to make # quacks-ingredients-L$l,Tests_L.auto.gcode # and then edits them and copies them to the SD card as # PREPARED/Q$l.G set -e f=$1 shift lhs=quacks-ingredients-L gh () { g=$lhs$l.auto.gcode h=/media/sd/PREPARED/Q$l.G } for l in 1 2 3 4 5; do gh cura -i quacks.ini -s $lhs$l,$f.auto.stl -o $g case $l in 1|2|3|4) perl -i~ -pe 's/^/;/ if m/^M140 S0\b.*\n/' $g ;; esac perl -i~ -ne ' $l =~ s/^/;/ if m/^M400/; $l .= "G91\nG1 Z5\nG90\n" if m/^M84/; print $l or die $!; $l = $_; END { print $l or die $!; } ' $g done for l in 2 4 5; do gh perl -i~ -0777 -pe ' s{ ^G1 \ Z([0-9.]+) \s*\n ( ^G0 \ F(\d+) \ X\S+ \ Y\S+ \s*\n (?: ; .* \s*\n )? ^G1 \ Z([0-9.]+) \s*\n ) }{ die unless $1 > $4; die unless $3 > 9000; "G0 F$3\n". "G1 Z".($4 + 0.5)."\n" . $2 }gmxe or die; ' $g done exec 3>${lhs}234.auto.gcode for l in 2 3; do gh perl -pe 's/^/;/ if m/^M104 S0\b/ || (m/^M84/..0)' $g >&3 done for l in 4; do gh cat $g >&3 done umount /media/sd >/dev/null 2>&1 ||: mount /media/sd for l in 1 2 3 4 5 234; do gh cp $g $h done sleep 0.5 umount /media/sd mount /media/sd for l in 1 2 3 4 5 234; do gh cmp $g $h ls -l $h done sleep 0.5 umount /media/sd