Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcadapter: fix Android unused constant warning #12098

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 17 additions & 15 deletions Source/Core/InputCommon/GCAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ enum class ControllerType : u8

static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_rumble;

constexpr size_t CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
constexpr size_t CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE = 1;
constexpr size_t CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE = 5;
constexpr size_t CONTROLLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
constexpr size_t CONTROLLER_OUTPUT_INIT_PAYLOAD_SIZE = 1;
#endif
constexpr size_t CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE = 5;

struct PortState
{
Expand All @@ -115,7 +117,7 @@ struct PortState
// Only access with s_mutex held!
static std::array<PortState, SerialInterface::MAX_SI_CHANNELS> s_port_states;

static std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> s_controller_write_payload;
static std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> s_controller_write_payload;
static std::atomic<int> s_controller_write_payload_size{0};

static std::thread s_read_adapter_thread;
Expand Down Expand Up @@ -200,7 +202,7 @@ static void ReadThreadFunc()
while (s_read_adapter_thread_running.IsSet())
{
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
std::array<u8, CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE> input_buffer;
std::array<u8, CONTROLLER_INPUT_PAYLOAD_EXPECTED_SIZE> input_buffer;

int payload_size = 0;
int error = libusb_interrupt_transfer(s_handle, s_endpoint_in, input_buffer.data(),
Expand Down Expand Up @@ -289,7 +291,7 @@ static void WriteThreadFunc()
LibusbUtils::ErrorWrap(error));
}
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
const jbyteArray jrumble_array = env->NewByteArray(CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
const jbyteArray jrumble_array = env->NewByteArray(CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
jbyte* const jrumble = env->GetByteArrayElements(jrumble_array, nullptr);

{
Expand Down Expand Up @@ -650,9 +652,9 @@ static void AddGCAdapter(libusb_device* device)
config.reset();

int size = 0;
std::array<u8, CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE> payload = {0x13};
std::array<u8, CONTROLLER_OUTPUT_INIT_PAYLOAD_SIZE> payload = {0x13};
error = libusb_interrupt_transfer(s_handle, s_endpoint_out, payload.data(),
CONTROLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS);
CONTROLLER_OUTPUT_INIT_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS);
if (error != LIBUSB_SUCCESS)
{
WARN_LOG_FMT(CONTROLLERINTERFACE, "AddGCAdapter: libusb_interrupt_transfer failed: {}",
Expand Down Expand Up @@ -776,7 +778,7 @@ static ControllerType IdentifyControllerType(u8 data)

void ProcessInputPayload(const u8* data, std::size_t size)
{
if (size != CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE
if (size != CONTROLLER_INPUT_PAYLOAD_EXPECTED_SIZE
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|| data[0] != LIBUSB_DT_HID
#endif
Expand Down Expand Up @@ -891,11 +893,11 @@ void ResetRumble()
return;
ResetRumbleLockNeeded();
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {0x11, 0, 0, 0, 0};
std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {0x11, 0, 0, 0, 0};
{
std::lock_guard lk(s_write_mutex);
s_controller_write_payload = rumble;
s_controller_write_payload_size.store(CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
s_controller_write_payload_size.store(CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
}
s_write_happened.Set();
#endif
Expand All @@ -913,14 +915,14 @@ static void ResetRumbleLockNeeded()

std::fill(std::begin(s_controller_rumble), std::end(s_controller_rumble), 0);

std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
s_controller_rumble[3]};

int size = 0;
const int error =
libusb_interrupt_transfer(s_handle, s_endpoint_out, rumble.data(),
CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS);
CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE, &size, USB_TIMEOUT_MS);
if (error != LIBUSB_SUCCESS)
{
WARN_LOG_FMT(CONTROLLERINTERFACE, "ResetRumbleLockNeeded: libusb_interrupt_transfer failed: {}",
Expand Down Expand Up @@ -949,15 +951,15 @@ void Output(int chan, u8 rumble_command)
s_port_states[chan].controller_type != ControllerType::Wireless)
{
s_controller_rumble[chan] = rumble_command;
std::array<u8, CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
std::array<u8, CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE> rumble = {
0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2],
s_controller_rumble[3]};
{
#if GCADAPTER_USE_ANDROID_IMPLEMENTATION
std::lock_guard lk(s_write_mutex);
#endif
s_controller_write_payload = rumble;
s_controller_write_payload_size.store(CONTROLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
s_controller_write_payload_size.store(CONTROLLER_OUTPUT_RUMBLE_PAYLOAD_SIZE);
}
s_write_happened.Set();
}
Expand Down