Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos TextLCD
main.cpp
- Committer:
- thomasmorris
- Date:
- 2019-02-12
- Revision:
- 20:c943b74eb3bd
- Parent:
- 19:384642f39496
- Child:
- 21:6d9f6a986647
File content as of revision 20:c943b74eb3bd:
#include "SETUP.hpp"
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 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(){//Output data to the LCD for the interface
while(1)
{
lcd.cls();//Clear the LCD screen
if(INTERFACE.Get_Function() == 0)//Turn
{
lcd.printf("Mode: Turn\n");
lcd.printf("Done:%dToDo: %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);//Refresh rate for Lcd
}
}
void LED_thread(){//Led thread to toggle the on board led to show the CPU is running
while (1)
{
led2 = !led2; //Toggle the LED
Thread::wait(1000);//Wait 1 second
}
}
//Interrupt functions
void up_thread_function()//Action if the up button is pressed increment
{
while(1)
{
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);//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);//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);//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);//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
//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);//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
osThreadSetPriority(osThreadGetId(), osPriorityHigh);
while(1)// Main code in a main thread
{
INTERFACE.Interface_main();//Run main thread code
Thread::wait(10);//Small delay to save CPU time
}
}