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 -pe '
45                 s{
46                         ^G1 \ Z([0-9.]+) \s*\n
47                 (       ^G0 \ F(\d+) \ X\S+ \ Y\S+ \s*\n
48                         (?: ; .* \s*\n )?
49                         ^G1 \ Z([0-9.]+) \s*\n  )
50                 }{
51                         die unless $1 > $4;
52                         die unless $3 > 9000;
53                         "G0 F$3\n".
54                         "G1 Z".($4 + 0.5)."\n" .
55                         $2
56                 }gmxe or die;
57         ' $g
58 done
59
60 exec 3>${lhs}234.auto.gcode
61 for l in 2 3; do
62         gh
63         perl -pe 's/^/;/ if m/^M104 S0\b/ || (m/^M84/..0)' $g >&3
64 done
65 for l in 4; do
66         gh
67         cat $g >&3
68 done
69
70 umount /media/sd >/dev/null 2>&1 ||:
71 mount /media/sd
72
73 for l in 1 2 3 4 5 234; do
74         gh
75         cp $g $h
76 done
77 sleep 0.5
78
79 umount /media/sd
80 mount /media/sd
81
82 for l in 1 2 3 4 5 234; do
83         gh
84         cmp $g $h
85         ls -l $h
86 done
87 sleep 0.5
88
89 umount /media/sd