LP-551 Changes from review, change names and fix typos.
[librepilot.git] / ground / gcs / src / plugins / config / configinputwidget.h
blob3df60305d8e8d0ad4102fd526b1caf40905bf434
1 /**
2 ******************************************************************************
4 * @file configservowidget.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup ConfigPlugin Config Plugin
10 * @{
11 * @brief Servo input configuration panel for the config gadget
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef CONFIGINPUTWIDGET_H
29 #define CONFIGINPUTWIDGET_H
31 #include "uavobjectwidgetutils/configtaskwidget.h"
33 #include "uavobject.h"
35 #include "manualcontrolcommand.h"
36 #include "manualcontrolsettings.h"
37 #include "actuatorsettings.h"
38 #include "mixersettings.h"
39 #include "flightmodesettings.h"
40 #include "receiveractivity.h"
41 #include "flightstatus.h"
42 #include "accessorydesired.h"
43 #include "systemsettings.h"
44 #include "hwsettings.h"
45 #include <QPointer>
46 #include <QWidget>
47 #include <QList>
48 #include <QTimer>
50 class Ui_InputWidget;
51 class Ui_InputWizardWidget;
53 class QEventLoop;
54 class QSvgRenderer;
55 class QGraphicsSvgItem;
56 class QGraphicsSimpleTextItem;
58 class ConfigInputWidget : public ConfigTaskWidget {
59 Q_OBJECT
60 public:
61 ConfigInputWidget(QWidget *parent = 0);
62 ~ConfigInputWidget();
63 enum wizardSteps { wizardWelcome, wizardChooseMode, wizardChooseType, wizardIdentifySticks, wizardIdentifyCenter, wizardIdentifyLimits, wizardIdentifyInverted, wizardFinish, wizardNone };
64 enum txMode { mode1, mode2, mode3, mode4 };
65 enum txMovements { moveLeftVerticalStick, moveRightVerticalStick, moveLeftHorizontalStick, moveRightHorizontalStick, moveAccess0, moveAccess1, moveAccess2, moveAccess3, moveFlightMode, centerAll, moveAll, nothing };
66 enum txMovementType { vertical, horizontal, jump, mix };
67 enum txType { acro, heli, ground };
68 void startInputWizard()
70 goToWizard();
72 void enableControls(bool enable);
73 bool shouldObjectBeSaved(UAVObject *object);
75 public slots:
76 void setOutputConfigSafe(bool status);
78 signals:
79 void inputCalibrationStateChanged(bool newState);
81 private:
82 bool throttleError;
83 bool growing;
84 bool reverse[ManualControlSettings::CHANNELNEUTRAL_NUMELEM];
85 bool outputConfigIsSafe;
86 txMovements currentMovement;
87 int movePos;
88 void setTxMovement(txMovements movement);
89 Ui_InputWidget *ui;
90 Ui_InputWizardWidget *wizardUi;
92 wizardSteps wizardStep;
93 QList<QPointer<QWidget> > extraWidgets;
94 txMode transmitterMode;
95 txType transmitterType;
96 struct channelsStruct {
97 bool operator ==(const channelsStruct & rhs) const
99 return (group == rhs.group) && (number == rhs.number);
101 bool operator !=(const channelsStruct & rhs) const
103 return !operator==(rhs);
105 int group;
106 int number;
107 int channelIndex;
108 } lastChannel;
109 channelsStruct currentChannel;
110 QList<channelsStruct> usedChannels;
111 bool channelDetected;
112 QEventLoop *loop;
113 bool skipflag;
115 // Variables to support delayed transitions when detecting input controls.
116 QTimer nextDelayedTimer;
117 int nextDelayedTick;
118 int nextDelayedLatestActivityTick;
120 int currentChannelNum;
121 QList<int> heliChannelOrder;
122 QList<int> acroChannelOrder;
123 QList<int> groundChannelOrder;
125 uint16_t flightModeSignalValue[FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM];
127 UAVObject::Metadata manualControlMdata;
128 ManualControlCommand *manualCommandObj;
129 ManualControlCommand::DataFields manualCommandData;
131 FlightStatus *flightStatusObj;
132 FlightStatus::DataFields flightStatusData;
134 UAVObject::Metadata accessoryDesiredMdata0;
135 AccessoryDesired *accessoryDesiredObj0;
136 AccessoryDesired *accessoryDesiredObj1;
137 AccessoryDesired *accessoryDesiredObj2;
138 AccessoryDesired *accessoryDesiredObj3;
139 AccessoryDesired *rssiDesiredObj4;
141 ManualControlSettings *manualSettingsObj;
142 ManualControlSettings::DataFields manualSettingsData;
144 ActuatorSettings *actuatorSettingsObj;
145 ActuatorSettings::DataFields actuatorSettingsData;
147 FlightModeSettings *flightModeSettingsObj;
148 FlightModeSettings::DataFields flightModeSettingsData;
149 ReceiverActivity *receiverActivityObj;
150 ReceiverActivity::DataFields receiverActivityData;
152 SystemSettings *systemSettingsObj;
153 SystemSettings::DataFields systemSettingsData;
155 HwSettings *hwSettingsObj;
157 typedef struct {
158 ManualControlSettings::DataFields manualSettingsData;
159 ActuatorSettings::DataFields actuatorSettingsData;
160 FlightModeSettings::DataFields flightModeSettingsData;
161 SystemSettings::DataFields systemSettingsData;
162 } Memento;
163 Memento memento;
165 QSvgRenderer *m_renderer;
167 // Background: background
168 QGraphicsSvgItem *m_txMainBody;
169 QGraphicsSvgItem *m_txLeftStick;
170 QGraphicsSvgItem *m_txRightStick;
171 QGraphicsSvgItem *m_txAccess0;
172 QGraphicsSvgItem *m_txAccess1;
173 QGraphicsSvgItem *m_txAccess2;
174 QGraphicsSvgItem *m_txAccess3;
175 QGraphicsSvgItem *m_txFlightMode;
176 QGraphicsSvgItem *m_txFlightModeCountBG;
177 QGraphicsSimpleTextItem *m_txFlightModeCountText;
178 QGraphicsSvgItem *m_txBackground;
179 QGraphicsSvgItem *m_txArrows;
180 QTransform m_txLeftStickOrig;
181 QTransform m_txRightStickOrig;
182 QTransform m_txAccess0Orig;
183 QTransform m_txAccess1Orig;
184 QTransform m_txAccess2Orig;
185 QTransform m_txAccess3Orig;
186 QTransform m_txFlightModeCOrig;
187 QTransform m_txFlightModeLOrig;
188 QTransform m_txFlightModeROrig;
189 QTransform m_txFlightModeCountBGOrig;
190 QTransform m_txFlightModeCountTextOrig;
191 QTransform m_txMainBodyOrig;
192 QTransform m_txArrowsOrig;
193 QTimer *animate;
194 void resetTxControls();
195 void setMoveFromCommand(int command);
197 void fastMdata();
198 void restoreMdata();
200 void setChannel(int);
201 void nextChannel();
202 void prevChannel();
204 void wizardSetUpStep(enum wizardSteps);
205 void wizardTearDownStep(enum wizardSteps);
207 void registerControlActivity();
209 void wzNextDelayedStart();
210 void wzNextDelayedCancel();
212 AccessoryDesired *getAccessoryDesiredInstance(int instance);
213 float getAccessoryDesiredValue(int instance);
215 void highlightStabilizationMode(int pos);
217 private slots:
218 void wzNext();
219 void wzNextDelayed();
220 void wzBack();
221 void wzCancel();
222 void goToWizard();
223 void disableWizardButton(int);
224 void identifyControls();
225 void identifyLimits();
226 void moveTxControls();
227 void moveSticks();
228 void dimOtherControls(bool value);
229 void moveFMSlider();
230 void updatePositionSlider();
231 void updateConfigAlarmStatus();
232 void invertControls();
233 void simpleCalibration(bool state);
234 void adjustSpecialNeutrals();
235 void checkThrottleRange();
236 void updateCalibration();
237 void resetChannelSettings();
238 void resetFlightModeSettings();
239 void resetActuatorSettings();
240 void updateReceiverActivityStatus();
242 void failsafeFlightModeChanged(int index);
243 void failsafeFlightModeCbToggled(bool checked);
244 void failsafeBatteryWarningFlightModeChanged(int index);
245 void failsafeBatteryWarningFlightModeCbToggled(bool checked);
246 void failsafeBatteryCriticalFlightModeChanged(int index);
247 void failsafeBatteryCriticalFlightModeCbToggled(bool checked);
248 void enableControlsChanged(bool enabled);
250 protected:
251 void resizeEvent(QResizeEvent *event);
252 void buildOptionComboBox(QComboBox *combo, UAVObjectField *field, int index, bool applyLimits);
255 #endif // ifndef CONFIGINPUTWIDGET_H