dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
setupwizard.cpp
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #include "setupwizard.h"
32 #include "pages/tlstartpage.h"
33 #include "pages/tlendpage.h"
35 #include "pages/controllerpage.h"
36 #include "pages/vehiclepage.h"
37 #include "pages/multipage.h"
38 #include "pages/fixedwingpage.h"
39 #include "pages/helipage.h"
40 #include "pages/surfacepage.h"
41 #include "pages/inputpage.h"
43 #include "pages/outputpage.h"
45 #include "pages/summarypage.h"
46 #include "pages/savepage.h"
48 #include "pages/rebootpage.h"
52 #include "actuatorsettings.h"
53 
54 SetupWizard::SetupWizard(bool autoLaunched, QWidget *parent)
55  : QWizard(parent)
57  , m_controllerType(NULL)
58  , m_vehicleType(VEHICLE_UNKNOWN)
59  , m_inputType(Core::IBoardType::INPUT_TYPE_UNKNOWN)
60  , m_escType(ESC_UNKNOWN)
61  , m_calibrationPerformed(false)
62  , m_restartNeeded(false)
63  , m_autoLaunched(autoLaunched)
64  , m_connectionManager(nullptr)
65 {
66  connect(this, &QWizard::rejected, this, &SetupWizard::boardIgnorePrompt);
67  setWindowTitle(tr("dRonin Setup Wizard"));
68  setOption(QWizard::IndependentPages, false);
69  for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
70  m_actuatorSettings << actuatorChannelSettings();
71  }
72  setWizardStyle(QWizard::ModernStyle);
73  setMinimumSize(600, 500);
74  resize(600, 500);
75  createPages();
76 }
77 
79 {
80  switch (currentId()) {
81  case PAGE_START:
82  return PAGE_CONTROLLER;
83 
84  case PAGE_CONTROLLER: {
85  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
86  Q_ASSERT(pm);
87  UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
88  Q_ASSERT(utilMngr);
89 
90  const QString fwHash = utilMngr->getFirmwareHash();
91  const QString gcsHash = utilMngr->getGcsHash();
92  if (!fwHash.length() || fwHash != gcsHash) {
93  qobject_cast<BoardtypeUnknown *>(page(PAGE_BOARDTYPE_UNKNOWN))
94  ->setFailureType(BoardtypeUnknown::UNKNOWN_FIRMWARE);
95  return PAGE_BOARDTYPE_UNKNOWN;
96  }
97 
99  if (type == NULL) {
100  qobject_cast<BoardtypeUnknown *>(page(PAGE_BOARDTYPE_UNKNOWN))
101  ->setFailureType(BoardtypeUnknown::UNKNOWN_BOARD);
102  return PAGE_BOARDTYPE_UNKNOWN;
103  }
104 
105  if (type->isInputConfigurationSupported())
106  return PAGE_INPUT;
107  else
108  return PAGE_INPUT_NOT_SUPPORTED;
109  }
110  case PAGE_VEHICLES: {
111  switch (getVehicleType()) {
112  case VEHICLE_MULTI:
113  return PAGE_MULTI;
114 
115  case VEHICLE_FIXEDWING:
116  return PAGE_FIXEDWING;
117 
118  case VEHICLE_HELI:
119  return PAGE_HELI;
120 
121  case VEHICLE_SURFACE:
122  return PAGE_SURFACE;
123 
124  default:
125  return PAGE_NOTYETIMPLEMENTED;
126  }
127  }
128  case PAGE_MULTI:
129  return PAGE_OUTPUT;
130 
131  case PAGE_INPUT:
132  if (isRestartNeeded()) {
133  saveHardwareSettings();
134  return PAGE_REBOOT;
135  } else {
136  return PAGE_VEHICLES;
137  }
138  case PAGE_REBOOT:
139  return PAGE_VEHICLES;
140 
141  case PAGE_OUTPUT:
142  return PAGE_SUMMARY;
143 
144  case PAGE_BIAS_CALIBRATION:
145  return PAGE_OUTPUT_CALIBRATION;
146 
147  case PAGE_OUTPUT_CALIBRATION:
148  return PAGE_SAVE;
149 
150  case PAGE_SUMMARY: {
152  if (type != NULL)
153  return PAGE_BIAS_CALIBRATION;
154  else
155  return PAGE_NOTYETIMPLEMENTED;
156  }
157  case PAGE_SAVE:
158  return PAGE_END;
159 
160  case PAGE_INPUT_NOT_SUPPORTED:
161  // The user is informed on this page to configure manually and restart the wizard
162  // but if they advance assume they have configured the input.
163  return PAGE_VEHICLES;
164 
165  case PAGE_BOARDTYPE_UNKNOWN:
166  case PAGE_NOTYETIMPLEMENTED:
167  return PAGE_END;
168 
169  default:
170  return -1;
171  }
172 }
173 
175 {
176  QString summary = "";
177 
178  summary.append("<b>").append(tr("Controller type: ")).append("</b>");
180  if (type != NULL)
181  summary.append(type->shortName());
182  else
183  summary.append(tr("Unknown"));
184 
185  summary.append("<br>");
186  summary.append("<b>").append(tr("Vehicle type: ")).append("</b>");
187  switch (getVehicleType()) {
188  case VEHICLE_MULTI:
189  summary.append(tr("Multirotor"));
190 
191  summary.append("<br>");
192  summary.append("<b>").append(tr("Vehicle sub type: ")).append("</b>");
193  switch (getVehicleSubType()) {
195  summary.append(tr("Tricopter"));
196  break;
198  summary.append(tr("Quadcopter X"));
199  break;
201  summary.append(tr("Quadcopter +"));
202  break;
204  summary.append(tr("Hexacopter"));
205  break;
207  summary.append(tr("Hexacopter Coax (Y6)"));
208  break;
210  summary.append(tr("Hexacopter X"));
211  break;
213  summary.append(tr("Octocopter"));
214  break;
216  summary.append(tr("Octocopter Coax X"));
217  break;
219  summary.append(tr("Octocopter Coax +"));
220  break;
222  summary.append(tr("Octocopter V"));
223  break;
224  default:
225  summary.append(tr("Unknown"));
226  break;
227  }
228 
229  break;
230  case VEHICLE_FIXEDWING:
231  summary.append(tr("Fixed wing"));
232  break;
233  case VEHICLE_HELI:
234  summary.append(tr("Helicopter"));
235  break;
236  case VEHICLE_SURFACE:
237  summary.append(tr("Surface vehicle"));
238  break;
239  default:
240  summary.append(tr("Unknown"));
241  }
242 
243  summary.append("<br>");
244  summary.append("<b>").append(tr("Input type: ")).append("</b>");
245  switch (getInputType()) {
247  summary.append(tr("PWM (One cable per channel)"));
248  break;
250  summary.append(tr("PPM (One cable for all channels)"));
251  break;
253  summary.append(tr("Futaba S.Bus"));
254  break;
256  summary.append(tr("Futaba S.Bus Non-inverted"));
257  break;
259  summary.append(tr("Spektrum satellite (DSM)"));
260  break;
262  summary.append(tr("Graupner HoTT (SUMD)"));
263  break;
265  summary.append(tr("Graupner HoTT (SUMH)"));
266  break;
268  summary.append(tr("FlySky I-Bus"));
269  break;
271  summary.append(tr("Multiplex SRXL"));
272  break;
274  summary.append(tr("Team BlackSheep Crossfire"));
275  break;
276  default:
277  summary.append(tr("Unknown"));
278  }
279 
280  summary.append("<br>");
281  summary.append("<b>").append(tr("ESC type: ")).append("</b>");
282  switch (getESCType()) {
283  case ESC_LEGACY:
284  summary.append(tr("Legacy ESC (50 Hz)"));
285  break;
286  case ESC_RAPID:
287  summary.append(tr("Rapid ESC (400 Hz)"));
288  break;
289  case ESC_ONESHOT125:
290  summary.append(tr("Oneshot125 (SyncPwm + 125-250us)"));
291  break;
292  case ESC_ONESHOT42:
293  summary.append(tr("Oneshot42 (SyncPWM + 42-83us"));
294  break;
295  case ESC_DSHOT300:
296  summary.append(tr("Dshot300"));
297  break;
298  case ESC_DSHOT600:
299  summary.append(tr("Dshot600"));
300  break;
301  case ESC_DSHOT1200:
302  summary.append(tr("Dshot1200"));
303  break;
304  default:
305  summary.append(tr("Unknown"));
306  }
307 
308  /*
309  summary.append("<br>");
310  summary.append("<b>").append(tr("Reboot required: ")).append("</b>");
311  summary.append(isRestartNeeded() ? tr("<font color='red'>Yes</font>") : tr("<font
312  color='green'>No</font>"));
313  */
314  return summary;
315 }
316 
317 void SetupWizard::createPages()
318 {
319  setPage(PAGE_START, new TLStartPage(this));
320  setPage(PAGE_CONTROLLER, new ControllerPage(this));
321  setPage(PAGE_VEHICLES, new VehiclePage(this));
322  setPage(PAGE_MULTI, new MultiPage(this));
323  setPage(PAGE_FIXEDWING, new FixedWingPage(this));
324  setPage(PAGE_HELI, new HeliPage(this));
325  setPage(PAGE_SURFACE, new SurfacePage(this));
326  setPage(PAGE_INPUT, new InputPage(this));
327  setPage(PAGE_INPUT_NOT_SUPPORTED, new InputPageNotSupported(this));
328  setPage(PAGE_OUTPUT, new OutputPage(this));
329  setPage(PAGE_BIAS_CALIBRATION, new BiasCalibrationPage(this));
330  setPage(PAGE_OUTPUT_CALIBRATION, new OutputCalibrationPage(this));
331  setPage(PAGE_SUMMARY, new SummaryPage(this));
332  setPage(PAGE_SAVE, new SavePage(this));
333  setPage(PAGE_REBOOT, new RebootPage(this));
334  setPage(PAGE_NOTYETIMPLEMENTED, new NotYetImplementedPage(this));
335  setPage(PAGE_BOARDTYPE_UNKNOWN, new BoardtypeUnknown(this));
336  setPage(PAGE_END, new TLEndPage(this));
337 
338  setStartId(PAGE_START);
339 
340  connect(button(QWizard::CustomButton1), &QAbstractButton::clicked, this,
341  &SetupWizard::customBackClicked);
342  setButtonText(QWizard::CustomButton1, buttonText(QWizard::BackButton));
343  QList<QWizard::WizardButton> button_layout;
344  button_layout << QWizard::Stretch << QWizard::CustomButton1 << QWizard::NextButton
345  << QWizard::CancelButton << QWizard::FinishButton;
346  setButtonLayout(button_layout);
347  connect(this, &QWizard::currentIdChanged, this, &SetupWizard::pageChanged);
348 }
349 
350 void SetupWizard::customBackClicked()
351 {
352  if (currentId() == PAGE_OUTPUT_CALIBRATION) {
353  static_cast<OutputCalibrationPage *>(currentPage())->customBackClicked();
354  } else {
355  back();
356  }
357 }
358 
359 void SetupWizard::pageChanged(int currId)
360 {
361  button(QWizard::CustomButton1)->setVisible(currId != PAGE_START);
362  button(QWizard::CancelButton)->setVisible(currId != PAGE_END);
363 }
364 
365 bool SetupWizard::saveHardwareSettings() const
366 {
367  VehicleConfigurationHelper helper(const_cast<SetupWizard *>(this));
368 
369  return helper.setupHardwareSettings();
370 }
371 
372 void SetupWizard::boardIgnorePrompt()
373 {
374  if (!m_autoLaunched)
375  return;
376 
377  QMessageBox prompt(QMessageBox::Question, tr("Setup Wizard Cancelled"),
378  tr("Would you like to prevent the setup wizard from automatically opening"
379  " for the remainder of this session?"), QMessageBox::Yes | QMessageBox::No, this);
380  if (prompt.exec() == QMessageBox::No)
381  return;
382 
383  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
384  UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
385  if (!utilMngr) {
386  qWarning() << "Can't get UAVObjectUtilManager";
387  Q_ASSERT(false);
388  return;
389  }
390  emit boardIgnored(utilMngr->getBoardCPUSerial());
391  qInfo() << "Setup wizard will be ignored for this board";
392 }
int nextId() const
Definition: setupwizard.cpp:78
SetupWizard::ESC_TYPE getESCType() const
Definition: setupwizard.h:68
SetupWizard::VEHICLE_TYPE getVehicleType() const
Definition: setupwizard.h:59
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
for i
Definition: OPPlots.m:140
void boardIgnored(QByteArray uuid)
SetupWizard(bool autoLaunched=false, QWidget *parent=nullptr)
Definition: setupwizard.cpp:54
bool isRestartNeeded() const
Definition: setupwizard.h:92
Core::IBoardType * getControllerType() const
Definition: setupwizard.h:56
QString getSummaryText()
virtual bool isInputConfigurationSupported(InputType type=INPUT_TYPE_ANY)
Determine if this board supports configuring the receiver.
Definition: iboardtype.h:186
The BoardtypeUnknown class tells the user this board type is unknown and unsupported.
SetupWizard::VEHICLE_SUB_TYPE getVehicleSubType() const
Definition: setupwizard.h:62
Definition: icore.h:39
Core::IBoardType::InputType getInputType() const
Definition: setupwizard.h:65
virtual QString shortName()=0
The VehicleConfigurationHelper class provides an interface between the settings selected in the wizar...
The InputPageNotSupported class Inform the user that they must manually configure input first...