mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-06 06:19:43 +00:00
Progress on #1
This commit is contained in:
parent
2361c15ec2
commit
860173824d
@ -10,7 +10,6 @@
|
|||||||
class SwitchHDLHandler : public SwitchVirtualGamepadHandler
|
class SwitchHDLHandler : public SwitchVirtualGamepadHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
u32 m_vibrationDeviceHandle;
|
|
||||||
u64 m_hdlHandle;
|
u64 m_hdlHandle;
|
||||||
HiddbgHdlsDeviceInfo m_deviceInfo;
|
HiddbgHdlsDeviceInfo m_deviceInfo;
|
||||||
HiddbgHdlsState m_hdlState;
|
HiddbgHdlsState m_hdlState;
|
||||||
@ -37,6 +36,4 @@ public:
|
|||||||
void FillHdlState(const NormalizedButtonData &data);
|
void FillHdlState(const NormalizedButtonData &data);
|
||||||
//Passes the HDL state to HID so that it could register the inputs
|
//Passes the HDL state to HID so that it could register the inputs
|
||||||
Result UpdateHdlState();
|
Result UpdateHdlState();
|
||||||
|
|
||||||
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
|
|
||||||
};
|
};
|
@ -8,6 +8,7 @@
|
|||||||
class SwitchVirtualGamepadHandler
|
class SwitchVirtualGamepadHandler
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
u32 m_vibrationDeviceHandle;
|
||||||
SwitchControllerHandler m_controllerHandler;
|
SwitchControllerHandler m_controllerHandler;
|
||||||
|
|
||||||
bool m_keepInputThreadRunning;
|
bool m_keepInputThreadRunning;
|
||||||
@ -49,4 +50,5 @@ public:
|
|||||||
//Get the raw controller handler pointer
|
//Get the raw controller handler pointer
|
||||||
inline SwitchControllerHandler *GetControllerHandler() { return &m_controllerHandler; }
|
inline SwitchControllerHandler *GetControllerHandler() { return &m_controllerHandler; }
|
||||||
inline IController *GetController() { return m_controllerHandler.GetController(); }
|
inline IController *GetController() { return m_controllerHandler.GetController(); }
|
||||||
|
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
|
||||||
};
|
};
|
@ -1,6 +1,7 @@
|
|||||||
#include "SwitchAbstractedPadHandler.h"
|
#include "SwitchAbstractedPadHandler.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include "../../source/log.h"
|
||||||
|
|
||||||
SwitchAbstractedPadHandler::SwitchAbstractedPadHandler(std::unique_ptr<IController> &&controller)
|
SwitchAbstractedPadHandler::SwitchAbstractedPadHandler(std::unique_ptr<IController> &&controller)
|
||||||
: SwitchVirtualGamepadHandler(std::move(controller))
|
: SwitchVirtualGamepadHandler(std::move(controller))
|
||||||
@ -18,10 +19,37 @@ Result SwitchAbstractedPadHandler::Initialize()
|
|||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
hidScanInput();
|
||||||
|
HidControllerID lastOfflineID;
|
||||||
|
for (int i = 0; i != 8; ++i)
|
||||||
|
{
|
||||||
|
if (!hidIsControllerConnected(static_cast<HidControllerID>(i)))
|
||||||
|
{
|
||||||
|
lastOfflineID = static_cast<HidControllerID>(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteToLog("Found last offline ID: ", lastOfflineID);
|
||||||
|
|
||||||
rc = InitAbstractedPadState();
|
rc = InitAbstractedPadState();
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
svcSleepThread(1e+7L);
|
||||||
|
hidScanInput();
|
||||||
|
|
||||||
|
WriteToLog("Is last offline id connected? ", hidIsControllerConnected(lastOfflineID));
|
||||||
|
WriteToLog("Last offline id type: ", hidGetControllerType(lastOfflineID));
|
||||||
|
|
||||||
|
Result rc2 = hidInitializeVibrationDevices(&m_vibrationDeviceHandle, 1, lastOfflineID, hidGetControllerType(lastOfflineID));
|
||||||
|
if (R_SUCCEEDED(rc2))
|
||||||
|
{
|
||||||
|
WriteToLog("Initializing vibration device with handle ", m_vibrationDeviceHandle);
|
||||||
|
InitOutputThread();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
WriteToLog("Failed to iniitalize vibration with error ", rc2);
|
||||||
|
|
||||||
InitInputThread();
|
InitInputThread();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -31,7 +59,7 @@ void SwitchAbstractedPadHandler::Exit()
|
|||||||
ExitAbstractedPadState();
|
ExitAbstractedPadState();
|
||||||
m_controllerHandler.Exit();
|
m_controllerHandler.Exit();
|
||||||
ExitInputThread();
|
ExitInputThread();
|
||||||
//ExitRumbleThread();
|
ExitOutputThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Used to give out unique ids to abstracted pads
|
//Used to give out unique ids to abstracted pads
|
||||||
@ -129,5 +157,13 @@ void SwitchAbstractedPadHandler::UpdateInput()
|
|||||||
|
|
||||||
void SwitchAbstractedPadHandler::UpdateOutput()
|
void SwitchAbstractedPadHandler::UpdateOutput()
|
||||||
{
|
{
|
||||||
|
Result rc;
|
||||||
|
HidVibrationValue value;
|
||||||
|
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
rc = GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
|
||||||
|
|
||||||
svcSleepThread(1e+7L);
|
svcSleepThread(1e+7L);
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "SwitchHDLHandler.h"
|
#include "SwitchHDLHandler.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "../../source/log.h"
|
||||||
|
|
||||||
SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller)
|
SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller)
|
||||||
: SwitchVirtualGamepadHandler(std::move(controller))
|
: SwitchVirtualGamepadHandler(std::move(controller))
|
||||||
@ -17,16 +18,39 @@ Result SwitchHDLHandler::Initialize()
|
|||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
hidScanInput();
|
||||||
|
HidControllerID lastOfflineID;
|
||||||
|
for (int i = 0; i != 8; ++i)
|
||||||
|
{
|
||||||
|
if (!hidIsControllerConnected(static_cast<HidControllerID>(i)))
|
||||||
|
{
|
||||||
|
lastOfflineID = static_cast<HidControllerID>(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteToLog("Found last offline ID: ", lastOfflineID);
|
||||||
|
|
||||||
rc = InitHdlState();
|
rc = InitHdlState();
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (R_SUCCEEDED(hidInitializeVibrationDevices(&m_vibrationDeviceHandle, 1, CONTROLLER_PLAYER_2, static_cast<HidControllerType>(TYPE_PROCONTROLLER | TYPE_SYSTEM_EXT))))
|
svcSleepThread(1e+7L);
|
||||||
|
hidScanInput();
|
||||||
|
|
||||||
|
WriteToLog("Is last offline id connected? ", hidIsControllerConnected(lastOfflineID));
|
||||||
|
WriteToLog("Last offline id type: ", hidGetControllerType(lastOfflineID));
|
||||||
|
|
||||||
|
Result rc2 = hidInitializeVibrationDevices(&m_vibrationDeviceHandle, 1, lastOfflineID, hidGetControllerType(lastOfflineID));
|
||||||
|
if (R_SUCCEEDED(rc2))
|
||||||
{
|
{
|
||||||
|
WriteToLog("Initializing vibration device with handle ", m_vibrationDeviceHandle);
|
||||||
InitOutputThread();
|
InitOutputThread();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
WriteToLog("Failed to iniitalize vibration with error ", rc2);
|
||||||
|
|
||||||
InitInputThread();
|
InitInputThread();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +69,7 @@ Result SwitchHDLHandler::InitHdlState()
|
|||||||
m_hdlState = {0};
|
m_hdlState = {0};
|
||||||
|
|
||||||
// Set the controller type to Pro-Controller, and set the npadInterfaceType.
|
// Set the controller type to Pro-Controller, and set the npadInterfaceType.
|
||||||
m_deviceInfo.deviceType = HidDeviceType_FullKey3;
|
m_deviceInfo.deviceType = HidDeviceType_FullKey15;
|
||||||
m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB;
|
m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB;
|
||||||
// Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+].
|
// Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+].
|
||||||
m_deviceInfo.singleColorBody = RGBA8_MAXALPHA(107, 107, 107);
|
m_deviceInfo.singleColorBody = RGBA8_MAXALPHA(107, 107, 107);
|
||||||
|
@ -61,10 +61,19 @@ extern "C"
|
|||||||
rc = usbCommsInitialize();
|
rc = usbCommsInitialize();
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
|
||||||
|
#ifndef __APPLET__
|
||||||
|
rc = hidInitialize();
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
fatalThrow(rc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((weak)) userAppExit(void)
|
void __attribute__((weak)) userAppExit(void)
|
||||||
{
|
{
|
||||||
|
#ifndef __APPLET__
|
||||||
|
hidExit();
|
||||||
|
#endif
|
||||||
usbCommsExit();
|
usbCommsExit();
|
||||||
usbHsExit();
|
usbHsExit();
|
||||||
hiddbgReleaseHdlsWorkBuffer();
|
hiddbgReleaseHdlsWorkBuffer();
|
||||||
|
@ -20,6 +20,8 @@ Result mainLoop()
|
|||||||
s32 total_entries;
|
s32 total_entries;
|
||||||
std::vector<uint16_t> vendors = GetVendors();
|
std::vector<uint16_t> vendors = GetVendors();
|
||||||
bool useAbstractedPad = hosversionBetween(5, 7);
|
bool useAbstractedPad = hosversionBetween(5, 7);
|
||||||
|
hidPermitVibration(false);
|
||||||
|
hidPermitVibration(true);
|
||||||
VendorEvent events[vendors.size()];
|
VendorEvent events[vendors.size()];
|
||||||
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerInterfaces;
|
std::vector<std::unique_ptr<SwitchVirtualGamepadHandler>> controllerInterfaces;
|
||||||
|
|
||||||
@ -50,6 +52,45 @@ Result mainLoop()
|
|||||||
#ifdef __APPLET__
|
#ifdef __APPLET__
|
||||||
hidScanInput();
|
hidScanInput();
|
||||||
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||||
|
|
||||||
|
if (kDown & KEY_Y)
|
||||||
|
{
|
||||||
|
for (int i = 0; i != 8; ++i)
|
||||||
|
{
|
||||||
|
bool isConnected = hidIsControllerConnected(static_cast<HidControllerID>(i));
|
||||||
|
WriteToLog("Is controller ", i, " connected: ", isConnected);
|
||||||
|
if (isConnected)
|
||||||
|
{
|
||||||
|
HidControllerType type = hidGetControllerType(static_cast<HidControllerID>(i));
|
||||||
|
WriteToLog("Controller ", i, " type: ", type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kDown & KEY_X)
|
||||||
|
{
|
||||||
|
WriteToLog("Sending rumble to all controllers\n");
|
||||||
|
for (auto &&con : controllerInterfaces)
|
||||||
|
{
|
||||||
|
u32 *vibrationHandle = con->GetVibrationHandle();
|
||||||
|
bool flag;
|
||||||
|
Result rc = hidIsVibrationDeviceMounted(vibrationHandle, &flag);
|
||||||
|
if (R_SUCCEEDED(rc))
|
||||||
|
{
|
||||||
|
WriteToLog("Is vibration device mounted: ", flag);
|
||||||
|
HidVibrationValue value;
|
||||||
|
value.amp_high = 0.5f;
|
||||||
|
value.amp_low = 0.5f;
|
||||||
|
value.freq_high = 320.0f;
|
||||||
|
value.freq_low = 160.0f;
|
||||||
|
rc = hidSendVibrationValue(vibrationHandle, &value);
|
||||||
|
WriteToLog("SendVirationValue result: ", rc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
WriteToLog("failed to check for vibration device");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kDown & KEY_B)
|
if (kDown & KEY_B)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user