Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Interface/Interface.cpp@21:6d9f6a986647, 2019-02-14 (annotated)
- Committer:
- thomasmorris
- Date:
- Thu Feb 14 10:22:54 2019 +0000
- Revision:
- 21:6d9f6a986647
- Parent:
- 18:3523660f3930
- Child:
- 23:07a368f2cdb1
Debounce code added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 16:9f98ec0ededb | 1 | #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations |
thomasmorris | 16:9f98ec0ededb | 2 | PwmOut Tendon_Power(PE_8); |
thomasmorris | 16:9f98ec0ededb | 3 | //Constructor |
thomasmorris | 17:68b3fdabe4c5 | 4 | INTERFACE::INTERFACE(int Default_Turns)//Set all values to 0 |
thomasmorris | 16:9f98ec0ededb | 5 | { |
thomasmorris | 17:68b3fdabe4c5 | 6 | _Turns_Todo = Default_Turns; |
thomasmorris | 16:9f98ec0ededb | 7 | } |
thomasmorris | 16:9f98ec0ededb | 8 | INTERFACE::~INTERFACE(){} //Destructor |
thomasmorris | 16:9f98ec0ededb | 9 | //Interrupt run functions |
thomasmorris | 17:68b3fdabe4c5 | 10 | void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns |
thomasmorris | 16:9f98ec0ededb | 11 | { |
thomasmorris | 17:68b3fdabe4c5 | 12 | _No_Of_Rotations =20; |
thomasmorris | 17:68b3fdabe4c5 | 13 | _Function =0; |
thomasmorris | 17:68b3fdabe4c5 | 14 | _Twist_Go =0; |
thomasmorris | 17:68b3fdabe4c5 | 15 | _Anneal_Go =0; |
thomasmorris | 17:68b3fdabe4c5 | 16 | _Test_Go =0; |
thomasmorris | 17:68b3fdabe4c5 | 17 | _Select =0; |
thomasmorris | 17:68b3fdabe4c5 | 18 | _Turns_Done =0; |
thomasmorris | 17:68b3fdabe4c5 | 19 | _Turns_Todo =20; |
thomasmorris | 17:68b3fdabe4c5 | 20 | _Loop =0; |
thomasmorris | 17:68b3fdabe4c5 | 21 | _Wait_Time =0; |
thomasmorris | 17:68b3fdabe4c5 | 22 | _Duty_Cycle =0; |
thomasmorris | 17:68b3fdabe4c5 | 23 | _Power_Time =0; |
thomasmorris | 16:9f98ec0ededb | 24 | } |
thomasmorris | 17:68b3fdabe4c5 | 25 | void INTERFACE::Up()//Up Routine |
thomasmorris | 16:9f98ec0ededb | 26 | { |
thomasmorris | 17:68b3fdabe4c5 | 27 | if (_Function == 0)//Turns Function |
thomasmorris | 16:9f98ec0ededb | 28 | { |
thomasmorris | 16:9f98ec0ededb | 29 | _No_Of_Rotations = _No_Of_Rotations + 1;//Increases Turn number |
thomasmorris | 16:9f98ec0ededb | 30 | _Turns_Todo = _No_Of_Rotations; |
thomasmorris | 16:9f98ec0ededb | 31 | } |
thomasmorris | 17:68b3fdabe4c5 | 32 | else if (_Function == 1)//Annealing Function |
thomasmorris | 16:9f98ec0ededb | 33 | { |
thomasmorris | 17:68b3fdabe4c5 | 34 | if (_Select == false)//Select = 0 |
thomasmorris | 16:9f98ec0ededb | 35 | { |
thomasmorris | 16:9f98ec0ededb | 36 | _Loop = _Loop + 1; //Increases Repetitions in Annealing |
thomasmorris | 16:9f98ec0ededb | 37 | } |
thomasmorris | 17:68b3fdabe4c5 | 38 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 39 | { |
thomasmorris | 16:9f98ec0ededb | 40 | _Wait_Time = _Wait_Time + 1; //Increases Wait time |
thomasmorris | 16:9f98ec0ededb | 41 | } |
thomasmorris | 16:9f98ec0ededb | 42 | } |
thomasmorris | 17:68b3fdabe4c5 | 43 | else if (_Function == 2)//Test Function |
thomasmorris | 16:9f98ec0ededb | 44 | { |
thomasmorris | 17:68b3fdabe4c5 | 45 | if (_Select == false)//Select = 0 |
thomasmorris | 16:9f98ec0ededb | 46 | { |
thomasmorris | 16:9f98ec0ededb | 47 | if (_Duty_Cycle < 100) |
thomasmorris | 16:9f98ec0ededb | 48 | { |
thomasmorris | 16:9f98ec0ededb | 49 | _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle |
thomasmorris | 16:9f98ec0ededb | 50 | } |
thomasmorris | 17:68b3fdabe4c5 | 51 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 52 | { |
thomasmorris | 16:9f98ec0ededb | 53 | _Power_Time = _Power_Time + 1; //Increases time on |
thomasmorris | 16:9f98ec0ededb | 54 | } |
thomasmorris | 16:9f98ec0ededb | 55 | } |
thomasmorris | 16:9f98ec0ededb | 56 | } |
thomasmorris | 16:9f98ec0ededb | 57 | } |
thomasmorris | 17:68b3fdabe4c5 | 58 | void INTERFACE::Down()//Down Routine |
thomasmorris | 16:9f98ec0ededb | 59 | { |
thomasmorris | 17:68b3fdabe4c5 | 60 | if (_Function == 0)//Turn Function |
thomasmorris | 16:9f98ec0ededb | 61 | { |
thomasmorris | 16:9f98ec0ededb | 62 | _No_Of_Rotations = _No_Of_Rotations - 1; |
thomasmorris | 16:9f98ec0ededb | 63 | _Turns_Todo = _No_Of_Rotations; |
thomasmorris | 16:9f98ec0ededb | 64 | } |
thomasmorris | 17:68b3fdabe4c5 | 65 | else if (_Function == 1)//Anneal Function |
thomasmorris | 16:9f98ec0ededb | 66 | { |
thomasmorris | 17:68b3fdabe4c5 | 67 | if (_Select == false)//Select = 0 |
thomasmorris | 16:9f98ec0ededb | 68 | { |
thomasmorris | 21:6d9f6a986647 | 69 | |
thomasmorris | 16:9f98ec0ededb | 70 | if (_Loop > 0) |
thomasmorris | 16:9f98ec0ededb | 71 | { |
thomasmorris | 16:9f98ec0ededb | 72 | _Loop = _Loop - 1; |
thomasmorris | 16:9f98ec0ededb | 73 | } |
thomasmorris | 17:68b3fdabe4c5 | 74 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 75 | { |
thomasmorris | 16:9f98ec0ededb | 76 | if (_Wait_Time > 0) |
thomasmorris | 16:9f98ec0ededb | 77 | { |
thomasmorris | 16:9f98ec0ededb | 78 | _Wait_Time = _Wait_Time - 1; |
thomasmorris | 16:9f98ec0ededb | 79 | } |
thomasmorris | 16:9f98ec0ededb | 80 | } |
thomasmorris | 16:9f98ec0ededb | 81 | } |
thomasmorris | 16:9f98ec0ededb | 82 | } |
thomasmorris | 17:68b3fdabe4c5 | 83 | else if (_Function == 2)//Test Function |
thomasmorris | 16:9f98ec0ededb | 84 | { |
thomasmorris | 17:68b3fdabe4c5 | 85 | if (_Select == false)//Select = 0 |
thomasmorris | 16:9f98ec0ededb | 86 | { |
thomasmorris | 16:9f98ec0ededb | 87 | if (_Duty_Cycle > 0) |
thomasmorris | 16:9f98ec0ededb | 88 | { |
thomasmorris | 16:9f98ec0ededb | 89 | _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty |
thomasmorris | 16:9f98ec0ededb | 90 | } |
thomasmorris | 17:68b3fdabe4c5 | 91 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 92 | { |
thomasmorris | 16:9f98ec0ededb | 93 | if (_Power_Time > 0) |
thomasmorris | 16:9f98ec0ededb | 94 | { |
thomasmorris | 16:9f98ec0ededb | 95 | _Power_Time = _Power_Time - 1; //Decreases Time on |
thomasmorris | 16:9f98ec0ededb | 96 | } |
thomasmorris | 16:9f98ec0ededb | 97 | } |
thomasmorris | 16:9f98ec0ededb | 98 | } |
thomasmorris | 16:9f98ec0ededb | 99 | } |
thomasmorris | 16:9f98ec0ededb | 100 | } |
thomasmorris | 17:68b3fdabe4c5 | 101 | void INTERFACE::Start_Stop()//Start / Stop Routine |
thomasmorris | 16:9f98ec0ededb | 102 | { |
thomasmorris | 16:9f98ec0ededb | 103 | if (_Function == 0)//Twist selected |
thomasmorris | 16:9f98ec0ededb | 104 | { |
thomasmorris | 17:68b3fdabe4c5 | 105 | _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting and Running the code |
thomasmorris | 16:9f98ec0ededb | 106 | } |
thomasmorris | 16:9f98ec0ededb | 107 | else if (_Function == 1) //Annealing selected |
thomasmorris | 16:9f98ec0ededb | 108 | { |
thomasmorris | 17:68b3fdabe4c5 | 109 | _Anneal_Go = !_Anneal_Go;//toggle and Run the code |
thomasmorris | 16:9f98ec0ededb | 110 | } |
thomasmorris | 16:9f98ec0ededb | 111 | else if (_Function == 2) //Testing selected |
thomasmorris | 16:9f98ec0ededb | 112 | { |
thomasmorris | 17:68b3fdabe4c5 | 113 | _Test_Go = !_Test_Go;//toggle and run the code |
thomasmorris | 16:9f98ec0ededb | 114 | } |
thomasmorris | 16:9f98ec0ededb | 115 | } |
thomasmorris | 17:68b3fdabe4c5 | 116 | void INTERFACE::Function()//Function Routine used to increment through the three functions |
thomasmorris | 16:9f98ec0ededb | 117 | { |
thomasmorris | 17:68b3fdabe4c5 | 118 | /* |
thomasmorris | 17:68b3fdabe4c5 | 119 | Function 0 = Turn |
thomasmorris | 17:68b3fdabe4c5 | 120 | Function 1 = Anneal |
thomasmorris | 17:68b3fdabe4c5 | 121 | Function 2 = Test |
thomasmorris | 17:68b3fdabe4c5 | 122 | */ |
thomasmorris | 16:9f98ec0ededb | 123 | if (_Function < 2){ |
thomasmorris | 16:9f98ec0ededb | 124 | _Function = _Function + 1; |
thomasmorris | 16:9f98ec0ededb | 125 | } |
thomasmorris | 16:9f98ec0ededb | 126 | else |
thomasmorris | 16:9f98ec0ededb | 127 | { |
thomasmorris | 16:9f98ec0ededb | 128 | _Function = 0; |
thomasmorris | 16:9f98ec0ededb | 129 | } |
thomasmorris | 16:9f98ec0ededb | 130 | } |
thomasmorris | 17:68b3fdabe4c5 | 131 | void INTERFACE::Select()//Select Routine |
thomasmorris | 16:9f98ec0ededb | 132 | { |
thomasmorris | 17:68b3fdabe4c5 | 133 | _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible |
thomasmorris | 21:6d9f6a986647 | 134 | if(_Select == false) |
thomasmorris | 21:6d9f6a986647 | 135 | { |
thomasmorris | 21:6d9f6a986647 | 136 | Led_Select_Left = 1; |
thomasmorris | 21:6d9f6a986647 | 137 | Led_Select_Right= 0; |
thomasmorris | 21:6d9f6a986647 | 138 | } |
thomasmorris | 21:6d9f6a986647 | 139 | else |
thomasmorris | 21:6d9f6a986647 | 140 | { |
thomasmorris | 21:6d9f6a986647 | 141 | Led_Select_Left = 0; |
thomasmorris | 21:6d9f6a986647 | 142 | Led_Select_Right= 1; |
thomasmorris | 21:6d9f6a986647 | 143 | } |
thomasmorris | 17:68b3fdabe4c5 | 144 | //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led |
thomasmorris | 16:9f98ec0ededb | 145 | } |
thomasmorris | 17:68b3fdabe4c5 | 146 | void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed |
thomasmorris | 16:9f98ec0ededb | 147 | { |
thomasmorris | 16:9f98ec0ededb | 148 | if (_Function == 0) //Turning Code |
thomasmorris | 16:9f98ec0ededb | 149 | { |
thomasmorris | 16:9f98ec0ededb | 150 | if (_Twist_Go == true) |
thomasmorris | 16:9f98ec0ededb | 151 | { |
thomasmorris | 21:6d9f6a986647 | 152 | Led_Power = 1; |
thomasmorris | 18:3523660f3930 | 153 | //printf("20 Turns\n"); |
thomasmorris | 17:68b3fdabe4c5 | 154 | //STEPPER_MOTOR_1.Rotate_Steps(22); |
thomasmorris | 17:68b3fdabe4c5 | 155 | STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo);//Rotates for the specified number of steps given |
thomasmorris | 17:68b3fdabe4c5 | 156 | _Twist_Go = false; |
thomasmorris | 21:6d9f6a986647 | 157 | Led_Power = 0; |
thomasmorris | 16:9f98ec0ededb | 158 | } |
thomasmorris | 16:9f98ec0ededb | 159 | } |
thomasmorris | 16:9f98ec0ededb | 160 | else if (_Function == 1) //Annealing Code |
thomasmorris | 16:9f98ec0ededb | 161 | { |
thomasmorris | 16:9f98ec0ededb | 162 | if (_Anneal_Go == true) |
thomasmorris | 16:9f98ec0ededb | 163 | { |
thomasmorris | 21:6d9f6a986647 | 164 | Led_Power = 1; |
thomasmorris | 16:9f98ec0ededb | 165 | for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works |
thomasmorris | 16:9f98ec0ededb | 166 | { |
thomasmorris | 16:9f98ec0ededb | 167 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 16:9f98ec0ededb | 168 | Tendon_Power=1; // set duty cycle to 100% |
thomasmorris | 16:9f98ec0ededb | 169 | wait(_Wait_Time);//Variable |
thomasmorris | 16:9f98ec0ededb | 170 | Tendon_Power=0; // set duty cycle to 0% |
thomasmorris | 16:9f98ec0ededb | 171 | wait(6);//Fixed off time |
thomasmorris | 16:9f98ec0ededb | 172 | } |
thomasmorris | 17:68b3fdabe4c5 | 173 | _Anneal_Go = false; |
thomasmorris | 21:6d9f6a986647 | 174 | Led_Power = 0; |
thomasmorris | 16:9f98ec0ededb | 175 | } |
thomasmorris | 16:9f98ec0ededb | 176 | } |
thomasmorris | 16:9f98ec0ededb | 177 | else if (_Function == 2) //Testing Code |
thomasmorris | 16:9f98ec0ededb | 178 | { |
thomasmorris | 16:9f98ec0ededb | 179 | if (_Test_Go == true) |
thomasmorris | 16:9f98ec0ededb | 180 | { |
thomasmorris | 21:6d9f6a986647 | 181 | Led_Power = 1; |
thomasmorris | 16:9f98ec0ededb | 182 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 16:9f98ec0ededb | 183 | 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 | 184 | wait(_Power_Time);//Variable on time for power on |
thomasmorris | 16:9f98ec0ededb | 185 | Tendon_Power=0; // set duty cycle to 0% and power off |
thomasmorris | 17:68b3fdabe4c5 | 186 | _Test_Go = false; |
thomasmorris | 21:6d9f6a986647 | 187 | Led_Power = 0; |
thomasmorris | 16:9f98ec0ededb | 188 | } |
thomasmorris | 16:9f98ec0ededb | 189 | } |
thomasmorris | 16:9f98ec0ededb | 190 | } |
thomasmorris | 17:68b3fdabe4c5 | 191 | //Setter functions |
thomasmorris | 16:9f98ec0ededb | 192 | void INTERFACE::Set_No_Of_Rotations(int Rotations){_No_Of_Rotations = Rotations;} |
thomasmorris | 16:9f98ec0ededb | 193 | void INTERFACE::Set_Function(int Function){_Function = Function;} |
thomasmorris | 16:9f98ec0ededb | 194 | void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go = Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 195 | void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go = Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 196 | void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go = Test_Go;} |
thomasmorris | 16:9f98ec0ededb | 197 | void INTERFACE::Set_Select(bool Select){_Select = Select;} |
thomasmorris | 16:9f98ec0ededb | 198 | void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done = Turns_Done;} |
thomasmorris | 16:9f98ec0ededb | 199 | void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo = Turns_Todo;} |
thomasmorris | 16:9f98ec0ededb | 200 | void INTERFACE::Set_Loop(int Loop){Loop = Loop;} |
thomasmorris | 16:9f98ec0ededb | 201 | void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time = Wait_Time;} |
thomasmorris | 16:9f98ec0ededb | 202 | void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle = Duty_Cycle;} |
thomasmorris | 16:9f98ec0ededb | 203 | void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time = Power_Time;} |
thomasmorris | 17:68b3fdabe4c5 | 204 | //Getter functions |
thomasmorris | 16:9f98ec0ededb | 205 | int INTERFACE::Get_No_Of_Rotations(){return _No_Of_Rotations;} |
thomasmorris | 16:9f98ec0ededb | 206 | int INTERFACE::Get_Function(){return _Function;} |
thomasmorris | 16:9f98ec0ededb | 207 | bool INTERFACE::Get_Twist_Go(){return _Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 208 | bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 209 | bool INTERFACE::Get_Test_Go(){return _Test_Go;} |
thomasmorris | 16:9f98ec0ededb | 210 | bool INTERFACE::Get_Select(){return _Select;} |
thomasmorris | 18:3523660f3930 | 211 | int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Turns(); return _Turns_Done;} |
thomasmorris | 18:3523660f3930 | 212 | //int INTERFACE::Get_Turns_Done(){return _Turns_Done;} |
thomasmorris | 17:68b3fdabe4c5 | 213 | |
thomasmorris | 16:9f98ec0ededb | 214 | int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} |
thomasmorris | 16:9f98ec0ededb | 215 | int INTERFACE::Get_Loop(){return _Loop;} |
thomasmorris | 16:9f98ec0ededb | 216 | int INTERFACE::Get_Wait_Time(){return _Wait_Time;} |
thomasmorris | 16:9f98ec0ededb | 217 | int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} |
thomasmorris | 16:9f98ec0ededb | 218 | int INTERFACE::Get_Power_Time(){return _Power_Time;} |