mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Adding progress to rest api
This commit is contained in:
parent
ba1ca3e322
commit
633fc86551
@ -10,6 +10,7 @@ local M = {
|
|||||||
|
|
||||||
local ULTIFI_BASE_PATH = '/tmp/UltiFi'
|
local ULTIFI_BASE_PATH = '/tmp/UltiFi'
|
||||||
local TEMPERATURE_FILE = 'temp.out'
|
local TEMPERATURE_FILE = 'temp.out'
|
||||||
|
local PROGRESS_FILE = 'progress2.out'
|
||||||
local COMMAND_FILE = 'command.in'
|
local COMMAND_FILE = 'command.in'
|
||||||
local GCODE_TMP_FILE = '/tmp/UltiFi/combined.gc'
|
local GCODE_TMP_FILE = '/tmp/UltiFi/combined.gc'
|
||||||
|
|
||||||
@ -177,6 +178,42 @@ function M.temperature(request, response)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--requires id(int)
|
||||||
|
function M.progress(request, response)
|
||||||
|
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
||||||
|
if argId == nil then return end
|
||||||
|
|
||||||
|
local f = io.open(ultipath .. '/' .. PROGRESS_FILE)
|
||||||
|
|
||||||
|
if not f then
|
||||||
|
response:setError("could not open progress file")
|
||||||
|
response:addData('id', argId)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local tempText = f:read('*all')
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
local currentLine,numLines = tempText:match('(%d+)/(%d+)')
|
||||||
|
|
||||||
|
response:setSuccess()
|
||||||
|
|
||||||
|
if(currentLine == nil) then
|
||||||
|
response:addData('printing', false)
|
||||||
|
else
|
||||||
|
response:addData('printing', true)
|
||||||
|
response:addData('current_line', currentLine)
|
||||||
|
response:addData('num_lines', numLines)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get last modified time
|
||||||
|
local file_attr = lfs.attributes(ultipath .. '/' .. PROGRESS_FILE)
|
||||||
|
local last_mod = file_attr.modification
|
||||||
|
local last_mod = os.difftime (os.time(),last_mod)
|
||||||
|
response:addData('last_mod', last_mod)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
--requires id(int)
|
--requires id(int)
|
||||||
function M.busy(request, response)
|
function M.busy(request, response)
|
||||||
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
||||||
|
Loading…
Reference in New Issue
Block a user