Commit 47cd05ea authored by Bryant's avatar Bryant

The hat readings from the joystick now works correctly. Also moved some...

The hat readings from the joystick now works correctly. Also moved some signals over to using an enum from an int type.
parent 902f359f
......@@ -205,11 +205,18 @@ void JoystickInput::run()
// Build up vectors describing the hat position
int hatPosition = SDL_JoystickGetHat(joystick, 0);
if ((SDL_HAT_UP & hatPosition) > 0) yHat = 1;
if ((SDL_HAT_DOWN & hatPosition) > 0) yHat = -1;
if ((SDL_HAT_LEFT & hatPosition) > 0) xHat = -1;
if ((SDL_HAT_RIGHT & hatPosition) > 0) xHat = 1;
emit hatDirectionChanged(xHat, yHat);
int newYHat = 0;
if ((SDL_HAT_UP & hatPosition) > 0) newYHat = 1;
if ((SDL_HAT_DOWN & hatPosition) > 0) newYHat = -1;
int newXHat = 0;
if ((SDL_HAT_LEFT & hatPosition) > 0) newXHat = -1;
if ((SDL_HAT_RIGHT & hatPosition) > 0) newXHat = 1;
if (newYHat != yHat || newXHat != xHat)
{
xHat = newXHat;
yHat = newYHat;
}
emit hatDirectionChanged(newXHat, newYHat);
// Emit signals for each button individually
for (int i = 0; i < joystickNumButtons; i++)
......
#include "JoystickAxis.h"
#include "JoystickInput.h"
#include "ui_JoystickAxis.h"
#include <QString>
......@@ -24,5 +25,5 @@ void JoystickAxis::setValue(float value)
void JoystickAxis::mappingComboBoxChanged(int newMapping)
{
emit mappingChanged(id, newMapping);
emit mappingChanged(id, (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping);
}
......@@ -2,6 +2,7 @@
#define JOYSTICKAXIS_H
#include <QWidget>
#include "JoystickInput.h"
namespace Ui {
class JoystickAxis;
......@@ -17,7 +18,7 @@ public:
signals:
/** @brief Signal a change in this axis' yaw/pitch/roll mapping */
void mappingChanged(int id, int newMapping);
void mappingChanged(int id, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
public slots:
/** @brief Update the displayed value of the included progressbar.
......
......@@ -21,10 +21,11 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) :
// Initialize the UI based on the current joystick
initUI();
// Watch for button and hat input events from the joystick.
// Watch for button, axis, and hat input events from the joystick.
connect(this->joystick, SIGNAL(buttonPressed(int)), this, SLOT(joystickButtonPressed(int)));
connect(this->joystick, SIGNAL(buttonReleased(int)), this, SLOT(joystickButtonReleased(int)));
connect(this->joystick, SIGNAL(axisValueChanged(int,float)), this, SLOT(updateAxisValue(int,float)));
connect(this->joystick, SIGNAL(hatDirectionChanged(int,int)), this, SLOT(setHat(int,int)));
// Update the UI if the joystick changes.
connect(m_ui->joystickNameComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUIForJoystick(int)));
......@@ -131,7 +132,7 @@ void JoystickWidget::updateUIForJoystick(int id)
{
JoystickAxis* axis = new JoystickAxis(i, m_ui->axesBox);
axis->setValue(joystick->getCurrentValueForAxis(i));
connect(axis, SIGNAL(mappingChanged(int,int)), this, SLOT(setMappingAxis(int,int)));
connect(axis, SIGNAL(mappingChanged(int,JoystickInput::JOYSTICK_INPUT_MAPPING)), this, SLOT(setMappingAxis(int,JoystickInput::JOYSTICK_INPUT_MAPPING)));
// And make sure we insert BEFORE the vertical spacer.
m_ui->axesLayout->insertWidget(i, axis);
axes.append(axis);
......@@ -146,9 +147,9 @@ void JoystickWidget::updateAxisValue(int axis, float value)
}
}
void JoystickWidget::setHat(float x, float y)
void JoystickWidget::setHat(int x, int y)
{
updateStatus(tr("Hat position: x: %1, y: %2").arg(x).arg(y));
m_ui->statusLabel->setText(tr("Hat position: x: %1, y: %2").arg(x).arg(y));
}
void JoystickWidget::setMappingAxis(int axisID, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping)
......@@ -167,6 +168,9 @@ void JoystickWidget::setMappingAxis(int axisID, JoystickInput::JOYSTICK_INPUT_MA
case JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE:
joystick->setMappingThrottleAxis(axisID);
break;
case JoystickInput::JOYSTICK_INPUT_MAPPING_NONE:
default:
break;
}
}
......@@ -180,8 +184,3 @@ void JoystickWidget::joystickButtonReleased(int key)
{
buttons.at(key)->setStyleSheet("");
}
void JoystickWidget::updateStatus(const QString& status)
{
m_ui->statusLabel->setText(status);
}
......@@ -53,14 +53,25 @@ public:
virtual ~JoystickWidget();
public slots:
/** @brief Update the UI for a new joystick based on SDL ID. */
void updateUIForJoystick(int id);
/** @brief Change the stored mapping for a given axis. */
void setMappingAxis(int axisID, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
/**
* @brief Update a given axis with a new value
* @param axis The index of the axis to update.
* @param value The new value for the axis, [-1.0:1.0].
* @see JoystickInput:axisValueChanged
*/
void updateAxisValue(int axis, float value);
void setHat(float x, float y);
/** @brief Update the UI with new values for the hat.
* @see JoystickInput::hatDirectionChanged
*/
void setHat(int x, int y);
/** @brief Trigger a UI change based on a button being pressed */
void joystickButtonPressed(int key);
/** @brief Trigger a UI change based on a button being released */
void joystickButtonReleased(int key);
/** @brief Update status string */
void updateStatus(const QString& status);
/** @brief Update the UI color scheme when the MainWindow theme changes. */
void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE);
......@@ -77,12 +88,6 @@ protected:
/** @brief The color to use for button labels when their corresponding button is pressed */
QColor buttonLabelColor;
protected slots:
/** @brief Update the UI for a new joystick based on SDL ID. */
void updateUIForJoystick(int id);
/** @brief Change the stored mapping for a given axis. */
void setMappingAxis(int axisID, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
private:
Ui::JoystickWidget *m_ui;
/** @brief Initialize all dynamic UI elements (button list, joystick names, etc.) */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment