Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Revision:
26:83550fc299aa
Parent:
25:9751619fa030
Child:
27:22d6fd88828e
diff -r 9751619fa030 -r 83550fc299aa main.cpp
--- a/main.cpp	Mon Feb 18 22:04:54 2019 +0000
+++ b/main.cpp	Tue Feb 19 14:40:01 2019 +0000
@@ -1,18 +1,60 @@
 #include "SETUP.hpp"
-
-//Thread signal functions
-void up_signal_rise(){up_thread.signal_set(1);}            //Sets the up thread to operate
-void down_signal_rise(){down_thread.signal_set(1);}        //Sets the down thread to operate
-void start_signal_rise(){start_stop_thread.signal_set(1);} //Sets the start thread to operate
-void function_signal_rise(){function_thread.signal_set(1);}//Sets the function thread to operate
-void select_signal_rise(){select_thread.signal_set(1);}    //Sets the select thread to operate
-void up_signal_fall(){up_thread.signal_set(2);}            //Sets the up thread to operate
-void down_signal_fall(){down_thread.signal_set(2);}        //Sets the down thread to operate
-void start_signal_fall(){start_stop_thread.signal_set(2);} //Sets the start thread to operate
-void function_signal_fall(){function_thread.signal_set(2);}//Sets the function thread to operate
-void select_signal_fall(){select_thread.signal_set(2);}    //Sets the select thread to operate
-
-void LCD_thread(){//Output data to the LCD for the interface
+void Polling_thread_function()// Polling thread for the buttons
+{
+    while(1)
+    {
+        //printf("In polling\n");//Check the value
+        if(button_up.read() == 0)
+        {
+            printf("Up button read\n");
+            Thread::wait(Debounce_Time);
+            if(button_up.read() == 1)
+            {   
+                printf("Up button released\n");
+                up_thread.signal_set(1);
+            }   
+        }
+        if(button_down.read() == 0)
+        {
+            printf("Down button read\n");
+            Thread::wait(Debounce_Time);
+            if(button_down.read() == 1)
+            {
+                down_thread.signal_set(1);
+            }  
+        }
+        if(button_start.read() == 0)
+        {
+            printf("Start/Stop button read\n");
+            Thread::wait(Debounce_Time);
+            if(button_start.read() == 1)
+            {
+                start_stop_thread.signal_set(1);
+            }   
+        }
+        if(button_function.read() == 0)
+        {
+            printf("Function button read\n");
+            Thread::wait(Debounce_Time);
+            if(button_function.read() == 1)
+            {
+                function_thread.signal_set(1);
+            }   
+        }
+        if(button_select.read() == 0)
+        {
+            printf("Select button read\n");
+            Thread::wait(Debounce_Time);
+            if(button_select.read() == 1)
+            {
+                select_thread.signal_set(1);
+            }   
+        }
+        Thread::wait(50);   
+    }   
+}
+void LCD_thread()//Output data to the LCD for the interface
+{
     while(1)
     {
         lcd.cls();//Clear the LCD screen
@@ -35,12 +77,12 @@
         }
         else if(INTERFACE.Get_Function() == 2)//Coil
         {
-            lcd.printf("Mode: Turn\n");
+            lcd.printf("Mode: Coil\n");
             lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
         }
         else if(INTERFACE.Get_Function() == 3)//Twist
         {
-            lcd.printf("Mode: Turn\n");
+            lcd.printf("Mode: Twist\n");
             lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
         }
         Thread::wait(250);//Refresh rate for Lcd
@@ -65,81 +107,70 @@
         
         */
         Thread::signal_wait(1);  //Wait to be signaled by the up button interrupt
-        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
-        if(INTERFACE.Get_Function() == 0 || INTERFACE.Get_Function() == 1)
-        {
-            Thread::signal_wait(2);  //Wait to be signaled by the up button interrupt
-        }
+        pc.printf("Up Button Pressed in thread function\n");//Output data to the putty terminal
+        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs this debouce time might need to be longer
         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);  //Wait to be signaled by the up button interrupt
+         /*
+        Thread::signal_wait(1);  //Wait to be signaled by the down button interrupt
         Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
-        Thread::signal_wait(2);  //Wait to be signaled by the up button interrupt
+        Thread::signal_wait(2);  //Wait to be signaled by the down button interrupt
+        
+        */
+        Thread::signal_wait(1);  //Wait to be signaled by the down button interrupt
+        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer
         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::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
-        Thread::signal_wait(2);  //Wait to be signaled by the up button interrupt
+        Thread::signal_wait(1);  //Wait to be signaled by the start / stop button interrupt
+        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer
         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
+        //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);  //Wait to be signaled by the up button interrupt
-        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
-        Thread::signal_wait(2);  //Wait to be signaled by the up button interrupt
+        Thread::signal_wait(1);  //Wait to be signaled by the function button interrupt
+        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer
         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
+        //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);  //Wait to be signaled by the up button interrupt
-        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
-        Thread::signal_wait(2);  //Wait to be signaled by the up button interrupt
+        Thread::signal_wait(1);  //Wait to be signaled by the select button interrupt
+        Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer
         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
+        //Thread::wait(1000);//Button debounce to prevent multiple re-runs
     }
 }
 int main() 
 {
     //Interrupt setters
-    button_up.rise(&up_signal_rise);         //Sets up Up button
-    button_down.rise(&down_signal_rise);     //Sets up Down Button
-    button_start.rise(&start_signal_rise);  //Sets up Start/Stop Button
-    button_funct.rise(&function_signal_rise);//Sets up Function Button
-    button_select.rise(&select_signal_rise); //Sets up Select Button
-    button_up.fall(&up_signal_fall);         //Sets up Up button
-    button_down.fall(&down_signal_fall);     //Sets up Down Button
-    button_start.fall(&start_signal_fall);   //Sets up Start/Stop Button
-    button_funct.fall(&function_signal_fall);//Sets up Function Button
-    button_select.fall(&select_signal_fall); //Sets up Select Button
+
     
     lcd.printf("Ready   Player\n");
     lcd.printf("     One      \n");
@@ -147,6 +178,7 @@
     pc.printf("Program start\n");//Outputs informtation to the putty terminal
     
     //Thread Starts
+    polling_thread.start(Polling_thread_function);//Start the button polling
     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