Skip to content

Commit

Permalink
Merge pull request #1761 from srcejon/gamepad_calibration
Browse files Browse the repository at this point in the history
Rotator controller: Additional gamepad calibration
  • Loading branch information
f4exb authored Aug 6, 2023
2 parents 8383467 + 5e80362 commit 958078c
Show file tree
Hide file tree
Showing 22 changed files with 1,024 additions and 160 deletions.
1 change: 1 addition & 0 deletions plugins/feature/gs232controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if(NOT SERVER_MODE)
gs232controllergui.h
dfmstatusdialog.h
inputcontroller.h
inputcontrollersettings.h
)

set(TARGET_NAME featuregs232controller)
Expand Down
73 changes: 71 additions & 2 deletions plugins/feature/gs232controller/gamepadconfigurationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@
#include <QGamepad>

#include "gamepadconfigurationdialog.h"
#include "inputcontrollersettings.h"

GamepadConfigurationDialog::GamepadConfigurationDialog(QGamepad *gamepad, QWidget* parent) :
GamepadConfigurationDialog::GamepadConfigurationDialog(QGamepad *gamepad, InputControllerSettings *settings, bool supportsConfiguraiton, QWidget* parent) :
QDialog(parent),
ui(new Ui::GamepadConfigurationDialog),
m_gamepad(gamepad)
m_gamepad(gamepad),
m_settings(settings)
{
ui->setupUi(this);
connect(m_gamepad, &QGamepad::axisRightXChanged, this, &GamepadConfigurationDialog::axisRightXChanged);
connect(m_gamepad, &QGamepad::axisRightYChanged, this, &GamepadConfigurationDialog::axisRightYChanged);
connect(m_gamepad, &QGamepad::axisLeftXChanged, this, &GamepadConfigurationDialog::axisLeftXChanged);
connect(m_gamepad, &QGamepad::axisLeftYChanged, this, &GamepadConfigurationDialog::axisLeftYChanged);
ui->deadzone0->setValue(settings->m_deadzone[0]);
ui->deadzone1->setValue(settings->m_deadzone[1]);
ui->deadzone2->setValue(settings->m_deadzone[2]);
ui->deadzone3->setValue(settings->m_deadzone[3]);
ui->lowSensitivity->blockSignals(true);
ui->lowSensitivity->setRange(0.01, 100);
ui->lowSensitivity->blockSignals(false);
ui->lowSensitivity->setValue((double)settings->m_lowSensitivity);
ui->highSensitivity->blockSignals(true);
ui->highSensitivity->setRange(0.01, 100);
ui->highSensitivity->blockSignals(false);
ui->highSensitivity->setValue((double)settings->m_highSensitivity);
ui->configurationGroup->setEnabled(supportsConfiguraiton);
}

GamepadConfigurationDialog::~GamepadConfigurationDialog()
Expand All @@ -42,6 +57,11 @@ void GamepadConfigurationDialog::accept()
QDialog::accept();
}

void GamepadConfigurationDialog::on_configReset_clicked()
{
QGamepadManager::instance()->resetConfiguration(m_gamepad->deviceId());
}

void GamepadConfigurationDialog::on_config0_clicked()
{
ui->config0->setText("Configuring");
Expand Down Expand Up @@ -121,3 +141,52 @@ void GamepadConfigurationDialog::axisLeftYChanged(double value)
ui->config2->setEnabled(true);
ui->config3->setEnabled(true);
}

// Convert double to string and remove trailing zeros
static QString toSimpleFloat(double v, int prec)
{
QString s = QString::number(v, 'f', prec);
while (s.back() == '0') {
s.chop(1);
}
if (s.back() == '.') {
s.chop(1);
}
return s;
}

void GamepadConfigurationDialog::on_lowSensitivity_logValueChanged(double value)
{
m_settings->m_lowSensitivity = value;
ui->lowSensitivityText->setText(QString("%1%").arg(toSimpleFloat(m_settings->m_lowSensitivity, 4)));
}

void GamepadConfigurationDialog::on_highSensitivity_logValueChanged(double value)
{
m_settings->m_highSensitivity = value;
ui->highSensitivityText->setText(QString("%1%").arg(toSimpleFloat(m_settings->m_highSensitivity, 4)));
}

void GamepadConfigurationDialog::on_deadzone0_valueChanged(int value)
{
m_settings->m_deadzone[0] = value;
ui->deadzone0Text->setText(QString("%1%").arg(m_settings->m_deadzone[0]));
}

void GamepadConfigurationDialog::on_deadzone1_valueChanged(int value)
{
m_settings->m_deadzone[1] = value;
ui->deadzone1Text->setText(QString("%1%").arg(m_settings->m_deadzone[1]));
}

void GamepadConfigurationDialog::on_deadzone2_valueChanged(int value)
{
m_settings->m_deadzone[2] = value;
ui->deadzone2Text->setText(QString("%1%").arg(m_settings->m_deadzone[2]));
}

void GamepadConfigurationDialog::on_deadzone3_valueChanged(int value)
{
m_settings->m_deadzone[3] = value;
ui->deadzone3Text->setText(QString("%1%").arg(m_settings->m_deadzone[3]));
}
11 changes: 10 additions & 1 deletion plugins/feature/gs232controller/gamepadconfigurationdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
#include "ui_gamepadconfigurationdialog.h"

class QGamepad;
struct InputControllerSettings;

class GamepadConfigurationDialog : public QDialog {
Q_OBJECT

public:
explicit GamepadConfigurationDialog(QGamepad *gamepad, QWidget* parent = 0);
explicit GamepadConfigurationDialog(QGamepad *gamepad, InputControllerSettings *settings, bool supportsConfiguraiton, QWidget* parent = 0);
~GamepadConfigurationDialog();

private slots:
void accept();
void on_configReset_clicked();
void on_config0_clicked();
void on_config1_clicked();
void on_config2_clicked();
Expand All @@ -39,10 +41,17 @@ private slots:
void axisRightYChanged(double value);
void axisLeftXChanged(double value);
void axisLeftYChanged(double value);
void on_lowSensitivity_logValueChanged(double value);
void on_highSensitivity_logValueChanged(double value);
void on_deadzone0_valueChanged(int value);
void on_deadzone1_valueChanged(int value);
void on_deadzone2_valueChanged(int value);
void on_deadzone3_valueChanged(int value);

private:
Ui::GamepadConfigurationDialog* ui;
QGamepad *m_gamepad;
InputControllerSettings *m_settings;
};

#endif // INCLUDE_GAMEPADCONFIGURATIONDIALOG_H
Expand Down
Loading

0 comments on commit 958078c

Please sign in to comment.