QGCParamWidget.h 5.05 KB
Newer Older
1 2 3 4
/*=====================================================================

QGroundControl Open Source Ground Control Station

5
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

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
 *   @brief Declaration of class QGCParamWidget
 *   @author Lorenz Meier <mail@qgroundcontrol.org>
 */

pixhawk's avatar
pixhawk committed
30 31 32 33 34 35 36
#ifndef QGCPARAMWIDGET_H
#define QGCPARAMWIDGET_H

#include <QWidget>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QMap>
lm's avatar
lm committed
37
#include <QLabel>
38
#include <QTimer>
pixhawk's avatar
pixhawk committed
39

40
#include "QGCUASParamManager.h"
pixhawk's avatar
pixhawk committed
41 42
#include "UASInterface.h"

43 44 45
/**
 * @brief Widget to read/set onboard parameters
 */
46
class QGCParamWidget : public QGCUASParamManager
pixhawk's avatar
pixhawk committed
47
{
48
    Q_OBJECT
pixhawk's avatar
pixhawk committed
49
public:
50
    QGCParamWidget(UASInterface* uas, QWidget *parent = 0);
51
    /** @brief Get the UAS of this widget */
pixhawk's avatar
pixhawk committed
52
    UASInterface* getUAS();
LM's avatar
LM committed
53 54 55 56 57 58 59

    bool isParamMinKnown(const QString& param) { return paramMin.contains(param); }
    bool isParamMaxKnown(const QString& param) { return paramMax.contains(param); }
    bool isParamDefaultKnown(const QString& param) { return paramDefault.contains(param); }
    double getParamMin(const QString& param) { return paramMin.value(param, 0.0f); }
    double getParamMax(const QString& param) { return paramMax.value(param, 0.0f); }
    double getParamDefault(const QString& param) { return paramDefault.value(param, 0.0f); }
Lorenz Meier's avatar
Lorenz Meier committed
60
    QString getParamInfo(const QString& param) { return paramToolTips.value(param, ""); }
61
    void setParamInfo(const QMap<QString,QString>& param) { paramToolTips = param; }
LM's avatar
LM committed
62

pixhawk's avatar
pixhawk committed
63
signals:
64
    /** @brief A parameter was changed in the widget, NOT onboard */
oberion's avatar
oberion committed
65
    //void parameterChanged(int component, QString parametername, float value); // defined in QGCUASParamManager already
66 67
    /** @brief Request a single parameter */
    void requestParameter(int component, int parameter);
68 69
    /** @brief Request a single parameter by name */
    void requestParameter(int component, const QString& parameter);
pixhawk's avatar
pixhawk committed
70
public slots:
71 72
    /** @brief Add a component to the list */
    void addComponent(int uas, int component, QString componentName);
lm's avatar
lm committed
73
    /** @brief Add a parameter to the list with retransmission / safety checks */
74
    void addParameter(int uas, int component, int paramCount, int paramId, QString parameterName, QVariant value);
75
    /** @brief Add a parameter to the list */
76
    void addParameter(int uas, int component, QString parameterName, QVariant value);
77 78
    /** @brief Request list of parameters from MAV */
    void requestParameterList();
79 80
    /** @brief Request one single parameter */
    void requestParameterUpdate(int component, const QString& parameter);
81
    /** @brief Set one parameter, changes value in RAM of MAV */
82
    void setParameter(int component, QString parameterName, QVariant value);
83 84 85 86
    /** @brief Set all parameters, changes the value in RAM of MAV */
    void setParameters();
    /** @brief Write the current parameters to permanent storage (EEPROM/HDD) */
    void writeParameters();
87 88
    /** @brief Read the parameters from permanent storage to RAM */
    void readParameters();
89
    /** @brief Clear the parameter list */
pixhawk's avatar
pixhawk committed
90
    void clear();
lm's avatar
lm committed
91
    /** @brief Update when user changes parameters */
92
    void parameterItemChanged(QTreeWidgetItem* prev, int column);
93 94 95 96 97

    /** @brief Store parameters to a file */
    void saveParameters();
    /** @brief Load parameters from a file */
    void loadParameters();
98 99 100 101

    /** @brief Check for missing parameters */
    void retransmissionGuardTick();

pixhawk's avatar
pixhawk committed
102
protected:
lm's avatar
lm committed
103 104
    QTreeWidget* tree;   ///< The parameter tree
    QLabel* statusLabel; ///< Parameter transmission label
105
    QMap<int, QTreeWidgetItem*>* components; ///< The list of components
pixhawk's avatar
pixhawk committed
106
    QMap<int, QMap<QString, QTreeWidgetItem*>* > paramGroups; ///< Parameter groups
107

lm's avatar
lm committed
108 109 110
    // Tooltip data structures
    QMap<QString, QString> paramToolTips; ///< Tooltip values
    // Min / Default / Max data structures
111 112 113
    QMap<QString, double> paramMin; ///< Minimum param values
    QMap<QString, double> paramDefault; ///< Default param values
    QMap<QString, double> paramMax; ///< Minimum param values
lm's avatar
lm committed
114

115 116
    /** @brief Activate / deactivate parameter retransmission */
    void setRetransmissionGuardEnabled(bool enabled);
117 118
    /** @brief Load  settings */
    void loadSettings();
lm's avatar
lm committed
119 120
    /** @brief Load meta information from CSV */
    void loadParameterInfoCSV(const QString& autopilot, const QString& airframe);
pixhawk's avatar
pixhawk committed
121 122 123
};

#endif // QGCPARAMWIDGET_H