Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
579 lines (497 loc) · 17.9 KB

SDL_dxjoystick.c

File metadata and controls

579 lines (497 loc) · 17.9 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifdef SDL_JOYSTICK_DINPUT
/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
* A. Formiga's WINMM driver.
*
* Hats and sliders are completely untested; the app I'm writing this for mostly
* doesn't use them and I don't own any joysticks with them.
*
* We don't bother to use event notification here. It doesn't seem to work
* with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
* let it return 0 events. */
#include "SDL_error.h"
#include "SDL_events.h"
#include "SDL_joystick.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0500
#include <dinput.h>
May 28, 2006
May 28, 2006
48
#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
49
50
extern HINSTANCE SDL_Instance;
May 29, 2006
May 29, 2006
51
52
53
54
55
extern int DX5_Load();
extern void DX5_Unload();
extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * ppDI,
LPUNKNOWN punkOuter);
56
57
58
59
static LPDIRECTINPUT dinput = NULL;
#define MAX_JOYSTICKS 8
May 28, 2006
May 28, 2006
60
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
61
62
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
May 28, 2006
May 28, 2006
63
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
May 28, 2006
May 28, 2006
65
66
typedef enum Type
{ BUTTON, AXIS, HAT } Type;
67
68
69
/* array to hold joystick ID values */
static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS];
May 28, 2006
May 28, 2006
70
static int SYS_NumJoysticks;
71
72
73
74
75
extern HWND SDL_Window;
typedef struct input_t
{
May 28, 2006
May 28, 2006
76
77
/* DirectInput offset for this input type: */
DWORD ofs;
May 28, 2006
May 28, 2006
79
80
/* Button, axis or hat: */
Type type;
May 28, 2006
May 28, 2006
82
83
/* SDL input offset: */
Uint8 num;
84
85
86
87
88
} input_t;
/* The private structure used to keep track of a joystick */
struct joystick_hwdata
{
May 28, 2006
May 28, 2006
89
90
LPDIRECTINPUTDEVICE2 InputDevice;
int buffered;
May 28, 2006
May 28, 2006
92
93
input_t Inputs[MAX_INPUTS];
int NumInputs;
94
95
96
};
/* Convert a DirectInput return code to a text message */
May 28, 2006
May 28, 2006
97
static void
May 29, 2006
May 29, 2006
98
SetDIerror(char *function, int code)
May 28, 2006
May 28, 2006
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
static char *error;
static char errbuf[1024];
errbuf[0] = 0;
switch (code) {
case DIERR_GENERIC:
error = "Undefined error!";
break;
case DIERR_OLDDIRECTINPUTVERSION:
error = "Your version of DirectInput needs upgrading";
break;
case DIERR_INVALIDPARAM:
error = "Invalid parameters";
break;
case DIERR_OUTOFMEMORY:
error = "Out of memory";
break;
case DIERR_DEVICENOTREG:
error = "Device not registered";
break;
case DIERR_NOINTERFACE:
error = "Interface not supported";
break;
case DIERR_NOTINITIALIZED:
error = "Device not initialized";
break;
default:
May 29, 2006
May 29, 2006
127
128
sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x",
function, code);
May 28, 2006
May 28, 2006
129
130
131
break;
}
if (!errbuf[0]) {
May 29, 2006
May 29, 2006
132
sprintf(errbuf, "%s: %s", function, error);
May 28, 2006
May 28, 2006
133
}
May 29, 2006
May 29, 2006
134
SDL_SetError("%s", errbuf);
May 28, 2006
May 28, 2006
135
return;
136
137
138
}
May 28, 2006
May 28, 2006
139
BOOL CALLBACK
May 29, 2006
May 29, 2006
140
EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
May 29, 2006
May 29, 2006
142
143
memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
sizeof(DIDEVICEINSTANCE));
May 28, 2006
May 28, 2006
144
SYS_NumJoysticks++;
May 28, 2006
May 28, 2006
146
147
if (SYS_NumJoysticks >= MAX_JOYSTICKS)
return DIENUM_STOP;
May 28, 2006
May 28, 2006
149
return DIENUM_CONTINUE;
150
151
}
May 28, 2006
May 28, 2006
152
static BOOL CALLBACK
May 29, 2006
May 29, 2006
153
DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
May 28, 2006
May 28, 2006
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
SDL_Joystick *joystick = (SDL_Joystick *) pvRef;
HRESULT result;
input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS;
if (!(dev->dwType & SupportedMask))
return DIENUM_CONTINUE; /* unsupported */
in->ofs = dev->dwOfs;
if (dev->dwType & DIDFT_BUTTON) {
in->type = BUTTON;
in->num = joystick->nbuttons;
joystick->nbuttons++;
} else if (dev->dwType & DIDFT_POV) {
in->type = HAT;
in->num = joystick->nhats;
joystick->nhats++;
} else { /* dev->dwType & DIDFT_AXIS */
DIPROPRANGE diprg;
DIPROPDWORD dilong;
in->type = AXIS;
in->num = joystick->naxes;
May 29, 2006
May 29, 2006
179
180
diprg.diph.dwSize = sizeof(diprg);
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
May 28, 2006
May 28, 2006
181
182
183
184
185
186
diprg.diph.dwObj = dev->dwOfs;
diprg.diph.dwHow = DIPH_BYOFFSET;
diprg.lMin = AXIS_MIN;
diprg.lMax = AXIS_MAX;
result =
May 29, 2006
May 29, 2006
187
188
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
DIPROP_RANGE, &diprg.diph);
May 28, 2006
May 28, 2006
189
190
191
192
if (result != DI_OK)
return DIENUM_CONTINUE; /* don't use this axis */
/* Set dead zone to 0. */
May 29, 2006
May 29, 2006
193
194
dilong.diph.dwSize = sizeof(dilong);
dilong.diph.dwHeaderSize = sizeof(dilong.diph);
May 28, 2006
May 28, 2006
195
196
197
198
dilong.diph.dwObj = dev->dwOfs;
dilong.diph.dwHow = DIPH_BYOFFSET;
dilong.dwData = 0;
result =
May 29, 2006
May 29, 2006
199
200
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
DIPROP_DEADZONE, &dilong.diph);
May 28, 2006
May 28, 2006
201
202
203
204
205
206
207
208
209
210
211
212
if (result != DI_OK)
return DIENUM_CONTINUE; /* don't use this axis */
joystick->naxes++;
}
joystick->hwdata->NumInputs++;
if (joystick->hwdata->NumInputs == MAX_INPUTS)
return DIENUM_STOP; /* too many */
return DIENUM_CONTINUE;
213
214
215
216
217
218
219
}
/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
* joysticks. Joystick 0 should be the system default joystick.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
May 28, 2006
May 28, 2006
220
int
May 29, 2006
May 29, 2006
221
SDL_SYS_JoystickInit(void)
May 28, 2006
May 28, 2006
223
224
225
226
227
HRESULT result;
SYS_NumJoysticks = 0;
/* Create the DirectInput object */
May 29, 2006
May 29, 2006
228
229
if (DX5_Load() < 0) {
SDL_SetError("Couldn't load DirectInput");
May 28, 2006
May 28, 2006
230
231
return (-1);
}
May 29, 2006
May 29, 2006
232
result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL);
May 28, 2006
May 28, 2006
233
if (result != DI_OK) {
May 29, 2006
May 29, 2006
234
235
DX5_Unload();
SetDIerror("DirectInputCreate", result);
May 28, 2006
May 28, 2006
236
237
238
return (-1);
}
May 29, 2006
May 29, 2006
239
240
241
242
result = IDirectInput_EnumDevices(dinput,
DIDEVTYPE_JOYSTICK,
EnumJoysticksCallback,
NULL, DIEDFL_ATTACHEDONLY);
May 28, 2006
May 28, 2006
243
244
return SYS_NumJoysticks;
245
246
247
}
/* Function to get the device-dependent name of a joystick */
May 28, 2006
May 28, 2006
248
const char *
May 29, 2006
May 29, 2006
249
SDL_SYS_JoystickName(int index)
May 28, 2006
May 28, 2006
251
252
/***-> test for invalid index ? */
return (SYS_Joystick[index].tszProductName);
253
254
255
256
257
258
259
}
/* Function to open a joystick for use.
The joystick to open is specified by the index field of the joystick.
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
May 28, 2006
May 28, 2006
260
int
May 29, 2006
May 29, 2006
261
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
May 28, 2006
May 28, 2006
263
264
265
266
267
HRESULT result;
LPDIRECTINPUTDEVICE device;
/* allocate memory for system specific hardware data */
joystick->hwdata =
May 29, 2006
May 29, 2006
268
(struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
May 28, 2006
May 28, 2006
269
if (joystick->hwdata == NULL) {
May 29, 2006
May 29, 2006
270
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
271
272
return (-1);
}
May 29, 2006
May 29, 2006
273
memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
May 28, 2006
May 28, 2006
274
275
276
joystick->hwdata->buffered = 1;
result =
May 29, 2006
May 29, 2006
277
278
279
IDirectInput_CreateDevice(dinput,
&SYS_Joystick[joystick->index].
guidInstance, &device, NULL);
May 28, 2006
May 28, 2006
280
if (result != DI_OK) {
May 29, 2006
May 29, 2006
281
SetDIerror("DirectInput::CreateDevice", result);
May 28, 2006
May 28, 2006
282
283
284
return (-1);
}
May 29, 2006
May 29, 2006
285
286
287
288
289
result = IDirectInputDevice_QueryInterface(device,
&IID_IDirectInputDevice2,
(LPVOID *) & joystick->
hwdata->InputDevice);
IDirectInputDevice_Release(device);
May 28, 2006
May 28, 2006
290
if (result != DI_OK) {
May 29, 2006
May 29, 2006
291
SetDIerror("DirectInputDevice::QueryInterface", result);
May 28, 2006
May 28, 2006
292
293
294
295
return (-1);
}
result =
May 29, 2006
May 29, 2006
296
297
298
299
IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_Window,
DISCL_NONEXCLUSIVE |
DISCL_BACKGROUND);
May 28, 2006
May 28, 2006
300
if (result != DI_OK) {
May 29, 2006
May 29, 2006
301
SetDIerror("DirectInputDevice::SetCooperativeLevel", result);
May 28, 2006
May 28, 2006
302
303
304
305
return (-1);
}
result =
May 29, 2006
May 29, 2006
306
307
IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice,
&c_dfDIJoystick);
May 28, 2006
May 28, 2006
308
if (result != DI_OK) {
May 29, 2006
May 29, 2006
309
SetDIerror("DirectInputDevice::SetDataFormat", result);
May 28, 2006
May 28, 2006
310
311
312
return (-1);
}
May 29, 2006
May 29, 2006
313
314
315
316
IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice,
DIJoystick_EnumDevObjectsProc,
joystick,
DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
May 28, 2006
May 28, 2006
317
318
319
{
DIPROPDWORD dipdw;
May 29, 2006
May 29, 2006
320
321
322
memset(&dipdw, 0, sizeof(dipdw));
dipdw.diph.dwSize = sizeof(dipdw);
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
May 28, 2006
May 28, 2006
323
324
325
326
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = INPUT_QSIZE;
result =
May 29, 2006
May 29, 2006
327
328
IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
DIPROP_BUFFERSIZE, &dipdw.diph);
May 28, 2006
May 28, 2006
329
330
331
332
333
334
if (result == DI_POLLEDDEVICE) {
/* This device doesn't support buffering, so we're forced
* to use less reliable polling. */
joystick->hwdata->buffered = 0;
} else if (result != DI_OK) {
May 29, 2006
May 29, 2006
335
SetDIerror("DirectInputDevice::SetProperty", result);
May 28, 2006
May 28, 2006
336
337
338
339
340
return (-1);
}
}
return (0);
341
342
}
May 28, 2006
May 28, 2006
343
static Uint8
May 29, 2006
May 29, 2006
344
TranslatePOV(DWORD value)
May 28, 2006
May 28, 2006
346
347
348
349
350
351
352
353
354
355
356
const int HAT_VALS[] = {
SDL_HAT_UP,
SDL_HAT_UP | SDL_HAT_RIGHT,
SDL_HAT_RIGHT,
SDL_HAT_DOWN | SDL_HAT_RIGHT,
SDL_HAT_DOWN,
SDL_HAT_DOWN | SDL_HAT_LEFT,
SDL_HAT_LEFT,
SDL_HAT_UP | SDL_HAT_LEFT
};
May 29, 2006
May 29, 2006
357
if (LOWORD(value) == 0xFFFF)
May 28, 2006
May 28, 2006
358
359
360
361
362
363
364
365
366
367
368
return SDL_HAT_CENTERED;
/* Round the value up: */
value += 4500 / 2;
value %= 36000;
value /= 4500;
if (value >= 8)
return SDL_HAT_CENTERED; /* shouldn't happen */
return HAT_VALS[value];
369
370
371
372
}
/* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to
* do it. */
May 28, 2006
May 28, 2006
373
static int
May 29, 2006
May 29, 2006
374
SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
May 28, 2006
May 28, 2006
376
if (joystick->axes[axis] != value)
May 29, 2006
May 29, 2006
377
return SDL_PrivateJoystickAxis(joystick, axis, value);
May 28, 2006
May 28, 2006
378
return 0;
379
380
}
May 28, 2006
May 28, 2006
381
static int
May 29, 2006
May 29, 2006
382
SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
May 28, 2006
May 28, 2006
384
if (joystick->hats[hat] != value)
May 29, 2006
May 29, 2006
385
return SDL_PrivateJoystickHat(joystick, hat, value);
May 28, 2006
May 28, 2006
386
return 0;
387
388
}
May 28, 2006
May 28, 2006
389
static int
May 29, 2006
May 29, 2006
390
391
SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button,
Uint8 state)
May 28, 2006
May 28, 2006
393
if (joystick->buttons[button] != state)
May 29, 2006
May 29, 2006
394
return SDL_PrivateJoystickButton(joystick, button, state);
May 28, 2006
May 28, 2006
395
return 0;
396
397
398
399
400
401
402
}
/* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events
* and update joystick device state.
*/
May 28, 2006
May 28, 2006
403
void
May 29, 2006
May 29, 2006
404
SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick)
May 28, 2006
May 28, 2006
406
407
408
409
410
DIJOYSTATE state;
HRESULT result;
int i;
result =
May 29, 2006
May 29, 2006
411
412
IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
sizeof(state), &state);
May 28, 2006
May 28, 2006
413
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
May 29, 2006
May 29, 2006
414
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
May 28, 2006
May 28, 2006
415
result =
May 29, 2006
May 29, 2006
416
417
418
IDirectInputDevice2_GetDeviceState(joystick->hwdata->
InputDevice, sizeof(state),
&state);
May 28, 2006
May 28, 2006
419
420
421
422
423
424
425
426
427
428
}
/* Set each known axis, button and POV. */
for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
const input_t *in = &joystick->hwdata->Inputs[i];
switch (in->type) {
case AXIS:
switch (in->ofs) {
case DIJOFS_X:
May 29, 2006
May 29, 2006
429
430
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lX);
May 28, 2006
May 28, 2006
431
432
break;
case DIJOFS_Y:
May 29, 2006
May 29, 2006
433
434
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lY);
May 28, 2006
May 28, 2006
435
436
break;
case DIJOFS_Z:
May 29, 2006
May 29, 2006
437
438
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lZ);
May 28, 2006
May 28, 2006
439
440
break;
case DIJOFS_RX:
May 29, 2006
May 29, 2006
441
442
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lRx);
May 28, 2006
May 28, 2006
443
444
break;
case DIJOFS_RY:
May 29, 2006
May 29, 2006
445
446
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lRy);
May 28, 2006
May 28, 2006
447
448
break;
case DIJOFS_RZ:
May 29, 2006
May 29, 2006
449
450
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.lRz);
May 28, 2006
May 28, 2006
451
break;
May 29, 2006
May 29, 2006
452
453
454
case DIJOFS_SLIDER(0):
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.rglSlider[0]);
May 28, 2006
May 28, 2006
455
break;
May 29, 2006
May 29, 2006
456
457
458
case DIJOFS_SLIDER(1):
SDL_PrivateJoystickAxis_Int(joystick, in->num,
(Sint16) state.rglSlider[0]);
May 28, 2006
May 28, 2006
459
460
461
462
463
464
break;
}
break;
case BUTTON:
May 29, 2006
May 29, 2006
465
466
467
468
469
470
SDL_PrivateJoystickButton_Int(joystick, in->num,
(Uint8) (state.
rgbButtons[in->ofs -
DIJOFS_BUTTON0]
? SDL_PRESSED :
SDL_RELEASED));
May 28, 2006
May 28, 2006
471
472
473
474
break;
case HAT:
{
Uint8 pos =
May 29, 2006
May 29, 2006
475
476
TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
SDL_PrivateJoystickHat_Int(joystick, in->num, pos);
May 28, 2006
May 28, 2006
477
478
479
480
break;
}
}
}
481
482
}
May 28, 2006
May 28, 2006
483
void
May 29, 2006
May 29, 2006
484
SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick)
May 28, 2006
May 28, 2006
486
487
488
489
490
491
492
int i;
HRESULT result;
DWORD numevents;
DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
numevents = INPUT_QSIZE;
result =
May 29, 2006
May 29, 2006
493
494
495
IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
sizeof(DIDEVICEOBJECTDATA),
evtbuf, &numevents, 0);
May 28, 2006
May 28, 2006
496
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
May 29, 2006
May 29, 2006
497
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
May 28, 2006
May 28, 2006
498
result =
May 29, 2006
May 29, 2006
499
500
501
502
IDirectInputDevice2_GetDeviceData(joystick->hwdata->
InputDevice,
sizeof(DIDEVICEOBJECTDATA),
evtbuf, &numevents, 0);
May 28, 2006
May 28, 2006
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
}
/* Handle the events */
if (result != DI_OK)
return;
for (i = 0; i < (int) numevents; ++i) {
int j;
for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
const input_t *in = &joystick->hwdata->Inputs[j];
if (evtbuf[i].dwOfs != in->ofs)
continue;
switch (in->type) {
case AXIS:
May 29, 2006
May 29, 2006
520
521
SDL_PrivateJoystickAxis(joystick, in->num,
(Sint16) evtbuf[i].dwData);
May 28, 2006
May 28, 2006
522
523
break;
case BUTTON:
May 29, 2006
May 29, 2006
524
525
526
527
SDL_PrivateJoystickButton(joystick, in->num,
(Uint8) (evtbuf[i].
dwData ? SDL_PRESSED
: SDL_RELEASED));
May 28, 2006
May 28, 2006
528
529
530
break;
case HAT:
{
May 29, 2006
May 29, 2006
531
532
Uint8 pos = TranslatePOV(evtbuf[i].dwData);
SDL_PrivateJoystickHat(joystick, in->num, pos);
May 28, 2006
May 28, 2006
533
534
535
536
}
}
}
}
537
538
}
May 28, 2006
May 28, 2006
539
void
May 29, 2006
May 29, 2006
540
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
May 28, 2006
May 28, 2006
542
543
HRESULT result;
May 29, 2006
May 29, 2006
544
result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
May 28, 2006
May 28, 2006
545
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
May 29, 2006
May 29, 2006
546
547
IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
May 28, 2006
May 28, 2006
548
549
550
}
if (joystick->hwdata->buffered)
May 29, 2006
May 29, 2006
551
SDL_SYS_JoystickUpdate_Buffered(joystick);
May 28, 2006
May 28, 2006
552
else
May 29, 2006
May 29, 2006
553
SDL_SYS_JoystickUpdate_Polled(joystick);
554
555
556
}
/* Function to close a joystick after use */
May 28, 2006
May 28, 2006
557
void
May 29, 2006
May 29, 2006
558
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
May 29, 2006
May 29, 2006
560
561
IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice);
IDirectInputDevice2_Release(joystick->hwdata->InputDevice);
May 28, 2006
May 28, 2006
563
564
if (joystick->hwdata != NULL) {
/* free system specific hardware data */
May 29, 2006
May 29, 2006
565
free(joystick->hwdata);
May 28, 2006
May 28, 2006
566
}
567
568
569
}
/* Function to perform any system-specific joystick related cleanup */
May 28, 2006
May 28, 2006
570
void
May 29, 2006
May 29, 2006
571
SDL_SYS_JoystickQuit(void)
May 29, 2006
May 29, 2006
573
IDirectInput_Release(dinput);
May 28, 2006
May 28, 2006
574
dinput = NULL;
May 29, 2006
May 29, 2006
575
DX5_Unload();
576
577
578
}
#endif /* SDL_JOYSTICK_DINPUT */
May 28, 2006
May 28, 2006
579
/* vi: set ts=4 sw=4 expandtab: */