Browse Source

Joystick axes can now be specified as being exclusively-positive in the range [0:1.0] for the throttle. This should really be a vehicle-specific setting.

QGC4.4
Bryant 12 years ago
parent
commit
f820eefc8e
  1. 17
      src/input/JoystickInput.cc
  2. 11
      src/input/JoystickInput.h
  3. 25
      src/ui/JoystickAxis.cc
  4. 6
      src/ui/JoystickAxis.h
  5. 24
      src/ui/JoystickAxis.ui
  6. 6
      src/ui/JoystickWidget.cc

17
src/input/JoystickInput.cc

@ -198,7 +198,12 @@ void JoystickInput::run() @@ -198,7 +198,12 @@ void JoystickInput::run()
axisValue = (axisValue - calibrationPositive[i]) / (calibrationNegative[i] - calibrationPositive[i]);
}
axisValue = 1.0f - axisValue;
axisValue = axisValue * 2.0f - 1.0f;
// If the joystick isn't limited to [0:1.0], map it into [-1.0:1.0].
if (!joystickAxesRangeLimited[i])
{
axisValue = axisValue * 2.0f - 1.0f;
}
// Bound rounding errors
if (axisValue > 1.0f) axisValue = 1.0f;
@ -276,6 +281,7 @@ void JoystickInput::setActiveJoystick(int id) @@ -276,6 +281,7 @@ void JoystickInput::setActiveJoystick(int id)
// Update cached joystick values
joystickAxes.clear();
joystickAxesInverted.clear();
joystickAxesRangeLimited.clear();
for (int i = 0; i < joystickNumAxes; i++)
{
int axisValue = SDL_JoystickGetAxis(joystick, i);
@ -283,6 +289,7 @@ void JoystickInput::setActiveJoystick(int id) @@ -283,6 +289,7 @@ void JoystickInput::setActiveJoystick(int id)
emit axisValueChanged(i, axisValue);
joystickAxesInverted.append(false);
joystickAxesRangeLimited.append(false);
}
joystickButtons = 0;
for (int i = 0; i < joystickNumButtons; i++)
@ -348,6 +355,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted) @@ -348,6 +355,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted)
}
}
void JoystickInput::setAxisRangeLimit(int axis, bool rangeLimited)
{
if (axis < joystickAxesRangeLimited.size())
{
joystickAxesRangeLimited[axis] = rangeLimited;
}
}
float JoystickInput::getCurrentValueForAxis(int axis)
{
if (axis < joystickAxes.size())

11
src/input/JoystickInput.h

@ -156,8 +156,9 @@ protected: @@ -156,8 +156,9 @@ protected:
int joystickNumAxes;
int joystickNumButtons;
QList<float> joystickAxes; ///< The values of every axes during the last sample
QList<bool> joystickAxesInverted; ///< Whether each axis should be used inverted from what was reported
QList<float> joystickAxes; ///< The values of every axes during the last sample.
QList<bool> joystickAxesInverted; ///< Whether each axis should be used inverted from what was reported.
QList<bool> joystickAxesRangeLimited; ///< Whether each axis should be scaled into [0:1.0] instead of [-1.0:1.0].
quint16 joystickButtons; ///< The state of every button. Bitfield supporting 16 buttons with 1s indicating that the button is down.
int xHat, yHat; ///< The horizontal/vertical hat directions. Values are -1, 0, 1, with (-1,-1) indicating bottom-left.
@ -232,6 +233,12 @@ public slots: @@ -232,6 +233,12 @@ public slots:
* @param inverted True indicates inverted from normal. Varies by controller.
*/
void setAxisInversion(int axis, bool inverted);
/**
* @brief Specifies whether an axis should have its range limited to only positive values.
* @param axis The index of the axis to limit
* @param rangeLimited True if the axis should be limited, false otherwise.
*/
void setAxisRangeLimit(int axis, bool rangeLimited);
};
#endif // _JOYSTICKINPUT_H_

25
src/ui/JoystickAxis.cc

@ -9,9 +9,11 @@ JoystickAxis::JoystickAxis(int id, QWidget *parent) : @@ -9,9 +9,11 @@ JoystickAxis::JoystickAxis(int id, QWidget *parent) :
ui(new Ui::JoystickAxis)
{
ui->setupUi(this);
ui->limitRangeCheckBox->hide(); // Hide the range checkbox by default. It's only activated by switching to the Throttle axis option.
ui->label->setText(QString::number(id));
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(mappingComboBoxChanged(int)));
connect(ui->checkBox, SIGNAL(clicked(bool)), this, SLOT(inversionCheckBoxChanged(bool)));
connect(ui->invertedCheckBox, SIGNAL(clicked(bool)), this, SLOT(inversionCheckBoxChanged(bool)));
connect(ui->limitRangeCheckBox, SIGNAL(clicked(bool)), this, SLOT(limitRangeCheckBoxChanged(bool)));
}
JoystickAxis::~JoystickAxis()
@ -26,6 +28,14 @@ void JoystickAxis::setValue(float value) @@ -26,6 +28,14 @@ void JoystickAxis::setValue(float value)
void JoystickAxis::mappingComboBoxChanged(int newMapping)
{
if (newMapping == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
{
ui->limitRangeCheckBox->show();
}
else
{
ui->limitRangeCheckBox->hide();
}
emit mappingChanged(id, (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping);
}
@ -33,3 +43,16 @@ void JoystickAxis::inversionCheckBoxChanged(bool inverted) @@ -33,3 +43,16 @@ void JoystickAxis::inversionCheckBoxChanged(bool inverted)
{
emit inversionChanged(id, inverted);
}
void JoystickAxis::limitRangeCheckBoxChanged(bool limited)
{
if (limited)
{
ui->progressBar->setRange(0, 100);
}
else
{
ui->progressBar->setRange(-100, 100);
}
emit rangeLimitChanged(id, limited);
}

6
src/ui/JoystickAxis.h

@ -21,6 +21,8 @@ signals: @@ -21,6 +21,8 @@ signals:
void mappingChanged(int id, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
/** @brief Signal a change in this axis' inversion status */
void inversionChanged(int id, bool);
/** @brief Signal a change in this axis' range limit */
void rangeLimitChanged(int id, bool);
public slots:
/** @brief Update the displayed value of the included progressbar.
@ -35,8 +37,10 @@ private: @@ -35,8 +37,10 @@ private:
private slots:
/** @brief Handle changes to the mapping dropdown bar. */
void mappingComboBoxChanged(int newMapping);
/** @brief Handle changes to the inversion checkbox. */
/** @brief Emit signal when the inversion checkbox is changed. */
void inversionCheckBoxChanged(bool inverted);
/** @brief Emit signal when the limit range checkbox is changed. */
void limitRangeCheckBoxChanged(bool limited);
};
#endif // JOYSTICKAXIS_H

24
src/ui/JoystickAxis.ui

@ -87,9 +87,16 @@ @@ -87,9 +87,16 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="limitRangeCheckBox">
<property name="text">
<string>Limit range</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
@ -113,21 +120,30 @@ @@ -113,21 +120,30 @@
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="textDirection">
<enum>QProgressBar::TopToBottom</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="invertedCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>Inverted</string>
</property>

6
src/ui/JoystickWidget.cc

@ -126,7 +126,7 @@ void JoystickWidget::updateUIForJoystick(int id) @@ -126,7 +126,7 @@ void JoystickWidget::updateUIForJoystick(int id)
{
JoystickButton* button = new JoystickButton(i, m_ui->buttonBox);
// And make sure we insert BEFORE the vertical spacer.
m_ui->buttonLayout->insertWidget(i, button);
m_ui->buttonLayout->addWidget(button);
buttons.append(button);
}
}
@ -145,8 +145,8 @@ void JoystickWidget::updateUIForJoystick(int id) @@ -145,8 +145,8 @@ void JoystickWidget::updateUIForJoystick(int id)
axis->setValue(joystick->getCurrentValueForAxis(i));
connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this->joystick, SLOT(setAxisMapping(int,JoystickInput::JOYSTICK_INPUT_MAPPING)));
connect(axis, SIGNAL(inversionChanged(int,bool)), this->joystick, SLOT(setAxisInversion(int,bool)));
// And make sure we insert BEFORE the vertical spacer.
m_ui->axesLayout->insertWidget(i, axis);
connect(axis, SIGNAL(rangeLimitChanged(int,bool)), this->joystick, SLOT(setAxisRangeLimit(int,bool)));
m_ui->axesLayout->addWidget(axis);
axes.append(axis);
}
}

Loading…
Cancel
Save