Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / gcscontrol / gcscontrolgadgetconfiguration.cpp
blob4c6dbf835cacd25ecd3484bddf349b424d59f94a
1 /**
2 ******************************************************************************
4 * @file gcscontrolgadgetconfiguration.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
9 * @{
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
21 * for more details.
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"
30 /**
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)
76 udp_port = port;
77 udp_host = QHostAddress(host);
80 int GCSControlGadgetConfiguration::getUDPControlPort()
82 return udp_port;
85 QHostAddress GCSControlGadgetConfiguration::getUDPControlHost()
87 return udp_host;
90 void GCSControlGadgetConfiguration::setRPYTchannels(int roll, int pitch, int yaw, int throttle)
92 rollChannel = roll;
93 pitchChannel = pitch;
94 yawChannel = yaw;
95 throttleChannel = throttle;
98 QList<int> GCSControlGadgetConfiguration::getChannelsMapping()
100 QList<int> ql;
101 ql << rollChannel << pitchChannel << yawChannel << throttleChannel;
102 return ql;
105 QList<bool> GCSControlGadgetConfiguration::getChannelsReverse()
107 QList<bool> ql;
108 for (int i = 0; i < 8; i++) {
109 ql << channelReverse[i];
111 return ql;
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]);