mirror of
https://github.com/cathery/sys-con.git
synced 2025-03-14 01:27:37 +00:00
Begin implementing Xbox One Adapter
This commit is contained in:
parent
ecf6d2987e
commit
4ba875800c
@ -6,6 +6,7 @@ enum ControllerType
|
||||
CONTROLLER_XBOX360,
|
||||
CONTROLLER_XBOX360W,
|
||||
CONTROLLER_XBOXONE,
|
||||
CONTROLLER_XBOXONEW,
|
||||
CONTROLLER_DUALSHOCK3,
|
||||
CONTROLLER_DUALSHOCK4,
|
||||
};
|
||||
@ -43,6 +44,7 @@ enum ControllerSupport
|
||||
SUPPORTS_RUMBLE,
|
||||
SUPPORTS_BLUETOOTH,
|
||||
SUPPORTS_PAIRING,
|
||||
SUPPORTS_NOTHING,
|
||||
SUPPORTS_SIXAXIS,
|
||||
SUPPORTS_SEVENAXIS,
|
||||
SUPPORTS_PRESSUREBUTTONS,
|
||||
|
@ -4,5 +4,6 @@
|
||||
#include "Controllers/Xbox360WirelessController.h"
|
||||
#include "Controllers/XboxController.h"
|
||||
#include "Controllers/XboxOneController.h"
|
||||
#include "Controllers/XboxOneAdapter.h"
|
||||
#include "Controllers/Dualshock3Controller.h"
|
||||
#include "Controllers/Dualshock4Controller.h"
|
||||
|
29
ControllerUSB/include/Controllers/XboxOneAdapter.h
Normal file
29
ControllerUSB/include/Controllers/XboxOneAdapter.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "IController.h"
|
||||
#include "Controllers/XboxOneController.h"
|
||||
|
||||
//References used:
|
||||
//https://github.com/quantus/xbox-one-controller-protocol
|
||||
//https://cs.chromium.org/chromium/src/device/gamepad/xbox_controller_mac.mm
|
||||
|
||||
class XboxOneAdapter : public IController
|
||||
{
|
||||
private:
|
||||
IUSBEndpoint *m_inPipe = nullptr;
|
||||
IUSBEndpoint *m_outPipe = nullptr;
|
||||
|
||||
public:
|
||||
XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface);
|
||||
virtual ~XboxOneAdapter();
|
||||
|
||||
virtual Status Initialize();
|
||||
virtual void Exit();
|
||||
|
||||
Status OpenInterfaces();
|
||||
void CloseInterfaces();
|
||||
|
||||
virtual ControllerType GetType() { return CONTROLLER_XBOXONEW; }
|
||||
|
||||
Status SendInitBytes();
|
||||
};
|
@ -22,6 +22,10 @@ bool DoesControllerSupport(ControllerType type, ControllerSupport supportType)
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
case CONTROLLER_XBOXONEW:
|
||||
if (supportType == SUPPORTS_NOTHING)
|
||||
return true;
|
||||
return false;
|
||||
case CONTROLLER_DUALSHOCK3:
|
||||
switch (supportType)
|
||||
{
|
||||
|
105
ControllerUSB/source/Controllers/XboxOneAdapter.cpp
Normal file
105
ControllerUSB/source/Controllers/XboxOneAdapter.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
#include "Controllers/XboxOneAdapter.h"
|
||||
#include <cmath>
|
||||
#include "../../source/log.h"
|
||||
|
||||
XboxOneAdapter::XboxOneAdapter(std::unique_ptr<IUSBDevice> &&interface)
|
||||
: IController(std::move(interface))
|
||||
{
|
||||
}
|
||||
|
||||
XboxOneAdapter::~XboxOneAdapter()
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
|
||||
Status XboxOneAdapter::Initialize()
|
||||
{
|
||||
Status rc;
|
||||
|
||||
rc = OpenInterfaces();
|
||||
if (S_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
rc = SendInitBytes();
|
||||
if (S_FAILED(rc))
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
void XboxOneAdapter::Exit()
|
||||
{
|
||||
CloseInterfaces();
|
||||
}
|
||||
|
||||
Status XboxOneAdapter::OpenInterfaces()
|
||||
{
|
||||
Status rc;
|
||||
rc = m_device->Open();
|
||||
if (S_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
std::vector<std::unique_ptr<IUSBInterface>> &interfaces = m_device->GetInterfaces();
|
||||
for (auto &&interface : interfaces)
|
||||
{
|
||||
rc = interface->Open();
|
||||
if (S_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
/*
|
||||
|
||||
if (interface->GetDescriptor()->bInterfaceProtocol != 208)
|
||||
continue;
|
||||
|
||||
if (interface->GetDescriptor()->bNumEndpoints < 2)
|
||||
continue;
|
||||
*/
|
||||
|
||||
if (!m_inPipe)
|
||||
{
|
||||
for (uint8_t i = 0; i != 15; ++i)
|
||||
{
|
||||
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i);
|
||||
if (inEndpoint)
|
||||
{
|
||||
rc = inEndpoint->Open();
|
||||
if (S_FAILED(rc))
|
||||
return 5555;
|
||||
|
||||
m_inPipe = inEndpoint;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_outPipe)
|
||||
{
|
||||
for (uint8_t i = 0; i != 15; ++i)
|
||||
{
|
||||
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);
|
||||
if (outEndpoint)
|
||||
{
|
||||
rc = outEndpoint->Open();
|
||||
if (S_FAILED(rc))
|
||||
return 6666;
|
||||
|
||||
m_outPipe = outEndpoint;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_inPipe || !m_outPipe)
|
||||
return 69;
|
||||
|
||||
return rc;
|
||||
}
|
||||
void XboxOneAdapter::CloseInterfaces()
|
||||
{
|
||||
//m_device->Reset();
|
||||
m_device->Close();
|
||||
}
|
||||
|
||||
Status XboxOneAdapter::SendInitBytes()
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -19,20 +19,8 @@ Result SwitchAbstractedPadHandler::Initialize()
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
/*
|
||||
|
||||
hidScanInput();
|
||||
HidControllerID lastOfflineID = CONTROLLER_PLAYER_1;
|
||||
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);
|
||||
*/
|
||||
if (DoesControllerSupport(GetController()->GetType(), SUPPORTS_NOTHING))
|
||||
return rc;
|
||||
|
||||
rc = InitAbstractedPadState();
|
||||
if (R_FAILED(rc))
|
||||
@ -68,10 +56,14 @@ Result SwitchAbstractedPadHandler::Initialize()
|
||||
|
||||
void SwitchAbstractedPadHandler::Exit()
|
||||
{
|
||||
ExitAbstractedPadState();
|
||||
m_controllerHandler.Exit();
|
||||
|
||||
if (DoesControllerSupport(GetController()->GetType(), SUPPORTS_NOTHING))
|
||||
return;
|
||||
|
||||
ExitInputThread();
|
||||
ExitOutputThread();
|
||||
ExitAbstractedPadState();
|
||||
}
|
||||
|
||||
//Used to give out unique ids to abstracted pads
|
||||
|
@ -18,6 +18,9 @@ Result SwitchHDLHandler::Initialize()
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
|
||||
if (DoesControllerSupport(GetController()->GetType(), SUPPORTS_NOTHING))
|
||||
return rc;
|
||||
|
||||
rc = InitHdlState();
|
||||
if (R_FAILED(rc))
|
||||
return rc;
|
||||
@ -39,6 +42,10 @@ Result SwitchHDLHandler::Initialize()
|
||||
void SwitchHDLHandler::Exit()
|
||||
{
|
||||
m_controllerHandler.Exit();
|
||||
|
||||
if (DoesControllerSupport(GetController()->GetType(), SUPPORTS_NOTHING))
|
||||
return;
|
||||
|
||||
ExitInputThread();
|
||||
ExitOutputThread();
|
||||
ExitHdlState();
|
||||
|
@ -152,6 +152,12 @@ Result mainLoop()
|
||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||
controllerPtr = std::make_unique<XboxOneController>(std::move(devicePtr));
|
||||
}
|
||||
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 255, 255)))
|
||||
{
|
||||
WriteToLog("Registering Xbox One adapter");
|
||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||
controllerPtr = std::make_unique<XboxOneAdapter>(std::move(devicePtr));
|
||||
}
|
||||
}
|
||||
}
|
||||
rc = eventWait(&ds3Event, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user