Merge pull request #5086 from lioncash/si

SI_Devices: Minor cleanup
This commit is contained in:
Markus Wick
2017-03-15 10:07:27 +01:00
committed by GitHub
8 changed files with 203 additions and 203 deletions
+11 -11
View File
@@ -7,27 +7,27 @@
#include "Common/CommonTypes.h"
#include "InputCommon/GCPadStatus.h"
CSIDevice_DanceMat::CSIDevice_DanceMat(SIDevices device, int _iDeviceNumber)
: CSIDevice_GCController(device, _iDeviceNumber)
CSIDevice_DanceMat::CSIDevice_DanceMat(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
{
}
int CSIDevice_DanceMat::RunBuffer(u8* _pBuffer, int _iLength)
int CSIDevice_DanceMat::RunBuffer(u8* buffer, int length)
{
// Read the command
EBufferCommands command = static_cast<EBufferCommands>(_pBuffer[3]);
EBufferCommands command = static_cast<EBufferCommands>(buffer[3]);
if (command == CMD_RESET)
{
ISIDevice::RunBuffer(_pBuffer, _iLength);
*(u32*)&_pBuffer[0] = SI_DANCEMAT;
ISIDevice::RunBuffer(buffer, length);
*(u32*)&buffer[0] = SI_DANCEMAT;
}
else
{
return CSIDevice_GCController::RunBuffer(_pBuffer, _iLength);
return CSIDevice_GCController::RunBuffer(buffer, length);
}
return _iLength;
return length;
}
u32 CSIDevice_DanceMat::MapPadStatus(const GCPadStatus& pad_status)
@@ -59,12 +59,12 @@ u32 CSIDevice_DanceMat::MapPadStatus(const GCPadStatus& pad_status)
return (u32)(map << 16) | 0x8080;
}
bool CSIDevice_DanceMat::GetData(u32& _Hi, u32& _Low)
bool CSIDevice_DanceMat::GetData(u32& hi, u32& low)
{
CSIDevice_GCController::GetData(_Hi, _Low);
CSIDevice_GCController::GetData(hi, low);
// Identifies the dance mat
_Low = 0x8080ffff;
low = 0x8080ffff;
return true;
}
+3 -3
View File
@@ -12,9 +12,9 @@ struct GCPadStatus;
class CSIDevice_DanceMat : public CSIDevice_GCController
{
public:
CSIDevice_DanceMat(SIDevices device, int _iDeviceNumber);
CSIDevice_DanceMat(SIDevices device, int device_number);
int RunBuffer(u8* _pBuffer, int _iLength) override;
int RunBuffer(u8* buffer, int length) override;
u32 MapPadStatus(const GCPadStatus& pad_status) override;
bool GetData(u32& _Hi, u32& _Low) override;
bool GetData(u32& hi, u32& low) override;
};
@@ -15,13 +15,13 @@
#include "Core/NetPlayProto.h"
#include "InputCommon/GCAdapter.h"
CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber)
: CSIDevice_GCController(device, _iDeviceNumber)
CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
{
// get the correct pad number that should rumble locally when using netplay
const int numPAD = NetPlay_InGamePadToLocalPad(m_device_number);
if (numPAD < 4)
m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[numPAD];
const int pad_num = NetPlay_InGamePadToLocalPad(m_device_number);
if (pad_num < 4)
m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[pad_num];
}
GCPadStatus CSIDevice_GCAdapter::GetPadStatus()
@@ -60,11 +60,11 @@ int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int length)
return CSIDevice_GCController::RunBuffer(buffer, length);
}
void CSIDevice_GCController::Rumble(int numPad, ControlState strength)
void CSIDevice_GCController::Rumble(int pad_num, ControlState strength)
{
SIDevices device = SConfig::GetInstance().m_SIDevice[numPad];
SIDevices device = SConfig::GetInstance().m_SIDevice[pad_num];
if (device == SIDEVICE_WIIU_ADAPTER)
GCAdapter::Output(numPad, static_cast<u8>(strength));
GCAdapter::Output(pad_num, static_cast<u8>(strength));
else if (SIDevice_IsGCController(device))
Pad::Rumble(numPad, strength);
Pad::Rumble(pad_num, strength);
}
+1 -1
View File
@@ -11,7 +11,7 @@
class CSIDevice_GCAdapter : public CSIDevice_GCController
{
public:
CSIDevice_GCAdapter(SIDevices device, int _iDeviceNumber);
CSIDevice_GCAdapter(SIDevices device, int device_number);
GCPadStatus GetPadStatus() override;
int RunBuffer(u8* buffer, int length) override;
@@ -8,106 +8,106 @@
#include "Common/Logging/Log.h"
#include "Core/HW/GCPad.h"
CSIDevice_GCSteeringWheel::CSIDevice_GCSteeringWheel(SIDevices device, int _iDeviceNumber)
: CSIDevice_GCController(device, _iDeviceNumber)
CSIDevice_GCSteeringWheel::CSIDevice_GCSteeringWheel(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
{
}
int CSIDevice_GCSteeringWheel::RunBuffer(u8* _pBuffer, int _iLength)
int CSIDevice_GCSteeringWheel::RunBuffer(u8* buffer, int length)
{
// For debug logging only
ISIDevice::RunBuffer(_pBuffer, _iLength);
ISIDevice::RunBuffer(buffer, length);
// Read the command
EBufferCommands command = static_cast<EBufferCommands>(_pBuffer[3]);
EBufferCommands command = static_cast<EBufferCommands>(buffer[3]);
// Handle it
switch (command)
{
case CMD_RESET:
case CMD_ID:
*(u32*)&_pBuffer[0] = SI_GC_STEERING;
*(u32*)&buffer[0] = SI_GC_STEERING;
break;
// DEFAULT
default:
{
return CSIDevice_GCController::RunBuffer(_pBuffer, _iLength);
return CSIDevice_GCController::RunBuffer(buffer, length);
}
break;
}
return _iLength;
return length;
}
bool CSIDevice_GCSteeringWheel::GetData(u32& _Hi, u32& _Low)
bool CSIDevice_GCSteeringWheel::GetData(u32& hi, u32& low)
{
if (m_mode == 6)
{
GCPadStatus PadStatus = GetPadStatus();
GCPadStatus pad_status = GetPadStatus();
_Hi = (u32)((u8)PadStatus.stickX); // Steering
_Hi |= 0x800; // Pedal connected flag
_Hi |= (u32)((u16)(PadStatus.button | PAD_USE_ORIGIN) << 16);
hi = (u32)((u8)pad_status.stickX); // Steering
hi |= 0x800; // Pedal connected flag
hi |= (u32)((u16)(pad_status.button | PAD_USE_ORIGIN) << 16);
_Low = (u8)PadStatus.triggerRight; // All 8 bits
_Low |= (u32)((u8)PadStatus.triggerLeft << 8); // All 8 bits
low = (u8)pad_status.triggerRight; // All 8 bits
low |= (u32)((u8)pad_status.triggerLeft << 8); // All 8 bits
// The GC Steering Wheel appears to have combined pedals
// (both the Accelerate and Brake pedals are mapped to a single axis)
// We use the stickY axis for the pedals.
if (PadStatus.stickY < 128)
_Low |= (u32)((u8)(255 - ((PadStatus.stickY & 0x7f) * 2)) << 16); // All 8 bits (Brake)
if (PadStatus.stickY >= 128)
_Low |= (u32)((u8)((PadStatus.stickY & 0x7f) * 2) << 24); // All 8 bits (Accelerate)
if (pad_status.stickY < 128)
low |= (u32)((u8)(255 - ((pad_status.stickY & 0x7f) * 2)) << 16); // All 8 bits (Brake)
if (pad_status.stickY >= 128)
low |= (u32)((u8)((pad_status.stickY & 0x7f) * 2) << 24); // All 8 bits (Accelerate)
HandleButtonCombos(PadStatus);
HandleButtonCombos(pad_status);
}
else
{
return CSIDevice_GCController::GetData(_Hi, _Low);
return CSIDevice_GCController::GetData(hi, low);
}
return true;
}
void CSIDevice_GCSteeringWheel::SendCommand(u32 _Cmd, u8 _Poll)
void CSIDevice_GCSteeringWheel::SendCommand(u32 command, u8 poll)
{
UCommand command(_Cmd);
UCommand wheel_command(command);
if (command.command == CMD_FORCE)
if (wheel_command.command == CMD_FORCE)
{
// 0 = left strong, 127 = left weak, 128 = right weak, 255 = right strong
unsigned int uStrength = command.parameter1;
unsigned int strength = wheel_command.parameter1;
// 06 = motor on, 04 = motor off
unsigned int uType = command.parameter2;
unsigned int type = wheel_command.parameter2;
// get the correct pad number that should rumble locally when using netplay
const int numPAD = NetPlay_InGamePadToLocalPad(m_device_number);
const int pad_num = NetPlay_InGamePadToLocalPad(m_device_number);
if (numPAD < 4)
if (pad_num < 4)
{
if (uType == 0x06)
if (type == 0x06)
{
// map 0..255 to -1.0..1.0
ControlState strength = uStrength / 127.5 - 1;
Pad::Rumble(numPAD, strength);
ControlState mapped_strength = strength / 127.5 - 1;
Pad::Rumble(pad_num, mapped_strength);
}
else
{
Pad::Rumble(numPAD, 0);
Pad::Rumble(pad_num, 0);
}
}
if (!_Poll)
if (!poll)
{
m_mode = command.parameter2;
m_mode = wheel_command.parameter2;
INFO_LOG(SERIALINTERFACE, "PAD %i set to mode %i", m_device_number, m_mode);
}
}
else
{
return CSIDevice_GCController::SendCommand(_Cmd, _Poll);
return CSIDevice_GCController::SendCommand(command, poll);
}
}
@@ -8,6 +8,13 @@
class CSIDevice_GCSteeringWheel : public CSIDevice_GCController
{
public:
CSIDevice_GCSteeringWheel(SIDevices device, int device_number);
int RunBuffer(u8* buffer, int length) override;
bool GetData(u32& hi, u32& low) override;
void SendCommand(u32 command, u8 poll) override;
private:
// Commands
enum EBufferCommands
@@ -23,11 +30,4 @@ private:
CMD_FORCE = 0x30,
CMD_WRITE = 0x40
};
public:
CSIDevice_GCSteeringWheel(SIDevices device, int _iDeviceNumber);
int RunBuffer(u8* _pBuffer, int _iLength) override;
bool GetData(u32& _Hi, u32& _Low) override;
void SendCommand(u32 _Cmd, u8 _Poll) override;
};
File diff suppressed because it is too large Load Diff
+27 -27
View File
@@ -11,6 +11,25 @@ struct KeyboardStatus;
class CSIDevice_Keyboard : public ISIDevice
{
public:
// Constructor
CSIDevice_Keyboard(SIDevices device, int device_number);
// Run the SI Buffer
int RunBuffer(u8* buffer, int length) override;
// Return true on new data
bool GetData(u32& hi, u32& low) override;
KeyboardStatus GetKeyboardStatus() const;
void MapKeys(const KeyboardStatus& key_status, u8* key);
// Send a command directly
void SendCommand(u32 command, u8 poll) override;
// Savestate support
void DoState(PointerWrap& p) override;
protected:
// Commands
enum EBufferCommands
@@ -28,40 +47,21 @@ protected:
union UCommand
{
u32 Hex;
u32 hex = 0;
struct
{
u32 Parameter1 : 8;
u32 Parameter2 : 8;
u32 Command : 8;
u32 parameter1 : 8;
u32 parameter2 : 8;
u32 command : 8;
u32 : 8;
};
UCommand() { Hex = 0; }
UCommand(u32 _iValue) { Hex = _iValue; }
UCommand() = default;
UCommand(u32 value) : hex{value} {}
};
// PADAnalogMode
u8 m_Mode;
u8 m_mode = 0;
// Internal counter synchonizing GC and keyboard
u8 m_Counter;
public:
// Constructor
CSIDevice_Keyboard(SIDevices device, int _iDeviceNumber);
// Run the SI Buffer
int RunBuffer(u8* _pBuffer, int _iLength) override;
// Return true on new data
bool GetData(u32& _Hi, u32& _Low) override;
KeyboardStatus GetKeyboardStatus() const;
void MapKeys(const KeyboardStatus& KeyStatus, u8* key);
// Send a command directly
void SendCommand(u32 _Cmd, u8 _Poll) override;
// Savestate support
void DoState(PointerWrap& p) override;
u8 m_counter = 0;
};