From c536fe32213b4ee11c6681c5f7497572506bea03 Mon Sep 17 00:00:00 2001 From: Simon Voordouw Date: Thu, 6 Jul 2017 14:17:49 +0200 Subject: [PATCH] consistent formatting in print-fetch. Fixes issue #77 --- src/script/print-fetch.lua | 98 +++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/script/print-fetch.lua b/src/script/print-fetch.lua index 8266480..420222a 100755 --- a/src/script/print-fetch.lua +++ b/src/script/print-fetch.lua @@ -1,13 +1,13 @@ #!/usr/bin/lua local function log(message) - os.execute("logger " .. message) - print(message) + os.execute("logger " .. message) + print(message) end if (table.getn(arg) == 0) then - print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]") - return + print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]") + return end log("starting gcode fetch program") @@ -19,8 +19,8 @@ local p3d = require("print3d") local printer = p3d.getPrinter(arg[1]) if printer == nil then - log("error connecting to printer") - return + log("error connecting to printer") + return end local gcodeServer = arg[2] @@ -35,8 +35,8 @@ log("gcode server: " .. gcodeServer) local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a")) if info == nil then - log("could not retrieve file info") - return + log("could not retrieve file info") + return end local current_line = 0 @@ -49,64 +49,64 @@ local startCode = nil local endCode = nil function countlines(file) - return tonumber(io.popen("wc -l < " .. file):read('*a')) + return tonumber(io.popen("wc -l < " .. file):read('*a')) end function readGCodeArg(argi) - local gcodeFile = arg[argi] - return io.open(gcodeFile):read('*a') + local gcodeFile = arg[argi] + return io.open(gcodeFile):read('*a') end if table.getn(arg) >= 5 then - startCode = readGCodeArg(4) - endCode = readGCodeArg(5) + startCode = readGCodeArg(4) + endCode = readGCodeArg(5) end if startCode ~= nil then - log("appending start gcode") - printer:appendGcode(startCode) + log("appending start gcode") + printer:appendGcode(startCode) end while(not finished) do - local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line) - local line = f:read() - while line ~= nil do - printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id }) - current_line = current_line + 1 - line = f:read() - end - - if not started then - started = true - print("send print start command") - printer:startPrint() - end - - if current_line >= total_lines then - log("finished fetching gcode") - if endCode ~= nil then - log("appending end gcode") - printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id }) + local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line) + local line = f:read() + while line ~= nil do + printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id }) + current_line = current_line + 1 + line = f:read() + end + + if not started then + started = true + print("send print start command") + printer:startPrint() + end + + if current_line >= total_lines then + log("finished fetching gcode") + if endCode ~= nil then + log("appending end gcode") + printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id }) + end + finished = true + break end - finished = true - break - end - local accepts_new_gcode = false + local accepts_new_gcode = false - while (not accepts_new_gcode) - do - local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress() - local percentageBufferSize = bufferSize / maxBufferSize + while (not accepts_new_gcode) + do + local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress() + local percentageBufferSize = bufferSize / maxBufferSize - if percentageBufferSize < 0.8 then - print("buffer below 80% capacity, sending new gcode") - accepts_new_gcode = true - else - print("buffer above 80% capacity") - os.execute("sleep 10") + if percentageBufferSize < 0.8 then + print("buffer below 80% capacity, sending new gcode") + accepts_new_gcode = true + else + print("buffer above 80% capacity") + os.execute("sleep 10") + end end - end end