PlayBack

Dependencies:   TPixy-Interface

Fork of ManualControlFinal by ECE4333 - 2018 - Ahmed & Brandon

Revision:
23:1839085ffdcf
Parent:
22:c09acff62e6a
--- a/ui.cpp	Fri Mar 23 22:42:41 2018 +0000
+++ b/ui.cpp	Thu Mar 29 22:33:52 2018 +0000
@@ -7,7 +7,7 @@
 /******************************************************************************/
 // filename: ui.cpp
 // file content description:
-//      * Functions to display and manage the user interface on the PC terminal. 
+//      * Functions to display and manage the user interface on the PC terminal.
 /******************************************************************************/
 
 #include "mbed.h"
@@ -16,6 +16,9 @@
 #include "CameraThread.h"
 #include "PiControlThread.h"
 
+bool startRecording = false;
+bool MC = true;
+
 Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins
 Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
 
@@ -30,7 +33,7 @@
     bluetooth.printf("\r\n************************************");
     bluetooth.printf("\r\n**** AUTONOMOUS FOLLOWING ROBOT ****");
     bluetooth.printf("\r\n************************************");
-    bluetooth.printf("\r\n-PRESS 'r' TO KILL ROBOT");
+    bluetooth.printf("\r\n-PRESS 'r' TO reset");
 }
 
 /******************************************************************************
@@ -41,57 +44,85 @@
 {
     if (bluetooth.readable()) {
         x = bluetooth.getc();
+
+        // enter manual control and exit patrol mode
+        if(x == 'm') {
+            MC = true;
+        }
+
+        // exit manual control and enter patrol mode
+        if(x == 'p') {
+            MC = false;
+            startRecording = false;
+        }
         
+        if(x == 'l'){
+            startRecording = true;
+        }
+
         // if input from console is the letter 'r'
-        if(x == 'r') {
+        if(x == 'r' && (MC)) {
+            
             // reset watchdog timer
             WatchdogReset();
             setpointR = 0;
             setpointL = 0;
-            bluetooth.printf("\r\nWatchdog has been reset");
+            MC = true;
+            startRecording = false;
+            memoryFull = false;
+            dpArray.i = 0;
+            
+            // reset array
+            for(int i = 0; i < dpArray.size; i++){
+                dpArray.dpR[i] = 0;
+                dpArray.dpL[i] = 0;
+            }
+            
+            bluetooth.printf("\r\nSystem has been Reset");
+            
         }
-        
-/******************************ROBOT FWD RVS***********************************/
+
+        /******************************ROBOT FWD RVS***********************************/
         // if w is pressed increase the speed
         // by incrementing u
-        else if(x == 'w') {
+        else if(x == 'w'&& (MC)) {
             mutexSetpoint.lock();
             Setpoint = -40;
             mutexSetpoint.unlock();
-        
+
         }
 
         // if s is pressed decrease the speed
         // by decrementing u
-        else if(x == 's') {
+        else if(x == 's' && (MC)) {
             mutexSetpoint.lock();
             Setpoint = 40;
             mutexSetpoint.unlock();
-        
+
         }
 
-/******************************ROBOT STEERING**********************************/        
-        else if (x=='a')
-        {
+        /******************************ROBOT STEERING**********************************/
+        else if (x=='a'&& (MC)) {
             mutexSetpoint.lock();
             SteeringError = 80;
             mutexSetpoint.unlock();
-        }
-        else if (x=='d')
-        {
+        } else if (x=='d'&& (MC)) {
             mutexSetpoint.lock();
             SteeringError = -80;
             mutexSetpoint.unlock();
-        }        
+        }
         // error wrong input
         else {
-            bluetooth.printf("\r\nwrong input please enter \'w\' to increase the speed, \'s\' to reduce it or move in the opposite direction and \'r\' to reset the watchdog");
+            //bluetooth.printf("\r\nwrong input please enter \'w\' to increase the speed, \'s\' to reduce it or move in the opposite direction and \'r\' to reset the watchdog");
         }
-    }
-    else{
-        // If no key is pressed stop the robot. 
+    } else {
+        // If no key is pressed stop the robot.
         Setpoint = 0;
         SteeringError = 0;
     }
     
+    if(memoryFull){
+        bluetooth.printf("\r\nmemory is full");
+    }
+
 }