ff_uinput.lua (1400B)
1 local uinput = require("lib.uinput") 2 local decls = require("lib.ev_api.decls") 3 4 local u = uinput() 5 6 for k,v in pairs(decls.enums.FF) do 7 if type(k) == "number" and v ~= "MAX" then 8 u:set_ffbit(k) 9 end 10 end 11 12 u:set_evbit("KEY") 13 for k,v in ipairs{"BTN_SOUTH", "BTN_EAST", "BTN_NORTH", "BTN_WEST", 14 "BTN_TL", "BTN_TL2", "BTN_TR", "BTN_TR2", "BTN_SELECT", 15 "BTN_START", "BTN_MODE", "BTN_THUMBL", "BTN_THUMBR"} do 16 u:set_keybit(v) 17 end 18 19 u:set_evbit("ABS") 20 for _,v in ipairs{"X","Y","Z","RX","RY","RZ","HAT0X","HAT0Y"} do 21 u:abs_setup(v, {maximum=255}) 22 end 23 24 u:setup{ 25 -- note: wine won't detect FF unless you enter a valid id of a real life 26 -- controller, because joystick handling in wine is utterly completely broken 27 -- since the hid rewrite 28 --id={bustype="BLUETOOTH", vendor=0x54c, product=0x9cc, version=0x8100}, 29 id={bustype="BLUETOOTH"}, 30 name="Test Controller", 31 ff_effects_max=16, 32 } 33 u:create() 34 print("created", u.sysname) 35 36 while true do 37 local ev = u:read() 38 print("event", ev) 39 40 if ev.type == "UINPUT" then 41 local code = ev.code 42 if code == "FF_UPLOAD" then 43 local x = u:begin_ff_upload(ev) 44 print("upload", x) 45 x.retval = 0 46 u:end_ff_upload(x) 47 elseif code == "FF_ERASE" then 48 local x = u:begin_ff_erase(ev) 49 print("erase", x) 50 x.retval = 0 51 u:end_ff_erase(x) 52 end 53 end 54 end 55 56 u:destroy() 57 u = nil