Kodi Development 19.0
for Binary and Script based Add-Ons
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), m_strName(strName)
255 {
256 }
257
259 virtual ~Peripheral(void) = default;
260
264 PERIPHERAL_TYPE Type(void) const { return m_type; }
265
269 const std::string& Name(void) const { return m_strName; }
270
274 uint16_t VendorID(void) const { return m_vendorId; }
275
279 uint16_t ProductID(void) const { return m_productId; }
280
284 unsigned int Index(void) const { return m_index; }
285
291 bool IsVidPidKnown(void) const { return m_vendorId != 0 || m_productId != 0; }
292
296 void SetType(PERIPHERAL_TYPE type) { m_type = type; }
297
301 void SetName(const std::string& strName) { m_strName = strName; }
302
306 void SetVendorID(uint16_t vendorId) { m_vendorId = vendorId; }
307
311 void SetProductID(uint16_t productId) { m_productId = productId; }
312
316 void SetIndex(unsigned int index) { m_index = index; }
317
319
320 explicit Peripheral(const PERIPHERAL_INFO& info)
321 : m_type(info.type),
322 m_strName(info.name ? info.name : ""),
323 m_vendorId(info.vendor_id),
324 m_productId(info.product_id),
325 m_index(info.index)
326 {
327 }
328
329 void ToStruct(PERIPHERAL_INFO& info) const
330 {
331 info.type = m_type;
332 info.name = new char[m_strName.size() + 1];
333 info.vendor_id = m_vendorId;
334 info.product_id = m_productId;
335 info.index = m_index;
336
337 std::strcpy(info.name, m_strName.c_str());
338 }
339
340 static void FreeStruct(PERIPHERAL_INFO& info) { PERIPHERAL_SAFE_DELETE_ARRAY(info.name); }
341
342private:
343 PERIPHERAL_TYPE m_type;
344 std::string m_strName;
345 uint16_t m_vendorId = 0;
346 uint16_t m_productId = 0;
347 unsigned int m_index = 0;
348};
350//------------------------------------------------------------------------------
351
352typedef PeripheralVector<Peripheral, PERIPHERAL_INFO> Peripherals;
353
354//==============================================================================
369{
370public:
387
390
392 PeripheralEvent() = default;
393
399 PeripheralEvent(unsigned int peripheralIndex,
400 unsigned int buttonIndex,
403 m_peripheralIndex(peripheralIndex),
404 m_driverIndex(buttonIndex),
405 m_buttonState(state)
406 {
407 }
408
414 PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state)
416 m_peripheralIndex(peripheralIndex),
417 m_driverIndex(hatIndex),
418 m_hatState(state)
419 {
420 }
421
427 PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state)
429 m_peripheralIndex(peripheralIndex),
430 m_driverIndex(axisIndex),
431 m_axisState(state)
432 {
433 }
434
438 PERIPHERAL_EVENT_TYPE Type(void) const { return m_type; }
439
443 unsigned int PeripheralIndex(void) const { return m_peripheralIndex; }
444
448 unsigned int DriverIndex(void) const { return m_driverIndex; }
449
453 JOYSTICK_STATE_BUTTON ButtonState(void) const { return m_buttonState; }
454
458 JOYSTICK_STATE_HAT HatState(void) const { return m_hatState; }
459
463 JOYSTICK_STATE_AXIS AxisState(void) const { return m_axisState; }
464
468 JOYSTICK_STATE_MOTOR MotorState(void) const { return m_motorState; }
469
473 void SetType(PERIPHERAL_EVENT_TYPE type) { m_type = type; }
474
478 void SetPeripheralIndex(unsigned int index) { m_peripheralIndex = index; }
479
483 void SetDriverIndex(unsigned int index) { m_driverIndex = index; }
484
488 void SetButtonState(JOYSTICK_STATE_BUTTON state) { m_buttonState = state; }
489
493 void SetHatState(JOYSTICK_STATE_HAT state) { m_hatState = state; }
494
498 void SetAxisState(JOYSTICK_STATE_AXIS state) { m_axisState = state; }
499
503 void SetMotorState(JOYSTICK_STATE_MOTOR state) { m_motorState = state; }
504
506
507 explicit PeripheralEvent(const PERIPHERAL_EVENT& event)
508 : m_type(event.type),
509 m_peripheralIndex(event.peripheral_index),
510 m_driverIndex(event.driver_index),
511 m_buttonState(event.driver_button_state),
512 m_hatState(event.driver_hat_state),
513 m_axisState(event.driver_axis_state),
514 m_motorState(event.motor_state)
515 {
516 }
517
518 void ToStruct(PERIPHERAL_EVENT& event) const
519 {
520 event.type = m_type;
521 event.peripheral_index = m_peripheralIndex;
522 event.driver_index = m_driverIndex;
523 event.driver_button_state = m_buttonState;
524 event.driver_hat_state = m_hatState;
525 event.driver_axis_state = m_axisState;
526 event.motor_state = m_motorState;
527 }
528
529 static void FreeStruct(PERIPHERAL_EVENT& event) { (void)event; }
530
531private:
533 unsigned int m_peripheralIndex = 0;
534 unsigned int m_driverIndex = 0;
537 JOYSTICK_STATE_AXIS m_axisState = 0.0f;
538 JOYSTICK_STATE_MOTOR m_motorState = 0.0f;
539};
541//------------------------------------------------------------------------------
542
543typedef PeripheralVector<PeripheralEvent, PERIPHERAL_EVENT> PeripheralEvents;
544
545//==============================================================================
568class Joystick : public Peripheral
569{
570public:
596
599
604 Joystick(const std::string& provider = "", const std::string& strName = "")
606 m_provider(provider),
607 m_requestedPort(NO_PORT_REQUESTED)
608 {
609 }
610
614 Joystick(const Joystick& other) { *this = other; }
615
618 ~Joystick(void) override = default;
619
624 {
625 if (this != &rhs)
626 {
627 Peripheral::operator=(rhs);
628
629 m_provider = rhs.m_provider;
630 m_requestedPort = rhs.m_requestedPort;
631 m_buttonCount = rhs.m_buttonCount;
632 m_hatCount = rhs.m_hatCount;
633 m_axisCount = rhs.m_axisCount;
634 m_motorCount = rhs.m_motorCount;
635 m_supportsPowerOff = rhs.m_supportsPowerOff;
636 }
637 return *this;
638 }
639
643 const std::string& Provider(void) const { return m_provider; }
644
648 int RequestedPort(void) const { return m_requestedPort; }
649
653 unsigned int ButtonCount(void) const { return m_buttonCount; }
654
658 unsigned int HatCount(void) const { return m_hatCount; }
659
663 unsigned int AxisCount(void) const { return m_axisCount; }
664
668 unsigned int MotorCount(void) const { return m_motorCount; }
669
673 bool SupportsPowerOff(void) const { return m_supportsPowerOff; }
674
678 void SetProvider(const std::string& provider) { m_provider = provider; }
679
683 void SetRequestedPort(int requestedPort) { m_requestedPort = requestedPort; }
684
688 void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; }
689
693 void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; }
694
698 void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; }
699
703 void SetMotorCount(unsigned int motorCount) { m_motorCount = motorCount; }
704
708 void SetSupportsPowerOff(bool supportsPowerOff) { m_supportsPowerOff = supportsPowerOff; }
709
711
712 explicit Joystick(const JOYSTICK_INFO& info)
713 : Peripheral(info.peripheral),
714 m_provider(info.provider ? info.provider : ""),
715 m_requestedPort(info.requested_port),
716 m_buttonCount(info.button_count),
717 m_hatCount(info.hat_count),
718 m_axisCount(info.axis_count),
719 m_motorCount(info.motor_count),
720 m_supportsPowerOff(info.supports_poweroff)
721 {
722 }
723
724 void ToStruct(JOYSTICK_INFO& info) const
725 {
726 Peripheral::ToStruct(info.peripheral);
727
728 info.provider = new char[m_provider.size() + 1];
729 info.requested_port = m_requestedPort;
730 info.button_count = m_buttonCount;
731 info.hat_count = m_hatCount;
732 info.axis_count = m_axisCount;
733 info.motor_count = m_motorCount;
734 info.supports_poweroff = m_supportsPowerOff;
735
736 std::strcpy(info.provider, m_provider.c_str());
737 }
738
739 static void FreeStruct(JOYSTICK_INFO& info)
740 {
741 Peripheral::FreeStruct(info.peripheral);
742
743 PERIPHERAL_SAFE_DELETE_ARRAY(info.provider);
744 }
745
746private:
747 std::string m_provider;
748 int m_requestedPort;
749 unsigned int m_buttonCount = 0;
750 unsigned int m_hatCount = 0;
751 unsigned int m_axisCount = 0;
752 unsigned int m_motorCount = 0;
753 bool m_supportsPowerOff = false;
754};
756//------------------------------------------------------------------------------
757
758typedef PeripheralVector<Joystick, JOYSTICK_INFO> Joysticks;
759
760class JoystickFeature;
761
762//==============================================================================
806{
807protected:
811 DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE type, unsigned int driverIndex)
812 : m_type(type), m_driverIndex(driverIndex)
813 {
814 }
815
816public:
819
821 DriverPrimitive(void) = default;
822
827 static DriverPrimitive CreateButton(unsigned int buttonIndex)
828 {
830 }
831
837 DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction)
839 m_driverIndex(hatIndex),
840 m_hatDirection(direction)
841 {
842 }
843
851 DriverPrimitive(unsigned int axisIndex,
852 int center,
854 unsigned int range)
856 m_driverIndex(axisIndex),
857 m_center(center),
858 m_semiAxisDirection(direction),
859 m_range(range)
860 {
861 }
862
867 static DriverPrimitive CreateMotor(unsigned int motorIndex)
868 {
870 }
871
875 DriverPrimitive(std::string keycode)
876 : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY), m_keycode(std::move(keycode))
877 {
878 }
879
885 {
887 static_cast<unsigned int>(buttonIndex));
888 }
889
895 : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION), m_relPointerDirection(direction)
896 {
897 }
898
902 JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const { return m_type; }
903
907 unsigned int DriverIndex(void) const { return m_driverIndex; }
908
912 JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const { return m_hatDirection; }
913
917 int Center(void) const { return m_center; }
918
922 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const { return m_semiAxisDirection; }
923
927 unsigned int Range(void) const { return m_range; }
928
932 const std::string& Keycode(void) const { return m_keycode; }
933
938 {
939 return static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex);
940 }
941
946 {
947 return m_relPointerDirection;
948 }
949
954 bool operator==(const DriverPrimitive& other) const
955 {
956 if (m_type == other.m_type)
957 {
958 switch (m_type)
959 {
961 {
962 return m_driverIndex == other.m_driverIndex;
963 }
965 {
966 return m_driverIndex == other.m_driverIndex && m_hatDirection == other.m_hatDirection;
967 }
969 {
970 return m_driverIndex == other.m_driverIndex && m_center == other.m_center &&
971 m_semiAxisDirection == other.m_semiAxisDirection && m_range == other.m_range;
972 }
974 {
975 return m_keycode == other.m_keycode;
976 }
978 {
979 return m_driverIndex == other.m_driverIndex;
980 }
982 {
983 return m_driverIndex == other.m_driverIndex;
984 }
986 {
987 return m_relPointerDirection == other.m_relPointerDirection;
988 }
989 default:
990 break;
991 }
992 }
993 return false;
994 }
995
997
998 explicit DriverPrimitive(const JOYSTICK_DRIVER_PRIMITIVE& primitive) : m_type(primitive.type)
999 {
1000 switch (m_type)
1001 {
1003 {
1004 m_driverIndex = primitive.button.index;
1005 break;
1006 }
1008 {
1009 m_driverIndex = primitive.hat.index;
1010 m_hatDirection = primitive.hat.direction;
1011 break;
1012 }
1014 {
1015 m_driverIndex = primitive.semiaxis.index;
1016 m_center = primitive.semiaxis.center;
1017 m_semiAxisDirection = primitive.semiaxis.direction;
1018 m_range = primitive.semiaxis.range;
1019 break;
1020 }
1022 {
1023 m_driverIndex = primitive.motor.index;
1024 break;
1025 }
1027 {
1028 m_keycode = primitive.key.keycode;
1029 break;
1030 }
1032 {
1033 m_driverIndex = primitive.mouse.button;
1034 break;
1035 }
1037 {
1038 m_relPointerDirection = primitive.relpointer.direction;
1039 break;
1040 }
1041 default:
1042 break;
1043 }
1044 }
1045
1046 void ToStruct(JOYSTICK_DRIVER_PRIMITIVE& driver_primitive) const
1047 {
1048 driver_primitive.type = m_type;
1049 switch (m_type)
1050 {
1052 {
1053 driver_primitive.button.index = m_driverIndex;
1054 break;
1055 }
1057 {
1058 driver_primitive.hat.index = m_driverIndex;
1059 driver_primitive.hat.direction = m_hatDirection;
1060 break;
1061 }
1063 {
1064 driver_primitive.semiaxis.index = m_driverIndex;
1065 driver_primitive.semiaxis.center = m_center;
1066 driver_primitive.semiaxis.direction = m_semiAxisDirection;
1067 driver_primitive.semiaxis.range = m_range;
1068 break;
1069 }
1071 {
1072 driver_primitive.motor.index = m_driverIndex;
1073 break;
1074 }
1076 {
1077 const size_t size = sizeof(driver_primitive.key.keycode);
1078 std::strncpy(driver_primitive.key.keycode, m_keycode.c_str(), size - 1);
1079 driver_primitive.key.keycode[size - 1] = '\0';
1080 break;
1081 }
1083 {
1084 driver_primitive.mouse.button = static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex);
1085 break;
1086 }
1088 {
1089 driver_primitive.relpointer.direction = m_relPointerDirection;
1090 break;
1091 }
1092 default:
1093 break;
1094 }
1095 }
1096
1097 static void FreeStruct(JOYSTICK_DRIVER_PRIMITIVE& primitive) { (void)primitive; }
1098
1099private:
1101 unsigned int m_driverIndex = 0;
1103 int m_center = 0;
1105 unsigned int m_range = 1;
1106 std::string m_keycode;
1108};
1110//------------------------------------------------------------------------------
1111
1112typedef PeripheralVector<DriverPrimitive, JOYSTICK_DRIVER_PRIMITIVE> DriverPrimitives;
1113
1114//==============================================================================
1140{
1141public:
1144
1150 JoystickFeature(const std::string& name = "",
1152 : m_name(name), m_type(type), m_primitives{}
1153 {
1154 }
1155
1159 JoystickFeature(const JoystickFeature& other) { *this = other; }
1160
1165 {
1166 if (this != &rhs)
1167 {
1168 m_name = rhs.m_name;
1169 m_type = rhs.m_type;
1170 m_primitives = rhs.m_primitives;
1171 }
1172 return *this;
1173 }
1174
1179 bool operator==(const JoystickFeature& other) const
1180 {
1181 return m_name == other.m_name && m_type == other.m_type && m_primitives == other.m_primitives;
1182 }
1183
1187 const std::string& Name(void) const { return m_name; }
1188
1192 JOYSTICK_FEATURE_TYPE Type(void) const { return m_type; }
1193
1197 bool IsValid() const { return m_type != JOYSTICK_FEATURE_TYPE_UNKNOWN; }
1198
1202 void SetName(const std::string& name) { m_name = name; }
1203
1207 void SetType(JOYSTICK_FEATURE_TYPE type) { m_type = type; }
1208
1211
1217 {
1218 return m_primitives[which];
1219 }
1220
1226 {
1227 m_primitives[which] = primitive;
1228 }
1229
1233 std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() { return m_primitives; }
1234
1238 const std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() const
1239 {
1240 return m_primitives;
1241 }
1242
1244
1245 explicit JoystickFeature(const JOYSTICK_FEATURE& feature)
1246 : m_name(feature.name ? feature.name : ""), m_type(feature.type)
1247 {
1248 for (unsigned int i = 0; i < JOYSTICK_PRIMITIVE_MAX; i++)
1249 m_primitives[i] = DriverPrimitive(feature.primitives[i]);
1250 }
1251
1252 void ToStruct(JOYSTICK_FEATURE& feature) const
1253 {
1254 feature.name = new char[m_name.length() + 1];
1255 feature.type = m_type;
1256 for (unsigned int i = 0; i < JOYSTICK_PRIMITIVE_MAX; i++)
1257 m_primitives[i].ToStruct(feature.primitives[i]);
1258
1259 std::strcpy(feature.name, m_name.c_str());
1260 }
1261
1262 static void FreeStruct(JOYSTICK_FEATURE& feature) { PERIPHERAL_SAFE_DELETE_ARRAY(feature.name); }
1263
1264private:
1265 std::string m_name;
1266 JOYSTICK_FEATURE_TYPE m_type;
1267 std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX> m_primitives;
1268};
1270//------------------------------------------------------------------------------
1271
1272typedef PeripheralVector<JoystickFeature, JOYSTICK_FEATURE> JoystickFeatures;
1273
1274} /* namespace addon */
1275} /* namespace kodi */
1276
1277#endif /* __cplusplus */
Definition: Peripheral.h:216
Definition: AddonBase.h:250
Definition: PeripheralUtils.h:1140
Definition: PeripheralUtils.h:569
Definition: PeripheralUtils.h:133
Definition: PeripheralUtils.h:369
Definition: PeripheralUtils.h:225
Definition: PeripheralUtils.h:48
JOYSTICK_STATE_BUTTON
Definition: peripheral.h:145
@ JOYSTICK_STATE_BUTTON_UNPRESSED
button is released
Definition: peripheral.h:147
JOYSTICK_STATE_HAT
Definition: peripheral.h:162
@ JOYSTICK_STATE_HAT_UNPRESSED
no directions are pressed
Definition: peripheral.h:164
PERIPHERAL_EVENT_TYPE
Definition: peripheral.h:119
@ PERIPHERAL_EVENT_TYPE_DRIVER_HAT
state changed for joystick driver hat
Definition: peripheral.h:127
@ PERIPHERAL_EVENT_TYPE_NONE
unknown event
Definition: peripheral.h:121
@ PERIPHERAL_EVENT_TYPE_DRIVER_AXIS
state changed for joystick driver axis
Definition: peripheral.h:130
@ PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON
state changed for joystick driver button
Definition: peripheral.h:124
float JOYSTICK_STATE_AXIS
Axis value in the closed interval [-1.0, 1.0].
Definition: peripheral.h:201
float JOYSTICK_STATE_MOTOR
Motor value in the closed interval [0.0, 1.0].
Definition: peripheral.h:207
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:954
static DriverPrimitive CreateMouseButton(JOYSTICK_DRIVER_MOUSE_INDEX buttonIndex)
Construct a driver primitive representing a mouse button.
Definition: PeripheralUtils.h:884
DriverPrimitive(std::string keycode)
Construct a driver primitive representing a key on a keyboard.
Definition: PeripheralUtils.h:875
static DriverPrimitive CreateButton(unsigned int buttonIndex)
Construct a driver primitive representing a joystick button.
Definition: PeripheralUtils.h:827
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:851
unsigned int Range(void) const
Get range.
Definition: PeripheralUtils.h:927
JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const
Get hat direction.
Definition: PeripheralUtils.h:912
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:894
int Center(void) const
Get center.
Definition: PeripheralUtils.h:917
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const
Get semi axis direction.
Definition: PeripheralUtils.h:922
JOYSTICK_DRIVER_RELPOINTER_DIRECTION RelPointerDirection(void) const
Get relative pointer direction.
Definition: PeripheralUtils.h:945
static DriverPrimitive CreateMotor(unsigned int motorIndex)
Construct a driver primitive representing a motor.
Definition: PeripheralUtils.h:867
JOYSTICK_DRIVER_MOUSE_INDEX MouseIndex(void) const
Get mouse index.
Definition: PeripheralUtils.h:937
const std::string & Keycode(void) const
Get key code as string.
Definition: PeripheralUtils.h:932
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:837
unsigned int DriverIndex(void) const
Get driver index.
Definition: PeripheralUtils.h:907
JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const
Get type of primitive.
Definition: PeripheralUtils.h:902
JOYSTICK_DRIVER_HAT_DIRECTION
Definition: peripheral.h:307
@ JOYSTICK_DRIVER_HAT_UNKNOWN
Driver hat unknown.
Definition: peripheral.h:309
JOYSTICK_DRIVER_MOUSE_INDEX
Definition: peripheral.h:389
JOYSTICK_DRIVER_PRIMITIVE_TYPE
Definition: peripheral.h:264
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR
Driver input primitive type motor.
Definition: peripheral.h:278
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON
Driver input primitive type mouse button.
Definition: peripheral.h:284
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN
Driver input primitive type unknown.
Definition: peripheral.h:266
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION
Driver input primitive type relative pointer direction.
Definition: peripheral.h:287
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION
Driver input primitive type hat direction.
Definition: peripheral.h:272
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON
Driver input primitive type button.
Definition: peripheral.h:269
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS
Driver input primitive type semiaxis.
Definition: peripheral.h:275
@ JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY
Driver input primitive type key.
Definition: peripheral.h:281
JOYSTICK_DRIVER_RELPOINTER_DIRECTION
Definition: peripheral.h:438
@ JOYSTICK_DRIVER_RELPOINTER_UNKNOWN
Relative pointer direction unknown.
Definition: peripheral.h:440
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
Definition: peripheral.h:342
@ JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN
unknown direction
Definition: peripheral.h:347
JOYSTICK_FEATURE_PRIMITIVE
Definition: peripheral.h:536
@ JOYSTICK_PRIMITIVE_MAX
Maximum number of primitives.
Definition: peripheral.h:585
JOYSTICK_FEATURE_TYPE
Definition: peripheral.h:494
@ JOYSTICK_FEATURE_TYPE_UNKNOWN
Unknown type.
Definition: peripheral.h:496
std::array< DriverPrimitive, JOYSTICK_PRIMITIVE_MAX > & Primitives()
Get all primitives on this class.
Definition: PeripheralUtils.h:1233
void SetType(JOYSTICK_FEATURE_TYPE type)
Set type of feature.
Definition: PeripheralUtils.h:1207
void SetInvalid(void)
Set type as invalid.
Definition: PeripheralUtils.h:1210
JoystickFeature & operator=(const JoystickFeature &rhs)
Copy data from another JoystickFeature class to here.
Definition: PeripheralUtils.h:1164
const DriverPrimitive & Primitive(JOYSTICK_FEATURE_PRIMITIVE which) const
Get primitive of feature by wanted type.
Definition: PeripheralUtils.h:1216
const std::string & Name(void) const
Get name of feature.
Definition: PeripheralUtils.h:1187
JOYSTICK_FEATURE_TYPE Type(void) const
Get name of feature.
Definition: PeripheralUtils.h:1192
void SetPrimitive(JOYSTICK_FEATURE_PRIMITIVE which, const DriverPrimitive &primitive)
Set primitive for feature by wanted type.
Definition: PeripheralUtils.h:1225
void SetName(const std::string &name)
Set name of feature.
Definition: PeripheralUtils.h:1202
const std::array< DriverPrimitive, JOYSTICK_PRIMITIVE_MAX > & Primitives() const
Get all primitives on this class (as constant).
Definition: PeripheralUtils.h:1238
bool operator==(const JoystickFeature &other) const
Compare this with another class of this type.
Definition: PeripheralUtils.h:1179
bool IsValid() const
Check this feature is valid.
Definition: PeripheralUtils.h:1197
JoystickFeature(const std::string &name="", JOYSTICK_FEATURE_TYPE type=JOYSTICK_FEATURE_TYPE_UNKNOWN)
Class constructor.
Definition: PeripheralUtils.h:1150
JoystickFeature(const JoystickFeature &other)
Class copy constructor.
Definition: PeripheralUtils.h:1159
void SetMotorCount(unsigned int motorCount)
Get motor count.
Definition: PeripheralUtils.h:703
const std::string & Provider(void) const
Get provider name.
Definition: PeripheralUtils.h:643
Joystick & operator=(const Joystick &rhs)
Copy data from another Joystick class to here.
Definition: PeripheralUtils.h:623
unsigned int ButtonCount(void) const
Get button count.
Definition: PeripheralUtils.h:653
unsigned int HatCount(void) const
Get hat count.
Definition: PeripheralUtils.h:658
Joystick(const Joystick &other)
Class copy constructor.
Definition: PeripheralUtils.h:614
bool SupportsPowerOff(void) const
Get supports power off.
Definition: PeripheralUtils.h:673
void SetButtonCount(unsigned int buttonCount)
Get button count.
Definition: PeripheralUtils.h:688
int RequestedPort(void) const
Get requested port number.
Definition: PeripheralUtils.h:648
void SetSupportsPowerOff(bool supportsPowerOff)
Get supports power off.
Definition: PeripheralUtils.h:708
void SetProvider(const std::string &provider)
Set provider name.
Definition: PeripheralUtils.h:678
void SetRequestedPort(int requestedPort)
Get requested port number.
Definition: PeripheralUtils.h:683
Joystick(const std::string &provider="", const std::string &strName="")
Constructor.
Definition: PeripheralUtils.h:604
unsigned int AxisCount(void) const
Get axis count.
Definition: PeripheralUtils.h:663
void SetAxisCount(unsigned int axisCount)
Get axis count.
Definition: PeripheralUtils.h:698
void SetHatCount(unsigned int hatCount)
Get hat count.
Definition: PeripheralUtils.h:693
unsigned int MotorCount(void) const
Get motor count.
Definition: PeripheralUtils.h:668
~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:473
JOYSTICK_STATE_HAT HatState(void) const
Get hat state.
Definition: PeripheralUtils.h:458
void SetAxisState(JOYSTICK_STATE_AXIS state)
Set axis state.
Definition: PeripheralUtils.h:498
JOYSTICK_STATE_MOTOR MotorState(void) const
Get motor state.
Definition: PeripheralUtils.h:468
JOYSTICK_STATE_BUTTON ButtonState(void) const
Get button state.
Definition: PeripheralUtils.h:453
PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state)
Constructor.
Definition: PeripheralUtils.h:414
void SetDriverIndex(unsigned int index)
Set driver index.
Definition: PeripheralUtils.h:483
PeripheralEvent()=default
Constructor.
unsigned int PeripheralIndex(void) const
Get peripheral index.
Definition: PeripheralUtils.h:443
void SetPeripheralIndex(unsigned int index)
Set peripheral index.
Definition: PeripheralUtils.h:478
void SetHatState(JOYSTICK_STATE_HAT state)
Set hat state.
Definition: PeripheralUtils.h:493
JOYSTICK_STATE_AXIS AxisState(void) const
Get axis state.
Definition: PeripheralUtils.h:463
PERIPHERAL_EVENT_TYPE Type(void) const
Get type of event.
Definition: PeripheralUtils.h:438
void SetMotorState(JOYSTICK_STATE_MOTOR state)
Set motor state.
Definition: PeripheralUtils.h:503
PeripheralEvent(unsigned int peripheralIndex, unsigned int buttonIndex, JOYSTICK_STATE_BUTTON state)
Constructor.
Definition: PeripheralUtils.h:399
PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state)
Constructor.
Definition: PeripheralUtils.h:427
void SetButtonState(JOYSTICK_STATE_BUTTON state)
Set button state.
Definition: PeripheralUtils.h:488
unsigned int DriverIndex(void) const
Get driver index.
Definition: PeripheralUtils.h:448
uint16_t VendorID(void) const
Get peripheral vendor id.
Definition: PeripheralUtils.h:274
void SetName(const std::string &strName)
Set peripheral name.
Definition: PeripheralUtils.h:301
uint16_t ProductID(void) const
Get peripheral product id.
Definition: PeripheralUtils.h:279
void SetIndex(unsigned int index)
Set peripheral index.
Definition: PeripheralUtils.h:316
const std::string & Name(void) const
Get peripheral name.
Definition: PeripheralUtils.h:269
virtual ~Peripheral(void)=default
Destructor.
bool IsVidPidKnown(void) const
Check VID and PID are known.
Definition: PeripheralUtils.h:291
void SetType(PERIPHERAL_TYPE type)
Set peripheral type.
Definition: PeripheralUtils.h:296
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:311
unsigned int Index(void) const
Get peripheral index identifier.
Definition: PeripheralUtils.h:284
PERIPHERAL_TYPE Type(void) const
Get peripheral type.
Definition: PeripheralUtils.h:264
void SetVendorID(uint16_t vendorId)
Set peripheral vendor id.
Definition: PeripheralUtils.h:306
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:469
Mapping between higher-level controller feature and its driver primitives.
Definition: peripheral.h:594
Info specific to joystick peripherals.
Definition: peripheral.h:239
unsigned int motor_count
number of motors reported by the driver
Definition: peripheral.h:246
unsigned int axis_count
number of axes reported by the driver
Definition: peripheral.h:245
char * provider
name of the driver or interface providing the joystick
Definition: peripheral.h:241
unsigned int button_count
number of buttons reported by the driver
Definition: peripheral.h:243
bool supports_poweroff
whether the joystick supports being powered off
Definition: peripheral.h:247
unsigned int hat_count
number of hats reported by the driver
Definition: peripheral.h:244
PERIPHERAL_INFO peripheral
peripheral info for this joystick
Definition: peripheral.h:240
int requested_port
requested port number (such as for 360 controllers), or NO_PORT_REQUESTED
Definition: peripheral.h:242
Peripheral add-on capabilities.
Definition: peripheral.h:100
bool provides_joysticks
Definition: peripheral.h:101
bool provides_buttonmaps
Definition: peripheral.h:104
Event information.
Definition: peripheral.h:214
Information shared between peripherals.
Definition: peripheral.h:88
uint16_t product_id
Definition: peripheral.h:92
unsigned int index
Definition: peripheral.h:93
char * name
Definition: peripheral.h:90
uint16_t vendor_id
Definition: peripheral.h:91
PERIPHERAL_TYPE type
Definition: peripheral.h:89
Definition: PeripheralUtils.h:806
DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE type, unsigned int driverIndex)
Construct a driver primitive of the specified type.
Definition: PeripheralUtils.h:811