mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-15 08:49:20 +01:00
GCAdapter: Return input state by value
This commit is contained in:
parent
2be2b2a4f1
commit
041f4f5eea
@ -25,19 +25,18 @@ CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber)
|
|||||||
|
|
||||||
GCPadStatus CSIDevice_GCAdapter::GetPadStatus()
|
GCPadStatus CSIDevice_GCAdapter::GetPadStatus()
|
||||||
{
|
{
|
||||||
GCPadStatus PadStatus;
|
GCPadStatus pad_status = {};
|
||||||
memset(&PadStatus, 0, sizeof(PadStatus));
|
|
||||||
|
|
||||||
// For netplay, the local controllers are polled in GetNetPads(), and
|
// For netplay, the local controllers are polled in GetNetPads(), and
|
||||||
// the remote controllers receive their status there as well
|
// the remote controllers receive their status there as well
|
||||||
if (!NetPlay::IsNetPlayRunning())
|
if (!NetPlay::IsNetPlayRunning())
|
||||||
{
|
{
|
||||||
GCAdapter::Input(ISIDevice::m_iDeviceNumber, &PadStatus);
|
pad_status = GCAdapter::Input(m_iDeviceNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleMoviePadStatus(&PadStatus);
|
HandleMoviePadStatus(&pad_status);
|
||||||
|
|
||||||
return PadStatus;
|
return pad_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int length)
|
int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int length)
|
||||||
|
@ -973,7 +973,7 @@ bool NetPlayClient::GetNetPads(const u8 pad_nb, GCPadStatus* pad_status)
|
|||||||
switch (SConfig::GetInstance().m_SIDevice[local_pad])
|
switch (SConfig::GetInstance().m_SIDevice[local_pad])
|
||||||
{
|
{
|
||||||
case SIDEVICE_WIIU_ADAPTER:
|
case SIDEVICE_WIIU_ADAPTER:
|
||||||
GCAdapter::Input(local_pad, pad_status);
|
*pad_status = GCAdapter::Input(local_pad);
|
||||||
break;
|
break;
|
||||||
case SIDEVICE_GC_CONTROLLER:
|
case SIDEVICE_GC_CONTROLLER:
|
||||||
default:
|
default:
|
||||||
|
@ -371,13 +371,13 @@ static void Reset()
|
|||||||
NOTICE_LOG(SERIALINTERFACE, "GC Adapter detached");
|
NOTICE_LOG(SERIALINTERFACE, "GC Adapter detached");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input(int chan, GCPadStatus* pad)
|
GCPadStatus Input(int chan)
|
||||||
{
|
{
|
||||||
if (!UseAdapter())
|
if (!UseAdapter())
|
||||||
return;
|
return {};
|
||||||
|
|
||||||
if (s_handle == nullptr || !s_detected)
|
if (s_handle == nullptr || !s_detected)
|
||||||
return;
|
return {};
|
||||||
|
|
||||||
int payload_size = 0;
|
int payload_size = 0;
|
||||||
u8 controller_payload_copy[37];
|
u8 controller_payload_copy[37];
|
||||||
@ -389,6 +389,7 @@ void Input(int chan, GCPadStatus* pad)
|
|||||||
payload_size = s_controller_payload_size.load();
|
payload_size = s_controller_payload_size.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GCPadStatus pad = {};
|
||||||
if (payload_size != sizeof(controller_payload_copy) ||
|
if (payload_size != sizeof(controller_payload_copy) ||
|
||||||
controller_payload_copy[0] != LIBUSB_DT_HID)
|
controller_payload_copy[0] != LIBUSB_DT_HID)
|
||||||
{
|
{
|
||||||
@ -410,57 +411,58 @@ void Input(int chan, GCPadStatus* pad)
|
|||||||
|
|
||||||
s_controller_type[chan] = type;
|
s_controller_type[chan] = type;
|
||||||
|
|
||||||
memset(pad, 0, sizeof(*pad));
|
|
||||||
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
||||||
{
|
{
|
||||||
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
||||||
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
||||||
|
|
||||||
if (b1 & (1 << 0))
|
if (b1 & (1 << 0))
|
||||||
pad->button |= PAD_BUTTON_A;
|
pad.button |= PAD_BUTTON_A;
|
||||||
if (b1 & (1 << 1))
|
if (b1 & (1 << 1))
|
||||||
pad->button |= PAD_BUTTON_B;
|
pad.button |= PAD_BUTTON_B;
|
||||||
if (b1 & (1 << 2))
|
if (b1 & (1 << 2))
|
||||||
pad->button |= PAD_BUTTON_X;
|
pad.button |= PAD_BUTTON_X;
|
||||||
if (b1 & (1 << 3))
|
if (b1 & (1 << 3))
|
||||||
pad->button |= PAD_BUTTON_Y;
|
pad.button |= PAD_BUTTON_Y;
|
||||||
|
|
||||||
if (b1 & (1 << 4))
|
if (b1 & (1 << 4))
|
||||||
pad->button |= PAD_BUTTON_LEFT;
|
pad.button |= PAD_BUTTON_LEFT;
|
||||||
if (b1 & (1 << 5))
|
if (b1 & (1 << 5))
|
||||||
pad->button |= PAD_BUTTON_RIGHT;
|
pad.button |= PAD_BUTTON_RIGHT;
|
||||||
if (b1 & (1 << 6))
|
if (b1 & (1 << 6))
|
||||||
pad->button |= PAD_BUTTON_DOWN;
|
pad.button |= PAD_BUTTON_DOWN;
|
||||||
if (b1 & (1 << 7))
|
if (b1 & (1 << 7))
|
||||||
pad->button |= PAD_BUTTON_UP;
|
pad.button |= PAD_BUTTON_UP;
|
||||||
|
|
||||||
if (b2 & (1 << 0))
|
if (b2 & (1 << 0))
|
||||||
pad->button |= PAD_BUTTON_START;
|
pad.button |= PAD_BUTTON_START;
|
||||||
if (b2 & (1 << 1))
|
if (b2 & (1 << 1))
|
||||||
pad->button |= PAD_TRIGGER_Z;
|
pad.button |= PAD_TRIGGER_Z;
|
||||||
if (b2 & (1 << 2))
|
if (b2 & (1 << 2))
|
||||||
pad->button |= PAD_TRIGGER_R;
|
pad.button |= PAD_TRIGGER_R;
|
||||||
if (b2 & (1 << 3))
|
if (b2 & (1 << 3))
|
||||||
pad->button |= PAD_TRIGGER_L;
|
pad.button |= PAD_TRIGGER_L;
|
||||||
|
|
||||||
if (get_origin)
|
if (get_origin)
|
||||||
pad->button |= PAD_GET_ORIGIN;
|
pad.button |= PAD_GET_ORIGIN;
|
||||||
|
|
||||||
pad->stickX = controller_payload_copy[1 + (9 * chan) + 3];
|
pad.stickX = controller_payload_copy[1 + (9 * chan) + 3];
|
||||||
pad->stickY = controller_payload_copy[1 + (9 * chan) + 4];
|
pad.stickY = controller_payload_copy[1 + (9 * chan) + 4];
|
||||||
pad->substickX = controller_payload_copy[1 + (9 * chan) + 5];
|
pad.substickX = controller_payload_copy[1 + (9 * chan) + 5];
|
||||||
pad->substickY = controller_payload_copy[1 + (9 * chan) + 6];
|
pad.substickY = controller_payload_copy[1 + (9 * chan) + 6];
|
||||||
pad->triggerLeft = controller_payload_copy[1 + (9 * chan) + 7];
|
pad.triggerLeft = controller_payload_copy[1 + (9 * chan) + 7];
|
||||||
pad->triggerRight = controller_payload_copy[1 + (9 * chan) + 8];
|
pad.triggerRight = controller_payload_copy[1 + (9 * chan) + 8];
|
||||||
}
|
}
|
||||||
else if (!Core::g_want_determinism)
|
else if (!Core::g_want_determinism)
|
||||||
{
|
{
|
||||||
// This is a hack to prevent a desync due to SI devices
|
// This is a hack to prevent a desync due to SI devices
|
||||||
// being different and returning different values.
|
// being different and returning different values.
|
||||||
// The corresponding code in DeviceGCAdapter has the same check
|
// The corresponding code in DeviceGCAdapter has the same check
|
||||||
pad->button = PAD_ERR_STATUS;
|
pad.button = PAD_ERR_STATUS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceConnected(int chan)
|
bool DeviceConnected(int chan)
|
||||||
|
@ -24,7 +24,7 @@ void Shutdown();
|
|||||||
void SetAdapterCallback(std::function<void(void)> func);
|
void SetAdapterCallback(std::function<void(void)> func);
|
||||||
void StartScanThread();
|
void StartScanThread();
|
||||||
void StopScanThread();
|
void StopScanThread();
|
||||||
void Input(int chan, GCPadStatus* pad);
|
GCPadStatus Input(int chan);
|
||||||
void Output(int chan, u8 rumble_command);
|
void Output(int chan, u8 rumble_command);
|
||||||
bool IsDetected();
|
bool IsDetected();
|
||||||
bool IsDriverDetected();
|
bool IsDriverDetected();
|
||||||
|
@ -262,10 +262,10 @@ void StopScanThread()
|
|||||||
s_adapter_detect_thread.join();
|
s_adapter_detect_thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input(int chan, GCPadStatus* pad)
|
GCPadStatus Input(int chan)
|
||||||
{
|
{
|
||||||
if (!UseAdapter() || !s_detected || !s_fd)
|
if (!UseAdapter() || !s_detected || !s_fd)
|
||||||
return;
|
return {};
|
||||||
|
|
||||||
int payload_size = 0;
|
int payload_size = 0;
|
||||||
u8 controller_payload_copy[37];
|
u8 controller_payload_copy[37];
|
||||||
@ -277,6 +277,7 @@ void Input(int chan, GCPadStatus* pad)
|
|||||||
payload_size = s_controller_payload_size.load();
|
payload_size = s_controller_payload_size.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GCPadStatus pad = {};
|
||||||
if (payload_size != sizeof(controller_payload_copy))
|
if (payload_size != sizeof(controller_payload_copy))
|
||||||
{
|
{
|
||||||
ERROR_LOG(SERIALINTERFACE, "error reading payload (size: %d, type: %02x)", payload_size,
|
ERROR_LOG(SERIALINTERFACE, "error reading payload (size: %d, type: %02x)", payload_size,
|
||||||
@ -297,54 +298,55 @@ void Input(int chan, GCPadStatus* pad)
|
|||||||
|
|
||||||
s_controller_type[chan] = type;
|
s_controller_type[chan] = type;
|
||||||
|
|
||||||
memset(pad, 0, sizeof(*pad));
|
|
||||||
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
||||||
{
|
{
|
||||||
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
||||||
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
||||||
|
|
||||||
if (b1 & (1 << 0))
|
if (b1 & (1 << 0))
|
||||||
pad->button |= PAD_BUTTON_A;
|
pad.button |= PAD_BUTTON_A;
|
||||||
if (b1 & (1 << 1))
|
if (b1 & (1 << 1))
|
||||||
pad->button |= PAD_BUTTON_B;
|
pad.button |= PAD_BUTTON_B;
|
||||||
if (b1 & (1 << 2))
|
if (b1 & (1 << 2))
|
||||||
pad->button |= PAD_BUTTON_X;
|
pad.button |= PAD_BUTTON_X;
|
||||||
if (b1 & (1 << 3))
|
if (b1 & (1 << 3))
|
||||||
pad->button |= PAD_BUTTON_Y;
|
pad.button |= PAD_BUTTON_Y;
|
||||||
|
|
||||||
if (b1 & (1 << 4))
|
if (b1 & (1 << 4))
|
||||||
pad->button |= PAD_BUTTON_LEFT;
|
pad.button |= PAD_BUTTON_LEFT;
|
||||||
if (b1 & (1 << 5))
|
if (b1 & (1 << 5))
|
||||||
pad->button |= PAD_BUTTON_RIGHT;
|
pad.button |= PAD_BUTTON_RIGHT;
|
||||||
if (b1 & (1 << 6))
|
if (b1 & (1 << 6))
|
||||||
pad->button |= PAD_BUTTON_DOWN;
|
pad.button |= PAD_BUTTON_DOWN;
|
||||||
if (b1 & (1 << 7))
|
if (b1 & (1 << 7))
|
||||||
pad->button |= PAD_BUTTON_UP;
|
pad.button |= PAD_BUTTON_UP;
|
||||||
|
|
||||||
if (b2 & (1 << 0))
|
if (b2 & (1 << 0))
|
||||||
pad->button |= PAD_BUTTON_START;
|
pad.button |= PAD_BUTTON_START;
|
||||||
if (b2 & (1 << 1))
|
if (b2 & (1 << 1))
|
||||||
pad->button |= PAD_TRIGGER_Z;
|
pad.button |= PAD_TRIGGER_Z;
|
||||||
if (b2 & (1 << 2))
|
if (b2 & (1 << 2))
|
||||||
pad->button |= PAD_TRIGGER_R;
|
pad.button |= PAD_TRIGGER_R;
|
||||||
if (b2 & (1 << 3))
|
if (b2 & (1 << 3))
|
||||||
pad->button |= PAD_TRIGGER_L;
|
pad.button |= PAD_TRIGGER_L;
|
||||||
|
|
||||||
if (get_origin)
|
if (get_origin)
|
||||||
pad->button |= PAD_GET_ORIGIN;
|
pad.button |= PAD_GET_ORIGIN;
|
||||||
|
|
||||||
pad->stickX = controller_payload_copy[1 + (9 * chan) + 3];
|
pad.stickX = controller_payload_copy[1 + (9 * chan) + 3];
|
||||||
pad->stickY = controller_payload_copy[1 + (9 * chan) + 4];
|
pad.stickY = controller_payload_copy[1 + (9 * chan) + 4];
|
||||||
pad->substickX = controller_payload_copy[1 + (9 * chan) + 5];
|
pad.substickX = controller_payload_copy[1 + (9 * chan) + 5];
|
||||||
pad->substickY = controller_payload_copy[1 + (9 * chan) + 6];
|
pad.substickY = controller_payload_copy[1 + (9 * chan) + 6];
|
||||||
pad->triggerLeft = controller_payload_copy[1 + (9 * chan) + 7];
|
pad.triggerLeft = controller_payload_copy[1 + (9 * chan) + 7];
|
||||||
pad->triggerRight = controller_payload_copy[1 + (9 * chan) + 8];
|
pad.triggerRight = controller_payload_copy[1 + (9 * chan) + 8];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pad->button = PAD_ERR_STATUS;
|
pad.button = PAD_ERR_STATUS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Output(int chan, u8 rumble_command)
|
void Output(int chan, u8 rumble_command)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "InputCommon/GCAdapter.h"
|
#include "InputCommon/GCAdapter.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "InputCommon/GCPadStatus.h"
|
||||||
|
|
||||||
namespace GCAdapter
|
namespace GCAdapter
|
||||||
{
|
{
|
||||||
@ -25,8 +26,9 @@ void StartScanThread()
|
|||||||
void StopScanThread()
|
void StopScanThread()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void Input(int chan, GCPadStatus* pad)
|
GCPadStatus Input(int chan)
|
||||||
{
|
{
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void Output(int chan, u8 rumble_command)
|
void Output(int chan, u8 rumble_command)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user