From b2590e41427ecba19bc143a206c54675de6f09ca Mon Sep 17 00:00:00 2001 From: Simon Voordouw Date: Mon, 12 Jun 2017 17:20:29 +0200 Subject: [PATCH] add options to pass start and end-gcode to print-fetch --- src/script/print-fetch.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/script/print-fetch.lua b/src/script/print-fetch.lua index 3fd0eaa..5d4d7d3 100755 --- a/src/script/print-fetch.lua +++ b/src/script/print-fetch.lua @@ -6,7 +6,7 @@ local function log(message) end if (table.getn(arg) == 0) then - print("Usage: ./print-fetch {printerSocket} {remoteURL} {id}") + print("Usage: ./print-fetch {printerSocket} {remoteURL} {id} [startGcode] [endGCode]") return end @@ -35,6 +35,26 @@ local started = false log("total lines: " .. total_lines) +local startCode = '' +local endCode = '' + +function countlines(file) + return tonumber(io.popen("wc -l < " .. file):read('*a')) +end + +function readGCodeArg(argi) + local gcodeFile = arg[argi] + total_lines = total_lines + countlines(gcodeFile) + return io.open(gcodeFile):read('*a') +end + +if table.getn(arg) >= 5 then + startCode = readGCodeArg(4) + endCode = readGCodeArg(5) +end + +printer:appendGcode(startCode) + while(not finished) do local f = io.popen("wget -qO - " .. remote .. "/fetch/" .. id .. "/" .. current_line) @@ -45,6 +65,7 @@ do line = f:read() end if current_line >= total_lines then + printer:appendGcode(endCode) finished = true break end