1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-05 17:26:28 +00:00

Fixed 360 Wireless not working

This commit is contained in:
cathery 2019-11-08 21:06:02 +03:00
parent 47dfafaaac
commit 435b203525
7 changed files with 75 additions and 31 deletions

View File

@ -42,6 +42,7 @@ enum ControllerSupport
{
SUPPORTS_RUMBLE,
SUPPORTS_BLUETOOTH,
SUPPORTS_PAIRING,
SUPPORTS_SIXAXIS,
SUPPORTS_SEVENAXIS,
SUPPORTS_PRESSUREBUTTONS,

View File

@ -6,6 +6,12 @@
//References used:
//https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
struct OutputPacket
{
const uint8_t *packet;
uint8_t length;
};
class Xbox360WirelessController : public IController
{
private:
@ -16,6 +22,8 @@ private:
bool m_presence;
std::vector<OutputPacket> m_outputBuffer;
public:
Xbox360WirelessController(std::unique_ptr<IUSBDevice> &&interface);
virtual ~Xbox360WirelessController();
@ -39,8 +47,8 @@ public:
Status SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude);
Status SetLED(Xbox360LEDValue value);
Status PowerOffController();
Status ReconnectController();
static void LoadConfig(const ControllerConfig *config);
Status OutputBuffer();
};

View File

@ -32,4 +32,6 @@ public:
inline IUSBDevice *GetDevice() { return m_device.get(); }
virtual ControllerType GetType() = 0;
virtual Status SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude) = 0;
Status OutputBuffer() { return 1; };
};

View File

@ -8,6 +8,10 @@ bool DoesControllerSupport(ControllerType type, ControllerSupport supportType)
if (supportType == SUPPORTS_RUMBLE)
return true;
return false;
case CONTROLLER_XBOX360W:
if (supportType == SUPPORTS_PAIRING)
return true;
return false;
case CONTROLLER_XBOXONE:
switch (supportType)
{

View File

@ -2,6 +2,9 @@
#include <cmath>
static ControllerConfig _xbox360WControllerConfig{};
static const uint8_t reconnectPacket[]{0x08, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t poweroffPacket[]{0x00, 0x00, 0x08, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t ledPacket[]{0x00, 0x00, 0x08, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Xbox360WirelessController::Xbox360WirelessController(std::unique_ptr<IUSBDevice> &&interface)
: IController(std::move(interface))
@ -16,12 +19,14 @@ Xbox360WirelessController::~Xbox360WirelessController()
Status Xbox360WirelessController::Initialize()
{
Status rc;
m_outputBuffer.clear();
m_outputBuffer.reserve(4);
rc = OpenInterfaces();
if (S_FAILED(rc))
return rc;
rc = ReconnectController();
rc = m_outPipe->Write(reconnectPacket, sizeof(reconnectPacket));
if (S_FAILED(rc))
return rc;
@ -97,7 +102,7 @@ Status Xbox360WirelessController::OpenInterfaces()
void Xbox360WirelessController::CloseInterfaces()
{
if (m_presence)
PowerOffController();
m_outPipe->Write(poweroffPacket, sizeof(poweroffPacket));
//m_device->Reset();
m_device->Close();
@ -120,9 +125,12 @@ Status Xbox360WirelessController::GetInput()
m_presence = newPresence;
if (m_presence)
ReconnectController();
{
m_outputBuffer.push_back(OutputPacket{reconnectPacket, sizeof(reconnectPacket)});
m_outputBuffer.push_back(OutputPacket{ledPacket, sizeof(ledPacket)});
}
else
PowerOffController();
m_outputBuffer.push_back(OutputPacket{poweroffPacket, sizeof(poweroffPacket)});
}
}
@ -131,7 +139,7 @@ Status Xbox360WirelessController::GetInput()
if (type == XBOX360INPUT_BUTTON)
{
m_buttonData = *reinterpret_cast<Xbox360ButtonData *>(input_bytes);
m_buttonData = *reinterpret_cast<Xbox360ButtonData *>(input_bytes + 4);
}
return rc;
@ -237,19 +245,17 @@ Status Xbox360WirelessController::SetLED(Xbox360LEDValue value)
return m_outPipe->Write(ledPacket, sizeof(ledPacket));
}
Status Xbox360WirelessController::PowerOffController()
{
uint8_t poweroffPacket[]{0x00, 0x00, 0x08, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
return m_outPipe->Write(poweroffPacket, sizeof(poweroffPacket));
}
Status Xbox360WirelessController::ReconnectController()
{
uint8_t reconnectPacket[]{0x08, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
return m_outPipe->Write(reconnectPacket, sizeof(reconnectPacket));
}
void Xbox360WirelessController::LoadConfig(const ControllerConfig *config)
{
_xbox360WControllerConfig = *config;
}
}
Status Xbox360WirelessController::OutputBuffer()
{
if (m_outputBuffer.empty())
return 1;
Status rc = m_outPipe->Write(m_outputBuffer[0].packet, m_outputBuffer[0].length);
m_outputBuffer.erase(m_outputBuffer.begin());
return rc;
}

View File

@ -1,4 +1,5 @@
#include "SwitchAbstractedPadHandler.h"
#include "ControllerHelpers.h"
#include <cmath>
#include <array>
@ -51,6 +52,13 @@ Result SwitchAbstractedPadHandler::Initialize()
WriteToLog("Failed to iniitalize vibration device with error ", rc2);
*/
if (DoesControllerSupport(m_controllerHandler.GetController()->GetType(), SUPPORTS_PAIRING))
{
rc = InitOutputThread();
if (R_FAILED(rc))
return rc;
}
rc = InitInputThread();
if (R_FAILED(rc))
return rc;
@ -164,13 +172,17 @@ void SwitchAbstractedPadHandler::UpdateInput()
void SwitchAbstractedPadHandler::UpdateOutput()
{
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
if (R_FAILED(rc))
if (R_SUCCEEDED(m_controllerHandler.GetController()->OutputBuffer()))
return;
rc = GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
if (DoesControllerSupport(m_controllerHandler.GetController()->GetType(), SUPPORTS_RUMBLE))
{
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
if (R_SUCCEEDED(rc))
GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
svcSleepThread(1e+7L);
}

View File

@ -1,4 +1,5 @@
#include "SwitchHDLHandler.h"
#include "ControllerHelpers.h"
#include <cmath>
SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller)
@ -49,6 +50,13 @@ Result SwitchHDLHandler::Initialize()
WriteToLog("Failed to iniitalize vibration with error ", rc2);
*/
if (DoesControllerSupport(m_controllerHandler.GetController()->GetType(), SUPPORTS_PAIRING))
{
rc = InitOutputThread();
if (R_FAILED(rc))
return rc;
}
rc = InitInputThread();
if (R_FAILED(rc))
return rc;
@ -155,14 +163,17 @@ void SwitchHDLHandler::UpdateInput()
void SwitchHDLHandler::UpdateOutput()
{
//Implement rumble here
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
if (R_FAILED(rc))
if (R_SUCCEEDED(m_controllerHandler.GetController()->OutputBuffer()))
return;
rc = GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
if (DoesControllerSupport(m_controllerHandler.GetController()->GetType(), SUPPORTS_RUMBLE))
{
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
if (R_SUCCEEDED(rc))
GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
svcSleepThread(1e+7L);
}