Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Interface/Interface.cpp@28:3193157ebb0c, 2019-03-11 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Mar 11 14:19:26 2019 +0000
- Revision:
- 28:3193157ebb0c
- Parent:
- 26:83550fc299aa
- Child:
- 29:f3b1387c81f1
Version 16 Working
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 | 17:68b3fdabe4c5 | 5 | void INTERFACE::Interface_Init()//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 | _Function_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 16 | _Function = Type_of_Rig; |
thomasmorris | 23:07a368f2cdb1 | 17 | _Function_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 18 | |
thomasmorris | 23:07a368f2cdb1 | 19 | _Twist_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 20 | _Twist_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 21 | _Twist_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 22 | |
thomasmorris | 23:07a368f2cdb1 | 23 | _Anneal_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 24 | _Anneal_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 25 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 26 | |
thomasmorris | 23:07a368f2cdb1 | 27 | _Test_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 28 | _Test_Go =0; |
thomasmorris | 23:07a368f2cdb1 | 29 | _Test_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 30 | |
thomasmorris | 23:07a368f2cdb1 | 31 | _Select_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 32 | _Select =0; |
thomasmorris | 23:07a368f2cdb1 | 33 | _Select_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 34 | |
thomasmorris | 23:07a368f2cdb1 | 35 | _Turns_Done_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 36 | _Turns_Done =0; |
thomasmorris | 23:07a368f2cdb1 | 37 | _Turns_Done_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 38 | |
thomasmorris | 23:07a368f2cdb1 | 39 | _Loop_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 40 | _Loop =6; |
thomasmorris | 23:07a368f2cdb1 | 41 | _Loop_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 42 | |
thomasmorris | 25:9751619fa030 | 43 | _On_Time_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 44 | _On_Time =6; |
thomasmorris | 25:9751619fa030 | 45 | _On_Time_mutex.unlock(); |
thomasmorris | 25:9751619fa030 | 46 | |
thomasmorris | 25:9751619fa030 | 47 | _Off_Time_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 48 | _Off_Time =6; |
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 | 26:83550fc299aa | 85 | if(Type_of_Rig == 2) |
thomasmorris | 26:83550fc299aa | 86 | { |
thomasmorris | 26:83550fc299aa | 87 | _Turns_Todo = Default_Coiling_Turns; |
thomasmorris | 26:83550fc299aa | 88 | } |
thomasmorris | 26:83550fc299aa | 89 | else if(Type_of_Rig == 3) |
thomasmorris | 26:83550fc299aa | 90 | { |
thomasmorris | 26:83550fc299aa | 91 | _Turns_Todo = Default_Twisting_Turns; |
thomasmorris | 26:83550fc299aa | 92 | } |
thomasmorris | 26:83550fc299aa | 93 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 94 | } |
thomasmorris | 17:68b3fdabe4c5 | 95 | void INTERFACE::Up()//Up Routine |
thomasmorris | 16:9f98ec0ededb | 96 | { |
thomasmorris | 26:83550fc299aa | 97 | printf("In up routine\n"); |
thomasmorris | 26:83550fc299aa | 98 | printf("Function value is: %d\n",_Function); |
thomasmorris | 26:83550fc299aa | 99 | printf("Select Value is :%d\n",_Select); |
thomasmorris | 25:9751619fa030 | 100 | if (_Function == 2 || _Function == 3 )//Coiling or twist Function |
thomasmorris | 16:9f98ec0ededb | 101 | { |
thomasmorris | 23:07a368f2cdb1 | 102 | _Turns_Todo_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 103 | _Turns_Todo = _Turns_Todo +1; |
thomasmorris | 23:07a368f2cdb1 | 104 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 105 | } |
thomasmorris | 25:9751619fa030 | 106 | else if (_Function == 0)//Annealing Function |
thomasmorris | 16:9f98ec0ededb | 107 | { |
thomasmorris | 25:9751619fa030 | 108 | if (_Select == 0)//Select = 0 |
thomasmorris | 23:07a368f2cdb1 | 109 | { |
thomasmorris | 26:83550fc299aa | 110 | if(_On_Time > 0) |
thomasmorris | 26:83550fc299aa | 111 | { |
thomasmorris | 26:83550fc299aa | 112 | _On_Time_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 113 | _On_Time = _On_Time+ 1; //Increments On time |
thomasmorris | 26:83550fc299aa | 114 | _On_Time_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 115 | } |
thomasmorris | 16:9f98ec0ededb | 116 | } |
thomasmorris | 25:9751619fa030 | 117 | else if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 118 | { |
thomasmorris | 26:83550fc299aa | 119 | if(_Loop > 0) |
thomasmorris | 26:83550fc299aa | 120 | { |
thomasmorris | 26:83550fc299aa | 121 | _Loop_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 122 | _Loop = _Loop + 1; //Increments Repetitions in Annealing |
thomasmorris | 26:83550fc299aa | 123 | _Loop_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 124 | } |
thomasmorris | 25:9751619fa030 | 125 | } |
thomasmorris | 26:83550fc299aa | 126 | else if (_Select == 2)//Select = 2 |
thomasmorris | 25:9751619fa030 | 127 | { |
thomasmorris | 26:83550fc299aa | 128 | if(_Off_Time > 0) |
thomasmorris | 26:83550fc299aa | 129 | { |
thomasmorris | 26:83550fc299aa | 130 | _Off_Time_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 131 | _Off_Time = _Off_Time + 1; //Increments Off time |
thomasmorris | 26:83550fc299aa | 132 | _Off_Time_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 133 | } |
thomasmorris | 16:9f98ec0ededb | 134 | } |
thomasmorris | 16:9f98ec0ededb | 135 | } |
thomasmorris | 25:9751619fa030 | 136 | else if (_Function == 1)//Test Function |
thomasmorris | 16:9f98ec0ededb | 137 | { |
thomasmorris | 26:83550fc299aa | 138 | if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 139 | { |
thomasmorris | 16:9f98ec0ededb | 140 | if (_Duty_Cycle < 100) |
thomasmorris | 16:9f98ec0ededb | 141 | { |
thomasmorris | 23:07a368f2cdb1 | 142 | _Duty_Cycle_mutex.lock(); |
thomasmorris | 16:9f98ec0ededb | 143 | _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle |
thomasmorris | 23:07a368f2cdb1 | 144 | _Duty_Cycle_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 145 | } |
thomasmorris | 24:728de4bf961e | 146 | } |
thomasmorris | 26:83550fc299aa | 147 | else if (_Select == 0)//Select = 0 |
thomasmorris | 24:728de4bf961e | 148 | { |
thomasmorris | 24:728de4bf961e | 149 | _Power_Time_mutex.lock(); |
thomasmorris | 24:728de4bf961e | 150 | _Power_Time = _Power_Time + 1; //Increases time on |
thomasmorris | 24:728de4bf961e | 151 | _Power_Time_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 152 | } |
thomasmorris | 16:9f98ec0ededb | 153 | } |
thomasmorris | 16:9f98ec0ededb | 154 | } |
thomasmorris | 17:68b3fdabe4c5 | 155 | void INTERFACE::Down()//Down Routine |
thomasmorris | 16:9f98ec0ededb | 156 | { |
thomasmorris | 25:9751619fa030 | 157 | if (_Function == 2 || _Function == 3)//Coiling or twist Function |
thomasmorris | 25:9751619fa030 | 158 | { |
thomasmorris | 23:07a368f2cdb1 | 159 | _Turns_Todo_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 160 | _Turns_Todo = _Turns_Todo -1; |
thomasmorris | 23:07a368f2cdb1 | 161 | _Turns_Todo_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 162 | } |
thomasmorris | 26:83550fc299aa | 163 | else if (_Function == 0)//Annealing Function |
thomasmorris | 16:9f98ec0ededb | 164 | { |
thomasmorris | 25:9751619fa030 | 165 | if (_Select == 0)//Select = 0 |
thomasmorris | 26:83550fc299aa | 166 | { |
thomasmorris | 26:83550fc299aa | 167 | if(_On_Time > 1) |
thomasmorris | 16:9f98ec0ededb | 168 | { |
thomasmorris | 26:83550fc299aa | 169 | _On_Time_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 170 | _On_Time = _On_Time - 1; //Decrements On time |
thomasmorris | 26:83550fc299aa | 171 | _On_Time_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 172 | } |
thomasmorris | 24:728de4bf961e | 173 | } |
thomasmorris | 25:9751619fa030 | 174 | else if (_Select == 1)//Select = 1 |
thomasmorris | 24:728de4bf961e | 175 | { |
thomasmorris | 26:83550fc299aa | 176 | if(_Loop > 1) |
thomasmorris | 26:83550fc299aa | 177 | { |
thomasmorris | 26:83550fc299aa | 178 | _Loop_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 179 | _Loop = _Loop - 1; //Decrements Repetitions in Annealing |
thomasmorris | 26:83550fc299aa | 180 | _Loop_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 181 | } |
thomasmorris | 25:9751619fa030 | 182 | } |
thomasmorris | 26:83550fc299aa | 183 | else if (_Select == 2)//Select = 2 |
thomasmorris | 25:9751619fa030 | 184 | { |
thomasmorris | 26:83550fc299aa | 185 | if(_Off_Time > 1) |
thomasmorris | 26:83550fc299aa | 186 | { |
thomasmorris | 26:83550fc299aa | 187 | _Off_Time_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 188 | _Off_Time = _Off_Time - 1; //Decrements Off time |
thomasmorris | 26:83550fc299aa | 189 | _Off_Time_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 190 | } |
thomasmorris | 16:9f98ec0ededb | 191 | } |
thomasmorris | 16:9f98ec0ededb | 192 | } |
thomasmorris | 25:9751619fa030 | 193 | else if (_Function == 1)//Test Function |
thomasmorris | 16:9f98ec0ededb | 194 | { |
thomasmorris | 26:83550fc299aa | 195 | if (_Select == 1)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 196 | { |
thomasmorris | 16:9f98ec0ededb | 197 | if (_Duty_Cycle > 0) |
thomasmorris | 16:9f98ec0ededb | 198 | { |
thomasmorris | 23:07a368f2cdb1 | 199 | _Duty_Cycle_mutex.lock(); |
thomasmorris | 16:9f98ec0ededb | 200 | _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty |
thomasmorris | 23:07a368f2cdb1 | 201 | _Duty_Cycle_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 202 | } |
thomasmorris | 24:728de4bf961e | 203 | } |
thomasmorris | 26:83550fc299aa | 204 | else if (_Select == 0)//Select = 0 |
thomasmorris | 24:728de4bf961e | 205 | { |
thomasmorris | 24:728de4bf961e | 206 | if (_Power_Time > 0) |
thomasmorris | 16:9f98ec0ededb | 207 | { |
thomasmorris | 24:728de4bf961e | 208 | _Power_Time_mutex.lock(); |
thomasmorris | 24:728de4bf961e | 209 | _Power_Time = _Power_Time - 1; //Decreases Time on |
thomasmorris | 24:728de4bf961e | 210 | _Power_Time_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 211 | } |
thomasmorris | 16:9f98ec0ededb | 212 | } |
thomasmorris | 16:9f98ec0ededb | 213 | } |
thomasmorris | 16:9f98ec0ededb | 214 | } |
thomasmorris | 28:3193157ebb0c | 215 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
thomasmorris | 17:68b3fdabe4c5 | 216 | void INTERFACE::Start_Stop()//Start / Stop Routine |
thomasmorris | 16:9f98ec0ededb | 217 | { |
thomasmorris | 28:3193157ebb0c | 218 | /* |
thomasmorris | 28:3193157ebb0c | 219 | System Running = 0 Stop |
thomasmorris | 28:3193157ebb0c | 220 | System Running = 1 Running |
thomasmorris | 28:3193157ebb0c | 221 | System Running = 2 Paused |
thomasmorris | 28:3193157ebb0c | 222 | */ |
thomasmorris | 24:728de4bf961e | 223 | |
thomasmorris | 28:3193157ebb0c | 224 | printf("Function is: %d, System is: %d\n",_Function,_System_Running);//Used for debugging |
thomasmorris | 28:3193157ebb0c | 225 | |
thomasmorris | 28:3193157ebb0c | 226 | //Start Cases for when the system is stopped/////////////////////////////////////////////////////////////////////////////////// |
thomasmorris | 28:3193157ebb0c | 227 | if ((_Function == 2 || _Function == 3) & _System_Running == 0)//Twist selected |
thomasmorris | 23:07a368f2cdb1 | 228 | { |
thomasmorris | 28:3193157ebb0c | 229 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 230 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 231 | _System_Running_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 232 | |
thomasmorris | 23:07a368f2cdb1 | 233 | _Twist_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 234 | _Twist_Go = true;//toggle used for coiling and twisting and Running the code |
thomasmorris | 23:07a368f2cdb1 | 235 | _Twist_Go_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 236 | |
thomasmorris | 23:07a368f2cdb1 | 237 | } |
thomasmorris | 28:3193157ebb0c | 238 | else if (_Function == 0 & _System_Running == 0) //Annealing selected |
thomasmorris | 23:07a368f2cdb1 | 239 | { |
thomasmorris | 28:3193157ebb0c | 240 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 241 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 242 | _System_Running_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 243 | |
thomasmorris | 23:07a368f2cdb1 | 244 | _Anneal_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 245 | _Anneal_Go = true;//toggle and Run the code |
thomasmorris | 23:07a368f2cdb1 | 246 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 247 | } |
thomasmorris | 28:3193157ebb0c | 248 | else if (_Function == 1 & _System_Running == 0) //Testing selected |
thomasmorris | 16:9f98ec0ededb | 249 | { |
thomasmorris | 28:3193157ebb0c | 250 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 251 | _System_Running = 1;//Code is running |
thomasmorris | 28:3193157ebb0c | 252 | _System_Running_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 253 | |
thomasmorris | 23:07a368f2cdb1 | 254 | _Test_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 255 | _Test_Go = true;//toggle and run the code |
thomasmorris | 23:07a368f2cdb1 | 256 | _Test_Go_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 257 | } |
thomasmorris | 28:3193157ebb0c | 258 | /////////////////////////////////////// |
thomasmorris | 28:3193157ebb0c | 259 | |
thomasmorris | 28:3193157ebb0c | 260 | //System Running cases run to pause the code |
thomasmorris | 28:3193157ebb0c | 261 | else if ((_Function == 2 || _Function == 3) & _System_Running == 1)//Coiling / Twisting selected to be paused |
thomasmorris | 23:07a368f2cdb1 | 262 | { |
thomasmorris | 23:07a368f2cdb1 | 263 | _Twist_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 264 | _Twist_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 265 | _Twist_Stop_mutex.unlock(); |
thomasmorris | 25:9751619fa030 | 266 | |
thomasmorris | 25:9751619fa030 | 267 | if(_Function == 2) |
thomasmorris | 25:9751619fa030 | 268 | { |
thomasmorris | 25:9751619fa030 | 269 | printf("Coiling Code Paused\n"); |
thomasmorris | 25:9751619fa030 | 270 | } |
thomasmorris | 25:9751619fa030 | 271 | if(_Function == 3) |
thomasmorris | 25:9751619fa030 | 272 | { |
thomasmorris | 25:9751619fa030 | 273 | printf("Twisting Code Paused\n"); |
thomasmorris | 25:9751619fa030 | 274 | } |
thomasmorris | 23:07a368f2cdb1 | 275 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 276 | _System_Running = 2; |
thomasmorris | 23:07a368f2cdb1 | 277 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 278 | STEPPER_MOTOR_1.Pause_Code(); |
thomasmorris | 23:07a368f2cdb1 | 279 | } |
thomasmorris | 25:9751619fa030 | 280 | else if (_Function == 0 & _System_Running == 1) //Annealing selected to be stopped |
thomasmorris | 23:07a368f2cdb1 | 281 | { |
thomasmorris | 23:07a368f2cdb1 | 282 | _Anneal_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 283 | _Anneal_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 284 | _Anneal_Stop_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 285 | printf("Annealing Code Paused\n"); |
thomasmorris | 23:07a368f2cdb1 | 286 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 287 | _System_Running = 2;//Pause code |
thomasmorris | 23:07a368f2cdb1 | 288 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 289 | } |
thomasmorris | 28:3193157ebb0c | 290 | else if (_Function == 1 & _System_Running == 1) //Testing selected to be paused |
thomasmorris | 16:9f98ec0ededb | 291 | { |
thomasmorris | 23:07a368f2cdb1 | 292 | _Test_Stop_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 293 | _Test_Stop = true; |
thomasmorris | 23:07a368f2cdb1 | 294 | _Test_Stop_mutex.unlock(); |
thomasmorris | 24:728de4bf961e | 295 | |
thomasmorris | 23:07a368f2cdb1 | 296 | printf("Testing Code Paused\n"); |
thomasmorris | 24:728de4bf961e | 297 | |
thomasmorris | 23:07a368f2cdb1 | 298 | _Tendon_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 299 | Tendon_Power=0; |
thomasmorris | 23:07a368f2cdb1 | 300 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 301 | |
thomasmorris | 23:07a368f2cdb1 | 302 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 303 | _System_Running = 2;//Pause code |
thomasmorris | 23:07a368f2cdb1 | 304 | _System_Running_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 305 | } |
thomasmorris | 28:3193157ebb0c | 306 | |
thomasmorris | 28:3193157ebb0c | 307 | //////////////// |
thomasmorris | 28:3193157ebb0c | 308 | //System Paused cases run to unpause |
thomasmorris | 28:3193157ebb0c | 309 | else if ((_Function == 2 || _Function == 3) & _System_Running == 2)//Coil Twist selected to be unpaused |
thomasmorris | 23:07a368f2cdb1 | 310 | { |
thomasmorris | 28:3193157ebb0c | 311 | _Twist_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 312 | _Twist_Stop = false; |
thomasmorris | 28:3193157ebb0c | 313 | _Twist_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 314 | |
thomasmorris | 23:07a368f2cdb1 | 315 | _Twist_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 316 | _Twist_Go = true;//toggle used for coiling and twisting and Running the code |
thomasmorris | 23:07a368f2cdb1 | 317 | _Twist_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 318 | |
thomasmorris | 28:3193157ebb0c | 319 | STEPPER_MOTOR_1.Unpause_Code(); |
thomasmorris | 28:3193157ebb0c | 320 | |
thomasmorris | 28:3193157ebb0c | 321 | if(_Function == 2)//Coiling |
thomasmorris | 28:3193157ebb0c | 322 | { |
thomasmorris | 28:3193157ebb0c | 323 | printf("Coiling Code unpaused\n"); |
thomasmorris | 28:3193157ebb0c | 324 | } |
thomasmorris | 28:3193157ebb0c | 325 | if(_Function == 3)//Twisiting |
thomasmorris | 28:3193157ebb0c | 326 | { |
thomasmorris | 28:3193157ebb0c | 327 | printf("Twisting Code unpaused\n"); |
thomasmorris | 28:3193157ebb0c | 328 | } |
thomasmorris | 28:3193157ebb0c | 329 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 330 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 331 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 332 | } |
thomasmorris | 28:3193157ebb0c | 333 | else if (_Function == 0 & _System_Running == 2) //Annealing selected to be unpaused |
thomasmorris | 16:9f98ec0ededb | 334 | { |
thomasmorris | 28:3193157ebb0c | 335 | _Anneal_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 336 | _Anneal_Stop = false; |
thomasmorris | 28:3193157ebb0c | 337 | _Anneal_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 338 | printf("Annealing Code unpaused\n"); |
thomasmorris | 28:3193157ebb0c | 339 | |
thomasmorris | 23:07a368f2cdb1 | 340 | _Anneal_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 341 | _Anneal_Go = true;//toggle and Run the code |
thomasmorris | 23:07a368f2cdb1 | 342 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 343 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 344 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 345 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 346 | } |
thomasmorris | 28:3193157ebb0c | 347 | else if (_Function == 1 & _System_Running == 2) //Testing selected to be re run |
thomasmorris | 23:07a368f2cdb1 | 348 | { |
thomasmorris | 28:3193157ebb0c | 349 | _Test_Stop_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 350 | _Test_Stop = false; |
thomasmorris | 28:3193157ebb0c | 351 | _Test_Stop_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 352 | printf("Testing Code unpaused\n"); |
thomasmorris | 23:07a368f2cdb1 | 353 | _Test_Go_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 354 | _Test_Go = true;//toggle and run the code |
thomasmorris | 23:07a368f2cdb1 | 355 | _Test_Go_mutex.unlock(); |
thomasmorris | 28:3193157ebb0c | 356 | _System_Running_mutex.lock(); |
thomasmorris | 28:3193157ebb0c | 357 | _System_Running = 1;//Code is unpaused |
thomasmorris | 28:3193157ebb0c | 358 | _System_Running_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 359 | } |
thomasmorris | 16:9f98ec0ededb | 360 | } |
thomasmorris | 17:68b3fdabe4c5 | 361 | void INTERFACE::Function()//Function Routine used to increment through the three functions |
thomasmorris | 16:9f98ec0ededb | 362 | { |
thomasmorris | 17:68b3fdabe4c5 | 363 | /* |
thomasmorris | 25:9751619fa030 | 364 | Function 0 = Anneal |
thomasmorris | 25:9751619fa030 | 365 | Function 1 = Test |
thomasmorris | 25:9751619fa030 | 366 | Function 2 = Coiling |
thomasmorris | 25:9751619fa030 | 367 | Function 3 = Twisting |
thomasmorris | 17:68b3fdabe4c5 | 368 | */ |
thomasmorris | 26:83550fc299aa | 369 | if(Type_of_Rig == 3) |
thomasmorris | 26:83550fc299aa | 370 | { |
thomasmorris | 26:83550fc299aa | 371 | if(_Function < 3) |
thomasmorris | 26:83550fc299aa | 372 | { |
thomasmorris | 26:83550fc299aa | 373 | if(_Function == 1)//Skip coiling |
thomasmorris | 26:83550fc299aa | 374 | { |
thomasmorris | 26:83550fc299aa | 375 | _Function_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 376 | _Function = _Function + 1; |
thomasmorris | 26:83550fc299aa | 377 | _Function_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 378 | } |
thomasmorris | 26:83550fc299aa | 379 | _Function_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 380 | _Function = _Function + 1; |
thomasmorris | 26:83550fc299aa | 381 | _Function_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 382 | } |
thomasmorris | 26:83550fc299aa | 383 | else if(_Function == 3) |
thomasmorris | 26:83550fc299aa | 384 | { |
thomasmorris | 26:83550fc299aa | 385 | _Function = 0; |
thomasmorris | 26:83550fc299aa | 386 | } |
thomasmorris | 26:83550fc299aa | 387 | } |
thomasmorris | 25:9751619fa030 | 388 | if(Type_of_Rig == 2) |
thomasmorris | 25:9751619fa030 | 389 | { |
thomasmorris | 25:9751619fa030 | 390 | if(_Function < 2) |
thomasmorris | 25:9751619fa030 | 391 | { |
thomasmorris | 25:9751619fa030 | 392 | _Function_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 393 | _Function = _Function + 1; |
thomasmorris | 26:83550fc299aa | 394 | _Function_mutex.unlock(); |
thomasmorris | 25:9751619fa030 | 395 | } |
thomasmorris | 25:9751619fa030 | 396 | else if(_Function == 2) |
thomasmorris | 25:9751619fa030 | 397 | { |
thomasmorris | 26:83550fc299aa | 398 | _Function = 0; |
thomasmorris | 25:9751619fa030 | 399 | } |
thomasmorris | 16:9f98ec0ededb | 400 | } |
thomasmorris | 16:9f98ec0ededb | 401 | } |
thomasmorris | 17:68b3fdabe4c5 | 402 | void INTERFACE::Select()//Select Routine |
thomasmorris | 16:9f98ec0ededb | 403 | { |
thomasmorris | 23:07a368f2cdb1 | 404 | _Select_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 405 | if(_Function == 0)//Anneal |
thomasmorris | 25:9751619fa030 | 406 | { |
thomasmorris | 26:83550fc299aa | 407 | printf("Select Value is :%d\n",_Select); |
thomasmorris | 26:83550fc299aa | 408 | if(_Select == 2) |
thomasmorris | 26:83550fc299aa | 409 | { |
thomasmorris | 26:83550fc299aa | 410 | _Select = 0; |
thomasmorris | 26:83550fc299aa | 411 | } |
thomasmorris | 26:83550fc299aa | 412 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 413 | { |
thomasmorris | 26:83550fc299aa | 414 | _Select = 2; |
thomasmorris | 26:83550fc299aa | 415 | } |
thomasmorris | 26:83550fc299aa | 416 | else if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 417 | { |
thomasmorris | 26:83550fc299aa | 418 | _Select = 1; |
thomasmorris | 26:83550fc299aa | 419 | } |
thomasmorris | 26:83550fc299aa | 420 | if(_Select == 0 || _Select == 2) |
thomasmorris | 26:83550fc299aa | 421 | { |
thomasmorris | 26:83550fc299aa | 422 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 423 | Led_Select_Left = 0; |
thomasmorris | 26:83550fc299aa | 424 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 425 | |
thomasmorris | 26:83550fc299aa | 426 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 427 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 428 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 429 | } |
thomasmorris | 26:83550fc299aa | 430 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 431 | { |
thomasmorris | 26:83550fc299aa | 432 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 433 | Led_Select_Left = 1; |
thomasmorris | 26:83550fc299aa | 434 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 435 | |
thomasmorris | 26:83550fc299aa | 436 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 437 | Led_Select_Right= 0; |
thomasmorris | 26:83550fc299aa | 438 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 439 | } |
thomasmorris | 26:83550fc299aa | 440 | printf("Select Value is :%d\n",_Select); |
thomasmorris | 25:9751619fa030 | 441 | } |
thomasmorris | 26:83550fc299aa | 442 | else if(_Function == 1)//Test |
thomasmorris | 23:07a368f2cdb1 | 443 | { |
thomasmorris | 26:83550fc299aa | 444 | if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 445 | { |
thomasmorris | 26:83550fc299aa | 446 | _Select = 1; |
thomasmorris | 26:83550fc299aa | 447 | } |
thomasmorris | 26:83550fc299aa | 448 | else if(_Select == 1) |
thomasmorris | 26:83550fc299aa | 449 | { |
thomasmorris | 26:83550fc299aa | 450 | _Select = 0; |
thomasmorris | 26:83550fc299aa | 451 | } |
thomasmorris | 23:07a368f2cdb1 | 452 | |
thomasmorris | 26:83550fc299aa | 453 | if(_Select == 0) |
thomasmorris | 26:83550fc299aa | 454 | { |
thomasmorris | 26:83550fc299aa | 455 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 456 | Led_Select_Left = 0; |
thomasmorris | 26:83550fc299aa | 457 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 458 | |
thomasmorris | 26:83550fc299aa | 459 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 460 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 461 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 462 | } |
thomasmorris | 26:83550fc299aa | 463 | else if(_Select ==1) |
thomasmorris | 26:83550fc299aa | 464 | { |
thomasmorris | 26:83550fc299aa | 465 | Led_Select_Left_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 466 | Led_Select_Left = 1; |
thomasmorris | 26:83550fc299aa | 467 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 468 | |
thomasmorris | 26:83550fc299aa | 469 | Led_Select_Right_mutex.lock(); |
thomasmorris | 26:83550fc299aa | 470 | Led_Select_Right= 0; |
thomasmorris | 26:83550fc299aa | 471 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 26:83550fc299aa | 472 | } |
thomasmorris | 21:6d9f6a986647 | 473 | } |
thomasmorris | 26:83550fc299aa | 474 | else if(_Function == 2 || _Function == 3) |
thomasmorris | 21:6d9f6a986647 | 475 | { |
thomasmorris | 26:83550fc299aa | 476 | _Select = 0; |
thomasmorris | 23:07a368f2cdb1 | 477 | Led_Select_Left_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 478 | Led_Select_Left = 0; |
thomasmorris | 23:07a368f2cdb1 | 479 | Led_Select_Left_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 480 | |
thomasmorris | 23:07a368f2cdb1 | 481 | Led_Select_Right_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 482 | Led_Select_Right= 1; |
thomasmorris | 26:83550fc299aa | 483 | Led_Select_Right_mutex.unlock(); |
thomasmorris | 21:6d9f6a986647 | 484 | } |
thomasmorris | 26:83550fc299aa | 485 | _Select_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 486 | } |
thomasmorris | 17:68b3fdabe4c5 | 487 | void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed |
thomasmorris | 16:9f98ec0ededb | 488 | { |
thomasmorris | 28:3193157ebb0c | 489 | if (_Function == 2 || _Function == 3) //Turning Code for coiling and twisting |
thomasmorris | 16:9f98ec0ededb | 490 | { |
thomasmorris | 16:9f98ec0ededb | 491 | if (_Twist_Go == true) |
thomasmorris | 16:9f98ec0ededb | 492 | { |
thomasmorris | 23:07a368f2cdb1 | 493 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 494 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 495 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 496 | |
thomasmorris | 23:07a368f2cdb1 | 497 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 498 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 499 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 500 | |
thomasmorris | 25:9751619fa030 | 501 | STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo,_Function);//Rotates for the specified number of steps given |
thomasmorris | 23:07a368f2cdb1 | 502 | |
thomasmorris | 23:07a368f2cdb1 | 503 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 504 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 505 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 506 | |
thomasmorris | 23:07a368f2cdb1 | 507 | |
thomasmorris | 23:07a368f2cdb1 | 508 | _Twist_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 509 | _Twist_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 510 | _Twist_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 511 | |
thomasmorris | 23:07a368f2cdb1 | 512 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 513 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 514 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 515 | } |
thomasmorris | 16:9f98ec0ededb | 516 | } |
thomasmorris | 25:9751619fa030 | 517 | else if (_Function == 0) //Annealing Code |
thomasmorris | 16:9f98ec0ededb | 518 | { |
thomasmorris | 16:9f98ec0ededb | 519 | if (_Anneal_Go == true) |
thomasmorris | 16:9f98ec0ededb | 520 | { |
thomasmorris | 23:07a368f2cdb1 | 521 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 522 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 523 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 524 | |
thomasmorris | 23:07a368f2cdb1 | 525 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 526 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 527 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 528 | |
thomasmorris | 16:9f98ec0ededb | 529 | for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works |
thomasmorris | 16:9f98ec0ededb | 530 | { |
thomasmorris | 23:07a368f2cdb1 | 531 | if(_System_Running == 1) |
thomasmorris | 23:07a368f2cdb1 | 532 | { |
thomasmorris | 23:07a368f2cdb1 | 533 | _Tendon_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 534 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 23:07a368f2cdb1 | 535 | Tendon_Power=1; // set duty cycle to 100% |
thomasmorris | 25:9751619fa030 | 536 | _On_Time_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 537 | wait(_On_Time);//Variable |
thomasmorris | 25:9751619fa030 | 538 | _On_Time_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 539 | Tendon_Power=0; // set duty cycle to 0% |
thomasmorris | 25:9751619fa030 | 540 | _Off_Time_mutex.lock(); |
thomasmorris | 25:9751619fa030 | 541 | wait(_Off_Time);//Fixed off time |
thomasmorris | 25:9751619fa030 | 542 | _Off_Time_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 543 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 544 | } |
thomasmorris | 23:07a368f2cdb1 | 545 | while(_System_Running == 2)//Stops the system and just spins in this while loop until system running is not paused |
thomasmorris | 23:07a368f2cdb1 | 546 | { |
thomasmorris | 23:07a368f2cdb1 | 547 | _Tendon_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 548 | Tendon_Power =0; |
thomasmorris | 23:07a368f2cdb1 | 549 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 550 | } |
thomasmorris | 16:9f98ec0ededb | 551 | } |
thomasmorris | 23:07a368f2cdb1 | 552 | |
thomasmorris | 23:07a368f2cdb1 | 553 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 554 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 555 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 556 | |
thomasmorris | 23:07a368f2cdb1 | 557 | _Anneal_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 558 | _Anneal_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 559 | _Anneal_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 560 | |
thomasmorris | 23:07a368f2cdb1 | 561 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 562 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 563 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 564 | } |
thomasmorris | 16:9f98ec0ededb | 565 | } |
thomasmorris | 25:9751619fa030 | 566 | 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 | 567 | { |
thomasmorris | 16:9f98ec0ededb | 568 | if (_Test_Go == true) |
thomasmorris | 16:9f98ec0ededb | 569 | { |
thomasmorris | 23:07a368f2cdb1 | 570 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 571 | Led_Power = 1; |
thomasmorris | 23:07a368f2cdb1 | 572 | Led_Power_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 573 | |
thomasmorris | 23:07a368f2cdb1 | 574 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 575 | _System_Running = 1; |
thomasmorris | 23:07a368f2cdb1 | 576 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 577 | |
thomasmorris | 23:07a368f2cdb1 | 578 | _Tendon_mutex.lock(); |
thomasmorris | 16:9f98ec0ededb | 579 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 16:9f98ec0ededb | 580 | 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 | 581 | wait(_Power_Time);//Variable on time for power on |
thomasmorris | 16:9f98ec0ededb | 582 | Tendon_Power=0; // set duty cycle to 0% and power off |
thomasmorris | 23:07a368f2cdb1 | 583 | _Tendon_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 584 | |
thomasmorris | 23:07a368f2cdb1 | 585 | _System_Running_mutex.lock(); |
thomasmorris | 23:07a368f2cdb1 | 586 | _System_Running = 0; |
thomasmorris | 23:07a368f2cdb1 | 587 | _System_Running_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 588 | |
thomasmorris | 23:07a368f2cdb1 | 589 | _Test_Go_mutex.lock(); |
thomasmorris | 17:68b3fdabe4c5 | 590 | _Test_Go = false; |
thomasmorris | 23:07a368f2cdb1 | 591 | _Test_Go_mutex.unlock(); |
thomasmorris | 23:07a368f2cdb1 | 592 | |
thomasmorris | 23:07a368f2cdb1 | 593 | Led_Power_mutex.lock(); |
thomasmorris | 21:6d9f6a986647 | 594 | Led_Power = 0; |
thomasmorris | 23:07a368f2cdb1 | 595 | Led_Power_mutex.unlock(); |
thomasmorris | 16:9f98ec0ededb | 596 | } |
thomasmorris | 16:9f98ec0ededb | 597 | } |
thomasmorris | 16:9f98ec0ededb | 598 | } |
thomasmorris | 17:68b3fdabe4c5 | 599 | //Setter functions |
thomasmorris | 23:07a368f2cdb1 | 600 | void INTERFACE::Set_System_Running(int System_Running){_System_Running_mutex.lock(); _System_Running = System_Running; _System_Running_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 601 | void INTERFACE::Set_Function(int Function){_Function_mutex.lock();_Function = Function;_Function_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 602 | void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go_mutex.lock();_Twist_Go = Twist_Go;_Twist_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 603 | void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go_mutex.lock();_Anneal_Go = Anneal_Go;_Anneal_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 604 | void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go_mutex.lock();_Test_Go = Test_Go;_Test_Go_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 605 | void INTERFACE::Set_Twist_Stop(bool Twist_Stop){_Twist_Stop_mutex.lock();_Twist_Stop = Twist_Stop;_Twist_Stop_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 606 | void INTERFACE::Set_Anneal_Stop(bool Anneal_Stop){_Anneal_Stop_mutex.lock();_Anneal_Stop = Anneal_Stop;_Anneal_Stop_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 607 | void INTERFACE::Set_Test_Stop(bool Test_Stop){_Test_Stop_mutex.lock();_Test_Go = Test_Stop;_Test_Stop_mutex.unlock();} |
thomasmorris | 25:9751619fa030 | 608 | void INTERFACE::Set_Select(int Select){_Select_mutex.lock();_Select = Select;_Select_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 609 | void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done_mutex.lock();_Turns_Done = Turns_Done;_Turns_Done_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 610 | void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo_mutex.lock();_Turns_Todo = Turns_Todo;_Turns_Todo_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 611 | void INTERFACE::Set_Loop(int Loop){_Loop_mutex.lock();Loop = Loop;_Loop_mutex.unlock();} |
thomasmorris | 25:9751619fa030 | 612 | void INTERFACE::Set_On_Time(int On_Time){_On_Time_mutex.lock();_On_Time = On_Time;_On_Time_mutex.unlock();} |
thomasmorris | 25:9751619fa030 | 613 | void INTERFACE::Set_Off_Time(int Off_Time){_Off_Time_mutex.lock();_Off_Time = Off_Time;_Off_Time_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 614 | void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle_mutex.lock();_Duty_Cycle = Duty_Cycle;_Duty_Cycle_mutex.unlock();} |
thomasmorris | 23:07a368f2cdb1 | 615 | void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time_mutex.lock();_Power_Time = Power_Time;_Power_Time_mutex.unlock();} |
thomasmorris | 17:68b3fdabe4c5 | 616 | //Getter functions |
thomasmorris | 23:07a368f2cdb1 | 617 | int INTERFACE::Get_System_Running(){return _System_Running;} |
thomasmorris | 23:07a368f2cdb1 | 618 | int INTERFACE::Get_Function(){return _Function;} |
thomasmorris | 16:9f98ec0ededb | 619 | bool INTERFACE::Get_Twist_Go(){return _Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 620 | bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 621 | bool INTERFACE::Get_Test_Go(){return _Test_Go;} |
thomasmorris | 23:07a368f2cdb1 | 622 | bool INTERFACE::Get_Twist_Stop(){return _Twist_Stop;} |
thomasmorris | 23:07a368f2cdb1 | 623 | bool INTERFACE::Get_Anneal_Stop(){return _Anneal_Stop;} |
thomasmorris | 23:07a368f2cdb1 | 624 | bool INTERFACE::Get_Test_Stop(){return _Test_Stop;} |
thomasmorris | 25:9751619fa030 | 625 | int INTERFACE::Get_Select(){return _Select;} |
thomasmorris | 18:3523660f3930 | 626 | int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;} |
thomasmorris | 16:9f98ec0ededb | 627 | int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} |
thomasmorris | 16:9f98ec0ededb | 628 | int INTERFACE::Get_Loop(){return _Loop;} |
thomasmorris | 25:9751619fa030 | 629 | int INTERFACE::Get_On_Time(){return _On_Time;} |
thomasmorris | 25:9751619fa030 | 630 | int INTERFACE::Get_Off_Time(){return _Off_Time;} |
thomasmorris | 16:9f98ec0ededb | 631 | int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} |
thomasmorris | 23:07a368f2cdb1 | 632 | int INTERFACE::Get_Power_Time(){return _Power_Time;} |