return true;
}
-bool FFBDevice::removeEffect(const int idx)
+bool FFBDevice::removeAndEraseEffect(const int idx)
{
if (m_effects[idx]->status() == FFBEffect::FFBEffectStatus::NOT_LOADED)
return true;
+ if (removeEffect(idx)) {
+ m_effects[idx] = FFBEffectFactory::createEffect(FFBEffectTypes::NONE);
+ if (m_effects[idx]->type() != FFBEffectTypes::NONE) {
+ qCritical("Unable to empty the effect slot.");
+ return false;
+ }
+ } else {
+ qCritical("Unable to stop the effect.");
+ return false;
+ }
+
+ m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::NOT_LOADED);
+ return true;
+}
+
+bool FFBDevice::removeEffect(const int idx)
+{
if (!stopEffect(idx))
return false;
int ret = ioctl(c_fd, EVIOCRMFF, internalIdx);
if (ret < 0)
return false;
-
- m_effects[idx]->setStatus(FFBEffect::FFBEffectStatus::NOT_LOADED);
return true;
}
bool FFBDevice::startEffect(const int idx, FFBEffectTypes type, std::shared_ptr<FFBEffectParameters> params)
{
if (idx < 0 || idx > c_maxEffectCount) {
- qDebug() << "Effect index out of bounds";
+ qCritical() << "Effect index out of bounds";
return false;
}
inline const QString& id() const { return c_id; }
inline int maxEffectCount() const { return c_maxEffectCount; }
bool queryDeviceCapabilities();
- bool removeEffect(const int idx);
+ bool removeAndEraseEffect(const int idx);
bool startEffect(const int idx, FFBEffectTypes type, std::shared_ptr<FFBEffectParameters> params);
bool stopEffect(const int idx);
QString waveformName(const PeriodicWaveforms waveform) const;
private:
bool isEffectUpdateable(const std::shared_ptr<FFBEffect> effect, const std::shared_ptr<FFBEffectParameters> params, const FFBEffectTypes type);
+ bool removeEffect(const int idx);
int uploadEffect(struct ff_effect* effect);
std::vector<FFBEffectTypes> m_availableEffects;
std::vector<PeriodicWaveforms> m_availablePeriodicWaveforms;
#include <QtWidgets/QMessageBox>
#include <QDebug>
+const QString MainWindow::res_deviceErrorCap("Device error");
const QString MainWindow::res_effectNotLoaded("Not loaded");
const QString MainWindow::res_effectPlaying("Playing");
const QString MainWindow::res_effectStopped("Stopped");
connect(ui->cbox_effectSlots, SIGNAL(activated(const int)), this, SLOT(onEffectSlotSelected(const int)));
connect(ui->cbox_effectTypes, SIGNAL(activated(const int)), this, SLOT(onEffectTypeSelected(const int)));
connect(ui->qpb_refreshDevices, SIGNAL(clicked()), this, SLOT(onRefreshDevicesClicked()));
+ connect(ui->qpb_remove, SIGNAL(clicked()), this, SLOT(onRemoveEffectClicked()));
connect(ui->qpb_start, SIGNAL(clicked()), this, SLOT(onStartEffectClicked()));
connect(ui->qpb_stop, SIGNAL(clicked()), this, SLOT(onStopEffectClicked()));
}
fillDeviceList();
}
+void MainWindow::onRemoveEffectClicked()
+{
+ if (m_activeDevice == nullptr)
+ return;
+ if (!m_activeDevice->removeAndEraseEffect(ui->cbox_effectSlots->currentIndex()))
+ QMessageBox::warning(this, res_deviceErrorCap, "Unable to remove the effect.");
+ else
+ setEffectStatusText(FFBEffect::FFBEffectStatus::NOT_LOADED);
+}
+
void MainWindow::onStartEffectClicked()
{
if (m_activeDevice == nullptr)
bool ret = m_activeDevice->startEffect(effectSlot, type, params);
if (ret)
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
+ else
+ QMessageBox::warning(this, res_deviceErrorCap, "Unable to start the effect.");
}
void MainWindow::onStopEffectClicked()
std::shared_ptr<DeviceProber> m_prober;
Ui::MainWindow* ui;
+ static const QString res_deviceErrorCap;
static const QString res_effectNotLoaded;
static const QString res_effectPlaying;
static const QString res_effectStopped;
void onEffectSlotSelected(const int idx);
void onEffectTypeSelected(const int idx);
void onRefreshDevicesClicked();
+ void onRemoveEffectClicked();
void onStartEffectClicked();
void onStopEffectClicked();
};