usbjoy.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* Title: USB Joystick library
  2. Version 0.2
  3. Written by Puck2099 (puck2099@gmail.com), (c) 2006.
  4. <http://www.gp32wip.com>
  5. If you use this library or a part of it, please, let it know.
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. This library 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 GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef USBJOY_H
  19. #define USBJOY_H
  20. /* notaz: my Logitech has different button layout, and I want it to match gp2x's */
  21. typedef enum {
  22. JOY_TYPE_GENERIC,
  23. JOY_TYPE_LOGITECH
  24. } joy_type;
  25. /*
  26. Enumeration: Axes values
  27. This enumeration contains shortcuts to the values used on axes.
  28. Constants:
  29. JOYUP - Joystick Up
  30. JOYDOWN - Joystick Down
  31. JOYLEFT - Joystick Left
  32. JOYRIGHT - Joystick Right
  33. See also:
  34. <joy_getaxe>
  35. */
  36. #define JOYUP (0)
  37. #define JOYDOWN (1)
  38. #define JOYLEFT (2)
  39. #define JOYRIGHT (3)
  40. /*
  41. Struct: usbjoy
  42. Contains all Joystick needed information.
  43. Fields:
  44. fd - File descriptor used.
  45. name - Joystick's name.
  46. device - /dev/input/jsX device.
  47. numbuttons - Joystick's buttons.
  48. numaxes - Joystick's axes.
  49. numhats - Joystick's hats.
  50. statebuttons - Current state of each button.
  51. stateaxes - Current state of each direction.
  52. */
  53. struct usbjoy {
  54. int fd;
  55. char name [128];
  56. char device [128];
  57. int numbuttons;
  58. int numaxes;
  59. int numhats;
  60. int statebuttons[32];
  61. int stateaxes[4];
  62. int axevals[2];
  63. joy_type type;
  64. };
  65. /*
  66. Function: joy_open
  67. Opens a USB joystick and fills its information.
  68. Parameters:
  69. joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
  70. Returns:
  71. Filled usbjoy structure.
  72. */
  73. struct usbjoy * joy_open (int joynumber);
  74. /*
  75. Function: joy_name
  76. Returns Joystick's name.
  77. Parameters:
  78. joy - Selected joystick.
  79. Returns:
  80. Joystick's name or NULL if <usbjoy> struct is empty.
  81. */
  82. char * joy_name (struct usbjoy * joy);
  83. /*
  84. Function: joy_device
  85. Returns Joystick's device.
  86. Parameters:
  87. joy - Selected joystick.
  88. Returns:
  89. Joystick's device or NULL if <usbjoy> struct is empty.
  90. */
  91. char * joy_device (struct usbjoy * joy);
  92. /*
  93. Function: joy_buttons
  94. Returns Joystick's buttons number.
  95. Parameters:
  96. joy - Selected joystick.
  97. Returns:
  98. Joystick's buttons or 0 if <usbjoy> struct is empty.
  99. */
  100. int joy_buttons (struct usbjoy * joy);
  101. /*
  102. Function: joy_axes
  103. Returns Joystick's axes number.
  104. Parameters:
  105. joy - Selected joystick.
  106. Returns:
  107. Joystick's axes or 0 if <usbjoy> struct is empty.
  108. */
  109. int joy_axes (struct usbjoy * joy);
  110. /*
  111. Function: joy_update
  112. Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
  113. Parameters:
  114. joy - Selected joystick.
  115. Returns:
  116. 0 - No events registered (no need to update).
  117. 1 - Events registered (a button or axe has been pushed).
  118. -1 - Error: <usbjoy> struct is empty.
  119. */
  120. int joy_update (struct usbjoy * joy);
  121. /*
  122. Function: joy_getbutton
  123. Returns Joystick's button information.
  124. Parameters:
  125. button - Button which value you want to know (from 0 to 31).
  126. joy - Selected joystick.
  127. Returns:
  128. 0 - Button NOT pushed.
  129. 1 - Button pushed.
  130. -1 - Error: <usbjoy> struct is empty.
  131. */
  132. int joy_getbutton (int button, struct usbjoy * joy);
  133. /*
  134. Function: joy_getaxe
  135. Returns Joystick's axes information.
  136. Parameters:
  137. axe - Axe which value you want to know (see <Axes values>).
  138. joy - Selected joystick.
  139. Returns:
  140. 0 - Direction NOT pushed.
  141. 1 - Direction pushed.
  142. -1 - Error: <usbjoy> struct is empty.
  143. */
  144. int joy_getaxe (int axe, struct usbjoy * joy);
  145. /*
  146. Function: joy_close
  147. Closes selected joystick's file descriptor and detroys it's fields.
  148. Parameters:
  149. joy - Selected joystick.
  150. Returns:
  151. 0 - Joystick successfully closed.
  152. -1 - Error: <usbjoy> struct is empty.
  153. */
  154. int joy_close (struct usbjoy * joy);
  155. /* more stuff */
  156. extern int num_of_joys;
  157. extern struct usbjoy *joys[4];
  158. void usbjoy_update(void);
  159. void usbjoy_init(void);
  160. int usbjoy_check(int joyno);
  161. int usbjoy_check2(int joyno);
  162. void usbjoy_deinit(void);
  163. #endif // USBJOY_H