From: Michal MalĂ˝ Date: Sun, 2 Aug 2015 10:34:30 +0000 (+0200) Subject: Add an option to set autocentering strength X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=a93ac2384c555d429fd1e19c91e1378f753d4b12;p=FFBChecker.git Add an option to set autocentering strength --- diff --git a/ffbdevice.h b/ffbdevice.h index ed3ddc0..baa5104 100644 --- a/ffbdevice.h +++ b/ffbdevice.h @@ -21,6 +21,7 @@ public: virtual void close() = 0; virtual bool queryDeviceCapabilities() = 0; virtual bool removeAndEraseEffect(const int idx) = 0; + virtual bool setAutocentering(const int strength) = 0; virtual bool setGain(const int gain) = 0; virtual bool startEffect(const int idx, const FFBEffectTypes type, std::shared_ptr parameters) = 0; virtual bool stopEffect(const int idx) = 0; @@ -33,6 +34,7 @@ protected: std::vector m_availableConditionSubtypes; std::vector m_availableEffects; std::vector m_availablePeriodicWaveforms; + bool m_adjustableAC; bool m_adjustableGain; std::vector> m_effects; diff --git a/linuxffbdevice.cpp b/linuxffbdevice.cpp index 9afcd33..4ab6b7e 100644 --- a/linuxffbdevice.cpp +++ b/linuxffbdevice.cpp @@ -78,6 +78,8 @@ bool LinuxFFBDevice::queryDeviceCapabilities() /* Query device-wide capabilities */ if (testBit(FF_GAIN, caps)) m_adjustableGain = true; + if (testBit(FF_AUTOCENTER, caps)) + m_adjustableAC = true; return true; } @@ -120,6 +122,34 @@ bool LinuxFFBDevice::removeEffect(const int idx) return true; } +bool LinuxFFBDevice::setAutocentering(const int strength) +{ + struct input_event evt; + int ret; + + if (!m_adjustableAC) { + QMessageBox::warning(nullptr, LNXDEV_ERR_CAPTION, "Device does not have adjustable autocentering"); + return false; + } + + if (strength < 0 || strength > 0xFFFF) { + QMessageBox::warning(nullptr, LNXDEV_ERR_CAPTION, "Autocentering strength must be within <0; 65535>"); + return false; + } + + evt.type = EV_FF; + evt.code = FF_AUTOCENTER; + evt.value = strength; + ret = write(c_fd, &evt, sizeof(struct input_event)); + if (ret != sizeof(struct input_event)) { + QMessageBox::warning(nullptr, LNXDEV_ERR_CAPTION, "Unable to set autocentering strength"); + return false; + } + + return true; +} + + bool LinuxFFBDevice::setGain(const int gain) { struct input_event evt; diff --git a/linuxffbdevice.h b/linuxffbdevice.h index 52460bd..66289c9 100644 --- a/linuxffbdevice.h +++ b/linuxffbdevice.h @@ -14,6 +14,7 @@ public: void close(); bool queryDeviceCapabilities(); bool removeAndEraseEffect(const int idx); + bool setAutocentering(const int strength); bool setGain(const int gain); bool startEffect(const int idx, const FFBEffectTypes type, std::shared_ptr parameters); bool stopEffect(const int idx); diff --git a/mainwindow.cpp b/mainwindow.cpp index f260c06..351d7b6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -53,6 +53,7 @@ MainWindow::MainWindow(const QString& title, QWidget* parent) : connect(ui->cbox_interfaces, SIGNAL(activated(int)), this, SLOT(onInterfaceSelected(const int))); connect(ui->qpb_refreshDevices, SIGNAL(clicked()), this, SLOT(onRefreshDevicesClicked())); connect(ui->qpb_remove, SIGNAL(clicked()), this, SLOT(onRemoveEffectClicked())); + connect(ui->qpb_setAC, SIGNAL(clicked()), this, SLOT(onSetACClicked())); connect(ui->qpb_setGain, SIGNAL(clicked()), this, SLOT(onSetGainClicked())); connect(ui->qpb_start, SIGNAL(clicked()), this, SLOT(onStartEffectClicked())); connect(ui->qpb_stop, SIGNAL(clicked()), this, SLOT(onStopEffectClicked())); @@ -273,6 +274,24 @@ void MainWindow::onRemoveEffectClicked() setEffectStatusText(m_activeDevice->effectStatusByIdx(effectIdx)); } +void MainWindow::onSetACClicked() +{ + bool ok; + int strength; + + if (m_activeDevice == nullptr) + return; + + strength = ui->qle_autocentering->text().toInt(&ok); + if (!ok) { + QMessageBox::warning(this, res_inputFormatErrCap, "Invalid autocentering strength value"); + return; + } + + m_activeDevice->setAutocentering(strength); +} + + void MainWindow::onSetGainClicked() { bool ok; diff --git a/mainwindow.h b/mainwindow.h index 36c0322..2776b74 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -70,6 +70,7 @@ private slots: void onInterfaceSelected(const int cboxIdx); void onRefreshDevicesClicked(); void onRemoveEffectClicked(); + void onSetACClicked(); void onSetGainClicked(); void onStartEffectClicked(); void onStopEffectClicked(); diff --git a/mainwindow.ui b/mainwindow.ui index 9646068..a80af5b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 444 - 623 + 670 @@ -29,16 +29,6 @@ - - - - Effect slots: - - - - - - @@ -103,6 +93,30 @@ + + + + Autocentering: + + + + + + + 65535 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Set AC + + + @@ -128,6 +142,20 @@ + + + + + + Effect slots: + + + + + + + + diff --git a/sdl2ffbdevice.cpp b/sdl2ffbdevice.cpp index eeb7311..45fed88 100644 --- a/sdl2ffbdevice.cpp +++ b/sdl2ffbdevice.cpp @@ -81,6 +81,9 @@ bool SDL2FFBDevice::queryDeviceCapabilities() if (caps & SDL_HAPTIC_GAIN) m_adjustableGain = true; + if (caps & SDL_HAPTIC_AUTOCENTER) + m_adjustableAC = true; + return true; } @@ -125,6 +128,27 @@ bool SDL2FFBDevice::removeAndEraseEffect(const int idx) return true; } +bool SDL2FFBDevice::setAutocentering(const int strength) +{ + if (!m_adjustableAC) { + QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, "Device does not have adjustable autocentering"); + return false; + } + + if (strength < 0 || strength > 100) { + QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, "Autocentering strength must be within <0; 100>"); + return false; + } + + if (SDL_HapticSetAutocenter(c_haptic, strength) < 0) { + QMessageBox::warning(nullptr, SDL2DEV_ERR_CAPTION, QString("Unable to set autocentering:\n%1").arg(SDL_GetError())); + return false; + } + + return true; +} + + bool SDL2FFBDevice::setGain(const int gain) { if (!m_adjustableGain) { diff --git a/sdl2ffbdevice.h b/sdl2ffbdevice.h index e25cd75..fa89c4d 100644 --- a/sdl2ffbdevice.h +++ b/sdl2ffbdevice.h @@ -10,6 +10,7 @@ public: void close(); bool queryDeviceCapabilities(); bool removeAndEraseEffect(const int idx); + bool setAutocentering(const int strength); bool setGain(const int idx); bool startEffect(const int idx, const FFBEffectTypes type, std::shared_ptr parameters); bool stopEffect(const int idx);