comparison src/haptic/win32/SDL_syshaptic.c @ 2612:63ea27a96a96 gsoc2008_force_feedback

Check for capabilities at init.
author Edgar Simo <bobbens@gmail.com>
date Wed, 06 Aug 2008 07:51:30 +0000
parents cdea9a70dade
children b081c72b739c
comparison
equal deleted inserted replaced
2611:cdea9a70dade 2612:63ea27a96a96
55 */ 55 */
56 static struct 56 static struct
57 { 57 {
58 DIDEVICEINSTANCE instance; 58 DIDEVICEINSTANCE instance;
59 SDL_Haptic *haptic; 59 SDL_Haptic *haptic;
60 DIDEVCAPS capabilities;
60 } SDL_hapticlist[MAX_HAPTICS]; 61 } SDL_hapticlist[MAX_HAPTICS];
61 62
62 63
63 /* 64 /*
64 * Haptic system hardware data. 65 * Haptic system hardware data.
65 */ 66 */
66 struct haptic_hwdata 67 struct haptic_hwdata
67 { 68 {
68 LPDIRECTINPUTDEVICE2 device; 69 LPDIRECTINPUTDEVICE2 device;
69 DWORD axes[3]; 70 DWORD axes[3];
70 DIDEVCAPS capabilities;
71 }; 71 };
72 72
73 73
74 /* 74 /*
75 * Haptic system effect data. 75 * Haptic system effect data.
167 * Callback to find the haptic devices. 167 * Callback to find the haptic devices.
168 */ 168 */
169 static BOOL CALLBACK 169 static BOOL CALLBACK
170 EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext) 170 EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
171 { 171 {
172 HRESULT ret;
173 LPDIRECTINPUTDEVICE device;
174
175 /* Copy the instance over, useful for creating devices. */
172 SDL_memcpy(&SDL_hapticlist[SDL_numhaptics].instance, pdidInstance, 176 SDL_memcpy(&SDL_hapticlist[SDL_numhaptics].instance, pdidInstance,
173 sizeof(DIDEVICEINSTANCE)); 177 sizeof(DIDEVICEINSTANCE));
178
179 /* Open the device */
180 ret = IDirectInput_CreateDevice( dinput, &instance.guidInstance,
181 &device, NULL );
182 if (FAILED(ret)) {
183 /* DI_SetError("Creating DirectInput device",ret); */
184 return DIENUM_CONTINUE;
185 }
186
187 /* Get capabilities. */
188 SDL_hapticlist[SDL_numhaptics].capabilities.dwSize = sizeof(DIDEVCAPS);
189 ret = IDirectInputDevice_GetCapabilities( device,
190 &SDL_hapticlist[SDL_numhaptics].capabilities );
191 if (FAILED(ret)) {
192 /* DI_SetError("Getting device capabilities",ret); */
193 IDirectInputDevice_Release(device);
194 return DIENUM_CONTINUE;
195 }
196
197 /* Close up device and count it. */
198 IDirectInputDevice_Release(device);
174 SDL_numhaptics++; 199 SDL_numhaptics++;
175 200
201 /* Watch out for hard limit. */
176 if (SDL_numhaptics >= MAX_HAPTICS) 202 if (SDL_numhaptics >= MAX_HAPTICS)
177 return DIENUM_STOP; 203 return DIENUM_STOP;
178 204
179 return DIENUM_CONTINUE; 205 return DIENUM_CONTINUE;
180 } 206 }
254 * - Open temporary DirectInputDevice interface. 280 * - Open temporary DirectInputDevice interface.
255 * - Create DirectInputDevice2 interface. 281 * - Create DirectInputDevice2 interface.
256 * - Release DirectInputDevice interface. 282 * - Release DirectInputDevice interface.
257 * - Set cooperative level. 283 * - Set cooperative level.
258 * - Set data format. 284 * - Set data format.
259 * - Get capabilities.
260 * - Acquire exclusiveness. 285 * - Acquire exclusiveness.
261 * - Reset actuators. 286 * - Reset actuators.
262 * - Get supported featuers. 287 * - Get supported featuers.
263 */ 288 */
264 static int 289 static int
309 ret = IDirectInputDevice2_SetDataFormat( haptic->hwdata->device, 334 ret = IDirectInputDevice2_SetDataFormat( haptic->hwdata->device,
310 &c_dfDIJoystick2 ); 335 &c_dfDIJoystick2 );
311 if (FAILED(ret)) { 336 if (FAILED(ret)) {
312 DI_SetError("Setting data format",ret); 337 DI_SetError("Setting data format",ret);
313 goto query_err; 338 goto query_err;
314 }
315
316 /* Get capabilities. */
317 haptic->hwdata->capabilities.dwSize = sizeof(DIDEVCAPS);
318 ret = IDirectInputDevice2_GetCapabilities( haptic->hwdata->device,
319 &haptic->hwdata->capabilities );
320 if (FAILED(ret)) {
321 DI_SetError("Getting device capabilities",ret);
322 goto acquire_err;
323 } 339 }
324 340
325 /* Get number of axes. */ 341 /* Get number of axes. */
326 ret = IDirectInputDevice2_EnumObjects( haptic->hwdata->device, 342 ret = IDirectInputDevice2_EnumObjects( haptic->hwdata->device,
327 DI_DeviceObjectCallback, 343 DI_DeviceObjectCallback,
433 * Opens a haptic device from first mouse it finds for usage. 449 * Opens a haptic device from first mouse it finds for usage.
434 */ 450 */
435 int 451 int
436 SDL_SYS_HapticMouse(void) 452 SDL_SYS_HapticMouse(void)
437 { 453 {
454 int i;
455
456 for (i=0; i<SDL_numhaptics; i++) {
457 }
438 return -1; 458 return -1;
439 } 459 }
440 460
441 461
442 /* 462 /*