Skip to content

Commit

Permalink
consistent formatting in print-fetch. Fixes issue #77
Browse files Browse the repository at this point in the history
  • Loading branch information
mith committed Jul 6, 2017
1 parent db259bb commit c536fe3
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions src/script/print-fetch.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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

0 comments on commit c536fe3

Please sign in to comment.