![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Interface/Interface.cpp
- Committer:
- thomasmorris
- Date:
- 2019-02-14
- Revision:
- 21:6d9f6a986647
- Parent:
- 18:3523660f3930
- Child:
- 23:07a368f2cdb1
File content as of revision 21:6d9f6a986647:
#include "Interface.hpp" //Include the header file, this acts like a series of forward declarations PwmOut Tendon_Power(PE_8); //Constructor INTERFACE::INTERFACE(int Default_Turns)//Set all values to 0 { _Turns_Todo = Default_Turns; } INTERFACE::~INTERFACE(){} //Destructor //Interrupt run functions 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()//Up Routine { if (_Function == 0)//Turns Function { _No_Of_Rotations = _No_Of_Rotations + 1;//Increases Turn number _Turns_Todo = _No_Of_Rotations; } else if (_Function == 1)//Annealing Function { if (_Select == false)//Select = 0 { _Loop = _Loop + 1; //Increases Repetitions in Annealing } else if (_Select == true)//Select = 1 { _Wait_Time = _Wait_Time + 1; //Increases Wait time } } else if (_Function == 2)//Test Function { if (_Select == false)//Select = 0 { if (_Duty_Cycle < 100) { _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle } else if (_Select == true)//Select = 1 { _Power_Time = _Power_Time + 1; //Increases time on } } } } void INTERFACE::Down()//Down Routine { if (_Function == 0)//Turn Function { _No_Of_Rotations = _No_Of_Rotations - 1; _Turns_Todo = _No_Of_Rotations; } else if (_Function == 1)//Anneal Function { if (_Select == false)//Select = 0 { if (_Loop > 0) { _Loop = _Loop - 1; } else if (_Select == true)//Select = 1 { if (_Wait_Time > 0) { _Wait_Time = _Wait_Time - 1; } } } } else if (_Function == 2)//Test Function { if (_Select == false)//Select = 0 { if (_Duty_Cycle > 0) { _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty } else if (_Select == true)//Select = 1 { if (_Power_Time > 0) { _Power_Time = _Power_Time - 1; //Decreases Time on } } } } } void INTERFACE::Start_Stop()//Start / Stop Routine { if (_Function == 0)//Twist selected { _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 and Run the code } else if (_Function == 2) //Testing selected { _Test_Go = !_Test_Go;//toggle and run the code } } 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; } else { _Function = 0; } } void INTERFACE::Select()//Select Routine { _Select = !_Select;//Toggle select to choose between two options e.g. Duty cycle and loops as only two options are avalible if(_Select == false) { Led_Select_Left = 1; Led_Select_Right= 0; } else { Led_Select_Left = 0; Led_Select_Right= 1; } //Output to leds here dependant upon the select value e.g. 0 is left led and 1 is right led } 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) { Led_Power = 1; //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; Led_Power = 0; } } else if (_Function == 1) //Annealing Code { if (_Anneal_Go == true) { Led_Power = 1; for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works { Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare Tendon_Power=1; // set duty cycle to 100% wait(_Wait_Time);//Variable Tendon_Power=0; // set duty cycle to 0% wait(6);//Fixed off time } _Anneal_Go = false; Led_Power = 0; } } else if (_Function == 2) //Testing Code { if (_Test_Go == true) { Led_Power = 1; Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare 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; Led_Power = 0; } } } //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;} void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go = Anneal_Go;} void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go = Test_Go;} void INTERFACE::Set_Select(bool Select){_Select = Select;} void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done = Turns_Done;} void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo = Turns_Todo;} void INTERFACE::Set_Loop(int Loop){Loop = Loop;} 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;} //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_Turns(); 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;} int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;} int INTERFACE::Get_Power_Time(){return _Power_Time;}