Skip to contentSkip to conversation

uinput: How to use force feedback?

DISCUSSION Manuel Reimer 4 participants 8 messages Jan 17, 2016 – Feb 15, 2016 HID

lore
Share & tools
lore
#0 lore raw

Hello,

I have an existing uinput driver, which itself sits on an open device with a blocking read(), waiting for events to come in. Every event is translated to a key code and then sent to uinput.

My next step would be to pass through force feedback information, but I don't really understand how I should do this.

As far as I can see, the "uninput device" itself sends events in this case. But my main loop is already blocked by the "read", I use to get device events.

I see two possible solutions:
- "Somehow", I should be able to get "blocking read" from two open devices. As far as I found out, so far, "select" should be the right command to do this?
- I could start two threads. One blocked by the "device events" and one by the "uinput events".

Which one would you recommend? Is uinput/ioctl thread safe? Is the second thread a good idea or is the communication, coming from uinput, such "low traffic", that it doesn't delay key handling in a relevant way?

Thank you very much in advance

Manuel

#1 lore raw
Quoted 8 lines · Manuel Reimer

Hello,

I have an existing uinput driver, which itself sits on an open device with a blocking read(), waiting for events to come in. Every event is translated to a key code and then sent to uinput.

My next step would be to pass through force feedback information, but I don't really understand how I should do this.

Concerning this,
the following may give you an example how to read incoming FF events on uinput:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

A good while ago I started working on FF support for
the uinput user-space library libsuinput, (and also for python-uinput,) but I have to clean up some things before I can merge it to:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

Thanks,
Elias

#2 lore raw
Quoted 11 lines · Elias Vanderstuyft
Quoted 8 lines · Manuel Reimer

Hello,

I have an existing uinput driver, which itself sits on an open device with a blocking read(), waiting for events to come in. Every event is translated to a key code and then sent to uinput.

My next step would be to pass through force feedback information, but I don't really understand how I should do this.

Quoted 8 lines

Concerning this,
the following may give you an example how to read incoming FF events on uinput:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

A good while ago I started working on FF support for
the uinput user-space library libsuinput, (and also for python-uinput,) but I have to clean up some things before I can merge it to:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

Sorry for the typo, here is the correct link:
https://github.com/tuomasjjrasanen/python-uinput/tree/master/libsuinput

#3 lore raw
In reply to Elias Vanderstuyft
Quoted 6 lines · Elias Vanderstuyft

A good while ago I started working on FF support for
the uinput user-space library libsuinput, (and also for python-uinput,) but I have to clean up some things before I can merge it to:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

Patches are more than welcome! (I'm the author of libsuinput, happy to see someone actually uses it without python-uinput, but I welcome patches to python-uinput as well).

Signature · 1 line
Tuomas
#4 lore raw
In reply to Elias Vanderstuyft
Quoted 3 lines · Elias Vanderstuyft

Concerning this,
the following may give you an example how to read incoming FF events on uinput:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

Tried that and I'm pretty close to giving up...

I've added the following to my uinput init function:

// Set up force feedback parameters
ret = ioctl(fd, UI_SET_EVBIT, EV_FF);

  ret = ioctl(fd, UI_SET_FFBIT, FF_PERIODIC);
  ret = ioctl(fd, UI_SET_FFBIT, FF_RUMBLE);
  ret = ioctl(fd, UI_SET_FFBIT, FF_GAIN);
  ret = ioctl(fd, UI_SET_FFBIT, FF_SQUARE);
  ret = ioctl(fd, UI_SET_FFBIT, FF_TRIANGLE);
  ret = ioctl(fd, UI_SET_FFBIT, FF_SINE);

From my device handling thread, I'm starting a separate thread to handle the opposite direction of communication. Plan is to do blocking read from the open uinput device. I open the device with O_RDWR to be able to read and write. The "rumble thread" starts with:

  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

struct input_event event;

  while (1) {
    ssize_t n = read(args->fduinput, &event, sizeof(event));
    printf("n: %d\n", n);

Everything beyond this never executes. The read blocks forever.

And even worse: If the read blocks, my "driver", and all programs connected to my input device, are deadlocked. No chance to kill them.

And to be honest: After three hours of debugging I'm kind of sick of rebooting my machine over and over again.

Any chance to get some hint?

Thanks in advance

Manuel

#5 lore raw

Hello,

I just want to add here, that I found the reason for this problem.

It is required that the ff_effects_max field of the uinput_user_dev struct is set. Without doing this everything just hangs...

Best regards,

Manuel

Quoted 54 lines · Manuel Reimer
Quoted 5 lines · Elias Vanderstuyft

Concerning this,
the following may give you an example how to read incoming FF events on uinput:
https://github.com/xboxdrv/xboxdrv/blob/8e9fb6b40df568d4e4af63e80518366ee4aa5fd3/src/linux_uinput.cpp#L341

Tried that and I'm pretty close to giving up...

I've added the following to my uinput init function:

   // Set up force feedback parameters
   ret = ioctl(fd, UI_SET_EVBIT, EV_FF);

   ret = ioctl(fd, UI_SET_FFBIT, FF_PERIODIC);
   ret = ioctl(fd, UI_SET_FFBIT, FF_RUMBLE);
   ret = ioctl(fd, UI_SET_FFBIT, FF_GAIN);
   ret = ioctl(fd, UI_SET_FFBIT, FF_SQUARE);
   ret = ioctl(fd, UI_SET_FFBIT, FF_TRIANGLE);
   ret = ioctl(fd, UI_SET_FFBIT, FF_SINE);

From my device handling thread, I'm starting a separate thread to
handle the opposite direction of communication. Plan is to do blocking read from the open uinput device. I open the device with O_RDWR to be able to read and write. The "rumble thread" starts with:

   pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
   struct input_event event;

   while (1) {
     ssize_t n = read(args->fduinput, &event, sizeof(event));
     printf("n: %d\n", n);

Everything beyond this never executes. The read blocks forever.

And even worse: If the read blocks, my "driver", and all programs connected to my input device, are deadlocked. No chance to kill them.

And to be honest: After three hours of debugging I'm kind of sick of rebooting my machine over and over again.

Any chance to get some hint?

Thanks in advance

Manuel

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 6 lines · Manuel Reimer

Hello,

I just want to add here, that I found the reason for this problem.

It is required that the ff_effects_max field of the uinput_user_dev struct is set. Without doing this everything just hangs...

Indeed, the uinput_user_dev struct should be properly initialized. I ran into the same problem, and I created some patches which may fix the hangs:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/drivers/input/ff-core.c?id=33b96d934902f96e901b72ac18bbc47afad1ac20
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/drivers/input/misc/uinput.c?id=daf6cd0c1829c48cba197bd87d57fc8bf3f65faa

Which kernel version are you using?
The first patch is already in version 4.4.

Glad you got it working now,
Elias

#7 lore raw
Quoted 2 lines · Elias Vanderstuyft

Which kernel version are you using?
The first patch is already in version 4.4.

Currently 4.3.3. Self-built to have a small patch which makes PS4 controller bluetooth binding possible (will be in kernel in version 4.5).

Rumble seems to be a problem with uinput in general. For example it is pretty easy to create "non-killable" processes if fftest is still running when the uinput daemon is killed. Not much fun to debug something like this, so I finally disabled my rumble support.

Quoted 1 line

Glad you got it working now,

Partially but not really solving my problem. Still working on it.

Manuel