aboutsummaryrefslogtreecommitdiffstats
path: root/libgamepad.h
blob: 404e526974a1d4a05e137540723d4af826578c1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
/* See LICENSE file for copyright and license details. */
#ifndef LIBGAMEPAD_H
#define LIBGAMEPAD_H

#include <linux/input.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include <libevdev/libevdev.h>


/**
 * Opaque structure for monitoring device attachment changes
 */
typedef struct libgamepad_attachment_monitor LIBGAMEPAD_ATTACHMENT_MONITOR;

/**
 * Opaque structure for internal data in `struct libgamepad_device`
 */
typedef struct libgamepad_device_internals LIBGAMEPAD_DEVICE_INTERNALS;


/**
 * Device attachment event type
 */
enum libgamepad_attachment_event_type {
	/**
	 * Device has been added
	 */
	LIBGAMEPAD_ADDED,

	/**
	 * Device has been removed
	 */
	LIBGAMEPAD_REMOVED
};


/**
 * Device categorisation
 */
enum libgamepad_class {
	/**
	 * Unknown category
	 */
	LIBGAMEPAD_CLASS_UNKNOWN,

	/**
	 * Unlisted category
	 */
	LIBGAMEPAD_CLASS_OTHER,

	/**
	 * Game controller
	 */
	LIBGAMEPAD_CLASS_GAME_CONTROLLER,

	/**
	 * Joystick
	 */
	LIBGAMEPAD_CLASS_JOYSTICK,

	/**
	 * Steering wheel
	 */
	LIBGAMEPAD_CLASS_STEERING_WHEEL,

	/**
	 * TV remote controller
	 */
	LIBGAMEPAD_CLASS_TV_CONTROLLER,

	/**
	 * 3D modelling mouse
	 */
	LIBGAMEPAD_CLASS_3D_MOUSE,

	/**
	 * Motion sensor (typically camera)
	 */
	LIBGAMEPAD_CLASS_MOTION_SENSOR,

	/**
	 * Piano or similar instrument
	 */
	LIBGAMEPAD_CLASS_PIANO,

	/**
	 * Guitar
	 */
	LIBGAMEPAD_CLASS_GUITAR,

	/**
	 * Drum set
	 */
	LIBGAMEPAD_CLASS_DRUMS,

	/**
	 * Gun
	 */
	LIBGAMEPAD_CLASS_GUN,

	/**
	 * Pen
	 */
	LIBGAMEPAD_CLASS_PEN,

	/**
	 * Non-interactive sensor,
	 * e.g. accelerometer built into laptop
	 */
	LIBGAMEPAD_CLASS_SENSOR
};


/**
 * Game controller profiles
 * 
 * This list only contains well-known profiles, mainly
 * the primary controllers from video gaming consoles
 * and handheld gaming consoles
 */
enum libgamepad_game_controller {
	/**
	 * Unknown controller profile
	 */
	LIBGAMEPAD_CONTROLLER_UNKNOWN,

	/**
	 * Unlisted controller profile
	 */
	LIBGAMEPAD_CONTROLLER_OTHER,

	/* TODO force feedback capabilities */

	/**
	 * Amazon Luna Controller
	 * 
	 * Released 2022-03-01 for Amazon Luna
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = "Y"
	 *     - West  = "X"
	 *     - South = "A"
	 *     - East  = "B"
	 *     Digital button "LB" at upper left index finger position
	 *     Digital button "RB" at upper right index finger position
	 *     Analogue button "LT" at lower left index finger position
	 *     Analogue button "RT" at lower right index finger position
	 *     Four buttons at upper centre position:
	 *     - West   = Home (icon: circle)
	 *     - Centre = Action (icon: brand)
	 *     - East   = Menu (icon: three vertically stacked horizontal line)
	 *     - South  = Microphone (icon: microphone)
	 * 
	 * Other features:
	 * - Built in microphone
	 * - Stereo headset port
	 * - Wireless via WiFi
	 * - Wireless via Bluetooth Low Energi 4.2
	 * - RGB LED on Action button (??)
	 */
	LIBGAMEPAD_CONTROLLER_AMAZON_LUNA,

	/**
	 * DualSense
	 * 
	 * Released 2020-11-12 for PlayStation 5
	 * 
	 * Layout:
	 *     Digital D-pad at upper left thumb position
	 *     Clickable analogue stick at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = Triangle
	 *     - West  = Square
	 *     - South = Cross
	 *     - East  = Circle
	 *     Digital button "L1" at upper left index finger position
	 *     Digital button "R1" at upper right index finger position
	 *     Analogue button "L2" at lower left index finger position
	 *     Analogue button "R2" at lower right index finger position
	 *     Digital Create (logo: \|/) button north east of D-pad
	 *     Digital Options (logo: three vertically stacked horizontal line)
	 *       button north west of upper right thumb position
	 *     Two digital buttons between analogue stick:
	 *     - North = PS (icon: brand)
	 *     - South = Microphone mute (icon: NW-to-SE diagonally crossed out microphone)
	 *     Clickable 2-point capacitive touchpad between upper thumb positions
	 * 
	 * Other features:
	 * - Built in dual-microphone array
	 * - Built in single-channel speaker
	 * - Stereo headset port
	 * - Extension port
	 * - Wireless via WiFi
	 * - Wireless via Bluetooth 5.1
	 * - RGB LED
	 * - 5 digital LEDs
	 * - 3 axis accelerometer
	 * - 3 axis gyroscope
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_SENSE,

	/**
	 * Google Stadia Controller
	 * 
	 * Released 2019-11-19 for Google Stadia
	 *
	 * Layout:
	 *     Digital D-pad at upper left thumb position
	 *     Clickable analogue stick at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = "Y"
	 *     - West  = "X"
	 *     - South = "A"
	 *     - East  = "B"
	 *     Digital button "L1" at upper left index finger position
	 *     Digital button "R1" at upper right index finger position
	 *     Analogue button "L2" at lower left index finger position
	 *     Analogue button "R2" at lower right index finger position
	 *     Digital Stadia (icon: brand) button between analogue sticks
	 *     2 digital buttons at inner left thumb position:
	 *     - North = Options (icon: three horizontally stacked dots)
	 *     - East  = Google Assistant (icon: four uniquely arrayed dots)
	 *     2 digital buttons at inner right thumb position:
	 *     - North = Menu (icon: three vertically stacked horizontal lines)
	 *     - West  = Capture (icon: corners of a square)
	 * 
	 * Other features:
	 * - Built in microphone (??)
	 * - Stereo headset port
	 * - Wireless via WiFi
	 * - Wireless via Bluetooth Low Energi 4.2
	 * - LED (unknown capabilities)
	 */
	LIBGAMEPAD_CONTROLLER_GOOGLE_STADIA,

	/**
	 * Nintendo Switch Pro Controller
	 * 
	 * Released 2017-03-03 for Nintendo Switch
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = "X"
	 *     - West  = "Y"
	 *     - South = "B"
	 *     - East  = "A"
	 *     Digital button "L" at upper left index finger position
	 *     Digital button "R" at upper right index finger position
	 *     Digital button "ZL" at lower left index finger position
	 *     Digital button "ZR" at lower right index finger position
	 *     Digital Stadia (icon: brand) button between analogue sticks
	 *     2 digital buttons at inner left thumb position:
	 *     - North = "−"
	 *     - East  = Capture (icon: circle; shape: square)
	 *     2 digital buttons at inner right thumb position:
	 *     - North = "+"
	 *     - West  = Home (icon: house)
	 * 
	 * Other features:
	 * - Wireless via Bluetooth
	 * - Wireless via NFC
	 * - Accelerometer (3 axis??)
	 * - Gyroscope (3 axis??)
	 * - 4 digital LEDs (??)
	 * 
	 * Some versions seem to have additional features
	 */
	LIBGAMEPAD_CONTROLLER_NINTENDO_SWITCH_PRO,

	/**
	 * Joy-Con L
	 * 
	 * Released 2017-03-03 for Nintendo Switch
	 * 
	 * Layout (when rotated 90 degrees counter-clockwise to become horizontal):
	 *     Clickable analogue stick at left thumb position
	 *     4 digital directional buttons stick a bit inwards of right thumb position
	 *     Digital "−" button north west of analogue stick
	 *     Digital Capture (icon: circle; shape: square)
	 *       button north east of directional buttons
	 *     On front side (hidden when attached):
	 *       Digital "SL" at left index finger position
	 *       Digital "SR" at right index finger position
	 *       Digital synchronisaton button left of "SR"
	 * 
	 * Additional layout (described from attached state):
	 *     Digital "L" button at upper left index finger position
	 *     Digital "ZL" button at lower left index finger position
	 * 
	 * Other features:
	 * - Wireless via Bluetooth 3.0
	 * - Accelerometer (3 axis??)
	 * - Gyroscope (3 axis??)
	 * - 4 digital LEDs, hidden when attached (??)
	 */
	LIBGAMEPAD_CONTROLLER_JOY_CON_L,

	/**
	 * Joy-Con R
	 * 
	 * Released 2017-03-03 for Nintendo Switch
	 * 
	 * Layout (when rotated 90 degrees clockwise to become horizontal):
	 *     Clickable analogue stick a bit inwards of left thumb position
	 *     4 digital buttons stick at right thumb position
	 *     - North = "Y" ("X" when not rotated)
	 *     - West  = "B" ("Y" when not rotated)
	 *     - South = "A" ("B" when not rotated)
	 *     - East  = "X" ("A" when not rotated)
	 *     Digital "+" button north east of group of 4 digital buttons
	 *     Digital Home (icon: house) button north west of analogue stick
	 *     On front side (hidden when attached):
	 *       Digital "SL" at left index finger position
	 *       Digital "SR" at right index finger position
	 *       Digital synchronisaton button left of "SR"
	 * 
	 * Additional layout (described from attached state):
	 *     Digital "R" button at upper right index finger position
	 *     Digital "ZR" button at lower right index finger position
	 * 
	 * Other features:
	 * - Wireless via Bluetooth 3.0
	 * - Wireless via NFC
	 * - Accelerometer (3 axis??)
	 * - Gyroscope (3 axis??)
	 * - 4 digital LEDs, hidden when attached (??)
	 * - Infrared depth camera for motion sensoring
	 */
	LIBGAMEPAD_CONTROLLER_JOY_CON_R,

	/**
	 * Joy-Con
	 * 
	 * Released 2017-03-03 for Nintendo Switch
	 * 
	 * Joy-Con L and Joy-Con R together in attached state
	 */
	LIBGAMEPAD_CONTROLLER_JOY_CON,

	/**
	 * Steam Controller
	 * 
	 * Released 2015-11-10 for Steam
	 * 
	 * TODO Document Steam Controller
	 */
	LIBGAMEPAD_CONTROLLER_STEAM,

	/**
	 * Xbox Wireless Controller
	 * 
	 * Released 2013-11-22 for Xbox One, also primary
	 * controller for Xbox Series X and Xbox Series S
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position
	 *     - North = "Y" (colour: yellow)
	 *     - West  = "X" (colour: blue)
	 *     - South = "A" (colour: green)
	 *     - East  = "B" (colour: red)
	 *     3 or 4 digital buttons at centre position
	 *     - North = Xbox (icon: brand)
	 *     - West  = View (icon: two z-stacked windows)
	 *     - East  = Menu (icon: three vertically stacked horizontal lines)
	 * 
	 * Other features:
	 * - Wireless via proprietary protocol
	 * - Wireless via Bluetooth 4.0 (second revision)
	 * - Stereo headset port (second revision)
	 * - Extension port
	 * 
	 * Some versions have additional buttons.
	 * "Y", "X", "A", and "B" are not coloured on some versions.
	 */
	LIBGAMEPAD_CONTROLLER_XBOX_WIRELESS,

	/**
	 * Xbox Wireless Controller, third revision
	 * 
	 * Released 2020-11-10 for Xbox Series X and Xbox Series S
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position
	 *     - North = "Y" (colour: yellow)
	 *     - West  = "X" (colour: blue)
	 *     - South = "A" (colour: green)
	 *     - East  = "B" (colour: red)
	 *     3 or 4 digital buttons at centre position
	 *     - North = Xbox (icon: brand)
	 *     - West  = View (icon: two z-stacked windows)
	 *     - South = Share (icon: flat rectangle with upper edge replace with an up-arrow)
	 *     - East  = Menu (icon: three vertically stacked horizontal lines)
	 * 
	 * Other features:
	 * - Wireless via proprietary protocol
	 * - Wireless via Bluetooth Low Energy
	 * - Stereo headset port
	 * - Extension port
	 * 
	 * Some versions have additional buttons.
	 * "Y", "X", "A", and "B" are not coloured on some versions.
	 */
	LIBGAMEPAD_CONTROLLER_XBOX_WIRELESS_REV_3,

	/**
	 * DualShock 4
	 * 
	 * Released 2013-11-15 for PlayStation 4
	 * 
	 * Layout:
	 *     Digital D-pad at upper left thumb position
	 *     Clickable analogue stick at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = Triangle (colour: green)
	 *     - West  = Square (colour: pink)
	 *     - South = Cross (colour: blue)
	 *     - East  = Circle (colour: red)
	 *     Digital button "L1" at upper left index finger position
	 *     Digital button "R1" at upper right index finger position
	 *     Analogue button "L2" at lower left index finger position
	 *     Analogue button "R2" at lower right index finger position
	 *     Digital "SHARE" button north east of D-pad
	 *     Digital "OPTIONS" button north west of upper right thumb position
	 *     Digital PS (icon: brand) button between analogue stick
	 *     Clickable 2-point capacitive touchpad between upper thumb positions
	 * 
	 * Other features:
	 * - Stereo headset port
	 * - Extension port
	 * - Wireless via Bluetooth 2.1+EDR
	 * - RGB LED
	 * - 3 axis accelerometer
	 * - 3 axis gyroscope
	 * - Built in single-channel speaker
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_SHOCK_4,

	/**
	 * Ouya controller
	 * 
	 * Released 2013-06-25 for Ouya
	 *
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = "Y" (colour: orange–yellow)
	 *     - West  = "U" (colour: blue)
	 *     - South = "O" (colour: lime)
	 *     - East  = "A" (colour: red)
	 *     Digital Menu (icon: U inscribed in a ring) button between,
	 *        but slightly below, the D-pad and right stick
	 *     Touchpad (details missing) between upper thumb positions
	 *     Digital button at upper left index finger position
	 *     Digital button at upper right index finger position
	 *     Analogue button at lower left index finger position
	 *     Analogue button at lower right index finger position
	 * 
	 * Other features:
	 * - Wireless via Bluetooth
	 */
	LIBGAMEPAD_CONTROLLER_OUYA,

	/**
	 * Wii U Pro Controller
	 * 
	 * Released 2012-11-18 for Wii U
	 * 
	 * TODO Document Wii U Pro Controller
	 */
	LIBGAMEPAD_CONTROLLER_WII_U_PRO,

	/**
	 * Wii U GamePad
	 * 
	 * Released 2012-11-18 for Wii U
	 * 
	 * TODO Document Wii U GamePad
	 */
	LIBGAMEPAD_CONTROLLER_WII_U,

	/**
	 * PlayStation Move Navigation controller
	 * 
	 * Released 2010-09-15 for PlayStation 3
	 * 
	 * TODO Document PlayStation Move Navigation controller
	 */
	LIBGAMEPAD_CONTROLLER_PLAYSTATION_MOVE_NAVIGATION,

	/**
	 * PlayStation Move
	 * 
	 * Released 2010-09-15 for PlayStation 3
	 * 
	 * TODO Document PlayStation Move
	 */
	LIBGAMEPAD_CONTROLLER_PLAYSTATION_MOVE,

	/**
	 * Classic Controller Pro
	 * 
	 * Released 2009-??-?? for Wii
	 * 
	 * TODO Document Classic Controller Pro
	 */
	LIBGAMEPAD_CONTROLLER_WII_CLASSIC_PRO,

	/**
	 * DualShock 3
	 * 
	 * Released 2007-11-11 for PlayStation 3
	 * 
	 * Adds rumble support to `LIBGAMEPAD_CONTROLLER_SIXAXIS`,
	 * no other differences
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_SHOCK_3,

	/**
	 * Classic Controller
	 * 
	 * Released 2006-11-19 for Wii
	 * 
	 * TODO Document Classic Controller
	 */
	LIBGAMEPAD_CONTROLLER_WII_CLASSIC,

	/**
	 * Nunchuk
	 * 
	 * Released 2006-11-19 for Wii
	 * 
	 * TODO Document Nunchuk
	 */
	LIBGAMEPAD_CONTROLLER_NUNCHUK,

	/**
	 * Wii Remote
	 * 
	 * Released 2006-11-19 for Wii
	 * 
	 * TODO Document Wii Remote
	 */
	LIBGAMEPAD_CONTROLLER_WII_REMOTE,

	/**
	 * Wii Remote Plus
	 * 
	 * Released 2010-10-28 for Wii
	 * 
	 * Adds (3 axis?) gyroscope to `LIBGAMEPAD_CONTROLLER_WII_REMOTE`
	 */
	LIBGAMEPAD_CONTROLLER_WII_REMOTE_PLUS,

	/**
	 * Sixaxis
	 * 
	 * Released 2006-11-11 for PlayStation 3
	 * 
	 * Note:
	 * - Newer Linux drivers no longer report pressure on the D-pad
	 *   (reason: "there is no good way for reporting them")
	 * - Newer Linux drivers no longer report pressure L1, L2, Triangle, Square, Cross, or Circle
	 *   (reason: "there is no good way for reporting them")
	 * - Newer Linux drivers no longer report gyroscope readings
	 *   (reason: "very difficult to manage from within the driver even to get
	 *             data, the sensor is inaccurate and the behavior is very
	 *             different between hardware revisions")
	 * - Older Linux drivers failed to report left pressure on the D-pad
	 * 
	 * Layout:
	 *     Pressure-sensitive D-pad at upper left thumb position
	 *     Clickable analogue stick at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 Pressure-sensitive buttons at upper right thumb position:
	 *     - North = Triangle (colour: green)
	 *     - West  = Square (colour: pink)
	 *     - South = Cross (colour: blue)
	 *     - East  = Circle (colour: red)
	 *     Pressure-sensitive button "L1" at upper left index finger position
	 *     Pressure-sensitive button "R1" at upper right index finger position
	 *     Analogue button "L2" at lower left index finger position
	 *     Analogue button "R2" at lower right index finger position
	 *     3 digital buttons at centre position:
	 *     - West  = "SELECT" (shape: flat rectangle)
	 *     - East  = "START"  (shape: flat play icon)
	 *     - South = PS (icon: brand)
	 * 
	 * Other features:
	 * - Stereo headset port
	 * - Extension port
	 * - Wireless via Bluetooth 2.1+EDR
	 * - 4 digital LEDs numbered 1 through 4
	 * - 3 axis accelerometer
	 * - 1 axis gyroscope
	 * - Built in single-channel speaker
	 */
	LIBGAMEPAD_CONTROLLER_SIXAXIS,

	/**
	 * Xbox 360 Controller
	 * 
	 * Released 2005-11-22 for Xbox 360
	 * 
	 * TODO Document Xbox 360 Controller
	 */
	LIBGAMEPAD_CONTROLLER_XBOX_360,

	/**
	 * Xbox Controller S
	 * 
	 * Released 2002-??-?? for Xbox
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 Pressure-sensitive buttons at upper right thumb position:
	 *     - North = "Y" (colour: orange)
	 *     - West  = "X" (colour: blue)
	 *     - South = "A" (colour: green)
	 *     - East  = "B" (colour: red)
	 *     Digital button "L" at left index finger position
	 *     Digital button "R" at right index finger position
	 *     Analogue button "LT" at left long finger position
	 *     Analogue button "RT" at right long finger position
	 *     2 digital buttons west of lower left thumb position
	 *     - North = "BACK" (icon: mirrored play icon)
	 *     - East  = "START"  (icon: play icon)
	 *     2 Pressure-sensitive  buttons east of lower right thumb position
	 *     - East  = Black (colour: black)
	 *     - South = White  (colour: white)
	 */
	LIBGAMEPAD_CONTROLLER_XBOX_S,

	/**
	 * Xbox Controller
	 * 
	 * Released 2001-11-15 for Xbox
	 * 
	 * Layout:
	 *     Clickable analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     6 Pressure-sensitive buttons at upper right thumb position:
	 *     - North = "Y" (colour: orange)
	 *     - West  = "X" (colour: blue)
	 *     - South = "A" (colour: green)
	 *     - East  = "B" (colour: red)
	 *     - North east (slightly off) of "Y" = White (colour: white)
	 *     - North east (slightly off) of "B" = Black (colour: black)
	 *     Digital button "L" at left index finger position
	 *     Digital button "R" at right index finger position
	 *     Analogue button "LT" at left long finger position
	 *     Analogue button "RT" at right long finger position
	 *     2 digital buttons at lower centre thumb position
	 *     - East = "BACK" 
	 *     - West = "START"
	 */
	LIBGAMEPAD_CONTROLLER_XBOX,

	/**
	 * Nintendo GameCube controller
	 * 
	 * Released 2001-09-14 for Nintendo GameCube
	 * 
	 * Layout:
	 *     Analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     Analogue "C" (colour: yellow) stick at lower right thumb position
	 *     4 digit buttons at upper right thumb position:
	 *     - Centre           = "A" (colour: green; extra large)
	 *     - South west       = "B" (colour: red)
	 *     - North north west = "Y" (shape: circle arc)
	 *     - North east east  = "X" (shape: circle arc)
	 *     Digital button "Z" (colour: blue) at upper right index finger position
	 *     Analogue button "L" at lower left index finger position
	 *     Analogue button "R" at lower right index finger position
	 *     Digital "START/PAUSE" button at centre thumb position
	 * 
	 * Other features:
	 * - "L" and "R" sends digital signal when fully depressed
	 */
	LIBGAMEPAD_CONTROLLER_NINTENDO_GAME_CUBE,

	/**
	 * DualShock 2 Analog Controller
	 * 
	 * Released 2000-03-04 for PlayStation 2
	 * 
	 * Layout:
	 *     Pressure-sensitive D-pad at upper left thumb position
	 *     Clickable analogue stick at lower left thumb position
	 *     Clickable analogue stick at lower right thumb position
	 *     4 Pressure-sensitive buttons at upper right thumb position:
	 *     - North = Triangle (colour: green)
	 *     - West  = Square (colour: pink)
	 *     - South = Cross (colour: blue)
	 *     - East  = Circle (colour: red)
	 *     Pressure-sensitive button "L1" at upper left index finger position
	 *     Pressure-sensitive button "R1" at upper right index finger position
	 *     Pressure-sensitive button "L2" at lower left index finger position
	 *     Pressure-sensitive button "R2" at lower right index finger position
	 *     2 digital buttons at centre position:
	 *     - West = "SELECT" (shape: flat rectangle)
	 *     - East = "START"  (shape: flat play icon)
	 * 
	 * Other features:
	 * - LED-indicated digital "ANALOG" button at south part of center position
	 *   for toggling between analogue and digital mode
	 *   (TODO What does digital mode on DualShock 2 do?)
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_SHOCK_2,

	/**
	 * Dreamcast controller
	 * 
	 * Released 1998-11-27 for Dreamcast
	 * 
	 * Layout:
	 *     Analogue stick at upper left thumb position
	 *     Digital D-pad at lower left thumb position
	 *     4 digital buttons at upper right thumb position:
	 *     - North = "Y" (colour: green)
	 *     - West  = "X" (colour: yellow)
	 *     - South = "A" (colour: red)
	 *     - East  = "B" (colour: blue)
	 *     Digital "START" (shape: up-pointing equilateral trangle)
	 *       button at lower centre thumb position
	 * 
	 * Other features:
	 * - 2 expansion sockets
	 */
	LIBGAMEPAD_CONTROLLER_DREAMCAST,

	/**
	 * DualShock Analog Controller
	 * 
	 * Released 1997-11-20 for PlayStation
	 * 
	 * TODO Document DualShock Analog Controller
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_SHOCK,

	/**
	 * Dual Analog Controller
	 * 
	 * Released 1997-04-25 for PlayStation
	 * 
	 * TODO Document Dual Analog Controller
	 */
	LIBGAMEPAD_CONTROLLER_DUAL_ANALOG,

	/**
	 * 3D Pad
	 * 
	 * Released 1996-07-05 for Sega Saturn
	 * 
	 * TODO Document 3D Pad
	 */
	LIBGAMEPAD_CONTROLLER_3D_PAD,

	/**
	 * Nintendo 64 controller
	 * 
	 * Released 1996-06-23 for Nintendo 64
	 * 
	 * Layout:
	 *     M-shaped, allowing it to be hold one-handed as
	 *       a gun or two-handed as a regular game controller
	 *     Digital D-pad at left thumb position
	 *     Analogue stick at middle thumb position
	 *     4 directional "C" (colour: yellow) buttons at right thumb position
	 *     Digital "L" button at left index finger position
	 *     Digital "Z" button at middle index finger position
	 *     Digital "R" button at right index finger position
	 *     Digital "START" (colour: red) button north of middle thumb position
	 *     2 digital buttons south east of right thumb position
	 *     - North = "B" (colour: green)
	 *     - West  = "A" (colour: blue)
	 * 
	 * Other features:
	 * - Expension slot
	 */
	LIBGAMEPAD_CONTROLLER_NINTENDO_64,

	/**
	 * Virtual Boy controller
	 *
	 * Released 1995-07-21 for Virtual Boy
	 *
	 * Layout:
	 *     Digital D-pad at outer left thumb position
	 *     Digital D-pad at outer right thumb position
	 *     Digital "SELECT" button at middle left thumb position
	 *     Digital "A" button at middle right thumb position
	 *     Digital "START" button at inner left thumb position
	 *     Digital "B" button at inner right thumb position
	 *     Digital button at rear left index finger position
	 *     Digital button at rear right index finger position
	 */
	LIBGAMEPAD_CONTROLLER_VIRTUAL_BOY,

	/**
	 * PlayStation Controller
	 * 
	 * Released 1994-12-03 for PlayStation
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     4 digital buttons at right thumb position:
	 *     - North = Triangle (colour: green)
	 *     - West  = Square (colour: pink)
	 *     - South = Cross (colour: blue)
	 *     - East  = Circle (colour: red)
	 *     Digital button "L1" at upper left index finger position
	 *     Digital button "R1" at upper right index finger position
	 *     Digital button "L2" at lower left index finger position
	 *     Digital button "R2" at lower right index finger position
	 *     2 digital buttons at centre position:
	 *     - West = "SELECT" (shape: flat rectangle)
	 *     - East = "START"  (shape: flat play icon)
	 */
	LIBGAMEPAD_CONTROLLER_PLAY_STATION,

	/**
	 * Sega Saturn controller
	 * 
	 * Released 1994-11-22 for Sega Saturn
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     6 digital buttons at right thumb position:
	 *     - Lower left   = "A"
	 *     - Lower middle = "B"
	 *     - Lower right  = "C"
	 *     - Upper left   = "X"
	 *     - Upper middle = "Y"
	 *     - Upper right  = "Z"
	 *     Digital button left index finger position
	 *     Digital button right index finger position
	 *     Digital "START" (shape: horizontal line) button at centre position
	 */
	LIBGAMEPAD_CONTROLLER_SEGA_SATURN,

	/**
	 * 6-Button Arcade Pad
	 * 
	 * Released 1993-??-?? for Sega Mega Drive
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     6 digital buttons at right thumb position:
	 *     - Lower left   = "A"
	 *     - Lower middle = "B"
	 *     - Lower right  = "C"
	 *     - Upper left   = "X"
	 *     - Upper middle = "Y"
	 *     - Upper right  = "Z"
	 *     Digital "MODE" button right index finger position
	 *     Digital "START" (shape: horizontal line) button at centre position
	 * 
	 * Conforming platforms:
	 * - Sega Nomad (however "MODE" is east of "START" which is far south east of "A")
	 */
	LIBGAMEPAD_CONTROLLER_6_BUTTON_ARCADE_PAD,

	/**
	 * Gravis PC GamePad
	 * 
	 * Released 1992-??-?? for PC
	 *
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     4 digital buttons at right thumb position
	 *     - North = blue
	 *     - West  = red
	 *     - South = yellow
	 *     - East  = green
	 * 
	 * Other features:
	 * - Has a switch for rotating the layout 180 degrees
	 * - Has a switch for turning two buttons into autofire versions of the other two
	 */
	LIBGAMEPAD_CONTROLLER_GRAVIS_PC,

	/**
	 * SNES controller
	 * 
	 * Released 1990-11-21 for SNES (Super Nintendo Entertainment System)
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     4 digital buttons at right thumb position:
	 *     - North = "X" (colour: blue)
	 *     - West  = "Y" (colour: green)
	 *     - South = "B" (colour: yellow)
	 *     - East  = "A" (colour: red)
	 *     Digital "L" button at left index finger position
	 *     Digital "R" button at right index finger position
	 *     2 digital (/ shaped) buttons at centre thumb position:
	 *     - East = "SELECT"
	 *     - West = "START"
	 *
	 * The buttons are uncoloured on some versions
	 */
	LIBGAMEPAD_CONTROLLER_SNES,

	/**
	 * Sega Mega Drive controller
	 * 
	 * Released 1988-10-29 for Sega Mega Drive
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     3 digital buttons at right thumb position:
	 *     - Left   = "A"
	 *     - Middle = "B"
	 *     - Right  = "C"
	 *     Digital "START" (shape: horizontal line) above "B"
	 */
	LIBGAMEPAD_CONTROLLER_SEGA_MEGA_DRIVE,

	/**
	 * Master System controller
	 * 
	 * Released 1986-09-?? for Master System
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     2 digital buttons at right thumb position:
	 *     - West  = "1 START"
	 *     - East  = "2"
	 */
	LIBGAMEPAD_CONTROLLER_MASTER_SYSTEM,

	/**
	 * NES controller
	 * 
	 * Released 1983-07-15 for NES (Nintendo Entertainment System)
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     2 digital buttons at right thumb position:
	 *     - West = "B"
	 *     - East = "A"
	 *     2 digital buttons (shape: horizontal line) at centre thumb position:
	 *     - West = "SELECT"
	 *     - East = "START"
	 * 
	 * Conforming platforms:
	 * - Nintendo Game Boy
	 * - Supervision (however "START" is also labelled "PAUSE" and the "SELECT" and "START"
	 *                buttons are horizontal and north (slightly east) for "A" and "B" which
	 *                are with a / slant)
	 * - Mega Duck (however "SELECT" and "START" are south of "A" and "B")
	 */
	LIBGAMEPAD_CONTROLLER_NES,

	/**
	 * Steam Deck
	 * 
	 * Handheld gaming PC released 2022-02-25
	 * 
	 * Layout:
	 *     Digital D-pad at outer left thumb position
	 *     Analogue stick with capacitive touch at natural left thumb position
	 *     Analogue stick with capacitive touch at natural right thumb position
	 *     4 digital buttons at outer right thumb position:
	 *     - North = "Y"
	 *     - West  = "X"
	 *     - South = "A"
	 *     - East  = "B"
	 *     Multi-touch trackpad at lower left thumb position
	 *     Multi-touch trackpad at lower right thumb position
	 *     Digital "L1" button at upper left index finger position
	 *     Digital "R1" button at upper right index finger position
	 *     Analogue "L2" button at lower left index finger position
	 *     Analogue "R2" button at lower right index finger position
	 *     Digital "L4" button at left long finger position
	 *     Digital "R4" button at right long finger position
	 *     Digital "L5" button at left ring finger position
	 *     Digital "R5" button at right ring finger position
	 *     Digital "STEAM" button beneath lower left thumb position
	 *     Digital Quick Access (icon: three horizontally stacked dots)
	 *       button beneath lower right thumb position
	 *     Digital View (icon: two z-stacked windows) button
	 *       north west of natural left thumb position
	 *     Digital Menu (icon: three vertically stacked horizontal lines)
	 *       button north east of natural right thumb position
	 *     2 digital buttons inward from upper left index finger position:
	 *     - Outer = Volume "−"
	 *     - Inner = Volume "+"
	 * 
	 * Other features:
	 * - 3 axis accelerometer
	 * - 3 axis gyroscope
	 * - Ambient light sensor
	 */
	LIBGAMEPAD_CONTROLLER_STEAM_DECK,

	/**
	 * Game Boy Advanced
	 *
	 * Handheld gaming console released 2001-03-21
	 *
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     2 digital buttons at south south west of D-pad
	 *     - North = "START"
	 *     - South = "SELECT"
	 *     2 digital buttons at right thumb position:
	 *     - West = "B"
	 *     - East = "A"
	 *     Digital "L" button at left index finger position
	 *     Digital "R" button at right index finger position
	 *
	 * Conforming platforms:
	 * - Game King (however "SELECT" and "START" are north of D-pad,
	 *              "SELECT" to east and "START to west)
	 */
	LIBGAMEPAD_CONTROLLER_GAME_BOY_ADVANCED,

	/**
	 * Game Gear
	 * 
	 * Handheld gaming console released 1990-10-06
	 * 
	 * Layout:
	 *     Digital D-pad at left thumb position
	 *     2 digital buttons at right thumb position:
	 *     - West  = "1"
	 *     - North = "2"
	 *     Digital "START" (colour: blue, shape: corda-cut circle)
	 *       button north of right thumb position
	 */
	LIBGAMEPAD_CONTROLLER_GAME_GEAR
};


/**
 * Joystick profiles
 * 
 * This list only contains well-known profiles, mainly
 * the primary controllers from video gaming consoles
 */
enum libgamepad_joystick {
	/**
	 * Unknown joystick profile
	 */
	LIBGAMEPAD_JOYSTICK_UNKNOWN,

	/**
	 * Unlisted joystick profile
	 */
	LIBGAMEPAD_JOYSTICK_OTHER,

	/**
	 * Atari CX40 joystick
	 *
	 * Released 1978 for Atari 2600
	 *
	 * Layout:
	 *     8-directional digital joystick in centre
	 *     Digital button at north east
	 */
	LIBGAMEPAD_JOYSTICK_ATARI_CX40
};


/**
 * Device type
 *
 * A device can have any number of these applied to
 * it, it may also have unknown types beyond these
 */
enum libgamepad_type {
	/**
	 * Gamepad, joystick, steering wheel, or similar
	 */
	LIBGAMEPAD_GAMEPAD = 0x0001,

	/**
	 * Computer mouse
	 */
	LIBGAMEPAD_MOUSE = 0x0002
};


/**
 * Gamepad input type
 */
enum libgamepad_input_type {
	/**
	 * Button/key
	 */
	LIBGAMEPAD_BUTTON,

	/**
	 * Absolute axis
	 */
	LIBGAMEPAD_ABSOLUTE_AXIS,

	/**
	 * Relative axis
	 */
	LIBGAMEPAD_RELATIVE_AXIS
};


/**
 * Subdevice input event structure
 */
struct libgamepad_input_event {
	/**
	 * The affect input type
	 */
	enum libgamepad_input_type type;

	/**
	 * Whether the event was polled in a
	 * synchronisation read
	 */
	short int sync_event;

	/**
	 * The button/key or axis affect by the event
	 */
	uint16_t code;

	/**
	 * The new value on the button/key or axis,
	 * or the delta if on a relative axis
	 */
	int32_t value;

	/**
	 * Event timestamp
	 */
	struct timeval time;
};


/**
 * Subdevice on a device
 * 
 * For example a modern gamepad may be split into
 * a gamepad, computer mouse, and motion sensor
 *
 * Structure is always deallocated by the library
 * using free(3)
 */
struct libgamepad_subdevice {
	/**
	 * Device type
	 */
	enum libgamepad_type type;

	/**
	 * Device path
	 */
	char path[];
};


/**
 * Physical device
 * 
 * Contents of structure is deallocated with
 * `libgamepad_close_superdevice`
 */
struct libgamepad_superdevice {
	/**
	 * Device path in /sys
	 */
	char *syspath;

	/**
	 * Number of subdevices
	 */
	size_t ndevices;

	/**
	 * Subdevices
	 */
	struct libgamepad_subdevice **devices;

	/**
	 * Number of LEDs
	 */
	size_t nleds;

	/**
	 * Paths to LEDs
	 */
	char **leds;

	/**
	 * Number of power supplies (batteries)
	 */
	size_t npower_supplies;

	/**
	 * Paths of power supplies (batteries)
	 */
	char **power_supplies;
};


/**
 * Subdevice structure for detailed information listening on input events
 */
struct libgamepad_device {
	/**
	 * File descriptor to the device, the application
	 * may use it to poll for read-readyness
	 */
	int fd;

	/**
	 * Bus type the device is connect via, see BUS_-prefixed
	 * constants in <linux/input.h>
	 */
	unsigned int bus_type;

	/**
	 * Vendor ID for the device (sub- or superdevice)
	 */
	unsigned int vendor;

	/**
	 * Product ID for the device (sub- or superdevice)
	 */
	unsigned int product;

	/**
	 * Product version ID for the device (sub- or superdevice)
	 */
	unsigned int version;

	/**
	 * Data for internal use
	 */
	LIBGAMEPAD_DEVICE_INTERNALS *internals;

	/**
	 * Human-readable device (sub- or superdevice) name
	 */
	const char *name;

	/**
	 * ID that is supposted to be unique to the device
	 * (sub- or superdevice)
	 */
	const char *unique_id;

	/**
	 * The location if the device
	 */
	const char *physical_location;

	/**
	 * Number of (digital) buttons/keys present
	 * on the device
	 */
	size_t nbuttons;

	/**
	 * Number of absolute axes present on the device
	 */
	size_t nabsolute_axes;

	/**
	 * Number of relative axes present on the device
	 */
	size_t nrelative_axes;

	/**
	 * Map from button/key indices to button/key codes
	 */
	uint16_t *buttons;

	/**
	 * Map from absolute axis indices to absolute axis codes
	 */
	uint16_t *absolute_axes;

	/**
	 * Map from relative axis indices to relative axis codes
	 */
	uint16_t *relative_axes;

	/**
	 * Maps from button/key codes to button indices,
	 * non-present buttons/keys map to -1, other
	 * values are in [0, `.nbuttons`[.
	 */
	int16_t button_map[KEY_CNT];

	/**
	 * Maps from absolute axis codes to absolute axis
	 * indices, non-present axes map to -1, other
	 * values are in [0, `.nabsolute_axes`[.
	 */
	int16_t absolute_axis_map[ABS_CNT];

	/**
	 * Maps from relative axis codes to absolute axis
	 * indices, non-present axes map to -1, other
	 * values are in [0, `.nrelative_axes`[.
	 */
	int16_t relative_axis_map[REL_CNT];

	/**
	 * Bitmap of supported force feedback effects
	 */
	uint8_t force_feedback_support[(FF_CNT + 7) / 8];
};


/* FOR INTERNAL USE */
void libgamepad_construct_force_feedback_effect__(struct ff_effect *, const struct ff_effect *, double, uint16_t, uint16_t);


/**
 * Get a list of all available physical devices
 * 
 * @param   devicesp   Output parameter for the list of devices
 * @param   ndevicesp  Output parameter for the number of listed devices
 * @return             0 on success, -1 on failure
 * 
 * This function may fail for any reason specified for
 * realloc(3), open(3), fdopendir(3), or readdir(3)
 */
int libgamepad_list_superdevices(char ***, size_t *);

/**
 * Get information about a physical device
 * 
 * @param   devicep  Output parameter for the device information,
 *                   allocated memory shall be deallocated with
 *                   `libgamepad_close_superdevice(devicep)`
 * @param   syspath  The path of the device, in /sys
 * @return           0 on success, -1 on failure
 * 
 * This function may fail for any reason specified for
 * realloc(3), openat(3), fdopendir(3), or readdir(3)
 */
int libgamepad_open_superdevice(struct libgamepad_superdevice *, const char *);

/**
 * Deallocate the contents of a `struct libgamepad_superdevice`
 * 
 * @param  device  The structure whose nested memory allocations
 *                 shall be deallocated, may be `NULL`
 */
void libgamepad_close_superdevice(struct libgamepad_superdevice *);

/**
 * Search for sound devices built into or attached a device
 * 
 * @param   syspath  The superdevice's path in /sys
 * @param   cardsp   Output parameter for a list of sound card indices
 * @return           The number of found sound cards, -1 on failure
 */
ssize_t libgamepad_find_sound_devices(const char *, size_t **);


/**
 * Create a device attachment monitor
 * 
 * The user shall poll the returned file descriptor
 * for read-readiness, and whenever it is ready,
 * call `libgamepad_get_attachment_event`
 * 
 * @param   monitorp  Output parameter for the monitor, shall deallocated with
 *                    `libgamepad_destroy_attachment_monitor` when no longer used
 * @return            A file descriptor on successful completion, -1 on failure
 *
 * This function may fail for any reason specified by
 * malloc(3), udev_new(3), udev_monitor_new_from_netlink(3), or
 * udev_monitor_enable_receiving(3)
 */
int libgamepad_create_attachment_monitor(LIBGAMEPAD_ATTACHMENT_MONITOR **);

/**
 * Deallocate a device attachment monitor
 * 
 * @param  monitor  The monitor to deallocate; the file descriptor returned
 *                  with it will also be closed and become invalid, may be `NULL`
 */
void libgamepad_destroy_attachment_monitor(LIBGAMEPAD_ATTACHMENT_MONITOR *);

/**
 * Get the next device attachment event
 * 
 * @param   monitor   Monitor created with `libgamepad_create_attachment_monitor`
 * @param   syspathp  Pointer to output buffer for the device's path in /sys;
 *                    the buffer may be reallocated by the function
 * @param   sizep     Pointer to the allocation size of `*syspath`; may be
 *                    updated by the function
 * @param   typep     Output parameter for the attachment event type; in the
 *                    event that this value is set to `LIBGAMEPAD_REMOVED`, the
 *                    device is not necessarily on supported by this library
 * @return            1 on success, 0 if the received event was suppressed
 *                    by the library, -1 on failure
 * 
 * This function may fail for any reason specified for
 * realloc(3) or udev_monitor_receive_device(3); notable,
 * this function may set `errno` to `EAGAIN` or `EINTR`
 */
int libgamepad_get_attachment_event(LIBGAMEPAD_ATTACHMENT_MONITOR *, char **, size_t *, enum libgamepad_attachment_event_type *);


/**
 * Open a subdevice
 * 
 * @param   devicep  Output parameter for the device information and handles;
 *                   deallocated with `libgamepad_close_device`
 * @param   dirfd    File descriptor to path that `path` is relative to
 *                   (unless it is an absolute path), or `AT_FDCWD` for the
 *                   current working directory
 * @param   path     The path to the device, if `NULL` or empty, `dirfd`
 *                   will be used as the file descriptor to the device,
 *                   in which case the application must keep it open until
 *                   the device is closed, and then close it manually, and
 *                   `mode` is ignored
 * @param   mode     Mode to open the device in, normally `O_RDONLY`,
 *                   `O_RDONLY|O_NONBLOCK`, `O_RDWR`, or `O_RDWR|O_NONBLOCK`
 * @return           0 on success, -1 on failure
 * 
 * This function may fail for any reason specified for
 * malloc(3), openat(3) or libevdev_new_from_fd(3)
 */
int libgamepad_open_device(struct libgamepad_device *, int, const char *, int);

/**
 * Close a subdevice
 * 
 * @param  device  Device information and handles, may be `NULL`
 */
void libgamepad_close_device(struct libgamepad_device *);

/**
 * Get the next event on a subdevice
 * 
 * NB! events may be queued internally (by libevdev), therefore
 * an application must either call this function in a loop in
 * its own thread, or have the device opened in non-blocking
 * mode and even the poll the device's file descriptor for
 * read-readyness and when it is ready clal this function in
 * a loop until it sets `errno` to `EAGAIN`.
 * 
 * @param   device  Device to read an event from
 * @param   eventp  Output parameter for the event
 * @return          1 if an event was returned,
 *                  0 if no event was returned,
 *                  -1 on failure
 * 
 * This function may fail for any reason specified for
 * libevdev_next_event(3), including:
 * -  EAGAIN  no more data currently available (non-blocking mode)
 * -  EINTR   system call was interrupted, try again
 * -  ENODEV  device has been unplugged or access has been revoked
 */
int libgamepad_next_event(struct libgamepad_device *, struct libgamepad_input_event *);


/**
 * Get the name of a button/key
 * 
 * @param   device  If `NULL`, a generic name will be returned,
 *                  otherwise the canonical name for the button/key
 *                  on the specific device will be returned
 *                  (`NULL` if not information is unavailable)
 * @param   code    The button/key
 * @return          The button/key's name, `NULL` if not found
 */
const char *libgamepad_get_button_name(const struct libgamepad_device *, uint16_t);

/**
 * Get the name of an absolute axis
 * 
 * @param   device  If `NULL`, a generic name will be returned,
 *                  otherwise the canonical name for the axis
 *                  on the specific device will be returned
 *                  (`NULL` if not information is unavailable)
 * @param   code    The axis
 * @return          The axis' name, `NULL` if not found
 */
const char *libgamepad_get_absolute_axis_name(const struct libgamepad_device *, uint16_t);

/**
 * Get the name of a relative axis
 * 
 * @param   device  If `NULL`, a generic name will be returned,
 *                  otherwise the canonical name for the axis
 *                  on the specific device will be returned
 *                  (`NULL` if not information is unavailable)
 * @param   code    The axis
 * @return          The axis' name, `NULL` if not found
 */
const char *libgamepad_get_relative_axis_name(const struct libgamepad_device *, uint16_t);

/**
 * Get a button/key code from it's name
 * 
 * @param   name  The button/key's name or textual
 *                representation of its code number
 * @return        The button/key, -1 if not found
 */
int16_t libgamepad_get_button_by_name(const char *);

/**
 * Get a absolute axis code from it's name
 * 
 * @param   name  The absolute axis' name or textual
 *                representation of its code number
 * @return        The absolute axis, -1 if not found
 */
int16_t libgamepad_get_absolute_axis_by_name(const char *);

/**
 * Get a relative axis code from it's name
 * 
 * @param   name  The relative axis' name or textual
 *                representation of its code number
 * @return        The relative axis, -1 if not found
 */
int16_t libgamepad_get_relative_axis_by_name(const char *);


/**
 * Get whether a button/key is pressed down or not
 * 
 * @param   device  The device to retrieve the information for
 * @param   code    The button/key
 * @return          1 if the button/key is pressed down,
 *                  0 otherwise
 */
int libgamepad_get_button_is_pressed(struct libgamepad_device *, uint16_t);

/**
 * Get information about an absolute axis
 * 
 * @param   device  The device to retrieve the information for
 * @param   code    The axis
 * @return          Information about the axis
 */
const struct input_absinfo *libgamepad_get_absolute_axis_info(struct libgamepad_device *, uint16_t);
/* `struct input_absinfo` is defined in <linux/input.h> */


/**
 * Grab a subdevice, if not already grabbed
 *
 * This is supposed to block out clients from
 * retrieving events for the device, but it
 * does not necessarily stop them from reading
 * the device state
 * 
 * @param   device  The device to grab
 * @return          0 on success, -1 on failure
 * 
 * In the event that the device is already grabbed by
 * via another open file descriptor (duplicates share
 * grab), this function will return -1 and set `errno`
 * to `EBUSY`
 */
inline int
libgamepad_grab(struct libgamepad_device *device)
{
	return ioctl(device->fd, EVIOCGRAB, (void *)1);
}

/**
 * Ungrab a subdevice, unless not currently grabbed
 * 
 * @param   device  The device to ungrab
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_ungrab(struct libgamepad_device *device)
{
	return ioctl(device->fd, EVIOCGRAB, (void *)0);
}


/**
 * Set the clock that event timestamps shall be reported in
 * 
 * @param   device   The device to configure
 * @param   clockid  The clock to use on event timestamps
 * @return           0 on success, -1 on failure
 */
inline int
libgamepad_set_clock(struct libgamepad_device *device, clockid_t clockid)
{
	return ioctl(device->fd, EVIOCSCLOCKID, &clockid);
}


/**
 * Install a force feedback effect that can be played back later
 * 
 * @param   device  The device to configure
 * @param   effect  The effect to install; will be edited, specifically the ID
 *                  will be set (need not be set before calling this function)
 * @return          0 on success, -1 on failure
 */
inline int /* `struct ff_effect` is defined in <linux/input.h> */
libgamepad_install_force_feedback_effect(struct libgamepad_device *device, struct ff_effect *effect)
{
	effect->id = -1;
	return ioctl(device->fd, EVIOCSFF, effect);
}

/**
 * Reconfigure an already installed force feedback effect
 * 
 * @param   device  The device to configure
 * @param   effect  The effect to update, the ID must be set to the ID of a
 *                  previously installed effect
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_update_force_feedback_effect(struct libgamepad_device *device, struct ff_effect *effect)
{
	return ioctl(device->fd, EVIOCSFF, effect);
}

/**
 * Uninstall an installed force feedback effect
 * 
 * @param   device  The device to configure
 * @param   effect  The effect to remove, the ID must be set to the ID of a
 *                  previously installed effect and will be reset
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_uninstall_force_feedback_effect(struct libgamepad_device *device, struct ff_effect *effect)
{
	int ret = ioctl(device->fd, EVIOCRMFF, effect);
	effect->id = -1;
	return ret;
}

/**
 * Get the number of force feedback effects that can be played concurrently
 * 
 * @param   device  The device to configure
 * @return          The number of maximum number concurrent effects, -1 on failure
 */
inline int
libgamepad_get_force_feedback_max_concurrency(struct libgamepad_device *device)
{
	int num;
	return ioctl(device->fd, EVIOCGEFFECTS, &num) ? -1 : num;
}

/**
 * Play a force feedback effect
 * 
 * @param   device  The device to play the force feedback effect on
 * @param   effect  The force feedback effect to play, must already be installed
 *                  with `libgamepad_install_force_feedback_effect`
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_play_force_feedback_effect(struct libgamepad_device *device, const struct ff_effect *effect)
{
	struct input_event message;
	message.type = EV_FF;
	message.code = (uint16_t)effect->id;
	message.value = 1;
	return write(device->fd, &message, sizeof(message)) < 0 ? -1 : 0;
}

/**
 * Stop playing a force feedback effect
 * 
 * @param   device  The device playing the force feedback effect on
 * @param   effect  The force feedback effect to play, must already be installed
 *                  with `libgamepad_install_force_feedback_effect`
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_stop_force_feedback_effect(struct libgamepad_device *device, const struct ff_effect *effect)
{
	struct input_event message;
	message.type = EV_FF;
	message.code = (uint16_t)effect->id;
	message.value = 0;
	return write(device->fd, &message, sizeof(message)) < 0 ? -1 : 0;
}

/**
 * Check if a force feedback effect or waveform is supported
 *
 * @param   device  The device to check force feedback support on
 * @param   effect  The force feedback effect or waveform
 * @return          1 if the effect/waveform is supported, 0 otherwise
 */
inline int
libgamepad_is_force_feedback_effect_supported(struct libgamepad_device *device, uint16_t effect)
{
	return effect < sizeof(device->force_feedback_support) * 8 &&
	       ((device->force_feedback_support[effect / 8] >> (effect % 8)) & 1);
}

/**
 * Set the force feedback master gain on a device
 * 
 * Requires support for `FF_GAIN` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * @param   device  The device to configure
 * @param   gain    The master gain, shall be a value in [0, 0xFFFF]
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_set_force_feedback_master_gain(struct libgamepad_device *device, uint16_t gain)
{
	struct input_event message;
	message.type = EV_FF;
	message.code = FF_GAIN;
	message.value = (int16_t)gain;
	return write(device->fd, &message, sizeof(message)) < 0 ? -1 : 0;
}

/**
 * Set the autocenter force feedback on a device
 * 
 * Requires support for `FF_AUTOCENTER` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * @param   device      The device to configure
 * @param   autocenter  Autocenter strength, shall be a value in [0, 0xFFFF], select 0 to
 *                      disable (you can also use `libgamepad_disable_force_feedback_autocenter`)
 * @return              0 on success, -1 on failure
 */
inline int
libgamepad_set_force_feedback_autocenter(struct libgamepad_device *device, uint16_t autocenter)
{
	struct input_event message;
	message.type = EV_FF;
	message.code = FF_AUTOCENTER;
	message.value = (int16_t)autocenter;
	return write(device->fd, &message, sizeof(message)) < 0 ? -1 : 0;
}

/**
 * Disable the autocenter force feedback on a device
 * 
 * Requires support for `FF_AUTOCENTER` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * @param   device  device to configure
 * @return          0 on success, -1 on failure
 */
inline int
libgamepad_disable_force_feedback_autocenter(struct libgamepad_device *device)
{
	struct input_event message;
	message.type = EV_FF;
	message.code = FF_AUTOCENTER;
	message.value = 0;
	return write(device->fd, &message, sizeof(message)) < 0 ? -1 : 0;
}

/**
 * Construct a rumble force-feedback effect
 * 
 * Requires support for `FF_RUMBLE` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details:
 *                    - .strong_magnitude  Heavy motor strength, unsigned 16-bit integer
 *                    - .weak_magnitude    Light motor strength, unsigned 16-bit integer
 */
inline void
libgamepad_construct_rumble_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                  double direction, uint16_t length, const struct ff_rumble_effect *effect)
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_RUMBLE);
	memcpy(&effectp->u.rumble, effect, sizeof(effectp->u.rumble));
}

/**
 * Construct a constant force-feedback effect
 * 
 * Requires support for `FF_CONSTANT` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details:
 *                    - .level                     Strength, signed 16-bit integer
 *                    - .envelope.attack_strength  Strength at beginning, unsigned 16-bit integer
 *                    - .envelope.fade_strength    Strength at end, unsigned 16-bit integer
 *                    - .envelope.attack_length    The number of milliseconds the strength shall
 *                                                 transition from `.envelope.attack_strength`
 *                                                 to `.level`, unsigned 16-bit integer
 *                    - .envelope.fade_length      The number of milliseconds the strength shall
 *                                                 transition to `.envelope.fade_strength`
 *                                                 from `.level`, unsigned 16-bit integer
 */
inline void
libgamepad_construct_constant_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                    double direction, uint16_t length, const struct ff_constant_effect *effect)
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_CONSTANT);
	memcpy(&effectp->u.constant, effect, sizeof(effectp->u.constant));
}

/**
 * Construct a ramp force-feedback effect
 * 
 * Requires support for `FF_RAMP` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details:
 *                    - .start_level               Strength at beginning, signed 16-bit integer
 *                    - .end_level                 Strength at end, signed 16-bit integer
 *                    - .envelope.attack_strength  Strength at beginning, unsigned 16-bit integer
 *                    - .envelope.fade_strength    Strength at end, unsigned 16-bit integer
 *                    - .envelope.attack_length    The number of milliseconds the strength shall
 *                                                 transition from `.envelope.attack_strength`,
 *                                                 unsigned 16-bit integer
 *                    - .envelope.fade_length      The number of milliseconds the strength shall
 *                                                 transition to `.envelope.fade_strength`,
 *                                                 unsigned 16-bit integer
 */
inline void
libgamepad_construct_ramp_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                double direction, uint16_t length, const struct ff_ramp_effect *effect)
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_RUMBLE);
	memcpy(&effectp->u.ramp, effect, sizeof(effectp->u.ramp));
}

/**
 * Construct a periodic force-feedback effect
 * 
 * Requires support for `FF_PERIODIC` and the selected waveform
 * (check with `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details:
 *                    - .waveform                  `FF_SQUARE`, `FF_TRIANGLE`, `FF_SINE`, `FF_SAW_UP`,
 *                                                 `FF_SAW_DOWN`, or `FF_CUSTOM`
 *                    - .period                    The period of the wave, in milliseconds (unsigned 16-bit integer)
 *                    - .magnitude                 The peak value, signed 16-bit integer
 *                    - .offset                    The rough mean value, signed 16-bit integer
 *                    - .phase                     Horiztonal wave-shift, in milliseconds (unsigned 16-bit integer)
 *                    - .envelope.attack_strength  Strength at beginning, unsigned 16-bit integer
 *                    - .envelope.fade_strength    Strength at end, unsigned 16-bit integer
 *                    - .envelope.attack_length    The number of milliseconds the strength shall
 *                                                 transition from `.envelope.attack_strength`,
 *                                                 unsigned 16-bit integer
 *                    - .envelope.fade_length      The number of milliseconds the strength shall
 *                                                 transition to `.envelope.fade_strength`,
 *                                                 unsigned 16-bit integer
 *                    - .custom_len                Set to zero unless you are using (`FF_CUSTOM`)
 *                    - .custom_data               Set to `NULL` unless you are using (`FF_CUSTOM`)
 */
inline void
libgamepad_construct_periodic_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                   double direction, uint16_t length, const struct ff_periodic_effect *effect)
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_PERIODIC);
	memcpy(&effectp->u.periodic, effect, sizeof(effectp->u.periodic));
}

/**
 * Construct a spring force-feedback effect
 * 
 * Requires support for `FF_SPRING` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details (one of each axis):
 *                    - .right_saturation  Maximum level at end of axis, unsigned 16-bit integer
 *                    - .left_saturation   Maximum level at beginning of axis, unsigned 16-bit integer
 *                    - .right_coeff       Growth coefficient after the dead zone, signed 16-bit integer
 *                    - .left_coeff        Growth coefficient before the dead zone, signed 16-bit integer
 *                    - .deadband          Size of the dead zone
 *                    - .center            The position of the center of the dead zone
 */
inline void
libgamepad_construct_spring_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                  double direction, uint16_t length, const struct ff_condition_effect effect[2])
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_SPRING);
	memcpy(effectp->u.condition, effect, sizeof(effectp->u.condition));
}

/**
 * Construct a friction force-feedback effect
 * 
 * Requires support for `FF_FRICTION` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details (one of each axis):
 *                    - .right_saturation  Maximum level at end of axis, unsigned 16-bit integer
 *                    - .left_saturation   Maximum level at beginning of axis, unsigned 16-bit integer
 *                    - .right_coeff       Growth coefficient after the dead zone, signed 16-bit integer
 *                    - .left_coeff        Growth coefficient before the dead zone, signed 16-bit integer
 *                    - .deadband          Size of the dead zone
 *                    - .center            The position of the center of the dead zone
 */
inline void
libgamepad_construct_friction_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                    double direction, uint16_t length, const struct ff_condition_effect effect[2])
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_FRICTION);
	memcpy(effectp->u.condition, effect, sizeof(effectp->u.condition));
}

/**
 * Construct a damper force-feedback effect
 * 
 * Requires support for `FF_DAMPER` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details (one of each axis):
 *                    - .right_saturation  Maximum level at end of axis, unsigned 16-bit integer
 *                    - .left_saturation   Maximum level at beginning of axis, unsigned 16-bit integer
 *                    - .right_coeff       Growth coefficient after the dead zone, signed 16-bit integer
 *                    - .left_coeff        Growth coefficient before the dead zone, signed 16-bit integer
 *                    - .deadband          Size of the dead zone
 *                    - .center            The position of the center of the dead zone
 */
inline void
libgamepad_construct_damper_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                  double direction, uint16_t length, const struct ff_condition_effect effect[2])
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_DAMPER);
	memcpy(effectp->u.condition, effect, sizeof(effectp->u.condition));
}

/**
 * Construct a inertia force-feedback effect
 * 
 * Requires support for `FF_INERTIA` (check with
 * `libgamepad_is_force_feedback_effect_supported`)
 * 
 * This function will set the following values to
 * zero if `from` is `NULL`, see <linux/input.h>
 * for more details:
 * -  effectp->trigger.button
 * -  effectp->trigger.interval
 * -  effectp->replay.delay
 * 
 * @param  effectp    Output parameter for the effect
 * @param  from       Effect to reconfigure, `NULL` to create a new effect
 * @param  direction  The direction of the force feedback (if directional), where
 *                    values are measure clockwise and both 0 and 1 are upwards
 * @param  length     The number of milliseconds the effect is played
 * @param  effect     Effect specific details (one of each axis):
 *                    - .right_saturation  Maximum level at end of axis, unsigned 16-bit integer
 *                    - .left_saturation   Maximum level at beginning of axis, unsigned 16-bit integer
 *                    - .right_coeff       Growth coefficient after the dead zone, signed 16-bit integer
 *                    - .left_coeff        Growth coefficient before the dead zone, signed 16-bit integer
 *                    - .deadband          Size of the dead zone
 *                    - .center            The position of the center of the dead zone
 */
inline void
libgamepad_construct_inertia_force_feedback_effect(struct ff_effect *effectp, const struct ff_effect *from,
                                                   double direction, uint16_t length, const struct ff_condition_effect effect[2])
{
	libgamepad_construct_force_feedback_effect__(effectp, from, direction, length, FF_INERTIA);
	memcpy(effectp->u.condition, effect, sizeof(effectp->u.condition));
}


#endif