23 #ifdef SDL_JOYSTICK_BEOS
27 #include <be/support/String.h>
28 #include <be/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;
65 char name[B_OS_NAME_LENGTH];
68 nports = joystick.CountDevices();
69 SDL_SYS_numjoysticks = 0;
70 SDL_memset(SDL_joyport, 0, (
sizeof SDL_joyport));
71 SDL_memset(SDL_joyname, 0, (
sizeof SDL_joyname));
72 for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++
i)
74 if (joystick.GetDeviceName(i, name) == B_OK) {
75 if (joystick.Open(name) != B_ERROR) {
77 joystick.GetControllerName(&stick_name);
78 SDL_joyport[SDL_SYS_numjoysticks] =
strdup(name);
79 SDL_joyname[SDL_SYS_numjoysticks] =
strdup(stick_name.String());
80 SDL_SYS_numjoysticks++;
85 return (SDL_SYS_numjoysticks);
90 return SDL_SYS_numjoysticks;
105 return SDL_joyname[device_index];
131 stick =
new BJoystick;
132 joystick->
hwdata->stick = stick;
135 if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
141 stick->EnableCalibration();
144 joystick->
nbuttons = stick->CountButtons();
145 joystick->
naxes = stick->CountAxes();
146 joystick->
nhats = stick->CountHats();
148 joystick->
hwdata->new_axes = (int16 *)
150 joystick->
hwdata->new_hats = (uint8 *)
152 if (!joystick->
hwdata->new_hats || !joystick->
hwdata->new_axes) {
174 static const Uint8 hat_map[9] = {
185 const int JITTER = (32768 / 10);
194 stick = joystick->
hwdata->stick;
195 axes = joystick->
hwdata->new_axes;
196 hats = joystick->
hwdata->new_hats;
200 stick->GetAxisValues(axes);
201 stick->GetHatValues(hats);
202 buttons = stick->ButtonValues();
205 for (i = 0; i < joystick->
naxes; ++
i) {
206 change = ((int32) axes[i] - joystick->
axes[i]);
207 if ((change > JITTER) || (change < -JITTER)) {
213 for (i = 0; i < joystick->
nhats; ++
i) {
214 if (hats[i] != joystick->
hats[i]) {
220 for (i = 0; i < joystick->
nbuttons; ++
i) {
221 if ((buttons & 0x01) != joystick->
buttons[i]) {
232 joystick->
hwdata->stick->Close();
233 delete joystick->
hwdata->stick;
246 for (i = 0; SDL_joyport[
i]; ++
i) {
249 SDL_joyport[0] =
NULL;
251 for (i = 0; SDL_joyname[
i]; ++
i) {
254 SDL_joyname[0] =
NULL;
271 const char *name = joystick->
name;
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
char * strdup(const char *inStr)
int SDL_SYS_NumJoysticks()
DECLSPEC void SDLCALL SDL_free(void *mem)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
EGLImageKHR EGLint * name
void SDL_SYS_JoystickQuit(void)
struct joystick_hwdata * hwdata
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
#define SDL_HAT_RIGHTDOWN
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
void SDL_SYS_JoystickDetect()
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
SDL_bool SDL_SYS_JoystickNeedsPolling()
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
int SDL_SYS_JoystickInit(void)
#define SDL_OutOfMemory()
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
uint8_t Uint8
An unsigned 8-bit integer type.
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_JoystickID instance_id
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)