2018-11-19 13:20:46 -05:00
|
|
|
#include "PH_GenericInput.h"
|
2023-11-03 14:21:16 +00:00
|
|
|
#include <array>
|
|
|
|
#include <utility>
|
2018-11-19 13:20:46 -05:00
|
|
|
|
|
|
|
void CPH_GenericInput::Update(uint8* ram)
|
|
|
|
{
|
2023-11-03 14:21:16 +00:00
|
|
|
using MotorPair = std::pair<uint8, uint8>;
|
|
|
|
std::array<MotorPair, CInputBindingManager::MAX_PADS> motorInfo;
|
2023-10-31 19:50:26 +00:00
|
|
|
for(auto* interface : m_interfaces)
|
2018-11-19 13:20:46 -05:00
|
|
|
{
|
2020-09-15 09:24:04 -04:00
|
|
|
for(unsigned int pad = 0; pad < CInputBindingManager::MAX_PADS; pad++)
|
2018-11-19 13:20:46 -05:00
|
|
|
{
|
2020-09-15 09:24:04 -04:00
|
|
|
for(unsigned int buttonIdx = 0; buttonIdx < PS2::CControllerInfo::MAX_BUTTONS; buttonIdx++)
|
2018-11-19 13:20:46 -05:00
|
|
|
{
|
2020-09-15 09:24:04 -04:00
|
|
|
auto button = static_cast<PS2::CControllerInfo::BUTTON>(buttonIdx);
|
|
|
|
const auto& binding = m_bindingManager.GetBinding(pad, button);
|
|
|
|
if(!binding) continue;
|
|
|
|
uint32 value = binding->GetValue();
|
2021-09-11 13:27:24 -04:00
|
|
|
if(PS2::CControllerInfo::IsAxis(button))
|
2020-09-15 09:24:04 -04:00
|
|
|
{
|
2023-10-31 19:50:26 +00:00
|
|
|
interface->SetAxisState(pad, button, value & 0xFF, ram);
|
2020-09-15 09:24:04 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-31 19:50:26 +00:00
|
|
|
interface->SetButtonState(pad, button, value != 0, ram);
|
2020-09-15 09:24:04 -04:00
|
|
|
}
|
2018-11-19 13:20:46 -05:00
|
|
|
}
|
2023-10-30 21:58:23 +00:00
|
|
|
// Only Sio2 currently provides vibration information
|
2023-11-03 14:21:16 +00:00
|
|
|
MotorPair motors{0, 0};
|
|
|
|
interface->GetVibration(pad, motors.first, motors.second);
|
|
|
|
auto& [largeMotor, smallMotor] = motorInfo[pad];
|
|
|
|
largeMotor = std::max(motors.first, largeMotor);
|
|
|
|
smallMotor = std::max(motors.second, smallMotor);
|
2018-11-19 13:20:46 -05:00
|
|
|
}
|
|
|
|
}
|
2023-10-30 22:11:10 +00:00
|
|
|
|
2023-11-03 14:21:16 +00:00
|
|
|
for(unsigned int pad = 0; pad < CInputBindingManager::MAX_PADS; pad++)
|
2023-10-30 22:11:10 +00:00
|
|
|
{
|
|
|
|
auto motorBinding = m_bindingManager.GetMotorBinding(pad);
|
|
|
|
if(!motorBinding) continue;
|
2023-11-03 14:21:16 +00:00
|
|
|
auto& [largeMotor, smallMotor] = motorInfo[pad];
|
2023-10-30 22:11:10 +00:00
|
|
|
motorBinding->ProcessEvent(largeMotor, smallMotor);
|
|
|
|
}
|
2018-11-19 13:20:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CInputBindingManager& CPH_GenericInput::GetBindingManager()
|
|
|
|
{
|
|
|
|
return m_bindingManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPadHandler::FactoryFunction CPH_GenericInput::GetFactoryFunction()
|
|
|
|
{
|
2018-11-28 22:32:27 -05:00
|
|
|
return []() { return new CPH_GenericInput(); };
|
2018-11-19 13:20:46 -05:00
|
|
|
}
|