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