Merge pull request #1410 from ggrtk/get-analog-input-bytes

Controller: Add method for reading analog input bytes
This commit is contained in:
Connor McLaughlin 2021-01-09 00:19:38 +10:00 committed by GitHub
commit 5add87c8ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 0 deletions

View file

@ -151,6 +151,12 @@ u32 AnalogController::GetButtonStateBits() const
return m_button_state ^ 0xFFFF;
}
std::optional<u32> AnalogController::GetAnalogInputBytes() const
{
return m_axis_state[static_cast<size_t>(Axis::LeftY)] << 24 | m_axis_state[static_cast<size_t>(Axis::LeftX)] << 16 |
m_axis_state[static_cast<size_t>(Axis::RightY)] << 8 | m_axis_state[static_cast<size_t>(Axis::RightX)];
}
u32 AnalogController::GetVibrationMotorCount() const
{
return NUM_MOTORS;

View file

@ -62,6 +62,7 @@ public:
void SetAxisState(s32 axis_code, float value) override;
void SetButtonState(s32 button_code, bool pressed) override;
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
void ResetTransferState() override;
bool Transfer(const u8 data_in, u8* data_out) override;

View file

@ -115,6 +115,12 @@ u32 AnalogJoystick::GetButtonStateBits() const
return m_button_state ^ 0xFFFF;
}
std::optional<u32> AnalogJoystick::GetAnalogInputBytes() const
{
return m_axis_state[static_cast<size_t>(Axis::LeftY)] << 24 | m_axis_state[static_cast<size_t>(Axis::LeftX)] << 16 |
m_axis_state[static_cast<size_t>(Axis::RightY)] << 8 | m_axis_state[static_cast<size_t>(Axis::RightX)];
}
void AnalogJoystick::ResetTransferState()
{
m_transfer_state = TransferState::Idle;

View file

@ -60,6 +60,7 @@ public:
void SetAxisState(s32 axis_code, float value) override;
void SetButtonState(s32 button_code, bool pressed) override;
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
void ResetTransferState() override;
bool Transfer(const u8 data_in, u8* data_out) override;

View file

@ -35,6 +35,11 @@ u32 Controller::GetButtonStateBits() const
return 0;
}
std::optional<u32> Controller::GetAnalogInputBytes() const
{
return std::nullopt;
}
u32 Controller::GetVibrationMotorCount() const
{
return 0;

View file

@ -54,6 +54,9 @@ public:
/// Returns a bitmask of the current button states, 1 = on.
virtual u32 GetButtonStateBits() const;
/// Returns analog input bytes packed as a u32. Values are specific to controller type.
virtual std::optional<u32> GetAnalogInputBytes() const;
/// Returns the number of vibration motors.
virtual u32 GetVibrationMotorCount() const;

View file

@ -97,6 +97,17 @@ void NeGcon::SetButtonState(Button button, bool pressed)
m_button_state |= u16(1) << indices[static_cast<u8>(button)];
}
u32 NeGcon::GetButtonStateBits() const
{
return m_button_state ^ 0xFFFF;
}
std::optional<u32> NeGcon::GetAnalogInputBytes() const
{
return m_axis_state[static_cast<size_t>(Axis::L)] << 24 | m_axis_state[static_cast<size_t>(Axis::II)] << 16 |
m_axis_state[static_cast<size_t>(Axis::I)] << 8 | m_axis_state[static_cast<size_t>(Axis::Steering)];
}
void NeGcon::ResetTransferState()
{
m_transfer_state = TransferState::Idle;

View file

@ -57,6 +57,9 @@ public:
void SetAxisState(Axis axis, u8 value);
void SetButtonState(Button button, bool pressed);
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
void LoadSettings(const char* section) override;
private: