Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Mon Feb 18 12:02:34 2019 +0000
Revision:
24:728de4bf961e
Parent:
23:07a368f2cdb1
Child:
25:9751619fa030
Working Code(start + stop)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 23:07a368f2cdb1 1 #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations
thomasmorris 16:9f98ec0ededb 2 //Constructor
thomasmorris 23:07a368f2cdb1 3 INTERFACE::INTERFACE(int Default_Turns)//Set all values to 0 bar the turns to do which is passed through by the constructor being run
thomasmorris 16:9f98ec0ededb 4 {
thomasmorris 23:07a368f2cdb1 5 _Turns_Todo_mutex.lock();
thomasmorris 17:68b3fdabe4c5 6 _Turns_Todo = Default_Turns;
thomasmorris 23:07a368f2cdb1 7 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 8 }
thomasmorris 16:9f98ec0ededb 9 INTERFACE::~INTERFACE(){} //Destructor
thomasmorris 16:9f98ec0ededb 10 //Interrupt run functions
thomasmorris 17:68b3fdabe4c5 11 void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns
thomasmorris 16:9f98ec0ededb 12 {
thomasmorris 24:728de4bf961e 13 Led_Select_Left_mutex.lock();
thomasmorris 24:728de4bf961e 14 Led_Select_Left = 0;
thomasmorris 24:728de4bf961e 15 Led_Select_Left_mutex.unlock();
thomasmorris 24:728de4bf961e 16
thomasmorris 24:728de4bf961e 17 Led_Select_Right_mutex.lock();
thomasmorris 24:728de4bf961e 18 Led_Select_Right= 0;
thomasmorris 24:728de4bf961e 19 Led_Select_Right_mutex.unlock();
thomasmorris 24:728de4bf961e 20
thomasmorris 23:07a368f2cdb1 21 _Function_mutex.lock();
thomasmorris 17:68b3fdabe4c5 22 _Function =0;
thomasmorris 23:07a368f2cdb1 23 _Function_mutex.unlock();
thomasmorris 23:07a368f2cdb1 24
thomasmorris 23:07a368f2cdb1 25 _Twist_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 26 _Twist_Go =0;
thomasmorris 23:07a368f2cdb1 27 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 28
thomasmorris 23:07a368f2cdb1 29 _Anneal_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 30 _Anneal_Go =0;
thomasmorris 23:07a368f2cdb1 31 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 32
thomasmorris 23:07a368f2cdb1 33 _Test_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 34 _Test_Go =0;
thomasmorris 23:07a368f2cdb1 35 _Test_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 36
thomasmorris 23:07a368f2cdb1 37 _Select_mutex.lock();
thomasmorris 17:68b3fdabe4c5 38 _Select =0;
thomasmorris 23:07a368f2cdb1 39 _Select_mutex.unlock();
thomasmorris 23:07a368f2cdb1 40
thomasmorris 23:07a368f2cdb1 41 _Turns_Done_mutex.lock();
thomasmorris 17:68b3fdabe4c5 42 _Turns_Done =0;
thomasmorris 23:07a368f2cdb1 43 _Turns_Done_mutex.unlock();
thomasmorris 23:07a368f2cdb1 44
thomasmorris 23:07a368f2cdb1 45 _Turns_Todo_mutex.lock();
thomasmorris 23:07a368f2cdb1 46 _Turns_Todo =_Turns_Todo;
thomasmorris 23:07a368f2cdb1 47 _Turns_Todo_mutex.unlock();
thomasmorris 23:07a368f2cdb1 48
thomasmorris 23:07a368f2cdb1 49 _Loop_mutex.lock();
thomasmorris 17:68b3fdabe4c5 50 _Loop =0;
thomasmorris 23:07a368f2cdb1 51 _Loop_mutex.unlock();
thomasmorris 23:07a368f2cdb1 52
thomasmorris 23:07a368f2cdb1 53 _Wait_Time_mutex.lock();
thomasmorris 17:68b3fdabe4c5 54 _Wait_Time =0;
thomasmorris 23:07a368f2cdb1 55 _Wait_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 56
thomasmorris 23:07a368f2cdb1 57 _Duty_Cycle_mutex.lock();
thomasmorris 17:68b3fdabe4c5 58 _Duty_Cycle =0;
thomasmorris 23:07a368f2cdb1 59 _Duty_Cycle_mutex.unlock();
thomasmorris 23:07a368f2cdb1 60
thomasmorris 23:07a368f2cdb1 61 _Power_Time_mutex.lock();
thomasmorris 17:68b3fdabe4c5 62 _Power_Time =0;
thomasmorris 23:07a368f2cdb1 63 _Power_Time_mutex.unlock();
thomasmorris 23:07a368f2cdb1 64
thomasmorris 23:07a368f2cdb1 65 Led_Select_Left_mutex.lock();
thomasmorris 23:07a368f2cdb1 66 Led_Select_Left = 0;
thomasmorris 23:07a368f2cdb1 67 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 68
thomasmorris 23:07a368f2cdb1 69 Led_Select_Right_mutex.lock();
thomasmorris 23:07a368f2cdb1 70 Led_Select_Right= 0;
thomasmorris 23:07a368f2cdb1 71 Led_Select_Right_mutex.unlock();
thomasmorris 23:07a368f2cdb1 72
thomasmorris 23:07a368f2cdb1 73 Led_Power_mutex.lock();
thomasmorris 23:07a368f2cdb1 74 Led_Power =0;
thomasmorris 23:07a368f2cdb1 75 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 76
thomasmorris 23:07a368f2cdb1 77 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 78 _System_Running =0;
thomasmorris 23:07a368f2cdb1 79 _System_Running_mutex.unlock();
thomasmorris 24:728de4bf961e 80
thomasmorris 24:728de4bf961e 81
thomasmorris 24:728de4bf961e 82 Led_Select_Left_mutex.lock();
thomasmorris 24:728de4bf961e 83 Led_Select_Left = 0;
thomasmorris 24:728de4bf961e 84 Led_Select_Left_mutex.unlock();
thomasmorris 24:728de4bf961e 85
thomasmorris 24:728de4bf961e 86 Led_Select_Right_mutex.lock();
thomasmorris 24:728de4bf961e 87 Led_Select_Right= 1;
thomasmorris 24:728de4bf961e 88 Led_Select_Right_mutex.unlock();
thomasmorris 16:9f98ec0ededb 89 }
thomasmorris 17:68b3fdabe4c5 90 void INTERFACE::Up()//Up Routine
thomasmorris 16:9f98ec0ededb 91 {
thomasmorris 17:68b3fdabe4c5 92 if (_Function == 0)//Turns Function
thomasmorris 16:9f98ec0ededb 93 {
thomasmorris 23:07a368f2cdb1 94 _Turns_Todo_mutex.lock();
thomasmorris 23:07a368f2cdb1 95 _Turns_Todo = _Turns_Todo +1;//Increases Turn number
thomasmorris 23:07a368f2cdb1 96 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 97 }
thomasmorris 17:68b3fdabe4c5 98 else if (_Function == 1)//Annealing Function
thomasmorris 16:9f98ec0ededb 99 {
thomasmorris 17:68b3fdabe4c5 100 if (_Select == false)//Select = 0
thomasmorris 23:07a368f2cdb1 101 {
thomasmorris 23:07a368f2cdb1 102 _Loop_mutex.lock();
thomasmorris 16:9f98ec0ededb 103 _Loop = _Loop + 1; //Increases Repetitions in Annealing
thomasmorris 23:07a368f2cdb1 104 _Loop_mutex.unlock();
thomasmorris 16:9f98ec0ededb 105 }
thomasmorris 17:68b3fdabe4c5 106 else if (_Select == true)//Select = 1
thomasmorris 16:9f98ec0ededb 107 {
thomasmorris 23:07a368f2cdb1 108 _Wait_Time_mutex.lock();
thomasmorris 16:9f98ec0ededb 109 _Wait_Time = _Wait_Time + 1; //Increases Wait time
thomasmorris 23:07a368f2cdb1 110 _Wait_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 111 }
thomasmorris 16:9f98ec0ededb 112 }
thomasmorris 17:68b3fdabe4c5 113 else if (_Function == 2)//Test Function
thomasmorris 16:9f98ec0ededb 114 {
thomasmorris 17:68b3fdabe4c5 115 if (_Select == false)//Select = 0
thomasmorris 16:9f98ec0ededb 116 {
thomasmorris 16:9f98ec0ededb 117 if (_Duty_Cycle < 100)
thomasmorris 16:9f98ec0ededb 118 {
thomasmorris 23:07a368f2cdb1 119 _Duty_Cycle_mutex.lock();
thomasmorris 16:9f98ec0ededb 120 _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle
thomasmorris 23:07a368f2cdb1 121 _Duty_Cycle_mutex.unlock();
thomasmorris 16:9f98ec0ededb 122 }
thomasmorris 24:728de4bf961e 123 }
thomasmorris 24:728de4bf961e 124 else if (_Select == true)//Select = 1
thomasmorris 24:728de4bf961e 125 {
thomasmorris 24:728de4bf961e 126 _Power_Time_mutex.lock();
thomasmorris 24:728de4bf961e 127 _Power_Time = _Power_Time + 1; //Increases time on
thomasmorris 24:728de4bf961e 128 _Power_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 129 }
thomasmorris 16:9f98ec0ededb 130 }
thomasmorris 16:9f98ec0ededb 131 }
thomasmorris 17:68b3fdabe4c5 132 void INTERFACE::Down()//Down Routine
thomasmorris 16:9f98ec0ededb 133 {
thomasmorris 17:68b3fdabe4c5 134 if (_Function == 0)//Turn Function
thomasmorris 16:9f98ec0ededb 135 {
thomasmorris 23:07a368f2cdb1 136 _Turns_Todo_mutex.lock();
thomasmorris 23:07a368f2cdb1 137 _Turns_Todo = _Turns_Todo -1;//Decrement Turn number
thomasmorris 23:07a368f2cdb1 138 _Turns_Todo_mutex.unlock();
thomasmorris 16:9f98ec0ededb 139 }
thomasmorris 17:68b3fdabe4c5 140 else if (_Function == 1)//Anneal Function
thomasmorris 16:9f98ec0ededb 141 {
thomasmorris 17:68b3fdabe4c5 142 if (_Select == false)//Select = 0
thomasmorris 16:9f98ec0ededb 143 {
thomasmorris 21:6d9f6a986647 144
thomasmorris 16:9f98ec0ededb 145 if (_Loop > 0)
thomasmorris 16:9f98ec0ededb 146 {
thomasmorris 23:07a368f2cdb1 147 _Loop_mutex.lock();
thomasmorris 16:9f98ec0ededb 148 _Loop = _Loop - 1;
thomasmorris 23:07a368f2cdb1 149 _Loop_mutex.unlock();
thomasmorris 16:9f98ec0ededb 150 }
thomasmorris 24:728de4bf961e 151 }
thomasmorris 24:728de4bf961e 152 else if (_Select == true)//Select = 1
thomasmorris 24:728de4bf961e 153 {
thomasmorris 24:728de4bf961e 154 if (_Wait_Time > 0)
thomasmorris 16:9f98ec0ededb 155 {
thomasmorris 24:728de4bf961e 156 _Wait_Time_mutex.lock();
thomasmorris 24:728de4bf961e 157 _Wait_Time = _Wait_Time - 1;
thomasmorris 24:728de4bf961e 158 _Wait_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 159 }
thomasmorris 16:9f98ec0ededb 160 }
thomasmorris 16:9f98ec0ededb 161 }
thomasmorris 17:68b3fdabe4c5 162 else if (_Function == 2)//Test Function
thomasmorris 16:9f98ec0ededb 163 {
thomasmorris 17:68b3fdabe4c5 164 if (_Select == false)//Select = 0
thomasmorris 16:9f98ec0ededb 165 {
thomasmorris 16:9f98ec0ededb 166 if (_Duty_Cycle > 0)
thomasmorris 16:9f98ec0ededb 167 {
thomasmorris 23:07a368f2cdb1 168 _Duty_Cycle_mutex.lock();
thomasmorris 16:9f98ec0ededb 169 _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty
thomasmorris 23:07a368f2cdb1 170 _Duty_Cycle_mutex.unlock();
thomasmorris 16:9f98ec0ededb 171 }
thomasmorris 24:728de4bf961e 172 }
thomasmorris 24:728de4bf961e 173 else if (_Select == true)//Select = 1
thomasmorris 24:728de4bf961e 174 {
thomasmorris 24:728de4bf961e 175 if (_Power_Time > 0)
thomasmorris 16:9f98ec0ededb 176 {
thomasmorris 24:728de4bf961e 177 _Power_Time_mutex.lock();
thomasmorris 24:728de4bf961e 178 _Power_Time = _Power_Time - 1; //Decreases Time on
thomasmorris 24:728de4bf961e 179 _Power_Time_mutex.unlock();
thomasmorris 16:9f98ec0ededb 180 }
thomasmorris 16:9f98ec0ededb 181 }
thomasmorris 24:728de4bf961e 182
thomasmorris 16:9f98ec0ededb 183 }
thomasmorris 16:9f98ec0ededb 184 }
thomasmorris 17:68b3fdabe4c5 185 void INTERFACE::Start_Stop()//Start / Stop Routine
thomasmorris 16:9f98ec0ededb 186 {
thomasmorris 24:728de4bf961e 187
thomasmorris 24:728de4bf961e 188 if(_System_Running != 2)
thomasmorris 24:728de4bf961e 189 {
thomasmorris 24:728de4bf961e 190 _System_Running = !_System_Running;
thomasmorris 24:728de4bf961e 191 }
thomasmorris 23:07a368f2cdb1 192 //System not running cases (START)
thomasmorris 24:728de4bf961e 193 printf("Function is: %d, System is: %d\n",_Function,_System_Running);
thomasmorris 24:728de4bf961e 194
thomasmorris 24:728de4bf961e 195 //System Running cases (Unpause)
thomasmorris 24:728de4bf961e 196 if (_Function == 0 & _System_Running == 2)//Twist selected to be unpasued
thomasmorris 23:07a368f2cdb1 197 {
thomasmorris 24:728de4bf961e 198 printf("Twisting Code unpaused\n");
thomasmorris 24:728de4bf961e 199 _Twist_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 200 _Twist_Stop = false;
thomasmorris 24:728de4bf961e 201 _Twist_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 202
thomasmorris 23:07a368f2cdb1 203 _Twist_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 204 _Twist_Go = true;//toggle used for coiling and twisting and Running the code
thomasmorris 23:07a368f2cdb1 205 _Twist_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 206
thomasmorris 24:728de4bf961e 207 STEPPER_MOTOR_1.Unpause_Code();
thomasmorris 24:728de4bf961e 208
thomasmorris 24:728de4bf961e 209 printf("Twisting Code unpaused\n");
thomasmorris 24:728de4bf961e 210 _System_Running = 0;
thomasmorris 24:728de4bf961e 211
thomasmorris 23:07a368f2cdb1 212 }
thomasmorris 24:728de4bf961e 213 else if (_Function == 1 & _System_Running == 2) //Annealing selected to be unpaused
thomasmorris 23:07a368f2cdb1 214 {
thomasmorris 24:728de4bf961e 215 _Anneal_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 216 _Anneal_Stop = false;
thomasmorris 24:728de4bf961e 217 _Anneal_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 218 printf("Annealing Code unpaused\n");
thomasmorris 24:728de4bf961e 219
thomasmorris 23:07a368f2cdb1 220 _Anneal_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 221 _Anneal_Go = true;//toggle and Run the code
thomasmorris 23:07a368f2cdb1 222 _Anneal_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 223 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 224 }
thomasmorris 24:728de4bf961e 225 else if (_Function == 2 & _System_Running == 2) //Testing selected to be re run
thomasmorris 16:9f98ec0ededb 226 {
thomasmorris 24:728de4bf961e 227 _Test_Stop_mutex.lock();
thomasmorris 24:728de4bf961e 228 _Test_Stop = false;
thomasmorris 24:728de4bf961e 229 _Test_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 230 printf("Testing Code unpaused\n");
thomasmorris 23:07a368f2cdb1 231 _Test_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 232 _Test_Go = true;//toggle and run the code
thomasmorris 23:07a368f2cdb1 233 _Test_Go_mutex.unlock();
thomasmorris 24:728de4bf961e 234 _System_Running = 0;
thomasmorris 24:728de4bf961e 235
thomasmorris 16:9f98ec0ededb 236 }
thomasmorris 23:07a368f2cdb1 237 //System Running cases (STOP)
thomasmorris 23:07a368f2cdb1 238 else if (_Function == 0 & _System_Running == 1)//Twist selected to be stopped
thomasmorris 23:07a368f2cdb1 239 {
thomasmorris 23:07a368f2cdb1 240 _Twist_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 241 _Twist_Stop = true;
thomasmorris 23:07a368f2cdb1 242 _Twist_Stop_mutex.unlock();
thomasmorris 23:07a368f2cdb1 243 printf("Twisting Code Paused\n");
thomasmorris 23:07a368f2cdb1 244 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 245 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 246 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 247 STEPPER_MOTOR_1.Pause_Code();
thomasmorris 23:07a368f2cdb1 248 }
thomasmorris 23:07a368f2cdb1 249 else if (_Function == 1 & _System_Running == 1) //Annealing selected to be stopped
thomasmorris 23:07a368f2cdb1 250 {
thomasmorris 23:07a368f2cdb1 251 _Anneal_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 252 _Anneal_Stop = true;
thomasmorris 23:07a368f2cdb1 253 _Anneal_Stop_mutex.unlock();
thomasmorris 23:07a368f2cdb1 254 printf("Annealing Code Paused\n");
thomasmorris 23:07a368f2cdb1 255 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 256 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 257 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 258 }
thomasmorris 23:07a368f2cdb1 259 else if (_Function == 2 & _System_Running == 1) //Testing selected to be stopped
thomasmorris 16:9f98ec0ededb 260 {
thomasmorris 23:07a368f2cdb1 261 _Test_Stop_mutex.lock();
thomasmorris 23:07a368f2cdb1 262 _Test_Stop = true;
thomasmorris 23:07a368f2cdb1 263 _Test_Stop_mutex.unlock();
thomasmorris 24:728de4bf961e 264
thomasmorris 23:07a368f2cdb1 265 printf("Testing Code Paused\n");
thomasmorris 24:728de4bf961e 266
thomasmorris 23:07a368f2cdb1 267 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 268 Tendon_Power=0;
thomasmorris 23:07a368f2cdb1 269 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 270
thomasmorris 23:07a368f2cdb1 271 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 272 _System_Running = 2;
thomasmorris 23:07a368f2cdb1 273 _System_Running_mutex.unlock();
thomasmorris 16:9f98ec0ededb 274 }
thomasmorris 24:728de4bf961e 275 //Start Cases
thomasmorris 24:728de4bf961e 276 else if (_Function == 0 & _System_Running == 0)//Twist selected
thomasmorris 23:07a368f2cdb1 277 {
thomasmorris 23:07a368f2cdb1 278 _Twist_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 279 _Twist_Go = true;//toggle used for coiling and twisting and Running the code
thomasmorris 23:07a368f2cdb1 280 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 281 }
thomasmorris 24:728de4bf961e 282 else if (_Function == 1 & _System_Running == 0) //Annealing selected
thomasmorris 16:9f98ec0ededb 283 {
thomasmorris 23:07a368f2cdb1 284 _Anneal_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 285 _Anneal_Go = true;//toggle and Run the code
thomasmorris 23:07a368f2cdb1 286 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 287 }
thomasmorris 24:728de4bf961e 288 else if (_Function == 2 & _System_Running == 0) //Testing selected
thomasmorris 23:07a368f2cdb1 289 {
thomasmorris 23:07a368f2cdb1 290 _Test_Go_mutex.lock();
thomasmorris 23:07a368f2cdb1 291 _Test_Go = true;//toggle and run the code
thomasmorris 23:07a368f2cdb1 292 _Test_Go_mutex.unlock();
thomasmorris 16:9f98ec0ededb 293 }
thomasmorris 16:9f98ec0ededb 294 }
thomasmorris 17:68b3fdabe4c5 295 void INTERFACE::Function()//Function Routine used to increment through the three functions
thomasmorris 16:9f98ec0ededb 296 {
thomasmorris 17:68b3fdabe4c5 297 /*
thomasmorris 17:68b3fdabe4c5 298 Function 0 = Turn
thomasmorris 17:68b3fdabe4c5 299 Function 1 = Anneal
thomasmorris 17:68b3fdabe4c5 300 Function 2 = Test
thomasmorris 17:68b3fdabe4c5 301 */
thomasmorris 16:9f98ec0ededb 302 if (_Function < 2){
thomasmorris 23:07a368f2cdb1 303 _Function_mutex.lock();
thomasmorris 16:9f98ec0ededb 304 _Function = _Function + 1;
thomasmorris 23:07a368f2cdb1 305 _Function_mutex.unlock();
thomasmorris 16:9f98ec0ededb 306 }
thomasmorris 16:9f98ec0ededb 307 else
thomasmorris 16:9f98ec0ededb 308 {
thomasmorris 23:07a368f2cdb1 309 _Function_mutex.lock();
thomasmorris 16:9f98ec0ededb 310 _Function = 0;
thomasmorris 23:07a368f2cdb1 311 _Function_mutex.unlock();
thomasmorris 16:9f98ec0ededb 312 }
thomasmorris 16:9f98ec0ededb 313 }
thomasmorris 17:68b3fdabe4c5 314 void INTERFACE::Select()//Select Routine
thomasmorris 16:9f98ec0ededb 315 {
thomasmorris 23:07a368f2cdb1 316 _Select_mutex.lock();
thomasmorris 17:68b3fdabe4c5 317 _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible
thomasmorris 23:07a368f2cdb1 318 _Select_mutex.unlock();
thomasmorris 23:07a368f2cdb1 319 if(_Function == 0)
thomasmorris 21:6d9f6a986647 320 {
thomasmorris 23:07a368f2cdb1 321 Led_Select_Left_mutex.lock();
thomasmorris 23:07a368f2cdb1 322 Led_Select_Right = 1;
thomasmorris 23:07a368f2cdb1 323 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 324 }
thomasmorris 23:07a368f2cdb1 325 else if(_Select == false)
thomasmorris 23:07a368f2cdb1 326 {
thomasmorris 23:07a368f2cdb1 327 Led_Select_Left_mutex.lock();
thomasmorris 21:6d9f6a986647 328 Led_Select_Left = 1;
thomasmorris 23:07a368f2cdb1 329 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 330
thomasmorris 23:07a368f2cdb1 331 Led_Select_Right_mutex.lock();
thomasmorris 21:6d9f6a986647 332 Led_Select_Right= 0;
thomasmorris 23:07a368f2cdb1 333 Led_Select_Right_mutex.unlock();
thomasmorris 21:6d9f6a986647 334 }
thomasmorris 21:6d9f6a986647 335 else
thomasmorris 21:6d9f6a986647 336 {
thomasmorris 23:07a368f2cdb1 337 Led_Select_Left_mutex.lock();
thomasmorris 21:6d9f6a986647 338 Led_Select_Left = 0;
thomasmorris 23:07a368f2cdb1 339 Led_Select_Left_mutex.unlock();
thomasmorris 23:07a368f2cdb1 340
thomasmorris 23:07a368f2cdb1 341 Led_Select_Right_mutex.lock();
thomasmorris 21:6d9f6a986647 342 Led_Select_Right= 1;
thomasmorris 23:07a368f2cdb1 343 Led_Select_Right_mutex.unlock();
thomasmorris 21:6d9f6a986647 344 }
thomasmorris 17:68b3fdabe4c5 345 //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led
thomasmorris 16:9f98ec0ededb 346 }
thomasmorris 17:68b3fdabe4c5 347 void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed
thomasmorris 16:9f98ec0ededb 348 {
thomasmorris 16:9f98ec0ededb 349 if (_Function == 0) //Turning Code
thomasmorris 16:9f98ec0ededb 350 {
thomasmorris 16:9f98ec0ededb 351 if (_Twist_Go == true)
thomasmorris 16:9f98ec0ededb 352 {
thomasmorris 23:07a368f2cdb1 353 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 354 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 355 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 356
thomasmorris 23:07a368f2cdb1 357 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 358 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 359 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 360
thomasmorris 17:68b3fdabe4c5 361 STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo);//Rotates for the specified number of steps given
thomasmorris 23:07a368f2cdb1 362
thomasmorris 23:07a368f2cdb1 363 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 364 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 365 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 366
thomasmorris 23:07a368f2cdb1 367
thomasmorris 23:07a368f2cdb1 368 _Twist_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 369 _Twist_Go = false;
thomasmorris 23:07a368f2cdb1 370 _Twist_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 371
thomasmorris 23:07a368f2cdb1 372 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 373 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 374 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 375 }
thomasmorris 16:9f98ec0ededb 376 }
thomasmorris 16:9f98ec0ededb 377 else if (_Function == 1) //Annealing Code
thomasmorris 16:9f98ec0ededb 378 {
thomasmorris 16:9f98ec0ededb 379 if (_Anneal_Go == true)
thomasmorris 16:9f98ec0ededb 380 {
thomasmorris 23:07a368f2cdb1 381 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 382 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 383 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 384
thomasmorris 23:07a368f2cdb1 385 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 386 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 387 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 388
thomasmorris 16:9f98ec0ededb 389 for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works
thomasmorris 16:9f98ec0ededb 390 {
thomasmorris 23:07a368f2cdb1 391 if(_System_Running == 1)
thomasmorris 23:07a368f2cdb1 392 {
thomasmorris 23:07a368f2cdb1 393 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 394 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 23:07a368f2cdb1 395 Tendon_Power=1; // set duty cycle to 100%
thomasmorris 23:07a368f2cdb1 396 wait(_Wait_Time);//Variable
thomasmorris 23:07a368f2cdb1 397 Tendon_Power=0; // set duty cycle to 0%
thomasmorris 23:07a368f2cdb1 398 wait(6);//Fixed off time
thomasmorris 23:07a368f2cdb1 399 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 400 }
thomasmorris 23:07a368f2cdb1 401 while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused
thomasmorris 23:07a368f2cdb1 402 {
thomasmorris 23:07a368f2cdb1 403 _Tendon_mutex.lock();
thomasmorris 23:07a368f2cdb1 404 Tendon_Power =0;
thomasmorris 23:07a368f2cdb1 405 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 406 }
thomasmorris 16:9f98ec0ededb 407 }
thomasmorris 23:07a368f2cdb1 408
thomasmorris 23:07a368f2cdb1 409 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 410 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 411 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 412
thomasmorris 23:07a368f2cdb1 413 _Anneal_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 414 _Anneal_Go = false;
thomasmorris 23:07a368f2cdb1 415 _Anneal_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 416
thomasmorris 23:07a368f2cdb1 417 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 418 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 419 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 420 }
thomasmorris 16:9f98ec0ededb 421 }
thomasmorris 23:07a368f2cdb1 422 else if (_Function == 2) //Testing Code //This code is paused / unpaused in start / stop note this code is not paused it is re run.
thomasmorris 16:9f98ec0ededb 423 {
thomasmorris 16:9f98ec0ededb 424 if (_Test_Go == true)
thomasmorris 16:9f98ec0ededb 425 {
thomasmorris 23:07a368f2cdb1 426 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 427 Led_Power = 1;
thomasmorris 23:07a368f2cdb1 428 Led_Power_mutex.unlock();
thomasmorris 23:07a368f2cdb1 429
thomasmorris 23:07a368f2cdb1 430 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 431 _System_Running = 1;
thomasmorris 23:07a368f2cdb1 432 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 433
thomasmorris 23:07a368f2cdb1 434 _Tendon_mutex.lock();
thomasmorris 16:9f98ec0ededb 435 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 16:9f98ec0ededb 436 Tendon_Power= _Duty_Cycle / 100; // set duty cycle to variable input from buttons between 0-1 (on lcd this is a percentage) also increment by values of 10
thomasmorris 16:9f98ec0ededb 437 wait(_Power_Time);//Variable on time for power on
thomasmorris 16:9f98ec0ededb 438 Tendon_Power=0; // set duty cycle to 0% and power off
thomasmorris 23:07a368f2cdb1 439 _Tendon_mutex.unlock();
thomasmorris 23:07a368f2cdb1 440
thomasmorris 23:07a368f2cdb1 441 _System_Running_mutex.lock();
thomasmorris 23:07a368f2cdb1 442 _System_Running = 0;
thomasmorris 23:07a368f2cdb1 443 _System_Running_mutex.unlock();
thomasmorris 23:07a368f2cdb1 444
thomasmorris 23:07a368f2cdb1 445 _Test_Go_mutex.lock();
thomasmorris 17:68b3fdabe4c5 446 _Test_Go = false;
thomasmorris 23:07a368f2cdb1 447 _Test_Go_mutex.unlock();
thomasmorris 23:07a368f2cdb1 448
thomasmorris 23:07a368f2cdb1 449 Led_Power_mutex.lock();
thomasmorris 21:6d9f6a986647 450 Led_Power = 0;
thomasmorris 23:07a368f2cdb1 451 Led_Power_mutex.unlock();
thomasmorris 16:9f98ec0ededb 452 }
thomasmorris 16:9f98ec0ededb 453 }
thomasmorris 16:9f98ec0ededb 454 }
thomasmorris 17:68b3fdabe4c5 455 //Setter functions
thomasmorris 23:07a368f2cdb1 456 void INTERFACE::Set_System_Running(int System_Running){_System_Running_mutex.lock(); _System_Running = System_Running; _System_Running_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 457 void INTERFACE::Set_Function(int Function){_Function_mutex.lock();_Function = Function;_Function_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 458 void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go_mutex.lock();_Twist_Go = Twist_Go;_Twist_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 459 void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go_mutex.lock();_Anneal_Go = Anneal_Go;_Anneal_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 460 void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go_mutex.lock();_Test_Go = Test_Go;_Test_Go_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 461 void INTERFACE::Set_Twist_Stop(bool Twist_Stop){_Twist_Stop_mutex.lock();_Twist_Stop = Twist_Stop;_Twist_Stop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 462 void INTERFACE::Set_Anneal_Stop(bool Anneal_Stop){_Anneal_Stop_mutex.lock();_Anneal_Stop = Anneal_Stop;_Anneal_Stop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 463 void INTERFACE::Set_Test_Stop(bool Test_Stop){_Test_Stop_mutex.lock();_Test_Go = Test_Stop;_Test_Stop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 464 void INTERFACE::Set_Select(bool Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 465 void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done_mutex.lock();_Turns_Done = Turns_Done;_Turns_Done_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 466 void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo_mutex.lock();_Turns_Todo = Turns_Todo;_Turns_Todo_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 467 void INTERFACE::Set_Loop(int Loop){_Loop_mutex.lock();Loop = Loop;_Loop_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 468 void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time_mutex.lock();_Wait_Time = Wait_Time;_Wait_Time_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 469 void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle_mutex.lock();_Duty_Cycle = Duty_Cycle;_Duty_Cycle_mutex.unlock();}
thomasmorris 23:07a368f2cdb1 470 void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time_mutex.lock();_Power_Time = Power_Time;_Power_Time_mutex.unlock();}
thomasmorris 17:68b3fdabe4c5 471 //Getter functions
thomasmorris 23:07a368f2cdb1 472 int INTERFACE::Get_System_Running(){return _System_Running;}
thomasmorris 23:07a368f2cdb1 473 int INTERFACE::Get_Function(){return _Function;}
thomasmorris 16:9f98ec0ededb 474 bool INTERFACE::Get_Twist_Go(){return _Twist_Go;}
thomasmorris 16:9f98ec0ededb 475 bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;}
thomasmorris 16:9f98ec0ededb 476 bool INTERFACE::Get_Test_Go(){return _Test_Go;}
thomasmorris 23:07a368f2cdb1 477 bool INTERFACE::Get_Twist_Stop(){return _Twist_Stop;}
thomasmorris 23:07a368f2cdb1 478 bool INTERFACE::Get_Anneal_Stop(){return _Anneal_Stop;}
thomasmorris 23:07a368f2cdb1 479 bool INTERFACE::Get_Test_Stop(){return _Test_Stop;}
thomasmorris 16:9f98ec0ededb 480 bool INTERFACE::Get_Select(){return _Select;}
thomasmorris 18:3523660f3930 481 int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;}
thomasmorris 16:9f98ec0ededb 482 int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;}
thomasmorris 16:9f98ec0ededb 483 int INTERFACE::Get_Loop(){return _Loop;}
thomasmorris 16:9f98ec0ededb 484 int INTERFACE::Get_Wait_Time(){return _Wait_Time;}
thomasmorris 16:9f98ec0ededb 485 int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;}
thomasmorris 23:07a368f2cdb1 486 int INTERFACE::Get_Power_Time(){return _Power_Time;}