0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 11:03:48 +01:00

Added usb highspeed info to API:info/status

This commit is contained in:
peteruithoven 2013-11-18 20:32:48 +01:00
parent 11c061c8ed
commit 00414bb67d
2 changed files with 32 additions and 12 deletions

View File

@ -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 accessManager = require('util.access') local accessManager = require('util.access')
local usb = require('util.usb')
local printDriver = require('print3d') local printDriver = require('print3d')
local printerUtils = require('util.printer') local printerUtils = require('util.printer')
local printerAPI = require('rest.api.api_printer') local printerAPI = require('rest.api.api_printer')
@ -114,17 +115,9 @@ end
function M.usb(request, response) function M.usb(request, response)
response:setSuccess() response:setSuccess()
local speed, highSpeed = usb.getInfo()
local file, error = io.open("/sys/devices/platform/ehci-platform/usb1/1-1/speed",'r') if speed ~= nil then
if file ~= nil then
local speed = file:read('*a')
file:close()
speed = tonumber(speed)
response:addData('speed', speed) response:addData('speed', speed)
-- check usb device speed
-- http://stackoverflow.com/questions/1957589/usb-port-speed-linux
local highSpeed = (speed == 480)
response:addData('highSpeed', highSpeed) response:addData('highSpeed', highSpeed)
end end
end end
@ -145,8 +138,11 @@ function M.status(request, response)
if(rv == false) then return end if(rv == false) then return end
rv = M.access(request, response) rv = M.access(request, response)
if(rv == false) then return end if(rv == false) then return end
local speed, highSpeed = usb.getInfo()
if speed ~= nil then
response:addData('usb_highSpeed', highSpeed)
end
end end
response:addData('v', 10)
end end
return M return M

24
src/util/usb.lua Normal file
View File

@ -0,0 +1,24 @@
local log = require('util.logger')
local utils = require('util.utils')
local M = {}
function M.getInfo()
local file, error = io.open("/sys/devices/platform/ehci-platform/usb1/1-1/speed",'r')
if file ~= nil then
local speed = file:read('*a')
file:close()
speed = tonumber(speed)
-- determine if high speed
-- http://stackoverflow.com/questions/1957589/usb-port-speed-linux
local highSpeed = (speed == 480)
return speed, highSpeed
else
return nil
end
end
return M