xbmc
peripheral.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 #ifndef C_API_ADDONINSTANCE_PERIPHERAL_H
10 #define C_API_ADDONINSTANCE_PERIPHERAL_H
11 
12 #include "../addon_base.h"
13 
14 /* indicates a joystick has no preference for port number */
15 #define NO_PORT_REQUESTED (-1)
16 
17 /* joystick's driver button/hat/axis index is unknown */
18 #define DRIVER_INDEX_UNKNOWN (-1)
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif /* __cplusplus */
24 
25  //============================================================================
35  typedef enum PERIPHERAL_ERROR
36  {
39 
42 
45 
48 
51 
54 
59  //----------------------------------------------------------------------------
60 
61  // @name Peripheral types
62  //{
63 
64  //============================================================================
70  typedef enum PERIPHERAL_TYPE
71  {
74 
77 
82  //----------------------------------------------------------------------------
83 
87  typedef struct PERIPHERAL_INFO
88  {
89  PERIPHERAL_TYPE type;
90  char* name;
91  uint16_t vendor_id;
92  uint16_t product_id;
93  unsigned int index;
94  } ATTR_PACKED PERIPHERAL_INFO;
95 
99  typedef struct PERIPHERAL_CAPABILITIES
100  {
102  bool provides_joystick_rumble;
103  bool provides_joystick_power_off;
105  } ATTR_PACKED PERIPHERAL_CAPABILITIES;
106 
107  //}
108 
109  // @name Event types
110  //{
111 
112  //============================================================================
119  {
122 
125 
128 
131 
136  //----------------------------------------------------------------------------
137 
138  //============================================================================
145  {
148 
153  //----------------------------------------------------------------------------
154 
155  //============================================================================
161  typedef enum JOYSTICK_STATE_HAT
162  {
165 
168 
171 
174 
177 
180 
183 
186 
191  //----------------------------------------------------------------------------
192 
193  //============================================================================
201  typedef float JOYSTICK_STATE_AXIS;
202  //----------------------------------------------------------------------------
203 
204  //============================================================================
207  typedef float JOYSTICK_STATE_MOTOR;
208  //----------------------------------------------------------------------------
209 
213  typedef struct PERIPHERAL_EVENT
214  {
216  unsigned int peripheral_index;
217 
219  PERIPHERAL_EVENT_TYPE type;
220 
222  unsigned int driver_index;
223 
224  JOYSTICK_STATE_BUTTON driver_button_state;
225  JOYSTICK_STATE_HAT driver_hat_state;
226  JOYSTICK_STATE_AXIS driver_axis_state;
227  JOYSTICK_STATE_MOTOR motor_state;
228  } ATTR_PACKED PERIPHERAL_EVENT;
229 
230  //}
231 
232  // @name Joystick types
233  //{
234 
238  typedef struct JOYSTICK_INFO
239  {
240  PERIPHERAL_INFO peripheral;
241  char* provider;
243  unsigned int button_count;
244  unsigned int hat_count;
245  unsigned int axis_count;
246  unsigned int motor_count;
248  } ATTR_PACKED JOYSTICK_INFO;
249 
250  //============================================================================
264  {
267 
270 
273 
276 
279 
282 
285 
290  //----------------------------------------------------------------------------
291 
295  typedef struct JOYSTICK_DRIVER_BUTTON
296  {
297  int index;
298  } ATTR_PACKED JOYSTICK_DRIVER_BUTTON;
299 
300  //============================================================================
307  {
310 
313 
316 
319 
324  //----------------------------------------------------------------------------
325 
329  typedef struct JOYSTICK_DRIVER_HAT
330  {
331  int index;
332  JOYSTICK_DRIVER_HAT_DIRECTION direction;
333  } ATTR_PACKED JOYSTICK_DRIVER_HAT;
334 
335  //============================================================================
342  {
345 
348 
353  //----------------------------------------------------------------------------
354 
359  {
360  int index;
361  int center;
363  unsigned int range;
364  } ATTR_PACKED JOYSTICK_DRIVER_SEMIAXIS;
365 
369  typedef struct JOYSTICK_DRIVER_MOTOR
370  {
371  int index;
372  } ATTR_PACKED JOYSTICK_DRIVER_MOTOR;
373 
377  typedef struct JOYSTICK_DRIVER_KEY
378  {
379  char keycode[16];
380  } ATTR_PACKED JOYSTICK_DRIVER_KEY;
381 
382  //============================================================================
389  {
392 
395 
398 
401 
404 
407 
410 
413 
416 
421  //----------------------------------------------------------------------------
422 
427  {
428  JOYSTICK_DRIVER_MOUSE_INDEX button;
429  } ATTR_PACKED JOYSTICK_DRIVER_MOUSE_BUTTON;
430 
431  //============================================================================
438  {
441 
444 
447 
450 
455  //----------------------------------------------------------------------------
456 
461  {
462  JOYSTICK_DRIVER_RELPOINTER_DIRECTION direction;
463  } ATTR_PACKED JOYSTICK_DRIVER_RELPOINTER;
464 
469  {
470  JOYSTICK_DRIVER_PRIMITIVE_TYPE type;
471  union
472  {
473  struct JOYSTICK_DRIVER_BUTTON button;
474  struct JOYSTICK_DRIVER_HAT hat;
475  struct JOYSTICK_DRIVER_SEMIAXIS semiaxis;
476  struct JOYSTICK_DRIVER_MOTOR motor;
477  struct JOYSTICK_DRIVER_KEY key;
478  struct JOYSTICK_DRIVER_MOUSE_BUTTON mouse;
479  struct JOYSTICK_DRIVER_RELPOINTER relpointer;
480  };
481  } ATTR_PACKED JOYSTICK_DRIVER_PRIMITIVE;
482 
483  //============================================================================
494  {
497 
500 
503 
506 
509 
512 
515 
518 
521 
526  //----------------------------------------------------------------------------
527 
528  //============================================================================
536  {
539 
548 
555 
558 
563 
568 
571 
574 
583 
588  //----------------------------------------------------------------------------
589 
593  typedef struct JOYSTICK_FEATURE
594  {
595  char* name;
596  JOYSTICK_FEATURE_TYPE type;
597  struct JOYSTICK_DRIVER_PRIMITIVE primitives[JOYSTICK_PRIMITIVE_MAX];
598  } ATTR_PACKED JOYSTICK_FEATURE;
599  //}
600 
601  typedef struct AddonProps_Peripheral
602  {
603  const char* user_path;
604  const char* addon_path;
605  } ATTR_PACKED AddonProps_Peripheral;
606 
608 
610  {
611  KODI_HANDLE kodiInstance;
612  void (*trigger_scan)(void* kodiInstance);
613  void (*refresh_button_maps)(void* kodiInstance,
614  const char* device_name,
615  const char* controller_id);
616  unsigned int (*feature_count)(void* kodiInstance,
617  const char* controller_id,
618  JOYSTICK_FEATURE_TYPE type);
619  JOYSTICK_FEATURE_TYPE(*feature_type)
620  (void* kodiInstance, const char* controller_id, const char* feature_name);
622 
624 
626  {
627  KODI_HANDLE addonInstance;
628 
629  void(__cdecl* get_capabilities)(const struct AddonInstance_Peripheral* addonInstance,
630  struct PERIPHERAL_CAPABILITIES* capabilities);
631  PERIPHERAL_ERROR(__cdecl* perform_device_scan)
632  (const struct AddonInstance_Peripheral* addonInstance,
633  unsigned int* peripheral_count,
634  struct PERIPHERAL_INFO** scan_results);
635  void(__cdecl* free_scan_results)(const struct AddonInstance_Peripheral* addonInstance,
636  unsigned int peripheral_count,
637  struct PERIPHERAL_INFO* scan_results);
638  PERIPHERAL_ERROR(__cdecl* get_events)
639  (const struct AddonInstance_Peripheral* addonInstance,
640  unsigned int* event_count,
641  struct PERIPHERAL_EVENT** events);
642  void(__cdecl* free_events)(const struct AddonInstance_Peripheral* addonInstance,
643  unsigned int event_count,
644  struct PERIPHERAL_EVENT* events);
645  bool(__cdecl* send_event)(const struct AddonInstance_Peripheral* addonInstance,
646  const struct PERIPHERAL_EVENT* event);
647 
650  PERIPHERAL_ERROR(__cdecl* get_joystick_info)
651  (const struct AddonInstance_Peripheral* addonInstance,
652  unsigned int index,
653  struct JOYSTICK_INFO* info);
654  void(__cdecl* free_joystick_info)(const struct AddonInstance_Peripheral* addonInstance,
655  struct JOYSTICK_INFO* info);
656  PERIPHERAL_ERROR(__cdecl* get_features)
657  (const struct AddonInstance_Peripheral* addonInstance,
658  const struct JOYSTICK_INFO* joystick,
659  const char* controller_id,
660  unsigned int* feature_count,
661  struct JOYSTICK_FEATURE** features);
662  void(__cdecl* free_features)(const struct AddonInstance_Peripheral* addonInstance,
663  unsigned int feature_count,
664  struct JOYSTICK_FEATURE* features);
665  PERIPHERAL_ERROR(__cdecl* map_features)
666  (const struct AddonInstance_Peripheral* addonInstance,
667  const struct JOYSTICK_INFO* joystick,
668  const char* controller_id,
669  unsigned int feature_count,
670  const struct JOYSTICK_FEATURE* features);
671  PERIPHERAL_ERROR(__cdecl* get_ignored_primitives)
672  (const struct AddonInstance_Peripheral* addonInstance,
673  const struct JOYSTICK_INFO* joystick,
674  unsigned int* feature_count,
675  struct JOYSTICK_DRIVER_PRIMITIVE** primitives);
676  void(__cdecl* free_primitives)(const struct AddonInstance_Peripheral* addonInstance,
677  unsigned int,
678  struct JOYSTICK_DRIVER_PRIMITIVE* primitives);
679  PERIPHERAL_ERROR(__cdecl* set_ignored_primitives)
680  (const struct AddonInstance_Peripheral* addonInstance,
681  const struct JOYSTICK_INFO* joystick,
682  unsigned int primitive_count,
683  const struct JOYSTICK_DRIVER_PRIMITIVE* primitives);
684  void(__cdecl* save_button_map)(const struct AddonInstance_Peripheral* addonInstance,
685  const struct JOYSTICK_INFO* joystick);
686  void(__cdecl* revert_button_map)(const struct AddonInstance_Peripheral* addonInstance,
687  const struct JOYSTICK_INFO* joystick);
688  void(__cdecl* reset_button_map)(const struct AddonInstance_Peripheral* addonInstance,
689  const struct JOYSTICK_INFO* joystick,
690  const char* controller_id);
691  void(__cdecl* power_off_joystick)(const struct AddonInstance_Peripheral* addonInstance,
692  unsigned int index);
695 
697  {
698  struct AddonProps_Peripheral* props;
699  struct AddonToKodiFuncTable_Peripheral* toKodi;
700  struct KodiToAddonFuncTable_Peripheral* toAddon;
702 
703 #ifdef __cplusplus
704 } /* extern "C" */
705 #endif /* __cplusplus */
706 
707 #endif /* !C_API_ADDONINSTANCE_PERIPHERAL_H */
Type accelerometer.
Definition: peripheral.h:505
Button primitive.
Definition: peripheral.h:295
Relative pointer direction right.
Definition: peripheral.h:580
right and up is pressed
Definition: peripheral.h:185
uint16_t vendor_id
Definition: peripheral.h:91
Relative pointer direction left.
Definition: peripheral.h:443
Driver input primitive type mouse button.
Definition: peripheral.h:284
Definition: peripheral.h:601
Maximum number of primitives.
Definition: peripheral.h:585
JOYSTICK_FEATURE_PRIMITIVE
Definition: peripheral.h:535
button is released
Definition: peripheral.h:147
Driver input primitive type semiaxis.
Definition: peripheral.h:275
Information shared between peripherals.
Definition: peripheral.h:87
Relative pointer direction down.
Definition: peripheral.h:452
Relative pointer direction down.
Definition: peripheral.h:578
Wheel left.
Definition: peripheral.h:560
Semiaxis primitive.
Definition: peripheral.h:358
Mouse index unknown.
Definition: peripheral.h:391
bool provides_buttonmaps
Definition: peripheral.h:104
Peripheral add-on capabilities.
Definition: peripheral.h:99
char * provider
name of the driver or interface providing the joystick
Definition: peripheral.h:241
Mouse index wheel up.
Definition: peripheral.h:409
PERIPHERAL_TYPE
Definition: peripheral.h:70
PERIPHERAL_ERROR
Definition: peripheral.h:35
Type throttle.
Definition: peripheral.h:520
Driver hat up.
Definition: peripheral.h:318
Relative pointer direction unknown.
Definition: peripheral.h:440
Accelerometer Y.
Definition: peripheral.h:552
only up is pressed
Definition: peripheral.h:173
Motor.
Definition: peripheral.h:557
bool provides_joysticks
Definition: peripheral.h:101
Throttle down.
Definition: peripheral.h:567
Wheel right.
Definition: peripheral.h:562
Mouse index horizontal wheel left.
Definition: peripheral.h:415
Throttle up.
Definition: peripheral.h:565
Type analog stick.
Definition: peripheral.h:502
Type relative pointer.
Definition: peripheral.h:511
left and down is pressed
Definition: peripheral.h:182
Unknown type.
Definition: peripheral.h:496
Definition: peripheral.h:625
only left is pressed
Definition: peripheral.h:167
JOYSTICK_STATE_BUTTON
Definition: peripheral.h:144
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
Definition: peripheral.h:341
JOYSTICK_DRIVER_MOUSE_INDEX
Definition: peripheral.h:388
Type declared as unknown.
Definition: peripheral.h:73
Analog stick up.
Definition: peripheral.h:541
Analog stick down.
Definition: peripheral.h:543
Analog stick right.
Definition: peripheral.h:545
PERIPHERAL_INFO peripheral
peripheral info for this joystick
Definition: peripheral.h:240
left and up is pressed
Definition: peripheral.h:179
Accelerometer Z.
Definition: peripheral.h:554
Event information.
Definition: peripheral.h:213
Driver hat right.
Definition: peripheral.h:315
JOYSTICK_FEATURE_TYPE
Definition: peripheral.h:493
Driver input primitive type button.
Definition: peripheral.h:269
Driver input primitive type motor.
Definition: peripheral.h:278
Relative pointer direction primitive.
Definition: peripheral.h:460
Mouse button.
Definition: peripheral.h:573
const char * addon_path
path to this add-on
Definition: peripheral.h:604
Mouse index button 5.
Definition: peripheral.h:406
uint16_t product_id
Definition: peripheral.h:92
Analog stick left.
Definition: peripheral.h:547
Type key.
Definition: peripheral.h:523
Mouse index button 4.
Definition: peripheral.h:403
state changed for joystick driver hat
Definition: peripheral.h:127
-3 : The parameters of the method are invalid for this operation
Definition: peripheral.h:47
negative half of the axis
Definition: peripheral.h:344
PERIPHERAL_EVENT_TYPE type
Type of the event used to determine which enum field to access below.
Definition: peripheral.h:219
JOYSTICK_DRIVER_RELPOINTER_DIRECTION
Definition: peripheral.h:437
JOYSTICK_STATE_HAT
Definition: peripheral.h:161
Driver hat down.
Definition: peripheral.h:321
int requested_port
requested port number (such as for 360 controllers), or NO_PORT_REQUESTED
Definition: peripheral.h:242
PERIPHERAL_TYPE type
Definition: peripheral.h:89
Type wheel.
Definition: peripheral.h:517
Driver input primitive type unknown.
Definition: peripheral.h:266
Key.
Definition: peripheral.h:570
JOYSTICK_DRIVER_HAT_DIRECTION
Definition: peripheral.h:306
-5 : No peripherals are connected
Definition: peripheral.h:53
Mouse index left.
Definition: peripheral.h:394
Driver input primitive type key.
Definition: peripheral.h:281
-6 : Peripherals are connected, but command was interrupted
Definition: peripheral.h:56
no directions are pressed
Definition: peripheral.h:164
unsigned int index
Definition: peripheral.h:93
unsigned int peripheral_index
Index of the peripheral handling/receiving the event.
Definition: peripheral.h:216
Mouse index horizontal wheel right.
Definition: peripheral.h:418
unsigned int hat_count
number of hats reported by the driver
Definition: peripheral.h:244
Driver primitive struct.
Definition: peripheral.h:468
Accelerometer X.
Definition: peripheral.h:550
Relative pointer direction right.
Definition: peripheral.h:446
button is pressed
Definition: peripheral.h:150
PERIPHERAL_EVENT_TYPE
Definition: peripheral.h:118
Info specific to joystick peripherals.
Definition: peripheral.h:238
right and down is pressed
Definition: peripheral.h:188
Type declared as keyboard.
Definition: peripheral.h:79
positive half of the axis
Definition: peripheral.h:350
Scalar feature (a button, hat direction or semiaxis)
Definition: peripheral.h:538
Mouse index wheel down.
Definition: peripheral.h:412
Definition: peripheral.h:609
Type motor.
Definition: peripheral.h:508
state changed for joystick driver axis
Definition: peripheral.h:130
only down is pressed
Definition: peripheral.h:176
JOYSTICK_DRIVER_PRIMITIVE_TYPE
Definition: peripheral.h:263
set the state for joystick rumble motor
Definition: peripheral.h:133
-1 : An unknown error occurred
Definition: peripheral.h:41
Mapping between higher-level controller feature and its driver primitives.
Definition: peripheral.h:593
state changed for joystick driver button
Definition: peripheral.h:124
bool supports_poweroff
whether the joystick supports being powered off
Definition: peripheral.h:247
Mouse button primitive.
Definition: peripheral.h:426
-4 : The method that the frontend called is not implemented
Definition: peripheral.h:50
unsigned int button_count
number of buttons reported by the driver
Definition: peripheral.h:243
Driver input primitive type hat direction.
Definition: peripheral.h:272
unknown event
Definition: peripheral.h:121
Relative pointer direction up.
Definition: peripheral.h:576
Driver input primitive type relative pointer direction.
Definition: peripheral.h:287
unsigned int motor_count
number of motors reported by the driver
Definition: peripheral.h:246
Mouse index right.
Definition: peripheral.h:397
only right is pressed
Definition: peripheral.h:170
Type scalar.
Definition: peripheral.h:499
Type absolute pointer.
Definition: peripheral.h:514
Driver hat left.
Definition: peripheral.h:312
Driver hat unknown.
Definition: peripheral.h:309
Keyboard key primitive.
Definition: peripheral.h:377
const char * user_path
path to the user profile
Definition: peripheral.h:603
unsigned int axis_count
number of axes reported by the driver
Definition: peripheral.h:245
Type declared as joystick.
Definition: peripheral.h:76
Motor primitive.
Definition: peripheral.h:369
Relative pointer direction left.
Definition: peripheral.h:582
-2 : The command failed
Definition: peripheral.h:44
Hat direction primitive.
Definition: peripheral.h:329
unknown direction
Definition: peripheral.h:347
Definition: peripheral.h:696
0 : No error occurred
Definition: peripheral.h:38
Mouse index middle.
Definition: peripheral.h:400
char * name
Definition: peripheral.h:90
unsigned int driver_index
The index of the event source.
Definition: peripheral.h:222
Relative pointer direction up.
Definition: peripheral.h:449