mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Initial API replacement to use new printer driver (limited functionality).
This commit is contained in:
parent
c1fa030b97
commit
8a7162330b
@ -2,6 +2,7 @@ local lfs = require('lfs')
|
|||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local settings = require('util.settings')
|
local settings = require('util.settings')
|
||||||
|
local printDriver = require('print3d')
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
isApi = true
|
isApi = true
|
||||||
@ -14,21 +15,29 @@ local PROGRESS_FILE = 'progress2.out'
|
|||||||
local COMMAND_FILE = 'command.in'
|
local COMMAND_FILE = 'command.in'
|
||||||
local GCODE_TMP_FILE = 'combined.gc'
|
local GCODE_TMP_FILE = 'combined.gc'
|
||||||
|
|
||||||
-- returns full path + ultifi path or nil
|
|
||||||
local function printerExists(id)
|
|
||||||
if id == nil then return nil end
|
|
||||||
|
|
||||||
local path = '/dev/ttyACM' .. id
|
|
||||||
local upath = ULTIFI_BASE_PATH .. '/ttyACM' .. id
|
|
||||||
if utils.exists(path) then return path,upath end
|
|
||||||
|
|
||||||
path = '/dev/ttyUSB' .. id
|
--NEW
|
||||||
upath = ULTIFI_BASE_PATH .. '/ttyUSB' .. id
|
--returns a printer instance or nil (and sets error state on response in the latter case)
|
||||||
if utils.exists(path) then return path,upath end
|
local function createPrinterOrFail(deviceId, response)
|
||||||
|
local msg,printer = nil, nil
|
||||||
|
|
||||||
return nil
|
if deviceId and deviceId ~= "" then
|
||||||
|
printer,msg = printDriver.getPrinter(deviceId)
|
||||||
|
else
|
||||||
|
msg = "missing device ID"
|
||||||
|
end
|
||||||
|
|
||||||
|
if not printer then
|
||||||
|
response:setError("could not open printer driver (" .. msg .. ")")
|
||||||
|
response:addData('id', deviceId)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return printer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- returns printerId,devicePath,ultifiPath or nil if printer does not exist
|
-- returns printerId,devicePath,ultifiPath or nil if printer does not exist
|
||||||
-- when nil is returned, response has already been set as an error
|
-- when nil is returned, response has already been set as an error
|
||||||
local function getPrinterDataOrFail(request, response)
|
local function getPrinterDataOrFail(request, response)
|
||||||
@ -50,6 +59,23 @@ local function getPrinterDataOrFail(request, response)
|
|||||||
return id,devpath,ultipath
|
return id,devpath,ultipath
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- returns full path + ultifi path or nil
|
||||||
|
local function printerExists(id)
|
||||||
|
if id == nil then return nil end
|
||||||
|
|
||||||
|
local path = '/dev/ttyACM' .. id
|
||||||
|
local upath = ULTIFI_BASE_PATH .. '/ttyACM' .. id
|
||||||
|
if utils.exists(path) then return path,upath end
|
||||||
|
|
||||||
|
path = '/dev/ttyUSB' .. id
|
||||||
|
upath = ULTIFI_BASE_PATH .. '/ttyUSB' .. id
|
||||||
|
if utils.exists(path) then return path,upath end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- assumes printerPath exists, returns true if successful, false if command file already exists and is non-empty (i.e. printer busy),
|
-- assumes printerPath exists, returns true if successful, false if command file already exists and is non-empty (i.e. printer busy),
|
||||||
-- nil+err if file could not be opened
|
-- nil+err if file could not be opened
|
||||||
local function sendGcode(printerPath, gcode)
|
local function sendGcode(printerPath, gcode)
|
||||||
@ -137,48 +163,22 @@ function M._global(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--requires id(int)
|
--requires id(int)
|
||||||
--accepts with_raw(bool) to include raw printer response
|
--accepts with_raw(bool) to include raw printer response (currently not implemented)
|
||||||
function M.temperature(request, response)
|
function M.temperature(request, response)
|
||||||
local withRaw = utils.toboolean(request:get("with_raw"))
|
local argId = request:get("id")
|
||||||
|
local printer,msg = createPrinterOrFail(argId, response)
|
||||||
local argId,devpath,ultipath = getPrinterDataOrFail(request, response)
|
if not printer then return end
|
||||||
if argId == nil then return end
|
|
||||||
|
|
||||||
local f = io.open(ultipath .. '/' .. TEMPERATURE_FILE)
|
|
||||||
|
|
||||||
if not f then
|
|
||||||
response:setError("could not open temperature file")
|
|
||||||
response:addData('id', argId)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local tempText = f:read('*all')
|
|
||||||
f:close()
|
|
||||||
|
|
||||||
local hotend, hotendTarget, bed, bedTarget = tempText:match('T:(.*)%s+/(.*)%s+B:(.*)%s/(.*)%s+@.*')
|
|
||||||
|
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
if withRaw then response:addData('raw', tempText) end
|
response:addData('id', argId)
|
||||||
|
response:addData('hotend', printer:getTemperature())
|
||||||
-- After pressing print it waits until it's at the right temperature.
|
|
||||||
-- it then stores temperature in the following format
|
|
||||||
-- T:204.5 E:0 W:?
|
|
||||||
if(hotend == nil) then
|
|
||||||
local hotend = tempText:match('T:([%d%.]*).*')
|
|
||||||
response:addData('hotend', hotend)
|
|
||||||
else
|
|
||||||
response:addData('hotend', hotend)
|
|
||||||
response:addData('bed', bed)
|
|
||||||
response:addData('hotend_target', hotendTarget)
|
|
||||||
response:addData('bed_target', bedTarget)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get last modified time
|
|
||||||
local file_attr = lfs.attributes(ultipath .. '/' .. TEMPERATURE_FILE)
|
|
||||||
local last_mod = file_attr.modification
|
|
||||||
local last_mod = os.difftime (os.time(),last_mod)
|
|
||||||
response:addData('last_mod', last_mod)
|
|
||||||
|
|
||||||
|
-- TODO: reimplement the following fields
|
||||||
|
-- if withRaw then response:addData('raw', tempText) end
|
||||||
|
-- response:addData('bed', printer:getBedTemperature())
|
||||||
|
-- response:addData('hotend_target', printer:getHotendTargetTemperature())
|
||||||
|
-- response:addData('bed_target', printer:getBedTargetTemperature())
|
||||||
|
-- response:addData('last_mod', printer:getLastTemperatureUpdate())
|
||||||
end
|
end
|
||||||
|
|
||||||
--requires id(int)
|
--requires id(int)
|
||||||
|
Loading…
Reference in New Issue
Block a user