Commits

Jérôme Vuarand  committed 54cfaae

Made the demo compatible with Lua 5.2.

  • Participants
  • Parent commits 7bad2ca

Comments (0)

Files changed (2)

 
 local usb = require 'usb'
 local names = require 'names'
-local bit = require 'bit'
+local bit
+if _VERSION == 'Lua 5.2' then
+	bit = require 'bit32'
+elseif _VERSION == 'Lua 5.1' then
+	bit = require 'bit'
+else
+	error("unsupported Lua version")
+end
 local serial = require 'serial'
 require 'serial.util'
 --require 'util'
 local typeattr = { "Control", "Isochronous", "Bulk", "Interrupt" }
 local syncattr = { "None", "Asynchronous", "Adaptive", "Synchronous" }
 local usage = { "Data", "Feedback", "Implicit feedback Data", "(reserved)" }
-local hb = { "1x", "2x", "3x", "(?\?)" }
+local hb = { "1x", "2x", "3x", "(??)" }
 
 local function dump_endpoint(dev, interface, endpoint)
 	local wmax = le16_to_cpu(endpoint.wMaxPacketSize)

File demo/names.lua

-module(..., package.seeall)
+local _M = {}
 
-physdes = {}
-bias = {}
-langid = {}
-class = {}
-audioterminal = {}
-videoterminal = {}
-countrycode = {}
-vendor = {}
-product = {}
-subclass = {}
-protocol = {}
-hid = {}
-reporttag = {}
-huts = {}
-hutus = {}
+local io = require 'io'
+
+_M.physdes = {}
+_M.bias = {}
+_M.langid = {}
+_M.class = {}
+_M.audioterminal = {}
+_M.videoterminal = {}
+_M.countrycode = {}
+_M.vendor = {}
+_M.product = {}
+_M.subclass = {}
+_M.protocol = {}
+_M.hid = {}
+_M.reporttag = {}
+_M.huts = {}
+_M.hutus = {}
 
 local function parse(f)
 	local linectr = 0
 				local u,cp = buf:match('^PHYSDES%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid PHYSDES type at line "..linectr)
-				physdes[u] = cp
+				_M.physdes[u] = cp
 
 			elseif buf:match('^PHY%s+') then
 				local u,cp = buf:match('^PHY%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid PHY type at line "..linectr)
-				physdes[u] = cp
+				_M.physdes[u] = cp
 
 			elseif buf:match('^BIAS%s+') then
 				local u,cp = buf:match('^BIAS%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid BIAS type at line "..linectr)
-				bias[u] = cp
+				_M.bias[u] = cp
 
 			elseif buf:match('^L%s+') then
 				local u,cp = buf:match('^L%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid L type at line "..linectr)
-				langid[u] = cp
+				_M.langid[u] = cp
 				lasthut,lastclass,lastvendor,lastsubclass = nil
 				lastlang = u
 
 				local u,cp = buf:match('^C%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid C type at line "..linectr)
-				class[u] = cp
+				_M.class[u] = cp
 				lasthut,lastlang,lastvendor,lastsubclass = nil
 				lastclass = u
 
 				local u,cp = buf:match('^AT%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid AT type at line "..linectr)
-				audioterminal[u] = cp
+				_M.audioterminal[u] = cp
 
 			elseif buf:match('^VT%s+') then
 				local u,cp = buf:match('^VT%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid VT type at line "..linectr)
-				videoterminal[u] = cp
+				_M.videoterminal[u] = cp
 
 			elseif buf:match('^HCC%s+') then
 				local u,cp = buf:match('^HCC%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid HCC type at line "..linectr)
-				countrycode[u] = cp
+				_M.countrycode[u] = cp
 
 			elseif buf:match('^%x') then
 				local u,cp = buf:match('^(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid vendor spec at line "..linectr)
-				vendor[u] = cp
+				_M.vendor[u] = cp
 				lastvendor = u
 				lasthut,lastlang,lastclass,lastsubclass = nil
 
 				assert(u and cp, "Invalid product/subclass spec at line "..linectr)
 				
 				if lastvendor then
-					product[lastvendor] = product[lastvendor] or {}
-					product[lastvendor][u] = cp
+					_M.product[lastvendor] = _M.product[lastvendor] or {}
+					_M.product[lastvendor][u] = cp
 				elseif lastclass then
-					subclass[lastclass] = subclass[lastclass] or {}
-					subclass[lastclass][u] = cp
+					_M.subclass[lastclass] = _M.subclass[lastclass] or {}
+					_M.subclass[lastclass][u] = cp
 					lastsubclass = u
 				elseif lasthut then
-					hutus[lasthut * 2^16 + u] = cp
+					_M.hutus[lasthut * 2^16 + u] = cp
 				elseif lastlang then
-					langid[lastlang * 2^10 + u] = cp
+					_M.langid[lastlang * 2^10 + u] = cp
 				else
 					error("Product/Subclass spec without prior Vendor/Class spec at line "..linectr)
 				end
 				assert(u and cp, "Invalid protocol spec at line "..linectr)
 
 				if lastclass and lastsubclass then
-					protocol[lastclass] = protocol[lastclass] or {}
-					protocol[lastclass][lastsubclass] = protocol[lastclass][lastsubclass] or {}
-					protocol[lastclass][lastsubclass][u] = cp
+					_M.protocol[lastclass] = _M.protocol[lastclass] or {}
+					_M.protocol[lastclass][lastsubclass] = _M.protocol[lastclass][lastsubclass] or {}
+					_M.protocol[lastclass][lastsubclass][u] = cp
 				end
 
 			elseif buf:match('^HID%s') then
 				local u,cp = buf:match('^HID%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid HID type at line "..linectr)
-				hid[u] = cp
+				_M.hid[u] = cp
 
 			elseif buf:match('^HUT%s') then
 				local u,cp = buf:match('^HUT%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid HUT type at line "..linectr)
-				huts[u] = cp
+				_M.huts[u] = cp
 				lastlang,lastclass,lastvendor,lastsubclass = nil
 				lasthut = u
 
 				local u,cp = buf:match('^R%s+(%x+)%s+(.*)$')
 				u = u and tonumber(u, 16)
 				assert(u and cp, "Invalid R type at line "..linectr)
-				reporttag[u] = cp
+				_M.reporttag[u] = cp
 
 			else
 				error("Unknown line at line "..linectr)
 	end
 end
 
-function init(n)
+function _M.init(n)
 	local f = assert(io.open(n, "r"))
 	parse(f)
 	f:close()
 end
 
+return _M