Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Interface/Interface.cpp@30:a35f0ab97a65, 2019-04-04 (annotated)
- Committer:
- thomasmorris
- Date:
- Thu Apr 04 10:52:22 2019 +0000
- Revision:
- 30:a35f0ab97a65
- Parent:
- 29:f3b1387c81f1
Testing 1;
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:9751619fa030 | 3 | INTERFACE::INTERFACE(){}//Set all values to 0 |
thomasmorris | 16:9f98ec0ededb | 4 | INTERFACE::~INTERFACE(){} //Destructor |
thomasmorris | 30:a35f0ab97a65 | 5 | void INTERFACE::Interface_Init(int turns)//Set all values to 0 bar the default turns |
thomasmorris | 16:9f98ec0ededb | 6 | { |
thomasmorris | 24:728de4bf961e | 7 | Led_Select_Left_mutex.lock(); |
thomasmorris | 24:728de4bf961e | 8 | Led_Select_Left = 0; |
thomasmorris | 24:728de4bf961e | 9 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 10 | |
thomasmorris | 24:728de4bf961e | 11 | Led_Select_Right_mutex.lock(); |
thomasmorris | 24:728de4bf961e | 12 | Led_Select_Right= 0; |
thomasmorris | 24:728de4bf961e | 13 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 14 | |
thomasmorris | 23:07a368f2cdb1 | 15 | _Twist_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 16 | _Twist_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 17 | _Twist_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 18 | |
thomasmorris | 23:07a368f2cdb1 | 19 | _Anneal_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 20 | _Anneal_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 21 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 22 | |
thomasmorris | 23:07a368f2cdb1 | 23 | _Test_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 24 | _Test_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 25 | _Test_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 26 | |
thomasmorris | 23:07a368f2cdb1 | 27 | _Select_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 28 | _Select =0; |
thomasmorris | 23:07a368f2cdb1 | 29 | _Select_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 30 | |
thomasmorris | 23:07a368f2cdb1 | 31 | _Turns_Done_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 32 | _Turns_Done =0; |
thomasmorris | 23:07a368f2cdb1 | 33 | _Turns_Done_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 34 | |
thomasmorris | 23:07a368f2cdb1 | 35 | _Loop_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 36 | _Loop =6; |
thomasmorris | 23:07a368f2cdb1 | 37 | _Loop_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 38 | |
thomasmorris | 30:a35f0ab97a65 | 39 | _Loops_done_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 40 | _Loops_done = 0; |
thomasmorris | 30:a35f0ab97a65 | 41 | _Loops_done_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 42 | |
thomasmorris | 25:9751619fa030 | 43 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 44 | _On_Time =4; |
thomasmorris | 25:9751619fa030 | 45 | _On_Time_mutex.unlock(); |
thomasmorris | 25:9751619fa030 | 46 | |
thomasmorris | 25:9751619fa030 | 47 | _Off_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 48 | _Off_Time =9; |
thomasmorris | 25:9751619fa030 | 49 | _Off_Time_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 50 | |
thomasmorris | 23:07a368f2cdb1 | 51 | _Duty_Cycle_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 52 | _Duty_Cycle =0; |
thomasmorris | 23:07a368f2cdb1 | 53 | _Duty_Cycle_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 54 | |
thomasmorris | 23:07a368f2cdb1 | 55 | _Power_Time_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 56 | _Power_Time =0; |
thomasmorris | 23:07a368f2cdb1 | 57 | _Power_Time_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 58 | |
thomasmorris | 23:07a368f2cdb1 | 59 | Led_Select_Left_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 60 | Led_Select_Left = 0; |
thomasmorris | 23:07a368f2cdb1 | 61 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 62 | |
thomasmorris | 23:07a368f2cdb1 | 63 | Led_Select_Right_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 64 | Led_Select_Right= 0; |
thomasmorris | 23:07a368f2cdb1 | 65 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 66 | |
thomasmorris | 23:07a368f2cdb1 | 67 | Led_Power_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 68 | Led_Power =0; |
thomasmorris | 23:07a368f2cdb1 | 69 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 70 | |
thomasmorris | 23:07a368f2cdb1 | 71 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 72 | _System_Running =0; |
thomasmorris | 23:07a368f2cdb1 | 73 | _System_Running_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 74 | |
thomasmorris | 24:728de4bf961e | 75 | |
thomasmorris | 26:83550fc299aa | 76 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 77 | Led_Select_Left = 0; |
thomasmorris | 26:83550fc299aa | 78 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 79 | |
thomasmorris | 26:83550fc299aa | 80 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 81 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 82 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 83 | |
thomasmorris | 26:83550fc299aa | 84 | _Turns_Todo_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 85 | _Turns_Todo = turns; |
thomasmorris | 29:f3b1387c81f1 | 86 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 87 | |
thomasmorris | 29:f3b1387c81f1 | 88 | |
thomasmorris | 29:f3b1387c81f1 | 89 | _Function_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 90 | _Function = 0; |
thomasmorris | 29:f3b1387c81f1 | 91 | _Function_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 92 | } |
thomasmorris | 30:a35f0ab97a65 | 93 | |
thomasmorris | 30:a35f0ab97a65 | 94 | void INTERFACE::Interface_Serial() |
thomasmorris | 30:a35f0ab97a65 | 95 | { |
thomasmorris | 30:a35f0ab97a65 | 96 | printf("Testing\n"); |
thomasmorris | 30:a35f0ab97a65 | 97 | Thread::wait(1000); |
thomasmorris | 30:a35f0ab97a65 | 98 | } |
thomasmorris | 17:68b3fdabe4c5 | 99 | void INTERFACE::Up()//Up Routine |
thomasmorris | 16:9f98ec0ededb | 100 | { |
thomasmorris | 30:a35f0ab97a65 | 101 | if (_Function == 2)//Coiling |
thomasmorris | 16:9f98ec0ededb | 102 | { |
thomasmorris | 29:f3b1387c81f1 | 103 | if(_Select == 0) |
thomasmorris | 29:f3b1387c81f1 | 104 | { |
thomasmorris | 29:f3b1387c81f1 | 105 | _Turns_Todo_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 106 | _Turns_Todo = _Turns_Todo +1; |
thomasmorris | 29:f3b1387c81f1 | 107 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 108 | } |
thomasmorris | 29:f3b1387c81f1 | 109 | else if(_Select == 1) |
thomasmorris | 29:f3b1387c81f1 | 110 | { |
thomasmorris | 29:f3b1387c81f1 | 111 | _Direction = !_Direction; |
thomasmorris | 29:f3b1387c81f1 | 112 | } |
thomasmorris | 16:9f98ec0ededb | 113 | } |
thomasmorris | 30:a35f0ab97a65 | 114 | else if (_Function == 3)//Run Once |
thomasmorris | 30:a35f0ab97a65 | 115 | { |
thomasmorris | 30:a35f0ab97a65 | 116 | if(_On_Time > 0) |
thomasmorris | 30:a35f0ab97a65 | 117 | { |
thomasmorris | 30:a35f0ab97a65 | 118 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 119 | _On_Time = _On_Time+ 0.5f; //Increments On time |
thomasmorris | 30:a35f0ab97a65 | 120 | _On_Time_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 121 | } |
thomasmorris | 30:a35f0ab97a65 | 122 | } |
thomasmorris | 25:9751619fa030 | 123 | else if (_Function == 0)//Annealing Function |
thomasmorris | 16:9f98ec0ededb | 124 | { |
thomasmorris | 25:9751619fa030 | 125 | if (_Select == 0)//Select = 0 |
thomasmorris | 23:07a368f2cdb1 | 126 | { |
thomasmorris | 26:83550fc299aa | 127 | if(_On_Time > 0) |
thomasmorris | 26:83550fc299aa | 128 | { |
thomasmorris | 26:83550fc299aa | 129 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 130 | _On_Time = _On_Time+ 0.5f; //Increments On time |
thomasmorris | 26:83550fc299aa | 131 | _On_Time_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 132 | } |
thomasmorris | 16:9f98ec0ededb | 133 | } |
thomasmorris | 25:9751619fa030 | 134 | else if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 135 | { |
thomasmorris | 26:83550fc299aa | 136 | if(_Loop > 0) |
thomasmorris | 26:83550fc299aa | 137 | { |
thomasmorris | 26:83550fc299aa | 138 | _Loop_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 139 | _Loop = _Loop + 1; //Increments Repetitions in Annealing |
thomasmorris | 26:83550fc299aa | 140 | _Loop_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 141 | } |
thomasmorris | 25:9751619fa030 | 142 | } |
thomasmorris | 26:83550fc299aa | 143 | else if (_Select == 2)//Select = 2 |
thomasmorris | 25:9751619fa030 | 144 | { |
thomasmorris | 26:83550fc299aa | 145 | if(_Off_Time > 0) |
thomasmorris | 26:83550fc299aa | 146 | { |
thomasmorris | 26:83550fc299aa | 147 | _Off_Time_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 148 | _Off_Time = _Off_Time + 1; //Increments Off time |
thomasmorris | 26:83550fc299aa | 149 | _Off_Time_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 150 | } |
thomasmorris | 16:9f98ec0ededb | 151 | } |
thomasmorris | 16:9f98ec0ededb | 152 | } |
thomasmorris | 25:9751619fa030 | 153 | else if (_Function == 1)//Test Function |
thomasmorris | 16:9f98ec0ededb | 154 | { |
thomasmorris | 26:83550fc299aa | 155 | if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 156 | { |
thomasmorris | 16:9f98ec0ededb | 157 | if (_Duty_Cycle < 100) |
thomasmorris | 16:9f98ec0ededb | 158 | { |
thomasmorris | 23:07a368f2cdb1 | 159 | _Duty_Cycle_mutex.lock(); |
thomasmorris | 16:9f98ec0ededb | 160 | _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle |
thomasmorris | 23:07a368f2cdb1 | 161 | _Duty_Cycle_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 162 | } |
thomasmorris | 24:728de4bf961e | 163 | } |
thomasmorris | 26:83550fc299aa | 164 | else if (_Select == 0)//Select = 0 |
thomasmorris | 24:728de4bf961e | 165 | { |
thomasmorris | 24:728de4bf961e | 166 | _Power_Time_mutex.lock(); |
thomasmorris | 24:728de4bf961e | 167 | _Power_Time = _Power_Time + 1; //Increases time on |
thomasmorris | 24:728de4bf961e | 168 | _Power_Time_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 169 | } |
thomasmorris | 16:9f98ec0ededb | 170 | } |
thomasmorris | 16:9f98ec0ededb | 171 | } |
thomasmorris | 29:f3b1387c81f1 | 172 | |
thomasmorris | 17:68b3fdabe4c5 | 173 | void INTERFACE::Down()//Down Routine |
thomasmorris | 16:9f98ec0ededb | 174 | { |
thomasmorris | 30:a35f0ab97a65 | 175 | if(_Function == 3)//Run Once |
thomasmorris | 30:a35f0ab97a65 | 176 | { |
thomasmorris | 30:a35f0ab97a65 | 177 | if(_On_Time > 0) |
thomasmorris | 30:a35f0ab97a65 | 178 | { |
thomasmorris | 30:a35f0ab97a65 | 179 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 180 | _On_Time = _On_Time - 0.5f; //Decrements On time |
thomasmorris | 30:a35f0ab97a65 | 181 | _On_Time_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 182 | } |
thomasmorris | 30:a35f0ab97a65 | 183 | } |
thomasmorris | 30:a35f0ab97a65 | 184 | else if (_Function == 2)//Coiling |
thomasmorris | 29:f3b1387c81f1 | 185 | { |
thomasmorris | 29:f3b1387c81f1 | 186 | if(_Select == 0) |
thomasmorris | 16:9f98ec0ededb | 187 | { |
thomasmorris | 29:f3b1387c81f1 | 188 | _Turns_Todo_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 189 | _Turns_Todo = _Turns_Todo -1; |
thomasmorris | 29:f3b1387c81f1 | 190 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 191 | } |
thomasmorris | 29:f3b1387c81f1 | 192 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 193 | { |
thomasmorris | 29:f3b1387c81f1 | 194 | _Direction = !_Direction; |
thomasmorris | 26:83550fc299aa | 195 | } |
thomasmorris | 25:9751619fa030 | 196 | } |
thomasmorris | 29:f3b1387c81f1 | 197 | else if (_Function == 0)//Annealing Function |
thomasmorris | 25:9751619fa030 | 198 | { |
thomasmorris | 29:f3b1387c81f1 | 199 | if (_Select == 0)//Select = 0 |
thomasmorris | 29:f3b1387c81f1 | 200 | { |
thomasmorris | 30:a35f0ab97a65 | 201 | if(_On_Time > 0) |
thomasmorris | 29:f3b1387c81f1 | 202 | { |
thomasmorris | 29:f3b1387c81f1 | 203 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 204 | _On_Time = _On_Time - 0.5f; //Decrements On time |
thomasmorris | 29:f3b1387c81f1 | 205 | _On_Time_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 206 | } |
thomasmorris | 29:f3b1387c81f1 | 207 | } |
thomasmorris | 29:f3b1387c81f1 | 208 | else if (_Select == 1)//Select = 1 |
thomasmorris | 26:83550fc299aa | 209 | { |
thomasmorris | 29:f3b1387c81f1 | 210 | if(_Loop > 1) |
thomasmorris | 29:f3b1387c81f1 | 211 | { |
thomasmorris | 29:f3b1387c81f1 | 212 | _Loop_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 213 | _Loop = _Loop - 1; //Decrements Repetitions in Annealing |
thomasmorris | 29:f3b1387c81f1 | 214 | _Loop_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 215 | } |
thomasmorris | 29:f3b1387c81f1 | 216 | } |
thomasmorris | 29:f3b1387c81f1 | 217 | else if (_Select == 2)//Select = 2 |
thomasmorris | 29:f3b1387c81f1 | 218 | { |
thomasmorris | 29:f3b1387c81f1 | 219 | if(_Off_Time > 1) |
thomasmorris | 29:f3b1387c81f1 | 220 | { |
thomasmorris | 29:f3b1387c81f1 | 221 | _Off_Time_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 222 | _Off_Time = _Off_Time - 1; //Decrements Off time |
thomasmorris | 29:f3b1387c81f1 | 223 | _Off_Time_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 224 | } |
thomasmorris | 26:83550fc299aa | 225 | } |
thomasmorris | 16:9f98ec0ededb | 226 | } |
thomasmorris | 29:f3b1387c81f1 | 227 | else if (_Function == 1)//Test Function |
thomasmorris | 29:f3b1387c81f1 | 228 | { |
thomasmorris | 29:f3b1387c81f1 | 229 | if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 230 | { |
thomasmorris | 29:f3b1387c81f1 | 231 | if (_Duty_Cycle > 0) |
thomasmorris | 29:f3b1387c81f1 | 232 | { |
thomasmorris | 29:f3b1387c81f1 | 233 | _Duty_Cycle_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 234 | _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty |
thomasmorris | 29:f3b1387c81f1 | 235 | _Duty_Cycle_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 236 | } |
thomasmorris | 29:f3b1387c81f1 | 237 | } |
thomasmorris | 29:f3b1387c81f1 | 238 | else if (_Select == 0)//Select = 0 |
thomasmorris | 29:f3b1387c81f1 | 239 | { |
thomasmorris | 29:f3b1387c81f1 | 240 | if (_Power_Time > 0) |
thomasmorris | 29:f3b1387c81f1 | 241 | { |
thomasmorris | 29:f3b1387c81f1 | 242 | _Power_Time_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 243 | _Power_Time = _Power_Time - 1; //Decreases Time on |
thomasmorris | 29:f3b1387c81f1 | 244 | _Power_Time_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 245 | } |
thomasmorris | 16:9f98ec0ededb | 246 | } |
thomasmorris | 24:728de4bf961e | 247 | } |
thomasmorris | 16:9f98ec0ededb | 248 | } |
thomasmorris | 28:3193157ebb0c | 249 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
thomasmorris | 17:68b3fdabe4c5 | 250 | void INTERFACE::Start_Stop()//Start / Stop Routine |
thomasmorris | 16:9f98ec0ededb | 251 | { |
thomasmorris | 28:3193157ebb0c | 252 | /* |
thomasmorris | 28:3193157ebb0c | 253 | System Running = 0 Stop |
thomasmorris | 28:3193157ebb0c | 254 | System Running = 1 Running |
thomasmorris | 28:3193157ebb0c | 255 | System Running = 2 Paused |
thomasmorris | 28:3193157ebb0c | 256 | */ |
thomasmorris | 24:728de4bf961e | 257 | |
thomasmorris | 28:3193157ebb0c | 258 | printf("Function is: %d, System is: %d\n",_Function,_System_Running);//Used for debugging |
thomasmorris | 28:3193157ebb0c | 259 | |
thomasmorris | 28:3193157ebb0c | 260 | //Start Cases for when the system is stopped/////////////////////////////////////////////////////////////////////////////////// |
thomasmorris | 30:a35f0ab97a65 | 261 | if((_Function == 3) & _System_Running == 0)//Run Once selected |
thomasmorris | 30:a35f0ab97a65 | 262 | { |
thomasmorris | 30:a35f0ab97a65 | 263 | _System_Running_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 264 | _System_Running = 1;//Code is running |
thomasmorris | 30:a35f0ab97a65 | 265 | _System_Running_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 266 | |
thomasmorris | 30:a35f0ab97a65 | 267 | _Run_Go_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 268 | _Run_Go = true;//Run the run once code |
thomasmorris | 30:a35f0ab97a65 | 269 | _Run_Go_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 270 | } |
thomasmorris | 30:a35f0ab97a65 | 271 | |
thomasmorris | 30:a35f0ab97a65 | 272 | else if ((_Function == 2) & _System_Running == 0)//Coiling selected |
thomasmorris | 23:07a368f2cdb1 | 273 | { |
thomasmorris | 28:3193157ebb0c | 274 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 275 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 276 | _System_Running_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 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 | 24:728de4bf961e | 281 | |
thomasmorris | 23:07a368f2cdb1 | 282 | } |
thomasmorris | 28:3193157ebb0c | 283 | else if (_Function == 0 & _System_Running == 0) //Annealing selected |
thomasmorris | 23:07a368f2cdb1 | 284 | { |
thomasmorris | 28:3193157ebb0c | 285 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 286 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 287 | _System_Running_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 288 | |
thomasmorris | 23:07a368f2cdb1 | 289 | _Anneal_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 290 | _Anneal_Go = true;//toggle and Run the code |
thomasmorris | 23:07a368f2cdb1 | 291 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 292 | |
thomasmorris | 30:a35f0ab97a65 | 293 | _Loops_done_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 294 | _Loops_done = 0; |
thomasmorris | 30:a35f0ab97a65 | 295 | _Loops_done_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 296 | } |
thomasmorris | 28:3193157ebb0c | 297 | else if (_Function == 1 & _System_Running == 0) //Testing selected |
thomasmorris | 16:9f98ec0ededb | 298 | { |
thomasmorris | 28:3193157ebb0c | 299 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 300 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 301 | _System_Running_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 302 | |
thomasmorris | 23:07a368f2cdb1 | 303 | _Test_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 304 | _Test_Go = true;//toggle and run the code |
thomasmorris | 23:07a368f2cdb1 | 305 | _Test_Go_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 306 | } |
thomasmorris | 28:3193157ebb0c | 307 | /////////////////////////////////////// |
thomasmorris | 28:3193157ebb0c | 308 | |
thomasmorris | 28:3193157ebb0c | 309 | //System Running cases run to pause the code |
thomasmorris | 30:a35f0ab97a65 | 310 | else if((_Function == 3) & _System_Running == 1)//Run once code |
thomasmorris | 30:a35f0ab97a65 | 311 | { |
thomasmorris | 30:a35f0ab97a65 | 312 | _Run_Stop_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 313 | _Run_Stop = true; |
thomasmorris | 30:a35f0ab97a65 | 314 | _Run_Stop_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 315 | _System_Running_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 316 | _System_Running = 2; |
thomasmorris | 30:a35f0ab97a65 | 317 | _System_Running_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 318 | } |
thomasmorris | 30:a35f0ab97a65 | 319 | else if ((_Function == 2) & _System_Running == 1)//Coiling |
thomasmorris | 23:07a368f2cdb1 | 320 | { |
thomasmorris | 23:07a368f2cdb1 | 321 | _Twist_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 322 | _Twist_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 323 | _Twist_Stop_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 324 | |
thomasmorris | 30:a35f0ab97a65 | 325 | printf("Coiling Code Paused\n"); |
thomasmorris | 23:07a368f2cdb1 | 326 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 327 | _System_Running = 2; |
thomasmorris | 23:07a368f2cdb1 | 328 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 329 | STEPPER_MOTOR_1.Pause_Code(); |
thomasmorris | 23:07a368f2cdb1 | 330 | } |
thomasmorris | 25:9751619fa030 | 331 | else if (_Function == 0 & _System_Running == 1) //Annealing selected to be stopped |
thomasmorris | 23:07a368f2cdb1 | 332 | { |
thomasmorris | 23:07a368f2cdb1 | 333 | _Anneal_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 334 | _Anneal_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 335 | _Anneal_Stop_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 336 | printf("Annealing Code Paused\n"); |
thomasmorris | 23:07a368f2cdb1 | 337 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 338 | _System_Running = 2;//Pause code |
thomasmorris | 23:07a368f2cdb1 | 339 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 340 | } |
thomasmorris | 28:3193157ebb0c | 341 | else if (_Function == 1 & _System_Running == 1) //Testing selected to be paused |
thomasmorris | 16:9f98ec0ededb | 342 | { |
thomasmorris | 23:07a368f2cdb1 | 343 | _Test_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 344 | _Test_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 345 | _Test_Stop_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 346 | |
thomasmorris | 23:07a368f2cdb1 | 347 | printf("Testing Code Paused\n"); |
thomasmorris | 24:728de4bf961e | 348 | |
thomasmorris | 30:a35f0ab97a65 | 349 | |
thomasmorris | 23:07a368f2cdb1 | 350 | |
thomasmorris | 23:07a368f2cdb1 | 351 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 352 | _System_Running = 2;//Pause code |
thomasmorris | 23:07a368f2cdb1 | 353 | _System_Running_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 354 | } |
thomasmorris | 28:3193157ebb0c | 355 | |
thomasmorris | 28:3193157ebb0c | 356 | //////////////// |
thomasmorris | 28:3193157ebb0c | 357 | //System Paused cases run to unpause |
thomasmorris | 30:a35f0ab97a65 | 358 | else if ((_Function == 3) & _System_Running ==2) |
thomasmorris | 30:a35f0ab97a65 | 359 | { |
thomasmorris | 30:a35f0ab97a65 | 360 | _Run_Stop_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 361 | _Run_Stop = false; |
thomasmorris | 30:a35f0ab97a65 | 362 | _Run_Stop_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 363 | |
thomasmorris | 30:a35f0ab97a65 | 364 | _Run_Go_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 365 | _Run_Go = true;//toggle used for coiling and twisting and Running the code |
thomasmorris | 30:a35f0ab97a65 | 366 | _Run_Go_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 367 | |
thomasmorris | 30:a35f0ab97a65 | 368 | |
thomasmorris | 30:a35f0ab97a65 | 369 | _System_Running_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 370 | _System_Running = 1;//Code is unpaused |
thomasmorris | 30:a35f0ab97a65 | 371 | _System_Running_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 372 | |
thomasmorris | 30:a35f0ab97a65 | 373 | } |
thomasmorris | 30:a35f0ab97a65 | 374 | else if ((_Function == 2) & _System_Running == 2)//Coil to be unpaused |
thomasmorris | 23:07a368f2cdb1 | 375 | { |
thomasmorris | 28:3193157ebb0c | 376 | _Twist_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 377 | _Twist_Stop = false; |
thomasmorris | 28:3193157ebb0c | 378 | _Twist_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 379 | |
thomasmorris | 23:07a368f2cdb1 | 380 | _Twist_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 381 | _Twist_Go = true;//toggle used for coiling and twisting and Running the code |
thomasmorris | 23:07a368f2cdb1 | 382 | _Twist_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 383 | |
thomasmorris | 28:3193157ebb0c | 384 | STEPPER_MOTOR_1.Unpause_Code(); |
thomasmorris | 28:3193157ebb0c | 385 | |
thomasmorris | 30:a35f0ab97a65 | 386 | |
thomasmorris | 30:a35f0ab97a65 | 387 | printf("Coiling Code unpaused\n"); |
thomasmorris | 30:a35f0ab97a65 | 388 | |
thomasmorris | 28:3193157ebb0c | 389 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 390 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 391 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 392 | } |
thomasmorris | 28:3193157ebb0c | 393 | else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused |
thomasmorris | 16:9f98ec0ededb | 394 | { |
thomasmorris | 28:3193157ebb0c | 395 | _Anneal_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 396 | _Anneal_Stop = false; |
thomasmorris | 28:3193157ebb0c | 397 | _Anneal_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 398 | printf("Annealing Code unpaused\n"); |
thomasmorris | 28:3193157ebb0c | 399 | |
thomasmorris | 23:07a368f2cdb1 | 400 | _Anneal_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 401 | _Anneal_Go = true;//toggle and Run the code |
thomasmorris | 23:07a368f2cdb1 | 402 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 403 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 404 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 405 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 406 | } |
thomasmorris | 28:3193157ebb0c | 407 | else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run |
thomasmorris | 23:07a368f2cdb1 | 408 | { |
thomasmorris | 28:3193157ebb0c | 409 | _Test_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 410 | _Test_Stop = false; |
thomasmorris | 28:3193157ebb0c | 411 | _Test_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 412 | printf("Testing Code unpaused\n"); |
thomasmorris | 23:07a368f2cdb1 | 413 | _Test_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 414 | _Test_Go = true;//toggle and run the code |
thomasmorris | 23:07a368f2cdb1 | 415 | _Test_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 416 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 417 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 418 | _System_Running_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 419 | } |
thomasmorris | 16:9f98ec0ededb | 420 | } |
thomasmorris | 17:68b3fdabe4c5 | 421 | void INTERFACE::Function()//Function Routine used to increment through the three functions |
thomasmorris | 16:9f98ec0ededb | 422 | { |
thomasmorris | 17:68b3fdabe4c5 | 423 | /* |
thomasmorris | 25:9751619fa030 | 424 | Function 0 = Anneal |
thomasmorris | 25:9751619fa030 | 425 | Function 1 = Test |
thomasmorris | 25:9751619fa030 | 426 | Function 2 = Coiling |
thomasmorris | 30:a35f0ab97a65 | 427 | Function 3 = Run Once |
thomasmorris | 17:68b3fdabe4c5 | 428 | */ |
thomasmorris | 30:a35f0ab97a65 | 429 | _Select_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 430 | _Select = 0;//Set the select value to 0 whenever the function is changed |
thomasmorris | 30:a35f0ab97a65 | 431 | _Select_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 432 | |
thomasmorris | 30:a35f0ab97a65 | 433 | if(_Function < 3) |
thomasmorris | 25:9751619fa030 | 434 | { |
thomasmorris | 30:a35f0ab97a65 | 435 | _Function_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 436 | _Function = _Function + 1; |
thomasmorris | 30:a35f0ab97a65 | 437 | _Function_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 438 | } |
thomasmorris | 30:a35f0ab97a65 | 439 | else if(_Function == 3) |
thomasmorris | 30:a35f0ab97a65 | 440 | { |
thomasmorris | 30:a35f0ab97a65 | 441 | _Function = 0; |
thomasmorris | 16:9f98ec0ededb | 442 | } |
thomasmorris | 16:9f98ec0ededb | 443 | } |
thomasmorris | 17:68b3fdabe4c5 | 444 | void INTERFACE::Select()//Select Routine |
thomasmorris | 16:9f98ec0ededb | 445 | { |
thomasmorris | 23:07a368f2cdb1 | 446 | _Select_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 447 | if(_Function == 0)//Anneal |
thomasmorris | 25:9751619fa030 | 448 | { |
thomasmorris | 26:83550fc299aa | 449 | printf("Select Value is :%d\n",_Select); |
thomasmorris | 26:83550fc299aa | 450 | if(_Select == 2) |
thomasmorris | 26:83550fc299aa | 451 | { |
thomasmorris | 26:83550fc299aa | 452 | _Select = 0; |
thomasmorris | 26:83550fc299aa | 453 | } |
thomasmorris | 26:83550fc299aa | 454 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 455 | { |
thomasmorris | 26:83550fc299aa | 456 | _Select = 2; |
thomasmorris | 26:83550fc299aa | 457 | } |
thomasmorris | 26:83550fc299aa | 458 | else if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 459 | { |
thomasmorris | 26:83550fc299aa | 460 | _Select = 1; |
thomasmorris | 26:83550fc299aa | 461 | } |
thomasmorris | 26:83550fc299aa | 462 | if(_Select == 0 || _Select == 2) |
thomasmorris | 26:83550fc299aa | 463 | { |
thomasmorris | 26:83550fc299aa | 464 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 465 | Led_Select_Left = 0; |
thomasmorris | 26:83550fc299aa | 466 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 467 | |
thomasmorris | 26:83550fc299aa | 468 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 469 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 470 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 471 | } |
thomasmorris | 26:83550fc299aa | 472 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 473 | { |
thomasmorris | 26:83550fc299aa | 474 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 475 | Led_Select_Left = 1; |
thomasmorris | 26:83550fc299aa | 476 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 477 | |
thomasmorris | 26:83550fc299aa | 478 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 479 | Led_Select_Right= 0; |
thomasmorris | 26:83550fc299aa | 480 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 481 | } |
thomasmorris | 26:83550fc299aa | 482 | printf("Select Value is :%d\n",_Select); |
thomasmorris | 25:9751619fa030 | 483 | } |
thomasmorris | 26:83550fc299aa | 484 | else if(_Function == 1)//Test |
thomasmorris | 23:07a368f2cdb1 | 485 | { |
thomasmorris | 26:83550fc299aa | 486 | if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 487 | { |
thomasmorris | 26:83550fc299aa | 488 | _Select = 1; |
thomasmorris | 26:83550fc299aa | 489 | } |
thomasmorris | 26:83550fc299aa | 490 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 491 | { |
thomasmorris | 26:83550fc299aa | 492 | _Select = 0; |
thomasmorris | 26:83550fc299aa | 493 | } |
thomasmorris | 23:07a368f2cdb1 | 494 | |
thomasmorris | 26:83550fc299aa | 495 | if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 496 | { |
thomasmorris | 26:83550fc299aa | 497 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 498 | Led_Select_Left = 0; |
thomasmorris | 26:83550fc299aa | 499 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 500 | |
thomasmorris | 26:83550fc299aa | 501 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 502 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 503 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 504 | } |
thomasmorris | 26:83550fc299aa | 505 | else if(_Select ==1) |
thomasmorris | 26:83550fc299aa | 506 | { |
thomasmorris | 26:83550fc299aa | 507 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 508 | Led_Select_Left = 1; |
thomasmorris | 26:83550fc299aa | 509 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 510 | |
thomasmorris | 26:83550fc299aa | 511 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 512 | Led_Select_Right= 0; |
thomasmorris | 26:83550fc299aa | 513 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 514 | } |
thomasmorris | 21:6d9f6a986647 | 515 | } |
thomasmorris | 30:a35f0ab97a65 | 516 | else if(_Function == 2 )//Coiling |
thomasmorris | 21:6d9f6a986647 | 517 | { |
thomasmorris | 29:f3b1387c81f1 | 518 | if(_Select == 0)//Toggle code for select |
thomasmorris | 29:f3b1387c81f1 | 519 | { |
thomasmorris | 29:f3b1387c81f1 | 520 | _Select = 1; |
thomasmorris | 29:f3b1387c81f1 | 521 | } |
thomasmorris | 29:f3b1387c81f1 | 522 | else if(_Select == 1) |
thomasmorris | 29:f3b1387c81f1 | 523 | { |
thomasmorris | 29:f3b1387c81f1 | 524 | _Select = 0; |
thomasmorris | 29:f3b1387c81f1 | 525 | } |
thomasmorris | 23:07a368f2cdb1 | 526 | |
thomasmorris | 29:f3b1387c81f1 | 527 | if(_Select == 0) |
thomasmorris | 29:f3b1387c81f1 | 528 | { |
thomasmorris | 29:f3b1387c81f1 | 529 | Led_Select_Left_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 530 | Led_Select_Left = 0; |
thomasmorris | 29:f3b1387c81f1 | 531 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 532 | |
thomasmorris | 29:f3b1387c81f1 | 533 | Led_Select_Right_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 534 | Led_Select_Right= 1; |
thomasmorris | 29:f3b1387c81f1 | 535 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 536 | } |
thomasmorris | 29:f3b1387c81f1 | 537 | else if(_Select == 1) |
thomasmorris | 29:f3b1387c81f1 | 538 | { |
thomasmorris | 29:f3b1387c81f1 | 539 | Led_Select_Left_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 540 | Led_Select_Left = 1; |
thomasmorris | 29:f3b1387c81f1 | 541 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 542 | |
thomasmorris | 29:f3b1387c81f1 | 543 | Led_Select_Right_mutex.lock(); |
thomasmorris | 29:f3b1387c81f1 | 544 | Led_Select_Right= 0; |
thomasmorris | 29:f3b1387c81f1 | 545 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 29:f3b1387c81f1 | 546 | } |
thomasmorris | 21:6d9f6a986647 | 547 | } |
thomasmorris | 30:a35f0ab97a65 | 548 | else if(_Function == 3)//Run once code alway have the led to be on the left |
thomasmorris | 30:a35f0ab97a65 | 549 | { |
thomasmorris | 30:a35f0ab97a65 | 550 | Led_Select_Left_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 551 | Led_Select_Left = 0; |
thomasmorris | 30:a35f0ab97a65 | 552 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 553 | |
thomasmorris | 30:a35f0ab97a65 | 554 | Led_Select_Right_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 555 | Led_Select_Right= 1; |
thomasmorris | 30:a35f0ab97a65 | 556 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 557 | } |
thomasmorris | 26:83550fc299aa | 558 | _Select_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 559 | } |
thomasmorris | 17:68b3fdabe4c5 | 560 | void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed |
thomasmorris | 16:9f98ec0ededb | 561 | { |
thomasmorris | 30:a35f0ab97a65 | 562 | if (_Function == 3) //Run once code Code |
thomasmorris | 30:a35f0ab97a65 | 563 | { |
thomasmorris | 30:a35f0ab97a65 | 564 | if (_Run_Go == true) |
thomasmorris | 30:a35f0ab97a65 | 565 | { |
thomasmorris | 30:a35f0ab97a65 | 566 | Led_Power_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 567 | Led_Power = 1; |
thomasmorris | 30:a35f0ab97a65 | 568 | Led_Power_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 569 | |
thomasmorris | 30:a35f0ab97a65 | 570 | _System_Running_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 571 | _System_Running = 1; |
thomasmorris | 30:a35f0ab97a65 | 572 | _System_Running_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 573 | |
thomasmorris | 30:a35f0ab97a65 | 574 | |
thomasmorris | 30:a35f0ab97a65 | 575 | if(_System_Running == 1) |
thomasmorris | 30:a35f0ab97a65 | 576 | { |
thomasmorris | 30:a35f0ab97a65 | 577 | |
thomasmorris | 30:a35f0ab97a65 | 578 | _Run_Once_On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 579 | Thread::wait((_Run_Once_On_Time)*1000);//Variable |
thomasmorris | 30:a35f0ab97a65 | 580 | _Run_Once_On_Time_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 581 | |
thomasmorris | 30:a35f0ab97a65 | 582 | Thread::wait(9001);//Fixed off time ITS OVER 9000 |
thomasmorris | 30:a35f0ab97a65 | 583 | _Tendon_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 584 | } |
thomasmorris | 30:a35f0ab97a65 | 585 | while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused |
thomasmorris | 30:a35f0ab97a65 | 586 | { |
thomasmorris | 30:a35f0ab97a65 | 587 | _Tendon_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 588 | |
thomasmorris | 30:a35f0ab97a65 | 589 | _Tendon_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 590 | } |
thomasmorris | 30:a35f0ab97a65 | 591 | |
thomasmorris | 30:a35f0ab97a65 | 592 | _System_Running_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 593 | _System_Running = 0; |
thomasmorris | 30:a35f0ab97a65 | 594 | _System_Running_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 595 | |
thomasmorris | 30:a35f0ab97a65 | 596 | _Run_Go_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 597 | _Run_Go = false; |
thomasmorris | 30:a35f0ab97a65 | 598 | _Run_Go_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 599 | |
thomasmorris | 30:a35f0ab97a65 | 600 | Led_Power_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 601 | Led_Power = 0; |
thomasmorris | 30:a35f0ab97a65 | 602 | Led_Power_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 603 | } |
thomasmorris | 30:a35f0ab97a65 | 604 | } |
thomasmorris | 30:a35f0ab97a65 | 605 | else if (_Function == 2) //Turning Code for coiling |
thomasmorris | 16:9f98ec0ededb | 606 | { |
thomasmorris | 16:9f98ec0ededb | 607 | if (_Twist_Go == true) |
thomasmorris | 16:9f98ec0ededb | 608 | { |
thomasmorris | 23:07a368f2cdb1 | 609 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 610 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 611 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 612 | |
thomasmorris | 23:07a368f2cdb1 | 613 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 614 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 615 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 616 | |
thomasmorris | 29:f3b1387c81f1 | 617 | STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo,_Function,_Direction);//Rotates for the specified number of steps given |
thomasmorris | 23:07a368f2cdb1 | 618 | |
thomasmorris | 23:07a368f2cdb1 | 619 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 620 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 621 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 622 | |
thomasmorris | 23:07a368f2cdb1 | 623 | |
thomasmorris | 23:07a368f2cdb1 | 624 | _Twist_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 625 | _Twist_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 626 | _Twist_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 627 | |
thomasmorris | 23:07a368f2cdb1 | 628 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 629 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 630 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 631 | } |
thomasmorris | 16:9f98ec0ededb | 632 | } |
thomasmorris | 25:9751619fa030 | 633 | else if (_Function == 0) //Annealing Code |
thomasmorris | 16:9f98ec0ededb | 634 | { |
thomasmorris | 16:9f98ec0ededb | 635 | if (_Anneal_Go == true) |
thomasmorris | 16:9f98ec0ededb | 636 | { |
thomasmorris | 23:07a368f2cdb1 | 637 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 638 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 639 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 640 | |
thomasmorris | 23:07a368f2cdb1 | 641 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 642 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 643 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 644 | |
thomasmorris | 30:a35f0ab97a65 | 645 | _Loops_done_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 646 | _Loops_done = 0; |
thomasmorris | 30:a35f0ab97a65 | 647 | _Loops_done_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 648 | |
thomasmorris | 16:9f98ec0ededb | 649 | for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works |
thomasmorris | 16:9f98ec0ededb | 650 | { |
thomasmorris | 23:07a368f2cdb1 | 651 | if(_System_Running == 1) |
thomasmorris | 23:07a368f2cdb1 | 652 | { |
thomasmorris | 23:07a368f2cdb1 | 653 | _Tendon_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 654 | |
thomasmorris | 25:9751619fa030 | 655 | _On_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 656 | Thread::wait((_On_Time)*1000);//Variable |
thomasmorris | 25:9751619fa030 | 657 | _On_Time_mutex.unlock(); |
thomasmorris | 30:a35f0ab97a65 | 658 | |
thomasmorris | 25:9751619fa030 | 659 | _Off_Time_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 660 | Thread::wait((_Off_Time)*1000);//Fixed off time |
thomasmorris | 25:9751619fa030 | 661 | _Off_Time_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 662 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 663 | } |
thomasmorris | 23:07a368f2cdb1 | 664 | while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused |
thomasmorris | 23:07a368f2cdb1 | 665 | { |
thomasmorris | 30:a35f0ab97a65 | 666 | |
thomasmorris | 23:07a368f2cdb1 | 667 | } |
thomasmorris | 30:a35f0ab97a65 | 668 | _Loops_done_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 669 | _Loops_done = _Loops_done + 1; |
thomasmorris | 30:a35f0ab97a65 | 670 | _Loops_done_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 671 | } |
thomasmorris | 23:07a368f2cdb1 | 672 | |
thomasmorris | 23:07a368f2cdb1 | 673 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 674 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 675 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 676 | |
thomasmorris | 23:07a368f2cdb1 | 677 | _Anneal_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 678 | _Anneal_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 679 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 680 | |
thomasmorris | 23:07a368f2cdb1 | 681 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 682 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 683 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 684 | } |
thomasmorris | 16:9f98ec0ededb | 685 | } |
thomasmorris | 25:9751619fa030 | 686 | else if (_Function == 1) //Testing Code //This code is paused / unpaused in start / stop note this code is not paused it is re run. |
thomasmorris | 16:9f98ec0ededb | 687 | { |
thomasmorris | 16:9f98ec0ededb | 688 | if (_Test_Go == true) |
thomasmorris | 16:9f98ec0ededb | 689 | { |
thomasmorris | 23:07a368f2cdb1 | 690 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 691 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 692 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 693 | |
thomasmorris | 23:07a368f2cdb1 | 694 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 695 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 696 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 697 | |
thomasmorris | 23:07a368f2cdb1 | 698 | _Tendon_mutex.lock(); |
thomasmorris | 30:a35f0ab97a65 | 699 | Thread::wait((_Power_Time)*1000);//Variable on time for power on |
thomasmorris | 30:a35f0ab97a65 | 700 | |
thomasmorris | 23:07a368f2cdb1 | 701 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 702 | |
thomasmorris | 23:07a368f2cdb1 | 703 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 704 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 705 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 706 | |
thomasmorris | 23:07a368f2cdb1 | 707 | _Test_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 708 | _Test_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 709 | _Test_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 710 | |
thomasmorris | 23:07a368f2cdb1 | 711 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 712 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 713 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 714 | } |
thomasmorris | 16:9f98ec0ededb | 715 | } |
thomasmorris | 16:9f98ec0ededb | 716 | } |
thomasmorris | 17:68b3fdabe4c5 | 717 | //Setter functions |
thomasmorris | 23:07a368f2cdb1 | 718 | void INTERFACE::Set_System_Running(int System_Running){_System_Running_mutex.lock(); _System_Running = System_Running; _System_Running_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 719 | void INTERFACE::Set_Function(int Function){_Function_mutex.lock();_Function = Function;_Function_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 720 | void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go_mutex.lock();_Twist_Go = Twist_Go;_Twist_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 721 | void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go_mutex.lock();_Anneal_Go = Anneal_Go;_Anneal_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 722 | void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go_mutex.lock();_Test_Go = Test_Go;_Test_Go_mutex.unlock();} |
thomasmorris | 30:a35f0ab97a65 | 723 | void INTERFACE::Set_Run_Go(bool Run_Go){_Run_Go_mutex.lock();_Run_Go = Run_Go;_Run_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 724 | void INTERFACE::Set_Twist_Stop(bool Twist_Stop){_Twist_Stop_mutex.lock();_Twist_Stop = Twist_Stop;_Twist_Stop_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 725 | void INTERFACE::Set_Anneal_Stop(bool Anneal_Stop){_Anneal_Stop_mutex.lock();_Anneal_Stop = Anneal_Stop;_Anneal_Stop_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 726 | void INTERFACE::Set_Test_Stop(bool Test_Stop){_Test_Stop_mutex.lock();_Test_Go = Test_Stop;_Test_Stop_mutex.unlock();} |
thomasmorris | 30:a35f0ab97a65 | 727 | void INTERFACE::Set_Run_Stop(bool Run_Stop){_Run_Stop_mutex.lock();_Run_Stop = Run_Stop;_Run_Stop_mutex.unlock();} |
thomasmorris | 25:9751619fa030 | 728 | void INTERFACE::Set_Select(int Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 729 | void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done_mutex.lock();_Turns_Done = Turns_Done;_Turns_Done_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 730 | void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo_mutex.lock();_Turns_Todo = Turns_Todo;_Turns_Todo_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 731 | void INTERFACE::Set_Loop(int Loop){_Loop_mutex.lock();Loop = Loop;_Loop_mutex.unlock();} |
thomasmorris | 30:a35f0ab97a65 | 732 | void INTERFACE::Set_Loops_done(int Loops_done){_Loops_done_mutex.lock();_Loops_done = Loops_done; _Loops_done_mutex.unlock();} |
thomasmorris | 30:a35f0ab97a65 | 733 | void INTERFACE::Set_On_Time(float On_Time){_On_Time_mutex.lock();_On_Time = On_Time;_On_Time_mutex.unlock();} |
thomasmorris | 30:a35f0ab97a65 | 734 | void INTERFACE::Set_Run_Once_On_Time(float Run_Once_On_Time){_Run_Once_On_Time_mutex.lock();_Run_Once_On_Time = Run_Once_On_Time;_Run_Once_On_Time_mutex.unlock();} |
thomasmorris | 25:9751619fa030 | 735 | void INTERFACE::Set_Off_Time(int Off_Time){_Off_Time_mutex.lock();_Off_Time = Off_Time;_Off_Time_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 736 | void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle_mutex.lock();_Duty_Cycle = Duty_Cycle;_Duty_Cycle_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 737 | void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time_mutex.lock();_Power_Time = Power_Time;_Power_Time_mutex.unlock();} |
thomasmorris | 29:f3b1387c81f1 | 738 | void INTERFACE::Set_Direction(bool Direction){_Direction_mutex.lock();_Direction = Direction;_Direction_mutex.unlock();} |
thomasmorris | 17:68b3fdabe4c5 | 739 | //Getter functions |
thomasmorris | 23:07a368f2cdb1 | 740 | int INTERFACE::Get_System_Running(){return _System_Running;} |
thomasmorris | 23:07a368f2cdb1 | 741 | int INTERFACE::Get_Function(){return _Function;} |
thomasmorris | 16:9f98ec0ededb | 742 | bool INTERFACE::Get_Twist_Go(){return _Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 743 | bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 744 | bool INTERFACE::Get_Test_Go(){return _Test_Go;} |
thomasmorris | 30:a35f0ab97a65 | 745 | bool INTERFACE::Get_Run_Go(){return _Run_Go;} |
thomasmorris | 23:07a368f2cdb1 | 746 | bool INTERFACE::Get_Twist_Stop(){return _Twist_Stop;} |
thomasmorris | 23:07a368f2cdb1 | 747 | bool INTERFACE::Get_Anneal_Stop(){return _Anneal_Stop;} |
thomasmorris | 23:07a368f2cdb1 | 748 | bool INTERFACE::Get_Test_Stop(){return _Test_Stop;} |
thomasmorris | 30:a35f0ab97a65 | 749 | bool INTERFACE::Get_Run_Stop(){return _Run_Stop;} |
thomasmorris | 25:9751619fa030 | 750 | int INTERFACE::Get_Select(){return _Select;} |
thomasmorris | 18:3523660f3930 | 751 | int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;} |
thomasmorris | 16:9f98ec0ededb | 752 | int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} |
thomasmorris | 30:a35f0ab97a65 | 753 | int INTERFACE::Get_Loops_done(){return _Loops_done;} |
thomasmorris | 16:9f98ec0ededb | 754 | int INTERFACE::Get_Loop(){return _Loop;} |
thomasmorris | 30:a35f0ab97a65 | 755 | float INTERFACE::Get_On_Time(){return _On_Time;} |
thomasmorris | 30:a35f0ab97a65 | 756 | float INTERFACE::Get_Run_Once_On_Time(){return _Run_Once_On_Time;} |
thomasmorris | 25:9751619fa030 | 757 | int INTERFACE::Get_Off_Time(){return _Off_Time;} |
thomasmorris | 16:9f98ec0ededb | 758 | int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} |
thomasmorris | 29:f3b1387c81f1 | 759 | int INTERFACE::Get_Power_Time(){return _Power_Time;} |
thomasmorris | 29:f3b1387c81f1 | 760 | bool INTERFACE::Get_Direction(){return _Direction;} |