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-18
- Revision:
- 25:9751619fa030
- Parent:
- 24:728de4bf961e
- Child:
- 26:83550fc299aa
File content as of revision 25:9751619fa030:
#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
while(1)
{
lcd.cls();//Clear the LCD screen
if(INTERFACE.Get_Function() == 0)//Anneal
{
lcd.printf("Mode: Anneal\n");
if(INTERFACE.Get_Select() == 0 || INTERFACE.Get_Select() == 1)
{
lcd.printf("Loop:%d On_t:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_On_Time());
}
else if(INTERFACE.Get_Select() == 2)
{
lcd.printf("Loop:%d Offt:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Off_Time());
}
}
else if(INTERFACE.Get_Function() == 1)//Test
{
lcd.printf("Mode: Test\n");
lcd.printf("Duty: %dTime: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
}
else if(INTERFACE.Get_Function() == 2)//Coil
{
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() == 3)//Twist
{
lcd.printf("Mode: Turn\n");
lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
}
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
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 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
}
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::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
Thread::signal_wait(2); //Wait to be signaled by the up 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::wait(Debounce_Time); //Button debounce to prevent multiple re-runs
Thread::signal_wait(2); //Wait to be signaled by the up 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 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
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 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
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_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");
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);//This is done to make sure the code for the stepper motor is the highest priority to ensure correct rotations of the stepper motor
INTERFACE.Interface_Init();
while(1)// Main code in a main thread
{
INTERFACE.Interface_main();//Run main thread code
Thread::wait(10);//Small delay to save CPU time
}
}