]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Add support for ramp effect via SDL2
authorMichal Malý <madcatxster@devoid-pointer.net>
Sat, 1 Aug 2015 11:41:23 +0000 (13:41 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Sat, 1 Aug 2015 11:41:23 +0000 (13:41 +0200)
CMakeLists.txt
sdl2ffbrampeffect.cpp [new file with mode: 0644]
sdl2ffbrampeffect.h [new file with mode: 0644]

index 964f67132f61f26dbd036123db1f886a0982b3c0..cb0c0b517c40eb87a2eb7d39b57d110737bc1bd7 100644 (file)
@@ -60,6 +60,7 @@ if (SDL2_FOUND)
         sdl2ffbconstanteffect.cpp
         sdl2ffbconditioneffect.cpp
         sdl2ffbperiodiceffect.cpp
+        sdl2ffbrampeffect.cpp
         sdl2deviceprober.cpp)
 endif()
 
diff --git a/sdl2ffbrampeffect.cpp b/sdl2ffbrampeffect.cpp
new file mode 100644 (file)
index 0000000..f2e078c
--- /dev/null
@@ -0,0 +1,67 @@
+#include "sdl2ffbrampeffect.h"
+#include "globalsettings.h"
+#include <QtWidgets/QMessageBox>
+
+SDL2FFBRampEffect::SDL2FFBRampEffect() :
+  SDL2FFBEffect(FFBEffectTypes::RAMP)
+{}
+
+SDL_HapticEffect* SDL2FFBRampEffect::createFFstruct()
+{
+  SDL_HapticEffect* effect = SDL2FFBEffect::createFFstruct();
+
+  if (effect == nullptr)
+    return nullptr;
+
+  effect->type = SDL_HAPTIC_RAMP;
+
+  effect->ramp.direction.type = SDL_HAPTIC_POLAR;
+  effect->ramp.direction.dir[0] = m_params->direction;
+
+  effect->ramp.attack_length = m_params->attackLength;
+  effect->ramp.attack_level = m_params->attackLevel;
+  effect->ramp.fade_length = m_params->fadeLength;
+  effect->ramp.fade_level = m_params->fadeLevel;
+
+  effect->ramp.start = m_params->startLevel;
+  effect->ramp.end = m_params->endLevel;
+
+  return effect;
+}
+
+bool SDL2FFBRampEffect::setParameters(const std::shared_ptr<FFBEffectParameters>  params)
+{
+  try {
+    const std::shared_ptr<FFBRampEffectParameters> iParams = std::dynamic_pointer_cast<FFBRampEffectParameters>(params);
+    return setParameters(iParams);
+  } catch (std::bad_cast& ) {
+    return false;
+  }
+}
+
+bool SDL2FFBRampEffect::setParameters(const std::shared_ptr<FFBRampEffectParameters> params)
+{
+  if (!GlobalSettings::GS()->doSanityChecks)
+    return true;
+
+  if (!checkGenericParameters(params))
+    return false;
+
+  if (!checkEnvelopeParameters(params->attackLength, params->attackLevel, params->fadeLength, params->fadeLevel))
+    return false;
+
+  if (checkBoundsInclusive(params->startLevel, -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "Start level must be within <-32767; 32767>");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->endLevel, -0x7FFF, 0x7FFF)) {
+    QMessageBox::warning(nullptr, CAPTION, "End level must be within <-32767; 32767>");
+    return false;
+  }
+
+  m_params = params;
+  return true;
+}
+
+
diff --git a/sdl2ffbrampeffect.h b/sdl2ffbrampeffect.h
new file mode 100644 (file)
index 0000000..c3c7416
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef SDL2FFBRAMPEFFECT_H
+#define SDL2FFBRAMPEFFECT_H
+
+#include "sdl2ffbeffect.h"
+#include "ffbrampeffectparameters.h"
+
+class SDL2FFBRampEffect : public SDL2FFBEffect
+{
+public:
+  SDL2FFBRampEffect();
+  SDL_HapticEffect* createFFstruct();
+  inline const std::shared_ptr<FFBEffectParameters> parameters() const { return m_params; }
+  bool setParameters(const std::shared_ptr<FFBEffectParameters> params);
+
+private:
+  bool setParameters(const std::shared_ptr<FFBRampEffectParameters> params);
+
+  std::shared_ptr<FFBRampEffectParameters> m_params;
+};
+
+#endif // SDL2FFBRAMPEFFECT_H