Game controller axes misbehaving at application startup

hi

i’m trying to add game controller support to my sdl based game and
I’m more or less done except for the following:

each time the program starts up and i push the stick, say, left (axis
0 reads -32767) and then release it, the axis 0 reads 32767 - as if i
pushed it right all the way. only after I also pushed the stick right
does it seem to figure out where the center is and settle to some
number close to zero.

the same is true for the vertical axis and other order (first push
right).

i’m using SDL 1.2.11 form darwin ports on mac os. my game controller
is speedlink’s Hornet Force Pad Touch Edition (SL-6526)

http://www.nobilis-informatika.hr/php/proizvod.php?kat_id=83&pro_id=1843

(can’t find it at speedlink website)

is this normal behaviour? can i work around it?

hmm… anybody using joysticks with SDL at all?

to make it easy on everyone, here is my test program and its output
(in reaction to my pushing the joystick left, relasing, right,
releasing, up, releasing, down, releasing).

could somebody test it and send the output?

----(sdljoy.c)----
#include <stdio.h>
#include <assert.h>
#include <SDL.h>

int
main(int argc,char**argv)
{
assert (SDL_Init(SDL_INIT_VIDEO|// need video for events
SDL_INIT_JOYSTICK) == 0);
atexit(SDL_Quit);

SDL_Joystick * joy = NULL;
if(SDL_NumJoysticks()>0){
	joy = SDL_JoystickOpen(0);
	assert(joy);
	SDL_JoystickEventState(SDL_ENABLE);
}

while(1) {
	SDL_Event ev;
	while(SDL_PollEvent(&ev)) {
		switch(ev.type) {
		case SDL_KEYDOWN:
			switch(ev.key.keysym.sym) {
			case SDLK_ESCAPE:
				exit(0);
				break;
			}
		case SDL_JOYAXISMOTION:
			printf("jaxis: which=%u axis=%u value=%d\n", ev.jaxis.which,  

ev.jaxis.axis, ev.jaxis.value);
break;
}
}
}
}
----(output of ./sdljoy)----
jaxis: which=0 axis=0 value=0
jaxis: which=0 axis=0 value=-32768
jaxis: which=0 axis=0 value=32767
jaxis: which=0 axis=0 value=32254
jaxis: which=0 axis=0 value=32767
jaxis: which=0 axis=0 value=128
jaxis: which=0 axis=0 value=-32768
jaxis: which=0 axis=0 value=128
jaxis: which=0 axis=0 value=32767
jaxis: which=0 axis=0 value=128
jaxis: which=0 axis=1 value=0
jaxis: which=0 axis=1 value=-32768
jaxis: which=0 axis=1 value=32767
jaxis: which=0 axis=1 value=32254
jaxis: which=0 axis=1 value=32767
jaxis: which=0 axis=1 value=128
jaxis: which=0 axis=1 value=-32768
jaxis: which=0 axis=1 value=128
jaxis: which=0 axis=1 value=32767
jaxis: which=0 axis=1 value=128On 5 Oct 2006, at 01:44, Artem Baguinski wrote:

hi

i’m trying to add game controller support to my sdl based game and
I’m more or less done except for the following:

each time the program starts up and i push the stick, say, left
(axis 0 reads -32767) and then release it, the axis 0 reads 32767 -
as if i pushed it right all the way. only after I also pushed the
stick right does it seem to figure out where the center is and
settle to some number close to zero.

the same is true for the vertical axis and other order (first push
right).

i’m using SDL 1.2.11 form darwin ports on mac os. my game
controller is speedlink’s Hornet Force Pad Touch Edition (SL-6526)

http://www.nobilis-informatika.hr/php/proizvod.php?
kat_id=83&pro_id=1843

(can’t find it at speedlink website)

is this normal behaviour? can i work around it?

Artem Baguinski <artm v2.nl> writes:

----(sdljoy.c)----
#include <stdio.h>
#include <assert.h>
#include <SDL.h>

int
main(int argc,char**argv)
{
assert (SDL_Init(SDL_INIT_VIDEO|// need video for events
SDL_INIT_JOYSTICK) == 0);
atexit(SDL_Quit);

SDL_Joystick * joy = NULL;
if(SDL_NumJoysticks()>0){
joy = SDL_JoystickOpen(0);
assert(joy);
SDL_JoystickEventState(SDL_ENABLE);
}

while(1) {
SDL_Event ev;
while(SDL_PollEvent(&ev)) {
switch(ev.type) {
case SDL_KEYDOWN:
switch(ev.key.keysym.sym) {
case SDLK_ESCAPE:
exit(0);
break;
}
case SDL_JOYAXISMOTION:
printf(“jaxis: which=%u axis=%u value=%d\n”, ev.jaxis.which,
ev.jaxis.axis, ev.jaxis.value);
break;
}
}
}
}

hi

i’m trying to add game controller support to my sdl based game and
I’m more or less done except for the following:

each time the program starts up and i push the stick, say, left
(axis 0 reads -32767) and then release it, the axis 0 reads 32767 -
as if i pushed it right all the way. only after I also pushed the
stick right does it seem to figure out where the center is and
settle to some number close to zero.

the same is true for the vertical axis and other order (first push
right).

I’m using joystick input in my application.

From what I can tell (I’m no expert) you should initalize the joystick axises
(sp) to 0.
I know there might be a problem with this if you hold down a direction as the
application loads, but that’s the users fault :slight_smile:

Snippits from my input class:

InputState() //Constructor
{
InputState::SetX(0);
InputState::SetY(0);
}

void InputState::SetX(int x){ InputState::xAxis = x; }
void InputState::SetY(int y){ InputState::yAxis = y; }

Hope this helps at least a little.> On 5 Oct 2006, at 01:44, Artem Baguinski wrote: