From 6a48cef37d65f4f97f1004d119770e69ae64a2fd Mon Sep 17 00:00:00 2001
From: Lorenz Meier <lm@inf.ethz.ch>
Date: Sat, 28 Dec 2013 22:55:22 +0100
Subject: [PATCH] Cleaned up PX4 autostart, made indices consistent and added
 new configs

---
 .../px4_configuration/QGCPX4AirframeConfig.cc | 117 ++++++++++++++----
 .../px4_configuration/QGCPX4AirframeConfig.h  |   7 +-
 .../px4_configuration/QGCPX4AirframeConfig.ui |  31 ++++-
 3 files changed, 124 insertions(+), 31 deletions(-)

diff --git a/src/ui/px4_configuration/QGCPX4AirframeConfig.cc b/src/ui/px4_configuration/QGCPX4AirframeConfig.cc
index 48d321b11..3df866d77 100644
--- a/src/ui/px4_configuration/QGCPX4AirframeConfig.cc
+++ b/src/ui/px4_configuration/QGCPX4AirframeConfig.cc
@@ -25,51 +25,73 @@ QGCPX4AirframeConfig::QGCPX4AirframeConfig(QWidget *parent) :
     // Fill the lists here manually in accordance with the list from:
     // https://github.com/PX4/Firmware/blob/master/ROMFS/px4fmu_common/init.d/rcS
 
-    ui->planeComboBox->addItem(tr("Multiplex Easystar 1/2"), 100);
-    ui->planeComboBox->addItem(tr("Hobbyking Bixler 1/2"), 101);
-    ui->planeComboBox->addItem(tr("HilStar (SIMULATION)"), 1000);
+    ui->simComboBox->addItem(tr("HilStar (SIMULATION)"), 1000);
+
+    connect(ui->simPushButton, SIGNAL(clicked()), this, SLOT(simSelected()));
+    connect(ui->simComboBox, SIGNAL(activated(int)), this, SLOT(simSelected(int)));
+    ui->simPushButton->setEnabled(ui->simComboBox->count() > 0);
+
+    ui->planeComboBox->addItem(tr("Multiplex Easystar 1/2"), 2100);
+    ui->planeComboBox->addItem(tr("Hobbyking Bixler 1/2"), 2101);
 
     connect(ui->planePushButton, SIGNAL(clicked()), this, SLOT(planeSelected()));
     connect(ui->planeComboBox, SIGNAL(activated(int)), this, SLOT(planeSelected(int)));
     ui->planePushButton->setEnabled(ui->planeComboBox->count() > 0);
 
-    ui->flyingWingComboBox->addItem(tr("Bormatec Camflyer Q"), 30);
-    ui->flyingWingComboBox->addItem(tr("Phantom FPV"), 31);
+    ui->flyingWingComboBox->addItem(tr("Bormatec Camflyer Q (800 mm)"), 3030);
+    ui->flyingWingComboBox->addItem(tr("Z-84 Wing Wing (845 mm)"), 3033);
+    ui->flyingWingComboBox->addItem(tr("FX-61 Phantom FPV (1550 mm)"), 3031);
+    ui->flyingWingComboBox->addItem(tr("FX-79 Buffalo (2000 mm)"), 3034);
+    ui->flyingWingComboBox->addItem(tr("Skywalker X5 (1180 mm)"), 3032);
 
     connect(ui->flyingWingPushButton, SIGNAL(clicked()), this, SLOT(flyingWingSelected()));
     connect(ui->flyingWingComboBox, SIGNAL(activated(int)), this, SLOT(flyingWingSelected(int)));
 
-    ui->quadXComboBox->addItem(tr("DJI F330 8\" Quad"), 10);
-    ui->quadXComboBox->addItem(tr("DJI F450 10\" Quad"), 11);
-    ui->quadXComboBox->addItem(tr("Turnigy Talon v2 X550 Quad"), 666);
-    ui->quadXComboBox->addItem(tr("AR.Drone Frame Quad"), 8);
-    ui->quadXComboBox->addItem(tr("AR.Drone Quad (w. PX4FLOW)"), 9);
+    ui->quadXComboBox->addItem(tr("DJI F330 8\" Quad"), 4010);
+    ui->quadXComboBox->addItem(tr("DJI F450 10\" Quad"), 4011);
+    ui->quadXComboBox->addItem(tr("Turnigy Talon v2 X550 Quad"), 4012);
+    ui->quadXComboBox->addItem(tr("AR.Drone Frame Quad"), 4008);
+    ui->quadXComboBox->addItem(tr("AR.Drone Quad (w. PX4FLOW)"), 4009);
+    ui->quadXComboBox->addItem(tr("DJI F330 with MK BLCTRL"), 4017);
+    ui->quadXComboBox->addItem(tr("Mikrokopter X frame"), 4019);
 
     connect(ui->quadXPushButton, SIGNAL(clicked()), this, SLOT(quadXSelected()));
     connect(ui->quadXComboBox, SIGNAL(activated(int)), this, SLOT(quadXSelected(int)));
+    ui->quadXPushButton->setEnabled(ui->quadXComboBox->count() > 0);
+
+    ui->quadPlusComboBox->addItem(tr("DJI F330 8\" Quad"), 4010);
+    ui->quadXComboBox->addItem(tr("Mikrokopter + frame"), 5020);
 
     connect(ui->quadPlusPushButton, SIGNAL(clicked()), this, SLOT(quadPlusSelected()));
     connect(ui->quadPlusComboBox, SIGNAL(activated(int)), this, SLOT(quadPlusSelected(int)));
     ui->quadPlusPushButton->setEnabled(ui->quadPlusComboBox->count() > 0);
 
+    ui->hexaPlusComboBox->addItem(tr("DJI F550 10\" Hexa"), 6012);
+
     connect(ui->hexaXPushButton, SIGNAL(clicked()), this, SLOT(hexaXSelected()));
     connect(ui->hexaXComboBox, SIGNAL(activated(int)), this, SLOT(hexaXSelected(int)));
     ui->hexaXPushButton->setEnabled(ui->hexaXComboBox->count() > 0);
 
+    ui->hexaPlusComboBox->addItem(tr("DJI F550 10\" Hexa"), 7013);
+
     connect(ui->hexaPlusPushButton, SIGNAL(clicked()), this, SLOT(hexaPlusSelected()));
     connect(ui->hexaPlusComboBox, SIGNAL(activated(int)), this, SLOT(hexaPlusSelected(int)));
     ui->hexaPlusPushButton->setEnabled(ui->hexaPlusComboBox->count() > 0);
 
+    ui->octoXComboBox->addItem(tr("Standard 10\" Octo"), 8001);
+
     connect(ui->octoXPushButton, SIGNAL(clicked()), this, SLOT(octoXSelected()));
     connect(ui->octoXComboBox, SIGNAL(activated(int)), this, SLOT(octoXSelected(int)));
     ui->octoXPushButton->setEnabled(ui->octoXComboBox->count() > 0);
 
+    ui->octoPlusComboBox->addItem(tr("Standard 10\" Octo"), 9001);
+
     connect(ui->octoPlusPushButton, SIGNAL(clicked()), this, SLOT(octoPlusSelected()));
     connect(ui->octoPlusComboBox, SIGNAL(activated(int)), this, SLOT(octoPlusSelected(int)));
     ui->octoPlusPushButton->setEnabled(ui->octoPlusComboBox->count() > 0);
 
-    ui->hComboBox->addItem(tr("3DR Iris"), 16);
-    ui->hComboBox->addItem(tr("TBS Discovery"), 15);
+    ui->hComboBox->addItem(tr("3DR Iris"), 10016);
+    ui->hComboBox->addItem(tr("TBS Discovery"), 10015);
 
     connect(ui->hPushButton, SIGNAL(clicked()), this, SLOT(hSelected()));
     connect(ui->hComboBox, SIGNAL(activated(int)), this, SLOT(hSelected(int)));
@@ -144,29 +166,62 @@ void QGCPX4AirframeConfig::setAirframeID(int id)
     // a quick hack to get started
     uncheckAll();
 
-    if (id > 0 && id < 15) {
-        ui->quadXPushButton->setChecked(true);
-        ui->quadXComboBox->setCurrentIndex(ui->quadXComboBox->findData(id));
-        ui->statusLabel->setText(tr("Selected quad X (ID: #%1)").arg(selectedId));
+    if (id >= 1000 && id < 2000)
+    {
+        ui->simPushButton->setChecked(true);
+        ui->simComboBox->setCurrentIndex(ui->simComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected simulation (ID: #%1)").arg(selectedId));
     }
-    else if (id >= 15 && id < 20)
+    else if (id >= 2000 && id < 3000)
     {
-        ui->hPushButton->setChecked(true);
-        ui->hComboBox->setCurrentIndex(ui->hComboBox->findData(id));
-        ui->statusLabel->setText(tr("Selected H Frame (ID: #%1)").arg(selectedId));
+        ui->planePushButton->setChecked(true);
+        ui->planeComboBox->setCurrentIndex(ui->planeComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected plane (ID: #%1)").arg(selectedId));
     }
-    else if (id >= 30 && id < 50)
+    else if (id >= 3000 && id < 4000)
     {
         ui->flyingWingPushButton->setChecked(true);
         ui->flyingWingComboBox->setCurrentIndex(ui->flyingWingComboBox->findData(id));
         ui->statusLabel->setText(tr("Selected flying wing (ID: #%1)").arg(selectedId));
     }
-    else if (id >= 100 && id < 150 || id >= 1000 <= 2000)
+    else if (id >= 4000 && id < 5000) {
+        ui->quadXPushButton->setChecked(true);
+        ui->quadXComboBox->setCurrentIndex(ui->quadXComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected quadrotor in X config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 5000 && id < 6000) {
+        ui->quadPlusPushButton->setChecked(true);
+        ui->quadPlusComboBox->setCurrentIndex(ui->quadPlusComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected quadrotor in + config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 6000 && id < 7000) {
+        ui->hexaXPushButton->setChecked(true);
+        ui->hexaXComboBox->setCurrentIndex(ui->hexaXComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected hexarotor in X config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 7000 && id < 8000) {
+        ui->hexaPlusPushButton->setChecked(true);
+        ui->hexaPlusComboBox->setCurrentIndex(ui->hexaPlusComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected hexarotor in + config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 8000 && id < 9000) {
+        ui->octoXPushButton->setChecked(true);
+        ui->octoXComboBox->setCurrentIndex(ui->octoXComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected octorotor in X config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 9000 && id < 10000) {
+        ui->octoPlusPushButton->setChecked(true);
+        ui->octoPlusComboBox->setCurrentIndex(ui->octoPlusComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected octorotor in + config (ID: #%1)").arg(selectedId));
+    }
+    else if (id >= 10000 && id < 11000)
     {
-        ui->planePushButton->setChecked(true);
-        ui->planeComboBox->setCurrentIndex(ui->planeComboBox->findData(id));
-        ui->statusLabel->setText(tr("Selected plane (ID: #%1)").arg(selectedId));
+        ui->hPushButton->setChecked(true);
+        ui->hComboBox->setCurrentIndex(ui->hComboBox->findData(id));
+        ui->statusLabel->setText(tr("Selected H frame multirotor (ID: #%1)").arg(selectedId));
     }
+
+
 }
 
 void QGCPX4AirframeConfig::applyAndReboot()
@@ -363,6 +418,17 @@ void QGCPX4AirframeConfig::setAutoConfig(bool enabled)
     paramMgr->setPendingParam(0, "SYS_AUTOCONFIG", (qint32) ((enabled) ? 1 : 0));
 }
 
+void QGCPX4AirframeConfig::simSelected()
+{
+    simSelected(ui->simComboBox->currentIndex());
+}
+
+void QGCPX4AirframeConfig::simSelected(int index)
+{
+    int system_index = ui->simComboBox->itemData(index).toInt();
+    setAirframeID(system_index);
+}
+
 void QGCPX4AirframeConfig::flyingWingSelected()
 {
     flyingWingSelected(ui->flyingWingComboBox->currentIndex());
@@ -385,7 +451,6 @@ void QGCPX4AirframeConfig::planeSelected(int index)
     setAirframeID(system_index);
 }
 
-
 void QGCPX4AirframeConfig::quadXSelected()
 {
     quadXSelected(ui->quadXComboBox->currentIndex());
diff --git a/src/ui/px4_configuration/QGCPX4AirframeConfig.h b/src/ui/px4_configuration/QGCPX4AirframeConfig.h
index dcbf4abc1..e8a41f529 100644
--- a/src/ui/px4_configuration/QGCPX4AirframeConfig.h
+++ b/src/ui/px4_configuration/QGCPX4AirframeConfig.h
@@ -46,11 +46,12 @@ public slots:
      */
     void quadXSelected(int index);
 
-    void flyingWingSelected();
-    void flyingWingSelected(int index);
+    void simSelected();
+    void simSelected(int index);
     void planeSelected();
     void planeSelected(int index);
-
+    void flyingWingSelected();
+    void flyingWingSelected(int index);
     void quadPlusSelected();
     void quadPlusSelected(int index);
     void hexaXSelected();
diff --git a/src/ui/px4_configuration/QGCPX4AirframeConfig.ui b/src/ui/px4_configuration/QGCPX4AirframeConfig.ui
index 245c3741e..6f7cb3d93 100644
--- a/src/ui/px4_configuration/QGCPX4AirframeConfig.ui
+++ b/src/ui/px4_configuration/QGCPX4AirframeConfig.ui
@@ -26,6 +26,12 @@
    </item>
    <item row="0" column="0" colspan="4">
     <widget class="QScrollArea" name="scrollArea">
+     <property name="baseSize">
+      <size>
+       <width>0</width>
+       <height>0</height>
+      </size>
+     </property>
      <property name="widgetResizable">
       <bool>true</bool>
      </property>
@@ -33,9 +39,9 @@
       <property name="geometry">
        <rect>
         <x>0</x>
-        <y>0</y>
+        <y>-282</y>
         <width>762</width>
-        <height>647</height>
+        <height>638</height>
        </rect>
       </property>
       <layout class="QGridLayout" name="gridLayout">
@@ -345,6 +351,27 @@
          </item>
         </layout>
        </item>
+       <item row="2" column="1">
+        <layout class="QVBoxLayout" name="verticalLayout_10">
+         <item>
+          <widget class="QPushButton" name="simPushButton">
+           <property name="text">
+            <string>Simulation Setup</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QComboBox" name="simComboBox"/>
+         </item>
+         <item>
+          <widget class="QLabel" name="label_10">
+           <property name="text">
+            <string>Simulation / Experimental</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
       </layout>
      </widget>
     </widget>
-- 
2.22.0