1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-27 06:15:19 +00:00
sys-con/SwitchUSB/source/SwitchVirtualGamepadHandler.cpp

75 lines
1.8 KiB
C++
Raw Normal View History

2019-10-31 18:00:42 +00:00
#include "SwitchVirtualGamepadHandler.h"
SwitchVirtualGamepadHandler::SwitchVirtualGamepadHandler(std::unique_ptr<IController> &&controller)
: m_controllerHandler(std::move(controller))
{
}
SwitchVirtualGamepadHandler::~SwitchVirtualGamepadHandler()
{
}
Result SwitchVirtualGamepadHandler::Initialize()
{
return 0;
}
void SwitchVirtualGamepadHandler::Exit()
{
}
void inputThreadLoop(void *handler)
2019-10-31 18:00:42 +00:00
{
svcSleepThread(1e+7L);
SwitchVirtualGamepadHandler *switchHandler = static_cast<SwitchVirtualGamepadHandler *>(handler);
bool *keepThreadRunning = switchHandler->GetInputThreadBool();
2019-10-31 18:00:42 +00:00
while (*keepThreadRunning)
{
switchHandler->UpdateInput();
2019-10-31 18:00:42 +00:00
}
}
void outputThreadLoop(void *handler)
2019-10-31 18:00:42 +00:00
{
svcSleepThread(1e+7L);
SwitchVirtualGamepadHandler *switchHandler = static_cast<SwitchVirtualGamepadHandler *>(handler);
bool *keepThreadRunning = switchHandler->GetInputThreadBool();
2019-10-31 18:00:42 +00:00
while (*keepThreadRunning)
{
switchHandler->UpdateOutput();
2019-10-31 18:00:42 +00:00
}
}
Result SwitchVirtualGamepadHandler::InitInputThread()
2019-10-31 18:00:42 +00:00
{
m_keepInputThreadRunning = true;
Result rc = threadCreate(&m_inputThread, inputThreadLoop, this, NULL, 0x400, 0x3B, -2);
if (R_FAILED(rc))
return rc;
return threadStart(&m_inputThread);
2019-10-31 18:00:42 +00:00
}
void SwitchVirtualGamepadHandler::ExitInputThread()
{
m_keepInputThreadRunning = false;
threadWaitForExit(&m_inputThread);
threadClose(&m_inputThread);
2019-10-31 18:00:42 +00:00
}
Result SwitchVirtualGamepadHandler::InitOutputThread()
2019-10-31 18:00:42 +00:00
{
m_keepOutputThreadRunning = true;
Result rc = threadCreate(&m_outputThread, outputThreadLoop, this, NULL, 0x400, 0x3B, -2);
if (R_FAILED(rc))
return rc;
return threadStart(&m_outputThread);
2019-10-31 18:00:42 +00:00
}
void SwitchVirtualGamepadHandler::ExitOutputThread()
{
m_keepOutputThreadRunning = false;
threadWaitForExit(&m_outputThread);
threadClose(&m_outputThread);
2019-10-31 18:00:42 +00:00
}