Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Revision:
17:68b3fdabe4c5
Parent:
16:9f98ec0ededb
Child:
18:3523660f3930
diff -r 9f98ec0ededb -r 68b3fdabe4c5 main.cpp
--- a/main.cpp	Mon Feb 11 22:03:47 2019 +0000
+++ b/main.cpp	Tue Feb 12 10:03:05 2019 +0000
@@ -1,18 +1,15 @@
 #include "SETUP.hpp"
-
-
-INTERFACE INTERFACE;
+INTERFACE INTERFACE(20);
 //Thread Functions
-void up_signal(){up_thread.signal_set(1);}      //Sets the up thread to operate
-void down_signal(){down_thread.signal_set(1);}    //Sets the down thread to operate
-void start_signal(){start_stop_thread.signal_set(1);}   //Sets the start thread to operate
+void up_signal(){up_thread.signal_set(1);}            //Sets the up thread to operate
+void down_signal(){down_thread.signal_set(1);}        //Sets the down thread to operate
+void start_signal(){start_stop_thread.signal_set(1);} //Sets the start thread to operate
 void function_signal(){function_thread.signal_set(1);}//Sets the function thread to operate
-
-void select_signal(){select_thread.signal_set(1);}  //Sets the select thread to operate
-void LCD_thread(){
+void select_signal(){select_thread.signal_set(1);}    //Sets the select thread to operate
+void LCD_thread(){//Output data to the LCD for the interface
     while(1)
     {
-        lcd.cls();
+        lcd.cls();//Clear the LCD screen
         if(INTERFACE.Get_Function() == 0)//Turn
         {
             lcd.printf("Mode: Turn\n");
@@ -28,15 +25,14 @@
             lcd.printf("Mode: Test\n");
             lcd.printf("Duty: %d Time: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
         }
-        Thread::wait(250);
-        lcd.cls();
+        Thread::wait(250);//Refresh rate for Lcd
     } 
 }
-void LED_thread(){
+void LED_thread(){//Led thread to toggle the on board led to show the CPU is running
     while (1)
     {
-        led2 = !led2;
-        Thread::wait(1000);
+        led2 = !led2;      //Toggle the LED
+        Thread::wait(1000);//Wait 1 second
     }
 }
 //Interrupt functions
@@ -44,90 +40,86 @@
 {
     while(1)
     {
-        Thread::signal_wait(1);
-        up_thread.signal_set(0);
-        pc.printf("Up Button Pressed\n");  
-        INTERFACE.Up();
-        Thread::wait(1000);//Button debounce
+        Thread::signal_wait(1);  //Wait to be signaled by the up button interrupt
+        up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring
+        pc.printf("Up Button Pressed\n");//Output data to the putty terminal
+        INTERFACE.Up();     //Run the interface up routine
+        Thread::wait(1000); //Button debounce to prevent multiple re-runs
     }
 }
 void down_thread_function() //Action if the down button is pressed decrement
 {
     while(1)
     {
-        Thread::signal_wait(1);
-        down_thread.signal_set(0);
-        pc.printf("Down Button Pressed\n");
-        INTERFACE.Down();
-         Thread::wait(1000);//Button debounce
+        Thread::signal_wait(1);//Wait to be signaled by the down button interrupt
+        down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring
+        pc.printf("Down Button Pressed\n");//Output data to the putty terminal
+        INTERFACE.Down();//Run the interface down routine
+         Thread::wait(1000);//Button debounce to prevent multiple re-runs
     }
 }
 void start_stop_thread_function() //Action if the Start/Stop button is pressed
 {
     while(1)
     {
-        Thread::signal_wait(1);
-        start_stop_thread.signal_set(0);
-        pc.printf("S/S Button Pressed\n");
-        INTERFACE.Start_Stop();
-        Thread::wait(1000);//Button debounce
+        Thread::signal_wait(1);//Wait to be signaled by the start / stop button interrupt
+        start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring
+        pc.printf("S/S Button Pressed\n");//Output data to the putty terminal
+        INTERFACE.Start_Stop();//Run the interface start / stop routine
+        Thread::wait(1000);//Button debounce to prevent multiple re-runs
     }
 }
 void Function_Selection_thread_function()//Action if the Function button is pressed
 {
     while(1)
     {
-        Thread::signal_wait(1);
-        function_thread.signal_set(0);
-        pc.printf("Function Button Pressed\n");
-        INTERFACE.Function();
-        Thread::wait(2000);//Button debounce
+        Thread::signal_wait(1);//Wait to be signaled by the function button interrupt
+        function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring
+        pc.printf("Function Button Pressed\n");//Output data to the putty terminal
+        INTERFACE.Function();//Run the interface function routine
+        Thread::wait(2000);//Button debounce to prevent multiple re-runs
     }
 }
 void Selection_thread_function()//Action if the Select button is pressed
 {
     while(1)
     {
-        Thread::signal_wait(1);
-        select_thread.signal_set(0);
-        pc.printf("Select Button Pressed\n");
-        INTERFACE.Select();
-        Thread::wait(1000);//Button debounce
+        Thread::signal_wait(1);//Wait to be signaled by the selection button interrupt
+        select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring
+        pc.printf("Select Button Pressed\n");//Output data to the putty terminal
+        INTERFACE.Select();//Run the interface selection routine
+        Thread::wait(1000);//Button debounce to prevent multiple re-runs
     }
 }
 int main() 
 {
     //Interrupt setters
-    button_up.rise(&up_signal);                        //Sets up Up button
-    button_down.rise(&down_signal);                    //Sets up Down Button
-    button_start.rise(&start_signal);             //Sets up Start/Stop Button
-    button_funct.rise(&function_signal);     //Sets up Function Button
-    button_select.rise(&select_signal);             //Sets up Select Button
+    button_up.rise(&up_signal);         //Sets up Up button
+    button_down.rise(&down_signal);     //Sets up Down Button
+    button_start.rise(&start_signal);   //Sets up Start/Stop Button
+    button_funct.rise(&function_signal);//Sets up Function Button
+    button_select.rise(&select_signal); //Sets up Select Button
+    
+
+    //Output data to lcd prior to main code starting
+    
+    INTERFACE.Interface_Init();
+    lcd.printf("Ready   Player\n");
+    lcd.printf("     One      \n");
+    Thread::wait(1000);
+    pc.printf("Program start\n");//Outputs informtation to the putty terminal
     
     //Thread Starts
-    lcd_thread.start(LCD_thread);
-    led_thread.start(LED_thread);  
-      
-    up_thread.start(up_thread_function);
-    start_stop_thread.start(start_stop_thread_function);
-    
-    down_thread.start(down_thread_function);
-    function_thread.start(Function_Selection_thread_function);
-    select_thread.start(Selection_thread_function);    
-    /*
-    Function 0 = Turn
-    Function 1 = Anneal
-    Function 2 = Test
-    */
-
-    pc.printf("Program start\n");//Outputs informtation to the putty terminal
-
-    
-    while(1)            // Main code
+    lcd_thread.start(LCD_thread);//Output data to LCD
+    led_thread.start(LED_thread);//Blinking led to show CPU running    
+    up_thread.start(up_thread_function);//UP interface thread
+    down_thread.start(down_thread_function);//Down interface thread
+    start_stop_thread.start(start_stop_thread_function);//Start / stop interface thread
+    function_thread.start(Function_Selection_thread_function);//Function interface thread
+    select_thread.start(Selection_thread_function);//Start interface thread
+    while(1)// Main code in a main thread
     {
-        INTERFACE.Interface_main();
-        Thread::wait(100);  
+        INTERFACE.Interface_main();//Run main thread code
+        //Thread::wait(10);//Small delay to save CPU time  
     } 
 }
-
-