Пример #1
0
void Init( std::vector<Core::Device*>& devices )
{
	// this is used to number the joysticks
	// multiple joysticks with the same name shall get unique ids starting at 0
	std::map<std::string, int> name_counts;

#ifdef USE_SDL_HAPTIC
	if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) >= 0)
	{
		// Correctly initialized
	}
	else
#endif
	if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
	{
		// Failed to initialize
		return;
	}

	// joysticks
	for (int i = 0; i < SDL_NumJoysticks(); ++i)
	{
		SDL_Joystick* dev = SDL_JoystickOpen(i);
		if (dev)
		{
			Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++);
			// only add if it has some inputs/outputs
			if (js->Inputs().size() || js->Outputs().size())
				devices.push_back( js );
			else
				delete js;
		}
	}
}
Пример #2
0
/* Function to scan the system for joysticks.
 * This function should set SDL_numjoysticks to the number of available
 * joysticks.  Joystick 0 should be the system default joystick.
 * It should return 0, or -1 on an unrecoverable fatal error.
 */
int SDL_SYS_JoystickInit(void)
{
	int	i;
	int maxdevs;
	int numdevs;
	JOYINFOEX joyinfo;
	JOYCAPS	joycaps;
	MMRESULT result;

	/* Reset the joystick ID & name mapping tables */
	for ( i = 0; i < MAX_JOYSTICKS; ++i ) {
		SYS_JoystickID[i] = 0;
		SYS_JoystickName[i] = NULL;
	}

	/* Loop over all potential joystick devices */
	numdevs = 0;
	maxdevs = joyGetNumDevs();
	for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) {
		
		joyinfo.dwSize = sizeof(joyinfo);
		joyinfo.dwFlags = JOY_RETURNALL;
		result = joyGetPosEx(i, &joyinfo);
		if ( result == JOYERR_NOERROR ) {
			result = joyGetDevCaps(i, &joycaps, sizeof(joycaps));
			if ( result == JOYERR_NOERROR ) {
				SYS_JoystickID[numdevs] = i;
				SYS_Joystick[numdevs] = joycaps;
				SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey);
				numdevs++;
			}
		}
	}
	return(numdevs);
}
Пример #3
0
void Init( std::vector<Core::Device*>& devices )
{
	// this is used to number the joysticks
	// multiple joysticks with the same name shall get unique ids starting at 0
	std::map<std::string, int> name_counts;

	if (SDL_Init( SDL_INIT_FLAGS ) >= 0)
	{
		// joysticks
		for(int i = 0; i < SDL_NumJoysticks(); ++i)
		{
			SDL_Joystick* dev = SDL_JoystickOpen(i);
			if (dev)
			{
				Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++);
				// only add if it has some inputs/outputs
				if (js->Inputs().size() || js->Outputs().size())
					devices.push_back( js );
				else
					delete js;
			}
		}
	}
}
Пример #4
0
   U32 retMask = 0;
   for(S32 i = 0; i < MaxJoystickButtons; i++)
      if(buttonMask & (1 << i))
         retMask |= gControllerButtonRemaps[OptionsMenuUserInterface::joystickType][i];
   buttonMask = retMask | hatMask;
   return true;
}

S32 autodetectJoystickType()
{
   S32 ret = -1;
   TNL_JOURNAL_READ_BLOCK(JoystickAutodetect, 
      TNL_JOURNAL_READ((&ret));
      return ret;
      )
   const char *joystickName = GetJoystickName();
   if(!strncmp(joystickName, "WingMan", 7))
      ret = LogitechWingman;
   else if(!strcmp(joystickName, "XBoxOnXBox"))
      ret = XBoxControllerOnXBox;
   else if(strstr(joystickName, "XBox"))
      ret = XBoxController;
   else if(!strcmp(joystickName, "4 axis 16 button joystick"))
      ret = PS2DualShock;
   else if(strstr(joystickName, "P880"))
      ret = SaitekDualAnalog;
   else if(strstr(joystickName, "Logitech Dual Action"))
      ret = LogitechDualAction;
   TNL_JOURNAL_WRITE_BLOCK(JoystickAutodetect,
      TNL_JOURNAL_WRITE((ret));
   )
Пример #5
0
std::string Joystick::GetName() const
{
	return StripSpaces(GetJoystickName(m_sdl_index));
}