Add a stubbed GCAdapter namespace.

This cleans up a bunch of #ifdef checks in places.
This commit is contained in:
Ryan Houdek 2016-01-06 00:57:08 -06:00
parent af6a5ddafe
commit 6e503bebc4
8 changed files with 38 additions and 33 deletions

View File

@ -21,9 +21,7 @@ GCPadStatus CSIDevice_GCAdapter::GetPadStatus()
GCPadStatus PadStatus;
memset(&PadStatus, 0, sizeof(PadStatus));
#if defined(__LIBUSB__) || defined (_WIN32)
GCAdapter::Input(ISIDevice::m_iDeviceNumber, &PadStatus);
#endif
HandleMoviePadStatus(&PadStatus);
@ -38,11 +36,9 @@ int CSIDevice_GCAdapter::RunBuffer(u8* _pBuffer, int _iLength)
// Read the command
EBufferCommands command = static_cast<EBufferCommands>(_pBuffer[3]);
#if defined(__LIBUSB__) || defined (_WIN32)
// get the correct pad number that should rumble locally when using netplay
const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber);
if (!GCAdapter::DeviceConnected(numPAD))
#endif
{
reinterpret_cast<u32*>(_pBuffer)[0] = SI_NONE;
return 4;
@ -122,7 +118,6 @@ void CSIDevice_GCAdapter::SendCommand(u32 _Cmd, u8 _Poll)
case CMD_WRITE:
{
#if defined(__LIBUSB__) || defined (_WIN32)
unsigned int uType = command.Parameter1; // 0 = stop, 1 = rumble, 2 = stop hard
unsigned int uStrength = command.Parameter2;
@ -136,7 +131,6 @@ void CSIDevice_GCAdapter::SendCommand(u32 _Cmd, u8 _Poll)
else
GCAdapter::Output(numPAD, 0);
}
#endif
if (!_Poll)
{
m_Mode = command.Parameter2;

View File

@ -30,7 +30,6 @@ GCAdapterConfigDiag::GCAdapterConfigDiag(wxWindow* const parent, const wxString&
m_adapter_status = new wxStaticText(this, wxID_ANY, _("Adapter Not Detected"));
#if defined(__LIBUSB__) || defined (_WIN32)
if (!GCAdapter::IsDetected())
{
if (!GCAdapter::IsDriverDetected())
@ -44,7 +43,6 @@ GCAdapterConfigDiag::GCAdapterConfigDiag(wxWindow* const parent, const wxString&
m_adapter_status->SetLabelText(_("Adapter Detected"));
}
GCAdapter::SetAdapterCallback(std::bind(&GCAdapterConfigDiag::ScheduleAdapterUpdate, this));
#endif
szr->Add(m_adapter_status, 0, wxEXPAND);
szr->Add(gamecube_rumble, 0, wxEXPAND);
@ -65,19 +63,15 @@ void GCAdapterConfigDiag::ScheduleAdapterUpdate()
void GCAdapterConfigDiag::UpdateAdapter(wxCommandEvent& ev)
{
#if defined(__LIBUSB__) || defined (_WIN32)
bool unpause = Core::PauseAndLock(true);
if (GCAdapter::IsDetected())
m_adapter_status->SetLabelText(_("Adapter Detected"));
else
m_adapter_status->SetLabelText(_("Adapter Not Detected"));
Core::PauseAndLock(false, unpause);
#endif
}
GCAdapterConfigDiag::~GCAdapterConfigDiag()
{
#if defined(__LIBUSB__) || defined (_WIN32)
GCAdapter::SetAdapterCallback(nullptr);
#endif
}

View File

@ -487,12 +487,10 @@ void ControllerConfigDiag::OnGameCubePortChanged(wxCommandEvent& event)
SConfig::GetInstance().m_SIDevice[device_num] = tempType;
#if defined(__LIBUSB__) || defined (_WIN32)
if (GCAdapter::UseAdapter())
GCAdapter::StartScanThread();
else
GCAdapter::StopScanThread();
#endif
if (Core::IsRunning())
SerialInterface::ChangeDevice(tempType, device_num);

View File

@ -37,6 +37,8 @@ endif()
if(LIBUSB_FOUND)
set(SRCS ${SRCS} GCAdapter.cpp)
else()
set(SRCS ${SRCS} GCAdapter_Null.cpp)
endif(LIBUSB_FOUND)
if(LIBEVDEV_FOUND AND LIBUDEV_FOUND)

View File

@ -20,19 +20,12 @@
namespace GCAdapter
{
enum ControllerTypes
{
CONTROLLER_NONE = 0,
CONTROLLER_WIRED = 1,
CONTROLLER_WIRELESS = 2
};
static bool CheckDeviceAccess(libusb_device* device);
static void AddGCAdapter(libusb_device* device);
static bool s_detected = false;
static libusb_device_handle* s_handle = nullptr;
static u8 s_controller_type[MAX_SI_CHANNELS] = { CONTROLLER_NONE, CONTROLLER_NONE, CONTROLLER_NONE, CONTROLLER_NONE };
static u8 s_controller_type[MAX_SI_CHANNELS] = { ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE };
static u8 s_controller_rumble[4];
static std::mutex s_mutex;
@ -189,7 +182,7 @@ void Setup()
for (int i = 0; i < MAX_SI_CHANNELS; i++)
{
s_controller_type[i] = CONTROLLER_NONE;
s_controller_type[i] = ControllerTypes::CONTROLLER_NONE;
s_controller_rumble[i] = 0;
}
@ -339,7 +332,7 @@ void Reset()
}
for (int i = 0; i < MAX_SI_CHANNELS; i++)
s_controller_type[i] = CONTROLLER_NONE;
s_controller_type[i] = ControllerTypes::CONTROLLER_NONE;
s_detected = false;
@ -378,7 +371,7 @@ void Input(int chan, GCPadStatus* pad)
{
bool get_origin = false;
u8 type = controller_payload_copy[1 + (9 * chan)] >> 4;
if (type != CONTROLLER_NONE && s_controller_type[chan] == CONTROLLER_NONE)
if (type != ControllerTypes::CONTROLLER_NONE && s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE)
{
NOTICE_LOG(SERIALINTERFACE, "New device connected to Port %d of Type: %02x", chan + 1, controller_payload_copy[1 + (9 * chan)]);
get_origin = true;
@ -387,7 +380,7 @@ void Input(int chan, GCPadStatus* pad)
s_controller_type[chan] = type;
memset(pad, 0, sizeof(*pad));
if (s_controller_type[chan] != CONTROLLER_NONE)
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
{
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
@ -425,7 +418,7 @@ void Input(int chan, GCPadStatus* pad)
bool DeviceConnected(int chan)
{
return s_controller_type[chan] != CONTROLLER_NONE;
return s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE;
}
bool UseAdapter()
@ -459,7 +452,7 @@ void Output(int chan, u8 rumble_command)
return;
// Skip over rumble commands if it has not changed or the controller is wireless
if (rumble_command != s_controller_rumble[chan] && s_controller_type[chan] != CONTROLLER_WIRELESS)
if (rumble_command != s_controller_rumble[chan] && s_controller_type[chan] != ControllerTypes::CONTROLLER_WIRELESS)
{
s_controller_rumble[chan] = rumble_command;

View File

@ -10,7 +10,12 @@ struct GCPadStatus;
namespace GCAdapter
{
enum ControllerTypes
{
CONTROLLER_NONE = 0,
CONTROLLER_WIRED = 1,
CONTROLLER_WIRELESS = 2
};
void Init();
void Reset();
void ResetRumble();

View File

@ -0,0 +1,23 @@
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/GCAdapter.h"
namespace GCAdapter
{
void Init() {}
void Reset() {}
void ResetRumble() {}
void Setup() {}
void Shutdown() {}
void SetAdapterCallback(std::function<void(void)> func) {}
void StartScanThread() {}
void StopScanThread() {}
void Input(int chan, GCPadStatus* pad) {}
void Output(int chan, u8 rumble_command) {}
bool IsDetected() { return false; }
bool IsDriverDetected() { return false; }
bool DeviceConnected(int chan) { return false; }
bool UseAdapter() { return false; }
} // end of namespace GCAdapter

View File

@ -28,9 +28,7 @@ void Init()
SConfig::Init();
VideoBackend::PopulateList();
WiimoteReal::LoadSettings();
#if defined(__LIBUSB__) || defined (_WIN32)
GCAdapter::Init();
#endif
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
SetEnableAlert(SConfig::GetInstance().bUsePanicHandlers);
@ -38,9 +36,7 @@ void Init()
void Shutdown()
{
#if defined(__LIBUSB__) || defined (_WIN32)
GCAdapter::Shutdown();
#endif
WiimoteReal::Shutdown();
VideoBackend::ClearList();
SConfig::Shutdown();