Beispiel #1
0
void JoyStick::close()
{
	if (m_joystick && SDL_JoystickOpened(m_index))
	{
		SDL_JoystickClose(m_joystick);
	}
}
controllerClass::controllerClass(paddle_class *pc, bulletsClass *bu, ballManager *bm)
{
  paddle = pc;
  bullet = bu;
  bMan = bm;
  shotTime=200;
  itemSelectTime=0;

  //Try to open a joystick.
  if(setting.joyEnabled && SDL_NumJoysticks() > 0)
  {
    joystickLeftX = setting.controlMaxSpeed / setting.JoyCalMin;
    joystickRightX = setting.controlMaxSpeed / setting.JoyCalMax;
    joystick = NULL;
    joystick = SDL_JoystickOpen(0);
    if(SDL_JoystickOpened(0))
    {
      cout << "Using joystick: '"<<SDL_JoystickName(0)<<"' as "<<(setting.joyIsDigital ? "digital":"analog")<<"."<<endl;
      SDL_JoystickEventState( SDL_ENABLE );
    } else {
      cout << "Failed to open joystick: '"<<SDL_JoystickName(0)<<"'"<<endl;
    }
  }

  #ifdef WITH_WIIUSE
  var.wiiConnect=0;
  moteAccel = setting.controlMaxSpeed / 90.0;
  #endif

}
Beispiel #3
0
qboolean
OpenJoystick(cvar_t * joy_dev)
{
	int		num_joysticks, i;

	joy = NULL;

	if (!(SDL_INIT_JOYSTICK & SDL_WasInit(SDL_INIT_JOYSTICK))) {
		ri.Con_Printf(PRINT_ALL, "SDL Joystick not initialized, trying to init...\n");
		SDL_Init(SDL_INIT_JOYSTICK);
	}
	ri.Con_Printf(PRINT_ALL, "Trying to start-up joystick...\n");
	if ((num_joysticks = SDL_NumJoysticks())) {
		for (i = 0; i < num_joysticks; i++) {
			ri.Con_Printf(PRINT_ALL, "Trying joystick [%s]\n",
			    SDL_JoystickName(i));
			if (!SDL_JoystickOpened(i)) {
				joy = SDL_JoystickOpen(i);
				if (joy) {
					ri.Con_Printf(PRINT_ALL, "Joytick activated.\n");
					joy_numbuttons = SDL_JoystickNumButtons(joy);
					break;
				}
			}
		}
		if (!joy) {
			ri.Con_Printf(PRINT_ALL, "Failed to open any joysticks\n");
			return false;
		}
	} else {
		ri.Con_Printf(PRINT_ALL, "No joysticks available\n");
		return false;
	}
	return true;
}
void SystemStub_SDL::destroy() {
	cleanupGfxMode();
	if (SDL_JoystickOpened(0)) {
		SDL_JoystickClose(_joystick);
	}
	SDL_Quit();
}
Beispiel #5
0
void event_initialize(void)
{
    const char *event_str = NULL;
    int i;

    /* set initial state of all joystick commands to 'off' */
    for (i = 0; i < NumJoyCommands; i++)
        JoyCmdActive[i] = 0;

    /* activate any joysticks which are referenced in the joystick event command strings */
    for (i = 0; i < NumJoyCommands; i++)
    {
        event_str = ConfigGetParamString(g_CoreConfig, JoyCmdName[i]);
        if (event_str != NULL && strlen(event_str) >= 4 && event_str[0] == 'J' && event_str[1] >= '0' && event_str[1] <= '9')
        {
            int device = event_str[1] - '0';
            if (!SDL_WasInit(SDL_INIT_JOYSTICK))
                SDL_InitSubSystem(SDL_INIT_JOYSTICK);
            if (!SDL_JoystickOpened(device))
                SDL_JoystickOpen(device);
        }
    }

    /* set up SDL event filter and disable key repeat */
    SDL_EnableKeyRepeat(0, 0);
    SDL_SetEventFilter(event_sdl_filter);
}
Beispiel #6
0
/* returns -1 on error, the (unchanged) joystick number (>=0) on success */
int open_joystick(int joy_no)
{
  if((joy_no > -1) && (joy_no < number_of_joysticks)) {
    if(SDL_JoystickOpened(joy_no)) {
#ifdef DEBUG_JOYSTICK
      fprintf(stderr, "open_joystick(): joystick %d already open\n", joy_no);
#endif
      return joy_no;
    } else {
      if((joystick) && !(joystick[joy_no] = SDL_JoystickOpen(joy_no))) {
       fprintf(stderr, "open_joystick(): could not open joystick %d\n", joy_no);
       return -1;
      } else {
#ifdef DEBUG_JOYSTICK
       fprintf(stderr, "open_joystick(): opened joystick %d\n", joy_no);
#endif
       return joy_no;
      }
    }
  } else {
    if(joy_no == -1) {
#ifdef DEBUG_JOYSTICK
      fprintf(stderr, "open_joystick(): joystick disabled");
#endif
    } else {
      fprintf(stderr, "open_joystick(): there is no joystick %d\n", joy_no);
    }
    return -1;
  }
}
Beispiel #7
0
void PERSDLJoyDeInit(void) {
	// close joysticks
	if ( SDL_PERCORE_INITIALIZED == 1 )
	{
		int i;
		for ( i = 0; i < SDL_PERCORE_JOYSTICKS_INITIALIZED; i++ )
		{
#if SDL_VERSION_ATLEAST(2,0,0)
         if ( SDL_PERCORE_JOYSTICKS[ i ].mJoystick )
#else
			if ( SDL_JoystickOpened( i ) )
#endif
         {
            SDL_JoystickClose( SDL_PERCORE_JOYSTICKS[ i ].mJoystick );

            free( SDL_PERCORE_JOYSTICKS[ i ].mScanStatus );
            free( SDL_PERCORE_JOYSTICKS[ i ].mHatStatus );
         }
		}
		free( SDL_PERCORE_JOYSTICKS );
	}
	
	SDL_PERCORE_JOYSTICKS_INITIALIZED = 0;
	SDL_PERCORE_INITIALIZED = 0;
	
	// close sdl joysticks
	SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
}
Beispiel #8
0
VOID
PAL_ShutdownInput(
   VOID
)
/*++
  Purpose:

    Shutdown the input subsystem.

  Parameters:

    None.

  Return value:

    None.

--*/
{
#ifdef PAL_HAS_JOYSTICKS
   if (SDL_JoystickOpened(0))
   {
      assert(g_pJoy != NULL);
      SDL_JoystickClose(g_pJoy);
      g_pJoy = NULL;
   }
#endif
}
Beispiel #9
0
void cJoystickSDL::Close() {
	if( SDL_JoystickOpened( mIndex ) )
		SDL_JoystickClose( mJoystick );

	mJoystick 	= NULL;
	mName		= "";
	mHats = mButtons = mAxes = mBalls = 0;
}
Beispiel #10
0
JNIEXPORT jint JNICALL Java_at_wisch_joystick_JoystickManager_openJoystick (JNIEnv *env, jclass, jint joystickIndex) {
	joysticks[joystickIndex] = SDL_JoystickOpen(joystickIndex);
	if (!SDL_JoystickOpened(joystickIndex)){
		throwException(env, SDL_GetError());
		return -2;
	}
	return 2;
}
Beispiel #11
0
int SCA_Joystick::Connected(void)
{
#ifdef WITH_SDL
	if (m_isinit && SDL_JoystickOpened(m_joyindex))
		return 1;
#endif
	return 0;
}
Beispiel #12
0
static void uninitTempJoystick(int i) {
	if(joysticks_inited_temp[i] && SDL_JoystickOpened(i)) {
		notes << "Uninit temporary loaded joystick " << i << endl;
		SDL_JoystickClose(joys[i]);
		joys[i] = NULL;
		joysticks_inited_temp[i] = false;
	}
}
Beispiel #13
0
void close_joystick( int joy_idx ){
  if ( !SDL_JoystickOpened( joy_idx ) ){
      lo_send_from( t, s, LO_TT_IMMEDIATE, "/joystick/close/error", "i", joy_idx );
      return;
  }
//   joy_map_t::const_iterator it;
  lo_send_from( t, s, LO_TT_IMMEDIATE, "/joystick/closed", "is", joy_idx, SDL_JoystickName( joy_idx ) );
  SDL_JoystickClose( joysticks.find( joy_idx )->second );
  joysticks.erase( joysticks.find( joy_idx ) );
}
Beispiel #14
0
//
// I_OpenJoystick
//
bool I_OpenJoystick()
{
	int numjoy;

	numjoy = I_GetJoystickCount();

	if(!numjoy || !use_joystick)
		return false;

	if((int)joy_active > numjoy)
		joy_active.Set(0.0);

	if(!SDL_JoystickOpened(joy_active))
		openedjoy = SDL_JoystickOpen(joy_active);

	if(!SDL_JoystickOpened(joy_active))
		return false;

	return true;
}
Beispiel #15
0
void ShutdownJoystick()
{
	int i;
	for (i = 0; i < JOY_LAST; ++i)
	{
		if(joy[i] && SDL_JoystickOpened(i))
		{
			SDL_JoystickClose(joy[i]);
		}
		joy[i] = 0;
	}
}
Beispiel #16
0
void SCA_Joystick::DestroyJoystickDevice(void)
{
#ifdef WITH_SDL
	if (m_isinit) {
		if (SDL_JoystickOpened(m_joyindex)) {
			echo("Closing-joystick " << m_joyindex);
			SDL_JoystickClose(m_private->m_joystick);
		}
		m_isinit = false;
	}
#endif /* WITH_SDL */
}
Beispiel #17
0
// Search attached devices. Populate joyinfo for all attached physical devices.
// -----------------------
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{
	if (!SDL_WasInit(0))
#if SDL_VERSION_ATLEAST(1, 3, 0)
		if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0)
#else
		if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
#endif
		{
			//PanicAlert("Could not initialize SDL: %s", SDL_GetError());
			return false;
		}

	// Get device status
	int numjoy = SDL_NumJoysticks();
	for (int i = 0; i < numjoy; i++ )
	{
		CONTROLLER_INFO Tmp;

		Tmp.joy			= SDL_JoystickOpen(i);
		Tmp.ID			= i;
		Tmp.NumAxes		= SDL_JoystickNumAxes(Tmp.joy);
		Tmp.NumButtons	= SDL_JoystickNumButtons(Tmp.joy);
		Tmp.NumBalls	= SDL_JoystickNumBalls(Tmp.joy);
		Tmp.NumHats		= SDL_JoystickNumHats(Tmp.joy);
		Tmp.Name		= SDL_JoystickName(i);

		// Check if the device is okay
		if (   Tmp.NumAxes == 0
			&&  Tmp.NumBalls == 0
			&&  Tmp.NumButtons == 0
			&&  Tmp.NumHats == 0
			)
		{
			Tmp.Good = false;
		}
		else
		{
			_NumGoodPads++;
			Tmp.Good = true;
		}

		_joyinfo.push_back(Tmp);

		// We have now read the values we need so we close the device
		if (SDL_JoystickOpened(i)) SDL_JoystickClose(_joyinfo[i].joy);
	}

	_NumPads = (int)_joyinfo.size();

	return true;
}
Beispiel #18
0
bool GP2X_Events::stop() {
	if(!SDL_JoystickOpened(0)) {
		return false;
	}

	m_running = false;
	int status;
	SDL_WaitThread(m_thread, &status);

	SDL_JoystickClose(m_joy);

	return true;	
}
/// The cleanup 
void do_quit()
{
	Mix_CloseAudio();

	if (SDL_JoystickOpened(0)) {
		SDL_JoystickClose( gamepad.sdlinfo );
	}

	SDL_Quit();

	
	exit(0);
}
Beispiel #20
0
//------------------------------------------------------------
void ofxSDLAppWindow::exitApp() {
	ofLog(OF_LOG_VERBOSE, "SDL OF app is being terminated!");
  
  // clean up SDL
  for (int j = 0; j < numJoys; j++) {
    if (joys[j] && SDL_JoystickOpened(j)) {
      SDL_JoystickClose(joys[j]);
      joys[j] = NULL;
    }
  }
  SDL_Quit();

	OF_EXIT_APP(0);
}
Beispiel #21
0
void es_joystick_opened(sdl_data *sd, int len,char *buff)
{
   int sendlen;
   char *bp, *start;
   int index, bool;
   
   bp = buff;
   index = get8(bp);
   bp = start = sdl_get_temp_buff(sd, 1);
   bool = SDL_JoystickOpened(index);
   put8(bp, bool);
   sendlen = bp - start;
   sdl_send(sd, sendlen);
}
void InputHandler_SDL::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
	vDevicesOut.push_back( DEVICE_KEYBOARD );
	vDescriptionsOut.push_back( "Keyboard" );

	for( int i=0; i<SDL_NumJoysticks(); i++ )
	{
		if( SDL_JoystickOpened(i) )
		{
			vDevicesOut.push_back( InputDevice(DEVICE_JOY1+i) );
			vDescriptionsOut.push_back( SDL_JoystickName(i) );
		}
	}
}
Beispiel #23
0
/**
 * input_sdl_end(): Shut down the SDL input subsystem.
 * @return 0 on success; non-zero on error.
 */
int input_sdl_end(void)
{
	// If any joysticks were opened, close them.
	for (unsigned int i = 0; i < INPUT_SDL_MAX_JOYSTICKS; i++)
	{
		if (SDL_JoystickOpened(i))
		{
			SDL_JoystickClose(input_sdl_joys[i]);
			input_sdl_joys[i] = NULL;
		}
	}
	
	return 0;
}
void CloseJoystick(void)
{
	int i,numSticks;
	SDL_Joystick *pStick;

	numSticks = SDL_NumJoysticks();
	for(i=0;i<numSticks;i++){
		if(SDL_JoystickOpened(i)){
			pStick = GetJoystickObjFromNum(i);
			SDL_JoystickClose(pStick);
		}
	}

}
Beispiel #25
0
static PyObject*
_sdl_joyopened (PyObject *self, PyObject *args)
{
    int joy;
    ASSERT_JOYSTICK_INIT(NULL);

    if (!IntFromObj (args, &joy))
        return NULL;
    if (joy < 0 || joy >= SDL_NumJoysticks())
    {
        PyErr_SetString (PyExc_ValueError, "invalid joystick index");
        return NULL;
    }
    return PyBool_FromLong (SDL_JoystickOpened (joy));
}
Beispiel #26
0
void JoystickInfo::Destroy()
{
	if (joy != NULL)
	{
#if SDL_VERSION_ATLEAST(1,3,0)
		// Haptic must be closed before the joystick
		if (haptic != NULL) {
			SDL_HapticClose(haptic);
			haptic = NULL;
		}
#endif

		if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy);
		joy = NULL;
	}
}
Beispiel #27
0
void JoyStick::open(int index)
{
	if (SDL_JoystickOpened(index))
	{
	}

	else {
		if (FAILED(m_joystick = SDL_JoystickOpen(index)))
		{
			// throw
		}

		else {
			m_index = index;
		}
	}
}
Beispiel #28
0
INLINE BOOL Input::Shutdown()
{
	Log(TAG "Terminating...");

	for (u32 i = 0; i < iJoystickCount; i++)
	{
		if (SDL_JoystickOpened(i))
			SDL_JoystickClose(parJoy[i]);
	}

	MEMSET(parJoy, '\0', sizeof(parJoy));

	BOOL r = this->Reset();
	Log(TAG "Terminated.");

	return r;
}
Beispiel #29
0
void open_joystick( int joy_idx ){
  if ( SDL_JoystickOpened( joy_idx ) ){
      return;
  }
  SDL_Joystick * newjoy = SDL_JoystickOpen( joy_idx );
  if (!newjoy)
  {
    fprintf(stderr, "Unable to open joystick %d\n", joy_idx);
    lo_send_from( t, s, LO_TT_IMMEDIATE, "/joystick/open/error", "i", joy_idx );
  }
  else
  {
    joysticks[ joy_idx ] = newjoy;
    lo_send_from( t, s, LO_TT_IMMEDIATE, "/joystick/open", "is", joy_idx, SDL_JoystickName( joy_idx ) );
//     /// add to the vector:
//     joysticks.push_back( newjoy );
  }
}
bool JoystickDevice::open()
{
	if(m_joyIndex == -1)
    {
    	LOG_WARN << "JoystickDevice: cannot open, index not set" << endl;
        return false;
    }

	if(SDL_JoystickOpened(m_joyIndex))
    {
    	LOG_WARN << "JoystickDevice: joystick with index "
        		 << m_joyIndex << " already opened" << endl;
        return false;
    }

	m_joystick = SDL_JoystickOpen(m_joyIndex);
    if(!m_joystick)
    {
    	LOG_WARN << "JoystickDevice: open failed for index " << m_joyIndex << endl;
        return false;
    }
    
    // try to set the address from the mapping list using the dev name
    m_oscAddress = m_config.getDeviceAddress((string) SDL_JoystickName(m_joyIndex));
    if(m_oscAddress == "")
    {
    	// not found ... set a generic name using the index
        stringstream stream;
        stream << "/js" << m_joyIndex;
        m_oscAddress = stream.str();
    }
    
    m_devName = SDL_JoystickName(m_joyIndex);
            
    // create prev axis values
    for(int i = 0; i < SDL_JoystickNumAxes(m_joystick); ++i)
    	m_prevAxisValues.push_back(0);
    
    LOG_DEBUG << "JoystickDevice: opened " << m_joyIndex
              << " \"" << m_devName << "\" with address "
              << m_oscAddress << endl;
    return true;
}