Commit 8e533fd3 authored by Bryant's avatar Bryant

Vastly improved the joystick documentation, removed some redundant/unnecessary...

Vastly improved the joystick documentation, removed some redundant/unnecessary code, and fixed a couple of small bugs. This code should be ready for live testing.
parent adbbdb45
...@@ -505,7 +505,6 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -505,7 +505,6 @@ void JoystickInput::setActiveJoystick(int id)
joystick = SDL_JoystickOpen(joystickID); joystick = SDL_JoystickOpen(joystickID);
if (joystick && SDL_JoystickOpened(joystickID)) if (joystick && SDL_JoystickOpened(joystickID))
{ {
SDL_JoystickUpdate();
// Update joystick configuration. // Update joystick configuration.
joystickName = QString(SDL_JoystickName(joystickID)); joystickName = QString(SDL_JoystickName(joystickID));
joystickNumButtons = SDL_JoystickNumButtons(joystick); joystickNumButtons = SDL_JoystickNumButtons(joystick);
...@@ -532,6 +531,9 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -532,6 +531,9 @@ void JoystickInput::setActiveJoystick(int id)
joystickNumAxes = 0; joystickNumAxes = 0;
} }
// Specify that a new joystick has been selected, so that any UI elements can update.
emit newJoystickSelected();
// And then trigger an update of this new UI.
emit joystickSettingsChanged(); emit joystickSettingsChanged();
} }
......
...@@ -23,11 +23,20 @@ This file is part of the PIXHAWK project ...@@ -23,11 +23,20 @@ This file is part of the PIXHAWK project
/** /**
* @file * @file
* @brief Definition of joystick interface * @brief Definition of joystick interface
* *
* @author Lorenz Meier <mavteam@student.ethz.ch> * This class defines a new thread to operate the reading of any joystick/controllers
* @author Andreas Romer <mavteam@student.ethz.ch> * via the Simple Directmedia Library (libsdl.org). This relies on polling of the SDL,
* which is not their recommended method, instead they suggest use event checking. That
* does not seem to support switching joysticks after their internal event loop has started,
* so it was abandoned.
* *
* All joystick-related functionality is done in this class, though the JoystickWidget provides
* a UI around modifying its settings. Additionally controller buttons can be mapped to
* actions defined by any UASInterface object through the `UASInterface::getActions()` function.
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
* @author Andreas Romer <mavteam@student.ethz.ch>
*/ */
#ifndef _JOYSTICKINPUT_H_ #ifndef _JOYSTICKINPUT_H_
...@@ -198,6 +207,9 @@ protected: ...@@ -198,6 +207,9 @@ protected:
quint16 joystickButtons; ///< The state of every button. Bitfield supporting 16 buttons with 1s indicating that the button is down. 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. int xHat, yHat; ///< The horizontal/vertical hat directions. Values are -1, 0, 1, with (-1,-1) indicating bottom-left.
/**
* @brief Called before main run() event loop starts. Waits for joysticks to be connected.
*/
void init(); void init();
signals: signals:
...@@ -265,6 +277,9 @@ signals: ...@@ -265,6 +277,9 @@ signals:
/** @brief Signals that new joystick-specific settings were changed. Useful for triggering updates that at dependent on the current joystick. */ /** @brief Signals that new joystick-specific settings were changed. Useful for triggering updates that at dependent on the current joystick. */
void joystickSettingsChanged(); void joystickSettingsChanged();
/** @brief The JoystickInput has switched to a different joystick. UI should be adjusted accordingly. */
void newJoystickSelected();
public slots: public slots:
/** @brief Enable or disable emitting the high-level control signals from the joystick. */ /** @brief Enable or disable emitting the high-level control signals from the joystick. */
void setEnabled(bool enable); void setEnabled(bool enable);
......
...@@ -284,7 +284,7 @@ int UAS::getUASID() const ...@@ -284,7 +284,7 @@ int UAS::getUASID() const
void UAS::triggerAction(int action) void UAS::triggerAction(int action)
{ {
if (action > 0 && action < actions.size()) if (action >= 0 && action < actions.size())
{ {
qDebug() << "Triggering action: '" << actions[action]->text() << "'"; qDebug() << "Triggering action: '" << actions[action]->text() << "'";
actions[action]->trigger(); actions[action]->trigger();
...@@ -2789,27 +2789,6 @@ int UAS::getSystemType() ...@@ -2789,27 +2789,6 @@ int UAS::getSystemType()
return this->type; return this->type;
} }
/**
* @param buttonIndex
*/
void UAS::receiveButton(int buttonIndex)
{
switch (buttonIndex)
{
case 0:
break;
case 1:
break;
default:
break;
}
// qDebug() << __FILE__ << __LINE__ << ": Received button clicked signal (button # is: " << buttonIndex << "), UNIMPLEMENTED IN MAVLINK!";
}
/** /**
* Halt the uas. * Halt the uas.
*/ */
......
...@@ -799,8 +799,6 @@ public slots: ...@@ -799,8 +799,6 @@ public slots:
/** @brief Set the values for the manual control of the vehicle */ /** @brief Set the values for the manual control of the vehicle */
void setManualControlCommands(double roll, double pitch, double yaw, double thrust, int xHat, int yHat, int buttons); void setManualControlCommands(double roll, double pitch, double yaw, double thrust, int xHat, int yHat, int buttons);
/** @brief Receive a button pressed event from an input device, e.g. joystick */
void receiveButton(int buttonIndex);
/** @brief Set the values for the 6dof manual control of the vehicle */ /** @brief Set the values for the 6dof manual control of the vehicle */
void setManual6DOFControlCommands(double x, double y, double z, double roll, double pitch, double yaw); void setManual6DOFControlCommands(double x, double y, double z, double roll, double pitch, double yaw);
......
...@@ -261,7 +261,9 @@ public: ...@@ -261,7 +261,9 @@ public:
} }
/** @brief Returns a list of actions/commands that this vehicle can perform. /** @brief Returns a list of actions/commands that this vehicle can perform.
* Used for creating UI elements for built-in functionality for this vehicle. * Used for creating UI elements for built-in functionality for this vehicle.
* Actions should be mappings to `void f(void);` functions that simply issue
* a command to the vehicle.
*/ */
virtual QList<QAction*> getActions() const = 0; virtual QList<QAction*> getActions() const = 0;
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* This class defines a UI element to represent a single controller axis.
* It is used by the JoystickWidget to simplify some of the logic in that class.
*/
#ifndef JOYSTICKAXIS_H #ifndef JOYSTICKAXIS_H
#define JOYSTICKAXIS_H #define JOYSTICKAXIS_H
......
/*=====================================================================
QGroundControl Open Source Ground Control Station
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/**
* @file
* This class defines a UI element to represent a single controller axis.
* It is used by the JoystickWidget to simplify some of the logic in that class.
*/
#ifndef JOYSTICKBUTTON_H #ifndef JOYSTICKBUTTON_H
#define JOYSTICKBUTTON_H #define JOYSTICKBUTTON_H
......
...@@ -30,8 +30,10 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) : ...@@ -30,8 +30,10 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) :
// Also watch for when new settings were loaded for the current joystick to do a mass UI refresh. // Also watch for when new settings were loaded for the current joystick to do a mass UI refresh.
connect(this->joystick, SIGNAL(joystickSettingsChanged()), this, SLOT(updateUI())); connect(this->joystick, SIGNAL(joystickSettingsChanged()), this, SLOT(updateUI()));
// If the selected joystick is changed, update the joystick. // If the selected joystick is changed, update the JoystickInput.
connect(m_ui->joystickNameComboBox, SIGNAL(currentIndexChanged(int)), this->joystick, SLOT(setActiveJoystick(int))); connect(m_ui->joystickNameComboBox, SIGNAL(currentIndexChanged(int)), this->joystick, SLOT(setActiveJoystick(int)));
// Also wait for the JoystickInput to switch, then update our UI.
connect(this->joystick, SIGNAL(newJoystickSelected()), this, SLOT(createUIForJoystick()));
// Initialize the UI to the current JoystickInput state. Also make sure to listen for future changes // Initialize the UI to the current JoystickInput state. Also make sure to listen for future changes
// so that the UI can be updated. // so that the UI can be updated.
...@@ -124,8 +126,6 @@ void JoystickWidget::updateUI() ...@@ -124,8 +126,6 @@ void JoystickWidget::updateUI()
for (int i = 0; i < axes.size(); i++) for (int i = 0; i < axes.size(); i++)
{ {
JoystickAxis* axis = axes[i]; JoystickAxis* axis = axes[i];
float value = joystick->getCurrentValueForAxis(i);
axis->setValue(value);
JoystickInput::JOYSTICK_INPUT_MAPPING mapping = JoystickInput::JOYSTICK_INPUT_MAPPING_NONE; JoystickInput::JOYSTICK_INPUT_MAPPING mapping = JoystickInput::JOYSTICK_INPUT_MAPPING_NONE;
if (i == rollAxis) if (i == rollAxis)
{ {
......
...@@ -23,7 +23,7 @@ This file is part of the PIXHAWK project ...@@ -23,7 +23,7 @@ This file is part of the PIXHAWK project
/** /**
* @file * @file
* @brief Definition of joystick widget * @brief Definition of joystick widget. Provides a UI for configuring the joystick settings.
* @author Lorenz Meier <mavteam@student.ethz.ch> * @author Lorenz Meier <mavteam@student.ethz.ch>
* *
*/ */
...@@ -76,8 +76,6 @@ public slots: ...@@ -76,8 +76,6 @@ public slots:
void updateUI(); void updateUI();
protected: protected:
/** @brief Update the proper number of buttons for the current joystick. */
void updateButtons();
/** @brief UI change event */ /** @brief UI change event */
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
JoystickInput* joystick; ///< Reference to the joystick JoystickInput* joystick; ///< Reference to the joystick
...@@ -90,7 +88,9 @@ protected: ...@@ -90,7 +88,9 @@ protected:
private: private:
Ui::JoystickWidget *m_ui; Ui::JoystickWidget *m_ui;
/** @brief Initialize all dynamic UI elements (button list, joystick names, etc.) */ /** @brief Initialize all dynamic UI elements (button list, joystick names, etc.).
* Only done once at startup.
*/
void initUI(); void initUI();
}; };
......
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