]> Devoid-pointer.net GitWeb - FFBChecker.git/commitdiff
Allow bypassing of sanity checks of FFB effect parameters.
authorMichal Malý <madcatxster@prifuk.cz>
Sat, 7 Dec 2013 19:42:28 +0000 (20:42 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Sat, 7 Dec 2013 19:42:28 +0000 (20:42 +0100)
FFBChecker.pro
ffbconditioneffect.cpp
ffbconstanteffect.cpp
ffbeffect.cpp
ffbperiodiceffect.cpp
ffbrampeffect.cpp
globalsettings.cpp [new file with mode: 0644]
globalsettings.h [new file with mode: 0644]
main.cpp
mainwindow.cpp
mainwindow.ui

index 5556cd31968d4cd8ddf1c27d95d6fcc09b06e33d..b55c41a5c99155252d26f2911845f4e405aad8dc 100644 (file)
@@ -34,7 +34,8 @@ SOURCES += main.cpp\
     ffbconditioneffect.cpp \
     rampeffectsettings.cpp \
     ffbrampeffectparameters.cpp \
-    ffbrampeffect.cpp
+    ffbrampeffect.cpp \
+    globalsettings.cpp
 
 HEADERS  += mainwindow.h \
     deviceprober.h \
@@ -59,7 +60,8 @@ HEADERS  += mainwindow.h \
     ffbconditioneffect.h \
     rampeffectsettings.h \
     ffbrampeffectparameters.h \
-    ffbrampeffect.h
+    ffbrampeffect.h \
+    globalsettings.h
 
 FORMS    += mainwindow.ui \
     constanteffectsettings.ui \
index b6cce690df1bb04e9c7bddba175789b2203acbd0..a0dbf4f8c6aac558744c61714dd7836f2841a45f 100644 (file)
@@ -1,4 +1,5 @@
 #include "ffbconditioneffect.h"
+#include "globalsettings.h"
 
 FFBConditionEffect::FFBConditionEffect() :
   FFBEffect(FFBEffectTypes::CONDITION)
@@ -61,63 +62,65 @@ bool FFBConditionEffect::setParameters(const std::shared_ptr<FFBConditionEffectP
   if (!checkGenericParameters(params))
     return false;
 
-  if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
-    reportError("Center X out of bounds,");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
-    reportError("Center Y out of bounds,");
-    return false;
-  }
-
-  if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
-    reportError("Deadband X out of bounds.");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
-    reportError("Deadband Y out of bounds.");
-    return false;
-  }
-
-  if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
-    reportError("Left coefficient X out of bounds.");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
-    reportError("Left coefficient Y out of bounds.");
-    return false;
-  }
-
-  if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
-    reportError("Right coefficient X out of bounds.");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
-    reportError("Right coefficient Y out of bounds.");
-    return false;
-  }
-
-  if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
-    reportError("Left saturation X out of bounds.");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
-    reportError("Left saturation Y out of bounds.");
-    return false;
-  }
-
-  if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
-    reportError("Right saturation X out of bounds.");
-    return false;
-  }
-  if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
-    reportError("Right saturation Y out of bounds.");
-    return false;
-  }
-
-  if (params->subtype == ConditionSubtypes::NONE) {
-    reportError("Invalid subtype");
-    return false;
+  if (GlobalSettings::GS()->doSanityChecks) {
+    if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
+      reportError("Center X out of bounds,");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
+      reportError("Center Y out of bounds,");
+      return false;
+    }
+
+    if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
+      reportError("Deadband X out of bounds.");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
+      reportError("Deadband Y out of bounds.");
+      return false;
+    }
+
+    if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
+      reportError("Left coefficient X out of bounds.");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
+      reportError("Left coefficient Y out of bounds.");
+      return false;
+    }
+
+    if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
+      reportError("Right coefficient X out of bounds.");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
+      reportError("Right coefficient Y out of bounds.");
+      return false;
+    }
+
+    if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
+      reportError("Left saturation X out of bounds.");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
+      reportError("Left saturation Y out of bounds.");
+      return false;
+    }
+
+    if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
+      reportError("Right saturation X out of bounds.");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
+      reportError("Right saturation Y out of bounds.");
+      return false;
+    }
+
+    if (params->subtype == ConditionSubtypes::NONE) {
+      reportError("Invalid subtype");
+      return false;
+    }
   }
 
   m_params = params;
index e713009748df3c939656c710605ed392091e8867..c9616b442854d46315ed9b2c87491585b37d50e2 100644 (file)
@@ -1,4 +1,5 @@
 #include "ffbconstanteffect.h"
+#include "globalsettings.h"
 
 FFBConstantEffect::FFBConstantEffect() :
   FFBEffect(FFBEffectTypes::CONSTANT)
@@ -37,18 +38,27 @@ bool FFBConstantEffect::setParameters(const std::shared_ptr<FFBConstantEffectPar
   if (!checkGenericParameters(params))
     return false;
 
-  if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF))
-    return false;
-  if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF))
-    return false;
-  if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF))
-    return false;
-  if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF))
-    return false;
+  if (GlobalSettings::GS()->doSanityChecks) {
+    if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF)){
+      reportError("Attack length out of bounds");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF)) {
+      reportError("Attack level out of bounds");
+      return false;
+    } if (!checkBoundsInclusive(params->fadeLength, 0, 0xFFFF)) {
+      reportError("Fade length out of bounds");
+      return false;
+    }
+    if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF)) {
+      reportError("Fade level out of bounds");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->level, -0x7FFF, 0x7FFF)) {
-    reportError("Level out of bounds.");
-    return false;
+    if (!checkBoundsInclusive(params->level, -0x7FFF, 0x7FFF)) {
+      reportError("Level out of bounds.");
+      return false;
+    }
   }
 
   m_params = params;
index e0493fc9876c5bc3cf7bdbd1f2dcb22392b12d4d..98a49b871a7257318459235ddfa9c327ab6dc26d 100644 (file)
@@ -1,4 +1,5 @@
 #include "ffbeffect.h"
+#include "globalsettings.h"
 #include <QtWidgets/QMessageBox>
 
 FFBEffect::FFBEffect(FFBEffectTypes type)
@@ -28,6 +29,9 @@ void FFBEffect::reportError(const QString& errorMsg) const
 
 bool FFBEffect::checkGenericParameters(const std::shared_ptr<FFBEffectParameters> params)
 {
+  if (!GlobalSettings::GS()->doSanityChecks)
+    return true;
+
   if (!checkBoundsInclusive(params->direction, 0, 0xFFFF)) {
     reportError("Direction out of bounds.");
     return false;
index 62898dfdbb9452e859cab9ff5452e4a64e7592bc..c9ff718961a657106a9f86aa9b5a73125ab418c4 100644 (file)
@@ -1,4 +1,5 @@
 #include "ffbperiodiceffect.h"
+#include "globalsettings.h"
 #include <QDebug>
 
 FFBPeriodicEffect::FFBPeriodicEffect() :
@@ -62,49 +63,51 @@ bool FFBPeriodicEffect::setParameters(const std::shared_ptr<FFBPeriodicEffectPar
   if (!checkGenericParameters(params))
     return false;
 
-  if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF)) {
-    reportError("Attack length out of bounds.");
-    return false;
-  }
+  if (GlobalSettings::GS()->doSanityChecks) {
+    if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF)) {
+      reportError("Attack length out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF)) {
-    reportError("Attack level out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF)) {
+      reportError("Attack level out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->fadeLength, 0, 0xFFFF)) {
-    reportError("Fade length out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->fadeLength, 0, 0xFFFF)) {
+      reportError("Fade length out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF)) {
-    reportError("Fade level out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF)) {
+      reportError("Fade level out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->magnitude, -0x7FFF, 0x7FFF)) {
-    reportError("Magnitude out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->magnitude, -0x7FFF, 0x7FFF)) {
+      reportError("Magnitude out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->offset, -0x7FFF, 0x7FFF)) {
-    reportError("Offset out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->offset, -0x7FFF, 0x7FFF)) {
+      reportError("Offset out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->period, 0, 0xFFFF)) {
-    reportError("Period out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->period, 0, 0xFFFF)) {
+      reportError("Period out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->phase, 0, 0xFFFF)) {
-    reportError("Phase out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->phase, 0, 0xFFFF)) {
+      reportError("Phase out of bounds.");
+      return false;
+    }
 
-  if (params->waveform == PeriodicWaveforms::NONE) {
-    reportError("Invalid waveform type.");
-    return false;
+    if (params->waveform == PeriodicWaveforms::NONE) {
+      reportError("Invalid waveform type.");
+      return false;
+    }
   }
 
   m_params = params;
index 54d19f7ceba40bb328af6384fd4790ef3aa8f503..97c3afec3fcd9d52d305f5befa7483ede84ed6f3 100644 (file)
@@ -1,4 +1,5 @@
 #include "ffbrampeffect.h"
+#include "globalsettings.h"
 
 FFBRampEffect::FFBRampEffect() :
   FFBEffect(FFBEffectTypes::RAMP)
@@ -40,29 +41,36 @@ bool FFBRampEffect::setParameters(const std::shared_ptr<FFBRampEffectParameters>
   if (!checkGenericParameters(params))
     return false;
 
- if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF)) {
-    reportError("Attack length out of bounds.");
-    return false;
-  }
+  if (GlobalSettings::GS()->doSanityChecks) {
+    if (!checkBoundsInclusive(params->attackLength, 0, 0xFFFF)) {
+      reportError("Attack length out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF)) {
-    reportError("Attack level out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->attackLevel, 0, 0xFFFF)) {
+      reportError("Attack level out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->fadeLength, 0, 0xFFFF)) {
-    reportError("Fade length out of bounds.");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->fadeLength, 0, 0xFFFF)) {
+      reportError("Fade length out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->endLevel, -0x7FFF, 0x7FFF)) {
-    reportError("End level out of bounds");
-    return false;
-  }
+    if (!checkBoundsInclusive(params->fadeLevel, 0, 0xFFFF)) {
+      reportError("Fade level out of bounds.");
+      return false;
+    }
 
-  if (!checkBoundsInclusive(params->startLevel, -0x7FFF, 0x7FFF)) {
-      reportError("Start level out of bounds");
+    if (!checkBoundsInclusive(params->endLevel, -0x7FFF, 0x7FFF)) {
+      reportError("End level out of bounds");
       return false;
+    }
+
+    if (!checkBoundsInclusive(params->startLevel, -0x7FFF, 0x7FFF)) {
+        reportError("Start level out of bounds");
+        return false;
+    }
   }
 
   m_params = params;
diff --git a/globalsettings.cpp b/globalsettings.cpp
new file mode 100644 (file)
index 0000000..6fe3eea
--- /dev/null
@@ -0,0 +1,25 @@
+#include "globalsettings.h"
+
+GlobalSettings* GlobalSettings::s_instance(nullptr);
+
+void GlobalSettings::init(bool doSanityChecks)
+{
+  if (s_instance == nullptr) {
+    s_instance = new GlobalSettings;
+
+    s_instance->doSanityChecks = doSanityChecks;
+  }
+}
+
+const GlobalSettings* GlobalSettings::GS() {
+  return s_instance;
+}
+
+GlobalSettings::GlobalSettings()
+{}
+
+GlobalSettings::~GlobalSettings()
+{
+  delete s_instance;
+  s_instance = nullptr;
+}
diff --git a/globalsettings.h b/globalsettings.h
new file mode 100644 (file)
index 0000000..08c98b1
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef GLOBALSETTINGS_H
+#define GLOBALSETTINGS_H
+
+class GlobalSettings {
+public:
+  static void init(bool doSanityChecks);
+  static const GlobalSettings* GS();
+  explicit GlobalSettings();
+  ~GlobalSettings();
+
+  bool doSanityChecks;
+
+private:
+  static GlobalSettings* s_instance;
+};
+
+#endif // GLOBALSETTINGS_H
index 4d8e1faeda554634212f5788d94bc2c1e6b4b164..e1a8b8b1609915b95c3c7e880195a470411b80fe 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,12 +1,31 @@
 #include "deviceprober.h"
+#include "globalsettings.h"
 #include "mainwindow.h"
 #include <QtWidgets/QApplication>
 
+#include <QDebug>
+
+const QString NO_CHECKS_ARG("--no-checks");
+
 int main(int argc, char** argv)
 {
   QApplication myApp(argc, argv);
   const QString VERSION_STRING = QString(APP_NAME) + " " + QString::number(APP_VERSION_MAJOR) + "." + QString::number(APP_VERSION_MINOR) +
                                  QString(APP_VERSION_REL);
+
+  /* Setup global settings */
+  {
+    bool doSanityChecks;
+    QStringList cmdArgs = QCoreApplication::arguments();
+    if (cmdArgs.contains(NO_CHECKS_ARG)) {
+      doSanityChecks = false;
+      qDebug() << "Disabling effect parameters sanity checks";
+    } else
+      doSanityChecks = true;
+
+   GlobalSettings::init(doSanityChecks);
+  }
+
   std::shared_ptr<DeviceProber> prober(new DeviceProber);
   MainWindow* mWin = new MainWindow(prober, VERSION_STRING);
 
index d7d84bd3151f30ef1ec39a0952596fe7eb3be5d5..f5ae49c2974fdf85d14ef8a5d427505597c3569c 100644 (file)
@@ -1,3 +1,4 @@
+#include "globalsettings.h"
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include <QtWidgets/QMessageBox>
@@ -26,6 +27,9 @@ MainWindow::MainWindow(std::shared_ptr<DeviceProber> prober, const QString& titl
   ui->qstw_effectSpecifics->addWidget(m_periodicEffSet);
   ui->qstw_effectSpecifics->addWidget(m_rampEffSet);
 
+  if (GlobalSettings::GS()->doSanityChecks)
+    ui->ql_noChecksWarning->setHidden(true);
+
   fillDeviceList();
   connect(ui->cbox_devices, SIGNAL(activated(const QString&)), this, SLOT(onDeviceSelected(const QString&)));
   connect(ui->cbox_effectSlots, SIGNAL(activated(const int)), this, SLOT(onEffectSlotSelected(const int)));
index 7183eaea43bd90810e8ad04c05703a7b14b4a753..2292c7faa2d71e464f142487806bd1b93c046e40 100644 (file)
       </item>
      </layout>
     </item>
+    <item>
+     <widget class="QLabel" name="ql_noChecksWarning">
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string>WARNING: Sanity checks disabled!</string>
+      </property>
+      <property name="textFormat">
+       <enum>Qt::PlainText</enum>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignCenter</set>
+      </property>
+     </widget>
+    </item>
    </layout>
   </widget>
  </widget>