mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
Clang Formatting
This commit is contained in:
parent
0076a08d04
commit
c94583d867
9 changed files with 184 additions and 182 deletions
|
@ -44,7 +44,7 @@ static Controller_NPad::NPadControllerType MapSettingsTypeToNPad(Settings::Contr
|
||||||
case Settings::ControllerType::RightJoycon:
|
case Settings::ControllerType::RightJoycon:
|
||||||
return Controller_NPad::NPadControllerType::JoyRight;
|
return Controller_NPad::NPadControllerType::JoyRight;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return Controller_NPad::NPadControllerType::JoyDual;
|
return Controller_NPad::NPadControllerType::JoyDual;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,7 @@ u32 Controller_NPad::IndexToNPad(std::size_t index) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller_NPad::Controller_NPad(Core::System& system)
|
Controller_NPad::Controller_NPad(Core::System& system) : ControllerBase(system), system(system) {}
|
||||||
: ControllerBase(system), system(system) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller_NPad::~Controller_NPad() = default;
|
Controller_NPad::~Controller_NPad() = default;
|
||||||
|
|
||||||
void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
|
void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
|
||||||
|
@ -109,7 +106,7 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
|
||||||
controller.device_type.raw = 0;
|
controller.device_type.raw = 0;
|
||||||
switch (controller_type) {
|
switch (controller_type) {
|
||||||
case NPadControllerType::None:
|
case NPadControllerType::None:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
case NPadControllerType::Handheld:
|
case NPadControllerType::Handheld:
|
||||||
controller.joy_styles.handheld.Assign(1);
|
controller.joy_styles.handheld.Assign(1);
|
||||||
|
@ -197,8 +194,7 @@ void Controller_NPad::OnInit() {
|
||||||
|
|
||||||
std::transform(
|
std::transform(
|
||||||
Settings::values.players.begin(), Settings::values.players.end(),
|
Settings::values.players.begin(), Settings::values.players.end(),
|
||||||
connected_controllers.begin(), [](const Settings::PlayerInput& player)
|
connected_controllers.begin(), [](const Settings::PlayerInput& player) {
|
||||||
{
|
|
||||||
return ControllerHolder{MapSettingsTypeToNPad(player.type), player.connected};
|
return ControllerHolder{MapSettingsTypeToNPad(player.type), player.connected};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -242,8 +238,7 @@ void Controller_NPad::OnLoadInputDevices() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller_NPad::OnRelease() {
|
void Controller_NPad::OnRelease() {}
|
||||||
}
|
|
||||||
|
|
||||||
void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
|
void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
|
||||||
const auto controller_idx = NPadIdToIndex(npad_id);
|
const auto controller_idx = NPadIdToIndex(npad_id);
|
||||||
|
@ -281,31 +276,27 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
|
||||||
pad_state.d_down.Assign(button_state[DDown - BUTTON_HID_BEGIN]->GetStatus());
|
pad_state.d_down.Assign(button_state[DDown - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
pad_state.l_stick_right.Assign(
|
pad_state.l_stick_right.Assign(
|
||||||
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->
|
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
|
||||||
GetAnalogDirectionStatus(
|
|
||||||
Input::AnalogDirection::RIGHT));
|
Input::AnalogDirection::RIGHT));
|
||||||
pad_state.l_stick_left.Assign(
|
pad_state.l_stick_left.Assign(
|
||||||
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->
|
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
|
||||||
GetAnalogDirectionStatus(
|
|
||||||
Input::AnalogDirection::LEFT));
|
Input::AnalogDirection::LEFT));
|
||||||
pad_state.l_stick_up.Assign(
|
pad_state.l_stick_up.Assign(
|
||||||
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->
|
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
|
||||||
GetAnalogDirectionStatus(
|
|
||||||
Input::AnalogDirection::UP));
|
Input::AnalogDirection::UP));
|
||||||
pad_state.l_stick_down.Assign(
|
pad_state.l_stick_down.Assign(
|
||||||
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->
|
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
|
||||||
GetAnalogDirectionStatus(
|
|
||||||
Input::AnalogDirection::DOWN));
|
Input::AnalogDirection::DOWN));
|
||||||
|
|
||||||
pad_state.r_stick_right.Assign(
|
pad_state.r_stick_right.Assign(
|
||||||
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
||||||
->GetAnalogDirectionStatus(Input::AnalogDirection::RIGHT));
|
->GetAnalogDirectionStatus(Input::AnalogDirection::RIGHT));
|
||||||
pad_state.r_stick_left.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
pad_state.r_stick_left.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
||||||
->GetAnalogDirectionStatus(Input::AnalogDirection::LEFT));
|
->GetAnalogDirectionStatus(Input::AnalogDirection::LEFT));
|
||||||
pad_state.r_stick_up.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
pad_state.r_stick_up.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
||||||
->GetAnalogDirectionStatus(Input::AnalogDirection::UP));
|
->GetAnalogDirectionStatus(Input::AnalogDirection::UP));
|
||||||
pad_state.r_stick_down.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
pad_state.r_stick_down.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
|
||||||
->GetAnalogDirectionStatus(Input::AnalogDirection::DOWN));
|
->GetAnalogDirectionStatus(Input::AnalogDirection::DOWN));
|
||||||
|
|
||||||
pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus());
|
pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus());
|
pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
@ -372,7 +363,7 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
|
||||||
|
|
||||||
switch (controller_type) {
|
switch (controller_type) {
|
||||||
case NPadControllerType::None:
|
case NPadControllerType::None:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
break;
|
break;
|
||||||
case NPadControllerType::Handheld:
|
case NPadControllerType::Handheld:
|
||||||
handheld_entry.connection_status.raw = 0;
|
handheld_entry.connection_status.raw = 0;
|
||||||
|
@ -468,9 +459,8 @@ void Controller_NPad::SetSupportedNPadIdTypes(u8* data, std::size_t length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto requested_controller =
|
const auto requested_controller =
|
||||||
i <= MAX_NPAD_ID
|
i <= MAX_NPAD_ID ? MapSettingsTypeToNPad(Settings::values.players[i].type)
|
||||||
? MapSettingsTypeToNPad(Settings::values.players[i].type)
|
: NPadControllerType::Handheld;
|
||||||
: NPadControllerType::Handheld;
|
|
||||||
if (!IsControllerSupported(requested_controller)) {
|
if (!IsControllerSupported(requested_controller)) {
|
||||||
const auto is_handheld = requested_controller == NPadControllerType::Handheld;
|
const auto is_handheld = requested_controller == NPadControllerType::Handheld;
|
||||||
if (is_handheld) {
|
if (is_handheld) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2014 Dolphin Emulator Project
|
// Copyright 2014 Dolphin Emulator Project
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
//*
|
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/threadsafe_queue.h"
|
#include "common/threadsafe_queue.h"
|
||||||
#include "input_common/gcadapter/gc_adapter.h"
|
#include "input_common/gcadapter/gc_adapter.h"
|
||||||
|
@ -45,35 +45,48 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) {
|
||||||
u8 b1 = adapter_payload[1 + (9 * port) + 1];
|
u8 b1 = adapter_payload[1 + (9 * port) + 1];
|
||||||
u8 b2 = adapter_payload[1 + (9 * port) + 2];
|
u8 b2 = adapter_payload[1 + (9 * port) + 2];
|
||||||
|
|
||||||
if (b1 & (1 << 0))
|
if (b1 & (1 << 0)) {
|
||||||
pad.button |= PAD_BUTTON_A;
|
pad.button |= PAD_BUTTON_A;
|
||||||
if (b1 & (1 << 1))
|
}
|
||||||
|
if (b1 & (1 << 1)) {
|
||||||
pad.button |= PAD_BUTTON_B;
|
pad.button |= PAD_BUTTON_B;
|
||||||
if (b1 & (1 << 2))
|
}
|
||||||
|
if (b1 & (1 << 2)) {
|
||||||
pad.button |= PAD_BUTTON_X;
|
pad.button |= PAD_BUTTON_X;
|
||||||
if (b1 & (1 << 3))
|
}
|
||||||
|
if (b1 & (1 << 3)) {
|
||||||
pad.button |= PAD_BUTTON_Y;
|
pad.button |= PAD_BUTTON_Y;
|
||||||
|
}
|
||||||
|
|
||||||
if (b1 & (1 << 4))
|
if (b1 & (1 << 4)) {
|
||||||
pad.button |= PAD_BUTTON_LEFT;
|
pad.button |= PAD_BUTTON_LEFT;
|
||||||
if (b1 & (1 << 5))
|
}
|
||||||
|
if (b1 & (1 << 5)) {
|
||||||
pad.button |= PAD_BUTTON_RIGHT;
|
pad.button |= PAD_BUTTON_RIGHT;
|
||||||
if (b1 & (1 << 6))
|
}
|
||||||
|
if (b1 & (1 << 6)) {
|
||||||
pad.button |= PAD_BUTTON_DOWN;
|
pad.button |= PAD_BUTTON_DOWN;
|
||||||
if (b1 & (1 << 7))
|
}
|
||||||
|
if (b1 & (1 << 7)) {
|
||||||
pad.button |= PAD_BUTTON_UP;
|
pad.button |= PAD_BUTTON_UP;
|
||||||
|
}
|
||||||
|
|
||||||
if (b2 & (1 << 0))
|
if (b2 & (1 << 0)) {
|
||||||
pad.button |= PAD_BUTTON_START;
|
pad.button |= PAD_BUTTON_START;
|
||||||
if (b2 & (1 << 1))
|
}
|
||||||
|
if (b2 & (1 << 1)) {
|
||||||
pad.button |= PAD_TRIGGER_Z;
|
pad.button |= PAD_TRIGGER_Z;
|
||||||
if (b2 & (1 << 2))
|
}
|
||||||
|
if (b2 & (1 << 2)) {
|
||||||
pad.button |= PAD_TRIGGER_R;
|
pad.button |= PAD_TRIGGER_R;
|
||||||
if (b2 & (1 << 3))
|
}
|
||||||
|
if (b2 & (1 << 3)) {
|
||||||
pad.button |= PAD_TRIGGER_L;
|
pad.button |= PAD_TRIGGER_L;
|
||||||
|
}
|
||||||
|
|
||||||
if (get_origin)
|
if (get_origin) {
|
||||||
pad.button |= PAD_GET_ORIGIN;
|
pad.button |= PAD_GET_ORIGIN;
|
||||||
|
}
|
||||||
|
|
||||||
pad.stickX = adapter_payload[1 + (9 * port) + 3];
|
pad.stickX = adapter_payload[1 + (9 * port) + 3];
|
||||||
pad.stickY = adapter_payload[1 + (9 * port) + 4];
|
pad.stickY = adapter_payload[1 + (9 * port) + 4];
|
||||||
|
@ -86,7 +99,7 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PadToState(GCPadStatus pad, GCState& state) {
|
void PadToState(GCPadStatus pad, GCState& state) {
|
||||||
//std::lock_guard lock{s_mutex};
|
// std::lock_guard lock{s_mutex};
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A);
|
state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A);
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B);
|
state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B);
|
||||||
state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X);
|
state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X);
|
||||||
|
@ -125,7 +138,7 @@ static void Read() {
|
||||||
std::begin(controller_payload_copy));
|
std::begin(controller_payload_copy));
|
||||||
payload_size = payload_size_in;
|
payload_size = payload_size_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
GCPadStatus pad[4];
|
GCPadStatus pad[4];
|
||||||
if (payload_size != sizeof(controller_payload_copy) ||
|
if (payload_size != sizeof(controller_payload_copy) ||
|
||||||
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
||||||
|
@ -137,8 +150,9 @@ static void Read() {
|
||||||
}
|
}
|
||||||
for (int port = 0; port < 4; port++) {
|
for (int port = 0; port < 4; port++) {
|
||||||
if (DeviceConnected(port) && configuring) {
|
if (DeviceConnected(port) && configuring) {
|
||||||
if (pad[port].button != PAD_GET_ORIGIN)
|
if (pad[port].button != PAD_GET_ORIGIN) {
|
||||||
pad_queue[port].Push(pad[port]);
|
pad_queue[port].Push(pad[port]);
|
||||||
|
}
|
||||||
|
|
||||||
// Accounting for a threshold here because of some controller variance
|
// Accounting for a threshold here because of some controller variance
|
||||||
if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD ||
|
if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD ||
|
||||||
|
@ -186,8 +200,9 @@ static void ScanThreadFunc() {
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
|
|
||||||
if (usb_adapter_handle != nullptr)
|
if (usb_adapter_handle != nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
LOG_INFO(Input, "GC Adapter Initialization started");
|
LOG_INFO(Input, "GC Adapter Initialization started");
|
||||||
|
|
||||||
current_status = NO_ADAPTER_DETECTED;
|
current_status = NO_ADAPTER_DETECTED;
|
||||||
|
@ -197,10 +212,12 @@ void Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartScanThread() {
|
void StartScanThread() {
|
||||||
if (detect_thread_running)
|
if (detect_thread_running) {
|
||||||
return;
|
return;
|
||||||
if (!libusb_ctx)
|
}
|
||||||
|
if (!libusb_ctx) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
detect_thread_running = true;
|
detect_thread_running = true;
|
||||||
detect_thread = std::thread(ScanThreadFunc);
|
detect_thread = std::thread(ScanThreadFunc);
|
||||||
|
@ -212,15 +229,17 @@ void StopScanThread() {
|
||||||
|
|
||||||
static void Setup() {
|
static void Setup() {
|
||||||
// Reset the error status in case the adapter gets unplugged
|
// Reset the error status in case the adapter gets unplugged
|
||||||
if (current_status < 0)
|
if (current_status < 0) {
|
||||||
current_status = NO_ADAPTER_DETECTED;
|
current_status = NO_ADAPTER_DETECTED;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++) {
|
||||||
adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE;
|
adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
libusb_device** devs; // pointer to list of connected usb devices
|
libusb_device** devs; // pointer to list of connected usb devices
|
||||||
|
|
||||||
int cnt = libusb_get_device_list(libusb_ctx, &devs); //get the list of devices
|
int cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices
|
||||||
|
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
if (CheckDeviceAccess(devs[i])) {
|
if (CheckDeviceAccess(devs[i])) {
|
||||||
|
@ -247,9 +266,8 @@ static bool CheckDeviceAccess(libusb_device* device) {
|
||||||
ret = libusb_open(device, &usb_adapter_handle);
|
ret = libusb_open(device, &usb_adapter_handle);
|
||||||
|
|
||||||
if (ret == LIBUSB_ERROR_ACCESS) {
|
if (ret == LIBUSB_ERROR_ACCESS) {
|
||||||
LOG_ERROR(Input,
|
LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor,
|
||||||
"Yuzu can not gain access to this device: ID %04X:%04X.",
|
desc.idProduct);
|
||||||
desc.idVendor, desc.idProduct);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -260,8 +278,9 @@ static bool CheckDeviceAccess(libusb_device* device) {
|
||||||
ret = libusb_kernel_driver_active(usb_adapter_handle, 0);
|
ret = libusb_kernel_driver_active(usb_adapter_handle, 0);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
ret = libusb_detach_kernel_driver(usb_adapter_handle, 0);
|
ret = libusb_detach_kernel_driver(usb_adapter_handle, 0);
|
||||||
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED)
|
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) {
|
||||||
LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret);
|
LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) {
|
if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) {
|
||||||
|
@ -290,8 +309,9 @@ static void GetGCEndpoint(libusb_device* device) {
|
||||||
const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i];
|
const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i];
|
||||||
for (u8 e = 0; e < interface->bNumEndpoints; e++) {
|
for (u8 e = 0; e < interface->bNumEndpoints; e++) {
|
||||||
const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e];
|
const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e];
|
||||||
if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN)
|
if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) {
|
||||||
input_endpoint = endpoint->bEndpointAddress;
|
input_endpoint = endpoint->bEndpointAddress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,16 +331,20 @@ void Shutdown() {
|
||||||
|
|
||||||
static void Reset() {
|
static void Reset() {
|
||||||
std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock);
|
std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock);
|
||||||
if (!lock.try_lock())
|
if (!lock.try_lock()) {
|
||||||
return;
|
return;
|
||||||
if (current_status != ADAPTER_DETECTED)
|
}
|
||||||
|
if (current_status != ADAPTER_DETECTED) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (adapter_thread_running)
|
if (adapter_thread_running) {
|
||||||
adapter_input_thread.join();
|
adapter_input_thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++) {
|
||||||
adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE;
|
adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
current_status = NO_ADAPTER_DETECTED;
|
current_status = NO_ADAPTER_DETECTED;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
// Copyright 2014 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <libusb.h>
|
|
||||||
#include <mutex>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <libusb.h>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PAD_USE_ORIGIN = 0x0080,
|
PAD_USE_ORIGIN = 0x0080,
|
||||||
PAD_GET_ORIGIN = 0x2000,
|
PAD_GET_ORIGIN = 0x2000,
|
||||||
|
@ -61,13 +64,8 @@ struct GCState {
|
||||||
std::unordered_map<int, u16> axes;
|
std::unordered_map<int, u16> axes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace GCAdapter {
|
namespace GCAdapter {
|
||||||
enum ControllerTypes {
|
enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 };
|
||||||
CONTROLLER_NONE = 0,
|
|
||||||
CONTROLLER_WIRED = 1,
|
|
||||||
CONTROLLER_WIRELESS = 2
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NO_ADAPTER_DETECTED = 0,
|
NO_ADAPTER_DETECTED = 0,
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "input_common/gcadapter/gc_poller.h"
|
|
||||||
#include "input_common/gcadapter/gc_adapter.h"
|
|
||||||
#include "common/threadsafe_queue.h"
|
#include "common/threadsafe_queue.h"
|
||||||
|
#include "input_common/gcadapter/gc_adapter.h"
|
||||||
|
#include "input_common/gcadapter/gc_poller.h"
|
||||||
|
|
||||||
// Using extern as to avoid multply defined symbols.
|
// Using extern as to avoid multply defined symbols.
|
||||||
extern Common::SPSCQueue<GCPadStatus> pad_queue[4];
|
extern Common::SPSCQueue<GCPadStatus> pad_queue[4];
|
||||||
|
@ -14,9 +18,7 @@ namespace InputCommon {
|
||||||
|
|
||||||
class GCButton final : public Input::ButtonDevice {
|
class GCButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit GCButton(int port_, int button_, int axis_)
|
explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {}
|
||||||
: port(port_), button(button_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~GCButton() override;
|
~GCButton() override;
|
||||||
|
|
||||||
|
@ -31,17 +33,14 @@ private:
|
||||||
|
|
||||||
class GCAxisButton final : public Input::ButtonDevice {
|
class GCAxisButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit GCAxisButton(int port_, int axis_, float threshold_,
|
explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_)
|
||||||
bool trigger_if_greater_)
|
: port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) {
|
||||||
: port(port_), axis(axis_), threshold(threshold_),
|
|
||||||
trigger_if_greater(trigger_if_greater_) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f;
|
const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f;
|
||||||
if (trigger_if_greater) {
|
if (trigger_if_greater) {
|
||||||
return axis_value > 0.10f; //TODO(ameerj) : Fix threshold.
|
return axis_value > 0.10f; // TODO(ameerj) : Fix threshold.
|
||||||
}
|
}
|
||||||
return axis_value < -0.10f;
|
return axis_value < -0.10f;
|
||||||
}
|
}
|
||||||
|
@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
|
||||||
|
|
||||||
void GCButtonFactory::BeginConfiguration() {
|
void GCButtonFactory::BeginConfiguration() {
|
||||||
polling = true;
|
polling = true;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++) {
|
||||||
pad_queue[i].Clear();
|
pad_queue[i].Clear();
|
||||||
|
}
|
||||||
GCAdapter::BeginConfiguration();
|
GCAdapter::BeginConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCButtonFactory::EndConfiguration() {
|
void GCButtonFactory::EndConfiguration() {
|
||||||
polling = false;
|
polling = false;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
pad_queue[i].Clear();
|
pad_queue[i].Clear();
|
||||||
|
}
|
||||||
GCAdapter::EndConfiguration();
|
GCAdapter::EndConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
class GCAnalog final : public Input::AnalogDevice {
|
class GCAnalog final : public Input::AnalogDevice {
|
||||||
public:
|
public:
|
||||||
GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_)
|
GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_)
|
||||||
: port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {
|
: port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {}
|
||||||
}
|
|
||||||
|
|
||||||
float GetAxis(int axis) const {
|
float GetAxis(int axis) const {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
// division is not by a perfect 128 to account for some variance in center location
|
// division is not by a perfect 128 to account for some variance in center location
|
||||||
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230]
|
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
|
||||||
|
// [20-230]
|
||||||
return (state[port].axes.at(axis) - 128.0f) / 95.0f;
|
return (state[port].axes.at(axis) - 128.0f) / 95.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,18 +240,16 @@ private:
|
||||||
mutable std::mutex mutex;
|
mutable std::mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// An analog device factory that creates analog devices from GC Adapter
|
/// An analog device factory that creates analog devices from GC Adapter
|
||||||
GCAnalogFactory::GCAnalogFactory() {};
|
GCAnalogFactory::GCAnalogFactory(){};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates analog device from joystick axes
|
* Creates analog device from joystick axes
|
||||||
* @param params contains parameters for creating the device:
|
* @param params contains parameters for creating the device:
|
||||||
* - "port": the nth gcpad on the adapter
|
* - "port": the nth gcpad on the adapter
|
||||||
* - "axis_x": the index of the axis to be bind as x-axis
|
* - "axis_x": the index of the axis to be bind as x-axis
|
||||||
* - "axis_y": the index of the axis to be bind as y-axis
|
* - "axis_y": the index of the axis to be bind as y-axis
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) {
|
std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) {
|
||||||
const std::string guid = params.Get("guid", "0");
|
const std::string guid = params.Get("guid", "0");
|
||||||
const int port = params.Get("port", 0);
|
const int port = params.Get("port", 0);
|
||||||
|
@ -264,15 +262,17 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param
|
||||||
|
|
||||||
void GCAnalogFactory::BeginConfiguration() {
|
void GCAnalogFactory::BeginConfiguration() {
|
||||||
polling = true;
|
polling = true;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++) {
|
||||||
pad_queue[i].Clear();
|
pad_queue[i].Clear();
|
||||||
|
}
|
||||||
GCAdapter::BeginConfiguration();
|
GCAdapter::BeginConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCAnalogFactory::EndConfiguration() {
|
void GCAnalogFactory::EndConfiguration() {
|
||||||
polling = false;
|
polling = false;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++) {
|
||||||
pad_queue[i].Clear();
|
pad_queue[i].Clear();
|
||||||
|
}
|
||||||
GCAdapter::EndConfiguration();
|
GCAdapter::EndConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -5,7 +9,6 @@
|
||||||
|
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A button device factory representing a gcpad. It receives gcpad events and forward them
|
* A button device factory representing a gcpad. It receives gcpad events and forward them
|
||||||
* to all button devices it created.
|
* to all button devices it created.
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "input_common/gcadapter/gc_poller.h"
|
|
||||||
#include "input_common/gcadapter/gc_adapter.h"
|
#include "input_common/gcadapter/gc_adapter.h"
|
||||||
|
#include "input_common/gcadapter/gc_poller.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
class ParamPackage;
|
class ParamPackage;
|
||||||
|
@ -38,7 +38,6 @@ class GCAnalogFactory;
|
||||||
GCButtonFactory* GetGCButtons();
|
GCButtonFactory* GetGCButtons();
|
||||||
GCAnalogFactory* GetGCAnalogs();
|
GCAnalogFactory* GetGCAnalogs();
|
||||||
|
|
||||||
|
|
||||||
/// Generates a serialized param package for creating a keyboard button device
|
/// Generates a serialized param package for creating a keyboard button device
|
||||||
std::string GenerateKeyboardParam(int key_code);
|
std::string GenerateKeyboardParam(int key_code);
|
||||||
|
|
||||||
|
|
|
@ -225,8 +225,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie
|
||||||
} else {
|
} else {
|
||||||
failure_callback();
|
failure_callback();
|
||||||
}
|
}
|
||||||
})
|
}).detach();
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationConfigurationJob::CalibrationConfigurationJob(
|
CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
|
@ -280,8 +279,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
complete_event.Wait();
|
complete_event.Wait();
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
worker_thread.join();
|
worker_thread.join();
|
||||||
})
|
}).detach();
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalibrationConfigurationJob::~CalibrationConfigurationJob() {
|
CalibrationConfigurationJob::~CalibrationConfigurationJob() {
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
#include "yuzu/configuration/configure_input_player.h"
|
#include "yuzu/configuration/configure_input_player.h"
|
||||||
|
|
||||||
const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM>
|
const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM>
|
||||||
ConfigureInputPlayer::analog_sub_buttons{{
|
ConfigureInputPlayer::analog_sub_buttons{{
|
||||||
"up",
|
"up",
|
||||||
"down",
|
"down",
|
||||||
"left",
|
"left",
|
||||||
"right",
|
"right",
|
||||||
"modifier",
|
"modifier",
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) {
|
static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) {
|
||||||
const int index1 = grid->indexOf(item);
|
const int index1 = grid->indexOf(item);
|
||||||
|
@ -151,13 +151,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
setFocusPolicy(Qt::ClickFocus);
|
setFocusPolicy(Qt::ClickFocus);
|
||||||
|
|
||||||
button_map = {
|
button_map = {
|
||||||
ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY,
|
ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY,
|
||||||
ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR,
|
ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR,
|
||||||
ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus,
|
ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus,
|
||||||
ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown,
|
ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown,
|
||||||
ui->buttonLStickLeft, ui->buttonLStickUp, ui->buttonLStickRight, ui->buttonLStickDown,
|
ui->buttonLStickLeft, ui->buttonLStickUp, ui->buttonLStickRight, ui->buttonLStickDown,
|
||||||
ui->buttonRStickLeft, ui->buttonRStickUp, ui->buttonRStickRight, ui->buttonRStickDown,
|
ui->buttonRStickLeft, ui->buttonRStickUp, ui->buttonRStickRight, ui->buttonRStickDown,
|
||||||
ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
|
ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot,
|
||||||
};
|
};
|
||||||
|
|
||||||
analog_map_buttons = {{
|
analog_map_buttons = {{
|
||||||
|
@ -178,11 +178,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
}};
|
}};
|
||||||
|
|
||||||
debug_hidden = {
|
debug_hidden = {
|
||||||
ui->buttonSL, ui->labelSL,
|
ui->buttonSL, ui->labelSL,
|
||||||
ui->buttonSR, ui->labelSR,
|
ui->buttonSR, ui->labelSR,
|
||||||
ui->buttonLStick, ui->labelLStickPressed,
|
ui->buttonLStick, ui->labelLStickPressed,
|
||||||
ui->buttonRStick, ui->labelRStickPressed,
|
ui->buttonRStick, ui->labelRStickPressed,
|
||||||
ui->buttonHome, ui->labelHome,
|
ui->buttonHome, ui->labelHome,
|
||||||
ui->buttonScreenshot, ui->labelScreenshot,
|
ui->buttonScreenshot, ui->labelScreenshot,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -221,12 +221,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
case Settings::ControllerType::RightJoycon:
|
case Settings::ControllerType::RightJoycon:
|
||||||
layout_hidden = {
|
layout_hidden = {
|
||||||
ui->left_body_button, ui->left_buttons_button,
|
ui->left_body_button, ui->left_buttons_button,
|
||||||
ui->left_body_label, ui->left_buttons_label,
|
ui->left_body_label, ui->left_buttons_label,
|
||||||
ui->buttonL, ui->labelL,
|
ui->buttonL, ui->labelL,
|
||||||
ui->buttonZL, ui->labelZL,
|
ui->buttonZL, ui->labelZL,
|
||||||
ui->labelScreenshot, ui->buttonScreenshot,
|
ui->labelScreenshot, ui->buttonScreenshot,
|
||||||
ui->buttonMinus, ui->labelMinus,
|
ui->buttonMinus, ui->labelMinus,
|
||||||
ui->LStick, ui->Dpad,
|
ui->LStick, ui->Dpad,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -261,38 +261,34 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
}
|
}
|
||||||
|
|
||||||
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(button, &QPushButton::clicked, [=]
|
connect(button, &QPushButton::clicked, [=] {
|
||||||
{
|
HandleClick(
|
||||||
HandleClick(button_map[button_id],
|
button_map[button_id],
|
||||||
[=](Common::ParamPackage params)
|
[=](Common::ParamPackage params) {
|
||||||
{
|
// Workaround for ZL & ZR for analog triggers like on XBOX controllors.
|
||||||
// Workaround for ZL & ZR for analog triggers like on XBOX controllors.
|
// Analog triggers (from controllers like the XBOX controller) would not
|
||||||
// Analog triggers (from controllers like the XBOX controller) would not
|
// work due to a different range of their signals (from 0 to 255 on
|
||||||
// work due to a different range of their signals (from 0 to 255 on
|
// analog triggers instead of -32768 to 32768 on analog joysticks). The
|
||||||
// analog triggers instead of -32768 to 32768 on analog joysticks). The
|
// SDL driver misinterprets analog triggers as analog joysticks.
|
||||||
// SDL driver misinterprets analog triggers as analog joysticks.
|
// TODO: reinterpret the signal range for analog triggers to map the
|
||||||
// TODO: reinterpret the signal range for analog triggers to map the
|
// values correctly. This is required for the correct emulation of the
|
||||||
// values correctly. This is required for the correct emulation of the
|
// analog triggers of the GameCube controller.
|
||||||
// analog triggers of the GameCube controller.
|
if (button_id == Settings::NativeButton::ZL ||
|
||||||
if (button_id == Settings::NativeButton::ZL ||
|
button_id == Settings::NativeButton::ZR) {
|
||||||
button_id == Settings::NativeButton::ZR) {
|
params.Set("direction", "+");
|
||||||
params.Set("direction", "+");
|
params.Set("threshold", "0.5");
|
||||||
params.Set("threshold", "0.5");
|
}
|
||||||
}
|
buttons_param[button_id] = std::move(params);
|
||||||
buttons_param[button_id] = std::move(params);
|
},
|
||||||
},
|
InputCommon::Polling::DeviceType::Button);
|
||||||
InputCommon::Polling::DeviceType::Button);
|
|
||||||
});
|
});
|
||||||
connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location)
|
connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
|
||||||
{
|
|
||||||
QMenu context_menu;
|
QMenu context_menu;
|
||||||
context_menu.addAction(tr("Clear"), [&]
|
context_menu.addAction(tr("Clear"), [&] {
|
||||||
{
|
|
||||||
buttons_param[button_id].Clear();
|
buttons_param[button_id].Clear();
|
||||||
button_map[button_id]->setText(tr("[not set]"));
|
button_map[button_id]->setText(tr("[not set]"));
|
||||||
});
|
});
|
||||||
context_menu.addAction(tr("Restore Default"), [&]
|
context_menu.addAction(tr("Restore Default"), [&] {
|
||||||
{
|
|
||||||
buttons_param[button_id] = Common::ParamPackage{
|
buttons_param[button_id] = Common::ParamPackage{
|
||||||
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
|
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
|
||||||
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
|
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
|
||||||
|
@ -309,27 +305,23 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
}
|
}
|
||||||
|
|
||||||
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
|
analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(analog_button, &QPushButton::clicked, [=]()
|
connect(analog_button, &QPushButton::clicked, [=]() {
|
||||||
{
|
HandleClick(
|
||||||
HandleClick(analog_map_buttons[analog_id][sub_button_id],
|
analog_map_buttons[analog_id][sub_button_id],
|
||||||
[=](const Common::ParamPackage& params)
|
[=](const Common::ParamPackage& params) {
|
||||||
{
|
SetAnalogButton(params, analogs_param[analog_id],
|
||||||
SetAnalogButton(params, analogs_param[analog_id],
|
analog_sub_buttons[sub_button_id]);
|
||||||
analog_sub_buttons[sub_button_id]);
|
},
|
||||||
},
|
InputCommon::Polling::DeviceType::Button);
|
||||||
InputCommon::Polling::DeviceType::Button);
|
|
||||||
});
|
});
|
||||||
connect(analog_button, &QPushButton::customContextMenuRequested,
|
connect(analog_button, &QPushButton::customContextMenuRequested,
|
||||||
[=](const QPoint& menu_location)
|
[=](const QPoint& menu_location) {
|
||||||
{
|
|
||||||
QMenu context_menu;
|
QMenu context_menu;
|
||||||
context_menu.addAction(tr("Clear"), [&]
|
context_menu.addAction(tr("Clear"), [&] {
|
||||||
{
|
|
||||||
analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
|
analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
|
||||||
analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
|
analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
|
||||||
});
|
});
|
||||||
context_menu.addAction(tr("Restore Default"), [&]
|
context_menu.addAction(tr("Restore Default"), [&] {
|
||||||
{
|
|
||||||
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
|
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
|
||||||
Config::default_analogs[analog_id][sub_button_id])};
|
Config::default_analogs[analog_id][sub_button_id])};
|
||||||
SetAnalogButton(params, analogs_param[analog_id],
|
SetAnalogButton(params, analogs_param[analog_id],
|
||||||
|
@ -341,12 +333,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
menu_location));
|
menu_location));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
connect(analog_map_stick[analog_id], &QPushButton::clicked, [=]
|
connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] {
|
||||||
{
|
|
||||||
if (QMessageBox::information(
|
if (QMessageBox::information(
|
||||||
this, tr("Information"),
|
this, tr("Information"),
|
||||||
tr("After pressing OK, first move your joystick horizontally, "
|
tr("After pressing OK, first move your joystick horizontally, "
|
||||||
"and then vertically."),
|
"and then vertically."),
|
||||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
||||||
HandleClick(
|
HandleClick(
|
||||||
analog_map_stick[analog_id],
|
analog_map_stick[analog_id],
|
||||||
|
@ -355,8 +346,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=]
|
connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] {
|
||||||
{
|
|
||||||
const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value();
|
const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value();
|
||||||
if (analogs_param[analog_id].Get("engine", "") == "sdl" ||
|
if (analogs_param[analog_id].Get("engine", "") == "sdl" ||
|
||||||
analogs_param[analog_id].Get("engine", "") == "gcpad") {
|
analogs_param[analog_id].Get("engine", "") == "gcpad") {
|
||||||
|
@ -377,8 +367,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
timeout_timer->setSingleShot(true);
|
timeout_timer->setSingleShot(true);
|
||||||
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
|
connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); });
|
||||||
|
|
||||||
connect(poll_timer.get(), &QTimer::timeout, [this]
|
connect(poll_timer.get(), &QTimer::timeout, [this] {
|
||||||
{
|
|
||||||
Common::ParamPackage params;
|
Common::ParamPackage params;
|
||||||
if (InputCommon::GetGCButtons()->IsPolling()) {
|
if (InputCommon::GetGCButtons()->IsPolling()) {
|
||||||
params = InputCommon::GetGCButtons()->GetNextInput();
|
params = InputCommon::GetGCButtons()->GetNextInput();
|
||||||
|
@ -505,7 +494,7 @@ void ConfigureInputPlayer::LoadConfiguration() {
|
||||||
for (std::size_t i = 0; i < colors.size(); ++i) {
|
for (std::size_t i = 0; i < colors.size(); ++i) {
|
||||||
controller_color_buttons[i]->setStyleSheet(
|
controller_color_buttons[i]->setStyleSheet(
|
||||||
QStringLiteral("QPushButton { background-color: %1 }")
|
QStringLiteral("QPushButton { background-color: %1 }")
|
||||||
.arg(controller_colors[i].name()));
|
.arg(controller_colors[i].name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,10 +614,11 @@ void ConfigureInputPlayer::HandleClick(
|
||||||
|
|
||||||
grabKeyboard();
|
grabKeyboard();
|
||||||
grabMouse();
|
grabMouse();
|
||||||
if (type == InputCommon::Polling::DeviceType::Button)
|
if (type == InputCommon::Polling::DeviceType::Button) {
|
||||||
InputCommon::GetGCButtons()->BeginConfiguration();
|
InputCommon::GetGCButtons()->BeginConfiguration();
|
||||||
else
|
} else {
|
||||||
InputCommon::GetGCAnalogs()->BeginConfiguration();
|
InputCommon::GetGCAnalogs()->BeginConfiguration();
|
||||||
|
}
|
||||||
timeout_timer->start(5000); // Cancel after 5 seconds
|
timeout_timer->start(5000); // Cancel after 5 seconds
|
||||||
poll_timer->start(200); // Check for new inputs every 200ms
|
poll_timer->start(200); // Check for new inputs every 200ms
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class ConfigureInputPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigureInputPlayer : public QDialog {
|
class ConfigureInputPlayer : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false);
|
explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false);
|
||||||
|
@ -92,15 +92,15 @@ private:
|
||||||
/// A group of five QPushButtons represent one analog input. The buttons each represent up,
|
/// A group of five QPushButtons represent one analog input. The buttons each represent up,
|
||||||
/// down, left, right, and modifier, respectively.
|
/// down, left, right, and modifier, respectively.
|
||||||
std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
|
std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
|
||||||
analog_map_buttons;
|
analog_map_buttons;
|
||||||
|
|
||||||
/// Analog inputs are also represented each with a single button, used to configure with an
|
/// Analog inputs are also represented each with a single button, used to configure with an
|
||||||
/// actual analog stick
|
/// actual analog stick
|
||||||
std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> analog_map_stick;
|
std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> analog_map_stick;
|
||||||
std::array<QSlider*, Settings::NativeAnalog::NumAnalogs>
|
std::array<QSlider*, Settings::NativeAnalog::NumAnalogs>
|
||||||
analog_map_deadzone_and_modifier_slider;
|
analog_map_deadzone_and_modifier_slider;
|
||||||
std::array<QLabel*, Settings::NativeAnalog::NumAnalogs>
|
std::array<QLabel*, Settings::NativeAnalog::NumAnalogs>
|
||||||
analog_map_deadzone_and_modifier_slider_label;
|
analog_map_deadzone_and_modifier_slider_label;
|
||||||
|
|
||||||
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
|
static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue