From 3a13459bd5615c6d2b083fbf1ba9e0b059a34377 Mon Sep 17 00:00:00 2001
From: roangel <roangel@student.ethz.ch>
Date: Tue, 15 Aug 2017 15:49:39 +0200
Subject: [PATCH] Added LUT for addresses. Now they are not editable during
 runtime

---
 pps_ws/src/d_fall_pps/CMakeLists.txt          |  1 +
 .../GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro.user   |  2 +-
 .../GUI_Qt/CrazyFlyGUI/include/addressLUT.h   | 10 ++++++++
 .../CrazyFlyGUI/include/mainguiwindow.h       |  2 ++
 .../GUI_Qt/CrazyFlyGUI/src/addressLUT.cpp     |  9 +++++++
 .../GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp  | 24 +++++++++++++++++++
 .../GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui   |  9 ++++++-
 pps_ws/src/d_fall_pps/param/Crazyflie.db      |  5 ++--
 8 files changed, 58 insertions(+), 4 deletions(-)
 create mode 100644 pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/addressLUT.h
 create mode 100644 pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/addressLUT.cpp

diff --git a/pps_ws/src/d_fall_pps/CMakeLists.txt b/pps_ws/src/d_fall_pps/CMakeLists.txt
index c3232780..5aa50bc4 100755
--- a/pps_ws/src/d_fall_pps/CMakeLists.txt
+++ b/pps_ws/src/d_fall_pps/CMakeLists.txt
@@ -237,6 +237,7 @@ set(MY_CPP_SOURCES              # compilation of sources
     ${MY_LIB_PATH_SRC}/rosNodeThread.cpp
     ${MY_LIB_PATH_SRC}/crazyFly.cpp
     ${MY_LIB_PATH_SRC}/CFLinker.cpp
+    ${MY_LIB_PATH_SRC}/addressLUT.cpp
     )
 
 
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro.user b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro.user
index 9fc84e79..ebe2fd31 100755
--- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro.user
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/CrazyFlyGUI.pro.user
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.0.2, 2017-05-26T12:05:49. -->
+<!-- Written by QtCreator 4.0.2, 2017-08-15T15:30:19. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/addressLUT.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/addressLUT.h
new file mode 100644
index 00000000..ac92f871
--- /dev/null
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/addressLUT.h
@@ -0,0 +1,10 @@
+#ifndef ADDRESSLUT_H
+#define ADDRESSLUT_H
+
+#include <string>
+#include <map>
+
+
+extern std::map<std::string, std::string> address_LUT;
+
+#endif
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h
index 4606b0ce..b0914b96 100755
--- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/include/mainguiwindow.h
@@ -128,6 +128,8 @@ private slots:
     void setTabIndex(int index);
     void doTabClosed(int tab_index);
 
+    void on_comboBoxCFs_currentTextChanged(const QString &arg1);
+
 private:
 
     Ui::MainGUIWindow *ui;
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/addressLUT.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/addressLUT.cpp
new file mode 100644
index 00000000..6210de02
--- /dev/null
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/addressLUT.cpp
@@ -0,0 +1,9 @@
+#include "addressLUT.h"
+
+
+std::map<std::string, std::string> address_LUT
+{
+    {"CF1", "A12D2"},
+    {"CF2", "E341E"},
+    {"CF3", "4E21A"},
+};
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp
index 0821c001..606e5432 100755
--- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.cpp
@@ -3,6 +3,7 @@
 #include "crazyFlyZoneTab.h"
 #include "myGraphicsScene.h"
 #include "myGraphicsView.h"
+#include "addressLUT.h"
 
 #include <QObject>
 #include <QDoubleSpinBox>
@@ -124,6 +125,13 @@ void MainGUIWindow::_init()
     // ui->err_message_cf_zone->hide();
     // ui->err_message_student_id->hide();
 
+    ui->radioAddress_text->setReadOnly(true);
+
+    QPalette *palette = new QPalette();
+    palette->setColor(QPalette::Base,Qt::lightGray);
+    palette->setColor(QPalette::Text,Qt::darkGray);
+    ui->radioAddress_text->setPalette(*palette);
+
     ui->err_message_cf->setStyleSheet("QLabel { color : red; }");
     ui->err_message_cf_zone->setStyleSheet("QLabel { color : red; }");
     ui->err_message_student_id->setStyleSheet("QLabel { color : red; }");
@@ -872,3 +880,19 @@ void MainGUIWindow::on_load_from_DB_button_clicked()
         ROS_ERROR("Failed to read DB");
     }
 }
+
+void MainGUIWindow::on_comboBoxCFs_currentTextChanged(const QString &arg1)
+{
+    std::string key = arg1.toStdString();
+    auto it = address_LUT.find(key);
+    if(it != address_LUT.end())
+    {
+        std::string found = it->second;
+        QString found_qstr = QString::fromStdString(found);
+        ui->radioAddress_text->setText(found_qstr);
+    }
+    else
+    {
+        ROS_INFO("name not found in LUT");
+    }
+}
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui
index c3bfaa5b..13c41f36 100755
--- a/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/CrazyFlyGUI/src/mainguiwindow.ui
@@ -422,7 +422,14 @@
             </widget>
            </item>
            <item row="10" column="6">
-            <widget class="QLineEdit" name="radioAddress_text"/>
+            <widget class="QLineEdit" name="radioAddress_text">
+             <property name="readOnly">
+              <bool>true</bool>
+             </property>
+             <property name="clearButtonEnabled">
+              <bool>false</bool>
+             </property>
+            </widget>
            </item>
            <item row="11" column="6">
             <widget class="QLabel" name="err_message_radio_address">
diff --git a/pps_ws/src/d_fall_pps/param/Crazyflie.db b/pps_ws/src/d_fall_pps/param/Crazyflie.db
index 454f843a..2c6f791e 100644
--- a/pps_ws/src/d_fall_pps/param/Crazyflie.db
+++ b/pps_ws/src/d_fall_pps/param/Crazyflie.db
@@ -1,2 +1,3 @@
-2,CF1,1,0,0.52,0.41,-0.2,1.56,1.55,2
-1,CF2,2,1,-1.62398,-1.65338,-0.2,1.70872,0.674222,2
+1,CF1,A12D2,0,0.180387,0.712283,-0.2,1.77763,1.34043,2
+2,CF2,E341E,1,-0.628728,-0.48753,-0.2,0.971272,0.52247,2
+3,CF3,4E21A,2,0.425248,-1.49146,-0.2,1.66704,-0.577371,2
-- 
GitLab