2016-01-06 07:00:02 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-01-06 07:00:02 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
#include <algorithm>
|
2017-03-07 03:48:07 +00:00
|
|
|
#include <array>
|
2016-01-06 07:00:02 +00:00
|
|
|
#include <jni.h>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include "Common/Event.h"
|
|
|
|
#include "Common/Flag.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/Thread.h"
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/CoreTiming.h"
|
2017-01-20 23:45:11 +00:00
|
|
|
#include "Core/HW/SI/SI.h"
|
2019-06-07 22:25:32 +00:00
|
|
|
#include "Core/HW/SI/SI_Device.h"
|
2016-01-06 07:00:02 +00:00
|
|
|
#include "Core/HW/SystemTimers.h"
|
|
|
|
|
|
|
|
#include "InputCommon/GCPadStatus.h"
|
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
namespace GCAdapter
|
|
|
|
{
|
2016-05-19 19:52:44 +00:00
|
|
|
static void Setup();
|
|
|
|
static void Reset();
|
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
// Java classes
|
|
|
|
static jclass s_adapter_class;
|
|
|
|
|
|
|
|
static bool s_detected = false;
|
|
|
|
static int s_fd = 0;
|
2020-08-26 20:40:22 +00:00
|
|
|
static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_type = {
|
2016-01-06 07:00:02 +00:00
|
|
|
ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE,
|
|
|
|
ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE};
|
|
|
|
static u8 s_controller_rumble[4];
|
|
|
|
|
|
|
|
// Input handling
|
|
|
|
static std::mutex s_read_mutex;
|
2017-03-07 03:48:07 +00:00
|
|
|
static std::array<u8, 37> s_controller_payload;
|
2016-01-23 12:32:07 +00:00
|
|
|
static std::atomic<int> s_controller_payload_size{0};
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
// Output handling
|
|
|
|
static std::mutex s_write_mutex;
|
|
|
|
static u8 s_controller_write_payload[5];
|
2016-02-13 14:17:20 +00:00
|
|
|
static std::atomic<int> s_controller_write_payload_size{0};
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
// Adapter running thread
|
|
|
|
static std::thread s_read_adapter_thread;
|
|
|
|
static Common::Flag s_read_adapter_thread_running;
|
|
|
|
|
|
|
|
static Common::Flag s_write_adapter_thread_running;
|
|
|
|
static Common::Event s_write_happened;
|
|
|
|
|
|
|
|
// Adapter scanning thread
|
|
|
|
static std::thread s_adapter_detect_thread;
|
|
|
|
static Common::Flag s_adapter_detect_thread_running;
|
|
|
|
|
|
|
|
static u64 s_last_init = 0;
|
|
|
|
|
|
|
|
static void ScanThreadFunc()
|
|
|
|
{
|
|
|
|
Common::SetCurrentThreadName("GC Adapter Scanning Thread");
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread started");
|
2016-01-06 07:00:02 +00:00
|
|
|
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z");
|
|
|
|
|
|
|
|
while (s_adapter_detect_thread_running.IsSet())
|
|
|
|
{
|
|
|
|
if (!s_detected && UseAdapter() &&
|
|
|
|
env->CallStaticBooleanMethod(s_adapter_class, queryadapter_func))
|
|
|
|
Setup();
|
|
|
|
Common::SleepCurrentThread(1000);
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter scanning thread stopped");
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
static void Write()
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
Common::SetCurrentThreadName("GC Adapter Write Thread");
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter write thread started");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2016-02-13 14:17:20 +00:00
|
|
|
jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "Output", "([B)I");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
while (s_write_adapter_thread_running.IsSet())
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
s_write_happened.Wait();
|
|
|
|
int write_size = s_controller_write_payload_size.load();
|
|
|
|
if (write_size)
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
jbyteArray jrumble_array = env->NewByteArray(5);
|
2020-08-26 20:40:22 +00:00
|
|
|
jbyte* jrumble = env->GetByteArrayElements(jrumble_array, nullptr);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(s_write_mutex);
|
|
|
|
memcpy(jrumble, s_controller_write_payload, write_size);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
env->ReleaseByteArrayElements(jrumble_array, jrumble, 0);
|
|
|
|
int size = env->CallStaticIntMethod(s_adapter_class, output_func, jrumble_array);
|
|
|
|
// Netplay sends invalid data which results in size = 0x00. Ignore it.
|
|
|
|
if (size != write_size && size != 0x00)
|
|
|
|
{
|
2021-05-04 20:37:06 +00:00
|
|
|
ERROR_LOG_FMT(CONTROLLERINTERFACE, "error writing rumble (size: {})", size);
|
2016-02-13 14:17:20 +00:00
|
|
|
Reset();
|
|
|
|
}
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
Common::YieldCPU();
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter write thread stopped");
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
static void Read()
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
Common::SetCurrentThreadName("GC Adapter Read Thread");
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter read thread started");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
bool first_read = true;
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "controller_payload", "[B");
|
|
|
|
jobject payload_object = env->GetStaticObjectField(s_adapter_class, payload_field);
|
2020-08-26 20:40:22 +00:00
|
|
|
auto* java_controller_payload = reinterpret_cast<jbyteArray*>(&payload_object);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
// Get function pointers
|
|
|
|
jmethodID getfd_func = env->GetStaticMethodID(s_adapter_class, "GetFD", "()I");
|
|
|
|
jmethodID input_func = env->GetStaticMethodID(s_adapter_class, "Input", "()I");
|
|
|
|
jmethodID openadapter_func = env->GetStaticMethodID(s_adapter_class, "OpenAdapter", "()Z");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
bool connected = env->CallStaticBooleanMethod(s_adapter_class, openadapter_func);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
if (connected)
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
s_write_adapter_thread_running.Set(true);
|
|
|
|
std::thread write_adapter_thread(Write);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
// Reset rumble once on initial reading
|
|
|
|
ResetRumble();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
while (s_read_adapter_thread_running.IsSet())
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
int read_size = env->CallStaticIntMethod(s_adapter_class, input_func);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
jbyte* java_data = env->GetByteArrayElements(*java_controller_payload, nullptr);
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(s_read_mutex);
|
2017-03-07 03:48:07 +00:00
|
|
|
std::copy(java_data, java_data + s_controller_payload.size(), s_controller_payload.begin());
|
2016-02-13 14:17:20 +00:00
|
|
|
s_controller_payload_size.store(read_size);
|
|
|
|
}
|
|
|
|
env->ReleaseByteArrayElements(*java_controller_payload, java_data, 0);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
if (first_read)
|
|
|
|
{
|
|
|
|
first_read = false;
|
|
|
|
s_fd = env->CallStaticIntMethod(s_adapter_class, getfd_func);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
Common::YieldCPU();
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
// Terminate the write thread on leaving
|
|
|
|
if (s_write_adapter_thread_running.TestAndClear())
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-02-13 14:17:20 +00:00
|
|
|
s_controller_write_payload_size.store(0);
|
|
|
|
s_write_happened.Set(); // Kick the waiting event
|
|
|
|
write_adapter_thread.join();
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-13 14:17:20 +00:00
|
|
|
s_fd = 0;
|
|
|
|
s_detected = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter read thread stopped");
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
if (s_fd)
|
|
|
|
return;
|
|
|
|
|
2017-07-01 21:08:58 +00:00
|
|
|
if (Core::GetState() != Core::State::Uninitialized && Core::GetState() != Core::State::Starting)
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
|
|
|
if ((CoreTiming::GetTicks() - s_last_init) < SystemTimers::GetTicksPerSecond())
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_last_init = CoreTiming::GetTicks();
|
|
|
|
}
|
|
|
|
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter");
|
|
|
|
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
|
|
|
|
|
|
|
|
if (UseAdapter())
|
|
|
|
StartScanThread();
|
|
|
|
}
|
|
|
|
|
2016-05-19 19:52:44 +00:00
|
|
|
static void Setup()
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2016-01-23 12:27:03 +00:00
|
|
|
s_fd = 0;
|
2016-02-13 14:17:20 +00:00
|
|
|
s_detected = true;
|
|
|
|
|
|
|
|
// Make sure the thread isn't in the middle of shutting down while starting a new one
|
|
|
|
if (s_read_adapter_thread_running.TestAndClear())
|
|
|
|
s_read_adapter_thread.join();
|
2016-01-23 12:27:03 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
s_read_adapter_thread_running.Set(true);
|
|
|
|
s_read_adapter_thread = std::thread(Read);
|
|
|
|
}
|
|
|
|
|
2016-05-19 19:52:44 +00:00
|
|
|
static void Reset()
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
|
|
|
if (!s_detected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (s_read_adapter_thread_running.TestAndClear())
|
|
|
|
s_read_adapter_thread.join();
|
|
|
|
|
2020-08-26 20:40:22 +00:00
|
|
|
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
|
2016-01-06 07:00:02 +00:00
|
|
|
|
|
|
|
s_detected = false;
|
|
|
|
s_fd = 0;
|
2021-05-04 20:37:06 +00:00
|
|
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "GC Adapter detached");
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
|
|
|
StopScanThread();
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartScanThread()
|
|
|
|
{
|
|
|
|
if (s_adapter_detect_thread_running.IsSet())
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_adapter_detect_thread_running.Set(true);
|
|
|
|
s_adapter_detect_thread = std::thread(ScanThreadFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopScanThread()
|
|
|
|
{
|
|
|
|
if (s_adapter_detect_thread_running.TestAndClear())
|
|
|
|
s_adapter_detect_thread.join();
|
|
|
|
}
|
|
|
|
|
2016-08-02 01:16:00 +00:00
|
|
|
GCPadStatus Input(int chan)
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
|
|
|
if (!UseAdapter() || !s_detected || !s_fd)
|
2016-08-02 01:16:00 +00:00
|
|
|
return {};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-23 12:27:03 +00:00
|
|
|
int payload_size = 0;
|
2020-08-26 20:40:22 +00:00
|
|
|
std::array<u8, 37> controller_payload_copy{};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(s_read_mutex);
|
2017-03-07 03:48:07 +00:00
|
|
|
controller_payload_copy = s_controller_payload;
|
2016-01-23 12:27:03 +00:00
|
|
|
payload_size = s_controller_payload_size.load();
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 01:16:00 +00:00
|
|
|
GCPadStatus pad = {};
|
2017-03-07 03:48:07 +00:00
|
|
|
if (payload_size != controller_payload_copy.size())
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
2021-05-04 20:37:06 +00:00
|
|
|
ERROR_LOG_FMT(CONTROLLERINTERFACE, "error reading payload (size: {}, type: {:02x})",
|
|
|
|
payload_size, controller_payload_copy[0]);
|
2016-01-06 07:00:02 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool get_origin = false;
|
|
|
|
u8 type = controller_payload_copy[1 + (9 * chan)] >> 4;
|
|
|
|
if (type != ControllerTypes::CONTROLLER_NONE &&
|
|
|
|
s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE)
|
|
|
|
{
|
2021-05-04 20:37:06 +00:00
|
|
|
ERROR_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}",
|
|
|
|
chan + 1, controller_payload_copy[1 + (9 * chan)]);
|
2016-01-06 07:00:02 +00:00
|
|
|
get_origin = true;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
s_controller_type[chan] = type;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
|
|
|
{
|
|
|
|
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
|
|
|
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 0))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_A;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 1))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_B;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 2))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_X;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 3))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_Y;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 4))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_LEFT;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 5))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_RIGHT;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 6))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_DOWN;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b1 & (1 << 7))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_UP;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b2 & (1 << 0))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_BUTTON_START;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b2 & (1 << 1))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_TRIGGER_Z;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b2 & (1 << 2))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_TRIGGER_R;
|
2016-01-06 07:00:02 +00:00
|
|
|
if (b2 & (1 << 3))
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_TRIGGER_L;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
if (get_origin)
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button |= PAD_GET_ORIGIN;
|
|
|
|
|
|
|
|
pad.stickX = controller_payload_copy[1 + (9 * chan) + 3];
|
|
|
|
pad.stickY = controller_payload_copy[1 + (9 * chan) + 4];
|
|
|
|
pad.substickX = controller_payload_copy[1 + (9 * chan) + 5];
|
|
|
|
pad.substickY = controller_payload_copy[1 + (9 * chan) + 6];
|
|
|
|
pad.triggerLeft = controller_payload_copy[1 + (9 * chan) + 7];
|
|
|
|
pad.triggerRight = controller_payload_copy[1 + (9 * chan) + 8];
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-02 01:16:00 +00:00
|
|
|
pad.button = PAD_ERR_STATUS;
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-02 01:16:00 +00:00
|
|
|
|
|
|
|
return pad;
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Output(int chan, u8 rumble_command)
|
|
|
|
{
|
|
|
|
if (!UseAdapter() || !s_detected || !s_fd)
|
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
// Skip over rumble commands if it has not changed or the controller is wireless
|
|
|
|
if (rumble_command != s_controller_rumble[chan] &&
|
|
|
|
s_controller_type[chan] != ControllerTypes::CONTROLLER_WIRELESS)
|
|
|
|
{
|
|
|
|
s_controller_rumble[chan] = rumble_command;
|
|
|
|
unsigned char rumble[5] = {0x11, s_controller_rumble[0], s_controller_rumble[1],
|
|
|
|
s_controller_rumble[2], s_controller_rumble[3]};
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(s_write_mutex);
|
|
|
|
memcpy(s_controller_write_payload, rumble, 5);
|
2016-02-13 14:17:20 +00:00
|
|
|
s_controller_write_payload_size.store(5);
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
s_write_happened.Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-29 20:37:48 +00:00
|
|
|
bool IsDetected(const char** error_message)
|
2016-01-06 07:00:02 +00:00
|
|
|
{
|
|
|
|
return s_detected;
|
|
|
|
}
|
|
|
|
bool DeviceConnected(int chan)
|
|
|
|
{
|
|
|
|
return s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE;
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:15:58 +00:00
|
|
|
void ResetDeviceType(int chan)
|
|
|
|
{
|
|
|
|
s_controller_type[chan] = ControllerTypes::CONTROLLER_NONE;
|
|
|
|
}
|
|
|
|
|
2016-01-06 07:00:02 +00:00
|
|
|
bool UseAdapter()
|
|
|
|
{
|
2017-03-16 08:41:36 +00:00
|
|
|
const auto& si_devices = SConfig::GetInstance().m_SIDevice;
|
|
|
|
|
|
|
|
return std::any_of(std::begin(si_devices), std::end(si_devices), [](const auto device_type) {
|
|
|
|
return device_type == SerialInterface::SIDEVICE_WIIU_ADAPTER;
|
|
|
|
});
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetRumble()
|
|
|
|
{
|
|
|
|
unsigned char rumble[5] = {0x11, 0, 0, 0, 0};
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(s_read_mutex);
|
|
|
|
memcpy(s_controller_write_payload, rumble, 5);
|
2016-02-13 14:17:20 +00:00
|
|
|
s_controller_write_payload_size.store(5);
|
2016-01-06 07:00:02 +00:00
|
|
|
}
|
|
|
|
s_write_happened.Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAdapterCallback(std::function<void(void)> func)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace GCAdapter
|