21 #include "../../SDL_internal.h" 23 #ifdef SDL_JOYSTICK_HAIKU 27 #include <support/String.h> 28 #include <device/Joystick.h> 34 #include "../SDL_sysjoystick.h" 35 #include "../SDL_joystick_c.h" 39 #define MAX_JOYSTICKS 16 42 static char *SDL_joyport[MAX_JOYSTICKS];
43 static char *SDL_joyname[MAX_JOYSTICKS];
53 static int SDL_SYS_numjoysticks = 0;
64 char name[B_OS_NAME_LENGTH];
67 nports = joystick.CountDevices();
68 SDL_SYS_numjoysticks = 0;
69 SDL_memset(SDL_joyport, 0, (
sizeof SDL_joyport));
70 SDL_memset(SDL_joyname, 0, (
sizeof SDL_joyname));
71 for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++
i)
73 if (joystick.GetDeviceName(i, name) == B_OK) {
74 if (joystick.Open(name) != B_ERROR) {
76 joystick.GetControllerName(&stick_name);
77 SDL_joyport[SDL_SYS_numjoysticks] =
SDL_strdup(name);
78 SDL_joyname[SDL_SYS_numjoysticks] =
SDL_strdup(stick_name.String());
79 SDL_SYS_numjoysticks++;
84 return (SDL_SYS_numjoysticks);
89 return SDL_SYS_numjoysticks;
99 return SDL_joyname[device_index];
118 joystick->instance_id = device_index;
121 if (joystick->hwdata ==
NULL) {
124 SDL_memset(joystick->hwdata, 0,
sizeof(*joystick->hwdata));
125 stick =
new BJoystick;
126 joystick->hwdata->stick = stick;
129 if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
135 stick->EnableCalibration();
138 joystick->nbuttons = stick->CountButtons();
139 joystick->naxes = stick->CountAxes();
140 joystick->nhats = stick->CountHats();
142 joystick->hwdata->new_axes = (int16 *)
144 joystick->hwdata->new_hats = (uint8 *)
146 if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
168 static const Uint8 hat_map[9] = {
187 stick = joystick->hwdata->stick;
188 axes = joystick->hwdata->new_axes;
189 hats = joystick->hwdata->new_hats;
193 stick->GetAxisValues(axes);
194 stick->GetHatValues(hats);
195 buttons = stick->ButtonValues();
198 for (i = 0; i < joystick->naxes; ++
i) {
203 for (i = 0; i < joystick->nhats; ++
i) {
208 for (i = 0; i < joystick->nbuttons; ++
i) {
217 if (joystick->hwdata) {
218 joystick->hwdata->stick->Close();
219 delete joystick->hwdata->stick;
220 SDL_free(joystick->hwdata->new_hats);
221 SDL_free(joystick->hwdata->new_axes);
231 for (i = 0; i < SDL_SYS_numjoysticks; ++
i) {
234 SDL_joyport[0] =
NULL;
236 for (i = 0; i < SDL_SYS_numjoysticks; ++
i) {
239 SDL_joyname[0] =
NULL;
256 const char *name = joystick->name;
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
void SDL_SYS_JoystickQuit(void)
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
GLuint const GLchar * name
#define SDL_HAT_RIGHTDOWN
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
int SDL_SYS_JoystickInit(void)
#define SDL_OutOfMemory()
int SDL_SYS_NumJoysticks(void)
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
void SDL_SYS_JoystickDetect(void)