kodi
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 
80 
85  //----------------------------------------------------------------------------
86 
90  typedef struct PERIPHERAL_INFO
91  {
92  PERIPHERAL_TYPE type;
93  char* name;
94  uint16_t vendor_id;
95  uint16_t product_id;
96  unsigned int index;
97  } ATTR_PACKED PERIPHERAL_INFO;
98 
102  typedef struct PERIPHERAL_CAPABILITIES
103  {
105  bool provides_joystick_rumble;
106  bool provides_joystick_power_off;
108  } ATTR_PACKED PERIPHERAL_CAPABILITIES;
109 
110  //}
111 
112  // @name Event types
113  //{
114 
115  //============================================================================
122  {
125 
128 
131 
134 
139  //----------------------------------------------------------------------------
140 
141  //============================================================================
148  {
151 
156  //----------------------------------------------------------------------------
157 
158  //============================================================================
164  typedef enum JOYSTICK_STATE_HAT
165  {
168 
171 
174 
177 
180 
183 
186 
189 
194  //----------------------------------------------------------------------------
195 
196  //============================================================================
204  typedef float JOYSTICK_STATE_AXIS;
205  //----------------------------------------------------------------------------
206 
207  //============================================================================
210  typedef float JOYSTICK_STATE_MOTOR;
211  //----------------------------------------------------------------------------
212 
216  typedef struct PERIPHERAL_EVENT
217  {
219  unsigned int peripheral_index;
220 
222  PERIPHERAL_EVENT_TYPE type;
223 
225  unsigned int driver_index;
226 
227  JOYSTICK_STATE_BUTTON driver_button_state;
228  JOYSTICK_STATE_HAT driver_hat_state;
229  JOYSTICK_STATE_AXIS driver_axis_state;
230  JOYSTICK_STATE_MOTOR motor_state;
231  } ATTR_PACKED PERIPHERAL_EVENT;
232 
233  //}
234 
235  // @name Joystick types
236  //{
237 
241  typedef struct JOYSTICK_INFO
242  {
243  PERIPHERAL_INFO peripheral;
244  char* provider;
246  unsigned int button_count;
247  unsigned int hat_count;
248  unsigned int axis_count;
249  unsigned int motor_count;
251  } ATTR_PACKED JOYSTICK_INFO;
252 
253  //============================================================================
267  {
270 
273 
276 
279 
282 
285 
288 
293  //----------------------------------------------------------------------------
294 
298  typedef struct JOYSTICK_DRIVER_BUTTON
299  {
300  int index;
301  } ATTR_PACKED JOYSTICK_DRIVER_BUTTON;
302 
303  //============================================================================
310  {
313 
316 
319 
322 
327  //----------------------------------------------------------------------------
328 
332  typedef struct JOYSTICK_DRIVER_HAT
333  {
334  int index;
335  JOYSTICK_DRIVER_HAT_DIRECTION direction;
336  } ATTR_PACKED JOYSTICK_DRIVER_HAT;
337 
338  //============================================================================
345  {
348 
351 
356  //----------------------------------------------------------------------------
357 
362  {
363  int index;
364  int center;
366  unsigned int range;
367  } ATTR_PACKED JOYSTICK_DRIVER_SEMIAXIS;
368 
372  typedef struct JOYSTICK_DRIVER_MOTOR
373  {
374  int index;
375  } ATTR_PACKED JOYSTICK_DRIVER_MOTOR;
376 
380  typedef struct JOYSTICK_DRIVER_KEY
381  {
382  char keycode[16];
383  } ATTR_PACKED JOYSTICK_DRIVER_KEY;
384 
385  //============================================================================
392  {
395 
398 
401 
404 
407 
410 
413 
416 
419 
424  //----------------------------------------------------------------------------
425 
430  {
431  JOYSTICK_DRIVER_MOUSE_INDEX button;
432  } ATTR_PACKED JOYSTICK_DRIVER_MOUSE_BUTTON;
433 
434  //============================================================================
441  {
444 
447 
450 
453 
458  //----------------------------------------------------------------------------
459 
464  {
465  JOYSTICK_DRIVER_RELPOINTER_DIRECTION direction;
466  } ATTR_PACKED JOYSTICK_DRIVER_RELPOINTER;
467 
472  {
473  JOYSTICK_DRIVER_PRIMITIVE_TYPE type;
474  union
475  {
476  struct JOYSTICK_DRIVER_BUTTON button;
477  struct JOYSTICK_DRIVER_HAT hat;
478  struct JOYSTICK_DRIVER_SEMIAXIS semiaxis;
479  struct JOYSTICK_DRIVER_MOTOR motor;
480  struct JOYSTICK_DRIVER_KEY key;
481  struct JOYSTICK_DRIVER_MOUSE_BUTTON mouse;
482  struct JOYSTICK_DRIVER_RELPOINTER relpointer;
483  };
484  } ATTR_PACKED JOYSTICK_DRIVER_PRIMITIVE;
485 
486  //============================================================================
497  {
500 
503 
506 
509 
512 
515 
518 
521 
524 
529  //----------------------------------------------------------------------------
530 
531  //============================================================================
539  {
542 
551 
558 
561 
566 
571 
574 
577 
586 
591  //----------------------------------------------------------------------------
592 
596  typedef struct JOYSTICK_FEATURE
597  {
598  char* name;
599  JOYSTICK_FEATURE_TYPE type;
600  struct JOYSTICK_DRIVER_PRIMITIVE primitives[JOYSTICK_PRIMITIVE_MAX];
601  } ATTR_PACKED JOYSTICK_FEATURE;
602  //}
603 
604  typedef struct AddonProps_Peripheral
605  {
606  const char* user_path;
607  const char* addon_path;
608  } ATTR_PACKED AddonProps_Peripheral;
609 
611 
613  {
614  KODI_HANDLE kodiInstance;
615 
616  void (*trigger_scan)(void* kodiInstance);
617 
618  void (*refresh_button_maps)(void* kodiInstance,
619  const char* device_name,
620  const char* controller_id);
621 
622  unsigned int (*feature_count)(void* kodiInstance,
623  const char* controller_id,
624  JOYSTICK_FEATURE_TYPE type);
625 
626  JOYSTICK_FEATURE_TYPE(*feature_type)
627  (void* kodiInstance, const char* controller_id, const char* feature_name);
629 
631 
633  {
634  KODI_HANDLE addonInstance;
635 
636  void(__cdecl* get_capabilities)(const struct AddonInstance_Peripheral* addonInstance,
637  struct PERIPHERAL_CAPABILITIES* capabilities);
638 
639  PERIPHERAL_ERROR(__cdecl* perform_device_scan)
640  (const struct AddonInstance_Peripheral* addonInstance,
641  unsigned int* peripheral_count,
642  struct PERIPHERAL_INFO** scan_results);
643 
644  void(__cdecl* free_scan_results)(const struct AddonInstance_Peripheral* addonInstance,
645  unsigned int peripheral_count,
646  struct PERIPHERAL_INFO* scan_results);
647 
648  PERIPHERAL_ERROR(__cdecl* get_events)
649  (const struct AddonInstance_Peripheral* addonInstance,
650  unsigned int* event_count,
651  struct PERIPHERAL_EVENT** events);
652 
653  void(__cdecl* free_events)(const struct AddonInstance_Peripheral* addonInstance,
654  unsigned int event_count,
655  struct PERIPHERAL_EVENT* events);
656 
657  bool(__cdecl* send_event)(const struct AddonInstance_Peripheral* addonInstance,
658  const struct PERIPHERAL_EVENT* event);
659 
662  PERIPHERAL_ERROR(__cdecl* get_joystick_info)
663  (const struct AddonInstance_Peripheral* addonInstance,
664  unsigned int index,
665  struct JOYSTICK_INFO* info);
666 
667  void(__cdecl* free_joystick_info)(const struct AddonInstance_Peripheral* addonInstance,
668  struct JOYSTICK_INFO* info);
669 
670  PERIPHERAL_ERROR(__cdecl* get_appearance)
671  (const struct AddonInstance_Peripheral* addonInstance,
672  const struct JOYSTICK_INFO* joystick,
673  char* buffer,
674  unsigned int bufferSize);
675 
676  PERIPHERAL_ERROR(__cdecl* set_appearance)
677  (const struct AddonInstance_Peripheral* addonInstance,
678  const struct JOYSTICK_INFO* joystick,
679  const char* controller_id);
680 
681  PERIPHERAL_ERROR(__cdecl* get_features)
682  (const struct AddonInstance_Peripheral* addonInstance,
683  const struct JOYSTICK_INFO* joystick,
684  const char* controller_id,
685  unsigned int* feature_count,
686  struct JOYSTICK_FEATURE** features);
687 
688  void(__cdecl* free_features)(const struct AddonInstance_Peripheral* addonInstance,
689  unsigned int feature_count,
690  struct JOYSTICK_FEATURE* features);
691 
692  PERIPHERAL_ERROR(__cdecl* map_features)
693  (const struct AddonInstance_Peripheral* addonInstance,
694  const struct JOYSTICK_INFO* joystick,
695  const char* controller_id,
696  unsigned int feature_count,
697  const struct JOYSTICK_FEATURE* features);
698 
699  PERIPHERAL_ERROR(__cdecl* get_ignored_primitives)
700  (const struct AddonInstance_Peripheral* addonInstance,
701  const struct JOYSTICK_INFO* joystick,
702  unsigned int* feature_count,
703  struct JOYSTICK_DRIVER_PRIMITIVE** primitives);
704 
705  void(__cdecl* free_primitives)(const struct AddonInstance_Peripheral* addonInstance,
706  unsigned int,
707  struct JOYSTICK_DRIVER_PRIMITIVE* primitives);
708 
709  PERIPHERAL_ERROR(__cdecl* set_ignored_primitives)
710  (const struct AddonInstance_Peripheral* addonInstance,
711  const struct JOYSTICK_INFO* joystick,
712  unsigned int primitive_count,
713  const struct JOYSTICK_DRIVER_PRIMITIVE* primitives);
714 
715  void(__cdecl* save_button_map)(const struct AddonInstance_Peripheral* addonInstance,
716  const struct JOYSTICK_INFO* joystick);
717 
718  void(__cdecl* revert_button_map)(const struct AddonInstance_Peripheral* addonInstance,
719  const struct JOYSTICK_INFO* joystick);
720 
721  void(__cdecl* reset_button_map)(const struct AddonInstance_Peripheral* addonInstance,
722  const struct JOYSTICK_INFO* joystick,
723  const char* controller_id);
724 
725  void(__cdecl* power_off_joystick)(const struct AddonInstance_Peripheral* addonInstance,
726  unsigned int index);
729 
731  {
732  struct AddonProps_Peripheral* props;
733  struct AddonToKodiFuncTable_Peripheral* toKodi;
734  struct KodiToAddonFuncTable_Peripheral* toAddon;
736 
737 #ifdef __cplusplus
738 } /* extern "C" */
739 #endif /* __cplusplus */
740 
741 #endif /* !C_API_ADDONINSTANCE_PERIPHERAL_H */
Type accelerometer.
Definition: peripheral.h:508
Button primitive.
Definition: peripheral.h:298
Relative pointer direction right.
Definition: peripheral.h:583
right and up is pressed
Definition: peripheral.h:188
uint16_t vendor_id
Definition: peripheral.h:94
Relative pointer direction left.
Definition: peripheral.h:446
Driver input primitive type mouse button.
Definition: peripheral.h:287
Definition: peripheral.h:604
Maximum number of primitives.
Definition: peripheral.h:588
JOYSTICK_FEATURE_PRIMITIVE
Definition: peripheral.h:538
button is released
Definition: peripheral.h:150
Driver input primitive type semiaxis.
Definition: peripheral.h:278
Information shared between peripherals.
Definition: peripheral.h:90
Relative pointer direction down.
Definition: peripheral.h:455
Relative pointer direction down.
Definition: peripheral.h:581
Wheel left.
Definition: peripheral.h:563
Semiaxis primitive.
Definition: peripheral.h:361
Mouse index unknown.
Definition: peripheral.h:394
bool provides_buttonmaps
Definition: peripheral.h:107
Peripheral add-on capabilities.
Definition: peripheral.h:102
char * provider
name of the driver or interface providing the joystick
Definition: peripheral.h:244
Mouse index wheel up.
Definition: peripheral.h:412
PERIPHERAL_TYPE
Definition: peripheral.h:70
PERIPHERAL_ERROR
Definition: peripheral.h:35
Type throttle.
Definition: peripheral.h:523
Driver hat up.
Definition: peripheral.h:321
Relative pointer direction unknown.
Definition: peripheral.h:443
Accelerometer Y.
Definition: peripheral.h:555
only up is pressed
Definition: peripheral.h:176
Motor.
Definition: peripheral.h:560
bool provides_joysticks
Definition: peripheral.h:104
Throttle down.
Definition: peripheral.h:570
Wheel right.
Definition: peripheral.h:565
Mouse index horizontal wheel left.
Definition: peripheral.h:418
Throttle up.
Definition: peripheral.h:568
Type analog stick.
Definition: peripheral.h:505
Type relative pointer.
Definition: peripheral.h:514
left and down is pressed
Definition: peripheral.h:185
Unknown type.
Definition: peripheral.h:499
Definition: peripheral.h:632
only left is pressed
Definition: peripheral.h:170
JOYSTICK_STATE_BUTTON
Definition: peripheral.h:147
JOYSTICK_DRIVER_SEMIAXIS_DIRECTION
Definition: peripheral.h:344
JOYSTICK_DRIVER_MOUSE_INDEX
Definition: peripheral.h:391
Type declared as unknown.
Definition: peripheral.h:73
Analog stick up.
Definition: peripheral.h:544
Analog stick down.
Definition: peripheral.h:546
Analog stick right.
Definition: peripheral.h:548
PERIPHERAL_INFO peripheral
peripheral info for this joystick
Definition: peripheral.h:243
left and up is pressed
Definition: peripheral.h:182
Accelerometer Z.
Definition: peripheral.h:557
Event information.
Definition: peripheral.h:216
Driver hat right.
Definition: peripheral.h:318
JOYSTICK_FEATURE_TYPE
Definition: peripheral.h:496
Driver input primitive type button.
Definition: peripheral.h:272
Driver input primitive type motor.
Definition: peripheral.h:281
Relative pointer direction primitive.
Definition: peripheral.h:463
Mouse button.
Definition: peripheral.h:576
const char * addon_path
path to this add-on
Definition: peripheral.h:607
Mouse index button 5.
Definition: peripheral.h:409
uint16_t product_id
Definition: peripheral.h:95
Analog stick left.
Definition: peripheral.h:550
Type key.
Definition: peripheral.h:526
Mouse index button 4.
Definition: peripheral.h:406
state changed for joystick driver hat
Definition: peripheral.h:130
-3 : The parameters of the method are invalid for this operation
Definition: peripheral.h:47
negative half of the axis
Definition: peripheral.h:347
PERIPHERAL_EVENT_TYPE type
Type of the event used to determine which enum field to access below.
Definition: peripheral.h:222
JOYSTICK_DRIVER_RELPOINTER_DIRECTION
Definition: peripheral.h:440
JOYSTICK_STATE_HAT
Definition: peripheral.h:164
Driver hat down.
Definition: peripheral.h:324
int requested_port
requested port number (such as for 360 controllers), or NO_PORT_REQUESTED
Definition: peripheral.h:245
PERIPHERAL_TYPE type
Definition: peripheral.h:92
Type wheel.
Definition: peripheral.h:520
Driver input primitive type unknown.
Definition: peripheral.h:269
Key.
Definition: peripheral.h:573
JOYSTICK_DRIVER_HAT_DIRECTION
Definition: peripheral.h:309
-5 : No peripherals are connected
Definition: peripheral.h:53
Mouse index left.
Definition: peripheral.h:397
Driver input primitive type key.
Definition: peripheral.h:284
-6 : Peripherals are connected, but command was interrupted
Definition: peripheral.h:56
no directions are pressed
Definition: peripheral.h:167
unsigned int index
Definition: peripheral.h:96
unsigned int peripheral_index
Index of the peripheral handling/receiving the event.
Definition: peripheral.h:219
Mouse index horizontal wheel right.
Definition: peripheral.h:421
unsigned int hat_count
number of hats reported by the driver
Definition: peripheral.h:247
Driver primitive struct.
Definition: peripheral.h:471
Accelerometer X.
Definition: peripheral.h:553
Relative pointer direction right.
Definition: peripheral.h:449
button is pressed
Definition: peripheral.h:153
PERIPHERAL_EVENT_TYPE
Definition: peripheral.h:121
Info specific to joystick peripherals.
Definition: peripheral.h:241
right and down is pressed
Definition: peripheral.h:191
Type declared as keyboard.
Definition: peripheral.h:79
positive half of the axis
Definition: peripheral.h:353
Scalar feature (a button, hat direction or semiaxis)
Definition: peripheral.h:541
Mouse index wheel down.
Definition: peripheral.h:415
Definition: peripheral.h:612
Type motor.
Definition: peripheral.h:511
state changed for joystick driver axis
Definition: peripheral.h:133
only down is pressed
Definition: peripheral.h:179
JOYSTICK_DRIVER_PRIMITIVE_TYPE
Definition: peripheral.h:266
set the state for joystick rumble motor
Definition: peripheral.h:136
-1 : An unknown error occurred
Definition: peripheral.h:41
Mapping between higher-level controller feature and its driver primitives.
Definition: peripheral.h:596
state changed for joystick driver button
Definition: peripheral.h:127
bool supports_poweroff
whether the joystick supports being powered off
Definition: peripheral.h:250
Mouse button primitive.
Definition: peripheral.h:429
-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:246
Driver input primitive type hat direction.
Definition: peripheral.h:275
unknown event
Definition: peripheral.h:124
Relative pointer direction up.
Definition: peripheral.h:579
Driver input primitive type relative pointer direction.
Definition: peripheral.h:290
unsigned int motor_count
number of motors reported by the driver
Definition: peripheral.h:249
Mouse index right.
Definition: peripheral.h:400
only right is pressed
Definition: peripheral.h:173
Type scalar.
Definition: peripheral.h:502
Type absolute pointer.
Definition: peripheral.h:517
Driver hat left.
Definition: peripheral.h:315
Driver hat unknown.
Definition: peripheral.h:312
Keyboard key primitive.
Definition: peripheral.h:380
const char * user_path
path to the user profile
Definition: peripheral.h:606
unsigned int axis_count
number of axes reported by the driver
Definition: peripheral.h:248
Type declared as joystick.
Definition: peripheral.h:76
Motor primitive.
Definition: peripheral.h:372
Relative pointer direction left.
Definition: peripheral.h:585
Type declared as mouse.
Definition: peripheral.h:82
-2 : The command failed
Definition: peripheral.h:44
Hat direction primitive.
Definition: peripheral.h:332
unknown direction
Definition: peripheral.h:350
Definition: peripheral.h:730
0 : No error occurred
Definition: peripheral.h:38
Mouse index middle.
Definition: peripheral.h:403
char * name
Definition: peripheral.h:93
unsigned int driver_index
The index of the event source.
Definition: peripheral.h:225
Relative pointer direction up.
Definition: peripheral.h:452