Initial work on create/uinput tests.

This commit is contained in:
Merlijn Wajer 2013-04-19 01:11:56 +02:00
parent 1bddfc11ad
commit b6c5b6bee1
3 changed files with 83 additions and 4 deletions

79
py/create.py Normal file
View File

@ -0,0 +1,79 @@
import cinput, linux_uinput, ctypes, fcntl
def open_uinput():
try:
f = open('/dev/uinput', 'w+')
except IOError:
try:
f = open('/dev/input/uinput', 'w+')
except IOError:
print 'FAIL MUCH?'
return None
return f
def handle_specs(f, s):
print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_SET_EVBIT, cinput.EV_KEY)
print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_SET_KEYBIT, cinput.KEY_UP)
def create_device(specs):
f = open_uinput()
if not f:
print 'Failed to open uinput'
return None
# Add keys, etc
handle_specs(f, specs)
# Allocate other info
# TODO:
# * Make sure the uidev structure is correct
# * Make sure that we are setting the values in the structure
# * Make sure the value is properly written to 'f'
uidev = linux_uinput.uinput_user_dev()
uidev.name = 'key2joy\0'
uidev._id.bustype = 0x03 # BUS_USB (TODO)
uidev._id.vendor = 0x42
uidev._id.product = 0xBEBE
uidev._id.product = 1
buf = buffer(uidev)[:]
print repr(buf)
# Write dev info
f.write(buf)
print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_DEV_CREATE)
return f
create_device(None)
print 'Hoi'
import time
time.sleep(5)
# config
#dev = {
# "input_devices" : [
# ("/dev/input/event3", "keyboard1"),
# ],
# "type" : "mouse", # "mixed" "mouse" "keyboard" "joystick" "clone"?
# "keymap" : {
# "any" : { # From
# EV_KEY : {
# KEY_UP : {
# "type" : EV_REL
# "key" : REL_X
# "value" : lambda x: -x*10
# }
# KEY_DOWN : {
# "type": EV_REL
# "key": REL_X
# "value" : lambda x: x*10
# }
# }
# },
# }
#}

View File

@ -35,17 +35,17 @@ EV_UINPUT = 0x0101
UI_FF_UPLOAD = 1 UI_FF_UPLOAD = 1
UI_FF_ERASE = 2 UI_FF_ERASE = 2
import ctypes import ctypes
UINPUT_MAX_NAME_SIZE = 80 UINPUT_MAX_NAME_SIZE = 80
class uinput_user_dev(ctypes.Structure): class uinput_user_dev(ctypes.Structure):
_fields_ = [ _fields_ = [
("name", ctypes.c_char * UINPUT_MAX_NAME_SIZE), ("name", ctypes.c_char * UINPUT_MAX_NAME_SIZE),
("id", linux_input.input_id), ("_id", linux_input.input_id),
("ff_effects_max", ctypes.c_uint32), ("ff_effects_max", ctypes.c_uint32),
("absmax", ctypes.c_int32), ("absmax", ctypes.c_int32),
("absmin", ctypes.c_int32), ("absmin", ctypes.c_int32),
("absfuzz", ctypes.c_int32), ("absfuzz", ctypes.c_int32),
("absflac", ctypes.c_int32) ("absflac", ctypes.c_int32)
] ]