# Allegro Joystick Axes messed up.. help

This topic is 4039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, Im running into issues here.. Not too big, but enough to warrant concern on my part as I want to make this work properly. When I compile and run the following code, it autodetects the joysticks, displays the button info properly including a color change for button presses, but when it displays the axis information, its wrong. The gamepad Im using is a Saitek 2900 wireless.. Works perfect.. Has 1 8way hat, 2 sticks and 14 buttons.. The 2 sticks each have an x & y axis along with a button.. When I run this, allegro tells me I have 3 sticks.. Heres what it displays: Stick 0: stick Num Axes: 0 Axis 0: x axis - 0 Axis 1: y axis - 0 Axis 2: z axis - 0 <<<<<<< This turns out to be Stick 1(right stick), its Y axis. 0 centered, -128 to 128.. HUH? Why isnt this on stick 1? Stick 1: z-rotation Num Axes: 1 Axis 0: -128 <<<<<<<<<< this is the right hand stick, its x axis.. -128 centered, 0 is to the left, 256 to the right Stick 2: hat Switch Everything works great except for the right stick has its Y axis listed under stick 0 with a different range of values than its x axis.. I know I could set it to use the left stick, but I wanted to use the right as well. Problem is, if it were just for me, I could code it right.. But if I want to release it, Im sure its going to read the sticks different.. So why does stick 1 have its Axes listed as 2 different sticks in allegro?? For what its worth, its something in allegro doing this. Ive tested this using directinput and XNA and it reads the stick and axes properly, so does the windows control panel. Allegro is the only place it shows the right stick as a z rotation. Ive listed the code below which is the joystick polling, the rest was just setting up the display and then looping through this. If you want the full source or executable, click the links.. Full Source Zip of executable
// working on posting source. whenever i do, it times out.. =(
void mainLoop()
{
poll_joystick();
textprintf_ex(buffer, font, 10, 10, makecol(255,255,255), 0, "Number of Joysticks: %d", num_joysticks);
if(num_joysticks > 0)
{
textprintf_ex(buffer, font, 10, 20, makecol(255,255,255), 0, "Number of sticks: %d", joy[0].num_sticks);
textprintf_ex(buffer, font, 10, 30, makecol(255,255,255), 0, "Number of buttons: %d", joy[0].num_buttons);
int y = 50;
for(int n=0; n < joy[0].num_sticks; n++)
{
textprintf_ex(buffer, font, 10, y, makecol(255,255,255), 0, "Stick %d: %s", n, joy[0].stick[n].name);
y += 10;
textprintf_ex(buffer, font, 10, y, makecol(255,255,255), 0, "Num Axes:  %d", n, joy[0].stick[n].num_axis);
y += 20;
for (int ax = 0; ax < joy[0].stick[n].num_axis; ax++)
{
textprintf_ex(buffer, font, 10, y, makecol(255,255,255), 0, "Axis %d: %s - %d", ax, joy[0].stick[n].axis[ax].name, joy[0].stick[n].axis[ax].pos);
y += 10;
}
y += 30;
}
textprintf_ex(buffer, font, 10, y, makecol(255,255,255), 0, "Buttons:");
y += 20;
for( int n=0; n < joy[0].num_buttons; n++)
{
if( joy[0].button[n].b)
{
textprintf_ex(buffer, font, 10, y, makecol(255,0,0), 0, "Button %d: %s", n, joy[0].button[n].name);
}
else
{
textprintf_ex(buffer, font, 10, y, makecol(255,255,255), 0, "Button %d: %s", n, joy[0].button[n].name);
}
y += 10;
}
}
}


[Edited by - cdxrd on May 5, 2007 11:40:59 PM]

• 10
• 17
• 9
• 13
• 41