From: Michal MalĂ˝ Date: Wed, 4 Dec 2013 16:48:48 +0000 (+0100) Subject: Add support for FF_RAMP, bump version. X-Git-Tag: 0.2d~7 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=99ef45a025eb71caf24992b22422c929d70ed142;p=FFBChecker.git Add support for FF_RAMP, bump version. --- diff --git a/FFBChecker.pro b/FFBChecker.pro index d40811f..5556cd3 100644 --- a/FFBChecker.pro +++ b/FFBChecker.pro @@ -31,7 +31,10 @@ SOURCES += main.cpp\ ffbnulleffect.cpp \ conditioneffectsettings.cpp \ ffbconditioneffectparameters.cpp \ - ffbconditioneffect.cpp + ffbconditioneffect.cpp \ + rampeffectsettings.cpp \ + ffbrampeffectparameters.cpp \ + ffbrampeffect.cpp HEADERS += mainwindow.h \ deviceprober.h \ @@ -53,15 +56,20 @@ HEADERS += mainwindow.h \ ffbnulleffect.h \ conditioneffectsettings.h \ ffbconditioneffectparameters.h \ - ffbconditioneffect.h + ffbconditioneffect.h \ + rampeffectsettings.h \ + ffbrampeffectparameters.h \ + ffbrampeffect.h FORMS += mainwindow.ui \ constanteffectsettings.ui \ envelopesettings.ui \ periodiceffectsettings.ui \ - conditioneffectsettings.ui + conditioneffectsettings.ui \ + rampeffectsettings.ui QMAKE_CXXFLAGS += -std=c++11 -Wall +QMAKE_CXXFLAGS_DEBUG += -ggdb3 OTHER_FILES += \ TODO.txt diff --git a/conditioneffectsettings.cpp b/conditioneffectsettings.cpp index 347237e..15b458a 100644 --- a/conditioneffectsettings.cpp +++ b/conditioneffectsettings.cpp @@ -1,11 +1,24 @@ #include "conditioneffectsettings.h" #include "ui_conditioneffectsettings.h" +#include ConditionEffectSettings::ConditionEffectSettings(QWidget* parent) : EffectSettings(parent), ui(new Ui::ConditionEffectSettings) { ui->setupUi(this); + connect(ui->cbox_axis, SIGNAL(currentIndexChanged(int)), this, SLOT(axisChanged(const int))); +} + +void ConditionEffectSettings::axisChanged(const int idx) +{ + ui->qstw_center->setCurrentIndex(idx); + ui->qstw_deadband->setCurrentIndex(idx); + ui->qstw_leftCoeff->setCurrentIndex(idx); + ui->qstw_leftSat->setCurrentIndex(idx); + ui->qstw_rightCoeff->setCurrentIndex(idx); + ui->qstw_rightSat->setCurrentIndex(idx); + qDebug() << "Axis changed" << idx; } void ConditionEffectSettings::fillAvailableSubtypesList(const QStringList& list) @@ -27,43 +40,91 @@ bool ConditionEffectSettings::fillFromParameters(const std::shared_ptr cdParams) { - ui->qle_center->setText(QString::number(cdParams->center)); - ui->qle_deadband->setText(QString::number(cdParams->deadband)); - ui->qle_leftCoeff->setText(QString::number(cdParams->leftCoeff)); - ui->qle_rightCoeff->setText(QString::number(cdParams->rightCoeff)); - ui->qle_leftSat->setText(QString::number(cdParams->leftSat)); - ui->qle_rightSat->setText(QString::number(cdParams->rightCoeff)); + ui->qle_centerX->setText(QString::number(cdParams->center[FFBConditionEffectParameters::Axis::X])); + ui->qle_deadbandX->setText(QString::number(cdParams->deadband[FFBConditionEffectParameters::Axis::X])); + ui->qle_leftCoeffX->setText(QString::number(cdParams->leftCoeff[FFBConditionEffectParameters::Axis::X])); + ui->qle_rightCoeffX->setText(QString::number(cdParams->rightCoeff[FFBConditionEffectParameters::Axis::X])); + ui->qle_leftSatX->setText(QString::number(cdParams->leftSat[FFBConditionEffectParameters::Axis::X])); + ui->qle_rightSatX->setText(QString::number(cdParams->rightCoeff[FFBConditionEffectParameters::Axis::X])); + ui->qle_centerY->setText(QString::number(cdParams->center[FFBConditionEffectParameters::Axis::Y])); + ui->qle_deadbandY->setText(QString::number(cdParams->deadband[FFBConditionEffectParameters::Axis::Y])); + ui->qle_leftCoeffY->setText(QString::number(cdParams->leftCoeff[FFBConditionEffectParameters::Axis::Y])); + ui->qle_rightCoeffY->setText(QString::number(cdParams->rightCoeff[FFBConditionEffectParameters::Axis::Y])); + ui->qle_leftSatY->setText(QString::number(cdParams->leftSat[FFBConditionEffectParameters::Axis::Y])); + ui->qle_rightSatY->setText(QString::number(cdParams->rightCoeff[FFBConditionEffectParameters::Axis::Y])); return true; } -QString ConditionEffectSettings::center() const +FFBConditionEffectParameters::Axis ConditionEffectSettings::axis() const +{ + switch (ui->cbox_axis->currentIndex()) { + case 0: + return FFBConditionEffectParameters::Axis::X; + case 1: + return FFBConditionEffectParameters::Axis::Y; + default: + return FFBConditionEffectParameters::Axis::NONE; + } +} + +QString ConditionEffectSettings::centerX() const +{ + return ui->qle_centerX->text(); +} + +QString ConditionEffectSettings::centerY() const +{ + return ui->qle_centerY->text(); +} + +QString ConditionEffectSettings::deadbandX() const +{ + return ui->qle_deadbandX->text(); +} + +QString ConditionEffectSettings::deadbandY() const +{ + return ui->qle_deadbandY->text(); +} + +QString ConditionEffectSettings::leftCoeffX() const +{ + return ui->qle_leftCoeffX->text(); +} + +QString ConditionEffectSettings::leftCoeffY() const +{ + return ui->qle_leftCoeffY->text(); +} + +QString ConditionEffectSettings::rightCoeffX() const { - return ui->qle_center->text(); + return ui->qle_rightCoeffX->text(); } -QString ConditionEffectSettings::deadband() const +QString ConditionEffectSettings::rightCoeffY() const { - return ui->qle_deadband->text(); + return ui->qle_rightCoeffY->text(); } -QString ConditionEffectSettings::leftCoeff() const +QString ConditionEffectSettings::leftSatX() const { - return ui->qle_leftCoeff->text(); + return ui->qle_leftSatX->text(); } -QString ConditionEffectSettings::rightCoeff() const +QString ConditionEffectSettings::leftSatY() const { - return ui->qle_rightCoeff->text(); + return ui->qle_leftSatY->text(); } -QString ConditionEffectSettings::leftSat() const +QString ConditionEffectSettings::rightSatX() const { - return ui->qle_leftSat->text(); + return ui->qle_rightSatX->text(); } -QString ConditionEffectSettings::rightSat() const +QString ConditionEffectSettings::rightSatY() const { - return ui->qle_rightSat->text(); + return ui->qle_rightSatY->text(); } int ConditionEffectSettings::subtypeIdx() const diff --git a/conditioneffectsettings.h b/conditioneffectsettings.h index a6f5a28..5dd680d 100644 --- a/conditioneffectsettings.h +++ b/conditioneffectsettings.h @@ -17,16 +17,26 @@ public: void fillAvailableSubtypesList(const QStringList& list); bool fillFromParameters(const std::shared_ptr params); bool fillFromParameters(const std::shared_ptr cdParams); - QString center() const; - QString deadband() const; - QString leftCoeff() const; - QString rightCoeff() const; - QString leftSat() const; - QString rightSat() const; + FFBConditionEffectParameters::Axis axis() const; + QString centerX() const; + QString centerY() const; + QString deadbandX() const; + QString deadbandY() const; + QString leftCoeffX() const; + QString leftCoeffY() const; + QString rightCoeffX() const; + QString rightCoeffY() const; + QString leftSatX() const; + QString leftSatY() const; + QString rightSatX() const; + QString rightSatY() const; int subtypeIdx() const; private: Ui::ConditionEffectSettings* ui; + +private slots: + void axisChanged(const int); }; #endif // CONDITIONEFFECTSETTINGS_H diff --git a/conditioneffectsettings.ui b/conditioneffectsettings.ui index d1a155e..085fed1 100644 --- a/conditioneffectsettings.ui +++ b/conditioneffectsettings.ui @@ -19,68 +19,92 @@ QFormLayout::AllNonFixedFieldsGrow - + + + + 0 + 0 + + Left saturation: - - - - + + + + 0 + 0 + + Right saturation: - - - - + + + + 0 + 0 + + Left coefficient: - - - - + + + + 0 + 0 + + Right coefficient: - - - - + + + + 0 + 0 + + Deadband: - + + + + 0 + 0 + + Center: - - - - - - + + + 0 + 0 + + Subtype: @@ -89,6 +113,291 @@ + + + + + 0 + 0 + + + + Axis: + + + + + + + 0 + + + + X + + + + + Y + + + + + + + + + 0 + 0 + + + + 0 + + + + + + + + 0 + 0 + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 1 + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 1 + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 1 + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + 6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + diff --git a/ffbconditioneffect.cpp b/ffbconditioneffect.cpp index b282d7e..b6cce69 100644 --- a/ffbconditioneffect.cpp +++ b/ffbconditioneffect.cpp @@ -8,12 +8,19 @@ struct ff_effect* FFBConditionEffect::createFFStruct() { struct ff_effect* eff = FFBEffect::createFFStruct(m_params); - eff->u.condition[0].center = m_params->center; - eff->u.condition[0].deadband = m_params->deadband; - eff->u.condition[0].left_coeff = m_params->leftCoeff; - eff->u.condition[0].right_coeff = m_params->rightCoeff; - eff->u.condition[0].left_saturation = m_params->leftSat; - eff->u.condition[0].right_saturation = m_params->rightSat; + eff->u.condition[0].center = m_params->center[FFBConditionEffectParameters::Axis::X]; + eff->u.condition[0].deadband = m_params->deadband[FFBConditionEffectParameters::Axis::X]; + eff->u.condition[0].left_coeff = m_params->leftCoeff[FFBConditionEffectParameters::Axis::X]; + eff->u.condition[0].right_coeff = m_params->rightCoeff[FFBConditionEffectParameters::Axis::X]; + eff->u.condition[0].left_saturation = m_params->leftSat[FFBConditionEffectParameters::Axis::X]; + eff->u.condition[0].right_saturation = m_params->rightSat[FFBConditionEffectParameters::Axis::X]; + + eff->u.condition[1].center = m_params->center[FFBConditionEffectParameters::Axis::Y]; + eff->u.condition[1].deadband = m_params->deadband[FFBConditionEffectParameters::Axis::Y]; + eff->u.condition[1].left_coeff = m_params->leftCoeff[FFBConditionEffectParameters::Axis::Y]; + eff->u.condition[1].right_coeff = m_params->rightCoeff[FFBConditionEffectParameters::Axis::Y]; + eff->u.condition[1].left_saturation = m_params->leftSat[FFBConditionEffectParameters::Axis::Y]; + eff->u.condition[1].right_saturation = m_params->rightSat[FFBConditionEffectParameters::Axis::Y]; switch (m_params->subtype) { case ConditionSubtypes::DAMPER: @@ -40,9 +47,9 @@ struct ff_effect* FFBConditionEffect::createFFStruct() bool FFBConditionEffect::setParameters(const std::shared_ptr params) { try { - const std::shared_ptr cdParams = std::dynamic_pointer_cast(params); - return setParameters(cdParams); - } catch (std::bad_cast& ex) { + return setParameters(std::dynamic_pointer_cast(params)); + //return setParameters(cdParams); + } catch (const std::bad_cast& ex) { qCritical(ex.what()); return false; } @@ -54,33 +61,57 @@ bool FFBConditionEffect::setParameters(const std::shared_ptrcenter, -0x7FFF, 0x7FFF)) { - reportError("Center out of bounds,"); + 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, 0, 0xFFFF)) { - reportError("Deadband out of bounds."); + 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, -0x7FFF, 0x7FFF)) { - reportError("Left coefficient out of bounds."); + 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, -0x7FFF, 0x7FFF)) { - reportError("Right coefficient out of bounds."); + 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, 0, 0xFFFF)) { - reportError("Left saturation out of bounds."); + 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, 0, 0xFFFF)) { - reportError("Right saturation out of bounds."); + 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; } diff --git a/ffbconditioneffectparameters.cpp b/ffbconditioneffectparameters.cpp index dc21949..9980474 100644 --- a/ffbconditioneffectparameters.cpp +++ b/ffbconditioneffectparameters.cpp @@ -1,43 +1,67 @@ #include "ffbconditioneffectparameters.h" FFBConditionEffectParameters::FFBConditionEffectParameters() : - FFBEffectParameters(), - center(0), - deadband(0), - leftCoeff(0), - rightCoeff(0), - leftSat(0), - rightSat(0) + FFBEffectParameters() {} -bool FFBConditionEffectParameters::centerFromString(const QString& center) +bool FFBConditionEffectParameters::centerFromString(const QString& center, Axis a) { - return qstringToInt(this->center, center); + bool ok = false; + int val = center.toInt(&ok); + if (!ok) return false; + + this->center[a] = val; + return true; } -bool FFBConditionEffectParameters::deadbandFromString(const QString& deadband) +bool FFBConditionEffectParameters::deadbandFromString(const QString& deadband, Axis a) { - return qstringToInt(this->deadband, deadband); + bool ok = false; + int val = deadband.toInt(&ok); + if (!ok) return false; + + this->deadband[a] = val; + return true; } -bool FFBConditionEffectParameters::leftCoeffFromString(const QString& leftCoeff) +bool FFBConditionEffectParameters::leftCoeffFromString(const QString& leftCoeff, Axis a) { - return qstringToInt(this->leftCoeff, leftCoeff); + bool ok = false; + int val = leftCoeff.toInt(&ok); + if (!ok) return false; + + this->leftCoeff[a] = val; + return true; } -bool FFBConditionEffectParameters::rightCoeffFromString(const QString& rightCoeff) +bool FFBConditionEffectParameters::rightCoeffFromString(const QString& rightCoeff, Axis a) { - return qstringToInt(this->rightCoeff, rightCoeff); + bool ok = false; + int val = rightCoeff.toInt(&ok); + if (!ok) return false; + + this->rightCoeff[a] = val; + return true; } -bool FFBConditionEffectParameters::leftSatFromString(const QString& leftSat) +bool FFBConditionEffectParameters::leftSatFromString(const QString& leftSat, Axis a) { - return qstringToInt(this->leftSat, leftSat); + bool ok = false; + int val = leftSat.toInt(&ok); + if (!ok) return false; + + this->leftSat[a] = val; + return true; } -bool FFBConditionEffectParameters::rightSatFromString(const QString& rightSat) +bool FFBConditionEffectParameters::rightSatFromString(const QString& rightSat, Axis a) { - return qstringToInt(this->rightSat, rightSat); + bool ok = false; + int val = rightSat.toInt(&ok); + if (!ok) return false; + + this->rightSat[a] = val; + return true; } diff --git a/ffbconditioneffectparameters.h b/ffbconditioneffectparameters.h index 9805a7f..9e16335 100644 --- a/ffbconditioneffectparameters.h +++ b/ffbconditioneffectparameters.h @@ -2,25 +2,31 @@ #define FFBCONDITIONEFFECTPARAMETERS_H #include "ffbeffectparameters.h" +#include class FFBConditionEffectParameters : public FFBEffectParameters { public: + enum class Axis : quint8 { NONE = 0, X = 1, Y = 2 }; + struct Axis_less { + bool operator()(Axis a, Axis b) const { return quint8(a) == quint8(b); } + }; + FFBConditionEffectParameters(); - bool centerFromString(const QString& center); - bool deadbandFromString(const QString& deadband); - bool leftCoeffFromString(const QString& leftCoeff); - bool rightCoeffFromString(const QString& rightCoeff); - bool leftSatFromString(const QString& leftSat); - bool rightSatFromString(const QString& rightSat); + bool centerFromString(const QString& center, Axis a); + bool deadbandFromString(const QString& deadband, Axis a); + bool leftCoeffFromString(const QString& leftCoeff, Axis a); + bool rightCoeffFromString(const QString& rightCoeff, Axis a); + bool leftSatFromString(const QString& leftSat, Axis a); + bool rightSatFromString(const QString& rightSat, Axis a); inline void subtypeFromIdx(const ConditionSubtypes subtype) { this->subtype = subtype; } - int center; - int deadband; - int leftCoeff; - int rightCoeff; - int leftSat; - int rightSat; + std::map center; + std::map deadband; + std::map leftCoeff; + std::map rightCoeff; + std::map leftSat; + std::map rightSat; ConditionSubtypes subtype; private: inline bool qstringToInt(int& val, const QString& str) { diff --git a/ffbeffectfactory.cpp b/ffbeffectfactory.cpp index 8b01a0f..38d02e3 100644 --- a/ffbeffectfactory.cpp +++ b/ffbeffectfactory.cpp @@ -15,6 +15,8 @@ std::shared_ptr FFBEffectFactory::createEffect(FFBEffectTypes type) return std::shared_ptr(new FFBPeriodicEffect()); case FFBEffectTypes::CONDITION: return std::shared_ptr(new FFBConditionEffect()); + case FFBEffectTypes::RAMP: + return std::shared_ptr(new FFBRampEffect()); default: return nullptr; } diff --git a/ffbeffectfactory.h b/ffbeffectfactory.h index 6842d74..078dcca 100644 --- a/ffbeffectfactory.h +++ b/ffbeffectfactory.h @@ -6,6 +6,7 @@ #include "ffbconstanteffect.h" #include "ffbnulleffect.h" #include "ffbperiodiceffect.h" +#include "ffbrampeffect.h" class FFBEffectFactory { diff --git a/ffbnulleffect.h b/ffbnulleffect.h index 96a1ffe..5829574 100644 --- a/ffbnulleffect.h +++ b/ffbnulleffect.h @@ -9,7 +9,7 @@ public: explicit FFBNullEffect(); inline struct ff_effect* createFFStruct() { return nullptr; } inline const std::shared_ptr parameters() const { return nullptr; } - inline bool setParameters(const std::shared_ptr params) { return false; } + inline bool setParameters(const std::shared_ptr params) { (void)(params); return false; } }; #endif // FFBNULLEFFECT_H diff --git a/ffbrampeffect.cpp b/ffbrampeffect.cpp new file mode 100644 index 0000000..54d19f7 --- /dev/null +++ b/ffbrampeffect.cpp @@ -0,0 +1,74 @@ +#include "ffbrampeffect.h" + +FFBRampEffect::FFBRampEffect() : + FFBEffect(FFBEffectTypes::RAMP) +{ +} + +struct ff_effect* FFBRampEffect::createFFStruct() +{ + struct ff_effect* eff = FFBEffect::createFFStruct(m_params); + if (eff == nullptr) + return nullptr; + + eff->type = FF_RAMP; + + eff->u.ramp.envelope.attack_length = m_params->attackLength; + eff->u.ramp.envelope.attack_level = m_params->attackLevel; + eff->u.ramp.envelope.fade_length = m_params->fadeLength; + eff->u.ramp.envelope.fade_level = m_params->fadeLevel; + + eff->u.ramp.end_level = m_params->endLevel; + eff->u.ramp.start_level = m_params->startLevel; + + return eff; +} + + +bool FFBRampEffect::setParameters(const std::shared_ptr params) +{ + try { + return setParameters(std::dynamic_pointer_cast(params)); + } catch (const std::bad_cast& ex) { + reportError("Invalid effect parameters object " + QString(ex.what())); + return false; + } +} + +bool FFBRampEffect::setParameters(const std::shared_ptr params) +{ + if (!checkGenericParameters(params)) + return false; + + 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->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; + return true; +} + +FFBRampEffect::~FFBRampEffect() +{ +} diff --git a/ffbrampeffect.h b/ffbrampeffect.h new file mode 100644 index 0000000..b4ab26e --- /dev/null +++ b/ffbrampeffect.h @@ -0,0 +1,21 @@ +#ifndef FFBRAMPEFFECT_H +#define FFBRAMPEFFECT_H + +#include "ffbeffect.h" +#include "ffbrampeffectparameters.h" + +class FFBRampEffect : public FFBEffect +{ +public: + FFBRampEffect(); + ~FFBRampEffect(); + 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 // FFBRAMPEFFECT_H diff --git a/ffbrampeffectparameters.cpp b/ffbrampeffectparameters.cpp new file mode 100644 index 0000000..5b43774 --- /dev/null +++ b/ffbrampeffectparameters.cpp @@ -0,0 +1,23 @@ +#include "ffbrampeffectparameters.h" + +FFBRampEffectParameters::FFBRampEffectParameters() : + FFBEffectParameters(), FFBEnvelopeParameters(), + endLevel(0), + startLevel(0) +{ +} + +bool FFBRampEffectParameters::endLevelFromString(const QString& endLevel) +{ + bool ok; + this->endLevel = endLevel.toInt(&ok); + return ok; +} + +bool FFBRampEffectParameters::startLevelFromString(const QString& startLevel) +{ + bool ok; + this->startLevel = startLevel.toInt(&ok); + return ok; +} + diff --git a/ffbrampeffectparameters.h b/ffbrampeffectparameters.h new file mode 100644 index 0000000..3b0f87b --- /dev/null +++ b/ffbrampeffectparameters.h @@ -0,0 +1,18 @@ +#ifndef FFBRAMPEFFECTPARAMETERS_H +#define FFBRAMPEFFECTPARAMETERS_H + +#include "ffbeffectparameters.h" +#include "ffbenvelopeparameters.h" + +class FFBRampEffectParameters : public FFBEffectParameters, public FFBEnvelopeParameters +{ +public: + FFBRampEffectParameters(); + bool endLevelFromString(const QString& endLevel); + bool startLevelFromString(const QString& startLevel); + + int endLevel; + int startLevel; +}; + +#endif // FFBRAMPEFFECTPARAMETERS_H diff --git a/globals.h b/globals.h index ed8d45a..1760468 100644 --- a/globals.h +++ b/globals.h @@ -4,7 +4,7 @@ #define APP_NAME "FFBChecker" static const int APP_VERSION_MAJOR(0); static const int APP_VERSION_MINOR(2); -static const char APP_VERSION_REL('a'); +static const char APP_VERSION_REL('b'); enum class FFBEffectTypes { NONE, CONSTANT, PERIODIC, RAMP, CONDITION, RUMBLE}; enum class PeriodicWaveforms { NONE, SQUARE, TRIANGLE, SINE, SAW_UP, SAW_DOWN }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 5b72e71..d7d84bd 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,9 +20,11 @@ MainWindow::MainWindow(std::shared_ptr prober, const QString& titl m_constantEffSet = new ConstantEffectSettings(); m_periodicEffSet = new PeriodicEffectSettings(); m_conditionEffSet = new ConditionEffectSettings(); + m_rampEffSet = new RampEffectSettings(); ui->qstw_effectSpecifics->addWidget(m_conditionEffSet); ui->qstw_effectSpecifics->addWidget(m_constantEffSet); ui->qstw_effectSpecifics->addWidget(m_periodicEffSet); + ui->qstw_effectSpecifics->addWidget(m_rampEffSet); fillDeviceList(); connect(ui->cbox_devices, SIGNAL(activated(const QString&)), this, SLOT(onDeviceSelected(const QString&))); @@ -43,6 +45,8 @@ EffectSettings* MainWindow::effectSettingsByType(FFBEffectTypes type) return m_periodicEffSet; case FFBEffectTypes::CONDITION: return m_conditionEffSet; + case FFBEffectTypes::RAMP: + return m_rampEffSet; default: abort(); } @@ -243,38 +247,82 @@ bool MainWindow::readEffectParameters(std::shared_ptr& para } case FFBEffectTypes::CONDITION: { - std::shared_ptr cdParams = std::shared_ptr(new FFBConditionEffectParameters); - if (!readGeneralEffectParameters(params)) + std::shared_ptr iParams = std::shared_ptr(new FFBConditionEffectParameters); + if (!readGeneralEffectParameters(iParams)) return false; - if (!cdParams->centerFromString(m_conditionEffSet->center())) { + if (!iParams->centerFromString(m_conditionEffSet->centerX(), FFBConditionEffectParameters::Axis::X)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Center\""); return false; } - if (!cdParams->deadbandFromString(m_conditionEffSet->deadband())) { + if (!iParams->centerFromString(m_conditionEffSet->centerY(), FFBConditionEffectParameters::Axis::Y)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Center\""); + return false; + } + if (!iParams->deadbandFromString(m_conditionEffSet->deadbandX(), FFBConditionEffectParameters::Axis::X)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Deadband\""); + return false; + } + if (!iParams->deadbandFromString(m_conditionEffSet->deadbandY(), FFBConditionEffectParameters::Axis::Y)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Deadband\""); return false; } - if (!cdParams->leftCoeffFromString(m_conditionEffSet->leftCoeff())) { + if (!iParams->leftCoeffFromString(m_conditionEffSet->leftCoeffX(), FFBConditionEffectParameters::Axis::X)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left coefficient\""); return false; } - if (!cdParams->rightCoeffFromString(m_conditionEffSet->rightCoeff())) { + if (!iParams->leftCoeffFromString(m_conditionEffSet->leftCoeffY(), FFBConditionEffectParameters::Axis::Y)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left coefficient\""); + return false; + } + if (!iParams->rightCoeffFromString(m_conditionEffSet->rightCoeffX(), FFBConditionEffectParameters::Axis::X)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right coefficient\""); + return false; + } + if (!iParams->rightCoeffFromString(m_conditionEffSet->rightCoeffY(), FFBConditionEffectParameters::Axis::Y)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right coefficient\""); return false; } - if (!cdParams->leftSatFromString(m_conditionEffSet->leftSat())) { + if (!iParams->leftSatFromString(m_conditionEffSet->leftSatX(), FFBConditionEffectParameters::Axis::X)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left saturation\""); + return false; + } + if (!iParams->leftSatFromString(m_conditionEffSet->leftSatY(), FFBConditionEffectParameters::Axis::Y)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left saturation\""); return false; } - if (!cdParams->rightSatFromString(m_conditionEffSet->rightSat())) { + if (!iParams->rightSatFromString(m_conditionEffSet->rightSatX(), FFBConditionEffectParameters::Axis::X)) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right saturation\""); + return false; + } + if (!iParams->rightSatFromString(m_conditionEffSet->rightSatY(), FFBConditionEffectParameters::Axis::Y)) { QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right saturation\""); return false; } ConditionSubtypes subtype = m_activeDevice->conditionSubtypeByIdx(m_conditionEffSet->subtypeIdx()); - cdParams->subtypeFromIdx(subtype); + iParams->subtypeFromIdx(subtype); + + params = iParams; + break; + } + case FFBEffectTypes::RAMP: { + std::shared_ptr iParams = std::shared_ptr(new FFBRampEffectParameters); + if (!readGeneralEffectParameters(iParams)) + return false; + if (!readEnvelopeParameters(iParams, m_rampEffSet->envelopeSettings())) + return false; - params = cdParams; + if (!iParams->endLevelFromString(m_rampEffSet->endLevel())) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"End level\""); + return false; + } + if (!iParams->startLevelFromString(m_rampEffSet->startLevel())) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Start level\""); + return false; + } + + params = iParams; + break; } default: qDebug() << "Unhandled type of effect"; diff --git a/mainwindow.h b/mainwindow.h index 6c64e8b..bfc58fd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,7 +7,9 @@ #include "ffbconstanteffectparameters.h" #include "ffbdevice.h" #include "ffbperiodiceffectparameters.h" +#include "ffbrampeffectparameters.h" #include "periodiceffectsettings.h" +#include "rampeffectsettings.h" #include #include @@ -37,6 +39,7 @@ private: ConditionEffectSettings* m_conditionEffSet; ConstantEffectSettings* m_constantEffSet; PeriodicEffectSettings* m_periodicEffSet; + RampEffectSettings* m_rampEffSet; std::shared_ptr m_prober; Ui::MainWindow* ui; diff --git a/rampeffectsettings.cpp b/rampeffectsettings.cpp new file mode 100644 index 0000000..4152073 --- /dev/null +++ b/rampeffectsettings.cpp @@ -0,0 +1,44 @@ +#include "rampeffectsettings.h" +#include "ui_rampeffectsettings.h" + +RampEffectSettings::RampEffectSettings(QWidget* parent) : + EffectSettings(parent), + ui(new Ui::RampEffectSettings) +{ + ui->setupUi(this); +} + +const EnvelopeSettings* RampEffectSettings::envelopeSettings() const +{ + return ui->qwid_envelope; +} + +QString RampEffectSettings::endLevel() const +{ + return ui->qle_endLevel->text(); +} + +QString RampEffectSettings::startLevel() const +{ + return ui->qle_startLevel->text(); +} + +bool RampEffectSettings::fillFromParameters(const std::shared_ptr params) +{ + try { + const std::shared_ptr rfParams = std::dynamic_pointer_cast(params); + + ui->qle_endLevel->setText(QString::number(rfParams->endLevel)); + ui->qle_startLevel->setText(QString::number(rfParams->startLevel)); + return ui->qwid_envelope->fillFromParameters(params); + } catch (std::bad_cast& ex) { + qCritical(ex.what()); + return false; + } + return false; +} + +RampEffectSettings::~RampEffectSettings() +{ + delete ui; +} diff --git a/rampeffectsettings.h b/rampeffectsettings.h new file mode 100644 index 0000000..ce3f464 --- /dev/null +++ b/rampeffectsettings.h @@ -0,0 +1,28 @@ +#ifndef RAMPEFFECTSETTINGS_H +#define RAMPEFFECTSETTINGS_H + +#include "effectsettings.h" +#include "envelopesettings.h" +#include"ffbrampeffectparameters.h" + +namespace Ui { + class RampEffectSettings; +} + +class RampEffectSettings : public EffectSettings +{ + Q_OBJECT + +public: + explicit RampEffectSettings(QWidget* parent = nullptr); + ~RampEffectSettings(); + const EnvelopeSettings* envelopeSettings() const; + bool fillFromParameters(const std::shared_ptr params); + QString endLevel() const; + QString startLevel() const; + +private: + Ui::RampEffectSettings *ui; +}; + +#endif // RAMPEFFECTSETTINGS_H diff --git a/rampeffectsettings.ui b/rampeffectsettings.ui new file mode 100644 index 0000000..299a084 --- /dev/null +++ b/rampeffectsettings.ui @@ -0,0 +1,70 @@ + + + RampEffectSettings + + + + 0 + 0 + 400 + 84 + + + + Form + + + + + + + + Start level: + + + + + + + End level: + + + + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + EnvelopeSettings + QWidget +
envelopesettings.h
+ 1 +
+
+ + +