Clang Formatting
This commit is contained in:
parent
0076a08d04
commit
c94583d867
@ -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) {
|
||||||
@ -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,20 +276,16 @@ 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(
|
||||||
@ -468,8 +459,7 @@ 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;
|
||||||
|
@ -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];
|
||||||
@ -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,11 +229,13 @@ 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
|
||||||
|
|
||||||
@ -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,9 +278,10 @@ 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) {
|
||||||
libusb_close(usb_adapter_handle);
|
libusb_close(usb_adapter_handle);
|
||||||
@ -290,11 +309,12 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
adapter_thread_running = true;
|
adapter_thread_running = true;
|
||||||
current_status = ADAPTER_DETECTED;
|
current_status = ADAPTER_DETECTED;
|
||||||
@ -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,13 +33,10 @@ 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) {
|
||||||
@ -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,11 +240,9 @@ 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:
|
||||||
@ -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() {
|
||||||
|
@ -261,11 +261,10 @@ 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
|
||||||
@ -283,16 +282,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|||||||
},
|
},
|
||||||
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,8 +333,7 @@ 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, "
|
||||||
@ -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();
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user