mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
consistent formatting in print-fetch. Fixes issue #77
This commit is contained in:
parent
db259bbfc6
commit
c536fe3221
@ -1,13 +1,13 @@
|
|||||||
#!/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
|
||||||
|
|
||||||
if (table.getn(arg) == 0) then
|
if (table.getn(arg) == 0) then
|
||||||
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
log("starting gcode fetch program")
|
log("starting gcode fetch program")
|
||||||
@ -19,8 +19,8 @@ local p3d = require("print3d")
|
|||||||
|
|
||||||
local printer = p3d.getPrinter(arg[1])
|
local printer = p3d.getPrinter(arg[1])
|
||||||
if printer == nil then
|
if printer == nil then
|
||||||
log("error connecting to printer")
|
log("error connecting to printer")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local gcodeServer = arg[2]
|
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"))
|
local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a"))
|
||||||
|
|
||||||
if info == nil then
|
if info == nil then
|
||||||
log("could not retrieve file info")
|
log("could not retrieve file info")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local current_line = 0
|
local current_line = 0
|
||||||
@ -49,64 +49,64 @@ local startCode = nil
|
|||||||
local endCode = nil
|
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'))
|
||||||
end
|
end
|
||||||
|
|
||||||
function readGCodeArg(argi)
|
function readGCodeArg(argi)
|
||||||
local gcodeFile = arg[argi]
|
local gcodeFile = arg[argi]
|
||||||
return io.open(gcodeFile):read('*a')
|
return io.open(gcodeFile):read('*a')
|
||||||
end
|
end
|
||||||
|
|
||||||
if table.getn(arg) >= 5 then
|
if table.getn(arg) >= 5 then
|
||||||
startCode = readGCodeArg(4)
|
startCode = readGCodeArg(4)
|
||||||
endCode = readGCodeArg(5)
|
endCode = readGCodeArg(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
if startCode ~= nil then
|
if startCode ~= nil then
|
||||||
log("appending start gcode")
|
log("appending start gcode")
|
||||||
printer:appendGcode(startCode)
|
printer:appendGcode(startCode)
|
||||||
end
|
end
|
||||||
|
|
||||||
while(not finished)
|
while(not finished)
|
||||||
do
|
do
|
||||||
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
|
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
|
||||||
local line = f:read()
|
local line = f:read()
|
||||||
while line ~= nil do
|
while line ~= nil do
|
||||||
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||||
current_line = current_line + 1
|
current_line = current_line + 1
|
||||||
line = f:read()
|
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
|
end
|
||||||
finished = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if not started then
|
||||||
local accepts_new_gcode = false
|
started = true
|
||||||
|
print("send print start command")
|
||||||
while (not accepts_new_gcode)
|
printer:startPrint()
|
||||||
do
|
end
|
||||||
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
|
|
||||||
local percentageBufferSize = bufferSize / maxBufferSize
|
if current_line >= total_lines then
|
||||||
|
log("finished fetching gcode")
|
||||||
if percentageBufferSize < 0.8 then
|
if endCode ~= nil then
|
||||||
print("buffer below 80% capacity, sending new gcode")
|
log("appending end gcode")
|
||||||
accepts_new_gcode = true
|
printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
||||||
else
|
end
|
||||||
print("buffer above 80% capacity")
|
finished = true
|
||||||
os.execute("sleep 10")
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local accepts_new_gcode = false
|
||||||
|
|
||||||
|
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")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user