call print start before finishing fetch loop

This commit is contained in:
Simon Voordouw 2017-06-13 13:04:09 +02:00
parent 533988a409
commit 97fb6609ea
1 changed files with 18 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/lua #!/usr/bin/lua
local function log(message) local function log(message)
os.execute("logger" .. message) os.execute("logger " .. message)
print(message) print(message)
end end
@ -35,8 +35,8 @@ local started = false
log("total lines: " .. total_lines) log("total lines: " .. total_lines)
local startCode = '' local startCode = nil
local endCode = '' local endCode = nil
function countlines(file) function countlines(file)
return tonumber(io.popen("wc -l < " .. file):read('*a')) return tonumber(io.popen("wc -l < " .. file):read('*a'))
@ -53,7 +53,10 @@ if table.getn(arg) >= 5 then
endCode = readGCodeArg(5) endCode = readGCodeArg(5)
end end
printer:appendGcode(startCode) if startCode ~= nil then
log("appending start gcode")
printer:appendGcode(startCode)
end
while(not finished) while(not finished)
do do
@ -64,11 +67,6 @@ do
current_line = current_line + 1 current_line = current_line + 1
line = f:read() line = f:read()
end end
if current_line >= total_lines then
printer:appendGcode(endCode)
finished = true
break
end
if not started then if not started then
started = true started = true
@ -76,6 +74,17 @@ do
printer:startPrint() printer:startPrint()
end end
if current_line >= total_lines then
log("finished fetching gcode")
if endCode ~= nil then
log("appending end gcode")
printer:appendGcode(endCode)
end
finished = true
break
end
local accepts_new_gcode = false local accepts_new_gcode = false
while (not accepts_new_gcode) while (not accepts_new_gcode)