From 026bbb4185b1bef1bdf7b81202f275a323646573 Mon Sep 17 00:00:00 2001
From: Angel <roangel@student.ethz.ch>
Date: Tue, 26 Sep 2017 17:16:58 +0200
Subject: [PATCH] added battery threshold, now we disable the buttons in GUI
 when battery low

---
 .../GUI_Qt/studentGUI/include/MainWindow.h    |  5 +++++
 .../GUI_Qt/studentGUI/src/MainWindow.cpp      | 22 ++++++++++++++++---
 .../GUI_Qt/studentGUI/src/MainWindow.ui       | 19 +++++++++++++---
 3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h
index 9e222738..6c39e0b0 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/include/MainWindow.h
@@ -40,6 +40,11 @@
 #define STATE_FLYING     3
 #define STATE_LAND       4
 
+// battery states
+
+#define BATTERY_STATE_NORMAL 0
+#define BATTERY_STATE_LOW    1
+
 
 #define PI 3.141592653589
 
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp
index 5c879f98..76b3e707 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.cpp
@@ -91,6 +91,7 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
 
     disableGUI();
     highlightSafeControllerTab();
+    ui->label_battery->setStyleSheet("QLabel { color : red; }");
 }
 
 
@@ -101,12 +102,12 @@ MainWindow::~MainWindow()
 
 void MainWindow::disableGUI()
 {
-    ui->groupBox_general->setEnabled(false);
+    // ui->groupBox_general->setEnabled(false);
 }
 
 void MainWindow::enableGUI()
 {
-    ui->groupBox_general->setEnabled(true);
+    // ui->groupBox_general->setEnabled(true);
 }
 
 void MainWindow::highlightSafeControllerTab()
@@ -186,7 +187,22 @@ void MainWindow::flyingStateChangedCallback(const std_msgs::Int32& msg)
 
 void MainWindow::batteryStateChangedCallback(const std_msgs::Int32& msg)
 {
-    // switch case with unabling buttons motors off, take off, etc... when battery is shit
+    // switch case with unabling buttons motors off, take off, etc... when battery is low
+    QString qstr = "";
+    switch(msg.data)
+    {
+        case BATTERY_STATE_LOW:
+            qstr.append("Low Battery!");
+            ui->groupBox_4->setEnabled(false);
+            ui->label_battery->setText(qstr);
+            break;
+        case BATTERY_STATE_NORMAL:
+            ui->groupBox_4->setEnabled(true);
+            ui->label_battery->clear();
+            break;
+        default:
+            break;
+    }
 }
 
 
diff --git a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui
index f26c868b..454375c1 100644
--- a/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui
+++ b/pps_ws/src/d_fall_pps/GUI_Qt/studentGUI/src/MainWindow.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1027</width>
-    <height>585</height>
+    <width>1056</width>
+    <height>670</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -1107,6 +1107,19 @@
             </property>
            </widget>
           </item>
+          <item>
+           <widget class="QLabel" name="label_battery">
+            <property name="font">
+             <font>
+              <pointsize>9</pointsize>
+              <italic>true</italic>
+             </font>
+            </property>
+            <property name="text">
+             <string/>
+            </property>
+           </widget>
+          </item>
          </layout>
         </widget>
        </item>
@@ -1214,7 +1227,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>1027</width>
+     <width>1056</width>
      <height>25</height>
     </rect>
    </property>
-- 
GitLab