You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
1.5 KiB
C++
99 lines
1.5 KiB
C++
#include "Run.h"
|
|
#include <iostream>
|
|
|
|
Run::Run(int count) {
|
|
// constructor
|
|
m_bExit = false;
|
|
m_bHalt = false;
|
|
m_state = IDLE;
|
|
|
|
m_myThread = std::thread(&Run::DoTask, this);
|
|
|
|
// assign a member function of a class
|
|
// @link https://thispointer.com//c11-multithreading-part-3-carefully-pass-arguments-to-threads/
|
|
//new_thread dummyObj;
|
|
//m_myThread = std::thread(&new_thread::operator(), &dummyObj, 1);
|
|
|
|
//m_myThread = std::thread(new_thread(), count);
|
|
}
|
|
|
|
Run::~Run()
|
|
{
|
|
}
|
|
|
|
void Run::Maintenance()
|
|
{
|
|
std::cout << "Maintenance";
|
|
}
|
|
|
|
void Run::Auto()
|
|
{
|
|
std::cout << "Auto";
|
|
}
|
|
|
|
void Run::PowerUp()
|
|
{
|
|
std::cout << "PowerUp";
|
|
}
|
|
|
|
void Run::DoTask()
|
|
{
|
|
while (true)
|
|
{
|
|
std::cout << "DoTask";
|
|
|
|
|
|
switch (m_state)
|
|
{
|
|
case POWERUP:
|
|
{
|
|
PowerUp();
|
|
break;
|
|
}
|
|
|
|
case AUTO:
|
|
{
|
|
Auto();
|
|
break;
|
|
}
|
|
|
|
case MAINTENANCE:
|
|
{
|
|
Maintenance();
|
|
break;
|
|
}
|
|
|
|
case IDLE:
|
|
{
|
|
std::cout << "Idling...";
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
std::cout << "Unknown State";
|
|
}
|
|
}
|
|
|
|
if (m_bExit) return;
|
|
if (m_bHalt) continue;
|
|
}
|
|
}
|
|
|
|
void Run::setState(STATES s)
|
|
{
|
|
|
|
m_state = s;
|
|
}
|
|
|
|
void Run::EndTask()
|
|
{
|
|
m_bExit = true;
|
|
|
|
}
|
|
|
|
void Run::WaitThreadTerminate()
|
|
{
|
|
m_myThread.join();
|
|
}
|