]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Add support for condition effects via SDL2
authorMichal Malý <madcatxster@devoid-pointer.net>
Fri, 31 Jul 2015 14:10:27 +0000 (16:10 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Fri, 31 Jul 2015 14:10:27 +0000 (16:10 +0200)
CMakeLists.txt
sdl2ffbconditioneffect.cpp [new file with mode: 0644]
sdl2ffbconditioneffect.h [new file with mode: 0644]
sdl2ffbeffectfactory.cpp
sdl2ffbeffectfactory.h

index eabde32eee2bd5891f79ecbbe5134b0894781449..a18ce447f211a0d110ef56a0b206c3000b98fe74 100644 (file)
@@ -58,6 +58,7 @@ if (SDL2_FOUND)
         sdl2ffbdevice.cpp
         sdl2ffbeffect.cpp
         sdl2ffbconstanteffect.cpp
+        sdl2ffbconditioneffect.cpp
         sdl2deviceprober.cpp)
 endif()
 
diff --git a/sdl2ffbconditioneffect.cpp b/sdl2ffbconditioneffect.cpp
new file mode 100644 (file)
index 0000000..fa7c6e6
--- /dev/null
@@ -0,0 +1,139 @@
+#include "sdl2ffbconditioneffect.h"
+#include "globalsettings.h"
+#include <QtWidgets/QMessageBox>
+
+SDL2FFBConditionEffect::SDL2FFBConditionEffect() :
+  SDL2FFBEffect(FFBEffectTypes::CONDITION)
+{}
+
+SDL_HapticEffect* SDL2FFBConditionEffect::createFFstruct()
+{
+  SDL_HapticEffect* effect = SDL2FFBEffect::createFFstruct();
+  if (effect == nullptr)
+    return nullptr;
+
+  switch (m_params->subtype) {
+    case ConditionSubtypes::DAMPER:
+      effect->type = SDL_HAPTIC_DAMPER;
+      break;
+    case ConditionSubtypes::FRICTION:
+      effect->type = SDL_HAPTIC_FRICTION;
+      break;
+    case ConditionSubtypes::INERTIA:
+      effect->type = SDL_HAPTIC_INERTIA;
+      break;
+    case ConditionSubtypes::SPRING:
+      effect->type = SDL_HAPTIC_SPRING;
+      break;
+    default:
+      delete effect;
+      return nullptr;
+  }
+
+  effect->condition.delay = m_params->replayDelay;
+  if (m_params->replayLength == 0)
+    effect->condition.length = SDL_HAPTIC_INFINITY;
+  else
+    effect->condition.length = m_params->replayLength;
+
+  effect->condition.center[0] = m_params->center.at(FFBConditionEffectParameters::Axis::X);
+  effect->condition.deadband[0] = m_params->deadband.at(FFBConditionEffectParameters::Axis::X);
+  effect->condition.center[1] = m_params->center.at(FFBConditionEffectParameters::Axis::Y);
+  effect->condition.deadband[1] = m_params->deadband.at(FFBConditionEffectParameters::Axis::Y);
+
+  effect->condition.left_sat[0] = m_params->leftSat.at(FFBConditionEffectParameters::Axis::X);
+  effect->condition.right_sat[0] = m_params->rightSat.at(FFBConditionEffectParameters::Axis::X);
+  effect->condition.left_coeff[0] = m_params->leftCoeff.at(FFBConditionEffectParameters::Axis::X);;
+  effect->condition.right_coeff[0] = m_params->rightCoeff.at(FFBConditionEffectParameters::Axis::X);;
+
+  effect->condition.left_sat[1] = m_params->leftSat.at(FFBConditionEffectParameters::Axis::Y);
+  effect->condition.right_sat[1] = m_params->rightSat.at(FFBConditionEffectParameters::Axis::Y);
+  effect->condition.left_coeff[1] = m_params->leftCoeff.at(FFBConditionEffectParameters::Axis::Y);;
+  effect->condition.right_coeff[1] = m_params->rightCoeff.at(FFBConditionEffectParameters::Axis::Y);;
+
+  return effect;
+}
+
+bool SDL2FFBConditionEffect::setParameters(std::shared_ptr<FFBEffectParameters> params)
+{
+  try {
+    const std::shared_ptr<FFBConditionEffectParameters> iParams = std::dynamic_pointer_cast<FFBConditionEffectParameters>(params);
+    return setParameters(iParams);
+  } catch (std::bad_cast& ) {
+    return false;
+  }
+}
+
+bool SDL2FFBConditionEffect::setParameters(std::shared_ptr<FFBConditionEffectParameters> params)
+{
+  if (!GlobalSettings::GS()->doSanityChecks)
+    return true;
+
+  if (!checkGenericParameters(params))
+    return false;
+
+  if (!checkBoundsInclusive(params->leftSat.at(FFBConditionEffectParameters::Axis::X), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Left X saturation must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->leftSat.at(FFBConditionEffectParameters::Axis::Y), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Left Y saturation must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->rightSat.at(FFBConditionEffectParameters::Axis::X), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Right X saturation must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->rightSat.at(FFBConditionEffectParameters::Axis::Y), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Right Y saturation must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->leftCoeff.at(FFBConditionEffectParameters::Axis::X), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Left X coefficient must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->leftCoeff.at(FFBConditionEffectParameters::Axis::Y), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Left Y coefficient must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->rightCoeff.at(FFBConditionEffectParameters::Axis::X), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Right X coefficient must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->rightCoeff.at(FFBConditionEffectParameters::Axis::Y), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Right Y coefficient must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->deadband.at(FFBConditionEffectParameters::Axis::X), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Deadband X must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->deadband.at(FFBConditionEffectParameters::Axis::Y), 0, 0xFFFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Deadband Y must be within <0; 65535>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->center.at(FFBConditionEffectParameters::Axis::X), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Center X must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->center.at(FFBConditionEffectParameters::Axis::Y), -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Center Y must be within <-32767; 32767>");
+    return false;
+  }
+
+  m_params = params;
+  return true;
+}
+
+
diff --git a/sdl2ffbconditioneffect.h b/sdl2ffbconditioneffect.h
new file mode 100644 (file)
index 0000000..ed2345f
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef SDL2FFBCONDITIONEFFECT_H
+#define SDL2FFBCONDITIONEFFECT_H
+
+#include "sdl2ffbeffect.h"
+#include "ffbconditioneffectparameters.h"
+
+class SDL2FFBConditionEffect : public SDL2FFBEffect
+{
+public:
+  SDL2FFBConditionEffect();
+  virtual SDL_HapticEffect* createFFstruct();
+  inline const std::shared_ptr<FFBEffectParameters> parameters() const { return m_params; }
+  bool setParameters(std::shared_ptr<FFBEffectParameters> params);
+  bool setParameters(std::shared_ptr<FFBConditionEffectParameters> params);
+
+private:
+  std::shared_ptr<FFBConditionEffectParameters> m_params;
+};
+
+#endif // SDL2FFBCONDITIONEFFECT_H
index 8682e9066d8042c307bb5b1f9c536848ef7f1dad..19fc4b289ec86dcd8e9223b6b066b4076051c18f 100644 (file)
@@ -5,6 +5,8 @@ std::shared_ptr<FFBEffect> SDL2FFBEffectFactory::createEffect(FFBEffectTypes typ
   switch (type) {
     case FFBEffectTypes::NONE:
       return std::shared_ptr<FFBEffect>(new FFBNullEffect());
+    case FFBEffectTypes::CONDITION:
+      return std::shared_ptr<SDL2FFBEffect>(new SDL2FFBConditionEffect());
     case FFBEffectTypes::CONSTANT:
       return std::shared_ptr<SDL2FFBEffect>(new SDL2FFBConstantEffect());
     default:
index 1ca167c09c13a15a3ad179bc672c4a7c42b94051..14453e4aabb7db43cea838d4e910b5bb8c3fbb2b 100644 (file)
@@ -4,6 +4,7 @@
 #include "globals.h"
 #include "ffbnulleffect.h"
 #include "sdl2ffbconstanteffect.h"
+#include "sdl2ffbconditioneffect.h"
 
 class SDL2FFBEffectFactory
 {