In a project I am using a USB adapter to connect a Nintendo 64 controller to my computer. (I then make it control an Ocarina of Time.) When experimenting with code under Windows, I found that C-Left and C-Right were read by GetJoystick as Axis 3. However, on Linux, the same GetJoystick call on the same two buttons are now registered as Axis 5. I was wondering about the cause of the discrepancy. How does the GetJoystick routine work? How does it decide how to read data coming in from the controller? Before working on this project I assumed that the C-buttons on an N64 controller would be part of the bit array for the buttons, so I was surprised to find that they controlled an axis.
That's when I had a thought. Maybe if I wrote a custom GetJoystick routine for my project I would be able to read the C-buttons as part of a bit array of buttons instead of being extremes on an axis. I downloaded a copy of the source but everything is everywhere! Where could I read the implementation of the routine GetJoystick? I am most interested in learning how to read data directly coming in from the joystick, so something I can read about that would be good as well.
I heard from my brother (my collaborator on this project) that the system actually has to poll the joystick in order for the joystick to transmit data. Is this relevant to what I am looking for?
Thank you for any assistance you can provide.
The source for the ocarina program (tested on Windows 7 and XP) was posted as a project earlier: http://www.freebasic.net/forum/viewtopi ... =8&t=19165.
Reading joystick data directly
-
- Posts: 72
- Joined: Oct 13, 2006 6:11
- Location: Latte Plantation, Guam
- Contact:
Re: Reading joystick data directly
Well, you can use libhid to talk to the joystick directly, but it's way too complex for just reading data from the joystick. On Linux you can also just read from /dev/hidrawX, but again, why do we need this if there are joystick drivers already working.
Sometimes Linux maps joysticks differently from Windows. There are 3 easier alternatives to deal with this:
(1) #IFDEF __FB_LINUX__ and / or #IFDEF __FB_WIN32__
(2) On Linux you can use "jscal -u ..." to remap the buttons / axis. You could call this using "SHELL" or "EXEC" and remap the joystick so it behaves like on Windows.
(3) Make your program read joystick definitions from an external configuration file. You can have separate definitions for Linux and Windows, and set the defaults by combining with alternative (1).
I recommend (3).
[EDIT]
Ah, FreeBASIC doen't read directly from the joystick either. It uses winmm under windows and /dev/input/jsX on Linux.
Sometimes Linux maps joysticks differently from Windows. There are 3 easier alternatives to deal with this:
(1) #IFDEF __FB_LINUX__ and / or #IFDEF __FB_WIN32__
(2) On Linux you can use "jscal -u ..." to remap the buttons / axis. You could call this using "SHELL" or "EXEC" and remap the joystick so it behaves like on Windows.
(3) Make your program read joystick definitions from an external configuration file. You can have separate definitions for Linux and Windows, and set the defaults by combining with alternative (1).
I recommend (3).
[EDIT]
Ah, FreeBASIC doen't read directly from the joystick either. It uses winmm under windows and /dev/input/jsX on Linux.
-
- Posts: 72
- Joined: Oct 13, 2006 6:11
- Location: Latte Plantation, Guam
- Contact:
Re: Reading joystick data directly
Thanks for the suggestions. I do agree that recommendation 3 is the best one, where the program reads joystick definitions from a file (which, if I get ambitious, could be generated by the program itself by asking, "Press A now", "Press C-Left now", etc.). I guess my concern was that different machines would read the joystick different ways (as opposed to reading it one way on Windows and another way in Linux).
As for reading the joystick directly, I think I would be interested in seeing that as one of the goals was to realize the ocarina effect as an external device you could plug the N64 controller to. Thanks for the tip; I now know where to look in order to satisfy my curiosity.
Romel
As for reading the joystick directly, I think I would be interested in seeing that as one of the goals was to realize the ocarina effect as an external device you could plug the N64 controller to. Thanks for the tip; I now know where to look in order to satisfy my curiosity.
Romel