JoystickAxis.h 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================

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.
 */

28 29 30 31
#ifndef JOYSTICKAXIS_H
#define JOYSTICKAXIS_H

#include <QWidget>
32
#include "JoystickInput.h"
33
#include "Vehicle.h"
34 35 36 37 38 39 40 41 42 43 44 45

namespace Ui {
class JoystickAxis;
}

class JoystickAxis : public QWidget
{
    Q_OBJECT
    
public:
    explicit JoystickAxis(int id, QWidget *parent = 0);
    ~JoystickAxis();
46 47 48
    void setMapping(JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
    void setInverted(bool newValue);
    void setRangeLimit(bool newValue);
49 50
    void setAxisRangeMin(float min);
    void setAxisRangeMax(float max);
51

52 53
signals:
    /** @brief Signal a change in this axis' yaw/pitch/roll mapping */
54
    void mappingChanged(int id, JoystickInput::JOYSTICK_INPUT_MAPPING newMapping);
55
    /** @brief Signal a change in this axis' inversion status */
56 57 58
    void inversionChanged(int id, bool inversion);
    /** @brief Signal a change in this axis' range setting. If limited is true then only the positive values should be read from this axis. */
    void rangeChanged(int id, bool limited);
59

60
public slots:
61 62 63 64
    /** @brief Update the displayed value of the included progressbar.
     * @param value A value between -1.0 and 1.0.
     */
    void setValue(float value);
65
    /** @brief Specify the UAS that this axis should track for displaying throttle properly. */
66
    void activeVehicleChanged(Vehicle* vehicle);
67 68
    
private:
69
    int id; ///< The ID for this axis. Corresponds to the IDs used by JoystickInput.
70
    Ui::JoystickAxis *ui;
71 72 73 74 75
    /**
     * @brief Update the UI based on both the current UAS and the current axis mapping.
     * @param uas The currently-active UAS.
     * @param axisMapping The new mapping for this axis.
     */
76
    void updateUIBasedOnUAS(Vehicle* vehicle, JoystickInput::JOYSTICK_INPUT_MAPPING axisMapping);
77 78 79 80

private slots:
    /** @brief Handle changes to the mapping dropdown bar. */
    void mappingComboBoxChanged(int newMapping);
81
    /** @brief Emit signal when the inversion checkbox is changed. */
82
    void inversionCheckBoxChanged(bool inverted);
83 84
    /** @brief Emit signal when the range checkbox is changed. */
    void rangeCheckBoxChanged(bool inverted);
85 86 87
};

#endif // JOYSTICKAXIS_H