GCAdapter: Harmonize read/write thread variable names
This commit is contained in:
parent
279888da8c
commit
27947046af
|
@ -95,38 +95,32 @@ constexpr size_t CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
|
||||||
constexpr size_t CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE = 1;
|
constexpr size_t CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE = 1;
|
||||||
constexpr size_t CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE = 5;
|
constexpr size_t CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE = 5;
|
||||||
|
|
||||||
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
|
||||||
static std::mutex s_mutex;
|
|
||||||
static std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> s_controller_payload;
|
static std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> s_controller_payload;
|
||||||
|
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
||||||
static std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> s_controller_payload_swap;
|
static std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> s_controller_payload_swap;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Only access with s_mutex held!
|
// Only access with s_mutex held!
|
||||||
static int s_controller_payload_size = {0};
|
static int s_controller_payload_size = {0};
|
||||||
|
|
||||||
static std::thread s_adapter_input_thread;
|
#if GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
||||||
static std::thread s_adapter_output_thread;
|
|
||||||
static Common::Flag s_adapter_thread_running;
|
|
||||||
|
|
||||||
static Common::Event s_rumble_data_available;
|
|
||||||
|
|
||||||
static std::mutex s_init_mutex;
|
|
||||||
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
|
||||||
// Input handling
|
|
||||||
static std::mutex s_read_mutex;
|
|
||||||
static std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> s_controller_payload;
|
|
||||||
static int s_controller_payload_size = {0};
|
|
||||||
|
|
||||||
// Output handling
|
|
||||||
static std::mutex s_write_mutex;
|
|
||||||
static std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> s_controller_write_payload;
|
static std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> s_controller_write_payload;
|
||||||
static std::atomic<int> s_controller_write_payload_size{0};
|
static std::atomic<int> s_controller_write_payload_size{0};
|
||||||
|
#endif
|
||||||
|
|
||||||
// Adapter running thread
|
|
||||||
static std::thread s_read_adapter_thread;
|
static std::thread s_read_adapter_thread;
|
||||||
static Common::Flag s_read_adapter_thread_running;
|
static std::thread s_write_adapter_thread;
|
||||||
|
|
||||||
static Common::Flag s_write_adapter_thread_running;
|
|
||||||
static Common::Event s_write_happened;
|
static Common::Event s_write_happened;
|
||||||
|
|
||||||
|
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
||||||
|
static std::mutex s_mutex;
|
||||||
|
static std::mutex s_init_mutex;
|
||||||
|
static Common::Flag s_adapter_thread_running;
|
||||||
|
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
||||||
|
static std::mutex s_read_mutex;
|
||||||
|
static std::mutex s_write_mutex;
|
||||||
|
static Common::Flag s_read_adapter_thread_running;
|
||||||
|
static Common::Flag s_write_adapter_thread_running;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::thread s_adapter_detect_thread;
|
static std::thread s_adapter_detect_thread;
|
||||||
|
@ -201,7 +195,7 @@ static void Read()
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
s_write_adapter_thread_running.Set(true);
|
s_write_adapter_thread_running.Set(true);
|
||||||
std::thread write_adapter_thread(Write);
|
s_write_adapter_thread = std::thread(Write);
|
||||||
|
|
||||||
// Reset rumble once on initial reading
|
// Reset rumble once on initial reading
|
||||||
ResetRumble();
|
ResetRumble();
|
||||||
|
@ -253,7 +247,7 @@ static void Write()
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
s_rumble_data_available.Wait();
|
s_write_happened.Wait();
|
||||||
|
|
||||||
if (!s_adapter_thread_running.IsSet())
|
if (!s_adapter_thread_running.IsSet())
|
||||||
return;
|
return;
|
||||||
|
@ -615,8 +609,8 @@ static void AddGCAdapter(libusb_device* device)
|
||||||
CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, 16);
|
CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, 16);
|
||||||
|
|
||||||
s_adapter_thread_running.Set(true);
|
s_adapter_thread_running.Set(true);
|
||||||
s_adapter_input_thread = std::thread(Read);
|
s_read_adapter_thread = std::thread(Read);
|
||||||
s_adapter_output_thread = std::thread(Write);
|
s_write_adapter_thread = std::thread(Write);
|
||||||
|
|
||||||
s_status = ADAPTER_DETECTED;
|
s_status = ADAPTER_DETECTED;
|
||||||
if (s_detect_callback != nullptr)
|
if (s_detect_callback != nullptr)
|
||||||
|
@ -659,9 +653,9 @@ static void Reset()
|
||||||
|
|
||||||
if (s_adapter_thread_running.TestAndClear())
|
if (s_adapter_thread_running.TestAndClear())
|
||||||
{
|
{
|
||||||
s_rumble_data_available.Set();
|
s_write_happened.Set();
|
||||||
s_adapter_input_thread.join();
|
s_read_adapter_thread.join();
|
||||||
s_adapter_output_thread.join();
|
s_write_adapter_thread.join();
|
||||||
}
|
}
|
||||||
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
||||||
if (!s_detected)
|
if (!s_detected)
|
||||||
|
@ -878,9 +872,7 @@ void Output(int chan, u8 rumble_command)
|
||||||
s_controller_type[chan] != ControllerType::Wireless)
|
s_controller_type[chan] != ControllerType::Wireless)
|
||||||
{
|
{
|
||||||
s_controller_rumble[chan] = rumble_command;
|
s_controller_rumble[chan] = rumble_command;
|
||||||
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
#if GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
||||||
s_rumble_data_available.Set();
|
|
||||||
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
|
|
||||||
std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
|
std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
|
||||||
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
|
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
|
||||||
s_controller_rumble[3]};
|
s_controller_rumble[3]};
|
||||||
|
@ -889,8 +881,8 @@ void Output(int chan, u8 rumble_command)
|
||||||
s_controller_write_payload = rumble;
|
s_controller_write_payload = rumble;
|
||||||
s_controller_write_payload_size.store(CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
|
s_controller_write_payload_size.store(CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
|
||||||
}
|
}
|
||||||
s_write_happened.Set();
|
|
||||||
#endif
|
#endif
|
||||||
|
s_write_happened.Set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue