22 #include <emscripten/emscripten.h>
25 #ifndef SDL_JOYSTICK_DISABLED
27 #define SCREEN_WIDTH 512
28 #define SCREEN_HEIGHT 320
83 const char *basetitle =
"Game Controller Test: ";
120 SDL_GameController *controller;
124 if (controller_id < 0) {
157 SDL_Log(
"Enabling accelerometer\n");
241 if (
axis > half_axis) {
256 switch (
event.type) {
263 SDL_Log(
"Game controller device %d removed.\n", (
int)
event.cdevice.which);
270 SDL_Log(
"Controller touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
271 event.ctouchpad.touchpad,
272 event.ctouchpad.finger,
278 event.ctouchpad.pressure);
282 SDL_Log(
"Controller sensor %s: %.2f, %.2f, %.2f\n",
285 event.csensor.data[0],
286 event.csensor.data[1],
287 event.csensor.data[2]);
338 if (on_front == showing_front) {
347 const Sint16 deadzone = 8000;
349 if (
value < -deadzone) {
353 }
else if (
value > deadzone) {
367 set_LED = (
x < -8000 ||
x > 8000 ||
y > 8000);
373 r = (
Uint8)(((
int)(~
x) * 255) / 32767);
377 b = (
Uint8)(((
int)(
x) * 255) / 32767);
380 g = (
Uint8)(((
int)(
y) * 255) / 32767);
411 #ifdef __EMSCRIPTEN__
413 emscripten_cancel_main_loop();
422 int controller_count = 0;
423 int controller_index = 0;
442 if (argv[1] &&
SDL_strcmp(argv[1],
"--mappings") == 0) {
443 SDL_Log(
"Supported mappings:\n");
457 const char *description;
460 guid,
sizeof (guid));
467 description =
"XBox 360 Controller";
470 description =
"XBox One Controller";
473 description =
"PS3 Controller";
476 description =
"PS4 Controller";
479 description =
"Nintendo Switch Pro Controller";
482 description =
"Virtual Game Controller";
485 description =
"Game Controller";
491 description =
"Joystick";
493 SDL_Log(
"%s %d: %s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
494 description,
i,
name ?
name :
"Unknown", guid,
538 if (argv[1] && *argv[1] !=
'-') {
539 controller_index =
SDL_atoi(argv[1]);
549 #ifdef __EMSCRIPTEN__
550 emscripten_set_main_loop_arg(
loop,
NULL, 0, 1);
567 main(
int argc,
char *argv[])
#define SDL_INIT_GAMECONTROLLER
#define SDL_INIT_JOYSTICK
#define SDL_GameControllerNumMappings
#define SDL_JoystickGetDeviceInstanceID
#define SDL_RenderPresent
#define SDL_GameControllerGetSerial
#define SDL_GameControllerHasSensor
#define SDL_DestroyWindow
#define SDL_GameControllerGetJoystick
#define SDL_JoystickGetDeviceProduct
#define SDL_DestroyRenderer
#define SDL_JoystickGetDeviceVendor
#define SDL_SetRenderDrawColor
#define SDL_CreateTextureFromSurface
#define SDL_GameControllerRumble
#define SDL_JoystickGetDevicePlayerIndex
#define SDL_GameControllerClose
#define SDL_JoystickNameForIndex
#define SDL_RenderSetLogicalSize
#define SDL_JoystickGetGUIDString
#define SDL_GameControllerSetSensorEnabled
#define SDL_GameControllerTypeForIndex
#define SDL_GameControllerGetStringForButton
#define SDL_CreateRenderer
#define SDL_GameControllerNameForIndex
#define SDL_JoystickGetDeviceGUID
#define SDL_LogSetPriority
#define SDL_GameControllerSetLED
#define SDL_GameControllerRumbleTriggers
#define SDL_GameControllerName
#define SDL_GameControllerOpen
#define SDL_GameControllerGetStringForAxis
#define SDL_SetTextureColorMod
#define SDL_GameControllerMappingForIndex
#define SDL_GameControllerGetButton
#define SDL_JoystickInstanceID
#define SDL_QuitSubSystem
#define SDL_GameControllerGetAxis
#define SDL_IsGameController
#define SDL_SetWindowTitle
@ SDL_CONTROLLERTOUCHPADDOWN
@ SDL_CONTROLLERTOUCHPADMOTION
@ SDL_CONTROLLERDEVICEADDED
@ SDL_CONTROLLERBUTTONDOWN
@ SDL_CONTROLLERAXISMOTION
@ SDL_CONTROLLERDEVICEREMOVED
@ SDL_CONTROLLERTOUCHPADUP
@ SDL_CONTROLLERSENSORUPDATE
@ SDL_CONTROLLER_AXIS_LEFTX
@ SDL_CONTROLLER_AXIS_TRIGGERRIGHT
@ SDL_CONTROLLER_AXIS_RIGHTY
@ SDL_CONTROLLER_AXIS_MAX
@ SDL_CONTROLLER_AXIS_TRIGGERLEFT
@ SDL_CONTROLLER_AXIS_LEFTY
#define SDL_GameControllerAddMappingsFromFile(file)
@ SDL_CONTROLLER_BUTTON_PADDLE1
@ SDL_CONTROLLER_BUTTON_TOUCHPAD
@ SDL_CONTROLLER_BUTTON_PADDLE4
@ SDL_CONTROLLER_TYPE_VIRTUAL
@ SDL_CONTROLLER_TYPE_XBOX360
@ SDL_CONTROLLER_TYPE_PS4
@ SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO
@ SDL_CONTROLLER_TYPE_PS3
@ SDL_CONTROLLER_TYPE_XBOXONE
#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK
A variable controlling whether the Android / iOS built-in accelerometer should be listed as a joystic...
#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE
A variable controlling whether extended input reports should be used for PS4 controllers when using t...
#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
A variable that lets you enable joystick (and gamecontroller) events even when your app is in the bac...
#define SDL_JOYSTICK_AXIS_MAX
@ SDL_LOG_CATEGORY_APPLICATION
GLint GLint GLint GLint GLint GLint y
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint x
GLboolean GLboolean GLboolean b
GLuint const GLchar * name
GLenum GLenum GLenum GLenum mapping
GLenum GLenum GLuint texture
GLsizei const GLfloat * value
#define SDL_LoadBMP(file)
#define SDL_WINDOWPOS_CENTERED
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
A rectangle, with the origin at the upper left (integer).
A collection of pixels used in software blitting.
The type used to identify a window.
static SDL_Renderer * renderer
int main(int argc, char *argv[])
static int FindController(SDL_JoystickID controller_id)
static const struct @466 button_positions[]
SDL_Texture * background_front
SDL_GameController * gamecontroller
static Uint16 ConvertAxisToRumble(Sint16 axis)
static SDL_Texture * LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
SDL_Texture * background_back
static void DelController(SDL_JoystickID controller)
static const struct @467 axis_positions[]
static void SetController(SDL_JoystickID controller)
SDL_GameController ** gamecontrollers
static void AddController(int device_index, SDL_bool verbose)
static void UpdateWindowTitle()