diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/PeripheralUtils.h | 1277 |
2 files changed, 1282 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/CMakeLists.txt new file mode 100644 index 0000000..d6fba69 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/CMakeLists.txt | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | set(HEADERS PeripheralUtils.h) | ||
| 2 | |||
| 3 | if(NOT ENABLE_STATIC_LIBS) | ||
| 4 | core_add_library(addons_kodi-dev-kit_include_kodi_addon-instance_peripheral) | ||
| 5 | endif() | ||
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/PeripheralUtils.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/PeripheralUtils.h new file mode 100644 index 0000000..febaeb9 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/PeripheralUtils.h | |||
| @@ -0,0 +1,1277 @@ | |||
| 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 | |||
| 36 | namespace kodi | ||
| 37 | { | ||
| 38 | namespace addon | ||
| 39 | { | ||
| 40 | |||
| 41 | class CInstancePeripheral; | ||
| 42 | |||
| 43 | /*! | ||
| 44 | * Utility class to manipulate arrays of peripheral types. | ||
| 45 | */ | ||
| 46 | template<class THE_CLASS, typename THE_STRUCT> | ||
| 47 | class PeripheralVector | ||
| 48 | { | ||
| 49 | public: | ||
| 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 | //============================================================================== | ||
| 114 | /// @defgroup cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities class PeripheralCapabilities | ||
| 115 | /// @ingroup cpp_kodi_addon_peripheral_Defs_General | ||
| 116 | /// @brief **%Peripheral add-on capabilities**\n | ||
| 117 | /// This class is needed to tell Kodi which options are supported on the addon. | ||
| 118 | /// | ||
| 119 | /// If a capability is set to **true**, then the corresponding methods from | ||
| 120 | /// @ref cpp_kodi_addon_peripheral "kodi::addon::CInstancePeripheral" need to be | ||
| 121 | /// implemented. | ||
| 122 | /// | ||
| 123 | /// As default them all set to **false**. | ||
| 124 | /// | ||
| 125 | /// Used on @ref kodi::addon::CInstancePeripheral::GetCapabilities(). | ||
| 126 | /// | ||
| 127 | /// ---------------------------------------------------------------------------- | ||
| 128 | /// | ||
| 129 | /// @copydetails cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities_Help | ||
| 130 | /// | ||
| 131 | ///@{ | ||
| 132 | class PeripheralCapabilities : public CStructHdl<PeripheralCapabilities, PERIPHERAL_CAPABILITIES> | ||
| 133 | { | ||
| 134 | /*! \cond PRIVATE */ | ||
| 135 | friend class CInstancePeripheral; | ||
| 136 | /*! \endcond */ | ||
| 137 | |||
| 138 | public: | ||
| 139 | /*! \cond PRIVATE */ | ||
| 140 | PeripheralCapabilities() | ||
| 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 | |||
| 148 | PeripheralCapabilities(const PeripheralCapabilities& data) : CStructHdl(data) {} | ||
| 149 | /*! \endcond */ | ||
| 150 | |||
| 151 | /// @defgroup cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities_Help Value Help | ||
| 152 | /// @ingroup cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities | ||
| 153 | /// ---------------------------------------------------------------------------- | ||
| 154 | /// | ||
| 155 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities :</b> | ||
| 156 | /// | Name | Type | Set call | Get call | ||
| 157 | /// |------|------|----------|---------- | ||
| 158 | /// | **Provides joysticks** | `boolean` | @ref PeripheralCapabilities::SetProvidesJoysticks "SetProvidesJoysticks" | @ref PeripheralCapabilities::GetProvidesJoysticks "GetProvidesJoysticks" | ||
| 159 | /// | **Provides joystick rumble** | `boolean` | @ref PeripheralCapabilities::SetProvidesJoystickRumble "SetProvidesJoystickRumble" | @ref PeripheralCapabilities::GetProvidesJoystickRumble "GetProvidesJoystickRumble" | ||
| 160 | /// | **Provides joystick power off** | `boolean` | @ref PeripheralCapabilities::SetProvidesJoystickPowerOff "SetProvidesJoystickPowerOff" | @ref PeripheralCapabilities::GetProvidesJoystickPowerOff "GetProvidesJoystickPowerOff" | ||
| 161 | /// | **Provides button maps** | `boolean` | @ref PeripheralCapabilities::SetProvidesButtonmaps "SetProvidesButtonmaps" | @ref PeripheralCapabilities::GetProvidesButtonmaps "GetProvidesButtonmaps" | ||
| 162 | |||
| 163 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_PeripheralCapabilities | ||
| 164 | ///@{ | ||
| 165 | |||
| 166 | /// @brief Set true if the add-on provides joysticks. | ||
| 167 | void SetProvidesJoysticks(bool providesJoysticks) | ||
| 168 | { | ||
| 169 | m_cStructure->provides_joysticks = providesJoysticks; | ||
| 170 | } | ||
| 171 | |||
| 172 | /// @brief To get with @ref SetProvidesJoysticks changed values. | ||
| 173 | bool GetProvidesJoysticks() const { return m_cStructure->provides_joysticks; } | ||
| 174 | |||
| 175 | /// @brief Set true if the add-on provides joystick rumble. | ||
| 176 | void SetProvidesJoystickRumble(bool providesJoystickRumble) | ||
| 177 | { | ||
| 178 | m_cStructure->provides_joystick_rumble = providesJoystickRumble; | ||
| 179 | } | ||
| 180 | |||
| 181 | /// @brief To get with @ref SetProvidesJoystickRumble changed values. | ||
| 182 | bool GetProvidesJoystickRumble() const { return m_cStructure->provides_joystick_rumble; } | ||
| 183 | |||
| 184 | /// @brief Set true if the add-on provides power off about joystick. | ||
| 185 | void SetProvidesJoystickPowerOff(bool providesJoystickPowerOff) | ||
| 186 | { | ||
| 187 | m_cStructure->provides_joystick_power_off = providesJoystickPowerOff; | ||
| 188 | } | ||
| 189 | |||
| 190 | /// @brief To get with @ref SetProvidesJoystickPowerOff changed values. | ||
| 191 | bool GetProvidesJoystickPowerOff() const { return m_cStructure->provides_joystick_power_off; } | ||
| 192 | |||
| 193 | /// @brief Set true if the add-on provides button maps. | ||
| 194 | void SetProvidesButtonmaps(bool providesButtonmaps) | ||
| 195 | { | ||
| 196 | m_cStructure->provides_buttonmaps = providesButtonmaps; | ||
| 197 | } | ||
| 198 | |||
| 199 | /// @brief To get with @ref SetProvidesButtonmaps changed values. | ||
| 200 | bool GetProvidesButtonmaps() const { return m_cStructure->provides_buttonmaps; } | ||
| 201 | |||
| 202 | ///@} | ||
| 203 | |||
| 204 | private: | ||
| 205 | PeripheralCapabilities(const PERIPHERAL_CAPABILITIES* data) : CStructHdl(data) {} | ||
| 206 | PeripheralCapabilities(PERIPHERAL_CAPABILITIES* data) : CStructHdl(data) {} | ||
| 207 | }; | ||
| 208 | ///@} | ||
| 209 | //------------------------------------------------------------------------------ | ||
| 210 | |||
| 211 | //============================================================================== | ||
| 212 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral class Peripheral | ||
| 213 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Peripheral | ||
| 214 | /// @brief **Wrapper class providing peripheral information**\n | ||
| 215 | /// Classes can extend %Peripheral to inherit peripheral properties. | ||
| 216 | /// | ||
| 217 | /// Used on @ref kodi::addon::CInstancePeripheral::PerformDeviceScan(). | ||
| 218 | /// | ||
| 219 | /// ---------------------------------------------------------------------------- | ||
| 220 | /// | ||
| 221 | /// @copydetails cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral_Help | ||
| 222 | /// | ||
| 223 | ///@{ | ||
| 224 | class Peripheral | ||
| 225 | { | ||
| 226 | public: | ||
| 227 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral_Help Value Help | ||
| 228 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral | ||
| 229 | /// ---------------------------------------------------------------------------- | ||
| 230 | /// | ||
| 231 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral :</b> | ||
| 232 | /// | Name | Type | Set call | Get call | ||
| 233 | /// |------|------|----------|---------- | ||
| 234 | /// | **%Peripheral type** | @ref PERIPHERAL_TYPE | @ref Peripheral::SetType "SetType" | @ref Peripheral::Type "Type" | ||
| 235 | /// | **%Peripheral name** | `const std::string&` | @ref Peripheral::SetName "SetName" | @ref Peripheral::Name "Name" | ||
| 236 | /// | **%Peripheral vendor id** | `uint16_t` | @ref Peripheral::SetVendorID "SetVendorID" | @ref Peripheral::VendorID "VendorID" | ||
| 237 | /// | **%Peripheral product id** | `uint16_t` | @ref Peripheral::SetProductID "SetProductID" | @ref Peripheral::ProductID "ProductID" | ||
| 238 | /// | **%Peripheral index** | `unsigned int` | @ref Peripheral::SetIndex "SetIndex" | @ref Peripheral::Index "Index" | ||
| 239 | /// | ||
| 240 | /// Further are following included: | ||
| 241 | /// - @ref Peripheral::Peripheral "Peripheral(PERIPHERAL_TYPE type = PERIPHERAL_TYPE_UNKNOWN, const std::string& strName = \"\")": Class constructor. | ||
| 242 | /// - @ref Peripheral::IsVidPidKnown "IsVidPidKnown()": To check VID and PID are known. | ||
| 243 | /// | ||
| 244 | |||
| 245 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral | ||
| 246 | ///@{ | ||
| 247 | |||
| 248 | /// @brief Constructor. | ||
| 249 | /// | ||
| 250 | /// @param[in] type [optional] Peripheral type, or @ref PERIPHERAL_TYPE_UNKNOWN | ||
| 251 | /// as default | ||
| 252 | /// @param[in] strName [optional] Name of related peripheral | ||
| 253 | Peripheral(PERIPHERAL_TYPE type = PERIPHERAL_TYPE_UNKNOWN, const std::string& strName = "") | ||
| 254 | : m_type(type), m_strName(strName) | ||
| 255 | { | ||
| 256 | } | ||
| 257 | |||
| 258 | /// @brief Destructor. | ||
| 259 | virtual ~Peripheral(void) = default; | ||
| 260 | |||
| 261 | /// @brief Get peripheral type. | ||
| 262 | /// | ||
| 263 | /// @return Type defined with @ref PERIPHERAL_TYPE | ||
| 264 | PERIPHERAL_TYPE Type(void) const { return m_type; } | ||
| 265 | |||
| 266 | /// @brief Get peripheral name. | ||
| 267 | /// | ||
| 268 | /// @return Name string of peripheral | ||
| 269 | const std::string& Name(void) const { return m_strName; } | ||
| 270 | |||
| 271 | /// @brief Get peripheral vendor id. | ||
| 272 | /// | ||
| 273 | /// @return Vendor id | ||
| 274 | uint16_t VendorID(void) const { return m_vendorId; } | ||
| 275 | |||
| 276 | /// @brief Get peripheral product id. | ||
| 277 | /// | ||
| 278 | /// @return Product id | ||
| 279 | uint16_t ProductID(void) const { return m_productId; } | ||
| 280 | |||
| 281 | /// @brief Get peripheral index identifier. | ||
| 282 | /// | ||
| 283 | /// @return Index number | ||
| 284 | unsigned int Index(void) const { return m_index; } | ||
| 285 | |||
| 286 | /// @brief Check VID and PID are known. | ||
| 287 | /// | ||
| 288 | /// @return true if VID and PID are not 0 | ||
| 289 | /// | ||
| 290 | /// @note Derived property: VID and PID are `0x0000` if unknown | ||
| 291 | bool IsVidPidKnown(void) const { return m_vendorId != 0 || m_productId != 0; } | ||
| 292 | |||
| 293 | /// @brief Set peripheral type. | ||
| 294 | /// | ||
| 295 | /// @param[in] type Type to set | ||
| 296 | void SetType(PERIPHERAL_TYPE type) { m_type = type; } | ||
| 297 | |||
| 298 | /// @brief Set peripheral name. | ||
| 299 | /// | ||
| 300 | /// @param[in] strName Name to set | ||
| 301 | void SetName(const std::string& strName) { m_strName = strName; } | ||
| 302 | |||
| 303 | /// @brief Set peripheral vendor id. | ||
| 304 | /// | ||
| 305 | /// @param[in] vendorId Type to set | ||
| 306 | void SetVendorID(uint16_t vendorId) { m_vendorId = vendorId; } | ||
| 307 | |||
| 308 | /// @brief Set peripheral product identifier. | ||
| 309 | /// | ||
| 310 | /// @param[in] productId Type to set | ||
| 311 | void SetProductID(uint16_t productId) { m_productId = productId; } | ||
| 312 | |||
| 313 | /// @brief Set peripheral index. | ||
| 314 | /// | ||
| 315 | /// @param[in] index Type to set | ||
| 316 | void SetIndex(unsigned int index) { m_index = index; } | ||
| 317 | |||
| 318 | ///@} | ||
| 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 | |||
| 342 | private: | ||
| 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 | }; | ||
| 349 | ///@} | ||
| 350 | //------------------------------------------------------------------------------ | ||
| 351 | |||
| 352 | typedef PeripheralVector<Peripheral, PERIPHERAL_INFO> Peripherals; | ||
| 353 | |||
| 354 | //============================================================================== | ||
| 355 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent class PeripheralEvent | ||
| 356 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Peripheral | ||
| 357 | /// @brief **Wrapper class for %peripheral events**\n | ||
| 358 | /// To handle data of change events between add-on and Kodi. | ||
| 359 | /// | ||
| 360 | /// Used on @ref kodi::addon::CInstancePeripheral::GetEvents() and | ||
| 361 | /// @ref kodi::addon::CInstancePeripheral::SendEvent(). | ||
| 362 | /// | ||
| 363 | /// ---------------------------------------------------------------------------- | ||
| 364 | /// | ||
| 365 | /// @copydetails cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent_Help | ||
| 366 | /// | ||
| 367 | ///@{ | ||
| 368 | class PeripheralEvent | ||
| 369 | { | ||
| 370 | public: | ||
| 371 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent_Help Value Help | ||
| 372 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent | ||
| 373 | /// ---------------------------------------------------------------------------- | ||
| 374 | /// | ||
| 375 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent :</b> | ||
| 376 | /// | Name | Type | Set call | Get call | ||
| 377 | /// |------|------|----------|---------- | ||
| 378 | /// | **%Peripheral event type** | @ref PERIPHERAL_EVENT_TYPE | @ref PeripheralEvent::SetType "SetType" | @ref PeripheralEvent::Type "Type" | ||
| 379 | /// | **%Peripheral index** | `unsigned int` | @ref PeripheralEvent::SetPeripheralIndex "SetPeripheralIndex" | @ref PeripheralEvent::PeripheralIndex "PeripheralIndex" | ||
| 380 | /// | **%Peripheral event driver index** | `unsigned int` | @ref PeripheralEvent::SetDriverIndex "SetDriverIndex" | @ref PeripheralEvent::DriverIndex "DriverIndex" | ||
| 381 | /// | **%Peripheral event button state** | @ref JOYSTICK_STATE_BUTTON | @ref PeripheralEvent::SetButtonState "SetButtonState" | @ref PeripheralEvent::ButtonState "ButtonState" | ||
| 382 | /// | **%Peripheral event hat state** | @ref JOYSTICK_STATE_HAT | @ref PeripheralEvent::SetHatState "SetHatState" | @ref PeripheralEvent::HatState "HatState" | ||
| 383 | /// | **%Peripheral event axis state** | @ref JOYSTICK_STATE_AXIS (`float`) | @ref PeripheralEvent::SetAxisState "SetAxisState" | @ref PeripheralEvent::AxisState "AxisState" | ||
| 384 | /// | **%Peripheral event motor state** | @ref JOYSTICK_STATE_MOTOR (`float`) | @ref PeripheralEvent::SetMotorState "SetMotorState" | @ref PeripheralEvent::MotorState "MotorState" | ||
| 385 | /// | ||
| 386 | /// Further are several class constructors with values included. | ||
| 387 | |||
| 388 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_Peripheral_PeripheralEvent | ||
| 389 | ///@{ | ||
| 390 | |||
| 391 | /// @brief Constructor. | ||
| 392 | PeripheralEvent() = default; | ||
| 393 | |||
| 394 | /// @brief Constructor. | ||
| 395 | /// | ||
| 396 | /// @param[in] peripheralIndex %Peripheral index | ||
| 397 | /// @param[in] buttonIndex Button index | ||
| 398 | /// @param[in] state Joystick state button | ||
| 399 | PeripheralEvent(unsigned int peripheralIndex, | ||
| 400 | unsigned int buttonIndex, | ||
| 401 | JOYSTICK_STATE_BUTTON state) | ||
| 402 | : m_type(PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON), | ||
| 403 | m_peripheralIndex(peripheralIndex), | ||
| 404 | m_driverIndex(buttonIndex), | ||
| 405 | m_buttonState(state) | ||
| 406 | { | ||
| 407 | } | ||
| 408 | |||
| 409 | /// @brief Constructor. | ||
| 410 | /// | ||
| 411 | /// @param[in] peripheralIndex %Peripheral index | ||
| 412 | /// @param[in] hatIndex Hat index | ||
| 413 | /// @param[in] state Joystick state hat | ||
| 414 | PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state) | ||
| 415 | : m_type(PERIPHERAL_EVENT_TYPE_DRIVER_HAT), | ||
| 416 | m_peripheralIndex(peripheralIndex), | ||
| 417 | m_driverIndex(hatIndex), | ||
| 418 | m_hatState(state) | ||
| 419 | { | ||
| 420 | } | ||
| 421 | |||
| 422 | /// @brief Constructor. | ||
| 423 | /// | ||
| 424 | /// @param[in] peripheralIndex %Peripheral index | ||
| 425 | /// @param[in] axisIndex Axis index | ||
| 426 | /// @param[in] state Joystick state axis | ||
| 427 | PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state) | ||
| 428 | : m_type(PERIPHERAL_EVENT_TYPE_DRIVER_AXIS), | ||
| 429 | m_peripheralIndex(peripheralIndex), | ||
| 430 | m_driverIndex(axisIndex), | ||
| 431 | m_axisState(state) | ||
| 432 | { | ||
| 433 | } | ||
| 434 | |||
| 435 | /// @brief Get type of event. | ||
| 436 | /// | ||
| 437 | /// @return Type defined with @ref PERIPHERAL_EVENT_TYPE | ||
| 438 | PERIPHERAL_EVENT_TYPE Type(void) const { return m_type; } | ||
| 439 | |||
| 440 | /// @brief Get peripheral index. | ||
| 441 | /// | ||
| 442 | /// @return %Peripheral index number | ||
| 443 | unsigned int PeripheralIndex(void) const { return m_peripheralIndex; } | ||
| 444 | |||
| 445 | /// @brief Get driver index. | ||
| 446 | /// | ||
| 447 | /// @return Driver index number | ||
| 448 | unsigned int DriverIndex(void) const { return m_driverIndex; } | ||
| 449 | |||
| 450 | /// @brief Get button state. | ||
| 451 | /// | ||
| 452 | /// @return Button state as @ref JOYSTICK_STATE_BUTTON | ||
| 453 | JOYSTICK_STATE_BUTTON ButtonState(void) const { return m_buttonState; } | ||
| 454 | |||
| 455 | /// @brief Get hat state. | ||
| 456 | /// | ||
| 457 | /// @return Hat state | ||
| 458 | JOYSTICK_STATE_HAT HatState(void) const { return m_hatState; } | ||
| 459 | |||
| 460 | /// @brief Get axis state. | ||
| 461 | /// | ||
| 462 | /// @return Axis state | ||
| 463 | JOYSTICK_STATE_AXIS AxisState(void) const { return m_axisState; } | ||
| 464 | |||
| 465 | /// @brief Get motor state. | ||
| 466 | /// | ||
| 467 | /// @return Motor state | ||
| 468 | JOYSTICK_STATE_MOTOR MotorState(void) const { return m_motorState; } | ||
| 469 | |||
| 470 | /// @brief Set type of event. | ||
| 471 | /// | ||
| 472 | /// @param[in] type Type defined with @ref PERIPHERAL_EVENT_TYPE | ||
| 473 | void SetType(PERIPHERAL_EVENT_TYPE type) { m_type = type; } | ||
| 474 | |||
| 475 | /// @brief Set peripheral index. | ||
| 476 | /// | ||
| 477 | /// @param[in] index %Peripheral index number | ||
| 478 | void SetPeripheralIndex(unsigned int index) { m_peripheralIndex = index; } | ||
| 479 | |||
| 480 | /// @brief Set driver index. | ||
| 481 | /// | ||
| 482 | /// @param[in] index Driver index number | ||
| 483 | void SetDriverIndex(unsigned int index) { m_driverIndex = index; } | ||
| 484 | |||
| 485 | /// @brief Set button state. | ||
| 486 | /// | ||
| 487 | /// @param[in] state Button state as @ref JOYSTICK_STATE_BUTTON | ||
| 488 | void SetButtonState(JOYSTICK_STATE_BUTTON state) { m_buttonState = state; } | ||
| 489 | |||
| 490 | /// @brief Set hat state. | ||
| 491 | /// | ||
| 492 | /// @param[in] state Hat state as @ref JOYSTICK_STATE_HAT (float) | ||
| 493 | void SetHatState(JOYSTICK_STATE_HAT state) { m_hatState = state; } | ||
| 494 | |||
| 495 | /// @brief Set axis state. | ||
| 496 | /// | ||
| 497 | /// @param[in] state Axis state as @ref JOYSTICK_STATE_AXIS (float) | ||
| 498 | void SetAxisState(JOYSTICK_STATE_AXIS state) { m_axisState = state; } | ||
| 499 | |||
| 500 | /// @brief Set motor state. | ||
| 501 | /// | ||
| 502 | /// @param[in] state Motor state as @ref JOYSTICK_STATE_MOTOR (float) | ||
| 503 | void SetMotorState(JOYSTICK_STATE_MOTOR state) { m_motorState = state; } | ||
| 504 | |||
| 505 | ///@} | ||
| 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 | |||
| 531 | private: | ||
| 532 | PERIPHERAL_EVENT_TYPE m_type = PERIPHERAL_EVENT_TYPE_NONE; | ||
| 533 | unsigned int m_peripheralIndex = 0; | ||
| 534 | unsigned int m_driverIndex = 0; | ||
| 535 | JOYSTICK_STATE_BUTTON m_buttonState = JOYSTICK_STATE_BUTTON_UNPRESSED; | ||
| 536 | JOYSTICK_STATE_HAT m_hatState = JOYSTICK_STATE_HAT_UNPRESSED; | ||
| 537 | JOYSTICK_STATE_AXIS m_axisState = 0.0f; | ||
| 538 | JOYSTICK_STATE_MOTOR m_motorState = 0.0f; | ||
| 539 | }; | ||
| 540 | ///@} | ||
| 541 | //------------------------------------------------------------------------------ | ||
| 542 | |||
| 543 | typedef PeripheralVector<PeripheralEvent, PERIPHERAL_EVENT> PeripheralEvents; | ||
| 544 | |||
| 545 | //============================================================================== | ||
| 546 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Joystick_Joystick class Joystick | ||
| 547 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Joystick | ||
| 548 | /// @brief **Wrapper class providing additional joystick information**\n | ||
| 549 | /// This is a child class to expand another class with necessary joystick data. | ||
| 550 | /// | ||
| 551 | /// For data not provided by @ref cpp_kodi_addon_peripheral_Defs_Peripheral_Peripheral. | ||
| 552 | /// | ||
| 553 | /// Used on: | ||
| 554 | /// - @ref kodi::addon::CInstancePeripheral::GetJoystickInfo() | ||
| 555 | /// - @ref kodi::addon::CInstancePeripheral::GetFeatures(). | ||
| 556 | /// - @ref kodi::addon::CInstancePeripheral::MapFeatures(). | ||
| 557 | /// - @ref kodi::addon::CInstancePeripheral::GetIgnoredPrimitives(). | ||
| 558 | /// - @ref kodi::addon::CInstancePeripheral::SetIgnoredPrimitives(). | ||
| 559 | /// - @ref kodi::addon::CInstancePeripheral::SaveButtonMap(). | ||
| 560 | /// - @ref kodi::addon::CInstancePeripheral::RevertButtonMap(). | ||
| 561 | /// - @ref kodi::addon::CInstancePeripheral::ResetButtonMap(). | ||
| 562 | /// | ||
| 563 | /// ---------------------------------------------------------------------------- | ||
| 564 | /// | ||
| 565 | /// @copydetails cpp_kodi_addon_peripheral_Defs_Joystick_Joystick_Help | ||
| 566 | /// | ||
| 567 | ///@{ | ||
| 568 | class Joystick : public Peripheral | ||
| 569 | { | ||
| 570 | public: | ||
| 571 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Joystick_Joystick_Help Value Help | ||
| 572 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Joystick_Joystick | ||
| 573 | /// ---------------------------------------------------------------------------- | ||
| 574 | /// | ||
| 575 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_peripheral_Defs_Joystick_Joystick :</b> | ||
| 576 | /// | Name | Type | Class | Set call | Get call | ||
| 577 | /// |------|------|-------|----------|---------- | ||
| 578 | /// | **%Joystick provider** | `const std::string&` | @ref Joystick | @ref Joystick::SetProvider "SetProvider" | @ref Joystick::Provider "Provider" | ||
| 579 | /// | **%Joystick requested port** | `int` | @ref Joystick | @ref Joystick::SetRequestedPort "SetRequestedPort" | @ref Joystick::RequestedPort "RequestedPort" | ||
| 580 | /// | **%Joystick button count** | `unsigned int` | @ref Joystick | @ref Joystick::SetButtonCount "SetButtonCount" | @ref Joystick::ButtonCount "ButtonCount" | ||
| 581 | /// | **%Joystick hat count** | `unsigned int` | @ref Joystick | @ref Joystick::SetHatCount "SetHatCount" | @ref Joystick::HatCount "HatCount" | ||
| 582 | /// | **%Joystick axis count** | `unsigned int` | @ref Joystick | @ref Joystick::SetAxisCount "SetAxisCount" | @ref Joystick::AxisCount "AxisCount" | ||
| 583 | /// | **%Joystick motor count** | `unsigned int` | @ref Joystick | @ref Joystick::SetMotorCount "SetMotorCount" | @ref Joystick::MotorCount "MotorCount" | ||
| 584 | /// | **%Joystick support power off** | `bool` | @ref Joystick | @ref Joystick::SetSupportsPowerOff "SetSupportsPowerOff" | @ref Joystick::SupportsPowerOff "SupportsPowerOff" | ||
| 585 | /// | **%Peripheral type** | @ref PERIPHERAL_TYPE | @ref Peripheral | @ref Peripheral::SetType "SetType" | @ref Peripheral::Type "Type" | ||
| 586 | /// | **%Peripheral name** | `const std::string&` | @ref Peripheral | @ref Peripheral::SetName "SetName" | @ref Peripheral::Name "Name" | ||
| 587 | /// | **%Peripheral vendor id** | `uint16_t` | @ref Peripheral | @ref Peripheral::SetVendorID "SetVendorID" | @ref Peripheral::VendorID "VendorID" | ||
| 588 | /// | **%Peripheral product id** | `uint16_t` | @ref Peripheral | @ref Peripheral::SetProductID "SetProductID" | @ref Peripheral::ProductID "ProductID" | ||
| 589 | /// | **%Peripheral index** | `unsigned int` | @ref Peripheral | @ref Peripheral::SetIndex "SetIndex" | @ref Peripheral::Index "Index" | ||
| 590 | /// | ||
| 591 | /// Further are following included: | ||
| 592 | /// - @ref Joystick::Joystick "Joystick(const std::string& provider = \"\", const std::string& strName = \"\")" | ||
| 593 | /// - @ref Joystick::operator= "Joystick& operator=(const Joystick& rhs)" | ||
| 594 | /// - @ref Peripheral::IsVidPidKnown "IsVidPidKnown()": To check VID and PID are known. | ||
| 595 | /// | ||
| 596 | |||
| 597 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_Joystick_Joystick | ||
| 598 | ///@{ | ||
| 599 | |||
| 600 | /// @brief Constructor. | ||
| 601 | /// | ||
| 602 | /// @param[in] provider [optional] Provide name | ||
| 603 | /// @param[in] strName [optional] Name of related joystick | ||
| 604 | Joystick(const std::string& provider = "", const std::string& strName = "") | ||
| 605 | : Peripheral(PERIPHERAL_TYPE_JOYSTICK, strName), | ||
| 606 | m_provider(provider), | ||
| 607 | m_requestedPort(NO_PORT_REQUESTED) | ||
| 608 | { | ||
| 609 | } | ||
| 610 | |||
| 611 | /// @brief Class copy constructor. | ||
| 612 | /// | ||
| 613 | /// @param[in] other Other class to copy on construct here | ||
| 614 | Joystick(const Joystick& other) { *this = other; } | ||
| 615 | |||
| 616 | /// @brief Destructor. | ||
| 617 | /// | ||
| 618 | ~Joystick(void) override = default; | ||
| 619 | |||
| 620 | /// @brief Copy data from another @ref Joystick class to here. | ||
| 621 | /// | ||
| 622 | /// @param[in] other Other class to copy here | ||
| 623 | Joystick& operator=(const Joystick& rhs) | ||
| 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 | |||
| 640 | /// @brief Get provider name. | ||
| 641 | /// | ||
| 642 | /// @return Name of provider | ||
| 643 | const std::string& Provider(void) const { return m_provider; } | ||
| 644 | |||
| 645 | /// @brief Get requested port number. | ||
| 646 | /// | ||
| 647 | /// @return Port | ||
| 648 | int RequestedPort(void) const { return m_requestedPort; } | ||
| 649 | |||
| 650 | /// @brief Get button count. | ||
| 651 | /// | ||
| 652 | /// @return Button count | ||
| 653 | unsigned int ButtonCount(void) const { return m_buttonCount; } | ||
| 654 | |||
| 655 | /// @brief Get hat count. | ||
| 656 | /// | ||
| 657 | /// @return Hat count | ||
| 658 | unsigned int HatCount(void) const { return m_hatCount; } | ||
| 659 | |||
| 660 | /// @brief Get axis count. | ||
| 661 | /// | ||
| 662 | /// @return Axis count | ||
| 663 | unsigned int AxisCount(void) const { return m_axisCount; } | ||
| 664 | |||
| 665 | /// @brief Get motor count. | ||
| 666 | /// | ||
| 667 | /// @return Motor count | ||
| 668 | unsigned int MotorCount(void) const { return m_motorCount; } | ||
| 669 | |||
| 670 | /// @brief Get supports power off. | ||
| 671 | /// | ||
| 672 | /// @return True if power off is supported, false otherwise | ||
| 673 | bool SupportsPowerOff(void) const { return m_supportsPowerOff; } | ||
| 674 | |||
| 675 | /// @brief Set provider name. | ||
| 676 | /// | ||
| 677 | /// @param[in] provider Name of provider | ||
| 678 | void SetProvider(const std::string& provider) { m_provider = provider; } | ||
| 679 | |||
| 680 | /// @brief Get requested port number. | ||
| 681 | /// | ||
| 682 | /// @param[in] requestedPort Port | ||
| 683 | void SetRequestedPort(int requestedPort) { m_requestedPort = requestedPort; } | ||
| 684 | |||
| 685 | /// @brief Get button count. | ||
| 686 | /// | ||
| 687 | /// @param[in] buttonCount Button count | ||
| 688 | void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; } | ||
| 689 | |||
| 690 | /// @brief Get hat count. | ||
| 691 | /// | ||
| 692 | /// @param[in] hatCount Hat count | ||
| 693 | void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; } | ||
| 694 | |||
| 695 | /// @brief Get axis count. | ||
| 696 | /// | ||
| 697 | /// @param[in] axisCount Axis count | ||
| 698 | void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; } | ||
| 699 | |||
| 700 | /// @brief Get motor count. | ||
| 701 | /// | ||
| 702 | /// @param[in] motorCount Motor count | ||
| 703 | void SetMotorCount(unsigned int motorCount) { m_motorCount = motorCount; } | ||
| 704 | |||
| 705 | /// @brief Get supports power off. | ||
| 706 | /// | ||
| 707 | /// @param[in] supportsPowerOff True if power off is supported, false otherwise | ||
| 708 | void SetSupportsPowerOff(bool supportsPowerOff) { m_supportsPowerOff = supportsPowerOff; } | ||
| 709 | |||
| 710 | ///@} | ||
| 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 | |||
| 746 | private: | ||
| 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 | }; | ||
| 755 | ///@} | ||
| 756 | //------------------------------------------------------------------------------ | ||
| 757 | |||
| 758 | typedef PeripheralVector<Joystick, JOYSTICK_INFO> Joysticks; | ||
| 759 | |||
| 760 | class JoystickFeature; | ||
| 761 | |||
| 762 | //============================================================================== | ||
| 763 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Joystick_DriverPrimitive class DriverPrimitive | ||
| 764 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Joystick | ||
| 765 | /// @brief **Base class for joystick driver primitives** | ||
| 766 | /// | ||
| 767 | /// A driver primitive can be: | ||
| 768 | /// | ||
| 769 | /// 1. a button | ||
| 770 | /// 2. a hat direction | ||
| 771 | /// 3. a semiaxis (either the positive or negative half of an axis) | ||
| 772 | /// 4. a motor | ||
| 773 | /// 5. a keyboard key | ||
| 774 | /// 6. a mouse button | ||
| 775 | /// 7. a relative pointer direction | ||
| 776 | /// | ||
| 777 | /// The type determines the fields in use: | ||
| 778 | /// | ||
| 779 | /// Button: | ||
| 780 | /// - driver index | ||
| 781 | /// | ||
| 782 | /// Hat direction: | ||
| 783 | /// - driver index | ||
| 784 | /// - hat direction | ||
| 785 | /// | ||
| 786 | /// Semiaxis: | ||
| 787 | /// - driver index | ||
| 788 | /// - center | ||
| 789 | /// - semiaxis direction | ||
| 790 | /// - range | ||
| 791 | /// | ||
| 792 | /// Motor: | ||
| 793 | /// - driver index | ||
| 794 | /// | ||
| 795 | /// Key: | ||
| 796 | /// - key code | ||
| 797 | /// | ||
| 798 | /// Mouse button: | ||
| 799 | /// - driver index | ||
| 800 | /// | ||
| 801 | /// Relative pointer direction: | ||
| 802 | /// - relative pointer direction | ||
| 803 | /// | ||
| 804 | ///@{ | ||
| 805 | struct DriverPrimitive | ||
| 806 | { | ||
| 807 | protected: | ||
| 808 | /*! | ||
| 809 | * \brief Construct a driver primitive of the specified type | ||
| 810 | */ | ||
| 811 | DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE type, unsigned int driverIndex) | ||
| 812 | : m_type(type), m_driverIndex(driverIndex) | ||
| 813 | { | ||
| 814 | } | ||
| 815 | |||
| 816 | public: | ||
| 817 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_Joystick_DriverPrimitive | ||
| 818 | ///@{ | ||
| 819 | |||
| 820 | /// @brief Construct an invalid driver primitive. | ||
| 821 | DriverPrimitive(void) = default; | ||
| 822 | |||
| 823 | /// @brief Construct a driver primitive representing a joystick button. | ||
| 824 | /// | ||
| 825 | /// @param[in] buttonIndex Index | ||
| 826 | /// @return Created class | ||
| 827 | static DriverPrimitive CreateButton(unsigned int buttonIndex) | ||
| 828 | { | ||
| 829 | return DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON, buttonIndex); | ||
| 830 | } | ||
| 831 | |||
| 832 | /// @brief Construct a driver primitive representing one of the four direction | ||
| 833 | /// arrows on a dpad. | ||
| 834 | /// | ||
| 835 | /// @param[in] hatIndex Hat index | ||
| 836 | /// @param[in] direction With @ref JOYSTICK_DRIVER_HAT_DIRECTION defined direction | ||
| 837 | DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction) | ||
| 838 | : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION), | ||
| 839 | m_driverIndex(hatIndex), | ||
| 840 | m_hatDirection(direction) | ||
| 841 | { | ||
| 842 | } | ||
| 843 | |||
| 844 | /// @brief Construct a driver primitive representing the positive or negative | ||
| 845 | /// half of an axis. | ||
| 846 | /// | ||
| 847 | /// @param[in] axisIndex Axis index | ||
| 848 | /// @param[in] center Center | ||
| 849 | /// @param[in] direction With @ref JOYSTICK_DRIVER_HAT_DIRECTION defined direction | ||
| 850 | /// @param[in] range Range | ||
| 851 | DriverPrimitive(unsigned int axisIndex, | ||
| 852 | int center, | ||
| 853 | JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction, | ||
| 854 | unsigned int range) | ||
| 855 | : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS), | ||
| 856 | m_driverIndex(axisIndex), | ||
| 857 | m_center(center), | ||
| 858 | m_semiAxisDirection(direction), | ||
| 859 | m_range(range) | ||
| 860 | { | ||
| 861 | } | ||
| 862 | |||
| 863 | /// @brief Construct a driver primitive representing a motor. | ||
| 864 | /// | ||
| 865 | /// @param[in] motorIndex Motor index number | ||
| 866 | /// @return Constructed driver primitive representing a motor | ||
| 867 | static DriverPrimitive CreateMotor(unsigned int motorIndex) | ||
| 868 | { | ||
| 869 | return DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR, motorIndex); | ||
| 870 | } | ||
| 871 | |||
| 872 | /// @brief Construct a driver primitive representing a key on a keyboard. | ||
| 873 | /// | ||
| 874 | /// @param[in] keycode Keycode to use | ||
| 875 | DriverPrimitive(std::string keycode) | ||
| 876 | : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY), m_keycode(std::move(keycode)) | ||
| 877 | { | ||
| 878 | } | ||
| 879 | |||
| 880 | /// @brief Construct a driver primitive representing a mouse button. | ||
| 881 | /// | ||
| 882 | /// @param[in] buttonIndex Index | ||
| 883 | /// @return Constructed driver primitive representing a mouse button | ||
| 884 | static DriverPrimitive CreateMouseButton(JOYSTICK_DRIVER_MOUSE_INDEX buttonIndex) | ||
| 885 | { | ||
| 886 | return DriverPrimitive(JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON, | ||
| 887 | static_cast<unsigned int>(buttonIndex)); | ||
| 888 | } | ||
| 889 | |||
| 890 | /// @brief Construct a driver primitive representing one of the four | ||
| 891 | /// direction in which a relative pointer can move | ||
| 892 | /// | ||
| 893 | /// @param[in] direction With @ref JOYSTICK_DRIVER_RELPOINTER_DIRECTION defined direction | ||
| 894 | DriverPrimitive(JOYSTICK_DRIVER_RELPOINTER_DIRECTION direction) | ||
| 895 | : m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION), m_relPointerDirection(direction) | ||
| 896 | { | ||
| 897 | } | ||
| 898 | |||
| 899 | /// @brief Get type of primitive. | ||
| 900 | /// | ||
| 901 | /// @return The with @ref JOYSTICK_DRIVER_PRIMITIVE_TYPE defined type | ||
| 902 | JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const { return m_type; } | ||
| 903 | |||
| 904 | /// @brief Get driver index. | ||
| 905 | /// | ||
| 906 | /// @return Index number | ||
| 907 | unsigned int DriverIndex(void) const { return m_driverIndex; } | ||
| 908 | |||
| 909 | /// @brief Get hat direction | ||
| 910 | /// | ||
| 911 | /// @return The with @ref JOYSTICK_DRIVER_HAT_DIRECTION defined direction | ||
| 912 | JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const { return m_hatDirection; } | ||
| 913 | |||
| 914 | /// @brief Get center | ||
| 915 | /// | ||
| 916 | /// @return Center | ||
| 917 | int Center(void) const { return m_center; } | ||
| 918 | |||
| 919 | /// @brief Get semi axis direction | ||
| 920 | /// | ||
| 921 | /// @return With @ref JOYSTICK_DRIVER_SEMIAXIS_DIRECTION defined direction | ||
| 922 | JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const { return m_semiAxisDirection; } | ||
| 923 | |||
| 924 | /// @brief Get range. | ||
| 925 | /// | ||
| 926 | /// @return Range | ||
| 927 | unsigned int Range(void) const { return m_range; } | ||
| 928 | |||
| 929 | /// @brief Get key code as string. | ||
| 930 | /// | ||
| 931 | /// @return Key code | ||
| 932 | const std::string& Keycode(void) const { return m_keycode; } | ||
| 933 | |||
| 934 | /// @brief Get mouse index | ||
| 935 | /// | ||
| 936 | /// @return With @ref JOYSTICK_DRIVER_MOUSE_INDEX defined mouse index | ||
| 937 | JOYSTICK_DRIVER_MOUSE_INDEX MouseIndex(void) const | ||
| 938 | { | ||
| 939 | return static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex); | ||
| 940 | } | ||
| 941 | |||
| 942 | /// @brief Get relative pointer direction. | ||
| 943 | /// | ||
| 944 | /// @return With @ref JOYSTICK_DRIVER_RELPOINTER_DIRECTION defined direction | ||
| 945 | JOYSTICK_DRIVER_RELPOINTER_DIRECTION RelPointerDirection(void) const | ||
| 946 | { | ||
| 947 | return m_relPointerDirection; | ||
| 948 | } | ||
| 949 | |||
| 950 | /// @brief Compare this with another class of this type. | ||
| 951 | /// | ||
| 952 | /// @param[in] other Other class to compare | ||
| 953 | /// @return True if they are equal, false otherwise | ||
| 954 | bool operator==(const DriverPrimitive& other) const | ||
| 955 | { | ||
| 956 | if (m_type == other.m_type) | ||
| 957 | { | ||
| 958 | switch (m_type) | ||
| 959 | { | ||
| 960 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: | ||
| 961 | { | ||
| 962 | return m_driverIndex == other.m_driverIndex; | ||
| 963 | } | ||
| 964 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: | ||
| 965 | { | ||
| 966 | return m_driverIndex == other.m_driverIndex && m_hatDirection == other.m_hatDirection; | ||
| 967 | } | ||
| 968 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: | ||
| 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 | } | ||
| 973 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY: | ||
| 974 | { | ||
| 975 | return m_keycode == other.m_keycode; | ||
| 976 | } | ||
| 977 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR: | ||
| 978 | { | ||
| 979 | return m_driverIndex == other.m_driverIndex; | ||
| 980 | } | ||
| 981 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON: | ||
| 982 | { | ||
| 983 | return m_driverIndex == other.m_driverIndex; | ||
| 984 | } | ||
| 985 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION: | ||
| 986 | { | ||
| 987 | return m_relPointerDirection == other.m_relPointerDirection; | ||
| 988 | } | ||
| 989 | default: | ||
| 990 | break; | ||
| 991 | } | ||
| 992 | } | ||
| 993 | return false; | ||
| 994 | } | ||
| 995 | |||
| 996 | ///@} | ||
| 997 | |||
| 998 | explicit DriverPrimitive(const JOYSTICK_DRIVER_PRIMITIVE& primitive) : m_type(primitive.type) | ||
| 999 | { | ||
| 1000 | switch (m_type) | ||
| 1001 | { | ||
| 1002 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: | ||
| 1003 | { | ||
| 1004 | m_driverIndex = primitive.button.index; | ||
| 1005 | break; | ||
| 1006 | } | ||
| 1007 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: | ||
| 1008 | { | ||
| 1009 | m_driverIndex = primitive.hat.index; | ||
| 1010 | m_hatDirection = primitive.hat.direction; | ||
| 1011 | break; | ||
| 1012 | } | ||
| 1013 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: | ||
| 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 | } | ||
| 1021 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR: | ||
| 1022 | { | ||
| 1023 | m_driverIndex = primitive.motor.index; | ||
| 1024 | break; | ||
| 1025 | } | ||
| 1026 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY: | ||
| 1027 | { | ||
| 1028 | m_keycode = primitive.key.keycode; | ||
| 1029 | break; | ||
| 1030 | } | ||
| 1031 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON: | ||
| 1032 | { | ||
| 1033 | m_driverIndex = primitive.mouse.button; | ||
| 1034 | break; | ||
| 1035 | } | ||
| 1036 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION: | ||
| 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 | { | ||
| 1051 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON: | ||
| 1052 | { | ||
| 1053 | driver_primitive.button.index = m_driverIndex; | ||
| 1054 | break; | ||
| 1055 | } | ||
| 1056 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION: | ||
| 1057 | { | ||
| 1058 | driver_primitive.hat.index = m_driverIndex; | ||
| 1059 | driver_primitive.hat.direction = m_hatDirection; | ||
| 1060 | break; | ||
| 1061 | } | ||
| 1062 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS: | ||
| 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 | } | ||
| 1070 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOTOR: | ||
| 1071 | { | ||
| 1072 | driver_primitive.motor.index = m_driverIndex; | ||
| 1073 | break; | ||
| 1074 | } | ||
| 1075 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_KEY: | ||
| 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 | } | ||
| 1082 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_MOUSE_BUTTON: | ||
| 1083 | { | ||
| 1084 | driver_primitive.mouse.button = static_cast<JOYSTICK_DRIVER_MOUSE_INDEX>(m_driverIndex); | ||
| 1085 | break; | ||
| 1086 | } | ||
| 1087 | case JOYSTICK_DRIVER_PRIMITIVE_TYPE_RELPOINTER_DIRECTION: | ||
| 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 | |||
| 1099 | private: | ||
| 1100 | JOYSTICK_DRIVER_PRIMITIVE_TYPE m_type = JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN; | ||
| 1101 | unsigned int m_driverIndex = 0; | ||
| 1102 | JOYSTICK_DRIVER_HAT_DIRECTION m_hatDirection = JOYSTICK_DRIVER_HAT_UNKNOWN; | ||
| 1103 | int m_center = 0; | ||
| 1104 | JOYSTICK_DRIVER_SEMIAXIS_DIRECTION m_semiAxisDirection = JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN; | ||
| 1105 | unsigned int m_range = 1; | ||
| 1106 | std::string m_keycode; | ||
| 1107 | JOYSTICK_DRIVER_RELPOINTER_DIRECTION m_relPointerDirection = JOYSTICK_DRIVER_RELPOINTER_UNKNOWN; | ||
| 1108 | }; | ||
| 1109 | ///@} | ||
| 1110 | //------------------------------------------------------------------------------ | ||
| 1111 | |||
| 1112 | typedef PeripheralVector<DriverPrimitive, JOYSTICK_DRIVER_PRIMITIVE> DriverPrimitives; | ||
| 1113 | |||
| 1114 | //============================================================================== | ||
| 1115 | /// @defgroup cpp_kodi_addon_peripheral_Defs_Joystick_JoystickFeature class JoystickFeature | ||
| 1116 | /// @ingroup cpp_kodi_addon_peripheral_Defs_Joystick | ||
| 1117 | /// @brief **Base class for joystick feature primitives** | ||
| 1118 | /// | ||
| 1119 | /// Class for joystick features. A feature can be: | ||
| 1120 | /// | ||
| 1121 | /// 1. scalar *[1]* | ||
| 1122 | /// 2. analog stick | ||
| 1123 | /// 3. accelerometer | ||
| 1124 | /// 4. motor | ||
| 1125 | /// 5. relative pointer *[2]* | ||
| 1126 | /// 6. absolute pointer | ||
| 1127 | /// 7. wheel | ||
| 1128 | /// 8. throttle | ||
| 1129 | /// 9. keyboard key | ||
| 1130 | /// | ||
| 1131 | /// *[1]* All three driver primitives (buttons, hats and axes) have a state that | ||
| 1132 | /// can be represented using a single scalar value. For this reason, | ||
| 1133 | /// features that map to a single primitive are called "scalar features". | ||
| 1134 | /// | ||
| 1135 | /// *[2]* Relative pointers are similar to analog sticks, but they use | ||
| 1136 | /// relative distances instead of positions. | ||
| 1137 | /// | ||
| 1138 | ///@{ | ||
| 1139 | class JoystickFeature | ||
| 1140 | { | ||
| 1141 | public: | ||
| 1142 | /// @addtogroup cpp_kodi_addon_peripheral_Defs_Joystick_JoystickFeature | ||
| 1143 | ///@{ | ||
| 1144 | |||
| 1145 | /// @brief Class constructor. | ||
| 1146 | /// | ||
| 1147 | /// @param[in] name [optional] Name of the feature | ||
| 1148 | /// @param[in] type [optional] Type of the feature, @ref JOYSTICK_FEATURE_TYPE_UNKNOWN | ||
| 1149 | /// as default | ||
| 1150 | JoystickFeature(const std::string& name = "", | ||
| 1151 | JOYSTICK_FEATURE_TYPE type = JOYSTICK_FEATURE_TYPE_UNKNOWN) | ||
| 1152 | : m_name(name), m_type(type), m_primitives{} | ||
| 1153 | { | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | /// @brief Class copy constructor. | ||
| 1157 | /// | ||
| 1158 | /// @param[in] other Other class to copy on construct here | ||
| 1159 | JoystickFeature(const JoystickFeature& other) { *this = other; } | ||
| 1160 | |||
| 1161 | /// @brief Copy data from another @ref JoystickFeature class to here. | ||
| 1162 | /// | ||
| 1163 | /// @param[in] other Other class to copy here | ||
| 1164 | JoystickFeature& operator=(const JoystickFeature& rhs) | ||
| 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 | |||
| 1175 | /// @brief Compare this with another class of this type. | ||
| 1176 | /// | ||
| 1177 | /// @param[in] other Other class to compare | ||
| 1178 | /// @return True if they are equal, false otherwise | ||
| 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 | |||
| 1184 | /// @brief Get name of feature. | ||
| 1185 | /// | ||
| 1186 | /// @return Name of feature | ||
| 1187 | const std::string& Name(void) const { return m_name; } | ||
| 1188 | |||
| 1189 | /// @brief Get name of feature. | ||
| 1190 | /// | ||
| 1191 | /// @return Type of feature defined with @ref JOYSTICK_FEATURE_TYPE | ||
| 1192 | JOYSTICK_FEATURE_TYPE Type(void) const { return m_type; } | ||
| 1193 | |||
| 1194 | /// @brief Check this feature is valid. | ||
| 1195 | /// | ||
| 1196 | /// @return True if valid (type != JOYSTICK_FEATURE_TYPE_UNKNOWN), false otherwise | ||
| 1197 | bool IsValid() const { return m_type != JOYSTICK_FEATURE_TYPE_UNKNOWN; } | ||
| 1198 | |||
| 1199 | /// @brief Set name of feature. | ||
| 1200 | /// | ||
| 1201 | /// @param[in] name Name of feature | ||
| 1202 | void SetName(const std::string& name) { m_name = name; } | ||
| 1203 | |||
| 1204 | /// @brief Set type of feature. | ||
| 1205 | /// | ||
| 1206 | /// @param[in] type Type of feature | ||
| 1207 | void SetType(JOYSTICK_FEATURE_TYPE type) { m_type = type; } | ||
| 1208 | |||
| 1209 | /// @brief Set type as invalid. | ||
| 1210 | void SetInvalid(void) { m_type = JOYSTICK_FEATURE_TYPE_UNKNOWN; } | ||
| 1211 | |||
| 1212 | /// @brief Get primitive of feature by wanted type. | ||
| 1213 | /// | ||
| 1214 | /// @param[in] which Type of feature, defined with @ref JOYSTICK_FEATURE_PRIMITIVE | ||
| 1215 | /// @return Primitive of asked type | ||
| 1216 | const DriverPrimitive& Primitive(JOYSTICK_FEATURE_PRIMITIVE which) const | ||
| 1217 | { | ||
| 1218 | return m_primitives[which]; | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | /// @brief Set primitive for feature by wanted type. | ||
| 1222 | /// | ||
| 1223 | /// @param[in] which Type of feature, defined with @ref JOYSTICK_FEATURE_PRIMITIVE | ||
| 1224 | /// @param[in] primitive The with @ref DriverPrimitive defined primitive to set | ||
| 1225 | void SetPrimitive(JOYSTICK_FEATURE_PRIMITIVE which, const DriverPrimitive& primitive) | ||
| 1226 | { | ||
| 1227 | m_primitives[which] = primitive; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | /// @brief Get all primitives on this class. | ||
| 1231 | /// | ||
| 1232 | /// @return Array list of primitives | ||
| 1233 | std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() { return m_primitives; } | ||
| 1234 | |||
| 1235 | /// @brief Get all primitives on this class (as constant). | ||
| 1236 | /// | ||
| 1237 | /// @return Constant a´rray list of primitives | ||
| 1238 | const std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX>& Primitives() const | ||
| 1239 | { | ||
| 1240 | return m_primitives; | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | ///@} | ||
| 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 | |||
| 1264 | private: | ||
| 1265 | std::string m_name; | ||
| 1266 | JOYSTICK_FEATURE_TYPE m_type; | ||
| 1267 | std::array<DriverPrimitive, JOYSTICK_PRIMITIVE_MAX> m_primitives; | ||
| 1268 | }; | ||
| 1269 | ///@} | ||
| 1270 | //------------------------------------------------------------------------------ | ||
| 1271 | |||
| 1272 | typedef PeripheralVector<JoystickFeature, JOYSTICK_FEATURE> JoystickFeatures; | ||
| 1273 | |||
| 1274 | } /* namespace addon */ | ||
| 1275 | } /* namespace kodi */ | ||
| 1276 | |||
| 1277 | #endif /* __cplusplus */ | ||
