Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
main.cpp@17:68b3fdabe4c5, 2019-02-12 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Feb 12 10:03:05 2019 +0000
- Revision:
- 17:68b3fdabe4c5
- Parent:
- 16:9f98ec0ededb
- Child:
- 18:3523660f3930
Working Code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 12:d9c133b360b0 | 1 | #include "SETUP.hpp" |
thomasmorris | 17:68b3fdabe4c5 | 2 | INTERFACE INTERFACE(20); |
thomasmorris | 12:d9c133b360b0 | 3 | //Thread Functions |
thomasmorris | 17:68b3fdabe4c5 | 4 | void up_signal(){up_thread.signal_set(1);} //Sets the up thread to operate |
thomasmorris | 17:68b3fdabe4c5 | 5 | void down_signal(){down_thread.signal_set(1);} //Sets the down thread to operate |
thomasmorris | 17:68b3fdabe4c5 | 6 | void start_signal(){start_stop_thread.signal_set(1);} //Sets the start thread to operate |
thomasmorris | 14:63998be3d43c | 7 | void function_signal(){function_thread.signal_set(1);}//Sets the function thread to operate |
thomasmorris | 17:68b3fdabe4c5 | 8 | void select_signal(){select_thread.signal_set(1);} //Sets the select thread to operate |
thomasmorris | 17:68b3fdabe4c5 | 9 | void LCD_thread(){//Output data to the LCD for the interface |
thomasmorris | 16:9f98ec0ededb | 10 | while(1) |
thomasmorris | 16:9f98ec0ededb | 11 | { |
thomasmorris | 17:68b3fdabe4c5 | 12 | lcd.cls();//Clear the LCD screen |
thomasmorris | 16:9f98ec0ededb | 13 | if(INTERFACE.Get_Function() == 0)//Turn |
thomasmorris | 16:9f98ec0ededb | 14 | { |
thomasmorris | 14:63998be3d43c | 15 | lcd.printf("Mode: Turn\n"); |
thomasmorris | 16:9f98ec0ededb | 16 | lcd.printf("Done: %d ToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do()); |
thomasmorris | 16:9f98ec0ededb | 17 | } |
thomasmorris | 16:9f98ec0ededb | 18 | else if(INTERFACE.Get_Function() == 1)//Anneal |
thomasmorris | 16:9f98ec0ededb | 19 | { |
thomasmorris | 12:d9c133b360b0 | 20 | lcd.printf("Mode: Anneal\n"); |
thomasmorris | 16:9f98ec0ededb | 21 | lcd.printf("Loop:%d Wait:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Wait_Time()); |
thomasmorris | 14:63998be3d43c | 22 | |
thomasmorris | 16:9f98ec0ededb | 23 | }else if(INTERFACE.Get_Function() == 2)//Test |
thomasmorris | 16:9f98ec0ededb | 24 | { |
thomasmorris | 12:d9c133b360b0 | 25 | lcd.printf("Mode: Test\n"); |
thomasmorris | 16:9f98ec0ededb | 26 | lcd.printf("Duty: %d Time: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time()); |
thomasmorris | 12:d9c133b360b0 | 27 | } |
thomasmorris | 17:68b3fdabe4c5 | 28 | Thread::wait(250);//Refresh rate for Lcd |
thomasmorris | 12:d9c133b360b0 | 29 | } |
thomasmorris | 12:d9c133b360b0 | 30 | } |
thomasmorris | 17:68b3fdabe4c5 | 31 | void LED_thread(){//Led thread to toggle the on board led to show the CPU is running |
thomasmorris | 16:9f98ec0ededb | 32 | while (1) |
thomasmorris | 16:9f98ec0ededb | 33 | { |
thomasmorris | 17:68b3fdabe4c5 | 34 | led2 = !led2; //Toggle the LED |
thomasmorris | 17:68b3fdabe4c5 | 35 | Thread::wait(1000);//Wait 1 second |
emilmont | 1:491820ee784d | 36 | } |
emilmont | 1:491820ee784d | 37 | } |
thomasmorris | 12:d9c133b360b0 | 38 | //Interrupt functions |
thomasmorris | 16:9f98ec0ededb | 39 | void up_thread_function()//Action if the up button is pressed increment |
thomasmorris | 16:9f98ec0ededb | 40 | { |
thomasmorris | 14:63998be3d43c | 41 | while(1) |
thomasmorris | 14:63998be3d43c | 42 | { |
thomasmorris | 17:68b3fdabe4c5 | 43 | Thread::signal_wait(1); //Wait to be signaled by the up button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 44 | up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 45 | pc.printf("Up Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 46 | INTERFACE.Up(); //Run the interface up routine |
thomasmorris | 17:68b3fdabe4c5 | 47 | Thread::wait(1000); //Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 48 | } |
thomasmorris | 14:63998be3d43c | 49 | } |
thomasmorris | 16:9f98ec0ededb | 50 | void down_thread_function() //Action if the down button is pressed decrement |
thomasmorris | 16:9f98ec0ededb | 51 | { |
thomasmorris | 14:63998be3d43c | 52 | while(1) |
thomasmorris | 14:63998be3d43c | 53 | { |
thomasmorris | 17:68b3fdabe4c5 | 54 | Thread::signal_wait(1);//Wait to be signaled by the down button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 55 | down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 56 | pc.printf("Down Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 57 | INTERFACE.Down();//Run the interface down routine |
thomasmorris | 17:68b3fdabe4c5 | 58 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 12:d9c133b360b0 | 59 | } |
thomasmorris | 12:d9c133b360b0 | 60 | } |
thomasmorris | 16:9f98ec0ededb | 61 | void start_stop_thread_function() //Action if the Start/Stop button is pressed |
thomasmorris | 16:9f98ec0ededb | 62 | { |
thomasmorris | 14:63998be3d43c | 63 | while(1) |
thomasmorris | 14:63998be3d43c | 64 | { |
thomasmorris | 17:68b3fdabe4c5 | 65 | Thread::signal_wait(1);//Wait to be signaled by the start / stop button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 66 | start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 67 | pc.printf("S/S Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 68 | INTERFACE.Start_Stop();//Run the interface start / stop routine |
thomasmorris | 17:68b3fdabe4c5 | 69 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 70 | } |
thomasmorris | 14:63998be3d43c | 71 | } |
thomasmorris | 16:9f98ec0ededb | 72 | void Function_Selection_thread_function()//Action if the Function button is pressed |
thomasmorris | 16:9f98ec0ededb | 73 | { |
thomasmorris | 14:63998be3d43c | 74 | while(1) |
thomasmorris | 14:63998be3d43c | 75 | { |
thomasmorris | 17:68b3fdabe4c5 | 76 | Thread::signal_wait(1);//Wait to be signaled by the function button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 77 | function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 78 | pc.printf("Function Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 79 | INTERFACE.Function();//Run the interface function routine |
thomasmorris | 17:68b3fdabe4c5 | 80 | Thread::wait(2000);//Button debounce to prevent multiple re-runs |
emilmont | 1:491820ee784d | 81 | } |
emilmont | 1:491820ee784d | 82 | } |
thomasmorris | 16:9f98ec0ededb | 83 | void Selection_thread_function()//Action if the Select button is pressed |
thomasmorris | 16:9f98ec0ededb | 84 | { |
thomasmorris | 14:63998be3d43c | 85 | while(1) |
thomasmorris | 14:63998be3d43c | 86 | { |
thomasmorris | 17:68b3fdabe4c5 | 87 | Thread::signal_wait(1);//Wait to be signaled by the selection button interrupt |
thomasmorris | 17:68b3fdabe4c5 | 88 | select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring |
thomasmorris | 17:68b3fdabe4c5 | 89 | pc.printf("Select Button Pressed\n");//Output data to the putty terminal |
thomasmorris | 17:68b3fdabe4c5 | 90 | INTERFACE.Select();//Run the interface selection routine |
thomasmorris | 17:68b3fdabe4c5 | 91 | Thread::wait(1000);//Button debounce to prevent multiple re-runs |
thomasmorris | 14:63998be3d43c | 92 | } |
thomasmorris | 12:d9c133b360b0 | 93 | } |
thomasmorris | 12:d9c133b360b0 | 94 | int main() |
thomasmorris | 12:d9c133b360b0 | 95 | { |
thomasmorris | 12:d9c133b360b0 | 96 | //Interrupt setters |
thomasmorris | 17:68b3fdabe4c5 | 97 | button_up.rise(&up_signal); //Sets up Up button |
thomasmorris | 17:68b3fdabe4c5 | 98 | button_down.rise(&down_signal); //Sets up Down Button |
thomasmorris | 17:68b3fdabe4c5 | 99 | button_start.rise(&start_signal); //Sets up Start/Stop Button |
thomasmorris | 17:68b3fdabe4c5 | 100 | button_funct.rise(&function_signal);//Sets up Function Button |
thomasmorris | 17:68b3fdabe4c5 | 101 | button_select.rise(&select_signal); //Sets up Select Button |
thomasmorris | 17:68b3fdabe4c5 | 102 | |
thomasmorris | 17:68b3fdabe4c5 | 103 | |
thomasmorris | 17:68b3fdabe4c5 | 104 | //Output data to lcd prior to main code starting |
thomasmorris | 17:68b3fdabe4c5 | 105 | |
thomasmorris | 17:68b3fdabe4c5 | 106 | INTERFACE.Interface_Init(); |
thomasmorris | 17:68b3fdabe4c5 | 107 | lcd.printf("Ready Player\n"); |
thomasmorris | 17:68b3fdabe4c5 | 108 | lcd.printf(" One \n"); |
thomasmorris | 17:68b3fdabe4c5 | 109 | Thread::wait(1000); |
thomasmorris | 17:68b3fdabe4c5 | 110 | pc.printf("Program start\n");//Outputs informtation to the putty terminal |
thomasmorris | 14:63998be3d43c | 111 | |
thomasmorris | 14:63998be3d43c | 112 | //Thread Starts |
thomasmorris | 17:68b3fdabe4c5 | 113 | lcd_thread.start(LCD_thread);//Output data to LCD |
thomasmorris | 17:68b3fdabe4c5 | 114 | led_thread.start(LED_thread);//Blinking led to show CPU running |
thomasmorris | 17:68b3fdabe4c5 | 115 | up_thread.start(up_thread_function);//UP interface thread |
thomasmorris | 17:68b3fdabe4c5 | 116 | down_thread.start(down_thread_function);//Down interface thread |
thomasmorris | 17:68b3fdabe4c5 | 117 | start_stop_thread.start(start_stop_thread_function);//Start / stop interface thread |
thomasmorris | 17:68b3fdabe4c5 | 118 | function_thread.start(Function_Selection_thread_function);//Function interface thread |
thomasmorris | 17:68b3fdabe4c5 | 119 | select_thread.start(Selection_thread_function);//Start interface thread |
thomasmorris | 17:68b3fdabe4c5 | 120 | while(1)// Main code in a main thread |
thomasmorris | 12:d9c133b360b0 | 121 | { |
thomasmorris | 17:68b3fdabe4c5 | 122 | INTERFACE.Interface_main();//Run main thread code |
thomasmorris | 17:68b3fdabe4c5 | 123 | //Thread::wait(10);//Small delay to save CPU time |
thomasmorris | 16:9f98ec0ededb | 124 | } |
thomasmorris | 12:d9c133b360b0 | 125 | } |