Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos TextLCD
Revision 24:728de4bf961e, committed 2019-02-18
- Comitter:
- thomasmorris
- Date:
- Mon Feb 18 12:02:34 2019 +0000
- Parent:
- 23:07a368f2cdb1
- Child:
- 25:9751619fa030
- Commit message:
- Working Code(start + stop)
Changed in this revision
--- a/Interface/Interface.cpp Sat Feb 16 15:19:21 2019 +0000
+++ b/Interface/Interface.cpp Mon Feb 18 12:02:34 2019 +0000
@@ -10,6 +10,14 @@
//Interrupt run functions
void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns
{
+ Led_Select_Left_mutex.lock();
+ Led_Select_Left = 0;
+ Led_Select_Left_mutex.unlock();
+
+ Led_Select_Right_mutex.lock();
+ Led_Select_Right= 0;
+ Led_Select_Right_mutex.unlock();
+
_Function_mutex.lock();
_Function =0;
_Function_mutex.unlock();
@@ -69,6 +77,15 @@
_System_Running_mutex.lock();
_System_Running =0;
_System_Running_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();
}
void INTERFACE::Up()//Up Routine
{
@@ -103,12 +120,12 @@
_Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle
_Duty_Cycle_mutex.unlock();
}
- else if (_Select == true)//Select = 1
- {
- _Power_Time_mutex.lock();
- _Power_Time = _Power_Time + 1; //Increases time on
- _Power_Time_mutex.unlock();
- }
+ }
+ else if (_Select == true)//Select = 1
+ {
+ _Power_Time_mutex.lock();
+ _Power_Time = _Power_Time + 1; //Increases time on
+ _Power_Time_mutex.unlock();
}
}
}
@@ -131,14 +148,14 @@
_Loop = _Loop - 1;
_Loop_mutex.unlock();
}
- else if (_Select == true)//Select = 1
+ }
+ else if (_Select == true)//Select = 1
+ {
+ if (_Wait_Time > 0)
{
- if (_Wait_Time > 0)
- {
- _Wait_Time_mutex.lock();
- _Wait_Time = _Wait_Time - 1;
- _Wait_Time_mutex.unlock();
- }
+ _Wait_Time_mutex.lock();
+ _Wait_Time = _Wait_Time - 1;
+ _Wait_Time_mutex.unlock();
}
}
}
@@ -152,39 +169,70 @@
_Duty_Cycle = _Duty_Cycle - 10; //Decreases duty
_Duty_Cycle_mutex.unlock();
}
- else if (_Select == true)//Select = 1
+ }
+ else if (_Select == true)//Select = 1
+ {
+ if (_Power_Time > 0)
{
- if (_Power_Time > 0)
- {
- _Power_Time_mutex.lock();
- _Power_Time = _Power_Time - 1; //Decreases Time on
- _Power_Time_mutex.unlock();
- }
+ _Power_Time_mutex.lock();
+ _Power_Time = _Power_Time - 1; //Decreases Time on
+ _Power_Time_mutex.unlock();
}
}
+
}
}
void INTERFACE::Start_Stop()//Start / Stop Routine
{
- _System_Running = !_System_Running;
+
+ if(_System_Running != 2)
+ {
+ _System_Running = !_System_Running;
+ }
//System not running cases (START)
- if (_Function == 0 & _System_Running == 0)//Twist selected
+ 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
{
+ printf("Twisting Code unpaused\n");
+ _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();
+
+ printf("Twisting Code unpaused\n");
+ _System_Running = 0;
+
}
- else if (_Function == 1 & _System_Running == 0) //Annealing selected
+ else if (_Function == 1 & _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 = 0;
}
- else if (_Function == 2 & _System_Running == 0) //Testing selected
+ else if (_Function == 2 & _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 = 0;
+
}
//System Running cases (STOP)
else if (_Function == 0 & _System_Running == 1)//Twist selected to be stopped
@@ -213,7 +261,9 @@
_Test_Stop_mutex.lock();
_Test_Stop = true;
_Test_Stop_mutex.unlock();
+
printf("Testing Code Paused\n");
+
_Tendon_mutex.lock();
Tendon_Power=0;
_Tendon_mutex.unlock();
@@ -222,44 +272,24 @@
_System_Running = 2;
_System_Running_mutex.unlock();
}
- //System Running cases (Unpause)
- else if (_Function == 0 & _System_Running == 2)//Twist selected to be unpasued
+ //Start Cases
+ else if (_Function == 0 & _System_Running == 0)//Twist selected
{
- _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();
-
- printf("Twisting Code unpaused\n");
-
}
- else if (_Function == 1 & _System_Running == 2) //Annealing selected to be unpaused
+ else if (_Function == 1 & _System_Running == 0) //Annealing selected
{
- _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();
}
- else if (_Function == 2 & _System_Running == 2) //Testing selected to be re run
+ else if (_Function == 2 & _System_Running == 0) //Testing selected
{
- _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();
-
-
}
}
void INTERFACE::Function()//Function Routine used to increment through the three functions
--- a/SETUP.hpp Sat Feb 16 15:19:21 2019 +0000 +++ b/SETUP.hpp Mon Feb 18 12:02:34 2019 +0000 @@ -10,7 +10,7 @@ #include "STEPPER_MOTOR.hpp" #include "Interface.hpp" -#define Debounce_Time 50 +#define Debounce_Time 200 INTERFACE INTERFACE(20); //If the code compiles GET IN THE BIN //Interrupt In for the button control to the interface
--- a/main.cpp Sat Feb 16 15:19:21 2019 +0000
+++ b/main.cpp Mon Feb 18 12:02:34 2019 +0000
@@ -30,7 +30,7 @@
}else if(INTERFACE.Get_Function() == 2)//Test
{
lcd.printf("Mode: Test\n");
- lcd.printf("Duty: %d Time: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
+ lcd.printf("Duty: %dTime: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
}
Thread::wait(250);//Refresh rate for Lcd
}
@@ -121,9 +121,6 @@
button_funct.fall(&function_signal_fall);//Sets up Function Button
button_select.fall(&select_signal_fall); //Sets up Select Button
- //Output data to lcd prior to main code starting
-
- INTERFACE.Interface_Init();
lcd.printf("Ready Player\n");
lcd.printf(" One \n");
Thread::wait(1000);
@@ -139,7 +136,7 @@
select_thread.start(Selection_thread_function);//Start interface thread
osThreadSetPriority(osThreadGetId(), osPriorityHigh);//This is done to make sure the code for the stepper motor is the highest priority to ensure correct rotations of the stepper motor
-
+ INTERFACE.Interface_Init();
while(1)// Main code in a main thread
{
INTERFACE.Interface_main();//Run main thread code