Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Thu Feb 14 10:22:54 2019 +0000
Revision:
21:6d9f6a986647
Parent:
20:c943b74eb3bd
Child:
22:fc2186b610b5
Debounce code added

Who changed what in which revision?

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