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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-06 12:28:56 +00:00
|
|
|
void inputThreadLoop(void *handler)
|
2019-10-31 18:00:42 +00:00
|
|
|
{
|
|
|
|
svcSleepThread(1e+7L);
|
2019-11-06 12:28:56 +00:00
|
|
|
SwitchVirtualGamepadHandler *switchHandler = static_cast<SwitchVirtualGamepadHandler *>(handler);
|
|
|
|
bool *keepThreadRunning = switchHandler->GetInputThreadBool();
|
|
|
|
|
2019-10-31 18:00:42 +00:00
|
|
|
while (*keepThreadRunning)
|
|
|
|
{
|
2019-11-06 12:28:56 +00:00
|
|
|
switchHandler->UpdateInput();
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 12:28:56 +00:00
|
|
|
void outputThreadLoop(void *handler)
|
2019-10-31 18:00:42 +00:00
|
|
|
{
|
|
|
|
svcSleepThread(1e+7L);
|
2019-11-06 12:28:56 +00:00
|
|
|
SwitchVirtualGamepadHandler *switchHandler = static_cast<SwitchVirtualGamepadHandler *>(handler);
|
|
|
|
bool *keepThreadRunning = switchHandler->GetInputThreadBool();
|
|
|
|
|
2019-10-31 18:00:42 +00:00
|
|
|
while (*keepThreadRunning)
|
|
|
|
{
|
2019-11-06 12:28:56 +00:00
|
|
|
switchHandler->UpdateOutput();
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 12:28:56 +00:00
|
|
|
Result SwitchVirtualGamepadHandler::InitInputThread()
|
2019-10-31 18:00:42 +00:00
|
|
|
{
|
|
|
|
m_keepInputThreadRunning = true;
|
2019-11-21 22:49:14 +00:00
|
|
|
Result rc = threadCreate(&m_inputThread, &inputThreadLoop, this, NULL, 0x400, 0x3B, -2);
|
2019-11-06 12:28:56 +00:00
|
|
|
if (R_FAILED(rc))
|
|
|
|
return rc;
|
|
|
|
return threadStart(&m_inputThread);
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchVirtualGamepadHandler::ExitInputThread()
|
|
|
|
{
|
|
|
|
m_keepInputThreadRunning = false;
|
2019-11-06 12:28:56 +00:00
|
|
|
threadWaitForExit(&m_inputThread);
|
|
|
|
threadClose(&m_inputThread);
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 12:28:56 +00:00
|
|
|
Result SwitchVirtualGamepadHandler::InitOutputThread()
|
2019-10-31 18:00:42 +00:00
|
|
|
{
|
|
|
|
m_keepOutputThreadRunning = true;
|
2019-11-21 22:49:14 +00:00
|
|
|
Result rc = threadCreate(&m_outputThread, &outputThreadLoop, this, NULL, 0x400, 0x3B, -2);
|
2019-11-06 12:28:56 +00:00
|
|
|
if (R_FAILED(rc))
|
|
|
|
return rc;
|
|
|
|
return threadStart(&m_outputThread);
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchVirtualGamepadHandler::ExitOutputThread()
|
|
|
|
{
|
|
|
|
m_keepOutputThreadRunning = false;
|
2019-11-06 12:28:56 +00:00
|
|
|
threadWaitForExit(&m_outputThread);
|
|
|
|
threadClose(&m_outputThread);
|
2019-10-31 18:00:42 +00:00
|
|
|
}
|