예제 #1
0
/*
 * Opens a SDL_Haptic from a SDL_Joystick.
 */
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    int i;
    HRESULT idret;
    DIDEVICEINSTANCE joy_instance;
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    if (joystick->hwdata->bXInputDevice) {
        const Uint8 userid = joystick->hwdata->userid;
        for (i=0; i<SDL_numhaptics; i++) {
            if ((SDL_hapticlist[i].bXInputHaptic) && (SDL_hapticlist[i].userid == userid)) {
                SDL_assert(joystick->hwdata->bXInputHaptic);
                haptic->index = i;
                return SDL_SYS_HapticOpenFromXInput(haptic, SDL_hapticlist[haptic->index].userid);
            }
        }
    } else {
        for (i=0; i<SDL_numhaptics; i++) {
            idret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
            if (FAILED(idret)) {
                return -1;
            }
            if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance,
                              &joy_instance.guidInstance)) {
                haptic->index = i;
                return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
            }
        }
    }
    /* No match to our haptic list */
    return -1;
}
예제 #2
0
/*
 * Checks to see if the haptic device and joystick and in reality the same.
 */
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    if ((joystick->hwdata->bXInputHaptic == haptic->hwdata->bXInputHaptic) && (haptic->hwdata->userid == joystick->hwdata->userid)) {
        return 1;
    } else {
        HRESULT ret;
        DIDEVICEINSTANCE hap_instance, joy_instance;

        hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
        joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

        /* Get the device instances. */
        ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
                                            &hap_instance);
        if (FAILED(ret)) {
            return 0;
        }
        ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
                                                &joy_instance);
        if (FAILED(ret)) {
            return 0;
        }

        if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance))
            return 1;
    }

    return 0;
}
예제 #3
0
int
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    SDL_hapticlist_item *item;
    int index = 0;
    HRESULT ret;
    DIDEVICEINSTANCE joy_instance;

    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
    if (FAILED(ret)) {
        return -1;
    }

    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
        if (!item->bXInputHaptic && DI_GUIDIsSame(&item->instance.guidInstance, &joy_instance.guidInstance)) {
            haptic->index = index;
            return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
        }
        ++index;
    }

    SDL_SetError("Couldn't find joystick in haptic device list");
    return -1;
}
예제 #4
0
/*
 * Callback to get supported axes.
 */
static BOOL CALLBACK
DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
{
    SDL_Haptic *haptic = (SDL_Haptic *) pvRef;

    if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
        const GUID *guid = &dev->guidType;
        DWORD offset = 0;
        if (DI_GUIDIsSame(guid, &GUID_XAxis)) {
            offset = DIJOFS_X;
        } else if (DI_GUIDIsSame(guid, &GUID_YAxis)) {
            offset = DIJOFS_Y;
        } else if (DI_GUIDIsSame(guid, &GUID_ZAxis)) {
            offset = DIJOFS_Z;
        } else if (DI_GUIDIsSame(guid, &GUID_RxAxis)) {
            offset = DIJOFS_RX;
        } else if (DI_GUIDIsSame(guid, &GUID_RyAxis)) {
            offset = DIJOFS_RY;
        } else if (DI_GUIDIsSame(guid, &GUID_RzAxis)) {
            offset = DIJOFS_RZ;
        } else {
            return DIENUM_CONTINUE;   /* can't use this, go on. */
        }

        haptic->hwdata->axes[haptic->naxes] = offset;
        haptic->naxes++;

        /* Currently using the artificial limit of 3 axes. */
        if (haptic->naxes >= 3) {
            return DIENUM_STOP;
        }
    }

    return DIENUM_CONTINUE;
}
예제 #5
0
/*
 * Opens a SDL_Haptic from a SDL_Joystick.
 */
int
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    int i, ret;
    HRESULT idret;
    DIDEVICEINSTANCE joy_instance;
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    for (i=0; i<SDL_numhaptics; i++) {
        idret = IDirectInputDevice2_GetDeviceInfo(joystick->hwdata->InputDevice,
              &joy_instance);
        if (FAILED(idret)) {
            return -1;
        }
        if (DI_GUIDIsSame(&SDL_hapticlist[i].instance.guidInstance,
                          &joy_instance.guidInstance)) {
            haptic->index = i;
            break;
        }
    }
    if (i >= SDL_numhaptics) {
        return -1;
    }

    /* Allocate the hwdata */
    haptic->hwdata = (struct haptic_hwdata *)
        SDL_malloc(sizeof(*haptic->hwdata));
    if (haptic->hwdata == NULL) {
        SDL_OutOfMemory();
        return -1;
    }
    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));

    /* Now open the device. */
    ret =
        SDL_SYS_HapticOpenFromDevice2(haptic, joystick->hwdata->InputDevice);
    if (ret < 0) {
        return -1;
    }

    /* It's using the joystick device. */
    haptic->hwdata->is_joystick = 1;

    return 0;
}
예제 #6
0
/*
 * Checks to see if the haptic device and joystick and in reality the same.
 */
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    HRESULT ret;
    DIDEVICEINSTANCE hap_instance, joy_instance;

    /* Get the device instances. */
    ret = IDirectInputDevice2_GetDeviceInfo(haptic->hwdata->device,
                                            &hap_instance);
    if (FAILED(ret)) {
        return 0;
    }
    ret = IDirectInputDevice2_GetDeviceInfo(joystick->hwdata->InputDevice,
                                            &joy_instance);
    if (FAILED(ret)) {
        return 0;
    }

    if (DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance))
        return 1;

    return 0;
}
예제 #7
0
int
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
    HRESULT ret;
    DIDEVICEINSTANCE hap_instance, joy_instance;

    hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);

    /* Get the device instances. */
    ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
        &hap_instance);
    if (FAILED(ret)) {
        return 0;
    }
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
        &joy_instance);
    if (FAILED(ret)) {
        return 0;
    }

    return DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance);
}