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