Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
PeripheralUtils.h
1/*
2 * Copyright (C) 2014-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../../AddonBase.h"
12#include "../../c-api/addon-instance/peripheral.h"
13
14#ifdef __cplusplus
15
16#include <array> // Requires c++11
17#include <cstring>
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
22
23#define PERIPHERAL_SAFE_DELETE(x) \
24 do \
25 { \
26 delete (x); \
27 (x) = NULL; \
28 } while (0)
29#define PERIPHERAL_SAFE_DELETE_ARRAY(x) \
30 do \
31 { \
32 delete[] (x); \
33 (x) = NULL; \
34 } while (0)
35
36namespace kodi
37{
38namespace addon
39{
40
41class CInstancePeripheral;
42
46template<class THE_CLASS, typename THE_STRUCT>
48{
49public:
50 static void ToStructs(const std::vector<THE_CLASS>& vecObjects, THE_STRUCT** pStructs)
51 {
52 if (!pStructs)
53 return;
54
55 if (vecObjects.empty())
56 {
57 *pStructs = NULL;
58 }
59 else
60 {
61 (*pStructs) = new THE_STRUCT[vecObjects.size()];
62 for (unsigned int i = 0; i < vecObjects.size(); i++)
63 vecObjects.at(i).ToStruct((*pStructs)[i]);
64 }
65 }
66
67 static void ToStructs(const std::vector<THE_CLASS*>& vecObjects, THE_STRUCT** pStructs)
68 {
69 if (!pStructs)
70 return;
71
72 if (vecObjects.empty())
73 {
74 *pStructs = NULL;
75 }
76 else
77 {
78 *pStructs = new THE_STRUCT[vecObjects.size()];
79 for (unsigned int i = 0; i < vecObjects.size(); i++)
80 vecObjects.at(i)->ToStruct((*pStructs)[i]);
81 }
82 }
83
84 static void ToStructs(const std::vector<std::shared_ptr<THE_CLASS>>& vecObjects,
85 THE_STRUCT** pStructs)
86 {
87 if (!pStructs)
88 return;
89
90 if (vecObjects.empty())
91 {
92 *pStructs = NULL;
93 }
94 else
95 {
96 *pStructs = new THE_STRUCT[vecObjects.size()];
97 for (unsigned int i = 0; i < vecObjects.size(); i++)
98 vecObjects.at(i)->ToStruct((*pStructs)[i]);
99 }
100 }
101
102 static void FreeStructs(unsigned int structCount, THE_STRUCT* structs)
103 {
104 if (structs)
105 {
106 for (unsigned int i = 0; i < structCount; i++)
107 THE_CLASS::FreeStruct(structs[i]);
108 }
109 PERIPHERAL_SAFE_DELETE_ARRAY(structs);
110 }
111};
112
113//==============================================================================
132class PeripheralCapabilities : public CStructHdl<PeripheralCapabilities, PERIPHERAL_CAPABILITIES>
133{
135 friend class CInstancePeripheral;
138public:
141 {
142 m_cStructure->provides_joysticks = false;
143 m_cStructure->provides_joystick_rumble = false;
144 m_cStructure->provides_joystick_power_off = false;
145 m_cStructure->provides_buttonmaps = false;
146 }
147
162
165
167 void SetProvidesJoysticks(bool providesJoysticks)
168 {
169 m_cStructure->provides_joysticks = providesJoysticks;
170 }
171
173 bool GetProvidesJoysticks() const { return m_cStructure->provides_joysticks; }
174
176 void SetProvidesJoystickRumble(bool providesJoystickRumble)
177 {
178 m_cStructure->provides_joystick_rumble = providesJoystickRumble;
179 }
180
182 bool GetProvidesJoystickRumble() const { return m_cStructure->provides_joystick_rumble; }
183
185 void SetProvidesJoystickPowerOff(bool providesJoystickPowerOff)
186 {
187 m_cStructure->provides_joystick_power_off = providesJoystickPowerOff;
188 }
189
191 bool GetProvidesJoystickPowerOff() const { return m_cStructure->provides_joystick_power_off; }
192
194 void SetProvidesButtonmaps(bool providesButtonmaps)
195 {
196 m_cStructure->provides_buttonmaps = providesButtonmaps;
197 }
198
200 bool GetProvidesButtonmaps() const { return m_cStructure->provides_buttonmaps; }
201
203
204private:
206 PeripheralCapabilities(PERIPHERAL_CAPABILITIES* data) : CStructHdl(data) {}
207};
209//------------------------------------------------------------------------------
210
211//==============================================================================
225{
226public:
244
247
253 Peripheral(PERIPHERAL_TYPE type = PERIPHERAL_TYPE_UNKNOWN, const std::string& strName = "")
254 : m_type(type),
255 m_strName(strName)
256 {
257 }
258
260 virtual ~Peripheral(void) = default;
261
266 bool operator==(const Peripheral& rhs) const
267 {
268 // clang-format off
269 return m_type == rhs.m_type &&
270 m_strName == rhs.m_strName &&
271 m_vendorId == rhs.m_vendorId &&
272 m_productId == rhs.m_productId;
273 // clang-format on
274 }
275
279 PERIPHERAL_TYPE Type(void) const { return m_type; }
280
284 const std::string& Name(void) const { return m_strName; }
285
289 uint16_t VendorID(void) const { return m_vendorId; }
290
294 uint16_t ProductID(void) const { return m_productId; }
295
299 unsigned int Index(void) const { return m_index; }
300
306 bool IsVidPidKnown(void) const { return m_vendorId != 0 || m_productId != 0; }
307
311 void SetType(PERIPHERAL_TYPE type) { m_type = type; }
312
316 void SetName(const std::string& strName) { m_strName = strName; }
317
321 void SetVendorID(uint16_t vendorId) { m_vendorId = vendorId; }
322
326 void SetProductID(uint16_t productId) { m_productId = productId; }
327
331 void SetIndex(unsigned int index) { m_index = index; }
332
334
335 explicit Peripheral(const PERIPHERAL_INFO& info)
336 : m_type(info.type),
337 m_strName(info.name ? info.name : ""),
338 m_vendorId(info.vendor_id),
339 m_productId(info.product_id),
340 m_index(info.index)
341 {
342 }
343
344 void ToStruct(PERIPHERAL_INFO& info) const
345 {
346 info.type = m_type;
347 info.name = new char[m_strName.size() + 1];
348 info.vendor_id = m_vendorId;
349 info.product_id = m_productId;
350 info.index = m_index;
351
352 std::strcpy(info.name, m_strName.c_str());
353 }
354
355 static void FreeStruct(PERIPHERAL_INFO& info) { PERIPHERAL_SAFE_DELETE_ARRAY(info.name); }
356
357private:
358 PERIPHERAL_TYPE m_type;
359 std::string m_strName;
360 uint16_t m_vendorId = 0;
361 uint16_t m_productId = 0;
362 unsigned int m_index = 0;
363};
365//------------------------------------------------------------------------------
366
367typedef PeripheralVector<Peripheral, PERIPHERAL_INFO> Peripherals;
368
369//==============================================================================
384{
385public:
402
405
407 PeripheralEvent() = default;
408
414 PeripheralEvent(unsigned int peripheralIndex,
415 unsigned int buttonIndex,
418 m_peripheralIndex(peripheralIndex),
419 m_driverIndex(buttonIndex),
420 m_buttonState(state)
421 {
422 }
423
429 PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state)
431 m_peripheralIndex(peripheralIndex),
432 m_driverIndex(hatIndex),
433 m_hatState(state)
434 {
435 }
436
442 PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state)
444 m_peripheralIndex(peripheralIndex),
445 m_driverIndex(axisIndex),
446 m_axisState(state)
447 {
448 }
449
453 PERIPHERAL_EVENT_TYPE Type(void) const { return m_type; }
454
458 unsigned int PeripheralIndex(void) const { return m_peripheralIndex; }
459
463 unsigned int DriverIndex(void) const { return m_driverIndex; }
464
468 JOYSTICK_STATE_BUTTON ButtonState(void) const { return m_buttonState; }
469
473 JOYSTICK_STATE_HAT HatState(void) const { return m_hatState; }
474
478 JOYSTICK_STATE_AXIS AxisState(void) const { return m_axisState; }
479
483 JOYSTICK_STATE_MOTOR MotorState(void) const { return m_motorState; }
484
488 void SetType(PERIPHERAL_EVENT_TYPE type) { m_type = type; }
489
493 void SetPeripheralIndex(unsigned int index) { m_peripheralIndex = index; }
494
498 void SetDriverIndex(unsigned int index) { m_driverIndex = index; }
499
503 void SetButtonState(JOYSTICK_STATE_BUTTON state) { m_buttonState = state; }
504
508 void SetHatState(JOYSTICK_STATE_HAT state) { m_hatState = state; }
509
513 void SetAxisState(JOYSTICK_STATE_AXIS state) { m_axisState = state; }
514
518 void SetMotorState(JOYSTICK_STATE_MOTOR state) { m_motorState = state; }
519
521
522 explicit PeripheralEvent(const PERIPHERAL_EVENT& event)
523 : m_type(event.type),
524 m_peripheralIndex(event.peripheral_index),
525 m_driverIndex(event.driver_index),
526 m_buttonState(event.driver_button_state),
527 m_hatState(event.driver_hat_state),
528 m_axisState(event.driver_axis_state),
529 m_motorState(event.motor_state)
530 {
531 }
532
533 void ToStruct(PERIPHERAL_EVENT& event) const
534 {
535 event.type = m_type;
536 event.peripheral_index = m_peripheralIndex;
537 event.driver_index = m_driverIndex;
538 event.driver_button_state = m_buttonState;
539 event.driver_hat_state = m_hatState;
540 event.driver_axis_state = m_axisState;
541 event.motor_state = m_motorState;
542 }
543
544 static void FreeStruct(PERIPHERAL_EVENT& event) { (void)event; }
545
546private:
548 unsigned int m_peripheralIndex = 0;
549 unsigned int m_driverIndex = 0;
552 JOYSTICK_STATE_AXIS m_axisState = 0.0f;
553 JOYSTICK_STATE_MOTOR m_motorState = 0.0f;
554};
556//------------------------------------------------------------------------------
557
558typedef PeripheralVector<PeripheralEvent, PERIPHERAL_EVENT> PeripheralEvents;
559
560//==============================================================================
583class Joystick : public Peripheral
584{
585public:
611
614
619 Joystick(const std::string& provider = "", const std::string& strName = "")
621 m_provider(provider),
622 m_requestedPort(NO_PORT_REQUESTED)
623 {
624 }
625
629 Joystick(const Joystick& other) : Peripheral(other) { *this = other; }
630
633 ~Joystick(void) override = default;
634
639 {
640 if (this != &rhs)
641 {
642 Peripheral::operator=(rhs);
643
644 m_provider = rhs.m_provider;
645 m_requestedPort = rhs.m_requestedPort;
646 m_buttonCount = rhs.m_buttonCount;
647 m_hatCount = rhs.m_hatCount;
648 m_axisCount = rhs.m_axisCount;
649 m_motorCount = rhs.m_motorCount;
650 m_supportsPowerOff = rhs.m_supportsPowerOff;
651 }
652 return *this;
653 }
654
656 bool operator==(const Joystick& rhs) const
657 {
658 // clang-format off
659 return Peripheral::operator==(rhs) &&
660 m_provider == rhs.m_provider &&
661 m_requestedPort == rhs.m_requestedPort &&
662 m_buttonCount == rhs.m_buttonCount &&
663 m_hatCount == rhs.m_hatCount &&
664 m_axisCount == rhs.m_axisCount &&
665 m_motorCount == rhs.m_motorCount &&
666 m_supportsPowerOff == rhs.m_supportsPowerOff;
667 // clang-format on
668 }
669
673 const std::string& Provider(void) const { return m_provider; }
674
678 int RequestedPort(void) const { return m_requestedPort; }
679
683 unsigned int ButtonCount(void) const { return m_buttonCount; }
684
688 unsigned int HatCount(void) const { return m_hatCount; }
689
693 unsigned int AxisCount(void) const { return m_axisCount; }
694
698 unsigned int MotorCount(void) const { return m_motorCount; }
699
703 bool SupportsPowerOff(void) const { return m_supportsPowerOff; }
704
708 void SetProvider(const std::string& provider) { m_provider = provider; }
709
713 void SetRequestedPort(int requestedPort) { m_requestedPort = requestedPort; }
714
718 void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; }
719
723 void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; }
724
728 void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; }
729
733 void SetMotorCount(unsigned int motorCount) { m_motorCount = motorCount; }
734
738 void SetSupportsPowerOff(bool supportsPowerOff) { m_supportsPowerOff = supportsPowerOff; }
739
741
742 explicit Joystick(const JOYSTICK_INFO& info)
743 : Peripheral(info.peripheral),
744 m_provider(info.provider ? info.provider : ""),
745 m_requestedPort(info.requested_port),
746 m_buttonCount(info.button_count),
747 m_hatCount(info.hat_count),
748 m_axisCount(info.axis_count),
749 m_motorCount(info.motor_count),
750 m_supportsPowerOff(info.supports_poweroff)
751 {
752 }
753
754 void ToStruct(JOYSTICK_INFO& info) const
755 {
756 Peripheral::ToStruct(info.peripheral);
757
758 info.provider = new char[m_provider.size() + 1];
759 info.requested_port = m_requestedPort;
760 info.button_count = m_buttonCount;
761 info.hat_count = m_hatCount;
762 info.axis_count = m_axisCount;
763 info.motor_count = m_motorCount;
764 info.supports_poweroff = m_supportsPowerOff;
765
766 std::strcpy(info.provider, m_provider.c_str());
767 }
768
769 static void FreeStruct(JOYSTICK_INFO& info)
770 {
771 Peripheral::FreeStruct(info.peripheral);
772
773 PERIPHERAL_SAFE_DELETE_ARRAY(info.provider);
774 }
775
776private:
777 std::string m_provider;
778 int m_requestedPort;
779 unsigned int m_buttonCount = 0;
780 unsigned int m_hatCount = 0;
781 unsigned int m_axisCount = 0;
782 unsigned int m_motorCount = 0;
783 bool m_supportsPowerOff = false;
784};
786//------------------------------------------------------------------------------
787
788typedef PeripheralVector<Joystick, JOYSTICK_INFO> Joysticks;
789
790class JoystickFeature;
791
792//==============================================================================
836{
837protected:
841 DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE type, unsigned int driverIndex)
842 : m_type(type),
843 m_driverIndex(driverIndex)
844 {
845 }
846
847public:
850
852 DriverPrimitive(void) = default;
853
858 static DriverPrimitive CreateButton(unsigned int buttonIndex)
859 {
861 }
862
868 DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction)
870 m_driverIndex(hatIndex),
871 m_hatDirection(direction)
872 {
873 }
874
882 DriverPrimitive(unsigned int axisIndex,
883 int center,
885 unsigned int range)
887 m_driverIndex(axisIndex),
888 m_center(center),
889 m_semiAxisDirection(direction),
890 m_range(range)
891 {
892 }
893
898 static DriverPrimitive CreateMotor(unsigned int motorIndex)
899 {
901 }
902
906 DriverPrimitive(std::string keycode)
908 m_keycode(std::move(keycode))
909 {
910 }
911
917 {
919 static_cast<unsigned int>(buttonIndex));
920 }
921
928 m_relPointerDirection(direction)
929 {
930 }
931
935 JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const { return m_type; }
936
940 unsigned int DriverIndex(void) const { return m_driverIndex; }
941
945 JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const { return m_hatDirection; }
946
950 int Center(void) const { return m_center; }
951
955 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const { return m_semiAxisDirection; }
956
960 unsigned int Range(void) const { return m_range; }
961
965 const std::string& Keycode(void) const { return m_keycode; }
966
971 {
972 return static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex);
973 }
974
979 {
980 return m_relPointerDirection;
981 }
982
987 bool operator==(const DriverPrimitive& other) const
988 {
989 if (m_type == other.m_type)
990 {
991 switch (m_type)
992 {
994 {
995 return m_driverIndex == other.m_driverIndex;
996 }
998 {
999 return m_driverIndex == other.m_driverIndex && m_hatDirection == other.m_hatDirection;
1000 }
1002 {
1003 return m_driverIndex == other.m_driverIndex && m_center == other.m_center &&
1004 m_semiAxisDirection == other.m_semiAxisDirection && m_range == other.m_range;
1005 }
1007 {
1008 return m_keycode == other.m_keycode;
1009 }
1011 {
1012 return m_driverIndex == other.m_driverIndex;
1013 }
1015 {
1016 return m_driverIndex == other.m_driverIndex;
1017 }
1019 {
1020 return m_relPointerDirection == other.m_relPointerDirection;
1021 }
1022 default:
1023 break;
1024 }
1025 }
1026 return false;
1027 }
1028
1030
1031 explicit DriverPrimitive(const JOYSTICK_DRIVER_PRIMITIVE& primitive) : m_type(primitive.type)
1032 {
1033 switch (m_type)
1034 {
1036 {
1037 m_driverIndex = primitive.button.index;
1038 break;
1039 }
1041 {
1042 m_driverIndex = primitive.hat.index;
1043 m_hatDirection = primitive.hat.direction;
1044 break;
1045 }
1047 {
1048 m_driverIndex = primitive.semiaxis.index;
1049 m_center = primitive.semiaxis.center;
1050 m_semiAxisDirection = primitive.semiaxis.direction;
1051 m_range = primitive.semiaxis.range;
1052 break;
1053 }
1055 {
1056 m_driverIndex = primitive.motor.index;
1057 break;
1058 }
1060 {
1061 m_keycode = primitive.key.keycode;
1062 break;
1063 }
1065 {
1066 m_driverIndex = primitive.mouse.button;
1067 break;
1068 }
1070 {
1071 m_relPointerDirection = primitive.relpointer.direction;
1072 break;
1073 }
1074 default:
1075 break;
1076 }
1077 }
1078
1079 void ToStruct(JOYSTICK_DRIVER_PRIMITIVE& driver_primitive) const
1080 {
1081 driver_primitive.type = m_type;
1082 switch (m_type)
1083 {
1085 {
1086 driver_primitive.button.index = m_driverIndex;
1087 break;
1088 }
1090 {
1091 driver_primitive.hat.index = m_driverIndex;
1092 driver_primitive.hat.direction = m_hatDirection;
1093 break;
1094 }
1096 {
1097 driver_primitive.semiaxis.index = m_driverIndex;
1098 driver_primitive.semiaxis.center = m_center;
1099 driver_primitive.semiaxis.direction = m_semiAxisDirection;
1100 driver_primitive.semiaxis.range = m_range;
1101 break;
1102 }
1104 {
1105 driver_primitive.motor.index = m_driverIndex;
1106 break;
1107 }
1109 {
1110 const size_t size = sizeof(driver_primitive.key.keycode);
1111 std::strncpy(driver_primitive.key.keycode, m_keycode.c_str(), size - 1);
1112 driver_primitive.key.keycode[size - 1] = '\0';
1113 break;
1114 }
1116 {
1117 driver_primitive.mouse.button = static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex);
1118 break;
1119 }
1121 {
1122 driver_primitive.relpointer.direction = m_relPointerDirection;
1123 break;
1124 }
1125 default:
1126 break;
1127 }
1128 }
1129
1130 static void FreeStruct(JOYSTICK_DRIVER_PRIMITIVE& primitive) { (void)primitive; }
1131
1132private:
1134 unsigned int m_driverIndex = 0;
1136 int m_center = 0;
1138 unsigned int m_range = 1;
1139 std::string m_keycode;
1141};
1143//------------------------------------------------------------------------------
1144
1145typedef PeripheralVector<DriverPrimitive, JOYSTICK_DRIVER_PRIMITIVE> DriverPrimitives;
1146
1147//==============================================================================
1173{
1174public:
1177
1183 JoystickFeature(const std::string& name = "",
1185 : m_name(name),
1186 m_type(type),
1187 m_primitives{}
1188 {
1189 }
1190
1194 JoystickFeature(const JoystickFeature& other) { *this = other; }
1195
1200 {
1201 if (this != &rhs)
1202 {
1203 m_name = rhs.m_name;
1204 m_type = rhs.m_type;
1205 m_primitives = rhs.m_primitives;
1206 }
1207 return *this;
1208 }
1209
1214 bool operator==(const JoystickFeature& other) const
1215 {
1216 return m_name == other.m_name && m_type == other.m_type && m_primitives == other.m_primitives;
1217 }
1218
1222 const std::string& Name(void) const { return m_name; }
1223
1227 JOYSTICK_FEATURE_TYPE Type(void) const { return m_type; }
1228
1232 bool IsValid() const { return m_type != JOYSTICK_FEATURE_TYPE_UNKNOWN; }
1233
1237 void SetName(const std::string& name) { m_name = name; }
1238
1242 void SetType(JOYSTICK_FEATURE_TYPE type) { m_type = type; }
1243
1246
1252 {
1253 return m_primitives[which];
1254 }
1255
1261 {
1262 m_primitives[which] = primitive;
1263 }
1264
1268 std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() { return m_primitives; }
1269
1273 const std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() const
1274 {
1275 return m_primitives;
1276 }
1277
1279
1280 explicit JoystickFeature(const JOYSTICK_FEATURE& feature)
1281 : m_name(feature.name ? feature.name : ""),
1282 m_type(feature.type)
1283 {
1284 for (unsigned int i = 0; i < JOYSTICK_PRIMITIVE_MAX; i++)
1285 m_primitives[i] = DriverPrimitive(feature.primitives[i]);
1286 }
1287
1288 void ToStruct(JOYSTICK_FEATURE& feature) const
1289 {
1290 feature.name = new char[m_name.length() + 1];
1291 feature.type = m_type;
1292 for (unsigned int i = 0; i < JOYSTICK_PRIMITIVE_MAX; i++)
1293 m_primitives[i].ToStruct(feature.primitives[i]);
1294
1295 std::strcpy(feature.name, m_name.c_str());
1296 }
1297
1298 static void FreeStruct(JOYSTICK_FEATURE& feature) { PERIPHERAL_SAFE_DELETE_ARRAY(feature.name); }
1299
1300private:
1301 std::string m_name;
1302 JOYSTICK_FEATURE_TYPE m_type;
1303 std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX> m_primitives;
1304};
1306//------------------------------------------------------------------------------
1307
1308typedef PeripheralVector<JoystickFeature, JOYSTICK_FEATURE> JoystickFeatures;
1309
1310} /* namespace addon */
1311} /* namespace kodi */
1312
1313#endif /* __cplusplus */
Definition Peripheral.h:210
Definition AddonBase.h:206
Definition PeripheralUtils.h:1173
Definition PeripheralUtils.h:584
Definition PeripheralUtils.h:133
Definition PeripheralUtils.h:384
Definition PeripheralUtils.h:225
Definition PeripheralUtils.h:48
JOYSTICK_STATE_BUTTON
Definition peripheral.h:148
@ JOYSTICK_STATE_BUTTON_UNPRESSED
button is released
Definition peripheral.h:150
JOYSTICK_STATE_HAT
Definition peripheral.h:165
@ JOYSTICK_STATE_HAT_UNPRESSED
no directions are pressed
Definition peripheral.h:167
PERIPHERAL_EVENT_TYPE
Definition peripheral.h:122
@ PERIPHERAL_EVENT_TYPE_DRIVER_HAT
state changed for joystick driver hat
Definition peripheral.h:130
@ PERIPHERAL_EVENT_TYPE_NONE
unknown event
Definition peripheral.h:124
@ PERIPHERAL_EVENT_TYPE_DRIVER_AXIS
state changed for joystick driver axis
Definition peripheral.h:133
@ PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON
state changed for joystick driver button
Definition peripheral.h:127
float JOYSTICK_STATE_AXIS
Axis value in the closed interval [-1.0, 1.0].
Definition peripheral.h:204
float JOYSTICK_STATE_MOTOR
Motor value in the closed interval [0.0, 1.0].
Definition peripheral.h:210
DriverPrimitive(void)=default
Construct an invalid driver primitive.
bool operator==(const DriverPrimitive &other) const
Compare this with another class of this type.
Definition PeripheralUtils.h:987
static DriverPrimitive CreateMouseButton(JOYSTICK_DRIVER_MOUSE_INDEX buttonIndex)
Construct a driver primitive representing a mouse button.
Definition PeripheralUtils.h:916
DriverPrimitive(std::string keycode)
Construct a driver primitive representing a key on a keyboard.
Definition PeripheralUtils.h:906
static DriverPrimitive CreateButton(unsigned int buttonIndex)
Construct a driver primitive representing a joystick button.
Definition PeripheralUtils.h:858
DriverPrimitive(unsigned int axisIndex, int center, JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction, unsigned int range)
Construct a driver primitive representing the positive or negative half of an axis.
Definition PeripheralUtils.h:882
unsigned int Range(void) const
Get range.
Definition PeripheralUtils.h:960
JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const
Get hat direction.
Definition PeripheralUtils.h:945
DriverPrimitive(JOYSTICK_DRIVER_RELPOINTER_DIRECTION direction)
Construct a driver primitive representing one of the four direction in which a relative pointer can m...
Definition PeripheralUtils.h:926
int Center(void) const
Get center.
Definition PeripheralUtils.h:950
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const
Get semi axis direction.
Definition PeripheralUtils.h:955
JOYSTICK_DRIVER_RELPOINTER_DIRECTION RelPointerDirection(void) const
Get relative pointer direction.
Definition PeripheralUtils.h:978
static DriverPrimitive CreateMotor(unsigned int motorIndex)
Construct a driver primitive representing a motor.
Definition PeripheralUtils.h:898
JOYSTICK_DRIVER_MOUSE_INDEX MouseIndex(void) const
Get mouse index.
Definition PeripheralUtils.h:970
const std::string & Keycode(void) const
Get key code as string.
Definition PeripheralUtils.h:965
DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction)
Construct a driver primitive representing one of the four direction arrows on a dpad.
Definition PeripheralUtils.h:868
unsigned int DriverIndex(void) const
Get driver index.
Definition PeripheralUtils.h:940
JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const
Get type of primitive.
Definition PeripheralUtils.h:935
JOYSTICK_DRIVER_HAT_DIRECTION
Definition peripheral.h:310
@ JOYSTICK_DRIVER_HAT_UNKNOWN
Driver hat unknown.
Definition peripheral.h:312
JOYSTICK_DRIVER_MOUSE_INDEX
Definition peripheral.h:392
JOYSTICK_DRIVER_PRIMITIVE_TYPE
Definition peripheral.h:267
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR
Driver input primitive type motor.
Definition peripheral.h:281
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON
Driver input primitive type mouse button.
Definition peripheral.h:287
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN
Driver input primitive type unknown.
Definition peripheral.h:269
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION
Driver input primitive type relative pointer direction.
Definition peripheral.h:290
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION
Driver input primitive type hat direction.
Definition peripheral.h:275
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON
Driver input primitive type button.
Definition peripheral.h:272
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS
Driver input primitive type semiaxis.
Definition peripheral.h:278
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY
Driver input primitive type key.
Definition peripheral.h:284
JOYSTICK_DRIVER_RELPOINTER_DIRECTION
Definition peripheral.h:441
@ JOYSTICK_DRIVER_RELPOINTER_UNKNOWN
Relative pointer direction unknown.
Definition peripheral.h:443
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
Definition peripheral.h:345
@ JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN
unknown direction
Definition peripheral.h:350
JOYSTICK_FEATURE_PRIMITIVE
Definition peripheral.h:539
@ JOYSTICK_PRIMITIVE_MAX
Maximum number of primitives.
Definition peripheral.h:588
JOYSTICK_FEATURE_TYPE
Definition peripheral.h:497
@ JOYSTICK_FEATURE_TYPE_UNKNOWN
Unknown type.
Definition peripheral.h:499
std::array< DriverPrimitive, JOYSTICK_PRIMITIVE_MAX > & Primitives()
Get all primitives on this class.
Definition PeripheralUtils.h:1268
void SetType(JOYSTICK_FEATURE_TYPE type)
Set type of feature.
Definition PeripheralUtils.h:1242
void SetInvalid(void)
Set type as invalid.
Definition PeripheralUtils.h:1245
JoystickFeature & operator=(const JoystickFeature &rhs)
Copy data from another JoystickFeature class to here.
Definition PeripheralUtils.h:1199
const DriverPrimitive & Primitive(JOYSTICK_FEATURE_PRIMITIVE which) const
Get primitive of feature by wanted type.
Definition PeripheralUtils.h:1251
const std::string & Name(void) const
Get name of feature.
Definition PeripheralUtils.h:1222
JOYSTICK_FEATURE_TYPE Type(void) const
Get name of feature.
Definition PeripheralUtils.h:1227
void SetPrimitive(JOYSTICK_FEATURE_PRIMITIVE which, const DriverPrimitive &primitive)
Set primitive for feature by wanted type.
Definition PeripheralUtils.h:1260
void SetName(const std::string &name)
Set name of feature.
Definition PeripheralUtils.h:1237
const std::array< DriverPrimitive, JOYSTICK_PRIMITIVE_MAX > & Primitives() const
Get all primitives on this class (as constant).
Definition PeripheralUtils.h:1273
bool operator==(const JoystickFeature &other) const
Compare this with another class of this type.
Definition PeripheralUtils.h:1214
bool IsValid() const
Check this feature is valid.
Definition PeripheralUtils.h:1232
JoystickFeature(const std::string &name="", JOYSTICK_FEATURE_TYPE type=JOYSTICK_FEATURE_TYPE_UNKNOWN)
Class constructor.
Definition PeripheralUtils.h:1183
JoystickFeature(const JoystickFeature &other)
Class copy constructor.
Definition PeripheralUtils.h:1194
void SetMotorCount(unsigned int motorCount)
Get motor count.
Definition PeripheralUtils.h:733
const std::string & Provider(void) const
Get provider name.
Definition PeripheralUtils.h:673
Joystick & operator=(const Joystick &rhs)
Copy data from another Joystick class to here.
Definition PeripheralUtils.h:638
unsigned int ButtonCount(void) const
Get button count.
Definition PeripheralUtils.h:683
unsigned int HatCount(void) const
Get hat count.
Definition PeripheralUtils.h:688
Joystick(const Joystick &other)
Class copy constructor.
Definition PeripheralUtils.h:629
bool SupportsPowerOff(void) const
Get supports power off.
Definition PeripheralUtils.h:703
bool operator==(const Joystick &rhs) const
Comparison operator.
Definition PeripheralUtils.h:656
void SetButtonCount(unsigned int buttonCount)
Get button count.
Definition PeripheralUtils.h:718
int RequestedPort(void) const
Get requested port number.
Definition PeripheralUtils.h:678
void SetSupportsPowerOff(bool supportsPowerOff)
Get supports power off.
Definition PeripheralUtils.h:738
void SetProvider(const std::string &provider)
Set provider name.
Definition PeripheralUtils.h:708
void SetRequestedPort(int requestedPort)
Get requested port number.
Definition PeripheralUtils.h:713
Joystick(const std::string &provider="", const std::string &strName="")
Constructor.
Definition PeripheralUtils.h:619
unsigned int AxisCount(void) const
Get axis count.
Definition PeripheralUtils.h:693
void SetAxisCount(unsigned int axisCount)
Get axis count.
Definition PeripheralUtils.h:728
void SetHatCount(unsigned int hatCount)
Get hat count.
Definition PeripheralUtils.h:723
unsigned int MotorCount(void) const
Get motor count.
Definition PeripheralUtils.h:698
~Joystick(void) override=default
Destructor.
PERIPHERAL_TYPE
Definition peripheral.h:71
@ PERIPHERAL_TYPE_UNKNOWN
Type declared as unknown.
Definition peripheral.h:73
@ PERIPHERAL_TYPE_JOYSTICK
Type declared as joystick.
Definition peripheral.h:76
void SetType(PERIPHERAL_EVENT_TYPE type)
Set type of event.
Definition PeripheralUtils.h:488
JOYSTICK_STATE_HAT HatState(void) const
Get hat state.
Definition PeripheralUtils.h:473
void SetAxisState(JOYSTICK_STATE_AXIS state)
Set axis state.
Definition PeripheralUtils.h:513
JOYSTICK_STATE_MOTOR MotorState(void) const
Get motor state.
Definition PeripheralUtils.h:483
JOYSTICK_STATE_BUTTON ButtonState(void) const
Get button state.
Definition PeripheralUtils.h:468
PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state)
Constructor.
Definition PeripheralUtils.h:429
void SetDriverIndex(unsigned int index)
Set driver index.
Definition PeripheralUtils.h:498
PeripheralEvent()=default
Constructor.
unsigned int PeripheralIndex(void) const
Get peripheral index.
Definition PeripheralUtils.h:458
void SetPeripheralIndex(unsigned int index)
Set peripheral index.
Definition PeripheralUtils.h:493
void SetHatState(JOYSTICK_STATE_HAT state)
Set hat state.
Definition PeripheralUtils.h:508
JOYSTICK_STATE_AXIS AxisState(void) const
Get axis state.
Definition PeripheralUtils.h:478
PERIPHERAL_EVENT_TYPE Type(void) const
Get type of event.
Definition PeripheralUtils.h:453
void SetMotorState(JOYSTICK_STATE_MOTOR state)
Set motor state.
Definition PeripheralUtils.h:518
PeripheralEvent(unsigned int peripheralIndex, unsigned int buttonIndex, JOYSTICK_STATE_BUTTON state)
Constructor.
Definition PeripheralUtils.h:414
PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state)
Constructor.
Definition PeripheralUtils.h:442
void SetButtonState(JOYSTICK_STATE_BUTTON state)
Set button state.
Definition PeripheralUtils.h:503
unsigned int DriverIndex(void) const
Get driver index.
Definition PeripheralUtils.h:463
uint16_t VendorID(void) const
Get peripheral vendor id.
Definition PeripheralUtils.h:289
void SetName(const std::string &strName)
Set peripheral name.
Definition PeripheralUtils.h:316
uint16_t ProductID(void) const
Get peripheral product id.
Definition PeripheralUtils.h:294
void SetIndex(unsigned int index)
Set peripheral index.
Definition PeripheralUtils.h:331
const std::string & Name(void) const
Get peripheral name.
Definition PeripheralUtils.h:284
virtual ~Peripheral(void)=default
Destructor.
bool IsVidPidKnown(void) const
Check VID and PID are known.
Definition PeripheralUtils.h:306
void SetType(PERIPHERAL_TYPE type)
Set peripheral type.
Definition PeripheralUtils.h:311
Peripheral(PERIPHERAL_TYPE type=PERIPHERAL_TYPE_UNKNOWN, const std::string &strName="")
Constructor.
Definition PeripheralUtils.h:253
void SetProductID(uint16_t productId)
Set peripheral product identifier.
Definition PeripheralUtils.h:326
bool operator==(const Peripheral &rhs) const
Comparison operator.
Definition PeripheralUtils.h:266
unsigned int Index(void) const
Get peripheral index identifier.
Definition PeripheralUtils.h:299
PERIPHERAL_TYPE Type(void) const
Get peripheral type.
Definition PeripheralUtils.h:279
void SetVendorID(uint16_t vendorId)
Set peripheral vendor id.
Definition PeripheralUtils.h:321
void SetProvidesJoystickPowerOff(bool providesJoystickPowerOff)
Set true if the add-on provides power off about joystick.
Definition PeripheralUtils.h:185
bool GetProvidesJoysticks() const
To get with SetProvidesJoysticks changed values.
Definition PeripheralUtils.h:173
void SetProvidesButtonmaps(bool providesButtonmaps)
Set true if the add-on provides button maps.
Definition PeripheralUtils.h:194
bool GetProvidesButtonmaps() const
To get with SetProvidesButtonmaps changed values.
Definition PeripheralUtils.h:200
bool GetProvidesJoystickPowerOff() const
To get with SetProvidesJoystickPowerOff changed values.
Definition PeripheralUtils.h:191
bool GetProvidesJoystickRumble() const
To get with SetProvidesJoystickRumble changed values.
Definition PeripheralUtils.h:182
void SetProvidesJoysticks(bool providesJoysticks)
Set true if the add-on provides joysticks.
Definition PeripheralUtils.h:167
void SetProvidesJoystickRumble(bool providesJoystickRumble)
Set true if the add-on provides joystick rumble.
Definition PeripheralUtils.h:176
Driver primitive struct.
Definition peripheral.h:472
Mapping between higher-level controller feature and its driver primitives.
Definition peripheral.h:597
Info specific to joystick peripherals.
Definition peripheral.h:242
Peripheral add-on capabilities.
Definition peripheral.h:103
bool provides_joysticks
Definition peripheral.h:104
bool provides_buttonmaps
Definition peripheral.h:107
Event information.
Definition peripheral.h:217
Information shared between peripherals.
Definition peripheral.h:91
Definition PeripheralUtils.h:836
DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE type, unsigned int driverIndex)
Construct a driver primitive of the specified type.
Definition PeripheralUtils.h:841