2011-02-08 16:49:33 +00:00
/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
2011-08-20 19:10:28 +01:00
* @ file configinputwidget . cpp
2011-08-10 15:24:35 +01:00
* @ author The OpenPilot Team , http : //www.openpilot.org Copyright (C) 2010.
2011-02-08 16:49:33 +00:00
* @ addtogroup GCSPlugins GCS Plugins
* @ {
* @ addtogroup ConfigPlugin Config Plugin
* @ {
* @ brief Servo input / output configuration panel for the config gadget
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
* 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
2011-02-27 19:20:43 +00:00
2011-03-28 15:39:22 +00:00
# include "configinputwidget.h"
2011-02-08 16:49:33 +00:00
2013-12-11 22:22:28 +01:00
# include <extensionsystem/pluginmanager.h>
# include <coreplugin/generalsettings.h>
2011-02-27 19:20:43 +00:00
2011-02-08 16:49:33 +00:00
# include <QDebug>
# include <QStringList>
2013-09-15 23:06:25 +02:00
# include <QWidget>
# include <QTextEdit>
# include <QVBoxLayout>
# include <QPushButton>
2011-05-31 00:16:01 -07:00
# include <QDesktopServices>
# include <QUrl>
2011-06-13 12:14:40 +02:00
# include <QMessageBox>
2011-08-16 16:06:18 +01:00
# include <utils/stylehelper.h>
2011-08-20 19:10:28 +01:00
# include <QMessageBox>
2011-02-08 16:49:33 +00:00
2012-01-24 22:29:08 +00:00
# define ACCESS_MIN_MOVE -3
# define ACCESS_MAX_MOVE 3
2013-05-19 17:37:30 +03:00
# define STICK_MIN_MOVE -8
# define STICK_MAX_MOVE 8
2011-06-07 17:35:21 -05:00
2013-05-19 17:37:30 +03:00
ConfigInputWidget : : ConfigInputWidget ( QWidget * parent ) :
2012-10-19 20:30:42 +10:30
ConfigTaskWidget ( parent ) ,
wizardStep ( wizardNone ) ,
// not currently stored in the settings UAVO
2013-05-19 17:37:30 +03:00
transmitterMode ( mode2 ) ,
transmitterType ( acro ) ,
2012-10-19 20:30:42 +10:30
//
loop ( NULL ) ,
2014-08-31 20:57:13 +02:00
skipflag ( false ) ,
2014-08-31 23:24:20 +02:00
nextDelayedTimer ( ) ,
2014-08-31 20:57:13 +02:00
nextDelayedTick ( 0 ) ,
2014-11-09 22:39:05 +01:00
nextDelayedLatestActivityTick ( 0 ) ,
accessoryDesiredObj0 ( NULL ) ,
accessoryDesiredObj1 ( NULL ) ,
accessoryDesiredObj2 ( NULL )
2011-02-08 16:49:33 +00:00
{
2014-02-09 19:33:29 +01:00
manualCommandObj = ManualControlCommand : : GetInstance ( getObjectManager ( ) ) ;
manualSettingsObj = ManualControlSettings : : GetInstance ( getObjectManager ( ) ) ;
flightModeSettingsObj = FlightModeSettings : : GetInstance ( getObjectManager ( ) ) ;
flightStatusObj = FlightStatus : : GetInstance ( getObjectManager ( ) ) ;
receiverActivityObj = ReceiverActivity : : GetInstance ( getObjectManager ( ) ) ;
2014-11-09 22:54:13 +01:00
accessoryDesiredObj0 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 0 ) ;
accessoryDesiredObj1 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 1 ) ;
accessoryDesiredObj2 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 2 ) ;
2014-12-30 09:49:35 +01:00
actuatorSettingsObj = ActuatorSettings : : GetInstance ( getObjectManager ( ) ) ;
2014-11-09 22:54:13 +01:00
// Only instance 0 is present if the board is not connected.
// The other instances are populated lazily.
Q_ASSERT ( accessoryDesiredObj0 ) ;
2013-05-04 00:13:15 +02:00
ui = new Ui_InputWidget ( ) ;
ui - > setupUi ( this ) ;
2011-02-08 16:49:33 +00:00
2015-02-19 22:44:45 +10:00
wizardUi = new Ui_InputWizardWidget ( ) ;
wizardUi - > setupUi ( ui - > wizard ) ;
2013-05-19 17:37:30 +03:00
addApplySaveButtons ( ui - > saveRCInputToRAM , ui - > saveRCInputToSD ) ;
ExtensionSystem : : PluginManager * pm = ExtensionSystem : : PluginManager : : instance ( ) ;
Core : : Internal : : GeneralSettings * settings = pm - > getObject < Core : : Internal : : GeneralSettings > ( ) ;
if ( ! settings - > useExpertMode ( ) ) {
2013-05-04 00:13:15 +02:00
ui - > saveRCInputToRAM - > setVisible ( false ) ;
2013-05-19 17:37:30 +03:00
}
addApplySaveButtons ( ui - > saveRCInputToRAM , ui - > saveRCInputToSD ) ;
2011-08-04 16:58:41 +01:00
2013-05-19 17:37:30 +03:00
// Generate the rows of buttons in the input channel form GUI
unsigned int index = 0 ;
2012-11-17 12:58:16 +02:00
unsigned int indexRT = 0 ;
2013-05-19 17:37:30 +03:00
foreach ( QString name , manualSettingsObj - > getField ( " ChannelNumber " ) - > getElementNames ( ) ) {
2011-09-06 18:26:47 -05:00
Q_ASSERT ( index < ManualControlSettings : : CHANNELGROUPS_NUMELEM ) ;
2014-05-12 22:30:50 +02:00
InputChannelForm * form = new InputChannelForm ( index , this ) ;
2014-05-10 20:40:14 +02:00
form - > setName ( name ) ;
2014-12-26 00:00:08 +01:00
2014-05-12 22:30:50 +02:00
form - > moveTo ( * ( ui - > channelLayout ) ) ;
2014-01-21 00:06:20 +01:00
2014-01-28 19:41:07 +01:00
// The order of the following binding calls is important. Since the values will be populated
2014-01-21 00:06:20 +01:00
// in reverse order of the binding order otherwise the 'Reversed' logic will floor the neutral value
2014-01-28 19:41:07 +01:00
// to the max value ( which is smaller than the neutral value when reversed ) and the channel number
// will not be set correctly.
2014-05-10 20:40:14 +02:00
addWidgetBinding ( " ManualControlSettings " , " ChannelNumber " , form - > ui - > channelNumber , index ) ;
addWidgetBinding ( " ManualControlSettings " , " ChannelGroups " , form - > ui - > channelGroup , index ) ;
2014-12-25 17:49:19 +01:00
// Slider position based on real time Rcinput (allow monitoring)
addWidgetBinding ( " ManualControlCommand " , " Channel " , form - > ui - > channelNeutral , index ) ;
// Neutral value stored on board (SpinBox)
2014-05-10 20:40:14 +02:00
addWidgetBinding ( " ManualControlSettings " , " ChannelNeutral " , form - > ui - > neutralValue , index ) ;
addWidgetBinding ( " ManualControlSettings " , " ChannelMax " , form - > ui - > channelMax , index ) ;
addWidgetBinding ( " ManualControlSettings " , " ChannelMin " , form - > ui - > channelMin , index ) ;
addWidgetBinding ( " ManualControlSettings " , " ChannelMax " , form - > ui - > channelMax , index ) ;
2014-01-21 00:06:20 +01:00
2014-05-10 20:40:14 +02:00
addWidget ( form - > ui - > channelRev ) ;
2012-11-17 12:58:16 +02:00
2014-05-11 17:42:44 +02:00
// Reversing supported for some channels only
bool reversable = ( ( index = = ManualControlSettings : : CHANNELGROUPS_THROTTLE ) | |
2014-05-12 22:30:50 +02:00
( index = = ManualControlSettings : : CHANNELGROUPS_ROLL ) | |
( index = = ManualControlSettings : : CHANNELGROUPS_PITCH ) | |
( index = = ManualControlSettings : : CHANNELGROUPS_YAW ) ) ;
2014-05-11 17:42:44 +02:00
form - > ui - > channelRev - > setVisible ( reversable ) ;
2012-11-17 12:58:16 +02:00
// Input filter response time fields supported for some channels only
switch ( index ) {
case ManualControlSettings : : CHANNELGROUPS_ROLL :
case ManualControlSettings : : CHANNELGROUPS_PITCH :
case ManualControlSettings : : CHANNELGROUPS_YAW :
2014-05-12 22:42:01 +02:00
case ManualControlSettings : : CHANNELGROUPS_COLLECTIVE :
2012-11-17 12:58:16 +02:00
case ManualControlSettings : : CHANNELGROUPS_ACCESSORY0 :
case ManualControlSettings : : CHANNELGROUPS_ACCESSORY1 :
case ManualControlSettings : : CHANNELGROUPS_ACCESSORY2 :
2014-05-10 20:40:14 +02:00
addWidgetBinding ( " ManualControlSettings " , " ResponseTime " , form - > ui - > channelResponseTime , indexRT ) ;
2012-11-17 12:58:16 +02:00
+ + indexRT ;
break ;
2012-12-02 13:50:03 +02:00
case ManualControlSettings : : CHANNELGROUPS_THROTTLE :
2012-11-17 12:58:16 +02:00
case ManualControlSettings : : CHANNELGROUPS_FLIGHTMODE :
2014-05-11 17:32:04 +02:00
form - > ui - > channelResponseTime - > setVisible ( false ) ;
2012-11-17 12:58:16 +02:00
break ;
default :
Q_ASSERT ( 0 ) ;
break ;
}
2011-08-04 16:58:41 +01:00
+ + index ;
}
2011-09-06 17:48:45 -05:00
2014-01-01 22:49:04 +01:00
addWidgetBinding ( " ManualControlSettings " , " Deadband " , ui - > deadband , 0 , 0.01f ) ;
2015-01-08 13:20:47 +11:00
addWidgetBinding ( " ManualControlSettings " , " DeadbandAssistedControl " , ui - > assistedControlDeadband , 0 , 0.01f ) ;
2013-05-04 00:13:15 +02:00
2013-05-19 17:37:30 +03:00
connect ( ui - > configurationWizard , SIGNAL ( clicked ( ) ) , this , SLOT ( goToWizard ( ) ) ) ;
connect ( ui - > stackedWidget , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( disableWizardButton ( int ) ) ) ;
connect ( ui - > runCalibration , SIGNAL ( toggled ( bool ) ) , this , SLOT ( simpleCalibration ( bool ) ) ) ;
2013-05-04 00:13:15 +02:00
2015-02-19 22:44:45 +10:00
connect ( wizardUi - > wzNext , SIGNAL ( clicked ( ) ) , this , SLOT ( wzNext ( ) ) ) ;
connect ( wizardUi - > wzCancel , SIGNAL ( clicked ( ) ) , this , SLOT ( wzCancel ( ) ) ) ;
connect ( wizardUi - > wzBack , SIGNAL ( clicked ( ) ) , this , SLOT ( wzBack ( ) ) ) ;
2013-05-04 00:13:15 +02:00
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
2014-02-09 19:33:29 +01:00
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos1 , 0 , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos2 , 1 , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos3 , 2 , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos4 , 3 , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos5 , 4 , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " FlightModePosition " , ui - > fmsModePos6 , 5 , 1 , true ) ;
2014-01-01 22:49:04 +01:00
addWidgetBinding ( " ManualControlSettings " , " FlightModeNumber " , ui - > fmsPosNum ) ;
2014-02-09 19:33:29 +01:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization1Settings " , ui - > fmsSsPos1Roll , " Roll " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization2Settings " , ui - > fmsSsPos2Roll , " Roll " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization3Settings " , ui - > fmsSsPos3Roll , " Roll " , 1 , true ) ;
2014-05-03 18:38:45 +02:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization4Settings " , ui - > fmsSsPos4Roll , " Roll " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization5Settings " , ui - > fmsSsPos5Roll , " Roll " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization6Settings " , ui - > fmsSsPos6Roll , " Roll " , 1 , true ) ;
2014-02-09 19:33:29 +01:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization1Settings " , ui - > fmsSsPos1Pitch , " Pitch " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization2Settings " , ui - > fmsSsPos2Pitch , " Pitch " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization3Settings " , ui - > fmsSsPos3Pitch , " Pitch " , 1 , true ) ;
2014-05-03 18:38:45 +02:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization4Settings " , ui - > fmsSsPos4Pitch , " Pitch " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization5Settings " , ui - > fmsSsPos5Pitch , " Pitch " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization6Settings " , ui - > fmsSsPos6Pitch , " Pitch " , 1 , true ) ;
2014-02-09 19:33:29 +01:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization1Settings " , ui - > fmsSsPos1Yaw , " Yaw " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization2Settings " , ui - > fmsSsPos2Yaw , " Yaw " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization3Settings " , ui - > fmsSsPos3Yaw , " Yaw " , 1 , true ) ;
2014-05-03 18:38:45 +02:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization4Settings " , ui - > fmsSsPos4Yaw , " Yaw " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization5Settings " , ui - > fmsSsPos5Yaw , " Yaw " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization6Settings " , ui - > fmsSsPos6Yaw , " Yaw " , 1 , true ) ;
2014-04-26 15:14:40 +02:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization1Settings " , ui - > fmsSsPos1Thrust , " Thrust " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization2Settings " , ui - > fmsSsPos2Thrust , " Thrust " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization3Settings " , ui - > fmsSsPos3Thrust , " Thrust " , 1 , true ) ;
2014-05-03 18:38:45 +02:00
addWidgetBinding ( " FlightModeSettings " , " Stabilization4Settings " , ui - > fmsSsPos4Thrust , " Thrust " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization5Settings " , ui - > fmsSsPos5Thrust , " Thrust " , 1 , true ) ;
addWidgetBinding ( " FlightModeSettings " , " Stabilization6Settings " , ui - > fmsSsPos6Thrust , " Thrust " , 1 , true ) ;
2014-02-09 19:33:29 +01:00
addWidgetBinding ( " FlightModeSettings " , " Arming " , ui - > armControl ) ;
addWidgetBinding ( " FlightModeSettings " , " ArmedTimeout " , ui - > armTimeout , 0 , 1000 ) ;
2013-05-19 17:37:30 +03:00
connect ( ManualControlCommand : : GetInstance ( getObjectManager ( ) ) , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveFMSlider ( ) ) ) ;
connect ( ManualControlSettings : : GetInstance ( getObjectManager ( ) ) , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( updatePositionSlider ( ) ) ) ;
2013-05-04 00:13:15 +02:00
addWidget ( ui - > configurationWizard ) ;
addWidget ( ui - > runCalibration ) ;
2011-08-16 16:06:18 +01:00
2014-01-17 01:15:02 +01:00
autoLoadWidgets ( ) ;
2011-08-04 16:58:41 +01:00
populateWidgets ( ) ;
refreshWidgetsValues ( ) ;
2011-05-31 00:16:01 -07:00
// Connect the help button
2013-05-04 00:13:15 +02:00
connect ( ui - > inputHelp , SIGNAL ( clicked ( ) ) , this , SLOT ( openHelp ( ) ) ) ;
2011-08-16 16:06:18 +01:00
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > setScene ( new QGraphicsScene ( this ) ) ;
wizardUi - > graphicsView - > setViewportUpdateMode ( QGraphicsView : : FullViewportUpdate ) ;
2011-08-16 16:06:18 +01:00
m_renderer = new QSvgRenderer ( ) ;
2015-02-19 22:44:45 +10:00
QGraphicsScene * l_scene = wizardUi - > graphicsView - > scene ( ) ;
wizardUi - > graphicsView - > setBackgroundBrush ( QBrush ( Utils : : StyleHelper : : baseColor ( ) ) ) ;
2013-05-19 17:37:30 +03:00
if ( QFile : : exists ( " :/configgadget/images/TX2.svg " ) & & m_renderer - > load ( QString ( " :/configgadget/images/TX2.svg " ) ) & & m_renderer - > isValid ( ) ) {
2011-08-16 16:06:18 +01:00
l_scene - > clear ( ) ; // Deletes all items contained in the scene as well.
m_txBackground = new QGraphicsSvgItem ( ) ;
// All other items will be clipped to the shape of the background
2013-05-19 17:37:30 +03:00
m_txBackground - > setFlags ( QGraphicsItem : : ItemClipsChildrenToShape |
2011-08-16 16:06:18 +01:00
QGraphicsItem : : ItemClipsToShape ) ;
m_txBackground - > setSharedRenderer ( m_renderer ) ;
m_txBackground - > setElementId ( " background " ) ;
l_scene - > addItem ( m_txBackground ) ;
m_txMainBody = new QGraphicsSvgItem ( ) ;
m_txMainBody - > setParentItem ( m_txBackground ) ;
m_txMainBody - > setSharedRenderer ( m_renderer ) ;
m_txMainBody - > setElementId ( " body " ) ;
l_scene - > addItem ( m_txMainBody ) ;
m_txLeftStick = new QGraphicsSvgItem ( ) ;
m_txLeftStick - > setParentItem ( m_txBackground ) ;
m_txLeftStick - > setSharedRenderer ( m_renderer ) ;
m_txLeftStick - > setElementId ( " ljoy " ) ;
m_txRightStick = new QGraphicsSvgItem ( ) ;
m_txRightStick - > setParentItem ( m_txBackground ) ;
m_txRightStick - > setSharedRenderer ( m_renderer ) ;
m_txRightStick - > setElementId ( " rjoy " ) ;
m_txAccess0 = new QGraphicsSvgItem ( ) ;
m_txAccess0 - > setParentItem ( m_txBackground ) ;
m_txAccess0 - > setSharedRenderer ( m_renderer ) ;
m_txAccess0 - > setElementId ( " access0 " ) ;
m_txAccess1 = new QGraphicsSvgItem ( ) ;
m_txAccess1 - > setParentItem ( m_txBackground ) ;
m_txAccess1 - > setSharedRenderer ( m_renderer ) ;
m_txAccess1 - > setElementId ( " access1 " ) ;
m_txAccess2 = new QGraphicsSvgItem ( ) ;
m_txAccess2 - > setParentItem ( m_txBackground ) ;
m_txAccess2 - > setSharedRenderer ( m_renderer ) ;
m_txAccess2 - > setElementId ( " access2 " ) ;
m_txFlightMode = new QGraphicsSvgItem ( ) ;
m_txFlightMode - > setParentItem ( m_txBackground ) ;
m_txFlightMode - > setSharedRenderer ( m_renderer ) ;
m_txFlightMode - > setElementId ( " flightModeCenter " ) ;
m_txFlightMode - > setZValue ( - 10 ) ;
m_txArrows = new QGraphicsSvgItem ( ) ;
m_txArrows - > setParentItem ( m_txBackground ) ;
m_txArrows - > setSharedRenderer ( m_renderer ) ;
m_txArrows - > setElementId ( " arrows " ) ;
m_txArrows - > setVisible ( false ) ;
2013-05-19 17:37:30 +03:00
QRectF orig = m_renderer - > boundsOnElement ( " ljoy " ) ;
2011-08-16 16:06:18 +01:00
QMatrix Matrix = m_renderer - > matrixForElement ( " ljoy " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txLeftStickOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txLeftStick - > setTransform ( m_txLeftStickOrig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " arrows " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " arrows " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txArrowsOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txArrows - > setTransform ( m_txArrowsOrig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " body " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " body " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txMainBodyOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txMainBody - > setTransform ( m_txMainBodyOrig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " flightModeCenter " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txFlightModeCOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " flightModeLeft " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " flightModeLeft " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txFlightModeLOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
orig = m_renderer - > boundsOnElement ( " flightModeRight " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " flightModeRight " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txFlightModeROrig . translate ( orig . x ( ) , orig . y ( ) ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " rjoy " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " rjoy " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txRightStickOrig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txRightStick - > setTransform ( m_txRightStickOrig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " access0 " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " access0 " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txAccess0Orig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txAccess0 - > setTransform ( m_txAccess0Orig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " access1 " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " access1 " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txAccess1Orig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txAccess1 - > setTransform ( m_txAccess1Orig , false ) ;
2011-08-16 16:06:18 +01:00
2013-05-19 17:37:30 +03:00
orig = m_renderer - > boundsOnElement ( " access2 " ) ;
2011-08-16 16:06:18 +01:00
Matrix = m_renderer - > matrixForElement ( " access2 " ) ;
2013-05-19 17:37:30 +03:00
orig = Matrix . mapRect ( orig ) ;
m_txAccess2Orig . translate ( orig . x ( ) , orig . y ( ) ) ;
m_txAccess2 - > setTransform ( m_txAccess2Orig , true ) ;
2011-08-16 16:06:18 +01:00
}
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > fitInView ( m_txMainBody , Qt : : KeepAspectRatio ) ;
2013-05-19 17:37:30 +03:00
animate = new QTimer ( this ) ;
connect ( animate , SIGNAL ( timeout ( ) ) , this , SLOT ( moveTxControls ( ) ) ) ;
2011-09-11 11:14:09 -05:00
heliChannelOrder < < ManualControlSettings : : CHANNELGROUPS_COLLECTIVE < <
2013-05-19 17:37:30 +03:00
ManualControlSettings : : CHANNELGROUPS_THROTTLE < <
ManualControlSettings : : CHANNELGROUPS_ROLL < <
ManualControlSettings : : CHANNELGROUPS_PITCH < <
ManualControlSettings : : CHANNELGROUPS_YAW < <
ManualControlSettings : : CHANNELGROUPS_FLIGHTMODE < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY0 < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY1 < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY2 ;
2011-09-11 11:14:09 -05:00
acroChannelOrder < < ManualControlSettings : : CHANNELGROUPS_THROTTLE < <
2013-05-19 17:37:30 +03:00
ManualControlSettings : : CHANNELGROUPS_ROLL < <
ManualControlSettings : : CHANNELGROUPS_PITCH < <
ManualControlSettings : : CHANNELGROUPS_YAW < <
ManualControlSettings : : CHANNELGROUPS_FLIGHTMODE < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY0 < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY1 < <
ManualControlSettings : : CHANNELGROUPS_ACCESSORY2 ;
2013-05-04 00:13:15 +02:00
updateEnableControls ( ) ;
2011-08-16 16:06:18 +01:00
}
2013-05-04 00:13:15 +02:00
2011-08-16 16:06:18 +01:00
void ConfigInputWidget : : resetTxControls ( )
{
2013-05-19 17:37:30 +03:00
m_txLeftStick - > setTransform ( m_txLeftStickOrig , false ) ;
m_txRightStick - > setTransform ( m_txRightStickOrig , false ) ;
m_txAccess0 - > setTransform ( m_txAccess0Orig , false ) ;
m_txAccess1 - > setTransform ( m_txAccess1Orig , false ) ;
m_txAccess2 - > setTransform ( m_txAccess2Orig , false ) ;
2011-08-16 16:06:18 +01:00
m_txFlightMode - > setElementId ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
2011-08-16 16:06:18 +01:00
m_txArrows - > setVisible ( false ) ;
2011-02-08 16:49:33 +00:00
}
2011-03-28 15:39:22 +00:00
ConfigInputWidget : : ~ ConfigInputWidget ( )
2013-05-19 17:37:30 +03:00
{ }
2011-05-31 00:16:01 -07:00
2013-05-04 00:13:15 +02:00
void ConfigInputWidget : : enableControls ( bool enable )
{
ConfigTaskWidget : : enableControls ( enable ) ;
2013-05-19 17:37:30 +03:00
if ( enable ) {
2013-05-04 00:13:15 +02:00
updatePositionSlider ( ) ;
}
}
2011-08-16 16:06:18 +01:00
void ConfigInputWidget : : resizeEvent ( QResizeEvent * event )
{
QWidget : : resizeEvent ( event ) ;
2013-05-19 17:37:30 +03:00
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > fitInView ( m_txBackground , Qt : : KeepAspectRatio ) ;
2011-08-16 16:06:18 +01:00
}
2011-05-31 00:16:01 -07:00
void ConfigInputWidget : : openHelp ( )
{
2014-05-10 11:56:24 +02:00
QDesktopServices : : openUrl ( QUrl ( tr ( " http://wiki.openpilot.org/x/04Cf " ) , QUrl : : StrictMode ) ) ;
2011-05-31 00:16:01 -07:00
}
2012-10-01 21:50:00 +02:00
2011-08-10 15:24:35 +01:00
void ConfigInputWidget : : goToWizard ( )
{
2011-08-20 19:10:28 +01:00
QMessageBox msgBox ;
2013-05-19 17:37:30 +03:00
2012-10-19 20:30:42 +10:30
msgBox . setText ( tr ( " Arming Settings are now set to 'Always Disarmed' for your safety. " ) ) ;
2012-09-30 17:27:20 +02:00
msgBox . setDetailedText ( tr ( " You will have to reconfigure the arming settings manually "
" when the wizard is finished. After the last step of the "
" wizard you will be taken to the Arming Settings screen. " ) ) ;
2011-08-20 19:10:28 +01:00
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . exec ( ) ;
2012-09-30 14:19:31 +02:00
2012-09-30 14:24:54 +02:00
// Set correct tab visible before starting wizard.
2013-05-19 17:37:30 +03:00
if ( ui - > tabWidget - > currentIndex ( ) ! = 0 ) {
2013-05-04 00:13:15 +02:00
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
2012-09-30 14:24:54 +02:00
}
2013-05-19 17:37:30 +03:00
// Stash current manual settings data in case the wizard is
2012-10-19 20:30:42 +10:30
// cancelled or the user proceeds far enough into the wizard such
// that the UAVO is changed, but then backs out to the start and
// chooses a different TX type (which could otherwise result in
// unexpected TX channels being enabled)
2014-02-09 19:33:29 +01:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
previousManualSettingsData = manualSettingsData ;
flightModeSettingsData = flightModeSettingsObj - > getData ( ) ;
previousFlightModeSettingsData = flightModeSettingsData ;
flightModeSettingsData . Arming = FlightModeSettings : : ARMING_ALWAYSDISARMED ;
flightModeSettingsObj - > setData ( flightModeSettingsData ) ;
2014-12-30 09:49:35 +01:00
// Stash actuatorSettings
actuatorSettingsData = actuatorSettingsObj - > getData ( ) ;
previousActuatorSettingsData = actuatorSettingsData ;
2013-05-19 17:37:30 +03:00
2014-12-30 09:49:35 +01:00
// Now reset channel and actuator settings (disable outputs)
2014-12-29 01:07:11 +01:00
resetChannelSettings ( ) ;
2014-12-30 09:49:35 +01:00
resetActuatorSettings ( ) ;
2014-12-29 01:07:11 +01:00
2014-08-24 21:10:58 +02:00
// Use faster input update rate.
fastMdata ( ) ;
2012-10-19 20:30:42 +10:30
// start the wizard
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardWelcome ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > fitInView ( m_txBackground , Qt : : KeepAspectRatio ) ;
2011-08-10 15:24:35 +01:00
}
2012-09-16 15:14:47 +02:00
void ConfigInputWidget : : disableWizardButton ( int value )
{
2013-05-19 17:37:30 +03:00
if ( value ! = 0 ) {
2013-05-04 00:13:15 +02:00
ui - > groupBox_3 - > setVisible ( false ) ;
2013-05-19 17:37:30 +03:00
} else {
2013-05-04 00:13:15 +02:00
ui - > groupBox_3 - > setVisible ( true ) ;
2013-05-19 17:37:30 +03:00
}
2012-09-16 15:14:47 +02:00
}
2011-08-10 15:24:35 +01:00
void ConfigInputWidget : : wzCancel ( )
{
2011-08-17 12:43:08 +01:00
dimOtherControls ( false ) ;
2014-08-31 15:47:13 +02:00
2014-08-31 20:57:13 +02:00
// Cancel any ongoing delayd next trigger.
wzNextDelayedCancel ( ) ;
2014-08-31 15:47:13 +02:00
// Restore original input update rate.
restoreMdata ( ) ;
2013-05-04 00:13:15 +02:00
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
2011-09-11 11:14:09 -05:00
2013-05-19 17:37:30 +03:00
if ( wizardStep ! = wizardNone ) {
2011-09-11 11:14:09 -05:00
wizardTearDownStep ( wizardStep ) ;
2013-05-19 17:37:30 +03:00
}
wizardStep = wizardNone ;
2013-05-04 00:13:15 +02:00
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
2011-09-11 11:14:09 -05:00
// Load settings back from beginning of wizard
manualSettingsObj - > setData ( previousManualSettingsData ) ;
2014-02-09 19:33:29 +01:00
flightModeSettingsObj - > setData ( previousFlightModeSettingsData ) ;
2014-12-30 09:49:35 +01:00
actuatorSettingsObj - > setData ( previousActuatorSettingsData ) ;
2011-09-11 11:14:09 -05:00
}
2014-08-31 20:57:13 +02:00
void ConfigInputWidget : : registerControlActivity ( )
{
nextDelayedLatestActivityTick = nextDelayedTick ;
}
void ConfigInputWidget : : wzNextDelayed ( )
{
nextDelayedTick + + ;
// Call next after the full 2500 ms timeout has been reached,
// or if no input activity has occurred the last 500 ms.
if ( nextDelayedTick = = 25 | |
nextDelayedTick - nextDelayedLatestActivityTick > = 5 ) {
wzNext ( ) ;
}
}
void ConfigInputWidget : : wzNextDelayedStart ( )
{
// Call wzNextDelayed every 100 ms, to see if it's time to go to the next page.
2014-08-31 23:24:20 +02:00
connect ( & nextDelayedTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( wzNextDelayed ( ) ) ) ;
nextDelayedTimer . start ( 100 ) ;
2014-08-31 20:57:13 +02:00
}
// Cancel the delayed next timer, if it's active.
void ConfigInputWidget : : wzNextDelayedCancel ( )
{
nextDelayedTick = 0 ;
nextDelayedLatestActivityTick = 0 ;
2014-08-31 23:24:20 +02:00
if ( nextDelayedTimer . isActive ( ) ) {
nextDelayedTimer . stop ( ) ;
disconnect ( & nextDelayedTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( wzNextDelayed ( ) ) ) ;
2014-08-31 20:57:13 +02:00
}
}
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : wzNext ( )
{
2014-08-31 20:57:13 +02:00
wzNextDelayedCancel ( ) ;
2011-09-11 11:14:09 -05:00
// In identify sticks mode the next button can indicate
// channel advance
2013-05-19 17:37:30 +03:00
if ( wizardStep ! = wizardNone & &
wizardStep ! = wizardIdentifySticks ) {
2011-09-11 11:14:09 -05:00
wizardTearDownStep ( wizardStep ) ;
2013-05-19 17:37:30 +03:00
}
2011-09-11 11:14:09 -05:00
// State transitions for next button
2013-05-19 17:37:30 +03:00
switch ( wizardStep ) {
2011-08-10 15:24:35 +01:00
case wizardWelcome :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardChooseType ) ;
break ;
2011-09-07 09:09:41 -05:00
case wizardChooseType :
2012-10-19 20:30:42 +10:30
wizardSetUpStep ( wizardChooseMode ) ;
break ;
case wizardChooseMode :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardIdentifySticks ) ;
2011-08-10 15:24:35 +01:00
break ;
case wizardIdentifySticks :
2011-09-11 11:14:09 -05:00
nextChannel ( ) ;
2013-05-19 17:37:30 +03:00
if ( currentChannelNum = = - 1 ) { // Gone through all channels
2011-09-11 11:14:09 -05:00
wizardTearDownStep ( wizardIdentifySticks ) ;
wizardSetUpStep ( wizardIdentifyCenter ) ;
}
2011-08-10 15:24:35 +01:00
break ;
case wizardIdentifyCenter :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardIdentifyLimits ) ;
2011-08-10 15:24:35 +01:00
break ;
case wizardIdentifyLimits :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardIdentifyInverted ) ;
2011-08-10 15:24:35 +01:00
break ;
case wizardIdentifyInverted :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardFinish ) ;
2011-08-10 15:24:35 +01:00
break ;
case wizardFinish :
2013-05-19 17:37:30 +03:00
wizardStep = wizardNone ;
2014-08-24 21:10:58 +02:00
// Restore original input update rate.
restoreMdata ( ) ;
2014-12-30 09:49:35 +01:00
// Load actuator settings back from beginning of wizard
actuatorSettingsObj - > setData ( previousActuatorSettingsData ) ;
2015-02-03 22:13:30 +01:00
// Force flight mode neutral to middle and Throttle neutral at 4%
adjustSpecialNeutrals ( ) ;
2015-03-08 02:20:57 +01:00
throttleError = false ;
checkThrottleRange ( ) ;
2015-02-03 21:50:45 +01:00
2012-10-19 20:30:42 +10:30
manualSettingsObj - > setData ( manualSettingsData ) ;
// move to Arming Settings tab
2013-05-04 00:13:15 +02:00
ui - > stackedWidget - > setCurrentIndex ( 0 ) ;
ui - > tabWidget - > setCurrentIndex ( 2 ) ;
2011-08-10 15:24:35 +01:00
break ;
default :
2011-09-11 11:14:09 -05:00
Q_ASSERT ( 0 ) ;
2011-08-10 15:24:35 +01:00
}
}
void ConfigInputWidget : : wzBack ( )
{
2014-08-31 20:57:13 +02:00
wzNextDelayedCancel ( ) ;
2013-05-19 17:37:30 +03:00
if ( wizardStep ! = wizardNone & &
wizardStep ! = wizardIdentifySticks ) {
2011-09-11 11:14:09 -05:00
wizardTearDownStep ( wizardStep ) ;
2013-05-19 17:37:30 +03:00
}
2011-09-11 11:14:09 -05:00
// State transitions for next button
2013-05-19 17:37:30 +03:00
switch ( wizardStep ) {
2012-10-19 20:30:42 +10:30
case wizardChooseType :
2011-09-11 11:14:09 -05:00
wizardSetUpStep ( wizardWelcome ) ;
break ;
2012-10-19 20:30:42 +10:30
case wizardChooseMode :
wizardSetUpStep ( wizardChooseType ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifySticks :
prevChannel ( ) ;
2013-05-19 17:37:30 +03:00
if ( currentChannelNum = = - 1 ) {
2011-09-11 11:14:09 -05:00
wizardTearDownStep ( wizardIdentifySticks ) ;
2012-10-19 20:30:42 +10:30
wizardSetUpStep ( wizardChooseMode ) ;
2011-09-11 11:14:09 -05:00
}
break ;
case wizardIdentifyCenter :
wizardSetUpStep ( wizardIdentifySticks ) ;
break ;
case wizardIdentifyLimits :
wizardSetUpStep ( wizardIdentifyCenter ) ;
break ;
case wizardIdentifyInverted :
wizardSetUpStep ( wizardIdentifyLimits ) ;
break ;
case wizardFinish :
wizardSetUpStep ( wizardIdentifyInverted ) ;
break ;
default :
Q_ASSERT ( 0 ) ;
}
2011-08-10 15:24:35 +01:00
}
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : wizardSetUpStep ( enum wizardSteps step )
2011-08-10 15:24:35 +01:00
{
2015-02-19 22:44:45 +10:00
wizardUi - > wzNext - > setText ( tr ( " Next " ) ) ;
2013-05-19 17:37:30 +03:00
switch ( step ) {
2011-09-11 11:14:09 -05:00
case wizardWelcome :
2013-05-19 17:37:30 +03:00
foreach ( QPointer < QWidget > wd , extraWidgets ) {
if ( ! wd . isNull ( ) ) {
2012-09-16 15:14:47 +02:00
delete wd ;
2013-05-19 17:37:30 +03:00
}
2012-09-16 15:14:47 +02:00
}
extraWidgets . clear ( ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > setVisible ( false ) ;
2011-08-16 16:06:18 +01:00
setTxMovement ( nothing ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > wzBack - > setEnabled ( false ) ;
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > welcomePage ) ;
2013-05-04 00:13:15 +02:00
ui - > stackedWidget - > setCurrentIndex ( 1 ) ;
2011-09-11 11:14:09 -05:00
break ;
2012-10-19 20:30:42 +10:30
case wizardChooseType :
2011-08-10 15:24:35 +01:00
{
2015-02-19 22:44:45 +10:00
wizardUi - > graphicsView - > setVisible ( true ) ;
wizardUi - > graphicsView - > fitInView ( m_txBackground , Qt : : KeepAspectRatio ) ;
2011-08-16 16:06:18 +01:00
setTxMovement ( nothing ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > wzBack - > setEnabled ( true ) ;
2012-10-19 20:30:42 +10:30
if ( transmitterType = = heli ) {
2015-02-19 22:44:45 +10:00
wizardUi - > typeHeli - > setChecked ( true ) ;
2013-05-19 17:37:30 +03:00
} else {
2015-02-19 22:44:45 +10:00
wizardUi - > typeAcro - > setChecked ( true ) ;
2012-10-19 20:30:42 +10:30
}
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > chooseTypePage ) ;
2011-08-10 15:24:35 +01:00
}
2013-05-19 17:37:30 +03:00
break ;
2012-10-19 20:30:42 +10:30
case wizardChooseMode :
2011-08-10 15:24:35 +01:00
{
2015-02-19 22:44:45 +10:00
wizardUi - > wzBack - > setEnabled ( true ) ;
2015-02-23 00:01:22 +01:00
QRadioButton * modeButtons [ ] = {
2015-02-19 22:44:45 +10:00
wizardUi - > mode1Button ,
wizardUi - > mode2Button ,
wizardUi - > mode3Button ,
wizardUi - > mode4Button
} ;
2012-10-19 20:30:42 +10:30
for ( int i = 0 ; i < = mode4 ; + + i ) {
QString label ;
txMode mode = static_cast < txMode > ( i ) ;
if ( transmitterType = = heli ) {
switch ( mode ) {
2013-05-19 17:37:30 +03:00
case mode1 : label = tr ( " Mode 1: Fore/Aft Cyclic and Yaw on the left, Throttle/Collective and Left/Right Cyclic on the right " ) ; break ;
case mode2 : label = tr ( " Mode 2: Throttle/Collective and Yaw on the left, Cyclic on the right " ) ; break ;
case mode3 : label = tr ( " Mode 3: Cyclic on the left, Throttle/Collective and Yaw on the right " ) ; break ;
case mode4 : label = tr ( " Mode 4: Throttle/Collective and Left/Right Cyclic on the left, Fore/Aft Cyclic and Yaw on the right " ) ; break ;
default : Q_ASSERT ( 0 ) ; break ;
}
2015-02-19 22:44:45 +10:00
wizardUi - > typePageFooter - > setText ( " " ) ;
2013-05-19 17:37:30 +03:00
} else {
2012-10-19 20:30:42 +10:30
switch ( mode ) {
2013-05-19 17:37:30 +03:00
case mode1 : label = tr ( " Mode 1: Elevator and Rudder on the left, Throttle and Ailerons on the right " ) ; break ;
case mode2 : label = tr ( " Mode 2: Throttle and Rudder on the left, Elevator and Ailerons on the right " ) ; break ;
case mode3 : label = tr ( " Mode 3: Elevator and Ailerons on the left, Throttle and Rudder on the right " ) ; break ;
case mode4 : label = tr ( " Mode 4: Throttle and Ailerons on the left, Elevator and Rudder on the right " ) ; break ;
default : Q_ASSERT ( 0 ) ; break ;
}
2015-02-19 22:44:45 +10:00
wizardUi - > typePageFooter - > setText ( tr ( " For a Quad: Elevator is Pitch, Ailerons are Roll, and Rudder is Yaw. " ) ) ;
2012-10-19 20:30:42 +10:30
}
2015-02-19 22:44:45 +10:00
modeButtons [ i ] - > setText ( label ) ;
2012-10-19 20:30:42 +10:30
if ( transmitterMode = = mode ) {
2015-02-19 22:44:45 +10:00
modeButtons [ i ] - > setChecked ( true ) ;
2012-10-19 20:30:42 +10:30
}
}
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > chooseModePage ) ;
2011-09-11 11:14:09 -05:00
}
2013-05-19 17:37:30 +03:00
break ;
2011-09-11 11:14:09 -05:00
case wizardIdentifySticks :
2011-09-07 09:09:41 -05:00
usedChannels . clear ( ) ;
2013-05-19 17:37:30 +03:00
currentChannelNum = - 1 ;
2011-09-11 11:14:09 -05:00
nextChannel ( ) ;
2013-05-19 17:37:30 +03:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
connect ( receiverActivityObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( identifyControls ( ) ) ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > wzNext - > setEnabled ( false ) ;
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > identifySticksPage ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifyCenter :
2011-08-16 16:06:18 +01:00
setTxMovement ( centerAll ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > identifyCenterPage ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifyLimits :
2011-08-10 15:24:35 +01:00
{
2011-10-26 22:04:24 -05:00
setTxMovement ( nothing ) ;
2014-08-31 15:51:19 +02:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
2013-05-19 17:37:30 +03:00
for ( uint i = 0 ; i < ManualControlSettings : : CHANNELMAX_NUMELEM ; + + i ) {
2011-11-25 12:30:17 -06:00
// Preserve the inverted status
2013-05-19 17:37:30 +03:00
if ( manualSettingsData . ChannelMin [ i ] < = manualSettingsData . ChannelMax [ i ] ) {
manualSettingsData . ChannelMin [ i ] = manualSettingsData . ChannelNeutral [ i ] ;
manualSettingsData . ChannelMax [ i ] = manualSettingsData . ChannelNeutral [ i ] ;
2011-11-25 12:30:17 -06:00
} else {
// Make this detect as still inverted
2013-05-19 17:37:30 +03:00
manualSettingsData . ChannelMin [ i ] = manualSettingsData . ChannelNeutral [ i ] + 1 ;
manualSettingsData . ChannelMax [ i ] = manualSettingsData . ChannelNeutral [ i ] ;
2011-11-25 12:30:17 -06:00
}
2011-08-10 15:24:35 +01:00
}
2013-05-19 17:37:30 +03:00
connect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( identifyLimits ( ) ) ) ;
connect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
connect ( flightStatusObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
connect ( accessoryDesiredObj0 , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > identifyLimitsPage ) ;
2011-08-10 15:24:35 +01:00
}
2013-05-19 17:37:30 +03:00
break ;
2011-09-11 11:14:09 -05:00
case wizardIdentifyInverted :
2011-08-17 12:43:08 +01:00
dimOtherControls ( true ) ;
2011-08-16 16:06:18 +01:00
setTxMovement ( nothing ) ;
2011-08-10 15:24:35 +01:00
extraWidgets . clear ( ) ;
2013-05-19 17:37:30 +03:00
for ( int index = 0 ; index < manualSettingsObj - > getField ( " ChannelMax " ) - > getElementNames ( ) . length ( ) ; index + + ) {
2011-11-25 12:30:17 -06:00
QString name = manualSettingsObj - > getField ( " ChannelMax " ) - > getElementNames ( ) . at ( index ) ;
2013-05-19 17:37:30 +03:00
if ( ! name . contains ( " Access " ) & & ! name . contains ( " Flight " ) & &
( ! name . contains ( " Collective " ) | | transmitterType = = heli ) ) {
QCheckBox * cb = new QCheckBox ( name , this ) ;
2011-11-25 12:30:17 -06:00
// Make sure checked status matches current one
cb - > setChecked ( manualSettingsData . ChannelMax [ index ] < manualSettingsData . ChannelMin [ index ] ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > checkBoxesLayout - > addWidget ( cb , extraWidgets . size ( ) / 4 , extraWidgets . size ( ) % 4 ) ;
2011-08-16 16:06:18 +01:00
extraWidgets . append ( cb ) ;
2013-05-19 17:37:30 +03:00
connect ( cb , SIGNAL ( toggled ( bool ) ) , this , SLOT ( invertControls ( ) ) ) ;
2011-08-16 16:06:18 +01:00
}
2011-08-10 15:24:35 +01:00
}
2013-05-19 17:37:30 +03:00
connect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > identifyInvertedPage ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardFinish :
2012-09-16 15:14:47 +02:00
dimOtherControls ( false ) ;
2013-05-19 17:37:30 +03:00
connect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
connect ( flightStatusObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
connect ( accessoryDesiredObj0 , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > pagesStack - > setCurrentWidget ( wizardUi - > finishPage ) ;
2011-09-11 11:14:09 -05:00
break ;
default :
Q_ASSERT ( 0 ) ;
}
wizardStep = step ;
}
void ConfigInputWidget : : wizardTearDownStep ( enum wizardSteps step )
{
Q_ASSERT ( step = = wizardStep ) ;
2013-05-19 17:37:30 +03:00
switch ( step ) {
2011-09-11 11:14:09 -05:00
case wizardWelcome :
break ;
2013-05-19 17:37:30 +03:00
case wizardChooseType :
2015-02-19 22:44:45 +10:00
if ( wizardUi - > typeAcro - > isChecked ( ) ) {
2013-05-19 17:37:30 +03:00
transmitterType = acro ;
} else {
transmitterType = heli ;
}
2011-09-11 11:14:09 -05:00
break ;
2013-05-19 17:37:30 +03:00
case wizardChooseMode :
2015-02-23 00:01:22 +01:00
{
QRadioButton * modeButtons [ ] = {
wizardUi - > mode1Button ,
wizardUi - > mode2Button ,
wizardUi - > mode3Button ,
wizardUi - > mode4Button
} ;
for ( int i = mode1 ; i < = mode4 ; + + i ) {
if ( modeButtons [ i ] - > isChecked ( ) ) {
transmitterMode = static_cast < txMode > ( i ) ;
2012-10-19 20:30:42 +10:30
}
}
2015-02-23 00:01:22 +01:00
}
break ;
2011-09-11 11:14:09 -05:00
case wizardIdentifySticks :
2013-05-19 17:37:30 +03:00
disconnect ( receiverActivityObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( identifyControls ( ) ) ) ;
2015-02-19 22:44:45 +10:00
wizardUi - > wzNext - > setEnabled ( true ) ;
2011-11-25 11:23:56 -06:00
setTxMovement ( nothing ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifyCenter :
2013-05-19 17:37:30 +03:00
manualCommandData = manualCommandObj - > getData ( ) ;
manualSettingsData = manualSettingsObj - > getData ( ) ;
for ( unsigned int i = 0 ; i < ManualControlCommand : : CHANNEL_NUMELEM ; + + i ) {
manualSettingsData . ChannelNeutral [ i ] = manualCommandData . Channel [ i ] ;
2011-09-11 11:14:09 -05:00
}
manualSettingsObj - > setData ( manualSettingsData ) ;
2011-11-25 11:23:56 -06:00
setTxMovement ( nothing ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifyLimits :
2013-05-19 17:37:30 +03:00
disconnect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( identifyLimits ( ) ) ) ;
disconnect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
disconnect ( flightStatusObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
disconnect ( accessoryDesiredObj0 , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2011-09-11 11:14:09 -05:00
manualSettingsObj - > setData ( manualSettingsData ) ;
2011-11-25 11:23:56 -06:00
setTxMovement ( nothing ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardIdentifyInverted :
2011-11-25 11:23:56 -06:00
dimOtherControls ( false ) ;
2013-05-19 17:37:30 +03:00
foreach ( QWidget * wd , extraWidgets ) {
QCheckBox * cb = qobject_cast < QCheckBox * > ( wd ) ;
if ( cb ) {
disconnect ( cb , SIGNAL ( toggled ( bool ) ) , this , SLOT ( invertControls ( ) ) ) ;
2011-09-11 11:14:09 -05:00
delete cb ;
}
}
extraWidgets . clear ( ) ;
2013-05-19 17:37:30 +03:00
disconnect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2011-09-11 11:14:09 -05:00
break ;
case wizardFinish :
2011-11-25 11:23:56 -06:00
dimOtherControls ( false ) ;
2011-09-11 11:14:09 -05:00
setTxMovement ( nothing ) ;
2013-05-19 17:37:30 +03:00
disconnect ( manualCommandObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
disconnect ( flightStatusObj , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
disconnect ( accessoryDesiredObj0 , SIGNAL ( objectUpdated ( UAVObject * ) ) , this , SLOT ( moveSticks ( ) ) ) ;
2011-09-11 11:14:09 -05:00
break ;
default :
Q_ASSERT ( 0 ) ;
2011-08-10 15:24:35 +01:00
}
2011-09-11 11:14:09 -05:00
}
2011-08-10 15:24:35 +01:00
2014-08-31 15:51:19 +02:00
static void fastMdataSingle ( UAVDataObject * object , UAVObject : : Metadata * savedMdata )
{
* savedMdata = object - > getMetadata ( ) ;
UAVObject : : Metadata mdata = * savedMdata ;
UAVObject : : SetFlightTelemetryUpdateMode ( mdata , UAVObject : : UPDATEMODE_PERIODIC ) ;
mdata . flightTelemetryUpdatePeriod = 150 ;
object - > setMetadata ( mdata ) ;
}
static void restoreMdataSingle ( UAVDataObject * object , UAVObject : : Metadata * savedMdata )
{
object - > setMetadata ( * savedMdata ) ;
}
2011-09-11 11:14:09 -05:00
/**
2013-05-19 17:37:30 +03:00
* Set manual control command to fast updates
*/
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : fastMdata ( )
{
2014-08-31 15:51:19 +02:00
fastMdataSingle ( manualCommandObj , & manualControlMdata ) ;
fastMdataSingle ( accessoryDesiredObj0 , & accessoryDesiredMdata0 ) ;
2011-08-10 15:24:35 +01:00
}
2011-09-07 09:09:41 -05:00
/**
2013-05-19 17:37:30 +03:00
* Restore previous update settings for manual control data
*/
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : restoreMdata ( )
2011-09-07 09:09:41 -05:00
{
2014-08-31 15:51:19 +02:00
restoreMdataSingle ( manualCommandObj , & manualControlMdata ) ;
restoreMdataSingle ( accessoryDesiredObj0 , & accessoryDesiredMdata0 ) ;
2011-09-11 11:14:09 -05:00
}
/**
2013-05-19 17:37:30 +03:00
* Set the display to indicate which channel the person should move
*/
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : setChannel ( int newChan )
{
2013-05-19 17:37:30 +03:00
if ( newChan = = ManualControlSettings : : CHANNELGROUPS_COLLECTIVE ) {
2015-02-19 22:44:45 +10:00
wizardUi - > identifyStickInstructions - > setText ( QString ( tr ( " Please enable throttle hold mode. \n \n Move the Collective Pitch stick. " ) ) ) ;
2013-05-19 17:37:30 +03:00
} else if ( newChan = = ManualControlSettings : : CHANNELGROUPS_FLIGHTMODE ) {
2015-02-19 22:44:45 +10:00
wizardUi - > identifyStickInstructions - > setText ( QString ( tr ( " Please toggle the Flight Mode switch. \n \n For switches you may have to repeat this rapidly. " ) ) ) ;
2013-05-19 17:37:30 +03:00
} else if ( ( transmitterType = = heli ) & & ( newChan = = ManualControlSettings : : CHANNELGROUPS_THROTTLE ) ) {
2015-02-19 22:44:45 +10:00
wizardUi - > identifyStickInstructions - > setText ( QString ( tr ( " Please disable throttle hold mode. \n \n Move the Throttle stick. " ) ) ) ;
2013-05-19 17:37:30 +03:00
} else {
2015-02-19 22:44:45 +10:00
wizardUi - > identifyStickInstructions - > setText ( QString ( tr ( " Please move each control one at a time according to the instructions and picture below. \n \n "
2015-02-23 00:01:22 +01:00
" Move the %1 stick. " ) ) . arg ( manualSettingsObj - > getField ( " ChannelGroups " ) - > getElementNames ( ) . at ( newChan ) ) ) ;
2013-05-19 17:37:30 +03:00
}
2011-09-11 11:14:09 -05:00
2014-11-22 11:04:20 +11:00
if ( manualSettingsObj - > getField ( " ChannelGroups " ) - > getElementNames ( ) . at ( newChan ) . contains ( " Accessory " ) ) {
2015-02-19 22:44:45 +10:00
wizardUi - > wzNext - > setEnabled ( true ) ;
wizardUi - > wzNext - > setText ( tr ( " Next / Skip " ) ) ;
wizardUi - > identifyStickInstructions - > setText ( wizardUi - > identifyStickInstructions - > text ( ) + tr ( " Alternatively, click Next to skip this channel. " ) ) ;
2013-05-19 17:37:30 +03:00
} else {
2015-02-19 22:44:45 +10:00
wizardUi - > wzNext - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
}
2011-09-11 11:14:09 -05:00
setMoveFromCommand ( newChan ) ;
currentChannelNum = newChan ;
2013-05-19 17:37:30 +03:00
channelDetected = false ;
2011-09-11 11:14:09 -05:00
}
/**
2013-05-19 17:37:30 +03:00
* Unfortunately order of channel should be different in different conditions . Selects
* next channel based on heli or acro mode
*/
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : nextChannel ( )
{
QList < int > order = ( transmitterType = = heli ) ? heliChannelOrder : acroChannelOrder ;
2011-09-07 09:09:41 -05:00
2013-05-19 17:37:30 +03:00
if ( currentChannelNum = = - 1 ) {
2011-09-11 11:14:09 -05:00
setChannel ( order [ 0 ] ) ;
return ;
}
for ( int i = 0 ; i < order . length ( ) - 1 ; i + + ) {
2013-05-19 17:37:30 +03:00
if ( order [ i ] = = currentChannelNum ) {
setChannel ( order [ i + 1 ] ) ;
2011-09-11 11:14:09 -05:00
return ;
}
}
currentChannelNum = - 1 ; // hit end of list
}
/**
2013-05-19 17:37:30 +03:00
* Unfortunately order of channel should be different in different conditions . Selects
* previous channel based on heli or acro mode
*/
2011-09-11 11:14:09 -05:00
void ConfigInputWidget : : prevChannel ( )
{
QList < int > order = transmitterType = = heli ? heliChannelOrder : acroChannelOrder ;
// No previous from unset channel or next state
2013-05-19 17:37:30 +03:00
if ( currentChannelNum = = - 1 ) {
2011-09-11 11:14:09 -05:00
return ;
2013-05-19 17:37:30 +03:00
}
2011-09-11 11:14:09 -05:00
for ( int i = 1 ; i < order . length ( ) ; i + + ) {
2013-05-19 17:37:30 +03:00
if ( order [ i ] = = currentChannelNum ) {
if ( ! usedChannels . isEmpty ( ) & &
2014-09-02 18:53:02 +02:00
usedChannels . back ( ) . channelIndex = = order [ i - 1 ] ) {
2012-10-19 20:30:42 +10:30
usedChannels . removeLast ( ) ;
}
2013-05-19 17:37:30 +03:00
setChannel ( order [ i - 1 ] ) ;
2011-09-11 11:14:09 -05:00
return ;
}
}
currentChannelNum = - 1 ; // hit end of list
2011-09-07 09:09:41 -05:00
}
2011-08-10 15:24:35 +01:00
void ConfigInputWidget : : identifyControls ( )
{
2014-08-31 18:25:15 +02:00
static const int DEBOUNCE_COUNT = 4 ;
2013-05-19 17:37:30 +03:00
static int debounce = 0 ;
2011-09-07 09:09:41 -05:00
2013-05-19 17:37:30 +03:00
receiverActivityData = receiverActivityObj - > getData ( ) ;
2014-08-31 18:25:15 +02:00
2013-05-19 17:37:30 +03:00
if ( receiverActivityData . ActiveChannel = = 255 ) {
2011-08-10 15:24:35 +01:00
return ;
2013-05-19 17:37:30 +03:00
}
2014-08-31 18:25:15 +02:00
2013-05-19 17:37:30 +03:00
if ( channelDetected ) {
2014-08-31 20:57:13 +02:00
registerControlActivity ( ) ;
2011-10-20 08:26:46 -05:00
return ;
2014-08-31 18:25:15 +02:00
}
receiverActivityData = receiverActivityObj - > getData ( ) ;
currentChannel . group = receiverActivityData . ActiveGroup ;
currentChannel . number = receiverActivityData . ActiveChannel ;
if ( debounce = = 0 ) {
// Register a channel to be debounced.
2013-05-19 17:37:30 +03:00
lastChannel . group = currentChannel . group ;
lastChannel . number = currentChannel . number ;
lastChannel . channelIndex = currentChannelNum ;
2014-08-31 18:25:15 +02:00
+ + debounce ;
return ;
2011-08-10 15:24:35 +01:00
}
2011-09-11 11:14:09 -05:00
2014-08-31 18:25:15 +02:00
if ( currentChannel ! = lastChannel ) {
// A new channel was seen. Only register it if we count down to 0.
- - debounce ;
return ;
}
if ( debounce < DEBOUNCE_COUNT ) {
// We still haven't seen enough enough activity on this channel yet.
+ + debounce ;
return ;
}
// Channel has been debounced and it's enough record it.
if ( usedChannels . contains ( lastChannel ) ) {
// Channel is already recorded.
return ;
}
// Record the channel.
channelDetected = true ;
debounce = 0 ;
usedChannels . append ( lastChannel ) ;
manualSettingsData = manualSettingsObj - > getData ( ) ;
manualSettingsData . ChannelGroups [ currentChannelNum ] = currentChannel . group ;
manualSettingsData . ChannelNumber [ currentChannelNum ] = currentChannel . number ;
manualSettingsObj - > setData ( manualSettingsData ) ;
2013-05-19 17:37:30 +03:00
// m_config->wzText->clear();
2011-09-11 11:14:09 -05:00
setTxMovement ( nothing ) ;
2014-08-31 20:57:13 +02:00
wzNextDelayedStart ( ) ;
2011-08-10 15:24:35 +01:00
}
void ConfigInputWidget : : identifyLimits ( )
{
2013-05-19 17:37:30 +03:00
manualCommandData = manualCommandObj - > getData ( ) ;
for ( uint i = 0 ; i < ManualControlSettings : : CHANNELMAX_NUMELEM ; + + i ) {
if ( manualSettingsData . ChannelMin [ i ] < = manualSettingsData . ChannelMax [ i ] ) {
2011-11-25 12:30:17 -06:00
// Non inverted channel
2013-05-19 17:37:30 +03:00
if ( manualSettingsData . ChannelMin [ i ] > manualCommandData . Channel [ i ] ) {
manualSettingsData . ChannelMin [ i ] = manualCommandData . Channel [ i ] ;
}
if ( manualSettingsData . ChannelMax [ i ] < manualCommandData . Channel [ i ] ) {
manualSettingsData . ChannelMax [ i ] = manualCommandData . Channel [ i ] ;
}
2011-11-25 12:30:17 -06:00
} else {
// Inverted channel
2013-05-19 17:37:30 +03:00
if ( manualSettingsData . ChannelMax [ i ] > manualCommandData . Channel [ i ] ) {
manualSettingsData . ChannelMax [ i ] = manualCommandData . Channel [ i ] ;
}
if ( manualSettingsData . ChannelMin [ i ] < manualCommandData . Channel [ i ] ) {
manualSettingsData . ChannelMin [ i ] = manualCommandData . Channel [ i ] ;
}
2011-11-25 12:30:17 -06:00
}
2011-08-10 15:24:35 +01:00
}
2011-10-26 22:04:24 -05:00
manualSettingsObj - > setData ( manualSettingsData ) ;
2011-08-10 15:24:35 +01:00
}
2011-08-16 16:06:18 +01:00
void ConfigInputWidget : : setMoveFromCommand ( int command )
{
2012-10-19 20:30:42 +10:30
// ManualControlSettings::ChannelNumberElem:
2013-05-19 17:37:30 +03:00
// CHANNELNUMBER_ROLL=0,
// CHANNELNUMBER_PITCH=1,
// CHANNELNUMBER_YAW=2,
// CHANNELNUMBER_THROTTLE=3,
// CHANNELNUMBER_FLIGHTMODE=4,
// CHANNELNUMBER_ACCESSORY0=5,
// CHANNELNUMBER_ACCESSORY1=6,
// CHANNELNUMBER_ACCESSORY2=7
2014-03-04 23:45:01 +01:00
txMovements movement = moveLeftVerticalStick ;
2013-05-19 17:37:30 +03:00
2012-10-19 20:30:42 +10:30
switch ( command ) {
2013-05-19 17:37:30 +03:00
case ManualControlSettings : : CHANNELNUMBER_ROLL :
movement = ( ( transmitterMode = = mode3 | | transmitterMode = = mode4 ) ?
moveLeftHorizontalStick : moveRightHorizontalStick ) ;
break ;
case ManualControlSettings : : CHANNELNUMBER_PITCH :
movement = ( transmitterMode = = mode1 | | transmitterMode = = mode3 ) ?
moveLeftVerticalStick : moveRightVerticalStick ;
break ;
case ManualControlSettings : : CHANNELNUMBER_YAW :
movement = ( ( transmitterMode = = mode1 | | transmitterMode = = mode2 ) ?
moveLeftHorizontalStick : moveRightHorizontalStick ) ;
break ;
case ManualControlSettings : : CHANNELNUMBER_THROTTLE :
movement = ( transmitterMode = = mode2 | | transmitterMode = = mode4 ) ?
moveLeftVerticalStick : moveRightVerticalStick ;
break ;
case ManualControlSettings : : CHANNELNUMBER_COLLECTIVE :
movement = ( transmitterMode = = mode2 | | transmitterMode = = mode4 ) ?
moveLeftVerticalStick : moveRightVerticalStick ;
break ;
case ManualControlSettings : : CHANNELNUMBER_FLIGHTMODE :
movement = moveFlightMode ;
break ;
case ManualControlSettings : : CHANNELNUMBER_ACCESSORY0 :
movement = moveAccess0 ;
break ;
case ManualControlSettings : : CHANNELNUMBER_ACCESSORY1 :
movement = moveAccess1 ;
break ;
case ManualControlSettings : : CHANNELNUMBER_ACCESSORY2 :
movement = moveAccess2 ;
break ;
default :
Q_ASSERT ( 0 ) ;
break ;
}
2012-10-19 20:30:42 +10:30
setTxMovement ( movement ) ;
2011-08-16 16:06:18 +01:00
}
void ConfigInputWidget : : setTxMovement ( txMovements movement )
{
resetTxControls ( ) ;
2013-05-19 17:37:30 +03:00
switch ( movement ) {
2011-08-16 16:06:18 +01:00
case moveLeftVerticalStick :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveLeftVerticalStick ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveRightVerticalStick :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveRightVerticalStick ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveLeftHorizontalStick :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveLeftHorizontalStick ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveRightHorizontalStick :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveRightHorizontalStick ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveAccess0 :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveAccess0 ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveAccess1 :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveAccess1 ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveAccess2 :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveAccess2 ;
2011-08-16 16:06:18 +01:00
animate - > start ( 100 ) ;
break ;
case moveFlightMode :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveFlightMode ;
2011-08-16 16:06:18 +01:00
animate - > start ( 1000 ) ;
break ;
case centerAll :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
currentMovement = centerAll ;
2011-08-16 16:06:18 +01:00
animate - > start ( 1000 ) ;
break ;
case moveAll :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
growing = true ;
currentMovement = moveAll ;
2011-08-16 16:06:18 +01:00
animate - > start ( 50 ) ;
break ;
case nothing :
2013-05-19 17:37:30 +03:00
movePos = 0 ;
2011-08-16 16:06:18 +01:00
animate - > stop ( ) ;
break ;
default :
2012-10-19 20:30:42 +10:30
Q_ASSERT ( 0 ) ;
2011-08-16 16:06:18 +01:00
break ;
}
}
void ConfigInputWidget : : moveTxControls ( )
{
QTransform trans ;
2014-03-04 23:45:01 +01:00
QGraphicsItem * item = NULL ;
txMovementType move = vertical ;
int limitMax = 0 ;
int limitMin = 0 ;
2013-05-19 17:37:30 +03:00
static bool auxFlag = false ;
switch ( currentMovement ) {
2011-08-16 16:06:18 +01:00
case moveLeftVerticalStick :
2013-05-19 17:37:30 +03:00
item = m_txLeftStick ;
trans = m_txLeftStickOrig ;
limitMax = STICK_MAX_MOVE ;
limitMin = STICK_MIN_MOVE ;
move = vertical ;
2011-08-16 16:06:18 +01:00
break ;
case moveRightVerticalStick :
2013-05-19 17:37:30 +03:00
item = m_txRightStick ;
trans = m_txRightStickOrig ;
limitMax = STICK_MAX_MOVE ;
limitMin = STICK_MIN_MOVE ;
move = vertical ;
2011-08-16 16:06:18 +01:00
break ;
case moveLeftHorizontalStick :
2013-05-19 17:37:30 +03:00
item = m_txLeftStick ;
trans = m_txLeftStickOrig ;
limitMax = STICK_MAX_MOVE ;
limitMin = STICK_MIN_MOVE ;
move = horizontal ;
2011-08-16 16:06:18 +01:00
break ;
case moveRightHorizontalStick :
2013-05-19 17:37:30 +03:00
item = m_txRightStick ;
trans = m_txRightStickOrig ;
limitMax = STICK_MAX_MOVE ;
limitMin = STICK_MIN_MOVE ;
move = horizontal ;
2011-08-16 16:06:18 +01:00
break ;
case moveAccess0 :
2013-05-19 17:37:30 +03:00
item = m_txAccess0 ;
trans = m_txAccess0Orig ;
limitMax = ACCESS_MAX_MOVE ;
limitMin = ACCESS_MIN_MOVE ;
move = horizontal ;
2011-08-16 16:06:18 +01:00
break ;
case moveAccess1 :
2013-05-19 17:37:30 +03:00
item = m_txAccess1 ;
trans = m_txAccess1Orig ;
limitMax = ACCESS_MAX_MOVE ;
limitMin = ACCESS_MIN_MOVE ;
move = horizontal ;
2011-08-16 16:06:18 +01:00
break ;
case moveAccess2 :
2013-05-19 17:37:30 +03:00
item = m_txAccess2 ;
trans = m_txAccess2Orig ;
limitMax = ACCESS_MAX_MOVE ;
limitMin = ACCESS_MIN_MOVE ;
move = horizontal ;
2011-08-16 16:06:18 +01:00
break ;
case moveFlightMode :
2013-05-19 17:37:30 +03:00
item = m_txFlightMode ;
move = jump ;
2011-08-16 16:06:18 +01:00
break ;
case centerAll :
2013-05-19 17:37:30 +03:00
item = m_txArrows ;
move = jump ;
2011-08-16 16:06:18 +01:00
break ;
case moveAll :
2013-05-19 17:37:30 +03:00
limitMax = STICK_MAX_MOVE ;
limitMin = STICK_MIN_MOVE ;
move = mix ;
2011-08-16 16:06:18 +01:00
break ;
default :
break ;
}
2013-05-19 17:37:30 +03:00
if ( move = = vertical ) {
item - > setTransform ( trans . translate ( 0 , movePos * 10 ) , false ) ;
} else if ( move = = horizontal ) {
item - > setTransform ( trans . translate ( movePos * 10 , 0 ) , false ) ;
} else if ( move = = jump ) {
if ( item = = m_txArrows ) {
2011-08-16 16:06:18 +01:00
m_txArrows - > setVisible ( ! m_txArrows - > isVisible ( ) ) ;
2013-05-19 17:37:30 +03:00
} else if ( item = = m_txFlightMode ) {
QGraphicsSvgItem * svg ;
svg = ( QGraphicsSvgItem * ) item ;
if ( svg ) {
if ( svg - > elementId ( ) = = " flightModeCenter " ) {
if ( growing ) {
2011-08-16 16:06:18 +01:00
svg - > setElementId ( " flightModeRight " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeROrig , false ) ;
} else {
2011-08-16 16:06:18 +01:00
svg - > setElementId ( " flightModeLeft " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeLOrig , false ) ;
2011-08-16 16:06:18 +01:00
}
2013-05-19 17:37:30 +03:00
} else if ( svg - > elementId ( ) = = " flightModeRight " ) {
growing = false ;
2011-08-16 16:06:18 +01:00
svg - > setElementId ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
} else if ( svg - > elementId ( ) = = " flightModeLeft " ) {
growing = true ;
2011-08-16 16:06:18 +01:00
svg - > setElementId ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
2011-08-16 16:06:18 +01:00
}
}
}
2013-05-19 17:37:30 +03:00
} else if ( move = = mix ) {
trans = m_txAccess0Orig ;
m_txAccess0 - > setTransform ( trans . translate ( movePos * 10 * ACCESS_MAX_MOVE / STICK_MAX_MOVE , 0 ) , false ) ;
trans = m_txAccess1Orig ;
m_txAccess1 - > setTransform ( trans . translate ( movePos * 10 * ACCESS_MAX_MOVE / STICK_MAX_MOVE , 0 ) , false ) ;
trans = m_txAccess2Orig ;
m_txAccess2 - > setTransform ( trans . translate ( movePos * 10 * ACCESS_MAX_MOVE / STICK_MAX_MOVE , 0 ) , false ) ;
if ( auxFlag ) {
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( 0 , movePos * 10 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( 0 , movePos * 10 ) , false ) ;
} else {
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( movePos * 10 , 0 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( movePos * 10 , 0 ) , false ) ;
2011-08-16 16:06:18 +01:00
}
2013-05-19 17:37:30 +03:00
if ( movePos = = 0 ) {
2011-08-16 16:06:18 +01:00
m_txFlightMode - > setElementId ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
} else if ( movePos = = ACCESS_MAX_MOVE / 2 ) {
2011-08-16 16:06:18 +01:00
m_txFlightMode - > setElementId ( " flightModeRight " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeROrig , false ) ;
} else if ( movePos = = ACCESS_MIN_MOVE / 2 ) {
2011-08-16 16:06:18 +01:00
m_txFlightMode - > setElementId ( " flightModeLeft " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeLOrig , false ) ;
2011-08-16 16:06:18 +01:00
}
}
2013-05-19 17:37:30 +03:00
if ( move = = horizontal | | move = = vertical | | move = = mix ) {
if ( movePos = = 0 & & growing ) {
auxFlag = ! auxFlag ;
}
if ( growing ) {
2011-08-16 16:06:18 +01:00
+ + movePos ;
2013-05-19 17:37:30 +03:00
} else {
2011-08-16 16:06:18 +01:00
- - movePos ;
}
2013-05-19 17:37:30 +03:00
if ( movePos > limitMax ) {
movePos = movePos - 2 ;
growing = false ;
}
if ( movePos < limitMin ) {
movePos = movePos + 2 ;
growing = true ;
2011-08-16 16:06:18 +01:00
}
}
}
2014-11-09 22:39:05 +01:00
AccessoryDesired * ConfigInputWidget : : getAccessoryDesiredInstance ( int instance )
{
switch ( instance ) {
case 0 :
if ( accessoryDesiredObj0 = = NULL ) {
accessoryDesiredObj0 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 0 ) ;
}
return accessoryDesiredObj0 ;
case 1 :
if ( accessoryDesiredObj1 = = NULL ) {
accessoryDesiredObj1 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 1 ) ;
}
return accessoryDesiredObj1 ;
case 2 :
if ( accessoryDesiredObj2 = = NULL ) {
accessoryDesiredObj2 = AccessoryDesired : : GetInstance ( getObjectManager ( ) , 2 ) ;
}
return accessoryDesiredObj2 ;
default :
Q_ASSERT ( false ) ;
}
return NULL ;
}
float ConfigInputWidget : : getAccessoryDesiredValue ( int instance )
{
AccessoryDesired * accessoryDesiredObj = getAccessoryDesiredInstance ( instance ) ;
if ( accessoryDesiredObj = = NULL ) {
Q_ASSERT ( false ) ;
return 0.0f ;
}
AccessoryDesired : : DataFields data = accessoryDesiredObj - > getData ( ) ;
return data . AccessoryVal ;
}
2011-08-16 16:06:18 +01:00
void ConfigInputWidget : : moveSticks ( )
{
QTransform trans ;
2013-05-19 17:37:30 +03:00
2014-11-09 22:39:05 +01:00
manualCommandData = manualCommandObj - > getData ( ) ;
flightStatusData = flightStatusObj - > getData ( ) ;
2012-09-16 15:14:47 +02:00
2012-10-19 20:30:42 +10:30
switch ( transmitterMode ) {
2013-05-19 17:37:30 +03:00
case mode1 :
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( manualCommandData . Yaw * STICK_MAX_MOVE * 10 , manualCommandData . Pitch * STICK_MAX_MOVE * 10 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( manualCommandData . Roll * STICK_MAX_MOVE * 10 , - manualCommandData . Throttle * STICK_MAX_MOVE * 10 ) , false ) ;
break ;
case mode2 :
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( manualCommandData . Yaw * STICK_MAX_MOVE * 10 , - manualCommandData . Throttle * STICK_MAX_MOVE * 10 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( manualCommandData . Roll * STICK_MAX_MOVE * 10 , manualCommandData . Pitch * STICK_MAX_MOVE * 10 ) , false ) ;
break ;
case mode3 :
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( manualCommandData . Roll * STICK_MAX_MOVE * 10 , manualCommandData . Pitch * STICK_MAX_MOVE * 10 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( manualCommandData . Yaw * STICK_MAX_MOVE * 10 , - manualCommandData . Throttle * STICK_MAX_MOVE * 10 ) , false ) ;
break ;
case mode4 :
trans = m_txLeftStickOrig ;
m_txLeftStick - > setTransform ( trans . translate ( manualCommandData . Roll * STICK_MAX_MOVE * 10 , - manualCommandData . Throttle * STICK_MAX_MOVE * 10 ) , false ) ;
trans = m_txRightStickOrig ;
m_txRightStick - > setTransform ( trans . translate ( manualCommandData . Yaw * STICK_MAX_MOVE * 10 , manualCommandData . Pitch * STICK_MAX_MOVE * 10 ) , false ) ;
break ;
default :
Q_ASSERT ( 0 ) ;
break ;
2011-08-16 16:06:18 +01:00
}
2014-02-09 19:33:29 +01:00
if ( flightStatusData . FlightMode = = flightModeSettingsData . FlightModePosition [ 0 ] ) {
2012-09-16 15:14:47 +02:00
m_txFlightMode - > setElementId ( " flightModeLeft " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeLOrig , false ) ;
2014-02-09 19:33:29 +01:00
} else if ( flightStatusData . FlightMode = = flightModeSettingsData . FlightModePosition [ 1 ] ) {
2012-09-16 15:14:47 +02:00
m_txFlightMode - > setElementId ( " flightModeCenter " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeCOrig , false ) ;
2014-02-09 19:33:29 +01:00
} else if ( flightStatusData . FlightMode = = flightModeSettingsData . FlightModePosition [ 2 ] ) {
2012-09-16 15:14:47 +02:00
m_txFlightMode - > setElementId ( " flightModeRight " ) ;
2013-05-19 17:37:30 +03:00
m_txFlightMode - > setTransform ( m_txFlightModeROrig , false ) ;
2012-09-16 15:14:47 +02:00
}
2014-11-09 22:39:05 +01:00
m_txAccess0 - > setTransform ( QTransform ( m_txAccess0Orig ) . translate ( getAccessoryDesiredValue ( 0 ) * ACCESS_MAX_MOVE * 10 , 0 ) , false ) ;
m_txAccess1 - > setTransform ( QTransform ( m_txAccess1Orig ) . translate ( getAccessoryDesiredValue ( 1 ) * ACCESS_MAX_MOVE * 10 , 0 ) , false ) ;
m_txAccess2 - > setTransform ( QTransform ( m_txAccess2Orig ) . translate ( getAccessoryDesiredValue ( 2 ) * ACCESS_MAX_MOVE * 10 , 0 ) , false ) ;
2011-08-16 16:06:18 +01:00
}
2011-06-20 14:28:16 +01:00
2011-08-17 12:43:08 +01:00
void ConfigInputWidget : : dimOtherControls ( bool value )
{
qreal opac ;
2013-05-19 17:37:30 +03:00
if ( value ) {
opac = 0.1 ;
} else {
opac = 1 ;
}
2011-08-17 12:43:08 +01:00
m_txAccess0 - > setOpacity ( opac ) ;
m_txAccess1 - > setOpacity ( opac ) ;
m_txAccess2 - > setOpacity ( opac ) ;
m_txFlightMode - > setOpacity ( opac ) ;
}
2011-08-20 19:10:28 +01:00
void ConfigInputWidget : : invertControls ( )
{
2013-05-19 17:37:30 +03:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
foreach ( QWidget * wd , extraWidgets ) {
QCheckBox * cb = qobject_cast < QCheckBox * > ( wd ) ;
if ( cb ) {
2012-01-14 21:23:26 +02:00
int index = manualSettingsObj - > getField ( " ChannelNumber " ) - > getElementNames ( ) . indexOf ( cb - > text ( ) ) ;
2013-05-19 17:37:30 +03:00
if ( ( cb - > isChecked ( ) & & ( manualSettingsData . ChannelMax [ index ] > manualSettingsData . ChannelMin [ index ] ) ) | |
( ! cb - > isChecked ( ) & & ( manualSettingsData . ChannelMax [ index ] < manualSettingsData . ChannelMin [ index ] ) ) ) {
2011-08-20 19:10:28 +01:00
qint16 aux ;
2013-05-19 17:37:30 +03:00
aux = manualSettingsData . ChannelMax [ index ] ;
manualSettingsData . ChannelMax [ index ] = manualSettingsData . ChannelMin [ index ] ;
manualSettingsData . ChannelMin [ index ] = aux ;
2011-08-20 19:10:28 +01:00
}
}
}
manualSettingsObj - > setData ( manualSettingsData ) ;
}
2012-06-23 17:14:59 +03:00
2011-08-23 11:25:28 +01:00
void ConfigInputWidget : : moveFMSlider ( )
2011-08-20 19:10:28 +01:00
{
2011-08-23 11:25:28 +01:00
ManualControlSettings : : DataFields manualSettingsDataPriv = manualSettingsObj - > getData ( ) ;
2013-05-19 17:37:30 +03:00
ManualControlCommand : : DataFields manualCommandDataPriv = manualCommandObj - > getData ( ) ;
2011-08-20 19:10:28 +01:00
2011-09-12 22:27:11 -05:00
float valueScaled ;
2013-05-19 17:37:30 +03:00
int chMin = manualSettingsDataPriv . ChannelMin [ ManualControlSettings : : CHANNELMIN_FLIGHTMODE ] ;
int chMax = manualSettingsDataPriv . ChannelMax [ ManualControlSettings : : CHANNELMAX_FLIGHTMODE ] ;
2011-09-12 22:27:11 -05:00
int chNeutral = manualSettingsDataPriv . ChannelNeutral [ ManualControlSettings : : CHANNELNEUTRAL_FLIGHTMODE ] ;
2011-08-20 19:10:28 +01:00
2013-05-19 17:37:30 +03:00
int value = manualCommandDataPriv . Channel [ ManualControlSettings : : CHANNELMIN_FLIGHTMODE ] ;
if ( ( chMax > chMin & & value > = chNeutral ) | | ( chMin > chMax & & value < = chNeutral ) ) {
if ( chMax ! = chNeutral ) {
2011-09-12 22:27:11 -05:00
valueScaled = ( float ) ( value - chNeutral ) / ( float ) ( chMax - chNeutral ) ;
2013-05-19 17:37:30 +03:00
} else {
2011-09-12 22:27:11 -05:00
valueScaled = 0 ;
2013-05-19 17:37:30 +03:00
}
} else {
if ( chMin ! = chNeutral ) {
2011-09-12 22:27:11 -05:00
valueScaled = ( float ) ( value - chNeutral ) / ( float ) ( chNeutral - chMin ) ;
2013-05-19 17:37:30 +03:00
} else {
2011-09-12 22:27:11 -05:00
valueScaled = 0 ;
2013-05-19 17:37:30 +03:00
}
2011-08-20 19:10:28 +01:00
}
2011-09-12 22:27:11 -05:00
2012-06-23 17:14:59 +03:00
// Bound and scale FlightMode from [-1..+1] to [0..1] range
2013-05-19 17:37:30 +03:00
if ( valueScaled < - 1.0 ) {
2012-06-23 17:14:59 +03:00
valueScaled = - 1.0 ;
2013-05-19 17:37:30 +03:00
} else if ( valueScaled > 1.0 ) {
valueScaled = 1.0 ;
}
2012-06-23 17:14:59 +03:00
2012-06-25 00:30:42 +03:00
// Convert flightMode value into the switch position in the range [0..N-1]
2012-06-25 11:41:42 +03:00
// This uses the same optimized computation as flight code to be consistent
uint8_t pos = ( ( int16_t ) ( valueScaled * 256 ) + 256 ) * manualSettingsDataPriv . FlightModeNumber > > 9 ;
2013-05-19 17:37:30 +03:00
if ( pos > = manualSettingsDataPriv . FlightModeNumber ) {
2012-06-25 00:30:42 +03:00
pos = manualSettingsDataPriv . FlightModeNumber - 1 ;
2013-05-19 17:37:30 +03:00
}
2013-05-04 00:13:15 +02:00
ui - > fmsSlider - > setValue ( pos ) ;
2012-06-23 17:14:59 +03:00
}
void ConfigInputWidget : : updatePositionSlider ( )
{
ManualControlSettings : : DataFields manualSettingsDataPriv = manualSettingsObj - > getData ( ) ;
2013-05-19 17:37:30 +03:00
switch ( manualSettingsDataPriv . FlightModeNumber ) {
2012-06-23 17:14:59 +03:00
default :
case 6 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos6 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_5 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos6 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 5 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos5 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_4 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos5 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 4 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos4 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_3 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos4 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 3 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos3 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_2 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos3 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 2 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos2 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_1 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos2 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 1 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos1 - > setEnabled ( true ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_0 - > setEnabled ( true ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos1 - > setEnabled ( true ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 0 :
2013-05-19 17:37:30 +03:00
break ;
2012-06-23 17:14:59 +03:00
}
2013-05-19 17:37:30 +03:00
switch ( manualSettingsDataPriv . FlightModeNumber ) {
2012-06-23 17:14:59 +03:00
case 0 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos1 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_0 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos1 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 1 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos2 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_1 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos2 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 2 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos3 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_2 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos3 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 3 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos4 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_3 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos4 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 4 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos5 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_4 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos5 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 5 :
2013-05-04 00:13:15 +02:00
ui - > fmsModePos6 - > setEnabled ( false ) ;
2014-01-17 01:15:02 +01:00
ui - > pidBankSs1_5 - > setEnabled ( false ) ;
2015-01-08 13:20:47 +11:00
ui - > assistControlPos6 - > setEnabled ( false ) ;
2013-05-19 17:37:30 +03:00
// pass through
2012-06-23 17:14:59 +03:00
case 6 :
default :
2013-05-19 17:37:30 +03:00
break ;
2012-06-23 17:14:59 +03:00
}
2014-12-26 22:45:15 +01:00
QString fmNumber = QString ( ) . setNum ( manualSettingsDataPriv . FlightModeNumber ) ;
int count = 0 ;
foreach ( QSlider * sp , findChildren < QSlider * > ( ) ) {
// Find FlightMode slider and apply stylesheet
if ( sp - > objectName ( ) = = " channelNeutral " ) {
if ( count = = 4 ) {
sp - > setStyleSheet (
2015-01-03 13:01:25 +01:00
" QSlider::groove:horizontal {border: 2px solid rgb(196, 196, 196); height: 12px; border-radius: 4px; "
2014-12-26 22:45:15 +01:00
" border-image:url(:/configgadget/images/flightmode_bg " + fmNumber + " .png); } "
" QSlider::add-page:horizontal { background: none; border: none; } "
" QSlider::sub-page:horizontal { background: none; border: none; } "
" QSlider::handle:horizontal { background: rgba(196, 196, 196, 255); width: 10px; height: 28px; "
2014-12-27 02:12:47 +01:00
" margin: -3px -2px; border-radius: 3px; border: 1px solid #777; } " ) ;
2014-12-26 22:45:15 +01:00
count + + ;
} else {
count + + ;
}
}
}
2011-08-20 19:10:28 +01:00
}
2011-09-06 18:26:47 -05:00
void ConfigInputWidget : : updateCalibration ( )
{
2013-05-19 17:37:30 +03:00
manualCommandData = manualCommandObj - > getData ( ) ;
for ( uint i = 0 ; i < ManualControlSettings : : CHANNELMAX_NUMELEM ; + + i ) {
if ( ( ! reverse [ i ] & & manualSettingsData . ChannelMin [ i ] > manualCommandData . Channel [ i ] ) | |
( reverse [ i ] & & manualSettingsData . ChannelMin [ i ] < manualCommandData . Channel [ i ] ) ) {
manualSettingsData . ChannelMin [ i ] = manualCommandData . Channel [ i ] ;
}
if ( ( ! reverse [ i ] & & manualSettingsData . ChannelMax [ i ] < manualCommandData . Channel [ i ] ) | |
( reverse [ i ] & & manualSettingsData . ChannelMax [ i ] > manualCommandData . Channel [ i ] ) ) {
manualSettingsData . ChannelMax [ i ] = manualCommandData . Channel [ i ] ;
}
2015-02-03 21:50:45 +01:00
if ( ( i = = ManualControlSettings : : CHANNELNUMBER_FLIGHTMODE ) | | ( i = = ManualControlSettings : : CHANNELNUMBER_THROTTLE ) ) {
2014-12-25 00:14:32 +01:00
adjustSpecialNeutrals ( ) ;
} else {
manualSettingsData . ChannelNeutral [ i ] = manualCommandData . Channel [ i ] ;
}
2011-09-06 18:26:47 -05:00
}
manualSettingsObj - > setData ( manualSettingsData ) ;
manualSettingsObj - > updated ( ) ;
}
void ConfigInputWidget : : simpleCalibration ( bool enable )
{
if ( enable ) {
2013-05-04 00:13:15 +02:00
ui - > configurationWizard - > setEnabled ( false ) ;
2014-12-25 14:18:34 +01:00
ui - > saveRCInputToRAM - > setEnabled ( false ) ;
ui - > saveRCInputToSD - > setEnabled ( false ) ;
2014-12-25 01:30:08 +01:00
ui - > runCalibration - > setText ( tr ( " Stop Manual Calibration " ) ) ;
2015-03-08 02:20:57 +01:00
throttleError = false ;
2011-10-20 08:31:58 -05:00
2011-09-06 18:26:47 -05:00
QMessageBox msgBox ;
2014-12-25 17:49:19 +01:00
msgBox . setText ( tr ( " <p>Arming Settings are now set to 'Always Disarmed' for your safety.</p> "
" <p>Be sure your receiver is powered with an external source and Transmitter is on.</p> "
" <p align='center'><b>Stop Manual Calibration</b> when done</p> " ) ) ;
2014-12-25 14:18:34 +01:00
msgBox . setDetailedText ( tr ( " You will have to reconfigure the arming settings manually when the manual calibration is finished. " ) ) ;
2011-09-06 18:26:47 -05:00
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . exec ( ) ;
2014-02-09 19:33:29 +01:00
manualCommandData = manualCommandObj - > getData ( ) ;
2011-09-06 18:26:47 -05:00
2014-02-09 19:33:29 +01:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
flightModeSettingsData = flightModeSettingsObj - > getData ( ) ;
flightModeSettingsData . Arming = FlightModeSettings : : ARMING_ALWAYSDISARMED ;
flightModeSettingsObj - > setData ( flightModeSettingsData ) ;
2011-09-06 18:26:47 -05:00
2011-09-07 01:47:10 -05:00
for ( unsigned int i = 0 ; i < ManualControlCommand : : CHANNEL_NUMELEM ; i + + ) {
2011-09-09 00:54:47 -05:00
reverse [ i ] = manualSettingsData . ChannelMax [ i ] < manualSettingsData . ChannelMin [ i ] ;
2014-12-26 00:00:08 +01:00
manualSettingsData . ChannelMin [ i ] = manualCommandData . Channel [ i ] ;
manualSettingsData . ChannelNeutral [ i ] = manualCommandData . Channel [ i ] ;
manualSettingsData . ChannelMax [ i ] = manualCommandData . Channel [ i ] ;
2011-09-06 18:26:47 -05:00
}
2014-11-09 23:01:34 +01:00
fastMdataSingle ( manualCommandObj , & manualControlMdata ) ;
2011-09-06 18:26:47 -05:00
2014-12-30 09:49:35 +01:00
// Stash actuatorSettings
actuatorSettingsData = actuatorSettingsObj - > getData ( ) ;
previousActuatorSettingsData = actuatorSettingsData ;
// Disable all actuators
resetActuatorSettings ( ) ;
2013-05-19 17:37:30 +03:00
connect ( manualCommandObj , SIGNAL ( objectUnpacked ( UAVObject * ) ) , this , SLOT ( updateCalibration ( ) ) ) ;
2011-09-06 18:26:47 -05:00
} else {
2013-05-19 17:37:30 +03:00
manualCommandData = manualCommandObj - > getData ( ) ;
2011-09-06 18:26:47 -05:00
manualSettingsData = manualSettingsObj - > getData ( ) ;
2014-11-09 23:01:34 +01:00
restoreMdataSingle ( manualCommandObj , & manualControlMdata ) ;
2011-09-06 18:26:47 -05:00
2013-05-19 17:37:30 +03:00
for ( unsigned int i = 0 ; i < ManualControlCommand : : CHANNEL_NUMELEM ; i + + ) {
2015-02-03 21:50:45 +01:00
if ( ( i = = ManualControlSettings : : CHANNELNUMBER_FLIGHTMODE ) | | ( i = = ManualControlSettings : : CHANNELNUMBER_THROTTLE ) ) {
2014-12-25 00:14:32 +01:00
adjustSpecialNeutrals ( ) ;
2015-03-08 02:20:57 +01:00
checkThrottleRange ( ) ;
2014-12-25 00:14:32 +01:00
} else {
manualSettingsData . ChannelNeutral [ i ] = manualCommandData . Channel [ i ] ;
}
2013-05-19 17:37:30 +03:00
}
2011-09-06 18:26:47 -05:00
manualSettingsObj - > setData ( manualSettingsData ) ;
2014-12-30 09:49:35 +01:00
// Load actuator settings back from beginning of manual calibration
actuatorSettingsObj - > setData ( previousActuatorSettingsData ) ;
2015-03-08 02:20:57 +01:00
ui - > configurationWizard - > setEnabled ( true ) ;
ui - > saveRCInputToRAM - > setEnabled ( true ) ;
ui - > saveRCInputToSD - > setEnabled ( true ) ;
ui - > runCalibration - > setText ( tr ( " Start Manual Calibration " ) ) ;
2013-05-19 17:37:30 +03:00
disconnect ( manualCommandObj , SIGNAL ( objectUnpacked ( UAVObject * ) ) , this , SLOT ( updateCalibration ( ) ) ) ;
2011-09-06 18:26:47 -05:00
}
}
2014-12-25 00:14:32 +01:00
void ConfigInputWidget : : adjustSpecialNeutrals ( )
{
// FlightMode and Throttle need special neutral settings
//
// Force flight mode neutral to middle
2015-02-03 21:50:45 +01:00
manualSettingsData . ChannelNeutral [ ManualControlSettings : : CHANNELNEUTRAL_FLIGHTMODE ] =
( manualSettingsData . ChannelMax [ ManualControlSettings : : CHANNELMAX_FLIGHTMODE ] +
manualSettingsData . ChannelMin [ ManualControlSettings : : CHANNELMIN_FLIGHTMODE ] ) / 2 ;
2014-12-25 00:14:32 +01:00
// Force throttle to be near min, add 4% from total range to avoid arming issues
manualSettingsData . ChannelNeutral [ ManualControlSettings : : CHANNELNEUTRAL_THROTTLE ] =
manualSettingsData . ChannelMin [ ManualControlSettings : : CHANNELMIN_THROTTLE ] +
( ( manualSettingsData . ChannelMax [ ManualControlSettings : : CHANNELMAX_THROTTLE ] -
manualSettingsData . ChannelMin [ ManualControlSettings : : CHANNELMIN_THROTTLE ] ) * 0.04 ) ;
}
2014-12-25 17:49:19 +01:00
2015-03-08 02:20:57 +01:00
void ConfigInputWidget : : checkThrottleRange ( )
{
2015-03-09 13:08:56 +01:00
int throttleRange = abs ( manualSettingsData . ChannelMax [ ManualControlSettings : : CHANNELMAX_THROTTLE ] -
2015-03-12 21:33:30 +11:00
manualSettingsData . ChannelMin [ ManualControlSettings : : CHANNELMIN_THROTTLE ] ) ;
2015-03-09 13:08:56 +01:00
if ( ! throttleError & & ( throttleRange < 300 ) ) {
2015-03-08 02:20:57 +01:00
throttleError = true ;
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " <p>There is something wrong with Throttle range. Please redo calibration and move <b>ALL sticks</b>, Throttle stick included.</p> " ) , QMessageBox : : Ok ) ;
// Set Throttle neutral to max value so Throttle can't be positive
manualSettingsData . ChannelNeutral [ ManualControlSettings : : CHANNELNEUTRAL_THROTTLE ] =
manualSettingsData . ChannelMax [ ManualControlSettings : : CHANNELMAX_THROTTLE ] ;
}
}
2014-12-25 17:49:19 +01:00
bool ConfigInputWidget : : shouldObjectBeSaved ( UAVObject * object )
{
// ManualControlCommand no need to be saved
2014-12-30 14:57:34 +01:00
return dynamic_cast < ManualControlCommand * > ( object ) = = NULL ;
2014-12-25 17:49:19 +01:00
}
2014-12-29 01:07:11 +01:00
void ConfigInputWidget : : resetChannelSettings ( )
{
manualSettingsData = manualSettingsObj - > getData ( ) ;
// Clear all channel data : Channel Type (PPM,PWM..) and Number
for ( unsigned int channel = 0 ; channel < 9 ; channel + + ) {
manualSettingsData . ChannelGroups [ channel ] = ManualControlSettings : : CHANNELGROUPS_NONE ;
manualSettingsData . ChannelNumber [ channel ] = 0 ;
manualSettingsObj - > setData ( manualSettingsData ) ;
}
}
2014-12-30 09:49:35 +01:00
void ConfigInputWidget : : resetActuatorSettings ( )
{
actuatorSettingsData = actuatorSettingsObj - > getData ( ) ;
2015-02-11 23:38:01 +01:00
UAVDataObject * mixer = dynamic_cast < UAVDataObject * > ( getObjectManager ( ) - > getObject ( QString ( " MixerSettings " ) ) ) ;
Q_ASSERT ( mixer ) ;
QString mixerType ;
// Clear all output data : Min, max, neutral at same value
// 1000 for motors and 1500 for all others (Reversable motor included)
2014-12-30 09:49:35 +01:00
for ( unsigned int output = 0 ; output < 12 ; output + + ) {
2015-02-11 23:38:01 +01:00
QString mixerNumType = QString ( " Mixer%1Type " ) . arg ( output + 1 ) ;
UAVObjectField * field = mixer - > getField ( mixerNumType ) ;
Q_ASSERT ( field ) ;
if ( field ) {
mixerType = field - > getValue ( ) . toString ( ) ;
}
if ( ( mixerType = = " Motor " ) | | ( mixerType = = " Disabled " ) ) {
actuatorSettingsData . ChannelMax [ output ] = 1000 ;
actuatorSettingsData . ChannelMin [ output ] = 1000 ;
actuatorSettingsData . ChannelNeutral [ output ] = 1000 ;
} else {
actuatorSettingsData . ChannelMax [ output ] = 1500 ;
actuatorSettingsData . ChannelMin [ output ] = 1500 ;
actuatorSettingsData . ChannelNeutral [ output ] = 1500 ;
}
2014-12-30 09:49:35 +01:00
actuatorSettingsObj - > setData ( actuatorSettingsData ) ;
}
}