void print_joy_info() { printf("Name: %s\n", SDL_JoystickNameForIndex(0)); printf("Number of Axes: %d\n", SDL_JoystickNumAxes(gJoystick)); printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(gJoystick)); if(SDL_JoystickNumBalls(gJoystick) > 0) printf("Number of Balls: %d\n", SDL_JoystickNumBalls(gJoystick)); if(strncmp(SDL_JoystickNameForIndex(0), "PLAYSTATION(R)3 Controller", 25) == 0) { // PS3 Rumble controller via BT gControllerType = PS3_CONTROLLER; } if(strncmp(SDL_JoystickNameForIndex(0), "Sony PLAYSTATION(R)3 Controller", 30) == 0) { // PS3 directly connected gControllerType = PS3_CONTROLLER; } map_joy(); }
bool QJoystick::open(int stick) { if ( isOpen() ) close(); if(SDL_NumJoysticks() == 0) return false; joystick = SDL_JoystickOpen(stick); if ( joystick ) { joystickNameSelected = stick + 1; numAxes = SDL_JoystickNumAxes(joystick); numButtons = SDL_JoystickNumButtons(joystick); numHats = SDL_JoystickNumHats(joystick); numTrackballs = SDL_JoystickNumBalls(joystick); qWarning("DEBUG: SDL joystick %d opened; axes = %d, buttons = %d, hats = %d, trackballs = %d", stick, numAxes, numButtons, numHats, numTrackballs); axis_old_values.clear(); for(int i=0; i < numAxes; i++) axis_old_values.append(0); emit initJoystick(numAxes, numButtons, numHats, joystickNames.at(stick)); joystickTimer.start(eventTimeout); return true; } else { qWarning("ERROR: couldn't open SDL joystick %d", stick); return false; } }
void print_joystick_info(int joy_idx, SDL_Joystick* joy, SDL_GameController* gamepad) { SDL_JoystickGUID guid = SDL_JoystickGetGUID(joy); char guid_str[1024]; SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); printf("Joystick Name: '%s'\n", SDL_JoystickName(joy)); printf("Joystick GUID: %s\n", guid_str); printf("Joystick Number: %2d\n", joy_idx); printf("Number of Axes: %2d\n", SDL_JoystickNumAxes(joy)); printf("Number of Buttons: %2d\n", SDL_JoystickNumButtons(joy)); printf("Number of Hats: %2d\n", SDL_JoystickNumHats(joy)); printf("Number of Balls: %2d\n", SDL_JoystickNumBalls(joy)); printf("GameController:\n"); if (!gamepad) { printf(" not a gamepad\n"); } else { printf(" Name: '%s'\n", SDL_GameControllerName(gamepad)); printf(" Mapping: '%s'\n", SDL_GameControllerMappingForGUID(guid)); } printf("\n"); }
krad_rc_sdl_joy_t *krad_rc_sdl_joy_create (int joynum) { krad_rc_sdl_joy_t *krad_rc_sdl_joy = calloc(1, sizeof(krad_rc_sdl_joy_t)); int num_axes, num_buttons, num_balls, num_hats; krad_rc_sdl_joy->joynum = joynum; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); return NULL; } SDL_JoystickEventState (SDL_ENABLE); krad_rc_sdl_joy->joystick = SDL_JoystickOpen (krad_rc_sdl_joy->joynum); num_axes = SDL_JoystickNumAxes (krad_rc_sdl_joy->joystick); num_buttons = SDL_JoystickNumButtons (krad_rc_sdl_joy->joystick); num_balls = SDL_JoystickNumBalls (krad_rc_sdl_joy->joystick); num_hats = SDL_JoystickNumHats (krad_rc_sdl_joy->joystick); printf("%s: %d axes, %d buttons, %d balls, %d hats\n", SDL_JoystickName(krad_rc_sdl_joy->joynum), num_axes, num_buttons, num_balls, num_hats); krad_rc_sdl_joy->run = 1; pthread_create (&krad_rc_sdl_joy->joy_thread, NULL, krad_rc_sdl_joy_thread, (void *)krad_rc_sdl_joy); pthread_detach (krad_rc_sdl_joy->joy_thread); return krad_rc_sdl_joy; }
//-------------------------------------------------------------------------------------------------------------------// Application::Application(): mScreen(NULL), mEvent(), mIsItTimeToClose(false), mJoystick(NULL) { // On initialise la SDL. MTest_T_MSG (SDL_Init(SDL_INIT_EVERYTHING) == -1, "SDL Initialization Error : " << SDL_GetError()); // Log pour les Joysticks. MOut(SDL_NumJoysticks() << " joysticks connected"); for (int i = 0; i < SDL_NumJoysticks() ; ++i) { MOut("Joystick_" << i << " : " << SDL_JoystickName(i)); } if (SDL_NumJoysticks() > 0) { // On active la gestion des evenements des Joysticks. SDL_JoystickEventState(SDL_ENABLE); // On charge le premier Joystick connecté. mJoystick = SDL_JoystickOpen(0); MOut("----> " << SDL_JoystickNumButtons(mJoystick) << " buttons"); MOut("----> " << SDL_JoystickNumAxes(mJoystick) << " axes"); MOut("----> " << SDL_JoystickNumBalls(mJoystick) << " trackballs"); MOut("----> " << SDL_JoystickNumHats(mJoystick) << " hats"); } }
void controller_joystick_attach( Tank *t ) { JoystickPrivateData *data; /* Make sure that this is even a joystick to connect to: */ if(SDL_NumJoysticks() == 0) { /* TODO: exiting isn't all that friendly... we need a better controller API... */ gamelib_debug("No joysticks connected.\n"); exit(1); } data = get_object(JoystickPrivateData); data->joystick = SDL_JoystickOpen(0); if(data->joystick) { gamelib_debug("Using Joystick #0:\n"); gamelib_debug(" Name: %s\n", SDL_JoystickName(0)); gamelib_debug(" Axes: %d\n", SDL_JoystickNumAxes(data->joystick)); gamelib_debug(" Buttons: %d\n", SDL_JoystickNumButtons(data->joystick)); gamelib_debug(" Balls: %d\n", SDL_JoystickNumBalls(data->joystick)); } else { gamelib_debug("Failed to open Joystick #0.\n"); exit(1); } tank_set_controller(t, joystick_controller, data); }
int main(int, char**){ SDL_Init(SDL_INIT_JOYSTICK); SDL_JoystickEventState(SDL_ENABLE); atexit(SDL_Quit); int num_joysticks = SDL_NumJoysticks(); if(num_joysticks == 0) { std::cout << "No joysticks found! please attach a device and re-run this program" << std::endl; return 0; } js = SDL_JoystickOpen(0); //ok we've found our joystick! if (js) { SDL_JoystickGUID guid = SDL_JoystickGetGUID(js); char guid_str[1024]; SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); const char* name = SDL_JoystickName(js); int num_axes = SDL_JoystickNumAxes(js); int num_buttons = SDL_JoystickNumButtons(js); int num_hats = SDL_JoystickNumHats(js); int num_balls = SDL_JoystickNumBalls(js); std:: cout << guid_str << " \\ " << name << " \\ axes: " << num_axes << " buttons: " << num_buttons << " hats: " << num_hats << " balls: " << num_balls << std::endl; } //start webserver and bind to socket. handler handler_; http_server::options options(handler_); http_server server( options.address("0.0.0.0") .port("1111")); std::cout << "found joystick! starting server!" << std::endl; server.run(); //function BLOCKS! see handler struct at top of page! return 0; }
TGen::Engine::SDLGamepad::SDLGamepad(int id, int internalId) : TGen::Engine::InputDevice("gamepad", id) , joystick(NULL) { joystick = SDL_JoystickOpen(internalId); if (!joystick) throw TGen::RuntimeException("SDLGamepad::SDLGamepad", "failed to open joystick # ") << internalId << "!"; joyName = SDL_JoystickName(internalId); controls.numAxes = SDL_JoystickNumAxes(joystick); controls.numButtons = SDL_JoystickNumBalls(joystick); controls.numBalls = SDL_JoystickNumBalls(joystick); controls.numHats = SDL_JoystickNumHats(joystick); }
INLINE BOOL Input::Initialize() { Log(TAG "Initializing..."); BOOL r = this->Reset(); #if defined(WIN32) && defined(DEBUG) SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); #endif MEMSET(parJoy, '\0', sizeof(parJoy)); SDL_InitSubSystem(SDL_INIT_JOYSTICK); iJoystickCount = SDL_NumJoysticks(); if (iJoystickCount) { SDL_JoystickEventState(SDL_ENABLE); Log(TAG "Joystick(s): "); for (u32 i = 0; i < iJoystickCount; i++) { parJoy[i] = SDL_JoystickOpen(i); if (parJoy[i]) { Log("Opened Joystick %d:", i); Log(TAG "\tName: %s", SDL_JoystickName(i)); Log(TAG "\t\tAxes: %d", SDL_JoystickNumAxes(parJoy[i])); Log(TAG "\t\tButtons: %d", SDL_JoystickNumButtons(parJoy[i])); Log(TAG "\t\tHats: %d", SDL_JoystickNumHats(parJoy[i])); Log(TAG "\t\tBalls: %d", SDL_JoystickNumBalls(parJoy[i])); } } } Log(TAG "Initialization completed."); return r; }
/* Initialize joysticks */ BOOL init_joy(u16 joyCfg[]) { int i; set_joy_keys(default_joypad_cfg); if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { fprintf(stderr, "Error trying to initialize joystick support: %s\n", SDL_GetError()); return FALSE; } nbr_joy = SDL_NumJoysticks(); printf("Nbr of joysticks: %d\n\n", nbr_joy); for (i = 0; i < nbr_joy; i++) { SDL_Joystick * joy = SDL_JoystickOpen(i); printf("Joystick %s\n", i, SDL_JoystickName(i)); printf("Axes: %d\n", SDL_JoystickNumAxes(joy)); printf("Buttons: %d\n", SDL_JoystickNumButtons(joy)); printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy)); printf("Hats: %d\n\n", SDL_JoystickNumHats(joy)); } return TRUE; }
bool cJoystick :: OpenStick( unsigned int index ) { SDL_Joystick *Joystick = SDL_JoystickOpen( index ); if( !Joystick ) { printf( "Couldn't open joystick %d\n", index ); Opened = 0; return 0; } cur_stick = index; num_buttons = SDL_JoystickNumButtons( Joystick ); num_axes = SDL_JoystickNumAxes( Joystick ); num_balls = SDL_JoystickNumBalls( Joystick ); if( Debug ) { printf( "Opened Joystick %d\n", index ); printf( "Name: %s\n", SDL_JoystickName( index ) ); printf( "Number of Axes: %d\n", num_axes ); printf( "Number of Buttons: %d\n", num_buttons ); printf( "Number of Balls: %d\n\n", num_balls ); } Opened = 1; return 1; }
static PyObject* joy_get_ball (PyObject* self, PyObject* args) { int joy_id = PyJoystick_AsID (self); SDL_Joystick* joy = joystick_stickdata[joy_id]; int _index, dx, dy; Uint32 value; if (!PyArg_ParseTuple (args, "i", &_index)) { return NULL; } JOYSTICK_INIT_CHECK (); if (!joy) { return RAISE (PyExc_SDLError, "Joystick not initialized"); } value = SDL_JoystickNumBalls (joy); #ifdef DEBUG /*printf("SDL_JoystickNumBalls value:%d:\n", value);*/ #endif if (_index < 0 || _index >= value) { return RAISE (PyExc_SDLError, "Invalid joystick trackball"); } SDL_JoystickGetBall (joy, _index, &dx, &dy); return Py_BuildValue ("(ii)", dx, dy); }
/** * @brief Makes the game use a joystick by index. * * @param indjoystick Index of the joystick to use. * @return 0 on success. */ int joystick_use( int indjoystick ) { /* Check to see if it exists. */ if ((indjoystick < 0) || (indjoystick >= SDL_NumJoysticks())) { WARN("Joystick of index number %d does not existing, switching to default 0", indjoystick); indjoystick = 0; } /* Close if already open. */ if (joystick != NULL) { SDL_JoystickClose(joystick); joystick = NULL; } /* Start using joystick. */ joystick = SDL_JoystickOpen(indjoystick); if (joystick == NULL) { WARN("Error opening joystick %d [%s]", indjoystick, SDL_JoystickName(indjoystick)); return -1; } LOG("Using joystick %d - %s", indjoystick, SDL_JoystickName(indjoystick)); DEBUG(" with %d axes, %d buttons, %d balls and %d hats", SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick), SDL_JoystickNumBalls(joystick), SDL_JoystickNumHats(joystick)); /* Initialize the haptic if possible. */ joystick_initHaptic(); /* For style purposes. */ DEBUG(); return 0; }
int gui_init_sdl() { if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) == -1 ) { fprintf(stderr, "Couldn’t initialize SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); int joystick = 0, x = 0; joystick = SDL_NumJoysticks(); printf("Joysticks spotted : %d\n", joystick); for (x = 0; x < joystick; x++) { SDL_Joystick * joy = SDL_JoystickOpen(x); printf("Joystick %i: %s\n", x, SDL_JoystickName(x)); printf("Axes: %d\n", SDL_JoystickNumAxes(joy)); printf("Boutons: %d\n", SDL_JoystickNumButtons(joy)); printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy)); printf("Hats: %d\n\n", SDL_JoystickNumHats(joy)); } myscreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); if( myscreen == NULL ) { fprintf(stderr, "Couldn’t initialize VideoMode: %s\n", SDL_GetError()); return 0; } if( TTF_Init() == -1 ) { printf("TTF_Init() failed : %s\n", SDL_GetError()); return 0; } font = TTF_OpenFont( "data/font.ttf", 16); if( font == NULL ) { printf("TTF_OpenFont failed : %s\n", SDL_GetError()); return 0; } font_big = TTF_OpenFont( "data/font.ttf", 20); if( font == NULL ) { printf("TTF_OpenFont failed : %s\n", SDL_GetError()); return 0; } #ifndef PANDORA SDL_ShowCursor(SDL_ENABLE); #else SDL_ShowCursor(SDL_DISABLE); #endif return 1; }
JNIEXPORT jint JNICALL Java_at_wisch_joystick_Joystick_getNoOfBalls (JNIEnv *env, jclass, jint joystickIndex){ int num = SDL_JoystickNumBalls(joysticks[joystickIndex]); if (num < 0) { throwException(env, SDL_GetError()); return -10; } return num; }
int libjoy_balls_specific( int joy ) { if ( joy >= 0 && joy < _max_joys ) { return SDL_JoystickNumBalls( _joysticks[ joy ] ) ; } return 0 ; }
int libjoy_balls( void ) { if ( _selected_joystick >= 0 && _selected_joystick < _max_joys ) { return SDL_JoystickNumBalls( _joysticks[ _selected_joystick ] ) ; } return 0 ; }
SDLIntegration::SDLIntegration() { _verbose = false; // init SDL if ( SDL_Init(SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); int numJoysticks = SDL_NumJoysticks(); if (_verbose) { std::cout<<"number of joysticks "<<numJoysticks<<std::endl; for(int i=0; i<numJoysticks; ++i) { std::cout<<"Joystick name '"<<SDL_JoystickName(i)<<"'"<<std::endl; } } _joystick = numJoysticks>0 ? SDL_JoystickOpen(0) : 0; _numAxes = _joystick ? SDL_JoystickNumAxes(_joystick) : 0; _numBalls = _joystick ? SDL_JoystickNumBalls(_joystick) : 0; _numHats = _joystick ? SDL_JoystickNumHats(_joystick) : 0; _numButtons = _joystick ? SDL_JoystickNumButtons(_joystick) : 0; if (_verbose) { std::cout<<"numAxes = "<<_numAxes<<std::endl; std::cout<<"numBalls = "<<_numBalls<<std::endl; std::cout<<"numHats = "<<_numHats<<std::endl; std::cout<<"numButtons = "<<_numButtons<<std::endl; } addMouseButtonMapping(4, 1); // left addMouseButtonMapping(5, 3); // right addMouseButtonMapping(6, 2); // middle addKeyMapping(10, ' '); // R2 addKeyMapping(0, '1'); // 1 addKeyMapping(1, '2'); // 2 addKeyMapping(2, '3'); // 3 addKeyMapping(4, '4'); // 4 addKeyMapping(7, ' '); // home addKeyMapping(8, osgGA::GUIEventAdapter::KEY_Page_Up); // Start addKeyMapping(9, osgGA::GUIEventAdapter::KEY_Page_Down); // Start addKeyMapping(10, osgGA::GUIEventAdapter::KEY_Home); // Start capture(_axisValues, _buttonValues); }
/* =============== IN_InitJoystick =============== */ static void IN_InitJoystick( void ) { int i = 0; int total = 0; char buf[16384] = ""; for( i = 0; i < NUM_JOYSTICKS; i++ ) { if (sticks[i] != NULL) SDL_JoystickClose(sticks[i]); } for( i = 0; i < NUM_JOYSTICKS; i++ ) { sticks[i] = NULL; memset(&stick_state[i], 0, sizeof (stick_state[i])); } if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { Com_DPrintf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n"); if (SDL_Init(SDL_INIT_JOYSTICK) == -1) { Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError()); return; } Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) passed.\n"); } total = SDL_NumJoysticks(); Com_DPrintf("%d possible joysticks\n", total); // Print list and build cvar to allow ui to select joystick. for ( i = 0; i < total; i++ ) { Q_strcat(buf, sizeof(buf), SDL_JoystickName(i)); Q_strcat(buf, sizeof(buf), "\n"); } Cvar_Get( "in_availableJoysticks", buf, CVAR_ROM ); for( i = 0; i < NUM_JOYSTICKS; i++ ) { sticks[i] = SDL_JoystickOpen( i ); if (sticks[i] == NULL) { Com_DPrintf( "No joystick opened.\n" ); return; } Com_DPrintf( "Joystick %d opened\n", i ); Com_DPrintf( "Name: %s\n", SDL_JoystickName(i) ); Com_DPrintf( "Axes: %d\n", SDL_JoystickNumAxes(sticks[i]) ); Com_DPrintf( "Hats: %d\n", SDL_JoystickNumHats(sticks[i]) ); Com_DPrintf( "Buttons: %d\n", SDL_JoystickNumButtons(sticks[i]) ); Com_DPrintf( "Balls: %d\n", SDL_JoystickNumBalls(sticks[i]) ); } }
bool C_GamepadManager::Initialize() { // ジョイスティックが初期化されていない場合 if( SDL_WasInit( SDL_INIT_JOYSTICK ) == 0 ) { // ジョイスティックを初期化 SDL_InitSubSystem( SDL_INIT_JOYSTICK ); } // ゲームパッドの総数を取得 gamepadTotalNumber_ = SDL_NumJoysticks(); // ゲームパッドが接続されていない場合 if ( gamepadTotalNumber_ == 0 ) { std::cout << "[ C_GamepadManager::Initialize ] : ゲームパッドが接続されていません。" << std::endl; return true; } for ( int i = 0; i < gamepadTotalNumber_; ++i ) { // ゲームパッドの情報 S_GamepadData gamepadData; // ゲームパッドを開く gamepadData.pGamepad_ = SDL_JoystickOpen( i ); // ゲームパッドの取得に失敗した場合 if( gamepadData.pGamepad_ == nullptr ) { std::cout << "[ C_GamepadManager::Initialize ] : ゲームパッドを開くのに失敗しました。" << std::endl; std::cout << " エラー内容 : " << SDL_GetError() << std::endl; break; } // ゲームパッドの情報を追加 gamepadDatas_.push_back( gamepadData ); gamepadDatas_[i].name_ = SDL_JoystickName( gamepadDatas_[i].pGamepad_ ); // ゲームパッドの情報を出力 std::cout << "[ C_GamepadManager::Initialize ] : Name : " << gamepadDatas_[i].name_ << std::endl; std::cout << " AxesNumber : " << SDL_JoystickNumAxes( gamepadDatas_[i].pGamepad_ ) << std::endl; std::cout << " ButtonNumber : " << SDL_JoystickNumButtons( gamepadDatas_[i].pGamepad_ ) << std::endl; std::cout << " BallNumber : " << SDL_JoystickNumBalls( gamepadDatas_[i].pGamepad_ ) << std::endl; std::cout << " HatNumber : " << SDL_JoystickNumHats( gamepadDatas_[i].pGamepad_ ) << std::endl; } // イベントのポーリングを無効にする if ( SDL_JoystickEventState( SDL_IGNORE ) < 0 ) { std::cout << "[ C_JoystickManager::Initialize ] : イベントのポーリングの設定に失敗しました。" << std::endl; std::cout << " エラー内容 : " << SDL_GetError() << std::endl; } return true; }
//On affiche les informations du Joysticks void print_joystick_info(int joy_idx, SDL_Joystick* joy) { printf("Nom du Joystick: '%s'\n", SDL_JoystickName(joy_idx)); printf("Numéro du Joystick: %2d\n", joy_idx); printf("Nombre d'axes : %2d\n", SDL_JoystickNumAxes(joy)); printf("Nombre de bouttons : %2d\n", SDL_JoystickNumButtons(joy)); printf("Nombre de chapeaux : %2d\n", SDL_JoystickNumHats(joy)); printf("Nombre de boules : %2d\n", SDL_JoystickNumBalls(joy)); printf("\n"); }
void Joystick::init() { //Open the joystick and record all the data about the joystick. m_pJoystick = SDL_JoystickOpen(m_iNum); m_iAxes = SDL_JoystickNumAxes(m_pJoystick); m_iButtons = SDL_JoystickNumButtons(m_pJoystick); m_iHats = SDL_JoystickNumHats(m_pJoystick); m_iBalls = SDL_JoystickNumBalls(m_pJoystick); m_sName = SDL_JoystickName(m_iNum); }
void print_joystick_info(int joy_idx, SDL_Joystick* joy) { printf("Joystick Name: '%s'\n", SDL_JoystickName(joy_idx)); printf("Joystick Number: %2d\n", joy_idx); printf("Number of Axes: %2d\n", SDL_JoystickNumAxes(joy)); printf("Number of Buttons: %2d\n", SDL_JoystickNumButtons(joy)); printf("Number of Hats: %2d\n", SDL_JoystickNumHats(joy)); printf("Number of Balls: %2d\n", SDL_JoystickNumBalls(joy)); printf("\n"); }
bool JoystickController::bindJoystickKey(SDL_Joystick *joy, KM_Key &k) { int val=0, dx=0, dy=0; //SDL_PumpEvents(); SDL_JoystickUpdate(); for(int i=0; i<SDL_JoystickNumBalls(joy);i++) { dx=0; dy=0; SDL_JoystickGetBall(joy, i, &dx, &dy); if(dx!=0) { k.val=dx; k.id=i; k.type=(int)KeyMapJoyCtrls::JoyBallX; return true; }else if(dy!=0) { k.val=dy; k.id=i; k.type=(int)KeyMapJoyCtrls::JoyBallY; return true; } } for(int i=0; i<SDL_JoystickNumHats(joy);i++) { val=0; val=SDL_JoystickGetHat(joy, i); if(val!=0) { k.val=val; k.id=i; k.type=(int)KeyMapJoyCtrls::JoyHat; return true; } } for(int i=0; i<SDL_JoystickNumButtons(joy);i++) { val=0; val=SDL_JoystickGetButton(joy, i); if(val==1) { k.val=val; k.id=i; k.type=(int)KeyMapJoyCtrls::JoyButton; return true; } } k.val=0; k.id=0; k.type=(int)KeyMapJoyCtrls::NoControl; return false; }
// bk001130 - from cvs1.17 (mkv), removed from linux_glimp.c void IN_StartupJoystick( void ) { int i = 0; int total = 0; if (stick != NULL) SDL_JoystickClose(stick); stick = NULL; memset(&stick_state, '\0', sizeof (stick_state)); if( !in_joystick->integer ) { Com_Printf( "Joystick is not active.\n" ); return; } if (!SDL_WasInit(SDL_INIT_JOYSTICK)) { Com_Printf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n"); if (SDL_Init(SDL_INIT_JOYSTICK) == -1) { Com_Printf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError()); return; } Com_Printf("SDL_Init(SDL_INIT_JOYSTICK) passed.\n"); } total = SDL_NumJoysticks(); Com_Printf("I see %d possible joysticks\n", total); for (i = 0; i < total; i++) Com_Printf("[%d] %s\n", i, SDL_JoystickName(i)); in_joystickNo = Cvar_Get( "in_joystickNo", "0", CVAR_ARCHIVE ); if( in_joystickNo->integer < 0 || in_joystickNo->integer >= total ) Cvar_Set( "in_joystickNo", "0" ); stick = SDL_JoystickOpen( in_joystickNo->integer ); if (stick == NULL) { Com_Printf( "No joystick opened.\n" ); return; } Com_Printf( "Joystick %d opened\n", in_joystickNo->integer ); Com_Printf( "Name: %s\n", SDL_JoystickName(in_joystickNo->integer) ); Com_Printf( "Axes: %d\n", SDL_JoystickNumAxes(stick) ); Com_Printf( "Hats: %d\n", SDL_JoystickNumHats(stick) ); Com_Printf( "Buttons: %d\n", SDL_JoystickNumButtons(stick) ); Com_Printf( "Balls: %d\n", SDL_JoystickNumBalls(stick) ); SDL_JoystickEventState(SDL_QUERY); /* Our work here is done. */ return; }
int libjoy_get_ball( int ball, int * dx, int * dy ) { if ( _selected_joystick >= 0 && _selected_joystick < _max_joys ) { if ( ball >= 0 && ball <= SDL_JoystickNumBalls( _joysticks[ball] ) ) { return SDL_JoystickGetBall( _joysticks[ _selected_joystick ], ball, dx, dy ) ; } } return -1 ; }
int libjoy_get_ball_specific( int joy, int ball, int * dx, int * dy ) { if ( joy >= 0 && joy < _max_joys ) { if ( ball >= 0 && ball <= SDL_JoystickNumBalls( _joysticks[ joy ] ) ) { return SDL_JoystickGetBall( _joysticks[ joy ], ball, dx, dy ) ; } } return -1 ; }
static mrb_value mrb_sdl2_joystick_joystick_get_num_buttons(mrb_state *mrb, mrb_value self) { SDL_Joystick * joystick_p = mrb_sdl2_joystick_joystick_get_ptr(mrb, self); int result = SDL_JoystickNumBalls(joystick_p); if (result < 1) { mruby_sdl2_raise_error(mrb); } return mrb_fixnum_value(result); }
//numballsjoystick(i) : Get the number of joystick trackballs int numballsjoystick(int index) { int ret; SDL_JoystickUpdate(); if (SDLjoy[index]) ret= SDL_JoystickNumBalls(SDLjoy[index]); else ret=-1; return ret; }
//initalizes all game systems int game_system_init(game_system_t* sys){ //initalization if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0){ printf(M_SDL_INIT_ERROR); exit(0); } //depth and color buffer properities SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); //joystick initalization if(SDL_NumJoysticks() < 1){ printf("No joysticks found\n"); } SDL_Joystick *joy = SDL_JoystickOpen(0); if(joy != NULL){ printf("Opened Joystick 0\n"); printf("Name: %s\n", SDL_JoystickName(0)); printf("Number of Axes: %d\n", SDL_JoystickNumAxes(0)); printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joy)); printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joy)); } //init random number generator srand(time(0)); //renderer renderer_init(&sys->renderer); default_game_renderer_settings(&sys->renderer); //load default settings renderer_reload(&sys->renderer); //set inital state sys->state = STATE_INTRO; //read record sys->best_score = 0; FILE* best = fopen("data/best","r"); if(best == NULL){ best = fopen("data/best","w"); fprintf(best,"%d",0); } else{ fscanf(best,"%d",&sys->best_score); } fclose(best); return 0; }