This has increased comments and a readme

Dependencies:   mbed mbed-rtos TextLCD

main.cpp

Committer:
thomasmorris
Date:
2019-02-11
Revision:
16:9f98ec0ededb
Parent:
15:7cf5595ed1b1
Child:
17:68b3fdabe4c5

File content as of revision 16:9f98ec0ededb:

#include "SETUP.hpp"


INTERFACE INTERFACE;
//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 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(){
    while(1)
    {
        lcd.cls();
        if(INTERFACE.Get_Function() == 0)//Turn
        {
            lcd.printf("Mode: Turn\n");
            lcd.printf("Done: %d ToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
        }
        else if(INTERFACE.Get_Function() == 1)//Anneal
        {
            lcd.printf("Mode: Anneal\n");
            lcd.printf("Loop:%d Wait:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Wait_Time());
      
        }else if(INTERFACE.Get_Function() == 2)//Test
        {
            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();
    } 
}
void LED_thread(){
    while (1)
    {
        led2 = !led2;
        Thread::wait(1000);
    }
}
//Interrupt functions
void up_thread_function()//Action if the up button is pressed increment
{
    while(1)
    {
        Thread::signal_wait(1);
        up_thread.signal_set(0);
        pc.printf("Up Button Pressed\n");  
        INTERFACE.Up();
        Thread::wait(1000);//Button debounce
    }
}
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
    }
}
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
    }
}
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
    }
}
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
    }
}
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
    
    //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
    {
        INTERFACE.Interface_main();
        Thread::wait(100);  
    } 
}