![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Diff: Interface/Interface.cpp
- Revision:
- 25:9751619fa030
- Parent:
- 24:728de4bf961e
- Child:
- 26:83550fc299aa
--- a/Interface/Interface.cpp Mon Feb 18 12:02:34 2019 +0000 +++ b/Interface/Interface.cpp Mon Feb 18 22:04:54 2019 +0000 @@ -1,11 +1,7 @@ #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations //Constructor -INTERFACE::INTERFACE(int Default_Turns)//Set all values to 0 bar the turns to do which is passed through by the constructor being run -{ - _Turns_Todo_mutex.lock(); - _Turns_Todo = Default_Turns; - _Turns_Todo_mutex.unlock(); -} +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 @@ -19,7 +15,7 @@ Led_Select_Right_mutex.unlock(); _Function_mutex.lock(); - _Function =0; + _Function =2; _Function_mutex.unlock(); _Twist_Go_mutex.lock(); @@ -43,16 +39,27 @@ _Turns_Done_mutex.unlock(); _Turns_Todo_mutex.lock(); - _Turns_Todo =_Turns_Todo; + 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 =0; + _Loop =6; _Loop_mutex.unlock(); - _Wait_Time_mutex.lock(); - _Wait_Time =0; - _Wait_Time_mutex.unlock(); + _On_Time_mutex.lock(); + _On_Time =6; + _On_Time_mutex.unlock(); + + _Off_Time_mutex.lock(); + _Off_Time =6; + _Off_Time_mutex.unlock(); _Duty_Cycle_mutex.lock(); _Duty_Cycle =0; @@ -89,30 +96,40 @@ } void INTERFACE::Up()//Up Routine { - if (_Function == 0)//Turns Function + if (_Function == 2 || _Function == 3 )//Coiling or twist Function { _Turns_Todo_mutex.lock(); - _Turns_Todo = _Turns_Todo +1;//Increases Turn number + while(button_up.read() == 1) + { + _Turns_Todo = _Turns_Todo +1; + Thread::wait(100); + } _Turns_Todo_mutex.unlock(); } - else if (_Function == 1)//Annealing Function + else if (_Function == 0)//Annealing Function { - if (_Select == false)//Select = 0 + if (_Select == 0)//Select = 0 { _Loop_mutex.lock(); _Loop = _Loop + 1; //Increases Repetitions in Annealing _Loop_mutex.unlock(); } - else if (_Select == true)//Select = 1 + else if (_Select == 1)//Select = 1 { - _Wait_Time_mutex.lock(); - _Wait_Time = _Wait_Time + 1; //Increases Wait time - _Wait_Time_mutex.unlock(); + _On_Time_mutex.lock(); + _On_Time = _On_Time + 1; //Increases On time + _On_Time_mutex.unlock(); + } + else if (_Select == 2)//Select = 1 + { + _Off_Time_mutex.lock(); + _Off_Time = _On_Time + 1; //Increases Off time + _Off_Time_mutex.unlock(); } } - else if (_Function == 2)//Test Function + else if (_Function == 1)//Test Function { - if (_Select == false)//Select = 0 + if (_Select == 0)//Select = 0 { if (_Duty_Cycle < 100) { @@ -121,7 +138,7 @@ _Duty_Cycle_mutex.unlock(); } } - else if (_Select == true)//Select = 1 + else if (_Select == 1)//Select = 1 { _Power_Time_mutex.lock(); _Power_Time = _Power_Time + 1; //Increases time on @@ -131,15 +148,19 @@ } void INTERFACE::Down()//Down Routine { - if (_Function == 0)//Turn Function - { + if (_Function == 2 || _Function == 3)//Coiling or twist Function + { _Turns_Todo_mutex.lock(); - _Turns_Todo = _Turns_Todo -1;//Decrement Turn number + while(button_up.read() == 1) + { + _Turns_Todo = _Turns_Todo -1; + Thread::wait(100); + } _Turns_Todo_mutex.unlock(); } - else if (_Function == 1)//Anneal Function + else if (_Function == 0)//Anneal Function { - if (_Select == false)//Select = 0 + if (_Select == 0)//Select = 0 { if (_Loop > 0) @@ -149,19 +170,22 @@ _Loop_mutex.unlock(); } } - else if (_Select == true)//Select = 1 + else if (_Select == 1)//Select = 1 { - if (_Wait_Time > 0) - { - _Wait_Time_mutex.lock(); - _Wait_Time = _Wait_Time - 1; - _Wait_Time_mutex.unlock(); - } + _On_Time_mutex.lock(); + _On_Time = _On_Time - 1; //Decrease On time + _On_Time_mutex.unlock(); + } + else if (_Select == 2)//Select = 1 + { + _Off_Time_mutex.lock(); + _Off_Time = _On_Time - 1; //Decrements Off time + _Off_Time_mutex.unlock(); } } - else if (_Function == 2)//Test Function + else if (_Function == 1)//Test Function { - if (_Select == false)//Select = 0 + if (_Select == 0)//Select = 0 { if (_Duty_Cycle > 0) { @@ -170,7 +194,7 @@ _Duty_Cycle_mutex.unlock(); } } - else if (_Select == true)//Select = 1 + else if (_Select == 1)//Select = 1 { if (_Power_Time > 0) { @@ -193,9 +217,8 @@ printf("Function is: %d, System is: %d\n",_Function,_System_Running); //System Running cases (Unpause) - if (_Function == 0 & _System_Running == 2)//Twist selected to be unpasued + if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused { - printf("Twisting Code unpaused\n"); _Twist_Stop_mutex.lock(); _Twist_Stop = false; _Twist_Stop_mutex.unlock(); @@ -206,11 +229,18 @@ STEPPER_MOTOR_1.Unpause_Code(); - printf("Twisting Code unpaused\n"); + if(_Function == 2)//Coiling + { + printf("Coiling Code unpaused\n"); + } + if(_Function == 3)//Twisiting + { + printf("Twisting Code unpaused\n"); + } _System_Running = 0; } - else if (_Function == 1 & _System_Running == 2) //Annealing selected to be unpaused + else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused { _Anneal_Stop_mutex.lock(); _Anneal_Stop = false; @@ -222,7 +252,7 @@ _Anneal_Go_mutex.unlock(); _System_Running = 0; } - else if (_Function == 2 & _System_Running == 2) //Testing selected to be re run + else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run { _Test_Stop_mutex.lock(); _Test_Stop = false; @@ -235,18 +265,26 @@ } //System Running cases (STOP) - else if (_Function == 0 & _System_Running == 1)//Twist selected to be stopped + else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be stopped { _Twist_Stop_mutex.lock(); _Twist_Stop = true; _Twist_Stop_mutex.unlock(); - printf("Twisting Code Paused\n"); + + if(_Function == 2) + { + printf("Coiling Code Paused\n"); + } + if(_Function == 3) + { + printf("Twisting Code Paused\n"); + } _System_Running_mutex.lock(); _System_Running = 2; _System_Running_mutex.unlock(); STEPPER_MOTOR_1.Pause_Code(); } - else if (_Function == 1 & _System_Running == 1) //Annealing selected to be stopped + else if (_Function == 0 & _System_Running == 1) //Annealing selected to be stopped { _Anneal_Stop_mutex.lock(); _Anneal_Stop = true; @@ -256,7 +294,7 @@ _System_Running = 2; _System_Running_mutex.unlock(); } - else if (_Function == 2 & _System_Running == 1) //Testing selected to be stopped + else if (_Function == 1 & _System_Running == 1) //Testing selected to be stopped { _Test_Stop_mutex.lock(); _Test_Stop = true; @@ -273,19 +311,19 @@ _System_Running_mutex.unlock(); } //Start Cases - else if (_Function == 0 & _System_Running == 0)//Twist selected + else if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected { _Twist_Go_mutex.lock(); _Twist_Go = true;//toggle used for coiling and twisting and Running the code _Twist_Go_mutex.unlock(); } - else if (_Function == 1 & _System_Running == 0) //Annealing selected + else if (_Function == 0 & _System_Running == 0) //Annealing selected { _Anneal_Go_mutex.lock(); _Anneal_Go = true;//toggle and Run the code _Anneal_Go_mutex.unlock(); } - else if (_Function == 2 & _System_Running == 0) //Testing selected + else if (_Function == 1 & _System_Running == 0) //Testing selected { _Test_Go_mutex.lock(); _Test_Go = true;//toggle and run the code @@ -295,26 +333,68 @@ void INTERFACE::Function()//Function Routine used to increment through the three functions { /* - Function 0 = Turn - Function 1 = Anneal - Function 2 = Test + Function 0 = Anneal + Function 1 = Test + Function 2 = Coiling + Function 3 = Twisting */ - if (_Function < 2){ - _Function_mutex.lock(); - _Function = _Function + 1; - _Function_mutex.unlock(); + + if(Type_of_Rig == 2) + { + if(_Function < 2) + { + _Function_mutex.lock(); + _Function = _Function + 1; + _Function_mutex.unlock(); + } + else if(_Function == 2) + { + _Function_mutex.lock(); + _Function = 0; + _Function_mutex.unlock(); + } } - else + else if(Type_of_Rig == 3) { - _Function_mutex.lock(); - _Function = 0; - _Function_mutex.unlock(); + 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(); + } } } void INTERFACE::Select()//Select Routine { _Select_mutex.lock(); - _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible + if(_Select == 0 & _Function == !2)//All but anneal have 2 component menu's + { + _Select = 1; + } + else if(_Select == 1 & _Function == !2)//Toggle the value + { + _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; + } _Select_mutex.unlock(); if(_Function == 0) { @@ -322,7 +402,7 @@ Led_Select_Right = 1; Led_Select_Left_mutex.unlock(); } - else if(_Select == false) + else if(_Function == 1 & _Select == false) { Led_Select_Left_mutex.lock(); Led_Select_Left = 1; @@ -332,7 +412,7 @@ Led_Select_Right= 0; Led_Select_Right_mutex.unlock(); } - else + else if(_Function == 1 & _Select == true) { Led_Select_Left_mutex.lock(); Led_Select_Left = 0; @@ -342,11 +422,30 @@ Led_Select_Right= 1; Led_Select_Right_mutex.unlock(); } - //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led + 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(); + } } void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed { - if (_Function == 0) //Turning Code + if (_Function == 2 || _Function == 3) //Turning Code { if (_Twist_Go == true) { @@ -358,7 +457,7 @@ _System_Running = 1; _System_Running_mutex.unlock(); - STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo);//Rotates for the specified number of steps given + STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo,_Function);//Rotates for the specified number of steps given _System_Running_mutex.lock(); _System_Running = 0; @@ -374,7 +473,7 @@ Led_Power_mutex.unlock(); } } - else if (_Function == 1) //Annealing Code + else if (_Function == 0) //Annealing Code { if (_Anneal_Go == true) { @@ -393,9 +492,13 @@ _Tendon_mutex.lock(); Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare Tendon_Power=1; // set duty cycle to 100% - wait(_Wait_Time);//Variable + _On_Time_mutex.lock(); + wait(_On_Time);//Variable + _On_Time_mutex.unlock(); Tendon_Power=0; // set duty cycle to 0% - wait(6);//Fixed off time + _Off_Time_mutex.lock(); + wait(_Off_Time);//Fixed off time + _Off_Time_mutex.unlock(); _Tendon_mutex.unlock(); } while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused @@ -419,7 +522,7 @@ Led_Power_mutex.unlock(); } } - else if (_Function == 2) //Testing Code //This code is paused / unpaused in start / stop note this code is not paused it is re run. + else if (_Function == 1) //Testing Code //This code is paused / unpaused in start / stop note this code is not paused it is re run. { if (_Test_Go == true) { @@ -461,11 +564,12 @@ void INTERFACE::Set_Twist_Stop(bool Twist_Stop){_Twist_Stop_mutex.lock();_Twist_Stop = Twist_Stop;_Twist_Stop_mutex.unlock();} void INTERFACE::Set_Anneal_Stop(bool Anneal_Stop){_Anneal_Stop_mutex.lock();_Anneal_Stop = Anneal_Stop;_Anneal_Stop_mutex.unlock();} void INTERFACE::Set_Test_Stop(bool Test_Stop){_Test_Stop_mutex.lock();_Test_Go = Test_Stop;_Test_Stop_mutex.unlock();} -void INTERFACE::Set_Select(bool Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();} +void INTERFACE::Set_Select(int Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();} void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done_mutex.lock();_Turns_Done = Turns_Done;_Turns_Done_mutex.unlock();} void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo_mutex.lock();_Turns_Todo = Turns_Todo;_Turns_Todo_mutex.unlock();} void INTERFACE::Set_Loop(int Loop){_Loop_mutex.lock();Loop = Loop;_Loop_mutex.unlock();} -void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time_mutex.lock();_Wait_Time = Wait_Time;_Wait_Time_mutex.unlock();} +void INTERFACE::Set_On_Time(int On_Time){_On_Time_mutex.lock();_On_Time = On_Time;_On_Time_mutex.unlock();} +void INTERFACE::Set_Off_Time(int Off_Time){_Off_Time_mutex.lock();_Off_Time = Off_Time;_Off_Time_mutex.unlock();} void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle_mutex.lock();_Duty_Cycle = Duty_Cycle;_Duty_Cycle_mutex.unlock();} void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time_mutex.lock();_Power_Time = Power_Time;_Power_Time_mutex.unlock();} //Getter functions @@ -477,10 +581,11 @@ bool INTERFACE::Get_Twist_Stop(){return _Twist_Stop;} bool INTERFACE::Get_Anneal_Stop(){return _Anneal_Stop;} bool INTERFACE::Get_Test_Stop(){return _Test_Stop;} -bool INTERFACE::Get_Select(){return _Select;} +int INTERFACE::Get_Select(){return _Select;} int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;} int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} int INTERFACE::Get_Loop(){return _Loop;} -int INTERFACE::Get_Wait_Time(){return _Wait_Time;} +int INTERFACE::Get_On_Time(){return _On_Time;} +int INTERFACE::Get_Off_Time(){return _Off_Time;} int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} int INTERFACE::Get_Power_Time(){return _Power_Time;} \ No newline at end of file