diff --git a/README.md b/README.md index 200560d..127890a 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ If you want to make sure, the file should be located in `sdmc:/atmosphere/titles - [ ] **[Dualshock 3 Support](https://github.com/cathery/sys-con/issues/3)** - [ ] **[Dualshock 4 Support](https://github.com/cathery/sys-con/issues/4)** - [ ] **Config application** -- [ ] **[\[5.0.0-7.0.0\] FW Version Support](https://github.com/cathery/sys-con/issues/2)** +- [x] **~~[\[5.0.0-7.0.0\] FW Version Support](https://github.com/cathery/sys-con/issues/2)~~** ## Support [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H316ZQV) diff --git a/SwitchUSB/source/SwitchAbstractedPadHandler.cpp b/SwitchUSB/source/SwitchAbstractedPadHandler.cpp index 1bc48ab..ce0d64c 100644 --- a/SwitchUSB/source/SwitchAbstractedPadHandler.cpp +++ b/SwitchUSB/source/SwitchAbstractedPadHandler.cpp @@ -1,5 +1,6 @@ #include "SwitchAbstractedPadHandler.h" #include +#include SwitchAbstractedPadHandler::SwitchAbstractedPadHandler(std::unique_ptr &&controller) : SwitchVirtualGamepadHandler(std::move(controller)) @@ -33,17 +34,32 @@ void SwitchAbstractedPadHandler::Exit() //ExitRumbleThread(); } +//Used to give out unique ids to abstracted pads +static std::array uniqueIDs{false}; + +static s8 getUniqueId() +{ + for (s8 i = 0; i != 8; ++i) + { + if (uniqueIDs[i] == false) + { + uniqueIDs[i] = true; + return i; + } + } + return 0; +} + +static void freeUniqueId(s8 id) +{ + uniqueIDs[id] = false; +} + Result SwitchAbstractedPadHandler::InitAbstractedPadState() { Result rc; - /* - u64 pads[8] = {0}; - HiddbgAbstractedPadState states[8] = {0}; - s32 tmpout = 0; - rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads) / sizeof(u64), &tmpout); - */ m_state = {0}; - m_abstractedPadID = 0; + m_abstractedPadID = getUniqueId(); m_state.type = BIT(0); m_state.npadInterfaceType = NpadInterfaceType_USB; m_state.flags = 0xff; @@ -56,31 +72,11 @@ Result SwitchAbstractedPadHandler::InitAbstractedPadState() return rc; return rc; - /* - m_hdlHandle = 0; - m_deviceInfo = {0}; - m_hdlState = {0}; - - // Set the controller type to Pro-Controller, and set the npadInterfaceType. - m_deviceInfo.deviceType = HidDeviceType_FullKey3; - m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB; - // 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.singleColorButtons = RGBA8_MAXALPHA(0, 0, 0); - m_deviceInfo.colorLeftGrip = RGBA8_MAXALPHA(23, 125, 62); - m_deviceInfo.colorRightGrip = RGBA8_MAXALPHA(23, 125, 62); - - m_hdlState.batteryCharge = 4; // Set battery charge to full. - m_hdlState.joysticks[JOYSTICK_LEFT].dx = 0x1234; - m_hdlState.joysticks[JOYSTICK_LEFT].dy = -0x1234; - m_hdlState.joysticks[JOYSTICK_RIGHT].dx = 0x5678; - m_hdlState.joysticks[JOYSTICK_RIGHT].dy = -0x5678; - - return hiddbgAttachHdlsVirtualDevice(&m_hdlHandle, &m_deviceInfo); - */ } + Result SwitchAbstractedPadHandler::ExitAbstractedPadState() { + freeUniqueId(m_abstractedPadID); return hiddbgUnsetAutoPilotVirtualPadState(m_abstractedPadID); } @@ -92,10 +88,6 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData m_state.state.buttons |= (data.top_action ? KEY_X : 0); m_state.state.buttons |= (data.left_action ? KEY_Y : 0); - //Breaks when buttons has a value of more than 25 or more - //if buttons is 0x2000 or more, it also calls a interface change event, breaking any possibility of disconnecting a controller properly - //None of this happens on the main thread, this is a problem only when running from a separate thread - /* m_state.state.buttons |= (data.left_stick_click ? KEY_LSTICK : 0); m_state.state.buttons |= (data.right_stick_click ? KEY_RSTICK : 0); @@ -112,7 +104,7 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData m_state.state.buttons |= (data.dpad_up ? KEY_DUP : 0); m_state.state.buttons |= (data.dpad_right ? KEY_DRIGHT : 0); m_state.state.buttons |= (data.dpad_down ? KEY_DDOWN : 0); - */ + m_controllerHandler.ConvertAxisToSwitchAxis(data.left_stick_x, data.left_stick_y, 0, &m_state.state.joysticks[JOYSTICK_LEFT].dx, &m_state.state.joysticks[JOYSTICK_LEFT].dy); m_controllerHandler.ConvertAxisToSwitchAxis(data.right_stick_x, data.right_stick_y, 0, &m_state.state.joysticks[JOYSTICK_RIGHT].dx, &m_state.state.joysticks[JOYSTICK_RIGHT].dy); } diff --git a/SwitchUSB/source/SwitchUSBDevice.cpp b/SwitchUSB/source/SwitchUSBDevice.cpp index c36115e..10ccb5d 100644 --- a/SwitchUSB/source/SwitchUSBDevice.cpp +++ b/SwitchUSB/source/SwitchUSBDevice.cpp @@ -1,5 +1,4 @@ #include "SwitchUSBDevice.h" -#include "libnxFix.h" #include //for memset #include "malloc.h" //for memalign @@ -39,13 +38,8 @@ void SwitchUSBDevice::Reset() //I'm expecting all interfaces to point to one device decsriptor // as such resetting on any of them should do the trick //TODO: needs testing - for (auto &&interface : m_interfaces) - { - interface->Reset(); - } - - //if (m_interfaces.size() != 0) - //m_interfaces[0]->Reset(); + if (m_interfaces.size() != 0) + m_interfaces[0]->Reset(); } void SwitchUSBDevice::SetInterfaces(UsbHsInterface *interfaces, int length)