Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Diff: Interface/Interface.cpp
- Revision:
- 26:83550fc299aa
- Parent:
- 25:9751619fa030
- Child:
- 28:3193157ebb0c
diff -r 9751619fa030 -r 83550fc299aa Interface/Interface.cpp --- a/Interface/Interface.cpp Mon Feb 18 22:04:54 2019 +0000 +++ b/Interface/Interface.cpp Tue Feb 19 14:40:01 2019 +0000 @@ -1,9 +1,7 @@ #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations //Constructor INTERFACE::INTERFACE(){}//Set all values to 0 - INTERFACE::~INTERFACE(){} //Destructor -//Interrupt run functions void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns { Led_Select_Left_mutex.lock(); @@ -15,7 +13,7 @@ Led_Select_Right_mutex.unlock(); _Function_mutex.lock(); - _Function =2; + _Function = Type_of_Rig; _Function_mutex.unlock(); _Twist_Go_mutex.lock(); @@ -38,17 +36,6 @@ _Turns_Done =0; _Turns_Done_mutex.unlock(); - _Turns_Todo_mutex.lock(); - if(Type_of_Rig == 2) - { - _Turns_Todo = Default_Coiling_Turns; - } - else if(Type_of_Rig == 3) - { - _Turns_Todo = Default_Twisting_Turns; - } - _Turns_Todo_mutex.unlock(); - _Loop_mutex.lock(); _Loop =6; _Loop_mutex.unlock(); @@ -86,50 +73,69 @@ _System_Running_mutex.unlock(); - Led_Select_Left_mutex.lock(); - Led_Select_Left = 0; - Led_Select_Left_mutex.unlock(); + Led_Select_Left_mutex.lock(); + Led_Select_Left = 0; + Led_Select_Left_mutex.unlock(); - Led_Select_Right_mutex.lock(); - Led_Select_Right= 1; - Led_Select_Right_mutex.unlock(); + Led_Select_Right_mutex.lock(); + Led_Select_Right= 1; + Led_Select_Right_mutex.unlock(); + + _Turns_Todo_mutex.lock(); + if(Type_of_Rig == 2) + { + _Turns_Todo = Default_Coiling_Turns; + } + else if(Type_of_Rig == 3) + { + _Turns_Todo = Default_Twisting_Turns; + } + _Turns_Todo_mutex.unlock(); } void INTERFACE::Up()//Up Routine { + printf("In up routine\n"); + printf("Function value is: %d\n",_Function); + printf("Select Value is :%d\n",_Select); if (_Function == 2 || _Function == 3 )//Coiling or twist Function { _Turns_Todo_mutex.lock(); - while(button_up.read() == 1) - { - _Turns_Todo = _Turns_Todo +1; - Thread::wait(100); - } + _Turns_Todo = _Turns_Todo +1; _Turns_Todo_mutex.unlock(); } else if (_Function == 0)//Annealing Function { if (_Select == 0)//Select = 0 { - _Loop_mutex.lock(); - _Loop = _Loop + 1; //Increases Repetitions in Annealing - _Loop_mutex.unlock(); + if(_On_Time > 0) + { + _On_Time_mutex.lock(); + _On_Time = _On_Time+ 1; //Increments On time + _On_Time_mutex.unlock(); + } } else if (_Select == 1)//Select = 1 { - _On_Time_mutex.lock(); - _On_Time = _On_Time + 1; //Increases On time - _On_Time_mutex.unlock(); + if(_Loop > 0) + { + _Loop_mutex.lock(); + _Loop = _Loop + 1; //Increments Repetitions in Annealing + _Loop_mutex.unlock(); + } } - else if (_Select == 2)//Select = 1 + else if (_Select == 2)//Select = 2 { - _Off_Time_mutex.lock(); - _Off_Time = _On_Time + 1; //Increases Off time - _Off_Time_mutex.unlock(); + if(_Off_Time > 0) + { + _Off_Time_mutex.lock(); + _Off_Time = _Off_Time + 1; //Increments Off time + _Off_Time_mutex.unlock(); + } } } else if (_Function == 1)//Test Function { - if (_Select == 0)//Select = 0 + if (_Select == 1)//Select = 1 { if (_Duty_Cycle < 100) { @@ -138,7 +144,7 @@ _Duty_Cycle_mutex.unlock(); } } - else if (_Select == 1)//Select = 1 + else if (_Select == 0)//Select = 0 { _Power_Time_mutex.lock(); _Power_Time = _Power_Time + 1; //Increases time on @@ -151,41 +157,42 @@ if (_Function == 2 || _Function == 3)//Coiling or twist Function { _Turns_Todo_mutex.lock(); - while(button_up.read() == 1) - { - _Turns_Todo = _Turns_Todo -1; - Thread::wait(100); - } + _Turns_Todo = _Turns_Todo -1; _Turns_Todo_mutex.unlock(); } - else if (_Function == 0)//Anneal Function + else if (_Function == 0)//Annealing Function { if (_Select == 0)//Select = 0 - { - - if (_Loop > 0) + { + if(_On_Time > 1) { - _Loop_mutex.lock(); - _Loop = _Loop - 1; - _Loop_mutex.unlock(); + _On_Time_mutex.lock(); + _On_Time = _On_Time - 1; //Decrements On time + _On_Time_mutex.unlock(); } } else if (_Select == 1)//Select = 1 { - _On_Time_mutex.lock(); - _On_Time = _On_Time - 1; //Decrease On time - _On_Time_mutex.unlock(); + if(_Loop > 1) + { + _Loop_mutex.lock(); + _Loop = _Loop - 1; //Decrements Repetitions in Annealing + _Loop_mutex.unlock(); + } } - else if (_Select == 2)//Select = 1 + else if (_Select == 2)//Select = 2 { - _Off_Time_mutex.lock(); - _Off_Time = _On_Time - 1; //Decrements Off time - _Off_Time_mutex.unlock(); + if(_Off_Time > 1) + { + _Off_Time_mutex.lock(); + _Off_Time = _Off_Time - 1; //Decrements Off time + _Off_Time_mutex.unlock(); + } } } else if (_Function == 1)//Test Function { - if (_Select == 0)//Select = 0 + if (_Select == 1)//Select = 1 { if (_Duty_Cycle > 0) { @@ -194,7 +201,7 @@ _Duty_Cycle_mutex.unlock(); } } - else if (_Select == 1)//Select = 1 + else if (_Select == 0)//Select = 0 { if (_Power_Time > 0) { @@ -203,12 +210,10 @@ _Power_Time_mutex.unlock(); } } - } } void INTERFACE::Start_Stop()//Start / Stop Routine { - if(_System_Running != 2) { _System_Running = !_System_Running; @@ -338,110 +343,123 @@ Function 2 = Coiling Function 3 = Twisting */ - + if(Type_of_Rig == 3) + { + if(_Function < 3) + { + if(_Function == 1)//Skip coiling + { + _Function_mutex.lock(); + _Function = _Function + 1; + _Function_mutex.unlock(); + } + _Function_mutex.lock(); + _Function = _Function + 1; + _Function_mutex.unlock(); + } + else if(_Function == 3) + { + _Function = 0; + } + } if(Type_of_Rig == 2) { if(_Function < 2) { _Function_mutex.lock(); - _Function = _Function + 1; - _Function_mutex.unlock(); + _Function = _Function + 1; + _Function_mutex.unlock(); } else if(_Function == 2) { - _Function_mutex.lock(); - _Function = 0; - _Function_mutex.unlock(); - } - } - else if(Type_of_Rig == 3) - { - if(_Function == 3) - { - _Function_mutex.lock(); - _Function = 0; - _Function_mutex.unlock(); - } - else if(_Function < 2) - { - _Function_mutex.lock(); - _Function = _Function + 1; - _Function_mutex.unlock(); - } - else if(_Function == 2) - { - _Function_mutex.lock(); - _Function = 3; - _Function_mutex.unlock(); + _Function = 0; } } } void INTERFACE::Select()//Select Routine { _Select_mutex.lock(); - if(_Select == 0 & _Function == !2)//All but anneal have 2 component menu's - { - _Select = 1; - } - else if(_Select == 1 & _Function == !2)//Toggle the value + if(_Function == 0)//Anneal { - _Select = 0; - } - else if(_Function == 1 & _Select < 2) - { - _Select = _Select + 1; - } - else if(_Select == 2 & _Function == 1)//Set select to 0 if the function is anneal, as anneal has 3 components in the menu - { - _Select = 0; + printf("Select Value is :%d\n",_Select); + if(_Select == 2) + { + _Select = 0; + } + else if(_Select == 1) + { + _Select = 2; + } + else if(_Select == 0) + { + _Select = 1; + } + if(_Select == 0 || _Select == 2) + { + Led_Select_Left_mutex.lock(); + Led_Select_Left = 0; + Led_Select_Left_mutex.unlock(); + + Led_Select_Right_mutex.lock(); + Led_Select_Right= 1; + Led_Select_Right_mutex.unlock(); + } + else if(_Select == 1) + { + Led_Select_Left_mutex.lock(); + Led_Select_Left = 1; + Led_Select_Left_mutex.unlock(); + + Led_Select_Right_mutex.lock(); + Led_Select_Right= 0; + Led_Select_Right_mutex.unlock(); + } + printf("Select Value is :%d\n",_Select); } - _Select_mutex.unlock(); - if(_Function == 0) - { - Led_Select_Left_mutex.lock(); - Led_Select_Right = 1; - Led_Select_Left_mutex.unlock(); - } - else if(_Function == 1 & _Select == false) + else if(_Function == 1)//Test { - Led_Select_Left_mutex.lock(); - Led_Select_Left = 1; - Led_Select_Left_mutex.unlock(); + if(_Select == 0) + { + _Select = 1; + } + else if(_Select == 1) + { + _Select = 0; + } - Led_Select_Right_mutex.lock(); - Led_Select_Right= 0; - Led_Select_Right_mutex.unlock(); + if(_Select == 0) + { + Led_Select_Left_mutex.lock(); + Led_Select_Left = 0; + Led_Select_Left_mutex.unlock(); + + Led_Select_Right_mutex.lock(); + Led_Select_Right= 1; + Led_Select_Right_mutex.unlock(); + } + else if(_Select ==1) + { + Led_Select_Left_mutex.lock(); + Led_Select_Left = 1; + Led_Select_Left_mutex.unlock(); + + Led_Select_Right_mutex.lock(); + Led_Select_Right= 0; + Led_Select_Right_mutex.unlock(); + } } - else if(_Function == 1 & _Select == true) + else if(_Function == 2 || _Function == 3) { + _Select = 0; Led_Select_Left_mutex.lock(); Led_Select_Left = 0; Led_Select_Left_mutex.unlock(); Led_Select_Right_mutex.lock(); Led_Select_Right= 1; - Led_Select_Right_mutex.unlock(); + Led_Select_Right_mutex.unlock(); } - else if(_Function == 2 & _Select == false) - { - Led_Select_Left_mutex.lock(); - Led_Select_Left = 1; - Led_Select_Left_mutex.unlock(); - - Led_Select_Right_mutex.lock(); - Led_Select_Right= 0; - Led_Select_Right_mutex.unlock(); - } - else if(_Function == 2 & _Select == true) - { - Led_Select_Left_mutex.lock(); - Led_Select_Left = 0; - Led_Select_Left_mutex.unlock(); - - Led_Select_Right_mutex.lock(); - Led_Select_Right= 1; - Led_Select_Right_mutex.unlock(); - } + _Select_mutex.unlock(); } void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed {