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

Author Topic: Joystick problem?  (Read 4243 times)

0 Members and 1 Guest are viewing this topic.

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Joystick problem?
« on: January 31, 2013, 04:05:04 pm »
Hello,
I have one Twin USB Joystick(Human Interface Devices).
Each joystick have 12 buttons.
Now I test number 0-200 and I can not find it.
I found some joystick with 4752 buttons.


OS: Windows Seven 32 Bit
IDE:CodeBlocks
Compiler:MinGW 4.7.2
SFML:2.0 RC

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #1 on: February 01, 2013, 08:35:56 am »
Can you be more specific about "I test number 0-200" and "I found some joystick with 4752 buttons"? What exactly did you do, and what was the result?

Showing a minimal code would be perfect.

And by the way, did you recompile SFML? There's no official download of SFML 2.0 RC which is compatible with gcc 4.7.
Laurent Gomila - SFML developer

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #2 on: February 01, 2013, 09:06:38 am »
This is my test code
#include <SFGUI/SFGUI.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
using namespace std;
int main() {
    for(int i=0;i<=20;i++) {
        cout << i << ":" << sf::Joystick::isConnected(i) << ":" << sf::Joystick::getButtonCount(i) << endl;
    }
        return 0;
}
I didn't make SFML and I use  http://sfml.my-gate.net/nightly/
I download MinGW32 GCC 4.7.2 and Now it work fine for me just I have problem with JoySticks.

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Joystick problem?
« Reply #3 on: February 01, 2013, 09:16:46 am »
SFML supports:
8 joysticks (sf::Joystick::Count)
Don't go up to 20.
Can't make sense of the rest of your answers. ^^

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #4 on: February 01, 2013, 09:24:48 am »
RTFM ;)
Quote from: the tutorial
Joystick states are automatically updated by the event loop. If you don't have one, or need to read a joystick state (for example, check which joysticks are connected) before starting your game loop, you'll have to call the sf::Joystick::update() function to make sure that the joystick states are up to date.
Quote from: the API documentation
Unlike the keyboard or mouse, the state of joysticks is sometimes not directly available (depending on the OS), therefore an update() function must be called in order to update the current state of joysticks. When you have a window with event handling, this is done automatically, you don't need to call anything. But if you have no window, or if you want to check joysticks state before creating one, you must call sf::Joystick::update explicitely.

Quote
I didn't make SFML and I use  http://sfml.my-gate.net/nightly/
So this is not 2.0 RC ;)
Laurent Gomila - SFML developer

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #5 on: February 01, 2013, 09:38:46 am »
I want to use SFML 2.0 because I don't need to update my codes when officially SFML 2.0 released.
This my new code:
#include <SFGUI/SFGUI.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
using namespace std;
int main() {
    sf::Joystick::update();
    for(int i=0;i<=20;i++) {
        cout << i << ":" << sf::Joystick::isConnected(i) << ":" << sf::Joystick::getButtonCount(i) << endl;
    }
        return 0;
}
Output:
Quote
0:0:0
1:0:0
2:0:0
3:0:0
4:0:0
5:0:0
6:0:0
7:0:0
8:0:0
9:0:0
10:0:0
11:0:0
12:0:0
13:0:0
14:0:0
15:0:0
16:12:4752
17:4:2555942
18:83:843995743
19:87:1446469459
20:102:1986622563
I download CMake 2.8.10.2 and also source https://github.com/SFML/SFML.
After I use CMake I get this page:


[attachment deleted by admin]
« Last Edit: February 01, 2013, 09:41:43 am by Hamed »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #6 on: February 01, 2013, 09:41:42 am »
I didn't mean that you should recompile SFML, I just said that your version was not the RC, it's more recent. But it's fine (and better if you want to be as close as possible to the final 2.0 version).

Don't recompile SFML, just add a call to sf::Joystick::update() in your code, and everything should be ok.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #7 on: February 01, 2013, 09:42:42 am »
And please don't edit your posts after you have new answers, this is really confusing ;)

As already said, you shouldn't use indices > sf::Joystick::Count (which is 8 ).
Laurent Gomila - SFML developer

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #8 on: February 01, 2013, 09:44:25 am »
I add update function but not work for me.
Where can I find my recompiled source? I can not find it.

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #9 on: February 01, 2013, 09:47:37 am »
Sorry for editing.
This my code:
#include <SFGUI/SFGUI.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
using namespace std;
int main() {
    sf::Joystick::update();
    for(int i=0;i<=sf::Joystick::Count;i++) {
        cout << i << ":" << sf::Joystick::isConnected(i) << ":" << sf::Joystick::getButtonCount(i) << endl;
    }
        return 0;
}
Output:
Quote
0:0:0
1:0:0
2:0:0
3:0:0
4:0:0
5:0:0
6:0:0
7:0:0
8:0:0


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #10 on: February 01, 2013, 09:52:09 am »
Are you sure that your device is correctly recognized by your OS as a joystick? Can you see/configure it with your OS tools?

And don't use <=sf::Joystick::Count, but <sf::Joystick::Count.
Laurent Gomila - SFML developer

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #11 on: February 01, 2013, 09:57:17 am »
Yes it is ok and I can play other games with it.

How can I switch to SFML 2.0?(Maybe work on that)
Download:Windows 32 bits - GCC SJLJ (Code::Blocks) and after that I replace files with old version but compiler can not find include files.

[attachment deleted by admin]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #12 on: February 01, 2013, 10:03:51 am »
I don't know why your joystick is not recognized by SFML, it should work. I'll try to test this small code at home, just to be sure.

Quote
How can I switch to SFML 2.0?
You ARE using SFML 2. The nightly builds are the latest sources, it cannot be more SFML 2.0 than that.
Laurent Gomila - SFML developer

Hamed

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: Joystick problem?
« Reply #13 on: February 02, 2013, 06:48:10 am »
I test my code on another computer and I have the same problem.
Also I change my joysticks and it doesn't worked for me.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Joystick problem?
« Reply #14 on: February 02, 2013, 10:09:50 am »
It was a bug, it's fixed now. If you don't want to recompile SFML or wait for the corresponding nightly builds to be ready, you can insert a sf::sleep(sf::seconds(1)) before calling sf::Joystick::update() in your code.
Laurent Gomila - SFML developer