SDL_hidapijoystick.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 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_HIDAPI
  20. #include "SDL_assert.h"
  21. #include "SDL_atomic.h"
  22. #include "SDL_endian.h"
  23. #include "SDL_hints.h"
  24. #include "SDL_log.h"
  25. #include "SDL_thread.h"
  26. #include "SDL_timer.h"
  27. #include "SDL_joystick.h"
  28. #include "../SDL_sysjoystick.h"
  29. #include "SDL_hidapijoystick_c.h"
  30. #include "SDL_hidapi_rumble.h"
  31. #include "../../SDL_hints_c.h"
  32. #if defined(__WIN32__)
  33. #include "../../core/windows/SDL_windows.h"
  34. #include "../windows/SDL_rawinputjoystick_c.h"
  35. #endif
  36. #if defined(__MACOSX__)
  37. #include <CoreFoundation/CoreFoundation.h>
  38. #include <mach/mach.h>
  39. #include <IOKit/IOKitLib.h>
  40. #include <IOKit/hid/IOHIDDevice.h>
  41. #include <IOKit/usb/USBSpec.h>
  42. #endif
  43. #if defined(__LINUX__)
  44. #include "../../core/linux/SDL_udev.h"
  45. #ifdef SDL_USE_LIBUDEV
  46. #include <poll.h>
  47. #endif
  48. #endif
  49. struct joystick_hwdata
  50. {
  51. SDL_HIDAPI_Device *device;
  52. };
  53. static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
  54. #ifdef SDL_JOYSTICK_HIDAPI_PS4
  55. &SDL_HIDAPI_DriverPS4,
  56. #endif
  57. #ifdef SDL_JOYSTICK_HIDAPI_STEAM
  58. &SDL_HIDAPI_DriverSteam,
  59. #endif
  60. #ifdef SDL_JOYSTICK_HIDAPI_SWITCH
  61. &SDL_HIDAPI_DriverSwitch,
  62. #endif
  63. #ifdef SDL_JOYSTICK_HIDAPI_XBOX360
  64. &SDL_HIDAPI_DriverXbox360,
  65. &SDL_HIDAPI_DriverXbox360W,
  66. #endif
  67. #ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
  68. &SDL_HIDAPI_DriverXboxOne,
  69. #endif
  70. #ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
  71. &SDL_HIDAPI_DriverGameCube,
  72. #endif
  73. };
  74. static int SDL_HIDAPI_numdrivers = 0;
  75. static SDL_SpinLock SDL_HIDAPI_spinlock;
  76. static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
  77. static int SDL_HIDAPI_numjoysticks = 0;
  78. static SDL_bool initialized = SDL_FALSE;
  79. static SDL_bool shutting_down = SDL_FALSE;
  80. #if defined(SDL_USE_LIBUDEV)
  81. static const SDL_UDEV_Symbols * usyms = NULL;
  82. #endif
  83. static struct
  84. {
  85. SDL_bool m_bHaveDevicesChanged;
  86. SDL_bool m_bCanGetNotifications;
  87. Uint32 m_unLastDetect;
  88. #if defined(__WIN32__)
  89. SDL_threadID m_nThreadID;
  90. WNDCLASSEXA m_wndClass;
  91. HWND m_hwndMsg;
  92. HDEVNOTIFY m_hNotify;
  93. double m_flLastWin32MessageCheck;
  94. #endif
  95. #if defined(__MACOSX__)
  96. IONotificationPortRef m_notificationPort;
  97. mach_port_t m_notificationMach;
  98. #endif
  99. #if defined(SDL_USE_LIBUDEV)
  100. struct udev *m_pUdev;
  101. struct udev_monitor *m_pUdevMonitor;
  102. int m_nUdevFd;
  103. #endif
  104. } SDL_HIDAPI_discovery;
  105. #ifdef __WIN32__
  106. struct _DEV_BROADCAST_HDR
  107. {
  108. DWORD dbch_size;
  109. DWORD dbch_devicetype;
  110. DWORD dbch_reserved;
  111. };
  112. typedef struct _DEV_BROADCAST_DEVICEINTERFACE_A
  113. {
  114. DWORD dbcc_size;
  115. DWORD dbcc_devicetype;
  116. DWORD dbcc_reserved;
  117. GUID dbcc_classguid;
  118. char dbcc_name[ 1 ];
  119. } DEV_BROADCAST_DEVICEINTERFACE_A, *PDEV_BROADCAST_DEVICEINTERFACE_A;
  120. typedef struct _DEV_BROADCAST_HDR DEV_BROADCAST_HDR;
  121. #define DBT_DEVICEARRIVAL 0x8000 /* system detected a new device */
  122. #define DBT_DEVICEREMOVECOMPLETE 0x8004 /* device was removed from the system */
  123. #define DBT_DEVTYP_DEVICEINTERFACE 0x00000005 /* device interface class */
  124. #define DBT_DEVNODES_CHANGED 0x0007
  125. #define DBT_CONFIGCHANGED 0x0018
  126. #define DBT_DEVICETYPESPECIFIC 0x8005 /* type specific event */
  127. #define DBT_DEVINSTSTARTED 0x8008 /* device installed and started */
  128. #include <initguid.h>
  129. DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
  130. static LRESULT CALLBACK ControllerWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  131. {
  132. switch (message) {
  133. case WM_DEVICECHANGE:
  134. switch (wParam) {
  135. case DBT_DEVICEARRIVAL:
  136. case DBT_DEVICEREMOVECOMPLETE:
  137. if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
  138. SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
  139. }
  140. break;
  141. }
  142. return TRUE;
  143. }
  144. return DefWindowProc(hwnd, message, wParam, lParam);
  145. }
  146. #endif /* __WIN32__ */
  147. #if defined(__MACOSX__)
  148. static void CallbackIOServiceFunc(void *context, io_iterator_t portIterator)
  149. {
  150. /* Must drain the iterator, or we won't receive new notifications */
  151. io_object_t entry;
  152. while ((entry = IOIteratorNext(portIterator)) != 0) {
  153. IOObjectRelease(entry);
  154. *(SDL_bool*)context = SDL_TRUE;
  155. }
  156. }
  157. #endif /* __MACOSX__ */
  158. static void
  159. HIDAPI_InitializeDiscovery()
  160. {
  161. SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
  162. SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_FALSE;
  163. SDL_HIDAPI_discovery.m_unLastDetect = 0;
  164. #if defined(__WIN32__)
  165. SDL_HIDAPI_discovery.m_nThreadID = SDL_ThreadID();
  166. SDL_memset(&SDL_HIDAPI_discovery.m_wndClass, 0x0, sizeof(SDL_HIDAPI_discovery.m_wndClass));
  167. SDL_HIDAPI_discovery.m_wndClass.hInstance = GetModuleHandle(NULL);
  168. SDL_HIDAPI_discovery.m_wndClass.lpszClassName = "SDL_HIDAPI_DEVICE_DETECTION";
  169. SDL_HIDAPI_discovery.m_wndClass.lpfnWndProc = ControllerWndProc; /* This function is called by windows */
  170. SDL_HIDAPI_discovery.m_wndClass.cbSize = sizeof(WNDCLASSEX);
  171. RegisterClassExA(&SDL_HIDAPI_discovery.m_wndClass);
  172. SDL_HIDAPI_discovery.m_hwndMsg = CreateWindowExA(0, "SDL_HIDAPI_DEVICE_DETECTION", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
  173. {
  174. DEV_BROADCAST_DEVICEINTERFACE_A devBroadcast;
  175. SDL_memset( &devBroadcast, 0x0, sizeof( devBroadcast ) );
  176. devBroadcast.dbcc_size = sizeof( devBroadcast );
  177. devBroadcast.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
  178. devBroadcast.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
  179. /* DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is important, makes GUID_DEVINTERFACE_USB_DEVICE ignored,
  180. * but that seems to be necessary to get a notice after each individual usb input device actually
  181. * installs, rather than just as the composite device is seen.
  182. */
  183. SDL_HIDAPI_discovery.m_hNotify = RegisterDeviceNotification( SDL_HIDAPI_discovery.m_hwndMsg, &devBroadcast, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
  184. SDL_HIDAPI_discovery.m_bCanGetNotifications = ( SDL_HIDAPI_discovery.m_hNotify != 0 );
  185. }
  186. #endif /* __WIN32__ */
  187. #if defined(__MACOSX__)
  188. SDL_HIDAPI_discovery.m_notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
  189. if (SDL_HIDAPI_discovery.m_notificationPort) {
  190. {
  191. io_iterator_t portIterator = 0;
  192. io_object_t entry;
  193. IOReturn result = IOServiceAddMatchingNotification(
  194. SDL_HIDAPI_discovery.m_notificationPort,
  195. kIOFirstMatchNotification,
  196. IOServiceMatching(kIOHIDDeviceKey),
  197. CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator);
  198. if (result == 0) {
  199. /* Must drain the existing iterator, or we won't receive new notifications */
  200. while ((entry = IOIteratorNext(portIterator)) != 0) {
  201. IOObjectRelease(entry);
  202. }
  203. } else {
  204. IONotificationPortDestroy(SDL_HIDAPI_discovery.m_notificationPort);
  205. SDL_HIDAPI_discovery.m_notificationPort = nil;
  206. }
  207. }
  208. {
  209. io_iterator_t portIterator = 0;
  210. io_object_t entry;
  211. IOReturn result = IOServiceAddMatchingNotification(
  212. SDL_HIDAPI_discovery.m_notificationPort,
  213. kIOTerminatedNotification,
  214. IOServiceMatching(kIOHIDDeviceKey),
  215. CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator);
  216. if (result == 0) {
  217. /* Must drain the existing iterator, or we won't receive new notifications */
  218. while ((entry = IOIteratorNext(portIterator)) != 0) {
  219. IOObjectRelease(entry);
  220. }
  221. } else {
  222. IONotificationPortDestroy(SDL_HIDAPI_discovery.m_notificationPort);
  223. SDL_HIDAPI_discovery.m_notificationPort = nil;
  224. }
  225. }
  226. }
  227. SDL_HIDAPI_discovery.m_notificationMach = MACH_PORT_NULL;
  228. if (SDL_HIDAPI_discovery.m_notificationPort) {
  229. SDL_HIDAPI_discovery.m_notificationMach = IONotificationPortGetMachPort(SDL_HIDAPI_discovery.m_notificationPort);
  230. }
  231. SDL_HIDAPI_discovery.m_bCanGetNotifications = (SDL_HIDAPI_discovery.m_notificationMach != MACH_PORT_NULL);
  232. #endif // __MACOSX__
  233. #if defined(SDL_USE_LIBUDEV)
  234. SDL_HIDAPI_discovery.m_pUdev = NULL;
  235. SDL_HIDAPI_discovery.m_pUdevMonitor = NULL;
  236. SDL_HIDAPI_discovery.m_nUdevFd = -1;
  237. usyms = SDL_UDEV_GetUdevSyms();
  238. if (usyms) {
  239. SDL_HIDAPI_discovery.m_pUdev = usyms->udev_new();
  240. }
  241. if (SDL_HIDAPI_discovery.m_pUdev) {
  242. SDL_HIDAPI_discovery.m_pUdevMonitor = usyms->udev_monitor_new_from_netlink(SDL_HIDAPI_discovery.m_pUdev, "udev");
  243. if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
  244. usyms->udev_monitor_enable_receiving(SDL_HIDAPI_discovery.m_pUdevMonitor);
  245. SDL_HIDAPI_discovery.m_nUdevFd = usyms->udev_monitor_get_fd(SDL_HIDAPI_discovery.m_pUdevMonitor);
  246. SDL_HIDAPI_discovery.m_bCanGetNotifications = SDL_TRUE;
  247. }
  248. }
  249. #endif /* SDL_USE_LIBUDEV */
  250. }
  251. static void
  252. HIDAPI_UpdateDiscovery()
  253. {
  254. if (!SDL_HIDAPI_discovery.m_bCanGetNotifications) {
  255. const Uint32 SDL_HIDAPI_DETECT_INTERVAL_MS = 3000; /* Update every 3 seconds */
  256. Uint32 now = SDL_GetTicks();
  257. if (!SDL_HIDAPI_discovery.m_unLastDetect || SDL_TICKS_PASSED(now, SDL_HIDAPI_discovery.m_unLastDetect + SDL_HIDAPI_DETECT_INTERVAL_MS)) {
  258. SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
  259. SDL_HIDAPI_discovery.m_unLastDetect = now;
  260. }
  261. return;
  262. }
  263. #if defined(__WIN32__)
  264. #if 0 /* just let the usual SDL_PumpEvents loop dispatch these, fixing bug 4286. --ryan. */
  265. /* We'll only get messages on the same thread that created the window */
  266. if (SDL_ThreadID() == SDL_HIDAPI_discovery.m_nThreadID) {
  267. MSG msg;
  268. while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) {
  269. if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) {
  270. TranslateMessage(&msg);
  271. DispatchMessage(&msg);
  272. }
  273. }
  274. }
  275. #endif
  276. #endif /* __WIN32__ */
  277. #if defined(__MACOSX__)
  278. if (SDL_HIDAPI_discovery.m_notificationPort) {
  279. struct { mach_msg_header_t hdr; char payload[ 4096 ]; } msg;
  280. while (mach_msg(&msg.hdr, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0, sizeof(msg), SDL_HIDAPI_discovery.m_notificationMach, 0, MACH_PORT_NULL) == KERN_SUCCESS) {
  281. IODispatchCalloutFromMessage(NULL, &msg.hdr, SDL_HIDAPI_discovery.m_notificationPort);
  282. }
  283. }
  284. #endif
  285. #if defined(SDL_USE_LIBUDEV)
  286. if (SDL_HIDAPI_discovery.m_nUdevFd >= 0) {
  287. /* Drain all notification events.
  288. * We don't expect a lot of device notifications so just
  289. * do a new discovery on any kind or number of notifications.
  290. * This could be made more restrictive if necessary.
  291. */
  292. for (;;) {
  293. struct pollfd PollUdev;
  294. struct udev_device *pUdevDevice;
  295. PollUdev.fd = SDL_HIDAPI_discovery.m_nUdevFd;
  296. PollUdev.events = POLLIN;
  297. if (poll(&PollUdev, 1, 0) != 1) {
  298. break;
  299. }
  300. SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
  301. pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor);
  302. if (pUdevDevice) {
  303. usyms->udev_device_unref(pUdevDevice);
  304. }
  305. }
  306. }
  307. #endif
  308. }
  309. static void
  310. HIDAPI_ShutdownDiscovery()
  311. {
  312. #if defined(__WIN32__)
  313. if (SDL_HIDAPI_discovery.m_hNotify)
  314. UnregisterDeviceNotification(SDL_HIDAPI_discovery.m_hNotify);
  315. if (SDL_HIDAPI_discovery.m_hwndMsg) {
  316. DestroyWindow(SDL_HIDAPI_discovery.m_hwndMsg);
  317. }
  318. UnregisterClassA(SDL_HIDAPI_discovery.m_wndClass.lpszClassName, SDL_HIDAPI_discovery.m_wndClass.hInstance);
  319. #endif
  320. #if defined(__MACOSX__)
  321. if (SDL_HIDAPI_discovery.m_notificationPort) {
  322. IONotificationPortDestroy(SDL_HIDAPI_discovery.m_notificationPort);
  323. }
  324. #endif
  325. #if defined(SDL_USE_LIBUDEV)
  326. if (usyms) {
  327. if (SDL_HIDAPI_discovery.m_pUdevMonitor) {
  328. usyms->udev_monitor_unref(SDL_HIDAPI_discovery.m_pUdevMonitor);
  329. }
  330. if (SDL_HIDAPI_discovery.m_pUdev) {
  331. usyms->udev_unref(SDL_HIDAPI_discovery.m_pUdev);
  332. }
  333. SDL_UDEV_ReleaseUdevSyms();
  334. usyms = NULL;
  335. }
  336. #endif
  337. }
  338. static void HIDAPI_JoystickDetect(void);
  339. static void HIDAPI_JoystickClose(SDL_Joystick * joystick);
  340. static SDL_bool
  341. HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
  342. {
  343. int i;
  344. SDL_GameControllerType type = SDL_GetJoystickGameControllerType(name, vendor_id, product_id, -1, 0, 0, 0);
  345. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  346. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  347. if (driver->enabled && driver->IsSupportedDevice(name, type, vendor_id, product_id, version, -1, 0, 0, 0)) {
  348. return SDL_TRUE;
  349. }
  350. }
  351. return SDL_FALSE;
  352. }
  353. static SDL_HIDAPI_DeviceDriver *
  354. HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
  355. {
  356. const Uint16 USAGE_PAGE_GENERIC_DESKTOP = 0x0001;
  357. const Uint16 USAGE_JOYSTICK = 0x0004;
  358. const Uint16 USAGE_GAMEPAD = 0x0005;
  359. const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
  360. int i;
  361. SDL_GameControllerType type;
  362. if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) {
  363. return NULL;
  364. }
  365. #ifdef SDL_JOYSTICK_RAWINPUT
  366. if (RAWINPUT_IsDevicePresent(device->vendor_id, device->product_id, device->version)) {
  367. /* The RAWINPUT driver is taking care of this device */
  368. return NULL;
  369. }
  370. #endif
  371. if (device->usage_page && device->usage_page != USAGE_PAGE_GENERIC_DESKTOP) {
  372. return NULL;
  373. }
  374. if (device->usage && device->usage != USAGE_JOYSTICK && device->usage != USAGE_GAMEPAD && device->usage != USAGE_MULTIAXISCONTROLLER) {
  375. return NULL;
  376. }
  377. type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
  378. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  379. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  380. if (driver->enabled && driver->IsSupportedDevice(device->name, type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
  381. return driver;
  382. }
  383. }
  384. return NULL;
  385. }
  386. static SDL_HIDAPI_Device *
  387. HIDAPI_GetDeviceByIndex(int device_index, SDL_JoystickID *pJoystickID)
  388. {
  389. SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
  390. while (device) {
  391. if (device->driver) {
  392. if (device_index < device->num_joysticks) {
  393. if (pJoystickID) {
  394. *pJoystickID = device->joysticks[device_index];
  395. }
  396. return device;
  397. }
  398. device_index -= device->num_joysticks;
  399. }
  400. device = device->next;
  401. }
  402. return NULL;
  403. }
  404. static SDL_HIDAPI_Device *
  405. HIDAPI_GetJoystickByInfo(const char *path, Uint16 vendor_id, Uint16 product_id)
  406. {
  407. SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
  408. while (device) {
  409. if (device->vendor_id == vendor_id && device->product_id == product_id &&
  410. SDL_strcmp(device->path, path) == 0) {
  411. break;
  412. }
  413. device = device->next;
  414. }
  415. return device;
  416. }
  417. static void
  418. HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device)
  419. {
  420. if (device->driver) {
  421. /* Already setup */
  422. return;
  423. }
  424. device->driver = HIDAPI_GetDeviceDriver(device);
  425. if (device->driver) {
  426. const char *name = device->driver->GetDeviceName(device->vendor_id, device->product_id);
  427. if (name) {
  428. SDL_free(device->name);
  429. device->name = SDL_strdup(name);
  430. }
  431. }
  432. /* Initialize the device, which may cause a connected event */
  433. if (device->driver && !device->driver->InitDevice(device)) {
  434. device->driver = NULL;
  435. }
  436. }
  437. static void
  438. HIDAPI_CleanupDeviceDriver(SDL_HIDAPI_Device *device)
  439. {
  440. if (!device->driver) {
  441. /* Already cleaned up */
  442. return;
  443. }
  444. /* Disconnect any joysticks */
  445. while (device->num_joysticks) {
  446. HIDAPI_JoystickDisconnected(device, device->joysticks[0], SDL_FALSE);
  447. }
  448. device->driver->FreeDevice(device);
  449. device->driver = NULL;
  450. }
  451. static void SDLCALL
  452. SDL_HIDAPIDriverHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
  453. {
  454. int i;
  455. SDL_HIDAPI_Device *device;
  456. SDL_bool enabled = SDL_GetStringBoolean(hint, SDL_TRUE);
  457. if (SDL_strcmp(name, SDL_HINT_JOYSTICK_HIDAPI) == 0) {
  458. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  459. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  460. driver->enabled = SDL_GetHintBoolean(driver->hint, enabled);
  461. }
  462. } else {
  463. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  464. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  465. if (SDL_strcmp(name, driver->hint) == 0) {
  466. driver->enabled = enabled;
  467. }
  468. }
  469. }
  470. SDL_HIDAPI_numdrivers = 0;
  471. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  472. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  473. if (driver->enabled) {
  474. ++SDL_HIDAPI_numdrivers;
  475. }
  476. }
  477. /* Update device list if driver availability changes */
  478. SDL_LockJoysticks();
  479. for (device = SDL_HIDAPI_devices; device; device = device->next) {
  480. if (device->driver && !device->driver->enabled) {
  481. HIDAPI_CleanupDeviceDriver(device);
  482. }
  483. HIDAPI_SetupDeviceDriver(device);
  484. }
  485. SDL_UnlockJoysticks();
  486. }
  487. static int
  488. HIDAPI_JoystickInit(void)
  489. {
  490. int i;
  491. if (initialized) {
  492. return 0;
  493. }
  494. #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
  495. /* The hidapi framwork is weak-linked on Apple platforms */
  496. int HID_API_EXPORT HID_API_CALL hid_init(void) __attribute__((weak_import));
  497. if (hid_init == NULL) {
  498. SDL_SetError("Couldn't initialize hidapi, framework not available");
  499. return -1;
  500. }
  501. #endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */
  502. if (hid_init() < 0) {
  503. SDL_SetError("Couldn't initialize hidapi");
  504. return -1;
  505. }
  506. #ifdef __WINDOWS__
  507. /* On Windows, turns out HIDAPI for Xbox controllers doesn't allow background input, so off by default */
  508. SDL_SetHintWithPriority(SDL_HINT_JOYSTICK_HIDAPI_XBOX, "0", SDL_HINT_DEFAULT);
  509. #endif
  510. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  511. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  512. SDL_AddHintCallback(driver->hint, SDL_HIDAPIDriverHintChanged, NULL);
  513. }
  514. SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI,
  515. SDL_HIDAPIDriverHintChanged, NULL);
  516. HIDAPI_InitializeDiscovery();
  517. HIDAPI_JoystickDetect();
  518. HIDAPI_UpdateDevices();
  519. initialized = SDL_TRUE;
  520. return 0;
  521. }
  522. SDL_bool
  523. HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID, SDL_bool is_external)
  524. {
  525. SDL_JoystickID joystickID;
  526. SDL_JoystickID *joysticks = (SDL_JoystickID *)SDL_realloc(device->joysticks, (device->num_joysticks + 1)*sizeof(*device->joysticks));
  527. if (!joysticks) {
  528. return SDL_FALSE;
  529. }
  530. joystickID = SDL_GetNextJoystickInstanceID();
  531. device->joysticks = joysticks;
  532. device->joysticks[device->num_joysticks++] = joystickID;
  533. if (!is_external) {
  534. ++SDL_HIDAPI_numjoysticks;
  535. }
  536. SDL_PrivateJoystickAdded(joystickID);
  537. if (pJoystickID) {
  538. *pJoystickID = joystickID;
  539. }
  540. return SDL_TRUE;
  541. }
  542. void
  543. HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID, SDL_bool is_external)
  544. {
  545. int i;
  546. for (i = 0; i < device->num_joysticks; ++i) {
  547. if (device->joysticks[i] == joystickID) {
  548. SDL_Joystick *joystick = SDL_JoystickFromInstanceID(joystickID);
  549. if (joystick && !is_external) {
  550. HIDAPI_JoystickClose(joystick);
  551. }
  552. SDL_memmove(&device->joysticks[i], &device->joysticks[i+1], device->num_joysticks - i - 1);
  553. --device->num_joysticks;
  554. if (!is_external) {
  555. --SDL_HIDAPI_numjoysticks;
  556. }
  557. if (device->num_joysticks == 0) {
  558. SDL_free(device->joysticks);
  559. device->joysticks = NULL;
  560. }
  561. if (!shutting_down) {
  562. SDL_PrivateJoystickRemoved(joystickID);
  563. }
  564. return;
  565. }
  566. }
  567. }
  568. static int
  569. HIDAPI_JoystickGetCount(void)
  570. {
  571. return SDL_HIDAPI_numjoysticks;
  572. }
  573. static void
  574. HIDAPI_AddDevice(struct hid_device_info *info)
  575. {
  576. SDL_HIDAPI_Device *device;
  577. SDL_HIDAPI_Device *curr, *last = NULL;
  578. for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
  579. continue;
  580. }
  581. device = (SDL_HIDAPI_Device *)SDL_calloc(1, sizeof(*device));
  582. if (!device) {
  583. return;
  584. }
  585. device->path = SDL_strdup(info->path);
  586. if (!device->path) {
  587. SDL_free(device);
  588. return;
  589. }
  590. device->seen = SDL_TRUE;
  591. device->vendor_id = info->vendor_id;
  592. device->product_id = info->product_id;
  593. device->version = info->release_number;
  594. device->interface_number = info->interface_number;
  595. device->interface_class = info->interface_class;
  596. device->interface_subclass = info->interface_subclass;
  597. device->interface_protocol = info->interface_protocol;
  598. device->usage_page = info->usage_page;
  599. device->usage = info->usage;
  600. {
  601. /* FIXME: Is there any way to tell whether this is a Bluetooth device? */
  602. const Uint16 vendor = device->vendor_id;
  603. const Uint16 product = device->product_id;
  604. const Uint16 version = device->version;
  605. Uint16 *guid16 = (Uint16 *)device->guid.data;
  606. *guid16++ = SDL_SwapLE16(SDL_HARDWARE_BUS_USB);
  607. *guid16++ = 0;
  608. *guid16++ = SDL_SwapLE16(vendor);
  609. *guid16++ = 0;
  610. *guid16++ = SDL_SwapLE16(product);
  611. *guid16++ = 0;
  612. *guid16++ = SDL_SwapLE16(version);
  613. *guid16++ = 0;
  614. /* Note that this is a HIDAPI device for special handling elsewhere */
  615. device->guid.data[14] = 'h';
  616. device->guid.data[15] = 0;
  617. }
  618. device->dev_lock = SDL_CreateMutex();
  619. /* Need the device name before getting the driver to know whether to ignore this device */
  620. {
  621. char *manufacturer_string = NULL;
  622. char *product_string = NULL;
  623. if (info->manufacturer_string) {
  624. manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
  625. if (!manufacturer_string) {
  626. if (sizeof(wchar_t) == sizeof(Uint16)) {
  627. manufacturer_string = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
  628. } else if (sizeof(wchar_t) == sizeof(Uint32)) {
  629. manufacturer_string = SDL_iconv_string("UTF-8", "UCS-4-INTERNAL", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
  630. }
  631. }
  632. }
  633. if (info->product_string) {
  634. product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
  635. if (!product_string) {
  636. if (sizeof(wchar_t) == sizeof(Uint16)) {
  637. product_string = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
  638. } else if (sizeof(wchar_t) == sizeof(Uint32)) {
  639. product_string = SDL_iconv_string("UTF-8", "UCS-4-INTERNAL", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
  640. }
  641. }
  642. }
  643. device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
  644. if (manufacturer_string) {
  645. SDL_free(manufacturer_string);
  646. }
  647. if (product_string) {
  648. SDL_free(product_string);
  649. }
  650. if (!device->name) {
  651. SDL_free(device->path);
  652. SDL_free(device);
  653. return;
  654. }
  655. }
  656. /* Add it to the list */
  657. if (last) {
  658. last->next = device;
  659. } else {
  660. SDL_HIDAPI_devices = device;
  661. }
  662. HIDAPI_SetupDeviceDriver(device);
  663. #ifdef DEBUG_HIDAPI
  664. SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s (%s)\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE", device->driver && device->driver->enabled ? "ENABLED" : "DISABLED");
  665. #endif
  666. }
  667. static void
  668. HIDAPI_DelDevice(SDL_HIDAPI_Device *device)
  669. {
  670. SDL_HIDAPI_Device *curr, *last;
  671. for (curr = SDL_HIDAPI_devices, last = NULL; curr; last = curr, curr = curr->next) {
  672. if (curr == device) {
  673. if (last) {
  674. last->next = curr->next;
  675. } else {
  676. SDL_HIDAPI_devices = curr->next;
  677. }
  678. HIDAPI_CleanupDeviceDriver(device);
  679. SDL_DestroyMutex(device->dev_lock);
  680. SDL_free(device->name);
  681. SDL_free(device->path);
  682. SDL_free(device);
  683. return;
  684. }
  685. }
  686. }
  687. static void
  688. HIDAPI_UpdateDeviceList(void)
  689. {
  690. SDL_HIDAPI_Device *device;
  691. struct hid_device_info *devs, *info;
  692. SDL_LockJoysticks();
  693. /* Prepare the existing device list */
  694. device = SDL_HIDAPI_devices;
  695. while (device) {
  696. device->seen = SDL_FALSE;
  697. device = device->next;
  698. }
  699. /* Enumerate the devices */
  700. if (SDL_HIDAPI_numdrivers > 0) {
  701. devs = hid_enumerate(0, 0);
  702. if (devs) {
  703. for (info = devs; info; info = info->next) {
  704. device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
  705. if (device) {
  706. device->seen = SDL_TRUE;
  707. } else {
  708. HIDAPI_AddDevice(info);
  709. }
  710. }
  711. hid_free_enumeration(devs);
  712. }
  713. }
  714. /* Remove any devices that weren't seen */
  715. device = SDL_HIDAPI_devices;
  716. while (device) {
  717. SDL_HIDAPI_Device *next = device->next;
  718. if (!device->seen) {
  719. HIDAPI_DelDevice(device);
  720. }
  721. device = next;
  722. }
  723. SDL_UnlockJoysticks();
  724. }
  725. SDL_bool
  726. HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
  727. {
  728. SDL_HIDAPI_Device *device;
  729. SDL_bool supported = SDL_FALSE;
  730. SDL_bool result = SDL_FALSE;
  731. /* Make sure we're initialized, as this could be called from other drivers during startup */
  732. if (HIDAPI_JoystickInit() < 0) {
  733. return SDL_FALSE;
  734. }
  735. /* Only update the device list for devices we know might be supported.
  736. If we did this for every device, it would hit the USB driver too hard and potentially
  737. lock up the system. This won't catch devices that we support but can only detect using
  738. USB interface details, like Xbox controllers, but hopefully the device list update is
  739. responsive enough to catch those.
  740. */
  741. supported = HIDAPI_IsDeviceSupported(vendor_id, product_id, version, name);
  742. #if defined(SDL_JOYSTICK_HIDAPI_XBOX360) || defined(SDL_JOYSTICK_HIDAPI_XBOXONE)
  743. if (!supported &&
  744. (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box") || SDL_strstr(name, "XBOX"))) {
  745. supported = SDL_TRUE;
  746. }
  747. #endif /* SDL_JOYSTICK_HIDAPI_XBOX360 || SDL_JOYSTICK_HIDAPI_XBOXONE */
  748. if (supported) {
  749. if (SDL_AtomicTryLock(&SDL_HIDAPI_spinlock)) {
  750. HIDAPI_UpdateDeviceList();
  751. SDL_AtomicUnlock(&SDL_HIDAPI_spinlock);
  752. }
  753. }
  754. /* Note that this isn't a perfect check - there may be multiple devices with 0 VID/PID,
  755. or a different name than we have it listed here, etc, but if we support the device
  756. and we have something similar in our device list, mark it as present.
  757. */
  758. SDL_LockJoysticks();
  759. device = SDL_HIDAPI_devices;
  760. while (device) {
  761. if (device->vendor_id == vendor_id && device->product_id == product_id && device->driver) {
  762. result = SDL_TRUE;
  763. }
  764. device = device->next;
  765. }
  766. SDL_UnlockJoysticks();
  767. /* If we're looking for the wireless XBox 360 controller, also look for the dongle */
  768. if (!result && vendor_id == USB_VENDOR_MICROSOFT && product_id == 0x02a1) {
  769. return HIDAPI_IsDevicePresent(USB_VENDOR_MICROSOFT, 0x0719, version, name);
  770. }
  771. #ifdef DEBUG_HIDAPI
  772. SDL_Log("HIDAPI_IsDevicePresent() returning %s for 0x%.4x / 0x%.4x\n", result ? "true" : "false", vendor_id, product_id);
  773. #endif
  774. return result;
  775. }
  776. static void
  777. HIDAPI_JoystickDetect(void)
  778. {
  779. int i;
  780. if (SDL_AtomicTryLock(&SDL_HIDAPI_spinlock)) {
  781. HIDAPI_UpdateDiscovery();
  782. if (SDL_HIDAPI_discovery.m_bHaveDevicesChanged) {
  783. /* FIXME: We probably need to schedule an update in a few seconds as well */
  784. HIDAPI_UpdateDeviceList();
  785. SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_FALSE;
  786. }
  787. SDL_AtomicUnlock(&SDL_HIDAPI_spinlock);
  788. }
  789. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  790. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  791. if (driver->enabled && driver->PostUpdate) {
  792. driver->PostUpdate();
  793. }
  794. }
  795. }
  796. void
  797. HIDAPI_UpdateDevices(void)
  798. {
  799. SDL_HIDAPI_Device *device;
  800. /* Update the devices, which may change connected joysticks and send events */
  801. /* Prepare the existing device list */
  802. if (SDL_AtomicTryLock(&SDL_HIDAPI_spinlock)) {
  803. device = SDL_HIDAPI_devices;
  804. while (device) {
  805. if (device->driver) {
  806. if (SDL_TryLockMutex(device->dev_lock) == 0) {
  807. device->driver->UpdateDevice(device);
  808. SDL_UnlockMutex(device->dev_lock);
  809. }
  810. }
  811. device = device->next;
  812. }
  813. SDL_AtomicUnlock(&SDL_HIDAPI_spinlock);
  814. }
  815. }
  816. static const char *
  817. HIDAPI_JoystickGetDeviceName(int device_index)
  818. {
  819. SDL_HIDAPI_Device *device;
  820. const char *name = NULL;
  821. device = HIDAPI_GetDeviceByIndex(device_index, NULL);
  822. if (device) {
  823. /* FIXME: The device could be freed after this name is returned... */
  824. name = device->name;
  825. }
  826. return name;
  827. }
  828. static int
  829. HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
  830. {
  831. SDL_HIDAPI_Device *device;
  832. SDL_JoystickID instance_id;
  833. int player_index = -1;
  834. device = HIDAPI_GetDeviceByIndex(device_index, &instance_id);
  835. if (device) {
  836. player_index = device->driver->GetDevicePlayerIndex(device, instance_id);
  837. }
  838. return player_index;
  839. }
  840. static void
  841. HIDAPI_JoystickSetDevicePlayerIndex(int device_index, int player_index)
  842. {
  843. SDL_HIDAPI_Device *device;
  844. SDL_JoystickID instance_id;
  845. device = HIDAPI_GetDeviceByIndex(device_index, &instance_id);
  846. if (device) {
  847. device->driver->SetDevicePlayerIndex(device, instance_id, player_index);
  848. }
  849. }
  850. static SDL_JoystickGUID
  851. HIDAPI_JoystickGetDeviceGUID(int device_index)
  852. {
  853. SDL_HIDAPI_Device *device;
  854. SDL_JoystickGUID guid;
  855. device = HIDAPI_GetDeviceByIndex(device_index, NULL);
  856. if (device) {
  857. SDL_memcpy(&guid, &device->guid, sizeof(guid));
  858. } else {
  859. SDL_zero(guid);
  860. }
  861. return guid;
  862. }
  863. static SDL_JoystickID
  864. HIDAPI_JoystickGetDeviceInstanceID(int device_index)
  865. {
  866. SDL_JoystickID joystickID = -1;
  867. HIDAPI_GetDeviceByIndex(device_index, &joystickID);
  868. return joystickID;
  869. }
  870. static int
  871. HIDAPI_JoystickOpen(SDL_Joystick * joystick, int device_index)
  872. {
  873. SDL_JoystickID joystickID;
  874. SDL_HIDAPI_Device *device = HIDAPI_GetDeviceByIndex(device_index, &joystickID);
  875. struct joystick_hwdata *hwdata;
  876. hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata));
  877. if (!hwdata) {
  878. return SDL_OutOfMemory();
  879. }
  880. hwdata->device = device;
  881. if (!device->driver->OpenJoystick(device, joystick)) {
  882. SDL_free(hwdata);
  883. return -1;
  884. }
  885. joystick->hwdata = hwdata;
  886. return 0;
  887. }
  888. static int
  889. HIDAPI_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
  890. {
  891. int result;
  892. if (joystick->hwdata) {
  893. SDL_HIDAPI_Device *device = joystick->hwdata->device;
  894. result = device->driver->RumbleJoystick(device, joystick, low_frequency_rumble, high_frequency_rumble);
  895. } else {
  896. SDL_SetError("Rumble failed, device disconnected");
  897. result = -1;
  898. }
  899. return result;
  900. }
  901. static void
  902. HIDAPI_JoystickUpdate(SDL_Joystick * joystick)
  903. {
  904. /* This is handled in SDL_HIDAPI_UpdateDevices() */
  905. }
  906. static void
  907. HIDAPI_JoystickClose(SDL_Joystick * joystick)
  908. {
  909. if (joystick->hwdata) {
  910. SDL_HIDAPI_Device *device = joystick->hwdata->device;
  911. /* Wait for pending rumble to complete */
  912. while (SDL_AtomicGet(&device->rumble_pending) > 0) {
  913. SDL_Delay(10);
  914. }
  915. device->driver->CloseJoystick(device, joystick);
  916. SDL_free(joystick->hwdata);
  917. joystick->hwdata = NULL;
  918. }
  919. }
  920. static void
  921. HIDAPI_JoystickQuit(void)
  922. {
  923. int i;
  924. shutting_down = SDL_TRUE;
  925. HIDAPI_ShutdownDiscovery();
  926. while (SDL_HIDAPI_devices) {
  927. HIDAPI_DelDevice(SDL_HIDAPI_devices);
  928. }
  929. SDL_HIDAPI_QuitRumble();
  930. for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
  931. SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
  932. SDL_DelHintCallback(driver->hint, SDL_HIDAPIDriverHintChanged, NULL);
  933. }
  934. SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI,
  935. SDL_HIDAPIDriverHintChanged, NULL);
  936. hid_exit();
  937. /* Make sure the drivers cleaned up properly */
  938. SDL_assert(SDL_HIDAPI_numjoysticks == 0);
  939. shutting_down = SDL_FALSE;
  940. initialized = SDL_FALSE;
  941. }
  942. SDL_JoystickDriver SDL_HIDAPI_JoystickDriver =
  943. {
  944. HIDAPI_JoystickInit,
  945. HIDAPI_JoystickGetCount,
  946. HIDAPI_JoystickDetect,
  947. HIDAPI_JoystickGetDeviceName,
  948. HIDAPI_JoystickGetDevicePlayerIndex,
  949. HIDAPI_JoystickSetDevicePlayerIndex,
  950. HIDAPI_JoystickGetDeviceGUID,
  951. HIDAPI_JoystickGetDeviceInstanceID,
  952. HIDAPI_JoystickOpen,
  953. HIDAPI_JoystickRumble,
  954. HIDAPI_JoystickUpdate,
  955. HIDAPI_JoystickClose,
  956. HIDAPI_JoystickQuit,
  957. };
  958. #endif /* SDL_JOYSTICK_HIDAPI */
  959. /* vi: set ts=4 sw=4 expandtab: */