My final year project

Dependencies:   BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG SDFileSystem TS_DISCO_F746NG ResistiveTouchController Map CYS8218Controller MedianFilter

Revision:
20:70c5b1e499f0
Parent:
19:ef78ac1a98f8
Child:
22:dd9ff475b34c
--- a/Screens/AutomaticControlScreen.cpp	Sun Oct 02 18:45:48 2016 +0200
+++ b/Screens/AutomaticControlScreen.cpp	Sun Oct 02 23:16:00 2016 +0200
@@ -5,8 +5,8 @@
   _lbTitle( SCREEN_W/2, 0, "Automatic", Label::CENTER, Font24),
   _btBack( 0, SCREEN_H-30, 100, 30, "Back"),
   _btSettings(SCREEN_W-100, SCREEN_H-30, 100, 30, "Settings"),
-  _btStart(0, SCREEN_H-65, SCREEN_W, 30, "Start"), //TODO Custom colors and disabled featrure
-  _btStop(0, SCREEN_H-65, SCREEN_W, 30, "Start"), //TODO Custom colors
+  _btStart(0, SCREEN_H-65, SCREEN_W, 30, "Start"),
+  _btStop(0, SCREEN_H-65, SCREEN_W, 30, "Stop"),
   _btMore((SCREEN_W/2)-50, SCREEN_H-30, 100, 30, "More"),
   _nlbTs( SCREEN_W/2, 26, "Cycle Time (us):%d", *Ts, Label::CENTER),
   _gXPos( 0, 40, SCREEN_W/2-1,  158, -170, 170, "X Position (mm)"),
@@ -19,6 +19,7 @@
   _started = started;
   _xSP = xSP;
   _ySP = ySP;
+  _ballOnPlate = ballOnPlate;
 }
 
 void AutomaticControlScreen::Draw()
@@ -27,6 +28,7 @@
   _lbTitle.Draw();
   _btBack.Draw();
   _btSettings.Draw();
+  _btStop.Inactivate();
   _btStart.Inactivate();
   _btStart.Draw();
   _btMore.Draw();
@@ -50,50 +52,72 @@
 
   if( _btMore.Touched() )
   {
+    if( *_started )
+    {
+      *_started = false;
+    }
+
     *_nextScreen = AUTOMATIC_MORE_SCREEN;
-    //TODO Ensure control system is not active
   }
 
 
-  if( !_btStart.IsActive() )
+  if( _btStart.IsActive() )
   {
-    if( _ballOnPlate() )
-      _btStart.Activate();
-  }
-  else
-  {
-    if( _ballOnPlate() )
+    if( !*_ballOnPlate )
+      _btStart.Inactivate();
+    else
     {
       if( _btStart.Touched() )
       {
-
+        _btStart.Inactivate();
+        _btStart.Erase();
+        _btStop.Activate();
+        _btStop.Draw(0xFFFF0000);
+        Thread::wait(200);
+        *_started = true;
       }
     }
-    else
+  }
+  else if( _btStop.IsActive() )
+  {
+    if( _btStop.Touched() )
     {
-        _btStart.Inactivate();
+      _btStop.Inactivate();
+      _btStop.Erase();
+      _btStart.Activate();
+      _btStart.Draw(0xFF00FF00);
+      Thread::wait(200);
+      *_started = false;
+    }
+  }
+  else if( *_ballOnPlate )
+  {
+    if( !_btStart.IsActive() )
+    {
+      _btStart.Activate();
+      _btStart.Draw(0xFF00FF00);
     }
   }
 
-    //TODO Add stop logic
-
-
-  if( *_started && *_ballOnPlate )
+  if( *_ballOnPlate && *_started )
   {
     _gXPos.Insert(*_xPos);
-    _gXPos.Update();
+    _gYPos.Insert(*_yPos);
 
-    if( *_xSP != 0 )
-      _gXPos.HLine(*_xSP);
-
-    _gYPos.Insert(*_yPos);
+    _gXPos.Update();
     _gYPos.Update();
 
-    if( *_ySP != 0 )
+    _nlbTs.Draw("Cycle time (us):%d",*_Ts);
+
+    if( *_xSP )
+    {
+      _gXPos.HLine(*_xSP);
+    }
+
+    if( *_ySP )
+    {
       _gYPos.HLine(*_ySP);
-
-    _nlbTs.Draw("Cycle Time (us):%d", *_Ts);
+    }
 
   }
-
 }