You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB
Lua

local uinput = require("lib.uinput")
local decls = require("lib.ev_api.decls")
local u = uinput()
for k,v in pairs(decls.enums.FF) do
if type(k) == "number" and v ~= "MAX" then
u:set_ffbit(k)
end
end
u:set_evbit("KEY")
for k,v in ipairs{"BTN_SOUTH", "BTN_EAST", "BTN_NORTH", "BTN_WEST",
"BTN_TL", "BTN_TL2", "BTN_TR", "BTN_TR2", "BTN_SELECT",
"BTN_START", "BTN_MODE", "BTN_THUMBL", "BTN_THUMBR"} do
u:set_keybit(v)
end
u:set_evbit("ABS")
for _,v in ipairs{"X","Y","Z","RX","RY","RZ","HAT0X","HAT0Y"} do
u:abs_setup(v, {maximum=255})
end
u:setup{
-- note: wine won't detect FF unless you enter a valid id of a real life
-- controller, because joystick handling in wine is utterly completely broken
-- since the hid rewrite
--id={bustype="BLUETOOTH", vendor=0x54c, product=0x9cc, version=0x8100},
id={bustype="BLUETOOTH"},
name="Test Controller",
ff_effects_max=16,
}
u:create()
print("created", u.sysname)
while true do
local ev = u:read()
print("event", ev)
if ev.type == "UINPUT" then
local code = ev.code
if code == "FF_UPLOAD" then
local x = u:begin_ff_upload(ev)
print("upload", x)
x.retval = 0
u:end_ff_upload(x)
elseif code == "FF_ERASE" then
local x = u:begin_ff_erase(ev)
print("erase", x)
x.retval = 0
u:end_ff_erase(x)
end
end
end
u:destroy()
u = nil