21 #include "../../SDL_internal.h" 23 #ifdef SDL_JOYSTICK_HAIKU 27 #include <os/support/String.h> 28 #include <os/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] = strdup(name);
78 SDL_joyname[SDL_SYS_numjoysticks] = 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] = {
179 const int JITTER = (32768 / 10);
188 stick = joystick->hwdata->stick;
189 axes = joystick->hwdata->new_axes;
190 hats = joystick->hwdata->new_hats;
194 stick->GetAxisValues(axes);
195 stick->GetHatValues(hats);
196 buttons = stick->ButtonValues();
199 for (i = 0; i < joystick->naxes; ++
i) {
200 change = ((int32) axes[i] - joystick->axes[i]);
201 if ((change > JITTER) || (change < -JITTER)) {
207 for (i = 0; i < joystick->nhats; ++
i) {
208 if (hats[i] != joystick->hats[i]) {
214 for (i = 0; i < joystick->nbuttons; ++
i) {
215 if ((buttons & 0x01) != joystick->buttons[i]) {
225 if (joystick->hwdata) {
226 joystick->hwdata->stick->Close();
227 delete joystick->hwdata->stick;
228 SDL_free(joystick->hwdata->new_hats);
229 SDL_free(joystick->hwdata->new_axes);
239 for (i = 0; SDL_joyport[
i]; ++
i) {
242 SDL_joyport[0] =
NULL;
244 for (i = 0; SDL_joyname[
i]; ++
i) {
247 SDL_joyname[0] =
NULL;
264 const char *name = joystick->name;
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_SYS_NumJoysticks()
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
GLuint const GLchar * name
void SDL_SYS_JoystickQuit(void)
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
#define SDL_HAT_RIGHTDOWN
uint8_t Uint8
An unsigned 8-bit integer type.
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
void SDL_SYS_JoystickDetect()
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()
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)