From 67cab25cfd7307cec57d6ca5872daf7df44b2143 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Sun, 15 Dec 2013 12:09:52 +0100 Subject: [PATCH] - Fix updatable effects handling - Version bump --- ffbconditioneffect.cpp | 14 +++++++++++ ffbconditioneffect.h | 1 + ffbdevice.cpp | 54 ++++++++++++++---------------------------- ffbdevice.h | 1 - ffbperiodiceffect.cpp | 5 ---- ffbperiodiceffect.h | 1 - globals.h | 2 +- 7 files changed, 34 insertions(+), 44 deletions(-) diff --git a/ffbconditioneffect.cpp b/ffbconditioneffect.cpp index 56961c2..7e6ef21 100644 --- a/ffbconditioneffect.cpp +++ b/ffbconditioneffect.cpp @@ -125,3 +125,17 @@ bool FFBConditionEffect::setParameters(const std::shared_ptrtype() != other.type()) + return false; + else { + try { + const FFBConditionEffect& cother = dynamic_cast(other); + return this->m_params->subtype == cother.m_params->subtype; + } catch (std::bad_cast&) { + return false; + } + } +} diff --git a/ffbconditioneffect.h b/ffbconditioneffect.h index 34a3699..8bc7869 100644 --- a/ffbconditioneffect.h +++ b/ffbconditioneffect.h @@ -12,6 +12,7 @@ public: inline const std::shared_ptr parameters() const { return m_params; } bool setParameters(const std::shared_ptr params); bool setParameters(const std::shared_ptr params); + bool operator==(const FFBEffect& other) const; private: std::shared_ptr m_params; diff --git a/ffbdevice.cpp b/ffbdevice.cpp index 63ec856..b3c93f5 100644 --- a/ffbdevice.cpp +++ b/ffbdevice.cpp @@ -110,24 +110,6 @@ unsigned int FFBDevice::effectTypeToIdx(FFBEffectTypes type) return 0; } -bool FFBDevice::isEffectUpdateable(const std::shared_ptr effect, const std::shared_ptr params, const FFBEffectTypes type) -{ - if (effect->type() != type) - return false; - if (type == FFBEffectTypes::PERIODIC) { - const std::shared_ptr pParams; - try { - PeriodicWaveforms waveform = std::dynamic_pointer_cast(effect->parameters())->waveform; - if (waveform != std::dynamic_pointer_cast(params)->waveform) - return false; - } catch (std::bad_cast& ex) { - qDebug() << ex.what(); - return false; - } - } - return true; -} - QString FFBDevice::waveformName(const PeriodicWaveforms waveform) const { switch (waveform) { @@ -241,6 +223,16 @@ bool FFBDevice::removeEffect(const int idx) bool FFBDevice::startEffect(const int idx, FFBEffectTypes type, std::shared_ptr params) { + std::shared_ptr effect = FFBEffectFactory::createEffect(type); + if (effect == nullptr) { + qDebug() << "Unable to create effect"; + return false; + } + if (!effect->setParameters(params)) { + qDebug() << "Unable to set effect parameters, some values are probably invalid."; + return false; + } + if (idx < 0 || idx > c_maxEffectCount) { qCritical() << "Effect index out of bounds"; return false; @@ -248,30 +240,17 @@ bool FFBDevice::startEffect(const int idx, FFBEffectTypes type, std::shared_ptr< /* There is no effect in the selected slot */ if (m_effects[idx]->type() == FFBEffectTypes::NONE) { - std::shared_ptr effect = FFBEffectFactory::createEffect(type); - if (effect == nullptr) { - qWarning() << "Unable to create FFBEffect"; - return false; - } - m_effects[idx] = effect; qDebug() << "Creating new effect"; } else { - if (!isEffectUpdateable(m_effects[idx], params, type)) { + if (*m_effects[idx] != *effect) { removeEffect(idx); - m_effects[idx] = FFBEffectFactory::createEffect(type); - if (m_effects[idx] == nullptr) { - qDebug() << "Effect was not recreated."; - return false; - } qDebug() << "Recreating effect" << idx; - } else + } else { + effect->setInternalIdx(m_effects[idx]->internalIdx()); qDebug() << "Updating effect" << idx; + } } - - if (!m_effects[idx]->setParameters(params)) { - qDebug() << "Unable to set effect parameters, some values are probably invalid."; - return false; - } + m_effects[idx] = effect; struct ff_effect* kernelEff = nullptr; kernelEff = m_effects[idx]->createFFStruct(); @@ -280,6 +259,7 @@ bool FFBDevice::startEffect(const int idx, FFBEffectTypes type, std::shared_ptr< qDebug() << "struct ff_effect not created"; return false; } + int ret = uploadEffect(kernelEff); if (ret < 0) { QMessageBox::critical(nullptr, "FFB Device", "Effect could not have been uploaded, error code: " + QString::number(ret)); @@ -291,6 +271,8 @@ bool FFBDevice::startEffect(const int idx, FFBEffectTypes type, std::shared_ptr< m_effects[idx]->setInternalIdx(kernelEff->id); m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::STOPPED); + qDebug() << "idx" << "internal idx" << kernelEff->id; + /* Start playback */ struct input_event evt; evt.type = EV_FF; diff --git a/ffbdevice.h b/ffbdevice.h index e366ca7..bcf05b7 100644 --- a/ffbdevice.h +++ b/ffbdevice.h @@ -40,7 +40,6 @@ public: inline PeriodicWaveforms waveformByIdx(const int idx) const { return m_availablePeriodicWaveforms[idx]; } private: - bool isEffectUpdateable(const std::shared_ptr effect, const std::shared_ptr params, const FFBEffectTypes type); bool removeEffect(const int idx); int uploadEffect(struct ff_effect* effect); std::vector m_availableConditionSubtypes; diff --git a/ffbperiodiceffect.cpp b/ffbperiodiceffect.cpp index b07200a..0dea0d6 100644 --- a/ffbperiodiceffect.cpp +++ b/ffbperiodiceffect.cpp @@ -128,11 +128,6 @@ bool FFBPeriodicEffect::operator==(const FFBEffect& other) const } } -bool FFBPeriodicEffect::operator!=(const FFBEffect& other) const -{ - return !(*this == other); -} - FFBPeriodicEffect::~FFBPeriodicEffect() { } diff --git a/ffbperiodiceffect.h b/ffbperiodiceffect.h index 2a5b5ad..14891b0 100644 --- a/ffbperiodiceffect.h +++ b/ffbperiodiceffect.h @@ -14,7 +14,6 @@ public: bool setParameters(const std::shared_ptr params); bool setParameters(const std::shared_ptr params); bool operator==(const FFBEffect& other) const; - bool operator!=(const FFBEffect& other) const; private: std::shared_ptr m_params; diff --git a/globals.h b/globals.h index 9dff3a3..aa21149 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('c'); +static const char APP_VERSION_REL('d'); enum class FFBEffectTypes { NONE, CONSTANT, PERIODIC, RAMP, CONDITION, RUMBLE}; enum class PeriodicWaveforms { NONE, SQUARE, TRIANGLE, SINE, SAW_UP, SAW_DOWN }; -- 2.43.5