#include "negcon.h" #include "common/assert.h" #include "common/log.h" #include "common/state_wrapper.h" #include #include NeGcon::NeGcon() { m_axis_state.fill(0x00); m_axis_state[static_cast(Axis::Steering)] = 0x80; } NeGcon::~NeGcon() = default; ControllerType NeGcon::GetType() const { return ControllerType::NeGcon; } std::optional NeGcon::GetAxisCodeByName(std::string_view axis_name) const { return StaticGetAxisCodeByName(axis_name); } std::optional NeGcon::GetButtonCodeByName(std::string_view button_name) const { return StaticGetButtonCodeByName(button_name); } void NeGcon::Reset() { m_transfer_state = TransferState::Idle; } bool NeGcon::DoState(StateWrapper& sw) { if (!Controller::DoState(sw)) return false; sw.Do(&m_button_state); sw.Do(&m_transfer_state); return true; } void NeGcon::SetAxisState(s32 axis_code, float value) { if (axis_code < 0 || axis_code >= static_cast(Axis::Count)) return; // Steering Axis: -1..1 -> 0..255 if (axis_code == static_cast(Axis::Steering)) { const u8 u8_value = static_cast(std::clamp(((value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); return; } // I, II, L: 0..1 -> 0..255 or -1..0 -> 0..255 to support negative axis ranges, // e.g. if bound to analog stick instead of trigger const u8 u8_value = static_cast(std::clamp(std::abs(value) * 255.0f, 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); } void NeGcon::SetAxisState(Axis axis, u8 value) { m_axis_state[static_cast(axis)] = value; } void NeGcon::SetButtonState(s32 button_code, bool pressed) { if (button_code < 0 || button_code >= static_cast(Button::Count)) return; SetButtonState(static_cast