![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Interface/Interface.cpp@17:68b3fdabe4c5, 2019-02-12 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Feb 12 10:03:05 2019 +0000
- Revision:
- 17:68b3fdabe4c5
- Parent:
- 16:9f98ec0ededb
- Child:
- 18:3523660f3930
Working Code;
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 | 16:9f98ec0ededb | 69 | if (_Loop > 0) |
thomasmorris | 16:9f98ec0ededb | 70 | { |
thomasmorris | 16:9f98ec0ededb | 71 | _Loop = _Loop - 1; |
thomasmorris | 16:9f98ec0ededb | 72 | } |
thomasmorris | 17:68b3fdabe4c5 | 73 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 74 | { |
thomasmorris | 16:9f98ec0ededb | 75 | if (_Wait_Time > 0) |
thomasmorris | 16:9f98ec0ededb | 76 | { |
thomasmorris | 16:9f98ec0ededb | 77 | _Wait_Time = _Wait_Time - 1; |
thomasmorris | 16:9f98ec0ededb | 78 | } |
thomasmorris | 16:9f98ec0ededb | 79 | } |
thomasmorris | 16:9f98ec0ededb | 80 | } |
thomasmorris | 16:9f98ec0ededb | 81 | } |
thomasmorris | 17:68b3fdabe4c5 | 82 | else if (_Function == 2)//Test Function |
thomasmorris | 16:9f98ec0ededb | 83 | { |
thomasmorris | 17:68b3fdabe4c5 | 84 | if (_Select == false)//Select = 0 |
thomasmorris | 16:9f98ec0ededb | 85 | { |
thomasmorris | 16:9f98ec0ededb | 86 | if (_Duty_Cycle > 0) |
thomasmorris | 16:9f98ec0ededb | 87 | { |
thomasmorris | 16:9f98ec0ededb | 88 | _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty |
thomasmorris | 16:9f98ec0ededb | 89 | } |
thomasmorris | 17:68b3fdabe4c5 | 90 | else if (_Select == true)//Select = 1 |
thomasmorris | 16:9f98ec0ededb | 91 | { |
thomasmorris | 16:9f98ec0ededb | 92 | if (_Power_Time > 0) |
thomasmorris | 16:9f98ec0ededb | 93 | { |
thomasmorris | 16:9f98ec0ededb | 94 | _Power_Time = _Power_Time - 1; //Decreases Time on |
thomasmorris | 16:9f98ec0ededb | 95 | } |
thomasmorris | 16:9f98ec0ededb | 96 | } |
thomasmorris | 16:9f98ec0ededb | 97 | } |
thomasmorris | 16:9f98ec0ededb | 98 | } |
thomasmorris | 16:9f98ec0ededb | 99 | } |
thomasmorris | 17:68b3fdabe4c5 | 100 | void INTERFACE::Start_Stop()//Start / Stop Routine |
thomasmorris | 16:9f98ec0ededb | 101 | { |
thomasmorris | 16:9f98ec0ededb | 102 | if (_Function == 0)//Twist selected |
thomasmorris | 16:9f98ec0ededb | 103 | { |
thomasmorris | 17:68b3fdabe4c5 | 104 | _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting and Running the code |
thomasmorris | 16:9f98ec0ededb | 105 | } |
thomasmorris | 16:9f98ec0ededb | 106 | else if (_Function == 1) //Annealing selected |
thomasmorris | 16:9f98ec0ededb | 107 | { |
thomasmorris | 17:68b3fdabe4c5 | 108 | _Anneal_Go = !_Anneal_Go;//toggle and Run the code |
thomasmorris | 16:9f98ec0ededb | 109 | } |
thomasmorris | 16:9f98ec0ededb | 110 | else if (_Function == 2) //Testing selected |
thomasmorris | 16:9f98ec0ededb | 111 | { |
thomasmorris | 17:68b3fdabe4c5 | 112 | _Test_Go = !_Test_Go;//toggle and run the code |
thomasmorris | 16:9f98ec0ededb | 113 | } |
thomasmorris | 16:9f98ec0ededb | 114 | } |
thomasmorris | 17:68b3fdabe4c5 | 115 | void INTERFACE::Function()//Function Routine used to increment through the three functions |
thomasmorris | 16:9f98ec0ededb | 116 | { |
thomasmorris | 17:68b3fdabe4c5 | 117 | /* |
thomasmorris | 17:68b3fdabe4c5 | 118 | Function 0 = Turn |
thomasmorris | 17:68b3fdabe4c5 | 119 | Function 1 = Anneal |
thomasmorris | 17:68b3fdabe4c5 | 120 | Function 2 = Test |
thomasmorris | 17:68b3fdabe4c5 | 121 | */ |
thomasmorris | 16:9f98ec0ededb | 122 | if (_Function < 2){ |
thomasmorris | 16:9f98ec0ededb | 123 | _Function = _Function + 1; |
thomasmorris | 16:9f98ec0ededb | 124 | } |
thomasmorris | 16:9f98ec0ededb | 125 | else |
thomasmorris | 16:9f98ec0ededb | 126 | { |
thomasmorris | 16:9f98ec0ededb | 127 | _Function = 0; |
thomasmorris | 16:9f98ec0ededb | 128 | } |
thomasmorris | 16:9f98ec0ededb | 129 | } |
thomasmorris | 17:68b3fdabe4c5 | 130 | void INTERFACE::Select()//Select Routine |
thomasmorris | 16:9f98ec0ededb | 131 | { |
thomasmorris | 17:68b3fdabe4c5 | 132 | _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible |
thomasmorris | 17:68b3fdabe4c5 | 133 | //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led |
thomasmorris | 16:9f98ec0ededb | 134 | } |
thomasmorris | 17:68b3fdabe4c5 | 135 | void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed |
thomasmorris | 16:9f98ec0ededb | 136 | { |
thomasmorris | 16:9f98ec0ededb | 137 | if (_Function == 0) //Turning Code |
thomasmorris | 16:9f98ec0ededb | 138 | { |
thomasmorris | 16:9f98ec0ededb | 139 | if (_Twist_Go == true) |
thomasmorris | 16:9f98ec0ededb | 140 | { |
thomasmorris | 17:68b3fdabe4c5 | 141 | printf("20 Turns\n"); |
thomasmorris | 17:68b3fdabe4c5 | 142 | //STEPPER_MOTOR_1.Rotate_Steps(22); |
thomasmorris | 17:68b3fdabe4c5 | 143 | STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo);//Rotates for the specified number of steps given |
thomasmorris | 17:68b3fdabe4c5 | 144 | _Twist_Go = false; |
thomasmorris | 16:9f98ec0ededb | 145 | } |
thomasmorris | 16:9f98ec0ededb | 146 | } |
thomasmorris | 16:9f98ec0ededb | 147 | else if (_Function == 1) //Annealing Code |
thomasmorris | 16:9f98ec0ededb | 148 | { |
thomasmorris | 16:9f98ec0ededb | 149 | if (_Anneal_Go == true) |
thomasmorris | 16:9f98ec0ededb | 150 | { |
thomasmorris | 16:9f98ec0ededb | 151 | for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works |
thomasmorris | 16:9f98ec0ededb | 152 | { |
thomasmorris | 16:9f98ec0ededb | 153 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 16:9f98ec0ededb | 154 | Tendon_Power=1; // set duty cycle to 100% |
thomasmorris | 16:9f98ec0ededb | 155 | wait(_Wait_Time);//Variable |
thomasmorris | 16:9f98ec0ededb | 156 | Tendon_Power=0; // set duty cycle to 0% |
thomasmorris | 16:9f98ec0ededb | 157 | wait(6);//Fixed off time |
thomasmorris | 16:9f98ec0ededb | 158 | } |
thomasmorris | 17:68b3fdabe4c5 | 159 | _Anneal_Go = false; |
thomasmorris | 16:9f98ec0ededb | 160 | } |
thomasmorris | 16:9f98ec0ededb | 161 | } |
thomasmorris | 16:9f98ec0ededb | 162 | else if (_Function == 2) //Testing Code |
thomasmorris | 16:9f98ec0ededb | 163 | { |
thomasmorris | 16:9f98ec0ededb | 164 | if (_Test_Go == true) |
thomasmorris | 16:9f98ec0ededb | 165 | { |
thomasmorris | 16:9f98ec0ededb | 166 | Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare |
thomasmorris | 16:9f98ec0ededb | 167 | 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 | 168 | wait(_Power_Time);//Variable on time for power on |
thomasmorris | 16:9f98ec0ededb | 169 | Tendon_Power=0; // set duty cycle to 0% and power off |
thomasmorris | 17:68b3fdabe4c5 | 170 | _Test_Go = false; |
thomasmorris | 16:9f98ec0ededb | 171 | } |
thomasmorris | 16:9f98ec0ededb | 172 | } |
thomasmorris | 16:9f98ec0ededb | 173 | } |
thomasmorris | 17:68b3fdabe4c5 | 174 | //Setter functions |
thomasmorris | 16:9f98ec0ededb | 175 | void INTERFACE::Set_No_Of_Rotations(int Rotations){_No_Of_Rotations = Rotations;} |
thomasmorris | 16:9f98ec0ededb | 176 | void INTERFACE::Set_Function(int Function){_Function = Function;} |
thomasmorris | 16:9f98ec0ededb | 177 | void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go = Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 178 | void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go = Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 179 | void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go = Test_Go;} |
thomasmorris | 16:9f98ec0ededb | 180 | void INTERFACE::Set_Select(bool Select){_Select = Select;} |
thomasmorris | 16:9f98ec0ededb | 181 | void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done = Turns_Done;} |
thomasmorris | 16:9f98ec0ededb | 182 | void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo = Turns_Todo;} |
thomasmorris | 16:9f98ec0ededb | 183 | void INTERFACE::Set_Loop(int Loop){Loop = Loop;} |
thomasmorris | 16:9f98ec0ededb | 184 | void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time = Wait_Time;} |
thomasmorris | 16:9f98ec0ededb | 185 | void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle = Duty_Cycle;} |
thomasmorris | 16:9f98ec0ededb | 186 | void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time = Power_Time;} |
thomasmorris | 17:68b3fdabe4c5 | 187 | //Getter functions |
thomasmorris | 16:9f98ec0ededb | 188 | int INTERFACE::Get_No_Of_Rotations(){return _No_Of_Rotations;} |
thomasmorris | 16:9f98ec0ededb | 189 | int INTERFACE::Get_Function(){return _Function;} |
thomasmorris | 16:9f98ec0ededb | 190 | bool INTERFACE::Get_Twist_Go(){return _Twist_Go;} |
thomasmorris | 16:9f98ec0ededb | 191 | bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;} |
thomasmorris | 16:9f98ec0ededb | 192 | bool INTERFACE::Get_Test_Go(){return _Test_Go;} |
thomasmorris | 16:9f98ec0ededb | 193 | bool INTERFACE::Get_Select(){return _Select;} |
thomasmorris | 17:68b3fdabe4c5 | 194 | //int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Steps_Done(); return _Turns_Done;} |
thomasmorris | 17:68b3fdabe4c5 | 195 | int INTERFACE::Get_Turns_Done(){return _Turns_Done;} |
thomasmorris | 17:68b3fdabe4c5 | 196 | |
thomasmorris | 16:9f98ec0ededb | 197 | int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} |
thomasmorris | 16:9f98ec0ededb | 198 | int INTERFACE::Get_Loop(){return _Loop;} |
thomasmorris | 16:9f98ec0ededb | 199 | int INTERFACE::Get_Wait_Time(){return _Wait_Time;} |
thomasmorris | 16:9f98ec0ededb | 200 | int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} |
thomasmorris | 16:9f98ec0ededb | 201 | int INTERFACE::Get_Power_Time(){return _Power_Time;} |