summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2016-03-14 14:56:55 +0100
committermanuel <manuel@mausz.at>2016-03-14 14:56:55 +0100
commit4b3b7807b7df1964778855b5c0daab4cc417bd91 (patch)
tree2d801f7ee868f6b6be5221bc2674eaf95f0e7074 /xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp
parent1e0e2df2619a2c7fdc20806884eb81f36d458c61 (diff)
downloadkodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.tar.gz
kodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.tar.bz2
kodi-pvr-build-4b3b7807b7df1964778855b5c0daab4cc417bd91.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp657
1 files changed, 657 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp
new file mode 100644
index 0000000..4423cb4
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/kodi_peripheral_utils.hpp
@@ -0,0 +1,657 @@
1/*
2 * Copyright (C) 2014-2016 Team Kodi
3 * http://kodi.tv
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this Program; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20#pragma once
21
22#include "kodi_peripheral_types.h"
23
24#include <cstring>
25#include <map>
26#include <string>
27#include <vector>
28
29#define PERIPHERAL_SAFE_DELETE(x) do { delete (x); (x) = NULL; } while (0)
30#define PERIPHERAL_SAFE_DELETE_ARRAY(x) do { delete[] (x); (x) = NULL; } while (0)
31
32namespace ADDON
33{
34 /*!
35 * Utility class to manipulate arrays of peripheral types.
36 */
37 template <class THE_CLASS, typename THE_STRUCT>
38 class PeripheralVector
39 {
40 public:
41 static void ToStructs(const std::vector<THE_CLASS>& vecObjects, THE_STRUCT** pStructs)
42 {
43 if (!pStructs)
44 return;
45
46 if (vecObjects.empty())
47 {
48 *pStructs = NULL;
49 }
50 else
51 {
52 (*pStructs) = new THE_STRUCT[vecObjects.size()];
53 for (unsigned int i = 0; i < vecObjects.size(); i++)
54 vecObjects.at(i).ToStruct((*pStructs)[i]);
55 }
56 }
57
58 static void ToStructs(const std::vector<THE_CLASS*>& vecObjects, THE_STRUCT** pStructs)
59 {
60 if (!pStructs)
61 return;
62
63 if (vecObjects.empty())
64 {
65 *pStructs = NULL;
66 }
67 else
68 {
69 *pStructs = new THE_STRUCT[vecObjects.size()];
70 for (unsigned int i = 0; i < vecObjects.size(); i++)
71 vecObjects.at(i)->ToStruct((*pStructs)[i]);
72 }
73 }
74
75 static void FreeStructs(unsigned int structCount, THE_STRUCT* structs)
76 {
77 if (structs)
78 {
79 for (unsigned int i = 0; i < structCount; i++)
80 THE_CLASS::FreeStruct(structs[i]);
81 }
82 PERIPHERAL_SAFE_DELETE_ARRAY(structs);
83 }
84 };
85
86 /*!
87 * ADDON::Peripheral
88 *
89 * Wrapper class providing peripheral information. Classes can extend
90 * Peripheral to inherit peripheral properties.
91 */
92 class Peripheral
93 {
94 public:
95 Peripheral(PERIPHERAL_TYPE type = PERIPHERAL_TYPE_UNKNOWN, const std::string& strName = "") :
96 m_type(type),
97 m_strName(strName),
98 m_vendorId(0),
99 m_productId(0),
100 m_index(0)
101 {
102 }
103
104 Peripheral(const PERIPHERAL_INFO& info) :
105 m_type(info.type),
106 m_strName(info.name ? info.name : ""),
107 m_vendorId(info.vendor_id),
108 m_productId(info.product_id),
109 m_index(info.index)
110 {
111 }
112
113 virtual ~Peripheral(void) { }
114
115 PERIPHERAL_TYPE Type(void) const { return m_type; }
116 const std::string& Name(void) const { return m_strName; }
117 uint16_t VendorID(void) const { return m_vendorId; }
118 uint16_t ProductID(void) const { return m_productId; }
119 unsigned int Index(void) const { return m_index; }
120
121 // Derived property: VID and PID are 0x0000 if unknown
122 bool IsVidPidKnown(void) const { return m_vendorId != 0 || m_productId != 0; }
123
124 void SetType(PERIPHERAL_TYPE type) { m_type = type; }
125 void SetName(const std::string& strName) { m_strName = strName; }
126 void SetVendorID(uint16_t vendorId) { m_vendorId = vendorId; }
127 void SetProductID(uint16_t productId) { m_productId = productId; }
128 void SetIndex(unsigned int index) { m_index = index; }
129
130 void ToStruct(PERIPHERAL_INFO& info) const
131 {
132 info.type = m_type;
133 info.name = new char[m_strName.size() + 1];
134 info.vendor_id = m_vendorId;
135 info.product_id = m_productId;
136 info.index = m_index;
137
138 std::strcpy(info.name, m_strName.c_str());
139 }
140
141 static void FreeStruct(PERIPHERAL_INFO& info)
142 {
143 PERIPHERAL_SAFE_DELETE_ARRAY(info.name);
144 }
145
146 private:
147 PERIPHERAL_TYPE m_type;
148 std::string m_strName;
149 uint16_t m_vendorId;
150 uint16_t m_productId;
151 unsigned int m_index;
152 };
153
154 typedef PeripheralVector<Peripheral, PERIPHERAL_INFO> Peripherals;
155
156 /*!
157 * ADDON::PeripheralEvent
158 *
159 * Wrapper class for peripheral events.
160 */
161 class PeripheralEvent
162 {
163 public:
164 PeripheralEvent(void) :
165 m_event()
166 {
167 }
168
169 PeripheralEvent(unsigned int peripheralIndex, unsigned int buttonIndex, JOYSTICK_STATE_BUTTON state) :
170 m_event()
171 {
172 SetType(PERIPHERAL_EVENT_TYPE_DRIVER_BUTTON);
173 SetPeripheralIndex(peripheralIndex);
174 SetDriverIndex(buttonIndex);
175 SetButtonState(state);
176 }
177
178 PeripheralEvent(unsigned int peripheralIndex, unsigned int hatIndex, JOYSTICK_STATE_HAT state) :
179 m_event()
180 {
181 SetType(PERIPHERAL_EVENT_TYPE_DRIVER_HAT);
182 SetPeripheralIndex(peripheralIndex);
183 SetDriverIndex(hatIndex);
184 SetHatState(state);
185 }
186
187 PeripheralEvent(unsigned int peripheralIndex, unsigned int axisIndex, JOYSTICK_STATE_AXIS state) :
188 m_event()
189 {
190 SetType(PERIPHERAL_EVENT_TYPE_DRIVER_AXIS);
191 SetPeripheralIndex(peripheralIndex);
192 SetDriverIndex(axisIndex);
193 SetAxisState(state);
194 }
195
196 PeripheralEvent(const PERIPHERAL_EVENT& event) :
197 m_event(event)
198 {
199 }
200
201 PERIPHERAL_EVENT_TYPE Type(void) const { return m_event.type; }
202 unsigned int PeripheralIndex(void) const { return m_event.peripheral_index; }
203 unsigned int DriverIndex(void) const { return m_event.driver_index; }
204 JOYSTICK_STATE_BUTTON ButtonState(void) const { return m_event.driver_button_state; }
205 JOYSTICK_STATE_HAT HatState(void) const { return m_event.driver_hat_state; }
206 JOYSTICK_STATE_AXIS AxisState(void) const { return m_event.driver_axis_state; }
207
208 void SetType(PERIPHERAL_EVENT_TYPE type) { m_event.type = type; }
209 void SetPeripheralIndex(unsigned int index) { m_event.peripheral_index = index; }
210 void SetDriverIndex(unsigned int index) { m_event.driver_index = index; }
211 void SetButtonState(JOYSTICK_STATE_BUTTON state) { m_event.driver_button_state = state; }
212 void SetHatState(JOYSTICK_STATE_HAT state) { m_event.driver_hat_state = state; }
213 void SetAxisState(JOYSTICK_STATE_AXIS state) { m_event.driver_axis_state = state; }
214
215 void ToStruct(PERIPHERAL_EVENT& event) const
216 {
217 event = m_event;
218 }
219
220 static void FreeStruct(PERIPHERAL_EVENT& event)
221 {
222 (void)event;
223 }
224
225 private:
226 PERIPHERAL_EVENT m_event;
227 };
228
229 typedef PeripheralVector<PeripheralEvent, PERIPHERAL_EVENT> PeripheralEvents;
230
231 /*!
232 * ADDON::Joystick
233 *
234 * Wrapper class providing additional joystick information not provided by
235 * ADDON::Peripheral.
236 */
237 class Joystick : public Peripheral
238 {
239 public:
240 Joystick(const std::string& provider = "", const std::string& strName = "") :
241 Peripheral(PERIPHERAL_TYPE_JOYSTICK, strName),
242 m_provider(provider),
243 m_requestedPort(NO_PORT_REQUESTED),
244 m_buttonCount(0),
245 m_hatCount(0),
246 m_axisCount(0)
247 {
248 }
249
250 Joystick(const Joystick& other)
251 {
252 *this = other;
253 }
254
255 Joystick(const JOYSTICK_INFO& info) :
256 Peripheral(info.peripheral),
257 m_provider(info.provider ? info.provider : ""),
258 m_requestedPort(info.requested_port),
259 m_buttonCount(info.button_count),
260 m_hatCount(info.hat_count),
261 m_axisCount(info.axis_count)
262 {
263 }
264
265 virtual ~Joystick(void) { }
266
267 Joystick& operator=(const Joystick& rhs)
268 {
269 if (this != &rhs)
270 {
271 Peripheral::operator=(rhs);
272
273 m_provider = rhs.m_provider;
274 m_requestedPort = rhs.m_requestedPort;
275 m_buttonCount = rhs.m_buttonCount;
276 m_hatCount = rhs.m_hatCount;
277 m_axisCount = rhs.m_axisCount;
278 }
279 return *this;
280 }
281
282 const std::string& Provider(void) const { return m_provider; }
283 int RequestedPort(void) const { return m_requestedPort; }
284 unsigned int ButtonCount(void) const { return m_buttonCount; }
285 unsigned int HatCount(void) const { return m_hatCount; }
286 unsigned int AxisCount(void) const { return m_axisCount; }
287
288 // Derived property: Counts are unknown if all are zero
289 bool AreElementCountsKnown(void) const { return m_buttonCount != 0 || m_hatCount != 0 || m_axisCount != 0; }
290
291 void SetProvider(const std::string& provider) { m_provider = provider; }
292 void SetRequestedPort(int requestedPort) { m_requestedPort = requestedPort; }
293 void SetButtonCount(unsigned int buttonCount) { m_buttonCount = buttonCount; }
294 void SetHatCount(unsigned int hatCount) { m_hatCount = hatCount; }
295 void SetAxisCount(unsigned int axisCount) { m_axisCount = axisCount; }
296
297 void ToStruct(JOYSTICK_INFO& info) const
298 {
299 Peripheral::ToStruct(info.peripheral);
300
301 info.provider = new char[m_provider.size() + 1];
302 info.requested_port = m_requestedPort;
303 info.button_count = m_buttonCount;
304 info.hat_count = m_hatCount;
305 info.axis_count = m_axisCount;
306
307 std::strcpy(info.provider, m_provider.c_str());
308 }
309
310 static void FreeStruct(JOYSTICK_INFO& info)
311 {
312 Peripheral::FreeStruct(info.peripheral);
313
314 PERIPHERAL_SAFE_DELETE_ARRAY(info.provider);
315 }
316
317 private:
318 std::string m_provider;
319 int m_requestedPort;
320 unsigned int m_buttonCount;
321 unsigned int m_hatCount;
322 unsigned int m_axisCount;
323 };
324
325 typedef PeripheralVector<Joystick, JOYSTICK_INFO> Joysticks;
326
327 /*!
328 * ADDON::DriverPrimitive
329 *
330 * Base class for joystick driver primitives. A driver primitive can be:
331 *
332 * 1) a button
333 * 2) a hat direction
334 * 3) a semiaxis (either the positive or negative half of an axis)
335 *
336 * The type determines the fields in use:
337 *
338 * Button:
339 * - driver index
340 *
341 * Hat direction:
342 * - driver index
343 * - hat direction
344 *
345 * Semiaxis:
346 * - driver index
347 * - semiaxis direction
348 */
349 class DriverPrimitive
350 {
351 public:
352 /*!
353 * \brief Construct an invalid driver primitive
354 */
355 DriverPrimitive(void) :
356 m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_UNKNOWN),
357 m_driverIndex(0),
358 m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN),
359 m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN)
360 {
361 }
362
363 /*!
364 * \brief Construct a driver primitive representing a button
365 */
366 DriverPrimitive(unsigned int buttonIndex) :
367 m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON),
368 m_driverIndex(buttonIndex),
369 m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN),
370 m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN)
371 {
372 }
373
374 /*!
375 * \brief Construct a driver primitive representing one of the four direction
376 * arrows on a dpad
377 */
378 DriverPrimitive(unsigned int hatIndex, JOYSTICK_DRIVER_HAT_DIRECTION direction) :
379 m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION),
380 m_driverIndex(hatIndex),
381 m_hatDirection(direction),
382 m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN)
383 {
384 }
385
386 /*!
387 * \brief Construct a driver primitive representing the positive or negative
388 * half of an axis
389 */
390 DriverPrimitive(unsigned int axisIndex, JOYSTICK_DRIVER_SEMIAXIS_DIRECTION direction) :
391 m_type(JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS),
392 m_driverIndex(axisIndex),
393 m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN),
394 m_semiAxisDirection(direction)
395 {
396 }
397
398 DriverPrimitive(const JOYSTICK_DRIVER_PRIMITIVE& primitive) :
399 m_type(primitive.type),
400 m_driverIndex(0),
401 m_hatDirection(JOYSTICK_DRIVER_HAT_UNKNOWN),
402 m_semiAxisDirection(JOYSTICK_DRIVER_SEMIAXIS_UNKNOWN)
403 {
404 switch (m_type)
405 {
406 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON:
407 {
408 m_driverIndex = primitive.button.index;
409 break;
410 }
411 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION:
412 {
413 m_driverIndex = primitive.hat.index;
414 m_hatDirection = primitive.hat.direction;
415 break;
416 }
417 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS:
418 {
419 m_driverIndex = primitive.semiaxis.index;
420 m_semiAxisDirection = primitive.semiaxis.direction;
421 break;
422 }
423 default:
424 break;
425 }
426 }
427
428 JOYSTICK_DRIVER_PRIMITIVE_TYPE Type(void) const { return m_type; }
429 unsigned int DriverIndex(void) const { return m_driverIndex; }
430 JOYSTICK_DRIVER_HAT_DIRECTION HatDirection(void) const { return m_hatDirection; }
431 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION SemiAxisDirection(void) const { return m_semiAxisDirection; }
432
433 bool operator==(const DriverPrimitive& other) const
434 {
435 if (m_type == other.m_type)
436 {
437 switch (m_type)
438 {
439 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON:
440 {
441 return m_driverIndex == other.m_driverIndex;
442 }
443 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION:
444 {
445 return m_driverIndex == other.m_driverIndex &&
446 m_hatDirection == other.m_hatDirection;
447 }
448 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS:
449 {
450 return m_driverIndex == other.m_driverIndex &&
451 m_semiAxisDirection == other.m_semiAxisDirection;
452 }
453 default:
454 break;
455 }
456 }
457 return false;
458 }
459
460 void ToStruct(JOYSTICK_DRIVER_PRIMITIVE& driver_primitive) const
461 {
462 driver_primitive.type = m_type;
463 switch (m_type)
464 {
465 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_BUTTON:
466 {
467 driver_primitive.button.index = m_driverIndex;
468 break;
469 }
470 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_HAT_DIRECTION:
471 {
472 driver_primitive.hat.index = m_driverIndex;
473 driver_primitive.hat.direction = m_hatDirection;
474 break;
475 }
476 case JOYSTICK_DRIVER_PRIMITIVE_TYPE_SEMIAXIS:
477 {
478 driver_primitive.semiaxis.index = m_driverIndex;
479 driver_primitive.semiaxis.direction = m_semiAxisDirection;
480 break;
481 }
482 default:
483 break;
484 }
485 }
486
487 private:
488 JOYSTICK_DRIVER_PRIMITIVE_TYPE m_type;
489 unsigned int m_driverIndex;
490 JOYSTICK_DRIVER_HAT_DIRECTION m_hatDirection;
491 JOYSTICK_DRIVER_SEMIAXIS_DIRECTION m_semiAxisDirection;
492 };
493
494 /*!
495 * ADDON::JoystickFeature
496 *
497 * Class for joystick features. A feature can be:
498 *
499 * 1) scalar[1]
500 * 2) analog stick
501 * 3) accelerometer
502 *
503 * [1] All three driver primitives (buttons, hats and axes) have a state that
504 * can be represented using a single scalar value. For this reason,
505 * features that map to a single primitive are called "scalar features".
506 *
507 * Features can be mapped to a variable number of driver primitives. The names
508 * of the primitives for each feature are:
509 *
510 * Scalar feature:
511 * - primitive
512 *
513 * Analog stick:
514 * - up
515 * - down
516 * - right
517 * - left
518 *
519 * Accelerometer:
520 * - positive X
521 * - positive Y
522 * - positive Z
523 */
524 class JoystickFeature
525 {
526 public:
527 const unsigned int MAX_PRIMITIVES = 4;
528
529 JoystickFeature(void) :
530 m_type(JOYSTICK_FEATURE_TYPE_UNKNOWN)
531 {
532 m_primitives.resize(MAX_PRIMITIVES);
533 }
534
535 JoystickFeature(const std::string& name, JOYSTICK_FEATURE_TYPE type) :
536 m_name(name),
537 m_type(type)
538 {
539 m_primitives.resize(MAX_PRIMITIVES);
540 }
541
542 JoystickFeature(const JoystickFeature& other)
543 {
544 *this = other;
545 }
546
547 JoystickFeature(const JOYSTICK_FEATURE& feature) :
548 m_name(feature.name ? feature.name : ""),
549 m_type(feature.type)
550 {
551 m_primitives.resize(MAX_PRIMITIVES);
552 switch (m_type)
553 {
554 case JOYSTICK_FEATURE_TYPE_SCALAR:
555 SetPrimitive(feature.scalar.primitive);
556 break;
557 case JOYSTICK_FEATURE_TYPE_ANALOG_STICK:
558 SetUp(feature.analog_stick.up);
559 SetDown(feature.analog_stick.down);
560 SetRight(feature.analog_stick.right);
561 SetLeft(feature.analog_stick.left);
562 break;
563 case JOYSTICK_FEATURE_TYPE_ACCELEROMETER:
564 SetPositiveX(feature.accelerometer.positive_x);
565 SetPositiveY(feature.accelerometer.positive_y);
566 SetPositiveZ(feature.accelerometer.positive_z);
567 break;
568 default:
569 break;
570 }
571 }
572
573 JoystickFeature& operator=(const JoystickFeature& rhs)
574 {
575 if (this != &rhs)
576 {
577 m_name = rhs.m_name;
578 m_type = rhs.m_type;
579 m_primitives = rhs.m_primitives;
580 }
581 return *this;
582 }
583
584 bool operator==(const JoystickFeature& other) const
585 {
586 return m_name == other.m_name &&
587 m_type == other.m_type &&
588 m_primitives == other.m_primitives;
589 }
590
591 const std::string& Name(void) const { return m_name; }
592 JOYSTICK_FEATURE_TYPE Type(void) const { return m_type; }
593
594 void SetName(const std::string& name) { m_name = name; }
595 void SetType(JOYSTICK_FEATURE_TYPE type) { m_type = type; }
596
597 // Scalar methods
598 const DriverPrimitive& Primitive(void) const { return m_primitives[0]; }
599 void SetPrimitive(const DriverPrimitive& primitive) { m_primitives[0] = primitive; }
600
601 // Analog stick methods
602 const DriverPrimitive& Up(void) const { return m_primitives[0]; }
603 const DriverPrimitive& Down(void) const { return m_primitives[1]; }
604 const DriverPrimitive& Right(void) const { return m_primitives[2]; }
605 const DriverPrimitive& Left(void) const { return m_primitives[3]; }
606 void SetUp(const DriverPrimitive& primitive) { m_primitives[0] = primitive; }
607 void SetDown(const DriverPrimitive& primitive) { m_primitives[1] = primitive; }
608 void SetRight(const DriverPrimitive& primitive) { m_primitives[2] = primitive; }
609 void SetLeft(const DriverPrimitive& primitive) { m_primitives[3] = primitive; }
610
611 // Accelerometer methods
612 const DriverPrimitive& PositiveX(void) const { return m_primitives[0]; }
613 const DriverPrimitive& PositiveY(void) const { return m_primitives[1]; }
614 const DriverPrimitive& PositiveZ(void) const { return m_primitives[2]; }
615 void SetPositiveX(const DriverPrimitive& primitive) { m_primitives[0] = primitive; }
616 void SetPositiveY(const DriverPrimitive& primitive) { m_primitives[1] = primitive; }
617 void SetPositiveZ(const DriverPrimitive& primitive) { m_primitives[2] = primitive; }
618
619 void ToStruct(JOYSTICK_FEATURE& feature) const
620 {
621 feature.name = new char[m_name.length() + 1];
622 feature.type = m_type;
623 switch (m_type)
624 {
625 case JOYSTICK_FEATURE_TYPE_SCALAR:
626 Primitive().ToStruct(feature.scalar.primitive);
627 break;
628 case JOYSTICK_FEATURE_TYPE_ANALOG_STICK:
629 Up().ToStruct(feature.analog_stick.up);
630 Down().ToStruct(feature.analog_stick.down);
631 Right().ToStruct(feature.analog_stick.right);
632 Left().ToStruct(feature.analog_stick.left);
633 break;
634 case JOYSTICK_FEATURE_TYPE_ACCELEROMETER:
635 PositiveX().ToStruct(feature.accelerometer.positive_x);
636 PositiveY().ToStruct(feature.accelerometer.positive_y);
637 PositiveZ().ToStruct(feature.accelerometer.positive_z);
638 break;
639 default:
640 break;
641 }
642 std::strcpy(feature.name, m_name.c_str());
643 }
644
645 static void FreeStruct(JOYSTICK_FEATURE& feature)
646 {
647 PERIPHERAL_SAFE_DELETE_ARRAY(feature.name);
648 }
649
650 private:
651 std::string m_name;
652 JOYSTICK_FEATURE_TYPE m_type;
653 std::vector<DriverPrimitive> m_primitives;
654 };
655
656 typedef PeripheralVector<JoystickFeature, JOYSTICK_FEATURE> JoystickFeatures;
657}