]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Add support for FF_RUMBLE
authorMichal Malý <madcatxster@prifuk.cz>
Wed, 5 Mar 2014 11:23:57 +0000 (12:23 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Wed, 5 Mar 2014 11:23:57 +0000 (12:23 +0100)
16 files changed:
FFBChecker.pro
effectsettings.h
ffbdevice.cpp
ffbeffectfactory.cpp
ffbeffectfactory.h
ffbrumbleeffect.cpp [new file with mode: 0644]
ffbrumbleeffect.h [new file with mode: 0644]
ffbrumbleeffectparameters.cpp [new file with mode: 0644]
ffbrumbleeffectparameters.h [new file with mode: 0644]
globals.h
mainwindow.cpp
mainwindow.h
rampeffectsettings.h
rumbleeffectsettings.cpp [new file with mode: 0644]
rumbleeffectsettings.h [new file with mode: 0644]
rumbleeffectsettings.ui [new file with mode: 0644]

index b55c41a5c99155252d26f2911845f4e405aad8dc..3fbff7ad8c7e7ec5891d4388c9be4e3b9ea433fb 100644 (file)
@@ -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
index 14f42ff90a1576e7e09d68958822dd5a795ff026..0143c2da1a2b817d66a8b7a638eb11e6074eb77e 100644 (file)
@@ -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<FFBEffectParameters> params) = 0;
 
 signals:
index 9df7e729524f18d2134f45dd0890804a22c8c0f3..57e58381146137806b65e901577187babc2d4070 100644 (file)
@@ -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)) {
index 38d02e3cb24a50412315431e5fe360499b7dcce5..41462cf7e7dfd3edc77a23fd1421ae2b96ab36ba 100644 (file)
@@ -17,6 +17,8 @@ std::shared_ptr<FFBEffect> FFBEffectFactory::createEffect(FFBEffectTypes type)
       return std::shared_ptr<FFBEffect>(new FFBConditionEffect());
     case FFBEffectTypes::RAMP:
       return std::shared_ptr<FFBEffect>(new FFBRampEffect());
+    case FFBEffectTypes::RUMBLE:
+      return std::shared_ptr<FFBEffect>(new FFBRumbleEffect());
     default:
       return nullptr;
   }
index 078dccab9ac5a0d895fe653b680d6f66d4281610..a276be930b35ae3c2d8df612d80e3883bf5d8af7 100644 (file)
@@ -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 (file)
index 0000000..1eee734
--- /dev/null
@@ -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<FFBEffectParameters> params)
+{
+  try {
+    return setParameters(std::dynamic_pointer_cast<FFBRumbleEffectParameters>(params));
+  } catch (std::bad_cast& ex) {
+    reportError("Invalid effect parameters object " + QString(ex.what()));
+    return false;
+  }
+}
+
+bool FFBRumbleEffect::setParameters(const std::shared_ptr<FFBRumbleEffectParameters> params)
+{
+  if (!checkGenericParameters(params))
+    return false;
+
+  if (!checkBoundsInclusive(params->strongMagnitude, static_cast<quint16>(0), static_cast<quint16>(0xFFFF))) {
+    reportError("Strong magnitude out of bounds");
+    return false;
+  }
+
+  if (!checkBoundsInclusive(params->weakMagnitude, static_cast<quint16>(0), static_cast<quint16>(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 (file)
index 0000000..e0075c3
--- /dev/null
@@ -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<FFBEffectParameters> parameters() const { return m_params; }
+  bool setParameters(const std::shared_ptr<FFBEffectParameters> params);
+  bool setParameters(const std::shared_ptr<FFBRumbleEffectParameters> params);
+
+private:
+  std::shared_ptr<FFBRumbleEffectParameters> m_params;
+};
+
+#endif // FFBRUMBLEEFFECT_H
diff --git a/ffbrumbleeffectparameters.cpp b/ffbrumbleeffectparameters.cpp
new file mode 100644 (file)
index 0000000..5b5cb67
--- /dev/null
@@ -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 (file)
index 0000000..f901c8e
--- /dev/null
@@ -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
index aa211495efd02938eeb7e3d187b81a88f1c15c37..e2e2a63b65cc496c47828ee1b16e62a4b87edaff 100644 (file)
--- 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 };
 
index 50a62e91616debeb450325f818164d5de34be24d..bff315cac846eee0b0e015079bb0039e9dffab69 100644 (file)
@@ -22,10 +22,12 @@ MainWindow::MainWindow(std::shared_ptr<DeviceProber> 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<FFBEffectParameters>& para
       params = iParams;
       break;
     }
+    case FFBEffectTypes::RUMBLE: {
+      std::shared_ptr<FFBRumbleEffectParameters> 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;
index bfc58fd5d024b63ac15260c5b2173a6d0a3ccef1..33687ce477050d73d6072e0f7d7a76cf9bfc0701 100644 (file)
@@ -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 <memory>
 #include <QMainWindow>
 
@@ -40,6 +42,7 @@ private:
   ConstantEffectSettings* m_constantEffSet;
   PeriodicEffectSettings* m_periodicEffSet;
   RampEffectSettings* m_rampEffSet;
+  RumbleEffectSettings* m_rumbleEffSet;
   std::shared_ptr<DeviceProber> m_prober;
   Ui::MainWindow* ui;
 
index ce3f464b4a564b66d86185bfa771f9fa3fd952cf..d15b957816e86d07ab5e406dad7901773cba0978 100644 (file)
@@ -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 (file)
index 0000000..19e0c78
--- /dev/null
@@ -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<FFBEffectParameters> params)
+{
+  try {
+    const std::shared_ptr<FFBRumbleEffectParameters> ruParams = std::dynamic_pointer_cast<FFBRumbleEffectParameters>(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 (file)
index 0000000..246f6e1
--- /dev/null
@@ -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<FFBEffectParameters> 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 (file)
index 0000000..e399cab
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>RumbleEffectSettings</class>
+ <widget class="QWidget" name="RumbleEffectSettings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>338</width>
+    <height>234</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <layout class="QFormLayout" name="formLayout">
+   <item row="1" column="0">
+    <widget class="QLabel" name="ql_strongMag">
+     <property name="text">
+      <string>Strong magnitude:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="ql_weakMag">
+     <property name="text">
+      <string>Weak magnitude:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QLineEdit" name="qle_strongMag">
+     <property name="text">
+      <string>0</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QLineEdit" name="qle_weakMag">
+     <property name="text">
+      <string>0</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>