View Single Post
  #12   Spotlight this post!  
Unread 14-02-2004, 23:50
Ryan Cumings's Avatar
Ryan Cumings Ryan Cumings is offline
Programmer and University Rejected
#0134 (Team Discovery)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Pembroke, NH
Posts: 65
Ryan Cumings is an unknown quantity at this point
Send a message via AIM to Ryan Cumings
Re: Programming joysticks

Quote:
Originally Posted by deltacoder1020
example:
Code:
if( (p1_wheel & 0xC0) == 0xC0 )
{
     //hat control is pushed right
}
else if( (p1_wheel & 0xA4) == 0xA4 )
{
     //hat control is pushed down-left
}
...
et cetera
...
just use the bitwise AND function (&) to determine if the correct bits are set.
Haven't been on for a while, but here goes (Sorry delta!)
If you push the hat up by your code then it will default to the first conditional statement you put in.

A more correct way might be to do it this way (using constants provided courtesy of Astronouth7303)
Code:
switch (px_wheel & 0xFC) {
	case Hat_Up_Left: {
		// ... Code here
		break;
	}
	case Hat_Up_Right: {
		// ... Code here
		break;
	}
	// etc...
	default: {
		break;
	}
}