Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Diff: Interface/Interface.cpp
- Revision:
- 28:3193157ebb0c
- Parent:
- 26:83550fc299aa
- Child:
- 29:f3b1387c81f1
--- a/Interface/Interface.cpp Fri Mar 01 21:57:59 2019 +0000 +++ b/Interface/Interface.cpp Mon Mar 11 14:19:26 2019 +0000 @@ -212,65 +212,53 @@ } } } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void INTERFACE::Start_Stop()//Start / Stop Routine { - if(_System_Running != 2) - { - _System_Running = !_System_Running; - } - //System not running cases (START) - printf("Function is: %d, System is: %d\n",_Function,_System_Running); + /* + System Running = 0 Stop + System Running = 1 Running + System Running = 2 Paused + */ - //System Running cases (Unpause) - if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused + printf("Function is: %d, System is: %d\n",_Function,_System_Running);//Used for debugging + + //Start Cases for when the system is stopped/////////////////////////////////////////////////////////////////////////////////// + if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected { - _Twist_Stop_mutex.lock(); - _Twist_Stop = false; - _Twist_Stop_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); _Twist_Go_mutex.lock(); _Twist_Go = true;//toggle used for coiling and twisting and Running the code _Twist_Go_mutex.unlock(); - STEPPER_MOTOR_1.Unpause_Code(); - - if(_Function == 2)//Coiling - { - printf("Coiling Code unpaused\n"); - } - if(_Function == 3)//Twisiting - { - printf("Twisting Code unpaused\n"); - } - _System_Running = 0; - } - else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused + else if (_Function == 0 & _System_Running == 0) //Annealing selected { - _Anneal_Stop_mutex.lock(); - _Anneal_Stop = false; - _Anneal_Stop_mutex.unlock(); - printf("Annealing Code unpaused\n"); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); _Anneal_Go_mutex.lock(); _Anneal_Go = true;//toggle and Run the code _Anneal_Go_mutex.unlock(); - _System_Running = 0; } - else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run + else if (_Function == 1 & _System_Running == 0) //Testing selected { - _Test_Stop_mutex.lock(); - _Test_Stop = false; - _Test_Stop_mutex.unlock(); - printf("Testing Code unpaused\n"); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is running + _System_Running_mutex.unlock(); + _Test_Go_mutex.lock(); _Test_Go = true;//toggle and run the code _Test_Go_mutex.unlock(); - _System_Running = 0; - } - //System Running cases (STOP) - else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be stopped + /////////////////////////////////////// + + //System Running cases run to pause the code + else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be paused { _Twist_Stop_mutex.lock(); _Twist_Stop = true; @@ -296,10 +284,10 @@ _Anneal_Stop_mutex.unlock(); printf("Annealing Code Paused\n"); _System_Running_mutex.lock(); - _System_Running = 2; + _System_Running = 2;//Pause code _System_Running_mutex.unlock(); } - else if (_Function == 1 & _System_Running == 1) //Testing selected to be stopped + else if (_Function == 1 & _System_Running == 1) //Testing selected to be paused { _Test_Stop_mutex.lock(); _Test_Stop = true; @@ -312,27 +300,62 @@ _Tendon_mutex.unlock(); _System_Running_mutex.lock(); - _System_Running = 2; + _System_Running = 2;//Pause code _System_Running_mutex.unlock(); } - //Start Cases - else if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected + + //////////////// + //System Paused cases run to unpause + else if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused { + _Twist_Stop_mutex.lock(); + _Twist_Stop = false; + _Twist_Stop_mutex.unlock(); + _Twist_Go_mutex.lock(); _Twist_Go = true;//toggle used for coiling and twisting and Running the code _Twist_Go_mutex.unlock(); + + STEPPER_MOTOR_1.Unpause_Code(); + + if(_Function == 2)//Coiling + { + printf("Coiling Code unpaused\n"); + } + if(_Function == 3)//Twisiting + { + printf("Twisting Code unpaused\n"); + } + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } - else if (_Function == 0 & _System_Running == 0) //Annealing selected + else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused { + _Anneal_Stop_mutex.lock(); + _Anneal_Stop = false; + _Anneal_Stop_mutex.unlock(); + printf("Annealing Code unpaused\n"); + _Anneal_Go_mutex.lock(); _Anneal_Go = true;//toggle and Run the code _Anneal_Go_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } - else if (_Function == 1 & _System_Running == 0) //Testing selected + else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run { + _Test_Stop_mutex.lock(); + _Test_Stop = false; + _Test_Stop_mutex.unlock(); + printf("Testing Code unpaused\n"); _Test_Go_mutex.lock(); _Test_Go = true;//toggle and run the code _Test_Go_mutex.unlock(); + _System_Running_mutex.lock(); + _System_Running = 1;//Code is unpaused + _System_Running_mutex.unlock(); } } void INTERFACE::Function()//Function Routine used to increment through the three functions @@ -463,7 +486,7 @@ } void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed { - if (_Function == 2 || _Function == 3) //Turning Code + if (_Function == 2 || _Function == 3) //Turning Code for coiling and twisting { if (_Twist_Go == true) {