gamepad_standard_mappings_mac.mm 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <algorithm>
  6. #include <iterator>
  7. #include "device/gamepad/gamepad_id_list.h"
  8. #include "device/gamepad/gamepad_standard_mappings.h"
  9. namespace device {
  10. namespace {
  11. // Older versions of the Stadia Controller firmware use an alternate mapping
  12. // function.
  13. const uint16_t kStadiaControllerOldFirmwareVersion = 0x0001;
  14. enum StadiaGamepadButtons {
  15. STADIA_GAMEPAD_BUTTON_EXTRA = BUTTON_INDEX_COUNT,
  16. STADIA_GAMEPAD_BUTTON_EXTRA2,
  17. STADIA_GAMEPAD_BUTTON_COUNT
  18. };
  19. void MapperXbox360Gamepad(const Gamepad& input, Gamepad* mapped) {
  20. *mapped = input;
  21. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
  22. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
  23. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[9];
  24. mapped->buttons[BUTTON_INDEX_START] = input.buttons[8];
  25. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[6];
  26. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[7];
  27. mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[11];
  28. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[12];
  29. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[13];
  30. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[14];
  31. mapped->buttons[BUTTON_INDEX_META] = input.buttons[10];
  32. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
  33. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
  34. mapped->buttons_length = BUTTON_INDEX_COUNT;
  35. mapped->axes_length = AXIS_INDEX_COUNT;
  36. }
  37. void MapperXboxOneS(const Gamepad& input, Gamepad* mapped) {
  38. *mapped = input;
  39. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  40. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  41. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[2];
  42. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
  43. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
  44. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
  45. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
  46. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
  47. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
  48. mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
  49. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[8];
  50. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[9];
  51. mapped->buttons[BUTTON_INDEX_META] = input.buttons[10];
  52. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
  53. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
  54. DpadFromAxis(mapped, input.axes[9]);
  55. mapped->buttons_length = BUTTON_INDEX_COUNT;
  56. mapped->axes_length = AXIS_INDEX_COUNT;
  57. }
  58. void MapperXboxOneS2016Firmware(const Gamepad& input, Gamepad* mapped) {
  59. *mapped = input;
  60. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  61. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  62. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  63. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  64. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  65. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  66. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  67. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  68. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[16];
  69. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  70. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  71. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  72. // Xbox Wireless Controller (045e:02fd) received a firmware update in 2019
  73. // that changed which field is populated with the Xbox button state. Check
  74. // both fields and combine the results.
  75. auto& xbox_old = input.buttons[15];
  76. auto& xbox_new = input.buttons[12];
  77. mapped->buttons[BUTTON_INDEX_META].pressed =
  78. (xbox_old.pressed || xbox_new.pressed);
  79. mapped->buttons[BUTTON_INDEX_META].touched =
  80. (xbox_old.touched || xbox_new.touched);
  81. mapped->buttons[BUTTON_INDEX_META].value =
  82. std::max(xbox_old.value, xbox_new.value);
  83. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  84. DpadFromAxis(mapped, input.axes[9]);
  85. mapped->buttons_length = BUTTON_INDEX_COUNT;
  86. mapped->axes_length = AXIS_INDEX_COUNT;
  87. }
  88. void MapperXboxBluetooth(const Gamepad& input, Gamepad* mapped) {
  89. *mapped = input;
  90. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  91. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  92. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  93. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  94. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  95. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  96. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  97. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  98. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  99. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  100. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  101. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  102. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  103. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[2];
  104. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  105. DpadFromAxis(mapped, input.axes[9]);
  106. mapped->buttons_length = BUTTON_INDEX_COUNT;
  107. mapped->axes_length = AXIS_INDEX_COUNT;
  108. }
  109. void MapperXboxSeriesXBluetooth(const Gamepad& input, Gamepad* mapped) {
  110. MapperXboxBluetooth(input, mapped);
  111. // Xbox Wireless Controller Model 1914 has an extra Share button not present
  112. // on other Xbox controllers. Map Share to the next button index after Meta.
  113. mapped->buttons[XBOX_SERIES_X_BUTTON_SHARE] = input.buttons[15];
  114. mapped->buttons_length = XBOX_SERIES_X_BUTTON_COUNT;
  115. mapped->axes_length = AXIS_INDEX_COUNT;
  116. }
  117. void MapperPlaystationSixAxis(const Gamepad& input, Gamepad* mapped) {
  118. *mapped = input;
  119. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[14];
  120. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[13];
  121. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[15];
  122. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[12];
  123. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[10];
  124. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[11];
  125. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
  126. ButtonFromButtonAndAxis(input.buttons[8], input.axes[14]);
  127. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] =
  128. ButtonFromButtonAndAxis(input.buttons[9], input.axes[15]);
  129. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[0];
  130. mapped->buttons[BUTTON_INDEX_START] = input.buttons[3];
  131. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[1];
  132. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[2];
  133. // The SixAxis Dpad is pressure sensitive.
  134. mapped->buttons[BUTTON_INDEX_DPAD_UP] =
  135. ButtonFromButtonAndAxis(input.buttons[4], input.axes[10]);
  136. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] =
  137. ButtonFromButtonAndAxis(input.buttons[6], input.axes[12]);
  138. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] =
  139. ButtonFromButtonAndAxis(input.buttons[7], input.axes[13]);
  140. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
  141. ButtonFromButtonAndAxis(input.buttons[5], input.axes[11]);
  142. mapped->buttons[BUTTON_INDEX_META] = input.buttons[16];
  143. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  144. mapped->buttons_length = BUTTON_INDEX_COUNT;
  145. mapped->axes_length = AXIS_INDEX_COUNT;
  146. }
  147. void MapperDualshock4(const Gamepad& input, Gamepad* mapped) {
  148. enum Dualshock4Buttons {
  149. DUALSHOCK_BUTTON_TOUCHPAD = BUTTON_INDEX_COUNT,
  150. DUALSHOCK_BUTTON_COUNT
  151. };
  152. *mapped = input;
  153. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
  154. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
  155. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
  156. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
  157. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
  158. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
  159. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  160. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  161. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8];
  162. mapped->buttons[BUTTON_INDEX_START] = input.buttons[9];
  163. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[10];
  164. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[11];
  165. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  166. mapped->buttons[DUALSHOCK_BUTTON_TOUCHPAD] = input.buttons[13];
  167. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  168. DpadFromAxis(mapped, input.axes[9]);
  169. mapped->buttons_length = DUALSHOCK_BUTTON_COUNT;
  170. mapped->axes_length = AXIS_INDEX_COUNT;
  171. }
  172. void MapperDualSense(const Gamepad& input, Gamepad* mapped) {
  173. enum DualSenseButtons {
  174. DUAL_SENSE_BUTTON_TOUCHPAD = BUTTON_INDEX_COUNT,
  175. DUAL_SENSE_BUTTON_COUNT
  176. };
  177. *mapped = input;
  178. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
  179. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
  180. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
  181. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
  182. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
  183. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
  184. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  185. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  186. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8];
  187. mapped->buttons[BUTTON_INDEX_START] = input.buttons[9];
  188. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[10];
  189. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[11];
  190. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  191. mapped->buttons[DUAL_SENSE_BUTTON_TOUCHPAD] = input.buttons[13];
  192. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[2];
  193. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  194. DpadFromAxis(mapped, input.axes[9]);
  195. mapped->buttons_length = DUAL_SENSE_BUTTON_COUNT;
  196. mapped->axes_length = AXIS_INDEX_COUNT;
  197. }
  198. void MapperIBuffalo(const Gamepad& input, Gamepad* mapped) {
  199. *mapped = input;
  200. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
  201. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[0];
  202. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  203. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[2];
  204. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
  205. mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
  206. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
  207. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
  208. mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
  209. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
  210. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
  211. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
  212. AxisPositiveAsButton(input.axes[0]);
  213. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  214. mapped->axes_length = 2;
  215. }
  216. void MapperDirectInputStyle(const Gamepad& input, Gamepad* mapped) {
  217. *mapped = input;
  218. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
  219. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
  220. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
  221. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  222. DpadFromAxis(mapped, input.axes[9]);
  223. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  224. mapped->axes_length = AXIS_INDEX_COUNT;
  225. }
  226. void MapperMacallyIShock(const Gamepad& input, Gamepad* mapped) {
  227. enum IShockButtons {
  228. ISHOCK_BUTTON_C = BUTTON_INDEX_COUNT,
  229. ISHOCK_BUTTON_D,
  230. ISHOCK_BUTTON_E,
  231. ISHOCK_BUTTON_COUNT,
  232. };
  233. *mapped = input;
  234. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[6];
  235. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[5];
  236. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[7];
  237. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  238. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[14];
  239. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[12];
  240. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[15];
  241. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[13];
  242. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[9];
  243. mapped->buttons[BUTTON_INDEX_START] = input.buttons[10];
  244. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[16];
  245. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[17];
  246. mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[0];
  247. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[1];
  248. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[2];
  249. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[3];
  250. mapped->buttons[BUTTON_INDEX_META] = input.buttons[11];
  251. mapped->buttons[ISHOCK_BUTTON_C] = input.buttons[8];
  252. mapped->buttons[ISHOCK_BUTTON_D] = input.buttons[18];
  253. mapped->buttons[ISHOCK_BUTTON_E] = input.buttons[19];
  254. mapped->axes[AXIS_INDEX_LEFT_STICK_X] = input.axes[0];
  255. mapped->axes[AXIS_INDEX_LEFT_STICK_Y] = input.axes[1];
  256. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = -input.axes[5];
  257. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[6];
  258. mapped->buttons_length = ISHOCK_BUTTON_COUNT;
  259. mapped->axes_length = AXIS_INDEX_COUNT;
  260. }
  261. void MapperXGEAR(const Gamepad& input, Gamepad* mapped) {
  262. *mapped = input;
  263. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
  264. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  265. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
  266. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  267. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  268. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
  269. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
  270. DpadFromAxis(mapped, input.axes[9]);
  271. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[5];
  272. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[2];
  273. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  274. mapped->axes_length = AXIS_INDEX_COUNT;
  275. }
  276. void MapperSmartJoyPLUS(const Gamepad& input, Gamepad* mapped) {
  277. *mapped = input;
  278. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
  279. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  280. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
  281. mapped->buttons[BUTTON_INDEX_START] = input.buttons[8];
  282. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[9];
  283. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  284. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  285. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
  286. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
  287. DpadFromAxis(mapped, input.axes[9]);
  288. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  289. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  290. mapped->axes_length = AXIS_INDEX_COUNT;
  291. }
  292. void MapperDragonRiseGeneric(const Gamepad& input, Gamepad* mapped) {
  293. *mapped = input;
  294. DpadFromAxis(mapped, input.axes[9]);
  295. mapped->axes[AXIS_INDEX_LEFT_STICK_X] = input.axes[0];
  296. mapped->axes[AXIS_INDEX_LEFT_STICK_Y] = input.axes[1];
  297. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[2];
  298. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  299. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  300. mapped->axes_length = AXIS_INDEX_COUNT;
  301. }
  302. void Mapper2Axes8Keys(const Gamepad& input, Gamepad* mapped) {
  303. *mapped = input;
  304. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
  305. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  306. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  307. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
  308. mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
  309. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
  310. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
  311. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
  312. AxisPositiveAsButton(input.axes[0]);
  313. // Missing buttons
  314. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = NullButton();
  315. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = NullButton();
  316. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = NullButton();
  317. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = NullButton();
  318. mapped->buttons_length = BUTTON_INDEX_COUNT - 1;
  319. mapped->axes_length = 0;
  320. }
  321. void MapperOnLiveWireless(const Gamepad& input, Gamepad* mapped) {
  322. *mapped = input;
  323. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  324. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  325. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  326. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  327. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  328. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  329. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
  330. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
  331. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  332. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  333. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  334. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  335. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  336. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
  337. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
  338. DpadFromAxis(mapped, input.axes[9]);
  339. mapped->buttons_length = BUTTON_INDEX_COUNT;
  340. mapped->axes_length = AXIS_INDEX_COUNT;
  341. }
  342. void MapperADT1(const Gamepad& input, Gamepad* mapped) {
  343. *mapped = input;
  344. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  345. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  346. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  347. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  348. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  349. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  350. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  351. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  352. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
  353. mapped->buttons[BUTTON_INDEX_START] = NullButton();
  354. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  355. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  356. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  357. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  358. DpadFromAxis(mapped, input.axes[9]);
  359. mapped->buttons_length = BUTTON_INDEX_COUNT;
  360. mapped->axes_length = AXIS_INDEX_COUNT;
  361. }
  362. void MapperNvShield(const Gamepad& input, Gamepad* mapped) {
  363. enum ShieldButtons {
  364. SHIELD_BUTTON_CIRCLE = BUTTON_INDEX_COUNT,
  365. SHIELD_BUTTON_COUNT
  366. };
  367. *mapped = input;
  368. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  369. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  370. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  371. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  372. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  373. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  374. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  375. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  376. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[9];
  377. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  378. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  379. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  380. mapped->buttons[BUTTON_INDEX_META] = input.buttons[2];
  381. mapped->buttons[SHIELD_BUTTON_CIRCLE] = input.buttons[5];
  382. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  383. DpadFromAxis(mapped, input.axes[9]);
  384. mapped->buttons_length = SHIELD_BUTTON_COUNT;
  385. mapped->axes_length = AXIS_INDEX_COUNT;
  386. }
  387. void MapperOUYA(const Gamepad& input, Gamepad* mapped) {
  388. *mapped = input;
  389. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  390. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[3];
  391. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[1];
  392. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[2];
  393. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
  394. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
  395. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
  396. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
  397. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
  398. mapped->buttons[BUTTON_INDEX_START] = NullButton();
  399. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[6];
  400. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[7];
  401. mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[8];
  402. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[9];
  403. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[10];
  404. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[11];
  405. mapped->buttons[BUTTON_INDEX_META] = input.buttons[15];
  406. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
  407. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
  408. mapped->buttons_length = BUTTON_INDEX_COUNT;
  409. mapped->axes_length = AXIS_INDEX_COUNT;
  410. }
  411. void MapperRazerServal(const Gamepad& input, Gamepad* mapped) {
  412. *mapped = input;
  413. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  414. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  415. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  416. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  417. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  418. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  419. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  420. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  421. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  422. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  423. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  424. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  425. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  426. DpadFromAxis(mapped, input.axes[9]);
  427. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  428. mapped->axes_length = AXIS_INDEX_COUNT;
  429. }
  430. void MapperMogaPro(const Gamepad& input, Gamepad* mapped) {
  431. *mapped = input;
  432. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  433. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  434. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  435. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  436. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  437. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  438. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  439. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  440. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
  441. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  442. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  443. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  444. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  445. DpadFromAxis(mapped, input.axes[9]);
  446. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; /* no meta */
  447. mapped->axes_length = AXIS_INDEX_COUNT;
  448. }
  449. void MapperStadiaControllerOldFirmware(const Gamepad& input, Gamepad* mapped) {
  450. *mapped = input;
  451. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  452. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  453. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  454. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  455. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  456. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  457. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  458. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  459. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  460. mapped->buttons[BUTTON_INDEX_START] = input.buttons[12];
  461. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  462. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  463. mapped->buttons[BUTTON_INDEX_META] = input.buttons[11];
  464. mapped->buttons[STADIA_GAMEPAD_BUTTON_EXTRA] = input.buttons[16];
  465. mapped->buttons[STADIA_GAMEPAD_BUTTON_EXTRA2] = input.buttons[17];
  466. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  467. DpadFromAxis(mapped, input.axes[9]);
  468. mapped->buttons_length = STADIA_GAMEPAD_BUTTON_COUNT;
  469. mapped->axes_length = AXIS_INDEX_COUNT;
  470. }
  471. void MapperStadiaController(const Gamepad& input, Gamepad* mapped) {
  472. *mapped = input;
  473. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  474. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  475. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  476. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  477. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  478. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  479. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  480. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  481. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  482. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  483. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  484. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  485. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  486. mapped->buttons[STADIA_GAMEPAD_BUTTON_EXTRA] = input.buttons[16];
  487. mapped->buttons[STADIA_GAMEPAD_BUTTON_EXTRA2] = input.buttons[17];
  488. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  489. DpadFromAxis(mapped, input.axes[9]);
  490. mapped->buttons_length = STADIA_GAMEPAD_BUTTON_COUNT;
  491. mapped->axes_length = AXIS_INDEX_COUNT;
  492. }
  493. void MapperXSkills(const Gamepad& input, Gamepad* mapped) {
  494. enum GamecubeButtons {
  495. GAMECUBE_BUTTON_LEFT_TRIGGER_CLICK = BUTTON_INDEX_COUNT,
  496. GAMECUBE_BUTTON_RIGHT_TRIGGER_CLICK,
  497. GAMECUBE_BUTTON_COUNT
  498. };
  499. *mapped = input;
  500. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0]; // A
  501. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2]; // X
  502. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[1]; // B
  503. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3]; // Y
  504. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = NullButton();
  505. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[6]; // Z
  506. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
  507. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
  508. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
  509. mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
  510. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = NullButton();
  511. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = NullButton();
  512. mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[11];
  513. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[10];
  514. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[8];
  515. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[9];
  516. mapped->buttons[BUTTON_INDEX_META] = NullButton();
  517. mapped->buttons[GAMECUBE_BUTTON_LEFT_TRIGGER_CLICK] = input.buttons[4];
  518. mapped->buttons[GAMECUBE_BUTTON_RIGHT_TRIGGER_CLICK] = input.buttons[5];
  519. mapped->axes[AXIS_INDEX_LEFT_STICK_X] = input.axes[0];
  520. mapped->axes[AXIS_INDEX_LEFT_STICK_Y] = input.axes[1];
  521. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[5];
  522. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[2];
  523. mapped->buttons_length = GAMECUBE_BUTTON_COUNT;
  524. mapped->axes_length = AXIS_INDEX_COUNT;
  525. }
  526. void MapperBoomN64Psx(const Gamepad& input, Gamepad* mapped) {
  527. *mapped = input;
  528. // Mapped for a PSX device with Analog mode enabled.
  529. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
  530. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  531. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  532. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
  533. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  534. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  535. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
  536. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
  537. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8];
  538. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  539. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[9];
  540. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[10];
  541. mapped->buttons[BUTTON_INDEX_DPAD_UP] = input.buttons[12];
  542. mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = input.buttons[14];
  543. mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = input.buttons[15];
  544. mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] = input.buttons[13];
  545. mapped->buttons[BUTTON_INDEX_META] = NullButton();
  546. mapped->axes[AXIS_INDEX_LEFT_STICK_X] = input.axes[0];
  547. mapped->axes[AXIS_INDEX_LEFT_STICK_Y] = input.axes[1];
  548. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[2];
  549. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  550. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta
  551. mapped->axes_length = AXIS_INDEX_COUNT;
  552. }
  553. void MapperXboxOneBluetooth(const Gamepad& input, Gamepad* mapped) {
  554. *mapped = input;
  555. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  556. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  557. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  558. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  559. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  560. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  561. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[10]);
  562. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[11]);
  563. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[31];
  564. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  565. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  566. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  567. DpadFromAxis(mapped, input.axes[9]);
  568. mapped->buttons[BUTTON_INDEX_META] = input.buttons[30];
  569. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  570. mapped->buttons_length = BUTTON_INDEX_COUNT;
  571. mapped->axes_length = AXIS_INDEX_COUNT;
  572. }
  573. void MapperXboxElite2Bluetooth(const Gamepad& input, Gamepad* mapped) {
  574. *mapped = input;
  575. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
  576. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
  577. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  578. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  579. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  580. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  581. // Firmware updates have changed the mappings in this controller. The newer
  582. // firmware has an axes length of 10 and some new mappings. Since this seems
  583. // to be the only way to tell which firmware version we have we are splitting
  584. // the mapping based on the axes_length.
  585. if (mapped->axes_length > 10) {
  586. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[10]);
  587. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[11]);
  588. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[31];
  589. mapped->buttons[BUTTON_INDEX_META] = input.buttons[30];
  590. } else {
  591. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
  592. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
  593. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[16];
  594. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  595. }
  596. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  597. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
  598. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
  599. DpadFromAxis(mapped, input.axes[9]);
  600. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  601. mapped->buttons_length = BUTTON_INDEX_COUNT;
  602. mapped->axes_length = AXIS_INDEX_COUNT;
  603. }
  604. void MapperSnakebyteIDroidCon(const Gamepad& input, Gamepad* mapped) {
  605. *mapped = input;
  606. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
  607. mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
  608. mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
  609. mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
  610. mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
  611. mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
  612. mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[2];
  613. mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[5];
  614. mapped->buttons[BUTTON_INDEX_META] = NullButton();
  615. DpadFromAxis(mapped, input.axes[9]);
  616. // The iDroid:con has two different modes. Distinguish them based on which
  617. // axes are used.
  618. if ((input.axes_used & 0b11000) == 0) {
  619. // "Game controller 1" mode: digital triggers.
  620. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[8];
  621. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[9];
  622. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  623. } else {
  624. // "Game controller 2" mode: analog triggers.
  625. mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] =
  626. AxisPositiveAsButton(input.axes[2]);
  627. mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] =
  628. AxisNegativeAsButton(input.axes[2]);
  629. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
  630. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
  631. }
  632. mapped->buttons_length = BUTTON_INDEX_COUNT - 1; // no meta
  633. mapped->axes_length = AXIS_INDEX_COUNT;
  634. }
  635. void MapperHoripadSwitch(const Gamepad& input, Gamepad* mapped) {
  636. *mapped = input;
  637. mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
  638. mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
  639. mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
  640. DpadFromAxis(mapped, input.axes[9]);
  641. mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
  642. mapped->buttons[SWITCH_PRO_BUTTON_CAPTURE] = input.buttons[13];
  643. mapped->axes[AXIS_INDEX_LEFT_STICK_X] = input.axes[0];
  644. mapped->axes[AXIS_INDEX_LEFT_STICK_Y] = input.axes[1];
  645. mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[2];
  646. mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
  647. mapped->buttons_length = SWITCH_PRO_BUTTON_COUNT;
  648. mapped->axes_length = AXIS_INDEX_COUNT;
  649. }
  650. constexpr struct MappingData {
  651. GamepadId gamepad_id;
  652. GamepadStandardMappingFunction function;
  653. } AvailableMappings[] = {
  654. // PowerA Wireless Controller - Nintendo GameCube style
  655. {GamepadId::kPowerALicPro, MapperSwitchPro},
  656. // Snakebyte iDroid:con
  657. {GamepadId::kBroadcomProduct8502, MapperSnakebyteIDroidCon},
  658. // DragonRise Generic USB
  659. {GamepadId::kDragonRiseProduct0006, MapperDragonRiseGeneric},
  660. // 2Axes 8Keys Game Pad
  661. {GamepadId::kDragonRiseProduct0011, Mapper2Axes8Keys},
  662. // HORIPAD for Nintendo Switch
  663. {GamepadId::kHoriProduct00c1, MapperHoripadSwitch},
  664. // Xbox 360 Wired
  665. {GamepadId::kMicrosoftProduct028e, MapperXbox360Gamepad},
  666. // Xbox 360 Wireless
  667. {GamepadId::kMicrosoftProduct028f, MapperXbox360Gamepad},
  668. // Xbox One Wired
  669. {GamepadId::kMicrosoftProduct02d1, MapperXbox360Gamepad},
  670. // Xbox One Wired (2015 FW)
  671. {GamepadId::kMicrosoftProduct02dd, MapperXbox360Gamepad},
  672. // Xbox One S (Bluetooth)
  673. {GamepadId::kMicrosoftProduct02e0, MapperXboxOneS},
  674. // Xbox One Elite (USB)
  675. {GamepadId::kMicrosoftProduct02e3, MapperXbox360Gamepad},
  676. // Xbox One S (USB)
  677. {GamepadId::kMicrosoftProduct02ea, MapperXbox360Gamepad},
  678. // Xbox One S (Bluetooth)
  679. {GamepadId::kMicrosoftProduct02fd, MapperXboxOneS2016Firmware},
  680. // Xbox 360 Wireless
  681. {GamepadId::kMicrosoftProduct0719, MapperXbox360Gamepad},
  682. // Xbox One Elite 2 (USB)
  683. {GamepadId::kMicrosoftProduct0b00, MapperXbox360Gamepad},
  684. // Xbox One Elite 2 (Bluetooth)
  685. {GamepadId::kMicrosoftProduct0b05, MapperXboxElite2Bluetooth},
  686. // Xbox Adaptive Controller (USB)
  687. {GamepadId::kMicrosoftProduct0b0a, MapperXbox360Gamepad},
  688. // Xbox Adaptive Controller (Bluetooth)
  689. {GamepadId::kMicrosoftProduct0b0c, MapperXboxOneBluetooth},
  690. // Xbox Series X (Bluetooth)
  691. {GamepadId::kMicrosoftProduct0b13, MapperXboxSeriesXBluetooth},
  692. // Xbox One S (Bluetooth)
  693. {GamepadId::kMicrosoftProduct0b20, MapperXboxBluetooth},
  694. // Xbox Adaptive (Bluetooth)
  695. {GamepadId::kMicrosoftProduct0b21, MapperXboxBluetooth},
  696. // Xbox Elite Series 2 (Bluetooth)
  697. {GamepadId::kMicrosoftProduct0b22, MapperXboxBluetooth},
  698. // Logitech F310, D mode
  699. {GamepadId::kLogitechProductc216, MapperDirectInputStyle},
  700. // Logitech F510, D mode
  701. {GamepadId::kLogitechProductc218, MapperDirectInputStyle},
  702. // Logitech F710, D mode
  703. {GamepadId::kLogitechProductc219, MapperDirectInputStyle},
  704. // Playstation SIXAXIS
  705. {GamepadId::kSonyProduct0268, MapperPlaystationSixAxis},
  706. // Playstation Dualshock 4
  707. {GamepadId::kSonyProduct05c4, MapperDualshock4},
  708. // Dualshock 4 (PS4 Slim)
  709. {GamepadId::kSonyProduct09cc, MapperDualshock4},
  710. // Dualshock 4 USB receiver
  711. {GamepadId::kSonyProduct0ba0, MapperDualshock4},
  712. // DualSense
  713. {GamepadId::kSonyProduct0ce6, MapperDualSense},
  714. // Switch Joy-Con L
  715. {GamepadId::kNintendoProduct2006, MapperSwitchJoyCon},
  716. // Switch Joy-Con R
  717. {GamepadId::kNintendoProduct2007, MapperSwitchJoyCon},
  718. // Switch Pro Controller
  719. {GamepadId::kNintendoProduct2009, MapperSwitchPro},
  720. // Switch Charging Grip
  721. {GamepadId::kNintendoProduct200e, MapperSwitchPro},
  722. // iBuffalo Classic
  723. {GamepadId::kPadixProduct2060, MapperIBuffalo},
  724. // SmartJoy PLUS Adapter
  725. {GamepadId::kLakeviewResearchProduct0005, MapperSmartJoyPLUS},
  726. // Nvidia Shield gamepad (2015)
  727. {GamepadId::kNvidiaProduct7210, MapperNvShield},
  728. // XSkills Gamecube USB adapter
  729. {GamepadId::kPlayComProduct0005, MapperXSkills},
  730. // Nexus Player Controller
  731. {GamepadId::kAsusTekProduct4500, MapperADT1},
  732. // XFXforce XGEAR PS2 Controller
  733. {GamepadId::kPdpProduct0003, MapperXGEAR},
  734. // Razer Serval Controller
  735. {GamepadId::kRazer1532Product0900, MapperRazerServal},
  736. // ADT-1 Controller
  737. {GamepadId::kGoogleProduct2c40, MapperADT1},
  738. // Stadia Controller
  739. {GamepadId::kGoogleProduct9400, MapperStadiaController},
  740. // Moga Pro Controller (HID mode)
  741. {GamepadId::kBdaProduct6271, MapperMogaPro},
  742. // Macally iShockX, analog mode
  743. {GamepadId::kMacAllyProduct0060, MapperDirectInputStyle},
  744. // Macally iShock
  745. {GamepadId::kMacAllyProduct4010, MapperMacallyIShock},
  746. // OnLive Controller (Bluetooth)
  747. {GamepadId::kOnLiveProduct1008, MapperOnLiveWireless},
  748. // OnLive Controller (Wired)
  749. {GamepadId::kOnLiveProduct100a, MapperOnLiveWireless},
  750. // OUYA Controller
  751. {GamepadId::kOuyaProduct0001, MapperOUYA},
  752. // SCUF Vantage, SCUF Vantage 2
  753. {GamepadId::kScufProduct7725, MapperDualshock4},
  754. // boom PSX+N64 USB Converter
  755. {GamepadId::kPrototypeVendorProduct0667, MapperBoomN64Psx},
  756. // Stadia Controller prototype
  757. {GamepadId::kPrototypeVendorProduct9401, MapperStadiaControllerOldFirmware},
  758. };
  759. } // namespace
  760. GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
  761. const base::StringPiece product_name,
  762. const uint16_t vendor_id,
  763. const uint16_t product_id,
  764. const uint16_t hid_specification_version,
  765. const uint16_t version_number,
  766. GamepadBusType bus_type) {
  767. GamepadId gamepad_id =
  768. GamepadIdList::Get().GetGamepadId(product_name, vendor_id, product_id);
  769. const MappingData* begin = std::begin(AvailableMappings);
  770. const MappingData* end = std::end(AvailableMappings);
  771. const auto* find_it = std::find_if(begin, end, [=](const MappingData& item) {
  772. return gamepad_id == item.gamepad_id;
  773. });
  774. GamepadStandardMappingFunction mapper =
  775. (find_it == end) ? nullptr : find_it->function;
  776. // The Switch Joy-Con Charging Grip allows a pair of Joy-Cons to be docked
  777. // with the grip and used over USB as a single composite gamepad. The Nintendo
  778. // data fetcher also allows a pair of Bluetooth-connected Joy-Cons to be used
  779. // as a composite device and sets the same product ID as the Charging Grip.
  780. //
  781. // In both configurations, we remap the Joy-Con buttons to align with the
  782. // Standard Gamepad mapping. Docking a Joy-Con in the Charging Grip makes the
  783. // SL and SR buttons inaccessible.
  784. //
  785. // If the Joy-Cons are not docked, the SL and SR buttons are still accessible.
  786. // Inspect the |bus_type| of the composite device to detect this case and use
  787. // an alternate mapping function that exposes the extra buttons.
  788. if (gamepad_id == GamepadId::kNintendoProduct200e &&
  789. mapper == MapperSwitchPro && bus_type != GAMEPAD_BUS_USB) {
  790. mapper = MapperSwitchComposite;
  791. }
  792. // Use an alternate mapping function if the Stadia controller is using an old
  793. // firmware version.
  794. if (gamepad_id == GamepadId::kGoogleProduct9400 &&
  795. mapper == MapperStadiaController &&
  796. version_number == kStadiaControllerOldFirmwareVersion) {
  797. mapper = MapperStadiaControllerOldFirmware;
  798. }
  799. return mapper;
  800. }
  801. } // namespace device