|
|
|
@ -25,19 +25,15 @@ Adapter::Adapter() {
|
|
|
|
|
|
|
|
|
|
current_status = NO_ADAPTER_DETECTED;
|
|
|
|
|
libusb_init(&libusb_ctx);
|
|
|
|
|
get_origin.fill(true);
|
|
|
|
|
|
|
|
|
|
StartScanThread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) {
|
|
|
|
|
GCPadStatus pad = {};
|
|
|
|
|
bool get_origin = false;
|
|
|
|
|
|
|
|
|
|
ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4);
|
|
|
|
|
if (type != ControllerTypes::None) {
|
|
|
|
|
get_origin = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adapter_controllers_status[port] = type;
|
|
|
|
|
|
|
|
|
|
static constexpr std::array<PadButton, 8> b1_buttons{
|
|
|
|
@ -69,16 +65,22 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_origin) {
|
|
|
|
|
pad.button |= PAD_GET_ORIGIN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pad.stick_x = adapter_payload[1 + (9 * port) + 3];
|
|
|
|
|
pad.stick_y = adapter_payload[1 + (9 * port) + 4];
|
|
|
|
|
pad.substick_x = adapter_payload[1 + (9 * port) + 5];
|
|
|
|
|
pad.substick_y = adapter_payload[1 + (9 * port) + 6];
|
|
|
|
|
pad.trigger_left = adapter_payload[1 + (9 * port) + 7];
|
|
|
|
|
pad.trigger_right = adapter_payload[1 + (9 * port) + 8];
|
|
|
|
|
|
|
|
|
|
if (get_origin[port]) {
|
|
|
|
|
origin_status[port].stick_x = pad.stick_x;
|
|
|
|
|
origin_status[port].stick_y = pad.stick_y;
|
|
|
|
|
origin_status[port].substick_x = pad.substick_x;
|
|
|
|
|
origin_status[port].substick_y = pad.substick_y;
|
|
|
|
|
origin_status[port].trigger_left = pad.trigger_left;
|
|
|
|
|
origin_status[port].trigger_right = pad.trigger_right;
|
|
|
|
|
get_origin[port] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pad;
|
|
|
|
|
}
|
|
|
|
@ -127,31 +129,31 @@ void Adapter::Read() {
|
|
|
|
|
for (std::size_t port = 0; port < pads.size(); ++port) {
|
|
|
|
|
pads[port] = GetPadStatus(port, adapter_payload_copy);
|
|
|
|
|
if (DeviceConnected(port) && configuring) {
|
|
|
|
|
if (pads[port].button != PAD_GET_ORIGIN) {
|
|
|
|
|
if (pads[port].button != 0) {
|
|
|
|
|
pad_queue[port].Push(pads[port]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Accounting for a threshold here because of some controller variance
|
|
|
|
|
if (pads[port].stick_x > pads[port].MAIN_STICK_CENTER_X + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].stick_x < pads[port].MAIN_STICK_CENTER_X - pads[port].THRESHOLD) {
|
|
|
|
|
if (pads[port].stick_x > origin_status[port].stick_x + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].stick_x < origin_status[port].stick_x - pads[port].THRESHOLD) {
|
|
|
|
|
pads[port].axis = GCAdapter::PadAxes::StickX;
|
|
|
|
|
pads[port].axis_value = pads[port].stick_x;
|
|
|
|
|
pad_queue[port].Push(pads[port]);
|
|
|
|
|
}
|
|
|
|
|
if (pads[port].stick_y > pads[port].MAIN_STICK_CENTER_Y + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].stick_y < pads[port].MAIN_STICK_CENTER_Y - pads[port].THRESHOLD) {
|
|
|
|
|
if (pads[port].stick_y > origin_status[port].stick_y + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].stick_y < origin_status[port].stick_y - pads[port].THRESHOLD) {
|
|
|
|
|
pads[port].axis = GCAdapter::PadAxes::StickY;
|
|
|
|
|
pads[port].axis_value = pads[port].stick_y;
|
|
|
|
|
pad_queue[port].Push(pads[port]);
|
|
|
|
|
}
|
|
|
|
|
if (pads[port].substick_x > pads[port].C_STICK_CENTER_X + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].substick_x < pads[port].C_STICK_CENTER_X - pads[port].THRESHOLD) {
|
|
|
|
|
if (pads[port].substick_x > origin_status[port].substick_x + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].substick_x < origin_status[port].substick_x - pads[port].THRESHOLD) {
|
|
|
|
|
pads[port].axis = GCAdapter::PadAxes::SubstickX;
|
|
|
|
|
pads[port].axis_value = pads[port].substick_x;
|
|
|
|
|
pad_queue[port].Push(pads[port]);
|
|
|
|
|
}
|
|
|
|
|
if (pads[port].substick_y > pads[port].C_STICK_CENTER_Y + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].substick_y < pads[port].C_STICK_CENTER_Y - pads[port].THRESHOLD) {
|
|
|
|
|
if (pads[port].substick_y > origin_status[port].substick_y + pads[port].THRESHOLD ||
|
|
|
|
|
pads[port].substick_y < origin_status[port].substick_y - pads[port].THRESHOLD) {
|
|
|
|
|
pads[port].axis = GCAdapter::PadAxes::SubstickY;
|
|
|
|
|
pads[port].axis_value = pads[port].substick_y;
|
|
|
|
|
pad_queue[port].Push(pads[port]);
|
|
|
|
@ -325,6 +327,7 @@ void Adapter::Reset() {
|
|
|
|
|
adapter_input_thread.join();
|
|
|
|
|
|
|
|
|
|
adapter_controllers_status.fill(ControllerTypes::None);
|
|
|
|
|
get_origin.fill(true);
|
|
|
|
|
current_status = NO_ADAPTER_DETECTED;
|
|
|
|
|
|
|
|
|
|
if (usb_adapter_handle) {
|
|
|
|
@ -347,6 +350,7 @@ void Adapter::ResetDeviceType(int port) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Adapter::BeginConfiguration() {
|
|
|
|
|
get_origin.fill(true);
|
|
|
|
|
for (auto& pq : pad_queue) {
|
|
|
|
|
pq.Clear();
|
|
|
|
|
}
|
|
|
|
@ -376,4 +380,36 @@ const std::array<GCState, 4>& Adapter::GetPadState() const {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Adapter::GetOriginValue(int port, int axis) {
|
|
|
|
|
const PadAxes padaxis = static_cast<PadAxes>(axis);
|
|
|
|
|
if (padaxis == PadAxes::StickX)
|
|
|
|
|
return origin_status[port].stick_x;
|
|
|
|
|
if (padaxis == PadAxes::StickY)
|
|
|
|
|
return origin_status[port].stick_y;
|
|
|
|
|
if (padaxis == PadAxes::SubstickX)
|
|
|
|
|
return origin_status[port].substick_x;
|
|
|
|
|
if (padaxis == PadAxes::SubstickY)
|
|
|
|
|
return origin_status[port].substick_x;
|
|
|
|
|
if (padaxis == PadAxes::TriggerLeft)
|
|
|
|
|
return origin_status[port].trigger_left;
|
|
|
|
|
if (padaxis == PadAxes::TriggerRight)
|
|
|
|
|
return origin_status[port].trigger_right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int Adapter::GetOriginValue(int port, int axis) const {
|
|
|
|
|
const PadAxes padaxis = static_cast<PadAxes>(axis);
|
|
|
|
|
if (padaxis == PadAxes::StickX)
|
|
|
|
|
return origin_status[port].stick_x;
|
|
|
|
|
if (padaxis == PadAxes::StickY)
|
|
|
|
|
return origin_status[port].stick_y;
|
|
|
|
|
if (padaxis == PadAxes::SubstickX)
|
|
|
|
|
return origin_status[port].substick_x;
|
|
|
|
|
if (padaxis == PadAxes::SubstickY)
|
|
|
|
|
return origin_status[port].substick_x;
|
|
|
|
|
if (padaxis == PadAxes::TriggerLeft)
|
|
|
|
|
return origin_status[port].trigger_left;
|
|
|
|
|
if (padaxis == PadAxes::TriggerRight)
|
|
|
|
|
return origin_status[port].trigger_right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace GCAdapter
|
|
|
|
|