Exemplo n.º 1
0
JNIEXPORT jint JNICALL Java_at_wisch_joystick_FFJoystick_setAutoCenterNative (JNIEnv *env, jclass, jint hapticDeviceIndex, jint autocenterValue){
	int num = SDL_HapticSetAutocenter(ffjoysticks[hapticDeviceIndex], autocenterValue);
	if (num < 0) {
		throwException(env, SDL_GetError());
		return -17;
	}
	return num;
}
Exemplo n.º 2
0
/*
 * Opens a Haptic device.
 */
SDL_Haptic *
SDL_HapticOpen(int device_index)
{
    int i;
    SDL_Haptic *haptic;

    if ((device_index < 0) || (device_index >= SDL_numhaptics)) {
        SDL_SetError("Haptic: There are %d haptic devices available",
                     SDL_numhaptics);
        return NULL;
    }

    /* If the haptic is already open, return it */
    for (i = 0; SDL_haptics[i]; i++) {
        if (device_index == SDL_haptics[i]->index) {
            haptic = SDL_haptics[i];
            ++haptic->ref_count;
            return haptic;
        }
    }

    /* Create the haptic device */
    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
    if (haptic == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize the haptic device */
    SDL_memset(haptic, 0, (sizeof *haptic));
    haptic->rumble_id = -1;
    haptic->index = device_index;
    if (SDL_SYS_HapticOpen(haptic) < 0) {
        SDL_free(haptic);
        return NULL;
    }

    /* Add haptic to list */
    for (i = 0; SDL_haptics[i]; i++)
        /* Skip to next haptic */ ;
    if (i >= SDL_numhaptics) {
        SDL_free(haptic);
        SDL_SetError("Haptic: Trying to add device past the number originally detected");
        return NULL;
    }
    SDL_haptics[i] = haptic;
    ++haptic->ref_count;

    /* Disable autocenter and set gain to max. */
    if (haptic->supported & SDL_HAPTIC_GAIN)
        SDL_HapticSetGain(haptic, 100);
    if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
        SDL_HapticSetAutocenter(haptic, 0);

    return haptic;
}
Exemplo n.º 3
0
/*
 * Opens a Haptic device.
 */
SDL_Haptic *
SDL_HapticOpen(int device_index)
{
    SDL_Haptic *haptic;
    SDL_Haptic *hapticlist;

    if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
        SDL_SetError("Haptic: There are %d haptic devices available",
                     SDL_NumHaptics());
        return NULL;
    }

    hapticlist = SDL_haptics;
    /* If the haptic is already open, return it
    * TODO: Should we create haptic instance IDs like the Joystick API?
    */
    while ( hapticlist )
    {
        if (device_index == hapticlist->index) {
            haptic = hapticlist;
            ++haptic->ref_count;
            return haptic;
        }
        hapticlist = hapticlist->next;
    }

    /* Create the haptic device */
    haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
    if (haptic == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }

    /* Initialize the haptic device */
    SDL_memset(haptic, 0, (sizeof *haptic));
    haptic->rumble_id = -1;
    haptic->index = device_index;
    if (SDL_SYS_HapticOpen(haptic) < 0) {
        SDL_free(haptic);
        return NULL;
    }

    /* Add haptic to list */
    ++haptic->ref_count;
    /* Link the haptic in the list */
    haptic->next = SDL_haptics;
    SDL_haptics = haptic;

    /* Disable autocenter and set gain to max. */
    if (haptic->supported & SDL_HAPTIC_GAIN)
        SDL_HapticSetGain(haptic, 100);
    if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
        SDL_HapticSetAutocenter(haptic, 0);

    return haptic;
}
Exemplo n.º 4
0
bool SDL2FFBDevice::setAutocentering(const int strength)
{
  if (!m_adjustableAC) {
    QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, "Device does not have adjustable autocentering");
    return false;
  }

  if (strength < 0 || strength > 100) {
    QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, "Autocentering strength must be within <0; 100>");
    return false;
  }

  if (SDL_HapticSetAutocenter(c_haptic, strength) < 0) {
    QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to set autocentering:\n%1").arg(SDL_GetError()));
    return false;
  }

  return true;
}