bool joypad::check_ff_features() { FFCAPABILITIES features; HRESULT ret = FFDeviceGetForceFeedbackCapabilities(ff_device, &features); if (ret == FF_OK && (features.supportedEffects & FFCAP_ET_CONSTANTFORCE)) { uint32_t val; ret = FFDeviceGetForceFeedbackProperty(ff_device, FFPROP_FFGAIN, &val, sizeof(val)); if (ret != FF_OK) return false; int num_axes = features.numFfAxes; ff_axes = (DWORD *)memalloc(sizeof(DWORD) * num_axes); ff_directions = (LONG *)memalloc(sizeof(LONG) * num_axes); for (int i = 0; i < num_axes; i++) { ff_axes[i] = features.ffAxes[i]; ff_directions[i] = 0; } ff_effect.cAxes = num_axes; ff_effect.rgdwAxes = ff_axes; ff_effect.rglDirection = ff_directions; return true; } return false; }
/* * Gets supported features. */ static unsigned int GetSupportedFeatures(SDL_Haptic * haptic) { HRESULT ret; FFDeviceObjectReference device; FFCAPABILITIES features; unsigned int supported; Uint32 val; device = haptic->hwdata->device; ret = FFDeviceGetForceFeedbackCapabilities(device, &features); if (ret != FF_OK) { return SDL_SetError("Haptic: Unable to get device's supported features."); } supported = 0; /* Get maximum effects. */ haptic->neffects = features.storageCapacity; haptic->nplaying = features.playbackCapacity; /* Test for effects. */ FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT); FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP); /* !!! FIXME: put this back when we have more bits in 2.1 */ /* FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE); */ FF_TEST(FFCAP_ET_SINE, SDL_HAPTIC_SINE); FF_TEST(FFCAP_ET_TRIANGLE, SDL_HAPTIC_TRIANGLE); FF_TEST(FFCAP_ET_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHUP); FF_TEST(FFCAP_ET_SAWTOOTHDOWN, SDL_HAPTIC_SAWTOOTHDOWN); FF_TEST(FFCAP_ET_SPRING, SDL_HAPTIC_SPRING); FF_TEST(FFCAP_ET_DAMPER, SDL_HAPTIC_DAMPER); FF_TEST(FFCAP_ET_INERTIA, SDL_HAPTIC_INERTIA); FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION); FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM); /* Check if supports gain. */ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN, &val, sizeof(val)); if (ret == FF_OK) { supported |= SDL_HAPTIC_GAIN; } else if (ret != FFERR_UNSUPPORTED) { return SDL_SetError("Haptic: Unable to get if device supports gain: %s.", FFStrError(ret)); } /* Checks if supports autocenter. */ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER, &val, sizeof(val)); if (ret == FF_OK) { supported |= SDL_HAPTIC_AUTOCENTER; } else if (ret != FFERR_UNSUPPORTED) { return SDL_SetError ("Haptic: Unable to get if device supports autocenter: %s.", FFStrError(ret)); } /* Check for axes, we have an artificial limit on axes */ haptic->naxes = ((features.numFfAxes) > 3) ? 3 : features.numFfAxes; /* Actually store the axes we want to use */ SDL_memcpy(haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8)); /* Always supported features. */ supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE; haptic->supported = supported; return 0; }
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; }