Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Joystick axes  (Read 4219 times)

0 Members and 1 Guest are viewing this topic.

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Joystick axes
« on: April 21, 2015, 10:07:06 am »
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++

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Joystick axes
« Reply #1 on: April 21, 2015, 10:34:16 am »
Did you try the master revision of SFML? Joystick detection was rewritten a month ago.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Joystick axes
« Reply #2 on: April 21, 2015, 10:46:55 am »
Did you try the master revision of SFML? Joystick detection was rewritten a month ago.

Thanks, I'll try it out at home ;) Forget to mention that I used SFML v2.2 release sources.

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Joystick axes
« Reply #3 on: April 21, 2015, 10:56:07 pm »
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

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Joystick axes
« Reply #4 on: April 21, 2015, 11:08:32 pm »
You might want to try calibrating it.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Joystick axes
« Reply #5 on: April 21, 2015, 11:27:52 pm »
You might want to try calibrating it.

Thanks a lot, Binary1248! It helps =) First time I had no success and bug came again after joystick reconnect, but after I find out about 'jscal-store' and now everything's great :D