summaryrefslogtreecommitdiffstats
path: root/src/input_common/gcadapter/gc_adapter.h
diff options
context:
space:
mode:
authorFernando S <fsahmkow27@gmail.com>2021-10-23 23:32:16 +0200
committerGitHub <noreply@github.com>2021-10-23 23:32:16 +0200
commit33e92c15ebf3f1cbfb48601108f3eaa70eefe18f (patch)
tree685813e5c402326e30bba9daf6aff9d55cfb8b1a /src/input_common/gcadapter/gc_adapter.h
parentMerge pull request #6515 from german77/gc_thread_safe (diff)
downloadyuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.gz
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.bz2
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.lz
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.xz
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.tar.zst
yuzu-33e92c15ebf3f1cbfb48601108f3eaa70eefe18f.zip
Diffstat (limited to '')
-rw-r--r--src/input_common/gcadapter/gc_adapter.h46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h
index 28dbcbe05..e5de5e94f 100644
--- a/src/input_common/gcadapter/gc_adapter.h
+++ b/src/input_common/gcadapter/gc_adapter.h
@@ -3,14 +3,11 @@
// Refer to the license.txt file included.
#pragma once
-
#include <algorithm>
#include <functional>
#include <mutex>
-#include <stop_token>
#include <thread>
#include <unordered_map>
-
#include "common/common_types.h"
#include "common/threadsafe_queue.h"
#include "input_common/main.h"
@@ -21,9 +18,6 @@ struct libusb_device_handle;
namespace GCAdapter {
-class LibUSBContext;
-class LibUSBDeviceHandle;
-
enum class PadButton {
Undefined = 0x0000,
ButtonLeft = 0x0001,
@@ -69,11 +63,11 @@ struct GCPadStatus {
};
struct GCController {
- ControllerTypes type = ControllerTypes::None;
- bool enable_vibration = false;
- u8 rumble_amplitude = 0;
- u16 buttons = 0;
- PadButton last_button = PadButton::Undefined;
+ ControllerTypes type{};
+ bool enable_vibration{};
+ u8 rumble_amplitude{};
+ u16 buttons{};
+ PadButton last_button{};
std::array<s16, 6> axis_values{};
std::array<u8, 6> axis_origin{};
u8 reset_origin_counter{};
@@ -115,9 +109,9 @@ private:
void UpdateStateAxes(std::size_t port, const AdapterPayload& adapter_payload);
void UpdateVibrations();
- void AdapterInputThread(std::stop_token stop_token);
+ void AdapterInputThread();
- void AdapterScanThread(std::stop_token stop_token);
+ void AdapterScanThread();
bool IsPayloadCorrect(const AdapterPayload& adapter_payload, s32 payload_size);
@@ -125,7 +119,13 @@ private:
void SendVibrations();
/// For use in initialization, querying devices to find the adapter
- bool Setup();
+ void Setup();
+
+ /// Resets status of all GC controller devices to a disconnected state
+ void ResetDevices();
+
+ /// Resets status of device connected to a disconnected state
+ void ResetDevice(std::size_t port);
/// Returns true if we successfully gain access to GC Adapter
bool CheckDeviceAccess();
@@ -137,15 +137,23 @@ private:
/// For shutting down, clear all data, join all threads, release usb
void Reset();
- std::unique_ptr<LibUSBDeviceHandle> usb_adapter_handle;
+ // Join all threads
+ void JoinThreads();
+
+ // Release usb handles
+ void ClearLibusbHandle();
+
+ libusb_device_handle* usb_adapter_handle = nullptr;
std::array<GCController, 4> pads;
Common::SPSCQueue<GCPadStatus> pad_queue;
- std::jthread adapter_input_thread;
- std::jthread adapter_scan_thread;
- bool restart_scan_thread{};
+ std::thread adapter_input_thread;
+ std::thread adapter_scan_thread;
+ bool adapter_input_thread_running;
+ bool adapter_scan_thread_running;
+ bool restart_scan_thread;
- std::unique_ptr<LibUSBContext> libusb_ctx;
+ libusb_context* libusb_ctx;
u8 input_endpoint{0};
u8 output_endpoint{0};