![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
main.cpp@25:9751619fa030, 2019-02-18 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Feb 18 22:04:54 2019 +0000
- Revision:
- 25:9751619fa030
- Parent:
- 24:728de4bf961e
- Child:
- 26:83550fc299aa
GET IN THE BIN
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 12:d9c133b360b0 | 1 | #include "SETUP.hpp" |
thomasmorris | 21:6d9f6a986647 | 2 | |
thomasmorris | 23:07a368f2cdb1 | 3 | //Thread signal functions |
thomasmorris | 21:6d9f6a986647 | 4 | void up_signal_rise(){up_thread.signal_set(1);} //Sets the up thread to operate |
thomasmorris | 21:6d9f6a986647 | 5 | void down_signal_rise(){down_thread.signal_set(1);} //Sets the down thread to operate |
thomasmorris | 21:6d9f6a986647 | 6 | void start_signal_rise(){start_stop_thread.signal_set(1);} //Sets the start thread to operate |
thomasmorris | 21:6d9f6a986647 | 7 | void function_signal_rise(){function_thread.signal_set(1);}//Sets the function thread to operate |
thomasmorris | 21:6d9f6a986647 | 8 | void select_signal_rise(){select_thread.signal_set(1);} //Sets the select thread to operate |
thomasmorris | 21:6d9f6a986647 | 9 | void up_signal_fall(){up_thread.signal_set(2);} //Sets the up thread to operate |
thomasmorris | 21:6d9f6a986647 | 10 | void down_signal_fall(){down_thread.signal_set(2);} //Sets the down thread to operate |
thomasmorris | 21:6d9f6a986647 | 11 | void start_signal_fall(){start_stop_thread.signal_set(2);} //Sets the start thread to operate |
thomasmorris | 21:6d9f6a986647 | 12 | void function_signal_fall(){function_thread.signal_set(2);}//Sets the function thread to operate |
thomasmorris | 21:6d9f6a986647 | 13 | void select_signal_fall(){select_thread.signal_set(2);} //Sets the select thread to operate |
thomasmorris | 21:6d9f6a986647 | 14 | |
thomasmorris | 17:68b3fdabe4c5 | 15 | void LCD_thread(){//Output data to the LCD for the interface |
thomasmorris | 16:9f98ec0ededb | 16 | while(1) |
thomasmorris | 16:9f98ec0ededb | 17 | { |
thomasmorris | 17:68b3fdabe4c5 | 18 | lcd.cls();//Clear the LCD screen |
thomasmorris | 25:9751619fa030 | 19 | if(INTERFACE.Get_Function() == 0)//Anneal |
thomasmorris | 25:9751619fa030 | 20 | { |
thomasmorris | 25:9751619fa030 | 21 | lcd.printf("Mode: Anneal\n"); |
thomasmorris | 25:9751619fa030 | 22 | if(INTERFACE.Get_Select() == 0 || INTERFACE.Get_Select() == 1) |
thomasmorris | 25:9751619fa030 | 23 | { |
thomasmorris | 25:9751619fa030 | 24 | lcd.printf("Loop:%d On_t:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_On_Time()); |
thomasmorris | 25:9751619fa030 | 25 | } |
thomasmorris | 25:9751619fa030 | 26 | else if(INTERFACE.Get_Select() == 2) |
thomasmorris | 25:9751619fa030 | 27 | { |
thomasmorris | 25:9751619fa030 | 28 | lcd.printf("Loop:%d Offt:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Off_Time()); |
thomasmorris | 25:9751619fa030 | 29 | } |
thomasmorris | 25:9751619fa030 | 30 | } |
thomasmorris | 25:9751619fa030 | 31 | else if(INTERFACE.Get_Function() == 1)//Test |
thomasmorris | 25:9751619fa030 | 32 | { |
thomasmorris | 25:9751619fa030 | 33 | lcd.printf("Mode: Test\n"); |
thomasmorris | 25:9751619fa030 | 34 | lcd.printf("Duty: %dTime: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time()); |
thomasmorris | 25:9751619fa030 | 35 | } |
thomasmorris | 25:9751619fa030 | 36 | else if(INTERFACE.Get_Function() == 2)//Coil |
thomasmorris | 16:9f98ec0ededb | 37 | { |
thomasmorris | 14:63998be3d43c | 38 | lcd.printf("Mode: Turn\n"); |
thomasmorris | 18:3523660f3930 | 39 | lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do()); |
thomasmorris | 16:9f98ec0ededb | 40 | } |
thomasmorris | 25:9751619fa030 | 41 | else if(INTERFACE.Get_Function() == 3)//Twist |
thomasmorris | 16:9f98ec0ededb | 42 | { |
thomasmorris | 25:9751619fa030 | 43 | lcd.printf("Mode: Turn\n"); |
thomasmorris | 25:9751619fa030 | 44 | lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do()); |
thomasmorris | 12:d9c133b360b0 | 45 | } |
thomasmorris | 17:68b3fdabe4c5 | 46 | Thread::wait(250);//Refresh rate for Lcd |
thomasmorris | 12:d9c133b360b0 | 47 | } |
thomasmorris | 12:d9c133b360b0 | 48 | } |
thomasmorris | 17:68b3fdabe4c5 | 49 | void LED_thread(){//Led thread to toggle the on board led to show the CPU is running |
thomasmorris | 16:9f98ec0ededb | 50 | while (1) |
thomasmorris | 16:9f98ec0ededb | 51 | { |
thomasmorris | 17:68b3fdabe4c5 | 52 | led2 = !led2; //Toggle the LED |
thomasmorris | 17:68b3fdabe4c5 | 53 | Thread::wait(1000);//Wait 1 second |
emilmont | 1:491820ee784d | 54 | } |
emilmont | 1:491820ee784d | 55 | } |
thomasmorris | 12:d9c133b360b0 | 56 | //Interrupt functions |
thomasmorris | 16:9f98ec0ededb | 57 | void up_thread_function()//Action if the up button is pressed increment |
thomasmorris | 16:9f98ec0ededb | 58 | { |
thomasmorris | 14:63998be3d43c | 59 | while(1) |
thomasmorris | 14:63998be3d43c | 60 | { |
thomasmorris | 25:9751619fa030 | 61 | /* |
thomasmorris | 17:68b3fdabe4c5 | 62 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 21:6d9f6a986647 | 63 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 21:6d9f6a986647 | 64 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 25:9751619fa030 | 65 | |
thomasmorris | 25:9751619fa030 | 66 | */ |
thomasmorris | 25:9751619fa030 | 67 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 25:9751619fa030 | 68 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 25:9751619fa030 | 69 | if(INTERFACE.Get_Function() == 0 || INTERFACE.Get_Function() == 1) |
thomasmorris | 25:9751619fa030 | 70 | { |
thomasmorris | 25:9751619fa030 | 71 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 25:9751619fa030 | 72 | } |
thomasmorris | 17:68b3fdabe4c5 | 73 | up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 74 | pc.printf("Up Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 75 | INTERFACE.Up(); //Run the interface up routine |
thomasmorris | 17:68b3fdabe4c5 | 76 | Thread::wait(1000); //Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 77 | } |
thomasmorris | 14:63998be3d43c | 78 | } |
thomasmorris | 16:9f98ec0ededb | 79 | void down_thread_function() //Action if the down button is pressed decrement |
thomasmorris | 16:9f98ec0ededb | 80 | { |
thomasmorris | 14:63998be3d43c | 81 | while(1) |
thomasmorris | 14:63998be3d43c | 82 | { |
thomasmorris | 21:6d9f6a986647 | 83 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 21:6d9f6a986647 | 84 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 21:6d9f6a986647 | 85 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 86 | down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 87 | pc.printf("Down Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 88 | INTERFACE.Down();//Run the interface down routine |
thomasmorris | 17:68b3fdabe4c5 | 89 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 12:d9c133b360b0 | 90 | } |
thomasmorris | 12:d9c133b360b0 | 91 | } |
thomasmorris | 16:9f98ec0ededb | 92 | void start_stop_thread_function() //Action if the Start/Stop button is pressed |
thomasmorris | 16:9f98ec0ededb | 93 | { |
thomasmorris | 14:63998be3d43c | 94 | while(1) |
thomasmorris | 14:63998be3d43c | 95 | { |
thomasmorris | 21:6d9f6a986647 | 96 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 21:6d9f6a986647 | 97 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 98 | start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 99 | pc.printf("S/S Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 100 | INTERFACE.Start_Stop();//Run the interface start / stop routine |
thomasmorris | 17:68b3fdabe4c5 | 101 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 102 | } |
thomasmorris | 14:63998be3d43c | 103 | } |
thomasmorris | 16:9f98ec0ededb | 104 | void Function_Selection_thread_function()//Action if the Function button is pressed |
thomasmorris | 16:9f98ec0ededb | 105 | { |
thomasmorris | 14:63998be3d43c | 106 | while(1) |
thomasmorris | 14:63998be3d43c | 107 | { |
thomasmorris | 21:6d9f6a986647 | 108 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 21:6d9f6a986647 | 109 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 21:6d9f6a986647 | 110 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 111 | function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 112 | pc.printf("Function Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 113 | INTERFACE.Function();//Run the interface function routine |
thomasmorris | 17:68b3fdabe4c5 | 114 | Thread::wait(2000);//Button debounce to prevent multiple re-runs |
emilmont | 1:491820ee784d | 115 | } |
emilmont | 1:491820ee784d | 116 | } |
thomasmorris | 16:9f98ec0ededb | 117 | void Selection_thread_function()//Action if the Select button is pressed |
thomasmorris | 16:9f98ec0ededb | 118 | { |
thomasmorris | 14:63998be3d43c | 119 | while(1) |
thomasmorris | 14:63998be3d43c | 120 | { |
thomasmorris | 21:6d9f6a986647 | 121 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 21:6d9f6a986647 | 122 | Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs |
thomasmorris | 21:6d9f6a986647 | 123 | Thread::signal_wait(2); //Wait to be signaled by the up button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 124 | select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 125 | pc.printf("Select Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 126 | INTERFACE.Select();//Run the interface selection routine |
thomasmorris | 17:68b3fdabe4c5 | 127 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 128 | } |
thomasmorris | 12:d9c133b360b0 | 129 | } |
thomasmorris | 12:d9c133b360b0 | 130 | int main() |
thomasmorris | 12:d9c133b360b0 | 131 | { |
thomasmorris | 12:d9c133b360b0 | 132 | //Interrupt setters |
thomasmorris | 21:6d9f6a986647 | 133 | button_up.rise(&up_signal_rise); //Sets up Up button |
thomasmorris | 21:6d9f6a986647 | 134 | button_down.rise(&down_signal_rise); //Sets up Down Button |
thomasmorris | 21:6d9f6a986647 | 135 | button_start.rise(&start_signal_rise); //Sets up Start/Stop Button |
thomasmorris | 21:6d9f6a986647 | 136 | button_funct.rise(&function_signal_rise);//Sets up Function Button |
thomasmorris | 21:6d9f6a986647 | 137 | button_select.rise(&select_signal_rise); //Sets up Select Button |
thomasmorris | 21:6d9f6a986647 | 138 | button_up.fall(&up_signal_fall); //Sets up Up button |
thomasmorris | 21:6d9f6a986647 | 139 | button_down.fall(&down_signal_fall); //Sets up Down Button |
thomasmorris | 21:6d9f6a986647 | 140 | button_start.fall(&start_signal_fall); //Sets up Start/Stop Button |
thomasmorris | 21:6d9f6a986647 | 141 | button_funct.fall(&function_signal_fall);//Sets up Function Button |
thomasmorris | 21:6d9f6a986647 | 142 | button_select.fall(&select_signal_fall); //Sets up Select Button |
thomasmorris | 17:68b3fdabe4c5 | 143 | |
thomasmorris | 17:68b3fdabe4c5 | 144 | lcd.printf("Ready Player\n"); |
thomasmorris | 17:68b3fdabe4c5 | 145 | lcd.printf(" One \n"); |
thomasmorris | 17:68b3fdabe4c5 | 146 | Thread::wait(1000); |
thomasmorris | 17:68b3fdabe4c5 | 147 | pc.printf("Program start\n");//Outputs informtation to the putty terminal |
thomasmorris | 14:63998be3d43c | 148 | |
thomasmorris | 14:63998be3d43c | 149 | //Thread Starts |
thomasmorris | 17:68b3fdabe4c5 | 150 | lcd_thread.start(LCD_thread);//Output data to LCD |
thomasmorris | 17:68b3fdabe4c5 | 151 | led_thread.start(LED_thread);//Blinking led to show CPU running |
thomasmorris | 17:68b3fdabe4c5 | 152 | up_thread.start(up_thread_function);//UP interface thread |
thomasmorris | 17:68b3fdabe4c5 | 153 | down_thread.start(down_thread_function);//Down interface thread |
thomasmorris | 17:68b3fdabe4c5 | 154 | start_stop_thread.start(start_stop_thread_function);//Start / stop interface thread |
thomasmorris | 17:68b3fdabe4c5 | 155 | function_thread.start(Function_Selection_thread_function);//Function interface thread |
thomasmorris | 17:68b3fdabe4c5 | 156 | select_thread.start(Selection_thread_function);//Start interface thread |
mwthewsey | 19:384642f39496 | 157 | |
thomasmorris | 23:07a368f2cdb1 | 158 | osThreadSetPriority(osThreadGetId(), osPriorityHigh);//This is done to make sure the code for the stepper motor is the highest priority to ensure correct rotations of the stepper motor |
thomasmorris | 24:728de4bf961e | 159 | INTERFACE.Interface_Init(); |
thomasmorris | 17:68b3fdabe4c5 | 160 | while(1)// Main code in a main thread |
thomasmorris | 12:d9c133b360b0 | 161 | { |
thomasmorris | 17:68b3fdabe4c5 | 162 | INTERFACE.Interface_main();//Run main thread code |
mwthewsey | 19:384642f39496 | 163 | Thread::wait(10);//Small delay to save CPU time |
thomasmorris | 16:9f98ec0ededb | 164 | } |
thomasmorris | 12:d9c133b360b0 | 165 | } |