SDL_sysjoystick.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifdef SDL_JOYSTICK_EMSCRIPTEN
  20. #include <stdio.h> // For the definition of NULL
  21. #include "SDL_sysjoystick_c.h"
  22. #include "../SDL_joystick_c.h"
  23. #include "../usb_ids.h"
  24. static SDL_joylist_item *JoystickByIndex(int index);
  25. static SDL_joylist_item *SDL_joylist = NULL;
  26. static SDL_joylist_item *SDL_joylist_tail = NULL;
  27. static int numjoysticks = 0;
  28. EM_JS(int, SDL_GetEmscriptenJoystickVendor, (int device_index), {
  29. // Let's assume that if we're calling these function then the gamepad object definitely exists
  30. let gamepad = navigator['getGamepads']()[device_index];
  31. // Chrome, Edge, Opera: Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc)
  32. let vendor_str = 'Vendor: ';
  33. if (gamepad['id']['indexOf'](vendor_str) > 0) {
  34. let vendor_str_index = gamepad['id']['indexOf'](vendor_str) + vendor_str['length'];
  35. return parseInt(gamepad['id']['substr'](vendor_str_index, 4), 16);
  36. }
  37. // Firefox, Safari: 046d-c216-Logitech Dual Action (or 46d-c216-Logicool Dual Action)
  38. let id_split = gamepad['id']['split']('-');
  39. if (id_split['length'] > 1 && !isNaN(parseInt(id_split[0], 16))) {
  40. return parseInt(id_split[0], 16);
  41. }
  42. return 0;
  43. });
  44. EM_JS(int, SDL_GetEmscriptenJoystickProduct, (int device_index), {
  45. let gamepad = navigator['getGamepads']()[device_index];
  46. // Chrome, Edge, Opera: Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc)
  47. let product_str = 'Product: ';
  48. if (gamepad['id']['indexOf'](product_str) > 0) {
  49. let product_str_index = gamepad['id']['indexOf'](product_str) + product_str['length'];
  50. return parseInt(gamepad['id']['substr'](product_str_index, 4), 16);
  51. }
  52. // Firefox, Safari: 046d-c216-Logitech Dual Action (or 46d-c216-Logicool Dual Action)
  53. let id_split = gamepad['id']['split']('-');
  54. if (id_split['length'] > 1 && !isNaN(parseInt(id_split[1], 16))) {
  55. return parseInt(id_split[1], 16);
  56. }
  57. return 0;
  58. });
  59. EM_JS(int, SDL_IsEmscriptenJoystickXInput, (int device_index), {
  60. let gamepad = navigator['getGamepads']()[device_index];
  61. // Chrome, Edge, Opera: Xbox 360 Controller (XInput STANDARD GAMEPAD)
  62. // Firefox: xinput
  63. // TODO: Safari
  64. return gamepad['id']['toLowerCase']()['indexOf']('xinput') >= 0;
  65. });
  66. static EM_BOOL Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
  67. {
  68. SDL_joylist_item *item;
  69. int i;
  70. Uint16 vendor, product;
  71. bool is_xinput;
  72. SDL_LockJoysticks();
  73. if (JoystickByIndex(gamepadEvent->index) != NULL) {
  74. goto done;
  75. }
  76. item = (SDL_joylist_item *)SDL_malloc(sizeof(SDL_joylist_item));
  77. if (!item) {
  78. goto done;
  79. }
  80. SDL_zerop(item);
  81. item->index = gamepadEvent->index;
  82. vendor = SDL_GetEmscriptenJoystickVendor(gamepadEvent->index);
  83. product = SDL_GetEmscriptenJoystickProduct(gamepadEvent->index);
  84. is_xinput = SDL_IsEmscriptenJoystickXInput(gamepadEvent->index);
  85. // Use a generic VID/PID representing an XInput controller
  86. if (!vendor && !product && is_xinput) {
  87. vendor = USB_VENDOR_MICROSOFT;
  88. product = USB_PRODUCT_XBOX360_XUSB_CONTROLLER;
  89. }
  90. item->name = SDL_CreateJoystickName(vendor, product, NULL, gamepadEvent->id);
  91. if (!item->name) {
  92. SDL_free(item);
  93. goto done;
  94. }
  95. if (vendor && product) {
  96. item->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_UNKNOWN, vendor, product, 0, NULL, item->name, 0, 0);
  97. } else {
  98. item->guid = SDL_CreateJoystickGUIDForName(item->name);
  99. }
  100. if (is_xinput) {
  101. item->guid.data[14] = 'x'; // See SDL_IsJoystickXInput
  102. }
  103. item->mapping = SDL_strdup(gamepadEvent->mapping);
  104. if (!item->mapping) {
  105. SDL_free(item->name);
  106. SDL_free(item);
  107. goto done;
  108. }
  109. const int real_button_count = gamepadEvent->numButtons;
  110. const int real_axis_count = gamepadEvent->numAxes;
  111. int first_trigger_button = -1;
  112. int first_hat_button = -1;
  113. int num_buttons = gamepadEvent->numButtons;
  114. int num_axes = gamepadEvent->numAxes;
  115. bool triggers_are_buttons = false;
  116. if ((SDL_strcmp(gamepadEvent->mapping, "standard") == 0) && (num_buttons >= 16)) { // maps to a game console gamepad layout, turn the d-pad into a hat, treat triggers as analog.
  117. num_buttons -= 4; // 4 dpad buttons become a hat.
  118. first_hat_button = 12;
  119. if (num_axes == 4) { // Chrome gives the triggers analog button values, Firefox exposes them as extra axes. Both have the digital buttons.
  120. num_axes += 2; // the two trigger "buttons"
  121. triggers_are_buttons = true;
  122. }
  123. // dump the digital trigger buttons in any case.
  124. first_trigger_button = 6;
  125. num_buttons -= 2;
  126. }
  127. item->first_hat_button = first_hat_button;
  128. item->first_trigger_button = first_trigger_button;
  129. item->triggers_are_buttons = triggers_are_buttons;
  130. item->nhats = (first_hat_button >= 0) ? 1 : 0;
  131. item->naxes = num_axes;
  132. item->nbuttons = num_buttons;
  133. item->device_instance = SDL_GetNextObjectID();
  134. item->timestamp = gamepadEvent->timestamp;
  135. int buttonidx = 0;
  136. for (i = 0; i < real_button_count; i++, buttonidx++) {
  137. if (buttonidx == first_hat_button) {
  138. buttonidx += 4; // skip these buttons, we're treating them as hat input.
  139. } else if (buttonidx == first_trigger_button) {
  140. buttonidx += 2; // skip these buttons, we're treating them as axes.
  141. }
  142. item->analogButton[i] = gamepadEvent->analogButton[buttonidx];
  143. item->digitalButton[i] = gamepadEvent->digitalButton[buttonidx];
  144. }
  145. for (i = 0; i < real_axis_count; i++) {
  146. item->axis[i] = gamepadEvent->axis[i];
  147. }
  148. if (item->triggers_are_buttons) {
  149. item->axis[real_axis_count] = (gamepadEvent->analogButton[first_trigger_button] * 2.0f) - 1.0f;
  150. item->axis[real_axis_count+1] = (gamepadEvent->analogButton[first_trigger_button+1] * 2.0f) - 1.0f;
  151. }
  152. SDL_assert(item->nhats <= 1); // there is (currently) only ever one of these, faked from the d-pad buttons.
  153. if (first_hat_button != -1) {
  154. Uint8 value = SDL_HAT_CENTERED;
  155. // this currently expects the first button to be up, then down, then left, then right.
  156. if (gamepadEvent->digitalButton[first_hat_button + 0]) {
  157. value |= SDL_HAT_UP;
  158. }
  159. if (gamepadEvent->digitalButton[first_hat_button + 1]) {
  160. value |= SDL_HAT_DOWN;
  161. }
  162. if (gamepadEvent->digitalButton[first_hat_button + 2]) {
  163. value |= SDL_HAT_LEFT;
  164. }
  165. if (gamepadEvent->digitalButton[first_hat_button + 3]) {
  166. value |= SDL_HAT_RIGHT;
  167. }
  168. item->hat = value;
  169. }
  170. if (!SDL_joylist_tail) {
  171. SDL_joylist = SDL_joylist_tail = item;
  172. } else {
  173. SDL_joylist_tail->next = item;
  174. SDL_joylist_tail = item;
  175. }
  176. ++numjoysticks;
  177. SDL_PrivateJoystickAdded(item->device_instance);
  178. #ifdef DEBUG_JOYSTICK
  179. SDL_Log("Number of joysticks is %d", numjoysticks);
  180. #endif
  181. #ifdef DEBUG_JOYSTICK
  182. SDL_Log("Added joystick with index %d", item->index);
  183. #endif
  184. done:
  185. SDL_UnlockJoysticks();
  186. return 1;
  187. }
  188. static EM_BOOL Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
  189. {
  190. SDL_joylist_item *item = SDL_joylist;
  191. SDL_joylist_item *prev = NULL;
  192. SDL_LockJoysticks();
  193. while (item) {
  194. if (item->index == gamepadEvent->index) {
  195. break;
  196. }
  197. prev = item;
  198. item = item->next;
  199. }
  200. if (!item) {
  201. goto done;
  202. }
  203. if (item->joystick) {
  204. item->joystick->hwdata = NULL;
  205. }
  206. if (prev) {
  207. prev->next = item->next;
  208. } else {
  209. SDL_assert(SDL_joylist == item);
  210. SDL_joylist = item->next;
  211. }
  212. if (item == SDL_joylist_tail) {
  213. SDL_joylist_tail = prev;
  214. }
  215. // Need to decrement the joystick count before we post the event
  216. --numjoysticks;
  217. SDL_PrivateJoystickRemoved(item->device_instance);
  218. #ifdef DEBUG_JOYSTICK
  219. SDL_Log("Removed joystick with id %d", item->device_instance);
  220. #endif
  221. SDL_free(item->name);
  222. SDL_free(item->mapping);
  223. SDL_free(item);
  224. done:
  225. SDL_UnlockJoysticks();
  226. return 1;
  227. }
  228. // Function to perform any system-specific joystick related cleanup
  229. static void EMSCRIPTEN_JoystickQuit(void)
  230. {
  231. SDL_joylist_item *item = NULL;
  232. SDL_joylist_item *next = NULL;
  233. for (item = SDL_joylist; item; item = next) {
  234. next = item->next;
  235. SDL_free(item->mapping);
  236. SDL_free(item->name);
  237. SDL_free(item);
  238. }
  239. SDL_joylist = SDL_joylist_tail = NULL;
  240. numjoysticks = 0;
  241. emscripten_set_gamepadconnected_callback(NULL, 0, NULL);
  242. emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL);
  243. }
  244. // Function to scan the system for joysticks.
  245. static bool EMSCRIPTEN_JoystickInit(void)
  246. {
  247. int rc, i, numjs;
  248. EmscriptenGamepadEvent gamepadState;
  249. numjoysticks = 0;
  250. rc = emscripten_sample_gamepad_data();
  251. // Check if gamepad is supported by browser
  252. if (rc == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
  253. return SDL_SetError("Gamepads not supported");
  254. }
  255. numjs = emscripten_get_num_gamepads();
  256. // handle already connected gamepads
  257. if (numjs > 0) {
  258. for (i = 0; i < numjs; i++) {
  259. rc = emscripten_get_gamepad_status(i, &gamepadState);
  260. if (rc == EMSCRIPTEN_RESULT_SUCCESS) {
  261. Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
  262. &gamepadState,
  263. NULL);
  264. }
  265. }
  266. }
  267. rc = emscripten_set_gamepadconnected_callback(NULL,
  268. 0,
  269. Emscripten_JoyStickConnected);
  270. if (rc != EMSCRIPTEN_RESULT_SUCCESS) {
  271. EMSCRIPTEN_JoystickQuit();
  272. return SDL_SetError("Could not set gamepad connect callback");
  273. }
  274. rc = emscripten_set_gamepaddisconnected_callback(NULL,
  275. 0,
  276. Emscripten_JoyStickDisconnected);
  277. if (rc != EMSCRIPTEN_RESULT_SUCCESS) {
  278. EMSCRIPTEN_JoystickQuit();
  279. return SDL_SetError("Could not set gamepad disconnect callback");
  280. }
  281. return true;
  282. }
  283. // Returns item matching given SDL device index.
  284. static SDL_joylist_item *JoystickByDeviceIndex(int device_index)
  285. {
  286. SDL_joylist_item *item = SDL_joylist;
  287. while (0 < device_index) {
  288. --device_index;
  289. item = item->next;
  290. }
  291. return item;
  292. }
  293. // Returns item matching given HTML gamepad index.
  294. static SDL_joylist_item *JoystickByIndex(int index)
  295. {
  296. SDL_joylist_item *item = SDL_joylist;
  297. if (index < 0) {
  298. return NULL;
  299. }
  300. while (item) {
  301. if (item->index == index) {
  302. break;
  303. }
  304. item = item->next;
  305. }
  306. return item;
  307. }
  308. static int EMSCRIPTEN_JoystickGetCount(void)
  309. {
  310. return numjoysticks;
  311. }
  312. static void EMSCRIPTEN_JoystickDetect(void)
  313. {
  314. }
  315. static bool EMSCRIPTEN_JoystickIsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
  316. {
  317. // We don't override any other drivers
  318. return false;
  319. }
  320. static const char *EMSCRIPTEN_JoystickGetDeviceName(int device_index)
  321. {
  322. return JoystickByDeviceIndex(device_index)->name;
  323. }
  324. static const char *EMSCRIPTEN_JoystickGetDevicePath(int device_index)
  325. {
  326. return NULL;
  327. }
  328. static int EMSCRIPTEN_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index)
  329. {
  330. return -1;
  331. }
  332. static int EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index)
  333. {
  334. return -1;
  335. }
  336. static void EMSCRIPTEN_JoystickSetDevicePlayerIndex(int device_index, int player_index)
  337. {
  338. }
  339. static SDL_JoystickID EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
  340. {
  341. return JoystickByDeviceIndex(device_index)->device_instance;
  342. }
  343. static bool EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
  344. {
  345. SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
  346. bool rumble_available = false;
  347. if (!item) {
  348. return SDL_SetError("No such device");
  349. }
  350. if (item->joystick) {
  351. return SDL_SetError("Joystick already opened");
  352. }
  353. joystick->hwdata = (struct joystick_hwdata *)item;
  354. item->joystick = joystick;
  355. // HTML5 Gamepad API doesn't offer hats, but we can fake it from the d-pad buttons on the "standard" mapping.
  356. joystick->nhats = item->nhats;
  357. joystick->nbuttons = item->nbuttons;
  358. joystick->naxes = item->naxes;
  359. rumble_available = EM_ASM_INT({
  360. let gamepads = navigator['getGamepads']();
  361. if (!gamepads) {
  362. return 0;
  363. }
  364. let gamepad = gamepads[$0];
  365. if (!gamepad || !gamepad['vibrationActuator']) {
  366. return 0;
  367. }
  368. return 1;
  369. }, item->index);
  370. if (rumble_available) {
  371. SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true);
  372. }
  373. return true;
  374. }
  375. /* Function to update the state of a joystick - called as a device poll.
  376. * This function shouldn't update the joystick structure directly,
  377. * but instead should call SDL_PrivateJoystick*() to deliver events
  378. * and update joystick device state.
  379. */
  380. static void EMSCRIPTEN_JoystickUpdate(SDL_Joystick *joystick)
  381. {
  382. EmscriptenGamepadEvent gamepadState;
  383. SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
  384. int i, result;
  385. Uint64 timestamp = SDL_GetTicksNS();
  386. emscripten_sample_gamepad_data();
  387. if (item) {
  388. result = emscripten_get_gamepad_status(item->index, &gamepadState);
  389. if (result == EMSCRIPTEN_RESULT_SUCCESS) {
  390. if (gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
  391. const int first_hat_button = item->first_hat_button;
  392. const int first_trigger_button = item->first_trigger_button;
  393. const int real_button_count = gamepadState.numButtons;
  394. const int real_axis_count = gamepadState.numAxes;
  395. int buttonidx = 0;
  396. for (i = 0; i < real_button_count; i++, buttonidx++) {
  397. if (buttonidx == first_hat_button) {
  398. buttonidx += 4; // skip these buttons, we're treating them as hat input.
  399. } else if (buttonidx == first_trigger_button) {
  400. buttonidx += 2; // skip these buttons, we're treating them as axes.
  401. }
  402. if (item->digitalButton[i] != gamepadState.digitalButton[buttonidx]) {
  403. const bool down = (gamepadState.digitalButton[buttonidx] != 0);
  404. SDL_SendJoystickButton(timestamp, item->joystick, i, down);
  405. }
  406. // store values to compare them in the next update
  407. item->analogButton[i] = gamepadState.analogButton[buttonidx];
  408. item->digitalButton[i] = gamepadState.digitalButton[buttonidx];
  409. }
  410. for (i = 0; i < real_axis_count; i++) {
  411. if (item->axis[i] != gamepadState.axis[i]) {
  412. SDL_SendJoystickAxis(timestamp, item->joystick, i, (Sint16)(32767.0f * gamepadState.axis[i]));
  413. item->axis[i] = gamepadState.axis[i];
  414. }
  415. }
  416. if (item->triggers_are_buttons) {
  417. for (i = 0; i < 2; i++) {
  418. if (item->axis[real_axis_count+i] != gamepadState.analogButton[first_trigger_button+i]) {
  419. SDL_SendJoystickAxis(timestamp, item->joystick, real_axis_count+i, (Sint16)(32767.0f * ((gamepadState.analogButton[first_trigger_button+i] * 2.0f) - 1.0f)));
  420. item->axis[real_axis_count+i] = gamepadState.analogButton[first_trigger_button+i];
  421. }
  422. }
  423. }
  424. SDL_assert(item->nhats <= 1); // there is (currently) only ever one of these, faked from the d-pad buttons.
  425. if (item->nhats) {
  426. Uint8 value = SDL_HAT_CENTERED;
  427. // this currently expects the first button to be up, then down, then left, then right.
  428. if (gamepadState.digitalButton[first_hat_button + 0]) {
  429. value |= SDL_HAT_UP;
  430. } else if (gamepadState.digitalButton[first_hat_button + 1]) {
  431. value |= SDL_HAT_DOWN;
  432. }
  433. if (gamepadState.digitalButton[first_hat_button + 2]) {
  434. value |= SDL_HAT_LEFT;
  435. } else if (gamepadState.digitalButton[first_hat_button + 3]) {
  436. value |= SDL_HAT_RIGHT;
  437. }
  438. if (item->hat != value) {
  439. item->hat = value;
  440. SDL_SendJoystickHat(timestamp, item->joystick, 0, value);
  441. }
  442. }
  443. item->timestamp = gamepadState.timestamp;
  444. }
  445. }
  446. }
  447. }
  448. // Function to close a joystick after use
  449. static void EMSCRIPTEN_JoystickClose(SDL_Joystick *joystick)
  450. {
  451. SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
  452. if (item) {
  453. item->joystick = NULL;
  454. }
  455. }
  456. static SDL_GUID EMSCRIPTEN_JoystickGetDeviceGUID(int device_index)
  457. {
  458. return JoystickByDeviceIndex(device_index)->guid;
  459. }
  460. static bool EMSCRIPTEN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
  461. {
  462. SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata;
  463. // clang-format off
  464. bool result = EM_ASM_INT({
  465. let gamepads = navigator['getGamepads']();
  466. if (!gamepads) {
  467. return 0;
  468. }
  469. let gamepad = gamepads[$0];
  470. if (!gamepad || !gamepad['vibrationActuator']) {
  471. return 0;
  472. }
  473. gamepad['vibrationActuator']['playEffect']('dual-rumble', {
  474. 'startDelay': 0,
  475. 'duration': 3000,
  476. 'weakMagnitude': $2 / 0xFFFF,
  477. 'strongMagnitude': $1 / 0xFFFF,
  478. });
  479. return 1;
  480. }, item->index, low_frequency_rumble, high_frequency_rumble);
  481. return result;
  482. }
  483. static bool EMSCRIPTEN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
  484. {
  485. return SDL_Unsupported();
  486. }
  487. static bool EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
  488. {
  489. return false;
  490. }
  491. static bool EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
  492. {
  493. return SDL_Unsupported();
  494. }
  495. static bool EMSCRIPTEN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
  496. {
  497. return SDL_Unsupported();
  498. }
  499. static bool EMSCRIPTEN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled)
  500. {
  501. return SDL_Unsupported();
  502. }
  503. SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver = {
  504. EMSCRIPTEN_JoystickInit,
  505. EMSCRIPTEN_JoystickGetCount,
  506. EMSCRIPTEN_JoystickDetect,
  507. EMSCRIPTEN_JoystickIsDevicePresent,
  508. EMSCRIPTEN_JoystickGetDeviceName,
  509. EMSCRIPTEN_JoystickGetDevicePath,
  510. EMSCRIPTEN_JoystickGetDeviceSteamVirtualGamepadSlot,
  511. EMSCRIPTEN_JoystickGetDevicePlayerIndex,
  512. EMSCRIPTEN_JoystickSetDevicePlayerIndex,
  513. EMSCRIPTEN_JoystickGetDeviceGUID,
  514. EMSCRIPTEN_JoystickGetDeviceInstanceID,
  515. EMSCRIPTEN_JoystickOpen,
  516. EMSCRIPTEN_JoystickRumble,
  517. EMSCRIPTEN_JoystickRumbleTriggers,
  518. EMSCRIPTEN_JoystickSetLED,
  519. EMSCRIPTEN_JoystickSendEffect,
  520. EMSCRIPTEN_JoystickSetSensorsEnabled,
  521. EMSCRIPTEN_JoystickUpdate,
  522. EMSCRIPTEN_JoystickClose,
  523. EMSCRIPTEN_JoystickQuit,
  524. EMSCRIPTEN_JoystickGetGamepadMapping
  525. };
  526. #endif // SDL_JOYSTICK_EMSCRIPTEN