![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Diff: Interface/Interface.cpp
- Revision:
- 17:68b3fdabe4c5
- Parent:
- 16:9f98ec0ededb
- Child:
- 18:3523660f3930
--- a/Interface/Interface.cpp Mon Feb 11 22:03:47 2019 +0000 +++ b/Interface/Interface.cpp Tue Feb 12 10:03:05 2019 +0000 @@ -1,65 +1,76 @@ #include "Interface.hpp" //Include the header file, this acts like a series of forward declarations PwmOut Tendon_Power(PE_8); //Constructor -INTERFACE::INTERFACE() +INTERFACE::INTERFACE(int Default_Turns)//Set all values to 0 { - + _Turns_Todo = Default_Turns; } INTERFACE::~INTERFACE(){} //Destructor //Interrupt run functions -void INTERFACE::Interface_Init() +void INTERFACE::Interface_Init()//Set all values to 0 bar the default turns { - + _No_Of_Rotations =20; + _Function =0; + _Twist_Go =0; + _Anneal_Go =0; + _Test_Go =0; + _Select =0; + _Turns_Done =0; + _Turns_Todo =20; + _Loop =0; + _Wait_Time =0; + _Duty_Cycle =0; + _Power_Time =0; } -void INTERFACE::Up() +void INTERFACE::Up()//Up Routine { - if (_Function == 0) + if (_Function == 0)//Turns Function { _No_Of_Rotations = _No_Of_Rotations + 1;//Increases Turn number _Turns_Todo = _No_Of_Rotations; } - else if (_Function == 1) + else if (_Function == 1)//Annealing Function { - if (_Select == false) + if (_Select == false)//Select = 0 { _Loop = _Loop + 1; //Increases Repetitions in Annealing } - else if (_Select == true) + else if (_Select == true)//Select = 1 { _Wait_Time = _Wait_Time + 1; //Increases Wait time } } - else if (_Function == 2) + else if (_Function == 2)//Test Function { - if (_Select == false) + if (_Select == false)//Select = 0 { if (_Duty_Cycle < 100) { _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle } - else if (_Select == true) + else if (_Select == true)//Select = 1 { _Power_Time = _Power_Time + 1; //Increases time on } } } } -void INTERFACE::Down() +void INTERFACE::Down()//Down Routine { - if (_Function == 0) + if (_Function == 0)//Turn Function { _No_Of_Rotations = _No_Of_Rotations - 1; _Turns_Todo = _No_Of_Rotations; } - else if (_Function == 1) + else if (_Function == 1)//Anneal Function { - if (_Select == false) + if (_Select == false)//Select = 0 { if (_Loop > 0) { _Loop = _Loop - 1; } - else if (_Select == true) + else if (_Select == true)//Select = 1 { if (_Wait_Time > 0) { @@ -68,15 +79,15 @@ } } } - else if (_Function == 2) + else if (_Function == 2)//Test Function { - if (_Select == false) + if (_Select == false)//Select = 0 { if (_Duty_Cycle > 0) { _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty } - else if (_Select == true) + else if (_Select == true)//Select = 1 { if (_Power_Time > 0) { @@ -86,23 +97,28 @@ } } } -void INTERFACE::Start_Stop() +void INTERFACE::Start_Stop()//Start / Stop Routine { if (_Function == 0)//Twist selected { - _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting + _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting and Running the code } else if (_Function == 1) //Annealing selected { - _Anneal_Go = !_Anneal_Go;//toggle + _Anneal_Go = !_Anneal_Go;//toggle and Run the code } else if (_Function == 2) //Testing selected { - _Test_Go = !_Test_Go;//toggle + _Test_Go = !_Test_Go;//toggle and run the code } } -void INTERFACE::Function() +void INTERFACE::Function()//Function Routine used to increment through the three functions { + /* + Function 0 = Turn + Function 1 = Anneal + Function 2 = Test + */ if (_Function < 2){ _Function = _Function + 1; } @@ -111,17 +127,21 @@ _Function = 0; } } -void INTERFACE::Select() +void INTERFACE::Select()//Select Routine { - _Select = !_Select; + _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible + //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led } -void INTERFACE::Interface_main() +void INTERFACE::Interface_main()//Main Routine to execute commands when the start button has been pressed { if (_Function == 0) //Turning Code { if (_Twist_Go == true) { - STEPPER_MOTOR_1.Rotate_Steps(_No_Of_Rotations);//Rotates for the specified number of steps given + printf("20 Turns\n"); + //STEPPER_MOTOR_1.Rotate_Steps(22); + STEPPER_MOTOR_1.Rotate_Steps(_Turns_Todo);//Rotates for the specified number of steps given + _Twist_Go = false; } } else if (_Function == 1) //Annealing Code @@ -136,6 +156,7 @@ Tendon_Power=0; // set duty cycle to 0% wait(6);//Fixed off time } + _Anneal_Go = false; } } else if (_Function == 2) //Testing Code @@ -146,10 +167,11 @@ 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 wait(_Power_Time);//Variable on time for power on Tendon_Power=0; // set duty cycle to 0% and power off + _Test_Go = false; } } } - +//Setter functions void INTERFACE::Set_No_Of_Rotations(int Rotations){_No_Of_Rotations = Rotations;} void INTERFACE::Set_Function(int Function){_Function = Function;} void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go = Twist_Go;} @@ -162,14 +184,16 @@ void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time = Wait_Time;} void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle = Duty_Cycle;} void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time = Power_Time;} -//Getters +//Getter functions int INTERFACE::Get_No_Of_Rotations(){return _No_Of_Rotations;} int INTERFACE::Get_Function(){return _Function;} bool INTERFACE::Get_Twist_Go(){return _Twist_Go;} bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;} bool INTERFACE::Get_Test_Go(){return _Test_Go;} bool INTERFACE::Get_Select(){return _Select;} -int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Steps_Done(); return _Turns_Done;} +//int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Steps_Done(); return _Turns_Done;} +int INTERFACE::Get_Turns_Done(){return _Turns_Done;} + int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;} int INTERFACE::Get_Loop(){return _Loop;} int INTERFACE::Get_Wait_Time(){return _Wait_Time;}