${FFBChecker_SRCS}
sdl2ffbeffectfactory.cpp
sdl2ffbdevice.cpp
+ sdl2ffbeffect.cpp
+ sdl2ffbconstanteffect.cpp
sdl2deviceprober.cpp)
endif()
int direction;
int repeat;
int replayDelay;
- int replayLength;
+ int64_t replayLength;
};
#endif // FFBEFFECTPARAMETERS_H
return false;
}
- if (!checkBoundsInclusive(params->replayLength, 0, 0x7FFF)) {
+ if (!checkBoundsInclusive(params->replayLength, static_cast<int64_t>(0), static_cast<int64_t>(0x7FFF))) {
reportError("Replay length out of bounds.");
return false;
}
--- /dev/null
+#include "sdl2ffbconstanteffect.h"
+#include "globalsettings.h"
+#include <QtWidgets/QMessageBox>
+
+SDL2FFBConstantEffect::SDL2FFBConstantEffect() :
+ SDL2FFBEffect(FFBEffectTypes::CONSTANT)
+{}
+
+SDL_HapticEffect* SDL2FFBConstantEffect::createFFStruct()
+{
+ SDL_HapticEffect* effect = SDL2FFBEffect::createFFstruct();
+ if (effect == nullptr)
+ return nullptr;
+
+ effect->type = SDL_HAPTIC_CONSTANT;
+ effect->constant.direction.type = SDL_HAPTIC_POLAR;
+ effect->constant.direction.dir[0] = m_params->direction;
+
+ if (m_params->replayLength == 0)
+ effect->constant.length = SDL_HAPTIC_INFINITY;
+ else
+ effect->constant.length = m_params->replayLength;
+ effect->constant.delay = m_params->replayDelay;
+
+ effect->constant.attack_length = m_params->attackLength;
+ effect->constant.attack_level = m_params->attackLevel;
+ effect->constant.fade_length = m_params->fadeLength;
+ effect->constant.fade_level = m_params->fadeLevel;
+
+ effect->constant.level = m_params->level;
+
+ return effect;
+}
+
+bool SDL2FFBConstantEffect::setParameters(const std::shared_ptr<FFBEffectParameters> params)
+{
+ try {
+ const std::shared_ptr<FFBConstantEffectParameters> iParams = std::dynamic_pointer_cast<FFBConstantEffectParameters>(params);
+ return setParameters(iParams);
+ } catch (std::bad_cast& ) {
+ return false;
+ }
+}
+
+
+bool SDL2FFBConstantEffect::setParameters(const std::shared_ptr<FFBConstantEffectParameters> params)
+{
+ if (!GlobalSettings::GS()->doSanityChecks)
+ return true;
+
+ if (!checkGenericParameters(m_params))
+ return false;
+
+ if (!checkEnvelopeParameters(m_params->attackLength, m_params->attackLevel, m_params->fadeLength, m_params->fadeLevel))
+ return false;
+
+ if (!checkBoundsInclusive(m_params->level, -0x7FFF, 0x7FFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Level parameters must be within <-32767; 32767>");
+ return false;
+ }
+
+ m_params = params;
+ return true;
+}
+
--- /dev/null
+#ifndef SDL2FFBCONSTANTEFFECT_H
+#define SDL2FFBCONSTANTEFFECT_H
+
+#include "sdl2ffbeffect.h"
+#include "ffbconstanteffectparameters.h"
+
+class SDL2FFBConstantEffect : public SDL2FFBEffect
+{
+public:
+ explicit SDL2FFBConstantEffect();
+ SDL_HapticEffect* createFFStruct();
+ inline const std::shared_ptr<FFBEffectParameters> parameters() const { return m_params; }
+ bool setParameters(const std::shared_ptr<FFBEffectParameters> params);
+ bool setParameters(const std::shared_ptr<FFBConstantEffectParameters> params);
+
+private:
+ std::shared_ptr<FFBConstantEffectParameters> m_params;
+};
+
+#endif // SDL2FFBCONSTANTEFFECT_H
--- /dev/null
+/*
+ * Copyright 2015 <copyright holder> <email>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "sdl2ffbeffect.h"
+#include "globalsettings.h"
+#include <QtWidgets/QMessageBox>
+
+const QString SDL2FFBEffect::CAPTION("Invalid FFB parameter");
+
+SDL_HapticEffect* SDL2FFBEffect::createFFstruct()
+{
+ return new SDL_HapticEffect;
+}
+
+bool SDL2FFBEffect::checkEnvelopeParameters(const int attackLength, const int attackLevel, const int fadeLength, const int fadeLevel)
+{
+ if (!GlobalSettings::GS()->doSanityChecks)
+ return true;
+
+ if (!checkBoundsInclusive(attackLength, 0, 0x7FFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Attack length must be within <0; 32767>");
+ return false;
+ }
+
+ if (!checkBoundsInclusive(attackLevel, 0, 0x7FFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Attack level must be within <0; 32767>");
+ return false;
+ }
+
+ if (!checkBoundsInclusive(fadeLength, 0, 0x7FFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Fade length must be within <0; 32767>");
+ return false;
+ }
+
+ if (!checkBoundsInclusive(fadeLevel, 0, 0x7FFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Fade level must be within <0; 32767>");
+ return false;
+ }
+
+ return true;
+}
+
+bool SDL2FFBEffect::checkGenericParameters(const std::shared_ptr<FFBEffectParameters> params)
+{
+ if (!GlobalSettings::GS()->doSanityChecks)
+ return true;
+
+ if (!checkBoundsInclusive(params->direction, 0, 35999)) {
+ QMessageBox::warning(nullptr, CAPTION, "Direction must be within <0; 35999)");
+ return false;
+ }
+
+ if (!checkBoundsInclusive(params->replayLength, static_cast<int64_t>(0), static_cast<int64_t>(0x7FFF))) {
+ QMessageBox::warning(nullptr, CAPTION, "Replay length must be within <0; 32767>");
+ return false;
+ }
+
+ if (!checkBoundsInclusive(params->replayDelay, 0, 0xFFFF)) {
+ QMessageBox::warning(nullptr, CAPTION, "Replay delay must be within <0; 65535>");
+ return false;
+ }
+
+ return true;
+}
+
+
--- /dev/null
+#ifndef SDL2FFBEFFECT_H
+#define SDL2FFBEFFECT_H
+
+#include "ffbeffect.h"
+#include "SDL.h"
+
+class SDL2FFBEffect : public FFBEffect
+{
+public:
+ explicit SDL2FFBEffect(FFBEffectTypes type) : FFBEffect(type) {}
+ virtual SDL_HapticEffect* createFFstruct();
+
+protected:
+ virtual bool checkGenericParameters(const std::shared_ptr<FFBEffectParameters> params);
+ bool checkEnvelopeParameters(const int attackLength, const int attackLevel, const int fadeLength, const int fadeLevel);
+
+ static const QString CAPTION;
+};
+
+#endif // SDL2FFBEFFECT_H
switch (type) {
case FFBEffectTypes::NONE:
return std::shared_ptr<FFBEffect>(new FFBNullEffect());
+ case FFBEffectTypes::CONSTANT:
+ return std::shared_ptr<SDL2FFBEffect>(new SDL2FFBConstantEffect());
default:
return std::shared_ptr<FFBEffect>(new FFBNullEffect());
}
#include "globals.h"
#include "ffbnulleffect.h"
+#include "sdl2ffbconstanteffect.h"
class SDL2FFBEffectFactory
{