how to get JInput to work under linux?

I have problems to see any devices in the linux version. Can someone explain me which kernel options are required?

Hi
First question, what kernel are you running, 2.6 series?

Cheers

Endolf

Of course 2.6. I am following JInput development since may last year and know from one your posts that it only runs on 2.5+. :slight_smile:

Hi
You need to make sure of the following options

CONFIG_INPUT=y
CONFIG_INPUT_MOUSEDEV=y

if you want joystick support add

CONFIG_INPUT_JOYDEV=y

CONFIG_INPUT_EVDEV=y

CONFIG_INPUT_MOUSE=y and
CONFIG_MOUSE_PS2 or
CONFIG_MOUSE_SERIAL for your legacy mouse, ignore if you have a USB one

you’ll need to make sure you have the appropriate joystick drivers loaded, if you have a USB, non force feedback joystick then you will be fine, otherwise you will need drivers and maybe gameport drivers if you are using an old gameport on a soundcard type thing.

CONFIG_USB_HID=y and any drivers for USB devices you want to show up

I think thats it, let me know if something inparticular doesn’t work

Cheers

Endolf

Also will this work with 2.4.x kernels?

Look 3 messages back.
(The answer is no.)

[quote] Of course 2.6. I am following JInput development since may last year and know from one your posts that it only runs on 2.5+
[/quote]

[quote]Look 3 messages back.
[/quote]
This doesn’t answere my question. Just because 2.4 wasn’t supported maybe a year ago, or from whenever that guy read the posts doesn’t mean that it isn’t supported now.

So why isn’t the 2.4 kernel supported? Is there a big differnce in how devices are used in 2.5+ kernels?

[quote]So why isn’t the 2.4 kernel supported? Is there a big differnce in how devices are used in 2.5+ kernels?
[/quote]
Spot on. I expect you can find the details if you search for them.

Edit: I’m in a generous mood: ;D

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jinput;action=display;num=1058288140

Basically, things couldn’t work the way the team wanted them to with the way the 2.4 kernel handled things, but 2.5 added a new method of access which made everything possible.

Hi
Yeah, joysticks and USB devices should work fine in 2.4, but I’ve not tested it. Under 2.6 any keyboard and/or mouse will show up as an event device in /dev/input, under 2.4 they don’t. The event interface makes life very simple and means that jinput doesn’t have to cope with every single mouse protocol, microsoft and logitec mice for example don’t talk the same way with ps2 ports, so I would have had to written device drivers for each one, keyboards would have been simpler though. So thats why we have the requirement for 2.6, but like I said, if you are all USB, then you should get /dev/input/event* devices anyway, so it should work fine.

HTH

Endolf

Yahoo!!! This works!

I have tested this on Gentoo Linux with kernel 2.6.1.

But some notes on this:
1)
I had to add write permission on the event objects for ‘others’: Isn’t read permission sufficent? Thats annoying because new hotplugged devices won’t be recognized until I change the access rights.

My Thrustmaster gamepad (recognized as “Mega World”) is in fact a digital pad but JInput tells me it is analog and the values for x and y are 0,004 in released state (However when pressed everything is alright…)

The 12 buttons of the gamepad were named by some unknown scheme. In Windows it just says ‘Button i’ but in Linux names like ‘Button A’ or ‘Left Thumb Button’ were given. These names are not correct with my particular gamepad.

Although there are some minor flaws I am very happy with that library especially because it recognizes additional mice as separate devices (Which is impossible on Win, I think).
I suppose this is true for additional (USB-) keyboards too?

[quote] Yahoo!!! This works!
[/quote]
Great! :slight_smile:

[quote]I have tested this on Gentoo Linux with kernel 2.6.1.
[/quote]
i’m using gentoo too, but that box has 2.6.0 on it still, not that thats important :slight_smile:

no, read isn’t enough, to send requests to the device you have to write to it, also forcefeedback will need write permissions, but even non ff stuff needs it. sorry.

Digital means 0 or 1, your axis report -1 to +1, so it’s classed as analog, it’s picked up by the kernel driver, so there is nothing we can do, also, any axis that has a positive and a negative is analog.

Tha naming is done by linux, in the input modules in the kernel, as far as I can see no linux devices can name their own buttons, or axes, they get to choose one from the list and thats it.

Coo, hadn’t though of that, this is the first machine I’ve had more than one k/b connected too, and I don’t have jinput on it yet (still building it with linux). But I think it should do. Interesting is when you enable things like event support for the pc speaker and it shows up in the jinput test apps :), no axes or buttons, just amusing, guess I’m just sad enough to laff at that :slight_smile:

Cheers

Endolf

Hello Endolf:
The stuff is working but now I tried to actually use JInput(Linux) in a game and the following problems came up:

My gamepad is not identified as such. Instead JInput recognizes it as an unknown device. This is rather bad because this way I cannot programmatically decide what kind of polldata I can expect.

  1. Then I went over to the axes:
    Using Controller.getAxis(Axis.Identifier.BUTTON) is useless because it currently returns null and otherwise would give me no possibility to choose from one of the 12 buttons the gamepad has.

Then I took the direct approach with Controller.getAxes() which gave me all the wanted Axes-implementation but again it is hard to decide whether one of them is a button. For a real axis (eg: X) this is true:


axisx.getIdentifier().equals(Axis.Identifier.X)

but for a button:


button.getIdentifier().equals(Axis.Identifier.BUTTON)

is false. And that would be the last way to find out of what type that thing is.

Please help. :’(
I am really interested in JInput. So if you want me to test things out and such just call me.

BTW: I am using a current version of JInput - downloaded some hours ago.

Hi
Do you get all the axes and buttons and responses you expect if you try the java webstart version here ?

Cheers

Endolf

Webstart version version works but I have no problem with the responses with the local JInput here.

My own jinputtester can enumerate all devices and show their polldata, too. But the tester is somewhat dumb: it isnt neccessary to know whether some axis is a button or not. Problems arise when I actually do something meaningful with the data and what to interpret it.

Hi
Do you have a website you could post your code to for us to look at, or the relivant bits of it?

Cheers

Endolf

P.S. I probably won’t get to look at it till next week now

Hey. I am using gentoo 2.6.1 kernel and I am getting the following error for the keyboardtest.java.

Exception in thread “main” java.lang.NullPointerException
at KeyboardTest.keyboardupdate(KeyboardTest.java:26)
at KeyboardTest.(KeyboardTest.java:19)
at KeyboardTest.main(KeyboardTest.java:39)

Do you guys think this is a classpath/environment path problem?

Thanks

Hi
It looks like a null pointer exception ;P, but without any of your code I can’t tell.

Cheers

Endolf

Ah, I got this either on the formums here or from the jinput demos stuff.

Anyways, here it is:


import net.java.games.input.*;
public class KeyboardTest {
  Keyboard kb = null;
  public KeyboardTest() {
   //ControllerEnvironment ce = LinuxEnvironmentPlugin.getDefaultEnvironment();
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cont = ce.getControllers();
    System.out.println("cont: " + cont.length);
     for (int i = 0; i < cont.length; i++) {
       if (cont[i].getType() == cont[i].getType().KEYBOARD) {
         kb = (Keyboard) cont[i];
      }
    }
    for(int i = 0; i < 100000; i++) {
      keyboardupdate();
    }
    System.out.println("done...");
  }
  public void keyboardupdate() {
    kb.poll();
    Axis[] ax = kb.getAxes();
    for (int x = 0; x < ax.length; x++) {
      float num = ax[x].getPollData();
      if (num != ax[x].getDeadZone()) {
        if (ax[x].getName().equalsIgnoreCase("key 110")) {
          System.out.println("up arrow");
        }
      }
    }
  }
   public static void main(String []args){
      KeyboardTest kbt = new KeyboardTest();
   }
}

Hi
Thats not the code you are running, the stack trace starts at 39, but the code you posted doesn’t have 39 lines, the other lines don’t point to anything that makes sense either, either you posted the wrong code, or you have a classpath issue that is causeing you to run a different KeyboardTest class.

HTH

Endolf

Nope, the error I get is from running KeyboardTest. Note, in the above code, I removed spaces and other comment stuff so thats why there isn’t a line 39. I did this so it wouldn’t take up so much space in the forum.

So the null pointer is caused by this line


  kb.poll(); 

Here is how I’m setting up my class path and stuff.

java -cp .:/opt/java/java-gaming/jinput.jar:/opt/java/java-gaming/linux.jar:/opt/java/java-gaming/jutils.jar -Djava.library.path=/opt/java/java-gaming KeyboardTest