diff options
author | Ameer <aj662@drexel.edu> | 2020-06-21 21:31:57 +0200 |
---|---|---|
committer | Ameer <aj662@drexel.edu> | 2020-06-21 21:31:57 +0200 |
commit | c94583d867fd909d8731ba50e085352aae0e6885 (patch) | |
tree | 9c691c1382d3317f45ad09cb43a93f9223fe379b /src/input_common | |
parent | Cleanup after linter (diff) | |
download | yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.gz yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.bz2 yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.lz yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.xz yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.zst yuzu-c94583d867fd909d8731ba50e085352aae0e6885.zip |
Diffstat (limited to 'src/input_common')
-rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 90 | ||||
-rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 16 | ||||
-rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 56 | ||||
-rw-r--r-- | src/input_common/gcadapter/gc_poller.h | 5 | ||||
-rw-r--r-- | src/input_common/main.h | 3 | ||||
-rw-r--r-- | src/input_common/udp/client.cpp | 6 |
6 files changed, 99 insertions, 77 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index d42261d61..dc04116ce 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -1,7 +1,7 @@ // Copyright 2014 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -//* + #include "common/logging/log.h" #include "common/threadsafe_queue.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 b2 = adapter_payload[1 + (9 * port) + 2]; - if (b1 & (1 << 0)) + if (b1 & (1 << 0)) { pad.button |= PAD_BUTTON_A; - if (b1 & (1 << 1)) + } + if (b1 & (1 << 1)) { pad.button |= PAD_BUTTON_B; - if (b1 & (1 << 2)) + } + if (b1 & (1 << 2)) { pad.button |= PAD_BUTTON_X; - if (b1 & (1 << 3)) + } + if (b1 & (1 << 3)) { pad.button |= PAD_BUTTON_Y; + } - if (b1 & (1 << 4)) + if (b1 & (1 << 4)) { pad.button |= PAD_BUTTON_LEFT; - if (b1 & (1 << 5)) + } + if (b1 & (1 << 5)) { pad.button |= PAD_BUTTON_RIGHT; - if (b1 & (1 << 6)) + } + if (b1 & (1 << 6)) { pad.button |= PAD_BUTTON_DOWN; - if (b1 & (1 << 7)) + } + if (b1 & (1 << 7)) { pad.button |= PAD_BUTTON_UP; + } - if (b2 & (1 << 0)) + if (b2 & (1 << 0)) { pad.button |= PAD_BUTTON_START; - if (b2 & (1 << 1)) + } + if (b2 & (1 << 1)) { pad.button |= PAD_TRIGGER_Z; - if (b2 & (1 << 2)) + } + if (b2 & (1 << 2)) { pad.button |= PAD_TRIGGER_R; - if (b2 & (1 << 3)) + } + if (b2 & (1 << 3)) { pad.button |= PAD_TRIGGER_L; + } - if (get_origin) + if (get_origin) { pad.button |= PAD_GET_ORIGIN; + } pad.stickX = adapter_payload[1 + (9 * port) + 3]; 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) { - //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_B, pad.button & PAD_BUTTON_B); 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)); payload_size = payload_size_in; } - + GCPadStatus pad[4]; if (payload_size != sizeof(controller_payload_copy) || controller_payload_copy[0] != LIBUSB_DT_HID) { @@ -137,8 +150,9 @@ static void Read() { } for (int port = 0; port < 4; port++) { if (DeviceConnected(port) && configuring) { - if (pad[port].button != PAD_GET_ORIGIN) + if (pad[port].button != PAD_GET_ORIGIN) { pad_queue[port].Push(pad[port]); + } // Accounting for a threshold here because of some controller variance if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || @@ -186,8 +200,9 @@ static void ScanThreadFunc() { void Init() { - if (usb_adapter_handle != nullptr) + if (usb_adapter_handle != nullptr) { return; + } LOG_INFO(Input, "GC Adapter Initialization started"); current_status = NO_ADAPTER_DETECTED; @@ -197,10 +212,12 @@ void Init() { } void StartScanThread() { - if (detect_thread_running) + if (detect_thread_running) { return; - if (!libusb_ctx) + } + if (!libusb_ctx) { return; + } detect_thread_running = true; detect_thread = std::thread(ScanThreadFunc); @@ -212,15 +229,17 @@ void StopScanThread() { static void Setup() { // Reset the error status in case the adapter gets unplugged - if (current_status < 0) + if (current_status < 0) { 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; - + } + 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++) { if (CheckDeviceAccess(devs[i])) { @@ -247,9 +266,8 @@ static bool CheckDeviceAccess(libusb_device* device) { ret = libusb_open(device, &usb_adapter_handle); if (ret == LIBUSB_ERROR_ACCESS) { - LOG_ERROR(Input, - "Yuzu can not gain access to this device: ID %04X:%04X.", - desc.idVendor, desc.idProduct); + LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, + desc.idProduct); return false; } if (ret) { @@ -260,8 +278,9 @@ static bool CheckDeviceAccess(libusb_device* device) { ret = libusb_kernel_driver_active(usb_adapter_handle, 0); if (ret == 1) { 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); + } } 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]; for (u8 e = 0; e < interface->bNumEndpoints; 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; + } } } } @@ -311,16 +331,20 @@ void Shutdown() { static void Reset() { std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock); - if (!lock.try_lock()) + if (!lock.try_lock()) { return; - if (current_status != ADAPTER_DETECTED) + } + if (current_status != ADAPTER_DETECTED) { return; + } - if (adapter_thread_running) + if (adapter_thread_running) { 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; + } current_status = NO_ADAPTER_DETECTED; diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 9b02d1382..05ee73c65 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -1,11 +1,14 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + #pragma once #include <algorithm> -#include <libusb.h> -#include <mutex> #include <functional> +#include <mutex> +#include <libusb.h> #include "common/common_types.h" - enum { PAD_USE_ORIGIN = 0x0080, PAD_GET_ORIGIN = 0x2000, @@ -61,13 +64,8 @@ struct GCState { std::unordered_map<int, u16> axes; }; - namespace GCAdapter { -enum ControllerTypes { - CONTROLLER_NONE = 0, - CONTROLLER_WIRED = 1, - CONTROLLER_WIRELESS = 2 -}; +enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; enum { NO_ADAPTER_DETECTED = 0, diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 772bd8890..51b3362d6 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -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 <list> #include <mutex> #include <utility> -#include "input_common/gcadapter/gc_poller.h" -#include "input_common/gcadapter/gc_adapter.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. extern Common::SPSCQueue<GCPadStatus> pad_queue[4]; @@ -14,9 +18,7 @@ namespace InputCommon { class GCButton final : public Input::ButtonDevice { public: - explicit GCButton(int port_, int button_, int axis_) - : port(port_), button(button_) { - } + explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} ~GCButton() override; @@ -31,17 +33,14 @@ private: class GCAxisButton final : public Input::ButtonDevice { public: - explicit GCAxisButton(int port_, int axis_, float threshold_, - bool trigger_if_greater_) - : port(port_), axis(axis_), threshold(threshold_), - trigger_if_greater(trigger_if_greater_) { + explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) + : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { } - bool GetStatus() const override { const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; 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; } @@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { void GCButtonFactory::BeginConfiguration() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCButtonFactory::EndConfiguration() { polling = false; - - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } class GCAnalog final : public Input::AnalogDevice { public: 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 { std::lock_guard lock{mutex}; // 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; } @@ -240,18 +240,16 @@ private: mutable std::mutex mutex; }; - /// An analog device factory that creates analog devices from GC Adapter -GCAnalogFactory::GCAnalogFactory() {}; - +GCAnalogFactory::GCAnalogFactory(){}; /** -* Creates analog device from joystick axes -* @param params contains parameters for creating the device: -* - "port": the nth gcpad on the adapter -* - "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 -*/ + * Creates analog device from joystick axes + * @param params contains parameters for creating the device: + * - "port": the nth gcpad on the adapter + * - "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 + */ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { const std::string guid = params.Get("guid", "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() { polling = true; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::BeginConfiguration(); } void GCAnalogFactory::EndConfiguration() { polling = false; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { pad_queue[i].Clear(); + } GCAdapter::EndConfiguration(); } diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index d115b1d2a..43aa9e93a 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -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 #include <memory> @@ -5,7 +9,6 @@ namespace InputCommon { - /** * A button device factory representing a gcpad. It receives gcpad events and forward them * to all button devices it created. diff --git a/src/input_common/main.h b/src/input_common/main.h index be2e7a6c4..9e1528c88 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -7,8 +7,8 @@ #include <memory> #include <string> #include <vector> -#include "input_common/gcadapter/gc_poller.h" #include "input_common/gcadapter/gc_adapter.h" +#include "input_common/gcadapter/gc_poller.h" namespace Common { class ParamPackage; @@ -38,7 +38,6 @@ class GCAnalogFactory; GCButtonFactory* GetGCButtons(); GCAnalogFactory* GetGCAnalogs(); - /// Generates a serialized param package for creating a keyboard button device std::string GenerateKeyboardParam(int key_code); diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..4c9794ce2 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -225,8 +225,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie } else { failure_callback(); } - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::CalibrationConfigurationJob( @@ -280,8 +279,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( complete_event.Wait(); socket.Stop(); worker_thread.join(); - }) - .detach(); + }).detach(); } CalibrationConfigurationJob::~CalibrationConfigurationJob() { |