2019-10-31 18:00:42 +00:00
|
|
|
#pragma once
|
|
|
|
#include "switch.h"
|
|
|
|
#include "IController.h"
|
2020-02-20 00:27:19 +00:00
|
|
|
#include <stratosphere.hpp>
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
//This class is a base class for SwitchHDLHandler and SwitchAbstractedPaadHandler.
|
|
|
|
class SwitchVirtualGamepadHandler
|
|
|
|
{
|
|
|
|
protected:
|
2019-11-02 17:42:24 +00:00
|
|
|
u32 m_vibrationDeviceHandle;
|
2020-04-22 13:42:06 +00:00
|
|
|
std::unique_ptr<IController> m_controller;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
2020-05-13 12:00:25 +00:00
|
|
|
alignas(ams::os::ThreadStackAlignment) u8 input_thread_stack[0x1000];
|
|
|
|
alignas(ams::os::ThreadStackAlignment) u8 output_thread_stack[0x1000];
|
|
|
|
|
|
|
|
Thread m_inputThread;
|
|
|
|
Thread m_outputThread;
|
2020-02-20 00:27:19 +00:00
|
|
|
|
|
|
|
bool m_inputThreadIsRunning = false;
|
|
|
|
bool m_outputThreadIsRunning = false;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
2019-12-04 18:44:01 +00:00
|
|
|
static void InputThreadLoop(void *argument);
|
|
|
|
static void OutputThreadLoop(void *argument);
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
SwitchVirtualGamepadHandler(std::unique_ptr<IController> &&controller);
|
|
|
|
virtual ~SwitchVirtualGamepadHandler();
|
|
|
|
|
|
|
|
//Override this if you want a custom init procedure
|
|
|
|
virtual Result Initialize();
|
|
|
|
//Override this if you want a custom exit procedure
|
|
|
|
virtual void Exit();
|
|
|
|
|
|
|
|
//Separately init the input-reading thread
|
2019-11-06 12:28:56 +00:00
|
|
|
Result InitInputThread();
|
2019-10-31 18:00:42 +00:00
|
|
|
//Separately close the input-reading thread
|
|
|
|
void ExitInputThread();
|
|
|
|
|
|
|
|
//Separately init the rumble sending thread
|
2019-11-06 12:28:56 +00:00
|
|
|
Result InitOutputThread();
|
2019-10-31 18:00:42 +00:00
|
|
|
//Separately close the rumble sending thread
|
|
|
|
void ExitOutputThread();
|
|
|
|
|
|
|
|
//The function to call indefinitely by the input thread
|
|
|
|
virtual void UpdateInput() = 0;
|
|
|
|
//The function to call indefinitely by the output thread
|
|
|
|
virtual void UpdateOutput() = 0;
|
|
|
|
|
2020-04-22 13:42:06 +00:00
|
|
|
void ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out);
|
|
|
|
|
|
|
|
Result SetControllerVibration(float strong_mag, float weak_mag);
|
|
|
|
|
|
|
|
//Get the raw controller pointer
|
|
|
|
inline IController *GetController() { return m_controller.get(); }
|
2019-11-02 17:42:24 +00:00
|
|
|
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
|
2019-10-31 18:00:42 +00:00
|
|
|
};
|