dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
gcscontrolgadgetoptionspage.cpp
Go to the documentation of this file.
1 
12 /*
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.
17  *
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.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
29 #include "ui_gcscontrolgadgetoptionspage.h"
30 #include "gcscontrol.h"
31 
32 #include <QFileDialog>
33 #include <QtAlgorithms>
34 #include <QStringList>
35 
37  QObject *parent)
38  : IOptionsPage(parent)
39  , m_config(config)
40 {
41  options_page = NULL;
42 
43 #if defined(USE_SDL)
44  sdlGamepad = dynamic_cast<GCSControl *>(parent)->sdlGamepad;
45 #endif
46 }
47 
49 {
50 }
51 
53 {
54  Q_UNUSED(count);
55 }
56 
57 #if defined(USE_SDL)
58 void GCSControlGadgetOptionsPage::buttonState(ButtonNumber number, bool pressed)
59 {
60  if (options_page) {
61  QList<QCheckBox *> rbList;
62  rbList << options_page->buttonInput0 << options_page->buttonInput1
63  << options_page->buttonInput2 << options_page->buttonInput3
64  << options_page->buttonInput4 << options_page->buttonInput5
65  << options_page->buttonInput6 << options_page->buttonInput7;
66 
67  if (number < 8) // We only support 8 buttons
68  {
69  rbList.at(number)->setChecked(pressed);
70  }
71  }
72 }
73 
75 {
76  if (options_page) {
77  QList<QProgressBar *> pbList;
78  pbList << options_page->joyCh0 << options_page->joyCh1 << options_page->joyCh2
79  << options_page->joyCh3 << options_page->joyCh4 << options_page->joyCh5
80  << options_page->joyCh6 << options_page->joyCh7;
81  int i = 0;
82  foreach (qint16 value, values) {
83  if (i > 7)
84  break; // We only support 7 channels
85  if (chRevList.at(i)->isChecked() == 1)
86  value = 65535 - value;
87  if (pbList.at(i)->minimum() > value)
88  pbList.at(i)->setMinimum(value);
89  if (pbList.at(i)->maximum() < value)
90  pbList.at(i)->setMaximum(value);
91  pbList.at(i++)->setValue(value);
92  }
93  }
94 }
95 #endif
96 
97 // creates options page widget (uses the UI file)
98 QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
99 {
100  Q_UNUSED(parent);
101 
102  int i;
103  options_page = new Ui::GCSControlGadgetOptionsPage();
104  QWidget *optionsPageWidget = new QWidget;
105  options_page->setupUi(optionsPageWidget);
106 
107  options_page->gcsReceiverCB->setChecked(m_config->getGcsReceiverMode());
108 
109  // QList<QComboBox*> chList;
110  chList.clear();
111  chList << options_page->channel0 << options_page->channel1 << options_page->channel2
112  << options_page->channel3 << options_page->channel4 << options_page->channel5
113  << options_page->channel6 << options_page->channel7;
114  QStringList chOptions;
115  chOptions << "None"
116  << "Roll"
117  << "Pitch"
118  << "Yaw"
119  << "Throttle";
120  foreach (QComboBox *qb, chList) {
121  qb->addItems(chOptions);
122  }
123  // QList<QCheckBox*> chRevList;
124  chRevList.clear();
125  chRevList << options_page->revCheckBox_1 << options_page->revCheckBox_2
126  << options_page->revCheckBox_3 << options_page->revCheckBox_4
127  << options_page->revCheckBox_5 << options_page->revCheckBox_6
128  << options_page->revCheckBox_7 << options_page->revCheckBox_8;
129 
130  // QList<QComboBox*> buttonFunctionList;
131  buttonFunctionList.clear();
132  buttonFunctionList << options_page->buttonFunction0 << options_page->buttonFunction1
133  << options_page->buttonFunction2 << options_page->buttonFunction3
134  << options_page->buttonFunction4 << options_page->buttonFunction5
135  << options_page->buttonFunction6 << options_page->buttonFunction7;
136  QStringList buttonOptions;
137  buttonOptions << "-"
138  << "Roll"
139  << "Pitch"
140  << "Yaw"
141  << "Throttle"
142  << "Armed"
143  << "GCS Control";
144  foreach (QComboBox *qb, buttonFunctionList) {
145  qb->addItems(buttonOptions);
146  }
147  // QList<QComboBox*> buttonActionList;
148  buttonActionList.clear();
149  buttonActionList << options_page->buttonAction0 << options_page->buttonAction1
150  << options_page->buttonAction2 << options_page->buttonAction3
151  << options_page->buttonAction4 << options_page->buttonAction5
152  << options_page->buttonAction6 << options_page->buttonAction7;
153  QStringList buttonActionOptions;
154  buttonActionOptions << "Does nothing"
155  << "Increases"
156  << "Decreases"
157  << "Toggles";
158  foreach (QComboBox *qb, buttonActionList) {
159  qb->addItems(buttonActionOptions);
160  }
161  // QList<QDoubleSpinBox*> buttonValueList;
162  buttonValueList.clear();
163  buttonValueList << options_page->buttonAmount0 << options_page->buttonAmount1
164  << options_page->buttonAmount2 << options_page->buttonAmount3
165  << options_page->buttonAmount4 << options_page->buttonAmount5
166  << options_page->buttonAmount6 << options_page->buttonAmount7;
167  // QList<QLabel*> buttonLabelList;
168  buttonLabelList.clear();
169  buttonLabelList << options_page->buttonLabel0 << options_page->buttonLabel1
170  << options_page->buttonLabel2 << options_page->buttonLabel3
171  << options_page->buttonLabel4 << options_page->buttonLabel5
172  << options_page->buttonLabel6 << options_page->buttonLabel7;
173 
174  for (i = 0; i < 8; i++) {
175  buttonActionList.at(i)->setCurrentIndex(m_config->getbuttonSettings(i).ActionID);
176  buttonFunctionList.at(i)->setCurrentIndex(m_config->getbuttonSettings(i).FunctionID);
177  buttonValueList.at(i)->setValue(m_config->getbuttonSettings(i).Amount);
178 
179  connect(buttonFunctionList.at(i), SIGNAL(currentIndexChanged(int)), this,
180  SLOT(updateButtonFunction()));
181  // connect(buttonActionList.at(i),SIGNAL(currentIndexChanged(int)),this,SLOT(updateButtonActions[i]()));
183  buttonFunctionList.at(i)->setCurrentIndex(m_config->getbuttonSettings(i).FunctionID);
184  }
185  connect(buttonActionList.at(0), SIGNAL(currentIndexChanged(int)), this,
186  SLOT(updateButtonAction_0()));
187  connect(buttonActionList.at(1), SIGNAL(currentIndexChanged(int)), this,
188  SLOT(updateButtonAction_1()));
189  connect(buttonActionList.at(2), SIGNAL(currentIndexChanged(int)), this,
190  SLOT(updateButtonAction_2()));
191  connect(buttonActionList.at(3), SIGNAL(currentIndexChanged(int)), this,
192  SLOT(updateButtonAction_3()));
193  connect(buttonActionList.at(4), SIGNAL(currentIndexChanged(int)), this,
194  SLOT(updateButtonAction_4()));
195  connect(buttonActionList.at(5), SIGNAL(currentIndexChanged(int)), this,
196  SLOT(updateButtonAction_5()));
197  connect(buttonActionList.at(6), SIGNAL(currentIndexChanged(int)), this,
198  SLOT(updateButtonAction_6()));
199  connect(buttonActionList.at(7), SIGNAL(currentIndexChanged(int)), this,
200  SLOT(updateButtonAction_7()));
201 
202  // Controls mode are from 1 to 4.
203  if (m_config->getControlsMode() > 0 && m_config->getControlsMode() < 5)
204  options_page->controlsMode->setCurrentIndex(m_config->getControlsMode() - 1);
205  else
206  qDebug() << "GCSControl: Invalid control modes setting! Did you edit by hand?";
207 
208  QList<int> ql = m_config->getChannelsMapping();
209  for (int i = 0; i < 4; i++) {
210  if (ql.at(i) > -1)
211  chList.at(ql.at(i))->setCurrentIndex(i + 1);
212  }
213  QList<bool> qlChRev = m_config->getChannelsReverse();
214  for (i = 0; i < 8; i++) {
215  chRevList.at(i)->setChecked(qlChRev.at(i));
216  ;
217  }
218 
219 #if defined(USE_SDL)
220  connect(sdlGamepad, SIGNAL(axesValues(QListInt16)), this, SLOT(axesValues(QListInt16)));
221  connect(sdlGamepad, SIGNAL(buttonState(ButtonNumber, bool)), this,
222  SLOT(buttonState(ButtonNumber, bool)));
223  connect(sdlGamepad, SIGNAL(gamepads(quint8)), this, SLOT(gamepads(quint8)));
224 #endif
225 
226  return optionsPageWidget;
227 }
228 
236 {
237  m_config->setControlsMode(options_page->controlsMode->currentIndex() + 1);
238 
239  int roll = -1, pitch = -1, yaw = -1, throttle = -1;
240  for (int i = 0; i < chList.length(); i++) {
241  switch (chList.at(i)->currentIndex()) {
242  case 1:
243  roll = i;
244  break;
245  case 2:
246  pitch = i;
247  break;
248  case 3:
249  yaw = i;
250  break;
251  case 4:
252  throttle = i;
253  break;
254  }
255  }
256  m_config->setRPYTchannels(roll, pitch, yaw, throttle);
257 
258  m_config->setGcsReceiverMode(options_page->gcsReceiverCB->checkState());
259 
260  for (unsigned int j = 0; j < 8; j++) {
261  m_config->setbuttonSettingsAction(j, buttonActionList.at(j)->currentIndex());
262  m_config->setbuttonSettingsFunction(j, buttonFunctionList.at(j)->currentIndex());
263  m_config->setbuttonSettingsAmount(j, buttonValueList.at(j)->value());
264  m_config->setChannelReverse(j, chRevList.at(j)->isChecked());
265  }
266 }
267 
269 {
270 #if defined(USE_SDL)
271  disconnect(sdlGamepad, 0, this, 0);
272 #endif
273  delete options_page;
274  options_page = NULL;
275 }
276 
278 {
279  for (unsigned int i = 0; i < 8; i++) {
280  if (buttonActionList.at(i)->currentText().compare("Does nothing") == 0) {
281  buttonFunctionList.at(i)->setVisible(0);
282  buttonLabelList.at(i)->setVisible(0);
283  buttonValueList.at(i)->setVisible(0);
284  } else if (buttonActionList.at(i)->currentText().compare("Toggles") == 0) {
285  buttonFunctionList.at(i)->setVisible(1);
286  buttonLabelList.at(i)->setVisible(0);
287  buttonValueList.at(i)->setVisible(0);
288  } else {
289  buttonFunctionList.at(i)->setVisible(1);
290  buttonLabelList.at(i)->setVisible(1);
291  buttonValueList.at(i)->setVisible(1);
292  }
293  }
294 }
295 
297 {
298  QStringList buttonOptions;
299 
300  {
301  if (buttonActionList.at(controlID)->currentText().compare("Does nothing") == 0) {
302  buttonFunctionList.at(controlID)->setVisible(0);
303  buttonLabelList.at(controlID)->setVisible(0);
304  buttonValueList.at(controlID)->setVisible(0);
305  } else if (buttonActionList.at(controlID)->currentText().compare("Toggles") == 0) {
306  disconnect(buttonFunctionList.at(controlID), SIGNAL(currentIndexChanged(int)), this,
307  SLOT(updateButtonFunction()));
308  buttonOptions << "-"
309  << "Armed"
310  << "GCS Control";
311  buttonFunctionList.at(controlID)->clear();
312  buttonFunctionList.at(controlID)->insertItems(-1, buttonOptions);
313 
314  buttonFunctionList.at(controlID)->setVisible(1);
315  buttonLabelList.at(controlID)->setVisible(0);
316  buttonValueList.at(controlID)->setVisible(0);
317  connect(buttonFunctionList.at(controlID), SIGNAL(currentIndexChanged(int)), this,
318  SLOT(updateButtonFunction()));
319  } else {
320  disconnect(buttonFunctionList.at(controlID), SIGNAL(currentIndexChanged(int)), this,
321  SLOT(updateButtonFunction()));
322  buttonOptions << "-"
323  << "Roll"
324  << "Pitch"
325  << "Yaw"
326  << "Throttle";
327  buttonFunctionList.at(controlID)->clear();
328  buttonFunctionList.at(controlID)->addItems(buttonOptions);
329 
330  buttonFunctionList.at(controlID)->setVisible(1);
331  buttonLabelList.at(controlID)->setVisible(1);
332  buttonValueList.at(controlID)->setVisible(1);
333  connect(buttonFunctionList.at(controlID), SIGNAL(currentIndexChanged(int)), this,
334  SLOT(updateButtonFunction()));
335  }
336  }
337 }
buttonSettingsStruct getbuttonSettings(int i)
void setChannelReverse(int i, bool Reverse)
void setbuttonSettingsFunction(int i, int FunctionID)
void buttonState(ButtonNumber number, bool pressed)
for i
Definition: OPPlots.m:140
void setbuttonSettingsAction(int i, int ActionID)
GCSControlGadgetOptionsPage(GCSControlGadgetConfiguration *config, QObject *parent=nullptr)
QWidget * createPage(QWidget *parent)
void setbuttonSettingsAmount(int i, double Amount)
void setRPYTchannels(int roll, int pitch, int yaw, int throttle)