Exemplo n.º 1
0
bool SDL2FFBDevice::startEffect(const int idx, const FFBEffectTypes type, std::shared_ptr<FFBEffectParameters> parameters)
{
  std::shared_ptr<SDL2FFBEffect> sdlEff;
  Uint32 repeat;

  CHECK_EFFECT_IDX(idx);

  if (m_effects[idx]->status() == FFBEffect::FFBEffectStatus::NOT_LOADED) {
    if (!uploadEffect(idx, type, parameters))
      return false;
  }
  if (m_effects[idx]->status() == FFBEffect::FFBEffectStatus::PLAYING)
    return true;

  sdlEff = std::static_pointer_cast<SDL2FFBEffect>(m_effects[idx]);
  if (sdlEff->parameters()->repeat == 0) {
    if (sdlEff->parameters()->replayLength > 0)
      repeat = SDL_HAPTIC_INFINITY;
    else
      repeat = 1;
  } else
    repeat = sdlEff->parameters()->repeat;

  if (SDL_HapticRunEffect(c_haptic, sdlEff->internalIdx(), repeat) < 0) {
    QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to start the effect:\n%1").arg(SDL_GetError()));
    return false;
  }

  sdlEff->setStatus(FFBEffect::FFBEffectStatus::PLAYING);
  return true;
}
Exemplo n.º 2
0
void NeoVibrateAccessory::setVibrateNow(const bool value, int timeoutMs, int strength)
{
    struct input_event event;

    //qLog(Modem) << "setVibrateNow " << value << ", timeoutMs=" << timeoutMs << ", strength=" << strength;

    if (value && rumbleFd < 0)
        rumbleFd = openRumble();

    if (rumbleFd < 0)
        return;

    if (value && effectId < 0)
        effectId = uploadEffect(rumbleFd, (quint16)(strength), timeoutMs);

    if (effectId < 0)
        return;

    // Play/stop the effect
    event.type = EV_FF;
    event.code = effectId;
    event.value = (value ? 1 : 0);

    if (write(rumbleFd, (const void *)&event, sizeof(event)) == -1) {
        perror("rumble write");
    }

    if (!value)
        removeEffect(rumbleFd, effectId, true);

    QVibrateAccessoryProvider::setVibrateNow(value);
}