xwiimote / xwiimote

Open Source Nintendo Wii Remote Linux Device Driver
Other
240 stars 31 forks source link

Axes & sideways #2

Open mikeru opened 12 years ago

mikeru commented 12 years ago

The module should support the D-pad as axes. I've found that most games expect them as axes, and when they don't, at least they're not expecting KEY_*s.

I made a patch to deal with this, it can be found at http://pastebin.com/fGu8Bnpq . It adds supports for D-pad as axes and uses it as default. It also changes the D-pad mappings when in button mode to BTN_TRIGGERHAPPY, as the xpad driver for XBox controllers uses them for this mode. KEY__ mappings are for keyboards, not for controllers :P

It also adds support for handling the D-pad when the Wii Remote is being held sideways. As no app in linux that accesses gamepads has specific code to handle wiimotes, the user-space tools should allow to set the wiimote to have its D-pad correctly handled when being held sideways. However, the userspace tools aren't yet ready, and they might require at the end some help from the kernel module (unless they perform XTest mumo jumbo or something like that). The sideways mode can be enabled when loading the module or at runtime by setting /sys/modules/hid_wiimote/parameters/sideways to Y. Nevertheless, this is just an stopgap measure until the userspace xwiimote apps are ready. Also, I don't know about a way to have module parameters changed by normal users, so the userspace apps would need another way to communicate with the kernel driver to set the sideways mode, or do some xserver-black-magic or whatever)

dvdhrm commented 12 years ago

Hi

The driver is developed as in-tree kernel driver. I'd recommend writing to linux-input@vger.kernel.org (LKML) when discussing code. Anyway, these changes cannot be applied like you want it. Once something is upstream, we never break the API, we only extend it. Therefore, I cannot push these changes to the linux-kernel unchanged.

About the changes: I do not like the way you use the kernel driver to track state. Module-parameters are global and different users of the module may want to use different settings (one uses sideways, the other does not). Therefore, I'd recommend doing this inside of the client. Yes, this means that the module needs client-support and doesn't work with generic APIs, but we need this anyway to support all wiimote features. Furthermore, the kernel input drivers are used to provide the most generic access to the device for userspace and apply as less policy as possible. The module guarantees a way it reports it data so the userspace clients should add interpreters which work with this data. For the wiimote this would mean writing an XInput2 driver that provides xwiimote data as XInput data for most games.

However, the wiimote provides an interface which is not that common on linux so I never wrote such an XInput driver as I think this is really not needed. Instead I work on a separate libxwiimote library that can easily be added to applications/games as separate input driver.

I appreciate any comments on the API and other criticism. However, as long as is belongs to the kernel driver I'd actually prefer doing it over the LKML as there are other kernel developers (including HID and input maintainers) which can probably explain the kernel input API design better.

Thanks for the Review David

mikeru commented 12 years ago

Oh, didn't know that. So, under which circumstances is further funcionality added to a kernel module?

That's fine, I just hacked together that code quickly to play Super Meat Boy with the wiimote :P I completely agree with you that it should be done client side (except maybe the dpad as buttons - xpad is included in the kernel and has that parameter)

I'd still suggest you remap the dpad to BTNsomething. KEY* doesn't even show up on any joypad test app and I couldn't even use it in some apps (i.e. I wasn't able to assign the dpad on Gens to the corresponding Mega Drive buttons - unless I didn't enable the ignore wiimote in xorg, and then it mapped directly to keyboard keys)

dvdhrm commented 12 years ago

Adding functionality is no problem. But breaking the existing API is critical. Therefore, remapping the buttons cannot be done in kernel as there already might be applications which expect these keys. I will update the xwiimote tools next week, then I will also have a look on this.

Thanks David

mikeru commented 12 years ago

Hmm, are you sure that functionality for use as a joypad should be added in a xinput driver? Very few games use it for input (usually, SDL is used, and it only supports evdev and joydev). I'd say a xinput driver would be useful for apps, but useless for 99% of games (e.g. bsnes is the only emulator so far that includes support for xinput - and then, it defaults to SDL).

http://freegamedev.net/wiki/Input_Handling#xinput_.28Xorg.29

dvdhrm commented 12 years ago

As I said, I will not write an XInput driver (at least for now). An X-developer mentioned that this would be the most straightforward way. However, I want the driver to be independent of X so I am working on another app that provides a new input device via uinput that simulates a mouse/keyboard or whatever and allows arbitrary remappings of the keys. This should integrate well with all kinds of input handling (X, SDL, etc.)

I will leave this issue open as the axes/sideways stuff needs to be implemented in the new apps and I wasn't aware of the issue. However, it will take some time until these apps are ready to use.