From 89915e22cca1766d624fd86a899b2dcf8aa0065f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Wed, 5 Mar 2014 12:23:57 +0100 Subject: [PATCH] Add support for FF_RUMBLE --- FFBChecker.pro | 13 +++++++-- effectsettings.h | 2 +- ffbdevice.cpp | 2 ++ ffbeffectfactory.cpp | 2 ++ ffbeffectfactory.h | 1 + ffbrumbleeffect.cpp | 47 ++++++++++++++++++++++++++++++ ffbrumbleeffect.h | 20 +++++++++++++ ffbrumbleeffectparameters.cpp | 23 +++++++++++++++ ffbrumbleeffectparameters.h | 20 +++++++++++++ globals.h | 6 ++-- mainwindow.cpp | 21 +++++++++++++ mainwindow.h | 3 ++ rampeffectsettings.h | 2 +- rumbleeffectsettings.cpp | 39 +++++++++++++++++++++++++ rumbleeffectsettings.h | 27 +++++++++++++++++ rumbleeffectsettings.ui | 55 +++++++++++++++++++++++++++++++++++ 16 files changed, 275 insertions(+), 8 deletions(-) create mode 100644 ffbrumbleeffect.cpp create mode 100644 ffbrumbleeffect.h create mode 100644 ffbrumbleeffectparameters.cpp create mode 100644 ffbrumbleeffectparameters.h create mode 100644 rumbleeffectsettings.cpp create mode 100644 rumbleeffectsettings.h create mode 100644 rumbleeffectsettings.ui diff --git a/FFBChecker.pro b/FFBChecker.pro index b55c41a..3fbff7a 100644 --- a/FFBChecker.pro +++ b/FFBChecker.pro @@ -35,7 +35,10 @@ SOURCES += main.cpp\ rampeffectsettings.cpp \ ffbrampeffectparameters.cpp \ ffbrampeffect.cpp \ - globalsettings.cpp + globalsettings.cpp \ + rumbleeffectsettings.cpp \ + ffbrumbleeffectparameters.cpp \ + ffbrumbleeffect.cpp HEADERS += mainwindow.h \ deviceprober.h \ @@ -61,14 +64,18 @@ HEADERS += mainwindow.h \ rampeffectsettings.h \ ffbrampeffectparameters.h \ ffbrampeffect.h \ - globalsettings.h + globalsettings.h \ + rumbleeffectsettings.h \ + ffbrumbleeffectparameters.h \ + ffbrumbleeffect.h FORMS += mainwindow.ui \ constanteffectsettings.ui \ envelopesettings.ui \ periodiceffectsettings.ui \ conditioneffectsettings.ui \ - rampeffectsettings.ui + rampeffectsettings.ui \ + rumbleeffectsettings.ui QMAKE_CXXFLAGS += -std=c++11 -Wall QMAKE_CXXFLAGS_DEBUG += -ggdb3 diff --git a/effectsettings.h b/effectsettings.h index 14f42ff..0143c2d 100644 --- a/effectsettings.h +++ b/effectsettings.h @@ -8,7 +8,7 @@ class EffectSettings : public QWidget { Q_OBJECT public: - explicit EffectSettings(QWidget* parent = 0); + explicit EffectSettings(QWidget* parent = nullptr); virtual bool fillFromParameters(const std::shared_ptr params) = 0; signals: diff --git a/ffbdevice.cpp b/ffbdevice.cpp index 9df7e72..57e5838 100644 --- a/ffbdevice.cpp +++ b/ffbdevice.cpp @@ -161,6 +161,8 @@ bool FFBDevice::queryDeviceCapabilities() if (testBit(FF_SPRING, caps) || testBit(FF_FRICTION, caps) || testBit(FF_DAMPER, caps) || testBit(FF_INERTIA, caps)) m_availableEffects.push_back(FFBEffectTypes::CONDITION); + if (testBit(FF_RUMBLE, caps)) + m_availableEffects.push_back(FFBEffectTypes::RUMBLE); /* Query waveforms for PERIODIC if the device supports it */ if (hasEffect(FFBEffectTypes::PERIODIC)) { diff --git a/ffbeffectfactory.cpp b/ffbeffectfactory.cpp index 38d02e3..41462cf 100644 --- a/ffbeffectfactory.cpp +++ b/ffbeffectfactory.cpp @@ -17,6 +17,8 @@ std::shared_ptr FFBEffectFactory::createEffect(FFBEffectTypes type) return std::shared_ptr(new FFBConditionEffect()); case FFBEffectTypes::RAMP: return std::shared_ptr(new FFBRampEffect()); + case FFBEffectTypes::RUMBLE: + return std::shared_ptr(new FFBRumbleEffect()); default: return nullptr; } diff --git a/ffbeffectfactory.h b/ffbeffectfactory.h index 078dcca..a276be9 100644 --- a/ffbeffectfactory.h +++ b/ffbeffectfactory.h @@ -7,6 +7,7 @@ #include "ffbnulleffect.h" #include "ffbperiodiceffect.h" #include "ffbrampeffect.h" +#include "ffbrumbleeffect.h" class FFBEffectFactory { diff --git a/ffbrumbleeffect.cpp b/ffbrumbleeffect.cpp new file mode 100644 index 0000000..1eee734 --- /dev/null +++ b/ffbrumbleeffect.cpp @@ -0,0 +1,47 @@ +#include "ffbrumbleeffect.h" + +FFBRumbleEffect::FFBRumbleEffect() : + FFBEffect(FFBEffectTypes::RUMBLE) +{ +} + +struct ff_effect* FFBRumbleEffect::createFFStruct() +{ + struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + + eff->type = FF_RUMBLE; + + eff->u.rumble.strong_magnitude = m_params->strongMagnitude; + eff->u.rumble.weak_magnitude = m_params->weakMagnitude; + + return eff; +} + +bool FFBRumbleEffect::setParameters(const std::shared_ptr params) +{ + try { + return setParameters(std::dynamic_pointer_cast(params)); + } catch (std::bad_cast& ex) { + reportError("Invalid effect parameters object " + QString(ex.what())); + return false; + } +} + +bool FFBRumbleEffect::setParameters(const std::shared_ptr params) +{ + if (!checkGenericParameters(params)) + return false; + + if (!checkBoundsInclusive(params->strongMagnitude, static_cast(0), static_cast(0xFFFF))) { + reportError("Strong magnitude out of bounds"); + return false; + } + + if (!checkBoundsInclusive(params->weakMagnitude, static_cast(0), static_cast(0xFFFF))) { + reportError("Weak magnitude out of bounds"); + return false; + } + + m_params = params; + return true; +} diff --git a/ffbrumbleeffect.h b/ffbrumbleeffect.h new file mode 100644 index 0000000..e0075c3 --- /dev/null +++ b/ffbrumbleeffect.h @@ -0,0 +1,20 @@ +#ifndef FFBRUMBLEEFFECT_H +#define FFBRUMBLEEFFECT_H + +#include "ffbeffect.h" +#include "ffbrumbleeffectparameters.h" + +class FFBRumbleEffect : public FFBEffect +{ +public: + FFBRumbleEffect(); + struct ff_effect* createFFStruct(); + inline const std::shared_ptr parameters() const { return m_params; } + bool setParameters(const std::shared_ptr params); + bool setParameters(const std::shared_ptr params); + +private: + std::shared_ptr m_params; +}; + +#endif // FFBRUMBLEEFFECT_H diff --git a/ffbrumbleeffectparameters.cpp b/ffbrumbleeffectparameters.cpp new file mode 100644 index 0000000..5b5cb67 --- /dev/null +++ b/ffbrumbleeffectparameters.cpp @@ -0,0 +1,23 @@ +#include "ffbrumbleeffectparameters.h" + +FFBRumbleEffectParameters::FFBRumbleEffectParameters() +{ +} + +bool FFBRumbleEffectParameters::strongMagnitudeFromString(const QString& strong) +{ + return magnitudeFromString(strong, strongMagnitude); +} + +bool FFBRumbleEffectParameters::weakMagnitudeFromString(const QString& weak) +{ + return magnitudeFromString(weak, weakMagnitude); +} + +bool FFBRumbleEffectParameters::magnitudeFromString(const QString& str, quint16& val) +{ + bool ok; + val = str.toInt(&ok); + + return ok; +} diff --git a/ffbrumbleeffectparameters.h b/ffbrumbleeffectparameters.h new file mode 100644 index 0000000..f901c8e --- /dev/null +++ b/ffbrumbleeffectparameters.h @@ -0,0 +1,20 @@ +#ifndef FFBRUMBLEEFFECTPARAMETERS_H +#define FFBRUMBLEEFFECTPARAMETERS_H + +#include "ffbeffectparameters.h" + +class FFBRumbleEffectParameters : public FFBEffectParameters +{ +public: + FFBRumbleEffectParameters(); + bool strongMagnitudeFromString(const QString& strong); + bool weakMagnitudeFromString(const QString& weak); + + quint16 strongMagnitude; + quint16 weakMagnitude; + +private: + bool magnitudeFromString(const QString& str, quint16& val); +}; + +#endif // FFBRUMBLEEFFECTPARAMETERS_H diff --git a/globals.h b/globals.h index aa21149..e2e2a63 100644 --- a/globals.h +++ b/globals.h @@ -3,10 +3,10 @@ #define APP_NAME "FFBChecker" static const int APP_VERSION_MAJOR(0); -static const int APP_VERSION_MINOR(2); -static const char APP_VERSION_REL('d'); +static const int APP_VERSION_MINOR(3); +static const char APP_VERSION_REL('a'); -enum class FFBEffectTypes { NONE, CONSTANT, PERIODIC, RAMP, CONDITION, RUMBLE}; +enum class FFBEffectTypes { NONE, CONSTANT, PERIODIC, RAMP, CONDITION, RUMBLE }; enum class PeriodicWaveforms { NONE, SQUARE, TRIANGLE, SINE, SAW_UP, SAW_DOWN }; enum class ConditionSubtypes { NONE, SPRING, FRICTION, DAMPER, INERTIA }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 50a62e9..bff315c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,10 +22,12 @@ MainWindow::MainWindow(std::shared_ptr prober, const QString& titl m_periodicEffSet = new PeriodicEffectSettings(); m_conditionEffSet = new ConditionEffectSettings(); m_rampEffSet = new RampEffectSettings(); + m_rumbleEffSet = new RumbleEffectSettings(); ui->qstw_effectSpecifics->addWidget(m_conditionEffSet); ui->qstw_effectSpecifics->addWidget(m_constantEffSet); ui->qstw_effectSpecifics->addWidget(m_periodicEffSet); ui->qstw_effectSpecifics->addWidget(m_rampEffSet); + ui->qstw_effectSpecifics->addWidget(m_rumbleEffSet); if (GlobalSettings::GS()->doSanityChecks) ui->ql_noChecksWarning->setHidden(true); @@ -51,6 +53,8 @@ EffectSettings* MainWindow::effectSettingsByType(FFBEffectTypes type) return m_conditionEffSet; case FFBEffectTypes::RAMP: return m_rampEffSet; + case FFBEffectTypes::RUMBLE: + return m_rumbleEffSet; default: abort(); } @@ -329,6 +333,23 @@ bool MainWindow::readEffectParameters(std::shared_ptr& para params = iParams; break; } + case FFBEffectTypes::RUMBLE: { + std::shared_ptr iParams(new FFBRumbleEffectParameters()); + if (!readGeneralEffectParameters(iParams)) + return false; + + if (!iParams->strongMagnitudeFromString(m_rumbleEffSet->strongMagnitude())) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Strong magnitude\""); + return false; + } + if (!iParams->weakMagnitudeFromString(m_rumbleEffSet->weakMagnitude())) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Weak magnitude\""); + return false; + } + + params = iParams; + break; + } default: qDebug() << "Unhandled type of effect"; return false; diff --git a/mainwindow.h b/mainwindow.h index bfc58fd..33687ce 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,8 +8,10 @@ #include "ffbdevice.h" #include "ffbperiodiceffectparameters.h" #include "ffbrampeffectparameters.h" +#include "ffbrumbleeffectparameters.h" #include "periodiceffectsettings.h" #include "rampeffectsettings.h" +#include "rumbleeffectsettings.h" #include #include @@ -40,6 +42,7 @@ private: ConstantEffectSettings* m_constantEffSet; PeriodicEffectSettings* m_periodicEffSet; RampEffectSettings* m_rampEffSet; + RumbleEffectSettings* m_rumbleEffSet; std::shared_ptr m_prober; Ui::MainWindow* ui; diff --git a/rampeffectsettings.h b/rampeffectsettings.h index ce3f464..d15b957 100644 --- a/rampeffectsettings.h +++ b/rampeffectsettings.h @@ -3,7 +3,7 @@ #include "effectsettings.h" #include "envelopesettings.h" -#include"ffbrampeffectparameters.h" +#include "ffbrampeffectparameters.h" namespace Ui { class RampEffectSettings; diff --git a/rumbleeffectsettings.cpp b/rumbleeffectsettings.cpp new file mode 100644 index 0000000..19e0c78 --- /dev/null +++ b/rumbleeffectsettings.cpp @@ -0,0 +1,39 @@ +#include "rumbleeffectsettings.h" +#include "ui_rumbleeffectsettings.h" + +RumbleEffectSettings::RumbleEffectSettings(QWidget* parent) : + EffectSettings(parent), + ui(new Ui::RumbleEffectSettings) +{ + ui->setupUi(this); +} + +bool RumbleEffectSettings::fillFromParameters(const std::shared_ptr params) +{ + try { + const std::shared_ptr ruParams = std::dynamic_pointer_cast(params); + + ui->qle_strongMag->setText(QString::number(ruParams->strongMagnitude)); + ui->qle_weakMag->setText(QString::number(ruParams->weakMagnitude)); + return true; + } catch (std::bad_cast& ex) { + qCritical(ex.what()); + return false; + } + return false; +} + +QString RumbleEffectSettings::strongMagnitude() const +{ + return ui->qle_strongMag->text(); +} + +QString RumbleEffectSettings::weakMagnitude() const +{ + return ui->qle_weakMag->text(); +} + +RumbleEffectSettings::~RumbleEffectSettings() +{ + delete ui; +} diff --git a/rumbleeffectsettings.h b/rumbleeffectsettings.h new file mode 100644 index 0000000..246f6e1 --- /dev/null +++ b/rumbleeffectsettings.h @@ -0,0 +1,27 @@ +#ifndef RUMBLEEFFECTSETTINGS_H +#define RUMBLEEFFECTSETTINGS_H + +#include "effectsettings.h" +#include "envelopesettings.h" +#include "ffbrumbleeffectparameters.h" + +namespace Ui { +class RumbleEffectSettings; +} + +class RumbleEffectSettings : public EffectSettings +{ + Q_OBJECT + +public: + explicit RumbleEffectSettings(QWidget* parent = nullptr); + ~RumbleEffectSettings(); + bool fillFromParameters(const std::shared_ptr params); + QString strongMagnitude() const; + QString weakMagnitude() const; + +private: + Ui::RumbleEffectSettings *ui; +}; + +#endif // RUMBLEEFFECTSETTINGS_H diff --git a/rumbleeffectsettings.ui b/rumbleeffectsettings.ui new file mode 100644 index 0000000..e399cab --- /dev/null +++ b/rumbleeffectsettings.ui @@ -0,0 +1,55 @@ + + + RumbleEffectSettings + + + + 0 + 0 + 338 + 234 + + + + MainWindow + + + + + + Strong magnitude: + + + + + + + Weak magnitude: + + + + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + -- 2.43.5