-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiretract.lua
57 lines (46 loc) · 1.37 KB
/
Multiretract.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--convert firmware retraction gcode into normal retraction split across 3 extruders
local RetractAmount = 5
local RetractSpeed = 60*60
local UnretractAmount = RetractAmount
local UnretractSpeed = RetractSpeed
local RetractionTool = 15
local OutFile = io.open(arg[2], "w")
local RetractTotal = RetractAmount * 3
local UnretractTotal = UnretractAmount * 3
local Tool = 0
function get_gcode(gcode)
first, last, address, code = gcode:find('^(%a)(%d+)')
return address, code
end
function get_parameter(gcode, param)
first, last, val = gcode:find(param..'(%d+%.?%d*)')
return val
end
for Line in io.lines(arg[1]) do
addr, code = get_gcode(Line)
if addr == 'G' then
if code == '10' then
--retract
if Tool ~= RetractionTool then
OutFile:write("T"..tostring(RetractionTool).."\n")
end
OutFile:write("G1 F"..RetractSpeed.." E-"..RetractTotal.."\n")
elseif code == '11' then
--unretract
if Tool ~= RetractionTool then
OutFile:write("T"..tostring(RetractionTool).."\n")
end
OutFile:write("G1 F"..UnretractSpeed.." E"..UnretractTotal.."\n")
if Tool ~= RetractionTool then
OutFile:write("T"..tostring(Tool).."\n")
end
else
OutFile:write(Line,"\n")
end
elseif addr == 'T' then --tool change
Tool = tonumber(code)
OutFile:write(Line,"\n")
else
OutFile:write(Line,"\n")
end
end