This is the strangest thing I ever seen. I have a joystick "EXEQ Spitfire" and tested it on 4 different systems:
- Linux 32bit laptop ASUS X200CA
- Linux 64bit (Ubuntu 14.10) at home
- WinXP 32bit at home
- Linux 64bit (Ubuntu 14.10) at work
All the linux systems throw me two messages to console:
Unable to get joystick attribute. Could not find USB device for joystick at index 0.
Unable to get joystick attribute. Could not find USB device for joystick at index 0.
This code:
printf("[%u : %u] %s\n", sf::Joystick::getIdentification(0).vendorId,
sf::Joystick::getIdentification(0).productId,
sf::Joystick::getIdentification(0).name.toAnsiString().c_str());
Gives me:
[0 : 0] Microntek USB Joystick
Well, about the problem:
Linux 64bit (Ubuntu 14.10) at work works properly.
WinXP 32bit at home gives me (-0.78, -0.78) on X and Y axes when nothing is pressed.
Linux 32bit on laptop and Linux 64bit (Ubuntu 14.10) at home got same results on following sequence:
1. I connect joystick
2. Run application
3. Get axes positions (-100, -100) on X and Y
4. Pressing D-pad on X and Y
5. Releasing D-pad and got (0, 0)
6. Run application again
7. Get axes positions (0, 0) on X and Y
So the initial state is wrong.
Can anyone help me, what could be the reason of this strange behavior? :-\
Tested on this:
#include <SFML/Window.hpp>
#include <stdio.h>
#include <unistd.h>
int main() {
sf::Window window(sf::VideoMode(800, 600), "My window");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
printf("(%3.2f, %3.2f)\n", sf::Joystick::getAxisPosition(0, sf::Joystick::X),
sf::Joystick::getAxisPosition(0, sf::Joystick::Y));
}
return 0;
}
gcc main.cpp -o test -lsfml-window -lsfml-system -lstdc++
Huh.. Seems to be a driver problem. It's at initial state:
achpile@linux:~$ hexdump /dev/input/js0 -C
00000000 4c 2f 31 00 00 00 81 00 4c 2f 31 00 00 00 81 01 |L/1.....L/1.....|
00000010 4c 2f 31 00 00 00 81 02 4c 2f 31 00 00 00 81 03 |L/1.....L/1.....|
00000020 4c 2f 31 00 00 00 81 04 4c 2f 31 00 00 00 81 05 |L/1.....L/1.....|
00000030 4c 2f 31 00 00 00 81 06 4c 2f 31 00 00 00 81 07 |L/1.....L/1.....|
00000040 4c 2f 31 00 00 00 81 08 4c 2f 31 00 00 00 81 09 |L/1.....L/1.....|
00000050 4c 2f 31 00 01 80 82 00 4c 2f 31 00 01 80 82 01 |L/1.....L/1.....|
So each 16 bytes is 1 event. 81 is initial button event, 82 is initial axis event (0x80 | 0x02). First 4 bytes is timestamp, next 2 bytes - value. So initial values for axes is "01 80" = 0x8001 = -32767 as signed int16