void initjoypad(void) { int num = 0; int i = 0; int chosen = 0; printf("Joypads detected %d\n", SDL_NumJoysticks()); if ((num = SDL_NumJoysticks()) > 0) { if(num > 1) chosen = detect_joypad(num); #ifdef PANDORA if(!SDL_strcmp(SDL_JoystickNameForIndex(chosen), "touchscreen")) { printf("Touchscreen is ignored as joystick.\n"); joypad = 0; return; } #endif joystick = SDL_JoystickOpen(chosen); if(joystick) { joypad = 1; printf("Using joystick: %s\n", SDL_JoystickNameForIndex(chosen)); strncpy(settings.joystickName, SDL_JoystickNameForIndex(chosen), 254); } else printf("Couldn't open Joystick %d\n", chosen); } }
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(); }
inline std::string joystick_name_at(int index) noexcept { const char* name = SDL_JoystickNameForIndex(index); if(name == nullptr) { return ""; } return { name }; }
bool XJoystickInit_old(int ErrHUsed) { JoystickAvailable = 0; XJoystickErrHUsed = ErrHUsed; SDL_InitSubSystem(SDL_INIT_JOYSTICK); //SDL_JoystickEventState(SDL_ENABLE); //SDL_JoystickEventState(SDL_IGNORE); // we will poll ourselves int nJoysticks = SDL_NumJoysticks(); // FIXME: pick first if (nJoysticks < 1) return false; std::cout<<"Found "<<nJoysticks<<" joysticks"<<std::endl; joy = SDL_JoystickOpen(0); if (!joy) return false; std::cout<<"Init joystick: "<<SDL_JoystickNameForIndex(0)<<std::endl; // set joystick parameters (deadzone, etc) if(!inputPrepareDevice()) { XJOYSTICK_ABORT("Device preparation failed\nXJoystick - Force Feedback", -1); return false; } // if we get here, we succeeded return true; /* */ } //*** end XJoystickInit()
int main(int argc, char *argv[]) { int num_joy, i; if(argc > 1) { printf("%s%s%s%s", "\nThis program lists the joysticks connected to the system.\n", "It returns a non-zero value if no joystick was found.\n", "The ouput format is:\nindex:JoystickName\n\n", "Usage: jslist\n\n"); return 1; } SDL_Init(SDL_INIT_JOYSTICK); num_joy = SDL_NumJoysticks(); if(num_joy < 1) { fputs("No joystick found!\n", stderr); SDL_Quit(); return -1; } for(i = 0; i < num_joy; i++) printf("%d:%s\n", i, SDL_JoystickNameForIndex(i)); SDL_Quit(); return 0; }
// static QVariantList Joystick::enumerateDevices() { QVariantList list; char guidbuf[128]; int nconnected = SDL_NumJoysticks(); if (!nconnected) { qCCritical(phxInput, "Unable to enumerate joysticks: %s", SDL_GetError()); } for (int i = 0; i < nconnected; i++) { const char* jsname = SDL_JoystickNameForIndex(i); if (!jsname) continue; SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), guidbuf, 128); list.append(QVariantMap { { "text", QString(jsname) }, // for QML model { "name", QString(jsname) }, { "driver", QString(SDL_IsGameController(i) ? "sdl_gamecontroller" : "sdl_joystick") }, { "guid", QString(guidbuf) } }); } return list; }
void input_joystick_init (void) { const char *name; int i; //Load joystick defaults joy_cfg.axis1 = 0; joy_cfg.axis2 = 1; joy_cfg.fire = 0; joy_cfg.bomb = 1; joy_cfg.pause = 2; for (i = 0; i < SDL_NumJoysticks(); ++i) { name = SDL_JoystickNameForIndex(i); SDL_Log(" Found Joystick %d: %s\n", i, name ? name : "Unknown Joystick"); joysticks[i] = SDL_JoystickOpen(i); if (joysticks[i] == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i, SDL_GetError()); } /* else { char guid[64]; SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), guid, sizeof (guid)); SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick)); SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick)); SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick)); SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick)); SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick)); SDL_Log(" guid: %s\n", guid); } */ } }
/* * Helper function to determine pre-calculated offset to certain joystick mappings */ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) { SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index); ControllerMapping_t *mapping; mapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); #if SDL_JOYSTICK_XINPUT if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) { mapping = s_pXInputMapping; } #endif #if defined(SDL_JOYSTICK_EMSCRIPTEN) if (!mapping && s_pEmscriptenMapping) { mapping = s_pEmscriptenMapping; } #endif if (!mapping) { const char *name = SDL_JoystickNameForIndex(device_index); if (name) { if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box")) { mapping = s_pXInputMapping; } } } return mapping; }
SDLApplication::SDLApplication () { if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); } currentApplication = this; framePeriod = 1000.0 / 60.0; #ifdef EMSCRIPTEN emscripten_cancel_main_loop (); emscripten_set_main_loop (UpdateFrame, 0, 0); emscripten_set_main_loop_timing (EM_TIMING_RAF, 1); #endif currentUpdate = 0; lastUpdate = 0; nextUpdate = 0; ApplicationEvent applicationEvent; GamepadEvent gamepadEvent; KeyEvent keyEvent; MouseEvent mouseEvent; RenderEvent renderEvent; SensorEvent sensorEvent; TextEvent textEvent; TouchEvent touchEvent; WindowEvent windowEvent; #if defined(IOS) || defined(ANDROID) for (int i = 0; i < SDL_NumJoysticks (); i++) { if (strstr (SDL_JoystickNameForIndex (i), "Accelerometer")) { accelerometer = SDL_JoystickOpen (i); accelerometerID = SDL_JoystickInstanceID (accelerometer); } } #endif #ifdef HX_MACOS CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ()); char path[PATH_MAX]; if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { chdir (path); } CFRelease (resourcesURL); #endif }
static std::string GetJoystickName(int index) { #if SDL_VERSION_ATLEAST(2, 0, 0) return SDL_JoystickNameForIndex(index); #else return SDL_JoystickName(index); #endif }
void IN_StartupJoystick (void) { int i; int nummappings; char controllerdb[MAX_OSPATH]; SDL_GameController *gamecontroller; if (COM_CheckParm("-nojoy")) return; if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1 ) { Con_Warning("could not initialize SDL Game Controller\n"); return; } // Load additional SDL2 controller definitions from gamecontrollerdb.txt q_snprintf (controllerdb, sizeof(controllerdb), "%s/gamecontrollerdb.txt", com_basedir); nummappings = SDL_GameControllerAddMappingsFromFile(controllerdb); if (nummappings > 0) Con_Printf("%d mappings loaded from gamecontrollerdb.txt\n", nummappings); // Also try host_parms->userdir if (host_parms->userdir != host_parms->basedir) { q_snprintf (controllerdb, sizeof(controllerdb), "%s/gamecontrollerdb.txt", host_parms->userdir); nummappings = SDL_GameControllerAddMappingsFromFile(controllerdb); if (nummappings > 0) Con_Printf("%d mappings loaded from gamecontrollerdb.txt\n", nummappings); } for (i = 0; i < SDL_NumJoysticks(); i++) { const char *joyname = SDL_JoystickNameForIndex(i); if ( SDL_IsGameController(i) ) { const char *controllername = SDL_GameControllerNameForIndex(i); gamecontroller = SDL_GameControllerOpen(i); if (gamecontroller) { Con_Printf("detected controller: %s\n", controllername != NULL ? controllername : "NULL"); joy_active_instaceid = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontroller)); joy_active_controller = gamecontroller; break; } else { Con_Warning("failed to open controller: %s\n", controllername != NULL ? controllername : "NULL"); } } else { Con_Warning("joystick missing controller mappings: %s\n", joyname != NULL ? joyname : "NULL" ); } } }
void Joystick_Init(void) { #ifndef PSP int i, nr_joys, nr_axes, nr_btns, nr_hats; #endif joy[0] = 1; // active only one joy[1] = 0; JoyKeyState = 0; JoyKeyState0 = 0; JoyKeyState1 = 0; JoyState0[0] = 0xff; JoyState0[1] = 0xff; JoyState1[0] = 0xff; JoyState1[1] = 0xff; JoyPortData[0] = 0; JoyPortData[1] = 0; #if defined(ANDROID) || TARGET_OS_IPHONE Joystick_Vbtn_Update(WinUI_get_vkscale()); #endif #ifndef PSP sdl_joy = 0; SDL_InitSubSystem(SDL_INIT_JOYSTICK); nr_joys = SDL_NumJoysticks(); p6logd("joy num %d\n", nr_joys); for (i = 0; i < nr_joys; i++) { sdl_joy = SDL_JoystickOpen(i); if (sdl_joy) { nr_btns = SDL_JoystickNumButtons(sdl_joy); nr_axes = SDL_JoystickNumAxes(sdl_joy); nr_hats = SDL_JoystickNumHats(sdl_joy); #if SDL_VERSION_ATLEAST(2, 0, 0) p6logd("Name: %s\n", SDL_JoystickNameForIndex(i)); #endif p6logd("# of Axes: %d\n", nr_axes); p6logd("# of Btns: %d\n", nr_btns); p6logd("# of Hats: %d\n", nr_hats); // skip accelerometer and keyboard if (nr_btns < 2 || (nr_axes < 2 && nr_hats == 0)) { Joystick_Cleanup(); sdl_joy = 0; } else { break; } } else { p6logd("can't open joy %d\n", i); } } #endif }
static const char* sdl_pad_name(unsigned id) { #ifdef HAVE_SDL2 if (sdl_pads[id].controller) return SDL_GameControllerNameForIndex(id); return SDL_JoystickNameForIndex(id); #else return SDL_JoystickName(id); #endif }
static mrb_value mrb_sdl2_joystick_get_name(mrb_state *mrb, mrb_value self) { const char * result; mrb_int index; mrb_get_args(mrb, "i", &index); result = SDL_JoystickNameForIndex((int) index); return mrb_str_new_cstr(mrb, result); }
//=========================================================================== // XJoystickInit // // Creates and initializes joysticks. // // Parameters: // // Returns: // //=========================================================================== bool XJoystickInit() { int i; SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_JoystickEventState(SDL_ENABLE); SDL_GameControllerEventState(SDL_ENABLE); if(!SDL_WasInit(SDL_INIT_JOYSTICK) && SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { std::cout<<"Unable to initialize the joystick subsystem"<<std::endl; return false; } for(i = 0; i < SDL_NumJoysticks(); ++i) { if (SDL_IsGameController(i)) { printf("Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i)); ctrl = SDL_GameControllerOpen(i); joy = SDL_GameControllerGetJoystick(ctrl); break; } else { printf("Index \'%s\' is not a compatible controller.\n", SDL_JoystickNameForIndex(i)); } } if (ctrl) { JoystickAvailable = 1; return true; } for(i = 0; i < SDL_NumJoysticks(); ++i) { joy = SDL_JoystickOpen(i); if (joy) { printf("Index \'%i\' is a compatible joystick, named \'%s\'\n", i, SDL_JoystickNameForIndex(i)); break; } } if (joy) { JoystickAvailable = 1; return true; } else { return false; } }
/* * Helper function to determine pre-calculated offset to certain joystick mappings */ static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) { SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index); ControllerMapping_t *mapping; mapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); #if SDL_JOYSTICK_XINPUT if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) { mapping = s_pXInputMapping; } #endif #if defined(SDL_JOYSTICK_EMSCRIPTEN) if (!mapping && s_pEmscriptenMapping) { mapping = s_pEmscriptenMapping; } #endif #ifdef __LINUX__ if (!mapping) { const char *name = SDL_JoystickNameForIndex(device_index); if (name) { if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) { /* The Linux driver xpad.c maps the wireless dpad to buttons */ SDL_bool existing; mapping = SDL_PrivateAddMappingForGUID(jGUID, "none,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,", &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT); } } } #endif /* __LINUX__ */ if (!mapping) { const char *name = SDL_JoystickNameForIndex(device_index); if (name) { if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box")) { mapping = s_pXInputMapping; } } } return mapping; }
/* * SDL.joystickNameForIndex(index) * * Arguments: * index the joystick index * * Returns: * The name or nil on failure * The error message */ static int l_joystickNameForIndex(lua_State *L) { int index = luaL_checkinteger(L, 1); const char *name; name = SDL_JoystickNameForIndex(index); if (name == NULL) return commonPushSDLError(L, 1); return commonPush(L, "s", name); }
static const char *sdl_joypad_name(unsigned pad) { if (pad >= MAX_USERS) return NULL; #ifdef HAVE_SDL2 if (sdl_pads[pad].controller) return SDL_GameControllerNameForIndex(pad); return SDL_JoystickNameForIndex(pad); #else return SDL_JoystickName(pad); #endif }
int input_pad_getinfos(int pad, padinfos *infos) { assert(pad<SDL_NumJoysticks()); if(statuspads[pad].joy==NULL) return 0; infos->name = SDL_JoystickNameForIndex(pad); infos->buttons = SDL_JoystickNumButtons(statuspads[pad].joy); infos->axis = SDL_JoystickNumAxes(statuspads[pad].joy); infos->hats = SDL_JoystickNumBalls(statuspads[pad].joy); return 1; }
void C4GamePadControl::CheckGamePad(const SDL_Event& e) { switch (e.type) { case SDL_JOYDEVICEADDED: // Report that an unsupported joystick device has been detected, to help with controller issues. if (!SDL_IsGameController(e.jdevice.which)) LogF("Gamepad %s isn't supported.", SDL_JoystickNameForIndex(e.jdevice.which)); break; case SDL_CONTROLLERDEVICEADDED: { auto device = std::make_shared<C4GamePadOpener>(e.cdevice.which); Gamepads[device->GetID()] = device; LogF("Gamepad #%d connected: %s", device->GetID(), SDL_JoystickNameForIndex(e.cdevice.which)); break; } case SDL_CONTROLLERDEVICEREMOVED: LogF("Gamepad #%d disconnected.", e.cdevice.which); Gamepads.erase(e.cdevice.which); break; } }
VOID PAL_InitInput( VOID ) /*++ Purpose: Initialize the input subsystem. Parameters: None. Return value: None. --*/ { memset((void *)&g_InputState, 0, sizeof(g_InputState)); g_InputState.dir = kDirUnknown; g_InputState.prevdir = kDirUnknown; // // Check for joystick // #if PAL_HAS_JOYSTICKS if (SDL_NumJoysticks() > 0 && g_fUseJoystick) { int i; for (i = 0; i < SDL_NumJoysticks(); i++) { if (PAL_IS_VALID_JOYSTICK(SDL_JoystickNameForIndex(i))) { g_pJoy = SDL_JoystickOpen(i); break; } } if (g_pJoy != NULL) { SDL_JoystickEventState(SDL_ENABLE); } } #endif input_init_filter(); }
void BMOP_EnumerateJoysticks(void *arg, void (*AnnounceNumJoysticks)(void *, unsigned), BMOP_JoystickEnumerator_t enumerator){ unsigned joystick_num = 0; SDL_Joystick *stick = NULL; if(!AnnounceNumJoysticks) AnnounceNumJoysticks = BMOP_DefaultNumJoysticks; if(!enumerator) enumerator = BMOP_DefaultJoystickEnumerator; AnnounceNumJoysticks(arg, SDL_NumJoysticks()); while((stick = SDL_JoystickOpen(joystick_num++))) enumerator(arg, SDL_JoystickNameForIndex(joystick_num-1), SDL_JoystickNumButtons(stick), SDL_JoystickNumAxes(stick), SDL_JoystickNumHats(stick)); }
void SDLJoystick::Init () { #if defined(IPHONE) || defined(ANDROID) || defined(TVOS) for (int i = 0; i < SDL_NumJoysticks (); i++) { if (strstr (SDL_JoystickNameForIndex (i), "Accelerometer")) { accelerometer = SDL_JoystickOpen (i); accelerometerID = SDL_JoystickInstanceID (accelerometer); } } #endif }
void SDLFrontend::initJoystickAndHaptic () { if (_haptic != nullptr) { SDL_HapticClose(_haptic); _haptic = nullptr; } const int joysticks = SDL_NumJoysticks(); SDL_Haptic *haptic = nullptr; for (int i = 0; i < joysticks; i++) { const char *name; if (SDL_IsGameController(i)) { name = SDL_GameControllerNameForIndex(i); } else { name = SDL_JoystickNameForIndex(i); } SDL_Joystick *joystick = SDL_JoystickOpen(i); info(LOG_CLIENT, String::format("found joystick %s", name ? name : "Unknown Joystick")); info(LOG_CLIENT, String::format("joystick axes: %i", SDL_JoystickNumAxes(joystick))); info(LOG_CLIENT, String::format("joystick hats: %i", SDL_JoystickNumHats(joystick))); info(LOG_CLIENT, String::format("joystick balls: %i", SDL_JoystickNumBalls(joystick))); info(LOG_CLIENT, String::format("joystick buttons: %i", SDL_JoystickNumButtons(joystick))); if (haptic == nullptr) haptic = SDL_HapticOpenFromJoystick(joystick); } if (!joysticks) { info(LOG_CLIENT, "no joysticks found"); } info(LOG_CLIENT, String::format("found %i touch device(s)", SDL_GetNumTouchDevices())); info(LOG_CLIENT, String::format("%i haptic devices", SDL_NumHaptics())); if (haptic == nullptr && SDL_MouseIsHaptic()) { haptic = SDL_HapticOpenFromMouse(); } if (haptic != nullptr) { const bool rumbleSupported = SDL_HapticRumbleSupported(haptic) && SDL_HapticRumbleInit(haptic) == 0; if (rumbleSupported) { info(LOG_CLIENT, "rumble support"); _haptic = haptic; } } if (_haptic == nullptr) { info(LOG_CLIENT, "no rumble support"); } }
/** * \brief This will start the joystick driver and search for all the controls attached * to your computer * \return false, if the driver couldn't be started, else true */ bool CInput::startJoyDriver() { gLogging.textOut("JoyDrv_Start() : "); if (SDL_Init( SDL_INIT_JOYSTICK ) < 0) { gLogging.ftextOut("JoyDrv_Start() : Couldn't initialize SDL: %s<br>", SDL_GetError()); return 1; } else { const size_t joyNum = SDL_NumJoysticks(); if( joyNum > 0 ) { SDL_JoystickEventState(SDL_ENABLE); gLogging.ftextOut("Detected %i joystick(s).<br>\n", joyNum ); gLogging.textOut("The names of the joysticks are:<br>"); for( size_t i=0; i < joyNum; i++ ) { #if SDL_VERSION_ATLEAST(2, 0, 0) gLogging.ftextOut(" %s<br>", SDL_JoystickNameForIndex(i)); #else gLogging.ftextOut(" %s<br>", SDL_JoystickName(i)); #endif SDL_Joystick *pJoystick = SDL_JoystickOpen(i); mp_Joysticks.push_back(pJoystick); gLogging.ftextOut(" Axes: %i<br>", SDL_JoystickNumAxes(pJoystick)); gLogging.ftextOut(" Buttons: %i <br>", SDL_JoystickNumButtons(pJoystick)); gLogging.ftextOut(" Balls: %i <br>", SDL_JoystickNumBalls(pJoystick)); gLogging.ftextOut(" Hats: %i<br>", SDL_JoystickNumHats(pJoystick)); } } else { gLogging.ftextOut("No joysticks were found.<br>\n"); } } return 0; }
static const char* gamepad_device_name_unmapped(int idx) { const char *name = SDL_GameControllerNameForIndex(idx); if(name == NULL) { return "Unknown device"; } if(!strcasecmp(name, "Xinput Controller")) { // HACK: let's try to get a more descriptive name... const char *prev_name = name; name = SDL_JoystickNameForIndex(idx); if(name == NULL) { name = prev_name; } } return name; }
static void initializeSDL2() { extern const char binaryGameVersion; printf("%s\n Wrapper v%s\n Game v%s\n", title, WRAPPER_VERSION, &binaryGameVersion); fflush(stdout); if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_GAMECONTROLLER) < 0) fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); const int n = SDL_NumJoysticks(); for (int i = 0; i < n; ++i) { const char *name = SDL_JoystickNameForIndex(i); if (name && strstr(name, "SynPS/2")) { touchpadJoyIdx = i; break; } } }
void CInput::Init() { m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>(); m_pConsole = Kernel()->RequestInterface<IConsole>(); // FIXME: unicode handling: use SDL_StartTextInput/SDL_StopTextInput on inputs MouseModeRelative(); if(!SDL_WasInit(SDL_INIT_JOYSTICK)) { if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { dbg_msg("joystick", "unable to init SDL joystick: %s", SDL_GetError()); return; } } if(SDL_NumJoysticks() > 0) { m_pJoystick = SDL_JoystickOpen(0); if(!m_pJoystick) { dbg_msg("joystick", "Could not open 0th joystick: %s", SDL_GetError()); return; } dbg_msg("joystick", "Opened Joystick 0"); dbg_msg("joystick", "Name: %s", SDL_JoystickNameForIndex(0)); dbg_msg("joystick", "Number of Axes: %d", SDL_JoystickNumAxes(m_pJoystick)); dbg_msg("joystick", "Number of Buttons: %d", SDL_JoystickNumButtons(m_pJoystick)); dbg_msg("joystick", "Number of Balls: %d", SDL_JoystickNumBalls(m_pJoystick)); } else { dbg_msg("joystick", "No joysticks found"); } }
void Joystick::open() { if (m_joystickHandle) { close(); } m_joystickHandle = SDL_JoystickOpen(m_deviceIndex); if (m_joystickHandle) { m_instanceId = SDL_JoystickInstanceID(m_joystickHandle); char tmp[33]; SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(m_deviceIndex); SDL_JoystickGetGUIDString(guid, tmp, sizeof(tmp)); m_guidStr = std::string(tmp); openController(); const char* name = SDL_JoystickNameForIndex(m_deviceIndex); if (isController() && !name) { name = SDL_GameControllerNameForIndex(m_deviceIndex); } m_name = std::string(name); } else { throw SDLException(SDL_GetError()); } }
bool input_init(void) { memset(inputs, 0, sizeof(inputs)); memset(lastinputs, 0, sizeof(lastinputs)); memset(mappings, -1, sizeof(mappings)); for (int i=0;i<INPUT_COUNT;i++) { mappings[i].key=-1; mappings[i].jbut=-1; mappings[i].jhat=-1; mappings[i].jaxis=-1; } // default mappings mappings[LEFTKEY].key = SDLK_LEFT; mappings[RIGHTKEY].key = SDLK_RIGHT; mappings[UPKEY].key = SDLK_UP; mappings[DOWNKEY].key = SDLK_DOWN; mappings[JUMPKEY].key = SDLK_z; mappings[FIREKEY].key = SDLK_x; mappings[PREVWPNKEY].key = SDLK_a; mappings[NEXTWPNKEY].key = SDLK_s; mappings[INVENTORYKEY].key = SDLK_q; mappings[MAPSYSTEMKEY].key = SDLK_w; mappings[ESCKEY].key = SDLK_ESCAPE; mappings[F1KEY].key = SDLK_F1; mappings[F2KEY].key = SDLK_F2; mappings[F3KEY].key = SDLK_F3; mappings[F4KEY].key = SDLK_F4; mappings[F5KEY].key = SDLK_F5; mappings[F6KEY].key = SDLK_F6; mappings[F7KEY].key = SDLK_F7; mappings[F8KEY].key = SDLK_F8; mappings[F9KEY].key = SDLK_F9; mappings[F10KEY].key = SDLK_F10; mappings[F11KEY].key = SDLK_F11; mappings[F12KEY].key = SDLK_F12; mappings[FREEZE_FRAME_KEY].key = SDLK_SPACE; mappings[FRAME_ADVANCE_KEY].key = SDLK_c; mappings[DEBUG_FLY_KEY].key = SDLK_v; mappings[HOMEKEY].key = SDLK_HOME; mappings[ENDKEY].key = SDLK_END; mappings[ENTERKEY].key = SDLK_RETURN; SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC); if (SDL_NumJoysticks() > 0) { // Open joystick joy = SDL_JoystickOpen(0); if (joy) { stat("Opened Joystick 0"); stat("Name: %s", SDL_JoystickNameForIndex(0)); stat("Number of Axes: %d", SDL_JoystickNumAxes(joy)); stat("Number of Buttons: %d", SDL_JoystickNumButtons(joy)); stat("Number of Balls: %d", SDL_JoystickNumBalls(joy)); haptic = SDL_HapticOpenFromJoystick( joy ); if (haptic == NULL) { stat("No force feedback support"); } else { if (SDL_HapticRumbleInit( haptic ) != 0) stat("Coiuldn't init simple rumble"); } } else { stat("Couldn't open Joystick 0"); } } return 0; }