chiark / gitweb /
quacks-ingredients: gcode manipulation
[reprap-play.git] / quacks-ingredients-make-copy-gcodes
1 #!/bin/sh
2 #
3 # usage:
4 #    ./quacks-ingredients-make-copy-gcodes Tests_L
5 # Uses
6 #    quacks-ingredients-L$l,Tests_L.auto.stl
7 # to make
8 #    quacks-ingredients-L$l,Tests_L.auto.gcode
9 # and then edits them and copies them to the SD card as
10 #    PREPARED/Q$l.G
11
12 set -e
13
14 f=$1
15 shift
16
17 lhs=quacks-ingredients-L
18
19 gh () {
20         g=$lhs$l.auto.gcode
21         h=/media/sd/PREPARED/Q$l.G
22 }
23
24 for l in 1 2 3 4 5; do
25         gh
26         cura -i quacks.ini -s $lhs$l,$f.auto.stl -o $g
27         case $l in
28         1|2|3|4)
29                 perl -i~ -pe 's/^/;/ if m/^M140 S0\b.*\n/' $g
30                 ;;
31         esac
32
33         perl -i~ -ne '
34                 $l =~ s/^/;/ if m/^M400/;
35                 $l .= "G91\nG1 Z5\nG90\n" if m/^M84/;
36                 print $l or die $!;
37                 $l = $_;
38                 END { print $l or die $!; }
39         ' $g
40 done
41
42 for l in 2 4 5; do
43         gh
44         perl -i~ -0777 -ne '
45                 @l = split m{^(?=;LAYER:\d+\n)}m, $_;
46                 foreach my $i (0..$#l) {
47                         $l[$i] =~
48                                 s{
49                                         ^G1 \ Z([0-9.]+) \s*\n
50                                 (       ^G0 \ F(\d+) \ X\S+ \ Y\S+ \s*\n
51                                         (?: ; .* \s*\n )?
52                                         ^G1 \ Z([0-9.]+) \s*\n  )
53                                 }{
54                                         die unless $1 > $4;
55                                         die unless $3 > 9000;
56                                         my $z = $i == $#l ? $1 : $4 + 0.5;
57                                         "G0 F$3\n".
58                                         "G1 Z$z\n" .
59                                         $2
60                                 }gmxe or $l==0 or die $i;
61                 }
62                 print or die $! foreach @l;
63         ' $g
64 done
65
66 exec 3>${lhs}234.auto.gcode
67 for l in 2 3; do
68         gh
69         perl -pe 's/^/;/ if m/^M104 S0\b/ || (m/^M84/..0)' $g >&3
70 done
71 for l in 4; do
72         gh
73         cat $g >&3
74 done
75
76 umount /media/sd >/dev/null 2>&1 ||:
77 mount /media/sd
78
79 for l in 1 2 3 4 5 234; do
80         gh
81         cp $g $h
82 done
83 sleep 0.5
84
85 umount /media/sd
86 mount /media/sd
87
88 for l in 1 2 3 4 5 234; do
89         gh
90         cmp $g $h
91         ls -l $h
92 done
93 sleep 0.5
94
95 umount /media/sd