static HRESULT get_ff(IOHIDDeviceRef device, FFDeviceObjectReference *ret) { io_service_t service; CFMutableDictionaryRef matching; CFTypeRef type; matching = IOServiceMatching(kIOHIDDeviceKey); if(!matching) { WARN("IOServiceMatching failed, force feedback disabled\n"); return DIERR_DEVICENOTREG; } type = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDLocationIDKey)); if(!matching) { CFRelease(matching); WARN("IOHIDDeviceGetProperty failed, force feedback disabled\n"); return DIERR_DEVICENOTREG; } CFDictionaryAddValue(matching, CFSTR(kIOHIDLocationIDKey), type); service = IOServiceGetMatchingService(kIOMasterPortDefault, matching); if(!ret) return FFIsForceFeedback(service) == FF_OK ? S_OK : S_FALSE; return osx_to_win32_hresult(FFCreateDevice(service, ret)); }
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; }
/* * 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; }