Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Mon Feb 11 22:03:47 2019 +0000
Revision:
16:9f98ec0ededb
Parent:
15:7cf5595ed1b1
Child:
17:68b3fdabe4c5
Class Structure interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 12:d9c133b360b0 1 #include "SETUP.hpp"
thomasmorris 16:9f98ec0ededb 2
thomasmorris 16:9f98ec0ededb 3
thomasmorris 16:9f98ec0ededb 4 INTERFACE INTERFACE;
thomasmorris 12:d9c133b360b0 5 //Thread Functions
thomasmorris 14:63998be3d43c 6 void up_signal(){up_thread.signal_set(1);} //Sets the up thread to operate
thomasmorris 14:63998be3d43c 7 void down_signal(){down_thread.signal_set(1);} //Sets the down thread to operate
thomasmorris 14:63998be3d43c 8 void start_signal(){start_stop_thread.signal_set(1);} //Sets the start thread to operate
thomasmorris 14:63998be3d43c 9 void function_signal(){function_thread.signal_set(1);}//Sets the function thread to operate
thomasmorris 16:9f98ec0ededb 10
thomasmorris 14:63998be3d43c 11 void select_signal(){select_thread.signal_set(1);} //Sets the select thread to operate
thomasmorris 12:d9c133b360b0 12 void LCD_thread(){
thomasmorris 16:9f98ec0ededb 13 while(1)
thomasmorris 16:9f98ec0ededb 14 {
thomasmorris 12:d9c133b360b0 15 lcd.cls();
thomasmorris 16:9f98ec0ededb 16 if(INTERFACE.Get_Function() == 0)//Turn
thomasmorris 16:9f98ec0ededb 17 {
thomasmorris 14:63998be3d43c 18 lcd.printf("Mode: Turn\n");
thomasmorris 16:9f98ec0ededb 19 lcd.printf("Done: %d ToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
thomasmorris 16:9f98ec0ededb 20 }
thomasmorris 16:9f98ec0ededb 21 else if(INTERFACE.Get_Function() == 1)//Anneal
thomasmorris 16:9f98ec0ededb 22 {
thomasmorris 12:d9c133b360b0 23 lcd.printf("Mode: Anneal\n");
thomasmorris 16:9f98ec0ededb 24 lcd.printf("Loop:%d Wait:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Wait_Time());
thomasmorris 14:63998be3d43c 25
thomasmorris 16:9f98ec0ededb 26 }else if(INTERFACE.Get_Function() == 2)//Test
thomasmorris 16:9f98ec0ededb 27 {
thomasmorris 12:d9c133b360b0 28 lcd.printf("Mode: Test\n");
thomasmorris 16:9f98ec0ededb 29 lcd.printf("Duty: %d Time: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
thomasmorris 12:d9c133b360b0 30 }
thomasmorris 14:63998be3d43c 31 Thread::wait(250);
thomasmorris 12:d9c133b360b0 32 lcd.cls();
thomasmorris 12:d9c133b360b0 33 }
thomasmorris 12:d9c133b360b0 34 }
thomasmorris 12:d9c133b360b0 35 void LED_thread(){
thomasmorris 16:9f98ec0ededb 36 while (1)
thomasmorris 16:9f98ec0ededb 37 {
emilmont 1:491820ee784d 38 led2 = !led2;
mbed_official 11:0309bef74ba8 39 Thread::wait(1000);
emilmont 1:491820ee784d 40 }
emilmont 1:491820ee784d 41 }
thomasmorris 12:d9c133b360b0 42 //Interrupt functions
thomasmorris 16:9f98ec0ededb 43 void up_thread_function()//Action if the up button is pressed increment
thomasmorris 16:9f98ec0ededb 44 {
thomasmorris 14:63998be3d43c 45 while(1)
thomasmorris 14:63998be3d43c 46 {
thomasmorris 14:63998be3d43c 47 Thread::signal_wait(1);
thomasmorris 14:63998be3d43c 48 up_thread.signal_set(0);
thomasmorris 16:9f98ec0ededb 49 pc.printf("Up Button Pressed\n");
thomasmorris 16:9f98ec0ededb 50 INTERFACE.Up();
thomasmorris 16:9f98ec0ededb 51 Thread::wait(1000);//Button debounce
thomasmorris 14:63998be3d43c 52 }
thomasmorris 14:63998be3d43c 53 }
thomasmorris 16:9f98ec0ededb 54 void down_thread_function() //Action if the down button is pressed decrement
thomasmorris 16:9f98ec0ededb 55 {
thomasmorris 14:63998be3d43c 56 while(1)
thomasmorris 14:63998be3d43c 57 {
thomasmorris 14:63998be3d43c 58 Thread::signal_wait(1);
thomasmorris 14:63998be3d43c 59 down_thread.signal_set(0);
thomasmorris 14:63998be3d43c 60 pc.printf("Down Button Pressed\n");
thomasmorris 16:9f98ec0ededb 61 INTERFACE.Down();
thomasmorris 14:63998be3d43c 62 Thread::wait(1000);//Button debounce
thomasmorris 12:d9c133b360b0 63 }
thomasmorris 12:d9c133b360b0 64 }
thomasmorris 16:9f98ec0ededb 65 void start_stop_thread_function() //Action if the Start/Stop button is pressed
thomasmorris 16:9f98ec0ededb 66 {
thomasmorris 14:63998be3d43c 67 while(1)
thomasmorris 14:63998be3d43c 68 {
thomasmorris 14:63998be3d43c 69 Thread::signal_wait(1);
thomasmorris 14:63998be3d43c 70 start_stop_thread.signal_set(0);
thomasmorris 14:63998be3d43c 71 pc.printf("S/S Button Pressed\n");
thomasmorris 16:9f98ec0ededb 72 INTERFACE.Start_Stop();
thomasmorris 16:9f98ec0ededb 73 Thread::wait(1000);//Button debounce
thomasmorris 14:63998be3d43c 74 }
thomasmorris 14:63998be3d43c 75 }
thomasmorris 16:9f98ec0ededb 76 void Function_Selection_thread_function()//Action if the Function button is pressed
thomasmorris 16:9f98ec0ededb 77 {
thomasmorris 14:63998be3d43c 78 while(1)
thomasmorris 14:63998be3d43c 79 {
thomasmorris 14:63998be3d43c 80 Thread::signal_wait(1);
thomasmorris 14:63998be3d43c 81 function_thread.signal_set(0);
thomasmorris 14:63998be3d43c 82 pc.printf("Function Button Pressed\n");
thomasmorris 16:9f98ec0ededb 83 INTERFACE.Function();
thomasmorris 16:9f98ec0ededb 84 Thread::wait(2000);//Button debounce
emilmont 1:491820ee784d 85 }
emilmont 1:491820ee784d 86 }
thomasmorris 16:9f98ec0ededb 87 void Selection_thread_function()//Action if the Select button is pressed
thomasmorris 16:9f98ec0ededb 88 {
thomasmorris 14:63998be3d43c 89 while(1)
thomasmorris 14:63998be3d43c 90 {
thomasmorris 14:63998be3d43c 91 Thread::signal_wait(1);
thomasmorris 14:63998be3d43c 92 select_thread.signal_set(0);
thomasmorris 14:63998be3d43c 93 pc.printf("Select Button Pressed\n");
thomasmorris 16:9f98ec0ededb 94 INTERFACE.Select();
thomasmorris 14:63998be3d43c 95 Thread::wait(1000);//Button debounce
thomasmorris 14:63998be3d43c 96 }
thomasmorris 12:d9c133b360b0 97 }
thomasmorris 12:d9c133b360b0 98 int main()
thomasmorris 12:d9c133b360b0 99 {
thomasmorris 12:d9c133b360b0 100 //Interrupt setters
thomasmorris 14:63998be3d43c 101 button_up.rise(&up_signal); //Sets up Up button
thomasmorris 14:63998be3d43c 102 button_down.rise(&down_signal); //Sets up Down Button
thomasmorris 14:63998be3d43c 103 button_start.rise(&start_signal); //Sets up Start/Stop Button
thomasmorris 14:63998be3d43c 104 button_funct.rise(&function_signal); //Sets up Function Button
thomasmorris 14:63998be3d43c 105 button_select.rise(&select_signal); //Sets up Select Button
thomasmorris 14:63998be3d43c 106
thomasmorris 14:63998be3d43c 107 //Thread Starts
thomasmorris 14:63998be3d43c 108 lcd_thread.start(LCD_thread);
thomasmorris 14:63998be3d43c 109 led_thread.start(LED_thread);
thomasmorris 14:63998be3d43c 110
thomasmorris 14:63998be3d43c 111 up_thread.start(up_thread_function);
thomasmorris 14:63998be3d43c 112 start_stop_thread.start(start_stop_thread_function);
thomasmorris 14:63998be3d43c 113
thomasmorris 14:63998be3d43c 114 down_thread.start(down_thread_function);
thomasmorris 14:63998be3d43c 115 function_thread.start(Function_Selection_thread_function);
thomasmorris 16:9f98ec0ededb 116 select_thread.start(Selection_thread_function);
thomasmorris 12:d9c133b360b0 117 /*
thomasmorris 14:63998be3d43c 118 Function 0 = Turn
thomasmorris 14:63998be3d43c 119 Function 1 = Anneal
thomasmorris 12:d9c133b360b0 120 Function 2 = Test
thomasmorris 12:d9c133b360b0 121 */
thomasmorris 14:63998be3d43c 122
thomasmorris 14:63998be3d43c 123 pc.printf("Program start\n");//Outputs informtation to the putty terminal
thomasmorris 14:63998be3d43c 124
thomasmorris 14:63998be3d43c 125
thomasmorris 12:d9c133b360b0 126 while(1) // Main code
thomasmorris 12:d9c133b360b0 127 {
thomasmorris 16:9f98ec0ededb 128 INTERFACE.Interface_main();
thomasmorris 16:9f98ec0ededb 129 Thread::wait(100);
thomasmorris 16:9f98ec0ededb 130 }
thomasmorris 12:d9c133b360b0 131 }
thomasmorris 14:63998be3d43c 132
thomasmorris 14:63998be3d43c 133