Skip to content

Commit c536fe3

Browse files
committed
consistent formatting in print-fetch. Fixes issue #77
1 parent db259bb commit c536fe3

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

src/script/print-fetch.lua

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/lua
22

33
local function log(message)
4-
os.execute("logger " .. message)
5-
print(message)
4+
os.execute("logger " .. message)
5+
print(message)
66
end
77

88
if (table.getn(arg) == 0) then
9-
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
10-
return
9+
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
10+
return
1111
end
1212

1313
log("starting gcode fetch program")
@@ -19,8 +19,8 @@ local p3d = require("print3d")
1919

2020
local printer = p3d.getPrinter(arg[1])
2121
if printer == nil then
22-
log("error connecting to printer")
23-
return
22+
log("error connecting to printer")
23+
return
2424
end
2525

2626
local gcodeServer = arg[2]
@@ -35,8 +35,8 @@ log("gcode server: " .. gcodeServer)
3535
local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a"))
3636

3737
if info == nil then
38-
log("could not retrieve file info")
39-
return
38+
log("could not retrieve file info")
39+
return
4040
end
4141

4242
local current_line = 0
@@ -49,64 +49,64 @@ local startCode = nil
4949
local endCode = nil
5050

5151
function countlines(file)
52-
return tonumber(io.popen("wc -l < " .. file):read('*a'))
52+
return tonumber(io.popen("wc -l < " .. file):read('*a'))
5353
end
5454

5555
function readGCodeArg(argi)
56-
local gcodeFile = arg[argi]
57-
return io.open(gcodeFile):read('*a')
56+
local gcodeFile = arg[argi]
57+
return io.open(gcodeFile):read('*a')
5858
end
5959

6060
if table.getn(arg) >= 5 then
61-
startCode = readGCodeArg(4)
62-
endCode = readGCodeArg(5)
61+
startCode = readGCodeArg(4)
62+
endCode = readGCodeArg(5)
6363
end
6464

6565
if startCode ~= nil then
66-
log("appending start gcode")
67-
printer:appendGcode(startCode)
66+
log("appending start gcode")
67+
printer:appendGcode(startCode)
6868
end
6969

7070
while(not finished)
7171
do
72-
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
73-
local line = f:read()
74-
while line ~= nil do
75-
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
76-
current_line = current_line + 1
77-
line = f:read()
78-
end
79-
80-
if not started then
81-
started = true
82-
print("send print start command")
83-
printer:startPrint()
84-
end
85-
86-
if current_line >= total_lines then
87-
log("finished fetching gcode")
88-
if endCode ~= nil then
89-
log("appending end gcode")
90-
printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id })
72+
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
73+
local line = f:read()
74+
while line ~= nil do
75+
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
76+
current_line = current_line + 1
77+
line = f:read()
78+
end
79+
80+
if not started then
81+
started = true
82+
print("send print start command")
83+
printer:startPrint()
84+
end
85+
86+
if current_line >= total_lines then
87+
log("finished fetching gcode")
88+
if endCode ~= nil then
89+
log("appending end gcode")
90+
printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id })
91+
end
92+
finished = true
93+
break
9194
end
92-
finished = true
93-
break
94-
end
9595

9696

97-
local accepts_new_gcode = false
97+
local accepts_new_gcode = false
9898

99-
while (not accepts_new_gcode)
100-
do
101-
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
102-
local percentageBufferSize = bufferSize / maxBufferSize
99+
while (not accepts_new_gcode)
100+
do
101+
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
102+
local percentageBufferSize = bufferSize / maxBufferSize
103103

104-
if percentageBufferSize < 0.8 then
105-
print("buffer below 80% capacity, sending new gcode")
106-
accepts_new_gcode = true
107-
else
108-
print("buffer above 80% capacity")
109-
os.execute("sleep 10")
104+
if percentageBufferSize < 0.8 then
105+
print("buffer below 80% capacity, sending new gcode")
106+
accepts_new_gcode = true
107+
else
108+
print("buffer above 80% capacity")
109+
os.execute("sleep 10")
110+
end
110111
end
111-
end
112112
end

0 commit comments

Comments
 (0)