Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Mon Feb 11 22:03:47 2019 +0000
Revision:
16:9f98ec0ededb
Child:
17:68b3fdabe4c5
Class Structure interface

Who changed what in which revision?

UserRevisionLine numberNew 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 16:9f98ec0ededb 4 INTERFACE::INTERFACE()
thomasmorris 16:9f98ec0ededb 5 {
thomasmorris 16:9f98ec0ededb 6
thomasmorris 16:9f98ec0ededb 7 }
thomasmorris 16:9f98ec0ededb 8 INTERFACE::~INTERFACE(){} //Destructor
thomasmorris 16:9f98ec0ededb 9 //Interrupt run functions
thomasmorris 16:9f98ec0ededb 10 void INTERFACE::Interface_Init()
thomasmorris 16:9f98ec0ededb 11 {
thomasmorris 16:9f98ec0ededb 12
thomasmorris 16:9f98ec0ededb 13 }
thomasmorris 16:9f98ec0ededb 14 void INTERFACE::Up()
thomasmorris 16:9f98ec0ededb 15 {
thomasmorris 16:9f98ec0ededb 16 if (_Function == 0)
thomasmorris 16:9f98ec0ededb 17 {
thomasmorris 16:9f98ec0ededb 18 _No_Of_Rotations = _No_Of_Rotations + 1;//Increases Turn number
thomasmorris 16:9f98ec0ededb 19 _Turns_Todo = _No_Of_Rotations;
thomasmorris 16:9f98ec0ededb 20 }
thomasmorris 16:9f98ec0ededb 21 else if (_Function == 1)
thomasmorris 16:9f98ec0ededb 22 {
thomasmorris 16:9f98ec0ededb 23 if (_Select == false)
thomasmorris 16:9f98ec0ededb 24 {
thomasmorris 16:9f98ec0ededb 25 _Loop = _Loop + 1; //Increases Repetitions in Annealing
thomasmorris 16:9f98ec0ededb 26 }
thomasmorris 16:9f98ec0ededb 27 else if (_Select == true)
thomasmorris 16:9f98ec0ededb 28 {
thomasmorris 16:9f98ec0ededb 29 _Wait_Time = _Wait_Time + 1; //Increases Wait time
thomasmorris 16:9f98ec0ededb 30 }
thomasmorris 16:9f98ec0ededb 31 }
thomasmorris 16:9f98ec0ededb 32 else if (_Function == 2)
thomasmorris 16:9f98ec0ededb 33 {
thomasmorris 16:9f98ec0ededb 34 if (_Select == false)
thomasmorris 16:9f98ec0ededb 35 {
thomasmorris 16:9f98ec0ededb 36 if (_Duty_Cycle < 100)
thomasmorris 16:9f98ec0ededb 37 {
thomasmorris 16:9f98ec0ededb 38 _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle
thomasmorris 16:9f98ec0ededb 39 }
thomasmorris 16:9f98ec0ededb 40 else if (_Select == true)
thomasmorris 16:9f98ec0ededb 41 {
thomasmorris 16:9f98ec0ededb 42 _Power_Time = _Power_Time + 1; //Increases time on
thomasmorris 16:9f98ec0ededb 43 }
thomasmorris 16:9f98ec0ededb 44 }
thomasmorris 16:9f98ec0ededb 45 }
thomasmorris 16:9f98ec0ededb 46 }
thomasmorris 16:9f98ec0ededb 47 void INTERFACE::Down()
thomasmorris 16:9f98ec0ededb 48 {
thomasmorris 16:9f98ec0ededb 49 if (_Function == 0)
thomasmorris 16:9f98ec0ededb 50 {
thomasmorris 16:9f98ec0ededb 51 _No_Of_Rotations = _No_Of_Rotations - 1;
thomasmorris 16:9f98ec0ededb 52 _Turns_Todo = _No_Of_Rotations;
thomasmorris 16:9f98ec0ededb 53 }
thomasmorris 16:9f98ec0ededb 54 else if (_Function == 1)
thomasmorris 16:9f98ec0ededb 55 {
thomasmorris 16:9f98ec0ededb 56 if (_Select == false)
thomasmorris 16:9f98ec0ededb 57 {
thomasmorris 16:9f98ec0ededb 58 if (_Loop > 0)
thomasmorris 16:9f98ec0ededb 59 {
thomasmorris 16:9f98ec0ededb 60 _Loop = _Loop - 1;
thomasmorris 16:9f98ec0ededb 61 }
thomasmorris 16:9f98ec0ededb 62 else if (_Select == true)
thomasmorris 16:9f98ec0ededb 63 {
thomasmorris 16:9f98ec0ededb 64 if (_Wait_Time > 0)
thomasmorris 16:9f98ec0ededb 65 {
thomasmorris 16:9f98ec0ededb 66 _Wait_Time = _Wait_Time - 1;
thomasmorris 16:9f98ec0ededb 67 }
thomasmorris 16:9f98ec0ededb 68 }
thomasmorris 16:9f98ec0ededb 69 }
thomasmorris 16:9f98ec0ededb 70 }
thomasmorris 16:9f98ec0ededb 71 else if (_Function == 2)
thomasmorris 16:9f98ec0ededb 72 {
thomasmorris 16:9f98ec0ededb 73 if (_Select == false)
thomasmorris 16:9f98ec0ededb 74 {
thomasmorris 16:9f98ec0ededb 75 if (_Duty_Cycle > 0)
thomasmorris 16:9f98ec0ededb 76 {
thomasmorris 16:9f98ec0ededb 77 _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty
thomasmorris 16:9f98ec0ededb 78 }
thomasmorris 16:9f98ec0ededb 79 else if (_Select == true)
thomasmorris 16:9f98ec0ededb 80 {
thomasmorris 16:9f98ec0ededb 81 if (_Power_Time > 0)
thomasmorris 16:9f98ec0ededb 82 {
thomasmorris 16:9f98ec0ededb 83 _Power_Time = _Power_Time - 1; //Decreases Time on
thomasmorris 16:9f98ec0ededb 84 }
thomasmorris 16:9f98ec0ededb 85 }
thomasmorris 16:9f98ec0ededb 86 }
thomasmorris 16:9f98ec0ededb 87 }
thomasmorris 16:9f98ec0ededb 88 }
thomasmorris 16:9f98ec0ededb 89 void INTERFACE::Start_Stop()
thomasmorris 16:9f98ec0ededb 90 {
thomasmorris 16:9f98ec0ededb 91 if (_Function == 0)//Twist selected
thomasmorris 16:9f98ec0ededb 92 {
thomasmorris 16:9f98ec0ededb 93 _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting
thomasmorris 16:9f98ec0ededb 94 }
thomasmorris 16:9f98ec0ededb 95 else if (_Function == 1) //Annealing selected
thomasmorris 16:9f98ec0ededb 96 {
thomasmorris 16:9f98ec0ededb 97 _Anneal_Go = !_Anneal_Go;//toggle
thomasmorris 16:9f98ec0ededb 98 }
thomasmorris 16:9f98ec0ededb 99 else if (_Function == 2) //Testing selected
thomasmorris 16:9f98ec0ededb 100 {
thomasmorris 16:9f98ec0ededb 101 _Test_Go = !_Test_Go;//toggle
thomasmorris 16:9f98ec0ededb 102 }
thomasmorris 16:9f98ec0ededb 103 }
thomasmorris 16:9f98ec0ededb 104 void INTERFACE::Function()
thomasmorris 16:9f98ec0ededb 105 {
thomasmorris 16:9f98ec0ededb 106 if (_Function < 2){
thomasmorris 16:9f98ec0ededb 107 _Function = _Function + 1;
thomasmorris 16:9f98ec0ededb 108 }
thomasmorris 16:9f98ec0ededb 109 else
thomasmorris 16:9f98ec0ededb 110 {
thomasmorris 16:9f98ec0ededb 111 _Function = 0;
thomasmorris 16:9f98ec0ededb 112 }
thomasmorris 16:9f98ec0ededb 113 }
thomasmorris 16:9f98ec0ededb 114 void INTERFACE::Select()
thomasmorris 16:9f98ec0ededb 115 {
thomasmorris 16:9f98ec0ededb 116 _Select = !_Select;
thomasmorris 16:9f98ec0ededb 117 }
thomasmorris 16:9f98ec0ededb 118 void INTERFACE::Interface_main()
thomasmorris 16:9f98ec0ededb 119 {
thomasmorris 16:9f98ec0ededb 120 if (_Function == 0) //Turning Code
thomasmorris 16:9f98ec0ededb 121 {
thomasmorris 16:9f98ec0ededb 122 if (_Twist_Go == true)
thomasmorris 16:9f98ec0ededb 123 {
thomasmorris 16:9f98ec0ededb 124 STEPPER_MOTOR_1.Rotate_Steps(_No_Of_Rotations);//Rotates for the specified number of steps given
thomasmorris 16:9f98ec0ededb 125 }
thomasmorris 16:9f98ec0ededb 126 }
thomasmorris 16:9f98ec0ededb 127 else if (_Function == 1) //Annealing Code
thomasmorris 16:9f98ec0ededb 128 {
thomasmorris 16:9f98ec0ededb 129 if (_Anneal_Go == true)
thomasmorris 16:9f98ec0ededb 130 {
thomasmorris 16:9f98ec0ededb 131 for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works
thomasmorris 16:9f98ec0ededb 132 {
thomasmorris 16:9f98ec0ededb 133 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 16:9f98ec0ededb 134 Tendon_Power=1; // set duty cycle to 100%
thomasmorris 16:9f98ec0ededb 135 wait(_Wait_Time);//Variable
thomasmorris 16:9f98ec0ededb 136 Tendon_Power=0; // set duty cycle to 0%
thomasmorris 16:9f98ec0ededb 137 wait(6);//Fixed off time
thomasmorris 16:9f98ec0ededb 138 }
thomasmorris 16:9f98ec0ededb 139 }
thomasmorris 16:9f98ec0ededb 140 }
thomasmorris 16:9f98ec0ededb 141 else if (_Function == 2) //Testing Code
thomasmorris 16:9f98ec0ededb 142 {
thomasmorris 16:9f98ec0ededb 143 if (_Test_Go == true)
thomasmorris 16:9f98ec0ededb 144 {
thomasmorris 16:9f98ec0ededb 145 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 16:9f98ec0ededb 146 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 147 wait(_Power_Time);//Variable on time for power on
thomasmorris 16:9f98ec0ededb 148 Tendon_Power=0; // set duty cycle to 0% and power off
thomasmorris 16:9f98ec0ededb 149 }
thomasmorris 16:9f98ec0ededb 150 }
thomasmorris 16:9f98ec0ededb 151 }
thomasmorris 16:9f98ec0ededb 152
thomasmorris 16:9f98ec0ededb 153 void INTERFACE::Set_No_Of_Rotations(int Rotations){_No_Of_Rotations = Rotations;}
thomasmorris 16:9f98ec0ededb 154 void INTERFACE::Set_Function(int Function){_Function = Function;}
thomasmorris 16:9f98ec0ededb 155 void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go = Twist_Go;}
thomasmorris 16:9f98ec0ededb 156 void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go = Anneal_Go;}
thomasmorris 16:9f98ec0ededb 157 void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go = Test_Go;}
thomasmorris 16:9f98ec0ededb 158 void INTERFACE::Set_Select(bool Select){_Select = Select;}
thomasmorris 16:9f98ec0ededb 159 void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done = Turns_Done;}
thomasmorris 16:9f98ec0ededb 160 void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo = Turns_Todo;}
thomasmorris 16:9f98ec0ededb 161 void INTERFACE::Set_Loop(int Loop){Loop = Loop;}
thomasmorris 16:9f98ec0ededb 162 void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time = Wait_Time;}
thomasmorris 16:9f98ec0ededb 163 void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle = Duty_Cycle;}
thomasmorris 16:9f98ec0ededb 164 void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time = Power_Time;}
thomasmorris 16:9f98ec0ededb 165 //Getters
thomasmorris 16:9f98ec0ededb 166 int INTERFACE::Get_No_Of_Rotations(){return _No_Of_Rotations;}
thomasmorris 16:9f98ec0ededb 167 int INTERFACE::Get_Function(){return _Function;}
thomasmorris 16:9f98ec0ededb 168 bool INTERFACE::Get_Twist_Go(){return _Twist_Go;}
thomasmorris 16:9f98ec0ededb 169 bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;}
thomasmorris 16:9f98ec0ededb 170 bool INTERFACE::Get_Test_Go(){return _Test_Go;}
thomasmorris 16:9f98ec0ededb 171 bool INTERFACE::Get_Select(){return _Select;}
thomasmorris 16:9f98ec0ededb 172 int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Steps_Done(); return _Turns_Done;}
thomasmorris 16:9f98ec0ededb 173 int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;}
thomasmorris 16:9f98ec0ededb 174 int INTERFACE::Get_Loop(){return _Loop;}
thomasmorris 16:9f98ec0ededb 175 int INTERFACE::Get_Wait_Time(){return _Wait_Time;}
thomasmorris 16:9f98ec0ededb 176 int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;}
thomasmorris 16:9f98ec0ededb 177 int INTERFACE::Get_Power_Time(){return _Power_Time;}