Linux Joystick support in GLFW

Hi!

I have just updated GLFW with support for Linux joysticks, but I have been unable to get my gamepad to function under Linux, so I have not really tested the interface much (yes, it compiles, and yes, it says I have no sticks).

Are there any volounteers for testing the GLFW joystick interface under Linux? Basically, I’d be satisfied if the lib & examples are built (i.e. run ‘make xfree86-gcc’), and then test the ‘pong3d’ program, which uses stick 1 & 2 for control.

i don’t know how to do that.
But, i can give you some (maybe?) ways to do:

is it an USB joy ? if it is, is it recognized under linux ? have you USB enabled ?

in all casis, could you read from /dev/js0 ?
it is the normal way to know.
i have tested with my sidewinder gamepad USB, and i could see when i moved the joy or put some buttons.

simple way is like this if i remember correctly:

int main( void)
{
FILE *fd= fopen( “/dev/js0”);

printf( “%s”, fread( fd, 2));
}

anyway, it’s not that, but it may give you some way to know.

if you want, i could give you what i wrote next time (i am now at school, so i haven’t got what i do at home, sorry).

when i tested it, i could have correct behaviors, but i could see that things happen when i use my pad.

good luck.

saian

ps: i remember that there is a programm under gtk to test your joy. maybe it helps.

No, I know my stick isn’t recognized. I have tried the jstest program that comes with the 1.x joystick driver, and it always says ‘device not found’ (or something similar), regardless which /dev/js* I try. It’s not a USB stick, it’s plugged into my soundcard. I also know that

fd = open( “/dev/js0”, O_NONBLOCK );

returns -1 (=fail), also for differnt sticks (e.g. /dev/js1 etc).

Of course it would be nice with a working stick under Linux, but for now I’m satisfied if my code works. I’ll write a ‘joytest.c’ program example for GLFW some time in the future, and then it will be easier to spot errors in the code, but for now the ‘pong3d.c’ example program should work as a basic test (it only uses the second axis of the 1st and 2nd sticks).

BTW. Do you know the positive direction of the Y axis under the Linux drivers? Is it forward or back?

marcus,you might want to check the options of your sound driver module to make sure that the joystick port is enabled.If opening /dev/js* returns -1 that may mean that the port isn’t enabled.Take a look at the souind driver messages during startup.

What kernel is it? The 2.4 series need a different joystick system than 2.2.x; check that the module for ns558 is loaded.

P.S. Left is negative, top is negative, right and bottom are positive.

[This message has been edited by FermatSpiral (edited 10-16-2002).]

Thanks,

I am using kernel 2.4. I use the Mandrake 8.0 distro, which came with joystick drivers installed (apparantly, since I have /dev/js*). I suspect my stick isn’t auto-detected (perhaps the game port isn’t even there?).

Thanks for the down = positive info => I have to change the GLFW source… (in GLFW up = positive).

/Marcus

Originally posted by zen:
marcus,you might want to check the options of your sound driver module to make sure that the joystick port is enabled.If opening /dev/js* returns -1 that may mean that the port isn’t enabled.Take a look at the souind driver messages during startup.

Then, how do I enable it?

Another question: How do I properly detect if a stick is present or not? I thought open => -1 means that the stick could not be opened (=not present or not supported). Could I get success (not -1), but the stick isn’t there?

I would still like someone to just test if the pong3d program reacts on joysticks (stick 1 & 2 up/down is used). Here’s a link to a precompiled version, just extract into your /tmp dir and run. (should be simple enough ):
http://hem.passagen.se/opengl/glfw/files/pong3d-glfw-2.2.2.tar.gz

Thanks in advance…

Maybe I wasn’t clear enough. If your joystick is lead by the ‘analog’ module, that is, most of them are, you an do

/sbin/lsmod

and the following modules should be loaded for the joystick to work: joydev, ns558, analog. If they aren’t, do

modprobe joydev
modprobe ns558
modprobe analog

If on one of those steps, more probably the ns558 bit, the kernel complains of “device not found” it’s still probable that your sound card driver doesn’t set the PCI registers that activate the gameport, as happened to me once. If that’s the case, do a web search for the model of your soundcard and ‘lspci’; that should help.

I’ve just compiled glfw221.zip with ‘make xfree86-gcc’; examples/pong3d runs and closes.

It is failing at

pong3d.c
807 if( !glfwOpenWindow( WIDTH, HEIGHT, 8,8,8,0, 16,0, GLFW_FULLSCREEN ) )

and terminationg.

Thanks for the kernel module information (I’m a bit new to that side of Linux). I’ll try it once I boot Linux (my winmodem only works under win2k, so I have to surf from there).

Originally posted by FermatSpiral:
[b]I’ve just compiled glfw221.zip with ‘make xfree86-gcc’; examples/pong3d runs and closes.

It is failing at

pong3d.c
807 if( !glfwOpenWindow( WIDTH, HEIGHT, 8,8,8,0, 16,0, GLFW_FULLSCREEN ) )

and terminationg.[/b]

Strange, it works for me (bad programmers justification). Did you run the program standing in the examples directory (it needs to load some TGA files - but in any case it shouldn’t fail, at least not in glfwOpenWindow, hmmm)? I suppose I have to add a proper error handling system to GLFW some day so that you do not have to debug the code every time something goes wrong.

Hi,
regarding the joystick port on the soundcard:Besides looking for info on google you can go to /usr/src/linux/Documentation. This are the kernel docs(assuming you have the kernel sources installed).Look into the sound directory(not sure about the actual name) for docs on you specific soundcard.Hopefully there will be all you need to know in there.
Regarding the modules:Mandrake has the bad habbit to compile everything into the kernel so they may not be compiled as modules.I suggest a manual kernel config if you haven’t done so allready.Just look at the Kernel-HOWTO.
Also AFAIK the -1 return value from the open call means that the file(port actaully) wasn’t even there.Otherwise you should be able to open it although trying to read from it would result in your process beeing put to sleep(suspended not killed that is).I’m not sure about this though,it depends on the driver I suppose.It might choose not to initialize the port if it doesn’t find a stick during init.
And lastly about that pong3d game.I bet it fails because it can’t create a context.At least that’s common,especially if you request a RGB8_Z16 visual and fermat has X configured to run in 16bits.But then again I might be totally wrong .A little verbosity won’t kill ya.

PS: I would try it out myself but I don’t even have HW acceleation on this box.I also have to do something about the length of my posts.

[This message has been edited by zen (edited 10-17-2002).]

zen is completly right. I changed the 8, 8, 8 for 4, 4, 4 at glfwOpenWindow (a quick look at the documentation) and now it runs fine.

By the way marcus, the joystick works, and up/down are inverted, as you surely suspect.

Aaahh… This is interesting information, folks! This means that either glXChooseVisual or glXCreateContext fails (the latter perhaps because the visual can’t be supported, somehow). It seems I have to dig into the visual & context functions to see exactly how they work (I assumed they picked the closest match, not the exact match).

Anyhow, the next version of GLFW (2.3) will hopefully have full error info available (glfwGetError & glfwGetErrorString).

Nice to see the stick support working then

Thanks guys! I couldn’t have done this without you! (at least not in a timely manner)

[This message has been edited by marcus256 (edited 10-18-2002).]

If memory serves me right glXChooseVisual fails.The values you pass on to the call are the lowest you expect to get so if the screen can not support at least RGB8_Z16 it fails.Demanding RGB1_Z1 will still get you the best visual the screen can support but it will not fail even if this best visual is RGB1_Z1.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.