bool joypad::config_force_feedback(io_service_t p_service) { HRESULT ret = FFCreateDevice(p_service, &ff_device); ERR_FAIL_COND_V(ret != FF_OK, false); ret = FFDeviceSendForceFeedbackCommand(ff_device, FFSFFC_RESET); FF_ERR(); ret = FFDeviceSendForceFeedbackCommand(ff_device, FFSFFC_SETACTUATORSON); FF_ERR(); if (check_ff_features()) { ret = FFDeviceCreateEffect(ff_device, kFFEffectType_ConstantForce_ID, &ff_effect, &ff_object); FF_ERR(); return true; } FFReleaseDevice(ff_device); return false; }
/* * Stops all currently playing effects. */ int SDL_SYS_HapticStopAll(SDL_Haptic * haptic) { HRESULT ret; ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_STOPALL); if (ret != FF_OK) { return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); } return 0; }
/* * Unpauses the device. */ int SDL_SYS_HapticUnpause(SDL_Haptic * haptic) { HRESULT ret; ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_CONTINUE); if (ret != FF_OK) { return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } return 0; }
static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(IDirectInputDevice8W *iface, DWORD flags) { JoystickImpl *This = impl_from_IDirectInputDevice8W(iface); HRESULT hr; TRACE("%p 0x%x\n", This, flags); if(!This->ff) return DI_NOEFFECT; hr = osx_to_win32_hresult(FFDeviceSendForceFeedbackCommand(This->ff, flags)); if(FAILED(hr)) { WARN("FFDeviceSendForceFeedbackCommand failed: %08x\n", hr); return hr; } return S_OK; }
/* * Opens the haptic device from the file descriptor. */ static int SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service) { HRESULT ret; int ret2; /* Allocate the hwdata */ haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata)); if (haptic->hwdata == NULL) { SDL_OutOfMemory(); goto creat_err; } SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); /* Open the device */ ret = FFCreateDevice(service, &haptic->hwdata->device); if (ret != FF_OK) { SDL_SetError("Haptic: Unable to create device from service: %s.", FFStrError(ret)); goto creat_err; } /* Get supported features. */ ret2 = GetSupportedFeatures(haptic); if (ret2 < 0) { goto open_err; } /* Reset and then enable actuators. */ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_RESET); if (ret != FF_OK) { SDL_SetError("Haptic: Unable to reset device: %s.", FFStrError(ret)); goto open_err; } ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_SETACTUATORSON); if (ret != FF_OK) { SDL_SetError("Haptic: Unable to enable actuators: %s.", FFStrError(ret)); goto open_err; } /* Allocate effects memory. */ haptic->effects = (struct haptic_effect *) SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects); if (haptic->effects == NULL) { SDL_OutOfMemory(); goto open_err; } /* Clear the memory */ SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); return 0; /* Error handling */ open_err: FFReleaseDevice(haptic->hwdata->device); creat_err: if (haptic->hwdata != NULL) { SDL_free(haptic->hwdata); haptic->hwdata = NULL; } return -1; }
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **pdev, unsigned short index) { DWORD i; IOHIDDeviceRef device; JoystickImpl* newDevice; char name[MAX_PATH]; HRESULT hr; LPDIDATAFORMAT df = NULL; int idx = 0; int axis_map[8]; /* max axes */ int slider_count = 0; FFCAPABILITIES ffcaps; TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index); newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl)); if (newDevice == 0) { WARN("out of memory\n"); *pdev = 0; return DIERR_OUTOFMEMORY; } newDevice->id = index; newDevice->generic.guidInstance = DInput_Wine_OsX_Joystick_GUID; newDevice->generic.guidInstance.Data3 = index; newDevice->generic.guidProduct = DInput_Wine_OsX_Joystick_GUID; newDevice->generic.joy_polldev = poll_osx_device_state; /* get the device name */ get_osx_device_name(index, name, MAX_PATH); TRACE("Name %s\n",name); /* copy the device name */ newDevice->generic.name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1); strcpy(newDevice->generic.name, name); list_init(&newDevice->effects); device = get_device_ref(index); if(get_ff(device, &newDevice->ff) == S_OK) { newDevice->generic.devcaps.dwFlags |= DIDC_FORCEFEEDBACK; hr = FFDeviceGetForceFeedbackCapabilities(newDevice->ff, &ffcaps); if(SUCCEEDED(hr)) { TRACE("FF Capabilities:\n"); TRACE("\tsupportedEffects: 0x%x\n", (unsigned int)ffcaps.supportedEffects); TRACE("\temulatedEffects: 0x%x\n", (unsigned int)ffcaps.emulatedEffects); TRACE("\tsubType: 0x%x\n", (unsigned int)ffcaps.subType); TRACE("\tnumFfAxes: %u\n", (unsigned int)ffcaps.numFfAxes); TRACE("\tffAxes: ["); for(i = 0; i < ffcaps.numFfAxes; ++i) { TRACE("%s", osx_ff_axis_name(ffcaps.ffAxes[i])); if(i < ffcaps.numFfAxes - 1) TRACE(", "); } TRACE("]\n"); TRACE("\tstorageCapacity: %u\n", (unsigned int)ffcaps.storageCapacity); TRACE("\tplaybackCapacity: %u\n", (unsigned int)ffcaps.playbackCapacity); } hr = FFDeviceSendForceFeedbackCommand(newDevice->ff, FFSFFC_RESET); if(FAILED(hr)) WARN("FFDeviceSendForceFeedbackCommand(FFSFFC_RESET) failed: %08x\n", hr); hr = FFDeviceSendForceFeedbackCommand(newDevice->ff, FFSFFC_SETACTUATORSON); if(FAILED(hr)) WARN("FFDeviceSendForceFeedbackCommand(FFSFFC_SETACTUATORSON) failed: %08x\n", hr); } memset(axis_map, 0, sizeof(axis_map)); get_osx_device_elements(newDevice, axis_map); TRACE("%i axes %i buttons %i povs\n",newDevice->generic.devcaps.dwAxes,newDevice->generic.devcaps.dwButtons,newDevice->generic.devcaps.dwPOVs); if (newDevice->generic.devcaps.dwButtons > 128) { WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->generic.devcaps.dwButtons); newDevice->generic.devcaps.dwButtons = 128; } newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt; newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt; newDevice->generic.base.ref = 1; newDevice->generic.base.dinput = dinput; newDevice->generic.base.guid = *rguid; InitializeCriticalSection(&newDevice->generic.base.crit); newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit"); /* Create copy of default data format */ if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED; memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize); df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons; if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED; for (i = 0; i < newDevice->generic.devcaps.dwAxes; i++) { int wine_obj = -1; BOOL has_ff = FALSE; switch (axis_map[i]) { case kHIDUsage_GD_X: wine_obj = 0; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_X); break; case kHIDUsage_GD_Y: wine_obj = 1; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_Y); break; case kHIDUsage_GD_Z: wine_obj = 2; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_Z); break; case kHIDUsage_GD_Rx: wine_obj = 3; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_RX); break; case kHIDUsage_GD_Ry: wine_obj = 4; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_RY); break; case kHIDUsage_GD_Rz: wine_obj = 5; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_RZ); break; case kHIDUsage_GD_Slider: wine_obj = 6 + slider_count; has_ff = (newDevice->ff != 0) && osx_axis_has_ff(&ffcaps, FFJOFS_SLIDER(slider_count)); slider_count++; break; } if (wine_obj < 0 ) continue; memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize); df->rgodf[idx].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS; if(has_ff) df->rgodf[idx].dwFlags |= DIDOI_FFACTUATOR; ++idx; } for (i = 0; i < newDevice->generic.devcaps.dwPOVs; i++) { memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 8], df->dwObjSize); df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_POV; } for (i = 0; i < newDevice->generic.devcaps.dwButtons; i++) { memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 12], df->dwObjSize); df->rgodf[idx ].pguid = &GUID_Button; df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON; } newDevice->generic.base.data_format.wine_df = df; /* initialize default properties */ get_osx_device_elements_props(newDevice); IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface); EnterCriticalSection(&dinput->crit); list_add_tail(&dinput->devices_list, &newDevice->generic.base.entry); LeaveCriticalSection(&dinput->crit); newDevice->generic.devcaps.dwSize = sizeof(newDevice->generic.devcaps); newDevice->generic.devcaps.dwFlags |= DIDC_ATTACHED; if (newDevice->generic.base.dinput->dwVersion >= 0x0800) newDevice->generic.devcaps.dwDevType = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8); else newDevice->generic.devcaps.dwDevType = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8); newDevice->generic.devcaps.dwFFSamplePeriod = 0; newDevice->generic.devcaps.dwFFMinTimeResolution = 0; newDevice->generic.devcaps.dwFirmwareRevision = 0; newDevice->generic.devcaps.dwHardwareRevision = 0; newDevice->generic.devcaps.dwFFDriverVersion = 0; if (TRACE_ON(dinput)) { _dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df); _dump_DIDEVCAPS(&newDevice->generic.devcaps); } *pdev = newDevice; return DI_OK; FAILED: hr = DIERR_OUTOFMEMORY; if (df) HeapFree(GetProcessHeap(), 0, df->rgodf); HeapFree(GetProcessHeap(), 0, df); release_DataFormat(&newDevice->generic.base.data_format); HeapFree(GetProcessHeap(),0,newDevice->generic.name); HeapFree(GetProcessHeap(),0,newDevice); *pdev = 0; return hr; }