From 00414bb67daf3ec98e630b1738c7d93f7c55b8d2 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 18 Nov 2013 20:32:48 +0100 Subject: [PATCH] Added usb highspeed info to API:info/status --- src/rest/api/api_info.lua | 20 ++++++++------------ src/util/usb.lua | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 src/util/usb.lua diff --git a/src/rest/api/api_info.lua b/src/rest/api/api_info.lua index b824215..e6b7873 100644 --- a/src/rest/api/api_info.lua +++ b/src/rest/api/api_info.lua @@ -2,6 +2,7 @@ local lfs = require('lfs') local log = require('util.logger') local utils = require('util.utils') local accessManager = require('util.access') +local usb = require('util.usb') local printDriver = require('print3d') local printerUtils = require('util.printer') local printerAPI = require('rest.api.api_printer') @@ -106,7 +107,7 @@ function M.access(request, response) local hasControl = accessManager.hasControl(request.remoteAddress) response:setSuccess() - response:addData('has_control', hasControl) + response:addData('has_control', hasControl) return true end @@ -114,17 +115,9 @@ end function M.usb(request, response) response:setSuccess() - - 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) + local speed, highSpeed = usb.getInfo() + if speed ~= nil then 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) end end @@ -145,8 +138,11 @@ function M.status(request, response) if(rv == false) then return end rv = M.access(request, response) if(rv == false) then return end + local speed, highSpeed = usb.getInfo() + if speed ~= nil then + response:addData('usb_highSpeed', highSpeed) + end end - response:addData('v', 10) end return M diff --git a/src/util/usb.lua b/src/util/usb.lua new file mode 100644 index 0000000..9128e7a --- /dev/null +++ b/src/util/usb.lua @@ -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