2 ******************************************************************************
4 * @file gcscontrolgadgetconfiguration.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
10 * @brief A gadget to control the UAV, either from the keyboard or a joystick
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "gcscontrolgadgetconfiguration.h"
31 * Loads a saved configuration or defaults if non exist.
34 GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(QString classId
, QSettings
&settings
, QObject
*parent
) :
35 IUAVGadgetConfiguration(classId
, parent
)
37 controlsMode
= settings
.value("controlsMode").toInt();
38 rollChannel
= settings
.value("rollChannel", -1).toInt();
39 pitchChannel
= settings
.value("pitchChannel", -1).toInt();
40 yawChannel
= settings
.value("yawChannel", -1).toInt();
41 throttleChannel
= settings
.value("throttleChannel", -1).toInt();
43 udp_port
= settings
.value("controlPortUDP").toUInt();
44 udp_host
= QHostAddress(settings
.value("controlHostUDP").toString());
46 for (int i
= 0; i
< 8; i
++) {
47 buttonSettings
[i
].ActionID
= settings
.value(QString().sprintf("button%dAction", i
)).toInt();
48 buttonSettings
[i
].FunctionID
= settings
.value(QString().sprintf("button%dFunction", i
)).toInt();
49 buttonSettings
[i
].Amount
= settings
.value(QString().sprintf("button%dAmount", i
)).toDouble();
50 channelReverse
[i
] = settings
.value(QString().sprintf("channel%dReverse", i
)).toBool();
54 GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(const GCSControlGadgetConfiguration
&obj
) :
55 IUAVGadgetConfiguration(obj
.classId(), obj
.parent())
57 controlsMode
= obj
.controlsMode
;
58 rollChannel
= obj
.rollChannel
;
59 pitchChannel
= obj
.pitchChannel
;
60 yawChannel
= obj
.yawChannel
;
61 throttleChannel
= obj
.throttleChannel
;
63 udp_host
= obj
.udp_host
;
64 udp_port
= obj
.udp_port
;
66 for (int i
= 0; i
< 8; i
++) {
67 buttonSettings
[i
].ActionID
= obj
.buttonSettings
[i
].ActionID
;
68 buttonSettings
[i
].FunctionID
= obj
.buttonSettings
[i
].FunctionID
;
69 buttonSettings
[i
].Amount
= obj
.buttonSettings
[i
].Amount
;
70 channelReverse
[i
] = obj
.channelReverse
[i
];
74 void GCSControlGadgetConfiguration::setUDPControlSettings(int port
, QString host
)
77 udp_host
= QHostAddress(host
);
80 int GCSControlGadgetConfiguration::getUDPControlPort()
85 QHostAddress
GCSControlGadgetConfiguration::getUDPControlHost()
90 void GCSControlGadgetConfiguration::setRPYTchannels(int roll
, int pitch
, int yaw
, int throttle
)
95 throttleChannel
= throttle
;
98 QList
<int> GCSControlGadgetConfiguration::getChannelsMapping()
101 ql
<< rollChannel
<< pitchChannel
<< yawChannel
<< throttleChannel
;
105 QList
<bool> GCSControlGadgetConfiguration::getChannelsReverse()
108 for (int i
= 0; i
< 8; i
++) {
109 ql
<< channelReverse
[i
];
115 * Clones a configuration.
118 IUAVGadgetConfiguration
*GCSControlGadgetConfiguration::clone() const
120 return new GCSControlGadgetConfiguration(*this);
124 * Saves a configuration.
127 void GCSControlGadgetConfiguration::saveConfig(QSettings
&settings
) const
129 settings
.setValue("controlsMode", controlsMode
);
130 settings
.setValue("rollChannel", rollChannel
);
131 settings
.setValue("pitchChannel", pitchChannel
);
132 settings
.setValue("yawChannel", yawChannel
);
133 settings
.setValue("throttleChannel", throttleChannel
);
135 settings
.setValue("controlPortUDP", QString::number(udp_port
));
136 settings
.setValue("controlHostUDP", udp_host
.toString());
138 for (int i
= 0; i
< 8; i
++) {
139 settings
.setValue(QString().sprintf("button%dAction", i
), buttonSettings
[i
].ActionID
);
140 settings
.setValue(QString().sprintf("button%dFunction", i
), buttonSettings
[i
].FunctionID
);
141 settings
.setValue(QString().sprintf("button%dAmount", i
), buttonSettings
[i
].Amount
);
142 settings
.setValue(QString().sprintf("channel%dReverse", i
), channelReverse
[i
]);